Skip to contentSkip to conversation

net: phy: state machine fixes for interrupt driven PHYs

PATCH Superseded Roger Quadros 4 participants 13 messages Mar 22, 2017 – Apr 19, 2017

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v2 cover net: phy: state machine fixes for interrupt driven PHYs

Hi,

These 2 patches fix the following 2 issues with the PHY state machine when used with interrupt driven PHYs.

- PHY link not coming up if Ethernet cable is plugged before Ethernet network interface is brought up.

- PHY not being suspended when PHY is halted.

cheers,
-roger

Roger Quadros (2):
net: phy: Fix PHY AN done state machine for interrupt driven PHYs
net: phy: Don't miss phy_suspend() on PHY_HALTED for PHYs with
interrupts

 drivers/net/phy/phy.c | 5 +++++
 1 file changed, 5 insertions(+)
Signature · 1 line
2.7.4
#1 lore raw

PATCH v2 1/2 net: phy: Fix PHY AN done state machine for interrupt driven PHYs

he ethernet link on an interrupt driven PHY was not coming up if the ethernet cable was plugged before the ethernet interface was brought up.

The PHY state machine seems to be stuck from RUNNING to AN state with no new interrupts from the PHY. So it doesn't know when the PHY Auto-negotiation has been completed and doesn't transition to RUNNING state with ANEG done thus netif_carrier_on() is never called.

NOTE: genphy_config_aneg() will not restart PHY Auto-negotiation of advertisement parameters didn't change.

Fix this by scheduling the PHY state machine in phy_start_aneg().

Fixes 3c293f4e08b5 ("net: phy: Trigger state machine on state change and not polling.")
Cc stable <[email protected]> # v4.9+
---
 drivers/net/phy/phy.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/net/phy/phy.c +4 -0
index 1be69d8..49dedf8 100644
@@ -630,6 +630,10 @@ int phy_start_aneg(struct phy_device *phydev)
 
 out_unlock:
 	mutex_unlock(&phydev->lock);
+	if (!err && phy_interrupt_is_valid(phydev))
+		queue_delayed_work(system_power_efficient_wq,
+				   &phydev->state_queue, HZ);
+
 	return err;
 }
 EXPORT_SYMBOL(phy_start_aneg);
Signature · 1 line
2.7.4
#2 lore raw

Re: [PATCH v2 1/2] net: phy: Fix PHY AN done state machine for interrupt driven PHYs

Hello!

Quoted 1 line · Roger Quadros

he ethernet link on an interrupt driven PHY was not coming up if the

s/he/The/?

Quoted 1 line

ethernet cable was plugged before the ethernet interface was brought up.

Also, my spell checker trips on "ethernet", perhaps should be capitalized?

Quoted 5 lines

The PHY state machine seems to be stuck from RUNNING to AN state with no new interrupts from the PHY. So it doesn't know when the PHY Auto-negotiation has been completed and doesn't transition to RUNNING state with ANEG done thus netif_carrier_on() is never called.

Quoted 8 lines

NOTE: genphy_config_aneg() will not restart PHY Auto-negotiation of advertisement parameters didn't change.

Fix this by scheduling the PHY state machine in phy_start_aneg().

Fixes 3c293f4e08b5 ("net: phy: Trigger state machine on state change and not polling.")
Cc stable <[email protected]> # v4.9+

[...]

MBR, Sergei

#3 lore raw

Re: [PATCH v2 1/2] net: phy: Fix PHY AN done state machine for interrupt driven PHYs

Quoted 11 lines · Sergei Shtylyov

Hello!

Quoted 1 line · Roger Quadros

he ethernet link on an interrupt driven PHY was not coming up if the

   s/he/The/?
Quoted 1 line

ethernet cable was plugged before the ethernet interface was brought up.

Also, my spell checker trips on "ethernet", perhaps should be capitalized?

Thanks. I'll fix both issues.

Quoted 9 lines
Quoted 9 lines

The PHY state machine seems to be stuck from RUNNING to AN state with no new interrupts from the PHY. So it doesn't know when the PHY Auto-negotiation has been completed and doesn't transition to RUNNING state with ANEG done thus netif_carrier_on() is never called.

NOTE: genphy_config_aneg() will not restart PHY Auto-negotiation of advertisement parameters didn't change.

