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

wei.fang@nxp.com posted 1 patch 3 years, 7 months ago
drivers/net/ethernet/freescale/fec.h      |  1 +
drivers/net/ethernet/freescale/fec_main.c | 13 +++++++++++++
2 files changed, 14 insertions(+)
[PATCH net-next] net: fec: add pm runtime force suspend and resume support
Posted by wei.fang@nxp.com 3 years, 7 months ago
From: Wei Fang <wei.fang@nxp.com>

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 <wei.fang@nxp.com>
---
 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
Re: [PATCH net-next] net: fec: add pm runtime force suspend and resume support
Posted by patchwork-bot+netdevbpf@kernel.org 3 years, 6 months ago
Hello:

This patch was applied to netdev/net-next.git (master)
by David S. Miller <davem@davemloft.net>:

On Tue,  6 Sep 2022 16:39:23 +0800 you wrote:
> From: Wei Fang <wei.fang@nxp.com>
> 
> 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
Re: [PATCH net-next] net: fec: add pm runtime force suspend and resume support
Posted by Andrew Lunn 3 years, 7 months ago
On Tue, Sep 06, 2022 at 04:39:23PM +0800, wei.fang@nxp.com wrote:
> From: Wei Fang <wei.fang@nxp.com>
> 
> 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
RE: [PATCH net-next] net: fec: add pm runtime force suspend and resume support
Posted by Wei Fang 3 years, 7 months ago

> -----Original Message-----
> From: Andrew Lunn <andrew@lunn.ch>
> Sent: 2022年9月6日 22:42
> To: Wei Fang <wei.fang@nxp.com>
> Cc: davem@davemloft.net; edumazet@google.com; kuba@kernel.org;
> pabeni@redhat.com; netdev@vger.kernel.org; linux-kernel@vger.kernel.org
> 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, wei.fang@nxp.com wrote:
> > From: Wei Fang <wei.fang@nxp.com>
> >
> > 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.