hikptool: Modify the review comments to increase the reliability of the code

Synchronize code, Modify the review comments to increase the reliability of the code

Signed-off-by: veega2022 <zhuweijia@huawei.com>
(cherry picked from commit d2a23f9ffed0201385c7864b9cd58312fb395cb6)
This commit is contained in:
zhangyuyang 2024-11-21 20:49:07 +08:00 committed by openeuler-sync-bot
parent 7ab6c5319a
commit 9266dc4f4d
28 changed files with 7819 additions and 1 deletions

View File

@ -0,0 +1,739 @@
From f1664742cfa1cae3872d412b09f0c6865f553711 Mon Sep 17 00:00:00 2001
From: Junxian Huang <huangjunxian6@hisilicon.com>
Date: Sat, 22 Jun 2024 14:01:10 +0800
Subject: [PATCH 01/27] hikptool/roce: Print names of registers for
gmv/mdb/pkt/qmm/scc/timer/trp/tsp
Print names of registers for gmv/mdb/pkt/qmm/scc/timer/trp/tsp to
improve usability.
Signed-off-by: Junxian Huang <huangjunxian6@hisilicon.com>
---
net/roce/roce_gmv/hikp_roce_gmv.c | 18 +++-
net/roce/roce_mdb/hikp_roce_mdb.c | 33 +++++-
net/roce/roce_pkt/hikp_roce_pkt.c | 26 ++++-
net/roce/roce_qmm/hikp_roce_qmm.c | 80 ++++++++++++++-
net/roce/roce_scc/hikp_roce_scc.c | 116 ++++++++++++++++++++-
net/roce/roce_timer/hikp_roce_timer.c | 58 ++++++++++-
net/roce/roce_trp/hikp_roce_trp.c | 140 +++++++++++++++++++++++++-
net/roce/roce_tsp/hikp_roce_tsp.c | 84 +++++++++++++++-
8 files changed, 541 insertions(+), 14 deletions(-)
diff --git a/net/roce/roce_gmv/hikp_roce_gmv.c b/net/roce/roce_gmv/hikp_roce_gmv.c
index 36ba665..bc01ccf 100644
--- a/net/roce/roce_gmv/hikp_roce_gmv.c
+++ b/net/roce/roce_gmv/hikp_roce_gmv.c
@@ -58,14 +58,28 @@ static int hikp_roce_gmv_idxget(struct major_cmd_ctrl *self, const char *argv)
return 0;
}
+/* DON'T change the order of this array or add entries between! */
+static const char *g_gmv_reg_name[] = {
+ "ROCEE_VF_GMV_RO0",
+ "ROCEE_VF_GMV_RO1",
+ "ROCEE_VF_GMV_RO2",
+ "ROCEE_VF_GMV_RO3",
+ "ROCEE_VF_GMV_RO4",
+ "ROCEE_VF_GMV_RO5",
+ "ROCEE_VF_GMV_RO6",
+};
+
static void hikp_roce_gmv_print(uint32_t reg_num, struct roce_gmv_rsp_data *gmv_rsp)
{
+ uint8_t arr_len = HIKP_ARRAY_SIZE(g_gmv_reg_name);
uint32_t i;
printf("*******************GMV INFO****************\n");
- printf("addr_offset : reg_data\n");
+ printf("%-40s[addr_offset] : reg_data\n", "reg_name");
for (i = 0; i < reg_num; i++)
- printf("0x%08X : 0x%08X\n", gmv_rsp->reg_offset[i], gmv_rsp->reg_data[i]);
+ printf("%-40s[0x%08X] : 0x%08X\n",
+ i < arr_len ? g_gmv_reg_name[i] : "",
+ gmv_rsp->reg_offset[i], gmv_rsp->reg_data[i]);
printf("*******************************************\n");
}
diff --git a/net/roce/roce_mdb/hikp_roce_mdb.c b/net/roce/roce_mdb/hikp_roce_mdb.c
index 374f100..b2b2c41 100644
--- a/net/roce/roce_mdb/hikp_roce_mdb.c
+++ b/net/roce/roce_mdb/hikp_roce_mdb.c
@@ -48,14 +48,43 @@ static int hikp_roce_mdb_clear_set(struct major_cmd_ctrl *self, const char *argv
return 0;
}
+/* DON'T change the order of this array or add entries between! */
+static const char *g_mdb_reg_name[] = {
+ "ROCEE_DWQE_WQE_ISSUE_CNT",
+ "ROCEE_DWQE_WQE_EXEC_CNT",
+ "ROCEE_DWQE_WQE_DROP_CNT",
+ "ROCEE_DWQE_SQDB_ISSUE_CNT",
+ "ROCEE_DWQE_SQDB_EXEC_CNT",
+ "ROCEE_MBX_ISSUE_CNT",
+ "ROCEE_MBX_EXEC_CNT",
+ "ROCEE_DB_ISSUE_CNT",
+ "ROCEE_DB_EXEC_CNT",
+ "ROCEE_EQDB_ISSUE_CNT",
+ "MDB_ALM",
+ "ROCEE_MDB_EMPTY",
+ "ROCEE_MDB_FULL",
+ "MDB_STA_0",
+ "MDB_STA_1",
+ "MDB_STA_2",
+ "MDB_MEM_INIT_DONE",
+ "ROCEE_MDB_ECC_ERR",
+ "ROCEE_MDB_ECC_ERR_INFO",
+ "MDB_STA_3",
+ "MDB_STA_4",
+ "MDB_STA_5",
+};
+
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);
uint32_t i;
printf("**************MDB INFO*************\n");
- printf("addr_offset : reg_data\n");
+ printf("%-40s[addr_offset] : reg_data\n", "reg_name");
for (i = 0; i < reg_num; i++)
- printf("0x%08X : 0x%08X\n", mdb_rsp->reg_offset[i], mdb_rsp->reg_data[i]);
+ printf("%-40s[0x%08X] : 0x%08X\n",
+ i < arr_len ? g_mdb_reg_name[i] : "",
+ mdb_rsp->reg_offset[i], mdb_rsp->reg_data[i]);
printf("***********************************\n");
}
diff --git a/net/roce/roce_pkt/hikp_roce_pkt.c b/net/roce/roce_pkt/hikp_roce_pkt.c
index e710e08..74294c6 100644
--- a/net/roce/roce_pkt/hikp_roce_pkt.c
+++ b/net/roce/roce_pkt/hikp_roce_pkt.c
@@ -62,14 +62,38 @@ static int hikp_roce_pkt_get_data(struct hikp_cmd_ret **cmd_ret, struct roce_pkt
return ret;
}
+/* DON'T change the order of this array or add entries between! */
+static const char *g_pkt_reg_name[] = {
+ "ROCEE_RC_PKT_RX_CNT",
+ "ROCEE_UD_PKT_RX_CNT",
+ "ROCEE_XRC_PKT_RX_CNT",
+ "ROCEE_PKT_RX_CNT",
+ "ROCEE_ERR_PKT_RX_CNT",
+ "ROCEE_CNP_PKT_RX_CNT",
+ "TRP_RX_ERR_FLAG",
+ "RX_BUFF_CNT",
+ "ROCEE_RC_PKT_TX_CNT",
+ "ROCEE_UD_PKT_TX_CNT",
+ "ROCEE_XRC_PKT_TX_CNT",
+ "ROCEE_PKT_TX_CNT",
+ "ROCEE_ERR_PKT_TX_CNT",
+ "ROCEE_CNP_PKT_TX_CNT",
+ "TRP_GET_MPT_ERR_PKT_CNT",
+ "TRP_GET_IRRL_ERR_PKT_CNT",
+};
+
static void hikp_roce_pkt_print(uint32_t total_block_num,
const uint32_t *offset, const uint32_t *data)
{
+ uint8_t arr_len = HIKP_ARRAY_SIZE(g_pkt_reg_name);
uint32_t i;
printf("**************PKT INFO*************\n");
+ 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 ? g_pkt_reg_name[i] : "",
+ offset[i], data[i]);
printf("***********************************\n");
}
diff --git a/net/roce/roce_qmm/hikp_roce_qmm.c b/net/roce/roce_qmm/hikp_roce_qmm.c
index e440b82..fa4e18a 100644
--- a/net/roce/roce_qmm/hikp_roce_qmm.c
+++ b/net/roce/roce_qmm/hikp_roce_qmm.c
@@ -58,14 +58,90 @@ static int hikp_roce_qmm_bank_get(struct major_cmd_ctrl *self, const char *argv)
return 0;
}
+/* DON'T change the order of these arrays or add entries between! */
+static const char *g_qmm_top_reg_name[] = {
+ "ROCEE_QMM_SRQC_ALM",
+ "ROCEE_QMM_MPT_ALM",
+ "ROCEE_QMM_ECC_ERR",
+ "QMM_AXI_RESP_ERR",
+ "ROCEE_LPRC_RO",
+ "ROCEE_LPRC_RC",
+ "QMM_LPRC_EMPTY_RD",
+ "QPC_DMAE_EMPTY_RD",
+ "QMM_LPRC_FULL_WR",
+ "QPC_DMAE_FULL_WR",
+ "ROCEE_QMM_QPC_ALM",
+ "ROCEE_QMM_GMV_ALM",
+};
+
+static const char *g_qmm_cqc_reg_name[] = {
+ "ROCEE_CQC_SRH_REQ_RO_BK0",
+ "ROCEE_CQC_SRH_REQ_RO_BK1",
+ "ROCEE_CQC_ECC_ERR",
+ "ROCEE_CQC_RESP_ERR",
+ "CQC_RW_REQ_RO_BK0",
+ "CQC_RW_REQ_RO_BK1",
+ "ROCEE_QMM_CQC_ALM",
+};
+
+static const char *g_qmm_qpc_reg_name[] = {
+ "QMM_QPC_SRH_CNT_0",
+ "QMM_QPC_SRH_CNT_1",
+ "ROCEE_QPC_EMPTY_RD",
+ "ROCEE_QPC_FULL_WR",
+ "ROCEE_QPC_SRH_REQ_RO_0",
+ "ROCEE_QPC_SRH_REQ_RO_1",
+ "QMM_QPC_CLR_CNT0_0",
+ "QMM_QPC_CLR_CNT1_0",
+ "QMM_QPC_CLR_CNT2_0",
+ "QMM_QPC_CLR_CNT3_0",
+ "QMM_QPC_CLR_CNT0_1",
+ "QMM_QPC_CLR_CNT1_1",
+ "QMM_QPC_CLR_CNT2_1",
+ "QMM_QPC_CLR_CNT3_1",
+ "QPC_RW_REQ_RO_0",
+ "QPC_RW_REQ_RO_1",
+ "QPC_WQE_ECC_ERR",
+};
+
+static const struct reg_name_info {
+ enum roce_qmm_cmd_type sub_cmd;
+ const char **reg_name;
+ uint8_t arr_len;
+} g_qmm_reg_name_info_table[] = {
+ {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)},
+};
+
static void hikp_roce_qmm_print(struct roce_qmm_rsp_data *qmm_rsp)
{
+ const char **reg_name;
+ uint8_t arr_len;
int index = 0;
+ for (index = 0; index < HIKP_ARRAY_SIZE(g_qmm_reg_name_info_table); index++) {
+ if (g_qmm_reg_name_info_table[index].sub_cmd != g_roce_qmm_param.sub_cmd)
+ continue;
+ arr_len = g_qmm_reg_name_info_table[index].arr_len;
+ reg_name = g_qmm_reg_name_info_table[index].reg_name;
+ break;
+ }
+
+ if (index == HIKP_ARRAY_SIZE(g_qmm_reg_name_info_table)) {
+ printf("can't find reg name table for roce_qmm sub_cmd %u.\n",
+ g_roce_qmm_param.sub_cmd);
+ return;
+ }
+
printf("**************QMM %s INFO*************\n",
g_roce_qmm_param.sub_name);
+ printf("%-40s[addr_offset] : reg_data\n", "reg_name");
+ index = 0;
while (index < qmm_rsp->reg_num) {
- printf("0x%08X : 0x%08X\n", qmm_rsp->qmm_content[index][0],
+ printf("%-40s[0x%08X] : 0x%08X\n",
+ index < arr_len ? reg_name[index] : "",
+ qmm_rsp->qmm_content[index][0],
qmm_rsp->qmm_content[index][1]);
index++;
}
@@ -125,7 +201,7 @@ exec_error:
static void hikp_roce_qmm_execute(struct major_cmd_ctrl *self)
{
- const struct cmd_type_info {
+ static const struct cmd_type_info {
enum roce_qmm_cmd_type sub_cmd;
enum roce_qmm_cmd_type sub_ext_cmd;
const char *sub_name;
diff --git a/net/roce/roce_scc/hikp_roce_scc.c b/net/roce/roce_scc/hikp_roce_scc.c
index fe08873..76c0ca6 100644
--- a/net/roce/roce_scc/hikp_roce_scc.c
+++ b/net/roce/roce_scc/hikp_roce_scc.c
@@ -208,14 +208,128 @@ static int hikp_roce_scc_get_next_data(struct roce_scc_head *res_head,
return 0;
}
+/* DON'T change the order of these arrays or add entries between! */
+static const char *g_scc_common_reg_name[] = {
+ "SCC_MODE_SEL",
+ "SCC_OUTSTANDING_CTRL",
+ "SCC_FW_BASE_ADDR",
+ "SCC_MEM_START_INIT",
+ "SCC_MEM_INIT_DONE",
+ "SCC_FW_REQ_CNT",
+ "SCC_FW_RSP_CNT",
+ "SCC_FW_CNT_CTRL",
+ "SCC_GLB_OUTSTANDING",
+ "SCC_AXI_OUTSTANDING",
+ "SCC_FW_REQRSP_CNT0",
+ "SCC_FW_REQRSP_CNT1",
+ "SCC_OUTSTANDING_ID",
+ "SCC_OUTSTANDING_STS",
+ "SCC_CACHEMISS_LOAD_CNT",
+ "SCC_CACHEMISS_STORE_CNT",
+ "FW_PROCESS_TIME",
+ "SCC_INT_EN",
+ "SCC_INT_SRC",
+ "SCC_ECC_1BIT_CNT",
+ "SCC_ECC_1BIT_INFO",
+ "SCC_ECC_MBIT_INFO",
+ "ECC_ERR_INJ_SEL",
+ "CTX_RDWR_ERR_INFO",
+ "SCC_FW_REQRSP_CNT2",
+ "SCC_LOAD_CAL_CFG_0",
+ "SCC_LOAD_CAL_CFG_1",
+ "SCC_LOAD_CAL_CFG_2",
+ "SCC_LOAD_CAL_CFG_3",
+ "SCC_LOAD_CAL_CFG_4",
+ "SCC_LOAD_CAL_CFG_5",
+ "SCC_LOAD_CAL_CFG_6",
+ "SCC_LOAD_CAL_CFG_7",
+ "SCC_MAX_PROCESS_TIME",
+ "SCC_TIMEOUT_SET",
+ "SCC_TIMEOUT_CNT",
+ "SCC_TIME_STA_EN",
+ "SCC_INPUT_REQ_CNT",
+ "SCC_OUTPUT_RSP_CNT",
+ "SCC_INOUT_CNT_CFG",
+};
+
+static const char *g_scc_dcqcn_reg_name[] = {
+ "SCC_TEMP_CFG0",
+ "SCC_TEMP_CFG1",
+ "SCC_TEMP_CFG2",
+ "SCC_TEMP_CFG3",
+ "ROCEE_CNP_PKT_RX_CNT",
+ "ROCEE_CNP_PKT_TX_CNT",
+ "ROCEE_ECN_DB_CNT0",
+ "ROCEE_ECN_DB_CNT1",
+ "ROCEE_ECN_DB_CNT2",
+ "ROCEE_ECN_DB_CNT3",
+};
+
+static const char *g_scc_dip_reg_name[] = {
+ "SCC_TEMP_CFG0",
+ "SCC_TEMP_CFG1",
+ "SCC_TEMP_CFG2",
+ "SCC_TEMP_CFG3",
+};
+
+static const char *g_scc_hc3_reg_name[] = {
+ "SCC_TEMP_CFG0",
+ "SCC_TEMP_CFG1",
+ "SCC_TEMP_CFG2",
+ "SCC_TEMP_CFG3",
+};
+
+static const char *g_scc_ldcp_reg_name[] = {
+ "SCC_TEMP_CFG0",
+ "SCC_TEMP_CFG1",
+ "SCC_TEMP_CFG2",
+ "SCC_TEMP_CFG3",
+};
+
+static const char *g_scc_cfg_reg_name[] = {
+ "ROCEE_TM_CFG",
+};
+
+static const struct reg_name_info {
+ enum roce_scc_type sub_cmd;
+ const char **reg_name;
+ uint8_t arr_len;
+} g_scc_reg_name_info_table[] = {
+ {COMMON, g_scc_common_reg_name, HIKP_ARRAY_SIZE(g_scc_common_reg_name)},
+ {DCQCN, g_scc_dcqcn_reg_name, HIKP_ARRAY_SIZE(g_scc_dcqcn_reg_name)},
+ {DIP, g_scc_dip_reg_name, HIKP_ARRAY_SIZE(g_scc_dip_reg_name)},
+ {HC3, g_scc_hc3_reg_name, HIKP_ARRAY_SIZE(g_scc_hc3_reg_name)},
+ {LDCP, g_scc_ldcp_reg_name, HIKP_ARRAY_SIZE(g_scc_ldcp_reg_name)},
+ {CFG, g_scc_cfg_reg_name, HIKP_ARRAY_SIZE(g_scc_cfg_reg_name)},
+};
+
static void hikp_roce_scc_print(uint8_t total_block_num,
const uint32_t *offset, const uint32_t *data)
{
+ const char **reg_name;
+ uint8_t arr_len;
uint32_t i;
+ for (i = 0; i < HIKP_ARRAY_SIZE(g_scc_reg_name_info_table); i++) {
+ if (g_scc_reg_name_info_table[i].sub_cmd != g_roce_scc_param_t.sub_cmd)
+ continue;
+ arr_len = g_scc_reg_name_info_table[i].arr_len;
+ reg_name = g_scc_reg_name_info_table[i].reg_name;
+ break;
+ }
+
+ if (i == HIKP_ARRAY_SIZE(g_scc_reg_name_info_table)) {
+ printf("can't find reg name table for roce_scc sub_cmd %u.\n",
+ g_roce_scc_param_t.sub_cmd);
+ return;
+ }
+
printf("**************SCC INFO*************\n");
+ 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");
}
diff --git a/net/roce/roce_timer/hikp_roce_timer.c b/net/roce/roce_timer/hikp_roce_timer.c
index 05ad3e1..a36257e 100644
--- a/net/roce/roce_timer/hikp_roce_timer.c
+++ b/net/roce/roce_timer/hikp_roce_timer.c
@@ -44,12 +44,62 @@ static int hikp_roce_timer_clear_set(struct major_cmd_ctrl *self, const char *ar
return 0;
}
-static void hikp_roce_timer_print(struct roce_timer_rsp_data *timer_rsp)
+/* DON'T change the order of these arrays or add entries between! */
+static const char *g_timer_qpc_reg_name[] = {
+ "QPC_AXI_ERR",
+ "QPC_SEARCH_CNT",
+ "QPC_DB_SEND_CNT",
+ "FIFO_FILL0",
+ "FIFO_FILL1",
+ "FIFO_FILL2",
+ "FIFO_OVER_FLOW",
+ "QPC_START_CNT",
+ "QPC_DB_SEND_NUM_CNT",
+ "ROCEE_TIMER_QPC_ECC_ERR",
+ "ROCEE_TIMER_QPC_ECC_ERR_INFO",
+ "START_TYPE_ERR_CNT",
+};
+
+static const char *g_timer_cqc_reg_name[] = {
+ "TIMER_MEM_INIT_DONE",
+ "CQC_AXI_ERR",
+ "CQC_SEARCH_CNT",
+ "CQC_DB_SEND_CNT",
+ "CQC_FIFO_FILL0",
+ "CQC_FIFO_FILL1",
+ "CQC_FIFO_FILL2",
+ "CQC_START_CNT",
+ "CQC_DB_SEND_NUM_CNT",
+ "FLR_DONE_STATE",
+ "ZERO_ADDR_ACC",
+ "ROCEE_TIMER_CQC_ECC_ERR",
+ "ROCEE_TIMER_CQC_ECC_ERR_INFO",
+ "TIMER_STA_0",
+ "CQC_LOSE_DB_CNT",
+ "TIMER_TDP_DONE_CNT",
+ "CQC_PAGE_OVER_CNT",
+};
+
+static void hikp_roce_timer_print(struct roce_timer_rsp_data *timer_rsp,
+ enum roce_timer_cmd_type cmd_type)
{
+ const char **reg_name;
+ uint8_t arr_len;
int index = 0;
+ if (cmd_type == TIMER_SHOW_QPC) {
+ reg_name = g_timer_qpc_reg_name;
+ arr_len = HIKP_ARRAY_SIZE(g_timer_qpc_reg_name);
+ } else {
+ reg_name = g_timer_cqc_reg_name;
+ arr_len = HIKP_ARRAY_SIZE(g_timer_cqc_reg_name);
+ }
+
+ printf("%-40s[addr_offset] : reg_data\n", "reg_name");
while (index < timer_rsp->reg_num) {
- printf("0x%08X : 0x%08X\n", timer_rsp->timer_content[index][0],
+ printf("%-40s[0x%08X] : 0x%08X\n",
+ index < arr_len ? reg_name[index] : "",
+ timer_rsp->timer_content[index][0],
timer_rsp->timer_content[index][1]);
index++;
}
@@ -83,7 +133,7 @@ static int hikp_roce_timer_show_qpc(struct major_cmd_ctrl *self)
}
printf("**************QPC TIMER INFO*************\n");
- hikp_roce_timer_print(timer_rsp);
+ hikp_roce_timer_print(timer_rsp, TIMER_SHOW_QPC);
out:
free(cmd_ret);
cmd_ret = NULL;
@@ -117,7 +167,7 @@ static int hikp_roce_timer_show_cqc(struct major_cmd_ctrl *self)
}
printf("**************CQC TIMER INFO*************\n");
- hikp_roce_timer_print(timer_rsp);
+ hikp_roce_timer_print(timer_rsp, TIMER_SHOW_CQC);
out:
free(cmd_ret);
cmd_ret = NULL;
diff --git a/net/roce/roce_trp/hikp_roce_trp.c b/net/roce/roce_trp/hikp_roce_trp.c
index fad3317..61f0511 100644
--- a/net/roce/roce_trp/hikp_roce_trp.c
+++ b/net/roce/roce_trp/hikp_roce_trp.c
@@ -231,14 +231,152 @@ static int hikp_roce_trp_get_next_data(struct roce_trp_head *res_head,
return 0;
}
+/* DON'T change the order of these arrays or add entries between! */
+static const char *g_trp_common_reg_name[] = {
+ "GEN_AC_QP_FIFO_FULL",
+ "GEN_AC_QP_FIFO_EMPTY",
+ "GEN_AC_QP_INNER_STA_0",
+ "GEN_AC_QP_INNER_STA_1",
+ "GEN_AC_QP_ALM",
+ "GEN_AC_QP_TSP_CQE_CNT",
+ "TRP_GET_PBL_FULL",
+ "TRP_GET_PBL_EMPTY",
+ "TRP_GET_PBL_INNER_ALM",
+ "TRP_GET_PBL_INNER_STA",
+ "TRP_GET_MPT_FSM",
+ "TRP_GET_MPT_EMPTY",
+ "TRP_GET_MPT_INNER_ALM",
+ "TRP_GET_MPT_INNER_STA",
+ "TRP_GET_SGE_FSM",
+ "TRP_GET_SGE_EMPTY",
+ "TRP_GET_SGE_INNER_ALM",
+ "TRP_GET_SGE_INNER_STA",
+ "TRP_GET_BA_EMPTY",
+ "TRP_GET_BA_INNER_ALM",
+ "TRP_GET_BA_INNER_STA",
+ "TRP_DMAECMD_EMPTY_0",
+ "TRP_DMAECMD_EMPTY_1",
+ "TRP_DMAECMD_FULL",
+ "TRP_GET_IRRL_FSM",
+ "TRP_GET_IRRL_FULL",
+ "TRP_GET_IRRL_EMPTY",
+ "TRP_GET_IRRL_INNER_ALM",
+ "TRP_GET_IRRL_INNER_STA",
+ "TRP_GET_QPC_FSM",
+ "TRP_GET_QPC_INNER_ALM",
+ "TRP_GET_QPC_INNER_STA",
+ "ROCEE_TRP_ECC_ERR_INFO",
+ "ROCEE_TRP_ECC1B",
+ "ROCEE_TRP_ECC2B",
+ "ROCEE_TRP_FUN_RST_DFX",
+ "TRP_GET_MPT_ERR_FLG",
+ "TRP_GET_IRRL_ERR_FLG",
+ "TRP_GET_QPC_ERR_FLG",
+ "ROCEE_ECN_DB_CNT",
+ "GEN_AC_QP_TSP_AE_CNT",
+ "GEN_AC_QP_MDB_CQE_CNT",
+ "GEN_AC_QP_LPRC_CQE_CNT",
+ "TRP_CNP_CNT",
+ "TRP_SGE_ERR_DROP_LEN",
+ "TRP_SGE_AXI_CNT",
+};
+
+static const char *g_trp_trp_rx_reg_name[] = {
+ "TRP_RX_CHECK_EN",
+ "TRP_RX_WR_PAYL_AXI_ERR",
+ "ROCEE_TRP_RX_STA",
+ "RX_FIFO_FULL",
+ "RX_FIFO_EMPTY_0",
+ "RX_FIFO_EMPTY_1",
+ "HEAD_BUFF_ECC",
+ "HEAD_BUFF_ECC_ADDR",
+ "TRP_RX_FIFO_EMPTY_0",
+ "TRP_RX_FIFO_EMPTY_1",
+ "TRP_RX_FIFO_EMPTY_2",
+ "TRP_RX_FIFO_EMPTY_3",
+};
+
+static const char *g_trp_gen_ac_reg_name[] = {
+ "GEN_AC_CQ_FIFO_FULL",
+ "GEN_AC_CQ_FIFO_EMPTY",
+ "GEN_AC_CQ_INNER_STA",
+ "GEN_AC_CQ_ALM",
+ "GEN_AC_CQ_CQE_CNT_0",
+ "GEN_AC_CQ_CQE_CNT_1",
+ "GEN_AC_CQ_CQE_CNT_2",
+ "GEN_AC_CQ_CQE_CNT_3",
+ "ROCEE_GENAC_ECC_ERR_INFO",
+ "ROCEE_GENAC_ECC1B",
+ "ROCEE_GENAC_ECC2B",
+ "GEN_AC_DMAECMD_STA",
+ "GEN_AC_DMAECMD_ALM",
+ "SWQE_LINK_STA",
+ "SWQE_LINK_ALM",
+ "GEN_AC_CQ_MAIN_STA_0",
+ "GEN_AC_CQ_MAIN_ALM",
+ "GEN_AC_CQ_MAIN_STA_1",
+ "POE_DFX_0",
+ "POE_DFX_1",
+ "POE_DFX_2",
+};
+
+static const char *g_trp_payl_reg_name[] = {
+ "ROCEE_EXT_ATOMIC_DFX_0",
+ "ROCEE_EXT_ATOMIC_DFX_1",
+ "ROCEE_EXT_ATOMIC_DFX_2",
+ "ROCEE_EXT_ATOMIC_DFX_3",
+ "ATOMIC_DFX_0",
+ "ATOMIC_DFX_1",
+ "ATOMIC_DFX_2",
+ "WR_PAYL_DFX_1",
+ "PAYL_BUFF_DFX_0",
+ "PAYL_BUFF_DFX_1",
+ "PAYL_BUFF_DFX_2",
+ "PAYL_BUFF_DFX_3",
+ "PAYL_BUFF_DFX_4",
+ "WR_PAYL_DFX_RC",
+ "WR_PAYL_DFX_RO",
+ "WR_PAYL_1_OST_NUM",
+};
+
+static const struct reg_name_info {
+ enum roce_trp_type sub_cmd;
+ const char **reg_name;
+ uint8_t arr_len;
+} g_trp_reg_name_info_table[] = {
+ {COMMON, g_trp_common_reg_name, HIKP_ARRAY_SIZE(g_trp_common_reg_name)},
+ {TRP_RX, g_trp_trp_rx_reg_name, HIKP_ARRAY_SIZE(g_trp_trp_rx_reg_name)},
+ {GEN_AC, g_trp_gen_ac_reg_name, HIKP_ARRAY_SIZE(g_trp_gen_ac_reg_name)},
+ {PAYL, g_trp_payl_reg_name, HIKP_ARRAY_SIZE(g_trp_payl_reg_name)},
+};
+
static void hikp_roce_trp_print(uint8_t total_block_num,
const uint32_t *offset, const uint32_t *data)
{
+ const char **reg_name;
+ uint8_t arr_len;
uint32_t i;
+ for (i = 0; i < HIKP_ARRAY_SIZE(g_trp_reg_name_info_table); i++) {
+ if (g_trp_reg_name_info_table[i].sub_cmd != g_roce_trp_param_t.sub_cmd)
+ continue;
+ arr_len = g_trp_reg_name_info_table[i].arr_len;
+ reg_name = g_trp_reg_name_info_table[i].reg_name;
+ break;
+ }
+
+ if (i == HIKP_ARRAY_SIZE(g_trp_reg_name_info_table)) {
+ printf("can't find reg name table for roce_trp sub_cmd %u.\n",
+ g_roce_trp_param_t.sub_cmd);
+ return;
+ }
+
printf("**************TRP INFO*************\n");
+ 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");
}
diff --git a/net/roce/roce_tsp/hikp_roce_tsp.c b/net/roce/roce_tsp/hikp_roce_tsp.c
index 5bb2649..b16f0a4 100644
--- a/net/roce/roce_tsp/hikp_roce_tsp.c
+++ b/net/roce/roce_tsp/hikp_roce_tsp.c
@@ -137,14 +137,96 @@ static int hikp_roce_tsp_get_data(struct hikp_cmd_ret **cmd_ret,
return ret;
}
+/* DON'T change the order of these arrays or add entries between! */
+static const char *g_tsp_common_reg_name[] = {
+ "ROCEE_TPP_ECC_ERR",
+ "ROCEE_TWP_STA",
+ "ROCEE_TWP_ALM",
+ "ROCEE_TWP_STA1",
+ "TSP_INDRECT_RW_STA",
+ "TSP_INDRECT_RD_CTRL",
+ "TSP_INDRECT_RD_DATA",
+ "ROCEE_TSP_OVF",
+};
+
+static const char *g_tsp_tdp_reg_name[] = {
+ "TDP_M_MEM_INIT_DONE",
+ "TDP_M_ECC1B",
+ "TDP_M_ECC2B",
+ "TDP_M_ECC_ERR_INFO",
+ "TDP_M_ALM",
+ "ROCEE_TDP_CNT_CFG0",
+ "ROCEE_TDP_CNT_CFG1",
+ "ROCEE_TDP_IN_CNT_ENB",
+ "ROCEE_TDP_TWP_CNT0_CFG",
+ "ROCEE_TDP_TWP_CNT1_CFG",
+ "ROCEE_TDP_TRP_CNT",
+ "ROCEE_TDP_MDB_CNT",
+ "ROCEE_TDP_LP_CNT",
+ "ROCEE_TDP_QMM_CNT",
+ "ROCEE_TDP_TWP_CNT0",
+ "ROCEE_TDP_TWP_CNT1",
+ "TDP_V_ECC1B",
+ "TDP_V_ECC2B",
+ "TDP_V_ECC_ERR_INFO",
+ "TDP_V_ALM",
+ "TDP_V_STA",
+ "ROCEE_TSP_OOO_ERR",
+ "TDP_M_STA",
+ "TDP_M_STA1",
+};
+
+static const char *g_tsp_tgp_tmp_reg_name[] = {
+ "ROCEE_TGP_ALM0",
+ "ROCEE_TGP_ALM1",
+ "ROCEE_TGP_STA0",
+ "ROCEE_TGP_STA1",
+ "TGP_INDRECT_RD_CTRL",
+ "TGP_INDRECT_RD_STA",
+ "TGP_INDRECT_RD_DATA",
+ "ROCEE_TMP_ALM0",
+ "ROCEE_TMP_ALM1",
+ "ROCEE_TMP_STA0",
+ "ROCEE_TMP_STA1",
+};
+
+static const struct reg_name_info {
+ enum roce_tsp_sub_cmd_code sub_cmd;
+ const char **reg_name;
+ uint8_t arr_len;
+} g_tsp_reg_name_info_table[] = {
+ {COMMON, g_tsp_common_reg_name, HIKP_ARRAY_SIZE(g_tsp_common_reg_name)},
+ {TDP, g_tsp_tdp_reg_name, HIKP_ARRAY_SIZE(g_tsp_tdp_reg_name)},
+ {TGP_TMP, g_tsp_tgp_tmp_reg_name, HIKP_ARRAY_SIZE(g_tsp_tgp_tmp_reg_name)},
+};
+
static void hikp_roce_tsp_print(uint32_t total_block_num,
const uint32_t *offset, const uint32_t *data)
{
+ const char **reg_name;
+ uint8_t arr_len;
uint32_t i;
+ for (i = 0; i < HIKP_ARRAY_SIZE(g_tsp_reg_name_info_table); i++) {
+ if (g_tsp_reg_name_info_table[i].sub_cmd != g_roce_tsp_param_t.sub_cmd_code)
+ continue;
+ arr_len = g_tsp_reg_name_info_table[i].arr_len;
+ reg_name = g_tsp_reg_name_info_table[i].reg_name;
+ break;
+ }
+
+ if (i == HIKP_ARRAY_SIZE(g_tsp_reg_name_info_table)) {
+ printf("can't find reg name table for roce_tsp sub_cmd %u.\n",
+ g_roce_tsp_param_t.sub_cmd_code);
+ return;
+ }
+
printf("**************TSP INFO*************\n");
+ 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");
}
--
2.45.0.windows.1

View File

@ -0,0 +1,354 @@
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

View File

@ -0,0 +1,70 @@
From a5846b63d1f987242bd33a563c15d91dbdcd8273 Mon Sep 17 00:00:00 2001
From: Junxian Huang <huangjunxian6@hisilicon.com>
Date: Mon, 5 Aug 2024 19:39:12 +0800
Subject: [PATCH 03/27] hikptool/roce: Fix the validation check of
cur_block_num
hikp_roce_ext_get_res() will be called multiple times within a loop,
and each time the remaining space of register array will become less.
So the cur_block_num from FW should be check against remaining block
number, but not the total one.
Fixes: 8b3b68347165 ("hikptool/roce: Add a common frame for hikptool roce register query")
Signed-off-by: Junxian Huang <huangjunxian6@hisilicon.com>
---
net/roce/roce_ext_common/hikp_roce_ext_common.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
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 c22303f..e90720c 100644
--- a/net/roce/roce_ext_common/hikp_roce_ext_common.c
+++ b/net/roce/roce_ext_common/hikp_roce_ext_common.c
@@ -101,7 +101,7 @@ static int hikp_roce_ext_get_res(enum roce_cmd_type 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;
+ uint32_t remain_block;
size_t cur_size;
int ret;
@@ -119,29 +119,30 @@ static int hikp_roce_ext_get_res(enum roce_cmd_type cmd_type,
roce_ext_res = (struct roce_ext_res_param *)cmd_ret->rsp_data;
*res_head = roce_ext_res->head;
- max_size = res_head->total_block_num * sizeof(uint32_t);
if (block_id == 0) {
reg->offset = (uint32_t *)calloc(res_head->total_block_num, sizeof(uint32_t));
reg->data = (uint32_t *)calloc(res_head->total_block_num, sizeof(uint32_t));
if ((reg->offset == NULL) || (reg->data == NULL)) {
printf("hikptool roce_%s alloc log memmory 0x%zx failed!\n",
- cmd_name, max_size);
+ cmd_name, res_head->total_block_num * sizeof(uint32_t));
ret = -ENOMEM;
hikp_roce_ext_reg_data_free(reg);
goto get_data_error;
}
}
- cur_size = res_head->cur_block_num * sizeof(uint32_t);
- if (!cur_size || cur_size > max_size) {
- printf("hikptool roce_%s log data copy size error, data size: 0x%zx, max size: 0x%zx\n",
- cmd_name, cur_size, max_size);
+ remain_block = res_head->total_block_num - block_id;
+ if (!res_head->cur_block_num || res_head->cur_block_num > remain_block) {
+ printf("hikptool roce_%s block size error, cur: %u, total: %u, remain: %u.\n",
+ cmd_name, res_head->cur_block_num,
+ res_head->total_block_num, remain_block);
ret = -EINVAL;
hikp_roce_ext_reg_data_free(reg);
goto get_data_error;
}
+ cur_size = res_head->cur_block_num * sizeof(uint32_t);
memcpy(reg->offset + block_id,
(uint32_t *)&roce_ext_res->reg_data, cur_size);
memcpy(reg->data + block_id,
--
2.45.0.windows.1

View File

@ -0,0 +1,36 @@
From 53a9e2244b16196681e96a1cbaf9e23eef22f56d Mon Sep 17 00:00:00 2001
From: Junxian Huang <huangjunxian6@hisilicon.com>
Date: Mon, 5 Aug 2024 19:47:31 +0800
Subject: [PATCH 04/27] hikptool/roce: Fix redundant update of total_block_num
total_block_num needs to be updated only in the first loop of query,
and should stay constant from then on. Otherwise there may be
out-of-bound accessing problems if subsequent update value from FW
is larger than the first one, with which the memory of the register
array is allocated.
Fixes: 8b3b68347165 ("hikptool/roce: Add a common frame for hikptool roce register query")
Signed-off-by: Junxian Huang <huangjunxian6@hisilicon.com>
---
net/roce/roce_ext_common/hikp_roce_ext_common.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
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 e90720c..049b64a 100644
--- a/net/roce/roce_ext_common/hikp_roce_ext_common.c
+++ b/net/roce/roce_ext_common/hikp_roce_ext_common.c
@@ -118,9 +118,10 @@ static int hikp_roce_ext_get_res(enum roce_cmd_type cmd_type,
}
roce_ext_res = (struct roce_ext_res_param *)cmd_ret->rsp_data;
- *res_head = roce_ext_res->head;
+ res_head->cur_block_num = roce_ext_res->head.cur_block_num;
if (block_id == 0) {
+ res_head->total_block_num = roce_ext_res->head.total_block_num;
reg->offset = (uint32_t *)calloc(res_head->total_block_num, sizeof(uint32_t));
reg->data = (uint32_t *)calloc(res_head->total_block_num, sizeof(uint32_t));
if ((reg->offset == NULL) || (reg->data == NULL)) {
--
2.45.0.windows.1

View File

@ -0,0 +1,70 @@
From 31b9eb2f181ff9275ccbba787a8c1f991a70f69d Mon Sep 17 00:00:00 2001
From: Junxian Huang <huangjunxian6@hisilicon.com>
Date: Mon, 5 Aug 2024 19:59:19 +0800
Subject: [PATCH 05/27] hikptool/roce: Add check for total_block_num from FW
total_block_num is used to allocate memory for register array.
Check whether it is 0 to prevent calloc() error.
Fixes: 8b3b68347165 ("hikptool/roce: Add a common frame for hikptool roce register query")
Signed-off-by: Junxian Huang <huangjunxian6@hisilicon.com>
---
net/roce/roce_ext_common/hikp_roce_ext_common.c | 6 ++++++
net/roce/roce_scc/hikp_roce_scc.c | 6 ++++++
net/roce/roce_trp/hikp_roce_trp.c | 6 ++++++
3 files changed, 18 insertions(+)
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 049b64a..bc3b883 100644
--- a/net/roce/roce_ext_common/hikp_roce_ext_common.c
+++ b/net/roce/roce_ext_common/hikp_roce_ext_common.c
@@ -122,6 +122,12 @@ static int hikp_roce_ext_get_res(enum roce_cmd_type cmd_type,
if (block_id == 0) {
res_head->total_block_num = roce_ext_res->head.total_block_num;
+ if (!res_head->total_block_num) {
+ printf("hikptool roce_%s total_block_num error!\n",
+ cmd_name);
+ ret = -EINVAL;
+ goto get_data_error;
+ }
reg->offset = (uint32_t *)calloc(res_head->total_block_num, sizeof(uint32_t));
reg->data = (uint32_t *)calloc(res_head->total_block_num, sizeof(uint32_t));
if ((reg->offset == NULL) || (reg->data == NULL)) {
diff --git a/net/roce/roce_scc/hikp_roce_scc.c b/net/roce/roce_scc/hikp_roce_scc.c
index 76c0ca6..0ecb8cf 100644
--- a/net/roce/roce_scc/hikp_roce_scc.c
+++ b/net/roce/roce_scc/hikp_roce_scc.c
@@ -146,6 +146,12 @@ static int hikp_roce_scc_get_total_data_num(struct roce_scc_head *res_head,
}
roce_scc_res = (struct roce_scc_res_param *)cmd_ret->rsp_data;
+ if (!roce_scc_res->head.total_block_num) {
+ printf("hikptool roce_scc total_block_num error!\n");
+ ret = -EINVAL;
+ goto get_data_error;
+ }
+
max_size = roce_scc_res->head.total_block_num * sizeof(uint32_t);
*offset = (uint32_t *)calloc(1, max_size);
*data = (uint32_t *)calloc(1, max_size);
diff --git a/net/roce/roce_trp/hikp_roce_trp.c b/net/roce/roce_trp/hikp_roce_trp.c
index 61f0511..486bbe3 100644
--- a/net/roce/roce_trp/hikp_roce_trp.c
+++ b/net/roce/roce_trp/hikp_roce_trp.c
@@ -166,6 +166,12 @@ static int hikp_roce_trp_get_total_data_num(struct roce_trp_head *res_head,
}
roce_trp_res = (struct roce_trp_res_param *)cmd_ret->rsp_data;
+ if (!roce_trp_res->head.total_block_num) {
+ printf("hikptool roce_trp total_block_num error!\n");
+ ret = -EINVAL;
+ goto get_data_error;
+ }
+
max_size = roce_trp_res->head.total_block_num * sizeof(uint32_t);
*offset = (uint32_t *)calloc(1, max_size);
*data = (uint32_t *)calloc(1, max_size);
--
2.45.0.windows.1

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,76 @@
From 0f262056cdc114738a8da3947185a89d10ade581 Mon Sep 17 00:00:00 2001
From: veega2022 <zhuweijia@huawei.com>
Date: Tue, 12 Nov 2024 19:23:50 +0800
Subject: [PATCH 07/27] hikptool: Support static compilation for hikptool
Support static compilation by add the option ENABLE_STATIC,
Please refer to the following usage methods:
```
cmake ${src} -DENABLE_STATIC=1
```
Signed-off-by: Chengchang Tang <tangchengchang@huawei.com>
---
CMakeLists.txt | 14 +++++++++++++-
libhikptdev/src/rciep/CMakeLists.txt | 6 +++++-
2 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index cbd063c..f2ffe6c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -26,6 +26,8 @@ macro(get_header_dir_recurse HEADER_DIR_LIST)
set(${HEADER_DIR_LIST} ${DIR_LIST})
endmacro()
+option(ENABLE_STATIC "Make tool run as independently as possible" off)
+
file(GLOB_RECURSE HIKPTOOL_SRC
${CMAKE_CURRENT_SOURCE_DIR}/cxl/*.c
${CMAKE_CURRENT_SOURCE_DIR}/net/*.c
@@ -38,13 +40,23 @@ file(GLOB_RECURSE HIKPTOOL_SRC
${CMAKE_CURRENT_SOURCE_DIR}/tool_lib/*.c
${CMAKE_CURRENT_SOURCE_DIR}/hikp_init_main.c
)
+
add_subdirectory(libhikptdev)
add_executable(hikptool ${HIKPTOOL_SRC})
get_header_dir_recurse(HIKPTOOL_HEADER_DIR)
target_include_directories(hikptool PRIVATE ${HIKPTOOL_HEADER_DIR})
target_link_directories(hikptool PRIVATE ${CMAKE_INSTALL_PREFIX}/lib)
target_link_libraries(hikptool PRIVATE KPTDEV_SO)
+if (ENABLE_STATIC)
+ # I don¡¯t know why, but once you add double quotes to these
+ # link parameters, an error will be reported.
+ set(EXT_LINK_FLAGS -static-libgcc -static-libstdc++ -static)
+ set_target_properties(hikptool PROPERTIES LINK_SEARCH_START_STATIC ON)
+ set_target_properties(hikptool PROPERTIES LINK_SEARCH_END_STATIC ON)
+else()
+ set(EXT_LINK_FLAGS "-fPIE")
+endif()
target_link_options(hikptool PRIVATE
- -Wl,-z,relro,-z,now -Wl,-z,noexecstack -fPIE -pie
+ -Wl,-z,relro,-z,now -Wl,-z,noexecstack -pie ${EXT_LINK_FLAGS}
-s -lpthread -ldl -lm -lrt -T ${CMAKE_CURRENT_SOURCE_DIR}/hikp_register.ld)
install(TARGETS hikptool RUNTIME DESTINATION bin OPTIONAL)
diff --git a/libhikptdev/src/rciep/CMakeLists.txt b/libhikptdev/src/rciep/CMakeLists.txt
index 5017f5b..e3f96c0 100644
--- a/libhikptdev/src/rciep/CMakeLists.txt
+++ b/libhikptdev/src/rciep/CMakeLists.txt
@@ -13,7 +13,11 @@ cmake_minimum_required(VERSION 3.0.0)
set(KPTDEV_SO_NAME hikptdev)
-add_library(KPTDEV_SO SHARED hikpt_rciep.c)
+if (ENABLE_STATIC)
+ add_library(KPTDEV_SO STATIC hikpt_rciep.c)
+else()
+ add_library(KPTDEV_SO SHARED hikpt_rciep.c)
+endif()
target_include_directories(KPTDEV_SO PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../include)
--
2.45.0.windows.1

View File

@ -0,0 +1,265 @@
From 2994a8d169adc6ba5b543a2f35b579e437044beb Mon Sep 17 00:00:00 2001
From: Jie Hai <haijie1@huawei.com>
Date: Tue, 6 Aug 2024 16:43:24 +0800
Subject: [PATCH 08/27] hikptool/nic: Fix the Code review comments
The value got from the firmware may cause the following problem.
1. Out-of-bounds access may occur.
2. Apply for memory of size 0.
3. Integer overflow may happen.
This patch fixes it.
Signed-off-by: Jie Hai <haijie1@huawei.com>
---
net/nic/nic_ppp/hikp_nic_ppp.c | 142 +++++++++++++++++++++++++++++++--
1 file changed, 137 insertions(+), 5 deletions(-)
diff --git a/net/nic/nic_ppp/hikp_nic_ppp.c b/net/nic/nic_ppp/hikp_nic_ppp.c
index 4dbe8d6..c070666 100644
--- a/net/nic/nic_ppp/hikp_nic_ppp.c
+++ b/net/nic/nic_ppp/hikp_nic_ppp.c
@@ -42,6 +42,8 @@ static int hikp_nic_query_ppp_by_entryid(struct hikp_cmd_header *req_header,
#define NIC_PPP_VLAN_TBL_NAME "vlan"
#define NIC_PPP_MNG_TBL_NAME "mng"
+#define HIKP_PPP_MAX_MAC_ID_NUM 8
+
static const struct ppp_feature_cmd g_ppp_feature_cmd[] = {
{NIC_PPP_MAC_TBL_NAME, NIC_MAC_TBL_DUMP, true,
hikp_nic_query_ppp_by_entryid, hikp_nic_ppp_show_mac_tbl},
@@ -259,6 +261,9 @@ static void hikp_nic_ppp_show_mac_tbl(const void *data)
hikp_nic_ppp_show_key_mem((struct nic_mac_tbl *)data, true);
+ if (g_ppp_hw_res.overflow_cam_size == 0)
+ return;
+
of_uc_entry = (struct mac_vlan_uc_entry *)calloc(g_ppp_hw_res.overflow_cam_size,
sizeof(struct mac_vlan_uc_entry));
if (of_uc_entry == NULL) {
@@ -326,8 +331,9 @@ static void hikp_nic_ppp_show_vf_vlan_info(const struct vf_vlan_tbl *vf_tbl, uin
offset = abs_func_id % HIKP_NIC_PPP_FUNC_BITMAP_SIZE;
hikp_nic_ppp_get_func_name(func_name, sizeof(func_name), func_id);
printf("%s_abs_func_id: %u\n", func_name,
- (uint32_t)(g_ppp_hw_res.abs_func_id_base + func_id - 1));
+ (uint32_t)(hw_res->abs_func_id_base + func_id - 1));
printf("%s VLAN id:\n\t", func_name);
+
for (i = 0; i < vf_tbl->entry_size; i++) {
vf_entry = &vf_tbl->entry[i];
if (hikp_get_bit(vf_entry->func_bitmap[idx], offset) != 0) {
@@ -490,10 +496,11 @@ static int hikp_nic_ppp_get_blk(struct hikp_cmd_header *req_header,
goto out;
rsp = (struct nic_ppp_rsp *)cmd_ret->rsp_data;
- if (rsp->rsp_head.cur_blk_size > buf_len) {
+ if (rsp->rsp_head.cur_blk_size > buf_len ||
+ rsp->rsp_head.cur_blk_size > sizeof(rsp->rsp_data)) {
HIKP_ERROR_PRINT("nic_ppp block context copy size error, "
- "buffer size=%zu, data size=%u.\n",
- buf_len, rsp->rsp_head.cur_blk_size);
+ "dst buffer size=%zu, src buffer size=%zu, data size=%u.\n",
+ buf_len, sizeof(rsp->rsp_data), rsp->rsp_head.cur_blk_size);
ret = -EINVAL;
goto out;
}
@@ -532,6 +539,17 @@ static int hikp_nic_ppp_query_uc_mac_addr(struct hikp_cmd_header *req_header,
idx, ret);
return ret;
}
+ if (rsp_head.next_entry_idx <= idx) {
+ HIKP_ERROR_PRINT("Next entry index (%u) should be greater than current (%u).\n",
+ rsp_head.next_entry_idx, idx);
+ return -EINVAL;
+ }
+ if (entry_size + rsp_head.cur_blk_entry_cnt > max_hw_entry_size) {
+ HIKP_ERROR_PRINT("The sum of entry number (%lu) after block-%u "
+ "is over the maximum entry nubmer (%u) of unicast MAC table.\n",
+ entry_size + rsp_head.cur_blk_entry_cnt, idx, max_hw_entry_size);
+ return -EINVAL;
+ }
entry_size += rsp_head.cur_blk_entry_cnt;
idx = rsp_head.next_entry_idx;
}
@@ -563,6 +581,17 @@ static int hikp_nic_ppp_query_mc_mac_addr(struct hikp_cmd_header *req_header,
idx, ret);
return ret;
}
+ if (rsp_head.next_entry_idx <= idx) {
+ HIKP_ERROR_PRINT("Next entry index (%u) should be greater than current (%u).\n",
+ rsp_head.next_entry_idx, idx);
+ return -EINVAL;
+ }
+ if (entry_size + rsp_head.cur_blk_entry_cnt > max_hw_entry_size) {
+ HIKP_ERROR_PRINT("The sum of entry number (%lu) after block-%u "
+ "is over the maximum entry nubmer (%u) of multicast MAC table.\n",
+ entry_size + rsp_head.cur_blk_entry_cnt, idx, max_hw_entry_size);
+ return -EINVAL;
+ }
entry_size += rsp_head.cur_blk_entry_cnt;
idx = rsp_head.next_entry_idx;
}
@@ -623,6 +652,17 @@ static int hikp_nic_ppp_query_vf_vlan_tbl(struct hikp_cmd_header *req_header,
idx, ret);
return ret;
}
+ if (rsp_head.next_entry_idx <= idx) {
+ HIKP_ERROR_PRINT("Next entry index (%u) should be greater than current (%u).\n",
+ rsp_head.next_entry_idx, idx);
+ return -EINVAL;
+ }
+ if (entry_size + rsp_head.cur_blk_entry_cnt > hw_entry_size) {
+ HIKP_ERROR_PRINT("The sum of entry number (%lu) after block-%u "
+ "is over the maximum entry nubmer (%u) of VF VLAN table.\n",
+ entry_size + rsp_head.cur_blk_entry_cnt, idx, hw_entry_size);
+ return -EINVAL;
+ }
entry_size += rsp_head.cur_blk_entry_cnt;
idx = rsp_head.next_entry_idx;
}
@@ -653,6 +693,17 @@ static int hikp_nic_ppp_query_port_vlan_tbl(struct hikp_cmd_header *req_header,
idx, ret);
return ret;
}
+ if (rsp_head.next_entry_idx <= idx) {
+ HIKP_ERROR_PRINT("Next entry index (%u) should be greater than current (%u).\n",
+ rsp_head.next_entry_idx, idx);
+ return -EINVAL;
+ }
+ if (entry_size + rsp_head.cur_blk_entry_cnt > hw_entry_size) {
+ HIKP_ERROR_PRINT("The sum of entry number (%lu) after block-%u "
+ "is over the maximum entry nubmer (%u) of port VLAN table.\n",
+ entry_size + rsp_head.cur_blk_entry_cnt, idx, hw_entry_size);
+ return -EINVAL;
+ }
entry_size += rsp_head.cur_blk_entry_cnt;
idx = rsp_head.next_entry_idx;
}
@@ -704,6 +755,17 @@ static int hikp_nic_query_mng_tbl(struct hikp_cmd_header *req_header,
idx, ret);
return ret;
}
+ if (rsp_head.next_entry_idx <= idx) {
+ HIKP_ERROR_PRINT("Next entry index (%u) should be greater than current (%u).\n",
+ rsp_head.next_entry_idx, idx);
+ return -EINVAL;
+ }
+ if (entry_size + rsp_head.cur_blk_entry_cnt > g_ppp_hw_res.mng_tbl_size) {
+ HIKP_ERROR_PRINT("The sum of entry number (%lu) after block-%u "
+ "is over the maximum entry nubmer (%u) of manager table.\n",
+ entry_size + rsp_head.cur_blk_entry_cnt, idx, g_ppp_hw_res.mng_tbl_size);
+ return -EINVAL;
+ }
entry_size += rsp_head.cur_blk_entry_cnt;
idx = rsp_head.next_entry_idx;
}
@@ -729,6 +791,24 @@ static int hikp_nic_query_ppp_by_entryid(struct hikp_cmd_header *req_header,
return hikp_nic_query_mng_tbl(req_header, &req_data, (struct nic_mng_tbl *)data);
}
+static int hikp_nic_ppp_check_func_num(void *data)
+{
+ const struct ppp_feature_cmd *ppp_cmd;
+ uint16_t func_num = 0;
+
+ ppp_cmd = &g_ppp_feature_cmd[g_ppp_param.feature_idx];
+ if (ppp_cmd->sub_cmd_code == NIC_PROMISCUOUS_TBL_DUMP)
+ func_num = ((struct nic_promisc_tbl *)data)->func_num;
+ else if (ppp_cmd->sub_cmd_code == NIC_VLAN_OFFLOAD_DUMP)
+ func_num = ((struct nic_vlan_offload_cfg *)data)->func_num;
+
+ if (func_num > HIKP_NIC_MAX_FUNC_NUM) {
+ HIKP_ERROR_PRINT("Illegal function num(%u) from firmware.\n", func_num);
+ return -EINVAL;
+ }
+ return 0;
+}
+
static int hikp_nic_query_ppp_by_blkid(struct hikp_cmd_header *req_header, const struct bdf_t *bdf,
void *data, size_t len)
{
@@ -752,6 +832,10 @@ static int hikp_nic_query_ppp_by_blkid(struct hikp_cmd_header *req_header, const
/* Copy the remaining block content if total block number is greater than 1. */
for (blk_id = 1; blk_id < total_blk_num; blk_id++) {
req_data.block_id = blk_id;
+ if (len <= total_blk_size) {
+ HIKP_ERROR_PRINT("No enough buffer to get block-%u context.\n", blk_id);
+ return -ENOMEM;
+ }
ret = hikp_nic_ppp_get_blk(req_header, &req_data, (uint8_t *)data + total_blk_size,
len - total_blk_size, &rsp_head);
if (ret != 0) {
@@ -761,7 +845,7 @@ static int hikp_nic_query_ppp_by_blkid(struct hikp_cmd_header *req_header, const
total_blk_size += rsp_head.cur_blk_size;
}
- return ret;
+ return hikp_nic_ppp_check_func_num(data);
}
static int hikp_nic_ppp_get_hw_resources(const struct bdf_t *bdf,
@@ -975,6 +1059,46 @@ static int hikp_nic_check_func_id_valid(struct major_cmd_ctrl *self,
return 0;
}
+static int hikp_nic_check_hw_res(struct hikp_nic_ppp_hw_resources *hw_res)
+{
+ if (!g_ppp_feature_cmd[g_ppp_param.feature_idx].need_query_hw_res)
+ return 0;
+
+ if (hw_res->max_key_mem_size == 0) {
+ HIKP_ERROR_PRINT("Max key memory size should not be zero!\n");
+ return -EINVAL;
+ }
+ if (hw_res->port_vlan_tbl_size == 0) {
+ HIKP_ERROR_PRINT("PORT VLAN Table size should not be zero!\n");
+ return -EINVAL;
+ }
+ if (hw_res->vf_vlan_tbl_size == 0) {
+ HIKP_ERROR_PRINT("VF VLAN Table size should not be zero!\n");
+ return -EINVAL;
+ }
+ if (hw_res->mng_tbl_size == 0) {
+ HIKP_ERROR_PRINT("VF VLAN Table size (%uis zero!\n");
+ return -EINVAL;
+ }
+ if (hw_res->mac_id >= HIKP_PPP_MAX_MAC_ID_NUM) {
+ HIKP_ERROR_PRINT("MAC ID (%u) should be less than %u.\n",
+ hw_res->mac_id, HIKP_PPP_MAX_MAC_ID_NUM);
+ return -EINVAL;
+ }
+ if (hw_res->total_func_num == 0 || hw_res->total_func_num > HIKP_NIC_MAX_FUNC_NUM) {
+ HIKP_ERROR_PRINT("Total_func_num (%ushould be in [1, %u].\n",
+ hw_res->total_func_num, HIKP_NIC_MAX_FUNC_NUM);
+ return -EINVAL;
+ }
+ if (hw_res->abs_func_id_base >= HIKP_NIC_MAX_FUNC_NUM) {
+ HIKP_ERROR_PRINT("Function ID base (%u) should be less than %u.\n",
+ hw_res->abs_func_id_base, HIKP_NIC_MAX_FUNC_NUM);
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
static void hikp_nic_ppp_cmd_execute(struct major_cmd_ctrl *self)
{
struct bdf_t *bdf = &g_ppp_param.target.bdf;
@@ -995,6 +1119,14 @@ static void hikp_nic_ppp_cmd_execute(struct major_cmd_ctrl *self)
return;
}
+ ret = hikp_nic_check_hw_res(&g_ppp_hw_res);
+ if (ret != 0) {
+ snprintf(self->err_str, sizeof(self->err_str),
+ "ppp hardware resources obtained is invalid.");
+ self->err_no = ret;
+ return;
+ }
+
ppp_cmd = &g_ppp_feature_cmd[g_ppp_param.feature_idx];
ret = hikp_nic_check_func_id_valid(self, ppp_cmd, &g_ppp_param, &g_ppp_hw_res);
if (ret != 0)
--
2.45.0.windows.1

View File

@ -0,0 +1,172 @@
From a2514156dfd5ec10fa30e72dbc6496e0b8c87846 Mon Sep 17 00:00:00 2001
From: Dengdui Huang <huangdengdui@huawei.com>
Date: Thu, 15 Aug 2024 17:29:32 +0800
Subject: [PATCH 09/27] hikptool/nic: add check for the value from FW
The value obtained from the firmware is unreliable,
and the software needs to verify the validity.
Signed-off-by: Dengdui Huang <huangdengdui@huawei.com>
---
net/nic/nic_fd/hikp_nic_fd.c | 44 +++++++++++++++++++++++++++---
net/nic/nic_qos/hikp_nic_qos.c | 8 ++++--
net/nic/nic_queue/hikp_nic_queue.c | 8 ++++--
net/nic/nic_rss/hikp_nic_rss.c | 8 ++++--
4 files changed, 55 insertions(+), 13 deletions(-)
diff --git a/net/nic/nic_fd/hikp_nic_fd.c b/net/nic/nic_fd/hikp_nic_fd.c
index e699bf9..3d6a9dc 100644
--- a/net/nic/nic_fd/hikp_nic_fd.c
+++ b/net/nic/nic_fd/hikp_nic_fd.c
@@ -550,7 +550,7 @@ static void hikp_nic_show_fd_counter(const void *data)
static int hikp_nic_fd_get_blk(struct hikp_cmd_header *req_header,
const struct nic_fd_req_para *req_data,
- void *buf, uint32_t buf_len, struct nic_fd_rsp_head *rsp_head)
+ void *buf, size_t buf_len, struct nic_fd_rsp_head *rsp_head)
{
struct hikp_cmd_ret *cmd_ret;
struct nic_fd_rsp *rsp;
@@ -563,10 +563,12 @@ static int hikp_nic_fd_get_blk(struct hikp_cmd_header *req_header,
}
rsp = (struct nic_fd_rsp *)cmd_ret->rsp_data;
- if (rsp->rsp_head.cur_blk_size > buf_len) {
+ if (rsp->rsp_head.cur_blk_size > buf_len ||
+ rsp->rsp_head.cur_blk_size > sizeof(rsp->rsp_data)) {
HIKP_ERROR_PRINT("nic_fd block context copy size error, "
- "buffer size=%u, data size=%u.\n",
- buf_len, rsp->rsp_head.cur_blk_size);
+ "dst buffer size=%zu, src buffer size=%zu, "
+ "data size=%u.\n", buf_len, sizeof(rsp->rsp_data),
+ rsp->rsp_head.cur_blk_size);
ret = -EINVAL;
goto out;
}
@@ -657,7 +659,19 @@ static int hikp_nic_query_fd_rules(struct hikp_cmd_header *req_header, const str
idx, ret);
return ret;
}
+ if (rsp_head.cur_blk_entry_cnt + entry_cnt > g_fd_hw_info.alloc.stage_entry_num[stage]) {
+ HIKP_ERROR_PRINT("The sum of entry number (%u) after block-%u "
+ "is over the maximum entry nubmer (%u) of this stage.",
+ rsp_head.cur_blk_entry_cnt + entry_cnt, idx,
+ g_fd_hw_info.alloc.stage_entry_num[stage]);
+ return -EINVAL;
+ }
entry_cnt += rsp_head.cur_blk_entry_cnt;
+ if (rsp_head.next_entry_idx <= idx) {
+ HIKP_ERROR_PRINT("The next entry index (%u) is less than or equal with the curent(%u).\n",
+ rsp_head.next_entry_idx, idx);
+ return -EINVAL;
+ }
idx = rsp_head.next_entry_idx;
if (req_data.query_single_entry == 1)
break;
@@ -702,7 +716,19 @@ static int hikp_nic_query_fd_counter(struct hikp_cmd_header *req_header, const s
idx, ret);
return ret;
}
+ if (rsp_head.cur_blk_entry_cnt + entry_size > g_fd_hw_info.alloc.stage_counter_num[stage]) {
+ HIKP_ERROR_PRINT("The sum of entry number (%u) after block-%u "
+ "is over the maximum counter nubmer (%u) of this stage.",
+ rsp_head.cur_blk_entry_cnt + entry_size, idx,
+ g_fd_hw_info.alloc.stage_counter_num[stage]);
+ return -EINVAL;
+ }
entry_size += rsp_head.cur_blk_entry_cnt;
+ if (rsp_head.next_entry_idx <= idx) {
+ HIKP_ERROR_PRINT("The next entry index (%u) is less than or equal with the curent(%u).\n",
+ rsp_head.next_entry_idx, idx);
+ return -EINVAL;
+ }
idx = rsp_head.next_entry_idx;
if (req_data.query_single_entry == 1)
break;
@@ -808,6 +834,11 @@ static int hikp_nic_check_fd_hw_info(const struct nic_fd_hw_info *hw_info,
uint16_t i;
if (strcmp(fd_cmd->feature_name, NIC_FD_RULES_NAME) == 0) {
+ /* Stage2 does not support query. So only stage1 is verified. */
+ if(hw_info->alloc.stage_entry_num[NIC_FD_STAGE_1] == 0) {
+ HIKP_ERROR_PRINT("The stage1's entry number is zero.\n");
+ return -EINVAL;
+ }
if (hw_info->mode > FD_MODE_DEPTH_2K_WIDTH_200B_STAGE_2)
HIKP_WARN_PRINT("Unknown fd mode(%u), "
"unsupport for displaying meta data info.\n",
@@ -822,6 +853,11 @@ static int hikp_nic_check_fd_hw_info(const struct nic_fd_hw_info *hw_info,
return -EOPNOTSUPP;
}
}
+ } else if (strcmp(fd_cmd->feature_name, NIC_FD_COUNTER_NAME) == 0) {
+ if (hw_info->alloc.stage_counter_num[NIC_FD_STAGE_1] == 0) {
+ HIKP_ERROR_PRINT("The stage1's counter number is zero.\n");
+ return -EINVAL;
+ }
}
return 0;
diff --git a/net/nic/nic_qos/hikp_nic_qos.c b/net/nic/nic_qos/hikp_nic_qos.c
index a09b4f1..9e997e4 100644
--- a/net/nic/nic_qos/hikp_nic_qos.c
+++ b/net/nic/nic_qos/hikp_nic_qos.c
@@ -174,10 +174,12 @@ static int hikp_nic_qos_get_blk(struct hikp_cmd_header *req_header,
}
rsp = (struct nic_qos_rsp *)cmd_ret->rsp_data;
- if (rsp->rsp_head.cur_blk_size > buf_len) {
+ if (rsp->rsp_head.cur_blk_size > buf_len ||
+ rsp->rsp_head.cur_blk_size > sizeof(rsp->rsp_data)) {
HIKP_ERROR_PRINT("nic_qos block-%u copy size error, "
- "buffer size=%zu, data size=%u.\n",
- req_data->block_id, buf_len, rsp->rsp_head.cur_blk_size);
+ "dst buffer size=%zu, src buffer size=%zu, "
+ "data size=%u.\n", req_data->block_id, buf_len,
+ sizeof(rsp->rsp_data), rsp->rsp_head.cur_blk_size);
ret = -EINVAL;
goto out;
}
diff --git a/net/nic/nic_queue/hikp_nic_queue.c b/net/nic/nic_queue/hikp_nic_queue.c
index fa3b9d3..c73c8f7 100644
--- a/net/nic/nic_queue/hikp_nic_queue.c
+++ b/net/nic/nic_queue/hikp_nic_queue.c
@@ -246,10 +246,12 @@ static int hikp_nic_queue_get_blk(struct hikp_cmd_header *req_header,
}
rsp = (struct nic_queue_rsp *)cmd_ret->rsp_data;
- if (rsp->rsp_head.cur_blk_size > buf_len) {
+ if (rsp->rsp_head.cur_blk_size > buf_len ||
+ rsp->rsp_head.cur_blk_size > sizeof(rsp->rsp_data)) {
HIKP_ERROR_PRINT("nic_queue block-%u copy size error, "
- "buffer size=%zu, data size=%u.\n",
- req_data->block_id, buf_len, rsp->rsp_head.cur_blk_size);
+ "dst buffer size=%zu, src buffer size=%zu, "
+ "data size=%u.\n", req_data->block_id, buf_len,
+ sizeof(rsp->rsp_data), rsp->rsp_head.cur_blk_size);
ret = -EINVAL;
goto out;
}
diff --git a/net/nic/nic_rss/hikp_nic_rss.c b/net/nic/nic_rss/hikp_nic_rss.c
index ff1cfd2..558f931 100644
--- a/net/nic/nic_rss/hikp_nic_rss.c
+++ b/net/nic/nic_rss/hikp_nic_rss.c
@@ -364,10 +364,12 @@ static int hikp_nic_rss_get_blk(struct hikp_cmd_header *req_header,
}
rsp = (struct nic_rss_rsp *)cmd_ret->rsp_data;
- if (rsp->rsp_head.cur_blk_size > buf_len) {
+ if (rsp->rsp_head.cur_blk_size > buf_len ||
+ rsp->rsp_head.cur_blk_size > sizeof(rsp->rsp_data)) {
HIKP_ERROR_PRINT("nic_rss block-%u copy size error, "
- "buffer size=%zu, data size=%u.\n",
- req_data->block_id, buf_len, rsp->rsp_head.cur_blk_size);
+ "dst buffer size=%zu, src buffer size=%zu, "
+ "data size=%u.\n", req_data->block_id, buf_len,
+ sizeof(rsp->rsp_data), rsp->rsp_head.cur_blk_size);
ret = -EINVAL;
goto out;
}
--
2.45.0.windows.1

View File

@ -0,0 +1,85 @@
From 54d612f78a417090bc0449658426d9180b84b2e9 Mon Sep 17 00:00:00 2001
From: Jijie Shao <shaojijie@huawei.com>
Date: Wed, 14 Aug 2024 16:16:57 +0800
Subject: [PATCH 10/27] hikptool: nic: Fix the Code review comments in NIC
modules
Fix issue of Out-of-bounds access may occur.
Signed-off-by: Jijie Shao <shaojijie@huawei.com>
---
net/nic/nic_dfx/hikp_nic_dfx.c | 20 +++++++++++++++++++-
net/nic/nic_mac/hikp_nic_port.c | 7 +++++++
2 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/net/nic/nic_dfx/hikp_nic_dfx.c b/net/nic/nic_dfx/hikp_nic_dfx.c
index 4095229..2cc4367 100644
--- a/net/nic/nic_dfx/hikp_nic_dfx.c
+++ b/net/nic/nic_dfx/hikp_nic_dfx.c
@@ -21,6 +21,9 @@
#include "hikp_net_lib.h"
#include "hikp_nic_dfx.h"
+#define dfx_get_max_reg_bffer_size(rsp_head) \
+ (uint32_t)((rsp_head)->total_blk_num * MAX_DFX_DATA_NUM * sizeof(uint32_t))
+
struct nic_dfx_param g_dfx_param = { 0 };
static const struct dfx_module_cmd g_dfx_module_parse[] = {
@@ -138,7 +141,7 @@ static int hikp_nic_get_first_blk_dfx(struct nic_dfx_rsp_head_t *rsp_head, uint3
rsp_head->total_type_num = 0;
goto err_out;
}
- *max_dfx_size = (uint32_t)(rsp_head->total_blk_num * MAX_DFX_DATA_NUM * sizeof(uint32_t));
+ *max_dfx_size = dfx_get_max_reg_bffer_size(rsp_head);
*reg_data = (uint32_t *)calloc(1, *max_dfx_size);
if (*reg_data == NULL) {
HIKP_ERROR_PRINT("malloc log memory 0x%x failed.\n", *max_dfx_size);
@@ -284,8 +287,23 @@ static void hikp_nic_dfx_print(const struct nic_dfx_rsp_head_t *rsp_head, uint32
struct nic_dfx_type_head *type_head;
uint8_t last_type_id = 0;
uint32_t *ptr = reg_data;
+ uint32_t max_size;
+ uint32_t num_u32;
uint8_t i;
+ max_size = dfx_get_max_reg_bffer_size(rsp_head);
+ for (i = 0; i < rsp_head->total_type_num; i++) {
+ type_head = (struct nic_dfx_type_head *)ptr;
+ num_u32 = type_head->reg_num * WORD_NUM_PER_REG + 1; /* including type_head */
+ if (max_size < num_u32 * sizeof(uint32_t)) {
+ HIKP_ERROR_PRINT("register real size exceeds the max size\n");
+ return;
+ }
+ ptr += num_u32;
+ max_size -= num_u32 * sizeof(uint32_t);
+ }
+
+ ptr = reg_data;
printf("****************** module %s reg dump start ********************\n",
g_dfx_module_parse[g_dfx_param.module_idx].module_name);
for (i = 0; i < rsp_head->total_type_num; i++) {
diff --git a/net/nic/nic_mac/hikp_nic_port.c b/net/nic/nic_mac/hikp_nic_port.c
index 725ef95..f818001 100644
--- a/net/nic/nic_mac/hikp_nic_port.c
+++ b/net/nic/nic_mac/hikp_nic_port.c
@@ -498,9 +498,16 @@ static void mac_cmd_print_cdr_dfx(struct mac_cmd_cdr_dfx *cdr_dfx, struct mac_po
static void mac_cmd_disp_cdr_info(struct mac_cmd_cdr_dfx *cdr_dfx)
{
+ uint8_t cdr_max_num = HIKP_ARRAY_SIZE(cdr_dfx->wire_cdr.dfx);
+
if (!cdr_dfx->cdr_num)
return;
+ if (cdr_dfx->cdr_num > cdr_max_num) {
+ printf("the cdr_num(%u) exceeds %u\n", cdr_dfx->cdr_num, cdr_max_num);
+ return;
+ }
+
printf("\n======================== PORT CDR INFO =======================\n");
printf("direct\t|addr |lane |type |mode |status \n");
printf("----------------------------------------------------------------------------\n");
--
2.45.0.windows.1

View File

@ -0,0 +1,43 @@
From 0a53156f7281337ac037ea334f7011b54a6f5655 Mon Sep 17 00:00:00 2001
From: Peiyang Wang <wangpeiyang1@huawei.com>
Date: Tue, 20 Aug 2024 16:33:35 +0800
Subject: [PATCH 11/27] hikptool: nic: return real errno if realpath failed in
NIC module
Return real errno if realpath failed.
Signed-off-by: Peiyang Wang <wangpeiyang1@huawei.com>
---
net/hikp_net_lib.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/net/hikp_net_lib.c b/net/hikp_net_lib.c
index 8db4ad5..32b278b 100644
--- a/net/hikp_net_lib.c
+++ b/net/hikp_net_lib.c
@@ -25,7 +25,7 @@
static int hikp_read_net_pci_info(const char *file_path, char *content, size_t len)
{
- char path[PATH_MAX + 1] = { 0 };
+ char path[PATH_MAX] = { 0 }; /* PATH_MAX includes the \0 so +1 is not required */
int ret;
int fd;
@@ -35,9 +35,12 @@ static int hikp_read_net_pci_info(const char *file_path, char *content, size_t l
if (len > MAX_PCI_ID_LEN + 1 || len < 1)
return -EINVAL;
- if (strlen(file_path) > PATH_MAX || realpath(file_path, path) == NULL)
+ if (strlen(file_path) > PATH_MAX)
return -ENOENT;
+ if (!realpath(file_path, path))
+ return -errno;
+
fd = open(path, O_RDONLY);
if (fd < 0)
return -EPERM;
--
2.45.0.windows.1

View File

@ -0,0 +1,165 @@
From 40f0b1281cb66cbd19c7ffdab7746857a4d89409 Mon Sep 17 00:00:00 2001
From: Peiyang Wang <wangpeiyang1@huawei.com>
Date: Tue, 20 Aug 2024 16:46:41 +0800
Subject: [PATCH 12/27] hikptool: nic: return real cmd status if alloc failed
in NIC module
return real cmd status if alloc failed
Signed-off-by: Peiyang Wang <wangpeiyang1@huawei.com>
---
net/nic/nic_fec/hikp_nic_fec.c | 11 ++++++-----
net/nic/nic_ft/hikp_nic_port_fault.c | 9 +++++----
net/nic/nic_gro/hikp_nic_gro.c | 11 ++++++-----
net/nic/nic_torus/hikp_nic_torus.c | 9 +++++----
4 files changed, 22 insertions(+), 18 deletions(-)
diff --git a/net/nic/nic_fec/hikp_nic_fec.c b/net/nic/nic_fec/hikp_nic_fec.c
index 342b3eb..edea28b 100644
--- a/net/nic/nic_fec/hikp_nic_fec.c
+++ b/net/nic/nic_fec/hikp_nic_fec.c
@@ -22,19 +22,20 @@ static struct tool_target g_fec_target;
static int hikp_nic_fec_err_query(const struct bdf_t *bdf, struct nic_fec_err_info *info)
{
- struct nic_fec_req_para req = { 0 };
struct hikp_cmd_header header = { 0 };
+ struct nic_fec_req_para req = { 0 };
struct hikp_cmd_ret *cmd_ret;
struct nic_fec_rsp *rsp;
+ int ret;
req.bdf = *bdf;
hikp_cmd_init(&header, NIC_MOD, GET_FEC_INFO_CMD, NIC_FEC_ERR_INFO_DUMP);
cmd_ret = hikp_cmd_alloc(&header, &req, sizeof(req));
if (cmd_ret == NULL || cmd_ret->status != 0) {
- HIKP_ERROR_PRINT("fail to get fec info, retcode: %u\n",
- cmd_ret ? cmd_ret->status : EIO);
+ ret = cmd_ret ? -cmd_ret->status : -EIO;
+ HIKP_ERROR_PRINT("fail to get fec info, retcode: %d\n", ret);
free(cmd_ret);
- return -EIO;
+ return ret;
}
rsp = (struct nic_fec_rsp *)cmd_ret->rsp_data;
@@ -111,7 +112,7 @@ static void hikp_nic_fec_err_show(const struct nic_fec_err_info *info)
static void hikp_nic_fec_cmd_execute(struct major_cmd_ctrl *self)
{
struct bdf_t *bdf = &g_fec_target.bdf;
- struct nic_fec_err_info info;
+ struct nic_fec_err_info info = { 0 };
int ret;
ret = hikp_nic_fec_err_query(bdf, &info);
diff --git a/net/nic/nic_ft/hikp_nic_port_fault.c b/net/nic/nic_ft/hikp_nic_port_fault.c
index fd94214..85fa874 100644
--- a/net/nic/nic_ft/hikp_nic_port_fault.c
+++ b/net/nic/nic_ft/hikp_nic_port_fault.c
@@ -26,18 +26,19 @@ static int hikp_nic_port_fault_query(const struct bdf_t *bdf,
struct hikp_cmd_header header = { 0 };
struct nic_port_fault_rsp *rsp;
struct hikp_cmd_ret *cmd_ret;
+ int ret = 0;
req.bdf = *bdf;
hikp_cmd_init(&header, NIC_MOD, GET_PORT_FAULT_STATUS,
NIC_PORT_FAULT_INFO_DUMP);
cmd_ret = hikp_cmd_alloc(&header, &req, sizeof(req));
if (cmd_ret == NULL || cmd_ret->status != 0) {
- HIKP_ERROR_PRINT("fail to get port fault, retcode: %u\n",
- cmd_ret ? cmd_ret->status : EIO);
+ ret = cmd_ret ? -cmd_ret->status : -EIO;
+ HIKP_ERROR_PRINT("fail to get port fault, retcode: %d\n", ret);
if (cmd_ret != NULL)
free(cmd_ret);
- return -EIO;
+ return ret;
}
rsp = (struct nic_port_fault_rsp *)cmd_ret->rsp_data;
@@ -83,7 +84,7 @@ static void hikp_nic_port_fault_show(struct nic_port_fault_status *info)
static void hikp_nic_port_fault_cmd_execute(struct major_cmd_ctrl *self)
{
struct bdf_t *bdf = &g_port_fault_target.bdf;
- struct nic_port_fault_status info;
+ struct nic_port_fault_status info = { 0 };
int ret;
ret = hikp_nic_port_fault_query(bdf, &info);
diff --git a/net/nic/nic_gro/hikp_nic_gro.c b/net/nic/nic_gro/hikp_nic_gro.c
index 84b54c8..d897f11 100644
--- a/net/nic/nic_gro/hikp_nic_gro.c
+++ b/net/nic/nic_gro/hikp_nic_gro.c
@@ -22,19 +22,20 @@ static struct tool_target g_gro_target;
static int hikp_nic_gro_query(const struct bdf_t *bdf, struct nic_gro_info *info)
{
- struct nic_gro_req_para req = { 0 };
struct hikp_cmd_header header = { 0 };
+ struct nic_gro_req_para req = { 0 };
struct hikp_cmd_ret *cmd_ret;
struct nic_gro_rsp *rsp;
+ int ret = 0;
req.bdf = *bdf;
hikp_cmd_init(&header, NIC_MOD, GET_GRO_INFO_CMD, NIC_GRO_INFO_DUMP);
cmd_ret = hikp_cmd_alloc(&header, &req, sizeof(req));
if (cmd_ret == NULL || cmd_ret->status != 0) {
- HIKP_ERROR_PRINT("fail to get gro info, retcode: %u\n",
- cmd_ret ? cmd_ret->status : EIO);
+ ret = cmd_ret ? -cmd_ret->status : -EIO;
+ HIKP_ERROR_PRINT("fail to get gro info, retcode: %d\n", ret);
free(cmd_ret);
- return -EIO;
+ return ret;
}
rsp = (struct nic_gro_rsp *)cmd_ret->rsp_data;
@@ -55,7 +56,7 @@ static void hikp_nic_gro_show(const struct nic_gro_info *info)
static void hikp_nic_gro_cmd_execute(struct major_cmd_ctrl *self)
{
struct bdf_t *bdf = &g_gro_target.bdf;
- struct nic_gro_info info;
+ struct nic_gro_info info = { 0 };
int ret;
ret = hikp_nic_gro_query(bdf, &info);
diff --git a/net/nic/nic_torus/hikp_nic_torus.c b/net/nic/nic_torus/hikp_nic_torus.c
index 4baede6..9483bfe 100644
--- a/net/nic/nic_torus/hikp_nic_torus.c
+++ b/net/nic/nic_torus/hikp_nic_torus.c
@@ -27,16 +27,17 @@ static int hikp_nic_torus_query(const struct bdf_t *bdf,
struct hikp_cmd_header header = { 0 };
struct hikp_cmd_ret *cmd_ret;
struct nic_torus_rsp *rsp;
+ int ret = 0;
req.bdf = *bdf;
hikp_cmd_init(&header, NIC_MOD, GET_TORUS_INFO_CMD, NIC_TORUS_INFO_DUMP);
cmd_ret = hikp_cmd_alloc(&header, &req, sizeof(req));
if (cmd_ret == NULL || cmd_ret->status != 0) {
- HIKP_ERROR_PRINT("fail to get torus info, retcode: %u\n",
- cmd_ret ? cmd_ret->status : EIO);
+ ret = cmd_ret ? -cmd_ret->status : -EIO;
+ HIKP_ERROR_PRINT("fail to get torus info, retcode: %d\n", ret);
if (cmd_ret)
free(cmd_ret);
- return -EIO;
+ return ret;
}
rsp = (struct nic_torus_rsp *)cmd_ret->rsp_data;
@@ -133,7 +134,7 @@ static void hikp_nic_torus_show(const struct nic_torus_info *info)
static void hikp_nic_torus_cmd_execute(struct major_cmd_ctrl *self)
{
struct bdf_t *bdf = &g_torus_target.bdf;
- struct nic_torus_info info;
+ struct nic_torus_info info = { 0 };
int ret;
ret = hikp_nic_torus_query(bdf, &info);
--
2.45.0.windows.1

View File

@ -0,0 +1,40 @@
From e6127d30663daef7cb847265006b592eebbfc152 Mon Sep 17 00:00:00 2001
From: Peiyang Wang <wangpeiyang1@huawei.com>
Date: Tue, 20 Aug 2024 17:02:33 +0800
Subject: [PATCH 13/27] hikptool: nic: check path before used it in function
hikp_get_dir_name_of_device
check path before used it in hikp_get_dir_name_of_device
Signed-off-by: Peiyang Wang <wangpeiyang1@huawei.com>
---
net/hikp_net_lib.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/net/hikp_net_lib.c b/net/hikp_net_lib.c
index 32b278b..4e1e305 100644
--- a/net/hikp_net_lib.c
+++ b/net/hikp_net_lib.c
@@ -238,13 +238,17 @@ int get_revision_id_by_bdf(const struct bdf_t *bdf, char *revision_id, size_t id
static int hikp_get_dir_name_of_device(const char *path, size_t len, char *dir_name)
{
+ char file_path[PATH_MAX] = { 0 }; /* PATH_MAX includes the \0 so +1 is not required */
struct dirent *ptr;
DIR *dir = NULL;
- if (len > PCI_MAX_DIR_NAME_LEN)
+ if (len > PCI_MAX_DIR_NAME_LEN || strlen(path) > PATH_MAX)
return -EINVAL;
- dir = opendir(path);
+ if (!realpath(path, file_path))
+ return -errno;
+
+ dir = opendir(file_path);
if (dir == NULL) {
HIKP_ERROR_PRINT("read path %s fail.\n", path);
return -EINVAL;
--
2.45.0.windows.1

View File

@ -0,0 +1,35 @@
From 043c7d14e8b09bfe1b242bfcf2b0a3342e3d18da Mon Sep 17 00:00:00 2001
From: Peiyang Wang <wangpeiyang1@huawei.com>
Date: Tue, 20 Aug 2024 17:16:53 +0800
Subject: [PATCH 14/27] hikptool: nic: check strtol if it failed in
get_numvfs_by_bdf
Since strtol() can legitimately return 0, LONG_MAX, or LONG_MIN (LLONG_MAX
or LLONG_MIN for strtoll()) on both success and failure. So set errno to 0
and check it after calling.
Signed-off-by: Peiyang Wang <wangpeiyang1@huawei.com>
---
net/hikp_net_lib.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/net/hikp_net_lib.c b/net/hikp_net_lib.c
index 4e1e305..23adbdc 100644
--- a/net/hikp_net_lib.c
+++ b/net/hikp_net_lib.c
@@ -366,7 +366,12 @@ int get_numvfs_by_bdf(const struct bdf_t *bdf, uint8_t *numvfs)
if (ret != 0)
return ret;
+ errno = 0;
ret = (int)strtol(numvf, NULL, 0);
+ if (errno) {
+ HIKP_ERROR_PRINT("get numvfs by bdf failed, ret=%d\n", -errno);
+ return -errno;
+ }
if ((ret > UCHAR_MAX) || (ret < 0)) {
HIKP_ERROR_PRINT("get numvfs by bdf fail.\n");
return -EINVAL;
--
2.45.0.windows.1

View File

@ -0,0 +1,43 @@
From f24d89b76811f7b2bbfea787bb403358f960f097 Mon Sep 17 00:00:00 2001
From: Peiyang Wang <wangpeiyang1@huawei.com>
Date: Wed, 21 Aug 2024 10:30:09 +0800
Subject: [PATCH 15/27] hikptool: nic: adding NUL at the end of the buffer
length that is actually read.
When pread is called, the return value may be smaller than the length that
want to read, the position of adding NUL is too much and memory might be
exposed. To avoid that case, to add NUL at the end of the buffer length
that is actually read.
Signed-off-by: Peiyang Wang <wangpeiyang1@huawei.com>
---
net/hikp_net_lib.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/net/hikp_net_lib.c b/net/hikp_net_lib.c
index 23adbdc..fbf03bd 100644
--- a/net/hikp_net_lib.c
+++ b/net/hikp_net_lib.c
@@ -47,13 +47,14 @@ static int hikp_read_net_pci_info(const char *file_path, char *content, size_t l
ret = pread(fd, content, len - 1, 0);
if (ret < 0) {
- close(fd);
- return -EIO;
+ ret = -errno;
+ } else {
+ content[ret] = '\0'; // The invoker ensures that the bounds are not crossed.
+ ret = 0;
}
- content[len - 1] = '\0'; // The invoker ensures that the bounds are not crossed.
- close(fd);
- return 0;
+ close(fd);
+ return ret;
}
int hikp_net_creat_sock(void)
--
2.45.0.windows.1

View File

@ -0,0 +1,59 @@
From bc4420a4c0cb1fa85b15d671c7ebabbe534a0196 Mon Sep 17 00:00:00 2001
From: Peiyang Wang <wangpeiyang1@huawei.com>
Date: Wed, 21 Aug 2024 10:28:27 +0800
Subject: [PATCH 16/27] hikptool: nic: avoid array boundary exceeded in
hikp_nic_info.c
In hikp_nic_info.c, when using pf id or die id, the value should be not
bigger than the max value. Otherwise, array boundary exceeded might be
occurred.
Signed-off-by: Peiyang Wang <wangpeiyang1@huawei.com>
---
net/nic/nic_info/hikp_nic_info.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/net/nic/nic_info/hikp_nic_info.c b/net/nic/nic_info/hikp_nic_info.c
index 992bbf0..cd07b13 100644
--- a/net/nic/nic_info/hikp_nic_info.c
+++ b/net/nic/nic_info/hikp_nic_info.c
@@ -113,6 +113,11 @@ static void hikp_nic_info_print_cur_pf(const struct bdf_t *bdf)
uint8_t i;
int ret;
+ if (pf_id >= HIKP_MAX_PF_NUM) {
+ HIKP_ERROR_PRINT("pf_id(%u) is invalid.\n", pf_id);
+ return;
+ }
+
printf("Current function: pf%u\n", pf_id);
printf("\t%-16s %s\n", "pf mode:",
g_info_param.info.pf_info[pf_id].pf_mode ? "X86" : "ARM");
@@ -148,6 +153,11 @@ static void hikp_nic_info_print_cur_die(void)
{
uint8_t i;
+ if (g_info_param.info.pf_num > HIKP_MAX_PF_NUM) {
+ HIKP_ERROR_PRINT("pf_num(%u) is invalid.\n", g_info_param.info.pf_num);
+ return;
+ }
+
printf("Current die(chip%u-die%u) info:\n",
g_info_param.info.chip_id, g_info_param.info.die_id);
printf("revision id: %s", g_info_param.revision_id);
@@ -186,6 +196,12 @@ static bool is_bus_id_accessed(void)
{
uint8_t i;
+ if (g_info_param.accessed_die_num >= MAX_DIE_NUM) {
+ HIKP_ERROR_PRINT("accessed_die_num(%u) is invalid.\n",
+ g_info_param.accessed_die_num);
+ return false;
+ }
+
for (i = 0; i < g_info_param.accessed_die_num; i++) {
if (g_info_param.accessed_bus_id[i] == g_info_param.target.bdf.bus_id)
return true;
--
2.45.0.windows.1

View File

@ -0,0 +1,31 @@
From dd185f7120e3a55af2ef4fc061aa3a271a986a1d Mon Sep 17 00:00:00 2001
From: Jie Hai <haijie1@huawei.com>
Date: Thu, 29 Aug 2024 10:11:47 +0800
Subject: [PATCH 17/27] hikptool/nic: Fix bad usage of format string
The format string lacks parameters, which may cause
information leakage. This patch fixes it.
Fixes: 8244390e29a3 ("hikptool/nic: Fix the Code review comments")
Signed-off-by: Jie Hai <haijie1@huawei.com>
---
net/nic/nic_ppp/hikp_nic_ppp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/nic/nic_ppp/hikp_nic_ppp.c b/net/nic/nic_ppp/hikp_nic_ppp.c
index c070666..96f317b 100644
--- a/net/nic/nic_ppp/hikp_nic_ppp.c
+++ b/net/nic/nic_ppp/hikp_nic_ppp.c
@@ -1077,7 +1077,7 @@ static int hikp_nic_check_hw_res(struct hikp_nic_ppp_hw_resources *hw_res)
return -EINVAL;
}
if (hw_res->mng_tbl_size == 0) {
- HIKP_ERROR_PRINT("VF VLAN Table size (%uis zero!\n");
+ HIKP_ERROR_PRINT("Manager Table size should not be zero!\n");
return -EINVAL;
}
if (hw_res->mac_id >= HIKP_PPP_MAX_MAC_ID_NUM) {
--
2.45.0.windows.1

View File

@ -0,0 +1,43 @@
From c89df2898b19f1a1503bd41c065aa163a1900b53 Mon Sep 17 00:00:00 2001
From: Jie Hai <haijie1@huawei.com>
Date: Thu, 29 Aug 2024 10:08:55 +0800
Subject: [PATCH 18/27] hikptool/nic: Fix potential dead loop
When the loop variable range does not cover the upper bound
of the loop, an infinite loop occurs. This patch fixes it.
Signed-off-by: Jie Hai <haijie1@huawei.com>
---
net/nic/nic_fd/hikp_nic_fd.c | 2 +-
net/nic/nic_ppp/hikp_nic_ppp.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/net/nic/nic_fd/hikp_nic_fd.c b/net/nic/nic_fd/hikp_nic_fd.c
index 3d6a9dc..7125699 100644
--- a/net/nic/nic_fd/hikp_nic_fd.c
+++ b/net/nic/nic_fd/hikp_nic_fd.c
@@ -503,7 +503,7 @@ static void hikp_nic_show_fd_rules(const void *data)
struct nic_fd_rule_info *rule;
uint16_t max_key_bytes;
size_t one_rule_size;
- uint16_t i;
+ uint32_t i;
key_cfg = &g_fd_hw_info.key_cfg[stage_no];
stage_rules = &rules[stage_no];
diff --git a/net/nic/nic_ppp/hikp_nic_ppp.c b/net/nic/nic_ppp/hikp_nic_ppp.c
index 96f317b..67a3be6 100644
--- a/net/nic/nic_ppp/hikp_nic_ppp.c
+++ b/net/nic/nic_ppp/hikp_nic_ppp.c
@@ -184,7 +184,7 @@ static void hikp_nic_ppp_show_func_uc_mac_addr(struct mac_vlan_uc_tbl *uc_tbl,
struct mac_vlan_uc_entry *uc_entry;
uint8_t pf_id;
uint8_t vf_id;
- uint8_t i;
+ uint32_t i;
for (i = 0; i < uc_tbl->entry_size; i++) {
uc_entry = &uc_tbl->entry[i];
--
2.45.0.windows.1

View File

@ -0,0 +1,482 @@
From 90e86309519707998fa9b2b79df9734ea43f1304 Mon Sep 17 00:00:00 2001
From: veega2022 <zhuweijia@huawei.com>
Date: Tue, 12 Nov 2024 19:38:31 +0800
Subject: [PATCH 19/27] hikptool: Rectify the cleancode issue.
Rectify some cleancode alarms.Includes:
1. Add the function return value verification.
2. The logic for assigning values to output parameters of functions is optimized.
3. Use of parentheses.
4. Fix potential dead loop.
5. Fix unsigned-signed mixed use.
Signed-off-by: veega2022 <zhuweijia@huawei.com>
---
net/nic/nic_fd/hikp_nic_fd.c | 2 +-
net/nic/nic_log/hikp_nic_log.c | 7 +++--
net/nic/nic_mac/hikp_nic_xsfp.h | 4 +--
net/nic/nic_ppp/hikp_nic_ppp.c | 10 +++---
.../roce_ext_common/hikp_roce_ext_common.c | 2 +-
net/roce/roce_qmm/hikp_roce_qmm.c | 2 +-
net/roce/roce_timer/hikp_roce_timer.c | 2 +-
net/roh/hikp_roh_mac.c | 24 ++++++--------
net/roh/hikp_roh_show_bp.c | 2 +-
net/roh/hikp_roh_show_mib.c | 2 +-
net/ub/ub_crd/hikp_ub_crd.c | 4 +--
net/ub/ub_ppp/hikp_unic_ppp.c | 4 +--
ossl/ossl_user_linux.c | 10 +++---
pcie/func_lib/pcie_func/pcie_reg_dump.c | 2 +-
pcie/func_lib/pcie_func/pcie_statistics.c | 2 +-
serdes/hikp_serdes.c | 5 ++-
tool_lib/op_logs.c | 31 +++++++++++++------
17 files changed, 63 insertions(+), 52 deletions(-)
diff --git a/net/nic/nic_fd/hikp_nic_fd.c b/net/nic/nic_fd/hikp_nic_fd.c
index 7125699..d4a9678 100644
--- a/net/nic/nic_fd/hikp_nic_fd.c
+++ b/net/nic/nic_fd/hikp_nic_fd.c
@@ -630,7 +630,7 @@ static int hikp_nic_query_fd_rules(struct hikp_cmd_header *req_header, const str
uint16_t max_key_bytes;
uint32_t left_buf_len;
size_t one_rule_size;
- uint16_t idx;
+ uint32_t idx;
int ret = 0;
if (stage >= NIC_FD_STAGE_NUM) {
diff --git a/net/nic/nic_log/hikp_nic_log.c b/net/nic/nic_log/hikp_nic_log.c
index 893aef1..dc622e0 100644
--- a/net/nic/nic_log/hikp_nic_log.c
+++ b/net/nic/nic_log/hikp_nic_log.c
@@ -106,7 +106,9 @@ static int hikp_nic_get_first_blk_info(uint32_t *total_blk_num,
log_rsp = (struct nic_log_rsp_data *)(cmd_ret->rsp_data);
log_size = (uint32_t)(log_rsp->total_blk_num * MAX_LOG_DATA_NUM * sizeof(uint32_t));
- if (log_size < log_rsp->cur_blk_size) {
+ if (log_rsp->cur_blk_size == 0 ||
+ log_size < log_rsp->cur_blk_size ||
+ log_rsp->cur_blk_size > sizeof(log_rsp->log_data)) {
HIKP_ERROR_PRINT("log size must bigger than current block size.\n");
ret = -EINVAL;
goto err_out;
@@ -142,7 +144,8 @@ static int hikp_nic_get_log_info(uint32_t blk_id, uint32_t *cur_blk_size, uint8_
log_rsp = (struct nic_log_rsp_data *)(cmd_ret->rsp_data);
*cur_blk_size = (uint32_t)log_rsp->cur_blk_size;
*blk_num = (uint32_t)log_rsp->total_blk_num;
- if (max_log_size < *cur_blk_size) {
+ if (max_log_size < *cur_blk_size ||
+ *cur_blk_size > sizeof(log_rsp->log_data)) {
HIKP_ERROR_PRINT("log size must bigger than current block(%u) size.\n", blk_id);
ret = -EINVAL;
goto err_out;
diff --git a/net/nic/nic_mac/hikp_nic_xsfp.h b/net/nic/nic_mac/hikp_nic_xsfp.h
index 6f5e38f..a04ecdc 100644
--- a/net/nic/nic_mac/hikp_nic_xsfp.h
+++ b/net/nic/nic_mac/hikp_nic_xsfp.h
@@ -176,7 +176,7 @@ struct sfp_a0_page {
uint8_t rsvd_dm : 1;
};
uint8_t enhanced_options; /* reg 93: Enhanced Options */
- uint8_t Sff_8472_compliance; /* reg 94: SFF-8472 Compliance */
+ uint8_t sff_8472_compliance; /* reg 94: SFF-8472 Compliance */
uint8_t cc_ext; /* reg 95: Check code for the Extended ID Fields (addresses 64 to 94) */
/* 96~255 */
@@ -247,7 +247,7 @@ struct sfp_page_info {
#define QSFP_TRANS_OPTICAL_MAX 0x9
struct qsfp_page0_lower {
- uint8_t Identifier; /* reg 0: Identifier (1 Byte) */
+ uint8_t identifier; /* reg 0: Identifier (1 Byte) */
uint8_t revision_comp; /* reg 1: Revision Compliance */
uint8_t status_indicator; /* reg 2: Status Indicators */
uint8_t tx_rx_los; /* reg 3: Latched Tx/Rx LOS indicator */
diff --git a/net/nic/nic_ppp/hikp_nic_ppp.c b/net/nic/nic_ppp/hikp_nic_ppp.c
index 67a3be6..3f777b3 100644
--- a/net/nic/nic_ppp/hikp_nic_ppp.c
+++ b/net/nic/nic_ppp/hikp_nic_ppp.c
@@ -519,13 +519,13 @@ out:
static int hikp_nic_ppp_query_uc_mac_addr(struct hikp_cmd_header *req_header,
struct nic_ppp_req_para *req_data,
struct mac_vlan_uc_tbl *uc_tbl,
- uint16_t max_hw_entry_size)
+ uint32_t max_hw_entry_size)
{
struct mac_vlan_uc_entry *uc_entry = uc_tbl->entry;
struct nic_ppp_rsp_head rsp_head = {0};
uint32_t entry_size = 0;
size_t left_buf_len;
- uint16_t idx = 0;
+ uint32_t idx = 0;
int ret = 0;
while (idx < max_hw_entry_size) {
@@ -561,13 +561,13 @@ static int hikp_nic_ppp_query_uc_mac_addr(struct hikp_cmd_header *req_header,
static int hikp_nic_ppp_query_mc_mac_addr(struct hikp_cmd_header *req_header,
struct nic_ppp_req_para *req_data,
struct mac_vlan_mc_tbl *mc_tbl,
- uint16_t max_hw_entry_size)
+ uint32_t max_hw_entry_size)
{
struct mac_vlan_mc_entry *mc_entry = mc_tbl->entry;
struct nic_ppp_rsp_head rsp_head = {0};
uint32_t entry_size = 0;
size_t left_buf_len;
- uint16_t idx = 0;
+ uint32_t idx = 0;
int ret = 0;
while (idx < max_hw_entry_size) {
@@ -1086,7 +1086,7 @@ static int hikp_nic_check_hw_res(struct hikp_nic_ppp_hw_resources *hw_res)
return -EINVAL;
}
if (hw_res->total_func_num == 0 || hw_res->total_func_num > HIKP_NIC_MAX_FUNC_NUM) {
- HIKP_ERROR_PRINT("Total_func_num (%ushould be in [1, %u].\n",
+ HIKP_ERROR_PRINT("Total_func_num (%u) should be in [1, %u].\n",
hw_res->total_func_num, HIKP_NIC_MAX_FUNC_NUM);
return -EINVAL;
}
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 bc3b883..cc9f509 100644
--- a/net/roce/roce_ext_common/hikp_roce_ext_common.c
+++ b/net/roce/roce_ext_common/hikp_roce_ext_common.c
@@ -169,7 +169,7 @@ static void hikp_roce_ext_print(enum roce_cmd_type 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;
+ uint32_t i;
printf("**************%s INFO*************\n", cmd_name);
printf("%-40s[addr_offset] : reg_data\n", "reg_name");
diff --git a/net/roce/roce_qmm/hikp_roce_qmm.c b/net/roce/roce_qmm/hikp_roce_qmm.c
index 9189f88..6ab2c84 100644
--- a/net/roce/roce_qmm/hikp_roce_qmm.c
+++ b/net/roce/roce_qmm/hikp_roce_qmm.c
@@ -154,8 +154,8 @@ static const struct reg_name_info {
static void hikp_roce_qmm_print(struct roce_qmm_rsp_data *qmm_rsp)
{
const char **reg_name;
+ uint32_t index = 0;
uint8_t arr_len;
- int index = 0;
for (index = 0; index < HIKP_ARRAY_SIZE(g_qmm_reg_name_info_table); index++) {
if (g_qmm_reg_name_info_table[index].sub_cmd != g_roce_qmm_param.sub_cmd)
diff --git a/net/roce/roce_timer/hikp_roce_timer.c b/net/roce/roce_timer/hikp_roce_timer.c
index a36257e..ea35241 100644
--- a/net/roce/roce_timer/hikp_roce_timer.c
+++ b/net/roce/roce_timer/hikp_roce_timer.c
@@ -84,8 +84,8 @@ static void hikp_roce_timer_print(struct roce_timer_rsp_data *timer_rsp,
enum roce_timer_cmd_type cmd_type)
{
const char **reg_name;
+ uint32_t index = 0;
uint8_t arr_len;
- int index = 0;
if (cmd_type == TIMER_SHOW_QPC) {
reg_name = g_timer_qpc_reg_name;
diff --git a/net/roh/hikp_roh_mac.c b/net/roh/hikp_roh_mac.c
index 43f954c..4a8cf7b 100644
--- a/net/roh/hikp_roh_mac.c
+++ b/net/roh/hikp_roh_mac.c
@@ -39,34 +39,29 @@ static int hikp_roh_mac_target(struct major_cmd_ctrl *self, const char *argv)
return self->err_no;
}
-static int cmd_show_mac_type_parse(void)
+static void cmd_show_mac_type_parse(void)
{
g_roh_mac_param.flag |= CMD_SHOW_MAC_TYPE_FLAG;
- return 0;
}
-static int cmd_show_cam_parse(void)
+static void cmd_show_cam_parse(void)
{
g_roh_mac_param.flag |= CMD_SHOW_CAM_FLAG;
- return 0;
}
-static int cmd_show_credit_parse(void)
+static void cmd_show_credit_parse(void)
{
g_roh_mac_param.flag |= CMD_SHOW_CREDIT_CNT;
- return 0;
}
static int hikp_roh_mac_show_parse(struct major_cmd_ctrl *self, const char *argv)
{
- int ret;
-
if (strncmp(argv, "cam", sizeof("cam")) == 0) {
- ret = cmd_show_cam_parse();
+ cmd_show_cam_parse();
} else if (strncmp(argv, "mac_type", sizeof("mac_type")) == 0) {
- ret = cmd_show_mac_type_parse();
+ cmd_show_mac_type_parse();
} else if (strncmp(argv, "credit", sizeof("credit")) == 0) {
- ret = cmd_show_credit_parse();
+ cmd_show_credit_parse();
} else {
hikp_roh_mac_help(self, NULL);
snprintf(self->err_str, sizeof(self->err_str),
@@ -74,7 +69,7 @@ static int hikp_roh_mac_show_parse(struct major_cmd_ctrl *self, const char *argv
self->err_no = -EINVAL;
return -EINVAL;
}
- return ret;
+ return 0;
}
int hikp_roh_get_mac_type(struct major_cmd_ctrl *self, struct bdf_t bdf)
@@ -180,7 +175,7 @@ static int hikp_roh_build_cam(struct major_cmd_ctrl *self, struct cam_table_entr
for (int i = 0; i < block_num; i++) {
req_data.bdf = g_roh_mac_param.target.bdf;
- req_data.cam_block_index = i;
+ req_data.cam_block_index = (uint32_t)i;
hikp_cmd_init(&req_header, ROH_MOD, HIKP_ROH_MAC, CMD_BUILD_CAM_TABLE);
cmd_ret = hikp_cmd_alloc(&req_header, &req_data, sizeof(req_data));
if (cmd_ret == NULL || cmd_ret->status != 0) {
@@ -249,6 +244,7 @@ static int hikp_roh_query_crd(uint8_t crd_type, uint32_t num_rows, char const *c
struct roh_mac_req_para req_data = { 0 };
struct hikp_cmd_header req_header = { 0 };
struct hikp_cmd_ret *cmd_ret = NULL;
+ uint32_t i;
int ret;
hikp_cmd_init(&req_header, ROH_MOD, HIKP_ROH_MAC, CMD_SHOW_CREDIT);
@@ -262,7 +258,7 @@ static int hikp_roh_query_crd(uint8_t crd_type, uint32_t num_rows, char const *c
return ret;
}
mac_rsp = (struct roh_mac_credit_data *)(cmd_ret->rsp_data);
- for (int i = 0; i < num_rows; i++) {
+ for (i = 0; i < num_rows; i++) {
union cut_reg reg;
reg.value = (mac_rsp->cut_reg_value)[i];
diff --git a/net/roh/hikp_roh_show_bp.c b/net/roh/hikp_roh_show_bp.c
index 73a53d8..3f3f622 100644
--- a/net/roh/hikp_roh_show_bp.c
+++ b/net/roh/hikp_roh_show_bp.c
@@ -39,7 +39,7 @@ static int hikp_roh_show_bp_target(struct major_cmd_ctrl *self, const char *argv
static int hikp_roh_show_bp(struct major_cmd_ctrl *self)
{
- uint8_t pfc[8] = { 0 };
+ uint8_t pfc[BP_SIZE] = { 0 };
uint8_t egu_tx_bp;
union bp_val res;
uint8_t flit_bp;
diff --git a/net/roh/hikp_roh_show_mib.c b/net/roh/hikp_roh_show_mib.c
index 7267fe5..91e8344 100644
--- a/net/roh/hikp_roh_show_mib.c
+++ b/net/roh/hikp_roh_show_mib.c
@@ -184,7 +184,7 @@ static int hikp_roh_fill_pmu_cnt(int round)
hikp_cmd_init(&req_header, ROH_MOD, HIKP_ROH_SHOW_MIB, CMD_SHOW_MIB_FILL_CNT);
req_data.bdf = roh_show_mib_param.target.bdf;
- req_data.round = round;
+ req_data.round = (uint32_t)round;
cmd_ret = hikp_cmd_alloc(&req_header, &req_data, sizeof(req_data));
ret = hikp_rsp_normal_check(cmd_ret);
diff --git a/net/ub/ub_crd/hikp_ub_crd.c b/net/ub/ub_crd/hikp_ub_crd.c
index 91e1cb7..d564800 100644
--- a/net/ub/ub_crd/hikp_ub_crd.c
+++ b/net/ub/ub_crd/hikp_ub_crd.c
@@ -40,8 +40,8 @@ static int hikp_ub_crd_target(struct major_cmd_ctrl *self, const char *argv)
static uint32_t hikp_ub_show_crd(uint32_t off, struct ub_crd_rsp *crd_rsp, uint32_t num_rows,
char const *crds[][2])
{
- int reg_index;
- int i;
+ uint32_t reg_index;
+ uint32_t i;
for (i = 0; i < num_rows; i++) {
union cut_reg reg;
diff --git a/net/ub/ub_ppp/hikp_unic_ppp.c b/net/ub/ub_ppp/hikp_unic_ppp.c
index 2164f04..105253f 100644
--- a/net/ub/ub_ppp/hikp_unic_ppp.c
+++ b/net/ub/ub_ppp/hikp_unic_ppp.c
@@ -69,7 +69,7 @@ static int hikp_unic_cmd_ppp_feature_select(struct major_cmd_ctrl *self, const c
for (i = 0; i < feat_size; i++) {
if (strncmp(argv, g_unic_ppp_feature_cmd[i].feature_name,
HIKP_UNIC_PPP_MAX_FEATURE_NAME_LEN) == 0) {
- g_unic_ppp_param.feature_idx = i;
+ g_unic_ppp_param.feature_idx = (int)i;
return 0;
}
}
@@ -348,7 +348,7 @@ static void hikp_unic_ppp_show_ip_tbl(const void *data)
struct unic_ip_tbl *ip_tbl = (struct unic_ip_tbl *)data;
struct unic_ip_entry *entry;
uint16_t *ip_addr_tbl_str;
- int i, j;
+ uint32_t i, j;
printf("ip_table_size = %u\n", ip_tbl->entry_size);
printf("index\t| func_id\t| ip_addr\n");
diff --git a/ossl/ossl_user_linux.c b/ossl/ossl_user_linux.c
index a369c68..dc682dd 100644
--- a/ossl/ossl_user_linux.c
+++ b/ossl/ossl_user_linux.c
@@ -47,7 +47,7 @@ int uda_realpath(const char *file_dir, char *format_dir)
int uda_fcntl(const char *lock_file, uint32_t operation, int *fd)
{
- int fd_t = 0;
+ int fd_t;
int ret;
if ((fd == NULL) || (lock_file == NULL))
@@ -57,15 +57,17 @@ int uda_fcntl(const char *lock_file, uint32_t operation, int *fd)
if (fd_t < 0)
return -errno;
- *fd = fd_t;
-
g_fcntl_lock.l_type = F_WRLCK;
if (operation == UDA_FLOCK_NOBLOCK)
ret = fcntl(fd_t, F_SETLK, &g_fcntl_lock);
else
ret = fcntl(fd_t, F_SETLKW, &g_fcntl_lock);
- if (ret != 0)
+ if (ret != 0) {
close(fd_t);
+ *fd = -1; /* Assignment -1 is an invalid value */
+ } else {
+ *fd = fd_t;
+ }
return ret;
}
diff --git a/pcie/func_lib/pcie_func/pcie_reg_dump.c b/pcie/func_lib/pcie_func/pcie_reg_dump.c
index 856aebe..58fcbea 100644
--- a/pcie/func_lib/pcie_func/pcie_reg_dump.c
+++ b/pcie/func_lib/pcie_func/pcie_reg_dump.c
@@ -559,7 +559,7 @@ int pcie_dumpreg_do_dump(uint32_t port_id, uint32_t dump_level)
cmd_ret = hikp_cmd_alloc(&req_header, &req_data, sizeof(req_data));
ret = hikp_rsp_normal_check(cmd_ret);
if (ret) {
- Err("PCIe DUMPREG", "pcie dump cmd_ret check failed, ret: %d.\n", ret);
+ Err("pcie dump cmd_ret check failed, ret: %d.\n", ret);
goto free_cmd_ret;
}
ret = pcie_create_dumpreg_log_file(port_id, dump_level);
diff --git a/pcie/func_lib/pcie_func/pcie_statistics.c b/pcie/func_lib/pcie_func/pcie_statistics.c
index e2bfcb4..6cf7a61 100644
--- a/pcie/func_lib/pcie_func/pcie_statistics.c
+++ b/pcie/func_lib/pcie_func/pcie_statistics.c
@@ -79,7 +79,7 @@ static int pcie_portid_serdes_relation(const struct pcie_macro_info *macro_info,
Info("\tndie_id: %s\n", g_global_ndie_name[ndie_id]);
for (i = 0; i < macro_num; i++) {
for (j = macro_info[i].lane_s; j <= macro_info[i].lane_e; j++)
- Info("\t\tmacro %d \t lane: %d\n", macro_info[i].id, j);
+ Info("\t\tmacro %u \t lane: %u\n", macro_info[i].id, j);
}
return 0;
}
diff --git a/serdes/hikp_serdes.c b/serdes/hikp_serdes.c
index 4afcb9b..23a7946 100644
--- a/serdes/hikp_serdes.c
+++ b/serdes/hikp_serdes.c
@@ -11,7 +11,6 @@
* See the Mulan PSL v2 for more details.
*/
-#include <unistd.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/types.h>
@@ -75,7 +74,7 @@ static int cmd_serdes_start_lane_id(struct major_cmd_ctrl *self, const char *arg
ptr++;
macro_id = strtol(ptr, &endptr, 10); /* 10:decimal */
- if (endptr <= ptr)
+ if ((endptr <= ptr) || (macro_id < 0) || (macro_id > UCHAR_MAX))
goto _START_LANE_ID_ERR_PRO_;
ptr = endptr;
@@ -87,7 +86,7 @@ static int cmd_serdes_start_lane_id(struct major_cmd_ctrl *self, const char *arg
if ((endptr <= ptr) || (*endptr != 0))
goto _START_LANE_ID_ERR_PRO_;
- if ((macro_id < 0) || (macro_id > UCHAR_MAX) || (ds_id < 0) || (ds_id > UCHAR_MAX))
+ if ((ds_id < 0) || (ds_id > UCHAR_MAX))
goto _START_LANE_ID_ERR_PRO_;
g_serdes_param.macro_id = (uint8_t)macro_id;
diff --git a/tool_lib/op_logs.c b/tool_lib/op_logs.c
index b6ecc48..6f28ecd 100644
--- a/tool_lib/op_logs.c
+++ b/tool_lib/op_logs.c
@@ -25,29 +25,38 @@ static bool g_record = true;
static bool g_log_info;
static char g_input_buf[OP_LOG_FILE_W_MAXSIZE + 1] = {0};
-static void op_log_write(const char *log_data)
+static int op_log_write(const char *log_data)
{
size_t w_size;
FILE *fd;
if (strlen(g_op_log) == 0)
- return;
+ return -EINVAL;
if (!is_file_exist(g_op_log))
- return;
+ return -EPERM;
fd = fopen(g_op_log, "a");
if (fd == NULL) {
HIKP_ERROR_PRINT("Can not open operation log file[%s], errno is %d\n",
g_op_log, errno);
- return;
+ return -errno;
}
- (void)chmod(g_op_log, 0640);
+
+ if (chmod(g_op_log, 0640)) {
+ HIKP_ERROR_PRINT("Can not chmod log file[%s], errno is %d\n", g_op_log, errno);
+ (void)fclose(fd);
+ return -errno;
+ }
+
w_size = fwrite((void *)log_data, 1U, strlen(log_data), fd);
- if (strlen(log_data) > ((uint32_t)w_size))
+ if (strlen(log_data) > ((uint32_t)w_size)) {
HIKP_ERROR_PRINT("Error data size write to file, errno is %d\n", errno);
+ (void)fclose(fd);
+ return -errno;
+ }
- (void)fclose(fd);
+ return fclose(fd);
}
static int op_log_write_buffer(const char *log_data, const char *log_dir)
@@ -70,11 +79,13 @@ static int op_log_write_buffer(const char *log_data, const char *log_dir)
return ret;
}
- op_log_write(log_data);
+ ret = op_log_write(log_data);
+ if (ret == 0)
+ g_log_info = true;
+
tool_unlock(&op_lock_fd, UDA_FLOCK_BLOCK);
- g_log_info = true;
(void)sigprocmask(SIG_UNBLOCK, &sigset, NULL);
- return 0;
+ return ret;
}
void op_log_on(void)
--
2.45.0.windows.1

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,519 @@
From 3a36fc8f5e079656823a8093c0233500a4959ac0 Mon Sep 17 00:00:00 2001
From: Jie Hai <haijie1@huawei.com>
Date: Mon, 12 Aug 2024 10:55:15 +0800
Subject: [PATCH 22/27] hikptool/nic: Dump register names for SSU and PPP
module
This patch supports dumping name-offset-values for registers
of SSU and PPP modules. An example is shown:
hikptool nic_dfx -i 0000:37:00.0 -m SSU
DFX cmd version: 0x0
****************** module SSU reg dump start ******* \
*************
-----------------------------------------------------
type name: 32 bit running status
name offset value
FULL_DROP_NUM 0x0350 0x00000000
PART_DROP_NUM 0x0354 0x00000000
......
-----------------------------------------------------
type name: 64 bit common statistics
name offset value
SSU_PPP_MAC_KEY_NUM 0x0330 0x00000000000000f7
SSU_PPP_HOST_KEY_NUM 0x0338 0x000000000000002f
......
Signed-off-by: Jie Hai <haijie1@huawei.com>
---
net/nic/nic_dfx/hikp_nic_dfx.c | 400 ++++++++++++++++++++++++++++++++-
net/nic/nic_dfx/hikp_nic_dfx.h | 11 +
2 files changed, 405 insertions(+), 6 deletions(-)
diff --git a/net/nic/nic_dfx/hikp_nic_dfx.c b/net/nic/nic_dfx/hikp_nic_dfx.c
index 318d85f..67a5fe1 100644
--- a/net/nic/nic_dfx/hikp_nic_dfx.c
+++ b/net/nic/nic_dfx/hikp_nic_dfx.c
@@ -80,6 +80,329 @@ static const struct dfx_type_parse g_dfx_type_parse[] = {
{TYPE_64_TX_PF_NORMAL_STATS, WIDTH_64_BIT, "64 bit TX pf statistics"},
};
+static const struct dfx_reg_name dfx_ppp_type_32_common_drop_stats1[] = {
+ { "DROP_FROM_PRT_PKT_CNT"},
+ { "DROP_FROM_HOST_PKT_CNT"},
+ { "DROP_TX_VLAN_PROC_CNT"},
+ { "DROP_MNG_CNT"},
+ { "DROP_FD_CNT"},
+ { "DROP_NO_DST_CNT"},
+ { "DROP_MC_MBID_FULL_CNT"},
+ { "DROP_SC_FILTERED"},
+};
+
+static const struct dfx_reg_name dfx_ppp_type_32_common_drop_stats2[] = {
+ { "PPP_MC_DROP_PKT_CNT"},
+ { "DROP_PT_CNT"},
+ { "DROP_MAC_ANTI_SPOOF_CNT"},
+ { "DROP_IG_VFV_CNT"},
+ { "DROP_IG_PRTV_CNT"},
+ { "DROP_CNM_PFC_PAUSE_CNT"},
+ { "DROP_TORUS_TC_CNT"},
+ { "DROP_TORUS_LPBK_CNT"},
+ { "FWD_BONDING_PRT_EG_VLAN_DROP_CNT"},
+ { "UMV_UPLINK_EG_VLAN_DROP_CNT"},
+ { "BONDING_UPLINK_VLAN_FILTER_FAIL_CNT"},
+ { "PROMIS_PRUNE_DROP_CNT"},
+ { "UMV_UC_SRC_PRUNE_DROP_CNT"},
+ { "PPP_GRO_DROP_CNT"},
+};
+
+static const struct dfx_reg_name dfx_ppp_type_32_rx_normal_stats[] = {
+ { "PPP_GRO_KEY_CNT" },
+ { "PPP_GRO_INFO_CNT" },
+ { "PPP_GRO_OUT_CNT" },
+ { "PPP_GRO_KEY_MATCH_DATA_CNT" },
+ { "PPP_GRO_KEY_MATCH_TCAM_CNT" },
+ { "PPP_GRO_INFO_MATCH_CNT" },
+};
+
+static const struct dfx_reg_name dfx_ppp_type_64_rx_normal_stats1[] = {
+ { "GET_RX_PKT_CNT" },
+ { "SEND_UC_PRT2HOST_PKT_CNT" },
+ { "SEND_UC_PRT2PRT_PKT_CNT" },
+ { "SEND_MC_FROM_PRT_CNT" },
+ { "SSU_MC_RD_CNT" },
+ { "SSU_MC_DROP_CNT" },
+ { "SSU_MC_RD_PKT_CNT" },
+ { "PPP_MC_2HOST_PKT_CNT" },
+ { "NR_PKT_CNT" },
+ { "RR_PKT_CNT" },
+ { "MNG_TBL_HIT_CNT" },
+ { "FD_TBL_HIT_CNT" },
+ { "FD_LKUP_CNT" },
+ { "UM_TBL_UC_HIT_CNT" },
+ { "UM_TBL_MC_HIT_CNT" },
+ { "UM_TBL_MC_HIT_PKT_CNT" },
+ { "UM_TBL_VMDQ1_HIT_CNT" },
+ { "MTA_TBL_HIT_CNT" },
+ { "MTA_TBL_HIT_PKT_CNT" },
+ { "FWD_BONDING_HIT_CNT" },
+ { "GET_BMC_PKT_CNT" },
+ { "SEND_UC_PRT2BMC_PKT_CNT" },
+ { "SEND_UC_HOST2BMC_PKT_CNT" },
+ { "PROMIS_TBL_HIT_CNT" },
+ { "PROMIS_TBL_HIT_PKT_CNT" },
+ { "GET_TUNL_PKT_CNT" },
+};
+
+static const struct dfx_reg_name dfx_ppp_type_64_rx_normal_stats2[] = {
+ { "SEND_UC_BMC2PRT_PKT_CNT" },
+ { "RX_DEFAULT_HOST_HIT_CNT" },
+ { "LAN_PAIR_CNT" },
+};
+
+static const struct dfx_reg_name dfx_ppp_type_64_tx_normal_stats1[] = {
+ { "GET_TX_PKT_CNT" },
+ { "SEND_UC_HOST2HOST_PKT_CNT" },
+ { "SEND_UC_HOST2PRT_PKT_CNT" },
+ { "SEND_MC_FROM_HOST_CNT" },
+ { "PPP_MC_2PRT_PKT_CNT" },
+ { "NTSNOS_PKT_CNT" },
+ { "NTUP_PKT_CNT" },
+ { "NTLCL_PKT_CNT" },
+ { "NTTGT_PKT_CNT" },
+ { "RTNS_PKT_CNT" },
+ { "RTLPBK_PKT_CNT" },
+ { "BC_HIT_CNT" },
+ { "SEND_UC_HOST2BMC_PKT_CNT" },
+};
+
+static const struct dfx_reg_name dfx_ppp_type_64_tx_normal_stats2[] = {
+ { "PPP_MC_2BMC_PKT_CNT" },
+};
+
+static const struct dfx_reg_name dfx_ppp_type_64_tx_drop_stats[] = {
+ { "PPP_TX_TAG_DROP_CNT_0" },
+ { "PPP_TX_TAG_DROP_CNT_1" },
+ { "PPP_TX_TAG_DROP_CNT_2" },
+ { "PPP_TX_TAG_DROP_CNT_3" },
+};
+
+static const struct dfx_reg_name dfx_ppp_type_32_running_stats[] = {
+ { "PPP_HFS_STS" },
+ { "PPP_MC_RSLT_STS" },
+ { "PPP_RSLT_DESCR_STS" },
+ { "PPP_UMV_STS_0" },
+ { "PPP_UMV_STS_1" },
+ { "PPP_VFV_STS" },
+};
+
+static const struct dfx_type_name_parse g_dfx_ppp_name_parse[] = {
+ { TYPE_32_COMM_DROP_STATS,
+ dfx_ppp_type_32_common_drop_stats1, HIKP_ARRAY_SIZE(dfx_ppp_type_32_common_drop_stats1)},
+ { TYPE_32_COMM_DROP_STATS,
+ dfx_ppp_type_32_common_drop_stats2, HIKP_ARRAY_SIZE(dfx_ppp_type_32_common_drop_stats2)},
+ { TYPE_32_RX_NORMAL_STATS,
+ dfx_ppp_type_32_rx_normal_stats, HIKP_ARRAY_SIZE(dfx_ppp_type_32_rx_normal_stats)},
+ { TYPE_64_RX_NORMAL_STATS,
+ dfx_ppp_type_64_rx_normal_stats1, HIKP_ARRAY_SIZE(dfx_ppp_type_64_rx_normal_stats1)},
+ { TYPE_64_RX_NORMAL_STATS,
+ dfx_ppp_type_64_rx_normal_stats2, HIKP_ARRAY_SIZE(dfx_ppp_type_64_rx_normal_stats2)},
+ { TYPE_64_TX_NORMAL_STATS,
+ dfx_ppp_type_64_tx_normal_stats1, HIKP_ARRAY_SIZE(dfx_ppp_type_64_tx_normal_stats1)},
+ { TYPE_64_TX_NORMAL_STATS,
+ dfx_ppp_type_64_tx_normal_stats2, HIKP_ARRAY_SIZE(dfx_ppp_type_64_tx_normal_stats2)},
+ { TYPE_64_TX_DROP_STATS,
+ dfx_ppp_type_64_tx_drop_stats, HIKP_ARRAY_SIZE(dfx_ppp_type_64_tx_drop_stats)},
+ { TYPE_32_RUNNING_STATUS,
+ dfx_ppp_type_32_running_stats, HIKP_ARRAY_SIZE(dfx_ppp_type_32_running_stats)},
+};
+
+static const struct dfx_reg_name dfx_ssu_type_32_rx_drop_stats[] = {
+ { "RX_OQ_DROP_PKT_CNT" },
+ { "RX_OQ_GLB_DROP_PKT_CNT" },
+};
+
+static const struct dfx_reg_name dfx_ssu_type_32_rx_normal_stats[] = {
+ { "NCSI_RX_PACKET_IN_CNT" },
+};
+
+static const struct dfx_reg_name dfx_ssu_type_32_tx_drop_stats[] = {
+ { "TX_OQ_DROP_PKT_CNT" },
+};
+
+static const struct dfx_reg_name dfx_ssu_type_32_tx_normal_stats[] = {
+ { "NCSI_TX_PACKET_OUT_CNT" },
+};
+
+static const struct dfx_reg_name dfx_ssu_type_32_rx_port_drop_stats1[] = {
+ { "RX_FULL_DROP_NUM" },
+ { "RX_PART_DROP_NUM" },
+ { "ROCE_RX_BYPASS_5NS_DROP_NUM" },
+};
+
+static const struct dfx_reg_name dfx_ssu_type_32_rx_port_drop_stats2[] = {
+ { "RX_OQ_GLB_DROP_PKT_CNT_PORT" },
+};
+
+static const struct dfx_reg_name dfx_ssu_type_32_tx_port_drop_stats1[] = {
+ { "TX_FULL_DROP_NUM" },
+ { "TX_PART_DROP_NUM" },
+};
+
+static const struct dfx_reg_name dfx_ssu_type_32_tx_port_drop_stats2[] = {
+ { "TX_OQ_GLB_DROP_PKT_CNT_PORT" },
+};
+
+static const struct dfx_reg_name dfx_ssu_type_32_running_stats[] = {
+ { "SSU_BP_STATUS_0" },
+ { "SSU_BP_STATUS_1" },
+ { "SSU_BP_STATUS_2" },
+ { "SSU_BP_STATUS_3" },
+ { "SSU_BP_STATUS_4" },
+ { "SSU_BP_STATUS_5" },
+ { "SSU_MAC_TX_PFC_IND" },
+ { "MAC_SSU_RX_PFC_IND" },
+ { "ROH_SSU_PFC" },
+ { "SSU_ETS_PORT_STATUS" },
+ { "SSU_ETS_TCG_STATUS" },
+ { "BTMP_AGEING_ST" },
+};
+
+static const struct dfx_reg_name dfx_ssu_type_32_port_running_stats[] = {
+ { "PKT_TC_0_CURR_BUF_CNT" },
+ { "PKT_TC_1_CURR_BUF_CNT" },
+ { "PKT_TC_2_CURR_BUF_CNT" },
+ { "PKT_TC_3_CURR_BUF_CNT" },
+ { "PKT_TC_4_CURR_BUF_CNT" },
+ { "PKT_TC_5_CURR_BUF_CNT" },
+ { "PKT_TC_6_CURR_BUF_CNT" },
+ { "PKT_TC_7_CURR_BUF_CNT" },
+};
+
+static const struct dfx_reg_name dfx_ssu_type_32_comm_stats[] = {
+ { "LO_PRI_UNICAST_CUR_CNT" },
+ { "HI_PRI_MULTICAST_CUR_CNT" },
+ { "LO_PRI_MULTICAST_CUR_CNT" },
+};
+
+static const struct dfx_reg_name dfx_ssu_type_32_comm_drop_stats[] = {
+ { "FULL_DROP_NUM" },
+ { "PART_DROP_NUM" },
+ { "PPP_KEY_DROP_NUM" },
+ { "PPP_RLT_DROP_NUM" },
+ { "MB_UNCOPY_NUM" },
+ { "LO_PRI_UNICAST_RLT_DROP_NUM" },
+ { "HI_PRI_MULTICAST_RLT_DROP_NUM" },
+ { "LO_PRI_MULTICAST_RLT_DROP_NUM" },
+ { "NIC_L2_ERR_DROP_PKT_CNT" },
+ { "ROC_L2_ERR_DROP_PKT_CNT" },
+ { "BANK_UNBALANCE_DROP_CNT" },
+ { "SSU_MB_RD_RLT_DROP_CNT" },
+ { "NCSI_FULL_DROP_NUM" },
+ { "NCSI_PART_DROP_NUM" },
+ { "NCSI_OQ_GLB_DROP_PKT_CNT_PORT" },
+ { "LO_MB_DROP_FOR_CNT_MEM_EMPTY" },
+ { "HI_MB_DROP_FOR_CNT_MEM_EMPTY" },
+ { "SSU_OVERSIZE_DROP_NUM" },
+};
+
+static const struct dfx_reg_name dfx_ssu_type_32_comm_err_stats[] = {
+ { "SSU_ECC_1BIT_ERR_CNT" },
+ { "SSU_ECC_MULTI_BIT_ERR_CNT" },
+};
+
+static const struct dfx_reg_name dfx_ssu_type_64_rx_port_drop_stats[] = {
+ { "RX_PACKET_IN_ERR_CNT" },
+ { "RX_PACKET_OUT_ERR_CNT" },
+};
+
+static const struct dfx_reg_name dfx_ssu_type_64_tx_port_drop_stats[] = {
+ { "TX_PACKET_IN_ERR_CNT" },
+ { "TX_PACKET_OUT_ERR_CNT" },
+};
+
+static const struct dfx_reg_name dfx_ssu_type_64_rx_port_normal_stats[] = {
+ { "RX_PKT_IN_CNT" },
+ { "RX_PACKET_OUT_CNT" },
+ { "RX_PKT_TC_0_IN_CNT" },
+ { "RX_PKT_TC_1_IN_CNT" },
+ { "RX_PKT_TC_2_IN_CNT" },
+ { "RX_PKT_TC_3_IN_CNT" },
+ { "RX_PKT_TC_4_IN_CNT" },
+ { "RX_PKT_TC_5_IN_CNT" },
+ { "RX_PKT_TC_6_IN_CNT" },
+ { "RX_PKT_TC_7_IN_CNT" },
+ { "RX_PACKET_TC_0_OUT_CNT" },
+ { "RX_PACKET_TC_1_OUT_CNT" },
+ { "RX_PACKET_TC_2_OUT_CNT" },
+ { "RX_PACKET_TC_3_OUT_CNT" },
+ { "RX_PACKET_TC_4_OUT_CNT" },
+ { "RX_PACKET_TC_5_OUT_CNT" },
+ { "RX_PACKET_TC_6_OUT_CNT" },
+ { "RX_PACKET_TC_7_OUT_CNT" },
+ { "ROC_RX_PACKET_IN_CNT" },
+};
+
+static const struct dfx_reg_name dfx_ssu_type_64_tx_port_normal_stats[] = {
+ { "TX_PKT_IN_CNT" },
+ { "TX_PKT_OUT_CNT" },
+ { "TX_PKT_TC_0_IN_CNT" },
+ { "TX_PKT_TC_1_IN_CNT" },
+ { "TX_PKT_TC_2_IN_CNT" },
+ { "TX_PKT_TC_3_IN_CNT" },
+ { "TX_PKT_TC_4_IN_CNT" },
+ { "TX_PKT_TC_5_IN_CNT" },
+ { "TX_PKT_TC_6_IN_CNT" },
+ { "TX_PKT_TC_7_IN_CNT" },
+ { "TX_PACKET_TC_0_OUT_CNT" },
+ { "TX_PACKET_TC_1_OUT_CNT" },
+ { "TX_PACKET_TC_2_OUT_CNT" },
+ { "TX_PACKET_TC_3_OUT_CNT" },
+ { "TX_PACKET_TC_4_OUT_CNT" },
+ { "TX_PACKET_TC_5_OUT_CNT" },
+ { "TX_PACKET_TC_6_OUT_CNT" },
+ { "TX_PACKET_TC_7_OUT_CNT" },
+ { "ROC_TX_PACKET_OUT_CNT" },
+};
+
+static const struct dfx_reg_name dfx_ssu_type_64_tx_comm_stats[] = {
+ { "SSU_PPP_MAC_KEY_NUM" },
+ { "SSU_PPP_HOST_KEY_NUM" },
+ { "PPP_SSU_MAC_RLT_NUM" },
+ { "PPP_SSU_HOST_RLT_NUM" },
+};
+
+static const struct dfx_type_name_parse g_dfx_ssu_name_parse[] = {
+ { TYPE_32_RX_DROP_STATS,
+ dfx_ssu_type_32_rx_drop_stats, HIKP_ARRAY_SIZE(dfx_ssu_type_32_rx_drop_stats)},
+ { TYPE_32_RX_NORMAL_STATS,
+ dfx_ssu_type_32_rx_normal_stats, HIKP_ARRAY_SIZE(dfx_ssu_type_32_rx_normal_stats)},
+ { TYPE_32_TX_DROP_STATS,
+ dfx_ssu_type_32_tx_drop_stats, HIKP_ARRAY_SIZE(dfx_ssu_type_32_tx_drop_stats)},
+ { TYPE_32_TX_NORMAL_STATS,
+ dfx_ssu_type_32_tx_normal_stats, HIKP_ARRAY_SIZE(dfx_ssu_type_32_tx_normal_stats)},
+ { TYPE_32_RX_PORT_DROP_STATS,
+ dfx_ssu_type_32_rx_port_drop_stats1, HIKP_ARRAY_SIZE(dfx_ssu_type_32_rx_port_drop_stats1)},
+ { TYPE_32_RX_PORT_DROP_STATS,
+ dfx_ssu_type_32_rx_port_drop_stats2, HIKP_ARRAY_SIZE(dfx_ssu_type_32_rx_port_drop_stats2)},
+ { TYPE_32_TX_PORT_DROP_STATS,
+ dfx_ssu_type_32_tx_port_drop_stats1, HIKP_ARRAY_SIZE(dfx_ssu_type_32_tx_port_drop_stats1)},
+ { TYPE_32_TX_PORT_DROP_STATS,
+ dfx_ssu_type_32_tx_port_drop_stats2, HIKP_ARRAY_SIZE(dfx_ssu_type_32_tx_port_drop_stats2)},
+ { TYPE_32_RUNNING_STATUS,
+ dfx_ssu_type_32_running_stats, HIKP_ARRAY_SIZE(dfx_ssu_type_32_running_stats)},
+ { TYPE_32_PORT_RUNNING_STATUS,
+ dfx_ssu_type_32_port_running_stats, HIKP_ARRAY_SIZE(dfx_ssu_type_32_port_running_stats)},
+ { TYPE_32_COMM_STATS,
+ dfx_ssu_type_32_comm_stats, HIKP_ARRAY_SIZE(dfx_ssu_type_32_comm_stats)},
+ { TYPE_32_COMM_DROP_STATS,
+ dfx_ssu_type_32_comm_drop_stats, HIKP_ARRAY_SIZE(dfx_ssu_type_32_comm_drop_stats)},
+ { TYPE_32_COMM_ERROR_STATS,
+ dfx_ssu_type_32_comm_err_stats, HIKP_ARRAY_SIZE(dfx_ssu_type_32_comm_err_stats)},
+ { TYPE_64_RX_PORT_DROP_STATS,
+ dfx_ssu_type_64_rx_port_drop_stats, HIKP_ARRAY_SIZE(dfx_ssu_type_64_rx_port_drop_stats)},
+ { TYPE_64_TX_PORT_DROP_STATS,
+ dfx_ssu_type_64_tx_port_drop_stats, HIKP_ARRAY_SIZE(dfx_ssu_type_64_tx_port_drop_stats)},
+ { TYPE_64_RX_PORT_NORMAL_STATS,
+ dfx_ssu_type_64_rx_port_normal_stats, HIKP_ARRAY_SIZE(dfx_ssu_type_64_rx_port_normal_stats)},
+ { TYPE_64_TX_PORT_NORMAL_STATS,
+ dfx_ssu_type_64_tx_port_normal_stats, HIKP_ARRAY_SIZE(dfx_ssu_type_64_tx_port_normal_stats)},
+ { TYPE_64_COMM_STATS,
+ dfx_ssu_type_64_tx_comm_stats, HIKP_ARRAY_SIZE(dfx_ssu_type_64_tx_comm_stats)},
+};
+
static void dfx_help_info(const struct major_cmd_ctrl *self)
{
printf("\n Usage: %s %s\n", self->cmd_ptr->name, "-i <interface>\n");
@@ -218,35 +541,96 @@ static int cmd_dfx_module_select(struct major_cmd_ctrl *self, const char *argv)
return -EINVAL;
}
-static void hikp_nic_dfx_print_b32(uint32_t num, uint32_t *reg_data)
+static const struct dfx_reg_name *hikp_nic_get_ssu_list(uint8_t type_id, uint32_t reg_num)
{
+ uint32_t i;
+
+ for (i = 0; i < HIKP_ARRAY_SIZE(g_dfx_ssu_name_parse); i++) {
+ if (g_dfx_ssu_name_parse[i].type_id != type_id)
+ continue;
+ if (reg_num != g_dfx_ssu_name_parse[i].reg_num)
+ continue;
+
+ return g_dfx_ssu_name_parse[i].reg_list;
+ }
+ return NULL;
+}
+
+static const struct dfx_reg_name *hikp_nic_get_ppp_list(uint8_t type_id, uint32_t reg_num)
+{
+ uint32_t i;
+
+ for (i = 0; i < HIKP_ARRAY_SIZE(g_dfx_ppp_name_parse); i++) {
+ if (g_dfx_ppp_name_parse[i].type_id != type_id)
+ continue;
+ if (reg_num != g_dfx_ppp_name_parse[i].reg_num)
+ continue;
+
+ return g_dfx_ppp_name_parse[i].reg_list;
+ }
+ return NULL;
+}
+
+static const struct dfx_reg_name *hikp_nic_dfx_get_reg_list(uint8_t type_id,
+ uint32_t sub_cmd_code,
+ uint32_t reg_num)
+{
+ if (sub_cmd_code == SSU_DFX_REG_DUMP)
+ return hikp_nic_get_ssu_list(type_id, reg_num);
+ else if (sub_cmd_code == PPP_DFX_REG_DUMP)
+ return hikp_nic_get_ppp_list(type_id, reg_num);
+ return NULL;
+}
+
+static void hikp_nic_dfx_print_b32(struct nic_dfx_type_head *type_head, uint32_t *reg_data)
+{
+ uint32_t num = (uint32_t)type_head->reg_num;
uint32_t word_num = num * WORD_NUM_PER_REG;
+ const struct dfx_reg_name *reg_list;
+ uint32_t sub_cmd_code;
uint16_t offset;
uint32_t value;
uint32_t index;
uint32_t i;
+ sub_cmd_code = g_dfx_module_parse[g_dfx_param.module_idx].sub_cmd_code;
+ reg_list = hikp_nic_dfx_get_reg_list(type_head->type_id, sub_cmd_code, num);
for (i = 0, index = 1; i < word_num; i = i + WORD_NUM_PER_REG, index++) {
offset = (uint16_t)HI_GET_BITFIELD(reg_data[i], 0, DFX_REG_ADDR_MASK);
value = reg_data[i + 1];
- printf("%03u: 0x%04x\t0x%08x\n", index, offset, value);
+ if (reg_list != NULL) {
+ printf("%-30s\t0x%04x\t0x%08x\n", reg_list->name, offset, value);
+ reg_list++;
+ } else {
+ printf("%-30s\t0x%04x\t0x%08x\n", "", offset, value);
+ }
}
}
-static void hikp_nic_dfx_print_b64(uint32_t num, uint32_t *reg_data)
+static void hikp_nic_dfx_print_b64(struct nic_dfx_type_head *type_head, uint32_t *reg_data)
{
+ uint32_t num = (uint32_t)type_head->reg_num;
uint32_t word_num = num * WORD_NUM_PER_REG;
+ const struct dfx_reg_name *reg_list;
+ uint32_t sub_cmd_code;
uint16_t offset;
uint64_t value;
uint32_t index;
uint32_t i;
+ sub_cmd_code = g_dfx_module_parse[g_dfx_param.module_idx].sub_cmd_code;
+ reg_list = hikp_nic_dfx_get_reg_list(type_head->type_id, sub_cmd_code, num);
for (i = 0, index = 1; i < word_num; i = i + WORD_NUM_PER_REG, index++) {
offset = (uint16_t)HI_GET_BITFIELD(reg_data[i], 0, DFX_REG_ADDR_MASK);
value = (uint64_t)reg_data[i + 1] |
(HI_GET_BITFIELD((uint64_t)reg_data[i], DFX_REG_VALUE_OFF,
DFX_REG_VALUE_MASK) << BIT_NUM_OF_WORD);
- printf("%03u: 0x%04x\t0x%016lx\n", index, offset, value);
+ if (reg_list != NULL) {
+ printf("%-30s\t0x%04x\t0x%016lx\n", reg_list->name, offset, value);
+ reg_list++;
+ } else {
+ printf("%-30s\t0x%04x\t0x%08x\n", "", offset, value);
+ }
}
}
@@ -287,6 +671,7 @@ static void hikp_nic_dfx_print(const struct nic_dfx_rsp_head_t *rsp_head, uint32
uint32_t *ptr = reg_data;
uint32_t max_size;
uint32_t num_u32;
+ bool show_title;
uint8_t i;
max_size = dfx_get_max_reg_bffer_size(rsp_head);
@@ -310,12 +695,15 @@ static void hikp_nic_dfx_print(const struct nic_dfx_rsp_head_t *rsp_head, uint32
HIKP_ERROR_PRINT("No.%u type is incorrect reg type\n", i + 1u);
break;
}
+ show_title = type_head->type_id != last_type_id;
hikp_nic_dfx_print_type_head(type_head->type_id, &last_type_id);
ptr++;
+ if (show_title)
+ printf("%-30s\t%s\t%s\n", "name", "offset", "value");
if (type_head->bit_width == WIDTH_32_BIT) {
- hikp_nic_dfx_print_b32((uint32_t)type_head->reg_num, ptr);
+ hikp_nic_dfx_print_b32(type_head, ptr);
} else if (type_head->bit_width == WIDTH_64_BIT) {
- hikp_nic_dfx_print_b64((uint32_t)type_head->reg_num, ptr);
+ hikp_nic_dfx_print_b64(type_head, ptr);
} else {
HIKP_ERROR_PRINT("type%u's bit width error.\n", type_head->type_id);
break;
diff --git a/net/nic/nic_dfx/hikp_nic_dfx.h b/net/nic/nic_dfx/hikp_nic_dfx.h
index d46d290..38f76aa 100644
--- a/net/nic/nic_dfx/hikp_nic_dfx.h
+++ b/net/nic/nic_dfx/hikp_nic_dfx.h
@@ -138,4 +138,15 @@ struct nic_dfx_rsp_t {
uint32_t reg_data[MAX_DFX_DATA_NUM];
};
+#define MAX_REG_NAME_LEN 64
+struct dfx_reg_name {
+ const char name[MAX_REG_NAME_LEN];
+};
+
+struct dfx_type_name_parse {
+ uint8_t type_id;
+ const struct dfx_reg_name *reg_list;
+ uint32_t reg_num;
+};
+
#endif /* HIKP_NIC_DFX_H */
--
2.45.0.windows.1

View File

@ -0,0 +1,54 @@
From 2aa68f56a13a74d4398f1cb51c67747a04e84146 Mon Sep 17 00:00:00 2001
From: Bingquan Mou <moubingquan@huawei.com>
Date: Mon, 30 Sep 2024 10:02:39 +0800
Subject: [PATCH 23/27] hikptool: Added the dfx register for PCIe dump.
category: feature
bugzilla: NA
CVE: NA
This register is added for PCIe dump.
MAC: MAC_REG_PHY_RXDATA_TS_REG/MAC_LTSSM_TRACER_CFG0_REG/MAC_POWERDOWN_VALUE_REG
PCS: DETECT_CLK_FLG_REG/SDS_CFG_REG_REG
GLB: PCIE_LINK_DOWN_CLR_PORT_EN_REG/CORE_CLK_FLG_REG
Signed-off-by: Bingquan Mou <moubingquan@huawei.com>
---
pcie/func_lib/pcie_func/pcie_reg_dump.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/pcie/func_lib/pcie_func/pcie_reg_dump.c b/pcie/func_lib/pcie_func/pcie_reg_dump.c
index 9444f64..abf0e26 100644
--- a/pcie/func_lib/pcie_func/pcie_reg_dump.c
+++ b/pcie/func_lib/pcie_func/pcie_reg_dump.c
@@ -129,6 +129,9 @@ struct pcie_dumpreg_info g_reg_table_mac[] = {
{0, "MAC_LEAVE_L0_INFO"},
{0, "DFX_APB_LANE_ERROR_STATUS_0"},
{0, "DFX_APB_LANE_ERROR_STATUS_1"},
+ {0, "MAC_REG_PHY_RXDATA_TS_REG"},
+ {0, "MAC_LTSSM_TRACER_CFG0_REG"},
+ {0, "MAC_POWERDOWN_VALUE_REG"},
};
struct pcie_dumpreg_info g_reg_table_pcs[] = {
@@ -141,6 +144,8 @@ struct pcie_dumpreg_info g_reg_table_pcs[] = {
HIKP_PCIE_PCS_LANE_TBL_ENTRY(LANE_INTR_STATUS),
HIKP_PCIE_PCS_LANE_TBL_ENTRY(M_PCS_RPT_REG),
HIKP_PCIE_PCS_LANE_TBL_ENTRY(MSG_BUS_DFX),
+ HIKP_PCIE_PCS_LANE_TBL_ENTRY(DETECT_CLK_FLG_REG),
+ HIKP_PCIE_PCS_LANE_TBL_ENTRY(SDS_CFG_REG_REG),
};
struct pcie_dumpreg_info g_reg_table_iob_tx[] = {
@@ -364,6 +369,8 @@ struct pcie_dumpreg_info g_reg_table_core_glb[] = {
{0, "CORE_INT_FE_RO_2"},
{0, "PORT07_LINK_MODE"},
{0, "PORT815_LINK_MODE"},
+ {0, "PCIE_LINK_DOWN_CLR_PORT_EN_REG"},
+ {0, "CORE_CLK_FLG_REG"},
};
struct pcie_dumpreg_info g_reg_table_core_tl[] = {
--
2.45.0.windows.1

View File

@ -0,0 +1,62 @@
From f8edb8f7f8882aaa68b24d7bb37659f2589c90ca Mon Sep 17 00:00:00 2001
From: Bingquan Mou <moubingquan@huawei.com>
Date: Sat, 12 Oct 2024 17:11:38 +0800
Subject: [PATCH 24/27] hikptool: The macro_num error is rectified, and the
offset writing is incorrect.
category: feature
bugzilla: NA
CVE: NA
1.It is reasonable that core0 has three macros. Therefore, macro_num == 3 is reasonable.
2.The offset writing is incorrect.
Signed-off-by: Bingquan Mou <moubingquan@huawei.com>
---
pcie/func_lib/pcie_func/pcie_link_ltssm.c | 2 +-
pcie/func_lib/pcie_func/pcie_link_ltssm.h | 2 +-
pcie/func_lib/pcie_func/pcie_statistics.c | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/pcie/func_lib/pcie_func/pcie_link_ltssm.c b/pcie/func_lib/pcie_func/pcie_link_ltssm.c
index 1bc2edb..d3534f5 100644
--- a/pcie/func_lib/pcie_func/pcie_link_ltssm.c
+++ b/pcie/func_lib/pcie_func/pcie_link_ltssm.c
@@ -211,7 +211,7 @@ static int pcie_print_ltssm_trace(const uint64_t *ltssm_input, uint32_t ltssm_nu
(uint32_t)ltssm_val.bits.any_change_pipe_req,
(uint32_t)ltssm_val.bits.rxl0s_st,
(uint32_t)ltssm_val.bits.train_bit_map1,
- (((uint32_t)ltssm_val.bits.rxl0s_st) << GEN5_BIT_OFFEST) |
+ (((uint32_t)ltssm_val.bits.rxl0s_st) << GEN5_BIT_OFFSET) |
((uint32_t)ltssm_val.bits.mac_rate),
(uint32_t)ltssm_val.bits.duration_counter,
(uint32_t)ltssm_val.bits.ltssm_state,
diff --git a/pcie/func_lib/pcie_func/pcie_link_ltssm.h b/pcie/func_lib/pcie_func/pcie_link_ltssm.h
index 9986f7a..278f3e4 100644
--- a/pcie/func_lib/pcie_func/pcie_link_ltssm.h
+++ b/pcie/func_lib/pcie_func/pcie_link_ltssm.h
@@ -19,7 +19,7 @@
#define TRACE_STR_NUM 0x20
#define TRACER_DEPTH 65
#define PM_TRACE_STR_NUM 0x28
-#define GEN5_BIT_OFFEST 2
+#define GEN5_BIT_OFFSET 2
struct pcie_ltssm_num_string {
int ltssm;
diff --git a/pcie/func_lib/pcie_func/pcie_statistics.c b/pcie/func_lib/pcie_func/pcie_statistics.c
index 54d4edb..be187f2 100644
--- a/pcie/func_lib/pcie_func/pcie_statistics.c
+++ b/pcie/func_lib/pcie_func/pcie_statistics.c
@@ -70,7 +70,7 @@ static int pcie_portid_serdes_relation(const struct pcie_macro_info *macro_info,
return -1;
}
- if (macro_num >= MAX_MACRO_ONEPORT) {
+ if (macro_num > MAX_MACRO_ONEPORT) {
Info("macro_num [%u] exceeds the maximum array length\n", macro_num);
return -1;
}
--
2.45.0.windows.1

View File

@ -0,0 +1,185 @@
From 261fdd1cc832989c60b3940cd8b2aa6593bc94ea Mon Sep 17 00:00:00 2001
From: Yuyu Li <liyuyu6@huawei.com>
Date: Tue, 12 Nov 2024 20:17:06 +0800
Subject: [PATCH 25/27] Fix the logic of obtaining statistics on flow control
storm suppression
Previously, regardless of the direction specified by -d, FW would return the statistics
of flow control storm suppression in both directions. Now it only returns the statistic
in the specified direction. An example is shown:
hikptool nic_qos -i eth6 -g pfc_storm_para -d rx
before:
PFC STORM Information:
direction: rx
enabled: on
period: 2000ms
pfc threshold: 1000ms
recovery period: 500ms
rx storm suppression count: 14
after:
PFC STORM Information:
direction: rx
enabled: on
period: 2000ms
pfc threshold: 1000ms
recovery period: 500ms
storm count: 14
Signed-off-by: Yuyu Li <liyuyu6@huawei.com>
---
net/nic/nic_qos/hikp_nic_qos.c | 32 ++++++++++++++++++++++----------
net/nic/nic_qos/hikp_nic_qos.h | 14 +++++++++-----
2 files changed, 31 insertions(+), 15 deletions(-)
diff --git a/net/nic/nic_qos/hikp_nic_qos.c b/net/nic/nic_qos/hikp_nic_qos.c
index 81eb0ba..32f251e 100644
--- a/net/nic/nic_qos/hikp_nic_qos.c
+++ b/net/nic/nic_qos/hikp_nic_qos.c
@@ -56,7 +56,8 @@ static int hikp_nic_qos_cmd_help(struct major_cmd_ctrl *self, const char *argv)
static void hikp_nic_qos_show_pkt_buf(const void *data)
{
- struct nic_pkt_buf_info *pkt_buf = (struct nic_pkt_buf_info *)data;
+ struct qos_cmd_info *qos_info_pkt = (struct qos_cmd_info *)data;
+ struct nic_pkt_buf_info *pkt_buf = (struct nic_pkt_buf_info *)&qos_info_pkt->info;
struct nic_shared_buf *share_buf = &pkt_buf->share_buf;
struct nic_priv_buf *priv_buf = pkt_buf->priv_buf;
uint16_t tc_no;
@@ -88,11 +89,12 @@ static void hikp_nic_qos_show_pkt_buf(const void *data)
static void hikp_nic_qos_show_dcb_info(const void *data)
{
- struct nic_dcb_info *dcb = (struct nic_dcb_info *)data;
+ struct qos_cmd_info *qos_info_dcb = (struct qos_cmd_info *)data;
+ struct nic_dcb_info *dcb = (struct nic_dcb_info *)&qos_info_dcb->info;
struct nic_pfc_info *pfc = &dcb->pfc;
struct nic_ets_info *ets = &dcb->ets;
- uint16_t up;
uint16_t tc_no;
+ uint16_t up;
printf("PFC configuration\n");
printf(" PFC enable:");
@@ -125,7 +127,8 @@ static void hikp_nic_qos_show_dcb_info(const void *data)
static void hikp_nic_qos_show_pause_info(const void *data)
{
- struct nic_pause_info *pause = (struct nic_pause_info *)data;
+ struct qos_cmd_info *qos_info_pause = (struct qos_cmd_info *)data;
+ struct nic_pause_info *pause = (struct nic_pause_info *)&qos_info_pause->info;
printf("PAUSE Information\n");
if (pause->type == HIKP_NONE_PAUSE)
@@ -143,8 +146,10 @@ static void hikp_nic_qos_show_pause_info(const void *data)
static void hikp_nic_qos_show_pfc_storm_para(const void *data)
{
+ struct qos_cmd_info *qos_info_pfc = (struct qos_cmd_info *)data;
struct nic_pfc_storm_para *pfc_storm_para =
- (struct nic_pfc_storm_para *)data;
+ (struct nic_pfc_storm_para *)&qos_info_pfc->info;
+ uint32_t length = qos_info_pfc->length;
printf("PFC STORM Information:\n");
printf("direction: %s\n", pfc_storm_para->dir ? "tx" : "rx");
@@ -155,6 +160,11 @@ static void hikp_nic_qos_show_pfc_storm_para(const void *data)
printf("check times: %u\n", pfc_storm_para->times) :
printf("pfc threshold: %ums\n", pfc_storm_para->times);
printf("recovery period: %ums\n", pfc_storm_para->recovery_period_ms);
+
+ if (length < sizeof(struct nic_pfc_storm_para))
+ return;
+
+ printf("storm count: %u\n", pfc_storm_para->storm_count);
}
static int hikp_nic_qos_get_blk(struct hikp_cmd_header *req_header,
@@ -192,11 +202,11 @@ out:
}
static int hikp_nic_query_qos_feature(struct hikp_cmd_header *req_header, const struct bdf_t *bdf,
- union nic_qos_feature_info *data)
+ struct qos_cmd_info *qcmd_info)
{
+ size_t buf_len = sizeof(qcmd_info->info);
struct nic_qos_rsp_head rsp_head = {0};
struct nic_qos_req_para req_data;
- size_t buf_len = sizeof(*data);
uint32_t total_blk_size;
uint8_t total_blk_num;
uint8_t blk_id = 0;
@@ -207,7 +217,7 @@ static int hikp_nic_query_qos_feature(struct hikp_cmd_header *req_header, const
req_data.block_id = blk_id;
req_data.dir = g_qos_param.dir;
- ret = hikp_nic_qos_get_blk(req_header, &req_data, data, buf_len, &rsp_head);
+ ret = hikp_nic_qos_get_blk(req_header, &req_data, &qcmd_info->info, buf_len, &rsp_head);
if (ret != 0)
return ret;
@@ -220,13 +230,15 @@ static int hikp_nic_query_qos_feature(struct hikp_cmd_header *req_header, const
req_data.dir = g_qos_param.dir;
ret = hikp_nic_qos_get_blk(req_header, &req_data,
- (uint8_t *)data + total_blk_size,
+ (uint8_t *)&qcmd_info->info + total_blk_size,
buf_len - total_blk_size, &rsp_head);
if (ret != 0)
return ret;
total_blk_size += rsp_head.cur_blk_size;
}
+ qcmd_info->length = total_blk_size;
+
return ret;
}
@@ -234,9 +246,9 @@ static void hikp_nic_qos_cmd_execute(struct major_cmd_ctrl *self)
{
char *revision_id = g_qos_param.revision_id;
struct bdf_t *bdf = &g_qos_param.target.bdf;
- union nic_qos_feature_info qos_data = {0};
struct hikp_cmd_header req_header = {0};
const struct qos_feature_cmd *qos_cmd;
+ struct qos_cmd_info qos_data = {0};
int ret;
if (bdf->dev_id != 0) {
diff --git a/net/nic/nic_qos/hikp_nic_qos.h b/net/nic/nic_qos/hikp_nic_qos.h
index d55970a..77fbdd9 100644
--- a/net/nic/nic_qos/hikp_nic_qos.h
+++ b/net/nic/nic_qos/hikp_nic_qos.h
@@ -57,6 +57,7 @@ struct nic_pfc_storm_para {
uint32_t period_ms;
uint32_t times;
uint32_t recovery_period_ms;
+ uint32_t storm_count;
};
struct nic_ets_info {
@@ -87,11 +88,14 @@ struct nic_pause_info {
uint16_t rsv;
};
-union nic_qos_feature_info {
- struct nic_pkt_buf_info pkt_buf;
- struct nic_dcb_info dcb;
- struct nic_pause_info pause;
- struct nic_pfc_storm_para pfc_storm_para;
+struct qos_cmd_info {
+ uint32_t length;
+ union nic_qos_feature_info {
+ struct nic_pkt_buf_info pkt_buf;
+ struct nic_dcb_info dcb;
+ struct nic_pause_info pause;
+ struct nic_pfc_storm_para pfc_storm_para;
+ } info;
};
struct nic_qos_rsp_head {
--
2.45.0.windows.1

View File

@ -0,0 +1,102 @@
From de71b27c71022e1051b1c3e85f849aedb13ec644 Mon Sep 17 00:00:00 2001
From: veega2022 <zhuweijia@huawei.com>
Date: Thu, 24 Oct 2024 20:52:48 +0800
Subject: [PATCH 26/27] hikptool: Rectify the compilation alarm.
Replace -Wextra with -Werror option.
Signed-off-by: veega2022 <zhuweijia@huawei.com>
---
CMakeLists.txt | 2 +-
net/hikp_net_lib.c | 3 ++-
net/nic/nic_dfx/hikp_nic_dfx.c | 5 +++--
net/nic/nic_ft/hikp_nic_port_fault.c | 2 +-
net/nic/nic_qos/hikp_nic_qos.c | 7 ++++---
5 files changed, 11 insertions(+), 8 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f2ffe6c..4fb82ca 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -11,7 +11,7 @@
project(hikptool C)
-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 -fPIC -fPIE -Wall -Wextra -fno-common -std=gnu11")
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 -fPIC -fPIE -Wall -Werror -fno-common -std=gnu11")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wfloat-equal -fstack-protector-strong -D_FORTIFY_SOURCE=2")
set(CMAKE_SKIP_RPATH TRUE)
diff --git a/net/hikp_net_lib.c b/net/hikp_net_lib.c
index fbf03bd..f4d4c2a 100644
--- a/net/hikp_net_lib.c
+++ b/net/hikp_net_lib.c
@@ -142,7 +142,8 @@ static bool check_dev_name_and_get_bdf(int sockfd, struct tool_target *target)
ifr.ifr_data = (char *)&drvinfo;
drvinfo.cmd = ETHTOOL_GDRVINFO;
- strncpy(ifr.ifr_name, target->dev_name, IFNAMSIZ - 1);
+ strncpy(ifr.ifr_name, target->dev_name, IFNAMSIZ);
+ ifr.ifr_name[IFNAMSIZ - 1] = '\0';
if (ioctl(sockfd, SIOCETHTOOL, &ifr) < 0)
return false;
diff --git a/net/nic/nic_dfx/hikp_nic_dfx.c b/net/nic/nic_dfx/hikp_nic_dfx.c
index 67a5fe1..c42b8e7 100644
--- a/net/nic/nic_dfx/hikp_nic_dfx.c
+++ b/net/nic/nic_dfx/hikp_nic_dfx.c
@@ -17,6 +17,7 @@
#include <sys/types.h>
#include <ifaddrs.h>
#include <unistd.h>
+#include <inttypes.h>
#include "tool_cmd.h"
#include "hikp_net_lib.h"
#include "hikp_nic_dfx.h"
@@ -626,10 +627,10 @@ static void hikp_nic_dfx_print_b64(struct nic_dfx_type_head *type_head, uint32_t
(HI_GET_BITFIELD((uint64_t)reg_data[i], DFX_REG_VALUE_OFF,
DFX_REG_VALUE_MASK) << BIT_NUM_OF_WORD);
if (reg_list != NULL) {
- printf("%-30s\t0x%04x\t0x%016lx\n", reg_list->name, offset, value);
+ printf("%-30s\t0x%04x\t0x%" PRIx64 "\n", reg_list->name, offset, value);
reg_list++;
} else {
- printf("%-30s\t0x%04x\t0x%08x\n", "", offset, value);
+ printf("%-30s\t0x%04x\t0x%" PRIx64 "\n", "", offset, value);
}
}
}
diff --git a/net/nic/nic_ft/hikp_nic_port_fault.c b/net/nic/nic_ft/hikp_nic_port_fault.c
index 6561e3e..5f78cdd 100644
--- a/net/nic/nic_ft/hikp_nic_port_fault.c
+++ b/net/nic/nic_ft/hikp_nic_port_fault.c
@@ -41,7 +41,7 @@ static int hikp_nic_port_fault_query(const struct bdf_t *bdf,
}
rsp = (struct nic_port_fault_rsp *)cmd_ret->rsp_data;
- *info = *(struct nic_port_fault_status *)rsp->data;
+ memcpy(info, rsp->data, sizeof(struct nic_port_fault_status));
hikp_cmd_free(&cmd_ret);
return 0;
diff --git a/net/nic/nic_qos/hikp_nic_qos.c b/net/nic/nic_qos/hikp_nic_qos.c
index 32f251e..c620a08 100644
--- a/net/nic/nic_qos/hikp_nic_qos.c
+++ b/net/nic/nic_qos/hikp_nic_qos.c
@@ -286,9 +286,10 @@ static void hikp_nic_qos_cmd_execute(struct major_cmd_ctrl *self)
memset(revision_id, 0, MAX_PCI_ID_LEN + 1);
ret = get_revision_id_by_bdf(bdf, revision_id, sizeof(g_qos_param.revision_id));
// show pfc threshold as default if get revision_id error
- if (ret)
- strncpy(g_qos_param.revision_id, HIKP_IEP_REVISION,
- MAX_PCI_REVISION_LEN);
+ if (ret) {
+ strncpy(g_qos_param.revision_id, HIKP_IEP_REVISION, MAX_PCI_REVISION_LEN);
+ g_qos_param.revision_id[MAX_PCI_ID_LEN] = '\0';
+ }
printf("############## NIC QOS: %s info ############\n", qos_cmd->feature_name);
qos_cmd->show(&qos_data);
--
2.45.0.windows.1

View File

@ -0,0 +1,28 @@
From 43577e52be8f24eff1eab81d6474f0b66edc6a21 Mon Sep 17 00:00:00 2001
From: veega2022 <zhuweijia@huawei.com>
Date: Tue, 12 Nov 2024 20:28:55 +0800
Subject: [PATCH 27/27] hikptool: Update the tool version number to 1.1.3
Update the tool version number to 1.1.3
Signed-off-by: veega2022 <zhuweijia@huawei.com>
---
tool_lib/tool_lib.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tool_lib/tool_lib.h b/tool_lib/tool_lib.h
index 15dac74..34cc3e8 100644
--- a/tool_lib/tool_lib.h
+++ b/tool_lib/tool_lib.h
@@ -18,7 +18,7 @@
#define TOOL_NAME "hikptool"
-#define TOOL_VER "1.1.2"
+#define TOOL_VER "1.1.3"
#define HI_GET_BITFIELD(value, start, mask) (((value) >> (start)) & (mask))
#define HI_SET_FIELD(origin, shift, val) ((origin) |= (val) << (shift))
--
2.45.0.windows.1

View File

@ -3,7 +3,7 @@
Name: hikptool
Summary: A userspace tool for Linux providing problem location on Kunpeng chips
Version: 1.0.0
Release: 15
Release: 16
License: MulanPSL2
Source: %{name}-%{version}.tar.gz
ExclusiveOS: linux
@ -78,6 +78,33 @@ Patch0059: 0059-hikptool-fix-cleancode-codecheck-alarm.patch
Patch0060: 0060-hikptool-Delete-meaningless-printing.patch
Patch0061: 0061-hikptool-Update-the-tool-version-number-to-1.1.1.patch
Patch0062: 0062-hikptool-The-ecam-register-is-added-to-the-PCIe-dump.patch
Patch0063: 0063-hikptool-roce-Print-names-of-registers-for-gmv-mdb-p.patch
Patch0064: 0064-hikptool-roce-Support-exposing-names-of-extend-regis.patch
Patch0065: 0065-hikptool-roce-Fix-the-validation-check-of-cur_block_.patch
Patch0066: 0066-hikptool-roce-Fix-redundant-update-of-total_block_nu.patch
Patch0067: 0067-hikptool-roce-Add-check-for-total_block_num-from-FW.patch
Patch0068: 0068-hikptool-Resolve-the-review-problems-found-in-the-R-.patch
Patch0069: 0069-hikptool-Support-static-compilation-for-hikptool.patch
Patch0070: 0070-hikptool-nic-Fix-the-Code-review-comments.patch
Patch0071: 0071-hikptool-nic-add-check-for-the-value-from-FW.patch
Patch0072: 0072-hikptool-nic-Fix-the-Code-review-comments-in-NIC-mod.patch
Patch0073: 0073-hikptool-nic-return-real-errno-if-realpath-failed-in.patch
Patch0074: 0074-hikptool-nic-return-real-cmd-status-if-alloc-failed-.patch
Patch0075: 0075-hikptool-nic-check-path-before-used-it-in-function-h.patch
Patch0076: 0076-hikptool-nic-check-strtol-if-it-failed-in-get_numvfs.patch
Patch0077: 0077-hikptool-nic-adding-NUL-at-the-end-of-the-buffer-len.patch
Patch0078: 0078-hikptool-nic-avoid-array-boundary-exceeded-in-hikp_n.patch
Patch0079: 0079-hikptool-nic-Fix-bad-usage-of-format-string.patch
Patch0080: 0080-hikptool-nic-Fix-potential-dead-loop.patch
Patch0081: 0081-hikptool-Rectify-the-cleancode-issue.patch
Patch0082: 0082-hikptool-Modify-the-macro-definition-of-the-header-f.patch
Patch0083: 0083-hikptool-The-memory-release-interface-is-added.patch
Patch0084: 0084-hikptool-nic-Dump-register-names-for-SSU-and-PPP-mod.patch
Patch0085: 0085-hikptool-Added-the-dfx-register-for-PCIe-dump.patch
Patch0086: 0086-hikptool-The-macro_num-error-is-rectified-and-the-of.patch
Patch0087: 0087-Fix-the-logic-of-obtaining-statistics-on-flow-contro.patch
Patch0088: 0088-hikptool-Rectify-the-compilation-alarm.patch
Patch0089: 0089-hikptool-Update-the-tool-version-number-to-1.1.3.patch
%description
This package contains the hikptool
@ -130,6 +157,9 @@ fi
/sbin/ldconfig
%changelog
* Thu Nov 21 2024 veega2022 <zhuweijia@huawei.com> 1.0.0-16
- Synchronize code, Modify the review comments to increase the reliability of the code
* Thu May 23 2024 veega2022 <zhuweijia@huawei.com> 1.0.0-15
- Synchronize code, the DFX register of the ECAM is added when the PCIe dumps registers