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

net: switchdev: pass flags and mask to both {PRE_,}BRIDGE_FLAGS attributes

This switchdev attribute offers a counterproductive API for a driver
writer, because although br_switchdev_set_port_flag gets passed a
"flags" and a "mask", those are passed piecemeal to the driver, so while
the PRE_BRIDGE_FLAGS listener knows what changed because it has the
"mask", the BRIDGE_FLAGS listener doesn't, because it only has the final
value. But certain drivers can offload only certain combinations of
settings, like for example they cannot change unicast flooding
independently of multicast flooding - they must be both on or both off.
The way the information is passed to switchdev makes drivers not
expressive enough, and unable to reject this request ahead of time, in
the PRE_BRIDGE_FLAGS notifier, so they are forced to reject it during
the deferred BRIDGE_FLAGS attribute, where the rejection is currently
ignored.

This patch also changes drivers to make use of the "mask" field for edge
detection when possible.
Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: default avatarGrygorii Strashko <grygorii.strashko@ti.com>
Reviewed-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 5e38c158
...@@ -581,7 +581,7 @@ int prestera_bridge_port_event(struct net_device *dev, unsigned long event, ...@@ -581,7 +581,7 @@ int prestera_bridge_port_event(struct net_device *dev, unsigned long event,
static int prestera_port_attr_br_flags_set(struct prestera_port *port, static int prestera_port_attr_br_flags_set(struct prestera_port *port,
struct net_device *dev, struct net_device *dev,
unsigned long flags) struct switchdev_brport_flags flags)
{ {
struct prestera_bridge_port *br_port; struct prestera_bridge_port *br_port;
int err; int err;
...@@ -590,15 +590,20 @@ static int prestera_port_attr_br_flags_set(struct prestera_port *port, ...@@ -590,15 +590,20 @@ static int prestera_port_attr_br_flags_set(struct prestera_port *port,
if (!br_port) if (!br_port)
return 0; return 0;
err = prestera_hw_port_flood_set(port, flags & BR_FLOOD); if (flags.mask & BR_FLOOD) {
if (err) err = prestera_hw_port_flood_set(port, flags.val & BR_FLOOD);
return err; if (err)
return err;
}
err = prestera_hw_port_learning_set(port, flags & BR_LEARNING); if (flags.mask & BR_LEARNING) {
if (err) err = prestera_hw_port_learning_set(port,
return err; flags.val & BR_LEARNING);
if (err)
return err;
}
memcpy(&br_port->flags, &flags, sizeof(flags)); memcpy(&br_port->flags, &flags.val, sizeof(flags.val));
return 0; return 0;
} }
...@@ -707,7 +712,7 @@ static int prestera_port_obj_attr_set(struct net_device *dev, ...@@ -707,7 +712,7 @@ static int prestera_port_obj_attr_set(struct net_device *dev,
attr->u.stp_state); attr->u.stp_state);
break; break;
case SWITCHDEV_ATTR_ID_PORT_PRE_BRIDGE_FLAGS: case SWITCHDEV_ATTR_ID_PORT_PRE_BRIDGE_FLAGS:
if (attr->u.brport_flags & if (attr->u.brport_flags.mask &
~(BR_LEARNING | BR_FLOOD | BR_MCAST_FLOOD)) ~(BR_LEARNING | BR_FLOOD | BR_MCAST_FLOOD))
err = -EINVAL; err = -EINVAL;
break; break;
......
...@@ -653,11 +653,11 @@ mlxsw_sp_bridge_port_learning_set(struct mlxsw_sp_port *mlxsw_sp_port, ...@@ -653,11 +653,11 @@ mlxsw_sp_bridge_port_learning_set(struct mlxsw_sp_port *mlxsw_sp_port,
return err; return err;
} }
static int mlxsw_sp_port_attr_br_pre_flags_set(struct mlxsw_sp_port static int
*mlxsw_sp_port, mlxsw_sp_port_attr_br_pre_flags_set(struct mlxsw_sp_port *mlxsw_sp_port,
unsigned long brport_flags) struct switchdev_brport_flags flags)
{ {
if (brport_flags & ~(BR_LEARNING | BR_FLOOD | BR_MCAST_FLOOD)) if (flags.mask & ~(BR_LEARNING | BR_FLOOD | BR_MCAST_FLOOD))
return -EINVAL; return -EINVAL;
return 0; return 0;
...@@ -665,7 +665,7 @@ static int mlxsw_sp_port_attr_br_pre_flags_set(struct mlxsw_sp_port ...@@ -665,7 +665,7 @@ static int mlxsw_sp_port_attr_br_pre_flags_set(struct mlxsw_sp_port
static int mlxsw_sp_port_attr_br_flags_set(struct mlxsw_sp_port *mlxsw_sp_port, static int mlxsw_sp_port_attr_br_flags_set(struct mlxsw_sp_port *mlxsw_sp_port,
struct net_device *orig_dev, struct net_device *orig_dev,
unsigned long brport_flags) struct switchdev_brport_flags flags)
{ {
struct mlxsw_sp_bridge_port *bridge_port; struct mlxsw_sp_bridge_port *bridge_port;
int err; int err;
...@@ -675,29 +675,37 @@ static int mlxsw_sp_port_attr_br_flags_set(struct mlxsw_sp_port *mlxsw_sp_port, ...@@ -675,29 +675,37 @@ static int mlxsw_sp_port_attr_br_flags_set(struct mlxsw_sp_port *mlxsw_sp_port,
if (!bridge_port) if (!bridge_port)
return 0; return 0;
err = mlxsw_sp_bridge_port_flood_table_set(mlxsw_sp_port, bridge_port, if (flags.mask & BR_FLOOD) {
MLXSW_SP_FLOOD_TYPE_UC, err = mlxsw_sp_bridge_port_flood_table_set(mlxsw_sp_port,
brport_flags & BR_FLOOD); bridge_port,
if (err) MLXSW_SP_FLOOD_TYPE_UC,
return err; flags.val & BR_FLOOD);
if (err)
return err;
}
err = mlxsw_sp_bridge_port_learning_set(mlxsw_sp_port, bridge_port, if (flags.mask & BR_LEARNING) {
brport_flags & BR_LEARNING); err = mlxsw_sp_bridge_port_learning_set(mlxsw_sp_port,
if (err) bridge_port,
return err; flags.val & BR_LEARNING);
if (err)
return err;
}
if (bridge_port->bridge_device->multicast_enabled) if (bridge_port->bridge_device->multicast_enabled)
goto out; goto out;
err = mlxsw_sp_bridge_port_flood_table_set(mlxsw_sp_port, bridge_port, if (flags.mask & BR_MCAST_FLOOD) {
MLXSW_SP_FLOOD_TYPE_MC, err = mlxsw_sp_bridge_port_flood_table_set(mlxsw_sp_port,
brport_flags & bridge_port,
BR_MCAST_FLOOD); MLXSW_SP_FLOOD_TYPE_MC,
if (err) flags.val & BR_MCAST_FLOOD);
return err; if (err)
return err;
}
out: out:
memcpy(&bridge_port->flags, &brport_flags, sizeof(brport_flags)); memcpy(&bridge_port->flags, &flags.val, sizeof(flags.val));
return 0; return 0;
} }
......
...@@ -1576,7 +1576,7 @@ rocker_world_port_attr_bridge_flags_support_get(const struct rocker_port * ...@@ -1576,7 +1576,7 @@ rocker_world_port_attr_bridge_flags_support_get(const struct rocker_port *
static int static int
rocker_world_port_attr_pre_bridge_flags_set(struct rocker_port *rocker_port, rocker_world_port_attr_pre_bridge_flags_set(struct rocker_port *rocker_port,
unsigned long brport_flags) struct switchdev_brport_flags flags)
{ {
struct rocker_world_ops *wops = rocker_port->rocker->wops; struct rocker_world_ops *wops = rocker_port->rocker->wops;
unsigned long brport_flags_s; unsigned long brport_flags_s;
...@@ -1590,7 +1590,7 @@ rocker_world_port_attr_pre_bridge_flags_set(struct rocker_port *rocker_port, ...@@ -1590,7 +1590,7 @@ rocker_world_port_attr_pre_bridge_flags_set(struct rocker_port *rocker_port,
if (err) if (err)
return err; return err;
if (brport_flags & ~brport_flags_s) if (flags.mask & ~brport_flags_s)
return -EINVAL; return -EINVAL;
return 0; return 0;
...@@ -1598,14 +1598,14 @@ rocker_world_port_attr_pre_bridge_flags_set(struct rocker_port *rocker_port, ...@@ -1598,14 +1598,14 @@ rocker_world_port_attr_pre_bridge_flags_set(struct rocker_port *rocker_port,
static int static int
rocker_world_port_attr_bridge_flags_set(struct rocker_port *rocker_port, rocker_world_port_attr_bridge_flags_set(struct rocker_port *rocker_port,
unsigned long brport_flags) struct switchdev_brport_flags flags)
{ {
struct rocker_world_ops *wops = rocker_port->rocker->wops; struct rocker_world_ops *wops = rocker_port->rocker->wops;
if (!wops->port_attr_bridge_flags_set) if (!wops->port_attr_bridge_flags_set)
return -EOPNOTSUPP; return -EOPNOTSUPP;
return wops->port_attr_bridge_flags_set(rocker_port, brport_flags); return wops->port_attr_bridge_flags_set(rocker_port, flags.val);
} }
static int static int
...@@ -2058,7 +2058,7 @@ static int rocker_port_attr_set(struct net_device *dev, ...@@ -2058,7 +2058,7 @@ static int rocker_port_attr_set(struct net_device *dev,
break; break;
case SWITCHDEV_ATTR_ID_PORT_PRE_BRIDGE_FLAGS: case SWITCHDEV_ATTR_ID_PORT_PRE_BRIDGE_FLAGS:
err = rocker_world_port_attr_pre_bridge_flags_set(rocker_port, err = rocker_world_port_attr_pre_bridge_flags_set(rocker_port,
attr->u.brport_flags); attr->u.brport_flags);
break; break;
case SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS: case SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS:
err = rocker_world_port_attr_bridge_flags_set(rocker_port, err = rocker_world_port_attr_bridge_flags_set(rocker_port,
......
...@@ -55,26 +55,30 @@ static int am65_cpsw_port_stp_state_set(struct am65_cpsw_port *port, u8 state) ...@@ -55,26 +55,30 @@ static int am65_cpsw_port_stp_state_set(struct am65_cpsw_port *port, u8 state)
static int am65_cpsw_port_attr_br_flags_set(struct am65_cpsw_port *port, static int am65_cpsw_port_attr_br_flags_set(struct am65_cpsw_port *port,
struct net_device *orig_dev, struct net_device *orig_dev,
unsigned long brport_flags) struct switchdev_brport_flags flags)
{ {
struct am65_cpsw_common *cpsw = port->common; struct am65_cpsw_common *cpsw = port->common;
bool unreg_mcast_add = false;
if (brport_flags & BR_MCAST_FLOOD) if (flags.mask & BR_MCAST_FLOOD) {
unreg_mcast_add = true; bool unreg_mcast_add = false;
netdev_dbg(port->ndev, "BR_MCAST_FLOOD: %d port %u\n",
unreg_mcast_add, port->port_id);
cpsw_ale_set_unreg_mcast(cpsw->ale, BIT(port->port_id), if (flags.val & BR_MCAST_FLOOD)
unreg_mcast_add); unreg_mcast_add = true;
netdev_dbg(port->ndev, "BR_MCAST_FLOOD: %d port %u\n",
unreg_mcast_add, port->port_id);
cpsw_ale_set_unreg_mcast(cpsw->ale, BIT(port->port_id),
unreg_mcast_add);
}
return 0; return 0;
} }
static int am65_cpsw_port_attr_br_flags_pre_set(struct net_device *netdev, static int am65_cpsw_port_attr_br_flags_pre_set(struct net_device *netdev,
unsigned long flags) struct switchdev_brport_flags flags)
{ {
if (flags & ~(BR_LEARNING | BR_MCAST_FLOOD)) if (flags.mask & ~(BR_LEARNING | BR_MCAST_FLOOD))
return -EINVAL; return -EINVAL;
return 0; return 0;
......
...@@ -57,26 +57,30 @@ static int cpsw_port_stp_state_set(struct cpsw_priv *priv, u8 state) ...@@ -57,26 +57,30 @@ static int cpsw_port_stp_state_set(struct cpsw_priv *priv, u8 state)
static int cpsw_port_attr_br_flags_set(struct cpsw_priv *priv, static int cpsw_port_attr_br_flags_set(struct cpsw_priv *priv,
struct net_device *orig_dev, struct net_device *orig_dev,
unsigned long brport_flags) struct switchdev_brport_flags flags)
{ {
struct cpsw_common *cpsw = priv->cpsw; struct cpsw_common *cpsw = priv->cpsw;
bool unreg_mcast_add = false;
if (brport_flags & BR_MCAST_FLOOD) if (flags.mask & BR_MCAST_FLOOD) {
unreg_mcast_add = true; bool unreg_mcast_add = false;
dev_dbg(priv->dev, "BR_MCAST_FLOOD: %d port %u\n",
unreg_mcast_add, priv->emac_port);
cpsw_ale_set_unreg_mcast(cpsw->ale, BIT(priv->emac_port), if (flags.val & BR_MCAST_FLOOD)
unreg_mcast_add); unreg_mcast_add = true;
dev_dbg(priv->dev, "BR_MCAST_FLOOD: %d port %u\n",
unreg_mcast_add, priv->emac_port);
cpsw_ale_set_unreg_mcast(cpsw->ale, BIT(priv->emac_port),
unreg_mcast_add);
}
return 0; return 0;
} }
static int cpsw_port_attr_br_flags_pre_set(struct net_device *netdev, static int cpsw_port_attr_br_flags_pre_set(struct net_device *netdev,
unsigned long flags) struct switchdev_brport_flags flags)
{ {
if (flags & ~(BR_LEARNING | BR_MCAST_FLOOD)) if (flags.mask & ~(BR_LEARNING | BR_MCAST_FLOOD))
return -EINVAL; return -EINVAL;
return 0; return 0;
......
...@@ -908,31 +908,39 @@ static int dpaa2_switch_port_attr_stp_state_set(struct net_device *netdev, ...@@ -908,31 +908,39 @@ static int dpaa2_switch_port_attr_stp_state_set(struct net_device *netdev,
return dpaa2_switch_port_set_stp_state(port_priv, state); return dpaa2_switch_port_set_stp_state(port_priv, state);
} }
static int dpaa2_switch_port_attr_br_flags_pre_set(struct net_device *netdev, static int
unsigned long flags) dpaa2_switch_port_attr_br_flags_pre_set(struct net_device *netdev,
struct switchdev_brport_flags flags)
{ {
if (flags & ~(BR_LEARNING | BR_FLOOD)) if (flags.mask & ~(BR_LEARNING | BR_FLOOD))
return -EINVAL; return -EINVAL;
return 0; return 0;
} }
static int dpaa2_switch_port_attr_br_flags_set(struct net_device *netdev, static int
unsigned long flags) dpaa2_switch_port_attr_br_flags_set(struct net_device *netdev,
struct switchdev_brport_flags flags)
{ {
struct ethsw_port_priv *port_priv = netdev_priv(netdev); struct ethsw_port_priv *port_priv = netdev_priv(netdev);
int err = 0; int err = 0;
/* Learning is enabled per switch */ if (flags.mask & BR_LEARNING) {
err = dpaa2_switch_set_learning(port_priv->ethsw_data, /* Learning is enabled per switch */
!!(flags & BR_LEARNING)); err = dpaa2_switch_set_learning(port_priv->ethsw_data,
if (err) !!(flags.val & BR_LEARNING));
goto exit; if (err)
return err;
}
err = dpaa2_switch_port_set_flood(port_priv, !!(flags & BR_FLOOD)); if (flags.mask & BR_FLOOD) {
err = dpaa2_switch_port_set_flood(port_priv,
!!(flags.val & BR_FLOOD));
if (err)
return err;
}
exit: return 0;
return err;
} }
static int dpaa2_switch_port_attr_set(struct net_device *netdev, static int dpaa2_switch_port_attr_set(struct net_device *netdev,
......
...@@ -32,6 +32,11 @@ enum switchdev_attr_id { ...@@ -32,6 +32,11 @@ enum switchdev_attr_id {
#endif #endif
}; };
struct switchdev_brport_flags {
unsigned long val;
unsigned long mask;
};
struct switchdev_attr { struct switchdev_attr {
struct net_device *orig_dev; struct net_device *orig_dev;
enum switchdev_attr_id id; enum switchdev_attr_id id;
...@@ -40,7 +45,7 @@ struct switchdev_attr { ...@@ -40,7 +45,7 @@ struct switchdev_attr {
void (*complete)(struct net_device *dev, int err, void *priv); void (*complete)(struct net_device *dev, int err, void *priv);
union { union {
u8 stp_state; /* PORT_STP_STATE */ u8 stp_state; /* PORT_STP_STATE */
unsigned long brport_flags; /* PORT_{PRE}_BRIDGE_FLAGS */ struct switchdev_brport_flags brport_flags; /* PORT_BRIDGE_FLAGS */
bool mrouter; /* PORT_MROUTER */ bool mrouter; /* PORT_MROUTER */
clock_t ageing_time; /* BRIDGE_AGEING_TIME */ clock_t ageing_time; /* BRIDGE_AGEING_TIME */
bool vlan_filtering; /* BRIDGE_VLAN_FILTERING */ bool vlan_filtering; /* BRIDGE_VLAN_FILTERING */
......
...@@ -65,7 +65,6 @@ int br_switchdev_set_port_flag(struct net_bridge_port *p, ...@@ -65,7 +65,6 @@ int br_switchdev_set_port_flag(struct net_bridge_port *p,
{ {
struct switchdev_attr attr = { struct switchdev_attr attr = {
.orig_dev = p->dev, .orig_dev = p->dev,
.id = SWITCHDEV_ATTR_ID_PORT_PRE_BRIDGE_FLAGS,
}; };
struct switchdev_notifier_port_attr_info info = { struct switchdev_notifier_port_attr_info info = {
.attr = &attr, .attr = &attr,
...@@ -76,7 +75,9 @@ int br_switchdev_set_port_flag(struct net_bridge_port *p, ...@@ -76,7 +75,9 @@ int br_switchdev_set_port_flag(struct net_bridge_port *p,
if (!mask) if (!mask)
return 0; return 0;
attr.u.brport_flags = mask; attr.id = SWITCHDEV_ATTR_ID_PORT_PRE_BRIDGE_FLAGS;
attr.u.brport_flags.val = flags;
attr.u.brport_flags.mask = mask;
/* We run from atomic context here */ /* We run from atomic context here */
err = call_switchdev_notifiers(SWITCHDEV_PORT_ATTR_SET, p->dev, err = call_switchdev_notifiers(SWITCHDEV_PORT_ATTR_SET, p->dev,
...@@ -94,7 +95,6 @@ int br_switchdev_set_port_flag(struct net_bridge_port *p, ...@@ -94,7 +95,6 @@ int br_switchdev_set_port_flag(struct net_bridge_port *p,
attr.id = SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS; attr.id = SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS;
attr.flags = SWITCHDEV_F_DEFER; attr.flags = SWITCHDEV_F_DEFER;
attr.u.brport_flags = flags;
err = switchdev_port_attr_set(p->dev, &attr); err = switchdev_port_attr_set(p->dev, &attr);
if (err) { if (err) {
......
...@@ -183,8 +183,10 @@ int dsa_port_mdb_add(const struct dsa_port *dp, ...@@ -183,8 +183,10 @@ int dsa_port_mdb_add(const struct dsa_port *dp,
const struct switchdev_obj_port_mdb *mdb); const struct switchdev_obj_port_mdb *mdb);
int dsa_port_mdb_del(const struct dsa_port *dp, int dsa_port_mdb_del(const struct dsa_port *dp,
const struct switchdev_obj_port_mdb *mdb); const struct switchdev_obj_port_mdb *mdb);
int dsa_port_pre_bridge_flags(const struct dsa_port *dp, unsigned long flags); int dsa_port_pre_bridge_flags(const struct dsa_port *dp,
int dsa_port_bridge_flags(const struct dsa_port *dp, unsigned long flags); struct switchdev_brport_flags flags);
int dsa_port_bridge_flags(const struct dsa_port *dp,
struct switchdev_brport_flags flags);
int dsa_port_mrouter(struct dsa_port *dp, bool mrouter); int dsa_port_mrouter(struct dsa_port *dp, bool mrouter);
int dsa_port_vlan_add(struct dsa_port *dp, int dsa_port_vlan_add(struct dsa_port *dp,
const struct switchdev_obj_port_vlan *vlan); const struct switchdev_obj_port_vlan *vlan);
......
...@@ -125,21 +125,22 @@ void dsa_port_disable(struct dsa_port *dp) ...@@ -125,21 +125,22 @@ void dsa_port_disable(struct dsa_port *dp)
static void dsa_port_change_brport_flags(struct dsa_port *dp, static void dsa_port_change_brport_flags(struct dsa_port *dp,
bool bridge_offload) bool bridge_offload)
{ {
unsigned long mask, flags; struct switchdev_brport_flags flags;
int flag, err; int flag;
mask = BR_LEARNING | BR_FLOOD | BR_MCAST_FLOOD | BR_BCAST_FLOOD; flags.mask = BR_LEARNING | BR_FLOOD | BR_MCAST_FLOOD | BR_BCAST_FLOOD;
if (bridge_offload) if (bridge_offload)
flags = mask; flags.val = flags.mask;
else else
flags = mask & ~BR_LEARNING; flags.val = flags.mask & ~BR_LEARNING;
for_each_set_bit(flag, &mask, 32) { for_each_set_bit(flag, &flags.mask, 32) {
err = dsa_port_pre_bridge_flags(dp, BIT(flag)); struct switchdev_brport_flags tmp;
if (err)
continue; tmp.val = flags.val & BIT(flag);
tmp.mask = BIT(flag);
dsa_port_bridge_flags(dp, flags & BIT(flag)); dsa_port_bridge_flags(dp, tmp);
} }
} }
...@@ -423,26 +424,29 @@ int dsa_port_ageing_time(struct dsa_port *dp, clock_t ageing_clock) ...@@ -423,26 +424,29 @@ int dsa_port_ageing_time(struct dsa_port *dp, clock_t ageing_clock)
return 0; return 0;
} }
int dsa_port_pre_bridge_flags(const struct dsa_port *dp, unsigned long flags) int dsa_port_pre_bridge_flags(const struct dsa_port *dp,
struct switchdev_brport_flags flags)
{ {
struct dsa_switch *ds = dp->ds; struct dsa_switch *ds = dp->ds;
if (!ds->ops->port_egress_floods || if (!ds->ops->port_egress_floods ||
(flags & ~(BR_FLOOD | BR_MCAST_FLOOD))) (flags.mask & ~(BR_FLOOD | BR_MCAST_FLOOD)))
return -EINVAL; return -EINVAL;
return 0; return 0;
} }
int dsa_port_bridge_flags(const struct dsa_port *dp, unsigned long flags) int dsa_port_bridge_flags(const struct dsa_port *dp,
struct switchdev_brport_flags flags)
{ {
struct dsa_switch *ds = dp->ds; struct dsa_switch *ds = dp->ds;
int port = dp->index; int port = dp->index;
int err = 0; int err = 0;
if (ds->ops->port_egress_floods) if (ds->ops->port_egress_floods)
err = ds->ops->port_egress_floods(ds, port, flags & BR_FLOOD, err = ds->ops->port_egress_floods(ds, port,
flags & BR_MCAST_FLOOD); flags.val & BR_FLOOD,
flags.val & BR_MCAST_FLOOD);
return err; return err;
} }
......
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