diff mbox series

[net,v2,2/2] net: fec: Suspend and resume the PHY

Message ID 20240229105256.2903095-3-john.ernberg@actia.se (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series net: fec: Fixes to suspend / resume with mac_managed_pm | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 956 this patch: 956
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 9 of 9 maintainers
netdev/build_clang success Errors and warnings before: 973 this patch: 973
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 973 this patch: 973
netdev/checkpatch warning WARNING: Possible repeated word: 'or'
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-02-29--21-00 (tests: 885)

Commit Message

John Ernberg Feb. 29, 2024, 10:53 a.m. UTC
PHYs that are always-on will not enter their low power modes otherwise as
they have no regulator to be powered off with.

Since the PHY is picked up via {of_,}phy_connect() and dropped with
phy_disconnect() when the link is brought up and down respectively the only
cases were pm is needed is when the netif is running or or when the link
has never been up.

To deal with the latter case the PHY is suspended on discovery in probe,
since it won't be needed until link up.

Fixes: 557d5dc83f68 ("net: fec: use mac-managed PHY PM")
Signed-off-by: John Ernberg <john.ernberg@actia.se>
---

v2: New patch
---
 drivers/net/ethernet/freescale/fec_main.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Wei Fang March 1, 2024, 1:49 a.m. UTC | #1
> -----Original Message-----
> From: John Ernberg <john.ernberg@actia.se>
> Sent: 2024年2月29日 18:53
> To: Wei Fang <wei.fang@nxp.com>
> Cc: Shenwei Wang <shenwei.wang@nxp.com>; Clark Wang
> <xiaoning.wang@nxp.com>; dl-linux-imx <linux-imx@nxp.com>; David S.
> Miller <davem@davemloft.net>; Eric Dumazet <edumazet@google.com>;
> Jakub Kicinski <kuba@kernel.org>; Paolo Abeni <pabeni@redhat.com>;
> Heiner Kallweit <hkallweit1@gmail.com>; netdev@vger.kernel.org;
> linux-kernel@vger.kernel.org; John Ernberg <john.ernberg@actia.se>
> Subject: [PATCH net v2 2/2] net: fec: Suspend and resume the PHY
> 
> PHYs that are always-on will not enter their low power modes otherwise as
> they have no regulator to be powered off with.
> 
> Since the PHY is picked up via {of_,}phy_connect() and dropped with
> phy_disconnect() when the link is brought up and down respectively the only
> cases were pm is needed is when the netif is running or or when the link
nit: where

> has never been up.
> 
> To deal with the latter case the PHY is suspended on discovery in probe,
> since it won't be needed until link up.
> 
> Fixes: 557d5dc83f68 ("net: fec: use mac-managed PHY PM")
I'm not sure whether this commit should be blamed. After checking my local
code (not the recent upstream code), fec_suspend() will make the PHY enter 
suspend mode when calling phy_stop(), the specific logic is fec_suspend() -->
phy_stop() --> phy_state_machine() --> phy_suspend (). But the latest upstream
code may have changed this logic. I'm sorry that I don't have time to sit down
and look at the latest code.

> Signed-off-by: John Ernberg <john.ernberg@actia.se>
> ---
> 
> v2: New patch
> ---
>  drivers/net/ethernet/freescale/fec_main.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/freescale/fec_main.c
> b/drivers/net/ethernet/freescale/fec_main.c
> index 8decb1b072c5..c5394a4d8491 100644
> --- a/drivers/net/ethernet/freescale/fec_main.c
> +++ b/drivers/net/ethernet/freescale/fec_main.c
> @@ -2539,8 +2539,10 @@ static int fec_enet_mii_init(struct
> platform_device *pdev)
>  	/* find all the PHY devices on the bus and set mac_managed_pm to true
> */
>  	for (addr = 0; addr < PHY_MAX_ADDR; addr++) {
>  		phydev = mdiobus_get_phy(fep->mii_bus, addr);
> -		if (phydev)
> +		if (phydev) {
>  			phydev->mac_managed_pm = true;
> +			phy_suspend(phydev);
> +		}
>  	}
> 
>  	mii_cnt++;
> @@ -4631,6 +4633,7 @@ static int __maybe_unused fec_suspend(struct
> device *dev)
>  		if (fep->wol_flag & FEC_WOL_FLAG_ENABLE)
>  			fep->wol_flag |= FEC_WOL_FLAG_SLEEP_ON;
>  		phy_stop(ndev->phydev);
> +		phy_suspend(ndev->phydev);
As I aforementioned, if phy_stop() does not suspend the PHY in the latest
code, is it more general to restore the suspend operation in phy_stop()?

>  		napi_disable(&fep->napi);
>  		netif_tx_lock_bh(ndev);
>  		netif_device_detach(ndev);
> @@ -4716,6 +4719,7 @@ static int __maybe_unused fec_resume(struct
> device *dev)
>  		netif_tx_unlock_bh(ndev);
>  		napi_enable(&fep->napi);
>  		phy_init_hw(ndev->phydev);
> +		phy_resume(ndev->phydev);
>  		phy_start(ndev->phydev);
>  	}
>  	rtnl_unlock();
> --
> 2.43.0
John Ernberg March 1, 2024, 8:10 a.m. UTC | #2
Hi Wei,

