Skip to contentSkip to conversation

Some VLAN handling cleanup in DSA

PATCH Superseded Vladimir Oltean 3 participants 31 messages Sep 7, 2020 – Oct 5, 2020

Subsystems (11)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Vladimir Oltean

author maintainer
#0 lore raw

cover Some VLAN handling cleanup in DSA

From: Vladimir Oltean <[email protected]>

This small series tries to consolidate the VLAN handling in DSA a little bit.

First, tag_8021q is reworked to be minimally invasive to the dsa_switch_ops structure. This makes the rest of the code a bit easier to follow.

Then, the configure_vlan_while_not_filtering flag is enabled by default, so new drivers won't use the legacy behavior by mistake. This was done after the recent conversation with Kurt Kanzenbach on the Hirschmann Hellcreek review patches.

Vladimir Oltean (4):
net: dsa: tag_8021q: include missing refcount.h
net: dsa: tag_8021q: add a context structure
Revert "net: dsa: Add more convenient functions for installing port
VLANs"
net: dsa: set configure_vlan_while_not_filtering to true by default

 drivers/net/dsa/b53/b53_common.c       |   1 +
 drivers/net/dsa/bcm_sf2.c              |   1 +
 drivers/net/dsa/dsa_loop.c             |   1 -
 drivers/net/dsa/lantiq_gswip.c         |   3 +
 drivers/net/dsa/microchip/ksz8795.c    |   2 +
 drivers/net/dsa/microchip/ksz9477.c    |   2 +
 drivers/net/dsa/mt7530.c               |   1 -
 drivers/net/dsa/mv88e6xxx/chip.c       |   1 +
 drivers/net/dsa/ocelot/felix.c         |   1 -
 drivers/net/dsa/qca/ar9331.c           |   2 +
 drivers/net/dsa/qca8k.c                |   1 -
 drivers/net/dsa/rtl8366rb.c            |   2 +
 drivers/net/dsa/sja1105/sja1105.h      |   3 +-
 drivers/net/dsa/sja1105/sja1105_main.c | 246 +++++++++++++++----------
 include/linux/dsa/8021q.h              |  49 ++---
 net/dsa/dsa2.c                         |   2 +
 net/dsa/dsa_priv.h                     |   2 -
 net/dsa/port.c                         |  33 ----
 net/dsa/slave.c                        |  63 ++++++-
 net/dsa/tag_8021q.c                    | 138 ++++++++------
 20 files changed, 319 insertions(+), 235 deletions(-)
Signature · 1 line
2.25.1
author maintainer
#1 lore raw

PATCH 1/4 net: dsa: tag_8021q: include missing refcount.h

From: Vladimir Oltean <[email protected]>

The previous assumption was that the caller would already have this header file included.

---
 include/linux/dsa/8021q.h | 1 +
 1 file changed, 1 insertion(+)
include/linux/dsa/8021q.h +1 -0
index 311aa04e7520..804750122c66 100644
@@ -5,6 +5,7 @@
 #ifndef _NET_DSA_8021Q_H
 #define _NET_DSA_8021Q_H
 
+#include <linux/refcount.h>
 #include <linux/types.h>
 
 struct dsa_switch;
Signature · 1 line
2.25.1
author maintainer
#3 lore raw

PATCH 2/4 net: dsa: tag_8021q: add a context structure

In reply to Vladimir Oltean

From: Vladimir Oltean <[email protected]>

While working on another tag_8021q driver implementation, some things became apparent:

- It is not mandatory for a DSA driver to offload the tag_8021q VLANs by using the VLAN table per se. For example, it can add custom TCAM rules that simply encapsulate RX traffic, and redirect & decapsulate rules for TX traffic. For such a driver, it makes no sense to receive the tag_8021q configuration through the same callback as it receives the VLAN configuration from the bridge and the 8021q modules.

- Currently, sja1105 (the only tag_8021q user) sets a priv->expect_dsa_8021q variable to distinguish between the bridge calling, and tag_8021q calling. That can be improved, to say the least.

- The crosschip bridging operations are, in fact, stateful already. The list of crosschip_links must be kept by the caller and passed to the relevant tag_8021q functions.

So it would be nice if the tag_8021q configuration was more self-contained. This patch attempts to do that.

Create a struct dsa_8021q_context which encapsulates a struct dsa_switch, and has 2 function pointers for adding and deleting a VLAN. These will replace the previous channel to the driver, which was through the .port_vlan_add and .port_vlan_del callbacks of dsa_switch_ops.

Also put the list of crosschip_links into this dsa_8021q_context. Drivers that don't support cross-chip bridging can simply omit to initialize this list, as long as they dont call any cross-chip function.

The rest of the patch is mostly plain refactoring of "ds" -> "ctx". The dsa_8021q_context structure needs to be propagated because adding a VLAN is now done through the ops function pointers inside of it.

---
 drivers/net/dsa/sja1105/sja1105.h      |   3 +-
 drivers/net/dsa/sja1105/sja1105_main.c | 244 +++++++++++++++----------
 include/linux/dsa/8021q.h              |  48 ++---
 net/dsa/tag_8021q.c                    | 138 +++++++-------
 4 files changed, 249 insertions(+), 184 deletions(-)
drivers/net/dsa/sja1105/sja1105.h +1 -2
index ba70b40a9a95..40b492cb1454 100644
@@ -210,14 +210,13 @@ struct sja1105_private {
 	struct dsa_switch *ds;
 	struct list_head dsa_8021q_vlans;
 	struct list_head bridge_vlans;
-	struct list_head crosschip_links;
 	struct sja1105_flow_block flow_block;
 	struct sja1105_port ports[SJA1105_NUM_PORTS];
 	/* Serializes transmission of management frames so that
 	 * the switch doesn't confuse them with one another.
 	 */
 	struct mutex mgmt_lock;
-	bool expect_dsa_8021q;
+	struct dsa_8021q_context dsa_8021q_ctx;
 	enum sja1105_vlan_state vlan_state;
 	struct sja1105_cbs_entry *cbs;
 	struct sja1105_tagger_data tagger_data;
drivers/net/dsa/sja1105/sja1105_main.c +144 -100

385 lines not on this page · raw message

include/linux/dsa/8021q.h +27 -21

82 lines not on this page · raw message

net/dsa/tag_8021q.c +77 -61

278 lines not on this page · raw message

Signature · 1 line
2.25.1
author maintainer
#4 lore raw

PATCH 3/4 Revert "net: dsa: Add more convenient functions for installing port VLANs"

In reply to Vladimir Oltean

From: Vladimir Oltean <[email protected]>

This reverts commit 314f76d7a68bab0516aa52877944e6aacfa0fc3f.

Citing that commit message, the call graph was:

    dsa_slave_vlan_rx_add_vid   dsa_port_setup_8021q_tagging
                |                        |
                |                        |
                |          +-------------+
                |          |
                v          v
               dsa_port_vid_add      dsa_slave_port_obj_add
                      |                         |
                      +-------+         +-------+
                              |         |
                              v         v
                           dsa_port_vlan_add

Now that tag_8021q has its own ops structure, it no longer relies on dsa_port_vid_add, and therefore on the dsa_switch_ops to install its VLANs.

So dsa_port_vid_add now only has one single caller. So we can simplify the call graph to what it was before, aka:

        dsa_slave_vlan_rx_add_vid     dsa_slave_port_obj_add
                      |                         |
                      +-------+         +-------+
                              |         |
                              v         v
                           dsa_port_vlan_add
---
 net/dsa/dsa_priv.h |  2 --
 net/dsa/port.c     | 33 ---------------------------------
 net/dsa/slave.c    | 34 +++++++++++++++++++++++++++++++---
 3 files changed, 31 insertions(+), 38 deletions(-)
net/dsa/dsa_priv.h +0 -2
index 1653e3377cb3..2da656d984ef 100644
@@ -164,8 +164,6 @@ int dsa_port_vlan_add(struct dsa_port *dp,
 		      struct switchdev_trans *trans);
 int dsa_port_vlan_del(struct dsa_port *dp,
 		      const struct switchdev_obj_port_vlan *vlan);
-int dsa_port_vid_add(struct dsa_port *dp, u16 vid, u16 flags);
-int dsa_port_vid_del(struct dsa_port *dp, u16 vid);
 int dsa_port_link_register_of(struct dsa_port *dp);
 void dsa_port_link_unregister_of(struct dsa_port *dp);
 extern const struct phylink_mac_ops dsa_port_phylink_mac_ops;
net/dsa/port.c +0 -33
index e23ece229c7e..46c9bf709683 100644
@@ -433,39 +433,6 @@ int dsa_port_vlan_del(struct dsa_port *dp,
 	return dsa_port_notify(dp, DSA_NOTIFIER_VLAN_DEL, &info);
 }
 
-int dsa_port_vid_add(struct dsa_port *dp, u16 vid, u16 flags)
-{
-	struct switchdev_obj_port_vlan vlan = {
-		.obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
-		.flags = flags,
-		.vid_begin = vid,
-		.vid_end = vid,
-	};
-	struct switchdev_trans trans;
-	int err;
-
-	trans.ph_prepare = true;
-	err = dsa_port_vlan_add(dp, &vlan, &trans);
-	if (err)
-		return err;
-
-	trans.ph_prepare = false;
-	return dsa_port_vlan_add(dp, &vlan, &trans);
-}
-EXPORT_SYMBOL(dsa_port_vid_add);
-
-int dsa_port_vid_del(struct dsa_port *dp, u16 vid)
-{
-	struct switchdev_obj_port_vlan vlan = {
-		.obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
-		.vid_begin = vid,
-		.vid_end = vid,
-	};
-
-	return dsa_port_vlan_del(dp, &vlan);
-}
-EXPORT_SYMBOL(dsa_port_vid_del);
-
 static struct phy_device *dsa_port_get_phy_device(struct dsa_port *dp)
 {
 	struct device_node *phy_dn;
net/dsa/slave.c +31 -3
index 9af1a2d0cec4..e429c71df854 100644
@@ -1233,7 +1233,15 @@ static int dsa_slave_vlan_rx_add_vid(struct net_device *dev, __be16 proto,
 				     u16 vid)
 {
 	struct dsa_port *dp = dsa_slave_to_port(dev);
+	struct switchdev_obj_port_vlan vlan = {
+		.obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
+		.vid_begin = vid,
+		.vid_end = vid,
+		/* This API only allows programming tagged, non-PVID VIDs */
+		.flags = 0,
+	};
 	struct bridge_vlan_info info;
+	struct switchdev_trans trans;
 	int ret;
 
 	/* Check for a possible bridge VLAN entry now since there is no
@@ -1252,11 +1260,25 @@ static int dsa_slave_vlan_rx_add_vid(struct net_device *dev, __be16 proto,
 			return -EBUSY;
 	}
 
-	ret = dsa_port_vid_add(dp, vid, 0);
+	/* User port... */
+	trans.ph_prepare = true;
+	ret = dsa_port_vlan_add(dp, &vlan, &trans);
+	if (ret)
+		return ret;
+
+	trans.ph_prepare = false;
+	ret = dsa_port_vlan_add(dp, &vlan, &trans);
 	if (ret)
 		return ret;
 
-	ret = dsa_port_vid_add(dp->cpu_dp, vid, 0);
+	/* And CPU port... */
+	trans.ph_prepare = true;
+	ret = dsa_port_vlan_add(dp->cpu_dp, &vlan, &trans);
+	if (ret)
+		return ret;
+
+	trans.ph_prepare = false;
+	ret = dsa_port_vlan_add(dp->cpu_dp, &vlan, &trans);
 	if (ret)
 		return ret;
 
@@ -1267,6 +1289,12 @@ static int dsa_slave_vlan_rx_kill_vid(struct net_device *dev, __be16 proto,
 				      u16 vid)
 {
 	struct dsa_port *dp = dsa_slave_to_port(dev);
+	struct switchdev_obj_port_vlan vlan = {
+		.vid_begin = vid,
+		.vid_end = vid,
+		/* This API only allows programming tagged, non-PVID VIDs */
+		.flags = 0,
+	};
 	struct bridge_vlan_info info;
 	int ret;
 
@@ -1289,7 +1317,7 @@ static int dsa_slave_vlan_rx_kill_vid(struct net_device *dev, __be16 proto,
 	/* Do not deprogram the CPU port as it may be shared with other user
 	 * ports which can be members of this VLAN as well.
 	 */
-	return dsa_port_vid_del(dp, vid);
+	return dsa_port_vlan_del(dp, &vlan);
 }
 
 struct dsa_hw_port {
Signature · 1 line
2.25.1
author maintainer
#5 lore raw

PATCH 4/4 net: dsa: set configure_vlan_while_not_filtering to true by default

In reply to Vladimir Oltean

From: Vladimir Oltean <[email protected]>

As explained in commit 54a0ed0df496 ("net: dsa: provide an option for drivers to always receive bridge VLANs"), DSA has historically been skipping VLAN switchdev operations when the bridge wasn't in vlan_filtering mode, but the reason why it was doing that has never been clear. So the configure_vlan_while_not_filtering option is there merely to preserve functionality for existing drivers. It isn't some behavior that drivers should opt into. Ideally, when all drivers leave this flag set, we can delete the dsa_port_skip_vlan_configuration() function.

New drivers always seem to omit setting this flag, for some reason. So let's reverse the logic: the DSA core sets it by default to true before the .setup() callback, and legacy drivers can turn it off. This way, new drivers get the new behavior by default, unless they explicitly set the flag to false, which is more obvious during review.

Remove the assignment from drivers which were setting it to true, and add the assignment to false for the drivers that didn't previously have it. This way, it should be easier to see how many we have left.

The following drivers: lan9303, mv88e6060 were skipped from setting this flag to false, because they didn't have any VLAN offload ops in the first place.

Also, print a message to the console every time a VLAN has been skipped. This is mildly annoying on purpose, so that (a) it is at least clear that VLANs are being skipped - the legacy behavior in itself is confusing - and (b) people have one more incentive to convert to the new behavior.

No behavior change except for the added prints is intended at this time.

---
 drivers/net/dsa/b53/b53_common.c       |  1 +
 drivers/net/dsa/bcm_sf2.c              |  1 +
 drivers/net/dsa/dsa_loop.c             |  1 -
 drivers/net/dsa/lantiq_gswip.c         |  3 +++
 drivers/net/dsa/microchip/ksz8795.c    |  2 ++
 drivers/net/dsa/microchip/ksz9477.c    |  2 ++
 drivers/net/dsa/mt7530.c               |  1 -
 drivers/net/dsa/mv88e6xxx/chip.c       |  1 +
 drivers/net/dsa/ocelot/felix.c         |  1 -
 drivers/net/dsa/qca/ar9331.c           |  2 ++
 drivers/net/dsa/qca8k.c                |  1 -
 drivers/net/dsa/rtl8366rb.c            |  2 ++
 drivers/net/dsa/sja1105/sja1105_main.c |  2 --
 net/dsa/dsa2.c                         |  2 ++
 net/dsa/slave.c                        | 29 +++++++++++++++++++-------
 15 files changed, 38 insertions(+), 13 deletions(-)
drivers/net/dsa/b53/b53_common.c +1 -0
index 26fcff85d881..d127cdda16e8 100644
@@ -1011,6 +1011,7 @@ static int b53_setup(struct dsa_switch *ds)
 	 * devices. (not hardware supported)
 	 */
 	ds->vlan_filtering_is_global = true;
+	ds->configure_vlan_while_not_filtering = false;
 
 	return ret;
 }
drivers/net/dsa/bcm_sf2.c +1 -0
index 3263e8a0ae67..f9587a73fe54 100644
@@ -1242,6 +1242,7 @@ static int bcm_sf2_sw_probe(struct platform_device *pdev)
 
 	/* Advertise the 8 egress queues */
 	ds->num_tx_queues = SF2_NUM_EGRESS_QUEUES;
+	ds->configure_vlan_while_not_filtering = false;
 
 	dev_set_drvdata(&pdev->dev, priv);
 
drivers/net/dsa/dsa_loop.c +0 -1
index b588614d1e5e..65b5c1a50282 100644
@@ -343,7 +343,6 @@ static int dsa_loop_drv_probe(struct mdio_device *mdiodev)
 	ds->dev = &mdiodev->dev;
 	ds->ops = &dsa_loop_driver;
 	ds->priv = ps;
-	ds->configure_vlan_while_not_filtering = true;
 	ps->bus = mdiodev->bus;
 
 	dev_set_drvdata(&mdiodev->dev, ds);
drivers/net/dsa/lantiq_gswip.c +3 -0
index 521ebc072903..8622d836cbd3 100644
@@ -837,6 +837,9 @@ static int gswip_setup(struct dsa_switch *ds)
 	}
 
 	gswip_port_enable(ds, cpu_port, NULL);
+
+	ds->configure_vlan_while_not_filtering = false;
+
 	return 0;
 }
 
drivers/net/dsa/microchip/ksz8795.c +2 -0
index 8f1d15ea15d9..03d65dc5a304 100644
@@ -1087,6 +1087,8 @@ static int ksz8795_setup(struct dsa_switch *ds)
 
 	ksz_init_mib_timer(dev);
 
+	ds->configure_vlan_while_not_filtering = false;
+
 	return 0;
 }
 
drivers/net/dsa/microchip/ksz9477.c +2 -0
index 3cb22d149813..fea265ca6f82 100644
@@ -1357,6 +1357,8 @@ static int ksz9477_setup(struct dsa_switch *ds)
 
 	ksz_init_mib_timer(dev);
 
+	ds->configure_vlan_while_not_filtering = false;
+
 	return 0;
 }
 
