Netdev List
 help / color / mirror / Atom feed
From: David Yang <mmyangfl@gmail.com>
To: netdev@vger.kernel.org
Cc: David Yang <mmyangfl@gmail.com>, Andrew Lunn <andrew@lunn.ch>,
	Vladimir Oltean <olteanv@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH net v2 4/4] net: dsa: motorcomm: Use VID 0 as the unaware PVID
Date: Tue, 17 Nov 2026 00:01:04 +0800	[thread overview]
Message-ID: <20261116160107.1351198-5-mmyangfl@gmail.com> (raw)
In-Reply-To: <20261116160107.1351198-1-mmyangfl@gmail.com>

The hardware classifies untagged and priority-tagged frames to the
port's PVID before the VLAN table lookup, and the FDB lookup key equals
the classified VID (measured on YT9215S).

The driver assigned PVID 4095 to the VLAN-unaware ports, while switchdev
reports the bridge's FDB entries with VID 0. These entries were then
installed under FID 0 and could never be hit by the hardware lookups.
Dynamic entries learnt under VID 4095, if any, took effect instead.

Lift the restriction on VLAN 0. Keep VLAN 0 out of the generic VLAN
add/delete paths, otherwise 8021q's automatic VLAN 0 filtering would
leave a stray CPU port bit behind.

Use VLAN 0 as the PVID of the VLAN-unaware ports. Program the PVID when
a port joins a VLAN-unaware bridge since DSA does not necessarily call
.port_vlan_filtering().

The standalone default of 4095 stays, so mislearnt entries, if any,
would not pollute the bridge FDB.

Fixes: 186623f4aa72 ("net: dsa: yt921x: Add support for Motorcomm YT921x")
Signed-off-by: David Yang <mmyangfl@gmail.com>
---
 drivers/net/dsa/motorcomm/chip.c | 44 +++++++++++++++++++-------------
 1 file changed, 26 insertions(+), 18 deletions(-)

diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c
index d84d863080ce..aa4d6a0c930c 100644
--- a/drivers/net/dsa/motorcomm/chip.c
+++ b/drivers/net/dsa/motorcomm/chip.c
@@ -79,7 +79,7 @@ static const struct yt921x_info yt921x_infos[] = {
 	{}
 };
 
