Skip to content

Commit 9c428c5

Browse files
viviendavem330
authored andcommitted
net: dsa: add switch vlan bitmap functions
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]>
1 parent 3709aad commit 9c428c5

File tree

1 file changed

+34
-15
lines changed

1 file changed

+34
-15
lines changed

net/dsa/switch.c

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,43 @@ static int dsa_switch_mdb_del(struct dsa_switch *ds,
157157
return 0;
158158
}
159159

160+
static int
161+
dsa_switch_vlan_prepare_bitmap(struct dsa_switch *ds,
162+
const struct switchdev_obj_port_vlan *vlan,
163+
const unsigned long *bitmap)
164+
{
165+
int port, err;
166+
167+
if (!ds->ops->port_vlan_prepare || !ds->ops->port_vlan_add)
168+
return -EOPNOTSUPP;
169+
170+
for_each_set_bit(port, bitmap, ds->num_ports) {
171+
err = ds->ops->port_vlan_prepare(ds, port, vlan);
172+
if (err)
173+
return err;
174+
}
175+
176+
return 0;
177+
}
178+
179+
static void
180+
dsa_switch_vlan_add_bitmap(struct dsa_switch *ds,
181+
const struct switchdev_obj_port_vlan *vlan,
182+
const unsigned long *bitmap)
183+
{
184+
int port;
185+
186+
for_each_set_bit(port, bitmap, ds->num_ports)
187+
ds->ops->port_vlan_add(ds, port, vlan);
188+
}
189+
160190
static int dsa_switch_vlan_add(struct dsa_switch *ds,
161191
struct dsa_notifier_vlan_info *info)
162192
{
163193
const struct switchdev_obj_port_vlan *vlan = info->vlan;
164194
struct switchdev_trans *trans = info->trans;
165195
DECLARE_BITMAP(members, ds->num_ports);
166-
int port, err;
196+
int port;
167197

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

176-
if (switchdev_trans_ph_prepare(trans)) {
177-
if (!ds->ops->port_vlan_prepare || !ds->ops->port_vlan_add)
178-
return -EOPNOTSUPP;
206+
if (switchdev_trans_ph_prepare(trans))
207+
return dsa_switch_vlan_prepare_bitmap(ds, vlan, members);
179208

180-
for_each_set_bit(port, members, ds->num_ports) {
181-
err = ds->ops->port_vlan_prepare(ds, port, vlan);
182-
if (err)
183-
return err;
184-
}
185-
186-
return 0;
187-
}
188-
189-
for_each_set_bit(port, members, ds->num_ports)
190-
ds->ops->port_vlan_add(ds, port, vlan);
209+
dsa_switch_vlan_add_bitmap(ds, vlan, members);
191210

192211
return 0;
193212
}

0 commit comments

Comments
 (0)