All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next v1 0/9] Enhanced DCB and DSCP Support for KSZ Switches
@ 2024-03-28 16:05 Oleksij Rempel
  2024-03-28 16:05 ` [PATCH net-next v1 1/9] net: dsa: add support for DCB get/set apptrust configuration Oleksij Rempel
                   ` (8 more replies)
  0 siblings, 9 replies; 19+ messages in thread
From: Oleksij Rempel @ 2024-03-28 16:05 UTC (permalink / raw)
  To: David S. Miller, Andrew Lunn, Eric Dumazet, Florian Fainelli,
	Jakub Kicinski, Paolo Abeni, Vladimir Oltean, Woojung Huh,
	Arun Ramadoss
  Cc: Oleksij Rempel, kernel, linux-kernel, netdev, UNGLinuxDriver,
	David Ahern, Simon Horman, Willem de Bruijn, Søren Andersen

This patch series is aimed at improving support for DCB (Data Center
Bridging) and DSCP (Differentiated Services Code Point) on KSZ switches.

The main goal is to introduce global DSCP and PCP (Priority Code Point)
mapping support, addressing the limitation of KSZ switches not having
per-port DSCP priority mapping. This involves extending the DSA
framework with new callbacks for managing trust settings for global DSCP
and PCP maps. Additionally, we introduce IEEE 802.1q helpers for default
configurations, benefiting other drivers too.

Oleksij Rempel (9):
  net: dsa: add support for DCB get/set apptrust configuration
  net: dsa: microchip: add IPV information support
  net: add IEEE 802.1q specific helpers
  net: dsa: microchip: add multi queue support for KSZ88X3 variants
  net: dsa: microchip: add support for different DCB app configurations
  net: dsa: microchip: dcb: add special handling for KSZ88X3 family
  net: dsa: microchip: enable ETS support for KSZ989X variants
  net: dsa: microchip: init predictable IPV to queue mapping for all non
    KSZ8xxx variants
  net: dsa: microchip: let DCB code do PCP and DSCP policy configuration

 drivers/net/dsa/microchip/Kconfig       |   2 +
 drivers/net/dsa/microchip/Makefile      |   2 +-
 drivers/net/dsa/microchip/ksz8.h        |   1 +
 drivers/net/dsa/microchip/ksz8795.c     | 106 ++--
 drivers/net/dsa/microchip/ksz8795_reg.h |   9 +-
 drivers/net/dsa/microchip/ksz9477.c     |   6 -
 drivers/net/dsa/microchip/ksz_common.c  |  94 +++-
 drivers/net/dsa/microchip/ksz_common.h  |   7 +-
 drivers/net/dsa/microchip/ksz_dcb.c     | 712 ++++++++++++++++++++++++
 drivers/net/dsa/microchip/ksz_dcb.h     |  21 +
 include/net/dsa.h                       |   4 +
 include/net/dscp.h                      |  76 +++
 include/net/ieee8021q.h                 |  34 ++
 net/Kconfig                             |   4 +
 net/core/Makefile                       |   1 +
 net/core/ieee8021q_helpers.c            | 165 ++++++
 net/dsa/user.c                          |  28 +
 17 files changed, 1198 insertions(+), 74 deletions(-)
 create mode 100644 drivers/net/dsa/microchip/ksz_dcb.c
 create mode 100644 drivers/net/dsa/microchip/ksz_dcb.h
 create mode 100644 include/net/dscp.h
 create mode 100644 include/net/ieee8021q.h
 create mode 100644 net/core/ieee8021q_helpers.c

-- 
2.39.2


^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH net-next v1 1/9] net: dsa: add support for DCB get/set apptrust configuration
  2024-03-28 16:05 [PATCH net-next v1 0/9] Enhanced DCB and DSCP Support for KSZ Switches Oleksij Rempel
@ 2024-03-28 16:05 ` Oleksij Rempel
  2024-03-28 16:05 ` [PATCH net-next v1 2/9] net: dsa: microchip: add IPV information support Oleksij Rempel
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 19+ messages in thread
From: Oleksij Rempel @ 2024-03-28 16:05 UTC (permalink / raw)
  To: David S. Miller, Andrew Lunn, Eric Dumazet, Florian Fainelli,
	Jakub Kicinski, Paolo Abeni, Vladimir Oltean, Woojung Huh,
	Arun Ramadoss
  Cc: Oleksij Rempel, kernel, linux-kernel, netdev, UNGLinuxDriver,
	David Ahern, Simon Horman, Willem de Bruijn, Søren Andersen

Add DCB support to get/set trust configuration for different packet
priority information sources. Some switch allow to choice different
source of packet priority classification. For example on KSZ switches it
is possible to configure VLAN PCP and/or DSCP sources.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 include/net/dsa.h |  4 ++++
 net/dsa/user.c    | 28 ++++++++++++++++++++++++++++
 2 files changed, 32 insertions(+)

diff --git a/include/net/dsa.h b/include/net/dsa.h
index 7c0da9effe4e9..96bde2aa86efd 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -955,6 +955,10 @@ struct dsa_switch_ops {
 				      u8 prio);
 	int	(*port_del_dscp_prio)(struct dsa_switch *ds, int port, u8 dscp,
 				      u8 prio);
+	int	(*port_set_apptrust)(struct dsa_switch *ds, int port,
+				     const u8 *sel, int nsel);
+	int	(*port_get_apptrust)(struct dsa_switch *ds, int port, u8 *sel,
+				     int *nsel);
 
 	/*
 	 * Suspend and resume
diff --git a/net/dsa/user.c b/net/dsa/user.c
index 16d395bb1a1fe..b6aec6615c76e 100644
--- a/net/dsa/user.c
+++ b/net/dsa/user.c
@@ -2136,6 +2136,32 @@ int dsa_user_change_mtu(struct net_device *dev, int new_mtu)
 	return err;
 }
 
+static int __maybe_unused
+dsa_user_dcbnl_set_apptrust(struct net_device *dev, u8 *sel, int nsel)
+{
+	struct dsa_port *dp = dsa_user_to_port(dev);
+	struct dsa_switch *ds = dp->ds;
+	int port = dp->index;
+
+	if (!ds->ops->port_get_apptrust)
+		return -EOPNOTSUPP;
+
+	return ds->ops->port_set_apptrust(ds, port, sel, nsel);
+}
+
+static int __maybe_unused
+dsa_user_dcbnl_get_apptrust(struct net_device *dev, u8 *sel, int *nsel)
+{
+	struct dsa_port *dp = dsa_user_to_port(dev);
+	struct dsa_switch *ds = dp->ds;
+	int port = dp->index;
+
+	if (!ds->ops->port_get_apptrust)
+		return -EOPNOTSUPP;
+
+	return ds->ops->port_get_apptrust(ds, port, sel, nsel);
+}
+
 static int __maybe_unused
 dsa_user_dcbnl_set_default_prio(struct net_device *dev, struct dcb_app *app)
 {
@@ -2376,6 +2402,8 @@ static const struct ethtool_ops dsa_user_ethtool_ops = {
 static const struct dcbnl_rtnl_ops __maybe_unused dsa_user_dcbnl_ops = {
 	.ieee_setapp		= dsa_user_dcbnl_ieee_setapp,
 	.ieee_delapp		= dsa_user_dcbnl_ieee_delapp,
+	.dcbnl_setapptrust	= dsa_user_dcbnl_set_apptrust,
+	.dcbnl_getapptrust	= dsa_user_dcbnl_get_apptrust,
 };
 
 static void dsa_user_get_stats64(struct net_device *dev,
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH net-next v1 2/9] net: dsa: microchip: add IPV information support
  2024-03-28 16:05 [PATCH net-next v1 0/9] Enhanced DCB and DSCP Support for KSZ Switches Oleksij Rempel
  2024-03-28 16:05 ` [PATCH net-next v1 1/9] net: dsa: add support for DCB get/set apptrust configuration Oleksij Rempel
@ 2024-03-28 16:05 ` Oleksij Rempel
  2024-04-02  3:57   ` Arun.Ramadoss
  2024-03-28 16:05 ` [PATCH net-next v1 3/9] net: add IEEE 802.1q specific helpers Oleksij Rempel
                   ` (6 subsequent siblings)
  8 siblings, 1 reply; 19+ messages in thread
From: Oleksij Rempel @ 2024-03-28 16:05 UTC (permalink / raw)
  To: David S. Miller, Andrew Lunn, Eric Dumazet, Florian Fainelli,
	Jakub Kicinski, Paolo Abeni, Vladimir Oltean, Woojung Huh,
	Arun Ramadoss
  Cc: Oleksij Rempel, kernel, linux-kernel, netdev, UNGLinuxDriver,
	David Ahern, Simon Horman, Willem de Bruijn, Søren Andersen

Most of Microchip KSZ switches use Internal Priority Value associated
with every frame. For example, it is possible to map any VLAN PCP or
DSCP value to IPV and at the end, map IPV to a queue.

Since amount of IPVs is not equal to amount of queues, add this
information and make use of it in some functions.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/net/dsa/microchip/ksz_common.c | 28 ++++++++++++++++++++++++--
 drivers/net/dsa/microchip/ksz_common.h |  2 +-
 2 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
index 42330e8fd26e7..cf81739d91dae 100644
--- a/drivers/net/dsa/microchip/ksz_common.c
+++ b/drivers/net/dsa/microchip/ksz_common.c
@@ -1194,6 +1194,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.port_cnt = 3,		/* total port count */
 		.port_nirqs = 3,
 		.num_tx_queues = 4,
+		.max_ipvs = 8,
 		.tc_cbs_supported = true,
 		.tc_ets_supported = true,
 		.ops = &ksz9477_dev_ops,
@@ -1223,6 +1224,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.cpu_ports = 0x10,	/* can be configured as cpu port */
 		.port_cnt = 5,		/* total cpu and user ports */
 		.num_tx_queues = 4,
+		.max_ipvs = 4,
 		.ops = &ksz8_dev_ops,
 		.ksz87xx_eee_link_erratum = true,
 		.mib_names = ksz9477_mib_names,
@@ -1262,6 +1264,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.cpu_ports = 0x10,	/* can be configured as cpu port */
 		.port_cnt = 5,		/* total cpu and user ports */
 		.num_tx_queues = 4,
+		.max_ipvs = 4,
 		.ops = &ksz8_dev_ops,
 		.ksz87xx_eee_link_erratum = true,
 		.mib_names = ksz9477_mib_names,
@@ -1287,6 +1290,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.cpu_ports = 0x10,	/* can be configured as cpu port */
 		.port_cnt = 5,		/* total cpu and user ports */
 		.num_tx_queues = 4,
+		.max_ipvs = 4,
 		.ops = &ksz8_dev_ops,
 		.ksz87xx_eee_link_erratum = true,
 		.mib_names = ksz9477_mib_names,
@@ -1312,6 +1316,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.cpu_ports = 0x4,	/* can be configured as cpu port */
 		.port_cnt = 3,
 		.num_tx_queues = 4,
+		.max_ipvs = 4,
 		.ops = &ksz8_dev_ops,
 		.mib_names = ksz88xx_mib_names,
 		.mib_cnt = ARRAY_SIZE(ksz88xx_mib_names),
@@ -1336,6 +1341,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.port_cnt = 7,		/* total physical port count */
 		.port_nirqs = 4,
 		.num_tx_queues = 4,
+		.max_ipvs = 8,
 		.tc_cbs_supported = true,
 		.tc_ets_supported = true,
 		.ops = &ksz9477_dev_ops,
@@ -1370,6 +1376,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.port_cnt = 6,		/* total physical port count */
 		.port_nirqs = 2,
 		.num_tx_queues = 4,
+		.max_ipvs = 8,
 		.ops = &ksz9477_dev_ops,
 		.mib_names = ksz9477_mib_names,
 		.mib_cnt = ARRAY_SIZE(ksz9477_mib_names),
@@ -1402,6 +1409,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.port_cnt = 7,		/* total physical port count */
 		.port_nirqs = 2,
 		.num_tx_queues = 4,
+		.max_ipvs = 8,
 		.ops = &ksz9477_dev_ops,
 		.mib_names = ksz9477_mib_names,
 		.mib_cnt = ARRAY_SIZE(ksz9477_mib_names),
@@ -1432,6 +1440,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.port_cnt = 3,		/* total port count */
 		.port_nirqs = 2,
 		.num_tx_queues = 4,
+		.max_ipvs = 8,
 		.ops = &ksz9477_dev_ops,
 		.mib_names = ksz9477_mib_names,
 		.mib_cnt = ARRAY_SIZE(ksz9477_mib_names),
@@ -1458,6 +1467,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.port_cnt = 3,		/* total port count */
 		.port_nirqs = 3,
 		.num_tx_queues = 4,
+		.max_ipvs = 8,
 		.tc_cbs_supported = true,
 		.tc_ets_supported = true,
 		.ops = &ksz9477_dev_ops,
@@ -1486,6 +1496,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.port_cnt = 7,		/* total port count */
 		.port_nirqs = 3,
 		.num_tx_queues = 4,
+		.max_ipvs = 8,
 		.tc_cbs_supported = true,
 		.tc_ets_supported = true,
 		.ops = &ksz9477_dev_ops,
@@ -1519,6 +1530,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.port_cnt = 7,		/* total physical port count */
 		.port_nirqs = 3,
 		.num_tx_queues = 4,
+		.max_ipvs = 8,
 		.tc_cbs_supported = true,
 		.tc_ets_supported = true,
 		.ops = &ksz9477_dev_ops,
@@ -1551,6 +1563,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.port_cnt = 5,		/* total physical port count */
 		.port_nirqs = 6,
 		.num_tx_queues = 8,
+		.max_ipvs = 8,
 		.tc_cbs_supported = true,
 		.tc_ets_supported = true,
 		.ops = &lan937x_dev_ops,
@@ -1578,6 +1591,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.port_cnt = 6,		/* total physical port count */
 		.port_nirqs = 6,
 		.num_tx_queues = 8,
+		.max_ipvs = 8,
 		.tc_cbs_supported = true,
 		.tc_ets_supported = true,
 		.ops = &lan937x_dev_ops,
@@ -1605,6 +1619,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.port_cnt = 8,		/* total physical port count */
 		.port_nirqs = 6,
 		.num_tx_queues = 8,
+		.max_ipvs = 8,
 		.tc_cbs_supported = true,
 		.tc_ets_supported = true,
 		.ops = &lan937x_dev_ops,
@@ -1636,6 +1651,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.port_cnt = 5,		/* total physical port count */
 		.port_nirqs = 6,
 		.num_tx_queues = 8,
+		.max_ipvs = 8,
 		.tc_cbs_supported = true,
 		.tc_ets_supported = true,
 		.ops = &lan937x_dev_ops,
@@ -1667,6 +1683,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.port_cnt = 8,		/* total physical port count */
 		.port_nirqs = 6,
 		.num_tx_queues = 8,
+		.max_ipvs = 8,
 		.tc_cbs_supported = true,
 		.tc_ets_supported = true,
 		.ops = &lan937x_dev_ops,
@@ -2296,6 +2313,13 @@ static int ksz_setup(struct dsa_switch *ds)
 
 	dev->dev_ops->enable_stp_addr(dev);
 
