From: Mieczyslaw Nalewaj <namiltd@yahoo.com>
To: linusw@kernel.org, andrew@lunn.ch, olteanv@gmail.com,
kuba@kernel.org, davem@davemloft.net, edumazet@google.com,
pabeni@redhat.com, linux@armlinux.org.uk, luizluca@gmail.com,
maxime.chevallier@bootlin.com, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, alvin.sipraga@analog.com,
gusfmora@gmail.com, kuncy7@gmail.com, fabianotassotti@gmail.com,
gabonpivovich@gmail.com, contact@c127.dev
Subject: [PATCH net-next v13 13/14] net: dsa: realtek: rtl8365mb: use PCP numbering on family D
Date: Sun, 22 Nov 2026 10:49:32 +0100 [thread overview]
Message-ID: <f5adc725-64fd-4aa5-b76f-b817528ba1be@yahoo.com> (raw)
In-Reply-To: <3f1826f8-3096-40dd-a278-c70fce4852c8@yahoo.com>
Family C has separate per-port registers for the 802.1p PCP given to
untagged frames (0x0851-0x0852) and for the port's default internal
priority (0x0877-0x0878). The shared QoS layer hands the backend internal
priorities that are 802.1Q traffic types (Best Effort is 1, Background is
0) and writes the untagged PCP separately.
Family D has no 0x0851-0x0852 registers: its per-port PVID register at
0x0700 + port holds only the 12-bit VID, and
dal_rtl8367d_vlan_portPvid_set() rejects any priority != 0. On an
RTL8367S-VB the PCP of a newly inserted 802.1Q tag follows the frame's
internal priority, so writing the traffic type as is made untagged
frames leave an egress-tagged port with PCP 1 (Background) instead of
PCP 0 (Best Effort).
The vendor API numbers family D internal priorities like PCP values:
dal_rtl8367d_qos_init() maps each PCP to the same internal priority, sets
the port priority to 0 and keeps 1p remarking disabled. Do the same.
On family D only, convert between traffic types and the chip's numbering
at the register boundary: for the port priority, the PCP-to-priority and
DSCP-to-priority tables, and the priority-to-queue table. The PCP of a
newly inserted tag then matches the traffic type whichever source
classified the frame, and each traffic type still lands in the same
queue as before.
The PCP of untagged frames cannot differ from the one the port priority
implies, so rtl8365mb_qos_set_port_prio() returns -EOPNOTSUPP on family D
for a mismatching @untag_pcp. The shared layer never asks for one.
Tested by Gustavo Foletto Mora on a TP-Link EX511 v2 with the baseline
QoS configuration (no CONFIG_DCB): untagged frames leave tagged with PCP
0, tagged frames keep their PCP, and the QoS registers read back in PCP
numbering.
Reported-by: Gustavo Foletto Mora <gusfmora@gmail.com>
Closes: https://github.com/openwrt/openwrt/pull/19644#issuecomment-7067296792
Tested-by: Gustavo Foletto Mora <gusfmora@gmail.com>
Signed-off-by: Mieczyslaw Nalewaj <namiltd@yahoo.com>
---
drivers/net/dsa/realtek/rtl8365mb_qos.c | 111 +++++++++++++++++++-----
1 file changed, 90 insertions(+), 21 deletions(-)
diff --git a/drivers/net/dsa/realtek/rtl8365mb_qos.c b/drivers/net/dsa/realtek/rtl8365mb_qos.c
index 5b9e1ab..c06d684 100644
--- a/drivers/net/dsa/realtek/rtl8365mb_qos.c
+++ b/drivers/net/dsa/realtek/rtl8365mb_qos.c
@@ -18,10 +18,15 @@
#include <net/ieee8021q.h>
#include "realtek.h"
+#include "rtl8365mb.h"
#include "rtl8365mb_qos.h"
-/* The chip's eight internal priorities carry 802.1Q traffic types, one
- * internal priority per traffic type.
+/* The shared rtl83xx-qos.c layer hands this backend internal priorities
+ * that are 802.1Q traffic types, one per traffic type. Family C stores them
+ * as they are. Family D numbers its internal priorities like PCP values, as
+ * its vendor API does, and takes the PCP of a newly inserted 802.1Q tag from
+ * the internal priority, so it is converted at the register boundary (see
+ * rtl8365mb_qos_iprio_to_hw()).
*/
static_assert(RTL8365MB_NUM_INTERNAL_PRIOS == IEEE8021Q_TT_MAX);
@@ -65,7 +70,9 @@ static_assert(RTL8365MB_QOS_QMAP_DEFAULT < RTL8365MB_QOS_NUM_QMAPS);
#define RTL8365MB_QOS_1Q_REMAP_REG(_pcp) \
(0x0865 + (_pcp) / RTL8365MB_QOS_SELS_PER_REG)
-/* PCP given to untagged frames, one 3-bit field per port */
+/* PCP given to untagged frames, one 3-bit field per port (family C only;
+ * family D has no such register, see rtl8365mb_qos_set_port_prio())
+ */
#define RTL8365MB_QOS_PORT_UNTAG_PCP_REG(_p) \
(0x0851 + (_p) / RTL8365MB_QOS_SELS_PER_REG)
@@ -218,11 +225,37 @@ static int rtl8365mb_qos_check_port(struct realtek_priv *priv, int port)
return 0;
}
+/* Convert an internal priority (an 802.1Q traffic type) to the value the
+ * chip uses. Return the value or a negative errno.
+ */
+static int rtl8365mb_qos_iprio_to_hw(struct realtek_priv *priv, u8 iprio)
+{
+ if (rtl8365mb_is_d(priv))
+ return ieee8021q_tt_to_pcp(iprio);
+
+ return iprio;
+}
+
+/* Convert a chip priority back to an internal priority (a traffic type) */
+static int rtl8365mb_qos_hw_to_iprio(struct realtek_priv *priv, u8 hw)
+{
+ if (rtl8365mb_is_d(priv))
+ return ieee8021q_pcp_to_tt(hw);
+
+ return hw;
+}
+
int rtl8365mb_qos_get_port_prio(struct realtek_priv *priv, int port)
{
- return rtl8365mb_qos_regmap_read_field(priv,
- RTL8365MB_QOS_PORT_PRI_REG(port),
- rtl8365mb_qos_sel_mask(port));
+ int val;
+
+ val = rtl8365mb_qos_regmap_read_field(priv,
+ RTL8365MB_QOS_PORT_PRI_REG(port),
+ rtl8365mb_qos_sel_mask(port));
+ if (val < 0)
+ return val;
+
+ return rtl8365mb_qos_hw_to_iprio(priv, val);
}
int rtl8365mb_qos_set_port_prio(struct realtek_priv *priv, int port, u8 iprio,
@@ -231,41 +264,69 @@ int rtl8365mb_qos_set_port_prio(struct realtek_priv *priv, int port, u8 iprio,
u32 untag_reg = RTL8365MB_QOS_PORT_UNTAG_PCP_REG(port);
u32 reg = RTL8365MB_QOS_PORT_PRI_REG(port);
u32 mask = rtl8365mb_qos_sel_mask(port);
- int ret;
+ int hw, ret;
ret = rtl8365mb_qos_check_port(priv, port);
if (ret)
return ret;
- ret = rtl8365mb_qos_regmap_update_field(priv, untag_reg, mask,
- untag_pcp);
- if (ret)
- return ret;
+ hw = rtl8365mb_qos_iprio_to_hw(priv, iprio);
+ if (hw < 0)
+ return hw;
+
+ if (rtl8365mb_is_d(priv)) {
+ /* No separate PCP for untagged frames: it is the one the
+ * port priority implies, so a different one cannot be set.
+ */
+ if (untag_pcp != hw)
+ return -EOPNOTSUPP;
+ } else {
+ ret = rtl8365mb_qos_regmap_update_field(priv, untag_reg, mask,
+ untag_pcp);
+ if (ret)
+ return ret;
+ }
- return rtl8365mb_qos_regmap_update_field(priv, reg, mask, iprio);
+ return rtl8365mb_qos_regmap_update_field(priv, reg, mask, hw);
}
int rtl8365mb_qos_set_pcp_prio(struct realtek_priv *priv, u8 pcp, u8 iprio)
{
u32 reg = RTL8365MB_QOS_1Q_REMAP_REG(pcp);
u32 mask = rtl8365mb_qos_sel_mask(pcp);
+ int hw;
- return rtl8365mb_qos_regmap_update_field(priv, reg, mask, iprio);
+ hw = rtl8365mb_qos_iprio_to_hw(priv, iprio);
+ if (hw < 0)
+ return hw;
+
+ return rtl8365mb_qos_regmap_update_field(priv, reg, mask, hw);
}
int rtl8365mb_qos_get_dscp_prio(struct realtek_priv *priv, u8 dscp)
{
- return rtl8365mb_qos_regmap_read_field(priv,
- RTL8365MB_QOS_DSCP_PRI_REG(dscp),
- rtl8365mb_qos_sel_mask(dscp));
+ int val;
+
+ val = rtl8365mb_qos_regmap_read_field(priv,
+ RTL8365MB_QOS_DSCP_PRI_REG(dscp),
+ rtl8365mb_qos_sel_mask(dscp));
+ if (val < 0)
+ return val;
+
+ return rtl8365mb_qos_hw_to_iprio(priv, val);
}
int rtl8365mb_qos_set_dscp_prio(struct realtek_priv *priv, u8 dscp, u8 iprio)
{
u32 reg = RTL8365MB_QOS_DSCP_PRI_REG(dscp);
u32 mask = rtl8365mb_qos_sel_mask(dscp);
+ int hw;
- return rtl8365mb_qos_regmap_update_field(priv, reg, mask, iprio);
+ hw = rtl8365mb_qos_iprio_to_hw(priv, iprio);
+ if (hw < 0)
+ return hw;
+
+ return rtl8365mb_qos_regmap_update_field(priv, reg, mask, hw);
}
static int rtl8365mb_qos_set_port_qmap(struct realtek_priv *priv, int port,
@@ -306,19 +367,27 @@ int rtl8365mb_qos_qmap_init(struct realtek_priv *priv)
{
unsigned int nq = priv->ds.num_tx_queues;
struct dsa_port *dp;
- int iprio, ret;
+ int prio, ret;
- for (iprio = 0; iprio < RTL8365MB_NUM_INTERNAL_PRIOS; iprio++) {
- int tc = ieee8021q_tt_to_tc(iprio, nq);
+ /* The table is indexed by the chip's priority, which is the traffic
+ * type on family C and the PCP on family D.
+ */
+ for (prio = 0; prio < RTL8365MB_NUM_INTERNAL_PRIOS; prio++) {
+ int tt = rtl8365mb_qos_hw_to_iprio(priv, prio);
+ int tc;
u8 qid;
+ if (tt < 0)
+ return tt;
+
+ tc = ieee8021q_tt_to_tc(tt, nq);
if (tc < 0)
return tc;
qid = rtl8365mb_qos_tc_to_qid(nq, tc);
ret = rtl8365mb_qos_set_qmap_qid(priv,
RTL8365MB_QOS_QMAP_DEFAULT,
- iprio, qid);
+ prio, qid);
if (ret)
return ret;
}
--
2.53.0
next prev parent reply other threads:[~2026-11-22 9:49 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <3f1826f8-3096-40dd-a278-c70fce4852c8.ref@yahoo.com>
2026-11-22 9:35 ` [PATCH net-next v13 00/14] net: dsa: realtek: rtl8365mb: add support for RTL8367S-VB Mieczyslaw Nalewaj
2026-11-22 9:36 ` [PATCH net-next v13 01/14] dt-bindings: net: dsa: realtek: add RTL8367S-VB Mieczyslaw Nalewaj
2026-11-22 9:37 ` [PATCH net-next v13 02/14] net: dsa: realtek: rtl8365mb: add chip family infrastructure Mieczyslaw Nalewaj
2026-11-22 9:38 ` [PATCH net-next v13 03/14] net: dsa: realtek: rtl8365mb: refactor forcemode handling Mieczyslaw Nalewaj
2026-11-22 9:39 ` [PATCH net-next v13 04/14] net: dsa: realtek: rtl8365mb: set speed for family D Mieczyslaw Nalewaj
2026-11-22 9:41 ` [PATCH net-next v13 05/14] net: dsa: realtek: rtl8365mb: set RGMII mode " Mieczyslaw Nalewaj
2026-11-22 9:42 ` [PATCH net-next v13 06/14] net: dsa: realtek: rtl8365mb: refactor VLAN 4k handling Mieczyslaw Nalewaj
2026-11-22 9:43 ` [PATCH net-next v13 07/14] net: dsa: realtek: rtl8365mb: set and get vlan 4k for family D Mieczyslaw Nalewaj
2026-11-22 9:44 ` [PATCH net-next v13 08/14] net: dsa: realtek: rtl8365mb: refactor PVID handling Mieczyslaw Nalewaj
2026-11-22 9:45 ` [PATCH net-next v13 09/14] net: dsa: realtek: rtl8365mb: use raw VID for PVID on family D Mieczyslaw Nalewaj
2026-11-22 9:46 ` [PATCH net-next v13 10/14] net: dsa: realtek: rtl8365mb: add family D SDS13 PCS support Mieczyslaw Nalewaj
2026-11-22 9:47 ` [PATCH net-next v13 11/14] net: dsa: realtek: rtl8365mb: refactor L2 MAC handling Mieczyslaw Nalewaj
2026-11-22 9:48 ` [PATCH net-next v13 12/14] net: dsa: realtek: rtl8365mb: make L2/LUT access work on family D Mieczyslaw Nalewaj
2026-11-22 9:49 ` Mieczyslaw Nalewaj [this message]
2026-11-22 9:50 ` [PATCH net-next v13 14/14] net: dsa: realtek: rtl8365mb: add support for RTL8367S-VB Mieczyslaw Nalewaj
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f5adc725-64fd-4aa5-b76f-b817528ba1be@yahoo.com \
--to=namiltd@yahoo.com \
--cc=alvin.sipraga@analog.com \
--cc=andrew@lunn.ch \
--cc=contact@c127.dev \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=fabianotassotti@gmail.com \
--cc=gabonpivovich@gmail.com \
--cc=gusfmora@gmail.com \
--cc=kuba@kernel.org \
--cc=kuncy7@gmail.com \
--cc=linusw@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=luizluca@gmail.com \
--cc=maxime.chevallier@bootlin.com \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®