mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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,
	o.rempel@pengutronix.de
Subject: [PATCH net-next v14 14/15] net: dsa: realtek: rtl8365mb: use PCP numbering on family D
Date: Wed, 25 Nov 2026 01:13:00 +0100	[thread overview]
Message-ID: <fd7d2df4-3994-4091-a63f-7ba57310cedc@yahoo.com> (raw)
In-Reply-To: <874b29a3-f47f-4bf2-a0f6-2f9fea712f4c@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, 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.

Add the family D implementations of the qos_iprio_to_hw, qos_hw_to_iprio
and qos_set_untag_pcp hooks introduced by the previous patch. The PCP of
untagged frames cannot differ from the one the port priority implies, so
the family D qos_set_untag_pcp hook returns -EOPNOTSUPP for a mismatching
@untag_pcp. The shared layer never asks for one. As for the other family
D functions, the hooks are wired up by the patch that adds the first
family D chip, so this patch changes no behaviour yet.

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. Trusting PCP (dcb apptrust) together with a non-zero default
priority was not tested on family D, so it is not known whether the chip
then classifies untagged frames by that priority or by PCP 0.

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 | 36 +++++++++++++++++++++----
 drivers/net/dsa/realtek/rtl8365mb_qos.h |  4 +++
 2 files changed, 35 insertions(+), 5 deletions(-)

diff --git a/drivers/net/dsa/realtek/rtl8365mb_qos.c b/drivers/net/dsa/realtek/rtl8365mb_qos.c
index b61ffdb..23e1ebb 100644
--- a/drivers/net/dsa/realtek/rtl8365mb_qos.c
+++ b/drivers/net/dsa/realtek/rtl8365mb_qos.c
@@ -21,8 +21,12 @@
 #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 converts them at the register boundary
+ * through the qos_* hooks of struct rtl8365mb_family_info.
  */
 static_assert(RTL8365MB_NUM_INTERNAL_PRIOS == IEEE8021Q_TT_MAX);
 
@@ -66,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_d_qos_set_untag_pcp())
+ */
 #define RTL8365MB_QOS_PORT_UNTAG_PCP_REG(_p) \
 	(0x0851 + (_p) / RTL8365MB_QOS_SELS_PER_REG)
 
@@ -239,6 +245,26 @@ int rtl8365mb_c_qos_set_untag_pcp(struct realtek_priv *priv, int port,
 						 untag_pcp);
 }
 
+/* Family D numbers its internal priorities like PCP values */
+int rtl8365mb_d_qos_iprio_to_hw(u8 iprio)
+{
+	return ieee8021q_tt_to_pcp(iprio);
+}
+
+int rtl8365mb_d_qos_hw_to_iprio(u8 hw)
+{
+	return ieee8021q_pcp_to_tt(hw);
+}
+
+/* There is no separate PCP for untagged frames: it is the one the port
+ * priority implies, so a different one cannot be set.
+ */
+int rtl8365mb_d_qos_set_untag_pcp(struct realtek_priv *priv, int port,
+				  u8 hw_prio, u8 untag_pcp)
+{
+	return untag_pcp == hw_prio ? 0 : -EOPNOTSUPP;
+}
+
 /* Convert an internal priority (an 802.1Q traffic type) to the value the
  * chip uses. Return the value or a negative errno.
  */
@@ -368,8 +394,8 @@ int rtl8365mb_qos_qmap_init(struct realtek_priv *priv)
 	struct dsa_port *dp;
 	int prio, ret;
 
-	/* The table is indexed by the chip's priority, not by the traffic
-	 * type.
+	/* 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);
diff --git a/drivers/net/dsa/realtek/rtl8365mb_qos.h b/drivers/net/dsa/realtek/rtl8365mb_qos.h
index d68b2bd..ec88eb2 100644
--- a/drivers/net/dsa/realtek/rtl8365mb_qos.h
+++ b/drivers/net/dsa/realtek/rtl8365mb_qos.h
@@ -35,5 +35,9 @@ int rtl8365mb_c_qos_iprio_to_hw(u8 iprio);
 int rtl8365mb_c_qos_hw_to_iprio(u8 hw);
 int rtl8365mb_c_qos_set_untag_pcp(struct realtek_priv *priv, int port,
 				  u8 hw_prio, u8 untag_pcp);
+int rtl8365mb_d_qos_iprio_to_hw(u8 iprio);
+int rtl8365mb_d_qos_hw_to_iprio(u8 hw);
+int rtl8365mb_d_qos_set_untag_pcp(struct realtek_priv *priv, int port,
+				  u8 hw_prio, u8 untag_pcp);
 
 #endif /* _REALTEK_RTL8365MB_QOS_H */
-- 
2.53.0


  parent reply	other threads:[~2026-11-25  0:13 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <874b29a3-f47f-4bf2-a0f6-2f9fea712f4c.ref@yahoo.com>
2026-11-24 23:59 ` [PATCH net-next v14 00/15] net: dsa: realtek: rtl8365mb: add support for RTL8367S-VB Mieczyslaw Nalewaj
2026-11-25  0:00   ` [PATCH net-next v14 01/15] dt-bindings: net: dsa: realtek: add RTL8367S-VB Mieczyslaw Nalewaj
2026-11-25  0:01   ` [PATCH net-next v14 02/15] net: dsa: realtek: rtl8365mb: add chip family infrastructure Mieczyslaw Nalewaj
2026-11-25  0:02   ` [PATCH net-next v14 03/15] net: dsa: realtek: rtl8365mb: refactor forcemode handling Mieczyslaw Nalewaj
2026-11-25  0:03   ` [PATCH net-next v14 04/15] net: dsa: realtek: rtl8365mb: set speed for family D Mieczyslaw Nalewaj
2026-11-25  0:04   ` [PATCH net-next v14 05/15] net: dsa: realtek: rtl8365mb: set RGMII mode " Mieczyslaw Nalewaj
2026-11-25  0:05   ` [PATCH net-next v14 06/15] net: dsa: realtek: rtl8365mb: refactor VLAN 4k handling Mieczyslaw Nalewaj
2026-11-25  0:06   ` [PATCH net-next v14 07/15] net: dsa: realtek: rtl8365mb: set and get vlan 4k for family D Mieczyslaw Nalewaj
2026-11-25  0:07   ` [PATCH net-next v14 08/15] net: dsa: realtek: rtl8365mb: refactor PVID handling Mieczyslaw Nalewaj
2026-11-25  0:08   ` [PATCH net-next v14 09/15] net: dsa: realtek: rtl8365mb: use raw VID for PVID on family D Mieczyslaw Nalewaj
2026-11-25  0:09   ` [PATCH net-next v14 10/15] net: dsa: realtek: rtl8365mb: add family D SDS13 PCS support Mieczyslaw Nalewaj
2026-11-25  0:10   ` [PATCH net-next v14 11/15] net: dsa: realtek: rtl8365mb: refactor L2 MAC handling Mieczyslaw Nalewaj
2026-11-25  0:11   ` [PATCH net-next v14 12/15] net: dsa: realtek: rtl8365mb: make L2/LUT access work on family D Mieczyslaw Nalewaj
2026-11-25  0:12   ` [PATCH net-next v14 13/15] net: dsa: realtek: rtl8365mb: refactor QoS priority handling Mieczyslaw Nalewaj
2026-11-25  0:13   ` Mieczyslaw Nalewaj [this message]
2026-11-25  0:14   ` [PATCH net-next v14 15/15] 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=fd7d2df4-3994-4091-a63f-7ba57310cedc@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=o.rempel@pengutronix.de \
    --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®