Re: [PATCH net-next v3 2/2] net: stmmac: dwmac-motorcomm: support Wake-on-LAN from S5

From: netdev-bot+sashiko

Date: Tue Dec 01 2026 - 05:18:35 EST


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

Critical: 0 · High: 0 · Medium: 3 · 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] In drivers/net/ethernet/stmicro/stmmac/dwmac-motorcomm.c,
motorcomm_shutdown() arms S5 wake on a board whose eFuse holds no MAC…
- [Medium] motorcomm_shutdown() takes a snapshot of netif_running(ndev),
spriv->wolopts and device_may_wakeup() under rtnl_lock() and stores it…
- [Medium] motorcomm_shutdown() starts the chip's self-arm sequence by
toggling SYS_RESET.
- [Low] motorcomm_shutdown() releases SYS_RESET and, with no settle delay
and no read-back, runs a read-modify-write on WOL_CTRL to set…

--

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

This adds a separate .shutdown callback to the YT6801 glue driver. On
power-off with magic packet WoL enabled, it removes the stmmac device and
resets the chip so that it re-arms OOB WoL by itself using the eFuse MAC.
It then sets WOL_CTRL_PKT_EN again, enables PME and puts the function in
D3hot.

> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-motorcomm.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-motorcomm.c
> index 63ce2301a0f69..41e440ed141e3 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-motorcomm.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-motorcomm.c

[ ... ]

> @@ -363,6 +367,36 @@ static void motorcomm_remove(struct pci_dev *pdev)
> stmmac_dvr_remove(&pdev->dev);
> }
>
> +static void motorcomm_shutdown(struct pci_dev *pdev)
> +{
> + struct net_device *ndev = dev_get_drvdata(&pdev->dev);
> + struct stmmac_priv *spriv = netdev_priv(ndev);
> + struct dwmac_motorcomm_priv *priv = spriv->plat->bsp_priv;
> + bool wake;
> + u32 reg;
> +
> + /* Userspace is still running and may close the interface */
> + rtnl_lock();
> + wake = system_state == SYSTEM_POWER_OFF && netif_running(ndev) &&
> + (spriv->wolopts & WAKE_MAGIC) && device_may_wakeup(&pdev->dev);
> + rtnl_unlock();
> +
> + stmmac_dvr_remove(&pdev->dev);

[Severity: Medium]
Can the value of wake go stale between rtnl_unlock() and the netdev
teardown?

Userspace is still running during device_shutdown(). A request that was
blocked on rtnl can take it right after this rtnl_unlock() and complete
successfully. Examples are "ethtool -s <dev> wol d" or
"ip link set <dev> down":

phylink_ethtool_set_wol()
stmmac_mac_wol_set()
device_set_wakeup_enable(priv->device, !!wolopts);
...
priv->wolopts = wolopts;

After that, stmmac_dvr_remove()->unregister_netdev() runs. The old value
of wake is still used to reset the chip, set WOL_CTRL_PKT_EN, enable PME
and enter D3hot.

Could the machine then wake from S5 on a magic packet after WoL was
disabled or the interface was brought down? That would go against the
commit message note that "reboot, kexec and interface down stop at the
remove". The reverse case, enabling WoL in that window, would leave the
device unarmed.

Would it help to call netif_device_detach(ndev) in the same rtnl section
as the snapshot? Another option is to keep the wake decision and the
netdev teardown in one exclusion region.

> +
> + if (!wake)
> + return;
> +
> + /* Reset re-enables OOB WoL; left alone, chip arms itself (eFuse MAC) */
> + motorcomm_reset(priv);

[Severity: Medium]
What happens here on boards whose eFuse holds no MAC address?

motorcomm_probe() already handles that case by falling back to a random
address:

ret = motorcomm_efuse_read_mac(&pdev->dev, priv, res.mac);
if (ret == -ENOENT) {
dev_warn(&pdev->dev, "eFuse contains no valid MAC address\n");
dev_warn(&pdev->dev, "fallback to random MAC address\n");

eth_random_addr(res.mac);

The commit message says the chip arms itself with "the eFuse address
loaded into the first MAC filter". It also says "It wakes on the eFuse
address, not the software one".

On such a board the random MAC is the only address the network knows.
The wake decision above only checks system_state, netif_running(),
WAKE_MAGIC and device_may_wakeup(). Nothing records whether probe found
an eFuse MAC.

With "wol g" set, would this path silently arm the chip with an address
that a magic packet sent to the interface can never match? Should arming
be skipped, or at least warned about, when probe fell back to a random
MAC? Alternatively, should the commit message state this limitation?

> +
> + reg = readl(priv->base + WOL_CTRL);
> + reg |= WOL_CTRL_PKT_EN;
> + writel(reg, priv->base + WOL_CTRL);

[Severity: Low]
Is it safe to do this read-modify-write right after the reset is
released?

motorcomm_probe() follows the same motorcomm_reset() with a settle delay,
because the eFuse controller is still loading internal data:

motorcomm_reset(priv);

/*
* After system reset, the eFuse controller needs time to load
* its internal data. Without this delay, eFuse reads return
* all zeros, causing MAC address detection to fail.
*/
usleep_range(2000, 5000);

The commit message also describes the chip running its own arming
sequence for about 2-3 s after the reset.

If the eFuse autoload or the self-arm sequence writes WOL_CTRL after this
RMW, PKT_EN would be lost. Nothing reads the register back, so the driver
would still enter D3hot as if wake were armed.

On the other hand, the EPHY_CTRL RMW in motorcomm_reset() takes effect
immediately after the reset, and the patch was tested successfully. So
this depends on undocumented hardware behaviour.

Would a short delay or a read-back check here be worth adding?

> +
> + pci_wake_from_d3(pdev, true);
> + pci_set_power_state(pdev, PCI_D3hot);
> +}

[Severity: Medium]
Does the self-arm sequence started by motorcomm_reset() have time to
finish before power is removed?

The commit message says it takes "about 2-3 s" for the chip to bring the
PHY up, start the receiver, load the eFuse MAC into the first MAC filter
and get PMT ready. That was timed from userspace with no driver bound,
not across an S5 transition.

Here the function moves the device to D3hot and returns at once. Nothing
in the rest of kernel_power_off() waits for that window:

kernel/reboot.c:kernel_power_off() {
kernel_shutdown_prepare(SYSTEM_POWER_OFF);
do_kernel_power_off_prepare();
migrate_to_reboot_cpu();
syscore_shutdown();
pr_emerg("Power down\n");
pr_flush(1000, true);
kmsg_dump(KMSG_DUMP_SHUTDOWN);
machine_power_off();
}

The commit message also notes that after a power loss the chip doesn't
arm itself again until the next clean shutdown.

Suppose PERST# assertion or main-power removal interrupts the sequence.
Could the device be left with OOB WoL and PME enabled but no programmed
MAC filter or PMT, so that "wol g" fails silently?

Is there a completion indication that could be polled here? Or does the
hardware guarantee that the sequence survives the power transition?

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