[PATCH] net: phy: fix may not suspend when phy has WoL
From: WangYuli
Date: Mon Nov 11 2024 - 03:07:46 EST
From: Wentao Guan <guanwentao@xxxxxxxxxxxxx>
When system suspends and mdio_bus_phy goes to suspend, if the phy
enabled wol, phy_suspend will returned -EBUSY, and break system
suspend.
Commit 93f41e67dc8f ("net: phy: fix WoL handling when suspending
the PHY") fixes the case when netdev->wol_enabled=1, but some case,
netdev->wol_enabled=0 and phydev set wol_enabled enabled, so check
phydev->wol_enabled.
This case happens when using some out of tree ethernet drivers or
phy drivers.
Log:
YT8531S Gigabit Ethernet phytmac_mii_bus-PHYT0046:00:07: PM: dpm_run_callback(): mdio_bus_phy_suspend+0x0/0x10c returns -16
YT8531S Gigabit Ethernet phytmac_mii_bus-PHYT0046:00:07: PM: failed to suspend: error -16
PM: Some devices failed to suspend, or early wake event detected
YT8531S Gigabit Ethernet phytmac_mii_bus-PHYT0046:00:07: PM: dpm_run_callback(): mdio_bus_phy_suspend+0x0/0x10c returns -16
YT8531S Gigabit Ethernet phytmac_mii_bus-PHYT0046:00:07: PM: failed to suspend: error -16
PM: Some devices failed to suspend, or early wake event detected
YT8531S Gigabit Ethernet phytmac_mii_bus-PHYT0046:00:07: PM: dpm_run_callback(): mdio_bus_phy_suspend+0x0/0x10c returns -16
YT8531S Gigabit Ethernet phytmac_mii_bus-PHYT0046:00:07: PM: failed to freeze: error -16
Link: https://lore.kernel.org/all/20240827092446.7948-1-guanwentao@xxxxxxxxxxxxx/
Fixes: 481b5d938b4a ("net: phy: provide phy_resume/phy_suspend helpers")
Signed-off-by: Wentao Guan <guanwentao@xxxxxxxxxxxxx>
Signed-off-by: WangYuli <wangyuli@xxxxxxxxxxxxx>
---
drivers/net/phy/phy_device.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index bc24c9f2786b..12af590bfd99 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -315,6 +315,19 @@ static bool mdio_bus_phy_may_suspend(struct phy_device *phydev)
if (netdev->ethtool->wol_enabled)
return false;
+ /* Ethernet and phy device wol state may not same, netdev->wol_enabled
+ * disabled, and phydev set wol_enabled enabled, so netdev->wol_enabled
+ * is not enough.
+ * Check phydev->wol_enabled.
+ */
+ struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL };
+
+ phy_ethtool_get_wol(phydev, &wol);
+ if (wol.wolopts) {
+ phydev_warn(phydev, "Phy and mac wol are not compatible\n");
+ return false;
+ }
+
/* As long as not all affected network drivers support the
* wol_enabled flag, let's check for hints that WoL is enabled.
* Don't suspend PHY if the attached netdev parent may wake up.
--
2.45.2