linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH net] net: phy: fix the issue that netif always links up after resuming
@ 2018-11-29  8:12 Kunihiko Hayashi
  2018-11-29 22:47 ` Heiner Kallweit
  0 siblings, 1 reply; 6+ messages in thread
From: Kunihiko Hayashi @ 2018-11-29  8:12 UTC (permalink / raw)
  To: Andrew Lunn, Florian Fainelli, Heiner Kallweit, David S. Miller
  Cc: netdev, linux-kernel, Kunihiko Hayashi

Even though the link is down before entering hibernation,
there is an issue that the network interface always links up after resuming
from hibernation.

The phydev->state is PHY_READY before enabling the network interface, so
the link is down. After resuming from hibernation, the phydev->state is
forcibly set to PHY_UP in mdio_bus_phy_restore(), and the link becomes up.

This patch expects to solve the issue by changing phydev->state to PHY_UP
only when the link is up.

Signed-off-by: Kunihiko Hayashi <hayashi.kunihiko@socionext.com>
---
 drivers/net/phy/phy_device.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index ab33d17..d5bba0f 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -309,8 +309,10 @@ static int mdio_bus_phy_restore(struct device *dev)
 		return ret;
 
 	/* The PHY needs to renegotiate. */
-	phydev->link = 0;
-	phydev->state = PHY_UP;
+	if (phydev->link) {
+		phydev->link = 0;
+		phydev->state = PHY_UP;
+	}
 
 	phy_start_machine(phydev);
 
-- 
2.7.4


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

* Re: [RFC PATCH net] net: phy: fix the issue that netif always links up after resuming
  2018-11-29  8:12 [RFC PATCH net] net: phy: fix the issue that netif always links up after resuming Kunihiko Hayashi
@ 2018-11-29 22:47 ` Heiner Kallweit
  2018-11-30  0:37   ` Florian Fainelli
  0 siblings, 1 reply; 6+ messages in thread
From: Heiner Kallweit @ 2018-11-29 22:47 UTC (permalink / raw)
  To: Kunihiko Hayashi, Andrew Lunn, Florian Fainelli, David S. Miller
  Cc: netdev, linux-kernel

On 29.11.2018 09:12, Kunihiko Hayashi wrote:
> Even though the link is down before entering hibernation,
> there is an issue that the network interface always links up after resuming
> from hibernation.
> 
> The phydev->state is PHY_READY before enabling the network interface, so
> the link is down. After resuming from hibernation, the phydev->state is
> forcibly set to PHY_UP in mdio_bus_phy_restore(), and the link becomes up.
> 
> This patch expects to solve the issue by changing phydev->state to PHY_UP
> only when the link is up.
> 
> Signed-off-by: Kunihiko Hayashi <hayashi.kunihiko@socionext.com>
> ---
>  drivers/net/phy/phy_device.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
> index ab33d17..d5bba0f 100644
> --- a/drivers/net/phy/phy_device.c
> +++ b/drivers/net/phy/phy_device.c
> @@ -309,8 +309,10 @@ static int mdio_bus_phy_restore(struct device *dev)
>  		return ret;
>  
>  	/* The PHY needs to renegotiate. */
> -	phydev->link = 0;
> -	phydev->state = PHY_UP;
> +	if (phydev->link) {
> +		phydev->link = 0;
> +		phydev->state = PHY_UP;
> +	}
>  
Thanks for reporting. I agree that it isn't right to unconditionally set
PHY_UP, because we don't know whether the PHY was started before
hibernation. However I don't think using phydev->link as criteria is
right. Example would be: PHY was started before hibernation, but w/o link.
In this case we want to set PHY_UP to start an aneg, because a cable may
have been plugged in whilst system was sleeping.

So I think, similar to phy_stop_machine, we should use state >= UP and
state != HALTED as criteria, and also phy_start_machine() would need to
be called only if this criteria is met.

It may make sense to add a helper for checking whether PHY is in a
started state (>=UP && !=HALTED), because we need this in more than
one place.

>  	phy_start_machine(phydev);
>  
> 


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

* Re: [RFC PATCH net] net: phy: fix the issue that netif always links up after resuming
  2018-11-29 22:47 ` Heiner Kallweit
@ 2018-11-30  0:37   ` Florian Fainelli
  2018-11-30  4:37     ` Kunihiko Hayashi
  0 siblings, 1 reply; 6+ messages in thread
From: Florian Fainelli @ 2018-11-30  0:37 UTC (permalink / raw)
  To: Heiner Kallweit, Kunihiko Hayashi, Andrew Lunn, David S. Miller
  Cc: netdev, linux-kernel



