From 217cdce3822eb68343807b80a3bc3c9b1530f9bb Mon Sep 17 00:00:00 2001
From: Junxian Huang <huangjunxian6@hisilicon.com>
Date: Sat, 22 Jun 2024 16:23:52 +0800
Subject: [PATCH 02/27] hikptool/roce: Support exposing names of extend
 registers

Add support for exposing names of extend registers through the common
frame. To use this feature, the new-added input param reg_name should
be set inside the get_data() callback of each sub modules. For now only
mdb and qmm are supported.

Signed-off-by: Junxian Huang <huangjunxian6@hisilicon.com>
---
 net/roce/roce_bond/hikp_roce_bond.c           |  3 +-
 net/roce/roce_caep/hikp_roce_caep.c           |  5 +-
 .../roce_ext_common/hikp_roce_ext_common.c    | 43 ++++++++------
 .../roce_ext_common/hikp_roce_ext_common.h    | 14 ++++-
 .../roce_global_cfg/hikp_roce_global_cfg.c    |  3 +-
 net/roce/roce_mdb/hikp_roce_mdb.c             | 20 ++++++-
 net/roce/roce_qmm/hikp_roce_qmm.c             | 57 ++++++++++++++++++-
 net/roce/roce_rst/hikp_roce_rst.c             |  3 +-
 8 files changed, 121 insertions(+), 27 deletions(-)

diff --git a/net/roce/roce_bond/hikp_roce_bond.c b/net/roce/roce_bond/hikp_roce_bond.c
index 89f8bab..8434a0b 100644
--- a/net/roce/roce_bond/hikp_roce_bond.c
+++ b/net/roce/roce_bond/hikp_roce_bond.c
@@ -37,7 +37,8 @@ static int hikp_roce_bond_target(struct major_cmd_ctrl *self, const char *argv)
 }
 
 static int hikp_roce_bond_get_data(struct hikp_cmd_ret **cmd_ret,
-				   uint32_t block_id)
+				   uint32_t block_id,
+				   struct roce_ext_reg_name *reg_name)
 {
 	struct hikp_cmd_header req_header = { 0 };
 	struct roce_bond_req_param req_data;
diff --git a/net/roce/roce_caep/hikp_roce_caep.c b/net/roce/roce_caep/hikp_roce_caep.c
index 126551a..0453bc4 100644
--- a/net/roce/roce_caep/hikp_roce_caep.c
+++ b/net/roce/roce_caep/hikp_roce_caep.c
@@ -40,7 +40,8 @@ static int hikp_roce_caep_target(struct major_cmd_ctrl *self, const char *argv)
 }
 
 static int hikp_roce_caep_get_data(struct hikp_cmd_ret **cmd_ret,
-				   uint32_t block_id)
+				   uint32_t block_id,
+				   struct roce_ext_reg_name *reg_name)
 {
 	struct roce_caep_req_param_ext req_data_ext;
 	struct hikp_cmd_header req_header = { 0 };
@@ -80,7 +81,7 @@ static void hikp_roce_caep_execute_origin(struct major_cmd_ctrl *self)
 	struct roce_caep_res_param *roce_caep_res;
 	struct hikp_cmd_ret *cmd_ret;
 
-	self->err_no = hikp_roce_caep_get_data(&cmd_ret, 0);
+	self->err_no = hikp_roce_caep_get_data(&cmd_ret, 0, NULL);
 	if (self->err_no) {
 		printf("hikptool roce_caep get data failed.\n");
 		goto exec_error;
diff --git a/net/roce/roce_ext_common/hikp_roce_ext_common.c b/net/roce/roce_ext_common/hikp_roce_ext_common.c
index 5bc3ce6..c22303f 100644
--- a/net/roce/roce_ext_common/hikp_roce_ext_common.c
+++ b/net/roce/roce_ext_common/hikp_roce_ext_common.c
@@ -89,14 +89,17 @@ static int get_cmd_reg_array_length(enum roce_cmd_type cmd_type)
 
 static int hikp_roce_ext_get_res(enum roce_cmd_type cmd_type,
 				 uint32_t block_id,
-				 struct roce_ext_head *res_head,
-				 struct reg_data *reg,
+				 struct roce_ext_res_output *output,
 				 int (*get_data)(struct hikp_cmd_ret **cmd_ret,
-						 uint32_t block_id))
+						 uint32_t block_id,
+						 struct roce_ext_reg_name *reg_name))
 {
 	int reg_array_length = get_cmd_reg_array_length(cmd_type);
+	struct roce_ext_reg_name *reg_name = &output->reg_name;
+	struct roce_ext_head *res_head = &output->res_head;
 	const char *cmd_name = get_cmd_name(cmd_type);
 	struct roce_ext_res_param *roce_ext_res;
+	struct reg_data *reg = &output->reg;
 	struct hikp_cmd_ret *cmd_ret;
 	size_t max_size;
 	size_t cur_size;
@@ -108,7 +111,7 @@ static int hikp_roce_ext_get_res(enum roce_cmd_type cmd_type,
 	if (reg_array_length < 0)
 		return reg_array_length;
 
-	ret = get_data(&cmd_ret, block_id);
+	ret = get_data(&cmd_ret, block_id, reg_name);
 	if (ret) {
 		printf("hikptool roce_%s get data failed!\n", cmd_name);
 		goto get_data_error;
@@ -149,37 +152,45 @@ get_data_error:
 	return ret;
 }
 
-static void hikp_roce_ext_print(const char *cmd_name, uint32_t total_block_num,
-				const uint32_t *offset, const uint32_t *data)
+static void hikp_roce_ext_print(enum roce_cmd_type cmd_type,
+				struct roce_ext_res_output *output)
 {
+	uint32_t total_block_num = output->res_head.total_block_num;
+	const char **reg_name = output->reg_name.reg_name;
+	const char *cmd_name = get_cmd_name(cmd_type);
+	uint8_t arr_len = output->reg_name.arr_len;
+	uint32_t *offset = output->reg.offset;
+	uint32_t *data = output->reg.data;
 	int i;
 
 	printf("**************%s INFO*************\n", cmd_name);
+	printf("%-40s[addr_offset] : reg_data\n", "reg_name");
 	for (i = 0; i < total_block_num; i++)
-		printf("[0x%08X] : 0x%08X\n", offset[i], data[i]);
+		printf("%-40s[0x%08X] : 0x%08X\n",
+		       i < arr_len ? reg_name[i] : "",
+		       offset[i], data[i]);
 	printf("************************************\n");
 }
 
 void hikp_roce_ext_execute(struct major_cmd_ctrl *self,
 			   enum roce_cmd_type cmd_type,
 			   int (*get_data)(struct hikp_cmd_ret **cmd_ret,
-					   uint32_t block_id))
+					   uint32_t block_id,
+					   struct roce_ext_reg_name *reg_name))
 {
+	struct roce_ext_res_output output = { 0 };
 	uint32_t queried_block_id = 0;
-	struct roce_ext_head res_head;
-	struct reg_data reg = { 0 };
 
 	do {
 		self->err_no = hikp_roce_ext_get_res(cmd_type, queried_block_id,
-						     &res_head, &reg, get_data);
+						     &output, get_data);
 		if (self->err_no)
 			return;
 
-		queried_block_id += res_head.cur_block_num;
-	} while (queried_block_id < res_head.total_block_num);
+		queried_block_id += output.res_head.cur_block_num;
+	} while (queried_block_id < output.res_head.total_block_num);
 
