Skip to content

Commit ab06900

Browse files
viviendavem330
authored andcommitted
net: switchdev: abstract object in add/del ops
Similar to the notifier_call callback of a notifier_block, change the function signature of switchdev add and del operations to: int switchdev_port_obj_add/del(struct net_device *dev, enum switchdev_obj_id id, void *obj); This allows the caller to pass a specific switchdev_obj_* structure instead of the generic switchdev_obj one. Drivers implementation of these operations and switchdev have been changed accordingly. Signed-off-by: Vivien Didelot <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 25f07ad commit ab06900

File tree

6 files changed

+99
-117
lines changed

6 files changed

+99
-117
lines changed

drivers/net/ethernet/rocker/rocker.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4437,26 +4437,25 @@ static int rocker_port_fdb_add(struct rocker_port *rocker_port,
44374437
}
44384438

44394439
static int rocker_port_obj_add(struct net_device *dev,
4440-
struct switchdev_obj *obj,
4440+
enum switchdev_obj_id id, const void *obj,
44414441
struct switchdev_trans *trans)
44424442
{
44434443
struct rocker_port *rocker_port = netdev_priv(dev);
44444444
const struct switchdev_obj_ipv4_fib *fib4;
44454445
int err = 0;
44464446

4447-
switch (obj->id) {
4447+
switch (id) {
44484448
case SWITCHDEV_OBJ_PORT_VLAN:
4449-
err = rocker_port_vlans_add(rocker_port, trans,
4450-
&obj->u.vlan);
4449+
err = rocker_port_vlans_add(rocker_port, trans, obj);
44514450
break;
44524451
case SWITCHDEV_OBJ_IPV4_FIB:
4453-
fib4 = &obj->u.ipv4_fib;
4452+
fib4 = obj;
44544453
err = rocker_port_fib_ipv4(rocker_port, trans,
44554454
htonl(fib4->dst), fib4->dst_len,
44564455
fib4->fi, fib4->tb_id, 0);
44574456
break;
44584457
case SWITCHDEV_OBJ_PORT_FDB:
4459-
err = rocker_port_fdb_add(rocker_port, trans, &obj->u.fdb);
4458+
err = rocker_port_fdb_add(rocker_port, trans, obj);
44604459
break;
44614460
default:
44624461
err = -EOPNOTSUPP;
@@ -4509,25 +4508,25 @@ static int rocker_port_fdb_del(struct rocker_port *rocker_port,
45094508
}
45104509

45114510
static int rocker_port_obj_del(struct net_device *dev,
4512-
struct switchdev_obj *obj)
4511+
enum switchdev_obj_id id, const void *obj)
45134512
{
45144513
struct rocker_port *rocker_port = netdev_priv(dev);
45154514
const struct switchdev_obj_ipv4_fib *fib4;
45164515
int err = 0;
45174516

4518-
switch (obj->id) {
4517+
switch (id) {
45194518
case SWITCHDEV_OBJ_PORT_VLAN:
4520-
err = rocker_port_vlans_del(rocker_port, &obj->u.vlan);
4519+
err = rocker_port_vlans_del(rocker_port, obj);
45214520
break;
45224521
case SWITCHDEV_OBJ_IPV4_FIB:
4523-
fib4 = &obj->u.ipv4_fib;
4522+
fib4 = obj;
45244523
err = rocker_port_fib_ipv4(rocker_port, NULL,
45254524
htonl(fib4->dst), fib4->dst_len,
45264525
fib4->fi, fib4->tb_id,
45274526
ROCKER_OP_FLAG_REMOVE);
45284527
break;
45294528
case SWITCHDEV_OBJ_PORT_FDB:
4530-
err = rocker_port_fdb_del(rocker_port, NULL, &obj->u.fdb);
4529+
err = rocker_port_fdb_del(rocker_port, NULL, obj);
45314530
break;
45324531
default:
45334532
err = -EOPNOTSUPP;

include/net/switchdev.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,12 @@ struct switchdev_ops {
115115
struct switchdev_attr *attr,
116116
struct switchdev_trans *trans);
117117
int (*switchdev_port_obj_add)(struct net_device *dev,
118-
struct switchdev_obj *obj,
118+
enum switchdev_obj_id id,
119+
const void *obj,
119120
struct switchdev_trans *trans);
120121
int (*switchdev_port_obj_del)(struct net_device *dev,
121-
struct switchdev_obj *obj);
122+
enum switchdev_obj_id id,
123+
const void *obj);
122124
int (*switchdev_port_obj_dump)(struct net_device *dev,
123125
enum switchdev_obj_id id, void *obj,
124126
int (*cb)(void *obj));
@@ -151,8 +153,10 @@ int switchdev_port_attr_get(struct net_device *dev,
151153
struct switchdev_attr *attr);
152154
int switchdev_port_attr_set(struct net_device *dev,
153155
struct switchdev_attr *attr);
154-
int switchdev_port_obj_add(struct net_device *dev, struct switchdev_obj *obj);
155-
int switchdev_port_obj_del(struct net_device *dev, struct switchdev_obj *obj);
156+
int switchdev_port_obj_add(struct net_device *dev, enum switchdev_obj_id id,
157+
const void *obj);
158+
int switchdev_port_obj_del(struct net_device *dev, enum switchdev_obj_id id,
159+
const void *obj);
156160
int switchdev_port_obj_dump(struct net_device *dev, enum switchdev_obj_id id,
157161
void *obj, int (*cb)(void *obj));
158162
int register_switchdev_notifier(struct notifier_block *nb);
@@ -199,13 +203,15 @@ static inline int switchdev_port_attr_set(struct net_device *dev,
199203
}
200204

201205
static inline int switchdev_port_obj_add(struct net_device *dev,
202-
struct switchdev_obj *obj)
206+
enum switchdev_obj_id id,
207+
const void *obj)
203208
{
204209
return -EOPNOTSUPP;
205210
}
206211

207212
static inline int switchdev_port_obj_del(struct net_device *dev,
208-
struct switchdev_obj *obj)
213+
enum switchdev_obj_id id,
214+
const void *obj)
209215
{
210216
return -EOPNOTSUPP;
211217
}

net/bridge/br_fdb.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,12 @@ static void fdb_del_hw_addr(struct net_bridge *br, const unsigned char *addr)
133133

134134
static void fdb_del_external_learn(struct net_bridge_fdb_entry *f)
135135
{
136-
struct switchdev_obj obj = {
137-
.id = SWITCHDEV_OBJ_PORT_FDB,
138-
.u.fdb = {
139-
.addr = f->addr.addr,
140-
.vid = f->vlan_id,
141-
},
136+
struct switchdev_obj_fdb fdb = {
137+
.addr = f->addr.addr,
138+
.vid = f->vlan_id,
142139
};
143140

144-
switchdev_port_obj_del(f->dst->dev, &obj);
141+
switchdev_port_obj_del(f->dst->dev, SWITCHDEV_OBJ_PORT_FDB, &fdb);
145142
}
146143

147144
static void fdb_delete(struct net_bridge *br, struct net_bridge_fdb_entry *f)

net/bridge/br_vlan.c

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,13 @@ static int __vlan_vid_add(struct net_device *dev, struct net_bridge *br,
8080
if (ops->ndo_vlan_rx_add_vid) {
8181
err = vlan_vid_add(dev, br->vlan_proto, vid);
8282
} else {
83-
struct switchdev_obj vlan_obj = {
84-
.id = SWITCHDEV_OBJ_PORT_VLAN,
85-
.u.vlan = {
86-
.flags = flags,
87-
.vid_begin = vid,
88-
.vid_end = vid,
89-
},
83+
struct switchdev_obj_vlan v = {
84+
.flags = flags,
85+
.vid_begin = vid,
86+
.vid_end = vid,
9087
};
9188

92-
err = switchdev_port_obj_add(dev, &vlan_obj);
89+
err = switchdev_port_obj_add(dev, SWITCHDEV_OBJ_PORT_VLAN, &v);
9390
if (err == -EOPNOTSUPP)
9491
err = 0;
9592
}
@@ -132,15 +129,12 @@ static int __vlan_vid_del(struct net_device *dev, struct net_bridge *br,
132129
if (ops->ndo_vlan_rx_kill_vid) {
133130
vlan_vid_del(dev, br->vlan_proto, vid);
134131
} else {
135-
struct switchdev_obj vlan_obj = {
136-
.id = SWITCHDEV_OBJ_PORT_VLAN,
137-
.u.vlan = {
138-
.vid_begin = vid,
139-
.vid_end = vid,
140-
},
132+
struct switchdev_obj_vlan v = {
133+
.vid_begin = vid,
134+
.vid_end = vid,
141135
};
142136

143-
err = switchdev_port_obj_del(dev, &vlan_obj);
137+
err = switchdev_port_obj_del(dev, SWITCHDEV_OBJ_PORT_VLAN, &v);
144138
if (err == -EOPNOTSUPP)
145139
err = 0;
146140
}

net/dsa/slave.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,9 @@ static int dsa_bridge_check_vlan_range(struct dsa_switch *ds,
242242
}
243243

244244
static int dsa_slave_port_vlan_add(struct net_device *dev,
245-
struct switchdev_obj *obj,
245+
const struct switchdev_obj_vlan *vlan,
246246
struct switchdev_trans *trans)
247247
{
248-
struct switchdev_obj_vlan *vlan = &obj->u.vlan;
249248
struct dsa_slave_priv *p = netdev_priv(dev);
250249
struct dsa_switch *ds = p->parent;
251250
u16 vid;
@@ -279,9 +278,8 @@ static int dsa_slave_port_vlan_add(struct net_device *dev,
279278
}
280279

281280
static int dsa_slave_port_vlan_del(struct net_device *dev,
282-
struct switchdev_obj *obj)
281+
const struct switchdev_obj_vlan *vlan)
283282
{
284-
struct switchdev_obj_vlan *vlan = &obj->u.vlan;
285283
struct dsa_slave_priv *p = netdev_priv(dev);
286284
struct dsa_switch *ds = p->parent;
287285
u16 vid;
@@ -343,10 +341,9 @@ static int dsa_slave_port_vlan_dump(struct net_device *dev,
343341
}
344342

345343
static int dsa_slave_port_fdb_add(struct net_device *dev,
346-
struct switchdev_obj *obj,
344+
const struct switchdev_obj_fdb *fdb,
347345
struct switchdev_trans *trans)
348346
{
349-
struct switchdev_obj_fdb *fdb = &obj->u.fdb;
350347
struct dsa_slave_priv *p = netdev_priv(dev);
351348
struct dsa_switch *ds = p->parent;
352349
int ret = -EOPNOTSUPP;
@@ -360,9 +357,8 @@ static int dsa_slave_port_fdb_add(struct net_device *dev,
360357
}
361358

362359
static int dsa_slave_port_fdb_del(struct net_device *dev,
363-
struct switchdev_obj *obj)
360+
const struct switchdev_obj_fdb *fdb)
364361
{
365-
struct switchdev_obj_fdb *fdb = &obj->u.fdb;
366362
struct dsa_slave_priv *p = netdev_priv(dev);
367363
struct dsa_switch *ds = p->parent;
368364
int ret = -EOPNOTSUPP;
@@ -473,7 +469,7 @@ static int dsa_slave_port_attr_set(struct net_device *dev,
473469
}
474470

475471
static int dsa_slave_port_obj_add(struct net_device *dev,
476-
struct switchdev_obj *obj,
472+
enum switchdev_obj_id id, const void *obj,
477473
struct switchdev_trans *trans)
478474
{
479475
int err;
@@ -483,7 +479,7 @@ static int dsa_slave_port_obj_add(struct net_device *dev,
483479
* supported, return -EOPNOTSUPP.
484480
*/
485481

486-
switch (obj->id) {
482+
switch (id) {
487483
case SWITCHDEV_OBJ_PORT_FDB:
488484
err = dsa_slave_port_fdb_add(dev, obj, trans);
489485
break;
@@ -499,11 +495,11 @@ static int dsa_slave_port_obj_add(struct net_device *dev,
499495
}
500496

501497
static int dsa_slave_port_obj_del(struct net_device *dev,
502-
struct switchdev_obj *obj)
498+
enum switchdev_obj_id id, const void *obj)
503499
{
504500
int err;
505501

506-
switch (obj->id) {
502+
switch (id) {
507503
case SWITCHDEV_OBJ_PORT_FDB:
508504
err = dsa_slave_port_fdb_del(dev, obj);
509505
break;

0 commit comments

Comments
 (0)