Skip to contentSkip to conversation

net: stmmac: hold the MDIO bus lock during the MAC soft reset

PATCH In review Savvas Etairidis 4 participants 4 messages Dec 2 – Dec 4

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: stmmac: hold the MDIO bus lock during the MAC soft reset

From: Savvas Etairidis <[email protected]>

The MAC soft reset in stmmac_init_dma_engine() stops the MDIO master. If an MDIO transaction is in flight at that moment, it is cut off in the middle of a frame. On a Realtek switch managed over MDIO (SMI), this was seen to store a value in the wrong register (0x00bb written to 0x08a2) or leave the switch not answering.

Take the MDIO bus lock around the reset with stmmac_mdio_lock(), as dwmac-dwc-qos-eth already does for its pad calibration, so that no transaction can be running while the reset happens. Every MDIO transaction holds this lock for the whole frame.

On two boards, forced MAC resets triggered the corruption within 250 resets without the lock. With the lock, 36000 forced resets caused none.

stmmac_init_dma_engine() is only called from __stmmac_open() and stmmac_resume(), neither of which holds the bus lock.

This patch was developed with the help of an AI coding assistant (Claude Code). It wrote the change and the changelog. I reviewed both and tested the fix on 6.6.162 hardware (36000 forced MAC resets with the lock, none failing).

Fixes 47dd7a540b8a ("net: add support for STMicroelectronics Ethernet controllers.")
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +3 -0
index a685ce4638f6..1011e08f20c8 100644
@@ -3331,7 +3331,10 @@ static int stmmac_init_dma_engine(struct stmmac_priv *priv)
 	if (ret)
 		return ret;
 
+	/* The soft reset stops the MDIO master, so keep the bus idle. */
+	stmmac_mdio_lock(priv);
 	ret = stmmac_reset(priv);
+	stmmac_mdio_unlock(priv);
 	if (ret) {
 		netdev_err(priv->dev, "Failed to reset the dma\n");
 		return ret;
Signature · 1 line
2.56.1
#1 lore raw
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

Hi!

This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

- What hardware the change was tested on. For driver fixes please mention the device (and if relevant firmware version) used for testing, or say that the change was not tested on real hardware.

Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include the relevant info in the cover letter or commit messages.

Signature · 2 lines
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.
maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Savvas Etairidis

Hi,

Quoted 20 lines · Savvas Etairidis

From: Savvas Etairidis <[email protected]>

The MAC soft reset in stmmac_init_dma_engine() stops the MDIO master. If an MDIO transaction is in flight at that moment, it is cut off in the middle of a frame. On a Realtek switch managed over MDIO (SMI), this was seen to store a value in the wrong register (0x00bb written to 0x08a2) or leave the switch not answering.

Take the MDIO bus lock around the reset with stmmac_mdio_lock(), as dwmac-dwc-qos-eth already does for its pad calibration, so that no transaction can be running while the reset happens. Every MDIO transaction holds this lock for the whole frame.

On two boards, forced MAC resets triggered the corruption within 250 resets without the lock. With the lock, 36000 forced resets caused none.

stmmac_init_dma_engine() is only called from __stmmac_open() and stmmac_resume(), neither of which holds the bus lock.

Quoted 7 lines

This patch was developed with the help of an AI coding assistant (Claude Code). It wrote the change and the changelog. I reviewed both and tested the fix on 6.6.162 hardware (36000 forced MAC resets with the lock, none failing).

Fixes 47dd7a540b8a ("net: add support for STMicroelectronics Ethernet controllers.")

I've browsed the docs, this seems to be indeed required.

I think this makes sense,

(out of curiosity, how did you hit that ? it seems fairly rare no ?)

Maxime

Quoted 19 lines
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +3 -0
index a685ce4638f6..1011e08f20c8 100644
@@ -3331,7 +3331,10 @@ static int stmmac_init_dma_engine(struct stmmac_priv *priv)
 	if (ret)
 		return ret;
 
+	/* The soft reset stops the MDIO master, so keep the bus idle. */
+	stmmac_mdio_lock(priv);
 	ret = stmmac_reset(priv);
+	stmmac_mdio_unlock(priv);
 	if (ret) {
 		netdev_err(priv->dev, "Failed to reset the dma\n");
 		return ret;
Reviewed-by on v1 1/1
#3 lore raw
In reply to Savvas Etairidis
Quoted 20 lines

From: Savvas Etairidis <[email protected]>

The MAC soft reset in stmmac_init_dma_engine() stops the MDIO master. If an MDIO transaction is in flight at that moment, it is cut off in the middle of a frame. On a Realtek switch managed over MDIO (SMI), this was seen to store a value in the wrong register (0x00bb written to 0x08a2) or leave the switch not answering.

Take the MDIO bus lock around the reset with stmmac_mdio_lock(), as dwmac-dwc-qos-eth already does for its pad calibration, so that no transaction can be running while the reset happens. Every MDIO transaction holds this lock for the whole frame.

On two boards, forced MAC resets triggered the corruption within 250 resets without the lock. With the lock, 36000 forced resets caused none.

stmmac_init_dma_engine() is only called from __stmmac_open() and stmmac_resume(), neither of which holds the bus lock.

Quoted 7 lines

This patch was developed with the help of an AI coding assistant (Claude Code). It wrote the change and the changelog. I reviewed both and tested the fix on 6.6.162 hardware (36000 forced MAC resets with the lock, none failing).

Fixes 47dd7a540b8a ("net: add support for STMicroelectronics Ethernet controllers.")
Quoted 23 lines
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +3 -0
index a685ce4638f6..1011e08f20c8 100644
@@ -3331,7 +3331,10 @@ static int stmmac_init_dma_engine(struct stmmac_priv *priv)
 	if (ret)
 		return ret;
 
+	/* The soft reset stops the MDIO master, so keep the bus idle. */
+	stmmac_mdio_lock(priv);
 	ret = stmmac_reset(priv);
+	stmmac_mdio_unlock(priv);
 	if (ret) {
 		netdev_err(priv->dev, "Failed to reset the dma\n");
 		return ret;
Signature · 1 line
2.56.1