Skip to contentSkip to conversation

net: fec: add pm runtime force suspend and resume support

PATCH Applied [email protected] 3 participants 4 messages Sep 6, 2022 – Sep 16, 2022

Subsystems (3)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

PATCH 1/1 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.

---
 drivers/net/ethernet/freescale/fec.h      |  1 +
 drivers/net/ethernet/freescale/fec_main.c | 13 +++++++++++++
 2 files changed, 14 insertions(+)
drivers/net/ethernet/freescale/fec.h +1 -0
index 0cebe4b63adb..521f60c7f2e0 100644
@@ -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;
drivers/net/ethernet/freescale/fec_main.c +13 -0
index 7211597d323d..13210b216ee4 100644
@@ -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();
Signature · 1 line
2.25.1
#1 lore raw
Quoted 6 lines · 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

author maintainer
#2 lore raw
Quoted 19 lines

-----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

Quoted 6 lines · 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.

Quoted 6 lines

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.

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

Hello:

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

Quoted 8 lines · 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!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html