diff mbox series

[v2,1/2] net: phylink: init phydev on phylink_resume()

Message ID 20221212112845.73290-2-claudiu.beznea@microchip.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series net: macb: fix connectivity after resume | expand

Checks

Context Check Description
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix warning Target tree name not specified in the subject
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 8 of 8 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/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch warning WARNING: Missing a blank line after declarations
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Claudiu Beznea Dec. 12, 2022, 11:28 a.m. UTC
There are scenarios where PHY power is cut off on system suspend.
There are also MAC drivers which handles themselves the PHY on
suspend/resume path. For such drivers the
struct phy_device::mac_managed_phy is set to true and thus the
mdio_bus_phy_suspend()/mdio_bus_phy_resume() wouldn't do the
proper PHY suspend/resume. For such scenarios call phy_init_hw()
from phylink_resume().

Suggested-by: Russell King (Oracle) <linux@armlinux.org.uk>
Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
---

Hi, Russel,

I let phy_init_hw() to execute for all devices. I can restrict it only
for PHYs that has struct phy_device::mac_managed_phy = true.

Please let me know what you think.

Thank you,
Claudiu Beznea


 drivers/net/phy/phylink.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Russell King (Oracle) Dec. 12, 2022, 12:47 p.m. UTC | #1
On Mon, Dec 12, 2022 at 01:28:44PM +0200, Claudiu Beznea wrote:
> There are scenarios where PHY power is cut off on system suspend.
> There are also MAC drivers which handles themselves the PHY on
> suspend/resume path. For such drivers the
> struct phy_device::mac_managed_phy is set to true and thus the
> mdio_bus_phy_suspend()/mdio_bus_phy_resume() wouldn't do the
> proper PHY suspend/resume. For such scenarios call phy_init_hw()
> from phylink_resume().
> 
> Suggested-by: Russell King (Oracle) <linux@armlinux.org.uk>
> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
> ---
> 
> Hi, Russel,
> 
> I let phy_init_hw() to execute for all devices. I can restrict it only
> for PHYs that has struct phy_device::mac_managed_phy = true.
> 
> Please let me know what you think.

I think it would be better to only do this in the path where we call
phy_start() - if we do it in the WoL path (where the PHY remains
running), then there is no phy_start() call, so phy_init_hw() could
result in the PHY not working after a suspend/resume event.
Claudiu Beznea Dec. 12, 2022, 1:26 p.m. UTC | #2
On 12.12.2022 14:47, Russell King (Oracle) wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> On Mon, Dec 12, 2022 at 01:28:44PM +0200, Claudiu Beznea wrote:
>> There are scenarios where PHY power is cut off on system suspend.
>> There are also MAC drivers which handles themselves the PHY on
>> suspend/resume path. For such drivers the
>> struct phy_device::mac_managed_phy is set to true and thus the
>> mdio_bus_phy_suspend()/mdio_bus_phy_resume() wouldn't do the
>> proper PHY suspend/resume. For such scenarios call phy_init_hw()
>> from phylink_resume().
>>
>> Suggested-by: Russell King (Oracle) <linux@armlinux.org.uk>
>> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
>> ---
>>
>> Hi, Russel,
>>
>> I let phy_init_hw() to execute for all devices. I can restrict it only
>> for PHYs that has struct phy_device::mac_managed_phy = true.
>>
>> Please let me know what you think.
> 
> I think it would be better to only do this in the path where we call
> phy_start() - if we do it in the WoL path (where the PHY remains
> running), then there is no phy_start() call, so phy_init_hw() could
> result in the PHY not working after a suspend/resume event.

This will not work all the time for MACB usage on AT91 devices.

As explained here [1] the scenario where:
- MACB is configured to handle WoL
- the system goes to a suspend mode (named backup and self-refresh (BSR) in
  our case) with power cut off on PHY and limited wake-up source (few pins
  and RTC alarms)

is still valid. In this case MAC IP and MAC PHY are not powered. And in
those cases phylink_resume() will not hit phy_start().


Just my feeling about this: after looking to phylink_resume() it looks to
me that (at least for MACB on AT91) it is better to have the PHY handling
still in the MAC driver (calling phy_init_hw() from driver itself) as this
was the intent (I think) of struct phy_device::mac_managed_phy. But this is
not based on any technical argument at the moment.

Thank you,
Claudiu Beznea

[1]
https://lore.kernel.org/all/4375d733-ed49-869c-635f-0f0ba7304283@microchip.com/

> 
> --
> RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
> FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
Vladimir Oltean Dec. 12, 2022, 1:54 p.m. UTC | #3
Hi Claudiu,

