Netdev List
 help / color / mirror / Atom feed
* [PATCH net-next v5] net: stmmac: program the FSM timeout timer
@ 2026-11-25 11:19 Zxyan Zhu
  2026-11-26  8:06 ` Maxime Chevallier
  2026-11-27 11:20 ` netdev-bot+sashiko
  0 siblings, 2 replies; 4+ messages in thread
From: Zxyan Zhu @ 2026-11-25 11:19 UTC (permalink / raw)
  To: maxime.chevallier, andrew+netdev, davem, edumazet, kuba, pabeni
  Cc: netdev, mcoquelin.stm32, alexandre.torgue, linux-stm32,
	linux-arm-kernel, linux-kernel, rmk+kernel, Zxyan Zhu

stmmac enables the FSM timeout checker (TMOUTEN) but never programs the
MAC_FSM_ACT_Timer register.  Per the databook the checker only fires once
NTMRMD is programmed with a non-zero duration; NTMRMD == 0 disables the
timer, so with TMOUTEN set but the timer left at reset a stuck FSM is
never reported and the advertised timeout protection is ineffective.

Program MAC_FSM_ACT_Timer right after TMOUTEN is enabled, deriving the
TMR field (CSR clocks per 1us tic) from the CSR clock rate and using a
4s timeout.  4s is chosen because a PAUSE frame with the maximum 0xffff
quanta stalls the transmitter for about 3.36s at 10 Mb/s, and a shorter
timeout could wrongly report a flow-control stall as a stuck FSM.

The NTMRMD field holds a power-of-two microsecond timeout per the
databook: 0x0 disables it, and 0x1..0xa encode 1us, 1.024ms (~1ms),
16.384ms (~16ms), 65.536ms (~64ms), 262.144ms (~256ms), 1.048s (~1s),
4.194s (~4s), 16.777s (~16s), 33.554s (~32s), 67.108s (~64s).

The issue was hit in testing on dwmac4 and dwxgmac, where a stuck FSM was
not reported through the safety interrupt despite TMOUTEN being set.

Signed-off-by: Zxyan Zhu <zxyan0222@gmail.com>
---
v5:
- Make the dwxgmac3 timer write unconditional, matching the unconditional
  XGMAC_TMOUTEN set, so NULL-config XGMAC platforms program it too.
- Bump the hardcoded timeout from 1s to 4s to cover a 10 Mb/s PAUSE stall
  (up to ~3.36s).

v4: https://lore.kernel.org/netdev/20261118025528.2703790-1-zxyan0222@gmail.com/
v3: https://lore.kernel.org/netdev/20261116114923.1157920-1-zxyan0222@gmail.com/
v2: https://lore.kernel.org/netdev/20261112053321.1103678-1-zxyan0222@gmail.com/
v1: https://lore.kernel.org/netdev/20261111143322.2234321-1-zxyan0222@gmail.com/

 drivers/net/ethernet/stmicro/stmmac/dwmac5.c   | 17 ++++++++++++++++-
 drivers/net/ethernet/stmicro/stmmac/dwmac5.h   |  6 +++++-
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h |  3 +++
 .../ethernet/stmicro/stmmac/dwxgmac2_core.c    | 18 +++++++++++++++++-
 drivers/net/ethernet/stmicro/stmmac/hwif.h     |  3 ++-
 .../net/ethernet/stmicro/stmmac/stmmac_main.c  |  8 +++++++-
 include/linux/stmmac.h                         | 12 ++++++++++++
 7 files changed, 62 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac5.c b/drivers/net/ethernet/stmicro/stmmac/dwmac5.c
index f1bb981cab7c..37e70b82c8b5 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac5.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac5.c
@@ -2,6 +2,7 @@
 // Copyright (c) 2017 Synopsys, Inc. and/or its affiliates.
 // stmmac Support for 5.xx Ethernet QoS cores
 
+#include <linux/bitfield.h>
 #include <linux/bitops.h>
 #include <linux/iopoll.h>
 #include "common.h"
@@ -184,7 +185,8 @@ static void dwmac5_handle_dma_err(struct net_device *ndev,
 }
 
 int dwmac5_safety_feat_config(void __iomem *ioaddr, unsigned int asp,
-			      struct stmmac_safety_feature_cfg *safety_feat_cfg)
+			      struct stmmac_safety_feature_cfg *safety_feat_cfg,
+			      unsigned int csr_clk_mhz)
 {
 	struct stmmac_safety_feature_cfg all_safety_feats = {
 		.tsoee = 1,
@@ -245,6 +247,19 @@ int dwmac5_safety_feat_config(void __iomem *ioaddr, unsigned int asp,
 		value |= TMOUTEN; /* FSM Timeout Feature */
 	writel(value, ioaddr + MAC_FSM_CONTROL);
 
+	/* Program the FSM active timer so the timeout checker actually fires.
+	 * TMR is the number of CSR clocks per 1us tic, i.e. csr_clk in MHz.
+	 * Use a 4s timeout.
+	 */
+	if (safety_feat_cfg->tmouten && csr_clk_mhz) {
+		value = readl(ioaddr + MAC_FSM_ACT_TIMER);
+		value &= ~(MAC_FSM_ACT_TIMER_NTMRMD | MAC_FSM_ACT_TIMER_TMR);
+		value |= FIELD_PREP(MAC_FSM_ACT_TIMER_NTMRMD,
+				    STMMAC_NTMRMD_4SEC) |
+			 FIELD_PREP(MAC_FSM_ACT_TIMER_TMR, csr_clk_mhz);
+		writel(value, ioaddr + MAC_FSM_ACT_TIMER);
+	}
+
 	/* 4. Enable Data Parity Protection */
 	value = readl(ioaddr + MTL_DPP_CONTROL);
 	if (safety_feat_cfg->edpp)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac5.h b/drivers/net/ethernet/stmicro/stmmac/dwmac5.h
index 00b151b3b688..734e7630f28d 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac5.h
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac5.h
@@ -8,8 +8,11 @@
 #define MAC_DPP_FSM_INT_STATUS		0x00000140
 #define MAC_AXI_SLV_DPE_ADDR_STATUS	0x00000144
 #define MAC_FSM_CONTROL			0x00000148
+#define MAC_FSM_ACT_TIMER		0x0000014C
 #define PRTYEN				BIT(1)
 #define TMOUTEN				BIT(0)
+#define MAC_FSM_ACT_TIMER_TMR		GENMASK(9, 0)
+#define MAC_FSM_ACT_TIMER_NTMRMD	GENMASK(19, 16)
 
 #define MAC_PPS_CONTROL			0x00000b70
 #define PPS_MAXIDX(x)			((((x) + 1) * 8) - 1)
@@ -82,7 +85,8 @@
 #define GMAC_INT_FPE_EN			BIT(17)
 
 int dwmac5_safety_feat_config(void __iomem *ioaddr, unsigned int asp,
-			      struct stmmac_safety_feature_cfg *safety_cfg);
+			      struct stmmac_safety_feature_cfg *safety_cfg,
+			      unsigned int csr_clk_mhz);
 int dwmac5_safety_feat_irq_status(struct net_device *ndev,
 		void __iomem *ioaddr, unsigned int asp,
 		struct stmmac_safety_stats *stats);
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h
index f8ab347f7b5b..1fd501728b18 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h
+++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h
@@ -169,8 +169,11 @@
 #define XGMAC_HWFEAT_PCSEL		GENMASK(1, 0)
 #define XGMAC_MAC_DPP_FSM_INT_STATUS	0x00000150
 #define XGMAC_MAC_FSM_CONTROL		0x00000158
+#define XGMAC_MAC_FSM_ACT_TIMER		0x0000015C
 #define XGMAC_PRTYEN			BIT(1)
 #define XGMAC_TMOUTEN			BIT(0)
+#define XGMAC_MAC_FSM_ACT_TIMER_TMR		GENMASK(9, 0)
+#define XGMAC_MAC_FSM_ACT_TIMER_NTMRMD		GENMASK(19, 16)
 #define XGMAC_MDIO_ADDR			0x00000200
 #define XGMAC_MDIO_DATA			0x00000204
 #define XGMAC_MDIO_C22P			0x00000220
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
index 09194b9d8322..d5bcbd6dfadf 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
@@ -4,6 +4,7 @@
  * stmmac XGMAC support.
  */
 
+#include <linux/bitfield.h>
 #include <linux/bitrev.h>
 #include <linux/crc32.h>
 #include <linux/iopoll.h>
@@ -837,7 +838,8 @@ static void dwxgmac3_handle_dma_err(struct net_device *ndev,
 
 static int
 dwxgmac3_safety_feat_config(void __iomem *ioaddr, unsigned int asp,
-			    struct stmmac_safety_feature_cfg *safety_cfg)
+			    struct stmmac_safety_feature_cfg *safety_cfg,
+			    unsigned int csr_clk_mhz)
 {
 	u32 value;
 
@@ -873,6 +875,20 @@ dwxgmac3_safety_feat_config(void __iomem *ioaddr, unsigned int asp,
 	value |= XGMAC_TMOUTEN; /* FSM Timeout Feature */
 	writel(value, ioaddr + XGMAC_MAC_FSM_CONTROL);
 
+	/* Program the FSM active timer so the timeout checker actually fires.
+	 * TMR is the number of CSR clocks per 1us tic, i.e. csr_clk in MHz.
+	 * Use a 4s timeout.
+	 */
+	if (csr_clk_mhz) {
+		value = readl(ioaddr + XGMAC_MAC_FSM_ACT_TIMER);
+		value &= ~(XGMAC_MAC_FSM_ACT_TIMER_NTMRMD |
+			   XGMAC_MAC_FSM_ACT_TIMER_TMR);
+		value |= FIELD_PREP(XGMAC_MAC_FSM_ACT_TIMER_NTMRMD,
+				    STMMAC_NTMRMD_4SEC) |
+			 FIELD_PREP(XGMAC_MAC_FSM_ACT_TIMER_TMR, csr_clk_mhz);
+		writel(value, ioaddr + XGMAC_MAC_FSM_ACT_TIMER);
+	}
+
 	/* 5. Enable Data Path Parity Protection */
 	value = readl(ioaddr + XGMAC_MTL_DPP_CONTROL);
 	/* already enabled by default, explicit enable it again */
diff --git a/drivers/net/ethernet/stmicro/stmmac/hwif.h b/drivers/net/ethernet/stmicro/stmmac/hwif.h
index 047bda5cbd92..6895ae21f918 100644
--- a/drivers/net/ethernet/stmicro/stmmac/hwif.h
+++ b/drivers/net/ethernet/stmicro/stmmac/hwif.h
@@ -380,7 +380,8 @@ struct stmmac_ops {
 			     bool srgmi_ral);
 	/* Safety Features */
 	int (*safety_feat_config)(void __iomem *ioaddr, unsigned int asp,
-				  struct stmmac_safety_feature_cfg *safety_cfg);
+				  struct stmmac_safety_feature_cfg *safety_cfg,
+				  unsigned int csr_clk_mhz);
 	int (*safety_feat_irq_status)(struct net_device *ndev,
 			void __iomem *ioaddr, unsigned int asp,
 			struct stmmac_safety_stats *stats);
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index ca4c7fb11b73..4ee4952a1427 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -3707,10 +3707,16 @@ static void stmmac_mtl_configuration(struct stmmac_priv *priv)
 
 static void stmmac_safety_feat_configuration(struct stmmac_priv *priv)
 {
+	unsigned int csr_clk_mhz = 0;
+
 	if (priv->dma_cap.asp) {
 		netdev_info(priv->dev, "Enabling Safety Features\n");
+		if (priv->plat->stmmac_clk)
+			csr_clk_mhz = clk_get_rate(priv->plat->stmmac_clk) /
+				      1000000;
 		stmmac_safety_feat_config(priv, priv->ioaddr, priv->dma_cap.asp,
-					  priv->plat->safety_feat_cfg);
+					  priv->plat->safety_feat_cfg,
+					  csr_clk_mhz);
 	} else {
 		netdev_info(priv->dev, "No Safety Features support found\n");
 	}
diff --git a/include/linux/stmmac.h b/include/linux/stmmac.h
index 00be2df63d22..659f5db528d3 100644
--- a/include/linux/stmmac.h
+++ b/include/linux/stmmac.h
@@ -170,6 +170,18 @@ struct stmmac_safety_feature_cfg {
 	u32 tmouten;
 };
 
+/* MAC_FSM_ACT_Timer.NTMRMD timeout durations */
+#define STMMAC_NTMRMD_1US		0x1
+#define STMMAC_NTMRMD_1MS		0x2
+#define STMMAC_NTMRMD_16MS		0x3
+#define STMMAC_NTMRMD_64MS		0x4
+#define STMMAC_NTMRMD_256MS		0x5
+#define STMMAC_NTMRMD_1SEC		0x6
+#define STMMAC_NTMRMD_4SEC		0x7
+#define STMMAC_NTMRMD_16SEC		0x8
+#define STMMAC_NTMRMD_32SEC		0x9
+#define STMMAC_NTMRMD_64SEC		0xa
+
 /* Addresses that may be customized by a platform */
 struct dwmac4_addrs {
 	u32 dma_chan;
-- 
2.34.1


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

* Re: [PATCH net-next v5] net: stmmac: program the FSM timeout timer
  2026-11-25 11:19 [PATCH net-next v5] net: stmmac: program the FSM timeout timer Zxyan Zhu
@ 2026-11-26  8:06 ` Maxime Chevallier
  2026-11-26  9:19   ` zhu xin
  2026-11-27 11:20 ` netdev-bot+sashiko
  1 sibling, 1 reply; 4+ messages in thread
From: Maxime Chevallier @ 2026-11-26  8:06 UTC (permalink / raw)
  To: Zxyan Zhu, andrew+netdev, davem, edumazet, kuba, pabeni
  Cc: netdev, mcoquelin.stm32, alexandre.torgue, linux-stm32,
	linux-arm-kernel, linux-kernel, rmk+kernel

Hi,

On 11/25/26 12:19, Zxyan Zhu wrote:
> stmmac enables the FSM timeout checker (TMOUTEN) but never programs the
> MAC_FSM_ACT_Timer register.  Per the databook the checker only fires once
> NTMRMD is programmed with a non-zero duration; NTMRMD == 0 disables the
> timer, so with TMOUTEN set but the timer left at reset a stuck FSM is
> never reported and the advertised timeout protection is ineffective.
> 
> Program MAC_FSM_ACT_Timer right after TMOUTEN is enabled, deriving the
> TMR field (CSR clocks per 1us tic) from the CSR clock rate and using a
> 4s timeout.  4s is chosen because a PAUSE frame with the maximum 0xffff
> quanta stalls the transmitter for about 3.36s at 10 Mb/s, and a shorter
> timeout could wrongly report a flow-control stall as a stuck FSM.
> 
> The NTMRMD field holds a power-of-two microsecond timeout per the
> databook: 0x0 disables it, and 0x1..0xa encode 1us, 1.024ms (~1ms),
> 16.384ms (~16ms), 65.536ms (~64ms), 262.144ms (~256ms), 1.048s (~1s),
> 4.194s (~4s), 16.777s (~16s), 33.554s (~32s), 67.108s (~64s).
> 
> The issue was hit in testing on dwmac4 and dwxgmac, where a stuck FSM was
> not reported through the safety interrupt despite TMOUTEN being set.
> 
> Signed-off-by: Zxyan Zhu <zxyan0222@gmail.com>

[...]

> diff --git a/include/linux/stmmac.h b/include/linux/stmmac.h
> index 00be2df63d22..659f5db528d3 100644
> --- a/include/linux/stmmac.h
> +++ b/include/linux/stmmac.h
> @@ -170,6 +170,18 @@ struct stmmac_safety_feature_cfg {
>  	u32 tmouten;
>  };
>  
> +/* MAC_FSM_ACT_Timer.NTMRMD timeout durations */
> +#define STMMAC_NTMRMD_1US		0x1
> +#define STMMAC_NTMRMD_1MS		0x2
> +#define STMMAC_NTMRMD_16MS		0x3
> +#define STMMAC_NTMRMD_64MS		0x4
> +#define STMMAC_NTMRMD_256MS		0x5
> +#define STMMAC_NTMRMD_1SEC		0x6
> +#define STMMAC_NTMRMD_4SEC		0x7
> +#define STMMAC_NTMRMD_16SEC		0x8
> +#define STMMAC_NTMRMD_32SEC		0x9
> +#define STMMAC_NTMRMD_64SEC		0xa

This whole patch starts to look good, one last comment, sorry I
didn't spot this before. Can you put all these definitions
in the "common.h" file in the driver folder ? These are some
register values (same on dwmac5 and xgmac, but still), so they
should go there.

With that changed, you can send a new iteration with

  Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com>

Thanks,

Maxime

pw-bot: cr



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

* Re: [PATCH net-next v5] net: stmmac: program the FSM timeout timer
  2026-11-26  8:06 ` Maxime Chevallier
@ 2026-11-26  9:19   ` zhu xin
  0 siblings, 0 replies; 4+ messages in thread
From: zhu xin @ 2026-11-26  9:19 UTC (permalink / raw)
  To: Maxime Chevallier
  Cc: andrew+netdev, davem, edumazet, kuba, pabeni, netdev,
	mcoquelin.stm32, alexandre.torgue, linux-stm32, linux-arm-kernel,
	linux-kernel, rmk+kernel

Hi Maxime,

On Thu, Nov 26, 2026 at 4:07 PM Maxime Chevallier
<maxime.chevallier@bootlin.com> wrote:
>
> Hi,
>
> On 11/25/26 12:19, Zxyan Zhu wrote:
> > stmmac enables the FSM timeout checker (TMOUTEN) but never programs the
> > MAC_FSM_ACT_Timer register.  Per the databook the checker only fires once
> > NTMRMD is programmed with a non-zero duration; NTMRMD == 0 disables the
> > timer, so with TMOUTEN set but the timer left at reset a stuck FSM is
> > never reported and the advertised timeout protection is ineffective.
> >
> > Program MAC_FSM_ACT_Timer right after TMOUTEN is enabled, deriving the
> > TMR field (CSR clocks per 1us tic) from the CSR clock rate and using a
> > 4s timeout.  4s is chosen because a PAUSE frame with the maximum 0xffff
> > quanta stalls the transmitter for about 3.36s at 10 Mb/s, and a shorter
> > timeout could wrongly report a flow-control stall as a stuck FSM.
> >
> > The NTMRMD field holds a power-of-two microsecond timeout per the
> > databook: 0x0 disables it, and 0x1..0xa encode 1us, 1.024ms (~1ms),
> > 16.384ms (~16ms), 65.536ms (~64ms), 262.144ms (~256ms), 1.048s (~1s),
> > 4.194s (~4s), 16.777s (~16s), 33.554s (~32s), 67.108s (~64s).
> >
> > The issue was hit in testing on dwmac4 and dwxgmac, where a stuck FSM was
> > not reported through the safety interrupt despite TMOUTEN being set.
> >
> > Signed-off-by: Zxyan Zhu <zxyan0222@gmail.com>
>
> [...]
>
> > diff --git a/include/linux/stmmac.h b/include/linux/stmmac.h
> > index 00be2df63d22..659f5db528d3 100644
> > --- a/include/linux/stmmac.h
> > +++ b/include/linux/stmmac.h
> > @@ -170,6 +170,18 @@ struct stmmac_safety_feature_cfg {
> >       u32 tmouten;
> >  };
> >
> > +/* MAC_FSM_ACT_Timer.NTMRMD timeout durations */
> > +#define STMMAC_NTMRMD_1US            0x1
> > +#define STMMAC_NTMRMD_1MS            0x2
> > +#define STMMAC_NTMRMD_16MS           0x3
> > +#define STMMAC_NTMRMD_64MS           0x4
> > +#define STMMAC_NTMRMD_256MS          0x5
> > +#define STMMAC_NTMRMD_1SEC           0x6
> > +#define STMMAC_NTMRMD_4SEC           0x7
> > +#define STMMAC_NTMRMD_16SEC          0x8
> > +#define STMMAC_NTMRMD_32SEC          0x9
> > +#define STMMAC_NTMRMD_64SEC          0xa
>
> This whole patch starts to look good, one last comment, sorry I
> didn't spot this before. Can you put all these definitions
> in the "common.h" file in the driver folder ? These are some
> register values (same on dwmac5 and xgmac, but still), so they
> should go there.
>
> With that changed, you can send a new iteration with
>
>   Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com>

Sure, I'll move the STMMAC_NTMRMD_* encodings to the driver's common.h.
v6 follows with your Reviewed-by.

>
> Thanks,
>
> Maxime
>
> pw-bot: cr
>
>

Thanks,
 Zxyan

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

* Re: [PATCH net-next v5] net: stmmac: program the FSM timeout timer
  2026-11-25 11:19 [PATCH net-next v5] net: stmmac: program the FSM timeout timer Zxyan Zhu
  2026-11-26  8:06 ` Maxime Chevallier
@ 2026-11-27 11:20 ` netdev-bot+sashiko
  1 sibling, 0 replies; 4+ messages in thread
From: netdev-bot+sashiko @ 2026-11-27 11:20 UTC (permalink / raw)
  To: zxyan0222
  Cc: maxime.chevallier, andrew+netdev, davem, edumazet, kuba, pabeni,
	netdev, mcoquelin.stm32, alexandre.torgue, linux-stm32,
	linux-arm-kernel, linux-kernel, rmk+kernel

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

Critical: 0 · High: 0 · Medium: 2 · Low: 2

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 arms a 4 s FSM timeout that had no effect before.
- [Medium] On platforms where csr_clk_mhz ends up 0, the fix silently
  does nothing.
- [Low] With this patch, a timed-out FSM is no longer just 'reported'.
- [Low] The patch is presented as a fix for a functional defect found in
  testing: TMOUTEN is enabled but MAC_FSM_ACT_Timer is never programmed.

--

net: stmmac: program the FSM timeout timer

This commit programs the MAC_FSM_ACT_Timer register in
dwmac5_safety_feat_config() and dwxgmac3_safety_feat_config(), so the FSM
timeout checker enabled by TMOUTEN actually fires. It uses a fixed 4s
NTMRMD timeout and derives the TMR field from the stmmac_clk rate. The rate
is passed down through a new csr_clk_mhz argument to the safety_feat_config
callback.

> The issue was hit in testing on dwmac4 and dwxgmac, where a stuck FSM was
> not reported through the safety interrupt despite TMOUTEN being set.

[Severity: Low]
This isn't a bug, but should the commit message mention that a timed-out
FSM now leads to a full adapter reset, not just a report?

dwmac5_safety_feat_irq_status() and dwxgmac3_safety_feat_irq_status()
hard-code corr = false for MCSIS errors. As a result,
stmmac_safety_feat_interrupt() calls stmmac_global_err().

When a usable stmmac_clk is present, this becomes the default in these
cases:

  - GMAC4/5 cores with asp >= 2 and tmouten set. This includes platforms
    with a NULL safety_feat_cfg, which fall back to all_safety_feats with
    .tmouten = 1.

  - Every XGMAC core with asp != 0x4, because
    dwxgmac3_safety_feat_config() ignores safety_cfg and sets
    XGMAC_TMOUTEN unconditionally.

> Signed-off-by: Zxyan Zhu <zxyan0222@gmail.com>

[Severity: Low]
This fixes a defect that was hit in testing. Should it carry a Fixes: tag
and say whether it is meant for net or net-next?

The missing timer programming goes back to the commits that first enabled
TMOUTEN. For GMAC that is "net: stmmac: Add support for DWMAC5 and
implement Safety Features". For XGMAC it is "net: stmmac: Implement Safety
Features in XGMAC core".

> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac5.c b/drivers/net/ethernet/stmicro/stmmac/dwmac5.c
> index f1bb981cab7cd..37e70b82c8b56 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac5.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac5.c

[ ... ]

> @@ -245,6 +247,19 @@ int dwmac5_safety_feat_config(void __iomem *ioaddr, unsigned int asp,
>  		value |= TMOUTEN; /* FSM Timeout Feature */
>  	writel(value, ioaddr + MAC_FSM_CONTROL);
>  
> +	/* Program the FSM active timer so the timeout checker actually fires.
> +	 * TMR is the number of CSR clocks per 1us tic, i.e. csr_clk in MHz.
> +	 * Use a 4s timeout.
> +	 */
> +	if (safety_feat_cfg->tmouten && csr_clk_mhz) {
> +		value = readl(ioaddr + MAC_FSM_ACT_TIMER);
> +		value &= ~(MAC_FSM_ACT_TIMER_NTMRMD | MAC_FSM_ACT_TIMER_TMR);
> +		value |= FIELD_PREP(MAC_FSM_ACT_TIMER_NTMRMD,
> +				    STMMAC_NTMRMD_4SEC) |
> +			 FIELD_PREP(MAC_FSM_ACT_TIMER_TMR, csr_clk_mhz);
> +		writel(value, ioaddr + MAC_FSM_ACT_TIMER);
> +	}

[Severity: Medium]
The 4s value is justified by a single PAUSE frame with 0xffff quanta at
10 Mb/s, which stalls the transmitter for about 3.36s. The commit message
also accepts that a flow-control stall counts against this timer ("could
wrongly report a flow-control stall as a stuck FSM").

Can a link partner keep the transmitter paused for longer than that? Under
802.3x the peer can send a new PAUSE frame before the current one expires.
A congested switch or a misbehaving peer could then hold off transmission
indefinitely.

If a refreshed pause doesn't restart the FSM activity timer, would TTES
fire after about 4.19s at any link speed?

That error is handled as uncorrectable:

dwmac5_safety_feat_irq_status()
    err = (mtl & MCSIS) || (dma & MCSIS);
    corr = false;
    if (err) {
        dwmac5_handle_mac_err(ndev, ioaddr, corr, stats);
        ret |= !corr;
    }

stmmac_safety_feat_interrupt()
    if (ret && (ret != -EINVAL)) {
        stmmac_global_err(priv);

dwxgmac3_safety_feat_irq_status() behaves the same way. The reset path goes
back through stmmac_safety_feat_configuration(), which re-arms the same
timer. Could a sustained PAUSE stream then cause repeated adapter resets?

Separately, only NTMRMD (bits 19:16) and TMR are programmed here. The
read-modify-write keeps the rest of MAC_FSM_ACT_Timer unchanged. LTMRMD
(bits 23:20 in the databook) is not defined or mentioned, so it stays at
its reset value.

Is a paused TX FSM timed by NTMRMD, or by the large mode LTMRMD field?

The margin is also small: 4.194s against 3.36s is about 25%.

The same timeout is programmed in dwxgmac3_safety_feat_config(), where
XGMAC_TMOUTEN is set unconditionally. Platforms there cannot opt out
through safety_feat_cfg->tmouten.

[ ... ]

> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> index ca4c7fb11b73f..4ee4952a14273 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> @@ -3707,10 +3707,16 @@ static void stmmac_mtl_configuration(struct stmmac_priv *priv)
>  
>  static void stmmac_safety_feat_configuration(struct stmmac_priv *priv)
>  {
> +	unsigned int csr_clk_mhz = 0;
> +
>  	if (priv->dma_cap.asp) {
>  		netdev_info(priv->dev, "Enabling Safety Features\n");
> +		if (priv->plat->stmmac_clk)
> +			csr_clk_mhz = clk_get_rate(priv->plat->stmmac_clk) /
> +				      1000000;

[Severity: Medium]
Can csr_clk_mhz end up as 0 here on platforms that ask for the FSM
timeout? It stays 0 in three cases:

  - plat->stmmac_clk is NULL.
  - The clock rate is below 1 MHz.
  - CONFIG_HAVE_CLK=n, where the clk_get_rate() stub returns 0.

In that case both config functions still set the enable bit but skip the
MAC_FSM_ACT_Timer write. dwmac5_safety_feat_config() sets TMOUTEN based on
safety_feat_cfg->tmouten alone, and dwxgmac3_safety_feat_config() sets
XGMAC_TMOUTEN unconditionally. The timer writes are gated like this:

dwmac5_safety_feat_config()
    if (safety_feat_cfg->tmouten && csr_clk_mhz) {

dwxgmac3_safety_feat_config()
    if (csr_clk_mhz) {

Doesn't that leave the state the commit message calls broken, with
TMOUTEN set, NTMRMD at 0, and nothing logged?

At least one in-tree platform seems to hit this. stmmac_pci.c never
assigns plat->stmmac_clk, but it does request the timeout:

snps_gmac5_default_data()
    plat->clk_csr = STMMAC_CSR_250_300M;

stmmac_pci_probe()
    plat->safety_feat_cfg->tmouten = 1;

Tegra MGBE (XGMAC) gets its platform data from
devm_stmmac_probe_config_dt(), which looks up the "stmmaceth" clock. That
clock is not in the Tegra mgbe_clks list, so stmmac_clk is NULL there too.
If that IP reports asp, the XGMAC timer write would also be skipped.

stmmac_mdio_bus_config() already prefers the platform-provided CSR clock
over the stmmac_clk rate:

    if (priv->plat->clk_csr >= 0)
        value = priv->plat->clk_csr;

Could this fall back to a rate derived from plat->clk_csr, or at least
warn when the timer cannot be programmed?

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261125111929.3395740-1-zxyan0222%40gmail.com

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

end of thread, other threads:[~2026-11-27 11:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 11:19 [PATCH net-next v5] net: stmmac: program the FSM timeout timer Zxyan Zhu
2026-11-26  8:06 ` Maxime Chevallier
2026-11-26  9:19   ` zhu xin
2026-11-27 11:20 ` 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