net: phy: fix PHY possibly unwork after MDIO bus resume back
Subsystems (4)
PATCH 1/1 net: phy: fix PHY possibly unwork after MDIO bus resume back
commit 4c0d2e96ba055 ("net: phy: consider that suspend2ram may cut off PHY power") invokes phy_init_hw() when MDIO bus resume, it will soft reset PHY if PHY driver implements soft_reset callback. commit 764d31cacfe4 ("net: phy: micrel: set soft_reset callback to genphy_soft_reset for KSZ8081") adds soft_reset for KSZ8081. After these two patches, I found i.MX6UL 14x14 EVK which connected to KSZ8081RNB doesn't work any more when system resume back, MAC driver is fec_main.c.
It's obvious that initializing PHY hardware when MDIO bus resume back would introduce some regression when PHY implements soft_reset. When I am debugging, I found PHY works fine if MAC doesn't support suspend/resume or phy_stop()/phy_start() doesn't been called during suspend/resume. This let me realize, PHY state machine phy_state_machine() could do something breaks the PHY.
As we known, MAC resume first and then MDIO bus resume when system resume back from suspend. When MAC resume, usually it will invoke phy_start() where to change PHY state to PHY_UP, then trigger the state machine to run now. In phy_state_machine(), it will start/config auto-nego, then change PHY state to PHY_NOLINK, what to next is periodically check PHY link status. When MDIO bus resume, it will initialize PHY hardware, including soft_reset, what would soft_reset affect seems various from different PHYs. For KSZ8081RNB, when it in PHY_NOLINK state and then perform a soft reset, it will never complete auto-nego.
This patch changes PHY state to PHY_UP when MDIO bus resume back, it should be reasonable after PHY hardware re-initialized. Also give state machine a chance to start/config auto-nego again.
--- drivers/net/phy/phy_device.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/net/phy/phy_device.c +7 -0
@@ -306,6 +306,13 @@ static __maybe_unused int mdio_bus_phy_resume(struct device *dev) ret =phy_resume (phydev);if (ret <0 )return ret; + +/* PHY state could be changed to PHY_NOLINK from MAC controller resume +* rounte with phy_start(), here change to PHY_UP after re-initializing +* PHY hardware, let PHY state machine to start/config auto-nego again. +*/ + phydev->state =PHY_UP ; + no_resume:if (phydev->attached_dev && phydev->adjust_link)phy_start_machine (phydev);
Signature · 1 line
2.17.1
Heiner Kallweit
maintainerQuoted 10 lines · Joakim Zhang
commit
4c0d2e96ba055("net: phy: consider that suspend2ram may cut off PHY power") invokesphy_init_hw()when MDIO bus resume, it will soft reset PHY if PHY driver implementssoft_resetcallback. commit764d31cacfe4("net: phy: micrel: setsoft_resetcallback togenphy_soft_resetfor KSZ8081") addssoft_resetfor KSZ8081. After these two patches, I found i.MX6UL 14x14 EVK which connected to KSZ8081RNB doesn't work any more when system resume back, MAC driver isfec_main.c.It's obvious that initializing PHY hardware when MDIO bus resume back would introduce some regression when PHY implements
soft_reset. When I
Why is this obvious? Please elaborate on why a soft reset should break something.
Quoted 5 lines
am debugging, I found PHY works fine if MAC doesn't support suspend/resume or phy_stop()/phy_start() doesn't been called during suspend/resume. This let me realize, PHY state machine
phy_state_machine()could do something breaks the PHY.
Quoted 9 lines
As we known, MAC resume first and then MDIO bus resume when system
resume back from suspend. When MAC resume, usually it will invokephy_start()where to change PHY state toPHY_UP, then trigger the stat> machine to run now. Inphy_state_machine(), it will start/config auto-nego, then change PHY state toPHY_NOLINK, what to next is
periodically check PHY link status. When MDIO bus resume, it will
initialize PHY hardware, includingsoft_reset, what wouldsoft_reset
affect seems various from different PHYs. For KSZ8081RNB, when it inPHY_NOLINKstate and then perform a soft reset, it will never complete
auto-nego.
Why? That would need to be checked in detail. Maybe chip errata documentation provides a hint.
Quoted 5 lines
This patch changes PHY state to
PHY_UPwhen MDIO bus resume back, it should be reasonable after PHY hardware re-initialized. Also give state machine a chance to start/config auto-nego again.
If the MAC driver calls phy_stop() on suspend, then phydev->suspended is true and mdio_bus_phy_may_suspend() returns false. As a consequence phydev->suspended_by_mdio_bus is false and mdio_bus_phy_resume() skips the PHY hw initialization.
Please also note that mdio_bus_phy_suspend() calls phy_stop_machine() that sets the state to PHY_UP.
Having said that the current argumentation isn't convincing. I'm not aware of such issues on other systems, therefore it's likely that something is system-dependent.
Please check the exact call sequence on your system, maybe it provides a hint.
Quoted 24 lines
Signed-off-by Joakim Zhang <[email protected]>--- drivers/net/phy/phy_device.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/net/phy/phy_device.c +7
-0@@ -306,6 +306,13 @@ static __maybe_unused int mdio_bus_phy_resume(struct device *dev) ret =phy_resume (phydev);if (ret <0 )return ret; + +/* PHY state could be changed to PHY_NOLINK from MAC controller resume +* rounte with phy_start(), here change to PHY_UP after re-initializing +* PHY hardware, let PHY state machine to start/config auto-nego again. +*/ + phydev->state =PHY_UP ; + no_resume:if (phydev->attached_dev && phydev->adjust_link)phy_start_machine (phydev);
Heiner Kallweit
maintainerQuoted 30 lines · Heiner Kallweit
Quoted 10 lines · Joakim Zhang
commit
4c0d2e96ba055("net: phy: consider that suspend2ram may cut off PHY power") invokesphy_init_hw()when MDIO bus resume, it will soft reset PHY if PHY driver implementssoft_resetcallback. commit764d31cacfe4("net: phy: micrel: setsoft_resetcallback togenphy_soft_resetfor KSZ8081") addssoft_resetfor KSZ8081. After these two patches, I found i.MX6UL 14x14 EVK which connected to KSZ8081RNB doesn't work any more when system resume back, MAC driver isfec_main.c.It's obvious that initializing PHY hardware when MDIO bus resume back would introduce some regression when PHY implements
soft_reset. When IWhy is this obvious? Please elaborate on why a soft reset should break something.
Quoted 5 lines
am debugging, I found PHY works fine if MAC doesn't support suspend/resume or phy_stop()/phy_start() doesn't been called during suspend/resume. This let me realize, PHY state machine
phy_state_machine()could do something breaks the PHY.Quoted 9 lines
As we known, MAC resume first and then MDIO bus resume when system
resume back from suspend. When MAC resume, usually it will invokephy_start()where to change PHY state toPHY_UP, then trigger the stat> machine to run now. Inphy_state_machine(), it will start/config auto-nego, then change PHY state toPHY_NOLINK, what to next is
periodically check PHY link status. When MDIO bus resume, it will
initialize PHY hardware, includingsoft_reset, what wouldsoft_reset
affect seems various from different PHYs. For KSZ8081RNB, when it inPHY_NOLINKstate and then perform a soft reset, it will never complete
auto-nego.
Quoted 3 lines
Why? That would need to be checked in detail. Maybe chip errata documentation provides a hint.
The KSZ8081 spec says the following about bit BMCR_PDOWN:
If software reset (Register 0.15) is
used to exit power-down mode
(Register 0.11 = 1), two software
reset writes (Register 0.15 = 1) are
required. The first write clears
power-down mode; the second
write resets the chip and re-latches
the pin strapping pin values.
Maybe this causes the issue you see and genphy_soft_reset() isn't appropriate for this PHY. Please re-test with the KSZ8081 soft reset following the spec comment.
Quoted 6 lines
Quoted 5 lines
This patch changes PHY state to
PHY_UPwhen MDIO bus resume back, it should be reasonable after PHY hardware re-initialized. Also give state machine a chance to start/config auto-nego again.
Quoted 7 lines
If the MAC driver calls
phy_stop()on suspend, thenphydev->suspendedis true andmdio_bus_phy_may_suspend()returns false. As a consequencephydev->suspended_by_mdio_busis false andmdio_bus_phy_resume()skips the PHY hw initialization.
Please also note thatmdio_bus_phy_suspend()callsphy_stop_machine()that sets the state toPHY_UP.
Forgot that MDIO bus suspend is done before MAC driver suspend. Therefore disregard this part for now.
Quoted 32 lines
Having said that the current argumentation isn't convincing. I'm not aware of such issues on other systems, therefore it's likely that something is system-dependent.
Please check the exact call sequence on your system, maybe it provides a hint.
Quoted 24 lines
Signed-off-by Joakim Zhang <[email protected]>--- drivers/net/phy/phy_device.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/net/phy/phy_device.c +7
-0@@ -306,6 +306,13 @@ static __maybe_unused int mdio_bus_phy_resume(struct device *dev) ret =phy_resume (phydev);if (ret <0 )return ret; + +/* PHY state could be changed to PHY_NOLINK from MAC controller resume +* rounte with phy_start(), here change to PHY_UP after re-initializing +* PHY hardware, let PHY state machine to start/config auto-nego again. +*/ + phydev->state =PHY_UP ; + no_resume:if (phydev->attached_dev && phydev->adjust_link)phy_start_machine (phydev);
Quoted 46 lines · Heiner Kallweit
Quoted 30 lines · Heiner Kallweit
Quoted 10 lines · Joakim Zhang
commit
4c0d2e96ba055("net: phy: consider that suspend2ram may cut off PHY power") invokesphy_init_hw()when MDIO bus resume, it will soft reset PHY if PHY driver implementssoft_resetcallback. commit764d31cacfe4("net: phy: micrel: setsoft_resetcallback togenphy_soft_resetfor KSZ8081") addssoft_resetfor KSZ8081. After these two patches, I found i.MX6UL 14x14 EVK which connected to KSZ8081RNB doesn't work any more when system resume back, MAC driver isfec_main.c.It's obvious that initializing PHY hardware when MDIO bus resume back would introduce some regression when PHY implements
soft_reset. When IWhy is this obvious? Please elaborate on why a soft reset should break something.
Quoted 5 lines
am debugging, I found PHY works fine if MAC doesn't support suspend/resume or phy_stop()/phy_start() doesn't been called during suspend/resume. This let me realize, PHY state machine
phy_state_machine()could do something breaks the PHY.Quoted 9 lines
As we known, MAC resume first and then MDIO bus resume when system
resume back from suspend. When MAC resume, usually it will invokephy_start()where to change PHY state toPHY_UP, then trigger the stat> machine to run now. Inphy_state_machine(), it will start/config auto-nego, then change PHY state toPHY_NOLINK, what to next is
periodically check PHY link status. When MDIO bus resume, it will
initialize PHY hardware, includingsoft_reset, what wouldsoft_reset
affect seems various from different PHYs. For KSZ8081RNB, when it inPHY_NOLINKstate and then perform a soft reset, it will never complete
auto-nego.Quoted 3 lines
Why? That would need to be checked in detail. Maybe chip errata documentation provides a hint.
The KSZ8081 spec says the following about bit
BMCR_PDOWN:If software reset (Register 0.15) is
used to exit power-down mode
(Register 0.11 = 1), two software
reset writes (Register 0.15 = 1) are
required. The first write clears
power-down mode; the second
write resets the chip and re-latches
the pin strapping pin values.
Quoted 4 lines
Maybe this causes the issue you see and
genphy_soft_reset()isn't appropriate for this PHY. Please re-test with the KSZ8081 soft reset following the spec comment.
Interesting. Never expected that behavior.
Thanks for catching it. Skimmed through the datasheets/erratas. This is what I found (micrel.c):
10/100:
8001 - Unaffected?
8021/8031 - Double reset after PDOWN.
8041 - Errata. PDOWN broken. Recommended do not use. Unclear if reset solves the issue since errata says no error after reset but is also claiming that only toggling PDOWN (may) or power will help. 8051 - Double reset after PDOWN.
8061 - Double reset after PDOWN.
8081 - Double reset after PDOWN.
8091 - Double reset after PDOWN.
10/100/1000:
Nothing in gigabit afaics.
Switches:
8862 - Not affected?
8863 - Errata. PDOWN broken. Reset will not help. Workaround exists. 8864 - Not affected?
8873 - Errata. PDOWN broken. Reset will not help. Workaround exists. 9477 - Errata. PDOWN broken. Will randomly cause link failure on adjacent links. Do not use.
This certainly explains a lot.
Quoted 50 lines
Quoted 6 lines
Quoted 5 lines
This patch changes PHY state to
PHY_UPwhen MDIO bus resume back, it should be reasonable after PHY hardware re-initialized. Also give state machine a chance to start/config auto-nego again.Quoted 7 lines
If the MAC driver calls
phy_stop()on suspend, thenphydev->suspendedis true andmdio_bus_phy_may_suspend()returns false. As a consequencephydev->suspended_by_mdio_busis false andmdio_bus_phy_resume()skips the PHY hw initialization.
Please also note thatmdio_bus_phy_suspend()callsphy_stop_machine()that sets the state toPHY_UP.Forgot that MDIO bus suspend is done before MAC driver suspend. Therefore disregard this part for now.
Quoted 32 lines
Having said that the current argumentation isn't convincing. I'm not aware of such issues on other systems, therefore it's likely that something is system-dependent.
Please check the exact call sequence on your system, maybe it provides a hint.
Quoted 24 lines
Signed-off-by Joakim Zhang <[email protected]>--- drivers/net/phy/phy_device.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/net/phy/phy_device.c +7
-0@@ -306,6 +306,13 @@ static __maybe_unused int mdio_bus_phy_resume(struct device *dev) ret =phy_resume (phydev);if (ret <0 )return ret; + +/* PHY state could be changed to PHY_NOLINK from MAC controller resume +* rounte with phy_start(), here change to PHY_UP after re-initializing +* PHY hardware, let PHY state machine to start/config auto-nego again. +*/ + phydev->state =PHY_UP ; + no_resume:if (phydev->attached_dev && phydev->adjust_link)phy_start_machine (phydev);
Heiner Kallweit
maintainerQuoted 78 lines · Christian Melki
Quoted 46 lines · Heiner Kallweit
Quoted 30 lines · Heiner Kallweit
Quoted 10 lines · Joakim Zhang
commit
4c0d2e96ba055("net: phy: consider that suspend2ram may cut off PHY power") invokesphy_init_hw()when MDIO bus resume, it will soft reset PHY if PHY driver implementssoft_resetcallback. commit764d31cacfe4("net: phy: micrel: setsoft_resetcallback togenphy_soft_resetfor KSZ8081") addssoft_resetfor KSZ8081. After these two patches, I found i.MX6UL 14x14 EVK which connected to KSZ8081RNB doesn't work any more when system resume back, MAC driver isfec_main.c.It's obvious that initializing PHY hardware when MDIO bus resume back would introduce some regression when PHY implements
soft_reset. When IWhy is this obvious? Please elaborate on why a soft reset should break something.
Quoted 5 lines
am debugging, I found PHY works fine if MAC doesn't support suspend/resume or phy_stop()/phy_start() doesn't been called during suspend/resume. This let me realize, PHY state machine
phy_state_machine()could do something breaks the PHY.Quoted 9 lines
As we known, MAC resume first and then MDIO bus resume when system
resume back from suspend. When MAC resume, usually it will invokephy_start()where to change PHY state toPHY_UP, then trigger the stat> machine to run now. Inphy_state_machine(), it will start/config auto-nego, then change PHY state toPHY_NOLINK, what to next is
periodically check PHY link status. When MDIO bus resume, it will
initialize PHY hardware, includingsoft_reset, what wouldsoft_reset
affect seems various from different PHYs. For KSZ8081RNB, when it inPHY_NOLINKstate and then perform a soft reset, it will never complete
auto-nego.Quoted 3 lines
Why? That would need to be checked in detail. Maybe chip errata documentation provides a hint.
The KSZ8081 spec says the following about bit
BMCR_PDOWN:If software reset (Register 0.15) is
used to exit power-down mode
(Register 0.11 = 1), two software
reset writes (Register 0.15 = 1) are
required. The first write clears
power-down mode; the second
write resets the chip and re-latches
the pin strapping pin values.Quoted 4 lines
Maybe this causes the issue you see and
genphy_soft_reset()isn't appropriate for this PHY. Please re-test with the KSZ8081 soft reset following the spec comment.Interesting. Never expected that behavior.
Thanks for catching it. Skimmed through the datasheets/erratas. This is what I found (micrel.c):10/100:
8001 - Unaffected?
8021/8031 - Double reset after PDOWN.
8041 - Errata. PDOWN broken. Recommended do not use. Unclear if reset solves the issue since errata says no error after reset but is also claiming that only toggling PDOWN (may) or power will help. 8051 - Double reset after PDOWN.
8061 - Double reset after PDOWN.
8081 - Double reset after PDOWN.
8091 - Double reset after PDOWN.10/100/1000:
Nothing in gigabit afaics.Switches:
8862 - Not affected?
8863 - Errata. PDOWN broken. Reset will not help. Workaround exists. 8864 - Not affected?
8873 - Errata. PDOWN broken. Reset will not help. Workaround exists. 9477 - Errata. PDOWN broken. Will randomly cause link failure on adjacent links. Do not use.
Quoted 53 lines
This certainly explains a lot.
Quoted 50 lines
Quoted 6 lines
Quoted 5 lines
This patch changes PHY state to
PHY_UPwhen MDIO bus resume back, it should be reasonable after PHY hardware re-initialized. Also give state machine a chance to start/config auto-nego again.Quoted 7 lines
If the MAC driver calls
phy_stop()on suspend, thenphydev->suspendedis true andmdio_bus_phy_may_suspend()returns false. As a consequencephydev->suspended_by_mdio_busis false andmdio_bus_phy_resume()skips the PHY hw initialization.
Please also note thatmdio_bus_phy_suspend()callsphy_stop_machine()that sets the state toPHY_UP.Forgot that MDIO bus suspend is done before MAC driver suspend. Therefore disregard this part for now.
Quoted 32 lines
Having said that the current argumentation isn't convincing. I'm not aware of such issues on other systems, therefore it's likely that something is system-dependent.
Please check the exact call sequence on your system, maybe it provides a hint.
Quoted 24 lines
Signed-off-by Joakim Zhang <[email protected]>--- drivers/net/phy/phy_device.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/net/phy/phy_device.c +7
-0@@ -306,6 +306,13 @@ static __maybe_unused int mdio_bus_phy_resume(struct device *dev) ret =phy_resume (phydev);if (ret <0 )return ret; + +/* PHY state could be changed to PHY_NOLINK from MAC controller resume +* rounte with phy_start(), here change to PHY_UP after re-initializing +* PHY hardware, let PHY state machine to start/config auto-nego again. +*/ + phydev->state =PHY_UP ; + no_resume:if (phydev->attached_dev && phydev->adjust_link)phy_start_machine (phydev);
This is a quick draft of the modified soft reset for KSZ8081. Some tests would be appreciated.
drivers/net/phy/micrel.c +37 -1
@@ -1091,6 +1091,42 @@ static void kszphy_get_stats(struct phy_device *phydev, data[i] =kszphy_get_stat (phydev, i); } +int ksz8081_soft_reset (struct phy_device *phydev) +{ +int bmcr, ret, val; + +phy_lock_mdio_bus (phydev); + + bmcr =__phy_read (phydev,MII_BMCR ); +if (bmcr <0 ) +return bmcr; + + bmcr |=BMCR_RESET ; + +if (bmcr &BMCR_PDOWN ) +__phy_write (phydev,MII_BMCR , bmcr); + +if (phydev->autoneg ==AUTONEG_ENABLE ) + bmcr |=BMCR_ANRESTART ; + +__phy_write (phydev,MII_BMCR , bmcr & ~BMCR_ISOLATE ); + +phy_unlock_mdio_bus (phydev); + + phydev->suspended =0 ; + + ret =phy_read_poll_timeout (phydev,MII_BMCR , val, !(val &BMCR_RESET ), +50000 ,600000 , true); +if (ret) +return ret; + +/* BMCR may be reset to defaults */ +if (phydev->autoneg ==AUTONEG_DISABLE ) + ret =genphy_setup_forced (phydev); + +return ret; +} +static int kszphy_suspend (struct phy_device *phydev) {/* Disable PHY Interrupts */
@@ -1303,7 +1339,7 @@ static struct phy_driver ksphy_driver[] = { .driver_data = &ksz8081_type, .probe = kszphy_probe, .config_init = ksz8081_config_init, - .soft_reset = genphy_soft_reset, + .soft_reset = ksz8081_soft_reset, .config_intr = kszphy_config_intr, .handle_interrupt = kszphy_handle_interrupt, .get_sset_count = kszphy_get_sset_count,
Signature · 1 line
2.31.1
Quoted 155 lines · Heiner Kallweit
Quoted 78 lines · Christian Melki
Quoted 46 lines · Heiner Kallweit
Quoted 30 lines · Heiner Kallweit
Quoted 10 lines · Joakim Zhang
commit
4c0d2e96ba055("net: phy: consider that suspend2ram may cut off PHY power") invokesphy_init_hw()when MDIO bus resume, it will soft reset PHY if PHY driver implementssoft_resetcallback. commit764d31cacfe4("net: phy: micrel: setsoft_resetcallback togenphy_soft_resetfor KSZ8081") addssoft_resetfor KSZ8081. After these two patches, I found i.MX6UL 14x14 EVK which connected to KSZ8081RNB doesn't work any more when system resume back, MAC driver isfec_main.c.It's obvious that initializing PHY hardware when MDIO bus resume back would introduce some regression when PHY implements
soft_reset. When IWhy is this obvious? Please elaborate on why a soft reset should break something.
Quoted 5 lines
am debugging, I found PHY works fine if MAC doesn't support suspend/resume or phy_stop()/phy_start() doesn't been called during suspend/resume. This let me realize, PHY state machine
phy_state_machine()could do something breaks the PHY.Quoted 9 lines
As we known, MAC resume first and then MDIO bus resume when system
resume back from suspend. When MAC resume, usually it will invokephy_start()where to change PHY state toPHY_UP, then trigger the stat> machine to run now. Inphy_state_machine(), it will start/config auto-nego, then change PHY state toPHY_NOLINK, what to next is
periodically check PHY link status. When MDIO bus resume, it will
initialize PHY hardware, includingsoft_reset, what wouldsoft_reset
affect seems various from different PHYs. For KSZ8081RNB, when it inPHY_NOLINKstate and then perform a soft reset, it will never complete
auto-nego.Quoted 3 lines
Why? That would need to be checked in detail. Maybe chip errata documentation provides a hint.
The KSZ8081 spec says the following about bit
BMCR_PDOWN:If software reset (Register 0.15) is
used to exit power-down mode
(Register 0.11 = 1), two software
reset writes (Register 0.15 = 1) are
required. The first write clears
power-down mode; the second
write resets the chip and re-latches
the pin strapping pin values.Quoted 4 lines
Maybe this causes the issue you see and
genphy_soft_reset()isn't appropriate for this PHY. Please re-test with the KSZ8081 soft reset following the spec comment.Interesting. Never expected that behavior.
Thanks for catching it. Skimmed through the datasheets/erratas. This is what I found (micrel.c):10/100:
8001 - Unaffected?
8021/8031 - Double reset after PDOWN.
8041 - Errata. PDOWN broken. Recommended do not use. Unclear if reset solves the issue since errata says no error after reset but is also claiming that only toggling PDOWN (may) or power will help. 8051 - Double reset after PDOWN.
8061 - Double reset after PDOWN.
8081 - Double reset after PDOWN.
8091 - Double reset after PDOWN.10/100/1000:
Nothing in gigabit afaics.Switches:
8862 - Not affected?
8863 - Errata. PDOWN broken. Reset will not help. Workaround exists. 8864 - Not affected?
8873 - Errata. PDOWN broken. Reset will not help. Workaround exists. 9477 - Errata. PDOWN broken. Will randomly cause link failure on adjacent links. Do not use.Quoted 53 lines
This certainly explains a lot.
Quoted 50 lines
Quoted 6 lines
Quoted 5 lines
This patch changes PHY state to
PHY_UPwhen MDIO bus resume back, it should be reasonable after PHY hardware re-initialized. Also give state machine a chance to start/config auto-nego again.Quoted 7 lines
If the MAC driver calls
phy_stop()on suspend, thenphydev->suspendedis true andmdio_bus_phy_may_suspend()returns false. As a consequencephydev->suspended_by_mdio_busis false andmdio_bus_phy_resume()skips the PHY hw initialization.
Please also note thatmdio_bus_phy_suspend()callsphy_stop_machine()that sets the state toPHY_UP.Forgot that MDIO bus suspend is done before MAC driver suspend. Therefore disregard this part for now.
Quoted 32 lines
Having said that the current argumentation isn't convincing. I'm not aware of such issues on other systems, therefore it's likely that something is system-dependent.
Please check the exact call sequence on your system, maybe it provides a hint.
Quoted 24 lines
Signed-off-by Joakim Zhang <[email protected]>--- drivers/net/phy/phy_device.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/net/phy/phy_device.c +7
-0@@ -306,6 +306,13 @@ static __maybe_unused int mdio_bus_phy_resume(struct device *dev) ret =phy_resume (phydev);if (ret <0 )return ret; + +/* PHY state could be changed to PHY_NOLINK from MAC controller resume +* rounte with phy_start(), here change to PHY_UP after re-initializing +* PHY hardware, let PHY state machine to start/config auto-nego again. +*/ + phydev->state =PHY_UP ; + no_resume:if (phydev->attached_dev && phydev->adjust_link)phy_start_machine (phydev);This is a quick draft of the modified soft reset for KSZ8081. Some tests would be appreciated.
drivers/net/phy/micrel.c +10
-0@@ -1091,6 +1091,42 @@ static void kszphy_get_stats(struct phy_device *phydev, data[i] =kszphy_get_stat (phydev, i); } +int ksz8081_soft_reset (struct phy_device *phydev) +{ +int bmcr, ret, val; + +phy_lock_mdio_bus (phydev); + + bmcr =__phy_read (phydev,MII_BMCR ); +if (bmcr <0 ) +return bmcr; +
drivers/net/phy/micrel.c static void kszphy_get_stats(struct phy_device *phydev, · line 1113
Quoted 10 lines
drivers/net/phy/micrel.c +10
-0+ bmcr |=BMCR_RESET ; + +if (bmcr &BMCR_PDOWN ) +__phy_write (phydev,MII_BMCR , bmcr); + +if (phydev->autoneg ==AUTONEG_ENABLE ) + bmcr |=BMCR_ANRESTART ; + +__phy_write (phydev,MII_BMCR , bmcr & ~BMCR_ISOLATE ); +
Wouldn't this re-set BMCR_PDOWN?
Since this is probably required by a few other micrel phys, maybe a kszphy_type flag and continue with genphy_soft_reset?
Quoted 29 lines
drivers/net/phy/micrel.c +17
-1+phy_unlock_mdio_bus (phydev); + + phydev->suspended =0 ; + + ret =phy_read_poll_timeout (phydev,MII_BMCR , val, !(val &BMCR_RESET ), +50000 ,600000 , true); +if (ret) +return ret; + +/* BMCR may be reset to defaults */ +if (phydev->autoneg ==AUTONEG_DISABLE ) + ret =genphy_setup_forced (phydev); + +return ret; +} +static int kszphy_suspend (struct phy_device *phydev) {/* Disable PHY Interrupts */ @@ -1303,7 +1339,7 @@ static struct phy_driver ksphy_driver[] = { .driver_data = &ksz8081_type, .probe = kszphy_probe, .config_init = ksz8081_config_init, - .soft_reset = genphy_soft_reset, + .soft_reset = ksz8081_soft_reset, .config_intr = kszphy_config_intr, .handle_interrupt = kszphy_handle_interrupt, .get_sset_count = kszphy_get_sset_count,
Heiner Kallweit
maintainerQuoted 160 lines · Christian Melki
Quoted 159 lines · Heiner Kallweit
Quoted 78 lines · Christian Melki
Quoted 46 lines · Heiner Kallweit
Quoted 30 lines · Heiner Kallweit
Quoted 10 lines · Joakim Zhang
commit
4c0d2e96ba055("net: phy: consider that suspend2ram may cut off PHY power") invokesphy_init_hw()when MDIO bus resume, it will soft reset PHY if PHY driver implementssoft_resetcallback. commit764d31cacfe4("net: phy: micrel: setsoft_resetcallback togenphy_soft_resetfor KSZ8081") addssoft_resetfor KSZ8081. After these two patches, I found i.MX6UL 14x14 EVK which connected to KSZ8081RNB doesn't work any more when system resume back, MAC driver isfec_main.c.It's obvious that initializing PHY hardware when MDIO bus resume back would introduce some regression when PHY implements
soft_reset. When IWhy is this obvious? Please elaborate on why a soft reset should break something.
Quoted 5 lines
am debugging, I found PHY works fine if MAC doesn't support suspend/resume or phy_stop()/phy_start() doesn't been called during suspend/resume. This let me realize, PHY state machine
phy_state_machine()could do something breaks the PHY.Quoted 9 lines
As we known, MAC resume first and then MDIO bus resume when system
resume back from suspend. When MAC resume, usually it will invokephy_start()where to change PHY state toPHY_UP, then trigger the stat> machine to run now. Inphy_state_machine(), it will start/config auto-nego, then change PHY state toPHY_NOLINK, what to next is
periodically check PHY link status. When MDIO bus resume, it will
initialize PHY hardware, includingsoft_reset, what wouldsoft_reset
affect seems various from different PHYs. For KSZ8081RNB, when it inPHY_NOLINKstate and then perform a soft reset, it will never complete
auto-nego.Quoted 3 lines
Why? That would need to be checked in detail. Maybe chip errata documentation provides a hint.
The KSZ8081 spec says the following about bit
BMCR_PDOWN:If software reset (Register 0.15) is
used to exit power-down mode
(Register 0.11 = 1), two software
reset writes (Register 0.15 = 1) are
required. The first write clears
power-down mode; the second
write resets the chip and re-latches
the pin strapping pin values.Quoted 4 lines
Maybe this causes the issue you see and
genphy_soft_reset()isn't appropriate for this PHY. Please re-test with the KSZ8081 soft reset following the spec comment.Interesting. Never expected that behavior.
Thanks for catching it. Skimmed through the datasheets/erratas. This is what I found (micrel.c):10/100:
8001 - Unaffected?
8021/8031 - Double reset after PDOWN.
8041 - Errata. PDOWN broken. Recommended do not use. Unclear if reset solves the issue since errata says no error after reset but is also claiming that only toggling PDOWN (may) or power will help. 8051 - Double reset after PDOWN.
8061 - Double reset after PDOWN.
8081 - Double reset after PDOWN.
8091 - Double reset after PDOWN.10/100/1000:
Nothing in gigabit afaics.Switches:
8862 - Not affected?
8863 - Errata. PDOWN broken. Reset will not help. Workaround exists. 8864 - Not affected?
8873 - Errata. PDOWN broken. Reset will not help. Workaround exists. 9477 - Errata. PDOWN broken. Will randomly cause link failure on adjacent links. Do not use.Quoted 53 lines
This certainly explains a lot.
Quoted 50 lines
Quoted 6 lines
Quoted 5 lines
This patch changes PHY state to
PHY_UPwhen MDIO bus resume back, it should be reasonable after PHY hardware re-initialized. Also give state machine a chance to start/config auto-nego again.Quoted 7 lines
If the MAC driver calls
phy_stop()on suspend, thenphydev->suspendedis true andmdio_bus_phy_may_suspend()returns false. As a consequencephydev->suspended_by_mdio_busis false andmdio_bus_phy_resume()skips the PHY hw initialization.
Please also note thatmdio_bus_phy_suspend()callsphy_stop_machine()that sets the state toPHY_UP.Forgot that MDIO bus suspend is done before MAC driver suspend. Therefore disregard this part for now.
Quoted 32 lines
Having said that the current argumentation isn't convincing. I'm not aware of such issues on other systems, therefore it's likely that something is system-dependent.
Please check the exact call sequence on your system, maybe it provides a hint.
Quoted 24 lines
Signed-off-by Joakim Zhang <[email protected]>--- drivers/net/phy/phy_device.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/net/phy/phy_device.c +7
-0@@ -306,6 +306,13 @@ static __maybe_unused int mdio_bus_phy_resume(struct device *dev) ret =phy_resume (phydev);if (ret <0 )return ret; + +/* PHY state could be changed to PHY_NOLINK from MAC controller resume +* rounte with phy_start(), here change to PHY_UP after re-initializing +* PHY hardware, let PHY state machine to start/config auto-nego again. +*/ + phydev->state =PHY_UP ; + no_resume:if (phydev->attached_dev && phydev->adjust_link)phy_start_machine (phydev);This is a quick draft of the modified soft reset for KSZ8081. Some tests would be appreciated.
drivers/net/phy/micrel.c +14
-0@@ -1091,6 +1091,42 @@ static void kszphy_get_stats(struct phy_device *phydev, data[i] =kszphy_get_stat (phydev, i); } +int ksz8081_soft_reset (struct phy_device *phydev) +{ +int bmcr, ret, val; + +phy_lock_mdio_bus (phydev); + + bmcr =__phy_read (phydev,MII_BMCR ); +if (bmcr <0 ) +return bmcr; + + bmcr |=BMCR_RESET ; + +if (bmcr &BMCR_PDOWN ) +__phy_write (phydev,MII_BMCR , bmcr);
Quoted 8 lines
drivers/net/phy/micrel.c static void kszphy_get_stats(struct phy_device *phydev, · line 1113
Quoted 6 lines
drivers/net/phy/micrel.c +6
-0+ +if (phydev->autoneg ==AUTONEG_ENABLE ) + bmcr |=BMCR_ANRESTART ; + +__phy_write (phydev,MII_BMCR , bmcr & ~BMCR_ISOLATE ); +Wouldn't this re-set
BMCR_PDOWN?
No. A soft reset is supposed to reset all bits to their defaults. Therefore power-down bit should be cleared.
See genphy_soft_reset(), there we do it the same way.
Quoted 3 lines
Since this is probably required by a few other micrel phys, maybe a
kszphy_typeflag and continue withgenphy_soft_reset?
It seems only Micrel PHY's have this quirky behavior, therefore I'd like to keep the special soft reset handling in the Micrel PHY driver. But yes, we would have to switch more Micrel PHY drivers to the new soft reset callback.
Quoted 30 lines
Quoted 29 lines
drivers/net/phy/micrel.c +17
-1+phy_unlock_mdio_bus (phydev); + + phydev->suspended =0 ; + + ret =phy_read_poll_timeout (phydev,MII_BMCR , val, !(val &BMCR_RESET ), +50000 ,600000 , true); +if (ret) +return ret; + +/* BMCR may be reset to defaults */ +if (phydev->autoneg ==AUTONEG_DISABLE ) + ret =genphy_setup_forced (phydev); + +return ret; +} +static int kszphy_suspend (struct phy_device *phydev) {/* Disable PHY Interrupts */ @@ -1303,7 +1339,7 @@ static struct phy_driver ksphy_driver[] = { .driver_data = &ksz8081_type, .probe = kszphy_probe, .config_init = ksz8081_config_init, - .soft_reset = genphy_soft_reset, + .soft_reset = ksz8081_soft_reset, .config_intr = kszphy_config_intr, .handle_interrupt = kszphy_handle_interrupt, .get_sset_count = kszphy_get_sset_count,
Quoted 170 lines · Heiner Kallweit
Quoted 160 lines · Christian Melki
Quoted 159 lines · Heiner Kallweit
Quoted 78 lines · Christian Melki
Quoted 46 lines · Heiner Kallweit
Quoted 30 lines · Heiner Kallweit
Quoted 10 lines · Joakim Zhang
commit
4c0d2e96ba055("net: phy: consider that suspend2ram may cut off PHY power") invokesphy_init_hw()when MDIO bus resume, it will soft reset PHY if PHY driver implementssoft_resetcallback. commit764d31cacfe4("net: phy: micrel: setsoft_resetcallback togenphy_soft_resetfor KSZ8081") addssoft_resetfor KSZ8081. After these two patches, I found i.MX6UL 14x14 EVK which connected to KSZ8081RNB doesn't work any more when system resume back, MAC driver isfec_main.c.It's obvious that initializing PHY hardware when MDIO bus resume back would introduce some regression when PHY implements
soft_reset. When IWhy is this obvious? Please elaborate on why a soft reset should break something.
Quoted 5 lines
am debugging, I found PHY works fine if MAC doesn't support suspend/resume or phy_stop()/phy_start() doesn't been called during suspend/resume. This let me realize, PHY state machine
phy_state_machine()could do something breaks the PHY.Quoted 9 lines
As we known, MAC resume first and then MDIO bus resume when system
resume back from suspend. When MAC resume, usually it will invokephy_start()where to change PHY state toPHY_UP, then trigger the stat> machine to run now. Inphy_state_machine(), it will start/config auto-nego, then change PHY state toPHY_NOLINK, what to next is
periodically check PHY link status. When MDIO bus resume, it will
initialize PHY hardware, includingsoft_reset, what wouldsoft_reset
affect seems various from different PHYs. For KSZ8081RNB, when it inPHY_NOLINKstate and then perform a soft reset, it will never complete
auto-nego.Quoted 3 lines
Why? That would need to be checked in detail. Maybe chip errata documentation provides a hint.
The KSZ8081 spec says the following about bit
BMCR_PDOWN:If software reset (Register 0.15) is
used to exit power-down mode
(Register 0.11 = 1), two software
reset writes (Register 0.15 = 1) are
required. The first write clears
power-down mode; the second
write resets the chip and re-latches
the pin strapping pin values.Quoted 4 lines
Maybe this causes the issue you see and
genphy_soft_reset()isn't appropriate for this PHY. Please re-test with the KSZ8081 soft reset following the spec comment.Interesting. Never expected that behavior.
Thanks for catching it. Skimmed through the datasheets/erratas. This is what I found (micrel.c):10/100:
8001 - Unaffected?
8021/8031 - Double reset after PDOWN.
8041 - Errata. PDOWN broken. Recommended do not use. Unclear if reset solves the issue since errata says no error after reset but is also claiming that only toggling PDOWN (may) or power will help. 8051 - Double reset after PDOWN.
8061 - Double reset after PDOWN.
8081 - Double reset after PDOWN.
8091 - Double reset after PDOWN.10/100/1000:
Nothing in gigabit afaics.Switches:
8862 - Not affected?
8863 - Errata. PDOWN broken. Reset will not help. Workaround exists. 8864 - Not affected?
8873 - Errata. PDOWN broken. Reset will not help. Workaround exists. 9477 - Errata. PDOWN broken. Will randomly cause link failure on adjacent links. Do not use.Quoted 53 lines
This certainly explains a lot.
Quoted 50 lines
Quoted 6 lines
Quoted 5 lines
This patch changes PHY state to
PHY_UPwhen MDIO bus resume back, it should be reasonable after PHY hardware re-initialized. Also give state machine a chance to start/config auto-nego again.Quoted 7 lines
If the MAC driver calls
phy_stop()on suspend, thenphydev->suspendedis true andmdio_bus_phy_may_suspend()returns false. As a consequencephydev->suspended_by_mdio_busis false andmdio_bus_phy_resume()skips the PHY hw initialization.
Please also note thatmdio_bus_phy_suspend()callsphy_stop_machine()that sets the state toPHY_UP.Forgot that MDIO bus suspend is done before MAC driver suspend. Therefore disregard this part for now.
Quoted 32 lines
Having said that the current argumentation isn't convincing. I'm not aware of such issues on other systems, therefore it's likely that something is system-dependent.
Please check the exact call sequence on your system, maybe it provides a hint.
Quoted 24 lines
Signed-off-by Joakim Zhang <[email protected]>--- drivers/net/phy/phy_device.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/net/phy/phy_device.c +7
-0@@ -306,6 +306,13 @@ static __maybe_unused int mdio_bus_phy_resume(struct device *dev) ret =phy_resume (phydev);if (ret <0 )return ret; + +/* PHY state could be changed to PHY_NOLINK from MAC controller resume +* rounte with phy_start(), here change to PHY_UP after re-initializing +* PHY hardware, let PHY state machine to start/config auto-nego again. +*/ + phydev->state =PHY_UP ; + no_resume:if (phydev->attached_dev && phydev->adjust_link)phy_start_machine (phydev);This is a quick draft of the modified soft reset for KSZ8081. Some tests would be appreciated.
drivers/net/phy/micrel.c +14
-0@@ -1091,6 +1091,42 @@ static void kszphy_get_stats(struct phy_device *phydev, data[i] =kszphy_get_stat (phydev, i); } +int ksz8081_soft_reset (struct phy_device *phydev) +{ +int bmcr, ret, val; + +phy_lock_mdio_bus (phydev); + + bmcr =__phy_read (phydev,MII_BMCR ); +if (bmcr <0 ) +return bmcr; + + bmcr |=BMCR_RESET ; + +if (bmcr &BMCR_PDOWN ) +__phy_write (phydev,MII_BMCR , bmcr);Quoted 8 lines
drivers/net/phy/micrel.c static void kszphy_get_stats(struct phy_device *phydev, · line 1113
Quoted 6 lines
drivers/net/phy/micrel.c +6
-0+ +if (phydev->autoneg ==AUTONEG_ENABLE ) + bmcr |=BMCR_ANRESTART ; + +__phy_write (phydev,MII_BMCR , bmcr & ~BMCR_ISOLATE ); +Wouldn't this re-set
BMCR_PDOWN?
Quoted 1 line
No. A soft reset is supposed to reset all bits to their defaults.
FWIW, this behavior is not universally accepted by PHY vendors and some take liberties in how BMCR_RESET is implemented.
Signature · 1 line
Florian
Hi Heiner,
Quoted 153 lines
-----Original Message-----
From: Heiner Kallweit <[email protected]>
Sent: 2021年4月5日 20:10
To: [email protected]; Joakim Zhang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: Re: [PATCH] net: phy: fix PHY possibly unwork after MDIO bus resume backQuoted 10 lines · Christian Melki
Quoted 9 lines · Heiner Kallweit
Quoted 8 lines · Heiner Kallweit
Quoted 7 lines · Joakim Zhang
commit
4c0d2e96ba055("net: phy: consider that suspend2ram may cut off PHY power") invokesphy_init_hw()when MDIO bus resume, it will soft reset PHY if PHY driver implementssoft_resetcallback. commit764d31cacfe4("net: phy: micrel: setsoft_resetcallback togenphy_soft_resetfor KSZ8081") addssoft_resetfor KSZ8081. After these two patches, I found i.MX6UL 14x14 EVK which connected to KSZ8081RNB doesn't work any more when system resume back, MACdriver is
fec_main.c.Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 4 lines
It's obvious that initializing PHY hardware when MDIO bus resume back would introduce some regression when PHY implements
soft_reset. When IWhy is this obvious? Please elaborate on why a soft reset should break something.
Quoted 5 lines
am debugging, I found PHY works fine if MAC doesn't support suspend/resume or phy_stop()/phy_start() doesn't been called during suspend/resume. This let me realize, PHY state machine
phy_state_machine()could do something breaks the PHY.Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
As we known, MAC resume first and then MDIO bus resume when system resume back from suspend. When MAC resume, usually it will invoke
phy_start()where to change PHY state toPHY_UP, then trigger the stat> machine to run now. Inphy_state_machine(), it will start/config auto-nego, then change PHY state toPHY_NOLINK, what to next is periodically check PHY link status. When MDIO bus resume, it will initialize PHY hardware, includingsoft_reset, what wouldsoft_resetaffect seems various from different PHYs. For KSZ8081RNB, when it inPHY_NOLINKstate and then perform a soft reset,it will never complete auto-nego.
Quoted 79 lines
Quoted 16 lines
Quoted 4 lines
Why? That would need to be checked in detail. Maybe chip errata documentation provides a hint.
The KSZ8081 spec says the following about bit
BMCR_PDOWN:If software reset (Register 0.15) is
used to exit power-down mode
(Register 0.11 = 1), two software
reset writes (Register 0.15 = 1) are
required. The first write clears
power-down mode; the second
write resets the chip and re-latches
the pin strapping pin values.Quoted 4 lines
Maybe this causes the issue you see and
genphy_soft_reset()isn't appropriate for this PHY. Please re-test with the KSZ8081 soft reset following the spec comment.Interesting. Never expected that behavior.
Thanks for catching it. Skimmed through the datasheets/erratas. This is what I found (micrel.c):10/100:
8001 - Unaffected?
8021/8031 - Double reset after PDOWN.
8041 - Errata. PDOWN broken. Recommended do not use. Unclear if reset solves the issue since errata says no error after reset but is also claiming that only toggling PDOWN (may) or power will help. 8051 - Double reset after PDOWN.
8061 - Double reset after PDOWN.
8081 - Double reset after PDOWN.
8091 - Double reset after PDOWN.10/100/1000:
Nothing in gigabit afaics.Switches:
8862 - Not affected?
8863 - Errata. PDOWN broken. Reset will not help. Workaround exists. 8864 - Not affected?
8873 - Errata. PDOWN broken. Reset will not help. Workaround exists. 9477 - Errata. PDOWN broken. Will randomly cause link failure on adjacent links. Do not use.This certainly explains a lot.
Quoted 30 lines
Quoted 6 lines
Quoted 5 lines
This patch changes PHY state to
PHY_UPwhen MDIO bus resume back, it should be reasonable after PHY hardware re-initialized. Also give state machine a chance to start/config auto-nego again.Quoted 8 lines
If the MAC driver calls
phy_stop()on suspend, thenphydev->suspendedis true andmdio_bus_phy_may_suspend()returns false. As a consequencephydev->suspended_by_mdio_busis false andmdio_bus_phy_resume()skips the PHY hw initialization.
Please also note thatmdio_bus_phy_suspend()callsphy_stop_machine()that sets the state toPHY_UP.Forgot that MDIO bus suspend is done before MAC driver suspend. Therefore disregard this part for now.
Quoted 12 lines
Having said that the current argumentation isn't convincing. I'm not aware of such issues on other systems, therefore it's likely that something is system-dependent.
Please check the exact call sequence on your system, maybe it provides a hint.
Quoted 5 lines
Signed-off-by Joakim Zhang <[email protected]>--- drivers/net/phy/phy_device.c | 7 +++++++ 1 file changed, 7 insertions(+)Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/net/phy/phy_device.c static __maybe_unused int
Quoted 6 lines
(quoted diff) +0
-0
b/drivers/net/phy/phy_device.cindexcc38e326405a..312a6f662481100644drivers/net/phy/phy_device.c +0
-0@@ -306,6 +306,13 @@ static __maybe_unused int
mdio_bus_phy_resume(struct device *dev)Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/net/phy/phy_device.c static __maybe_unused int · line 310
Quoted 5 lines
drivers/net/phy/phy_device.c +2
-0ret =phy_resume (phydev);if (ret <0 )return ret; + +/* PHY state could be changed to PHY_NOLINK from MAC controller resume
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/net/phy/phy_device.c static __maybe_unused int · line 311
Quoted 1 line
drivers/net/phy/phy_device.c +1
-0+* rounte with phy_start(), here change to PHY_UP after re-initializing
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/net/phy/phy_device.c static __maybe_unused int · line 312
Quoted 1 line
drivers/net/phy/phy_device.c +1
-0+* PHY hardware, let PHY state machine to start/config auto-nego again.
Quoted 10 lines
Quoted 9 lines
Quoted 8 lines
drivers/net/phy/phy_device.c static __maybe_unused int · line 318
Quoted 7 lines
drivers/net/phy/phy_device.c +3
-0+*/ + phydev->state =PHY_UP ; + no_resume:if (phydev->attached_dev && phydev->adjust_link)phy_start_machine (phydev);
Quoted 3 lines
This is a quick draft of the modified soft reset for KSZ8081. Some tests would be appreciated.
I test this patch at my side, unfortunately, it still can't work.
I have not found what soft reset would affect in 8081 spec, is there ang common Description for different PHYs?
Best Regards,
Joakim Zhang
Quoted 57 lines
drivers/net/phy/micrel.c index renamed from drivers/net/phy/micrel.c +0
-0
a14a00328..4902235a8100644drivers/net/phy/micrel.c +36
-2@@ -1091,6 +1091,42 @@ static void kszphy_get_stats(struct phy_device *phydev, data[i] =kszphy_get_stat (phydev, i); } +int ksz8081_soft_reset (struct phy_device *phydev) { +int bmcr, ret, val; + +phy_lock_mdio_bus (phydev); + + bmcr =__phy_read (phydev,MII_BMCR ); +if (bmcr <0 ) +return bmcr; + + bmcr |=BMCR_RESET ; + +if (bmcr &BMCR_PDOWN ) +__phy_write (phydev,MII_BMCR , bmcr); + +if (phydev->autoneg ==AUTONEG_ENABLE ) + bmcr |=BMCR_ANRESTART ; + +__phy_write (phydev,MII_BMCR , bmcr & ~BMCR_ISOLATE ); + +phy_unlock_mdio_bus (phydev); + + phydev->suspended =0 ; + + ret =phy_read_poll_timeout (phydev,MII_BMCR , val, !(val &BMCR_RESET ), +50000 ,600000 , true); +if (ret) +return ret; + +/* BMCR may be reset to defaults */ +if (phydev->autoneg ==AUTONEG_DISABLE ) + ret =genphy_setup_forced (phydev); + +return ret; +} +static int kszphy_suspend (struct phy_device *phydev) {/* Disable PHY Interrupts */ @@ -1303,7 +1339,7 @@ static struct phy_driver ksphy_driver[] = { .driver_data = &ksz8081_type, .probe = kszphy_probe, .config_init = ksz8081_config_init, - .soft_reset = genphy_soft_reset, + .soft_reset = ksz8081_soft_reset, .config_intr = kszphy_config_intr, .handle_interrupt = kszphy_handle_interrupt, .get_sset_count = kszphy_get_sset_count, --2.31.1
Heiner Kallweit
maintainerQuoted 156 lines · Joakim Zhang
Hi Heiner,
Quoted 153 lines
-----Original Message-----
From: Heiner Kallweit <[email protected]>
Sent: 2021年4月5日 20:10
To: [email protected]; Joakim Zhang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: Re: [PATCH] net: phy: fix PHY possibly unwork after MDIO bus resume backQuoted 10 lines · Christian Melki
Quoted 9 lines · Heiner Kallweit
Quoted 8 lines · Heiner Kallweit
Quoted 7 lines · Joakim Zhang
commit
4c0d2e96ba055("net: phy: consider that suspend2ram may cut off PHY power") invokesphy_init_hw()when MDIO bus resume, it will soft reset PHY if PHY driver implementssoft_resetcallback. commit764d31cacfe4("net: phy: micrel: setsoft_resetcallback togenphy_soft_resetfor KSZ8081") addssoft_resetfor KSZ8081. After these two patches, I found i.MX6UL 14x14 EVK which connected to KSZ8081RNB doesn't work any more when system resume back, MACdriver is
fec_main.c.Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 4 lines
It's obvious that initializing PHY hardware when MDIO bus resume back would introduce some regression when PHY implements
soft_reset. When IWhy is this obvious? Please elaborate on why a soft reset should break something.
Quoted 5 lines
am debugging, I found PHY works fine if MAC doesn't support suspend/resume or phy_stop()/phy_start() doesn't been called during suspend/resume. This let me realize, PHY state machine
phy_state_machine()could do something breaks the PHY.Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
As we known, MAC resume first and then MDIO bus resume when system resume back from suspend. When MAC resume, usually it will invoke
phy_start()where to change PHY state toPHY_UP, then trigger the stat> machine to run now. Inphy_state_machine(), it will start/config auto-nego, then change PHY state toPHY_NOLINK, what to next is periodically check PHY link status. When MDIO bus resume, it will initialize PHY hardware, includingsoft_reset, what wouldsoft_resetaffect seems various from different PHYs. For KSZ8081RNB, when it inPHY_NOLINKstate and then perform a soft reset,it will never complete auto-nego.
Quoted 79 lines
Quoted 16 lines
Quoted 4 lines
Why? That would need to be checked in detail. Maybe chip errata documentation provides a hint.
The KSZ8081 spec says the following about bit
BMCR_PDOWN:If software reset (Register 0.15) is
used to exit power-down mode
(Register 0.11 = 1), two software
reset writes (Register 0.15 = 1) are
required. The first write clears
power-down mode; the second
write resets the chip and re-latches
the pin strapping pin values.Quoted 4 lines
Maybe this causes the issue you see and
genphy_soft_reset()isn't appropriate for this PHY. Please re-test with the KSZ8081 soft reset following the spec comment.Interesting. Never expected that behavior.
Thanks for catching it. Skimmed through the datasheets/erratas. This is what I found (micrel.c):10/100:
8001 - Unaffected?
8021/8031 - Double reset after PDOWN.
8041 - Errata. PDOWN broken. Recommended do not use. Unclear if reset solves the issue since errata says no error after reset but is also claiming that only toggling PDOWN (may) or power will help. 8051 - Double reset after PDOWN.
8061 - Double reset after PDOWN.
8081 - Double reset after PDOWN.
8091 - Double reset after PDOWN.10/100/1000:
Nothing in gigabit afaics.Switches:
8862 - Not affected?
8863 - Errata. PDOWN broken. Reset will not help. Workaround exists. 8864 - Not affected?
8873 - Errata. PDOWN broken. Reset will not help. Workaround exists. 9477 - Errata. PDOWN broken. Will randomly cause link failure on adjacent links. Do not use.This certainly explains a lot.
Quoted 30 lines
Quoted 6 lines
Quoted 5 lines
This patch changes PHY state to
PHY_UPwhen MDIO bus resume back, it should be reasonable after PHY hardware re-initialized. Also give state machine a chance to start/config auto-nego again.Quoted 8 lines
If the MAC driver calls
phy_stop()on suspend, thenphydev->suspendedis true andmdio_bus_phy_may_suspend()returns false. As a consequencephydev->suspended_by_mdio_busis false andmdio_bus_phy_resume()skips the PHY hw initialization.
Please also note thatmdio_bus_phy_suspend()callsphy_stop_machine()that sets the state toPHY_UP.Forgot that MDIO bus suspend is done before MAC driver suspend. Therefore disregard this part for now.
Quoted 12 lines
Having said that the current argumentation isn't convincing. I'm not aware of such issues on other systems, therefore it's likely that something is system-dependent.
Please check the exact call sequence on your system, maybe it provides a hint.
Quoted 5 lines
Signed-off-by Joakim Zhang <[email protected]>--- drivers/net/phy/phy_device.c | 7 +++++++ 1 file changed, 7 insertions(+)Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/net/phy/phy_device.c static __maybe_unused int
Quoted 6 lines
(quoted diff) +0
-0
b/drivers/net/phy/phy_device.cindexcc38e326405a..312a6f662481100644drivers/net/phy/phy_device.c +0
-0@@ -306,6 +306,13 @@ static __maybe_unused int
mdio_bus_phy_resume(struct device *dev)Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/net/phy/phy_device.c static __maybe_unused int · line 310
Quoted 5 lines
drivers/net/phy/phy_device.c +2
-0ret =phy_resume (phydev);if (ret <0 )return ret; + +/* PHY state could be changed to PHY_NOLINK from MAC controller resume
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/net/phy/phy_device.c static __maybe_unused int · line 311
Quoted 1 line
drivers/net/phy/phy_device.c +1
-0+* rounte with phy_start(), here change to PHY_UP after re-initializing
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/net/phy/phy_device.c static __maybe_unused int · line 312
Quoted 1 line
drivers/net/phy/phy_device.c +1
-0+* PHY hardware, let PHY state machine to start/config auto-nego again.
Quoted 10 lines
Quoted 9 lines
Quoted 8 lines
Quoted 7 lines
drivers/net/phy/phy_device.c +3
-0+*/ + phydev->state =PHY_UP ; + no_resume:if (phydev->attached_dev && phydev->adjust_link)phy_start_machine (phydev);
Quoted 9 lines
Quoted 3 lines
This is a quick draft of the modified soft reset for KSZ8081. Some tests would be appreciated.
I test this patch at my side, unfortunately, it still can't work.
I have not found what soft reset would affect in 8081 spec, is there ang common Description for different PHYs?
You can check the clause 22 spec: 802.3 22.2.4.1.1
Apart from that you can check BMCR value and which modes your PHY advertises after a soft reset. If the PHY indeed wouldn't restart aneg after a soft reset, then it would be the only one with this behavior I know. And I'd wonder why there aren't more such reports.
Quoted 60 lines
Best Regards,
Joakim ZhangQuoted 57 lines
drivers/net/phy/micrel.c index renamed from drivers/net/phy/micrel.c +0
-0
a14a00328..4902235a8100644drivers/net/phy/micrel.c +36
-2@@ -1091,6 +1091,42 @@ static void kszphy_get_stats(struct phy_device *phydev, data[i] =kszphy_get_stat (phydev, i); } +int ksz8081_soft_reset (struct phy_device *phydev) { +int bmcr, ret, val; + +phy_lock_mdio_bus (phydev); + + bmcr =__phy_read (phydev,MII_BMCR ); +if (bmcr <0 ) +return bmcr; + + bmcr |=BMCR_RESET ; + +if (bmcr &BMCR_PDOWN ) +__phy_write (phydev,MII_BMCR , bmcr); + +if (phydev->autoneg ==AUTONEG_ENABLE ) + bmcr |=BMCR_ANRESTART ; + +__phy_write (phydev,MII_BMCR , bmcr & ~BMCR_ISOLATE ); + +phy_unlock_mdio_bus (phydev); + + phydev->suspended =0 ; + + ret =phy_read_poll_timeout (phydev,MII_BMCR , val, !(val &BMCR_RESET ), +50000 ,600000 , true); +if (ret) +return ret; + +/* BMCR may be reset to defaults */ +if (phydev->autoneg ==AUTONEG_DISABLE ) + ret =genphy_setup_forced (phydev); + +return ret; +} +static int kszphy_suspend (struct phy_device *phydev) {/* Disable PHY Interrupts */ @@ -1303,7 +1339,7 @@ static struct phy_driver ksphy_driver[] = { .driver_data = &ksz8081_type, .probe = kszphy_probe, .config_init = ksz8081_config_init, - .soft_reset = genphy_soft_reset, + .soft_reset = ksz8081_soft_reset, .config_intr = kszphy_config_intr, .handle_interrupt = kszphy_handle_interrupt, .get_sset_count = kszphy_get_sset_count, --2.31.1
Quoted 180 lines
-----Original Message-----
From: Heiner Kallweit <[email protected]>
Sent: 2021年4月6日 14:29
To: Joakim Zhang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: Re: [PATCH] net: phy: fix PHY possibly unwork after MDIO bus resume backQuoted 25 lines · Joakim Zhang
Hi Heiner,
Quoted 22 lines
-----Original Message-----
From: Heiner Kallweit <[email protected]>
Sent: 2021年4月5日 20:10
To: [email protected]; Joakim Zhang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: Re: [PATCH] net: phy: fix PHY possibly unwork after MDIO bus resume backQuoted 10 lines · Christian Melki
Quoted 9 lines · Heiner Kallweit
Quoted 8 lines · Heiner Kallweit
Quoted 7 lines · Joakim Zhang
commit
4c0d2e96ba055("net: phy: consider that suspend2ram may cut off PHY power") invokesphy_init_hw()when MDIO bus resume, it will soft reset PHY if PHY driver implementssoft_resetcallback. commit764d31cacfe4("net: phy: micrel: setsoft_resetcallback togenphy_soft_resetfor KSZ8081") addssoft_resetfor KSZ8081. After these two patches, I found i.MX6UL 14x14 EVK which connected to KSZ8081RNB doesn't work any more when systemresume
Quoted 131 lines
Quoted 131 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
back, MAC
driver is
fec_main.c.Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 4 lines
It's obvious that initializing PHY hardware when MDIO bus resume back would introduce some regression when PHY implements
soft_reset. When IWhy is this obvious? Please elaborate on why a soft reset should break something.
Quoted 5 lines
am debugging, I found PHY works fine if MAC doesn't support suspend/resume or phy_stop()/phy_start() doesn't been called during suspend/resume. This let me realize, PHY state machine
phy_state_machine()could do something breaks the PHY.Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
As we known, MAC resume first and then MDIO bus resume when system resume back from suspend. When MAC resume, usually it will invoke
phy_start()where to change PHY state toPHY_UP, then trigger the stat> machine to run now. Inphy_state_machine(), it will start/config auto-nego, then change PHY state toPHY_NOLINK, what to next is periodically check PHY link status. When MDIO bus resume, it will initialize PHY hardware, includingsoft_reset, what wouldsoft_resetaffect seems various from different PHYs. For KSZ8081RNB, when it inPHY_NOLINKstate and then perform a soft reset,it will never complete auto-nego.
Quoted 75 lines
Quoted 7 lines
Quoted 4 lines
Why? That would need to be checked in detail. Maybe chip errata documentation provides a hint.
The KSZ8081 spec says the following about bit
BMCR_PDOWN:Quoted 9 lines
If software reset (Register 0.15) is used to exit power-down mode (Register 0.11 = 1), two software reset writes (Register 0.15 = 1) are required. The first write clears power-down mode; the second write resets the chip and re-latches the pin strapping pin values.
Maybe this causes the issue you see and
genphy_soft_reset()isn't appropriate for this PHY. Please re-test with the KSZ8081 soft reset following the spec comment.Interesting. Never expected that behavior.
Thanks for catching it. Skimmed through the datasheets/erratas. This is what I found (micrel.c):10/100:
8001 - Unaffected?
8021/8031 - Double reset after PDOWN.
8041 - Errata. PDOWN broken. Recommended do not use. Unclear if reset solves the issue since errata says no error after reset but is also claiming that only toggling PDOWN (may) or power will help. 8051 - Double reset after PDOWN.
8061 - Double reset after PDOWN.
8081 - Double reset after PDOWN.
8091 - Double reset after PDOWN.10/100/1000:
Nothing in gigabit afaics.Switches:
8862 - Not affected?
8863 - Errata. PDOWN broken. Reset will not help. Workaround exists. 8864 - Not affected?
8873 - Errata. PDOWN broken. Reset will not help. Workaround exists. 9477 - Errata. PDOWN broken. Will randomly cause link failure on adjacent links. Do not use.This certainly explains a lot.
Quoted 30 lines
Quoted 6 lines
Quoted 5 lines
This patch changes PHY state to
PHY_UPwhen MDIO bus resume back, it should be reasonable after PHY hardware re-initialized. Also give state machine a chance to start/config auto-nego again.Quoted 8 lines
If the MAC driver calls
phy_stop()on suspend, thenphydev->suspendedis true andmdio_bus_phy_may_suspend()returns false. As a consequencephydev->suspended_by_mdio_busis false andmdio_bus_phy_resume()skips the PHY hw initialization.
Please also note thatmdio_bus_phy_suspend()callsphy_stop_machine()that sets the state toPHY_UP.Forgot that MDIO bus suspend is done before MAC driver suspend. Therefore disregard this part for now.
Quoted 12 lines
Having said that the current argumentation isn't convincing. I'm not aware of such issues on other systems, therefore it's likely that something is system-dependent.
Please check the exact call sequence on your system, maybe it provides a hint.
Quoted 5 lines
Signed-off-by Joakim Zhang <[email protected]>--- drivers/net/phy/phy_device.c | 7 +++++++ 1 file changed, 7 insertions(+)Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/net/phy/phy_device.c static __maybe_unused int
Quoted 6 lines
(quoted diff) +0
-0
b/drivers/net/phy/phy_device.cindexcc38e326405a..312a6f662481100644drivers/net/phy/phy_device.c +0
-0@@ -306,6 +306,13 @@ static __maybe_unused int
mdio_bus_phy_resume(struct device *dev)Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/net/phy/phy_device.c static __maybe_unused int · line 310
Quoted 5 lines
drivers/net/phy/phy_device.c +2
-0ret =phy_resume (phydev);if (ret <0 )return ret; + +/* PHY state could be changed to PHY_NOLINK from MAC controller resume
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/net/phy/phy_device.c static __maybe_unused int · line 311
Quoted 1 line
drivers/net/phy/phy_device.c +1
-0+* rounte with phy_start(), here change to PHY_UP after re-initializing
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/net/phy/phy_device.c static __maybe_unused int · line 313
Quoted 2 lines
drivers/net/phy/phy_device.c +2
-0+ * PHY hardware, let PHY state machine to start/config +auto-negoagain.
Quoted 10 lines
Quoted 9 lines
Quoted 8 lines
Quoted 7 lines
drivers/net/phy/phy_device.c +3
-0+*/ + phydev->state =PHY_UP ; + no_resume:if (phydev->attached_dev && phydev->adjust_link)phy_start_machine (phydev);Quoted 9 lines
Quoted 3 lines
This is a quick draft of the modified soft reset for KSZ8081. Some tests would be appreciated.
I test this patch at my side, unfortunately, it still can't work.
I have not found what soft reset would affect in 8081 spec, is there ang common Description for different PHYs?
Quoted 6 lines
You can check the clause 22 spec: 802.3 22.2.4.1.1
Apart from that you can check BMCR value and which modes your PHY advertises after a soft reset. If the PHY indeed wouldn't restart aneg after a soft reset, then it would be the only one with this behavior I know. And I'd wonder why there aren't more such reports.
Hi Heiner,
We have reasons to believe it is a weird behavior of KSZ8081. I have another two PHYs at my side, AR8031 and RTL8211FD, they can work fine if soft_reset implemented.
As commit message described, phy_start() would change PHY state to PHY_UP finally to PHY_NOLINK when MAC resume. After MDIO bus resume back, it will periodically check link status. I did below code change to dump all PHY registers.
drivers/net/phy/phy.c +23 -1
@@ -35,7 +35,7 @@#include <net/genetlink.h> #include <net/sock.h> -#define PHY_STATE_TIME HZ +#define PHY_STATE_TIME (10 * HZ)#define PHY_STATE_STR (_state) \ case PHY_##_state: \
@@ -738,6 +738,28 @@ static int phy_check_link_status(struct phy_device *phydev)if (err)return err; +printk ("offset 0x00 data = %0x\n" ,phy_read (phydev,0x00 )); +printk ("offset 0x01 data = %0x\n" ,phy_read (phydev,0x01 )); +printk ("offset 0x02 data = %0x\n" ,phy_read (phydev,0x02 )); +printk ("offset 0x03 data = %0x\n" ,phy_read (phydev,0x03 )); +printk ("offset 0x04 data = %0x\n" ,phy_read (phydev,0x04 )); +printk ("offset 0x05 data = %0x\n" ,phy_read (phydev,0x05 )); +printk ("offset 0x06 data = %0x\n" ,phy_read (phydev,0x06 )); +printk ("offset 0x07 data = %0x\n" ,phy_read (phydev,0x07 )); +printk ("offset 0x08 data = %0x\n" ,phy_read (phydev,0x08 )); +printk ("offset 0x09 data = %0x\n" ,phy_read (phydev,0x09 )); +printk ("offset 0x10 data = %0x\n" ,phy_read (phydev,0x10 )); +printk ("offset 0x11 data = %0x\n" ,phy_read (phydev,0x11 )); +printk ("offset 0x15 data = %0x\n" ,phy_read (phydev,0x15 )); +printk ("offset 0x16 data = %0x\n" ,phy_read (phydev,0x16 )); +printk ("offset 0x17 data = %0x\n" ,phy_read (phydev,0x17 )); +printk ("offset 0x18 data = %0x\n" ,phy_read (phydev,0x18 )); +printk ("offset 0x1b data = %0x\n" ,phy_read (phydev,0x1b )); +printk ("offset 0x1c data = %0x\n" ,phy_read (phydev,0x1c )); +printk ("offset 0x1d data = %0x\n" ,phy_read (phydev,0x1d )); +printk ("offset 0x1e data = %0x\n" ,phy_read (phydev,0x1e )); +printk ("offset 0x1f data = %0x\n" ,phy_read (phydev,0x1f )); +printk ("\n\n" );if (phydev->link && phydev->state !=PHY_RUNNING ) {phy_check_downshift (phydev); phydev->state =PHY_RUNNING ;
After MDIO bus resume back, results as below:
[ 119.545383] offset 0x00 data = 1100 [ 119.549237] offset 0x01 data = 7849 [ 119.563125] offset 0x02 data = 22 [ 119.566810] offset 0x03 data = 1560 [ 119.570597] offset 0x04 data = 85e1 [ 119.588016] offset 0x05 data = 0 [ 119.592891] offset 0x06 data = 4 [ 119.596452] offset 0x07 data = 2001 [ 119.600233] offset 0x08 data = 0 [ 119.617864] offset 0x09 data = 0 [ 119.625990] offset 0x10 data = 0 [ 119.629576] offset 0x11 data = 0 [ 119.642735] offset 0x15 data = 0 [ 119.646332] offset 0x16 data = 202 [ 119.650030] offset 0x17 data = 5c02 [ 119.668054] offset 0x18 data = 801 [ 119.672997] offset 0x1b data = 0 [ 119.676565] offset 0x1c data = 0 [ 119.680084] offset 0x1d data = 0 [ 119.698031] offset 0x1e data = 20 [ 119.706246] offset 0x1f data = 8190 [ 119.709984] [ 119.709984] [ 120.182120] offset 0x00 data = 100 [ 120.185894] offset 0x01 data = 784d [ 120.189681] offset 0x02 data = 22 [ 120.206319] offset 0x03 data = 1560 [ 120.210171] offset 0x04 data = 8061 [ 120.225353] offset 0x05 data = 0 [ 120.228948] offset 0x06 data = 4 [ 120.242936] offset 0x07 data = 2001 [ 120.246792] offset 0x08 data = 0 [ 120.250313] offset 0x09 data = 0 [ 120.266748] offset 0x10 data = 0 [ 120.270335] offset 0x11 data = 0 [ 120.284167] offset 0x15 data = 0 [ 120.287760] offset 0x16 data = 202 [ 120.301031] offset 0x17 data = 3c02 [ 120.313209] offset 0x18 data = 801 [ 120.316983] offset 0x1b data = 0 [ 120.320513] offset 0x1c data = 1 [ 120.336589] offset 0x1d data = 0 [ 120.340184] offset 0x1e data = 115 [ 120.355357] offset 0x1f data = 8190 [ 120.359112] [ 120.359112] [ 129.785396] offset 0x00 data = 1100 [ 129.789252] offset 0x01 data = 7849 [ 129.809951] offset 0x02 data = 22 [ 129.815018] offset 0x03 data = 1560 [ 129.818845] offset 0x04 data = 85e1 [ 129.835808] offset 0x05 data = 0 [ 129.839398] offset 0x06 data = 4 [ 129.854514] offset 0x07 data = 2001 [ 129.858371] offset 0x08 data = 0 [ 129.873357] offset 0x09 data = 0 [ 129.876954] offset 0x10 data = 0 [ 129.880472] offset 0x11 data = 0 [ 129.896450] offset 0x15 data = 0 [ 129.900038] offset 0x16 data = 202 [ 129.915041] offset 0x17 data = 5c02 [ 129.918889] offset 0x18 data = 801 [ 129.932735] offset 0x1b data = 0 [ 129.946830] offset 0x1c data = 0 [ 129.950424] offset 0x1d data = 0 [ 129.964585] offset 0x1e data = 0 [ 129.968192] offset 0x1f data = 8190 [ 129.972938] [ 129.972938] [ 130.425125] offset 0x00 data = 100 [ 130.428889] offset 0x01 data = 784d [ 130.442671] offset 0x02 data = 22 [ 130.446360] offset 0x03 data = 1560 [ 130.450142] offset 0x04 data = 8061 [ 130.467207] offset 0x05 data = 0 [ 130.470789] offset 0x06 data = 4 [ 130.485071] offset 0x07 data = 2001 [ 130.488934] offset 0x08 data = 0 [ 130.504320] offset 0x09 data = 0 [ 130.507911] offset 0x10 data = 0 [ 130.520950] offset 0x11 data = 0 [ 130.532865] offset 0x15 data = 0 [ 130.536461] offset 0x16 data = 202 [ 130.540156] offset 0x17 data = 3c02 [ 130.557218] offset 0x18 data = 801 [ 130.560987] offset 0x1b data = 0 [ 130.575158] offset 0x1c data = 1 [ 130.578754] offset 0x1d data = 0 [ 130.593543] offset 0x1e data = 115 [ 130.597312] offset 0x1f data = 8190
We can see that BMCR and BMSR changes from 0x1100,0x7849 to 0x100,0x784d (BMCR[12] bit and BMSR[2]), and loop it. Above process is auto-nego enabled, link is down, auto-nego is disabled, link is up. And auto-nego complete bit is always 0.
PHY seems become unstable if soft reset after start/config auto-nego. I also want to fix it in micrel driver, but failed.
Do you have any other insights that can help me further locate the issue? Thanks.
Best Regards,
Joakim Zhang
[...]
Heiner Kallweit
maintainerQuoted 329 lines · Joakim Zhang
Quoted 180 lines
-----Original Message-----
From: Heiner Kallweit <[email protected]>
Sent: 2021年4月6日 14:29
To: Joakim Zhang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: Re: [PATCH] net: phy: fix PHY possibly unwork after MDIO bus resume backQuoted 25 lines · Joakim Zhang
Hi Heiner,
Quoted 22 lines
-----Original Message-----
From: Heiner Kallweit <[email protected]>
Sent: 2021年4月5日 20:10
To: [email protected]; Joakim Zhang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: Re: [PATCH] net: phy: fix PHY possibly unwork after MDIO bus resume backQuoted 10 lines · Christian Melki
Quoted 9 lines · Heiner Kallweit
Quoted 8 lines · Heiner Kallweit
Quoted 7 lines · Joakim Zhang
commit
4c0d2e96ba055("net: phy: consider that suspend2ram may cut off PHY power") invokesphy_init_hw()when MDIO bus resume, it will soft reset PHY if PHY driver implementssoft_resetcallback. commit764d31cacfe4("net: phy: micrel: setsoft_resetcallback togenphy_soft_resetfor KSZ8081") addssoft_resetfor KSZ8081. After these two patches, I found i.MX6UL 14x14 EVK which connected to KSZ8081RNB doesn't work any more when systemresume
Quoted 131 lines
Quoted 131 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
back, MAC
driver is
fec_main.c.Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 4 lines
It's obvious that initializing PHY hardware when MDIO bus resume back would introduce some regression when PHY implements
soft_reset. When IWhy is this obvious? Please elaborate on why a soft reset should break something.
Quoted 5 lines
am debugging, I found PHY works fine if MAC doesn't support suspend/resume or phy_stop()/phy_start() doesn't been called during suspend/resume. This let me realize, PHY state machine
phy_state_machine()could do something breaks the PHY.Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
As we known, MAC resume first and then MDIO bus resume when system resume back from suspend. When MAC resume, usually it will invoke
phy_start()where to change PHY state toPHY_UP, then trigger the stat> machine to run now. Inphy_state_machine(), it will start/config auto-nego, then change PHY state toPHY_NOLINK, what to next is periodically check PHY link status. When MDIO bus resume, it will initialize PHY hardware, includingsoft_reset, what wouldsoft_resetaffect seems various from different PHYs. For KSZ8081RNB, when it inPHY_NOLINKstate and then perform a soft reset,it will never complete auto-nego.
Quoted 75 lines
Quoted 7 lines
Quoted 4 lines
Why? That would need to be checked in detail. Maybe chip errata documentation provides a hint.
The KSZ8081 spec says the following about bit
BMCR_PDOWN:Quoted 9 lines
If software reset (Register 0.15) is used to exit power-down mode (Register 0.11 = 1), two software reset writes (Register 0.15 = 1) are required. The first write clears power-down mode; the second write resets the chip and re-latches the pin strapping pin values.
Maybe this causes the issue you see and
genphy_soft_reset()isn't appropriate for this PHY. Please re-test with the KSZ8081 soft reset following the spec comment.Interesting. Never expected that behavior.
Thanks for catching it. Skimmed through the datasheets/erratas. This is what I found (micrel.c):10/100:
8001 - Unaffected?
8021/8031 - Double reset after PDOWN.
8041 - Errata. PDOWN broken. Recommended do not use. Unclear if reset solves the issue since errata says no error after reset but is also claiming that only toggling PDOWN (may) or power will help. 8051 - Double reset after PDOWN.
8061 - Double reset after PDOWN.
8081 - Double reset after PDOWN.
8091 - Double reset after PDOWN.10/100/1000:
Nothing in gigabit afaics.Switches:
8862 - Not affected?
8863 - Errata. PDOWN broken. Reset will not help. Workaround exists. 8864 - Not affected?
8873 - Errata. PDOWN broken. Reset will not help. Workaround exists. 9477 - Errata. PDOWN broken. Will randomly cause link failure on adjacent links. Do not use.This certainly explains a lot.
Quoted 30 lines
Quoted 6 lines
Quoted 5 lines
This patch changes PHY state to
PHY_UPwhen MDIO bus resume back, it should be reasonable after PHY hardware re-initialized. Also give state machine a chance to start/config auto-nego again.Quoted 8 lines
If the MAC driver calls
phy_stop()on suspend, thenphydev->suspendedis true andmdio_bus_phy_may_suspend()returns false. As a consequencephydev->suspended_by_mdio_busis false andmdio_bus_phy_resume()skips the PHY hw initialization.
Please also note thatmdio_bus_phy_suspend()callsphy_stop_machine()that sets the state toPHY_UP.Forgot that MDIO bus suspend is done before MAC driver suspend. Therefore disregard this part for now.
Quoted 12 lines
Having said that the current argumentation isn't convincing. I'm not aware of such issues on other systems, therefore it's likely that something is system-dependent.
Please check the exact call sequence on your system, maybe it provides a hint.
Quoted 5 lines
Signed-off-by Joakim Zhang <[email protected]>--- drivers/net/phy/phy_device.c | 7 +++++++ 1 file changed, 7 insertions(+)Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/net/phy/phy_device.c static __maybe_unused int
Quoted 6 lines
(quoted diff) +0
-0
b/drivers/net/phy/phy_device.cindexcc38e326405a..312a6f662481100644drivers/net/phy/phy_device.c +0
-0@@ -306,6 +306,13 @@ static __maybe_unused int
mdio_bus_phy_resume(struct device *dev)Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/net/phy/phy_device.c static __maybe_unused int · line 310
Quoted 5 lines
drivers/net/phy/phy_device.c +2
-0ret =phy_resume (phydev);if (ret <0 )return ret; + +/* PHY state could be changed to PHY_NOLINK from MAC controller resume
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/net/phy/phy_device.c static __maybe_unused int · line 311
Quoted 1 line
drivers/net/phy/phy_device.c +1
-0+* rounte with phy_start(), here change to PHY_UP after re-initializing
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/net/phy/phy_device.c static __maybe_unused int · line 313
Quoted 2 lines
drivers/net/phy/phy_device.c +2
-0+ * PHY hardware, let PHY state machine to start/config +auto-negoagain.
Quoted 10 lines
Quoted 9 lines
Quoted 8 lines
Quoted 7 lines
drivers/net/phy/phy_device.c +3
-0+*/ + phydev->state =PHY_UP ; + no_resume:if (phydev->attached_dev && phydev->adjust_link)phy_start_machine (phydev);Quoted 9 lines
Quoted 3 lines
This is a quick draft of the modified soft reset for KSZ8081. Some tests would be appreciated.
I test this patch at my side, unfortunately, it still can't work.
I have not found what soft reset would affect in 8081 spec, is there ang common Description for different PHYs?
Quoted 6 lines
You can check the clause 22 spec: 802.3 22.2.4.1.1
Apart from that you can check BMCR value and which modes your PHY advertises after a soft reset. If the PHY indeed wouldn't restart aneg after a soft reset, then it would be the only one with this behavior I know. And I'd wonder why there aren't more such reports.
Hi Heiner,
We have reasons to believe it is a weird behavior of KSZ8081. I have another two PHYs at my side, AR8031 and RTL8211FD, they can work fine if
soft_resetimplemented.As commit message described,
phy_start()would change PHY state toPHY_UPfinally toPHY_NOLINKwhen MAC resume. After MDIO bus resume back, it will periodically check link status. I did below code change to dump all PHY registers.drivers/net/phy/phy.c +23
-1@@ -35,7 +35,7 @@#include <net/genetlink.h> #include <net/sock.h> -#define PHY_STATE_TIME HZ +#define PHY_STATE_TIME (10 * HZ)#define PHY_STATE_STR (_state) \ case PHY_##_state: \@@ -738,6 +738,28 @@ static int phy_check_link_status(struct phy_device *phydev)if (err)return err; +printk ("offset 0x00 data = %0x\n" ,phy_read (phydev,0x00 )); +printk ("offset 0x01 data = %0x\n" ,phy_read (phydev,0x01 )); +printk ("offset 0x02 data = %0x\n" ,phy_read (phydev,0x02 )); +printk ("offset 0x03 data = %0x\n" ,phy_read (phydev,0x03 )); +printk ("offset 0x04 data = %0x\n" ,phy_read (phydev,0x04 )); +printk ("offset 0x05 data = %0x\n" ,phy_read (phydev,0x05 )); +printk ("offset 0x06 data = %0x\n" ,phy_read (phydev,0x06 )); +printk ("offset 0x07 data = %0x\n" ,phy_read (phydev,0x07 )); +printk ("offset 0x08 data = %0x\n" ,phy_read (phydev,0x08 )); +printk ("offset 0x09 data = %0x\n" ,phy_read (phydev,0x09 )); +printk ("offset 0x10 data = %0x\n" ,phy_read (phydev,0x10 )); +printk ("offset 0x11 data = %0x\n" ,phy_read (phydev,0x11 )); +printk ("offset 0x15 data = %0x\n" ,phy_read (phydev,0x15 )); +printk ("offset 0x16 data = %0x\n" ,phy_read (phydev,0x16 )); +printk ("offset 0x17 data = %0x\n" ,phy_read (phydev,0x17 )); +printk ("offset 0x18 data = %0x\n" ,phy_read (phydev,0x18 )); +printk ("offset 0x1b data = %0x\n" ,phy_read (phydev,0x1b )); +printk ("offset 0x1c data = %0x\n" ,phy_read (phydev,0x1c )); +printk ("offset 0x1d data = %0x\n" ,phy_read (phydev,0x1d )); +printk ("offset 0x1e data = %0x\n" ,phy_read (phydev,0x1e )); +printk ("offset 0x1f data = %0x\n" ,phy_read (phydev,0x1f )); +printk ("\n\n" );if (phydev->link && phydev->state !=PHY_RUNNING ) {phy_check_downshift (phydev); phydev->state =PHY_RUNNING ;After MDIO bus resume back, results as below:
[ 119.545383] offset 0x00 data = 1100 [ 119.549237] offset 0x01 data = 7849 [ 119.563125] offset 0x02 data = 22 [ 119.566810] offset 0x03 data = 1560 [ 119.570597] offset 0x04 data = 85e1 [ 119.588016] offset 0x05 data = 0 [ 119.592891] offset 0x06 data = 4 [ 119.596452] offset 0x07 data = 2001 [ 119.600233] offset 0x08 data = 0 [ 119.617864] offset 0x09 data = 0 [ 119.625990] offset 0x10 data = 0 [ 119.629576] offset 0x11 data = 0 [ 119.642735] offset 0x15 data = 0 [ 119.646332] offset 0x16 data = 202 [ 119.650030] offset 0x17 data = 5c02 [ 119.668054] offset 0x18 data = 801 [ 119.672997] offset 0x1b data = 0 [ 119.676565] offset 0x1c data = 0 [ 119.680084] offset 0x1d data = 0 [ 119.698031] offset 0x1e data = 20 [ 119.706246] offset 0x1f data = 8190 [ 119.709984] [ 119.709984] [ 120.182120] offset 0x00 data = 100 [ 120.185894] offset 0x01 data = 784d [ 120.189681] offset 0x02 data = 22 [ 120.206319] offset 0x03 data = 1560 [ 120.210171] offset 0x04 data = 8061 [ 120.225353] offset 0x05 data = 0 [ 120.228948] offset 0x06 data = 4 [ 120.242936] offset 0x07 data = 2001 [ 120.246792] offset 0x08 data = 0 [ 120.250313] offset 0x09 data = 0 [ 120.266748] offset 0x10 data = 0 [ 120.270335] offset 0x11 data = 0 [ 120.284167] offset 0x15 data = 0 [ 120.287760] offset 0x16 data = 202 [ 120.301031] offset 0x17 data = 3c02 [ 120.313209] offset 0x18 data = 801 [ 120.316983] offset 0x1b data = 0 [ 120.320513] offset 0x1c data = 1 [ 120.336589] offset 0x1d data = 0 [ 120.340184] offset 0x1e data = 115 [ 120.355357] offset 0x1f data = 8190 [ 120.359112] [ 120.359112] [ 129.785396] offset 0x00 data = 1100 [ 129.789252] offset 0x01 data = 7849 [ 129.809951] offset 0x02 data = 22 [ 129.815018] offset 0x03 data = 1560 [ 129.818845] offset 0x04 data = 85e1 [ 129.835808] offset 0x05 data = 0 [ 129.839398] offset 0x06 data = 4 [ 129.854514] offset 0x07 data = 2001 [ 129.858371] offset 0x08 data = 0 [ 129.873357] offset 0x09 data = 0 [ 129.876954] offset 0x10 data = 0 [ 129.880472] offset 0x11 data = 0 [ 129.896450] offset 0x15 data = 0 [ 129.900038] offset 0x16 data = 202 [ 129.915041] offset 0x17 data = 5c02 [ 129.918889] offset 0x18 data = 801 [ 129.932735] offset 0x1b data = 0 [ 129.946830] offset 0x1c data = 0 [ 129.950424] offset 0x1d data = 0 [ 129.964585] offset 0x1e data = 0 [ 129.968192] offset 0x1f data = 8190 [ 129.972938] [ 129.972938] [ 130.425125] offset 0x00 data = 100 [ 130.428889] offset 0x01 data = 784d [ 130.442671] offset 0x02 data = 22 [ 130.446360] offset 0x03 data = 1560 [ 130.450142] offset 0x04 data = 8061 [ 130.467207] offset 0x05 data = 0 [ 130.470789] offset 0x06 data = 4 [ 130.485071] offset 0x07 data = 2001 [ 130.488934] offset 0x08 data = 0 [ 130.504320] offset 0x09 data = 0 [ 130.507911] offset 0x10 data = 0 [ 130.520950] offset 0x11 data = 0 [ 130.532865] offset 0x15 data = 0 [ 130.536461] offset 0x16 data = 202 [ 130.540156] offset 0x17 data = 3c02 [ 130.557218] offset 0x18 data = 801 [ 130.560987] offset 0x1b data = 0 [ 130.575158] offset 0x1c data = 1 [ 130.578754] offset 0x1d data = 0 [ 130.593543] offset 0x1e data = 115 [ 130.597312] offset 0x1f data = 8190
Quoted 5 lines
We can see that BMCR and BMSR changes from 0x1100,0x7849 to 0x100,0x784d (BMCR[12] bit and BMSR[2]), and loop it. Above process is auto-nego enabled, link is down, auto-nego is disabled, link is up. And auto-nego complete bit is always 0.
PHY seems become unstable if soft reset after start/config auto-nego. I also want to fix it in micrel driver, but failed.
Waiting for ANEG_COMPLETE to be set wouldn't be a good option. Aneg may never complete for different reasons, e.g. no physical link. And even if we use a timeout this may add unwanted delays.
Quoted 2 lines
Do you have any other insights that can help me further locate the issue? Thanks.
I think current MAC/PHY PM handling isn't perfect. Often we have the following scenario:
*suspend*
1. PHY is suspended (mdio_bus_phy_suspend)
2. MAC suspend callback (typically involving phy_stop())
*resume*
1. MAC resume callback (typically involving phy_start())
2. PHY is resumed (mdio_bus_phy_resume), incl. calling phy_init_hw()
Calling phy_init_hw() after phy_start() doesn't look right. It seems to work in most cases, but there's a certain risk that phy_init_hw() overwrites something, e.g. the advertised modes.
I think we have two valid scenarios:
1. phylib PM callbacks are used, then the MAC driver shouldn't touch the PHY in its PM callbacks, especially not call phy_stop/phy_start.
2. MAC PM callbacks take care also of the PHY. Then I think we would need a flag at the phy_device telling it to make the PHY PM callbacks a no-op.
Andrew, Russell: What do you think?
Quoted 5 lines
Best Regards,
Joakim Zhang[...]
Heiner
Heiner Kallweit
maintainerQuoted 368 lines · Heiner Kallweit
Quoted 329 lines · Joakim Zhang
Quoted 180 lines
-----Original Message-----
From: Heiner Kallweit <[email protected]>
Sent: 2021年4月6日 14:29
To: Joakim Zhang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: Re: [PATCH] net: phy: fix PHY possibly unwork after MDIO bus resume backQuoted 25 lines · Joakim Zhang
Hi Heiner,
Quoted 22 lines
-----Original Message-----
From: Heiner Kallweit <[email protected]>
Sent: 2021年4月5日 20:10
To: [email protected]; Joakim Zhang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: Re: [PATCH] net: phy: fix PHY possibly unwork after MDIO bus resume backQuoted 10 lines · Christian Melki
Quoted 9 lines · Heiner Kallweit
Quoted 8 lines · Heiner Kallweit
Quoted 7 lines · Joakim Zhang
commit
4c0d2e96ba055("net: phy: consider that suspend2ram may cut off PHY power") invokesphy_init_hw()when MDIO bus resume, it will soft reset PHY if PHY driver implementssoft_resetcallback. commit764d31cacfe4("net: phy: micrel: setsoft_resetcallback togenphy_soft_resetfor KSZ8081") addssoft_resetfor KSZ8081. After these two patches, I found i.MX6UL 14x14 EVK which connected to KSZ8081RNB doesn't work any more when systemresume
Quoted 131 lines
Quoted 131 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
back, MAC
driver is
fec_main.c.Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 4 lines
It's obvious that initializing PHY hardware when MDIO bus resume back would introduce some regression when PHY implements
soft_reset. When IWhy is this obvious? Please elaborate on why a soft reset should break something.
Quoted 5 lines
am debugging, I found PHY works fine if MAC doesn't support suspend/resume or phy_stop()/phy_start() doesn't been called during suspend/resume. This let me realize, PHY state machine
phy_state_machine()could do something breaks the PHY.Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
As we known, MAC resume first and then MDIO bus resume when system resume back from suspend. When MAC resume, usually it will invoke
phy_start()where to change PHY state toPHY_UP, then trigger the stat> machine to run now. Inphy_state_machine(), it will start/config auto-nego, then change PHY state toPHY_NOLINK, what to next is periodically check PHY link status. When MDIO bus resume, it will initialize PHY hardware, includingsoft_reset, what wouldsoft_resetaffect seems various from different PHYs. For KSZ8081RNB, when it inPHY_NOLINKstate and then perform a soft reset,it will never complete auto-nego.
Quoted 75 lines
Quoted 7 lines
Quoted 4 lines
Why? That would need to be checked in detail. Maybe chip errata documentation provides a hint.
The KSZ8081 spec says the following about bit
BMCR_PDOWN:Quoted 9 lines
If software reset (Register 0.15) is used to exit power-down mode (Register 0.11 = 1), two software reset writes (Register 0.15 = 1) are required. The first write clears power-down mode; the second write resets the chip and re-latches the pin strapping pin values.
Maybe this causes the issue you see and
genphy_soft_reset()isn't appropriate for this PHY. Please re-test with the KSZ8081 soft reset following the spec comment.Interesting. Never expected that behavior.
Thanks for catching it. Skimmed through the datasheets/erratas. This is what I found (micrel.c):10/100:
8001 - Unaffected?
8021/8031 - Double reset after PDOWN.
8041 - Errata. PDOWN broken. Recommended do not use. Unclear if reset solves the issue since errata says no error after reset but is also claiming that only toggling PDOWN (may) or power will help. 8051 - Double reset after PDOWN.
8061 - Double reset after PDOWN.
8081 - Double reset after PDOWN.
8091 - Double reset after PDOWN.10/100/1000:
Nothing in gigabit afaics.Switches:
8862 - Not affected?
8863 - Errata. PDOWN broken. Reset will not help. Workaround exists. 8864 - Not affected?
8873 - Errata. PDOWN broken. Reset will not help. Workaround exists. 9477 - Errata. PDOWN broken. Will randomly cause link failure on adjacent links. Do not use.This certainly explains a lot.
Quoted 30 lines
Quoted 6 lines
Quoted 5 lines
This patch changes PHY state to
PHY_UPwhen MDIO bus resume back, it should be reasonable after PHY hardware re-initialized. Also give state machine a chance to start/config auto-nego again.Quoted 8 lines
If the MAC driver calls
phy_stop()on suspend, thenphydev->suspendedis true andmdio_bus_phy_may_suspend()returns false. As a consequencephydev->suspended_by_mdio_busis false andmdio_bus_phy_resume()skips the PHY hw initialization.
Please also note thatmdio_bus_phy_suspend()callsphy_stop_machine()that sets the state toPHY_UP.Forgot that MDIO bus suspend is done before MAC driver suspend. Therefore disregard this part for now.
Quoted 12 lines
Having said that the current argumentation isn't convincing. I'm not aware of such issues on other systems, therefore it's likely that something is system-dependent.
Please check the exact call sequence on your system, maybe it provides a hint.
Quoted 5 lines
Signed-off-by Joakim Zhang <[email protected]>--- drivers/net/phy/phy_device.c | 7 +++++++ 1 file changed, 7 insertions(+)Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/net/phy/phy_device.c static __maybe_unused int
Quoted 6 lines
(quoted diff) +0
-0
b/drivers/net/phy/phy_device.cindexcc38e326405a..312a6f662481100644drivers/net/phy/phy_device.c +0
-0@@ -306,6 +306,13 @@ static __maybe_unused int
mdio_bus_phy_resume(struct device *dev)Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/net/phy/phy_device.c static __maybe_unused int · line 310
Quoted 5 lines
drivers/net/phy/phy_device.c +2
-0ret =phy_resume (phydev);if (ret <0 )return ret; + +/* PHY state could be changed to PHY_NOLINK from MAC controller resume
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/net/phy/phy_device.c static __maybe_unused int · line 311
Quoted 1 line
drivers/net/phy/phy_device.c +1
-0+* rounte with phy_start(), here change to PHY_UP after re-initializing
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/net/phy/phy_device.c static __maybe_unused int · line 313
Quoted 2 lines
drivers/net/phy/phy_device.c +2
-0+ * PHY hardware, let PHY state machine to start/config +auto-negoagain.
Quoted 10 lines
Quoted 9 lines
Quoted 8 lines
Quoted 7 lines
drivers/net/phy/phy_device.c +3
-0+*/ + phydev->state =PHY_UP ; + no_resume:if (phydev->attached_dev && phydev->adjust_link)phy_start_machine (phydev);Quoted 9 lines
Quoted 3 lines
This is a quick draft of the modified soft reset for KSZ8081. Some tests would be appreciated.
I test this patch at my side, unfortunately, it still can't work.
I have not found what soft reset would affect in 8081 spec, is there ang common Description for different PHYs?
Quoted 6 lines
You can check the clause 22 spec: 802.3 22.2.4.1.1
Apart from that you can check BMCR value and which modes your PHY advertises after a soft reset. If the PHY indeed wouldn't restart aneg after a soft reset, then it would be the only one with this behavior I know. And I'd wonder why there aren't more such reports.
Hi Heiner,
We have reasons to believe it is a weird behavior of KSZ8081. I have another two PHYs at my side, AR8031 and RTL8211FD, they can work fine if
soft_resetimplemented.As commit message described,
phy_start()would change PHY state toPHY_UPfinally toPHY_NOLINKwhen MAC resume. After MDIO bus resume back, it will periodically check link status. I did below code change to dump all PHY registers.drivers/net/phy/phy.c +23
-1@@ -35,7 +35,7 @@#include <net/genetlink.h> #include <net/sock.h> -#define PHY_STATE_TIME HZ +#define PHY_STATE_TIME (10 * HZ)#define PHY_STATE_STR (_state) \ case PHY_##_state: \@@ -738,6 +738,28 @@ static int phy_check_link_status(struct phy_device *phydev)if (err)return err; +printk ("offset 0x00 data = %0x\n" ,phy_read (phydev,0x00 )); +printk ("offset 0x01 data = %0x\n" ,phy_read (phydev,0x01 )); +printk ("offset 0x02 data = %0x\n" ,phy_read (phydev,0x02 )); +printk ("offset 0x03 data = %0x\n" ,phy_read (phydev,0x03 )); +printk ("offset 0x04 data = %0x\n" ,phy_read (phydev,0x04 )); +printk ("offset 0x05 data = %0x\n" ,phy_read (phydev,0x05 )); +printk ("offset 0x06 data = %0x\n" ,phy_read (phydev,0x06 )); +printk ("offset 0x07 data = %0x\n" ,phy_read (phydev,0x07 )); +printk ("offset 0x08 data = %0x\n" ,phy_read (phydev,0x08 )); +printk ("offset 0x09 data = %0x\n" ,phy_read (phydev,0x09 )); +printk ("offset 0x10 data = %0x\n" ,phy_read (phydev,0x10 )); +printk ("offset 0x11 data = %0x\n" ,phy_read (phydev,0x11 )); +printk ("offset 0x15 data = %0x\n" ,phy_read (phydev,0x15 )); +printk ("offset 0x16 data = %0x\n" ,phy_read (phydev,0x16 )); +printk ("offset 0x17 data = %0x\n" ,phy_read (phydev,0x17 )); +printk ("offset 0x18 data = %0x\n" ,phy_read (phydev,0x18 )); +printk ("offset 0x1b data = %0x\n" ,phy_read (phydev,0x1b )); +printk ("offset 0x1c data = %0x\n" ,phy_read (phydev,0x1c )); +printk ("offset 0x1d data = %0x\n" ,phy_read (phydev,0x1d )); +printk ("offset 0x1e data = %0x\n" ,phy_read (phydev,0x1e )); +printk ("offset 0x1f data = %0x\n" ,phy_read (phydev,0x1f )); +printk ("\n\n" );if (phydev->link && phydev->state !=PHY_RUNNING ) {phy_check_downshift (phydev); phydev->state =PHY_RUNNING ;After MDIO bus resume back, results as below:
[ 119.545383] offset 0x00 data = 1100 [ 119.549237] offset 0x01 data = 7849 [ 119.563125] offset 0x02 data = 22 [ 119.566810] offset 0x03 data = 1560 [ 119.570597] offset 0x04 data = 85e1 [ 119.588016] offset 0x05 data = 0 [ 119.592891] offset 0x06 data = 4 [ 119.596452] offset 0x07 data = 2001 [ 119.600233] offset 0x08 data = 0 [ 119.617864] offset 0x09 data = 0 [ 119.625990] offset 0x10 data = 0 [ 119.629576] offset 0x11 data = 0 [ 119.642735] offset 0x15 data = 0 [ 119.646332] offset 0x16 data = 202 [ 119.650030] offset 0x17 data = 5c02 [ 119.668054] offset 0x18 data = 801 [ 119.672997] offset 0x1b data = 0 [ 119.676565] offset 0x1c data = 0 [ 119.680084] offset 0x1d data = 0 [ 119.698031] offset 0x1e data = 20 [ 119.706246] offset 0x1f data = 8190 [ 119.709984] [ 119.709984] [ 120.182120] offset 0x00 data = 100 [ 120.185894] offset 0x01 data = 784d [ 120.189681] offset 0x02 data = 22 [ 120.206319] offset 0x03 data = 1560 [ 120.210171] offset 0x04 data = 8061 [ 120.225353] offset 0x05 data = 0 [ 120.228948] offset 0x06 data = 4 [ 120.242936] offset 0x07 data = 2001 [ 120.246792] offset 0x08 data = 0 [ 120.250313] offset 0x09 data = 0 [ 120.266748] offset 0x10 data = 0 [ 120.270335] offset 0x11 data = 0 [ 120.284167] offset 0x15 data = 0 [ 120.287760] offset 0x16 data = 202 [ 120.301031] offset 0x17 data = 3c02 [ 120.313209] offset 0x18 data = 801 [ 120.316983] offset 0x1b data = 0 [ 120.320513] offset 0x1c data = 1 [ 120.336589] offset 0x1d data = 0 [ 120.340184] offset 0x1e data = 115 [ 120.355357] offset 0x1f data = 8190 [ 120.359112] [ 120.359112] [ 129.785396] offset 0x00 data = 1100 [ 129.789252] offset 0x01 data = 7849 [ 129.809951] offset 0x02 data = 22 [ 129.815018] offset 0x03 data = 1560 [ 129.818845] offset 0x04 data = 85e1 [ 129.835808] offset 0x05 data = 0 [ 129.839398] offset 0x06 data = 4 [ 129.854514] offset 0x07 data = 2001 [ 129.858371] offset 0x08 data = 0 [ 129.873357] offset 0x09 data = 0 [ 129.876954] offset 0x10 data = 0 [ 129.880472] offset 0x11 data = 0 [ 129.896450] offset 0x15 data = 0 [ 129.900038] offset 0x16 data = 202 [ 129.915041] offset 0x17 data = 5c02 [ 129.918889] offset 0x18 data = 801 [ 129.932735] offset 0x1b data = 0 [ 129.946830] offset 0x1c data = 0 [ 129.950424] offset 0x1d data = 0 [ 129.964585] offset 0x1e data = 0 [ 129.968192] offset 0x1f data = 8190 [ 129.972938] [ 129.972938] [ 130.425125] offset 0x00 data = 100 [ 130.428889] offset 0x01 data = 784d [ 130.442671] offset 0x02 data = 22 [ 130.446360] offset 0x03 data = 1560 [ 130.450142] offset 0x04 data = 8061 [ 130.467207] offset 0x05 data = 0 [ 130.470789] offset 0x06 data = 4 [ 130.485071] offset 0x07 data = 2001 [ 130.488934] offset 0x08 data = 0 [ 130.504320] offset 0x09 data = 0 [ 130.507911] offset 0x10 data = 0 [ 130.520950] offset 0x11 data = 0 [ 130.532865] offset 0x15 data = 0 [ 130.536461] offset 0x16 data = 202 [ 130.540156] offset 0x17 data = 3c02 [ 130.557218] offset 0x18 data = 801 [ 130.560987] offset 0x1b data = 0 [ 130.575158] offset 0x1c data = 1 [ 130.578754] offset 0x1d data = 0 [ 130.593543] offset 0x1e data = 115 [ 130.597312] offset 0x1f data = 8190Quoted 5 lines
We can see that BMCR and BMSR changes from 0x1100,0x7849 to 0x100,0x784d (BMCR[12] bit and BMSR[2]), and loop it. Above process is auto-nego enabled, link is down, auto-nego is disabled, link is up. And auto-nego complete bit is always 0.
PHY seems become unstable if soft reset after start/config auto-nego. I also want to fix it in micrel driver, but failed.
Waiting for
ANEG_COMPLETEto be set wouldn't be a good option. Aneg may never complete for different reasons, e.g. no physical link. And even if we use a timeout this may add unwanted delays.Quoted 2 lines
Do you have any other insights that can help me further locate the issue? Thanks.
I think current MAC/PHY PM handling isn't perfect. Often we have the following scenario:
*suspend*
1. PHY is suspended (mdio_bus_phy_suspend)
2. MAC suspend callback (typically involvingphy_stop())*resume*
1. MAC resume callback (typically involvingphy_start())
2. PHY is resumed (mdio_bus_phy_resume), incl. callingphy_init_hw()Calling
phy_init_hw()afterphy_start()doesn't look right. It seems to work in most cases, but there's a certain risk thatphy_init_hw()overwrites something, e.g. the advertised modes.
I think we have two valid scenarios:1. phylib PM callbacks are used, then the MAC driver shouldn't touch the PHY in its PM callbacks, especially not call phy_stop/phy_start.
2. MAC PM callbacks take care also of the PHY. Then I think we would need a flag at the
phy_devicetelling it to make the PHY PM callbacks a no-op.
Quoted 9 lines
Andrew, Russell: What do you think?
Quoted 5 lines
Best Regards,
Joakim Zhang[...]
Heiner
Based on scenario 1 you can also try the following.
drivers/net/ethernet/freescale/fec_main.c +0 -2
@@ -3805,7 +3805,6 @@ static int __maybe_unused fec_suspend(struct device *dev)if (netif_running (ndev)) {if (fep->wol_flag &FEC_WOL_FLAG_ENABLE ) fep->wol_flag |=FEC_WOL_FLAG_SLEEP_ON ; -phy_stop (ndev->phydev);napi_disable (&fep->napi);netif_tx_lock_bh (ndev);netif_device_detach (ndev);
@@ -3864,7 +3863,6 @@ static int __maybe_unused fec_resume(struct device *dev)netif_device_attach (ndev);netif_tx_unlock_bh (ndev);napi_enable (&fep->napi); -phy_start (ndev->phydev); }rtnl_unlock ();
Signature · 1 line
2.31.1
Hi Heiner,
Quoted 384 lines
-----Original Message-----
From: Heiner Kallweit <[email protected]>
Sent: 2021年4月7日 2:22
To: Joakim Zhang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Russell King - ARM Linux <[email protected]>
Cc: [email protected]; [email protected]; dl-linux-imx <[email protected]>; Florian Fainelli <[email protected]>
Subject: Re: [PATCH] net: phy: fix PHY possibly unwork after MDIO bus resume backQuoted 28 lines · Heiner Kallweit
Quoted 27 lines · Joakim Zhang
Quoted 27 lines
-----Original Message-----
From: Heiner Kallweit <[email protected]>
Sent: 2021年4月6日 14:29
To: Joakim Zhang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: Re: [PATCH] net: phy: fix PHY possibly unwork after MDIO bus resume backQuoted 14 lines · Joakim Zhang
Hi Heiner,
Quoted 11 lines
-----Original Message-----
From: Heiner Kallweit <[email protected]>
Sent: 2021年4月5日 20:10
To: [email protected]; Joakim Zhang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: Re: [PATCH] net: phy: fix PHY possibly unwork after MDIO bus resume backQuoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines · Christian Melki
Quoted 4 lines · Heiner Kallweit
Quoted 3 lines · Heiner Kallweit
Quoted 2 lines · Joakim Zhang
Quoted 1 line
commit
4c0d2e96ba055("net: phy: consider that suspend2rammay
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
cut off PHY power") invokes
phy_init_hw()when MDIO bus resume, it will soft reset PHY if PHY driver implementssoft_resetcallback.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
commit
764d31cacfe4("net: phy: micrel: setsoft_resetcallback togenphy_soft_resetfor KSZ8081") addssoft_resetforKSZ8081.
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
After these two patches, I found i.MX6UL 14x14 EVK which connected to KSZ8081RNB doesn't work any more when system
resume
Quoted 15 lines
Quoted 15 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
back, MAC
driver is
fec_main.c.Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 4 lines
It's obvious that initializing PHY hardware when MDIO bus resume back would introduce some regression when PHY implements
soft_reset. When IWhy is this obvious? Please elaborate on why a soft reset should break something.
Quoted 5 lines
am debugging, I found PHY works fine if MAC doesn't support suspend/resume or phy_stop()/phy_start() doesn't been called during suspend/resume. This let me realize, PHY state machine
phy_state_machine()could do something breaks the PHY.Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
As we known, MAC resume first and then MDIO bus resume when system resume back from suspend. When MAC resume, usually it will invoke
phy_start()where to change PHY state toPHY_UP, then trigger the
stat> machine to run now. Inphy_state_machine(), it will start/config auto-nego, then change PHY state toPHY_NOLINK, what to next is periodically check PHY link status. When MDIO bus resume, it will initialize PHY hardware, includingsoft_reset, what wouldsoft_resetaffect seems various fromdifferent PHYs.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
For KSZ8081RNB, when it in
PHY_NOLINKstate and then perform a soft reset,it will never complete auto-nego.
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Why? That would need to be checked in detail. Maybe chip errata documentation provides a hint.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
The KSZ8081 spec says the following about bit
BMCR_PDOWN:If software reset (Register 0.15) is used to exit power-down mode (Register 0.11 = 1), two software reset writes (Register 0.15 = 1) are required. The first write clears power-down mode; the second write resets the chip and re-latches the pin strapping pin
values.
Quoted 32 lines
Quoted 32 lines
Quoted 32 lines
Quoted 32 lines
Quoted 32 lines
Quoted 32 lines
Quoted 5 lines
Maybe this causes the issue you see and
genphy_soft_reset()isn't appropriate for this PHY. Please re-test with the KSZ8081 soft reset following the spec comment.Interesting. Never expected that behavior.
Thanks for catching it. Skimmed through the datasheets/erratas. This is what I found (micrel.c):10/100:
8001 - Unaffected?
8021/8031 - Double reset after PDOWN.
8041 - Errata. PDOWN broken. Recommended do not use. Unclear if reset solves the issue since errata says no error after reset but is also claiming that only toggling PDOWN (may) or power will help. 8051 - Double reset after PDOWN.
8061 - Double reset after PDOWN.
8081 - Double reset after PDOWN.
8091 - Double reset after PDOWN.10/100/1000:
Nothing in gigabit afaics.Switches:
8862 - Not affected?
8863 - Errata. PDOWN broken. Reset will not help. Workaround exists. 8864 - Not affected?
8873 - Errata. PDOWN broken. Reset will not help. Workaround exists. 9477 - Errata. PDOWN broken. Will randomly cause link failure on adjacent links. Do not use.Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
This certainly explains a lot.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
This patch changes PHY state to
PHY_UPwhen MDIO bus resume back, it should be reasonable after PHY hardware re-initialized. Also give state machine a chance to start/configauto-nego again.
Quoted 76 lines
Quoted 76 lines
Quoted 75 lines
Quoted 59 lines
Quoted 59 lines
Quoted 28 lines
Quoted 28 lines
Quoted 12 lines
Quoted 1 line
If the MAC driver calls
phy_stop()on suspend, thenphydev->suspendedis true andmdio_bus_phy_may_suspend()phydev->returns
false. As a consequencephydev->suspended_by_mdio_busis false andphydev->mdio_bus_phy_resume()
skips the PHY hw initialization.
Please also note thatmdio_bus_phy_suspend()callsphy_stop_machine()that sets the state toPHY_UP.Forgot that MDIO bus suspend is done before MAC driver suspend. Therefore disregard this part for now.
Quoted 12 lines
Having said that the current argumentation isn't convincing. I'm not aware of such issues on other systems, therefore it's likely that something is system-dependent.
Please check the exact call sequence on your system, maybe it provides a hint.
Quoted 5 lines
Signed-off-by Joakim Zhang <[email protected]>--- drivers/net/phy/phy_device.c | 7 +++++++ 1 file changed, 7 insertions(+)Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
drivers/net/phy/phy_device.c static __maybe_unused int
Quoted 7 lines
(quoted diff) +0
-0
b/drivers/net/phy/phy_device.cindexcc38e326405a..312a6f662481
100644drivers/net/phy/phy_device.c +0
-0@@ -306,6 +306,13 @@ static __maybe_unused int
mdio_bus_phy_resume(struct device *dev)Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/net/phy/phy_device.c static __maybe_unused int · line 311
Quoted 6 lines
drivers/net/phy/phy_device.c +3
-0ret =phy_resume (phydev);if (ret <0 )return ret; + +/* PHY state could be changed to PHY_NOLINK from MAC +controller resume
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/net/phy/phy_device.c static __maybe_unused int · line 312
Quoted 1 line
drivers/net/phy/phy_device.c +1
-0+* rounte with phy_start(), here change to PHY_UP after re-initializing
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/net/phy/phy_device.c static __maybe_unused int · line 314
Quoted 2 lines
drivers/net/phy/phy_device.c +2
-0+ * PHY hardware, let PHY state machine to start/config +auto-negoagain.
Quoted 10 lines
Quoted 9 lines
Quoted 8 lines
Quoted 7 lines
drivers/net/phy/phy_device.c +3
-0+*/ + phydev->state =PHY_UP ; + no_resume:if (phydev->attached_dev && phydev->adjust_link)phy_start_machine (phydev);Quoted 9 lines
Quoted 3 lines
This is a quick draft of the modified soft reset for KSZ8081. Some tests would be appreciated.
I test this patch at my side, unfortunately, it still can't work.
I have not found what soft reset would affect in 8081 spec, is there ang common Description for different PHYs?
You can check the clause 22 spec: 802.3 22.2.4.1.1
Apart from that you can check BMCR value and which modes your PHY advertises after a soft reset. If the PHY indeed wouldn't restart aneg after a soft reset, then it would be the only one with this behavior I know. And I'd wonder why there aren't more such reports.
Quoted 4 lines
Quoted 4 lines
Hi Heiner,
We have reasons to believe it is a weird behavior of KSZ8081. I have another two PHYs at my side, AR8031 and RTL8211FD, they can work fine if
soft_resetimplemented.Quoted 2 lines
Quoted 2 lines
As commit message described,
phy_start()would change PHY state to
PHY_UPfinally toPHY_NOLINKwhen MAC resume.Quoted 1 line
Quoted 1 line
After MDIO bus resume back, it will periodically check link status. I did below
code change to dump all PHY registers.
Quoted 7 lines
Quoted 7 lines
drivers/net/phy/phy.c +0
-0@@ -35,7 +35,7 @@#include <net/genetlink.h> #include <net/sock.h> Quoted 6 lines
drivers/net/phy/phy.c static int phy_check_link_status(struct phy_device
Quoted 6 lines
drivers/net/phy/phy.c +1
-1-#define PHY_STATE_TIME HZ +#define PHY_STATE_TIME (10 * HZ)#define PHY_STATE_STR (_state) \ case PHY_##_state: \@@ -738,6 +738,28 @@ static int phy_check_link_status(struct phy_device*phydev)
Quoted 80 lines
Quoted 80 lines
drivers/net/phy/phy.c +22
-0if (err)return err; +printk ("offset 0x00 data = %0x\n" ,phy_read (phydev,0x00 )); +printk ("offset 0x01 data = %0x\n" ,phy_read (phydev,0x01 )); +printk ("offset 0x02 data = %0x\n" ,phy_read (phydev,0x02 )); +printk ("offset 0x03 data = %0x\n" ,phy_read (phydev,0x03 )); +printk ("offset 0x04 data = %0x\n" ,phy_read (phydev,0x04 )); +printk ("offset 0x05 data = %0x\n" ,phy_read (phydev,0x05 )); +printk ("offset 0x06 data = %0x\n" ,phy_read (phydev,0x06 )); +printk ("offset 0x07 data = %0x\n" ,phy_read (phydev,0x07 )); +printk ("offset 0x08 data = %0x\n" ,phy_read (phydev,0x08 )); +printk ("offset 0x09 data = %0x\n" ,phy_read (phydev,0x09 )); +printk ("offset 0x10 data = %0x\n" ,phy_read (phydev,0x10 )); +printk ("offset 0x11 data = %0x\n" ,phy_read (phydev,0x11 )); +printk ("offset 0x15 data = %0x\n" ,phy_read (phydev,0x15 )); +printk ("offset 0x16 data = %0x\n" ,phy_read (phydev,0x16 )); +printk ("offset 0x17 data = %0x\n" ,phy_read (phydev,0x17 )); +printk ("offset 0x18 data = %0x\n" ,phy_read (phydev,0x18 )); +printk ("offset 0x1b data = %0x\n" ,phy_read (phydev,0x1b )); +printk ("offset 0x1c data = %0x\n" ,phy_read (phydev,0x1c )); +printk ("offset 0x1d data = %0x\n" ,phy_read (phydev,0x1d )); +printk ("offset 0x1e data = %0x\n" ,phy_read (phydev,0x1e )); +printk ("offset 0x1f data = %0x\n" ,phy_read (phydev,0x1f )); +printk ("\n\n" );if (phydev->link && phydev->state !=PHY_RUNNING ) {phy_check_downshift (phydev); phydev->state =PHY_RUNNING ;After MDIO bus resume back, results as below:
[ 119.545383] offset 0x00 data = 1100 [ 119.549237] offset 0x01 data = 7849 [ 119.563125] offset 0x02 data = 22 [ 119.566810] offset 0x03 data = 1560 [ 119.570597] offset 0x04 data = 85e1 [ 119.588016] offset 0x05 data = 0 [ 119.592891] offset 0x06 data = 4 [ 119.596452] offset 0x07 data = 2001 [ 119.600233] offset 0x08data = 0 [ 119.617864] offset
0x09data = 0 [ 119.625990] offset0x10data = 0 [ 119.629576] offset0x11data = 0 [ 119.642735] offset0x15data = 0 [ 119.646332] offset0x16data = 202 [ 119.650030] offset0x17data = 5c02 [ 119.668054] offset0x18data = 801 [ 119.672997] offset0x1bdata = 0 [ 119.676565] offset0x1cdata = 0 [ 119.680084] offset0x1ddata = 0 [ 119.698031] offset0x1edata = 20 [ 119.706246] offset0x1fdata = 8190 [ 119.709984][ 119.709984] [ 120.182120] offset 0x00 data = 100 [ 120.185894]offset
0x01data = 784d [ 120.189681] offset0x02data = 22 [ 120.206319] offset0x03data = 1560 [ 120.210171] offset0x04data = 8061 [ 120.225353] offset0x05data = 0 [ 120.228948] offset0x06data = 4 [ 120.242936] offset0x07data = 2001 [ 120.246792] offset0x08data = 0 [ 120.250313] offset0x09data = 0 [ 120.266748] offset0x10data = 0 [ 120.270335] offset0x11data = 0 [ 120.284167] offset0x15data = 0 [ 120.287760] offset0x16data = 202 [ 120.301031] offset0x17data = 3c02 [ 120.313209] offset0x18data = 801 [ 120.316983] offset0x1bdata = 0 [ 120.320513] offset0x1cdata = 1 [ 120.336589] offset0x1ddata = 0 [ 120.340184] offset0x1edata = 115 [ 120.355357] offset0x1fdata = 8190 [ 120.359112] [ 120.359112] [ 129.785396] offset0x00data = 1100 [ 129.789252] offset0x01data = 7849 [ 129.809951] offset0x02data = 22 [ 129.815018] offset0x03data = 1560 [ 129.818845] offset0x04data = 85e1 [ 129.835808] offset0x05data = 0 [ 129.839398] offset0x06data = 4 [ 129.854514] offset0x07data = 2001 [ 129.858371] offset0x08data = 0 [ 129.873357] offset0x09data = 0 [ 129.876954] offset0x10data = 0 [ 129.880472] offset0x11data = 0[ 129.896450] offset 0x15 data = 0 [ 129.900038] offset 0x16 data =202 [ 129.915041] offset
0x17data = 5c02 [ 129.918889] offset0x18data = 801 [ 129.932735] offset0x1bdata = 0 [ 129.946830] offset0x1cdata = 0 [ 129.950424] offset0x1ddata = 0 [ 129.964585] offset0x1edata = 0 [ 129.968192] offset0x1fdata = 8190 [ 129.972938] [ 129.972938] [ 130.425125] offset0x00data = 100 [ 130.428889] offset0x01data = 784d [ 130.442671] offset0x02data = 22 [ 130.446360] offset0x03data = 1560 [ 130.450142] offset0x04data = 8061 [ 130.467207] offset0x05data = 0 [ 130.470789] offset0x06data = 4 [ 130.485071] offset0x07data = 2001 [ 130.488934] offset0x08data = 0 [ 130.504320] offset0x09data = 0 [ 130.507911] offset0x10data = 0 [ 130.520950] offset0x11data = 0[ 130.532865] offset 0x15 data = 0 [ 130.536461] offset 0x16 data =202 [ 130.540156] offset
0x17data = 3c02 [ 130.557218] offset0x18data = 801 [ 130.560987] offset0x1bdata = 0 [ 130.575158] offset0x1cdata = 1 [ 130.578754] offset0x1ddata = 0 [ 130.593543] offset0x1edata = 115 [ 130.597312] offset0x1fdata = 8190Quoted 1 line
Quoted 1 line
We can see that BMCR and BMSR changes from 0x1100,0x7849 to
0x100,0x784d (BMCR[12] bit and BMSR[2]), and loop it.
Quoted 1 line
Quoted 1 line
Above process is auto-nego enabled, link is down, auto-nego is disabled, link
is up. And auto-nego complete bit is always 0.
Quoted 2 lines
Quoted 2 lines
PHY seems become unstable if soft reset after start/config auto-nego. I also
want to fix it in micrel driver, but failed.
Quoted 7 lines
Quoted 1 line
Waiting for
ANEG_COMPLETEto be set wouldn't be a good option. Aneg may never complete for different reasons, e.g. no physical link. And even if we use a timeout this may add unwanted delays.Quoted 1 line
Do you have any other insights that can help me further locate the issue?
Thanks.
Quoted 27 lines
Quoted 1 line
I think current MAC/PHY PM handling isn't perfect. Often we have the following
scenario:*suspend*
1. PHY is suspended (mdio_bus_phy_suspend) 2. MAC suspend callback (typically involvingphy_stop())*resume*
1. MAC resume callback (typically involvingphy_start()) 2. PHY is resumed (mdio_bus_phy_resume), incl. callingphy_init_hw()Calling
phy_init_hw()afterphy_start()doesn't look right. It seems to work in most cases, but there's a certain risk thatphy_init_hw()overwrites something, e.g. the advertised modes. I think we have two valid scenarios:1. phylib PM callbacks are used, then the MAC driver shouldn't touch the PHY in its PM callbacks, especially not call phy_stop/phy_start.
2. MAC PM callbacks take care also of the PHY. Then I think we would need a flag at the
phy_devicetelling it to make the PHY PM callbacks a no-op.Quoted 9 lines
Andrew, Russell: What do you think?
Quoted 5 lines
Best Regards,
Joakim Zhang[...]
Heiner
Based on scenario 1 you can also try the following.
drivers/net/ethernet/freescale/fec_main.c +0
-1@@ -3805,7 +3805,6 @@ static int __maybe_unused fec_suspend(struct device *dev) if (netif_running(ndev)) {if (fep->wol_flag &FEC_WOL_FLAG_ENABLE ) fep->wol_flag |=FEC_WOL_FLAG_SLEEP_ON ; -phy_stop (ndev->phydev);napi_disable (&fep->napi);netif_tx_lock_bh (ndev);drivers/net/ethernet/freescale/fec_main.c +0
-0netif_device_detach (ndev);
drivers/net/ethernet/freescale/fec_main.c static int __maybe_unused fec_resume(struct · line 3868
Quoted 7 lines
drivers/net/ethernet/freescale/fec_main.c +0
-1@@ -3864,7 +3863,6 @@ static int __maybe_unused fec_resume(struct device *dev)netif_device_attach (ndev );netif_tx_unlock_bh (ndev);napi_enable (&fep->napi); -phy_start (ndev->phydev); }rtnl_unlock ();
As I described in commit message:
"When I am debugging, I found PHY works fine if MAC doesn't support suspend/resume or phy_stop()/phy_start() doesn't been called during suspend/resume. This let me realize, PHY state machine phy_state_machine() could do something breaks the PHY."
So I have tried your above code change before, and it works. But it is a very common phenomenon that MAC suspend/resume invokes phy_stop/start or phylink_stop/start, and it's been around for a long time.
As the scenarios you list, it is indeed unreasonable to soft reset or config PHY after calling phy_start_aneg() in state machine. PHY state should be PHY_UP after calling phy_init_hw(), It seems more reasonable.
Best Regards,
Joakim Zhang
Quoted 3 lines
--
2.31.1
Heiner Kallweit
maintainerQuoted 397 lines · Joakim Zhang
Hi Heiner,
Quoted 384 lines
-----Original Message-----
From: Heiner Kallweit <[email protected]>
Sent: 2021年4月7日 2:22
To: Joakim Zhang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Russell King - ARM Linux <[email protected]>
Cc: [email protected]; [email protected]; dl-linux-imx <[email protected]>; Florian Fainelli <[email protected]>
Subject: Re: [PATCH] net: phy: fix PHY possibly unwork after MDIO bus resume backQuoted 28 lines · Heiner Kallweit
Quoted 27 lines · Joakim Zhang
Quoted 27 lines
-----Original Message-----
From: Heiner Kallweit <[email protected]>
Sent: 2021年4月6日 14:29
To: Joakim Zhang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: Re: [PATCH] net: phy: fix PHY possibly unwork after MDIO bus resume backQuoted 14 lines · Joakim Zhang
Hi Heiner,
Quoted 11 lines
-----Original Message-----
From: Heiner Kallweit <[email protected]>
Sent: 2021年4月5日 20:10
To: [email protected]; Joakim Zhang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: Re: [PATCH] net: phy: fix PHY possibly unwork after MDIO bus resume backQuoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines · Christian Melki
Quoted 4 lines · Heiner Kallweit
Quoted 3 lines · Heiner Kallweit
Quoted 2 lines · Joakim Zhang
Quoted 1 line
commit
4c0d2e96ba055("net: phy: consider that suspend2rammay
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
cut off PHY power") invokes
phy_init_hw()when MDIO bus resume, it will soft reset PHY if PHY driver implementssoft_resetcallback.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
commit
764d31cacfe4("net: phy: micrel: setsoft_resetcallback togenphy_soft_resetfor KSZ8081") addssoft_resetforKSZ8081.
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
After these two patches, I found i.MX6UL 14x14 EVK which connected to KSZ8081RNB doesn't work any more when system
resume
Quoted 15 lines
Quoted 15 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
back, MAC
driver is
fec_main.c.Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 4 lines
It's obvious that initializing PHY hardware when MDIO bus resume back would introduce some regression when PHY implements
soft_reset. When IWhy is this obvious? Please elaborate on why a soft reset should break something.
Quoted 5 lines
am debugging, I found PHY works fine if MAC doesn't support suspend/resume or phy_stop()/phy_start() doesn't been called during suspend/resume. This let me realize, PHY state machine
phy_state_machine()could do something breaks the PHY.Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
As we known, MAC resume first and then MDIO bus resume when system resume back from suspend. When MAC resume, usually it will invoke
phy_start()where to change PHY state toPHY_UP, then trigger the
stat> machine to run now. Inphy_state_machine(), it will start/config auto-nego, then change PHY state toPHY_NOLINK, what to next is periodically check PHY link status. When MDIO bus resume, it will initialize PHY hardware, includingsoft_reset, what wouldsoft_resetaffect seems various fromdifferent PHYs.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
For KSZ8081RNB, when it in
PHY_NOLINKstate and then perform a soft reset,it will never complete auto-nego.
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Why? That would need to be checked in detail. Maybe chip errata documentation provides a hint.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
The KSZ8081 spec says the following about bit
BMCR_PDOWN:If software reset (Register 0.15) is used to exit power-down mode (Register 0.11 = 1), two software reset writes (Register 0.15 = 1) are required. The first write clears power-down mode; the second write resets the chip and re-latches the pin strapping pin
values.
Quoted 32 lines
Quoted 32 lines
Quoted 32 lines
Quoted 32 lines
Quoted 32 lines
Quoted 32 lines
Quoted 5 lines
Maybe this causes the issue you see and
genphy_soft_reset()isn't appropriate for this PHY. Please re-test with the KSZ8081 soft reset following the spec comment.Interesting. Never expected that behavior.
Thanks for catching it. Skimmed through the datasheets/erratas. This is what I found (micrel.c):10/100:
8001 - Unaffected?
8021/8031 - Double reset after PDOWN.
8041 - Errata. PDOWN broken. Recommended do not use. Unclear if reset solves the issue since errata says no error after reset but is also claiming that only toggling PDOWN (may) or power will help. 8051 - Double reset after PDOWN.
8061 - Double reset after PDOWN.
8081 - Double reset after PDOWN.
8091 - Double reset after PDOWN.10/100/1000:
Nothing in gigabit afaics.Switches:
8862 - Not affected?
8863 - Errata. PDOWN broken. Reset will not help. Workaround exists. 8864 - Not affected?
8873 - Errata. PDOWN broken. Reset will not help. Workaround exists. 9477 - Errata. PDOWN broken. Will randomly cause link failure on adjacent links. Do not use.Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
This certainly explains a lot.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
This patch changes PHY state to
PHY_UPwhen MDIO bus resume back, it should be reasonable after PHY hardware re-initialized. Also give state machine a chance to start/configauto-nego again.
Quoted 76 lines
Quoted 76 lines
Quoted 75 lines
Quoted 59 lines
Quoted 59 lines
Quoted 28 lines
Quoted 28 lines
Quoted 12 lines
Quoted 1 line
If the MAC driver calls
phy_stop()on suspend, thenphydev->suspendedis true andmdio_bus_phy_may_suspend()phydev->returns
false. As a consequencephydev->suspended_by_mdio_busis false andphydev->mdio_bus_phy_resume()
skips the PHY hw initialization.
Please also note thatmdio_bus_phy_suspend()callsphy_stop_machine()that sets the state toPHY_UP.Forgot that MDIO bus suspend is done before MAC driver suspend. Therefore disregard this part for now.
Quoted 12 lines
Having said that the current argumentation isn't convincing. I'm not aware of such issues on other systems, therefore it's likely that something is system-dependent.
Please check the exact call sequence on your system, maybe it provides a hint.
Quoted 5 lines
Signed-off-by Joakim Zhang <[email protected]>--- drivers/net/phy/phy_device.c | 7 +++++++ 1 file changed, 7 insertions(+)Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
drivers/net/phy/phy_device.c static __maybe_unused int
Quoted 7 lines
(quoted diff) +0
-0
b/drivers/net/phy/phy_device.cindexcc38e326405a..312a6f662481
100644drivers/net/phy/phy_device.c +0
-0@@ -306,6 +306,13 @@ static __maybe_unused int
mdio_bus_phy_resume(struct device *dev)Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/net/phy/phy_device.c static __maybe_unused int · line 311
Quoted 6 lines
drivers/net/phy/phy_device.c +3
-0ret =phy_resume (phydev);if (ret <0 )return ret; + +/* PHY state could be changed to PHY_NOLINK from MAC +controller resume
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/net/phy/phy_device.c static __maybe_unused int · line 312
Quoted 1 line
drivers/net/phy/phy_device.c +1
-0+* rounte with phy_start(), here change to PHY_UP after re-initializing
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/net/phy/phy_device.c static __maybe_unused int · line 314
Quoted 2 lines
drivers/net/phy/phy_device.c +2
-0+ * PHY hardware, let PHY state machine to start/config +auto-negoagain.
Quoted 10 lines
Quoted 9 lines
Quoted 8 lines
Quoted 7 lines
drivers/net/phy/phy_device.c +3
-0+*/ + phydev->state =PHY_UP ; + no_resume:if (phydev->attached_dev && phydev->adjust_link)phy_start_machine (phydev);Quoted 9 lines
Quoted 3 lines
This is a quick draft of the modified soft reset for KSZ8081. Some tests would be appreciated.
I test this patch at my side, unfortunately, it still can't work.
I have not found what soft reset would affect in 8081 spec, is there ang common Description for different PHYs?
You can check the clause 22 spec: 802.3 22.2.4.1.1
Apart from that you can check BMCR value and which modes your PHY advertises after a soft reset. If the PHY indeed wouldn't restart aneg after a soft reset, then it would be the only one with this behavior I know. And I'd wonder why there aren't more such reports.
Quoted 4 lines
Quoted 4 lines
Hi Heiner,
We have reasons to believe it is a weird behavior of KSZ8081. I have another two PHYs at my side, AR8031 and RTL8211FD, they can work fine if
soft_resetimplemented.Quoted 2 lines
Quoted 2 lines
As commit message described,
phy_start()would change PHY state to
PHY_UPfinally toPHY_NOLINKwhen MAC resume.Quoted 1 line
Quoted 1 line
After MDIO bus resume back, it will periodically check link status. I did below
code change to dump all PHY registers.
Quoted 7 lines
Quoted 7 lines
drivers/net/phy/phy.c +0
-0@@ -35,7 +35,7 @@#include <net/genetlink.h> #include <net/sock.h> Quoted 6 lines
drivers/net/phy/phy.c static int phy_check_link_status(struct phy_device
Quoted 6 lines
drivers/net/phy/phy.c +1
-1-#define PHY_STATE_TIME HZ +#define PHY_STATE_TIME (10 * HZ)#define PHY_STATE_STR (_state) \ case PHY_##_state: \@@ -738,6 +738,28 @@ static int phy_check_link_status(struct phy_device*phydev)
Quoted 80 lines
Quoted 80 lines
drivers/net/phy/phy.c +22
-0if (err)return err; +printk ("offset 0x00 data = %0x\n" ,phy_read (phydev,0x00 )); +printk ("offset 0x01 data = %0x\n" ,phy_read (phydev,0x01 )); +printk ("offset 0x02 data = %0x\n" ,phy_read (phydev,0x02 )); +printk ("offset 0x03 data = %0x\n" ,phy_read (phydev,0x03 )); +printk ("offset 0x04 data = %0x\n" ,phy_read (phydev,0x04 )); +printk ("offset 0x05 data = %0x\n" ,phy_read (phydev,0x05 )); +printk ("offset 0x06 data = %0x\n" ,phy_read (phydev,0x06 )); +printk ("offset 0x07 data = %0x\n" ,phy_read (phydev,0x07 )); +printk ("offset 0x08 data = %0x\n" ,phy_read (phydev,0x08 )); +printk ("offset 0x09 data = %0x\n" ,phy_read (phydev,0x09 )); +printk ("offset 0x10 data = %0x\n" ,phy_read (phydev,0x10 )); +printk ("offset 0x11 data = %0x\n" ,phy_read (phydev,0x11 )); +printk ("offset 0x15 data = %0x\n" ,phy_read (phydev,0x15 )); +printk ("offset 0x16 data = %0x\n" ,phy_read (phydev,0x16 )); +printk ("offset 0x17 data = %0x\n" ,phy_read (phydev,0x17 )); +printk ("offset 0x18 data = %0x\n" ,phy_read (phydev,0x18 )); +printk ("offset 0x1b data = %0x\n" ,phy_read (phydev,0x1b )); +printk ("offset 0x1c data = %0x\n" ,phy_read (phydev,0x1c )); +printk ("offset 0x1d data = %0x\n" ,phy_read (phydev,0x1d )); +printk ("offset 0x1e data = %0x\n" ,phy_read (phydev,0x1e )); +printk ("offset 0x1f data = %0x\n" ,phy_read (phydev,0x1f )); +printk ("\n\n" );if (phydev->link && phydev->state !=PHY_RUNNING ) {phy_check_downshift (phydev); phydev->state =PHY_RUNNING ;After MDIO bus resume back, results as below:
[ 119.545383] offset 0x00 data = 1100 [ 119.549237] offset 0x01 data = 7849 [ 119.563125] offset 0x02 data = 22 [ 119.566810] offset 0x03 data = 1560 [ 119.570597] offset 0x04 data = 85e1 [ 119.588016] offset 0x05 data = 0 [ 119.592891] offset 0x06 data = 4 [ 119.596452] offset 0x07 data = 2001 [ 119.600233] offset 0x08data = 0 [ 119.617864] offset
0x09data = 0 [ 119.625990] offset0x10data = 0 [ 119.629576] offset0x11data = 0 [ 119.642735] offset0x15data = 0 [ 119.646332] offset0x16data = 202 [ 119.650030] offset0x17data = 5c02 [ 119.668054] offset0x18data = 801 [ 119.672997] offset0x1bdata = 0 [ 119.676565] offset0x1cdata = 0 [ 119.680084] offset0x1ddata = 0 [ 119.698031] offset0x1edata = 20 [ 119.706246] offset0x1fdata = 8190 [ 119.709984][ 119.709984] [ 120.182120] offset 0x00 data = 100 [ 120.185894]offset
0x01data = 784d [ 120.189681] offset0x02data = 22 [ 120.206319] offset0x03data = 1560 [ 120.210171] offset0x04data = 8061 [ 120.225353] offset0x05data = 0 [ 120.228948] offset0x06data = 4 [ 120.242936] offset0x07data = 2001 [ 120.246792] offset0x08data = 0 [ 120.250313] offset0x09data = 0 [ 120.266748] offset0x10data = 0 [ 120.270335] offset0x11data = 0 [ 120.284167] offset0x15data = 0 [ 120.287760] offset0x16data = 202 [ 120.301031] offset0x17data = 3c02 [ 120.313209] offset0x18data = 801 [ 120.316983] offset0x1bdata = 0 [ 120.320513] offset0x1cdata = 1 [ 120.336589] offset0x1ddata = 0 [ 120.340184] offset0x1edata = 115 [ 120.355357] offset0x1fdata = 8190 [ 120.359112] [ 120.359112] [ 129.785396] offset0x00data = 1100 [ 129.789252] offset0x01data = 7849 [ 129.809951] offset0x02data = 22 [ 129.815018] offset0x03data = 1560 [ 129.818845] offset0x04data = 85e1 [ 129.835808] offset0x05data = 0 [ 129.839398] offset0x06data = 4 [ 129.854514] offset0x07data = 2001 [ 129.858371] offset0x08data = 0 [ 129.873357] offset0x09data = 0 [ 129.876954] offset0x10data = 0 [ 129.880472] offset0x11data = 0[ 129.896450] offset 0x15 data = 0 [ 129.900038] offset 0x16 data =202 [ 129.915041] offset
0x17data = 5c02 [ 129.918889] offset0x18data = 801 [ 129.932735] offset0x1bdata = 0 [ 129.946830] offset0x1cdata = 0 [ 129.950424] offset0x1ddata = 0 [ 129.964585] offset0x1edata = 0 [ 129.968192] offset0x1fdata = 8190 [ 129.972938] [ 129.972938] [ 130.425125] offset0x00data = 100 [ 130.428889] offset0x01data = 784d [ 130.442671] offset0x02data = 22 [ 130.446360] offset0x03data = 1560 [ 130.450142] offset0x04data = 8061 [ 130.467207] offset0x05data = 0 [ 130.470789] offset0x06data = 4 [ 130.485071] offset0x07data = 2001 [ 130.488934] offset0x08data = 0 [ 130.504320] offset0x09data = 0 [ 130.507911] offset0x10data = 0 [ 130.520950] offset0x11data = 0[ 130.532865] offset 0x15 data = 0 [ 130.536461] offset 0x16 data =202 [ 130.540156] offset
0x17data = 3c02 [ 130.557218] offset0x18data = 801 [ 130.560987] offset0x1bdata = 0 [ 130.575158] offset0x1cdata = 1 [ 130.578754] offset0x1ddata = 0 [ 130.593543] offset0x1edata = 115 [ 130.597312] offset0x1fdata = 8190Quoted 1 line
Quoted 1 line
We can see that BMCR and BMSR changes from 0x1100,0x7849 to
0x100,0x784d (BMCR[12] bit and BMSR[2]), and loop it.
Quoted 1 line
Quoted 1 line
Above process is auto-nego enabled, link is down, auto-nego is disabled, link
is up. And auto-nego complete bit is always 0.
Quoted 2 lines
Quoted 2 lines
PHY seems become unstable if soft reset after start/config auto-nego. I also
want to fix it in micrel driver, but failed.
Quoted 7 lines
Quoted 1 line
Waiting for
ANEG_COMPLETEto be set wouldn't be a good option. Aneg may never complete for different reasons, e.g. no physical link. And even if we use a timeout this may add unwanted delays.Quoted 1 line
Do you have any other insights that can help me further locate the issue?
Thanks.
Quoted 27 lines
Quoted 1 line
I think current MAC/PHY PM handling isn't perfect. Often we have the following
scenario:*suspend*
1. PHY is suspended (mdio_bus_phy_suspend) 2. MAC suspend callback (typically involvingphy_stop())*resume*
1. MAC resume callback (typically involvingphy_start()) 2. PHY is resumed (mdio_bus_phy_resume), incl. callingphy_init_hw()Calling
phy_init_hw()afterphy_start()doesn't look right. It seems to work in most cases, but there's a certain risk thatphy_init_hw()overwrites something, e.g. the advertised modes. I think we have two valid scenarios:1. phylib PM callbacks are used, then the MAC driver shouldn't touch the PHY in its PM callbacks, especially not call phy_stop/phy_start.
2. MAC PM callbacks take care also of the PHY. Then I think we would need a flag at the
phy_devicetelling it to make the PHY PM callbacks a no-op.Quoted 9 lines
Andrew, Russell: What do you think?
Quoted 5 lines
Best Regards,
Joakim Zhang[...]
Heiner
Based on scenario 1 you can also try the following.
drivers/net/ethernet/freescale/fec_main.c +0
-1@@ -3805,7 +3805,6 @@ static int __maybe_unused fec_suspend(struct device *dev) if (netif_running(ndev)) {if (fep->wol_flag &FEC_WOL_FLAG_ENABLE ) fep->wol_flag |=FEC_WOL_FLAG_SLEEP_ON ; -phy_stop (ndev->phydev);napi_disable (&fep->napi);netif_tx_lock_bh (ndev);drivers/net/ethernet/freescale/fec_main.c +0
-0netif_device_detach (ndev);drivers/net/ethernet/freescale/fec_main.c static int __maybe_unused fec_resume(struct · line 3868
Quoted 7 lines
drivers/net/ethernet/freescale/fec_main.c +0
-1@@ -3864,7 +3863,6 @@ static int __maybe_unused fec_resume(struct device *dev)netif_device_attach (ndev );netif_tx_unlock_bh (ndev);napi_enable (&fep->napi); -phy_start (ndev->phydev); }rtnl_unlock ();As I described in commit message:
Quoted 12 lines
"When I am debugging, I found PHY works fine if MAC doesn't support suspend/resume or phy_stop()/phy_start() doesn't been called during suspend/resume. This let me realize, PHY state machine
phy_state_machine()could do something breaks the PHY."So I have tried your above code change before, and it works. But it is a very common phenomenon that MAC suspend/resume invokes phy_stop/start or phylink_stop/start, and it's been around for a long time.
As the scenarios you list, it is indeed unreasonable to soft reset or config PHY after calling
phy_start_aneg()in state machine. PHY state should bePHY_UPafter callingphy_init_hw(), It seems more reasonable.Best Regards,
Joakim ZhangQuoted 3 lines
--
2.31.1
Following is a draft patch for scenario 1:
Make PHY PM a no-op if MAC manages PHY PM.
Can you give it a try?
drivers/net/phy/phy_device.c +6 -0
@@ -273,6 +273,9 @@ static __maybe_unused int mdio_bus_phy_suspend(struct device *dev) {struct phy_device *phydev =to_phy_device (dev); +if (phydev->mac_managed_pm) +return 0 ; +/* We must stop the state machine manually, otherwise it stops out of * control, possibly with the phydev->lock held. Upon resume, netdev * may call phy routines that try to grab the same lock, and that may
@@ -294,6 +297,9 @@ static __maybe_unused int mdio_bus_phy_resume(struct device *dev)struct phy_device *phydev =to_phy_device (dev);int ret; +if (phydev->mac_managed_pm) +return 0 ; +if (!phydev->suspended_by_mdio_bus) goto no_resume;
include/linux/phy.h +1 -0
@@ -567,6 +567,7 @@ struct phy_device { unsigned loopback_enabled:1; unsigned downshifted_rate:1; unsigned is_on_sfp_module:1; + unsigned mac_managed_pm:1; unsigned autoneg:1;/* The most recently read link state */
Signature · 1 line
2.31.1
drivers/net/ethernet/freescale/fec_main.c +3 -0
@@ -2048,6 +2048,8 @@ static int fec_enet_mii_probe(struct net_device *ndev) fep->link =0 ; fep->full_duplex =0 ; + phy_dev->mac_managed_pm =1 ; +phy_attached_info (phy_dev);return 0 ;
@@ -3864,6 +3866,7 @@ static int __maybe_unused fec_resume(struct device *dev)netif_device_attach (ndev);netif_tx_unlock_bh (ndev);napi_enable (&fep->napi); +phy_init_hw (ndev->phydev);phy_start (ndev->phydev); }rtnl_unlock ();
Signature · 1 line
2.31.1
Hi Heiner,
Quoted 452 lines
-----Original Message-----
From: Heiner Kallweit <[email protected]>
Sent: 2021年4月7日 15:12
To: Joakim Zhang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; dl-linux-imx <[email protected]>; Florian Fainelli <[email protected]>
Subject: Re: [PATCH] net: phy: fix PHY possibly unwork after MDIO bus resume backQuoted 79 lines · Joakim Zhang
Hi Heiner,
Quoted 76 lines
-----Original Message-----
From: Heiner Kallweit <[email protected]>
Sent: 2021年4月7日 2:22
To: Joakim Zhang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Russell King - ARM Linux <[email protected]>
Cc: [email protected]; [email protected]; dl-linux-imx <[email protected]>; Florian Fainelli <[email protected]>
Subject: Re: [PATCH] net: phy: fix PHY possibly unwork after MDIO bus resume backQuoted 28 lines · Heiner Kallweit
Quoted 27 lines · Joakim Zhang
Quoted 27 lines
-----Original Message-----
From: Heiner Kallweit <[email protected]>
Sent: 2021年4月6日 14:29
To: Joakim Zhang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: Re: [PATCH] net: phy: fix PHY possibly unwork after MDIO bus resume backQuoted 14 lines · Joakim Zhang
Hi Heiner,
Quoted 11 lines
-----Original Message-----
From: Heiner Kallweit <[email protected]>
Sent: 2021年4月5日 20:10
To: [email protected]; Joakim Zhang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: Re: [PATCH] net: phy: fix PHY possibly unwork after MDIO bus resume backQuoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines · Christian Melki
Quoted 4 lines · Heiner Kallweit
Quoted 3 lines · Heiner Kallweit
Quoted 2 lines · Joakim Zhang
Quoted 1 line
commit
4c0d2e96ba055("net: phy: consider that suspend2rammay
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
cut off PHY power") invokes
phy_init_hw()when MDIO bus resume, it will soft reset PHY if PHY driver implementssoft_resetcallback.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
commit
764d31cacfe4("net: phy: micrel: setsoft_resetcallback togenphy_soft_resetfor KSZ8081") addssoft_resetforKSZ8081.
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
After these two patches, I found i.MX6UL 14x14 EVK which connected to KSZ8081RNB doesn't work any more when system
resume
Quoted 17 lines
Quoted 17 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
back, MAC
driver is
fec_main.c.Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 4 lines
It's obvious that initializing PHY hardware when MDIO bus resume back would introduce some regression when PHY implements
soft_reset. When IWhy is this obvious? Please elaborate on why a soft reset should break something.
Quoted 7 lines
am debugging, I found PHY works fine if MAC doesn't support suspend/resume or phy_stop()/phy_start() doesn't been called during suspend/resume. This let me realize, PHY state machine
phy_state_machine()could do something breaks the PHY.As we known, MAC resume first and then MDIO bus resume
when
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
system resume back from suspend. When MAC resume, usually
it
Quoted 35 lines
Quoted 35 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
will invoke
phy_start()where to change PHY state toPHY_UP, then trigger the
stat> machine to run now. Inphy_state_machine(), it will start/config auto-nego, then change PHY state toPHY_NOLINK, what to next is periodically check PHY link status. When MDIO bus resume, it will initialize PHY hardware, includingsoft_reset, what wouldsoft_resetaffect seems various fromdifferent PHYs.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
For KSZ8081RNB, when it in
PHY_NOLINKstate and then perform a soft reset,it will never complete auto-nego.
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Why? That would need to be checked in detail. Maybe chip errata documentation provides a hint.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
The KSZ8081 spec says the following about bit
BMCR_PDOWN:If software reset (Register 0.15) is used to exit power-down mode (Register 0.11 = 1), two software reset writes (Register 0.15 = 1) are required. The first write clears power-down mode; the second write resets the chip and re-latches the pin strapping pin
values.
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 5 lines
Maybe this causes the issue you see and
genphy_soft_reset()isn't appropriate for this PHY. Please re-test with the KSZ8081 soft reset following the spec comment.Interesting. Never expected that behavior.
Thanks for catching it. Skimmed through the datasheets/erratas. This is what I found (micrel.c):Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
10/100:
8001 - Unaffected?
8021/8031 - Double reset after PDOWN.
8041 - Errata. PDOWN broken. Recommended do not use. Unclear if reset solves the issue since errata says no error after reset but is also claiming that only toggling PDOWN (may) or power willhelp.
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
8051 - Double reset after PDOWN.
8061 - Double reset after PDOWN.
8081 - Double reset after PDOWN.
8091 - Double reset after PDOWN.10/100/1000:
Nothing in gigabit afaics.Switches:
8862 - Not affected?
8863 - Errata. PDOWN broken. Reset will not help. Workaroundexists.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
8864 - Not affected?
8873 - Errata. PDOWN broken. Reset will not help. Workaroundexists.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
9477 - Errata. PDOWN broken. Will randomly cause link failure on adjacent links. Do not use.
This certainly explains a lot.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
This patch changes PHY state to
PHY_UPwhen MDIO busresume
Quoted 278 lines
Quoted 268 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
back, it should be reasonable after PHY hardware re-initialized. Also give state machine a chance to start/config
auto-nego again.
Quoted 76 lines
Quoted 76 lines
Quoted 75 lines
Quoted 59 lines
Quoted 59 lines
Quoted 28 lines
Quoted 28 lines
Quoted 12 lines
Quoted 1 line
If the MAC driver calls
phy_stop()on suspend, thenphydev->suspendedis true andmdio_bus_phy_may_suspend()phydev->returns
false. As a consequencephydev->suspended_by_mdio_busis false andphydev->mdio_bus_phy_resume()
skips the PHY hw initialization.
Please also note thatmdio_bus_phy_suspend()callsphy_stop_machine()that sets the state toPHY_UP.Forgot that MDIO bus suspend is done before MAC driver suspend. Therefore disregard this part for now.
Quoted 12 lines
Having said that the current argumentation isn't convincing. I'm not aware of such issues on other systems, therefore it's likely that something is system-dependent.
Please check the exact call sequence on your system, maybe it provides a hint.
Quoted 5 lines
Signed-off-by Joakim Zhang <[email protected]>--- drivers/net/phy/phy_device.c | 7 +++++++ 1 file changed, 7 insertions(+)Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
drivers/net/phy/phy_device.c static __maybe_unused int
Quoted 7 lines
(quoted diff) +0
-0
b/drivers/net/phy/phy_device.cindexcc38e326405a..312a6f662481
100644drivers/net/phy/phy_device.c +0
-0@@ -306,6 +306,13 @@ static __maybe_unused int
mdio_bus_phy_resume(struct device *dev)Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/net/phy/phy_device.c static __maybe_unused int · line 311
Quoted 6 lines
drivers/net/phy/phy_device.c +3
-0ret =phy_resume (phydev);if (ret <0 )return ret; + +/* PHY state could be changed to PHY_NOLINK from MAC +controller resume
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/net/phy/phy_device.c static __maybe_unused int · line 312
Quoted 1 line
drivers/net/phy/phy_device.c +1
-0+* rounte with phy_start(), here change to PHY_UP after re-initializing
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/net/phy/phy_device.c static __maybe_unused int · line 314
Quoted 2 lines
drivers/net/phy/phy_device.c +2
-0+ * PHY hardware, let PHY state machine to start/config +auto-negoagain.
Quoted 10 lines
Quoted 9 lines
Quoted 8 lines
Quoted 7 lines
drivers/net/phy/phy_device.c +3
-0+*/ + phydev->state =PHY_UP ; + no_resume:if (phydev->attached_dev && phydev->adjust_link)phy_start_machine (phydev);Quoted 9 lines
Quoted 3 lines
This is a quick draft of the modified soft reset for KSZ8081. Some tests would be appreciated.
I test this patch at my side, unfortunately, it still can't work.
I have not found what soft reset would affect in 8081 spec, is there ang common Description for different PHYs?
You can check the clause 22 spec: 802.3 22.2.4.1.1
Apart from that you can check BMCR value and which modes your PHY advertises after a soft reset. If the PHY indeed wouldn't restart aneg after a soft reset, then it would be the only one with this behavior I know. And I'd wonder why there aren't more such reports.
Quoted 5 lines
Quoted 5 lines
Hi Heiner,
We have reasons to believe it is a weird behavior of KSZ8081. I have another two PHYs at my side, AR8031 and RTL8211FD, they can work fine if
soft_resetimplemented.Quoted 2 lines
Quoted 2 lines
As commit message described,
phy_start()would change PHY state to
PHY_UPfinally toPHY_NOLINKwhen MAC resume.Quoted 2 lines
Quoted 2 lines
After MDIO bus resume back, it will periodically check link status. I did below
code change to dump all PHY registers.
Quoted 7 lines
Quoted 7 lines
drivers/net/phy/phy.c +0
-0@@ -35,7 +35,7 @@#include <net/genetlink.h> #include <net/sock.h> Quoted 7 lines
Quoted 7 lines
drivers/net/phy/phy.c +1
-1-#define PHY_STATE_TIME HZ +#define PHY_STATE_TIME (10 * HZ)#define PHY_STATE_STR (_state) \ case PHY_##_state: \@@ -738,6 +738,28 @@ static int phy_check_link_status(struct
phy_device*phydev)
Quoted 90 lines
Quoted 90 lines
if (err) return err;drivers/net/phy/phy.c +22
-0+printk ("offset 0x00 data = %0x\n" ,phy_read (phydev,0x00 )); +printk ("offset 0x01 data = %0x\n" ,phy_read (phydev,0x01 )); +printk ("offset 0x02 data = %0x\n" ,phy_read (phydev,0x02 )); +printk ("offset 0x03 data = %0x\n" ,phy_read (phydev,0x03 )); +printk ("offset 0x04 data = %0x\n" ,phy_read (phydev,0x04 )); +printk ("offset 0x05 data = %0x\n" ,phy_read (phydev,0x05 )); +printk ("offset 0x06 data = %0x\n" ,phy_read (phydev,0x06 )); +printk ("offset 0x07 data = %0x\n" ,phy_read (phydev,0x07 )); +printk ("offset 0x08 data = %0x\n" ,phy_read (phydev,0x08 )); +printk ("offset 0x09 data = %0x\n" ,phy_read (phydev,0x09 )); +printk ("offset 0x10 data = %0x\n" ,phy_read (phydev,0x10 )); +printk ("offset 0x11 data = %0x\n" ,phy_read (phydev,0x11 )); +printk ("offset 0x15 data = %0x\n" ,phy_read (phydev,0x15 )); +printk ("offset 0x16 data = %0x\n" ,phy_read (phydev,0x16 )); +printk ("offset 0x17 data = %0x\n" ,phy_read (phydev,0x17 )); +printk ("offset 0x18 data = %0x\n" ,phy_read (phydev,0x18 )); +printk ("offset 0x1b data = %0x\n" ,phy_read (phydev,0x1b )); +printk ("offset 0x1c data = %0x\n" ,phy_read (phydev,0x1c )); +printk ("offset 0x1d data = %0x\n" ,phy_read (phydev,0x1d )); +printk ("offset 0x1e data = %0x\n" ,phy_read (phydev,0x1e )); +printk ("offset 0x1f data = %0x\n" ,phy_read (phydev,0x1f )); +printk ("\n\n" );if (phydev->link && phydev->state !=PHY_RUNNING ) {phy_check_downshift (phydev); phydev->state =PHY_RUNNING ;After MDIO bus resume back, results as below:
[ 119.545383] offset 0x00 data = 1100 [ 119.549237] offset 0x01data = 7849 [ 119.563125] offset
0x02data = 22 [ 119.566810] offset0x03data = 1560 [ 119.570597] offset0x04data = 85e1 [ 119.588016] offset0x05data = 0 [ 119.592891] offset0x06data = 4 [ 119.596452] offset0x07data = 2001 [ 119.600233] offset0x08data = 0 [ 119.617864] offset0x09data = 0 [ 119.625990] offset0x10data = 0 [ 119.629576] offset0x11data = 0 [ 119.642735] offset0x15data = 0 [ 119.646332] offset0x16data = 202 [ 119.650030] offset0x17data = 5c02 [ 119.668054] offset0x18data =
801 [ 119.672997] offset0x1bdata = 0 [ 119.676565] offset0x1cdata = 0 [ 119.680084] offset0x1ddata = 0 [ 119.698031] offset0x1edata = 20 [ 119.706246] offset0x1fdata = 8190 [ 119.709984] [ 119.709984] [ 120.182120] offset0x00data = 100 [ 120.185894] offset0x01data = 784d [ 120.189681] offset0x02data = 22 [ 120.206319] offset0x03data = 1560 [ 120.210171] offset0x04data =
8061 [ 120.225353] offset0x05data = 0 [ 120.228948] offset0x06data = 4 [ 120.242936] offset0x07data = 2001 [ 120.246792] offset0x08data = 0 [ 120.250313] offset0x09data = 0 [ 120.266748] offset0x10data = 0 [ 120.270335] offset0x11data = 0 [ 120.284167] offset0x15data = 0 [ 120.287760] offset0x16data = 202 [ 120.301031] offset0x17data = 3c02 [ 120.313209] offset0x18data = 801 [ 120.316983] offset0x1bdata = 0 [ 120.320513] offset0x1cdata = 1 [ 120.336589] offset0x1ddata = 0 [ 120.340184] offset0x1edata = 115 [ 120.355357] offset0x1fdata = 8190 [ 120.359112] [ 120.359112] [ 129.785396] offset0x00data = 1100 [ 129.789252] offset0x01data = 7849 [ 129.809951] offset0x02data =
22 [ 129.815018] offset0x03data = 1560 [ 129.818845] offset0x04data = 85e1 [ 129.835808] offset0x05data = 0 [ 129.839398] offset0x06data = 4 [ 129.854514] offset0x07data = 2001 [ 129.858371] offset0x08data = 0 [ 129.873357] offset0x09data = 0 [ 129.876954] offset0x10data = 0 [ 129.880472] offset0x11data = 0 [ 129.896450] offset0x15data = 0 [ 129.900038] offset0x16data =
202 [ 129.915041] offset0x17data = 5c02 [ 129.918889] offset0x18data = 801 [ 129.932735] offset0x1bdata = 0 [ 129.946830] offset0x1cdata = 0 [ 129.950424] offset0x1ddata = 0 [ 129.964585] offset0x1edata = 0 [ 129.968192] offset0x1fdata = 8190 [ 129.972938] [ 129.972938] [ 130.425125] offset0x00data = 100 [ 130.428889] offset0x01data = 784d [ 130.442671] offset0x02data =
22 [ 130.446360] offset0x03data = 1560 [ 130.450142] offset0x04data = 8061 [ 130.467207] offset0x05data = 0 [ 130.470789] offset0x06data = 4 [ 130.485071] offset0x07data = 2001 [ 130.488934] offset0x08data = 0 [ 130.504320] offset0x09data = 0 [ 130.507911] offset0x10data = 0 [ 130.520950] offset0x11data = 0 [ 130.532865] offset0x15data = 0 [ 130.536461] offset0x16data =
202 [ 130.540156] offset0x17data = 3c02 [ 130.557218] offset0x18data = 801 [ 130.560987] offset0x1bdata = 0 [ 130.575158] offset0x1cdata = 1 [ 130.578754] offset0x1ddata = 0 [ 130.593543] offset0x1edata = 115 [ 130.597312] offset0x1fdata = 8190Quoted 1 line
Quoted 1 line
We can see that BMCR and BMSR changes from 0x1100,0x7849 to
0x100,0x784d (BMCR[12] bit and BMSR[2]), and loop it.
Quoted 2 lines
Quoted 2 lines
Above process is auto-nego enabled, link is down, auto-nego is disabled, link
is up. And auto-nego complete bit is always 0.
Quoted 3 lines
Quoted 3 lines
PHY seems become unstable if soft reset after start/config auto-nego. I also
want to fix it in micrel driver, but failed.
Quoted 7 lines
Quoted 1 line
Waiting for
ANEG_COMPLETEto be set wouldn't be a good option. Aneg may never complete for different reasons, e.g. no physical link. And even if we use a timeout this may add unwanted delays.Quoted 1 line
Do you have any other insights that can help me further locate the issue?
Thanks.
Quoted 27 lines
Quoted 1 line
I think current MAC/PHY PM handling isn't perfect. Often we have the following
scenario:*suspend*
1. PHY is suspended (mdio_bus_phy_suspend) 2. MAC suspend callback (typically involvingphy_stop())*resume*
1. MAC resume callback (typically involvingphy_start()) 2. PHY is resumed (mdio_bus_phy_resume), incl. callingphy_init_hw()Calling
phy_init_hw()afterphy_start()doesn't look right. It seems to work in most cases, but there's a certain risk thatphy_init_hw()overwrites something, e.g. the advertised modes. I think we have two valid scenarios:1. phylib PM callbacks are used, then the MAC driver shouldn't touch the PHY in its PM callbacks, especially not call phy_stop/phy_start.
2. MAC PM callbacks take care also of the PHY. Then I think we would need a flag at the
phy_devicetelling it to make the PHY PM callbacks a no-op.Quoted 9 lines
Andrew, Russell: What do you think?
Quoted 5 lines
Best Regards,
Joakim Zhang[...]
Heiner
Based on scenario 1 you can also try the following.
drivers/net/ethernet/freescale/fec_main.c +0
-1@@ -3805,7 +3805,6 @@ static int __maybe_unused fec_suspend(struct device *dev) if (netif_running(ndev)) {if (fep->wol_flag &FEC_WOL_FLAG_ENABLE ) fep->wol_flag |=FEC_WOL_FLAG_SLEEP_ON ; -phy_stop (ndev->phydev);napi_disable (&fep->napi);netif_tx_lock_bh (ndev);drivers/net/ethernet/freescale/fec_main.c +0
-0netif_device_detach (ndev);drivers/net/ethernet/freescale/fec_main.c static int __maybe_unused fec_resume(struct · line 3868
Quoted 7 lines
drivers/net/ethernet/freescale/fec_main.c +0
-1@@ -3864,7 +3863,6 @@ static int __maybe_unused fec_resume(struct device *dev)netif_device_attach (ndev );netif_tx_unlock_bh (ndev);napi_enable (&fep->napi); -phy_start (ndev->phydev); }rtnl_unlock ();As I described in commit message:
Quoted 1 line
"When I am debugging, I found PHY works fine if MAC doesn't support
suspend/resume or phy_stop()/phy_start() doesn't been called during suspend/resume. This let me realize, PHY state machine
phy_state_machine()could do something breaks the PHY."Quoted 2 lines
So I have tried your above code change before, and it works. But it is a very
common phenomenon that MAC suspend/resume invokes phy_stop/start or phylink_stop/start, and it's been around for a long time.
Quoted 2 lines
As the scenarios you list, it is indeed unreasonable to soft reset or config PHY
after calling
phy_start_aneg()in state machine. PHY state should bePHY_UPafter callingphy_init_hw(), It seems more reasonable.Quoted 3 lines
Best Regards,
Joakim Zhang
Quoted 9 lines
Quoted 4 lines
Quoted 3 lines
--
2.31.1Following is a draft patch for scenario 1:
Make PHY PM a no-op if MAC manages PHY PM.
Can you give it a try?
It can work for my case. Thanks.
Best Regards,
Joakim Zhang
Quoted 68 lines
drivers/net/phy/phy_device.c index renamed from drivers/net/phy/phy_device.c +0
-0
a009d1769..73d29fd5e100644drivers/net/phy/phy_device.c +3
-1@@ -273,6 +273,9 @@ static __maybe_unused int mdio_bus_phy_suspend(struct device *dev) {struct phy_device *phydev =to_phy_device (dev); +if (phydev->mac_managed_pm) +return 0 ; +/* We must stop the state machine manually, otherwise it stops out of * control, possibly with the phydev->lock held. Upon resume, netdev * may call phy routines that try to grab the same lock, and that may @@ -294,6 +297,9 @@ static __maybe_unused int mdio_bus_phy_resume(struct device *dev)
drivers/net/phy/phy_device.c +3
-0struct phy_device *phydev =to_phy_device (dev);int ret; +if (phydev->mac_managed_pm) +return 0 ; +if (!phydev->suspended_by_mdio_bus) goto no_resume;include/linux/phy.h index renamed from include/linux/phy.h +0
-0
8e2cf84b2..46702af18100644include/linux/phy.h +1
-1@@ -567,6 +567,7 @@ struct phy_device { unsigned loopback_enabled:1; unsigned downshifted_rate:1; unsigned is_on_sfp_module:1; + unsigned mac_managed_pm:1; unsigned autoneg:1;/* The most recently read link state */ --2.31.1
drivers/net/ethernet/freescale/fec_main.c +2
-0@@ -2048,6 +2048,8 @@ static int fec_enet_mii_probe(struct net_device *ndev) fep->link =0 ; fep->full_duplex =0 ; + phy_dev->mac_managed_pm =1 ; +phy_attached_info (phy_dev);drivers/net/ethernet/freescale/fec_main.c +1
-0return 0 ;@@ -3864,6 +3866,7 @@ static int __maybe_unused fec_resume(struct device *dev)netif_device_attach (ndev );netif_tx_unlock_bh (ndev);napi_enable (&fep->napi); +phy_init_hw (ndev->phydev);phy_start (ndev->phydev); }
rtnl_unlock();
--
2.31.1
Hi Heiner,
Quoted 490 lines
-----Original Message-----
From: Joakim Zhang <[email protected]>
Sent: 2021年4月7日 15:46
To: Heiner Kallweit <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; dl-linux-imx <[email protected]>; Florian Fainelli <[email protected]>
Subject: RE: [PATCH] net: phy: fix PHY possibly unwork after MDIO bus resume backHi Heiner,
Quoted 11 lines
-----Original Message-----
From: Heiner Kallweit <[email protected]>
Sent: 2021年4月7日 15:12
To: Joakim Zhang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; dl-linux-imx <[email protected]>; Florian Fainelli <[email protected]>
Subject: Re: [PATCH] net: phy: fix PHY possibly unwork after MDIO bus resume backQuoted 62 lines
Quoted 61 lines · Joakim Zhang
Hi Heiner,
Quoted 58 lines
-----Original Message-----
From: Heiner Kallweit <[email protected]>
Sent: 2021年4月7日 2:22
To: Joakim Zhang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Russell King - ARM Linux <[email protected]>
Cc: [email protected]; [email protected]; dl-linux-imx <[email protected]>; Florian Fainelli <[email protected]>
Subject: Re: [PATCH] net: phy: fix PHY possibly unwork after MDIO bus resume backQuoted 28 lines · Heiner Kallweit
Quoted 27 lines · Joakim Zhang
Quoted 27 lines
-----Original Message-----
From: Heiner Kallweit <[email protected]>
Sent: 2021年4月6日 14:29
To: Joakim Zhang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: Re: [PATCH] net: phy: fix PHY possibly unwork after MDIO bus resume backQuoted 14 lines · Joakim Zhang
Hi Heiner,
Quoted 11 lines
-----Original Message-----
From: Heiner Kallweit <[email protected]>
Sent: 2021年4月5日 20:10
To: [email protected]; Joakim Zhang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: Re: [PATCH] net: phy: fix PHY possibly unwork after MDIO bus resume backQuoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines · Christian Melki
Quoted 4 lines · Heiner Kallweit
Quoted 3 lines · Heiner Kallweit
Quoted 2 lines · Joakim Zhang
Quoted 1 line
commit 4c0d2e96ba055 ("net: phy: consider that suspend2ram
may
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
cut off PHY power") invokes phy_init_hw() when MDIO bus
resume, it will soft reset PHY if PHY driver implements
soft_resetcallback.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
commit 764d31cacfe4 ("net: phy: micrel: set soft_reset
callback to genphy_soft_reset for KSZ8081") adds
soft_reset forKSZ8081.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
After these two patches, I found i.MX6UL 14x14 EVK which
connected to KSZ8081RNB doesn't work any more whensystem
Quoted 81 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
resume
Quoted 10 lines
Quoted 10 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
back, MAC
driver is
fec_main.c.Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
It's obvious that initializing PHY hardware when MDIO bus
resume back would introduce some regression when PHY
implements soft_reset. When IWhy is this obvious? Please elaborate on why a soft reset should break something.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
am debugging, I found PHY works fine if MAC doesn't
support suspend/resume or phy_stop()/phy_start() doesn't
been called during suspend/resume. This let me realize,
PHY state machine
phy_state_machine() could do something breaks the PHY.As we known, MAC resume first and then MDIO bus resume
when
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
system resume back from suspend. When MAC resume, usually
it
Quoted 37 lines
Quoted 37 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
will invoke
phy_start() where to change PHY state to PHY_UP, then
trigger the
stat> machine to run now. In phy_state_machine(), it will
start/config auto-nego, then change PHY state to
PHY_NOLINK, what to next is periodically check PHY link
status. When MDIO bus resume, it will initialize PHY
hardware, including soft_reset, what would soft_reset
affect seems various fromdifferent PHYs.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
For KSZ8081RNB, when it in PHY_NOLINK state and then
perform a soft reset,it will never complete auto-nego.
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Why? That would need to be checked in detail. Maybe chip errata documentation provides a hint.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
The KSZ8081 spec says the following about bit
BMCR_PDOWN:If software reset (Register 0.15) is used to exit power-down mode (Register 0.11 = 1), two software reset writes (Register
0.15 = 1) are required. The first write clears power-down mode; the second write resets the chip and re-latches the pin strapping pinvalues.
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 5 lines
Maybe this causes the issue you see and
genphy_soft_reset()isn't appropriate for this PHY. Please re-test with the KSZ8081 soft reset following the spec comment.Interesting. Never expected that behavior.
Thanks for catching it. Skimmed through the datasheets/erratas. This is what I found (micrel.c):Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
10/100:
8001 - Unaffected?
8021/8031 - Double reset after PDOWN.
8041 - Errata. PDOWN broken. Recommended do not use. Unclear if reset solves the issue since errata says no error after reset but is also claiming that only toggling PDOWN (may) or power willhelp.
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
8051 - Double reset after PDOWN.
8061 - Double reset after PDOWN.
8081 - Double reset after PDOWN.
8091 - Double reset after PDOWN.10/100/1000:
Nothing in gigabit afaics.Switches:
8862 - Not affected?
8863 - Errata. PDOWN broken. Reset will not help. Workaroundexists.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
8864 - Not affected?
8873 - Errata. PDOWN broken. Reset will not help. Workaroundexists.
Quoted 26 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
9477 - Errata. PDOWN broken. Will randomly cause link failure on adjacent links. Do not use.
This certainly explains a lot.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
This patch changes PHY state to PHY_UP when MDIO bus
resume
Quoted 18 lines
Quoted 18 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
back, it should be reasonable after PHY hardware
re-initialized. Also give state machine a chance to
start/configauto-nego again.
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 12 lines
Quoted 1 line
If the MAC driver calls
phy_stop()on suspend, thenphydev->suspendedis true andmdio_bus_phy_may_suspend()phydev->returns
false. As a consequencephydev->suspended_by_mdio_busis false andphydev->mdio_bus_phy_resume()
skips the PHY hw initialization.
Please also note thatmdio_bus_phy_suspend()callsphy_stop_machine()that sets the state toPHY_UP.Forgot that MDIO bus suspend is done before MAC driver
suspend.
Quoted 55 lines
Quoted 55 lines
Quoted 55 lines
Quoted 55 lines
Quoted 55 lines
Quoted 55 lines
Quoted 54 lines
Quoted 45 lines
Quoted 14 lines
Quoted 14 lines
Therefore disregard this part for now.
Quoted 12 lines
Having said that the current argumentation isn't convincing. I'm not aware of such issues on other systems, therefore it's likely that something is system-dependent.
Please check the exact call sequence on your system, maybe it provides a hint.
Quoted 5 lines
Signed-off-by: Joakim Zhang <[email protected]>
---
drivers/net/phy/phy_device.c | 7 +++++++
1 file changed, 7 insertions(+)Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
diff --git a/drivers/net/phy/phy_device.c
b/drivers/net/phy/phy_device.c index
cc38e326405a..312a6f662481
100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -306,6 +306,13 @@ static __maybe_unused int
mdio_bus_phy_resume(struct device *dev)Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
ret = phy_resume(phydev);
if (ret < 0)
return ret;
+
+ /* PHY state could be changed to PHY_NOLINK from MAC
+controllerresume
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
+ * rounte with phy_start(), here change to PHY_UP after
re-initializing
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
+ * PHY hardware, let PHY state machine to start/config
+auto-negoagain.
Quoted 10 lines
Quoted 9 lines
Quoted 8 lines
Quoted 7 lines
+ */
+ phydev->state = PHY_UP;
+
no_resume:
if (phydev->attached_dev && phydev->adjust_link)
phy_start_machine(phydev);Quoted 3 lines
This is a quick draft of the modified soft reset for KSZ8081. Some tests would be appreciated.
I test this patch at my side, unfortunately, it still can't work.
I have not found what soft reset would affect in 8081 spec, is there ang common Description for different PHYs?
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
You can check the clause 22 spec: 802.3 22.2.4.1.1
Apart from that you can check BMCR value and which modes your PHY advertises after a soft reset. If the PHY indeed wouldn't restart aneg after a soft reset, then it would be the only one with this behavior I know. And I'd wonder why there aren't more such
reports.
Quoted 136 lines
Quoted 136 lines
Quoted 136 lines
Quoted 6 lines
Quoted 6 lines
Hi Heiner,
We have reasons to believe it is a weird behavior of KSZ8081. I have another two PHYs at my side, AR8031 and RTL8211FD, they can work fine if
soft_resetimplemented.Quoted 3 lines
Quoted 3 lines
As commit message described,
phy_start()would change PHY state to
PHY_UPfinally toPHY_NOLINKwhen MAC resume.Quoted 2 lines
Quoted 2 lines
After MDIO bus resume back, it will periodically check link status. I did below
code change to dump all PHY registers.
Quoted 7 lines
Quoted 7 lines
drivers/net/phy/phy.c +0
-0@@ -35,7 +35,7 @@#include <net/genetlink.h> #include <net/sock.h> Quoted 7 lines
Quoted 7 lines
drivers/net/phy/phy.c +1
-1-#define PHY_STATE_TIME HZ +#define PHY_STATE_TIME (10 * HZ)#define PHY_STATE_STR (_state) \ case PHY_##_state: \@@ -738,6 +738,28 @@ static int phy_check_link_status(struct
phy_device*phydev)
Quoted 99 lines
Quoted 99 lines
if (err) return err;drivers/net/phy/phy.c +22
-0+printk ("offset 0x00 data = %0x\n" ,phy_read (phydev,0x00 )); +printk ("offset 0x01 data = %0x\n" ,phy_read (phydev,0x01 )); +printk ("offset 0x02 data = %0x\n" ,phy_read (phydev,0x02 )); +printk ("offset 0x03 data = %0x\n" ,phy_read (phydev,0x03 )); +printk ("offset 0x04 data = %0x\n" ,phy_read (phydev,0x04 )); +printk ("offset 0x05 data = %0x\n" ,phy_read (phydev,0x05 )); +printk ("offset 0x06 data = %0x\n" ,phy_read (phydev,0x06 )); +printk ("offset 0x07 data = %0x\n" ,phy_read (phydev,0x07 )); +printk ("offset 0x08 data = %0x\n" ,phy_read (phydev,0x08 )); +printk ("offset 0x09 data = %0x\n" ,phy_read (phydev,0x09 )); +printk ("offset 0x10 data = %0x\n" ,phy_read (phydev,0x10 )); +printk ("offset 0x11 data = %0x\n" ,phy_read (phydev,0x11 )); +printk ("offset 0x15 data = %0x\n" ,phy_read (phydev,0x15 )); +printk ("offset 0x16 data = %0x\n" ,phy_read (phydev,0x16 )); +printk ("offset 0x17 data = %0x\n" ,phy_read (phydev,0x17 )); +printk ("offset 0x18 data = %0x\n" ,phy_read (phydev,0x18 )); +printk ("offset 0x1b data = %0x\n" ,phy_read (phydev,0x1b )); +printk ("offset 0x1c data = %0x\n" ,phy_read (phydev,0x1c )); +printk ("offset 0x1d data = %0x\n" ,phy_read (phydev,0x1d )); +printk ("offset 0x1e data = %0x\n" ,phy_read (phydev,0x1e )); +printk ("offset 0x1f data = %0x\n" ,phy_read (phydev,0x1f )); +printk ("\n\n" );if (phydev->link && phydev->state !=PHY_RUNNING ) {phy_check_downshift (phydev); phydev->state =PHY_RUNNING ;After MDIO bus resume back, results as below:
[ 119.545383] offset 0x00 data = 1100 [ 119.549237] offset 0x01data = 7849 [ 119.563125] offset
0x02data = 22 [ 119.566810] offset0x03data = 1560 [ 119.570597] offset0x04data = 85e1 [ 119.588016] offset0x05data = 0 [ 119.592891] offset0x06data =
4 [ 119.596452] offset0x07data = 2001 [ 119.600233] offset0x08data = 0 [ 119.617864] offset0x09data = 0 [ 119.625990] offset0x10data = 0 [ 119.629576] offset0x11data = 0 [ 119.642735] offset0x15data = 0 [ 119.646332] offset0x16data = 202 [ 119.650030] offset0x17data = 5c02 [ 119.668054] offset0x18data =
801 [ 119.672997] offset0x1bdata = 0 [ 119.676565] offset0x1cdata = 0 [ 119.680084] offset0x1ddata = 0 [ 119.698031] offset0x1edata = 20 [ 119.706246] offset0x1fdata = 8190 [ 119.709984] [ 119.709984] [ 120.182120] offset0x00data = 100[ 120.185894] offset 0x01 data = 784d [ 120.189681] offset 0x02data = 22 [ 120.206319] offset
0x03data = 1560 [ 120.210171] offset0x04data =
8061 [ 120.225353] offset0x05data = 0 [ 120.228948] offset0x06data = 4 [ 120.242936] offset0x07data = 2001 [ 120.246792] offset0x08data = 0 [ 120.250313] offset0x09data = 0 [ 120.266748] offset0x10data = 0 [ 120.270335] offset0x11data = 0 [ 120.284167] offset0x15data = 0 [ 120.287760] offset0x16data =
202 [ 120.301031] offset0x17data = 3c02 [ 120.313209] offset0x18data = 801 [ 120.316983] offset0x1bdata = 0 [ 120.320513] offset0x1cdata = 1 [ 120.336589] offset0x1ddata = 0 [ 120.340184] offset0x1edata = 115 [ 120.355357] offset0x1fdata = 8190 [ 120.359112] [ 120.359112] [ 129.785396] offset0x00data = 1100 [ 129.789252] offset0x01data = 7849 [ 129.809951] offset0x02data =
22 [ 129.815018] offset0x03data = 1560 [ 129.818845] offset0x04data = 85e1 [ 129.835808] offset0x05data = 0 [ 129.839398] offset0x06data = 4 [ 129.854514] offset0x07data = 2001 [ 129.858371] offset0x08data = 0 [ 129.873357] offset0x09data = 0 [ 129.876954] offset0x10data = 0 [ 129.880472] offset0x11data =
0 [ 129.896450] offset0x15data = 0 [ 129.900038] offset0x16data =
202 [ 129.915041] offset0x17data = 5c02 [ 129.918889] offset0x18data = 801 [ 129.932735] offset0x1bdata = 0 [ 129.946830] offset0x1cdata = 0 [ 129.950424] offset0x1ddata = 0 [ 129.964585] offset0x1edata = 0 [ 129.968192] offset0x1fdata =
8190 [ 129.972938] [ 129.972938] [ 130.425125] offset0x00data =
100 [ 130.428889] offset0x01data = 784d [ 130.442671] offset0x02data =
22 [ 130.446360] offset0x03data = 1560 [ 130.450142] offset0x04data = 8061 [ 130.467207] offset0x05data = 0 [ 130.470789] offset0x06data = 4 [ 130.485071] offset0x07data = 2001 [ 130.488934] offset0x08data = 0 [ 130.504320] offset0x09data = 0 [ 130.507911] offset0x10data = 0 [ 130.520950] offset0x11data =
0 [ 130.532865] offset0x15data = 0 [ 130.536461] offset0x16data =
202 [ 130.540156] offset0x17data = 3c02 [ 130.557218] offset0x18data = 801 [ 130.560987] offset0x1bdata = 0 [ 130.575158] offset0x1cdata = 1 [ 130.578754] offset0x1ddata = 0 [ 130.593543] offset0x1edata = 115 [ 130.597312] offset0x1fdata = 8190Quoted 1 line
Quoted 1 line
We can see that BMCR and BMSR changes from 0x1100,0x7849 to
0x100,0x784d (BMCR[12] bit and BMSR[2]), and loop it.
Quoted 2 lines
Quoted 2 lines
Above process is auto-nego enabled, link is down, auto-nego is disabled, link
is up. And auto-nego complete bit is always 0.
Quoted 3 lines
Quoted 3 lines
PHY seems become unstable if soft reset after start/config auto-nego. I also
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
want to fix it in micrel driver, but failed.
Quoted 7 lines
Quoted 1 line
Waiting for
ANEG_COMPLETEto be set wouldn't be a good option. Aneg may never complete for different reasons, e.g. no physical link. And even if we use a timeout this may add unwanted delays.Quoted 1 line
Do you have any other insights that can help me further locate the
issue?
Quoted 87 lines
Quoted 65 lines
Quoted 55 lines
Thanks.
Quoted 27 lines
Quoted 1 line
I think current MAC/PHY PM handling isn't perfect. Often we have the following
scenario:*suspend*
1. PHY is suspended (mdio_bus_phy_suspend) 2. MAC suspend callback (typically involvingphy_stop())*resume*
1. MAC resume callback (typically involvingphy_start()) 2. PHY is resumed (mdio_bus_phy_resume), incl. callingphy_init_hw()Calling
phy_init_hw()afterphy_start()doesn't look right. It seems to work in most cases, but there's a certain risk thatphy_init_hw()overwrites something, e.g. the advertised modes. I think we have two valid scenarios:1. phylib PM callbacks are used, then the MAC driver shouldn't touch the PHY in its PM callbacks, especially not call phy_stop/phy_start.
2. MAC PM callbacks take care also of the PHY. Then I think we would need a flag at the
phy_devicetelling it to make the PHY PM callbacks a no-op.Quoted 9 lines
Andrew, Russell: What do you think?
Quoted 5 lines
Best Regards,
Joakim Zhang[...]
Heiner
Based on scenario 1 you can also try the following.
drivers/net/ethernet/freescale/fec_main.c +0
-1@@ -3805,7 +3805,6 @@ static int __maybe_unused fec_suspend(struct device *dev) if (netif_running(ndev)) {if (fep->wol_flag &FEC_WOL_FLAG_ENABLE ) fep->wol_flag |=FEC_WOL_FLAG_SLEEP_ON ; -phy_stop (ndev->phydev);napi_disable (&fep->napi);netif_tx_lock_bh (ndev);drivers/net/ethernet/freescale/fec_main.c +0
-0netif_device_detach (ndev);drivers/net/ethernet/freescale/fec_main.c static int __maybe_unused fec_resume(struct · line 3868
Quoted 7 lines
drivers/net/ethernet/freescale/fec_main.c +0
-1@@ -3864,7 +3863,6 @@ static int __maybe_unused fec_resume(struct device *dev)netif_device_attach (ndev );netif_tx_unlock_bh (ndev);napi_enable (&fep->napi); -phy_start (ndev->phydev); }rtnl_unlock ();As I described in commit message:
Quoted 1 line
"When I am debugging, I found PHY works fine if MAC doesn't support
suspend/resume or phy_stop()/phy_start() doesn't been called during suspend/resume. This let me realize, PHY state machine
phy_state_machine()could do something breaks the PHY."Quoted 3 lines
So I have tried your above code change before, and it works. But it is a very
common phenomenon that MAC suspend/resume invokes phy_stop/start or phylink_stop/start, and it's been around for a long time.
Quoted 3 lines
As the scenarios you list, it is indeed unreasonable to soft reset or config PHY
after calling
phy_start_aneg()in state machine. PHY state should bePHY_UPafter callingphy_init_hw(), It seems more reasonable.Quoted 7 lines
Best Regards,
Joakim ZhangQuoted 3 lines
--
2.31.1
Quoted 6 lines
Quoted 4 lines
Following is a draft patch for scenario 1:
Make PHY PM a no-op if MAC manages PHY PM.
Can you give it a try?It can work for my case. Thanks.
I have another question, if it is possible to change the suspend/resume sequence?
MAC should suspend before MDIO bus, and MDIO bus should resume before MAC. For some MACs, they need PHY feed clocks. It seems more reasonable.
Best Regards,
Joakim Zhang
Quoted 71 lines
Best Regards,
Joakim ZhangQuoted 69 lines
(quoted diff) +0
-0
b/drivers/net/phy/phy_device.cindexa009d1769..73d29fd5e100644drivers/net/phy/phy_device.c +3
-0@@ -273,6 +273,9 @@ static __maybe_unused int mdio_bus_phy_suspend(struct device *dev) {struct phy_device *phydev =to_phy_device (dev); +if (phydev->mac_managed_pm) +return 0 ; +/* We must stop the state machine manually, otherwise it stops out of * control, possibly with the phydev->lock held. Upon resume, netdev * may call phy routines that try to grab the same lock, and that may @@
-294,6 +297,9 @@ static__maybe_unusedintmdio_bus_phy_resume(struct device *dev)drivers/net/phy/phy_device.c +3
-0struct phy_device *phydev =to_phy_device (dev);int ret; +if (phydev->mac_managed_pm) +return 0 ; +if (!phydev->suspended_by_mdio_bus) goto no_resume;include/linux/phy.h index renamed from include/linux/phy.h +0
-0
8e2cf84b2..46702af18100644include/linux/phy.h +1
-1@@ -567,6 +567,7 @@ struct phy_device { unsigned loopback_enabled:1; unsigned downshifted_rate:1; unsigned is_on_sfp_module:1; + unsigned mac_managed_pm:1; unsigned autoneg:1;/* The most recently read link state */ --2.31.1
drivers/net/ethernet/freescale/fec_main.c +2
-0@@ -2048,6 +2048,8 @@ static int fec_enet_mii_probe(struct net_device *ndev) fep->link =0 ; fep->full_duplex =0 ; + phy_dev->mac_managed_pm =1 ; +phy_attached_info (phy_dev);drivers/net/ethernet/freescale/fec_main.c +1
-0return 0 ;@@ -3864,6 +3866,7 @@ static int __maybe_unused fec_resume(struct device *dev)netif_device_attach (ndev );netif_tx_unlock_bh (ndev);napi_enable (&fep->napi); +phy_init_hw (ndev->phydev);phy_start (ndev->phydev); }
rtnl_unlock();
--
2.31.1
Heiner Kallweit
maintainerQuoted 498 lines · Joakim Zhang
Hi Heiner,
Quoted 495 lines
-----Original Message-----
From: Joakim Zhang <[email protected]>
Sent: 2021年4月7日 15:46
To: Heiner Kallweit <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; dl-linux-imx <[email protected]>; Florian Fainelli <[email protected]>
Subject: RE: [PATCH] net: phy: fix PHY possibly unwork after MDIO bus resume backHi Heiner,
Quoted 11 lines
-----Original Message-----
From: Heiner Kallweit <[email protected]>
Sent: 2021年4月7日 15:12
To: Joakim Zhang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; dl-linux-imx <[email protected]>; Florian Fainelli <[email protected]>
Subject: Re: [PATCH] net: phy: fix PHY possibly unwork after MDIO bus resume backQuoted 62 lines
Quoted 61 lines · Joakim Zhang
Hi Heiner,
Quoted 58 lines
-----Original Message-----
From: Heiner Kallweit <[email protected]>
Sent: 2021年4月7日 2:22
To: Joakim Zhang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Russell King - ARM Linux <[email protected]>
Cc: [email protected]; [email protected]; dl-linux-imx <[email protected]>; Florian Fainelli <[email protected]>
Subject: Re: [PATCH] net: phy: fix PHY possibly unwork after MDIO bus resume backQuoted 28 lines · Heiner Kallweit
Quoted 27 lines · Joakim Zhang
Quoted 27 lines
-----Original Message-----
From: Heiner Kallweit <[email protected]>
Sent: 2021年4月6日 14:29
To: Joakim Zhang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: Re: [PATCH] net: phy: fix PHY possibly unwork after MDIO bus resume backQuoted 14 lines · Joakim Zhang
Hi Heiner,
Quoted 11 lines
-----Original Message-----
From: Heiner Kallweit <[email protected]>
Sent: 2021年4月5日 20:10
To: [email protected]; Joakim Zhang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: Re: [PATCH] net: phy: fix PHY possibly unwork after MDIO bus resume backQuoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines · Christian Melki
Quoted 4 lines · Heiner Kallweit
Quoted 3 lines · Heiner Kallweit
Quoted 2 lines · Joakim Zhang
commit 4c0d2e96ba055 ("net: phy: consider that suspend2ram
may
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
cut off PHY power") invokes phy_init_hw() when MDIO bus
resume, it will soft reset PHY if PHY driver implements
soft_resetcallback.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
commit 764d31cacfe4 ("net: phy: micrel: set soft_reset
callback to genphy_soft_reset for KSZ8081") adds
soft_reset forKSZ8081.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
After these two patches, I found i.MX6UL 14x14 EVK which
connected to KSZ8081RNB doesn't work any more whensystem
Quoted 81 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
resume
Quoted 10 lines
Quoted 10 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
back, MAC
driver is
fec_main.c.Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
It's obvious that initializing PHY hardware when MDIO bus
resume back would introduce some regression when PHY
implements soft_reset. When IWhy is this obvious? Please elaborate on why a soft reset
should break something.Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
am debugging, I found PHY works fine if MAC doesn't
support suspend/resume or phy_stop()/phy_start() doesn't
been called during suspend/resume. This let me realize,
PHY state machine
phy_state_machine() could do something breaks the PHY.As we known, MAC resume first and then MDIO bus resume
when
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
system resume back from suspend. When MAC resume, usually
it
Quoted 37 lines
Quoted 37 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
will invoke
phy_start() where to change PHY state to PHY_UP, then
trigger the
stat> machine to run now. In phy_state_machine(), it will
start/config auto-nego, then change PHY state to
PHY_NOLINK, what to next is periodically check PHY link
status. When MDIO bus resume, it will initialize PHY
hardware, including soft_reset, what would soft_reset
affect seems various fromdifferent PHYs.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
For KSZ8081RNB, when it in PHY_NOLINK state and then
perform a soft reset,it will never complete auto-nego.
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Why? That would need to be checked in detail. Maybe chip
errata documentation provides a hint.Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
The KSZ8081 spec says the following about bit
BMCR_PDOWN:If software reset (Register 0.15) is used to exit power-down mode (Register 0.11 = 1), two software reset writes (Register
0.15 = 1) are required. The first write clears power-down mode; the second write resets the chip and re-latches the pin strapping pinvalues.
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 5 lines
Maybe this causes the issue you see and
genphy_soft_reset()isn't appropriate for this PHY. Please re-test with the KSZ8081 soft reset following the spec comment.Interesting. Never expected that behavior.
Thanks for catching it. Skimmed through the datasheets/erratas. This is what I found (micrel.c):Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
10/100:
8001 - Unaffected?
8021/8031 - Double reset after PDOWN.
8041 - Errata. PDOWN broken. Recommended do not use. Unclear if reset solves the issue since errata says no error after reset but is also claiming that only toggling PDOWN (may) or power willhelp.
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
8051 - Double reset after PDOWN.
8061 - Double reset after PDOWN.
8081 - Double reset after PDOWN.
8091 - Double reset after PDOWN.10/100/1000:
Nothing in gigabit afaics.Switches:
8862 - Not affected?
8863 - Errata. PDOWN broken. Reset will not help. Workaroundexists.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
8864 - Not affected?
8873 - Errata. PDOWN broken. Reset will not help. Workaroundexists.
Quoted 26 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
9477 - Errata. PDOWN broken. Will randomly cause link failure on adjacent links. Do not use.
This certainly explains a lot.
Quoted 2 lines
Quoted 2 lines
This patch changes PHY state to PHY_UP when MDIO bus
resume
Quoted 18 lines
Quoted 18 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
back, it should be reasonable after PHY hardware
re-initialized. Also give state machine a chance to
start/configauto-nego again.
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 12 lines
If the MAC driver calls phy_stop() on suspend, then
phydev->suspended is true and mdio_bus_phy_may_suspend()
phydev->returns
false. As a consequence
phydev->suspended_by_mdio_bus is false and
phydev->mdio_bus_phy_resume()
skips the PHY hw initialization.
Please also note that mdio_bus_phy_suspend() calls
phy_stop_machine() that sets the state to PHY_UP.Forgot that MDIO bus suspend is done before MAC driver
suspend.
Quoted 55 lines
Quoted 55 lines
Quoted 55 lines
Quoted 55 lines
Quoted 55 lines
Quoted 55 lines
Quoted 54 lines
Quoted 45 lines
Quoted 14 lines
Quoted 14 lines
Therefore disregard this part for now.
Quoted 12 lines
Having said that the current argumentation isn't convincing.
I'm not aware of such issues on other systems, therefore
it's likely that something is system-dependent.Please check the exact call sequence on your system, maybe
it provides a hint.Signed-off-by: Joakim Zhang <[email protected]>
---
drivers/net/phy/phy_device.c | 7 +++++++
1 file changed, 7 insertions(+)Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
diff --git a/drivers/net/phy/phy_device.c
b/drivers/net/phy/phy_device.c index
cc38e326405a..312a6f662481
100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -306,6 +306,13 @@ static __maybe_unused int
mdio_bus_phy_resume(struct device *dev)Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
ret = phy_resume(phydev);
if (ret < 0)
return ret;
+
+ /* PHY state could be changed to PHY_NOLINK from MAC
+controllerresume
Quoted 1 line
Quoted 1 line
Quoted 1 line
+ * rounte with phy_start(), here change to PHY_UP after
re-initializing
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
+ * PHY hardware, let PHY state machine to start/config
+auto-negoagain.
Quoted 10 lines
Quoted 9 lines
Quoted 8 lines
+ */
+ phydev->state = PHY_UP;
+
no_resume:
if (phydev->attached_dev && phydev->adjust_link)
phy_start_machine(phydev);Quoted 3 lines
This is a quick draft of the modified soft reset for KSZ8081. Some tests would be appreciated.
I test this patch at my side, unfortunately, it still can't work.
I have not found what soft reset would affect in 8081 spec, is there ang common Description for different PHYs?
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
You can check the clause 22 spec: 802.3 22.2.4.1.1
Apart from that you can check BMCR value and which modes your PHY advertises after a soft reset. If the PHY indeed wouldn't restart aneg after a soft reset, then it would be the only one with this behavior I know. And I'd wonder why there aren't more such
reports.
Quoted 136 lines
Quoted 136 lines
Quoted 136 lines
Quoted 6 lines
Quoted 6 lines
Hi Heiner,
We have reasons to believe it is a weird behavior of KSZ8081. I have another two PHYs at my side, AR8031 and RTL8211FD, they can work fine if
soft_resetimplemented.Quoted 3 lines
Quoted 3 lines
As commit message described,
phy_start()would change PHY state to
PHY_UPfinally toPHY_NOLINKwhen MAC resume.Quoted 2 lines
Quoted 2 lines
After MDIO bus resume back, it will periodically check link status. I did below
code change to dump all PHY registers.
Quoted 7 lines
Quoted 7 lines
drivers/net/phy/phy.c +0
-0@@ -35,7 +35,7 @@#include <net/genetlink.h> #include <net/sock.h> Quoted 7 lines
Quoted 7 lines
drivers/net/phy/phy.c +1
-1-#define PHY_STATE_TIME HZ +#define PHY_STATE_TIME (10 * HZ)#define PHY_STATE_STR (_state) \ case PHY_##_state: \@@ -738,6 +738,28 @@ static int phy_check_link_status(struct
phy_device*phydev)
Quoted 99 lines
Quoted 99 lines
if (err) return err;drivers/net/phy/phy.c +22
-0+printk ("offset 0x00 data = %0x\n" ,phy_read (phydev,0x00 )); +printk ("offset 0x01 data = %0x\n" ,phy_read (phydev,0x01 )); +printk ("offset 0x02 data = %0x\n" ,phy_read (phydev,0x02 )); +printk ("offset 0x03 data = %0x\n" ,phy_read (phydev,0x03 )); +printk ("offset 0x04 data = %0x\n" ,phy_read (phydev,0x04 )); +printk ("offset 0x05 data = %0x\n" ,phy_read (phydev,0x05 )); +printk ("offset 0x06 data = %0x\n" ,phy_read (phydev,0x06 )); +printk ("offset 0x07 data = %0x\n" ,phy_read (phydev,0x07 )); +printk ("offset 0x08 data = %0x\n" ,phy_read (phydev,0x08 )); +printk ("offset 0x09 data = %0x\n" ,phy_read (phydev,0x09 )); +printk ("offset 0x10 data = %0x\n" ,phy_read (phydev,0x10 )); +printk ("offset 0x11 data = %0x\n" ,phy_read (phydev,0x11 )); +printk ("offset 0x15 data = %0x\n" ,phy_read (phydev,0x15 )); +printk ("offset 0x16 data = %0x\n" ,phy_read (phydev,0x16 )); +printk ("offset 0x17 data = %0x\n" ,phy_read (phydev,0x17 )); +printk ("offset 0x18 data = %0x\n" ,phy_read (phydev,0x18 )); +printk ("offset 0x1b data = %0x\n" ,phy_read (phydev,0x1b )); +printk ("offset 0x1c data = %0x\n" ,phy_read (phydev,0x1c )); +printk ("offset 0x1d data = %0x\n" ,phy_read (phydev,0x1d )); +printk ("offset 0x1e data = %0x\n" ,phy_read (phydev,0x1e )); +printk ("offset 0x1f data = %0x\n" ,phy_read (phydev,0x1f )); +printk ("\n\n" );if (phydev->link && phydev->state !=PHY_RUNNING ) {phy_check_downshift (phydev); phydev->state =PHY_RUNNING ;After MDIO bus resume back, results as below:
[ 119.545383] offset 0x00 data = 1100 [ 119.549237] offset 0x01data = 7849 [ 119.563125] offset
0x02data = 22 [ 119.566810] offset0x03data = 1560 [ 119.570597] offset0x04data = 85e1 [ 119.588016] offset0x05data = 0 [ 119.592891] offset0x06data =
4 [ 119.596452] offset0x07data = 2001 [ 119.600233] offset0x08data = 0 [ 119.617864] offset0x09data = 0 [ 119.625990] offset0x10data = 0 [ 119.629576] offset0x11data = 0 [ 119.642735] offset0x15data = 0 [ 119.646332] offset0x16data = 202 [ 119.650030] offset0x17data = 5c02 [ 119.668054] offset0x18data =
801 [ 119.672997] offset0x1bdata = 0 [ 119.676565] offset0x1cdata = 0 [ 119.680084] offset0x1ddata = 0 [ 119.698031] offset0x1edata = 20 [ 119.706246] offset0x1fdata = 8190 [ 119.709984] [ 119.709984] [ 120.182120] offset0x00data = 100[ 120.185894] offset 0x01 data = 784d [ 120.189681] offset 0x02data = 22 [ 120.206319] offset
0x03data = 1560 [ 120.210171] offset0x04data =
8061 [ 120.225353] offset0x05data = 0 [ 120.228948] offset0x06data = 4 [ 120.242936] offset0x07data = 2001 [ 120.246792] offset0x08data = 0 [ 120.250313] offset0x09data = 0 [ 120.266748] offset0x10data = 0 [ 120.270335] offset0x11data = 0 [ 120.284167] offset0x15data = 0 [ 120.287760] offset0x16data =
202 [ 120.301031] offset0x17data = 3c02 [ 120.313209] offset0x18data = 801 [ 120.316983] offset0x1bdata = 0 [ 120.320513] offset0x1cdata = 1 [ 120.336589] offset0x1ddata = 0 [ 120.340184] offset0x1edata = 115 [ 120.355357] offset0x1fdata = 8190 [ 120.359112] [ 120.359112] [ 129.785396] offset0x00data = 1100 [ 129.789252] offset0x01data = 7849 [ 129.809951] offset0x02data =
22 [ 129.815018] offset0x03data = 1560 [ 129.818845] offset0x04data = 85e1 [ 129.835808] offset0x05data = 0 [ 129.839398] offset0x06data = 4 [ 129.854514] offset0x07data = 2001 [ 129.858371] offset0x08data = 0 [ 129.873357] offset0x09data = 0 [ 129.876954] offset0x10data = 0 [ 129.880472] offset0x11data =
0 [ 129.896450] offset0x15data = 0 [ 129.900038] offset0x16data =
202 [ 129.915041] offset0x17data = 5c02 [ 129.918889] offset0x18data = 801 [ 129.932735] offset0x1bdata = 0 [ 129.946830] offset0x1cdata = 0 [ 129.950424] offset0x1ddata = 0 [ 129.964585] offset0x1edata = 0 [ 129.968192] offset0x1fdata =
8190 [ 129.972938] [ 129.972938] [ 130.425125] offset0x00data =
100 [ 130.428889] offset0x01data = 784d [ 130.442671] offset0x02data =
22 [ 130.446360] offset0x03data = 1560 [ 130.450142] offset0x04data = 8061 [ 130.467207] offset0x05data = 0 [ 130.470789] offset0x06data = 4 [ 130.485071] offset0x07data = 2001 [ 130.488934] offset0x08data = 0 [ 130.504320] offset0x09data = 0 [ 130.507911] offset0x10data = 0 [ 130.520950] offset0x11data =
0 [ 130.532865] offset0x15data = 0 [ 130.536461] offset0x16data =
202 [ 130.540156] offset0x17data = 3c02 [ 130.557218] offset0x18data = 801 [ 130.560987] offset0x1bdata = 0 [ 130.575158] offset0x1cdata = 1 [ 130.578754] offset0x1ddata = 0 [ 130.593543] offset0x1edata = 115 [ 130.597312] offset0x1fdata = 8190Quoted 1 line
Quoted 1 line
We can see that BMCR and BMSR changes from 0x1100,0x7849 to
0x100,0x784d (BMCR[12] bit and BMSR[2]), and loop it.
Quoted 2 lines
Quoted 2 lines
Above process is auto-nego enabled, link is down, auto-nego is disabled, link
is up. And auto-nego complete bit is always 0.
Quoted 3 lines
Quoted 3 lines
PHY seems become unstable if soft reset after start/config auto-nego. I also
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
want to fix it in micrel driver, but failed.
Quoted 7 lines
Quoted 1 line
Waiting for
ANEG_COMPLETEto be set wouldn't be a good option. Aneg may never complete for different reasons, e.g. no physical link. And even if we use a timeout this may add unwanted delays.Quoted 1 line
Do you have any other insights that can help me further locate the
issue?
Quoted 91 lines
Quoted 65 lines
Quoted 55 lines
Thanks.
Quoted 27 lines
Quoted 1 line
I think current MAC/PHY PM handling isn't perfect. Often we have the following
scenario:*suspend*
1. PHY is suspended (mdio_bus_phy_suspend) 2. MAC suspend callback (typically involvingphy_stop())*resume*
1. MAC resume callback (typically involvingphy_start()) 2. PHY is resumed (mdio_bus_phy_resume), incl. callingphy_init_hw()Calling
phy_init_hw()afterphy_start()doesn't look right. It seems to work in most cases, but there's a certain risk thatphy_init_hw()overwrites something, e.g. the advertised modes. I think we have two valid scenarios:1. phylib PM callbacks are used, then the MAC driver shouldn't touch the PHY in its PM callbacks, especially not call phy_stop/phy_start.
2. MAC PM callbacks take care also of the PHY. Then I think we would need a flag at the
phy_devicetelling it to make the PHY PM callbacks a no-op.Quoted 9 lines
Andrew, Russell: What do you think?
Quoted 5 lines
Best Regards,
Joakim Zhang[...]
Heiner
Based on scenario 1 you can also try the following.
drivers/net/ethernet/freescale/fec_main.c +0
-1@@ -3805,7 +3805,6 @@ static int __maybe_unused fec_suspend(struct device *dev) if (netif_running(ndev)) {if (fep->wol_flag &FEC_WOL_FLAG_ENABLE ) fep->wol_flag |=FEC_WOL_FLAG_SLEEP_ON ; -phy_stop (ndev->phydev);napi_disable (&fep->napi);netif_tx_lock_bh (ndev);drivers/net/ethernet/freescale/fec_main.c +0
-0netif_device_detach (ndev);drivers/net/ethernet/freescale/fec_main.c static int __maybe_unused fec_resume(struct · line 3868
Quoted 7 lines
drivers/net/ethernet/freescale/fec_main.c +0
-1@@ -3864,7 +3863,6 @@ static int __maybe_unused fec_resume(struct device *dev)netif_device_attach (ndev );netif_tx_unlock_bh (ndev);napi_enable (&fep->napi); -phy_start (ndev->phydev); }rtnl_unlock ();As I described in commit message:
Quoted 1 line
"When I am debugging, I found PHY works fine if MAC doesn't support
suspend/resume or phy_stop()/phy_start() doesn't been called during suspend/resume. This let me realize, PHY state machine
phy_state_machine()could do something breaks the PHY."Quoted 3 lines
So I have tried your above code change before, and it works. But it is a very
common phenomenon that MAC suspend/resume invokes phy_stop/start or phylink_stop/start, and it's been around for a long time.
Quoted 3 lines
As the scenarios you list, it is indeed unreasonable to soft reset or config PHY
after calling
phy_start_aneg()in state machine. PHY state should bePHY_UPafter callingphy_init_hw(), It seems more reasonable.Quoted 7 lines
Best Regards,
Joakim ZhangQuoted 3 lines
--
2.31.1Following is a draft patch for scenario 1:
Make PHY PM a no-op if MAC manages PHY PM.
Can you give it a try?
Quoted 5 lines
Quoted 1 line
It can work for my case. Thanks.
I have another question, if it is possible to change the suspend/resume sequence?
MAC should suspend before MDIO bus, and MDIO bus should resume before MAC. For some MACs, they need PHY feed clocks. It seems more reasonable.
On the other hand we have cases where the PHY depends on the MAC. If the MAC suspends first, the MDIO bus (and therefore the PHY) may not be accessible any longer. Therefore it's not that easy.
This speaks for my proposal to be able to make the PHY PM ops no-ops. Then we can handle MAC + PHY PM in the MAC PM callbacks and consider any such dependency.
I don't think we can change the PM ordering, AFAIK the PM core does it based on registration order of devices.
Quoted 74 lines
Best Regards,
Joakim ZhangQuoted 71 lines
Best Regards,
Joakim ZhangQuoted 69 lines
(quoted diff) +0
-0
b/drivers/net/phy/phy_device.cindexa009d1769..73d29fd5e100644drivers/net/phy/phy_device.c +3
-0@@ -273,6 +273,9 @@ static __maybe_unused int mdio_bus_phy_suspend(struct device *dev) {struct phy_device *phydev =to_phy_device (dev); +if (phydev->mac_managed_pm) +return 0 ; +/* We must stop the state machine manually, otherwise it stops out of * control, possibly with the phydev->lock held. Upon resume, netdev * may call phy routines that try to grab the same lock, and that may @@
-294,6 +297,9 @@ static__maybe_unusedintmdio_bus_phy_resume(struct device *dev)drivers/net/phy/phy_device.c +3
-0struct phy_device *phydev =to_phy_device (dev);int ret; +if (phydev->mac_managed_pm) +return 0 ; +if (!phydev->suspended_by_mdio_bus) goto no_resume;include/linux/phy.h index renamed from include/linux/phy.h +0
-0
8e2cf84b2..46702af18100644include/linux/phy.h +1
-1@@ -567,6 +567,7 @@ struct phy_device { unsigned loopback_enabled:1; unsigned downshifted_rate:1; unsigned is_on_sfp_module:1; + unsigned mac_managed_pm:1; unsigned autoneg:1;/* The most recently read link state */ --2.31.1
drivers/net/ethernet/freescale/fec_main.c +2
-0@@ -2048,6 +2048,8 @@ static int fec_enet_mii_probe(struct net_device *ndev) fep->link =0 ; fep->full_duplex =0 ; + phy_dev->mac_managed_pm =1 ; +phy_attached_info (phy_dev);drivers/net/ethernet/freescale/fec_main.c +1
-0return 0 ;@@ -3864,6 +3866,7 @@ static int __maybe_unused fec_resume(struct device *dev)netif_device_attach (ndev );netif_tx_unlock_bh (ndev);napi_enable (&fep->napi); +phy_init_hw (ndev->phydev);phy_start (ndev->phydev); }
rtnl_unlock();
--
2.31.1
Quoted 524 lines
-----Original Message-----
From: Heiner Kallweit <[email protected]>
Sent: 2021年4月7日 18:22
To: Joakim Zhang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; dl-linux-imx <[email protected]>; Florian Fainelli <[email protected]>
Subject: Re: [PATCH] net: phy: fix PHY possibly unwork after MDIO bus resume backQuoted 114 lines · Joakim Zhang
Hi Heiner,
Quoted 111 lines
-----Original Message-----
From: Joakim Zhang <[email protected]>
Sent: 2021年4月7日 15:46
To: Heiner Kallweit <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; dl-linux-imx <[email protected]>; Florian Fainelli <[email protected]>
Subject: RE: [PATCH] net: phy: fix PHY possibly unwork after MDIO bus resume backHi Heiner,
Quoted 12 lines
-----Original Message-----
From: Heiner Kallweit <[email protected]>
Sent: 2021年4月7日 15:12
To: Joakim Zhang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; dl-linux-imx <[email protected]>; Florian Fainelli <[email protected]>
Subject: Re: [PATCH] net: phy: fix PHY possibly unwork after MDIO bus resume backQuoted 63 lines
Quoted 62 lines · Joakim Zhang
Hi Heiner,
Quoted 59 lines
-----Original Message-----
From: Heiner Kallweit <[email protected]>
Sent: 2021年4月7日 2:22
To: Joakim Zhang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Russell King - ARM Linux <[email protected]>
Cc: [email protected]; [email protected]; dl-linux-imx <[email protected]>; Florian Fainelli <[email protected]>
Subject: Re: [PATCH] net: phy: fix PHY possibly unwork after MDIO bus resume backQuoted 28 lines · Heiner Kallweit
Quoted 27 lines · Joakim Zhang
Quoted 27 lines
-----Original Message-----
From: Heiner Kallweit <[email protected]>
Sent: 2021年4月6日 14:29
To: Joakim Zhang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: Re: [PATCH] net: phy: fix PHY possibly unwork after MDIO bus resume backQuoted 14 lines · Joakim Zhang
Hi Heiner,
Quoted 11 lines
-----Original Message-----
From: Heiner Kallweit <[email protected]>
Sent: 2021年4月5日 20:10
To: [email protected]; Joakim Zhang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: Re: [PATCH] net: phy: fix PHY possibly unwork after MDIO bus resume backQuoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines · Christian Melki
Quoted 5 lines · Heiner Kallweit
Quoted 4 lines · Heiner Kallweit
On 04.04.2021 12:07, Joakim Zhang wrote:
commit 4c0d2e96ba055 ("net: phy: consider that
suspend2rammay
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
cut off PHY power") invokes phy_init_hw() when MDIO bus
resume, it will soft reset PHY if PHY driver implements
soft_resetcallback.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
commit 764d31cacfe4 ("net: phy: micrel: set soft_reset
callback to genphy_soft_reset for KSZ8081") adds
soft_reset forKSZ8081.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
After these two patches, I found i.MX6UL 14x14 EVK which
connected to KSZ8081RNB doesn't work any more whensystem
Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
resume
Quoted 10 lines
Quoted 10 lines
Quoted 1 line
Quoted 1 line
back, MAC
driver is
fec_main.c.Quoted 8 lines
Quoted 8 lines
It's obvious that initializing PHY hardware when MDIO bus
resume back would introduce some regression when PHY
implements soft_reset. When IWhy is this obvious? Please elaborate on why a soft reset
should break something.Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
am debugging, I found PHY works fine if MAC doesn't
support suspend/resume or phy_stop()/phy_start() doesn't
been called during suspend/resume. This let me realize,
PHY state machine
phy_state_machine() could do something breaks the PHY.As we known, MAC resume first and then MDIO bus resume
when
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
system resume back from suspend. When MAC resume,
usually
Quoted 34 lines
Quoted 34 lines
Quoted 34 lines
it
Quoted 33 lines
Quoted 33 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
will invoke
phy_start() where to change PHY state to PHY_UP, then
trigger the
stat> machine to run now. In phy_state_machine(), it will
start/config auto-nego, then change PHY state to
PHY_NOLINK, what to next is periodically check PHY link
status. When MDIO bus resume, it will initialize PHY
hardware, including soft_reset, what would soft_reset
affect seems various fromdifferent PHYs.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines
For KSZ8081RNB, when it in PHY_NOLINK state and then
perform a soft reset,it will never complete auto-nego.
Quoted 5 lines
Quoted 5 lines
Why? That would need to be checked in detail. Maybe chip
errata documentation provides a hint.Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
The KSZ8081 spec says the following about bit BMCR_PDOWN:
If software reset (Register 0.15) is used to exit
power-down mode (Register 0.11 = 1), two software reset
writes (Register
0.15 = 1) are required. The first write clears power-down
mode; the second write resets the chip and re-latches the
pin strapping pinvalues.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Maybe this causes the issue you see and genphy_soft_reset()
isn't appropriate for this PHY. Please re-test with the
KSZ8081 soft reset following the spec comment.Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Interesting. Never expected that behavior.
Thanks for catching it. Skimmed through the datasheets/erratas. This is what I found (micrel.c):10/100:
8001 - Unaffected?
8021/8031 - Double reset after PDOWN.
8041 - Errata. PDOWN broken. Recommended do not use.Unclear
Quoted 293 lines
Quoted 293 lines
Quoted 19 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
if reset solves the issue since errata says no error after reset but is also claiming that only toggling PDOWN (may) or power will
help.
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
8051 - Double reset after PDOWN.
8061 - Double reset after PDOWN.
8081 - Double reset after PDOWN.
8091 - Double reset after PDOWN.10/100/1000:
Nothing in gigabit afaics.Switches:
8862 - Not affected?
8863 - Errata. PDOWN broken. Reset will not help. Workaroundexists.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
8864 - Not affected?
8873 - Errata. PDOWN broken. Reset will not help. Workaroundexists.
Quoted 26 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
9477 - Errata. PDOWN broken. Will randomly cause link failure on adjacent links. Do not use.
This certainly explains a lot.
Quoted 2 lines
This patch changes PHY state to PHY_UP when MDIO bus
resume
Quoted 18 lines
Quoted 18 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
back, it should be reasonable after PHY hardware
re-initialized. Also give state machine a chance to
start/configauto-nego again.
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
If the MAC driver calls phy_stop() on suspend, then
phydev->suspended is true and mdio_bus_phy_may_suspend()
phydev->returns
false. As a consequence
phydev->suspended_by_mdio_bus is false and
phydev->mdio_bus_phy_resume()
skips the PHY hw initialization.
Please also note that mdio_bus_phy_suspend() calls
phy_stop_machine() that sets the state to PHY_UP.Forgot that MDIO bus suspend is done before MAC driver
suspend.
Quoted 55 lines
Quoted 55 lines
Quoted 55 lines
Quoted 55 lines
Quoted 55 lines
Quoted 55 lines
Quoted 54 lines
Quoted 45 lines
Quoted 14 lines
Quoted 14 lines
Therefore disregard this part for now.
Having said that the current argumentation isn't convincing.
I'm not aware of such issues on other systems, therefore
it's likely that something is system-dependent.Please check the exact call sequence on your system, maybe
it provides a hint.Signed-off-by: Joakim Zhang <[email protected]>
---
drivers/net/phy/phy_device.c | 7 +++++++
1 file changed, 7 insertions(+)Quoted 7 lines
Quoted 7 lines
diff --git a/drivers/net/phy/phy_device.c
b/drivers/net/phy/phy_device.c index
cc38e326405a..312a6f662481
100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -306,6 +306,13 @@ static __maybe_unused int
mdio_bus_phy_resume(struct device *dev)Quoted 6 lines
Quoted 6 lines
ret = phy_resume(phydev);
if (ret < 0)
return ret;
+
+ /* PHY state could be changed to PHY_NOLINK from MAC
+controllerresume
Quoted 1 line
Quoted 1 line
+ * rounte with phy_start(), here change to PHY_UP after
re-initializing
Quoted 2 lines
Quoted 2 lines
+ * PHY hardware, let PHY state machine to start/config
+auto-negoagain.
Quoted 10 lines
Quoted 9 lines
+ */
+ phydev->state = PHY_UP;
+
no_resume:
if (phydev->attached_dev && phydev->adjust_link)
phy_start_machine(phydev);Quoted 3 lines
This is a quick draft of the modified soft reset for KSZ8081. Some tests would be appreciated.
I test this patch at my side, unfortunately, it still can't work.
I have not found what soft reset would affect in 8081 spec, is there ang common Description for different PHYs?
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
You can check the clause 22 spec: 802.3 22.2.4.1.1
Apart from that you can check BMCR value and which modes your PHY advertises after a soft reset. If the PHY indeed wouldn't restart aneg after a soft reset, then it would be the only one with this behavior I know. And I'd wonder why there aren't more such
reports.
Quoted 139 lines
Quoted 139 lines
Quoted 139 lines
Quoted 6 lines
Quoted 6 lines
Hi Heiner,
We have reasons to believe it is a weird behavior of KSZ8081. I have another two PHYs at my side, AR8031 and RTL8211FD, they can work fine if
soft_resetimplemented.Quoted 3 lines
Quoted 3 lines
As commit message described,
phy_start()would change PHY state to
PHY_UPfinally toPHY_NOLINKwhen MAC resume.Quoted 2 lines
Quoted 2 lines
After MDIO bus resume back, it will periodically check link status. I did below
code change to dump all PHY registers.
Quoted 7 lines
Quoted 7 lines
drivers/net/phy/phy.c +0
-0@@ -35,7 +35,7 @@#include <net/genetlink.h> #include <net/sock.h> Quoted 7 lines
Quoted 7 lines
drivers/net/phy/phy.c +1
-1-#define PHY_STATE_TIME HZ +#define PHY_STATE_TIME (10 * HZ)#define PHY_STATE_STR (_state) \ case PHY_##_state: \@@ -738,6 +738,28 @@ static int phy_check_link_status(struct
phy_device*phydev)
Quoted 99 lines
Quoted 99 lines
if (err) return err;drivers/net/phy/phy.c +22
-0+printk ("offset 0x00 data = %0x\n" ,phy_read (phydev,0x00 )); +printk ("offset 0x01 data = %0x\n" ,phy_read (phydev,0x01 )); +printk ("offset 0x02 data = %0x\n" ,phy_read (phydev,0x02 )); +printk ("offset 0x03 data = %0x\n" ,phy_read (phydev,0x03 )); +printk ("offset 0x04 data = %0x\n" ,phy_read (phydev,0x04 )); +printk ("offset 0x05 data = %0x\n" ,phy_read (phydev,0x05 )); +printk ("offset 0x06 data = %0x\n" ,phy_read (phydev,0x06 )); +printk ("offset 0x07 data = %0x\n" ,phy_read (phydev,0x07 )); +printk ("offset 0x08 data = %0x\n" ,phy_read (phydev,0x08 )); +printk ("offset 0x09 data = %0x\n" ,phy_read (phydev,0x09 )); +printk ("offset 0x10 data = %0x\n" ,phy_read (phydev,0x10 )); +printk ("offset 0x11 data = %0x\n" ,phy_read (phydev,0x11 )); +printk ("offset 0x15 data = %0x\n" ,phy_read (phydev,0x15 )); +printk ("offset 0x16 data = %0x\n" ,phy_read (phydev,0x16 )); +printk ("offset 0x17 data = %0x\n" ,phy_read (phydev,0x17 )); +printk ("offset 0x18 data = %0x\n" ,phy_read (phydev,0x18 )); +printk ("offset 0x1b data = %0x\n" ,phy_read (phydev,0x1b )); +printk ("offset 0x1c data = %0x\n" ,phy_read (phydev,0x1c )); +printk ("offset 0x1d data = %0x\n" ,phy_read (phydev,0x1d )); +printk ("offset 0x1e data = %0x\n" ,phy_read (phydev,0x1e )); +printk ("offset 0x1f data = %0x\n" ,phy_read (phydev,0x1f )); +printk ("\n\n" );if (phydev->link && phydev->state !=PHY_RUNNING ) {phy_check_downshift (phydev); phydev->state =PHY_RUNNING ;After MDIO bus resume back, results as below:
[ 119.545383] offset 0x00 data = 1100 [ 119.549237] offset
0x01data = 7849 [ 119.563125] offset0x02data = 22 [ 119.566810] offset0x03data = 1560 [ 119.570597] offset0x04data = 85e1 [ 119.588016] offset0x05data = 0 [ 119.592891] offset0x06data =
4 [ 119.596452] offset0x07data = 2001 [ 119.600233] offset0x08data = 0 [ 119.617864] offset0x09data = 0 [ 119.625990] offset0x10data = 0 [ 119.629576] offset0x11data = 0 [ 119.642735] offset0x15data = 0 [ 119.646332] offset0x16data = 202 [ 119.650030] offset0x17data = 5c02 [ 119.668054] offset0x18data =
801 [ 119.672997] offset0x1bdata = 0 [ 119.676565] offset0x1cdata = 0 [ 119.680084] offset0x1ddata = 0 [ 119.698031] offset0x1edata = 20 [ 119.706246] offset0x1fdata = 8190 [ 119.709984] [ 119.709984] [ 120.182120] offset0x00data = 100[ 120.185894] offset 0x01 data = 784d [ 120.189681] offset 0x02data = 22 [ 120.206319] offset
0x03data = 1560 [ 120.210171] offset0x04data =
8061 [ 120.225353] offset0x05data = 0 [ 120.228948] offset0x06data = 4 [ 120.242936] offset0x07data = 2001 [ 120.246792] offset0x08data = 0 [ 120.250313] offset0x09data = 0 [ 120.266748] offset0x10data = 0 [ 120.270335] offset0x11data = 0 [ 120.284167] offset0x15data = 0 [ 120.287760] offset0x16data =
202 [ 120.301031] offset0x17data = 3c02 [ 120.313209] offset0x18data = 801 [ 120.316983] offset0x1bdata = 0 [ 120.320513] offset0x1cdata = 1 [ 120.336589] offset0x1ddata = 0 [ 120.340184] offset0x1edata = 115 [ 120.355357] offset0x1fdata = 8190 [ 120.359112] [ 120.359112] [ 129.785396] offset0x00data = 1100 [ 129.789252] offset0x01data = 7849 [ 129.809951] offset0x02data =
22 [ 129.815018] offset0x03data = 1560 [ 129.818845] offset0x04data = 85e1 [ 129.835808] offset0x05data = 0 [ 129.839398] offset0x06data = 4 [ 129.854514] offset0x07data = 2001 [ 129.858371] offset0x08data = 0 [ 129.873357] offset0x09data = 0 [ 129.876954] offset0x10data = 0 [ 129.880472] offset0x11data =
0 [ 129.896450] offset0x15data = 0 [ 129.900038] offset0x16data =
202 [ 129.915041] offset0x17data = 5c02 [ 129.918889] offset0x18data = 801 [ 129.932735] offset0x1bdata = 0 [ 129.946830] offset0x1cdata = 0 [ 129.950424] offset0x1ddata = 0 [ 129.964585] offset0x1edata = 0 [ 129.968192] offset0x1fdata =
8190 [ 129.972938] [ 129.972938] [ 130.425125] offset0x00data =
100 [ 130.428889] offset0x01data = 784d [ 130.442671] offset0x02data =
22 [ 130.446360] offset0x03data = 1560 [ 130.450142] offset0x04data = 8061 [ 130.467207] offset0x05data = 0 [ 130.470789] offset0x06data = 4 [ 130.485071] offset0x07data = 2001 [ 130.488934] offset0x08data = 0 [ 130.504320] offset0x09data = 0 [ 130.507911] offset0x10data = 0 [ 130.520950] offset0x11data =
0 [ 130.532865] offset0x15data = 0 [ 130.536461] offset0x16data =
202 [ 130.540156] offset0x17data = 3c02 [ 130.557218] offset0x18data = 801 [ 130.560987] offset0x1bdata = 0 [ 130.575158] offset0x1cdata = 1 [ 130.578754] offset0x1ddata = 0 [ 130.593543] offset0x1edata = 115 [ 130.597312] offset0x1fdata = 8190Quoted 1 line
Quoted 1 line
We can see that BMCR and BMSR changes from 0x1100,0x7849 to
0x100,0x784d (BMCR[12] bit and BMSR[2]), and loop it.
Quoted 2 lines
Quoted 2 lines
Above process is auto-nego enabled, link is down, auto-nego is disabled, link
is up. And auto-nego complete bit is always 0.
Quoted 3 lines
Quoted 3 lines
PHY seems become unstable if soft reset after start/config auto-nego. I also
want to fix it in micrel driver, but failed.
Quoted 2 lines
Quoted 1 line
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Waiting for
ANEG_COMPLETEto be set wouldn't be a good option. Aneg may never complete for different reasons, e.g. no physical link. And even if we use a timeout this may add unwanted delays.Quoted 2 lines
Do you have any other insights that can help me further locate the
issue?
Quoted 38 lines
Quoted 38 lines
Quoted 38 lines
Thanks.
Quoted 36 lines
Quoted 1 line
I think current MAC/PHY PM handling isn't perfect. Often we have the following
scenario:*suspend*
1. PHY is suspended (mdio_bus_phy_suspend) 2. MAC suspend callback (typically involvingphy_stop())*resume*
1. MAC resume callback (typically involvingphy_start()) 2. PHY is resumed (mdio_bus_phy_resume), incl. callingphy_init_hw()Calling
phy_init_hw()afterphy_start()doesn't look right. It seems to work in most cases, but there's a certain risk thatphy_init_hw()overwrites something, e.g. the advertised modes. I think we have two valid scenarios:1. phylib PM callbacks are used, then the MAC driver shouldn't touch the PHY in its PM callbacks, especially not call phy_stop/phy_start.
2. MAC PM callbacks take care also of the PHY. Then I think we would need a flag at the
phy_devicetelling it to make the PHY PM callbacks a no-op.Andrew, Russell: What do you think?
Quoted 5 lines
Best Regards,
Joakim Zhang[...]
Heiner
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/net/ethernet/freescale/fec_main.c static int __maybe_unused
Quoted 8 lines
Based on scenario 1 you can also try the following.
drivers/net/ethernet/freescale/fec_main.c +0
-0@@ -3805,7 +3805,6 @@ static int __maybe_unusedfec_suspend(struct
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/net/ethernet/freescale/fec_main.c static int __maybe_unused
Quoted 9 lines
drivers/net/ethernet/freescale/fec_main.c +0
-1device *dev) if (netif_running(ndev)) {if (fep->wol_flag &FEC_WOL_FLAG_ENABLE ) fep->wol_flag |=FEC_WOL_FLAG_SLEEP_ON ; -phy_stop (ndev->phydev);napi_disable (&fep->napi);netif_tx_lock_bh (ndev);drivers/net/ethernet/freescale/fec_main.c +0
-0netif_device_detach (ndev);@@ -3864,7 +3863,6 @@ static int __maybe_unusedfec_resume(struct
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
drivers/net/ethernet/freescale/fec_main.c static int __maybe_unused fec_resume(struct device *dev) · line 3872
Quoted 7 lines
drivers/net/ethernet/freescale/fec_main.c +0
-1device *dev)netif_device_attach (ndev );netif_tx_unlock_bh (ndev);napi_enable (&fep->napi); -phy_start (ndev->phydev); }rtnl_unlock ();As I described in commit message:
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 1 line
"When I am debugging, I found PHY works fine if MAC doesn't support
suspend/resume or phy_stop()/phy_start() doesn't been called during suspend/resume. This let me realize, PHY state machine
phy_state_machine()could do something breaks the PHY."Quoted 3 lines
So I have tried your above code change before, and it works. But it is a very
common phenomenon that MAC suspend/resume invokes phy_stop/start
or
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
phylink_stop/start, and it's been around for a long time.
Quoted 3 lines
As the scenarios you list, it is indeed unreasonable to soft reset or config PHY
after calling
phy_start_aneg()in state machine. PHY state should bePHY_UPafter callingphy_init_hw(), It seems more reasonable.Quoted 7 lines
Best Regards,
Joakim ZhangQuoted 3 lines
--
2.31.1Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Following is a draft patch for scenario 1:
Make PHY PM a no-op if MAC manages PHY PM.
Can you give it a try?It can work for my case. Thanks.
I have another question, if it is possible to change the suspend/resume
Quoted 8 lines
sequence?
Quoted 1 line
MAC should suspend before MDIO bus, and MDIO bus should resume before
MAC. For some MACs, they need PHY feed clocks. It seems more reasonable.
Quoted 1 line
On the other hand we have cases where the PHY depends on the MAC. If the MAC suspends first, the MDIO bus (and therefore the PHY) may not be accessible any longer. Therefore it's not that easy.
Yes, right.
Quoted 3 lines
This speaks for my proposal to be able to make the PHY PM ops no-ops. Then we can handle MAC + PHY PM in the MAC PM callbacks and consider any such dependency.
Yes, this can cover different cases.
Quoted 2 lines
I don't think we can change the PM ordering, AFAIK the PM core does it based on registration order of devices.
Learn more. Thanks.
Do you plan to send a formal patch for this?
Best Regards,
Joakim Zhang
Quoted 77 lines
Quoted 13 lines
Best Regards,
Joakim ZhangQuoted 10 lines
Best Regards,
Joakim ZhangQuoted 8 lines
(quoted diff) +0
-0
b/drivers/net/phy/phy_device.cindexa009d1769..73d29fd5e100644drivers/net/phy/phy_device.c +0
-0@@ -273,6 +273,9 @@ static __maybe_unused int mdio_bus_phy_suspend(struct device *dev) {struct phy_device *phydev =to_phy_device (dev);Quoted 4 lines
Quoted 4 lines
drivers/net/phy/phy_device.c static __maybe_unused int mdio_bus_phy_suspend(struct device *dev)
Quoted 4 lines
drivers/net/phy/phy_device.c +3
-0+if (phydev->mac_managed_pm) +return 0 ; +/* We must stop the state machine manually, otherwise it stops out of
Quoted 59 lines
Quoted 58 lines
Quoted 58 lines
drivers/net/phy/phy_device.c +0
-0* control, possibly with the phydev->lock held. Upon resume, netdev * may call phy routines that try to grab the same lock, and that may @@
-294,6 +297,9 @@ static__maybe_unusedintmdio_bus_phy_resume(struct device *dev)drivers/net/phy/phy_device.c +3
-0struct phy_device *phydev =to_phy_device (dev);int ret; +if (phydev->mac_managed_pm) +return 0 ; +if (!phydev->suspended_by_mdio_bus) goto no_resume;include/linux/phy.h index renamed from include/linux/phy.h +0
-0
8e2cf84b2..46702af18100644include/linux/phy.h +1
-1@@ -567,6 +567,7 @@ struct phy_device { unsigned loopback_enabled:1; unsigned downshifted_rate:1; unsigned is_on_sfp_module:1; + unsigned mac_managed_pm:1; unsigned autoneg:1;/* The most recently read link state */ --2.31.1
drivers/net/ethernet/freescale/fec_main.c +0
-0@@ -2048,6 +2048,8 @@ static int fec_enet_mii_probe(struct
net_device
*ndev)drivers/net/ethernet/freescale/fec_main.c +3
-0fep->link =0 ; fep->full_duplex =0 ; + phy_dev->mac_managed_pm =1 ; +phy_attached_info (phy_dev);return 0 ;@@ -3864,6 +3866,7 @@ static int __maybe_unused fec_resume(struct device *dev)netif_device_attach (ndev );netif_tx_unlock_bh (ndev);napi_enable (&fep->napi); +phy_init_hw (ndev->phydev);phy_start (ndev->phydev); }
rtnl_unlock();
--
2.31.1
Quoted 25 lines · Heiner Kallweit
Waiting for
ANEG_COMPLETEto be set wouldn't be a good option. Aneg may never complete for different reasons, e.g. no physical link. And even if we use a timeout this may add unwanted delays.Quoted 2 lines
Do you have any other insights that can help me further locate the issue? Thanks.
I think current MAC/PHY PM handling isn't perfect. Often we have the following scenario:
*suspend*
1. PHY is suspended (mdio_bus_phy_suspend)
2. MAC suspend callback (typically involvingphy_stop())*resume*
1. MAC resume callback (typically involvingphy_start())
2. PHY is resumed (mdio_bus_phy_resume), incl. callingphy_init_hw()Calling
phy_init_hw()afterphy_start()doesn't look right. It seems to work in most cases, but there's a certain risk thatphy_init_hw()overwrites something, e.g. the advertised modes.
I think we have two valid scenarios:
Quoted 7 lines
1. phylib PM callbacks are used, then the MAC driver shouldn't touch the PHY in its PM callbacks, especially not call phy_stop/phy_start.
2. MAC PM callbacks take care also of the PHY. Then I think we would need a flag at the
phy_devicetelling it to make the PHY PM callbacks a no-op.
Maybe part of the problem is that the FEC is calling phy_{stop,start} in its suspend/resume callbacks instead of phy_{suspend,resume} which would play nice and tell the MDIO bus PM callbacks that the PHY has already been suspended.
I am also suspicious about whether Wake-on-LAN actually works with the FEC, you cannot wake from LAN if the PHY is stopped and powered down.
Signature · 1 line
Florian
Heiner Kallweit
maintainerQuoted 32 lines · Florian Fainelli
Quoted 29 lines · Heiner Kallweit
Waiting for
ANEG_COMPLETEto be set wouldn't be a good option. Aneg may never complete for different reasons, e.g. no physical link. And even if we use a timeout this may add unwanted delays.Quoted 2 lines
Do you have any other insights that can help me further locate the issue? Thanks.
I think current MAC/PHY PM handling isn't perfect. Often we have the following scenario:
*suspend*
1. PHY is suspended (mdio_bus_phy_suspend)
2. MAC suspend callback (typically involvingphy_stop())*resume*
1. MAC resume callback (typically involvingphy_start())
2. PHY is resumed (mdio_bus_phy_resume), incl. callingphy_init_hw()Calling
phy_init_hw()afterphy_start()doesn't look right. It seems to work in most cases, but there's a certain risk thatphy_init_hw()overwrites something, e.g. the advertised modes.
I think we have two valid scenarios:1. phylib PM callbacks are used, then the MAC driver shouldn't touch the PHY in its PM callbacks, especially not call phy_stop/phy_start.
Quoted 9 lines
Quoted 3 lines
2. MAC PM callbacks take care also of the PHY. Then I think we would need a flag at the
phy_devicetelling it to make the PHY PM callbacks a no-op.Maybe part of the problem is that the FEC is calling phy_{stop,start} in its suspend/resume callbacks instead of phy_{suspend,resume} which would play nice and tell the MDIO bus PM callbacks that the PHY has already been suspended.
This basically is what I just proposed to test.
Quoted 3 lines
I am also suspicious about whether Wake-on-LAN actually works with the FEC, you cannot wake from LAN if the PHY is stopped and powered down.
phy_stop() calls phy_suspend() which checks for WoL. Therefore this should not be a problem.
Quoted 37 lines · Heiner Kallweit
Quoted 36 lines · Florian Fainelli
Quoted 32 lines · Heiner Kallweit
Waiting for
ANEG_COMPLETEto be set wouldn't be a good option. Aneg may never complete for different reasons, e.g. no physical link. And even if we use a timeout this may add unwanted delays.Quoted 2 lines
Do you have any other insights that can help me further locate the issue? Thanks.
I think current MAC/PHY PM handling isn't perfect. Often we have the following scenario:
*suspend*
1. PHY is suspended (mdio_bus_phy_suspend)
2. MAC suspend callback (typically involvingphy_stop())*resume*
1. MAC resume callback (typically involvingphy_start())
2. PHY is resumed (mdio_bus_phy_resume), incl. callingphy_init_hw()Calling
phy_init_hw()afterphy_start()doesn't look right. It seems to work in most cases, but there's a certain risk thatphy_init_hw()overwrites something, e.g. the advertised modes.
I think we have two valid scenarios:1. phylib PM callbacks are used, then the MAC driver shouldn't touch the PHY in its PM callbacks, especially not call phy_stop/phy_start.
2. MAC PM callbacks take care also of the PHY. Then I think we would need a flag at the
phy_devicetelling it to make the PHY PM callbacks a no-op.
Quoted 6 lines
Quoted 5 lines
Maybe part of the problem is that the FEC is calling phy_{stop,start} in its suspend/resume callbacks instead of phy_{suspend,resume} which would play nice and tell the MDIO bus PM callbacks that the PHY has already been suspended.
This basically is what I just proposed to test.
What you suggested to be tested is to let the MDIO bus PM callbacks deal with suspending the PHY, which is different from having the MAC do it explicitly, both would be interesting to try out.
Quoted 6 lines
Quoted 4 lines
I am also suspicious about whether Wake-on-LAN actually works with the FEC, you cannot wake from LAN if the PHY is stopped and powered down.
phy_stop()callsphy_suspend()which checks for WoL. Therefore this should not be a problem.
Indeed, and I had missed that phy_suspend() checks netdev->wol_enabled, thanks for reminding me.
Signature · 1 line
Florian
Hi Charistian,
Quoted 92 lines
-----Original Message-----
From: Christian Melki <[email protected]>
Sent: 2021年4月5日 16:44
To: Heiner Kallweit <[email protected]>; Joakim Zhang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: Re: [PATCH] net: phy: fix PHY possibly unwork after MDIO bus resume backQuoted 9 lines · Heiner Kallweit
Quoted 8 lines · Heiner Kallweit
Quoted 7 lines · Joakim Zhang
commit
4c0d2e96ba055("net: phy: consider that suspend2ram may cut off PHY power") invokesphy_init_hw()when MDIO bus resume, it will soft reset PHY if PHY driver implementssoft_resetcallback. commit764d31cacfe4("net: phy: micrel: setsoft_resetcallback togenphy_soft_resetfor KSZ8081") addssoft_resetfor KSZ8081. After these two patches, I found i.MX6UL 14x14 EVK which connected to KSZ8081RNB doesn't work any more when system resume back, MACdriver is
fec_main.c.Quoted 13 lines
Quoted 13 lines
Quoted 4 lines
It's obvious that initializing PHY hardware when MDIO bus resume back would introduce some regression when PHY implements
soft_reset. When IWhy is this obvious? Please elaborate on why a soft reset should break something.
Quoted 5 lines
am debugging, I found PHY works fine if MAC doesn't support suspend/resume or phy_stop()/phy_start() doesn't been called during suspend/resume. This let me realize, PHY state machine
phy_state_machine()could do something breaks the PHY.Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
As we known, MAC resume first and then MDIO bus resume when system resume back from suspend. When MAC resume, usually it will invoke
phy_start()where to change PHY state toPHY_UP, then trigger the stat> machine to run now. Inphy_state_machine(), it will start/config auto-nego, then change PHY state toPHY_NOLINK, what to next is periodically check PHY link status. When MDIO bus resume, it will initialize PHY hardware, includingsoft_reset, what wouldsoft_resetaffect seems various from different PHYs. For KSZ8081RNB, when it inPHY_NOLINKstate and then perform a soft reset, it will nevercomplete auto-nego.
Quoted 16 lines
Quoted 4 lines
Why? That would need to be checked in detail. Maybe chip errata documentation provides a hint.
The KSZ8081 spec says the following about bit
BMCR_PDOWN:If software reset (Register 0.15) is
used to exit power-down mode
(Register 0.11 = 1), two software
reset writes (Register 0.15 = 1) are
required. The first write clears
power-down mode; the second
write resets the chip and re-latches
the pin strapping pin values.Quoted 4 lines
Maybe this causes the issue you see and
genphy_soft_reset()isn't appropriate for this PHY. Please re-test with the KSZ8081 soft reset following the spec comment.Interesting. Never expected that behavior.
Thanks for catching it. Skimmed through the datasheets/erratas. This is what I found (micrel.c):10/100:
8001 - Unaffected?
8021/8031 - Double reset after PDOWN.
8041 - Errata. PDOWN broken. Recommended do not use. Unclear if reset solves the issue since errata says no error after reset but is also claiming that only toggling PDOWN (may) or power will help.
8051 - Double reset after PDOWN.
8061 - Double reset after PDOWN.
8081 - Double reset after PDOWN.
8091 - Double reset after PDOWN.10/100/1000:
Nothing in gigabit afaics.Switches:
8862 - Not affected?
8863 - Errata. PDOWN broken. Reset will not help. Workaround exists. 8864 - Not affected?
8873 - Errata. PDOWN broken. Reset will not help. Workaround exists. 9477 - Errata. PDOWN broken. Will randomly cause link failure on adjacent links. Do not use.
Quoted 1 line
This certainly explains a lot.
Thanks for digging into it. As I discussed with you before, there is no problem with these two fixes if I did ifdown/ifup. Almost the same route with suspend/resume. Difference is that it will start state machine after initializing PHY. But when resume back, state machine is running before initializing PHY. I think the key is to figure out what would soft reset affect in 8081, there is no any hint in spec.
Best Regards,
Joakim Zhang
Quoted 56 lines
Quoted 30 lines
Quoted 6 lines
Quoted 5 lines
This patch changes PHY state to
PHY_UPwhen MDIO bus resume back, it should be reasonable after PHY hardware re-initialized. Also give state machine a chance to start/config auto-nego again.Quoted 8 lines
If the MAC driver calls
phy_stop()on suspend, thenphydev->suspendedis true andmdio_bus_phy_may_suspend()returns false. As a consequencephydev->suspended_by_mdio_busis false andmdio_bus_phy_resume()skips the PHY hw initialization.
Please also note thatmdio_bus_phy_suspend()callsphy_stop_machine()that sets the state toPHY_UP.Forgot that MDIO bus suspend is done before MAC driver suspend. Therefore disregard this part for now.
Quoted 12 lines
Having said that the current argumentation isn't convincing. I'm not aware of such issues on other systems, therefore it's likely that something is system-dependent.
Please check the exact call sequence on your system, maybe it provides a hint.
Quoted 5 lines
Signed-off-by Joakim Zhang <[email protected]>--- drivers/net/phy/phy_device.c | 7 +++++++ 1 file changed, 7 insertions(+)Quoted 6 lines
Quoted 6 lines
drivers/net/phy/phy_device.c static __maybe_unused int
Quoted 6 lines
(quoted diff) +0
-0
b/drivers/net/phy/phy_device.cindexcc38e326405a..312a6f662481100644drivers/net/phy/phy_device.c +0
-0@@ -306,6 +306,13 @@ static __maybe_unused int
mdio_bus_phy_resume(struct device *dev)Quoted 5 lines
Quoted 5 lines
drivers/net/phy/phy_device.c static __maybe_unused int mdio_bus_phy_resume(struct device *dev)
Quoted 5 lines
drivers/net/phy/phy_device.c +2
-0ret =phy_resume (phydev);if (ret <0 )return ret; + +/* PHY state could be changed to PHY_NOLINK from MAC controller resume
Quoted 1 line
Quoted 1 line
drivers/net/phy/phy_device.c static __maybe_unused int · line 311
Quoted 1 line
drivers/net/phy/phy_device.c +1
-0+* rounte with phy_start(), here change to PHY_UP after re-initializing
Quoted 1 line
Quoted 1 line
drivers/net/phy/phy_device.c static __maybe_unused int · line 312
Quoted 1 line
drivers/net/phy/phy_device.c +1
-0+* PHY hardware, let PHY state machine to start/config auto-nego again.
Quoted 9 lines
Quoted 8 lines
Quoted 7 lines
drivers/net/phy/phy_device.c +3
-0+*/ + phydev->state =PHY_UP ; + no_resume:if (phydev->attached_dev && phydev->adjust_link)phy_start_machine (phydev);
Hi Heiner,
Quoted 59 lines
-----Original Message-----
From: Heiner Kallweit <[email protected]>
Sent: 2021年4月5日 6:49
To: Joakim Zhang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; dl-linux-imx <[email protected]>; [email protected]
Subject: Re: [PATCH] net: phy: fix PHY possibly unwork after MDIO bus resume backQuoted 8 lines · Heiner Kallweit
Quoted 7 lines · Joakim Zhang
commit
4c0d2e96ba055("net: phy: consider that suspend2ram may cut off PHY power") invokesphy_init_hw()when MDIO bus resume, it will soft reset PHY if PHY driver implementssoft_resetcallback. commit764d31cacfe4("net: phy: micrel: setsoft_resetcallback togenphy_soft_resetfor KSZ8081") addssoft_resetfor KSZ8081. After these two patches, I found i.MX6UL 14x14 EVK which connected to KSZ8081RNB doesn't work any more when system resume back, MAC driveris
fec_main.c.Quoted 22 lines
Quoted 4 lines
It's obvious that initializing PHY hardware when MDIO bus resume back would introduce some regression when PHY implements
soft_reset. When IWhy is this obvious? Please elaborate on why a soft reset should break something.
Quoted 14 lines
am debugging, I found PHY works fine if MAC doesn't support suspend/resume or phy_stop()/phy_start() doesn't been called during suspend/resume. This let me realize, PHY state machine
phy_state_machine()could do something breaks the PHY.As we known, MAC resume first and then MDIO bus resume when system resume back from suspend. When MAC resume, usually it will invoke
phy_start()where to change PHY state toPHY_UP, then trigger the stat> machine to run now. Inphy_state_machine(), it will start/config auto-nego, then change PHY state toPHY_NOLINK, what to next is periodically check PHY link status. When MDIO bus resume, it will initialize PHY hardware, includingsoft_reset, what wouldsoft_resetaffect seems various from different PHYs. For KSZ8081RNB, when it inPHY_NOLINKstate and then perform a soft reset, it will nevercomplete auto-nego.
Quoted 4 lines
Why? That would need to be checked in detail. Maybe chip errata documentation provides a hint.
The KSZ8081 spec says the following about bit
BMCR_PDOWN:If software reset (Register 0.15) is
used to exit power-down mode
(Register 0.11 = 1), two software
reset writes (Register 0.15 = 1) are
required. The first write clears
power-down mode; the second
write resets the chip and re-latches
the pin strapping pin values.
Quoted 3 lines
Maybe this causes the issue you see and
genphy_soft_reset()isn't appropriate for this PHY. Please re-test with the KSZ8081 soft reset following the spec comment.
Yes, I also noticed this note in spec, and tried to soft reset twice from PHY driver, but still can't work.
What is strange is that, ifup/ifdown can work fine, which is almost the same route with suspend/resume, except suspend/resume has state machine running.
Quoted 15 lines
Quoted 7 lines
Quoted 6 lines
This patch changes PHY state to
PHY_UPwhen MDIO bus resume back, it should be reasonable after PHY hardware re-initialized. Also give state machine a chance to start/config auto-nego again.Quoted 7 lines
If the MAC driver calls
phy_stop()on suspend, thenphydev->suspendedis true andmdio_bus_phy_may_suspend()returns false. As a consequencephydev->suspended_by_mdio_busis false andmdio_bus_phy_resume()skips the PHY hw initialization.
Please also note thatmdio_bus_phy_suspend()callsphy_stop_machine()that sets the state toPHY_UP.
Quoted 2 lines
Forgot that MDIO bus suspend is done before MAC driver suspend. Therefore disregard this part for now.
OK.
Best Regards,
Joakim Zhang
Quoted 35 lines
Quoted 12 lines
Having said that the current argumentation isn't convincing. I'm not aware of such issues on other systems, therefore it's likely that something is system-dependent.
Please check the exact call sequence on your system, maybe it provides a hint.
Quoted 5 lines
Signed-off-by Joakim Zhang <[email protected]>--- drivers/net/phy/phy_device.c | 7 +++++++ 1 file changed, 7 insertions(+)Quoted 6 lines
drivers/net/phy/phy_device.c static __maybe_unused int
Quoted 6 lines
(quoted diff) +0
-0
b/drivers/net/phy/phy_device.cindexcc38e326405a..312a6f662481100644drivers/net/phy/phy_device.c +0
-0@@ -306,6 +306,13 @@ static __maybe_unused int
mdio_bus_phy_resume(struct device *dev)Quoted 5 lines
drivers/net/phy/phy_device.c static __maybe_unused int mdio_bus_phy_resume(struct device *dev)
Quoted 5 lines
drivers/net/phy/phy_device.c +2
-0ret =phy_resume (phydev);if (ret <0 )return ret; + +/* PHY state could be changed to PHY_NOLINK from MAC controller resume
Quoted 10 lines
Quoted 9 lines
drivers/net/phy/phy_device.c +5
-0+* rounte with phy_start(), here change to PHY_UP after re-initializing +* PHY hardware, let PHY state machine to start/config auto-nego again. +*/ + phydev->state =PHY_UP ; + no_resume:if (phydev->attached_dev && phydev->adjust_link)phy_start_machine (phydev);
Hi Heiner,
Thanks for your comments.
Quoted 18 lines
-----Original Message-----
From: Heiner Kallweit <[email protected]>
Sent: 2021年4月4日 22:09
To: Joakim Zhang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; dl-linux-imx <[email protected]>; [email protected]
Subject: Re: [PATCH] net: phy: fix PHY possibly unwork after MDIO bus resume backQuoted 7 lines · Joakim Zhang
commit
4c0d2e96ba055("net: phy: consider that suspend2ram may cut off PHY power") invokesphy_init_hw()when MDIO bus resume, it will soft reset PHY if PHY driver implementssoft_resetcallback. commit764d31cacfe4("net: phy: micrel: setsoft_resetcallback togenphy_soft_resetfor KSZ8081") addssoft_resetfor KSZ8081. After these two patches, I found i.MX6UL 14x14 EVK which connected to KSZ8081RNB doesn't work any more when system resume back, MAC driver
Quoted 7 lines
is
fec_main.c.Quoted 3 lines
It's obvious that initializing PHY hardware when MDIO bus resume back would introduce some regression when PHY implements
soft_reset. When IWhy is this obvious? Please elaborate on why a soft reset should break something.
This obvious since only above two fixes work together can trigger this issue at my side.
Quoted 25 lines
Quoted 5 lines
am debugging, I found PHY works fine if MAC doesn't support suspend/resume or phy_stop()/phy_start() doesn't been called during suspend/resume. This let me realize, PHY state machine
phy_state_machine()could do something breaks the PHY.Quoted 9 lines
As we known, MAC resume first and then MDIO bus resume when system resume back from suspend. When MAC resume, usually it will invoke
phy_start()where to change PHY state toPHY_UP, then trigger the stat> machine to run now. Inphy_state_machine(), it will start/config auto-nego, then change PHY state toPHY_NOLINK, what to next is periodically check PHY link status. When MDIO bus resume, it will initialize PHY hardware, includingsoft_reset, what wouldsoft_resetaffect seems various from different PHYs. For KSZ8081RNB, when it inPHY_NOLINKstate and then perform a soft reset, it will never completeauto-nego.
Why? That would need to be checked in detail. Maybe chip errata documentation provides a hint.
Quoted 5 lines
This patch changes PHY state to
PHY_UPwhen MDIO bus resume back, it should be reasonable after PHY hardware re-initialized. Also give state machine a chance to start/config auto-nego again.
Quoted 4 lines
If the MAC driver calls
phy_stop()on suspend, thenphydev->suspendedis true andmdio_bus_phy_may_suspend()returns false. As a consequencephydev->suspended_by_mdio_busis false andmdio_bus_phy_resume()skips the PHY hw initialization.
Per my debugging, MDIO bus suspended before MAC, I think it is a common behavior, so PHY hw initialization is always called. Does this behavior be system-dependent?
Best Regards,
Joakim Zhang
Quoted 35 lines
Please also note that
mdio_bus_phy_suspend()callsphy_stop_machine()that sets the state toPHY_UP.Having said that the current argumentation isn't convincing. I'm not aware of such issues on other systems, therefore it's likely that something is system-dependent.
Please check the exact call sequence on your system, maybe it provides a hint.
drivers/net/phy/phy_device.c static __maybe_unused int
Quoted 10 lines
Signed-off-by Joakim Zhang <[email protected]>--- drivers/net/phy/phy_device.c | 7 +++++++ 1 file changed, 7 insertions(+)(quoted diff) +0
-0
b/drivers/net/phy/phy_device.cindexcc38e326405a..312a6f662481100644drivers/net/phy/phy_device.c +0
-0@@ -306,6 +306,13 @@ static __maybe_unused int
mdio_bus_phy_resume(struct device *dev)drivers/net/phy/phy_device.c static __maybe_unused int mdio_bus_phy_resume(struct device *dev)
Quoted 5 lines
drivers/net/phy/phy_device.c +2
-0ret =phy_resume (phydev);if (ret <0 )return ret; + +/* PHY state could be changed to PHY_NOLINK from MAC controller resume
Quoted 9 lines
drivers/net/phy/phy_device.c +5
-0+* rounte with phy_start(), here change to PHY_UP after re-initializing +* PHY hardware, let PHY state machine to start/config auto-nego again. +*/ + phydev->state =PHY_UP ; + no_resume:if (phydev->attached_dev && phydev->adjust_link)phy_start_machine (phydev);