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 c177a4107dd3672c07239f2a45871de63870e6b8
Author: zhanghongyu <[email protected]>
AuthorDate: Tue Nov 24 21:14:02 2026 +0800

    drivers/net: replace the TX quota with the -EBUSY contract.
    
    Remove the per-type netpkt quota from the network device upper half.  It
    counted the packets each driver could hold, so that the stack stopped
    polling a device whose hardware was full, and it needed every lower-half
    driver to publish and maintain a number that only the driver itself could
    know.  The transmit operation already reports a full device by returning
    -EBUSY, and the upper half already queues the packet and offers it again
    when the driver reports a completed transmission, so the count is
    redundant.
    
      - Drop quota_ptr, quota[] and the quota_is_valid() registration check
        from struct netdev_lowerhalf_s, and netdev_lower_quota_load() with
        all of its callers.  netpkt_alloc() and netpkt_free() no longer
        maintain a counter.
      - The TX completion flag moves into the upper half as an atomic_t.
        netdev_lower_txdone() raises it with atomic_xchg() before looking at
        the queue, and netdev_upper_txavail_work() clears it before the
        attempts and runs another round for every completion that landed
        while it was transmitting.  Both sides do a read-modify-write on one
        location, and those are totally ordered, so a completion can no
        longer be lost between the -EBUSY return and the flag store.
      - netdev_upper_can_tx() is gone: a full device stops the loop by the
        non-CONTINUE return of the transmit poll, and the re-queued packet
        left at the head of the queue is the record of that state.
    
    The lower-half drivers lose their quota bookkeeping.  Three of them had
    flow control that only worked through the quota and are adapted:
    
      - pic32mz reports -EBUSY instead of -EAGAIN when the descriptor ring
        is full, and no longer accounts the extra descriptors of a
        multi-fragment packet.
      - oa_tc6 reports -EBUSY instead of -EAGAIN while its single in-flight
        packet is not sent.
      - ameba_wlan reports -EBUSY instead of -EIO when the NP skb pool is
        exhausted, so that the packet is offered again instead of dropped.
      - rzv2h_canfd releases the message buffers at the start of its transmit
        operation.  It already reported -EBUSY while no buffer was free, and
        its reclaim callback only wrapped the same freeing.
    
    Assisted-by: Kiro:claude-opus-4
    Signed-off-by: zhanghongyu <[email protected]>
---
 arch/arm/src/common/ameba/ameba_wlan.c             |  45 +++---
 arch/arm/src/imxrt/imxrt_netc.c                    |   4 +-
 arch/arm/src/imxrt/imxrt_netc_priv.h               |   1 -
 arch/arm/src/rzv2h/rzv2h_canfd.c                   |  32 +++--
 arch/mips/src/pic32mz/pic32mz_ethernet.c           |  37 +----
 arch/mips/src/pic32mz/pic32mz_w1_wlan.c            |   7 +-
 arch/risc-v/src/common/espressif/esp_emac.c        |  13 --
 arch/risc-v/src/common/espressif/esp_wlan_netdev.c |   2 -
 arch/risc-v/src/gd32vw55x/gdwifi/gdwifi_netdev.c   |   2 -
 arch/risc-v/src/mpfs/mpfs_can.c                    |   5 -
 arch/sim/src/sim/sim_netdriver.c                   |   8 +-
 arch/xtensa/src/common/espressif/esp_openeth.c     |   2 -
 arch/xtensa/src/common/espressif/esp_wlan_netdev.c |   2 -
 drivers/can/ctucanfd_pci.c                         |  14 +-
 drivers/can/kvaser_pci.c                           |  12 --
 drivers/net/Kconfig                                |  12 --
 drivers/net/bridge.c                               |  61 --------
 drivers/net/e1000.c                                |  16 ---
 drivers/net/igb.c                                  |  16 ---
 drivers/net/igc.c                                  |  16 ---
 drivers/net/netdev_upperhalf.c                     | 158 ++++++---------------
 drivers/net/oa_tc6/oa_tc6.c                        |  13 +-
 drivers/net/rpmsgdrv.c                             |   6 +-
 drivers/net/vlan.c                                 |  13 +-
 drivers/usbdev/Kconfig                             |   8 --
 drivers/usbdev/cdcncm.c                            |   8 +-
 drivers/usbhost/usbhost_cdcecm.c                   |   2 -
 drivers/vhost/vhost-net.c                          |  12 +-
 drivers/virtio/virtio-net.c                        |  16 +--
 drivers/wireless/ieee80211/morse/Kconfig           |   8 --
 drivers/wireless/ieee80211/morse/morse_netdev.c    |   2 -
 include/nuttx/net/netdev_lowerhalf.h               |  27 +---
 net/netpoll/netpoll_pkt.c                          |   4 +-
 33 files changed, 113 insertions(+), 471 deletions(-)

diff --git a/arch/arm/src/common/ameba/ameba_wlan.c 
b/arch/arm/src/common/ameba/ameba_wlan.c
index 303d09604f2..f15b512e297 100644
--- a/arch/arm/src/common/ameba/ameba_wlan.c
+++ b/arch/arm/src/common/ameba/ameba_wlan.c
@@ -30,8 +30,8 @@
  * This driver uses the NuttX network "lower-half" framework
  * (include/nuttx/net/netdev_lowerhalf.h + drivers/net/netdev_upperhalf.c):
  * we implement struct netdev_ops_s (ifup/ifdown/transmit/receive/ioctl) and
- * the generic upper half owns the poll loop, the RX/TX worker, the IOB
- * (netpkt) accounting and the quota-based flow control.  See the guide
+ * the generic upper half owns the poll loop, the RX/TX worker and the IOB
+ * (netpkt) accounting.  See the guide
  * in Documentation/components/net/netdriver.rst.
  *
  * The data path crosses to the SDK-header side through a thin byte-buffer
@@ -83,15 +83,6 @@
 
 #define AMEBA_WLAN_BUFSIZE  (CONFIG_NET_ETH_PKTSIZE + CONFIG_NET_GUARDSIZE)
 
-/* Quotas: the WHC send copies the frame synchronously, so a single in-flight
- * TX buffer is enough.  The RX quota bounds how many staged frames
- * (netpkts) the driver may hold before the upper half
- * drains them; keep it well under the IOB pool.
- */
-
-#define AMEBA_WLAN_TX_QUOTA 1
-#define AMEBA_WLAN_RX_QUOTA 16
-
 /****************************************************************************
  * Private Types
  ****************************************************************************/
