net: dsa: Add more convenient functions for installing port VLANs
authorVladimir Oltean <olteanv@gmail.com>
Sun, 28 Apr 2019 18:45:54 +0000 (21:45 +0300)
committerDavid S. Miller <davem@davemloft.net>
Wed, 1 May 2019 03:05:29 +0000 (23:05 -0400)
This hides the need to perform a two-phase transaction and construct a
switchdev_obj_port_vlan struct.

Call graph (including a function that will be introduced in a follow-up
patch) looks like this now (same for the *_vlan_del function):

dsa_slave_vlan_rx_add_vid   dsa_port_setup_8021q_tagging
            |                        |
            |                        |
            |          +-------------+
            |          |
            v          v
           dsa_port_vid_add      dsa_slave_port_obj_add
                  |                         |
                  +-------+         +-------+
                          |         |
                          v         v
                       dsa_port_vlan_add

Signed-off-by: Vladimir Oltean <olteanv@gmail.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/dsa/dsa_priv.h
net/dsa/port.c
net/dsa/slave.c

index e860512d673ab78f531803061d67fc5623d8c10d..37751b5055728614d8d2134eeac199067d88ebc9 100644 (file)
@@ -171,6 +171,8 @@ int dsa_port_vlan_add(struct dsa_port *dp,
                      struct switchdev_trans *trans);
 int dsa_port_vlan_del(struct dsa_port *dp,
                      const struct switchdev_obj_port_vlan *vlan);
+int dsa_port_vid_add(struct dsa_port *dp, u16 vid, u16 flags);
+int dsa_port_vid_del(struct dsa_port *dp, u16 vid);
 int dsa_port_link_register_of(struct dsa_port *dp);
 void dsa_port_link_unregister_of(struct dsa_port *dp);
 
index aa7ec043d5ba4110414749b6ed51c7ee7601b982..1ed287b2badd344fafef4baf01af938b1c8ff5ac 100644 (file)
@@ -370,6 +370,37 @@ int dsa_port_vlan_del(struct dsa_port *dp,
        return 0;
 }
 
+int dsa_port_vid_add(struct dsa_port *dp, u16 vid, u16 flags)
+{
+       struct switchdev_obj_port_vlan vlan = {
+               .obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
+               .flags = flags,
+               .vid_begin = vid,
+               .vid_end = vid,
+       };
+       struct switchdev_trans trans;
+       int err;
+
+       trans.ph_prepare = true;
+       err = dsa_port_vlan_add(dp, &vlan, &trans);
+       if (err == -EOPNOTSUPP)
+               return 0;
+
+       trans.ph_prepare = false;
+       return dsa_port_vlan_add(dp, &vlan, &trans);
+}
+
+int dsa_port_vid_del(struct dsa_port *dp, u16 vid)
+{
+       struct switchdev_obj_port_vlan vlan = {
+               .obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
+               .vid_begin = vid,
+               .vid_end = vid,
+       };
+
+       return dsa_port_vlan_del(dp, &vlan);
+}
+
 static struct phy_device *dsa_port_get_phy_device(struct dsa_port *dp)
 {
        struct device_node *phy_dn;
index ce26dddc82707a6e90a1b8e02d8f175d34201ae8..8ad9bf957da19a20a7814b3ec7f9f08a7ad94d5d 100644 (file)
@@ -1001,13 +1001,6 @@ static int dsa_slave_vlan_rx_add_vid(struct net_device *dev, __be16 proto,
                                     u16 vid)
 {
        struct dsa_port *dp = dsa_slave_to_port(dev);
-       struct switchdev_obj_port_vlan vlan = {
-               .vid_begin = vid,
-               .vid_end = vid,
-               /* This API only allows programming tagged, non-PVID VIDs */
-               .flags = 0,
-       };
-       struct switchdev_trans trans;
        struct bridge_vlan_info info;
        int ret;
 
@@ -1024,25 +1017,14 @@ static int dsa_slave_vlan_rx_add_vid(struct net_device *dev, __be16 proto,
                        return -EBUSY;
        }
 
-       trans.ph_prepare = true;
-       ret = dsa_port_vlan_add(dp, &vlan, &trans);
-       if (ret == -EOPNOTSUPP)
-               return 0;
-
-       trans.ph_prepare = false;
-       return dsa_port_vlan_add(dp, &vlan, &trans);
+       /* This API only allows programming tagged, non-PVID VIDs */
+       return dsa_port_vid_add(dp, vid, 0);
 }
 
 static int dsa_slave_vlan_rx_kill_vid(struct net_device *dev, __be16 proto,
                                      u16 vid)
 {
        struct dsa_port *dp = dsa_slave_to_port(dev);
-       struct switchdev_obj_port_vlan vlan = {
-               .vid_begin = vid,
-               .vid_end = vid,
-               /* This API only allows programming tagged, non-PVID VIDs */
-               .flags = 0,
-       };
        struct bridge_vlan_info info;
        int ret;
 
@@ -1059,7 +1041,7 @@ static int dsa_slave_vlan_rx_kill_vid(struct net_device *dev, __be16 proto,
                        return -EBUSY;
        }
 
-       ret = dsa_port_vlan_del(dp, &vlan);
+       ret = dsa_port_vid_del(dp, vid);
        if (ret == -EOPNOTSUPP)
                ret = 0;