Skip to contentSkip to conversation

net: tsec: Improve receive error path

PATCH New J. Neuschäfer 1 participant 3 messages Feb 16, 2025 Network drivers

lore
Share & tools
lore
#0 lore raw

cover net: tsec: Improve receive error path

Currently, errors in the receive path of the TSEC Ethernet driver result in an exhaustion of packet buffer descriptors. This series fixes it.

---
J. Neuschäfer (2):
net: tsec: Reorder tsec_recv and tsec_free_pkt
net: tsec: Re-arm packet buffer in error case

 drivers/net/tsec.c | 39 +++++++++++++++++++++------------------
 1 file changed, 21 insertions(+), 18 deletions(-)

---
base-commit: 5919f48b1c751b85453adca96493ab16f9098be0
change-id: 20250216-tsec-2acd62b9f844

Best regards,

Signature · 1 line
J. Neuschäfer <[email protected]>
#1 lore raw

PATCH 1/2 net: tsec: Reorder tsec_recv and tsec_free_pkt

This is necessary for the following patch. No functional change.

---
 drivers/net/tsec.c | 36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)
drivers/net/tsec.c +18 -18
index 6481ee24a6010099cbabb5a213641c63706176a2..b27fc322db55b7b845f8d629348cb34d79de3cc2 100644
@@ -278,6 +278,24 @@ static int tsec_send(struct udevice *dev, void *packet, int length)
 	return result;
 }
 
+static int tsec_free_pkt(struct udevice *dev, uchar *packet, int length)
+{
+	struct tsec_private *priv = (struct tsec_private *)dev_get_priv(dev);
+	u16 status;
+
+	out_be16(&priv->rxbd[priv->rx_idx].length, 0);
+
+	status = RXBD_EMPTY;
+	/* Set the wrap bit if this is the last element in the list */
+	if ((priv->rx_idx + 1) == PKTBUFSRX)
+		status |= RXBD_WRAP;
+	out_be16(&priv->rxbd[priv->rx_idx].status, status);
+
+	priv->rx_idx = (priv->rx_idx + 1) % PKTBUFSRX;
+
+	return 0;
+}
+
 static int tsec_recv(struct udevice *dev, int flags, uchar **packetp)
 {
 	struct tsec_private *priv = (struct tsec_private *)dev_get_priv(dev);
@@ -307,24 +325,6 @@ static int tsec_recv(struct udevice *dev, int flags, uchar **packetp)
 	return ret;
 }
 
-static int tsec_free_pkt(struct udevice *dev, uchar *packet, int length)
-{
-	struct tsec_private *priv = (struct tsec_private *)dev_get_priv(dev);
-	u16 status;
-
-	out_be16(&priv->rxbd[priv->rx_idx].length, 0);
-
-	status = RXBD_EMPTY;
-	/* Set the wrap bit if this is the last element in the list */
-	if ((priv->rx_idx + 1) == PKTBUFSRX)
-		status |= RXBD_WRAP;
-	out_be16(&priv->rxbd[priv->rx_idx].status, status);
-
-	priv->rx_idx = (priv->rx_idx + 1) % PKTBUFSRX;
-
-	return 0;
-}
-
 static void tsec_halt(struct udevice *dev)
 {
 	struct tsec_private *priv;
Signature · 1 line
2.48.0.rc1.219.gb6b6757d772
#2 lore raw

PATCH 2/2 net: tsec: Re-arm packet buffer in error case

In reply to J. Neuschäfer

When an error is detected in the TSEC receive path, the driver currently prints an error message, but leaves the corresponding packet descriptor in its old state (i.e. owned by the CPU side). As a result, the packet queue can be starved of available buffers if enough errors happen.

To recover from errors, re-arm the packet buffer descriptor after an error has been detected.

Errors can be provoked by changing a PHY with phy-mode = "rgmii-id" to phy-mode = "rgmii".

---
 drivers/net/tsec.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/tsec.c +3 -0
index b27fc322db55b7b845f8d629348cb34d79de3cc2..bd4ebdd745a6cee5828ef1584518589c7667e667 100644
@@ -314,6 +314,9 @@ static int tsec_recv(struct udevice *dev, int flags, uchar **packetp)
 			ret = length - 4;
 		} else {
 			printf("Got error %x\n", (status & RXBD_STATS));
+
+			/* Rearm the packet buffer */
+			tsec_free_pkt(dev, NULL, 0);
 		}
 	}
 
Signature · 1 line
2.48.0.rc1.219.gb6b6757d772