@@ -191,14 +182,13 @@ static unsigned char ameba_wlan_is_dhcp(const uint8_t 
*frame,
  *
  * Description:
  *   netdev_ops_s::transmit -- hand one packet to the NP over WHC.
- *   Non-blocking; called by the upper half under the network lock, gated by
- *   the TX quota.  The netpkt (possibly IOB-fragmented) is copied out into
- *   the flat g_txbuf because the WHC send ABI wants a contiguous buffer.
+ *   Non-blocking; called by the upper half under the network lock.  The
+ *   netpkt (possibly IOB-fragmented) is copied out into the flat g_txbuf
+ *   because the WHC send ABI wants a contiguous buffer.
  *
- *   On success we own the packet and free it (which restores TX quota).  On
- *   failure (e.g. whc_ipc_host_send returns -2 when the NP skb pool is
- *   exhausted) we return a negated errno WITHOUT freeing: the upper half
- *   recycles the packet and stops the poll, which is genuine backpressure.
+ *   On success we own the packet and free it.  When the NP skb pool is
+ *   exhausted we return -EBUSY WITHOUT freeing: the upper half keeps the
+ *   packet and offers it again, which is genuine backpressure.
  *
  ****************************************************************************/
 
@@ -211,7 +201,7 @@ static int ameba_wlan_transmit(struct netdev_lowerhalf_s 
*dev,
 
   if (len == 0 || len > AMEBA_WLAN_BUFSIZE)
     {
-      /* Malformed: drop it (free -> quota restored) and report consumed. */
+      /* Malformed: drop it and report consumed */
 
       netpkt_free(dev, pkt, NETPKT_TX);
       return OK;
@@ -226,16 +216,15 @@ static int ameba_wlan_transmit(struct netdev_lowerhalf_s 
*dev,
 
   if (ret != 0)
     {
-      /* NP host skb pool full: recycle the packet (do NOT free) and
-       * let the upper half pause the poll -- genuine backpressure.
-       * This stays off the hot path because CONFIG_NET_SEND_BUFSIZE
-       * bounds a stream's in-flight data and the NP drains at line
-       * rate, so the transient host skb backlog stays well under the
-       * pool (skb_num_ap).  A momentary full pool just pauses here and
-       * resumes on the next poll.
+      /* NP host skb pool full: keep the packet (do NOT free) and report
+       * the device busy, so that the upper half queues it and offers it
+       * again -- genuine backpressure.  This stays off the hot path
+       * because CONFIG_NET_SEND_BUFSIZE bounds a stream's in-flight data
+       * and the NP drains at line rate, so the transient host skb backlog
+       * stays well under the pool (skb_num_ap).
        */
 
-      return -EIO;
+      return -EBUSY;
     }
 
   netpkt_free(dev, pkt, NETPKT_TX);
@@ -690,8 +679,6 @@ int ameba_wlan_initialize(void)
   spin_lock_init(&priv->rx_lock);
 
   dev->ops              = &g_ameba_wlan_ops;
-  dev->quota[NETPKT_TX] = AMEBA_WLAN_TX_QUOTA;
-  dev->quota[NETPKT_RX] = AMEBA_WLAN_RX_QUOTA;
 
   /* Dedicated RX/TX thread at a moderate priority (not HPWORK/192): HPWORK
    * would preempt the prebuilt WHC IPC RX-delivery task, which then cannot
diff --git a/arch/arm/src/imxrt/imxrt_netc.c b/arch/arm/src/imxrt/imxrt_netc.c
index 86ac6c3a621..17bd7ef155c 100644
--- a/arch/arm/src/imxrt/imxrt_netc.c
+++ b/arch/arm/src/imxrt/imxrt_netc.c
@@ -920,7 +920,7 @@ static int imxrt_netc_transmit(struct netdev_lowerhalf_s 
*lower,
 
   if (next == priv->txclean)
     {
-      nerr("NETC TX quota exceeded\n");
+      nerr("NETC transmit ring full\n");
       return -EBUSY;
     }
 
@@ -1209,8 +1209,6 @@ static int imxrt_netc_register(size_t index,
   priv->irq = g_msgintr_irq[config->msgintr - 1];
   priv->lower.ops = &g_netc_ops;
   priv->lower.priority = ETHWORK;
-  priv->lower.quota[NETPKT_TX] = NETC_TX_QUOTA;
-  priv->lower.quota[NETPKT_RX] = 1;
   memcpy(priv->lower.netdev.d_mac.ether.ether_addr_octet, config->mac, 6);
   priv->dma_cpu = imxrt_netc_alloc(sizeof(*priv->dma_cpu), &priv->dma_bus);
   if (priv->dma_cpu == NULL)
diff --git a/arch/arm/src/imxrt/imxrt_netc_priv.h 
b/arch/arm/src/imxrt/imxrt_netc_priv.h
index 7b95ee45290..a6d77bee611 100644
--- a/arch/arm/src/imxrt/imxrt_netc_priv.h
+++ b/arch/arm/src/imxrt/imxrt_netc_priv.h
@@ -53,7 +53,6 @@
                               ~(NETC_DMA_ALIGN - 1))
 #define NETC_TX_SLOTS         (CONFIG_IMXRT_NETC_NTXDESC / 2)
 #define NETC_RX_SLOTS         CONFIG_IMXRT_NETC_NRXDESC
-#define NETC_TX_QUOTA         (NETC_TX_SLOTS - 1)
 
 #ifdef CONFIG_ARCH_CORTEXM33
 #  define NETC_DCACHE_LINESIZE ARMV8M_DCACHE_LINESIZE
diff --git a/arch/arm/src/rzv2h/rzv2h_canfd.c b/arch/arm/src/rzv2h/rzv2h_canfd.c
index 711dd914889..009c2f02405 100644
--- a/arch/arm/src/rzv2h/rzv2h_canfd.c
+++ b/arch/arm/src/rzv2h/rzv2h_canfd.c
@@ -645,8 +645,7 @@ struct rzv2h_canfd_priv_s
   bool     rx_lost;                    /* A frame was dropped */
 
   /* Packet of the frame loaded into each TX message buffer, held until
-   * rzv2h_canfd_sock_reclaim() frees it, so the TX quota counts the frames
-   * still in the hardware.
+   * rzv2h_canfd_sock_reclaim() frees it.
    */
 
   netpkt_t *tx_pkt[RZV2H_CANFD_SOCK_TXMB_MAX];
@@ -863,7 +862,6 @@ static const struct netdev_ops_s g_rzv2h_canfd_sock_ops =
 #ifdef CONFIG_NETDEV_IOCTL
   .ioctl    = rzv2h_canfd_sock_ioctl,
 #endif
-  .reclaim  = rzv2h_canfd_sock_reclaim,
 };
 #else
 /* CANFD operations vtable */
@@ -4179,6 +4177,13 @@ static int rzv2h_canfd_send(struct can_dev_s *dev, 
struct can_msg_s *msg)
       return -EIO;
     }
 
+  /* Release the message buffers the hardware has finished with, so that a
+   * buffer freed since the last TX interrupt can be used right away
+   * instead of making the upper half wait for the next one.
+   */
+
+  rzv2h_canfd_sock_reclaim(dev);
+
   mb = rzv2h_canfd_txmb_next(priv);
   if (mb < 0)
     {
@@ -5702,8 +5707,7 @@ static void rzv2h_canfd_sock_txfree(struct 
rzv2h_canfd_priv_s *priv)
  * Name: rzv2h_canfd_sock_reclaim
  *
  * Description:
- *   NuttX callback, called when the TX quota is used up: free the held
- *   packets once every TX message buffer is idle, so that
+ *   Free the held packets once every TX message buffer is idle, so that
  *   rzv2h_canfd_txmb_next() starts again at TXMB0 with all txmb_num
  *   buffers free.
  *
@@ -5973,12 +5977,9 @@ static void rzv2h_canfd_sock_deadline_expiry(wdparm_t 
arg)
  *   rzv2h_canfd_sock_reclaim() frees it. The TX complete interrupt calls
  *   netdev_lower_txdone().
  *
- *   A packet that transmit() refuses is lost: devif_poll() releases it,
- *   and the socket has already reported the frame as sent. Holding the
- *   packets keeps the TX quota (txmb_num) at 0 from the moment the last
- *   TX message buffer is loaded until rzv2h_canfd_sock_reclaim() frees
- *   them, so transmit() is not called while rzv2h_canfd_txmb_next() has
- *   no buffer.
+ *   transmit() reports -EBUSY while rzv2h_canfd_txmb_next() has no free
+ *   buffer, so that the upper half keeps the packet and offers it again
+ *   once a transmission completes.
  *
  *   With CONFIG_NET_CAN_RAW_TX_DEADLINE, a frame whose deadline has passed
  *   is dropped, and rzv2h_canfd_sock_deadline_expiry() aborts a frame
@@ -6034,6 +6035,13 @@ static int rzv2h_canfd_sock_transmit(struct 
netdev_lowerhalf_s *dev,
     }
 #endif
 
+  /* Release the message buffers the hardware has finished with, so that a
+   * buffer freed since the last TX interrupt can be used right away
+   * instead of making the upper half wait for the next one.
+   */
+
+  rzv2h_canfd_sock_reclaim(dev);
+
   mb = rzv2h_canfd_txmb_next(priv);
   if (mb < 0)
     {
@@ -6570,8 +6578,6 @@ int rzv2h_canfd_sock_initialize(int channel)
 
   dev = &priv->dev;
   dev->ops = &g_rzv2h_canfd_sock_ops;
-  dev->quota[NETPKT_TX] = priv->txmb_num;
-  dev->quota[NETPKT_RX] = CONFIG_RZV2H_CANFD_SOCK_RX_DEPTH;
 
   /* Name the interface after the channel. netdev_register() uses a name
    * set here instead of the next free can<n> number.
diff --git a/arch/mips/src/pic32mz/pic32mz_ethernet.c 
b/arch/mips/src/pic32mz/pic32mz_ethernet.c
index 47600dc3de1..fe1d8004f7b 100644
--- a/arch/mips/src/pic32mz/pic32mz_ethernet.c
+++ b/arch/mips/src/pic32mz/pic32mz_ethernet.c
@@ -407,9 +407,7 @@ struct pic32mz_driver_s
 
   /* The packet being sent by each TX descriptor, kept in the descriptor
    * that holds the end of the packet.  It is held until that descriptor is
-   * reclaimed.  A packet takes one TX quota unit per descriptor, so that
-   * the network stack never queues more packets than there are free
-   * descriptors: pd_txfrags is the number of descriptors of the packet.
+   * reclaimed.  pd_txfrags is the number of descriptors of the packet.
    */
 
   netpkt_t  *pd_txpkt[CONFIG_PIC32MZ_ETH_NTXDESC];
@@ -1113,8 +1111,7 @@ static struct pic32mz_rxdesc_s *pic32mz_rxdesc(struct 
pic32mz_driver_s *priv)
  * Function: pic32mz_txrelease
  *
  * Description:
- *   Release the packet held by a TX descriptor, with the TX quota of all
- *   the descriptors of the packet.
+ *   Release the packet held by a TX descriptor.
  *
  * Input Parameters:
  *   priv - Reference to the driver state structure
@@ -1131,15 +1128,7 @@ static void pic32mz_txrelease(struct pic32mz_driver_s 
*priv, int idx)
 
   if (pkt != NULL)
     {
-      int extra = priv->pd_txfrags[idx] - 1;
-
       priv->pd_txpkt[idx] = NULL;
-
-      if (extra > 0)
-        {
-          atomic_add(&priv->pd_dev.quota_ptr[NETPKT_TX], extra);
-        }
-
       netpkt_free(&priv->pd_dev, pkt, NETPKT_TX);
     }
 }
@@ -1425,14 +1414,12 @@ static int pic32mz_transmit(struct netdev_lowerhalf_s 
*dev, netpkt_t *pkt)
 
   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.
-   */
+  /* Find the next available TX descriptor */
 
   txdesc = pic32mz_txdesc(priv);
   if (txdesc == NULL)
     {
-      ret = -EAGAIN;
+      ret = -EBUSY;
       goto errout;
     }
 
@@ -1521,19 +1508,12 @@ static int pic32mz_transmit(struct netdev_lowerhalf_s 
*dev, netpkt_t *pkt)
                       (uintptr_t)txdesc + sizeof(union pic32mz_txdesc_u));
     }
 
-  /* Hold the packet until its last descriptor is reclaimed.  The
-   * descriptors after the first take TX quota too.
-   */
+  /* Hold the packet until its last descriptor is reclaimed */
 
   last                  = (idx + nfrags - 1) % CONFIG_PIC32MZ_ETH_NTXDESC;
   priv->pd_txpkt[last]  = pkt;
   priv->pd_txfrags[last] = nfrags;
 
-  if (nfrags > 1)
-    {
-      atomic_sub(&priv->pd_dev.quota_ptr[NETPKT_TX], nfrags - 1);
-    }
-
   /* Update the index to the next descriptor to use in the Tx ring */
 
   priv->pd_txnext = (idx + nfrags) % CONFIG_PIC32MZ_ETH_NTXDESC;
@@ -3575,13 +3555,6 @@ static inline int pic32mz_ethinitialize(int intf)
   priv->pd_dev.ops = &g_pic32mz_ops;
   nxmutex_init(&priv->pd_lock);
 
-  /* The TX quota is the number of TX descriptors: a packet is held by the
-   * driver until its descriptor is reclaimed.  The RX packets are handed
-   * over to the network stack as soon as they are copied.
-   */
-
-  priv->pd_dev.quota[NETPKT_TX] = CONFIG_PIC32MZ_ETH_NTXDESC;
-  priv->pd_dev.quota[NETPKT_RX] = CONFIG_PIC32MZ_ETH_NRXDESC;
   priv->pd_dev.rxtype           = NETDEV_RX_WORK;
   priv->pd_dev.priority         = ETHWORK;
 
diff --git a/arch/mips/src/pic32mz/pic32mz_w1_wlan.c 
b/arch/mips/src/pic32mz/pic32mz_w1_wlan.c
index b1b2403b653..9bfb3f6958d 100644
--- a/arch/mips/src/pic32mz/pic32mz_w1_wlan.c
+++ b/arch/mips/src/pic32mz/pic32mz_w1_wlan.c
@@ -201,9 +201,6 @@
 #define WLAN_SCAN_BUFSIZE       2048
 #define WLAN_SCAN_TIMEOUT       SEC2TICK(10)
 
-#define WLAN_RX_QUOTA           8
-#define WLAN_TX_QUOTA           16
-
 #define WLAN_CRYPTO_DEFER_MAX   8
 
 #define IW_EVENT_SIZE(field) \
@@ -957,7 +954,7 @@ static int wlan_transmit(FAR struct netdev_lowerhalf_s *dev,
 
   netpkt_copyout(dev, buf + WLAN_TX_HDROFFSET, pkt, len, 0);
 
-  /* The packet is kept (and so its TX quota) until the library frees the
+  /* The packet is kept until the library frees the
    * buffer, see DRV_PIC32MZW_MemFree().  This bounds the frames queued in
    * the library, which would otherwise be limited by the heap only.
    */
@@ -1815,8 +1812,6 @@ int pic32mz_wlan_initialize(void)
   memcpy(dev->netdev.d_mac.ether.ether_addr_octet, g_wlan.mac, 6);
   dev->ops                = &g_wlan_ops;
   dev->iw_ops             = &g_wlan_iw_ops;
-  dev->quota[NETPKT_RX]   = WLAN_RX_QUOTA;
-  dev->quota[NETPKT_TX]   = WLAN_TX_QUOTA;
   dev->rxtype             = NETDEV_RX_THREAD;
   dev->priority           = CONFIG_PIC32MZ_W1_WLAN_PRIORITY;
 
diff --git a/arch/risc-v/src/common/espressif/esp_emac.c 
b/arch/risc-v/src/common/espressif/esp_emac.c
index c97bad3812a..a00662f094a 100644
--- a/arch/risc-v/src/common/espressif/esp_emac.c
+++ b/arch/risc-v/src/common/espressif/esp_emac.c
@@ -637,7 +637,6 @@ int esp_emac_init(void)
   struct esp_emac_s *priv = &g_esp_emac;
   esp_eth_mac_t *mac = NULL;
   esp_eth_phy_t *phy = NULL;
-  unsigned int quota;
   uint8_t mac_addr[6];
   esp_err_t err;
   int ret;
@@ -746,18 +745,6 @@ int esp_emac_init(void)
   memcpy(priv->dev.netdev.d_mac.ether.ether_addr_octet, mac_addr, 6);
   priv->dev.ops = &g_emac_ops;
 
-  /* Keep quotas well below the global netpkt pool size so lower-half
-   * registration remains valid across different board configurations.
-   */
-
-  quota = NETPKT_BUFNUM / 4;
-  if (quota == 0)
-    {
-      quota = 1;
-    }
-
-  priv->dev.quota[NETPKT_RX] = quota;
-  priv->dev.quota[NETPKT_TX] = quota;
   priv->dev.rxtype = NETDEV_RX_WORK;
   priv->dev.priority = LPWORK;
 
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 9354cb69df6..d14e82822c4 100644
--- a/arch/risc-v/src/common/espressif/esp_wlan_netdev.c
+++ b/arch/risc-v/src/common/espressif/esp_wlan_netdev.c
@@ -1208,8 +1208,6 @@ static int esp_wlan_initialize(uint32_t mode)
 
   /* Set the number of RX and TX buffers. */
 
-  priv->dev.quota[NETPKT_RX] = RX_BUF_COUNT;
-  priv->dev.quota[NETPKT_TX] = TX_BUF_COUNT;
   priv->dev.rxtype           = NETDEV_RX_THREAD;
   priv->dev.priority         = 100;
 
diff --git a/arch/risc-v/src/gd32vw55x/gdwifi/gdwifi_netdev.c 
b/arch/risc-v/src/gd32vw55x/gdwifi/gdwifi_netdev.c
index df7fb4299d5..4a21582f47e 100644
--- a/arch/risc-v/src/gd32vw55x/gdwifi/gdwifi_netdev.c
+++ b/arch/risc-v/src/gd32vw55x/gdwifi/gdwifi_netdev.c
@@ -996,8 +996,6 @@ int gdwifi_netdev_register(const uint8_t *mac)
 
   priv->dev.ops      = &g_netdev_ops;
   priv->dev.iw_ops   = &g_wireless_ops;
-  priv->dev.quota[NETPKT_RX] = 8;
-  priv->dev.quota[NETPKT_TX] = 4;
   priv->dev.rxtype   = NETDEV_RX_WORK;   /* Process RX in the work queue */
 
   /* This is NOT a task priority: netdev_lowerhalf uses it as the work
diff --git a/arch/risc-v/src/mpfs/mpfs_can.c b/arch/risc-v/src/mpfs/mpfs_can.c
index 931b64e5343..c6ca110ec06 100644
--- a/arch/risc-v/src/mpfs/mpfs_can.c
+++ b/arch/risc-v/src/mpfs/mpfs_can.c
@@ -2508,11 +2508,6 @@ int mpfs_can_init(int ncan, uint32_t bitrate)
   dev = &priv->dev;
   dev->ops = &g_netdev_ops;  /* Lower-half operations */
 
-  /* Set quotas for TX/RX buffers */
-
-  dev->quota[NETPKT_TX] = CAN_TX_BUFFER;
-  dev->quota[NETPKT_RX] = CAN_RX_BUFFER;
-
   ninfo("CAN driver init done for CAN controller %d\n", ncan);
 
   /* Put the interface in the down state */
diff --git a/arch/sim/src/sim/sim_netdriver.c b/arch/sim/src/sim/sim_netdriver.c
index ee8310c7f02..19041aca357 100644
--- a/arch/sim/src/sim/sim_netdriver.c
+++ b/arch/sim/src/sim/sim_netdriver.c
@@ -180,7 +180,6 @@ static int netdriver_send(struct netdev_lowerhalf_s *dev, 
netpkt_t *pkt)
 
       clock_gettime(CLOCK_REALTIME, &pkt->io_time);
       iob_add_queue(pkt, &priv->tstampq);
-      atomic_add(&dev->quota_ptr[NETPKT_TX], 1);
       netdev_lower_rxready(dev);
       return OK;
     }
@@ -209,7 +208,6 @@ static netpkt_t *netdriver_recv(struct netdev_lowerhalf_s 
*dev)
       netdev_unlock(&dev->netdev);
       if (pkt != NULL)
         {
-          atomic_sub(&dev->quota_ptr[NETPKT_RX], 1);
           return pkt;
         }
     }