On 11/29/2018 2:47 PM, Heiner Kallweit wrote:
> On 29.11.2018 09:12, Kunihiko Hayashi wrote:
>> Even though the link is down before entering hibernation,
>> there is an issue that the network interface always links up after resuming
>> from hibernation.
>>
>> The phydev->state is PHY_READY before enabling the network interface, so
>> the link is down. After resuming from hibernation, the phydev->state is
>> forcibly set to PHY_UP in mdio_bus_phy_restore(), and the link becomes up.
>>
>> This patch expects to solve the issue by changing phydev->state to PHY_UP
>> only when the link is up.
>>
>> Signed-off-by: Kunihiko Hayashi <hayashi.kunihiko@socionext.com>
>> ---
>>  drivers/net/phy/phy_device.c | 6 ++++--
>>  1 file changed, 4 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
>> index ab33d17..d5bba0f 100644
>> --- a/drivers/net/phy/phy_device.c
>> +++ b/drivers/net/phy/phy_device.c
>> @@ -309,8 +309,10 @@ static int mdio_bus_phy_restore(struct device *dev)
>>  		return ret;
>>  
>>  	/* The PHY needs to renegotiate. */
>> -	phydev->link = 0;
>> -	phydev->state = PHY_UP;
>> +	if (phydev->link) {
>> +		phydev->link = 0;
>> +		phydev->state = PHY_UP;
>> +	}
>>  
> Thanks for reporting. I agree that it isn't right to unconditionally set
> PHY_UP, because we don't know whether the PHY was started before
> hibernation. However I don't think using phydev->link as criteria is
> right. Example would be: PHY was started before hibernation, but w/o link.
> In this case we want to set PHY_UP to start an aneg, because a cable may
> have been plugged in whilst system was sleeping.
> 
> So I think, similar to phy_stop_machine, we should use state >= UP and
> state != HALTED as criteria, and also phy_start_machine() would need to
> be called only if this criteria is met.
> 
> It may make sense to add a helper for checking whether PHY is in a
> started state (>=UP && !=HALTED), because we need this in more than
> one place.

Agreed, that would make sense.
-- 
Florian

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

* Re: [RFC PATCH net] net: phy: fix the issue that netif always links up after resuming
  2018-11-30  0:37   ` Florian Fainelli
@ 2018-11-30  4:37     ` Kunihiko Hayashi
  2018-11-30  6:20       ` Heiner Kallweit
  0 siblings, 1 reply; 6+ messages in thread
From: Kunihiko Hayashi @ 2018-11-30  4:37 UTC (permalink / raw)
  To: Heiner Kallweit, Florian Fainelli
  Cc: Andrew Lunn, David S. Miller, netdev, linux-kernel

Hi Heiner Florian,

Thank you for your comments.

On Thu, 29 Nov 2018 16:37:48 -0800 <f.fainelli@gmail.com> wrote:

> 
> 
> On 11/29/2018 2:47 PM, Heiner Kallweit wrote:
> > On 29.11.2018 09:12, Kunihiko Hayashi wrote:
> >> Even though the link is down before entering hibernation,
> >> there is an issue that the network interface always links up after resuming
> >> from hibernation.
> >>
> >> The phydev->state is PHY_READY before enabling the network interface, so
> >> the link is down. After resuming from hibernation, the phydev->state is
> >> forcibly set to PHY_UP in mdio_bus_phy_restore(), and the link becomes up.
> >>
> >> This patch expects to solve the issue by changing phydev->state to PHY_UP
> >> only when the link is up.
> >>
> >> Signed-off-by: Kunihiko Hayashi <hayashi.kunihiko@socionext.com>
> >> ---
> >>  drivers/net/phy/phy_device.c | 6 ++++--
> >>  1 file changed, 4 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
> >> index ab33d17..d5bba0f 100644
> >> --- a/drivers/net/phy/phy_device.c
> >> +++ b/drivers/net/phy/phy_device.c
> >> @@ -309,8 +309,10 @@ static int mdio_bus_phy_restore(struct device *dev)
> >>  		return ret;
> >>  
> >>  	/* The PHY needs to renegotiate. */
> >> -	phydev->link = 0;
> >> -	phydev->state = PHY_UP;
> >> +	if (phydev->link) {
> >> +		phydev->link = 0;
> >> +		phydev->state = PHY_UP;
> >> +	}
> >>  
> > Thanks for reporting. I agree that it isn't right to unconditionally set
> > PHY_UP, because we don't know whether the PHY was started before
> > hibernation. However I don't think using phydev->link as criteria is
> > right. Example would be: PHY was started before hibernation, but w/o link.
> > In this case we want to set PHY_UP to start an aneg, because a cable may
> > have been plugged in whilst system was sleeping.

Indeed. I didn't consider the case that the PHY was started but a cable was
unplugged before hibernation.

> > So I think, similar to phy_stop_machine, we should use state >= UP and
> > state != HALTED as criteria, and also phy_start_machine() would need to
> > be called only if this criteria is met.
> > 
> > It may make sense to add a helper for checking whether PHY is in a
> > started state (>=UP && !=HALTED), because we need this in more than
> > one place.
> 
> Agreed, that would make sense.

I agree, too.
I'll try this in v2 patch that changes the PHY state to PHY_UP and calls
phy_start_machine(), only when the PHY was started before hibernation.
If I understand correctly, it will be like that:

	phydev->link = 0;
	if (phy_is_started(phydev)) {
		phydev->state = PHY_UP;
		phy_start_machine(phydev);
	}

Thank you,

---
Best Regards,
Kunihiko Hayashi



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

* Re: [RFC PATCH net] net: phy: fix the issue that netif always links up after resuming
  2018-11-30  4:37     ` Kunihiko Hayashi
@ 2018-11-30  6:20       ` Heiner Kallweit
  2018-11-30  6:38         ` Kunihiko Hayashi
  0 siblings, 1 reply; 6+ messages in thread
From: Heiner Kallweit @ 2018-11-30  6:20 UTC (permalink / raw)
  To: Kunihiko Hayashi, Florian Fainelli
  Cc: Andrew Lunn, David S. Miller, netdev, linux-kernel

On 30.11.2018 05:37, Kunihiko Hayashi wrote:
> Hi Heiner Florian,
> 
> Thank you for your comments.
> 
> On Thu, 29 Nov 2018 16:37:48 -0800 <f.fainelli@gmail.com> wrote:
> 
>>
>>
>> On 11/29/2018 2:47 PM, Heiner Kallweit wrote:
>>> On 29.11.2018 09:12, Kunihiko Hayashi wrote:
>>>> Even though the link is down before entering hibernation,
>>>> there is an issue that the network interface always links up after resuming
>>>> from hibernation.
>>>>
>>>> The phydev->state is PHY_READY before enabling the network interface, so
>>>> the link is down. After resuming from hibernation, the phydev->state is
>>>> forcibly set to PHY_UP in mdio_bus_phy_restore(), and the link becomes up.
>>>>
>>>> This patch expects to solve the issue by changing phydev->state to PHY_UP
>>>> only when the link is up.
>>>>
>>>> Signed-off-by: Kunihiko Hayashi <hayashi.kunihiko@socionext.com>
>>>> ---
>>>>  drivers/net/phy/phy_device.c | 6 ++++--
>>>>  1 file changed, 4 insertions(+), 2 deletions(-)
>>>>
>>>> diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
>>>> index ab33d17..d5bba0f 100644
>>>> --- a/drivers/net/phy/phy_device.c
>>>> +++ b/drivers/net/phy/phy_device.c
>>>> @@ -309,8 +309,10 @@ static int mdio_bus_phy_restore(struct device *dev)
>>>>  		return ret;
>>>>  
>>>>  	/* The PHY needs to renegotiate. */
>>>> -	phydev->link = 0;
>>>> -	phydev->state = PHY_UP;
>>>> +	if (phydev->link) {
>>>> +		phydev->link = 0;
>>>> +		phydev->state = PHY_UP;
>>>> +	}
>>>>  
>>> Thanks for reporting. I agree that it isn't right to unconditionally set
>>> PHY_UP, because we don't know whether the PHY was started before
>>> hibernation. However I don't think using phydev->link as criteria is
>>> right. Example would be: PHY was started before hibernation, but w/o link.
>>> In this case we want to set PHY_UP to start an aneg, because a cable may
>>> have been plugged in whilst system was sleeping.
> 
> Indeed. I didn't consider the case that the PHY was started but a cable was
> unplugged before hibernation.
> 
>>> So I think, similar to phy_stop_machine, we should use state >= UP and
>>> state != HALTED as criteria, and also phy_start_machine() would need to
>>> be called only if this criteria is met.
>>>
>>> It may make sense to add a helper for checking whether PHY is in a
>>> started state (>=UP && !=HALTED), because we need this in more than
>>> one place.
>>
>> Agreed, that would make sense.
> 
> I agree, too.
> I'll try this in v2 patch that changes the PHY state to PHY_UP and calls
> phy_start_machine(), only when the PHY was started before hibernation.
> If I understand correctly, it will be like that:
> 
> 	phydev->link = 0;
Even this may go into the if clause. If PHY isn't started then
phydev->link should be 0 anyway.

> 	if (phy_is_started(phydev)) {
> 		phydev->state = PHY_UP;
> 		phy_start_machine(phydev);
> 	}
> 
Yes, this is what was meant. Thanks.

> Thank you,
> 
> ---
> Best Regards,
> Kunihiko Hayashi
> 
> 
> 


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

