]> git.itanic.dy.fi Git - linux-stable/commitdiff
net: dsa: notify drivers of MAC address changes on user ports
authorVladimir Oltean <vladimir.oltean@nxp.com>
Fri, 22 Sep 2023 13:31:05 +0000 (15:31 +0200)
committerPaolo Abeni <pabeni@redhat.com>
Tue, 3 Oct 2023 11:51:02 +0000 (13:51 +0200)
In some cases, drivers may need to veto the changing of a MAC address on
a user port. Such is the case with KSZ9477 when it offloads a HSR device,
because it programs the MAC address of multiple ports to a shared
hardware register. Those ports need to have equal MAC addresses for the
lifetime of the HSR offload.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: Lukasz Majewski <lukma@denx.de>
Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
Reviewed-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
include/net/dsa.h
net/dsa/slave.c

index 426724808e7677ea063dc54f26b625e973a521d6..d98439ea6146f1c7ee083862dec200cc9427406f 100644 (file)
@@ -969,6 +969,16 @@ struct dsa_switch_ops {
                               struct phy_device *phy);
        void    (*port_disable)(struct dsa_switch *ds, int port);
 
+
+       /*
+        * Notification for MAC address changes on user ports. Drivers can
+        * currently only veto operations. They should not use the method to
+        * program the hardware, since the operation is not rolled back in case
+        * of other errors.
+        */
+       int     (*port_set_mac_address)(struct dsa_switch *ds, int port,
+                                       const unsigned char *addr);
+
        /*
         * Compatibility between device trees defining multiple CPU ports and
         * drivers which are not OK to use by default the numerically smallest
index 2b3d89b771218c86768e7ecd1a5dda70b146bbad..4c3e502d7e16653423f3e1cfc4d188bfb6c14a11 100644 (file)
@@ -457,6 +457,13 @@ static int dsa_slave_set_mac_address(struct net_device *dev, void *a)
        if (!is_valid_ether_addr(addr->sa_data))
                return -EADDRNOTAVAIL;
 
+       if (ds->ops->port_set_mac_address) {
+               err = ds->ops->port_set_mac_address(ds, dp->index,
+                                                   addr->sa_data);
+               if (err)
+                       return err;
+       }
+
        /* If the port is down, the address isn't synced yet to hardware or
         * to the DSA master, so there is nothing to change.
         */