Skip to contentSkip to conversation

net: ethernet: fec: Prevent MII event after MII_SPEED write

PATCH Applied Andrew Lunn 3 participants 10 messages Apr 28, 2020 – Apr 29, 2020

Subsystems (3)

v1 of 2 Applied Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: ethernet: fec: Prevent MII event after MII_SPEED write

The change to polled IO for MDIO completion assumes that MII events are only generated for MDIO transactions. However on some SoCs writing to the MII_SPEED register can also trigger an MII event. As a result, the next MDIO read has a pending MII event, and immediately reads the data registers before it contains useful data. When the read does complete, another MII event is posted, which results in the next read also going wrong, and the cycle continues.

By writing 0 to the MII_DATA register before writing to the speed register, this MII event for the MII_SPEED is suppressed, and polled IO works as expected.

Fixes 29ae6bd1b0d8 ("net: ethernet: fec: Replace interrupt driven MDIO with polled IO")
---
 drivers/net/ethernet/freescale/fec_main.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/net/ethernet/freescale/fec_main.c +17 -0
index 1ae075a246a3..aa5e744ec098 100644
@@ -996,6 +996,9 @@ fec_restart(struct net_device *ndev)
 		writel(0x0, fep->hwp + FEC_X_CNTRL);
 	}
 
+	/* Prevent an MII event being report when changing speed */
+	writel(0, fep->hwp + FEC_MII_DATA);
+
 	/* Set MII speed */
 	writel(fep->phy_speed, fep->hwp + FEC_MII_SPEED);
 
@@ -1182,6 +1185,10 @@ fec_stop(struct net_device *ndev)
 		writel(val, fep->hwp + FEC_ECNTRL);
 		fec_enet_stop_mode(fep, true);
 	}
+
+	/* Prevent an MII event being report when changing speed */
+	writel(0, fep->hwp + FEC_MII_DATA);
+
 	writel(fep->phy_speed, fep->hwp + FEC_MII_SPEED);
 
 	/* We have to keep ENET enabled to have MII interrupt stay working */
@@ -2142,6 +2149,16 @@ static int fec_enet_mii_init(struct platform_device *pdev)
 	if (suppress_preamble)
 		fep->phy_speed |= BIT(7);
 
+	/* Clear MMFR to avoid to generate MII event by writing MSCR.
+	 * MII event generation condition:
+	 * - writing MSCR:
+	 *	- mmfr[31:0]_not_zero & mscr[7:0]_is_zero &
+	 *	  mscr_reg_data_in[7:0] != 0
+	 * - writing MMFR:
+	 *	- mscr[7:0]_not_zero
+	 */
+	writel(0, fep->hwp + FEC_MII_DATA);
+
 	writel(fep->phy_speed, fep->hwp + FEC_MII_SPEED);
 
 	/* Clear any pending transaction complete indication */
Signature · 1 line
2.26.1
#1 lore raw
Quoted 11 lines · Andrew Lunn

The change to polled IO for MDIO completion assumes that MII events are only generated for MDIO transactions. However on some SoCs writing to the MII_SPEED register can also trigger an MII event. As a result, the next MDIO read has a pending MII event, and immediately reads the data registers before it contains useful data. When the read does complete, another MII event is posted, which results in the next read also going wrong, and the cycle continues.

By writing 0 to the MII_DATA register before writing to the speed register, this MII event for the MII_SPEED is suppressed, and polled IO works as expected.

Hi Andy

Could you get your LAVA instances to test this? Or do we need to wait for it to make its way into net-next?

Thanks
Andrew

#2 lore raw

From: Andrew Lunn <[email protected]> Sent: Wednesday, April 29, 2020 2:02 AM

Quoted 13 lines · Andrew Lunn
Quoted 11 lines

The change to polled IO for MDIO completion assumes that MII events are only generated for MDIO transactions. However on some SoCs writing to the MII_SPEED register can also trigger an MII event. As a result, the next MDIO read has a pending MII event, and immediately reads the data registers before it contains useful data. When the read does complete, another MII event is posted, which results in the next read also going wrong, and the cycle continues.

By writing 0 to the MII_DATA register before writing to the speed register, this MII event for the MII_SPEED is suppressed, and polled IO works as expected.

Quoted 7 lines

Hi Andy

Could you get your LAVA instances to test this? Or do we need to wait for it to make its way into net-next?

Thanks
Andrew

Yes, we need to wait for linux next.

Andy

maintainer Applied
#3 lore raw
In reply to Andrew Lunn

From: Andrew Lunn <[email protected]>
Date: Tue, 28 Apr 2020 19:58:33 +0200

Quoted 8 lines

