Skip to content

Commit 5420683

Browse files
committed
Merge branch 'dsa-simplify-switchdev-prepare-phase'
Vivien Didelot says: ==================== net: dsa: simplify switchdev prepare phase This patch series brings no functional changes. It removes the unused switchdev_trans arguments from the dsa_switch_ops for both MDB and VLAN operations, and provides functions to prepare and add these objects for a given bitmap of ports. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 183dea5 + e6db98d commit 5420683

File tree

8 files changed

+93
-75
lines changed

8 files changed

+93
-75
lines changed

drivers/net/dsa/b53/b53_common.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,8 +1029,7 @@ int b53_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering)
10291029
EXPORT_SYMBOL(b53_vlan_filtering);
10301030

10311031
int b53_vlan_prepare(struct dsa_switch *ds, int port,
1032-
const struct switchdev_obj_port_vlan *vlan,
1033-
struct switchdev_trans *trans)
1032+
const struct switchdev_obj_port_vlan *vlan)
10341033
{
10351034
struct b53_device *dev = ds->priv;
10361035

@@ -1047,8 +1046,7 @@ int b53_vlan_prepare(struct dsa_switch *ds, int port,
10471046
EXPORT_SYMBOL(b53_vlan_prepare);
10481047

10491048
void b53_vlan_add(struct dsa_switch *ds, int port,
1050-
const struct switchdev_obj_port_vlan *vlan,
1051-
struct switchdev_trans *trans)
1049+
const struct switchdev_obj_port_vlan *vlan)
10521050
{
10531051
struct b53_device *dev = ds->priv;
10541052
bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;

drivers/net/dsa/b53/b53_priv.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,11 +295,9 @@ void b53_br_set_stp_state(struct dsa_switch *ds, int port, u8 state);
295295
void b53_br_fast_age(struct dsa_switch *ds, int port);
296296
int b53_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering);
297297
int b53_vlan_prepare(struct dsa_switch *ds, int port,
298-
const struct switchdev_obj_port_vlan *vlan,
299-
struct switchdev_trans *trans);
298+
const struct switchdev_obj_port_vlan *vlan);
300299
void b53_vlan_add(struct dsa_switch *ds, int port,
301-
const struct switchdev_obj_port_vlan *vlan,
302-
struct switchdev_trans *trans);
300+
const struct switchdev_obj_port_vlan *vlan);
303301
int b53_vlan_del(struct dsa_switch *ds, int port,
304302
const struct switchdev_obj_port_vlan *vlan);
305303
int b53_fdb_add(struct dsa_switch *ds, int port,

drivers/net/dsa/dsa_loop.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,9 @@ static int dsa_loop_port_vlan_filtering(struct dsa_switch *ds, int port,
174174
return 0;
175175
}
176176

177-
static int dsa_loop_port_vlan_prepare(struct dsa_switch *ds, int port,
178-
const struct switchdev_obj_port_vlan *vlan,
179-
struct switchdev_trans *trans)
177+
static int
178+
dsa_loop_port_vlan_prepare(struct dsa_switch *ds, int port,
179+
const struct switchdev_obj_port_vlan *vlan)
180180
{
181181
struct dsa_loop_priv *ps = ds->priv;
182182
struct mii_bus *bus = ps->bus;
@@ -193,8 +193,7 @@ static int dsa_loop_port_vlan_prepare(struct dsa_switch *ds, int port,
193193
}
194194

195195
static void dsa_loop_port_vlan_add(struct dsa_switch *ds, int port,
196-
const struct switchdev_obj_port_vlan *vlan,
197-
struct switchdev_trans *trans)
196+
const struct switchdev_obj_port_vlan *vlan)
198197
{
199198
bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
200199
bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;

drivers/net/dsa/lan9303-core.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,8 +1217,7 @@ static int lan9303_port_fdb_dump(struct dsa_switch *ds, int port,
12171217
}
12181218

12191219
static int lan9303_port_mdb_prepare(struct dsa_switch *ds, int port,
1220-
const struct switchdev_obj_port_mdb *mdb,
1221-
struct switchdev_trans *trans)
1220+
const struct switchdev_obj_port_mdb *mdb)
12221221
{
12231222
struct lan9303 *chip = ds->priv;
12241223

@@ -1235,8 +1234,7 @@ static int lan9303_port_mdb_prepare(struct dsa_switch *ds, int port,
12351234
}
12361235

12371236
static void lan9303_port_mdb_add(struct dsa_switch *ds, int port,
1238-
const struct switchdev_obj_port_mdb *mdb,
1239-
struct switchdev_trans *trans)
1237+
const struct switchdev_obj_port_mdb *mdb)
12401238
{
12411239
struct lan9303 *chip = ds->priv;
12421240

drivers/net/dsa/microchip/ksz_common.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -559,17 +559,15 @@ static int ksz_port_vlan_filtering(struct dsa_switch *ds, int port, bool flag)
559559
}
560560

561561
static int ksz_port_vlan_prepare(struct dsa_switch *ds, int port,
562-
const struct switchdev_obj_port_vlan *vlan,
563-
struct switchdev_trans *trans)
562+
const struct switchdev_obj_port_vlan *vlan)
564563
{
565564
/* nothing needed */
566565

567566
return 0;
568567
}
569568

