Commit 3a262c71 authored by Jakub Kicinski's avatar Jakub Kicinski

Merge branch 'rework-dsa-bridge-tx-forwarding-offload-api'

Vladimir Oltean says:

====================
Rework DSA bridge TX forwarding offload API

This change set is preparation work for DSA support of bridge FDB
isolation. It replaces struct net_device *dp->bridge_dev with a struct
dsa_bridge *dp->bridge that contains some extra information about that
bridge, like a unique number kept by DSA.

Up until now we computed that number only with the bridge TX forwarding
offload feature, but it will be needed for other features too, like for
isolation of FDB entries belonging to different bridges. Hardware
implementations vary, but one common pattern seems to be the presence of
a FID field which can be associated with that bridge number kept by DSA.
The idea was outlined here:
https://patchwork.kernel.org/project/netdevbpf/patch/20210818120150.892647-16-vladimir.oltean@nxp.com/
(the difference being that with this new proposal, drivers would not
need to call dsa_bridge_num_find, instead the bridge_num would be part
of the struct dsa_bridge :: num passed as argument).

No functional change is intended for drivers that don't already make use
of the bridge TX forwarding offload. I've tested the changes on the
felix, sja1105 and mv88e6xxx drivers, but nonetheless I'm copying all
DSA driver maintainers due to API changes that are taking place.

Compared to v1 and v2, the amount of patches is larger, but the contents
is mostly the same, just split up hopefully a bit better for review.
====================