@@ -365,11 +363,7 @@ int sim_netdriver_init(void)
                       netdriver_txdone_interrupt,
                       netdriver_rxready_interrupt);
 
-      /* 1TX + 1RX is enough for sim. */
-
-      dev->quota[NETPKT_TX] = 1;
-      dev->quota[NETPKT_RX] = 1;
-      dev->ops              = &g_ops;
+      dev->ops = &g_ops;
 
 #if CONFIG_SIM_WIFIDEV_NUMBER != 0
       if (devidx < CONFIG_SIM_WIFIDEV_NUMBER)
diff --git a/arch/xtensa/src/common/espressif/esp_openeth.c 
b/arch/xtensa/src/common/espressif/esp_openeth.c
index 891174dfa91..27c32a207ca 100644
--- a/arch/xtensa/src/common/espressif/esp_openeth.c
+++ b/arch/xtensa/src/common/espressif/esp_openeth.c
@@ -500,8 +500,6 @@ int esp_openeth_initialize(void)
 
   dev->ops = &g_ops;
 
-  dev->quota[NETPKT_TX] = TX_BUF_COUNT;
-  dev->quota[NETPKT_RX] = RX_BUF_COUNT;
   dev->rxtype           = NETDEV_RX_THREAD;
   dev->priority         = 100;
 
