Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net: stmmac: reset the DMA on a fatal bus error
@ 2026-11-20 14:16 Jakob Unterwurzacher
  2026-11-22 17:53 ` Nicolai Buchwitz
  0 siblings, 1 reply; 2+ messages in thread
From: Jakob Unterwurzacher @ 2026-11-20 14:16 UTC (permalink / raw)
  To: Maxime Chevallier, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Maxime Coquelin, Alexandre Torgue,
	jakob.unterwurzacher
  Cc: netdev, linux-stm32, linux-arm-kernel, linux-kernel

From: Jakob Unterwurzacher <jakob.unterwurzacher@cherry.de>

A fatal bus error (FBE) stops both the TX and the RX DMA engine of the
channel. The DMA interrupt handlers report it as tx_hard_error, so
stmmac_tx_err() reinitializes and restarts the TX side only. The RX DMA
stays stopped: the RX descriptors remain owned by the DMA, the MAC
drops every received frame (mmc_rx_fifo_overflow grows) and nothing is
logged. The only trace is the fatal_bus_error_irq counter in
ethtool -S. The interface needs a manual down/up to recover.

This happens on RK3588 (dwmac4) after resume from suspend-to-RAM,
roughly once in 300-500 resumes: DMA_DEBUG_STATUS0 shows the RX process
of channel 0 stopped (RPS0 = 0), DMA_CH0_RX_CONTROL has SR cleared,
while TX keeps running.

Report a fatal bus error as a separate dma_fatal_error status and
handle it like other fatal errors with stmmac_global_err(), which
resets the adapter from the service task. Do so in the shared and in
the per-channel MSI interrupt paths, and for all DMA cores that report
the error (dwmac100/1000, dwmac4, dwxgmac2, loongson).

Tested on RK3588-Tiger where it catches and recovers the observed
hangs after resume.

Signed-off-by: Jakob Unterwurzacher <jakob.unterwurzacher@cherry.de>
---
 drivers/net/ethernet/stmicro/stmmac/common.h       |  1 +
 .../net/ethernet/stmicro/stmmac/dwmac-loongson.c   |  2 +-
 drivers/net/ethernet/stmicro/stmmac/dwmac4_lib.c   |  2 +-
 drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c    |  2 +-
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c |  2 +-
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c  | 29 +++++++++++++++++++++-
 6 files changed, 33 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/common.h b/drivers/net/ethernet/stmicro/stmmac/common.h
index c74bc7c9750e9..1f74cb451215f 100644
--- a/drivers/net/ethernet/stmicro/stmmac/common.h
+++ b/drivers/net/ethernet/stmicro/stmmac/common.h
@@ -376,6 +376,7 @@ enum dma_irq_status {
 	tx_hard_error_bump_tc = 0x2,
 	handle_rx = 0x4,
 	handle_tx = 0x8,
+	dma_fatal_error = 0x10,
 };
 
 enum dma_irq_dir {
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c
index a42d80ead9d40..0a15f5565106c 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c
@@ -268,7 +268,7 @@ static int loongson_dwmac_dma_interrupt(struct stmmac_priv *priv,
 		}
 		if (unlikely(fb_intr_status)) {
 			x->fatal_bus_error_irq++;
-			ret = tx_hard_error;
+			ret |= dma_fatal_error;
 		}
 	}
 	/* TX/RX NORMAL interrupts */
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_lib.c b/drivers/net/ethernet/stmicro/stmmac/dwmac4_lib.c
index a0249715fafaf..2147403629892 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_lib.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_lib.c
@@ -165,7 +165,7 @@ int dwmac4_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr,
 		}
 		if (unlikely(intr_status & DMA_CHAN_STATUS_FBE)) {
 			x->fatal_bus_error_irq++;
-			ret = tx_hard_error;
+			ret |= dma_fatal_error;
 		}
 	}
 
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c b/drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c
index a0383f9486c2d..3f3f2f623bd3e 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c
@@ -204,7 +204,7 @@ int dwmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr,
 		}
 		if (unlikely(intr_status & DMA_STATUS_FBI)) {
 			x->fatal_bus_error_irq++;
-			ret = tx_hard_error;
+			ret |= dma_fatal_error;
 		}
 	}
 	/* TX/RX NORMAL interrupts */
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c
index 0a6e82a155c0e..bc06076410dc7 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c
@@ -335,7 +335,7 @@ static int dwxgmac2_dma_interrupt(struct stmmac_priv *priv,
 		}
 		if (unlikely(intr_status & XGMAC_FBE)) {
 			x->fatal_bus_error_irq++;
-			ret |= tx_hard_error;
+			ret |= dma_fatal_error;
 		}
 	}
 
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 25894771e9e9f..16ba83db34546 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -349,6 +349,24 @@ static void stmmac_global_err(struct stmmac_priv *priv)
 	stmmac_service_event_schedule(priv);
 }
 
+/* A fatal bus error stops both the TX and the RX DMA of the channel. Only a
+ * reset of the DMA brings them back, so restarting the TX side alone is not
+ * enough: RX would stay stopped without any further error.
+ */
+static bool stmmac_dma_fatal_error(struct stmmac_priv *priv, int status,
+				   u32 chan)
+{
+	if (likely(!(status & dma_fatal_error)))
+		return false;
+
+	if (net_ratelimit())
+		netdev_err(priv->dev, "DMA fatal bus error on channel %u\n",
+			   chan);
+	stmmac_global_err(priv);
+
+	return true;
+}
+
 static void print_pkt(unsigned char *buf, int len)
 {
 	pr_debug("len = %d byte, buf addr: 0x%p\n", len, buf);
@@ -3169,6 +3187,10 @@ static void stmmac_dma_interrupt(struct stmmac_priv *priv)
 		status[chan] = stmmac_napi_check(priv, chan,
 						 DMA_DIR_RXTX);
 
+	for (chan = 0; chan < channels_to_check; chan++)
+		if (stmmac_dma_fatal_error(priv, status[chan], chan))
+			return;
+
 	for (chan = 0; chan < tx_channel_count; chan++) {
 		if (unlikely(status[chan] & tx_hard_error_bump_tc)) {
 			/* Try to bump up the dma threshold on this failure */
@@ -6533,6 +6555,9 @@ static irqreturn_t stmmac_msi_intr_tx(int irq, void *data)
 
 	status = stmmac_napi_check(priv, chan, DMA_DIR_TX);
 
+	if (stmmac_dma_fatal_error(priv, status, chan))
+		return IRQ_HANDLED;
+
 	if (unlikely(status & tx_hard_error_bump_tc)) {
 		/* Try to bump up the dma threshold on this failure */
 		stmmac_bump_dma_threshold(priv, chan);
@@ -6549,6 +6574,7 @@ static irqreturn_t stmmac_msi_intr_rx(int irq, void *data)
 	struct stmmac_dma_conf *dma_conf;
 	int chan = rx_q->queue_index;
 	struct stmmac_priv *priv;
+	int status;
 
 	dma_conf = container_of(rx_q, struct stmmac_dma_conf, rx_queue[chan]);
 	priv = container_of(dma_conf, struct stmmac_priv, dma_conf);
@@ -6557,7 +6583,8 @@ static irqreturn_t stmmac_msi_intr_rx(int irq, void *data)
 	if (test_bit(STMMAC_DOWN, &priv->state))
 		return IRQ_HANDLED;
 
-	stmmac_napi_check(priv, chan, DMA_DIR_RX);
+	status = stmmac_napi_check(priv, chan, DMA_DIR_RX);
+	stmmac_dma_fatal_error(priv, status, chan);
 
 	return IRQ_HANDLED;
 }

---
base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
change-id: 20261120-stmmac_dma_fatal_error-d26d71a0308a

Best regards,
--  
Jakob Unterwurzacher <jakob.unterwurzacher@cherry.de>



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-22 17:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20 14:16 [PATCH] net: stmmac: reset the DMA on a fatal bus error Jakob Unterwurzacher
2026-11-22 17:53 ` Nicolai Buchwitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox