Netdev List
 help / color / mirror / Atom feed
* [PATCH net-next 0/2] net: dsa: realtek: rtl8365mb: offload ETS strict priority
@ 2026-11-24 10:20 Oleksij Rempel
  2026-11-24 10:20 ` [PATCH net-next 1/2] net: dsa: realtek: rtl8365mb: default the egress scheduler to WFQ Oleksij Rempel
  2026-11-24 10:20 ` [PATCH net-next 2/2] net: dsa: realtek: rtl8365mb: offload ETS strict priority scheduling Oleksij Rempel
  0 siblings, 2 replies; 4+ messages in thread
From: Oleksij Rempel @ 2026-11-24 10:20 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Simon Horman, Linus Walleij, Luiz Angelo Daros de Luca,
	Alvin Šipraga, Andrew Lunn, Vladimir Oltean
  Cc: netdev, kernel, Oleksij Rempel

This series adds strict priority egress scheduling to the rtl8365mb
switch ports.

It uses the ETS qdisc interface, which is enough to express strict
priority. By default, the driver sets all queues of a port to weighted
fair queuing (WFQ) with equal weights. No queue is served before
another.

To enable strict priority on a port:

  tc qdisc replace dev swp1 root handle 1: ets strict 8

The qdisc must have as many bands as the port has queues, eight on
this switch.

To go back to the default:

  tc qdisc del dev swp1 root

These commands change only the egress scheduling of the port they
name. The CPU port stays on WFQ. The ETS priomap is not offloaded. The
ETS patch explains why.

Tested on an RTL8365MB-VC.

---
Oleksij Rempel (2):
      net: dsa: realtek: rtl8365mb: default the egress scheduler to WFQ
      net: dsa: realtek: rtl8365mb: offload ETS strict priority scheduling

 drivers/net/dsa/realtek/realtek.h        |  14 ++++
 drivers/net/dsa/realtek/rtl8365mb_main.c |   8 +++
 drivers/net/dsa/realtek/rtl8365mb_qos.c  | 107 +++++++++++++++++++++++++++++
 drivers/net/dsa/realtek/rtl8365mb_qos.h  |   3 +
 drivers/net/dsa/realtek/rtl83xx-qos.c    | 113 +++++++++++++++++++++++++++++++
 drivers/net/dsa/realtek/rtl83xx-qos.h    |   2 +
 6 files changed, 247 insertions(+)
---
base-commit: 2208ab00f4f213ade91ab775e7f8c4dacdcc856e
change-id: 20261123-rtl8365mb-ets-strict-113214ad321a

Best regards,
-- 
Oleksij Rempel <o.rempel@pengutronix.de>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH net-next 1/2] net: dsa: realtek: rtl8365mb: default the egress scheduler to WFQ
  2026-11-24 10:20 [PATCH net-next 0/2] net: dsa: realtek: rtl8365mb: offload ETS strict priority Oleksij Rempel
@ 2026-11-24 10:20 ` Oleksij Rempel
  2026-11-24 10:20 ` [PATCH net-next 2/2] net: dsa: realtek: rtl8365mb: offload ETS strict priority scheduling Oleksij Rempel
  1 sibling, 0 replies; 4+ messages in thread
From: Oleksij Rempel @ 2026-11-24 10:20 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Simon Horman, Linus Walleij, Luiz Angelo Daros de Luca,
	Alvin Šipraga, Andrew Lunn, Vladimir Oltean
  Cc: netdev, kernel, Oleksij Rempel

Set the egress scheduler of every port in use to WFQ (weighted fair
queuing) with equal weights at setup. WFQ serves all queues of a port
in turn, so no queue is served before another.

The chip resets every queue to strict priority. With strict priority a
busy higher queue can starve the lower ones.

By default every frame gets the Best Effort traffic type and uses one
queue. The scheduler change therefore shows only after apptrust or the
default 802.1Q priority of a port is configured.

The next patch lets tc switch a user port to strict priority. No tc
interface reaches the scheduler of the CPU port, so it stays on WFQ.

The microchip ksz9477 family driver uses the same default.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/net/dsa/realtek/rtl8365mb_main.c |  4 ++
 drivers/net/dsa/realtek/rtl8365mb_qos.c  | 90 ++++++++++++++++++++++++++++++++
 drivers/net/dsa/realtek/rtl8365mb_qos.h  |  1 +
 3 files changed, 95 insertions(+)

diff --git a/drivers/net/dsa/realtek/rtl8365mb_main.c b/drivers/net/dsa/realtek/rtl8365mb_main.c
index 6c11c3631eb10f8eebdb8526908534c2256ed12d..a81ef9dfaf970f45a988a1b496c011e0824ba939 100644
--- a/drivers/net/dsa/realtek/rtl8365mb_main.c
+++ b/drivers/net/dsa/realtek/rtl8365mb_main.c
@@ -3199,6 +3199,10 @@ static int rtl8365mb_setup(struct dsa_switch *ds)
 	if (ret)
 		goto out_teardown_irq;
 
