Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next 0/3] net: stmmac: dwmac-sun8i: enable Flow Control
@ 2026-11-22 14:49 Maxime Chevallier
  2026-11-22 14:49 ` [PATCH net-next 1/3] net: stmmac: dwmac-sun8i: allow controlling TX and RX flow control separately Maxime Chevallier
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Maxime Chevallier @ 2026-11-22 14:49 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

While running the "ethtool -t" selftests on H2+ (orangepi zero), the
Flow Control selftests consistently fails.

I originally blamed that on the fact that the board was connected to a
peer that didn't support Pause and that we didn't negotiate Pause at all.

The ethtool selftest are sensitive to what the Peer advertises even
though this is a full loopback test, but it is what it is :(

Since then, the orangepi zero I'm testing dwmac-sun8i on has been wired to
a proper peer, and the selftest still fails. This selftest sends tons of
frames in loopback and checks that Pause frames are generated, and
failing it means no pause frames were sent by the MAC.

Turns out, multiple things were missing in the dwmac-sun8i
implementation to get Flow Control to work.

Patch 1 allows independently setting RX/TX FC

Patch 2 is the one making FC actually work, by configuring the fifo
thresholds

Patch 3 sets the quanta values in the frames.

This seems to have never worked, so since it's not fixing a regression
I'm targetting net-next here.

This was tested only on H2+.

Thanks,

Maxime

Maxime Chevallier (3):
  net: stmmac: dwmac-sun8i: allow controlling TX and RX flow control
    separately
  net: stmmac: dwmac-sun8i: emit pause frames when the RX FIFO fills
  net: stmmac: dwmac-sun8i: configure the pause time for TX flow control

 .../net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 30 +++++++++++++++----
 1 file changed, 25 insertions(+), 5 deletions(-)

-- 
2.56.1



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

* [PATCH net-next 1/3] net: stmmac: dwmac-sun8i: allow controlling TX and RX flow control separately
  2026-11-22 14:49 [PATCH net-next 0/3] net: stmmac: dwmac-sun8i: enable Flow Control Maxime Chevallier
@ 2026-11-22 14:49 ` Maxime Chevallier
  2026-11-22 15:54   ` Nicolai Buchwitz
  2026-11-22 16:00   ` Chen-Yu Tsai
  2026-11-22 14:49 ` [PATCH net-next 2/3] net: stmmac: dwmac-sun8i: emit pause frames when the RX FIFO fills Maxime Chevallier
  2026-11-22 14:49 ` [PATCH net-next 3/3] net: stmmac: dwmac-sun8i: configure the pause time for TX flow control Maxime Chevallier
  2 siblings, 2 replies; 8+ messages in thread
From: Maxime Chevallier @ 2026-11-22 14:49 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

Currently, the sun8i flow control setup only looks at FLOW_AUTO (which
is FLOW_RX | FLOW_TX), and enables RX/TX based on that.

