diff mbox series

[net-next,3/3] net: fec: reset phy on resume after power-up

Message ID 20211214121638.138784-4-philippe.schenker@toradex.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series Add Possiblity to Reset PHY After Power-up | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 4 of 4 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 7 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Philippe Schenker Dec. 14, 2021, 12:16 p.m. UTC
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 <philippe.schenker@toradex.com>

---

 drivers/net/ethernet/freescale/fec_main.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Andrew Lunn Dec. 14, 2021, 6:54 p.m. UTC | #1
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 <philippe.schenker@toradex.com>
> 
> ---
> 
>  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
Russell King (Oracle) Dec. 14, 2021, 7:09 p.m. UTC | #2
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:
> > 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 <philippe.schenker@toradex.com>
> > 
> > ---
> > 
> >  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.
Francesco Dolcini Dec. 14, 2021, 10:35 p.m. UTC | #3
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.

--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -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

Francesco

[1] https://lore.kernel.org/netdev/20171211121700.10200-1-dev@g0hl1n.net/
[2] 1b0a83ac04e3 ("net: fec: add phy_reset_after_clk_enable() support")
Andrew Lunn Dec. 15, 2021, 9:36 a.m. UTC | #4
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:
> > 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).

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
Joakim Zhang Dec. 15, 2021, 10:25 a.m. UTC | #5
Hi Francesco,

> -----Original Message-----
> From: Francesco Dolcini <francesco.dolcini@toradex.com>
> Sent: 2021年12月15日 6:36
> To: Andrew Lunn <andrew@lunn.ch>
> Cc: Philippe Schenker <philippe.schenker@toradex.com>;
> netdev@vger.kernel.org; Joakim Zhang <qiangqing.zhang@nxp.com>; David
> S . Miller <davem@davemloft.net>; Russell King <linux@armlinux.org.uk>;
> Heiner Kallweit <hkallweit1@gmail.com>; Francesco Dolcini
> <francesco.dolcini@toradex.com>; Jakub Kicinski <kuba@kernel.org>; Fabio
> Estevam <festevam@gmail.com>; Fugang Duan <fugang.duan@nxp.com>;
> 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:
> > 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.
> 
> --- a/drivers/net/ethernet/freescale/fec_main.c
> +++ b/drivers/net/ethernet/freescale/fec_main.c
> @@ -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
> Francesco
> 
> [1]
> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.k
> ernel.org%2Fnetdev%2F20171211121700.10200-1-dev%40g0hl1n.net%2F&a
> mp;data=04%7C01%7Cqiangqing.zhang%40nxp.com%7Cf7140fe971544fe8d2
> 2608d9bf521517%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C6377
> 51181527979233%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiL
> CJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=itV
> m0jroQ0MzDG5Ipqs3OY0F5SY%2FkbdFRWauNKq2XiQ%3D&amp;reserved=0
> [2] 1b0a83ac04e3 ("net: fec: add phy_reset_after_clk_enable() support")
Russell King (Oracle) Dec. 15, 2021, 10:29 a.m. UTC | #6
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:
> > 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).
> 
> 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?
Francesco Dolcini Dec. 15, 2021, 11:10 a.m. UTC | #7
On Wed, Dec 15, 2021 at 12:01:39PM +0100, Francesco Dolcini wrote:
> Any agreement on how to move forward?
...
>  3. move regulator to phy/micrel.c and assert reset in the phy driver resume
>  callback
whoops, s/resume/suspend/
Andrew Lunn Dec. 15, 2021, 7:34 p.m. UTC | #8
> This is all correct and will solve the issue, however ...
> 
> The problem I see is that nor the phylib nor the PHY driver is aware
> that the PHY was powered down, if we unconditionally assert the reset in
> the suspend callback in the PHY driver/lib this will affect in a bad
> case the most common use case in which we keep the PHY powered in
> suspend.

We know if the PHY should be left up because of WoL. So that is not an
issue. We can also put the PHY into lower power mode, before making
the call to put the PHY into reset.  If the reset is not implemented,
the PHY stays in low power mode. If it is implemented, it is both in
lower power mode and held in reset. And if the regulator is provided,
the power will go off.

> The reason is that the power consumption in reset is higher in reset
> compared to the normal PHY software power down.

Does the datasheet have numbers for in lower power mode and held in
reset? We only have an issue if held in reset when in low power mode
consumes more power than simply in low power mode.

	Andrew
Francesco Dolcini Dec. 15, 2021, 7:48 p.m. UTC | #9
On Wed, Dec 15, 2021 at 08:34:00PM +0100, Andrew Lunn wrote:
> > The reason is that the power consumption in reset is higher in reset
> > compared to the normal PHY software power down.
> 
> Does the datasheet have numbers for in lower power mode and held in
> reset? We only have an issue if held in reset when in low power mode
> consumes more power than simply in low power mode.

The numbers for KSZ9131, Table 6-3: Power Consumption from datasheet [0]

61.2mW in reset, 24.4mW in software power down (3.3VDD)
40.9mW in reset, 12.5mW in software power down (2.5VDD)

Francesco

