diff --git a/arch/arm/src/c5471/c5471_ethernet.c b/arch/arm/src/c5471/c5471_ethernet.c index 7b1dab22a37..13a7549516a 100644 --- a/arch/arm/src/c5471/c5471_ethernet.c +++ b/arch/arm/src/c5471/c5471_ethernet.c @@ -1046,19 +1046,22 @@ static int c5471_txpoll(struct net_driver_s *dev) } #endif /* CONFIG_NET_IPv6 */ - /* 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) + if (!devif_loopback_out(&priv->c_dev)) { - /* No, then return non-zero to terminate the poll */ + /* Send the packet */ - return 1; + 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; + } } } diff --git a/arch/arm/src/imxrt/imxrt_enet.c b/arch/arm/src/imxrt/imxrt_enet.c index d92eeb87a44..73b88f105f5 100644 --- a/arch/arm/src/imxrt/imxrt_enet.c +++ b/arch/arm/src/imxrt/imxrt_enet.c @@ -600,20 +600,23 @@ static int imxrt_txpoll(struct net_driver_s *dev) } #endif /* CONFIG_NET_IPv6 */ - /* 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)) + if (!devif_loopback_out(&priv->dev)) { - return -EBUSY; - } + /* 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; + } + } } /* If zero is returned, the polling will continue until all connections have diff --git a/arch/arm/src/kinetis/kinetis_enet.c b/arch/arm/src/kinetis/kinetis_enet.c index d607bbc9819..c73d7f76e04 100644 --- a/arch/arm/src/kinetis/kinetis_enet.c +++ b/arch/arm/src/kinetis/kinetis_enet.c @@ -571,19 +571,22 @@ static int kinetis_txpoll(struct net_driver_s *dev) } #endif /* CONFIG_NET_IPv6 */ - /* 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)) + if (!devif_loopback_out(&priv->dev)) { - return -EBUSY; + /* 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; + } } } diff --git a/arch/arm/src/lpc17xx/lpc17_ethernet.c b/arch/arm/src/lpc17xx/lpc17_ethernet.c index 61b35a8f046..5205a474160 100644 --- a/arch/arm/src/lpc17xx/lpc17_ethernet.c +++ b/arch/arm/src/lpc17xx/lpc17_ethernet.c @@ -716,17 +716,20 @@ static int lpc17_txpoll(struct net_driver_s *dev) } #endif /* CONFIG_NET_IPv6 */ - /* Send this packet. In this context, we know that there is space for - * at least one more packet in the descriptor list. - */ + if (!devif_loopback_out(&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_transmit(priv); + lpc17_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. - */ + /* 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_txdesc(priv); + ret = lpc17_txdesc(priv); + } } /* If zero is returned, the polling will continue until all connections have diff --git a/arch/arm/src/lpc43xx/lpc43_ethernet.c b/arch/arm/src/lpc43xx/lpc43_ethernet.c index 5fbee8cfce3..83868772761 100644 --- a/arch/arm/src/lpc43xx/lpc43_ethernet.c +++ b/arch/arm/src/lpc43xx/lpc43_ethernet.c @@ -1165,44 +1165,47 @@ static int lpc43_txpoll(struct net_driver_s *dev) } #endif /* CONFIG_NET_IPv6 */ - /* 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) + if (!devif_loopback_out(&priv->dev)) { - /* We have to terminate the poll if we have no more descriptors - * available for another transfer. + /* 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). */ - return -EBUSY; - } + 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. + */ - /* We have the descriptor, we can continue the poll. Allocate a new - * buffer for the poll. - */ + return -EBUSY; + } - dev->d_buf = lpc43_allocbuffer(priv); + /* We have the descriptor, we can continue the poll. Allocate a new + * buffer for the poll. + */ - /* We can't continue the poll if we have no buffers */ + dev->d_buf = lpc43_allocbuffer(priv); - if (dev->d_buf == NULL) - { - /* Terminate the poll. */ + /* We can't continue the poll if we have no buffers */ - return -ENOMEM; + if (dev->d_buf == NULL) + { + /* Terminate the poll. */ + + return -ENOMEM; + } } } diff --git a/arch/arm/src/lpc54xx/lpc54_ethernet.c b/arch/arm/src/lpc54xx/lpc54_ethernet.c index b5c19c0ebbf..33f6553e726 100644 --- a/arch/arm/src/lpc54xx/lpc54_ethernet.c +++ b/arch/arm/src/lpc54xx/lpc54_ethernet.c @@ -790,49 +790,52 @@ static int lpc54_eth_txpoll(struct net_driver_s *dev) } #endif /* CONFIG_NET_IPv6 */ - /* 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) -#else - /* 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) -#endif + if (!devif_loopback_out(&priv->eth_dev)) { - /* Stop the poll.. no more Tx descriptors */ + /* Send the packet */ - return 1; - } + chan = lpc54_eth_getring(priv); + txring = &priv->eth_txring[chan]; - /* There is a free descriptor in the ring, allocate a new Tx buffer - * to perform the poll. - */ + (txring->tr_buffers)[txring->tr_supply] = + (uint32_t *)priv->eth_dev.d_buf; - 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 */ + lpc54_eth_transmit(priv, chan); - return 1; + 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) +#else + /* 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) +#endif + { + /* Stop the poll.. no more Tx descriptors */ + + return 1; + } + + /* 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 */ + + return 1; + } } } diff --git a/arch/arm/src/sam34/sam_emac.c b/arch/arm/src/sam34/sam_emac.c index e7015026899..02e4319a277 100644 --- a/arch/arm/src/sam34/sam_emac.c +++ b/arch/arm/src/sam34/sam_emac.c @@ -889,21 +889,24 @@ static int sam_txpoll(struct net_driver_s *dev) } #endif /* CONFIG_NET_IPv6 */ - /* 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) + if (!devif_loopback_out(&priv->dev)) { - /* We have to terminate the poll if we have no more descriptors - * available for another transfer. + /* 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. */ - return -EBUSY; + if (sam_txfree(priv) == 0) + { + /* We have to terminate the poll if we have no more descriptors + * available for another transfer. + */ + + return -EBUSY; + } } } diff --git a/arch/arm/src/sama5/sam_emaca.c b/arch/arm/src/sama5/sam_emaca.c index 27e323675ce..6c090382cac 100644 --- a/arch/arm/src/sama5/sam_emaca.c +++ b/arch/arm/src/sama5/sam_emaca.c @@ -898,21 +898,24 @@ static int sam_txpoll(struct net_driver_s *dev) } #endif /* CONFIG_NET_IPv6 */ - /* 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) + if (!devif_loopback_out(&priv->dev)) { - /* We have to terminate the poll if we have no more descriptors - * available for another transfer. + /* 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. */ - return -EBUSY; + if (sam_txfree(priv) == 0) + { + /* We have to terminate the poll if we have no more descriptors + * available for another transfer. + */ + + return -EBUSY; + } } } diff --git a/arch/arm/src/sama5/sam_emacb.c b/arch/arm/src/sama5/sam_emacb.c index c8e3704f902..b6d74855bb6 100644 --- a/arch/arm/src/sama5/sam_emacb.c +++ b/arch/arm/src/sama5/sam_emacb.c @@ -1233,21 +1233,24 @@ static int sam_txpoll(struct net_driver_s *dev) } #endif /* CONFIG_NET_IPv6 */ - /* 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) + if (!devif_loopback_out(&priv->dev)) { - /* We have to terminate the poll if we have no more descriptors - * available for another transfer. + /* 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. */ - return -EBUSY; + if (sam_txfree(priv) == 0) + { + /* We have to terminate the poll if we have no more descriptors + * available for another transfer. + */ + + return -EBUSY; + } } } diff --git a/arch/arm/src/sama5/sam_gmac.c b/arch/arm/src/sama5/sam_gmac.c index f61938939d8..99c664ae9f7 100644 --- a/arch/arm/src/sama5/sam_gmac.c +++ b/arch/arm/src/sama5/sam_gmac.c @@ -830,21 +830,24 @@ static int sam_txpoll(struct net_driver_s *dev) } #endif /* CONFIG_NET_IPv6 */ - /* 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) + if (!devif_loopback_out(&priv->dev)) { - /* We have to terminate the poll if we have no more descriptors - * available for another transfer. + /* 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. */ - return -EBUSY; + if (sam_txfree(priv) == 0) + { + /* We have to terminate the poll if we have no more descriptors + * available for another transfer. + */ + + return -EBUSY; + } } } diff --git a/arch/arm/src/samv7/sam_emac.c b/arch/arm/src/samv7/sam_emac.c index ca23ba8c224..a32d33f6436 100644 --- a/arch/arm/src/samv7/sam_emac.c +++ b/arch/arm/src/samv7/sam_emac.c @@ -1547,21 +1547,24 @@ static int sam_txpoll(struct net_driver_s *dev) } #endif /* CONFIG_NET_IPv6 */ - /* 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) + if (!devif_loopback_out(&priv->dev)) { - /* We have to terminate the poll if we have no more descriptors - * available for another transfer. + /* 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. */ - return -EBUSY; + 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; + } } } diff --git a/arch/arm/src/stm32/stm32_eth.c b/arch/arm/src/stm32/stm32_eth.c index 59913353012..99b194af8bc 100644 --- a/arch/arm/src/stm32/stm32_eth.c +++ b/arch/arm/src/stm32/stm32_eth.c @@ -1271,44 +1271,47 @@ static int stm32_txpoll(struct net_driver_s *dev) } #endif /* CONFIG_NET_IPv6 */ - /* 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->txhead->tdes0 & ETH_TDES0_OWN) != 0 || - priv->txhead->tdes2 != 0) + if (!devif_loopback_out(&priv->dev)) { - /* We have to terminate the poll if we have no more descriptors - * available for another transfer. + /* 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). */ - return -EBUSY; - } + 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. + */ - /* We have the descriptor, we can continue the poll. Allocate a new - * buffer for the poll. - */ + return -EBUSY; + } - dev->d_buf = stm32_allocbuffer(priv); + /* We have the descriptor, we can continue the poll. Allocate a new + * buffer for the poll. + */ - /* We can't continue the poll if we have no buffers */ + dev->d_buf = stm32_allocbuffer(priv); - if (dev->d_buf == NULL) - { - /* Terminate the poll. */ + /* We can't continue the poll if we have no buffers */ - return -ENOMEM; + if (dev->d_buf == NULL) + { + /* Terminate the poll. */ + + return -ENOMEM; + } } } diff --git a/arch/arm/src/stm32f7/stm32_ethernet.c b/arch/arm/src/stm32f7/stm32_ethernet.c index 04c9d9364fc..c80bf4d1eaf 100644 --- a/arch/arm/src/stm32f7/stm32_ethernet.c +++ b/arch/arm/src/stm32f7/stm32_ethernet.c @@ -1305,44 +1305,47 @@ static int stm32_txpoll(struct net_driver_s *dev) } #endif /* CONFIG_NET_IPv6 */ - /* 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->txhead->tdes0 & ETH_TDES0_OWN) != 0 || - priv->txhead->tdes2 != 0) + if (!devif_loopback_out(&priv->dev)) { - /* We have to terminate the poll if we have no more descriptors - * available for another transfer. + /* 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). */ - return -EBUSY; - } + 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. + */ - /* We have the descriptor, we can continue the poll. Allocate a new - * buffer for the poll. - */ + return -EBUSY; + } - dev->d_buf = stm32_allocbuffer(priv); + /* We have the descriptor, we can continue the poll. Allocate a new + * buffer for the poll. + */ - /* We can't continue the poll if we have no buffers */ + dev->d_buf = stm32_allocbuffer(priv); - if (dev->d_buf == NULL) - { - /* Terminate the poll. */ + /* We can't continue the poll if we have no buffers */ - return -ENOMEM; + if (dev->d_buf == NULL) + { + /* Terminate the poll. */ + + return -ENOMEM; + } } } diff --git a/arch/arm/src/tiva/lm3s_ethernet.c b/arch/arm/src/tiva/lm3s_ethernet.c index 291e1239b57..460ae9380cf 100644 --- a/arch/arm/src/tiva/lm3s_ethernet.c +++ b/arch/arm/src/tiva/lm3s_ethernet.c @@ -644,11 +644,14 @@ static int tiva_txpoll(struct net_driver_s *dev) } #endif /* CONFIG_NET_IPv6 */ - /* Send the packet. tiva_transmit() will return zero if the - * packet was successfully handled. - */ + if (!devif_loopback_out(&priv->ld_dev)) + { + /* Send the packet. tiva_transmit() will return zero if the + * packet was successfully handled. + */ - ret = tiva_transmit(priv); + ret = tiva_transmit(priv); + } } /* If zero is returned, the polling will continue until all connections have diff --git a/arch/arm/src/tiva/tm4c_ethernet.c b/arch/arm/src/tiva/tm4c_ethernet.c index da55ccaa13c..f8765b5f19d 100644 --- a/arch/arm/src/tiva/tm4c_ethernet.c +++ b/arch/arm/src/tiva/tm4c_ethernet.c @@ -1273,44 +1273,47 @@ static int tiva_txpoll(struct net_driver_s *dev) } #endif /* CONFIG_NET_IPv6 */ - /* 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->txhead->tdes0 & EMAC_TDES0_OWN) != 0 || - priv->txhead->tdes2 != 0) + if (!devif_loopback_out(&priv->dev)) { - /* We have to terminate the poll if we have no more descriptors - * available for another transfer. + /* 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). */ - return -EBUSY; - } + 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. + */ - /* We have the descriptor, we can continue the poll. Allocate a new - * buffer for the poll. - */ + return -EBUSY; + } - dev->d_buf = tiva_allocbuffer(priv); + /* We have the descriptor, we can continue the poll. Allocate a new + * buffer for the poll. + */ - /* We can't continue the poll if we have no buffers */ + dev->d_buf = tiva_allocbuffer(priv); - if (dev->d_buf == NULL) - { - /* Terminate the poll. */ + /* We can't continue the poll if we have no buffers */ - return -ENOMEM; + if (dev->d_buf == NULL) + { + /* Terminate the poll. */ + + return -ENOMEM; + } } } diff --git a/arch/hc/src/m9s12/m9s12_ethernet.c b/arch/hc/src/m9s12/m9s12_ethernet.c index 1666bab38bb..c44da32764d 100644 --- a/arch/hc/src/m9s12/m9s12_ethernet.c +++ b/arch/hc/src/m9s12/m9s12_ethernet.c @@ -244,13 +244,16 @@ static int emac_txpoll(struct net_driver_s *dev) } #endif /* CONFIG_NET_IPv6 */ - /* Send the packet */ + if (!devif_loopback_out(&priv->d_dev)) + { + /* Send the packet */ - emac_transmit(priv); + 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. - */ + /* Check if there is room in the device to hold another packet. If not, + * return a non-zero value to terminate the poll. + */ + } } /* If zero is returned, the polling will continue until all connections have diff --git a/arch/mips/src/pic32mx/pic32mx-ethernet.c b/arch/mips/src/pic32mx/pic32mx-ethernet.c index 0d6edbe1a6d..8618591ba2e 100644 --- a/arch/mips/src/pic32mx/pic32mx-ethernet.c +++ b/arch/mips/src/pic32mx/pic32mx-ethernet.c @@ -1149,31 +1149,34 @@ static int pic32mx_txpoll(struct net_driver_s *dev) } #endif /* CONFIG_NET_IPv6 */ - /* Send this packet. In this context, we know that there is space for - * at least one more packet in the descriptor list. - */ - - 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) + if (!devif_loopback_out(&priv->pd_dev)) { - /* There are no more TX descriptors/buffers available.. stop the poll */ + /* Send this packet. In this context, we know that there is space for + * at least one more packet in the descriptor list. + */ - return -EAGAIN; - } + pic32mx_transmit(priv); - /* Get the next Tx buffer needed in order to continue the poll */ + /* Check if the next TX descriptor is available. If not, return a + * non-zero value to terminate 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 */ + if (pic32mx_txdesc(priv) == NULL) + { + /* There are no more TX descriptors/buffers available.. stop the poll */ - return -ENOMEM; + 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; + } } } diff --git a/arch/mips/src/pic32mz/pic32mz-ethernet.c b/arch/mips/src/pic32mz/pic32mz-ethernet.c index f85f97c0709..95e8117460d 100644 --- a/arch/mips/src/pic32mz/pic32mz-ethernet.c +++ b/arch/mips/src/pic32mz/pic32mz-ethernet.c @@ -1176,31 +1176,34 @@ static int pic32mz_txpoll(struct net_driver_s *dev) } #endif /* CONFIG_NET_IPv6 */ - /* Send this packet. In this context, we know that there is space for - * at least one more packet in the descriptor list. - */ - - 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) + if (!devif_loopback_out(&priv->pd_dev)) { - /* There are no more TX descriptors/buffers available.. stop the poll */ + /* Send this packet. In this context, we know that there is space for + * at least one more packet in the descriptor list. + */ - return -EAGAIN; - } + pic32mz_transmit(priv); - /* Get the next Tx buffer needed in order to continue the poll */ + /* Check if the next TX descriptor is available. If not, return a + * non-zero value to terminate 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 nex Tx.. stop the poll */ + if (pic32mz_txdesc(priv) == NULL) + { + /* There are no more TX descriptors/buffers available.. stop the poll */ - return -ENOMEM; + 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 nex Tx.. stop the poll */ + + return -ENOMEM; + } } } diff --git a/arch/misoc/src/common/misoc_net.c b/arch/misoc/src/common/misoc_net.c index c00f3e02cff..8d80af7f9e4 100644 --- a/arch/misoc/src/common/misoc_net.c +++ b/arch/misoc/src/common/misoc_net.c @@ -334,13 +334,16 @@ static int misoc_net_txpoll(FAR struct net_driver_s *dev) } #endif /* CONFIG_NET_IPv6 */ - /* Send the packet */ + if (!devif_loopback_out(&priv->misoc_net_dev)) + { + /* Send the packet */ - misoc_net_transmit(priv); + 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. - */ + /* Check if there is room in the device to hold another packet. If not, + * return a non-zero value to terminate the poll. + */ + } } /* If zero is returned, the polling will continue until all connections have diff --git a/arch/sim/src/up_netdriver.c b/arch/sim/src/up_netdriver.c index b992752553c..90bebf6b0aa 100644 --- a/arch/sim/src/up_netdriver.c +++ b/arch/sim/src/up_netdriver.c @@ -151,9 +151,12 @@ static int sim_txpoll(struct net_driver_s *dev) } #endif /* CONFIG_NET_IPv6 */ - /* Send the packet */ + if (!devif_loopback_out(&g_sim_dev)) + { + /* Send the packet */ - netdev_send(g_sim_dev.d_buf, g_sim_dev.d_len); + netdev_send(g_sim_dev.d_buf, g_sim_dev.d_len); + } } /* If zero is returned, the polling will continue until all connections have diff --git a/arch/z80/src/ez80/ez80_emac.c b/arch/z80/src/ez80/ez80_emac.c index bf583aab477..a97d90093f2 100644 --- a/arch/z80/src/ez80/ez80_emac.c +++ b/arch/z80/src/ez80/ez80_emac.c @@ -1147,11 +1147,14 @@ static int ez80emac_txpoll(struct net_driver_s *dev) } #endif /* CONFIG_NET_IPv6 */ - /* Send the packet. ez80emac_transmit() will return zero if the - * packet was successfully handled. - */ + if (!devif_loopback_out(&priv->dev)) + { + /* Send the packet. ez80emac_transmit() will return zero if the + * packet was successfully handled. + */ - ret = ez80emac_transmit(priv); + ret = ez80emac_transmit(priv); + } } /* If zero is returned, the polling will continue until all connections have diff --git a/drivers/net/dm90x0.c b/drivers/net/dm90x0.c index 2116463a971..21cff8a27b2 100644 --- a/drivers/net/dm90x0.c +++ b/drivers/net/dm90x0.c @@ -819,19 +819,22 @@ static int dm9x_txpoll(struct net_driver_s *dev) } #endif /* CONFIG_NET_IPv6 */ - /* 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) + if (!devif_loopback_out(&priv->dm_dev)) { - /* Returning a non-zero value will terminate the poll operation */ + /* Send the packet */ - return 1; + 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 will terminate the poll operation */ + + return 1; + } } } diff --git a/drivers/net/enc28j60.c b/drivers/net/enc28j60.c index 38f00a714d0..46c1de5aede 100644 --- a/drivers/net/enc28j60.c +++ b/drivers/net/enc28j60.c @@ -1213,13 +1213,16 @@ static int enc_txpoll(struct net_driver_s *dev) } #endif /* CONFIG_NET_IPv6 */ - /* Send the packet */ + if (!devif_loopback_out(&priv->dev)) + { + /* Send the packet */ - enc_transmit(priv); + enc_transmit(priv); - /* Stop the poll now because we can queue only one packet */ + /* Stop the poll now because we can queue only one packet */ - return -EBUSY; + return -EBUSY; + } } /* If zero is returned, the polling will continue until all connections have diff --git a/drivers/net/encx24j600.c b/drivers/net/encx24j600.c index 770e740cbb3..b91fa08c1e8 100644 --- a/drivers/net/encx24j600.c +++ b/drivers/net/encx24j600.c @@ -1194,9 +1194,12 @@ static int enc_txpoll(struct net_driver_s *dev) } #endif /* CONFIG_NET_IPv6 */ - /* Send the packet */ + if (!devif_loopback_out(&priv->dev)) + { + /* Send the packet */ - ret = enc_txenqueue(priv); + ret = enc_txenqueue(priv); + } } /* If zero is returned, the polling will continue until all connections have diff --git a/drivers/net/ftmac100.c b/drivers/net/ftmac100.c index 1f002d8696f..8608eaf03b2 100644 --- a/drivers/net/ftmac100.c +++ b/drivers/net/ftmac100.c @@ -388,13 +388,16 @@ static int ftmac100_txpoll(struct net_driver_s *dev) } #endif /* CONFIG_NET_IPv6 */ - /* Send the packet */ + if (!devif_loopback_out(&priv->ft_dev)) + { + /* Send the packet */ - ftmac100_transmit(priv); + 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. - */ + /* Check if there is room in the device to hold another packet. If not, + * return a non-zero value to terminate the poll. + */ + } } /* If zero is returned, the polling will continue until all connections have diff --git a/drivers/net/skeleton.c b/drivers/net/skeleton.c index b4a122c950a..55190b882c9 100644 --- a/drivers/net/skeleton.c +++ b/drivers/net/skeleton.c @@ -299,13 +299,21 @@ static int skel_txpoll(FAR struct net_driver_s *dev) } #endif /* CONFIG_NET_IPv6 */ - /* 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. + /* 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 attmpt to put it on the wire. */ + + if (!devif_loopback_out(&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. + */ + } } /* If zero is returned, the polling will continue until all connections have diff --git a/drivers/net/slip.c b/drivers/net/slip.c index 700a6a16f54..673a7535983 100644 --- a/drivers/net/slip.c +++ b/drivers/net/slip.c @@ -405,7 +405,10 @@ static int slip_txpoll(FAR struct net_driver_s *dev) if (priv->dev.d_len > 0) { - slip_transmit(priv); + if (!devif_loopback_out(&priv->dev)) + { + slip_transmit(priv); + } } /* If zero is returned, the polling will continue until all connections have diff --git a/drivers/usbdev/cdcecm.c b/drivers/usbdev/cdcecm.c index 19b4a272eb8..580c190129c 100644 --- a/drivers/usbdev/cdcecm.c +++ b/drivers/usbdev/cdcecm.c @@ -400,15 +400,18 @@ static int cdcecm_txpoll(FAR struct net_driver_s *dev) } #endif /* CONFIG_NET_IPv6 */ - /* Send the packet */ + if (!devif_loopback_out(&priv->dev)) + { + /* Send the packet */ - cdcecm_transmit(priv); + 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. - */ + /* 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; + return 1; + } } /* If zero is returned, the polling will continue until all connections diff --git a/drivers/usbdev/rndis.c b/drivers/usbdev/rndis.c index 1a7e3482d49..30ec8398154 100644 --- a/drivers/usbdev/rndis.c +++ b/drivers/usbdev/rndis.c @@ -994,8 +994,10 @@ static int rndis_txpoll(FAR struct net_driver_s *dev) } #endif /* CONFIG_NET_IPv6 */ - ret = rndis_transmit(priv); - + if (!devif_loopback_out(&priv->netdev)) + { + ret = rndis_transmit(priv); + } } /* If zero is returned, the polling will continue until all connections have diff --git a/drivers/wireless/ieee80211/bcmf_netdev.c b/drivers/wireless/ieee80211/bcmf_netdev.c index b4a8a840b98..a6d894fab7d 100644 --- a/drivers/wireless/ieee80211/bcmf_netdev.c +++ b/drivers/wireless/ieee80211/bcmf_netdev.c @@ -473,16 +473,19 @@ static int bcmf_txpoll(FAR struct net_driver_s *dev) } #endif /* CONFIG_NET_IPv6 */ - /* Send the packet */ + if (!devif_loopback_out(&priv->bc_dev)) + { + /* Send the packet */ - bcmf_transmit(priv, priv->cur_tx_frame); + 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. - */ + /* 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; + priv->cur_tx_frame = NULL; + return 1; + } } /* If zero is returned, the polling will continue until all connections have diff --git a/include/nuttx/net/netdev.h b/include/nuttx/net/netdev.h index 7765ae0f06b..927c00bb659 100644 --- a/include/nuttx/net/netdev.h +++ b/include/nuttx/net/netdev.h @@ -568,6 +568,23 @@ int devif_timer(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_out + * + * 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 no zero value is returned. + * + ****************************************************************************/ + +int devif_loopback_out(FAR struct net_driver_s *dev); + /**************************************************************************** * Carrier detection * diff --git a/net/devif/Make.defs b/net/devif/Make.defs index 9d66378ee33..2797d50c490 100644 --- a/net/devif/Make.defs +++ b/net/devif/Make.defs @@ -36,6 +36,7 @@ # Network device interface source files NET_CSRCS += devif_initialize.c devif_send.c devif_poll.c devif_callback.c +NET_CSRCS += devif_loopbackout.c # Device driver IP packet receipt interfaces diff --git a/net/devif/devif_loopbackout.c b/net/devif/devif_loopbackout.c new file mode 100644 index 00000000000..63391923905 --- /dev/null +++ b/net/devif/devif_loopbackout.c @@ -0,0 +1,161 @@ +/**************************************************************************** + * net/devif/devif_loopbackout.c + * + * Copyright (C) 2018 Pinecone Inc. All rights reserved. + * Author: Xiang Xiao + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* This is a helper pointer for accessing the contents of the ip header */ + +#define IPv4BUF ((FAR struct ipv4_hdr_s *)(dev->d_buf + dev->d_llhdrlen)) +#define IPv6BUF ((FAR struct ipv6_hdr_s *)(dev->d_buf + dev->d_llhdrlen)) + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +static bool is_loopback(FAR struct net_driver_s *dev) +{ + if (dev->d_len > 0) + { +#ifdef CONFIG_NET_IPv4 + if ((IPv4BUF->vhl & IP_VERSION_MASK) == IPv4_VERSION && + net_ipv4addr_hdrcmp(IPv4BUF->destipaddr, &dev->d_ipaddr)) + { + return true; + } +#endif + +#ifdef CONFIG_NET_IPv6 + if ((IPv6BUF->vtc & IP_VERSION_MASK) == IPv6_VERSION && + net_ipv6addr_hdrcmp(IPv6BUF->destipaddr, dev->d_ipv6addr)) + { + return true; + } +#endif + } + + return false; +} + +/**************************************************************************** + * Name: devif_loopback_out + * + * 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 no zero value is returned. + * + ****************************************************************************/ + +int devif_loopback_out(FAR struct net_driver_s *dev) +{ + if (!is_loopback(dev)) + { + return 0; + } + + /* Loop while if there is data "sent" to ourself. + * Sending, of course, just means relaying back through the network. + */ + + do + { + NETDEV_TXPACKETS(dev); + NETDEV_RXPACKETS(dev); + +#ifdef CONFIG_NET_PKT + /* When packet sockets are enabled, feed the frame into the packet tap */ + + pkt_input(dev); +#endif + + /* We only accept IP packets of the configured type */ + +#ifdef CONFIG_NET_IPv4 + if ((IPv4BUF->vhl & IP_VERSION_MASK) == IPv4_VERSION) + { + ninfo("IPv4 frame\n"); + + NETDEV_RXIPV4(dev); + ipv4_input(dev); + } + else +#endif +#ifdef CONFIG_NET_IPv6 + if ((IPv6BUF->vtc & IP_VERSION_MASK) == IPv6_VERSION) + { + ninfo("Iv6 frame\n"); + + NETDEV_RXIPV6(dev); + ipv6_input(dev); + } + else +#endif + { + NETDEV_RXDROPPED(dev); + } + + NETDEV_TXDONE(dev); + + /* Add the data link header length for the next loop */ + + if (dev->d_len != 0) + { + dev->d_len += dev->d_llhdrlen; + } + } + while (dev->d_len > 0); + + return 1; +} +