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

Configure Feed

Select the types of activity you want to include in your feed.

net: dsa: mt7530: factor out bridge join/leave logic

As preparation for implementing bridge port isolation, move the logic to
add and remove bits in the port matrix into a new helper
mt7530_update_port_member(), which is called from
mt7530_port_bridge_join() and mt7530_port_bridge_leave().

Another part of the preparation is using dsa_port_offloads_bridge_dev()
instead of dsa_port_offloads_bridge() to check for bridge membership, as
we don't have a struct dsa_bridge in mt7530_port_bridge_flags().

The port matrix setting is slightly streamlined, now always first setting
the mt7530_port's pm field and then writing the port matrix from that
field into the hardware register, instead of duplicating the bit
manipulation for both the struct field and the register.

mt7530_port_bridge_join() was previously using |= to update the port
matrix with the port bitmap, which was unnecessary, as pm would only
have the CPU port set before joining a bridge; a simple assignment can
be used for both joining and leaving (and will also work when individual
bits are added/removed in port_bitmap with regard to the previous port
matrix, which is what happens with port isolation).

No functional change intended.

Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
Reviewed-by: Wojciech Drewek <wojciech.drewek@intel.com>
Reviewed-by: Arınç ÜNAL <arinc.unal@arinc9.com>
Tested-by: Arınç ÜNAL <arinc.unal@arinc9.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Matthias Schiffer and committed by
David S. Miller
c25c961f 65e4efa0

