net: dsa: microchip: ksz8: Separate static MAC table operations for code reuse
authorOleksij Rempel <o.rempel@pengutronix.de>
Tue, 4 Apr 2023 10:18:36 +0000 (12:18 +0200)
committerPaolo Abeni <pabeni@redhat.com>
Thu, 6 Apr 2023 09:34:45 +0000 (11:34 +0200)
Move static MAC table operations to separate functions in order to reuse
the code for add/del_fdb. This is needed to address kernel warnings
caused by the lack of fdb add function support in the current driver.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
Reviewed-by: Vladimir Oltean <olteanv@gmail.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
drivers/net/dsa/microchip/ksz8795.c

index 3fffd5da8d3b0b9da74756824952d1c2a4616879..e47d08cf3f26d7f7ee2eac92c732ff6de34ba7f5 100644 (file)
@@ -977,8 +977,8 @@ int ksz8_fdb_dump(struct ksz_device *dev, int port,
        return ret;
 }
 
-int ksz8_mdb_add(struct ksz_device *dev, int port,
-                const struct switchdev_obj_port_mdb *mdb, struct dsa_db db)
+static int ksz8_add_sta_mac(struct ksz_device *dev, int port,
+                           const unsigned char *addr, u16 vid)
 {
        struct alu_struct alu;
        int index;
@@ -988,8 +988,8 @@ int ksz8_mdb_add(struct ksz_device *dev, int port,
        for (index = 0; index < dev->info->num_statics; index++) {
                if (!ksz8_r_sta_mac_table(dev, index, &alu)) {
                        /* Found one already in static MAC table. */
-                       if (!memcmp(alu.mac, mdb->addr, ETH_ALEN) &&
-                           alu.fid == mdb->vid)
+                       if (!memcmp(alu.mac, addr, ETH_ALEN) &&
+                           alu.fid == vid)
                                break;
                /* Remember the first empty entry. */
                } else if (!empty) {
@@ -1005,23 +1005,23 @@ int ksz8_mdb_add(struct ksz_device *dev, int port,
        if (index == dev->info->num_statics) {
                index = empty - 1;
                memset(&alu, 0, sizeof(alu));
-               memcpy(alu.mac, mdb->addr, ETH_ALEN);
+               memcpy(alu.mac, addr, ETH_ALEN);
                alu.is_static = true;
        }
        alu.port_forward |= BIT(port);
-       if (mdb->vid) {
+       if (vid) {
                alu.is_use_fid = true;
 
                /* Need a way to map VID to FID. */
-               alu.fid = mdb->vid;
+               alu.fid = vid;
        }
        ksz8_w_sta_mac_table(dev, index, &alu);
 
        return 0;
 }
 
-int ksz8_mdb_del(struct ksz_device *dev, int port,
-                const struct switchdev_obj_port_mdb *mdb, struct dsa_db db)
+static int ksz8_del_sta_mac(struct ksz_device *dev, int port,
+                           const unsigned char *addr, u16 vid)
 {
        struct alu_struct alu;
        int index;
@@ -1029,8 +1029,8 @@ int ksz8_mdb_del(struct ksz_device *dev, int port,
        for (index = 0; index < dev->info->num_statics; index++) {
                if (!ksz8_r_sta_mac_table(dev, index, &alu)) {
                        /* Found one already in static MAC table. */
-                       if (!memcmp(alu.mac, mdb->addr, ETH_ALEN) &&
-                           alu.fid == mdb->vid)
+                       if (!memcmp(alu.mac, addr, ETH_ALEN) &&
+                           alu.fid == vid)
                                break;
                }
        }
@@ -1049,6 +1049,18 @@ exit:
        return 0;
 }
 
+int ksz8_mdb_add(struct ksz_device *dev, int port,
+                const struct switchdev_obj_port_mdb *mdb, struct dsa_db db)
+{
+       return ksz8_add_sta_mac(dev, port, mdb->addr, mdb->vid);
+}
+
+int ksz8_mdb_del(struct ksz_device *dev, int port,
+                const struct switchdev_obj_port_mdb *mdb, struct dsa_db db)
+{
+       return ksz8_del_sta_mac(dev, port, mdb->addr, mdb->vid);
+}
+
 int ksz8_port_vlan_filtering(struct ksz_device *dev, int port, bool flag,
                             struct netlink_ext_ack *extack)
 {