From: Magnus Leatti <magnusleatti@kernelriot.com>
To: Yao Zi <me@ziyao.cc>,
Maxime Chevallier <maxime.chevallier@bootlin.com>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>,
Alexandre Torgue <alexandre.torgue@foss.st.com>,
Giuseppe Nespolino <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: [PATCH net-next v2 2/2] net: stmmac: dwmac-motorcomm: support Wake-on-LAN from S5
Date: Fri, 20 Nov 2026 07:27:54 -0300 [thread overview]
Message-ID: <20261120102754.778283-3-magnusleatti@kernelriot.com> (raw)
In-Reply-To: <20261120102754.778283-1-magnusleatti@kernelriot.com>
"wol g" is accepted, but the chip sleeps right through magic packets
in S5: motorcomm_init() turns OOB WoL off and nothing turns it back on
at power-off.
Turns out the chip can just arm itself. Hit it with a reset, OOB WoL
comes right back on, and about 2-3 s later it has the PHY up, receiver
running, the eFuse address loaded into the first MAC filter, and PMT
ready for magic packets. Timed that from userspace without a driver
bound.
So on a power-off with "wol g": remove, reset, set WOL_CTRL_PKT_EN
again because the reset clears it, enable PME, D3hot.
Notes:
- It wakes on the eFuse address, not the software one. Same as r8169.
- Magic packets only. "wol u", reboot, kexec and interface down stop
at the remove.
- Hibernation that powers off through .shutdown arms too, and resume
copes without a reset. Tried twice: woke on the packet, link back.
- After a power loss (cable out and back in, BIOS set to stay off) it
won't wake until the next clean shutdown. The vendor driver does
the same, so that's the hardware.
With this the box wakes on a magic packet to the eFuse address, 5 of
5. Without it, 0 of 3.
Suggested-by: Yao Zi <me@ziyao.cc>
Signed-off-by: Magnus Leatti <magnusleatti@kernelriot.com>
---
.../ethernet/stmicro/stmmac/dwmac-motorcomm.c | 38 ++++++++++++++++++-
1 file changed, 37 insertions(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-motorcomm.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-motorcomm.c
index 63ce2301a0f6..34abbdb645ec 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-motorcomm.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-motorcomm.c
@@ -12,6 +12,7 @@
#include <linux/iopoll.h>
#include <linux/module.h>
#include <linux/pci.h>
+#include <linux/rtnetlink.h>
#include <linux/slab.h>
#include <linux/stmmac.h>
@@ -27,6 +28,9 @@
#define EPHY_CTRL 0x1004
/* Clearing this bit asserts resets for internal MDIO bus and PHY */
#define EPHY_MDIO_PHY_RESET BIT(0)
+#define WOL_CTRL 0x100c
+/* Magic and remote wake-up packet enable */
+#define WOL_CTRL_PKT_EN BIT(1)
#define OOB_WOL_CTRL 0x1010
#define OOB_WOL_CTRL_DIS BIT(0)
#define MGMT_INT_CTRL0 0x1100
@@ -363,6 +367,38 @@ 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();
+
+ /* The netdev is unregistered after this. priv and its mapping stay. */
+ stmmac_dvr_remove(&pdev->dev);
+
+ if (!wake)
+ return;
+
+ /* Reset re-enables OOB WoL; left alone, chip arms itself (eFuse MAC) */
+ motorcomm_reset(priv);
+
+ /* The reset has cleared it. Without it the chip does not wake. */
+ reg = readl(priv->base + WOL_CTRL);
+ reg |= WOL_CTRL_PKT_EN;
+ writel(reg, priv->base + WOL_CTRL);
+
+ pci_wake_from_d3(pdev, true);
+ pci_set_power_state(pdev, PCI_D3hot);
+}
+
static const struct pci_device_id dwmac_motorcomm_pci_id_table[] = {
{ PCI_DEVICE(PCI_VENDOR_ID_MOTORCOMM, 0x6801) },
{ },
@@ -374,7 +410,7 @@ static struct pci_driver dwmac_motorcomm_pci_driver = {
.id_table = dwmac_motorcomm_pci_id_table,
.probe = motorcomm_probe,
.remove = motorcomm_remove,
- .shutdown = motorcomm_remove,
+ .shutdown = motorcomm_shutdown,
.driver = {
.pm = &stmmac_simple_pm_ops,
},
--
2.56.1
prev parent reply other threads:[~2026-11-20 10:28 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 10:27 [PATCH net-next v2 0/2] net: stmmac: dwmac-motorcomm: shutdown hook and " Magnus Leatti
2026-11-20 10:27 ` [PATCH net-next v2 1/2] net: stmmac: dwmac-motorcomm: remove the device at shutdown Magnus Leatti
2026-11-20 10:27 ` Magnus Leatti [this message]
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=20261120102754.778283-3-magnusleatti@kernelriot.com \
--to=magnusleatti@kernelriot.com \
--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=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
all inboxes | Powered by JetHome®