Netdev List
 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
  2026-12-04  7:57 ` netdev-bot+sashiko
  0 siblings, 2 replies; 5+ 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] 5+ messages in thread

* Re: [PATCH net-next] net: stmmac: dwmac-sun8i: set the RX FIFO flow control in the RX mode setup
  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
  2026-12-03  9:05   ` Maxime Chevallier
  2026-12-04  7:57 ` netdev-bot+sashiko
  1 sibling, 1 reply; 5+ messages in thread
From: Nicolai Buchwitz @ 2026-12-03  7:59 UTC (permalink / raw)
  To: Maxime Chevallier
  Cc: 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, thomas.petazzoni, Alexis Lothoré, netdev,
	linux-kernel, linux-arm-kernel, linux-sunxi

Hi Maxime

On 3.12.2026 08:31, Maxime Chevallier wrote:

> [...]

> 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.

nit: IMHO other functions still touch this register, maybe reword?

> 
> 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.

unconditionnally -> unconditionally, that -> than

> [...]

> 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 |

This bit is now always set. Is that fine with TX pause off?

> [...]

Thanks,
Nicolai

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

* Re: [PATCH net-next] net: stmmac: dwmac-sun8i: set the RX FIFO flow control in the RX mode setup
  2026-12-03  7:59 ` Nicolai Buchwitz
@ 2026-12-03  9:05   ` Maxime Chevallier
  2026-12-03  9:26     ` Nicolai Buchwitz
  0 siblings, 1 reply; 5+ messages in thread
From: Maxime Chevallier @ 2026-12-03  9:05 UTC (permalink / raw)
  To: Nicolai Buchwitz
  Cc: 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, thomas.petazzoni, Alexis Lothoré, netdev,
	linux-kernel, linux-arm-kernel, linux-sunxi

Hi Nicolai,

On 12/3/26 08:59, Nicolai Buchwitz wrote:
> Hi Maxime
> 
> On 3.12.2026 08:31, Maxime Chevallier wrote:
> 
>> [...]
> 
>> 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.
> 
> nit: IMHO other functions still touch this register, maybe reword?

Sure, I can reword

> 
>>
>> 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.
> 
> unconditionnally -> unconditionally, that -> than

arg typos, sorry about that.

> 
>> [...]
> 
>> 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 |
> 
> This bit is now always set. Is that fine with TX pause off?

yes it's fine, I've tested that. As long as TX_FLOW_CTL_EN is clear
in TX_FLOW_CTL, we don't emit pause frames so we're all good :)

Maxime

> 
>> [...]
> 
> Thanks,
> Nicolai


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

* Re: [PATCH net-next] net: stmmac: dwmac-sun8i: set the RX FIFO flow control in the RX mode setup
  2026-12-03  9:05   ` Maxime Chevallier
@ 2026-12-03  9:26     ` Nicolai Buchwitz
  0 siblings, 0 replies; 5+ messages in thread
From: Nicolai Buchwitz @ 2026-12-03  9:26 UTC (permalink / raw)
  To: Maxime Chevallier
  Cc: 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, thomas.petazzoni, Alexis Lothoré, netdev,
	linux-kernel, linux-arm-kernel, linux-sunxi

On 3.12.2026 10:05, Maxime Chevallier wrote:

> [...]

>>> 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 |
>> 
>> This bit is now always set. Is that fine with TX pause off?
> 
> yes it's fine, I've tested that. As long as TX_FLOW_CTL_EN is clear
> in TX_FLOW_CTL, we don't emit pause frames so we're all good :)

Thanks for the clarification!

> [...]

Reviewed-by: Nicolai Buchwitz <nb@tipi-net.de>

Regards
Nicolai



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

* Re: [PATCH net-next] net: stmmac: dwmac-sun8i: set the RX FIFO flow control in the RX mode setup
  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