+	ret = rtl8365mb_qos_sched_init(priv);
+	if (ret)
+		goto out_teardown_irq;
+
 	/* Start with all ports blocked, including unused ports */
 	dsa_switch_for_each_port(dp, ds) {
 		struct rtl8365mb_port *p = &mb->ports[dp->index];
diff --git a/drivers/net/dsa/realtek/rtl8365mb_qos.c b/drivers/net/dsa/realtek/rtl8365mb_qos.c
index 5b9e1abe75c8b43b0cb6d07de0fd2ac09353f9d1..25d18cbc6fd1228fb0bf5c535b2a16548d614087 100644
--- a/drivers/net/dsa/realtek/rtl8365mb_qos.c
+++ b/drivers/net/dsa/realtek/rtl8365mb_qos.c
@@ -90,6 +90,38 @@ static_assert(RTL8365MB_QOS_1Q_REMAP_REG(IEEE_8021Q_MAX_PRIORITIES - 1) <
 static_assert(RTL8365MB_QOS_DSCP_PRI_REG(DSCP_MAX - 1) <
 	      RTL8365MB_QOS_PORT_PRI_REG(0));
 
+/* Egress queue ids per port */
+#define RTL8365MB_QOS_SCHED_QIDS			8
+
+/* Egress scheduler queue type: one bit per (port, queue id), two ports per
+ * register
+ */
+#define RTL8365MB_QOS_SCHED_QTYPE_PORTS_PER_REG		2
+#define RTL8365MB_QOS_SCHED_QTYPE_REG(_p) \
+	(0x0302 + (_p) / RTL8365MB_QOS_SCHED_QTYPE_PORTS_PER_REG)
+#define RTL8365MB_QOS_SCHED_QTYPE_BIT(_p, _qid) \
+	(((_p) % RTL8365MB_QOS_SCHED_QTYPE_PORTS_PER_REG) * \
+	 RTL8365MB_QOS_SCHED_QIDS + (_qid))
+
+#define RTL8365MB_QOS_SCHED_QTYPE_STRICT		0
+#define RTL8365MB_QOS_SCHED_QTYPE_WFQ			1
+
+static_assert(RTL8365MB_QOS_SCHED_QIDS *
+	      RTL8365MB_QOS_SCHED_QTYPE_PORTS_PER_REG <=
+	      RTL8365MB_QOS_REG_BITS);
+
+/* WFQ weight of a queue: one whole register per (port, queue id) */
+#define RTL8365MB_QOS_SCHED_WFQ_WEIGHT_REG(_p, _qid) \
+	(0x030c + (_p) * RTL8365MB_QOS_SCHED_QIDS + (_qid))
+
+/* The unit of the WFQ weight is unknown; the driver writes the same weight to
+ * every queue.
+ */
+#define RTL8365MB_QOS_SCHED_WFQ_WEIGHT_DEFAULT		1
+
+static_assert(RTL8365MB_QOS_SCHED_QTYPE_REG(RTL8365MB_QOS_MAX_PORTS - 1) <
+	      RTL8365MB_QOS_SCHED_WFQ_WEIGHT_REG(0, 0));
+
 /* Priority-decision weight tables. In the driver's model of the decision
  * hardware, a source ranks by its highest set weight bit (a one-hot rank), not
  * by numeric magnitude. A weight of zero disables the source.
@@ -294,6 +326,8 @@ static int rtl8365mb_qos_set_qmap_qid(struct realtek_priv *priv, int qmap,
  */
 #define RTL8365MB_QOS_QID_TOP				7
 
+static_assert(RTL8365MB_QOS_QID_TOP < RTL8365MB_QOS_SCHED_QIDS);
+
 static u8 rtl8365mb_qos_tc_to_qid(unsigned int num_queues, u8 tc)
 {
 	if (num_queues > 1 && tc == num_queues - 1)
@@ -334,6 +368,62 @@ int rtl8365mb_qos_qmap_init(struct realtek_priv *priv)
 	return 0;
 }
 
+static int rtl8365mb_qos_write_port_sched(struct realtek_priv *priv, int port,
+					  unsigned int num_queues)
+{
+	u32 weight = RTL8365MB_QOS_SCHED_WFQ_WEIGHT_DEFAULT;
+	unsigned int tc;
+	u32 qtype;
+	int ret;
+	u32 reg;
+
+	if (!num_queues || num_queues > RTL8365MB_QOS_SCHED_QIDS)
+		return -EINVAL;
+
+	reg = RTL8365MB_QOS_SCHED_QTYPE_REG(port);
+	qtype = RTL8365MB_QOS_SCHED_QTYPE_WFQ;
+
+	/* Program the queue ids that the traffic-type-to-queue map uses */
+	for (tc = 0; tc < num_queues; tc++) {
+		u32 mask;
+		u32 wreg;
+		u8 qid;
+
+		qid = rtl8365mb_qos_tc_to_qid(num_queues, tc);
+		mask = BIT(RTL8365MB_QOS_SCHED_QTYPE_BIT(port, qid));
+		wreg = RTL8365MB_QOS_SCHED_WFQ_WEIGHT_REG(port, qid);
+
+		ret = regmap_write(priv->map, wreg, weight);
+		if (ret)
+			return ret;
+
+		ret = rtl8365mb_qos_regmap_update_field(priv, reg, mask, qtype);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
+/* The chip resets every queue to strict priority. Put the ports in use on
+ * WFQ with equal weights.
+ */
+int rtl8365mb_qos_sched_init(struct realtek_priv *priv)
+{
+	unsigned int nq = priv->ds.num_tx_queues;
+	struct dsa_port *dp;
+	int ret;
+
+	/* Unused ports carry no traffic; their scheduler is left alone */
+	dsa_switch_for_each_available_port(dp, &priv->ds) {
+		ret = rtl8365mb_qos_write_port_sched(priv, dp->index, nq);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
 static int rtl8365mb_qos_set_pridec(struct realtek_priv *priv, int table,
 				    int src, u8 weight)
 {
diff --git a/drivers/net/dsa/realtek/rtl8365mb_qos.h b/drivers/net/dsa/realtek/rtl8365mb_qos.h
index 9602807f7db5b9c5bf0202612e4cd77b85079cb7..1daeee16e47294dead49b0843a863991de9731cd 100644
--- a/drivers/net/dsa/realtek/rtl8365mb_qos.h
+++ b/drivers/net/dsa/realtek/rtl8365mb_qos.h
@@ -19,6 +19,7 @@ struct realtek_priv;
 
 int rtl8365mb_qos_pridec_init(struct realtek_priv *priv);
 int rtl8365mb_qos_qmap_init(struct realtek_priv *priv);
+int rtl8365mb_qos_sched_init(struct realtek_priv *priv);
 int rtl8365mb_qos_get_port_prio(struct realtek_priv *priv, int port);
 int rtl8365mb_qos_set_port_prio(struct realtek_priv *priv, int port, u8 iprio,
 				u8 untag_pcp);

-- 
2.47.3


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH net-next 2/2] net: dsa: realtek: rtl8365mb: offload ETS strict priority scheduling
  2026-11-24 10:20 [PATCH net-next 0/2] net: dsa: realtek: rtl8365mb: offload ETS strict priority Oleksij Rempel
  2026-11-24 10:20 ` [PATCH net-next 1/2] net: dsa: realtek: rtl8365mb: default the egress scheduler to WFQ Oleksij Rempel
@ 2026-11-24 10:20 ` Oleksij Rempel
  2026-11-25 10:23   ` netdev-bot+sashiko
  1 sibling, 1 reply; 4+ messages in thread
From: Oleksij Rempel @ 2026-11-24 10:20 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Simon Horman, Linus Walleij, Luiz Angelo Daros de Luca,
	Alvin Šipraga, Andrew Lunn, Vladimir Oltean
  Cc: netdev, kernel, Oleksij Rempel

Offload the ETS qdisc so a user port can be switched from the WFQ
default to strict priority. With WFQ (weighted fair queuing) the
switch serves all queues of a port in turn, by their weights. By
default the driver sets equal weights, so no queue is served before
another. With strict priority a higher queue is always sent first.
Deleting the qdisc puts the port back on WFQ.

The driver offloads only strict bands. sch_ets gives each
bandwidth-sharing band a quantum in bytes. It is not known whether the
hardware WFQ counts bytes or frames. Even equal quanta therefore
cannot be offloaded.

The driver requires one band per queue, so the qdisc describes the
whole port. Band n is not queue n. The switch sends its higher queue
first.

If a root ets qdisc breaks one of these rules, the driver logs the
reason and refuses the offload. The qdisc then runs in software and
the port goes back to WFQ. An ets qdisc that is not the root qdisc is
not offloaded.

The priomap is not offloaded, for three reasons:
- Frames that the switch forwards have no skb->priority. The switch
  queues them by its own classification. It uses the default of the
  port the frame came in on, or the PCP or DSCP if that port trusts
  it.
- Frames that the host sends get the default traffic type of the CPU
  port.
- The switch maps traffic types to queues. It does not map
  skb->priority values. mqprio and taprio set the prio_tc_map of the
  netdev. sch_ets does not. The tagger therefore cannot apply the
  priomap to host frames.

The driver therefore accepts any priomap. Refusing a priomap would not
make the switch follow it.

The patch uses ets, not prio. The hardware picks strict priority or
WFQ per queue, and ets sets the type per band.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>

---
Q: What does the user see when the offload of a root ets qdisc is
   refused?
A: tc succeeds. The qdisc runs in software, and "tc qdisc show" does
   not mark it as offloaded. The driver logs the reason as
   "port N: ...".

Q: What happens with hw-tc-offload turned off?
A: tc stops telling the driver about ets changes, so the port keeps
   its last scheduler setting. Until the offload is on again and the
   root ets qdisc is installed again ("tc qdisc replace"), the port
   may not follow what tc shows.

Q: Does the switch queue frames that the host sends by their sch_ets
   band?
A: No, not in the switch. The tagger leaves the PRI_EN bit of the
   CPU tag clear, so the CPU port default applies. With PRI_EN set,
   the switch would use the PRI field of the CPU tag instead.
---
 drivers/net/dsa/realtek/realtek.h        |  14 ++++
 drivers/net/dsa/realtek/rtl8365mb_main.c |   4 ++
 drivers/net/dsa/realtek/rtl8365mb_qos.c  |  29 ++++++--
 drivers/net/dsa/realtek/rtl8365mb_qos.h  |   2 +
 drivers/net/dsa/realtek/rtl83xx-qos.c    | 113 +++++++++++++++++++++++++++++++
 drivers/net/dsa/realtek/rtl83xx-qos.h    |   2 +
 6 files changed, 158 insertions(+), 6 deletions(-)

diff --git a/drivers/net/dsa/realtek/realtek.h b/drivers/net/dsa/realtek/realtek.h
index cfe56d30f5cb1c6fabf381dd55e73934cbc66abb..af8315a80c642175b955bd4a16c9d34c7c9efdb3 100644
--- a/drivers/net/dsa/realtek/realtek.h
+++ b/drivers/net/dsa/realtek/realtek.h
@@ -45,6 +45,11 @@ struct rtl8366_vlan_4k {
 	u8	fid;
 };
 
+/* Size of ets_handle[]: the most ports a switch can have and still
+ * offload ETS.
+ */
+#define REALTEK_MAX_PORTS	11
+
 struct realtek_fdb_entry {
 	u8 mac_addr[ETH_ALEN];
 	u16 vid;
@@ -98,6 +103,9 @@ struct realtek_priv {
 	int			vlan4k_enabled;
 
 	void			*chip_data; /* Per-chip extra variant data */
+
+	/* Handle of the ETS qdisc offloaded last on each port, or 0 */
+	u32			ets_handle[REALTEK_MAX_PORTS];
 };
 
 /* apptrust selector slots: the index into the trust[] array of the
@@ -192,6 +200,12 @@ struct realtek_ops {
 				    const bool *trust, unsigned int n);
 	int	(*qos_get_apptrust)(struct realtek_priv *priv, int port,
 				    bool *trust, unsigned int n);
+	/* Set the scheduler of @port. If @strict, the queues for traffic
+	 * classes 0..@num_queues - 1 are strict priority, and a higher traffic
+	 * class is served first. Otherwise they are WFQ with equal weights.
+	 */
+	int	(*qos_set_port_sched)(struct realtek_priv *priv, int port,
+				      unsigned int num_queues, bool strict);
 };
 
 struct realtek_variant {
diff --git a/drivers/net/dsa/realtek/rtl8365mb_main.c b/drivers/net/dsa/realtek/rtl8365mb_main.c
index a81ef9dfaf970f45a988a1b496c011e0824ba939..d08c389eeb7f0222355774ac18464d92331d1915 100644
--- a/drivers/net/dsa/realtek/rtl8365mb_main.c
+++ b/drivers/net/dsa/realtek/rtl8365mb_main.c
@@ -125,6 +125,8 @@
 #define RTL8365MB_LEARN_LIMIT_MAX	2112
 #define RTL8365MB_MAX_NUM_EXTINTS	3
 
+static_assert(RTL8365MB_MAX_NUM_PORTS <= REALTEK_MAX_PORTS);
+
 /* Chip identification registers */
 #define RTL8365MB_CHIP_ID_REG		0x1300
 
@@ -3487,6 +3489,7 @@ static const struct dsa_switch_ops rtl8365mb_switch_ops = {
 	.port_get_apptrust = rtl83xx_port_get_apptrust,
 	.port_set_apptrust = rtl83xx_port_set_apptrust,
 	.port_get_dscp_prio = rtl83xx_port_get_dscp_prio,
+	.port_setup_tc = rtl83xx_port_setup_tc,
 	.port_stp_state_set = rtl8365mb_port_stp_state_set,
 	.port_fast_age = rtl83xx_port_fast_age,
 	.port_fdb_add = rtl83xx_port_fdb_add,
@@ -3536,6 +3539,7 @@ static const struct realtek_ops rtl8365mb_ops = {
 	.qos_set_dscp_prio = rtl8365mb_qos_set_dscp_prio,
 	.qos_set_apptrust = rtl8365mb_qos_set_apptrust,
 	.qos_get_apptrust = rtl8365mb_qos_get_apptrust,
+	.qos_set_port_sched = rtl8365mb_qos_set_port_sched,
 };
 
 static const char *const rtl8365mb_supplies[] = {
diff --git a/drivers/net/dsa/realtek/rtl8365mb_qos.c b/drivers/net/dsa/realtek/rtl8365mb_qos.c
index 25d18cbc6fd1228fb0bf5c535b2a16548d614087..b3e43a4e136da6fff126a04835a1967963fcc12c 100644
--- a/drivers/net/dsa/realtek/rtl8365mb_qos.c
+++ b/drivers/net/dsa/realtek/rtl8365mb_qos.c
@@ -368,8 +368,9 @@ int rtl8365mb_qos_qmap_init(struct realtek_priv *priv)
 	return 0;
 }
 
+/* Under strict priority a higher queue id is served first */
 static int rtl8365mb_qos_write_port_sched(struct realtek_priv *priv, int port,
-					  unsigned int num_queues)
+					  unsigned int num_queues, bool strict)
 {
 	u32 weight = RTL8365MB_QOS_SCHED_WFQ_WEIGHT_DEFAULT;
 	unsigned int tc;
@@ -381,7 +382,8 @@ static int rtl8365mb_qos_write_port_sched(struct realtek_priv *priv, int port,
 		return -EINVAL;
 
 	reg = RTL8365MB_QOS_SCHED_QTYPE_REG(port);
-	qtype = RTL8365MB_QOS_SCHED_QTYPE_WFQ;
+	qtype = strict ? RTL8365MB_QOS_SCHED_QTYPE_STRICT :
+			 RTL8365MB_QOS_SCHED_QTYPE_WFQ;
 
 	/* Program the queue ids that the traffic-type-to-queue map uses */
 	for (tc = 0; tc < num_queues; tc++) {
@@ -393,9 +395,11 @@ static int rtl8365mb_qos_write_port_sched(struct realtek_priv *priv, int port,
 		mask = BIT(RTL8365MB_QOS_SCHED_QTYPE_BIT(port, qid));
 		wreg = RTL8365MB_QOS_SCHED_WFQ_WEIGHT_REG(port, qid);
 
-		ret = regmap_write(priv->map, wreg, weight);
-		if (ret)
-			return ret;
+		if (!strict) {
+			ret = regmap_write(priv->map, wreg, weight);
+			if (ret)
+				return ret;
+		}
 
 		ret = rtl8365mb_qos_regmap_update_field(priv, reg, mask, qtype);
 		if (ret)
@@ -405,6 +409,18 @@ static int rtl8365mb_qos_write_port_sched(struct realtek_priv *priv, int port,
 	return 0;
 }
 
+int rtl8365mb_qos_set_port_sched(struct realtek_priv *priv, int port,
+				 unsigned int num_queues, bool strict)
+{
+	int ret;
+
+	ret = rtl8365mb_qos_check_port(priv, port);
+	if (ret)
+		return ret;
+
+	return rtl8365mb_qos_write_port_sched(priv, port, num_queues, strict);
+}
+
 /* The chip resets every queue to strict priority. Put the ports in use on
  * WFQ with equal weights.
  */
@@ -416,7 +432,8 @@ int rtl8365mb_qos_sched_init(struct realtek_priv *priv)
 
 	/* Unused ports carry no traffic; their scheduler is left alone */
 	dsa_switch_for_each_available_port(dp, &priv->ds) {
-		ret = rtl8365mb_qos_write_port_sched(priv, dp->index, nq);
+		ret = rtl8365mb_qos_write_port_sched(priv, dp->index, nq,
+						     false);
 		if (ret)
 			return ret;
 	}
diff --git a/drivers/net/dsa/realtek/rtl8365mb_qos.h b/drivers/net/dsa/realtek/rtl8365mb_qos.h
index 1daeee16e47294dead49b0843a863991de9731cd..d89cf12b4fe436a010f5f777ddd49c15ec9039bc 100644
--- a/drivers/net/dsa/realtek/rtl8365mb_qos.h
+++ b/drivers/net/dsa/realtek/rtl8365mb_qos.h
@@ -26,6 +26,8 @@ int rtl8365mb_qos_set_port_prio(struct realtek_priv *priv, int port, u8 iprio,
 int rtl8365mb_qos_set_pcp_prio(struct realtek_priv *priv, u8 pcp, u8 iprio);
 int rtl8365mb_qos_get_dscp_prio(struct realtek_priv *priv, u8 dscp);
 int rtl8365mb_qos_set_dscp_prio(struct realtek_priv *priv, u8 dscp, u8 iprio);
+int rtl8365mb_qos_set_port_sched(struct realtek_priv *priv, int port,
+				 unsigned int num_queues, bool strict);
 int rtl8365mb_qos_set_apptrust(struct realtek_priv *priv, int port,
 			       const bool *trust, unsigned int n);
 int rtl8365mb_qos_get_apptrust(struct realtek_priv *priv, int port, bool *trust,
diff --git a/drivers/net/dsa/realtek/rtl83xx-qos.c b/drivers/net/dsa/realtek/rtl83xx-qos.c
index f294222987eff8ba283688600c6eaba983669ea6..388013291d50244b251b865e0615e9ae0c084175 100644
--- a/drivers/net/dsa/realtek/rtl83xx-qos.c
+++ b/drivers/net/dsa/realtek/rtl83xx-qos.c
@@ -16,6 +16,7 @@
 #include <net/dscp.h>
 #include <net/dsa.h>
 #include <net/ieee8021q.h>
+#include <net/pkt_cls.h>
 
 #include "realtek.h"
 #include "rtl83xx-qos.h"
@@ -208,3 +209,115 @@ int rtl83xx_port_set_apptrust(struct dsa_switch *ds, int port, const u8 *sel,
 					   ARRAY_SIZE(trust));
 }
 EXPORT_SYMBOL_NS_GPL(rtl83xx_port_set_apptrust, "REALTEK_DSA");
+
+static int
+rtl83xx_setup_tc_ets_replace(struct dsa_switch *ds, int port,
+			     struct tc_ets_qopt_offload_replace_params *p)
+{
+	struct realtek_priv *priv = ds->priv;
+	unsigned int nq = ds->num_tx_queues;
+	int i;
+
+	/* The qdisc must have one band per queue. */
+	if (p->bands != nq) {
+		dev_err(priv->dev, "port %d: ETS must configure all %u bands\n",
+			port, nq);
+		return -EOPNOTSUPP;
+	}
+
+	/* Only strict bands can be offloaded. */
+	for (i = 0; i < p->bands; i++) {
+		if (p->quanta[i]) {
+			dev_err(priv->dev, "port %d: ETS weighted bands are not supported\n",
+				port);
+			return -EOPNOTSUPP;
+		}
+	}
+
+	/* The switch does not use the priomap. */
+	return priv->ops->qos_set_port_sched(priv, port, nq, true);
+}
+
+/* Forget the offloaded ETS qdisc of @port and put the port back on WFQ */
+static int rtl83xx_setup_tc_ets_restore_wfq(struct dsa_switch *ds, int port)
+{
+	struct realtek_priv *priv = ds->priv;
+	int ret;
+
+	priv->ets_handle[port] = 0;
+
+	ret = priv->ops->qos_set_port_sched(priv, port, ds->num_tx_queues,
+					    false);
+	if (ret)
+		dev_err(priv->dev, "port %d: failed to restore WFQ: %pe\n",
+			port, ERR_PTR(ret));
+
+	return ret;
+}
+
+int rtl83xx_port_setup_tc(struct dsa_switch *ds, int port,
+			  enum tc_setup_type type, void *type_data)
+{
+	struct tc_ets_qopt_offload *ets = type_data;
+	struct realtek_priv *priv = ds->priv;
+	int ret;
+
+	if (type != TC_SETUP_QDISC_ETS || !priv->ops->qos_set_port_sched)
+		return -EOPNOTSUPP;
+
+	if (port >= ARRAY_SIZE(priv->ets_handle) || ets->parent != TC_H_ROOT)
+		return -EOPNOTSUPP;
+
+	switch (ets->command) {
+	case TC_ETS_REPLACE:
+		/* sch_ets keeps the qdisc when the offload fails. Put the
+		 * port back on WFQ so an earlier strict setup does not stay
+		 * active.
+		 */
+		ret = rtl83xx_setup_tc_ets_replace(ds, port,
+						   &ets->replace_params);
+		if (ret) {
+			rtl83xx_setup_tc_ets_restore_wfq(ds, port);
+			return ret;
+		}
+
+		priv->ets_handle[port] = ets->handle;
+
+		return 0;
+
+	case TC_ETS_DESTROY:
+		/* sch_ets offloads a new root qdisc before it destroys the
+		 * old one. Put the port back on WFQ only when DESTROY carries
+		 * the handle that was offloaded last. The new qdisc can fail
+		 * after the driver has offloaded it, for example in its rate
+		 * estimator. In that case qdisc_create() destroys the new
+		 * qdisc. Its DESTROY carries the handle offloaded last, so the
+		 * port goes back to WFQ. The old qdisc keeps running in
+		 * software.
+		 *
+		 * With hw-tc-offload off, sch_ets sends no DESTROY, so the
+		 * port stays strict.
+		 */
+		if (ets->handle != priv->ets_handle[port])
+			return 0;
+
+		return rtl83xx_setup_tc_ets_restore_wfq(ds, port);
+
+	case TC_ETS_STATS:
+		/* Report the qdisc as offloaded. tc_ets_qopt_offload carries
+		 * no extack, so this mark is the only sign in tc that the
+		 * offload was accepted. The stats stay the software ones. They
+		 * count only what the host sends on this port, not traffic
+		 * the switch forwards.
+		 */
+		return ets->handle == priv->ets_handle[port] ? 0 : -EOPNOTSUPP;
+
+	default:
+		/* Child qdiscs (TC_ETS_GRAFT) run in software. If tc has
+		 * marked the parent ets qdisc as offloaded, tc warns about the
+		 * graft.
+		 */
+		return -EOPNOTSUPP;
+	}
+}
+EXPORT_SYMBOL_NS_GPL(rtl83xx_port_setup_tc, "REALTEK_DSA");
diff --git a/drivers/net/dsa/realtek/rtl83xx-qos.h b/drivers/net/dsa/realtek/rtl83xx-qos.h
index 06dbfd24b1af5cced870f463f15b1b39eceb56ee..8103c3c42840b55a54e85198d283d5d79d6c6c91 100644
--- a/drivers/net/dsa/realtek/rtl83xx-qos.h
+++ b/drivers/net/dsa/realtek/rtl83xx-qos.h
@@ -16,5 +16,7 @@ int rtl83xx_port_get_apptrust(struct dsa_switch *ds, int port, u8 *sel,
 int rtl83xx_port_set_apptrust(struct dsa_switch *ds, int port, const u8 *sel,
 			      int nsel);
 int rtl83xx_port_get_dscp_prio(struct dsa_switch *ds, int port, u8 dscp);
+int rtl83xx_port_setup_tc(struct dsa_switch *ds, int port,
+			  enum tc_setup_type type, void *type_data);
 
 #endif /* _RTL83XX_QOS_H */

-- 
2.47.3


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next 2/2] net: dsa: realtek: rtl8365mb: offload ETS strict priority scheduling
  2026-11-24 10:20 ` [PATCH net-next 2/2] net: dsa: realtek: rtl8365mb: offload ETS strict priority scheduling Oleksij Rempel
@ 2026-11-25 10:23   ` netdev-bot+sashiko
  0 siblings, 0 replies; 4+ messages in thread
From: netdev-bot+sashiko @ 2026-11-25 10:23 UTC (permalink / raw)
  To: o.rempel
  Cc: davem, edumazet, kuba, pabeni, horms, linusw, luizluca,
	alvin.sipraga, andrew, olteanv, netdev, kernel

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

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

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] rtl83xx_port_setup_tc() / rtl83xx_setup_tc_ets_replace()
  (drivers/net/dsa/realtek/rtl83xx-qos.c) never reads p->priomap and…
- [Low] In rtl83xx_port_setup_tc() (drivers/net/dsa/realtek/rtl83xx-
  qos.c), the TC_ETS_STATS reply decides whether a qdisc is offloaded…
- [Low] The driver writes to the kernel log with no rate limit when a
  user's tc configuration is refused: - rtl83xx_setup_tc_ets_replace()…
- [Low] rtl83xx_setup_tc_ets_restore_wfq()
  (drivers/net/dsa/realtek/rtl83xx-qos.c) sets priv->ets_handle[port] =…

--

net: dsa: realtek: rtl8365mb: offload ETS strict priority scheduling

This commit adds ETS qdisc offload to rtl8365mb user ports. A root ets
qdisc with one strict band per queue moves the port from the default
equal-weight WFQ to strict priority, and deleting the qdisc restores WFQ.
Weighted bands are refused, and any priomap is accepted but not applied.

> diff --git a/drivers/net/dsa/realtek/rtl83xx-qos.c b/drivers/net/dsa/realtek/rtl83xx-qos.c
> index f294222987eff..388013291d502 100644
> --- a/drivers/net/dsa/realtek/rtl83xx-qos.c
> +++ b/drivers/net/dsa/realtek/rtl83xx-qos.c

[ ... ]

> @@ -208,3 +209,115 @@ int rtl83xx_port_set_apptrust(struct dsa_switch *ds, int port, const u8 *sel,
>  					   ARRAY_SIZE(trust));
>  }
>  EXPORT_SYMBOL_NS_GPL(rtl83xx_port_set_apptrust, "REALTEK_DSA");
> +
> +static int
> +rtl83xx_setup_tc_ets_replace(struct dsa_switch *ds, int port,
> +			     struct tc_ets_qopt_offload_replace_params *p)
> +{
> +	struct realtek_priv *priv = ds->priv;
> +	unsigned int nq = ds->num_tx_queues;
> +	int i;
> +
> +	/* The qdisc must have one band per queue. */
> +	if (p->bands != nq) {
> +		dev_err(priv->dev, "port %d: ETS must configure all %u bands\n",
> +			port, nq);
> +		return -EOPNOTSUPP;
> +	}

[Severity: Low]
Should these prints be ratelimited?

This dev_err() fires on every refused root ets REPLACE. So does the
"ETS weighted bands are not supported" one below. While hw-tc-offload is
on, sch_ets sends REPLACE from every ets_init() and ets_change(). A loop
like this can therefore fill dmesg without bound:

    tc qdisc change dev swpN root ets bands 4 ...

Every refused REPLACE also goes through
rtl83xx_setup_tc_ets_restore_wfq(). That function adds another dev_err()
if the register write fails.

DSA user netdevs are not netns-local. Anyone with CAP_NET_ADMIN in a
netns that owns the port can trigger this. ksz_tc_ets_validate() uses
the same unratelimited pattern, so this is minor.

Since tc_ets_qopt_offload has no extack, would dev_err_ratelimited() or a
once-only print be a better fit here?

> +
> +	/* Only strict bands can be offloaded. */
> +	for (i = 0; i < p->bands; i++) {
> +		if (p->quanta[i]) {
> +			dev_err(priv->dev, "port %d: ETS weighted bands are not supported\n",
> +				port);
> +			return -EOPNOTSUPP;
> +		}
> +	}
> +
> +	/* The switch does not use the priomap. */
> +	return priv->ops->qos_set_port_sched(priv, port, nq, true);
> +}

[Severity: Medium]
Can this report offload for configurations the hardware does not
implement?

Only p->bands and p->quanta[] are checked here. p->priomap is never read,
and the band order is never compared with the order the hardware uses.
Later, TC_ETS_STATS in rtl83xx_port_setup_tc() returns 0 for the stored
handle, so qdisc_offload_dump_helper() sets TCQ_F_OFFLOADED.

In sch_ets, band 0 is the highest priority strict band. The default
priomap sends every priority to the last band:

net/sched/sch_ets.c:ets_qdisc_change() {
    ...
	memset(priomap, nbands - 1, sizeof(priomap));
    ...
}

The hardware maps internal priority to tc, and tc to qid through
rtl8365mb_qos_tc_to_qid(). In strict mode it serves the higher qid first.
The only priomap it actually implements is prio i -> band nq - 1 - tc(i).

For example, with this command the software qdisc gives no
prioritisation, because every priority goes to band 7:

    tc qdisc add dev swpN root ets bands 8 strict 8

The hardware still applies strict priority by internal priority. With
"priomap 0 1 2 3 4 5 6 7", the software order is the reverse of the
hardware order. In both cases tc shows the qdisc as offloaded.

Other TC_SETUP_QDISC_ETS implementers handle the priomap:

- ksz_tc_ets_add() programs priomap[] into KSZ9477_PORT_MRI_TC_MAP. It
  also returns -EOPNOTSUPP for TC_ETS_STATS.
- lan966x_ets_add() and the sparx5 offload reject any priomap except
  priomap[i] == 7 - i.
- airoha checks the priomap against its fixed layout.
- mlxsw programs the priomap.

Is the comment "The switch does not use the priomap." accurate? The
backend has a programmable internal-priority to qid table.
rtl8365mb_qos_qmap_init() fills it through rtl8365mb_qos_set_qmap_qid().
That is the same kind of map ksz drives from the priomap.

Would it be better to program that table from priomap[]? The other option
is to reject priomaps and band orders that do not match the fixed
hardware mapping.

The commit message also says:

    The patch uses ets, not prio. The hardware picks strict priority or
    WFQ per queue, and ets sets the type per band.

Every band with a quantum is refused, so the only accepted configuration
is all-strict, which is what prio expresses. Does this justification only
hold for future work?

> +
> +/* Forget the offloaded ETS qdisc of @port and put the port back on WFQ */
> +static int rtl83xx_setup_tc_ets_restore_wfq(struct dsa_switch *ds, int port)
> +{
> +	struct realtek_priv *priv = ds->priv;
> +	int ret;
> +
> +	priv->ets_handle[port] = 0;
> +
> +	ret = priv->ops->qos_set_port_sched(priv, port, ds->num_tx_queues,
> +					    false);
> +	if (ret)
> +		dev_err(priv->dev, "port %d: failed to restore WFQ: %pe\n",
> +			port, ERR_PTR(ret));
> +
> +	return ret;
> +}

[Severity: Low]
What state is the port left in if qos_set_port_sched() fails here?

ets_handle[port] is cleared before the call, and it stays cleared even if
the call fails. rtl8365mb_qos_write_port_sched() programs one queue at a
time and returns at the first error:

drivers/net/dsa/realtek/rtl8365mb_qos.c:rtl8365mb_qos_write_port_sched() {
    ...
	for (tc = 0; tc < num_queues; tc++) {
		...
		if (!strict) {
			ret = regmap_write(priv->map, wreg, weight);
			if (ret)
				return ret;
		}

		ret = rtl8365mb_qos_regmap_update_field(priv, reg, mask, qtype);
		if (ret)
			return ret;
	}
    ...
}

If an SMI/MDIO access fails partway through, some queues end up WFQ and
the rest stay strict. Consider this sequence:

1. qdisc A is offloaded, and the port is strict.
2. A tc qdisc change on A fails validation. restore_wfq() runs, and a
   register access fails midway. ets_handle[port] is now 0.
3. tc qdisc del sends TC_ETS_DESTROY with handle A.
   rtl83xx_port_setup_tc() then returns early:

	if (ets->handle != priv->ets_handle[port])
		return 0;

The port keeps a mixed strict/WFQ scheduler with no ETS qdisc present.
It only gets back to WFQ after another strict offload and its DESTROY, or
after a re-probe through rtl8365mb_qos_sched_init().

Would it make sense to keep the record until the restore succeeds, so
that the later DESTROY retries it?

> +
> +int rtl83xx_port_setup_tc(struct dsa_switch *ds, int port,
> +			  enum tc_setup_type type, void *type_data)
> +{

[ ... ]

> +	switch (ets->command) {
> +	case TC_ETS_REPLACE:

[ ... ]

> +		priv->ets_handle[port] = ets->handle;
> +
> +		return 0;
> +
> +	case TC_ETS_DESTROY:

[ ... ]

> +		 * With hw-tc-offload off, sch_ets sends no DESTROY, so the
> +		 * port stays strict.
> +		 */
> +		if (ets->handle != priv->ets_handle[port])
> +			return 0;
> +
> +		return rtl83xx_setup_tc_ets_restore_wfq(ds, port);
> +
> +	case TC_ETS_STATS:
> +		/* Report the qdisc as offloaded. tc_ets_qopt_offload carries
> +		 * no extack, so this mark is the only sign in tc that the
> +		 * offload was accepted. The stats stay the software ones. They
> +		 * count only what the host sends on this port, not traffic
> +		 * the switch forwards.
> +		 */
> +		return ets->handle == priv->ets_handle[port] ? 0 : -EOPNOTSUPP;

[Severity: Low]
Can a stale ets_handle[port] mark a qdisc as offloaded that the driver
never validated?

ets_handle[port] is only cleared by a matching DESTROY or by a failed
REPLACE. ets_offload_change() and ets_offload_destroy() both return early
when !tc_can_offload(dev). DSA user ports also have no ndo_set_features
hook to resync this state when NETIF_F_HW_TC is turned back on. Consider
this sequence:

1. With offload on:
       tc qdisc add dev swpN root handle 1: ets bands 8 strict 8
   ets_handle[port] becomes 1:0, and the port is strict.
2. ethtool -K swpN hw-tc-offload off
3. tc qdisc del dev swpN root
   No DESTROY is sent, so ets_handle[port] stays 1:0.
4. tc qdisc add dev swpN root handle 1: ets bands 8 quanta 1500 ...
   No REPLACE is sent, so the driver never sees this configuration.
5. ethtool -K swpN hw-tc-offload on, then tc qdisc show:
   ets_offload_dump()->qdisc_offload_dump_helper() sends TC_ETS_STATS
   with handle 1:0. It returns 0, so TCQ_F_OFFLOADED is set.

tc then marks a weighted qdisc as offloaded, although REPLACE would have
refused it with -EOPNOTSUPP. The hardware still runs the old strict
setup. The same happens after a tc qdisc change on 1: while offload is
off.

The commit message and the DESTROY comment do note that the port may not
follow tc while hw-tc-offload is off. This false offloaded mark, though,
contradicts the STATS comment that it is "the only sign in tc that the
offload was accepted". Is that intended?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124-rtl8365mb-ets-strict-v1-0-6ab01ad545c8%40pengutronix.de

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-25 10:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 10:20 [PATCH net-next 0/2] net: dsa: realtek: rtl8365mb: offload ETS strict priority Oleksij Rempel
2026-11-24 10:20 ` [PATCH net-next 1/2] net: dsa: realtek: rtl8365mb: default the egress scheduler to WFQ Oleksij Rempel
2026-11-24 10:20 ` [PATCH net-next 2/2] net: dsa: realtek: rtl8365mb: offload ETS strict priority scheduling Oleksij Rempel
2026-11-25 10:23   ` netdev-bot+sashiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox