Skip to contentSkip to conversation

net: dsa: motorcomm: TC offload follow-ups

PATCH Applied David Yang 3 participants 9 messages Oct 9 – Oct 17

Subsystems (4)
lore
Share & tools
lore

David Yang

author maintainer
#0 lore raw

v3 cover net: dsa: motorcomm: TC offload follow-ups

This series continues the traffic control work on the Motorcomm YT9215S DSA driver: it reorganizes the offload code and then adds ACL enablement on demand and flower priority mapping.

v3:
- rebase
- reword commit messages and comments
- fix cleanup path in acl_add()
v2: https://lore.kernel.org/r/[email protected]
- move type casting helper into chip.h
- remove flow statistics and broadcast/multicast policers
v1: https://lore.kernel.org/r/[email protected]

David Yang (4):
net: dsa: motorcomm: Split TC module
net: dsa: motorcomm: Use NSEC_PER_SEC
net: dsa: motorcomm: Enable ACL on demand
net: dsa: motorcomm: Add TC prio support

 drivers/net/dsa/motorcomm/Makefile |    1 +
 drivers/net/dsa/motorcomm/chip.c   | 1662 ++--------------------------
 drivers/net/dsa/motorcomm/chip.h   |  352 +-----
 drivers/net/dsa/motorcomm/tc.c     | 1583 ++++++++++++++++++++++++++
 drivers/net/dsa/motorcomm/tc.h     |  381 +++++++
 5 files changed, 2059 insertions(+), 1920 deletions(-)
 create mode 100644 drivers/net/dsa/motorcomm/tc.c
 create mode 100644 drivers/net/dsa/motorcomm/tc.h
Signature · 1 line
2.53.0
author maintainer
#1 lore raw

PATCH v3 1/4 net: dsa: motorcomm: Split TC module

Move the traffic control code from chip.c into a separate tc.c, to reduce the length of chip.c.

---
 drivers/net/dsa/motorcomm/Makefile |    1 +
 drivers/net/dsa/motorcomm/chip.c   | 1662 ++--------------------------
 drivers/net/dsa/motorcomm/chip.h   |  350 +-----
 drivers/net/dsa/motorcomm/tc.c     | 1496 +++++++++++++++++++++++++
 drivers/net/dsa/motorcomm/tc.h     |  380 +++++++
 5 files changed, 1969 insertions(+), 1920 deletions(-)
 create mode 100644 drivers/net/dsa/motorcomm/tc.c
 create mode 100644 drivers/net/dsa/motorcomm/tc.h
drivers/net/dsa/motorcomm/Makefile +1 -0
index 9c1e3d538d21..9eaa59f699e8 100644
@@ -6,3 +6,4 @@ yt921x-objs += mdio_bus.o
 yt921x-objs += mib.o
 yt921x-objs += pcs-921x.o
 yt921x-objs += smi.o
+yt921x-objs += tc.o
drivers/net/dsa/motorcomm/chip.c +82 -1580

1,752 lines not on this page · raw message

drivers/net/dsa/motorcomm/chip.h +10 -340

392 lines not on this page · raw message

drivers/net/dsa/motorcomm/tc.c new file +1496 -0

852 lines not on this page · raw message

drivers/net/dsa/motorcomm/tc.h new file +380 -0

380 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.53.0

Part of the diff is not shown here. View the raw message.

author maintainer
#2 lore raw

PATCH v3 2/4 net: dsa: motorcomm: Use NSEC_PER_SEC

In reply to David Yang

Get rid of magic numbers.

---
 drivers/net/dsa/motorcomm/tc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/dsa/motorcomm/tc.c +3 -3
index 433a428ed070..be3321df8868 100644
@@ -25,14 +25,14 @@ static u32 rate2token(u64 rate, unsigned int slot_ns, int unit, int C)
 {
 	int e = 2 * unit + C + YT921X_TOKEN_RATE_C;
 
-	return div_u64(ldexpu64(slot_ns * rate, -e), 1000000000);
+	return div_u64(ldexpu64(slot_ns * rate, -e), NSEC_PER_SEC);
 }
 
 static u64 token2rate(u32 token, unsigned int slot_ns, int unit, int C)
 {
 	int e = 2 * unit + C + YT921X_TOKEN_RATE_C;
 
-	return div_u64(ldexpu64(mul_u32_u32(1000000000, token), e), slot_ns);
+	return div_u64(ldexpu64(mul_u32_u32(NSEC_PER_SEC, token), e), slot_ns);
 }
 
 /* burst = 2^C * token * 4^unit */
@@ -83,7 +83,7 @@ yt921x_marker_tfm(struct yt921x_marker *marker, u64 rate, u64 burst,
 	}
 
 	/* Check for matching burst */
-	burst_est = div_u64(slot_ns * rate, 1000000000);
+	burst_est = div_u64(slot_ns * rate, NSEC_PER_SEC);
 	burst_sug = burst_est;
 	if (flags & YT921X_MARKER_PKT_MODE)
 		burst_sug++;
Signature · 1 line
2.53.0
author maintainer
#3 lore raw

PATCH v3 3/4 net: dsa: motorcomm: Enable ACL on demand

In reply to David Yang

Track the usage of ACL rules and enable it per port only when it is actually used. This is aligned with ODM recommendations and helps reduce latency.

---
 drivers/net/dsa/motorcomm/chip.h |  2 +
 drivers/net/dsa/motorcomm/tc.c   | 70 ++++++++++++++++++++++++++++----
 2 files changed, 64 insertions(+), 8 deletions(-)
drivers/net/dsa/motorcomm/chip.h +2 -0
index 012de4f444f5..7047ad98f431 100644
@@ -462,6 +462,8 @@ struct yt921x_port {
 	/* BR_ISOLATED */
 	bool isolated:1;
 
+	unsigned short acl_cnt;
+
 #if IS_ENABLED(CONFIG_NET_DSA_YT921X_LEDS)
 	unsigned char led_duty;
 	unsigned short led_cycle;
drivers/net/dsa/motorcomm/tc.c +62 -8

142 lines not on this page · raw message

Signature · 1 line
2.53.0
#4 lore raw

Re: [PATCH net-next v3 3/4] net: dsa: motorcomm: Enable ACL on demand

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] yt921x_acl_add() in drivers/net/dsa/motorcomm/tc.c writes YT921X_ACL_PORT before the rule is programmed.

--

net: dsa: motorcomm: Enable ACL on demand

This commit adds a per-port acl_cnt to struct yt921x_port. It now writes YT921X_ACL_PORT only for ports that have ACL rules, instead of enabling ACL on all ports at setup time. The register is updated from yt921x_acl_add() and yt921x_acl_del() when a port's rule count goes from zero to non-zero or back.

Quoted 4 lines
drivers/net/dsa/motorcomm/tc.c +0 -0
index be3321df88683..a302016912b5f 100644

[ ... ]

Quoted 31 lines
drivers/net/dsa/motorcomm/tc.c +18 -1
@@ -1312,21 +1349,39 @@ yt921x_acl_add(struct yt921x_priv *priv,
 	else
 		aclrule->action[0] &= ~YT921X_ACL_ACTa_METER_EN;
 
+	/* Activate ACL if needed */
+	ctrl = 0;
+	m = FIELD_GET(YT921X_ACL_KEYb_SPORTS_M, ruleext->r.entries[0].key[1]);
+	for_each_set_bit(o, &m, YT921X_PORT_NUM)
+		if (!priv->ports[o].acl_cnt)
+			ctrl |= YT921X_ACL_PORT_PORTn(o);
+	if (ctrl) {
+		ctrl |= yt921x_acl_activated_ports(priv);
+		res = yt921x_reg_write(priv, YT921X_ACL_PORT, ctrl);
+		if (res)
+			goto err;
+	}
+
 	/* Write rules */
 	aclblk->rules[binid] = aclrule;
 	res = yt921x_acl_commit(priv, entid, aclrule->mask);
 	if (res) {
 		aclblk->rules[binid] = NULL;
-		kvfree(aclrule);
 		goto err;
 	}
 
+	/* Bookkeeping */
+	m = FIELD_GET(YT921X_ACL_KEYb_SPORTS_M, ruleext->r.entries[0].key[1]);
+	for_each_set_bit(o, &m, YT921X_PORT_NUM)
+		priv->ports[o].acl_cnt++;
+

drivers/net/dsa/motorcomm/tc.c yt921x_acl_add(struct yt921x_priv *priv, · line 1387

Quoted 10 lines
drivers/net/dsa/motorcomm/tc.c +1 -0
 	if (meterid < YT921X_METER_NUM)
 		set_bit(meterid, priv->meters_map);
 	priv->acl_masks[blkid] |= aclrule->mask;
 	return 0;
 
 err:
+	kvfree(aclrule);
 	if (!priv->acl_masks[blkid]) {
 		kvfree(aclblk);
 		priv->acl_blks[blkid] = NULL;

[Severity: Low]
If yt921x_acl_commit() fails here, should YT921X_ACL_PORT be restored before returning?

The enable bits for the new rule's source ports have already been written by then. The err path frees aclrule (and aclblk if it is now empty), but it doesn't write YT921X_ACL_PORT back to yt921x_acl_activated_ports(priv).

acl_cnt++ only runs on success, so the driver counts zero rules on those ports while the hardware still has ACL lookup enabled on them. yt921x_acl_find() can no longer find the rejected rule, so it can't be deleted to clean this up.

yt921x_acl_commit() writes several registers in sequence (ACT, BLK_CMD modify, KEY/MASK, BLK_KEEP, ACLn_ENTRY, BLK_CMD commit), and any of those writes can fail.

yt921x_acl_del() can end up in the same state:

	if (refresh_en) {
		ctrl = yt921x_acl_activated_ports(priv);
		res = yt921x_reg_write(priv, YT921X_ACL_PORT, ctrl);
		if (res)
			ret = res;
	}

If this write fails after the last rule on a port took acl_cnt to 0, the rule is still freed. The enable bit stays set, and a second delete returns -ENOENT.

After either failure, YT921X_ACL_PORT stays wider than yt921x_acl_activated_ports() until some later add or delete happens to rewrite it. If that never happens, those ports keep the extra ACL lookup latency that this patch is meant to remove.

These paths are also unchanged later in the series. "net: dsa:
motorcomm: Add TC prio support" doesn't touch them.

Would it make sense to rewrite YT921X_ACL_PORT from yt921x_acl_activated_ports() on the add error path?

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261009165825.359259-1-mmyangfl%40gmail.com
author maintainer
#5 lore raw

PATCH v3 4/4 net: dsa: motorcomm: Add TC prio support

In reply to David Yang

The HW orders ACL rules by the 9-bit ORD field (512 values, larger matching first), while TC priorities span 1..U16_MAX with the smallest meaning the highest. Map them as evenly as possible, and reject others which do not map onto a hardware order instead of silently colliding with a neighbouring one.

---
 drivers/net/dsa/motorcomm/tc.c | 35 +++++++++++++++++++++++++++++++++-
 drivers/net/dsa/motorcomm/tc.h |  1 +
 2 files changed, 35 insertions(+), 1 deletion(-)
drivers/net/dsa/motorcomm/tc.c +34 -1
index a302016912b5..3e0f80500f41 100644
@@ -1029,7 +1029,10 @@ yt921x_acl_rule_ext_parse_flow(struct yt921x_acl_rule_ext *ruleext, int port,
 			       const struct flow_cls_offload *cls, bool ingress,
 			       struct yt921x_priv *priv)
 {
+	const unsigned int scale = (U16_MAX + 1) / YT921X_ACL_ORD_NUM;
 	struct netlink_ext_ack *extack = cls->common.extack;
+	u32 prio = cls->common.prio;
+	u32 ord;
 	int res;
 
 	if (!ingress) {
@@ -1042,6 +1045,36 @@ yt921x_acl_rule_ext_parse_flow(struct yt921x_acl_rule_ext *ruleext, int port,
 		return -EOPNOTSUPP;
 	}
 
+	/* Lower TC priorities take precedence, while larger orders win in
+	 * hardware. Spread the 512 hardware orders over the TC priority range
+	 * as evenly as possible, retaining the relative order:
+	 *
+	 *   prio 65535 -> ORD 0    catchall filter
+	 *   prio 65408 -> ORD 1    highest mappable TC priority
+	 *   ...
+	 *   prio 49152 -> ORD 128  default value for the first tc flower rule
+	 *   ...
+	 *   prio   128 -> ORD 511
+	 *   prio     0             (invalid TC priority)
+	 *
+	 * The catchall filter always comes with priority 65535; pin it to ORD
+	 * 0, the lowest hardware order, instead of rejecting it.
+	 *
+	 * Prefer explicit rejects over implicit behaviour changes: reject
+	 * the priorities which do not map onto a hardware order instead of
+	 * silently colliding with a neighbouring one.
+	 */
+	if (prio == U16_MAX) {
+		ord = 0;
+	} else if (!(prio % scale)) {
+		ord = YT921X_ACL_ORD_NUM - prio / scale;
+	} else {
+		NL_SET_ERR_MSG_FMT_MOD(extack,
+				       "Invalid priority %u, must be a multiple of %u or 65535",
+				       prio, scale);
+		return -EOPNOTSUPP;
+	}
+
 	res = yt921x_acl_rule_ext_parse_flow_action(ruleext, cls, priv, port);
 	if (res)
 		return res;
@@ -1049,7 +1082,7 @@ yt921x_acl_rule_ext_parse_flow(struct yt921x_acl_rule_ext *ruleext, int port,
 	if (res)
 		return res;
 
-	yt921x_acl_rule_set_ports(&ruleext->r, 0, BIT(port));
+	yt921x_acl_rule_set_ports(&ruleext->r, ord, BIT(port));
 	ruleext->r.tag = cls->cookie;
 	ruleext->r.type = TC_SETUP_CLSFLOWER;
 	return 0;
drivers/net/dsa/motorcomm/tc.h +1 -0
index 32b53f1f3825..f11136a1c5e2 100644
@@ -331,6 +331,7 @@ enum yt921x_l4_type {
 
 #define YT921X_ACL_ENT_PER_BLK	8
 #define YT921X_ACL_NUM		384
+#define YT921X_ACL_ORD_NUM	512
 
 struct yt921x_acl_entry {
 	u32 key[2];
Signature · 1 line
2.53.0
#6 lore raw

Re: [PATCH net-next v3 4/4] net: dsa: motorcomm: Add TC prio support

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] net: dsa: motorcomm: strict TC priority modulo check breaks auto-allocation

--

Quoted 30 lines
drivers/net/dsa/motorcomm/tc.c +23 -0
@@ -1042,6 +1045,36 @@ yt921x_acl_rule_ext_parse_flow(struct yt921x_acl_rule_ext *ruleext, int port,
 		return -EOPNOTSUPP;
 	}
 
+	/* Lower TC priorities take precedence, while larger orders win in
+	 * hardware. Spread the 512 hardware orders over the TC priority range
+	 * as evenly as possible, retaining the relative order:
+	 *
+	 *   prio 65535 -> ORD 0    catchall filter
+	 *   prio 65408 -> ORD 1    highest mappable TC priority
+	 *   ...
+	 *   prio 49152 -> ORD 128  default value for the first tc flower rule
+	 *   ...
+	 *   prio   128 -> ORD 511
+	 *   prio     0             (invalid TC priority)
+	 *
+	 * The catchall filter always comes with priority 65535; pin it to ORD
+	 * 0, the lowest hardware order, instead of rejecting it.
+	 *
+	 * Prefer explicit rejects over implicit behaviour changes: reject
+	 * the priorities which do not map onto a hardware order instead of
+	 * silently colliding with a neighbouring one.
+	 */
+	if (prio == U16_MAX) {
+		ord = 0;
+	} else if (!(prio % scale)) {
+		ord = YT921X_ACL_ORD_NUM - prio / scale;

drivers/net/dsa/motorcomm/tc.c yt921x_acl_rule_ext_parse_flow(struct yt921x_acl_rule_ext *ruleext, int port, · line 1080

Quoted 10 lines
drivers/net/dsa/motorcomm/tc.c +7 -0
+	} else {
+		NL_SET_ERR_MSG_FMT_MOD(extack,
+				       "Invalid priority %u, must be a multiple of %u or 65535",
+				       prio, scale);
+		return -EOPNOTSUPP;
+	}
+
 	res = yt921x_acl_rule_ext_parse_flow_action(ruleext, cls, priv, port);
 	if (res)
 		return res;

[Severity: Medium]
This rejects every priority that is not a multiple of 128, but the kernel's own auto-allocation does not produce such values.

When a filter is added without an explicit pref, tcf_auto_prio() in net/sched/cls_api.c gives the first filter 49152. Each later filter gets the previous priority minus one, so the second gets 49151, the third 49150, and so on.

With this patch, the first plain "tc filter add ... flower" on a port is offloaded at ORD 128. Every following one added without pref then fails here with -EOPNOTSUPP:

- With skip_sw this is a hard failure for a very common usage pattern.
- Without skip_sw the rule quietly stays software-only.

Before this patch the same sequence was offloaded, with every rule at ORD 0. That makes this a behaviour regression for anyone who does not hand-pick prefs in steps of 128.

Is a fixed linear prio-to-ORD mapping really what we want here? For example, could yt921x_acl_rule_ext_parse_flow() assign hardware orders from the relative priority of the rules currently installed? Or could it at least handle the auto-allocated range below 49152 sensibly? I'd like to understand how you expect users to drive this in practice.

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261009165825.359259-1-mmyangfl%40gmail.com
author maintainer
#7 lore raw

Re: [PATCH net-next v3 4/4] net: dsa: motorcomm: Add TC prio support

Quoted 6 lines · On Sun, Oct 11, 2026 at 1:14 AM <[email protected]> wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

Quoted 8 lines

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] net: dsa: motorcomm: strict TC priority modulo check breaks auto-allocation

Already explained in the comment. Also we already reject some rules with -EOPNOTSUPP, if returning -EOPNOTSUPP when skip_sw is not set is a problem, that should be fixed by another series.

#8 lore raw
In reply to David Yang
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 13 lines · On Sat, 10 Oct 2026 00:58:18 +0800 you wrote:

This series continues the traffic control work on the Motorcomm YT9215S DSA driver: it reorganizes the offload code and then adds ACL enablement on demand and flower priority mapping.

v3:
- rebase
- reword commit messages and comments
- fix cleanup path in acl_add()
v2: https://lore.kernel.org/r/[email protected]
- move type casting helper into chip.h
- remove flow statistics and broadcast/multicast policers
v1: https://lore.kernel.org/r/[email protected]

Quoted 1 line

[...]

Here is the summary with links:
- [net-next,v3,1/4] net: dsa: motorcomm: Split TC module

    https://git.kernel.org/netdev/net-next/c/ba13bd277d22
  - [net-next,v3,2/4] net: dsa: motorcomm: Use NSEC_PER_SEC
    https://git.kernel.org/netdev/net-next/c/4a8e05d62ecc
  - [net-next,v3,3/4] net: dsa: motorcomm: Enable ACL on demand
    https://git.kernel.org/netdev/net-next/c/73db071a6692
  - [net-next,v3,4/4] net: dsa: motorcomm: Add TC prio support
    https://git.kernel.org/netdev/net-next/c/f9822b4ca6ef

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html