Skip to content

Commit e6db98d

Browse files
viviendavem330
authored andcommitted
net: dsa: add switch mdb bitmap functions
This patch brings no functional changes. It moves out the MDB code iterating on a multicast group into new dsa_switch_mdb_{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 9c428c5 commit e6db98d

File tree

1 file changed

+33
-15
lines changed

1 file changed

+33
-15
lines changed

net/dsa/switch.c

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,42 @@ static int dsa_switch_fdb_del(struct dsa_switch *ds,
108108
info->vid);
109109
}
110110

111+
static int
112+
dsa_switch_mdb_prepare_bitmap(struct dsa_switch *ds,
113+
const struct switchdev_obj_port_mdb *mdb,
114+
const unsigned long *bitmap)
115+
{
116+
int port, err;
117+
118+
if (!ds->ops->port_mdb_prepare || !ds->ops->port_mdb_add)
119+
return -EOPNOTSUPP;
120+
121+
for_each_set_bit(port, bitmap, ds->num_ports) {
122+
err = ds->ops->port_mdb_prepare(ds, port, mdb);
123+
if (err)
124+
return err;
125+
}
126+
127+
return 0;
128+
}
129+
130+
static void dsa_switch_mdb_add_bitmap(struct dsa_switch *ds,
131+
const struct switchdev_obj_port_mdb *mdb,
132+
const unsigned long *bitmap)
133+
{
134+
int port;
135+
136+
for_each_set_bit(port, bitmap, ds->num_ports)
137+
ds->ops->port_mdb_add(ds, port, mdb);
138+
}
139+
111140
static int dsa_switch_mdb_add(struct dsa_switch *ds,
112141
struct dsa_notifier_mdb_info *info)
113142
{
114143
const struct switchdev_obj_port_mdb *mdb = info->mdb;
115144
struct switchdev_trans *trans = info->trans;
116145
DECLARE_BITMAP(group, ds->num_ports);
117-
int port, err;
146+
int port;
118147

119148
/* Build a mask of Multicast group members */
120149
bitmap_zero(group, ds->num_ports);
@@ -124,21 +153,10 @@ static int dsa_switch_mdb_add(struct dsa_switch *ds,
124153
if (dsa_is_dsa_port(ds, port))
125154
set_bit(port, group);
126155

127-
if (switchdev_trans_ph_prepare(trans)) {
128-
if (!ds->ops->port_mdb_prepare || !ds->ops->port_mdb_add)
129-
return -EOPNOTSUPP;
130-
131-
for_each_set_bit(port, group, ds->num_ports) {
132-
err = ds->ops->port_mdb_prepare(ds, port, mdb);
133-
if (err)
134-
return err;
135-
}
136-
137-
return 0;
138-
}
156+
if (switchdev_trans_ph_prepare(trans))
157+
return dsa_switch_mdb_prepare_bitmap(ds, mdb, group);
139158

140-
for_each_set_bit(port, group, ds->num_ports)
141-
ds->ops->port_mdb_add(ds, port, mdb);
159+
dsa_switch_mdb_add_bitmap(ds, mdb, group);
142160

143161
return 0;
144162
}

0 commit comments

Comments
 (0)