drivers/net/dsa/mt7530.c +0 -1
index 1aaf47a0da2b..4698e740f8fc 100644
@@ -1220,7 +1220,6 @@ mt7530_setup(struct dsa_switch *ds)
 	 * as two netdev instances.
 	 */
 	dn = dsa_to_port(ds, MT7530_CPU_PORT)->master->dev.of_node->parent;
-	ds->configure_vlan_while_not_filtering = true;
 
 	if (priv->id == ID_MT7530) {
 		regulator_set_voltage(priv->core_pwr, 1000000, 1000000);
drivers/net/dsa/mv88e6xxx/chip.c +1 -0
index 15b97a4f8d93..6948c6980092 100644
@@ -3090,6 +3090,7 @@ static int mv88e6xxx_setup(struct dsa_switch *ds)
 
 	chip->ds = ds;
 	ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
+	ds->configure_vlan_while_not_filtering = false;
 
 	mv88e6xxx_reg_lock(chip);
 
drivers/net/dsa/ocelot/felix.c +0 -1
index a1e1d3824110..2032c046a056 100644
@@ -612,7 +612,6 @@ static int felix_setup(struct dsa_switch *ds)
 				 ANA_FLOODING, tc);
 
 	ds->mtu_enforcement_ingress = true;
-	ds->configure_vlan_while_not_filtering = true;
 
 	return 0;
 }
drivers/net/dsa/qca/ar9331.c +2 -0
index e24a99031b80..20ac64219df2 100644
@@ -328,6 +328,8 @@ static int ar9331_sw_setup(struct dsa_switch *ds)
 	if (ret)
 		goto error;
 
+	ds->configure_vlan_while_not_filtering = false;
+
 	return 0;
 error:
 	dev_err_ratelimited(priv->dev, "%s: %i\n", __func__, ret);
drivers/net/dsa/qca8k.c +0 -1
index f1e484477e35..e05b9cc39231 100644
@@ -1442,7 +1442,6 @@ qca8k_sw_probe(struct mdio_device *mdiodev)
 
 	priv->ds->dev = &mdiodev->dev;
 	priv->ds->num_ports = QCA8K_NUM_PORTS;
-	priv->ds->configure_vlan_while_not_filtering = true;
 	priv->ds->priv = priv;
 	priv->ops = qca8k_switch_ops;
 	priv->ds->ops = &priv->ops;
drivers/net/dsa/rtl8366rb.c +2 -0
index f763f93f600f..c518ab49b968 100644
@@ -958,6 +958,8 @@ static int rtl8366rb_setup(struct dsa_switch *ds)
 		return -ENODEV;
 	}
 
+	ds->configure_vlan_while_not_filtering = false;
+
 	return 0;
 }
 
drivers/net/dsa/sja1105/sja1105_main.c +0 -2
index 045077252799..e2cee36f578f 100644
@@ -3047,8 +3047,6 @@ static int sja1105_setup(struct dsa_switch *ds)
 
 	ds->mtu_enforcement_ingress = true;
 
-	ds->configure_vlan_while_not_filtering = true;
-
 	rc = sja1105_setup_devlink_params(ds);
 	if (rc < 0)
 		return rc;
net/dsa/dsa2.c +2 -0
index c0ffc7a2b65f..4a5e2832009b 100644
@@ -414,6 +414,8 @@ static int dsa_switch_setup(struct dsa_switch *ds)
 	if (err)
 		goto unregister_devlink;
 
+	ds->configure_vlan_while_not_filtering = true;
+
 	err = ds->ops->setup(ds);
 	if (err < 0)
 		goto unregister_notifier;
net/dsa/slave.c +22 -7
index e429c71df854..e0c86e97bb78 100644
@@ -314,11 +314,14 @@ static int dsa_slave_vlan_add(struct net_device *dev,
 	if (obj->orig_dev != dev)
 		return -EOPNOTSUPP;
 
-	if (dsa_port_skip_vlan_configuration(dp))
-		return 0;
-
 	vlan = *SWITCHDEV_OBJ_PORT_VLAN(obj);
 
+	if (dsa_port_skip_vlan_configuration(dp)) {
+		netdev_warn(dev, "skipping configuration of VLAN %d-%d\n",
+			    vlan.vid_begin, vlan.vid_end);
+		return 0;
+	}
+
 	err = dsa_port_vlan_add(dp, &vlan, trans);
 	if (err)
 		return err;
@@ -377,17 +380,23 @@ static int dsa_slave_vlan_del(struct net_device *dev,
 			      const struct switchdev_obj *obj)
 {
 	struct dsa_port *dp = dsa_slave_to_port(dev);
+	struct switchdev_obj_port_vlan *vlan;
 
 	if (obj->orig_dev != dev)
 		return -EOPNOTSUPP;
 
-	if (dsa_port_skip_vlan_configuration(dp))
+	vlan = SWITCHDEV_OBJ_PORT_VLAN(obj);
+
+	if (dsa_port_skip_vlan_configuration(dp)) {
+		netdev_warn(dev, "skipping deletion of VLAN %d-%d\n",
+			    vlan->vid_begin, vlan->vid_end);
 		return 0;
+	}
 
 	/* Do not deprogram the CPU port as it may be shared with other user
 	 * ports which can be members of this VLAN as well.
 	 */
-	return dsa_port_vlan_del(dp, SWITCHDEV_OBJ_PORT_VLAN(obj));
+	return dsa_port_vlan_del(dp, vlan);
 }
 
 static int dsa_slave_port_obj_del(struct net_device *dev,
@@ -1248,8 +1257,11 @@ 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 (dsa_port_skip_vlan_configuration(dp))
+		if (dsa_port_skip_vlan_configuration(dp)) {
+			netdev_warn(dev, "skipping configuration of VLAN %d\n",
+				    vid);
 			return 0;
+		}
 
 		/* br_vlan_get_info() returns -EINVAL or -ENOENT if the
 		 * device, respectively the VID is not found, returning
@@ -1302,8 +1314,11 @@ 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 (dsa_port_skip_vlan_configuration(dp))
+		if (dsa_port_skip_vlan_configuration(dp)) {
+			netdev_warn(dev, "skipping deletion of VLAN %d\n",
+				    vid);
 			return 0;
+		}
 
 		/* br_vlan_get_info() returns -EINVAL or -ENOENT if the
 		 * device, respectively the VID is not found, returning
Signature · 1 line
2.25.1
#6 lore raw

Re: [PATCH net-next 4/4] net: dsa: set configure_vlan_while_not_filtering to true by default

Quoted 31 lines · Vladimir Oltean

From: Vladimir Oltean <[email protected]>

As explained in commit 54a0ed0df496 ("net: dsa: provide an option for drivers to always receive bridge VLANs"), DSA has historically been skipping VLAN switchdev operations when the bridge wasn't in vlan_filtering mode, but the reason why it was doing that has never been clear. So the configure_vlan_while_not_filtering option is there merely to preserve functionality for existing drivers. It isn't some behavior that drivers should opt into. Ideally, when all drivers leave this flag set, we can delete the dsa_port_skip_vlan_configuration() function.

New drivers always seem to omit setting this flag, for some reason. So let's reverse the logic: the DSA core sets it by default to true before the .setup() callback, and legacy drivers can turn it off. This way, new drivers get the new behavior by default, unless they explicitly set the flag to false, which is more obvious during review.

Remove the assignment from drivers which were setting it to true, and add the assignment to false for the drivers that didn't previously have it. This way, it should be easier to see how many we have left.

The following drivers: lan9303, mv88e6060 were skipped from setting this flag to false, because they didn't have any VLAN offload ops in the first place.

Also, print a message to the console every time a VLAN has been skipped. This is mildly annoying on purpose, so that (a) it is at least clear that VLANs are being skipped - the legacy behavior in itself is confusing - and (b) people have one more incentive to convert to the new behavior.

Quoted 3 lines

No behavior change except for the added prints is intended at this time.

You should be able to make b53 and bcm_sf2 also use configure_vlan_while_not_filtering to true (or rather not specify it), give me until tomorrow to run various tests if you don't mind.

Signature · 1 line
Florian
author maintainer
#7 lore raw

Re: [PATCH net-next 4/4] net: dsa: set configure_vlan_while_not_filtering to true by default

Quoted 3 lines · Florian Fainelli

You should be able to make b53 and bcm_sf2 also use configure_vlan_while_not_filtering to true (or rather not specify it), give me until tomorrow to run various tests if you don't mind.

Ok, but I would prefer not doing that in this patch.

Note that, given a choice, I try to avoid introducing functional changes in drivers where I don't have the hardware to test, or somebody to confirm that it works, at the very least.

For that reason, mv88e6xxx doesn't even have this flag set, even though Russell had sent a patch for it with the old name:
https://lore.kernel.org/netdev/[email protected]/

Somebody with a Marvell switch should probably pick that up and resend.

Thanks,
-Vladimir

#8 lore raw

Re: [PATCH net-next 4/4] net: dsa: set configure_vlan_while_not_filtering to true by default

In reply to Florian Fainelli
Quoted 34 lines · Florian Fainelli
Quoted 31 lines · Vladimir Oltean

From: Vladimir Oltean <[email protected]>

As explained in commit 54a0ed0df496 ("net: dsa: provide an option for drivers to always receive bridge VLANs"), DSA has historically been skipping VLAN switchdev operations when the bridge wasn't in vlan_filtering mode, but the reason why it was doing that has never been clear. So the configure_vlan_while_not_filtering option is there merely to preserve functionality for existing drivers. It isn't some behavior that drivers should opt into. Ideally, when all drivers leave this flag set, we can delete the dsa_port_skip_vlan_configuration() function.

New drivers always seem to omit setting this flag, for some reason. So let's reverse the logic: the DSA core sets it by default to true before the .setup() callback, and legacy drivers can turn it off. This way, new drivers get the new behavior by default, unless they explicitly set the flag to false, which is more obvious during review.

Remove the assignment from drivers which were setting it to true, and add the assignment to false for the drivers that didn't previously have it. This way, it should be easier to see how many we have left.

The following drivers: lan9303, mv88e6060 were skipped from setting this flag to false, because they didn't have any VLAN offload ops in the first place.

Also, print a message to the console every time a VLAN has been skipped. This is mildly annoying on purpose, so that (a) it is at least clear that VLANs are being skipped - the legacy behavior in itself is confusing - and (b) people have one more incentive to convert to the new behavior.

Quoted 5 lines
Quoted 3 lines

No behavior change except for the added prints is intended at this time.

You should be able to make b53 and bcm_sf2 also use configure_vlan_while_not_filtering to true (or rather not specify it), give me until tomorrow to run various tests if you don't mind.

For a reason I do not understand, we should be able to set configure_vlan_while_not_filtering to true, and get things to work, however this does not work for bridged ports unless the bridge also happens to have VLAN filtering enabled. There is a valid VLAN entry configured for the desired port, but nothing ingress or egresses, I will keep debugging but you can send this patch as-is I believe and I will amend b53 later once I understand what is going on.

Signature · 1 line
Florian
#9 lore raw

Re: [PATCH net-next 4/4] net: dsa: set configure_vlan_while_not_filtering to true by default

Quoted 37 lines · Florian Fainelli
Quoted 34 lines · Florian Fainelli
Quoted 31 lines · Vladimir Oltean

From: Vladimir Oltean <[email protected]>

As explained in commit 54a0ed0df496 ("net: dsa: provide an option for drivers to always receive bridge VLANs"), DSA has historically been skipping VLAN switchdev operations when the bridge wasn't in vlan_filtering mode, but the reason why it was doing that has never been clear. So the configure_vlan_while_not_filtering option is there merely to preserve functionality for existing drivers. It isn't some behavior that drivers should opt into. Ideally, when all drivers leave this flag set, we can delete the dsa_port_skip_vlan_configuration() function.

New drivers always seem to omit setting this flag, for some reason. So let's reverse the logic: the DSA core sets it by default to true before the .setup() callback, and legacy drivers can turn it off. This way, new drivers get the new behavior by default, unless they explicitly set the flag to false, which is more obvious during review.

Remove the assignment from drivers which were setting it to true, and add the assignment to false for the drivers that didn't previously have it. This way, it should be easier to see how many we have left.

The following drivers: lan9303, mv88e6060 were skipped from setting this flag to false, because they didn't have any VLAN offload ops in the first place.

Also, print a message to the console every time a VLAN has been skipped. This is mildly annoying on purpose, so that (a) it is at least clear that VLANs are being skipped - the legacy behavior in itself is confusing - and (b) people have one more incentive to convert to the new behavior.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

No behavior change except for the added prints is intended at this time.

You should be able to make b53 and bcm_sf2 also use configure_vlan_while_not_filtering to true (or rather not specify it), give me until tomorrow to run various tests if you don't mind.

For a reason I do not understand, we should be able to set configure_vlan_while_not_filtering to true, and get things to work, however this does not work for bridged ports unless the bridge also happens to have VLAN filtering enabled. There is a valid VLAN entry configured for the desired port, but nothing ingress or egresses, I will keep debugging but you can send this patch as-is I believe and I will amend b53 later once I understand what is going on.

Found the problem, we do not allow the CPU port to be configured as untagged, and when we toggle vlan_filtering we actually incorrectly "move" the PVID from 1 to 0, which is incorrect, but since the CPU is also untagged in VID 0 this is why it "works" or rather two mistakes canceling it each other.

I still need to confirm this, but the bridge in VLAN filtering mode seems to support receiving frames with the default_pvid as tagged, and it will untag it for the bridge master device transparently.

The reason for not allowing the CPU port to be untagged (ca8931948344c485569b04821d1f6bcebccd376b) was because the CPU port could be added as untagged in several VLANs, e.g.: when port0-3 are PVID 1 untagged, and port 4 is PVID 2 untagged. Back then there was no support for Broadcom tags, so the only way to differentiate traffic properly was to also add a pair of tagged VIDs to the DSA master.

I am still trying to remember whether there were other concerns that prompted me to make that change and would appreciate some thoughts on that. Tangentially, maybe we should finally add support for programming the CPU port's VLAN membership independently from the other ports.

The following appears to work nicely now and allows us to get rid of the b53_vlan_filtering() logic, which would no longer work now because it assumed that toggling vlan_filtering implied that there would be no VLAN configuration when filtering was off.

drivers/net/dsa/b53/b53_common.c +0 -0
index 26fcff85d881..fac033730f4a 100644
@@ -1322,23 +1322,6 @@ EXPORT_SYMBOL(b53_phylink_mac_link_up);
 int b53_vlan_filtering(struct dsa_switch *ds, int port, bool 

vlan_filtering)

 {
        struct b53_device *dev = ds->priv;

- u16 pvid, new_pvid;
-
- b53_read16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), &pvid);
- if (!vlan_filtering) {
- /* Filtering is currently enabled, use the default PVID since
- * the bridge does not expect tagging anymore
- */
- dev->ports[port].pvid = pvid;
- new_pvid = b53_default_pvid(dev);
- } else {
- /* Filtering is currently disabled, restore the previous PVID */
- new_pvid = dev->ports[port].pvid;
- }
-
- if (pvid != new_pvid)
- b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port),
- new_pvid);

        b53_enable_vlan(dev, dev->vlan_enabled, vlan_filtering);

