Skip to content

Commit 314f76d

Browse files
vladimirolteandavem330
authored andcommitted
net: dsa: Add more convenient functions for installing port VLANs
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 <[email protected]> Reviewed-by: Florian Fainelli <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent e74f014 commit 314f76d

File tree

3 files changed

+36
-21
lines changed

3 files changed

+36
-21
lines changed

net/dsa/dsa_priv.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ int dsa_port_vlan_add(struct dsa_port *dp,
171171
struct switchdev_trans *trans);
172172
int dsa_port_vlan_del(struct dsa_port *dp,
173173
const struct switchdev_obj_port_vlan *vlan);
174+
int dsa_port_vid_add(struct dsa_port *dp, u16 vid, u16 flags);
175+
int dsa_port_vid_del(struct dsa_port *dp, u16 vid);
174176
int dsa_port_link_register_of(struct dsa_port *dp);
175177
void dsa_port_link_unregister_of(struct dsa_port *dp);
176178

net/dsa/port.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,37 @@ int dsa_port_vlan_del(struct dsa_port *dp,
370370
return 0;
371371
}
372372

373+
int dsa_port_vid_add(struct dsa_port *dp, u16 vid, u16 flags)
374+
{
375+
struct switchdev_obj_port_vlan vlan = {
376+
.obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
377+
.flags = flags,
378+
.vid_begin = vid,
379+
.vid_end = vid,
380+
};
381+
struct switchdev_trans trans;
382+
int err;
383+
384+
trans.ph_prepare = true;
385+
err = dsa_port_vlan_add(dp, &vlan, &trans);
386+
if (err == -EOPNOTSUPP)
387+
return 0;
388+
389+
trans.ph_prepare = false;
390+
return dsa_port_vlan_add(dp, &vlan, &trans);
391+
}
392+
393+
int dsa_port_vid_del(struct dsa_port *dp, u16 vid)
394+
{
395+
struct switchdev_obj_port_vlan vlan = {
396+
.obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
397+
.vid_begin = vid,
398+
.vid_end = vid,
399+
};
400+
401+
return dsa_port_vlan_del(dp, &vlan);
402+
}
403+
373404
static struct phy_device *dsa_port_get_phy_device(struct dsa_port *dp)
374405
{
375406
struct device_node *phy_dn;

net/dsa/slave.c

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,13 +1001,6 @@ static int dsa_slave_vlan_rx_add_vid(struct net_device *dev, __be16 proto,
10011001
u16 vid)
10021002
{
10031003
struct dsa_port *dp = dsa_slave_to_port(dev);
1004-
struct switchdev_obj_port_vlan vlan = {
1005-
.vid_begin = vid,
1006-
.vid_end = vid,
1007-
/* This API only allows programming tagged, non-PVID VIDs */
1008-
.flags = 0,
1009-
};
1010-
struct switchdev_trans trans;
10111004
struct bridge_vlan_info info;
10121005
int ret;
10131006

@@ -1024,25 +1017,14 @@ static int dsa_slave_vlan_rx_add_vid(struct net_device *dev, __be16 proto,
10241017
return -EBUSY;
10251018
}
10261019

1027-
trans.ph_prepare = true;
1028-
ret = dsa_port_vlan_add(dp, &vlan, &trans);
1029-
if (ret == -EOPNOTSUPP)
1030-
return 0;
1031-
1032-
trans.ph_prepare = false;
1033-
return dsa_port_vlan_add(dp, &vlan, &trans);
1020+
/* This API only allows programming tagged, non-PVID VIDs */
1021+
return dsa_port_vid_add(dp, vid, 0);
10341022
}
10351023

10361024
static int dsa_slave_vlan_rx_kill_vid(struct net_device *dev, __be16 proto,
10371025
u16 vid)
10381026
{
10391027
struct dsa_port *dp = dsa_slave_to_port(dev);
1040-
struct switchdev_obj_port_vlan vlan = {
1041-
.vid_begin = vid,
1042-
.vid_end = vid,
1043-
/* This API only allows programming tagged, non-PVID VIDs */
1044-
.flags = 0,
1045-
};
10461028
struct bridge_vlan_info info;
10471029
int ret;
10481030

@@ -1059,7 +1041,7 @@ static int dsa_slave_vlan_rx_kill_vid(struct net_device *dev, __be16 proto,
10591041
return -EBUSY;
10601042
}
10611043

1062-
ret = dsa_port_vlan_del(dp, &vlan);
1044+
ret = dsa_port_vid_del(dp, vid);
10631045
if (ret == -EOPNOTSUPP)
10641046
ret = 0;
10651047

0 commit comments

Comments
 (0)