Allow enabling RX/TX flow control directions separately.

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

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
index 2ece7ba9dd73..c63f4d87de50 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
@@ -760,14 +760,14 @@ static void sun8i_dwmac_flow_ctrl(struct mac_device_info *hw,
 	u32 v;
 
 	v = readl(ioaddr + EMAC_RX_CTL0);
-	if (fc == FLOW_AUTO)
+	if (fc & FLOW_RX)
 		v |= EMAC_RX_FLOW_CTL_EN;
 	else
 		v &= ~EMAC_RX_FLOW_CTL_EN;
 	writel(v, ioaddr + EMAC_RX_CTL0);
 
 	v = readl(ioaddr + EMAC_TX_FLOW_CTL);
-	if (fc == FLOW_AUTO)
+	if (fc & FLOW_TX)
 		v |= EMAC_TX_FLOW_CTL_EN;
 	else
 		v &= ~EMAC_TX_FLOW_CTL_EN;
-- 
2.56.1



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

* [PATCH net-next 2/3] net: stmmac: dwmac-sun8i: emit pause frames when the RX FIFO fills
  2026-11-22 14:49 [PATCH net-next 0/3] net: stmmac: dwmac-sun8i: enable Flow Control Maxime Chevallier
  2026-11-22 14:49 ` [PATCH net-next 1/3] net: stmmac: dwmac-sun8i: allow controlling TX and RX flow control separately Maxime Chevallier
@ 2026-11-22 14:49 ` Maxime Chevallier
  2026-11-22 15:57   ` Nicolai Buchwitz
  2026-11-22 14:49 ` [PATCH net-next 3/3] net: stmmac: dwmac-sun8i: configure the pause time for TX flow control Maxime Chevallier
  2 siblings, 1 reply; 8+ messages in thread
From: Maxime Chevallier @ 2026-11-22 14:49 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

The TX flow control mechanism needs multiple things setup to actually
work:

 - The TX_FLOW_CTL_EN bit needs to be set in the TC_FLOW_CTL register,
   this is already done

 - The RX fifo thresholds needs to be set, to indicate when the MAC needs
   to start sending pause frames based on the RX fifo occupancy, and
   when it should stop.

Let's configure the threshold the following way:

 - Send pause frames when there's less than 2K left in the RX fifo
 - Stop sending them when there's more than 4K left in the RX fifo.

This was tested in Allwinner H2+ using the ethtool -t "flow control"
selftest. On that SoC, the RX fifo is 16K.

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

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
index c63f4d87de50..75c743dfe348 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
@@ -5,6 +5,7 @@
  * Copyright (C) 2017 Corentin Labbe <clabbe.montjoie@gmail.com>
  */
 
+#include <linux/bitfield.h>
 #include <linux/clk.h>
 #include <linux/io.h>
 #include <linux/iopoll.h>
@@ -202,6 +203,11 @@ static const struct emac_variant emac_variant_h616_emac1 = {
 #define EMAC_RX_TH_64		(0x1 << 4)
 #define EMAC_RX_TH_96		(0x2 << 4)
 #define EMAC_RX_TH_128		(0x3 << 4)
+#define EMAC_RX_FLOW_CTL_TH_ACT	GENMASK(21, 20)
+#define EMAC_RX_FLOW_CTL_TH_DEACT	GENMASK(23, 22)
+#define EMAC_RX_FLOW_CTL_TH_2K	0x1
+#define EMAC_RX_FLOW_CTL_TH_4K	0x3
+#define EMAC_RX_FIFO_FLOW_CTL	BIT(24)
 #define EMAC_RX_DMA_EN  BIT(30)
 #define EMAC_RX_DMA_START       BIT(31)
 
@@ -766,6 +772,17 @@ 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);
 	if (fc & FLOW_TX)
 		v |= EMAC_TX_FLOW_CTL_EN;
-- 
2.56.1



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

* [PATCH net-next 3/3] net: stmmac: dwmac-sun8i: configure the pause time for TX flow control
  2026-11-22 14:49 [PATCH net-next 0/3] net: stmmac: dwmac-sun8i: enable Flow Control Maxime Chevallier
  2026-11-22 14:49 ` [PATCH net-next 1/3] net: stmmac: dwmac-sun8i: allow controlling TX and RX flow control separately Maxime Chevallier
  2026-11-22 14:49 ` [PATCH net-next 2/3] net: stmmac: dwmac-sun8i: emit pause frames when the RX FIFO fills Maxime Chevallier
@ 2026-11-22 14:49 ` Maxime Chevallier
  2026-11-22 15:58   ` Nicolai Buchwitz
  2 siblings, 1 reply; 8+ messages in thread
From: Maxime Chevallier @ 2026-11-22 14:49 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

When sending pause frames for flow control, we need to indicate the
number of quantums the peer should wait before sending more frames.

This is maintained in stmmac's "pause_time" global variable (it's a
module param).

Let's program the pause time value, and also allow sending the
zero-quanta pause frame when the peer can resume sending traffic.

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

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
index 75c743dfe348..613199da57c1 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
@@ -232,6 +232,8 @@ static const struct emac_variant emac_variant_h616_emac1 = {
 
 /* Used in EMAC_TX_FLOW_CTL */
 #define EMAC_TX_FLOW_CTL_EN             BIT(0)
+#define EMAC_TX_FLOW_CTL_ZQP_FRM_EN	BIT(1)
+#define EMAC_TX_FLOW_CTL_PAUSE_TIME	GENMASK(19, 4)
 
 /* Used in EMAC_INT_STA */
 #define EMAC_TX_INT             BIT(0)
@@ -784,10 +786,11 @@ static void sun8i_dwmac_flow_ctrl(struct mac_device_info *hw,
 	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);
 	if (fc & FLOW_TX)
-		v |= EMAC_TX_FLOW_CTL_EN;
-	else
-		v &= ~EMAC_TX_FLOW_CTL_EN;
+		v |= EMAC_TX_FLOW_CTL_EN | EMAC_TX_FLOW_CTL_ZQP_FRM_EN |
+		     FIELD_PREP(EMAC_TX_FLOW_CTL_PAUSE_TIME, pause_time);
 	writel(v, ioaddr + EMAC_TX_FLOW_CTL);
 }
 
-- 
2.56.1



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

* Re: [PATCH net-next 1/3] net: stmmac: dwmac-sun8i: allow controlling TX and RX flow control separately
  2026-11-22 14:49 ` [PATCH net-next 1/3] net: stmmac: dwmac-sun8i: allow controlling TX and RX flow control separately Maxime Chevallier
@ 2026-11-22 15:54   ` Nicolai Buchwitz
  2026-11-22 16:00   ` Chen-Yu Tsai
  1 sibling, 0 replies; 8+ messages in thread
From: Nicolai Buchwitz @ 2026-11-22 15:54 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 22.11.2026 15:49, Maxime Chevallier wrote:
> Currently, the sun8i flow control setup only looks at FLOW_AUTO (which
> is FLOW_RX | FLOW_TX), and enables RX/TX based on that.
> 
> Allow enabling RX/TX flow control directions separately.
> 
> Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>

> [...]

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

Thanks,
Nicolai


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

* Re: [PATCH net-next 2/3] net: stmmac: dwmac-sun8i: emit pause frames when the RX FIFO fills
  2026-11-22 14:49 ` [PATCH net-next 2/3] net: stmmac: dwmac-sun8i: emit pause frames when the RX FIFO fills Maxime Chevallier
