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 v15 13/15] net: dsa: realtek: rtl8365mb: refactor QoS priority handling
Date: Sat, 28 Nov 2026 01:09:49 +0100 [thread overview]
Message-ID: <e81275c4-51d1-4974-9197-5925f9799d38@yahoo.com> (raw)
In-Reply-To: <790b9ea4-09d9-4a57-a393-cf10d58ed8cf@yahoo.com>
The shared QoS layer hands the backend internal priorities that are
802.1Q traffic types, and the backend stores them in the chip as they
are, together with a separate per-port PCP for untagged frames. Family D
numbers its internal priorities differently and has no separate
untagged-PCP register, which the next patch adds.
Move the conversion between a traffic type and the chip's priority, and
the programming of the PCP of untagged frames, behind three new hooks in
struct rtl8365mb_family_info, as for the VLAN, PVID and L2 helpers:
qos_iprio_to_hw, qos_hw_to_iprio and qos_set_untag_pcp. The existing
behaviour becomes the family C implementation: the traffic type is
stored as it is and the untagged PCP register is written as before.
rtl8365mb_qos_qmap_init() now iterates over the chip's priorities and
converts each one back to its traffic type. Name the qmap index
hw_prio throughout, because it is already in the chip's numbering.
No functional change.
Tested-by: Gustavo Foletto Mora <gusfmora@gmail.com>
Signed-off-by: Mieczyslaw Nalewaj <namiltd@yahoo.com>
---
drivers/net/dsa/realtek/rtl8365mb.h | 25 +++++
drivers/net/dsa/realtek/rtl8365mb_main.c | 3 +
drivers/net/dsa/realtek/rtl8365mb_qos.c | 119 ++++++++++++++++++-----
drivers/net/dsa/realtek/rtl8365mb_qos.h | 8 +-
4 files changed, 129 insertions(+), 26 deletions(-)
diff --git a/drivers/net/dsa/realtek/rtl8365mb.h b/drivers/net/dsa/realtek/rtl8365mb.h
index 9a69e85..7fb1a46 100644
--- a/drivers/net/dsa/realtek/rtl8365mb.h
+++ b/drivers/net/dsa/realtek/rtl8365mb.h
@@ -16,6 +16,27 @@ struct rtl8365mb_vlan4k;
struct rtl8365mb_l2_uc;
struct rtl8365mb_l2_mc;
+/**
+ * struct rtl8365mb_family_info - family-specific data and operations
+ * @family: silicon family identifier
+ * @jam_table: family-specific initialization jam table
+ * @jam_size: number of entries in @jam_table
+ * @ext_config_forcemode: program an external interface force-mode register
+ * @vlan_4k_read: read a 4K VLAN table entry
+ * @vlan_4k_write: write a 4K VLAN table entry
+ * @vlan_port_get_pvid: read a port PVID
+ * @vlan_port_reset_pvid: restore a port PVID to its default
+ * @vlan_pvid_port_set: add a port to a PVID
+ * @vlan_pvid_port_clear: remove a port from a PVID
+ * @l2_entry_size: number of words in an L2 table entry
+ * @l2_data_to_uc: unpack a unicast L2 table entry
+ * @l2_uc_to_data: pack a unicast L2 table entry
+ * @l2_data_to_mc: unpack a multicast L2 table entry
+ * @l2_mc_to_data: pack a multicast L2 table entry
+ * @qos_iprio_to_hw: convert a traffic type to a hardware priority
+ * @qos_hw_to_iprio: convert a hardware priority to a traffic type
+ * @qos_set_untag_pcp: program the per-port untagged PCP where supported
+ */
struct rtl8365mb_family_info {
enum rtl8365mb_family family;
const struct rtl8365mb_jam_tbl_entry *jam_table;
@@ -38,6 +59,10 @@ struct rtl8365mb_family_info {
void (*l2_uc_to_data)(const struct rtl8365mb_l2_uc *uc, u16 *data);
void (*l2_data_to_mc)(const u16 *data, struct rtl8365mb_l2_mc *mc);
void (*l2_mc_to_data)(const struct rtl8365mb_l2_mc *mc, u16 *data);
+ int (*qos_iprio_to_hw)(u8 iprio);
+ int (*qos_hw_to_iprio)(u8 hw);
+ int (*qos_set_untag_pcp)(struct realtek_priv *priv, int port,
+ u8 untag_pcp);
};
const struct rtl8365mb_family_info *
diff --git a/drivers/net/dsa/realtek/rtl8365mb_main.c b/drivers/net/dsa/realtek/rtl8365mb_main.c
index 7062c58..81c35f4 100644
--- a/drivers/net/dsa/realtek/rtl8365mb_main.c
+++ b/drivers/net/dsa/realtek/rtl8365mb_main.c
@@ -840,6 +840,9 @@ static const struct rtl8365mb_family_info rtl8365mb_family_c = {
.l2_uc_to_data = rtl8365mb_c_l2_uc_to_data,
.l2_data_to_mc = rtl8365mb_c_l2_data_to_mc,
.l2_mc_to_data = rtl8365mb_c_l2_mc_to_data,
+ .qos_iprio_to_hw = rtl8365mb_c_qos_iprio_to_hw,
+ .qos_hw_to_iprio = rtl8365mb_c_qos_hw_to_iprio,
+ .qos_set_untag_pcp = rtl8365mb_c_qos_set_untag_pcp,
};
/**
diff --git a/drivers/net/dsa/realtek/rtl8365mb_qos.c b/drivers/net/dsa/realtek/rtl8365mb_qos.c
index 5b9e1ab..d422955 100644
--- a/drivers/net/dsa/realtek/rtl8365mb_qos.c
+++ b/drivers/net/dsa/realtek/rtl8365mb_qos.c
@@ -18,10 +18,12 @@
#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. The chip's own priority is derived from
+ * them through the qos_* hooks of struct rtl8365mb_family_info.
*/
static_assert(RTL8365MB_NUM_INTERNAL_PRIOS == IEEE8021Q_TT_MAX);
@@ -40,12 +42,12 @@ static_assert(RTL8365MB_QOS_SEL_BITS <= RTL8365MB_QOS_SEL_STRIDE);
static_assert(RTL8365MB_QOS_SEL_STRIDE * RTL8365MB_QOS_SELS_PER_REG <=
RTL8365MB_QOS_REG_BITS);
-/* qmaps: the queue id of each internal priority, one table per qmap */
+/* qmaps: the queue id of each hardware priority, one table per qmap */
#define RTL8365MB_QOS_QMAP_TBL_REGS \
(RTL8365MB_NUM_INTERNAL_PRIOS / RTL8365MB_QOS_SELS_PER_REG)
-#define RTL8365MB_QOS_QMAP_TBL_REG(_m, _iprio) \
+#define RTL8365MB_QOS_QMAP_TBL_REG(_m, _hw_prio) \
(0x0904 + (_m) * RTL8365MB_QOS_QMAP_TBL_REGS + \
- (_iprio) / RTL8365MB_QOS_SELS_PER_REG)
+ (_hw_prio) / RTL8365MB_QOS_SELS_PER_REG)
/* The qmap each port reads, one select per port */
#define RTL8365MB_QOS_PORT_QMAP_SEL_REG(_p) \
@@ -218,54 +220,113 @@ static int rtl8365mb_qos_check_port(struct realtek_priv *priv, int port)
return 0;
}
+/* Family C stores the traffic type as the chip's priority */
+int rtl8365mb_c_qos_iprio_to_hw(u8 iprio)
+{
+ return iprio;
+}
+
+int rtl8365mb_c_qos_hw_to_iprio(u8 hw)
+{
+ return hw;
+}
+
+int rtl8365mb_c_qos_set_untag_pcp(struct realtek_priv *priv, int port,
+ u8 untag_pcp)
+{
+ return rtl8365mb_qos_regmap_update_field(priv,
+ RTL8365MB_QOS_PORT_UNTAG_PCP_REG(port),
+ rtl8365mb_qos_sel_mask(port),
+ untag_pcp);
+}
+
+/* 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)
+{
+ return rtl8365mb_get_family_info(priv)->qos_iprio_to_hw(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)
+{
+ return rtl8365mb_get_family_info(priv)->qos_hw_to_iprio(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,
u8 untag_pcp)
{
- 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);
+ hw = rtl8365mb_qos_iprio_to_hw(priv, iprio);
+ if (hw < 0)
+ return hw;
+
+ ret = rtl8365mb_get_family_info(priv)->qos_set_untag_pcp(priv, port,
+ 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,
@@ -280,10 +341,10 @@ static int rtl8365mb_qos_set_port_qmap(struct realtek_priv *priv, int port,
}
static int rtl8365mb_qos_set_qmap_qid(struct realtek_priv *priv, int qmap,
- u8 iprio, u8 qid)
+ u8 hw_prio, u8 qid)
{
- u32 reg = RTL8365MB_QOS_QMAP_TBL_REG(qmap, iprio);
- u32 mask = rtl8365mb_qos_sel_mask(iprio);
+ u32 reg = RTL8365MB_QOS_QMAP_TBL_REG(qmap, hw_prio);
+ u32 mask = rtl8365mb_qos_sel_mask(hw_prio);
return rtl8365mb_qos_regmap_update_field(priv, reg, mask, qid);
}
@@ -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 hw_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, not by the traffic
+ * type.
+ */
+ for (hw_prio = 0; hw_prio < RTL8365MB_NUM_INTERNAL_PRIOS; hw_prio++) {
+ int tt = rtl8365mb_qos_hw_to_iprio(priv, hw_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);
+ hw_prio, qid);
if (ret)
return ret;
}
diff --git a/drivers/net/dsa/realtek/rtl8365mb_qos.h b/drivers/net/dsa/realtek/rtl8365mb_qos.h
index 9602807..70c50ab 100644
--- a/drivers/net/dsa/realtek/rtl8365mb_qos.h
+++ b/drivers/net/dsa/realtek/rtl8365mb_qos.h
@@ -14,7 +14,7 @@ struct realtek_priv;
/* Ports the QoS code handles */
#define RTL8365MB_QOS_MAX_PORTS 8
-/* Internal priority -> queue id tables (qmaps) */
+/* Hardware priority -> queue id tables (qmaps) */
#define RTL8365MB_QOS_NUM_QMAPS 8
int rtl8365mb_qos_pridec_init(struct realtek_priv *priv);
@@ -30,4 +30,10 @@ int rtl8365mb_qos_set_apptrust(struct realtek_priv *priv, int port,
int rtl8365mb_qos_get_apptrust(struct realtek_priv *priv, int port, bool *trust,
unsigned int n);
+/* Hooks of struct rtl8365mb_family_info, one set per chip family */
+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 untag_pcp);
+
#endif /* _REALTEK_RTL8365MB_QOS_H */
--
2.53.0
next prev parent reply other threads:[~2026-11-28 0:09 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <790b9ea4-09d9-4a57-a393-cf10d58ed8cf.ref@yahoo.com>
2026-11-27 23:55 ` [PATCH net-next v15 00/15] net: dsa: realtek: rtl8365mb: add support for RTL8367S-VB Mieczyslaw Nalewaj
2026-11-27 23:57 ` [PATCH net-next v15 01/15] dt-bindings: net: dsa: realtek: add RTL8367S-VB Mieczyslaw Nalewaj
2026-11-27 23:58 ` [PATCH net-next v15 02/15] net: dsa: realtek: rtl8365mb: add chip family infrastructure Mieczyslaw Nalewaj
2026-11-27 23:59 ` [PATCH net-next v15 03/15] net: dsa: realtek: rtl8365mb: refactor forcemode handling Mieczyslaw Nalewaj
2026-11-28 0:00 ` [PATCH net-next v15 04/15] net: dsa: realtek: rtl8365mb: set speed for family D Mieczyslaw Nalewaj
2026-11-28 0:01 ` [PATCH net-next v15 05/15] net: dsa: realtek: rtl8365mb: set RGMII mode " Mieczyslaw Nalewaj
2026-11-28 0:02 ` [PATCH net-next v15 06/15] net: dsa: realtek: rtl8365mb: refactor VLAN 4k handling Mieczyslaw Nalewaj
2026-11-28 0:04 ` [PATCH net-next v15 07/15] net: dsa: realtek: rtl8365mb: set and get VLAN 4k for family D Mieczyslaw Nalewaj
2026-11-28 0:04 ` [PATCH net-next v15 08/15] net: dsa: realtek: rtl8365mb: refactor PVID handling Mieczyslaw Nalewaj
2026-11-28 0:05 ` [PATCH net-next v15 09/15] net: dsa: realtek: rtl8365mb: use raw VID for PVID on family D Mieczyslaw Nalewaj
2026-11-28 0:06 ` [PATCH net-next v15 10/15] net: dsa: realtek: rtl8365mb: add family D SDS13 PCS support Mieczyslaw Nalewaj
2026-11-28 0:07 ` [PATCH net-next v15 11/15] net: dsa: realtek: rtl8365mb: refactor L2 MAC handling Mieczyslaw Nalewaj
2026-11-28 0:08 ` [PATCH net-next v15 12/15] net: dsa: realtek: rtl8365mb: make L2/LUT access work on family D Mieczyslaw Nalewaj
2026-11-28 0:09 ` Mieczyslaw Nalewaj [this message]
2026-11-28 0:10 ` [PATCH net-next v15 14/15] net: dsa: realtek: rtl8365mb: use PCP numbering " Mieczyslaw Nalewaj
2026-11-28 0:11 ` [PATCH net-next v15 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=e81275c4-51d1-4974-9197-5925f9799d38@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®