Skip to contentSkip to conversation

net: dsa: yt921x: Add DCB/QoS support

PATCH Superseded David Yang 2 participants 5 messages Jan 25 – Jan 26

Subsystems (4)

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

David Yang

author maintainer
#0 lore raw

v3 cover net: dsa: yt921x: Add DCB/QoS support

This series add DCB/QoS support to the driver.

v2: https://lore.kernel.org/r/[email protected]
- make DCB support optional
- refine with enum yt921x_app_selector
- add missing dscp_prio_mapping_is_global
- fix pcp support
v1: https://lore.kernel.org/r/[email protected]
- rebase

David Yang (3):
net: dsa: tag_yt921x: fix priority support
net: dsa: yt921x: Refactor VLAN awareness setting
net: dsa: yt921x: Add DCB/QoS support

 drivers/net/dsa/Kconfig  |   1 +
 drivers/net/dsa/yt921x.c | 260 +++++++++++++++++++++++++++++++++++++--
 drivers/net/dsa/yt921x.h |  52 ++++++--
 net/dsa/tag_yt921x.c     |   8 +-
 4 files changed, 300 insertions(+), 21 deletions(-)
Signature · 1 line
2.51.0
author maintainer
#1 lore raw

PATCH v3 1/3 net: dsa: tag_yt921x: fix priority support

The packet priority is embedded in the rx tag. It defaults to 0, but adding DCB support to the switch driver will break the tag driver by setting it to non-zero.

---
 net/dsa/tag_yt921x.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
net/dsa/tag_yt921x.c +6 -2
index 6bbfd42dc5df..b93715a057c7 100644
@@ -17,7 +17,8 @@
  *   2: Rx Port
  *     15b: Rx Port Valid
  *     14b-11b: Rx Port
- *     10b-0b: Cmd?
+ *     10b-8b: Priority
+ *     7b-0b: Cmd
  *   2: Tx Port(s)
  *     15b: Tx Port(s) Valid
  *     10b-0b: Tx Port(s) Mask
@@ -33,7 +34,8 @@
 
 #define YT921X_TAG_PORT_EN		BIT(15)
 #define YT921X_TAG_RX_PORT_M		GENMASK(14, 11)
-#define YT921X_TAG_RX_CMD_M		GENMASK(10, 0)
+#define YT921X_TAG_RX_PRIO_M		GENMASK(10, 8)
+#define YT921X_TAG_RX_CMD_M		GENMASK(7, 0)
 #define  YT921X_TAG_RX_CMD(x)			FIELD_PREP(YT921X_TAG_RX_CMD_M, (x))
 #define  YT921X_TAG_RX_CMD_FORWARDED		0x80
 #define  YT921X_TAG_RX_CMD_UNK_UCAST		0xb2
@@ -98,6 +100,8 @@ yt921x_tag_rcv(struct sk_buff *skb, struct net_device *netdev)
 		return NULL;
 	}
 
+	skb->priority = FIELD_GET(YT921X_TAG_RX_PRIO_M, rx);
+
 	cmd = FIELD_GET(YT921X_TAG_RX_CMD_M, rx);
 	switch (cmd) {
 	case YT921X_TAG_RX_CMD_FORWARDED:
Signature · 1 line
2.51.0
reviewer
#2 lore raw

Re: [net-next,v3,1/3] net: dsa: tag_yt921x: fix priority support

This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.

For local reproduction steps see https://netdev-ai.bots.linux.dev/ai-local.html
---
net: dsa: yt921x: Add DCB/QoS support

This commit adds DCB/QoS support to the yt921x DSA switch driver, setting up global DSCP/PCP priority mappings and adding related DCB methods.

Quoted 4 lines
drivers/net/dsa/yt921x.c +0 -0
index af8464c42b51..87e33d0df4ac 100644

[ ... ]

Quoted 21 lines
drivers/net/dsa/yt921x.c +21 -0
+/* Not "port" - DSCP mapping is global */
+static int __maybe_unused
+yt921x_dsa_port_get_dscp_prio(struct dsa_switch *ds, int port, u8 dscp)
+{
+	struct yt921x_priv *priv = to_yt921x_priv(ds);
+	u32 val;
+	int res;
+
+	mutex_lock(&priv->reg_lock);
+	res = yt921x_reg_read(priv, YT921X_IPM_DSCPn(dscp), &val);
+	mutex_unlock(&priv->reg_lock);
+
+	if (res)
+		return res;
+
+	return FIELD_GET(YT921X_IPM_PRIO_M, val);
+}
+
+static int __maybe_unused
+yt921x_dsa_port_del_dscp_prio(struct dsa_switch *ds, int port, u8 dscp, u8 prio)
+{

drivers/net/dsa/yt921x.c

Quoted 10 lines
drivers/net/dsa/yt921x.c +10 -0
+	struct yt921x_priv *priv = to_yt921x_priv(ds);
+	int res;
+
+	mutex_lock(&priv->reg_lock);
+	res = yt921x_reg_write(priv, YT921X_IPM_DSCPn(dscp),
+			       YT921X_IPM_PRIO(IEEE8021Q_TT_BK));
+	mutex_unlock(&priv->reg_lock);
+
+	return res;
+}

Should yt921x_dsa_port_del_dscp_prio() check the prio parameter before resetting the DSCP mapping? The ocelot driver (ocelot_port_del_dscp_prio in drivers/net/ethernet/mscc/ocelot.c) has a comment explaining that during a "dcb app replace" command, the new entry is added first, then the old entry is deleted. If the delete operation ignores the prio parameter, it will incorrectly reset the newly-added mapping instead of only deleting when the current priority matches the old one.

The ksz driver also checks this condition in ksz_port_del_dscp_prio().

Without this check, the sequence for "dcb app replace ... dscp X prio N" followed by "dcb app replace ... dscp X prio M" would be:
1. add dscp X -> prio M (correct)
2. del dscp X, prio N (but code ignores prio N and resets to BK)
3. result: dscp X -> BK instead of prio M

Perhaps something like this is needed:

if (yt921x_dsa_port_get_dscp_prio(ds, port, dscp) != prio)

      return 0;
author maintainer
#3 lore raw

PATCH v3 2/3 net: dsa: yt921x: Refactor VLAN awareness setting

In reply to David Yang

Create a helper function to centralize the logic for enabling and disabling VLAN awareness on a port.

---
 drivers/net/dsa/yt921x.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)
