Skip to contentSkip to conversation

net: stmmac: start PHY early in __stmmac_open

PATCH In review Shenwei Wang 4 participants 6 messages Mar 16, 2023 – Mar 20, 2023

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

PATCH 1/1 net: stmmac: start PHY early in __stmmac_open

By initializing the PHY and establishing the link before setting the MAC relating configurations, this change ensures that the PHY is operational before the MAC logic starts relying on it. This can prevent synchronization errors and improve system stability.

This change especially applies to the RMII mode, where the PHY may drive the REF_CLK signal, which requires the PHY to be started and operational before the MAC logic initializes.

This change should not impact other modes of operation.

Fixes 74371272f97f ("net: stmmac: Convert to phylink and remove phylib logic")
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +4 -4
index 8f543c3ab5c5..4feeca4d0503 100644
@@ -3808,6 +3808,10 @@ static int __stmmac_open(struct net_device *dev,
 		}
 	}
 
+	phylink_start(priv->phylink);
+	/* We may have called phylink_speed_down before */
+	phylink_speed_up(priv->phylink);
+
 	/* Extra statistics */
 	memset(&priv->xstats, 0, sizeof(struct stmmac_extra_stats));
 	priv->xstats.threshold = tc;
@@ -3836,10 +3840,6 @@ static int __stmmac_open(struct net_device *dev,
 
 	stmmac_init_coalesce(priv);
 
-	phylink_start(priv->phylink);
-	/* We may have called phylink_speed_down before */
-	phylink_speed_up(priv->phylink);
-
 	ret = stmmac_request_irq(dev);
 	if (ret)
 		goto irq_error;
Signature · 1 line
2.34.1
#1 lore raw
Quoted 10 lines · Shenwei Wang

By initializing the PHY and establishing the link before setting the MAC relating configurations, this change ensures that the PHY is operational before the MAC logic starts relying on it. This can prevent synchronization errors and improve system stability.

This change especially applies to the RMII mode, where the PHY may drive the REF_CLK signal, which requires the PHY to be started and operational before the MAC logic initializes.

This change should not impact other modes of operation.

NAK. A patch similar to this has already been sent.

The problem with just moving this is that phylink can call the mac_link_up() method *before* phylink_start() has returned - and as this driver has not completed the setup, it doesn't expect the link to come up at that point.

There are several issues with this driver wanting the PHY clock early, and there have been two people working on addressing this previously, proposing two different changes to phylink.

I sent them away to talk to each other and come back with a unified solution. Shock horror, they never came back.

Now we seem to be starting again from the beginning.

stmmac folk really need to get a handle on this so reviewers are not having to NAK similar patches time and time again, resulting in the problem not being solved.

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
#2 lore raw
Quoted 11 lines

NAK. A patch similar to this has already been sent.

The problem with just moving this is that phylink can call the mac_link_up() method *before* phylink_start() has returned - and as this driver has not completed the setup, it doesn't expect the link to come up at that point.

There are several issues with this driver wanting the PHY clock early, and there have been two people working on addressing this previously, proposing two different changes to phylink.

Quoted 8 lines

I sent them away to talk to each other and come back with a unified solution. Shock horror, they never came back.

Now we seem to be starting again from the beginning.

stmmac folk really need to get a handle on this so reviewers are not having to NAK similar patches time and time again, resulting in the problem not being solved.

And just adding to that, Developers should also get into the habit of searching to see if somebody has already tried and failed to solve the problem.

“Those Who Do Not Learn History Are Doomed To Repeat It.”

Try avoiding wasting everybody's times by learning a bit of history.

Andrew

#3 lore raw
Quoted 20 lines · Andrew Lunn
Quoted 11 lines

NAK. A patch similar to this has already been sent.

The problem with just moving this is that phylink can call the mac_link_up() method *before* phylink_start() has returned - and as this driver has not completed the setup, it doesn't expect the link to come up at that point.

There are several issues with this driver wanting the PHY clock early, and there have been two people working on addressing this previously, proposing two different changes to phylink.

Quoted 8 lines

I sent them away to talk to each other and come back with a unified solution. Shock horror, they never came back.

Now we seem to be starting again from the beginning.

stmmac folk really need to get a handle on this so reviewers are not having to NAK similar patches time and time again, resulting in the problem not being solved.

Quoted 7 lines

And just adding to that, Developers should also get into the habit of searching to see if somebody has already tried and failed to solve the problem.

“Those Who Do Not Learn History Are Doomed To Repeat It.”

Try avoiding wasting everybody's times by learning a bit of history.

+1,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000!

(Yes, factorial too! :) )

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
#4 lore raw
In reply to Andrew Lunn
Quoted 20 lines · Andrew Lunn
Quoted 11 lines

