From: Philippe Schenker <hidden> Date: 2021-12-14 12:16:58
We do have a hardware design in which the ethernet phy regulator and
reset are controlled by software. The ethernet PHY is a Microchip
KSZ9131 [1] and the power sequencing requires a reset after the power
goes up.
In our case the ethernet PHY is connected to a Freescale FEC and the
driver is shutting down the regulator on suspend, however on the resume
path the reset signal is never asserted and because of that the
ethernet is not working anymore.
To solve this adds a new phy_reset_after_power_on() function, similar
to the existing phy_reset_after_clk_enable(), and call it in the fec
resume path after the regulator is switched on as suggested by
Joakim Zhang [off-list ref].
[1] https://ww1.microchip.com/downloads/en/DeviceDoc/00002841C.pdf
Philippe Schenker (3):
net: phy: add phy_reset_after_power_on() function
net: phy: micrel: add reset-after-power-on flag to ksz9x31 phys
net: fec: reset phy on resume after power-up
drivers/net/ethernet/freescale/fec_main.c | 1 +
drivers/net/phy/micrel.c | 2 ++
drivers/net/phy/phy_device.c | 24 +++++++++++++++++++++++
include/linux/phy.h | 2 ++
4 files changed, 29 insertions(+)
--
2.34.1
From: Philippe Schenker <hidden> Date: 2021-12-14 12:17:03
Some PHY requires a reset after being powered on (e.g. KSZ9131), add a
new function and related PHY_RST_AFTER_POWER_ON phy flag to be called
after the PHY regulator is enabled.
Signed-off-by: Philippe Schenker <redacted>
---
drivers/net/phy/phy_device.c | 24 ++++++++++++++++++++++++
include/linux/phy.h | 2 ++
2 files changed, 26 insertions(+)
@@ -1878,6 +1878,30 @@ int phy_reset_after_clk_enable(struct phy_device *phydev)}EXPORT_SYMBOL(phy_reset_after_clk_enable);+/**+*phy_reset_after_power_on-performaPHYresetifneeded+*@phydev:targetphy_devicestruct+*+*Description:SomePHYsorhardwaredesign,needaresetafterpowerwas+*enabledandrelyonthatsoftwarereset.Thisfunctionevaluatestheflags+*andperformtheresetifit'sneeded.+*Returns<0onerror,0ifthephywasn'tresetand1ifthephywasreset.+*/+intphy_reset_after_power_on(structphy_device*phydev)+{+if(!phydev||!phydev->drv)+return-ENODEV;++if(phydev->drv->flags&PHY_RST_AFTER_POWER_ON){+phy_device_reset(phydev,1);+phy_device_reset(phydev,0);+return1;+}++return0;+}+EXPORT_SYMBOL(phy_reset_after_power_on);+/* Generic PHY support and helper functions *//**
From: Philippe Schenker <hidden> Date: 2021-12-14 12:17:05
KSZ9031 and KSZ9131 do need a reset after power-on, set the
PHY_RST_AFTER_POWER_ON flag to enable the phylib to do it in case the
reset signal is controlled by software.
Signed-off-by: Philippe Schenker <redacted>
---
drivers/net/phy/micrel.c | 2 ++
1 file changed, 2 insertions(+)
From: Philippe Schenker <hidden> Date: 2021-12-14 12:17:06
Reset the eth PHY after resume in case the power was switched off
during suspend, this is required by some PHYs if the reset signal
is controlled by software.
Signed-off-by: Philippe Schenker <redacted>
---
drivers/net/ethernet/freescale/fec_main.c | 1 +
1 file changed, 1 insertion(+)
From: Francesco Dolcini <hidden> Date: 2021-12-14 12:24:08
On Tue, Dec 14, 2021 at 01:16:35PM +0100, Philippe Schenker wrote:
We do have a hardware design in which the ethernet phy regulator and
reset are controlled by software. The ethernet PHY is a Microchip
KSZ9131 [1] and the power sequencing requires a reset after the power
goes up.
In our case the ethernet PHY is connected to a Freescale FEC and the
driver is shutting down the regulator on suspend, however on the resume
path the reset signal is never asserted and because of that the
ethernet is not working anymore.
To solve this adds a new phy_reset_after_power_on() function, similar
to the existing phy_reset_after_clk_enable(), and call it in the fec
resume path after the regulator is switched on as suggested by
Joakim Zhang [off-list ref].
[1] https://ww1.microchip.com/downloads/en/DeviceDoc/00002841C.pdf
For the whole series.
Reviewed-by: Francesco Dolcini <redacted>
From: Andrew Lunn <andrew@lunn.ch> Date: 2021-12-14 18:55:13
On Tue, Dec 14, 2021 at 01:16:38PM +0100, Philippe Schenker wrote:
Reset the eth PHY after resume in case the power was switched off
during suspend, this is required by some PHYs if the reset signal
is controlled by software.
Signed-off-by: Philippe Schenker <redacted>
---
drivers/net/ethernet/freescale/fec_main.c | 1 +
Hi Philippe
What i don't particularly like about this is that the MAC driver is
doing it. Meaning if this PHY is used with any other MAC, the same
code needs adding there.
Is there a way we can put this into phylib? Maybe as part of
phy_init_hw()? Humm, actually, thinking aloud:
int phy_init_hw(struct phy_device *phydev)
{
int ret = 0;
/* Deassert the reset signal */
phy_device_reset(phydev, 0);
So maybe in the phy driver, add a suspend handler, which asserts the
reset. This call here will take it out of reset, so applying the reset
you need?
Andrew
From: "Russell King (Oracle)" <linux@armlinux.org.uk> Date: 2021-12-14 19:09:17
On Tue, Dec 14, 2021 at 07:54:54PM +0100, Andrew Lunn wrote:
On Tue, Dec 14, 2021 at 01:16:38PM +0100, Philippe Schenker wrote:
quoted
Reset the eth PHY after resume in case the power was switched off
during suspend, this is required by some PHYs if the reset signal
is controlled by software.
Signed-off-by: Philippe Schenker <redacted>
---
drivers/net/ethernet/freescale/fec_main.c | 1 +
Hi Philippe
What i don't particularly like about this is that the MAC driver is
doing it. Meaning if this PHY is used with any other MAC, the same
code needs adding there.
Is there a way we can put this into phylib? Maybe as part of
phy_init_hw()? Humm, actually, thinking aloud:
int phy_init_hw(struct phy_device *phydev)
{
int ret = 0;
/* Deassert the reset signal */
phy_device_reset(phydev, 0);
So maybe in the phy driver, add a suspend handler, which asserts the
reset. This call here will take it out of reset, so applying the reset
you need?
It seems to be a combination issue - it's the fact that the power is
turned off and the fact that the reset needs to be applied.
If other PHYs such as AR8035 are subjected to this, they appear to
have a requirement that reset is asserted when power is applied and
kept asserted until the clock has stabilised and a certain time has
elapsed.
As I've already highlighted, we do not want to be asserting the reset
signal in phy_init_hw() - doing so would mean that any PHY with a GPIO
reset gets reset whenever the PHY is connected to the MAC - which can
be whenever the interface is brought up. That will introduce a multi-
second delay to bringing up the network.
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
From: Francesco Dolcini <hidden> Date: 2021-12-14 22:35:54
Hello Andrew,
On Tue, Dec 14, 2021 at 07:54:54PM +0100, Andrew Lunn wrote:
What i don't particularly like about this is that the MAC driver is
doing it. Meaning if this PHY is used with any other MAC, the same
code needs adding there.
This is exactly the same case as phy_reset_after_clk_enable() [1][2], to
me it does not look that bad.
So maybe in the phy driver, add a suspend handler, which asserts the
reset. This call here will take it out of reset, so applying the reset
you need?
Asserting the reset in the phylib in suspend path is a bad idea, in the
general case in which the PHY is powered in suspend the
power-consumption is likely to be higher if the device is in reset
compared to software power-down using the BMCR register (at least for
the PHY datasheet I checked).
What we could do is to call phy_device_reset in the fec driver suspend
path when we know we are going to disable the regulator, I do not like
it, but it would solve the issue.
@@ -4064,7 +4064,11 @@ static int __maybe_unused fec_suspend(struct device *dev)rtnl_unlock();if(fep->reg_phy&&!(fep->wol_flag&FEC_WOL_FLAG_ENABLE))+{regulator_disable(fep->reg_phy);+phy_device_reset(ndev->phydev,1);+}+/* SOC supply clock to phy, when clock is disabled, phy link down*SOCcontrolphyregulator,whenregulatorisdisabled,phylinkdown
From: Andrew Lunn <andrew@lunn.ch> Date: 2021-12-15 09:37:04
On Tue, Dec 14, 2021 at 11:35:48PM +0100, Francesco Dolcini wrote:
Hello Andrew,
On Tue, Dec 14, 2021 at 07:54:54PM +0100, Andrew Lunn wrote:
quoted
What i don't particularly like about this is that the MAC driver is
doing it. Meaning if this PHY is used with any other MAC, the same
code needs adding there.
This is exactly the same case as phy_reset_after_clk_enable() [1][2], to
me it does not look that bad.
quoted
So maybe in the phy driver, add a suspend handler, which asserts the
reset. This call here will take it out of reset, so applying the reset
you need?
Asserting the reset in the phylib in suspend path is a bad idea, in the
general case in which the PHY is powered in suspend the
power-consumption is likely to be higher if the device is in reset
compared to software power-down using the BMCR register (at least for
the PHY datasheet I checked).
Maybe i don't understand your hardware.
You have a regulator providing power of the PHY.
You have a reset, i guess a GPIO, connected to the reset pin of the
PHY.
What you could do is:
PHY driver suspend handler does a phy_device_reset(ndev->phydev, 1)
to put the PHY into reset.
MAC driver disables the regulator.
Power consumption should now be 0, since it does not have any power.
On resume, the MAC enables the regulator. At this point, the PHY gets
power, but is still held in reset. It is now consuming power, but not
doing anything. The MAC calls phy_hw_init(), which calls
phy_device_reset(ndev->phydev, 0), taking the PHY out of reset.
Hopefully, this release from reset is enough to make the PHY work.
Doing it like this also addresses Russell point. phy_hw_init() is not
putting the device into reset, it is only taking it out of reset, if
it happens to be already in reset. So we are not slowing down link up
for everybody.
Andrew
-----Original Message-----
From: Francesco Dolcini <redacted>
Sent: 2021年12月15日 6:36
To: Andrew Lunn <andrew@lunn.ch>
Cc: Philippe Schenker <redacted>;
netdev@vger.kernel.org; Joakim Zhang [off-list ref]; David
S . Miller [off-list ref]; Russell King [off-list ref];
Heiner Kallweit [off-list ref]; Francesco Dolcini
[off-list ref]; Jakub Kicinski [off-list ref]; Fabio
Estevam [off-list ref]; Fugang Duan [off-list ref];
linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next 3/3] net: fec: reset phy on resume after
power-up
Hello Andrew,
On Tue, Dec 14, 2021 at 07:54:54PM +0100, Andrew Lunn wrote:
quoted
What i don't particularly like about this is that the MAC driver is
doing it. Meaning if this PHY is used with any other MAC, the same
code needs adding there.
This is exactly the same case as phy_reset_after_clk_enable() [1][2], to me it
does not look that bad.
quoted
So maybe in the phy driver, add a suspend handler, which asserts the
reset. This call here will take it out of reset, so applying the reset
you need?
Asserting the reset in the phylib in suspend path is a bad idea, in the general
case in which the PHY is powered in suspend the power-consumption is likely
to be higher if the device is in reset compared to software power-down using
the BMCR register (at least for the PHY datasheet I checked).
What we could do is to call phy_device_reset in the fec driver suspend path
when we know we are going to disable the regulator, I do not like it, but it
would solve the issue.
@@ -4064,7 +4064,11 @@ static int __maybe_unused fec_suspend(struct
device *dev)
rtnl_unlock();
if (fep->reg_phy && !(fep->wol_flag & FEC_WOL_FLAG_ENABLE))
+ {
regulator_disable(fep->reg_phy);
+ phy_device_reset(ndev->phydev, 1);
+ }
+
/* SOC supply clock to phy, when clock is disabled, phy link down
* SOC control phy regulator, when regulator is disabled, phy link
down
As I mentioned before, both mac and phylib have not taken PHY reset into consideration during
system suspend/resume scenario. As Andrew suggested, you could move this into phy driver suspend
function, this is a corner case. One point I don't understand, why do you reject to assert reset signal during
system suspended?
Best Regards,
Joakim Zhang
From: "Russell King (Oracle)" <linux@armlinux.org.uk> Date: 2021-12-15 10:29:14
On Wed, Dec 15, 2021 at 10:36:52AM +0100, Andrew Lunn wrote:
On Tue, Dec 14, 2021 at 11:35:48PM +0100, Francesco Dolcini wrote:
quoted
Hello Andrew,
On Tue, Dec 14, 2021 at 07:54:54PM +0100, Andrew Lunn wrote:
quoted
What i don't particularly like about this is that the MAC driver is
doing it. Meaning if this PHY is used with any other MAC, the same
code needs adding there.
This is exactly the same case as phy_reset_after_clk_enable() [1][2], to
me it does not look that bad.
quoted
So maybe in the phy driver, add a suspend handler, which asserts the
reset. This call here will take it out of reset, so applying the reset
you need?
Asserting the reset in the phylib in suspend path is a bad idea, in the
general case in which the PHY is powered in suspend the
power-consumption is likely to be higher if the device is in reset
compared to software power-down using the BMCR register (at least for
the PHY datasheet I checked).
Maybe i don't understand your hardware.
You have a regulator providing power of the PHY.
You have a reset, i guess a GPIO, connected to the reset pin of the
PHY.
What you could do is:
PHY driver suspend handler does a phy_device_reset(ndev->phydev, 1)
to put the PHY into reset.
MAC driver disables the regulator.
Power consumption should now be 0, since it does not have any power.
On resume, the MAC enables the regulator. At this point, the PHY gets
power, but is still held in reset. It is now consuming power, but not
doing anything. The MAC calls phy_hw_init(), which calls
phy_device_reset(ndev->phydev, 0), taking the PHY out of reset.
Hopefully, this release from reset is enough to make the PHY work.
Doing it like this also addresses Russell point. phy_hw_init() is not
putting the device into reset, it is only taking it out of reset, if
it happens to be already in reset. So we are not slowing down link up
for everybody.
Here's another question which no one seems to have considered. If the
PHY power source can be controlled, why doesn't the firmware describe
the power supply for the PHY, and why doesn't the PHY driver control
the PHY power source? Why is that in the SoC network driver?
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!