net: dsa: track the number of switches in a tree
authorVladimir Oltean <vladimir.oltean@nxp.com>
Thu, 22 Jul 2021 15:55:39 +0000 (18:55 +0300)
committerDavid S. Miller <davem@davemloft.net>
Fri, 23 Jul 2021 15:32:37 +0000 (16:32 +0100)
commit5b22d3669f2fa6e762c5302fc4b6051a92b81617
treee6ffc27c1aa0bb2bfc2e0694f6cae0dc0055dc3b
parent472111920f1c5fbe103022a4b05bfb37128a2a29
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 <vladimir.oltean@nxp.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/dsa.h
net/dsa/dsa2.c