Quoted 9 lines
Quoted 5 lines

Fix this by scheduling the PHY state machine in phy_start_aneg().

Fixes 3c293f4e08b5 ("net: phy: Trigger state machine on state change and not polling.")
Cc stable <[email protected]> # v4.9+

[...]

MBR, Sergei

cheers,
-roger

#4 lore raw

PATCH v3 1/2 net: phy: Fix PHY AN done state machine for interrupt driven PHYs

In reply to Roger Quadros

The Ethernet link on an interrupt driven PHY was not coming up if the Ethernet cable was plugged before the Ethernet interface was brought up.

The PHY state machine seems to be stuck from RUNNING to AN state with no new interrupts from the PHY. So it doesn't know when the PHY Auto-negotiation has been completed and doesn't transition to RUNNING state with ANEG done thus netif_carrier_on() is never called.

NOTE: genphy_config_aneg() will not restart PHY Auto-negotiation of advertisement parameters didn't change.

Fix this by scheduling the PHY state machine in phy_start_aneg(). There is no way of knowing in phy.c whether auto-negotiation was restarted or not by the PHY driver so we just wait for the next poll/interrupt to update the PHY state machine.

Fixes 3c293f4e08b5 ("net: phy: Trigger state machine on state change and not polling.")
Cc stable <[email protected]> # v4.9+

---
v3: Fix typo in commit message

 drivers/net/phy/phy.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/net/phy/phy.c +4 -0
index 1be69d8..49dedf8 100644
@@ -630,6 +630,10 @@ int phy_start_aneg(struct phy_device *phydev)
 
 out_unlock:
 	mutex_unlock(&phydev->lock);
+	if (!err && phy_interrupt_is_valid(phydev))
+		queue_delayed_work(system_power_efficient_wq,
+				   &phydev->state_queue, HZ);
+
 	return err;
 }
 EXPORT_SYMBOL(phy_start_aneg);
Signature · 1 line
2.7.4
#5 lore raw

Re: [PATCH v3 1/2] net: phy: Fix PHY AN done state machine for interrupt driven PHYs

+Andrew Davis & Sekhar.

Hi,

Andrew Davis posted a few comments offline which I'm clarifying here.

Quoted 10 lines · Roger Quadros

The Ethernet link on an interrupt driven PHY was not coming up if the Ethernet cable was plugged before the Ethernet interface was brought up.

The PHY state machine seems to be stuck from RUNNING to AN state with no new interrupts from the PHY. So it doesn't know when the PHY Auto-negotiation has been completed and doesn't transition to RUNNING state with ANEG done thus netif_carrier_on() is never called.

NOTE: genphy_config_aneg() will not restart PHY Auto-negotiation of advertisement parameters didn't change.

Is phy->config_aneg expected to *always* restart auto-negotiation even if advertisement parameters didn't change?
If so then we'll need to fix genphy_config_aneg().

Quoted 21 lines

Fix this by scheduling the PHY state machine in phy_start_aneg(). There is no way of knowing in phy.c whether auto-negotiation was restarted or not by the PHY driver so we just wait for the next poll/interrupt to update the PHY state machine.

Fixes 3c293f4e08b5 ("net: phy: Trigger state machine on state change and not polling.")
Cc stable <[email protected]> # v4.9+

---
v3: Fix typo in commit message

 drivers/net/phy/phy.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/net/phy/phy.c +0 -0
index 1be69d8..49dedf8 100644

drivers/net/phy/phy.c int phy_start_aneg(struct phy_device *phydev) · line 639

Quoted 10 lines
drivers/net/phy/phy.c +4 -0
@@ -630,6 +630,10 @@ int phy_start_aneg(struct phy_device *phydev)
 
 out_unlock:
 	mutex_unlock(&phydev->lock);
+	if (!err && phy_interrupt_is_valid(phydev))
+		queue_delayed_work(system_power_efficient_wq,
+				   &phydev->state_queue, HZ);
+
 	return err;
 }
 EXPORT_SYMBOL(phy_start_aneg);

There is still room for optimization for interrupt driven PHYs as I still see a delay of 1 second between "ifconfig ethx up" and link status coming up if cable was already plugged in. In fact if Auto-negotiation was already completed and not required to be restarted, the PHY state machine should have move from AN to RUNNING instantly without expecting a PHY interrupt.