diff --git a/arch/xtensa/src/common/espressif/esp_wlan_netdev.c 
b/arch/xtensa/src/common/espressif/esp_wlan_netdev.c
index 621790bcaf9..753e9f55ba7 100644
--- a/arch/xtensa/src/common/espressif/esp_wlan_netdev.c
+++ b/arch/xtensa/src/common/espressif/esp_wlan_netdev.c
@@ -1211,8 +1211,6 @@ static int esp_wlan_initialize(uint32_t mode)
 
   /* Set the number of RX and TX buffers. */
 
-  priv->dev.quota[NETPKT_RX] = RX_BUF_COUNT;
-  priv->dev.quota[NETPKT_TX] = TX_BUF_COUNT;
   priv->dev.rxtype           = NETDEV_RX_THREAD;
   priv->dev.priority         = 100;
 
diff --git a/drivers/can/ctucanfd_pci.c b/drivers/can/ctucanfd_pci.c
index 3e2d34e4c15..3ca12f71e21 100644
--- a/drivers/can/ctucanfd_pci.c
+++ b/drivers/can/ctucanfd_pci.c
@@ -82,14 +82,6 @@
 
 /* SocketCAN specific */
 
-#ifdef CONFIG_CAN_CTUCANFD_SOCKET
-#  define CTUCANFD_TX_QUOTA   CTUCANFD_TXBUF_CNT
-#  define CTUCANFD_RX_QUOTA   1
-#  if CONFIG_IOB_NBUFFERS < (CTUCANFD_RX_QUOTA + CTUCANFD_TX_QUOTA)
-#    error CONFIG_IOB_NBUFFERS must be > (CTUCANFD_RX_QUOTA + 
CTUCANFD_TX_QUOTA)
-#  endif
-#endif /* CONFIG_CAN_CTUCANFD_SOCKET */
-
 #ifndef CONFIG_NET_CAN_ERRORS
 #  define CTUCANFD_SOCK_RXINT (CTUCANFD_INT_RBNEI)
 #else
@@ -1923,8 +1915,6 @@ static int ctucanfd_probe(FAR struct pci_device_s *dev)
 
       /* Register the network device */
 
-      netdev->quota[NETPKT_TX] = CTUCANFD_TX_QUOTA;
-      netdev->quota[NETPKT_RX] = CTUCANFD_RX_QUOTA;
       netdev->ops = &g_ctucanfd_net_ops;
 
       /* Register the network interface. */
@@ -2065,9 +2055,7 @@ int ctucanfd_register(uintptr_t base, int irq, uint32_t 
id)
 #endif
 
 #ifdef CONFIG_CAN_CTUCANFD_SOCKET
-  dev->dev.quota[NETPKT_TX] = CTUCANFD_TX_QUOTA;
-  dev->dev.quota[NETPKT_RX] = CTUCANFD_RX_QUOTA;
-  dev->dev.ops              = &g_ctucanfd_net_ops;
+  dev->dev.ops = &g_ctucanfd_net_ops;
 
   snprintf(dev->dev.netdev.d_ifname, IFNAMSIZ, "can%" PRIu32, id);
 
diff --git a/drivers/can/kvaser_pci.c b/drivers/can/kvaser_pci.c
index e4836a2e132..324c26d5b37 100644
--- a/drivers/can/kvaser_pci.c
+++ b/drivers/can/kvaser_pci.c
@@ -86,16 +86,6 @@
 
 /* SocketCAN specific */
 
-#ifdef CONFIG_CAN_KVASER_SOCKET
-#  define KVASER_TX_QUOTA              1
-#  define KVASER_RX_QUOTA              1
-
-#  if CONFIG_IOB_NBUFFERS < (KVASER_RX_QUOTA + KVASER_TX_QUOTA)
-#    error CONFIG_IOB_NBUFFERS must be > (KVASER_RX_QUOTA + KVASER_TX_QUOTA)
-#  endif
-
-#endif /* CONFIG_CAN_KVASER_SOCKET */
-
 #ifndef CONFIG_NET_CAN_ERRORS
 #  define KVASER_SOCK_RXINT            (SJA1000_RX_INT_ST)
 #else
@@ -1694,8 +1684,6 @@ static int kvaser_probe(FAR struct pci_device_s *dev)
 
       /* Register the network device */
 
-      netdev->quota[NETPKT_TX] = KVASER_TX_QUOTA;
-      netdev->quota[NETPKT_RX] = KVASER_RX_QUOTA;
       netdev->ops = &g_kvaser_net_ops;
 
       /* Register the network interface. */
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index d65beb42eea..d92c6062e36 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -790,10 +790,6 @@ config NET_E1000_RXDESC
        int "Intel E1000 RX descriptors"
        default 256
 
-config NET_E1000_RXSPARE
-       int "Intel E1000 spare RX buffers"
-       default 8
-
 endif # NET_E1000
 
 menuconfig NET_IGB
@@ -813,10 +809,6 @@ config NET_IGB_RXDESC
        int "Intel IGB RX descriptors"
        default 256
 
-config NET_IGB_RXSPARE
-       int "Intel IGB spare RX buffers"
-       default 8
-
 config NET_IGB_INT_INTERVAL
        int "Intel IGB interrupt interval"
        default 100
@@ -843,10 +835,6 @@ config NET_IGC_RXDESC
        int "Intel IGC RX descriptors"
        default 256
 
-config NET_IGC_RXSPARE
-       int "Intel IGC spare RX buffers"
-       default 8
-
 config NET_IGC_INT_INTERVAL
        int "Intel IGC interrupt interval"
        default 100
diff --git a/drivers/net/bridge.c b/drivers/net/bridge.c
index 1a00fb28415..1bda982e498 100644
--- a/drivers/net/bridge.c
+++ b/drivers/net/bridge.c
@@ -350,45 +350,6 @@ static void bridge_fdb_learn(FAR struct bridge_s *br,
   victim->fdb_time = now;
 }
 
-/****************************************************************************
- * Name: bridge_update_quota
- *
- * Description:
- *   The bridge device can send as many packets as the port with the least
- *   room.  Publish that number as the TX quota of the bridge device, so
- *   that the network stack stops polling the device when a port is full,
- *   and resumes when bridge_txdone() is called.
- *
- * Assumptions:
- *   Called with br_lock held.
- *
- ****************************************************************************/
-
-static void bridge_update_quota(FAR struct bridge_s *br)
-{
-  int quota = INT_MAX;
-  int i;
-
-  for (i = 0; i < CONFIG_NET_BRIDGE_MAX_PORTS; i++)
-    {
-      FAR struct netdev_lowerhalf_s *dev = br->br_ports[i].bp_dev;
-      int avail;
-
-      if (dev == NULL)
-        {
-          break;
-        }
-
-      avail = atomic_read(&dev->quota_ptr[NETPKT_TX]);
-      if (avail < quota)
-        {
-          quota = avail;
-        }
-    }
-
-  atomic_set(&br->br_dev.quota_ptr[NETPKT_TX], quota == INT_MAX ? 0 : quota);
-}
-
 /****************************************************************************
  * Name: bridge_clone
  *
@@ -457,17 +418,6 @@ static int bridge_port_send(FAR struct bridge_port_s *port,
       return -EMSGSIZE;
     }
 
-  /* 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)
-    {
-      atomic_add(&dev->quota_ptr[NETPKT_TX], 1);
-      return -EBUSY;
-    }
-
   /* The transmit operation of the port is also reached under the device
    * lock of the port, by the upper half serving the local host, and a port
    * driver may count on that lock to serialize its transmit state.  Waiting
@@ -478,7 +428,6 @@ static int bridge_port_send(FAR struct bridge_port_s *port,
 
   if (netdev_trylock(&dev->netdev) < 0)
     {
-      atomic_add(&dev->quota_ptr[NETPKT_TX], 1);
       return -EBUSY;
     }
 
@@ -486,11 +435,6 @@ static int bridge_port_send(FAR struct bridge_port_s *port,
   ret = dev->ops->transmit(dev, pkt);
   netdev_unlock(&dev->netdev);
 
-  if (ret < 0)
-    {
-      atomic_add(&dev->quota_ptr[NETPKT_TX], 1);
-    }
-
   return ret;
 }
 
@@ -673,9 +617,6 @@ static int bridge_transmit(FAR struct netdev_lowerhalf_s 
*dev,
       iob_free_chain(pkt);
     }
 
-  /* The quota of the bridge now follows the ports */
-
-  bridge_update_quota(br);
   nxmutex_unlock(&br->br_lock);
   return ret;
 }
@@ -896,7 +837,6 @@ static void bridge_delport(FAR struct bridge_port_s *port)
       last->bp_dev = NULL;
     }
 
-  bridge_update_quota(br);
   nxmutex_unlock(&br->br_lock);
 
   if (moved != NULL)
@@ -1106,7 +1046,6 @@ static int bridge_addif(FAR const struct ifreq *req)
     }
 
   port->bp_dev = dev;
-  bridge_update_quota(br);
   nxmutex_unlock(&br->br_lock);
 
   bridge_update_pktsize(br);
diff --git a/drivers/net/e1000.c b/drivers/net/e1000.c
index 7f6c0276f23..35323f24cb8 100644
--- a/drivers/net/e1000.c
+++ b/drivers/net/e1000.c
@@ -66,22 +66,8 @@
 #define E1000_TX_DESC           CONFIG_NET_E1000_TXDESC
 #define E1000_RX_DESC           CONFIG_NET_E1000_RXDESC
 
-/* After RX packet is done, we provide free netpkt to the RX descriptor ring.
- * The upper-half network logic is responsible for freeing the RX packets
- * so we need some additional spare netpkt buffers to assure that it's
- * always possible to allocate the new RX packet in the receiver logic.
- * It's hard to tell how many spare buffers is needed, for now it's set to 8.
- */
-
-#define E1000_TX_QUOTA        E1000_TX_DESC
-#define E1000_RX_QUOTA        (E1000_RX_DESC + CONFIG_NET_E1000_RXSPARE)
-
 /* NOTE: CONFIG_IOB_ALIGNMENT must match system D-CACHE line size */
 
-#if CONFIG_IOB_NBUFFERS < (E1000_RX_QUOTA + E1000_TX_QUOTA)
-#  error CONFIG_IOB_NBUFFERS must be > (E1000_RX_QUOTA + E1000_TX_QUOTA)
-#endif
-
 #if CONFIG_IOB_BUFSIZE < E1000_PKTBUF_SIZE
 #  error CONFIG_IOB_BUFSIZE must be > E1000_PKTBUF_SIZE
 #endif
@@ -1604,8 +1590,6 @@ static int e1000_probe(FAR struct pci_device_s *dev)
 
   /* Register the network device */
 
-  netdev->quota[NETPKT_TX] = E1000_TX_QUOTA;
-  netdev->quota[NETPKT_RX] = E1000_RX_QUOTA;
   netdev->ops = &g_e1000_ops;
 
   return netdev_lower_register(netdev, NET_LL_ETHERNET);
diff --git a/drivers/net/igb.c b/drivers/net/igb.c
index 0392abd317a..d346d9ac57e 100644
--- a/drivers/net/igb.c
+++ b/drivers/net/igb.c
@@ -67,22 +67,8 @@
 #define IGB_TX_DESC            CONFIG_NET_IGB_TXDESC
 #define IGB_RX_DESC            CONFIG_NET_IGB_RXDESC
 
-/* After RX packet is done, we provide free netpkt to the RX descriptor ring.
- * The upper-half network logic is responsible for freeing the RX packets
- * so we need some additional spare netpkt buffers to assure that it's
- * always possible to allocate the new RX packet in the receiver logic.
- * It's hard to tell how many spare buffers is needed, for now it's set to 8.
- */
-
-#define IGB_TX_QUOTA           IGB_TX_DESC
-#define IGB_RX_QUOTA           (IGB_RX_DESC + CONFIG_NET_IGB_RXSPARE)
-
 /* NOTE: CONFIG_IOB_ALIGNMENT must match system D-CACHE line size */
 
-#if CONFIG_IOB_NBUFFERS < IGB_RX_QUOTA + IGB_TX_QUOTA
-#  error CONFIG_IOB_NBUFFERS must be > (IGB_RX_QUOTA + IGB_TX_QUOTA)
-#endif
-
 #if CONFIG_IOB_BUFSIZE < IGB_PKTBUF_SIZE
 #  error CONFIG_IOB_BUFSIZE must be > IGB_PKTBUF_SIZE
 #endif
@@ -1576,8 +1562,6 @@ static int igb_probe(FAR struct pci_device_s *dev)
 
   /* Register the network device */
 
-  netdev->quota[NETPKT_TX] = IGB_TX_QUOTA;
-  netdev->quota[NETPKT_RX] = IGB_RX_QUOTA;
   netdev->ops = &g_igb_ops;
 
   return netdev_lower_register(netdev, NET_LL_ETHERNET);
diff --git a/drivers/net/igc.c b/drivers/net/igc.c
index cf3bf9af0c2..d2fc30ef887 100644
--- a/drivers/net/igc.c
+++ b/drivers/net/igc.c
@@ -66,22 +66,8 @@
 #define IGC_TX_DESC            CONFIG_NET_IGC_TXDESC
 #define IGC_RX_DESC            CONFIG_NET_IGC_RXDESC
 
-/* After RX packet is done, we provide free netpkt to the RX descriptor ring.
- * The upper-half network logic is responsible for freeing the RX packets
- * so we need some additional spare netpkt buffers to assure that it's
- * always possible to allocate the new RX packet in the receiver logic.
- * It's hard to tell how many spare buffers is needed, for now it's set to 8.
- */
-
-#define IGC_TX_QUOTA           IGC_TX_DESC
-#define IGC_RX_QUOTA           (IGC_RX_DESC + CONFIG_NET_IGC_RXSPARE)
-
 /* NOTE: CONFIG_IOB_ALIGNMENT must match system D-CACHE line size */
 
-#if CONFIG_IOB_NBUFFERS < IGC_RX_QUOTA + IGC_TX_QUOTA
-#  error CONFIG_IOB_NBUFFERS must be > (IGC_RX_QUOTA + IGC_TX_QUOTA)
-#endif
-
 #if CONFIG_IOB_BUFSIZE < IGC_PKTBUF_SIZE
 #  error CONFIG_IOB_BUFSIZE must be > IGC_PKTBUF_SIZE
 #endif
@@ -1485,8 +1471,6 @@ static int igc_probe(FAR struct pci_device_s *dev)
 
   /* Register the network device */
 
-  netdev->quota[NETPKT_TX] = IGC_TX_QUOTA;
-  netdev->quota[NETPKT_RX] = IGC_RX_QUOTA;
   netdev->ops = &g_igc_ops;
 
   return netdev_lower_register(netdev, NET_LL_ETHERNET);
diff --git a/drivers/net/netdev_upperhalf.c b/drivers/net/netdev_upperhalf.c
index f402e8ea721..25d2ab14b08 100644
--- a/drivers/net/netdev_upperhalf.c
+++ b/drivers/net/netdev_upperhalf.c
@@ -32,6 +32,7 @@
 #include <stdio.h>
 #include <string.h>
 
