Skip to content

Commit 1ca4aa9

Browse files
viviendavem330
authored andcommitted
net: dsa: check VLAN capability of every switch
Now that the VLAN object is propagated to every switch chip of the switch fabric, we can easily ensure that they all support the required VLAN operations before modifying an entry on a single switch. To achieve that, remove the condition skipping other target switches, and add a bitmap of VLAN members, eventually containing the target port, if we are programming the switch target. This will allow us to easily add other VLAN members, such as the DSA or CPU ports (to introduce cross-chip VLAN support) or the other port members if we want to reduce hardware accesses later. Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent c91498e commit 1ca4aa9

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

net/dsa/switch.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -159,19 +159,27 @@ static int dsa_switch_vlan_add(struct dsa_switch *ds,
159159
{
160160
const struct switchdev_obj_port_vlan *vlan = info->vlan;
161161
struct switchdev_trans *trans = info->trans;
162+
DECLARE_BITMAP(members, ds->num_ports);
163+
int port, err;
162164

163-
/* Do not care yet about other switch chips of the fabric */
164-
if (ds->index != info->sw_index)
165-
return 0;
165+
/* Build a mask of VLAN members */
166+
bitmap_zero(members, ds->num_ports);
167+
if (ds->index == info->sw_index)
168+
set_bit(info->port, members);
166169

167170
if (switchdev_trans_ph_prepare(trans)) {
168171
if (!ds->ops->port_vlan_prepare || !ds->ops->port_vlan_add)
169172
return -EOPNOTSUPP;
170173

171-
return ds->ops->port_vlan_prepare(ds, info->port, vlan, trans);
174+
for_each_set_bit(port, members, ds->num_ports) {
175+
err = ds->ops->port_vlan_prepare(ds, port, vlan, trans);
176+
if (err)
177+
return err;
178+
}
172179
}
173180

174-
ds->ops->port_vlan_add(ds, info->port, vlan, trans);
181+
for_each_set_bit(port, members, ds->num_ports)
182+
ds->ops->port_vlan_add(ds, port, vlan, trans);
175183

176184
return 0;
177185
}
@@ -181,14 +189,13 @@ static int dsa_switch_vlan_del(struct dsa_switch *ds,
181189
{
182190
const struct switchdev_obj_port_vlan *vlan = info->vlan;
183191

184-
/* Do not care yet about other switch chips of the fabric */
185-
if (ds->index != info->sw_index)
186-
return 0;
187-
188192
if (!ds->ops->port_vlan_del)
189193
return -EOPNOTSUPP;
190194

191-
return ds->ops->port_vlan_del(ds, info->port, vlan);
195+
if (ds->index == info->sw_index)
196+
return ds->ops->port_vlan_del(ds, info->port, vlan);
197+
198+
return 0;
192199
}
193200

194201
static int dsa_switch_event(struct notifier_block *nb,

0 commit comments

Comments
 (0)