]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
net: phy: add phy_may_wakeup()
authorRussell King (Oracle) <rmk+kernel@armlinux.org.uk>
Thu, 23 Oct 2025 09:16:35 +0000 (10:16 +0100)
committerJakub Kicinski <kuba@kernel.org>
Sat, 25 Oct 2025 01:52:07 +0000 (18:52 -0700)
Add phy_may_wakeup() which uses the driver model's device_may_wakeup()
when the PHY driver has marked the device as wakeup capable in the
driver model, otherwise use phy_drv_wol_enabled().

Replace the sites that used to call phy_drv_wol_enabled() with this
as checking the driver model will be more efficient than checking the
WoL state.

Export phy_may_wakeup() so that phylink can use it.

Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Link: https://patch.msgid.link/E1vBrQx-0000000BLzO-1RLt@rmk-PC.armlinux.org.uk
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/phy/phy_device.c
include/linux/phy.h

index 7a67c900e79a5182295e45d5a2fc830ed884555d..b7feaf0cb1df12630559e453ac6c70f79f55ec17 100644 (file)
@@ -251,6 +251,16 @@ static bool phy_drv_wol_enabled(struct phy_device *phydev)
        return wol.wolopts != 0;
 }
 
+bool phy_may_wakeup(struct phy_device *phydev)
+{
+       /* If the PHY is using driver-model based wakeup, use that state. */
+       if (phy_can_wakeup(phydev))
+               return device_may_wakeup(&phydev->mdio.dev);
+
+       return phy_drv_wol_enabled(phydev);
+}
+EXPORT_SYMBOL_GPL(phy_may_wakeup);
+
 static void phy_link_change(struct phy_device *phydev, bool up)
 {
        struct net_device *netdev = phydev->attached_dev;
@@ -302,7 +312,7 @@ static bool mdio_bus_phy_may_suspend(struct phy_device *phydev)
        /* 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))
+       if (!netdev && phy_may_wakeup(phydev))
                return false;
 
        /* PHY not attached? May suspend if the PHY has not already been
@@ -1909,7 +1919,7 @@ int phy_suspend(struct phy_device *phydev)
        if (phydev->suspended || !phydrv)
                return 0;
 
-       phydev->wol_enabled = phy_drv_wol_enabled(phydev) ||
+       phydev->wol_enabled = phy_may_wakeup(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))
index 3eeeaec52832072c1696f730b8ba74a3ecc532f2..17a2cdc9f1a0f5698383e02799ae46f6213b0728 100644 (file)
@@ -1391,6 +1391,15 @@ static inline bool phy_can_wakeup(struct phy_device *phydev)
        return device_can_wakeup(&phydev->mdio.dev);
 }
 
+/**
+ * phy_may_wakeup() - indicate whether PHY has wakeup enabled
+ * @phydev: The phy_device struct
+ *
+ * Returns: true/false depending on the PHY driver's device_set_wakeup_enabled()
+ * setting if using the driver model, otherwise the legacy determination.
+ */
+bool phy_may_wakeup(struct phy_device *phydev);
+
 void phy_resolve_aneg_pause(struct phy_device *phydev);
 void phy_resolve_aneg_linkmode(struct phy_device *phydev);