[PATCH net-next v2 2/4] net: stmmac: stm32: add WoL from PHY support
Russell King (Oracle)
linux at armlinux.org.uk
Sun Sep 28 01:21:44 PDT 2025
On Fri, Sep 26, 2025 at 12:05:19PM -0700, Florian Fainelli wrote:
> I like the direction this is going, we could probably take one step further
> and extract the logic present in bcmgenet_wol.c and make those helper
> functions for other drivers to get the overlay of PHY+MAC WoL
> options/password consistent across all drivers. What do you think?
The logic I've implemented is fairly similar, but with one difference:
I'm always storing the sopass, which means in the wol_get method I
don't have to be concerned with the sopass returned by the PHY.
This should be fine, unless the PHY was already configured for WoL
magicsecure, and in that case we'll return a zero SOPASS but indicating
WAKE_MAGICSECURE which probably isn't great.
So, my new get_wol logic is:
if (phylink_mac_supports_wol(pl)) {
if (phylink_phy_supports_wol(pl, pl->phydev))
phy_ethtool_get_wol(pl->phydev, wol);
/* Where the MAC augments the WoL support, merge its support and
* current configuration.
*/
if (~wol->wolopts & pl->wolopts_mac & WAKE_MAGICSECURE)
memcpy(wol->sopass, pl->wol_sopass,
sizeof(wol->sopass));
wol->supported |= pl->config->wol_mac_support;
wol->wolopts |= pl->wolopts_mac;
with:
static bool phylink_mac_supports_wol(struct phylink *pl)
{
return !!pl->mac_ops->mac_wol_set;
}
static bool phylink_phy_supports_wol(struct phylink *pl,
struct phy_device *phydev)
{
return phydev && (pl->config->wol_phy_legacy || phy_can_wakeup(phydev));
}
static inline bool phy_can_wakeup(struct phy_device *phydev)
{
return device_can_wakeup(&phydev->mdio.dev);
}
This is to cope with PHYs that respond to phy_ethtool_get_wol()
reporting that they support WoL but have no capability to actually wake
the system up. MACs can choose whether to override that by setting
phylink_config->wol_phy_legacy.
Much like taking this logic away from MAC driver authors, I think we
need to take the logic around "can this PHY actually wake-up the
system" away from the PHY driver author. I believe every driver that
supports WoL with the exception of realtek and broadcom.c reports that
WoL is supported and accepts set_wol() even when they're not capable
of waking the system. e.g. bcm_phy_get_wol():
wol->supported = BCM54XX_WOL_SUPPORTED_MASK;
wol->wolopts = 0;
with no prior checks. This is why the "phylink_phy_supports_wol()"
logic above is necessary, otherwise implementing this "use either
the PHY or MAC" logic will break stuff.
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
More information about the linux-arm-kernel
mailing list