On Mon, Dec 12, 2022 at 01:28:44PM +0200, Claudiu Beznea wrote:
> There are scenarios where PHY power is cut off on system suspend.
> There are also MAC drivers which handles themselves the PHY on
> suspend/resume path. For such drivers the
> struct phy_device::mac_managed_phy is set to true and thus the
> mdio_bus_phy_suspend()/mdio_bus_phy_resume() wouldn't do the
> proper PHY suspend/resume. For such scenarios call phy_init_hw()
> from phylink_resume().
> 
> Suggested-by: Russell King (Oracle) <linux@armlinux.org.uk>
> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
> ---
> 
> Hi, Russel,
> 
> I let phy_init_hw() to execute for all devices. I can restrict it only
> for PHYs that has struct phy_device::mac_managed_phy = true.
> 
> Please let me know what you think.
> 
> Thank you,
> Claudiu Beznea
> 
> 
>  drivers/net/phy/phylink.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
> index 09cc65c0da93..6003c329638e 100644
> --- a/drivers/net/phy/phylink.c
> +++ b/drivers/net/phy/phylink.c
> @@ -2031,6 +2031,12 @@ void phylink_resume(struct phylink *pl)
>  {
>  	ASSERT_RTNL();
>  
> +	if (pl->phydev) {
> +		int ret = phy_init_hw(pl->phydev);
> +		if (ret)
> +			return;
> +	}
> +

If the config_init() method of the driver does things such as this:

	phydev->mdix_ctrl = ETH_TP_MDI_AUTO;

like for example the marvell10g.c driver, won't a user-configured manual
MDI setting get overwritten after a suspend/resume cycle?

>  	if (test_bit(PHYLINK_DISABLE_MAC_WOL, &pl->phylink_disable_state)) {
>  		/* Wake-on-Lan enabled, MAC handling */
>  
> -- 
> 2.34.1
>
Russell King (Oracle) Dec. 12, 2022, 2:24 p.m. UTC | #4
On Mon, Dec 12, 2022 at 01:26:54PM +0000, Claudiu.Beznea@microchip.com wrote:
> On 12.12.2022 14:47, Russell King (Oracle) wrote:
> > EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> > 
> > On Mon, Dec 12, 2022 at 01:28:44PM +0200, Claudiu Beznea wrote:
> >> There are scenarios where PHY power is cut off on system suspend.
> >> There are also MAC drivers which handles themselves the PHY on
> >> suspend/resume path. For such drivers the
> >> struct phy_device::mac_managed_phy is set to true and thus the
> >> mdio_bus_phy_suspend()/mdio_bus_phy_resume() wouldn't do the
> >> proper PHY suspend/resume. For such scenarios call phy_init_hw()
> >> from phylink_resume().
> >>
> >> Suggested-by: Russell King (Oracle) <linux@armlinux.org.uk>
> >> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
> >> ---
> >>
> >> Hi, Russel,
> >>
> >> I let phy_init_hw() to execute for all devices. I can restrict it only
> >> for PHYs that has struct phy_device::mac_managed_phy = true.
> >>
> >> Please let me know what you think.
> > 
> > I think it would be better to only do this in the path where we call
> > phy_start() - if we do it in the WoL path (where the PHY remains
> > running), then there is no phy_start() call, so phy_init_hw() could
> > result in the PHY not working after a suspend/resume event.
> 
> This will not work all the time for MACB usage on AT91 devices.
> 
> As explained here [1] the scenario where:
> - MACB is configured to handle WoL
> - the system goes to a suspend mode (named backup and self-refresh (BSR) in
>   our case) with power cut off on PHY and limited wake-up source (few pins
>   and RTC alarms)
> 
> is still valid. In this case MAC IP and MAC PHY are not powered. And in
> those cases phylink_resume() will not hit phy_start().

If the MAC is handling WoL, how does the MAC receive the packet to
wake up if the PHY has lost power?

If the PHY loses power, the MAC won't be able to receive the magic
packet, and so WoL will be non-functional, and therefore will be
completely pointless to support in such a configuration.

What am I missing?
Claudiu Beznea Dec. 12, 2022, 2:46 p.m. UTC | #5
On 12.12.2022 16:24, Russell King (Oracle) wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> On Mon, Dec 12, 2022 at 01:26:54PM +0000, Claudiu.Beznea@microchip.com wrote:
>> On 12.12.2022 14:47, Russell King (Oracle) wrote:
>>> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
>>>
>>> On Mon, Dec 12, 2022 at 01:28:44PM +0200, Claudiu Beznea wrote:
>>>> There are scenarios where PHY power is cut off on system suspend.
>>>> There are also MAC drivers which handles themselves the PHY on
>>>> suspend/resume path. For such drivers the
>>>> struct phy_device::mac_managed_phy is set to true and thus the
>>>> mdio_bus_phy_suspend()/mdio_bus_phy_resume() wouldn't do the
>>>> proper PHY suspend/resume. For such scenarios call phy_init_hw()
>>>> from phylink_resume().
>>>>
>>>> Suggested-by: Russell King (Oracle) <linux@armlinux.org.uk>
>>>> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
>>>> ---
>>>>
>>>> Hi, Russel,
>>>>
>>>> I let phy_init_hw() to execute for all devices. I can restrict it only
>>>> for PHYs that has struct phy_device::mac_managed_phy = true.
>>>>
>>>> Please let me know what you think.
>>>
>>> I think it would be better to only do this in the path where we call
>>> phy_start() - if we do it in the WoL path (where the PHY remains
>>> running), then there is no phy_start() call, so phy_init_hw() could
>>> result in the PHY not working after a suspend/resume event.
>>
>> This will not work all the time for MACB usage on AT91 devices.
>>
>> As explained here [1] the scenario where:
>> - MACB is configured to handle WoL
>> - the system goes to a suspend mode (named backup and self-refresh (BSR) in
>>   our case) with power cut off on PHY and limited wake-up source (few pins
>>   and RTC alarms)
>>
>> is still valid. In this case MAC IP and MAC PHY are not powered. And in
>> those cases phylink_resume() will not hit phy_start().
> 
> If the MAC is handling WoL, how does the MAC receive the packet to
> wake up if the PHY has lost power?

Yes, this can't happen.

> 
> If the PHY loses power, the MAC won't be able to receive the magic
> packet, and so WoL will be non-functional, and therefore will be
> completely pointless to support in such a configuration.
> 
> What am I missing?

As explained in the previous version [1], we currently don't impose any
restriction like this in arch specific PM code (the only place where we can
decide if going to BSR and device_may_wakeup()). I had in mind to do it at
some point but though that user will have to re-do all the wakeup sources
reconfiguration when switching b/w suspend modes that cut or not PHY power.
To be consistent this will have to be done for all devices registered as
wakeup sources (except the few pins and RTC in case). And this may be a
pain for users.

[1]
https://lore.kernel.org/all/4375d733-ed49-869c-635f-0f0ba7304283@microchip.com/

> 
> --
> RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
> FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
Claudiu Beznea Dec. 12, 2022, 3:20 p.m. UTC | #6
Hi, Vladimir,

On 12.12.2022 15:54, Vladimir Oltean wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> Hi Claudiu,
> 
> On Mon, Dec 12, 2022 at 01:28:44PM +0200, Claudiu Beznea wrote:
>> There are scenarios where PHY power is cut off on system suspend.
>> There are also MAC drivers which handles themselves the PHY on
>> suspend/resume path. For such drivers the
>> struct phy_device::mac_managed_phy is set to true and thus the
>> mdio_bus_phy_suspend()/mdio_bus_phy_resume() wouldn't do the
>> proper PHY suspend/resume. For such scenarios call phy_init_hw()
>> from phylink_resume().
>>
>> Suggested-by: Russell King (Oracle) <linux@armlinux.org.uk>
>> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
>> ---
>>
>> Hi, Russel,
>>
>> I let phy_init_hw() to execute for all devices. I can restrict it only
>> for PHYs that has struct phy_device::mac_managed_phy = true.
>>
>> Please let me know what you think.
>>
>> Thank you,
>> Claudiu Beznea
>>
>>
>>  drivers/net/phy/phylink.c | 6 ++++++
>>  1 file changed, 6 insertions(+)
>>
>> diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
>> index 09cc65c0da93..6003c329638e 100644
>> --- a/drivers/net/phy/phylink.c
>> +++ b/drivers/net/phy/phylink.c
>> @@ -2031,6 +2031,12 @@ void phylink_resume(struct phylink *pl)
>>  {
>>       ASSERT_RTNL();
>>
>> +     if (pl->phydev) {
>> +             int ret = phy_init_hw(pl->phydev);
>> +             if (ret)
>> +                     return;
>> +     }
>> +
> 
> If the config_init() method of the driver does things such as this:
> 
>         phydev->mdix_ctrl = ETH_TP_MDI_AUTO;
> 
> like for example the marvell10g.c driver, won't a user-configured manual
> MDI setting get overwritten after a suspend/resume cycle?

I'm not fully sure about it. I have to look further though the code.
At the same time phy_init_hw() is called also on mdio_bus_phy_resume().

Thank you,
Claudiu Beznea

> 
>>       if (test_bit(PHYLINK_DISABLE_MAC_WOL, &pl->phylink_disable_state)) {
>>               /* Wake-on-Lan enabled, MAC handling */
>>
>> --
>> 2.34.1
>>
diff mbox series

Patch

diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
index 09cc65c0da93..6003c329638e 100644
--- a/drivers/net/phy/phylink.c
+++ b/drivers/net/phy/phylink.c
@@ -2031,6 +2031,12 @@  void phylink_resume(struct phylink *pl)
 {
 	ASSERT_RTNL();
 
+	if (pl->phydev) {
+		int ret = phy_init_hw(pl->phydev);
+		if (ret)
+			return;
+	}
+
 	if (test_bit(PHYLINK_DISABLE_MAC_WOL, &pl->phylink_disable_state)) {
 		/* Wake-on-Lan enabled, MAC handling */