Netdev Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Ben Hutchings <ben.hutchings@mind.be>
To: Woojung Huh <woojung.huh@microchip.com>, UNGLinuxDriver@microchip.com
Cc: netdev@vger.kernel.org
Subject: [PATCH net 3/7] net: dsa: microchip: ksz8795: Reject unsupported VLAN configuration
Date: Tue, 10 Aug 2021 00:59:37 +0200	[thread overview]
Message-ID: <20210809225936.GD17207@cephalopod> (raw)
In-Reply-To: <20210809225753.GA17207@cephalopod>

The switches supported by ksz8795 only have a per-port flag for Tag
Removal.  This means it is not possible to support both tagged and
untagged VLANs on the same port.  Reject attempts to add a VLAN that
requires the flag to be changed, unless there are no VLANs currently
configured.

VID 0 is excluded from this check since it is untagged regardless of
the state of the flag.

On the CPU port we could support tagged and untagged VLANs at the same
time.  This will be enabled by a later patch.

Fixes: e66f840c08a2 ("net: dsa: ksz: Add Microchip KSZ8795 DSA driver")
Signed-off-by: Ben Hutchings <ben.hutchings@mind.be>
---
 drivers/net/dsa/microchip/ksz8795.c    | 27 +++++++++++++++++++++++++-
 drivers/net/dsa/microchip/ksz_common.h |  1 +
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c
index 95842f7b2f1b..045786f4e29e 100644
--- a/drivers/net/dsa/microchip/ksz8795.c
+++ b/drivers/net/dsa/microchip/ksz8795.c
@@ -1140,13 +1140,38 @@ static int ksz8_port_vlan_add(struct dsa_switch *ds, int port,
 {
 	bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
 	struct ksz_device *dev = ds->priv;
+	struct ksz_port *p = &dev->ports[port];
 	u16 data, new_pvid = 0;
 	u8 fid, member, valid;
 
 	if (ksz_is_ksz88x3(dev))
 		return -ENOTSUPP;
 
-	ksz_port_cfg(dev, port, P_TAG_CTRL, PORT_REMOVE_TAG, untagged);
+	/* If a VLAN is added with untagged flag different from the
+	 * port's Remove Tag flag, we need to change the latter.
+	 * Ignore VID 0, which is always untagged.
+	 */
+	if (untagged != p->remove_tag && vlan->vid != 0) {
+		unsigned int vid;
+
+		/* Reject attempts to add a VLAN that requires the
+		 * Remove Tag flag to be changed, unless there are no
+		 * other VLANs currently configured.
+		 */
+		for (vid = 1; vid < dev->num_vlans; ++vid) {
+			/* Skip the VID we are going to add or reconfigure */
+			if (vid == vlan->vid)
+				continue;
+
+			ksz8_from_vlan(dev, dev->vlan_cache[vid].table[0],
+				       &fid, &member, &valid);
+			if (valid && (member & BIT(port)))
+				return -EINVAL;
+		}
+
+		ksz_port_cfg(dev, port, P_TAG_CTRL, PORT_REMOVE_TAG, untagged);
+		p->remove_tag = untagged;
+	}
 
 	ksz8_r_vlan_table(dev, vlan->vid, &data);
 	ksz8_from_vlan(dev, data, &fid, &member, &valid);
diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h
index 6afbb41ad39e..1597c63988b4 100644
--- a/drivers/net/dsa/microchip/ksz_common.h
+++ b/drivers/net/dsa/microchip/ksz_common.h
@@ -27,6 +27,7 @@ struct ksz_port_mib {
 struct ksz_port {
 	u16 member;
 	u16 vid_member;
+	bool remove_tag;		/* Remove Tag flag set, for ksz8795 only */
 	int stp_state;
 	struct phy_device phydev;
 
-- 
2.20.1


  parent reply	other threads:[~2021-08-09 22:59 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-09 22:57 [PATCH net 0/7] ksz8795 VLAN fixes Ben Hutchings
2021-08-09 22:59 ` [PATCH net 1/7] net: dsa: microchip: Fix ksz_read64() Ben Hutchings
2021-08-09 22:59 ` [PATCH net 2/7] net: dsa: microchip: ksz8795: Fix PVID tag insertion Ben Hutchings
2021-08-09 22:59 ` Ben Hutchings [this message]
2021-08-09 22:59 ` [PATCH net 4/7] net: dsa: microchip: ksz8795: Fix VLAN untagged flag change on deletion Ben Hutchings
2021-08-09 22:59 ` [PATCH net 5/7] net: dsa: microchip: ksz8795: Use software untagging on CPU port Ben Hutchings
2021-08-09 23:00 ` [PATCH net 6/7] net: dsa: microchip: ksz8795: Fix VLAN filtering Ben Hutchings
2021-08-09 23:00 ` [PATCH net 7/7] net: dsa: microchip: ksz8795: Don't use phy_port_cnt in VLAN table lookup Ben Hutchings
2021-08-10  0:03 ` [PATCH net 0/7] ksz8795 VLAN fixes Jakub Kicinski
2021-08-10  9:00 ` patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210809225936.GD17207@cephalopod \
    --to=ben.hutchings@mind.be \
    --cc=UNGLinuxDriver@microchip.com \
    --cc=netdev@vger.kernel.org \
    --cc=woojung.huh@microchip.com \
    --subject='Re: [PATCH net 3/7] net: dsa: microchip: ksz8795: Reject unsupported VLAN configuration' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).