linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] net: stmmac: start PHY early in __stmmac_open
@ 2023-03-16 20:54 Shenwei Wang
  2023-03-16 21:56 ` Russell King (Oracle)
  0 siblings, 1 reply; 6+ messages in thread
From: Shenwei Wang @ 2023-03-16 20:54 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Maxime Coquelin, Russell King
  Cc: Giuseppe Cavallaro, Alexandre Torgue, Jose Abreu, netdev,
	linux-stm32, linux-arm-kernel, imx, 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.

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(-)

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;
-- 
2.34.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] net: stmmac: start PHY early in __stmmac_open
  2023-03-16 20:54 [PATCH 1/1] net: stmmac: start PHY early in __stmmac_open Shenwei Wang
@ 2023-03-16 21:56 ` Russell King (Oracle)
  2023-03-17 17:34   ` Andrew Lunn
  2023-03-20 14:07   ` [EXT] " Shenwei Wang
  0 siblings, 2 replies; 6+ messages in thread
From: Russell King (Oracle) @ 2023-03-16 21:56 UTC (permalink / raw)
  To: Shenwei Wang
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Maxime Coquelin, Giuseppe Cavallaro, Alexandre Torgue,
	Jose Abreu, netdev, linux-stm32, linux-arm-kernel, imx

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.

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] net: stmmac: start PHY early in __stmmac_open
  2023-03-16 21:56 ` Russell King (Oracle)
@ 2023-03-17 17:34   ` Andrew Lunn
  2023-03-17 17:38     ` Russell King (Oracle)
  2023-03-17 17:47     ` Florian Fainelli
  2023-03-20 14:07   ` [EXT] " Shenwei Wang
  1 sibling, 2 replies; 6+ messages in thread
From: Andrew Lunn @ 2023-03-17 17:34 UTC (permalink / raw)
  To: Russell King (Oracle)
  Cc: Shenwei Wang, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Maxime Coquelin, Giuseppe Cavallaro,
	Alexandre Torgue, Jose Abreu, netdev, linux-stm32,
	linux-arm-kernel, imx

> 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

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] net: stmmac: start PHY early in __stmmac_open
  2023-03-17 17:34   ` Andrew Lunn
@ 2023-03-17 17:38     ` Russell King (Oracle)
  2023-03-17 17:47     ` Florian Fainelli
  1 sibling, 0 replies; 6+ messages in thread
From: Russell King (Oracle) @ 2023-03-17 17:38 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: Shenwei Wang, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Maxime Coquelin, Giuseppe Cavallaro,
	Alexandre Torgue, Jose Abreu, netdev, linux-stm32,
	linux-arm-kernel, imx

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! :) )

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] net: stmmac: start PHY early in __stmmac_open
  2023-03-17 17:34   ` Andrew Lunn
  2023-03-17 17:38     ` Russell King (Oracle)
@ 2023-03-17 17:47     ` Florian Fainelli
  1 sibling, 0 replies; 6+ messages in thread
From: Florian Fainelli @ 2023-03-17 17:47 UTC (permalink / raw)
  To: Andrew Lunn, Russell King (Oracle)
  Cc: Shenwei Wang, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Maxime Coquelin, Giuseppe Cavallaro,
	Alexandre Torgue, Jose Abreu, netdev, linux-stm32,
	linux-arm-kernel, imx

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?
-- 
Florian


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: [EXT] Re: [PATCH 1/1] net: stmmac: start PHY early in __stmmac_open
  2023-03-16 21:56 ` Russell King (Oracle)
  2023-03-17 17:34   ` Andrew Lunn
@ 2023-03-20 14:07   ` Shenwei Wang
  1 sibling, 0 replies; 6+ messages in thread
From: Shenwei Wang @ 2023-03-20 14:07 UTC (permalink / raw)
  To: Russell King
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Maxime Coquelin, Giuseppe Cavallaro, Alexandre Torgue,
	Jose Abreu, netdev, linux-stm32, linux-arm-kernel, imx



> -----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!

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-03-20 14:08 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-16 20:54 [PATCH 1/1] net: stmmac: start PHY early in __stmmac_open Shenwei Wang
2023-03-16 21:56 ` Russell King (Oracle)
2023-03-17 17:34   ` Andrew Lunn
2023-03-17 17:38     ` Russell King (Oracle)
2023-03-17 17:47     ` Florian Fainelli
2023-03-20 14:07   ` [EXT] " Shenwei Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).