Skip to contentSkip to conversation

Traffic support for dsa_8021q in vlan_filtering=1 mode

PATCH Superseded Vladimir Oltean 3 participants 33 messages May 11, 2020 – May 12, 2020

Subsystems (6)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Vladimir Oltean

author maintainer
#0 lore raw

v2 cover Traffic support for dsa_8021q in vlan_filtering=1 mode

From: Vladimir Oltean <[email protected]>

This series is an attempt to support as much as possible in terms of traffic I/O from the network stack with the only dsa_8021q user thus far, sja1105.

The hardware doesn't support pushing a second VLAN tag to packets that are already tagged, so our only option is to combine the dsa_8021q with the user tag into a single tag and decode that on the CPU.

The assumption is that there is a type of use cases for which 7 VLANs per port are more than sufficient, and that there's another type of use cases where the full 4096 entries are barely enough. Those use cases are very different from one another, so I prefer trying to give both the best experience by creating this best_effort_vlan_filtering knob to select the mode in which they want to operate in.

v1 was submitted here:
https://patchwork.ozlabs.org/project/netdev/cover/[email protected]/

Changes in v2:
Patch 01/15:
- Rename variable from vlan_bridge_vtu to configure_vlans_while_disabled. Patch 03/15:
- Be much more thorough, and make sure that things like virtual links and FDB operations still work properly.
Patch 05/15:
- Free the vlan lists on teardown.
- Simplify sja1105_classify_vlan: only look at priv->expect_dsa_8021q.
- Keep vid 1 in the list of dsa_8021q VLANs, to make sure that untagged packets transmitted from the stack, like PTP, continue to work in VLAN-unaware mode.
Patch 06/15:
- Adapt to vlan_bridge_vtu variable name change.
Patch 11/15:
- In sja1105_best_effort_vlan_filtering_set, get the vlan_filtering value of each port instead of just one time for port 0. Normally this shouldn't matter, but it avoids issues when port 0 is disabled in device tree.
Patch 14/14:
- Only do anything in sja1105_build_subvlans and in sja1105_build_crosschip_subvlans when operating in SJA1105_VLAN_BEST_EFFORT state. This avoids installing VLAN retagging rules in unaware mode, which would cost us a penalty in terms of usable frame memory.

Russell King (1):
net: dsa: provide an option for drivers to always receive bridge VLANs

Vladimir Oltean (14):
net: dsa: tag_8021q: introduce a vid_is_dsa_8021q helper
net: dsa: sja1105: keep the VLAN awareness state in a driver variable
net: dsa: sja1105: deny alterations of dsa_8021q VLANs from the bridge
net: dsa: sja1105: save/restore VLANs using a delta commit method
net: dsa: sja1105: allow VLAN configuration from the bridge in all
states
net: dsa: sja1105: exit sja1105_vlan_filtering when called multiple
times
net: dsa: sja1105: prepare tagger for handling DSA tags and VLAN
simultaneously
net: dsa: tag_8021q: support up to 8 VLANs per port using sub-VLANs
net: dsa: tag_sja1105: implement sub-VLAN decoding
net: dsa: sja1105: add a new best_effort_vlan_filtering devlink
parameter
net: dsa: sja1105: add packing ops for the Retagging Table
net: dsa: sja1105: implement a common frame memory partitioning
function
net: dsa: sja1105: implement VLAN retagging for dsa_8021q sub-VLANs
docs: net: dsa: sja1105: document the best_effort_vlan_filtering
option

 .../networking/devlink-params-sja1105.txt     |   27 +
 Documentation/networking/dsa/sja1105.rst      |  211 ++-
 drivers/net/dsa/sja1105/sja1105.h             |   29 +
 .../net/dsa/sja1105/sja1105_dynamic_config.c  |   33 +
 drivers/net/dsa/sja1105/sja1105_main.c        | 1128 +++++++++++++++--
 drivers/net/dsa/sja1105/sja1105_spi.c         |    6 +
 .../net/dsa/sja1105/sja1105_static_config.c   |   62 +-
 .../net/dsa/sja1105/sja1105_static_config.h   |   16 +
 drivers/net/dsa/sja1105/sja1105_vl.c          |   44 +-
 include/linux/dsa/8021q.h                     |   42 +-
 include/linux/dsa/sja1105.h                   |    5 +
 include/net/dsa.h                             |    7 +
 net/dsa/slave.c                               |   12 +-
 net/dsa/tag_8021q.c                           |  108 +-
 net/dsa/tag_sja1105.c                         |   38 +-
 15 files changed, 1508 insertions(+), 260 deletions(-)
 create mode 100644 Documentation/networking/devlink-params-sja1105.txt
Signature · 1 line
2.17.1
author maintainer
#1 lore raw

PATCH v2 1/15 net: dsa: provide an option for drivers to always receive bridge VLANs

From: Russell King <[email protected]>

DSA assumes that a bridge which has vlan filtering disabled is not vlan aware, and ignores all vlan configuration. However, the kernel software bridge code allows configuration in this state.

This causes the kernel's idea of the bridge vlan state and the hardware state to disagree, so "bridge vlan show" indicates a correct configuration but the hardware lacks all configuration. Even worse, enabling vlan filtering on a DSA bridge immediately blocks all traffic which, given the output of "bridge vlan show", is very confusing.

Provide an option that drivers can set to indicate they want to receive vlan configuration even when vlan filtering is disabled. At the very least, this is safe for Marvell DSA bridges, which do not look up ingress traffic in the VTU if the port is in 8021Q disabled state. It is also safe for the Ocelot switch family. Whether this change is suitable for all DSA bridges is not known.

---
Changes in v2:
Rename variable from vlan_bridge_vtu to configure_vlans_while_disabled.

 include/net/dsa.h |  7 +++++++
 net/dsa/slave.c   | 12 ++++++++----
 2 files changed, 15 insertions(+), 4 deletions(-)
