• Youwan Wang's avatar
    net: phy: phy_device: fix PHY WOL enabled, PM failed to suspend · 4f534b7f
    Youwan Wang authored
    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: default avatarRussell King (Oracle) <rmk+kernel@armlinux.org.uk>
    Signed-off-by: default avatarYouwan Wang <youwan@nfschina.com>
    Reviewed-by: default avatarWojciech Drewek <wojciech.drewek@intel.com>
    Link: https://patch.msgid.link/20240731091537.771391-1-youwan@nfschina.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
    4f534b7f
phy_device.c 100 KB