@ 2026-11-22 15:57   ` Nicolai Buchwitz
  0 siblings, 0 replies; 8+ messages in thread
From: Nicolai Buchwitz @ 2026-11-22 15:57 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 22.11.2026 15:49, Maxime Chevallier wrote:
> The TX flow control mechanism needs multiple things setup to actually
> work:
> 
>  - The TX_FLOW_CTL_EN bit needs to be set in the TC_FLOW_CTL register,

nit: finger off by one :) TC_FLOW_CTL -> TX_FLOW_CTL

>    this is already done
> 
>  - The RX fifo thresholds needs to be set, to indicate when the MAC 
> needs
>    to start sending pause frames based on the RX fifo occupancy, and
>    when it should stop.
> 
> Let's configure the threshold the following way:
> 
>  - Send pause frames when there's less than 2K left in the RX fifo
>  - Stop sending them when there's more than 4K left in the RX fifo.
> 
> This was tested in Allwinner H2+ using the ethtool -t "flow control"
> selftest. On that SoC, the RX fifo is 16K.
> 
> Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>

> [...]

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

Thanks,
Nicolai


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

* Re: [PATCH net-next 3/3] net: stmmac: dwmac-sun8i: configure the pause time for TX flow control
  2026-11-22 14:49 ` [PATCH net-next 3/3] net: stmmac: dwmac-sun8i: configure the pause time for TX flow control Maxime Chevallier
@ 2026-11-22 15:58   ` Nicolai Buchwitz
  0 siblings, 0 replies; 8+ messages in thread
From: Nicolai Buchwitz @ 2026-11-22 15:58 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 22.11.2026 15:49, Maxime Chevallier wrote:
> When sending pause frames for flow control, we need to indicate the
> number of quantums the peer should wait before sending more frames.
> 
> This is maintained in stmmac's "pause_time" global variable (it's a
> module param).
> 
> Let's program the pause time value, and also allow sending the
> zero-quanta pause frame when the peer can resume sending traffic.
> 
> Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>

> [...]

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

Thanks,
Nicolai


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

* Re: [PATCH net-next 1/3] net: stmmac: dwmac-sun8i: allow controlling TX and RX flow control separately
  2026-11-22 14:49 ` [PATCH net-next 1/3] net: stmmac: dwmac-sun8i: allow controlling TX and RX flow control separately Maxime Chevallier
  2026-11-22 15:54   ` Nicolai Buchwitz
@ 2026-11-22 16:00   ` Chen-Yu Tsai
  1 sibling, 0 replies; 8+ messages in thread
From: Chen-Yu Tsai @ 2026-11-22 16:00 UTC (permalink / raw)
  To: Maxime Chevallier
  Cc: Andrew Lunn, Jakub Kicinski, davem, Eric Dumazet, Paolo Abeni,
	Simon Horman, Willem de Bruijn, Jernej Skrabec, Samuel Holland,
	Maxime Coquelin, Alexandre Torgue, Russell King, Lorenzo Bianconi,
	Nicolai Buchwitz, thomas.petazzoni, Alexis Lothoré, netdev,
	linux-kernel, linux-arm-kernel, linux-sunxi

On Sun, Nov 22, 2026 at 10:49 PM Maxime Chevallier
<maxime.chevallier@bootlin.com> wrote:
>
> Currently, the sun8i flow control setup only looks at FLOW_AUTO (which
> is FLOW_RX | FLOW_TX), and enables RX/TX based on that.
>
> Allow enabling RX/TX flow control directions separately.
>
> Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>

Reviewed-by: Chen-Yu Tsai <wens@kernel.org>


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

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

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-22 14:49 [PATCH net-next 0/3] net: stmmac: dwmac-sun8i: enable Flow Control Maxime Chevallier
2026-11-22 14:49 ` [PATCH net-next 1/3] net: stmmac: dwmac-sun8i: allow controlling TX and RX flow control separately Maxime Chevallier
2026-11-22 15:54   ` Nicolai Buchwitz
2026-11-22 16:00   ` Chen-Yu Tsai
2026-11-22 14:49 ` [PATCH net-next 2/3] net: stmmac: dwmac-sun8i: emit pause frames when the RX FIFO fills Maxime Chevallier
2026-11-22 15:57   ` Nicolai Buchwitz
2026-11-22 14:49 ` [PATCH net-next 3/3] net: stmmac: dwmac-sun8i: configure the pause time for TX flow control Maxime Chevallier
2026-11-22 15:58   ` Nicolai Buchwitz

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