net: phy: fix auto-negotiation stall due to unavailable interrupt
Subsystems (3)
PATCH 1/1 net: phy: fix auto-negotiation stall due to unavailable interrupt
Hello Florian, Roger and Madalin!
This is slightly modified version of previous patch[1].
It take into account that phy_start_aneg() may be called from differend places not only from PHY state machine. So the patch use phy_trigger_machine() to schedule link state update correctly.
I borrow some text from Roger's commit message.
Added 'Cc: stable <[email protected]> tag' because the problem exist on 4.9 and 4.10 branches.
Don't know what commit brake the code, so I don't add Fixes tag.
Roger, could you please test this one patch?
Madalin, I found, that you tested Roger’s patch[2] and this one patch will get upstream instead of patch[2]. Could you please test it?
Regards,
Alexander.
[1] http://patchwork.ozlabs.org/patch/743773/
[2] https://lkml.org/lkml/2017/3/30/517
Alexander Kochetkov (1):
net: phy: fix auto-negotiation stall due to unavailable interrupt
drivers/net/phy/phy.c | 40 ++++++++++++++++++++++++++++++++++++---- include/linux/phy.h | 1 + 2 files changed, 37 insertions(+), 4 deletions(-)
Signature · 1 line
1.7.9.5
PATCH 1/1 net: phy: fix auto-negotiation stall due to unavailable interrupt
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 patch trigger PHY state machine to update link state if PHY was requested to do auto-negotiation and auto-negotiation complete flag already set.
During power-up cycle the PHY do auto-negotiation, generate interrupt and set auto-negotiation complete flag. Interrupt is handled by PHY state machine but doesn't update link state because PHY is in PHY_READY state. After some time MAC bring up, start and request PHY to do auto-negotiation. If there are no new settings to advertise genphy_config_aneg() doesn't start PHY auto-negotiation. PHY continue to stay in auto-negotiation complete state and doesn't fire interrupt. At the same time PHY state machine expect that PHY started auto-negotiation and is waiting for interrupt from PHY and it won't get it.
--- drivers/net/phy/phy.c | 40 ++++++++++++++++++++++++++++++++++++---- include/linux/phy.h | 1 + 2 files changed, 37 insertions(+), 4 deletions(-)
drivers/net/phy/phy.c +36 -4
@@ -591,16 +591,18 @@ int phy_mii_ioctl(struct phy_device *phydev, struct ifreq *ifr, int cmd)EXPORT_SYMBOL (phy_mii_ioctl);/** -* phy_start_aneg - start auto-negotiation for this PHY device +* phy_start_aneg_priv - start auto-negotiation for this PHY device * @phydev: the phy_device struct +* @sync: indicate whether we should wait for the workqueue cancelation * * Description: Sanitizes the settings (if we're not autonegotiating * them), and then calls the driver's config_aneg function. * If the PHYCONTROL Layer is operating, we change the state to * reflect the beginning of Auto-negotiation or forcing. */ -int phy_start_aneg (struct phy_device *phydev) +static int phy_start_aneg_priv (struct phy_device *phydev,bool sync) { +bool trigger =0 ;int err;mutex_lock (&phydev->lock);
@@ -625,10 +627,40 @@ int phy_start_aneg(struct phy_device *phydev) } } +/* Re-schedule a PHY state machine to check PHY status because +* negotiation may already be done and aneg interrupt may not be +* generated. +*/ +if (phy_interrupt_is_valid (phydev) && (phydev->state ==PHY_AN )) { + err =phy_aneg_done (phydev); +if (err >0 ) { + trigger = true; + err =0 ; + } + } + out_unlock:mutex_unlock (&phydev->lock); + +if (trigger) +phy_trigger_machine (phydev, sync); +return err; } + +/** +* phy_start_aneg - start auto-negotiation for this PHY device +* @phydev: the phy_device struct +* +* Description: Sanitizes the settings (if we're not autonegotiating +* them), and then calls the driver's config_aneg function. +* If the PHYCONTROL Layer is operating, we change the state to +* reflect the beginning of Auto-negotiation or forcing. +*/ +int phy_start_aneg (struct phy_device *phydev) +{ +return phy_start_aneg_priv (phydev, true); +}EXPORT_SYMBOL (phy_start_aneg);/**
@@ -656,7 +688,7 @@ void phy_start_machine(struct phy_device *phydev)* state machine runs. */ -static void phy_trigger_machine (struct phy_device *phydev,bool sync) +void phy_trigger_machine (struct phy_device *phydev,bool sync) {if (sync)cancel_delayed_work_sync (&phydev->state_queue);
@@ -1151,7 +1183,7 @@ void phy_state_machine(struct work_struct *work)mutex_unlock (&phydev->lock);if (needs_aneg) - err =phy_start_aneg (phydev); + err =phy_start_aneg_priv (phydev, false);else if (do_suspend)phy_suspend (phydev);
include/linux/phy.h +1 -0
@@ -840,6 +840,7 @@ int phy_drivers_register(struct phy_driver *new_driver, int n,void phy_mac_interrupt (struct phy_device *phydev,int new_link);void phy_start_machine (struct phy_device *phydev);void phy_stop_machine (struct phy_device *phydev); +void phy_trigger_machine (struct phy_device *phydev,bool sync);int phy_ethtool_sset (struct phy_device *phydev,struct ethtool_cmd *cmd);int phy_ethtool_gset (struct phy_device *phydev,struct ethtool_cmd *cmd); int phy_ethtool_ksettings_get(struct phy_device *phydev,
Signature · 1 line
1.7.9.5
Hi, Alexandre!
Just found that you've fixed similar problem for Micrel PHY:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=99f81afc139c6edd14d77a91ee91685a414a1c66
Could you please test if my patch[1] fix your problem?
As reverting your patch will speedup MAC startup time for boards with Micrel PHY on 3~5 sec (auto-negotiation time[2]). Could you check that also?
Regards,
Alexander.
[1] https://lkml.org/lkml/2017/4/20/357
[2] http://www.ieee802.org/3/af/public/jan02/brown_1_0102.pdf
Quoted 123 lines
20 апр. 2017 г., в 14:00, Alexander Kochetkov <[email protected]> написал(а):
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 patch trigger PHY state machine to update link state if PHY was requested to do auto-negotiation and auto-negotiation complete flag already set.
During power-up cycle the PHY do auto-negotiation, generate interrupt and set auto-negotiation complete flag. Interrupt is handled by PHY state machine but doesn't update link state because PHY is in
PHY_READYstate. After some time MAC bring up, start and request PHY to do auto-negotiation. If there are no new settings to advertisegenphy_config_aneg()doesn't start PHY auto-negotiation. PHY continue to stay in auto-negotiation complete state and doesn't fire interrupt. At the same time PHY state machine expect that PHY started auto-negotiation and is waiting for interrupt from PHY and it won't get it.Signed-off-by Alexander Kochetkov <[email protected]>Cc stable <[email protected]> # v4.9+---
drivers/net/phy/phy.c| 40 ++++++++++++++++++++++++++++++++++++----include/linux/phy.h| 1 +2 files changed, 37 insertions(+), 4 deletions(-)drivers/net/phy/phy.c +16
-2@@ -591,16 +591,18 @@ int phy_mii_ioctl(struct phy_device *phydev, struct ifreq *ifr, int cmd)EXPORT_SYMBOL (phy_mii_ioctl);/** -* phy_start_aneg - start auto-negotiation for this PHY device +* phy_start_aneg_priv - start auto-negotiation for this PHY device * @phydev: the phy_device struct +* @sync: indicate whether we should wait for the workqueue cancelation * * Description: Sanitizes the settings (if we're not autonegotiating * them), and then calls the driver's config_aneg function. * If the PHYCONTROL Layer is operating, we change the state to * reflect the beginning of Auto-negotiation or forcing. */ -int phy_start_aneg (struct phy_device *phydev) +static int phy_start_aneg_priv (struct phy_device *phydev,bool sync) { +bool trigger =0 ;int err;mutex_lock (&phydev->lock);@@ -625,10 +627,40 @@ int phy_start_aneg(struct phy_device *phydev) } } +/* Re-schedule a PHY state machine to check PHY status because +* negotiation may already be done and aneg interrupt may not be +* generated. +*/ +if (phy_interrupt_is_valid (phydev) && (phydev->state ==PHY_AN )) { + err =phy_aneg_done (phydev); +if (err >0 ) { + trigger = true; + err =0 ; + } + } +
out_unlock:mutex_unlock(&phydev->lock);drivers/net/phy/phy.c +4
-0+ +if (trigger) +phy_trigger_machine (phydev, sync); +return err; }drivers/net/phy/phy.c +14
-0+ +/** +* phy_start_aneg - start auto-negotiation for this PHY device +* @phydev: the phy_device struct +* +* Description: Sanitizes the settings (if we're not autonegotiating +* them), and then calls the driver's config_aneg function. +* If the PHYCONTROL Layer is operating, we change the state to +* reflect the beginning of Auto-negotiation or forcing. +*/ +int phy_start_aneg (struct phy_device *phydev) +{ +return phy_start_aneg_priv (phydev, true); +}
EXPORT_SYMBOL(phy_start_aneg);/**
drivers/net/phy/phy.c +2
-2@@ -656,7 +688,7 @@ void phy_start_machine(struct phy_device *phydev)* state machine runs. */ -static void phy_trigger_machine (struct phy_device *phydev,bool sync) +void phy_trigger_machine (struct phy_device *phydev,bool sync) {if (sync)cancel_delayed_work_sync (&phydev->state_queue);@@ -1151,7 +1183,7 @@ void phy_state_machine(struct work_struct *work)mutex_unlock (&phydev->lock);if (needs_aneg) - err =phy_start_aneg (phydev); + err =phy_start_aneg_priv (phydev, false);else if (do_suspend)phy_suspend (phydev);include/linux/phy.h +1
-0@@ -840,6 +840,7 @@ int phy_drivers_register(struct phy_driver *new_driver, int n,void phy_mac_interrupt (struct phy_device *phydev,int new_link);void phy_start_machine (struct phy_device *phydev);void phy_stop_machine (struct phy_device *phydev); +void phy_trigger_machine (struct phy_device *phydev,bool sync);int phy_ethtool_sset (struct phy_device *phydev,struct ethtool_cmd *cmd);int phy_ethtool_gset (struct phy_device *phydev,struct ethtool_cmd *cmd); int phy_ethtool_ksettings_get(struct phy_device *phydev,Signature · 1 line
1.7.9.5
Quoted 15 lines · Alexander Kochetkov
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 patch trigger PHY state machine to update link state if PHY was requested to do auto-negotiation and auto-negotiation complete flag already set.
During power-up cycle the PHY do auto-negotiation, generate interrupt and set auto-negotiation complete flag. Interrupt is handled by PHY state machine but doesn't update link state because PHY is in
PHY_READYstate. After some time MAC bring up, start and request PHY to do auto-negotiation. If there are no new settings to advertisegenphy_config_aneg()doesn't start PHY auto-negotiation. PHY continue to stay in auto-negotiation complete state and doesn't fire interrupt. At the same time PHY state machine expect that PHY started auto-negotiation and is waiting for interrupt from PHY and it won't get it.
Quoted 2 lines
Signed-off-by Alexander Kochetkov <[email protected]>Cc stable <[email protected]> # v4.9+
I think the following commit broke functionality with interrupt driven PHYs 3c293f4e08b5 ("net: phy: Trigger state machine on state change and not polling.")
cheers,
-roger
Quoted 102 lines
--- drivers/net/phy/phy.c | 40 ++++++++++++++++++++++++++++++++++++---- include/linux/phy.h | 1 + 2 files changed, 37 insertions(+), 4 deletions(-)drivers/net/phy/phy.c +36
-4@@ -591,16 +591,18 @@ int phy_mii_ioctl(struct phy_device *phydev, struct ifreq *ifr, int cmd)EXPORT_SYMBOL (phy_mii_ioctl);/** -* phy_start_aneg - start auto-negotiation for this PHY device +* phy_start_aneg_priv - start auto-negotiation for this PHY device * @phydev: the phy_device struct +* @sync: indicate whether we should wait for the workqueue cancelation * * Description: Sanitizes the settings (if we're not autonegotiating * them), and then calls the driver's config_aneg function. * If the PHYCONTROL Layer is operating, we change the state to * reflect the beginning of Auto-negotiation or forcing. */ -int phy_start_aneg (struct phy_device *phydev) +static int phy_start_aneg_priv (struct phy_device *phydev,bool sync) { +bool trigger =0 ;int err;mutex_lock (&phydev->lock);@@ -625,10 +627,40 @@ int phy_start_aneg(struct phy_device *phydev) } } +/* Re-schedule a PHY state machine to check PHY status because +* negotiation may already be done and aneg interrupt may not be +* generated. +*/ +if (phy_interrupt_is_valid (phydev) && (phydev->state ==PHY_AN )) { + err =phy_aneg_done (phydev); +if (err >0 ) { + trigger = true; + err =0 ; + } + } + out_unlock:mutex_unlock (&phydev->lock); + +if (trigger) +phy_trigger_machine (phydev, sync); +return err; } + +/** +* phy_start_aneg - start auto-negotiation for this PHY device +* @phydev: the phy_device struct +* +* Description: Sanitizes the settings (if we're not autonegotiating +* them), and then calls the driver's config_aneg function. +* If the PHYCONTROL Layer is operating, we change the state to +* reflect the beginning of Auto-negotiation or forcing. +*/ +int phy_start_aneg (struct phy_device *phydev) +{ +return phy_start_aneg_priv (phydev, true); +}EXPORT_SYMBOL (phy_start_aneg);/** @@ -656,7 +688,7 @@ void phy_start_machine(struct phy_device *phydev)* state machine runs. */ -static void phy_trigger_machine (struct phy_device *phydev,bool sync) +void phy_trigger_machine (struct phy_device *phydev,bool sync) {if (sync)cancel_delayed_work_sync (&phydev->state_queue);@@ -1151,7 +1183,7 @@ void phy_state_machine(struct work_struct *work)mutex_unlock (&phydev->lock);if (needs_aneg) - err =phy_start_aneg (phydev); + err =phy_start_aneg_priv (phydev, false);else if (do_suspend)phy_suspend (phydev);include/linux/phy.h +1
-0@@ -840,6 +840,7 @@ int phy_drivers_register(struct phy_driver *new_driver, int n,void phy_mac_interrupt (struct phy_device *phydev,int new_link);void phy_start_machine (struct phy_device *phydev);void phy_stop_machine (struct phy_device *phydev); +void phy_trigger_machine (struct phy_device *phydev,bool sync);int phy_ethtool_sset (struct phy_device *phydev,struct ethtool_cmd *cmd);int phy_ethtool_gset (struct phy_device *phydev,struct ethtool_cmd *cmd); int phy_ethtool_ksettings_get(struct phy_device *phydev,
Quoted 5 lines
21 апр. 2017 г., в 17:18, Roger Quadros <[email protected]> написал(а):
I think the following commit broke functionality with interrupt driven PHYs
3c293f4e08b5("net: phy: Trigger state machine on state change and not polling.")
Probably this one[1] broke, according to Alexandre’s commit[2]. And it was since Nov 16 2015. But it was hidden by some other commits.
For Roger problem became visible after 3c293f4e08b5 ("net: phy:
Trigger state machine on state change and not polling.»),
For my problem became visible after 529ed1275263 ("net: phy: phy drivers should not set SUPPORTED_[Asym_]Pause»). As commit 529ed1275263 removed SUPPORTED_Pause flag from PHY advertising property and genphy_config_aneg() began to skip PHY auto-negotiation.
Alexander.
[1] Fixes: 321beec5047a (net: phy: Use interrupts when available in NOLINK state)
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=321beec5047af83db90c88114b7e664b156f49fe
David Miller
maintainerFrom: Alexander Kochetkov <[email protected]>
Date: Thu, 20 Apr 2017 14:00:04 +0300
Quoted 15 lines
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 patch trigger PHY state machine to update link state if PHY was requested to do auto-negotiation and auto-negotiation complete flag already set.
During power-up cycle the PHY do auto-negotiation, generate interrupt and set auto-negotiation complete flag. Interrupt is handled by PHY state machine but doesn't update link state because PHY is in
PHY_READYstate. After some time MAC bring up, start and request PHY to do auto-negotiation. If there are no new settings to advertisegenphy_config_aneg()doesn't start PHY auto-negotiation. PHY continue to stay in auto-negotiation complete state and doesn't fire interrupt. At the same time PHY state machine expect that PHY started auto-negotiation and is waiting for interrupt from PHY and it won't get it.
Quoted 2 lines
Signed-off-by Alexander Kochetkov <[email protected]>Cc stable <[email protected]> # v4.9+
So... what are we doing here?
My understanding is that this should fix the same problem that commit 99f81afc139c6edd14d77a91ee91685a414a1c66 ("phy: micrel: Disable auto negotiation on startup") fixed and that this micrel commit should thus be reverted to improve MAC startup times which regressed.
Florian, any guidance?
Hello David!
Quoted 10 lines
25 апр. 2017 г., в 17:36, David Miller <[email protected]> написал(а):
So... what are we doing here?
My understanding is that this should fix the same problem that commit
99f81afc139c6edd14d77a91ee91685a414a1c66("phy: micrel: Disable auto negotiation on startup") fixed and that this micrel commit should thus be reverted to improve MAC startup times which regressed.Florian, any guidance?
Yes, this should be done.
I aksed Alexandre to check if 99f81afc139c6edd14d77a91ee91685a414a1c66 ("phy: micrel: Disable auto negotiation on startup») can be reverted, and he answered what it may do that sometime this/next week.
Alexander.
Hi,
Quoted 11 lines · Alexander Kochetkov
Hello David!
Quoted 9 lines
25 апр. 2017 г., в 17:36, David Miller <[email protected]> написал(а):
So... what are we doing here?
My understanding is that this should fix the same problem that commit
99f81afc139c6edd14d77a91ee91685a414a1c66("phy: micrel: Disable auto negotiation on startup") fixed and that this micrel commit should thus be reverted to improve MAC startup times which regressed.
Quoted 8 lines
Quoted 1 line
Florian, any guidance?
Yes, this should be done.
I aksed Alexandre to check if
99f81afc139c6edd14d77a91ee91685a414a1c66("phy: micrel: Disable auto negotiation on startup») can be reverted, and he answered what it may do that sometime this/next week.
Yes, it can be safely reverted after Alexander's patch. I had to test on v4.7 because we are not using interrupts on those boards since v4.8 (another issue to be fixed).
As Florian pointed out, at the time I sent my patch, I didn't have time to investigate whether this was affecting other phys, see
https://lkml.org/lkml/2016/2/26/766
I can send the revert or you can do it.
Signature · 3 lines
Alexandre Belloni, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
David Miller
maintainerFrom: Alexandre Belloni <[email protected]>
Date: Tue, 25 Apr 2017 22:09:11 +0200
Quoted 27 lines
Hi,
Quoted 11 lines · Alexander Kochetkov
Hello David!
Quoted 9 lines
25 апр. 2017 г., в 17:36, David Miller <[email protected]> написал(а):
So... what are we doing here?
My understanding is that this should fix the same problem that commit
99f81afc139c6edd14d77a91ee91685a414a1c66("phy: micrel: Disable auto negotiation on startup") fixed and that this micrel commit should thus be reverted to improve MAC startup times which regressed.Quoted 8 lines
Quoted 1 line
Florian, any guidance?
Yes, this should be done.
I aksed Alexandre to check if
99f81afc139c6edd14d77a91ee91685a414a1c66("phy: micrel: Disable auto negotiation on startup») can be reverted, and he answered what it may do that sometime this/next week.Yes, it can be safely reverted after Alexander's patch. I had to test on v4.7 because we are not using interrupts on those boards since v4.8 (another issue to be fixed).
Quoted 5 lines
As Florian pointed out, at the time I sent my patch, I didn't have time to investigate whether this was affecting other phys, see
https://lkml.org/lkml/2016/2/26/766I can send the revert or you can do it.
I can take care of it, thanks for testing.
Quoted 30 lines · David Miller
From: Alexandre Belloni <[email protected]>
Date: Tue, 25 Apr 2017 22:09:11 +0200Quoted 27 lines
Hi,
Quoted 11 lines · Alexander Kochetkov
Hello David!
Quoted 9 lines
25 апр. 2017 г., в 17:36, David Miller <[email protected]> написал(а):
So... what are we doing here?
My understanding is that this should fix the same problem that commit
99f81afc139c6edd14d77a91ee91685a414a1c66("phy: micrel: Disable auto negotiation on startup") fixed and that this micrel commit should thus be reverted to improve MAC startup times which regressed.Quoted 8 lines
Quoted 1 line
Florian, any guidance?
Yes, this should be done.
I aksed Alexandre to check if
99f81afc139c6edd14d77a91ee91685a414a1c66("phy: micrel: Disable auto negotiation on startup») can be reverted, and he answered what it may do that sometime this/next week.Yes, it can be safely reverted after Alexander's patch. I had to test on v4.7 because we are not using interrupts on those boards since v4.8 (another issue to be fixed).
Quoted 7 lines
Quoted 5 lines
As Florian pointed out, at the time I sent my patch, I didn't have time to investigate whether this was affecting other phys, see
https://lkml.org/lkml/2016/2/26/766I can send the revert or you can do it.
I can take care of it, thanks for testing.
Thanks! Can you add the following Fixes tag:
state)
BTW, can you have the netdev patchwork instance automatically accepted
Fixes: tag sent as replies to patches? (just like Acked-by, Reviewed-by and so on are already accepted)?
Signature · 1 line
Florian
Quoted 27 lines · Alexandre Belloni
Hi,
Quoted 11 lines · Alexander Kochetkov
Hello David!
Quoted 9 lines
25 апр. 2017 г., в 17:36, David Miller <[email protected]> написал(а):
So... what are we doing here?
My understanding is that this should fix the same problem that commit
99f81afc139c6edd14d77a91ee91685a414a1c66("phy: micrel: Disable auto negotiation on startup") fixed and that this micrel commit should thus be reverted to improve MAC startup times which regressed.Quoted 8 lines
Quoted 1 line
Florian, any guidance?
Yes, this should be done.
I aksed Alexandre to check if
99f81afc139c6edd14d77a91ee91685a414a1c66("phy: micrel: Disable auto negotiation on startup») can be reverted, and he answered what it may do that sometime this/next week.Yes, it can be safely reverted after Alexander's patch. I had to test on v4.7 because we are not using interrupts on those boards since v4.8 (another issue to be fixed).
Quoted 6 lines
As Florian pointed out, at the time I sent my patch, I didn't have time to investigate whether this was affecting other phys, see
https://lkml.org/lkml/2016/2/26/766I can send the revert or you can do it.
I've now tested on linux-next after fixing phy interrupts in the macb driver and this also fixes the issue I was trying to solve with:
https://lkml.org/lkml/2016/4/15/786
Signature · 3 lines
Alexandre Belloni, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
From: Alexander Kochetkov <[email protected]>
Date: Thu, 20 Apr 2017 14:00:04 +0300
Quoted 15 lines
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 patch trigger PHY state machine to update link state if PHY was requested to do auto-negotiation and auto-negotiation complete flag already set.
During power-up cycle the PHY do auto-negotiation, generate interrupt and set auto-negotiation complete flag. Interrupt is handled by PHY state machine but doesn't update link state because PHY is in
PHY_READYstate. After some time MAC bring up, start and request PHY to do auto-negotiation. If there are no new settings to advertisegenphy_config_aneg()doesn't start PHY auto-negotiation. PHY continue to stay in auto-negotiation complete state and doesn't fire interrupt. At the same time PHY state machine expect that PHY started auto-negotiation and is waiting for interrupt from PHY and it won't get it.
Quoted 2 lines
Signed-off-by Alexander Kochetkov <[email protected]>Cc stable <[email protected]> # v4.9+
Applied, and I reverted the micrel commit too.
Thanks.