DSA tag_8021q cleanup
Vladimir Oltean
maintainerv2 cover DSA tag_8021q cleanup
From: Vladimir Oltean <[email protected]>
This small series tries to consolidate the VLAN handling in DSA a little bit. It reworks tag_8021q to be minimally invasive to the dsa_switch_ops structure. This makes the rest of the code a bit easier to follow.
Vladimir Oltean (4):
net: dsa: tag_8021q: include missing refcount.h
net: dsa: tag_8021q: setup tagging via a single function call
net: dsa: tag_8021q: add a context structure
Revert "net: dsa: Add more convenient functions for installing port
VLANs"
drivers/net/dsa/sja1105/sja1105.h | 3 +- drivers/net/dsa/sja1105/sja1105_main.c | 226 ++++++++++++++----------- include/linux/dsa/8021q.h | 49 +++--- net/dsa/dsa_priv.h | 2 - net/dsa/port.c | 33 ---- net/dsa/slave.c | 34 +++- net/dsa/tag_8021q.c | 138 ++++++++------- 7 files changed, 265 insertions(+), 220 deletions(-)
Signature · 1 line
2.25.1
Vladimir Oltean
maintainerPATCH v2 1/4 net: dsa: tag_8021q: include missing refcount.h
From: Vladimir Oltean <[email protected]>
The previous assumption was that the caller would already have this header file included.
--- include/linux/dsa/8021q.h | 1 + 1 file changed, 1 insertion(+)
include/linux/dsa/8021q.h +1 -0
@@ -5,6 +5,7 @@#ifndef _NET_DSA_8021Q_H#define _NET_DSA_8021Q_H +#include <linux/refcount.h> #include <linux/types.h> struct dsa_switch ;
Signature · 1 line
2.25.1
Vladimir Oltean
maintainerPATCH v2 2/4 net: dsa: tag_8021q: setup tagging via a single function call
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
There is no point in calling dsa_port_setup_8021q_tagging for each individual port. Additionally, it will become more difficult to do that when we'll have a context structure to tag_8021q (next patch). So refactor this now.
---
Changes in v2:
Split from a larger patch.
drivers/net/dsa/sja1105/sja1105_main.c | 15 ++++----------- include/linux/dsa/8021q.h | 6 ++---- net/dsa/tag_8021q.c | 21 +++++++++++++++++++-- 3 files changed, 25 insertions(+), 17 deletions(-)
drivers/net/dsa/sja1105/sja1105_main.c +4 -11
@@ -1934,18 +1934,11 @@ static void sja1105_crosschip_bridge_leave(struct dsa_switch *ds,static int sja1105_setup_8021q_tagging (struct dsa_switch *ds,bool enabled) {struct sja1105_private *priv = ds->priv; -int rc, i; +int rc; -for (i =0 ; i <SJA1105_NUM_PORTS ; i++) { - priv->expect_dsa_8021q = true; - rc =dsa_port_setup_8021q_tagging (ds, i, enabled); - priv->expect_dsa_8021q = false; -if (rc <0 ) { -dev_err (ds->dev,"Failed to setup VLAN tagging for port %d: %d\n" , - i, rc); -return rc; - } - } + rc =dsa_8021q_setup (priv->ds, enabled); +if (rc) +return rc;dev_info (ds->dev,"%s switch tagging\n" , enabled ?"Enabled" :"Disabled" );
include/linux/dsa/8021q.h +2 -4
@@ -25,8 +25,7 @@ struct dsa_8021q_crosschip_link {#if IS_ENABLED (CONFIG_NET_DSA_TAG_8021Q ) -int dsa_port_setup_8021q_tagging (struct dsa_switch *ds,int index, -bool enabled); +int dsa_8021q_setup (struct dsa_switch *ds,bool enabled); int dsa_8021q_crosschip_bridge_join(struct dsa_switch *ds, int port, struct dsa_switch *other_ds,
@@ -57,8 +56,7 @@ bool vid_is_dsa_8021q(u16 vid);#else -int dsa_port_setup_8021q_tagging (struct dsa_switch *ds,int index, -bool enabled) +int dsa_8021q_setup (struct dsa_switch *ds,bool enabled) {return 0 ; }
net/dsa/tag_8021q.c +19 -2
@@ -209,7 +209,7 @@ static int dsa_8021q_vid_apply(struct dsa_switch *ds, int port, u16 vid,* +-+-----+-+-----+-+-----+-+-----+-+ +-+-----+-+-----+-+-----+-+-----+-+ * swp0 swp1 swp2 swp3 swp0 swp1 swp2 swp3 */ -int dsa_port_setup_8021q_tagging (struct dsa_switch *ds,int port,bool enabled) +static int dsa_8021q_setup_port (struct dsa_switch *ds,int port,bool enabled) {int upstream =dsa_upstream_port (ds, port);u16 rx_vid =dsa_8021q_rx_vid (ds, port);
@@ -275,7 +275,24 @@ int dsa_port_setup_8021q_tagging(struct dsa_switch *ds, int port, bool enabled)return err; } -EXPORT_SYMBOL_GPL (dsa_port_setup_8021q_tagging); + +int dsa_8021q_setup (struct dsa_switch *ds,bool enabled) +{ +int rc, port; + +for (port =0 ; port < ds->num_ports; port++) { + rc =dsa_8021q_setup_port (ds, port, enabled); +if (rc <0 ) { +dev_err (ds->dev, +"Failed to setup VLAN tagging for port %d: %d\n" , + port, rc); +return rc; + } + } + +return 0 ; +} +EXPORT_SYMBOL_GPL (dsa_8021q_setup); static int dsa_8021q_crosschip_link_apply(struct dsa_switch *ds, int port, struct dsa_switch *other_ds,
Signature · 1 line
2.25.1
Re: [PATCH v2 net-next 2/4] net: dsa: tag_8021q: setup tagging via a single function call
Quoted 8 lines · Vladimir Oltean
From: Vladimir Oltean <[email protected]>
There is no point in calling
dsa_port_setup_8021q_taggingfor each individual port. Additionally, it will become more difficult to do that when we'll have a context structure totag_8021q(next patch). So refactor this now.Signed-off-by Vladimir Oltean <[email protected]>
Signature · 1 line
Florian
Vladimir Oltean
maintainerPATCH v2 3/4 net: dsa: tag_8021q: add a context structure
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
While working on another tag_8021q driver implementation, some things became apparent:
- It is not mandatory for a DSA driver to offload the tag_8021q VLANs by using the VLAN table per se. For example, it can add custom TCAM rules that simply encapsulate RX traffic, and redirect & decapsulate rules for TX traffic. For such a driver, it makes no sense to receive the tag_8021q configuration through the same callback as it receives the VLAN configuration from the bridge and the 8021q modules.
- Currently, sja1105 (the only tag_8021q user) sets a priv->expect_dsa_8021q variable to distinguish between the bridge calling, and tag_8021q calling. That can be improved, to say the least.
- The crosschip bridging operations are, in fact, stateful already. The list of crosschip_links must be kept by the caller and passed to the relevant tag_8021q functions.
So it would be nice if the tag_8021q configuration was more self-contained. This patch attempts to do that.
Create a struct dsa_8021q_context which encapsulates a struct dsa_switch, and has 2 function pointers for adding and deleting a VLAN. These will replace the previous channel to the driver, which was through the .port_vlan_add and .port_vlan_del callbacks of dsa_switch_ops.
Also put the list of crosschip_links into this dsa_8021q_context. Drivers that don't support cross-chip bridging can simply omit to initialize this list, as long as they dont call any cross-chip function.
The sja1105_vlan_add and sja1105_vlan_del functions are refactored into a smaller sja1105_vlan_add_one, which now has 2 entry points:
- sja1105_vlan_add, from struct dsa_switch_ops
- sja1105_dsa_8021q_vlan_add, from the tag_8021q ops
But even this change is fairly trivial. It just reflects the fact that for sja1105, the VLANs from these 2 channels end up in the same hardware table. However that is not necessarily true in the general sense (and that's the reason for making this change).
The rest of the patch is mostly plain refactoring of "ds" -> "ctx". The dsa_8021q_context structure needs to be propagated because adding a VLAN is now done through the ops function pointers inside of it.
---
Changes in v2:
Improved commit message.
Avoided some useless and incorrect refactoring. This should be a more trivial change now.
drivers/net/dsa/sja1105/sja1105.h | 3 +- drivers/net/dsa/sja1105/sja1105_main.c | 213 +++++++++++++++---------- include/linux/dsa/8021q.h | 46 +++--- net/dsa/tag_8021q.c | 127 ++++++++------- 4 files changed, 216 insertions(+), 173 deletions(-)
drivers/net/dsa/sja1105/sja1105.h +1 -2
@@ -210,14 +210,13 @@ struct sja1105_private {struct dsa_switch *ds;struct list_head dsa_8021q_vlans;struct list_head bridge_vlans; -struct list_head crosschip_links;struct sja1105_flow_block flow_block;struct sja1105_port ports[SJA1105_NUM_PORTS ];/* Serializes transmission of management frames so that * the switch doesn't confuse them with one another. */ struct mutex mgmt_lock; -bool expect_dsa_8021q; +struct dsa_8021q_context *dsa_8021q_ctx;enum sja1105_vlan_state vlan_state;struct sja1105_cbs_entry *cbs;struct sja1105_tagger_data tagger_data;
drivers/net/dsa/sja1105/sja1105_main.c +125 -88
345 lines not on this page · raw message
include/linux/dsa/8021q.h +27 -19
80 lines not on this page · raw message
net/dsa/tag_8021q.c +63 -64
276 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [PATCH v2 net-next 3/4] net: dsa: tag_8021q: add a context structure
Quoted 42 lines · Vladimir Oltean
From: Vladimir Oltean <[email protected]>
While working on another
tag_8021qdriver implementation, some things became apparent:- It is not mandatory for a DSA driver to offload the
tag_8021qVLANs by using the VLAN table per se. For example, it can add custom TCAM rules that simply encapsulate RX traffic, and redirect & decapsulate rules for TX traffic. For such a driver, it makes no sense to receive thetag_8021qconfiguration through the same callback as it receives the VLAN configuration from the bridge and the 8021q modules.- Currently, sja1105 (the only
tag_8021quser) sets apriv->expect_dsa_8021qvariable to distinguish between the bridge calling, andtag_8021qcalling. That can be improved, to say the least.- The crosschip bridging operations are, in fact, stateful already. The list of
crosschip_linksmust be kept by the caller and passed to the relevanttag_8021qfunctions.So it would be nice if the
tag_8021qconfiguration was more self-contained. This patch attempts to do that.Create a struct
dsa_8021q_contextwhich encapsulates a structdsa_switch, and has 2 function pointers for adding and deleting a VLAN. These will replace the previous channel to the driver, which was through the .port_vlan_add and .port_vlan_del callbacks ofdsa_switch_ops.Also put the list of
crosschip_linksinto thisdsa_8021q_context. Drivers that don't support cross-chip bridging can simply omit to initialize this list, as long as they dont call any cross-chip function.The
sja1105_vlan_addandsja1105_vlan_delfunctions are refactored into a smallersja1105_vlan_add_one, which now has 2 entry points:
-sja1105_vlan_add, from structdsa_switch_ops
-sja1105_dsa_8021q_vlan_add, from thetag_8021qops
But even this change is fairly trivial. It just reflects the fact that for sja1105, the VLANs from these 2 channels end up in the same hardware table. However that is not necessarily true in the general sense (and that's the reason for making this change).
Quoted 5 lines
The rest of the patch is mostly plain refactoring of "ds" -> "ctx". The
dsa_8021q_contextstructure needs to be propagated because adding a VLAN is now done through the ops function pointers inside of it.Signed-off-by Vladimir Oltean <[email protected]>
This was indeed easier to review than v1.
Signature · 1 line
Florian
Vladimir Oltean
maintainerPATCH v2 4/4 Revert "net: dsa: Add more convenient functions for installing port VLANs"
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
This reverts commit 314f76d7a68bab0516aa52877944e6aacfa0fc3f.
Citing that commit message, the call graph was:
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_addNow that tag_8021q has its own ops structure, it no longer relies on dsa_port_vid_add, and therefore on the dsa_switch_ops to install its VLANs.
So dsa_port_vid_add now only has one single caller. So we can simplify the call graph to what it was before, aka:
dsa_slave_vlan_rx_add_vid dsa_slave_port_obj_add
| |
+-------+ +-------+
| |
v v
dsa_port_vlan_add--- net/dsa/dsa_priv.h | 2 -- net/dsa/port.c | 33 --------------------------------- net/dsa/slave.c | 34 +++++++++++++++++++++++++++++++--- 3 files changed, 31 insertions(+), 38 deletions(-)
net/dsa/dsa_priv.h +0 -2
@@ -164,8 +164,6 @@ 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);extern const struct phylink_mac_ops dsa_port_phylink_mac_ops;
net/dsa/port.c +0 -33
@@ -433,39 +433,6 @@ int dsa_port_vlan_del(struct dsa_port *dp,return dsa_port_notify (dp,DSA_NOTIFIER_VLAN_DEL , &info); } -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) -return err; - - trans.ph_prepare = false; -return dsa_port_vlan_add (dp, &vlan, &trans); -} -EXPORT_SYMBOL (dsa_port_vid_add); - -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); -} -EXPORT_SYMBOL (dsa_port_vid_del); -static struct phy_device *dsa_port_get_phy_device (struct dsa_port *dp) {struct device_node *phy_dn;
net/dsa/slave.c +31 -3
@@ -1233,7 +1233,15 @@ 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 = { + .obj.id =SWITCHDEV_OBJ_ID_PORT_VLAN , + .vid_begin = vid, + .vid_end = vid, +/* This API only allows programming tagged, non-PVID VIDs */ + .flags =0 , + };struct bridge_vlan_info info; +struct switchdev_trans trans;int ret;/* Check for a possible bridge VLAN entry now since there is no
@@ -1252,11 +1260,25 @@ static int dsa_slave_vlan_rx_add_vid(struct net_device *dev, __be16 proto,return -EBUSY ; } - ret =dsa_port_vid_add (dp, vid,0 ); +/* User port... */ + trans.ph_prepare = true; + ret =dsa_port_vlan_add (dp, &vlan, &trans); +if (ret) +return ret; + + trans.ph_prepare = false; + ret =dsa_port_vlan_add (dp, &vlan, &trans);if (ret)return ret; - ret =dsa_port_vid_add (dp->cpu_dp, vid,0 ); +/* And CPU port... */ + trans.ph_prepare = true; + ret =dsa_port_vlan_add (dp->cpu_dp, &vlan, &trans); +if (ret) +return ret; + + trans.ph_prepare = false; + ret =dsa_port_vlan_add (dp->cpu_dp, &vlan, &trans);if (ret)return ret;
@@ -1267,6 +1289,12 @@ 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;
@@ -1289,7 +1317,7 @@ static int dsa_slave_vlan_rx_kill_vid(struct net_device *dev, __be16 proto,/* Do not deprogram the CPU port as it may be shared with other user * ports which can be members of this VLAN as well. */ -return dsa_port_vid_del (dp, vid); +return dsa_port_vlan_del (dp, &vlan); }struct dsa_hw_port {
Signature · 1 line
2.25.1
Re: [PATCH v2 net-next 4/4] Revert "net: dsa: Add more convenient functions for installing port VLANs"
Quoted 26 lines · Vladimir Oltean
From: Vladimir Oltean <[email protected]>
This reverts commit
314f76d7a68bab0516aa52877944e6aacfa0fc3f.Citing that commit message, the call graph was:
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_addNow that
tag_8021qhas its own ops structure, it no longer relies ondsa_port_vid_add, and therefore on thedsa_switch_opsto install its VLANs.So
dsa_port_vid_addnow only has one single caller. So we can simplify the call graph to what it was before, aka:
Quoted 8 lines
dsa_slave_vlan_rx_add_vid dsa_slave_port_obj_add | | +-------+ +-------+ | | v v dsa_port_vlan_addSigned-off-by Vladimir Oltean <[email protected]>
I would be keen on keeping this function just because it encapsulates the details of creating the switchdev object and it may be useful to add additional functionality later on (like the DSA master RX VLAN filtering?), but would not object to its removal if others disagree.
Signature · 1 line
Florian
Vladimir Oltean
maintainerRe: [PATCH v2 net-next 4/4] Revert "net: dsa: Add more convenient functions for installing port VLANs"
Quoted 34 lines · Florian Fainelli
Quoted 33 lines · Vladimir Oltean
From: Vladimir Oltean <[email protected]>
This reverts commit
314f76d7a68bab0516aa52877944e6aacfa0fc3f.Citing that commit message, the call graph was:
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_addNow that
tag_8021qhas its own ops structure, it no longer relies ondsa_port_vid_add, and therefore on thedsa_switch_opsto install its VLANs.So
dsa_port_vid_addnow only has one single caller. So we can simplify the call graph to what it was before, aka:dsa_slave_vlan_rx_add_vid dsa_slave_port_obj_add | | +-------+ +-------+ | | v v dsa_port_vlan_add
Quoted 8 lines
Quoted 1 line
Signed-off-by Vladimir Oltean <[email protected]>I would be keen on keeping this function just because it encapsulates the details of creating the switchdev object and it may be useful to add additional functionality later on (like the DSA master RX VLAN filtering?), but would not object to its removal if others disagree.
--
Florian
Hmm, I don't think there's a lot of value in having it, it's confusing to have such a layered call stack, and it shouldn't be an exported symbol any longer in any case.
Also, I already have a patch that calls vlan_vid_add(master) and having this dsa_port_vid_add() helper doesn't save much at all.
Thanks,
-Vladimir
Florian Fainelli
Reviewed-byRe: [PATCH v2 net-next 4/4] Revert "net: dsa: Add more convenient functions for installing port VLANs"
Quoted 44 lines · Vladimir Oltean
Quoted 34 lines · Florian Fainelli
Quoted 33 lines · Vladimir Oltean
From: Vladimir Oltean <[email protected]>
This reverts commit
314f76d7a68bab0516aa52877944e6aacfa0fc3f.Citing that commit message, the call graph was:
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_addNow that
tag_8021qhas its own ops structure, it no longer relies ondsa_port_vid_add, and therefore on thedsa_switch_opsto install its VLANs.So
dsa_port_vid_addnow only has one single caller. So we can simplify the call graph to what it was before, aka:dsa_slave_vlan_rx_add_vid dsa_slave_port_obj_add | | +-------+ +-------+ | | v v dsa_port_vlan_addQuoted 8 lines
Quoted 1 line
Signed-off-by Vladimir Oltean <[email protected]>I would be keen on keeping this function just because it encapsulates the details of creating the switchdev object and it may be useful to add additional functionality later on (like the DSA master RX VLAN filtering?), but would not object to its removal if others disagree.
--
Florian
Quoted 5 lines
Hmm, I don't think there's a lot of value in having it, it's confusing to have such a layered call stack, and it shouldn't be an exported symbol any longer in any case.
Also, I already have a patch that callsvlan_vid_add(master)and having thisdsa_port_vid_add()helper doesn't save much at all.
OK, I am convinced:
Signature · 1 line
Florian
David Miller
maintainerFrom: Vladimir Oltean <[email protected]>
Date: Thu, 10 Sep 2020 19:48:53 +0300
Quoted 5 lines
From: Vladimir Oltean <[email protected]>
This small series tries to consolidate the VLAN handling in DSA a little bit. It reworks
tag_8021qto be minimally invasive to thedsa_switch_opsstructure. This makes the rest of the code a bit easier to follow.
Series applied, thank you.