Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: magnusleatti@kernelriot.com
Cc: me@ziyao.cc, maxime.chevallier@bootlin.com,
	andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
	kuba@kernel.org, pabeni@redhat.com, mcoquelin.stm32@gmail.com,
	alexandre.torgue@foss.st.com, g.nespolino@gmail.com,
	netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next 2/2] net: stmmac: dwmac-motorcomm: support Wake-on-LAN from S5
Date: Wed, 18 Nov 2026 09:18:31 +0000	[thread overview]
Message-ID: <179499351186.3136.1370230751729152458@kernel.org> (raw)
In-Reply-To: <20261116091757.1656602-3-magnusleatti@kernelriot.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 1

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] Hibernation in shutdown mode arms OOB WoL, but the restore
  path has no way to disarm it.
- [Low] motorcomm_shutdown() computes `wake` with no lock held, from
  netif_running(ndev), spriv->wolopts and device_may_wakeup(&pdev->dev).

--

net: stmmac: dwmac-motorcomm: support Wake-on-LAN from S5

This patch arms the YT6801 to wake the system from S5. It does this in
motorcomm_shutdown() when powering off with Wake-on-LAN set, the
interface up and device wakeup enabled. After stmmac_suspend() it
enables OOB WoL, waits 2 ms, rewrites MAC address filter 0 and sets the
packet wake bit in WOL_CTRL, leaving the function in D0 with PME
enabled.

> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-motorcomm.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-motorcomm.c
> index 1e142ad39e33a..034547ad1e98e 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-motorcomm.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-motorcomm.c

[ ... ]

