Re: [PATCH net-next v4 5/9] net: dsa: microchip: ksz9477: Add Wake on Magic Packet support

From: Andrew Lunn
Date: Mon Oct 16 2023 - 21:36:23 EST


> @@ -155,6 +158,14 @@ int ksz9477_set_wol(struct ksz_device *dev, int port,
> if (ret)
> return ret;
>
> + if (wol->wolopts & WAKE_MAGIC) {
> + ret = ksz_switch_macaddr_get(dev->ds, port, NULL);
> + if (ret)
> + return ret;
> +
> + pme_ctrl |= PME_WOL_MAGICPKT;
> + }

There is no matching ksz_switch_macaddr_put() here when the user turns
WAKE_MAGIC off. Ideally you need to keep track of the WoL state per
port, and when the user disables it, release the MAC address.

> +
> if (wol->wolopts & WAKE_PHY)
> pme_ctrl |= PME_WOL_LINKUP | PME_WOL_ENERGY;
>
> diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
> index 3f7c86e545a7..4601aaca5179 100644
> --- a/drivers/net/dsa/microchip/ksz_common.c
> +++ b/drivers/net/dsa/microchip/ksz_common.c
> @@ -3569,6 +3569,7 @@ static int ksz_port_set_mac_address(struct dsa_switch *ds, int port,
> const unsigned char *addr)
> {
> struct dsa_port *dp = dsa_to_port(ds, port);
> + struct ethtool_wolinfo wol;
>
> if (dp->hsr_dev) {
> dev_err(ds->dev,
> @@ -3577,6 +3578,14 @@ static int ksz_port_set_mac_address(struct dsa_switch *ds, int port,
> return -EBUSY;
> }
>
> + ksz_get_wol(ds, dp->index, &wol);
> + if (wol.wolopts & WAKE_MAGIC) {
> + dev_err(ds->dev,
> + "Cannot change MAC address on port %d with active Wake on Magic Packet\n",
> + port);

This is not really an error, as in something went wrong. Its just a
hardware restriction. So dev_warn() would be better, or nothing at all
in the logs.

Andrew