Skip to contentSkip to conversation

fix mac not working after system resumed with WoL enabled

PATCH In review Clark Wang 3 participants 7 messages Dec 21, 2022 – Jan 3, 2023

Subsystems (6)
lore
Share & tools
lore

Clark Wang

author
#0 lore raw

v2 cover fix mac not working after system resumed with WoL enabled

Hi,
The issue description is in the commit message.

This patchset is the second version following discussions with Russell. But the name of each patch has changed, so V2 is not marked in each patch.

Thanks.

Clark Wang (2):
net: phylink: add a function to resume phy alone to fix resume issue
with WoL enabled
net: stmmac: resume phy separately before calling stmmac_hw_setup()

 .../net/ethernet/stmicro/stmmac/stmmac_main.c | 16 +++++++-------
 drivers/net/phy/phylink.c                     | 21 ++++++++++++++++++-
 include/linux/phylink.h                       |  1 +
 3 files changed, 28 insertions(+), 10 deletions(-)
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH v2 1/2 net: phylink: add a function to resume phy alone to fix resume issue with WoL enabled

Issue we met:
On some platforms, mac cannot work after resumed from the suspend with WoL enabled.

The cause of the issue:
1. phylink_resolve() is in a workqueue which will not be executed immediately. This is the call sequence:

       phylink_resolve()->phylink_link_up()->pl->mac_ops->mac_link_up()

For stmmac driver, mac_link_up() will set the correct speed/duplex... values which are from link_state.
2. In stmmac_resume(), it will call stmmac_hw_setup() after called the phylink_resume(), because mac need phy rx_clk to do the reset. stmmac_core_init() is called in function stmmac_hw_setup(), which will reset the mac and set the speed/duplex... to default value.
Conclusion: Because phylink_resolve() cannot determine when it is called, it
cannot be guaranteed to be called after stmmac_core_init(). Once stmmac_core_init() is called after phylink_resolve(), the mac will be misconfigured and cannot be used.

In order to avoid this problem, add a function called phylink_phy_resume() to resume phy separately. This eliminates the need to call phylink_resume() before stmmac_hw_setup().

Add another judgement before called phy_start() in phylink_start(). This way phy_start() will not be called multiple times when resumes. At the same time, it may not affect other drivers that do not use phylink_phy_resume().

---
 drivers/net/phy/phylink.c | 21 ++++++++++++++++++++-
 include/linux/phylink.h   |  1 +
 2 files changed, 21 insertions(+), 1 deletion(-)
drivers/net/phy/phylink.c +20 -1
index 09cc65c0da93..5bab59142579 100644
@@ -1939,7 +1939,7 @@ void phylink_start(struct phylink *pl)
 	}
 	if (poll)
 		mod_timer(&pl->link_poll, jiffies + HZ);
-	if (pl->phydev)
+	if (pl->phydev && pl->phydev->state < PHY_UP)
 		phy_start(pl->phydev);
 	if (pl->sfp_bus)
 		sfp_upstream_start(pl->sfp_bus);
@@ -2020,6 +2020,25 @@ void phylink_suspend(struct phylink *pl, bool mac_wol)
 }
 EXPORT_SYMBOL_GPL(phylink_suspend);
 
+/**
+ * phylink_phy_resume() - resume phy alone
+ * @pl: a pointer to a &struct phylink returned from phylink_create()
+ *
+ * In the MAC driver using phylink, if the MAC needs the clock of the phy
+ * when it resumes, can call this function to resume the phy separately.
+ * Then proceed to MAC resume operations.
+ */
+void phylink_phy_resume(struct phylink *pl)
+{
+	ASSERT_RTNL();
+
+	if (!test_bit(PHYLINK_DISABLE_MAC_WOL, &pl->phylink_disable_state)
+	    && pl->phydev)
+		phy_start(pl->phydev);
+
+}
+EXPORT_SYMBOL_GPL(phylink_phy_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
index c492c26202b5..6edfab5f754c 100644
@@ -589,6 +589,7 @@ void phylink_stop(struct phylink *);
 
 void phylink_suspend(struct phylink *pl, bool mac_wol);
 void phylink_resume(struct phylink *pl);
+void phylink_phy_resume(struct phylink *pl);
 
 void phylink_ethtool_get_wol(struct phylink *, struct ethtool_wolinfo *);
 int phylink_ethtool_set_wol(struct phylink *, struct ethtool_wolinfo *);
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH 1/2] net: phylink: add a function to resume phy alone to fix resume issue with WoL enabled

Quoted 19 lines · Clark Wang

Issue we met:
On some platforms, mac cannot work after resumed from the suspend with WoL enabled.

The cause of the issue:
1. phylink_resolve() is in a workqueue which will not be executed immediately. This is the call sequence:

       phylink_resolve()->phylink_link_up()->pl->mac_ops->mac_link_up()

For stmmac driver, mac_link_up() will set the correct speed/duplex... values which are from link_state.
2. In stmmac_resume(), it will call stmmac_hw_setup() after called the phylink_resume(), because mac need phy rx_clk to do the reset. stmmac_core_init() is called in function stmmac_hw_setup(), which will reset the mac and set the speed/duplex... to default value.
Conclusion: Because phylink_resolve() cannot determine when it is called, it
cannot be guaranteed to be called after stmmac_core_init(). Once stmmac_core_init() is called after phylink_resolve(), the mac will be misconfigured and cannot be used.

Quoted 8 lines

In order to avoid this problem, add a function called phylink_phy_resume() to resume phy separately. This eliminates the need to call phylink_resume() before stmmac_hw_setup().

Add another judgement before called phy_start() in phylink_start(). This way phy_start() will not be called multiple times when resumes. At the same time, it may not affect other drivers that do not use phylink_phy_resume().

It'd be nice to see Fixes tag.

Quoted 27 lines
---
 drivers/net/phy/phylink.c | 21 ++++++++++++++++++++-
 include/linux/phylink.h   |  1 +
 2 files changed, 21 insertions(+), 1 deletion(-)
drivers/net/phy/phylink.c +5 -1
index 09cc65c0da93..5bab59142579 100644
@@ -1939,7 +1939,7 @@ void phylink_start(struct phylink *pl)
 	}
 	if (poll)
 		mod_timer(&pl->link_poll, jiffies + HZ);
-	if (pl->phydev)
+	if (pl->phydev && pl->phydev->state < PHY_UP)
 		phy_start(pl->phydev);
 	if (pl->sfp_bus)
 		sfp_upstream_start(pl->sfp_bus);
@@ -2020,6 +2020,25 @@ void phylink_suspend(struct phylink *pl, bool mac_wol)
 }
 EXPORT_SYMBOL_GPL(phylink_suspend);
 
+/**
+ * phylink_phy_resume() - resume phy alone
+ * @pl: a pointer to a &struct phylink returned from phylink_create()
+ *

drivers/net/phy/phylink.c void phylink_suspend(struct phylink *pl, bool mac_wol) · line 2036

Quoted 10 lines
drivers/net/phy/phylink.c +10 -0
+ * In the MAC driver using phylink, if the MAC needs the clock of the phy
+ * when it resumes, can call this function to resume the phy separately.
+ * Then proceed to MAC resume operations.
+ */
+void phylink_phy_resume(struct phylink *pl)
+{
+	ASSERT_RTNL();
+
+	if (!test_bit(PHYLINK_DISABLE_MAC_WOL, &pl->phylink_disable_state)
+	    && pl->phydev)

you can fit && at the end of the previous line.

drivers/net/phy/phylink.c void phylink_suspend(struct phylink *pl, bool mac_wol) · line 2038

Quoted 2 lines
drivers/net/phy/phylink.c +2 -0
+		phy_start(pl->phydev);
+

this blank line is not necessary.

Quoted 21 lines
drivers/net/phy/phylink.c +3 -0
+}
+EXPORT_SYMBOL_GPL(phylink_phy_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
index c492c26202b5..6edfab5f754c 100644
@@ -589,6 +589,7 @@ void phylink_stop(struct phylink *);
 
 void phylink_suspend(struct phylink *pl, bool mac_wol);
 void phylink_resume(struct phylink *pl);
+void phylink_phy_resume(struct phylink *pl);
 
 void phylink_ethtool_get_wol(struct phylink *, struct ethtool_wolinfo *);
 int phylink_ethtool_set_wol(struct phylink *, struct ethtool_wolinfo *);
Signature · 1 line
2.34.1
#3 lore raw

Re: [PATCH 1/2] net: phylink: add a function to resume phy alone to fix resume issue with WoL enabled

In reply to Clark Wang
Quoted 38 lines · Clark Wang

Issue we met:
On some platforms, mac cannot work after resumed from the suspend with WoL enabled.

The cause of the issue:
1. phylink_resolve() is in a workqueue which will not be executed immediately. This is the call sequence:

       phylink_resolve()->phylink_link_up()->pl->mac_ops->mac_link_up()

For stmmac driver, mac_link_up() will set the correct speed/duplex... values which are from link_state.
2. In stmmac_resume(), it will call stmmac_hw_setup() after called the phylink_resume(), because mac need phy rx_clk to do the reset. stmmac_core_init() is called in function stmmac_hw_setup(), which will reset the mac and set the speed/duplex... to default value.
Conclusion: Because phylink_resolve() cannot determine when it is called, it
cannot be guaranteed to be called after stmmac_core_init(). Once stmmac_core_init() is called after phylink_resolve(), the mac will be misconfigured and cannot be used.

In order to avoid this problem, add a function called phylink_phy_resume() to resume phy separately. This eliminates the need to call phylink_resume() before stmmac_hw_setup().

Add another judgement before called phy_start() in phylink_start(). This way phy_start() will not be called multiple times when resumes. At the same time, it may not affect other drivers that do not use phylink_phy_resume().

---
 drivers/net/phy/phylink.c | 21 ++++++++++++++++++++-
 include/linux/phylink.h   |  1 +
 2 files changed, 21 insertions(+), 1 deletion(-)
drivers/net/phy/phylink.c +0 -0
index 09cc65c0da93..5bab59142579 100644

drivers/net/phy/phylink.c void phylink_start(struct phylink *pl) · line 1942

Quoted 5 lines
drivers/net/phy/phylink.c +1 -1
@@ -1939,7 +1939,7 @@ void phylink_start(struct phylink *pl)
 	}
 	if (poll)
 		mod_timer(&pl->link_poll, jiffies + HZ);
-	if (pl->phydev)
+	if (pl->phydev && pl->phydev->state < PHY_UP)

I'm really not happy with this - not only does this subvert the checks in phy_start(), it's a layering violation, and it delves into internals of phylib in an unprotected way.

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
author
#4 lore raw

PATCH v2 2/2 net: stmmac: resume phy separately before calling stmmac_hw_setup()

In reply to Clark Wang

On some platforms, mac cannot work after resumed from the suspend with WoL enabled.

We found the stmmac_hw_setup() when system resumes will called after the stmmac_mac_link_up(). So the correct values set in stmmac_mac_link_up() are overwritten by stmmac_core_init() in phylink_resume().

So call the new added function in phylink to resume phy fristly. Then can call the stmmac_hw_setup() before calling phy_resume().

---
 .../net/ethernet/stmicro/stmmac/stmmac_main.c    | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +7 -9
index c6951c976f5d..d0bdc9b6dbe8 100644
@@ -7532,16 +7532,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);
-	}
-	rtnl_unlock();
 
-	rtnl_lock();
+	phylink_phy_resume(priv->phylink);
+
 	mutex_lock(&priv->lock);
 
 	stmmac_reset_queues_param(priv);
@@ -7559,6 +7552,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.34.1
Reviewed-by on v2 2/2
#5 lore raw

Re: [PATCH 2/2] net: stmmac: resume phy separately before calling stmmac_hw_setup()

Quoted 8 lines · Clark Wang

On some platforms, mac cannot work after resumed from the suspend with WoL enabled.

We found the stmmac_hw_setup() when system resumes will called after the stmmac_mac_link_up(). So the correct values set in stmmac_mac_link_up() are overwritten by stmmac_core_init() in phylink_resume().

So call the new added function in phylink to resume phy fristly.

first.

Quoted 1 line

Then can call the stmmac_hw_setup() before calling phy_resume().

It'd be nice to add Fixes tag with appropriate commit id. Other than that looks fine.

Quoted 44 lines
---
 .../net/ethernet/stmicro/stmmac/stmmac_main.c    | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +7 -9
index c6951c976f5d..d0bdc9b6dbe8 100644
@@ -7532,16 +7532,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);
-	}
-	rtnl_unlock();
 
-	rtnl_lock();
+	phylink_phy_resume(priv->phylink);
+
 	mutex_lock(&priv->lock);
 
 	stmmac_reset_queues_param(priv);
@@ -7559,6 +7552,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.34.1
#6 lore raw
In reply to Clark Wang
Quoted 8 lines · Clark Wang

Hi,
The issue description is in the commit message.

This patchset is the second version following discussions with Russell. But the name of each patch has changed, so V2 is not marked in each patch.

Thanks.

Please include target tree name in the subject eg. [net 1/2]

Quoted 13 lines

Clark Wang (2):
net: phylink: add a function to resume phy alone to fix resume issue
with WoL enabled
net: stmmac: resume phy separately before calling stmmac_hw_setup()

 .../net/ethernet/stmicro/stmmac/stmmac_main.c | 16 +++++++-------
 drivers/net/phy/phylink.c                     | 21 ++++++++++++++++++-
 include/linux/phylink.h                       |  1 +
 3 files changed, 28 insertions(+), 10 deletions(-)
Signature · 1 line
2.34.1