+	/* Make sure driver provide plausible queue and IPV values */
+	if (!dev->info->num_tx_queues ||
+	    dev->info->num_tx_queues > dev->info->max_ipvs) {
+		dev_err(dev->dev, "Number of TX queues exceeds maximum supported IPVs\n");
+		return -EINVAL;
+	}
+
 	ds->num_tx_queues = dev->info->num_tx_queues;
 
 	regmap_update_bits(ksz_regmap_8(dev), regs[S_MULTICAST_CTRL],
@@ -3522,7 +3546,7 @@ static int ksz_tc_ets_add(struct ksz_device *dev, int port,
 	for (tc_prio = 0; tc_prio < ARRAY_SIZE(p->priomap); tc_prio++) {
 		int queue;
 
-		if (tc_prio > KSZ9477_MAX_TC_PRIO)
+		if (tc_prio >= dev->info->max_ipvs)
 			break;
 
 		queue = ksz_ets_band_to_queue(p, p->priomap[tc_prio]);
@@ -3564,7 +3588,7 @@ static int ksz_tc_ets_del(struct ksz_device *dev, int port)
 	/* Revert the queue mapping for TC-priority to its default setting on
 	 * the chip.
 	 */
-	for (tc_prio = 0; tc_prio <= KSZ9477_MAX_TC_PRIO; tc_prio++) {
+	for (tc_prio = 0; tc_prio < dev->info->max_ipvs; tc_prio++) {
 		int queue;
 
 		queue = tc_prio >> s;
diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h
index 40c11b0d6b625..1bedd240cbbe4 100644
--- a/drivers/net/dsa/microchip/ksz_common.h
+++ b/drivers/net/dsa/microchip/ksz_common.h
@@ -58,6 +58,7 @@ struct ksz_chip_data {
 	int port_cnt;
 	u8 port_nirqs;
 	u8 num_tx_queues;
+	u8 max_ipvs; /* max number of Internal Priority Values */
 	bool tc_cbs_supported;
 	bool tc_ets_supported;
 	const struct ksz_dev_ops *ops;
@@ -722,7 +723,6 @@ static inline int is_lan937x(struct ksz_device *dev)
 #define KSZ9477_PORT_MRI_TC_MAP__4	0x0808
 
 #define KSZ9477_PORT_TC_MAP_S		4
-#define KSZ9477_MAX_TC_PRIO		7
 
 /* CBS related registers */
 #define REG_PORT_MTI_QUEUE_INDEX__4	0x0900
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH net-next v1 3/9] net: add IEEE 802.1q specific helpers
  2024-03-28 16:05 [PATCH net-next v1 0/9] Enhanced DCB and DSCP Support for KSZ Switches Oleksij Rempel
  2024-03-28 16:05 ` [PATCH net-next v1 1/9] net: dsa: add support for DCB get/set apptrust configuration Oleksij Rempel
  2024-03-28 16:05 ` [PATCH net-next v1 2/9] net: dsa: microchip: add IPV information support Oleksij Rempel
@ 2024-03-28 16:05 ` Oleksij Rempel
  2024-03-28 16:05 ` [PATCH net-next v1 4/9] net: dsa: microchip: add multi queue support for KSZ88X3 variants Oleksij Rempel
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 19+ messages in thread
From: Oleksij Rempel @ 2024-03-28 16:05 UTC (permalink / raw)
  To: David S. Miller, Andrew Lunn, Eric Dumazet, Florian Fainelli,
	Jakub Kicinski, Paolo Abeni, Vladimir Oltean, Woojung Huh,
	Arun Ramadoss
  Cc: Oleksij Rempel, kernel, linux-kernel, netdev, UNGLinuxDriver,
	David Ahern, Simon Horman, Willem de Bruijn, Søren Andersen

IEEE 802.1q specification provides recommendation and examples which can
be used as good default values for different drivers.

This patch implements mapping examples documented in IEEE 802.1Q-2022 in
Annex I "I.3 Traffic type to traffic class mapping" and IETF DSCP naming
and mapping DSCP to Traffic Type inspired by RFC8325.

This helpers will be used in followup patches for dsa/microchip DCB
implementation.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 include/net/dscp.h           |  76 ++++++++++++++++
 include/net/ieee8021q.h      |  34 ++++++++
 net/Kconfig                  |   4 +
 net/core/Makefile            |   1 +
 net/core/ieee8021q_helpers.c | 165 +++++++++++++++++++++++++++++++++++
 5 files changed, 280 insertions(+)
 create mode 100644 include/net/dscp.h
 create mode 100644 include/net/ieee8021q.h
 create mode 100644 net/core/ieee8021q_helpers.c

diff --git a/include/net/dscp.h b/include/net/dscp.h
new file mode 100644
index 0000000000000..ba40540868c9c
--- /dev/null
+++ b/include/net/dscp.h
@@ -0,0 +1,76 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (c) 2024 Pengutronix, Oleksij Rempel <kernel@pengutronix.de> */
+
+#ifndef __DSCP_H__
+#define __DSCP_H__
+
+/*
+ * DSCP Pools and Codepoint Space Division:
+ *
+ * The Differentiated Services (Diffserv) architecture defines a method for
+ * classifying and managing network traffic using the DS field in IPv4 and IPv6
+ * packet headers. This field can carry one of 64 distinct DSCP (Differentiated
+ * Services Code Point) values, which are divided into three pools based on
+ * their Least Significant Bits (LSB) patterns and intended usage. Each pool has
+ * a specific registration procedure for assigning DSCP values:
+ *
+ * Pool 1 (Standards Action Pool):
+ * - Codepoint Space: xxxxx0
+ *   This pool includes DSCP values ending in '0' (binary), allocated via
+ *   Standards Action. It is intended for globally recognized traffic classes,
+ *   ensuring interoperability across the internet. This pool encompasses
+ *   well-known DSCP values such as CS0-CS7, AFxx, EF, and VOICE-ADMIT.
+ *
+ * Pool 2 (Experimental/Local Use Pool):
+ * - Codepoint Space: xxxx11
+ *   Reserved for DSCP values ending in '11' (binary), this pool is designated
+ *   for Experimental or Local Use. It allows for private or temporary traffic
+ *   marking schemes not intended for standardized global use, facilitating
+ *   testing and network-specific configurations without impacting
+ *   interoperability.
+ *
+ * Pool 3 (Preferential Standardization Pool):
+ * - Codepoint Space: xxxx01
+ *   Initially reserved for experimental or local use, this pool now serves as
+ *   a secondary standardization resource should Pool 1 become exhausted. DSCP
+ *   values ending in '01' (binary) are assigned via Standards Action, with a
+ *   focus on adopting new, standardized traffic classes as the need arises.
+ *
+ * For pool updates see:
+ * https://www.iana.org/assignments/dscp-registry/dscp-registry.xhtml
+ */
+
+/* Pool 1: Standardized DSCP values as per [RFC8126] */
+#define DSCP_CS0 0		/* 000000, [RFC2474] */
+/* CS0 is some times called default (DF) */
+#define DSCP_DF 0		/* 000000, [RFC2474] */
+#define DSCP_CS1 8		/* 001000, [RFC2474] */
+#define DSCP_CS2 16		/* 010000, [RFC2474] */
+#define DSCP_CS3 24		/* 011000, [RFC2474] */
+#define DSCP_CS4 32		/* 100000, [RFC2474] */
+#define DSCP_CS5 40		/* 101000, [RFC2474] */
+#define DSCP_CS6 48		/* 110000, [RFC2474] */
+#define DSCP_CS7 56		/* 111000, [RFC2474] */
+#define DSCP_AF11 10		/* 001010, [RFC2597] */
+#define DSCP_AF12 12		/* 001100, [RFC2597] */
+#define DSCP_AF13 14		/* 001110, [RFC2597] */
+#define DSCP_AF21 18		/* 010010, [RFC2597] */
+#define DSCP_AF22 20		/* 010100, [RFC2597] */
+#define DSCP_AF23 22		/* 010110, [RFC2597] */
+#define DSCP_AF31 26		/* 011010, [RFC2597] */
+#define DSCP_AF32 28		/* 011100, [RFC2597] */
+#define DSCP_AF33 30		/* 011110, [RFC2597] */
+#define DSCP_AF41 34		/* 100010, [RFC2597] */
+#define DSCP_AF42 36		/* 100100, [RFC2597] */
+#define DSCP_AF43 38		/* 100110, [RFC2597] */
+#define DSCP_EF 46		/* 101110, [RFC3246] */
+#define DSCP_VOICE_ADMIT 44	/* 101100, [RFC5865] */
+
+/* Pool 3: Standardized assignments, previously available for experimental/local
+ * use
+ */
+#define DSCP_LE 1		/* 000001, [RFC8622] */
+
+#define DSCP_MAX 64
+
+#endif /* __DSCP_H__ */
diff --git a/include/net/ieee8021q.h b/include/net/ieee8021q.h
new file mode 100644
index 0000000000000..e524f6174f968
--- /dev/null
+++ b/include/net/ieee8021q.h
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (c) 2024 Pengutronix, Oleksij Rempel <kernel@pengutronix.de> */
+
+#ifndef _NET_IEEE8021Q_H
+#define _NET_IEEE8021Q_H
+
+/**
+ * enum ieee8021q_traffic_type - 802.1Q traffic type priority values (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_EE: Excellent Effort
+ * @IEEE8021Q_TT_CA: Critical Applications
+ * @IEEE8021Q_TT_VI: Video, < 100 ms latency and jitter
+ * @IEEE8021Q_TT_VO: Voice, < 10 ms latency and jitter
+ * @IEEE8021Q_TT_IC: Internetwork Control
+ * @IEEE8021Q_TT_NC: Network Control
+ */
+enum ieee8021q_traffic_type {
+	IEEE8021Q_TT_BK = 0,
+	IEEE8021Q_TT_BE = 1,
+	IEEE8021Q_TT_EE = 2,
+	IEEE8021Q_TT_CA = 3,
+	IEEE8021Q_TT_VI = 4,
+	IEEE8021Q_TT_VO = 5,
+	IEEE8021Q_TT_IC = 6,
+	IEEE8021Q_TT_NC = 7,
+};
+
+int ietf_dscp_to_ieee8021q_tt(int dscp);
+int ieee8021q_tt_to_tc(int tt, int num_queues);
+
+#endif /* _NET_IEEE8021Q_H */
diff --git a/net/Kconfig b/net/Kconfig
index 3e57ccf0da279..2da4e6639527a 100644
--- a/net/Kconfig
+++ b/net/Kconfig
@@ -449,6 +449,10 @@ config GRO_CELLS
 config SOCK_VALIDATE_XMIT
 	bool
 
+config NET_IEEE8021Q_HELPERS
+	bool
+	default n
+
 config NET_SELFTESTS
 	def_tristate PHYLIB
 	depends on PHYLIB && INET
diff --git a/net/core/Makefile b/net/core/Makefile
index 6e6548011fae5..febc10af4bb8c 100644
--- a/net/core/Makefile
+++ b/net/core/Makefile
@@ -26,6 +26,7 @@ obj-$(CONFIG_NETPOLL) += netpoll.o
 obj-$(CONFIG_FIB_RULES) += fib_rules.o
 obj-$(CONFIG_TRACEPOINTS) += net-traces.o
 obj-$(CONFIG_NET_DROP_MONITOR) += drop_monitor.o
+obj-$(CONFIG_NET_IEEE8021Q_HELPERS) += ieee8021q_helpers.o
 obj-$(CONFIG_NET_SELFTESTS) += selftests.o
 obj-$(CONFIG_NETWORK_PHY_TIMESTAMPING) += timestamping.o
 obj-$(CONFIG_NET_PTP_CLASSIFY) += ptp_classifier.o
diff --git a/net/core/ieee8021q_helpers.c b/net/core/ieee8021q_helpers.c
new file mode 100644
index 0000000000000..df02f84ad3595
--- /dev/null
+++ b/net/core/ieee8021q_helpers.c
@@ -0,0 +1,165 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) 2024 Pengutronix, Oleksij Rempel <kernel@pengutronix.de>
+
+#include <linux/printk.h>
+#include <linux/types.h>
+#include <net/dscp.h>
+#include <net/ieee8021q.h>
+
+/* Following arrays map Traffic Types (TT) to traffic classes (TC) for different
+ * number of queues as shown in the example provided by  IEEE 802.1Q-2022 in
+ * Annex I "I.3 Traffic type to traffic class mapping" and Table I-1 "Traffic
+ * type to traffic class mapping".
+ */
+static const u8 ieee8021q_8queue_tt_tc_map[] = {
+	[IEEE8021Q_TT_BK] = 0,
+	[IEEE8021Q_TT_BE] = 1,
+	[IEEE8021Q_TT_EE] = 2,
+	[IEEE8021Q_TT_CA] = 3,
+	[IEEE8021Q_TT_VI] = 4,
+	[IEEE8021Q_TT_VO] = 5,
+	[IEEE8021Q_TT_IC] = 6,
+	[IEEE8021Q_TT_NC] = 7,
+};
+
+static const u8 ieee8021q_7queue_tt_tc_map[] = {
+	[IEEE8021Q_TT_BK] = 0,
+	[IEEE8021Q_TT_BE] = 1,
+	[IEEE8021Q_TT_EE] = 2,
+	[IEEE8021Q_TT_CA] = 3,
+	[IEEE8021Q_TT_VI] = 4,	[IEEE8021Q_TT_VO] = 4,
+	[IEEE8021Q_TT_IC] = 5,
+	[IEEE8021Q_TT_NC] = 6,
+};
+
+static const u8 ieee8021q_6queue_tt_tc_map[] = {
+	[IEEE8021Q_TT_BK] = 0,
+	[IEEE8021Q_TT_BE] = 1,
+	[IEEE8021Q_TT_EE] = 2,	[IEEE8021Q_TT_CA] = 2,
+	[IEEE8021Q_TT_VI] = 3,	[IEEE8021Q_TT_VO] = 3,
+	[IEEE8021Q_TT_IC] = 4,
+	[IEEE8021Q_TT_NC] = 5,
+};
+
+static const u8 ieee8021q_5queue_tt_tc_map[] = {
+	[IEEE8021Q_TT_BK] = 0, [IEEE8021Q_TT_BE] = 0,
+	[IEEE8021Q_TT_EE] = 1, [IEEE8021Q_TT_CA] = 1,
+	[IEEE8021Q_TT_VI] = 2, [IEEE8021Q_TT_VO] = 2,
+	[IEEE8021Q_TT_IC] = 3,
+	[IEEE8021Q_TT_NC] = 4,
+};
+
+static const u8 ieee8021q_4queue_tt_tc_map[] = {
+	[IEEE8021Q_TT_BK] = 0, [IEEE8021Q_TT_BE] = 0,
+	[IEEE8021Q_TT_EE] = 1, [IEEE8021Q_TT_CA] = 1,
+	[IEEE8021Q_TT_VI] = 2, [IEEE8021Q_TT_VO] = 2,
+	[IEEE8021Q_TT_IC] = 3, [IEEE8021Q_TT_NC] = 3,
+};
+
+static const u8 ieee8021q_3queue_tt_tc_map[] = {
+	[IEEE8021Q_TT_BK] = 0, [IEEE8021Q_TT_BE] = 0,
+	[IEEE8021Q_TT_EE] = 0, [IEEE8021Q_TT_CA] = 0,
+	[IEEE8021Q_TT_VI] = 1, [IEEE8021Q_TT_VO] = 1,
+	[IEEE8021Q_TT_IC] = 2, [IEEE8021Q_TT_NC] = 2,
+};
+
+static const u8 ieee8021q_2queue_tt_tc_map[] = {
+	[IEEE8021Q_TT_BK] = 0, [IEEE8021Q_TT_BE] = 0,
+	[IEEE8021Q_TT_EE] = 0, [IEEE8021Q_TT_CA] = 0,
+	[IEEE8021Q_TT_VI] = 1, [IEEE8021Q_TT_VO] = 1,
+	[IEEE8021Q_TT_IC] = 1, [IEEE8021Q_TT_NC] = 1,
+};
+
+static const u8 ieee8021q_1queue_tt_tc_map[] = {
+	[IEEE8021Q_TT_BK] = 0, [IEEE8021Q_TT_BE] = 0,
+	[IEEE8021Q_TT_EE] = 0, [IEEE8021Q_TT_CA] = 0,
+	[IEEE8021Q_TT_VI] = 0, [IEEE8021Q_TT_VO] = 0,
+	[IEEE8021Q_TT_IC] = 0, [IEEE8021Q_TT_NC] = 0,
+};
+
+/**
+ * ieee8021q_tt_to_tc - Map IEEE 802.1Q Traffic Type to Traffic Class
+ * @tt: IEEE 802.1Q Traffic Type
+ * @num_queues: Number of queues
+ *
+ * This function maps an IEEE 802.1Q Traffic Type to a Traffic Class (TC) based
+ * on the number of queues configured on the switch. The mapping is based on the
+ * example provided by IEEE 802.1Q-2022 in Annex I "I.3 Traffic type to traffic
+ * class mapping" and Table I-1 "Traffic type to traffic class mapping".
+ *
+ * Return: Traffic Class corresponding to the given Traffic Type.
+ */
+int ieee8021q_tt_to_tc(int tt, int num_queues)
+{
+	switch (num_queues) {
+	case 8:
+		return ieee8021q_8queue_tt_tc_map[tt];
+	case 7:
+		return ieee8021q_7queue_tt_tc_map[tt];
+	case 6:
+		return ieee8021q_6queue_tt_tc_map[tt];
+	case 5:
+		return ieee8021q_5queue_tt_tc_map[tt];
+	case 4:
+		return ieee8021q_4queue_tt_tc_map[tt];
+	case 3:
+		return ieee8021q_3queue_tt_tc_map[tt];
+	case 2:
+		return ieee8021q_2queue_tt_tc_map[tt];
+	case 1:
+		return ieee8021q_1queue_tt_tc_map[tt];
+	}
+
+	pr_warn("Invalid number of queues %d\n", num_queues);
+	return 0;
+}
+
+/**
+ * ietf_dscp_to_ieee8021q_tt - Map IETF DSCP to IEEE 802.1Q Traffic Type
+ * @dscp: IETF DSCP value
+ *
+ * This function maps an IETF DSCP value to an IEEE 802.1Q Traffic Type (TT).
+ * Since there is no corresponding mapping between DSCP and IEEE 802.1Q Traffic
+ * Type, this function is inspired by the RFC8325 documentation which describe
+ * the mapping between DSCP and 802.11 User Priority (UP) values.
+ *
+ * Return: IEEE 802.1Q Traffic Type corresponding to the given DSCP value
+ */
+
+int ietf_dscp_to_ieee8021q_tt(int dscp)
+{
+	switch (dscp) {
+	case DSCP_CS0:
+	case DSCP_AF11:
+	case DSCP_AF12:
+	case DSCP_AF13:
+		return IEEE8021Q_TT_BE;
+	case DSCP_CS1:
+		return IEEE8021Q_TT_BK;
+	case DSCP_CS2:
+	case DSCP_AF21:
+	case DSCP_AF22:
+	case DSCP_AF23:
+		return IEEE8021Q_TT_EE;
+	case DSCP_CS3:
+	case DSCP_AF31:
+	case DSCP_AF32:
+	case DSCP_AF33:
+		return IEEE8021Q_TT_CA;
+	case DSCP_CS4:
+	case DSCP_AF41:
+	case DSCP_AF42:
+	case DSCP_AF43:
+		return IEEE8021Q_TT_VI;
+	case DSCP_CS5:
+	case DSCP_EF:
+	case DSCP_VOICE_ADMIT:
+		return IEEE8021Q_TT_VO;
+	case DSCP_CS6:
+		return IEEE8021Q_TT_IC;
+	case DSCP_CS7:
+		return IEEE8021Q_TT_NC;
+	}
+
+	return (dscp >> 3) & 0x7;
+}
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH net-next v1 4/9] net: dsa: microchip: add multi queue support for KSZ88X3 variants
  2024-03-28 16:05 [PATCH net-next v1 0/9] Enhanced DCB and DSCP Support for KSZ Switches Oleksij Rempel
                   ` (2 preceding siblings ...)
  2024-03-28 16:05 ` [PATCH net-next v1 3/9] net: add IEEE 802.1q specific helpers Oleksij Rempel
@ 2024-03-28 16:05 ` Oleksij Rempel
  2024-03-28 16:05 ` [PATCH net-next v1 5/9] net: dsa: microchip: add support for different DCB app configurations Oleksij Rempel
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 19+ messages in thread
From: Oleksij Rempel @ 2024-03-28 16:05 UTC (permalink / raw)
  To: David S. Miller, Andrew Lunn, Eric Dumazet, Florian Fainelli,
	Jakub Kicinski, Paolo Abeni, Vladimir Oltean, Woojung Huh,
	Arun Ramadoss
  Cc: Oleksij Rempel, kernel, linux-kernel, netdev, UNGLinuxDriver,
	David Ahern, Simon Horman, Willem de Bruijn, Søren Andersen

KSZ88X3 switches support up to 4 queues. Rework ksz8795_set_prio_queue()
to support KSZ8795 and KSZ88X3 families of switches.

Per default, configure KSZ88X3 to use one queue, since it need special
handling due to priority related errata. Errata handling is implemented
in a separate patch.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/net/dsa/microchip/ksz8795.c     | 87 ++++++++++++++++---------
 drivers/net/dsa/microchip/ksz8795_reg.h |  9 ++-
 2 files changed, 61 insertions(+), 35 deletions(-)

diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c
index 14923535ca7e8..0ead198bacb2c 100644
--- a/drivers/net/dsa/microchip/ksz8795.c
+++ b/drivers/net/dsa/microchip/ksz8795.c
@@ -127,37 +127,56 @@ int ksz8_change_mtu(struct ksz_device *dev, int port, int mtu)
 	return -EOPNOTSUPP;
 }
 
-static void ksz8795_set_prio_queue(struct ksz_device *dev, int port, int queue)
+static int ksz8_port_queue_split(struct ksz_device *dev, int port, int queues)
 {
-	u8 hi, lo;
+	u8 mask_4q, mask_2q;
+	u8 reg_4q, reg_2q;
+	u8 data_4q = 0;
+	u8 data_2q = 0;
+	int ret;
 
-	/* Number of queues can only be 1, 2, or 4. */
-	switch (queue) {
-	case 4:
-	case 3:
-		queue = PORT_QUEUE_SPLIT_4;
-		break;
-	case 2:
-		queue = PORT_QUEUE_SPLIT_2;
-		break;
-	default:
-		queue = PORT_QUEUE_SPLIT_1;
+	if (ksz_is_ksz88x3(dev)) {
+		mask_4q = KSZ8873_PORT_4QUEUE_SPLIT_EN;
+		mask_2q = KSZ8873_PORT_2QUEUE_SPLIT_EN;
+		reg_4q = REG_PORT_CTRL_0;
+		reg_2q = REG_PORT_CTRL_2;
+
+		/* KSZ8795 family switches have Weighted Fair Queueing (WFQ)
+		 * enabled by default. Enable it for KSZ8873 family switches
+		 * too. Default value for KSZ8873 family is strict priority,
+		 * which should be enabled by using TC_SETUP_QDISC_ETS, not
+		 * by default.
+		 */
+		ret = ksz_rmw8(dev, REG_SW_CTRL_3, WEIGHTED_FAIR_QUEUE_ENABLE,
+			       WEIGHTED_FAIR_QUEUE_ENABLE);
+		if (ret)
+			return ret;
+	} else {
+		mask_4q = KSZ8795_PORT_4QUEUE_SPLIT_EN;
+		mask_2q = KSZ8795_PORT_2QUEUE_SPLIT_EN;
+		reg_4q = REG_PORT_CTRL_13;
+		reg_2q = REG_PORT_CTRL_0;
+
+		/* TODO: this is legacy from initial KSZ8795 driver, should be
+		 * moved to appropriate place in the future.
+		 */
+		ret = ksz_rmw8(dev, REG_SW_CTRL_19,
+			       SW_OUT_RATE_LIMIT_QUEUE_BASED,
+			       SW_OUT_RATE_LIMIT_QUEUE_BASED);
+		if (ret)
+			return ret;
 	}
-	ksz_pread8(dev, port, REG_PORT_CTRL_0, &lo);
-	ksz_pread8(dev, port, P_DROP_TAG_CTRL, &hi);
-	lo &= ~PORT_QUEUE_SPLIT_L;
-	if (queue & PORT_QUEUE_SPLIT_2)
-		lo |= PORT_QUEUE_SPLIT_L;
-	hi &= ~PORT_QUEUE_SPLIT_H;
-	if (queue & PORT_QUEUE_SPLIT_4)
-		hi |= PORT_QUEUE_SPLIT_H;
-	ksz_pwrite8(dev, port, REG_PORT_CTRL_0, lo);
-	ksz_pwrite8(dev, port, P_DROP_TAG_CTRL, hi);
-
-	/* Default is port based for egress rate limit. */
-	if (queue != PORT_QUEUE_SPLIT_1)
-		ksz_cfg(dev, REG_SW_CTRL_19, SW_OUT_RATE_LIMIT_QUEUE_BASED,
-			true);
+
+	if (queues == 4)
+		data_4q = mask_4q;
+	if (queues == 2)
+		data_2q = mask_2q;
+
+	ret = ksz_prmw8(dev, port, reg_4q, mask_4q, data_4q);
+	if (ret)
+		return ret;
+
+	return ksz_prmw8(dev, port, reg_2q, mask_2q, data_2q);
 }
 
 void ksz8_r_mib_cnt(struct ksz_device *dev, int port, u16 addr, u64 *cnt)
@@ -1512,6 +1531,7 @@ void ksz8_port_setup(struct ksz_device *dev, int port, bool cpu_port)
 {
 	struct dsa_switch *ds = dev->ds;
 	const u32 *masks;
+	int queues;
 	u8 member;
 
 	masks = dev->info->masks;
@@ -1519,8 +1539,15 @@ void ksz8_port_setup(struct ksz_device *dev, int port, bool cpu_port)
 	/* enable broadcast storm limit */
 	ksz_port_cfg(dev, port, P_BCAST_STORM_CTRL, PORT_BROADCAST_STORM, true);
 
-	if (!ksz_is_ksz88x3(dev))
-		ksz8795_set_prio_queue(dev, port, 4);
+	/* For KSZ88x3 enable only one queue by default, otherwise we won't
+	 * be able to get rid of PCP prios on Port 2.
+	 */
+	if (ksz_is_ksz88x3(dev))
+		queues = 1;
+	else
+		queues = dev->info->num_tx_queues;
+
+	ksz8_port_queue_split(dev, port, queues);
 
 	/* disable DiffServ priority */
 	ksz_port_cfg(dev, port, P_PRIO_CTRL, PORT_DIFFSERV_ENABLE, false);
diff --git a/drivers/net/dsa/microchip/ksz8795_reg.h b/drivers/net/dsa/microchip/ksz8795_reg.h
index 7c9341ef73b03..2a2a00202f643 100644
--- a/drivers/net/dsa/microchip/ksz8795_reg.h
+++ b/drivers/net/dsa/microchip/ksz8795_reg.h
@@ -124,7 +124,8 @@
 #define PORT_BASED_PRIO_3		3
 #define PORT_INSERT_TAG			BIT(2)
 #define PORT_REMOVE_TAG			BIT(1)
-#define PORT_QUEUE_SPLIT_L		BIT(0)
+#define KSZ8795_PORT_2QUEUE_SPLIT_EN	BIT(0)
+#define KSZ8873_PORT_4QUEUE_SPLIT_EN	BIT(0)
 
 #define REG_PORT_1_CTRL_1		0x11
 #define REG_PORT_2_CTRL_1		0x21
@@ -143,6 +144,7 @@
 #define REG_PORT_4_CTRL_2		0x42
 #define REG_PORT_5_CTRL_2		0x52
 
+#define KSZ8873_PORT_2QUEUE_SPLIT_EN	BIT(7)
 #define PORT_INGRESS_FILTER		BIT(6)
 #define PORT_DISCARD_NON_VID		BIT(5)
 #define PORT_FORCE_FLOW_CTRL		BIT(4)
@@ -463,10 +465,7 @@
 #define REG_PORT_4_CTRL_13		0xE1
 #define REG_PORT_5_CTRL_13		0xF1
 
-#define PORT_QUEUE_SPLIT_H		BIT(1)
-#define PORT_QUEUE_SPLIT_1		0
-#define PORT_QUEUE_SPLIT_2		1
-#define PORT_QUEUE_SPLIT_4		2
+#define KSZ8795_PORT_4QUEUE_SPLIT_EN	BIT(1)
 #define PORT_DROP_TAG			BIT(0)
 
 #define REG_PORT_1_CTRL_14		0xB2
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH net-next v1 5/9] net: dsa: microchip: add support for different DCB app configurations
  2024-03-28 16:05 [PATCH net-next v1 0/9] Enhanced DCB and DSCP Support for KSZ Switches Oleksij Rempel
                   ` (3 preceding siblings ...)
  2024-03-28 16:05 ` [PATCH net-next v1 4/9] net: dsa: microchip: add multi queue support for KSZ88X3 variants Oleksij Rempel
@ 2024-03-28 16:05 ` Oleksij Rempel
  2024-03-29  9:29   ` Naveen Mamindlapalli
                     ` (2 more replies)
  2024-03-28 16:05 ` [PATCH net-next v1 6/9] net: dsa: microchip: dcb: add special handling for KSZ88X3 family Oleksij Rempel
                   ` (3 subsequent siblings)
  8 siblings, 3 replies; 19+ messages in thread
From: Oleksij Rempel @ 2024-03-28 16:05 UTC (permalink / raw)
  To: David S. Miller, Andrew Lunn, Eric Dumazet, Florian Fainelli,
	Jakub Kicinski, Paolo Abeni, Vladimir Oltean, Woojung Huh,
	Arun Ramadoss
  Cc: Oleksij Rempel, kernel, linux-kernel, netdev, UNGLinuxDriver,
	David Ahern, Simon Horman, Willem de Bruijn, Søren Andersen

Add DCB support to configure app trust sources and default port priority.

Following commands can be used for testing:
dcb apptrust set dev lan1 order pcp dscp
dcb app replace dev lan1 default-prio 3

Since it is not possible to configure DSCP-Prio mapping per port, this
patch provide only ability to read switch global dscp-prio mapping and
way to enable/disable app trust for DSCP.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/net/dsa/microchip/Kconfig      |   2 +
 drivers/net/dsa/microchip/Makefile     |   2 +-
 drivers/net/dsa/microchip/ksz_common.c |  12 +-
 drivers/net/dsa/microchip/ksz_common.h |   5 +
 drivers/net/dsa/microchip/ksz_dcb.c    | 533 +++++++++++++++++++++++++
 drivers/net/dsa/microchip/ksz_dcb.h    |  21 +
 6 files changed, 573 insertions(+), 2 deletions(-)
 create mode 100644 drivers/net/dsa/microchip/ksz_dcb.c
 create mode 100644 drivers/net/dsa/microchip/ksz_dcb.h

diff --git a/drivers/net/dsa/microchip/Kconfig b/drivers/net/dsa/microchip/Kconfig
index 394ca8678d2ba..c1b906c05a025 100644
--- a/drivers/net/dsa/microchip/Kconfig
+++ b/drivers/net/dsa/microchip/Kconfig
@@ -4,6 +4,8 @@ menuconfig NET_DSA_MICROCHIP_KSZ_COMMON
 	depends on NET_DSA
 	select NET_DSA_TAG_KSZ
 	select NET_DSA_TAG_NONE
+	select NET_IEEE8021Q_HELPERS
+	select DCB
 	help
 	  This driver adds support for Microchip KSZ9477 series switch and
 	  KSZ8795/KSZ88x3 switch chips.
diff --git a/drivers/net/dsa/microchip/Makefile b/drivers/net/dsa/microchip/Makefile
index 49459a50dbc81..1cfba1ec9355a 100644
--- a/drivers/net/dsa/microchip/Makefile
+++ b/drivers/net/dsa/microchip/Makefile
@@ -1,6 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0-only
 obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ_COMMON)	+= ksz_switch.o
-ksz_switch-objs := ksz_common.o
+ksz_switch-objs := ksz_common.o ksz_dcb.o
 ksz_switch-objs += ksz9477.o ksz9477_acl.o ksz9477_tc_flower.o
 ksz_switch-objs += ksz8795.o
 ksz_switch-objs += lan937x_main.o
diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
index cf81739d91dae..ea2d6f8d381bc 100644
--- a/drivers/net/dsa/microchip/ksz_common.c
+++ b/drivers/net/dsa/microchip/ksz_common.c
@@ -28,6 +28,7 @@
 #include <net/switchdev.h>
 
 #include "ksz_common.h"
+#include "ksz_dcb.h"
 #include "ksz_ptp.h"
 #include "ksz8.h"
 #include "ksz9477.h"
@@ -2371,6 +2372,10 @@ static int ksz_setup(struct dsa_switch *ds)
 		goto out_ptp_clock_unregister;
 	}
 
+	ret = ksz_dcb_init(dev);
+	if (ret)
+		goto out_ptp_clock_unregister;
+
 	/* start switch */
 	regmap_update_bits(ksz_regmap_8(dev), regs[S_START_CTRL],
 			   SW_START, SW_START);
@@ -2698,7 +2703,7 @@ static int ksz_port_setup(struct dsa_switch *ds, int port)
 	 * there is no need to do anything.
 	 */
 
-	return 0;
+	return ksz_dcb_init_port(dev, port);
 }
 
 void ksz_port_stp_state_set(struct dsa_switch *ds, int port, u8 state)
@@ -3950,6 +3955,11 @@ static const struct dsa_switch_ops ksz_switch_ops = {
 	.port_setup_tc		= ksz_setup_tc,
 	.get_mac_eee		= ksz_get_mac_eee,
 	.set_mac_eee		= ksz_set_mac_eee,
+	.port_get_default_prio	= ksz_port_get_default_prio,
+	.port_set_default_prio	= ksz_port_set_default_prio,
+	.port_get_dscp_prio	= ksz_port_get_dscp_prio,
+	.port_set_apptrust	= ksz_port_set_apptrust,
+	.port_get_apptrust	= ksz_port_get_apptrust,
 };
 
 struct ksz_device *ksz_switch_alloc(struct device *base, void *priv)
diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h
index 1bedd240cbbe4..4f48a8347e5de 100644
--- a/drivers/net/dsa/microchip/ksz_common.h
+++ b/drivers/net/dsa/microchip/ksz_common.h
@@ -621,6 +621,11 @@ static inline bool ksz_is_ksz88x3(struct ksz_device *dev)
 	return dev->chip_id == KSZ8830_CHIP_ID;
 }
 
+static inline bool is_ksz8(struct ksz_device *dev)
+{
+	return ksz_is_ksz87xx(dev) || ksz_is_ksz88x3(dev);
+}
+
 static inline int is_lan937x(struct ksz_device *dev)
 {
 	return dev->chip_id == LAN9370_CHIP_ID ||
diff --git a/drivers/net/dsa/microchip/ksz_dcb.c b/drivers/net/dsa/microchip/ksz_dcb.c
new file mode 100644
index 0000000000000..527bf10d35dd3
--- /dev/null
+++ b/drivers/net/dsa/microchip/ksz_dcb.c
@@ -0,0 +1,533 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) 2024 Pengutronix, Oleksij Rempel <kernel@pengutronix.de>
+
+#include <linux/dsa/ksz_common.h>
+#include <net/dsa.h>
+#include <net/dscp.h>
+#include <net/ieee8021q.h>
+
+#include "ksz_common.h"
+#include "ksz_dcb.h"
+#include "ksz8.h"
+
+#define KSZ8_REG_PORT_1_CTRL_0			0x10
+#define KSZ8_PORT_DIFFSERV_ENABLE		BIT(6)
+#define KSZ8_PORT_802_1P_ENABLE			BIT(5)
+#define KSZ8_PORT_BASED_PRIO_M			GENMASK(4, 3)
+
+#define KSZ88X3_REG_TOS_DSCP_CTRL		0x60
+#define KSZ8765_REG_TOS_DSCP_CTRL		0x90
+
+#define KSZ9477_REG_SW_MAC_TOS_CTRL		0x033e
+#define KSZ9477_SW_TOS_DSCP_REMAP		BIT(0)
+#define KSZ9477_SW_TOS_DSCP_DEFAULT_PRIO_M	GENMASK(5, 3)
+
+#define KSZ9477_REG_DIFFSERV_PRIO_MAP		0x0340
+
+#define KSZ9477_REG_PORT_MRI_PRIO_CTRL		0x0801
+#define KSZ9477_PORT_HIGHEST_PRIO		BIT(7)
+#define KSZ9477_PORT_OR_PRIO			BIT(6)
+#define KSZ9477_PORT_MAC_PRIO_ENABLE		BIT(4)
+#define KSZ9477_PORT_VLAN_PRIO_ENABLE		BIT(3)
+#define KSZ9477_PORT_802_1P_PRIO_ENABLE		BIT(2)
+#define KSZ9477_PORT_DIFFSERV_PRIO_ENABLE	BIT(1)
+#define KSZ9477_PORT_ACL_PRIO_ENABLE		BIT(0)
+
+#define KSZ9477_REG_PORT_MRI_MAC_CTRL		0x0802
+#define KSZ9477_PORT_BASED_PRIO_M		GENMASK(2, 0)
+
+struct ksz_apptrust_map {
+	u8 apptrust;
+	u8 bit;
+};
+
+static const struct ksz_apptrust_map ksz8_apptrust_map_to_bit[] = {
+	{ DCB_APP_SEL_PCP, KSZ8_PORT_802_1P_ENABLE },
+	{ IEEE_8021QAZ_APP_SEL_DSCP, KSZ8_PORT_DIFFSERV_ENABLE },
+};
+
+static const struct ksz_apptrust_map ksz9477_apptrust_map_to_bit[] = {
+	{ DCB_APP_SEL_PCP, KSZ9477_PORT_802_1P_PRIO_ENABLE },
+	{ IEEE_8021QAZ_APP_SEL_DSCP, KSZ9477_PORT_DIFFSERV_PRIO_ENABLE },
+};
+
+/**
+ * ksz_supported_apptrust[] - Supported apptrust selectors and Priority Order
+ *			      of Internal Priority Value (IPV) sources.
+ *
+ * This array defines the apptrust selectors supported by the hardware, where
+ * the index within the array indicates the priority of the selector - lower
+ * indices correspond to higher priority. This fixed priority scheme is due to
+ * the hardware's design, which does not support configurable priority among
+ * different priority sources.
+ *
+ * The priority sources, including Tail Tag, ACL, VLAN PCP and DSCP are ordered
+ * by the hardware's fixed logic, as detailed below. The order reflects a
+ * non-configurable precedence where certain types of priority information
+ * override others:
+ *
+ * 1. Tail Tag - Highest priority, overrides ACL, VLAN PCP, and DSCP priorities.
+ * 2. ACL - Overrides VLAN PCP and DSCP priorities.
+ * 3. VLAN PCP - Overrides DSCP priority.
+ * 4. DSCP - Lowest priority, does not override any other priority source.
+ *
+ * In this context, the array's lower index (higher priority) for
+ * 'DCB_APP_SEL_PCP' suggests its relative priority over
+ * 'IEEE_8021QAZ_APP_SEL_DSCP' within the system's fixed priority scheme.
+ *
+ * DCB_APP_SEL_PCP - Priority Code Point selector
+ * IEEE_8021QAZ_APP_SEL_DSCP - Differentiated Services Code Point selector
+ */
+static const u8 ksz_supported_apptrust[] = {
+	DCB_APP_SEL_PCP,
+	IEEE_8021QAZ_APP_SEL_DSCP,
+};
+
+static const u8 ksz8_port2_supported_apptrust[] = {
+	DCB_APP_SEL_PCP,
+};
+
+static const char * const ksz_supported_apptrust_variants[] = {
+	"empty", "dscp", "pcp", "dscp pcp"
+};
+
+static void ksz_get_defult_port_prio_reg(struct ksz_device *dev, int *reg,
+					 u8 *mask, int *shift)
+{
+	if (is_ksz8(dev)) {
+		*reg = KSZ8_REG_PORT_1_CTRL_0;
+		*mask = KSZ8_PORT_BASED_PRIO_M;
+		*shift = __bf_shf(KSZ8_PORT_BASED_PRIO_M);
+	} else {
+		*reg = KSZ9477_REG_PORT_MRI_MAC_CTRL;
+		*mask = KSZ9477_PORT_BASED_PRIO_M;
+		*shift = __bf_shf(KSZ9477_PORT_BASED_PRIO_M);
+	}
+}
+
+/**
+ * ksz_port_get_default_prio - Retrieves the default priority for a port on a
+ *			       KSZ switch
+ * @ds: Pointer to the DSA switch structure
+ * @port: Port number from which to get the default priority
+ *
+ * This function fetches the default priority for the specified port on a KSZ
+ * switch.
+ *
+ * Return: The default priority of the port on success, or a negative error
+ * code on failure.
+ */
+int ksz_port_get_default_prio(struct dsa_switch *ds, int port)
+{
+	struct ksz_device *dev = ds->priv;
+	int ret, reg, shift;
+	u8 data, mask;
+
+	ksz_get_defult_port_prio_reg(dev, &reg, &mask, &shift);
+
+	ret = ksz_pread8(dev, port, reg, &data);
+	if (ret)
+		return ret;
+
+	return (data & mask) >> shift;
+}
+
+/**
+ * ksz_port_set_default_prio - Sets the default priority for a port on a KSZ
+ *			       switch
+ * @ds: Pointer to the DSA switch structure
+ * @port: Port number for which to set the default priority
+ * @prio: Priority value to set
+ *
+ * This function sets the default priority for the specified port on a KSZ
+ * switch.
+ *
+ * Return: 0 on success, or a negative error code on failure.
+ */
+int ksz_port_set_default_prio(struct dsa_switch *ds, int port, u8 prio)
+{
+	struct ksz_device *dev = ds->priv;
+	int reg, shift;
+	u8 mask;
+
+	if (prio >= dev->info->num_tx_queues)
+		return -EINVAL;
+
+	ksz_get_defult_port_prio_reg(dev, &reg, &mask, &shift);
+
+	return ksz_prmw8(dev, port, reg, mask, (prio << shift) & mask);
+}
+
+/**
+ * ksz_get_dscp_prio_reg - Retrieves the DSCP-to-priority-mapping register
+ * @dev: Pointer to the KSZ switch device structure
+ * @reg: Pointer to the register address to be set
+ * @per_reg: Pointer to the number of DSCP values per register
+ * @mask: Pointer to the mask to be set
+ *
+ * This function retrieves the DSCP to priority mapping register, the number of
+ * DSCP values per register, and the mask to be set.
+ */
+static void ksz_get_dscp_prio_reg(struct ksz_device *dev, int *reg,
+				  int *per_reg, u8 *mask)
+{
+	if (ksz_is_ksz87xx(dev)) {
+		*reg = KSZ8765_REG_TOS_DSCP_CTRL;
+		*per_reg = 4;
+		*mask = GENMASK(1, 0);
+	} else if (ksz_is_ksz88x3(dev)) {
+		*reg = KSZ88X3_REG_TOS_DSCP_CTRL;
+		*per_reg = 4;
+		*mask = GENMASK(1, 0);
+	} else {
+		*reg = KSZ9477_REG_DIFFSERV_PRIO_MAP;
+		*per_reg = 2;
+		*mask = GENMASK(2, 0);
+	}
+}
+
+/**
+ * ksz_port_get_dscp_prio - Retrieves the priority for a DSCP value on a KSZ
+ *			    switch
+ * @ds: Pointer to the DSA switch structure
+ * @port: Port number for which to get the priority
+ * @dscp: DSCP value for which to get the priority
+ *
+ * This function fetches the priority value from switch global DSCP-to-priorty
+ * mapping table for the specified DSCP value.
+ *
+ * Return: The priority value for the DSCP on success, or a negative error
+ * code on failure.
+ */
+int ksz_port_get_dscp_prio(struct dsa_switch *ds, int port, u8 dscp)
+{
+	struct ksz_device *dev = ds->priv;
+	int reg, per_reg, ret, shift;
+	u8 data, mask;
+
+	ksz_get_dscp_prio_reg(dev, &reg, &per_reg, &mask);
+
+	/* If DSCP remapping is disabled, DSCP bits 3-5 are used as Internal
+	 * Priority Value (IPV)
+	 */
+	if (!is_ksz8(dev)) {
+		ret = ksz_read8(dev, KSZ9477_REG_SW_MAC_TOS_CTRL, &data);
+		if (ret)
+			return ret;
+
+		/* If DSCP remapping is disabled, DSCP bits 3-5 are used as
+		 * Internal Priority Value (IPV)
+		 */
+		if (!(data & KSZ9477_SW_TOS_DSCP_REMAP))
+			return FIELD_GET(KSZ9477_SW_TOS_DSCP_DEFAULT_PRIO_M,
+					 dscp);
+	}
+
+	/* In case DSCP remapping is enabled, we need to write the DSCP to
+	 * priority mapping table.
+	 */
+	reg += dscp / per_reg;
+	ret = ksz_read8(dev, reg, &data);
+	if (ret)
+		return ret;
+
+	shift = (dscp % per_reg) * (8 / per_reg);
+
+	return (data >> shift) & mask;
+}
+
+/**
+ * ksz_init_global_dscp_map - Initializes the global DSCP-to-priority mapping
+ * @dev: Pointer to the KSZ switch device structure
+ *
+ * This function initializes the global DSCP-to-priority mapping table for the
+ * switch.
+ *
+ * Return: 0 on success, or a negative error code on failure
+ */
+static int ksz_init_global_dscp_map(struct ksz_device *dev)
+{
+	int reg, per_reg, ret, dscp;
+	u8 data = 0;
+	u8 mask;
+
+	/* On KSZ9xxx variants, DSCP remapping is disabled by default.
+	 * Enable to have, predictable and reproducible behavior across
+	 * different devices.
+	 */
+	if (!is_ksz8(dev)) {
+		ret = ksz_rmw8(dev, KSZ9477_REG_SW_MAC_TOS_CTRL,
+			       KSZ9477_SW_TOS_DSCP_REMAP,
+			       KSZ9477_SW_TOS_DSCP_REMAP);
+		if (ret)
+			return ret;
+	}
+
+	ksz_get_dscp_prio_reg(dev, &reg, &per_reg, &mask);
+
+	for (dscp = 0; dscp < DSCP_MAX; dscp++) {
+		int ipv, shift;
+
+		/* Map DSCP to Traffic Type, which is corresponding to the
+		 * Internal Priority Value (IPV) in the switch.
+		 */
+		if (!is_ksz8(dev)) {
+			ipv = ietf_dscp_to_ieee8021q_tt(dscp);
+		} else {
+			ipv = ieee8021q_tt_to_tc(ietf_dscp_to_ieee8021q_tt(dscp),
+						 dev->info->num_tx_queues);
+		}
+		shift = (dscp % per_reg) * (8 / per_reg);
+		data |= (ipv & mask) << shift;
+
+		if (dscp % per_reg == per_reg - 1) {
+			ret = ksz_write8(dev, reg + (dscp / per_reg), data);
+			if (ret)
+				return ret;
+
+			data = 0;
+		}
+	}
+
+	return 0;
+}
+
+/**
+ * ksz_apptrust_error - Prints an error message for an invalid apptrust selector
+ * @dev: Pointer to the KSZ switch device structure
+ *
+ * This function prints an error message when an invalid apptrust selector is
+ * provided.
+ */
+static void ksz_apptrust_error(struct ksz_device *dev)
+{
+	char supported_apptrust_variants[64];
+	int i;
+
+	supported_apptrust_variants[0] = '\0';
+	for (i = 0; i < ARRAY_SIZE(ksz_supported_apptrust_variants); i++) {
+		if (i > 0)
+			strlcat(supported_apptrust_variants, ", ",
+				sizeof(supported_apptrust_variants));
+		strlcat(supported_apptrust_variants,
+			ksz_supported_apptrust_variants[i],
+			sizeof(supported_apptrust_variants));
+	}
+
+	dev_err(dev->dev, "Invalid apptrust selector or priority order. Supported: %s\n",
+		supported_apptrust_variants);
+}
+
+/**
+ * ksz_port_set_apptrust_validate - Validates the apptrust selectors
+ * @dev: Pointer to the KSZ switch device structure
+ * @port: Port number for which to set the apptrust selectors
+ * @sel: Array of apptrust selectors to validate
+ * @nsel: Number of apptrust selectors in the array
+ *
+ * This function validates the apptrust selectors provided and ensures that
+ * they are in the correct order.
+ *
+ * This family of switches supports two apptrust selectors: DCB_APP_SEL_PCP and
+ * IEEE_8021QAZ_APP_SEL_DSCP. The priority order of the selectors is fixed and
+ * cannot be changed. The order is as follows:
+ * 1. DCB_APP_SEL_PCP - Priority Code Point selector (highest priority)
+ * 2. IEEE_8021QAZ_APP_SEL_DSCP - Differentiated Services Code Point selector
+ *   (lowest priority)
+ *
+ * Return: 0 on success, or a negative error code on failure
+ */
+static int ksz_port_set_apptrust_validate(struct ksz_device *dev, int port,
+					  const u8 *sel, int nsel)
+{
+	int i, j, j_prev, found;
+
+	/* Iterate through the requested selectors */
+	for (i = 0; i < nsel; i++) {
+		found = 0;
+
+		/* Check if the current selector is supported by the hardware */
+		for (j = 0; j < sizeof(ksz_supported_apptrust); j++) {
+			if (sel[i] != ksz_supported_apptrust[j])
+				continue;
+
+			found = 1;
+
+			/* Ensure that no higher priority selector (lower index)
+			 * precedes a lower priority one
+			 */
+			if (i > 0 && j <= j_prev)
+				goto invalid;
+
+			j_prev = j;
+			break;
+		}
+
+		if (!found)
+			goto invalid;
+	}
+
+	return 0;
+
+invalid:
+	ksz_apptrust_error(dev);
+
+	return -EINVAL;
+}
+
+/**
+ * ksz_get_apptrus_map_and_reg - Retrieves the apptrust map and register
+ * @dev: Pointer to the KSZ switch device structure
+ * @map: Pointer to the apptrust map to be set
+ * @reg: Pointer to the register address to be set
+ * @mask: Pointer to the mask to be set
+ *
+ * This function retrieves the apptrust map and register address for the
+ * apptrust configuration.
+ */
+static void ksz_get_apptrus_map_and_reg(struct ksz_device *dev,
+					const struct ksz_apptrust_map **map,
+					int *reg, u8 *mask)
+{
+	if (is_ksz8(dev)) {
+		*map = ksz8_apptrust_map_to_bit;
+		*reg = KSZ8_REG_PORT_1_CTRL_0;
+		*mask = KSZ8_PORT_DIFFSERV_ENABLE | KSZ8_PORT_802_1P_ENABLE;
+	} else {
+		*map = ksz9477_apptrust_map_to_bit;
+		*reg = KSZ9477_REG_PORT_MRI_PRIO_CTRL;
+		*mask = KSZ9477_PORT_802_1P_PRIO_ENABLE |
+			KSZ9477_PORT_DIFFSERV_PRIO_ENABLE;
+	}
+}
+
+/**
+ * ksz_port_set_apptrust - Sets the apptrust selectors for a port on a KSZ
+ *			   switch
+ * @ds: Pointer to the DSA switch structure
+ * @port: Port number for which to set the apptrust selectors
+ * @sel: Array of apptrust selectors to set
+ * @nsel: Number of apptrust selectors in the array
+ *
+ * This function sets the apptrust selectors for the specified port on a KSZ
+ * switch.
+ *
+ * Return: 0 on success, or a negative error code on failure
+ */
+int ksz_port_set_apptrust(struct dsa_switch *ds, int port,
+			  const u8 *sel, int nsel)
+{
+	const struct ksz_apptrust_map *map;
+	struct ksz_device *dev = ds->priv;
+	int reg, i, ret;
+	u8 data = 0;
+	u8 mask;
+
+	ret = ksz_port_set_apptrust_validate(dev, port, sel, nsel);
+	if (ret)
+		return ret;
+
+	ksz_get_apptrus_map_and_reg(dev, &map, &reg, &mask);
+
+	for (i = 0; i < nsel; i++) {
+		int j;
+
+		for (j = 0; j < ARRAY_SIZE(ksz_supported_apptrust); j++) {
+			if (sel[i] != ksz_supported_apptrust[j])
+				continue;
+
+			data |= map[j].bit;
+			break;
+		}
+	}
+
+	return ksz_prmw8(dev, port, reg, mask, data);
+}
+
+/**
+ * ksz_port_get_apptrust - Retrieves the apptrust selectors for a port on a KSZ
+ *			   switch
+ * @ds: Pointer to the DSA switch structure
+ * @port: Port number for which to get the apptrust selectors
+ * @sel: Array to store the apptrust selectors
+ * @nsel: Number of apptrust selectors in the array
+ *
+ * This function fetches the apptrust selectors for the specified port on a KSZ
+ * switch.
+ *
+ * Return: 0 on success, or a negative error code on failure
+ */
+int ksz_port_get_apptrust(struct dsa_switch *ds, int port, u8 *sel, int *nsel)
+{
+	const struct ksz_apptrust_map *map;
+	struct ksz_device *dev = ds->priv;
+	int reg, i, ret;
+	u8 data;
+	u8 mask;
+
+	ksz_get_apptrus_map_and_reg(dev, &map, &reg, &mask);
+
+	ret = ksz_pread8(dev, port, reg, &data);
+	if (ret)
+		return ret;
+
+	*nsel = 0;
+	for (i = 0; i < ARRAY_SIZE(ksz_supported_apptrust); i++) {
+		if (data & map[i].bit)
+			sel[(*nsel)++] = ksz_supported_apptrust[i];
+	}
+
+	return 0;
+}
+
+/**
+ * ksz_dcb_init_port - Initializes the DCB configuration for a port on a KSZ
+ * @dev: Pointer to the KSZ switch device structure
+ * @port: Port number for which to initialize the DCB configuration
+ *
+ * This function initializes the DCB configuration for the specified port on a
+ * KSZ switch. Particular DCB configuration is set for the port, including the
+ * default priority and apptrust selectors.
+ * The default priority is set to Best Effort, and the apptrust selectors are
+ * set to all supported selectors.
+ *
+ * Return: 0 on success, or a negative error code on failure
+ */
+int ksz_dcb_init_port(struct ksz_device *dev, int port)
+{
+	int ret, ipv;
+
+	if (is_ksz8(dev))
+		ipv = ieee8021q_tt_to_tc(IEEE8021Q_TT_BE,
+					 dev->info->num_tx_queues);
+	else
+		ipv = IEEE8021Q_TT_BE;
+
+	/* Set the default priority for the port to Best Effort */
+	ret = ksz_port_set_default_prio(dev->ds, port, ipv);
+	if (ret)
+		return ret;
+
+	return ksz_port_set_apptrust(dev->ds, port, ksz_supported_apptrust,
+				     ARRAY_SIZE(ksz_supported_apptrust));
+}
+
+/**
+ * ksz_dcb_init - Initializes the DCB configuration for a KSZ switch
+ * @dev: Pointer to the KSZ switch device structure
+ *
+ * This function initializes the DCB configuration for a KSZ switch. The global
+ * DSCP-to-priority mapping table is initialized.
+ *
+ * Return: 0 on success, or a negative error code on failure
+ */
+int ksz_dcb_init(struct ksz_device *dev)
+{
+	int ret;
+
+	ret = ksz_init_global_dscp_map(dev);
+	if (ret)
+		return ret;
+
+	return 0;
+}
diff --git a/drivers/net/dsa/microchip/ksz_dcb.h b/drivers/net/dsa/microchip/ksz_dcb.h
new file mode 100644
index 0000000000000..254c0e7bdafca
--- /dev/null
+++ b/drivers/net/dsa/microchip/ksz_dcb.h
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (c) 2024 Pengutronix, Oleksij Rempel <kernel@pengutronix.de> */
+
+#ifndef __KSZ_DCB_H
+#define __KSZ_DCB_H
+
+#include <net/dsa.h>
+
+#include "ksz_common.h"
+
+int ksz_port_get_default_prio(struct dsa_switch *ds, int port);
+int ksz_port_set_default_prio(struct dsa_switch *ds, int port, u8 prio);
+int ksz_port_get_dscp_prio(struct dsa_switch *ds, int port, u8 dscp);
+int ksz_port_set_apptrust(struct dsa_switch *ds, int port,
+			  const unsigned char *sel,
+			  int nsel);
+int ksz_port_get_apptrust(struct dsa_switch *ds, int port, u8 *sel, int *nsel);
+int ksz_dcb_init_port(struct ksz_device *dev, int port);
+int ksz_dcb_init(struct ksz_device *dev);
+
+#endif /* __KSZ_DCB_H */
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH net-next v1 6/9] net: dsa: microchip: dcb: add special handling for KSZ88X3 family
  2024-03-28 16:05 [PATCH net-next v1 0/9] Enhanced DCB and DSCP Support for KSZ Switches Oleksij Rempel
                   ` (4 preceding siblings ...)
  2024-03-28 16:05 ` [PATCH net-next v1 5/9] net: dsa: microchip: add support for different DCB app configurations Oleksij Rempel
@ 2024-03-28 16:05 ` Oleksij Rempel
  2024-03-28 16:05 ` [PATCH net-next v1 7/9] net: dsa: microchip: enable ETS support for KSZ989X variants Oleksij Rempel
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 19+ messages in thread
From: Oleksij Rempel @ 2024-03-28 16:05 UTC (permalink / raw)
  To: David S. Miller, Andrew Lunn, Eric Dumazet, Florian Fainelli,
	Jakub Kicinski, Paolo Abeni, Vladimir Oltean, Woojung Huh,
	Arun Ramadoss
  Cc: Oleksij Rempel, kernel, linux-kernel, netdev, UNGLinuxDriver,
	David Ahern, Simon Horman, Willem de Bruijn, Søren Andersen

KSZ88X3 switches have different behavior on different ports:
- It seems to be not possible to disable VLAN PCP classification on port
  2. It means, as soon as mutliqueue support is enabled, frames with
     VLAN tag will get PCP prios. This behavior do not affect Port 1 -
     it is possible to disable PCP prios.
- DSCP classification is not working on Port 2.

Since there are still usable configuration combinations, I added some
quirks to make sure user will get appropriate error message if not
possible configuration is chosen.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/net/dsa/microchip/ksz8.h    |   1 +
 drivers/net/dsa/microchip/ksz8795.c |  15 +++
 drivers/net/dsa/microchip/ksz_dcb.c | 185 +++++++++++++++++++++++++++-
 3 files changed, 198 insertions(+), 3 deletions(-)

diff --git a/drivers/net/dsa/microchip/ksz8.h b/drivers/net/dsa/microchip/ksz8.h
index 1a5225264e6a3..cf2f30fd7cfcd 100644
--- a/drivers/net/dsa/microchip/ksz8.h
+++ b/drivers/net/dsa/microchip/ksz8.h
@@ -60,5 +60,6 @@ void ksz8_phylink_mac_link_up(struct ksz_device *dev, int port,
 			      unsigned int mode, phy_interface_t interface,
 			      struct phy_device *phydev, int speed, int duplex,
 			      bool tx_pause, bool rx_pause);
+int ksz8_all_queues_split(struct ksz_device *dev, int queues);
 
 #endif
diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c
index 0ead198bacb2c..a520352d5b93e 100644
--- a/drivers/net/dsa/microchip/ksz8795.c
+++ b/drivers/net/dsa/microchip/ksz8795.c
@@ -179,6 +179,21 @@ static int ksz8_port_queue_split(struct ksz_device *dev, int port, int queues)
 	return ksz_prmw8(dev, port, reg_2q, mask_2q, data_2q);
 }
 
+int ksz8_all_queues_split(struct ksz_device *dev, int queues)
+{
+	struct dsa_switch *ds = dev->ds;
+	const struct dsa_port *dp;
+	int ret;
+
+	dsa_switch_for_each_port(dp, ds) {
+		ret = ksz8_port_queue_split(dev, dp->index, queues);
+		if (ret)
+			return ret;
+	}
+
+	return ret;
+}
+
 void ksz8_r_mib_cnt(struct ksz_device *dev, int port, u16 addr, u64 *cnt)
 {
 	const u32 *masks;
diff --git a/drivers/net/dsa/microchip/ksz_dcb.c b/drivers/net/dsa/microchip/ksz_dcb.c
index 527bf10d35dd3..0b9aa06ef4d24 100644
--- a/drivers/net/dsa/microchip/ksz_dcb.c
+++ b/drivers/net/dsa/microchip/ksz_dcb.c
@@ -132,6 +132,48 @@ int ksz_port_get_default_prio(struct dsa_switch *ds, int port)
 	return (data & mask) >> shift;
 }
 
+/**
+ * ksz88x3_port_set_default_prio_quirks - Quirks for default priority
+ * @dev: Pointer to the KSZ switch device structure
+ * @port: Port number for which to set the default priority
+ * @prio: Priority value to set
+ *
+ * This function implements quirks for setting the default priority on KSZ88x3
+ * devices. On Port 2 (port == 1), no other priority providers are working
+ * except of PCP. So, configuring default priority on Port 2 is not possible.
+ * On Port 1 (port == 0), it is not possible to configure port priority if PCP
+ * apptrust on Port 2 is disabled. Since we disable multiple queues on the
+ * switch to disable PCP on Port 2, we need to ensure that the default priority
+ * configuration on Port 1 is in agreement with the configuration on Port 2.
+ *
+ * Return: 0 on success, or a negative error code on failure
+ */
+static int ksz88x3_port_set_default_prio_quirks(struct ksz_device *dev, int port,
+						u8 prio)
+{
+	if (!prio)
+		return 0;
+
+	if (port == 1) {
+		dev_err(dev->dev, "Port priority configuration is not working on Port 2\n");
+		return -EINVAL;
+	} else if (port == 0) {
+		u8 port1_data;
+		int ret;
+
+		ret = ksz_pread8(dev, 1, KSZ8_REG_PORT_1_CTRL_0, &port1_data);
+		if (ret)
+			return ret;
+
+		if (!(port1_data & KSZ8_PORT_802_1P_ENABLE)) {
+			dev_err(dev->dev, "Not possible to configur port priority on Port 1 if PCP apptrust on Port 2 is disabled\n");
+			return -EINVAL;
+		}
+	}
+
+	return 0;
+}
+
 /**
  * ksz_port_set_default_prio - Sets the default priority for a port on a KSZ
  *			       switch
@@ -147,12 +189,19 @@ int ksz_port_get_default_prio(struct dsa_switch *ds, int port)
 int ksz_port_set_default_prio(struct dsa_switch *ds, int port, u8 prio)
 {
 	struct ksz_device *dev = ds->priv;
-	int reg, shift;
+	int reg, shift, ret;
 	u8 mask;
 
 	if (prio >= dev->info->num_tx_queues)
 		return -EINVAL;
 
+
+	if (ksz_is_ksz88x3(dev)) {
+		ret = ksz88x3_port_set_default_prio_quirks(dev, port, prio);
+		if (ret)
+			return ret;
+	}
+
 	ksz_get_defult_port_prio_reg(dev, &reg, &mask, &shift);
 
 	return ksz_prmw8(dev, port, reg, mask, (prio << shift) & mask);
@@ -401,6 +450,118 @@ static void ksz_get_apptrus_map_and_reg(struct ksz_device *dev,
 	}
 }
 
+/**
+ * ksz88x3_port0_apptrust_quirk - Quirk for apptrust configuration on Port 1
+ *				  (port == 0) of KSZ88x3 devices
+ * @dev: Pointer to the KSZ switch device structure
+ * @port: Port number for which to set the apptrust selectors
+ * @reg: Register address for the apptrust configuration
+ * @data: Data to set for the apptrust configuration
+ *
+ * This function implements a quirk for apptrust configuration on Port 1 of
+ * KSZ88x3 devices. It ensures that apptrust configuration on Port 1 is not
+ * possible if PCP apptrust on Port 2 is disabled. This is because the Port 2
+ * seems to be permanently hardwired to PCP classification, so we need to
+ * do Port 1 configuration always in agreement with Port 2 configuration.
+ *
+ * Return: 0 on success, or a negative error code on failure
+ */
+static int ksz88x3_port0_apptrust_quirk(struct ksz_device *dev, int port,
+					int reg, u8 data)
+{
+	u8 port1_data;
+	int ret;
+
+	if (!(data & (KSZ8_PORT_802_1P_ENABLE | KSZ8_PORT_DIFFSERV_ENABLE)))
+		return 0;
+
+	ret = ksz_pread8(dev, 1, reg, &port1_data);
+	if (ret)
+		return ret;
+
+	if (!(port1_data & KSZ8_PORT_802_1P_ENABLE)) {
+		dev_err(dev->dev, "Not possible to enable any apptrust on Port 1 if PCP apptrust on Port 2 is disabled\n");
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+/**
+ * ksz88x3_port1_apptrust_quirk - Quirk for apptrust configuration on Port 2
+ *				  (port == 1) of KSZ88x3 devices
+ * @dev: Pointer to the KSZ switch device structure
+ * @port: Port number for which to set the apptrust selectors
+ * @reg: Register address for the apptrust configuration
+ * @data: Data to set for the apptrust configuration
+ *
+ * This function implements a quirk for apptrust configuration on Port 2 of
+ * KSZ88x3 devices. It ensures that DSCP apptrust is not working on Port 2 and
+ * that it is not possible to disable PCP on Port 2. The only way to disable PCP
+ * on Port 2 is to disable multiple queues on the switch.
+ *
+ * Return: 0 on success, or a negative error code on failure
+ */
+static int ksz88x3_port1_apptrust_quirk(struct ksz_device *dev, int port,
+					int reg, u8 data)
+{
+	struct dsa_switch *ds = dev->ds;
+	u8 port0_data;
+	int ret;
+
+	if (data & KSZ8_PORT_DIFFSERV_ENABLE) {
+		dev_err(dev->dev, "DSCP apptrust is not working on Port 2\n");
+		return -EINVAL;
+	}
+
+	if (data & KSZ8_PORT_802_1P_ENABLE)
+		return ksz8_all_queues_split(dev, dev->info->num_tx_queues);
+
+	ret = ksz_pread8(dev, 0, reg, &port0_data);
+	if (ret)
+		return ret;
+
+	if (port0_data & (KSZ8_PORT_802_1P_ENABLE | KSZ8_PORT_DIFFSERV_ENABLE)) {
+		dev_err(dev->dev, "Not possible to disable PCP on Port 2 if any apptrust is enabled on Port 1\n");
+		return -EINVAL;
+	}
+
+	ret = ksz_port_get_default_prio(ds, 0);
+	if (ret < 0) {
+		return ret;
+	} else if (ret) {
+		dev_err(dev->dev, "Not possible to disable PCP on Port 2 if non zero default priority is set on Port 1\n");
+		return -EINVAL;
+	}
+
+	return ksz8_all_queues_split(dev, 1);
+}
+
+/**
+ * ksz88x3_port_apptrust_quirk - Quirk for apptrust configuration on KSZ88x3
+ *			       devices
+ * @dev: Pointer to the KSZ switch device structure
+ * @port: Port number for which to set the apptrust selectors
+ * @reg: Register address for the apptrust configuration
+ * @data: Data to set for the apptrust configuration
+ *
+ * This function implements a quirk for apptrust configuration on KSZ88x3
+ * devices. It ensures that apptrust configuration on Port 1 (port == 0) and
+ * Port 2 (port == 1) is done in agreement with each other.
+ *
+ * Return: 0 on success, or a negative error code on failure
+ */
+static int ksz88x3_port_apptrust_quirk(struct ksz_device *dev, int port,
+				       int reg, u8 data)
+{
+	if (port == 0) {
+		return ksz88x3_port0_apptrust_quirk(dev, port, reg, data);
+	} else if (port == 1)
+		return ksz88x3_port1_apptrust_quirk(dev, port, reg, data);
+
+	return 0;
+}
+
 /**
  * ksz_port_set_apptrust - Sets the apptrust selectors for a port on a KSZ
  *			   switch
@@ -441,6 +602,12 @@ int ksz_port_set_apptrust(struct dsa_switch *ds, int port,
 		}
 	}
 
+	if (ksz_is_ksz88x3(dev)) {
+		ret = ksz88x3_port_apptrust_quirk(dev, port, reg, data);
+		if (ret)
+			return ret;
+	}
+
 	return ksz_prmw8(dev, port, reg, mask, data);
 }
 
@@ -495,7 +662,9 @@ int ksz_port_get_apptrust(struct dsa_switch *ds, int port, u8 *sel, int *nsel)
  */
 int ksz_dcb_init_port(struct ksz_device *dev, int port)
 {
+	const u8 *sel;
 	int ret, ipv;
+	int sel_len;
 
 	if (is_ksz8(dev))
 		ipv = ieee8021q_tt_to_tc(IEEE8021Q_TT_BE,
@@ -508,8 +677,18 @@ int ksz_dcb_init_port(struct ksz_device *dev, int port)
 	if (ret)
 		return ret;
 
-	return ksz_port_set_apptrust(dev->ds, port, ksz_supported_apptrust,
-				     ARRAY_SIZE(ksz_supported_apptrust));
+	if (ksz_is_ksz88x3(dev) && port == 1) {
+		/* KSZ88x3 devices do not support DSCP classification on
+		 * "Port 2" (port == 1).
+		 */
+		sel = ksz8_port2_supported_apptrust;
+		sel_len = ARRAY_SIZE(ksz8_port2_supported_apptrust);
+	} else {
+		sel = ksz_supported_apptrust;
+		sel_len = ARRAY_SIZE(ksz_supported_apptrust);
+	}
+
+	return ksz_port_set_apptrust(dev->ds, port, sel, sel_len);
 }
 
 /**
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH net-next v1 7/9] net: dsa: microchip: enable ETS support for KSZ989X variants
  2024-03-28 16:05 [PATCH net-next v1 0/9] Enhanced DCB and DSCP Support for KSZ Switches Oleksij Rempel
                   ` (5 preceding siblings ...)
  2024-03-28 16:05 ` [PATCH net-next v1 6/9] net: dsa: microchip: dcb: add special handling for KSZ88X3 family Oleksij Rempel
@ 2024-03-28 16:05 ` Oleksij Rempel
  2024-04-02  3:38   ` Arun.Ramadoss
  2024-03-28 16:05 ` [PATCH net-next v1 8/9] net: dsa: microchip: init predictable IPV to queue mapping for all non KSZ8xxx variants Oleksij Rempel
  2024-03-28 16:05 ` [PATCH net-next v1 9/9] net: dsa: microchip: let DCB code do PCP and DSCP policy configuration Oleksij Rempel
  8 siblings, 1 reply; 19+ messages in thread
From: Oleksij Rempel @ 2024-03-28 16:05 UTC (permalink / raw)
  To: David S. Miller, Andrew Lunn, Eric Dumazet, Florian Fainelli,
	Jakub Kicinski, Paolo Abeni, Vladimir Oltean, Woojung Huh,
	Arun Ramadoss
  Cc: Oleksij Rempel, kernel, linux-kernel, netdev, UNGLinuxDriver,
	David Ahern, Simon Horman, Willem de Bruijn, Søren Andersen

I tested ETS support on KSZ9893, so it should work other KSZ989X
variants too.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/net/dsa/microchip/ksz_common.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
index ea2d6f8d381bc..08426f85f7707 100644
--- a/drivers/net/dsa/microchip/ksz_common.c
+++ b/drivers/net/dsa/microchip/ksz_common.c
@@ -1378,6 +1378,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.port_nirqs = 2,
 		.num_tx_queues = 4,
 		.max_ipvs = 8,
+		.tc_ets_supported = true,
 		.ops = &ksz9477_dev_ops,
 		.mib_names = ksz9477_mib_names,
 		.mib_cnt = ARRAY_SIZE(ksz9477_mib_names),
@@ -1411,6 +1412,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.port_nirqs = 2,
 		.num_tx_queues = 4,
 		.max_ipvs = 8,
+		.tc_ets_supported = true,
 		.ops = &ksz9477_dev_ops,
 		.mib_names = ksz9477_mib_names,
 		.mib_cnt = ARRAY_SIZE(ksz9477_mib_names),
@@ -1442,6 +1444,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.port_nirqs = 2,
 		.num_tx_queues = 4,
 		.max_ipvs = 8,
+		.tc_ets_supported = true,
 		.ops = &ksz9477_dev_ops,
 		.mib_names = ksz9477_mib_names,
 		.mib_cnt = ARRAY_SIZE(ksz9477_mib_names),
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH net-next v1 8/9] net: dsa: microchip: init predictable IPV to queue mapping for all non KSZ8xxx variants
  2024-03-28 16:05 [PATCH net-next v1 0/9] Enhanced DCB and DSCP Support for KSZ Switches Oleksij Rempel
                   ` (6 preceding siblings ...)
  2024-03-28 16:05 ` [PATCH net-next v1 7/9] net: dsa: microchip: enable ETS support for KSZ989X variants Oleksij Rempel
@ 2024-03-28 16:05 ` Oleksij Rempel
  2024-04-02  4:07   ` Arun.Ramadoss
  2024-03-28 16:05 ` [PATCH net-next v1 9/9] net: dsa: microchip: let DCB code do PCP and DSCP policy configuration Oleksij Rempel
  8 siblings, 1 reply; 19+ messages in thread
From: Oleksij Rempel @ 2024-03-28 16:05 UTC (permalink / raw)
  To: David S. Miller, Andrew Lunn, Eric Dumazet, Florian Fainelli,
	Jakub Kicinski, Paolo Abeni, Vladimir Oltean, Woojung Huh,
	Arun Ramadoss
  Cc: Oleksij Rempel, kernel, linux-kernel, netdev, UNGLinuxDriver,
	David Ahern, Simon Horman, Willem de Bruijn, Søren Andersen

Init priority to queue mapping in the way as it shown in IEEE 802.1Q
mapping example.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/net/dsa/microchip/ksz_common.c | 53 ++++++++++++++------------
 1 file changed, 29 insertions(+), 24 deletions(-)

diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
index 08426f85f7707..78e9610044ea8 100644
--- a/drivers/net/dsa/microchip/ksz_common.c
+++ b/drivers/net/dsa/microchip/ksz_common.c
@@ -24,6 +24,7 @@
 #include <linux/of_net.h>
 #include <linux/micrel_phy.h>
 #include <net/dsa.h>
+#include <net/ieee8021q.h>
 #include <net/pkt_cls.h>
 #include <net/switchdev.h>
 
@@ -2692,9 +2693,29 @@ static int ksz_port_mdb_del(struct dsa_switch *ds, int port,
 	return dev->dev_ops->mdb_del(dev, port, mdb, db);
 }
 
+static int ksz_set_default_prio_queue_mapping(struct ksz_device *dev, int port)
+{
+	u32 queue_map = 0;
+	int ipv;
+
+	for (ipv = 0; ipv < dev->info->max_ipvs; ipv++) {
+		int queue;
+
+		/* Traffic Type (TT) is corresponding to the Internal Priority
+		 * Value (IPV) in the switch. Traffic Class (TC) is
+		 * corresponding to the queue in the switch.
+		 */
+		queue = ieee8021q_tt_to_tc(ipv, dev->info->num_tx_queues);
+		queue_map |= queue << (ipv * KSZ9477_PORT_TC_MAP_S);
+	}
+
+	return ksz_pwrite32(dev, port, KSZ9477_PORT_MRI_TC_MAP__4, queue_map);
+}
+
 static int ksz_port_setup(struct dsa_switch *ds, int port)
 {
 	struct ksz_device *dev = ds->priv;
+	int ret;
 
 	if (!dsa_is_user_port(ds, port))
 		return 0;
@@ -2702,6 +2723,12 @@ static int ksz_port_setup(struct dsa_switch *ds, int port)
 	/* setup user port */
 	dev->dev_ops->port_setup(dev, port, false);
 
+	if (!is_ksz8(dev)) {
+		ret = ksz_set_default_prio_queue_mapping(dev, port);
+		if (ret)
+			return ret;
+	}
+
 	/* port_stp_state_set() will be called after to enable the port so
 	 * there is no need to do anything.
 	 */
@@ -3566,8 +3593,7 @@ static int ksz_tc_ets_add(struct ksz_device *dev, int port,
 
 static int ksz_tc_ets_del(struct ksz_device *dev, int port)
 {
-	int ret, queue, tc_prio, s;
-	u32 queue_map = 0;
+	int ret, queue;
 
 	/* To restore the default chip configuration, set all queues to use the
 	 * WRR scheduler with a weight of 1.
@@ -3579,31 +3605,10 @@ static int ksz_tc_ets_del(struct ksz_device *dev, int port)
 			return ret;
 	}
 
-	switch (dev->info->num_tx_queues) {
-	case 2:
-		s = 2;
-		break;
-	case 4:
-		s = 1;
-		break;
-	case 8:
-		s = 0;
-		break;
-	default:
-		return -EINVAL;
-	}
-
 	/* Revert the queue mapping for TC-priority to its default setting on
 	 * the chip.
 	 */
-	for (tc_prio = 0; tc_prio < dev->info->max_ipvs; tc_prio++) {
-		int queue;
-
-		queue = tc_prio >> s;
-		queue_map |= queue << (tc_prio * KSZ9477_PORT_TC_MAP_S);
-	}
-
-	return ksz_pwrite32(dev, port, KSZ9477_PORT_MRI_TC_MAP__4, queue_map);
+	return ksz_set_default_prio_queue_mapping(dev, port);
 }
 
 static int ksz_tc_ets_validate(struct ksz_device *dev, int port,
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH net-next v1 9/9] net: dsa: microchip: let DCB code do PCP and DSCP policy configuration
  2024-03-28 16:05 [PATCH net-next v1 0/9] Enhanced DCB and DSCP Support for KSZ Switches Oleksij Rempel
                   ` (7 preceding siblings ...)
  2024-03-28 16:05 ` [PATCH net-next v1 8/9] net: dsa: microchip: init predictable IPV to queue mapping for all non KSZ8xxx variants Oleksij Rempel
@ 2024-03-28 16:05 ` Oleksij Rempel
  8 siblings, 0 replies; 19+ messages in thread
From: Oleksij Rempel @ 2024-03-28 16:05 UTC (permalink / raw)
  To: David S. Miller, Andrew Lunn, Eric Dumazet, Florian Fainelli,
	Jakub Kicinski, Paolo Abeni, Vladimir Oltean, Woojung Huh,
	Arun Ramadoss
  Cc: Oleksij Rempel, kernel, linux-kernel, netdev, UNGLinuxDriver,
	David Ahern, Simon Horman, Willem de Bruijn, Søren Andersen

802.1P (PCP) and DiffServ (DSCP) are handled now by DCB code. Let it do
all needed initial configuration.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/net/dsa/microchip/ksz8795.c | 6 ------
 drivers/net/dsa/microchip/ksz9477.c | 6 ------
 2 files changed, 12 deletions(-)

diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c
index a520352d5b93e..06dbc75aef8fd 100644
--- a/drivers/net/dsa/microchip/ksz8795.c
+++ b/drivers/net/dsa/microchip/ksz8795.c
@@ -1564,16 +1564,10 @@ void ksz8_port_setup(struct ksz_device *dev, int port, bool cpu_port)
 
 	ksz8_port_queue_split(dev, port, queues);
 
-	/* disable DiffServ priority */
-	ksz_port_cfg(dev, port, P_PRIO_CTRL, PORT_DIFFSERV_ENABLE, false);
-
 	/* replace priority */
 	ksz_port_cfg(dev, port, P_802_1P_CTRL,
 		     masks[PORT_802_1P_REMAPPING], false);
 
-	/* enable 802.1p priority */
-	ksz_port_cfg(dev, port, P_PRIO_CTRL, PORT_802_1P_ENABLE, true);
-
 	if (cpu_port)
 		member = dsa_user_ports(ds);
 	else
diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c
index 7f745628c84d1..f8ad7833f5d9d 100644
--- a/drivers/net/dsa/microchip/ksz9477.c
+++ b/drivers/net/dsa/microchip/ksz9477.c
@@ -1158,18 +1158,12 @@ void ksz9477_port_setup(struct ksz_device *dev, int port, bool cpu_port)
 	/* enable broadcast storm limit */
 	ksz_port_cfg(dev, port, P_BCAST_STORM_CTRL, PORT_BROADCAST_STORM, true);
 
-	/* disable DiffServ priority */
-	ksz_port_cfg(dev, port, P_PRIO_CTRL, PORT_DIFFSERV_PRIO_ENABLE, false);
-
 	/* replace priority */
 	ksz_port_cfg(dev, port, REG_PORT_MRI_MAC_CTRL, PORT_USER_PRIO_CEILING,
 		     false);
 	ksz9477_port_cfg32(dev, port, REG_PORT_MTI_QUEUE_CTRL_0__4,
 			   MTI_PVID_REPLACE, false);
 
-	/* enable 802.1p priority */
-	ksz_port_cfg(dev, port, P_PRIO_CTRL, PORT_802_1P_PRIO_ENABLE, true);
-
 	/* force flow control for non-PHY ports only */
 	ksz_port_cfg(dev, port, REG_PORT_CTRL_0,
 		     PORT_FORCE_TX_FLOW_CTRL | PORT_FORCE_RX_FLOW_CTRL,
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* RE: [PATCH net-next v1 5/9] net: dsa: microchip: add support for different DCB app configurations
  2024-03-28 16:05 ` [PATCH net-next v1 5/9] net: dsa: microchip: add support for different DCB app configurations Oleksij Rempel
@ 2024-03-29  9:29   ` Naveen Mamindlapalli
  2024-03-30 14:55     ` Andrew Lunn
  2024-03-29  9:33   ` kernel test robot
  2024-03-30  2:55   ` kernel test robot
  2 siblings, 1 reply; 19+ messages in thread
From: Naveen Mamindlapalli @ 2024-03-29  9:29 UTC (permalink / raw)
  To: Oleksij Rempel, David S. Miller, Andrew Lunn, Eric Dumazet,
	Florian Fainelli, Jakub Kicinski, Paolo Abeni, Vladimir Oltean,
	Woojung Huh, Arun Ramadoss
  Cc: kernel, linux-kernel, netdev, UNGLinuxDriver, David Ahern,
	Simon Horman, Willem de Bruijn, Søren Andersen


> -----Original Message-----
> From: Oleksij Rempel <o.rempel@pengutronix.de>
> Sent: Thursday, March 28, 2024 9:35 PM
> To: David S. Miller <davem@davemloft.net>; Andrew Lunn <andrew@lunn.ch>;
> Eric Dumazet <edumazet@google.com>; Florian Fainelli <f.fainelli@gmail.com>;
> Jakub Kicinski <kuba@kernel.org>; Paolo Abeni <pabeni@redhat.com>; Vladimir
> Oltean <olteanv@gmail.com>; Woojung Huh <woojung.huh@microchip.com>;
> Arun Ramadoss <arun.ramadoss@microchip.com>
> Cc: Oleksij Rempel <o.rempel@pengutronix.de>; kernel@pengutronix.de; linux-
> kernel@vger.kernel.org; netdev@vger.kernel.org;
> UNGLinuxDriver@microchip.com; David Ahern <dsahern@kernel.org>; Simon
> Horman <horms@kernel.org>; Willem de Bruijn <willemb@google.com>; Søren
> Andersen <san@skov.dk>
> Subject: [PATCH net-next v1 5/9] net: dsa: microchip: add support
> for different DCB app configurations
> 
> Add DCB support to configure app trust sources and default port priority.
> 
> Following commands can be used for testing:
> dcb apptrust set dev lan1 order pcp dscp dcb app replace dev lan1 default-prio 3
> 
> Since it is not possible to configure DSCP-Prio mapping per port, this patch
> provide only ability to read switch global dscp-prio mapping and way to
> enable/disable app trust for DSCP.
> 
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> ---
>  drivers/net/dsa/microchip/Kconfig      |   2 +
>  drivers/net/dsa/microchip/Makefile     |   2 +-
>  drivers/net/dsa/microchip/ksz_common.c |  12 +-
>  drivers/net/dsa/microchip/ksz_common.h |   5 +
>  drivers/net/dsa/microchip/ksz_dcb.c    | 533 +++++++++++++++++++++++++
>  drivers/net/dsa/microchip/ksz_dcb.h    |  21 +
>  6 files changed, 573 insertions(+), 2 deletions(-)  create mode 100644
> drivers/net/dsa/microchip/ksz_dcb.c
>  create mode 100644 drivers/net/dsa/microchip/ksz_dcb.h
> 
> diff --git a/drivers/net/dsa/microchip/Kconfig b/drivers/net/dsa/microchip/Kconfig
> index 394ca8678d2ba..c1b906c05a025 100644
> --- a/drivers/net/dsa/microchip/Kconfig
> +++ b/drivers/net/dsa/microchip/Kconfig
> @@ -4,6 +4,8 @@ menuconfig NET_DSA_MICROCHIP_KSZ_COMMON
>  	depends on NET_DSA
>  	select NET_DSA_TAG_KSZ
>  	select NET_DSA_TAG_NONE
> +	select NET_IEEE8021Q_HELPERS
> +	select DCB
>  	help
>  	  This driver adds support for Microchip KSZ9477 series switch and
>  	  KSZ8795/KSZ88x3 switch chips.
> diff --git a/drivers/net/dsa/microchip/Makefile b/drivers/net/dsa/microchip/Makefile
> index 49459a50dbc81..1cfba1ec9355a 100644
> --- a/drivers/net/dsa/microchip/Makefile
> +++ b/drivers/net/dsa/microchip/Makefile
> @@ -1,6 +1,6 @@
>  # SPDX-License-Identifier: GPL-2.0-only
>  obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ_COMMON)	+= ksz_switch.o
> -ksz_switch-objs := ksz_common.o
> +ksz_switch-objs := ksz_common.o ksz_dcb.o
>  ksz_switch-objs += ksz9477.o ksz9477_acl.o ksz9477_tc_flower.o  ksz_switch-
> objs += ksz8795.o  ksz_switch-objs += lan937x_main.o diff --git
> a/drivers/net/dsa/microchip/ksz_common.c
> b/drivers/net/dsa/microchip/ksz_common.c
> index cf81739d91dae..ea2d6f8d381bc 100644
> --- a/drivers/net/dsa/microchip/ksz_common.c
> +++ b/drivers/net/dsa/microchip/ksz_common.c
> @@ -28,6 +28,7 @@
>  #include <net/switchdev.h>
> 
>  #include "ksz_common.h"
> +#include "ksz_dcb.h"
>  #include "ksz_ptp.h"
>  #include "ksz8.h"
>  #include "ksz9477.h"
> @@ -2371,6 +2372,10 @@ static int ksz_setup(struct dsa_switch *ds)
>  		goto out_ptp_clock_unregister;
>  	}
> 
> +	ret = ksz_dcb_init(dev);
> +	if (ret)
> +		goto out_ptp_clock_unregister;
> +
>  	/* start switch */
>  	regmap_update_bits(ksz_regmap_8(dev), regs[S_START_CTRL],
>  			   SW_START, SW_START);
> @@ -2698,7 +2703,7 @@ static int ksz_port_setup(struct dsa_switch *ds, int
> port)
>  	 * there is no need to do anything.
>  	 */
> 
> -	return 0;
> +	return ksz_dcb_init_port(dev, port);
>  }
> 
>  void ksz_port_stp_state_set(struct dsa_switch *ds, int port, u8 state) @@ -
> 3950,6 +3955,11 @@ static const struct dsa_switch_ops ksz_switch_ops = {
>  	.port_setup_tc		= ksz_setup_tc,
>  	.get_mac_eee		= ksz_get_mac_eee,
>  	.set_mac_eee		= ksz_set_mac_eee,
> +	.port_get_default_prio	= ksz_port_get_default_prio,
> +	.port_set_default_prio	= ksz_port_set_default_prio,
> +	.port_get_dscp_prio	= ksz_port_get_dscp_prio,
> +	.port_set_apptrust	= ksz_port_set_apptrust,
> +	.port_get_apptrust	= ksz_port_get_apptrust,
>  };
> 
>  struct ksz_device *ksz_switch_alloc(struct device *base, void *priv) diff --git
> a/drivers/net/dsa/microchip/ksz_common.h
> b/drivers/net/dsa/microchip/ksz_common.h
> index 1bedd240cbbe4..4f48a8347e5de 100644
> --- a/drivers/net/dsa/microchip/ksz_common.h
> +++ b/drivers/net/dsa/microchip/ksz_common.h
> @@ -621,6 +621,11 @@ static inline bool ksz_is_ksz88x3(struct ksz_device
> *dev)
>  	return dev->chip_id == KSZ8830_CHIP_ID;  }
> 
> +static inline bool is_ksz8(struct ksz_device *dev) {
> +	return ksz_is_ksz87xx(dev) || ksz_is_ksz88x3(dev); }
> +
>  static inline int is_lan937x(struct ksz_device *dev)  {
>  	return dev->chip_id == LAN9370_CHIP_ID || diff --git
> a/drivers/net/dsa/microchip/ksz_dcb.c b/drivers/net/dsa/microchip/ksz_dcb.c
> new file mode 100644
> index 0000000000000..527bf10d35dd3
> --- /dev/null
> +++ b/drivers/net/dsa/microchip/ksz_dcb.c
> @@ -0,0 +1,533 @@
> +// SPDX-License-Identifier: GPL-2.0
> +// Copyright (c) 2024 Pengutronix, Oleksij Rempel
> +<kernel@pengutronix.de>
> +
> +#include <linux/dsa/ksz_common.h>
> +#include <net/dsa.h>
> +#include <net/dscp.h>
> +#include <net/ieee8021q.h>
> +
> +#include "ksz_common.h"
> +#include "ksz_dcb.h"
> +#include "ksz8.h"
> +
> +#define KSZ8_REG_PORT_1_CTRL_0			0x10
> +#define KSZ8_PORT_DIFFSERV_ENABLE		BIT(6)
> +#define KSZ8_PORT_802_1P_ENABLE			BIT(5)
> +#define KSZ8_PORT_BASED_PRIO_M			GENMASK(4, 3)
> +
> +#define KSZ88X3_REG_TOS_DSCP_CTRL		0x60
> +#define KSZ8765_REG_TOS_DSCP_CTRL		0x90
> +
> +#define KSZ9477_REG_SW_MAC_TOS_CTRL		0x033e
> +#define KSZ9477_SW_TOS_DSCP_REMAP		BIT(0)
> +#define KSZ9477_SW_TOS_DSCP_DEFAULT_PRIO_M	GENMASK(5, 3)
> +
> +#define KSZ9477_REG_DIFFSERV_PRIO_MAP		0x0340
> +
> +#define KSZ9477_REG_PORT_MRI_PRIO_CTRL		0x0801
> +#define KSZ9477_PORT_HIGHEST_PRIO		BIT(7)
> +#define KSZ9477_PORT_OR_PRIO			BIT(6)
> +#define KSZ9477_PORT_MAC_PRIO_ENABLE		BIT(4)
> +#define KSZ9477_PORT_VLAN_PRIO_ENABLE		BIT(3)
> +#define KSZ9477_PORT_802_1P_PRIO_ENABLE		BIT(2)
> +#define KSZ9477_PORT_DIFFSERV_PRIO_ENABLE	BIT(1)
> +#define KSZ9477_PORT_ACL_PRIO_ENABLE		BIT(0)
> +
> +#define KSZ9477_REG_PORT_MRI_MAC_CTRL		0x0802
> +#define KSZ9477_PORT_BASED_PRIO_M		GENMASK(2, 0)
> +
> +struct ksz_apptrust_map {
> +	u8 apptrust;
> +	u8 bit;
> +};
> +
> +static const struct ksz_apptrust_map ksz8_apptrust_map_to_bit[] = {
> +	{ DCB_APP_SEL_PCP, KSZ8_PORT_802_1P_ENABLE },
> +	{ IEEE_8021QAZ_APP_SEL_DSCP, KSZ8_PORT_DIFFSERV_ENABLE },
> };
> +
> +static const struct ksz_apptrust_map ksz9477_apptrust_map_to_bit[] = {
> +	{ DCB_APP_SEL_PCP, KSZ9477_PORT_802_1P_PRIO_ENABLE },
> +	{ IEEE_8021QAZ_APP_SEL_DSCP,
> KSZ9477_PORT_DIFFSERV_PRIO_ENABLE }, };
> +
> +/**
> + * ksz_supported_apptrust[] - Supported apptrust selectors and Priority Order
> + *			      of Internal Priority Value (IPV) sources.
> + *
> + * This array defines the apptrust selectors supported by the hardware,
> +where
> + * the index within the array indicates the priority of the selector -
> +lower
> + * indices correspond to higher priority. This fixed priority scheme is
> +due to
> + * the hardware's design, which does not support configurable priority
> +among
> + * different priority sources.
> + *
> + * The priority sources, including Tail Tag, ACL, VLAN PCP and DSCP are
> +ordered
> + * by the hardware's fixed logic, as detailed below. The order reflects
> +a
> + * non-configurable precedence where certain types of priority
> +information
> + * override others:
> + *
> + * 1. Tail Tag - Highest priority, overrides ACL, VLAN PCP, and DSCP priorities.
> + * 2. ACL - Overrides VLAN PCP and DSCP priorities.
> + * 3. VLAN PCP - Overrides DSCP priority.
> + * 4. DSCP - Lowest priority, does not override any other priority source.
> + *
> + * In this context, the array's lower index (higher priority) for
> + * 'DCB_APP_SEL_PCP' suggests its relative priority over
> + * 'IEEE_8021QAZ_APP_SEL_DSCP' within the system's fixed priority scheme.
> + *
> + * DCB_APP_SEL_PCP - Priority Code Point selector
> + * IEEE_8021QAZ_APP_SEL_DSCP - Differentiated Services Code Point
> +selector  */ static const u8 ksz_supported_apptrust[] = {
> +	DCB_APP_SEL_PCP,
> +	IEEE_8021QAZ_APP_SEL_DSCP,
> +};
> +
> +static const u8 ksz8_port2_supported_apptrust[] = {
> +	DCB_APP_SEL_PCP,
> +};
> +
> +static const char * const ksz_supported_apptrust_variants[] = {
> +	"empty", "dscp", "pcp", "dscp pcp"
> +};
> +
> +static void ksz_get_defult_port_prio_reg(struct ksz_device *dev, int *reg,
> +					 u8 *mask, int *shift)
> +{
> +	if (is_ksz8(dev)) {
> +		*reg = KSZ8_REG_PORT_1_CTRL_0;
> +		*mask = KSZ8_PORT_BASED_PRIO_M;
> +		*shift = __bf_shf(KSZ8_PORT_BASED_PRIO_M);
> +	} else {
> +		*reg = KSZ9477_REG_PORT_MRI_MAC_CTRL;
> +		*mask = KSZ9477_PORT_BASED_PRIO_M;
> +		*shift = __bf_shf(KSZ9477_PORT_BASED_PRIO_M);
> +	}
> +}
> +
> +/**
> + * ksz_port_get_default_prio - Retrieves the default priority for a port on a
> + *			       KSZ switch
> + * @ds: Pointer to the DSA switch structure
> + * @port: Port number from which to get the default priority
> + *
> + * This function fetches the default priority for the specified port on
> +a KSZ
> + * switch.
> + *
> + * Return: The default priority of the port on success, or a negative
> +error
> + * code on failure.
> + */
> +int ksz_port_get_default_prio(struct dsa_switch *ds, int port) {
> +	struct ksz_device *dev = ds->priv;
> +	int ret, reg, shift;
> +	u8 data, mask;
> +
> +	ksz_get_defult_port_prio_reg(dev, &reg, &mask, &shift);
> +
> +	ret = ksz_pread8(dev, port, reg, &data);
> +	if (ret)
> +		return ret;
> +
> +	return (data & mask) >> shift;
> +}
> +
> +/**
> + * ksz_port_set_default_prio - Sets the default priority for a port on a KSZ
> + *			       switch
> + * @ds: Pointer to the DSA switch structure
> + * @port: Port number for which to set the default priority
> + * @prio: Priority value to set
> + *
> + * This function sets the default priority for the specified port on a
> +KSZ
> + * switch.
> + *
> + * Return: 0 on success, or a negative error code on failure.
> + */
> +int ksz_port_set_default_prio(struct dsa_switch *ds, int port, u8 prio)
> +{
> +	struct ksz_device *dev = ds->priv;
> +	int reg, shift;
> +	u8 mask;
> +
> +	if (prio >= dev->info->num_tx_queues)
> +		return -EINVAL;
> +
> +	ksz_get_defult_port_prio_reg(dev, &reg, &mask, &shift);
> +
> +	return ksz_prmw8(dev, port, reg, mask, (prio << shift) & mask); }
> +
> +/**
> + * ksz_get_dscp_prio_reg - Retrieves the DSCP-to-priority-mapping
> +register
> + * @dev: Pointer to the KSZ switch device structure
> + * @reg: Pointer to the register address to be set
> + * @per_reg: Pointer to the number of DSCP values per register
> + * @mask: Pointer to the mask to be set
> + *
> + * This function retrieves the DSCP to priority mapping register, the
> +number of
> + * DSCP values per register, and the mask to be set.
> + */
> +static void ksz_get_dscp_prio_reg(struct ksz_device *dev, int *reg,
> +				  int *per_reg, u8 *mask)
> +{
> +	if (ksz_is_ksz87xx(dev)) {
> +		*reg = KSZ8765_REG_TOS_DSCP_CTRL;
> +		*per_reg = 4;
> +		*mask = GENMASK(1, 0);
> +	} else if (ksz_is_ksz88x3(dev)) {
> +		*reg = KSZ88X3_REG_TOS_DSCP_CTRL;
> +		*per_reg = 4;
> +		*mask = GENMASK(1, 0);
> +	} else {
> +		*reg = KSZ9477_REG_DIFFSERV_PRIO_MAP;
> +		*per_reg = 2;
> +		*mask = GENMASK(2, 0);
> +	}
> +}
> +
> +/**
> + * ksz_port_get_dscp_prio - Retrieves the priority for a DSCP value on a KSZ
> + *			    switch
> + * @ds: Pointer to the DSA switch structure
> + * @port: Port number for which to get the priority
> + * @dscp: DSCP value for which to get the priority
> + *
> + * This function fetches the priority value from switch global
> +DSCP-to-priorty
> + * mapping table for the specified DSCP value.
> + *
> + * Return: The priority value for the DSCP on success, or a negative
> +error
> + * code on failure.
> + */
> +int ksz_port_get_dscp_prio(struct dsa_switch *ds, int port, u8 dscp) {
> +	struct ksz_device *dev = ds->priv;
> +	int reg, per_reg, ret, shift;
> +	u8 data, mask;
> +
> +	ksz_get_dscp_prio_reg(dev, &reg, &per_reg, &mask);
> +
> +	/* If DSCP remapping is disabled, DSCP bits 3-5 are used as Internal
> +	 * Priority Value (IPV)
> +	 */
> +	if (!is_ksz8(dev)) {
> +		ret = ksz_read8(dev, KSZ9477_REG_SW_MAC_TOS_CTRL,
> &data);
> +		if (ret)
> +			return ret;
> +
> +		/* If DSCP remapping is disabled, DSCP bits 3-5 are used as
> +		 * Internal Priority Value (IPV)
> +		 */
> +		if (!(data & KSZ9477_SW_TOS_DSCP_REMAP))
> +			return
> FIELD_GET(KSZ9477_SW_TOS_DSCP_DEFAULT_PRIO_M,
> +					 dscp);
> +	}
> +
> +	/* In case DSCP remapping is enabled, we need to write the DSCP to
> +	 * priority mapping table.
> +	 */
> +	reg += dscp / per_reg;
> +	ret = ksz_read8(dev, reg, &data);
> +	if (ret)
> +		return ret;
> +
> +	shift = (dscp % per_reg) * (8 / per_reg);
> +
> +	return (data >> shift) & mask;
> +}
> +
> +/**
> + * ksz_init_global_dscp_map - Initializes the global DSCP-to-priority
> +mapping
> + * @dev: Pointer to the KSZ switch device structure
> + *
> + * This function initializes the global DSCP-to-priority mapping table
> +for the
> + * switch.
> + *
> + * Return: 0 on success, or a negative error code on failure  */ static
> +int ksz_init_global_dscp_map(struct ksz_device *dev) {
> +	int reg, per_reg, ret, dscp;
> +	u8 data = 0;
> +	u8 mask;
> +
> +	/* On KSZ9xxx variants, DSCP remapping is disabled by default.
> +	 * Enable to have, predictable and reproducible behavior across
> +	 * different devices.
> +	 */
> +	if (!is_ksz8(dev)) {
> +		ret = ksz_rmw8(dev, KSZ9477_REG_SW_MAC_TOS_CTRL,
> +			       KSZ9477_SW_TOS_DSCP_REMAP,
> +			       KSZ9477_SW_TOS_DSCP_REMAP);
> +		if (ret)
> +			return ret;
> +	}
> +
> +	ksz_get_dscp_prio_reg(dev, &reg, &per_reg, &mask);
> +
> +	for (dscp = 0; dscp < DSCP_MAX; dscp++) {
> +		int ipv, shift;
> +
> +		/* Map DSCP to Traffic Type, which is corresponding to the
> +		 * Internal Priority Value (IPV) in the switch.
> +		 */
> +		if (!is_ksz8(dev)) {
> +			ipv = ietf_dscp_to_ieee8021q_tt(dscp);
> +		} else {
> +			ipv =
> ieee8021q_tt_to_tc(ietf_dscp_to_ieee8021q_tt(dscp),
> +						 dev->info->num_tx_queues);
> +		}

No need for braces for single statement.

> +		shift = (dscp % per_reg) * (8 / per_reg);
> +		data |= (ipv & mask) << shift;
> +
> +		if (dscp % per_reg == per_reg - 1) {
> +			ret = ksz_write8(dev, reg + (dscp / per_reg), data);
> +			if (ret)
> +				return ret;
> +
> +			data = 0;
> +		}
> +	}
> +
> +	return 0;
> +}
> +
> +/**
> + * ksz_apptrust_error - Prints an error message for an invalid apptrust
> +selector
> + * @dev: Pointer to the KSZ switch device structure
> + *
> + * This function prints an error message when an invalid apptrust
> +selector is
> + * provided.
> + */
> +static void ksz_apptrust_error(struct ksz_device *dev) {
> +	char supported_apptrust_variants[64];
> +	int i;
> +
> +	supported_apptrust_variants[0] = '\0';
> +	for (i = 0; i < ARRAY_SIZE(ksz_supported_apptrust_variants); i++) {
> +		if (i > 0)
> +			strlcat(supported_apptrust_variants, ", ",
> +				sizeof(supported_apptrust_variants));
> +		strlcat(supported_apptrust_variants,
> +			ksz_supported_apptrust_variants[i],
> +			sizeof(supported_apptrust_variants));
> +	}
> +
> +	dev_err(dev->dev, "Invalid apptrust selector or priority order. Supported:
> %s\n",
> +		supported_apptrust_variants);
> +}
> +
> +/**
> + * ksz_port_set_apptrust_validate - Validates the apptrust selectors
> + * @dev: Pointer to the KSZ switch device structure
> + * @port: Port number for which to set the apptrust selectors
> + * @sel: Array of apptrust selectors to validate
> + * @nsel: Number of apptrust selectors in the array
> + *
> + * This function validates the apptrust selectors provided and ensures
> +that
> + * they are in the correct order.
> + *
> + * This family of switches supports two apptrust selectors:
> +DCB_APP_SEL_PCP and
> + * IEEE_8021QAZ_APP_SEL_DSCP. The priority order of the selectors is
> +fixed and
> + * cannot be changed. The order is as follows:
> + * 1. DCB_APP_SEL_PCP - Priority Code Point selector (highest priority)
> + * 2. IEEE_8021QAZ_APP_SEL_DSCP - Differentiated Services Code Point
> selector
> + *   (lowest priority)
> + *
> + * Return: 0 on success, or a negative error code on failure  */ static
> +int ksz_port_set_apptrust_validate(struct ksz_device *dev, int port,
> +					  const u8 *sel, int nsel)
> +{
> +	int i, j, j_prev, found;
> +
> +	/* Iterate through the requested selectors */
> +	for (i = 0; i < nsel; i++) {
> +		found = 0;
> +
> +		/* Check if the current selector is supported by the hardware */
> +		for (j = 0; j < sizeof(ksz_supported_apptrust); j++) {
> +			if (sel[i] != ksz_supported_apptrust[j])
> +				continue;
> +
> +			found = 1;
> +
> +			/* Ensure that no higher priority selector (lower index)
> +			 * precedes a lower priority one
> +			 */
> +			if (i > 0 && j <= j_prev)

j_prev is uninitialized. It may contain garbage value.

> +				goto invalid;
> +
> +			j_prev = j;
> +			break;
> +		}
> +
> +		if (!found)
> +			goto invalid;
> +	}
> +
> +	return 0;
> +
> +invalid:
> +	ksz_apptrust_error(dev);
> +
> +	return -EINVAL;
> +}
> +
> +/**
> + * ksz_get_apptrus_map_and_reg - Retrieves the apptrust map and
> +register
> + * @dev: Pointer to the KSZ switch device structure
> + * @map: Pointer to the apptrust map to be set
> + * @reg: Pointer to the register address to be set
> + * @mask: Pointer to the mask to be set
> + *
> + * This function retrieves the apptrust map and register address for
> +the
> + * apptrust configuration.
> + */
> +static void ksz_get_apptrus_map_and_reg(struct ksz_device *dev,
> +					const struct ksz_apptrust_map **map,
> +					int *reg, u8 *mask)
> +{
> +	if (is_ksz8(dev)) {
> +		*map = ksz8_apptrust_map_to_bit;
> +		*reg = KSZ8_REG_PORT_1_CTRL_0;
> +		*mask = KSZ8_PORT_DIFFSERV_ENABLE |
> KSZ8_PORT_802_1P_ENABLE;
> +	} else {
> +		*map = ksz9477_apptrust_map_to_bit;
> +		*reg = KSZ9477_REG_PORT_MRI_PRIO_CTRL;
> +		*mask = KSZ9477_PORT_802_1P_PRIO_ENABLE |
> +			KSZ9477_PORT_DIFFSERV_PRIO_ENABLE;
> +	}
> +}
> +
> +/**
> + * ksz_port_set_apptrust - Sets the apptrust selectors for a port on a KSZ
> + *			   switch
> + * @ds: Pointer to the DSA switch structure
> + * @port: Port number for which to set the apptrust selectors
> + * @sel: Array of apptrust selectors to set
> + * @nsel: Number of apptrust selectors in the array
> + *
> + * This function sets the apptrust selectors for the specified port on
> +a KSZ
> + * switch.
> + *
> + * Return: 0 on success, or a negative error code on failure  */ int
> +ksz_port_set_apptrust(struct dsa_switch *ds, int port,
> +			  const u8 *sel, int nsel)
> +{
> +	const struct ksz_apptrust_map *map;
> +	struct ksz_device *dev = ds->priv;
> +	int reg, i, ret;
> +	u8 data = 0;
> +	u8 mask;
> +
> +	ret = ksz_port_set_apptrust_validate(dev, port, sel, nsel);
> +	if (ret)
> +		return ret;
> +
> +	ksz_get_apptrus_map_and_reg(dev, &map, &reg, &mask);
> +
> +	for (i = 0; i < nsel; i++) {
> +		int j;
> +
> +		for (j = 0; j < ARRAY_SIZE(ksz_supported_apptrust); j++) {
> +			if (sel[i] != ksz_supported_apptrust[j])
> +				continue;
> +
> +			data |= map[j].bit;
> +			break;
> +		}
> +	}
> +
> +	return ksz_prmw8(dev, port, reg, mask, data); }
> +
> +/**
> + * ksz_port_get_apptrust - Retrieves the apptrust selectors for a port on a KSZ
> + *			   switch
> + * @ds: Pointer to the DSA switch structure
> + * @port: Port number for which to get the apptrust selectors
> + * @sel: Array to store the apptrust selectors
> + * @nsel: Number of apptrust selectors in the array
> + *
> + * This function fetches the apptrust selectors for the specified port
> +on a KSZ
> + * switch.
> + *
> + * Return: 0 on success, or a negative error code on failure  */ int
> +ksz_port_get_apptrust(struct dsa_switch *ds, int port, u8 *sel, int
> +*nsel) {
> +	const struct ksz_apptrust_map *map;
> +	struct ksz_device *dev = ds->priv;
> +	int reg, i, ret;
> +	u8 data;
> +	u8 mask;
> +
> +	ksz_get_apptrus_map_and_reg(dev, &map, &reg, &mask);
> +
> +	ret = ksz_pread8(dev, port, reg, &data);
> +	if (ret)
> +		return ret;
> +
> +	*nsel = 0;
> +	for (i = 0; i < ARRAY_SIZE(ksz_supported_apptrust); i++) {
> +		if (data & map[i].bit)
> +			sel[(*nsel)++] = ksz_supported_apptrust[i];
> +	}
> +
> +	return 0;
> +}
> +
> +/**
> + * ksz_dcb_init_port - Initializes the DCB configuration for a port on
> +a KSZ
> + * @dev: Pointer to the KSZ switch device structure
> + * @port: Port number for which to initialize the DCB configuration
> + *
> + * This function initializes the DCB configuration for the specified
> +port on a
> + * KSZ switch. Particular DCB configuration is set for the port,
> +including the
> + * default priority and apptrust selectors.
> + * The default priority is set to Best Effort, and the apptrust
> +selectors are
> + * set to all supported selectors.
> + *
> + * Return: 0 on success, or a negative error code on failure  */ int
> +ksz_dcb_init_port(struct ksz_device *dev, int port) {
> +	int ret, ipv;
> +
> +	if (is_ksz8(dev))
> +		ipv = ieee8021q_tt_to_tc(IEEE8021Q_TT_BE,
> +					 dev->info->num_tx_queues);
> +	else
> +		ipv = IEEE8021Q_TT_BE;
> +
> +	/* Set the default priority for the port to Best Effort */
> +	ret = ksz_port_set_default_prio(dev->ds, port, ipv);
> +	if (ret)
> +		return ret;
> +
> +	return ksz_port_set_apptrust(dev->ds, port, ksz_supported_apptrust,
> +				     ARRAY_SIZE(ksz_supported_apptrust));
> +}
> +
> +/**
> + * ksz_dcb_init - Initializes the DCB configuration for a KSZ switch
> + * @dev: Pointer to the KSZ switch device structure
> + *
> + * This function initializes the DCB configuration for a KSZ switch.
> +The global
> + * DSCP-to-priority mapping table is initialized.
> + *
> + * Return: 0 on success, or a negative error code on failure  */ int
> +ksz_dcb_init(struct ksz_device *dev) {
> +	int ret;
> +
> +	ret = ksz_init_global_dscp_map(dev);
> +	if (ret)
> +		return ret;
> +
> +	return 0;
> +}
> diff --git a/drivers/net/dsa/microchip/ksz_dcb.h
> b/drivers/net/dsa/microchip/ksz_dcb.h
> new file mode 100644
> index 0000000000000..254c0e7bdafca
> --- /dev/null
> +++ b/drivers/net/dsa/microchip/ksz_dcb.h
> @@ -0,0 +1,21 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/* Copyright (c) 2024 Pengutronix, Oleksij Rempel
> +<kernel@pengutronix.de> */
> +
> +#ifndef __KSZ_DCB_H
> +#define __KSZ_DCB_H
> +
> +#include <net/dsa.h>
> +
> +#include "ksz_common.h"
> +
> +int ksz_port_get_default_prio(struct dsa_switch *ds, int port); int
> +ksz_port_set_default_prio(struct dsa_switch *ds, int port, u8 prio);
> +int ksz_port_get_dscp_prio(struct dsa_switch *ds, int port, u8 dscp);
> +int ksz_port_set_apptrust(struct dsa_switch *ds, int port,
> +			  const unsigned char *sel,
> +			  int nsel);
> +int ksz_port_get_apptrust(struct dsa_switch *ds, int port, u8 *sel, int
> +*nsel); int ksz_dcb_init_port(struct ksz_device *dev, int port); int
> +ksz_dcb_init(struct ksz_device *dev);
> +
> +#endif /* __KSZ_DCB_H */
> --
> 2.39.2
> 


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH net-next v1 5/9] net: dsa: microchip: add support for different DCB app configurations
  2024-03-28 16:05 ` [PATCH net-next v1 5/9] net: dsa: microchip: add support for different DCB app configurations Oleksij Rempel
  2024-03-29  9:29   ` Naveen Mamindlapalli
@ 2024-03-29  9:33   ` kernel test robot
  2024-03-30  2:55   ` kernel test robot
  2 siblings, 0 replies; 19+ messages in thread
From: kernel test robot @ 2024-03-29  9:33 UTC (permalink / raw)
  To: Oleksij Rempel, David S. Miller, Andrew Lunn, Eric Dumazet,
	Florian Fainelli, Jakub Kicinski, Paolo Abeni, Vladimir Oltean,
	Woojung Huh, Arun Ramadoss
  Cc: oe-kbuild-all, netdev, Oleksij Rempel, kernel, linux-kernel,
	UNGLinuxDriver, David Ahern, Simon Horman, Willem de Bruijn,
	Søren Andersen

Hi Oleksij,

kernel test robot noticed the following build warnings:

[auto build test WARNING on net-next/main]

url:    https://github.com/intel-lab-lkp/linux/commits/Oleksij-Rempel/net-dsa-add-support-for-DCB-get-set-apptrust-configuration/20240329-000847
base:   net-next/main
patch link:    https://lore.kernel.org/r/20240328160518.2396238-6-o.rempel%40pengutronix.de
patch subject: [PATCH net-next v1 5/9] net: dsa: microchip: add support for different DCB app configurations
config: sh-allmodconfig (https://download.01.org/0day-ci/archive/20240329/202403291727.iblGz7u1-lkp@intel.com/config)
compiler: sh4-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240329/202403291727.iblGz7u1-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202403291727.iblGz7u1-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> drivers/net/dsa/microchip/ksz_dcb.c:81: warning: cannot understand function prototype: 'const u8 ksz_supported_apptrust[] = '


vim +81 drivers/net/dsa/microchip/ksz_dcb.c

    53	
    54	/**
    55	 * ksz_supported_apptrust[] - Supported apptrust selectors and Priority Order
    56	 *			      of Internal Priority Value (IPV) sources.
    57	 *
    58	 * This array defines the apptrust selectors supported by the hardware, where
    59	 * the index within the array indicates the priority of the selector - lower
    60	 * indices correspond to higher priority. This fixed priority scheme is due to
    61	 * the hardware's design, which does not support configurable priority among
    62	 * different priority sources.
    63	 *
    64	 * The priority sources, including Tail Tag, ACL, VLAN PCP and DSCP are ordered
    65	 * by the hardware's fixed logic, as detailed below. The order reflects a
    66	 * non-configurable precedence where certain types of priority information
    67	 * override others:
    68	 *
    69	 * 1. Tail Tag - Highest priority, overrides ACL, VLAN PCP, and DSCP priorities.
    70	 * 2. ACL - Overrides VLAN PCP and DSCP priorities.
    71	 * 3. VLAN PCP - Overrides DSCP priority.
    72	 * 4. DSCP - Lowest priority, does not override any other priority source.
    73	 *
    74	 * In this context, the array's lower index (higher priority) for
    75	 * 'DCB_APP_SEL_PCP' suggests its relative priority over
    76	 * 'IEEE_8021QAZ_APP_SEL_DSCP' within the system's fixed priority scheme.
    77	 *
    78	 * DCB_APP_SEL_PCP - Priority Code Point selector
    79	 * IEEE_8021QAZ_APP_SEL_DSCP - Differentiated Services Code Point selector
    80	 */
  > 81	static const u8 ksz_supported_apptrust[] = {
    82		DCB_APP_SEL_PCP,
    83		IEEE_8021QAZ_APP_SEL_DSCP,
    84	};
    85	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH net-next v1 5/9] net: dsa: microchip: add support for different DCB app configurations
  2024-03-28 16:05 ` [PATCH net-next v1 5/9] net: dsa: microchip: add support for different DCB app configurations Oleksij Rempel
  2024-03-29  9:29   ` Naveen Mamindlapalli
  2024-03-29  9:33   ` kernel test robot
@ 2024-03-30  2:55   ` kernel test robot
  2 siblings, 0 replies; 19+ messages in thread
From: kernel test robot @ 2024-03-30  2:55 UTC (permalink / raw)
  To: Oleksij Rempel, David S. Miller, Andrew Lunn, Eric Dumazet,
	Florian Fainelli, Jakub Kicinski, Paolo Abeni, Vladimir Oltean,
	Woojung Huh, Arun Ramadoss
  Cc: oe-kbuild-all, netdev, Oleksij Rempel, kernel, linux-kernel,
	UNGLinuxDriver, David Ahern, Simon Horman, Willem de Bruijn,
	Søren Andersen

Hi Oleksij,

kernel test robot noticed the following build errors:

[auto build test ERROR on net-next/main]

url:    https://github.com/intel-lab-lkp/linux/commits/Oleksij-Rempel/net-dsa-add-support-for-DCB-get-set-apptrust-configuration/20240329-000847
base:   net-next/main
patch link:    https://lore.kernel.org/r/20240328160518.2396238-6-o.rempel%40pengutronix.de
patch subject: [PATCH net-next v1 5/9] net: dsa: microchip: add support for different DCB app configurations
config: i386-randconfig-012-20240330 (https://download.01.org/0day-ci/archive/20240330/202403301034.rVoygO9P-lkp@intel.com/config)
compiler: gcc-12 (Ubuntu 12.3.0-9ubuntu2) 12.3.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240330/202403301034.rVoygO9P-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202403301034.rVoygO9P-lkp@intel.com/

All errors (new ones prefixed by >>, old ones prefixed by <<):

WARNING: modpost: missing MODULE_DESCRIPTION() in kernel/rcu/rcuscale.o
WARNING: modpost: missing MODULE_DESCRIPTION() in kernel/rcu/refscale.o
WARNING: modpost: missing MODULE_DESCRIPTION() in kernel/time/time_test.o
WARNING: modpost: missing MODULE_DESCRIPTION() in kernel/trace/preemptirq_delay_test.o
WARNING: modpost: missing MODULE_DESCRIPTION() in kernel/torture.o
WARNING: modpost: missing MODULE_DESCRIPTION() in mm/dmapool_test.o
WARNING: modpost: missing MODULE_DESCRIPTION() in fs/nls/nls_cp737.o
WARNING: modpost: missing MODULE_DESCRIPTION() in fs/nls/nls_cp860.o
WARNING: modpost: missing MODULE_DESCRIPTION() in fs/nls/nls_cp862.o
WARNING: modpost: missing MODULE_DESCRIPTION() in fs/nls/nls_cp866.o
WARNING: modpost: missing MODULE_DESCRIPTION() in fs/nls/nls_cp936.o
WARNING: modpost: missing MODULE_DESCRIPTION() in fs/nls/nls_cp949.o
WARNING: modpost: missing MODULE_DESCRIPTION() in fs/nls/nls_cp950.o
WARNING: modpost: missing MODULE_DESCRIPTION() in fs/nls/nls_iso8859-2.o
WARNING: modpost: missing MODULE_DESCRIPTION() in fs/nls/nls_iso8859-5.o
WARNING: modpost: missing MODULE_DESCRIPTION() in fs/nls/nls_iso8859-7.o
WARNING: modpost: missing MODULE_DESCRIPTION() in fs/nls/nls_iso8859-13.o
WARNING: modpost: missing MODULE_DESCRIPTION() in fs/nls/mac-cyrillic.o
WARNING: modpost: missing MODULE_DESCRIPTION() in fs/nls/mac-gaelic.o
WARNING: modpost: missing MODULE_DESCRIPTION() in fs/nls/mac-roman.o
WARNING: modpost: missing MODULE_DESCRIPTION() in fs/nls/nls_ucs2_utils.o
WARNING: modpost: missing MODULE_DESCRIPTION() in fs/bcachefs/mean_and_variance_test.o
WARNING: modpost: missing MODULE_DESCRIPTION() in fs/binfmt_misc.o
WARNING: modpost: missing MODULE_DESCRIPTION() in fs/minix/minix.o
WARNING: modpost: missing MODULE_DESCRIPTION() in fs/efs/efs.o
WARNING: modpost: missing MODULE_DESCRIPTION() in fs/qnx4/qnx4.o
WARNING: modpost: missing MODULE_DESCRIPTION() in fs/qnx6/qnx6.o
WARNING: modpost: missing MODULE_DESCRIPTION() in security/keys/trusted-keys/trusted.o
WARNING: modpost: missing MODULE_DESCRIPTION() in crypto/algif_hash.o
WARNING: modpost: missing MODULE_DESCRIPTION() in block/t10-pi.o
WARNING: modpost: missing MODULE_DESCRIPTION() in lib/kunit/kunit.o
WARNING: modpost: missing MODULE_DESCRIPTION() in lib/kunit/kunit-test.o
WARNING: modpost: missing MODULE_DESCRIPTION() in lib/kunit/kunit-example-test.o
WARNING: modpost: missing MODULE_DESCRIPTION() in lib/crypto/libarc4.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/gpio/gpio-gw-pld.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/video/backlight/rt4831-backlight.o
WARNING: modpost: drivers/acpi/apei/einj: section mismatch in reference: einj_driver+0x8 (section: .data) -> einj_remove (section: .exit.text)
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/clk/clk-gate_test.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/virtio/virtio.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/virtio/virtio_ring.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/regulator/max20411-regulator.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/tty/n_hdlc.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/char/lp.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/char/nvram.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/char/ppdev.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/gpu/drm/tests/drm_kunit_helpers.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/gpu/drm/tests/drm_buddy_test.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/gpu/drm/tests/drm_cmdline_parser_test.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/gpu/drm/tests/drm_connector_test.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/gpu/drm/tests/drm_damage_helper_test.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/gpu/drm/tests/drm_dp_mst_helper_test.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/gpu/drm/tests/drm_exec_test.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/gpu/drm/tests/drm_format_test.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/gpu/drm/tests/drm_framebuffer_test.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/gpu/drm/tests/drm_gem_shmem_test.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/gpu/drm/tests/drm_managed_test.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/gpu/drm/tests/drm_mm_test.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/gpu/drm/tests/drm_modes_test.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/gpu/drm/tests/drm_plane_helper_test.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/gpu/drm/tests/drm_probe_helper_test.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/gpu/drm/tests/drm_rect_test.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/gpu/drm/bridge/sil-sii8620.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/gpu/drm/tiny/gm12u320.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/base/regmap/regmap-kunit.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/base/regmap/regmap-ram.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/base/regmap/regmap-raw-ram.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/misc/open-dice.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/scsi/scsi_common.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/scsi/aha1740.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/auxdisplay/charlcd.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/auxdisplay/hd44780_common.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/usb/host/xhci-pci-renesas.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/usb/mon/usbmon.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/usb/serial/usb_debug.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/usb/serial/mxuport.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/usb/serial/usb-serial-simple.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/usb/serial/symbolserial.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/input/tests/input_test.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/tuners/tda9887.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/rc-core.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/v4l2-core/v4l2-async.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/v4l2-core/v4l2-fwnode.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/hwmon/mr75203.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/watchdog/twl4030_wdt.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/mmc/core/pwrseq_simple.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/mmc/core/pwrseq_sd8787.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/mmc/core/pwrseq_emmc.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/mmc/core/sdio_uart.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/firmware/google/gsmi.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/of/of_test.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/devfreq/governor_simpleondemand.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/devfreq/governor_performance.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/fsi/fsi-master-gpio.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/parport/parport.o
WARNING: modpost: missing MODULE_DESCRIPTION() in samples/vfio-mdev/mdpy.o
WARNING: modpost: missing MODULE_DESCRIPTION() in samples/vfio-mdev/mbochs.o
WARNING: modpost: missing MODULE_DESCRIPTION() in samples/kobject/kobject-example.o
WARNING: modpost: missing MODULE_DESCRIPTION() in samples/kobject/kset-example.o
WARNING: modpost: missing MODULE_DESCRIPTION() in samples/kprobes/kprobe_example.o
WARNING: modpost: missing MODULE_DESCRIPTION() in samples/kprobes/kretprobe_example.o
>> ERROR: modpost: "ietf_dscp_to_ieee8021q_tt" [drivers/net/dsa/microchip/ksz_switch.ko] undefined!
>> ERROR: modpost: "ieee8021q_tt_to_tc" [drivers/net/dsa/microchip/ksz_switch.ko] undefined!

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH net-next v1 5/9] net: dsa: microchip: add support for different DCB app configurations
  2024-03-29  9:29   ` Naveen Mamindlapalli
@ 2024-03-30 14:55     ` Andrew Lunn
  0 siblings, 0 replies; 19+ messages in thread
From: Andrew Lunn @ 2024-03-30 14:55 UTC (permalink / raw)
  To: Naveen Mamindlapalli
  Cc: Oleksij Rempel, David S. Miller, Eric Dumazet, Florian Fainelli,
	Jakub Kicinski, Paolo Abeni, Vladimir Oltean, Woojung Huh,
	Arun Ramadoss, kernel, linux-kernel, netdev, UNGLinuxDriver,
	David Ahern, Simon Horman, Willem de Bruijn, Søren Andersen

On Fri, Mar 29, 2024 at 09:29:32AM +0000, Naveen Mamindlapalli wrote:
> 
> > +int ksz_init_global_dscp_map(struct ksz_device *dev) {
> > +	int reg, per_reg, ret, dscp;
> > +	u8 data = 0;
> > +	u8 mask;
> > +
> > +	/* On KSZ9xxx variants, DSCP remapping is disabled by default.
> > +	 * Enable to have, predictable and reproducible behavior across
> > +	 * different devices.
> > +	 */
> > +	if (!is_ksz8(dev)) {
> > +		ret = ksz_rmw8(dev, KSZ9477_REG_SW_MAC_TOS_CTRL,
> > +			       KSZ9477_SW_TOS_DSCP_REMAP,
> > +			       KSZ9477_SW_TOS_DSCP_REMAP);
> > +		if (ret)
> > +			return ret;
> > +	}
> > +
> > +	ksz_get_dscp_prio_reg(dev, &reg, &per_reg, &mask);
> > +
> > +	for (dscp = 0; dscp < DSCP_MAX; dscp++) {
> > +		int ipv, shift;
> > +
> > +		/* Map DSCP to Traffic Type, which is corresponding to the
> > +		 * Internal Priority Value (IPV) in the switch.
> > +		 */
> > +		if (!is_ksz8(dev)) {
> > +			ipv = ietf_dscp_to_ieee8021q_tt(dscp);
> > +		} else {
> > +			ipv =
> > ieee8021q_tt_to_tc(ietf_dscp_to_ieee8021q_tt(dscp),
> > +						 dev->info->num_tx_queues);
> > +		}
> 
> No need for braces for single statement.

Please trim the email when replying. It is very easy to miss comments
when it is 99% quoted text with a couple of one-liners mixed in.

     Andrew

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH net-next v1 7/9] net: dsa: microchip: enable ETS support for KSZ989X variants
  2024-03-28 16:05 ` [PATCH net-next v1 7/9] net: dsa: microchip: enable ETS support for KSZ989X variants Oleksij Rempel
@ 2024-04-02  3:38   ` Arun.Ramadoss
  2024-04-02  7:08     ` Oleksij Rempel
  0 siblings, 1 reply; 19+ messages in thread
From: Arun.Ramadoss @ 2024-04-02  3:38 UTC (permalink / raw)
  To: andrew, olteanv, davem, Woojung.Huh, pabeni, o.rempel, edumazet,
	f.fainelli, kuba
  Cc: kernel, dsahern, san, willemb, linux-kernel, netdev, horms,
	UNGLinuxDriver

Hi Oleksij,


On Thu, 2024-03-28 at 17:05 +0100, Oleksij Rempel wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you
> know the content is safe
> 
> I tested ETS support on KSZ9893, so it should work other KSZ989X
> variants too.

You have enabled ETS for KSZ9897, KSZ9896, KSZ9893. There are other
switches similar to KSZ9893,

KSZ9563 - Same as KSZ9893 but with PTP capability
KSZ8563 - Same as KSZ9563 but without gigabit
KSZ9567 - Same as KSZ9897 but with PTP capability
KSZ8567 - Same as KSZ9567 but without gigabit

Do we need enable ETS for those switches also.



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH net-next v1 2/9] net: dsa: microchip: add IPV information support
  2024-03-28 16:05 ` [PATCH net-next v1 2/9] net: dsa: microchip: add IPV information support Oleksij Rempel
@ 2024-04-02  3:57   ` Arun.Ramadoss
  0 siblings, 0 replies; 19+ messages in thread
From: Arun.Ramadoss @ 2024-04-02  3:57 UTC (permalink / raw)
  To: andrew, olteanv, davem, Woojung.Huh, pabeni, o.rempel, edumazet,
	f.fainelli, kuba
  Cc: kernel, dsahern, san, willemb, linux-kernel, netdev, horms,
	UNGLinuxDriver

Hi Oleksij,

On Thu, 2024-03-28 at 17:05 +0100, Oleksij Rempel wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you
> know the content is safe
> 
> Most of Microchip KSZ switches use Internal Priority Value associated
> with every frame. For example, it is possible to map any VLAN PCP or
> DSCP value to IPV and at the end, map IPV to a queue.
> 
> Since amount of IPVs is not equal to amount of queues, add this
> information and make use of it in some functions.

Reviewed the Priority values for different switches.

Acked-by: Arun Ramadoss <arun.ramadoss@microchip.com>

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH net-next v1 8/9] net: dsa: microchip: init predictable IPV to queue mapping for all non KSZ8xxx variants
  2024-03-28 16:05 ` [PATCH net-next v1 8/9] net: dsa: microchip: init predictable IPV to queue mapping for all non KSZ8xxx variants Oleksij Rempel
@ 2024-04-02  4:07   ` Arun.Ramadoss
  2024-04-02  7:09     ` Oleksij Rempel
  0 siblings, 1 reply; 19+ messages in thread
From: Arun.Ramadoss @ 2024-04-02  4:07 UTC (permalink / raw)
  To: andrew, olteanv, davem, Woojung.Huh, pabeni, o.rempel, edumazet,
	f.fainelli, kuba
  Cc: kernel, dsahern, san, willemb, linux-kernel, netdev, horms,
	UNGLinuxDriver

Hi Oleksij,

On Thu, 2024-03-28 at 17:05 +0100, Oleksij Rempel wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you
> know the content is safe
> 
> Init priority to queue mapping in the way as it shown in IEEE 802.1Q
> mapping example.
> 
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> ---
>  drivers/net/dsa/microchip/ksz_common.c | 53 ++++++++++++++--------
> ----
>  1 file changed, 29 insertions(+), 24 deletions(-)
> 
> diff --git a/drivers/net/dsa/microchip/ksz_common.c
> b/drivers/net/dsa/microchip/ksz_common.c
> index 08426f85f7707..78e9610044ea8 100644
> --- a/drivers/net/dsa/microchip/ksz_common.c
> +++ b/drivers/net/dsa/microchip/ksz_common.c
> @@ -24,6 +24,7 @@
>  #include <linux/of_net.h>
>  #include <linux/micrel_phy.h>
>  #include <net/dsa.h>
> +#include <net/ieee8021q.h>
>  #include <net/pkt_cls.h>
>  #include <net/switchdev.h>
> 
> @@ -2692,9 +2693,29 @@ static int ksz_port_mdb_del(struct dsa_switch
> *ds, int port,
>         return dev->dev_ops->mdb_del(dev, port, mdb, db);
>  }
> 
> +static int ksz_set_default_prio_queue_mapping(struct ksz_device
> *dev, int port)

Since this function is related to KSZ9477 series switch, do we need to
move this function out of ksz_common.c or function name prefixed with
ksz9477_set_default_prio_queue_mapping to differentiate it. 


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH net-next v1 7/9] net: dsa: microchip: enable ETS support for KSZ989X variants
  2024-04-02  3:38   ` Arun.Ramadoss
@ 2024-04-02  7:08     ` Oleksij Rempel
  0 siblings, 0 replies; 19+ messages in thread
From: Oleksij Rempel @ 2024-04-02  7:08 UTC (permalink / raw)
  To: Arun.Ramadoss
  Cc: andrew, olteanv, davem, Woojung.Huh, pabeni, edumazet,
	f.fainelli, kuba, kernel, dsahern, san, willemb, linux-kernel,
	netdev, horms, UNGLinuxDriver

Hi Arun,

On Tue, Apr 02, 2024 at 03:38:33AM +0000, Arun.Ramadoss@microchip.com wrote:
> Hi Oleksij,
> 
> 
> On Thu, 2024-03-28 at 17:05 +0100, Oleksij Rempel wrote:
> > EXTERNAL EMAIL: Do not click links or open attachments unless you
> > know the content is safe
> > 
> > I tested ETS support on KSZ9893, so it should work other KSZ989X
> > variants too.
> 
> You have enabled ETS for KSZ9897, KSZ9896, KSZ9893. There are other
> switches similar to KSZ9893,
> 
> KSZ9563 - Same as KSZ9893 but with PTP capability
> KSZ8563 - Same as KSZ9563 but without gigabit
> KSZ9567 - Same as KSZ9897 but with PTP capability
> KSZ8567 - Same as KSZ9567 but without gigabit
> 
> Do we need enable ETS for those switches also.

No, this variants are already enabled.

Regards,
Oleksij
-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH net-next v1 8/9] net: dsa: microchip: init predictable IPV to queue mapping for all non KSZ8xxx variants
  2024-04-02  4:07   ` Arun.Ramadoss
@ 2024-04-02  7:09     ` Oleksij Rempel
  0 siblings, 0 replies; 19+ messages in thread
