This is an automated email from the ASF dual-hosted git repository.

GUIDINGLI pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 8b361211df351452013ce8013142934e7bfe1cec
Author: zhanghongyu <[email protected]>
AuthorDate: Tue Nov 24 17:06:33 2026 +0800

    drivers/net: let the drivers reclaim their own finished transmissions.
    
    Remove the reclaim callback from netdev_ops_s.  It let the upper half ask
    a driver to release the packets the hardware had finished with, from
    netdev_upper_can_tx(), once the TX quota reached zero.  A driver knows
    better than the upper half when its transmissions complete, and it is
    already told about them by its own interrupt, so the reclaiming belongs
    to the driver: in its transmit operation, which needs the room, and
    before it reports a completed transmission with netdev_lower_txdone().
    
    The drivers of this tree are adapted accordingly:
    
      - pic32mz reaps the TX descriptors at the start of pic32mz_transmit().
        Its TX-done path already reaped them before netdev_lower_txdone(),
        and the reclaim callback was only a wrapper around the same reaping.
      - ctucanfd_pci releases the finished TXT buffers at the start of
        ctucanfd_sock_transmit() and in the TX interrupt, before reporting
        the completion.  Both return -EBUSY when no buffer is free.
      - imxrt_netc already reclaimed at the start of imxrt_netc_transmit()
        and in its watchdog, so only the callback entry is dropped.
      - The empty implementations of esp_wlan (both copies), usbhost_cdcecm
        and the NULL entry of mpfs_can are dropped with the callback.
      - The bridge no longer asks a port to reclaim before taking its quota:
        a port with no room is reported busy, which bridge_port_send()
        already handles.
    
    Assisted-by: Kiro:claude-opus-4
    Signed-off-by: zhanghongyu <[email protected]>
---
 arch/arm/src/imxrt/imxrt_netc.c                    |  1 -
 arch/mips/src/pic32mz/pic32mz_ethernet.c           | 32 ++++-----------
 arch/risc-v/src/common/espressif/esp_wlan_netdev.c | 21 ----------
 arch/risc-v/src/mpfs/mpfs_can.c                    |  5 +--
 arch/xtensa/src/common/espressif/esp_wlan_netdev.c | 21 ----------
 drivers/can/ctucanfd_pci.c                         | 13 +++++-
 drivers/net/bridge.c                               | 47 +++-------------------
 drivers/net/netdev_upperhalf.c                     | 12 ++----
 drivers/net/vlan.c                                 | 17 --------
 drivers/usbhost/usbhost_cdcecm.c                   | 16 --------
 drivers/vhost/vhost-net.c                          |  3 +-
 drivers/virtio/virtio-net.c                        |  1 -
 include/nuttx/net/netdev_lowerhalf.h               |  5 ---
 13 files changed, 29 insertions(+), 165 deletions(-)

diff --git a/arch/arm/src/imxrt/imxrt_netc.c b/arch/arm/src/imxrt/imxrt_netc.c
index d1071c80540..86ac6c3a621 100644
--- a/arch/arm/src/imxrt/imxrt_netc.c
+++ b/arch/arm/src/imxrt/imxrt_netc.c
@@ -165,7 +165,6 @@ static const struct netdev_ops_s g_netc_ops =
   .ifdown   = imxrt_netc_ifdown,
   .transmit = imxrt_netc_transmit,
   .receive  = imxrt_netc_receive,
-  .reclaim  = imxrt_netc_reclaim,
 #ifdef CONFIG_NET_MCASTGROUP
   .addmac   = imxrt_netc_multicast,
   .rmmac    = imxrt_netc_multicast,
diff --git a/arch/mips/src/pic32mz/pic32mz_ethernet.c 
b/arch/mips/src/pic32mz/pic32mz_ethernet.c
index ea543c5c8bb..47600dc3de1 100644
--- a/arch/mips/src/pic32mz/pic32mz_ethernet.c
+++ b/arch/mips/src/pic32mz/pic32mz_ethernet.c
@@ -500,7 +500,6 @@ static int pic32mz_ifup(struct netdev_lowerhalf_s *dev);
 static int pic32mz_ifdown(struct netdev_lowerhalf_s *dev);
 static int pic32mz_transmit(struct netdev_lowerhalf_s *dev, netpkt_t *pkt);
 static netpkt_t *pic32mz_receive(struct netdev_lowerhalf_s *dev);