@@ -1389,7 +1372,7 @@ void b53_vlan_add(struct dsa_switch *ds, int port,

                        untagged = true;

                vl->members |= BIT(port);
-               if (untagged && !dsa_is_cpu_port(ds, port))
+               if (untagged)
                        vl->untag |= BIT(port);
                else
                        vl->untag &= ~BIT(port);
@@ -1427,7 +1410,7 @@ int b53_vlan_del(struct dsa_switch *ds, int port,
                if (pvid == vid)
                        pvid = b53_default_pvid(dev);

- if (untagged && !dsa_is_cpu_port(ds, port))
+ if (untagged)

                        vl->untag &= ~(BIT(port));

                b53_set_vlan_entry(dev, vid, vl);
@@ -2563,6 +2546,8 @@ struct b53_device *b53_switch_alloc(struct device *base,
        dev->priv = priv;
        dev->ops = ops;
        ds->ops = &b53_switch_ops;
+       ds->configure_vlan_while_not_filtering = true;
+       dev->vlan_enabled = ds->configure_vlan_while_not_filtering;
        mutex_init(&dev->reg_mutex);
        mutex_init(&dev->stats_mutex);
Signature · 1 line
Florian
author maintainer
#10 lore raw

Re: [PATCH net-next 4/4] net: dsa: set configure_vlan_while_not_filtering to true by default

Quoted 3 lines · Florian Fainelli

Found the problem, we do not allow the CPU port to be configured as untagged, and when we toggle vlan_filtering we actually incorrectly "move" the PVID from 1 to 0,

pvid 1 must be coming from the default_pvid of the bridge, I assume. Where is pvid 0 (aka dev->ports[port].pvid) coming from? Is it simply the cached value from B53_VLAN_PORT_DEF_TAG, from a previous b53_vlan_filtering() call? Strange.

Quoted 2 lines

which is incorrect, but since the CPU is also untagged in VID 0 this is why it "works" or rather two mistakes canceling it each other.

How does the CPU end up untagged in VLAN 0?

Quoted 3 lines

I still need to confirm this, but the bridge in VLAN filtering mode seems to support receiving frames with the default_pvid as tagged, and it will untag it for the bridge master device transparently.

So it seems.

Quoted 8 lines

The reason for not allowing the CPU port to be untagged (ca8931948344c485569b04821d1f6bcebccd376b) was because the CPU port could be added as untagged in several VLANs, e.g.: when port0-3 are PVID 1 untagged, and port 4 is PVID 2 untagged. Back then there was no support for Broadcom tags, so the only way to differentiate traffic properly was to also add a pair of tagged VIDs to the DSA master.
I am still trying to remember whether there were other concerns that prompted me to make that change and would appreciate some thoughts on that.

I think it makes some sense to always configure the VLANs on the CPU port as tagged either way. I did the same in Felix and it's ok. But that was due to a hardware limitation. On sja1105 I'm keeping the same flags as on the user port, and that is ok too.

Quoted 2 lines

Tangentially, maybe we should finally add support for programming the CPU port's VLAN membership independently from the other ports.

How?

Quoted 28 lines

The following appears to work nicely now and allows us to get rid of the b53_vlan_filtering() logic, which would no longer work now because it assumed that toggling vlan_filtering implied that there would be no VLAN configuration when filtering was off.

drivers/net/dsa/b53/b53_common.c +0 -5
index 26fcff85d881..fac033730f4a 100644
@@ -1322,23 +1322,6 @@ EXPORT_SYMBOL(b53_phylink_mac_link_up);
 int b53_vlan_filtering(struct dsa_switch *ds, int port, bool
 vlan_filtering)
 {
        struct b53_device *dev = ds->priv;
-       u16 pvid, new_pvid;
-
-       b53_read16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), &pvid);
-       if (!vlan_filtering) {
-               /* Filtering is currently enabled, use the default PVID

since

drivers/net/dsa/b53/b53_common.c +0 -6
-                * the bridge does not expect tagging anymore
-                */
-               dev->ports[port].pvid = pvid;
-               new_pvid = b53_default_pvid(dev);
-       } else {
-               /* Filtering is currently disabled, restore the previous

PVID */

drivers/net/dsa/b53/b53_common.c

Quoted 6 lines
drivers/net/dsa/b53/b53_common.c +0 -6
-               new_pvid = dev->ports[port].pvid;
-       }
-
-       if (pvid != new_pvid)
-               b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port),
-                           new_pvid);

Yes, much simpler.

Quoted 13 lines
        b53_enable_vlan(dev, dev->vlan_enabled, vlan_filtering);
