From nobody Wed Dec 17 15:39:33 2025 Received: from mail.nfschina.com (unknown [42.101.60.195]) by smtp.subspace.kernel.org (Postfix) with SMTP id 1B8C618B04; Wed, 31 Jul 2024 09:16:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=42.101.60.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722417368; cv=none; b=Sd4uIiKYi2cF++8jY2u13wb917PprSv3rZB/+sRhmhj/EKD+8A85DxDwUUnwxIhoby/L2mAWLnHo+3azBsj3bd2DhSSb4oI42tWtOLnwOZYIqrEzBPhMMEpi96LkdZWGrgyqP+ElS5/MSioR+1GIe6u0CQePOM1INymn9Uq5W/c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722417368; c=relaxed/simple; bh=XlHX40UfltCi30+lIask3v2Ve30eJqGeq0QdnxbKbPU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version; b=qln6voaLg3ONO3hE0HfDlv3jvWcpsxvXGJCvv9cUXEHCEViMWs3DN+cLTdoETND3jCjYHhEs296ZpKtkK6k7XX2K3mJfzYELCMXYmzXIN/ZmjK3fyA9hjHzwtdHTJTEt/XipXJsAZLylWfZyjeBKSzNjVhPzUmLShsJdL5c24Jo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nfschina.com; spf=pass smtp.mailfrom=nfschina.com; arc=none smtp.client-ip=42.101.60.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nfschina.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nfschina.com Received: from localhost.localdomain (unknown [103.163.180.2]) by mail.nfschina.com (MailData Gateway V2.8.8) with ESMTPA id 0012F6022F61E; Wed, 31 Jul 2024 17:15:45 +0800 (CST) X-MD-Sfrom: youwan@nfschina.com X-MD-SrcIP: 103.163.180.2 From: Youwan Wang To: linux@armlinux.org.uk Cc: andrew@lunn.ch, davem@davemloft.net, edumazet@google.com, hkallweit1@gmail.com, kuba@kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, pabeni@redhat.com, youwan@nfschina.com, Russell King , Wojciech Drewek Subject: [net-next,v4] net: phy: phy_device: fix PHY WOL enabled, PM failed to suspend Date: Wed, 31 Jul 2024 17:15:37 +0800 Message-Id: <20240731091537.771391-1-youwan@nfschina.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 suspe= nd 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=3Dstmmac-0:00, irq=3DPOLL) [ 5.932512] YT8521 Gigabit Ethernet stmmac-0:01: attached PHY driver (mii_bus:phy_addr=3Dstmmac-0:01, irq=3DPOLL) [ 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 deb= ug) [ 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 dete= cted [ 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) Signed-off-by: Youwan Wang Reviewed-by: Wojciech Drewek --- drivers/net/phy/phy_device.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 7752e9386b40..34752a87f98f 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -279,6 +279,15 @@ static struct phy_driver genphy_driver; static LIST_HEAD(phy_fixup_list); static DEFINE_MUTEX(phy_fixup_lock); =20 +static bool phy_drv_wol_enabled(struct phy_device *phydev) +{ + struct ethtool_wolinfo wol =3D { .cmd =3D ETHTOOL_GWOL }; + + phy_ethtool_get_wol(phydev, &wol); + + return wol.wolopts !=3D 0; +} + static bool mdio_bus_phy_may_suspend(struct phy_device *phydev) { struct device_driver *drv =3D phydev->mdio.dev.driver; @@ -288,6 +297,12 @@ static bool mdio_bus_phy_may_suspend(struct phy_device= *phydev) if (!drv || !phydrv->suspend) return false; =20 + /* If the PHY on the mido bus is not attached but has WOL enabled + * we cannot suspend the PHY. + */ + if (!netdev && phy_drv_wol_enabled(phydev)) + return false; + /* PHY not attached? May suspend if the PHY has not already been * suspended as part of a prior call to phy_disconnect() -> * phy_detach() -> phy_suspend() because the parent netdev might be the @@ -1975,7 +1990,6 @@ EXPORT_SYMBOL(phy_detach); =20 int phy_suspend(struct phy_device *phydev) { - struct ethtool_wolinfo wol =3D { .cmd =3D ETHTOOL_GWOL }; struct net_device *netdev =3D phydev->attached_dev; const struct phy_driver *phydrv =3D phydev->drv; int ret; @@ -1983,8 +1997,7 @@ int phy_suspend(struct phy_device *phydev) if (phydev->suspended || !phydrv) return 0; =20 - phy_ethtool_get_wol(phydev, &wol); - phydev->wol_enabled =3D wol.wolopts || + phydev->wol_enabled =3D phy_drv_wol_enabled(phydev) || (netdev && netdev->ethtool->wol_enabled); /* If the device has WOL enabled, we cannot suspend the PHY */ if (phydev->wol_enabled && !(phydrv->flags & PHY_ALWAYS_CALL_SUSPEND)) --=20 2.25.1