diff mbox series

[1/1] net: stmmac: start PHY early in __stmmac_open

Message ID 20230316205449.1659395-1-shenwei.wang@nxp.com (mailing list archive)
State New, archived
Headers show
Series [1/1] net: stmmac: start PHY early in __stmmac_open | expand

Commit Message

Shenwei Wang March 16, 2023, 8:54 p.m. UTC
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")
Signed-off-by: Shenwei Wang <shenwei.wang@nxp.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Russell King (Oracle) March 16, 2023, 9:56 p.m. UTC | #1
On Thu, Mar 16, 2023 at 03:54:49PM -0500, Shenwei Wang wrote:
> 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.
Andrew Lunn March 17, 2023, 5:34 p.m. UTC | #2
> 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.

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
Russell King (Oracle) March 17, 2023, 5:38 p.m. UTC | #3
On Fri, Mar 17, 2023 at 06:34:13PM +0100, Andrew Lunn wrote:
> > 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.
> 
> 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! :) )
Florian Fainelli March 17, 2023, 5:47 p.m. UTC | #4
On 3/17/23 10:34, Andrew Lunn wrote:
>> 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.
> 
> 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?
Shenwei Wang March 20, 2023, 2:07 p.m. UTC | #5
> -----Original Message-----
> From: Russell King <linux@armlinux.org.uk>
> Sent: Thursday, March 16, 2023 4:56 PM
> To: Shenwei Wang <shenwei.wang@nxp.com>
> Cc: David S. Miller <davem@davemloft.net>; Eric Dumazet
> <edumazet@google.com>; Jakub Kicinski <kuba@kernel.org>; Paolo Abeni
> <pabeni@redhat.com>; Maxime Coquelin <mcoquelin.stm32@gmail.com>;
> Giuseppe Cavallaro <peppe.cavallaro@st.com>; Alexandre Torgue
> <alexandre.torgue@foss.st.com>; Jose Abreu <joabreu@synopsys.com>;
> netdev@vger.kernel.org; linux-stm32@st-md-mailman.stormreply.com; linux-
> arm-kernel@lists.infradead.org; imx@lists.linux.dev
> Subject: [EXT] Re: [PATCH 1/1] net: stmmac: start PHY early in __stmmac_open
> 
> Caution: EXT Email
> 
> On Thu, Mar 16, 2023 at 03:54:49PM -0500, Shenwei Wang wrote:
> > 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.
> 

Okay. Will fix the issue in another way.

Thanks,
Shenwei

> 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!
diff mbox series

Patch

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 8f543c3ab5c5..4feeca4d0503 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -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;