include/net/dsa.h +7 -0
index 312c2f067e65..e794c15d27de 100644
@@ -282,6 +282,13 @@ struct dsa_switch {
 	 */
 	bool			vlan_filtering_is_global;
 
+	/* Pass .port_vlan_add and .port_vlan_del to drivers even for bridges
+	 * that have vlan_filtering=0. All drivers should ideally set this (and
+	 * then the option would get removed), but it is unknown whether this
+	 * would break things or not.
+	 */
+	bool			configure_vlans_while_disabled;
+
 	/* In case vlan_filtering_is_global is set, the VLAN awareness state
 	 * should be retrieved from here and not from the per-port settings.
 	 */
net/dsa/slave.c +8 -4
index 61b0de52040a..06ac7641438e 100644
@@ -314,7 +314,8 @@ static int dsa_slave_vlan_add(struct net_device *dev,
 	if (obj->orig_dev != dev)
 		return -EOPNOTSUPP;
 
-	if (dp->bridge_dev && !br_vlan_enabled(dp->bridge_dev))
+	if (dp->bridge_dev && !br_vlan_enabled(dp->bridge_dev) &&
+	    !dp->ds->configure_vlans_while_disabled)
 		return 0;
 
 	vlan = *SWITCHDEV_OBJ_PORT_VLAN(obj);
@@ -381,7 +382,8 @@ static int dsa_slave_vlan_del(struct net_device *dev,
 	if (obj->orig_dev != dev)
 		return -EOPNOTSUPP;
 
-	if (dp->bridge_dev && !br_vlan_enabled(dp->bridge_dev))
+	if (dp->bridge_dev && !br_vlan_enabled(dp->bridge_dev) &&
+	    !dp->ds->configure_vlans_while_disabled)
 		return 0;
 
 	/* Do not deprogram the CPU port as it may be shared with other user
@@ -1240,7 +1242,8 @@ static int dsa_slave_vlan_rx_add_vid(struct net_device *dev, __be16 proto,
 	 * need to emulate the switchdev prepare + commit phase.
 	 */
 	if (dp->bridge_dev) {
-		if (!br_vlan_enabled(dp->bridge_dev))
+		if (!dp->ds->configure_vlans_while_disabled &&
+		    !br_vlan_enabled(dp->bridge_dev))
 			return 0;
 
 		/* br_vlan_get_info() returns -EINVAL or -ENOENT if the
@@ -1274,7 +1277,8 @@ static int dsa_slave_vlan_rx_kill_vid(struct net_device *dev, __be16 proto,
 	 * need to emulate the switchdev prepare + commit phase.
 	 */
 	if (dp->bridge_dev) {
-		if (!br_vlan_enabled(dp->bridge_dev))
+		if (!dp->ds->configure_vlans_while_disabled &&
+		    !br_vlan_enabled(dp->bridge_dev))
 			return 0;
 
 		/* br_vlan_get_info() returns -EINVAL or -ENOENT if the
Signature · 1 line
2.17.1
Reviewed-by on v2 1/15
#2 lore raw

Re: [PATCH v2 net-next 01/15] net: dsa: provide an option for drivers to always receive bridge VLANs

Quoted 19 lines · Vladimir Oltean

From: Russell King <[email protected]>

DSA assumes that a bridge which has vlan filtering disabled is not vlan aware, and ignores all vlan configuration. However, the kernel software bridge code allows configuration in this state.

This causes the kernel's idea of the bridge vlan state and the hardware state to disagree, so "bridge vlan show" indicates a correct configuration but the hardware lacks all configuration. Even worse, enabling vlan filtering on a DSA bridge immediately blocks all traffic which, given the output of "bridge vlan show", is very confusing.

Provide an option that drivers can set to indicate they want to receive vlan configuration even when vlan filtering is disabled. At the very least, this is safe for Marvell DSA bridges, which do not look up ingress traffic in the VTU if the port is in 8021Q disabled state. It is also safe for the Ocelot switch family. Whether this change is suitable for all DSA bridges is not known.

Quoted 2 lines

We may want to consolidate these checks in a helper function at some point, and the name is still not super clear to me (not sure what disabled refers to unless you read the comments), but this is as good as it could be:

Signature · 1 line
Florian
author maintainer
#3 lore raw

PATCH v2 2/15 net: dsa: tag_8021q: introduce a vid_is_dsa_8021q helper

In reply to Vladimir Oltean

From: Vladimir Oltean <[email protected]>

This function returns a boolean denoting whether the VLAN passed as argument is part of the 1024-3071 range that the dsa_8021q tagging scheme uses.

---
Changes in v2:
None.

 include/linux/dsa/8021q.h | 7 +++++++
 net/dsa/tag_8021q.c       | 7 +++++++
 2 files changed, 14 insertions(+)
include/linux/dsa/8021q.h +7 -0
index b8daaec0896e..ebc245ff838a 100644
@@ -50,6 +50,8 @@ int dsa_8021q_rx_switch_id(u16 vid);
 
 int dsa_8021q_rx_source_port(u16 vid);
 
+bool vid_is_dsa_8021q(u16 vid);
+
 #else
 
 int dsa_port_setup_8021q_tagging(struct dsa_switch *ds, int index,
@@ -107,6 +109,11 @@ int dsa_8021q_rx_source_port(u16 vid)
 	return 0;
 }
 
+bool vid_is_dsa_8021q(u16 vid)
+{
+	return false;
+}
+
 #endif /* IS_ENABLED(CONFIG_NET_DSA_TAG_8021Q) */
 
 #endif /* _NET_DSA_8021Q_H */
net/dsa/tag_8021q.c +7 -0
index ff9c5bf64bda..4774ecd1f8fc 100644
@@ -93,6 +93,13 @@ int dsa_8021q_rx_source_port(u16 vid)
 }
 EXPORT_SYMBOL_GPL(dsa_8021q_rx_source_port);
 
+bool vid_is_dsa_8021q(u16 vid)
+{
+	return ((vid & DSA_8021Q_DIR_MASK) == DSA_8021Q_DIR_RX ||
+		(vid & DSA_8021Q_DIR_MASK) == DSA_8021Q_DIR_TX);
+}
+EXPORT_SYMBOL_GPL(vid_is_dsa_8021q);
+
 static int dsa_8021q_restore_pvid(struct dsa_switch *ds, int port)
 {
 	struct bridge_vlan_info vinfo;
Signature · 1 line
2.17.1
Reviewed-by on v2 2/15
#4 lore raw

Re: [PATCH v2 net-next 02/15] net: dsa: tag_8021q: introduce a vid_is_dsa_8021q helper

Quoted 7 lines · Vladimir Oltean

From: Vladimir Oltean <[email protected]>

This function returns a boolean denoting whether the VLAN passed as argument is part of the 1024-3071 range that the dsa_8021q tagging scheme uses.

Signature · 1 line
Florian
author maintainer
#5 lore raw

PATCH v2 3/15 net: dsa: sja1105: keep the VLAN awareness state in a driver variable

In reply to Vladimir Oltean

From: Vladimir Oltean <[email protected]>

Soon we'll add a third operating mode to the driver. Introduce a vlan_state to make things more easy to manage, and use it where applicable.

---
Changes in v2:
Be much more thorough, and make sure that things like virtual links and FDB operations still work properly.

 drivers/net/dsa/sja1105/sja1105.h      |  6 ++++++
 drivers/net/dsa/sja1105/sja1105_main.c | 26 +++++++++++++++++++++-----
 drivers/net/dsa/sja1105/sja1105_vl.c   | 24 ++++++++++++++----------
 include/linux/dsa/sja1105.h            |  2 ++
 net/dsa/tag_sja1105.c                  |  2 +-
 5 files changed, 44 insertions(+), 16 deletions(-)
drivers/net/dsa/sja1105/sja1105.h +6 -0
index a64ace07b89f..5b2b275d01a7 100644
@@ -178,6 +178,11 @@ struct sja1105_flow_block {
 	int num_virtual_links;
 };
 
+enum sja1105_vlan_state {
+	SJA1105_VLAN_UNAWARE,
+	SJA1105_VLAN_FILTERING_FULL,
+};
+
 struct sja1105_private {
 	struct sja1105_static_config static_config;
 	bool rgmii_rx_delay[SJA1105_NUM_PORTS];
@@ -193,6 +198,7 @@ struct sja1105_private {
 	 * the switch doesn't confuse them with one another.
 	 */
 	struct mutex mgmt_lock;
+	enum sja1105_vlan_state vlan_state;
 	struct sja1105_tagger_data tagger_data;
 	struct sja1105_ptp_data ptp_data;
 	struct sja1105_tas_data tas_data;
drivers/net/dsa/sja1105/sja1105_main.c +21 -5
index d5de9305df25..72e12c02594d 100644
@@ -1303,7 +1303,7 @@ int sja1105pqrs_fdb_add(struct dsa_switch *ds, int port,
 	l2_lookup.vlanid = vid;
 	l2_lookup.iotag = SJA1105_S_TAG;
 	l2_lookup.mask_macaddr = GENMASK_ULL(ETH_ALEN * 8 - 1, 0);
-	if (dsa_port_is_vlan_filtering(dsa_to_port(ds, port))) {
+	if (priv->vlan_state != SJA1105_VLAN_UNAWARE) {
 		l2_lookup.mask_vlanid = VLAN_VID_MASK;
 		l2_lookup.mask_iotag = BIT(0);
 	} else {
@@ -1366,7 +1366,7 @@ int sja1105pqrs_fdb_del(struct dsa_switch *ds, int port,
 	l2_lookup.vlanid = vid;
 	l2_lookup.iotag = SJA1105_S_TAG;
 	l2_lookup.mask_macaddr = GENMASK_ULL(ETH_ALEN * 8 - 1, 0);
-	if (dsa_port_is_vlan_filtering(dsa_to_port(ds, port))) {
+	if (priv->vlan_state != SJA1105_VLAN_UNAWARE) {
 		l2_lookup.mask_vlanid = VLAN_VID_MASK;
 		l2_lookup.mask_iotag = BIT(0);
 	} else {
@@ -1412,7 +1412,7 @@ static int sja1105_fdb_add(struct dsa_switch *ds, int port,
 	 * for what gets printed in 'bridge fdb show'.  In the case of zero,
 	 * no VID gets printed at all.
 	 */
-	if (!dsa_port_is_vlan_filtering(dsa_to_port(ds, port)))
+	if (priv->vlan_state != SJA1105_VLAN_FILTERING_FULL)
 		vid = 0;
 
 	return priv->info->fdb_add_cmd(ds, port, addr, vid);
@@ -1423,7 +1423,7 @@ static int sja1105_fdb_del(struct dsa_switch *ds, int port,
 {
 	struct sja1105_private *priv = ds->priv;
 
-	if (!dsa_port_is_vlan_filtering(dsa_to_port(ds, port)))
+	if (priv->vlan_state != SJA1105_VLAN_FILTERING_FULL)
 		vid = 0;
 
 	return priv->info->fdb_del_cmd(ds, port, addr, vid);
@@ -1462,7 +1462,7 @@ static int sja1105_fdb_dump(struct dsa_switch *ds, int port,
 		u64_to_ether_addr(l2_lookup.macaddr, macaddr);
 
 		/* We need to hide the dsa_8021q VLANs from the user. */
-		if (!dsa_port_is_vlan_filtering(dsa_to_port(ds, port)))
+		if (priv->vlan_state == SJA1105_VLAN_UNAWARE)
 			l2_lookup.vlanid = 0;
 		cb(macaddr, l2_lookup.vlanid, l2_lookup.lockeds, data);
 	}
@@ -1917,6 +1917,7 @@ static int sja1105_vlan_filtering(struct dsa_switch *ds, int port, bool enabled)
 	struct sja1105_l2_lookup_params_entry *l2_lookup_params;
 	struct sja1105_general_params_entry *general_params;
 	struct sja1105_private *priv = ds->priv;
+	enum sja1105_vlan_state state;
 	struct sja1105_table *table;
 	struct sja1105_rule *rule;
 	u16 tpid, tpid2;
@@ -1940,6 +1941,13 @@ static int sja1105_vlan_filtering(struct dsa_switch *ds, int port, bool enabled)
 		tpid2 = ETH_P_SJA1105;
 	}
 
+	if (!enabled)
+		state = SJA1105_VLAN_UNAWARE;
+	else
+		state = SJA1105_VLAN_FILTERING_FULL;
+
+	priv->vlan_state = state;
+
 	table = &priv->static_config.tables[BLK_IDX_GENERAL_PARAMS];
 	general_params = table->entries;
 	/* EtherType used to identify inner tagged (C-tag) VLAN traffic */
@@ -1985,6 +1993,14 @@ static int sja1105_vlan_filtering(struct dsa_switch *ds, int port, bool enabled)
 	return sja1105_setup_8021q_tagging(ds, !enabled);
 }
 
+bool sja1105_can_use_vlan_as_tags(struct dsa_switch *ds)
+{
+	struct sja1105_private *priv = ds->priv;
+
+	return priv->vlan_state != SJA1105_VLAN_FILTERING_FULL;
+}
+EXPORT_SYMBOL_GPL(sja1105_can_use_vlan_as_tags);
+
 static void sja1105_vlan_add(struct dsa_switch *ds, int port,
 			     const struct switchdev_obj_port_vlan *vlan)
 {
drivers/net/dsa/sja1105/sja1105_vl.c +14 -10
index aa9b0b92f437..312401995b54 100644
@@ -353,14 +353,14 @@ int sja1105_vl_redirect(struct sja1105_private *priv, int port,
 	struct sja1105_rule *rule = sja1105_rule_find(priv, cookie);
 	int rc;
 
-	if (dsa_port_is_vlan_filtering(dsa_to_port(priv->ds, port)) &&
-	    key->type != SJA1105_KEY_VLAN_AWARE_VL) {
+	if (priv->vlan_state == SJA1105_VLAN_UNAWARE &&
+	    key->type != SJA1105_KEY_VLAN_UNAWARE_VL) {
 		NL_SET_ERR_MSG_MOD(extack,
-				   "Can only redirect based on {DMAC, VID, PCP}");
+				   "Can only redirect based on DMAC");
 		return -EOPNOTSUPP;
-	} else if (key->type != SJA1105_KEY_VLAN_UNAWARE_VL) {
+	} else if (key->type != SJA1105_KEY_VLAN_AWARE_VL) {
 		NL_SET_ERR_MSG_MOD(extack,
-				   "Can only redirect based on DMAC");
+				   "Can only redirect based on {DMAC, VID, PCP}");
 		return -EOPNOTSUPP;
 	}
 
@@ -602,14 +602,18 @@ int sja1105_vl_gate(struct sja1105_private *priv, int port,
 		return -ERANGE;
 	}
 
-	if (dsa_port_is_vlan_filtering(dsa_to_port(priv->ds, port)) &&
-	    key->type != SJA1105_KEY_VLAN_AWARE_VL) {
+	if (priv->vlan_state == SJA1105_VLAN_UNAWARE &&
+	    key->type != SJA1105_KEY_VLAN_UNAWARE_VL) {
+		dev_err(priv->ds->dev, "1: vlan state %d key type %d\n",
+			priv->vlan_state, key->type);
 		NL_SET_ERR_MSG_MOD(extack,
-				   "Can only gate based on {DMAC, VID, PCP}");
+				   "Can only gate based on DMAC");
 		return -EOPNOTSUPP;
-	} else if (key->type != SJA1105_KEY_VLAN_UNAWARE_VL) {
+	} else if (key->type != SJA1105_KEY_VLAN_AWARE_VL) {
+		dev_err(priv->ds->dev, "2: vlan state %d key type %d\n",
+			priv->vlan_state, key->type);
 		NL_SET_ERR_MSG_MOD(extack,
-				   "Can only gate based on DMAC");
+				   "Can only gate based on {DMAC, VID, PCP}");
 		return -EOPNOTSUPP;
 	}
 
include/linux/dsa/sja1105.h +2 -0
index fa5735c353cd..136481ce3c6f 100644
@@ -61,4 +61,6 @@ struct sja1105_port {
 	bool hwts_tx_en;
 };
 
+bool sja1105_can_use_vlan_as_tags(struct dsa_switch *ds);
+
 #endif /* _NET_DSA_SJA1105_H */
net/dsa/tag_sja1105.c +1 -1
index d553bf36bd41..5368cd34bcf4 100644
@@ -74,7 +74,7 @@ static inline bool sja1105_is_meta_frame(const struct sk_buff *skb)
  */
 static bool sja1105_filter(const struct sk_buff *skb, struct net_device *dev)
 {
-	if (!dsa_port_is_vlan_filtering(dev->dsa_ptr))
+	if (sja1105_can_use_vlan_as_tags(dev->dsa_ptr->ds))
 		return true;
 	if (sja1105_is_link_local(skb))
 		return true;
Signature · 1 line
2.17.1
#6 lore raw

Re: [PATCH v2 net-next 03/15] net: dsa: sja1105: keep the VLAN awareness state in a driver variable

I love your patch! Yet something to improve:

Hi Vladimir,

I love your patch! Yet something to improve:

[auto build test ERROR on net-next/master]
[cannot apply to linus/master v5.7-rc5]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Vladimir-Oltean/Traffic-support-for-dsa_8021q-in-vlan_filtering-1-mode/20200512-024329
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git a6f0b26d6a5dcf27980e65f965779a929039f11d
config: xtensa-randconfig-r021-20200511 (attached as .config)
compiler: xtensa-linux-gcc (GCC) 9.3.0

reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day GCC_VERSION=9.3.0 make.cross ARCH=xtensa

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

xtensa-linux-ld: net/dsa/tag_sja1105.o: in function `sja1105_rcv':

>> net/dsa/tag_sja1105.c:305: undefined reference to `sja1105_can_use_vlan_as_tags'

xtensa-linux-ld: net/dsa/tag_sja1105.o: in function `sja1105_filter':
net/dsa/tag_sja1105.c:77: undefined reference to `sja1105_can_use_vlan_as_tags'

vim +305 net/dsa/tag_sja1105.c

f3097be21bf17a Vladimir Oltean 2019-06-08  246  
227d07a07ef126 Vladimir Oltean 2019-05-05  247  static struct sk_buff *sja1105_rcv(struct sk_buff *skb,
227d07a07ef126 Vladimir Oltean 2019-05-05  248  				   struct net_device *netdev,
227d07a07ef126 Vladimir Oltean 2019-05-05  249  				   struct packet_type *pt)
227d07a07ef126 Vladimir Oltean 2019-05-05  250  {
e53e18a6fe4d3a Vladimir Oltean 2019-06-08  251  	struct sja1105_meta meta = {0};
d461933638ae9f Vladimir Oltean 2019-06-08  252  	int source_port, switch_id;
e80f40cbe4dd51 Vladimir Oltean 2020-03-24  253  	struct ethhdr *hdr;
227d07a07ef126 Vladimir Oltean 2019-05-05  254  	u16 tpid, vid, tci;
42824463d38d27 Vladimir Oltean 2019-06-08  255  	bool is_link_local;
227d07a07ef126 Vladimir Oltean 2019-05-05  256  	bool is_tagged;
e53e18a6fe4d3a Vladimir Oltean 2019-06-08  257  	bool is_meta;
227d07a07ef126 Vladimir Oltean 2019-05-05  258  
e80f40cbe4dd51 Vladimir Oltean 2020-03-24  259  	hdr = eth_hdr(skb);
e80f40cbe4dd51 Vladimir Oltean 2020-03-24  260  	tpid = ntohs(hdr->h_proto);
d461933638ae9f Vladimir Oltean 2019-06-08  261  	is_tagged = (tpid == ETH_P_SJA1105);
42824463d38d27 Vladimir Oltean 2019-06-08  262  	is_link_local = sja1105_is_link_local(skb);
e53e18a6fe4d3a Vladimir Oltean 2019-06-08  263  	is_meta = sja1105_is_meta_frame(skb);
227d07a07ef126 Vladimir Oltean 2019-05-05  264  
227d07a07ef126 Vladimir Oltean 2019-05-05  265  	skb->offload_fwd_mark = 1;
227d07a07ef126 Vladimir Oltean 2019-05-05  266  
42824463d38d27 Vladimir Oltean 2019-06-08  267  	if (is_tagged) {
42824463d38d27 Vladimir Oltean 2019-06-08  268  		/* Normal traffic path. */
e80f40cbe4dd51 Vladimir Oltean 2020-03-24  269  		skb_push_rcsum(skb, ETH_HLEN);
e80f40cbe4dd51 Vladimir Oltean 2020-03-24  270  		__skb_vlan_pop(skb, &tci);
e80f40cbe4dd51 Vladimir Oltean 2020-03-24  271  		skb_pull_rcsum(skb, ETH_HLEN);
e80f40cbe4dd51 Vladimir Oltean 2020-03-24  272  		skb_reset_network_header(skb);
e80f40cbe4dd51 Vladimir Oltean 2020-03-24  273  		skb_reset_transport_header(skb);
e80f40cbe4dd51 Vladimir Oltean 2020-03-24  274  
42824463d38d27 Vladimir Oltean 2019-06-08  275  		vid = tci & VLAN_VID_MASK;
42824463d38d27 Vladimir Oltean 2019-06-08  276  		source_port = dsa_8021q_rx_source_port(vid);
42824463d38d27 Vladimir Oltean 2019-06-08  277  		switch_id = dsa_8021q_rx_switch_id(vid);
42824463d38d27 Vladimir Oltean 2019-06-08  278  		skb->priority = (tci & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
42824463d38d27 Vladimir Oltean 2019-06-08  279  	} else if (is_link_local) {
227d07a07ef126 Vladimir Oltean 2019-05-05  280  		/* Management traffic path. Switch embeds the switch ID and
227d07a07ef126 Vladimir Oltean 2019-05-05  281  		 * port ID into bytes of the destination MAC, courtesy of
227d07a07ef126 Vladimir Oltean 2019-05-05  282  		 * the incl_srcpt options.
227d07a07ef126 Vladimir Oltean 2019-05-05  283  		 */
227d07a07ef126 Vladimir Oltean 2019-05-05  284  		source_port = hdr->h_dest[3];
227d07a07ef126 Vladimir Oltean 2019-05-05  285  		switch_id = hdr->h_dest[4];
227d07a07ef126 Vladimir Oltean 2019-05-05  286  		/* Clear the DMAC bytes that were mangled by the switch */
227d07a07ef126 Vladimir Oltean 2019-05-05  287  		hdr->h_dest[3] = 0;
227d07a07ef126 Vladimir Oltean 2019-05-05  288  		hdr->h_dest[4] = 0;
e53e18a6fe4d3a Vladimir Oltean 2019-06-08  289  	} else if (is_meta) {
e53e18a6fe4d3a Vladimir Oltean 2019-06-08  290  		sja1105_meta_unpack(skb, &meta);
e53e18a6fe4d3a Vladimir Oltean 2019-06-08  291  		source_port = meta.source_port;
e53e18a6fe4d3a Vladimir Oltean 2019-06-08  292  		switch_id = meta.switch_id;
227d07a07ef126 Vladimir Oltean 2019-05-05  293  	} else {
42824463d38d27 Vladimir Oltean 2019-06-08  294  		return NULL;
227d07a07ef126 Vladimir Oltean 2019-05-05  295  	}
227d07a07ef126 Vladimir Oltean 2019-05-05  296  
227d07a07ef126 Vladimir Oltean 2019-05-05  297  	skb->dev = dsa_master_find_slave(netdev, switch_id, source_port);
227d07a07ef126 Vladimir Oltean 2019-05-05  298  	if (!skb->dev) {
227d07a07ef126 Vladimir Oltean 2019-05-05  299  		netdev_warn(netdev, "Couldn't decode source port\n");
227d07a07ef126 Vladimir Oltean 2019-05-05  300  		return NULL;
227d07a07ef126 Vladimir Oltean 2019-05-05  301  	}
227d07a07ef126 Vladimir Oltean 2019-05-05  302  
f3097be21bf17a Vladimir Oltean 2019-06-08  303  	return sja1105_rcv_meta_state_machine(skb, &meta, is_link_local,
f3097be21bf17a Vladimir Oltean 2019-06-08  304  					      is_meta);

227d07a07ef126 Vladimir Oltean 2019-05-05 @305 }
227d07a07ef126 Vladimir Oltean 2019-05-05 306

:::::: The code at line 305 was first introduced by commit
:::::: 227d07a07ef126272ea2eed97fd136cd7a803d81 net: dsa: sja1105: Add support for traffic through standalone ports

:::::: TO: Vladimir Oltean <[email protected]>
:::::: CC: David S. Miller <[email protected]>

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

author maintainer
#7 lore raw

Re: [PATCH v2 net-next 03/15] net: dsa: sja1105: keep the VLAN awareness state in a driver variable

Quoted 22 lines · kbuild test robot

Hi Vladimir,

I love your patch! Yet something to improve:

[auto build test ERROR on net-next/master]
[cannot apply to linus/master v5.7-rc5]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Vladimir-Oltean/Traffic-support-for-dsa_8021q-in-vlan_filtering-1-mode/20200512-024329
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git a6f0b26d6a5dcf27980e65f965779a929039f11d
config: xtensa-randconfig-r021-20200511 (attached as .config)
compiler: xtensa-linux-gcc (GCC) 9.3.0

reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day GCC_VERSION=9.3.0 make.cross ARCH=xtensa

If you fix the issue, kindly add following tag as appropriate

Quoted 9 lines

All errors (new ones prefixed by >>):

   xtensa-linux-ld: net/dsa/tag_sja1105.o: in function `sja1105_rcv':
Quoted 1 line
Quoted 1 line

net/dsa/tag_sja1105.c:305: undefined reference to `sja1105_can_use_vlan_as_tags'

xtensa-linux-ld: net/dsa/tag_sja1105.o: in function `sja1105_filter':

   net/dsa/tag_sja1105.c:77: undefined reference to `sja1105_can_use_vlan_as_tags'

Argh, this is by compiling the tagger module without the driver, it looks like I can't get away with doing this.
The issue is that I don't want to expose struct sja1105_private publicly, but I do have a struct sja1105_port hanging off of dp->priv. But I don't have access to a dp pointer in the .filter method... So the only realistic idea I have is to provide a shim implementation for the call.

Quoted 73 lines

vim +305 net/dsa/tag_sja1105.c

f3097be21bf17a Vladimir Oltean 2019-06-08  246
227d07a07ef126 Vladimir Oltean 2019-05-05  247  static struct sk_buff *sja1105_rcv(struct sk_buff *skb,
227d07a07ef126 Vladimir Oltean 2019-05-05  248                                     struct net_device *netdev,
227d07a07ef126 Vladimir Oltean 2019-05-05  249                                     struct packet_type *pt)
227d07a07ef126 Vladimir Oltean 2019-05-05  250  {
e53e18a6fe4d3a Vladimir Oltean 2019-06-08  251          struct sja1105_meta meta = {0};
d461933638ae9f Vladimir Oltean 2019-06-08  252          int source_port, switch_id;
e80f40cbe4dd51 Vladimir Oltean 2020-03-24  253          struct ethhdr *hdr;
227d07a07ef126 Vladimir Oltean 2019-05-05  254          u16 tpid, vid, tci;
42824463d38d27 Vladimir Oltean 2019-06-08  255          bool is_link_local;
227d07a07ef126 Vladimir Oltean 2019-05-05  256          bool is_tagged;
e53e18a6fe4d3a Vladimir Oltean 2019-06-08  257          bool is_meta;
227d07a07ef126 Vladimir Oltean 2019-05-05  258
e80f40cbe4dd51 Vladimir Oltean 2020-03-24  259          hdr = eth_hdr(skb);
e80f40cbe4dd51 Vladimir Oltean 2020-03-24  260          tpid = ntohs(hdr->h_proto);
d461933638ae9f Vladimir Oltean 2019-06-08  261          is_tagged = (tpid == ETH_P_SJA1105);
42824463d38d27 Vladimir Oltean 2019-06-08  262          is_link_local = sja1105_is_link_local(skb);
e53e18a6fe4d3a Vladimir Oltean 2019-06-08  263          is_meta = sja1105_is_meta_frame(skb);
227d07a07ef126 Vladimir Oltean 2019-05-05  264
227d07a07ef126 Vladimir Oltean 2019-05-05  265          skb->offload_fwd_mark = 1;
227d07a07ef126 Vladimir Oltean 2019-05-05  266
42824463d38d27 Vladimir Oltean 2019-06-08  267          if (is_tagged) {
42824463d38d27 Vladimir Oltean 2019-06-08  268                  /* Normal traffic path. */
e80f40cbe4dd51 Vladimir Oltean 2020-03-24  269                  skb_push_rcsum(skb, ETH_HLEN);
e80f40cbe4dd51 Vladimir Oltean 2020-03-24  270                  __skb_vlan_pop(skb, &tci);
e80f40cbe4dd51 Vladimir Oltean 2020-03-24  271                  skb_pull_rcsum(skb, ETH_HLEN);
e80f40cbe4dd51 Vladimir Oltean 2020-03-24  272                  skb_reset_network_header(skb);
e80f40cbe4dd51 Vladimir Oltean 2020-03-24  273                  skb_reset_transport_header(skb);
e80f40cbe4dd51 Vladimir Oltean 2020-03-24  274
42824463d38d27 Vladimir Oltean 2019-06-08  275                  vid = tci & VLAN_VID_MASK;
42824463d38d27 Vladimir Oltean 2019-06-08  276                  source_port = dsa_8021q_rx_source_port(vid);
42824463d38d27 Vladimir Oltean 2019-06-08  277                  switch_id = dsa_8021q_rx_switch_id(vid);
42824463d38d27 Vladimir Oltean 2019-06-08  278                  skb->priority = (tci & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
42824463d38d27 Vladimir Oltean 2019-06-08  279          } else if (is_link_local) {
227d07a07ef126 Vladimir Oltean 2019-05-05  280                  /* Management traffic path. Switch embeds the switch ID and
227d07a07ef126 Vladimir Oltean 2019-05-05  281                   * port ID into bytes of the destination MAC, courtesy of
227d07a07ef126 Vladimir Oltean 2019-05-05  282                   * the incl_srcpt options.
227d07a07ef126 Vladimir Oltean 2019-05-05  283                   */
227d07a07ef126 Vladimir Oltean 2019-05-05  284                  source_port = hdr->h_dest[3];
227d07a07ef126 Vladimir Oltean 2019-05-05  285                  switch_id = hdr->h_dest[4];
227d07a07ef126 Vladimir Oltean 2019-05-05  286                  /* Clear the DMAC bytes that were mangled by the switch */
227d07a07ef126 Vladimir Oltean 2019-05-05  287                  hdr->h_dest[3] = 0;
227d07a07ef126 Vladimir Oltean 2019-05-05  288                  hdr->h_dest[4] = 0;
e53e18a6fe4d3a Vladimir Oltean 2019-06-08  289          } else if (is_meta) {
e53e18a6fe4d3a Vladimir Oltean 2019-06-08  290                  sja1105_meta_unpack(skb, &meta);
e53e18a6fe4d3a Vladimir Oltean 2019-06-08  291                  source_port = meta.source_port;
e53e18a6fe4d3a Vladimir Oltean 2019-06-08  292                  switch_id = meta.switch_id;
227d07a07ef126 Vladimir Oltean 2019-05-05  293          } else {
42824463d38d27 Vladimir Oltean 2019-06-08  294                  return NULL;
227d07a07ef126 Vladimir Oltean 2019-05-05  295          }
227d07a07ef126 Vladimir Oltean 2019-05-05  296
227d07a07ef126 Vladimir Oltean 2019-05-05  297          skb->dev = dsa_master_find_slave(netdev, switch_id, source_port);
227d07a07ef126 Vladimir Oltean 2019-05-05  298          if (!skb->dev) {
227d07a07ef126 Vladimir Oltean 2019-05-05  299                  netdev_warn(netdev, "Couldn't decode source port\n");
227d07a07ef126 Vladimir Oltean 2019-05-05  300                  return NULL;
227d07a07ef126 Vladimir Oltean 2019-05-05  301          }
227d07a07ef126 Vladimir Oltean 2019-05-05  302
f3097be21bf17a Vladimir Oltean 2019-06-08  303          return sja1105_rcv_meta_state_machine(skb, &meta, is_link_local,
f3097be21bf17a Vladimir Oltean 2019-06-08  304                                                is_meta);

227d07a07ef126 Vladimir Oltean 2019-05-05 @305 }
227d07a07ef126 Vladimir Oltean 2019-05-05 306

:::::: The code at line 305 was first introduced by commit
:::::: 227d07a07ef126272ea2eed97fd136cd7a803d81 net: dsa: sja1105: Add support for traffic through standalone ports

:::::: TO: Vladimir Oltean <[email protected]>
:::::: CC: David S. Miller <[email protected]>

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]

Reviewed-by on v2 3/15
#8 lore raw

Re: [PATCH v2 net-next 03/15] net: dsa: sja1105: keep the VLAN awareness state in a driver variable

In reply to Vladimir Oltean
Quoted 7 lines · Vladimir Oltean

From: Vladimir Oltean <[email protected]>

Soon we'll add a third operating mode to the driver. Introduce a vlan_state to make things more easy to manage, and use it where applicable.

Signature · 1 line
Florian
author maintainer
#9 lore raw

PATCH v2 4/15 net: dsa: sja1105: deny alterations of dsa_8021q VLANs from the bridge

In reply to Vladimir Oltean

From: Vladimir Oltean <[email protected]>

At the moment, this can never happen. The 2 modes that we operate in do not permit that:

- SJA1105_VLAN_UNAWARE: we are guarded from bridge VLANs added by the user by the DSA core. We will later lift this restriction by setting ds->vlan_bridge_vtu = true, and that is where we'll need it.

- SJA1105_VLAN_FILTERING_FULL: in this mode, dsa_8021q configuration is disabled. So the user is free to add these VLANs in the 1024-3071 range.

The reason for the patch is that we'll introduce a third VLAN awareness state, where both dsa_8021q as well as the bridge are going to call our .port_vlan_add and .port_vlan_del methods.

For that, we need a good way to discriminate between the 2. The easiest (and less intrusive way for upper layers) is to recognize the fact that dsa_8021q configurations are always driven by our driver - we _know_ when a .port_vlan_add method will be called from dsa_8021q because _we_ initiated it.

So introduce an expect_dsa_8021q boolean which is only used, at the moment, for blacklisting VLANs in range 1024-3071 in the modes when dsa_8021q is active.

---
Changes in v2:
None.

 drivers/net/dsa/sja1105/sja1105.h      |  1 +
 drivers/net/dsa/sja1105/sja1105_main.c | 31 +++++++++++++++++++++++++-
 2 files changed, 31 insertions(+), 1 deletion(-)
drivers/net/dsa/sja1105/sja1105.h +1 -0
index 5b2b275d01a7..667056d0c819 100644
@@ -198,6 +198,7 @@ struct sja1105_private {
 	 * the switch doesn't confuse them with one another.
 	 */
 	struct mutex mgmt_lock;
+	bool expect_dsa_8021q;
 	enum sja1105_vlan_state vlan_state;
 	struct sja1105_tagger_data tagger_data;
 	struct sja1105_ptp_data ptp_data;
drivers/net/dsa/sja1105/sja1105_main.c +30 -1
index 72e12c02594d..23c5d7488761 100644
@@ -1811,15 +1811,19 @@ static int sja1105_crosschip_bridge_join(struct dsa_switch *ds,
 		if (dsa_to_port(ds, port)->bridge_dev != br)
 			continue;
 
+		other_priv->expect_dsa_8021q = true;
 		rc = dsa_8021q_crosschip_bridge_join(ds, port, other_ds,
 						     other_port, br,
 						     &priv->crosschip_links);
+		other_priv->expect_dsa_8021q = false;
 		if (rc)
 			return rc;
 
+		priv->expect_dsa_8021q = true;
 		rc = dsa_8021q_crosschip_bridge_join(other_ds, other_port, ds,
 						     port, br,
 						     &other_priv->crosschip_links);
+		priv->expect_dsa_8021q = false;
 		if (rc)
 			return rc;
 	}
@@ -1846,12 +1850,16 @@ static void sja1105_crosschip_bridge_leave(struct dsa_switch *ds,
 		if (dsa_to_port(ds, port)->bridge_dev != br)
 			continue;
 
+		other_priv->expect_dsa_8021q = true;
 		dsa_8021q_crosschip_bridge_leave(ds, port, other_ds, other_port,
 						 br, &priv->crosschip_links);
+		other_priv->expect_dsa_8021q = false;
 
+		priv->expect_dsa_8021q = true;
 		dsa_8021q_crosschip_bridge_leave(other_ds, other_port, ds,
 						 port, br,
 						 &other_priv->crosschip_links);
+		priv->expect_dsa_8021q = false;
 	}
 }
 
@@ -1862,8 +1870,10 @@ static int sja1105_replay_crosschip_vlans(struct dsa_switch *ds, bool enabled)
 	int rc;
 
 	list_for_each_entry(c, &priv->crosschip_links, list) {
+		priv->expect_dsa_8021q = true;
 		rc = dsa_8021q_crosschip_link_apply(ds, c->port, c->other_ds,
 						    c->other_port, enabled);
+		priv->expect_dsa_8021q = false;
 		if (rc)
 			break;
 	}
@@ -1873,10 +1883,13 @@ static int sja1105_replay_crosschip_vlans(struct dsa_switch *ds, bool enabled)
 
 static int sja1105_setup_8021q_tagging(struct dsa_switch *ds, bool enabled)
 {
+	struct sja1105_private *priv = ds->priv;
 	int rc, i;
 
 	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);
@@ -1901,10 +1914,26 @@ sja1105_get_tag_protocol(struct dsa_switch *ds, int port,
 	return DSA_TAG_PROTO_SJA1105;
 }
 
-/* This callback needs to be present */
 static int sja1105_vlan_prepare(struct dsa_switch *ds, int port,
 				const struct switchdev_obj_port_vlan *vlan)
 {
+	struct sja1105_private *priv = ds->priv;
+	u16 vid;
+
+	if (priv->vlan_state == SJA1105_VLAN_FILTERING_FULL)
+		return 0;
+
+	/* If the user wants best-effort VLAN filtering (aka vlan_filtering
+	 * bridge plus tagging), be sure to at least deny alterations to the
+	 * configuration done by dsa_8021q.
+	 */
+	for (vid = vlan->vid_begin; vid <= vlan->vid_end; vid++) {
+		if (!priv->expect_dsa_8021q && vid_is_dsa_8021q(vid)) {
+			dev_err(ds->dev, "Range 1024-3071 reserved for dsa_8021q operation\n");
+			return -EBUSY;
+		}
+	}
+
 	return 0;
 }
 
Signature · 1 line
2.17.1
Reviewed-by on v2 4/15
#10 lore raw

Re: [PATCH v2 net-next 04/15] net: dsa: sja1105: deny alterations of dsa_8021q VLANs from the bridge

Quoted 23 lines · Vladimir Oltean

From: Vladimir Oltean <[email protected]>

At the moment, this can never happen. The 2 modes that we operate in do not permit that:

- SJA1105_VLAN_UNAWARE: we are guarded from bridge VLANs added by the user by the DSA core. We will later lift this restriction by setting ds->vlan_bridge_vtu = true, and that is where we'll need it.

- SJA1105_VLAN_FILTERING_FULL: in this mode, dsa_8021q configuration is disabled. So the user is free to add these VLANs in the 1024-3071 range.

The reason for the patch is that we'll introduce a third VLAN awareness state, where both dsa_8021q as well as the bridge are going to call our .port_vlan_add and .port_vlan_del methods.

For that, we need a good way to discriminate between the 2. The easiest (and less intrusive way for upper layers) is to recognize the fact that dsa_8021q configurations are always driven by our driver - we _know_ when a .port_vlan_add method will be called from dsa_8021q because _we_ initiated it.

Quoted 4 lines

So introduce an expect_dsa_8021q boolean which is only used, at the moment, for blacklisting VLANs in range 1024-3071 in the modes when dsa_8021q is active.>

Signature · 1 line
Florian
author maintainer
#11 lore raw

PATCH v2 5/15 net: dsa: sja1105: save/restore VLANs using a delta commit method

In reply to Vladimir Oltean

From: Vladimir Oltean <[email protected]>

Managing the VLAN table that is present in hardware will become very difficult once we add a third operating state (best_effort_vlan_filtering). That is because correct cleanup (not too little, not too much) becomes virtually impossible, when VLANs can be added from the bridge layer, from dsa_8021q for basic tagging, for cross-chip bridging, as well as retagging rules for sub-VLANs and cross-chip sub-VLANs. So we need to rethink VLAN interaction with the switch in a more scalable way.

In preparation for that, use the priv->expect_dsa_8021q boolean to classify any VLAN request received through .port_vlan_add or .port_vlan_del towards either one of 2 internal lists: bridge VLANs and dsa_8021q VLANs.

Then, implement a central sja1105_build_vlan_table method that creates a VLAN configuration from scratch based on the 2 lists of VLANs kept by the driver, and based on the VLAN awareness state. Currently, if we are VLAN-unaware, install the dsa_8021q VLANs, otherwise the bridge VLANs.

Then, implement a delta commit procedure that identifies which VLANs from this new configuration are actually different from the config previously committed to hardware. We apply the delta through the dynamic configuration interface (we don't reset the switch). The result is that the hardware should see the exact sequence of operations as before this patch.

This also helps remove the "br" argument passed to dsa_8021q_crosschip_bridge_join, which it was only using to figure out whether it should commit the configuration back to us or not, based on the VLAN awareness state of the bridge. We can simplify that, by always allowing those VLANs inside of our dsa_8021q_vlans list, and committing those to hardware when necessary.

---
Changes in v2:
- Free the vlan lists on teardown.
- Simplify sja1105_classify_vlan: only look at priv->expect_dsa_8021q.
- Keep vid 1 in the list of dsa_8021q VLANs, to make sure that untagged packets transmitted from the stack, like PTP, continue to work in VLAN-unaware mode.

 drivers/net/dsa/sja1105/sja1105.h      |  10 +
 drivers/net/dsa/sja1105/sja1105_main.c | 493 ++++++++++++++++++-------
 include/linux/dsa/8021q.h              |  19 +-
 net/dsa/tag_8021q.c                    |  45 +--
 4 files changed, 393 insertions(+), 174 deletions(-)
drivers/net/dsa/sja1105/sja1105.h +10 -0
index 667056d0c819..c80f1999c694 100644
@@ -178,6 +178,14 @@ struct sja1105_flow_block {
 	int num_virtual_links;
 };
 
+struct sja1105_bridge_vlan {
+	struct list_head list;
+	int port;
+	u16 vid;
+	bool pvid;
+	bool untagged;
+};
+
 enum sja1105_vlan_state {
 	SJA1105_VLAN_UNAWARE,
 	SJA1105_VLAN_FILTERING_FULL,
@@ -191,6 +199,8 @@ struct sja1105_private {
 	struct gpio_desc *reset_gpio;
 	struct spi_device *spidev;
 	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];
drivers/net/dsa/sja1105/sja1105_main.c +362 -131

592 lines not on this page · raw message

include/linux/dsa/8021q.h +4 -15
index ebc245ff838a..404bd2cce642 100644
@@ -25,18 +25,14 @@ struct dsa_8021q_crosschip_link {
 int dsa_port_setup_8021q_tagging(struct dsa_switch *ds, int index,
 				 bool enabled);
 
-int dsa_8021q_crosschip_link_apply(struct dsa_switch *ds, int port,
-				   struct dsa_switch *other_ds,
-				   int other_port, bool enabled);
-
 int dsa_8021q_crosschip_bridge_join(struct dsa_switch *ds, int port,
 				    struct dsa_switch *other_ds,
-				    int other_port, struct net_device *br,
+				    int other_port,
 				    struct list_head *crosschip_links);
 
 int dsa_8021q_crosschip_bridge_leave(struct dsa_switch *ds, int port,
 				     struct dsa_switch *other_ds,
-				     int other_port, struct net_device *br,
+				     int other_port,
 				     struct list_head *crosschip_links);
 
 struct sk_buff *dsa_8021q_xmit(struct sk_buff *skb, struct net_device *netdev,
@@ -60,16 +56,9 @@ int dsa_port_setup_8021q_tagging(struct dsa_switch *ds, int index,
 	return 0;
 }
 
-int dsa_8021q_crosschip_link_apply(struct dsa_switch *ds, int port,
-				   struct dsa_switch *other_ds,
-				   int other_port, bool enabled)
-{
-	return 0;
-}
-
 int dsa_8021q_crosschip_bridge_join(struct dsa_switch *ds, int port,
 				    struct dsa_switch *other_ds,
-				    int other_port, struct net_device *br,
+				    int other_port,
 				    struct list_head *crosschip_links)
 {
 	return 0;
@@ -77,7 +66,7 @@ int dsa_8021q_crosschip_bridge_join(struct dsa_switch *ds, int port,
 
 int dsa_8021q_crosschip_bridge_leave(struct dsa_switch *ds, int port,
 				     struct dsa_switch *other_ds,
-				     int other_port, struct net_device *br,
+				     int other_port,
 				     struct list_head *crosschip_links)
 {
 	return 0;
net/dsa/tag_8021q.c +17 -28

86 lines not on this page · raw message

Signature · 1 line
2.17.1
Reviewed-by on v2 5/15
#12 lore raw

Re: [PATCH v2 net-next 05/15] net: dsa: sja1105: save/restore VLANs using a delta commit method

Quoted 28 lines · Vladimir Oltean

From: Vladimir Oltean <[email protected]>

Managing the VLAN table that is present in hardware will become very difficult once we add a third operating state (best_effort_vlan_filtering). That is because correct cleanup (not too little, not too much) becomes virtually impossible, when VLANs can be added from the bridge layer, from dsa_8021q for basic tagging, for cross-chip bridging, as well as retagging rules for sub-VLANs and cross-chip sub-VLANs. So we need to rethink VLAN interaction with the switch in a more scalable way.

In preparation for that, use the priv->expect_dsa_8021q boolean to classify any VLAN request received through .port_vlan_add or .port_vlan_del towards either one of 2 internal lists: bridge VLANs and dsa_8021q VLANs.

Then, implement a central sja1105_build_vlan_table method that creates a VLAN configuration from scratch based on the 2 lists of VLANs kept by the driver, and based on the VLAN awareness state. Currently, if we are VLAN-unaware, install the dsa_8021q VLANs, otherwise the bridge VLANs.

Then, implement a delta commit procedure that identifies which VLANs from this new configuration are actually different from the config previously committed to hardware. We apply the delta through the dynamic configuration interface (we don't reset the switch). The result is that the hardware should see the exact sequence of operations as before this patch.

Quoted 8 lines

This also helps remove the "br" argument passed to dsa_8021q_crosschip_bridge_join, which it was only using to figure out whether it should commit the configuration back to us or not, based on the VLAN awareness state of the bridge. We can simplify that, by always allowing those VLANs inside of our dsa_8021q_vlans list, and committing those to hardware when necessary.

Signature · 1 line
Florian
author maintainer
#13 lore raw

PATCH v2 6/15 net: dsa: sja1105: allow VLAN configuration from the bridge in all states

In reply to Vladimir Oltean

From: Vladimir Oltean <[email protected]>

Let the DSA core call our .port_vlan_add methods every time the bridge layer requests so. We will deal internally with saving/restoring VLANs depending on our VLAN awareness state.

---
Changes in v2:
Adapt to variable name change.

 drivers/net/dsa/sja1105/sja1105_main.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/dsa/sja1105/sja1105_main.c +2 -0
index c0f11a185f31..d2755ab2853d 100644
@@ -2358,6 +2358,8 @@ static int sja1105_setup(struct dsa_switch *ds)
 
 	ds->mtu_enforcement_ingress = true;
 
+	ds->configure_vlans_while_disabled = true;
+
 	/* The DSA/switchdev model brings up switch ports in standalone mode by
 	 * default, and that means vlan_filtering is 0 since they're not under
 	 * a bridge, so it's safe to set up switch tagging at this time.
Signature · 1 line
2.17.1
Reviewed-by on v2 6/15
#14 lore raw

Re: [PATCH v2 net-next 06/15] net: dsa: sja1105: allow VLAN configuration from the bridge in all states

Quoted 7 lines · Vladimir Oltean

From: Vladimir Oltean <[email protected]>

Let the DSA core call our .port_vlan_add methods every time the bridge layer requests so. We will deal internally with saving/restoring VLANs depending on our VLAN awareness state.

Signature · 1 line
Florian
author maintainer
#15 lore raw

PATCH v2 7/15 net: dsa: sja1105: exit sja1105_vlan_filtering when called multiple times

In reply to Vladimir Oltean

From: Vladimir Oltean <[email protected]>

VLAN filtering is a global property for sja1105, and that means that we rely on the DSA core to not call us more than once.

But we need to introduce some per-port state for the tagger, namely the xmit_tpid, and the best place to do that is where the xmit_tpid changes, namely in sja1105_vlan_filtering. So at the moment, exit early from the function to avoid unnecessarily resetting the switch for each port call. Then we'll change the xmit_tpid prior to the early exit in the next patch.

---
Changes in v2:
None.

 drivers/net/dsa/sja1105/sja1105_main.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/dsa/sja1105/sja1105_main.c +3 -0
index d2755ab2853d..82b424a03658 100644
@@ -2158,6 +2158,9 @@ static int sja1105_vlan_filtering(struct dsa_switch *ds, int port, bool enabled)
 	else
 		state = SJA1105_VLAN_FILTERING_FULL;
 
+	if (priv->vlan_state == state)
+		return 0;
+
 	priv->vlan_state = state;
 
 	table = &priv->static_config.tables[BLK_IDX_GENERAL_PARAMS];
Signature · 1 line
2.17.1
Reviewed-by on v2 7/15
#16 lore raw

Re: [PATCH v2 net-next 07/15] net: dsa: sja1105: exit sja1105_vlan_filtering when called multiple times

Quoted 5 lines · Vladimir Oltean

From: Vladimir Oltean <[email protected]>

VLAN filtering is a global property for sja1105, and that means that we rely on the DSA core to not call us more than once.

Quoted 8 lines

But we need to introduce some per-port state for the tagger, namely the xmit_tpid, and the best place to do that is where the xmit_tpid changes, namely in sja1105_vlan_filtering. So at the moment, exit early from the function to avoid unnecessarily resetting the switch for each port call. Then we'll change the xmit_tpid prior to the early exit in the next patch.

Signature · 1 line
Florian
author maintainer
#17 lore raw

PATCH v2 8/15 net: dsa: sja1105: prepare tagger for handling DSA tags and VLAN simultaneously

In reply to Vladimir Oltean

From: Vladimir Oltean <[email protected]>

In VLAN-unaware mode, sja1105 uses VLAN tags with a custom TPID of 0xdadb. While in the yet-to-be introduced best_effort_vlan_filtering mode, it needs to work with normal VLAN TPID values.

A complication arises when we must transmit a VLAN-tagged packet to the switch when it's in VLAN-aware mode. We need to construct a packet with 2 VLAN tags, and the switch will use the outer header for routing and pop it on egress. But sadly, here the 2 hardware generations don't behave the same:

- E/T switches won't pop an ETH_P_8021AD tag on egress, it seems (packets will remain double-tagged).
- P/Q/R/S switches will drop a packet with 2 ETH_P_8021Q tags (it looks like it tries to prevent VLAN hopping).

But looks like the reverse is also true:

- E/T switches have no problem popping the outer tag from packets with 2 ETH_P_8021Q tags.
- P/Q/R/S will have no problem popping a single tag even if that is ETH_P_8021AD.

So it is clear that if we want the hardware to work with dsa_8021q tagging in VLAN-aware mode, we need to send different TPIDs depending on revision. Keep that information in priv->info->qinq_tpid.

The per-port tagger structure will hold an xmit_tpid value that depends not only upon the qinq_tpid, but also upon the VLAN awareness state itself (in case we must transmit using 0xdadb).

---
Changes in v2:
None.

 drivers/net/dsa/sja1105/sja1105.h      |  6 ++++++
 drivers/net/dsa/sja1105/sja1105_main.c | 10 ++++++++++
 drivers/net/dsa/sja1105/sja1105_spi.c  |  6 ++++++
 include/linux/dsa/sja1105.h            |  2 ++
 net/dsa/tag_sja1105.c                  | 17 +++++++----------
 5 files changed, 31 insertions(+), 10 deletions(-)
drivers/net/dsa/sja1105/sja1105.h +6 -0
index c80f1999c694..a019ffae38f1 100644
@@ -87,6 +87,12 @@ struct sja1105_info {
 	const struct sja1105_dynamic_table_ops *dyn_ops;
 	const struct sja1105_table_ops *static_ops;
 	const struct sja1105_regs *regs;
+	/* Both E/T and P/Q/R/S have quirks when it comes to popping the S-Tag
+	 * from double-tagged frames. E/T will pop it only when it's equal to
+	 * TPID from the General Parameters Table, while P/Q/R/S will only
+	 * pop it when it's equal to TPID2.
+	 */
+	u16 qinq_tpid;
 	int (*reset_cmd)(struct dsa_switch *ds);
 	int (*setup_rgmii_delay)(const void *ctx, int port);
 	/* Prototypes from include/net/dsa.h */
drivers/net/dsa/sja1105/sja1105_main.c +10 -0
index 82b424a03658..042ecbbc5572 100644
@@ -2153,6 +2153,15 @@ static int sja1105_vlan_filtering(struct dsa_switch *ds, int port, bool enabled)
 		tpid2 = ETH_P_SJA1105;
 	}
 
+	for (port = 0; port < ds->num_ports; port++) {
+		struct sja1105_port *sp = &priv->ports[port];
+
+		if (enabled)
+			sp->xmit_tpid = priv->info->qinq_tpid;
+		else
+			sp->xmit_tpid = ETH_P_SJA1105;
+	}
+
 	if (!enabled)
 		state = SJA1105_VLAN_UNAWARE;
 	else
@@ -2874,6 +2883,7 @@ static int sja1105_probe(struct spi_device *spi)
 			goto out;
 		}
 		skb_queue_head_init(&sp->xmit_queue);
+		sp->xmit_tpid = ETH_P_SJA1105;
 	}
 
 	return 0;
drivers/net/dsa/sja1105/sja1105_spi.c +6 -0
index 0be75c49e6c3..a0dacae803cc 100644
@@ -512,6 +512,7 @@ struct sja1105_info sja1105e_info = {
 	.part_no		= SJA1105ET_PART_NO,
 	.static_ops		= sja1105e_table_ops,
 	.dyn_ops		= sja1105et_dyn_ops,
+	.qinq_tpid		= ETH_P_8021Q,
 	.ptp_ts_bits		= 24,
 	.ptpegr_ts_bytes	= 4,
 	.reset_cmd		= sja1105et_reset_cmd,
@@ -526,6 +527,7 @@ struct sja1105_info sja1105t_info = {
 	.part_no		= SJA1105ET_PART_NO,
 	.static_ops		= sja1105t_table_ops,
 	.dyn_ops		= sja1105et_dyn_ops,
+	.qinq_tpid		= ETH_P_8021Q,
 	.ptp_ts_bits		= 24,
 	.ptpegr_ts_bytes	= 4,
 	.reset_cmd		= sja1105et_reset_cmd,
@@ -540,6 +542,7 @@ struct sja1105_info sja1105p_info = {
 	.part_no		= SJA1105P_PART_NO,
 	.static_ops		= sja1105p_table_ops,
 	.dyn_ops		= sja1105pqrs_dyn_ops,
+	.qinq_tpid		= ETH_P_8021AD,
 	.ptp_ts_bits		= 32,
 	.ptpegr_ts_bytes	= 8,
 	.setup_rgmii_delay	= sja1105pqrs_setup_rgmii_delay,
@@ -555,6 +558,7 @@ struct sja1105_info sja1105q_info = {
 	.part_no		= SJA1105Q_PART_NO,
 	.static_ops		= sja1105q_table_ops,
 	.dyn_ops		= sja1105pqrs_dyn_ops,
+	.qinq_tpid		= ETH_P_8021AD,
 	.ptp_ts_bits		= 32,
 	.ptpegr_ts_bytes	= 8,
 	.setup_rgmii_delay	= sja1105pqrs_setup_rgmii_delay,
@@ -570,6 +574,7 @@ struct sja1105_info sja1105r_info = {
 	.part_no		= SJA1105R_PART_NO,
 	.static_ops		= sja1105r_table_ops,
 	.dyn_ops		= sja1105pqrs_dyn_ops,
+	.qinq_tpid		= ETH_P_8021AD,
 	.ptp_ts_bits		= 32,
 	.ptpegr_ts_bytes	= 8,
 	.setup_rgmii_delay	= sja1105pqrs_setup_rgmii_delay,
@@ -586,6 +591,7 @@ struct sja1105_info sja1105s_info = {
 	.static_ops		= sja1105s_table_ops,
 	.dyn_ops		= sja1105pqrs_dyn_ops,
 	.regs			= &sja1105pqrs_regs,
+	.qinq_tpid		= ETH_P_8021AD,
 	.ptp_ts_bits		= 32,
 	.ptpegr_ts_bytes	= 8,
 	.setup_rgmii_delay	= sja1105pqrs_setup_rgmii_delay,
include/linux/dsa/sja1105.h +2 -0
index 136481ce3c6f..e47acf0965c5 100644
@@ -9,6 +9,7 @@
 
 #include <linux/skbuff.h>
 #include <linux/etherdevice.h>
+#include <linux/dsa/8021q.h>
 #include <net/dsa.h>
 
 #define ETH_P_SJA1105				ETH_P_DSA_8021Q
@@ -59,6 +60,7 @@ struct sja1105_port {
 	struct sja1105_tagger_data *data;
 	struct dsa_port *dp;
 	bool hwts_tx_en;
+	u16 xmit_tpid;
 };
 
 bool sja1105_can_use_vlan_as_tags(struct dsa_switch *ds);
net/dsa/tag_sja1105.c +7 -10
index 5368cd34bcf4..0a95fdd7bff8 100644
@@ -96,6 +96,11 @@ static struct sk_buff *sja1105_defer_xmit(struct sja1105_port *sp,
 	return NULL;
 }
 
+static u16 sja1105_xmit_tpid(struct sja1105_port *sp)
+{
+	return sp->xmit_tpid;
+}
+
 static struct sk_buff *sja1105_xmit(struct sk_buff *skb,
 				    struct net_device *netdev)
 {
@@ -111,15 +116,7 @@ static struct sk_buff *sja1105_xmit(struct sk_buff *skb,
 	if (unlikely(sja1105_is_link_local(skb)))
 		return sja1105_defer_xmit(dp->priv, skb);
 
-	/* If we are under a vlan_filtering bridge, IP termination on
-	 * switch ports based on 802.1Q tags is simply too brittle to
-	 * be passable. So just defer to the dsa_slave_notag_xmit
-	 * implementation.
-	 */
-	if (dsa_port_is_vlan_filtering(dp))
-		return skb;
-
-	return dsa_8021q_xmit(skb, netdev, ETH_P_SJA1105,
+	return dsa_8021q_xmit(skb, netdev, sja1105_xmit_tpid(dp->priv),
 			     ((pcp << VLAN_PRIO_SHIFT) | tx_vid));
 }
 
@@ -258,7 +255,7 @@ static struct sk_buff *sja1105_rcv(struct sk_buff *skb,
 
 	hdr = eth_hdr(skb);
 	tpid = ntohs(hdr->h_proto);
-	is_tagged = (tpid == ETH_P_SJA1105);
+	is_tagged = (tpid == ETH_P_SJA1105 || tpid == ETH_P_8021Q);
 	is_link_local = sja1105_is_link_local(skb);
 	is_meta = sja1105_is_meta_frame(skb);
 
Signature · 1 line
2.17.1
Reviewed-by on v2 8/15
#18 lore raw

Re: [PATCH v2 net-next 08/15] net: dsa: sja1105: prepare tagger for handling DSA tags and VLAN simultaneously

Quoted 28 lines · Vladimir Oltean

From: Vladimir Oltean <[email protected]>

In VLAN-unaware mode, sja1105 uses VLAN tags with a custom TPID of 0xdadb. While in the yet-to-be introduced best_effort_vlan_filtering mode, it needs to work with normal VLAN TPID values.

A complication arises when we must transmit a VLAN-tagged packet to the switch when it's in VLAN-aware mode. We need to construct a packet with 2 VLAN tags, and the switch will use the outer header for routing and pop it on egress. But sadly, here the 2 hardware generations don't behave the same:

- E/T switches won't pop an ETH_P_8021AD tag on egress, it seems (packets will remain double-tagged).
- P/Q/R/S switches will drop a packet with 2 ETH_P_8021Q tags (it looks like it tries to prevent VLAN hopping).

But looks like the reverse is also true:

- E/T switches have no problem popping the outer tag from packets with 2 ETH_P_8021Q tags.
- P/Q/R/S will have no problem popping a single tag even if that is ETH_P_8021AD.

So it is clear that if we want the hardware to work with dsa_8021q tagging in VLAN-aware mode, we need to send different TPIDs depending on revision. Keep that information in priv->info->qinq_tpid.

Quoted 5 lines

The per-port tagger structure will hold an xmit_tpid value that depends not only upon the qinq_tpid, but also upon the VLAN awareness state itself (in case we must transmit using 0xdadb).

Signature · 1 line
Florian
author maintainer
#19 lore raw

PATCH v2 9/15 net: dsa: tag_8021q: support up to 8 VLANs per port using sub-VLANs

In reply to Vladimir Oltean

From: Vladimir Oltean <[email protected]>

For switches that support VLAN retagging, such as sja1105, we extend dsa_8021q by encoding a "sub-VLAN" into the remaining 3 free bits in the dsa_8021q tag.

A sub-VLAN is nothing more than a number in the range 0-7, which serves as an index into a per-port driver lookup table. The sub-VLAN value of zero means that traffic is untagged (this is also backwards-compatible with dsa_8021q without retagging).

The switch should be configured to retag VLAN-tagged traffic that gets transmitted towards the CPU port (and towards the CPU only). Example:

bridge vlan add dev sw1p0 vid 100

The switch retags frames received on port 0, going to the CPU, and having VID 100, to the VID of 1104 (0x0450). In dsa_8021q language:

 | 11  | 10  |  9  |  8  |  7  |  6  |  5  |  4  |  3  |  2  |  1  |  0  |
 +-----------+-----+-----------------+-----------+-----------------------+
 |    DIR    | SVL |    SWITCH_ID    |  SUBVLAN  |          PORT         |
 +-----------+-----+-----------------+-----------+-----------------------+

0x0450 means:
- DIR = 0b01: this is an RX VLAN
- SUBVLAN = 0b001: this is subvlan #1
- SWITCH_ID = 0b001: this is switch 1 (see the name "sw1p0")
- PORT = 0b0000: this is port 0 (see the name "sw1p0")

The driver also remembers the "1 -> 100" mapping. In the hotpath, if the sub-VLAN from the tag encodes a non-untagged frame, this mapping is used to create a VLAN hwaccel tag, with the value of 100.

---
Changes in v2:
None.

 include/linux/dsa/8021q.h | 16 +++++++++++
 net/dsa/tag_8021q.c       | 56 +++++++++++++++++++++++++++++++++------
 2 files changed, 64 insertions(+), 8 deletions(-)
include/linux/dsa/8021q.h +16 -0
index 404bd2cce642..311aa04e7520 100644
@@ -20,6 +20,8 @@ struct dsa_8021q_crosschip_link {
 	refcount_t refcount;
 };
 
+#define DSA_8021Q_N_SUBVLAN			8
+
 #if IS_ENABLED(CONFIG_NET_DSA_TAG_8021Q)
 
 int dsa_port_setup_8021q_tagging(struct dsa_switch *ds, int index,
@@ -42,10 +44,14 @@ u16 dsa_8021q_tx_vid(struct dsa_switch *ds, int port);
 
 u16 dsa_8021q_rx_vid(struct dsa_switch *ds, int port);
 
+u16 dsa_8021q_rx_vid_subvlan(struct dsa_switch *ds, int port, u16 subvlan);
+
 int dsa_8021q_rx_switch_id(u16 vid);
 
 int dsa_8021q_rx_source_port(u16 vid);
 
+u16 dsa_8021q_rx_subvlan(u16 vid);
+
 bool vid_is_dsa_8021q(u16 vid);
 
 #else
@@ -88,6 +94,11 @@ u16 dsa_8021q_rx_vid(struct dsa_switch *ds, int port)
 	return 0;
 }
 
+u16 dsa_8021q_rx_vid_subvlan(struct dsa_switch *ds, int port, u16 subvlan)
+{
+	return 0;
+}
+
 int dsa_8021q_rx_switch_id(u16 vid)
 {
 	return 0;
@@ -98,6 +109,11 @@ int dsa_8021q_rx_source_port(u16 vid)
 	return 0;
 }
 
+u16 dsa_8021q_rx_subvlan(u16 vid)
+{
+	return 0;
+}
+
 bool vid_is_dsa_8021q(u16 vid)
 {
 	return false;
net/dsa/tag_8021q.c +48 -8

90 lines not on this page · raw message

Signature · 1 line
2.17.1
Reviewed-by on v2 9/15
#20 lore raw

Re: [PATCH v2 net-next 09/15] net: dsa: tag_8021q: support up to 8 VLANs per port using sub-VLANs

Quoted 30 lines · Vladimir Oltean

From: Vladimir Oltean <[email protected]>

For switches that support VLAN retagging, such as sja1105, we extend dsa_8021q by encoding a "sub-VLAN" into the remaining 3 free bits in the dsa_8021q tag.

A sub-VLAN is nothing more than a number in the range 0-7, which serves as an index into a per-port driver lookup table. The sub-VLAN value of zero means that traffic is untagged (this is also backwards-compatible with dsa_8021q without retagging).

The switch should be configured to retag VLAN-tagged traffic that gets transmitted towards the CPU port (and towards the CPU only). Example:

bridge vlan add dev sw1p0 vid 100

The switch retags frames received on port 0, going to the CPU, and having VID 100, to the VID of 1104 (0x0450). In dsa_8021q language:

 | 11  | 10  |  9  |  8  |  7  |  6  |  5  |  4  |  3  |  2  |  1  |  0  |
 +-----------+-----+-----------------+-----------+-----------------------+
 |    DIR    | SVL |    SWITCH_ID    |  SUBVLAN  |          PORT         |
 +-----------+-----+-----------------+-----------+-----------------------+

0x0450 means:
- DIR = 0b01: this is an RX VLAN
- SUBVLAN = 0b001: this is subvlan #1
- SWITCH_ID = 0b001: this is switch 1 (see the name "sw1p0")
- PORT = 0b0000: this is port 0 (see the name "sw1p0")

Quoted 5 lines

The driver also remembers the "1 -> 100" mapping. In the hotpath, if the sub-VLAN from the tag encodes a non-untagged frame, this mapping is used to create a VLAN hwaccel tag, with the value of 100.

Signature · 1 line
Florian
author maintainer
#21 lore raw

PATCH v2 10/15 net: dsa: tag_sja1105: implement sub-VLAN decoding

In reply to Vladimir Oltean

From: Vladimir Oltean <[email protected]>

Create a subvlan_map as part of each port's tagger private structure. This keeps reverse mappings of bridge-to-dsa_8021q VLAN retagging rules.

Note that as of this patch, this piece of code is never engaged, due to the fact that the driver hasn't installed any retagging rule, so we'll always see packets with a subvlan code of 0 (untagged).

---
Changes in v2:
None.

 drivers/net/dsa/sja1105/sja1105_main.c |  4 ++++
 include/linux/dsa/sja1105.h            |  1 +
 net/dsa/tag_sja1105.c                  | 19 +++++++++++++++++++
 3 files changed, 24 insertions(+)
drivers/net/dsa/sja1105/sja1105_main.c +4 -0
index 042ecbbc5572..fe300cf94509 100644
@@ -2864,6 +2864,7 @@ static int sja1105_probe(struct spi_device *spi)
 		struct sja1105_port *sp = &priv->ports[port];
 		struct dsa_port *dp = dsa_to_port(ds, port);
 		struct net_device *slave;
+		int subvlan;
 
 		if (!dsa_is_user_port(ds, port))
 			continue;
@@ -2884,6 +2885,9 @@ static int sja1105_probe(struct spi_device *spi)
 		}
 		skb_queue_head_init(&sp->xmit_queue);
 		sp->xmit_tpid = ETH_P_SJA1105;
+
+		for (subvlan = 0; subvlan < DSA_8021Q_N_SUBVLAN; subvlan++)
+			sp->subvlan_map[subvlan] = VLAN_N_VID;
 	}
 
 	return 0;
include/linux/dsa/sja1105.h +1 -0
index e47acf0965c5..cac168852321 100644
@@ -54,6 +54,7 @@ struct sja1105_skb_cb {
 	((struct sja1105_skb_cb *)DSA_SKB_CB_PRIV(skb))
 
 struct sja1105_port {
+	u16 subvlan_map[DSA_8021Q_N_SUBVLAN];
 	struct kthread_worker *xmit_worker;
 	struct kthread_work xmit_work;
 	struct sk_buff_head xmit_queue;
net/dsa/tag_sja1105.c +19 -0
index 0a95fdd7bff8..f690511b6d31 100644
@@ -241,6 +241,20 @@ static struct sk_buff
 	return skb;
 }
 
+static void sja1105_decode_subvlan(struct sk_buff *skb, u16 subvlan)
+{
+	struct dsa_port *dp = dsa_slave_to_port(skb->dev);
+	struct sja1105_port *sp = dp->priv;
+	u16 vid = sp->subvlan_map[subvlan];
+	u16 vlan_tci;
+
+	if (vid == VLAN_N_VID)
+		return;
+
+	vlan_tci = (skb->priority << VLAN_PRIO_SHIFT) | vid;
+	__vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vlan_tci);
+}
+
 static struct sk_buff *sja1105_rcv(struct sk_buff *skb,
 				   struct net_device *netdev,
 				   struct packet_type *pt)
@@ -250,6 +264,7 @@ static struct sk_buff *sja1105_rcv(struct sk_buff *skb,
 	struct ethhdr *hdr;
 	u16 tpid, vid, tci;
 	bool is_link_local;
+	u16 subvlan = 0;
 	bool is_tagged;
 	bool is_meta;
 
@@ -273,6 +288,7 @@ static struct sk_buff *sja1105_rcv(struct sk_buff *skb,
 		source_port = dsa_8021q_rx_source_port(vid);
 		switch_id = dsa_8021q_rx_switch_id(vid);
 		skb->priority = (tci & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
+		subvlan = dsa_8021q_rx_subvlan(vid);
 	} else if (is_link_local) {
 		/* Management traffic path. Switch embeds the switch ID and
 		 * port ID into bytes of the destination MAC, courtesy of
@@ -297,6 +313,9 @@ static struct sk_buff *sja1105_rcv(struct sk_buff *skb,
 		return NULL;
 	}
 
+	if (subvlan)
+		sja1105_decode_subvlan(skb, subvlan);
+
 	return sja1105_rcv_meta_state_machine(skb, &meta, is_link_local,
 					      is_meta);
 }
Signature · 1 line
2.17.1
Reviewed-by on v2 10/15
#22 lore raw

Re: [PATCH v2 net-next 10/15] net: dsa: tag_sja1105: implement sub-VLAN decoding

Quoted 10 lines · Vladimir Oltean

From: Vladimir Oltean <[email protected]>

Create a subvlan_map as part of each port's tagger private structure. This keeps reverse mappings of bridge-to-dsa_8021q VLAN retagging rules.

Note that as of this patch, this piece of code is never engaged, due to the fact that the driver hasn't installed any retagging rule, so we'll always see packets with a subvlan code of 0 (untagged).

Signature · 1 line
Florian
author maintainer
#23 lore raw

PATCH v2 11/15 net: dsa: sja1105: add a new best_effort_vlan_filtering devlink parameter

In reply to Vladimir Oltean

From: Vladimir Oltean <[email protected]>

This devlink parameter enables the handling of DSA tags when enslaved to a bridge with vlan_filtering=1. There are very good reasons to want this, but there are also very good reasons for not enabling it by default. So a devlink param named best_effort_vlan_filtering, currently driver-specific and exported only by sja1105, is used to configure this.

In practice, this is perhaps the way that most users are going to use the switch in. It assumes that no more than 7 VLANs are needed per port.

---
Changes in v2:
- In sja1105_best_effort_vlan_filtering_set, get the vlan_filtering value of each port instead of just one time for port 0. Normally this shouldn't matter, but it avoids issues when port 0 is disabled in device tree.

 drivers/net/dsa/sja1105/sja1105.h      |   2 +
 drivers/net/dsa/sja1105/sja1105_main.c | 122 ++++++++++++++++++++++++-
 2 files changed, 120 insertions(+), 4 deletions(-)
drivers/net/dsa/sja1105/sja1105.h +2 -0
index a019ffae38f1..1dcaecab0912 100644
@@ -194,6 +194,7 @@ struct sja1105_bridge_vlan {
 
 enum sja1105_vlan_state {
 	SJA1105_VLAN_UNAWARE,
+	SJA1105_VLAN_BEST_EFFORT,
 	SJA1105_VLAN_FILTERING_FULL,
 };
 
@@ -201,6 +202,7 @@ struct sja1105_private {
 	struct sja1105_static_config static_config;
 	bool rgmii_rx_delay[SJA1105_NUM_PORTS];
 	bool rgmii_tx_delay[SJA1105_NUM_PORTS];
+	bool best_effort_vlan_filtering;
 	const struct sja1105_info *info;
 	struct gpio_desc *reset_gpio;
 	struct spi_device *spidev;
drivers/net/dsa/sja1105/sja1105_main.c +118 -4

184 lines not on this page · raw message

Signature · 1 line
2.17.1
Reviewed-by on v2 11/15
#24 lore raw

Re: [PATCH v2 net-next 11/15] net: dsa: sja1105: add a new best_effort_vlan_filtering devlink parameter

Quoted 8 lines · Vladimir Oltean

From: Vladimir Oltean <[email protected]>

This devlink parameter enables the handling of DSA tags when enslaved to a bridge with vlan_filtering=1. There are very good reasons to want this, but there are also very good reasons for not enabling it by default. So a devlink param named best_effort_vlan_filtering, currently driver-specific and exported only by sja1105, is used to configure this.

Quoted 4 lines

In practice, this is perhaps the way that most users are going to use the switch in. It assumes that no more than 7 VLANs are needed per port.

Signature · 1 line
Florian
author maintainer
#25 lore raw

PATCH v2 12/15 net: dsa: sja1105: add packing ops for the Retagging Table

In reply to Vladimir Oltean

From: Vladimir Oltean <[email protected]>

The Retagging Table is an optional feature that allows the switch to match frames against a {ingress port, egress port, vid} rule and change their VLAN ID. The retagged frames are by default clones of the original ones (since the hardware-foreseen use case was to mirror traffic for debugging purposes and to tag it with a special VLAN for this purpose), but we can force the original frames to be dropped by removing the pre-retagging VLAN from the port membership list of the egress port.

---
Changes in v2:
None.

 drivers/net/dsa/sja1105/sja1105.h             |  2 +
 .../net/dsa/sja1105/sja1105_dynamic_config.c  | 33 ++++++++++
 .../net/dsa/sja1105/sja1105_static_config.c   | 62 ++++++++++++++++++-
 .../net/dsa/sja1105/sja1105_static_config.h   | 15 +++++
 4 files changed, 110 insertions(+), 2 deletions(-)
drivers/net/dsa/sja1105/sja1105.h +2 -0
index 1dcaecab0912..1ecdfd6be4c2 100644
@@ -328,6 +328,8 @@ size_t sja1105et_l2_lookup_entry_packing(void *buf, void *entry_ptr,
 					 enum packing_op op);
 size_t sja1105_vlan_lookup_entry_packing(void *buf, void *entry_ptr,
 					 enum packing_op op);
+size_t sja1105_retagging_entry_packing(void *buf, void *entry_ptr,
+				       enum packing_op op);
 size_t sja1105pqrs_mac_config_entry_packing(void *buf, void *entry_ptr,
 					    enum packing_op op);
 size_t sja1105pqrs_avb_params_entry_packing(void *buf, void *entry_ptr,
drivers/net/dsa/sja1105/sja1105_dynamic_config.c +33 -0
index bdee01811960..2a8fbd7fdedc 100644
@@ -133,6 +133,9 @@
 #define SJA1105PQRS_SIZE_AVB_PARAMS_DYN_CMD			\
 	(SJA1105_SIZE_DYN_CMD + SJA1105PQRS_SIZE_AVB_PARAMS_ENTRY)
 
+#define SJA1105_SIZE_RETAGGING_DYN_CMD				\
+	(SJA1105_SIZE_DYN_CMD + SJA1105_SIZE_RETAGGING_ENTRY)
+
 #define SJA1105_MAX_DYN_CMD_SIZE				\
 	SJA1105PQRS_SIZE_MAC_CONFIG_DYN_CMD
 
@@ -525,6 +528,20 @@ sja1105pqrs_avb_params_cmd_packing(void *buf, struct sja1105_dyn_cmd *cmd,
 	sja1105_packing(p, &cmd->rdwrset, 29, 29, size, op);
 }
 
+static void
+sja1105_retagging_cmd_packing(void *buf, struct sja1105_dyn_cmd *cmd,
+			      enum packing_op op)
+{
+	u8 *p = buf + SJA1105_SIZE_RETAGGING_ENTRY;
+	const int size = SJA1105_SIZE_DYN_CMD;
+
+	sja1105_packing(p, &cmd->valid,    31, 31, size, op);
+	sja1105_packing(p, &cmd->errors,   30, 30, size, op);
+	sja1105_packing(p, &cmd->valident, 29, 29, size, op);
+	sja1105_packing(p, &cmd->rdwrset,  28, 28, size, op);
+	sja1105_packing(p, &cmd->index,     5,  0, size, op);
+}
+
 #define OP_READ		BIT(0)
 #define OP_WRITE	BIT(1)
 #define OP_DEL		BIT(2)
@@ -606,6 +623,14 @@ struct sja1105_dynamic_table_ops sja1105et_dyn_ops[BLK_IDX_MAX_DYN] = {
 		.packed_size = SJA1105ET_SIZE_GENERAL_PARAMS_DYN_CMD,
 		.addr = 0x34,
 	},
+	[BLK_IDX_RETAGGING] = {
+		.entry_packing = sja1105_retagging_entry_packing,
+		.cmd_packing = sja1105_retagging_cmd_packing,
+		.max_entry_count = SJA1105_MAX_RETAGGING_COUNT,
+		.access = (OP_WRITE | OP_DEL),
+		.packed_size = SJA1105_SIZE_RETAGGING_DYN_CMD,
+		.addr = 0x31,
+	},
 	[BLK_IDX_XMII_PARAMS] = {0},
 };
 
@@ -692,6 +717,14 @@ struct sja1105_dynamic_table_ops sja1105pqrs_dyn_ops[BLK_IDX_MAX_DYN] = {
 		.packed_size = SJA1105ET_SIZE_GENERAL_PARAMS_DYN_CMD,
 		.addr = 0x34,
 	},
+	[BLK_IDX_RETAGGING] = {
+		.entry_packing = sja1105_retagging_entry_packing,
+		.cmd_packing = sja1105_retagging_cmd_packing,
+		.max_entry_count = SJA1105_MAX_RETAGGING_COUNT,
+		.access = (OP_READ | OP_WRITE | OP_DEL),
+		.packed_size = SJA1105_SIZE_RETAGGING_DYN_CMD,
+		.addr = 0x38,
+	},
 	[BLK_IDX_XMII_PARAMS] = {0},
 };
 
drivers/net/dsa/sja1105/sja1105_static_config.c +60 -2

122 lines not on this page · raw message

drivers/net/dsa/sja1105/sja1105_static_config.h +15 -0
index b569e3de3590..d96044d86b11 100644
@@ -20,6 +20,7 @@
 #define SJA1105_SIZE_VLAN_LOOKUP_ENTRY			8
 #define SJA1105_SIZE_L2_FORWARDING_ENTRY		8
 #define SJA1105_SIZE_L2_FORWARDING_PARAMS_ENTRY		12
+#define SJA1105_SIZE_RETAGGING_ENTRY			8
 #define SJA1105_SIZE_XMII_PARAMS_ENTRY			4
 #define SJA1105_SIZE_SCHEDULE_PARAMS_ENTRY		12
 #define SJA1105_SIZE_SCHEDULE_ENTRY_POINTS_PARAMS_ENTRY	4
@@ -54,6 +55,7 @@ enum {
 	BLKID_L2_FORWARDING_PARAMS			= 0x0E,
 	BLKID_AVB_PARAMS				= 0x10,
 	BLKID_GENERAL_PARAMS				= 0x11,
+	BLKID_RETAGGING					= 0x12,
 	BLKID_XMII_PARAMS				= 0x4E,
 };
 
@@ -75,6 +77,7 @@ enum sja1105_blk_idx {
 	BLK_IDX_L2_FORWARDING_PARAMS,
 	BLK_IDX_AVB_PARAMS,
 	BLK_IDX_GENERAL_PARAMS,
+	BLK_IDX_RETAGGING,
 	BLK_IDX_XMII_PARAMS,
 	BLK_IDX_MAX,
 	/* Fake block indices that are only valid for dynamic access */
@@ -99,10 +102,12 @@ enum sja1105_blk_idx {
 #define SJA1105_MAX_L2_LOOKUP_PARAMS_COUNT		1
 #define SJA1105_MAX_L2_FORWARDING_PARAMS_COUNT		1
 #define SJA1105_MAX_GENERAL_PARAMS_COUNT		1
+#define SJA1105_MAX_RETAGGING_COUNT			32
 #define SJA1105_MAX_XMII_PARAMS_COUNT			1
 #define SJA1105_MAX_AVB_PARAMS_COUNT			1
 
 #define SJA1105_MAX_FRAME_MEMORY			929
+#define SJA1105_MAX_FRAME_MEMORY_RETAGGING		910
 
 #define SJA1105E_DEVICE_ID				0x9C00000Cull
 #define SJA1105T_DEVICE_ID				0x9E00030Eull
@@ -273,6 +278,16 @@ struct sja1105_mac_config_entry {
 	u64 ingress;
 };
 
+struct sja1105_retagging_entry {
+	u64 egr_port;
+	u64 ing_port;
+	u64 vlan_ing;
+	u64 vlan_egr;
+	u64 do_not_learn;
+	u64 use_dest_ports;
+	u64 destports;
+};
+
 struct sja1105_xmii_params_entry {
 	u64 phy_mac[5];
 	u64 xmii_mode[5];
Signature · 1 line
2.17.1
Reviewed-by on v2 12/15
#26 lore raw

Re: [PATCH v2 net-next 12/15] net: dsa: sja1105: add packing ops for the Retagging Table

Quoted 11 lines · Vladimir Oltean

From: Vladimir Oltean <[email protected]>

The Retagging Table is an optional feature that allows the switch to match frames against a {ingress port, egress port, vid} rule and change their VLAN ID. The retagged frames are by default clones of the original ones (since the hardware-foreseen use case was to mirror traffic for debugging purposes and to tag it with a special VLAN for this purpose), but we can force the original frames to be dropped by removing the pre-retagging VLAN from the port membership list of the egress port.

Signature · 1 line
Florian
author maintainer
#27 lore raw

PATCH v2 13/15 net: dsa: sja1105: implement a common frame memory partitioning function

In reply to Vladimir Oltean

From: Vladimir Oltean <[email protected]>

There are 2 different features that require some reserved frame memory
space: VLAN retagging and virtual links. Create a central function that modifies the static config and ensures frame memory is never overcommitted.

---
Changes in v2:
None.

 drivers/net/dsa/sja1105/sja1105.h             |  2 +
 drivers/net/dsa/sja1105/sja1105_main.c        | 37 +++++++++++++++++++
 .../net/dsa/sja1105/sja1105_static_config.h   |  1 +
 drivers/net/dsa/sja1105/sja1105_vl.c          | 20 +---------
 4 files changed, 42 insertions(+), 18 deletions(-)
drivers/net/dsa/sja1105/sja1105.h +2 -0
index 1ecdfd6be4c2..198d2a7d7f95 100644
@@ -244,6 +244,8 @@ enum sja1105_reset_reason {
 int sja1105_static_config_reload(struct sja1105_private *priv,
 				 enum sja1105_reset_reason reason);
 
+void sja1105_frame_memory_partitioning(struct sja1105_private *priv);
+
 /* From sja1105_spi.c */
 int sja1105_xfer_buf(const struct sja1105_private *priv,
 		     sja1105_spi_rw_mode_t rw, u64 reg_addr,
drivers/net/dsa/sja1105/sja1105_main.c +37 -0
index 99139fcdc715..99b453d0d205 100644
@@ -432,6 +432,41 @@ static int sja1105_init_l2_forwarding_params(struct sja1105_private *priv)
 	return 0;
 }
 
+void sja1105_frame_memory_partitioning(struct sja1105_private *priv)
+{
+	struct sja1105_l2_forwarding_params_entry *l2_fwd_params;
+	struct sja1105_vl_forwarding_params_entry *vl_fwd_params;
+	struct sja1105_table *table;
+	int max_mem;
+
+	/* VLAN retagging is implemented using a loopback port that consumes
+	 * frame buffers. That leaves less for us.
+	 */
+	if (priv->vlan_state == SJA1105_VLAN_BEST_EFFORT)
+		max_mem = SJA1105_MAX_FRAME_MEMORY_RETAGGING;
+	else
+		max_mem = SJA1105_MAX_FRAME_MEMORY;
+
+	table = &priv->static_config.tables[BLK_IDX_L2_FORWARDING_PARAMS];
+	l2_fwd_params = table->entries;
+	l2_fwd_params->part_spc[0] = max_mem;
+
+	/* If we have any critical-traffic virtual links, we need to reserve
+	 * some frame buffer memory for them. At the moment, hardcode the value
+	 * at 100 blocks of 128 bytes of memory each. This leaves 829 blocks
+	 * remaining for best-effort traffic. TODO: figure out a more flexible
+	 * way to perform the frame buffer partitioning.
+	 */
+	if (!priv->static_config.tables[BLK_IDX_VL_FORWARDING].entry_count)
+		return;
+
+	table = &priv->static_config.tables[BLK_IDX_VL_FORWARDING_PARAMS];
+	vl_fwd_params = table->entries;
+
+	l2_fwd_params->part_spc[0] -= SJA1105_VL_FRAME_MEMORY;
+	vl_fwd_params->partspc[0] = SJA1105_VL_FRAME_MEMORY;
+}
+
 static int sja1105_init_general_params(struct sja1105_private *priv)
 {
 	struct sja1105_general_params_entry default_general_params = {
@@ -2213,6 +2248,8 @@ static int sja1105_vlan_filtering(struct dsa_switch *ds, int port, bool enabled)
 	l2_lookup_params = table->entries;
 	l2_lookup_params->shared_learn = want_tagging;
 
+	sja1105_frame_memory_partitioning(priv);
+
 	rc = sja1105_static_config_reload(priv, SJA1105_VLAN_FILTERING);
 	if (rc)
 		dev_err(ds->dev, "Failed to change VLAN Ethertype\n");
drivers/net/dsa/sja1105/sja1105_static_config.h +1 -0
index d96044d86b11..5946847bb5b9 100644
@@ -108,6 +108,7 @@ enum sja1105_blk_idx {
 
 #define SJA1105_MAX_FRAME_MEMORY			929
 #define SJA1105_MAX_FRAME_MEMORY_RETAGGING		910
+#define SJA1105_VL_FRAME_MEMORY				100
 
 #define SJA1105E_DEVICE_ID				0x9C00000Cull
 #define SJA1105T_DEVICE_ID				0x9E00030Eull
drivers/net/dsa/sja1105/sja1105_vl.c +2 -18
index 312401995b54..f37611885376 100644
@@ -5,7 +5,6 @@
 #include <linux/dsa/8021q.h>
 #include "sja1105.h"
 
-#define SJA1105_VL_FRAME_MEMORY			100
 #define SJA1105_SIZE_VL_STATUS			8
 
 /* The switch flow classification core implements TTEthernet, which 'thinks' in
@@ -141,8 +140,6 @@ static bool sja1105_vl_key_lower(struct sja1105_vl_lookup_entry *a,
 static int sja1105_init_virtual_links(struct sja1105_private *priv,
 				      struct netlink_ext_ack *extack)
 {
-	struct sja1105_l2_forwarding_params_entry *l2_fwd_params;
-	struct sja1105_vl_forwarding_params_entry *vl_fwd_params;
 	struct sja1105_vl_policing_entry *vl_policing;
 	struct sja1105_vl_forwarding_entry *vl_fwd;
 	struct sja1105_vl_lookup_entry *vl_lookup;
@@ -153,10 +150,6 @@ static int sja1105_init_virtual_links(struct sja1105_private *priv,
 	int max_sharindx = 0;
 	int i, j, k;
 
-	table = &priv->static_config.tables[BLK_IDX_L2_FORWARDING_PARAMS];
-	l2_fwd_params = table->entries;
-	l2_fwd_params->part_spc[0] = SJA1105_MAX_FRAME_MEMORY;
-
 	/* Figure out the dimensioning of the problem */
 	list_for_each_entry(rule, &priv->flow_block.rules, list) {
 		if (rule->type != SJA1105_RULE_VL)
@@ -308,17 +301,6 @@ static int sja1105_init_virtual_links(struct sja1105_private *priv,
 	if (!table->entries)
 		return -ENOMEM;
 	table->entry_count = 1;
-	vl_fwd_params = table->entries;
-
-	/* Reserve some frame buffer memory for the critical-traffic virtual
-	 * links (this needs to be done). At the moment, hardcode the value
-	 * at 100 blocks of 128 bytes of memory each. This leaves 829 blocks
-	 * remaining for best-effort traffic. TODO: figure out a more flexible
-	 * way to perform the frame buffer partitioning.
-	 */
-	l2_fwd_params->part_spc[0] = SJA1105_MAX_FRAME_MEMORY -
-				     SJA1105_VL_FRAME_MEMORY;
-	vl_fwd_params->partspc[0] = SJA1105_VL_FRAME_MEMORY;
 
 	for (i = 0; i < num_virtual_links; i++) {
 		unsigned long cookie = vl_lookup[i].flow_cookie;
@@ -342,6 +324,8 @@ static int sja1105_init_virtual_links(struct sja1105_private *priv,
 		}
 	}
 
+	sja1105_frame_memory_partitioning(priv);
+
 	return 0;
 }
 
Signature · 1 line
2.17.1
Reviewed-by on v2 13/15
#28 lore raw

Re: [PATCH v2 net-next 13/15] net: dsa: sja1105: implement a common frame memory partitioning function

Quoted 8 lines · Vladimir Oltean

From: Vladimir Oltean <[email protected]>

There are 2 different features that require some reserved frame memory
space: VLAN retagging and virtual links. Create a central function that modifies the static config and ensures frame memory is never overcommitted.

Signature · 1 line
Florian
author maintainer
#29 lore raw

PATCH v2 14/15 net: dsa: sja1105: implement VLAN retagging for dsa_8021q sub-VLANs

In reply to Vladimir Oltean

From: Vladimir Oltean <[email protected]>

Expand the delta commit procedure for VLANs with additional logic for treating bridge_vlans in the newly introduced operating mode, SJA1105_VLAN_BEST_EFFORT.

For every bridge VLAN on every user port, a sub-VLAN index is calculated and retagging rules are installed towards a dsa_8021q rx_vid that encodes that sub-VLAN index. This way, the tagger can identify the original VLANs.

Extra care is taken for VLANs to still work as intended in cross-chip scenarios. Retagging may have unintended consequences for these because a sub-VLAN encoding that works for the CPU does not make any sense for a front-panel port.

---
Changes in v2:
- Only do anything in sja1105_build_subvlans and in sja1105_build_crosschip_subvlans when operating in SJA1105_VLAN_BEST_EFFORT state. This avoids installing VLAN retagging rules in unaware mode, which would cost us a penalty in terms of usable frame memory.

 drivers/net/dsa/sja1105/sja1105_main.c | 412 ++++++++++++++++++++++++-
 1 file changed, 409 insertions(+), 3 deletions(-)
drivers/net/dsa/sja1105/sja1105_main.c +409 -3
index 99b453d0d205..b398b1b4ad4e 100644
@@ -1869,6 +1869,57 @@ sja1105_get_tag_protocol(struct dsa_switch *ds, int port,
 	return DSA_TAG_PROTO_SJA1105;
 }
 
+static int sja1105_find_free_subvlan(u16 *subvlan_map, bool pvid)
+{
+	int subvlan;
+
+	if (pvid)
+		return 0;
+
+	for (subvlan = 1; subvlan < DSA_8021Q_N_SUBVLAN; subvlan++)
+		if (subvlan_map[subvlan] == VLAN_N_VID)
+			return subvlan;
+
+	return -1;
+}
+
+static int sja1105_find_subvlan(u16 *subvlan_map, u16 vid)
+{
+	int subvlan;
+
+	for (subvlan = 0; subvlan < DSA_8021Q_N_SUBVLAN; subvlan++)
+		if (subvlan_map[subvlan] == vid)
+			return subvlan;
+
+	return -1;
+}
+
+static int sja1105_find_committed_subvlan(struct sja1105_private *priv,
+					  int port, u16 vid)
+{
+	struct sja1105_port *sp = &priv->ports[port];
+
+	return sja1105_find_subvlan(sp->subvlan_map, vid);
+}
+
+static void sja1105_init_subvlan_map(u16 *subvlan_map)
+{
+	int subvlan;
+
+	for (subvlan = 0; subvlan < DSA_8021Q_N_SUBVLAN; subvlan++)
+		subvlan_map[subvlan] = VLAN_N_VID;
+}
+
+static void sja1105_commit_subvlan_map(struct sja1105_private *priv, int port,
+				       u16 *subvlan_map)
+{
+	struct sja1105_port *sp = &priv->ports[port];
+	int subvlan;
+
+	for (subvlan = 0; subvlan < DSA_8021Q_N_SUBVLAN; subvlan++)
+		sp->subvlan_map[subvlan] = subvlan_map[subvlan];
+}
+
 static int sja1105_is_vlan_configured(struct sja1105_private *priv, u16 vid)
 {
 	struct sja1105_vlan_lookup_entry *vlan;
@@ -1885,9 +1936,29 @@ static int sja1105_is_vlan_configured(struct sja1105_private *priv, u16 vid)
 	return -1;
 }
 
+static int
+sja1105_find_retagging_entry(struct sja1105_retagging_entry *retagging,
+			     int count, int from_port, u16 from_vid,
+			     u16 to_vid)
+{
+	int i;
+
+	for (i = 0; i < count; i++)
+		if (retagging[i].ing_port == BIT(from_port) &&
+		    retagging[i].vlan_ing == from_vid &&
+		    retagging[i].vlan_egr == to_vid)
+			return i;
+
+	/* Return an invalid entry index if not found */
+	return -1;
+}
+
 static int sja1105_commit_vlans(struct sja1105_private *priv,
-				struct sja1105_vlan_lookup_entry *new_vlan)
+				struct sja1105_vlan_lookup_entry *new_vlan,
+				struct sja1105_retagging_entry *new_retagging,
+				int num_retagging)
 {
+	struct sja1105_retagging_entry *retagging;
 	struct sja1105_vlan_lookup_entry *vlan;
 	struct sja1105_table *table;
 	int num_vlans = 0;
@@ -1947,9 +2018,50 @@ static int sja1105_commit_vlans(struct sja1105_private *priv,
 		vlan[k++] = new_vlan[i];
 	}
 
+	/* VLAN Retagging Table */
+	table = &priv->static_config.tables[BLK_IDX_RETAGGING];
+	retagging = table->entries;
+
+	for (i = 0; i < table->entry_count; i++) {
+		rc = sja1105_dynamic_config_write(priv, BLK_IDX_RETAGGING,
+						  i, &retagging[i], false);
+		if (rc)
+			return rc;
+	}
+
+	if (table->entry_count)
+		kfree(table->entries);
+
+	table->entries = kcalloc(num_retagging, table->ops->unpacked_entry_size,
+				 GFP_KERNEL);
+	if (!table->entries)
+		return -ENOMEM;
+
+	table->entry_count = num_retagging;
+	retagging = table->entries;
+
+	for (i = 0; i < num_retagging; i++) {
+		retagging[i] = new_retagging[i];
+
+		/* Update entry */
+		rc = sja1105_dynamic_config_write(priv, BLK_IDX_RETAGGING,
+						  i, &retagging[i], true);
+		if (rc < 0)
+			return rc;
+	}
+
 	return 0;
 }
 
+struct sja1105_crosschip_vlan {
+	struct list_head list;
+	u16 vid;
+	bool untagged;
+	int port;
+	int other_port;
+	struct dsa_switch *other_ds;
+};
+
 struct sja1105_crosschip_switch {
 	struct list_head list;
 	struct dsa_switch *other_ds;
@@ -2021,6 +2133,265 @@ sja1105_build_dsa_8021q_vlans(struct sja1105_private *priv,
 	return 0;
 }
 
+static int sja1105_build_subvlans(struct sja1105_private *priv,
+				  u16 subvlan_map[][DSA_8021Q_N_SUBVLAN],
+				  struct sja1105_vlan_lookup_entry *new_vlan,
+				  struct sja1105_retagging_entry *new_retagging,
+				  int *num_retagging)
+{
+	struct sja1105_bridge_vlan *v;
+	int k = *num_retagging;
+
+	if (priv->vlan_state != SJA1105_VLAN_BEST_EFFORT)
+		return 0;
+
+	list_for_each_entry(v, &priv->bridge_vlans, list) {
+		int upstream = dsa_upstream_port(priv->ds, v->port);
+		int match, subvlan;
+		u16 rx_vid;
+
+		/* Only sub-VLANs on user ports need to be applied.
+		 * Bridge VLANs also include VLANs added automatically
+		 * by DSA on the CPU port.
+		 */
+		if (!dsa_is_user_port(priv->ds, v->port))
+			continue;
+
+		subvlan = sja1105_find_subvlan(subvlan_map[v->port],
+					       v->vid);
+		if (subvlan < 0) {
+			subvlan = sja1105_find_free_subvlan(subvlan_map[v->port],
+							    v->pvid);
+			if (subvlan < 0) {
+				dev_err(priv->ds->dev, "No more free subvlans\n");
+				return -ENOSPC;
+			}
+		}
+
+		rx_vid = dsa_8021q_rx_vid_subvlan(priv->ds, v->port, subvlan);
+
+		/* @v->vid on @v->port needs to be retagged to @rx_vid
+		 * on @upstream. Assume @v->vid on @v->port and on
+		 * @upstream was already configured by the previous
+		 * iteration over bridge_vlans.
+		 */
+		match = rx_vid;
+		new_vlan[match].vlanid = rx_vid;
+		new_vlan[match].vmemb_port |= BIT(v->port);
+		new_vlan[match].vmemb_port |= BIT(upstream);
+		new_vlan[match].vlan_bc |= BIT(v->port);
+		new_vlan[match].vlan_bc |= BIT(upstream);
+		/* The "untagged" flag is set the same as for the
+		 * original VLAN
+		 */
+		if (!v->untagged)
+			new_vlan[match].tag_port |= BIT(v->port);
+		/* But it's always tagged towards the CPU */
+		new_vlan[match].tag_port |= BIT(upstream);
+
+		/* The Retagging Table generates packet *clones* with
+		 * the new VLAN. This is a very odd hardware quirk
+		 * which we need to suppress by dropping the original
+		 * packet.
+		 * Deny egress of the original VLAN towards the CPU
+		 * port. This will force the switch to drop it, and
+		 * we'll see only the retagged packets.
+		 */
+		match = v->vid;
+		new_vlan[match].vlan_bc &= ~BIT(upstream);
+
+		/* And the retagging itself */
+		new_retagging[k].vlan_ing = v->vid;
+		new_retagging[k].vlan_egr = rx_vid;
+		new_retagging[k].ing_port = BIT(v->port);
+		new_retagging[k].egr_port = BIT(upstream);
+		if (k++ == SJA1105_MAX_RETAGGING_COUNT) {
+			dev_err(priv->ds->dev, "No more retagging rules\n");
+			return -ENOSPC;
+		}
+
+		subvlan_map[v->port][subvlan] = v->vid;
+	}
+
+	*num_retagging = k;
+
+	return 0;
+}
+
+/* Sadly, in crosschip scenarios where the CPU port is also the link to another
+ * switch, we should retag backwards (the dsa_8021q vid to the original vid) on
+ * the CPU port of neighbour switches.
+ */
+static int
+sja1105_build_crosschip_subvlans(struct sja1105_private *priv,
+				 struct sja1105_vlan_lookup_entry *new_vlan,
+				 struct sja1105_retagging_entry *new_retagging,
+				 int *num_retagging)
+{
+	struct sja1105_crosschip_vlan *tmp, *pos;
+	struct dsa_8021q_crosschip_link *c;
+	struct sja1105_bridge_vlan *v, *w;
+	struct list_head crosschip_vlans;
+	int k = *num_retagging;
+	int rc = 0;
+
+	if (priv->vlan_state != SJA1105_VLAN_BEST_EFFORT)
+		return 0;
+
+	INIT_LIST_HEAD(&crosschip_vlans);
+
+	list_for_each_entry(c, &priv->crosschip_links, list) {
+		struct sja1105_private *other_priv = c->other_ds->priv;
+
+		if (other_priv->vlan_state == SJA1105_VLAN_FILTERING_FULL)
+			continue;
+
+		/* Crosschip links are also added to the CPU ports.
+		 * Ignore those.
+		 */
+		if (!dsa_is_user_port(priv->ds, c->port))
+			continue;
+		if (!dsa_is_user_port(c->other_ds, c->other_port))
+			continue;
+
+		/* Search for VLANs on the remote port */
+		list_for_each_entry(v, &other_priv->bridge_vlans, list) {
+			bool already_added = false;
+			bool we_have_it = false;
+
+			if (v->port != c->other_port)
+				continue;
+
+			/* If @v is a pvid on @other_ds, it does not need
+			 * re-retagging, because its SVL field is 0 and we
+			 * already allow that, via the dsa_8021q crosschip
+			 * links.
+			 */
+			if (v->pvid)
+				continue;
+
+			/* Search for the VLAN on our local port */
+			list_for_each_entry(w, &priv->bridge_vlans, list) {
+				if (w->port == c->port && w->vid == v->vid) {
+					we_have_it = true;
+					break;
+				}
+			}
+
+			if (!we_have_it)
+				continue;
+
+			list_for_each_entry(tmp, &crosschip_vlans, list) {
+				if (tmp->vid == v->vid &&
+				    tmp->untagged == v->untagged &&
+				    tmp->port == c->port &&
+				    tmp->other_port == v->port &&
+				    tmp->other_ds == c->other_ds) {
+					already_added = true;
+					break;
+				}
+			}
+
+			if (already_added)
+				continue;
+
+			tmp = kzalloc(sizeof(*tmp), GFP_KERNEL);
+			if (!tmp) {
+				dev_err(priv->ds->dev, "Failed to allocate memory\n");
+				rc = -ENOMEM;
+				goto out;
+			}
+			tmp->vid = v->vid;
+			tmp->port = c->port;
+			tmp->other_port = v->port;
+			tmp->other_ds = c->other_ds;
+			tmp->untagged = v->untagged;
+			list_add(&tmp->list, &crosschip_vlans);
+		}
+	}
+
+	list_for_each_entry(tmp, &crosschip_vlans, list) {
+		struct sja1105_private *other_priv = tmp->other_ds->priv;
+		int upstream = dsa_upstream_port(priv->ds, tmp->port);
+		int match, subvlan;
+		u16 rx_vid;
+
+		subvlan = sja1105_find_committed_subvlan(other_priv,
+							 tmp->other_port,
+							 tmp->vid);
+		/* If this happens, it's a bug. The neighbour switch does not
+		 * have a subvlan for tmp->vid on tmp->other_port, but it
+		 * should, since we already checked for its vlan_state.
+		 */
+		if (WARN_ON(subvlan < 0)) {
+			rc = -EINVAL;
+			goto out;
+		}
+
+		rx_vid = dsa_8021q_rx_vid_subvlan(tmp->other_ds,
+						  tmp->other_port,
+						  subvlan);
+
+		/* The @rx_vid retagged from @tmp->vid on
+		 * {@tmp->other_ds, @tmp->other_port} needs to be
+		 * re-retagged to @tmp->vid on the way back to us.
+		 *
+		 * Assume the original @tmp->vid is already configured
+		 * on this local switch, otherwise we wouldn't be
+		 * retagging its subvlan on the other switch in the
+		 * first place. We just need to add a reverse retagging
+		 * rule for @rx_vid and install @rx_vid on our ports.
+		 */
+		match = rx_vid;
+		new_vlan[match].vlanid = rx_vid;
+		new_vlan[match].vmemb_port |= BIT(tmp->port);
+		new_vlan[match].vmemb_port |= BIT(upstream);
+		/* The "untagged" flag is set the same as for the
+		 * original VLAN. And towards the CPU, it doesn't
+		 * really matter, because @rx_vid will only receive
+		 * traffic on that port. For consistency with other dsa_8021q
+		 * VLANs, we'll keep the CPU port tagged.
+		 */
+		if (!tmp->untagged)
+			new_vlan[match].tag_port |= BIT(tmp->port);
+		new_vlan[match].tag_port |= BIT(upstream);
+		/* Deny egress of @rx_vid towards our front-panel port.
+		 * This will force the switch to drop it, and we'll see
+		 * only the re-retagged packets (having the original,
+		 * pre-initial-retagging, VLAN @tmp->vid).
+		 */
+		new_vlan[match].vlan_bc &= ~BIT(tmp->port);
+
+		/* On reverse retagging, the same ingress VLAN goes to multiple
+		 * ports. So we have an opportunity to create composite rules
+		 * to not waste the limited space in the retagging table.
+		 */
+		k = sja1105_find_retagging_entry(new_retagging, *num_retagging,
+						 upstream, rx_vid, tmp->vid);
+		if (k < 0) {
+			if (*num_retagging == SJA1105_MAX_RETAGGING_COUNT) {
+				dev_err(priv->ds->dev, "No more retagging rules\n");
+				rc = -ENOSPC;
+				goto out;
+			}
+			k = (*num_retagging)++;
+		}
+		/* And the retagging itself */
+		new_retagging[k].vlan_ing = rx_vid;
+		new_retagging[k].vlan_egr = tmp->vid;
+		new_retagging[k].ing_port = BIT(upstream);
+		new_retagging[k].egr_port |= BIT(tmp->port);
+	}
+
+out:
+	list_for_each_entry_safe(tmp, pos, &crosschip_vlans, list) {
+		list_del(&tmp->list);
+		kfree(tmp);
+	}
+
+	return rc;
+}
+
 static int sja1105_build_vlan_table(struct sja1105_private *priv, bool notify);
 
 static int sja1105_notify_crosschip_switches(struct sja1105_private *priv)
@@ -2074,10 +2445,12 @@ static int sja1105_notify_crosschip_switches(struct sja1105_private *priv)
 
 static int sja1105_build_vlan_table(struct sja1105_private *priv, bool notify)
 {
+	u16 subvlan_map[SJA1105_NUM_PORTS][DSA_8021Q_N_SUBVLAN];
+	struct sja1105_retagging_entry *new_retagging;
 	struct sja1105_vlan_lookup_entry *new_vlan;
 	struct sja1105_table *table;
+	int i, num_retagging = 0;
 	int rc;
-	int i;
 
 	table = &priv->static_config.tables[BLK_IDX_VLAN_LOOKUP];
 	new_vlan = kcalloc(VLAN_N_VID,
@@ -2085,9 +2458,23 @@ static int sja1105_build_vlan_table(struct sja1105_private *priv, bool notify)
 	if (!new_vlan)
 		return -ENOMEM;
 
+	table = &priv->static_config.tables[BLK_IDX_VLAN_LOOKUP];
+	new_retagging = kcalloc(SJA1105_MAX_RETAGGING_COUNT,
+				table->ops->unpacked_entry_size, GFP_KERNEL);
+	if (!new_retagging) {
+		kfree(new_vlan);
+		return -ENOMEM;
+	}
+
 	for (i = 0; i < VLAN_N_VID; i++)
 		new_vlan[i].vlanid = VLAN_N_VID;
 
+	for (i = 0; i < SJA1105_MAX_RETAGGING_COUNT; i++)
+		new_retagging[i].vlan_ing = VLAN_N_VID;
+
+	for (i = 0; i < priv->ds->num_ports; i++)
+		sja1105_init_subvlan_map(subvlan_map[i]);
+
 	/* Bridge VLANs */
 	rc = sja1105_build_bridge_vlans(priv, new_vlan);
 	if (rc)
@@ -2102,7 +2489,22 @@ static int sja1105_build_vlan_table(struct sja1105_private *priv, bool notify)
 	if (rc)
 		goto out;
 
-	rc = sja1105_commit_vlans(priv, new_vlan);
+	/* Private VLANs necessary for dsa_8021q operation, which we need to
+	 * determine on our own:
+	 * - Sub-VLANs
+	 * - Sub-VLANs of crosschip switches
+	 */
+	rc = sja1105_build_subvlans(priv, subvlan_map, new_vlan, new_retagging,
+				    &num_retagging);
+	if (rc)
+		goto out;
+
+	rc = sja1105_build_crosschip_subvlans(priv, new_vlan, new_retagging,
+					      &num_retagging);
+	if (rc)
+		goto out;
+
+	rc = sja1105_commit_vlans(priv, new_vlan, new_retagging, num_retagging);
 	if (rc)
 		goto out;
 
@@ -2110,6 +2512,9 @@ static int sja1105_build_vlan_table(struct sja1105_private *priv, bool notify)
 	if (rc)
 		goto out;
 
+	for (i = 0; i < priv->ds->num_ports; i++)
+		sja1105_commit_subvlan_map(priv, i, subvlan_map[i]);
+
 	if (notify) {
 		rc = sja1105_notify_crosschip_switches(priv);
 		if (rc)
@@ -2118,6 +2523,7 @@ static int sja1105_build_vlan_table(struct sja1105_private *priv, bool notify)
 
 out:
 	kfree(new_vlan);
+	kfree(new_retagging);
 
 	return rc;
 }
Signature · 1 line
2.17.1
Reviewed-by on v2 14/15
#30 lore raw

Re: [PATCH v2 net-next 14/15] net: dsa: sja1105: implement VLAN retagging for dsa_8021q sub-VLANs

Quoted 11 lines · Vladimir Oltean

From: Vladimir Oltean <[email protected]>

Expand the delta commit procedure for VLANs with additional logic for treating bridge_vlans in the newly introduced operating mode, SJA1105_VLAN_BEST_EFFORT.

For every bridge VLAN on every user port, a sub-VLAN index is calculated and retagging rules are installed towards a dsa_8021q rx_vid that encodes that sub-VLAN index. This way, the tagger can identify the original VLANs.

Quoted 6 lines

Extra care is taken for VLANs to still work as intended in cross-chip scenarios. Retagging may have unintended consequences for these because a sub-VLAN encoding that works for the CPU does not make any sense for a front-panel port.

Signature · 1 line
Florian
author maintainer
#31 lore raw

PATCH v2 15/15 docs: net: dsa: sja1105: document the best_effort_vlan_filtering option

In reply to Vladimir Oltean

From: Vladimir Oltean <[email protected]>

---
Changes in v2:
None.

 .../networking/devlink-params-sja1105.txt     |  27 +++
 Documentation/networking/dsa/sja1105.rst      | 211 +++++++++++++++---
 2 files changed, 212 insertions(+), 26 deletions(-)
 create mode 100644 Documentation/networking/devlink-params-sja1105.txt
Documentation/networking/devlink-params-sja1105.txt new file +27 -0
new file mode 100644
index 000000000000..1d71742e270a
@@ -0,0 +1,27 @@
+best_effort_vlan_filtering
+			[DEVICE, DRIVER-SPECIFIC]
+			Allow plain ETH_P_8021Q headers to be used as DSA tags.
+			Benefits:
+			- Can terminate untagged traffic over switch net
+			  devices even when enslaved to a bridge with
+			  vlan_filtering=1.
+			- Can terminate VLAN-tagged traffic over switch net
+			  devices even when enslaved to a bridge with
+			  vlan_filtering=1, with some constraints (no more than
+			  7 non-pvid VLANs per user port).
+			- Can do QoS based on VLAN PCP and VLAN membership
+			  admission control for autonomously forwarded frames
+			  (regardless of whether they can be terminated on the
+			  CPU or not).
+			Drawbacks:
+			- User cannot use VLANs in range 1024-3071. If the
+			  switch receives frames with such VIDs, it will
+			  misinterpret them as DSA tags.
+			- Switch uses Shared VLAN Learning (FDB lookup uses
+			  only DMAC as key).
+			- When VLANs span cross-chip topologies, the total
+			  number of permitted VLANs may be less than 7 per
+			  port, due to a maximum number of 32 VLAN retagging
+			  rules per switch.
+			Configuration mode: runtime
+			Type: bool.
Documentation/networking/dsa/sja1105.rst +185 -26

219 lines not on this page · raw message

Signature · 1 line
2.17.1