NAK. A patch similar to this has already been sent.

The problem with just moving this is that phylink can call the mac_link_up() method *before* phylink_start() has returned - and as this driver has not completed the setup, it doesn't expect the link to come up at that point.

There are several issues with this driver wanting the PHY clock early, and there have been two people working on addressing this previously, proposing two different changes to phylink.

Quoted 8 lines

I sent them away to talk to each other and come back with a unified solution. Shock horror, they never came back.

Now we seem to be starting again from the beginning.

stmmac folk really need to get a handle on this so reviewers are not having to NAK similar patches time and time again, resulting in the problem not being solved.

Quoted 7 lines

And just adding to that, Developers should also get into the habit of searching to see if somebody has already tried and failed to solve the problem.

“Those Who Do Not Learn History Are Doomed To Repeat It.”

Try avoiding wasting everybody's times by learning a bit of history.

This is a tough problem to solve though, we have had similar issues in the past with the GENET driver whereby we need the PHY clock in order to clock certain parts of the MAC's receive path to ensure it completes its reset. This is a terrible design that unfortunately a lot of designers get wrong.

Eventually we found that we had this "auto-configure" feature which could kick in when the PHY is up and running which solved it:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=88f6c8bf1aaed5039923fb4c701cab4d42176275

though it took a few attempts to get there:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=612eb1c3b9e504de24136c947ed7c07bc342f3aa

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=3a55402c93877d291b0a612d25edb03d1b4b93ac

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=28c2d1a7a0bf

Does something similar exit on stmmac? Can you somehow utilize the MAC's TX clock and loop it back to the RX clock to satisfy any clocking requirements?

Signature · 1 line
Florian
#5 lore raw
In reply to Russell King (Oracle)
Quoted 27 lines

-----Original Message-----
From: Russell King <[email protected]>
Sent: Thursday, March 16, 2023 4:56 PM
To: Shenwei Wang <[email protected]>
Cc: David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; Maxime Coquelin <[email protected]>; Giuseppe Cavallaro <[email protected]>; Alexandre Torgue <[email protected]>; Jose Abreu <[email protected]>; [email protected]; [email protected]; linux- [email protected]; [email protected]
Subject: [EXT] Re: [PATCH 1/1] net: stmmac: start PHY early in __stmmac_open

Caution: EXT Email

Quoted 9 lines · Shenwei Wang

By initializing the PHY and establishing the link before setting the MAC relating configurations, this change ensures that the PHY is operational before the MAC logic starts relying on it. This can prevent synchronization errors and improve system stability.

This change especially applies to the RMII mode, where the PHY may drive the REF_CLK signal, which requires the PHY to be started and operational before the MAC logic initializes.

Quoted 8 lines
Quoted 1 line

This change should not impact other modes of operation.

NAK. A patch similar to this has already been sent.

The problem with just moving this is that phylink can call the mac_link_up() method *before* phylink_start() has returned - and as this driver has not completed the setup, it doesn't expect the link to come up at that point.

Okay. Will fix the issue in another way.

Thanks,
Shenwei

Quoted 23 lines

There are several issues with this driver wanting the PHY clock early, and there have been two people working on addressing this previously, proposing two different changes to phylink.

I sent them away to talk to each other and come back with a unified solution. Shock horror, they never came back.

Now we seem to be starting again from the beginning.

stmmac folk really need to get a handle on this so reviewers are not having to NAK similar patches time and time again, resulting in the problem not being solved.

--
RMK's Patch system:
https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.ar
mlinux.org.uk%2Fdeveloper%2Fpatches%2F&data=05%7C01%7Cshenwei.wang %40nxp.com%7C23424b2776544630dbcc08db2669469c%7C686ea1d3bc2b4c6f a92cd99c5c301635%7C0%7C0%7C638146005820038948%7CUnknown%7CTWF pbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6 Mn0%3D%7C3000%7C%7C%7C&sdata=yLeW5tBxRpYK%2B%2FjbwaFqigzjWHRq m89FAE3Z%2BlVM4s0%3D&reserved=0
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!