How can we get rid of the unnecessary delay in the case where auto-negotiation is not restarted?
Should we check for phy_aneg_done() immediately after issuing a phy_start_aneg() in phy_state_machine() and switch from PHY_AN to PHY_RUNNING?

This should avoid the need to re-schedule the state machine in phy_start_angeg().

cheers,
-roger

#6 lore raw

Re: [PATCH v3 1/2] net: phy: Fix PHY AN done state machine for interrupt driven PHYs

Hi,

Quoted 60 lines · Roger Quadros

+Andrew Davis & Sekhar.

Hi,

Andrew Davis posted a few comments offline which I'm clarifying here.

Quoted 10 lines · Roger Quadros

The Ethernet link on an interrupt driven PHY was not coming up if the Ethernet cable was plugged before the Ethernet interface was brought up.

The PHY state machine seems to be stuck from RUNNING to AN state with no new interrupts from the PHY. So it doesn't know when the PHY Auto-negotiation has been completed and doesn't transition to RUNNING state with ANEG done thus netif_carrier_on() is never called.

NOTE: genphy_config_aneg() will not restart PHY Auto-negotiation of advertisement parameters didn't change.

Is phy->config_aneg expected to *always* restart auto-negotiation even if advertisement parameters didn't change?
If so then we'll need to fix genphy_config_aneg().

Quoted 21 lines

Fix this by scheduling the PHY state machine in phy_start_aneg(). There is no way of knowing in phy.c whether auto-negotiation was restarted or not by the PHY driver so we just wait for the next poll/interrupt to update the PHY state machine.

Fixes 3c293f4e08b5 ("net: phy: Trigger state machine on state change and not polling.")
Cc stable <[email protected]> # v4.9+

---
v3: Fix typo in commit message

 drivers/net/phy/phy.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/net/phy/phy.c +0 -0
index 1be69d8..49dedf8 100644

drivers/net/phy/phy.c int phy_start_aneg(struct phy_device *phydev) · line 639

Quoted 10 lines
drivers/net/phy/phy.c +4 -0
@@ -630,6 +630,10 @@ int phy_start_aneg(struct phy_device *phydev)
 
 out_unlock:
 	mutex_unlock(&phydev->lock);
+	if (!err && phy_interrupt_is_valid(phydev))
+		queue_delayed_work(system_power_efficient_wq,
+				   &phydev->state_queue, HZ);
+
 	return err;
 }
 EXPORT_SYMBOL(phy_start_aneg);

There is still room for optimization for interrupt driven PHYs as I still see a delay of 1 second between "ifconfig ethx up" and link status coming up if cable was already plugged in. In fact if Auto-negotiation was already completed and not required to be restarted, the PHY state machine should have move from AN to RUNNING instantly without expecting a PHY interrupt.

Quoted 6 lines

How can we get rid of the unnecessary delay in the case where auto-negotiation is not restarted?
Should we check for phy_aneg_done() immediately after issuing a phy_start_aneg() in phy_state_machine() and switch from PHY_AN to PHY_RUNNING?

This should avoid the need to re-schedule the state machine in phy_start_angeg().

Any comments on my questions?

cheers,
-roger

#7 lore raw

Re: [PATCH v3 1/2] net: phy: Fix PHY AN done state machine for interrupt driven PHYs

Quoted 67 lines · Roger Quadros

Hi,

Quoted 64 lines · Roger Quadros

+Andrew Davis & Sekhar.

Hi,

Andrew Davis posted a few comments offline which I'm clarifying here.

Quoted 10 lines · Roger Quadros

The Ethernet link on an interrupt driven PHY was not coming up if the Ethernet cable was plugged before the Ethernet interface was brought up.

The PHY state machine seems to be stuck from RUNNING to AN state with no new interrupts from the PHY. So it doesn't know when the PHY Auto-negotiation has been completed and doesn't transition to RUNNING state with ANEG done thus netif_carrier_on() is never called.

NOTE: genphy_config_aneg() will not restart PHY Auto-negotiation of advertisement parameters didn't change.

Is phy->config_aneg expected to *always* restart auto-negotiation even if advertisement parameters didn't change?
If so then we'll need to fix genphy_config_aneg().

Quoted 21 lines

