Commit f5e165e7 authored by Vladimir Oltean's avatar Vladimir Oltean Committed by David S. Miller

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: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 1a6ef20b
...@@ -155,9 +155,6 @@ struct dsa_switch_tree { ...@@ -155,9 +155,6 @@ struct dsa_switch_tree {
/* Track the largest switch index within a tree */ /* Track the largest switch index within a tree */
unsigned int last_switch; unsigned int last_switch;
/* Track the bridges with forwarding offload enabled */
unsigned long fwd_offloading_bridges;
}; };
#define dsa_lags_foreach_id(_id, _dst) \ #define dsa_lags_foreach_id(_id, _dst) \
...@@ -411,8 +408,9 @@ struct dsa_switch { ...@@ -411,8 +408,9 @@ struct dsa_switch {
unsigned int num_lag_ids; unsigned int num_lag_ids;
/* Drivers that support bridge forwarding offload should set this to /* Drivers that support bridge forwarding offload should set this to
* the maximum number of bridges spanning the same switch tree that can * the maximum number of bridges spanning the same switch tree (or all
* be offloaded. * trees, in the case of cross-tree bridging support) that can be
* offloaded.
*/ */
unsigned int num_fwd_offloading_bridges; unsigned int num_fwd_offloading_bridges;
......
...@@ -21,6 +21,9 @@ ...@@ -21,6 +21,9 @@
static DEFINE_MUTEX(dsa2_mutex); static DEFINE_MUTEX(dsa2_mutex);
LIST_HEAD(dsa_tree_list); LIST_HEAD(dsa_tree_list);
/* Track the bridges with forwarding offload enabled */
static unsigned long dsa_fwd_offloading_bridges;
/** /**
* dsa_tree_notify - Execute code for all switches in a DSA switch tree. * dsa_tree_notify - Execute code for all switches in a DSA switch tree.
* @dst: collection of struct dsa_switch devices to notify. * @dst: collection of struct dsa_switch devices to notify.
...@@ -126,6 +129,51 @@ void dsa_lag_unmap(struct dsa_switch_tree *dst, struct net_device *lag) ...@@ -126,6 +129,51 @@ void dsa_lag_unmap(struct dsa_switch_tree *dst, struct net_device *lag)
} }
} }
static int dsa_bridge_num_find(const struct net_device *bridge_dev)
{
struct dsa_switch_tree *dst;
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(dst, &dsa_tree_list, list)
list_for_each_entry(dp, &dst->ports, list)
if (dp->bridge_dev == bridge_dev &&
dp->bridge_num != -1)
return dp->bridge_num;
return -1;
}
int dsa_bridge_num_get(const struct net_device *bridge_dev, int max)
{
int bridge_num = dsa_bridge_num_find(bridge_dev);
if (bridge_num < 0) {
/* First port that offloads TX forwarding for this bridge */
bridge_num = find_first_zero_bit(&dsa_fwd_offloading_bridges,
DSA_MAX_NUM_OFFLOADING_BRIDGES);
if (bridge_num >= max)
return -1;
set_bit(bridge_num, &dsa_fwd_offloading_bridges);
}
return bridge_num;
}
void dsa_bridge_num_put(const struct net_device *bridge_dev, int bridge_num)
{
/* 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_bridge_num_find(bridge_dev))
clear_bit(bridge_num, &dsa_fwd_offloading_bridges);
}
struct dsa_switch *dsa_switch_find(int tree_index, int sw_index) struct dsa_switch *dsa_switch_find(int tree_index, int sw_index)
{ {
struct dsa_switch_tree *dst; struct dsa_switch_tree *dst;
......
...@@ -543,6 +543,8 @@ int dsa_tree_change_tag_proto(struct dsa_switch_tree *dst, ...@@ -543,6 +543,8 @@ int dsa_tree_change_tag_proto(struct dsa_switch_tree *dst,
struct net_device *master, struct net_device *master,
const struct dsa_device_ops *tag_ops, const struct dsa_device_ops *tag_ops,
const struct dsa_device_ops *old_tag_ops); const struct dsa_device_ops *old_tag_ops);
int dsa_bridge_num_get(const struct net_device *bridge_dev, int max);
void dsa_bridge_num_put(const struct net_device *bridge_dev, int bridge_num);
/* tag_8021q.c */ /* tag_8021q.c */
int dsa_tag_8021q_bridge_join(struct dsa_switch *ds, int dsa_tag_8021q_bridge_join(struct dsa_switch *ds,
......
...@@ -270,27 +270,9 @@ static void dsa_port_switchdev_unsync_attrs(struct dsa_port *dp) ...@@ -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, static void dsa_port_bridge_tx_fwd_unoffload(struct dsa_port *dp,
struct net_device *bridge_dev) struct net_device *bridge_dev)
{ {
struct dsa_switch_tree *dst = dp->ds->dst;
int bridge_num = dp->bridge_num; int bridge_num = dp->bridge_num;
struct dsa_switch *ds = dp->ds; struct dsa_switch *ds = dp->ds;
...@@ -300,11 +282,7 @@ static void dsa_port_bridge_tx_fwd_unoffload(struct dsa_port *dp, ...@@ -300,11 +282,7 @@ static void dsa_port_bridge_tx_fwd_unoffload(struct dsa_port *dp,
dp->bridge_num = -1; dp->bridge_num = -1;
/* Check if the bridge is still in use, otherwise it is time dsa_bridge_num_put(bridge_dev, bridge_num);
* 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);
/* Notify the chips only once the offload has been deactivated, so /* Notify the chips only once the offload has been deactivated, so
* that they can update their configuration accordingly. * that they can update their configuration accordingly.
...@@ -316,23 +294,16 @@ static void dsa_port_bridge_tx_fwd_unoffload(struct dsa_port *dp, ...@@ -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, static bool dsa_port_bridge_tx_fwd_offload(struct dsa_port *dp,
struct net_device *bridge_dev) struct net_device *bridge_dev)
{ {
struct dsa_switch_tree *dst = dp->ds->dst;
struct dsa_switch *ds = dp->ds; struct dsa_switch *ds = dp->ds;
int bridge_num, err; int bridge_num, err;
if (!ds->ops->port_bridge_tx_fwd_offload) if (!ds->ops->port_bridge_tx_fwd_offload)
return false; return false;
bridge_num = dsa_tree_find_bridge_num(dst, bridge_dev); bridge_num = dsa_bridge_num_get(bridge_dev,
if (bridge_num < 0) { ds->num_fwd_offloading_bridges);
/* First port that offloads TX forwarding for this bridge */ if (bridge_num < 0)
bridge_num = find_first_zero_bit(&dst->fwd_offloading_bridges, return false;
DSA_MAX_NUM_OFFLOADING_BRIDGES);
if (bridge_num >= ds->num_fwd_offloading_bridges)
return false;
set_bit(bridge_num, &dst->fwd_offloading_bridges);
}
dp->bridge_num = bridge_num; dp->bridge_num = bridge_num;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment