* [PATCH V2 0/2] fix mac not working after system resumed with WoL enabled
@ 2022-12-21 8:01 Clark Wang
2022-12-21 8:01 ` [PATCH 1/2] net: phylink: add a function to resume phy alone to fix resume issue " Clark Wang
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Clark Wang @ 2022-12-21 8:01 UTC (permalink / raw)
To: linux, peppe.cavallaro, alexandre.torgue, joabreu, davem,
edumazet, kuba, pabeni, mcoquelin.stm32, andrew, hkallweit1
Cc: netdev, linux-stm32, linux-arm-kernel, linux-kernel
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(-)
--
2.34.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/2] net: phylink: add a function to resume phy alone to fix resume issue with WoL enabled
2022-12-21 8:01 [PATCH V2 0/2] fix mac not working after system resumed with WoL enabled Clark Wang
@ 2022-12-21 8:01 ` Clark Wang
2022-12-22 20:32 ` Piotr Raczynski
2023-01-03 9:46 ` Russell King (Oracle)
2022-12-21 8:01 ` [PATCH 2/2] net: stmmac: resume phy separately before calling stmmac_hw_setup() Clark Wang
2022-12-22 19:56 ` [PATCH V2 0/2] fix mac not working after system resumed with WoL enabled Piotr Raczynski
2 siblings, 2 replies; 7+ messages in thread
From: Clark Wang @ 2022-12-21 8:01 UTC (permalink / raw)
To: linux, peppe.cavallaro, alexandre.torgue, joabreu, davem,
edumazet, kuba, pabeni, mcoquelin.stm32, andrew, hkallweit1
Cc: netdev, linux-stm32, linux-arm-kernel, linux-kernel
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().
Signed-off-by: Clark Wang <xiaoning.wang@nxp.com>
---
drivers/net/phy/phylink.c | 21 ++++++++++++++++++++-
include/linux/phylink.h | 1 +
2 files changed, 21 insertions(+), 1 deletion(-)
diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
index 09cc65c0da93..5bab59142579 100644
--- a/drivers/net/phy/phylink.c
+++ b/drivers/net/phy/phylink.c
@@ -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()
diff --git a/include/linux/phylink.h b/include/linux/phylink.h
index c492c26202b5..6edfab5f754c 100644
--- a/include/linux/phylink.h
+++ b/include/linux/phylink.h
@@ -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 *);
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/2] net: stmmac: resume phy separately before calling stmmac_hw_setup()
2022-12-21 8:01 [PATCH V2 0/2] fix mac not working after system resumed with WoL enabled Clark Wang
2022-12-21 8:01 ` [PATCH 1/2] net: phylink: add a function to resume phy alone to fix resume issue " Clark Wang
@ 2022-12-21 8:01 ` Clark Wang
2022-12-22 20:04 ` Piotr Raczynski
2022-12-22 19:56 ` [PATCH V2 0/2] fix mac not working after system resumed with WoL enabled Piotr Raczynski
2 siblings, 1 reply; 7+ messages in thread
From: Clark Wang @ 2022-12-21 8:01 UTC (permalink / raw)
To: linux, peppe.cavallaro, alexandre.torgue, joabreu, davem,
edumazet, kuba, pabeni, mcoquelin.stm32, andrew, hkallweit1
Cc: netdev, linux-stm32, linux-arm-kernel, linux-kernel
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().
Signed-off-by: Clark Wang <xiaoning.wang@nxp.com>
---
.../net/ethernet/stmicro/stmmac/stmmac_main.c | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index c6951c976f5d..d0bdc9b6dbe8 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -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);
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH V2 0/2] fix mac not working after system resumed with WoL enabled
2022-12-21 8:01 [PATCH V2 0/2] fix mac not working after system resumed with WoL enabled Clark Wang
2022-12-21 8:01 ` [PATCH 1/2] net: phylink: add a function to resume phy alone to fix resume issue " Clark Wang
2022-12-21 8:01 ` [PATCH 2/2] net: stmmac: resume phy separately before calling stmmac_hw_setup() Clark Wang
@ 2022-12-22 19:56 ` Piotr Raczynski
2 siblings, 0 replies; 7+ messages in thread
From: Piotr Raczynski @ 2022-12-22 19:56 UTC (permalink / raw)
To: Clark Wang
Cc: linux, peppe.cavallaro, alexandre.torgue, joabreu, davem,
edumazet, kuba, pabeni, mcoquelin.stm32, andrew, hkallweit1,
netdev, linux-stm32, linux-arm-kernel, linux-kernel
On Wed, Dec 21, 2022 at 04:01:42PM +0800, Clark Wang wrote:
> 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]
> 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(-)
>
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] net: stmmac: resume phy separately before calling stmmac_hw_setup()
2022-12-21 8:01 ` [PATCH 2/2] net: stmmac: resume phy separately before calling stmmac_hw_setup() Clark Wang
@ 2022-12-22 20:04 ` Piotr Raczynski
0 siblings, 0 replies; 7+ messages in thread
From: Piotr Raczynski @ 2022-12-22 20:04 UTC (permalink / raw)
To: Clark Wang
Cc: linux, peppe.cavallaro, alexandre.torgue, joabreu, davem,
edumazet, kuba, pabeni, mcoquelin.stm32, andrew, hkallweit1,
netdev, linux-stm32, linux-arm-kernel, linux-kernel
On Wed, Dec 21, 2022 at 04:01:44PM +0800, Clark Wang wrote:
> 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.
> 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.
Reviewed-by: Piotr Raczynski <piotr.raczynski@intel.com>
>
> Signed-off-by: Clark Wang <xiaoning.wang@nxp.com>
> ---
> .../net/ethernet/stmicro/stmmac/stmmac_main.c | 16 +++++++---------
> 1 file changed, 7 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> index c6951c976f5d..d0bdc9b6dbe8 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> @@ -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);
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] net: phylink: add a function to resume phy alone to fix resume issue with WoL enabled
2022-12-21 8:01 ` [PATCH 1/2] net: phylink: add a function to resume phy alone to fix resume issue " Clark Wang
@ 2022-12-22 20:32 ` Piotr Raczynski
2023-01-03 9:46 ` Russell King (Oracle)
1 sibling, 0 replies; 7+ messages in thread
From: Piotr Raczynski @ 2022-12-22 20:32 UTC (permalink / raw)
To: Clark Wang
Cc: linux, peppe.cavallaro, alexandre.torgue, joabreu, davem,
edumazet, kuba, pabeni, mcoquelin.stm32, andrew, hkallweit1,
netdev, linux-stm32, linux-arm-kernel, linux-kernel
On Wed, Dec 21, 2022 at 04:01:43PM +0800, Clark Wang wrote:
> 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().
>
It'd be nice to see Fixes tag.
> Signed-off-by: Clark Wang <xiaoning.wang@nxp.com>
> ---
> drivers/net/phy/phylink.c | 21 ++++++++++++++++++++-
> include/linux/phylink.h | 1 +
> 2 files changed, 21 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
> index 09cc65c0da93..5bab59142579 100644
> --- a/drivers/net/phy/phylink.c
> +++ b/drivers/net/phy/phylink.c
> @@ -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)
you can fit && at the end of the previous line.
> + phy_start(pl->phydev);
> +
this blank line is not necessary.
> +}
> +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()
> diff --git a/include/linux/phylink.h b/include/linux/phylink.h
> index c492c26202b5..6edfab5f754c 100644
> --- a/include/linux/phylink.h
> +++ b/include/linux/phylink.h
> @@ -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 *);
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] net: phylink: add a function to resume phy alone to fix resume issue with WoL enabled
2022-12-21 8:01 ` [PATCH 1/2] net: phylink: add a function to resume phy alone to fix resume issue " Clark Wang
2022-12-22 20:32 ` Piotr Raczynski
@ 2023-01-03 9:46 ` Russell King (Oracle)
1 sibling, 0 replies; 7+ messages in thread
From: Russell King (Oracle) @ 2023-01-03 9:46 UTC (permalink / raw)
To: Clark Wang
Cc: peppe.cavallaro, alexandre.torgue, joabreu, davem, edumazet, kuba,
pabeni, mcoquelin.stm32, andrew, hkallweit1, netdev, linux-stm32,
linux-arm-kernel, linux-kernel
On Wed, Dec 21, 2022 at 04:01:43PM +0800, Clark Wang wrote:
> 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().
>
> Signed-off-by: Clark Wang <xiaoning.wang@nxp.com>
> ---
> drivers/net/phy/phylink.c | 21 ++++++++++++++++++++-
> include/linux/phylink.h | 1 +
> 2 files changed, 21 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
> index 09cc65c0da93..5bab59142579 100644
> --- a/drivers/net/phy/phylink.c
> +++ b/drivers/net/phy/phylink.c
> @@ -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.
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-01-03 9:48 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-21 8:01 [PATCH V2 0/2] fix mac not working after system resumed with WoL enabled Clark Wang
2022-12-21 8:01 ` [PATCH 1/2] net: phylink: add a function to resume phy alone to fix resume issue " Clark Wang
2022-12-22 20:32 ` Piotr Raczynski
2023-01-03 9:46 ` Russell King (Oracle)
2022-12-21 8:01 ` [PATCH 2/2] net: stmmac: resume phy separately before calling stmmac_hw_setup() Clark Wang
2022-12-22 20:04 ` Piotr Raczynski
2022-12-22 19:56 ` [PATCH V2 0/2] fix mac not working after system resumed with WoL enabled Piotr Raczynski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).