-static void pic32mz_reclaim(struct netdev_lowerhalf_s *dev);
 
 #ifdef CONFIG_NET_MCASTGROUP
 static int pic32mz_addmac(struct netdev_lowerhalf_s *dev,
@@ -528,7 +527,6 @@ static const struct netdev_ops_s g_pic32mz_ops =
 #if defined(CONFIG_NETDEV_IOCTL) && defined(PIC32MZ_HAVE_PHY)
   .ioctl    = pic32mz_ioctl,
 #endif
-  .reclaim  = pic32mz_reclaim,
 };
 
 /* PHY initialization functions */
@@ -1420,6 +1418,13 @@ static int pic32mz_transmit(struct netdev_lowerhalf_s 
*dev, netpkt_t *pkt)
       goto errout;
     }
 
+  /* Reap the descriptors the hardware has finished with, so that a
+   * descriptor freed since the last TX-done interrupt can be used right
+   * away instead of making the upper half wait for the next one.
+   */
+
+  pic32mz_txreap(priv);
+
   /* Find the next available TX descriptor.  The TX quota is the number of
    * descriptors, so there is one unless the interface was reset.
    */
@@ -1699,29 +1704,6 @@ static netpkt_t *pic32mz_receive(struct 
netdev_lowerhalf_s *dev)
   return pkt;
 }
 
-/****************************************************************************
- * Function: pic32mz_reclaim
- *
- * Description:
- *   NuttX Callback: reclaim the TX descriptors that were already sent.
- *
- * Input Parameters:
- *   dev - Reference to the lower half driver state structure
- *
- * Returned Value:
- *   None
- *
- ****************************************************************************/
-
-static void pic32mz_reclaim(struct netdev_lowerhalf_s *dev)
-{
-  struct pic32mz_driver_s *priv = (struct pic32mz_driver_s *)dev;
-
-  nxmutex_lock(&priv->pd_lock);
-  pic32mz_txreap(priv);
-  nxmutex_unlock(&priv->pd_lock);
-}
-
 /****************************************************************************
  * Function: pic32mz_interrupt_work
  *
diff --git a/arch/risc-v/src/common/espressif/esp_wlan_netdev.c 
b/arch/risc-v/src/common/espressif/esp_wlan_netdev.c
index da4e55157c0..9354cb69df6 100644
--- a/arch/risc-v/src/common/espressif/esp_wlan_netdev.c
+++ b/arch/risc-v/src/common/espressif/esp_wlan_netdev.c
@@ -61,7 +61,6 @@ static int esp_wlan_ifup(struct netdev_lowerhalf_s *dev);
 static int esp_wlan_ifdown(struct netdev_lowerhalf_s *dev);
 static int esp_wlan_transmit(struct netdev_lowerhalf_s *dev, netpkt_t *pkt);
 static netpkt_t *esp_wlan_receive(struct netdev_lowerhalf_s *dev);
-static void esp_wlan_reclaim(struct netdev_lowerhalf_s *dev);
 static int esp_wlan_ioctl(struct netdev_lowerhalf_s *dev, int cmd,
                           unsigned long arg);
 
@@ -131,7 +130,6 @@ static const struct netdev_ops_s g_netdev_ops =
     .transmit = esp_wlan_transmit,
     .receive = esp_wlan_receive,
     .ioctl = esp_wlan_ioctl,
-    .reclaim = esp_wlan_reclaim,
 };
 
 /* Wireless operations */
@@ -389,25 +387,6 @@ static int esp_wlan_ioctl(struct netdev_lowerhalf_s *dev, 
int cmd,
 }
 #endif
 
-/****************************************************************************
- * Name: esp_wlan_reclaim
- *
- * Description:
- *   Reclaim function required by the netdev ops.
- *
- * Input Parameters:
- *   dev - The network device.
- *
- * Returned Value:
- *   None.
- *
- ****************************************************************************/
-
-static void esp_wlan_reclaim(struct netdev_lowerhalf_s *dev)
-{
-  /* TODO: Implement reclaim logic */
-}
-
 /* Skeleton implementations for wireless_ops_s functions */
 
 /****************************************************************************
diff --git a/arch/risc-v/src/mpfs/mpfs_can.c b/arch/risc-v/src/mpfs/mpfs_can.c
index e8e814526ee..931b64e5343 100644
--- a/arch/risc-v/src/mpfs/mpfs_can.c
+++ b/arch/risc-v/src/mpfs/mpfs_can.c
@@ -586,11 +586,10 @@ static const struct netdev_ops_s g_netdev_ops =
   NULL,          /* rmmac */
 #endif
 #ifdef CONFIG_NETDEV_IOCTL
-  mpfs_ioctl,    /* ioctl */
+  mpfs_ioctl     /* ioctl */
 #else
-  NULL,          /* ioctl */
+  NULL           /* ioctl */
 #endif
