Commit bd8762be authored by David S. Miller's avatar David S. Miller

Merge branch 'switchdev-obj'

Jiri Pirko says:

====================
switchdev: bring back switchdev_obj

Second version of the patch extends to a patchset. Basically this patchset
brings object structure back which disappeared with recent Vivien's patchset.
Also it does a bit of naming changes in order to get the things in line.
Also, object id is put back into object structure.
Thanks to Scott and Vivien for review and suggestions.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents c3fc7ac9 9e8f4a54
...@@ -115,7 +115,7 @@ Switch ID ...@@ -115,7 +115,7 @@ Switch ID
^^^^^^^^^ ^^^^^^^^^
The switchdev driver must implement the switchdev op switchdev_port_attr_get The switchdev driver must implement the switchdev op switchdev_port_attr_get
for SWITCHDEV_ATTR_PORT_PARENT_ID for each port netdev, returning the same for SWITCHDEV_ATTR_ID_PORT_PARENT_ID for each port netdev, returning the same
physical ID for each port of a switch. The ID must be unique between switches physical ID for each port of a switch. The ID must be unique between switches
on the same system. The ID does not need to be unique between switches on on the same system. The ID does not need to be unique between switches on
different systems. different systems.
...@@ -178,7 +178,7 @@ entries are installed, for example, using iproute2 bridge cmd: ...@@ -178,7 +178,7 @@ entries are installed, for example, using iproute2 bridge cmd:
bridge fdb add ADDR dev DEV [vlan VID] [self] bridge fdb add ADDR dev DEV [vlan VID] [self]
The driver should use the helper switchdev_port_fdb_xxx ops for ndo_fdb_xxx The driver should use the helper switchdev_port_fdb_xxx ops for ndo_fdb_xxx
ops, and handle add/delete/dump of SWITCHDEV_OBJ_PORT_FDB object using ops, and handle add/delete/dump of SWITCHDEV_OBJ_ID_PORT_FDB object using
switchdev_port_obj_xxx ops. switchdev_port_obj_xxx ops.
XXX: what should be done if offloading this rule to hardware fails (for XXX: what should be done if offloading this rule to hardware fails (for
...@@ -233,8 +233,9 @@ the bridge's FDB. It's possible, but not optimal, to enable learning on the ...@@ -233,8 +233,9 @@ the bridge's FDB. It's possible, but not optimal, to enable learning on the
device port and on the bridge port, and disable learning_sync. device port and on the bridge port, and disable learning_sync.
To support learning and learning_sync port attributes, the driver implements To support learning and learning_sync port attributes, the driver implements
switchdev op switchdev_port_attr_get/set for SWITCHDEV_ATTR_PORT_BRIDGE_FLAGS. switchdev op switchdev_port_attr_get/set for
The driver should initialize the attributes to the hardware defaults. SWITCHDEV_ATTR_PORT_ID_BRIDGE_FLAGS. The driver should initialize the attributes
to the hardware defaults.
FDB Ageing FDB Ageing
^^^^^^^^^^ ^^^^^^^^^^
...@@ -260,7 +261,7 @@ STP State Change on Port ...@@ -260,7 +261,7 @@ STP State Change on Port
Internally or with a third-party STP protocol implementation (e.g. mstpd), the Internally or with a third-party STP protocol implementation (e.g. mstpd), the
bridge driver maintains the STP state for ports, and will notify the switch bridge driver maintains the STP state for ports, and will notify the switch
driver of STP state change on a port using the switchdev op driver of STP state change on a port using the switchdev op
switchdev_attr_port_set for SWITCHDEV_ATTR_PORT_STP_UPDATE. switchdev_attr_port_set for SWITCHDEV_ATTR_PORT_ID_STP_UPDATE.
State is one of BR_STATE_*. The switch driver can use STP state updates to State is one of BR_STATE_*. The switch driver can use STP state updates to
update ingress packet filter list for the port. For example, if port is update ingress packet filter list for the port. For example, if port is
...@@ -316,9 +317,9 @@ SWITCHDEV_OBJ_IPV[4|6]_FIB object using switchdev_port_obj_xxx ops. ...@@ -316,9 +317,9 @@ SWITCHDEV_OBJ_IPV[4|6]_FIB object using switchdev_port_obj_xxx ops.
switchdev_port_obj_add is used for both adding a new FIB entry to the device, switchdev_port_obj_add is used for both adding a new FIB entry to the device,
or modifying an existing entry on the device. or modifying an existing entry on the device.
XXX: Currently, only SWITCHDEV_OBJ_IPV4_FIB objects are supported. XXX: Currently, only SWITCHDEV_OBJ_ID_IPV4_FIB objects are supported.
SWITCHDEV_OBJ_IPV4_FIB object passes: SWITCHDEV_OBJ_ID_IPV4_FIB object passes:
struct switchdev_obj_ipv4_fib { /* IPV4_FIB */ struct switchdev_obj_ipv4_fib { /* IPV4_FIB */
u32 dst; u32 dst;
......
...@@ -868,7 +868,7 @@ static int mlxsw_sx_port_attr_get(struct net_device *dev, ...@@ -868,7 +868,7 @@ static int mlxsw_sx_port_attr_get(struct net_device *dev,
struct mlxsw_sx *mlxsw_sx = mlxsw_sx_port->mlxsw_sx; struct mlxsw_sx *mlxsw_sx = mlxsw_sx_port->mlxsw_sx;
switch (attr->id) { switch (attr->id) {
case SWITCHDEV_ATTR_PORT_PARENT_ID: case SWITCHDEV_ATTR_ID_PORT_PARENT_ID:
attr->u.ppid.id_len = sizeof(mlxsw_sx->hw_id); attr->u.ppid.id_len = sizeof(mlxsw_sx->hw_id);
memcpy(&attr->u.ppid.id, &mlxsw_sx->hw_id, attr->u.ppid.id_len); memcpy(&attr->u.ppid.id, &mlxsw_sx->hw_id, attr->u.ppid.id_len);
break; break;
......
...@@ -4329,11 +4329,11 @@ static int rocker_port_attr_get(struct net_device *dev, ...@@ -4329,11 +4329,11 @@ static int rocker_port_attr_get(struct net_device *dev,
const struct rocker *rocker = rocker_port->rocker; const struct rocker *rocker = rocker_port->rocker;
switch (attr->id) { switch (attr->id) {
case SWITCHDEV_ATTR_PORT_PARENT_ID: case SWITCHDEV_ATTR_ID_PORT_PARENT_ID:
attr->u.ppid.id_len = sizeof(rocker->hw.id); attr->u.ppid.id_len = sizeof(rocker->hw.id);
memcpy(&attr->u.ppid.id, &rocker->hw.id, attr->u.ppid.id_len); memcpy(&attr->u.ppid.id, &rocker->hw.id, attr->u.ppid.id_len);
break; break;
case SWITCHDEV_ATTR_PORT_BRIDGE_FLAGS: case SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS:
attr->u.brport_flags = rocker_port->brport_flags; attr->u.brport_flags = rocker_port->brport_flags;
break; break;
default: default:
...@@ -4369,12 +4369,12 @@ static int rocker_port_attr_set(struct net_device *dev, ...@@ -4369,12 +4369,12 @@ static int rocker_port_attr_set(struct net_device *dev,
int err = 0; int err = 0;
switch (attr->id) { switch (attr->id) {
case SWITCHDEV_ATTR_PORT_STP_STATE: case SWITCHDEV_ATTR_ID_PORT_STP_STATE:
err = rocker_port_stp_update(rocker_port, trans, err = rocker_port_stp_update(rocker_port, trans,
ROCKER_OP_FLAG_NOWAIT, ROCKER_OP_FLAG_NOWAIT,
attr->u.stp_state); attr->u.stp_state);
break; break;
case SWITCHDEV_ATTR_PORT_BRIDGE_FLAGS: case SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS:
err = rocker_port_brport_flags_set(rocker_port, trans, err = rocker_port_brport_flags_set(rocker_port, trans,
attr->u.brport_flags); attr->u.brport_flags);
break; break;
...@@ -4408,7 +4408,7 @@ static int rocker_port_vlan_add(struct rocker_port *rocker_port, ...@@ -4408,7 +4408,7 @@ static int rocker_port_vlan_add(struct rocker_port *rocker_port,
static int rocker_port_vlans_add(struct rocker_port *rocker_port, static int rocker_port_vlans_add(struct rocker_port *rocker_port,
struct switchdev_trans *trans, struct switchdev_trans *trans,
const struct switchdev_obj_vlan *vlan) const struct switchdev_obj_port_vlan *vlan)
{ {
u16 vid; u16 vid;
int err; int err;
...@@ -4425,7 +4425,7 @@ static int rocker_port_vlans_add(struct rocker_port *rocker_port, ...@@ -4425,7 +4425,7 @@ static int rocker_port_vlans_add(struct rocker_port *rocker_port,
static int rocker_port_fdb_add(struct rocker_port *rocker_port, static int rocker_port_fdb_add(struct rocker_port *rocker_port,
struct switchdev_trans *trans, struct switchdev_trans *trans,
const struct switchdev_obj_fdb *fdb) const struct switchdev_obj_port_fdb *fdb)
{ {
__be16 vlan_id = rocker_port_vid_to_vlan(rocker_port, fdb->vid, NULL); __be16 vlan_id = rocker_port_vid_to_vlan(rocker_port, fdb->vid, NULL);
int flags = 0; int flags = 0;
...@@ -4437,25 +4437,27 @@ static int rocker_port_fdb_add(struct rocker_port *rocker_port, ...@@ -4437,25 +4437,27 @@ 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, 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);
const struct switchdev_obj_ipv4_fib *fib4; const struct switchdev_obj_ipv4_fib *fib4;
int err = 0; int err = 0;
switch (id) { switch (obj->id) {
case SWITCHDEV_OBJ_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_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_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;
...@@ -4480,7 +4482,7 @@ static int rocker_port_vlan_del(struct rocker_port *rocker_port, ...@@ -4480,7 +4482,7 @@ static int rocker_port_vlan_del(struct rocker_port *rocker_port,
} }
static int rocker_port_vlans_del(struct rocker_port *rocker_port, static int rocker_port_vlans_del(struct rocker_port *rocker_port,
const struct switchdev_obj_vlan *vlan) const struct switchdev_obj_port_vlan *vlan)
{ {
u16 vid; u16 vid;
int err; int err;
...@@ -4496,7 +4498,7 @@ static int rocker_port_vlans_del(struct rocker_port *rocker_port, ...@@ -4496,7 +4498,7 @@ static int rocker_port_vlans_del(struct rocker_port *rocker_port,
static int rocker_port_fdb_del(struct rocker_port *rocker_port, static int rocker_port_fdb_del(struct rocker_port *rocker_port,
struct switchdev_trans *trans, struct switchdev_trans *trans,
const struct switchdev_obj_fdb *fdb) const struct switchdev_obj_port_fdb *fdb)
{ {
__be16 vlan_id = rocker_port_vid_to_vlan(rocker_port, fdb->vid, NULL); __be16 vlan_id = rocker_port_vid_to_vlan(rocker_port, fdb->vid, NULL);
int flags = ROCKER_OP_FLAG_NOWAIT | ROCKER_OP_FLAG_REMOVE; int flags = ROCKER_OP_FLAG_NOWAIT | ROCKER_OP_FLAG_REMOVE;
...@@ -4508,25 +4510,27 @@ static int rocker_port_fdb_del(struct rocker_port *rocker_port, ...@@ -4508,25 +4510,27 @@ 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) 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;
int err = 0; int err = 0;
switch (id) { switch (obj->id) {
case SWITCHDEV_OBJ_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_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_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;
...@@ -4537,8 +4541,8 @@ static int rocker_port_obj_del(struct net_device *dev, ...@@ -4537,8 +4541,8 @@ 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_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 +4559,7 @@ static int rocker_port_fdb_dump(const struct rocker_port *rocker_port, ...@@ -4555,7 +4559,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;
} }
...@@ -4565,8 +4569,8 @@ static int rocker_port_fdb_dump(const struct rocker_port *rocker_port, ...@@ -4565,8 +4569,8 @@ 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_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 +4582,7 @@ static int rocker_port_vlan_dump(const struct rocker_port *rocker_port, ...@@ -4578,7 +4582,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 +4591,20 @@ static int rocker_port_vlan_dump(const struct rocker_port *rocker_port, ...@@ -4587,18 +4591,20 @@ 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, struct switchdev_obj *obj,
int (*cb)(void *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 (obj->id) {
case SWITCHDEV_OBJ_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_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;
......
...@@ -39,10 +39,10 @@ static inline bool switchdev_trans_ph_commit(struct switchdev_trans *trans) ...@@ -39,10 +39,10 @@ static inline bool switchdev_trans_ph_commit(struct switchdev_trans *trans)
} }
enum switchdev_attr_id { enum switchdev_attr_id {
SWITCHDEV_ATTR_UNDEFINED, SWITCHDEV_ATTR_ID_UNDEFINED,
SWITCHDEV_ATTR_PORT_PARENT_ID, SWITCHDEV_ATTR_ID_PORT_PARENT_ID,
SWITCHDEV_ATTR_PORT_STP_STATE, SWITCHDEV_ATTR_ID_PORT_STP_STATE,
SWITCHDEV_ATTR_PORT_BRIDGE_FLAGS, SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS,
}; };
struct switchdev_attr { struct switchdev_attr {
...@@ -58,21 +58,30 @@ struct switchdev_attr { ...@@ -58,21 +58,30 @@ struct switchdev_attr {
struct fib_info; struct fib_info;
enum switchdev_obj_id { enum switchdev_obj_id {
SWITCHDEV_OBJ_UNDEFINED, SWITCHDEV_OBJ_ID_UNDEFINED,
SWITCHDEV_OBJ_PORT_VLAN, SWITCHDEV_OBJ_ID_PORT_VLAN,
SWITCHDEV_OBJ_IPV4_FIB, SWITCHDEV_OBJ_ID_IPV4_FIB,
SWITCHDEV_OBJ_PORT_FDB, SWITCHDEV_OBJ_ID_PORT_FDB,
}; };
/* SWITCHDEV_OBJ_PORT_VLAN */ struct switchdev_obj {
struct switchdev_obj_vlan { enum switchdev_obj_id id;
};
/* SWITCHDEV_OBJ_ID_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;
}; };
/* SWITCHDEV_OBJ_IPV4_FIB */ #define SWITCHDEV_OBJ_PORT_VLAN(obj) \
container_of(obj, struct switchdev_obj_port_vlan, obj)
/* 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 +91,27 @@ struct switchdev_obj_ipv4_fib { ...@@ -82,18 +91,27 @@ struct switchdev_obj_ipv4_fib {
u32 tb_id; u32 tb_id;
}; };
/* SWITCHDEV_OBJ_PORT_FDB */ #define SWITCHDEV_OBJ_IPV4_FIB(obj) \
struct switchdev_obj_fdb { container_of(obj, struct switchdev_obj_ipv4_fib, obj)
/* SWITCHDEV_OBJ_ID_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
* *
...@@ -114,15 +132,13 @@ struct switchdev_ops { ...@@ -114,15 +132,13 @@ struct switchdev_ops {
struct switchdev_attr *attr, struct switchdev_attr *attr,
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, const struct switchdev_obj *obj,
const void *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, const struct switchdev_obj *obj);
const void *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, struct switchdev_obj *obj,
int (*cb)(void *obj)); switchdev_obj_dump_cb_t *cb);
}; };
enum switchdev_notifier_type { enum switchdev_notifier_type {
...@@ -152,12 +168,12 @@ int switchdev_port_attr_get(struct net_device *dev, ...@@ -152,12 +168,12 @@ int switchdev_port_attr_get(struct net_device *dev,
struct switchdev_attr *attr); struct switchdev_attr *attr);
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,
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,
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, struct switchdev_obj *obj,
void *obj, int (*cb)(void *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,
...@@ -202,22 +218,20 @@ static inline int switchdev_port_attr_set(struct net_device *dev, ...@@ -202,22 +218,20 @@ 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, const struct switchdev_obj *obj)
const void *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, const struct switchdev_obj *obj)
const void *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, const struct switchdev_obj *obj,
int (*cb)(void *obj)) switchdev_obj_dump_cb_t *cb)
{ {
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
......
...@@ -133,12 +133,13 @@ static void fdb_del_hw_addr(struct net_bridge *br, const unsigned char *addr) ...@@ -133,12 +133,13 @@ static void fdb_del_hw_addr(struct net_bridge *br, const unsigned char *addr)
static void fdb_del_external_learn(struct net_bridge_fdb_entry *f) static void fdb_del_external_learn(struct net_bridge_fdb_entry *f)
{ {
struct switchdev_obj_fdb fdb = { struct switchdev_obj_port_fdb fdb = {
.obj.id = SWITCHDEV_OBJ_ID_PORT_FDB,
.addr = f->addr.addr, .addr = f->addr.addr,
.vid = f->vlan_id, .vid = f->vlan_id,
}; };
switchdev_port_obj_del(f->dst->dev, SWITCHDEV_OBJ_PORT_FDB, &fdb); switchdev_port_obj_del(f->dst->dev, &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)
......
...@@ -40,7 +40,7 @@ void br_log_state(const struct net_bridge_port *p) ...@@ -40,7 +40,7 @@ void br_log_state(const struct net_bridge_port *p)
void br_set_state(struct net_bridge_port *p, unsigned int state) void br_set_state(struct net_bridge_port *p, unsigned int state)
{ {
struct switchdev_attr attr = { struct switchdev_attr attr = {
.id = SWITCHDEV_ATTR_PORT_STP_STATE, .id = SWITCHDEV_ATTR_ID_PORT_STP_STATE,
.u.stp_state = state, .u.stp_state = state,
}; };
int err; int err;
......
...@@ -82,13 +82,14 @@ static int __vlan_vid_add(struct net_device *dev, struct net_bridge *br, ...@@ -82,13 +82,14 @@ static int __vlan_vid_add(struct net_device *dev, struct net_bridge *br,
if (ops->ndo_vlan_rx_add_vid) { if (ops->ndo_vlan_rx_add_vid) {
err = vlan_vid_add(dev, br->vlan_proto, vid); err = vlan_vid_add(dev, br->vlan_proto, vid);
} else { } else {
struct switchdev_obj_vlan v = { struct switchdev_obj_port_vlan v = {
.obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
.flags = flags, .flags = flags,
.vid_begin = vid, .vid_begin = vid,
.vid_end = vid, .vid_end = vid,
}; };
err = switchdev_port_obj_add(dev, SWITCHDEV_OBJ_PORT_VLAN, &v); err = switchdev_port_obj_add(dev, &v.obj);
if (err == -EOPNOTSUPP) if (err == -EOPNOTSUPP)
err = 0; err = 0;
} }
...@@ -131,12 +132,13 @@ static int __vlan_vid_del(struct net_device *dev, struct net_bridge *br, ...@@ -131,12 +132,13 @@ static int __vlan_vid_del(struct net_device *dev, struct net_bridge *br,
if (ops->ndo_vlan_rx_kill_vid) { if (ops->ndo_vlan_rx_kill_vid) {
vlan_vid_del(dev, br->vlan_proto, vid); vlan_vid_del(dev, br->vlan_proto, vid);
} else { } else {
struct switchdev_obj_vlan v = { struct switchdev_obj_port_vlan v = {
.obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
.vid_begin = vid, .vid_begin = vid,
.vid_end = vid, .vid_end = vid,
}; };
err = switchdev_port_obj_del(dev, SWITCHDEV_OBJ_PORT_VLAN, &v); err = switchdev_port_obj_del(dev, &v.obj);
if (err == -EOPNOTSUPP) if (err == -EOPNOTSUPP)
err = 0; err = 0;
} }
......
...@@ -471,7 +471,7 @@ static ssize_t phys_switch_id_show(struct device *dev, ...@@ -471,7 +471,7 @@ static ssize_t phys_switch_id_show(struct device *dev,
if (dev_isalive(netdev)) { if (dev_isalive(netdev)) {
struct switchdev_attr attr = { struct switchdev_attr attr = {
.id = SWITCHDEV_ATTR_PORT_PARENT_ID, .id = SWITCHDEV_ATTR_ID_PORT_PARENT_ID,
.flags = SWITCHDEV_F_NO_RECURSE, .flags = SWITCHDEV_F_NO_RECURSE,
}; };
......
...@@ -1025,7 +1025,7 @@ static int rtnl_phys_switch_id_fill(struct sk_buff *skb, struct net_device *dev) ...@@ -1025,7 +1025,7 @@ static int rtnl_phys_switch_id_fill(struct sk_buff *skb, struct net_device *dev)
{ {
int err; int err;
struct switchdev_attr attr = { struct switchdev_attr attr = {
.id = SWITCHDEV_ATTR_PORT_PARENT_ID, .id = SWITCHDEV_ATTR_ID_PORT_PARENT_ID,
.flags = SWITCHDEV_F_NO_RECURSE, .flags = SWITCHDEV_F_NO_RECURSE,
}; };
......
...@@ -242,7 +242,7 @@ static int dsa_bridge_check_vlan_range(struct dsa_switch *ds, ...@@ -242,7 +242,7 @@ static int dsa_bridge_check_vlan_range(struct dsa_switch *ds,
} }
static int dsa_slave_port_vlan_add(struct net_device *dev, static int dsa_slave_port_vlan_add(struct net_device *dev,
const struct switchdev_obj_vlan *vlan, const struct switchdev_obj_port_vlan *vlan,
struct switchdev_trans *trans) struct switchdev_trans *trans)
{ {
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_slave_priv *p = netdev_priv(dev);
...@@ -278,7 +278,7 @@ static int dsa_slave_port_vlan_add(struct net_device *dev, ...@@ -278,7 +278,7 @@ static int dsa_slave_port_vlan_add(struct net_device *dev,
} }
static int dsa_slave_port_vlan_del(struct net_device *dev, static int dsa_slave_port_vlan_del(struct net_device *dev,
const struct switchdev_obj_vlan *vlan) const struct switchdev_obj_port_vlan *vlan)
{ {
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;
...@@ -298,8 +298,8 @@ static int dsa_slave_port_vlan_del(struct net_device *dev, ...@@ -298,8 +298,8 @@ 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_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;
} }
...@@ -341,7 +341,7 @@ static int dsa_slave_port_vlan_dump(struct net_device *dev, ...@@ -341,7 +341,7 @@ static int dsa_slave_port_vlan_dump(struct net_device *dev,
} }
static int dsa_slave_port_fdb_add(struct net_device *dev, static int dsa_slave_port_fdb_add(struct net_device *dev,
const struct switchdev_obj_fdb *fdb, const struct switchdev_obj_port_fdb *fdb,
struct switchdev_trans *trans) struct switchdev_trans *trans)
{ {
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_slave_priv *p = netdev_priv(dev);
...@@ -357,7 +357,7 @@ static int dsa_slave_port_fdb_add(struct net_device *dev, ...@@ -357,7 +357,7 @@ static int dsa_slave_port_fdb_add(struct net_device *dev,
} }
static int dsa_slave_port_fdb_del(struct net_device *dev, static int dsa_slave_port_fdb_del(struct net_device *dev,
const struct switchdev_obj_fdb *fdb) const struct switchdev_obj_port_fdb *fdb)
{ {
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;
...@@ -370,8 +370,8 @@ static int dsa_slave_port_fdb_del(struct net_device *dev, ...@@ -370,8 +370,8 @@ 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_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;
} }
...@@ -458,7 +458,7 @@ static int dsa_slave_port_attr_set(struct net_device *dev, ...@@ -458,7 +458,7 @@ static int dsa_slave_port_attr_set(struct net_device *dev,
int ret; int ret;
switch (attr->id) { switch (attr->id) {
case SWITCHDEV_ATTR_PORT_STP_STATE: case SWITCHDEV_ATTR_ID_PORT_STP_STATE:
if (switchdev_trans_ph_prepare(trans)) if (switchdev_trans_ph_prepare(trans))
ret = ds->drv->port_stp_update ? 0 : -EOPNOTSUPP; ret = ds->drv->port_stp_update ? 0 : -EOPNOTSUPP;
else else
...@@ -474,7 +474,7 @@ static int dsa_slave_port_attr_set(struct net_device *dev, ...@@ -474,7 +474,7 @@ 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, const struct switchdev_obj *obj,
struct switchdev_trans *trans) struct switchdev_trans *trans)
{ {
int err; int err;
...@@ -484,12 +484,16 @@ static int dsa_slave_port_obj_add(struct net_device *dev, ...@@ -484,12 +484,16 @@ static int dsa_slave_port_obj_add(struct net_device *dev,
* supported, return -EOPNOTSUPP. * supported, return -EOPNOTSUPP.
*/ */
switch (id) { switch (obj->id) {
case SWITCHDEV_OBJ_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_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 +504,18 @@ static int dsa_slave_port_obj_add(struct net_device *dev, ...@@ -500,16 +504,18 @@ 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) const struct switchdev_obj *obj)
{ {
int err; int err;
switch (id) { switch (obj->id) {
case SWITCHDEV_OBJ_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_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 +526,21 @@ static int dsa_slave_port_obj_del(struct net_device *dev, ...@@ -520,17 +526,21 @@ 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, struct switchdev_obj *obj,
int (*cb)(void *obj)) switchdev_obj_dump_cb_t *cb)
{ {
int err; int err;
switch (id) { switch (obj->id) {
case SWITCHDEV_OBJ_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_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;
...@@ -584,7 +594,7 @@ static int dsa_slave_port_attr_get(struct net_device *dev, ...@@ -584,7 +594,7 @@ static int dsa_slave_port_attr_get(struct net_device *dev,
struct dsa_switch *ds = p->parent; struct dsa_switch *ds = p->parent;
switch (attr->id) { switch (attr->id) {
case SWITCHDEV_ATTR_PORT_PARENT_ID: case SWITCHDEV_ATTR_ID_PORT_PARENT_ID:
attr->u.ppid.id_len = sizeof(ds->index); attr->u.ppid.id_len = sizeof(ds->index);
memcpy(&attr->u.ppid.id, &ds->index, attr->u.ppid.id_len); memcpy(&attr->u.ppid.id, &ds->index, attr->u.ppid.id_len);
break; break;
......
...@@ -104,7 +104,7 @@ int switchdev_port_attr_get(struct net_device *dev, struct switchdev_attr *attr) ...@@ -104,7 +104,7 @@ int switchdev_port_attr_get(struct net_device *dev, struct switchdev_attr *attr)
struct net_device *lower_dev; struct net_device *lower_dev;
struct list_head *iter; struct list_head *iter;
struct switchdev_attr first = { struct switchdev_attr first = {
.id = SWITCHDEV_ATTR_UNDEFINED .id = SWITCHDEV_ATTR_ID_UNDEFINED
}; };
int err = -EOPNOTSUPP; int err = -EOPNOTSUPP;
...@@ -124,7 +124,7 @@ int switchdev_port_attr_get(struct net_device *dev, struct switchdev_attr *attr) ...@@ -124,7 +124,7 @@ int switchdev_port_attr_get(struct net_device *dev, struct switchdev_attr *attr)
err = switchdev_port_attr_get(lower_dev, attr); err = switchdev_port_attr_get(lower_dev, attr);
if (err) if (err)
break; break;
if (first.id == SWITCHDEV_ATTR_UNDEFINED) if (first.id == SWITCHDEV_ATTR_ID_UNDEFINED)
first = *attr; first = *attr;
else if (memcmp(&first, attr, sizeof(*attr))) else if (memcmp(&first, attr, sizeof(*attr)))
return -ENODATA; return -ENODATA;
...@@ -270,7 +270,7 @@ int switchdev_port_attr_set(struct net_device *dev, struct switchdev_attr *attr) ...@@ -270,7 +270,7 @@ 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, 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;
...@@ -279,7 +279,7 @@ static int __switchdev_port_obj_add(struct net_device *dev, ...@@ -279,7 +279,7 @@ static int __switchdev_port_obj_add(struct net_device *dev,
int err = -EOPNOTSUPP; int err = -EOPNOTSUPP;
if (ops && ops->switchdev_port_obj_add) if (ops && ops->switchdev_port_obj_add)
return ops->switchdev_port_obj_add(dev, id, obj, trans); return ops->switchdev_port_obj_add(dev, obj, trans);
/* Switch device port(s) may be stacked under /* Switch device port(s) may be stacked under
* bond/team/vlan dev, so recurse down to add object on * bond/team/vlan dev, so recurse down to add object on
...@@ -287,7 +287,7 @@ static int __switchdev_port_obj_add(struct net_device *dev, ...@@ -287,7 +287,7 @@ static int __switchdev_port_obj_add(struct net_device *dev,
*/ */
netdev_for_each_lower_dev(dev, lower_dev, iter) { netdev_for_each_lower_dev(dev, lower_dev, iter) {
err = __switchdev_port_obj_add(lower_dev, id, obj, trans); err = __switchdev_port_obj_add(lower_dev, obj, trans);
if (err) if (err)
break; break;
} }
...@@ -308,8 +308,8 @@ static int __switchdev_port_obj_add(struct net_device *dev, ...@@ -308,8 +308,8 @@ 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,
const void *obj) const struct switchdev_obj *obj)
{ {
struct switchdev_trans trans; struct switchdev_trans trans;
int err; int err;
...@@ -326,7 +326,7 @@ int switchdev_port_obj_add(struct net_device *dev, enum switchdev_obj_id id, ...@@ -326,7 +326,7 @@ int switchdev_port_obj_add(struct net_device *dev, enum switchdev_obj_id id,
*/ */
trans.ph_prepare = true; trans.ph_prepare = true;
err = __switchdev_port_obj_add(dev, id, obj, &trans); err = __switchdev_port_obj_add(dev, obj, &trans);
if (err) { if (err) {
/* Prepare phase failed: abort the transaction. Any /* Prepare phase failed: abort the transaction. Any
* resources reserved in the prepare phase are * resources reserved in the prepare phase are
...@@ -345,8 +345,8 @@ int switchdev_port_obj_add(struct net_device *dev, enum switchdev_obj_id id, ...@@ -345,8 +345,8 @@ int switchdev_port_obj_add(struct net_device *dev, enum switchdev_obj_id id,
*/ */
trans.ph_prepare = false; trans.ph_prepare = false;
err = __switchdev_port_obj_add(dev, id, obj, &trans); err = __switchdev_port_obj_add(dev, obj, &trans);
WARN(err, "%s: Commit of object (id=%d) failed.\n", dev->name, id); WARN(err, "%s: Commit of object (id=%d) failed.\n", dev->name, obj->id);
switchdev_trans_items_warn_destroy(dev, &trans); switchdev_trans_items_warn_destroy(dev, &trans);
return err; return err;
...@@ -360,8 +360,8 @@ EXPORT_SYMBOL_GPL(switchdev_port_obj_add); ...@@ -360,8 +360,8 @@ EXPORT_SYMBOL_GPL(switchdev_port_obj_add);
* @id: object ID * @id: object ID
* @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,
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;
...@@ -369,7 +369,7 @@ int switchdev_port_obj_del(struct net_device *dev, enum switchdev_obj_id id, ...@@ -369,7 +369,7 @@ int switchdev_port_obj_del(struct net_device *dev, enum switchdev_obj_id id,
int err = -EOPNOTSUPP; int err = -EOPNOTSUPP;
if (ops && ops->switchdev_port_obj_del) if (ops && ops->switchdev_port_obj_del)
return ops->switchdev_port_obj_del(dev, id, obj); return ops->switchdev_port_obj_del(dev, obj);
/* Switch device port(s) may be stacked under /* Switch device port(s) may be stacked under
* bond/team/vlan dev, so recurse down to delete object on * bond/team/vlan dev, so recurse down to delete object on
...@@ -377,7 +377,7 @@ int switchdev_port_obj_del(struct net_device *dev, enum switchdev_obj_id id, ...@@ -377,7 +377,7 @@ int switchdev_port_obj_del(struct net_device *dev, enum switchdev_obj_id id,
*/ */
netdev_for_each_lower_dev(dev, lower_dev, iter) { netdev_for_each_lower_dev(dev, lower_dev, iter) {
err = switchdev_port_obj_del(lower_dev, id, obj); err = switchdev_port_obj_del(lower_dev, obj);
if (err) if (err)
break; break;
} }
...@@ -394,8 +394,8 @@ EXPORT_SYMBOL_GPL(switchdev_port_obj_del); ...@@ -394,8 +394,8 @@ EXPORT_SYMBOL_GPL(switchdev_port_obj_del);
* @obj: object to dump * @obj: object to dump
* @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, struct switchdev_obj *obj,
void *obj, int (*cb)(void *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;
...@@ -403,7 +403,7 @@ int switchdev_port_obj_dump(struct net_device *dev, enum switchdev_obj_id id, ...@@ -403,7 +403,7 @@ int switchdev_port_obj_dump(struct net_device *dev, enum switchdev_obj_id id,
int err = -EOPNOTSUPP; int err = -EOPNOTSUPP;
if (ops && ops->switchdev_port_obj_dump) if (ops && ops->switchdev_port_obj_dump)
return ops->switchdev_port_obj_dump(dev, id, obj, cb); return ops->switchdev_port_obj_dump(dev, obj, cb);
/* Switch device port(s) may be stacked under /* Switch device port(s) may be stacked under
* bond/team/vlan dev, so recurse down to dump objects on * bond/team/vlan dev, so recurse down to dump objects on
...@@ -411,7 +411,7 @@ int switchdev_port_obj_dump(struct net_device *dev, enum switchdev_obj_id id, ...@@ -411,7 +411,7 @@ int switchdev_port_obj_dump(struct net_device *dev, enum switchdev_obj_id id,
*/ */
netdev_for_each_lower_dev(dev, lower_dev, iter) { netdev_for_each_lower_dev(dev, lower_dev, iter) {
err = switchdev_port_obj_dump(lower_dev, id, obj, cb); err = switchdev_port_obj_dump(lower_dev, obj, cb);
break; break;
} }
...@@ -483,7 +483,7 @@ int call_switchdev_notifiers(unsigned long val, struct net_device *dev, ...@@ -483,7 +483,7 @@ int call_switchdev_notifiers(unsigned long val, struct net_device *dev,
EXPORT_SYMBOL_GPL(call_switchdev_notifiers); EXPORT_SYMBOL_GPL(call_switchdev_notifiers);
struct switchdev_vlan_dump { struct switchdev_vlan_dump {
struct switchdev_obj_vlan vlan; struct switchdev_obj_port_vlan vlan;
struct sk_buff *skb; struct sk_buff *skb;
u32 filter_mask; u32 filter_mask;
u16 flags; u16 flags;
...@@ -521,9 +521,9 @@ static int switchdev_port_vlan_dump_put(struct switchdev_vlan_dump *dump) ...@@ -521,9 +521,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_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;
...@@ -577,6 +577,7 @@ static int switchdev_port_vlan_fill(struct sk_buff *skb, struct net_device *dev, ...@@ -577,6 +577,7 @@ static int switchdev_port_vlan_fill(struct sk_buff *skb, struct net_device *dev,
u32 filter_mask) u32 filter_mask)
{ {
struct switchdev_vlan_dump dump = { struct switchdev_vlan_dump dump = {
.vlan.obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
.skb = skb, .skb = skb,
.filter_mask = filter_mask, .filter_mask = filter_mask,
}; };
...@@ -584,8 +585,7 @@ static int switchdev_port_vlan_fill(struct sk_buff *skb, struct net_device *dev, ...@@ -584,8 +585,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_PORT_VLAN, err = switchdev_port_obj_dump(dev, &dump.vlan.obj,
&dump.vlan,
switchdev_port_vlan_dump_cb); switchdev_port_vlan_dump_cb);
if (err) if (err)
goto err_out; goto err_out;
...@@ -611,7 +611,7 @@ int switchdev_port_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq, ...@@ -611,7 +611,7 @@ int switchdev_port_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
int nlflags) int nlflags)
{ {
struct switchdev_attr attr = { struct switchdev_attr attr = {
.id = SWITCHDEV_ATTR_PORT_BRIDGE_FLAGS, .id = SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS,
}; };
u16 mode = BRIDGE_MODE_UNDEF; u16 mode = BRIDGE_MODE_UNDEF;
u32 mask = BR_LEARNING | BR_LEARNING_SYNC; u32 mask = BR_LEARNING | BR_LEARNING_SYNC;
...@@ -632,7 +632,7 @@ static int switchdev_port_br_setflag(struct net_device *dev, ...@@ -632,7 +632,7 @@ static int switchdev_port_br_setflag(struct net_device *dev,
unsigned long brport_flag) unsigned long brport_flag)
{ {
struct switchdev_attr attr = { struct switchdev_attr attr = {
.id = SWITCHDEV_ATTR_PORT_BRIDGE_FLAGS, .id = SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS,
}; };
u8 flag = nla_get_u8(nlattr); u8 flag = nla_get_u8(nlattr);
int err; int err;
...@@ -699,12 +699,13 @@ static int switchdev_port_br_setlink_protinfo(struct net_device *dev, ...@@ -699,12 +699,13 @@ static int switchdev_port_br_setlink_protinfo(struct net_device *dev,
static int switchdev_port_br_afspec(struct net_device *dev, 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, const struct switchdev_obj *obj))
const void *obj))
{ {
struct nlattr *attr; struct nlattr *attr;
struct bridge_vlan_info *vinfo; struct bridge_vlan_info *vinfo;
struct switchdev_obj_vlan vlan = { 0 }; struct switchdev_obj_port_vlan vlan = {
.obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
};
int rem; int rem;
int err; int err;
...@@ -725,7 +726,7 @@ static int switchdev_port_br_afspec(struct net_device *dev, ...@@ -725,7 +726,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_PORT_VLAN, &vlan); err = f(dev, &vlan.obj);
if (err) if (err)
return err; return err;
memset(&vlan, 0, sizeof(vlan)); memset(&vlan, 0, sizeof(vlan));
...@@ -734,7 +735,7 @@ static int switchdev_port_br_afspec(struct net_device *dev, ...@@ -734,7 +735,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_PORT_VLAN, &vlan); err = f(dev, &vlan.obj);
if (err) if (err)
return err; return err;
memset(&vlan, 0, sizeof(vlan)); memset(&vlan, 0, sizeof(vlan));
...@@ -819,12 +820,13 @@ int switchdev_port_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], ...@@ -819,12 +820,13 @@ int switchdev_port_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
struct net_device *dev, const unsigned char *addr, struct net_device *dev, const unsigned char *addr,
u16 vid, u16 nlm_flags) u16 vid, u16 nlm_flags)
{ {
struct switchdev_obj_fdb fdb = { struct switchdev_obj_port_fdb fdb = {
.obj.id = SWITCHDEV_OBJ_ID_PORT_FDB,
.addr = addr, .addr = addr,
.vid = vid, .vid = vid,
}; };
return switchdev_port_obj_add(dev, SWITCHDEV_OBJ_PORT_FDB, &fdb); return switchdev_port_obj_add(dev, &fdb.obj);
} }
EXPORT_SYMBOL_GPL(switchdev_port_fdb_add); EXPORT_SYMBOL_GPL(switchdev_port_fdb_add);
...@@ -843,26 +845,27 @@ int switchdev_port_fdb_del(struct ndmsg *ndm, struct nlattr *tb[], ...@@ -843,26 +845,27 @@ int switchdev_port_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
struct net_device *dev, const unsigned char *addr, struct net_device *dev, const unsigned char *addr,
u16 vid) u16 vid)
{ {
struct switchdev_obj_fdb fdb = { struct switchdev_obj_port_fdb fdb = {
.obj.id = SWITCHDEV_OBJ_ID_PORT_FDB,
.addr = addr, .addr = addr,
.vid = vid, .vid = vid,
}; };
return switchdev_port_obj_del(dev, SWITCHDEV_OBJ_PORT_FDB, &fdb); return switchdev_port_obj_del(dev, &fdb.obj);
} }
EXPORT_SYMBOL_GPL(switchdev_port_fdb_del); EXPORT_SYMBOL_GPL(switchdev_port_fdb_del);
struct switchdev_fdb_dump { struct switchdev_fdb_dump {
struct switchdev_obj_fdb fdb; struct switchdev_obj_port_fdb fdb;
struct net_device *dev; struct net_device *dev;
struct sk_buff *skb; struct sk_buff *skb;
struct netlink_callback *cb; struct netlink_callback *cb;
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_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;
...@@ -920,14 +923,14 @@ int switchdev_port_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb, ...@@ -920,14 +923,14 @@ int switchdev_port_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb,
struct net_device *filter_dev, int idx) struct net_device *filter_dev, int idx)
{ {
struct switchdev_fdb_dump dump = { struct switchdev_fdb_dump dump = {
.fdb.obj.id = SWITCHDEV_OBJ_ID_PORT_FDB,
.dev = dev, .dev = dev,
.skb = skb, .skb = skb,
.cb = cb, .cb = cb,
.idx = idx, .idx = idx,
}; };
switchdev_port_obj_dump(dev, SWITCHDEV_OBJ_PORT_FDB, &dump.fdb, switchdev_port_obj_dump(dev, &dump.fdb.obj, switchdev_port_fdb_dump_cb);
switchdev_port_fdb_dump_cb);
return dump.idx; return dump.idx;
} }
EXPORT_SYMBOL_GPL(switchdev_port_fdb_dump); EXPORT_SYMBOL_GPL(switchdev_port_fdb_dump);
...@@ -958,7 +961,7 @@ static struct net_device *switchdev_get_lowest_dev(struct net_device *dev) ...@@ -958,7 +961,7 @@ static struct net_device *switchdev_get_lowest_dev(struct net_device *dev)
static struct net_device *switchdev_get_dev_by_nhs(struct fib_info *fi) static struct net_device *switchdev_get_dev_by_nhs(struct fib_info *fi)
{ {
struct switchdev_attr attr = { struct switchdev_attr attr = {
.id = SWITCHDEV_ATTR_PORT_PARENT_ID, .id = SWITCHDEV_ATTR_ID_PORT_PARENT_ID,
}; };
struct switchdev_attr prev_attr; struct switchdev_attr prev_attr;
struct net_device *dev = NULL; struct net_device *dev = NULL;
...@@ -1006,6 +1009,7 @@ int switchdev_fib_ipv4_add(u32 dst, int dst_len, struct fib_info *fi, ...@@ -1006,6 +1009,7 @@ int switchdev_fib_ipv4_add(u32 dst, int dst_len, struct fib_info *fi,
u8 tos, u8 type, u32 nlflags, u32 tb_id) u8 tos, u8 type, u32 nlflags, u32 tb_id)
{ {
struct switchdev_obj_ipv4_fib ipv4_fib = { struct switchdev_obj_ipv4_fib ipv4_fib = {
.obj.id = SWITCHDEV_OBJ_ID_IPV4_FIB,
.dst = dst, .dst = dst,
.dst_len = dst_len, .dst_len = dst_len,
.fi = fi, .fi = fi,
...@@ -1033,7 +1037,7 @@ int switchdev_fib_ipv4_add(u32 dst, int dst_len, struct fib_info *fi, ...@@ -1033,7 +1037,7 @@ 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_IPV4_FIB, &ipv4_fib); err = switchdev_port_obj_add(dev, &ipv4_fib.obj);
if (!err) if (!err)
fi->fib_flags |= RTNH_F_OFFLOAD; fi->fib_flags |= RTNH_F_OFFLOAD;
...@@ -1057,6 +1061,7 @@ int switchdev_fib_ipv4_del(u32 dst, int dst_len, struct fib_info *fi, ...@@ -1057,6 +1061,7 @@ int switchdev_fib_ipv4_del(u32 dst, int dst_len, struct fib_info *fi,
u8 tos, u8 type, u32 tb_id) u8 tos, u8 type, u32 tb_id)
{ {
struct switchdev_obj_ipv4_fib ipv4_fib = { struct switchdev_obj_ipv4_fib ipv4_fib = {
.obj.id = SWITCHDEV_OBJ_ID_IPV4_FIB,
.dst = dst, .dst = dst,
.dst_len = dst_len, .dst_len = dst_len,
.fi = fi, .fi = fi,
...@@ -1075,7 +1080,7 @@ int switchdev_fib_ipv4_del(u32 dst, int dst_len, struct fib_info *fi, ...@@ -1075,7 +1080,7 @@ 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_IPV4_FIB, &ipv4_fib); err = switchdev_port_obj_del(dev, &ipv4_fib.obj);
if (!err) if (!err)
fi->fib_flags &= ~RTNH_F_OFFLOAD; fi->fib_flags &= ~RTNH_F_OFFLOAD;
...@@ -1107,11 +1112,11 @@ static bool switchdev_port_same_parent_id(struct net_device *a, ...@@ -1107,11 +1112,11 @@ static bool switchdev_port_same_parent_id(struct net_device *a,
struct net_device *b) struct net_device *b)
{ {
struct switchdev_attr a_attr = { struct switchdev_attr a_attr = {
.id = SWITCHDEV_ATTR_PORT_PARENT_ID, .id = SWITCHDEV_ATTR_ID_PORT_PARENT_ID,
.flags = SWITCHDEV_F_NO_RECURSE, .flags = SWITCHDEV_F_NO_RECURSE,
}; };
struct switchdev_attr b_attr = { struct switchdev_attr b_attr = {
.id = SWITCHDEV_ATTR_PORT_PARENT_ID, .id = SWITCHDEV_ATTR_ID_PORT_PARENT_ID,
.flags = SWITCHDEV_F_NO_RECURSE, .flags = SWITCHDEV_F_NO_RECURSE,
}; };
......
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