Skip to contentSkip to conversation

net: stmmac: dwmac-sun8i: enable Flow Control

PATCH In review Maxime Chevallier 4 participants 12 messages Nov 22 – Nov 23

Subsystems (5)
lore
Share & tools
lore

Maxime Chevallier

author maintainer
#0 lore raw

cover net: stmmac: dwmac-sun8i: enable Flow Control

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(-)
Signature · 1 line
2.56.1
author maintainer
#1 lore raw

PATCH 1/3 net: stmmac: dwmac-sun8i: allow controlling TX and RX flow control separately

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.

---
 drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +2 -2
index 2ece7ba9dd73..c63f4d87de50 100644
@@ -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;
Signature · 1 line
2.56.1
Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH net-next 1/3] net: stmmac: dwmac-sun8i: allow controlling TX and RX flow control separately

Hi Maxime

Quoted 8 lines · Maxime Chevallier

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.

[...]

Thanks,
Nicolai

maintainer Reviewed-by on v1 1/3
#3 lore raw

Re: [PATCH net-next 1/3] net: stmmac: dwmac-sun8i: allow controlling TX and RX flow control separately

In reply to Maxime Chevallier
Quoted 7 lines · Maxime Chevallier

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.

#4 lore raw

Re: [PATCH net-next 1/3] net: stmmac: dwmac-sun8i: allow controlling TX and RX flow control separately

In reply to Maxime Chevallier
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] In drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c, the commit message for sun8i_dwmac_flow_ctrl() presents the change as a new…

--

net: stmmac: dwmac-sun8i: allow controlling TX and RX flow control separately

This changes sun8i_dwmac_flow_ctrl() in dwmac-sun8i.c to test the FLOW_RX and FLOW_TX bits on their own. Before, it only enabled EMAC_RX_FLOW_CTL_EN and EMAC_TX_FLOW_CTL_EN when fc == FLOW_AUTO.

Quoted 4 lines

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.

[Severity: Low]
Would this be better described as a fix than as a new capability?

Since commit 9cb54af214a7 ("net: stmmac: Fix IP-cores specific MAC capabilities"), sun8i_dwmac_setup() advertises asymmetric pause to phylink:

    mac->link.caps = MAC_ASYM_PAUSE | MAC_SYM_PAUSE |
                     MAC_10 | MAC_100 | MAC_1000;

When pause resolves asymmetrically, stmmac_mac_link_up() passes a single direction:

    if (rx_pause && tx_pause)
        flow_ctrl = FLOW_AUTO;
    else if (rx_pause && !tx_pause)
        flow_ctrl = FLOW_RX;
    else if (!rx_pause && tx_pause)
        flow_ctrl = FLOW_TX;

With the old fc == FLOW_AUTO test in sun8i_dwmac_flow_ctrl(), FLOW_RX or FLOW_TX alone cleared both EMAC_RX_FLOW_CTL_EN and EMAC_TX_FLOW_CTL_EN. Phylink and ethtool -a still reported pause as active.

There are two ways to reach the rx-only case:

- The link partner advertises only Asym_Pause, so linkmode_resolve_pause() gives rx_pause=1 and tx_pause=0.
- The admin runs "ethtool -A ethX autoneg off rx on tx off".

In that case the MAC ignores the partner's PAUSE frames.

Should the commit message say that this fixes that behaviour, and add a tag like this one?

Fixes 9f93ac8d4085 ("net-next: stmmac: Add dwmac-sun8i")

That would let the stable maintainers consider it for backporting.

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261122144926.284857-1-maxime.chevallier%40bootlin.com
author maintainer
#5 lore raw

PATCH 2/3 net: stmmac: dwmac-sun8i: emit pause frames when the RX FIFO fills

In reply to Maxime Chevallier

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.

---
 .../net/ethernet/stmicro/stmmac/dwmac-sun8i.c   | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +17 -0
index c63f4d87de50..75c743dfe348 100644
@@ -5,6 +5,7 @@
  * Copyright (C) 2017 Corentin Labbe <[email protected]>
  */
 
+#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;
Signature · 1 line
2.56.1
Reviewed-by on v1 2/3
#6 lore raw

Re: [PATCH net-next 2/3] net: stmmac: dwmac-sun8i: emit pause frames when the RX FIFO fills

Quoted 4 lines · Maxime Chevallier

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

Quoted 12 lines

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.

Quoted 6 lines

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

[...]

Thanks,
Nicolai

maintainer Reviewed-by on v1 2/3
#7 lore raw

Re: [PATCH net-next 2/3] net: stmmac: dwmac-sun8i: emit pause frames when the RX FIFO fills

In reply to Maxime Chevallier
Quoted 5 lines · Maxime Chevallier

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,

typo, as Nicolai mentioned

Quoted 6 lines

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.

Quoted 7 lines

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.

The latest chips (A133, A523) only have 8K for the RX FIFO. I think that still works.

Quoted 1 line
Quoted 50 lines
---
 .../net/ethernet/stmicro/stmmac/dwmac-sun8i.c   | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +17 -1
index c63f4d87de50..75c743dfe348 100644
@@ -5,6 +5,7 @@
  * Copyright (C) 2017 Corentin Labbe <[email protected]>
  */
 
+#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

#8 lore raw