From: Oleksij Rempel @ 2024-04-02  7:09 UTC (permalink / raw)
  To: Arun.Ramadoss
  Cc: andrew, olteanv, davem, Woojung.Huh, pabeni, edumazet,
	f.fainelli, kuba, kernel, dsahern, san, willemb, linux-kernel,
	netdev, horms, UNGLinuxDriver

Hi Arun,

On Tue, Apr 02, 2024 at 04:07:30AM +0000, Arun.Ramadoss@microchip.com wrote:
> Hi Oleksij,
> 
> On Thu, 2024-03-28 at 17:05 +0100, Oleksij Rempel wrote:
> > EXTERNAL EMAIL: Do not click links or open attachments unless you
> > know the content is safe
> > 
> > Init priority to queue mapping in the way as it shown in IEEE 802.1Q
> > mapping example.
> > 
> > Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> > ---
> >  drivers/net/dsa/microchip/ksz_common.c | 53 ++++++++++++++--------
> > ----
> >  1 file changed, 29 insertions(+), 24 deletions(-)
> > 
> > diff --git a/drivers/net/dsa/microchip/ksz_common.c
> > b/drivers/net/dsa/microchip/ksz_common.c
> > index 08426f85f7707..78e9610044ea8 100644
> > --- a/drivers/net/dsa/microchip/ksz_common.c
> > +++ b/drivers/net/dsa/microchip/ksz_common.c
> > @@ -24,6 +24,7 @@
> >  #include <linux/of_net.h>
> >  #include <linux/micrel_phy.h>
> >  #include <net/dsa.h>
> > +#include <net/ieee8021q.h>
> >  #include <net/pkt_cls.h>
> >  #include <net/switchdev.h>
> > 
> > @@ -2692,9 +2693,29 @@ static int ksz_port_mdb_del(struct dsa_switch
> > *ds, int port,
> >         return dev->dev_ops->mdb_del(dev, port, mdb, db);
> >  }
> > 
> > +static int ksz_set_default_prio_queue_mapping(struct ksz_device
> > *dev, int port)
> 
> Since this function is related to KSZ9477 series switch, do we need to
> move this function out of ksz_common.c or function name prefixed with
> ksz9477_set_default_prio_queue_mapping to differentiate it. 