Link: https://lore.kernel.org/r/20211206165758.1553882-1-vladimir.oltean@nxp.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents 1fe5b012 857fdd74
...@@ -1860,7 +1860,8 @@ int b53_mdb_del(struct dsa_switch *ds, int port, ...@@ -1860,7 +1860,8 @@ int b53_mdb_del(struct dsa_switch *ds, int port,
} }
EXPORT_SYMBOL(b53_mdb_del); EXPORT_SYMBOL(b53_mdb_del);
int b53_br_join(struct dsa_switch *ds, int port, struct net_device *br) int b53_br_join(struct dsa_switch *ds, int port, struct dsa_bridge bridge,
bool *tx_fwd_offload)
{ {
struct b53_device *dev = ds->priv; struct b53_device *dev = ds->priv;
s8 cpu_port = dsa_to_port(ds, port)->cpu_dp->index; s8 cpu_port = dsa_to_port(ds, port)->cpu_dp->index;
...@@ -1887,7 +1888,7 @@ int b53_br_join(struct dsa_switch *ds, int port, struct net_device *br) ...@@ -1887,7 +1888,7 @@ int b53_br_join(struct dsa_switch *ds, int port, struct net_device *br)
b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), &pvlan); b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), &pvlan);
b53_for_each_port(dev, i) { b53_for_each_port(dev, i) {
if (dsa_to_port(ds, i)->bridge_dev != br) if (!dsa_port_offloads_bridge(dsa_to_port(ds, i), &bridge))
continue; continue;
/* Add this local port to the remote port VLAN control /* Add this local port to the remote port VLAN control
...@@ -1911,7 +1912,7 @@ int b53_br_join(struct dsa_switch *ds, int port, struct net_device *br) ...@@ -1911,7 +1912,7 @@ int b53_br_join(struct dsa_switch *ds, int port, struct net_device *br)
} }
EXPORT_SYMBOL(b53_br_join); EXPORT_SYMBOL(b53_br_join);
void b53_br_leave(struct dsa_switch *ds, int port, struct net_device *br) void b53_br_leave(struct dsa_switch *ds, int port, struct dsa_bridge bridge)
{ {
struct b53_device *dev = ds->priv; struct b53_device *dev = ds->priv;
struct b53_vlan *vl = &dev->vlans[0]; struct b53_vlan *vl = &dev->vlans[0];
...@@ -1923,7 +1924,7 @@ void b53_br_leave(struct dsa_switch *ds, int port, struct net_device *br) ...@@ -1923,7 +1924,7 @@ void b53_br_leave(struct dsa_switch *ds, int port, struct net_device *br)
b53_for_each_port(dev, i) { b53_for_each_port(dev, i) {
/* Don't touch the remaining ports */ /* Don't touch the remaining ports */
if (dsa_to_port(ds, i)->bridge_dev != br) if (!dsa_port_offloads_bridge(dsa_to_port(ds, i), &bridge))
continue; continue;
b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), &reg); b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), &reg);
......
...@@ -324,8 +324,9 @@ void b53_get_strings(struct dsa_switch *ds, int port, u32 stringset, ...@@ -324,8 +324,9 @@ void b53_get_strings(struct dsa_switch *ds, int port, u32 stringset,
void b53_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *data); void b53_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *data);
int b53_get_sset_count(struct dsa_switch *ds, int port, int sset); int b53_get_sset_count(struct dsa_switch *ds, int port, int sset);
void b53_get_ethtool_phy_stats(struct dsa_switch *ds, int port, uint64_t *data); void b53_get_ethtool_phy_stats(struct dsa_switch *ds, int port, uint64_t *data);
int b53_br_join(struct dsa_switch *ds, int port, struct net_device *bridge); int b53_br_join(struct dsa_switch *ds, int port, struct dsa_bridge bridge,
void b53_br_leave(struct dsa_switch *ds, int port, struct net_device *bridge); bool *tx_fwd_offload);
void b53_br_leave(struct dsa_switch *ds, int port, struct dsa_bridge bridge);
void b53_br_set_stp_state(struct dsa_switch *ds, int port, u8 state); void b53_br_set_stp_state(struct dsa_switch *ds, int port, u8 state);
void b53_br_fast_age(struct dsa_switch *ds, int port); void b53_br_fast_age(struct dsa_switch *ds, int port);
int b53_br_flags_pre(struct dsa_switch *ds, int port, int b53_br_flags_pre(struct dsa_switch *ds, int port,
......
...@@ -167,19 +167,20 @@ static int dsa_loop_phy_write(struct dsa_switch *ds, int port, ...@@ -167,19 +167,20 @@ static int dsa_loop_phy_write(struct dsa_switch *ds, int port,
} }
static int dsa_loop_port_bridge_join(struct dsa_switch *ds, int port, static int dsa_loop_port_bridge_join(struct dsa_switch *ds, int port,
struct net_device *bridge) struct dsa_bridge bridge,
bool *tx_fwd_offload)
{ {
dev_dbg(ds->dev, "%s: port: %d, bridge: %s\n", dev_dbg(ds->dev, "%s: port: %d, bridge: %s\n",
__func__, port, bridge->name); __func__, port, bridge.dev->name);
return 0; return 0;
} }
static void dsa_loop_port_bridge_leave(struct dsa_switch *ds, int port, static void dsa_loop_port_bridge_leave(struct dsa_switch *ds, int port,
struct net_device *bridge) struct dsa_bridge bridge)
{ {
dev_dbg(ds->dev, "%s: port: %d, bridge: %s\n", dev_dbg(ds->dev, "%s: port: %d, bridge: %s\n",
__func__, port, bridge->name); __func__, port, bridge.dev->name);
} }
static void dsa_loop_port_stp_state_set(struct dsa_switch *ds, int port, static void dsa_loop_port_stp_state_set(struct dsa_switch *ds, int port,
......
...@@ -674,7 +674,8 @@ static int hellcreek_bridge_flags(struct dsa_switch *ds, int port, ...@@ -674,7 +674,8 @@ static int hellcreek_bridge_flags(struct dsa_switch *ds, int port,
} }
static int hellcreek_port_bridge_join(struct dsa_switch *ds, int port, static int hellcreek_port_bridge_join(struct dsa_switch *ds, int port,
struct net_device *br) struct dsa_bridge bridge,
bool *tx_fwd_offload)
{ {
struct hellcreek *hellcreek = ds->priv; struct hellcreek *hellcreek = ds->priv;
...@@ -691,7 +692,7 @@ static int hellcreek_port_bridge_join(struct dsa_switch *ds, int port, ...@@ -691,7 +692,7 @@ static int hellcreek_port_bridge_join(struct dsa_switch *ds, int port,
} }
static void hellcreek_port_bridge_leave(struct dsa_switch *ds, int port, static void hellcreek_port_bridge_leave(struct dsa_switch *ds, int port,
struct net_device *br) struct dsa_bridge bridge)
{ {
struct hellcreek *hellcreek = ds->priv; struct hellcreek *hellcreek = ds->priv;
......
...@@ -1103,12 +1103,13 @@ static void lan9303_port_disable(struct dsa_switch *ds, int port) ...@@ -1103,12 +1103,13 @@ static void lan9303_port_disable(struct dsa_switch *ds, int port)
} }
static int lan9303_port_bridge_join(struct dsa_switch *ds, int port, static int lan9303_port_bridge_join(struct dsa_switch *ds, int port,
struct net_device *br) struct dsa_bridge bridge,
bool *tx_fwd_offload)
{ {
struct lan9303 *chip = ds->priv; struct lan9303 *chip = ds->priv;
dev_dbg(chip->dev, "%s(port %d)\n", __func__, port); dev_dbg(chip->dev, "%s(port %d)\n", __func__, port);
if (dsa_to_port(ds, 1)->bridge_dev == dsa_to_port(ds, 2)->bridge_dev) { if (dsa_port_bridge_same(dsa_to_port(ds, 1), dsa_to_port(ds, 2))) {
lan9303_bridge_ports(chip); lan9303_bridge_ports(chip);
chip->is_bridged = true; /* unleash stp_state_set() */ chip->is_bridged = true; /* unleash stp_state_set() */
} }
...@@ -1117,7 +1118,7 @@ static int lan9303_port_bridge_join(struct dsa_switch *ds, int port, ...@@ -1117,7 +1118,7 @@ static int lan9303_port_bridge_join(struct dsa_switch *ds, int port,
} }
static void lan9303_port_bridge_leave(struct dsa_switch *ds, int port, static void lan9303_port_bridge_leave(struct dsa_switch *ds, int port,
struct net_device *br) struct dsa_bridge bridge)
{ {
struct lan9303 *chip = ds->priv; struct lan9303 *chip = ds->priv;
......
...@@ -759,7 +759,7 @@ static int gswip_port_vlan_filtering(struct dsa_switch *ds, int port, ...@@ -759,7 +759,7 @@ static int gswip_port_vlan_filtering(struct dsa_switch *ds, int port,
bool vlan_filtering, bool vlan_filtering,
struct netlink_ext_ack *extack) struct netlink_ext_ack *extack)
{ {
struct net_device *bridge = dsa_to_port(ds, port)->bridge_dev; struct net_device *bridge = dsa_port_bridge_dev_get(dsa_to_port(ds, port));
struct gswip_priv *priv = ds->priv; struct gswip_priv *priv = ds->priv;
/* Do not allow changing the VLAN filtering options while in bridge */ /* Do not allow changing the VLAN filtering options while in bridge */
...@@ -1146,16 +1146,18 @@ static int gswip_vlan_remove(struct gswip_priv *priv, ...@@ -1146,16 +1146,18 @@ static int gswip_vlan_remove(struct gswip_priv *priv,
} }
static int gswip_port_bridge_join(struct dsa_switch *ds, int port, static int gswip_port_bridge_join(struct dsa_switch *ds, int port,
struct net_device *bridge) struct dsa_bridge bridge,
bool *tx_fwd_offload)
{ {
struct net_device *br = bridge.dev;
struct gswip_priv *priv = ds->priv; struct gswip_priv *priv = ds->priv;
int err; int err;
/* When the bridge uses VLAN filtering we have to configure VLAN /* When the bridge uses VLAN filtering we have to configure VLAN
* specific bridges. No bridge is configured here. * specific bridges. No bridge is configured here.
*/ */
if (!br_vlan_enabled(bridge)) { if (!br_vlan_enabled(br)) {
err = gswip_vlan_add_unaware(priv, bridge, port); err = gswip_vlan_add_unaware(priv, br, port);
if (err) if (err)
return err; return err;
priv->port_vlan_filter &= ~BIT(port); priv->port_vlan_filter &= ~BIT(port);
...@@ -1166,8 +1168,9 @@ static int gswip_port_bridge_join(struct dsa_switch *ds, int port, ...@@ -1166,8 +1168,9 @@ static int gswip_port_bridge_join(struct dsa_switch *ds, int port,
} }
static void gswip_port_bridge_leave(struct dsa_switch *ds, int port, static void gswip_port_bridge_leave(struct dsa_switch *ds, int port,
struct net_device *bridge) struct dsa_bridge bridge)
{ {
struct net_device *br = bridge.dev;
struct gswip_priv *priv = ds->priv; struct gswip_priv *priv = ds->priv;
gswip_add_single_port_br(priv, port, true); gswip_add_single_port_br(priv, port, true);
...@@ -1175,16 +1178,16 @@ static void gswip_port_bridge_leave(struct dsa_switch *ds, int port, ...@@ -1175,16 +1178,16 @@ static void gswip_port_bridge_leave(struct dsa_switch *ds, int port,
/* When the bridge uses VLAN filtering we have to configure VLAN /* When the bridge uses VLAN filtering we have to configure VLAN
* specific bridges. No bridge is configured here. * specific bridges. No bridge is configured here.
*/ */
if (!br_vlan_enabled(bridge)) if (!br_vlan_enabled(br))
gswip_vlan_remove(priv, bridge, port, 0, true, false); gswip_vlan_remove(priv, br, port, 0, true, false);
} }
static int gswip_port_vlan_prepare(struct dsa_switch *ds, int port, static int gswip_port_vlan_prepare(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_vlan *vlan, const struct switchdev_obj_port_vlan *vlan,
struct netlink_ext_ack *extack) struct netlink_ext_ack *extack)
{ {
struct net_device *bridge = dsa_port_bridge_dev_get(dsa_to_port(ds, port));
struct gswip_priv *priv = ds->priv; struct gswip_priv *priv = ds->priv;
struct net_device *bridge = dsa_to_port(ds, port)->bridge_dev;
unsigned int max_ports = priv->hw_info->max_ports; unsigned int max_ports = priv->hw_info->max_ports;
int pos = max_ports; int pos = max_ports;
int i, idx = -1; int i, idx = -1;
...@@ -1229,8 +1232,8 @@ static int gswip_port_vlan_add(struct dsa_switch *ds, int port, ...@@ -1229,8 +1232,8 @@ static int gswip_port_vlan_add(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_vlan *vlan, const struct switchdev_obj_port_vlan *vlan,
struct netlink_ext_ack *extack) struct netlink_ext_ack *extack)
{ {
struct net_device *bridge = dsa_port_bridge_dev_get(dsa_to_port(ds, port));
struct gswip_priv *priv = ds->priv; struct gswip_priv *priv = ds->priv;
struct net_device *bridge = dsa_to_port(ds, port)->bridge_dev;
bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED; bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID; bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
int err; int err;
...@@ -1254,8 +1257,8 @@ static int gswip_port_vlan_add(struct dsa_switch *ds, int port, ...@@ -1254,8 +1257,8 @@ static int gswip_port_vlan_add(struct dsa_switch *ds, int port,
static int gswip_port_vlan_del(struct dsa_switch *ds, int port, static int gswip_port_vlan_del(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_vlan *vlan) const struct switchdev_obj_port_vlan *vlan)
{ {
struct net_device *bridge = dsa_port_bridge_dev_get(dsa_to_port(ds, port));
struct gswip_priv *priv = ds->priv; struct gswip_priv *priv = ds->priv;
struct net_device *bridge = dsa_to_port(ds, port)->bridge_dev;
bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID; bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
/* We have to receive all packets on the CPU port and should not /* We have to receive all packets on the CPU port and should not
...@@ -1340,8 +1343,8 @@ static void gswip_port_stp_state_set(struct dsa_switch *ds, int port, u8 state) ...@@ -1340,8 +1343,8 @@ static void gswip_port_stp_state_set(struct dsa_switch *ds, int port, u8 state)
static int gswip_port_fdb(struct dsa_switch *ds, int port, static int gswip_port_fdb(struct dsa_switch *ds, int port,
const unsigned char *addr, u16 vid, bool add) const unsigned char *addr, u16 vid, bool add)
{ {
struct net_device *bridge = dsa_port_bridge_dev_get(dsa_to_port(ds, port));
struct gswip_priv *priv = ds->priv; struct gswip_priv *priv = ds->priv;
struct net_device *bridge = dsa_to_port(ds, port)->bridge_dev;
struct gswip_pce_table_entry mac_bridge = {0,}; struct gswip_pce_table_entry mac_bridge = {0,};
unsigned int cpu_port = priv->hw_info->cpu_port; unsigned int cpu_port = priv->hw_info->cpu_port;
int fid = -1; int fid = -1;
......
...@@ -43,7 +43,7 @@ void ksz_update_port_member(struct ksz_device *dev, int port) ...@@ -43,7 +43,7 @@ void ksz_update_port_member(struct ksz_device *dev, int port)
continue; continue;
if (port == i) if (port == i)
continue; continue;
if (!dp->bridge_dev || dp->bridge_dev != other_dp->bridge_dev) if (!dsa_port_bridge_same(dp, other_dp))
continue; continue;
if (other_p->stp_state == BR_STATE_FORWARDING && if (other_p->stp_state == BR_STATE_FORWARDING &&
...@@ -192,7 +192,8 @@ void ksz_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *buf) ...@@ -192,7 +192,8 @@ void ksz_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *buf)
EXPORT_SYMBOL_GPL(ksz_get_ethtool_stats); EXPORT_SYMBOL_GPL(ksz_get_ethtool_stats);
int ksz_port_bridge_join(struct dsa_switch *ds, int port, int ksz_port_bridge_join(struct dsa_switch *ds, int port,
struct net_device *br) struct dsa_bridge bridge,
bool *tx_fwd_offload)
{ {
/* port_stp_state_set() will be called after to put the port in /* port_stp_state_set() will be called after to put the port in
* appropriate state so there is no need to do anything. * appropriate state so there is no need to do anything.
...@@ -203,7 +204,7 @@ int ksz_port_bridge_join(struct dsa_switch *ds, int port, ...@@ -203,7 +204,7 @@ int ksz_port_bridge_join(struct dsa_switch *ds, int port,
EXPORT_SYMBOL_GPL(ksz_port_bridge_join); EXPORT_SYMBOL_GPL(ksz_port_bridge_join);
void ksz_port_bridge_leave(struct dsa_switch *ds, int port, void ksz_port_bridge_leave(struct dsa_switch *ds, int port,
struct net_device *br) struct dsa_bridge bridge)
{ {
/* port_stp_state_set() will be called after to put the port in /* port_stp_state_set() will be called after to put the port in
* forwarding state so there is no need to do anything. * forwarding state so there is no need to do anything.
......
...@@ -155,9 +155,9 @@ void ksz_mac_link_down(struct dsa_switch *ds, int port, unsigned int mode, ...@@ -155,9 +155,9 @@ void ksz_mac_link_down(struct dsa_switch *ds, int port, unsigned int mode,
int ksz_sset_count(struct dsa_switch *ds, int port, int sset); int ksz_sset_count(struct dsa_switch *ds, int port, int sset);
void ksz_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *buf); void ksz_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *buf);
int ksz_port_bridge_join(struct dsa_switch *ds, int port, int ksz_port_bridge_join(struct dsa_switch *ds, int port,
struct net_device *br); struct dsa_bridge bridge, bool *tx_fwd_offload);
void ksz_port_bridge_leave(struct dsa_switch *ds, int port, void ksz_port_bridge_leave(struct dsa_switch *ds, int port,
struct net_device *br); struct dsa_bridge bridge);
void ksz_port_fast_age(struct dsa_switch *ds, int port); void ksz_port_fast_age(struct dsa_switch *ds, int port);
int ksz_port_fdb_dump(struct dsa_switch *ds, int port, dsa_fdb_dump_cb_t *cb, int ksz_port_fdb_dump(struct dsa_switch *ds, int port, dsa_fdb_dump_cb_t *cb,
void *data); void *data);
......
...@@ -1186,29 +1186,33 @@ mt7530_port_bridge_flags(struct dsa_switch *ds, int port, ...@@ -1186,29 +1186,33 @@ mt7530_port_bridge_flags(struct dsa_switch *ds, int port,
static int static int
mt7530_port_bridge_join(struct dsa_switch *ds, int port, mt7530_port_bridge_join(struct dsa_switch *ds, int port,
struct net_device *bridge) struct dsa_bridge bridge, bool *tx_fwd_offload)
{ {
struct mt7530_priv *priv = ds->priv; struct dsa_port *dp = dsa_to_port(ds, port), *other_dp;
u32 port_bitmap = BIT(MT7530_CPU_PORT); u32 port_bitmap = BIT(MT7530_CPU_PORT);
int i; struct mt7530_priv *priv = ds->priv;
mutex_lock(&priv->reg_mutex); mutex_lock(&priv->reg_mutex);
for (i = 0; i < MT7530_NUM_PORTS; i++) { dsa_switch_for_each_user_port(other_dp, ds) {
int other_port = other_dp->index;
if (dp == other_dp)
continue;
/* Add this port to the port matrix of the other ports in the /* Add this port to the port matrix of the other ports in the
* same bridge. If the port is disabled, port matrix is kept * same bridge. If the port is disabled, port matrix is kept
* and not being setup until the port becomes enabled. * and not being setup until the port becomes enabled.
*/ */
if (dsa_is_user_port(ds, i) && i != port) { if (!dsa_port_offloads_bridge(other_dp, &bridge))
if (dsa_to_port(ds, i)->bridge_dev != bridge) continue;
continue;
if (priv->ports[i].enable)
mt7530_set(priv, MT7530_PCR_P(i),
PCR_MATRIX(BIT(port)));
priv->ports[i].pm |= PCR_MATRIX(BIT(port));
port_bitmap |= BIT(i); if (priv->ports[other_port].enable)
} mt7530_set(priv, MT7530_PCR_P(other_port),
PCR_MATRIX(BIT(port)));
priv->ports[other_port].pm |= PCR_MATRIX(BIT(port));
port_bitmap |= BIT(other_port);
} }
/* Add the all other ports to this port matrix. */ /* Add the all other ports to this port matrix. */
...@@ -1236,7 +1240,7 @@ mt7530_port_set_vlan_unaware(struct dsa_switch *ds, int port) ...@@ -1236,7 +1240,7 @@ mt7530_port_set_vlan_unaware(struct dsa_switch *ds, int port)
/* This is called after .port_bridge_leave when leaving a VLAN-aware /* This is called after .port_bridge_leave when leaving a VLAN-aware
* bridge. Don't set standalone ports to fallback mode. * bridge. Don't set standalone ports to fallback mode.
*/ */
if (dsa_to_port(ds, port)->bridge_dev) if (dsa_port_bridge_dev_get(dsa_to_port(ds, port)))
mt7530_rmw(priv, MT7530_PCR_P(port), PCR_PORT_VLAN_MASK, mt7530_rmw(priv, MT7530_PCR_P(port), PCR_PORT_VLAN_MASK,
MT7530_PORT_FALLBACK_MODE); MT7530_PORT_FALLBACK_MODE);
...@@ -1299,26 +1303,30 @@ mt7530_port_set_vlan_aware(struct dsa_switch *ds, int port) ...@@ -1299,26 +1303,30 @@ mt7530_port_set_vlan_aware(struct dsa_switch *ds, int port)
static void static void
mt7530_port_bridge_leave(struct dsa_switch *ds, int port, mt7530_port_bridge_leave(struct dsa_switch *ds, int port,
struct net_device *bridge) struct dsa_bridge bridge)
{ {
struct dsa_port *dp = dsa_to_port(ds, port), *other_dp;
struct mt7530_priv *priv = ds->priv; struct mt7530_priv *priv = ds->priv;
int i;
mutex_lock(&priv->reg_mutex); mutex_lock(&priv->reg_mutex);
for (i = 0; i < MT7530_NUM_PORTS; i++) { dsa_switch_for_each_user_port(other_dp, ds) {
int other_port = other_dp->index;
if (dp == other_dp)
continue;
/* Remove this port from the port matrix of the other ports /* Remove this port from the port matrix of the other ports
* in the same bridge. If the port is disabled, port matrix * in the same bridge. If the port is disabled, port matrix
* is kept and not being setup until the port becomes enabled. * is kept and not being setup until the port becomes enabled.
*/ */
if (dsa_is_user_port(ds, i) && i != port) { if (!dsa_port_offloads_bridge(other_dp, &bridge))
if (dsa_to_port(ds, i)->bridge_dev != bridge) continue;
continue;
if (priv->ports[i].enable) if (priv->ports[other_port].enable)
mt7530_clear(priv, MT7530_PCR_P(i), mt7530_clear(priv, MT7530_PCR_P(other_port),
PCR_MATRIX(BIT(port))); PCR_MATRIX(BIT(port)));
priv->ports[i].pm &= ~PCR_MATRIX(BIT(port)); priv->ports[other_port].pm &= ~PCR_MATRIX(BIT(port));
}
} }
/* Set the cpu port to be the only one in the port matrix of /* Set the cpu port to be the only one in the port matrix of
......
...@@ -1228,8 +1228,7 @@ static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port) ...@@ -1228,8 +1228,7 @@ static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
{ {
struct dsa_switch *ds = chip->ds; struct dsa_switch *ds = chip->ds;
struct dsa_switch_tree *dst = ds->dst; struct dsa_switch_tree *dst = ds->dst;
struct net_device *br; struct dsa_port *dp, *other_dp;
struct dsa_port *dp;
bool found = false; bool found = false;
u16 pvlan; u16 pvlan;
...@@ -1238,11 +1237,9 @@ static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port) ...@@ -1238,11 +1237,9 @@ static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
list_for_each_entry(dp, &dst->ports, list) { list_for_each_entry(dp, &dst->ports, list) {
if (dp->ds->index == dev && dp->index == port) { if (dp->ds->index == dev && dp->index == port) {
/* dp might be a DSA link or a user port, so it /* dp might be a DSA link or a user port, so it
* might or might not have a bridge_dev * might or might not have a bridge.
* pointer. Use the "found" variable for both * Use the "found" variable for both cases.
* cases.
*/ */
br = dp->bridge_dev;
found = true; found = true;
break; break;
} }
...@@ -1250,13 +1247,14 @@ static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port) ...@@ -1250,13 +1247,14 @@ static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
/* dev is a virtual bridge */ /* dev is a virtual bridge */
} else { } else {
list_for_each_entry(dp, &dst->ports, list) { list_for_each_entry(dp, &dst->ports, list) {
if (dp->bridge_num < 0) unsigned int bridge_num = dsa_port_bridge_num_get(dp);
if (!bridge_num)
continue; continue;
if (dp->bridge_num + 1 + dst->last_switch != dev) if (bridge_num + dst->last_switch != dev)
continue; continue;
br = dp->bridge_dev;
found = true; found = true;
break; break;
} }
...@@ -1275,12 +1273,11 @@ static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port) ...@@ -1275,12 +1273,11 @@ static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
/* Frames from user ports can egress any local DSA links and CPU ports, /* Frames from user ports can egress any local DSA links and CPU ports,
* as well as any local member of their bridge group. * as well as any local member of their bridge group.
*/ */
list_for_each_entry(dp, &dst->ports, list) dsa_switch_for_each_port(other_dp, ds)
if (dp->ds == ds && if (other_dp->type == DSA_PORT_TYPE_CPU ||
(dp->type == DSA_PORT_TYPE_CPU || other_dp->type == DSA_PORT_TYPE_DSA ||
dp->type == DSA_PORT_TYPE_DSA || dsa_port_bridge_same(dp, other_dp))
(br && dp->bridge_dev == br))) pvlan |= BIT(other_dp->index);
pvlan |= BIT(dp->index);
return pvlan; return pvlan;
} }
...@@ -1647,12 +1644,13 @@ static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid) ...@@ -1647,12 +1644,13 @@ static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port, static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
u16 vid) u16 vid)
{ {
struct dsa_port *dp = dsa_to_port(ds, port), *other_dp;
struct mv88e6xxx_chip *chip = ds->priv; struct mv88e6xxx_chip *chip = ds->priv;
struct mv88e6xxx_vtu_entry vlan; struct mv88e6xxx_vtu_entry vlan;
int i, err; int err;
/* DSA and CPU ports have to be members of multiple vlans */ /* DSA and CPU ports have to be members of multiple vlans */
if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port)) if (dsa_port_is_dsa(dp) || dsa_port_is_cpu(dp))
return 0; return 0;
err = mv88e6xxx_vtu_get(chip, vid, &vlan); err = mv88e6xxx_vtu_get(chip, vid, &vlan);
...@@ -1662,27 +1660,22 @@ static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port, ...@@ -1662,27 +1660,22 @@ static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
if (!vlan.valid) if (!vlan.valid)
return 0; return 0;
for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) { dsa_switch_for_each_user_port(other_dp, ds) {
if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i)) struct net_device *other_br;
continue;
if (!dsa_to_port(ds, i)->slave) if (vlan.member[other_dp->index] ==
continue;
if (vlan.member[i] ==
MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
continue; continue;
if (dsa_to_port(ds, i)->bridge_dev == if (dsa_port_bridge_same(dp, other_dp))
dsa_to_port(ds, port)->bridge_dev)
break; /* same bridge, check next VLAN */ break; /* same bridge, check next VLAN */
if (!dsa_to_port(ds, i)->bridge_dev) other_br = dsa_port_bridge_dev_get(other_dp);
if (!other_br)
continue; continue;
dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n", dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n",
port, vlan.vid, i, port, vlan.vid, other_dp->index, netdev_name(other_br));
netdev_name(dsa_to_port(ds, i)->bridge_dev));
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
...@@ -1692,13 +1685,14 @@ static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port, ...@@ -1692,13 +1685,14 @@ static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
static int mv88e6xxx_port_commit_pvid(struct mv88e6xxx_chip *chip, int port) static int mv88e6xxx_port_commit_pvid(struct mv88e6xxx_chip *chip, int port)
{ {
struct dsa_port *dp = dsa_to_port(chip->ds, port); struct dsa_port *dp = dsa_to_port(chip->ds, port);
struct net_device *br = dsa_port_bridge_dev_get(dp);
struct mv88e6xxx_port *p = &chip->ports[port]; struct mv88e6xxx_port *p = &chip->ports[port];
u16 pvid = MV88E6XXX_VID_STANDALONE; u16 pvid = MV88E6XXX_VID_STANDALONE;
bool drop_untagged = false; bool drop_untagged = false;
int err; int err;
if (dp->bridge_dev) { if (br) {
if (br_vlan_enabled(dp->bridge_dev)) { if (br_vlan_enabled(br)) {
pvid = p->bridge_pvid.vid; pvid = p->bridge_pvid.vid;
drop_untagged = !p->bridge_pvid.valid; drop_untagged = !p->bridge_pvid.valid;
} else { } else {
...@@ -2416,7 +2410,7 @@ static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port, ...@@ -2416,7 +2410,7 @@ static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
} }
static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip, static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
struct net_device *br) struct dsa_bridge bridge)
{ {
struct dsa_switch *ds = chip->ds; struct dsa_switch *ds = chip->ds;
struct dsa_switch_tree *dst = ds->dst; struct dsa_switch_tree *dst = ds->dst;
...@@ -2424,7 +2418,7 @@ static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip, ...@@ -2424,7 +2418,7 @@ static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
int err; int err;
list_for_each_entry(dp, &dst->ports, list) { list_for_each_entry(dp, &dst->ports, list) {
if (dp->bridge_dev == br) { if (dsa_port_offloads_bridge(dp, &bridge)) {
if (dp->ds == ds) { if (dp->ds == ds) {
/* This is a local bridge group member, /* This is a local bridge group member,
* remap its Port VLAN Map. * remap its Port VLAN Map.
...@@ -2447,15 +2441,29 @@ static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip, ...@@ -2447,15 +2441,29 @@ static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
return 0; return 0;
} }
/* Treat the software bridge as a virtual single-port switch behind the
* CPU and map in the PVT. First dst->last_switch elements are taken by
* physical switches, so start from beyond that range.
*/
static int mv88e6xxx_map_virtual_bridge_to_pvt(struct dsa_switch *ds,
unsigned int bridge_num)
{
u8 dev = bridge_num + ds->dst->last_switch;
struct mv88e6xxx_chip *chip = ds->priv;
return mv88e6xxx_pvt_map(chip, dev, 0);
}
static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port, static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
struct net_device *br) struct dsa_bridge bridge,
bool *tx_fwd_offload)
{ {
struct mv88e6xxx_chip *chip = ds->priv; struct mv88e6xxx_chip *chip = ds->priv;
int err; int err;
mv88e6xxx_reg_lock(chip); mv88e6xxx_reg_lock(chip);
err = mv88e6xxx_bridge_map(chip, br); err = mv88e6xxx_bridge_map(chip, bridge);
if (err) if (err)
goto unlock; goto unlock;
...@@ -2463,6 +2471,14 @@ static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port, ...@@ -2463,6 +2471,14 @@ static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
if (err) if (err)
goto unlock; goto unlock;
if (mv88e6xxx_has_pvt(chip)) {
err = mv88e6xxx_map_virtual_bridge_to_pvt(ds, bridge.num);
if (err)
goto unlock;
*tx_fwd_offload = true;
}
unlock: unlock:
mv88e6xxx_reg_unlock(chip); mv88e6xxx_reg_unlock(chip);
...@@ -2470,14 +2486,18 @@ static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port, ...@@ -2470,14 +2486,18 @@ static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
} }
static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port, static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
struct net_device *br) struct dsa_bridge bridge)
{ {
struct mv88e6xxx_chip *chip = ds->priv; struct mv88e6xxx_chip *chip = ds->priv;
int err; int err;
mv88e6xxx_reg_lock(chip); mv88e6xxx_reg_lock(chip);
if (mv88e6xxx_bridge_map(chip, br) || if (bridge.tx_fwd_offload &&
mv88e6xxx_map_virtual_bridge_to_pvt(ds, bridge.num))
dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n");
if (mv88e6xxx_bridge_map(chip, bridge) ||
mv88e6xxx_port_vlan_map(chip, port)) mv88e6xxx_port_vlan_map(chip, port))
dev_err(ds->dev, "failed to remap in-chip Port VLAN\n"); dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
...@@ -2492,7 +2512,7 @@ static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port, ...@@ -2492,7 +2512,7 @@ static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
static int mv88e6xxx_crosschip_bridge_join(struct dsa_switch *ds, static int mv88e6xxx_crosschip_bridge_join(struct dsa_switch *ds,
int tree_index, int sw_index, int tree_index, int sw_index,
int port, struct net_device *br) int port, struct dsa_bridge bridge)
{ {
struct mv88e6xxx_chip *chip = ds->priv; struct mv88e6xxx_chip *chip = ds->priv;
int err; int err;
...@@ -2509,7 +2529,7 @@ static int mv88e6xxx_crosschip_bridge_join(struct dsa_switch *ds, ...@@ -2509,7 +2529,7 @@ static int mv88e6xxx_crosschip_bridge_join(struct dsa_switch *ds,
static void mv88e6xxx_crosschip_bridge_leave(struct dsa_switch *ds, static void mv88e6xxx_crosschip_bridge_leave(struct dsa_switch *ds,
int tree_index, int sw_index, int tree_index, int sw_index,
int port, struct net_device *br) int port, struct dsa_bridge bridge)
{ {
struct mv88e6xxx_chip *chip = ds->priv; struct mv88e6xxx_chip *chip = ds->priv;
...@@ -2522,44 +2542,6 @@ static void mv88e6xxx_crosschip_bridge_leave(struct dsa_switch *ds, ...@@ -2522,44 +2542,6 @@ static void mv88e6xxx_crosschip_bridge_leave(struct dsa_switch *ds,
mv88e6xxx_reg_unlock(chip); mv88e6xxx_reg_unlock(chip);
} }
/* Treat the software bridge as a virtual single-port switch behind the
* CPU and map in the PVT. First dst->last_switch elements are taken by
* physical switches, so start from beyond that range.
*/
static int mv88e6xxx_map_virtual_bridge_to_pvt(struct dsa_switch *ds,
int bridge_num)
{
u8 dev = bridge_num + ds->dst->last_switch + 1;
struct mv88e6xxx_chip *chip = ds->priv;
int err;
mv88e6xxx_reg_lock(chip);
err = mv88e6xxx_pvt_map(chip, dev, 0);
mv88e6xxx_reg_unlock(chip);
return err;
}
static int mv88e6xxx_bridge_tx_fwd_offload(struct dsa_switch *ds, int port,
struct net_device *br,
int bridge_num)
{
return mv88e6xxx_map_virtual_bridge_to_pvt(ds, bridge_num);
}
static void mv88e6xxx_bridge_tx_fwd_unoffload(struct dsa_switch *ds, int port,
struct net_device *br,
int bridge_num)
{
int err;
err = mv88e6xxx_map_virtual_bridge_to_pvt(ds, bridge_num);
if (err) {
dev_err(ds->dev, "failed to remap cross-chip Port VLAN: %pe\n",
ERR_PTR(err));
}
}
static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip) static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
{ {
if (chip->info->ops->reset) if (chip->info->ops->reset)
...@@ -3186,8 +3168,8 @@ static int mv88e6xxx_setup(struct dsa_switch *ds) ...@@ -3186,8 +3168,8 @@ static int mv88e6xxx_setup(struct dsa_switch *ds)
* time. * time.
*/ */
if (mv88e6xxx_has_pvt(chip)) if (mv88e6xxx_has_pvt(chip))
ds->num_fwd_offloading_bridges = MV88E6XXX_MAX_PVT_SWITCHES - ds->max_num_bridges = MV88E6XXX_MAX_PVT_SWITCHES -
ds->dst->last_switch - 1; ds->dst->last_switch - 1;
mv88e6xxx_reg_lock(chip); mv88e6xxx_reg_lock(chip);
...@@ -6279,8 +6261,6 @@ static const struct dsa_switch_ops mv88e6xxx_switch_ops = { ...@@ -6279,8 +6261,6 @@ static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
.crosschip_lag_change = mv88e6xxx_crosschip_lag_change, .crosschip_lag_change = mv88e6xxx_crosschip_lag_change,
.crosschip_lag_join = mv88e6xxx_crosschip_lag_join, .crosschip_lag_join = mv88e6xxx_crosschip_lag_join,
.crosschip_lag_leave = mv88e6xxx_crosschip_lag_leave, .crosschip_lag_leave = mv88e6xxx_crosschip_lag_leave,
.port_bridge_tx_fwd_offload = mv88e6xxx_bridge_tx_fwd_offload,
.port_bridge_tx_fwd_unoffload = mv88e6xxx_bridge_tx_fwd_unoffload,
}; };
static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip) static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
......
...@@ -706,21 +706,21 @@ static int felix_bridge_flags(struct dsa_switch *ds, int port, ...@@ -706,21 +706,21 @@ static int felix_bridge_flags(struct dsa_switch *ds, int port,
} }
static int felix_bridge_join(struct dsa_switch *ds, int port, static int felix_bridge_join(struct dsa_switch *ds, int port,
struct net_device *br) struct dsa_bridge bridge, bool *tx_fwd_offload)
{ {
struct ocelot *ocelot = ds->priv; struct ocelot *ocelot = ds->priv;
ocelot_port_bridge_join(ocelot, port, br); ocelot_port_bridge_join(ocelot, port, bridge.dev);
return 0; return 0;
} }
static void felix_bridge_leave(struct dsa_switch *ds, int port, static void felix_bridge_leave(struct dsa_switch *ds, int port,
struct net_device *br) struct dsa_bridge bridge)
{ {
struct ocelot *ocelot = ds->priv; struct ocelot *ocelot = ds->priv;
ocelot_port_bridge_leave(ocelot, port, br); ocelot_port_bridge_leave(ocelot, port, bridge.dev);
} }
static int felix_lag_join(struct dsa_switch *ds, int port, static int felix_lag_join(struct dsa_switch *ds, int port,
......
...@@ -1810,8 +1810,9 @@ qca8k_port_stp_state_set(struct dsa_switch *ds, int port, u8 state) ...@@ -1810,8 +1810,9 @@ qca8k_port_stp_state_set(struct dsa_switch *ds, int port, u8 state)
QCA8K_PORT_LOOKUP_STATE_MASK, stp_state); QCA8K_PORT_LOOKUP_STATE_MASK, stp_state);
} }
static int static int qca8k_port_bridge_join(struct dsa_switch *ds, int port,
qca8k_port_bridge_join(struct dsa_switch *ds, int port, struct net_device *br) struct dsa_bridge bridge,
bool *tx_fwd_offload)
{ {
struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv; struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv;
int port_mask, cpu_port; int port_mask, cpu_port;
...@@ -1823,7 +1824,7 @@ qca8k_port_bridge_join(struct dsa_switch *ds, int port, struct net_device *br) ...@@ -1823,7 +1824,7 @@ qca8k_port_bridge_join(struct dsa_switch *ds, int port, struct net_device *br)
for (i = 0; i < QCA8K_NUM_PORTS; i++) { for (i = 0; i < QCA8K_NUM_PORTS; i++) {
if (dsa_is_cpu_port(ds, i)) if (dsa_is_cpu_port(ds, i))
continue; continue;
if (dsa_to_port(ds, i)->bridge_dev != br) if (!dsa_port_offloads_bridge(dsa_to_port(ds, i), &bridge))
continue; continue;
/* Add this port to the portvlan mask of the other ports /* Add this port to the portvlan mask of the other ports
* in the bridge * in the bridge
...@@ -1844,8 +1845,8 @@ qca8k_port_bridge_join(struct dsa_switch *ds, int port, struct net_device *br) ...@@ -1844,8 +1845,8 @@ qca8k_port_bridge_join(struct dsa_switch *ds, int port, struct net_device *br)
return ret; return ret;
} }
static void static void qca8k_port_bridge_leave(struct dsa_switch *ds, int port,
qca8k_port_bridge_leave(struct dsa_switch *ds, int port, struct net_device *br) struct dsa_bridge bridge)
{ {
struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv; struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv;
int cpu_port, i; int cpu_port, i;
...@@ -1855,7 +1856,7 @@ qca8k_port_bridge_leave(struct dsa_switch *ds, int port, struct net_device *br) ...@@ -1855,7 +1856,7 @@ qca8k_port_bridge_leave(struct dsa_switch *ds, int port, struct net_device *br)
for (i = 0; i < QCA8K_NUM_PORTS; i++) { for (i = 0; i < QCA8K_NUM_PORTS; i++) {
if (dsa_is_cpu_port(ds, i)) if (dsa_is_cpu_port(ds, i))
continue; continue;
if (dsa_to_port(ds, i)->bridge_dev != br) if (!dsa_port_offloads_bridge(dsa_to_port(ds, i), &bridge))
continue; continue;
/* Remove this port to the portvlan mask of the other ports /* Remove this port to the portvlan mask of the other ports
* in the bridge * in the bridge
......
...@@ -1186,7 +1186,8 @@ rtl8366rb_port_disable(struct dsa_switch *ds, int port) ...@@ -1186,7 +1186,8 @@ rtl8366rb_port_disable(struct dsa_switch *ds, int port)
static int static int
rtl8366rb_port_bridge_join(struct dsa_switch *ds, int port, rtl8366rb_port_bridge_join(struct dsa_switch *ds, int port,
struct net_device *bridge) struct dsa_bridge bridge,
bool *tx_fwd_offload)
{ {
struct realtek_smi *smi = ds->priv; struct realtek_smi *smi = ds->priv;
unsigned int port_bitmap = 0; unsigned int port_bitmap = 0;
...@@ -1198,7 +1199,7 @@ rtl8366rb_port_bridge_join(struct dsa_switch *ds, int port, ...@@ -1198,7 +1199,7 @@ rtl8366rb_port_bridge_join(struct dsa_switch *ds, int port,
if (i == port) if (i == port)
continue; continue;
/* Not on this bridge */ /* Not on this bridge */
if (dsa_to_port(ds, i)->bridge_dev != bridge) if (!dsa_port_offloads_bridge(dsa_to_port(ds, i), &bridge))
continue; continue;
/* Join this port to each other port on the bridge */ /* Join this port to each other port on the bridge */
ret = regmap_update_bits(smi->map, RTL8366RB_PORT_ISO(i), ret = regmap_update_bits(smi->map, RTL8366RB_PORT_ISO(i),
...@@ -1218,7 +1219,7 @@ rtl8366rb_port_bridge_join(struct dsa_switch *ds, int port, ...@@ -1218,7 +1219,7 @@ rtl8366rb_port_bridge_join(struct dsa_switch *ds, int port,
static void static void
rtl8366rb_port_bridge_leave(struct dsa_switch *ds, int port, rtl8366rb_port_bridge_leave(struct dsa_switch *ds, int port,
struct net_device *bridge) struct dsa_bridge bridge)
{ {
struct realtek_smi *smi = ds->priv; struct realtek_smi *smi = ds->priv;
unsigned int port_bitmap = 0; unsigned int port_bitmap = 0;
...@@ -1230,7 +1231,7 @@ rtl8366rb_port_bridge_leave(struct dsa_switch *ds, int port, ...@@ -1230,7 +1231,7 @@ rtl8366rb_port_bridge_leave(struct dsa_switch *ds, int port,
if (i == port) if (i == port)
continue; continue;
/* Not on this bridge */ /* Not on this bridge */
if (dsa_to_port(ds, i)->bridge_dev != bridge) if (!dsa_port_offloads_bridge(dsa_to_port(ds, i), &bridge))
continue; continue;
/* Remove this port from any other port on the bridge */ /* Remove this port from any other port on the bridge */
ret = regmap_update_bits(smi->map, RTL8366RB_PORT_ISO(i), ret = regmap_update_bits(smi->map, RTL8366RB_PORT_ISO(i),
......
...@@ -118,13 +118,14 @@ static int sja1105_pvid_apply(struct sja1105_private *priv, int port, u16 pvid) ...@@ -118,13 +118,14 @@ static int sja1105_pvid_apply(struct sja1105_private *priv, int port, u16 pvid)
static int sja1105_commit_pvid(struct dsa_switch *ds, int port) static int sja1105_commit_pvid(struct dsa_switch *ds, int port)
{ {
struct dsa_port *dp = dsa_to_port(ds, port); struct dsa_port *dp = dsa_to_port(ds, port);
struct net_device *br = dsa_port_bridge_dev_get(dp);
struct sja1105_private *priv = ds->priv; struct sja1105_private *priv = ds->priv;
struct sja1105_vlan_lookup_entry *vlan; struct sja1105_vlan_lookup_entry *vlan;
bool drop_untagged = false; bool drop_untagged = false;
int match, rc; int match, rc;
u16 pvid; u16 pvid;
if (dp->bridge_dev && br_vlan_enabled(dp->bridge_dev)) if (br && br_vlan_enabled(br))
pvid = priv->bridge_pvid[port]; pvid = priv->bridge_pvid[port];
else else
pvid = priv->tag_8021q_pvid[port]; pvid = priv->tag_8021q_pvid[port];
...@@ -1979,7 +1980,7 @@ static int sja1105_manage_flood_domains(struct sja1105_private *priv) ...@@ -1979,7 +1980,7 @@ static int sja1105_manage_flood_domains(struct sja1105_private *priv)
} }
static int sja1105_bridge_member(struct dsa_switch *ds, int port, static int sja1105_bridge_member(struct dsa_switch *ds, int port,
struct net_device *br, bool member) struct dsa_bridge bridge, bool member)
{ {
struct sja1105_l2_forwarding_entry *l2_fwd; struct sja1105_l2_forwarding_entry *l2_fwd;
struct sja1105_private *priv = ds->priv; struct sja1105_private *priv = ds->priv;
...@@ -2004,7 +2005,7 @@ static int sja1105_bridge_member(struct dsa_switch *ds, int port, ...@@ -2004,7 +2005,7 @@ static int sja1105_bridge_member(struct dsa_switch *ds, int port,
*/ */
if (i == port) if (i == port)
continue; continue;
if (dsa_to_port(ds, i)->bridge_dev != br) if (!dsa_port_offloads_bridge(dsa_to_port(ds, i), &bridge))
continue; continue;
sja1105_port_allow_traffic(l2_fwd, i, port, member); sja1105_port_allow_traffic(l2_fwd, i, port, member);
sja1105_port_allow_traffic(l2_fwd, port, i, member); sja1105_port_allow_traffic(l2_fwd, port, i, member);
...@@ -2073,15 +2074,31 @@ static void sja1105_bridge_stp_state_set(struct dsa_switch *ds, int port, ...@@ -2073,15 +2074,31 @@ static void sja1105_bridge_stp_state_set(struct dsa_switch *ds, int port,
} }
static int sja1105_bridge_join(struct dsa_switch *ds, int port, static int sja1105_bridge_join(struct dsa_switch *ds, int port,
struct net_device *br) struct dsa_bridge bridge,
bool *tx_fwd_offload)
{ {
return sja1105_bridge_member(ds, port, br, true); int rc;
rc = sja1105_bridge_member(ds, port, bridge, true);
if (rc)
return rc;
rc = dsa_tag_8021q_bridge_tx_fwd_offload(ds, port, bridge);
if (rc) {
sja1105_bridge_member(ds, port, bridge, false);
return rc;
}
*tx_fwd_offload = true;
return 0;
} }
static void sja1105_bridge_leave(struct dsa_switch *ds, int port, static void sja1105_bridge_leave(struct dsa_switch *ds, int port,
struct net_device *br) struct dsa_bridge bridge)
{ {
sja1105_bridge_member(ds, port, br, false); dsa_tag_8021q_bridge_tx_fwd_unoffload(ds, port, bridge);
sja1105_bridge_member(ds, port, bridge, false);
} }
#define BYTES_PER_KBIT (1000LL / 8) #define BYTES_PER_KBIT (1000LL / 8)
...@@ -2587,8 +2604,9 @@ static int sja1105_prechangeupper(struct dsa_switch *ds, int port, ...@@ -2587,8 +2604,9 @@ static int sja1105_prechangeupper(struct dsa_switch *ds, int port,
if (netif_is_bridge_master(upper)) { if (netif_is_bridge_master(upper)) {
list_for_each_entry(dp, &dst->ports, list) { list_for_each_entry(dp, &dst->ports, list) {
if (dp->bridge_dev && dp->bridge_dev != upper && struct net_device *br = dsa_port_bridge_dev_get(dp);
br_vlan_enabled(dp->bridge_dev)) {
if (br && br != upper && br_vlan_enabled(br)) {
NL_SET_ERR_MSG_MOD(extack, NL_SET_ERR_MSG_MOD(extack,
"Only one VLAN-aware bridge is supported"); "Only one VLAN-aware bridge is supported");
return -EBUSY; return -EBUSY;
...@@ -3139,7 +3157,7 @@ static int sja1105_setup(struct dsa_switch *ds) ...@@ -3139,7 +3157,7 @@ static int sja1105_setup(struct dsa_switch *ds)
ds->vlan_filtering_is_global = true; ds->vlan_filtering_is_global = true;
ds->untag_bridge_pvid = true; ds->untag_bridge_pvid = true;
/* tag_8021q has 3 bits for the VBID, and the value 0 is reserved */ /* tag_8021q has 3 bits for the VBID, and the value 0 is reserved */
ds->num_fwd_offloading_bridges = 7; ds->max_num_bridges = 7;
/* Advertise the 8 egress queues */ /* Advertise the 8 egress queues */
ds->num_tx_queues = SJA1105_NUM_TC; ds->num_tx_queues = SJA1105_NUM_TC;
...@@ -3228,8 +3246,6 @@ static const struct dsa_switch_ops sja1105_switch_ops = { ...@@ -3228,8 +3246,6 @@ static const struct dsa_switch_ops sja1105_switch_ops = {
.tag_8021q_vlan_add = sja1105_dsa_8021q_vlan_add, .tag_8021q_vlan_add = sja1105_dsa_8021q_vlan_add,
.tag_8021q_vlan_del = sja1105_dsa_8021q_vlan_del, .tag_8021q_vlan_del = sja1105_dsa_8021q_vlan_del,
.port_prechangeupper = sja1105_prechangeupper, .port_prechangeupper = sja1105_prechangeupper,
.port_bridge_tx_fwd_offload = dsa_tag_8021q_bridge_tx_fwd_offload,
.port_bridge_tx_fwd_unoffload = dsa_tag_8021q_bridge_tx_fwd_unoffload,
}; };
static const struct of_device_id sja1105_dt_ids[]; static const struct of_device_id sja1105_dt_ids[];
......
...@@ -501,7 +501,7 @@ static void xrs700x_mac_link_up(struct dsa_switch *ds, int port, ...@@ -501,7 +501,7 @@ static void xrs700x_mac_link_up(struct dsa_switch *ds, int port,
} }
static int xrs700x_bridge_common(struct dsa_switch *ds, int port, static int xrs700x_bridge_common(struct dsa_switch *ds, int port,
struct net_device *bridge, bool join) struct dsa_bridge bridge, bool join)
{ {
unsigned int i, cpu_mask = 0, mask = 0; unsigned int i, cpu_mask = 0, mask = 0;
struct xrs700x *priv = ds->priv; struct xrs700x *priv = ds->priv;
...@@ -513,14 +513,14 @@ static int xrs700x_bridge_common(struct dsa_switch *ds, int port, ...@@ -513,14 +513,14 @@ static int xrs700x_bridge_common(struct dsa_switch *ds, int port,
cpu_mask |= BIT(i); cpu_mask |= BIT(i);
if (dsa_to_port(ds, i)->bridge_dev == bridge) if (dsa_port_offloads_bridge(dsa_to_port(ds, i), &bridge))
continue; continue;
mask |= BIT(i); mask |= BIT(i);
} }
for (i = 0; i < ds->num_ports; i++) { for (i = 0; i < ds->num_ports; i++) {
if (dsa_to_port(ds, i)->bridge_dev != bridge) if (!dsa_port_offloads_bridge(dsa_to_port(ds, i), &bridge))
continue; continue;
/* 1 = Disable forwarding to the port */ /* 1 = Disable forwarding to the port */
...@@ -540,13 +540,13 @@ static int xrs700x_bridge_common(struct dsa_switch *ds, int port, ...@@ -540,13 +540,13 @@ static int xrs700x_bridge_common(struct dsa_switch *ds, int port,
} }
static int xrs700x_bridge_join(struct dsa_switch *ds, int port, static int xrs700x_bridge_join(struct dsa_switch *ds, int port,
struct net_device *bridge) struct dsa_bridge bridge, bool *tx_fwd_offload)
{ {
return xrs700x_bridge_common(ds, port, bridge, true); return xrs700x_bridge_common(ds, port, bridge, true);
} }
static void xrs700x_bridge_leave(struct dsa_switch *ds, int port, static void xrs700x_bridge_leave(struct dsa_switch *ds, int port,
struct net_device *bridge) struct dsa_bridge bridge)
{ {
xrs700x_bridge_common(ds, port, bridge, false); xrs700x_bridge_common(ds, port, bridge, false);
} }
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <linux/refcount.h> #include <linux/refcount.h>
#include <linux/types.h> #include <linux/types.h>
#include <net/dsa.h>
struct dsa_switch; struct dsa_switch;
struct dsa_port; struct dsa_port;
...@@ -37,14 +38,12 @@ struct sk_buff *dsa_8021q_xmit(struct sk_buff *skb, struct net_device *netdev, ...@@ -37,14 +38,12 @@ struct sk_buff *dsa_8021q_xmit(struct sk_buff *skb, struct net_device *netdev,
void dsa_8021q_rcv(struct sk_buff *skb, int *source_port, int *switch_id); void dsa_8021q_rcv(struct sk_buff *skb, int *source_port, int *switch_id);
int dsa_tag_8021q_bridge_tx_fwd_offload(struct dsa_switch *ds, int port, int dsa_tag_8021q_bridge_tx_fwd_offload(struct dsa_switch *ds, int port,
struct net_device *br, struct dsa_bridge bridge);
int bridge_num);
void dsa_tag_8021q_bridge_tx_fwd_unoffload(struct dsa_switch *ds, int port, void dsa_tag_8021q_bridge_tx_fwd_unoffload(struct dsa_switch *ds, int port,
struct net_device *br, struct dsa_bridge bridge);
int bridge_num);
u16 dsa_8021q_bridge_tx_fwd_offload_vid(int bridge_num); u16 dsa_8021q_bridge_tx_fwd_offload_vid(unsigned int bridge_num);
u16 dsa_tag_8021q_tx_vid(const struct dsa_port *dp); u16 dsa_tag_8021q_tx_vid(const struct dsa_port *dp);
......
...@@ -219,6 +219,12 @@ struct dsa_mall_tc_entry { ...@@ -219,6 +219,12 @@ struct dsa_mall_tc_entry {
}; };
}; };
struct dsa_bridge {
struct net_device *dev;
unsigned int num;
bool tx_fwd_offload;
refcount_t refcount;
};
struct dsa_port { struct dsa_port {
/* A CPU port is physically connected to a master device. /* A CPU port is physically connected to a master device.
...@@ -256,8 +262,7 @@ struct dsa_port { ...@@ -256,8 +262,7 @@ struct dsa_port {
/* Managed by DSA on user ports and by drivers on CPU and DSA ports */ /* Managed by DSA on user ports and by drivers on CPU and DSA ports */
bool learning; bool learning;
u8 stp_state; u8 stp_state;
struct net_device *bridge_dev; struct dsa_bridge *bridge;
int bridge_num;
struct devlink_port devlink_port; struct devlink_port devlink_port;
bool devlink_port_setup; bool devlink_port_setup;
struct phylink *pl; struct phylink *pl;
...@@ -413,12 +418,12 @@ struct dsa_switch { ...@@ -413,12 +418,12 @@ 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 or FDB isolation
* the maximum number of bridges spanning the same switch tree (or all * should set this to the maximum number of bridges spanning the same
* trees, in the case of cross-tree bridging support) that can be * switch tree (or all trees, in the case of cross-tree bridging
* offloaded. * support) that can be offloaded.
*/ */
unsigned int num_fwd_offloading_bridges; unsigned int max_num_bridges;
size_t num_ports; size_t num_ports;
}; };
...@@ -588,7 +593,7 @@ static inline bool dsa_port_is_vlan_filtering(const struct dsa_port *dp) ...@@ -588,7 +593,7 @@ static inline bool dsa_port_is_vlan_filtering(const struct dsa_port *dp)
static inline static inline
struct net_device *dsa_port_to_bridge_port(const struct dsa_port *dp) struct net_device *dsa_port_to_bridge_port(const struct dsa_port *dp)
{ {
if (!dp->bridge_dev) if (!dp->bridge)
return NULL; return NULL;
if (dp->lag_dev) if (dp->lag_dev)
...@@ -599,6 +604,76 @@ struct net_device *dsa_port_to_bridge_port(const struct dsa_port *dp) ...@@ -599,6 +604,76 @@ struct net_device *dsa_port_to_bridge_port(const struct dsa_port *dp)
return dp->slave; return dp->slave;
} }
static inline struct net_device *
dsa_port_bridge_dev_get(const struct dsa_port *dp)
{
return dp->bridge ? dp->bridge->dev : NULL;
}
static inline unsigned int dsa_port_bridge_num_get(struct dsa_port *dp)
{
return dp->bridge ? dp->bridge->num : 0;
}
static inline bool dsa_port_bridge_same(const struct dsa_port *a,
const struct dsa_port *b)
{
struct net_device *br_a = dsa_port_bridge_dev_get(a);
struct net_device *br_b = dsa_port_bridge_dev_get(b);
/* Standalone ports are not in the same bridge with one another */
return (!br_a || !br_b) ? false : (br_a == br_b);
}
static inline bool dsa_port_offloads_bridge_port(struct dsa_port *dp,
const struct net_device *dev)
{
return dsa_port_to_bridge_port(dp) == dev;
}
static inline bool
dsa_port_offloads_bridge_dev(struct dsa_port *dp,
const struct net_device *bridge_dev)
{
/* DSA ports connected to a bridge, and event was emitted
* for the bridge.
*/
return dsa_port_bridge_dev_get(dp) == bridge_dev;
}
static inline bool dsa_port_offloads_bridge(struct dsa_port *dp,
const struct dsa_bridge *bridge)
{
return dsa_port_bridge_dev_get(dp) == bridge->dev;
}
/* Returns true if any port of this tree offloads the given net_device */
static inline bool dsa_tree_offloads_bridge_port(struct dsa_switch_tree *dst,
const struct net_device *dev)
{
struct dsa_port *dp;
list_for_each_entry(dp, &dst->ports, list)
if (dsa_port_offloads_bridge_port(dp, dev))
return true;
return false;
}
/* Returns true if any port of this tree offloads the given bridge */
static inline bool
dsa_tree_offloads_bridge_dev(struct dsa_switch_tree *dst,
const struct net_device *bridge_dev)
{
struct dsa_port *dp;
list_for_each_entry(dp, &dst->ports, list)
if (dsa_port_offloads_bridge_dev(dp, bridge_dev))
return true;
return false;
}
typedef int dsa_fdb_dump_cb_t(const unsigned char *addr, u16 vid, typedef int dsa_fdb_dump_cb_t(const unsigned char *addr, u16 vid,
bool is_static, void *data); bool is_static, void *data);
struct dsa_switch_ops { struct dsa_switch_ops {
...@@ -748,17 +823,10 @@ struct dsa_switch_ops { ...@@ -748,17 +823,10 @@ struct dsa_switch_ops {
*/ */
int (*set_ageing_time)(struct dsa_switch *ds, unsigned int msecs); int (*set_ageing_time)(struct dsa_switch *ds, unsigned int msecs);
int (*port_bridge_join)(struct dsa_switch *ds, int port, int (*port_bridge_join)(struct dsa_switch *ds, int port,
struct net_device *bridge); struct dsa_bridge bridge,
bool *tx_fwd_offload);
void (*port_bridge_leave)(struct dsa_switch *ds, int port, void (*port_bridge_leave)(struct dsa_switch *ds, int port,
struct net_device *bridge); struct dsa_bridge bridge);
/* Called right after .port_bridge_join() */
int (*port_bridge_tx_fwd_offload)(struct dsa_switch *ds, int port,
struct net_device *bridge,
int bridge_num);
/* Called right before .port_bridge_leave() */
void (*port_bridge_tx_fwd_unoffload)(struct dsa_switch *ds, int port,
struct net_device *bridge,
int bridge_num);
void (*port_stp_state_set)(struct dsa_switch *ds, int port, void (*port_stp_state_set)(struct dsa_switch *ds, int port,
u8 state); u8 state);
void (*port_fast_age)(struct dsa_switch *ds, int port); void (*port_fast_age)(struct dsa_switch *ds, int port);
...@@ -830,10 +898,10 @@ struct dsa_switch_ops { ...@@ -830,10 +898,10 @@ struct dsa_switch_ops {
*/ */
int (*crosschip_bridge_join)(struct dsa_switch *ds, int tree_index, int (*crosschip_bridge_join)(struct dsa_switch *ds, int tree_index,
int sw_index, int port, int sw_index, int port,
struct net_device *br); struct dsa_bridge bridge);
void (*crosschip_bridge_leave)(struct dsa_switch *ds, int tree_index, void (*crosschip_bridge_leave)(struct dsa_switch *ds, int tree_index,
int sw_index, int port, int sw_index, int port,
struct net_device *br); struct dsa_bridge bridge);
int (*crosschip_lag_change)(struct dsa_switch *ds, int sw_index, int (*crosschip_lag_change)(struct dsa_switch *ds, int sw_index,
int port); int port);
int (*crosschip_lag_join)(struct dsa_switch *ds, int sw_index, int (*crosschip_lag_join)(struct dsa_switch *ds, int sw_index,
......
...@@ -129,35 +129,52 @@ void dsa_lag_unmap(struct dsa_switch_tree *dst, struct net_device *lag) ...@@ -129,35 +129,52 @@ void dsa_lag_unmap(struct dsa_switch_tree *dst, struct net_device *lag)
} }
} }
struct dsa_bridge *dsa_tree_bridge_find(struct dsa_switch_tree *dst,
const struct net_device *br)
{
struct dsa_port *dp;
list_for_each_entry(dp, &dst->ports, list)
if (dsa_port_bridge_dev_get(dp) == br)
return dp->bridge;
return NULL;
}
static int dsa_bridge_num_find(const struct net_device *bridge_dev) static int dsa_bridge_num_find(const struct net_device *bridge_dev)
{ {
struct dsa_switch_tree *dst; struct dsa_switch_tree *dst;
struct dsa_port *dp;
/* When preparing the offload for a port, it will have a valid list_for_each_entry(dst, &dsa_tree_list, list) {
* dp->bridge_dev pointer but a not yet valid dp->bridge_num. struct dsa_bridge *bridge;
* 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; bridge = dsa_tree_bridge_find(dst, bridge_dev);
if (bridge)
return bridge->num;
}
return 0;
} }
int dsa_bridge_num_get(const struct net_device *bridge_dev, int max) unsigned int dsa_bridge_num_get(const struct net_device *bridge_dev, int max)
{ {
int bridge_num = dsa_bridge_num_find(bridge_dev); unsigned int bridge_num = dsa_bridge_num_find(bridge_dev);
if (bridge_num < 0) { /* Switches without FDB isolation support don't get unique
/* First port that offloads TX forwarding for this bridge */ * bridge numbering
bridge_num = find_first_zero_bit(&dsa_fwd_offloading_bridges, */
DSA_MAX_NUM_OFFLOADING_BRIDGES); if (!max)
return 0;
if (!bridge_num) {
/* First port that requests FDB isolation or TX forwarding
* offload for this bridge
*/
bridge_num = find_next_zero_bit(&dsa_fwd_offloading_bridges,
DSA_MAX_NUM_OFFLOADING_BRIDGES,
1);
if (bridge_num >= max) if (bridge_num >= max)
return -1; return 0;
set_bit(bridge_num, &dsa_fwd_offloading_bridges); set_bit(bridge_num, &dsa_fwd_offloading_bridges);
} }
...@@ -165,13 +182,14 @@ int dsa_bridge_num_get(const struct net_device *bridge_dev, int max) ...@@ -165,13 +182,14 @@ int dsa_bridge_num_get(const struct net_device *bridge_dev, int max)
return bridge_num; return bridge_num;
} }
void dsa_bridge_num_put(const struct net_device *bridge_dev, int bridge_num) void dsa_bridge_num_put(const struct net_device *bridge_dev,
unsigned int bridge_num)
{ {
/* Check if the bridge is still in use, otherwise it is time /* Since we refcount bridges, we know that when we call this function
* to clean it up so we can reuse this bridge_num later. * it is no longer in use, so we can just go ahead and remove it from
* the bit mask.
*/ */
if (dsa_bridge_num_find(bridge_dev) < 0) clear_bit(bridge_num, &dsa_fwd_offloading_bridges);
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)
...@@ -1184,7 +1202,6 @@ static struct dsa_port *dsa_port_touch(struct dsa_switch *ds, int index) ...@@ -1184,7 +1202,6 @@ static struct dsa_port *dsa_port_touch(struct dsa_switch *ds, int index)
dp->ds = ds; dp->ds = ds;
dp->index = index; dp->index = index;
dp->bridge_num = -1;
INIT_LIST_HEAD(&dp->list); INIT_LIST_HEAD(&dp->list);
list_add_tail(&dp->list, &dst->ports); list_add_tail(&dp->list, &dst->ports);
......
...@@ -52,10 +52,11 @@ struct dsa_notifier_ageing_time_info { ...@@ -52,10 +52,11 @@ struct dsa_notifier_ageing_time_info {
/* DSA_NOTIFIER_BRIDGE_* */ /* DSA_NOTIFIER_BRIDGE_* */
struct dsa_notifier_bridge_info { struct dsa_notifier_bridge_info {
struct net_device *br; struct dsa_bridge bridge;
int tree_index; int tree_index;
int sw_index; int sw_index;
int port; int port;
bool tx_fwd_offload;
}; };
/* DSA_NOTIFIER_FDB_* */ /* DSA_NOTIFIER_FDB_* */
...@@ -266,47 +267,6 @@ void dsa_port_hsr_leave(struct dsa_port *dp, struct net_device *hsr); ...@@ -266,47 +267,6 @@ void dsa_port_hsr_leave(struct dsa_port *dp, struct net_device *hsr);
int dsa_port_tag_8021q_vlan_add(struct dsa_port *dp, u16 vid, bool broadcast); int dsa_port_tag_8021q_vlan_add(struct dsa_port *dp, u16 vid, bool broadcast);
void dsa_port_tag_8021q_vlan_del(struct dsa_port *dp, u16 vid, bool broadcast); void dsa_port_tag_8021q_vlan_del(struct dsa_port *dp, u16 vid, bool broadcast);
static inline bool dsa_port_offloads_bridge_port(struct dsa_port *dp,
const struct net_device *dev)
{
return dsa_port_to_bridge_port(dp) == dev;
}
static inline bool dsa_port_offloads_bridge(struct dsa_port *dp,
const struct net_device *bridge_dev)
{
/* DSA ports connected to a bridge, and event was emitted
* for the bridge.
*/
return dp->bridge_dev == bridge_dev;
}
/* Returns true if any port of this tree offloads the given net_device */
static inline bool dsa_tree_offloads_bridge_port(struct dsa_switch_tree *dst,
const struct net_device *dev)
{
struct dsa_port *dp;
list_for_each_entry(dp, &dst->ports, list)
if (dsa_port_offloads_bridge_port(dp, dev))
return true;
return false;
}
/* Returns true if any port of this tree offloads the given bridge */
static inline bool dsa_tree_offloads_bridge(struct dsa_switch_tree *dst,
const struct net_device *bridge_dev)
{
struct dsa_port *dp;
list_for_each_entry(dp, &dst->ports, list)
if (dsa_port_offloads_bridge(dp, bridge_dev))
return true;
return false;
}
/* slave.c */ /* slave.c */
extern const struct dsa_device_ops notag_netdev_ops; extern const struct dsa_device_ops notag_netdev_ops;
extern struct notifier_block dsa_slave_switchdev_notifier; extern struct notifier_block dsa_slave_switchdev_notifier;
...@@ -345,7 +305,7 @@ dsa_slave_to_master(const struct net_device *dev) ...@@ -345,7 +305,7 @@ dsa_slave_to_master(const struct net_device *dev)
static inline struct sk_buff *dsa_untag_bridge_pvid(struct sk_buff *skb) static inline struct sk_buff *dsa_untag_bridge_pvid(struct sk_buff *skb)
{ {
struct dsa_port *dp = dsa_slave_to_port(skb->dev); struct dsa_port *dp = dsa_slave_to_port(skb->dev);
struct net_device *br = dp->bridge_dev; struct net_device *br = dsa_port_bridge_dev_get(dp);
struct net_device *dev = skb->dev; struct net_device *dev = skb->dev;
struct net_device *upper_dev; struct net_device *upper_dev;
u16 vid, pvid, proto; u16 vid, pvid, proto;
...@@ -415,7 +375,7 @@ dsa_find_designated_bridge_port_by_vid(struct net_device *master, u16 vid) ...@@ -415,7 +375,7 @@ dsa_find_designated_bridge_port_by_vid(struct net_device *master, u16 vid)
if (dp->type != DSA_PORT_TYPE_USER) if (dp->type != DSA_PORT_TYPE_USER)
continue; continue;
if (!dp->bridge_dev) if (!dp->bridge)
continue; continue;
if (dp->stp_state != BR_STATE_LEARNING && if (dp->stp_state != BR_STATE_LEARNING &&
...@@ -444,7 +404,7 @@ dsa_find_designated_bridge_port_by_vid(struct net_device *master, u16 vid) ...@@ -444,7 +404,7 @@ dsa_find_designated_bridge_port_by_vid(struct net_device *master, u16 vid)
/* If the ingress port offloads the bridge, we mark the frame as autonomously /* If the ingress port offloads the bridge, we mark the frame as autonomously
* forwarded by hardware, so the software bridge doesn't forward in twice, back * forwarded by hardware, so the software bridge doesn't forward in twice, back
* to us, because we already did. However, if we're in fallback mode and we do * to us, because we already did. However, if we're in fallback mode and we do
* software bridging, we are not offloading it, therefore the dp->bridge_dev * software bridging, we are not offloading it, therefore the dp->bridge
* pointer is not populated, and flooding needs to be done by software (we are * pointer is not populated, and flooding needs to be done by software (we are
* effectively operating in standalone ports mode). * effectively operating in standalone ports mode).
*/ */
...@@ -452,7 +412,7 @@ static inline void dsa_default_offload_fwd_mark(struct sk_buff *skb) ...@@ -452,7 +412,7 @@ static inline void dsa_default_offload_fwd_mark(struct sk_buff *skb)
{ {
struct dsa_port *dp = dsa_slave_to_port(skb->dev); struct dsa_port *dp = dsa_slave_to_port(skb->dev);
skb->offload_fwd_mark = !!(dp->bridge_dev); skb->offload_fwd_mark = !!(dp->bridge);
} }
/* Helper for removing DSA header tags from packets in the RX path. /* Helper for removing DSA header tags from packets in the RX path.
...@@ -546,8 +506,11 @@ int dsa_tree_change_tag_proto(struct dsa_switch_tree *dst, ...@@ -546,8 +506,11 @@ 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); unsigned 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); void dsa_bridge_num_put(const struct net_device *bridge_dev,
unsigned int bridge_num);
struct dsa_bridge *dsa_tree_bridge_find(struct dsa_switch_tree *dst,
const struct net_device *br);
/* 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,
......
...@@ -130,7 +130,7 @@ int dsa_port_enable_rt(struct dsa_port *dp, struct phy_device *phy) ...@@ -130,7 +130,7 @@ int dsa_port_enable_rt(struct dsa_port *dp, struct phy_device *phy)
return err; return err;
} }
if (!dp->bridge_dev) if (!dp->bridge)
dsa_port_set_state_now(dp, BR_STATE_FORWARDING, false); dsa_port_set_state_now(dp, BR_STATE_FORWARDING, false);
if (dp->pl) if (dp->pl)
...@@ -158,7 +158,7 @@ void dsa_port_disable_rt(struct dsa_port *dp) ...@@ -158,7 +158,7 @@ void dsa_port_disable_rt(struct dsa_port *dp)
if (dp->pl) if (dp->pl)
phylink_stop(dp->pl); phylink_stop(dp->pl);
if (!dp->bridge_dev) if (!dp->bridge)
dsa_port_set_state_now(dp, BR_STATE_DISABLED, false); dsa_port_set_state_now(dp, BR_STATE_DISABLED, false);
if (ds->ops->port_disable) if (ds->ops->port_disable)
...@@ -221,7 +221,7 @@ static int dsa_port_switchdev_sync_attrs(struct dsa_port *dp, ...@@ -221,7 +221,7 @@ static int dsa_port_switchdev_sync_attrs(struct dsa_port *dp,
struct netlink_ext_ack *extack) struct netlink_ext_ack *extack)
{ {
struct net_device *brport_dev = dsa_port_to_bridge_port(dp); struct net_device *brport_dev = dsa_port_to_bridge_port(dp);
struct net_device *br = dp->bridge_dev; struct net_device *br = dsa_port_bridge_dev_get(dp);
int err; int err;
err = dsa_port_inherit_brport_flags(dp, extack); err = dsa_port_inherit_brport_flags(dp, extack);
...@@ -270,52 +270,55 @@ static void dsa_port_switchdev_unsync_attrs(struct dsa_port *dp) ...@@ -270,52 +270,55 @@ static void dsa_port_switchdev_unsync_attrs(struct dsa_port *dp)
*/ */
} }
static void dsa_port_bridge_tx_fwd_unoffload(struct dsa_port *dp, static int dsa_port_bridge_create(struct dsa_port *dp,
struct net_device *bridge_dev) struct net_device *br,
struct netlink_ext_ack *extack)
{ {
int bridge_num = dp->bridge_num;
struct dsa_switch *ds = dp->ds; struct dsa_switch *ds = dp->ds;
struct dsa_bridge *bridge;
/* No bridge TX forwarding offload => do nothing */ bridge = dsa_tree_bridge_find(ds->dst, br);
if (!ds->ops->port_bridge_tx_fwd_unoffload || dp->bridge_num == -1) if (bridge) {
return; refcount_inc(&bridge->refcount);
dp->bridge = bridge;
return 0;
}
dp->bridge_num = -1; bridge = kzalloc(sizeof(*bridge), GFP_KERNEL);
if (!bridge)
return -ENOMEM;
dsa_bridge_num_put(bridge_dev, bridge_num); refcount_set(&bridge->refcount, 1);
/* Notify the chips only once the offload has been deactivated, so bridge->dev = br;
* that they can update their configuration accordingly.
*/ bridge->num = dsa_bridge_num_get(br, ds->max_num_bridges);
ds->ops->port_bridge_tx_fwd_unoffload(ds, dp->index, bridge_dev, if (ds->max_num_bridges && !bridge->num) {
bridge_num); NL_SET_ERR_MSG_MOD(extack,
"Range of offloadable bridges exceeded");
kfree(bridge);
return -EOPNOTSUPP;
}
dp->bridge = bridge;
return 0;
} }
static bool dsa_port_bridge_tx_fwd_offload(struct dsa_port *dp, static void dsa_port_bridge_destroy(struct dsa_port *dp,
struct net_device *bridge_dev) const struct net_device *br)
{ {
struct dsa_switch *ds = dp->ds; struct dsa_bridge *bridge = dp->bridge;
int bridge_num, err;
if (!ds->ops->port_bridge_tx_fwd_offload) dp->bridge = NULL;
return false;
bridge_num = dsa_bridge_num_get(bridge_dev, if (!refcount_dec_and_test(&bridge->refcount))
ds->num_fwd_offloading_bridges); return;
if (bridge_num < 0)
return false;
dp->bridge_num = bridge_num;
/* Notify the driver */ if (bridge->num)
err = ds->ops->port_bridge_tx_fwd_offload(ds, dp->index, bridge_dev, dsa_bridge_num_put(br, bridge->num);
bridge_num);
if (err) {
dsa_port_bridge_tx_fwd_unoffload(dp, bridge_dev);
return false;
}
return true; kfree(bridge);
} }
int dsa_port_bridge_join(struct dsa_port *dp, struct net_device *br, int dsa_port_bridge_join(struct dsa_port *dp, struct net_device *br,
...@@ -325,30 +328,32 @@ int dsa_port_bridge_join(struct dsa_port *dp, struct net_device *br, ...@@ -325,30 +328,32 @@ int dsa_port_bridge_join(struct dsa_port *dp, struct net_device *br,
.tree_index = dp->ds->dst->index, .tree_index = dp->ds->dst->index,
.sw_index = dp->ds->index, .sw_index = dp->ds->index,
.port = dp->index, .port = dp->index,
.br = br,
}; };
struct net_device *dev = dp->slave; struct net_device *dev = dp->slave;
struct net_device *brport_dev; struct net_device *brport_dev;
bool tx_fwd_offload;
int err; int err;
/* Here the interface is already bridged. Reflect the current /* Here the interface is already bridged. Reflect the current
* configuration so that drivers can program their chips accordingly. * configuration so that drivers can program their chips accordingly.
*/ */
dp->bridge_dev = br; err = dsa_port_bridge_create(dp, br, extack);
if (err)
return err;
brport_dev = dsa_port_to_bridge_port(dp); brport_dev = dsa_port_to_bridge_port(dp);
info.bridge = *dp->bridge;
err = dsa_broadcast(DSA_NOTIFIER_BRIDGE_JOIN, &info); err = dsa_broadcast(DSA_NOTIFIER_BRIDGE_JOIN, &info);
if (err) if (err)
goto out_rollback; goto out_rollback;
tx_fwd_offload = dsa_port_bridge_tx_fwd_offload(dp, br); /* Drivers which support bridge TX forwarding should set this */
dp->bridge->tx_fwd_offload = info.tx_fwd_offload;
err = switchdev_bridge_port_offload(brport_dev, dev, dp, err = switchdev_bridge_port_offload(brport_dev, dev, dp,
&dsa_slave_switchdev_notifier, &dsa_slave_switchdev_notifier,
&dsa_slave_switchdev_blocking_notifier, &dsa_slave_switchdev_blocking_notifier,
tx_fwd_offload, extack); dp->bridge->tx_fwd_offload, extack);
if (err) if (err)
goto out_rollback_unbridge; goto out_rollback_unbridge;
...@@ -365,7 +370,7 @@ int dsa_port_bridge_join(struct dsa_port *dp, struct net_device *br, ...@@ -365,7 +370,7 @@ int dsa_port_bridge_join(struct dsa_port *dp, struct net_device *br,
out_rollback_unbridge: out_rollback_unbridge:
dsa_broadcast(DSA_NOTIFIER_BRIDGE_LEAVE, &info); dsa_broadcast(DSA_NOTIFIER_BRIDGE_LEAVE, &info);
out_rollback: out_rollback:
dp->bridge_dev = NULL; dsa_port_bridge_destroy(dp, br);
return err; return err;
} }
...@@ -390,16 +395,14 @@ void dsa_port_bridge_leave(struct dsa_port *dp, struct net_device *br) ...@@ -390,16 +395,14 @@ void dsa_port_bridge_leave(struct dsa_port *dp, struct net_device *br)
.tree_index = dp->ds->dst->index, .tree_index = dp->ds->dst->index,
.sw_index = dp->ds->index, .sw_index = dp->ds->index,
.port = dp->index, .port = dp->index,
.br = br, .bridge = *dp->bridge,
}; };
int err; int err;
/* Here the port is already unbridged. Reflect the current configuration /* Here the port is already unbridged. Reflect the current configuration
* so that drivers can program their chips accordingly. * so that drivers can program their chips accordingly.
*/ */
dp->bridge_dev = NULL; dsa_port_bridge_destroy(dp, br);
dsa_port_bridge_tx_fwd_unoffload(dp, br);
err = dsa_broadcast(DSA_NOTIFIER_BRIDGE_LEAVE, &info); err = dsa_broadcast(DSA_NOTIFIER_BRIDGE_LEAVE, &info);
if (err) if (err)
...@@ -477,12 +480,15 @@ int dsa_port_lag_join(struct dsa_port *dp, struct net_device *lag, ...@@ -477,12 +480,15 @@ int dsa_port_lag_join(struct dsa_port *dp, struct net_device *lag,
void dsa_port_pre_lag_leave(struct dsa_port *dp, struct net_device *lag) void dsa_port_pre_lag_leave(struct dsa_port *dp, struct net_device *lag)
{ {
if (dp->bridge_dev) struct net_device *br = dsa_port_bridge_dev_get(dp);
dsa_port_pre_bridge_leave(dp, dp->bridge_dev);
if (br)
dsa_port_pre_bridge_leave(dp, br);
} }
void dsa_port_lag_leave(struct dsa_port *dp, struct net_device *lag) void dsa_port_lag_leave(struct dsa_port *dp, struct net_device *lag)
{ {
struct net_device *br = dsa_port_bridge_dev_get(dp);
struct dsa_notifier_lag_info info = { struct dsa_notifier_lag_info info = {
.sw_index = dp->ds->index, .sw_index = dp->ds->index,
.port = dp->index, .port = dp->index,
...@@ -496,8 +502,8 @@ void dsa_port_lag_leave(struct dsa_port *dp, struct net_device *lag) ...@@ -496,8 +502,8 @@ void dsa_port_lag_leave(struct dsa_port *dp, struct net_device *lag)
/* Port might have been part of a LAG that in turn was /* Port might have been part of a LAG that in turn was
* attached to a bridge. * attached to a bridge.
*/ */
if (dp->bridge_dev) if (br)
dsa_port_bridge_leave(dp, dp->bridge_dev); dsa_port_bridge_leave(dp, br);
dp->lag_tx_enabled = false; dp->lag_tx_enabled = false;
dp->lag_dev = NULL; dp->lag_dev = NULL;
...@@ -526,8 +532,8 @@ static bool dsa_port_can_apply_vlan_filtering(struct dsa_port *dp, ...@@ -526,8 +532,8 @@ static bool dsa_port_can_apply_vlan_filtering(struct dsa_port *dp,
* as long as we have 8021q uppers. * as long as we have 8021q uppers.
*/ */
if (vlan_filtering && dsa_port_is_user(dp)) { if (vlan_filtering && dsa_port_is_user(dp)) {
struct net_device *br = dsa_port_bridge_dev_get(dp);
struct net_device *upper_dev, *slave = dp->slave; struct net_device *upper_dev, *slave = dp->slave;
struct net_device *br = dp->bridge_dev;
struct list_head *iter; struct list_head *iter;
netdev_for_each_upper_dev_rcu(slave, upper_dev, iter) { netdev_for_each_upper_dev_rcu(slave, upper_dev, iter) {
...@@ -561,17 +567,15 @@ static bool dsa_port_can_apply_vlan_filtering(struct dsa_port *dp, ...@@ -561,17 +567,15 @@ static bool dsa_port_can_apply_vlan_filtering(struct dsa_port *dp,
* different setting than what is being requested. * different setting than what is being requested.
*/ */
dsa_switch_for_each_port(other_dp, ds) { dsa_switch_for_each_port(other_dp, ds) {
struct net_device *other_bridge; struct net_device *other_br = dsa_port_bridge_dev_get(other_dp);
other_bridge = other_dp->bridge_dev;
if (!other_bridge)
continue;
/* If it's the same bridge, it also has same /* If it's the same bridge, it also has same
* vlan_filtering setting => no need to check * vlan_filtering setting => no need to check
*/ */
if (other_bridge == dp->bridge_dev) if (!other_br || other_br == dsa_port_bridge_dev_get(dp))
continue; continue;
if (br_vlan_enabled(other_bridge) != vlan_filtering) {
if (br_vlan_enabled(other_br) != vlan_filtering) {
NL_SET_ERR_MSG_MOD(extack, NL_SET_ERR_MSG_MOD(extack,
"VLAN filtering is a global setting"); "VLAN filtering is a global setting");
return false; return false;
...@@ -655,13 +659,13 @@ int dsa_port_vlan_filtering(struct dsa_port *dp, bool vlan_filtering, ...@@ -655,13 +659,13 @@ int dsa_port_vlan_filtering(struct dsa_port *dp, bool vlan_filtering,
*/ */
bool dsa_port_skip_vlan_configuration(struct dsa_port *dp) bool dsa_port_skip_vlan_configuration(struct dsa_port *dp)
{ {
struct net_device *br = dsa_port_bridge_dev_get(dp);
struct dsa_switch *ds = dp->ds; struct dsa_switch *ds = dp->ds;
if (!dp->bridge_dev) if (!br)
return false; return false;
return (!ds->configure_vlan_while_not_filtering && return !ds->configure_vlan_while_not_filtering && !br_vlan_enabled(br);
!br_vlan_enabled(dp->bridge_dev));
} }
int dsa_port_ageing_time(struct dsa_port *dp, clock_t ageing_clock) int dsa_port_ageing_time(struct dsa_port *dp, clock_t ageing_clock)
......
...@@ -289,14 +289,14 @@ static int dsa_slave_port_attr_set(struct net_device *dev, const void *ctx, ...@@ -289,14 +289,14 @@ static int dsa_slave_port_attr_set(struct net_device *dev, const void *ctx,
ret = dsa_port_set_state(dp, attr->u.stp_state, true); ret = dsa_port_set_state(dp, attr->u.stp_state, true);
break; break;
case SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING: case SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING:
if (!dsa_port_offloads_bridge(dp, attr->orig_dev)) if (!dsa_port_offloads_bridge_dev(dp, attr->orig_dev))
return -EOPNOTSUPP; return -EOPNOTSUPP;
ret = dsa_port_vlan_filtering(dp, attr->u.vlan_filtering, ret = dsa_port_vlan_filtering(dp, attr->u.vlan_filtering,
extack); extack);
break; break;
case SWITCHDEV_ATTR_ID_BRIDGE_AGEING_TIME: case SWITCHDEV_ATTR_ID_BRIDGE_AGEING_TIME:
if (!dsa_port_offloads_bridge(dp, attr->orig_dev)) if (!dsa_port_offloads_bridge_dev(dp, attr->orig_dev))
return -EOPNOTSUPP; return -EOPNOTSUPP;
ret = dsa_port_ageing_time(dp, attr->u.ageing_time); ret = dsa_port_ageing_time(dp, attr->u.ageing_time);
...@@ -363,7 +363,7 @@ static int dsa_slave_vlan_add(struct net_device *dev, ...@@ -363,7 +363,7 @@ static int dsa_slave_vlan_add(struct net_device *dev,
/* Deny adding a bridge VLAN when there is already an 802.1Q upper with /* Deny adding a bridge VLAN when there is already an 802.1Q upper with
* the same VID. * the same VID.
*/ */
if (br_vlan_enabled(dp->bridge_dev)) { if (br_vlan_enabled(dsa_port_bridge_dev_get(dp))) {
rcu_read_lock(); rcu_read_lock();
err = dsa_slave_vlan_check_for_8021q_uppers(dev, &vlan); err = dsa_slave_vlan_check_for_8021q_uppers(dev, &vlan);
rcu_read_unlock(); rcu_read_unlock();
...@@ -409,7 +409,7 @@ static int dsa_slave_port_obj_add(struct net_device *dev, const void *ctx, ...@@ -409,7 +409,7 @@ static int dsa_slave_port_obj_add(struct net_device *dev, const void *ctx,
err = dsa_port_mdb_add(dp, SWITCHDEV_OBJ_PORT_MDB(obj)); err = dsa_port_mdb_add(dp, SWITCHDEV_OBJ_PORT_MDB(obj));
break; break;
case SWITCHDEV_OBJ_ID_HOST_MDB: case SWITCHDEV_OBJ_ID_HOST_MDB:
if (!dsa_port_offloads_bridge(dp, obj->orig_dev)) if (!dsa_port_offloads_bridge_dev(dp, obj->orig_dev))
return -EOPNOTSUPP; return -EOPNOTSUPP;
err = dsa_port_host_mdb_add(dp, SWITCHDEV_OBJ_PORT_MDB(obj)); err = dsa_port_host_mdb_add(dp, SWITCHDEV_OBJ_PORT_MDB(obj));
...@@ -421,13 +421,13 @@ static int dsa_slave_port_obj_add(struct net_device *dev, const void *ctx, ...@@ -421,13 +421,13 @@ static int dsa_slave_port_obj_add(struct net_device *dev, const void *ctx,
err = dsa_slave_vlan_add(dev, obj, extack); err = dsa_slave_vlan_add(dev, obj, extack);
break; break;
case SWITCHDEV_OBJ_ID_MRP: case SWITCHDEV_OBJ_ID_MRP:
if (!dsa_port_offloads_bridge(dp, obj->orig_dev)) if (!dsa_port_offloads_bridge_dev(dp, obj->orig_dev))
return -EOPNOTSUPP; return -EOPNOTSUPP;
err = dsa_port_mrp_add(dp, SWITCHDEV_OBJ_MRP(obj)); err = dsa_port_mrp_add(dp, SWITCHDEV_OBJ_MRP(obj));
break; break;
case SWITCHDEV_OBJ_ID_RING_ROLE_MRP: case SWITCHDEV_OBJ_ID_RING_ROLE_MRP:
if (!dsa_port_offloads_bridge(dp, obj->orig_dev)) if (!dsa_port_offloads_bridge_dev(dp, obj->orig_dev))
return -EOPNOTSUPP; return -EOPNOTSUPP;
err = dsa_port_mrp_add_ring_role(dp, err = dsa_port_mrp_add_ring_role(dp,
...@@ -483,7 +483,7 @@ static int dsa_slave_port_obj_del(struct net_device *dev, const void *ctx, ...@@ -483,7 +483,7 @@ static int dsa_slave_port_obj_del(struct net_device *dev, const void *ctx,
err = dsa_port_mdb_del(dp, SWITCHDEV_OBJ_PORT_MDB(obj)); err = dsa_port_mdb_del(dp, SWITCHDEV_OBJ_PORT_MDB(obj));
break; break;
case SWITCHDEV_OBJ_ID_HOST_MDB: case SWITCHDEV_OBJ_ID_HOST_MDB:
if (!dsa_port_offloads_bridge(dp, obj->orig_dev)) if (!dsa_port_offloads_bridge_dev(dp, obj->orig_dev))
return -EOPNOTSUPP; return -EOPNOTSUPP;
err = dsa_port_host_mdb_del(dp, SWITCHDEV_OBJ_PORT_MDB(obj)); err = dsa_port_host_mdb_del(dp, SWITCHDEV_OBJ_PORT_MDB(obj));
...@@ -495,13 +495,13 @@ static int dsa_slave_port_obj_del(struct net_device *dev, const void *ctx, ...@@ -495,13 +495,13 @@ static int dsa_slave_port_obj_del(struct net_device *dev, const void *ctx,
err = dsa_slave_vlan_del(dev, obj); err = dsa_slave_vlan_del(dev, obj);
break; break;
case SWITCHDEV_OBJ_ID_MRP: case SWITCHDEV_OBJ_ID_MRP:
if (!dsa_port_offloads_bridge(dp, obj->orig_dev)) if (!dsa_port_offloads_bridge_dev(dp, obj->orig_dev))
return -EOPNOTSUPP; return -EOPNOTSUPP;
err = dsa_port_mrp_del(dp, SWITCHDEV_OBJ_MRP(obj)); err = dsa_port_mrp_del(dp, SWITCHDEV_OBJ_MRP(obj));
break; break;
case SWITCHDEV_OBJ_ID_RING_ROLE_MRP: case SWITCHDEV_OBJ_ID_RING_ROLE_MRP:
if (!dsa_port_offloads_bridge(dp, obj->orig_dev)) if (!dsa_port_offloads_bridge_dev(dp, obj->orig_dev))
return -EOPNOTSUPP; return -EOPNOTSUPP;
err = dsa_port_mrp_del_ring_role(dp, err = dsa_port_mrp_del_ring_role(dp,
...@@ -1564,7 +1564,7 @@ static void dsa_bridge_mtu_normalization(struct dsa_port *dp) ...@@ -1564,7 +1564,7 @@ static void dsa_bridge_mtu_normalization(struct dsa_port *dp)
if (!dp->ds->mtu_enforcement_ingress) if (!dp->ds->mtu_enforcement_ingress)
return; return;
if (!dp->bridge_dev) if (!dp->bridge)
return; return;
INIT_LIST_HEAD(&hw_port_list); INIT_LIST_HEAD(&hw_port_list);
...@@ -1580,7 +1580,7 @@ static void dsa_bridge_mtu_normalization(struct dsa_port *dp) ...@@ -1580,7 +1580,7 @@ static void dsa_bridge_mtu_normalization(struct dsa_port *dp)
if (other_dp->type != DSA_PORT_TYPE_USER) if (other_dp->type != DSA_PORT_TYPE_USER)
continue; continue;
if (other_dp->bridge_dev != dp->bridge_dev) if (!dsa_port_bridge_same(dp, other_dp))
continue; continue;
if (!other_dp->ds->mtu_enforcement_ingress) if (!other_dp->ds->mtu_enforcement_ingress)
...@@ -2220,7 +2220,7 @@ dsa_prevent_bridging_8021q_upper(struct net_device *dev, ...@@ -2220,7 +2220,7 @@ dsa_prevent_bridging_8021q_upper(struct net_device *dev,
struct netdev_notifier_changeupper_info *info) struct netdev_notifier_changeupper_info *info)
{ {
struct netlink_ext_ack *ext_ack; struct netlink_ext_ack *ext_ack;
struct net_device *slave; struct net_device *slave, *br;
struct dsa_port *dp; struct dsa_port *dp;
ext_ack = netdev_notifier_info_to_extack(&info->info); ext_ack = netdev_notifier_info_to_extack(&info->info);
...@@ -2233,11 +2233,12 @@ dsa_prevent_bridging_8021q_upper(struct net_device *dev, ...@@ -2233,11 +2233,12 @@ dsa_prevent_bridging_8021q_upper(struct net_device *dev,
return NOTIFY_DONE; return NOTIFY_DONE;
dp = dsa_slave_to_port(slave); dp = dsa_slave_to_port(slave);
if (!dp->bridge_dev) br = dsa_port_bridge_dev_get(dp);
if (!br)
return NOTIFY_DONE; return NOTIFY_DONE;
/* Deny enslaving a VLAN device into a VLAN-aware bridge */ /* Deny enslaving a VLAN device into a VLAN-aware bridge */
if (br_vlan_enabled(dp->bridge_dev) && if (br_vlan_enabled(br) &&
netif_is_bridge_master(info->upper_dev) && info->linking) { netif_is_bridge_master(info->upper_dev) && info->linking) {
NL_SET_ERR_MSG_MOD(ext_ack, NL_SET_ERR_MSG_MOD(ext_ack,
"Cannot enslave VLAN device into VLAN aware bridge"); "Cannot enslave VLAN device into VLAN aware bridge");
...@@ -2252,7 +2253,7 @@ dsa_slave_check_8021q_upper(struct net_device *dev, ...@@ -2252,7 +2253,7 @@ dsa_slave_check_8021q_upper(struct net_device *dev,
struct netdev_notifier_changeupper_info *info) struct netdev_notifier_changeupper_info *info)
{ {
struct dsa_port *dp = dsa_slave_to_port(dev); struct dsa_port *dp = dsa_slave_to_port(dev);
struct net_device *br = dp->bridge_dev; struct net_device *br = dsa_port_bridge_dev_get(dp);
struct bridge_vlan_info br_info; struct bridge_vlan_info br_info;
struct netlink_ext_ack *extack; struct netlink_ext_ack *extack;
int err = NOTIFY_DONE; int err = NOTIFY_DONE;
...@@ -2449,7 +2450,7 @@ static bool dsa_foreign_dev_check(const struct net_device *dev, ...@@ -2449,7 +2450,7 @@ static bool dsa_foreign_dev_check(const struct net_device *dev,
struct dsa_switch_tree *dst = dp->ds->dst; struct dsa_switch_tree *dst = dp->ds->dst;
if (netif_is_bridge_master(foreign_dev)) if (netif_is_bridge_master(foreign_dev))
return !dsa_tree_offloads_bridge(dst, foreign_dev); return !dsa_tree_offloads_bridge_dev(dst, foreign_dev);
if (netif_is_bridge_port(foreign_dev)) if (netif_is_bridge_port(foreign_dev))
return !dsa_tree_offloads_bridge_port(dst, foreign_dev); return !dsa_tree_offloads_bridge_port(dst, foreign_dev);
......
...@@ -95,7 +95,8 @@ static int dsa_switch_bridge_join(struct dsa_switch *ds, ...@@ -95,7 +95,8 @@ static int dsa_switch_bridge_join(struct dsa_switch *ds,
if (!ds->ops->port_bridge_join) if (!ds->ops->port_bridge_join)
return -EOPNOTSUPP; return -EOPNOTSUPP;
err = ds->ops->port_bridge_join(ds, info->port, info->br); err = ds->ops->port_bridge_join(ds, info->port, info->bridge,
&info->tx_fwd_offload);
if (err) if (err)
return err; return err;
} }
...@@ -104,7 +105,7 @@ static int dsa_switch_bridge_join(struct dsa_switch *ds, ...@@ -104,7 +105,7 @@ static int dsa_switch_bridge_join(struct dsa_switch *ds,
ds->ops->crosschip_bridge_join) { ds->ops->crosschip_bridge_join) {
err = ds->ops->crosschip_bridge_join(ds, info->tree_index, err = ds->ops->crosschip_bridge_join(ds, info->tree_index,
info->sw_index, info->sw_index,
info->port, info->br); info->port, info->bridge);
if (err) if (err)
return err; return err;
} }
...@@ -124,19 +125,20 @@ static int dsa_switch_bridge_leave(struct dsa_switch *ds, ...@@ -124,19 +125,20 @@ static int dsa_switch_bridge_leave(struct dsa_switch *ds,
if (dst->index == info->tree_index && ds->index == info->sw_index && if (dst->index == info->tree_index && ds->index == info->sw_index &&
ds->ops->port_bridge_leave) ds->ops->port_bridge_leave)
ds->ops->port_bridge_leave(ds, info->port, info->br); ds->ops->port_bridge_leave(ds, info->port, info->bridge);
if ((dst->index != info->tree_index || ds->index != info->sw_index) && if ((dst->index != info->tree_index || ds->index != info->sw_index) &&
ds->ops->crosschip_bridge_leave) ds->ops->crosschip_bridge_leave)
ds->ops->crosschip_bridge_leave(ds, info->tree_index, ds->ops->crosschip_bridge_leave(ds, info->tree_index,
info->sw_index, info->port, info->sw_index, info->port,
info->br); info->bridge);
if (ds->needs_standalone_vlan_filtering && !br_vlan_enabled(info->br)) { if (ds->needs_standalone_vlan_filtering &&
!br_vlan_enabled(info->bridge.dev)) {
change_vlan_filtering = true; change_vlan_filtering = true;
vlan_filtering = true; vlan_filtering = true;
} else if (!ds->needs_standalone_vlan_filtering && } else if (!ds->needs_standalone_vlan_filtering &&
br_vlan_enabled(info->br)) { br_vlan_enabled(info->bridge.dev)) {
change_vlan_filtering = true; change_vlan_filtering = true;
vlan_filtering = false; vlan_filtering = false;
} }
...@@ -151,11 +153,9 @@ static int dsa_switch_bridge_leave(struct dsa_switch *ds, ...@@ -151,11 +153,9 @@ static int dsa_switch_bridge_leave(struct dsa_switch *ds,
*/ */
if (change_vlan_filtering && ds->vlan_filtering_is_global) { if (change_vlan_filtering && ds->vlan_filtering_is_global) {
dsa_switch_for_each_port(dp, ds) { dsa_switch_for_each_port(dp, ds) {
struct net_device *bridge_dev; struct net_device *br = dsa_port_bridge_dev_get(dp);
bridge_dev = dp->bridge_dev; if (br && br_vlan_enabled(br)) {
if (bridge_dev && br_vlan_enabled(bridge_dev)) {
change_vlan_filtering = false; change_vlan_filtering = false;
break; break;
} }
......
...@@ -67,10 +67,12 @@ ...@@ -67,10 +67,12 @@
#define DSA_8021Q_PORT(x) (((x) << DSA_8021Q_PORT_SHIFT) & \ #define DSA_8021Q_PORT(x) (((x) << DSA_8021Q_PORT_SHIFT) & \
DSA_8021Q_PORT_MASK) DSA_8021Q_PORT_MASK)
u16 dsa_8021q_bridge_tx_fwd_offload_vid(int bridge_num) u16 dsa_8021q_bridge_tx_fwd_offload_vid(unsigned int bridge_num)
{ {
/* The VBID value of 0 is reserved for precise TX */ /* The VBID value of 0 is reserved for precise TX, but it is also
return DSA_8021Q_DIR_TX | DSA_8021Q_VBID(bridge_num + 1); * reserved/invalid for the bridge_num, so all is well.
*/
return DSA_8021Q_DIR_TX | DSA_8021Q_VBID(bridge_num);
} }
EXPORT_SYMBOL_GPL(dsa_8021q_bridge_tx_fwd_offload_vid); EXPORT_SYMBOL_GPL(dsa_8021q_bridge_tx_fwd_offload_vid);
...@@ -335,7 +337,7 @@ dsa_port_tag_8021q_bridge_match(struct dsa_port *dp, ...@@ -335,7 +337,7 @@ dsa_port_tag_8021q_bridge_match(struct dsa_port *dp,
return false; return false;
if (dsa_port_is_user(dp)) if (dsa_port_is_user(dp))
return dp->bridge_dev == info->br; return dsa_port_offloads_bridge(dp, &info->bridge);
return false; return false;
} }
...@@ -408,10 +410,9 @@ int dsa_tag_8021q_bridge_leave(struct dsa_switch *ds, ...@@ -408,10 +410,9 @@ int dsa_tag_8021q_bridge_leave(struct dsa_switch *ds,
} }
int dsa_tag_8021q_bridge_tx_fwd_offload(struct dsa_switch *ds, int port, int dsa_tag_8021q_bridge_tx_fwd_offload(struct dsa_switch *ds, int port,
struct net_device *br, struct dsa_bridge bridge)
int bridge_num)
{ {
u16 tx_vid = dsa_8021q_bridge_tx_fwd_offload_vid(bridge_num); u16 tx_vid = dsa_8021q_bridge_tx_fwd_offload_vid(bridge.num);
return dsa_port_tag_8021q_vlan_add(dsa_to_port(ds, port), tx_vid, return dsa_port_tag_8021q_vlan_add(dsa_to_port(ds, port), tx_vid,
true); true);
...@@ -419,10 +420,9 @@ int dsa_tag_8021q_bridge_tx_fwd_offload(struct dsa_switch *ds, int port, ...@@ -419,10 +420,9 @@ int dsa_tag_8021q_bridge_tx_fwd_offload(struct dsa_switch *ds, int port,
EXPORT_SYMBOL_GPL(dsa_tag_8021q_bridge_tx_fwd_offload); EXPORT_SYMBOL_GPL(dsa_tag_8021q_bridge_tx_fwd_offload);
void dsa_tag_8021q_bridge_tx_fwd_unoffload(struct dsa_switch *ds, int port, void dsa_tag_8021q_bridge_tx_fwd_unoffload(struct dsa_switch *ds, int port,
struct net_device *br, struct dsa_bridge bridge)
int bridge_num)
{ {
u16 tx_vid = dsa_8021q_bridge_tx_fwd_offload_vid(bridge_num); u16 tx_vid = dsa_8021q_bridge_tx_fwd_offload_vid(bridge.num);
dsa_port_tag_8021q_vlan_del(dsa_to_port(ds, port), tx_vid, true); dsa_port_tag_8021q_vlan_del(dsa_to_port(ds, port), tx_vid, true);
} }
......
...@@ -132,6 +132,7 @@ static struct sk_buff *dsa_xmit_ll(struct sk_buff *skb, struct net_device *dev, ...@@ -132,6 +132,7 @@ static struct sk_buff *dsa_xmit_ll(struct sk_buff *skb, struct net_device *dev,
u8 *dsa_header; u8 *dsa_header;
if (skb->offload_fwd_mark) { if (skb->offload_fwd_mark) {
unsigned int bridge_num = dsa_port_bridge_num_get(dp);
struct dsa_switch_tree *dst = dp->ds->dst; struct dsa_switch_tree *dst = dp->ds->dst;
cmd = DSA_CMD_FORWARD; cmd = DSA_CMD_FORWARD;
...@@ -140,7 +141,7 @@ static struct sk_buff *dsa_xmit_ll(struct sk_buff *skb, struct net_device *dev, ...@@ -140,7 +141,7 @@ static struct sk_buff *dsa_xmit_ll(struct sk_buff *skb, struct net_device *dev,
* packets on behalf of a virtual switch device with an index * packets on behalf of a virtual switch device with an index
* past the physical switches. * past the physical switches.
*/ */
tag_dev = dst->last_switch + 1 + dp->bridge_num; tag_dev = dst->last_switch + bridge_num;
tag_port = 0; tag_port = 0;
} else { } else {
cmd = DSA_CMD_FROM_CPU; cmd = DSA_CMD_FROM_CPU;
...@@ -165,7 +166,7 @@ static struct sk_buff *dsa_xmit_ll(struct sk_buff *skb, struct net_device *dev, ...@@ -165,7 +166,7 @@ static struct sk_buff *dsa_xmit_ll(struct sk_buff *skb, struct net_device *dev,
dsa_header[2] &= ~0x10; dsa_header[2] &= ~0x10;
} }
} else { } else {
struct net_device *br = dp->bridge_dev; struct net_device *br = dsa_port_bridge_dev_get(dp);
u16 vid; u16 vid;
vid = br ? MV88E6XXX_VID_BRIDGED : MV88E6XXX_VID_STANDALONE; vid = br ? MV88E6XXX_VID_BRIDGED : MV88E6XXX_VID_STANDALONE;
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
static void ocelot_xmit_get_vlan_info(struct sk_buff *skb, struct dsa_port *dp, static void ocelot_xmit_get_vlan_info(struct sk_buff *skb, struct dsa_port *dp,
u64 *vlan_tci, u64 *tag_type) u64 *vlan_tci, u64 *tag_type)
{ {
struct net_device *br = READ_ONCE(dp->bridge_dev); struct net_device *br = dsa_port_bridge_dev_get(dp);
struct vlan_ethhdr *hdr; struct vlan_ethhdr *hdr;
u16 proto, tci; u16 proto, tci;
......
...@@ -159,14 +159,16 @@ static u16 sja1105_xmit_tpid(struct dsa_port *dp) ...@@ -159,14 +159,16 @@ static u16 sja1105_xmit_tpid(struct dsa_port *dp)
* need to find it. * need to find it.
*/ */
dsa_switch_for_each_port(other_dp, ds) { dsa_switch_for_each_port(other_dp, ds) {
if (!other_dp->bridge_dev) struct net_device *br = dsa_port_bridge_dev_get(other_dp);
if (!br)
continue; continue;
/* Error is returned only if CONFIG_BRIDGE_VLAN_FILTERING, /* Error is returned only if CONFIG_BRIDGE_VLAN_FILTERING,
* which seems pointless to handle, as our port cannot become * which seems pointless to handle, as our port cannot become
* VLAN-aware in that case. * VLAN-aware in that case.
*/ */
br_vlan_get_proto(other_dp->bridge_dev, &proto); br_vlan_get_proto(br, &proto);
return proto; return proto;
} }
...@@ -180,7 +182,8 @@ static struct sk_buff *sja1105_imprecise_xmit(struct sk_buff *skb, ...@@ -180,7 +182,8 @@ static struct sk_buff *sja1105_imprecise_xmit(struct sk_buff *skb,
struct net_device *netdev) struct net_device *netdev)
{ {
struct dsa_port *dp = dsa_slave_to_port(netdev); struct dsa_port *dp = dsa_slave_to_port(netdev);
struct net_device *br = dp->bridge_dev; unsigned int bridge_num = dsa_port_bridge_num_get(dp);
struct net_device *br = dsa_port_bridge_dev_get(dp);
u16 tx_vid; u16 tx_vid;
/* If the port is under a VLAN-aware bridge, just slide the /* If the port is under a VLAN-aware bridge, just slide the
...@@ -196,7 +199,7 @@ static struct sk_buff *sja1105_imprecise_xmit(struct sk_buff *skb, ...@@ -196,7 +199,7 @@ static struct sk_buff *sja1105_imprecise_xmit(struct sk_buff *skb,
* TX VLAN that targets the bridge's entire broadcast domain, * TX VLAN that targets the bridge's entire broadcast domain,
* instead of just the specific port. * instead of just the specific port.
*/ */
tx_vid = dsa_8021q_bridge_tx_fwd_offload_vid(dp->bridge_num); tx_vid = dsa_8021q_bridge_tx_fwd_offload_vid(bridge_num);
return dsa_8021q_xmit(skb, netdev, sja1105_xmit_tpid(dp), tx_vid); return dsa_8021q_xmit(skb, netdev, sja1105_xmit_tpid(dp), tx_vid);
} }
......
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