Fix this by scheduling the PHY state machine in phy_start_aneg(). There is no way of knowing in phy.c whether auto-negotiation was restarted or not by the PHY driver so we just wait for the next poll/interrupt to update the PHY state machine.

Fixes 3c293f4e08b5 ("net: phy: Trigger state machine on state change and not polling.")
Cc stable <[email protected]> # v4.9+

---
v3: Fix typo in commit message

 drivers/net/phy/phy.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/net/phy/phy.c +0 -0
index 1be69d8..49dedf8 100644

drivers/net/phy/phy.c int phy_start_aneg(struct phy_device *phydev) · line 639

Quoted 10 lines
drivers/net/phy/phy.c +4 -0
@@ -630,6 +630,10 @@ int phy_start_aneg(struct phy_device *phydev)
 
 out_unlock:
 	mutex_unlock(&phydev->lock);
+	if (!err && phy_interrupt_is_valid(phydev))
+		queue_delayed_work(system_power_efficient_wq,
+				   &phydev->state_queue, HZ);
+
 	return err;
 }
 EXPORT_SYMBOL(phy_start_aneg);

There is still room for optimization for interrupt driven PHYs as I still see a delay of 1 second between "ifconfig ethx up" and link status coming up if cable was already plugged in. In fact if Auto-negotiation was already completed and not required to be restarted, the PHY state machine should have move from AN to RUNNING instantly without expecting a PHY interrupt.

How can we get rid of the unnecessary delay in the case where auto-negotiation is not restarted?
Should we check for phy_aneg_done() immediately after issuing a phy_start_aneg() in phy_state_machine() and switch from PHY_AN to PHY_RUNNING?

That sounds like a good idea yes. It seems to me like Alexander's patch actually takes care of that:

http://patchwork.ozlabs.org/patch/752288/

Let's try to merge threads/recipients so we can shoot for a fix to be included soon.

Thanks!

Quoted 8 lines
Quoted 2 lines

This should avoid the need to re-schedule the state machine in phy_start_angeg().

Any comments on my questions?

cheers,
-roger

Signature · 1 line
Florian
Tested-by on v3 1/2
#8 lore raw

RE: [PATCH v3 1/2] net: phy: Fix PHY AN done state machine for interrupt driven PHYs

In reply to Roger Quadros
Quoted 17 lines · Roger Quadros

The Ethernet link on an interrupt driven PHY was not coming up if the Ethernet cable was plugged before the Ethernet interface was brought up.

The PHY state machine seems to be stuck from RUNNING to AN state with no new interrupts from the PHY. So it doesn't know when the PHY Auto-negotiation has been completed and doesn't transition to RUNNING state with ANEG done thus netif_carrier_on() is never called.

NOTE: genphy_config_aneg() will not restart PHY Auto-negotiation of advertisement parameters didn't change.

Fix this by scheduling the PHY state machine in phy_start_aneg(). There is no way of knowing in phy.c whether auto-negotiation was restarted or not by the PHY driver so we just wait for the next poll/interrupt to update the PHY state machine.