The change to polled IO for MDIO completion assumes that MII events are only generated for MDIO transactions. However on some SoCs writing to the MII_SPEED register can also trigger an MII event. As a result, the next MDIO read has a pending MII event, and immediately reads the data registers before it contains useful data. When the read does complete, another MII event is posted, which results in the next read also going wrong, and the cycle continues.

Quoted 8 lines

By writing 0 to the MII_DATA register before writing to the speed register, this MII event for the MII_SPEED is suppressed, and polled IO works as expected.

Fixes 29ae6bd1b0d8 ("net: ethernet: fec: Replace interrupt driven MDIO with polled IO")

Applied to net-next, thanks.

#4 lore raw

From: David Miller <[email protected]> Sent: Wednesday, April 29, 2020 5:34 AM

Quoted 15 lines

From: Andrew Lunn <[email protected]>
Date: Tue, 28 Apr 2020 19:58:33 +0200

Quoted 12 lines

The change to polled IO for MDIO completion assumes that MII events are only generated for MDIO transactions. However on some SoCs writing to the MII_SPEED register can also trigger an MII event. As a result, the next MDIO read has a pending MII event, and immediately reads the data registers before it contains useful data. When the read does complete, another MII event is posted, which results in the next read also going wrong, and the cycle continues.

By writing 0 to the MII_DATA register before writing to the speed register, this MII event for the MII_SPEED is suppressed, and polled IO works as expected.

