diff options
author | Vladimir Oltean <olteanv@gmail.com> | 2019-04-28 14:45:54 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2019-04-30 23:05:29 -0400 |
commit | 314f76d7a68bab0516aa52877944e6aacfa0fc3f (patch) | |
tree | 69566e08f1d74a449e6df3d1444ef89925084780 /net/dsa | |
parent | e74f014eb4ceeeefe4e5058daac705422eecb683 (diff) |
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 <olteanv@gmail.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/dsa')
-rw-r--r-- | net/dsa/dsa_priv.h | 2 | ||||
-rw-r--r-- | net/dsa/port.c | 31 | ||||
-rw-r--r-- | net/dsa/slave.c | 24 |
3 files changed, 36 insertions, 21 deletions
diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h index e860512d673a..37751b505572 100644 --- a/net/dsa/dsa_priv.h +++ b/net/dsa/dsa_priv.h | |||
@@ -171,6 +171,8 @@ int dsa_port_vlan_add(struct dsa_port *dp, | |||
171 | struct switchdev_trans *trans); | 171 | struct switchdev_trans *trans); |
172 | int dsa_port_vlan_del(struct dsa_port *dp, | 172 | int dsa_port_vlan_del(struct dsa_port *dp, |
173 | const struct switchdev_obj_port_vlan *vlan); | 173 | 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); | ||
174 | int dsa_port_link_register_of(struct dsa_port *dp); | 176 | int dsa_port_link_register_of(struct dsa_port *dp); |
175 | void dsa_port_link_unregister_of(struct dsa_port *dp); | 177 | void dsa_port_link_unregister_of(struct dsa_port *dp); |
176 | 178 | ||
diff --git a/net/dsa/port.c b/net/dsa/port.c index aa7ec043d5ba..1ed287b2badd 100644 --- a/net/dsa/port.c +++ b/net/dsa/port.c | |||
@@ -370,6 +370,37 @@ int dsa_port_vlan_del(struct dsa_port *dp, | |||
370 | return 0; | 370 | return 0; |
371 | } | 371 | } |
372 | 372 | ||
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 | |||
373 | static struct phy_device *dsa_port_get_phy_device(struct dsa_port *dp) | 404 | static struct phy_device *dsa_port_get_phy_device(struct dsa_port *dp) |
374 | { | 405 | { |
375 | struct device_node *phy_dn; | 406 | struct device_node *phy_dn; |
diff --git a/net/dsa/slave.c b/net/dsa/slave.c index ce26dddc8270..8ad9bf957da1 100644 --- a/net/dsa/slave.c +++ b/net/dsa/slave.c | |||
@@ -1001,13 +1001,6 @@ static int dsa_slave_vlan_rx_add_vid(struct net_device *dev, __be16 proto, | |||
1001 | u16 vid) | 1001 | u16 vid) |
1002 | { | 1002 | { |
1003 | struct dsa_port *dp = dsa_slave_to_port(dev); | 1003 | 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; | ||
1011 | struct bridge_vlan_info info; | 1004 | struct bridge_vlan_info info; |
1012 | int ret; | 1005 | int ret; |
1013 | 1006 | ||
@@ -1024,25 +1017,14 @@ static int dsa_slave_vlan_rx_add_vid(struct net_device *dev, __be16 proto, | |||
1024 | return -EBUSY; | 1017 | return -EBUSY; |
1025 | } | 1018 | } |
1026 | 1019 | ||
1027 | trans.ph_prepare = true; | 1020 | /* This API only allows programming tagged, non-PVID VIDs */ |
1028 | ret = dsa_port_vlan_add(dp, &vlan, &trans); | 1021 | return dsa_port_vid_add(dp, vid, 0); |
1029 | if (ret == -EOPNOTSUPP) | ||
1030 | return 0; | ||
1031 | |||
1032 | trans.ph_prepare = false; | ||
1033 | return dsa_port_vlan_add(dp, &vlan, &trans); | ||
1034 | } | 1022 | } |
1035 | 1023 | ||
1036 | static int dsa_slave_vlan_rx_kill_vid(struct net_device *dev, __be16 proto, | 1024 | static int dsa_slave_vlan_rx_kill_vid(struct net_device *dev, __be16 proto, |
1037 | u16 vid) | 1025 | u16 vid) |
1038 | { | 1026 | { |
1039 | struct dsa_port *dp = dsa_slave_to_port(dev); | 1027 | 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 | }; | ||
1046 | struct bridge_vlan_info info; | 1028 | struct bridge_vlan_info info; |
1047 | int ret; | 1029 | int ret; |
1048 | 1030 | ||
@@ -1059,7 +1041,7 @@ static int dsa_slave_vlan_rx_kill_vid(struct net_device *dev, __be16 proto, | |||
1059 | return -EBUSY; | 1041 | return -EBUSY; |
1060 | } | 1042 | } |
1061 | 1043 | ||
1062 | ret = dsa_port_vlan_del(dp, &vlan); | 1044 | ret = dsa_port_vid_del(dp, vid); |
1063 | if (ret == -EOPNOTSUPP) | 1045 | if (ret == -EOPNOTSUPP) |
1064 | ret = 0; | 1046 | ret = 0; |
1065 | 1047 | ||