> @@ -204,9 +207,51 @@ static int motorcomm_resume(struct device *dev, void *bsp_priv)
>  	return 0;
>  }
>  
> +/*
> + * Arm the chip to wake the system from S5. stmmac_suspend() has already
> + * programmed the PMT register of the GMAC. The rest lives in the wrapper.
> + */
> +static void motorcomm_arm_s5_wake(struct net_device *ndev)
> +{
> +	struct stmmac_priv *spriv = netdev_priv(ndev);
> +	struct dwmac_motorcomm_priv *priv = spriv->plat->bsp_priv;
> +	u32 reg;
> +
> +	/*
> +	 * motorcomm_init() disables OOB WoL right after the chip reset, as
> +	 * normal operation requires. With it disabled the chip ignores wake
> +	 * packets once the system is off. Once it has been enabled, only a
> +	 * chip reset disables it again, so enable it only when powering off.
> +	 */
> +	reg = readl(priv->base + OOB_WOL_CTRL);
> +	reg &= ~OOB_WOL_CTRL_DIS;
> +	writel(reg, priv->base + OOB_WOL_CTRL);

[Severity: Medium]
What happens when the system resumes from a hibernation that powered off
through this path?

The commit message says "Hibernation that powers off through the
shutdown path arms the chip the same way". For HIBERNATION_SHUTDOWN, and
for the platform-mode fallthrough, power_down() in kernel/power/hibernate.c
calls kernel_power_off():

    case HIBERNATION_SHUTDOWN:
            if (kernel_can_power_off()) {
                    entering_platform_hibernation = true;
                    kernel_power_off();

That reaches device_shutdown() with system_state == SYSTEM_POWER_OFF.
motorcomm_shutdown() then computes wake as true and OOB WoL gets enabled
here.

The commit message relies on "the next probe resets the chip", but a
hibernation restore does not probe. The .restore callback in
stmmac_simple_pm_ops runs stmmac_resume() -> motorcomm_resume():

motorcomm_resume() {
    ...
	motorcomm_deassert_mdio_phy_reset(priv);
	motorcomm_init(priv);
    ...
}

Neither of these calls motorcomm_reset(). Only motorcomm_probe() calls
it. The device was left in D0 at shutdown, so restore is not a
D3hot->D0 transition either. The only attempt to disarm OOB WoL is the
plain write in motorcomm_init():

	/*
	 * OOB WOL must be disabled during normal operation, or DMA interrupts
	 * cannot be delivered to the host.
	 */
	writel(OOB_WOL_CTRL_DIS, priv->base + OOB_WOL_CTRL);

The new comment says this write cannot undo OOB WoL once it has been
enabled. Nothing in the driver clears WOL_CTRL_PKT_EN either.

Suppose the boot kernel did not bind dwmac-motorcomm and reset the chip,
for example because the module is not in the initramfs. Could the
restored kernel then run with OOB WoL still enabled and get no DMA
interrupts?

The new comment also says motorcomm_init() runs "right after the chip
reset", but motorcomm_resume() calls it without a reset.

If "only a chip reset disables it again" is accurate, should the restore
path reset the chip, or should arming be skipped for hibernation? If it
is not accurate, should the comment and the commit message be corrected?

[ ... ]

> @@ -215,14 +260,31 @@ static void motorcomm_shutdown(struct pci_dev *pdev)
>  	if (!netif_device_present(ndev))
>  		return;
>  
> -	/* Stop the device before reboot, kexec or power-off */
> +	wake = system_state == SYSTEM_POWER_OFF && netif_running(ndev) &&
> +	       spriv->wolopts && device_may_wakeup(&pdev->dev);

[Severity: Low]
Can wake become stale before stmmac_suspend() reads the same state and
acts on it?

It is sampled with neither priv->lock nor rtnl held. Two paths can still
run until netif_device_detach() inside stmmac_suspend():

- stmmac_mac_wol_set(), from ethtool set_wol under rtnl
- dev_close() -> stmmac_release()

kernel_shutdown_prepare() does not freeze userspace before
device_shutdown().

In the first case, "ethtool -s ethX wol d" completes after wake was
sampled as true. stmmac_suspend() then calls stmmac_mac_set(false) and
phylink_suspend(false). motorcomm_shutdown() still skips
pci_wake_from_d3(pdev, false) and runs motorcomm_arm_s5_wake(). PME is
probably not enabled, since pci_enable_wake() refuses when
device_may_wakeup() is false. Even so, the chip is armed against the
last WoL setting.

In the second case, dev_close() runs after wake was sampled.
stmmac_suspend() sees the interface down and jumps straight to the bsp
hook:

	if (!ndev || !netif_running(ndev))
		goto suspend_bsp;

There stmmac_pci_plat_suspend() enables PME, because wakeup is still
enabled. Since wake is stale, PME stays on, and OOB WoL is armed on a
closed interface whose PMT was never programmed. Doesn't that conflict
with "If the interface is down at power-off, the system does not wake"?

Would it be more robust to base the arming decision on what
stmmac_suspend() actually did? One option is to check priv->irq_wake
after it returns. It is set only when PMT was armed, and the detach
blocks ethtool by then. Another option is to sample the state under the
same locks.

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116091757.1656602-1-magnusleatti%40kernelriot.com

  parent reply	other threads:[~2026-11-18  9:18 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16  9:17 [PATCH net-next 0/2] net: stmmac: dwmac-motorcomm: shutdown hook and Wake-on-LAN from S5 Magnus Leatti
2026-11-16  9:17 ` [PATCH net-next 1/2] net: stmmac: dwmac-motorcomm: quiesce the device at shutdown Magnus Leatti
2026-11-16 14:33   ` Yao Zi
2026-11-16 14:58     ` Magnus Leatti
2026-11-18  9:18   ` netdev-bot+sashiko
2026-11-16  9:17 ` [PATCH net-next 2/2] net: stmmac: dwmac-motorcomm: support Wake-on-LAN from S5 Magnus Leatti
2026-11-16 15:08   ` Yao Zi
2026-11-16 15:17     ` Yao Zi
2026-11-16 16:48       ` Magnus Leatti
2026-11-16 17:26         ` Yao Zi
2026-11-17  1:27         ` Andrew Lunn
2026-11-17 10:26           ` Yao Zi
2026-11-18  9:18   ` netdev-bot+sashiko [this message]
2026-11-16 11:23 ` [PATCH net-next 0/2] net: stmmac: dwmac-motorcomm: shutdown hook and " Giuseppe Nespolino
2026-11-16 11:36   ` Magnus Leatti

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179499351186.3136.1370230751729152458@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=alexandre.torgue@foss.st.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=g.nespolino@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=magnusleatti@kernelriot.com \
    --cc=maxime.chevallier@bootlin.com \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=me@ziyao.cc \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox