Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: dsa: remove the transactional logic from MDB entries

For many drivers, the .port_mdb_prepare callback was not a good opportunity
to avoid any error condition, and they would suppress errors found during
the actual commit phase.

Where a logical separation between the prepare and the commit phase
existed, the function that used to implement the .port_mdb_prepare
callback still exists, but now it is called directly from .port_mdb_add,
which was modified to return an int code.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Acked-by: Jiri Pirko <jiri@nvidia.com>
Reviewed-by: Kurt Kanzenbach <kurt@linutronix.de> # hellcreek
Reviewed-by: Linus Wallei <linus.walleij@linaro.org> # RTL8366
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Vladimir Oltean and committed by
Jakub Kicinski
a52b2da7 77b61365

+49 -97
+3 -16
drivers/net/dsa/b53/b53_common.c
··· 1741 1741 } 1742 1742 EXPORT_SYMBOL(b53_fdb_dump); 1743 1743 1744 - int b53_mdb_prepare(struct dsa_switch *ds, int port, 1745 - const struct switchdev_obj_port_mdb *mdb) 1744 + int b53_mdb_add(struct dsa_switch *ds, int port, 1745 + const struct switchdev_obj_port_mdb *mdb) 1746 1746 { 1747 1747 struct b53_device *priv = ds->priv; 1748 1748 ··· 1752 1752 if (is5325(priv) || is5365(priv)) 1753 1753 return -EOPNOTSUPP; 1754 1754 1755 - return 0; 1756 - } 1757 - EXPORT_SYMBOL(b53_mdb_prepare); 1758 - 1759 - void b53_mdb_add(struct dsa_switch *ds, int port, 1760 - const struct switchdev_obj_port_mdb *mdb) 1761 - { 1762 - struct b53_device *priv = ds->priv; 1763 - int ret; 1764 - 1765 - ret = b53_arl_op(priv, 0, port, mdb->addr, mdb->vid, true); 1766 - if (ret) 1767 - dev_err(ds->dev, "failed to add MDB entry\n"); 1755 + return b53_arl_op(priv, 0, port, mdb->addr, mdb->vid, true); 1768 1756 } 1769 1757 EXPORT_SYMBOL(b53_mdb_add); 1770 1758 ··· 2193 2205 .port_fdb_del = b53_fdb_del, 2194 2206 .port_mirror_add = b53_mirror_add, 2195 2207 .port_mirror_del = b53_mirror_del, 2196 - .port_mdb_prepare = b53_mdb_prepare, 2197 2208 .port_mdb_add = b53_mdb_add, 2198 2209 .port_mdb_del = b53_mdb_del, 2199 2210 .port_max_mtu = b53_get_max_mtu,
+2 -4
drivers/net/dsa/b53/b53_priv.h
··· 361 361 const unsigned char *addr, u16 vid); 362 362 int b53_fdb_dump(struct dsa_switch *ds, int port, 363 363 dsa_fdb_dump_cb_t *cb, void *data); 364 - int b53_mdb_prepare(struct dsa_switch *ds, int port, 365 - const struct switchdev_obj_port_mdb *mdb); 366 - void b53_mdb_add(struct dsa_switch *ds, int port, 367 - const struct switchdev_obj_port_mdb *mdb); 364 + int b53_mdb_add(struct dsa_switch *ds, int port, 365 + const struct switchdev_obj_port_mdb *mdb); 368 366 int b53_mdb_del(struct dsa_switch *ds, int port, 369 367 const struct switchdev_obj_port_mdb *mdb); 370 368 int b53_mirror_add(struct dsa_switch *ds, int port,
-1
drivers/net/dsa/bcm_sf2.c
··· 1126 1126 .set_rxnfc = bcm_sf2_set_rxnfc, 1127 1127 .port_mirror_add = b53_mirror_add, 1128 1128 .port_mirror_del = b53_mirror_del, 1129 - .port_mdb_prepare = b53_mdb_prepare, 1130 1129 .port_mdb_add = b53_mdb_add, 1131 1130 .port_mdb_del = b53_mdb_del, 1132 1131 };
+8 -4
drivers/net/dsa/lan9303-core.c
··· 1232 1232 return 0; 1233 1233 } 1234 1234 1235 - static void lan9303_port_mdb_add(struct dsa_switch *ds, int port, 1236 - const struct switchdev_obj_port_mdb *mdb) 1235 + static int lan9303_port_mdb_add(struct dsa_switch *ds, int port, 1236 + const struct switchdev_obj_port_mdb *mdb) 1237 1237 { 1238 1238 struct lan9303 *chip = ds->priv; 1239 + int err; 1240 + 1241 + err = lan9303_port_mdb_prepare(ds, port, mdb); 1242 + if (err) 1243 + return err; 1239 1244 1240 1245 dev_dbg(chip->dev, "%s(%d, %pM, %d)\n", __func__, port, mdb->addr, 1241 1246 mdb->vid); 1242 - lan9303_alr_add_port(chip, mdb->addr, port, false); 1247 + return lan9303_alr_add_port(chip, mdb->addr, port, false); 1243 1248 } 1244 1249 1245 1250 static int lan9303_port_mdb_del(struct dsa_switch *ds, int port, ··· 1279 1274 .port_fdb_add = lan9303_port_fdb_add, 1280 1275 .port_fdb_del = lan9303_port_fdb_del, 1281 1276 .port_fdb_dump = lan9303_port_fdb_dump, 1282 - .port_mdb_prepare = lan9303_port_mdb_prepare, 1283 1277 .port_mdb_add = lan9303_port_mdb_add, 1284 1278 .port_mdb_del = lan9303_port_mdb_del, 1285 1279 };
-1
drivers/net/dsa/microchip/ksz8795.c
··· 1114 1114 .port_vlan_add = ksz8795_port_vlan_add, 1115 1115 .port_vlan_del = ksz8795_port_vlan_del, 1116 1116 .port_fdb_dump = ksz_port_fdb_dump, 1117 - .port_mdb_prepare = ksz_port_mdb_prepare, 1118 1117 .port_mdb_add = ksz_port_mdb_add, 1119 1118 .port_mdb_del = ksz_port_mdb_del, 1120 1119 .port_mirror_add = ksz8795_port_mirror_add,
+9 -5
drivers/net/dsa/microchip/ksz9477.c
··· 774 774 return ret; 775 775 } 776 776 777 - static void ksz9477_port_mdb_add(struct dsa_switch *ds, int port, 778 - const struct switchdev_obj_port_mdb *mdb) 777 + static int ksz9477_port_mdb_add(struct dsa_switch *ds, int port, 778 + const struct switchdev_obj_port_mdb *mdb) 779 779 { 780 780 struct ksz_device *dev = ds->priv; 781 781 u32 static_table[4]; 782 782 u32 data; 783 783 int index; 784 784 u32 mac_hi, mac_lo; 785 + int err = 0; 785 786 786 787 mac_hi = ((mdb->addr[0] << 8) | mdb->addr[1]); 787 788 mac_lo = ((mdb->addr[2] << 24) | (mdb->addr[3] << 16)); ··· 797 796 ksz_write32(dev, REG_SW_ALU_STAT_CTRL__4, data); 798 797 799 798 /* wait to be finished */ 800 - if (ksz9477_wait_alu_sta_ready(dev)) { 799 + err = ksz9477_wait_alu_sta_ready(dev); 800 + if (err) { 801 801 dev_dbg(dev->dev, "Failed to read ALU STATIC\n"); 802 802 goto exit; 803 803 } ··· 821 819 } 822 820 823 821 /* no available entry */ 824 - if (index == dev->num_statics) 822 + if (index == dev->num_statics) { 823 + err = -ENOSPC; 825 824 goto exit; 825 + } 826 826 827 827 /* add entry */ 828 828 static_table[0] = ALU_V_STATIC_VALID; ··· 846 842 847 843 exit: 848 844 mutex_unlock(&dev->alu_mutex); 845 + return err; 849 846 } 850 847 851 848 static int ksz9477_port_mdb_del(struct dsa_switch *ds, int port, ··· 1400 1395 .port_fdb_dump = ksz9477_port_fdb_dump, 1401 1396 .port_fdb_add = ksz9477_port_fdb_add, 1402 1397 .port_fdb_del = ksz9477_port_fdb_del, 1403 - .port_mdb_prepare = ksz_port_mdb_prepare, 1404 1398 .port_mdb_add = ksz9477_port_mdb_add, 1405 1399 .port_mdb_del = ksz9477_port_mdb_del, 1406 1400 .port_mirror_add = ksz9477_port_mirror_add,
+5 -11
drivers/net/dsa/microchip/ksz_common.c
··· 253 253 } 254 254 EXPORT_SYMBOL_GPL(ksz_port_fdb_dump); 255 255 256 - int ksz_port_mdb_prepare(struct dsa_switch *ds, int port, 257 - const struct switchdev_obj_port_mdb *mdb) 258 - { 259 - /* nothing to do */ 260 - return 0; 261 - } 262 - EXPORT_SYMBOL_GPL(ksz_port_mdb_prepare); 263 - 264 - void ksz_port_mdb_add(struct dsa_switch *ds, int port, 265 - const struct switchdev_obj_port_mdb *mdb) 256 + int ksz_port_mdb_add(struct dsa_switch *ds, int port, 257 + const struct switchdev_obj_port_mdb *mdb) 266 258 { 267 259 struct ksz_device *dev = ds->priv; 268 260 struct alu_struct alu; ··· 276 284 277 285 /* no available entry */ 278 286 if (index == dev->num_statics && !empty) 279 - return; 287 + return -ENOSPC; 280 288 281 289 /* add entry */ 282 290 if (index == dev->num_statics) { ··· 293 301 alu.fid = mdb->vid; 294 302 } 295 303 dev->dev_ops->w_sta_mac_table(dev, index, &alu); 304 + 305 + return 0; 296 306 } 297 307 EXPORT_SYMBOL_GPL(ksz_port_mdb_add); 298 308
+2 -4
drivers/net/dsa/microchip/ksz_common.h
··· 165 165 const struct switchdev_obj_port_vlan *vlan); 166 166 int ksz_port_fdb_dump(struct dsa_switch *ds, int port, dsa_fdb_dump_cb_t *cb, 167 167 void *data); 168 - int ksz_port_mdb_prepare(struct dsa_switch *ds, int port, 169 - const struct switchdev_obj_port_mdb *mdb); 170 - void ksz_port_mdb_add(struct dsa_switch *ds, int port, 171 - const struct switchdev_obj_port_mdb *mdb); 168 + int ksz_port_mdb_add(struct dsa_switch *ds, int port, 169 + const struct switchdev_obj_port_mdb *mdb); 172 170 int ksz_port_mdb_del(struct dsa_switch *ds, int port, 173 171 const struct switchdev_obj_port_mdb *mdb); 174 172 int ksz_enable_port(struct dsa_switch *ds, int port, struct phy_device *phy);
+7 -17
drivers/net/dsa/mv88e6xxx/chip.c
··· 5238 5238 return chip->info->tag_protocol; 5239 5239 } 5240 5240 5241 - static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port, 5242 - const struct switchdev_obj_port_mdb *mdb) 5243 - { 5244 - /* We don't need any dynamic resource from the kernel (yet), 5245 - * so skip the prepare phase. 5246 - */ 5247 - 5248 - return 0; 5249 - } 5250 - 5251 - static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port, 5252 - const struct switchdev_obj_port_mdb *mdb) 5241 + static int mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port, 5242 + const struct switchdev_obj_port_mdb *mdb) 5253 5243 { 5254 5244 struct mv88e6xxx_chip *chip = ds->priv; 5245 + int err; 5255 5246 5256 5247 mv88e6xxx_reg_lock(chip); 5257 - if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid, 5258 - MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC)) 5259 - dev_err(ds->dev, "p%d: failed to load multicast MAC address\n", 5260 - port); 5248 + err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid, 5249 + MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC); 5261 5250 mv88e6xxx_reg_unlock(chip); 5251 + 5252 + return err; 5262 5253 } 5263 5254 5264 5255 static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port, ··· 5394 5403 .port_fdb_add = mv88e6xxx_port_fdb_add, 5395 5404 .port_fdb_del = mv88e6xxx_port_fdb_del, 5396 5405 .port_fdb_dump = mv88e6xxx_port_fdb_dump, 5397 - .port_mdb_prepare = mv88e6xxx_port_mdb_prepare, 5398 5406 .port_mdb_add = mv88e6xxx_port_mdb_add, 5399 5407 .port_mdb_del = mv88e6xxx_port_mdb_del, 5400 5408 .port_mirror_add = mv88e6xxx_port_mirror_add,
+3 -11
drivers/net/dsa/ocelot/felix.c
··· 65 65 return ocelot_fdb_del(ocelot, port, addr, vid); 66 66 } 67 67 68 - /* This callback needs to be present */ 69 - static int felix_mdb_prepare(struct dsa_switch *ds, int port, 70 - const struct switchdev_obj_port_mdb *mdb) 71 - { 72 - return 0; 73 - } 74 - 75 - static void felix_mdb_add(struct dsa_switch *ds, int port, 76 - const struct switchdev_obj_port_mdb *mdb) 68 + static int felix_mdb_add(struct dsa_switch *ds, int port, 69 + const struct switchdev_obj_port_mdb *mdb) 77 70 { 78 71 struct ocelot *ocelot = ds->priv; 79 72 80 - ocelot_port_mdb_add(ocelot, port, mdb); 73 + return ocelot_port_mdb_add(ocelot, port, mdb); 81 74 } 82 75 83 76 static int felix_mdb_del(struct dsa_switch *ds, int port, ··· 765 772 .port_fdb_dump = felix_fdb_dump, 766 773 .port_fdb_add = felix_fdb_add, 767 774 .port_fdb_del = felix_fdb_del, 768 - .port_mdb_prepare = felix_mdb_prepare, 769 775 .port_mdb_add = felix_mdb_add, 770 776 .port_mdb_del = felix_mdb_del, 771 777 .port_bridge_join = felix_bridge_join,
+3 -11
drivers/net/dsa/sja1105/sja1105_main.c
··· 1524 1524 return 0; 1525 1525 } 1526 1526 1527 - /* This callback needs to be present */ 1528 - static int sja1105_mdb_prepare(struct dsa_switch *ds, int port, 1529 - const struct switchdev_obj_port_mdb *mdb) 1527 + static int sja1105_mdb_add(struct dsa_switch *ds, int port, 1528 + const struct switchdev_obj_port_mdb *mdb) 1530 1529 { 1531 - return 0; 1532 - } 1533 - 1534 - static void sja1105_mdb_add(struct dsa_switch *ds, int port, 1535 - const struct switchdev_obj_port_mdb *mdb) 1536 - { 1537 - sja1105_fdb_add(ds, port, mdb->addr, mdb->vid); 1530 + return sja1105_fdb_add(ds, port, mdb->addr, mdb->vid); 1538 1531 } 1539 1532 1540 1533 static int sja1105_mdb_del(struct dsa_switch *ds, int port, ··· 3281 3288 .port_vlan_filtering = sja1105_vlan_filtering, 3282 3289 .port_vlan_add = sja1105_vlan_add, 3283 3290 .port_vlan_del = sja1105_vlan_del, 3284 - .port_mdb_prepare = sja1105_mdb_prepare, 3285 3291 .port_mdb_add = sja1105_mdb_add, 3286 3292 .port_mdb_del = sja1105_mdb_del, 3287 3293 .port_hwtstamp_get = sja1105_hwtstamp_get,
+1 -3
include/net/dsa.h
··· 585 585 /* 586 586 * Multicast database 587 587 */ 588 - int (*port_mdb_prepare)(struct dsa_switch *ds, int port, 588 + int (*port_mdb_add)(struct dsa_switch *ds, int port, 589 589 const struct switchdev_obj_port_mdb *mdb); 590 - void (*port_mdb_add)(struct dsa_switch *ds, int port, 591 - const struct switchdev_obj_port_mdb *mdb); 592 590 int (*port_mdb_del)(struct dsa_switch *ds, int port, 593 591 const struct switchdev_obj_port_mdb *mdb); 594 592 /*
+6 -9
net/dsa/switch.c
··· 181 181 static int dsa_switch_mdb_add(struct dsa_switch *ds, 182 182 struct dsa_notifier_mdb_info *info) 183 183 { 184 - int port, err; 184 + int err = 0; 185 + int port; 185 186 186 - if (!ds->ops->port_mdb_prepare || !ds->ops->port_mdb_add) 187 + if (!ds->ops->port_mdb_add) 187 188 return -EOPNOTSUPP; 188 189 189 190 for (port = 0; port < ds->num_ports; port++) { 190 191 if (dsa_switch_mdb_match(ds, port, info)) { 191 - err = ds->ops->port_mdb_prepare(ds, port, info->mdb); 192 + err = ds->ops->port_mdb_add(ds, port, info->mdb); 192 193 if (err) 193 - return err; 194 + break; 194 195 } 195 196 } 196 197 197 - for (port = 0; port < ds->num_ports; port++) 198 - if (dsa_switch_mdb_match(ds, port, info)) 199 - ds->ops->port_mdb_add(ds, port, info->mdb); 200 - 201 - return 0; 198 + return err; 202 199 } 203 200 204 201 static int dsa_switch_mdb_del(struct dsa_switch *ds,