Skip to content

Commit 25f07ad

Browse files
viviendavem330
authored andcommitted
net: switchdev: pass callback to dump operation
Similar to the notifier_call callback of a notifier_block, change the function signature of switchdev dump operation to: int switchdev_port_obj_dump(struct net_device *dev, enum switchdev_obj_id id, void *obj, int (*cb)(void *obj)); This allows the caller to pass and expect back a specific switchdev_obj_* structure instead of the generic switchdev_obj one. Drivers implementation of dump operation can now expect this specific structure and call the callback with it. Drivers have been changed accordingly. Signed-off-by: Vivien Didelot <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 03d5fb1 commit 25f07ad

File tree

4 files changed

+53
-48
lines changed

4 files changed

+53
-48
lines changed

drivers/net/ethernet/rocker/rocker.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4538,10 +4538,10 @@ static int rocker_port_obj_del(struct net_device *dev,
45384538
}
45394539

45404540
static int rocker_port_fdb_dump(const struct rocker_port *rocker_port,
4541-
struct switchdev_obj *obj)
4541+
struct switchdev_obj_fdb *fdb,
4542+
int (*cb)(void *obj))
45424543
{
45434544
struct rocker *rocker = rocker_port->rocker;
4544-
struct switchdev_obj_fdb *fdb = &obj->u.fdb;
45454545
struct rocker_fdb_tbl_entry *found;
45464546
struct hlist_node *tmp;
45474547
unsigned long lock_flags;
@@ -4556,7 +4556,7 @@ static int rocker_port_fdb_dump(const struct rocker_port *rocker_port,
45564556
fdb->ndm_state = NUD_REACHABLE;
45574557
fdb->vid = rocker_port_vlan_to_vid(rocker_port,
45584558
found->key.vlan_id);
4559-
err = obj->cb(obj);
4559+
err = cb(fdb);
45604560
if (err)
45614561
break;
45624562
}
@@ -4566,9 +4566,9 @@ static int rocker_port_fdb_dump(const struct rocker_port *rocker_port,
45664566
}
45674567

45684568
static int rocker_port_vlan_dump(const struct rocker_port *rocker_port,
4569-
struct switchdev_obj *obj)
4569+
struct switchdev_obj_vlan *vlan,
4570+
int (*cb)(void *obj))
45704571
{
4571-
struct switchdev_obj_vlan *vlan = &obj->u.vlan;
45724572
u16 vid;
45734573
int err = 0;
45744574

@@ -4579,7 +4579,7 @@ static int rocker_port_vlan_dump(const struct rocker_port *rocker_port,
45794579
if (rocker_vlan_id_is_internal(htons(vid)))
45804580
vlan->flags |= BRIDGE_VLAN_INFO_PVID;
45814581
vlan->vid_begin = vlan->vid_end = vid;
4582-
err = obj->cb(obj);
4582+
err = cb(vlan);
45834583
if (err)
45844584
break;
45854585
}
@@ -4588,17 +4588,18 @@ static int rocker_port_vlan_dump(const struct rocker_port *rocker_port,
45884588
}
45894589

45904590
static int rocker_port_obj_dump(struct net_device *dev,
4591-
struct switchdev_obj *obj)
4591+
enum switchdev_obj_id id, void *obj,
4592+
int (*cb)(void *obj))
45924593
{
45934594
const struct rocker_port *rocker_port = netdev_priv(dev);
45944595
int err = 0;
45954596

4596-
switch (obj->id) {
4597+
switch (id) {
45974598
case SWITCHDEV_OBJ_PORT_FDB:
4598-
err = rocker_port_fdb_dump(rocker_port, obj);
4599+
err = rocker_port_fdb_dump(rocker_port, obj, cb);
45994600
break;
46004601
case SWITCHDEV_OBJ_PORT_VLAN:
4601-
err = rocker_port_vlan_dump(rocker_port, obj);
4602+
err = rocker_port_vlan_dump(rocker_port, obj, cb);
46024603
break;
46034604
default:
46044605
err = -EOPNOTSUPP;

include/net/switchdev.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ struct switchdev_ops {
120120
int (*switchdev_port_obj_del)(struct net_device *dev,
121121
struct switchdev_obj *obj);
122122
int (*switchdev_port_obj_dump)(struct net_device *dev,
123-
struct switchdev_obj *obj);
123+
enum switchdev_obj_id id, void *obj,
124+
int (*cb)(void *obj));
124125
};
125126

126127
enum switchdev_notifier_type {
@@ -152,7 +153,8 @@ int switchdev_port_attr_set(struct net_device *dev,
152153
struct switchdev_attr *attr);
153154
int switchdev_port_obj_add(struct net_device *dev, struct switchdev_obj *obj);
154155
int switchdev_port_obj_del(struct net_device *dev, struct switchdev_obj *obj);
155-
int switchdev_port_obj_dump(struct net_device *dev, struct switchdev_obj *obj);
156+
int switchdev_port_obj_dump(struct net_device *dev, enum switchdev_obj_id id,
157+
void *obj, int (*cb)(void *obj));
156158
int register_switchdev_notifier(struct notifier_block *nb);
157159
int unregister_switchdev_notifier(struct notifier_block *nb);
158160
int call_switchdev_notifiers(unsigned long val, struct net_device *dev,
@@ -209,7 +211,8 @@ static inline int switchdev_port_obj_del(struct net_device *dev,
209211
}
210212

211213
static inline int switchdev_port_obj_dump(struct net_device *dev,
212-
struct switchdev_obj *obj)
214+
enum switchdev_obj_id id, void *obj,
215+
int (*cb)(void *obj))
213216
{
214217
return -EOPNOTSUPP;
215218
}

net/dsa/slave.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,9 @@ static int dsa_slave_port_vlan_del(struct net_device *dev,
300300
}
301301

302302
static int dsa_slave_port_vlan_dump(struct net_device *dev,
303-
struct switchdev_obj *obj)
303+
struct switchdev_obj_vlan *vlan,
304+
int (*cb)(void *obj))
304305
{
305-
struct switchdev_obj_vlan *vlan = &obj->u.vlan;
306306
struct dsa_slave_priv *p = netdev_priv(dev);
307307
struct dsa_switch *ds = p->parent;
308308
DECLARE_BITMAP(members, DSA_MAX_PORTS);
@@ -334,7 +334,7 @@ static int dsa_slave_port_vlan_dump(struct net_device *dev,
334334
if (test_bit(p->port, untagged))
335335
vlan->flags |= BRIDGE_VLAN_INFO_UNTAGGED;
336336

337-
err = obj->cb(obj);
337+
err = cb(vlan);
338338
if (err)
339339
break;
340340
}
@@ -374,7 +374,8 @@ static int dsa_slave_port_fdb_del(struct net_device *dev,
374374
}
375375

376376
static int dsa_slave_port_fdb_dump(struct net_device *dev,
377-
struct switchdev_obj *obj)
377+
struct switchdev_obj_fdb *fdb,
378+
int (*cb)(void *obj))
378379
{
379380
struct dsa_slave_priv *p = netdev_priv(dev);
380381
struct dsa_switch *ds = p->parent;
@@ -393,11 +394,11 @@ static int dsa_slave_port_fdb_dump(struct net_device *dev,
393394
if (ret < 0)
394395
break;
395396

396-
obj->u.fdb.addr = addr;
397-
obj->u.fdb.vid = vid;
398-
obj->u.fdb.ndm_state = is_static ? NUD_NOARP : NUD_REACHABLE;
397+
fdb->addr = addr;
398+
fdb->vid = vid;
399+
fdb->ndm_state = is_static ? NUD_NOARP : NUD_REACHABLE;
399400

400-
ret = obj->cb(obj);
401+
ret = cb(fdb);
401402
if (ret < 0)
402403
break;
403404
}
@@ -518,16 +519,17 @@ static int dsa_slave_port_obj_del(struct net_device *dev,
518519
}
519520

520521
static int dsa_slave_port_obj_dump(struct net_device *dev,
521-
struct switchdev_obj *obj)
522+
enum switchdev_obj_id id, void *obj,
523+
int (*cb)(void *obj))
522524
{
523525
int err;
524526

525-
switch (obj->id) {
527+
switch (id) {
526528
case SWITCHDEV_OBJ_PORT_FDB:
527-
err = dsa_slave_port_fdb_dump(dev, obj);
529+
err = dsa_slave_port_fdb_dump(dev, obj, cb);
528530
break;
529531
case SWITCHDEV_OBJ_PORT_VLAN:
530-
err = dsa_slave_port_vlan_dump(dev, obj);
532+
err = dsa_slave_port_vlan_dump(dev, obj, cb);
531533
break;
532534
default:
533535
err = -EOPNOTSUPP;

net/switchdev/switchdev.c

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -386,25 +386,28 @@ EXPORT_SYMBOL_GPL(switchdev_port_obj_del);
386386
* switchdev_port_obj_dump - Dump port objects
387387
*
388388
* @dev: port device
389+
* @id: object ID
389390
* @obj: object to dump
391+
* @cb: function to call with a filled object
390392
*/
391-
int switchdev_port_obj_dump(struct net_device *dev, struct switchdev_obj *obj)
393+
int switchdev_port_obj_dump(struct net_device *dev, enum switchdev_obj_id id,
394+
void *obj, int (*cb)(void *obj))
392395
{
393396
const struct switchdev_ops *ops = dev->switchdev_ops;
394397
struct net_device *lower_dev;
395398
struct list_head *iter;
396399
int err = -EOPNOTSUPP;
397400

398401
if (ops && ops->switchdev_port_obj_dump)
399-
return ops->switchdev_port_obj_dump(dev, obj);
402+
return ops->switchdev_port_obj_dump(dev, id, obj, cb);
400403

401404
/* Switch device port(s) may be stacked under
402405
* bond/team/vlan dev, so recurse down to dump objects on
403406
* first port at bottom of stack.
404407
*/
405408

406409
netdev_for_each_lower_dev(dev, lower_dev, iter) {
407-
err = switchdev_port_obj_dump(lower_dev, obj);
410+
err = switchdev_port_obj_dump(lower_dev, id, obj, cb);
408411
break;
409412
}
410413

@@ -476,7 +479,7 @@ int call_switchdev_notifiers(unsigned long val, struct net_device *dev,
476479
EXPORT_SYMBOL_GPL(call_switchdev_notifiers);
477480

478481
struct switchdev_vlan_dump {
479-
struct switchdev_obj obj;
482+
struct switchdev_obj_vlan vlan;
480483
struct sk_buff *skb;
481484
u32 filter_mask;
482485
u16 flags;
@@ -514,11 +517,11 @@ static int switchdev_port_vlan_dump_put(struct switchdev_vlan_dump *dump)
514517
return 0;
515518
}
516519

517-
static int switchdev_port_vlan_dump_cb(struct switchdev_obj *obj)
520+
static int switchdev_port_vlan_dump_cb(void *obj)
518521
{
522+
struct switchdev_obj_vlan *vlan = obj;
519523
struct switchdev_vlan_dump *dump =
520-
container_of(obj, struct switchdev_vlan_dump, obj);
521-
struct switchdev_obj_vlan *vlan = &dump->obj.u.vlan;
524+
container_of(vlan, struct switchdev_vlan_dump, vlan);
522525
int err = 0;
523526

524527
if (vlan->vid_begin > vlan->vid_end)
@@ -570,18 +573,16 @@ static int switchdev_port_vlan_fill(struct sk_buff *skb, struct net_device *dev,
570573
u32 filter_mask)
571574
{
572575
struct switchdev_vlan_dump dump = {
573-
.obj = {
574-
.id = SWITCHDEV_OBJ_PORT_VLAN,
575-
.cb = switchdev_port_vlan_dump_cb,
576-
},
577576
.skb = skb,
578577
.filter_mask = filter_mask,
579578
};
580579
int err = 0;
581580

582581
if ((filter_mask & RTEXT_FILTER_BRVLAN) ||
583582
(filter_mask & RTEXT_FILTER_BRVLAN_COMPRESSED)) {
584-
err = switchdev_port_obj_dump(dev, &dump.obj);
583+
err = switchdev_port_obj_dump(dev, SWITCHDEV_OBJ_PORT_VLAN,
584+
&dump.vlan,
585+
switchdev_port_vlan_dump_cb);
585586
if (err)
586587
goto err_out;
587588
if (filter_mask & RTEXT_FILTER_BRVLAN_COMPRESSED)
@@ -856,17 +857,18 @@ int switchdev_port_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
856857
EXPORT_SYMBOL_GPL(switchdev_port_fdb_del);
857858

858859
struct switchdev_fdb_dump {
859-
struct switchdev_obj obj;
860+
struct switchdev_obj_fdb fdb;
860861
struct net_device *dev;
861862
struct sk_buff *skb;
862863
struct netlink_callback *cb;
863864
int idx;
864865
};
865866

866-
static int switchdev_port_fdb_dump_cb(struct switchdev_obj *obj)
867+
static int switchdev_port_fdb_dump_cb(void *obj)
867868
{
869+
struct switchdev_obj_fdb *fdb = obj;
868870
struct switchdev_fdb_dump *dump =
869-
container_of(obj, struct switchdev_fdb_dump, obj);
871+
container_of(fdb, struct switchdev_fdb_dump, fdb);
870872
u32 portid = NETLINK_CB(dump->cb->skb).portid;
871873
u32 seq = dump->cb->nlh->nlmsg_seq;
872874
struct nlmsghdr *nlh;
@@ -887,12 +889,12 @@ static int switchdev_port_fdb_dump_cb(struct switchdev_obj *obj)
887889
ndm->ndm_flags = NTF_SELF;
888890
ndm->ndm_type = 0;
889891
ndm->ndm_ifindex = dump->dev->ifindex;
890-
ndm->ndm_state = obj->u.fdb.ndm_state;
892+
ndm->ndm_state = fdb->ndm_state;
891893

892-
if (nla_put(dump->skb, NDA_LLADDR, ETH_ALEN, obj->u.fdb.addr))
894+
if (nla_put(dump->skb, NDA_LLADDR, ETH_ALEN, fdb->addr))
893895
goto nla_put_failure;
894896

895-
if (obj->u.fdb.vid && nla_put_u16(dump->skb, NDA_VLAN, obj->u.fdb.vid))
897+
if (fdb->vid && nla_put_u16(dump->skb, NDA_VLAN, fdb->vid))
896898
goto nla_put_failure;
897899

898900
nlmsg_end(dump->skb, nlh);
@@ -922,17 +924,14 @@ int switchdev_port_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb,
922924
struct net_device *filter_dev, int idx)
923925
{
924926
struct switchdev_fdb_dump dump = {
925-
.obj = {
926-
.id = SWITCHDEV_OBJ_PORT_FDB,
927-
.cb = switchdev_port_fdb_dump_cb,
928-
},
929927
.dev = dev,
930928
.skb = skb,
931929
.cb = cb,
932930
.idx = idx,
933931
};
934932

935-
switchdev_port_obj_dump(dev, &dump.obj);
933+
switchdev_port_obj_dump(dev, SWITCHDEV_OBJ_PORT_FDB, &dump.fdb,
934+
switchdev_port_fdb_dump_cb);
936935
return dump.idx;
937936
}
938937
EXPORT_SYMBOL_GPL(switchdev_port_fdb_dump);

0 commit comments

Comments
 (0)