If the "st,phy-wol" property is present in the device tree node,
set the STMMAC_FLAG_USE_PHY_WOL flag to use the WoL capability of
the PHY.
Signed-off-by: Gatien Chevallier <gatien.chevallier@foss.st.com>
---
drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c
index 77a04c4579c9dbae886a0b387f69610a932b7b9e..6f197789cc2e8018d6959158b795e4bca46869c5 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c
@@ -106,6 +106,7 @@ struct stm32_dwmac {
u32 speed;
const struct stm32_ops *ops;
struct device *dev;
+ bool phy_wol;
};
struct stm32_ops {
@@ -433,6 +434,8 @@ static int stm32_dwmac_parse_data(struct stm32_dwmac *dwmac,
}
}
+ dwmac->phy_wol = of_property_read_bool(np, "st,phy-wol");
+
return err;
}
@@ -557,6 +560,8 @@ static int stm32_dwmac_probe(struct platform_device *pdev)
plat_dat->bsp_priv = dwmac;
plat_dat->suspend = stm32_dwmac_suspend;
plat_dat->resume = stm32_dwmac_resume;
+ if (dwmac->phy_wol)
+ plat_dat->flags |= STMMAC_FLAG_USE_PHY_WOL;
ret = stm32_dwmac_init(plat_dat);
if (ret)
--
2.35.3
On Wed, Sep 17, 2025 at 05:36:37PM +0200, Gatien Chevallier wrote: > If the "st,phy-wol" property is present in the device tree node, > set the STMMAC_FLAG_USE_PHY_WOL flag to use the WoL capability of > the PHY. > > Signed-off-by: Gatien Chevallier <gatien.chevallier@foss.st.com> > --- > drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c > index 77a04c4579c9dbae886a0b387f69610a932b7b9e..6f197789cc2e8018d6959158b795e4bca46869c5 100644 > --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c > +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c > @@ -106,6 +106,7 @@ struct stm32_dwmac { > u32 speed; > const struct stm32_ops *ops; > struct device *dev; > + bool phy_wol; > }; > > struct stm32_ops { > @@ -433,6 +434,8 @@ static int stm32_dwmac_parse_data(struct stm32_dwmac *dwmac, > } > } > > + dwmac->phy_wol = of_property_read_bool(np, "st,phy-wol"); > + > return err; > } > > @@ -557,6 +560,8 @@ static int stm32_dwmac_probe(struct platform_device *pdev) > plat_dat->bsp_priv = dwmac; > plat_dat->suspend = stm32_dwmac_suspend; > plat_dat->resume = stm32_dwmac_resume; > + if (dwmac->phy_wol) > + plat_dat->flags |= STMMAC_FLAG_USE_PHY_WOL; I would much rather we found a different approach, rather than adding custom per-driver DT properties to figure this out. Andrew has previously suggested that MAC drivers should ask the PHY whether WoL is supported, but this pre-supposes that PHY drivers are coded correctly to only report WoL capabilities if they are really capable of waking the system. As shown in your smsc PHY driver patch, this may not be the case. Given that we have historically had PHY drivers reporting WoL capabilities without being able to wake the system, we can't implement Andrew's suggestion easily. The only approach I can think that would allow us to transition is to add: static inline bool phy_can_wakeup(struct phy_device *phy_dev) { return device_can_wakeup(&phy_dev->mdio.dev); } to include/linux/phy.h, and a corresponding wrapper for phylink. This can then be used to determine whether to attempt to use PHY-based Wol in stmmac_get_wol() and rtl8211f_set_wol(), falling back to PMT-based WoL if supported at the MAC. So, maybe something like: static u32 stmmac_wol_support(struct stmmac_priv *priv) { u32 support = 0; if (priv->plat->pmt && device_can_wakeup(priv->device)) { support = WAKE_UCAST; if (priv->hw_cap_support && priv->dma_cap.pmt_magic_frame) support |= WAKE_MAGIC; } return support; } static void stmmac_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) { struct stmmac_priv *priv = netdev_priv(dev); int err; /* Check STMMAC_FLAG_USE_PHY_WOL for legacy */ if (phylink_can_wakeup(priv->phylink) || priv->plat->flags & STMMAC_FLAG_USE_PHY_WOL) { err = phylink_ethtool_get_wol(priv->phylink, wol); if (err != 0 && err != -EOPNOTSUPP) return; } wol->supported |= stmmac_wol_support(priv); /* A read of priv->wolopts is single-copy atomic. Locking * doesn't add any benefit. */ wol->wolopts |= priv->wolopts; } static int stmmac_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) { struct stmmac_priv *priv = netdev_priv(dev); u32 support, wolopts; int err; wolopts = wol->wolopts; /* Check STMMAC_FLAG_USE_PHY_WOL for legacy */ if (phylink_can_wakeup(priv->phylink) || priv->plat->flags & STMMAC_FLAG_USE_PHY_WOL) { struct ethtool_wolinfo w; err = phylink_ethtool_set_wol(priv->phylink, wol); if (err != -EOPNOTSUPP) return err; /* Remove the WoL modes that the PHY is handling */ if (!phylink_ethtool_get_wol(priv->phylink, &w)) wolopts &= ~w.wolopts; } support = stmmac_wol_support(priv); mutex_lock(&priv->lock); priv->wolopts = wolopts & support; device_set_wakeup_enable(priv->device, !!priv->wolopts); mutex_unlock(&priv->lock); return 0; } ... and now I'm wondering whether this complexity is something that phylink should handle internally, presenting a mac_set_wol() method to configure the MAC-side WoL settings. What makes it difficult to just move into phylink is the STMMAC_FLAG_USE_PHY_WOL flag, but that could be a "force_phy_wol" flag in struct phylink_config as a transitionary measure... so long as PHY drivers get fixed. -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
On Wed, Sep 17, 2025 at 05:31:16PM +0100, Russell King (Oracle) wrote: > On Wed, Sep 17, 2025 at 05:36:37PM +0200, Gatien Chevallier wrote: > > If the "st,phy-wol" property is present in the device tree node, > > set the STMMAC_FLAG_USE_PHY_WOL flag to use the WoL capability of > > the PHY. > > > > Signed-off-by: Gatien Chevallier <gatien.chevallier@foss.st.com> > > --- > > drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c | 5 +++++ > > 1 file changed, 5 insertions(+) > > > > diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c > > index 77a04c4579c9dbae886a0b387f69610a932b7b9e..6f197789cc2e8018d6959158b795e4bca46869c5 100644 > > --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c > > +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c > > @@ -106,6 +106,7 @@ struct stm32_dwmac { > > u32 speed; > > const struct stm32_ops *ops; > > struct device *dev; > > + bool phy_wol; > > }; > > > > struct stm32_ops { > > @@ -433,6 +434,8 @@ static int stm32_dwmac_parse_data(struct stm32_dwmac *dwmac, > > } > > } > > > > + dwmac->phy_wol = of_property_read_bool(np, "st,phy-wol"); > > + > > return err; > > } > > > > @@ -557,6 +560,8 @@ static int stm32_dwmac_probe(struct platform_device *pdev) > > plat_dat->bsp_priv = dwmac; > > plat_dat->suspend = stm32_dwmac_suspend; > > plat_dat->resume = stm32_dwmac_resume; > > + if (dwmac->phy_wol) > > + plat_dat->flags |= STMMAC_FLAG_USE_PHY_WOL; > > I would much rather we found a different approach, rather than adding > custom per-driver DT properties to figure this out. > > Andrew has previously suggested that MAC drivers should ask the PHY > whether WoL is supported, but this pre-supposes that PHY drivers are > coded correctly to only report WoL capabilities if they are really > capable of waking the system. As shown in your smsc PHY driver patch, > this may not be the case. > > Given that we have historically had PHY drivers reporting WoL > capabilities without being able to wake the system, we can't > implement Andrew's suggestion easily. > > The only approach I can think that would allow us to transition is > to add: > > static inline bool phy_can_wakeup(struct phy_device *phy_dev) > { > return device_can_wakeup(&phy_dev->mdio.dev); > } > > to include/linux/phy.h, and a corresponding wrapper for phylink. > This can then be used to determine whether to attempt to use PHY-based > Wol in stmmac_get_wol() and rtl8211f_set_wol(), falling back to > PMT-based WoL if supported at the MAC. > > So, maybe something like: > > static u32 stmmac_wol_support(struct stmmac_priv *priv) > { > u32 support = 0; > > if (priv->plat->pmt && device_can_wakeup(priv->device)) { > support = WAKE_UCAST; > if (priv->hw_cap_support && priv->dma_cap.pmt_magic_frame) > support |= WAKE_MAGIC; > } > > return support; > } > > static void stmmac_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) > { > struct stmmac_priv *priv = netdev_priv(dev); > int err; > > /* Check STMMAC_FLAG_USE_PHY_WOL for legacy */ > if (phylink_can_wakeup(priv->phylink) || > priv->plat->flags & STMMAC_FLAG_USE_PHY_WOL) { > err = phylink_ethtool_get_wol(priv->phylink, wol); > if (err != 0 && err != -EOPNOTSUPP) > return; > } > > wol->supported |= stmmac_wol_support(priv); > > /* A read of priv->wolopts is single-copy atomic. Locking > * doesn't add any benefit. > */ > wol->wolopts |= priv->wolopts; > } > > static int stmmac_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) > { > struct stmmac_priv *priv = netdev_priv(dev); > u32 support, wolopts; > int err; > > wolopts = wol->wolopts; > > /* Check STMMAC_FLAG_USE_PHY_WOL for legacy */ > if (phylink_can_wakeup(priv->phylink) || > priv->plat->flags & STMMAC_FLAG_USE_PHY_WOL) { > struct ethtool_wolinfo w; > > err = phylink_ethtool_set_wol(priv->phylink, wol); > if (err != -EOPNOTSUPP) > return err; > > /* Remove the WoL modes that the PHY is handling */ > if (!phylink_ethtool_get_wol(priv->phylink, &w)) > wolopts &= ~w.wolopts; > } > > support = stmmac_wol_support(priv); > > mutex_lock(&priv->lock); > priv->wolopts = wolopts & support; > device_set_wakeup_enable(priv->device, !!priv->wolopts); > mutex_unlock(&priv->lock); > > return 0; > } > > ... and now I'm wondering whether this complexity is something that > phylink should handle internally, presenting a mac_set_wol() method > to configure the MAC-side WoL settings. What makes it difficult to > just move into phylink is the STMMAC_FLAG_USE_PHY_WOL flag, but > that could be a "force_phy_wol" flag in struct phylink_config as > a transitionary measure... so long as PHY drivers get fixed. I came up with this as an experiment - I haven't tested it beyond running it through the compiler (didn't let it get to the link stage yet.) Haven't even done anything with it for stmmac yet. -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
On 9/26/2025 10:59 AM, Russell King (Oracle) wrote: > On Wed, Sep 17, 2025 at 05:31:16PM +0100, Russell King (Oracle) wrote: >> On Wed, Sep 17, 2025 at 05:36:37PM +0200, Gatien Chevallier wrote: >>> If the "st,phy-wol" property is present in the device tree node, >>> set the STMMAC_FLAG_USE_PHY_WOL flag to use the WoL capability of >>> the PHY. >>> >>> Signed-off-by: Gatien Chevallier <gatien.chevallier@foss.st.com> >>> --- >>> drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c | 5 +++++ >>> 1 file changed, 5 insertions(+) >>> >>> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c >>> index 77a04c4579c9dbae886a0b387f69610a932b7b9e..6f197789cc2e8018d6959158b795e4bca46869c5 100644 >>> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c >>> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c >>> @@ -106,6 +106,7 @@ struct stm32_dwmac { >>> u32 speed; >>> const struct stm32_ops *ops; >>> struct device *dev; >>> + bool phy_wol; >>> }; >>> >>> struct stm32_ops { >>> @@ -433,6 +434,8 @@ static int stm32_dwmac_parse_data(struct stm32_dwmac *dwmac, >>> } >>> } >>> >>> + dwmac->phy_wol = of_property_read_bool(np, "st,phy-wol"); >>> + >>> return err; >>> } >>> >>> @@ -557,6 +560,8 @@ static int stm32_dwmac_probe(struct platform_device *pdev) >>> plat_dat->bsp_priv = dwmac; >>> plat_dat->suspend = stm32_dwmac_suspend; >>> plat_dat->resume = stm32_dwmac_resume; >>> + if (dwmac->phy_wol) >>> + plat_dat->flags |= STMMAC_FLAG_USE_PHY_WOL; >> >> I would much rather we found a different approach, rather than adding >> custom per-driver DT properties to figure this out. >> >> Andrew has previously suggested that MAC drivers should ask the PHY >> whether WoL is supported, but this pre-supposes that PHY drivers are >> coded correctly to only report WoL capabilities if they are really >> capable of waking the system. As shown in your smsc PHY driver patch, >> this may not be the case. >> >> Given that we have historically had PHY drivers reporting WoL >> capabilities without being able to wake the system, we can't >> implement Andrew's suggestion easily. >> >> The only approach I can think that would allow us to transition is >> to add: >> >> static inline bool phy_can_wakeup(struct phy_device *phy_dev) >> { >> return device_can_wakeup(&phy_dev->mdio.dev); >> } >> >> to include/linux/phy.h, and a corresponding wrapper for phylink. >> This can then be used to determine whether to attempt to use PHY-based >> Wol in stmmac_get_wol() and rtl8211f_set_wol(), falling back to >> PMT-based WoL if supported at the MAC. >> >> So, maybe something like: >> >> static u32 stmmac_wol_support(struct stmmac_priv *priv) >> { >> u32 support = 0; >> >> if (priv->plat->pmt && device_can_wakeup(priv->device)) { >> support = WAKE_UCAST; >> if (priv->hw_cap_support && priv->dma_cap.pmt_magic_frame) >> support |= WAKE_MAGIC; >> } >> >> return support; >> } >> >> static void stmmac_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) >> { >> struct stmmac_priv *priv = netdev_priv(dev); >> int err; >> >> /* Check STMMAC_FLAG_USE_PHY_WOL for legacy */ >> if (phylink_can_wakeup(priv->phylink) || >> priv->plat->flags & STMMAC_FLAG_USE_PHY_WOL) { >> err = phylink_ethtool_get_wol(priv->phylink, wol); >> if (err != 0 && err != -EOPNOTSUPP) >> return; >> } >> >> wol->supported |= stmmac_wol_support(priv); >> >> /* A read of priv->wolopts is single-copy atomic. Locking >> * doesn't add any benefit. >> */ >> wol->wolopts |= priv->wolopts; >> } >> >> static int stmmac_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) >> { >> struct stmmac_priv *priv = netdev_priv(dev); >> u32 support, wolopts; >> int err; >> >> wolopts = wol->wolopts; >> >> /* Check STMMAC_FLAG_USE_PHY_WOL for legacy */ >> if (phylink_can_wakeup(priv->phylink) || >> priv->plat->flags & STMMAC_FLAG_USE_PHY_WOL) { >> struct ethtool_wolinfo w; >> >> err = phylink_ethtool_set_wol(priv->phylink, wol); >> if (err != -EOPNOTSUPP) >> return err; >> >> /* Remove the WoL modes that the PHY is handling */ >> if (!phylink_ethtool_get_wol(priv->phylink, &w)) >> wolopts &= ~w.wolopts; >> } >> >> support = stmmac_wol_support(priv); >> >> mutex_lock(&priv->lock); >> priv->wolopts = wolopts & support; >> device_set_wakeup_enable(priv->device, !!priv->wolopts); >> mutex_unlock(&priv->lock); >> >> return 0; >> } >> >> ... and now I'm wondering whether this complexity is something that >> phylink should handle internally, presenting a mac_set_wol() method >> to configure the MAC-side WoL settings. What makes it difficult to >> just move into phylink is the STMMAC_FLAG_USE_PHY_WOL flag, but >> that could be a "force_phy_wol" flag in struct phylink_config as >> a transitionary measure... so long as PHY drivers get fixed. > > I came up with this as an experiment - I haven't tested it beyond > running it through the compiler (didn't let it get to the link stage > yet.) Haven't even done anything with it for stmmac yet. > 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? -- Florian
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!
On 9/26/2025 12:05 PM, Florian Fainelli wrote: > > > On 9/26/2025 10:59 AM, Russell King (Oracle) wrote: >> On Wed, Sep 17, 2025 at 05:31:16PM +0100, Russell King (Oracle) wrote: >>> On Wed, Sep 17, 2025 at 05:36:37PM +0200, Gatien Chevallier wrote: >>>> If the "st,phy-wol" property is present in the device tree node, >>>> set the STMMAC_FLAG_USE_PHY_WOL flag to use the WoL capability of >>>> the PHY. >>>> >>>> Signed-off-by: Gatien Chevallier <gatien.chevallier@foss.st.com> >>>> --- >>>> drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c | 5 +++++ >>>> 1 file changed, 5 insertions(+) >>>> >>>> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c b/ >>>> drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c >>>> index >>>> 77a04c4579c9dbae886a0b387f69610a932b7b9e..6f197789cc2e8018d6959158b795e4bca46869c5 100644 >>>> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c >>>> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c >>>> @@ -106,6 +106,7 @@ struct stm32_dwmac { >>>> u32 speed; >>>> const struct stm32_ops *ops; >>>> struct device *dev; >>>> + bool phy_wol; >>>> }; >>>> struct stm32_ops { >>>> @@ -433,6 +434,8 @@ static int stm32_dwmac_parse_data(struct >>>> stm32_dwmac *dwmac, >>>> } >>>> } >>>> + dwmac->phy_wol = of_property_read_bool(np, "st,phy-wol"); >>>> + >>>> return err; >>>> } >>>> @@ -557,6 +560,8 @@ static int stm32_dwmac_probe(struct >>>> platform_device *pdev) >>>> plat_dat->bsp_priv = dwmac; >>>> plat_dat->suspend = stm32_dwmac_suspend; >>>> plat_dat->resume = stm32_dwmac_resume; >>>> + if (dwmac->phy_wol) >>>> + plat_dat->flags |= STMMAC_FLAG_USE_PHY_WOL; >>> >>> I would much rather we found a different approach, rather than adding >>> custom per-driver DT properties to figure this out. >>> >>> Andrew has previously suggested that MAC drivers should ask the PHY >>> whether WoL is supported, but this pre-supposes that PHY drivers are >>> coded correctly to only report WoL capabilities if they are really >>> capable of waking the system. As shown in your smsc PHY driver patch, >>> this may not be the case. >>> >>> Given that we have historically had PHY drivers reporting WoL >>> capabilities without being able to wake the system, we can't >>> implement Andrew's suggestion easily. >>> >>> The only approach I can think that would allow us to transition is >>> to add: >>> >>> static inline bool phy_can_wakeup(struct phy_device *phy_dev) >>> { >>> return device_can_wakeup(&phy_dev->mdio.dev); >>> } >>> >>> to include/linux/phy.h, and a corresponding wrapper for phylink. >>> This can then be used to determine whether to attempt to use PHY-based >>> Wol in stmmac_get_wol() and rtl8211f_set_wol(), falling back to >>> PMT-based WoL if supported at the MAC. >>> >>> So, maybe something like: >>> >>> static u32 stmmac_wol_support(struct stmmac_priv *priv) >>> { >>> u32 support = 0; >>> >>> if (priv->plat->pmt && device_can_wakeup(priv->device)) { >>> support = WAKE_UCAST; >>> if (priv->hw_cap_support && priv->dma_cap.pmt_magic_frame) >>> support |= WAKE_MAGIC; >>> } >>> >>> return support; >>> } >>> >>> static void stmmac_get_wol(struct net_device *dev, struct >>> ethtool_wolinfo *wol) >>> { >>> struct stmmac_priv *priv = netdev_priv(dev); >>> int err; >>> >>> /* Check STMMAC_FLAG_USE_PHY_WOL for legacy */ >>> if (phylink_can_wakeup(priv->phylink) || >>> priv->plat->flags & STMMAC_FLAG_USE_PHY_WOL) { >>> err = phylink_ethtool_get_wol(priv->phylink, wol); >>> if (err != 0 && err != -EOPNOTSUPP) >>> return; >>> } >>> >>> wol->supported |= stmmac_wol_support(priv); >>> >>> /* A read of priv->wolopts is single-copy atomic. Locking >>> * doesn't add any benefit. >>> */ >>> wol->wolopts |= priv->wolopts; >>> } >>> >>> static int stmmac_set_wol(struct net_device *dev, struct >>> ethtool_wolinfo *wol) >>> { >>> struct stmmac_priv *priv = netdev_priv(dev); >>> u32 support, wolopts; >>> int err; >>> >>> wolopts = wol->wolopts; >>> >>> /* Check STMMAC_FLAG_USE_PHY_WOL for legacy */ >>> if (phylink_can_wakeup(priv->phylink) || >>> priv->plat->flags & STMMAC_FLAG_USE_PHY_WOL) { >>> struct ethtool_wolinfo w; >>> >>> err = phylink_ethtool_set_wol(priv->phylink, wol); >>> if (err != -EOPNOTSUPP) >>> return err; >>> >>> /* Remove the WoL modes that the PHY is handling */ >>> if (!phylink_ethtool_get_wol(priv->phylink, &w)) >>> wolopts &= ~w.wolopts; >>> } >>> >>> support = stmmac_wol_support(priv); >>> >>> mutex_lock(&priv->lock); >>> priv->wolopts = wolopts & support; >>> device_set_wakeup_enable(priv->device, !!priv->wolopts); >>> mutex_unlock(&priv->lock); >>> >>> return 0; >>> } >>> >>> ... and now I'm wondering whether this complexity is something that >>> phylink should handle internally, presenting a mac_set_wol() method >>> to configure the MAC-side WoL settings. What makes it difficult to >>> just move into phylink is the STMMAC_FLAG_USE_PHY_WOL flag, but >>> that could be a "force_phy_wol" flag in struct phylink_config as >>> a transitionary measure... so long as PHY drivers get fixed. >> >> I came up with this as an experiment - I haven't tested it beyond >> running it through the compiler (didn't let it get to the link stage >> yet.) Haven't even done anything with it for stmmac yet. >> > > 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? + if (wolopts & WAKE_MAGIC) + changed |= !!memcmp(wol->sopass, pl->wol_sopass, + sizeof(wol->sopass)); Should not the hunk above be wolopts & WAKE_MAGICSECURE? -- Florian
On Sat, Sep 27, 2025 at 02:04:15PM -0700, Florian Fainelli wrote: > > > On 9/26/2025 12:05 PM, Florian Fainelli wrote: > > > > > > On 9/26/2025 10:59 AM, Russell King (Oracle) wrote: > > > On Wed, Sep 17, 2025 at 05:31:16PM +0100, Russell King (Oracle) wrote: > > > > On Wed, Sep 17, 2025 at 05:36:37PM +0200, Gatien Chevallier wrote: > > > > > If the "st,phy-wol" property is present in the device tree node, > > > > > set the STMMAC_FLAG_USE_PHY_WOL flag to use the WoL capability of > > > > > the PHY. > > > > > > > > > > Signed-off-by: Gatien Chevallier <gatien.chevallier@foss.st.com> > > > > > --- > > > > > drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c | 5 +++++ > > > > > 1 file changed, 5 insertions(+) > > > > > > > > > > diff --git > > > > > a/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c b/ > > > > > drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c > > > > > index 77a04c4579c9dbae886a0b387f69610a932b7b9e..6f197789cc2e8018d6959158b795e4bca46869c5 > > > > > 100644 > > > > > --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c > > > > > +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c > > > > > @@ -106,6 +106,7 @@ struct stm32_dwmac { > > > > > u32 speed; > > > > > const struct stm32_ops *ops; > > > > > struct device *dev; > > > > > + bool phy_wol; > > > > > }; > > > > > struct stm32_ops { > > > > > @@ -433,6 +434,8 @@ static int stm32_dwmac_parse_data(struct > > > > > stm32_dwmac *dwmac, > > > > > } > > > > > } > > > > > + dwmac->phy_wol = of_property_read_bool(np, "st,phy-wol"); > > > > > + > > > > > return err; > > > > > } > > > > > @@ -557,6 +560,8 @@ static int stm32_dwmac_probe(struct > > > > > platform_device *pdev) > > > > > plat_dat->bsp_priv = dwmac; > > > > > plat_dat->suspend = stm32_dwmac_suspend; > > > > > plat_dat->resume = stm32_dwmac_resume; > > > > > + if (dwmac->phy_wol) > > > > > + plat_dat->flags |= STMMAC_FLAG_USE_PHY_WOL; > > > > > > > > I would much rather we found a different approach, rather than adding > > > > custom per-driver DT properties to figure this out. > > > > > > > > Andrew has previously suggested that MAC drivers should ask the PHY > > > > whether WoL is supported, but this pre-supposes that PHY drivers are > > > > coded correctly to only report WoL capabilities if they are really > > > > capable of waking the system. As shown in your smsc PHY driver patch, > > > > this may not be the case. > > > > > > > > Given that we have historically had PHY drivers reporting WoL > > > > capabilities without being able to wake the system, we can't > > > > implement Andrew's suggestion easily. > > > > > > > > The only approach I can think that would allow us to transition is > > > > to add: > > > > > > > > static inline bool phy_can_wakeup(struct phy_device *phy_dev) > > > > { > > > > return device_can_wakeup(&phy_dev->mdio.dev); > > > > } > > > > > > > > to include/linux/phy.h, and a corresponding wrapper for phylink. > > > > This can then be used to determine whether to attempt to use PHY-based > > > > Wol in stmmac_get_wol() and rtl8211f_set_wol(), falling back to > > > > PMT-based WoL if supported at the MAC. > > > > > > > > So, maybe something like: > > > > > > > > static u32 stmmac_wol_support(struct stmmac_priv *priv) > > > > { > > > > u32 support = 0; > > > > > > > > if (priv->plat->pmt && device_can_wakeup(priv->device)) { > > > > support = WAKE_UCAST; > > > > if (priv->hw_cap_support && priv->dma_cap.pmt_magic_frame) > > > > support |= WAKE_MAGIC; > > > > } > > > > > > > > return support; > > > > } > > > > > > > > static void stmmac_get_wol(struct net_device *dev, struct > > > > ethtool_wolinfo *wol) > > > > { > > > > struct stmmac_priv *priv = netdev_priv(dev); > > > > int err; > > > > > > > > /* Check STMMAC_FLAG_USE_PHY_WOL for legacy */ > > > > if (phylink_can_wakeup(priv->phylink) || > > > > priv->plat->flags & STMMAC_FLAG_USE_PHY_WOL) { > > > > err = phylink_ethtool_get_wol(priv->phylink, wol); > > > > if (err != 0 && err != -EOPNOTSUPP) > > > > return; > > > > } > > > > > > > > wol->supported |= stmmac_wol_support(priv); > > > > > > > > /* A read of priv->wolopts is single-copy atomic. Locking > > > > * doesn't add any benefit. > > > > */ > > > > wol->wolopts |= priv->wolopts; > > > > } > > > > > > > > static int stmmac_set_wol(struct net_device *dev, struct > > > > ethtool_wolinfo *wol) > > > > { > > > > struct stmmac_priv *priv = netdev_priv(dev); > > > > u32 support, wolopts; > > > > int err; > > > > > > > > wolopts = wol->wolopts; > > > > > > > > /* Check STMMAC_FLAG_USE_PHY_WOL for legacy */ > > > > if (phylink_can_wakeup(priv->phylink) || > > > > priv->plat->flags & STMMAC_FLAG_USE_PHY_WOL) { > > > > struct ethtool_wolinfo w; > > > > > > > > err = phylink_ethtool_set_wol(priv->phylink, wol); > > > > if (err != -EOPNOTSUPP) > > > > return err; > > > > > > > > /* Remove the WoL modes that the PHY is handling */ > > > > if (!phylink_ethtool_get_wol(priv->phylink, &w)) > > > > wolopts &= ~w.wolopts; > > > > } > > > > > > > > support = stmmac_wol_support(priv); > > > > > > > > mutex_lock(&priv->lock); > > > > priv->wolopts = wolopts & support; > > > > device_set_wakeup_enable(priv->device, !!priv->wolopts); > > > > mutex_unlock(&priv->lock); > > > > > > > > return 0; > > > > } > > > > > > > > ... and now I'm wondering whether this complexity is something that > > > > phylink should handle internally, presenting a mac_set_wol() method > > > > to configure the MAC-side WoL settings. What makes it difficult to > > > > just move into phylink is the STMMAC_FLAG_USE_PHY_WOL flag, but > > > > that could be a "force_phy_wol" flag in struct phylink_config as > > > > a transitionary measure... so long as PHY drivers get fixed. > > > > > > I came up with this as an experiment - I haven't tested it beyond > > > running it through the compiler (didn't let it get to the link stage > > > yet.) Haven't even done anything with it for stmmac yet. > > > > > > > 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? > > + if (wolopts & WAKE_MAGIC) > + changed |= !!memcmp(wol->sopass, pl->wol_sopass, > + sizeof(wol->sopass)); > > > Should not the hunk above be wolopts & WAKE_MAGICSECURE? Yes, and there's a few other bits missing as well. The series has progressed, and stmmac is converted and tested on my Jetson platform. -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
On 9/17/25 18:31, Russell King (Oracle) wrote: > On Wed, Sep 17, 2025 at 05:36:37PM +0200, Gatien Chevallier wrote: >> If the "st,phy-wol" property is present in the device tree node, >> set the STMMAC_FLAG_USE_PHY_WOL flag to use the WoL capability of >> the PHY. >> >> Signed-off-by: Gatien Chevallier <gatien.chevallier@foss.st.com> >> --- >> drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c | 5 +++++ >> 1 file changed, 5 insertions(+) >> >> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c >> index 77a04c4579c9dbae886a0b387f69610a932b7b9e..6f197789cc2e8018d6959158b795e4bca46869c5 100644 >> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c >> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c >> @@ -106,6 +106,7 @@ struct stm32_dwmac { >> u32 speed; >> const struct stm32_ops *ops; >> struct device *dev; >> + bool phy_wol; >> }; >> >> struct stm32_ops { >> @@ -433,6 +434,8 @@ static int stm32_dwmac_parse_data(struct stm32_dwmac *dwmac, >> } >> } >> >> + dwmac->phy_wol = of_property_read_bool(np, "st,phy-wol"); >> + >> return err; >> } >> >> @@ -557,6 +560,8 @@ static int stm32_dwmac_probe(struct platform_device *pdev) >> plat_dat->bsp_priv = dwmac; >> plat_dat->suspend = stm32_dwmac_suspend; >> plat_dat->resume = stm32_dwmac_resume; >> + if (dwmac->phy_wol) >> + plat_dat->flags |= STMMAC_FLAG_USE_PHY_WOL; > > I would much rather we found a different approach, rather than adding > custom per-driver DT properties to figure this out. > > Andrew has previously suggested that MAC drivers should ask the PHY > whether WoL is supported, but this pre-supposes that PHY drivers are > coded correctly to only report WoL capabilities if they are really > capable of waking the system. As shown in your smsc PHY driver patch, > this may not be the case. So how can we distinguish whether a PHY that implements WoL features is actually able (wired) to wake up the system? By adding the "wakeup-source" property to the PHY node? Therefore, only set the "can wakeup" capability when both the PHY supports WoL and the property is present in the PHY node? However, this does not solve the actual static pin function configuration for pins that can, if correct alternate function is selected, generate interrupts, in PHY drivers. It would be nice to be able to apply some kind of pinctrl to configure the PHY pins over the MDIO bus thanks to some kind of pinctrl hogging. This suggests modifying relevant PHY drivers and documentation to be able to handle an optional pinctrl. Disregarding syntax issues, could be something like: phy0_eth1: ethernet-phy@0 { compatible = "ethernet-phy-id0007.c131"; reg = <0>; reset-gpios = <&mcp23017 9 GPIO_ACTIVE_LOW>; wakeup-source; pinctrl-0 = <&phy_pin_npme_hog &phy_pin_nint_hog>; phy_pin_npme_hog: nPME { pins = "LED2/nINT/nPME/nINTSEL"; function = "nPME"; }; phy_pin_nint_hog: nINT { pins = "LED1/nINT/nPME/nINTSEL"; function = "nINT"; }; }; What do you think of that? Otherwise, the idea below looks promising to me. > > Given that we have historically had PHY drivers reporting WoL > capabilities without being able to wake the system, we can't > implement Andrew's suggestion easily. > > The only approach I can think that would allow us to transition is > to add: > > static inline bool phy_can_wakeup(struct phy_device *phy_dev) > { > return device_can_wakeup(&phy_dev->mdio.dev); > } > > to include/linux/phy.h, and a corresponding wrapper for phylink. > This can then be used to determine whether to attempt to use PHY-based > Wol in stmmac_get_wol() and rtl8211f_set_wol(), falling back to > PMT-based WoL if supported at the MAC. > > So, maybe something like: > > static u32 stmmac_wol_support(struct stmmac_priv *priv) > { > u32 support = 0; > > if (priv->plat->pmt && device_can_wakeup(priv->device)) { > support = WAKE_UCAST; > if (priv->hw_cap_support && priv->dma_cap.pmt_magic_frame) > support |= WAKE_MAGIC; > } > > return support; > } > > static void stmmac_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) > { > struct stmmac_priv *priv = netdev_priv(dev); > int err; > > /* Check STMMAC_FLAG_USE_PHY_WOL for legacy */ > if (phylink_can_wakeup(priv->phylink) || > priv->plat->flags & STMMAC_FLAG_USE_PHY_WOL) { > err = phylink_ethtool_get_wol(priv->phylink, wol); > if (err != 0 && err != -EOPNOTSUPP) > return; > } > > wol->supported |= stmmac_wol_support(priv); > > /* A read of priv->wolopts is single-copy atomic. Locking > * doesn't add any benefit. > */ > wol->wolopts |= priv->wolopts; > } > > static int stmmac_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) > { > struct stmmac_priv *priv = netdev_priv(dev); > u32 support, wolopts; > int err; > > wolopts = wol->wolopts; > > /* Check STMMAC_FLAG_USE_PHY_WOL for legacy */ > if (phylink_can_wakeup(priv->phylink) || > priv->plat->flags & STMMAC_FLAG_USE_PHY_WOL) { > struct ethtool_wolinfo w; > > err = phylink_ethtool_set_wol(priv->phylink, wol); > if (err != -EOPNOTSUPP) > return err; > > /* Remove the WoL modes that the PHY is handling */ > if (!phylink_ethtool_get_wol(priv->phylink, &w)) > wolopts &= ~w.wolopts; > } > > support = stmmac_wol_support(priv); > > mutex_lock(&priv->lock); > priv->wolopts = wolopts & support; > device_set_wakeup_enable(priv->device, !!priv->wolopts); > mutex_unlock(&priv->lock); > > return 0; > } > > ... and now I'm wondering whether this complexity is something that > phylink should handle internally, presenting a mac_set_wol() method > to configure the MAC-side WoL settings. What makes it difficult to > just move into phylink is the STMMAC_FLAG_USE_PHY_WOL flag, but > that could be a "force_phy_wol" flag in struct phylink_config as > a transitionary measure... so long as PHY drivers get fixed. >
> > Andrew has previously suggested that MAC drivers should ask the PHY > > whether WoL is supported, but this pre-supposes that PHY drivers are > > coded correctly to only report WoL capabilities if they are really > > capable of waking the system. As shown in your smsc PHY driver patch, > > this may not be the case. > > So how can we distinguish whether a PHY that implements WoL features > is actually able (wired) to wake up the system? By adding the > "wakeup-source" property to the PHY node? > > Therefore, only set the "can wakeup" capability when both the PHY > supports WoL and the property is present in the PHY node? There are layering issue to solve, and backwards compatibility problems, but basically yes. I would prefer to keep the phylib API simple. Call get_wol() and it returns an empty set if the PHY is definitely not capable of waking the system. Calling set_wol() returns -EOPNOTSUPP, or maybe -EINVAL, if it definitely cannot wake the system. However, 'wakeup-source' on its own is not sufficient. It indicates the PHY definitely can wake the system. However, it being missing does not tell us it cannot wake the system, because old DT blobs never had it, but i assume some work, and some are broken. We need the PHY driver involved as well. If the driver only supports WoL via interrupts, and phy_interrupt_is_valid() returns False, it cannot wake the system. There other tests we can make, like device_can_wakeup(). In the end, we probably have some cases where we know it should work, some cases we know it will not work, and a middle ground, shrug our shoulders, it might work, try it and see. > However, this does not solve the actual static pin function > configuration for pins that can, if correct alternate function is > selected, generate interrupts, in PHY drivers. > > It would be nice to be able to apply some kind of pinctrl to configure > the PHY pins over the MDIO bus thanks to some kind of pinctrl hogging. I don't think it needs to be hogging. From what i remember of pinctrl, when a driver is probed, pinctrl-0 is activated. It is not limited to pins which the driver directly uses. So if LED2 is connected to a pin, pinctrl can at least select the needed function for that pin. Andrew
On 9/18/25 17:34, Andrew Lunn wrote: >>> Andrew has previously suggested that MAC drivers should ask the PHY >>> whether WoL is supported, but this pre-supposes that PHY drivers are >>> coded correctly to only report WoL capabilities if they are really >>> capable of waking the system. As shown in your smsc PHY driver patch, >>> this may not be the case. >> >> So how can we distinguish whether a PHY that implements WoL features >> is actually able (wired) to wake up the system? By adding the >> "wakeup-source" property to the PHY node? >> >> Therefore, only set the "can wakeup" capability when both the PHY >> supports WoL and the property is present in the PHY node? > > There are layering issue to solve, and backwards compatibility > problems, but basically yes. > Ack > I would prefer to keep the phylib API simple. Call get_wol() and it > returns an empty set if the PHY is definitely not capable of waking > the system. Calling set_wol() returns -EOPNOTSUPP, or maybe -EINVAL, > if it definitely cannot wake the system. > > However, 'wakeup-source' on its own is not sufficient. It indicates > the PHY definitely can wake the system. However, it being missing does > not tell us it cannot wake the system, because old DT blobs never had > it, but i assume some work, and some are broken. > > We need the PHY driver involved as well. If the driver only supports > WoL via interrupts, and phy_interrupt_is_valid() returns False, it > cannot wake the system. > > There other tests we can make, like device_can_wakeup(). In the end, > we probably have some cases where we know it should work, some cases > we know it will not work, and a middle ground, shrug our shoulders, it > might work, try it and see. > >> However, this does not solve the actual static pin function >> configuration for pins that can, if correct alternate function is >> selected, generate interrupts, in PHY drivers. >> >> It would be nice to be able to apply some kind of pinctrl to configure >> the PHY pins over the MDIO bus thanks to some kind of pinctrl hogging. > > I don't think it needs to be hogging. From what i remember of pinctrl, > when a driver is probed, pinctrl-0 is activated. It is not limited to > pins which the driver directly uses. So if LED2 is connected to a pin, > pinctrl can at least select the needed function for that pin. > Ok, I'll see where it takes me in a separate patch-set. Thank you for the feedback and clarifications. Gatien > Andrew
On Thu, Sep 18, 2025 at 02:46:54PM +0200, Gatien CHEVALLIER wrote: > On 9/17/25 18:31, Russell King (Oracle) wrote: > > On Wed, Sep 17, 2025 at 05:36:37PM +0200, Gatien Chevallier wrote: > > > If the "st,phy-wol" property is present in the device tree node, > > > set the STMMAC_FLAG_USE_PHY_WOL flag to use the WoL capability of > > > the PHY. > > > > > > Signed-off-by: Gatien Chevallier <gatien.chevallier@foss.st.com> > > > --- > > > drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c | 5 +++++ > > > 1 file changed, 5 insertions(+) > > > > > > diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c > > > index 77a04c4579c9dbae886a0b387f69610a932b7b9e..6f197789cc2e8018d6959158b795e4bca46869c5 100644 > > > --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c > > > +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c > > > @@ -106,6 +106,7 @@ struct stm32_dwmac { > > > u32 speed; > > > const struct stm32_ops *ops; > > > struct device *dev; > > > + bool phy_wol; > > > }; > > > struct stm32_ops { > > > @@ -433,6 +434,8 @@ static int stm32_dwmac_parse_data(struct stm32_dwmac *dwmac, > > > } > > > } > > > + dwmac->phy_wol = of_property_read_bool(np, "st,phy-wol"); > > > + > > > return err; > > > } > > > @@ -557,6 +560,8 @@ static int stm32_dwmac_probe(struct platform_device *pdev) > > > plat_dat->bsp_priv = dwmac; > > > plat_dat->suspend = stm32_dwmac_suspend; > > > plat_dat->resume = stm32_dwmac_resume; > > > + if (dwmac->phy_wol) > > > + plat_dat->flags |= STMMAC_FLAG_USE_PHY_WOL; > > > > I would much rather we found a different approach, rather than adding > > custom per-driver DT properties to figure this out. > > > > Andrew has previously suggested that MAC drivers should ask the PHY > > whether WoL is supported, but this pre-supposes that PHY drivers are > > coded correctly to only report WoL capabilities if they are really > > capable of waking the system. As shown in your smsc PHY driver patch, > > this may not be the case. > > So how can we distinguish whether a PHY that implements WoL features > is actually able (wired) to wake up the system? By adding the > "wakeup-source" property to the PHY node? Andrew's original idea was essentially that if the PHY reports that it supports WoL, then it's functional. Sadly, that's not the case with many PHY drivers - the driver implementers just considered "does this PHY have the ability to detect WoL packets" and not "can this PHY actually wake the system." Thankfully, all but one PHY driver does not use device_set_wakeup_capable() - my recent patches for realtek look like the first PHY driver to use this. Thus, if we insist that PHY drivers use device_set_wakeup_capable() to indicate that (a) they have WoL capability _and_ are really capable of waking the system, we have a knob we can test for. Sadly, there is no way to really know whether the interrupt that the PHY is attached to can wake the system. Things get worse with PHYs that don't use interrupts to wake the system. So, I would suggest that, as we already have this "wakeup-source" property available for _any_ device in DT, we start using this to say "on this system, this PHY is connected to something that can wake the system up." See the past discussion when Realtek was being added - some of the context there covers what I mention above. > Therefore, only set the "can wakeup" capability when both the PHY > supports WoL and the property is present in the PHY node? Given that telling the device model that a device is wakeup capable causes this to be advertised to userspace, we really do not want devices saying that they are wakeup capable when they aren't capable of waking the system. So I would say that a call to device_set_wakeup_capable(dev, true) should _only_ be made if the driver is 100% certain that this device really can, without question, wake the platform. If we don't have that guarantee, then we're on a hiding to nothing and chaos will reign, MAC drivers won't work properly... but I would suggest that's the price to be paid for shoddy implementation and not adhering to a sensible approach such as what I outline above. > However, this does not solve the actual static pin function > configuration for pins that can, if correct alternate function is > selected, generate interrupts, in PHY drivers. > > It would be nice to be able to apply some kind of pinctrl to configure > the PHY pins over the MDIO bus thanks to some kind of pinctrl hogging. > This suggests modifying relevant PHY drivers and documentation to be > able to handle an optional pinctrl. How would that work with something like the Realtek 8821F which has a single pin which can either signal interrupts (including a wake-up) or be in PME mode, where it only ever signals a wake-up event. Dynamically switching between the two modes is what got us into the crazy situation where, when WoL was enabled on this PHY, phylib stopped working because the pin was switched to PME mode, and we no longer got link status interrupts. So one could enable WoL, plug in an ethernet cable, and the kernel has no idea that the link has come up. So no. In a situation like this, either we want to be in interrupt mode (in which case we have an interrupt), or the pin is wired to a power management controller and needs to be in PME mode, or it isn't wired. Which it is can be easily identified. $1. Is there an interrupt specified (Y/N) ? $2. Is there a wakeup-source property (Y/N) ? States: $1 $2 * N we have no idea if an interrupt (if specified) can wake the system, or if there is other wiring from the PHY which might. Legacy driver, or has no wake-up support. We have to fall back on existing approaches to maintain compatibility and void breaking userspace, which may suggest WoL is supported when it isn't. For example, with stmmac, if STMMAC_FLAG_USE_PHY_WOL is set, we must assume the PHY can wake the system in this case. Y Y interrupt wakes the system, we're good for WoL N Y non-interrupt method of waking the system, e.g. PME I'd prefer not to go for a complicated solution to this, e.g. involving pinctrl, when we don't know how many PHYs need this, because forcing extra complexity on driver authors means we have yet more to review, and I think it's fair to say that we're already missing stuff. Getting the pinctrl stuff right also requires knowledge of the hardware, and is likely something that reviewers can't know if it's correct or not - because datasheets giving this information aren't publicly available. So, I'm all in favour of "keep it damn simple, don't give people more work, even if it looks nice in DT" here. -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
On 9/18/25 15:59, Russell King (Oracle) wrote: > On Thu, Sep 18, 2025 at 02:46:54PM +0200, Gatien CHEVALLIER wrote: >> On 9/17/25 18:31, Russell King (Oracle) wrote: >>> On Wed, Sep 17, 2025 at 05:36:37PM +0200, Gatien Chevallier wrote: >>>> If the "st,phy-wol" property is present in the device tree node, >>>> set the STMMAC_FLAG_USE_PHY_WOL flag to use the WoL capability of >>>> the PHY. >>>> >>>> Signed-off-by: Gatien Chevallier <gatien.chevallier@foss.st.com> >>>> --- >>>> drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c | 5 +++++ >>>> 1 file changed, 5 insertions(+) >>>> >>>> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c >>>> index 77a04c4579c9dbae886a0b387f69610a932b7b9e..6f197789cc2e8018d6959158b795e4bca46869c5 100644 >>>> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c >>>> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c >>>> @@ -106,6 +106,7 @@ struct stm32_dwmac { >>>> u32 speed; >>>> const struct stm32_ops *ops; >>>> struct device *dev; >>>> + bool phy_wol; >>>> }; >>>> struct stm32_ops { >>>> @@ -433,6 +434,8 @@ static int stm32_dwmac_parse_data(struct stm32_dwmac *dwmac, >>>> } >>>> } >>>> + dwmac->phy_wol = of_property_read_bool(np, "st,phy-wol"); >>>> + >>>> return err; >>>> } >>>> @@ -557,6 +560,8 @@ static int stm32_dwmac_probe(struct platform_device *pdev) >>>> plat_dat->bsp_priv = dwmac; >>>> plat_dat->suspend = stm32_dwmac_suspend; >>>> plat_dat->resume = stm32_dwmac_resume; >>>> + if (dwmac->phy_wol) >>>> + plat_dat->flags |= STMMAC_FLAG_USE_PHY_WOL; >>> >>> I would much rather we found a different approach, rather than adding >>> custom per-driver DT properties to figure this out. >>> >>> Andrew has previously suggested that MAC drivers should ask the PHY >>> whether WoL is supported, but this pre-supposes that PHY drivers are >>> coded correctly to only report WoL capabilities if they are really >>> capable of waking the system. As shown in your smsc PHY driver patch, >>> this may not be the case. >> >> So how can we distinguish whether a PHY that implements WoL features >> is actually able (wired) to wake up the system? By adding the >> "wakeup-source" property to the PHY node? > > Andrew's original idea was essentially that if the PHY reports that it > supports WoL, then it's functional. > > Sadly, that's not the case with many PHY drivers - the driver > implementers just considered "does this PHY have the ability to detect > WoL packets" and not "can this PHY actually wake the system." > > Thankfully, all but one PHY driver does not use > device_set_wakeup_capable() - my recent patches for realtek look like > the first PHY driver to use this. > > Thus, if we insist that PHY drivers use device_set_wakeup_capable() > to indicate that (a) they have WoL capability _and_ are really > capable of waking the system, we have a knob we can test for. > > Sadly, there is no way to really know whether the interrupt that the > PHY is attached to can wake the system. Things get worse with PHYs > that don't use interrupts to wake the system. So, I would suggest > that, as we already have this "wakeup-source" property available for > _any_ device in DT, we start using this to say "on this system, this > PHY is connected to something that can wake the system up." > Sure, seems fair. > See the past discussion when Realtek was being added - some of the > context there covers what I mention above. > >> Therefore, only set the "can wakeup" capability when both the PHY >> supports WoL and the property is present in the PHY node? > > Given that telling the device model that a device is wakeup > capable causes this to be advertised to userspace, we really do > not want devices saying that they are wakeup capable when they > aren't capable of waking the system. So I would say that a call > to device_set_wakeup_capable(dev, true) should _only_ be made if > the driver is 100% certain that this device really can, without > question, wake the platform. > > If we don't have that guarantee, then we're on a hiding to nothing > and chaos will reign, MAC drivers won't work properly... but I would > suggest that's the price to be paid for shoddy implementation and > not adhering to a sensible approach such as what I outline above. > >> However, this does not solve the actual static pin function >> configuration for pins that can, if correct alternate function is >> selected, generate interrupts, in PHY drivers. >> >> It would be nice to be able to apply some kind of pinctrl to configure >> the PHY pins over the MDIO bus thanks to some kind of pinctrl hogging. >> This suggests modifying relevant PHY drivers and documentation to be >> able to handle an optional pinctrl. > > How would that work with something like the Realtek 8821F which has > a single pin which can either signal interrupts (including a wake-up) > or be in PME mode, where it only ever signals a wake-up event. > Dynamically switching between the two modes is what got us into the > crazy situation where, when WoL was enabled on this PHY, phylib > stopped working because the pin was switched to PME mode, and we no > longer got link status interrupts. So one could enable WoL, plug in > an ethernet cable, and the kernel has no idea that the link has come > up. > > So no. In a situation like this, either we want to be in interrupt > mode (in which case we have an interrupt), or the pin is wired to > a power management controller and needs to be in PME mode, or it isn't > wired. > If you are in interrupt mode, plugging a cable would trigger a system wakeup in low-power mode if the INTB/PMEB line is wired to a power management controller and the WoL is enabled because we're no longer in polling mode, wouldn't it? I tested on the stm32mp135f-dk and it seems that's the case. Or in this case, maybe I should never describe an interrupt in the DT? You can argue that as per the Realtek 8211F datasheet: "The interrupts can be individually enabled or disabled by setting or clearing bits in the interrupt enable register INER". That requires PHY registers handling when going to low-power mode. There are PHYs like the LAN8742 on which 3 pins can be configured as nINT(equivalent to INTB), and 2 as nPME(equivalent to PMEB). The smsc driver, as is, contains hardcoded nPME mode on the LED2/nINT/nPME/nINTSEL pin. What if a manufacturer wired the power management controller to the LED1/nINT/nPME/nINTSEL? This is where the pinctrl would help even if I do agree it might be a bit tedious at first. The pinctrl would be optional though. On the other hand, if the pin is wired to a power management controller and configured in PMEB mode, then an interrupt cannot be described in the DT because the polling mode will be disabled and the PHY won't generate an interrupt on, let's say, a cable being plugged => no link as well (I had this issue on the stm32mp135f-dk board where the LED2/nINT/nPME/nINTSEL is wired to the power management controller and there is no other nINT-capable line wired). So it seems there are still some issues but I may be missing some elements here. > Which it is can be easily identified. > > $1. Is there an interrupt specified (Y/N) ? > $2. Is there a wakeup-source property (Y/N) ? > > States: > $1 $2 > * N we have no idea if an interrupt (if specified) can wake the > system, or if there is other wiring from the PHY which might. > Legacy driver, or has no wake-up support. We have to fall back > on existing approaches to maintain compatibility and void > breaking userspace, which may suggest WoL is supported when it > isn't. For example, with stmmac, if STMMAC_FLAG_USE_PHY_WOL is > set, we must assume the PHY can wake the system in this case. > Y Y interrupt wakes the system, we're good for WoL > N Y non-interrupt method of waking the system, e.g. PME > > I'd prefer not to go for a complicated solution to this, e.g. involving > pinctrl, when we don't know how many PHYs need this, because forcing > extra complexity on driver authors means we have yet more to review, and > I think it's fair to say that we're already missing stuff. Getting the > pinctrl stuff right also requires knowledge of the hardware, and is > likely something that reviewers can't know if it's correct or not - > because datasheets giving this information aren't publicly available. > > So, I'm all in favour of "keep it damn simple, don't give people more > work, even if it looks nice in DT" here. >
On Thu, Sep 18, 2025 at 05:07:00PM +0200, Gatien CHEVALLIER wrote: > On 9/18/25 15:59, Russell King (Oracle) wrote: > > > So no. In a situation like this, either we want to be in interrupt > > mode (in which case we have an interrupt), or the pin is wired to > > a power management controller and needs to be in PME mode, or it isn't > > wired. > > > > If you are in interrupt mode, plugging a cable would trigger a > system wakeup in low-power mode if the INTB/PMEB line is wired to a > power management controller and the WoL is enabled because we're no > longer in polling mode, wouldn't it? What Andrew suggested, which is what I implemented for Realtek, other interrupts get disabled when we enter suspend: static int rtl8211f_suspend(struct phy_device *phydev) { ... /* If a PME event is enabled, then configure the interrupt for * PME events only, disabling link interrupt. We avoid switching * to PMEB mode as we don't have a status bit for that. */ if (device_may_wakeup(&phydev->mdio.dev)) { ret = phy_write_paged(phydev, 0xa42, RTL821x_INER, RTL8211F_INER_PME); This disables all other interrupts when entering suspend _if_ WoL is enabled and only if WoL is enabled. If you're getting woken up when you unplug/replug the ethernet cable when WoL is disabled, that suggests you have something wrong in your interrupt controller - the wake-up state of the interrupt is managed by core driver-model code. I tested this on nVidia Jetson Xavier NX and if WoL wasn't enabled at the PHY, no wakeup occurred. > You can argue that as per the Realtek 8211F datasheet: > "The interrupts can be individually enabled or disabled by setting or > clearing bits in the interrupt enable register INER". That requires > PHY registers handling when going to low-power mode. ... which is what my patch does. > There are PHYs like the LAN8742 on which 3 pins can be configured > as nINT(equivalent to INTB), and 2 as nPME(equivalent to PMEB). The > smsc driver, as is, contains hardcoded nPME mode on the > LED2/nINT/nPME/nINTSEL pin. What if a manufacturer wired the power > management controller to the LED1/nINT/nPME/nINTSEL? > This is where the pinctrl would help even if I do agree it might be a > bit tedious at first. The pinctrl would be optional though. I'm not opposing the idea of pinctrl on PHYs. I'm opposing the idea of tying it into the WoL code in a way that makes it mandatory. Of course, if it makes sense for a PHY driver to do pinctrl stuff then go ahead - and if from that, the driver can work out that the PHY is wake-up capable, even better. What I was trying to say is that in such a case as the Realtek driver, I don't want to see pinctrl forced upon it unless there is a real reason and benefit, especially when there are simpler ways to do this. I also think that it would be helpful to add the wakeup-source property where PHYs are so capable even if the PHY driver doesn't need it for two reasons. 1. OS independence. 2. it's useful docs. 3. just because our driver as it stands at whatever moment in time doesn't make use of it doesn't mean that will always be the case. (e.g., we may want to have e.g. phylib looking at that property.) -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
On 9/18/25 17:36, Russell King (Oracle) wrote: > On Thu, Sep 18, 2025 at 05:07:00PM +0200, Gatien CHEVALLIER wrote: >> On 9/18/25 15:59, Russell King (Oracle) wrote: >>> > So no. In a situation like this, either we want to be in interrupt >>> mode (in which case we have an interrupt), or the pin is wired to >>> a power management controller and needs to be in PME mode, or it isn't >>> wired. >>> >> >> If you are in interrupt mode, plugging a cable would trigger a >> system wakeup in low-power mode if the INTB/PMEB line is wired to a >> power management controller and the WoL is enabled because we're no >> longer in polling mode, wouldn't it? > > What Andrew suggested, which is what I implemented for Realtek, other > interrupts get disabled when we enter suspend: > > static int rtl8211f_suspend(struct phy_device *phydev) > { > ... > /* If a PME event is enabled, then configure the interrupt for > * PME events only, disabling link interrupt. We avoid switching > * to PMEB mode as we don't have a status bit for that. > */ > if (device_may_wakeup(&phydev->mdio.dev)) { > ret = phy_write_paged(phydev, 0xa42, RTL821x_INER, > RTL8211F_INER_PME); > > This disables all other interrupts when entering suspend _if_ WoL > is enabled and only if WoL is enabled. > > If you're getting woken up when you unplug/replug the ethernet cable > when WoL is disabled, that suggests you have something wrong in your > interrupt controller - the wake-up state of the interrupt is managed > by core driver-model code. I tested this on nVidia Jetson Xavier NX > and if WoL wasn't enabled at the PHY, no wakeup occurred. > I'll replicate what you've done for the masking of interrupt when going to low-power modes to the Microchip driver and see where it takes me. The wakeup occurred because I didn't mask the other interrupt sources in nINT mode... :) >> You can argue that as per the Realtek 8211F datasheet: >> "The interrupts can be individually enabled or disabled by setting or >> clearing bits in the interrupt enable register INER". That requires >> PHY registers handling when going to low-power mode. > > ... which is what my patch does. > >> There are PHYs like the LAN8742 on which 3 pins can be configured >> as nINT(equivalent to INTB), and 2 as nPME(equivalent to PMEB). The >> smsc driver, as is, contains hardcoded nPME mode on the >> LED2/nINT/nPME/nINTSEL pin. What if a manufacturer wired the power >> management controller to the LED1/nINT/nPME/nINTSEL? >> This is where the pinctrl would help even if I do agree it might be a >> bit tedious at first. The pinctrl would be optional though. > > I'm not opposing the idea of pinctrl on PHYs. I'm opposing the idea > of tying it into the WoL code in a way that makes it mandatory. > Of course, if it makes sense for a PHY driver to do pinctrl stuff > then go ahead - and if from that, the driver can work out that > the PHY is wake-up capable, even better. > > What I was trying to say is that in such a case as the Realtek > driver, I don't want to see pinctrl forced upon it unless there is > a real reason and benefit, especially when there are simpler ways > to do this. > Yes, sure, I think there's a proper use-case for it. If it's going to happen, I think it would need a dedicated P-R. I'll send a V3 in the near future addressing what we discussed here. Thank you for the feedback. > I also think that it would be helpful to add the wakeup-source > property where PHYs are so capable even if the PHY driver doesn't > need it for two reasons. 1. OS independence. 2. it's useful docs. > 3. just because our driver as it stands at whatever moment in time > doesn't make use of it doesn't mean that will always be the case. > (e.g., we may want to have e.g. phylib looking at that property.) >
© 2016 - 2025 Red Hat, Inc.