summaryrefslogtreecommitdiff
path: root/net/dsa/port.c
diff options
context:
space:
mode:
authorVladimir Oltean <vladimir.oltean@nxp.com>2021-08-19 20:55:00 +0300
committerDavid S. Miller <davem@davemloft.net>2021-08-23 11:52:31 +0100
commitf5e165e72b29d908214e554ef57f67790ba95934 (patch)
treee74566f4048f4548c985f2cc4b19b2e10cca4e1a /net/dsa/port.c
parent1a6ef20b415220c8611679dcb9c31586641217fc (diff)
net: dsa: track unique bridge numbers across all DSA switch trees
Right now, cross-tree bridging setups work somewhat by mistake. In the case of cross-tree bridging with sja1105, all switch instances need to agree upon a common VLAN ID for forwarding a packet that belongs to a certain bridging domain. With TX forwarding offload, the VLAN ID is the bridge VLAN for VLAN-aware bridging, and the tag_8021q TX forwarding offload VID (a VLAN which has non-zero VBID bits) for VLAN-unaware bridging. The VBID for VLAN-unaware bridging is derived from the dp->bridge_num value calculated by DSA independently for each switch tree. If ports from one tree join one bridge, and ports from another tree join another bridge, DSA will assign them the same bridge_num, even though the bridges are different. If cross-tree bridging is supported, this is an issue. Modify DSA to calculate the bridge_num globally across all switch trees. This has the implication for a driver that the dp->bridge_num value that DSA will assign to its ports might not be contiguous, if there are boards with multiple DSA drivers instantiated. Additionally, all bridge_num values eat up towards each switch's ds->num_fwd_offloading_bridges maximum, which is potentially unfortunate, and can be seen as a limitation introduced by this patch. However, that is the lesser evil for now. Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/dsa/port.c')
-rw-r--r--net/dsa/port.c39
1 files changed, 5 insertions, 34 deletions
diff --git a/net/dsa/port.c b/net/dsa/port.c
index 979042a64d1a..4fbe81ffb1ce 100644
--- a/net/dsa/port.c
+++ b/net/dsa/port.c
@@ -270,27 +270,9 @@ static void dsa_port_switchdev_unsync_attrs(struct dsa_port *dp)
*/
}
-static int dsa_tree_find_bridge_num(struct dsa_switch_tree *dst,
- struct net_device *bridge_dev)
-{
- struct dsa_port *dp;
-
- /* When preparing the offload for a port, it will have a valid
- * dp->bridge_dev pointer but a not yet valid dp->bridge_num.
- * However there might be other ports having the same dp->bridge_dev
- * and a valid dp->bridge_num, so just ignore this port.
- */
- list_for_each_entry(dp, &dst->ports, list)
- if (dp->bridge_dev == bridge_dev && dp->bridge_num != -1)
- return dp->bridge_num;
-
- return -1;
-}
-
static void dsa_port_bridge_tx_fwd_unoffload(struct dsa_port *dp,
struct net_device *bridge_dev)
{
- struct dsa_switch_tree *dst = dp->ds->dst;
int bridge_num = dp->bridge_num;
struct dsa_switch *ds = dp->ds;
@@ -300,11 +282,7 @@ static void dsa_port_bridge_tx_fwd_unoffload(struct dsa_port *dp,
dp->bridge_num = -1;
- /* Check if the bridge is still in use, otherwise it is time
- * to clean it up so we can reuse this bridge_num later.
- */
- if (!dsa_tree_find_bridge_num(dst, bridge_dev))
- clear_bit(bridge_num, &dst->fwd_offloading_bridges);
+ dsa_bridge_num_put(bridge_dev, bridge_num);
/* Notify the chips only once the offload has been deactivated, so
* that they can update their configuration accordingly.
@@ -316,23 +294,16 @@ static void dsa_port_bridge_tx_fwd_unoffload(struct dsa_port *dp,
static bool dsa_port_bridge_tx_fwd_offload(struct dsa_port *dp,
struct net_device *bridge_dev)
{
- struct dsa_switch_tree *dst = dp->ds->dst;
struct dsa_switch *ds = dp->ds;
int bridge_num, err;
if (!ds->ops->port_bridge_tx_fwd_offload)
return false;
- bridge_num = dsa_tree_find_bridge_num(dst, bridge_dev);
- if (bridge_num < 0) {
- /* First port that offloads TX forwarding for this bridge */
- bridge_num = find_first_zero_bit(&dst->fwd_offloading_bridges,
- DSA_MAX_NUM_OFFLOADING_BRIDGES);
- if (bridge_num >= ds->num_fwd_offloading_bridges)
- return false;
-
- set_bit(bridge_num, &dst->fwd_offloading_bridges);
- }
+ bridge_num = dsa_bridge_num_get(bridge_dev,
+ ds->num_fwd_offloading_bridges);
+ if (bridge_num < 0)
+ return false;
dp->bridge_num = bridge_num;