Commit 648b4a99 authored by Jiri Pirko's avatar Jiri Pirko Committed by David S. Miller

switchdev: bring back switchdev_obj and use it as a generic object param

Replace "void *obj" with a generic structure. Introduce couple of
helpers along that.
Signed-off-by: default avatarJiri Pirko <jiri@mellanox.com>
Acked-by: default avatarScott Feldman <sfeldma@gmail.com>
Reviewed-by: default avatarVivien Didelot <vivien.didelot@savoirfairelinux.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 52ba57cf
...@@ -4437,7 +4437,8 @@ static int rocker_port_fdb_add(struct rocker_port *rocker_port, ...@@ -4437,7 +4437,8 @@ static int rocker_port_fdb_add(struct rocker_port *rocker_port,
} }
static int rocker_port_obj_add(struct net_device *dev, static int rocker_port_obj_add(struct net_device *dev,
enum switchdev_obj_id id, const void *obj, enum switchdev_obj_id id,
const struct switchdev_obj *obj,
struct switchdev_trans *trans) struct switchdev_trans *trans)
{ {
struct rocker_port *rocker_port = netdev_priv(dev); struct rocker_port *rocker_port = netdev_priv(dev);
...@@ -4446,16 +4447,18 @@ static int rocker_port_obj_add(struct net_device *dev, ...@@ -4446,16 +4447,18 @@ static int rocker_port_obj_add(struct net_device *dev,
switch (id) { switch (id) {
case SWITCHDEV_OBJ_ID_PORT_VLAN: case SWITCHDEV_OBJ_ID_PORT_VLAN:
err = rocker_port_vlans_add(rocker_port, trans, obj); err = rocker_port_vlans_add(rocker_port, trans,
SWITCHDEV_OBJ_PORT_VLAN(obj));
break; break;
case SWITCHDEV_OBJ_ID_IPV4_FIB: case SWITCHDEV_OBJ_ID_IPV4_FIB:
fib4 = obj; fib4 = SWITCHDEV_OBJ_IPV4_FIB(obj);
err = rocker_port_fib_ipv4(rocker_port, trans, err = rocker_port_fib_ipv4(rocker_port, trans,
htonl(fib4->dst), fib4->dst_len, htonl(fib4->dst), fib4->dst_len,
fib4->fi, fib4->tb_id, 0); fib4->fi, fib4->tb_id, 0);
break; break;
case SWITCHDEV_OBJ_ID_PORT_FDB: case SWITCHDEV_OBJ_ID_PORT_FDB:
err = rocker_port_fdb_add(rocker_port, trans, obj); err = rocker_port_fdb_add(rocker_port, trans,
SWITCHDEV_OBJ_PORT_FDB(obj));
break; break;
default: default:
err = -EOPNOTSUPP; err = -EOPNOTSUPP;
...@@ -4508,7 +4511,8 @@ static int rocker_port_fdb_del(struct rocker_port *rocker_port, ...@@ -4508,7 +4511,8 @@ static int rocker_port_fdb_del(struct rocker_port *rocker_port,
} }
static int rocker_port_obj_del(struct net_device *dev, static int rocker_port_obj_del(struct net_device *dev,
enum switchdev_obj_id id, const void *obj) enum switchdev_obj_id id,
const struct switchdev_obj *obj)
{ {
struct rocker_port *rocker_port = netdev_priv(dev); struct rocker_port *rocker_port = netdev_priv(dev);
const struct switchdev_obj_ipv4_fib *fib4; const struct switchdev_obj_ipv4_fib *fib4;
...@@ -4516,17 +4520,19 @@ static int rocker_port_obj_del(struct net_device *dev, ...@@ -4516,17 +4520,19 @@ static int rocker_port_obj_del(struct net_device *dev,
switch (id) { switch (id) {
case SWITCHDEV_OBJ_ID_PORT_VLAN: case SWITCHDEV_OBJ_ID_PORT_VLAN:
err = rocker_port_vlans_del(rocker_port, obj); err = rocker_port_vlans_del(rocker_port,
SWITCHDEV_OBJ_PORT_VLAN(obj));
break; break;
case SWITCHDEV_OBJ_ID_IPV4_FIB: case SWITCHDEV_OBJ_ID_IPV4_FIB:
fib4 = obj; fib4 = SWITCHDEV_OBJ_IPV4_FIB(obj);
err = rocker_port_fib_ipv4(rocker_port, NULL, err = rocker_port_fib_ipv4(rocker_port, NULL,
htonl(fib4->dst), fib4->dst_len, htonl(fib4->dst), fib4->dst_len,
fib4->fi, fib4->tb_id, fib4->fi, fib4->tb_id,
ROCKER_OP_FLAG_REMOVE); ROCKER_OP_FLAG_REMOVE);
break; break;
case SWITCHDEV_OBJ_ID_PORT_FDB: case SWITCHDEV_OBJ_ID_PORT_FDB:
err = rocker_port_fdb_del(rocker_port, NULL, obj); err = rocker_port_fdb_del(rocker_port, NULL,
SWITCHDEV_OBJ_PORT_FDB(obj));
break; break;
default: default:
err = -EOPNOTSUPP; err = -EOPNOTSUPP;
...@@ -4538,7 +4544,7 @@ static int rocker_port_obj_del(struct net_device *dev, ...@@ -4538,7 +4544,7 @@ static int rocker_port_obj_del(struct net_device *dev,
static int rocker_port_fdb_dump(const struct rocker_port *rocker_port, static int rocker_port_fdb_dump(const struct rocker_port *rocker_port,
struct switchdev_obj_port_fdb *fdb, struct switchdev_obj_port_fdb *fdb,
int (*cb)(void *obj)) switchdev_obj_dump_cb_t *cb)
{ {
struct rocker *rocker = rocker_port->rocker; struct rocker *rocker = rocker_port->rocker;
struct rocker_fdb_tbl_entry *found; struct rocker_fdb_tbl_entry *found;
...@@ -4555,7 +4561,7 @@ static int rocker_port_fdb_dump(const struct rocker_port *rocker_port, ...@@ -4555,7 +4561,7 @@ static int rocker_port_fdb_dump(const struct rocker_port *rocker_port,
fdb->ndm_state = NUD_REACHABLE; fdb->ndm_state = NUD_REACHABLE;
fdb->vid = rocker_port_vlan_to_vid(rocker_port, fdb->vid = rocker_port_vlan_to_vid(rocker_port,
found->key.vlan_id); found->key.vlan_id);
err = cb(fdb); err = cb(&fdb->obj);
if (err) if (err)
break; break;
} }
...@@ -4566,7 +4572,7 @@ static int rocker_port_fdb_dump(const struct rocker_port *rocker_port, ...@@ -4566,7 +4572,7 @@ static int rocker_port_fdb_dump(const struct rocker_port *rocker_port,
static int rocker_port_vlan_dump(const struct rocker_port *rocker_port, static int rocker_port_vlan_dump(const struct rocker_port *rocker_port,
struct switchdev_obj_port_vlan *vlan, struct switchdev_obj_port_vlan *vlan,
int (*cb)(void *obj)) switchdev_obj_dump_cb_t *cb)
{ {
u16 vid; u16 vid;
int err = 0; int err = 0;
...@@ -4578,7 +4584,7 @@ static int rocker_port_vlan_dump(const struct rocker_port *rocker_port, ...@@ -4578,7 +4584,7 @@ static int rocker_port_vlan_dump(const struct rocker_port *rocker_port,
if (rocker_vlan_id_is_internal(htons(vid))) if (rocker_vlan_id_is_internal(htons(vid)))
vlan->flags |= BRIDGE_VLAN_INFO_PVID; vlan->flags |= BRIDGE_VLAN_INFO_PVID;
vlan->vid_begin = vlan->vid_end = vid; vlan->vid_begin = vlan->vid_end = vid;
err = cb(vlan); err = cb(&vlan->obj);
if (err) if (err)
break; break;
} }
...@@ -4587,18 +4593,21 @@ static int rocker_port_vlan_dump(const struct rocker_port *rocker_port, ...@@ -4587,18 +4593,21 @@ static int rocker_port_vlan_dump(const struct rocker_port *rocker_port,
} }
static int rocker_port_obj_dump(struct net_device *dev, static int rocker_port_obj_dump(struct net_device *dev,
enum switchdev_obj_id id, void *obj, enum switchdev_obj_id id,
int (*cb)(void *obj)) struct switchdev_obj *obj,
switchdev_obj_dump_cb_t *cb)
{ {
const struct rocker_port *rocker_port = netdev_priv(dev); const struct rocker_port *rocker_port = netdev_priv(dev);
int err = 0; int err = 0;
switch (id) { switch (id) {
case SWITCHDEV_OBJ_ID_PORT_FDB: case SWITCHDEV_OBJ_ID_PORT_FDB:
err = rocker_port_fdb_dump(rocker_port, obj, cb); err = rocker_port_fdb_dump(rocker_port,
SWITCHDEV_OBJ_PORT_FDB(obj), cb);
break; break;
case SWITCHDEV_OBJ_ID_PORT_VLAN: case SWITCHDEV_OBJ_ID_PORT_VLAN:
err = rocker_port_vlan_dump(rocker_port, obj, cb); err = rocker_port_vlan_dump(rocker_port,
SWITCHDEV_OBJ_PORT_VLAN(obj), cb);
break; break;
default: default:
err = -EOPNOTSUPP; err = -EOPNOTSUPP;
......
...@@ -64,15 +64,23 @@ enum switchdev_obj_id { ...@@ -64,15 +64,23 @@ enum switchdev_obj_id {
SWITCHDEV_OBJ_ID_PORT_FDB, SWITCHDEV_OBJ_ID_PORT_FDB,
}; };
struct switchdev_obj {
};
/* SWITCHDEV_OBJ_ID_PORT_VLAN */ /* SWITCHDEV_OBJ_ID_PORT_VLAN */
struct switchdev_obj_port_vlan { struct switchdev_obj_port_vlan {
struct switchdev_obj obj;
u16 flags; u16 flags;
u16 vid_begin; u16 vid_begin;
u16 vid_end; u16 vid_end;
}; };
#define SWITCHDEV_OBJ_PORT_VLAN(obj) \
container_of(obj, struct switchdev_obj_port_vlan, obj)
/* SWITCHDEV_OBJ_ID_IPV4_FIB */ /* SWITCHDEV_OBJ_ID_IPV4_FIB */
struct switchdev_obj_ipv4_fib { struct switchdev_obj_ipv4_fib {
struct switchdev_obj obj;
u32 dst; u32 dst;
int dst_len; int dst_len;
struct fib_info *fi; struct fib_info *fi;
...@@ -82,18 +90,27 @@ struct switchdev_obj_ipv4_fib { ...@@ -82,18 +90,27 @@ struct switchdev_obj_ipv4_fib {
u32 tb_id; u32 tb_id;
}; };
#define SWITCHDEV_OBJ_IPV4_FIB(obj) \
container_of(obj, struct switchdev_obj_ipv4_fib, obj)
/* SWITCHDEV_OBJ_ID_PORT_FDB */ /* SWITCHDEV_OBJ_ID_PORT_FDB */
struct switchdev_obj_port_fdb { struct switchdev_obj_port_fdb {
struct switchdev_obj obj;
const unsigned char *addr; const unsigned char *addr;
u16 vid; u16 vid;
u16 ndm_state; u16 ndm_state;
}; };
#define SWITCHDEV_OBJ_PORT_FDB(obj) \
container_of(obj, struct switchdev_obj_port_fdb, obj)
void switchdev_trans_item_enqueue(struct switchdev_trans *trans, void switchdev_trans_item_enqueue(struct switchdev_trans *trans,
void *data, void (*destructor)(void const *), void *data, void (*destructor)(void const *),
struct switchdev_trans_item *tritem); struct switchdev_trans_item *tritem);
void *switchdev_trans_item_dequeue(struct switchdev_trans *trans); void *switchdev_trans_item_dequeue(struct switchdev_trans *trans);
typedef int switchdev_obj_dump_cb_t(struct switchdev_obj *obj);
/** /**
* struct switchdev_ops - switchdev operations * struct switchdev_ops - switchdev operations
* *
...@@ -115,14 +132,15 @@ struct switchdev_ops { ...@@ -115,14 +132,15 @@ struct switchdev_ops {
struct switchdev_trans *trans); struct switchdev_trans *trans);
int (*switchdev_port_obj_add)(struct net_device *dev, int (*switchdev_port_obj_add)(struct net_device *dev,
enum switchdev_obj_id id, enum switchdev_obj_id id,
const void *obj, const struct switchdev_obj *obj,
struct switchdev_trans *trans); struct switchdev_trans *trans);
int (*switchdev_port_obj_del)(struct net_device *dev, int (*switchdev_port_obj_del)(struct net_device *dev,
enum switchdev_obj_id id, enum switchdev_obj_id id,
const void *obj); const struct switchdev_obj *obj);
int (*switchdev_port_obj_dump)(struct net_device *dev, int (*switchdev_port_obj_dump)(struct net_device *dev,
enum switchdev_obj_id id, void *obj, enum switchdev_obj_id id,
int (*cb)(void *obj)); struct switchdev_obj *obj,
switchdev_obj_dump_cb_t *cb);
}; };
enum switchdev_notifier_type { enum switchdev_notifier_type {
...@@ -153,11 +171,12 @@ int switchdev_port_attr_get(struct net_device *dev, ...@@ -153,11 +171,12 @@ int switchdev_port_attr_get(struct net_device *dev,
int switchdev_port_attr_set(struct net_device *dev, int switchdev_port_attr_set(struct net_device *dev,
struct switchdev_attr *attr); struct switchdev_attr *attr);
int switchdev_port_obj_add(struct net_device *dev, enum switchdev_obj_id id, int switchdev_port_obj_add(struct net_device *dev, enum switchdev_obj_id id,
const void *obj); const struct switchdev_obj *obj);
int switchdev_port_obj_del(struct net_device *dev, enum switchdev_obj_id id, int switchdev_port_obj_del(struct net_device *dev, enum switchdev_obj_id id,
const void *obj); const struct switchdev_obj *obj);
int switchdev_port_obj_dump(struct net_device *dev, enum switchdev_obj_id id, int switchdev_port_obj_dump(struct net_device *dev, enum switchdev_obj_id id,
void *obj, int (*cb)(void *obj)); struct switchdev_obj *obj,
switchdev_obj_dump_cb_t *cb);
int register_switchdev_notifier(struct notifier_block *nb); int register_switchdev_notifier(struct notifier_block *nb);
int unregister_switchdev_notifier(struct notifier_block *nb); int unregister_switchdev_notifier(struct notifier_block *nb);
int call_switchdev_notifiers(unsigned long val, struct net_device *dev, int call_switchdev_notifiers(unsigned long val, struct net_device *dev,
...@@ -203,21 +222,22 @@ static inline int switchdev_port_attr_set(struct net_device *dev, ...@@ -203,21 +222,22 @@ static inline int switchdev_port_attr_set(struct net_device *dev,
static inline int switchdev_port_obj_add(struct net_device *dev, static inline int switchdev_port_obj_add(struct net_device *dev,
enum switchdev_obj_id id, enum switchdev_obj_id id,
const void *obj) const struct switchdev_obj *obj)
{ {
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
static inline int switchdev_port_obj_del(struct net_device *dev, static inline int switchdev_port_obj_del(struct net_device *dev,
enum switchdev_obj_id id, enum switchdev_obj_id id,
const void *obj) const struct switchdev_obj *obj)
{ {
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
static inline int switchdev_port_obj_dump(struct net_device *dev, static inline int switchdev_port_obj_dump(struct net_device *dev,
enum switchdev_obj_id id, void *obj, enum switchdev_obj_id id,
int (*cb)(void *obj)) const struct switchdev_obj *obj,
switchdev_obj_dump_cb_t *cb)
{ {
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
......
...@@ -138,7 +138,8 @@ static void fdb_del_external_learn(struct net_bridge_fdb_entry *f) ...@@ -138,7 +138,8 @@ static void fdb_del_external_learn(struct net_bridge_fdb_entry *f)
.vid = f->vlan_id, .vid = f->vlan_id,
}; };
switchdev_port_obj_del(f->dst->dev, SWITCHDEV_OBJ_ID_PORT_FDB, &fdb); switchdev_port_obj_del(f->dst->dev, SWITCHDEV_OBJ_ID_PORT_FDB,
&fdb.obj);
} }
static void fdb_delete(struct net_bridge *br, struct net_bridge_fdb_entry *f) static void fdb_delete(struct net_bridge *br, struct net_bridge_fdb_entry *f)
......
...@@ -89,7 +89,7 @@ static int __vlan_vid_add(struct net_device *dev, struct net_bridge *br, ...@@ -89,7 +89,7 @@ static int __vlan_vid_add(struct net_device *dev, struct net_bridge *br,
}; };
err = switchdev_port_obj_add(dev, SWITCHDEV_OBJ_ID_PORT_VLAN, err = switchdev_port_obj_add(dev, SWITCHDEV_OBJ_ID_PORT_VLAN,
&v); &v.obj);
if (err == -EOPNOTSUPP) if (err == -EOPNOTSUPP)
err = 0; err = 0;
} }
...@@ -138,7 +138,7 @@ static int __vlan_vid_del(struct net_device *dev, struct net_bridge *br, ...@@ -138,7 +138,7 @@ static int __vlan_vid_del(struct net_device *dev, struct net_bridge *br,
}; };
err = switchdev_port_obj_del(dev, SWITCHDEV_OBJ_ID_PORT_VLAN, err = switchdev_port_obj_del(dev, SWITCHDEV_OBJ_ID_PORT_VLAN,
&v); &v.obj);
if (err == -EOPNOTSUPP) if (err == -EOPNOTSUPP)
err = 0; err = 0;
} }
......
...@@ -299,7 +299,7 @@ static int dsa_slave_port_vlan_del(struct net_device *dev, ...@@ -299,7 +299,7 @@ static int dsa_slave_port_vlan_del(struct net_device *dev,
static int dsa_slave_port_vlan_dump(struct net_device *dev, static int dsa_slave_port_vlan_dump(struct net_device *dev,
struct switchdev_obj_port_vlan *vlan, struct switchdev_obj_port_vlan *vlan,
int (*cb)(void *obj)) switchdev_obj_dump_cb_t *cb)
{ {
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_slave_priv *p = netdev_priv(dev);
struct dsa_switch *ds = p->parent; struct dsa_switch *ds = p->parent;
...@@ -332,7 +332,7 @@ static int dsa_slave_port_vlan_dump(struct net_device *dev, ...@@ -332,7 +332,7 @@ static int dsa_slave_port_vlan_dump(struct net_device *dev,
if (test_bit(p->port, untagged)) if (test_bit(p->port, untagged))
vlan->flags |= BRIDGE_VLAN_INFO_UNTAGGED; vlan->flags |= BRIDGE_VLAN_INFO_UNTAGGED;
err = cb(vlan); err = cb(&vlan->obj);
if (err) if (err)
break; break;
} }
...@@ -371,7 +371,7 @@ static int dsa_slave_port_fdb_del(struct net_device *dev, ...@@ -371,7 +371,7 @@ static int dsa_slave_port_fdb_del(struct net_device *dev,
static int dsa_slave_port_fdb_dump(struct net_device *dev, static int dsa_slave_port_fdb_dump(struct net_device *dev,
struct switchdev_obj_port_fdb *fdb, struct switchdev_obj_port_fdb *fdb,
int (*cb)(void *obj)) switchdev_obj_dump_cb_t *cb)
{ {
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_slave_priv *p = netdev_priv(dev);
struct dsa_switch *ds = p->parent; struct dsa_switch *ds = p->parent;
...@@ -394,7 +394,7 @@ static int dsa_slave_port_fdb_dump(struct net_device *dev, ...@@ -394,7 +394,7 @@ static int dsa_slave_port_fdb_dump(struct net_device *dev,
fdb->vid = vid; fdb->vid = vid;
fdb->ndm_state = is_static ? NUD_NOARP : NUD_REACHABLE; fdb->ndm_state = is_static ? NUD_NOARP : NUD_REACHABLE;
ret = cb(fdb); ret = cb(&fdb->obj);
if (ret < 0) if (ret < 0)
break; break;
} }
...@@ -474,7 +474,8 @@ static int dsa_slave_port_attr_set(struct net_device *dev, ...@@ -474,7 +474,8 @@ static int dsa_slave_port_attr_set(struct net_device *dev,
} }
static int dsa_slave_port_obj_add(struct net_device *dev, static int dsa_slave_port_obj_add(struct net_device *dev,
enum switchdev_obj_id id, const void *obj, enum switchdev_obj_id id,
const struct switchdev_obj *obj,
struct switchdev_trans *trans) struct switchdev_trans *trans)
{ {
int err; int err;
...@@ -486,10 +487,14 @@ static int dsa_slave_port_obj_add(struct net_device *dev, ...@@ -486,10 +487,14 @@ static int dsa_slave_port_obj_add(struct net_device *dev,
switch (id) { switch (id) {
case SWITCHDEV_OBJ_ID_PORT_FDB: case SWITCHDEV_OBJ_ID_PORT_FDB:
err = dsa_slave_port_fdb_add(dev, obj, trans); err = dsa_slave_port_fdb_add(dev,
SWITCHDEV_OBJ_PORT_FDB(obj),
trans);
break; break;
case SWITCHDEV_OBJ_ID_PORT_VLAN: case SWITCHDEV_OBJ_ID_PORT_VLAN:
err = dsa_slave_port_vlan_add(dev, obj, trans); err = dsa_slave_port_vlan_add(dev,
SWITCHDEV_OBJ_PORT_VLAN(obj),
trans);
break; break;
default: default:
err = -EOPNOTSUPP; err = -EOPNOTSUPP;
...@@ -500,16 +505,19 @@ static int dsa_slave_port_obj_add(struct net_device *dev, ...@@ -500,16 +505,19 @@ static int dsa_slave_port_obj_add(struct net_device *dev,
} }
static int dsa_slave_port_obj_del(struct net_device *dev, static int dsa_slave_port_obj_del(struct net_device *dev,
enum switchdev_obj_id id, const void *obj) enum switchdev_obj_id id,
const struct switchdev_obj *obj)
{ {
int err; int err;
switch (id) { switch (id) {
case SWITCHDEV_OBJ_ID_PORT_FDB: case SWITCHDEV_OBJ_ID_PORT_FDB:
err = dsa_slave_port_fdb_del(dev, obj); err = dsa_slave_port_fdb_del(dev,
SWITCHDEV_OBJ_PORT_FDB(obj));
break; break;
case SWITCHDEV_OBJ_ID_PORT_VLAN: case SWITCHDEV_OBJ_ID_PORT_VLAN:
err = dsa_slave_port_vlan_del(dev, obj); err = dsa_slave_port_vlan_del(dev,
SWITCHDEV_OBJ_PORT_VLAN(obj));
break; break;
default: default:
err = -EOPNOTSUPP; err = -EOPNOTSUPP;
...@@ -520,17 +528,22 @@ static int dsa_slave_port_obj_del(struct net_device *dev, ...@@ -520,17 +528,22 @@ static int dsa_slave_port_obj_del(struct net_device *dev,
} }
static int dsa_slave_port_obj_dump(struct net_device *dev, static int dsa_slave_port_obj_dump(struct net_device *dev,
enum switchdev_obj_id id, void *obj, enum switchdev_obj_id id,
int (*cb)(void *obj)) struct switchdev_obj *obj,
switchdev_obj_dump_cb_t *cb)
{ {
int err; int err;
switch (id) { switch (id) {
case SWITCHDEV_OBJ_ID_PORT_FDB: case SWITCHDEV_OBJ_ID_PORT_FDB:
err = dsa_slave_port_fdb_dump(dev, obj, cb); err = dsa_slave_port_fdb_dump(dev,
SWITCHDEV_OBJ_PORT_FDB(obj),
cb);
break; break;
case SWITCHDEV_OBJ_ID_PORT_VLAN: case SWITCHDEV_OBJ_ID_PORT_VLAN:
err = dsa_slave_port_vlan_dump(dev, obj, cb); err = dsa_slave_port_vlan_dump(dev,
SWITCHDEV_OBJ_PORT_VLAN(obj),
cb);
break; break;
default: default:
err = -EOPNOTSUPP; err = -EOPNOTSUPP;
......
...@@ -270,7 +270,8 @@ int switchdev_port_attr_set(struct net_device *dev, struct switchdev_attr *attr) ...@@ -270,7 +270,8 @@ int switchdev_port_attr_set(struct net_device *dev, struct switchdev_attr *attr)
EXPORT_SYMBOL_GPL(switchdev_port_attr_set); EXPORT_SYMBOL_GPL(switchdev_port_attr_set);
static int __switchdev_port_obj_add(struct net_device *dev, static int __switchdev_port_obj_add(struct net_device *dev,
enum switchdev_obj_id id, const void *obj, enum switchdev_obj_id id,
const struct switchdev_obj *obj,
struct switchdev_trans *trans) struct switchdev_trans *trans)
{ {
const struct switchdev_ops *ops = dev->switchdev_ops; const struct switchdev_ops *ops = dev->switchdev_ops;
...@@ -309,7 +310,7 @@ static int __switchdev_port_obj_add(struct net_device *dev, ...@@ -309,7 +310,7 @@ static int __switchdev_port_obj_add(struct net_device *dev,
* rtnl_lock must be held. * rtnl_lock must be held.
*/ */
int switchdev_port_obj_add(struct net_device *dev, enum switchdev_obj_id id, int switchdev_port_obj_add(struct net_device *dev, enum switchdev_obj_id id,
const void *obj) const struct switchdev_obj *obj)
{ {
struct switchdev_trans trans; struct switchdev_trans trans;
int err; int err;
...@@ -361,7 +362,7 @@ EXPORT_SYMBOL_GPL(switchdev_port_obj_add); ...@@ -361,7 +362,7 @@ EXPORT_SYMBOL_GPL(switchdev_port_obj_add);
* @obj: object to delete * @obj: object to delete
*/ */
int switchdev_port_obj_del(struct net_device *dev, enum switchdev_obj_id id, int switchdev_port_obj_del(struct net_device *dev, enum switchdev_obj_id id,
const void *obj) const struct switchdev_obj *obj)
{ {
const struct switchdev_ops *ops = dev->switchdev_ops; const struct switchdev_ops *ops = dev->switchdev_ops;
struct net_device *lower_dev; struct net_device *lower_dev;
...@@ -395,7 +396,8 @@ EXPORT_SYMBOL_GPL(switchdev_port_obj_del); ...@@ -395,7 +396,8 @@ EXPORT_SYMBOL_GPL(switchdev_port_obj_del);
* @cb: function to call with a filled object * @cb: function to call with a filled object
*/ */
int switchdev_port_obj_dump(struct net_device *dev, enum switchdev_obj_id id, int switchdev_port_obj_dump(struct net_device *dev, enum switchdev_obj_id id,
void *obj, int (*cb)(void *obj)) struct switchdev_obj *obj,
switchdev_obj_dump_cb_t *cb)
{ {
const struct switchdev_ops *ops = dev->switchdev_ops; const struct switchdev_ops *ops = dev->switchdev_ops;
struct net_device *lower_dev; struct net_device *lower_dev;
...@@ -521,9 +523,9 @@ static int switchdev_port_vlan_dump_put(struct switchdev_vlan_dump *dump) ...@@ -521,9 +523,9 @@ static int switchdev_port_vlan_dump_put(struct switchdev_vlan_dump *dump)
return 0; return 0;
} }
static int switchdev_port_vlan_dump_cb(void *obj) static int switchdev_port_vlan_dump_cb(struct switchdev_obj *obj)
{ {
struct switchdev_obj_port_vlan *vlan = obj; struct switchdev_obj_port_vlan *vlan = SWITCHDEV_OBJ_PORT_VLAN(obj);
struct switchdev_vlan_dump *dump = struct switchdev_vlan_dump *dump =
container_of(vlan, struct switchdev_vlan_dump, vlan); container_of(vlan, struct switchdev_vlan_dump, vlan);
int err = 0; int err = 0;
...@@ -585,7 +587,7 @@ static int switchdev_port_vlan_fill(struct sk_buff *skb, struct net_device *dev, ...@@ -585,7 +587,7 @@ static int switchdev_port_vlan_fill(struct sk_buff *skb, struct net_device *dev,
if ((filter_mask & RTEXT_FILTER_BRVLAN) || if ((filter_mask & RTEXT_FILTER_BRVLAN) ||
(filter_mask & RTEXT_FILTER_BRVLAN_COMPRESSED)) { (filter_mask & RTEXT_FILTER_BRVLAN_COMPRESSED)) {
err = switchdev_port_obj_dump(dev, SWITCHDEV_OBJ_ID_PORT_VLAN, err = switchdev_port_obj_dump(dev, SWITCHDEV_OBJ_ID_PORT_VLAN,
&dump.vlan, &dump.vlan.obj,
switchdev_port_vlan_dump_cb); switchdev_port_vlan_dump_cb);
if (err) if (err)
goto err_out; goto err_out;
...@@ -700,11 +702,11 @@ static int switchdev_port_br_afspec(struct net_device *dev, ...@@ -700,11 +702,11 @@ static int switchdev_port_br_afspec(struct net_device *dev,
struct nlattr *afspec, struct nlattr *afspec,
int (*f)(struct net_device *dev, int (*f)(struct net_device *dev,
enum switchdev_obj_id id, enum switchdev_obj_id id,
const void *obj)) const struct switchdev_obj *obj))
{ {
struct nlattr *attr; struct nlattr *attr;
struct bridge_vlan_info *vinfo; struct bridge_vlan_info *vinfo;
struct switchdev_obj_port_vlan vlan = { 0 }; struct switchdev_obj_port_vlan vlan = { {}, 0 };
int rem; int rem;
int err; int err;
...@@ -725,7 +727,7 @@ static int switchdev_port_br_afspec(struct net_device *dev, ...@@ -725,7 +727,7 @@ static int switchdev_port_br_afspec(struct net_device *dev,
vlan.vid_end = vinfo->vid; vlan.vid_end = vinfo->vid;
if (vlan.vid_end <= vlan.vid_begin) if (vlan.vid_end <= vlan.vid_begin)
return -EINVAL; return -EINVAL;
err = f(dev, SWITCHDEV_OBJ_ID_PORT_VLAN, &vlan); err = f(dev, SWITCHDEV_OBJ_ID_PORT_VLAN, &vlan.obj);
if (err) if (err)
return err; return err;
memset(&vlan, 0, sizeof(vlan)); memset(&vlan, 0, sizeof(vlan));
...@@ -734,7 +736,7 @@ static int switchdev_port_br_afspec(struct net_device *dev, ...@@ -734,7 +736,7 @@ static int switchdev_port_br_afspec(struct net_device *dev,
return -EINVAL; return -EINVAL;
vlan.vid_begin = vinfo->vid; vlan.vid_begin = vinfo->vid;
vlan.vid_end = vinfo->vid; vlan.vid_end = vinfo->vid;
err = f(dev, SWITCHDEV_OBJ_ID_PORT_VLAN, &vlan); err = f(dev, SWITCHDEV_OBJ_ID_PORT_VLAN, &vlan.obj);
if (err) if (err)
return err; return err;
memset(&vlan, 0, sizeof(vlan)); memset(&vlan, 0, sizeof(vlan));
...@@ -824,7 +826,7 @@ int switchdev_port_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], ...@@ -824,7 +826,7 @@ int switchdev_port_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
.vid = vid, .vid = vid,
}; };
return switchdev_port_obj_add(dev, SWITCHDEV_OBJ_ID_PORT_FDB, &fdb); return switchdev_port_obj_add(dev, SWITCHDEV_OBJ_ID_PORT_FDB, &fdb.obj);
} }
EXPORT_SYMBOL_GPL(switchdev_port_fdb_add); EXPORT_SYMBOL_GPL(switchdev_port_fdb_add);
...@@ -848,7 +850,7 @@ int switchdev_port_fdb_del(struct ndmsg *ndm, struct nlattr *tb[], ...@@ -848,7 +850,7 @@ int switchdev_port_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
.vid = vid, .vid = vid,
}; };
return switchdev_port_obj_del(dev, SWITCHDEV_OBJ_ID_PORT_FDB, &fdb); return switchdev_port_obj_del(dev, SWITCHDEV_OBJ_ID_PORT_FDB, &fdb.obj);
} }
EXPORT_SYMBOL_GPL(switchdev_port_fdb_del); EXPORT_SYMBOL_GPL(switchdev_port_fdb_del);
...@@ -860,9 +862,9 @@ struct switchdev_fdb_dump { ...@@ -860,9 +862,9 @@ struct switchdev_fdb_dump {
int idx; int idx;
}; };
static int switchdev_port_fdb_dump_cb(void *obj) static int switchdev_port_fdb_dump_cb(struct switchdev_obj *obj)
{ {
struct switchdev_obj_port_fdb *fdb = obj; struct switchdev_obj_port_fdb *fdb = SWITCHDEV_OBJ_PORT_FDB(obj);
struct switchdev_fdb_dump *dump = struct switchdev_fdb_dump *dump =
container_of(fdb, struct switchdev_fdb_dump, fdb); container_of(fdb, struct switchdev_fdb_dump, fdb);
u32 portid = NETLINK_CB(dump->cb->skb).portid; u32 portid = NETLINK_CB(dump->cb->skb).portid;
...@@ -926,7 +928,7 @@ int switchdev_port_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb, ...@@ -926,7 +928,7 @@ int switchdev_port_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb,
.idx = idx, .idx = idx,
}; };
switchdev_port_obj_dump(dev, SWITCHDEV_OBJ_ID_PORT_FDB, &dump.fdb, switchdev_port_obj_dump(dev, SWITCHDEV_OBJ_ID_PORT_FDB, &dump.fdb.obj,
switchdev_port_fdb_dump_cb); switchdev_port_fdb_dump_cb);
return dump.idx; return dump.idx;
} }
...@@ -1033,7 +1035,8 @@ int switchdev_fib_ipv4_add(u32 dst, int dst_len, struct fib_info *fi, ...@@ -1033,7 +1035,8 @@ int switchdev_fib_ipv4_add(u32 dst, int dst_len, struct fib_info *fi,
if (!dev) if (!dev)
return 0; return 0;
err = switchdev_port_obj_add(dev, SWITCHDEV_OBJ_ID_IPV4_FIB, &ipv4_fib); err = switchdev_port_obj_add(dev, SWITCHDEV_OBJ_ID_IPV4_FIB,
&ipv4_fib.obj);
if (!err) if (!err)
fi->fib_flags |= RTNH_F_OFFLOAD; fi->fib_flags |= RTNH_F_OFFLOAD;
...@@ -1075,7 +1078,8 @@ int switchdev_fib_ipv4_del(u32 dst, int dst_len, struct fib_info *fi, ...@@ -1075,7 +1078,8 @@ int switchdev_fib_ipv4_del(u32 dst, int dst_len, struct fib_info *fi,
if (!dev) if (!dev)
return 0; return 0;
err = switchdev_port_obj_del(dev, SWITCHDEV_OBJ_ID_IPV4_FIB, &ipv4_fib); err = switchdev_port_obj_del(dev, SWITCHDEV_OBJ_ID_IPV4_FIB,
&ipv4_fib.obj);
if (!err) if (!err)
fi->fib_flags &= ~RTNH_F_OFFLOAD; fi->fib_flags &= ~RTNH_F_OFFLOAD;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment