Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* Failed to reinit phy of spacemit-dwmac when reset-gpio is present
@ 2026-07-12  4:52 Inochi Amaoto
  2026-07-12  8:55 ` Maxime Chevallier
  0 siblings, 1 reply; 4+ messages in thread
From: Inochi Amaoto @ 2026-07-12  4:52 UTC (permalink / raw)
  To: Inochi Amaoto, Andrew Lunn, Eric Dumazet, David S. Miller,
	Jakub Kicinski, Paolo Abeni, Yixun Lan, Maxime Coquelin,
	Alexandre Torgue
  Cc: netdev, linux-riscv, spacemit, linux-stm32, linux-arm-kernel,
	linux-kernel, E Shattow, Han Gao

TL;DR:

The DWMAC on Spacemit K3 is failled to register phy after the reload
the driver module (rmmod then insmod). Because the reset-gpio is
asserted while unloading the driver and is not desserted before reading
the c22 id, which leads to a fault.

Description

In a few days ago, E Shattow reports he has sufferred the a weird issue,
when unloading the spacemit-dwmac driver and then reloading it, he got
the following error:

[   60.713071] mdio_bus stmmac-0: MDIO device at address 1 is missing.

This only occurs when reloading the driver but the first initialization
successed. After some function tracking, I found it is failed at reading
c22 id. The call graph is as the follows:

stmmac_mdio_register
	mdiobus_alloc
	of_mdiobus_register
		__of_mdiobus_register
		__mdiobus_register
		__of_mdiobus_parse_phys
			of_mdiobus_child_is_phy
			of_mdiobus_register_phy
				fwnode_mdiobus_register_phy
					get_phy_device
						get_phy_c22_id

By checking the difference between the initialization process and the
reloading process, I found the reset gpio is asserted in the function
mdiobus_unregister(). And there is no any function desserted this reset
gpio in the loading stage. And in the initialization process, the reset
goio is deasserted.

This bug report is sent as I found it is hard to solve this problem
and ask for help to fix this issue as it is related to the framework
instead of a specific driver.

The possible workaround I found is as the following, just use the phy
id in the compatible string (Confirmed by dlan):
---
--- a/arch/riscv/boot/dts/spacemit/k3-pico-itx.dts
+++ b/arch/riscv/boot/dts/spacemit/k3-pico-itx.dts
@@ -196,7 +196,8 @@ &eth0 {

 	mdio {
 		phy0: phy@1 {
-			compatible = "ethernet-phy-ieee802.3-c22";
+			compatible = "ethernet-phy-id001c.c916",
+				     "ethernet-phy-ieee802.3-c22";
 			reg = <1>;
 			reset-gpios = <&gpio 0 15 GPIO_ACTIVE_LOW>;
 			reset-assert-us = <10000>;
---
An interesting thing is, moving the reset-gpio to the MDIO bus level
does not solve this problem. Only setting the right phy id can mitigate
the problem.

Regards,
Inochi


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

* Re: Failed to reinit phy of spacemit-dwmac when reset-gpio is present
  2026-07-12  4:52 Failed to reinit phy of spacemit-dwmac when reset-gpio is present Inochi Amaoto
@ 2026-07-12  8:55 ` Maxime Chevallier
  2026-07-12 13:49   ` Andrew Lunn
  0 siblings, 1 reply; 4+ messages in thread
From: Maxime Chevallier @ 2026-07-12  8:55 UTC (permalink / raw)
  To: Inochi Amaoto, Andrew Lunn, Eric Dumazet, David S. Miller,
	Jakub Kicinski, Paolo Abeni, Yixun Lan, Maxime Coquelin,
	Alexandre Torgue
  Cc: netdev, linux-riscv, spacemit, linux-stm32, linux-arm-kernel,
	linux-kernel, E Shattow, Han Gao

Hi Inochi,

On 7/12/26 06:52, Inochi Amaoto wrote:
> TL;DR:
> 
> The DWMAC on Spacemit K3 is failled to register phy after the reload
> the driver module (rmmod then insmod). Because the reset-gpio is
> asserted while unloading the driver and is not desserted before reading
> the c22 id, which leads to a fault.

You're not the first one facing this type of issues, this is a long standing
source of issues. The problem is partially hidden by the fact that often times
the bootloader deals with the PHY reset (like the case you're facing)

Take a look at these discussions :

https://lore.kernel.org/netdev/cover.1761732347.git.buday.csaba@prolan.hu/

and maybe more intersting, Russell suggested an approach on how we could potentially
address this here :

https://lore.kernel.org/all/aTBeVTlsElGXUCSN@shell.armlinux.org.uk/


> ---
> --- a/arch/riscv/boot/dts/spacemit/k3-pico-itx.dts
> +++ b/arch/riscv/boot/dts/spacemit/k3-pico-itx.dts
> @@ -196,7 +196,8 @@ &eth0 {
> 
>  	mdio {
>  		phy0: phy@1 {
> -			compatible = "ethernet-phy-ieee802.3-c22";
> +			compatible = "ethernet-phy-id001c.c916",
> +				     "ethernet-phy-ieee802.3-c22";

Indeed that's merely a workaround :(

Maxime


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

* Re: Failed to reinit phy of spacemit-dwmac when reset-gpio is present
  2026-07-12  8:55 ` Maxime Chevallier