570569
static void ksz_port_vlan_add(struct dsa_switch *ds, int port,
571-
const struct switchdev_obj_port_vlan *vlan,
572-
struct switchdev_trans *trans)
570+
const struct switchdev_obj_port_vlan *vlan)
573571
{
574572
struct ksz_device *dev = ds->priv;
575573
u32 vlan_table[3];
@@ -858,16 +856,14 @@ static int ksz_port_fdb_dump(struct dsa_switch *ds, int port,
858856
}
859857

860858
static int ksz_port_mdb_prepare(struct dsa_switch *ds, int port,
861-
const struct switchdev_obj_port_mdb *mdb,
862-
struct switchdev_trans *trans)
859+
const struct switchdev_obj_port_mdb *mdb)
863860
{
864861
/* nothing to do */
865862
return 0;
866863
}
867864

868865
static void ksz_port_mdb_add(struct dsa_switch *ds, int port,
869-
const struct switchdev_obj_port_mdb *mdb,
870-
struct switchdev_trans *trans)
866+
const struct switchdev_obj_port_mdb *mdb)
871867
{
872868
struct ksz_device *dev = ds->priv;
873869
u32 static_table[4];

drivers/net/dsa/mv88e6xxx/chip.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,8 +1185,7 @@ static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
11851185

11861186
static int
11871187
mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1188-
const struct switchdev_obj_port_vlan *vlan,
1189-
struct switchdev_trans *trans)
1188+
const struct switchdev_obj_port_vlan *vlan)
11901189
{
11911190
struct mv88e6xxx_chip *chip = ds->priv;
11921191
int err;
@@ -1295,8 +1294,7 @@ static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
12951294
}
12961295

12971296
static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1298-
const struct switchdev_obj_port_vlan *vlan,
1299-
struct switchdev_trans *trans)
1297+
const struct switchdev_obj_port_vlan *vlan)
13001298
{
13011299
struct mv88e6xxx_chip *chip = ds->priv;
13021300
bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
@@ -3788,8 +3786,7 @@ static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
37883786
}
37893787