Ack. Sounds good, will update it.

Regards,
Oleksij
-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2024-04-02  7:09 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-28 16:05 [PATCH net-next v1 0/9] Enhanced DCB and DSCP Support for KSZ Switches Oleksij Rempel
2024-03-28 16:05 ` [PATCH net-next v1 1/9] net: dsa: add support for DCB get/set apptrust configuration Oleksij Rempel
2024-03-28 16:05 ` [PATCH net-next v1 2/9] net: dsa: microchip: add IPV information support Oleksij Rempel
2024-04-02  3:57   ` Arun.Ramadoss
2024-03-28 16:05 ` [PATCH net-next v1 3/9] net: add IEEE 802.1q specific helpers Oleksij Rempel
2024-03-28 16:05 ` [PATCH net-next v1 4/9] net: dsa: microchip: add multi queue support for KSZ88X3 variants Oleksij Rempel
2024-03-28 16:05 ` [PATCH net-next v1 5/9] net: dsa: microchip: add support for different DCB app configurations Oleksij Rempel
2024-03-29  9:29   ` Naveen Mamindlapalli
2024-03-30 14:55     ` Andrew Lunn
2024-03-29  9:33   ` kernel test robot
2024-03-30  2:55   ` kernel test robot
2024-03-28 16:05 ` [PATCH net-next v1 6/9] net: dsa: microchip: dcb: add special handling for KSZ88X3 family Oleksij Rempel
2024-03-28 16:05 ` [PATCH net-next v1 7/9] net: dsa: microchip: enable ETS support for KSZ989X variants Oleksij Rempel
2024-04-02  3:38   ` Arun.Ramadoss
2024-04-02  7:08     ` Oleksij Rempel
2024-03-28 16:05 ` [PATCH net-next v1 8/9] net: dsa: microchip: init predictable IPV to queue mapping for all non KSZ8xxx variants Oleksij Rempel
2024-04-02  4:07   ` Arun.Ramadoss
2024-04-02  7:09     ` Oleksij Rempel
2024-03-28 16:05 ` [PATCH net-next v1 9/9] net: dsa: microchip: let DCB code do PCP and DSCP policy configuration Oleksij Rempel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.