-  NULL           /* reclaim */
 };
 
 /****************************************************************************
diff --git a/arch/xtensa/src/common/espressif/esp_wlan_netdev.c 
b/arch/xtensa/src/common/espressif/esp_wlan_netdev.c
index bd0a30fbc60..621790bcaf9 100644
--- a/arch/xtensa/src/common/espressif/esp_wlan_netdev.c
+++ b/arch/xtensa/src/common/espressif/esp_wlan_netdev.c
@@ -61,7 +61,6 @@ static int esp_wlan_ifup(struct netdev_lowerhalf_s *dev);
 static int esp_wlan_ifdown(struct netdev_lowerhalf_s *dev);
 static int esp_wlan_transmit(struct netdev_lowerhalf_s *dev, netpkt_t *pkt);
 static netpkt_t *esp_wlan_receive(struct netdev_lowerhalf_s *dev);
-static void esp_wlan_reclaim(struct netdev_lowerhalf_s *dev);
 static int esp_wlan_ioctl(struct netdev_lowerhalf_s *dev, int cmd,
                           unsigned long arg);
 
@@ -131,7 +130,6 @@ static const struct netdev_ops_s g_netdev_ops =
     .transmit = esp_wlan_transmit,
     .receive = esp_wlan_receive,
     .ioctl = esp_wlan_ioctl,
-    .reclaim = esp_wlan_reclaim,
 };
 
 /* Wireless operations */
@@ -389,25 +387,6 @@ static int esp_wlan_ioctl(struct netdev_lowerhalf_s *dev, 
int cmd,
 }
 #endif
 
-/****************************************************************************
- * Name: esp_wlan_reclaim
- *
- * Description:
- *   Reclaim function required by the netdev ops.
- *
- * Input Parameters:
- *   dev - The network device.
- *
- * Returned Value:
- *   None.
- *
- ****************************************************************************/
-
-static void esp_wlan_reclaim(struct netdev_lowerhalf_s *dev)
-{
-  /* TODO: Implement reclaim logic */
-}
-
 /* Skeleton implementations for wireless_ops_s functions */
 
 /****************************************************************************
diff --git a/drivers/can/ctucanfd_pci.c b/drivers/can/ctucanfd_pci.c
index 95a7c33cf4f..3e2d34e4c15 100644
--- a/drivers/can/ctucanfd_pci.c
+++ b/drivers/can/ctucanfd_pci.c
@@ -247,7 +247,6 @@ static const struct netdev_ops_s g_ctucanfd_net_ops =
   .ifdown   = ctucanfd_sock_ifdown,
   .transmit = ctucanfd_sock_transmit,
   .receive  = ctucanfd_sock_recv,
-  .reclaim  = ctucanfd_sock_reclaim,
 #ifdef CONFIG_NETDEV_IOCTL
   .ioctl    = ctucanfd_sock_ioctl,
 #endif
@@ -1165,6 +1164,13 @@ static int ctucanfd_sock_transmit(FAR struct 
netdev_lowerhalf_s *dev,
   int                         wirelen;
 #endif
 
+  /* Release the TXT buffers the hardware has finished with, so that a
+   * buffer freed since the last TX-done interrupt can be used right away
+   * instead of making the upper half wait for the next one.
+   */
+
+  ctucanfd_sock_reclaim(dev);
+
   /* Get TX empty buffer */
 
   regval = ctucanfd_getreg(priv, CTUCANFD_TXSTAT);
@@ -1651,10 +1657,13 @@ static void ctucanfd_sock_interrupt(FAR struct 
ctucanfd_driver_s *priv)
           netdev_lower_rxready(&priv->devs[i].dev);
         }
 
-      /* Frame transmitted, the upper half reclaims the TXT buffers */
+      /* Frame transmitted: release the TXT buffers the hardware is done
+       * with, then let the upper half offer the next packet.
+       */
 
       if (stat & CTUCANFD_INT_TXI)
         {
+          ctucanfd_sock_reclaim(&priv->devs[i].dev);
           netdev_lower_txdone(&priv->devs[i].dev);
         }
 
