net: mscc: ocelot: reapply bridge forwarding mask on bonding join/leave
authorVladimir Oltean <vladimir.oltean@nxp.com>
Fri, 29 Jan 2021 01:00:02 +0000 (03:00 +0200)
committerJakub Kicinski <kuba@kernel.org>
Sat, 30 Jan 2021 05:24:30 +0000 (21:24 -0800)
Applying the bridge forwarding mask currently is done only on the STP
state changes for any port. But it depends on both STP state changes,
and bonding interface state changes. Export the bit that recalculates
the forwarding mask so that it could be reused, and call it when a port
starts and stops offloading a bonding interface.

Now that the logic is split into a separate function, we can rename "p"
into "port", since the "port" variable was already taken in
ocelot_bridge_stp_state_set. Also, we can rename "i" into "lag", to make
it more clear what is it that we're iterating through.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/mscc/ocelot.c

index 5b2c0ce..7352f58 100644 (file)
@@ -889,10 +889,42 @@ int ocelot_get_ts_info(struct ocelot *ocelot, int port,
 }
 EXPORT_SYMBOL(ocelot_get_ts_info);
 
+static void ocelot_apply_bridge_fwd_mask(struct ocelot *ocelot)
+{
+       int port;
+
+       /* Apply FWD mask. The loop is needed to add/remove the current port as
+        * a source for the other ports.
+        */
+       for (port = 0; port < ocelot->num_phys_ports; port++) {
+               if (ocelot->bridge_fwd_mask & BIT(port)) {
+                       unsigned long mask = ocelot->bridge_fwd_mask & ~BIT(port);
+                       int lag;
+
+                       for (lag = 0; lag < ocelot->num_phys_ports; lag++) {
+                               unsigned long bond_mask = ocelot->lags[lag];
+
+                               if (!bond_mask)
+                                       continue;
+
+                               if (bond_mask & BIT(port)) {
+                                       mask &= ~bond_mask;
+                                       break;
+                               }
+                       }
+
+                       ocelot_write_rix(ocelot, mask,
+                                        ANA_PGID_PGID, PGID_SRC + port);
+               } else {
+                       ocelot_write_rix(ocelot, 0,
+                                        ANA_PGID_PGID, PGID_SRC + port);
+               }
+       }
+}
+
 void ocelot_bridge_stp_state_set(struct ocelot *ocelot, int port, u8 state)
 {
        u32 port_cfg;
-       int p, i;
 
        if (!(BIT(port) & ocelot->bridge_mask))
                return;
@@ -915,32 +947,7 @@ void ocelot_bridge_stp_state_set(struct ocelot *ocelot, int port, u8 state)
 
        ocelot_write_gix(ocelot, port_cfg, ANA_PORT_PORT_CFG, port);
 
-       /* Apply FWD mask. The loop is needed to add/remove the current port as
-        * a source for the other ports.
-        */
-       for (p = 0; p < ocelot->num_phys_ports; p++) {
-               if (ocelot->bridge_fwd_mask & BIT(p)) {
-                       unsigned long mask = ocelot->bridge_fwd_mask & ~BIT(p);
-
-                       for (i = 0; i < ocelot->num_phys_ports; i++) {
-                               unsigned long bond_mask = ocelot->lags[i];
-
-                               if (!bond_mask)
-                                       continue;
-
-                               if (bond_mask & BIT(p)) {
-                                       mask &= ~bond_mask;
-                                       break;
-                               }
-                       }
-
-                       ocelot_write_rix(ocelot, mask,
-                                        ANA_PGID_PGID, PGID_SRC + p);
-               } else {
-                       ocelot_write_rix(ocelot, 0,
-                                        ANA_PGID_PGID, PGID_SRC + p);
-               }
-       }
+       ocelot_apply_bridge_fwd_mask(ocelot);
 }
 EXPORT_SYMBOL(ocelot_bridge_stp_state_set);
 
@@ -1297,6 +1304,7 @@ int ocelot_port_lag_join(struct ocelot *ocelot, int port,
        }
 
        ocelot_setup_lag(ocelot, lag);
+       ocelot_apply_bridge_fwd_mask(ocelot);
        ocelot_set_aggr_pgids(ocelot);
 
        return 0;
@@ -1330,6 +1338,7 @@ void ocelot_port_lag_leave(struct ocelot *ocelot, int port,
        ocelot_write_gix(ocelot, port_cfg | ANA_PORT_PORT_CFG_PORTID_VAL(port),
                         ANA_PORT_PORT_CFG, port);
 
+       ocelot_apply_bridge_fwd_mask(ocelot);
        ocelot_set_aggr_pgids(ocelot);
 }
 EXPORT_SYMBOL(ocelot_port_lag_leave);