Blob Blame History Raw
From: Nogah Frankel <nogahf@mellanox.com>
Date: Wed, 10 Jan 2018 15:00:02 +0100
Subject: mlxsw: spectrum: qdiscs: Add tclass number to the mlxsw_sp_qdisc
Patch-mainline: v4.16-rc1
Git-commit: d56c89550bd0da43bfe9f91ade469ab3f233c62b
References: bsc#1112374

Tclass number is needed for most of the operations related to the qdisc in
the driver. Create a field for it in the mlxsw_sp_qdisc instead of passing
it to every function as parameter.

Signed-off-by: Nogah Frankel <nogahf@mellanox.com>
Reviewed-by: Yuval Mintz <yuvalm@mellanox.com>
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Acked-by: Thomas Bogendoerfer <tbogendoerfer@suse.de>
---
 drivers/net/ethernet/mellanox/mlxsw/spectrum_qdisc.c |   36 +++++++++----------
 1 file changed, 18 insertions(+), 18 deletions(-)

--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_qdisc.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_qdisc.c
@@ -49,6 +49,7 @@ enum mlxsw_sp_qdisc_type {
 struct mlxsw_sp_qdisc {
 	u32 handle;
 	enum mlxsw_sp_qdisc_type type;
+	u8 tclass_num;
 	union {
 		struct red_stats red;
 	} xstats_base;
@@ -100,9 +101,9 @@ mlxsw_sp_tclass_congestion_disable(struc
 
 static void
 mlxsw_sp_setup_tc_qdisc_red_clean_stats(struct mlxsw_sp_port *mlxsw_sp_port,
-					struct mlxsw_sp_qdisc *mlxsw_sp_qdisc,
-					int tclass_num)
+					struct mlxsw_sp_qdisc *mlxsw_sp_qdisc)
 {
+	u8 tclass_num = mlxsw_sp_qdisc->tclass_num;
 	struct mlxsw_sp_qdisc_stats *stats_base;
 	struct mlxsw_sp_port_xstats *xstats;
 	struct rtnl_link_stats64 *stats;
@@ -126,15 +127,15 @@ mlxsw_sp_setup_tc_qdisc_red_clean_stats(
 
 static int
 mlxsw_sp_qdisc_red_destroy(struct mlxsw_sp_port *mlxsw_sp_port, u32 handle,
-			   struct mlxsw_sp_qdisc *mlxsw_sp_qdisc,
-			   int tclass_num)
+			   struct mlxsw_sp_qdisc *mlxsw_sp_qdisc)
 {
 	int err;
 
 	if (mlxsw_sp_qdisc->handle != handle)
 		return 0;
 
-	err = mlxsw_sp_tclass_congestion_disable(mlxsw_sp_port, tclass_num);
+	err = mlxsw_sp_tclass_congestion_disable(mlxsw_sp_port,
+						 mlxsw_sp_qdisc->tclass_num);
 	mlxsw_sp_qdisc->handle = TC_H_UNSPEC;
 	mlxsw_sp_qdisc->type = MLXSW_SP_QDISC_NO_QDISC;
 
@@ -144,10 +145,10 @@ mlxsw_sp_qdisc_red_destroy(struct mlxsw_
 static int
 mlxsw_sp_qdisc_red_replace(struct mlxsw_sp_port *mlxsw_sp_port, u32 handle,
 			   struct mlxsw_sp_qdisc *mlxsw_sp_qdisc,
-			   int tclass_num,
 			   struct tc_red_qopt_offload_params *p)
 {
 	struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
+	u8 tclass_num = mlxsw_sp_qdisc->tclass_num;
 	u32 min, max;
 	u64 prob;
 	int err = 0;
@@ -184,8 +185,7 @@ mlxsw_sp_qdisc_red_replace(struct mlxsw_
 	mlxsw_sp_qdisc->type = MLXSW_SP_QDISC_RED;
 	if (mlxsw_sp_qdisc->handle != handle)
 		mlxsw_sp_setup_tc_qdisc_red_clean_stats(mlxsw_sp_port,
-							mlxsw_sp_qdisc,
-							tclass_num);
+							mlxsw_sp_qdisc);
 
 	mlxsw_sp_qdisc->handle = handle;
 	return 0;
@@ -194,16 +194,17 @@ err_bad_param:
 	err = -EINVAL;
 err_config:
 	mlxsw_sp_qdisc_red_destroy(mlxsw_sp_port, mlxsw_sp_qdisc->handle,
-				   mlxsw_sp_qdisc, tclass_num);
+				   mlxsw_sp_qdisc);
 	return err;
 }
 
 static int
 mlxsw_sp_qdisc_get_red_xstats(struct mlxsw_sp_port *mlxsw_sp_port, u32 handle,
 			      struct mlxsw_sp_qdisc *mlxsw_sp_qdisc,
-			      int tclass_num, struct red_stats *res)
+			      struct red_stats *res)
 {
 	struct red_stats *xstats_base = &mlxsw_sp_qdisc->xstats_base.red;
+	u8 tclass_num = mlxsw_sp_qdisc->tclass_num;
 	struct mlxsw_sp_port_xstats *xstats;
 	int early_drops, marks, pdrops;
 
@@ -230,10 +231,10 @@ mlxsw_sp_qdisc_get_red_xstats(struct mlx
 static int
 mlxsw_sp_qdisc_get_red_stats(struct mlxsw_sp_port *mlxsw_sp_port, u32 handle,
 			     struct mlxsw_sp_qdisc *mlxsw_sp_qdisc,
-			     int tclass_num,
 			     struct tc_qopt_offload_stats *res)
 {
 	u64 tx_bytes, tx_packets, overlimits, drops;
+	u8 tclass_num = mlxsw_sp_qdisc->tclass_num;
 	struct mlxsw_sp_qdisc_stats *stats_base;
 	struct mlxsw_sp_port_xstats *xstats;
 	struct rtnl_link_stats64 *stats;
@@ -272,29 +273,26 @@ int mlxsw_sp_setup_tc_red(struct mlxsw_s
 			  struct tc_red_qopt_offload *p)
 {
 	struct mlxsw_sp_qdisc *mlxsw_sp_qdisc;
-	int tclass_num;
 
 	if (p->parent != TC_H_ROOT)
 		return -EOPNOTSUPP;
 
 	mlxsw_sp_qdisc = mlxsw_sp_port->root_qdisc;
-	tclass_num = MLXSW_SP_PORT_DEFAULT_TCLASS;
 
 	switch (p->command) {
 	case TC_RED_REPLACE:
 		return mlxsw_sp_qdisc_red_replace(mlxsw_sp_port, p->handle,
-						  mlxsw_sp_qdisc, tclass_num,
-						  &p->set);
+						  mlxsw_sp_qdisc, &p->set);
 	case TC_RED_DESTROY:
 		return mlxsw_sp_qdisc_red_destroy(mlxsw_sp_port, p->handle,
-						  mlxsw_sp_qdisc, tclass_num);
+						  mlxsw_sp_qdisc);
 	case TC_RED_XSTATS:
 		return mlxsw_sp_qdisc_get_red_xstats(mlxsw_sp_port, p->handle,
-						     mlxsw_sp_qdisc, tclass_num,
+						     mlxsw_sp_qdisc,
 						     p->xstats);
 	case TC_RED_STATS:
 		return mlxsw_sp_qdisc_get_red_stats(mlxsw_sp_port, p->handle,
-						    mlxsw_sp_qdisc, tclass_num,
+						    mlxsw_sp_qdisc,
 						    &p->stats);
 	default:
 		return -EOPNOTSUPP;
@@ -308,6 +306,8 @@ int mlxsw_sp_tc_qdisc_init(struct mlxsw_
 	if (!mlxsw_sp_port->root_qdisc)
 		return -ENOMEM;
 
+	mlxsw_sp_port->root_qdisc->tclass_num = MLXSW_SP_PORT_DEFAULT_TCLASS;
+
 	return 0;
 }