Skip to contentSkip to conversation

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

PATCH In review Andrew Lunn 3 participants 4 messages Apr 29, 2020 – May 1, 2020

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

PATCH v2 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.

v2 - Only infec_enet_mii_init()

Fixes 29ae6bd1b0d8 ("net: ethernet: fec: Replace interrupt driven MDIO with polled IO")
---
 drivers/net/ethernet/freescale/fec_main.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/net/ethernet/freescale/fec_main.c +10 -0
index 1ae075a246a3..2e209142f2d1 100644
@@ -2142,6 +2142,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
Acked-by on v2 1/1
#1 lore raw

From: Andrew Lunn <[email protected]> Sent: Thursday, April 30, 2020 4:53 AM

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

v2 - Only infec_enet_mii_init()

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

polled IO")

Quoted 29 lines
---
 drivers/net/ethernet/freescale/fec_main.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/net/ethernet/freescale/fec_main.c +10 -0
index 1ae075a246a3..2e209142f2d1 100644
@@ -2142,6 +2142,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 */

--
2.26.1

maintainer
#2 lore raw
In reply to Andrew Lunn

From: Andrew Lunn <[email protected]>
Date: Wed, 29 Apr 2020 22:53:23 +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 6 lines

v2 - Only infec_enet_mii_init()

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

Hmmm, I reverted the Fixes: tag patch so you'll need to respin this I think.

Thanks.

#3 lore raw
Quoted 15 lines · David Miller

From: Andrew Lunn <[email protected]>
Date: Wed, 29 Apr 2020 22:53:23 +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 8 lines
Quoted 6 lines

v2 - Only infec_enet_mii_init()

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

Hmmm, I reverted the Fixes: tag patch so you'll need to respin this I think.

Ah.

We wanted the fix reverting, but not that the fix was fixing. Sorry, we were unclear.

Andrew