net: if: Add function to check any pending TX packets

This function can be used for example by network power management
to check if the network interface can be suspended or not.
If there are network packets in transmit queue, then the network
interface cannot be suspended yet.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
Jukka Rissanen 2020-03-19 18:48:50 +02:00
commit dee07c9e0a
2 changed files with 46 additions and 2 deletions

View file

@ -260,11 +260,18 @@ static bool net_if_tx(struct net_if *iface, struct net_pkt *pkt)
static void process_tx_packet(struct k_work *work)
{
struct net_if *iface;
struct net_pkt *pkt;
pkt = CONTAINER_OF(work, struct net_pkt, work);
net_if_tx(net_pkt_iface(pkt), pkt);
iface = net_pkt_iface(pkt);
net_if_tx(iface, pkt);
#if defined(CONFIG_NET_POWER_MANAGEMENT)
iface->tx_pending--;
#endif
}
void net_if_queue_tx(struct net_if *iface, struct net_pkt *pkt)
@ -282,7 +289,16 @@ void net_if_queue_tx(struct net_if *iface, struct net_pkt *pkt)
NET_DBG("TC %d with prio %d pkt %p", tc, prio, pkt);
#endif
net_tc_submit_to_tx_queue(tc, pkt);
#if defined(CONFIG_NET_POWER_MANAGEMENT)
iface->tx_pending++;
#endif
if (!net_tc_submit_to_tx_queue(tc, pkt)) {
#if defined(CONFIG_NET_POWER_MANAGEMENT)
iface->tx_pending--
#endif
;
}
}
void net_if_stats_reset(struct net_if *iface)