diff --git a/drivers/net/bridge.c b/drivers/net/bridge.c
index 809d654e75f..1a00fb28415 100644
--- a/drivers/net/bridge.c
+++ b/drivers/net/bridge.c
@@ -119,7 +119,6 @@ static int bridge_addmac(FAR struct netdev_lowerhalf_s *dev,
 static int bridge_rmmac(FAR struct netdev_lowerhalf_s *dev,
                         FAR const uint8_t *mac);
 #endif
-static void bridge_reclaim(FAR struct netdev_lowerhalf_s *dev);
 
 /****************************************************************************
  * Private Data
@@ -136,9 +135,8 @@ static const struct netdev_ops_s g_bridge_ops =
   bridge_rmmac,    /* rmmac */
 #endif
 #ifdef CONFIG_NETDEV_IOCTL
-  NULL,            /* ioctl */
+  NULL             /* ioctl */
 #endif
-  bridge_reclaim   /* reclaim */
 };
 
 /* All bridges, protected by g_bridge_lock */
@@ -459,11 +457,10 @@ static int bridge_port_send(FAR struct bridge_port_s 
*port,
       return -EMSGSIZE;
     }
 
-  if (atomic_read(&dev->quota_ptr[NETPKT_TX]) <= 0 &&
-      dev->ops->reclaim != NULL)
-    {
-      dev->ops->reclaim(dev);
-    }
+  /* The port reclaims its finished transmissions by itself, in its
+   * transmit operation and when it reports a completed one, so a port with
+   * no room is simply reported busy here.
+   */
 
   if (atomic_sub(&dev->quota_ptr[NETPKT_TX], 1) <= 0)
     {
@@ -761,40 +758,6 @@ static int bridge_rmmac(FAR struct netdev_lowerhalf_s *dev,
 }
 #endif
 
-/****************************************************************************
- * Name: bridge_reclaim
- *
- * Description:
- *   The network stack found no room on the bridge device: let the ports
- *   reclaim their sent packets, then look at the room again.
- *
- ****************************************************************************/
-
-static void bridge_reclaim(FAR struct netdev_lowerhalf_s *dev)
-{
-  FAR struct bridge_s *br = (FAR struct bridge_s *)dev;
-  int i;
-
-  nxmutex_lock(&br->br_lock);
-  for (i = 0; i < CONFIG_NET_BRIDGE_MAX_PORTS; i++)
-    {
-      FAR struct netdev_lowerhalf_s *port = br->br_ports[i].bp_dev;
-
-      if (port == NULL)
-        {
-          break;
-        }
-
-      if (port->ops->reclaim != NULL)
-        {
-          port->ops->reclaim(port);
-        }
-    }
-
-  bridge_update_quota(br);
-  nxmutex_unlock(&br->br_lock);
-}
-
 /****************************************************************************
  * Name: bridge_find
  *
diff --git a/drivers/net/netdev_upperhalf.c b/drivers/net/netdev_upperhalf.c
index 081806f02dd..f402e8ea721 100644
--- a/drivers/net/netdev_upperhalf.c
+++ b/drivers/net/netdev_upperhalf.c
@@ -261,20 +261,14 @@ netdev_upper_alloc(FAR struct netdev_lowerhalf_s *dev, 
size_t extra_size)
 static inline bool netdev_upper_can_tx(FAR struct netdev_upperhalf_s *upper)
 {
   FAR struct netdev_lowerhalf_s *lower = upper->lower;
-  int quota = netdev_lower_quota_load(lower, NETPKT_TX);
 
-  if (quota <= 0 && lower->ops->reclaim)
-    {
-      lower->ops->reclaim(lower);
-      quota = netdev_lower_quota_load(lower, NETPKT_TX);
-    }
-
-  if (quota <= 0)
+  if (netdev_lower_quota_load(lower, NETPKT_TX) <= 0)
     {
       lower->txdone = true;
+      return false;
     }
 
-  return quota > 0;
+  return true;
 }
 
 /****************************************************************************
diff --git a/drivers/net/vlan.c b/drivers/net/vlan.c
index eeaf17d6254..31931b505b1 100644
--- a/drivers/net/vlan.c
+++ b/drivers/net/vlan.c
@@ -76,7 +76,6 @@ static int vlan_rmmac(FAR struct netdev_lowerhalf_s *dev,
 static int vlan_ioctl(FAR struct netdev_lowerhalf_s *dev, int cmd,
                       unsigned long arg);
 #endif
-static void vlan_reclaim(FAR struct netdev_lowerhalf_s *dev);
 #ifdef CONFIG_NET_NETPOLL
 static void vlan_txpoll(FAR struct netdev_lowerhalf_s *dev);
 #endif
@@ -98,7 +97,6 @@ static const struct netdev_ops_s g_vlan_ops =
 #ifdef CONFIG_NETDEV_IOCTL
   vlan_ioctl,    /* ioctl */
 #endif
-  vlan_reclaim,  /* reclaim */
 #ifdef CONFIG_NET_NETPOLL
   vlan_txpoll,   /* txpoll */
 #endif
@@ -271,21 +269,6 @@ static int vlan_ioctl(FAR struct netdev_lowerhalf_s *dev, 
int cmd,
 }
 #endif
 
-/****************************************************************************
- * Name: vlan_reclaim
- ****************************************************************************/
-
-static void vlan_reclaim(FAR struct netdev_lowerhalf_s *dev)
-{
-  FAR struct vlan_device_s      *vlan = (FAR struct vlan_device_s *)dev;
-  FAR struct netdev_lowerhalf_s *real = vlan->real;
-
-  if (real->ops->reclaim != NULL)
-    {
-      real->ops->reclaim(real);
-    }
-}
-
 #ifdef CONFIG_NET_NETPOLL
 static void vlan_txpoll(FAR struct netdev_lowerhalf_s *dev)
 {
diff --git a/drivers/usbhost/usbhost_cdcecm.c b/drivers/usbhost/usbhost_cdcecm.c
index d53a572276e..f6a4ab27bdf 100644
--- a/drivers/usbhost/usbhost_cdcecm.c
+++ b/drivers/usbhost/usbhost_cdcecm.c
@@ -226,8 +226,6 @@ static FAR netpkt_t *cdcecm_net_receive(FAR struct 
netdev_lowerhalf_s *dev);
 static int cdcecm_net_ioctl(FAR struct netdev_lowerhalf_s *dev,
                             int cmd, unsigned long arg);
 #endif
-static void cdcecm_net_reclaim(FAR struct netdev_lowerhalf_s *dev);
-
 /****************************************************************************
  * Private Data
  ****************************************************************************/
@@ -276,7 +274,6 @@ static const struct netdev_ops_s g_cdcecm_netdev_ops =
 #ifdef CONFIG_NETDEV_IOCTL
     .ioctl    = cdcecm_net_ioctl,
 #endif
-    .reclaim  = cdcecm_net_reclaim,
 };
 
 /****************************************************************************
@@ -1846,19 +1843,6 @@ static int cdcecm_net_ioctl(FAR struct 
netdev_lowerhalf_s *dev, int cmd,
 }
 #endif
 
-/****************************************************************************
- * Name: cdcecm_net_reclaim
- *
- * Description:
- *   Lowerhalf reclaim callback. TX is synchronous via DRVR_TRANSFER
- *   so there are no queued TX packets to reclaim.
- *
- ****************************************************************************/
-
-static void cdcecm_net_reclaim(FAR struct netdev_lowerhalf_s *dev)
-{
-}
-
 /****************************************************************************
  * Name: cdcecm_ifup
  *
diff --git a/drivers/vhost/vhost-net.c b/drivers/vhost/vhost-net.c
index c73b4231d5b..956a8f31aba 100644
--- a/drivers/vhost/vhost-net.c
+++ b/drivers/vhost/vhost-net.c
@@ -174,9 +174,8 @@ static const struct netdev_ops_s g_vhost_net_ops =
   NULL,
 #endif
 #ifdef CONFIG_NETDEV_IOCTL
-  NULL,
-#endif
   NULL
+#endif
 };
 
 static struct vhost_driver g_vhost_net_driver =
diff --git a/drivers/virtio/virtio-net.c b/drivers/virtio/virtio-net.c
index 9597fe78d61..7f3b79270e3 100644
--- a/drivers/virtio/virtio-net.c
+++ b/drivers/virtio/virtio-net.c
@@ -207,7 +207,6 @@ static const struct netdev_ops_s g_virtio_net_ops =
 #ifdef CONFIG_NETDEV_IOCTL
   virtio_net_ioctl,
 #endif
-  virtio_net_txfree,  /* reclaim */
 #ifdef CONFIG_NET_NETPOLL
   virtio_net_txfree,  /* txpoll */
 #endif
diff --git a/include/nuttx/net/netdev_lowerhalf.h 
b/include/nuttx/net/netdev_lowerhalf.h
index c942f765e8a..701b3587b52 100644
--- a/include/nuttx/net/netdev_lowerhalf.h
+++ b/include/nuttx/net/netdev_lowerhalf.h
@@ -191,11 +191,6 @@ struct netdev_ops_s
   CODE int (*ioctl)(FAR struct netdev_lowerhalf_s *dev, int cmd,
                     unsigned long arg);
 #endif
-
-  /* reclaim - try to reclaim packets sent by netdev. */
-
-  CODE void (*reclaim)(FAR struct netdev_lowerhalf_s *dev);
-
 #ifdef CONFIG_NET_NETPOLL
   /* txpoll - Complete pending transmissions and free the finished TX
    *          packets, so their TX quota can be reused.

Reply via email to