All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yao Zi <me@ziyao.cc>
To: Magnus Leatti <magnusleatti@kernelriot.com>, 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: Re: [PATCH net-next v2 2/2] net: stmmac: dwmac-motorcomm: support Wake-on-LAN from S5
Date: Wed, 25 Nov 2026 16:28:28 +0000	[thread overview]
Message-ID: <awcMrBlm2RGC7gJ2@pie> (raw)
In-Reply-To: <20261120102754.778283-3-magnusleatti@kernelriot.com>

On Fri, Nov 20, 2026 at 07:27:54AM -0300, Magnus Leatti wrote:
> "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.

The last paragraph should probably not be carried in the commit message,
please remove it.

> 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. */

This is obvious, please remove this comment.

> +	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. */

This is also obvious from code, please remove.

> +	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
> 

With these minors fixed,

Reviewed-by: Yao Zi <me@ziyao.cc>

-- 
Thanks,
Yao Zi

Meow-mrrp-mrow, I'm a cat.

  parent reply	other threads:[~2026-11-25 16:29 UTC|newest]

Thread overview: 14+ 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 Wake-on-LAN from S5 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-24 10:57   ` netdev-bot+sashiko
2026-11-24 13:06     ` Magnus Leatti
2026-11-25 16:37       ` Yao Zi
2026-11-24 17:01   ` Maxime Chevallier
2026-11-20 10:27 ` [PATCH net-next v2 2/2] net: stmmac: dwmac-motorcomm: support Wake-on-LAN from S5 Magnus Leatti
2026-11-24 10:57   ` netdev-bot+sashiko
2026-11-24 13:18     ` Magnus Leatti
2026-11-24 17:04   ` Maxime Chevallier
2026-11-25 16:28   ` Yao Zi [this message]
2026-11-25 17:24 ` [PATCH net-next v2 0/2] net: stmmac: dwmac-motorcomm: shutdown hook and " Giuseppe Nespolino
2026-11-25 17:31 ` Magnus Leatti
2026-11-26  0:12   ` Giuseppe Nespolino

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=awcMrBlm2RGC7gJ2@pie \
    --to=me@ziyao.cc \
    --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=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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.