2022-09-06 09:16:24

by Wei Fang

[permalink] [raw]
Subject: [PATCH net-next] net: fec: add pm runtime force suspend and resume support

From: Wei Fang <[email protected]>

Force mii bus into runtime pm suspend state during device suspends,
since phydev state is already PHY_HALTED, and there is no need to
access mii bus during device suspend state. Then force mii bus into
runtime pm resume state when device resumes.

Signed-off-by: Wei Fang <[email protected]>
---
drivers/net/ethernet/freescale/fec.h | 1 +
drivers/net/ethernet/freescale/fec_main.c | 13 +++++++++++++
2 files changed, 14 insertions(+)

diff --git a/drivers/net/ethernet/freescale/fec.h b/drivers/net/ethernet/freescale/fec.h
index 0cebe4b63adb..521f60c7f2e0 100644
--- a/drivers/net/ethernet/freescale/fec.h
+++ b/drivers/net/ethernet/freescale/fec.h
@@ -579,6 +579,7 @@ struct fec_enet_private {
struct device_node *phy_node;
bool rgmii_txc_dly;
bool rgmii_rxc_dly;
+ bool rpm_active;
int link;
int full_duplex;
int speed;
diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c
index 7211597d323d..13210b216ee4 100644
--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -4092,6 +4092,7 @@ static int __maybe_unused fec_suspend(struct device *dev)
{
struct net_device *ndev = dev_get_drvdata(dev);
struct fec_enet_private *fep = netdev_priv(ndev);
+ int ret;

rtnl_lock();
if (netif_running(ndev)) {
@@ -4116,6 +4117,15 @@ static int __maybe_unused fec_suspend(struct device *dev)
}
/* It's safe to disable clocks since interrupts are masked */
fec_enet_clk_enable(ndev, false);
+
+ fep->rpm_active = !pm_runtime_status_suspended(dev);
+ if (fep->rpm_active) {
+ ret = pm_runtime_force_suspend(dev);
+ if (ret < 0) {
+ rtnl_unlock();
+ return ret;
+ }
+ }
}
rtnl_unlock();

@@ -4146,6 +4156,9 @@ static int __maybe_unused fec_resume(struct device *dev)

rtnl_lock();
if (netif_running(ndev)) {
+ if (fep->rpm_active)
+ pm_runtime_force_resume(dev);
+
ret = fec_enet_clk_enable(ndev, true);
if (ret) {
rtnl_unlock();
--
2.25.1


2022-09-06 16:05:34

by Andrew Lunn

[permalink] [raw]
Subject: Re: [PATCH net-next] net: fec: add pm runtime force suspend and resume support

On Tue, Sep 06, 2022 at 04:39:23PM +0800, [email protected] wrote:
> From: Wei Fang <[email protected]>
>
> Force mii bus into runtime pm suspend state during device suspends,
> since phydev state is already PHY_HALTED, and there is no need to
> access mii bus during device suspend state. Then force mii bus into
> runtime pm resume state when device resumes.

Have you tested this with an Ethernet switch hanging off the MDIO bus?
It has a life cycle of its own, and i'm not sure it is guaranteed that
the switch is suspended before the FEC. That is why the MDIO
read/write functions have there own runtime PM calls, they can be used
when the interface itself is down.

Andrew

2022-09-07 01:54:38

by Wei Fang

[permalink] [raw]
Subject: RE: [PATCH net-next] net: fec: add pm runtime force suspend and resume support



> -----Original Message-----
> From: Andrew Lunn <[email protected]>
> Sent: 2022??9??6?? 22:42
> To: Wei Fang <[email protected]>
> Cc: [email protected]; [email protected]; [email protected];
> [email protected]; [email protected]; [email protected]
> Subject: Re: [PATCH net-next] net: fec: add pm runtime force suspend and
> resume support
>
> On Tue, Sep 06, 2022 at 04:39:23PM +0800, [email protected] wrote:
> > From: Wei Fang <[email protected]>
> >
> > Force mii bus into runtime pm suspend state during device suspends,
> > since phydev state is already PHY_HALTED, and there is no need to
> > access mii bus during device suspend state. Then force mii bus into
> > runtime pm resume state when device resumes.
>
> Have you tested this with an Ethernet switch hanging off the MDIO bus?
> It has a life cycle of its own, and i'm not sure it is guaranteed that the switch is
> suspended before the FEC. That is why the MDIO read/write functions have
> there own runtime PM calls, they can be used when the interface itself is
> down.
>
Sorry, we don't have the product that an Ethernet switch hanging off the MIDO
bus of FEC. But I have tested system suspend/resume on i.MX6UL platform which
has two FEC MAC and share one MDIO bus. I have confirmed that the two PHYs
are suspended before the FEC. So it's safe to force the MDIO bus into runtime
suspend state. In addition, this patch has been already submitted to our local
repository for 3 years and our test team has test it for several times.

2022-09-16 09:31:35

by patchwork-bot+netdevbpf

[permalink] [raw]
Subject: Re: [PATCH net-next] net: fec: add pm runtime force suspend and resume support

Hello:

This patch was applied to netdev/net-next.git (master)
by David S. Miller <[email protected]>:

On Tue, 6 Sep 2022 16:39:23 +0800 you wrote:
> From: Wei Fang <[email protected]>
>
> Force mii bus into runtime pm suspend state during device suspends,
> since phydev state is already PHY_HALTED, and there is no need to
> access mii bus during device suspend state. Then force mii bus into
> runtime pm resume state when device resumes.
>
> [...]

Here is the summary with links:
- [net-next] net: fec: add pm runtime force suspend and resume support
https://git.kernel.org/netdev/net-next/c/da970726ea87

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html