drivers/net/dsa/b53/b53_common.c +1 -1
@@ -1389,7 +1372,7 @@ void b53_vlan_add(struct dsa_switch *ds, int port,
                        untagged = true;
 
                vl->members |= BIT(port);
-               if (untagged && !dsa_is_cpu_port(ds, port))
+               if (untagged)
                        vl->untag |= BIT(port);
                else
                        vl->untag &= ~BIT(port);

drivers/net/dsa/b53/b53_common.c int b53_vlan_del(struct dsa_switch *ds, int port, · line 1413

Quoted 5 lines
drivers/net/dsa/b53/b53_common.c +1 -1
@@ -1427,7 +1410,7 @@ int b53_vlan_del(struct dsa_switch *ds, int port,
                if (pvid == vid)
                        pvid = b53_default_pvid(dev);
 
-               if (untagged && !dsa_is_cpu_port(ds, port))
+               if (untagged)

Ok, so you're removing this workaround now. A welcome simplification.

Quoted 16 lines
drivers/net/dsa/b53/b53_common.c +2 -0
                        vl->untag &= ~(BIT(port));
 
                b53_set_vlan_entry(dev, vid, vl);
@@ -2563,6 +2546,8 @@ struct b53_device *b53_switch_alloc(struct device
 *base,
        dev->priv = priv;
        dev->ops = ops;
        ds->ops = &b53_switch_ops;
+       ds->configure_vlan_while_not_filtering = true;
+       dev->vlan_enabled = ds->configure_vlan_while_not_filtering;
        mutex_init(&dev->reg_mutex);
        mutex_init(&dev->stats_mutex);
Signature · 2 lines
-- 
Florian

Looks good!

I'm going to hold off with my configure_vlan_while_not_filtering patch. You can send this one before me.

Thanks,
-Vladimir

#11 lore raw

Re: [PATCH net-next 4/4] net: dsa: set configure_vlan_while_not_filtering to true by default

Quoted 9 lines · Vladimir Oltean
Quoted 3 lines · Florian Fainelli

Found the problem, we do not allow the CPU port to be configured as untagged, and when we toggle vlan_filtering we actually incorrectly "move" the PVID from 1 to 0,

pvid 1 must be coming from the default_pvid of the bridge, I assume. Where is pvid 0 (aka dev->ports[port].pvid) coming from? Is it simply the cached value from B53_VLAN_PORT_DEF_TAG, from a previous b53_vlan_filtering() call? Strange.

The logic that writes to B53_VLAN_PORT_DEF_TAG does not update the shadow copy in dev->ports[port].pvid which is how they are out of sync.

Quoted 5 lines
Quoted 3 lines

which is incorrect, but since the CPU is also untagged in VID 0 this is why it "works" or rather two mistakes canceling it each other.

How does the CPU end up untagged in VLAN 0?

The CPU port gets also programmed with 0 in B53_VLAN_PORT_DEF_TAG.

Quoted 16 lines
Quoted 4 lines

I still need to confirm this, but the bridge in VLAN filtering mode seems to support receiving frames with the default_pvid as tagged, and it will untag it for the bridge master device transparently.

So it seems.

Quoted 8 lines

The reason for not allowing the CPU port to be untagged (ca8931948344c485569b04821d1f6bcebccd376b) was because the CPU port could be added as untagged in several VLANs, e.g.: when port0-3 are PVID 1 untagged, and port 4 is PVID 2 untagged. Back then there was no support for Broadcom tags, so the only way to differentiate traffic properly was to also add a pair of tagged VIDs to the DSA master.
I am still trying to remember whether there were other concerns that prompted me to make that change and would appreciate some thoughts on that.

Quoted 4 lines

I think it makes some sense to always configure the VLANs on the CPU port as tagged either way. I did the same in Felix and it's ok. But that was due to a hardware limitation. On sja1105 I'm keeping the same flags as on the user port, and that is ok too.

How do you make sure that the CPU port sees the frame untagged which would be necessary for a VLAN-unaware bridge? Do you have a special remapping rule?

Initially the concern I had was with the use case described above which was a 802.1Q separation, but in hindsight MAC address learning would result in the frames going to the appropriate ports/VLANs anyway.

Quoted 5 lines
Quoted 3 lines

Tangentially, maybe we should finally add support for programming the CPU port's VLAN membership independently from the other ports.

How?

Something like this:

https://lore.kernel.org/lkml/20180625091713.GA13442@apalos/T/

Quoted 73 lines
Quoted 29 lines

The following appears to work nicely now and allows us to get rid of the b53_vlan_filtering() logic, which would no longer work now because it assumed that toggling vlan_filtering implied that there would be no VLAN configuration when filtering was off.

drivers/net/dsa/b53/b53_common.c +0 -5
index 26fcff85d881..fac033730f4a 100644
@@ -1322,23 +1322,6 @@ EXPORT_SYMBOL(b53_phylink_mac_link_up);
  int b53_vlan_filtering(struct dsa_switch *ds, int port, bool
 vlan_filtering)
  {
         struct b53_device *dev = ds->priv;
-       u16 pvid, new_pvid;
-
-       b53_read16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), &pvid);
-       if (!vlan_filtering) {
-               /* Filtering is currently enabled, use the default PVID

since

drivers/net/dsa/b53/b53_common.c +0 -6
-                * the bridge does not expect tagging anymore
-                */
-               dev->ports[port].pvid = pvid;
-               new_pvid = b53_default_pvid(dev);
-       } else {
-               /* Filtering is currently disabled, restore the previous

PVID */

drivers/net/dsa/b53/b53_common.c

Quoted 6 lines
drivers/net/dsa/b53/b53_common.c +0 -6
-               new_pvid = dev->ports[port].pvid;
-       }
-
-       if (pvid != new_pvid)
-               b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port),
-                           new_pvid);

Yes, much simpler.

Quoted 13 lines
         b53_enable_vlan(dev, dev->vlan_enabled, vlan_filtering);
drivers/net/dsa/b53/b53_common.c +1 -1
@@ -1389,7 +1372,7 @@ void b53_vlan_add(struct dsa_switch *ds, int port,
                         untagged = true;
 
                 vl->members |= BIT(port);
-               if (untagged && !dsa_is_cpu_port(ds, port))
+               if (untagged)
                         vl->untag |= BIT(port);
                 else
                         vl->untag &= ~BIT(port);

drivers/net/dsa/b53/b53_common.c int b53_vlan_del(struct dsa_switch *ds, int port, · line 1413

Quoted 5 lines
drivers/net/dsa/b53/b53_common.c +1 -1
@@ -1427,7 +1410,7 @@ int b53_vlan_del(struct dsa_switch *ds, int port,
                 if (pvid == vid)
                         pvid = b53_default_pvid(dev);
 
-               if (untagged && !dsa_is_cpu_port(ds, port))
+               if (untagged)

Ok, so you're removing this workaround now. A welcome simplification.

Quoted 14 lines
drivers/net/dsa/b53/b53_common.c +2 -0
                         vl->untag &= ~(BIT(port));
 
                 b53_set_vlan_entry(dev, vid, vl);
@@ -2563,6 +2546,8 @@ struct b53_device *b53_switch_alloc(struct device
 *base,
         dev->priv = priv;
         dev->ops = ops;
         ds->ops = &b53_switch_ops;
+       ds->configure_vlan_while_not_filtering = true;
+       dev->vlan_enabled = ds->configure_vlan_while_not_filtering;
         mutex_init(&dev->reg_mutex);
         mutex_init(&dev->stats_mutex);
Quoted 7 lines
Quoted 2 lines
Signature · 1 line
Florian

Looks good!

I'm going to hold off with my configure_vlan_while_not_filtering patch. You can send this one before me.

That's the plan, thanks!

Signature · 1 line
Florian
author maintainer
#12 lore raw

Re: [PATCH net-next 4/4] net: dsa: set configure_vlan_while_not_filtering to true by default

Quoted 3 lines · Florian Fainelli

How do you make sure that the CPU port sees the frame untagged which would be necessary for a VLAN-unaware bridge? Do you have a special remapping rule?

No, I don't have any remapping rules that would be relevant here. Why would the frames need to be necessarily untagged for a VLAN-unaware bridge, why is it a problem if they aren't?

bool br_allowed_ingress(const struct net_bridge *br,

			struct net_bridge_vlan_group *vg, struct sk_buff *skb,
			u16 *vid, u8 *state)
{
	/* If VLAN filtering is disabled on the bridge, all packets are
	 * permitted.
	 */
	if (!br_opt_get(br, BROPT_VLAN_ENABLED)) {
		BR_INPUT_SKB_CB(skb)->vlan_filtered = false;
		return true;
	}

	return __allowed_ingress(br, vg, skb, vid, state);
}

If I have a VLAN on a bridged switch port where the bridge is not filtering, I have an 8021q upper of the bridge with that VLAN ID.

Quoted 3 lines

Initially the concern I had was with the use case described above which was a 802.1Q separation, but in hindsight MAC address learning would result in the frames going to the appropriate ports/VLANs anyway.

If by "separation" you mean "limiting the forwarding domain", the switch keeps the same VLAN associated with the frame internally, regardless of whether it's egress-tagged or not.

Quoted 9 lines
Quoted 5 lines
Quoted 3 lines

Tangentially, maybe we should finally add support for programming the CPU port's VLAN membership independently from the other ports.

How?

Something like this:

https://lore.kernel.org/lkml/20180625091713.GA13442@apalos/T/

I need to take some time to understand what's going on there.

#13 lore raw

Re: [PATCH net-next 4/4] net: dsa: set configure_vlan_while_not_filtering to true by default

Quoted 24 lines · Vladimir Oltean
Quoted 3 lines · Florian Fainelli

How do you make sure that the CPU port sees the frame untagged which would be necessary for a VLAN-unaware bridge? Do you have a special remapping rule?

No, I don't have any remapping rules that would be relevant here. Why would the frames need to be necessarily untagged for a VLAN-unaware bridge, why is it a problem if they aren't?

bool br_allowed_ingress(const struct net_bridge *br,

			struct net_bridge_vlan_group *vg, struct sk_buff *skb,
			u16 *vid, u8 *state)
{
	/* If VLAN filtering is disabled on the bridge, all packets are
	 * permitted.
	 */
	if (!br_opt_get(br, BROPT_VLAN_ENABLED)) {
		BR_INPUT_SKB_CB(skb)->vlan_filtered = false;
		return true;
	}

	return __allowed_ingress(br, vg, skb, vid, state);
}
Quoted 2 lines

If I have a VLAN on a bridged switch port where the bridge is not filtering, I have an 8021q upper of the bridge with that VLAN ID.

Yes that is the key right there, you need an 8021q upper to pop the VLAN ID or push it, that is another thing that users need to be aware of which is a bit awkward, most expect things to just work. Maybe we should just refuse to have bridge devices that are not VLAN-aware, because this is just too cumbersome to deal with.

Quoted 8 lines
Quoted 4 lines

Initially the concern I had was with the use case described above which was a 802.1Q separation, but in hindsight MAC address learning would result in the frames going to the appropriate ports/VLANs anyway.

If by "separation" you mean "limiting the forwarding domain", the switch keeps the same VLAN associated with the frame internally, regardless of whether it's egress-tagged or not.

True, so I am not sure what I was thinking back then.

Quoted 13 lines
Quoted 10 lines
Quoted 6 lines
Quoted 4 lines

Tangentially, maybe we should finally add support for programming the CPU port's VLAN membership independently from the other ports.

How?

Something like this:

https://lore.kernel.org/lkml/20180625091713.GA13442@apalos/T/

I need to take some time to understand what's going on there.

Signature · 1 line
Florian
#14 lore raw

Re: [PATCH net-next 4/4] net: dsa: set configure_vlan_while_not_filtering to true by default

Quoted 24 lines · Florian Fainelli
Quoted 21 lines · Vladimir Oltean
Quoted 3 lines · Florian Fainelli

How do you make sure that the CPU port sees the frame untagged which would be necessary for a VLAN-unaware bridge? Do you have a special remapping rule?

No, I don't have any remapping rules that would be relevant here. Why would the frames need to be necessarily untagged for a VLAN-unaware bridge, why is it a problem if they aren't?

bool br_allowed_ingress(const struct net_bridge *br, struct net_bridge_vlan_group *vg, struct sk_buff *skb, u16 *vid, u8 *state)
{
    /* If VLAN filtering is disabled on the bridge, all packets are
     * permitted.
     */
    if (!br_opt_get(br, BROPT_VLAN_ENABLED)) { BR_INPUT_SKB_CB(skb)->vlan_filtered = false; return true;
    }

Quoted 7 lines
Quoted 5 lines

    return __allowed_ingress(br, vg, skb, vid, state); }

If I have a VLAN on a bridged switch port where the bridge is not filtering, I have an 8021q upper of the bridge with that VLAN ID.

Yes that is the key right there, you need an 8021q upper to pop the VLAN ID or push it, that is another thing that users need to be aware of which is a bit awkward, most expect things to just work. Maybe we should just refuse to have bridge devices that are not VLAN-aware, because this is just too cumbersome to deal with.

With the drivers that you currently maintain and with the CPU port being always tagged in the VLANs added to the user-facing ports, when you are using a non-VLAN aware bridge, do you systematically add an br0.1 upper 802.1Q device to pop/push the VLAN tag?

I am about ready to submit the changes we discussed to b53, but I am still a bit uncomfortable with this part of the change because it will make the CPU port follow the untagged attribute of an user-facing port.

@@ -1444,7 +1427,7 @@ void b53_vlan_add(struct dsa_switch *ds, int port,

                        untagged = true;

                vl->members |= BIT(port);
-               if (untagged && !dsa_is_cpu_port(ds, port))
+               if (untagged)
                        vl->untag |= BIT(port);
                else
                        vl->untag &= ~BIT(port);
@@ -1482,7 +1465,7 @@ int b53_vlan_del(struct dsa_switch *ds, int port,
                if (pvid == vid)
                        pvid = b53_default_pvid(dev);

- if (untagged && !dsa_is_cpu_port(ds, port))
+ if (untagged)

                        vl->untag &= ~(BIT(port));
Signature · 1 line
Florian
author maintainer
#15 lore raw

Re: [PATCH net-next 4/4] net: dsa: set configure_vlan_while_not_filtering to true by default

Quoted 36 lines · Florian Fainelli
Quoted 26 lines · Florian Fainelli
Quoted 25 lines · Vladimir Oltean
Quoted 4 lines · Florian Fainelli

How do you make sure that the CPU port sees the frame untagged which would
be necessary for a VLAN-unaware bridge? Do you have a special remapping rule?

No, I don't have any remapping rules that would be relevant here. Why would the frames need to be necessarily untagged for a VLAN-unaware bridge, why is it a problem if they aren't?

bool br_allowed_ingress(const struct net_bridge *br, struct net_bridge_vlan_group *vg, struct sk_buff *skb, u16 *vid, u8 *state)
{
    /* If VLAN filtering is disabled on the bridge, all packets are
     * permitted.
     */
    if (!br_opt_get(br, BROPT_VLAN_ENABLED)) { BR_INPUT_SKB_CB(skb)->vlan_filtered = false; return true;
    }

    return __allowed_ingress(br, vg, skb, vid, state); }

Quoted 8 lines
Quoted 2 lines

If I have a VLAN on a bridged switch port where the bridge is not filtering, I have an 8021q upper of the bridge with that VLAN ID.

Yes that is the key right there, you need an 8021q upper to pop the VLAN ID or push it, that is another thing that users need to be aware of which is a bit awkward, most expect things to just work. Maybe we should just refuse to have bridge devices that are not VLAN-aware, because this is just too cumbersome to deal with.

Quoted 4 lines

With the drivers that you currently maintain and with the CPU port being always tagged in the VLANs added to the user-facing ports, when you are using a non-VLAN aware bridge, do you systematically add an br0.1 upper 802.1Q device to pop/push the VLAN tag?

Talking to you, I realized that I confused you uselessly. But in doing that, I actually cleared up a couple of things for myself. So thanks, I guess?

This is actually a great question, and it gave me the opportunity to reflect. So, only 1 driver that I maintain has the logic of always marking the CPU port as egress-tagged. And that would be ocelot/felix.

I need to give you a bit of background.
The DSA mode of Ocelot switches is more of an afterthought, and I am saying this because there is a distinction I need to make between the "CPU port module" (which is a set of queues that the CPU can inject and extract frames from), and the "NPI port" (which is an operating mode, where a regular front-panel Ethernet port is connected internally to the CPU port module and injection/extraction I/O can therefore be done via Ethernet, and that's your DSA).
Basically, when the NPI mode is in use, then it behaves less like an Ethernet port, and more like a set of CPU queues that connect over Ethernet, if that makes sense.
The port settings for VLAN are bypassed, and the packet is copied as-is from ingress to the NPI port. The egress-tagged port VLAN configuration does not actually result in a VLAN header being pushed into the frame, if that egress port is the NPI port. Instead, the classified VLAN ID (i.e. derived from the packet, or from the port-based VLAN, or from custom VLAN classification TCAM rules) is always kept in a 12-bit field of the Extraction Frame Header.

Currently I am ignoring the classified VLAN from the Extraction Frame Header, and simply passing the skb as-is to the stack. As-is, meaning as the switch ingress port had received it. So, in retrospect, my patch 183be6f967fe ("net: dsa: felix: send VLANs on CPU port as egress-tagged") is nothing more than a formality to make this piece of code shut up and not error out:

static int ocelot_port_set_native_vlan(struct ocelot *ocelot, int port,

				       u16 vid)
{
	struct ocelot_port *ocelot_port = ocelot->ports[port];
	u32 val = 0;

	if (ocelot_port->vid != vid) {
		/* Always permit deleting the native VLAN (vid = 0) */
		if (ocelot_port->vid && vid) {
			dev_err(ocelot->dev,
				"Port already has a native VLAN: %d\n",
				ocelot_port->vid);
			return -EBUSY;
		}
		ocelot_port->vid = vid;
	}

It's just now that I connected the dots and realized that.

So, looks like I don't really know what it's like to always have a tagged skb on ingress, even for egress-tagged VLANs. It must suck, I guess?

I think if I were in that situation, and the source port would be under a vlan_filtering=0 bridge, then I would simply pop the tag from the skb in the DSA rcv function, for all VLANs that I don't have an 8021q upper for.

Explaining this, it makes a lot of sense to do what Vitesse / Microsemi / Microchip is doing, which is to copy the frame as-is to the CPU, and to also tell you, separately, what the classified VLAN is. For example, in vlan_filtering=0 mode, the classified VLAN will always be 1, regardless of how the frame is tagged, because VLAN awareness is truly turned off for the ingress port, and the port-based VLAN is always used. In this way, you have the most flexibility: you can either ignore the classified VLAN and proceed with just what was in the ingress skb (this way, you'll have a switch that is not VLAN-unaware, just "checking" as opposed to "secure". It has passed the ingress VLAN filter, but you still remember what the VLAN ID was.
Or you can have a completely VLAN-unaware switch, if you pop all VLANs that you can find in the skb, and add a hwaccel tag based on the classified VLAN, if it isn't equal to the pvid of the port. This is great for things like compatibility with a vlan_filtering=0 upper bridge which is what we're talking about.

Basically, this is what, I think, DSA tries to emulate with the rule of copying the flags of a user port VLAN to the CPU port too. If we had the API to request an "unmodified" VLAN (not egress-tagged, not egress-untagged, just the same as on ingress), I'm sure we'd be using that by default (useful when vlan_filtering is 1). Knowing what the classified VLAN was also can be very useful at times (like when vlan_filtering is 0), so if there was an API for that, I'm sure DSA would have used that as well. With no such APIs, we can only use approximations.

Quoted 14 lines

I am about ready to submit the changes we discussed to b53, but I am still a bit uncomfortable with this part of the change because it will make the CPU port follow the untagged attribute of an user-facing port.

(quoted diff) +1 -1
@@ -1444,7 +1427,7 @@ void b53_vlan_add(struct dsa_switch *ds, int port,
                        untagged = true;
 
                vl->members |= BIT(port);
-               if (untagged && !dsa_is_cpu_port(ds, port))
+               if (untagged)
                        vl->untag |= BIT(port);
                else
                        vl->untag &= ~BIT(port);

Review int b53_vlan_del(struct dsa_switch *ds, int port, · line 1470

Quoted 7 lines
(quoted diff) +1 -1
@@ -1482,7 +1465,7 @@ int b53_vlan_del(struct dsa_switch *ds, int port,
                if (pvid == vid)
                        pvid = b53_default_pvid(dev);
 
-               if (untagged && !dsa_is_cpu_port(ds, port))
+               if (untagged)
                        vl->untag &= ~(BIT(port));
 

Which is ok, I believe? I mean, that's the default DSA logic. If you think that isn't ok, we should change it at a more fundamental level. What we've been discussing so far is akin to your current setup, not to the one you're planning to change to, isn't it? Are there any problems with the new setup?

Cheers,
-Vladimir

#16 lore raw

Re: [PATCH net-next 4/4] net: dsa: set configure_vlan_while_not_filtering to true by default

Quoted 50 lines · Vladimir Oltean
Quoted 36 lines · Florian Fainelli
Quoted 26 lines · Florian Fainelli
Quoted 25 lines · Vladimir Oltean
Quoted 4 lines · Florian Fainelli

How do you make sure that the CPU port sees the frame untagged which would
be necessary for a VLAN-unaware bridge? Do you have a special remapping rule?

No, I don't have any remapping rules that would be relevant here. Why would the frames need to be necessarily untagged for a VLAN-unaware bridge, why is it a problem if they aren't?

bool br_allowed_ingress(const struct net_bridge *br,
            struct net_bridge_vlan_group *vg, struct sk_buff *skb, u16 *vid, u8 *state)
{
    /* If VLAN filtering is disabled on the bridge, all packets are
     * permitted.
     */
    if (!br_opt_get(br, BROPT_VLAN_ENABLED)) { BR_INPUT_SKB_CB(skb)->vlan_filtered = false; return true;
    }

    return __allowed_ingress(br, vg, skb, vid, state);
}

Quoted 8 lines
Quoted 2 lines

If I have a VLAN on a bridged switch port where the bridge is not filtering, I have an 8021q upper of the bridge with that VLAN ID.

Yes that is the key right there, you need an 8021q upper to pop the VLAN ID or push it, that is another thing that users need to be aware of which is a bit awkward, most expect things to just work. Maybe we should just refuse to have bridge devices that are not VLAN-aware, because this is just too cumbersome to deal with.

Quoted 4 lines

With the drivers that you currently maintain and with the CPU port being always tagged in the VLANs added to the user-facing ports, when you are using a non-VLAN aware bridge, do you systematically add an br0.1 upper 802.1Q device to pop/push the VLAN tag?

Talking to you, I realized that I confused you uselessly. But in doing that, I actually cleared up a couple of things for myself. So thanks, I guess?

This is actually a great question, and it gave me the opportunity to reflect. So, only 1 driver that I maintain has the logic of always marking the CPU port as egress-tagged. And that would be ocelot/felix.

Quoted 11 lines

I need to give you a bit of background.
The DSA mode of Ocelot switches is more of an afterthought, and I am saying this because there is a distinction I need to make between the "CPU port module" (which is a set of queues that the CPU can inject and extract frames from), and the "NPI port" (which is an operating mode, where a regular front-panel Ethernet port is connected internally to the CPU port module and injection/extraction I/O can therefore be done via Ethernet, and that's your DSA).
Basically, when the NPI mode is in use, then it behaves less like an Ethernet port, and more like a set of CPU queues that connect over Ethernet, if that makes sense.

SYSTEMPORT + bcm_sf2 act a lot like that, too, except the CPU port still obeys VLAN, buffering, classification and other switch internal rules, but essentially we want to map queues from the user-facing port to DMAs used by the host processor.

Quoted 60 lines

The port settings for VLAN are bypassed, and the packet is copied as-is from ingress to the NPI port. The egress-tagged port VLAN configuration does not actually result in a VLAN header being pushed into the frame, if that egress port is the NPI port. Instead, the classified VLAN ID (i.e. derived from the packet, or from the port-based VLAN, or from custom VLAN classification TCAM rules) is always kept in a 12-bit field of the Extraction Frame Header.

Currently I am ignoring the classified VLAN from the Extraction Frame Header, and simply passing the skb as-is to the stack. As-is, meaning as the switch ingress port had received it. So, in retrospect, my patch 183be6f967fe ("net: dsa: felix: send VLANs on CPU port as egress-tagged") is nothing more than a formality to make this piece of code shut up and not error out:

static int ocelot_port_set_native_vlan(struct ocelot *ocelot, int port,

				       u16 vid)
{
	struct ocelot_port *ocelot_port = ocelot->ports[port];
	u32 val = 0;

	if (ocelot_port->vid != vid) {
		/* Always permit deleting the native VLAN (vid = 0) */
		if (ocelot_port->vid && vid) {
			dev_err(ocelot->dev,
				"Port already has a native VLAN: %d\n",
				ocelot_port->vid);
			return -EBUSY;
		}
		ocelot_port->vid = vid;
	}

It's just now that I connected the dots and realized that.

So, looks like I don't really know what it's like to always have a tagged skb on ingress, even for egress-tagged VLANs. It must suck, I guess?

I think if I were in that situation, and the source port would be under a vlan_filtering=0 bridge, then I would simply pop the tag from the skb in the DSA rcv function, for all VLANs that I don't have an 8021q upper for.

Explaining this, it makes a lot of sense to do what Vitesse / Microsemi / Microchip is doing, which is to copy the frame as-is to the CPU, and to also tell you, separately, what the classified VLAN is. For example, in vlan_filtering=0 mode, the classified VLAN will always be 1, regardless of how the frame is tagged, because VLAN awareness is truly turned off for the ingress port, and the port-based VLAN is always used. In this way, you have the most flexibility: you can either ignore the classified VLAN and proceed with just what was in the ingress skb (this way, you'll have a switch that is not VLAN-unaware, just "checking" as opposed to "secure". It has passed the ingress VLAN filter, but you still remember what the VLAN ID was.
Or you can have a completely VLAN-unaware switch, if you pop all VLANs that you can find in the skb, and add a hwaccel tag based on the classified VLAN, if it isn't equal to the pvid of the port. This is great for things like compatibility with a vlan_filtering=0 upper bridge which is what we're talking about.

Quoted 9 lines

Basically, this is what, I think, DSA tries to emulate with the rule of copying the flags of a user port VLAN to the CPU port too. If we had the API to request an "unmodified" VLAN (not egress-tagged, not egress-untagged, just the same as on ingress), I'm sure we'd be using that by default (useful when vlan_filtering is 1). Knowing what the classified VLAN was also can be very useful at times (like when vlan_filtering is 0), so if there was an API for that, I'm sure DSA would have used that as well. With no such APIs, we can only use approximations.

egress unmodified is what mv88e6xxx uses which is why I do not believe they have had the same issues that I had with vlan_filtering=0. For Broadcom switches there is not any option to have an umodified mode, the CPU port must have a valid VLAN membership (with vlan_filtering=1) and the egress untagged from the CPU port to the Ethernet MAC must match the expectations of the software data path behind.

Quoted 18 lines
Quoted 18 lines

I am about ready to submit the changes we discussed to b53, but I am still a bit uncomfortable with this part of the change because it will make the CPU port follow the untagged attribute of an user-facing port.

(quoted diff) +1 -1
@@ -1444,7 +1427,7 @@ void b53_vlan_add(struct dsa_switch *ds, int port,
                         untagged = true;
 
                 vl->members |= BIT(port);
-               if (untagged && !dsa_is_cpu_port(ds, port))
+               if (untagged)
                         vl->untag |= BIT(port);
                 else
                         vl->untag &= ~BIT(port);
@@ -1482,7 +1465,7 @@ int b53_vlan_del(struct dsa_switch *ds, int port,
                 if (pvid == vid)
                         pvid = b53_default_pvid(dev);
 
Quoted 10 lines

Review int b53_vlan_del(struct dsa_switch *ds, int port, · line 1470

Quoted 4 lines
(quoted diff) +1 -1
-               if (untagged && !dsa_is_cpu_port(ds, port))
+               if (untagged)
                         vl->untag &= ~(BIT(port));
 

Which is ok, I believe? I mean, that's the default DSA logic. If you think that isn't ok, we should change it at a more fundamental level. What we've been discussing so far is akin to your current setup, not to the one you're planning to change to, isn't it? Are there any problems with the new setup?

The change above is functional because the CPU port ends up being egress untagged in all of the bridge's default_pvid, whether vlan_filtering is 0 or 1 and that works.

The slightly confusing part is that a vlan_filtering=1 bridge accepts the default_pvid either tagged or untagged whereas a vlan_filtering=0 bridge does not, except for DHCP for instance. I would have to add a br0.1 802.1Q upper to take care of the default_pvid being egress tagged on the CPU port.

We could solve this in the DSA receive path, or the Broadcom tag receive path as you say since that is dependent on the tagging format and switch properties.

With Broadcom tags enabled now, all is well since we can differentiate traffic from different source ports using that 4 bytes tag.

Where this broke was when using a 802.1Q separation because all frames that egressed the CPU were egress tagged and it was no longer possible to differentiate whether they came from the LAN group in VID 1 or the WAN group in VID 2. But all of this should be a thing of the past now, ok, all is clear again now.

Thanks!

Signature · 1 line
Florian
author maintainer
#17 lore raw

Re: [PATCH net-next 4/4] net: dsa: set configure_vlan_while_not_filtering to true by default

Quoted 63 lines · Florian Fainelli
Quoted 50 lines · Vladimir Oltean
Quoted 36 lines · Florian Fainelli
Quoted 26 lines · Florian Fainelli
Quoted 25 lines · Vladimir Oltean
Quoted 4 lines · Florian Fainelli

How do you make sure that the CPU port sees the frame untagged which would
be necessary for a VLAN-unaware bridge? Do you have a special remapping rule?

No, I don't have any remapping rules that would be relevant here. Why would the frames need to be necessarily untagged for a VLAN-unaware bridge, why is it a problem if they aren't?

bool br_allowed_ingress(const struct net_bridge *br,
            struct net_bridge_vlan_group *vg, struct sk_buff *skb, u16 *vid, u8 *state)
{
    /* If VLAN filtering is disabled on the bridge, all packets are
     * permitted.
     */
    if (!br_opt_get(br, BROPT_VLAN_ENABLED)) { BR_INPUT_SKB_CB(skb)->vlan_filtered = false; return true;
    }

    return __allowed_ingress(br, vg, skb, vid, state);
}

Quoted 8 lines
Quoted 2 lines

If I have a VLAN on a bridged switch port where the bridge is not filtering, I have an 8021q upper of the bridge with that VLAN ID.

Yes that is the key right there, you need an 8021q upper to pop the VLAN ID or push it, that is another thing that users need to be aware of which is a bit awkward, most expect things to just work. Maybe we should just refuse to have bridge devices that are not VLAN-aware, because this is just too cumbersome to deal with.

Quoted 4 lines

With the drivers that you currently maintain and with the CPU port being always tagged in the VLANs added to the user-facing ports, when you are using a non-VLAN aware bridge, do you systematically add an br0.1 upper 802.1Q device to pop/push the VLAN tag?

Talking to you, I realized that I confused you uselessly. But in doing that, I actually cleared up a couple of things for myself. So thanks, I guess?

This is actually a great question, and it gave me the opportunity to reflect. So, only 1 driver that I maintain has the logic of always marking the CPU port as egress-tagged. And that would be ocelot/felix.

Quoted 11 lines

I need to give you a bit of background.
The DSA mode of Ocelot switches is more of an afterthought, and I am saying this because there is a distinction I need to make between the "CPU port module" (which is a set of queues that the CPU can inject and extract frames from), and the "NPI port" (which is an operating mode, where a regular front-panel Ethernet port is connected internally to the CPU port module and injection/extraction I/O can therefore be done via Ethernet, and that's your DSA).
Basically, when the NPI mode is in use, then it behaves less like an Ethernet port, and more like a set of CPU queues that connect over Ethernet, if that makes sense.

Quoted 4 lines

SYSTEMPORT + bcm_sf2 act a lot like that, too, except the CPU port still obeys VLAN, buffering, classification and other switch internal rules, but essentially we want to map queues from the user-facing port to DMAs used by the host processor.

Digressing a lot here, but the NPI port of Ocelot switches really isn't like that. For example, the NPI port doesn't even need to be in the reachability domain for a frame to reach it. Other example, a TCAM rule to drop a frame won't prevent it from reaching the NPI port, if that was previously selected as a destination for that frame. Other example:
there is no source address learning for traffic injected by the network stack over the NPI port. So, on RX, every frame that should reach the CPU is actually _flooded_, due to the destination being unknown. Other
example: the NPI port is so hardcoded to wrap everything in an Extraction Frame Header, that it even wraps PAUSE frames in it. That one especially is so bad that I have a patch series in the works to simply disable the NPI port and use tag_8021q instead. I just hate it.

Quoted 71 lines
Quoted 61 lines

The port settings for VLAN are bypassed, and the packet is copied as-is from ingress to the NPI port. The egress-tagged port VLAN configuration does not actually result in a VLAN header being pushed into the frame, if that egress port is the NPI port. Instead, the classified VLAN ID (i.e. derived from the packet, or from the port-based VLAN, or from custom VLAN classification TCAM rules) is always kept in a 12-bit field of the Extraction Frame Header.

Currently I am ignoring the classified VLAN from the Extraction Frame Header, and simply passing the skb as-is to the stack. As-is, meaning as the switch ingress port had received it. So, in retrospect, my patch 183be6f967fe ("net: dsa: felix: send VLANs on CPU port as egress-tagged") is nothing more than a formality to make this piece of code shut up and not error out:

static int ocelot_port_set_native_vlan(struct ocelot *ocelot, int port,

				       u16 vid)
{
	struct ocelot_port *ocelot_port = ocelot->ports[port];
	u32 val = 0;

	if (ocelot_port->vid != vid) {
		/* Always permit deleting the native VLAN (vid = 0) */
		if (ocelot_port->vid && vid) {
			dev_err(ocelot->dev,
				"Port already has a native VLAN: %d\n",
				ocelot_port->vid);
			return -EBUSY;
		}
		ocelot_port->vid = vid;
	}

It's just now that I connected the dots and realized that.

So, looks like I don't really know what it's like to always have a tagged skb on ingress, even for egress-tagged VLANs. It must suck, I guess?

I think if I were in that situation, and the source port would be under a vlan_filtering=0 bridge, then I would simply pop the tag from the skb in the DSA rcv function, for all VLANs that I don't have an 8021q upper for.

Explaining this, it makes a lot of sense to do what Vitesse / Microsemi / Microchip is doing, which is to copy the frame as-is to the CPU, and to also tell you, separately, what the classified VLAN is. For example, in vlan_filtering=0 mode, the classified VLAN will always be 1, regardless of how the frame is tagged, because VLAN awareness is truly turned off for the ingress port, and the port-based VLAN is always used. In this way, you have the most flexibility: you can either ignore the classified VLAN and proceed with just what was in the ingress skb (this way, you'll have a switch that is not VLAN-unaware, just "checking" as opposed to "secure". It has passed the ingress VLAN filter, but you still remember what the VLAN ID was.
Or you can have a completely VLAN-unaware switch, if you pop all VLANs that you can find in the skb, and add a hwaccel tag based on the classified VLAN, if it isn't equal to the pvid of the port. This is great for things like compatibility with a vlan_filtering=0 upper bridge which is what we're talking about.

Quoted 9 lines

Basically, this is what, I think, DSA tries to emulate with the rule of copying the flags of a user port VLAN to the CPU port too. If we had the API to request an "unmodified" VLAN (not egress-tagged, not egress-untagged, just the same as on ingress), I'm sure we'd be using that by default (useful when vlan_filtering is 1). Knowing what the classified VLAN was also can be very useful at times (like when vlan_filtering is 0), so if there was an API for that, I'm sure DSA would have used that as well. With no such APIs, we can only use approximations.

Quoted 7 lines

egress unmodified is what mv88e6xxx uses which is why I do not believe they have had the same issues that I had with vlan_filtering=0. For Broadcom switches there is not any option to have an umodified mode, the CPU port must have a valid VLAN membership (with vlan_filtering=1) and the egress untagged from the CPU port to the Ethernet MAC must match the expectations of the software data path behind.

So excepting mv88e6xxx and ocelot/felix, you are really in the same situation now with b53 and starfighter as everybody else is, am I not right? The "pvid and not untagged" VLAN is problematic for everybody in vlan_filtering=0 mode.

Quoted 29 lines
Quoted 18 lines
Quoted 18 lines

I am about ready to submit the changes we discussed to b53, but I am still a bit uncomfortable with this part of the change because it will make the CPU port follow the untagged attribute of an user-facing port.

(quoted diff) +1 -1
@@ -1444,7 +1427,7 @@ void b53_vlan_add(struct dsa_switch *ds, int port,
                         untagged = true;
 
                 vl->members |= BIT(port);
-               if (untagged && !dsa_is_cpu_port(ds, port))
+               if (untagged)
                         vl->untag |= BIT(port);
                 else
                         vl->untag &= ~BIT(port);
@@ -1482,7 +1465,7 @@ int b53_vlan_del(struct dsa_switch *ds, int port,
                 if (pvid == vid)
                         pvid = b53_default_pvid(dev);
 
Quoted 10 lines

Review int b53_vlan_del(struct dsa_switch *ds, int port, · line 1470

Quoted 4 lines
(quoted diff) +1 -1
-               if (untagged && !dsa_is_cpu_port(ds, port))
+               if (untagged)
                         vl->untag &= ~(BIT(port));
 

Which is ok, I believe? I mean, that's the default DSA logic. If you think that isn't ok, we should change it at a more fundamental level. What we've been discussing so far is akin to your current setup, not to the one you're planning to change to, isn't it? Are there any problems with the new setup?

Quoted 3 lines

The change above is functional because the CPU port ends up being egress untagged in all of the bridge's default_pvid, whether vlan_filtering is 0 or 1 and that works.

Yeah, heard you about one mistake cancelling another one out.

Quoted 9 lines

The slightly confusing part is that a vlan_filtering=1 bridge accepts the default_pvid either tagged or untagged whereas a vlan_filtering=0 bridge does not, except for DHCP for instance. I would have to add a br0.1 802.1Q upper to take care of the default_pvid being egress tagged on the CPU port.

We could solve this in the DSA receive path, or the Broadcom tag receive path as you say since that is dependent on the tagging format and switch properties.

Quoted 8 lines

With Broadcom tags enabled now, all is well since we can differentiate traffic from different source ports using that 4 bytes tag.

Where this broke was when using a 802.1Q separation because all frames that egressed the CPU were egress tagged and it was no longer possible to differentiate whether they came from the LAN group in VID 1 or the WAN group in VID 2. But all of this should be a thing of the past now, ok, all is clear again now.

Or we could do this, what do you think?

From 178a46f0f96555e17f3fcefa356e324a92dafab2 Mon Sep 17 00:00:00 2001
From: Vladimir Oltean <[email protected]>
Date: Fri, 11 Sep 2020 18:16:48 +0300
Subject: [PATCH] net: bridge: pop vlan from skb if filtering is disabled but
it's a pvid

Currently the bridge untags VLANs from its VLAN group in __allowed_ingress() only when VLAN filtering is enabled.

When installing a pvid in egress-tagged mode:

ip link add dev br0 type bridge vlan_filtering 0
ip link set swp0 master br0
bridge vlan del dev swp0 vid 1
bridge vlan add dev swp0 vid 1 pvid

When adding a VLAN on a DSA switch interface, DSA configures the VLAN membership of the CPU port using the same flags as swp0 (in this case "pvid and not untagged"), in an attempt to copy the frame as-is from ingress to the CPU.

However, in this case, the packet may arrive untagged on ingress, it will be pvid-tagged by the ingress port, and will be sent as egress-tagged towards the CPU. Otherwise stated, the CPU will see a VLAN tag where there was none to speak of on ingress.

When vlan_filtering is 1, this is not a problem, as stated in the first paragraph, because __allowed_ingress() will pop it. But currently, when vlan_filtering is 0 and we have such a VLAN configuration, we need an 8021q upper (br0.1) to be able to ping over that VLAN.

Make the 2 cases (vlan_filtering 0 and 1) behave the same way as popping the pvid, if the skb happens to be tagged with it, when vlan_filtering is 0.

---
 net/bridge/br_vlan.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
net/bridge/br_vlan.c +16 -0
index d2b8737f9fc0..b1e7211bae51 100644
@@ -580,7 +580,23 @@ bool br_allowed_ingress(const struct net_bridge *br,
 	 * permitted.
 	 */
 	if (!br_opt_get(br, BROPT_VLAN_ENABLED)) {
+		u16 vid;
+
 		BR_INPUT_SKB_CB(skb)->vlan_filtered = false;
+
+		/* See comment in __allowed_ingress about how skb can end up
+		 * here not having a hwaccel tag
+		 */
+		if (unlikely(!skb_vlan_tag_present(skb) &&
+			     skb->protocol == br->vlan_proto)) {
+			skb = skb_vlan_untag(skb);
+			if (unlikely(!skb))
+				return false;
+		}
+
+		if (!br_vlan_get_tag(skb, &vid) && vid == br_get_pvid(vg))
+			__vlan_hwaccel_clear_tag(skb);
+
 		return true;
 	}
 
Signature · 4 lines
2.25.1

Thanks,
-Vladimir
#18 lore raw

PATCH 4/4 net: dsa: set configure_vlan_while_not_filtering to true by default

Quoted 161 lines · Vladimir Oltean
Quoted 63 lines · Florian Fainelli
Quoted 50 lines · Vladimir Oltean
Quoted 36 lines · Florian Fainelli
Quoted 26 lines · Florian Fainelli
Quoted 25 lines · Vladimir Oltean
Quoted 4 lines · Florian Fainelli

How do you make sure that the CPU port sees the frame untagged which would
be necessary for a VLAN-unaware bridge? Do you have a special remapping rule?

No, I don't have any remapping rules that would be relevant here. Why would the frames need to be necessarily untagged for a VLAN-unaware bridge, why is it a problem if they aren't?

bool br_allowed_ingress(const struct net_bridge *br,
            struct net_bridge_vlan_group *vg, struct sk_buff *skb, u16 *vid, u8 *state)
{
    /* If VLAN filtering is disabled on the bridge, all packets are
     * permitted.
     */
    if (!br_opt_get(br, BROPT_VLAN_ENABLED)) { BR_INPUT_SKB_CB(skb)->vlan_filtered = false; return true;
    }

    return __allowed_ingress(br, vg, skb, vid, state);
}

Quoted 8 lines
Quoted 2 lines

If I have a VLAN on a bridged switch port where the bridge is not filtering, I have an 8021q upper of the bridge with that VLAN ID.

Yes that is the key right there, you need an 8021q upper to pop the VLAN ID or push it, that is another thing that users need to be aware of which is a bit awkward, most expect things to just work. Maybe we should just refuse to have bridge devices that are not VLAN-aware, because this is just too cumbersome to deal with.

Quoted 4 lines

With the drivers that you currently maintain and with the CPU port being always tagged in the VLANs added to the user-facing ports, when you are using a non-VLAN aware bridge, do you systematically add an br0.1 upper 802.1Q device to pop/push the VLAN tag?

Talking to you, I realized that I confused you uselessly. But in doing that, I actually cleared up a couple of things for myself. So thanks, I guess?

This is actually a great question, and it gave me the opportunity to reflect. So, only 1 driver that I maintain has the logic of always marking the CPU port as egress-tagged. And that would be ocelot/felix.

Quoted 11 lines

I need to give you a bit of background.
The DSA mode of Ocelot switches is more of an afterthought, and I am saying this because there is a distinction I need to make between the "CPU port module" (which is a set of queues that the CPU can inject and extract frames from), and the "NPI port" (which is an operating mode, where a regular front-panel Ethernet port is connected internally to the CPU port module and injection/extraction I/O can therefore be done via Ethernet, and that's your DSA).
Basically, when the NPI mode is in use, then it behaves less like an Ethernet port, and more like a set of CPU queues that connect over Ethernet, if that makes sense.

Quoted 4 lines

SYSTEMPORT + bcm_sf2 act a lot like that, too, except the CPU port still obeys VLAN, buffering, classification and other switch internal rules, but essentially we want to map queues from the user-facing port to DMAs used by the host processor.

Digressing a lot here, but the NPI port of Ocelot switches really isn't like that. For example, the NPI port doesn't even need to be in the reachability domain for a frame to reach it. Other example, a TCAM rule to drop a frame won't prevent it from reaching the NPI port, if that was previously selected as a destination for that frame. Other example:
there is no source address learning for traffic injected by the network stack over the NPI port. So, on RX, every frame that should reach the CPU is actually _flooded_, due to the destination being unknown. Other
example: the NPI port is so hardcoded to wrap everything in an Extraction Frame Header, that it even wraps PAUSE frames in it. That one especially is so bad that I have a patch series in the works to simply disable the NPI port and use tag_8021q instead. I just hate it.

Quoted 71 lines
Quoted 61 lines

The port settings for VLAN are bypassed, and the packet is copied as-is from ingress to the NPI port. The egress-tagged port VLAN configuration does not actually result in a VLAN header being pushed into the frame, if that egress port is the NPI port. Instead, the classified VLAN ID (i.e. derived from the packet, or from the port-based VLAN, or from custom VLAN classification TCAM rules) is always kept in a 12-bit field of the Extraction Frame Header.

Currently I am ignoring the classified VLAN from the Extraction Frame Header, and simply passing the skb as-is to the stack. As-is, meaning as the switch ingress port had received it. So, in retrospect, my patch 183be6f967fe ("net: dsa: felix: send VLANs on CPU port as egress-tagged") is nothing more than a formality to make this piece of code shut up and not error out:

static int ocelot_port_set_native_vlan(struct ocelot *ocelot, int port,

				       u16 vid)
{
	struct ocelot_port *ocelot_port = ocelot->ports[port];
	u32 val = 0;

	if (ocelot_port->vid != vid) {
		/* Always permit deleting the native VLAN (vid = 0) */
		if (ocelot_port->vid && vid) {
			dev_err(ocelot->dev,
				"Port already has a native VLAN: %d\n",
				ocelot_port->vid);
			return -EBUSY;
		}
		ocelot_port->vid = vid;
	}

It's just now that I connected the dots and realized that.

So, looks like I don't really know what it's like to always have a tagged skb on ingress, even for egress-tagged VLANs. It must suck, I guess?

I think if I were in that situation, and the source port would be under a vlan_filtering=0 bridge, then I would simply pop the tag from the skb in the DSA rcv function, for all VLANs that I don't have an 8021q upper for.

Explaining this, it makes a lot of sense to do what Vitesse / Microsemi / Microchip is doing, which is to copy the frame as-is to the CPU, and to also tell you, separately, what the classified VLAN is. For example, in vlan_filtering=0 mode, the classified VLAN will always be 1, regardless of how the frame is tagged, because VLAN awareness is truly turned off for the ingress port, and the port-based VLAN is always used. In this way, you have the most flexibility: you can either ignore the classified VLAN and proceed with just what was in the ingress skb (this way, you'll have a switch that is not VLAN-unaware, just "checking" as opposed to "secure". It has passed the ingress VLAN filter, but you still remember what the VLAN ID was.
Or you can have a completely VLAN-unaware switch, if you pop all VLANs that you can find in the skb, and add a hwaccel tag based on the classified VLAN, if it isn't equal to the pvid of the port. This is great for things like compatibility with a vlan_filtering=0 upper bridge which is what we're talking about.

Quoted 9 lines

Basically, this is what, I think, DSA tries to emulate with the rule of copying the flags of a user port VLAN to the CPU port too. If we had the API to request an "unmodified" VLAN (not egress-tagged, not egress-untagged, just the same as on ingress), I'm sure we'd be using that by default (useful when vlan_filtering is 1). Knowing what the classified VLAN was also can be very useful at times (like when vlan_filtering is 0), so if there was an API for that, I'm sure DSA would have used that as well. With no such APIs, we can only use approximations.

Quoted 7 lines

egress unmodified is what mv88e6xxx uses which is why I do not believe they have had the same issues that I had with vlan_filtering=0. For Broadcom switches there is not any option to have an umodified mode, the CPU port must have a valid VLAN membership (with vlan_filtering=1) and the egress untagged from the CPU port to the Ethernet MAC must match the expectations of the software data path behind.

Quoted 4 lines

So excepting mv88e6xxx and ocelot/felix, you are really in the same situation now with b53 and starfighter as everybody else is, am I not right? The "pvid and not untagged" VLAN is problematic for everybody in vlan_filtering=0 mode.

Yes, this is a problem for any switch that forces the CPU port to be tagged in all VLANs added to user-ports I would say be it a driver decision or hardware limitation.

The customers I support with bcm_sf2 mostly use the switch ports as standalone network devices (which reminds me I need to test your DSA RX filtering series, sigh) with 802.1Q uppers on top. Bridging works, but does not seem to be their main use case at all that comes from having migrated from 3 independent Ethernet MACs to an integrated switch, and now back to integrated Ethernet MACs.

Quoted 48 lines
Quoted 30 lines
Quoted 19 lines
Quoted 19 lines

I am about ready to submit the changes we discussed to b53, but I am still a bit uncomfortable with this part of the change because it will make the CPU port follow the untagged attribute of an user-facing port.

(quoted diff) +1 -1
@@ -1444,7 +1427,7 @@ void b53_vlan_add(struct dsa_switch *ds, int port,
                          untagged = true;
 
                  vl->members |= BIT(port);
-               if (untagged && !dsa_is_cpu_port(ds, port))
+               if (untagged)
                          vl->untag |= BIT(port);
                  else
                          vl->untag &= ~BIT(port);
@@ -1482,7 +1465,7 @@ int b53_vlan_del(struct dsa_switch *ds, int port,
                  if (pvid == vid)
                          pvid = b53_default_pvid(dev);
 
Quoted 10 lines

Review int b53_vlan_del(struct dsa_switch *ds, int port, · line 1470

Quoted 4 lines
(quoted diff) +1 -1
-               if (untagged && !dsa_is_cpu_port(ds, port))
+               if (untagged)
                          vl->untag &= ~(BIT(port));
 

Which is ok, I believe? I mean, that's the default DSA logic. If you think that isn't ok, we should change it at a more fundamental level. What we've been discussing so far is akin to your current setup, not to the one you're planning to change to, isn't it? Are there any problems with the new setup?

Quoted 3 lines

The change above is functional because the CPU port ends up being egress untagged in all of the bridge's default_pvid, whether vlan_filtering is 0 or 1 and that works.

Yeah, heard you about one mistake cancelling another one out.

Quoted 12 lines

The slightly confusing part is that a vlan_filtering=1 bridge accepts the default_pvid either tagged or untagged whereas a vlan_filtering=0 bridge does not, except for DHCP for instance. I would have to add a br0.1 802.1Q upper to take care of the default_pvid being egress tagged on the CPU port.

We could solve this in the DSA receive path, or the Broadcom tag receive path as you say since that is dependent on the tagging format and switch properties.

With Broadcom tags enabled now, all is well since we can differentiate traffic from different source ports using that 4 bytes tag.

Quoted 7 lines
Quoted 5 lines

Where this broke was when using a 802.1Q separation because all frames that egressed the CPU were egress tagged and it was no longer possible to differentiate whether they came from the LAN group in VID 1 or the WAN group in VID 2. But all of this should be a thing of the past now, ok, all is clear again now.

Or we could do this, what do you think?

Yes, this would be working, and I just tested it with the following delta on top of my b53 patch:

drivers/net/dsa/b53/b53_common.c +2 -2
index 46ac8875f870..73507cff3bc4 100644
@@ -1427,7 +1427,7 @@ void b53_vlan_add(struct dsa_switch *ds, int port,
                        untagged = true;
 
                vl->members |= BIT(port);
-               if (untagged)
+               if (untagged && !dsa_is_cpu_port(ds, port))
                        vl->untag |= BIT(port);
                else
                        vl->untag &= ~BIT(port);
@@ -1465,7 +1465,7 @@ int b53_vlan_del(struct dsa_switch *ds, int port,
                if (pvid == vid)
                        pvid = b53_default_pvid(dev);
 
-               if (untagged)
+               if (untagged && !dsa_is_cpu_port(ds, port))
                        vl->untag &= ~(BIT(port));
 
                b53_set_vlan_entry(dev, vid, vl);

and it works, thanks!

Quoted 22 lines

From 178a46f0f96555e17f3fcefa356e324a92dafab2 Mon Sep 17 00:00:00 2001
From: Vladimir Oltean <[email protected]>
Date: Fri, 11 Sep 2020 18:16:48 +0300
Subject: [PATCH] net: bridge: pop vlan from skb if filtering is disabled but
it's a pvid

Currently the bridge untags VLANs from its VLAN group in __allowed_ingress() only when VLAN filtering is enabled.

When installing a pvid in egress-tagged mode:

ip link add dev br0 type bridge vlan_filtering 0
ip link set swp0 master br0
bridge vlan del dev swp0 vid 1
bridge vlan add dev swp0 vid 1 pvid

When adding a VLAN on a DSA switch interface, DSA configures the VLAN membership of the CPU port using the same flags as swp0 (in this case "pvid and not untagged"), in an attempt to copy the frame as-is from ingress to the CPU.

Quoted 4 lines

However, in this case, the packet may arrive untagged on ingress, it will be pvid-tagged by the ingress port, and will be sent as egress-tagged towards the CPU. Otherwise stated, the CPU will see a VLAN tag where there was none to speak of on ingress.

We could also indicate that some DSA switch drivers systematically configure their CPU port to be tagged in all VLANs, so even in the following case:

ip link add dev br0 type bridge vlan_filtering 0
ip link set swp0 master br0

we will be receiving egress tagged frames for default_pvid because the CPU port is configured as egress tagged for that VLAN. In the case of a vlan_filtering=1, the default_pvid is accepted as tagged or untagged by the bridge master device. (something along those lines).

Quoted 11 lines

When vlan_filtering is 1, this is not a problem, as stated in the first paragraph, because __allowed_ingress() will pop it. But currently, when vlan_filtering is 0 and we have such a VLAN configuration, we need an 8021q upper (br0.1) to be able to ping over that VLAN.

Make the 2 cases (vlan_filtering 0 and 1) behave the same way as popping the pvid, if the skb happens to be tagged with it, when vlan_filtering is 0.

Quoted 33 lines
---
  net/bridge/br_vlan.c | 16 ++++++++++++++++
  1 file changed, 16 insertions(+)
net/bridge/br_vlan.c +16 -0
index d2b8737f9fc0..b1e7211bae51 100644
@@ -580,7 +580,23 @@ bool br_allowed_ingress(const struct net_bridge *br,
  	 * permitted.
  	 */
  	if (!br_opt_get(br, BROPT_VLAN_ENABLED)) {
+		u16 vid;
+
  		BR_INPUT_SKB_CB(skb)->vlan_filtered = false;
+
+		/* See comment in __allowed_ingress about how skb can end up
+		 * here not having a hwaccel tag
+		 */
+		if (unlikely(!skb_vlan_tag_present(skb) &&
+			     skb->protocol == br->vlan_proto)) {
+			skb = skb_vlan_untag(skb);
+			if (unlikely(!skb))
+				return false;
+		}
+
+		if (!br_vlan_get_tag(skb, &vid) && vid == br_get_pvid(vg))
+			__vlan_hwaccel_clear_tag(skb);
+
  		return true;
  	}
 
Signature · 1 line
Florian
author maintainer
#19 lore raw

Re: [PATCH net-next 4/4] net: dsa: set configure_vlan_while_not_filtering to true by default

Quoted 48 lines · Florian Fainelli
Quoted 12 lines · Vladimir Oltean
Quoted 12 lines

The slightly confusing part is that a vlan_filtering=1 bridge accepts the default_pvid either tagged or untagged whereas a vlan_filtering=0 bridge does not, except for DHCP for instance. I would have to add a br0.1 802.1Q upper to take care of the default_pvid being egress tagged on the CPU port.

We could solve this in the DSA receive path, or the Broadcom tag receive path as you say since that is dependent on the tagging format and switch properties.

With Broadcom tags enabled now, all is well since we can differentiate traffic from different source ports using that 4 bytes tag.

Quoted 7 lines
Quoted 5 lines

Where this broke was when using a 802.1Q separation because all frames that egressed the CPU were egress tagged and it was no longer possible to differentiate whether they came from the LAN group in VID 1 or the WAN group in VID 2. But all of this should be a thing of the past now, ok, all is clear again now.

Or we could do this, what do you think?

Yes, this would be working, and I just tested it with the following delta on top of my b53 patch:

drivers/net/dsa/b53/b53_common.c +2 -2
index 46ac8875f870..73507cff3bc4 100644
@@ -1427,7 +1427,7 @@ void b53_vlan_add(struct dsa_switch *ds, int port,
                        untagged = true;
 
                vl->members |= BIT(port);
-               if (untagged)
+               if (untagged && !dsa_is_cpu_port(ds, port))
                        vl->untag |= BIT(port);
                else
                        vl->untag &= ~BIT(port);
@@ -1465,7 +1465,7 @@ int b53_vlan_del(struct dsa_switch *ds, int port,
                if (pvid == vid)
                        pvid = b53_default_pvid(dev);
 
-               if (untagged)
+               if (untagged && !dsa_is_cpu_port(ds, port))
                        vl->untag &= ~(BIT(port));
 
                b53_set_vlan_entry(dev, vid, vl);
Quoted 2 lines

and it works, thanks!

I'm conflicted. So you prefer having the CPU port as egress-tagged?

Also, I think I'll also experiment with a version of this patch that is local to the DSA RX path. The bridge people may not like it, and as far as I understand, only DSA has this situation where pvid-tagged traffic may end up with a vlan tag on ingress.

Thanks,
-Vladimir

#20 lore raw

Re: [PATCH net-next 4/4] net: dsa: set configure_vlan_while_not_filtering to true by default

Quoted 47 lines · Vladimir Oltean
Quoted 46 lines · Florian Fainelli
Quoted 12 lines · Vladimir Oltean
Quoted 12 lines

The slightly confusing part is that a vlan_filtering=1 bridge accepts the default_pvid either tagged or untagged whereas a vlan_filtering=0 bridge does not, except for DHCP for instance. I would have to add a br0.1 802.1Q upper to take care of the default_pvid being egress tagged on the CPU port.

We could solve this in the DSA receive path, or the Broadcom tag receive path as you say since that is dependent on the tagging format and switch properties.

With Broadcom tags enabled now, all is well since we can differentiate traffic from different source ports using that 4 bytes tag.

Quoted 7 lines
Quoted 5 lines

Where this broke was when using a 802.1Q separation because all frames that egressed the CPU were egress tagged and it was no longer possible to differentiate whether they came from the LAN group in VID 1 or the WAN group in VID 2. But all of this should be a thing of the past now, ok, all is clear again now.

Or we could do this, what do you think?

Yes, this would be working, and I just tested it with the following delta on top of my b53 patch:

drivers/net/dsa/b53/b53_common.c +2 -2
index 46ac8875f870..73507cff3bc4 100644
@@ -1427,7 +1427,7 @@ void b53_vlan_add(struct dsa_switch *ds, int port,
                         untagged = true;
 
                 vl->members |= BIT(port);
-               if (untagged)
+               if (untagged && !dsa_is_cpu_port(ds, port))
                         vl->untag |= BIT(port);
                 else
                         vl->untag &= ~BIT(port);
@@ -1465,7 +1465,7 @@ int b53_vlan_del(struct dsa_switch *ds, int port,
                 if (pvid == vid)
                         pvid = b53_default_pvid(dev);
 
-               if (untagged)
+               if (untagged && !dsa_is_cpu_port(ds, port))
                         vl->untag &= ~(BIT(port));
 
Quoted 6 lines
Quoted 4 lines
drivers/net/dsa/b53/b53_common.c +0 -0
                 b53_set_vlan_entry(dev, vid, vl);

and it works, thanks!

I'm conflicted. So you prefer having the CPU port as egress-tagged?

I do, because I realized that some of the switches we support are still configured in DSA_TAG_NONE mode because the CPU port they chose is not Broadcom tag capable and there is an user out there who cares a lot about that case not to "break".

Quoted 5 lines

Also, I think I'll also experiment with a version of this patch that is local to the DSA RX path. The bridge people may not like it, and as far as I understand, only DSA has this situation where pvid-tagged traffic may end up with a vlan tag on ingress.

OK so something along the lines of: port is bridged, and bridge has vlan_filtering=0 and switch does egress tagging and VID is bridge's default_pvid then pop the tag?

Should this be a helper function that is utilized by the relevant tagger drivers or do you want this in dsa_switch_rcv()?

Signature · 1 line
Florian
#21 lore raw

Re: [PATCH net-next 4/4] net: dsa: set configure_vlan_while_not_filtering to true by default

Quoted 60 lines · Florian Fainelli
Quoted 47 lines · Vladimir Oltean
Quoted 46 lines · Florian Fainelli
Quoted 12 lines · Vladimir Oltean
Quoted 12 lines

The slightly confusing part is that a vlan_filtering=1 bridge accepts the default_pvid either tagged or untagged whereas a vlan_filtering=0 bridge does not, except for DHCP for instance. I would have to add a br0.1 802.1Q upper to take care of the default_pvid being egress tagged on the CPU port.

We could solve this in the DSA receive path, or the Broadcom tag receive path as you say since that is dependent on the tagging format and switch properties.

With Broadcom tags enabled now, all is well since we can differentiate traffic from different source ports using that 4 bytes tag.

Quoted 7 lines
Quoted 5 lines

Where this broke was when using a 802.1Q separation because all frames that egressed the CPU were egress tagged and it was no longer possible to differentiate whether they came from the LAN group in VID 1 or the WAN group in VID 2. But all of this should be a thing of the past now, ok, all is clear again now.

Or we could do this, what do you think?

Yes, this would be working, and I just tested it with the following delta on top of my b53 patch:

drivers/net/dsa/b53/b53_common.c +1 -1
index 46ac8875f870..73507cff3bc4 100644
@@ -1427,7 +1427,7 @@ void b53_vlan_add(struct dsa_switch *ds, int port,
                          untagged = true;
 
                  vl->members |= BIT(port);
-               if (untagged)
+               if (untagged && !dsa_is_cpu_port(ds, port))
                          vl->untag |= BIT(port);

                 else
                         vl->untag &= ~BIT(port);

drivers/net/dsa/b53/b53_common.c +1 -1
@@ -1465,7 +1465,7 @@ int b53_vlan_del(struct dsa_switch *ds, int port,
                  if (pvid == vid)
                          pvid = b53_default_pvid(dev);
 
-               if (untagged)
+               if (untagged && !dsa_is_cpu_port(ds, port))
                          vl->untag &= ~(BIT(port));
 
Quoted 6 lines
Quoted 4 lines
drivers/net/dsa/b53/b53_common.c +0 -0
                  b53_set_vlan_entry(dev, vid, vl);

and it works, thanks!

I'm conflicted. So you prefer having the CPU port as egress-tagged?

I do, because I realized that some of the switches we support are still configured in DSA_TAG_NONE mode because the CPU port they chose is not Broadcom tag capable and there is an user out there who cares a lot about that case not to "break".

Quoted 1 line
Quoted 8 lines
Quoted 4 lines

Also, I think I'll also experiment with a version of this patch that is local to the DSA RX path. The bridge people may not like it, and as far as I understand, only DSA has this situation where pvid-tagged traffic may end up with a vlan tag on ingress.

OK so something along the lines of: port is bridged, and bridge has vlan_filtering=0 and switch does egress tagging and VID is bridge's default_pvid then pop the tag?

Should this be a helper function that is utilized by the relevant tagger drivers or do you want this in dsa_switch_rcv()?

The two drivers that appear to be untagging the CPU port unconditionally are b53 and kzs9477.

Signature · 1 line
Florian
author maintainer
#22 lore raw

Re: [PATCH net-next 4/4] net: dsa: set configure_vlan_while_not_filtering to true by default

Quoted 7 lines · Florian Fainelli
Quoted 7 lines
Quoted 1 line

I'm conflicted. So you prefer having the CPU port as egress-tagged?

I do, because I realized that some of the switches we support are still configured in DSA_TAG_NONE mode because the CPU port they chose is not Broadcom tag capable and there is an user out there who cares a lot about that case not to "break".

Ok.

Quoted 9 lines
Quoted 9 lines
Quoted 4 lines

Also, I think I'll also experiment with a version of this patch that is local to the DSA RX path. The bridge people may not like it, and as far as I understand, only DSA has this situation where pvid-tagged traffic may end up with a vlan tag on ingress.

OK so something along the lines of: port is bridged, and bridge has vlan_filtering=0 and switch does egress tagging and VID is bridge's default_pvid then pop the tag?

Quoted 5 lines
Quoted 2 lines

Should this be a helper function that is utilized by the relevant tagger drivers or do you want this in dsa_switch_rcv()?

The two drivers that appear to be untagging the CPU port unconditionally are b53 and kzs9477.

So, a helper in DSA would look something like this:

include/net/dsa.h +1 -0
index 75c8fac82017..c0bb978c6ff7 100644
@@ -204,6 +204,7 @@ struct dsa_port {
 	const char		*mac;
 	struct device_node	*dn;
 	unsigned int		ageing_time;
+	int			pvid;
 	bool			vlan_filtering;
 	u8			stp_state;
 	struct net_device	*bridge_dev;
net/dsa/dsa2.c +2 -0
index 4a5e2832009b..84d47f838b4e 100644
@@ -273,6 +273,8 @@ static int dsa_port_setup(struct dsa_port *dp)
 	if (dp->setup)
 		return 0;
 
+	dp->pvid = -1;
+
 	switch (dp->type) {
 	case DSA_PORT_TYPE_UNUSED:
 		dsa_port_disable(dp);
net/dsa/dsa_priv.h +35 -0
index 2da656d984ef..d1dec232fc45 100644
@@ -7,6 +7,7 @@
 #ifndef __DSA_PRIV_H
 #define __DSA_PRIV_H
 
+#include <linux/if_bridge.h>
 #include <linux/phy.h>
 #include <linux/netdevice.h>
 #include <linux/netpoll.h>
@@ -194,6 +195,40 @@ dsa_slave_to_master(const struct net_device *dev)
 	return dp->cpu_dp->master;
 }
 
+/* If under a bridge with vlan_filtering=0, make sure to send pvid-tagged
+ * frames as untagged, since the bridge will not untag them.
+ */
+static inline struct sk_buff *dsa_untag_bridge_pvid(struct sk_buff *skb)
+{
+	struct dsa_port *dp = dsa_slave_to_port(skb->dev);
+	struct vlan_ethhdr *hdr = vlan_eth_hdr(skb);
+	struct net_device *br = dp->bridge_dev;
+	u16 proto;
+	int err;
+
+	if (!br || br_vlan_enabled(br))
+		return skb;
+
+	err = br_vlan_get_proto(br, &proto);
+	if (err)
+		return skb;
+
+	if (!skb_vlan_tag_present(skb) && hdr->h_vlan_proto == htons(proto)) {
+		skb = skb_vlan_untag(skb);
+		if (!skb)
+			return NULL;
+	}
+
+	if (!skb_vlan_tag_present(skb))
+		return skb;
+
+	/* Cannot use br_vlan_get_pvid here as that requires RTNL */
+	if (skb_vlan_tag_get_id(skb) == dp->pvid)
+		__vlan_hwaccel_clear_tag(skb);
+
+	return skb;
+}
+
 /* switch.c */
 int dsa_switch_register_notifier(struct dsa_switch *ds);
 void dsa_switch_unregister_notifier(struct dsa_switch *ds);
net/dsa/switch.c +28 -4
index 86c8dc5c32a0..9167cc678f41 100644
@@ -315,21 +315,45 @@ static int dsa_switch_vlan_add(struct dsa_switch *ds,
 	if (!ds->ops->port_vlan_add)
 		return 0;
 
-	for (port = 0; port < ds->num_ports; port++)
-		if (dsa_switch_vlan_match(ds, port, info))
+	for (port = 0; port < ds->num_ports; port++) {
+		if (dsa_switch_vlan_match(ds, port, info)) {
 			ds->ops->port_vlan_add(ds, port, info->vlan);
 
+			if (info->vlan->flags & BRIDGE_VLAN_INFO_PVID) {
+				struct dsa_port *dp = dsa_to_port(ds, port);
+
+				dp->pvid = info->vlan->vid_end;
+			}
+		}
+	}
+
 	return 0;
 }
 
 static int dsa_switch_vlan_del(struct dsa_switch *ds,
 			       struct dsa_notifier_vlan_info *info)
 {
+	int err;
+
 	if (!ds->ops->port_vlan_del)
 		return -EOPNOTSUPP;
 
-	if (ds->index == info->sw_index)
-		return ds->ops->port_vlan_del(ds, info->port, info->vlan);
+	if (ds->index == info->sw_index) {
+		const struct switchdev_obj_port_vlan *vlan = info->vlan;
+		struct dsa_port *dp = dsa_to_port(ds, info->port);
+		int vid;
+
+		err = ds->ops->port_vlan_del(ds, info->port, info->vlan);
+		if (err)
+			return err;
+
+		for (vid = vlan->vid_begin; vid <= vlan->vid_end; vid++) {
+			if (vid == dp->pvid) {
+				dp->pvid = -1;
+				break;
+			}
+		}
+	}
 
 	/* Do not deprogram the DSA links as they may be used as conduit
 	 * for other VLAN members in the fabric.

It's quite a bit more complex, I don't like it.

Thanks,
-Vladimir

#23 lore raw

Re: [PATCH net-next 4/4] net: dsa: set configure_vlan_while_not_filtering to true by default

In reply to Vladimir Oltean
Quoted 11 lines · Vladimir Oltean

From: Vladimir Oltean <[email protected]>

As explained in commit 54a0ed0df496 ("net: dsa: provide an option for drivers to always receive bridge VLANs"), DSA has historically been skipping VLAN switchdev operations when the bridge wasn't in vlan_filtering mode, but the reason why it was doing that has never been clear. So the configure_vlan_while_not_filtering option is there merely to preserve functionality for existing drivers. It isn't some behavior that drivers should opt into. Ideally, when all drivers leave this flag set, we can delete the dsa_port_skip_vlan_configuration() function.

Quoted 1 line

New drivers always seem to omit setting this flag, for some reason.

Yes, because it's not well documented, or is it? Before writing the hellcreek DSA driver, I've read dsa.rst documentation to find out what callback function should to what. Did I miss something?

Quoted 4 lines

So let's reverse the logic: the DSA core sets it by default to true before the .setup() callback, and legacy drivers can turn it off. This way, new drivers get the new behavior by default, unless they explicitly set the flag to false, which is more obvious during review.

Yeah, that behavior makes more sense to me. Thank you.

Thanks,
Kurt

author maintainer
#24 lore raw

Re: [PATCH net-next 4/4] net: dsa: set configure_vlan_while_not_filtering to true by default

Quoted 6 lines · Kurt Kanzenbach
Quoted 1 line · Vladimir Oltean

New drivers always seem to omit setting this flag, for some reason.

Yes, because it's not well documented, or is it? Before writing the hellcreek DSA driver, I've read dsa.rst documentation to find out what callback function should to what. Did I miss something?

Honestly, Documentation/networking/dsa/dsa.rst is out of date by quite a bit. And this trend of having boolean flags in struct dsa_switch started after the documentation stopped being updated.

But I didn't say it's your fault for not setting the flag, it is easy to miss, and that's what this patch is trying to improve.

Quoted 6 lines
Quoted 4 lines

So let's reverse the logic: the DSA core sets it by default to true before the .setup() callback, and legacy drivers can turn it off. This way, new drivers get the new behavior by default, unless they explicitly set the flag to false, which is more obvious during review.

Yeah, that behavior makes more sense to me. Thank you.

Ok, thanks.

-Vladimir

#25 lore raw

Re: [PATCH net-next 4/4] net: dsa: set configure_vlan_while_not_filtering to true by default

Hi Vladimir,

Quoted 11 lines · Vladimir Oltean
Quoted 6 lines · Kurt Kanzenbach
Quoted 1 line · Vladimir Oltean

New drivers always seem to omit setting this flag, for some reason.

Yes, because it's not well documented, or is it? Before writing the hellcreek DSA driver, I've read dsa.rst documentation to find out what callback function should to what. Did I miss something?

Honestly, Documentation/networking/dsa/dsa.rst is out of date by quite a bit. And this trend of having boolean flags in struct dsa_switch started after the documentation stopped being updated.

Maybe it would be good to document new flags when they're introduced :).

Quoted 4 lines

But I didn't say it's your fault for not setting the flag, it is easy to miss, and that's what this patch is trying to improve.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

So let's reverse the logic: the DSA core sets it by default to true before the .setup() callback, and legacy drivers can turn it off. This way, new drivers get the new behavior by default, unless they explicitly set the flag to false, which is more obvious during review.

Yeah, that behavior makes more sense to me. Thank you.

Ok, thanks.

Is this merged? I don't see it. Do I have to set `configure_vlan_while_not_filtering' explicitly to true for the next hellcreek version?

Thanks,
Kurt

author maintainer
#26 lore raw

Re: [PATCH net-next 4/4] net: dsa: set configure_vlan_while_not_filtering to true by default

Quoted 11 lines · Kurt Kanzenbach

Hi Vladimir,

Quoted 8 lines · Vladimir Oltean
Quoted 6 lines · Kurt Kanzenbach
Quoted 1 line · Vladimir Oltean

New drivers always seem to omit setting this flag, for some reason.

Yes, because it's not well documented, or is it? Before writing the hellcreek DSA driver, I've read dsa.rst documentation to find out what callback function should to what. Did I miss something?

Quoted 5 lines
Quoted 3 lines

Honestly, Documentation/networking/dsa/dsa.rst is out of date by quite a bit. And this trend of having boolean flags in struct dsa_switch started after the documentation stopped being updated.

Maybe it would be good to document new flags when they're introduced :).

Yup, will definitely do that when I resend.

Quoted 9 lines
Quoted 9 lines

But I didn't say it's your fault for not setting the flag, it is easy to miss, and that's what this patch is trying to improve.

Quoted 5 lines
Quoted 4 lines

So let's reverse the logic: the DSA core sets it by default to true before the .setup() callback, and legacy drivers can turn it off. This way, new drivers get the new behavior by default, unless they explicitly set the flag to false, which is more obvious during review.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Yeah, that behavior makes more sense to me. Thank you.

Ok, thanks.

Is this merged? I don't see it. Do I have to set `configure_vlan_while_not_filtering' explicitly to true for the next hellcreek version?

Yes, please set it to true. The refactoring change didn't get merged in time, I don't want it to interfere with your series.

Thanks,
-Vladimir

author maintainer
#27 lore raw

Re: [PATCH net-next 4/4] net: dsa: set configure_vlan_while_not_filtering to true by default

Hi Kurt,

Quoted 6 lines · Vladimir Oltean
Quoted 3 lines

Is this merged? I don't see it. Do I have to set `configure_vlan_while_not_filtering' explicitly to true for the next hellcreek version?

Yes, please set it to true. The refactoring change didn't get merged in time, I don't want it to interfere with your series.

Do you plan on resending hellcreek for 5.10?

Thanks,
-Vladimir

#28 lore raw

Re: [PATCH net-next 4/4] net: dsa: set configure_vlan_while_not_filtering to true by default

Hi Vladimir,

Quoted 11 lines · Vladimir Oltean

Hi Kurt,

Quoted 6 lines · Vladimir Oltean
Quoted 3 lines

Is this merged? I don't see it. Do I have to set `configure_vlan_while_not_filtering' explicitly to true for the next hellcreek version?

Yes, please set it to true. The refactoring change didn't get merged in time, I don't want it to interfere with your series.

Do you plan on resending hellcreek for 5.10?

I've implemented the configure_vlan_while_not_filtering behaviour yesterday with caching and lists like the sja driver does. It needs some testing and then I'll post it. Maybe next week.

Thanks,
Kurt

author maintainer
#29 lore raw

Re: [PATCH net-next 4/4] net: dsa: set configure_vlan_while_not_filtering to true by default

Quoted 1 line · Kurt Kanzenbach

Maybe next week.

The merge window opens next week. This means you can still resend as RFC, but it can only be accepted in net-next after ~2 weeks.

Thanks,
-Vladimir

author maintainer
#30 lore raw

Re: [PATCH net-next 4/4] net: dsa: set configure_vlan_while_not_filtering to true by default

Quoted 5 lines · Vladimir Oltean
Quoted 1 line · Kurt Kanzenbach

Maybe next week.

The merge window opens next week. This means you can still resend as RFC, but it can only be accepted in net-next after ~2 weeks.

False alarm, looks like we have an rc8. I guess that means you can resend some time this week.

Thanks,
-Vladimir