Skip to content

Commit

Permalink
net: dsa: Add more convenient functions for installing port VLANs
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Vladimir Oltean authored and David S. Miller committed May 1, 2019
1 parent e74f014 commit 314f76d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 21 deletions.
2 changes: 2 additions & 0 deletions net/dsa/dsa_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
31 changes: 31 additions & 0 deletions net/dsa/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 3 additions & 21 deletions net/dsa/slave.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand All @@ -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;

Expand Down

0 comments on commit 314f76d

Please sign in to comment.