net: dsa: add slave VLAN helpers
authorVivien Didelot <vivien.didelot@gmail.com>
Sun, 25 Aug 2019 17:25:17 +0000 (13:25 -0400)
committerDavid S. Miller <davem@davemloft.net>
Wed, 28 Aug 2019 03:17:27 +0000 (20:17 -0700)
Add dsa_slave_vlan_add and dsa_slave_vlan_del helpers to handle
SWITCHDEV_OBJ_ID_PORT_VLAN switchdev objects. Also copy the
switchdev_obj_port_vlan structure on add since we will modify it in
future patches.

Signed-off-by: Vivien Didelot <vivien.didelot@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/dsa/slave.c

index 9d61d9dbf001f2e76f8f12e90e141cb6c1739aef..8f5126c41282f0abaa1e487dbaa212b7beb4179c 100644 (file)
@@ -312,6 +312,26 @@ static int dsa_slave_port_attr_set(struct net_device *dev,
        return ret;
 }
 
+static int dsa_slave_vlan_add(struct net_device *dev,
+                             const struct switchdev_obj *obj,
+                             struct switchdev_trans *trans)
+{
+       struct dsa_port *dp = dsa_slave_to_port(dev);
+       struct switchdev_obj_port_vlan vlan;
+       int err;
+
+       if (obj->orig_dev != dev)
+               return -EOPNOTSUPP;
+
+       vlan = *SWITCHDEV_OBJ_PORT_VLAN(obj);
+
+       err = dsa_port_vlan_add(dp, &vlan, trans);
+       if (err)
+               return err;
+
+       return 0;
+}
+
 static int dsa_slave_port_obj_add(struct net_device *dev,
                                  const struct switchdev_obj *obj,
                                  struct switchdev_trans *trans,
@@ -339,10 +359,7 @@ static int dsa_slave_port_obj_add(struct net_device *dev,
                                       trans);
                break;
        case SWITCHDEV_OBJ_ID_PORT_VLAN:
-               if (obj->orig_dev != dev)
-                       return -EOPNOTSUPP;
-               err = dsa_port_vlan_add(dp, SWITCHDEV_OBJ_PORT_VLAN(obj),
-                                       trans);
+               err = dsa_slave_vlan_add(dev, obj, trans);
                break;
        default:
                err = -EOPNOTSUPP;
@@ -352,6 +369,17 @@ static int dsa_slave_port_obj_add(struct net_device *dev,
        return err;
 }
 
+static int dsa_slave_vlan_del(struct net_device *dev,
+                             const struct switchdev_obj *obj)
+{
+       struct dsa_port *dp = dsa_slave_to_port(dev);
+
+       if (obj->orig_dev != dev)
+               return -EOPNOTSUPP;
+
+       return dsa_port_vlan_del(dp, SWITCHDEV_OBJ_PORT_VLAN(obj));
+}
+
 static int dsa_slave_port_obj_del(struct net_device *dev,
                                  const struct switchdev_obj *obj)
 {
@@ -371,9 +399,7 @@ static int dsa_slave_port_obj_del(struct net_device *dev,
                err = dsa_port_mdb_del(dp->cpu_dp, SWITCHDEV_OBJ_PORT_MDB(obj));
                break;
        case SWITCHDEV_OBJ_ID_PORT_VLAN:
-               if (obj->orig_dev != dev)
-                       return -EOPNOTSUPP;
-               err = dsa_port_vlan_del(dp, SWITCHDEV_OBJ_PORT_VLAN(obj));
+               err = dsa_slave_vlan_del(dev, obj);
                break;
        default:
                err = -EOPNOTSUPP;