On 3/1/24 02:49, Wei Fang wrote:
>> -----Original Message-----
>> From: John Ernberg <john.ernberg@actia.se>
>> Sent: 2024年2月29日 18:53
>> To: Wei Fang <wei.fang@nxp.com>
>> Cc: Shenwei Wang <shenwei.wang@nxp.com>; Clark Wang
>> <xiaoning.wang@nxp.com>; dl-linux-imx <linux-imx@nxp.com>; David S.
>> Miller <davem@davemloft.net>; Eric Dumazet <edumazet@google.com>;
>> Jakub Kicinski <kuba@kernel.org>; Paolo Abeni <pabeni@redhat.com>;
>> Heiner Kallweit <hkallweit1@gmail.com>; netdev@vger.kernel.org;
>> linux-kernel@vger.kernel.org; John Ernberg <john.ernberg@actia.se>
>> Subject: [PATCH net v2 2/2] net: fec: Suspend and resume the PHY
>>
>> PHYs that are always-on will not enter their low power modes otherwise as
>> they have no regulator to be powered off with.
>>
>> Since the PHY is picked up via {of_,}phy_connect() and dropped with
>> phy_disconnect() when the link is brought up and down respectively the only
>> cases were pm is needed is when the netif is running or or when the link
> nit: where
> 
>> has never been up.
>>
>> To deal with the latter case the PHY is suspended on discovery in probe,
>> since it won't be needed until link up.
>>
>> Fixes: 557d5dc83f68 ("net: fec: use mac-managed PHY PM")
> I'm not sure whether this commit should be blamed. After checking my local
> code (not the recent upstream code), fec_suspend() will make the PHY enter
> suspend mode when calling phy_stop(), the specific logic is fec_suspend() -->
> phy_stop() --> phy_state_machine() --> phy_suspend (). But the latest upstream
> code may have changed this logic. I'm sorry that I don't have time to sit down
> and look at the latest code.

I missed this flow, and also didn't see it take place when I look at the 
MDIO traffic. But the code has been there since 2013.

I will check why that isn't happening.

Thanks! // John Ernberg
diff mbox series

Patch

diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c
index 8decb1b072c5..c5394a4d8491 100644
--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -2539,8 +2539,10 @@  static int fec_enet_mii_init(struct platform_device *pdev)
 	/* find all the PHY devices on the bus and set mac_managed_pm to true */
 	for (addr = 0; addr < PHY_MAX_ADDR; addr++) {
 		phydev = mdiobus_get_phy(fep->mii_bus, addr);
-		if (phydev)
+		if (phydev) {
 			phydev->mac_managed_pm = true;
+			phy_suspend(phydev);
+		}
 	}
 
 	mii_cnt++;
@@ -4631,6 +4633,7 @@  static int __maybe_unused fec_suspend(struct device *dev)
 		if (fep->wol_flag & FEC_WOL_FLAG_ENABLE)
 			fep->wol_flag |= FEC_WOL_FLAG_SLEEP_ON;
 		phy_stop(ndev->phydev);
+		phy_suspend(ndev->phydev);
 		napi_disable(&fep->napi);
 		netif_tx_lock_bh(ndev);
 		netif_device_detach(ndev);
@@ -4716,6 +4719,7 @@  static int __maybe_unused fec_resume(struct device *dev)
 		netif_tx_unlock_bh(ndev);
 		napi_enable(&fep->napi);
 		phy_init_hw(ndev->phydev);
+		phy_resume(ndev->phydev);
 		phy_start(ndev->phydev);
 	}
 	rtnl_unlock();