37903788
static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
3791-
const struct switchdev_obj_port_mdb *mdb,
3792-
struct switchdev_trans *trans)
3789+
const struct switchdev_obj_port_mdb *mdb)
37933790
{
37943791
/* We don't need any dynamic resource from the kernel (yet),
37953792
* so skip the prepare phase.
@@ -3799,8 +3796,7 @@ static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
37993796
}
38003797

38013798
static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
3802-
const struct switchdev_obj_port_mdb *mdb,
3803-
struct switchdev_trans *trans)
3799+
const struct switchdev_obj_port_mdb *mdb)
38043800
{
38053801
struct mv88e6xxx_chip *chip = ds->priv;
38063802

include/net/dsa.h

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -412,12 +412,10 @@ struct dsa_switch_ops {
412412
*/
413413
int (*port_vlan_filtering)(struct dsa_switch *ds, int port,
414414
bool vlan_filtering);
415-
int (*port_vlan_prepare)(struct dsa_switch *ds, int port,
416-
const struct switchdev_obj_port_vlan *vlan,
417-
struct switchdev_trans *trans);
418-
void (*port_vlan_add)(struct dsa_switch *ds, int port,
419-
const struct switchdev_obj_port_vlan *vlan,
420-
struct switchdev_trans *trans);
415+
int (*port_vlan_prepare)(struct dsa_switch *ds, int port,
416+
const struct switchdev_obj_port_vlan *vlan);
417+
void (*port_vlan_add)(struct dsa_switch *ds, int port,
418+
const struct switchdev_obj_port_vlan *vlan);
421419
int (*port_vlan_del)(struct dsa_switch *ds, int port,
422420
const struct switchdev_obj_port_vlan *vlan);
423421
/*
@@ -433,12 +431,10 @@ struct dsa_switch_ops {
433431
/*
434432
* Multicast database
435433
*/
436-
int (*port_mdb_prepare)(struct dsa_switch *ds, int port,
437-
const struct switchdev_obj_port_mdb *mdb,
438-
struct switchdev_trans *trans);
439-
void (*port_mdb_add)(struct dsa_switch *ds, int port,
440-
const struct switchdev_obj_port_mdb *mdb,
441-
struct switchdev_trans *trans);
434+
int (*port_mdb_prepare)(struct dsa_switch *ds, int port,
435+
const struct switchdev_obj_port_mdb *mdb);
436+
void (*port_mdb_add)(struct dsa_switch *ds, int port,
437+
const struct switchdev_obj_port_mdb *mdb);
442438
int (*port_mdb_del)(struct dsa_switch *ds, int port,
443439
const struct switchdev_obj_port_mdb *mdb);
444440
/*

net/dsa/switch.c

Lines changed: 67 additions & 30 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, trans);
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, trans);
159+
dsa_switch_mdb_add_bitmap(ds, mdb, group);
142160

143161
return 0;
144162
}
@@ -157,13 +175,43 @@ static int dsa_switch_mdb_del(struct dsa_switch *ds,
157175
return 0;
158176
}
159177

178+
static int
179+
dsa_switch_vlan_prepare_bitmap(struct dsa_switch *ds,
180+
const struct switchdev_obj_port_vlan *vlan,
181+
const unsigned long *bitmap)
182+
{
183+
int port, err;
184+
185+
if (!ds->ops->port_vlan_prepare || !ds->ops->port_vlan_add)
186+
return -EOPNOTSUPP;
187+
188+
for_each_set_bit(port, bitmap, ds->num_ports) {
189+
err = ds->ops->port_vlan_prepare(ds, port, vlan);
190+
if (err)
191+
return err;
192+
}
193+
194+
return 0;
195+
}
196+
197+
static void
198+
dsa_switch_vlan_add_bitmap(struct dsa_switch *ds,
199+
const struct switchdev_obj_port_vlan *vlan,
200+
const unsigned long *bitmap)
201+
{
202+
int port;
203+
204+
for_each_set_bit(port, bitmap, ds->num_ports)
205+
ds->ops->port_vlan_add(ds, port, vlan);
206+
}
207+
160208
static int dsa_switch_vlan_add(struct dsa_switch *ds,
161209
struct dsa_notifier_vlan_info *info)
162210
{
163211
const struct switchdev_obj_port_vlan *vlan = info->vlan;
164212
struct switchdev_trans *trans = info->trans;
165213
DECLARE_BITMAP(members, ds->num_ports);
166-
int port, err;
214+
int port;
167215

168216
/* Build a mask of VLAN members */
169217
bitmap_zero(members, ds->num_ports);
@@ -173,21 +221,10 @@ static int dsa_switch_vlan_add(struct dsa_switch *ds,
173221
if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
174222
set_bit(port, members);
175223

176-
if (switchdev_trans_ph_prepare(trans)) {
177-
if (!ds->ops->port_vlan_prepare || !ds->ops->port_vlan_add)
178-
return -EOPNOTSUPP;
179-
180-
for_each_set_bit(port, members, ds->num_ports) {
181-
err = ds->ops->port_vlan_prepare(ds, port, vlan, trans);
182-
if (err)
183-
return err;
184-
}
185-
186-
return 0;
187-
}
224+
if (switchdev_trans_ph_prepare(trans))
225+
return dsa_switch_vlan_prepare_bitmap(ds, vlan, members);
188226

189-
for_each_set_bit(port, members, ds->num_ports)
190-
ds->ops->port_vlan_add(ds, port, vlan, trans);
227+
dsa_switch_vlan_add_bitmap(ds, vlan, members);
191228

192229
return 0;
193230
}

0 commit comments

Comments
 (0)