Article View: linux.kernel.netdev
Article #17420[PATCH net-next v3 02/10] net: ieee8021q: add pcp_to_tt()
From: Oleksij Rempel
Date: Mon, 16 Nov 2026 19:10
Date: Mon, 16 Nov 2026 19:10
141 lines
15522 bytes
15522 bytes
Add a helper that maps an IEEE 802.1Q Priority Code Point (PCP) to the
corresponding 802.1Q traffic type, complementing the existing
ietf_dscp_to_ieee8021q_tt().
It is very nearly an identity map, except that PCP 0 (Best Effort) and
PCP 1 (Background) are swapped: per 802.1Q-2022 (Annex I, Table I-2)
Background is a lower priority than Best Effort even though it carries
the higher PCP value. PCP 2..7 map straight through to the matching
traffic type, and values above 7 are rejected with -EINVAL. This decodes
the 8P0D encoding (Table 6-3), where every PCP value is a priority and
none carries drop eligibility.
Drivers that classify ingress traffic by PCP need this to map into a
priority-ordered internal space without misordering Best Effort and
Background. The first consumer, the realtek rtl8365mb DSA driver, lands
later in this series.
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
Reviewed-by: Linus Walleij <linusw@kernel.org>
Reviewed-by: Alvin ล ipraga <alvin.sipraga@analog.com>
Reviewed-by: Luiz Angelo Daros de Luca <luizluca@gmail.com>
---
Changes in v3:
- No changes.
Changes in v2:
- use a lookup table instead of the switch (Luiz)
- check the lookup table size at build time
- kernel-doc: cite Table 6-3 instead of Table I-7, fix the sentence on
7P1D/6P2D/5P3D, document the stub's return value
- commit message: cite Table 6-3 instead of Table I-7
- reword the @IEEE8021Q_TT_BE kernel-doc and the enum title
- keep Linus's Reviewed-by: the mapping is unchanged
---
include/net/ieee8021q.h | 15 ++++++++++++---
net/core/ieee8021q_helpers.c | 42 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 54 insertions(+), 3 deletions(-)
diff --git a/include/net/ieee8021q.h b/include/net/ieee8021q.h
index 8bfe903dd3d00fb432b32e3150d77f3a43d00f0c..c6c8c94ec7fb39603f631d50928f2354bfcd8f81 100644
--- a/include/net/ieee8021q.h
+++ b/include/net/ieee8021q.h
@@ -7,11 +7,14 @@
#include <linux/errno.h>
/**
- * enum ieee8021q_traffic_type - 802.1Q traffic type priority values (802.1Q-2022)
+ * enum ieee8021q_traffic_type - 802.1Q traffic types (802.1Q-2022)
*
* @IEEE8021Q_TT_BK: Background
- * @IEEE8021Q_TT_BE: Best Effort (default). According to 802.1Q-2022, BE is 0
- * but has higher priority than BK which is 1.
+ * @IEEE8021Q_TT_BE: Best Effort (default). The enum value is not the 802.1Q
+ * priority. IEEE 802.1Q-2022 (Annex I.4, Table I-2) gives Best Effort priority
+ * 0 and Background priority 1, and says that priority 1 is lower than priority
+ * 0. The enum orders the traffic types lowest first, so Background is 0 and
+ * Best Effort is 1.
* @IEEE8021Q_TT_EE: Excellent Effort
* @IEEE8021Q_TT_CA: Critical Applications
* @IEEE8021Q_TT_VI: Video, < 100 ms latency and jitter
@@ -38,6 +41,7 @@ enum ieee8021q_traffic_type {
#if IS_ENABLED(CONFIG_NET_IEEE8021Q_HELPERS)
int ietf_dscp_to_ieee8021q_tt(u8 dscp);
+int ieee8021q_pcp_to_tt(u8 pcp);
int ieee8021q_tt_to_tc(enum ieee8021q_traffic_type tt, unsigned int num_queues);
#else
@@ -47,6 +51,11 @@ static inline int ietf_dscp_to_ieee8021q_tt(u8 dscp)
return -EOPNOTSUPP;
}
+static inline int ieee8021q_pcp_to_tt(u8 pcp)
+{
+ 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 bbacdfff9b4c2ec14779baa79d341527fed1920c..b052120e67c525ac5a45b26de4cb879a0d758d17 100644
--- a/net/core/ieee8021q_helpers.c
+++ b/net/core/ieee8021q_helpers.c
@@ -2,6 +2,7 @@
// Copyright (c) 2024 Pengutronix, Oleksij Rempel <kernel@pengutronix.de>
#include <linux/array_size.h>
+#include <linux/if_vlan.h>
#include <linux/printk.h>
#include <linux/types.h>
#include <net/dscp.h>
@@ -222,3 +223,44 @@ int ietf_dscp_to_ieee8021q_tt(u8 dscp)
return SIMPLE_IETF_DSCP_TO_IEEE8021Q_TT(dscp);
}
EXPORT_SYMBOL_GPL(ietf_dscp_to_ieee8021q_tt);
+
+/* Index: the PCP, which in 8P0D is the 802.1Q priority. Priority 0 is Best
+ * Effort and priority 1 Background, the reverse of their enum order.
+ */
+static const u8 ieee8021q_pcp_to_tt_map[] = {
+ [0] = IEEE8021Q_TT_BE,
+ [1] = IEEE8021Q_TT_BK,
+ [2] = IEEE8021Q_TT_EE,
+ [3] = IEEE8021Q_TT_CA,
+ [4] = IEEE8021Q_TT_VI,
+ [5] = IEEE8021Q_TT_VO,
+ [6] = IEEE8021Q_TT_IC,
+ [7] = IEEE8021Q_TT_NC,
+};
+
+static_assert(ARRAY_SIZE(ieee8021q_pcp_to_tt_map) ==
+ (VLAN_PRIO_MASK >> VLAN_PRIO_SHIFT) + 1);
+
+/**
+ * ieee8021q_pcp_to_tt - Map an IEEE 802.1Q PCP to a traffic type
+ * @pcp: IEEE 802.1Q Priority Code Point value
+ *
+ * Decode @pcp with the 8P0D row of Table 6-3 (IEEE 802.1Q-2022, 6.9.3). In that
+ * row the priority equals the PCP, and no PCP carries drop eligibility. Then
+ * look up the traffic type for that priority in Table I-2. The enum values of
+ * Best Effort and Background are not their priorities, see
+ * &enum ieee8021q_traffic_type.
+ *
+ * The other rows of Table 6-3 (7P1D, 6P2D, 5P3D) are not decoded here.
+ *
+ * Return: the traffic type, or -EINVAL if @pcp is above 7. Without
+ * CONFIG_NET_IEEE8021Q_HELPERS, the stub returns -EOPNOTSUPP.
+ */
+int ieee8021q_pcp_to_tt(u8 pcp)
+{
+ if (pcp >= ARRAY_SIZE(ieee8021q_pcp_to_tt_map))
+ return -EINVAL;
+
+ return ieee8021q_pcp_to_tt_map[pcp];
+}
+EXPORT_SYMBOL_GPL(ieee8021q_pcp_to_tt);
--
2.47.3
Technical Details
Message-ID:
<20261116-rtl8365mb-dcb-ingress-v3-2-657f5fdb4db7@pengutronix.de>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-364665-linux-kernel-netdev=dewy.ruReferences:
<20261116-rtl8365mb-dcb-ingress-v3-0-657f5fdb4db7@pengutronix.de>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-364665-linux-kernel-netdev=dewy.ru From: o.rempel@pengutronix.de (Oleksij Rempel) Newsgroups: linux.kernel.netdev Subject: [PATCH net-next v3 02/10] net: ieee8021q: add pcp_to_tt() Date: Mon, 16 Nov 2026 20:10:13 +0100 Organization: Usenet Network Message-ID: <20261116-rtl8365mb-dcb-ingress-v3-2-657f5fdb4db7@pengutronix.de> References: <20261116-rtl8365mb-dcb-ingress-v3-0-657f5fdb4db7@pengutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="2146063"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:eFeDIMbmzpK7YoKWD40tJMq+LnU= sha256:2Oo5HV7RLUyD2VgX7brzIdbZFkG4//IF54zfKyXjWLI= sha1:0IJshvo4+h0CKZZBpSDixyNITKM= sha256:TMSgR36P/krvA+yGej7NpVzrHk4LuL/k4uCm3MDMonU= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id D2826114D4E; Mon, 16 Nov 2026 22:10:50 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.15 X-Spam-Status: No, score=-3.15 tagged_above=-9999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=pengutronix.de X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id CnpPoiYs-9yM; Mon, 16 Nov 2026 22:10:47 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-364665-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=none (p=none dis=none) header.from=pengutronix.de X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74]) by mail.dewy.ru (Postfix) with ESMTPS id F4044114D4A; Mon, 16 Nov 2026 22:10:35 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sto.lore.kernel.org (Postfix) with ESMTP id 13443601DD0; Mon, 16 Nov 2026 19:10:35 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=3; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1794856224; b=BkBp1pOU6SfyA33FXBCAUcTEO5Y2V4Vqtt1N1/SquD/6danIMl1IvhT4XZSsjbGSrWYX 4hcunzL2mYn+aLCG1GPxmZWx0rTuG7swmvkDTEcZEWXlun9LdsZBQK03jjqWLPlRNetjV Q0/qpko9jEyfFhuQxZS+E3fqt2tHsDnr7pkILbghZ2oJG+rKr05Z6pqPYQh2Kv8KbwCod GFRqE9Ld9Yh1M1IbkEbcFAXLlz2DtXMX1hXoqOUO4EiK6CvmJscf3wGXBIeYo0bFmmXGB fPIVps717MPbRw8qMxE3QHYbQRvG/yCNz4SEfCdwQqKsUm1dSbKWaBKGetuku7fsM2w== X-ARC-Message-Signature: i=3; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794856224; h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:Received: From:Date:Subject:X-Mailing-List:List-Id:List-Post:List-Help: List-Subscribe:List-Unsubscribe:List-Owner:Precedence:MIME-Version: Content-Type:Content-Transfer-Encoding:Message-Id:References: In-Reply-To:To:Cc:X-Mailer; bh=yIJjtU/l7LIomhy8OaXZF6t/MLWz3Z2YWmYF9eGCfnc=; b=MUNt0VZ/BGwfj9vRI2LX6v/pCQRbwumaX66ldxdKgdy59VbEsdDR0En1ZrSaR2lf5gMT veYYCZjjx8dlDKB2dDxVns9E6K4s0w9GOzDSsGqXFjAYtOCxmyBLjJnYvCPGGRiQ6MmHF BMO7NTxB4T9cupaipLchqsyNDjyVSlexZYh4kEJLYhGdVUSfL1gHkFAuoDWXBl7I+AFaR /mz2wt4US9eqbHZOG6nAJYBWMtly1Kb52L9iG87vTd6kTTVwk2V5znzoIyWCEg3YeRoTH J3Jas0S7gKTxSRnAvDvArQOkZ0+YWP9LldE1qdyWGylSgcbog6fwEnIY2Pq4ePiyZNA== X-ARC-Authentication-Results: i=3; smtp.subspace.kernel.org; dkim=pass header.d=pengutronix.de header.i=@pengutronix.de header.a=rsa-sha256 header.s=20260414 header.b=TMA13sEf; dmarc=none header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F2BF5606A88E; Mon, 16 Nov 2026 19:10:23 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pengutronix.de header.i=@pengutronix.de header.a=rsa-sha256 header.s=20260414 header.b=TMA13sEf X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=185.203.200.13 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1794856223; b=UmRGQg/VewsTUkxKXdFA4qB5tS0QpHb2wazCUD8fd9gnwbxS+YANAJltM4yEidFjzH1s gI3B3SGBGp0wlSn6Ks126g9nnevpfCthywQGR9RLo1uJkKsWBCX7il+4IgVadrzipYayw vr31PZGvpNNPDs0VFOLZUjWaFNsXL7dfpHQFieZqbi6QJiogW0VIH29xxgQULfEcdti/o c+rHxXLp0Nrxr0GBryBI4EeqeS0mP4PHxlEm7rxTy9l4JGvMYAiziaztusbw5/A00YzWl H5K+Nd3g4pq/wx1zmg4Udqei4phvdFLS4qO4zAMl+f6dD8BlrrTQBxkk4N/BYDVQm9A== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794856223; h=DMARC-Filter:Received:DKIM-Signature:Received:From:Date:Subject: MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id: References:In-Reply-To:To:Cc:X-Mailer; bh=yIJjtU/l7LIomhy8OaXZF6t/MLWz3Z2YWmYF9eGCfnc=; b=eckVKFSNw5pMHdAn5bn0C9GmPzcIj5odqFvwRanxulmztEQUSnfMv8/F4rdB8fG5b66Z qNJDaRZezyvDepMwvhgJAyCPd79gLZ3/spn0+RD3+8N2Bv4mdIjcRynqdYrvL6Jvf76dD qWiKpOI+hZaDFjzvVFDaMm87JDvIowAmpHuAHpn0DWHPjeZbSH9OQg6ltiM7ztoPFOs1g LWVy0QzRN64AzsVCx8bJwBEGnIJ2C+9PFDgsFcAw8c+Y7mvE5kL9syQv/GbB+A1u0rt+f /CPjpDr1j1Rjem4CALyyG19SBMFNSzJjoIRqT5Pk+L/ARsZ5+o4Ik+8hKmHT+mnJZpA== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=none header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; dkim=pass header.d=pengutronix.de header.i=@pengutronix.de header.a=rsa-sha256 header.s=20260414 header.b=TMA13sEf; arc=pass header.oldest-pass=0 smtp.remote-ip=185.203.200.13 X-Received: from mx1.white.stw.pengutronix.de (mx1.white.stw.pengutronix.de [185.203.200.13]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D3246606A322; Mon, 16 Nov 2026 19:10:21 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D3246606A322 X-Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de X-Received: from dude04.red.stw.pengutronix.de (dude04.red.stw.pengutronix.de [IPv6:2a0a:edc0:0:1101:1d::ac]) (Authenticated sender: relay-from-dude04.red.stw.pengutronix.de) by mx1.white.stw.pengutronix.de (Postfix) with ESMTPSA id D22C2205A17; Mon, 16 Nov 2026 20:10:15 +0100 (CET) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pengutronix.de; s=20260414; t=1794856215; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yIJjtU/l7LIomhy8OaXZF6t/MLWz3Z2YWmYF9eGCfnc=; b=TMA13sEfVFicjiGKZw3wIG/z+/nj3mruLDISZtxCgOptdw080ClA+3+fuLuq7M9X4uR+kq aDldvDeEVYbndsBZGVPzx0yVv4fxXFF0fSmLGIcm6JlLuIYN29p3hJ7mNRkaSIqTWp2KB6 pdFmYFbPmB7b6WvhSxxv6UcOsD+D+UhOnZx2ZnBLjVyuCeYcuFYQHlAJ0nOTRf88Kzk4+h pJyKvn4cHtdgeC3XTwnyZuaBfZ3rcvEHzhGYweIn4iqxR3IMz2JgJCjCUV4ySOAsk7LU5r ui6LJIJoizvF8yH+pwRwq6E+a45Konjwp7OkpzkBQpoK3r4QIlIh+TIxf+id0A== X-ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=pengutronix.de; s=20260414; t=1794856215; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yIJjtU/l7LIomhy8OaXZF6t/MLWz3Z2YWmYF9eGCfnc=; b=erWHu1iE9ec07e/GmLcnRJpmd0q4+SXhlhgGXIUCP6dHoGEj+R5e6UjGDy/nsW5z4x/mZK kgxTfgZvk6GuVmuAPeiZgUe6L0eTPtIbehOP4zdie2r977R+gBl8F60ntNagy1IWndnm0a NXPxVC4sQFqKAmmWIuvcwaVAYImZnAyN5PYZR34d0T9fFQ1Lca7a79hAsIz44XXKLG7zBo 6iFBO3hMz0TrYVtKM63XHjYc8QCF8QX7l1h1RGDqdR6mJqOWKqoVUET2yQqdHiMAjL/vwz zCA3zmp0CFR5D+b/DLsEbsOF4DnJeQD+h7pj9fDrDTJLCE0BlaPjsSjEDfx7+A== X-ARC-Seal: i=1; s=20260414; d=pengutronix.de; t=1794856215; a=rsa-sha256; cv=none; b=CM2KOTk9glxdF8vUalbwYsXqlO8ivXYQGNc2qd3Uev+BHtp1884lTjPIXTqLy8t1R0QoVW tSMgaeeAt7yhd1h3EeYhbtgbLnJpYXkXjGchV7qsiP7SA+PaLw0PDUUJ4P1AKRvsDno/pT T25L2mgEawDYxuqprXECKFEHrNI1/FCxyZrWfwe/pf3P9QMibkP8QwvS554mgyabaOTnU/ 5485cuYldC1QnKdGu5bfCtB2IThdzqYucuk6Gt+S4xxlisWTvjXBDRPpFI5klxlWfMkcmW 7flEglDOkuGnp3sA480Y3n8QSMU3LyPF/6nGteNlxPmvFTgcN4wDjN4S5SE6eQ== X-ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=relay-from-dude04.red.stw.pengutronix.de smtp.mailfrom=ore@pengutronix.de X-Received: by dude04.red.stw.pengutronix.de (Postfix, from userid 1058) id ACFAD3809F9; Mon, 16 Nov 2026 20:10:15 +0100 (CET) X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list X-In-Reply-To: <20261116-rtl8365mb-dcb-ingress-v3-0-657f5fdb4db7@pengutronix.de> X-Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@pengutronix.de, Oleksij Rempel <o.rempel@pengutronix.de> X-Mailer: b4 0.14.2