Re: [PATCH net-next 2/3] net: stmmac: dwmac-sun8i: emit pause frames when the RX FIFO fills

In reply to Maxime Chevallier
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

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

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

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] Unserialized read-modify-write of EMAC_RX_CTL1 in sun8i_dwmac_flow_ctrl() (drivers/net/ethernet/stmicro/stmmac/dwmac-…

--

net: stmmac: dwmac-sun8i: emit pause frames when the RX FIFO fills

This commit sets the RX FIFO flow control thresholds in EMAC_RX_CTL1 from sun8i_dwmac_flow_ctrl(). With these thresholds, the MAC sends pause frames when less than 2K is left in the RX FIFO and stops when more than 4K is free. The new bits are set only when TX flow control is requested.

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +0 -0
index c63f4d87de509..75c743dfe3483 100644

[ ... ]

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +0 -0
@@ -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);
 

drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c static void sun8i_dwmac_flow_ctrl(struct mac_device_info *hw, · line 784

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +10 -0
+	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: Medium]
Can this read-modify-write of EMAC_RX_CTL1 race with the RX DMA start and stop helpers?

EMAC_RX_CTL1 also holds EMAC_RX_DMA_EN and EMAC_RX_DMA_START. sun8i_dwmac_dma_start_rx() and sun8i_dwmac_dma_stop_rx() update those bits without a lock:

    v = readl(ioaddr + EMAC_RX_CTL1);
    v &= ~EMAC_RX_DMA_EN;
    writel(v, ioaddr + EMAC_RX_CTL1);

The phylink resolve worker reaches sun8i_dwmac_flow_ctrl() through this path:

phylink_resolve()
phylink_link_up()

    stmmac_mac_link_up()
      stmmac_mac_flow_ctrl()
        sun8i_dwmac_flow_ctrl()

That path holds pl->phydev_mutex and pl->state_mutex, but not rtnl.

On the XDP and XSK paths, the DMA start and stop callers hold only rtnl and never call phylink_stop(). One example:

stmmac_xdp_set_prog()
stmmac_xdp_release()
stmmac_stop_all_dma()
free_dma_desc_resources()

The same applies to stmmac_xdp_open()->stmmac_start_all_dma(), and to stmmac_disable_rx_queue() and stmmac_enable_rx_queue() during XSK pool setup.

If a link-up event is handled while an XDP program is being attached or detached, two interleavings look possible.

In the first, flow_ctrl reads RX_CTL1 while DMA_EN is set. Then stmmac_xdp_release() clears DMA_EN and frees the RX rings. Finally, flow_ctrl writes back the stale value, which sets DMA_EN again.

If the sun8i RX DMA resumes on DMA_EN alone, could the hardware then access the freed descriptors?

In the second, flow_ctrl reads DMA_EN as 0. Then stmmac_xdp_open() or stmmac_enable_rx_queue() sets DMA_EN | DMA_START, and flow_ctrl writes DMA_EN back as 0.

Would RX then stay stopped until the interface is reconfigured?

Before this patch, flow_ctrl did not touch EMAC_RX_CTL1, so these writers could not overlap. Could accesses to this register be serialized, or could the thresholds be programmed from a path that is already ordered against DMA start and stop?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261122144926.284857-1-maxime.chevallier%40bootlin.com
author maintainer
#9 lore raw

Re: [PATCH net-next 2/3] net: stmmac: dwmac-sun8i: emit pause frames when the RX FIFO fills

Quoted 34 lines · On 11/23/26 15:51, [email protected] wrote:

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

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

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] Unserialized read-modify-write of EMAC_RX_CTL1 in sun8i_dwmac_flow_ctrl() (drivers/net/ethernet/stmicro/stmmac/dwmac-…

--

net: stmmac: dwmac-sun8i: emit pause frames when the RX FIFO fills

This commit sets the RX FIFO flow control thresholds in EMAC_RX_CTL1 from sun8i_dwmac_flow_ctrl(). With these thresholds, the MAC sends pause frames when less than 2K is left in the RX FIFO and stops when more than 4K is free. The new bits are set only when TX flow control is requested.

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +0 -0
index c63f4d87de509..75c743dfe3483 100644

[ ... ]

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +0 -0
@@ -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);
 
Quoted 14 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c static void sun8i_dwmac_flow_ctrl(struct mac_device_info *hw, · line 784

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +10 -0
+	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: Medium]
Can this read-modify-write of EMAC_RX_CTL1 race with the RX DMA start and stop helpers?

Hmmm yes indeed, I think we can work around that by writing these FIFO values in sun8i_dwmac_dma_operation_mode_rx(), just like we do in dwmac1000 and dwmac4, that way no race :)

I'll iterate and fix my typos,

Maxime

author maintainer
#10 lore raw

PATCH 3/3 net: stmmac: dwmac-sun8i: configure the pause time for TX flow control

In reply to Maxime Chevallier

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.

---
 drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +6 -3
index 75c743dfe348..613199da57c1 100644
@@ -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);
 }
 
Signature · 1 line
2.56.1
Reviewed-by on v1 3/3
#11 lore raw

Re: [PATCH net-next 3/3] net: stmmac: dwmac-sun8i: configure the pause time for TX flow control

Quoted 6 lines · Maxime Chevallier

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

Quoted 6 lines

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

[...]

Thanks,
Nicolai