net: stmmac: fix resume failures due to RX clock
Subsystems (7)
Russell King (Oracle)
maintainercover net: stmmac: fix resume failures due to RX clock
Hi,
This series is likely dependent on the "net: stmmac: cleanup transmit clock setting" series which was submitted earlier today.
stmmac has a long history of failing to resume due to lack of receive clock. NVidia have reported that as a result of the EEE changes, they see a greater chance of resume failure with those patches applied than before.
The issue is that the DesignWare core requires that the receive clock is running in order to complete software reset, which causes stmmac_reset() and stmmac_hw_setup() to fail.
There are several things that are wrong:
1. Calling phylink_start() early can result in a call to mac_link_up() which will set TE and RE bits before stmmac_hw_setup() has been called. This is evident in the debug logs that NVidia sent while debugging the problem.
This is something I have pointed out in the past, but ithas been claimed to be necessary to do things this way to have the PHY receive clock running. Enabling RE before DMA is setup is against the DesignWare databook documentation.
2. Enabling LPI clock-stop at the PHY (as the driver has done prior to my patch set) allows the PHY to stop its receive clock when the link enters low-power mode. This means the completion of reset is dependent on the current EEE state, which is indeterminable, but is likely to be in low power mode on resume.
We solve (1) by moving the call to phylink_resume() later. This patch on its own probably causes regressions as it may make it more likely that the link will be in low power state, or maybe the PHY driver does not respect the PHY_F_RXC_ALWAYS_ON flag - this needs to be tested on as many different hardware setups that use this driver as possible, and any issues addressed *without* moving phylink_resume() back. If we need some way to resume the PHY early, then we need to work out some way to do that with phylib without calling phy_start() early.
(2) is fixed by introducing phylink_prepare_resume(), which will disable receive clock-stop in LPI mode at the PHY, and we will restore the clock-stop setting in phylink_resume(). It is possible that this solves some of the reason for the early placement of phylink_resume().
phylink_prepare_resume() also provides a convenient site should (1) need further work.
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 27 +++++++-------- drivers/net/phy/phylink.c | 40 ++++++++++++++++++++++- include/linux/phylink.h | 1 + 3 files changed, 51 insertions(+), 17 deletions(-)
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
RFC PATCH 1/5 net: phylink: add config of PHY receive clock-stop in phylink_resume()
--- drivers/net/phy/phylink.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
drivers/net/phy/phylink.c +15 -1
@@ -2264,7 +2264,7 @@ static int phylink_bringup_phy(struct phylink *pl, struct phy_device *phy, pl->mac_tx_clk_stop =phy_eee_tx_clock_stop_capable (phy) >0 ;if (pl->mac_supports_eee_ops) { -/* Explicitly configure whether the PHY is allowed to stop it's +/* Explicitly configure whether the PHY is allowed to stop its * receive clock. */ ret = phy_eee_rx_clock_stop(phy,
@@ -2645,8 +2645,22 @@ EXPORT_SYMBOL_GPL(phylink_suspend);*/ void phylink_resume (struct phylink *pl) { +int ret; +ASSERT_RTNL (); +if (pl->mac_supports_eee_ops && pl->phydev) { +/* Explicitly configure whether the PHY is allowed to stop its +* receive clock on resume to ensure that it is correctly +* configured. +*/ + ret =phy_eee_rx_clock_stop (pl->phydev, + pl->config->eee_rx_clk_stop_enable); +if (ret == -EOPNOTSUPP ) +phylink_warn (pl,"failed to set rx clock stop: %pe\n" , +ERR_PTR (ret)); + } +if (test_bit (PHYLINK_DISABLE_MAC_WOL , &pl->phylink_disable_state)) {/* Wake-on-Lan enabled, MAC handling */
Signature · 1 line
2.30.2
RFC PATCH 2/5 net: phylink: add phylink_prepare_resume()
In reply to Russell King (Oracle)Add a resume preparation function, which will ensure that the receive clock from the PHY is appropriately configured while resuming.
--- drivers/net/phy/phylink.c | 24 ++++++++++++++++++++++++ include/linux/phylink.h | 1 + 2 files changed, 25 insertions(+)
drivers/net/phy/phylink.c +24 -0
@@ -2636,6 +2636,30 @@ void phylink_suspend(struct phylink *pl, bool mac_wol) }EXPORT_SYMBOL_GPL (phylink_suspend); +/** +* phylink_prepare_resume() - prepare to resume a network device +* @pl: a pointer to a &struct phylink returned from phylink_create() +* +* Optional, thus must be called prior to phylink_resume(). +* +* Prepare to resume a network device, preparing the PHY as necessary. +*/ +void phylink_prepare_resume (struct phylink *pl) +{ +ASSERT_RTNL (); + +/* If the MAC requires the receive clock, but receive clock +* stop was enabled at the PHY, we need to ensure that the +* receive clock is running. Disable receive clock stop. +* phylink_resume() will re-enable it if necessary. +*/ +if (pl->mac_supports_eee_ops && pl->phydev && + pl->config->mac_requires_rxc && + pl->config->eee_rx_clk_stop_enable) +phy_eee_rx_clock_stop (pl->phydev, false); +} +EXPORT_SYMBOL_GPL (phylink_prepare_resume); +/** * phylink_resume() - handle a network device resume event * @pl: a pointer to a &struct phylink returned from phylink_create()
include/linux/phylink.h +1 -0
@@ -699,6 +699,7 @@ void phylink_start(struct phylink *);void phylink_stop (struct phylink *);void phylink_suspend (struct phylink *pl,bool mac_wol); +void phylink_prepare_resume (struct phylink *pl);void phylink_resume (struct phylink *pl);void phylink_ethtool_get_wol (struct phylink *,struct ethtool_wolinfo *);
Signature · 1 line
2.30.2
RFC PATCH 3/5 net: stmmac: simplify phylink_suspend() and phylink_resume() calls
In reply to Russell King (Oracle)Currently, the calls to phylink's suspend and resume functions are inside overly complex tests, and boil down to:
if (device_may_wakeup(priv->device) && priv->plat->pmt) {
call phylink
} else {
call phylink and
if (device_may_wakeup(priv->device))
do something else
}This results in phylink always being called, possibly with differing arguments for phylink_suspend().
Simplify this code, noting that each site is slightly different due to the order in which phylink is called and the "something else".
--- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +8 -14
@@ -7831,13 +7831,11 @@ int stmmac_suspend(struct device *dev)mutex_unlock (&priv->lock);rtnl_lock (); -if (device_may_wakeup (priv->device) && priv->plat->pmt) { -phylink_suspend (priv->phylink, true); - }else { -if (device_may_wakeup (priv->device)) -phylink_speed_down (priv->phylink, false); -phylink_suspend (priv->phylink, false); - } +if (device_may_wakeup (priv->device) && !priv->plat->pmt) +phylink_speed_down (priv->phylink, false); + +phylink_suspend (priv->phylink, +device_may_wakeup (priv->device) && priv->plat->pmt);rtnl_unlock ();if (stmmac_fpe_supported (priv))
@@ -7927,13 +7925,9 @@ int stmmac_resume(struct device *dev) }rtnl_lock (); -if (device_may_wakeup (priv->device) && priv->plat->pmt) { -phylink_resume (priv->phylink); - }else { -phylink_resume (priv->phylink); -if (device_may_wakeup (priv->device)) -phylink_speed_up (priv->phylink); - } +phylink_resume (priv->phylink); +if (device_may_wakeup (priv->device) && !priv->plat->pmt) +phylink_speed_up (priv->phylink);rtnl_unlock ();rtnl_lock ();
Signature · 1 line
2.30.2
RFC PATCH 4/5 net: stmmac: move phylink_resume() after resume setup is complete
In reply to Russell King (Oracle)Move phylink_resume() to be after the setup in stmmac_resume() has completed, as phylink_resume() may result in an immediate call to the .mac_link_up method, which will enable the transmitter and receiver, and enable the transmit queues.
This behaviour has been witnessed by Jon Hunter on the Jetson TX2 platform (Tegra 186).
--- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +5 -6
@@ -7924,12 +7924,6 @@ int stmmac_resume(struct device *dev)return ret; } -rtnl_lock (); -phylink_resume (priv->phylink); -if (device_may_wakeup (priv->device) && !priv->plat->pmt) -phylink_speed_up (priv->phylink); -rtnl_unlock (); -rtnl_lock ();mutex_lock (&priv->lock);
@@ -7948,6 +7942,11 @@ int stmmac_resume(struct device *dev)stmmac_enable_all_dma_irq (priv);mutex_unlock (&priv->lock); + +phylink_resume (priv->phylink); +if (device_may_wakeup (priv->device) && !priv->plat->pmt) +phylink_speed_up (priv->phylink); +rtnl_unlock ();netif_device_attach (ndev);
Signature · 1 line
2.30.2
RFC PATCH 5/5 net: stmmac: fix resume when media is in low-power mode
In reply to Russell King (Oracle)The Synopsys Designwavre GMAC core databook requires all clocks to be active in order to complete software reset.
This means if the PHY receive clock has been stopped due to the media being in EEE low-power state, and the PHY being permitted to stop its clock, then software reset will not complete.
Phylink now provides a way to work around this by calling phylink_prepare_resume() before attempting to issue a reset. This will prepare any attached PHY by disabling its permission to stop the clock. phylink_resume() will restore the receive clock stop setting according to the configuration passed from the netdev driver.
--- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +2 -0
@@ -7925,6 +7925,8 @@ int stmmac_resume(struct device *dev) }rtnl_lock (); +phylink_prepare_resume (priv->phylink); +mutex_lock (&priv->lock);stmmac_reset_queues_param (priv);
Signature · 1 line
2.30.2
Re: [PATCH RFC net-next 1/5] net: phylink: add config of PHY receive clock-stop in phylink_resume()
In reply to Russell King (Oracle)Quoted 1 line · Russell King (Oracle)
Signed-off-by Russell King (Oracle) <[email protected]>
Andrew
Re: [PATCH RFC net-next 2/5] net: phylink: add phylink_prepare_resume()
In reply to Russell King (Oracle)Quoted 4 lines · Russell King (Oracle)
Add a resume preparation function, which will ensure that the receive clock from the PHY is appropriately configured while resuming.
Signed-off-by Russell King (Oracle) <[email protected]>
Andrew
Re: [PATCH RFC net-next 3/5] net: stmmac: simplify phylink_suspend() and phylink_resume() calls
In reply to Russell King (Oracle)Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +0
-3@@ -7927,13 +7925,9 @@ int stmmac_resume(struct device *dev) }rtnl_lock (); -if (device_may_wakeup (priv->device) && priv->plat->pmt) { -phylink_resume (priv->phylink); - }else {
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c int stmmac_resume(struct device *dev) · line 7933
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +3
-4-phylink_resume (priv->phylink); -if (device_may_wakeup (priv->device)) -phylink_speed_up (priv->phylink); - } +phylink_resume (priv->phylink); +if (device_may_wakeup (priv->device) && !priv->plat->pmt) +phylink_speed_up (priv->phylink);rtnl_unlock ();rtnl_lock ();
Unrelated to this patch, but unlock() followed by lock()? Seems like some more code which could be cleaned up?
Andrew
Re: [PATCH RFC net-next 4/5] net: stmmac: move phylink_resume() after resume setup is complete
In reply to Russell King (Oracle)Quoted 9 lines · Russell King (Oracle)
Move
phylink_resume()to be after the setup instmmac_resume()has completed, asphylink_resume()may result in an immediate call to the .mac_link_up method, which will enable the transmitter and receiver, and enable the transmit queues.This behaviour has been witnessed by Jon Hunter on the Jetson TX2 platform (Tegra 186).
Signed-off-by Russell King (Oracle) <[email protected]>
Andrew
Re: [PATCH RFC net-next 5/5] net: stmmac: fix resume when media is in low-power mode
In reply to Russell King (Oracle)Quoted 7 lines · Russell King (Oracle)
The Synopsys Designwavre GMAC core databook requires all clocks to be active in order to complete software reset.
This means if the PHY receive clock has been stopped due to the media being in EEE low-power state, and the PHY being permitted to stop its clock, then software reset will not complete.
Quoted 7 lines
Phylink now provides a way to work around this by calling
phylink_prepare_resume()before attempting to issue a reset. This will prepare any attached PHY by disabling its permission to stop the clock.phylink_resume()will restore the receive clock stop setting according to the configuration passed from the netdev driver.Signed-off-by Russell King (Oracle) <[email protected]>
Andrew
Russell King (Oracle)
maintainerRe: [PATCH RFC net-next 3/5] net: stmmac: simplify phylink_suspend() and phylink_resume() calls
In reply to Andrew LunnQuoted 16 lines · Andrew Lunn
Quoted 16 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +3
-7@@ -7927,13 +7925,9 @@ int stmmac_resume(struct device *dev) }rtnl_lock (); -if (device_may_wakeup (priv->device) && priv->plat->pmt) { -phylink_resume (priv->phylink); - }else { -phylink_resume (priv->phylink); -if (device_may_wakeup (priv->device)) -phylink_speed_up (priv->phylink); - } +phylink_resume (priv->phylink); +if (device_may_wakeup (priv->device) && !priv->plat->pmt) +phylink_speed_up (priv->phylink);rtnl_unlock ();
Quoted 4 lines
Review int stmmac_resume(struct device *dev) · line 7933
Quoted 1 line
(quoted diff) +0
-0rtnl_lock();Unrelated to this patch, but
unlock()followed bylock()? Seems like some more code which could be cleaned up?
Indeed, this vanishes in the next patch due to phylink_resume() moving later.
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
Hi Russell,
Quoted 4 lines · Russell King (Oracle)
Hi,
This series is likely dependent on the "net: stmmac: cleanup transmit clock setting" series which was submitted earlier today.
I tested this series without the above on top of mainline and I still saw some issues with suspend. However, when testing this on top of -next (which has the referenced series) it works like a charm. So yes it does appear to be dependent indeed.
I have tested this on Tegra186, Tegra194 and Tegra234 with -next and all are working fine. So with that feel free to add my ...
Thanks!
Jon
Signature · 1 line
nvpublic
Russell King (Oracle)
maintainerQuoted 13 lines · Jon Hunter
Hi Russell,
Quoted 4 lines · Russell King (Oracle)
Hi,
This series is likely dependent on the "net: stmmac: cleanup transmit clock setting" series which was submitted earlier today.
I tested this series without the above on top of mainline and I still saw some issues with suspend. However, when testing this on top of -next (which has the referenced series) it works like a charm. So yes it does appear to be dependent indeed.
Quoted 4 lines
I have tested this on Tegra186, Tegra194 and Tegra234 with -next and all are working fine. So with that feel free to add my ...
Tested-by Jon Hunter <[email protected]>
Hi Jon,
I came up with an alternative approach which should make this safer - for example, if the PHY remains linked with the partner over an ifdown or module remove/re-insert.
Please see v2 of "net: stmmac: approach 2 to solve EEE LPI reset issues" which replaces this series.
https://lore.kernel.org/r/[email protected]
Thanks.
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!