-	hikp_roce_ext_print(get_cmd_name(cmd_type), res_head.total_block_num,
-			    reg.offset, reg.data);
+	hikp_roce_ext_print(cmd_type, &output);
 
-	hikp_roce_ext_reg_data_free(&reg);
+	hikp_roce_ext_reg_data_free(&output.reg);
 }
diff --git a/net/roce/roce_ext_common/hikp_roce_ext_common.h b/net/roce/roce_ext_common/hikp_roce_ext_common.h
index a600449..4930bed 100644
--- a/net/roce/roce_ext_common/hikp_roce_ext_common.h
+++ b/net/roce/roce_ext_common/hikp_roce_ext_common.h
@@ -47,9 +47,21 @@ struct reg_data {
 	uint32_t *data;
 };
 
+struct roce_ext_reg_name {
+	const char **reg_name;
+	uint8_t arr_len;
+};
+
+struct roce_ext_res_output {
+	struct roce_ext_head res_head;
+	struct reg_data reg;
+	struct roce_ext_reg_name reg_name;
+};
+
 void hikp_roce_ext_execute(struct major_cmd_ctrl *self,
 			   enum roce_cmd_type cmd_type,
 			   int (*get_data)(struct hikp_cmd_ret **cmd_ret,
-					   uint32_t block_id));
+					   uint32_t block_id,
+					   struct roce_ext_reg_name *reg_name));
 
 #endif /* __HIKP_ROCE_EXT_COMMON_H__ */
