This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 9b7d80456be89f0a05a4a844c8b10c14a3045e77 Author: zhanghongyu <[email protected]> AuthorDate: Tue Apr 14 15:54:09 2026 +0800 drivers/net/upperhalf: fix tx stall when txq has pending packets. Remove the redundant txdone=true assignment in the transmit failure path of netdev_upper_txpoll(). Extend netdev_lower_txdone() to also trigger tx work when the upper half txq is non-empty, ensuring queued packets are drained even if the txdone flag was not set. Since some network card drivers free multiple packets together and then call txdone_cb, the txdone member variable is retained. ``` while (priv->tx_now != priv->tx_done) { if (priv->tx[priv->tx_done].status == 0) { break; } netpkt_free(dev, priv->tx_pkt[priv->tx_done], NETPKT_TX); priv->tx_done = (priv->tx_done + 1) % E1000_TX_DESC; } netdev_lower_txdone(dev); ``` Signed-off-by: zhanghongyu <[email protected]> --- drivers/net/netdev_upperhalf.c | 52 ++++++++++++++---------------------------- 1 file changed, 17 insertions(+), 35 deletions(-) diff --git a/drivers/net/netdev_upperhalf.c b/drivers/net/netdev_upperhalf.c index a5a12b4b457..50b60ef5a52 100644 --- a/drivers/net/netdev_upperhalf.c +++ b/drivers/net/netdev_upperhalf.c @@ -325,28 +325,20 @@ static int netdev_upper_txpoll(FAR struct net_driver_s *dev) if (netpkt_getdatalen(lower, pkt) > NETDEV_PKTSIZE(dev)) { - nerr("ERROR: Packet too long to send!\n"); - ret = NETDEV_TX_CONTINUE; + nerr("ERROR: Packet too long to send!, dropping\n"); + + /* Permanent error -- drop the packet to avoid infinite retry. + * netpkt_put() restores quota and places pkt back into + * dev->d_iob so the caller can release it. + */ + + NETDEV_TXERRORS(dev); + netpkt_put(dev, pkt, NETPKT_TX); } else { ret = lower->ops->transmit(lower, pkt); - } - - if (ret != OK) - { - if (ret == NETDEV_TX_CONTINUE) - { - /* Permanent error -- drop the packet to avoid infinite retry. - * netpkt_put() restores quota and places pkt back into - * dev->d_iob so the caller can release it. - */ - - NETDEV_TXERRORS(dev); - nerr("ERROR: Packet too large, dropping\n"); - netpkt_put(dev, pkt, NETPKT_TX); - } - else + if (ret != OK) { /* Transient error -- re-queue to txq head for retry. * Head-insert preserves packet ordering. The retry will be @@ -360,15 +352,8 @@ static int netdev_upper_txpoll(FAR struct net_driver_s *dev) nwarn("WARNING: Transmit failed: %d, re-queue pkt\n", ret); iob_add_queue_head(pkt, &upper->txq); atomic_add(&upper->lower->quota_ptr[NETPKT_TX], 1); + return ret; } - - /* When the quota is not 0, lower half may also return a failure, - * in which case the txdone process is required to trigger subsequent - * packet transmissions. - */ - - lower->txdone = true; - return ret; } return NETDEV_TX_CONTINUE; @@ -1878,18 +1863,12 @@ void netdev_lower_rxready(FAR struct netdev_lowerhalf_s *dev) void netdev_lower_txdone(FAR struct netdev_lowerhalf_s *dev) { - if (dev->txdone) - { -#if defined(CONFIG_NET_VLAN) || defined(CONFIG_NET_BRIDGE) - FAR struct netdev_upperhalf_s *upper = dev->netdev.d_private; -#endif + FAR struct netdev_upperhalf_s *upper = dev->netdev.d_private; + if (dev->txdone || !IOB_QEMPTY(&upper->txq)) + { dev->txdone = false; -#ifdef CONFIG_NET_VLAN - netdev_upper_vlan_foreach(upper, netdev_lower_txdone); -#endif - #ifdef CONFIG_NET_BRIDGE /* The bridge device may wait for room on its ports */ @@ -1901,6 +1880,9 @@ void netdev_lower_txdone(FAR struct netdev_lowerhalf_s *dev) if (dev->rxtype == NETDEV_RX_DIRECT) { +#ifdef CONFIG_NET_VLAN + netdev_upper_vlan_foreach(upper, netdev_lower_txdone); +#endif netdev_upper_txavail_work(dev->netdev.d_private); } else
