[net-next,v2,1/2] net: dsa: microchip: add ksz_setup_tc_mode() function

Message ID 20230308091237.3483895-2-o.rempel@pengutronix.de
State New
Headers
Series net: dsa: microchip: tc-ets support |

Commit Message

Oleksij Rempel March 8, 2023, 9:12 a.m. UTC
  Add ksz_setup_tc_mode() to make queue scheduling and shaping
configuration more visible.

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

Comments

Simon Horman March 8, 2023, 4:37 p.m. UTC | #1
On Wed, Mar 08, 2023 at 10:12:36AM +0100, Oleksij Rempel wrote:
> Add ksz_setup_tc_mode() to make queue scheduling and shaping
> configuration more visible.
> 
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>

Reviewed-by: Simon Horman <simon.horman@corigine.com>
  
Arun Ramadoss March 10, 2023, 4 a.m. UTC | #2
On Wed, 2023-03-08 at 10:12 +0100, Oleksij Rempel wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you
> know the content is safe
> 
> Add ksz_setup_tc_mode() to make queue scheduling and shaping
> configuration more visible.
> 
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>

Acked-by: Arun Ramadoss <arun.ramadoss@microchip.com
  
Arun Ramadoss March 10, 2023, 4:22 a.m. UTC | #3
On Fri, 2023-03-10 at 04:00 +0000, Arun Ramadoss - I17769 wrote:
> On Wed, 2023-03-08 at 10:12 +0100, Oleksij Rempel wrote:
> > EXTERNAL EMAIL: Do not click links or open attachments unless you
> > know the content is safe
> > 
> > Add ksz_setup_tc_mode() to make queue scheduling and shaping
> > configuration more visible.
> > 
> > Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> 
> Acked-by: Arun Ramadoss <arun.ramadoss@microchip.com
> 

If the ets command is supported only in KSZ9477 series of switch, do we
need to return Not supported for KSZ87xx/KSZ88xx switch similar to tc
cbs implementation. I could infer from the patch set that, all the
register set are for KSZ9477, so invoking the command in
KSZ87xx/KSZ88xx will have undefined behaviour. Correct me if I am
wrong.
  
Oleksij Rempel March 10, 2023, 7:13 a.m. UTC | #4
On Fri, Mar 10, 2023 at 04:22:34AM +0000, Arun.Ramadoss@microchip.com wrote:
> On Fri, 2023-03-10 at 04:00 +0000, Arun Ramadoss - I17769 wrote:
> > On Wed, 2023-03-08 at 10:12 +0100, Oleksij Rempel wrote:
> > > EXTERNAL EMAIL: Do not click links or open attachments unless you
> > > know the content is safe
> > > 
> > > Add ksz_setup_tc_mode() to make queue scheduling and shaping
> > > configuration more visible.
> > > 
> > > Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> > 
> > Acked-by: Arun Ramadoss <arun.ramadoss@microchip.com
> > 
> 
> If the ets command is supported only in KSZ9477 series of switch, do we
> need to return Not supported for KSZ87xx/KSZ88xx switch similar to tc
> cbs implementation. I could infer from the patch set that, all the
> register set are for KSZ9477, so invoking the command in
> KSZ87xx/KSZ88xx will have undefined behaviour. Correct me if I am
> wrong.

Ack. You are correct.

Regards,
Oleksij
  

Patch

diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
index 48e35a1d110e..ae05fe0b0a81 100644
--- a/drivers/net/dsa/microchip/ksz_common.c
+++ b/drivers/net/dsa/microchip/ksz_common.c
@@ -32,10 +32,6 @@ 
 #include "ksz9477.h"
 #include "lan937x.h"
 
-#define KSZ_CBS_ENABLE ((MTI_SCHEDULE_STRICT_PRIO << MTI_SCHEDULE_MODE_S) | \
-			(MTI_SHAPING_SRP << MTI_SHAPING_S))
-#define KSZ_CBS_DISABLE ((MTI_SCHEDULE_WRR << MTI_SCHEDULE_MODE_S) |\
-			 (MTI_SHAPING_OFF << MTI_SHAPING_S))
 #define MIB_COUNTER_NUM 0x20
 
 struct ksz_stats_raw {
@@ -3119,6 +3115,14 @@  static int cinc_cal(s32 idle_slope, s32 send_slope, u32 *bw)
 	return 0;
 }
 
+static int ksz_setup_tc_mode(struct ksz_device *dev, int port, u8 scheduler,
+			     u8 shaper)
+{
+	return ksz_pwrite8(dev, port, REG_PORT_MTI_QUEUE_CTRL_0,
+			   FIELD_PREP(MTI_SCHEDULE_MODE_M, scheduler) |
+			   FIELD_PREP(MTI_SHAPING_M, shaper));
+}
+
 static int ksz_setup_tc_cbs(struct dsa_switch *ds, int port,
 			    struct tc_cbs_qopt_offload *qopt)
 {
@@ -3138,8 +3142,8 @@  static int ksz_setup_tc_cbs(struct dsa_switch *ds, int port,
 		return ret;
 
 	if (!qopt->enable)
-		return ksz_pwrite8(dev, port, REG_PORT_MTI_QUEUE_CTRL_0,
-				   KSZ_CBS_DISABLE);
+		return ksz_setup_tc_mode(dev, port, MTI_SCHEDULE_WRR,
+					 MTI_SHAPING_OFF);
 
 	/* High Credit */
 	ret = ksz_pwrite16(dev, port, REG_PORT_MTI_HI_WATER_MARK,
@@ -3164,8 +3168,8 @@  static int ksz_setup_tc_cbs(struct dsa_switch *ds, int port,
 			return ret;
 	}
 
-	return ksz_pwrite8(dev, port, REG_PORT_MTI_QUEUE_CTRL_0,
-			   KSZ_CBS_ENABLE);
+	return ksz_setup_tc_mode(dev, port, MTI_SCHEDULE_STRICT_PRIO,
+				 MTI_SHAPING_SRP);
 }
 
 static int ksz_setup_tc(struct dsa_switch *ds, int port,
diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h
index 10c732b1cea8..f53834bbe896 100644
--- a/drivers/net/dsa/microchip/ksz_common.h
+++ b/drivers/net/dsa/microchip/ksz_common.h
@@ -662,12 +662,10 @@  static inline int is_lan937x(struct ksz_device *dev)
 
 #define REG_PORT_MTI_QUEUE_CTRL_0	0x0914
 
-#define MTI_SCHEDULE_MODE_M		0x3
-#define MTI_SCHEDULE_MODE_S		6
+#define MTI_SCHEDULE_MODE_M		GENMASK(7, 6)
 #define MTI_SCHEDULE_STRICT_PRIO	0
 #define MTI_SCHEDULE_WRR		2
-#define MTI_SHAPING_M			0x3
-#define MTI_SHAPING_S			4
+#define MTI_SHAPING_M			GENMASK(5, 4)
 #define MTI_SHAPING_OFF			0
 #define MTI_SHAPING_SRP			1
 #define MTI_SHAPING_TIME_AWARE		2