net: Add preliminaly support for suspending/resuming a net interface

Such state needs to be set _from_ the PM API functions and not the other
way round. So if a network device driver does not support such API, it
will not be able to set the core net_if on PM state, obviously.

Currently, these functions only set/unset NET_IF_SUSPENDED flag.

More logic will be added later, to decide whether the net_if can be
actually set to suspend mode or not and also to take care of all timers
related to the interface.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
This commit is contained in:
Tomasz Bursztyka 2020-02-25 09:42:35 +01:00 committed by Jukka Rissanen
commit 80917ec16f
3 changed files with 62 additions and 1 deletions

View file

@ -347,7 +347,8 @@ enum net_verdict net_if_send_data(struct net_if *iface, struct net_pkt *pkt)
enum net_verdict verdict = NET_OK;
int status = -EIO;
if (!net_if_flag_is_set(iface, NET_IF_UP)) {
if (!net_if_flag_is_set(iface, NET_IF_UP) ||
net_if_flag_is_set(iface, NET_IF_SUSPENDED)) {
/* Drop packet if interface is not up */
NET_WARN("iface %p is down", iface);
verdict = NET_DROP;
@ -3623,6 +3624,34 @@ bool net_if_is_promisc(struct net_if *iface)
return net_if_flag_is_set(iface, NET_IF_PROMISC);
}
#ifdef CONFIG_NET_POWER_MANAGEMENT
int net_if_suspend(struct net_if *iface)
{
if (net_if_are_pending_tx_packets(iface)) {
return -EBUSY;
}
if (net_if_flag_test_and_set(iface, NET_IF_SUSPENDED)) {
return -EALREADY;
}
return 0;
}
int net_if_resume(struct net_if *iface)
{
if (!net_if_flag_is_set(iface, NET_IF_SUSPENDED)) {
return -EALREADY;
}
net_if_flag_clear(iface, NET_IF_SUSPENDED);
return 0;
}
#endif /* CONFIG_NET_POWER_MANAGEMENT */
#if defined(CONFIG_NET_PKT_TIMESTAMP_THREAD)
static void net_tx_ts_thread(void)
{