drivers/net/dsa/yt921x.c +14 -9
index a4b346ddf8dd..880e3b5966f8 100644
@@ -1768,6 +1768,18 @@ yt921x_dsa_port_mdb_add(struct dsa_switch *ds, int port,
 	return res;
 }
 
+static int
+yt921x_port_set_vlan_aware(struct yt921x_priv *priv, int port, bool vlan_aware)
+{
+	u32 ctrl;
+
+	if (!vlan_aware)
+		ctrl = 0;
+	else
+		ctrl = YT921X_PORT_IGR_TPIDn_CTAG(0);
+	return yt921x_reg_write(priv, YT921X_PORTn_IGR_TPID(port), ctrl);
+}
+
 static int
 yt921x_port_set_pvid(struct yt921x_priv *priv, int port, u16 vid)
 {
@@ -1818,13 +1830,7 @@ yt921x_vlan_filtering(struct yt921x_priv *priv, int port, bool vlan_filtering)
 		return res;
 
 	/* Turn on / off VLAN awareness */
-	mask = YT921X_PORT_IGR_TPIDn_CTAG_M;
-	if (!vlan_filtering)
-		ctrl = 0;
-	else
-		ctrl = YT921X_PORT_IGR_TPIDn_CTAG(0);
-	res = yt921x_reg_update_bits(priv, YT921X_PORTn_IGR_TPID(port),
-				     mask, ctrl);
+	res = yt921x_port_set_vlan_aware(priv, port, vlan_filtering);
 	if (res)
 		return res;
 
@@ -2021,8 +2027,7 @@ static int yt921x_userport_standalone(struct yt921x_priv *priv, int port)
 		return res;
 
 	/* Turn off VLAN awareness */
-	mask = YT921X_PORT_IGR_TPIDn_CTAG_M;
-	res = yt921x_reg_clear_bits(priv, YT921X_PORTn_IGR_TPID(port), mask);
+	res = yt921x_port_set_vlan_aware(priv, port, false);
 	if (res)
 		return res;
 
Signature · 1 line
2.51.0
author maintainer
#4 lore raw

PATCH v3 3/3 net: dsa: yt921x: Add DCB/QoS support

In reply to David Yang

Set up global DSCP/PCP priority mappings and add related DCB methods.

---
 drivers/net/dsa/Kconfig  |   1 +
 drivers/net/dsa/yt921x.c | 239 ++++++++++++++++++++++++++++++++++++++-
 drivers/net/dsa/yt921x.h |  52 +++++++--
 3 files changed, 281 insertions(+), 11 deletions(-)
drivers/net/dsa/Kconfig +1 -0
index 7eb301fd987d..24c37cbf70d7 100644
@@ -158,6 +158,7 @@ config NET_DSA_VITESSE_VSC73XX_PLATFORM
 config NET_DSA_YT921X
 	tristate "Motorcomm YT9215 ethernet switch chip support"
 	select NET_DSA_TAG_YT921X
+	select NET_IEEE8021Q_HELPERS if DCB
 	help
 	  This enables support for the Motorcomm YT9215 ethernet switch
 	  chip.
drivers/net/dsa/yt921x.c +238 -1

306 lines not on this page · raw message

drivers/net/dsa/yt921x.h +42 -10

92 lines not on this page · raw message

Signature · 1 line
2.51.0