* Re: [RFC PATCH net] net: phy: fix the issue that netif always links up after resuming
  2018-11-30  6:20       ` Heiner Kallweit
@ 2018-11-30  6:38         ` Kunihiko Hayashi
  0 siblings, 0 replies; 6+ messages in thread
From: Kunihiko Hayashi @ 2018-11-30  6:38 UTC (permalink / raw)
  To: Heiner Kallweit
  Cc: Florian Fainelli, Andrew Lunn, David S. Miller, netdev, linux-kernel

Hi Heiner,

On Fri, 30 Nov 2018 07:20:27 +0100 <hkallweit1@gmail.com> wrote:

> On 30.11.2018 05:37, Kunihiko Hayashi wrote:
> > Hi Heiner Florian,
> > 
> > Thank you for your comments.
> > 
> > On Thu, 29 Nov 2018 16:37:48 -0800 <f.fainelli@gmail.com> wrote:
> > 
> >>
> >>
> >> On 11/29/2018 2:47 PM, Heiner Kallweit wrote:
> >>> On 29.11.2018 09:12, Kunihiko Hayashi wrote:
> >>>> Even though the link is down before entering hibernation,
> >>>> there is an issue that the network interface always links up after resuming
> >>>> from hibernation.
> >>>>
> >>>> The phydev->state is PHY_READY before enabling the network interface, so
> >>>> the link is down. After resuming from hibernation, the phydev->state is
> >>>> forcibly set to PHY_UP in mdio_bus_phy_restore(), and the link becomes up.
> >>>>
> >>>> This patch expects to solve the issue by changing phydev->state to PHY_UP
> >>>> only when the link is up.
> >>>>
> >>>> Signed-off-by: Kunihiko Hayashi <hayashi.kunihiko@socionext.com>
> >>>> ---
> >>>>  drivers/net/phy/phy_device.c | 6 ++++--
> >>>>  1 file changed, 4 insertions(+), 2 deletions(-)
> >>>>
> >>>> diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
> >>>> index ab33d17..d5bba0f 100644
> >>>> --- a/drivers/net/phy/phy_device.c
> >>>> +++ b/drivers/net/phy/phy_device.c
> >>>> @@ -309,8 +309,10 @@ static int mdio_bus_phy_restore(struct device *dev)
> >>>>  		return ret;
> >>>>  
> >>>>  	/* The PHY needs to renegotiate. */
> >>>> -	phydev->link = 0;
> >>>> -	phydev->state = PHY_UP;
> >>>> +	if (phydev->link) {
> >>>> +		phydev->link = 0;
> >>>> +		phydev->state = PHY_UP;
> >>>> +	}
> >>>>  
> >>> Thanks for reporting. I agree that it isn't right to unconditionally set
> >>> PHY_UP, because we don't know whether the PHY was started before
> >>> hibernation. However I don't think using phydev->link as criteria is
> >>> right. Example would be: PHY was started before hibernation, but w/o link.
> >>> In this case we want to set PHY_UP to start an aneg, because a cable may
> >>> have been plugged in whilst system was sleeping.
> > 
> > Indeed. I didn't consider the case that the PHY was started but a cable was
> > unplugged before hibernation.
> > 
> >>> So I think, similar to phy_stop_machine, we should use state >= UP and
> >>> state != HALTED as criteria, and also phy_start_machine() would need to
> >>> be called only if this criteria is met.
> >>>
> >>> It may make sense to add a helper for checking whether PHY is in a
> >>> started state (>=UP && !=HALTED), because we need this in more than
> >>> one place.
> >>
> >> Agreed, that would make sense.
> > 
> > I agree, too.
> > I'll try this in v2 patch that changes the PHY state to PHY_UP and calls
> > phy_start_machine(), only when the PHY was started before hibernation.
> > If I understand correctly, it will be like that:
> > 
> > 	phydev->link = 0;
> Even this may go into the if clause. If PHY isn't started then
> phydev->link should be 0 anyway.

Yes. To clarify more, this will go into the if clause. 

> 
> > 	if (phy_is_started(phydev)) {
> > 		phydev->state = PHY_UP;
> > 		phy_start_machine(phydev);
> > 	}
> > 
> Yes, this is what was meant. Thanks.

Thank you,

---
Best Regards,
Kunihiko Hayashi



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

end of thread, other threads:[~2018-11-30  6:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-29  8:12 [RFC PATCH net] net: phy: fix the issue that netif always links up after resuming Kunihiko Hayashi
2018-11-29 22:47 ` Heiner Kallweit
2018-11-30  0:37   ` Florian Fainelli
2018-11-30  4:37     ` Kunihiko Hayashi
2018-11-30  6:20       ` Heiner Kallweit
2018-11-30  6:38         ` Kunihiko Hayashi

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