History

net: dsa: eliminate dsa_switch_ops :: port_bridge_tx_fwd_{,un}offload

We don't really need new switch API for these, and with new switches which intend to add support for this feature, it will become cumbersome to maintain. The change consists in restructuring the two drivers that implement this offload (sja1105 and mv88e6xxx) such that the offload is enabled and disabled from the ->port_bridge_{join,leave} methods instead of the old ->port_bridge_tx_fwd_{,un}offload. The only non-trivial change is that mv88e6xxx_map_virtual_bridge_to_pvt() has been moved to avoid a forward declaration, and the mv88e6xxx_reg_lock() calls from inside it have been removed, since locking is now done from mv88e6xxx_port_bridge_{join,leave}.

Vladimir Oltean committed 4 years ago

Commit 857fdd71 parent b0799224 files · +45 −83Browse files

Unified · Split

4 files
  1. drivers/net/dsa/mv88e6xxx/chip.c +25 −38
  2. drivers/net/dsa/sja1105/sja1105_main.c +16 −3
  3. include/net/dsa.h +1 −6
  4. net/dsa/port.c +3 −36
drivers/net/dsa/mv88e6xxx/chip.c+25−38
@@ -2441,6 +2441,19 @@ static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip, · 2440 unmodified lines
24412441 return 0;
24422442 }
24432443
2444+/* Treat the software bridge as a virtual single-port switch behind the
2445+ * CPU and map in the PVT. First dst->last_switch elements are taken by
2446+ * physical switches, so start from beyond that range.
2447+ */
2448+static int mv88e6xxx_map_virtual_bridge_to_pvt(struct dsa_switch *ds,
2449+ unsigned int bridge_num)
2450+{
2451+ u8 dev = bridge_num + ds->dst->last_switch;
2452+ struct mv88e6xxx_chip *chip = ds->priv;
2453+
2454+ return mv88e6xxx_pvt_map(chip, dev, 0);
2455+}
2456+
24442457 static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
24452458 struct dsa_bridge bridge,
24462459 bool *tx_fwd_offload)
@@ -2458,6 +2471,14 @@ static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port, · 11 unmodified lines
24582471 if (err)
24592472 goto unlock;
24602473
2474+ if (mv88e6xxx_has_pvt(chip)) {
2475+ err = mv88e6xxx_map_virtual_bridge_to_pvt(ds, bridge.num);
2476+ if (err)
2477+ goto unlock;
2478+
2479+ *tx_fwd_offload = true;
2480+ }
2481+
24612482 unlock:
24622483 mv88e6xxx_reg_unlock(chip);
24632484
@@ -2472,6 +2493,10 @@ static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port, · 8 unmodified lines
24722493
24732494 mv88e6xxx_reg_lock(chip);
24742495
2496+ if (bridge.tx_fwd_offload &&
2497+ mv88e6xxx_map_virtual_bridge_to_pvt(ds, bridge.num))
2498+ dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n");
2499+
24752500 if (mv88e6xxx_bridge_map(chip, bridge) ||
24762501 mv88e6xxx_port_vlan_map(chip, port))
24772502 dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
@@ -2517,42 +2542,6 @@ static void mv88e6xxx_crosschip_bridge_leave(struct dsa_switch *ds, · 39 unmodified lines
25172542 mv88e6xxx_reg_unlock(chip);
25182543 }
25192544
2520−/* Treat the software bridge as a virtual single-port switch behind the
2521− * CPU and map in the PVT. First dst->last_switch elements are taken by
2522− * physical switches, so start from beyond that range.
2523− */
2524−static int mv88e6xxx_map_virtual_bridge_to_pvt(struct dsa_switch *ds,
2525− unsigned int bridge_num)
2526−{
2527− u8 dev = bridge_num + ds->dst->last_switch;
2528− struct mv88e6xxx_chip *chip = ds->priv;
2529− int err;
2530−
2531− mv88e6xxx_reg_lock(chip);
2532− err = mv88e6xxx_pvt_map(chip, dev, 0);
2533− mv88e6xxx_reg_unlock(chip);
2534−
2535− return err;
2536−}
2537−
2538−static int mv88e6xxx_bridge_tx_fwd_offload(struct dsa_switch *ds, int port,
2539− struct dsa_bridge bridge)
2540−{
2541− return mv88e6xxx_map_virtual_bridge_to_pvt(ds, bridge.num);
2542−}
2543−
2544−static void mv88e6xxx_bridge_tx_fwd_unoffload(struct dsa_switch *ds, int port,
2545− struct dsa_bridge bridge)
2546−{
2547− int err;
2548−
2549− err = mv88e6xxx_map_virtual_bridge_to_pvt(ds, bridge.num);
2550− if (err) {
2551− dev_err(ds->dev, "failed to remap cross-chip Port VLAN: %pe\n",
2552− ERR_PTR(err));
2553− }
2554−}
2555−
25562545 static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
25572546 {
25582547 if (chip->info->ops->reset)
@@ -6272,8 +6261,6 @@ static const struct dsa_switch_ops mv88e6xxx_switch_ops = { · 3713 unmodified lines
62726261 .crosschip_lag_change = mv88e6xxx_crosschip_lag_change,
62736262 .crosschip_lag_join = mv88e6xxx_crosschip_lag_join,
62746263 .crosschip_lag_leave = mv88e6xxx_crosschip_lag_leave,
6275− .port_bridge_tx_fwd_offload = mv88e6xxx_bridge_tx_fwd_offload,
6276− .port_bridge_tx_fwd_unoffload = mv88e6xxx_bridge_tx_fwd_unoffload,
62776264 };
62786265
62796266 static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
drivers/net/dsa/sja1105/sja1105_main.c+16−3
@@ -2077,12 +2077,27 @@ static int sja1105_bridge_join(struct dsa_switch *ds, int port, · 2076 unmodified lines
20772077 struct dsa_bridge bridge,
20782078 bool *tx_fwd_offload)
20792079 {
2080− return sja1105_bridge_member(ds, port, bridge, true);
2080+ int rc;
2081+
2082+ rc = sja1105_bridge_member(ds, port, bridge, true);
2083+ if (rc)
2084+ return rc;
2085+
2086+ rc = dsa_tag_8021q_bridge_tx_fwd_offload(ds, port, bridge);
2087+ if (rc) {
2088+ sja1105_bridge_member(ds, port, bridge, false);
2089+ return rc;
2090+ }
2091+
2092+ *tx_fwd_offload = true;
2093+
2094+ return 0;
20812095 }
20822096
20832097 static void sja1105_bridge_leave(struct dsa_switch *ds, int port,
20842098 struct dsa_bridge bridge)
20852099 {
2100+ dsa_tag_8021q_bridge_tx_fwd_unoffload(ds, port, bridge);
20862101 sja1105_bridge_member(ds, port, bridge, false);
20872102 }
20882103
@@ -3231,8 +3246,6 @@ static const struct dsa_switch_ops sja1105_switch_ops = { · 1142 unmodified lines
32313246 .tag_8021q_vlan_add = sja1105_dsa_8021q_vlan_add,
32323247 .tag_8021q_vlan_del = sja1105_dsa_8021q_vlan_del,
32333248 .port_prechangeupper = sja1105_prechangeupper,
3234− .port_bridge_tx_fwd_offload = dsa_tag_8021q_bridge_tx_fwd_offload,
3235− .port_bridge_tx_fwd_unoffload = dsa_tag_8021q_bridge_tx_fwd_unoffload,
32363249 };
32373250
32383251 static const struct of_device_id sja1105_dt_ids[];
include/net/dsa.h+1−6
@@ -222,6 +222,7 @@ struct dsa_mall_tc_entry { · 221 unmodified lines
222222 struct dsa_bridge {
223223 struct net_device *dev;
224224 unsigned int num;
225+ bool tx_fwd_offload;
225226 refcount_t refcount;
226227 };
227228
@@ -826,12 +827,6 @@ struct dsa_switch_ops { · 598 unmodified lines
826827 bool *tx_fwd_offload);
827828 void (*port_bridge_leave)(struct dsa_switch *ds, int port,
828829 struct dsa_bridge bridge);
829− /* Called right after .port_bridge_join() */
830− int (*port_bridge_tx_fwd_offload)(struct dsa_switch *ds, int port,
831− struct dsa_bridge bridge);
832− /* Called right before .port_bridge_leave() */
833− void (*port_bridge_tx_fwd_unoffload)(struct dsa_switch *ds, int port,
834− struct dsa_bridge bridge);
835830 void (*port_stp_state_set)(struct dsa_switch *ds, int port,
836831 u8 state);
837832 void (*port_fast_age)(struct dsa_switch *ds, int port);
net/dsa/port.c+3−36
@@ -270,37 +270,6 @@ static void dsa_port_switchdev_unsync_attrs(struct dsa_port *dp) · 269 unmodified lines
270270 */
271271 }
272272
273−static void dsa_port_bridge_tx_fwd_unoffload(struct dsa_port *dp,
274− struct dsa_bridge bridge)
275−{
276− struct dsa_switch *ds = dp->ds;
277−
278− /* No bridge TX forwarding offload => do nothing */
279− if (!ds->ops->port_bridge_tx_fwd_unoffload || !bridge.num)
280− return;
281−
282− /* Notify the chips only once the offload has been deactivated, so
283− * that they can update their configuration accordingly.
284− */
285− ds->ops->port_bridge_tx_fwd_unoffload(ds, dp->index, bridge);
286−}
287−
288−static bool dsa_port_bridge_tx_fwd_offload(struct dsa_port *dp,
289− struct dsa_bridge bridge)
290−{
291− struct dsa_switch *ds = dp->ds;
292− int err;
293−
294− /* FDB isolation is required for TX forwarding offload */
295− if (!ds->ops->port_bridge_tx_fwd_offload || !bridge.num)
296− return false;
297−
298− /* Notify the driver */
299− err = ds->ops->port_bridge_tx_fwd_offload(ds, dp->index, bridge);
300−
301− return err ? false : true;
302−}
303−
304273 static int dsa_port_bridge_create(struct dsa_port *dp,
305274 struct net_device *br,
306275 struct netlink_ext_ack *extack)
@@ -362,7 +331,6 @@ int dsa_port_bridge_join(struct dsa_port *dp, struct net_device *br, · 55 unmodified lines
362331 };
363332 struct net_device *dev = dp->slave;
364333 struct net_device *brport_dev;
365− bool tx_fwd_offload;
366334 int err;
367335
368336 /* Here the interface is already bridged. Reflect the current
@@ -379,12 +347,13 @@ int dsa_port_bridge_join(struct dsa_port *dp, struct net_device *br, · 10 unmodified lines
379347 if (err)
380348 goto out_rollback;
381349
382− tx_fwd_offload = dsa_port_bridge_tx_fwd_offload(dp, info.bridge);
350+ /* Drivers which support bridge TX forwarding should set this */
351+ dp->bridge->tx_fwd_offload = info.tx_fwd_offload;
383352
384353 err = switchdev_bridge_port_offload(brport_dev, dev, dp,
385354 &dsa_slave_switchdev_notifier,
386355 &dsa_slave_switchdev_blocking_notifier,
387− tx_fwd_offload, extack);
356+ dp->bridge->tx_fwd_offload, extack);
388357 if (err)
389358 goto out_rollback_unbridge;
390359
@@ -435,8 +404,6 @@ void dsa_port_bridge_leave(struct dsa_port *dp, struct net_device *br) · 44 unmodified lines
435404 */
436405 dsa_port_bridge_destroy(dp, br);
437406
438− dsa_port_bridge_tx_fwd_unoffload(dp, info.bridge);
439−
440407 err = dsa_broadcast(DSA_NOTIFIER_BRIDGE_LEAVE, &info);
441408 if (err)
442409 dev_err(dp->ds->dev,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t