@ 2026-07-12 13:49   ` Andrew Lunn
  2026-07-12 14:49     ` E Shattow
  0 siblings, 1 reply; 4+ messages in thread
From: Andrew Lunn @ 2026-07-12 13:49 UTC (permalink / raw)
  To: Maxime Chevallier
  Cc: Inochi Amaoto, Andrew Lunn, Eric Dumazet, David S. Miller,
	Jakub Kicinski, Paolo Abeni, Yixun Lan, Maxime Coquelin,
	Alexandre Torgue, netdev, linux-riscv, spacemit, linux-stm32,
	linux-arm-kernel, linux-kernel, E Shattow, Han Gao

> > --- a/arch/riscv/boot/dts/spacemit/k3-pico-itx.dts
> > +++ b/arch/riscv/boot/dts/spacemit/k3-pico-itx.dts
> > @@ -196,7 +196,8 @@ &eth0 {
> > 
> >  	mdio {
> >  		phy0: phy@1 {
> > -			compatible = "ethernet-phy-ieee802.3-c22";
> > +			compatible = "ethernet-phy-id001c.c916",
> > +				     "ethernet-phy-ieee802.3-c22";
> 
> Indeed that's merely a workaround :(

Despite is being a workaround, there has not been much progress on a
generic framework for dealing with clocks, resets, regulators etc,
before probing PHYs. So this is probably what you want to do.

       Andrew


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

* Re: Failed to reinit phy of spacemit-dwmac when reset-gpio is present
  2026-07-12 13:49   ` Andrew Lunn
@ 2026-07-12 14:49     ` E Shattow
  0 siblings, 0 replies; 4+ messages in thread
From: E Shattow @ 2026-07-12 14:49 UTC (permalink / raw)
  To: Andrew Lunn, Maxime Chevallier
  Cc: Inochi Amaoto, Andrew Lunn, Eric Dumazet, David S. Miller,
	Jakub Kicinski, Paolo Abeni, Yixun Lan, Maxime Coquelin,
	Alexandre Torgue, netdev, linux-riscv, spacemit, linux-stm32,
	linux-arm-kernel, linux-kernel, Han Gao


On 7/12/26 06:49, Andrew Lunn wrote:
>>> --- a/arch/riscv/boot/dts/spacemit/k3-pico-itx.dts
>>> +++ b/arch/riscv/boot/dts/spacemit/k3-pico-itx.dts
>>> @@ -196,7 +196,8 @@ &eth0 {
>>>
>>>  	mdio {
>>>  		phy0: phy@1 {
>>> -			compatible = "ethernet-phy-ieee802.3-c22";
>>> +			compatible = "ethernet-phy-id001c.c916",
>>> +				     "ethernet-phy-ieee802.3-c22";
>>
>> Indeed that's merely a workaround :(
> 
> Despite is being a workaround, there has not been much progress on a
> generic framework for dealing with clocks, resets, regulators etc,
> before probing PHYs. So this is probably what you want to do.
> 
>        Andrew

Aside for my participation in reporting and testing here, I confirm that
the above addition to 'compatible' node does not itself resolve what I
observed to be a problem for debian-installer, however it does itself
resolve the rmmod/modprobe cycling issue of the eventual installed
Debian system as I described and what I am quoted as having reported
from dmesg output.

So the other report of increasing de-assert from 10ms to 50ms is needed
for success of the debian-installer hwprobe detection, and this here
issue of adding to the 'compatible' is needed for success of
rmmod/modprobe cycling. In concert together both fixes resolve all of
the trouble I observed and reported, tested and verified on Sipeed K3
Pico ITX.

Thanks for tracking this down it is very much appreciated :)

With that,

Tested-by: E Shattow <e@freeshell.de>


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

end of thread, other threads:[~2026-07-12 14:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-12  4:52 Failed to reinit phy of spacemit-dwmac when reset-gpio is present Inochi Amaoto
2026-07-12  8:55 ` Maxime Chevallier
2026-07-12 13:49   ` Andrew Lunn
2026-07-12 14:49     ` E Shattow

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox