diff mbox series

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

Message ID 20220906083923.3074354-1-wei.fang@nxp.com (mailing list archive)
State Accepted
Commit da970726ea872269dc311b6dd87af8cf457b8fe9
Delegated to: Netdev Maintainers
Headers show
Series [net-next] net: fec: add pm runtime force suspend and resume support | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 1 maintainers not CCed: qiangqing.zhang@nxp.com
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 38 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Wei Fang Sept. 6, 2022, 8:39 a.m. UTC
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(+)

Comments

Andrew Lunn Sept. 6, 2022, 2:42 p.m. UTC | #1
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
Wei Fang Sept. 7, 2022, 1:49 a.m. UTC | #2
> -----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.
patchwork-bot+netdevbpf@kernel.org Sept. 16, 2022, 8:30 a.m. UTC | #3
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!
diff mbox series

Patch

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();