Skip to contentSkip to conversation

net: return -EAGAIN when no RX packet is ready

PATCH In review James Hilliard 2 participants 11 messages Oct 12 – Oct 21

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover net: return -EAGAIN when no RX packet is ready

DHCP now checks net_lwip_poll(), exposing Ethernet drivers which return fatal errors for an ordinary receive poll with no packet available. net_lwip_rx() treats -EAGAIN as an empty receive, as specified by the Ethernet driver interface.

Keep the CPSW fix from v1 and fix the same issue in seven more drivers:
FMan, ColdFire FEC, Marvell GbE, TSEC, Xilinx EmacLite, Zynq GEM and HiSilicon GMAC, with one patch per driver. Change only their no-packet returns, preserving packet processing, actual error handling and polling limits. The driver fixes can be applied independently.

The additional cases were found by code inspection following the BeagleBone Black report. Cross-compiled the seven additional drivers with both lwIP and the legacy stack, and checked their receive functions with stubbed registers and descriptors, including negative controls against the old code. These additional drivers have not been tested on real hardware.

Based on u-boot-net/for-next.

Assisted-by Codex:gpt-6-astra

---
Changes in v2:
- Add separate fixes for empty receives in seven more Ethernet drivers.
- Add Tom Rini's Tested-by to the otherwise unchanged CPSW patch.
- Link to v1: https://patch.msgid.link/[email protected]

---
James Hilliard (8):
net: ti: cpsw: return -EAGAIN when no RX packet is ready
net: fm: return -EAGAIN for empty receives
net: higmacv300: return -EAGAIN for empty receives
net: mcffec: return -EAGAIN for empty receives
net: mvgbe: return -EAGAIN for empty receives
net: tsec: return -EAGAIN for empty receives
net: xilinx_emaclite: return -EAGAIN for empty receives
net: zynq_gem: return -EAGAIN for empty receives

 drivers/net/fm/eth.c          | 2 +-
 drivers/net/higmacv300.c      | 2 +-
 drivers/net/mcffec.c          | 2 +-
 drivers/net/mvgbe.c           | 2 +-
 drivers/net/ti/cpsw.c         | 2 ++
 drivers/net/tsec.c            | 2 ++
 drivers/net/xilinx_emaclite.c | 6 +++---
 drivers/net/zynq_gem.c        | 2 +-
 8 files changed, 12 insertions(+), 8 deletions(-)

---
base-commit: 28ddd369e2f7199539cdefe22ce014c592b890bd
change-id: 20261012-submit-cpsw-rx-eagain-v1-bdda0f670600

Best regards,

Signature · 1 line
James Hilliard <[email protected]>
#1 lore raw

PATCH v2 1/8 net: ti: cpsw: return -EAGAIN when no RX packet is ready

DHCP exits without acquiring an address on BeagleBone Black with lwIP enabled after DHCP started checking the return value of net_lwip_poll().

cpdma_process() returns -EBUSY while the receive descriptor is still owned by DMA. _cpsw_recv() passes that value through, but net_lwip_rx() only converts -EAGAIN to a non-fatal empty receive. DHCP therefore aborts on a normal poll with no packet ready.

Translate -EBUSY to -EAGAIN in _cpsw_recv(), following the Ethernet receive interface's no-packet convention. Leave other errors and the shared CPDMA helper's transmit behavior unchanged.

Fixes 53a0ca3757fe ("net: lwip: finish DHCP before starting autoload")
---
 drivers/net/ti/cpsw.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/ti/cpsw.c +2 -0
index 6b1f7764e0d..4d7869f405c 100644
@@ -808,6 +808,8 @@ static int _cpsw_recv(struct cpsw_priv *priv, uchar **pkt)
 	int ret;
 
 	ret = cpdma_process(priv, &priv->rx_chan, &buffer, &len);
+	if (ret == -EBUSY)
+		return -EAGAIN;
 	if (ret < 0)
 		return ret;
 
Signature · 1 line
2.53.0
#2 lore raw

PATCH v2 2/8 net: fm: return -EAGAIN for empty receives

In reply to James Hilliard

fm_eth_recv() returns -1 if the first receive descriptor is empty. net_lwip_rx() only treats -EAGAIN as a non-fatal empty receive, so DHCP can abort on an idle poll now that it checks net_lwip_poll().

Initialize the return value to -EAGAIN instead. Leave received-frame handling and the zero return after discarding erroneous frames unchanged.

Fixes 53a0ca3757fe ("net: lwip: finish DHCP before starting autoload")
---
 drivers/net/fm/eth.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/fm/eth.c +1 -1
index f0e7c0eca42..8b44a8ffae8 100644
@@ -618,7 +618,7 @@ static int fm_eth_recv(struct udevice *dev, int flags, uchar **packetp)
 	struct fm_port_bd *rxbd;
 	u32 buf_lo, buf_hi;
 	u16 status, len;
