Skip to content

Commit ce5df68

Browse files
vladimirolteandavem330
authored andcommitted
net: dsa: mv88e6xxx: map virtual bridges with forwarding offload in the PVT
The mv88e6xxx switches have the ability to receive FORWARD (data plane) frames from the CPU port and route them according to the FDB. We can use this to offload the forwarding process of packets sent by the software bridge. Because DSA supports bridge domain isolation between user ports, just sending FORWARD frames is not enough, as they might leak the intended broadcast domain of the bridge on behalf of which the packets are sent. It should be noted that FORWARD frames are also (and typically) used to forward data plane packets on DSA links in cross-chip topologies. The FORWARD frame header contains the source port and switch ID, and switches receiving this frame header forward the packet according to their cross-chip port-based VLAN table (PVT). To address the bridging domain isolation in the context of offloading the forwarding on TX, the idea is that we can reuse the parts of the PVT that don't have any physical switch mapped to them, one entry for each software bridge. The switches will therefore think that behind their upstream port lie many switches, all in fact backed up by software bridges through tag_dsa.c, which constructs FORWARD packets with the right switch ID corresponding to each bridge. The mapping we use is absolutely trivial: DSA gives us a unique bridge number, and we add the number of the physical switches in the DSA switch tree to that, to obtain a unique virtual bridge device number to use in the PVT. Co-developed-by: Tobias Waldekranz <[email protected]> Signed-off-by: Tobias Waldekranz <[email protected]> Signed-off-by: Vladimir Oltean <[email protected]> Reviewed-by: Florian Fainelli <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 123abc0 commit ce5df68

File tree

1 file changed

+74
-4
lines changed
  • drivers/net/dsa/mv88e6xxx

1 file changed

+74
-4
lines changed

drivers/net/dsa/mv88e6xxx/chip.c

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,22 +1221,43 @@ static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
12211221
bool found = false;
12221222
u16 pvlan;
12231223

1224-
list_for_each_entry(dp, &dst->ports, list) {
1225-
if (dp->ds->index == dev && dp->index == port) {
1224+
/* dev is a physical switch */
1225+
if (dev <= dst->last_switch) {
1226+
list_for_each_entry(dp, &dst->ports, list) {
1227+
if (dp->ds->index == dev && dp->index == port) {
1228+
/* dp might be a DSA link or a user port, so it
1229+
* might or might not have a bridge_dev
1230+
* pointer. Use the "found" variable for both
1231+
* cases.
1232+
*/
1233+
br = dp->bridge_dev;
1234+
found = true;
1235+
break;
1236+
}
1237+
}
1238+
/* dev is a virtual bridge */
1239+
} else {
1240+
list_for_each_entry(dp, &dst->ports, list) {
1241+
if (dp->bridge_num < 0)
1242+
continue;
1243+
1244+
if (dp->bridge_num + 1 + dst->last_switch != dev)
1245+
continue;
1246+
1247+
br = dp->bridge_dev;
12261248
found = true;
12271249
break;
12281250
}
12291251
}
12301252

1231-
/* Prevent frames from unknown switch or port */
1253+
/* Prevent frames from unknown switch or virtual bridge */
12321254
if (!found)
12331255
return 0;
12341256

12351257
/* Frames from DSA links and CPU ports can egress any local port */
12361258
if (dp->type == DSA_PORT_TYPE_CPU || dp->type == DSA_PORT_TYPE_DSA)
12371259
return mv88e6xxx_port_mask(chip);
12381260

1239-
br = dp->bridge_dev;
12401261
pvlan = 0;
12411262

12421263
/* Frames from user ports can egress any local DSA links and CPU ports,
@@ -2422,6 +2443,44 @@ static void mv88e6xxx_crosschip_bridge_leave(struct dsa_switch *ds,
24222443
mv88e6xxx_reg_unlock(chip);
24232444
}
24242445

2446+
/* Treat the software bridge as a virtual single-port switch behind the
2447+
* CPU and map in the PVT. First dst->last_switch elements are taken by
2448+
* physical switches, so start from beyond that range.
2449+
*/
2450+
static int mv88e6xxx_map_virtual_bridge_to_pvt(struct dsa_switch *ds,
2451+
int bridge_num)
2452+
{
2453+
u8 dev = bridge_num + ds->dst->last_switch + 1;
2454+
struct mv88e6xxx_chip *chip = ds->priv;
2455+
int err;
2456+
2457+
mv88e6xxx_reg_lock(chip);
2458+
err = mv88e6xxx_pvt_map(chip, dev, 0);
2459+
mv88e6xxx_reg_unlock(chip);
2460+
2461+
return err;
2462+
}
2463+
2464+
static int mv88e6xxx_bridge_tx_fwd_offload(struct dsa_switch *ds, int port,
2465+
struct net_device *br,
2466+
int bridge_num)
2467+
{
2468+
return mv88e6xxx_map_virtual_bridge_to_pvt(ds, bridge_num);
2469+
}
2470+
2471+
static void mv88e6xxx_bridge_tx_fwd_unoffload(struct dsa_switch *ds, int port,
2472+
struct net_device *br,
2473+
int bridge_num)
2474+
{
2475+
int err;
2476+
2477+
err = mv88e6xxx_map_virtual_bridge_to_pvt(ds, bridge_num);
2478+
if (err) {
2479+
dev_err(ds->dev, "failed to remap cross-chip Port VLAN: %pe\n",
2480+
ERR_PTR(err));
2481+
}
2482+
}
2483+
24252484
static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
24262485
{
24272486
if (chip->info->ops->reset)
@@ -3025,6 +3084,15 @@ static int mv88e6xxx_setup(struct dsa_switch *ds)
30253084
chip->ds = ds;
30263085
ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
30273086

3087+
/* Since virtual bridges are mapped in the PVT, the number we support
3088+
* depends on the physical switch topology. We need to let DSA figure
3089+
* that out and therefore we cannot set this at dsa_register_switch()
3090+
* time.
3091+
*/
3092+
if (mv88e6xxx_has_pvt(chip))
3093+
ds->num_fwd_offloading_bridges = MV88E6XXX_MAX_PVT_SWITCHES -
3094+
ds->dst->last_switch - 1;
3095+
30283096
mv88e6xxx_reg_lock(chip);
30293097

30303098
if (chip->info->ops->setup_errata) {
@@ -6128,6 +6196,8 @@ static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
61286196
.crosschip_lag_change = mv88e6xxx_crosschip_lag_change,
61296197
.crosschip_lag_join = mv88e6xxx_crosschip_lag_join,
61306198
.crosschip_lag_leave = mv88e6xxx_crosschip_lag_leave,
6199+
.port_bridge_tx_fwd_offload = mv88e6xxx_bridge_tx_fwd_offload,
6200+
.port_bridge_tx_fwd_unoffload = mv88e6xxx_bridge_tx_fwd_unoffload,
61316201
};
61326202

61336203
static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)

0 commit comments

Comments
 (0)