[0] https://ww1.microchip.com/downloads/en/DeviceDoc/00002841B.pdf
Joakim Zhang Dec. 16, 2021, 4:52 a.m. UTC | #10
> -----Original Message-----
> From: Francesco Dolcini <francesco.dolcini@toradex.com>
> Sent: 2021年12月15日 19:02
> To: Andrew Lunn <andrew@lunn.ch>; Russell King (Oracle)
> <linux@armlinux.org.uk>; Joakim Zhang <qiangqing.zhang@nxp.com>
> Cc: Russell King (Oracle) <linux@armlinux.org.uk>; Francesco Dolcini
> <francesco.dolcini@toradex.com>; Philippe Schenker
> <philippe.schenker@toradex.com>; netdev@vger.kernel.org; Joakim Zhang
> <qiangqing.zhang@nxp.com>; David S . Miller <davem@davemloft.net>;
> Heiner Kallweit <hkallweit1@gmail.com>; Jakub Kicinski <kuba@kernel.org>;
> Fabio Estevam <festevam@gmail.com>; linux-kernel@vger.kernel.org
> Subject: Re: [PATCH net-next 3/3] net: fec: reset phy on resume after
> power-up
> 
[...]

> On Wed, Dec 15, 2021 at 10:25:14AM +0000, Joakim Zhang wrote:
> > 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?
> See my answer to Andrew above, in short asserting the reset without
> disabling the regulator will create a regression on the power consumption.

As I can see, when system suspended, PHY is totally powered down, since you disable the 
regulator. At this situation, if you assert reset signal, you mean it will increase the power
consumption? PHY is totally powered down, why assert reset signal still affect PHY? 
 
Best Regards,
Joakim Zhang
Francesco Dolcini Dec. 16, 2021, 7:52 a.m. UTC | #11
On Thu, Dec 16, 2021 at 04:52:39AM +0000, Joakim Zhang wrote:
> As I can see, when system suspended, PHY is totally powered down,
> since you disable the regulator. At this situation, if you
> assert reset signal, you mean it will increase the power
> consumption? PHY is totally powered down, why assert reset
> signal still affect PHY? 
In general there are *other* use cases in which the PHY is powered in
suspend. We should not create a regression there.

Francesco
Andrew Lunn Dec. 16, 2021, 10:24 a.m. UTC | #12
On Thu, Dec 16, 2021 at 08:52:16AM +0100, Francesco Dolcini wrote:
> On Thu, Dec 16, 2021 at 04:52:39AM +0000, Joakim Zhang wrote:
> > As I can see, when system suspended, PHY is totally powered down,
> > since you disable the regulator. At this situation, if you
> > assert reset signal, you mean it will increase the power
> > consumption? PHY is totally powered down, why assert reset
> > signal still affect PHY? 

> In general there are *other* use cases in which the PHY is powered in
> suspend. We should not create a regression there.

Yes, this is the sticking point. We can do what you want, but
potentially, the change affects others.

I think you need to move the regulator into phylib, so the PHY driver
can do the right thing. It is really the only entity which knows what
is the correct thing to do.

   Andrew
Francesco Dolcini Dec. 16, 2021, 11:24 a.m. UTC | #13
On Thu, Dec 16, 2021 at 11:24:24AM +0100, Andrew Lunn wrote:
> I think you need to move the regulator into phylib, so the PHY driver
> can do the right thing. It is really the only entity which knows what
> is the correct thing to do.
Do you believe that the right place is the phylib and not the phy driver?
Is this generic enough?

Francesco
Andrew Lunn Dec. 16, 2021, 11:28 a.m. UTC | #14
On Thu, Dec 16, 2021 at 12:24:33PM +0100, Francesco Dolcini wrote:
> On Thu, Dec 16, 2021 at 11:24:24AM +0100, Andrew Lunn wrote:
> > I think you need to move the regulator into phylib, so the PHY driver
> > can do the right thing. It is really the only entity which knows what
> > is the correct thing to do.

> Do you believe that the right place is the phylib and not the phy driver?
> Is this generic enough?

It is split. phylib can do the lookup in DT, get the regulator and
provide a helper to enable/disable it. So very similar to the reset.

The phy driver would then use the helpers. It probably needs to look
into the phydev structure to see what is actually available, is there
a reset, a regulator etc, and then decide what is best to do given the
available resources.

	  Andrew
Francesco Dolcini Dec. 16, 2021, 11:31 a.m. UTC | #15
On Thu, Dec 16, 2021 at 12:28:19PM +0100, Andrew Lunn wrote:
> On Thu, Dec 16, 2021 at 12:24:33PM +0100, Francesco Dolcini wrote:
> > On Thu, Dec 16, 2021 at 11:24:24AM +0100, Andrew Lunn wrote:
> > > I think you need to move the regulator into phylib, so the PHY driver
> > > can do the right thing. It is really the only entity which knows what
> > > is the correct thing to do.
> 
> > Do you believe that the right place is the phylib and not the phy driver?
> > Is this generic enough?
> 
> It is split. phylib can do the lookup in DT, get the regulator and
> provide a helper to enable/disable it. So very similar to the reset.
Sounds good.

Can we safely assume that we do have at most one regulator for the phy?

Francesco
Andrew Lunn Dec. 16, 2021, 11:32 a.m. UTC | #16
> Can we safely assume that we do have at most one regulator for the phy?

Seems like a reasonable assumption.

      Andrew
diff mbox series

Patch

diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c
index 1b1f7f2a6130..c29eddbb0155 100644
--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -4086,6 +4086,7 @@  static int __maybe_unused fec_resume(struct device *dev)
 		ret = regulator_enable(fep->reg_phy);
 		if (ret)
 			return ret;
+		phy_reset_after_power_on(ndev->phydev);
 	}
 
 	rtnl_lock();