Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next] net: stmmac: dwmac-sun8i: set the RX FIFO flow control in the RX mode setup
@ 2026-12-03  7:31 Maxime Chevallier
  2026-12-03  7:59 ` Nicolai Buchwitz
  0 siblings, 1 reply; 2+ messages in thread
From: Maxime Chevallier @ 2026-12-03  7:31 UTC (permalink / raw)
  To: Andrew Lunn, Jakub Kicinski, davem, Eric Dumazet, Paolo Abeni,
	Simon Horman, Willem de Bruijn, Chen-Yu Tsai, Jernej Skrabec,
	Samuel Holland, Maxime Coquelin, Alexandre Torgue, Russell King,
	Lorenzo Bianconi, Nicolai Buchwitz
  Cc: Maxime Chevallier, thomas.petazzoni, Alexis Lothoré, netdev,
	linux-kernel, linux-arm-kernel, linux-sunxi

On dwmac sun8i, the TX pause behaviour is controlled via 2 registers:

 - TX_FLOW_CTL_EN, to enable/disable TX pause and set a few extra pause
   params,

 - EMAC_RX_CTL1, that configures the fifo thresholds to start/stop
   sending pause frames

EMAC_RX_CTL1 also configures the DMA engine, to enable/disable it as
well as start/stop it. There's a chance for a race if we trigger an
action that starts the DMA engine at the same time as we configure
pause.

Let's move the threshold setup in the DMA configuration path, making it
the only piece of code that touches this register. This is OK, as we
just set the thresholds, we don't change the FC status. That's also
what's done in other glues.

The thresholds are now configured unconditionnally, that's also OK as
it doesn't affect anything else that TX FC, and only if it's enabled in
HW.

This didn't happen before, as we didn't configure the thresholds up
until:

commit 22fc89783468 ("net: stmmac: dwmac-sun8i: emit pause frames when the RX FIFO fills")

This was reported by Sashiko when submitting the above patch. I've
tested this on Allwinner H2+, but only to make sure FC still works, I
haven't tried to reproduce the race.

Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
---
 .../net/ethernet/stmicro/stmmac/dwmac-sun8i.c   | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
index 613199da57c1..5a660d22b219 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
@@ -562,6 +562,12 @@ static void sun8i_dwmac_dma_operation_mode_rx(struct stmmac_priv *priv,
 		else if (mode < 128)
 			v |= EMAC_RX_TH_128;
 	}
+
+	v &= ~(EMAC_RX_FLOW_CTL_TH_ACT | EMAC_RX_FLOW_CTL_TH_DEACT);
+	v |= EMAC_RX_FIFO_FLOW_CTL |
+	     FIELD_PREP(EMAC_RX_FLOW_CTL_TH_ACT, EMAC_RX_FLOW_CTL_TH_2K) |
+	     FIELD_PREP(EMAC_RX_FLOW_CTL_TH_DEACT, EMAC_RX_FLOW_CTL_TH_4K);
+
 	writel(v, ioaddr + EMAC_RX_CTL1);
 }
 
@@ -774,17 +780,6 @@ static void sun8i_dwmac_flow_ctrl(struct mac_device_info *hw,
 		v &= ~EMAC_RX_FLOW_CTL_EN;
 	writel(v, ioaddr + EMAC_RX_CTL0);
 
-	v = readl(ioaddr + EMAC_RX_CTL1);
-	v &= ~(EMAC_RX_FIFO_FLOW_CTL | EMAC_RX_FLOW_CTL_TH_ACT |
-	       EMAC_RX_FLOW_CTL_TH_DEACT);
-	if (fc & FLOW_TX)
-		v |= EMAC_RX_FIFO_FLOW_CTL |
-		     FIELD_PREP(EMAC_RX_FLOW_CTL_TH_ACT,
-				EMAC_RX_FLOW_CTL_TH_2K) |
-		     FIELD_PREP(EMAC_RX_FLOW_CTL_TH_DEACT,
-				EMAC_RX_FLOW_CTL_TH_4K);
-	writel(v, ioaddr + EMAC_RX_CTL1);
-
 	v = readl(ioaddr + EMAC_TX_FLOW_CTL);
 	v &= ~(EMAC_TX_FLOW_CTL_EN | EMAC_TX_FLOW_CTL_ZQP_FRM_EN |
 	       EMAC_TX_FLOW_CTL_PAUSE_TIME);
-- 
2.56.1



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

end of thread, other threads:[~2026-12-03  8:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03  7:31 [PATCH net-next] net: stmmac: dwmac-sun8i: set the RX FIFO flow control in the RX mode setup Maxime Chevallier
2026-12-03  7:59 ` Nicolai Buchwitz

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