+48 -57
+48 -57
drivers/net/dsa/mt7530.c
··· 1302 1302 FID_PST(FID_BRIDGED, stp_state)); 1303 1303 } 1304 1304 1305 + static void mt7530_update_port_member(struct mt7530_priv *priv, int port, 1306 + const struct net_device *bridge_dev, 1307 + bool join) __must_hold(&priv->reg_mutex) 1308 + { 1309 + struct dsa_port *dp = dsa_to_port(priv->ds, port), *other_dp; 1310 + struct mt7530_port *p = &priv->ports[port], *other_p; 1311 + struct dsa_port *cpu_dp = dp->cpu_dp; 1312 + u32 port_bitmap = BIT(cpu_dp->index); 1313 + int other_port; 1314 + 1315 + dsa_switch_for_each_user_port(other_dp, priv->ds) { 1316 + other_port = other_dp->index; 1317 + other_p = &priv->ports[other_port]; 1318 + 1319 + if (dp == other_dp) 1320 + continue; 1321 + 1322 + /* Add/remove this port to/from the port matrix of the other 1323 + * ports in the same bridge. If the port is disabled, port 1324 + * matrix is kept and not being setup until the port becomes 1325 + * enabled. 1326 + */ 1327 + if (!dsa_port_offloads_bridge_dev(other_dp, bridge_dev)) 1328 + continue; 1329 + 1330 + if (join) { 1331 + other_p->pm |= PCR_MATRIX(BIT(port)); 1332 + port_bitmap |= BIT(other_port); 1333 + } else { 1334 + other_p->pm &= ~PCR_MATRIX(BIT(port)); 1335 + } 1336 + 1337 + if (other_p->enable) 1338 + mt7530_rmw(priv, MT7530_PCR_P(other_port), 1339 + PCR_MATRIX_MASK, other_p->pm); 1340 + } 1341 + 1342 + /* Add/remove the all other ports to this port matrix. For !join 1343 + * (leaving the bridge), only the CPU port will remain in the port matrix 1344 + * of this port. 1345 + */ 1346 + p->pm = PCR_MATRIX(port_bitmap); 1347 + if (priv->ports[port].enable) 1348 + mt7530_rmw(priv, MT7530_PCR_P(port), PCR_MATRIX_MASK, p->pm); 1349 + } 1350 + 1305 1351 static int 1306 1352 mt7530_port_pre_bridge_flags(struct dsa_switch *ds, int port, 1307 1353 struct switchdev_brport_flags flags, ··· 1391 1345 struct dsa_bridge bridge, bool *tx_fwd_offload, 1392 1346 struct netlink_ext_ack *extack) 1393 1347 { 1394 - struct dsa_port *dp = dsa_to_port(ds, port), *other_dp; 1395 - struct dsa_port *cpu_dp = dp->cpu_dp; 1396 - u32 port_bitmap = BIT(cpu_dp->index); 1397 1348 struct mt7530_priv *priv = ds->priv; 1398 1349 1399 1350 mutex_lock(&priv->reg_mutex); 1400 1351 1401 - dsa_switch_for_each_user_port(other_dp, ds) { 1402 - int other_port = other_dp->index; 1403 - 1404 - if (dp == other_dp) 1405 - continue; 1406 - 1407 - /* Add this port to the port matrix of the other ports in the 1408 - * same bridge. If the port is disabled, port matrix is kept 1409 - * and not being setup until the port becomes enabled. 1410 - */ 1411 - if (!dsa_port_offloads_bridge(other_dp, &bridge)) 1412 - continue; 1413 - 1414 - if (priv->ports[other_port].enable) 1415 - mt7530_set(priv, MT7530_PCR_P(other_port), 1416 - PCR_MATRIX(BIT(port))); 1417 - priv->ports[other_port].pm |= PCR_MATRIX(BIT(port)); 1418 - 1419 - port_bitmap |= BIT(other_port); 1420 - } 1421 - 1422 - /* Add the all other ports to this port matrix. */ 1423 - if (priv->ports[port].enable) 1424 - mt7530_rmw(priv, MT7530_PCR_P(port), 1425 - PCR_MATRIX_MASK, PCR_MATRIX(port_bitmap)); 1426 - priv->ports[port].pm |= PCR_MATRIX(port_bitmap); 1352 + mt7530_update_port_member(priv, port, bridge.dev, true); 1427 1353 1428 1354 /* Set to fallback mode for independent VLAN learning */ 1429 1355 mt7530_rmw(priv, MT7530_PCR_P(port), PCR_PORT_VLAN_MASK, ··· 1496 1478 mt7530_port_bridge_leave(struct dsa_switch *ds, int port, 1497 1479 struct dsa_bridge bridge) 1498 1480 { 1499 - struct dsa_port *dp = dsa_to_port(ds, port), *other_dp; 1500 - struct dsa_port *cpu_dp = dp->cpu_dp; 1501 1481 struct mt7530_priv *priv = ds->priv; 1502 1482 1503 1483 mutex_lock(&priv->reg_mutex); 1504 1484 1505 - dsa_switch_for_each_user_port(other_dp, ds) { 1506 - int other_port = other_dp->index; 1507 - 1508 - if (dp == other_dp) 1509 - continue; 1510 - 1511 - /* Remove this port from the port matrix of the other ports 1512 - * in the same bridge. If the port is disabled, port matrix 1513 - * is kept and not being setup until the port becomes enabled. 1514 - */ 1515 - if (!dsa_port_offloads_bridge(other_dp, &bridge)) 1516 - continue; 1517 - 1518 - if (priv->ports[other_port].enable) 1519 - mt7530_clear(priv, MT7530_PCR_P(other_port), 1520 - PCR_MATRIX(BIT(port))); 1521 - priv->ports[other_port].pm &= ~PCR_MATRIX(BIT(port)); 1522 - } 1523 - 1524 - /* Set the cpu port to be the only one in the port matrix of 1525 - * this port. 1526 - */ 1527 - if (priv->ports[port].enable) 1528 - mt7530_rmw(priv, MT7530_PCR_P(port), PCR_MATRIX_MASK, 1529 - PCR_MATRIX(BIT(cpu_dp->index))); 1530 - priv->ports[port].pm = PCR_MATRIX(BIT(cpu_dp->index)); 1485 + mt7530_update_port_member(priv, port, bridge.dev, false); 1531 1486 1532 1487 /* When a port is removed from the bridge, the port would be set up 1533 1488 * back to the default as is at initial boot which is a VLAN-unaware