Skip to content

Commit 4f534b7

Browse files
Youwan Wangkuba-moo
authored andcommitted
net: phy: phy_device: fix PHY WOL enabled, PM failed to suspend
If the PHY of the mido bus is enabled with Wake-on-LAN (WOL), we cannot suspend the PHY. Although the WOL status has been checked in phy_suspend(), returning -EBUSY(-16) would cause the Power Management (PM) to fail to suspend. Since phy_suspend() is an exported symbol (EXPORT_SYMBOL), timely error reporting is needed. Therefore, an additional check is performed here. If the PHY of the mido bus is enabled with WOL, we skip calling phy_suspend() to avoid PM failure. From the following logs, it has been observed that the phydev->attached_dev is NULL, phydev is "stmmac-0:01", it not attached, but it will affect suspend and resume.The actually attached "stmmac-0:00" will not dpm_run_callback(): mdio_bus_phy_suspend(). init log: [ 5.932502] YT8521 Gigabit Ethernet stmmac-0:00: attached PHY driver (mii_bus:phy_addr=stmmac-0:00, irq=POLL) [ 5.932512] YT8521 Gigabit Ethernet stmmac-0:01: attached PHY driver (mii_bus:phy_addr=stmmac-0:01, irq=POLL) [ 24.566289] YT8521 Gigabit Ethernet stmmac-0:00: yt8521_read_status, link down, media: UTP suspend log: [ 322.631362] OOM killer disabled. [ 322.631364] Freezing remaining freezable tasks [ 322.632536] Freezing remaining freezable tasks completed (elapsed 0.001 seconds) [ 322.632540] printk: Suspending console(s) (use no_console_suspend to debug) [ 322.633052] YT8521 Gigabit Ethernet stmmac-0:01: PM: dpm_run_callback(): mdio_bus_phy_suspend+0x0/0x110 [libphy] returns -16 [ 322.633071] YT8521 Gigabit Ethernet stmmac-0:01: PM: failed to suspend: error -16 [ 322.669699] PM: Some devices failed to suspend, or early wake event detected [ 322.669949] OOM killer enabled. [ 322.669951] Restarting tasks ... done. [ 322.671008] random: crng reseeded on system resumption [ 322.671014] PM: suspend exit Add a function that phylib can inquire of the driver whether WoL has been enabled at the PHY. Signed-off-by: Russell King (Oracle) <[email protected]> Signed-off-by: Youwan Wang <[email protected]> Reviewed-by: Wojciech Drewek <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 45160ce commit 4f534b7

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

drivers/net/phy/phy_device.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,15 @@ static struct phy_driver genphy_driver;
279279
static LIST_HEAD(phy_fixup_list);
280280
static DEFINE_MUTEX(phy_fixup_lock);
281281

282+
static bool phy_drv_wol_enabled(struct phy_device *phydev)
283+
{
284+
struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL };
285+
286+
phy_ethtool_get_wol(phydev, &wol);
287+
288+
return wol.wolopts != 0;
289+
}
290+
282291
static bool mdio_bus_phy_may_suspend(struct phy_device *phydev)
283292
{
284293
struct device_driver *drv = phydev->mdio.dev.driver;
@@ -288,6 +297,12 @@ static bool mdio_bus_phy_may_suspend(struct phy_device *phydev)
288297
if (!drv || !phydrv->suspend)
289298
return false;
290299

300+
/* If the PHY on the mido bus is not attached but has WOL enabled
301+
* we cannot suspend the PHY.
302+
*/
303+
if (!netdev && phy_drv_wol_enabled(phydev))
304+
return false;
305+
291306
/* PHY not attached? May suspend if the PHY has not already been
292307
* suspended as part of a prior call to phy_disconnect() ->
293308
* phy_detach() -> phy_suspend() because the parent netdev might be the
@@ -1975,16 +1990,14 @@ EXPORT_SYMBOL(phy_detach);
19751990

19761991
int phy_suspend(struct phy_device *phydev)
19771992
{
1978-
struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL };
19791993
struct net_device *netdev = phydev->attached_dev;
19801994
const struct phy_driver *phydrv = phydev->drv;
19811995
int ret;
19821996

19831997
if (phydev->suspended || !phydrv)
19841998
return 0;
19851999

1986-
phy_ethtool_get_wol(phydev, &wol);
1987-
phydev->wol_enabled = wol.wolopts ||
2000+
phydev->wol_enabled = phy_drv_wol_enabled(phydev) ||
19882001
(netdev && netdev->ethtool->wol_enabled);
19892002
/* If the device has WOL enabled, we cannot suspend the PHY */
19902003
if (phydev->wol_enabled && !(phydrv->flags & PHY_ALWAYS_CALL_SUSPEND))

0 commit comments

Comments
 (0)