-#define YT921X_VID_UNWARE	4095
+#define YT921X_VID_STANDALONE	4095
 
 struct yt921x_reg_mdio {
 	struct mii_bus *bus;
@@ -960,8 +960,10 @@ yt921x_vlan_filtering(struct yt921x_priv *priv, int port, bool vlan_filtering)
 
 	brport = dsa_port_to_bridge_port(dp);
 
-	if (!brport || !vlan_filtering)
-		pvid = YT921X_VID_UNWARE;
+	if (!brport)
+		pvid = YT921X_VID_STANDALONE;
+	else if (!vlan_filtering)
+		pvid = 0;
 	else
 		br_vlan_get_pvid(brport, &pvid);
 	res = yt921x_port_set_pvid(priv, port, pvid);
@@ -1029,8 +1031,7 @@ yt921x_pvid_clear(struct yt921x_priv *priv, int port)
 
 	vlan_filtering = dsa_port_is_vlan_filtering(dp);
 
-	res = yt921x_port_set_pvid(priv, port,
-				   vlan_filtering ? 0 : YT921X_VID_UNWARE);
+	res = yt921x_port_set_pvid(priv, port, 0);
 	if (res)
 		return res;
 
@@ -1098,6 +1099,8 @@ yt921x_dsa_port_vlan_del(struct dsa_switch *ds, int port,
 
 	if (dsa_is_cpu_port(ds, port))
 		return 0;
+	if (!vid)
+		return 0;
 
 	mutex_lock(&priv->reg_lock);
 	do {
@@ -1135,6 +1138,11 @@ yt921x_dsa_port_vlan_add(struct dsa_switch *ds, int port,
 	 */
 	if (dsa_is_cpu_port(ds, port))
 		return 0;
+	/* VID 0 is the VLAN-unaware bridges' FDB domain; nothing to program,
+	 * keep the entry at reset defaults
+	 */
+	if (!vid)
+		return 0;
 
 	mutex_lock(&priv->reg_lock);
 	do {
@@ -1187,7 +1195,7 @@ static int yt921x_userport_standalone(struct yt921x_priv *priv, int port)
 	/* Unrelated since learning is off and all packets are trapped;
 	 * set it anyway
 	 */
-	res = yt921x_port_set_pvid(priv, port, YT921X_VID_UNWARE);
+	res = yt921x_port_set_pvid(priv, port, YT921X_VID_STANDALONE);
 	if (res)
 		return res;
 
@@ -1285,7 +1293,8 @@ static int yt921x_bridge_leave(struct yt921x_priv *priv, int port)
 }
 
 static int
-yt921x_bridge_join(struct yt921x_priv *priv, int port, u16 ports_mask)
+yt921x_bridge_join(struct yt921x_priv *priv, int port, u16 ports_mask,
+		   bool vlan_filtering)
 {
 	int res;
 
@@ -1297,6 +1306,14 @@ yt921x_bridge_join(struct yt921x_priv *priv, int port, u16 ports_mask)
 	if (res)
 		return res;
 
+	if (!vlan_filtering) {
+		/* DSA may shortcut .port_vlan_filtering(), leaving stale PVID
+		 */
+		res = yt921x_port_set_pvid(priv, port, 0);
+		if (res)
+			return res;
+	}
+
 	return 0;
 }
 
@@ -1427,7 +1444,8 @@ yt921x_dsa_port_bridge_join(struct dsa_switch *ds, int port,
 	mutex_lock(&priv->reg_lock);
 	pp->isolated = br_port_flag_is_set(brport_dev, BR_ISOLATED);
 	pp->hairpin = br_port_flag_is_set(brport_dev, BR_HAIRPIN_MODE);
-	res = yt921x_bridge_join(priv, port, ports_mask);
+	res = yt921x_bridge_join(priv, port, ports_mask,
+				 br_vlan_enabled(bridge.dev));
 	mutex_unlock(&priv->reg_lock);
 
 	return res;
@@ -2277,7 +2295,6 @@ static int yt921x_chip_setup_dsa(struct yt921x_priv *priv)
 {
 	struct dsa_switch *ds = &priv->ds;
 	unsigned long cpu_ports_mask;
-	u32 ctrls[2];
 	u32 ctrl;
 	int port;
 	int res;
@@ -2335,15 +2352,6 @@ static int yt921x_chip_setup_dsa(struct yt921x_priv *priv)
 	if (res)
 		return res;
 
-	/* Tagged VID 0 should be treated as untagged, which confuses the
-	 * hardware a lot
-	 */
-	ctrls[0] = YT921X_VLAN_CTRLa_LEARN_DIS | YT921X_VLAN_CTRLa_PORTS_M;
-	ctrls[1] = 0;
-	res = yt921x_reg64_write(priv, YT921X_VLANn_CTRL(0), ctrls);
-	if (res)
-		return res;
-
 	return 0;
 }
 
-- 
2.53.0


      parent reply	other threads:[~2026-11-16 16:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 16:01 [PATCH net v2 0/4] net: dsa: motorcomm: FDB fixup David Yang
2026-11-16 16:01 ` [PATCH net v2 1/4] net: dsa: motorcomm: Do not inherit ports from dynamic FDB entries David Yang
2026-11-16 16:01 ` [PATCH net v2 2/4] net: dsa: motorcomm: Rewrite FDB entry on port migration David Yang
2026-11-16 16:01 ` [PATCH net v2 3/4] net: dsa: motorcomm: Read the port PVID instead of bridge's David Yang
2026-11-16 16:01 ` David Yang [this message]

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=20261116160107.1351198-5-mmyangfl@gmail.com \
    --to=mmyangfl@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.com \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox