* [PATCH net-next v2 0/2] net: dsa: realtek: rtl8365mb: offload ETS strict priority
@ 2026-11-30 13:23 Oleksij Rempel
2026-11-30 13:23 ` [PATCH net-next v2 1/2] net: dsa: realtek: rtl8365mb: default the egress scheduler to WFQ Oleksij Rempel
2026-11-30 13:23 ` [PATCH net-next v2 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-30 13:23 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Linus Walleij, Luiz Angelo Daros de Luca, Andrew Lunn,
Vladimir Oltean
Cc: Alvin Šipraga, Simon Horman, netdev, linux-kernel, kernel,
Oleksij Rempel
This series adds strict priority egress scheduling to the rtl8365mb
switch ports.
It uses the ETS qdisc interface, as ksz9477 does for the same setup.
When ets was chosen there, the priomap problem described below was not
clear. ksz8 uses ets the same way. Solving the priomap problem in
sch_ets later is likely simpler than moving these drivers to another
interface.
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 lan1 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 lan1 root
These commands change only the egress scheduling of the port they
name, also for frames that the host sends on it. Frames that the
switch sends to the host leave through the CPU port, which stays on
WFQ.
The ETS priomap is not offloaded. The figure shows how the switch picks
the egress queue of a frame that leaves on lan1:
lan2 (ingress), forwarded frame host, frame sent on lan1
port default PCP DSCP skb->priority (TC_PRIO_*)
802.1Q prio (trusted) (trusted) |
| | | | priomap
| pcp_to_tt |pcp_to_tt | dscp_to_tt | (TC_PRIO -> band)
v v v |
+------------------------------+ +-------v-------+
| traffic type (TT) | | sch_ets band |
| DSCP > PCP > port default | | strict: 0 1st |
+--------------+---------------+ +-------+-------+
| | software only
| | DSA tag, no class
| +-------v-------+
| | CPU port |
| | default -> TT |
| +-------+-------+
| |
+----------------+-----------------+
|
v
+-----------------------+
| TT -> traffic class |
+-----------+-----------+
|
v
+-----------------------+
| lan1 egress queue |
| strict: highest first |
+-----------------------+
The switch and the ets qdisc use different inputs:
- For a forwarded frame, the switch takes a traffic type from the port
default, the PCP or the DSCP. It then maps the traffic type to a
traffic class and a queue.
- The ets priomap maps skb->priority values (TC_PRIO_*) to a band.
Unlike mqprio and taprio, sch_ets does not set the netdev traffic
classes (prio_tc_map).
The driver therefore does not use the priomap to program the traffic
type to traffic class map of the port. It cannot check the priomap
against that map either, because the two maps have different inputs:
skb->priority values on one side, traffic types on the other. The
driver accepts any priomap and does not offload it.
Tested on an RTL8365MB-VC.
---
Changes in v2:
- Link to v1: https://lore.kernel.org/r/20261124-rtl8365mb-ets-strict-v1-0-6ab01ad545c8@pengutronix.de
---
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 | 108 +++++++++++++++++++++++++++++++
drivers/net/dsa/realtek/rtl83xx-qos.h | 2 +
6 files changed, 242 insertions(+)
---
base-commit: 81159a672c331993566a12ad8e07532b38355cba
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 v2 1/2] net: dsa: realtek: rtl8365mb: default the egress scheduler to WFQ
2026-11-30 13:23 [PATCH net-next v2 0/2] net: dsa: realtek: rtl8365mb: offload ETS strict priority Oleksij Rempel
@ 2026-11-30 13:23 ` Oleksij Rempel
2026-11-30 13:23 ` [PATCH net-next v2 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-30 13:23 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Linus Walleij, Luiz Angelo Daros de Luca, Andrew Lunn,
Vladimir Oltean
Cc: Alvin Šipraga, Simon Horman, netdev, linux-kernel, 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>
---
Changes in v2:
- No changes.
---
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 v2 2/2] net: dsa: realtek: rtl8365mb: offload ETS strict priority scheduling
2026-11-30 13:23 [PATCH net-next v2 0/2] net: dsa: realtek: rtl8365mb: offload ETS strict priority Oleksij Rempel
2026-11-30 13:23 ` [PATCH net-next v2 1/2] net: dsa: realtek: rtl8365mb: default the egress scheduler to WFQ Oleksij Rempel
@ 2026-11-30 13:23 ` Oleksij Rempel
2026-12-01 13:26 ` netdev-bot+sashiko
1 sibling, 1 reply; 4+ messages in thread
From: Oleksij Rempel @ 2026-11-30 13:23 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Linus Walleij, Luiz Angelo Daros de Luca, Andrew Lunn,
Vladimir Oltean
Cc: Alvin Šipraga, Simon Horman, netdev, linux-kernel, 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. The driver does not map bands to queues.
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. The priomap maps skb->priority values to
bands. The switch queues a frame by its traffic type. The switch takes
it from the port default, the PCP or the DSCP, as the driver programs
it. Frames that the host sends get the default traffic type of the CPU
port. The driver cannot check one map against the other, so it accepts
any priomap.
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, and the qdisc runs in software. The driver logs the
reason as "port N: ...". "tc qdisc show" does not mark the qdisc
as offloaded, also when the driver accepts it.
Q: What happens with hw-tc-offload turned off?
A: tc stops telling the driver about ets changes. The port keeps its
last scheduler setting. It follows tc again once the offload is on
and a root ets qdisc is installed again ("tc qdisc replace").
Deleting that qdisc then restores WFQ.
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.
Q: What happens if a register write fails while the port goes back to
WFQ?
A: The driver stops at the failed write and logs the error. After an
MDIO error the state of the chip is unknown, so the driver does not
retry.
Changes in v2:
- Return -EOPNOTSUPP for TC_ETS_STATS, so tc does not mark the qdisc
as offloaded (sashiko).
- Rate-limit the refusal and restore-WFQ error logs (sashiko).
- Drop the "ets, not prio" paragraph from the message (sashiko).
- Say what the priomap and the switch map from, and drop the band/queue
sentences (sashiko).
- Add a Q&A on a failed register write while going back to WFQ
(sashiko).
---
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 | 108 +++++++++++++++++++++++++++++++
drivers/net/dsa/realtek/rtl83xx-qos.h | 2 +
6 files changed, 153 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..d2b21521b6de4e4fd0e05c9e04ce9628a444fe2a 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,110 @@ 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_ratelimited(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_ratelimited(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_ratelimited(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:
+ /* Do not mark the qdisc as offloaded: its priomap is not.
+ * Its stats stay the software ones. They count only what the
+ * host sends on this port, not traffic the switch forwards.
+ */
+ return -EOPNOTSUPP;
+
+ default:
+ /* Child qdiscs (TC_ETS_GRAFT) run in software */
+ 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 v2 2/2] net: dsa: realtek: rtl8365mb: offload ETS strict priority scheduling
2026-11-30 13:23 ` [PATCH net-next v2 2/2] net: dsa: realtek: rtl8365mb: offload ETS strict priority scheduling Oleksij Rempel
@ 2026-12-01 13:26 ` netdev-bot+sashiko
0 siblings, 0 replies; 4+ messages in thread
From: netdev-bot+sashiko @ 2026-12-01 13:26 UTC (permalink / raw)
To: o.rempel
Cc: davem, edumazet, kuba, pabeni, linusw, luizluca, andrew, olteanv,
alvin.sipraga, horms, netdev, linux-kernel, kernel
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 2
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] In drivers/net/dsa/realtek/rtl83xx-qos.c,
rtl83xx_port_setup_tc() keeps only one ETS handle per port…
- [Low] rtl83xx_setup_tc_ets_replace() in
drivers/net/dsa/realtek/rtl83xx-qos.c accepts TC_ETS_REPLACE and…
- [Low] The commit body, which is the part that stays in git history
(everything after the first '---' is dropped by git am), describes the…
--
net: dsa: realtek: rtl8365mb: offload ETS strict priority scheduling
This commit adds ETS qdisc offload for rtl8365mb user ports. Installing
a root ETS qdisc with one strict band per queue switches the port from
the default equal-weight WFQ scheduler to strict priority. Deleting the
qdisc, or a refused offload, puts the port back on WFQ, and the priomap
is not offloaded.
> 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.
[Severity: Low]
Is the last sentence accurate in all cases? With hw-tc-offload off,
ets_offload_destroy() returns early on !tc_can_offload(dev), so deleting
the qdisc leaves the port strict. The comment in the TC_ETS_DESTROY case
says so, but the commit body does not.
A few other user-visible details appear only in the Q&A below the ---
line, which git am drops:
rtl83xx_port_setup_tc() returns -EOPNOTSUPP for TC_ETS_STATS on purpose.
So qdisc_offload_dump_helper() never sets TCQ_F_OFFLOADED, even while
the QTYPE register is set to strict. Nothing reports whether the port
runs strict or WFQ.
If a replacement root qdisc fails after its REPLACE was accepted, the
port goes back to WFQ while the old strict qdisc stays root.
Could these details go into the commit message itself?
> diff --git a/drivers/net/dsa/realtek/rtl83xx-qos.c b/drivers/net/dsa/realtek/rtl83xx-qos.c
> index f294222987eff..d2b21521b6de4 100644
> --- a/drivers/net/dsa/realtek/rtl83xx-qos.c
> +++ b/drivers/net/dsa/realtek/rtl83xx-qos.c
[ ... ]
> @@ -208,3 +209,110 @@ 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) {
[ ... ]
> + /* The switch does not use the priomap. */
> + return priv->ops->qos_set_port_sched(priv, port, nq, true);
> +}
[Severity: Low]
Should a non-default priomap be refused here, or programmed into the
switch?
rtl83xx_setup_tc_ets_replace() checks only p->bands and p->quanta[]. A
priomap that sends every skb->priority to a single band is accepted,
and the port still switches to strict priority based on the switch's
own traffic-type-to-queue map.
ksz_tc_ets_add() in drivers/net/dsa/microchip/ksz_common.c programs the
priomap into the switch's priority-to-queue map
(KSZ9477_PORT_MRI_TC_MAP__4). This chip has a per-port qmap
(rtl8365mb_qos_set_qmap_qid() and rtl8365mb_qos_set_port_qmap()) that
might do the same job.
The commit message documents this limitation, and the qdisc is never
reported as offloaded. The hardware scheduler still changes, though.
> +
> +/* 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;
[ ... ]
> + 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);
[Severity: Medium]
Can this leave the port on WFQ while an accepted all-strict root qdisc
is still installed?
Only one handle is tracked per port. So a DESTROY for a new qdisc that
failed after its REPLACE looks the same as a delete of the active
qdisc.
Consider this sequence:
1. Root ETS qdisc 1: with nq strict bands is offloaded. The port is
strict and ets_handle[port] = 1:.
2. tc qdisc replace dev lanX root handle 2: ets bands N strict N ...
3. qdisc_create()->ets_qdisc_init()->ets_qdisc_change()->
ets_offload_change() sends TC_ETS_REPLACE for 2:, which is
accepted, and ets_handle[port] = 2:.
4. qdisc_create() then fails in gen_new_estimator() for TCA_RATE, or
qdisc_graft() fails in tc_modify_qdisc() and calls qdisc_put(q).
5. ets_qdisc_destroy()->ets_offload_destroy() sends TC_ETS_DESTROY
for 2:. That matches ets_handle[port], so
rtl83xx_setup_tc_ets_restore_wfq() clears the handle and writes
WFQ.
The tc command fails and qdisc 1: stays root, but the port now runs
WFQ. Nothing sends the REPLACE for 1: again. A later DESTROY for 1: no
longer matches the cleared handle, so it is ignored.
The comment above describes this outcome. Could the driver remember
the previously offloaded handle and put the port back to strict here?
The two cases look different from the driver's side. On a successful
replace, the old qdisc's DESTROY arrives after the new REPLACE. On a
failed replace, the new qdisc's DESTROY arrives and the old qdisc is
never destroyed.
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130-rtl8365mb-ets-strict-v2-0-9639f6f40499%40pengutronix.de
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-12-01 13:26 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 13:23 [PATCH net-next v2 0/2] net: dsa: realtek: rtl8365mb: offload ETS strict priority Oleksij Rempel
2026-11-30 13:23 ` [PATCH net-next v2 1/2] net: dsa: realtek: rtl8365mb: default the egress scheduler to WFQ Oleksij Rempel
2026-11-30 13:23 ` [PATCH net-next v2 2/2] net: dsa: realtek: rtl8365mb: offload ETS strict priority scheduling Oleksij Rempel
2026-12-01 13:26 ` 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