+#include <nuttx/atomic.h>
 #include <nuttx/kmalloc.h>
 #include <nuttx/kthread.h>
 #include <nuttx/mm/iob.h>
@@ -105,6 +106,15 @@ struct netdev_upperhalf_s
 
   int txing;
 
+  /* TX completion flag (0/1), raised by netdev_lower_txdone() (possibly
+   * from an ISR or another CPU) and consumed by the TX loop.  Both sides
+   * must use atomic_xchg(): read-modify-writes on one location are totally
+   * ordered, so the two sides cannot miss each other and strand a
+   * re-queued packet.
+   */
+
+  atomic_t txdone;
+
   /* Deferring process to work queue or thread */
 
   union
@@ -124,40 +134,6 @@ static int netdev_upper_txavail(FAR struct net_driver_s 
*dev);
  * Private Functions
  ****************************************************************************/
 
-/****************************************************************************
- * Name: quota_is_valid
- *
- * Description:
- *   Check if the quota of the lower half is not too big.
- *
- ****************************************************************************/
-
-static bool quota_is_valid(FAR struct netdev_lowerhalf_s *lower)
-{
-  int total = 0;
-  enum netpkt_type_e type;
-
-  for (type = NETPKT_TX; type < NETPKT_TYPENUM; type++)
-    {
-      total += netdev_lower_quota_load(lower, type);
-    }
-
-  if (total > NETPKT_BUFNUM)
-    {
-      nerr("ERROR: Too big quota when registering device: %d\n", total);
-      return false;
-    }
-
-  if (total > NETPKT_BUFNUM / 2)
-    {
-      nwarn("WARNING: The quota of the registering device may consume more "
-            "than half of the network buffers, which may hurt performance. "
-            "Please consider decreasing driver quota or increasing nIOB.\n");
-    }
-
-  return true;
-}
-
 /****************************************************************************
  * Name: netpkt_get
  *
@@ -172,26 +148,14 @@ static bool quota_is_valid(FAR struct netdev_lowerhalf_s 
*lower)
 static FAR netpkt_t *netpkt_get(FAR struct net_driver_s *dev,
                                 enum netpkt_type_e type)
 {
-  FAR struct netdev_upperhalf_s *upper;
   FAR netpkt_t *pkt;
 
   DEBUGASSERT(dev && dev->d_iob);
 
-  upper = (FAR struct netdev_upperhalf_s *)dev->d_private;
   pkt = dev->d_iob;
 
   netdev_iob_clear(dev);
 
-  /* Do not limit quota here (simply relay iob instead of dropping), most
-   * cases will be limited by netdev_upper_can_tx and seldom reaches here.
-   */
-
-  if (atomic_sub(&upper->lower->quota_ptr[type], 1) <= 0)
-    {
-      nwarn("WARNING: Allowing temporarily exceeding quota of %s.\n",
-            dev->d_ifname);
-    }
-
   return pkt;
 }
 
@@ -209,11 +173,7 @@ static FAR netpkt_t *netpkt_get(FAR struct net_driver_s 
*dev,
 static void netpkt_put(FAR struct net_driver_s *dev, FAR netpkt_t *pkt,
                        enum netpkt_type_e type)
 {
-  FAR struct netdev_upperhalf_s *upper = dev->d_private;
-
   DEBUGASSERT(dev && pkt);
-
-  atomic_add(&upper->lower->quota_ptr[type], 1);
   netdev_iob_replace_l2(dev, pkt);
 }
 
@@ -247,30 +207,6 @@ netdev_upper_alloc(FAR struct netdev_lowerhalf_s *dev, 
size_t extra_size)
   return upper;
 }
 
-/****************************************************************************
- * Name: netdev_upper_can_tx
- *
- * Description:
- *   Check if we allow tx on this device.
- *
- * Assumptions:
- *   Called with the network locked.
- *
- ****************************************************************************/
-
-static inline bool netdev_upper_can_tx(FAR struct netdev_upperhalf_s *upper)
-{
-  FAR struct netdev_lowerhalf_s *lower = upper->lower;
-
-  if (netdev_lower_quota_load(lower, NETPKT_TX) <= 0)
-    {
-      lower->txdone = true;
-      return false;
-    }
-
-  return true;
-}
-
 /****************************************************************************
  * Name: netdev_upper_txpoll
  *
@@ -333,25 +269,22 @@ static int netdev_upper_txpoll(FAR struct net_driver_s 
*dev)
   if (ret == -EBUSY)
     {
       /* Transient error -- re-queue to txq head for retry.  Head-insert
-       * preserves packet ordering.  The retry will be driven by the
-       * txdone callback from the lower half driver.
+       * preserves packet ordering.  Returning the error breaks the TX
+       * loop, and netdev_lower_txdone() drives the retry.
        *
-       * Note: We manually restore quota instead of using netpkt_put()
-       * because the pkt is moved to txq, not back to dev->d_iob.
-       * After netpkt_get(), dev->d_iob is already NULL.
+       * Note: After netpkt_get(), dev->d_iob is already NULL.
        */
 
-      nwarn("WARNING: Transmit busy (%d), re-queue pkt\n", ret);
+      ninfo("Transmit busy (%d), re-queue pkt\n", ret);
       iob_add_queue_head(pkt, &upper->txq);
-      atomic_add(&upper->lower->quota_ptr[NETPKT_TX], 1);
       return ret;
     }
 
   nerr("ERROR: Transmit failed: %d, dropping pkt\n", ret);
 
   /* 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.
+   * netpkt_put() places pkt back into dev->d_iob so the caller can
+   * release it.
    */
 
 drop:
@@ -431,8 +364,19 @@ static void netdev_upper_txavail_work(FAR struct 
netdev_upperhalf_s *upper)
     {
       DEBUGASSERT(dev->d_buf == NULL); /* Make sure: IOB only. */
       upper->txing = true;
-      while (netdev_upper_can_tx(upper) &&
-             netdev_upper_tx(dev) == NETDEV_TX_CONTINUE);
+
+      /* Clear the flag before the attempts, then run another round for
+       * every completion that landed while we were transmitting.
+       */
+
+      atomic_xchg(&upper->txdone, 0);
+
+      do
+        {
+          while (netdev_upper_tx(dev) == NETDEV_TX_CONTINUE);
+        }
+      while (atomic_xchg(&upper->txdone, 0) != 0);
+
       upper->txing = false;
     }
 
