Skip to content

Commit 5b22d36

Browse files
vladimirolteandavem330
authored andcommitted
net: dsa: track the number of switches in a tree
In preparation of supporting data plane forwarding on behalf of a software bridge, some drivers might need to view bridges as virtual switches behind the CPU port in a cross-chip topology. Give them some help and let them know how many physical switches there are in the tree, so that they can count the virtual switches starting from that number on. Note that the first dsa_switch_ops method where this information is reliably available is .setup(). This is because of how DSA works: in a tree with 3 switches, each calling dsa_register_switch(), the first 2 will advance until dsa_tree_setup() -> dsa_tree_setup_routing_table() and exit with error code 0 because the topology is not complete. Since probing is parallel at this point, one switch does not know about the existence of the other. Then the third switch comes, and for it, dsa_tree_setup_routing_table() returns complete = true. This switch goes ahead and calls dsa_tree_setup_switches() for everybody else, calling their .setup() methods too. This acts as the synchronization point. Signed-off-by: Vladimir Oltean <[email protected]> Reviewed-by: Florian Fainelli <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 4721119 commit 5b22d36

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

include/net/dsa.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ struct dsa_switch_tree {
159159
*/
160160
struct net_device **lags;
161161
unsigned int lags_len;
162+
163+
/* Track the largest switch index within a tree */
164+
unsigned int last_switch;
162165
};
163166

164167
#define dsa_lags_foreach_id(_id, _dst) \

net/dsa/dsa2.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,6 +1265,9 @@ static int dsa_switch_parse_member_of(struct dsa_switch *ds,
12651265
return -EEXIST;
12661266
}
12671267

1268+
if (ds->dst->last_switch < ds->index)
1269+
ds->dst->last_switch = ds->index;
1270+
12681271
return 0;
12691272
}
12701273

0 commit comments

Comments
 (0)