@ 2026-12-04  7:57 ` netdev-bot+sashiko
  1 sibling, 0 replies; 5+ messages in thread
From: netdev-bot+sashiko @ 2026-12-04  7:57 UTC (permalink / raw)
  To: maxime.chevallier
  Cc: andrew+netdev, kuba, davem, edumazet, pabeni, horms, willemb,
	wens, jernej.skrabec, samuel, mcoquelin.stm32, alexandre.torgue,
	linux, lorenzo.bianconi, nb, thomas.petazzoni, alexis.lothore,
	netdev, linux-kernel, linux-arm-kernel, linux-sunxi

Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 1

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] The patch changes behaviour without saying so, and the commit
  message is inaccurate.
- [Low] The commit fixes a race that commit 22fc89783468 ("net: stmmac:
  dwmac-sun8i: emit pause frames when the RX FIFO fills") introduced,…

--

net: stmmac: dwmac-sun8i: set the RX FIFO flow control in the RX mode setup

This patch moves the EMAC_RX_CTL1 RX FIFO flow control threshold setup
out of sun8i_dwmac_flow_ctrl() and into
sun8i_dwmac_dma_operation_mode_rx(). The flow control path then no longer
does a read-modify-write of the register that also holds the RX DMA
start/enable bits. The thresholds and EMAC_RX_FIFO_FLOW_CTL are now set
unconditionally.

> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
> index 613199da57c1b..5a660d22b219f 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);

[Severity: Medium]
Is this change in behaviour intended? Before this patch,
sun8i_dwmac_flow_ctrl() cleared EMAC_RX_FIFO_FLOW_CTL unless fc & FLOW_TX
was set:

    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 | ...

Now this code always sets the bit, and the clear mask here does not
include it. sun8i_dwmac_flow_ctrl() also no longer touches EMAC_RX_CTL1.
The only thing that clears the bit is the writel(0, ioaddr + EMAC_RX_CTL1)
in sun8i_dwmac_dma_reset(), and stmmac_hw_setup() sets it again right
after.

When TX pause is disabled (ethtool -A tx off, or a link partner without
pause support), only EMAC_TX_FLOW_CTL_EN in EMAC_TX_FLOW_CTL now gates TX
pause.

If the sun8i EMAC does not gate RX FIFO threshold flow control on
EMAC_TX_FLOW_CTL_EN, could the MAC now send pause frames in full duplex,
or apply back-pressure in half duplex, while TX pause is off?

The other Synopsys cores do set the equivalent bit unconditionally in the
rx mode path (DMA_CONTROL_EFC in dwmac1000, MTL_OP_MODE_EHFC in dwmac4,
XGMAC_EHFC in dwxgmac2). I couldn't find anything showing that the
Allwinner EMAC behaves the same way.

The commit message also says:

    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.

EMAC_RX_FIFO_FLOW_CTL looks like an enable bit rather than a threshold.

sun8i_dwmac_dma_reset(), sun8i_dwmac_dma_start_rx() and
sun8i_dwmac_dma_stop_rx() also still write EMAC_RX_CTL1, for example:

sun8i_dwmac_dma_start_rx() {
    v = readl(ioaddr + EMAC_RX_CTL1);
    v |= EMAC_RX_DMA_START;
    v |= EMAC_RX_DMA_EN;
    writel(v, ioaddr + EMAC_RX_CTL1);
}

Could the commit message say that the flow control path no longer writes
EMAC_RX_CTL1, and mention the EMAC_RX_FIFO_FLOW_CTL change?

[ ... ]

> @@ -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);
> -

[Severity: Low]
This isn't a bug, but this removes the EMAC_RX_CTL1 read-modify-write that
commit 22fc89783468 added. The commit message already names that commit
as the source of the race. Should this carry a Fixes: tag?

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

The race comes from the phylink resolve worker calling
stmmac_mac_link_up()->stmmac_mac_flow_ctrl()->sun8i_dwmac_flow_ctrl()
without rtnl. That path can run at the same time as
sun8i_dwmac_dma_start_rx() or sun8i_dwmac_dma_stop_rx(), which modify the
same register.

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261203073137.958539-1-maxime.chevallier%40bootlin.com

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

end of thread, other threads:[~2026-12-04  7:57 UTC | newest]

Thread overview: 5+ 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
2026-12-03  9:05   ` Maxime Chevallier
2026-12-03  9:26     ` Nicolai Buchwitz
2026-12-04  7:57 ` netdev-bot+sashiko

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