@@ -891,7 +835,7 @@ static void netdev_upper_work(FAR void *arg)
 {
   FAR struct netdev_upperhalf_s *upper = arg;
 
-  /* RX may release quota and driver buffer, so do RX first. */
+  /* RX path may release driver-side resources, so do RX first. */
 
   netdev_upper_rxpoll_work(upper);
   netdev_upper_txavail_work(upper);
@@ -1483,6 +1427,7 @@ static int netdev_upper_ifdown(FAR struct net_driver_s 
*dev)
   /* Drain the TX queue before tearing down the interface. */
 
   iob_free_queue(&upper->txq);
+  atomic_set(&upper->txdone, 0);
 
   switch (upper->lower->rxtype)
     {
@@ -1627,16 +1572,6 @@ int netdev_lower_register(FAR struct netdev_lowerhalf_s 
*dev,
       return -EINVAL;
     }
 
-  if (dev->quota_ptr == NULL)
-    {
-      dev->quota_ptr = dev->quota;
-    }
-
-  if (quota_is_valid(dev) == false)
-    {
-      return -EINVAL;
-    }
-
   switch (dev->rxtype)
     {
       case NETDEV_RX_WORK:
@@ -1868,19 +1803,24 @@ void netdev_lower_txdone(FAR struct netdev_lowerhalf_s 
*dev)
 {
   FAR struct netdev_upperhalf_s *upper = dev->netdev.d_private;
 
-  if (dev->txdone || !IOB_QEMPTY(&upper->txq))
-    {
-      dev->txdone = false;
-
 #ifdef CONFIG_NET_BRIDGE
-      /* The bridge device may wait for room on its ports */
+  /* The bridge device may wait for room on its ports */
 
-      if (upper->bridge != NULL)
-        {
-          bridge_txdone(upper->bridge);
-        }
+  if (upper->bridge != NULL)
+    {
+      bridge_txdone(upper->bridge);
+    }
 #endif
 
+  /* Record the completion before looking at txq: both sides do a read-modify
+   * -write on this location, and those are totally ordered, so the TX loop
+   * cannot miss a completion and strand a re-queued packet.
+   */
+
+  atomic_xchg(&upper->txdone, 1);
+
+  if (!IOB_QEMPTY(&upper->txq))
+    {
       if (dev->rxtype == NETDEV_RX_DIRECT)
         {
 #ifdef CONFIG_NET_VLAN
@@ -2104,12 +2044,6 @@ FAR netpkt_t *netpkt_alloc(FAR struct netdev_lowerhalf_s 
*dev,
 {
   FAR netpkt_t *pkt;
 
-  if (atomic_sub(&dev->quota_ptr[type], 1) <= 0)
-    {
-      atomic_add(&dev->quota_ptr[type], 1);
-      return NULL;
-    }
-
 #ifdef CONFIG_NET_CAN
   if (dev->netdev.d_lltype == NET_LL_CAN)
     {
@@ -2123,7 +2057,6 @@ FAR netpkt_t *netpkt_alloc(FAR struct netdev_lowerhalf_s 
*dev,
 
   if (pkt == NULL)
     {
-      atomic_add(&dev->quota_ptr[type], 1);
       return NULL;
     }
 
@@ -2147,7 +2080,6 @@ FAR netpkt_t *netpkt_alloc(FAR struct netdev_lowerhalf_s 
*dev,
 void netpkt_free(FAR struct netdev_lowerhalf_s *dev, FAR netpkt_t *pkt,
                  enum netpkt_type_e type)
 {
-  atomic_add(&dev->quota_ptr[type], 1);
   iob_free_chain(pkt);
 }
 
diff --git a/drivers/net/oa_tc6/oa_tc6.c b/drivers/net/oa_tc6/oa_tc6.c
index 85fb0594e44..b7b150b5684 100644
--- a/drivers/net/oa_tc6/oa_tc6.c
+++ b/drivers/net/oa_tc6/oa_tc6.c
@@ -59,15 +59,6 @@
 
 /* Packet Memory ************************************************************/
 
-/* Maximum number of allocated TX and RX netpackets */
-
-#define OA_TC6_TX_QUOTA 1
-#define OA_TC6_RX_QUOTA 2
-
-#if CONFIG_IOB_NBUFFERS < (OA_TC6_TX_QUOTA + OA_TC6_RX_QUOTA)
-#  error "CONFIG_IOB_NBUFFERS must be > (OA_TC6_TX_QUOTA + OA_TC6_RX_QUOTA)"
-#endif
-
 #ifndef CONFIG_SCHED_LPWORK
 #  error "CONFIG_SCHED_LPWORK is needed by the OA-TC6 driver"
 #endif
@@ -1668,7 +1659,7 @@ static int oa_tc6_transmit(FAR struct netdev_lowerhalf_s 
*dev,
        */
 
       nxmutex_unlock(&priv->lock);
-      return -EAGAIN;
+      return -EBUSY;
     }
 
   priv->tx_pkt_idx = 0;
@@ -2142,8 +2133,6 @@ int oa_tc6_common_init(FAR struct oa_tc6_driver_s *priv,
   /* Fill the fields for the netdev upperhalf driver */
 
   netdev = &priv->dev;
-  netdev->quota[NETPKT_TX] = OA_TC6_TX_QUOTA;
-  netdev->quota[NETPKT_RX] = OA_TC6_RX_QUOTA;
   netdev->ops = &g_oa_tc6_ops;
 
   /* Allocate SPI buffers based on the config */
diff --git a/drivers/net/rpmsgdrv.c b/drivers/net/rpmsgdrv.c
index 666cc542902..6a36b8d4ffe 100644
--- a/drivers/net/rpmsgdrv.c
+++ b/drivers/net/rpmsgdrv.c
@@ -469,8 +469,10 @@ static int net_rpmsg_drv_transfer_handler(FAR struct 
rpmsg_endpoint *ept,
   netdev_lower_rxready(dev);
   return 0;
 
+#ifndef CONFIG_NET_PRMSG_DRV_ZERO_COPY_TRANSFER
 free:
   netpkt_free(dev, pkt, NETPKT_RX);
+#endif
 
 drop:
   NETDEV_RXDROPPED(&dev->netdev);
@@ -929,9 +931,7 @@ net_rpmsg_drv_alloc(FAR const char *devname, enum 
net_lltype_e lltype)
     }
 
   netdev = &drv->dev;
-  netdev->quota[NETPKT_RX] = CONFIG_IOB_NBUFFERS /
-                             NET_RPMSG_DRV_MAX_NIOB / 4;
-  netdev->quota[NETPKT_TX] = 1;
+
   netdev->ops = &g_net_rpmsg_drv_ops;
 
   drv->ept.priv = drv;
diff --git a/drivers/net/vlan.c b/drivers/net/vlan.c
index 31931b505b1..c7825790b29 100644
--- a/drivers/net/vlan.c
+++ b/drivers/net/vlan.c
@@ -338,13 +338,12 @@ int vlan_register(FAR struct netdev_lowerhalf_s *real, 
uint16_t vid,
   /* Init the VLAN device */
 
   spin_lock_init(&vlan->rxlock);
-  vlan->tci           = (vid & VLAN_VID_MASK) |
-                        ((prio << VLAN_PRIO_SHIFT) & VLAN_PRIO_MASK);
-  vlan->real          = real;
-  vlan->dev.quota_ptr = real->quota_ptr;
-  vlan->dev.rxtype    = real->rxtype;
-  vlan->dev.priority  = real->priority;
-  vlan->dev.ops       = &g_vlan_ops;
+  vlan->tci          = (vid & VLAN_VID_MASK) |
+                       ((prio << VLAN_PRIO_SHIFT) & VLAN_PRIO_MASK);
+  vlan->real         = real;
+  vlan->dev.rxtype   = real->rxtype;
+  vlan->dev.priority = real->priority;
+  vlan->dev.ops      = &g_vlan_ops;
 
   /* Copy MTU from the real device */
 
diff --git a/drivers/usbdev/Kconfig b/drivers/usbdev/Kconfig
index f270cab5a38..cc16b5c412a 100644
--- a/drivers/usbdev/Kconfig
+++ b/drivers/usbdev/Kconfig
@@ -1821,14 +1821,6 @@ endif # NET_CDCMBIM
 
 endif # !CDCNCM_COMPOSITE
 
-config CDCNCM_QUOTA_TX
-       int "The drive holds the maximum quota of TX"
-       default 8
-
-config CDCNCM_QUOTA_RX
-       int "The drive holds the maximum quota of RX"
-       default 8
-
 endif # CDCNCM
 
 config USBDEV_FS
diff --git a/drivers/usbdev/cdcncm.c b/drivers/usbdev/cdcncm.c
index 09b737bc699..895c1f3fb8b 100644
--- a/drivers/usbdev/cdcncm.c
+++ b/drivers/usbdev/cdcncm.c
@@ -2966,9 +2966,7 @@ static int cdcncm_classobject(int minor,
 
   /* Network device initialization */
 
-  self->dev.ops              = &g_netops;
-  self->dev.quota[NETPKT_TX] = CONFIG_CDCNCM_QUOTA_TX;
-  self->dev.quota[NETPKT_RX] = CONFIG_CDCNCM_QUOTA_RX;
+  self->dev.ops = &g_netops;
 
   /* USB device initialization */
 
@@ -3043,9 +3041,7 @@ static int cdcmbim_classobject(int minor,
 
   /* Network device initialization */
 
-  ncm->dev.ops              = &g_netops;
-  ncm->dev.quota[NETPKT_TX] = CONFIG_CDCNCM_QUOTA_TX;
-  ncm->dev.quota[NETPKT_RX] = CONFIG_CDCNCM_QUOTA_RX;
+  ncm->dev.ops = &g_netops;
 
   /* USB device initialization */
 
diff --git a/drivers/usbhost/usbhost_cdcecm.c b/drivers/usbhost/usbhost_cdcecm.c
index f6a4ab27bdf..160d928f1fc 100644
--- a/drivers/usbhost/usbhost_cdcecm.c
+++ b/drivers/usbhost/usbhost_cdcecm.c
@@ -1291,8 +1291,6 @@ static inline int usbhost_devinit(FAR struct 
usbhost_cdcecm_s *priv)
          priv->macaddr, sizeof(priv->macaddr));
 
   dev->ops = &g_cdcecm_netdev_ops;
-  dev->quota[NETPKT_TX] = 1;
-  dev->quota[NETPKT_RX] = 1;
   dev->rxtype           = NETDEV_RX_WORK;
   dev->priority         = LPWORK;
 
diff --git a/drivers/vhost/vhost-net.c b/drivers/vhost/vhost-net.c
index 956a8f31aba..e06a54be560 100644
--- a/drivers/vhost/vhost-net.c
+++ b/drivers/vhost/vhost-net.c
@@ -119,8 +119,9 @@ static inline_function FAR void *vhost_net_map(uint64_t pa,
 
 #define VHOST_NET_F_MAC      5
 
-/* netpkt quota per direction and the longest peer descriptor chain we
- * accept on either ring (Linux commonly splits header and payload).
+/* The number of netpkts per direction and the longest peer descriptor
+ * chain we accept on either ring (Linux commonly splits header and
+ * payload).
  */
 
 #define VHOST_NET_NPKTS      8
@@ -450,8 +451,7 @@ static int vhost_net_ifdown(FAR struct netdev_lowerhalf_s 
*dev)
  *   Fill one peer-posted RX chain with the frame and complete it.
  *   Completion is synchronous: the netpkt is consumed and freed before
  *   returning.  Note that txdone is deliberately not signalled from here,
- *   the upper half continues its poll on a successful transmit and
- *   netpkt_free() already returns the quota.
+ *   the upper half continues its poll on a successful transmit.
  *
  ****************************************************************************/
 
@@ -592,7 +592,7 @@ static FAR netpkt_t *vhost_net_receive(FAR struct 
netdev_lowerhalf_s *dev)
       pkt = netpkt_alloc(dev, NETPKT_RX);
       if (pkt == NULL)
         {
-          /* Out of receive quota: drop the frame, re-arm the peer's
+          /* No netpkt available: drop the frame, re-arm the peer's
            * notifications and stop polling so the stack can release
            * buffers.
            */
@@ -678,8 +678,6 @@ static int vhost_net_probe(FAR struct vhost_device *hdev)
   virtqueue_disable_cb(priv->txq);
   virtqueue_disable_cb(priv->rxq);
 
-  priv->lower.quota[NETPKT_RX] = VHOST_NET_NPKTS;
-  priv->lower.quota[NETPKT_TX] = VHOST_NET_NPKTS;
   priv->lower.ops = &g_vhost_net_ops;
 
   /* transmit() and receive() must not run concurrently: both walk peer
diff --git a/drivers/virtio/virtio-net.c b/drivers/virtio/virtio-net.c
index 7f3b79270e3..932bda0bd61 100644
--- a/drivers/virtio/virtio-net.c
+++ b/drivers/virtio/virtio-net.c
@@ -562,13 +562,6 @@ static int virtio_net_send(FAR struct netdev_lowerhalf_s 
*dev,
 
   virtio_net_txfree(dev);
 
-  /* If we have no buffer left, enable TX done callback. */
-
-  if (netdev_lower_quota_load(dev, NETPKT_TX) <= 0)
-    {
-      virtqueue_enable_cb_lock(vq, &priv->lock[VIRTIO_NET_TX]);
-    }
-
   return OK;
 }
 
@@ -785,8 +778,6 @@ static int virtio_net_probe(FAR struct virtio_device *vdev)
   /* Initialize the netdev lower half */
 
   netdev = (FAR struct netdev_lowerhalf_s *)priv;
-  netdev->quota[NETPKT_RX] = priv->bufnum;
-  netdev->quota[NETPKT_TX] = priv->bufnum;
   netdev->ops = &g_virtio_net_ops;
 
 #ifdef CONFIG_DRIVERS_WIFI_SIM
@@ -872,8 +863,7 @@ static void virtio_net_dump(FAR struct virtio_device *vdev)
          "mac=%02x:%02x:%02x:%02x:%02x:%02x\n",
          dev->d_ifname,
          mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
-  syslog(LOG_EMERG, "    bufnum=%d, iob_free=%d, "
-         "quota: rx=%" PRId32 " tx=%" PRId32
+  syslog(LOG_EMERG, "    bufnum=%d, iob_free=%d"
 #ifdef CONFIG_NET_IPv4
          ", ipv4=%u.%u.%u.%u"
 #endif
@@ -881,9 +871,7 @@ static void virtio_net_dump(FAR struct virtio_device *vdev)
          ", ipv6=%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x"
 #endif
          "\n",
-         priv->bufnum, iob_navail(false),
-         netdev_lower_quota_load(netdev, NETPKT_RX),
-         netdev_lower_quota_load(netdev, NETPKT_TX)
+         priv->bufnum, iob_navail(false)
 #ifdef CONFIG_NET_IPv4
          , ip4_addr1(dev->d_ipaddr), ip4_addr2(dev->d_ipaddr),
          ip4_addr3(dev->d_ipaddr), ip4_addr4(dev->d_ipaddr)
diff --git a/drivers/wireless/ieee80211/morse/Kconfig 
b/drivers/wireless/ieee80211/morse/Kconfig
index ef46a247289..f65ec7e086d 100644
--- a/drivers/wireless/ieee80211/morse/Kconfig
+++ b/drivers/wireless/ieee80211/morse/Kconfig
@@ -157,14 +157,6 @@ config IEEE80211_MORSE_TX_TIMEOUT
                Maximum time to wait for the transceiver TX queues before 
dropping
                a packet.
 
-config IEEE80211_MORSE_TX_QUOTA
-       int "TX packet quota"
-       default 8
-
-config IEEE80211_MORSE_RX_QUOTA
-       int "RX packet quota"
-       default 8
-
 config IEEE80211_MORSE_SCAN_BUFSIZE
        int "Scan result buffer size"
        default 4096
diff --git a/drivers/wireless/ieee80211/morse/morse_netdev.c 
b/drivers/wireless/ieee80211/morse/morse_netdev.c
index 8ff052c00d0..65cc500ded8 100644
--- a/drivers/wireless/ieee80211/morse/morse_netdev.c
+++ b/drivers/wireless/ieee80211/morse/morse_netdev.c
@@ -1166,8 +1166,6 @@ int morse_register(FAR struct spi_dev_s *spi,
 
   priv->dev.ops              = &g_morse_netdev_ops;
   priv->dev.iw_ops           = &g_morse_wireless_ops;
-  priv->dev.quota[NETPKT_TX] = CONFIG_IEEE80211_MORSE_TX_QUOTA;
-  priv->dev.quota[NETPKT_RX] = CONFIG_IEEE80211_MORSE_RX_QUOTA;
   priv->dev.rxtype           = NETDEV_RX_THREAD;
   priv->dev.priority         = CONFIG_IEEE80211_MORSE_TASK_PRIORITY;
 
diff --git a/include/nuttx/net/netdev_lowerhalf.h 
b/include/nuttx/net/netdev_lowerhalf.h
index 701b3587b52..816c296f715 100644
--- a/include/nuttx/net/netdev_lowerhalf.h
+++ b/include/nuttx/net/netdev_lowerhalf.h
@@ -129,12 +129,6 @@ struct netdev_lowerhalf_s
   FAR const struct wireless_ops_s *iw_ops;
 #endif
 
-  /* Max # of buffer held by driver */
-
-  FAR atomic_t *quota_ptr; /* Shared quota, ignore `quota` if ptr is set */
-  atomic_t quota[NETPKT_TYPENUM];
-  bool txdone;
-
   uint8_t rxtype;
   uint8_t priority;
 
@@ -192,14 +186,13 @@ struct netdev_ops_s
                     unsigned long arg);
 #endif
 #ifdef CONFIG_NET_NETPOLL
-  /* txpoll - Complete pending transmissions and free the finished TX
-   *          packets, so their TX quota can be reused.
+  /* txpoll - Complete the pending transmissions and release the finished
+   *          TX packets.
    *
    *   Used only by netpoll, which may run with interrupts disabled and
    *   without the network stack (e.g. on the panic path), where the
    *   driver's TX-done interrupt cannot run.  It must not depend on
-   *   interrupts or on the upper half.  It is separate from reclaim,
-   *   which is called by the upper half in normal context.
+   *   interrupts or on the upper half.
    */
 
   CODE void (*txpoll)(FAR struct netdev_lowerhalf_s *dev);
@@ -368,20 +361,6 @@ void netdev_lower_rxready(FAR struct netdev_lowerhalf_s 
*dev);
 
 void netdev_lower_txdone(FAR struct netdev_lowerhalf_s *dev);
 
-/****************************************************************************
- * Name: netdev_lower_quota_load
- *
- * Description:
- *   Fetch the quota, use this interface when device is running.
- *
- * Input Parameters:
- *   dev  - The lower half device driver structure
- *   type - Whether get quota for TX or RX
- *
- ****************************************************************************/
-
-#define netdev_lower_quota_load(dev, type) atomic_read(&(dev)->quota_ptr[type])
-
 /****************************************************************************
  * Name: netdev_lower_vlan_add
  *
diff --git a/net/netpoll/netpoll_pkt.c b/net/netpoll/netpoll_pkt.c
index a6b82fecc7c..5a1034bd96d 100644
--- a/net/netpoll/netpoll_pkt.c
+++ b/net/netpoll/netpoll_pkt.c
@@ -45,8 +45,8 @@
  *
  * Description:
  *   Allocate a TX packet for netpoll.
- *   When the TX quota is used up, ask the driver to reclaim finished TX
- *   packets and try again a bounded number of times.
+ *   When no packet is available, ask the driver to complete its pending
+ *   transmissions and try again a bounded number of times.
  *
  * Input Parameters:
  *   dev - The lower half device driver structure

Reply via email to