Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ab069002 authored by Vivien Didelot's avatar Vivien Didelot Committed by David S. Miller
Browse files

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: default avatarVivien Didelot <vivien.didelot@savoirfairelinux.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 25f07adc
Loading
Loading
Loading
Loading
+10 −11
Original line number Diff line number Diff line
@@ -4437,26 +4437,25 @@ static int rocker_port_fdb_add(struct rocker_port *rocker_port,
}

static int rocker_port_obj_add(struct net_device *dev,
			       struct switchdev_obj *obj,
			       enum switchdev_obj_id id, const void *obj,
			       struct switchdev_trans *trans)
{
	struct rocker_port *rocker_port = netdev_priv(dev);
	const struct switchdev_obj_ipv4_fib *fib4;
	int err = 0;

	switch (obj->id) {
	switch (id) {
	case SWITCHDEV_OBJ_PORT_VLAN:
		err = rocker_port_vlans_add(rocker_port, trans,
					    &obj->u.vlan);
		err = rocker_port_vlans_add(rocker_port, trans, obj);
		break;
	case SWITCHDEV_OBJ_IPV4_FIB:
		fib4 = &obj->u.ipv4_fib;
		fib4 = obj;
		err = rocker_port_fib_ipv4(rocker_port, trans,
					   htonl(fib4->dst), fib4->dst_len,
					   fib4->fi, fib4->tb_id, 0);
		break;
	case SWITCHDEV_OBJ_PORT_FDB:
		err = rocker_port_fdb_add(rocker_port, trans, &obj->u.fdb);
		err = rocker_port_fdb_add(rocker_port, trans, obj);
		break;
	default:
		err = -EOPNOTSUPP;
@@ -4509,25 +4508,25 @@ static int rocker_port_fdb_del(struct rocker_port *rocker_port,
}

static int rocker_port_obj_del(struct net_device *dev,
			       struct switchdev_obj *obj)
			       enum switchdev_obj_id id, const void *obj)
{
	struct rocker_port *rocker_port = netdev_priv(dev);
	const struct switchdev_obj_ipv4_fib *fib4;
	int err = 0;

	switch (obj->id) {
	switch (id) {
	case SWITCHDEV_OBJ_PORT_VLAN:
		err = rocker_port_vlans_del(rocker_port, &obj->u.vlan);
		err = rocker_port_vlans_del(rocker_port, obj);
		break;
	case SWITCHDEV_OBJ_IPV4_FIB:
		fib4 = &obj->u.ipv4_fib;
		fib4 = obj;
		err = rocker_port_fib_ipv4(rocker_port, NULL,
					   htonl(fib4->dst), fib4->dst_len,
					   fib4->fi, fib4->tb_id,
					   ROCKER_OP_FLAG_REMOVE);
		break;
	case SWITCHDEV_OBJ_PORT_FDB:
		err = rocker_port_fdb_del(rocker_port, NULL, &obj->u.fdb);
		err = rocker_port_fdb_del(rocker_port, NULL, obj);
		break;
	default:
		err = -EOPNOTSUPP;
+12 −6
Original line number Diff line number Diff line
@@ -115,10 +115,12 @@ struct switchdev_ops {
					   struct switchdev_attr *attr,
					   struct switchdev_trans *trans);
	int	(*switchdev_port_obj_add)(struct net_device *dev,
					  struct switchdev_obj *obj,
					  enum switchdev_obj_id id,
					  const void *obj,
					  struct switchdev_trans *trans);
	int	(*switchdev_port_obj_del)(struct net_device *dev,
					  struct switchdev_obj *obj);
					  enum switchdev_obj_id id,
					  const void *obj);
	int	(*switchdev_port_obj_dump)(struct net_device *dev,
					   enum switchdev_obj_id id, void *obj,
					   int (*cb)(void *obj));
@@ -151,8 +153,10 @@ int switchdev_port_attr_get(struct net_device *dev,
			    struct switchdev_attr *attr);
int switchdev_port_attr_set(struct net_device *dev,
			    struct switchdev_attr *attr);
int switchdev_port_obj_add(struct net_device *dev, struct switchdev_obj *obj);
int switchdev_port_obj_del(struct net_device *dev, struct switchdev_obj *obj);
int switchdev_port_obj_add(struct net_device *dev, enum switchdev_obj_id id,
			   const void *obj);
int switchdev_port_obj_del(struct net_device *dev, enum switchdev_obj_id id,
			   const void *obj);
int switchdev_port_obj_dump(struct net_device *dev, enum switchdev_obj_id id,
			    void *obj, int (*cb)(void *obj));
int register_switchdev_notifier(struct notifier_block *nb);
@@ -199,13 +203,15 @@ static inline int switchdev_port_attr_set(struct net_device *dev,
}

static inline int switchdev_port_obj_add(struct net_device *dev,
					 struct switchdev_obj *obj)
					 enum switchdev_obj_id id,
					 const void *obj)
{
	return -EOPNOTSUPP;
}

static inline int switchdev_port_obj_del(struct net_device *dev,
					 struct switchdev_obj *obj)
					 enum switchdev_obj_id id,
					 const void *obj)
{
	return -EOPNOTSUPP;
}
+4 −7
Original line number Diff line number Diff line
@@ -133,15 +133,12 @@ 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)
{
	struct switchdev_obj obj = {
		.id = SWITCHDEV_OBJ_PORT_FDB,
		.u.fdb = {
	struct switchdev_obj_fdb fdb = {
		.addr = f->addr.addr,
		.vid = f->vlan_id,
		},
	};

	switchdev_port_obj_del(f->dst->dev, &obj);
	switchdev_port_obj_del(f->dst->dev, SWITCHDEV_OBJ_PORT_FDB, &fdb);
}

static void fdb_delete(struct net_bridge *br, struct net_bridge_fdb_entry *f)
+9 −15
Original line number Diff line number Diff line
@@ -80,16 +80,13 @@ static int __vlan_vid_add(struct net_device *dev, struct net_bridge *br,
	if (ops->ndo_vlan_rx_add_vid) {
		err = vlan_vid_add(dev, br->vlan_proto, vid);
	} else {
		struct switchdev_obj vlan_obj = {
			.id = SWITCHDEV_OBJ_PORT_VLAN,
			.u.vlan = {
		struct switchdev_obj_vlan v = {
			.flags = flags,
			.vid_begin = vid,
			.vid_end = vid,
			},
		};

		err = switchdev_port_obj_add(dev, &vlan_obj);
		err = switchdev_port_obj_add(dev, SWITCHDEV_OBJ_PORT_VLAN, &v);
		if (err == -EOPNOTSUPP)
			err = 0;
	}
@@ -132,15 +129,12 @@ static int __vlan_vid_del(struct net_device *dev, struct net_bridge *br,
	if (ops->ndo_vlan_rx_kill_vid) {
		vlan_vid_del(dev, br->vlan_proto, vid);
	} else {
		struct switchdev_obj vlan_obj = {
			.id = SWITCHDEV_OBJ_PORT_VLAN,
			.u.vlan = {
		struct switchdev_obj_vlan v = {
			.vid_begin = vid,
			.vid_end = vid,
			},
		};

		err = switchdev_port_obj_del(dev, &vlan_obj);
		err = switchdev_port_obj_del(dev, SWITCHDEV_OBJ_PORT_VLAN, &v);
		if (err == -EOPNOTSUPP)
			err = 0;
	}
+8 −12
Original line number Diff line number Diff line
@@ -242,10 +242,9 @@ static int dsa_bridge_check_vlan_range(struct dsa_switch *ds,
}

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

static int dsa_slave_port_vlan_del(struct net_device *dev,
				   struct switchdev_obj *obj)
				   const struct switchdev_obj_vlan *vlan)
{
	struct switchdev_obj_vlan *vlan = &obj->u.vlan;
	struct dsa_slave_priv *p = netdev_priv(dev);
	struct dsa_switch *ds = p->parent;
	u16 vid;
@@ -343,10 +341,9 @@ static int dsa_slave_port_vlan_dump(struct net_device *dev,
}

static int dsa_slave_port_fdb_add(struct net_device *dev,
				  struct switchdev_obj *obj,
				  const struct switchdev_obj_fdb *fdb,
				  struct switchdev_trans *trans)
{
	struct switchdev_obj_fdb *fdb = &obj->u.fdb;
	struct dsa_slave_priv *p = netdev_priv(dev);
	struct dsa_switch *ds = p->parent;
	int ret = -EOPNOTSUPP;
@@ -360,9 +357,8 @@ static int dsa_slave_port_fdb_add(struct net_device *dev,
}

static int dsa_slave_port_fdb_del(struct net_device *dev,
				  struct switchdev_obj *obj)
				  const struct switchdev_obj_fdb *fdb)
{
	struct switchdev_obj_fdb *fdb = &obj->u.fdb;
	struct dsa_slave_priv *p = netdev_priv(dev);
	struct dsa_switch *ds = p->parent;
	int ret = -EOPNOTSUPP;
@@ -473,7 +469,7 @@ static int dsa_slave_port_attr_set(struct net_device *dev,
}

static int dsa_slave_port_obj_add(struct net_device *dev,
				  struct switchdev_obj *obj,
				  enum switchdev_obj_id id, const void *obj,
				  struct switchdev_trans *trans)
{
	int err;
@@ -483,7 +479,7 @@ static int dsa_slave_port_obj_add(struct net_device *dev,
	 * supported, return -EOPNOTSUPP.
	 */

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

static int dsa_slave_port_obj_del(struct net_device *dev,
				  struct switchdev_obj *obj)
				  enum switchdev_obj_id id, const void *obj)
{
	int err;

	switch (obj->id) {
	switch (id) {
	case SWITCHDEV_OBJ_PORT_FDB:
		err = dsa_slave_port_fdb_del(dev, obj);
		break;
Loading