From: Oleksij Rempel <o.rempel@pengutronix.de>
To: Linus Walleij <linusw@kernel.org>,
Luiz Angelo Daros de Luca <luizluca@gmail.com>,
Andrew Lunn <andrew@lunn.ch>, Vladimir Oltean <olteanv@gmail.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: "Oleksij Rempel" <o.rempel@pengutronix.de>,
kernel@pengutronix.de, linux-kernel@vger.kernel.org,
"Alvin Šipraga" <alvin.sipraga@analog.com>,
netdev@vger.kernel.org, "Simon Horman" <horms@kernel.org>
Subject: [PATCH net-next v1 4/8] net: ieee8021q: add tt_to_pcp()
Date: Fri, 2 Oct 2026 13:58:46 +0200 [thread overview]
Message-ID: <20261002115850.962676-5-o.rempel@pengutronix.de> (raw)
In-Reply-To: <20261002115850.962676-1-o.rempel@pengutronix.de>
Add ieee8021q_tt_to_pcp(), the inverse of ieee8021q_pcp_to_tt(): it
encodes an 802.1Q traffic type back to its Priority Code Point, and
completes the pcp/tt helper family.
A driver that reseeds its PCP classifier through ieee8021q_pcp_to_tt()
stores traffic types in the hardware tables, while the dcbnl priority
ops exchange 802.1p priorities across the DSA boundary. Reading such a
table back therefore needs the reverse mapping to restore the 802.1p
value, which no existing helper provides. Because pcp_to_tt only
transposes Best Effort and Background and is the identity elsewhere the
two directions are numerically equal; provide tt_to_pcp as its own named
function so the read path does not decode a traffic type as if it were a
PCP.
The first user is the Realtek rtl8365mb DSA driver, whose dcbnl
get_default_prio and get_dscp_prio paths read back traffic types and
must return 802.1p priorities.
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
include/net/ieee8021q.h | 6 ++++++
net/core/ieee8021q_helpers.c | 40 ++++++++++++++++++++++++++++++++++++
2 files changed, 46 insertions(+)
diff --git a/include/net/ieee8021q.h b/include/net/ieee8021q.h
index d24e4036577b..b09572da0289 100644
--- a/include/net/ieee8021q.h
+++ b/include/net/ieee8021q.h
@@ -39,6 +39,7 @@ enum ieee8021q_traffic_type {
int ietf_dscp_to_ieee8021q_tt(u8 dscp);
int ieee8021q_pcp_to_tt(u8 pcp);
+int ieee8021q_tt_to_pcp(enum ieee8021q_traffic_type tt);
int ieee8021q_tt_to_tc(enum ieee8021q_traffic_type tt, unsigned int num_queues);
#else
@@ -53,6 +54,11 @@ static inline int ieee8021q_pcp_to_tt(u8 pcp)
return -EOPNOTSUPP;
}
+static inline int ieee8021q_tt_to_pcp(enum ieee8021q_traffic_type tt)
+{
+ return -EOPNOTSUPP;
+}
+
static inline int ieee8021q_tt_to_tc(enum ieee8021q_traffic_type tt,
unsigned int num_queues)
{
diff --git a/net/core/ieee8021q_helpers.c b/net/core/ieee8021q_helpers.c
index 520d86d592eb..205c11793473 100644
--- a/net/core/ieee8021q_helpers.c
+++ b/net/core/ieee8021q_helpers.c
@@ -267,3 +267,43 @@ int ieee8021q_pcp_to_tt(u8 pcp)
return -EINVAL;
}
EXPORT_SYMBOL_GPL(ieee8021q_pcp_to_tt);
+
+/**
+ * ieee8021q_tt_to_pcp - Map an IEEE 802.1Q traffic type to a PCP
+ * @tt: IEEE 802.1Q traffic type
+ *
+ * Encode @tt back to its IEEE 802.1Q Priority Code Point per Table I-7
+ * ("Priority Code Point decoding") for the 8P0D encoding, the inverse of
+ * ieee8021q_pcp_to_tt(). It is nearly the identity, except traffic types Best
+ * Effort and Background map to swapped PCP values: Best Effort is the default
+ * (PCP 0) despite being higher priority than Background (PCP 1) (Table I-2:
+ * BE = priority 0, BK = priority 1).
+ *
+ * Return: the PCP value, or a negative value on error.
+ */
+int ieee8021q_tt_to_pcp(enum ieee8021q_traffic_type tt)
+{
+ switch (tt) {
+ case IEEE8021Q_TT_BK:
+ return 1;
+ case IEEE8021Q_TT_BE:
+ return 0;
+ case IEEE8021Q_TT_EE:
+ return 2;
+ case IEEE8021Q_TT_CA:
+ return 3;
+ case IEEE8021Q_TT_VI:
+ return 4;
+ case IEEE8021Q_TT_VO:
+ return 5;
+ case IEEE8021Q_TT_IC:
+ return 6;
+ case IEEE8021Q_TT_NC:
+ return 7;
+ case IEEE8021Q_TT_MAX:
+ break;
+ }
+
+ return -EINVAL;
+}
+EXPORT_SYMBOL_GPL(ieee8021q_tt_to_pcp);
--
2.47.3
next prev parent reply other threads:[~2026-10-02 11:58 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-02 11:58 [PATCH net-next v1 0/8] net: dsa: realtek: rtl8365mb: DCB ingress QoS offload Oleksij Rempel
2026-10-02 11:58 ` [PATCH net-next v1 1/8] net: ieee8021q: print traffic type and queue count with %u Oleksij Rempel
2026-10-02 14:22 ` Luiz Angelo Daros de Luca
2026-10-05 15:04 ` Linus Walleij
2026-10-02 11:58 ` [PATCH net-next v1 2/8] net: ieee8021q: add pcp_to_tt() Oleksij Rempel
2026-10-05 15:06 ` Linus Walleij
2026-10-02 11:58 ` [PATCH net-next v1 3/8] net: ieee8021q: clarify the tt_to_tc() traffic-class mapping Oleksij Rempel
2026-10-05 15:07 ` Linus Walleij
2026-10-02 11:58 ` Oleksij Rempel [this message]
2026-10-05 15:08 ` [PATCH net-next v1 4/8] net: ieee8021q: add tt_to_pcp() Linus Walleij
2026-10-02 11:58 ` [PATCH net-next v1 5/8] net: dsa: realtek: rtl8365mb: store the egress queue count per chip Oleksij Rempel
2026-10-05 15:10 ` Linus Walleij
2026-10-05 15:12 ` Linus Walleij
2026-10-02 11:58 ` [PATCH net-next v1 6/8] net: dsa: realtek: rtl8365mb: add QoS baseline and DCB default priority Oleksij Rempel
2026-10-05 23:18 ` Linus Walleij
2026-10-02 11:58 ` [PATCH net-next v1 7/8] net: dsa: realtek: rtl8365mb: offload DCB apptrust Oleksij Rempel
2026-10-05 23:38 ` Linus Walleij
2026-10-06 13:43 ` netdev-bot+sashiko
2026-10-02 11:58 ` [PATCH net-next v1 8/8] net: dsa: realtek: rtl8365mb: offload DCB DSCP-to-priority Oleksij Rempel
2026-10-06 13:43 ` netdev-bot+sashiko
2026-10-05 15:03 ` [PATCH net-next v1 0/8] net: dsa: realtek: rtl8365mb: DCB ingress QoS offload Linus Walleij
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=20261002115850.962676-5-o.rempel@pengutronix.de \
--to=o.rempel@pengutronix.de \
--cc=alvin.sipraga@analog.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=kernel@pengutronix.de \
--cc=kuba@kernel.org \
--cc=linusw@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luizluca@gmail.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