diff mbox series

[net-next,v7,11/12] net: dsa: microchip: add support DSCP priority mapping

Message ID 20240503131351.1969097-12-o.rempel@pengutronix.de (mailing list archive)
State Accepted
Commit c2e722657f18272a8b8711e94b29466f253715e6
Delegated to: Netdev Maintainers
Headers show
Series add DCB and DSCP support for KSZ switches | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 926 this patch: 926
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 9 of 9 maintainers
netdev/build_clang success Errors and warnings before: 937 this patch: 937
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 937 this patch: 937
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 112 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-05-08--03-00 (tests: 1005)

Commit Message

Oleksij Rempel May 3, 2024, 1:13 p.m. UTC
Microchip KSZ and LAN variants do not have per port DSCP priority
configuration. Instead there is a global DSCP mapping table.

This patch provides write access to this global DSCP map. In case entry
is "deleted", we map corresponding DSCP entry to a best effort prio,
which is expected to be the default priority for all untagged traffic.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/net/dsa/microchip/ksz_common.c |  3 ++
 drivers/net/dsa/microchip/ksz_dcb.c    | 60 +++++++++++++++++++-------
 drivers/net/dsa/microchip/ksz_dcb.h    |  2 +
 3 files changed, 50 insertions(+), 15 deletions(-)
diff mbox series

Patch

diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
index 695748d33c02a..95622dec2b28a 100644
--- a/drivers/net/dsa/microchip/ksz_common.c
+++ b/drivers/net/dsa/microchip/ksz_common.c
@@ -2360,6 +2360,7 @@  static int ksz_setup(struct dsa_switch *ds)
 	ksz_init_mib_timer(dev);
 
 	ds->configure_vlan_while_not_filtering = false;
+	ds->dscp_prio_mapping_is_global = true;
 
 	if (dev->dev_ops->setup) {
 		ret = dev->dev_ops->setup(ds);
@@ -3990,6 +3991,8 @@  static const struct dsa_switch_ops ksz_switch_ops = {
 	.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_add_dscp_prio	= ksz_port_add_dscp_prio,
+	.port_del_dscp_prio	= ksz_port_del_dscp_prio,
 	.port_get_apptrust	= ksz_port_get_apptrust,
 	.port_set_apptrust	= ksz_port_set_apptrust,
 };
diff --git a/drivers/net/dsa/microchip/ksz_dcb.c b/drivers/net/dsa/microchip/ksz_dcb.c
index 80fb322de8f74..5e520c02afd72 100644
--- a/drivers/net/dsa/microchip/ksz_dcb.c
+++ b/drivers/net/dsa/microchip/ksz_dcb.c
@@ -310,6 +310,19 @@  int ksz_port_get_dscp_prio(struct dsa_switch *ds, int port, u8 dscp)
 	return (data >> shift) & mask;
 }
 
+static int ksz_set_global_dscp_entry(struct ksz_device *dev, u8 dscp, u8 ipv)
+{
+	int reg, per_reg, shift;
+	u8 mask;
+
+	ksz_get_dscp_prio_reg(dev, &reg, &per_reg, &mask);
+
+	shift = (dscp % per_reg) * (8 / per_reg);
+
+	return ksz_rmw8(dev, reg + (dscp / per_reg), mask << shift,
+			ipv << shift);
+}
+
 /**
  * ksz_init_global_dscp_map - Initializes the global DSCP-to-priority mapping
  * @dev: Pointer to the KSZ switch device structure
@@ -321,9 +334,7 @@  int ksz_port_get_dscp_prio(struct dsa_switch *ds, int port, u8 dscp)
  */
 static int ksz_init_global_dscp_map(struct ksz_device *dev)
 {
-	int reg, per_reg, ret, dscp;
-	u8 data = 0;
-	u8 mask;
+	int ret, dscp;
 
 	/* On KSZ9xxx variants, DSCP remapping is disabled by default.
 	 * Enable to have, predictable and reproducible behavior across
@@ -337,10 +348,8 @@  static int ksz_init_global_dscp_map(struct ksz_device *dev)
 			return ret;
 	}
 
-	ksz_get_dscp_prio_reg(dev, &reg, &per_reg, &mask);
-
 	for (dscp = 0; dscp < DSCP_MAX; dscp++) {
-		int ipv, shift, tt;
+		int ipv, tt;
 
 		/* Map DSCP to Traffic Type, which is corresponding to the
 		 * Internal Priority Value (IPV) in the switch.
@@ -362,19 +371,40 @@  static int ksz_init_global_dscp_map(struct ksz_device *dev)
 		if (ipv < 0)
 			return ipv;
 
-		shift = (dscp % per_reg) * (8 / per_reg);
-		data |= (ipv & mask) << shift;
+		ret = ksz_set_global_dscp_entry(dev, dscp, ipv);
+	}
 
-		if (dscp % per_reg == per_reg - 1) {
-			ret = ksz_write8(dev, reg + (dscp / per_reg), data);
-			if (ret)
-				return ret;
+	return 0;
+}
 
-			data = 0;
-		}
+int ksz_port_add_dscp_prio(struct dsa_switch *ds, int port, u8 dscp, u8 prio)
+{
+	struct ksz_device *dev = ds->priv;
+
+	if (prio >= dev->info->num_ipvs)
+		return -ERANGE;
+
+	return ksz_set_global_dscp_entry(dev, dscp, prio);
+}
+
+int ksz_port_del_dscp_prio(struct dsa_switch *ds, int port, u8 dscp, u8 prio)
+{
+	struct ksz_device *dev = ds->priv;
+	int ipv;
+
+	if (ksz_port_get_dscp_prio(ds, port, dscp) != prio)
+		return 0;
+
+	if (is_ksz8(dev)) {
+		ipv = ieee8021q_tt_to_tc(IEEE8021Q_TT_BE,
+					 dev->info->num_tx_queues);
+		if (ipv < 0)
+			return ipv;
+	} else {
+		ipv = IEEE8021Q_TT_BE;
 	}
 
-	return 0;
+	return ksz_set_global_dscp_entry(dev, dscp, ipv);
 }
 
 /**
diff --git a/drivers/net/dsa/microchip/ksz_dcb.h b/drivers/net/dsa/microchip/ksz_dcb.h
index 254c0e7bdafca..e2065223ba90c 100644
--- a/drivers/net/dsa/microchip/ksz_dcb.h
+++ b/drivers/net/dsa/microchip/ksz_dcb.h
@@ -11,6 +11,8 @@ 
 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_add_dscp_prio(struct dsa_switch *ds, int port, u8 dscp, u8 prio);
+int ksz_port_del_dscp_prio(struct dsa_switch *ds, int port, u8 dscp, u8 prio);
 int ksz_port_set_apptrust(struct dsa_switch *ds, int port,
 			  const unsigned char *sel,
 			  int nsel);