Fixes 3c293f4e08b5 ("net: phy: Trigger state machine on state change and
Quoted 8 lines

not polling.")

---
v3: Fix typo in commit message

 drivers/net/phy/phy.c | 4 ++++
 1 file changed, 4 insertions(+)
Reviewed-by on v3 1/2
#9 lore raw

Re: [PATCH v3 1/2] net: phy: Fix PHY AN done state machine for interrupt driven PHYs

In reply to Roger Quadros
Quoted 11 lines · Roger Quadros

The Ethernet link on an interrupt driven PHY was not coming up if the Ethernet cable was plugged before the Ethernet interface was brought up.

The PHY state machine seems to be stuck from RUNNING to AN state with no new interrupts from the PHY. So it doesn't know when the PHY Auto-negotiation has been completed and doesn't transition to RUNNING state with ANEG done thus netif_carrier_on() is never called.

NOTE: genphy_config_aneg() will not restart PHY Auto-negotiation of advertisement parameters didn't change.

Quoted 8 lines

Fix this by scheduling the PHY state machine in phy_start_aneg(). There is no way of knowing in phy.c whether auto-negotiation was restarted or not by the PHY driver so we just wait for the next poll/interrupt to update the PHY state machine.

Fixes 3c293f4e08b5 ("net: phy: Trigger state machine on state change and not polling.")
Cc stable <[email protected]> # v4.9+
Signature · 1 line
Florian
#10 lore raw

Re: [PATCH v3 1/2] net: phy: Fix PHY AN done state machine for interrupt driven PHYs

Florian,

Quoted 17 lines · Florian Fainelli
Quoted 16 lines · Roger Quadros

The Ethernet link on an interrupt driven PHY was not coming up if the Ethernet cable was plugged before the Ethernet interface was brought up.

The PHY state machine seems to be stuck from RUNNING to AN state with no new interrupts from the PHY. So it doesn't know when the PHY Auto-negotiation has been completed and doesn't transition to RUNNING state with ANEG done thus netif_carrier_on() is never called.

NOTE: genphy_config_aneg() will not restart PHY Auto-negotiation of advertisement parameters didn't change.

Fix this by scheduling the PHY state machine in phy_start_aneg(). There is no way of knowing in phy.c whether auto-negotiation was restarted or not by the PHY driver so we just wait for the next poll/interrupt to update the PHY state machine.

Quoted 6 lines
Quoted 3 lines
Fixes 3c293f4e08b5 ("net: phy: Trigger state machine on state change and not polling.")
Cc stable <[email protected]> # v4.9+

Thanks for the review, but there are a still few unanswered questions in the parallel thread. Can you please clarify those first before this patch gets picked? Thanks.

cheers,
-roger

#11 lore raw

PATCH v2 2/2 net: phy: Don't miss phy_suspend() on PHY_HALTED for PHYs with interrupts

In reply to Roger Quadros

phy_suspend() doesn't get called as part of phy_stop() for PHYs using interrupts because the phy state machine is never triggered after a phy_stop().

Explicitly trigger the PHY state machine in phy_stop() so that it can see the new PHY state (HALTED) and suspend the PHY.

As most PHYLIB consumers will call phy_stop() with rtnl_lock() held from ndo_close() so we use don't wait for workqueue cancellation in phy_trigger_machine() by passing false for the 'sync' argument.

Fixes 3c293f4e08b5 ("net: phy: Trigger state machine on state change and not polling.")
Cc stable <[email protected]> # v4.9+
---
 drivers/net/phy/phy.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/phy/phy.c +1 -0
index 49dedf8..ab14e7b 100644
@@ -907,6 +907,7 @@ void phy_stop(struct phy_device *phydev)
 	 * of rtnl_lock(), but PHY_HALTED shall guarantee phy_change()
 	 * will not reenable interrupts.
 	 */
+	phy_trigger_machine(phydev, false);
 }
 EXPORT_SYMBOL(phy_stop);
 
Signature · 1 line
2.7.4
#12 lore raw

Re: [PATCH v2 2/2] net: phy: Don't miss phy_suspend() on PHY_HALTED for PHYs with interrupts

Quoted 10 lines · Roger Quadros

phy_suspend() doesn't get called as part of phy_stop() for PHYs using interrupts because the phy state machine is never triggered after a phy_stop().

Explicitly trigger the PHY state machine in phy_stop() so that it can see the new PHY state (HALTED) and suspend the PHY.

As most PHYLIB consumers will call phy_stop() with rtnl_lock() held from ndo_close() so we use don't wait for workqueue cancellation in phy_trigger_machine() by passing false for the 'sync' argument.

Sorry for this long delay in responding. I am not exactly sure if this thing to do here. phy_stop() does not have a requirement to suspend the PHY as it is currently defined. You may want to manually suspend the PHY after a phy_stop() by explicitly calling phy_suspend().

Let me think about it some more.

Quoted 21 lines
Fixes 3c293f4e08b5 ("net: phy: Trigger state machine on state change and not polling.")
Cc stable <[email protected]> # v4.9+
---
 drivers/net/phy/phy.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/phy/phy.c +1 -0
index 49dedf8..ab14e7b 100644
@@ -907,6 +907,7 @@ void phy_stop(struct phy_device *phydev)
 	 * of rtnl_lock(), but PHY_HALTED shall guarantee phy_change()
 	 * will not reenable interrupts.
 	 */
+	phy_trigger_machine(phydev, false);
 }
 EXPORT_SYMBOL(phy_stop);
 
Signature · 1 line
Florian