Quoted 7 lines
Quoted 5 lines
Fixes 29ae6bd1b0d8 ("net: ethernet: fec: Replace interrupt driven

MDIO with polled IO")

Applied to net-next, thanks.

David, it is too early to apply the patch, it will introduce another break issue as I explain in previous mail for the patch.

maintainer
#5 lore raw

From: Andy Duan <[email protected]>
Date: Wed, 29 Apr 2020 01:55:35 +0000

Quoted 22 lines

From: David Miller <[email protected]> Sent: Wednesday, April 29, 2020 5:34 AM

Quoted 21 lines

From: Andrew Lunn <[email protected]>
Date: Tue, 28 Apr 2020 19:58:33 +0200

Quoted 17 lines

The change to polled IO for MDIO completion assumes that MII events are only generated for MDIO transactions. However on some SoCs writing to the MII_SPEED register can also trigger an MII event. As a result, the next MDIO read has a pending MII event, and immediately reads the data registers before it contains useful data. When the read does complete, another MII event is posted, which results in the next read also going wrong, and the cycle continues.

By writing 0 to the MII_DATA register before writing to the speed register, this MII event for the MII_SPEED is suppressed, and polled IO works as expected.

Fixes 29ae6bd1b0d8 ("net: ethernet: fec: Replace interrupt driven

MDIO with polled IO")

Quoted 4 lines
Quoted 1 line

Applied to net-next, thanks.

David, it is too early to apply the patch, it will introduce another break issue as I explain in previous mail for the patch.

So what should I do, revert?

#6 lore raw

From: David Miller <[email protected]> Sent: Wednesday, April 29, 2020 11:35 AM

Quoted 26 lines

From: Andy Duan <[email protected]>
Date: Wed, 29 Apr 2020 01:55:35 +0000

Quoted 23 lines

From: David Miller <[email protected]> Sent: Wednesday, April 29, 2020 5:34 AM

Quoted 21 lines

From: Andrew Lunn <[email protected]>
Date: Tue, 28 Apr 2020 19:58:33 +0200

Quoted 17 lines

The change to polled IO for MDIO completion assumes that MII events are only generated for MDIO transactions. However on some SoCs writing to the MII_SPEED register can also trigger an MII event. As a result, the next MDIO read has a pending MII event, and immediately reads the data registers before it contains useful data. When the read does complete, another MII event is posted, which results in the next read also going wrong, and the cycle continues.

By writing 0 to the MII_DATA register before writing to the speed register, this MII event for the MII_SPEED is suppressed, and polled IO works as expected.

Fixes 29ae6bd1b0d8 ("net: ethernet: fec: Replace interrupt driven

MDIO with polled IO")

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Applied to net-next, thanks.

David, it is too early to apply the patch, it will introduce another break issue as I explain in previous mail for the patch.

So what should I do, revert?

If you can revert the patch, please do it.
Thanks, David.

#7 lore raw
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Applied to net-next, thanks.

David, it is too early to apply the patch, it will introduce another break issue as I explain in previous mail for the patch.

So what should I do, revert?

If you can revert the patch, please do it.
Thanks, David.

Hi David

Please do revert. I will send a new version of the patch soon. Probably RFC this time!

Andrew

maintainer
#8 lore raw

From: Andrew Lunn <[email protected]>
Date: Wed, 29 Apr 2020 16:11:02 +0200

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Applied to net-next, thanks.

David, it is too early to apply the patch, it will introduce another break issue as I explain in previous mail for the patch.

So what should I do, revert?

Quoted 7 lines
Quoted 2 lines

If you can revert the patch, please do it.
Thanks, David.

Hi David

Please do revert. I will send a new version of the patch soon. Probably RFC this time!

Ok, done.

#9 lore raw
In reply to Andrew Lunn

From: Andrew Lunn <[email protected]> Sent: Wednesday, April 29, 2020 1:59 AM

Quoted 26 lines

The change to polled IO for MDIO completion assumes that MII events are only generated for MDIO transactions. However on some SoCs writing to the MII_SPEED register can also trigger an MII event. As a result, the next MDIO read has a pending MII event, and immediately reads the data registers before it contains useful data. When the read does complete, another MII event is posted, which results in the next read also going wrong, and the cycle continues.

By writing 0 to the MII_DATA register before writing to the speed register, this MII event for the MII_SPEED is suppressed, and polled IO works as expected.

Fixes 29ae6bd1b0d8 ("net: ethernet: fec: Replace interrupt driven MDIO with

polled IO")

---
 drivers/net/ethernet/freescale/fec_main.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/net/ethernet/freescale/fec_main.c +0 -0
index 1ae075a246a3..aa5e744ec098 100644

drivers/net/ethernet/freescale/fec_main.c fec_restart(struct net_device *ndev) · line 1001

Quoted 6 lines
drivers/net/ethernet/freescale/fec_main.c +3 -0
@@ -996,6 +996,9 @@ fec_restart(struct net_device *ndev)
                writel(0x0, fep->hwp + FEC_X_CNTRL);
        }
 
+       /* Prevent an MII event being report when changing speed */
+       writel(0, fep->hwp + FEC_MII_DATA);
+

Andrew, my suggestion is only add the change in .fec_enet_mii_init(). There have risk and may introduce MII event here when wirte value into FEC_MII_DATA register.

As I said, if FEC_MII_SPEED register[7:0] is not zero, MII event will be generated when write FEC_MII_DATA register.
* - writing MMFR:
* - mscr[7:0]_not_zero

drivers/net/ethernet/freescale/fec_main.c fec_stop(struct net_device *ndev) · line 1191

Quoted 11 lines
drivers/net/ethernet/freescale/fec_main.c +4 -0
        /* Set MII speed */
        writel(fep->phy_speed, fep->hwp + FEC_MII_SPEED);
 
@@ -1182,6 +1185,10 @@ fec_stop(struct net_device *ndev)
                writel(val, fep->hwp + FEC_ECNTRL);
                fec_enet_stop_mode(fep, true);
        }
+
+       /* Prevent an MII event being report when changing speed */
+       writel(0, fep->hwp + FEC_MII_DATA);
+

The same here.
We should not add the change here.

I already consider normal case, suspend/resume with power on case, Suspend/resume with power off (register value lost) case, only add the change in . fec_enet_mii_init() seems safe.
The patch "net: ethernet: fec: Prevent MII event after MII_SPEED write" brings some trouble here, we need to consider all cases when writing FEC_MII_DATA, FEC_MII_SPEED registers.

Again, please note writing the two registers may trigger MII event with Below logic:
* MII event generation condition:
* - writing MSCR:
* - mmfr[31:0]_not_zero & mscr[7:0]_is_zero &
* mscr_reg_data_in[7:0] != 0
* - writing MMFR:
* - mscr[7:0]_not_zero
*/

If interrupt mode, we don't take care this logic and dependency.

Quoted 23 lines
drivers/net/ethernet/freescale/fec_main.c +0 -0
        writel(fep->phy_speed, fep->hwp + FEC_MII_SPEED);
 
        /* We have to keep ENET enabled to have MII interrupt stay

working */ @@ -2142,6 +2149,16 @@ static int fec_enet_mii_init(struct platform_device *pdev)

        if (suppress_preamble)
                fep->phy_speed |= BIT(7);
drivers/net/ethernet/freescale/fec_main.c +10 -1
+       /* Clear MMFR to avoid to generate MII event by writing MSCR.
+        * MII event generation condition:
+        * - writing MSCR:
+        *      - mmfr[31:0]_not_zero & mscr[7:0]_is_zero &
+        *        mscr_reg_data_in[7:0] != 0
+        * - writing MMFR:
+        *      - mscr[7:0]_not_zero
+        */
+       writel(0, fep->hwp + FEC_MII_DATA);
+
        writel(fep->phy_speed, fep->hwp + FEC_MII_SPEED);
 
        /* Clear any pending transaction complete indication */
--

2.26.1