Skip to content

Commit

Permalink
net: dsa: add switch vlan bitmap functions
Browse files Browse the repository at this point in the history
This patch brings no functional changes.
It moves out the VLAN code iterating on a list of VLAN members into new
dsa_switch_vlan_{prepare,add}_bitmap() functions.

This gives us a better isolation of the two switchdev phases.

Signed-off-by: Vivien Didelot <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
vivien authored and davem330 committed Dec 3, 2017
1 parent 3709aad commit 9c428c5
Showing 1 changed file with 34 additions and 15 deletions.
49 changes: 34 additions & 15 deletions net/dsa/switch.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,43 @@ static int dsa_switch_mdb_del(struct dsa_switch *ds,
return 0;
}

static int
dsa_switch_vlan_prepare_bitmap(struct dsa_switch *ds,
const struct switchdev_obj_port_vlan *vlan,
const unsigned long *bitmap)
{
int port, err;

if (!ds->ops->port_vlan_prepare || !ds->ops->port_vlan_add)
return -EOPNOTSUPP;

for_each_set_bit(port, bitmap, ds->num_ports) {
err = ds->ops->port_vlan_prepare(ds, port, vlan);
if (err)
return err;
}

return 0;
}

static void
dsa_switch_vlan_add_bitmap(struct dsa_switch *ds,
const struct switchdev_obj_port_vlan *vlan,
const unsigned long *bitmap)
{
int port;

for_each_set_bit(port, bitmap, ds->num_ports)
ds->ops->port_vlan_add(ds, port, vlan);
}

static int dsa_switch_vlan_add(struct dsa_switch *ds,
struct dsa_notifier_vlan_info *info)
{
const struct switchdev_obj_port_vlan *vlan = info->vlan;
struct switchdev_trans *trans = info->trans;
DECLARE_BITMAP(members, ds->num_ports);
int port, err;
int port;

/* Build a mask of VLAN members */
bitmap_zero(members, ds->num_ports);
Expand All @@ -173,21 +203,10 @@ static int dsa_switch_vlan_add(struct dsa_switch *ds,
if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
set_bit(port, members);

if (switchdev_trans_ph_prepare(trans)) {
if (!ds->ops->port_vlan_prepare || !ds->ops->port_vlan_add)
return -EOPNOTSUPP;
if (switchdev_trans_ph_prepare(trans))
return dsa_switch_vlan_prepare_bitmap(ds, vlan, members);

for_each_set_bit(port, members, ds->num_ports) {
err = ds->ops->port_vlan_prepare(ds, port, vlan);
if (err)
return err;
}

return 0;
}

for_each_set_bit(port, members, ds->num_ports)
ds->ops->port_vlan_add(ds, port, vlan);
dsa_switch_vlan_add_bitmap(ds, vlan, members);

return 0;
}
Expand Down

0 comments on commit 9c428c5

Please sign in to comment.