diff --git a/net/roce/roce_global_cfg/hikp_roce_global_cfg.c b/net/roce/roce_global_cfg/hikp_roce_global_cfg.c
index 49a4a2c..18df065 100644
--- a/net/roce/roce_global_cfg/hikp_roce_global_cfg.c
+++ b/net/roce/roce_global_cfg/hikp_roce_global_cfg.c
@@ -40,7 +40,8 @@ static int hikp_roce_global_cfg_target(struct major_cmd_ctrl *self,
 }
 
 static int hikp_roce_global_cfg_get_data(struct hikp_cmd_ret **cmd_ret,
-					 uint32_t block_id)
+					 uint32_t block_id,
+					 struct roce_ext_reg_name *reg_name)
 {
 	struct hikp_cmd_header req_header = { 0 };
 	struct roce_global_cfg_req_param req_data;
diff --git a/net/roce/roce_mdb/hikp_roce_mdb.c b/net/roce/roce_mdb/hikp_roce_mdb.c
index b2b2c41..e811bec 100644
--- a/net/roce/roce_mdb/hikp_roce_mdb.c
+++ b/net/roce/roce_mdb/hikp_roce_mdb.c
@@ -74,6 +74,16 @@ static const char *g_mdb_reg_name[] = {
 	"MDB_STA_5",
 };
 
+static const char *g_mdb_ext_reg_name[] = {
+	"ROCEE_EQDB_EXEC_CNT",
+	"MDB_STA_6",
+	"MDB_DFX_CNT_0",
+	"MDB_DFX_CNT_1",
+	"MDB_DFX_CNT_2",
+	"MDB_DFX_CNT_3",
+	"MDB_DFX_CNT_4",
+};
+
 static void hikp_roce_mdb_print(uint32_t reg_num, struct roce_mdb_rsp_data *mdb_rsp)
 {
 	uint8_t arr_len = HIKP_ARRAY_SIZE(g_mdb_reg_name);
@@ -89,13 +99,19 @@ static void hikp_roce_mdb_print(uint32_t reg_num, struct roce_mdb_rsp_data *mdb_
 }
 
 static int hikp_roce_mdb_get_data(struct hikp_cmd_ret **cmd_ret,
-				  uint32_t block_id)
+				  uint32_t block_id,
+				  struct roce_ext_reg_name *reg_name)
 {
 	struct roce_mdb_req_param_ext req_data_ext;
 	struct hikp_cmd_header req_header = { 0 };
 	uint32_t req_size;
 	int ret;
 
+	if (reg_name) {
+		reg_name->reg_name = g_mdb_ext_reg_name;
+		reg_name->arr_len = HIKP_ARRAY_SIZE(g_mdb_ext_reg_name);
+	}
+
 	req_data_ext.origin_param.bdf = g_roce_mdb_param.target.bdf;
 	req_data_ext.block_id = block_id;
 
@@ -119,7 +135,7 @@ static void hikp_roce_mdb_execute_origin(struct major_cmd_ctrl *self)
 	struct hikp_cmd_ret *cmd_ret = NULL;
 	uint32_t reg_num;
 
-	self->err_no = hikp_roce_mdb_get_data(&cmd_ret, 0);
+	self->err_no = hikp_roce_mdb_get_data(&cmd_ret, 0, NULL);
 	if (self->err_no) {
 		printf("hikptool roce_mdb get data failed\n");
 		goto exec_error;
diff --git a/net/roce/roce_qmm/hikp_roce_qmm.c b/net/roce/roce_qmm/hikp_roce_qmm.c
index fa4e18a..9189f88 100644
--- a/net/roce/roce_qmm/hikp_roce_qmm.c
+++ b/net/roce/roce_qmm/hikp_roce_qmm.c
@@ -104,6 +104,40 @@ static const char *g_qmm_qpc_reg_name[] = {
 	"QPC_WQE_ECC_ERR",
 };
 
+static const char *g_qmm_top_ext_reg_name[] = {
+	"ROCEE_QMM_SRQC_CACHE_RO",
+	"ROCEE_QMM_SRQC_DMAE_RO",
+	"ROCEE_QMM_SRQC_SRH_DFX",
+	"ROCEE_QMM_SRQC_SRH_REQ_RO",
+	"ROCEE_QMM_SRQC_RW_REQ_RO",
+	"ROCEE_QMM_MPT_CACHE_RO",
+	"ROCEE_QMM_MPT_DMAE_RO",
+	"ROCEE_QMM_MPT_SRH_DFX",
+	"ROCEE_QMM_MPT_SRH_REQ_RO",
+	"QPC_DMAE_INTF_RO",
+};
+
+static const char *g_qmm_cqc_ext_reg_name[] = {
+	"ROCEE_CQC_SRH_DFX_BK0",
+	"ROCEE_CQC_SRH_DFX_BK1",
+	"ROCEE_CQC_EMPTY_RD",
+	"ROCEE_CQC_FULL_WR",
+	"ROCEE_CQC_CACHE_RO_BK0",
+	"ROCEE_CQC_CACHE_RO_BK1",
+	"ROCEE_CQC_DMAE_RO",
+};
+
+static const char *g_qmm_qpc_ext_reg_name[] = {
+	"ROCEE_QPC_SRH_DFX_0",
+	"ROCEE_QPC_SRH_DFX_1",
+	"ROCEE_QPC_SRH_REQ_RO_0",
+	"ROCEE_QPC_SRH_REQ_RO_1",
+	"ROCEE_QMM_QPC_CACHE_RO_0",
+	"ROCEE_QMM_QPC_CACHE_RO_0",
+	"QMM_WQE_CACHE_RO",
+	"IRRL_CACHE_RO",
+};
+
 static const struct reg_name_info {
 	enum roce_qmm_cmd_type sub_cmd;
 	const char **reg_name;
@@ -112,6 +146,9 @@ static const struct reg_name_info {
 	{QMM_SHOW_CQC, g_qmm_cqc_reg_name, HIKP_ARRAY_SIZE(g_qmm_cqc_reg_name)},
 	{QMM_SHOW_QPC, g_qmm_qpc_reg_name, HIKP_ARRAY_SIZE(g_qmm_qpc_reg_name)},
 	{QMM_SHOW_TOP, g_qmm_top_reg_name, HIKP_ARRAY_SIZE(g_qmm_top_reg_name)},
+	{QMM_SHOW_CQC_EXT, g_qmm_cqc_ext_reg_name, HIKP_ARRAY_SIZE(g_qmm_cqc_ext_reg_name)},
+	{QMM_SHOW_QPC_EXT, g_qmm_qpc_ext_reg_name, HIKP_ARRAY_SIZE(g_qmm_qpc_ext_reg_name)},
+	{QMM_SHOW_TOP_EXT, g_qmm_top_ext_reg_name, HIKP_ARRAY_SIZE(g_qmm_top_ext_reg_name)},
 };
 
 static void hikp_roce_qmm_print(struct roce_qmm_rsp_data *qmm_rsp)
@@ -149,12 +186,26 @@ static void hikp_roce_qmm_print(struct roce_qmm_rsp_data *qmm_rsp)
 }
 
 static int hikp_roce_qmm_get_data(struct hikp_cmd_ret **cmd_ret,
-				  uint32_t block_id)
+				  uint32_t block_id,
+				  struct roce_ext_reg_name *reg_name)
 {
 	struct roce_qmm_req_para_ext req_data_ext;
 	struct hikp_cmd_header req_header = { 0 };
 	uint32_t req_size;
-	int ret;
+	int ret, i;
+
+	if (reg_name) {
+		for (i = 0; i < HIKP_ARRAY_SIZE(g_qmm_reg_name_info_table); i++) {
+			if (g_qmm_reg_name_info_table[i].sub_cmd != g_roce_qmm_param.sub_cmd)
+				continue;
+			reg_name->arr_len = g_qmm_reg_name_info_table[i].arr_len;
+			reg_name->reg_name = g_qmm_reg_name_info_table[i].reg_name;
+			break;
+		}
+
+		if (i == HIKP_ARRAY_SIZE(g_qmm_reg_name_info_table))
+			return -EINVAL;
+	}
 
 	req_data_ext.origin_param.bdf = g_roce_qmm_param.target.bdf;
 	req_data_ext.origin_param.bank_id = g_roce_qmm_param.bank_id;
@@ -179,7 +230,7 @@ static void hikp_roce_qmm_execute_origin(struct major_cmd_ctrl *self)
 	struct roce_qmm_rsp_data *roce_qmm_res;
 	struct hikp_cmd_ret *cmd_ret;
 
-	self->err_no = hikp_roce_qmm_get_data(&cmd_ret, 0);
+	self->err_no = hikp_roce_qmm_get_data(&cmd_ret, 0, NULL);
 	if (self->err_no) {
 		printf("hikptool roce_qmm get data failed.\n");
 		goto exec_error;
diff --git a/net/roce/roce_rst/hikp_roce_rst.c b/net/roce/roce_rst/hikp_roce_rst.c
index ad4dd0c..570e7f4 100644
--- a/net/roce/roce_rst/hikp_roce_rst.c
+++ b/net/roce/roce_rst/hikp_roce_rst.c
@@ -37,7 +37,8 @@ static int hikp_roce_rst_target(struct major_cmd_ctrl *self, const char *argv)
 }
 
 static int hikp_roce_rst_get_data(struct hikp_cmd_ret **cmd_ret,
-				  uint32_t block_id)
+				  uint32_t block_id,
+				  struct roce_ext_reg_name *reg_name)
 {
 	struct hikp_cmd_header req_header = { 0 };
 	struct roce_rst_req_param req_data;
-- 
2.45.0.windows.1

