lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <64b32996-9862-4716-8d14-16c80c4a2b10@foss.st.com>
Date: Thu, 18 Sep 2025 17:07:00 +0200
From: Gatien CHEVALLIER <gatien.chevallier@...s.st.com>
To: "Russell King (Oracle)" <linux@...linux.org.uk>
CC: Andrew Lunn <andrew+netdev@...n.ch>,
        "David S. Miller"
	<davem@...emloft.net>,
        Eric Dumazet <edumazet@...gle.com>, Jakub Kicinski
	<kuba@...nel.org>,
        Paolo Abeni <pabeni@...hat.com>, Rob Herring
	<robh@...nel.org>,
        Krzysztof Kozlowski <krzk+dt@...nel.org>,
        Conor Dooley
	<conor+dt@...nel.org>,
        Maxime Coquelin <mcoquelin.stm32@...il.com>,
        "Alexandre Torgue" <alexandre.torgue@...s.st.com>,
        Christophe Roullier
	<christophe.roullier@...s.st.com>,
        Andrew Lunn <andrew@...n.ch>,
        "Heiner
 Kallweit" <hkallweit1@...il.com>,
        Simon Horman <horms@...nel.org>,
        Tristram
 Ha <Tristram.Ha@...rochip.com>,
        Florian Fainelli
	<florian.fainelli@...adcom.com>,
        <netdev@...r.kernel.org>, <devicetree@...r.kernel.org>,
        <linux-stm32@...md-mailman.stormreply.com>,
        <linux-arm-kernel@...ts.infradead.org>, <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH net-next v2 2/4] net: stmmac: stm32: add WoL from PHY
 support



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@...s.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.
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