-	int ret = -1;
+	int ret = -EAGAIN;
 	u8 *data;
 
 	fm_eth = dev_get_priv(dev);
Signature · 1 line
2.53.0
#3 lore raw

PATCH v2 3/8 net: higmacv300: return -EAGAIN for empty receives

In reply to James Hilliard

higmac_recv() returns -ETIMEDOUT when polling its receive busy queue finds no packet. net_lwip_rx() only treats -EAGAIN as a non-fatal empty receive, so DHCP can abort on an idle poll now that it checks net_lwip_poll().

Return -EAGAIN when the queue remains empty. Preserve the existing polling limit, free-queue refill and received-buffer ownership handling. Leave transmit timeout handling unchanged.

Fixes 53a0ca3757fe ("net: lwip: finish DHCP before starting autoload")
---
 drivers/net/higmacv300.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/higmacv300.c +1 -1
index 6b88f6fbf59..a8ec0dd63a6 100644
@@ -193,7 +193,7 @@ static int higmac_recv(struct udevice *dev, int flags, uchar **packetp)
 	} while (--timeout && bqw_pos == bqr_pos);
 
 	if (!timeout)
-		return -ETIMEDOUT;
+		return -EAGAIN;
 
 	if (++bqr_pos >= RX_DESC_NUM)
 		bqr_pos = 0;
Signature · 1 line
2.53.0
#4 lore raw

PATCH v2 4/8 net: mcffec: return -EAGAIN for empty receives

In reply to James Hilliard

mcffec_recv() returns its initial value of -1 when the receive ring is empty at poll entry. net_lwip_rx() only treats -EAGAIN as a non-fatal empty receive, so DHCP can abort on an idle poll now that it checks net_lwip_poll().

Initialize the return value to -EAGAIN instead. Leave received-frame processing, descriptor rearming and ring-index updates unchanged.

Fixes 53a0ca3757fe ("net: lwip: finish DHCP before starting autoload")
---
 drivers/net/mcffec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/mcffec.c +1 -1
index 7e53492733e..b2b2a43c3de 100644
@@ -430,7 +430,7 @@ static int mcffec_recv(struct udevice *dev, int flags, uchar **packetp)
 {
 	struct fec_info_s *info = dev_get_priv(dev);
 	volatile fec_t *fecp = (fec_t *)info->iobase;
-	int length = -1;
+	int length = -EAGAIN;
 
 	for (;;) {
 #ifdef CONFIG_SYS_UNIFY_CACHE
Signature · 1 line
2.53.0
#5 lore raw

PATCH v2 5/8 net: mvgbe: return -EAGAIN for empty receives

In reply to James Hilliard

__mvgbe_recv() returns -1 when its receive descriptor remains owned by DMA throughout the polling loop. net_lwip_rx() only treats -EAGAIN as a non-fatal empty receive, so DHCP can abort on an idle poll now that it checks net_lwip_poll().

Return -EAGAIN when no packet becomes available. Preserve the existing polling limit, received-frame checks and descriptor handling.

Fixes 53a0ca3757fe ("net: lwip: finish DHCP before starting autoload")
---
 drivers/net/mvgbe.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/mvgbe.c +1 -1
index 4dc738980cb..c37f67a4334 100644
@@ -569,7 +569,7 @@ static int __mvgbe_recv(struct mvgbe_device *dmvgbe, uchar **packetp)
 			timeout++;
 		else {
 			debug("%s time out...\n", __func__);
-			return -1;
+			return -EAGAIN;
 		}
 	} while (readl(&p_rxdesc_curr->cmd_sts) & MVGBE_BUFFER_OWNED_BY_DMA);
 
Signature · 1 line
2.53.0
#6 lore raw

PATCH v2 6/8 net: tsec: return -EAGAIN for empty receives

In reply to James Hilliard

tsec_recv() returns -1 when the receive descriptor is empty. net_lwip_rx() only treats -EAGAIN as a non-fatal empty receive, so DHCP can abort on an idle poll now that it checks net_lwip_poll().

Set the return value to -EAGAIN for an empty descriptor. Keep the IEVENT_BSY receiver restart after that check, and preserve the separate error return and descriptor rearming for a malformed frame.

Fixes 53a0ca3757fe ("net: lwip: finish DHCP before starting autoload")
---
 drivers/net/tsec.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/tsec.c +2 -0
index d03368b9408..b6819fd5317 100644
@@ -335,6 +335,8 @@ static int tsec_recv(struct udevice *dev, int flags, uchar **packetp)
 			/* Rearm the packet buffer */
 			tsec_free_pkt(dev, NULL, 0);
 		}
