From 8850dee74605890fa2a63c98f6aa816b16bcf239 Mon Sep 17 00:00:00 2001 From: chao an Date: Sun, 27 Nov 2022 03:31:07 +0800 Subject: [PATCH] net/devif: move preprocess of txpoll into common code Signed-off-by: chao an --- arch/arm/src/c5471/c5471_ethernet.c | 50 ++------- arch/arm/src/gd32f4/gd32f4xx_enet.c | 76 +++++-------- arch/arm/src/imx6/imx_enet.c | 54 ++-------- arch/arm/src/imxrt/imxrt_enet.c | 52 ++------- arch/arm/src/imxrt/imxrt_flexcan.c | 29 +++-- arch/arm/src/kinetis/kinetis_enet.c | 52 ++------- arch/arm/src/kinetis/kinetis_flexcan.c | 33 +++--- arch/arm/src/lpc17xx_40xx/lpc17_40_can.c | 23 ++-- arch/arm/src/lpc17xx_40xx/lpc17_40_ethernet.c | 51 ++------- arch/arm/src/lpc43xx/lpc43_ethernet.c | 98 ++++++----------- arch/arm/src/lpc54xx/lpc54_ethernet.c | 100 ++++++------------ arch/arm/src/rtl8720c/amebaz_netdev.c | 55 +++------- arch/arm/src/s32k1xx/s32k1xx_enet.c | 52 ++------- arch/arm/src/s32k1xx/s32k1xx_flexcan.c | 33 +++--- arch/arm/src/s32k3xx/s32k3xx_emac.c | 89 ++++++---------- arch/arm/src/s32k3xx/s32k3xx_flexcan.c | 33 +++--- arch/arm/src/sam34/sam_emac.c | 52 ++------- arch/arm/src/sama5/sam_emaca.c | 52 ++------- arch/arm/src/sama5/sam_emacb.c | 52 ++------- arch/arm/src/sama5/sam_gmac.c | 52 ++------- arch/arm/src/samd5e5/sam_gmac.c | 52 ++------- arch/arm/src/samv7/sam_emac.c | 52 ++------- arch/arm/src/stm32/stm32_can_sock.c | 27 +++-- arch/arm/src/stm32/stm32_eth.c | 88 +++++---------- arch/arm/src/stm32/stm32_fdcan_sock.c | 27 +++-- arch/arm/src/stm32f7/stm32_can_sock.c | 27 +++-- arch/arm/src/stm32f7/stm32_ethernet.c | 88 +++++---------- arch/arm/src/stm32h7/stm32_ethernet.c | 89 ++++++---------- arch/arm/src/stm32h7/stm32_fdcan_sock.c | 23 ++-- arch/arm/src/tiva/lm/lm3s_ethernet.c | 48 +-------- arch/arm/src/tiva/tm4c/tm4c_ethernet.c | 88 +++++---------- arch/hc/src/m9s12/m9s12_ethernet.c | 40 +------ arch/mips/src/pic32mx/pic32mx_ethernet.c | 77 ++++---------- arch/mips/src/pic32mz/pic32mz_ethernet.c | 77 ++++---------- arch/misoc/src/common/misoc_net.c | 40 +------ arch/renesas/src/rx65n/rx65n_eth.c | 88 +++++---------- arch/risc-v/src/bl602/bl602_netdev.c | 65 +++--------- arch/risc-v/src/esp32c3/esp32c3_wlan.c | 43 ++------ arch/risc-v/src/litex/litex_emac.c | 36 +------ arch/risc-v/src/mpfs/mpfs_ethernet.c | 52 ++------- arch/sim/src/sim/sim_netdriver.c | 51 +-------- arch/xtensa/src/esp32/esp32_emac.c | 74 ++++--------- arch/xtensa/src/esp32/esp32_wlan.c | 43 ++------ arch/z80/src/ez80/ez80_emac.c | 46 +------- drivers/net/dm90x0.c | 56 ++-------- drivers/net/enc28j60.c | 47 +------- drivers/net/encx24j600.c | 45 +------- drivers/net/ftmac100.c | 40 +------ drivers/net/lan91c111.c | 48 ++------- drivers/net/rpmsgdrv.c | 56 ++-------- drivers/net/skeleton.c | 45 +------- drivers/net/slip.c | 12 +-- drivers/net/tun.c | 66 ++---------- drivers/net/w5500.c | 56 ++-------- drivers/usbdev/cdcecm.c | 52 ++------- drivers/usbdev/rndis.c | 42 +------- drivers/usbhost/usbhost_cdcmbim.c | 10 +- .../wireless/ieee80211/bcm43xxx/bcmf_netdev.c | 54 ++-------- include/nuttx/net/netdev.h | 17 --- net/devif/devif.h | 17 +++ net/devif/devif_poll.c | 33 ++++++ 61 files changed, 744 insertions(+), 2381 deletions(-) diff --git a/arch/arm/src/c5471/c5471_ethernet.c b/arch/arm/src/c5471/c5471_ethernet.c index 36a33897c8..b7de3b93b1 100644 --- a/arch/arm/src/c5471/c5471_ethernet.c +++ b/arch/arm/src/c5471/c5471_ethernet.c @@ -1015,51 +1015,19 @@ static int c5471_txpoll(struct net_driver_s *dev) { struct c5471_driver_s *priv = (struct c5471_driver_s *)dev->d_private; - /* If the polling resulted in data that should be sent out on the network, - * the field d_len is set to a value > 0. + /* Send the packet */ + + c5471_transmit(priv); + + /* Check if the ESM has let go of the RX descriptor giving us + * access rights to submit another Ethernet frame. */ - if (priv->c_dev.d_len > 0) + if ((EIM_TXDESC_OWN_HOST & getreg32(priv->c_rxcpudesc)) != 0) { - /* Look up the destination MAC address and add it to the Ethernet - * header. - */ + /* No, then return non-zero to terminate the poll */ -#ifdef CONFIG_NET_IPv4 -#ifdef CONFIG_NET_IPv6 - if (IFF_IS_IPv4(priv->c_dev.d_flags)) -#endif - { - arp_out(&priv->c_dev); - } -#endif /* CONFIG_NET_IPv4 */ - -#ifdef CONFIG_NET_IPv6 -#ifdef CONFIG_NET_IPv4 - else -#endif - { - neighbor_out(&priv->c_dev); - } -#endif /* CONFIG_NET_IPv6 */ - - if (!devif_loopback(&priv->c_dev)) - { - /* Send the packet */ - - c5471_transmit(priv); - - /* Check if the ESM has let go of the RX descriptor giving us - * access rights to submit another Ethernet frame. - */ - - if ((EIM_TXDESC_OWN_HOST & getreg32(priv->c_rxcpudesc)) != 0) - { - /* No, then return non-zero to terminate the poll */ - - return 1; - } - } + return 1; } /* If zero is returned, the polling will continue until all connections diff --git a/arch/arm/src/gd32f4/gd32f4xx_enet.c b/arch/arm/src/gd32f4/gd32f4xx_enet.c index ce740d19a0..ae3354198f 100644 --- a/arch/arm/src/gd32f4/gd32f4xx_enet.c +++ b/arch/arm/src/gd32f4/gd32f4xx_enet.c @@ -1205,64 +1205,44 @@ static int gd32_tx_poll(struct net_driver_s *dev) DEBUGASSERT(priv->dev.d_buf != NULL); - /* If the polling resulted in data that should be sent out on the network, - * the field d_len is set to a value > 0. + /* Send the packet */ + + gd32_transmit(priv); + DEBUGASSERT(dev->d_len == 0 && dev->d_buf == NULL); + + /* Check if the next TX descriptor is owned by the Ethernet DMA or + * CPU. We cannot perform the TX poll if we are unable to accept + * another packet for transmission. + * + * In a race condition, ENET_TDES0_DAV may be cleared BUT still + * not available because gd32_freeframe() has not yet run. If + * gd32_freeframe() has run, the buffer1 pointer (tdes2) will be + * nullified (and inflight should be < CONFIG_gd32_ETH_NTXDESC). */ - if (priv->dev.d_len > 0) + if ((priv->txhead->tdes0 & ENET_TDES0_DAV) != 0 || + priv->txhead->tdes2 != 0) { - /* Look up the destination MAC address and add it to the Ethernet - * header. + /* We have to terminate the poll if we have no more descriptors + * available for another transfer. */ -#ifdef CONFIG_NET_IPv4 + return -EBUSY; + } - arp_out(&priv->dev); + /* We have the descriptor, we can continue the poll. Allocate a new + * buffer for the poll. + */ -#endif /* CONFIG_NET_IPv4 */ + dev->d_buf = gd32_buf_alloc(priv); - if (!devif_loopback(&priv->dev)) - { - /* Send the packet */ + /* We can't continue the poll if we have no buffers */ - gd32_transmit(priv); - DEBUGASSERT(dev->d_len == 0 && dev->d_buf == NULL); + if (dev->d_buf == NULL) + { + /* Terminate the poll. */ - /* Check if the next TX descriptor is owned by the Ethernet DMA or - * CPU. We cannot perform the TX poll if we are unable to accept - * another packet for transmission. - * - * In a race condition, ENET_TDES0_DAV may be cleared BUT still - * not available because gd32_freeframe() has not yet run. If - * gd32_freeframe() has run, the buffer1 pointer (tdes2) will be - * nullified (and inflight should be < CONFIG_gd32_ETH_NTXDESC). - */ - - if ((priv->txhead->tdes0 & ENET_TDES0_DAV) != 0 || - priv->txhead->tdes2 != 0) - { - /* We have to terminate the poll if we have no more descriptors - * available for another transfer. - */ - - return -EBUSY; - } - - /* We have the descriptor, we can continue the poll. Allocate a new - * buffer for the poll. - */ - - dev->d_buf = gd32_buf_alloc(priv); - - /* We can't continue the poll if we have no buffers */ - - if (dev->d_buf == NULL) - { - /* Terminate the poll. */ - - return -ENOMEM; - } - } + return -ENOMEM; } /* If zero is returned, the polling will continue until all connections diff --git a/arch/arm/src/imx6/imx_enet.c b/arch/arm/src/imx6/imx_enet.c index d1c0414653..9789443a2a 100644 --- a/arch/arm/src/imx6/imx_enet.c +++ b/arch/arm/src/imx6/imx_enet.c @@ -705,53 +705,19 @@ static int imx_txpoll(struct net_driver_s *dev) struct imx_driver_s *priv = (struct imx_driver_s *)dev->d_private; - /* If the polling resulted in data that should be sent out on the network, - * the field d_len is set to a value > 0. + /* Send the packet */ + + imx_transmit(priv); + priv->dev.d_buf = (uint8_t *) + imx_swap32((uint32_t)priv->txdesc[priv->txhead].data); + + /* Check if there is room in the device to hold another packet. If + * not, return a non-zero value to terminate the poll. */ - ninfo("Poll result: d_len=%d\n", priv->dev.d_len); - - if (priv->dev.d_len > 0) + if (imx_txringfull(priv)) { - /* Look up the destination MAC address and add it to the Ethernet - * header. - */ - -#ifdef CONFIG_NET_IPv4 -#ifdef CONFIG_NET_IPv6 - if (IFF_IS_IPv4(priv->dev.d_flags)) -#endif - { - arp_out(&priv->dev); - } -#endif /* CONFIG_NET_IPv4 */ - -#ifdef CONFIG_NET_IPv6 -#ifdef CONFIG_NET_IPv4 - else -#endif - { - neighbor_out(&priv->dev); - } -#endif /* CONFIG_NET_IPv6 */ - - if (!devif_loopback(&priv->dev)) - { - /* Send the packet */ - - imx_transmit(priv); - priv->dev.d_buf = (uint8_t *) - imx_swap32((uint32_t)priv->txdesc[priv->txhead].data); - - /* Check if there is room in the device to hold another packet. If - * not, return a non-zero value to terminate the poll. - */ - - if (imx_txringfull(priv)) - { - return -EBUSY; - } - } + return -EBUSY; } /* If zero is returned, the polling will continue until diff --git a/arch/arm/src/imxrt/imxrt_enet.c b/arch/arm/src/imxrt/imxrt_enet.c index 71861de2a4..7214745dd1 100644 --- a/arch/arm/src/imxrt/imxrt_enet.c +++ b/arch/arm/src/imxrt/imxrt_enet.c @@ -747,51 +747,19 @@ static int imxrt_txpoll(struct net_driver_s *dev) struct imxrt_driver_s *priv = (struct imxrt_driver_s *)dev->d_private; - /* If the polling resulted in data that should be sent out on the network, - * the field d_len is set to a value > 0. + /* Send the packet */ + + imxrt_transmit(priv); + priv->dev.d_buf = (uint8_t *) + imxrt_swap32((uint32_t)priv->txdesc[priv->txhead].data); + + /* Check if there is room in the device to hold another packet. If + * not, return a non-zero value to terminate the poll. */ - if (priv->dev.d_len > 0) + if (imxrt_txringfull(priv)) { - /* Look up the destination MAC address and add it to the Ethernet - * header. - */ - -#ifdef CONFIG_NET_IPv4 -#ifdef CONFIG_NET_IPv6 - if (IFF_IS_IPv4(priv->dev.d_flags)) -#endif - { - arp_out(&priv->dev); - } -#endif /* CONFIG_NET_IPv4 */ - -#ifdef CONFIG_NET_IPv6 -#ifdef CONFIG_NET_IPv4 - else -#endif - { - neighbor_out(&priv->dev); - } -#endif /* CONFIG_NET_IPv6 */ - - if (!devif_loopback(&priv->dev)) - { - /* Send the packet */ - - imxrt_transmit(priv); - priv->dev.d_buf = (uint8_t *) - imxrt_swap32((uint32_t)priv->txdesc[priv->txhead].data); - - /* Check if there is room in the device to hold another packet. If - * not, return a non-zero value to terminate the poll. - */ - - if (imxrt_txringfull(priv)) - { - return -EBUSY; - } - } + return -EBUSY; } /* If zero is returned, the polling will continue until diff --git a/arch/arm/src/imxrt/imxrt_flexcan.c b/arch/arm/src/imxrt/imxrt_flexcan.c index 22a394daa2..8221647c8b 100644 --- a/arch/arm/src/imxrt/imxrt_flexcan.c +++ b/arch/arm/src/imxrt/imxrt_flexcan.c @@ -772,23 +772,20 @@ static int imxrt_txpoll(struct net_driver_s *dev) if (priv->dev.d_len > 0) { - if (!devif_loopback(&priv->dev)) + imxrt_txdone(priv); + + /* Send the packet */ + + imxrt_transmit(priv); + + /* Check if there is room in the device to hold another packet. If + * not, return a non-zero value to terminate the poll. + */ + + if (imxrt_txringfull(priv)) { - imxrt_txdone(priv); - - /* Send the packet */ - - imxrt_transmit(priv); - - /* Check if there is room in the device to hold another packet. If - * not, return a non-zero value to terminate the poll. - */ - - if (imxrt_txringfull(priv)) - { - spin_unlock_irqrestore(NULL, flags); - return -EBUSY; - } + spin_unlock_irqrestore(NULL, flags); + return -EBUSY; } } diff --git a/arch/arm/src/kinetis/kinetis_enet.c b/arch/arm/src/kinetis/kinetis_enet.c index bc8f206645..ac4b3bbfc0 100644 --- a/arch/arm/src/kinetis/kinetis_enet.c +++ b/arch/arm/src/kinetis/kinetis_enet.c @@ -531,51 +531,19 @@ static int kinetis_txpoll(struct net_driver_s *dev) struct kinetis_driver_s *priv = (struct kinetis_driver_s *)dev->d_private; - /* If the polling resulted in data that should be sent out on the network, - * the field d_len is set to a value > 0. + /* Send the packet */ + + kinetis_transmit(priv); + priv->dev.d_buf = (uint8_t *) + kinesis_swap32((uint32_t)priv->txdesc[priv->txhead].data); + + /* Check if there is room in the device to hold another packet. + * If not, return a non-zero value to terminate the poll. */ - if (priv->dev.d_len > 0) + if (kinetis_txringfull(priv)) { - /* Look up the destination MAC address and add it to the Ethernet - * header. - */ - -#ifdef CONFIG_NET_IPv4 -#ifdef CONFIG_NET_IPv6 - if (IFF_IS_IPv4(priv->dev.d_flags)) -#endif - { - arp_out(&priv->dev); - } -#endif /* CONFIG_NET_IPv4 */ - -#ifdef CONFIG_NET_IPv6 -#ifdef CONFIG_NET_IPv4 - else -#endif - { - neighbor_out(&priv->dev); - } -#endif /* CONFIG_NET_IPv6 */ - - if (!devif_loopback(&priv->dev)) - { - /* Send the packet */ - - kinetis_transmit(priv); - priv->dev.d_buf = (uint8_t *) - kinesis_swap32((uint32_t)priv->txdesc[priv->txhead].data); - - /* Check if there is room in the device to hold another packet. - * If not, return a non-zero value to terminate the poll. - */ - - if (kinetis_txringfull(priv)) - { - return -EBUSY; - } - } + return -EBUSY; } /* If zero is returned, the polling will continue until all connections diff --git a/arch/arm/src/kinetis/kinetis_flexcan.c b/arch/arm/src/kinetis/kinetis_flexcan.c index e3895048f6..9dfd32082e 100644 --- a/arch/arm/src/kinetis/kinetis_flexcan.c +++ b/arch/arm/src/kinetis/kinetis_flexcan.c @@ -795,26 +795,23 @@ static int kinetis_txpoll(struct net_driver_s *dev) if (priv->dev.d_len > 0) { - if (!devif_loopback(&priv->dev)) + kinetis_txdone(priv); + + /* Send the packet */ + + kinetis_transmit(priv); + + /* Check if there is room in the device to hold another packet. If + * not, return a non-zero value to terminate the poll. + */ + + if ((getreg32(priv->base + KINETIS_CAN_ESR2_OFFSET) & + (CAN_ESR2_IMB | CAN_ESR2_VPS)) == + (CAN_ESR2_IMB | CAN_ESR2_VPS)) { - kinetis_txdone(priv); - - /* Send the packet */ - - kinetis_transmit(priv); - - /* Check if there is room in the device to hold another packet. If - * not, return a non-zero value to terminate the poll. - */ - - if ((getreg32(priv->base + KINETIS_CAN_ESR2_OFFSET) & - (CAN_ESR2_IMB | CAN_ESR2_VPS)) == - (CAN_ESR2_IMB | CAN_ESR2_VPS)) + if (kinetis_txringfull(priv)) { - if (kinetis_txringfull(priv)) - { - return -EBUSY; - } + return -EBUSY; } } } diff --git a/arch/arm/src/lpc17xx_40xx/lpc17_40_can.c b/arch/arm/src/lpc17xx_40xx/lpc17_40_can.c index 1cc5b6daa4..2347f5dd74 100644 --- a/arch/arm/src/lpc17xx_40xx/lpc17_40_can.c +++ b/arch/arm/src/lpc17xx_40xx/lpc17_40_can.c @@ -1049,20 +1049,17 @@ static int lpc17can_txpoll(struct net_driver_s *dev) if (priv->dev.d_len > 0) { - if (!devif_loopback(&priv->dev)) + /* Send the packet */ + + lpc17can_transmit(priv); + + /* Check if there is room in the device to hold another packet. If + * not, return a non-zero value to terminate the poll. + */ + + if (lpc17can_txringfull(priv)) { - /* Send the packet */ - - lpc17can_transmit(priv); - - /* Check if there is room in the device to hold another packet. If - * not, return a non-zero value to terminate the poll. - */ - - if (lpc17can_txringfull(priv)) - { - return -EBUSY; - } + return -EBUSY; } } diff --git a/arch/arm/src/lpc17xx_40xx/lpc17_40_ethernet.c b/arch/arm/src/lpc17xx_40xx/lpc17_40_ethernet.c index 18143c4209..77566e8582 100644 --- a/arch/arm/src/lpc17xx_40xx/lpc17_40_ethernet.c +++ b/arch/arm/src/lpc17xx_40xx/lpc17_40_ethernet.c @@ -712,57 +712,18 @@ static int lpc17_40_txpoll(struct net_driver_s *dev) { struct lpc17_40_driver_s *priv = (struct lpc17_40_driver_s *)dev->d_private; - int ret = OK; - /* If the polling resulted in data that should be sent out on the network, - * the field d_len is set to a value > 0. + /* Send this packet. In this context, we know that there is space + * for at least one more packet in the descriptor list. */ - if (priv->lp_dev.d_len > 0) - { - /* Look up the destination MAC address and add it to the Ethernet - * header. - */ + lpc17_40_transmit(priv); -#ifdef CONFIG_NET_IPv4 -#ifdef CONFIG_NET_IPv6 - if (IFF_IS_IPv4(priv->lp_dev.d_flags)) -#endif - { - arp_out(&priv->lp_dev); - } -#endif /* CONFIG_NET_IPv4 */ - -#ifdef CONFIG_NET_IPv6 -#ifdef CONFIG_NET_IPv4 - else -#endif - { - neighbor_out(&priv->lp_dev); - } -#endif /* CONFIG_NET_IPv6 */ - - if (!devif_loopback(&priv->lp_dev)) - { - /* Send this packet. In this context, we know that there is space - * for at least one more packet in the descriptor list. - */ - - lpc17_40_transmit(priv); - - /* Check if there is room in the device to hold another packet. If - * not, return any non-zero value to terminate the poll. - */ - - ret = lpc17_40_txdesc(priv); - } - } - - /* If zero is returned, the polling will continue until all connections - * have been examined. + /* Check if there is room in the device to hold another packet. If + * not, return any non-zero value to terminate the poll. */ - return ret; + return lpc17_40_txdesc(priv); } /**************************************************************************** diff --git a/arch/arm/src/lpc43xx/lpc43_ethernet.c b/arch/arm/src/lpc43xx/lpc43_ethernet.c index 627194e7bd..c1dfac729f 100644 --- a/arch/arm/src/lpc43xx/lpc43_ethernet.c +++ b/arch/arm/src/lpc43xx/lpc43_ethernet.c @@ -1128,84 +1128,46 @@ static int lpc43_txpoll(struct net_driver_s *dev) struct lpc43_ethmac_s *priv = (struct lpc43_ethmac_s *)dev->d_private; - DEBUGASSERT(priv->dev.d_buf != NULL); + /* Send the packet */ - /* If the polling resulted in data that should be sent out on the network, - * the field d_len is set to a value > 0. + lpc43_transmit(priv); + DEBUGASSERT(dev->d_len == 0 && dev->d_buf == NULL); + + /* Check if the next TX descriptor is owned by the Ethernet DMA or + * CPU. We cannot perform the TX poll if we are unable to accept + * another packet for transmission. + * + * In a race condition, ETH_TDES0_OWN may be cleared BUT still + * not available because lpc43_freeframe() has not yet run. If + * lpc43_freeframe() has run, the buffer1 pointer (tdes2) will be + * nullified (and inflight should be < CONFIG_LPC43_ETH_NTXDESC). */ - if (priv->dev.d_len > 0) + if ((priv->txhead->tdes0 & ETH_TDES0_OWN) != 0 || + priv->txhead->tdes2 != 0) { - /* Look up the destination MAC address and add it to the Ethernet - * header. + /* We have to terminate the poll if we have no more descriptors + * available for another transfer. */ -#ifdef CONFIG_NET_IPv4 -#ifdef CONFIG_NET_IPv6 - if (IFF_IS_IPv4(priv->dev.d_flags)) -#endif - { - arp_out(&priv->dev); - } -#endif /* CONFIG_NET_IPv4 */ - -#ifdef CONFIG_NET_IPv6 -#ifdef CONFIG_NET_IPv4 - else -#endif - { - neighbor_out(&priv->dev); - } -#endif /* CONFIG_NET_IPv6 */ - - if (!devif_loopback(&priv->dev)) - { - /* Send the packet */ - - lpc43_transmit(priv); - DEBUGASSERT(dev->d_len == 0 && dev->d_buf == NULL); - - /* Check if the next TX descriptor is owned by the Ethernet DMA or - * CPU. We cannot perform the TX poll if we are unable to accept - * another packet for transmission. - * - * In a race condition, ETH_TDES0_OWN may be cleared BUT still - * not available because lpc43_freeframe() has not yet run. If - * lpc43_freeframe() has run, the buffer1 pointer (tdes2) will be - * nullified (and inflight should be < CONFIG_LPC43_ETH_NTXDESC). - */ - - if ((priv->txhead->tdes0 & ETH_TDES0_OWN) != 0 || - priv->txhead->tdes2 != 0) - { - /* We have to terminate the poll if we have no more descriptors - * available for another transfer. - */ - - return -EBUSY; - } - - /* We have the descriptor, we can continue the poll. Allocate a new - * buffer for the poll. - */ - - dev->d_buf = lpc43_allocbuffer(priv); - - /* We can't continue the poll if we have no buffers */ - - if (dev->d_buf == NULL) - { - /* Terminate the poll. */ - - return -ENOMEM; - } - } + return -EBUSY; } - /* If zero is returned, the polling will continue until all connections - * have been examined. + /* We have the descriptor, we can continue the poll. Allocate a new + * buffer for the poll. */ + dev->d_buf = lpc43_allocbuffer(priv); + + /* We can't continue the poll if we have no buffers */ + + if (dev->d_buf == NULL) + { + /* Terminate the poll. */ + + return -ENOMEM; + } + return 0; } diff --git a/arch/arm/src/lpc54xx/lpc54_ethernet.c b/arch/arm/src/lpc54xx/lpc54_ethernet.c index 7a6aa7f7e4..9c552d5722 100644 --- a/arch/arm/src/lpc54xx/lpc54_ethernet.c +++ b/arch/arm/src/lpc54xx/lpc54_ethernet.c @@ -757,81 +757,49 @@ static int lpc54_eth_txpoll(struct net_driver_s *dev) DEBUGASSERT(dev->d_private != NULL && dev->d_buf != NULL); priv = (struct lpc54_ethdriver_s *)dev->d_private; - /* If the polling resulted in data that should be sent out on the network, - * the field d_len is set to a value > 0. + /* Send the packet */ + + chan = lpc54_eth_getring(priv); + txring = &priv->eth_txring[chan]; + + (txring->tr_buffers)[txring->tr_supply] = + (uint32_t *)priv->eth_dev.d_buf; + + lpc54_eth_transmit(priv, chan); + + txring0 = &priv->eth_txring[0]; +#ifdef CONFIG_LPC54_ETH_MULTIQUEUE + txring1 = &priv->eth_txring[1]; + + /* We cannot perform the Tx poll now if all of the Tx descriptors + * for both channels are in-use. */ - if (priv->eth_dev.d_len > 0) - { - /* Look up the destination MAC address and add it to the Ethernet - * header. - */ - -#ifdef CONFIG_NET_IPv4 -#ifdef CONFIG_NET_IPv6 - if (IFF_IS_IPv4(priv->eth_dev.d_flags)) -#endif - { - arp_out(&priv->eth_dev); - } -#endif /* CONFIG_NET_IPv4 */ - -#ifdef CONFIG_NET_IPv6 -#ifdef CONFIG_NET_IPv4 - else -#endif - { - neighbor_out(&priv->eth_dev); - } -#endif /* CONFIG_NET_IPv6 */ - - if (!devif_loopback(&priv->eth_dev)) - { - /* Send the packet */ - - chan = lpc54_eth_getring(priv); - txring = &priv->eth_txring[chan]; - - (txring->tr_buffers)[txring->tr_supply] = - (uint32_t *)priv->eth_dev.d_buf; - - lpc54_eth_transmit(priv, chan); - - txring0 = &priv->eth_txring[0]; -#ifdef CONFIG_LPC54_ETH_MULTIQUEUE - txring1 = &priv->eth_txring[1]; - - /* We cannot perform the Tx poll now if all of the Tx descriptors - * for both channels are in-use. - */ - - if (txring0->tr_inuse >= txring0->tr_ndesc || - txring1->tr_inuse >= txring1->tr_ndesc) + if (txring0->tr_inuse >= txring0->tr_ndesc || + txring1->tr_inuse >= txring1->tr_ndesc) #else - /* We cannot continue the Tx poll now if all of the Tx descriptors - * for this channel 0 are in-use. - */ + /* We cannot continue the Tx poll now if all of the Tx descriptors + * for this channel 0 are in-use. + */ - if (txring0->tr_inuse >= txring0->tr_ndesc) + if (txring0->tr_inuse >= txring0->tr_ndesc) #endif - { - /* Stop the poll.. no more Tx descriptors */ + { + /* Stop the poll.. no more Tx descriptors */ - return 1; - } + return 1; + } - /* There is a free descriptor in the ring, allocate a new Tx buffer - * to perform the poll. - */ + /* There is a free descriptor in the ring, allocate a new Tx buffer + * to perform the poll. + */ - priv->eth_dev.d_buf = (uint8_t *)lpc54_pktbuf_alloc(priv); - if (priv->eth_dev.d_buf == NULL) - { - /* Stop the poll.. no more packet buffers */ + priv->eth_dev.d_buf = (uint8_t *)lpc54_pktbuf_alloc(priv); + if (priv->eth_dev.d_buf == NULL) + { + /* Stop the poll.. no more packet buffers */ - return 1; - } - } + return 1; } /* If zero is returned, the polling will continue until all connections diff --git a/arch/arm/src/rtl8720c/amebaz_netdev.c b/arch/arm/src/rtl8720c/amebaz_netdev.c index 80812c0a98..6b8cd17efe 100644 --- a/arch/arm/src/rtl8720c/amebaz_netdev.c +++ b/arch/arm/src/rtl8720c/amebaz_netdev.c @@ -42,49 +42,24 @@ static void amebaz_netdev_notify_tx_done(struct amebaz_dev_s *priv) static int amebaz_txpoll(struct net_driver_s *dev) { struct amebaz_dev_s *priv = (struct amebaz_dev_s *)dev->d_private; - if (priv->dev.d_len > 0) + + net_lock(); + if (!priv->curr) { -#ifdef CONFIG_NET_IPv4 -#ifdef CONFIG_NET_IPv6 - if (IFF_IS_IPv4(priv->dev.d_flags)) -#endif - { - arp_out(&priv->dev); - } - -#endif /* CONFIG_NET_IPv4 */ -#ifdef CONFIG_NET_IPv6 -#ifdef CONFIG_NET_IPv4 - else -#endif - { - neighbor_out(&priv->dev); - } - -#endif /* CONFIG_NET_IPv6 */ - if (!devif_loopback(&priv->dev)) - { - net_lock(); - if (!priv->curr) - { - net_unlock(); - amebaz_netdev_notify_tx_done(priv); - return false; - } - - DEBUGASSERT(priv->curr->tail == priv->dev.d_buf); - skb_put(priv->curr, priv->dev.d_len); - rltk_wlan_send_skb(priv->devnum, priv->curr); - priv->dev.d_buf = NULL; - priv->curr = NULL; - net_unlock(); - NETDEV_TXPACKETS(&priv->dev); - amebaz_netdev_notify_tx_done(priv); - return true; - } + net_unlock(); + amebaz_netdev_notify_tx_done(priv); + return false; } - return false; + DEBUGASSERT(priv->curr->tail == priv->dev.d_buf); + skb_put(priv->curr, priv->dev.d_len); + rltk_wlan_send_skb(priv->devnum, priv->curr); + priv->dev.d_buf = NULL; + priv->curr = NULL; + net_unlock(); + NETDEV_TXPACKETS(&priv->dev); + amebaz_netdev_notify_tx_done(priv); + return true; } static int amebaz_transmit(struct amebaz_dev_s *priv) diff --git a/arch/arm/src/s32k1xx/s32k1xx_enet.c b/arch/arm/src/s32k1xx/s32k1xx_enet.c index a62a74acb2..80c5e11d5b 100644 --- a/arch/arm/src/s32k1xx/s32k1xx_enet.c +++ b/arch/arm/src/s32k1xx/s32k1xx_enet.c @@ -590,51 +590,19 @@ static int s32k1xx_txpoll(struct net_driver_s *dev) struct s32k1xx_driver_s *priv = (struct s32k1xx_driver_s *)dev->d_private; - /* If the polling resulted in data that should be sent out on the network, - * the field d_len is set to a value > 0. + /* Send the packet */ + + s32k1xx_transmit(priv); + priv->dev.d_buf = (uint8_t *) + s32k1xx_swap32((uint32_t)priv->txdesc[priv->txhead].data); + + /* Check if there is room in the device to hold another packet. If + * not, return a non-zero value to terminate the poll. */ - if (priv->dev.d_len > 0) + if (s32k1xx_txringfull(priv)) { - /* Look up the destination MAC address and add it to the Ethernet - * header. - */ - -#ifdef CONFIG_NET_IPv4 -#ifdef CONFIG_NET_IPv6 - if (IFF_IS_IPv4(priv->dev.d_flags)) -#endif - { - arp_out(&priv->dev); - } -#endif /* CONFIG_NET_IPv4 */ - -#ifdef CONFIG_NET_IPv6 -#ifdef CONFIG_NET_IPv4 - else -#endif - { - neighbor_out(&priv->dev); - } -#endif /* CONFIG_NET_IPv6 */ - - if (!devif_loopback(&priv->dev)) - { - /* Send the packet */ - - s32k1xx_transmit(priv); - priv->dev.d_buf = (uint8_t *) - s32k1xx_swap32((uint32_t)priv->txdesc[priv->txhead].data); - - /* Check if there is room in the device to hold another packet. If - * not, return a non-zero value to terminate the poll. - */ - - if (s32k1xx_txringfull(priv)) - { - return -EBUSY; - } - } + return -EBUSY; } /* If zero is returned, the polling will continue until all connections diff --git a/arch/arm/src/s32k1xx/s32k1xx_flexcan.c b/arch/arm/src/s32k1xx/s32k1xx_flexcan.c index 5b6d2f9b5e..fa0e6b7106 100644 --- a/arch/arm/src/s32k1xx/s32k1xx_flexcan.c +++ b/arch/arm/src/s32k1xx/s32k1xx_flexcan.c @@ -796,26 +796,23 @@ static int s32k1xx_txpoll(struct net_driver_s *dev) if (priv->dev.d_len > 0) { - if (!devif_loopback(&priv->dev)) + s32k1xx_txdone(priv); + + /* Send the packet */ + + s32k1xx_transmit(priv); + + /* Check if there is room in the device to hold another packet. If + * not, return a non-zero value to terminate the poll. + */ + + if ((getreg32(priv->base + S32K1XX_CAN_ESR2_OFFSET) & + (CAN_ESR2_IMB | CAN_ESR2_VPS)) == + (CAN_ESR2_IMB | CAN_ESR2_VPS)) { - s32k1xx_txdone(priv); - - /* Send the packet */ - - s32k1xx_transmit(priv); - - /* Check if there is room in the device to hold another packet. If - * not, return a non-zero value to terminate the poll. - */ - - if ((getreg32(priv->base + S32K1XX_CAN_ESR2_OFFSET) & - (CAN_ESR2_IMB | CAN_ESR2_VPS)) == - (CAN_ESR2_IMB | CAN_ESR2_VPS)) + if (s32k1xx_txringfull(priv)) { - if (s32k1xx_txringfull(priv)) - { - return -EBUSY; - } + return -EBUSY; } } } diff --git a/arch/arm/src/s32k3xx/s32k3xx_emac.c b/arch/arm/src/s32k3xx/s32k3xx_emac.c index f93260c7e3..26b849d2bd 100644 --- a/arch/arm/src/s32k3xx/s32k3xx_emac.c +++ b/arch/arm/src/s32k3xx/s32k3xx_emac.c @@ -796,77 +796,48 @@ static int s32k3xx_txpoll(struct net_driver_s *dev) DEBUGASSERT(priv->dev.d_buf != NULL); - /* If the polling resulted in data that should be sent out on the network, - * the field d_len is set to a value > 0. + /* Send the packet */ + + s32k3xx_transmit(priv); + DEBUGASSERT(dev->d_len == 0 && dev->d_buf == NULL); + + /* Check if the next TX descriptor is owned by the Ethernet DMA or + * CPU. We cannot perform the TX poll if we are unable to accept + * another packet for transmission. + * + * In a race condition, ETH_TDES3_OWN may be cleared BUT still + * not available because s32k3xx_freeframe() has not yet run. If + * s32k3xx_freeframe() has run, the buffer1 pointer (tdes2) will be + * nullified (and inflight should be < CONFIG_S32K3XX_ENET_NTXBUFFERS). */ - if (priv->dev.d_len > 0) + if ((priv->txhead->des3 & EMAC_TDES3_OWN_MASK) != 0 || + priv->txhead->des0 != 0) { - /* Look up the destination MAC address and add it to the Ethernet - * header. + /* We have to terminate the poll if we have no more descriptors + * available for another transfer. */ -#ifdef CONFIG_NET_IPv4 -#ifdef CONFIG_NET_IPv6 - if (IFF_IS_IPv4(priv->dev.d_flags)) -#endif - { - arp_out(&priv->dev); - } -#endif /* CONFIG_NET_IPv4 */ + nerr("No tx descriptors available"); -#ifdef CONFIG_NET_IPv6 -#ifdef CONFIG_NET_IPv4 - else -#endif - { - neighbor_out(&priv->dev); - } -#endif /* CONFIG_NET_IPv6 */ + return -EBUSY; + } - /* Send the packet */ + /* We have the descriptor, we can continue the poll. Allocate a new + * buffer for the poll. + */ - s32k3xx_transmit(priv); - DEBUGASSERT(dev->d_len == 0 && dev->d_buf == NULL); + dev->d_buf = s32k3xx_allocbuffer(priv); - /* Check if the next TX descriptor is owned by the Ethernet DMA or - * CPU. We cannot perform the TX poll if we are unable to accept - * another packet for transmission. - * - * In a race condition, ETH_TDES3_OWN may be cleared BUT still - * not available because s32k3xx_freeframe() has not yet run. If - * s32k3xx_freeframe() has run, the buffer1 pointer (tdes2) will be - * nullified (and inflight should be < CONFIG_S32K3XX_ENET_NTXBUFFERS). - */ + /* We can't continue the poll if we have no buffers */ - if ((priv->txhead->des3 & EMAC_TDES3_OWN_MASK) != 0 || - priv->txhead->des0 != 0) - { - /* We have to terminate the poll if we have no more descriptors - * available for another transfer. - */ + if (dev->d_buf == NULL) + { + /* Terminate the poll. */ - nerr("No tx descriptors available"); + nerr("No tx buffer available"); - return -EBUSY; - } - - /* We have the descriptor, we can continue the poll. Allocate a new - * buffer for the poll. - */ - - dev->d_buf = s32k3xx_allocbuffer(priv); - - /* We can't continue the poll if we have no buffers */ - - if (dev->d_buf == NULL) - { - /* Terminate the poll. */ - - nerr("No tx buffer available"); - - return -ENOMEM; - } + return -ENOMEM; } /* If zero is returned, the polling will continue until all connections diff --git a/arch/arm/src/s32k3xx/s32k3xx_flexcan.c b/arch/arm/src/s32k3xx/s32k3xx_flexcan.c index f08a9380d0..3e17b52ee0 100644 --- a/arch/arm/src/s32k3xx/s32k3xx_flexcan.c +++ b/arch/arm/src/s32k3xx/s32k3xx_flexcan.c @@ -961,26 +961,23 @@ static int s32k3xx_txpoll(struct net_driver_s *dev) if (priv->dev.d_len > 0) { - if (!devif_loopback(&priv->dev)) + s32k3xx_txdone(priv); + + /* Send the packet */ + + s32k3xx_transmit(priv); + + /* Check if there is room in the device to hold another packet. If + * not, return a non-zero value to terminate the poll. + */ + + if ((getreg32(priv->base + S32K3XX_CAN_ESR2_OFFSET) & + (CAN_ESR2_IMB | CAN_ESR2_VPS)) == + (CAN_ESR2_IMB | CAN_ESR2_VPS)) { - s32k3xx_txdone(priv); - - /* Send the packet */ - - s32k3xx_transmit(priv); - - /* Check if there is room in the device to hold another packet. If - * not, return a non-zero value to terminate the poll. - */ - - if ((getreg32(priv->base + S32K3XX_CAN_ESR2_OFFSET) & - (CAN_ESR2_IMB | CAN_ESR2_VPS)) == - (CAN_ESR2_IMB | CAN_ESR2_VPS)) + if (s32k3xx_txringfull(priv)) { - if (s32k3xx_txringfull(priv)) - { - return -EBUSY; - } + return -EBUSY; } } } diff --git a/arch/arm/src/sam34/sam_emac.c b/arch/arm/src/sam34/sam_emac.c index d68c4c0304..f0cafc5762 100644 --- a/arch/arm/src/sam34/sam_emac.c +++ b/arch/arm/src/sam34/sam_emac.c @@ -831,53 +831,21 @@ static int sam_txpoll(struct net_driver_s *dev) { struct sam_emac_s *priv = (struct sam_emac_s *)dev->d_private; - /* If the polling resulted in data that should be sent out on the network, - * the field d_len is set to a value > 0. + /* Send the packet */ + + sam_transmit(priv); + + /* Check if there are any free TX descriptors. We cannot perform + * the TX poll if we do not have buffering for another packet. */ - if (priv->dev.d_len > 0) + if (sam_txfree(priv) == 0) { - /* Look up the destination MAC address and add it to the Ethernet - * header. + /* We have to terminate the poll if we have no more descriptors + * available for another transfer. */ -#ifdef CONFIG_NET_IPv4 -#ifdef CONFIG_NET_IPv6 - if (IFF_IS_IPv4(priv->dev.d_flags)) -#endif - { - arp_out(&priv->dev); - } -#endif /* CONFIG_NET_IPv4 */ - -#ifdef CONFIG_NET_IPv6 -#ifdef CONFIG_NET_IPv4 - else -#endif - { - neighbor_out(&priv->dev); - } -#endif /* CONFIG_NET_IPv6 */ - - if (!devif_loopback(&priv->dev)) - { - /* Send the packet */ - - sam_transmit(priv); - - /* Check if there are any free TX descriptors. We cannot perform - * the TX poll if we do not have buffering for another packet. - */ - - if (sam_txfree(priv) == 0) - { - /* We have to terminate the poll if we have no more descriptors - * available for another transfer. - */ - - return -EBUSY; - } - } + return -EBUSY; } /* If zero is returned, the polling will continue until all connections diff --git a/arch/arm/src/sama5/sam_emaca.c b/arch/arm/src/sama5/sam_emaca.c index d3d4ef586a..20d539cb32 100644 --- a/arch/arm/src/sama5/sam_emaca.c +++ b/arch/arm/src/sama5/sam_emaca.c @@ -866,53 +866,21 @@ static int sam_txpoll(struct net_driver_s *dev) { struct sam_emac_s *priv = (struct sam_emac_s *)dev->d_private; - /* If the polling resulted in data that should be sent out on the network, - * the field d_len is set to a value > 0. + /* Send the packet */ + + sam_transmit(priv); + + /* Check if there are any free TX descriptors. We cannot perform + * the TX poll if we do not have buffering for another packet. */ - if (priv->dev.d_len > 0) + if (sam_txfree(priv) == 0) { - /* Look up the destination MAC address and add it to the Ethernet - * header. + /* We have to terminate the poll if we have no more descriptors + * available for another transfer. */ -#ifdef CONFIG_NET_IPv4 -#ifdef CONFIG_NET_IPv6 - if (IFF_IS_IPv4(priv->dev.d_flags)) -#endif - { - arp_out(&priv->dev); - } -#endif /* CONFIG_NET_IPv4 */ - -#ifdef CONFIG_NET_IPv6 -#ifdef CONFIG_NET_IPv4 - else -#endif - { - neighbor_out(&priv->dev); - } -#endif /* CONFIG_NET_IPv6 */ - - if (!devif_loopback(&priv->dev)) - { - /* Send the packet */ - - sam_transmit(priv); - - /* Check if there are any free TX descriptors. We cannot perform - * the TX poll if we do not have buffering for another packet. - */ - - if (sam_txfree(priv) == 0) - { - /* We have to terminate the poll if we have no more descriptors - * available for another transfer. - */ - - return -EBUSY; - } - } + return -EBUSY; } /* If zero is returned, the polling will continue until all connections diff --git a/arch/arm/src/sama5/sam_emacb.c b/arch/arm/src/sama5/sam_emacb.c index d3b1d25f81..2b280b2f86 100644 --- a/arch/arm/src/sama5/sam_emacb.c +++ b/arch/arm/src/sama5/sam_emacb.c @@ -1179,53 +1179,21 @@ static int sam_txpoll(struct net_driver_s *dev) { struct sam_emac_s *priv = (struct sam_emac_s *)dev->d_private; - /* If the polling resulted in data that should be sent out on the network, - * the field d_len is set to a value > 0. + /* Send the packet */ + + sam_transmit(priv); + + /* Check if there are any free TX descriptors. We cannot perform + * the TX poll if we do not have buffering for another packet. */ - if (priv->dev.d_len > 0) + if (sam_txfree(priv) == 0) { - /* Look up the destination MAC address and add it to the Ethernet - * header. + /* We have to terminate the poll if we have no more descriptors + * available for another transfer. */ -#ifdef CONFIG_NET_IPv4 -#ifdef CONFIG_NET_IPv6 - if (IFF_IS_IPv4(priv->dev.d_flags)) -#endif - { - arp_out(&priv->dev); - } -#endif /* CONFIG_NET_IPv4 */ - -#ifdef CONFIG_NET_IPv6 -#ifdef CONFIG_NET_IPv4 - else -#endif - { - neighbor_out(&priv->dev); - } -#endif /* CONFIG_NET_IPv6 */ - - if (!devif_loopback(&priv->dev)) - { - /* Send the packet */ - - sam_transmit(priv); - - /* Check if there are any free TX descriptors. We cannot perform - * the TX poll if we do not have buffering for another packet. - */ - - if (sam_txfree(priv) == 0) - { - /* We have to terminate the poll if we have no more descriptors - * available for another transfer. - */ - - return -EBUSY; - } - } + return -EBUSY; } /* If zero is returned, the polling will continue until all connections diff --git a/arch/arm/src/sama5/sam_gmac.c b/arch/arm/src/sama5/sam_gmac.c index ba23706621..cd6f01d83c 100644 --- a/arch/arm/src/sama5/sam_gmac.c +++ b/arch/arm/src/sama5/sam_gmac.c @@ -808,53 +808,21 @@ static int sam_txpoll(struct net_driver_s *dev) { struct sam_gmac_s *priv = (struct sam_gmac_s *)dev->d_private; - /* If the polling resulted in data that should be sent out on the network, - * the field d_len is set to a value > 0. + /* Send the packet */ + + sam_transmit(priv); + + /* Check if there are any free TX descriptors. We cannot perform + * the TX poll if we do not have buffering for another packet. */ - if (priv->dev.d_len > 0) + if (sam_txfree(priv) == 0) { - /* Look up the destination MAC address and add it to the Ethernet - * header. + /* We have to terminate the poll if we have no more descriptors + * available for another transfer. */ -#ifdef CONFIG_NET_IPv4 -#ifdef CONFIG_NET_IPv6 - if (IFF_IS_IPv4(priv->dev.d_flags)) -#endif - { - arp_out(&priv->dev); - } -#endif /* CONFIG_NET_IPv4 */ - -#ifdef CONFIG_NET_IPv6 -#ifdef CONFIG_NET_IPv4 - else -#endif - { - neighbor_out(&priv->dev); - } -#endif /* CONFIG_NET_IPv6 */ - - if (!devif_loopback(&priv->dev)) - { - /* Send the packet */ - - sam_transmit(priv); - - /* Check if there are any free TX descriptors. We cannot perform - * the TX poll if we do not have buffering for another packet. - */ - - if (sam_txfree(priv) == 0) - { - /* We have to terminate the poll if we have no more descriptors - * available for another transfer. - */ - - return -EBUSY; - } - } + return -EBUSY; } /* If zero is returned, the polling will continue until all connections diff --git a/arch/arm/src/samd5e5/sam_gmac.c b/arch/arm/src/samd5e5/sam_gmac.c index e4ba499d3c..8ccc6914a9 100644 --- a/arch/arm/src/samd5e5/sam_gmac.c +++ b/arch/arm/src/samd5e5/sam_gmac.c @@ -796,53 +796,21 @@ static int sam_txpoll(struct net_driver_s *dev) { struct sam_gmac_s *priv = (struct sam_gmac_s *)dev->d_private; - /* If the polling resulted in data that should be sent out on the network, - * the field d_len is set to a value > 0. + /* Send the packet */ + + sam_transmit(priv); + + /* Check if there are any free TX descriptors. We cannot perform + * the TX poll if we do not have buffering for another packet. */ - if (priv->dev.d_len > 0) + if (sam_txfree(priv) == 0) { - /* Look up the destination MAC address and add it to the Ethernet - * header. + /* We have to terminate the poll if we have no more descriptors + * available for another transfer. */ -#ifdef CONFIG_NET_IPv4 -#ifdef CONFIG_NET_IPv6 - if (IFF_IS_IPv4(priv->dev.d_flags)) -#endif - { - arp_out(&priv->dev); - } -#endif /* CONFIG_NET_IPv4 */ - -#ifdef CONFIG_NET_IPv6 -#ifdef CONFIG_NET_IPv4 - else -#endif - { - neighbor_out(&priv->dev); - } -#endif /* CONFIG_NET_IPv6 */ - - if (!devif_loopback(&priv->dev)) - { - /* Send the packet */ - - sam_transmit(priv); - - /* Check if there are any free TX descriptors. We cannot perform - * the TX poll if we do not have buffering for another packet. - */ - - if (sam_txfree(priv) == 0) - { - /* We have to terminate the poll if we have no more descriptors - * available for another transfer. - */ - - return -EBUSY; - } - } + return -EBUSY; } /* If zero is returned, the polling will continue until all connections diff --git a/arch/arm/src/samv7/sam_emac.c b/arch/arm/src/samv7/sam_emac.c index 12acaf201d..820bb693d0 100644 --- a/arch/arm/src/samv7/sam_emac.c +++ b/arch/arm/src/samv7/sam_emac.c @@ -1470,53 +1470,21 @@ static int sam_txpoll(struct net_driver_s *dev) { struct sam_emac_s *priv = (struct sam_emac_s *)dev->d_private; - /* If the polling resulted in data that should be sent out on the network, - * the field d_len is set to a value > 0. + /* Send the packet */ + + sam_transmit(priv, EMAC_QUEUE_0); + + /* Check if there are any free TX descriptors. We cannot perform + * the TX poll if we do not have buffering for another packet. */ - if (priv->dev.d_len > 0) + if (sam_txfree(priv, EMAC_QUEUE_0) == 0) { - /* Look up the destination MAC address and add it to the Ethernet - * header. + /* We have to terminate the poll if we have no more descriptors + * available for another transfer. */ -#ifdef CONFIG_NET_IPv4 -#ifdef CONFIG_NET_IPv6 - if (IFF_IS_IPv4(priv->dev.d_flags)) -#endif - { - arp_out(&priv->dev); - } -#endif /* CONFIG_NET_IPv4 */ - -#ifdef CONFIG_NET_IPv6 -#ifdef CONFIG_NET_IPv4 - else -#endif - { - neighbor_out(&priv->dev); - } -#endif /* CONFIG_NET_IPv6 */ - - if (!devif_loopback(&priv->dev)) - { - /* Send the packet */ - - sam_transmit(priv, EMAC_QUEUE_0); - - /* Check if there are any free TX descriptors. We cannot perform - * the TX poll if we do not have buffering for another packet. - */ - - if (sam_txfree(priv, EMAC_QUEUE_0) == 0) - { - /* We have to terminate the poll if we have no more descriptors - * available for another transfer. - */ - - return -EBUSY; - } - } + return -EBUSY; } /* If zero is returned, the polling will continue until all connections diff --git a/arch/arm/src/stm32/stm32_can_sock.c b/arch/arm/src/stm32/stm32_can_sock.c index 2a12e1a33b..0a6d9733b2 100644 --- a/arch/arm/src/stm32/stm32_can_sock.c +++ b/arch/arm/src/stm32/stm32_can_sock.c @@ -1021,22 +1021,19 @@ static int stm32can_txpoll(struct net_driver_s *dev) if (priv->dev.d_len > 0) { - if (!devif_loopback(&priv->dev)) + stm32can_txdone(priv); + + /* Send the packet */ + + stm32can_transmit(priv); + + /* Check if there is room in the device to hold another packet. If + * not, return a non-zero value to terminate the poll. + */ + + if (stm32can_txready(priv) == false) { - stm32can_txdone(priv); - - /* Send the packet */ - - stm32can_transmit(priv); - - /* Check if there is room in the device to hold another packet. If - * not, return a non-zero value to terminate the poll. - */ - - if (stm32can_txready(priv) == false) - { - return -EBUSY; - } + return -EBUSY; } } diff --git a/arch/arm/src/stm32/stm32_eth.c b/arch/arm/src/stm32/stm32_eth.c index d9f7671fe4..885417430b 100644 --- a/arch/arm/src/stm32/stm32_eth.c +++ b/arch/arm/src/stm32/stm32_eth.c @@ -1246,76 +1246,44 @@ static int stm32_txpoll(struct net_driver_s *dev) DEBUGASSERT(priv->dev.d_buf != NULL); - /* If the polling resulted in data that should be sent out on the network, - * the field d_len is set to a value > 0. + /* Send the packet */ + + stm32_transmit(priv); + DEBUGASSERT(dev->d_len == 0 && dev->d_buf == NULL); + + /* Check if the next TX descriptor is owned by the Ethernet DMA or + * CPU. We cannot perform the TX poll if we are unable to accept + * another packet for transmission. + * + * In a race condition, ETH_TDES0_OWN may be cleared BUT still + * not available because stm32_freeframe() has not yet run. If + * stm32_freeframe() has run, the buffer1 pointer (tdes2) will be + * nullified (and inflight should be < CONFIG_STM32_ETH_NTXDESC). */ - if (priv->dev.d_len > 0) + if ((priv->txhead->tdes0 & ETH_TDES0_OWN) != 0 || + priv->txhead->tdes2 != 0) { - /* Look up the destination MAC address and add it to the Ethernet - * header. + /* We have to terminate the poll if we have no more descriptors + * available for another transfer. */ -#ifdef CONFIG_NET_IPv4 -#ifdef CONFIG_NET_IPv6 - if (IFF_IS_IPv4(priv->dev.d_flags)) -#endif - { - arp_out(&priv->dev); - } -#endif /* CONFIG_NET_IPv4 */ + return -EBUSY; + } -#ifdef CONFIG_NET_IPv6 -#ifdef CONFIG_NET_IPv4 - else -#endif - { - neighbor_out(&priv->dev); - } -#endif /* CONFIG_NET_IPv6 */ + /* We have the descriptor, we can continue the poll. Allocate a new + * buffer for the poll. + */ - if (!devif_loopback(&priv->dev)) - { - /* Send the packet */ + dev->d_buf = stm32_allocbuffer(priv); - stm32_transmit(priv); - DEBUGASSERT(dev->d_len == 0 && dev->d_buf == NULL); + /* We can't continue the poll if we have no buffers */ - /* Check if the next TX descriptor is owned by the Ethernet DMA or - * CPU. We cannot perform the TX poll if we are unable to accept - * another packet for transmission. - * - * In a race condition, ETH_TDES0_OWN may be cleared BUT still - * not available because stm32_freeframe() has not yet run. If - * stm32_freeframe() has run, the buffer1 pointer (tdes2) will be - * nullified (and inflight should be < CONFIG_STM32_ETH_NTXDESC). - */ + if (dev->d_buf == NULL) + { + /* Terminate the poll. */ - if ((priv->txhead->tdes0 & ETH_TDES0_OWN) != 0 || - priv->txhead->tdes2 != 0) - { - /* We have to terminate the poll if we have no more descriptors - * available for another transfer. - */ - - return -EBUSY; - } - - /* We have the descriptor, we can continue the poll. Allocate a new - * buffer for the poll. - */ - - dev->d_buf = stm32_allocbuffer(priv); - - /* We can't continue the poll if we have no buffers */ - - if (dev->d_buf == NULL) - { - /* Terminate the poll. */ - - return -ENOMEM; - } - } + return -ENOMEM; } /* If zero is returned, the polling will continue until all connections diff --git a/arch/arm/src/stm32/stm32_fdcan_sock.c b/arch/arm/src/stm32/stm32_fdcan_sock.c index 0493f29e19..debf7d0087 100644 --- a/arch/arm/src/stm32/stm32_fdcan_sock.c +++ b/arch/arm/src/stm32/stm32_fdcan_sock.c @@ -3045,22 +3045,19 @@ static int fdcan_txpoll(struct net_driver_s *dev) if (priv->dev.d_len > 0) { - if (!devif_loopback(&priv->dev)) + fdcan_txdone(priv); + + /* Send the packet */ + + fdcan_send(priv); + + /* Check if there is room in the device to hold another packet. If + * not, return a non-zero value to terminate the poll. + */ + + if (fdcan_txready(priv) == false) { - fdcan_txdone(priv); - - /* Send the packet */ - - fdcan_send(priv); - - /* Check if there is room in the device to hold another packet. If - * not, return a non-zero value to terminate the poll. - */ - - if (fdcan_txready(priv) == false) - { - return -EBUSY; - } + return -EBUSY; } } diff --git a/arch/arm/src/stm32f7/stm32_can_sock.c b/arch/arm/src/stm32f7/stm32_can_sock.c index d479546703..55c86fc21a 100644 --- a/arch/arm/src/stm32f7/stm32_can_sock.c +++ b/arch/arm/src/stm32f7/stm32_can_sock.c @@ -1045,22 +1045,19 @@ static int stm32can_txpoll(struct net_driver_s *dev) if (priv->dev.d_len > 0) { - if (!devif_loopback(&priv->dev)) + stm32can_txdone(priv); + + /* Send the packet */ + + stm32can_transmit(priv); + + /* Check if there is room in the device to hold another packet. If + * not, return a non-zero value to terminate the poll. + */ + + if (stm32can_txready(priv) == false) { - stm32can_txdone(priv); - - /* Send the packet */ - - stm32can_transmit(priv); - - /* Check if there is room in the device to hold another packet. If - * not, return a non-zero value to terminate the poll. - */ - - if (stm32can_txready(priv) == false) - { - return -EBUSY; - } + return -EBUSY; } } diff --git a/arch/arm/src/stm32f7/stm32_ethernet.c b/arch/arm/src/stm32f7/stm32_ethernet.c index c82b703d81..1be315e72c 100644 --- a/arch/arm/src/stm32f7/stm32_ethernet.c +++ b/arch/arm/src/stm32f7/stm32_ethernet.c @@ -1288,76 +1288,44 @@ static int stm32_txpoll(struct net_driver_s *dev) DEBUGASSERT(priv->dev.d_buf != NULL); - /* If the polling resulted in data that should be sent out on the network, - * the field d_len is set to a value > 0. + /* Send the packet */ + + stm32_transmit(priv); + DEBUGASSERT(dev->d_len == 0 && dev->d_buf == NULL); + + /* Check if the next TX descriptor is owned by the Ethernet DMA or + * CPU. We cannot perform the TX poll if we are unable to accept + * another packet for transmission. + * + * In a race condition, ETH_TDES0_OWN may be cleared BUT still + * not available because stm32_freeframe() has not yet run. If + * stm32_freeframe() has run, the buffer1 pointer (tdes2) will be + * nullified (and inflight should be < CONFIG_STM32F7_ETH_NTXDESC). */ - if (priv->dev.d_len > 0) + if ((priv->txhead->tdes0 & ETH_TDES0_OWN) != 0 || + priv->txhead->tdes2 != 0) { - /* Look up the destination MAC address and add it to the Ethernet - * header. + /* We have to terminate the poll if we have no more descriptors + * available for another transfer. */ -#ifdef CONFIG_NET_IPv4 -#ifdef CONFIG_NET_IPv6 - if (IFF_IS_IPv4(priv->dev.d_flags)) -#endif - { - arp_out(&priv->dev); - } -#endif /* CONFIG_NET_IPv4 */ + return -EBUSY; + } -#ifdef CONFIG_NET_IPv6 -#ifdef CONFIG_NET_IPv4 - else -#endif - { - neighbor_out(&priv->dev); - } -#endif /* CONFIG_NET_IPv6 */ + /* We have the descriptor, we can continue the poll. Allocate a new + * buffer for the poll. + */ - if (!devif_loopback(&priv->dev)) - { - /* Send the packet */ + dev->d_buf = stm32_allocbuffer(priv); - stm32_transmit(priv); - DEBUGASSERT(dev->d_len == 0 && dev->d_buf == NULL); + /* We can't continue the poll if we have no buffers */ - /* Check if the next TX descriptor is owned by the Ethernet DMA or - * CPU. We cannot perform the TX poll if we are unable to accept - * another packet for transmission. - * - * In a race condition, ETH_TDES0_OWN may be cleared BUT still - * not available because stm32_freeframe() has not yet run. If - * stm32_freeframe() has run, the buffer1 pointer (tdes2) will be - * nullified (and inflight should be < CONFIG_STM32F7_ETH_NTXDESC). - */ + if (dev->d_buf == NULL) + { + /* Terminate the poll. */ - if ((priv->txhead->tdes0 & ETH_TDES0_OWN) != 0 || - priv->txhead->tdes2 != 0) - { - /* We have to terminate the poll if we have no more descriptors - * available for another transfer. - */ - - return -EBUSY; - } - - /* We have the descriptor, we can continue the poll. Allocate a new - * buffer for the poll. - */ - - dev->d_buf = stm32_allocbuffer(priv); - - /* We can't continue the poll if we have no buffers */ - - if (dev->d_buf == NULL) - { - /* Terminate the poll. */ - - return -ENOMEM; - } - } + return -ENOMEM; } /* If zero is returned, the polling will continue until all connections diff --git a/arch/arm/src/stm32h7/stm32_ethernet.c b/arch/arm/src/stm32h7/stm32_ethernet.c index 52524a02cc..620983efc1 100644 --- a/arch/arm/src/stm32h7/stm32_ethernet.c +++ b/arch/arm/src/stm32h7/stm32_ethernet.c @@ -1323,77 +1323,48 @@ static int stm32_txpoll(struct net_driver_s *dev) DEBUGASSERT(priv->dev.d_buf != NULL); - /* If the polling resulted in data that should be sent out on the network, - * the field d_len is set to a value > 0. + /* Send the packet */ + + stm32_transmit(priv); + DEBUGASSERT(dev->d_len == 0 && dev->d_buf == NULL); + + /* Check if the next TX descriptor is owned by the Ethernet DMA or + * CPU. We cannot perform the TX poll if we are unable to accept + * another packet for transmission. + * + * In a race condition, ETH_TDES3_OWN may be cleared BUT still + * not available because stm32_freeframe() has not yet run. If + * stm32_freeframe() has run, the buffer1 pointer (tdes2) will be + * nullified (and inflight should be < CONFIG_STM32H7_ETH_NTXDESC). */ - if (priv->dev.d_len > 0) + if ((priv->txhead->des3 & ETH_TDES3_RD_OWN) != 0 || + priv->txhead->des0 != 0) { - /* Look up the destination MAC address and add it to the Ethernet - * header. + /* We have to terminate the poll if we have no more descriptors + * available for another transfer. */ -#ifdef CONFIG_NET_IPv4 -#ifdef CONFIG_NET_IPv6 - if (IFF_IS_IPv4(priv->dev.d_flags)) -#endif - { - arp_out(&priv->dev); - } -#endif /* CONFIG_NET_IPv4 */ + nerr("No tx descriptors available"); -#ifdef CONFIG_NET_IPv6 -#ifdef CONFIG_NET_IPv4 - else -#endif - { - neighbor_out(&priv->dev); - } -#endif /* CONFIG_NET_IPv6 */ + return -EBUSY; + } - /* Send the packet */ + /* We have the descriptor, we can continue the poll. Allocate a new + * buffer for the poll. + */ - stm32_transmit(priv); - DEBUGASSERT(dev->d_len == 0 && dev->d_buf == NULL); + dev->d_buf = stm32_allocbuffer(priv); - /* Check if the next TX descriptor is owned by the Ethernet DMA or - * CPU. We cannot perform the TX poll if we are unable to accept - * another packet for transmission. - * - * In a race condition, ETH_TDES3_OWN may be cleared BUT still - * not available because stm32_freeframe() has not yet run. If - * stm32_freeframe() has run, the buffer1 pointer (tdes2) will be - * nullified (and inflight should be < CONFIG_STM32H7_ETH_NTXDESC). - */ + /* We can't continue the poll if we have no buffers */ - if ((priv->txhead->des3 & ETH_TDES3_RD_OWN) != 0 || - priv->txhead->des0 != 0) - { - /* We have to terminate the poll if we have no more descriptors - * available for another transfer. - */ + if (dev->d_buf == NULL) + { + /* Terminate the poll. */ - nerr("No tx descriptors available"); + nerr("No tx buffer available"); - return -EBUSY; - } - - /* We have the descriptor, we can continue the poll. Allocate a new - * buffer for the poll. - */ - - dev->d_buf = stm32_allocbuffer(priv); - - /* We can't continue the poll if we have no buffers */ - - if (dev->d_buf == NULL) - { - /* Terminate the poll. */ - - nerr("No tx buffer available"); - - return -ENOMEM; - } + return -ENOMEM; } /* If zero is returned, the polling will continue until all connections diff --git a/arch/arm/src/stm32h7/stm32_fdcan_sock.c b/arch/arm/src/stm32h7/stm32_fdcan_sock.c index 35fafe3999..23beaa1467 100644 --- a/arch/arm/src/stm32h7/stm32_fdcan_sock.c +++ b/arch/arm/src/stm32h7/stm32_fdcan_sock.c @@ -934,20 +934,17 @@ static int fdcan_txpoll(struct net_driver_s *dev) if (priv->dev.d_len > 0) { - if (!devif_loopback(&priv->dev)) + /* Send the packet */ + + fdcan_transmit(priv); + + /* Check if there is room in the device to hold another packet. If + * not, return a non-zero value to terminate the poll. + */ + + if (fdcan_txringfull(priv)) { - /* Send the packet */ - - fdcan_transmit(priv); - - /* Check if there is room in the device to hold another packet. If - * not, return a non-zero value to terminate the poll. - */ - - if (fdcan_txringfull(priv)) - { - return -EBUSY; - } + return -EBUSY; } } diff --git a/arch/arm/src/tiva/lm/lm3s_ethernet.c b/arch/arm/src/tiva/lm/lm3s_ethernet.c index d590e32c4b..f6fa7b254c 100644 --- a/arch/arm/src/tiva/lm/lm3s_ethernet.c +++ b/arch/arm/src/tiva/lm/lm3s_ethernet.c @@ -603,54 +603,12 @@ static int tiva_transmit(struct tiva_driver_s *priv) static int tiva_txpoll(struct net_driver_s *dev) { struct tiva_driver_s *priv = (struct tiva_driver_s *)dev->d_private; - int ret = OK; - /* If the polling resulted in data that should be sent out on the network, - * the field d_len is set to a value > 0. + /* Send the packet. tiva_transmit() will return zero if the + * packet was successfully handled. */ - ninfo("Poll result: d_len=%d\n", priv->ld_dev.d_len); - if (priv->ld_dev.d_len > 0) - { - DEBUGASSERT(!(tiva_ethin(priv, TIVA_MAC_TR_OFFSET) & MAC_TR_NEWTX)); - - /* Look up the destination MAC address and add it to the Ethernet - * header. - */ - -#ifdef CONFIG_NET_IPv4 -#ifdef CONFIG_NET_IPv6 - if (IFF_IS_IPv4(priv->ld_dev.d_flags)) -#endif - { - arp_out(&priv->ld_dev); - } -#endif /* CONFIG_NET_IPv4 */ - -#ifdef CONFIG_NET_IPv6 -#ifdef CONFIG_NET_IPv4 - else -#endif - { - neighbor_out(&priv->ld_dev); - } -#endif /* CONFIG_NET_IPv6 */ - - if (!devif_loopback(&priv->ld_dev)) - { - /* Send the packet. tiva_transmit() will return zero if the - * packet was successfully handled. - */ - - ret = tiva_transmit(priv); - } - } - - /* If zero is returned, the polling will continue until all connections - * have been examined. - */ - - return ret; + return tiva_transmit(priv); } /**************************************************************************** diff --git a/arch/arm/src/tiva/tm4c/tm4c_ethernet.c b/arch/arm/src/tiva/tm4c/tm4c_ethernet.c index db6b71e88f..9cc553bd8b 100644 --- a/arch/arm/src/tiva/tm4c/tm4c_ethernet.c +++ b/arch/arm/src/tiva/tm4c/tm4c_ethernet.c @@ -1246,76 +1246,44 @@ static int tiva_txpoll(struct net_driver_s *dev) DEBUGASSERT(priv->dev.d_buf != NULL); - /* If the polling resulted in data that should be sent out on the network, - * the field d_len is set to a value > 0. + /* Send the packet */ + + tiva_transmit(priv); + DEBUGASSERT(dev->d_len == 0 && dev->d_buf == NULL); + + /* Check if the next TX descriptor is owned by the Ethernet DMA or + * CPU. We cannot perform the TX poll if we are unable to accept + * another packet for transmission. + * + * In a race condition, EMAC_TDES0_OWN may be cleared BUT still + * not available because tiva_freeframe() has not yet run. If + * tiva_freeframe() has run, the buffer1 pointer (tdes2) will be + * nullified (and inflight should be < CONFIG_TIVA_EMAC_NTXDESC). */ - if (priv->dev.d_len > 0) + if ((priv->txhead->tdes0 & EMAC_TDES0_OWN) != 0 || + priv->txhead->tdes2 != 0) { - /* Look up the destination MAC address and add it to the Ethernet - * header. + /* We have to terminate the poll if we have no more descriptors + * available for another transfer. */ -#ifdef CONFIG_NET_IPv4 -#ifdef CONFIG_NET_IPv6 - if (IFF_IS_IPv4(priv->dev.d_flags)) -#endif - { - arp_out(&priv->dev); - } -#endif /* CONFIG_NET_IPv4 */ + return -EBUSY; + } -#ifdef CONFIG_NET_IPv6 -#ifdef CONFIG_NET_IPv4 - else -#endif - { - neighbor_out(&priv->dev); - } -#endif /* CONFIG_NET_IPv6 */ + /* We have the descriptor, we can continue the poll. Allocate a new + * buffer for the poll. + */ - if (!devif_loopback(&priv->dev)) - { - /* Send the packet */ + dev->d_buf = tiva_allocbuffer(priv); - tiva_transmit(priv); - DEBUGASSERT(dev->d_len == 0 && dev->d_buf == NULL); + /* We can't continue the poll if we have no buffers */ - /* Check if the next TX descriptor is owned by the Ethernet DMA or - * CPU. We cannot perform the TX poll if we are unable to accept - * another packet for transmission. - * - * In a race condition, EMAC_TDES0_OWN may be cleared BUT still - * not available because tiva_freeframe() has not yet run. If - * tiva_freeframe() has run, the buffer1 pointer (tdes2) will be - * nullified (and inflight should be < CONFIG_TIVA_EMAC_NTXDESC). - */ + if (dev->d_buf == NULL) + { + /* Terminate the poll. */ - if ((priv->txhead->tdes0 & EMAC_TDES0_OWN) != 0 || - priv->txhead->tdes2 != 0) - { - /* We have to terminate the poll if we have no more descriptors - * available for another transfer. - */ - - return -EBUSY; - } - - /* We have the descriptor, we can continue the poll. Allocate a new - * buffer for the poll. - */ - - dev->d_buf = tiva_allocbuffer(priv); - - /* We can't continue the poll if we have no buffers */ - - if (dev->d_buf == NULL) - { - /* Terminate the poll. */ - - return -ENOMEM; - } - } + return -ENOMEM; } /* If zero is returned, the polling will continue until all connections diff --git a/arch/hc/src/m9s12/m9s12_ethernet.c b/arch/hc/src/m9s12/m9s12_ethernet.c index 71dd60776f..a4761e095b 100644 --- a/arch/hc/src/m9s12/m9s12_ethernet.c +++ b/arch/hc/src/m9s12/m9s12_ethernet.c @@ -199,45 +199,9 @@ static int emac_txpoll(struct net_driver_s *dev) FAR struct emac_driver_s *priv = (FAR struct emac_driver_s *)dev->d_private; - /* If the polling resulted in data that should be sent out on the network, - * the field d_len is set to a value > 0. - */ + /* Send the packet */ - if (priv->d_dev.d_len > 0) - { - /* Look up the destination MAC address and add it to the Ethernet - * header. - */ - -#ifdef CONFIG_NET_IPv4 -#ifdef CONFIG_NET_IPv6 - if (IFF_IS_IPv4(priv->d_dev.d_flags)) -#endif - { - arp_out(&priv->d_dev); - } -#endif /* CONFIG_NET_IPv4 */ - -#ifdef CONFIG_NET_IPv6 -#ifdef CONFIG_NET_IPv4 - else -#endif - { - neighbor_out(&priv->d_dev); - } -#endif /* CONFIG_NET_IPv6 */ - - if (!devif_loopback(&priv->d_dev)) - { - /* Send the packet */ - - emac_transmit(priv); - - /* Check if there is room in the device to hold another packet. - * If not, return a non-zero value to terminate the poll. - */ - } - } + emac_transmit(priv); /* If zero is returned, the polling will continue until all connections * have been examined. diff --git a/arch/mips/src/pic32mx/pic32mx_ethernet.c b/arch/mips/src/pic32mx/pic32mx_ethernet.c index edbc9c5943..66053d521c 100644 --- a/arch/mips/src/pic32mx/pic32mx_ethernet.c +++ b/arch/mips/src/pic32mx/pic32mx_ethernet.c @@ -1119,76 +1119,43 @@ static int pic32mx_transmit(struct pic32mx_driver_s *priv) static int pic32mx_txpoll(struct net_driver_s *dev) { struct pic32mx_driver_s *priv = (struct pic32mx_driver_s *)dev->d_private; - int ret = OK; - /* If the polling resulted in data that should be sent out on the network, - * the field d_len is set to a value > 0. + /* Send this packet. In this context, we know that there is space + * for at least one more packet in the descriptor list. */ - if (priv->pd_dev.d_len > 0) + pic32mx_transmit(priv); + + /* Check if the next TX descriptor is available. If not, return a + * non-zero value to terminate the poll. + */ + + if (pic32mx_txdesc(priv) == NULL) { - /* Look up the destination MAC address and add it to the Ethernet - * header. + /* There are no more TX descriptors/buffers available.. + * stop the poll */ -#ifdef CONFIG_NET_IPv4 -#ifdef CONFIG_NET_IPv6 - if (IFF_IS_IPv4(priv->pd_dev.d_flags)) -#endif - { - arp_out(&priv->pd_dev); - } -#endif /* CONFIG_NET_IPv4 */ + return -EAGAIN; + } -#ifdef CONFIG_NET_IPv6 -#ifdef CONFIG_NET_IPv4 - else -#endif - { - neighbor_out(&priv->pd_dev); - } -#endif /* CONFIG_NET_IPv6 */ + /* Get the next Tx buffer needed in order to continue the poll */ - if (!devif_loopback(&priv->pd_dev)) - { - /* Send this packet. In this context, we know that there is space - * for at least one more packet in the descriptor list. - */ + priv->pd_dev.d_buf = pic32mx_allocbuffer(priv); + if (priv->pd_dev.d_buf == NULL) + { + /* We have no more buffers available for the nex Tx.. stop the + * poll + */ - pic32mx_transmit(priv); - - /* Check if the next TX descriptor is available. If not, return a - * non-zero value to terminate the poll. - */ - - if (pic32mx_txdesc(priv) == NULL) - { - /* There are no more TX descriptors/buffers available.. - * stop the poll - */ - - return -EAGAIN; - } - - /* Get the next Tx buffer needed in order to continue the poll */ - - priv->pd_dev.d_buf = pic32mx_allocbuffer(priv); - if (priv->pd_dev.d_buf == NULL) - { - /* We have no more buffers available for the nex Tx.. stop the - * poll - */ - - return -ENOMEM; - } - } + return -ENOMEM; } /* If zero is returned, the polling will continue until all connections * have been examined. */ - return ret; + return 0; } /**************************************************************************** diff --git a/arch/mips/src/pic32mz/pic32mz_ethernet.c b/arch/mips/src/pic32mz/pic32mz_ethernet.c index 0bdce67bb0..08265311f0 100644 --- a/arch/mips/src/pic32mz/pic32mz_ethernet.c +++ b/arch/mips/src/pic32mz/pic32mz_ethernet.c @@ -1221,76 +1221,43 @@ static int pic32mz_transmit(struct pic32mz_driver_s *priv) static int pic32mz_txpoll(struct net_driver_s *dev) { struct pic32mz_driver_s *priv = (struct pic32mz_driver_s *)dev->d_private; - int ret = OK; - /* If the polling resulted in data that should be sent out on the network, - * the field d_len is set to a value > 0. + /* Send this packet. In this context, we know that there is space + * for at least one more packet in the descriptor list. */ - if (priv->pd_dev.d_len > 0) + pic32mz_transmit(priv); + + /* Check if the next TX descriptor is available. If not, return a + * non-zero value to terminate the poll. + */ + + if (pic32mz_txdesc(priv) == NULL) { - /* Look up the destination MAC address and add it to the Ethernet - * header. + /* There are no more TX descriptors/buffers available.. + * stop the poll */ -#ifdef CONFIG_NET_IPv4 -#ifdef CONFIG_NET_IPv6 - if (IFF_IS_IPv4(priv->pd_dev.d_flags)) -#endif - { - arp_out(&priv->pd_dev); - } -#endif /* CONFIG_NET_IPv4 */ + return -EAGAIN; + } -#ifdef CONFIG_NET_IPv6 -#ifdef CONFIG_NET_IPv4 - else -#endif - { - neighbor_out(&priv->pd_dev); - } -#endif /* CONFIG_NET_IPv6 */ + /* Get the next Tx buffer needed in order to continue the poll */ - if (!devif_loopback(&priv->pd_dev)) - { - /* Send this packet. In this context, we know that there is space - * for at least one more packet in the descriptor list. - */ + priv->pd_dev.d_buf = pic32mz_allocbuffer(priv); + if (priv->pd_dev.d_buf == NULL) + { + /* We have no more buffers available for the next Tx.. + * stop the poll + */ - pic32mz_transmit(priv); - - /* Check if the next TX descriptor is available. If not, return a - * non-zero value to terminate the poll. - */ - - if (pic32mz_txdesc(priv) == NULL) - { - /* There are no more TX descriptors/buffers available.. - * stop the poll - */ - - return -EAGAIN; - } - - /* Get the next Tx buffer needed in order to continue the poll */ - - priv->pd_dev.d_buf = pic32mz_allocbuffer(priv); - if (priv->pd_dev.d_buf == NULL) - { - /* We have no more buffers available for the next Tx.. - * stop the poll - */ - - return -ENOMEM; - } - } + return -ENOMEM; } /* If zero is returned, the polling will continue until all connections * have been examined. */ - return ret; + return 0; } /**************************************************************************** diff --git a/arch/misoc/src/common/misoc_net.c b/arch/misoc/src/common/misoc_net.c index ba91f8ba59..7755bc2dfe 100644 --- a/arch/misoc/src/common/misoc_net.c +++ b/arch/misoc/src/common/misoc_net.c @@ -282,45 +282,9 @@ static int misoc_net_txpoll(struct net_driver_s *dev) struct misoc_net_driver_s *priv = (struct misoc_net_driver_s *)dev->d_private; - /* If the polling resulted in data that should be sent out on the network, - * the field d_len is set to a value > 0. - */ + /* Send the packet */ - if (priv->misoc_net_dev.d_len > 0) - { - /* Look up the destination MAC address and add it to the Ethernet - * header. - */ - -#ifdef CONFIG_NET_IPv4 -#ifdef CONFIG_NET_IPv6 - if (IFF_IS_IPv4(priv->misoc_net_dev.d_flags)) -#endif - { - arp_out(&priv->misoc_net_dev); - } -#endif /* CONFIG_NET_IPv4 */ - -#ifdef CONFIG_NET_IPv6 -#ifdef CONFIG_NET_IPv4 - else -#endif - { - neighbor_out(&priv->misoc_net_dev); - } -#endif /* CONFIG_NET_IPv6 */ - - if (!devif_loopback(&priv->misoc_net_dev)) - { - /* Send the packet */ - - misoc_net_transmit(priv); - - /* Check if there is room in the device to hold another packet. - * If not, return a non-zero value to terminate the poll. - */ - } - } + misoc_net_transmit(priv); /* If zero is returned, the polling will continue until all connections * have been examined. diff --git a/arch/renesas/src/rx65n/rx65n_eth.c b/arch/renesas/src/rx65n/rx65n_eth.c index e4eceada32..f58a016b25 100644 --- a/arch/renesas/src/rx65n/rx65n_eth.c +++ b/arch/renesas/src/rx65n/rx65n_eth.c @@ -1047,76 +1047,44 @@ static int rx65n_txpoll(struct net_driver_s *dev) DEBUGASSERT(priv->dev.d_buf != NULL); - /* If the polling resulted in data that should be sent out on the network, - * the field d_len is set to a value > 0. + /* Send the packet */ + + rx65n_transmit(priv); + DEBUGASSERT(dev->d_len == 0 && dev->d_buf == NULL); + + /* Check if the next TX descriptor is owned by the Ethernet DMA or + * CPU. We cannot perform the TX poll if we are unable to accept + * another packet fo transmission. + * + * In a race condition, TACT may be cleared BUT still not available + * because rx65n_freeframe() has not yet run. If rx65n_freeframe() + * has run, the buffer1 pointer (tdes2) will be nullified (and + * inflight should be CONFIG_RX65N_ETH_NTXDESC). */ - if (priv->dev.d_len > 0) + if ((priv->txhead->tdes0 & TACT) != 0 || + priv->txhead->tdes2 != 0) { - /* Look up the destination MAC address and add it to the Ethernet - * header. + /* We have to terminate the poll if we have no more descriptors + * available for another transfer. */ -#ifdef CONFIG_NET_IPv4 -#ifdef CONFIG_NET_IPv6 - if (IFF_IS_IPv4(priv->dev.d_flags)) -#endif - { - arp_out(&priv->dev); - } -#endif /* CONFIG_NET_IPv4 */ + return -EBUSY; + } -#ifdef CONFIG_NET_IPv6 -#ifdef CONFIG_NET_IPv4 - else -#endif - { - neighbor_out(&priv->dev); - } -#endif /* CONFIG_NET_IPv6 */ + /* We have the descriptor, we can continue the poll. Allocate a new + * buffer for the poll. + */ - if (!devif_loopback(&priv->dev)) - { - /* Send the packet */ + dev->d_buf = rx65n_allocbuffer(priv); - rx65n_transmit(priv); - DEBUGASSERT(dev->d_len == 0 && dev->d_buf == NULL); + /* We can't continue the poll if we have no buffers */ - /* Check if the next TX descriptor is owned by the Ethernet DMA or - * CPU. We cannot perform the TX poll if we are unable to accept - * another packet fo transmission. - * - * In a race condition, TACT may be cleared BUT still not available - * because rx65n_freeframe() has not yet run. If rx65n_freeframe() - * has run, the buffer1 pointer (tdes2) will be nullified (and - * inflight should be CONFIG_RX65N_ETH_NTXDESC). - */ + if (dev->d_buf == NULL) + { + /* Terminate the poll. */ - if ((priv->txhead->tdes0 & TACT) != 0 || - priv->txhead->tdes2 != 0) - { - /* We have to terminate the poll if we have no more descriptors - * available for another transfer. - */ - - return -EBUSY; - } - - /* We have the descriptor, we can continue the poll. Allocate a new - * buffer for the poll. - */ - - dev->d_buf = rx65n_allocbuffer(priv); - - /* We can't continue the poll if we have no buffers */ - - if (dev->d_buf == NULL) - { - /* Terminate the poll. */ - - return -ENOMEM; - } - } + return -ENOMEM; } /* If zero is returned, the polling will continue until all connections diff --git a/arch/risc-v/src/bl602/bl602_netdev.c b/arch/risc-v/src/bl602/bl602_netdev.c index 24f315871e..a5795559df 100644 --- a/arch/risc-v/src/bl602/bl602_netdev.c +++ b/arch/risc-v/src/bl602/bl602_netdev.c @@ -372,63 +372,22 @@ static int bl602_net_txpoll(struct net_driver_s *dev) struct bl602_net_driver_s *priv = (struct bl602_net_driver_s *)dev->d_private; - if (priv->net_dev.d_len > 0) - { - DEBUGASSERT(priv->net_dev.d_buf); + /* Send the packet */ - /* Look up the destination MAC address and add it to the Ethernet - * header. - */ + bl602_net_transmit(priv); -#ifdef CONFIG_NET_IPv4 -#ifdef CONFIG_NET_IPv6 - if (IFF_IS_IPv4(priv->net_dev.d_flags)) -#endif - { - arp_out(&priv->net_dev); - } -#endif /* CONFIG_NET_IPv4 */ - -#ifdef CONFIG_NET_IPv6 -#ifdef CONFIG_NET_IPv4 - else -#endif - { - neighbor_out(&priv->net_dev); - } -#endif /* CONFIG_NET_IPv6 */ - - /* Check if the network is sending this packet to the IP address of - * this device. If so, just loop the packet back into the network but - * don't attempt to put it on the wire. - */ - - if (!devif_loopback(&priv->net_dev)) - { - /* Send the packet */ - - bl602_net_transmit(priv); - - /* Check if there is room in the device to hold another packet. - * If not, return a non-zero value to terminate the poll. - */ - - priv->net_dev.d_buf = bl602_netdev_alloc_txbuf(); - if (priv->net_dev.d_buf) - { - priv->net_dev.d_buf += PRESERVE_80211_HEADER_LEN; - priv->net_dev.d_len = 0; - } - - return priv->net_dev.d_buf == NULL; - } - } - - /* If zero is returned, the polling will continue until all connections - * have been examined. + /* Check if there is room in the device to hold another packet. + * If not, return a non-zero value to terminate the poll. */ - return 0; + priv->net_dev.d_buf = bl602_netdev_alloc_txbuf(); + if (priv->net_dev.d_buf) + { + priv->net_dev.d_buf += PRESERVE_80211_HEADER_LEN; + priv->net_dev.d_len = 0; + } + + return priv->net_dev.d_buf == NULL; } /**************************************************************************** diff --git a/arch/risc-v/src/esp32c3/esp32c3_wlan.c b/arch/risc-v/src/esp32c3/esp32c3_wlan.c index 921d63e19e..9c24a26b85 100644 --- a/arch/risc-v/src/esp32c3/esp32c3_wlan.c +++ b/arch/risc-v/src/esp32c3/esp32c3_wlan.c @@ -883,46 +883,17 @@ static int wlan_txpoll(struct net_driver_s *dev) DEBUGASSERT(dev->d_buf != NULL); - /* If the polling resulted in data that should be sent out on the network, - * the field d_len is set to a value > 0. - */ + wlan_cache_txpkt_tail(priv); - if (dev->d_len > 0) + pktbuf = wlan_alloc_buffer(priv); + if (pktbuf == NULL) { - /* Look up the destination MAC address and add it to the Ethernet - * header. - */ - -#ifdef CONFIG_NET_IPv4 -#ifdef CONFIG_NET_IPv6 - if (IFF_IS_IPv4(dev->d_flags)) -#endif - { - arp_out(dev); - } -#endif /* CONFIG_NET_IPv4 */ - -#ifdef CONFIG_NET_IPv6 -#ifdef CONFIG_NET_IPv4 - else -#endif - { - neighbor_out(dev); - } -#endif /* CONFIG_NET_IPv6 */ - - wlan_cache_txpkt_tail(priv); - - pktbuf = wlan_alloc_buffer(priv); - if (pktbuf == NULL) - { - return -ENOMEM; - } - - dev->d_buf = pktbuf->buffer; - dev->d_len = WLAN_BUF_SIZE; + return -ENOMEM; } + dev->d_buf = pktbuf->buffer; + dev->d_len = WLAN_BUF_SIZE; + /* If zero is returned, the polling will continue until * all connections have been examined. */ diff --git a/arch/risc-v/src/litex/litex_emac.c b/arch/risc-v/src/litex/litex_emac.c index 1aef87ab47..6d1d6865af 100644 --- a/arch/risc-v/src/litex/litex_emac.c +++ b/arch/risc-v/src/litex/litex_emac.c @@ -319,41 +319,9 @@ static int litex_txpoll(struct net_driver_s *dev) DEBUGASSERT(priv->dev.d_buf != NULL); - /* If the polling resulted in data that should be sent out on the network, - * the field d_len is set to a value > 0. - */ + /* Send the packet */ - if (priv->dev.d_len > 0) - { - /* Look up the destination MAC address and add it to the Ethernet - * header. - */ - -#ifdef CONFIG_NET_IPv4 -#ifdef CONFIG_NET_IPv6 - if (IFF_IS_IPv4(priv->dev.d_flags)) -#endif - { - arp_out(&priv->dev); - } -#endif /* CONFIG_NET_IPv4 */ - -#ifdef CONFIG_NET_IPv6 -#ifdef CONFIG_NET_IPv4 - else -#endif - { - neighbor_out(&priv->dev); - } -#endif /* CONFIG_NET_IPv6 */ - - if (!devif_loopback(&priv->dev)) - { - /* Send the packet */ - - litex_transmit(priv); - } - } + litex_transmit(priv); /* If zero is returned, the polling will continue until all connections * have been examined. diff --git a/arch/risc-v/src/mpfs/mpfs_ethernet.c b/arch/risc-v/src/mpfs/mpfs_ethernet.c index d36e9adb2e..5e17e7c5b5 100644 --- a/arch/risc-v/src/mpfs/mpfs_ethernet.c +++ b/arch/risc-v/src/mpfs/mpfs_ethernet.c @@ -1411,53 +1411,21 @@ static int mpfs_txpoll(struct net_driver_s *dev) { struct mpfs_ethmac_s *priv = (struct mpfs_ethmac_s *)dev->d_private; - /* If the polling resulted in data that should be sent out on the network, - * the field d_len is set to a value > 0. + /* Send the packet */ + + mpfs_transmit(priv, 0); + + /* Check if there are any free TX descriptors. We cannot perform + * the TX poll if we do not have buffering for another packet. */ - if (priv->dev.d_len > 0) + if (mpfs_txfree(priv, 0) == 0) { - /* Look up the destination MAC address and add it to the Ethernet - * header. + /* We have to terminate the poll if we have no more descriptors + * available for another transfer. */ - #ifdef CONFIG_NET_IPv4 - #ifdef CONFIG_NET_IPv6 - if (IFF_IS_IPv4(priv->dev.d_flags)) - #endif - { - arp_out(&priv->dev); - } - #endif /* CONFIG_NET_IPv4 */ - - #ifdef CONFIG_NET_IPv6 - #ifdef CONFIG_NET_IPv4 - else - #endif - { - neighbor_out(&priv->dev); - } - #endif /* CONFIG_NET_IPv6 */ - - if (!devif_loopback(&priv->dev)) - { - /* Send the packet */ - - mpfs_transmit(priv, 0); - - /* Check if there are any free TX descriptors. We cannot perform - * the TX poll if we do not have buffering for another packet. - */ - - if (mpfs_txfree(priv, 0) == 0) - { - /* We have to terminate the poll if we have no more descriptors - * available for another transfer. - */ - - return -EBUSY; - } - } + return -EBUSY; } /* If zero is returned, the polling will continue until all connections diff --git a/arch/sim/src/sim/sim_netdriver.c b/arch/sim/src/sim/sim_netdriver.c index 4b85c281fd..dc85e4a139 100644 --- a/arch/sim/src/sim/sim_netdriver.c +++ b/arch/sim/src/sim/sim_netdriver.c @@ -260,54 +260,11 @@ static int netdriver_txpoll(struct net_driver_s *dev) UNUSED(devidx); - /* If the polling resulted in data that should be sent out on the network, - * the field d_len is set to a value > 0. - */ + /* Send the packet */ - if (dev->d_len > 0) - { - /* Look up the destination MAC address and add it to the Ethernet - * header. - */ - -#ifdef CONFIG_NET_IPv4 -#ifdef CONFIG_NET_IPv6 - if (IFF_IS_IPv4(dev->d_flags)) -#endif - { - arp_out(dev); - } -#endif /* CONFIG_NET_IPv4 */ - -#ifdef CONFIG_NET_IPv6 -#ifdef CONFIG_NET_IPv4 - else -#endif - { - neighbor_out(dev); - } -#endif /* CONFIG_NET_IPv6 */ - - if (!devif_loopback(dev)) - { - /* Send the packet */ - - NETDEV_TXPACKETS(dev); - sim_netdev_send(devidx, dev->d_buf, dev->d_len); - NETDEV_TXDONE(dev); - } - else - { - /* Calling txdone callback after loopback. NETDEV_TXDONE macro is - * already called in devif_loopback. - * - * TODO: Maybe a unified interface with txdone callback registered - * is needed, then we can let devif_loopback call this callback. - */ - - netdriver_txdone_interrupt(dev); - } - } + NETDEV_TXPACKETS(dev); + sim_netdev_send(devidx, dev->d_buf, dev->d_len); + NETDEV_TXDONE(dev); /* If zero is returned, the polling will continue until all connections * have been examined. diff --git a/arch/xtensa/src/esp32/esp32_emac.c b/arch/xtensa/src/esp32/esp32_emac.c index cd2925b4ec..a5ed30d60a 100644 --- a/arch/xtensa/src/esp32/esp32_emac.c +++ b/arch/xtensa/src/esp32/esp32_emac.c @@ -1583,67 +1583,33 @@ static int emac_txpoll(struct net_driver_s *dev) DEBUGASSERT(priv->dev.d_buf != NULL); - /* If the polling resulted in data that should be sent out on the network, - * the field d_len is set to a value == 0. + /* Send the packet */ + + emac_transmit(priv); + DEBUGASSERT(dev->d_len == 0 && dev->d_buf == NULL); + + /* Check if the current TX descriptor is owned by the Ethernet DMA + * or CPU. We cannot perform the TX poll if we are unable to accept + * another packet for transmission. */ - if (priv->dev.d_len == 0) + if (TX_IS_BUSY(priv)) { - return 0; - } - - /* Look up the destination MAC address and add it to the Ethernet - * header. - */ - -#ifdef CONFIG_NET_IPv4 -#ifdef CONFIG_NET_IPv6 - if (IFF_IS_IPv4(priv->dev.d_flags)) -#endif - { - arp_out(&priv->dev); - } -#endif /* CONFIG_NET_IPv4 */ - -#ifdef CONFIG_NET_IPv6 -#ifdef CONFIG_NET_IPv4 - else -#endif - { - neighbor_out(&priv->dev); - } -#endif /* CONFIG_NET_IPv6 */ - - if (!devif_loopback(&priv->dev)) - { - /* Send the packet */ - - emac_transmit(priv); - DEBUGASSERT(dev->d_len == 0 && dev->d_buf == NULL); - - /* Check if the current TX descriptor is owned by the Ethernet DMA - * or CPU. We cannot perform the TX poll if we are unable to accept - * another packet for transmission. + /* We have to terminate the poll if we have no more descriptors + * available for another transfer. */ - if (TX_IS_BUSY(priv)) - { - /* We have to terminate the poll if we have no more descriptors - * available for another transfer. - */ - - return -EBUSY; - } - - dev->d_buf = (uint8_t *)emac_alloc_buffer(priv); - if (dev->d_buf == NULL) - { - return -ENOMEM; - } - - dev->d_len = EMAC_BUF_LEN; + return -EBUSY; } + dev->d_buf = (uint8_t *)emac_alloc_buffer(priv); + if (dev->d_buf == NULL) + { + return -ENOMEM; + } + + dev->d_len = EMAC_BUF_LEN; + /* If zero is returned, the polling will continue until all connections * have been examined. */ diff --git a/arch/xtensa/src/esp32/esp32_wlan.c b/arch/xtensa/src/esp32/esp32_wlan.c index 9a5c71d93a..f279051a1e 100644 --- a/arch/xtensa/src/esp32/esp32_wlan.c +++ b/arch/xtensa/src/esp32/esp32_wlan.c @@ -880,46 +880,17 @@ static int wlan_txpoll(struct net_driver_s *dev) DEBUGASSERT(dev->d_buf != NULL); - /* If the polling resulted in data that should be sent out on the network, - * the field d_len is set to a value > 0. - */ + wlan_cache_txpkt_tail(priv); - if (dev->d_len > 0) + pktbuf = wlan_alloc_buffer(priv); + if (!pktbuf) { - /* Look up the destination MAC address and add it to the Ethernet - * header. - */ - -#ifdef CONFIG_NET_IPv4 -#ifdef CONFIG_NET_IPv6 - if (IFF_IS_IPv4(dev->d_flags)) -#endif - { - arp_out(dev); - } -#endif /* CONFIG_NET_IPv4 */ - -#ifdef CONFIG_NET_IPv6 -#ifdef CONFIG_NET_IPv4 - else -#endif - { - neighbor_out(dev); - } -#endif /* CONFIG_NET_IPv6 */ - - wlan_cache_txpkt_tail(priv); - - pktbuf = wlan_alloc_buffer(priv); - if (!pktbuf) - { - return -ENOMEM; - } - - dev->d_buf = pktbuf->buffer; - dev->d_len = WLAN_BUF_SIZE; + return -ENOMEM; } + dev->d_buf = pktbuf->buffer; + dev->d_len = WLAN_BUF_SIZE; + /* If zero is returned, the polling will continue until * all connections have been examined. */ diff --git a/arch/z80/src/ez80/ez80_emac.c b/arch/z80/src/ez80/ez80_emac.c index 1bbb0d1509..4742e52cc2 100644 --- a/arch/z80/src/ez80/ez80_emac.c +++ b/arch/z80/src/ez80/ez80_emac.c @@ -1151,52 +1151,12 @@ static int ez80emac_txpoll(FAR struct net_driver_s *dev) { FAR struct ez80emac_driver_s *priv = (FAR struct ez80emac_driver_s *)dev->d_private; - int ret = 0; - /* If the polling resulted in data that should be sent out on the network, - * the field d_len is set to a value > 0. + /* Send the packet. ez80emac_transmit() will return zero if the + * packet was successfully handled. */ - ninfo("Poll result: d_len=%d\n", priv->dev.d_len); - if (priv->dev.d_len > 0) - { - /* Look up the destination MAC address and add it to the Ethernet - * header. - */ - -#ifdef CONFIG_NET_IPv4 -#ifdef CONFIG_NET_IPv6 - if (IFF_IS_IPv4(priv->dev.d_flags)) -#endif - { - arp_out(&priv->dev); - } -#endif /* CONFIG_NET_IPv4 */ - -#ifdef CONFIG_NET_IPv6 -#ifdef CONFIG_NET_IPv4 - else -#endif - { - neighbor_out(&priv->dev); - } -#endif /* CONFIG_NET_IPv6 */ - - if (!devif_loopback(&priv->dev)) - { - /* Send the packet. ez80emac_transmit() will return zero if the - * packet was successfully handled. - */ - - ret = ez80emac_transmit(priv); - } - } - - /* If zero is returned, the polling will continue until all connections - * have been examined. - */ - - return ret; + return ez80emac_transmit(priv); } /**************************************************************************** diff --git a/drivers/net/dm90x0.c b/drivers/net/dm90x0.c index 5c69905ee1..1af51eabdf 100644 --- a/drivers/net/dm90x0.c +++ b/drivers/net/dm90x0.c @@ -782,58 +782,22 @@ static int dm9x_txpoll(FAR struct net_driver_s *dev) FAR struct dm9x_driver_s *priv = (FAR struct dm9x_driver_s *)dev->d_private; - /* If the polling resulted in data that should be sent out on the network, - * the field d_len is set to a value > 0. + /* Send the packet */ + + dm9x_transmit(priv); + + /* Check if there is room in the DM90x0 to hold another packet. + * In 100M mode, that can be 2 packets, otherwise it is a single + * packet. */ - if (priv->dm_dev.d_len > 0) + if (priv->dm_ntxpending > 1 || !priv->dm_b100m) { - /* Look up the destination MAC address and add it to the Ethernet - * header. - */ + /* Returning a non-zero value terminate the poll operation */ -#ifdef CONFIG_NET_IPv4 -#ifdef CONFIG_NET_IPv6 - if (IFF_IS_IPv4(priv->dm_dev.d_flags)) -#endif - { - arp_out(&priv->dm_dev); - } -#endif /* CONFIG_NET_IPv4 */ - -#ifdef CONFIG_NET_IPv6 -#ifdef CONFIG_NET_IPv4 - else -#endif - { - neighbor_out(&priv->dm_dev); - } -#endif /* CONFIG_NET_IPv6 */ - - if (!devif_loopback(&priv->dm_dev)) - { - /* Send the packet */ - - dm9x_transmit(priv); - - /* Check if there is room in the DM90x0 to hold another packet. - * In 100M mode, that can be 2 packets, otherwise it is a single - * packet. - */ - - if (priv->dm_ntxpending > 1 || !priv->dm_b100m) - { - /* Returning a non-zero value terminate the poll operation */ - - return 1; - } - } + return 1; } - /* If zero is returned, the polling will continue until all connections - * have been examined. - */ - return 0; } diff --git a/drivers/net/enc28j60.c b/drivers/net/enc28j60.c index 326b5254fb..65a276346f 100644 --- a/drivers/net/enc28j60.c +++ b/drivers/net/enc28j60.c @@ -1175,52 +1175,13 @@ static int enc_txpoll(struct net_driver_s *dev) { FAR struct enc_driver_s *priv = (FAR struct enc_driver_s *)dev->d_private; - /* If the polling resulted in data that should be sent out on the network, - * the field d_len is set to a value > 0. - */ + /* Send the packet */ - ninfo("Poll result: d_len=%d\n", priv->dev.d_len); - if (priv->dev.d_len > 0) - { - /* Look up the destination MAC address and add it to the Ethernet - * header. - */ + enc_transmit(priv); -#ifdef CONFIG_NET_IPv4 -#ifdef CONFIG_NET_IPv6 - if (IFF_IS_IPv4(priv->dev.d_flags)) -#endif - { - arp_out(&priv->dev); - } -#endif /* CONFIG_NET_IPv4 */ + /* Stop the poll now because we can queue only one packet */ -#ifdef CONFIG_NET_IPv6 -#ifdef CONFIG_NET_IPv4 - else -#endif - { - neighbor_out(&priv->dev); - } -#endif /* CONFIG_NET_IPv6 */ - - if (!devif_loopback(&priv->dev)) - { - /* Send the packet */ - - enc_transmit(priv); - - /* Stop the poll now because we can queue only one packet */ - - return -EBUSY; - } - } - - /* If zero is returned, the polling will continue until all connections - * have been examined. - */ - - return OK; + return -EBUSY; } /**************************************************************************** diff --git a/drivers/net/encx24j600.c b/drivers/net/encx24j600.c index 2bdbacba0e..9a4dbcabff 100644 --- a/drivers/net/encx24j600.c +++ b/drivers/net/encx24j600.c @@ -1146,51 +1146,8 @@ static int enc_txenqueue(FAR struct enc_driver_s *priv) static int enc_txpoll(struct net_driver_s *dev) { FAR struct enc_driver_s *priv = (FAR struct enc_driver_s *)dev->d_private; - int ret = OK; - /* If the polling resulted in data that should be sent out on the network, - * the field d_len is set to a value > 0. - */ - - ninfo("Poll result: d_len=%d\n", priv->dev.d_len); - - if (priv->dev.d_len > 0) - { - /* Look up the destination MAC address and add it to the Ethernet - * header. - */ - -#ifdef CONFIG_NET_IPv4 -#ifdef CONFIG_NET_IPv6 - if (IFF_IS_IPv4(priv->dev.d_flags)) -#endif - { - arp_out(&priv->dev); - } -#endif /* CONFIG_NET_IPv4 */ - -#ifdef CONFIG_NET_IPv6 -#ifdef CONFIG_NET_IPv4 - else -#endif - { - neighbor_out(&priv->dev); - } -#endif /* CONFIG_NET_IPv6 */ - - if (!devif_loopback(&priv->dev)) - { - /* Send the packet */ - - ret = enc_txenqueue(priv); - } - } - - /* If zero is returned, the polling will continue until all connections - * have been examined. - */ - - return ret; + return enc_txenqueue(priv); } /**************************************************************************** diff --git a/drivers/net/ftmac100.c b/drivers/net/ftmac100.c index 1de52eaad4..5cd26be1d5 100644 --- a/drivers/net/ftmac100.c +++ b/drivers/net/ftmac100.c @@ -345,45 +345,9 @@ static int ftmac100_txpoll(struct net_driver_s *dev) FAR struct ftmac100_driver_s *priv = (FAR struct ftmac100_driver_s *)dev->d_private; - /* If the polling resulted in data that should be sent out on the network, - * the field d_len is set to a value > 0. - */ + /* Send the packet */ - if (priv->ft_dev.d_len > 0) - { - /* Look up the destination MAC address and add it to the Ethernet - * header. - */ - -#ifdef CONFIG_NET_IPv4 -#ifdef CONFIG_NET_IPv6 - if (IFF_IS_IPv4(priv->ft_dev.d_flags)) -#endif - { - arp_out(&priv->ft_dev); - } -#endif /* CONFIG_NET_IPv4 */ - -#ifdef CONFIG_NET_IPv6 -#ifdef CONFIG_NET_IPv4 - else -#endif - { - neighbor_out(&priv->ft_dev); - } -#endif /* CONFIG_NET_IPv6 */ - - if (!devif_loopback(&priv->ft_dev)) - { - /* Send the packet */ - - ftmac100_transmit(priv); - - /* Check if there is room in the device to hold another packet. If - * not, return a non-zero value to terminate the poll. - */ - } - } + ftmac100_transmit(priv); /* If zero is returned, the polling will continue until all connections * have been examined. diff --git a/drivers/net/lan91c111.c b/drivers/net/lan91c111.c index ef78e21608..fcf1499be3 100644 --- a/drivers/net/lan91c111.c +++ b/drivers/net/lan91c111.c @@ -496,49 +496,15 @@ static int lan91c111_txpoll(FAR struct net_driver_s *dev) { FAR struct lan91c111_driver_s *priv = dev->d_private; - /* If the polling resulted in data that should be sent out on the network, - * the field d_len is set to a value > 0. + /* Send the packet */ + + lan91c111_transmit(dev); + + /* Check if there is room in the device to hold another packet. If + * not, return a non-zero value to terminate the poll. */ - if (dev->d_len > 0) - { - /* Look up the destination MAC address and add it to the Ethernet - * header. - */ - -#ifdef CONFIG_NET_IPv4 - if (IFF_IS_IPv4(dev->d_flags)) - { - arp_out(dev); - } -#endif /* CONFIG_NET_IPv4 */ - -#ifdef CONFIG_NET_IPv6 - if (IFF_IS_IPv6(dev->d_flags)) - { - neighbor_out(dev); - } -#endif /* CONFIG_NET_IPv6 */ - - if (!devif_loopback(dev)) - { - /* Send the packet */ - - lan91c111_transmit(dev); - - /* Check if there is room in the device to hold another packet. If - * not, return a non-zero value to terminate the poll. - */ - - return !(getreg16(priv, MIR_REG) & MIR_FREE_MASK); - } - } - - /* If zero is returned, the polling will continue until all connections - * have been examined. - */ - - return 0; + return !(getreg16(priv, MIR_REG) & MIR_FREE_MASK); } /**************************************************************************** diff --git a/drivers/net/rpmsgdrv.c b/drivers/net/rpmsgdrv.c index d919db4ae9..0595776d51 100644 --- a/drivers/net/rpmsgdrv.c +++ b/drivers/net/rpmsgdrv.c @@ -255,56 +255,22 @@ static int net_rpmsg_drv_txpoll(FAR struct net_driver_s *dev) FAR struct net_rpmsg_drv_s *priv = dev->d_private; uint32_t size; - /* If the polling resulted in data that should be sent out on the network, - * the field d_len is set to a value > 0. + /* Send the packet */ + + net_rpmsg_drv_transmit(dev, true); + + /* Check if there is room in the device to hold another packet. If + * not, return a non-zero value to terminate the poll. */ - if (dev->d_len > 0) + dev->d_buf = rpmsg_get_tx_payload_buffer(&priv->ept, &size, false); + if (dev->d_buf) { - /* Look up the destination MAC address and add it to the Ethernet - * header. - */ - -#ifdef CONFIG_NET_IPv4 - if (IFF_IS_IPv4(dev->d_flags)) - { - arp_out(dev); - } -#endif /* CONFIG_NET_IPv4 */ - -#ifdef CONFIG_NET_IPv6 - if (IFF_IS_IPv6(dev->d_flags)) - { - neighbor_out(dev); - } -#endif /* CONFIG_NET_IPv6 */ - - if (!devif_loopback(dev)) - { - /* Send the packet */ - - net_rpmsg_drv_transmit(dev, true); - - /* Check if there is room in the device to hold another packet. If - * not, return a non-zero value to terminate the poll. - */ - - dev->d_buf = rpmsg_get_tx_payload_buffer(&priv->ept, &size, false); - if (dev->d_buf) - { - dev->d_buf += sizeof(struct net_rpmsg_transfer_s); - dev->d_pktsize = size - sizeof(struct net_rpmsg_transfer_s); - } - - return dev->d_buf == NULL; - } + dev->d_buf += sizeof(struct net_rpmsg_transfer_s); + dev->d_pktsize = size - sizeof(struct net_rpmsg_transfer_s); } - /* If zero is returned, the polling will continue until all connections - * have been examined. - */ - - return 0; + return dev->d_buf == NULL; } /**************************************************************************** diff --git a/drivers/net/skeleton.c b/drivers/net/skeleton.c index d738e610ec..e9387180b0 100644 --- a/drivers/net/skeleton.c +++ b/drivers/net/skeleton.c @@ -255,50 +255,9 @@ static int skel_txpoll(FAR struct net_driver_s *dev) FAR struct skel_driver_s *priv = (FAR struct skel_driver_s *)dev->d_private; - /* If the polling resulted in data that should be sent out on the network, - * the field d_len is set to a value > 0. - */ + /* Send the packet */ - if (priv->sk_dev.d_len > 0) - { - /* Look up the destination MAC address and add it to the Ethernet - * header. - */ - -#ifdef CONFIG_NET_IPv4 -#ifdef CONFIG_NET_IPv6 - if (IFF_IS_IPv4(priv->sk_dev.d_flags)) -#endif - { - arp_out(&priv->sk_dev); - } -#endif /* CONFIG_NET_IPv4 */ - -#ifdef CONFIG_NET_IPv6 -#ifdef CONFIG_NET_IPv4 - else -#endif - { - neighbor_out(&priv->sk_dev); - } -#endif /* CONFIG_NET_IPv6 */ - - /* Check if the network is sending this packet to the IP address of - * this device. If so, just loop the packet back into the network but - * don't attempt to put it on the wire. - */ - - if (!devif_loopback(&priv->sk_dev)) - { - /* Send the packet */ - - skel_transmit(priv); - - /* Check if there is room in the device to hold another packet. - * If not, return a non-zero value to terminate the poll. - */ - } - } + skel_transmit(priv); /* If zero is returned, the polling will continue until all connections * have been examined. diff --git a/drivers/net/slip.c b/drivers/net/slip.c index 2a54247737..1501538f5e 100644 --- a/drivers/net/slip.c +++ b/drivers/net/slip.c @@ -355,17 +355,7 @@ static int slip_txpoll(FAR struct net_driver_s *dev) FAR struct slip_driver_s *priv = (FAR struct slip_driver_s *)dev->d_private; - /* If the polling resulted in data that should be sent out on the network, - * the field d_len is set to a value > 0. - */ - - if (priv->dev.d_len > 0) - { - if (!devif_loopback(&priv->dev)) - { - slip_transmit(priv); - } - } + slip_transmit(priv); /* If zero is returned, the polling will continue until all connections * have been examined. diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 359b7a4648..c0935a77ee 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -358,46 +358,12 @@ static int tun_txpoll_tap(FAR struct net_driver_s *dev) { FAR struct tun_device_s *priv = (FAR struct tun_device_s *)dev->d_private; - /* If the polling resulted in data that should be sent out on the network, - * the field d_len is set to a value > 0. - */ + /* Send the packet */ - if (priv->dev.d_len > 0) - { - /* Look up the destination MAC address and add it to the Ethernet - * header. - */ + priv->read_d_len = priv->dev.d_len; + tun_fd_transmit(priv); -#ifdef CONFIG_NET_IPv4 - if (IFF_IS_IPv4(priv->dev.d_flags)) - { - arp_out(&priv->dev); - } -#endif /* CONFIG_NET_IPv4 */ - -#ifdef CONFIG_NET_IPv6 - if (IFF_IS_IPv6(priv->dev.d_flags)) - { - neighbor_out(&priv->dev); - } -#endif /* CONFIG_NET_IPv6 */ - - if (!devif_loopback(dev)) - { - /* Send the packet */ - - priv->read_d_len = priv->dev.d_len; - tun_fd_transmit(priv); - - return 1; - } - } - - /* If zero is returned, the polling will continue until all connections - * have been examined. - */ - - return 0; + return 1; } #endif @@ -430,28 +396,10 @@ static int tun_txpoll_tun(FAR struct net_driver_s *dev) { FAR struct tun_device_s *priv = (FAR struct tun_device_s *)dev->d_private; - /* If the polling resulted in data that should be sent out on the network, - * the field d_len is set to a value > 0. - */ + priv->read_d_len = priv->dev.d_len; + tun_fd_transmit(priv); - if (priv->dev.d_len > 0) - { - if (!devif_loopback(dev)) - { - /* Send the packet */ - - priv->read_d_len = priv->dev.d_len; - tun_fd_transmit(priv); - - return 1; - } - } - - /* If zero is returned, the polling will continue until all connections - * have been examined. - */ - - return 0; + return 1; } /**************************************************************************** diff --git a/drivers/net/w5500.c b/drivers/net/w5500.c index 74fd8491f8..6d659d8319 100644 --- a/drivers/net/w5500.c +++ b/drivers/net/w5500.c @@ -1186,57 +1186,15 @@ static int w5500_txpoll(FAR struct net_driver_s *dev) FAR struct w5500_driver_s *self = (FAR struct w5500_driver_s *)dev->d_private; - /* If the polling resulted in data that should be sent out on the network, - * the field d_len is set to a value > 0. + /* Send the packet */ + + w5500_transmit(self); + + /* Check if there is room in the device to hold another packet. + * If not, return a non-zero value to terminate the poll. */ - if (self->w_dev.d_len > 0) - { - /* Look up the destination MAC address and add it to the Ethernet - * header. - */ - -#ifdef CONFIG_NET_IPv4 - if (IFF_IS_IPv4(self->w_dev.d_flags)) - { - arp_out(&self->w_dev); - } -#endif /* CONFIG_NET_IPv4 */ - -#ifdef CONFIG_NET_IPv6 - if (IFF_IS_IPv6(self->w_dev.d_flags)) - { - neighbor_out(&self->w_dev); - } -#endif /* CONFIG_NET_IPv6 */ - - /* Check if the network is sending this packet to the IP address of - * this device. If so, just loop the packet back into the network but - * don't attempt to put it on the wire. - */ - - if (!devif_loopback(&self->w_dev)) - { - /* Send the packet */ - - w5500_transmit(self); - - /* Check if there is room in the device to hold another packet. - * If not, return a non-zero value to terminate the poll. - */ - - if (!w5500_txbuf_numfree(self)) - { - return -EBUSY; - } - } - } - - /* If zero is returned, the polling will continue until all connections - * have been examined. - */ - - return OK; + return !w5500_txbuf_numfree(self); } /**************************************************************************** diff --git a/drivers/usbdev/cdcecm.c b/drivers/usbdev/cdcecm.c index 554459ebac..7bc5b4e9ec 100644 --- a/drivers/usbdev/cdcecm.c +++ b/drivers/usbdev/cdcecm.c @@ -340,53 +340,15 @@ static int cdcecm_txpoll(FAR struct net_driver_s *dev) FAR struct cdcecm_driver_s *priv = (FAR struct cdcecm_driver_s *)dev->d_private; - /* If the polling resulted in data that should be sent out on the network, - * the field d_len is set to a value > 0. + /* Send the packet */ + + cdcecm_transmit(priv); + + /* Check if there is room in the device to hold another packet. If + * not, return a non-zero value to terminate the poll. */ - if (priv->dev.d_len > 0) - { - /* Look up the destination MAC address and add it to the Ethernet - * header. - */ - -#ifdef CONFIG_NET_IPv4 -#ifdef CONFIG_NET_IPv6 - if (IFF_IS_IPv4(priv->dev.d_flags)) -#endif - { - arp_out(&priv->dev); - } -#endif /* CONFIG_NET_IPv4 */ - -#ifdef CONFIG_NET_IPv6 -#ifdef CONFIG_NET_IPv4 - else -#endif - { - neighbor_out(&priv->dev); - } -#endif /* CONFIG_NET_IPv6 */ - - if (!devif_loopback(&priv->dev)) - { - /* Send the packet */ - - cdcecm_transmit(priv); - - /* Check if there is room in the device to hold another packet. If - * not, return a non-zero value to terminate the poll. - */ - - return 1; - } - } - - /* If zero is returned, the polling will continue until all connections - * have been examined. - */ - - return 0; + return 1; } /**************************************************************************** diff --git a/drivers/usbdev/rndis.c b/drivers/usbdev/rndis.c index 2fa3467a1f..5b2775ab10 100644 --- a/drivers/usbdev/rndis.c +++ b/drivers/usbdev/rndis.c @@ -983,53 +983,13 @@ static void rndis_rxdispatch(FAR void *arg) static int rndis_txpoll(FAR struct net_driver_s *dev) { FAR struct rndis_dev_s *priv = (FAR struct rndis_dev_s *)dev->d_private; - int ret = OK; if (!priv->connected) { return -EBUSY; } - /* If the polling resulted in data that should be sent out on the network, - * the field d_len is set to a value > 0. - */ - - ninfo("Poll result: d_len=%d\n", priv->netdev.d_len); - if (priv->netdev.d_len > 0) - { - /* Look up the destination MAC address and add it to the Ethernet - * header. - */ - -#ifdef CONFIG_NET_IPv4 -#ifdef CONFIG_NET_IPv6 - if (IFF_IS_IPv4(priv->netdev.d_flags)) -#endif - { - arp_out(&priv->netdev); - } -#endif /* CONFIG_NET_IPv4 */ - -#ifdef CONFIG_NET_IPv6 -#ifdef CONFIG_NET_IPv4 - else -#endif - { - neighbor_out(&priv->netdev); - } -#endif /* CONFIG_NET_IPv6 */ - - if (!devif_loopback(&priv->netdev)) - { - ret = rndis_transmit(priv); - } - } - - /* If zero is returned, the polling will continue until all connections - * have been examined. - */ - - return ret; + return rndis_transmit(priv); } /**************************************************************************** diff --git a/drivers/usbhost/usbhost_cdcmbim.c b/drivers/usbhost/usbhost_cdcmbim.c index 2f29be0aff..a59ecce323 100644 --- a/drivers/usbhost/usbhost_cdcmbim.c +++ b/drivers/usbhost/usbhost_cdcmbim.c @@ -2277,15 +2277,9 @@ static int cdcmbim_txpoll(struct net_driver_s *dev) nxmutex_lock(&priv->lock); - if (priv->netdev.d_len > 0) - { - if (!devif_loopback(&priv->netdev)) - { - /* Send the packet */ + /* Send the packet */ - cdcmbim_transmit(priv); - } - } + cdcmbim_transmit(priv); nxmutex_unlock(&priv->lock); diff --git a/drivers/wireless/ieee80211/bcm43xxx/bcmf_netdev.c b/drivers/wireless/ieee80211/bcm43xxx/bcmf_netdev.c index 7ab7f83898..e5e4b1ff31 100644 --- a/drivers/wireless/ieee80211/bcm43xxx/bcmf_netdev.c +++ b/drivers/wireless/ieee80211/bcm43xxx/bcmf_netdev.c @@ -436,54 +436,16 @@ static int bcmf_txpoll(FAR struct net_driver_s *dev) { FAR struct bcmf_dev_s *priv = (FAR struct bcmf_dev_s *)dev->d_private; - /* If the polling resulted in data that should be sent out on the network, - * the field d_len is set to a value > 0. + /* Send the packet */ + + bcmf_transmit(priv, priv->cur_tx_frame); + + /* TODO: Check if there is room in the device to hold another + * packet. If not, return a non-zero value to terminate the poll. */ - if (priv->bc_dev.d_len > 0) - { - /* Look up the destination MAC address and add it to the Ethernet - * header. - */ - -#ifdef CONFIG_NET_IPv4 -#ifdef CONFIG_NET_IPv6 - if (IFF_IS_IPv4(priv->bc_dev.d_flags)) -#endif - { - arp_out(&priv->bc_dev); - } -#endif /* CONFIG_NET_IPv4 */ - -#ifdef CONFIG_NET_IPv6 -#ifdef CONFIG_NET_IPv4 - else -#endif - { - neighbor_out(&priv->bc_dev); - } -#endif /* CONFIG_NET_IPv6 */ - - if (!devif_loopback(&priv->bc_dev)) - { - /* Send the packet */ - - bcmf_transmit(priv, priv->cur_tx_frame); - - /* TODO: Check if there is room in the device to hold another - * packet. If not, return a non-zero value to terminate the poll. - */ - - priv->cur_tx_frame = NULL; - return 1; - } - } - - /* If zero is returned, the polling will continue until all connections - * have been examined. - */ - - return 0; + priv->cur_tx_frame = NULL; + return 1; } /**************************************************************************** diff --git a/include/nuttx/net/netdev.h b/include/nuttx/net/netdev.h index 2c044ee638..0c6e628abf 100644 --- a/include/nuttx/net/netdev.h +++ b/include/nuttx/net/netdev.h @@ -594,23 +594,6 @@ int devif_poll(FAR struct net_driver_s *dev, devif_poll_callback_t callback); void neighbor_out(FAR struct net_driver_s *dev); #endif /* CONFIG_NET_IPv6 */ -/**************************************************************************** - * Name: devif_loopback - * - * Description: - * This function should be called before sending out a packet. The function - * checks the destination address of the packet to see whether the target - * of packet is ourself and then consume the packet directly by calling - * input process functions. - * - * Returned Value: - * Zero is returned if the packet don't loop back to ourself, otherwise - * a non-zero value is returned. - * - ****************************************************************************/ - -int devif_loopback(FAR struct net_driver_s *dev); - /**************************************************************************** * Name: netdev_ifup / netdev_ifdown * diff --git a/net/devif/devif.h b/net/devif/devif.h index 2e9c46f41e..ea96ac6f20 100644 --- a/net/devif/devif.h +++ b/net/devif/devif.h @@ -528,6 +528,23 @@ void devif_can_send(FAR struct net_driver_s *dev, FAR const void *buf, int devif_out(FAR struct net_driver_s *dev, devif_poll_callback_t callback); +/**************************************************************************** + * Name: devif_loopback + * + * Description: + * This function should be called before sending out a packet. The function + * checks the destination address of the packet to see whether the target + * of packet is ourself and then consume the packet directly by calling + * input process functions. + * + * Returned Value: + * Zero is returned if the packet don't loop back to ourself, otherwise + * a non-zero value is returned. + * + ****************************************************************************/ + +int devif_loopback(FAR struct net_driver_s *dev); + #undef EXTERN #ifdef __cplusplus } diff --git a/net/devif/devif_poll.c b/net/devif/devif_poll.c index 47aea719da..d728e6d1f2 100644 --- a/net/devif/devif_poll.c +++ b/net/devif/devif_poll.c @@ -31,6 +31,7 @@ #include #include #include +#include #include "devif/devif.h" #include "arp/arp.h" @@ -785,11 +786,43 @@ int devif_poll(FAR struct net_driver_s *dev, devif_poll_callback_t callback) int devif_out(FAR struct net_driver_s *dev, devif_poll_callback_t callback) { + int bstop; + if (dev->d_len == 0) { return 0; } + bstop = devif_loopback(dev); + if (bstop) + { + return bstop; + } + +#ifdef CONFIG_NET_ETHERNET + if (dev->d_lltype == NET_LL_ETHERNET || + dev->d_lltype == NET_LL_IEEE80211) + { +# ifdef CONFIG_NET_IPv4 +# ifdef CONFIG_NET_IPv6 + if (IFF_IS_IPv4(dev->d_flags)) +# endif /* CONFIG_NET_IPv6 */ + { + arp_out(dev); + } +# endif /* CONFIG_NET_IPv4 */ + +# ifdef CONFIG_NET_IPv6 +# ifdef CONFIG_NET_IPv4 + else +# endif /* CONFIG_NET_IPv4 */ + { + neighbor_out(dev); + } +# endif /* CONFIG_NET_IPv6 */ + } +#endif /* CONFIG_NET_ETHERNET */ + return callback(dev); }