+	} else {
+		ret = -EAGAIN;
 	}
 
 	if (in_be32(&regs->ievent) & IEVENT_BSY) {
Signature · 1 line
2.53.0
#7 lore raw

PATCH v2 7/8 net: xilinx_emaclite: return -EAGAIN for empty receives

In reply to James Hilliard

emaclite_recv() returns -1 when neither receive buffer has a packet. net_lwip_rx() only treats -EAGAIN as a non-fatal empty receive, so DHCP can abort on an idle poll now that it checks net_lwip_poll().

Return -EAGAIN from all three no-packet paths: an empty ping buffer without pong support, and both orders of checking the two buffers. Leave buffer selection, frame parsing and acknowledgment unchanged.

Fixes 53a0ca3757fe ("net: lwip: finish DHCP before starting autoload")
---
 drivers/net/xilinx_emaclite.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/xilinx_emaclite.c +3 -3
index c25ac2e6600..ba3c4d6f68f 100644
@@ -473,11 +473,11 @@ try_again:
 			debug("Data not found in rx_ping buffer\n");
 			/* Pong buffer is not available - return immediately */
 			if (!emaclite->rxpp)
-				return -1;
+				return -EAGAIN;
 
 			/* Try pong buffer if this is first attempt */
 			if (attempt++)
-				return -1;
+				return -EAGAIN;
 			emaclite->use_rx_pong_buffer_next =
 					!emaclite->use_rx_pong_buffer_next;
 			goto try_again;
@@ -493,7 +493,7 @@ try_again:
 			debug("Data not found in rx_pong buffer\n");
 			/* Try ping buffer if this is first attempt */
 			if (attempt++)
-				return -1;
+				return -EAGAIN;
 			emaclite->use_rx_pong_buffer_next =
 					!emaclite->use_rx_pong_buffer_next;
 			goto try_again;
Signature · 1 line
2.53.0
#8 lore raw

PATCH v2 8/8 net: zynq_gem: return -EAGAIN for empty receives

In reply to James Hilliard

zynq_gem_recv() returns -1 when the current receive descriptor has no new packet. net_lwip_rx() only treats -EAGAIN as a non-fatal empty receive, so DHCP can abort on an idle poll now that it checks net_lwip_poll().

Return -EAGAIN when the descriptor's new-packet bit is clear. Leave received-frame processing and the errors for missing frame flags or zero-length packets unchanged.

Fixes 53a0ca3757fe ("net: lwip: finish DHCP before starting autoload")
---
 drivers/net/zynq_gem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/zynq_gem.c +1 -1
index f570ae9ee73..957d5251cb8 100644
@@ -772,7 +772,7 @@ static int zynq_gem_recv(struct udevice *dev, int flags, uchar **packetp)
 	struct emac_bd *current_bd = &priv->rx_bd[priv->rxbd_current];
 
 	if (!(current_bd->addr & ZYNQ_GEM_RXBUF_NEW_MASK))
-		return -1;
+		return -EAGAIN;
 
 	if (!(current_bd->status &
 			(ZYNQ_GEM_RXBUF_SOF_MASK | ZYNQ_GEM_RXBUF_EOF_MASK))) {
Signature · 1 line
2.53.0
Acked-by on the v2 series
#9 lore raw
In reply to James Hilliard
Quoted 48 lines · James Hilliard

DHCP now checks net_lwip_poll(), exposing Ethernet drivers which return fatal errors for an ordinary receive poll with no packet available. net_lwip_rx() treats -EAGAIN as an empty receive, as specified by the Ethernet driver interface.

Keep the CPSW fix from v1 and fix the same issue in seven more drivers:
FMan, ColdFire FEC, Marvell GbE, TSEC, Xilinx EmacLite, Zynq GEM and HiSilicon GMAC, with one patch per driver. Change only their no-packet returns, preserving packet processing, actual error handling and polling limits. The driver fixes can be applied independently.

The additional cases were found by code inspection following the BeagleBone Black report. Cross-compiled the seven additional drivers with both lwIP and the legacy stack, and checked their receive functions with stubbed registers and descriptors, including negative controls against the old code. These additional drivers have not been tested on real hardware.

Based on u-boot-net/for-next.

Assisted-by Codex:gpt-6-astra

---
Changes in v2:
- Add separate fixes for empty receives in seven more Ethernet drivers.
- Add Tom Rini's Tested-by to the otherwise unchanged CPSW patch.
- Link to v1: https://patch.msgid.link/[email protected]

---
James Hilliard (8):
net: ti: cpsw: return -EAGAIN when no RX packet is ready
net: fm: return -EAGAIN for empty receives
net: higmacv300: return -EAGAIN for empty receives
net: mcffec: return -EAGAIN for empty receives
net: mvgbe: return -EAGAIN for empty receives
net: tsec: return -EAGAIN for empty receives
net: xilinx_emaclite: return -EAGAIN for empty receives
net: zynq_gem: return -EAGAIN for empty receives

 drivers/net/fm/eth.c          | 2 +-
 drivers/net/higmacv300.c      | 2 +-
 drivers/net/mcffec.c          | 2 +-
 drivers/net/mvgbe.c           | 2 +-
 drivers/net/ti/cpsw.c         | 2 ++
 drivers/net/tsec.c            | 2 ++
 drivers/net/xilinx_emaclite.c | 6 +++---
 drivers/net/zynq_gem.c        | 2 +-
 8 files changed, 12 insertions(+), 8 deletions(-)
Quoted 7 lines

---
base-commit: 28ddd369e2f7199539cdefe22ce014c592b890bd
change-id: 20261012-submit-cpsw-rx-eagain-v1-bdda0f670600

Best regards,

Signature · 1 line
James Hilliard <[email protected]>

LGTM. For the series:

Thanks,

Signature · 1 line
Jerome
#10 lore raw
In reply to James Hilliard
Quoted 48 lines

DHCP now checks net_lwip_poll(), exposing Ethernet drivers which return fatal errors for an ordinary receive poll with no packet available. net_lwip_rx() treats -EAGAIN as an empty receive, as specified by the Ethernet driver interface.

Keep the CPSW fix from v1 and fix the same issue in seven more drivers:
FMan, ColdFire FEC, Marvell GbE, TSEC, Xilinx EmacLite, Zynq GEM and HiSilicon GMAC, with one patch per driver. Change only their no-packet returns, preserving packet processing, actual error handling and polling limits. The driver fixes can be applied independently.

The additional cases were found by code inspection following the BeagleBone Black report. Cross-compiled the seven additional drivers with both lwIP and the legacy stack, and checked their receive functions with stubbed registers and descriptors, including negative controls against the old code. These additional drivers have not been tested on real hardware.

Based on u-boot-net/for-next.

Assisted-by Codex:gpt-6-astra

---
Changes in v2:
- Add separate fixes for empty receives in seven more Ethernet drivers.
- Add Tom Rini's Tested-by to the otherwise unchanged CPSW patch.
- Link to v1: https://patch.msgid.link/[email protected]

---
James Hilliard (8):
net: ti: cpsw: return -EAGAIN when no RX packet is ready
net: fm: return -EAGAIN for empty receives
net: higmacv300: return -EAGAIN for empty receives
net: mcffec: return -EAGAIN for empty receives
net: mvgbe: return -EAGAIN for empty receives
net: tsec: return -EAGAIN for empty receives
net: xilinx_emaclite: return -EAGAIN for empty receives
net: zynq_gem: return -EAGAIN for empty receives

 drivers/net/fm/eth.c          | 2 +-
 drivers/net/higmacv300.c      | 2 +-
 drivers/net/mcffec.c          | 2 +-
 drivers/net/mvgbe.c           | 2 +-
 drivers/net/ti/cpsw.c         | 2 ++
 drivers/net/tsec.c            | 2 ++
 drivers/net/xilinx_emaclite.c | 6 +++---
 drivers/net/zynq_gem.c        | 2 +-
 8 files changed, 12 insertions(+), 8 deletions(-)
Quoted 7 lines

---
base-commit: 28ddd369e2f7199539cdefe22ce014c592b890bd
change-id: 20261012-submit-cpsw-rx-eagain-v1-bdda0f670600

Best regards,

Signature · 1 line
James Hilliard <[email protected]>

Applied to u-boot-net branch for-main [1], thanks!

[1] https://git.u-boot-project.org/u-boot/custodians/u-boot-net/-/commits/for-main

[1/8] net: ti: cpsw: return -EAGAIN when no RX packet is ready

      commit: 40df38dd830981b00a257260983de43f883bb54b

[2/8] net: fm: return -EAGAIN for empty receives

      commit: ac07b58ba47f69bf50a4b5ec84890fb500289ce6

[3/8] net: higmacv300: return -EAGAIN for empty receives

      commit: d6fae8406e8e8641c9c428949ccc75259b94d2a5

[4/8] net: mcffec: return -EAGAIN for empty receives

      commit: 7927fd19290bd78371907a3e7a8bbf86c112cab0

[5/8] net: mvgbe: return -EAGAIN for empty receives

      commit: b530afa1cf32d3acd8390f850b5b8d4fbcbc2975

[6/8] net: tsec: return -EAGAIN for empty receives

      commit: 0b9a1026cbe26343d0c529553ae186895cc0b842

[7/8] net: xilinx_emaclite: return -EAGAIN for empty receives

      commit: 3fc35d33b5c24be293ee6294cf161f850f85e97f

[8/8] net: zynq_gem: return -EAGAIN for empty receives

      commit: 2f11f0a20f73e88f7719a5123a379910c366a4ec

Best regards,

Signature · 1 line
Jerome Forissier <[email protected]>