From: veega2022 zhuweijia@huawei.com
Return -EINVAL when the parameter check fails
Signed-off-by: fangjian f.fangjian@huawei.com --- socip/hikp_socip_dumpreg.c | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/socip/hikp_socip_dumpreg.c b/socip/hikp_socip_dumpreg.c index 088f5dd..b74dac8 100644 --- a/socip/hikp_socip_dumpreg.c +++ b/socip/hikp_socip_dumpreg.c @@ -131,6 +131,7 @@ static void hikp_socip_dumpreg_execute(struct major_cmd_ctrl *self) struct hikp_cmd_ret *cmd_ret;
if (!check_socip_dumpreg_param()) { + self->err_no = -EINVAL; cmd_socip_dump_help(self, NULL); return; } @@ -141,6 +142,7 @@ static void hikp_socip_dumpreg_execute(struct major_cmd_ctrl *self) hikp_cmd_init(&req_header, SOCIP_MOD, HIKP_SOCIP_CMD_DUMPREG, param[MODULE_ID_INDEX].val); cmd_ret = hikp_cmd_alloc(&req_header, &req_data, sizeof(req_data)); if (!cmd_ret) { + self->err_no=-EINVAL; HIKP_ERROR_PRINT("hikp_cmd_alloc\n"); return; }
From: veega2022 zhuweijia@huawei.com
add compiler option -pie -fPIE, -Wl,-z,relro,-z,now and disable rpath
Signed-off-by: veega2022 zhuweijia@huawei.com --- CMakeLists.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d79a31..c697edf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,9 @@
project(hikptool C)
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O2 -pie -fPIE -Wall") +set(CMAKE_SKIP_RPATH TRUE) + macro(get_header_dir_recurse HEADER_DIR_LIST) file(GLOB_RECURSE HEADER_LIST *.h) set(DIR_LIST "") @@ -40,5 +43,7 @@ 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) -target_link_options(hikptool PRIVATE -g -lpthread -ldl -lm -lrt -T ${CMAKE_CURRENT_SOURCE_DIR}/hikp_register.ld) +target_link_options(hikptool PRIVATE + -Wl,-z,relro,-z,now -Wl,-z,noexecstack + -g -lpthread -ldl -lm -lrt -T ${CMAKE_CURRENT_SOURCE_DIR}/hikp_register.ld) install(TARGETS hikptool RUNTIME DESTINATION bin OPTIONAL)
From: veega2022 zhuweijia@huawei.com
add link options "-fPIE -pie", because the -T link is used, the pie becomes invalid.Therefore,change the ld file PROVIDE address to 0.
Signed-off-by: veega2022 zhuweijia@huawei.com --- CMakeLists.txt | 4 ++-- hikp_register.ld | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt index 0ba7370..6a396e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@
project(hikptool C)
-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O2 -pie -fPIE -Wall") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O2 -fPIC -fPIE -Wall") set(CMAKE_SKIP_RPATH TRUE)
macro(get_header_dir_recurse HEADER_DIR_LIST) @@ -44,6 +44,6 @@ target_include_directories(hikptool PRIVATE ${HIKPTOOL_HEADER_DIR}) target_link_directories(hikptool PRIVATE ${CMAKE_INSTALL_PREFIX}/lib) target_link_libraries(hikptool PRIVATE KPTDEV_SO) target_link_options(hikptool PRIVATE - -Wl,-z,relro,-z,now -Wl,-z,noexecstack + -Wl,-z,relro,-z,now -Wl,-z,noexecstack -fPIE -pie -g -lpthread -ldl -lm -lrt -T ${CMAKE_CURRENT_SOURCE_DIR}/hikp_register.ld) install(TARGETS hikptool RUNTIME DESTINATION bin OPTIONAL) diff --git a/hikp_register.ld b/hikp_register.ld index b1bec44..3bd44ff 100644 --- a/hikp_register.ld +++ b/hikp_register.ld @@ -11,7 +11,7 @@ SEARCH_DIR("=/usr/aarch64-Huawei-linux/lib64"); SEARCH_DIR("=/usr/lib64"); SEARC SECTIONS { /* Read-only sections, merged into text segment: */ - PROVIDE (__executable_start = SEGMENT_START("text-segment", 0x400000)); . = SEGMENT_START("text-segment", 0x400000) + SIZEOF_HEADERS; + PROVIDE (__executable_start = SEGMENT_START("text-segment", 0x0)); . = SEGMENT_START("text-segment", 0x0) + SIZEOF_HEADERS; .interp : { *(.interp) } .note.gnu.build-id : { *(.note.gnu.build-id) } .hash : { *(.hash) }
From: veega2022 zhuweijia@huawei.com
the volatile modifier is added because the O2 compilation optimization is enbaled. As a result, the pointer data is not updated.
Signed-off-by: veega2022 zhuweijia@huawei.com --- sas/sas_func/sas_read_dev.c | 2 +- tool_lib/tool_lib.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/sas/sas_func/sas_read_dev.c b/sas/sas_func/sas_read_dev.c index 382a1ef..d01f95f 100644 --- a/sas/sas_func/sas_read_dev.c +++ b/sas/sas_func/sas_read_dev.c @@ -77,7 +77,7 @@ static void print_dev_link(const uint32_t *reg_save, uint32_t reg_num)
static void print_dev_info(const void *reg_save, uint32_t reg_num) { - struct hikp_sas_itct *itct = (struct hikp_sas_itct *)reg_save; + volatile struct hikp_sas_itct *itct = (volatile struct hikp_sas_itct *)reg_save;
printf("The device information as below:\n"); printf("dev_type: %d\n", itct->dw0.dev_type); diff --git a/tool_lib/tool_lib.h b/tool_lib/tool_lib.h index 29e7e8c..b211175 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.0.12" +#define TOOL_VER "1.0.13"
#define HI_GET_BITFIELD(value, start, mask) (((value) >> (start)) & (mask)) #define HI_SET_FIELD(origin, shift, val) ((origin) |= (val) << (shift))
From: veega2022 zhuweijia@huawei.com
union hikp_space_rsp 0xF8h is reserved and 0xFCh is cpl_status
Signed-off-by: hesiyuan hesiyuan4@huawei.com --- libhikptdev/src/rciep/hikpt_rciep.c | 2 +- libhikptdev/src/rciep/hikpt_rciep.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/libhikptdev/src/rciep/hikpt_rciep.c b/libhikptdev/src/rciep/hikpt_rciep.c index 9b7a82a..5c7e82f 100644 --- a/libhikptdev/src/rciep/hikpt_rciep.c +++ b/libhikptdev/src/rciep/hikpt_rciep.c @@ -97,7 +97,7 @@ static uint32_t hikp_wait_for_cpl_status(void) uint32_t status;
do { - status = g_hikp_req->field.cpl_status; + status = g_hikp_rsp->field.cpl_status; if (status != HIKP_INIT_STAT) return status; count--; diff --git a/libhikptdev/src/rciep/hikpt_rciep.h b/libhikptdev/src/rciep/hikpt_rciep.h index 093724a..8fbb3c0 100644 --- a/libhikptdev/src/rciep/hikpt_rciep.h +++ b/libhikptdev/src/rciep/hikpt_rciep.h @@ -75,8 +75,8 @@ union hikp_space_rsp { uint32_t version; /* 000h */ uint32_t rsp_para_num; /* 004h */ uint32_t data[HIKP_RSP_DATA_MAX]; /* 008h */ - uint32_t cpl_status; /* 0F8h */ - uint32_t pid_record; /* 0FCh */ + uint32_t rsv; /* 0F8h */ + uint32_t cpl_status; /* 0FCh */ struct iep_doorbell sw_db; /* 100h. Fixed and unmodifiable */ } field;
From: veega2022 zhuweijia@huawei.com
The spelling of WITDH is incorrect. Change it to WIDTH.
Signed-off-by: hesiyuan hesiyuan4@huawei.com --- pcie/func_lib/pcie_func/pcie_statistics.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/pcie/func_lib/pcie_func/pcie_statistics.c b/pcie/func_lib/pcie_func/pcie_statistics.c index f12660d..308a142 100644 --- a/pcie/func_lib/pcie_func/pcie_statistics.c +++ b/pcie/func_lib/pcie_func/pcie_statistics.c @@ -22,7 +22,7 @@ #include "pcie_statistics.h"
static const char *g_global_width_name[GLOBAL_WIDTH_TABLE_SIZE] = { - "PCIE_WITDH_X1", "PCIE_WITDH_X2", "PCIE_WITDH_X4", "PCIE_WITDH_X8", "PCIE_WITDH_X16" + "PCIE_WIDTH_X1", "PCIE_WIDTH_X2", "PCIE_WIDTH_X4", "PCIE_WIDTH_X8", "PCIE_WIDTH_X16" };
static int port_distribution_rsp_data_check(const struct hikp_cmd_ret *cmd_ret, uint32_t *port_num) @@ -81,7 +81,7 @@ int pcie_port_distribution_get(uint32_t chip_id) for (i = 0; i < pair_num; i++) { if (port_info->info_pair[i].port_width >= HIKP_ARRAY_SIZE(g_global_width_name)) { Info("PCIe Base", "port_id[%u] %s\n", port_info->info_pair[i].port_id, - "UNKNOWN_WITDH"); + "UNKNOWN_WIDTH"); continue; } Info("PCIe Base", "port_id[%u] %s\n", port_info->info_pair[i].port_id,
From: veega2022 zhuweijia@huawei.com
move sig_init api to op_logs public header file
Signed-off-by: wangkang wangkang124@hisilicon.com --- hikp_init_main.c | 20 -------------------- libhikptdev/src/rciep/hikpt_rciep.h | 2 +- tool_lib/op_logs.c | 23 ++++++++++++++++++++++- tool_lib/op_logs.h | 3 ++- 4 files changed, 25 insertions(+), 23 deletions(-)
diff --git a/hikp_init_main.c b/hikp_init_main.c index 4102c69..4629b40 100644 --- a/hikp_init_main.c +++ b/hikp_init_main.c @@ -19,26 +19,6 @@ /* hikptool command adapter */ struct cmd_adapter g_tool = { 0 };
-static void _sig_ign_handle(int arg) -{ - signal_op_log_write(arg); - hikp_unlock(); - _exit(1); -} - -static void sig_init(void) -{ - (void)signal(SIGINT, _sig_ign_handle); /* Quit process */ - (void)signal(SIGTERM, _sig_ign_handle); - (void)signal(SIGQUIT, _sig_ign_handle); - (void)signal(SIGHUP, _sig_ign_handle); - (void)signal(SIGSEGV, _sig_ign_handle); - (void)signal(SIGBUS, _sig_ign_handle); - (void)signal(SIGFPE, _sig_ign_handle); - (void)signal(SIGABRT, _sig_ign_handle); - (void)signal(SIGTSTP, _sig_ign_handle); /* Stop process */ -} - static void show_tool_version(const struct cmd_adapter *adapter) { printf("%s version %s Huawei\n", adapter->name, adapter->version); diff --git a/libhikptdev/src/rciep/hikpt_rciep.h b/libhikptdev/src/rciep/hikpt_rciep.h index 8fbb3c0..dd08759 100644 --- a/libhikptdev/src/rciep/hikpt_rciep.h +++ b/libhikptdev/src/rciep/hikpt_rciep.h @@ -40,7 +40,7 @@ #define MAX_LOCK_COUNT 5 #define LOCK_CHECK_GAP_US 1000 #define CPL_CHECK_GAP_US 1000 -#define WAIT_CPL_MAX_MS 5000 +#define WAIT_CPL_MAX_MS 8000
enum { HIKP_RESOURCE_DIR, diff --git a/tool_lib/op_logs.c b/tool_lib/op_logs.c index d6082a3..069428d 100644 --- a/tool_lib/op_logs.c +++ b/tool_lib/op_logs.c @@ -14,7 +14,9 @@ #include <syslog.h> #include <unistd.h> #include <sys/stat.h> +#include <signal.h> #include "tool_lib.h" +#include "hikptdev_plug.h" #include "op_logs.h"
static char g_op_log[OP_LOG_FILE_PATH_MAXLEN] = {0}; @@ -23,7 +25,6 @@ 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) { size_t w_size; @@ -414,3 +415,23 @@ SIGNAL_LOG_OUT: (void)close(fd); (void)uda_unfcntl(&op_log_fd, UDA_FLOCK_BLOCK); } + +static void signal_handle(int arg) +{ + signal_op_log_write(arg); + hikp_unlock(); + _exit(1); +} + +void sig_init(void) +{ + (void)signal(SIGINT, signal_handle); /* Quit process */ + (void)signal(SIGTERM, signal_handle); + (void)signal(SIGQUIT, signal_handle); + (void)signal(SIGHUP, signal_handle); + (void)signal(SIGSEGV, signal_handle); + (void)signal(SIGBUS, signal_handle); + (void)signal(SIGFPE, signal_handle); + (void)signal(SIGABRT, signal_handle); + (void)signal(SIGTSTP, signal_handle); /* Stop process */ +} diff --git a/tool_lib/op_logs.h b/tool_lib/op_logs.h index 597f063..6b6e421 100644 --- a/tool_lib/op_logs.h +++ b/tool_lib/op_logs.h @@ -45,7 +45,8 @@ struct op_log_print_t { char *str; };
-void signal_op_log_write(int signal_code); +void sig_init(void); + void op_log_on(void); void op_log_off(void); int op_log_initialise(const char *log_dir);
From: veega2022 zhuweijia@huawei.com
the AP_INT module is abandoned, so deleted this module and do not dump this module reg
Signed-off-by: hesiyuan hesiyuan4@huawei.com --- pcie/func_lib/pcie_func/pcie_reg_read.c | 1 - 1 file changed, 1 deletion(-)
diff --git a/pcie/func_lib/pcie_func/pcie_reg_read.c b/pcie/func_lib/pcie_func/pcie_reg_read.c index 6ba4f07..b3d4643 100644 --- a/pcie/func_lib/pcie_func/pcie_reg_read.c +++ b/pcie/func_lib/pcie_func/pcie_reg_read.c @@ -30,7 +30,6 @@ static struct pcie_module_table g_module_table[] = { {"PCIPC_REG", PCIPC_REG_ID}, {"AP_MCTP_REG", AP_MCTP_REG_ID}, {"AP_ENGINE_REG", AP_ENGINE_REG_ID}, - {"AP_INT_REG", AP_INT_REG_ID}, {"AP_DMA_REG", AP_DMA_REG_ID}, {"TOP_REG", TOP_REG_ID}, {"CORE_GLOBAL_REG", CORE_GLOBAL_REG_ID},
From: veega2022 zhuweijia@huawei.com
The number of new chip registers may increase. Therefore, increase the number of dump registers.
Signed-off-by: wangkang wangkang124@hisilicon.com --- serdes/hikp_serdes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/serdes/hikp_serdes.c b/serdes/hikp_serdes.c index 89e66e1..dd9eee3 100644 --- a/serdes/hikp_serdes.c +++ b/serdes/hikp_serdes.c @@ -23,7 +23,7 @@
static struct cmd_serdes_param g_serdes_param = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
-#define SERDES_OUTPUT_MAX_SIZE 2048 +#define SERDES_OUTPUT_MAX_SIZE 2560 static char g_serdes_data_out_buf[SERDES_OUTPUT_MAX_SIZE] = {0};
static int cmd_serdes_maininfo_help(struct major_cmd_ctrl *self, const char *argv)
From: veega2022 zhuweijia@huawei.com
Traverse the PCS registers of all lanes under the current core.
Signed-off-by: hesiyuan hesiyuan4@huawei.com --- pcie/func_lib/pcie_func/pcie_reg_dump.c | 36 +++++++++++------------- pcie/func_lib/pcie_func/pcie_reg_dump.h | 10 +++++++ pcie/usr_cmd/interface/pcie_common_api.h | 4 +++ 3 files changed, 31 insertions(+), 19 deletions(-)
diff --git a/pcie/func_lib/pcie_func/pcie_reg_dump.c b/pcie/func_lib/pcie_func/pcie_reg_dump.c index 7d91969..e10ff7e 100644 --- a/pcie/func_lib/pcie_func/pcie_reg_dump.c +++ b/pcie/func_lib/pcie_func/pcie_reg_dump.c @@ -108,13 +108,13 @@ struct pcie_dumpreg_info g_reg_table_mac[] = { };
struct pcie_dumpreg_info g_reg_table_pcs[] = { - {0, "SERDES_STATUS_RPT"}, - {0, "EBUF_STATUS"}, - {0, "GEN3_DEC_ENC_STATUS"}, - {0, "WAKE_STATUS"}, - {0, "RECV_DET_OR_PWR_CHAGE"}, - {0, "EQEVAL_STATUS"}, - {0, "LANE_INTR_STATUS"}, + HIKP_PCIE_PCS_LANE_TBL_ENTRY(SERDES_STATUS_RPT), + HIKP_PCIE_PCS_LANE_TBL_ENTRY(EBUF_STATUS), + HIKP_PCIE_PCS_LANE_TBL_ENTRY(GEN3_DEC_ENC_STATUS), + HIKP_PCIE_PCS_LANE_TBL_ENTRY(WAKE_STATUS), + HIKP_PCIE_PCS_LANE_TBL_ENTRY(RECV_DET_OR_PWR_CHAGE), + HIKP_PCIE_PCS_LANE_TBL_ENTRY(EQEVAL_STATUS), + HIKP_PCIE_PCS_LANE_TBL_ENTRY(LANE_INTR_STATUS), };
struct pcie_dumpreg_info g_reg_table_iob_tx[] = { @@ -348,6 +348,13 @@ static void pcie_dumpreg_save_glb_analysis_log(const uint32_t *data, uint32_t da pcie_dumpreg_write_value_to_file(g_reg_table_core_glb[item_i].name, g_reg_table_core_glb[item_i].val); } + /* PCS REG */ + for (item_i = 0; item_i < HIKP_ARRAY_SIZE(g_reg_table_pcs) && + data_i < data_num; item_i++, data_i++) { + g_reg_table_pcs[item_i].val = data[data_i]; + pcie_dumpreg_write_value_to_file(g_reg_table_pcs[item_i].name, + g_reg_table_pcs[item_i].val); + } }
static void pcie_dumpreg_save_port_analysis_log(uint32_t *data, uint32_t data_num) @@ -376,13 +383,6 @@ static void pcie_dumpreg_save_port_analysis_log(uint32_t *data, uint32_t data_nu pcie_dumpreg_write_value_to_file(g_reg_table_mac[item_i].name, g_reg_table_mac[item_i].val); } - /* PCS REG */ - for (item_i = 0; item_i < HIKP_ARRAY_SIZE(g_reg_table_pcs) && - data_i < data_num; item_i++, data_i++) { - g_reg_table_pcs[item_i].val = data[data_i]; - pcie_dumpreg_write_value_to_file(g_reg_table_pcs[item_i].name, - g_reg_table_pcs[item_i].val); - } }
static int pcie_dumpreg_write_header_to_file(uint32_t version, @@ -421,14 +421,12 @@ static int pcie_dumpreg_save_log(uint32_t *data, uint32_t data_num, switch (req_data->level) { case DUMP_GLOBAL_LEVEL: expect_data_num = HIKP_ARRAY_SIZE(g_reg_table_iob_tx) + - HIKP_ARRAY_SIZE(g_reg_table_iob_rx) + HIKP_ARRAY_SIZE(g_reg_table_ap_glb) + - HIKP_ARRAY_SIZE(g_reg_table_core_glb); + HIKP_ARRAY_SIZE(g_reg_table_iob_rx) + HIKP_ARRAY_SIZE(g_reg_table_ap_glb) + + HIKP_ARRAY_SIZE(g_reg_table_core_glb) + HIKP_ARRAY_SIZE(g_reg_table_pcs); break; case DUMP_PORT_LEVEL: expect_data_num = HIKP_ARRAY_SIZE(g_reg_table_tl) + - HIKP_ARRAY_SIZE(g_reg_table_dl) + - HIKP_ARRAY_SIZE(g_reg_table_mac) + - HIKP_ARRAY_SIZE(g_reg_table_pcs); + HIKP_ARRAY_SIZE(g_reg_table_dl) + HIKP_ARRAY_SIZE(g_reg_table_mac); break; default: Err("PCIe DUMPREG", "check dump level failed.\n"); diff --git a/pcie/func_lib/pcie_func/pcie_reg_dump.h b/pcie/func_lib/pcie_func/pcie_reg_dump.h index 1993c1f..4ec1909 100644 --- a/pcie/func_lib/pcie_func/pcie_reg_dump.h +++ b/pcie/func_lib/pcie_func/pcie_reg_dump.h @@ -20,6 +20,16 @@ #define MAX_STR_LEN 80 #define PCIE_DUMPREG_LOGFILE_NAME "pcie_dumpreg"
+#define HIKP_PCIE_PCS_LANE_TBL_ENTRY(name) \ + {0, STR(CONTACT(name, _00))}, {0, STR(CONTACT(name, _01))}, \ + {0, STR(CONTACT(name, _02))}, {0, STR(CONTACT(name, _03))}, \ + {0, STR(CONTACT(name, _04))}, {0, STR(CONTACT(name, _05))}, \ + {0, STR(CONTACT(name, _06))}, {0, STR(CONTACT(name, _07))}, \ + {0, STR(CONTACT(name, _08))}, {0, STR(CONTACT(name, _09))}, \ + {0, STR(CONTACT(name, _10))}, {0, STR(CONTACT(name, _11))}, \ + {0, STR(CONTACT(name, _12))}, {0, STR(CONTACT(name, _13))}, \ + {0, STR(CONTACT(name, _14))}, {0, STR(CONTACT(name, _15))} + enum pcie_dump_level { DUMP_GLOBAL_LEVEL = 1, DUMP_PORT_LEVEL = 2, diff --git a/pcie/usr_cmd/interface/pcie_common_api.h b/pcie/usr_cmd/interface/pcie_common_api.h index f6541bd..9809575 100644 --- a/pcie/usr_cmd/interface/pcie_common_api.h +++ b/pcie/usr_cmd/interface/pcie_common_api.h @@ -17,6 +17,10 @@ #include <stdint.h> #include <stdio.h>
+#define CONTACT(x, y) x##y +#define STR_INTER(x) #x +#define STR(x) STR_INTER(x) + struct print_info { char *buff; size_t buff_size;
From: veega2022 zhuweijia@huawei.com
The hikptool ub_dfx command is submitted for the first time. This command can be used to dump register information of the LRB, PFA, and PM modules.
Signed-off-by: Jianqiang Li lijianqiang16@huawei.com --- libhikptdev/include/hikptdev_plug.h | 1 + net/hikp_net_lib.h | 9 + net/ub/ub_dfx/hikp_ub_dfx.c | 319 ++++++++++++++++++++++++++++ net/ub/ub_dfx/hikp_ub_dfx.h | 100 +++++++++ tool_lib/tool_lib.h | 2 +- 5 files changed, 430 insertions(+), 1 deletion(-) create mode 100644 net/ub/ub_dfx/hikp_ub_dfx.c create mode 100644 net/ub/ub_dfx/hikp_ub_dfx.h
diff --git a/libhikptdev/include/hikptdev_plug.h b/libhikptdev/include/hikptdev_plug.h index 42bea6b..56cea78 100644 --- a/libhikptdev/include/hikptdev_plug.h +++ b/libhikptdev/include/hikptdev_plug.h @@ -43,6 +43,7 @@ enum cmd_module_type { MAC_MOD = 8, DPDK_MOD = 9, CXL_MOD = 10, + UB_MOD = 11, };
void hikp_unlock(void); diff --git a/net/hikp_net_lib.h b/net/hikp_net_lib.h index cc99d0c..af0a51d 100644 --- a/net/hikp_net_lib.h +++ b/net/hikp_net_lib.h @@ -98,6 +98,15 @@ enum roce_cmd_type { GET_ROCEE_TSP_CMD, };
+enum ub_cmd_type { + GET_UNIC_PPP_CMD = 0x1, + GET_UB_DFX_INFO_CMD, + GET_UB_LINK_INFO_CMD, + GET_UB_BP_INFO_CMD, + GET_UB_CRD_INFO_CMD, + GET_UB_BASIC_INFO_CMD, +}; + #define HIKP_MAX_PF_NUM 8 #define HIKP_NIC_MAX_FUNC_NUM 256
diff --git a/net/ub/ub_dfx/hikp_ub_dfx.c b/net/ub/ub_dfx/hikp_ub_dfx.c new file mode 100644 index 0000000..c50f555 --- /dev/null +++ b/net/ub/ub_dfx/hikp_ub_dfx.c @@ -0,0 +1,319 @@ +/* + * Copyright (c) 2023 Hisilicon Technologies Co., Ltd. + * Hikptool is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * + * See the Mulan PSL v2 for more details. + */ + +#include "tool_cmd.h" +#include "hikp_net_lib.h" +#include "hikp_ub_dfx.h" + +struct ub_dfx_param g_ub_dfx_param = { 0 }; + +static const struct dfx_module_cmd g_ub_dfx_module_parse[] = { + {"LRB", LRB_DFX_REG_DUMP}, + {"PFA", PFA_DFX_REG_DUMP}, + {"PM", PM_DFX_REG_DUMP} +}; + +static const struct dfx_type_parse g_dfx_type_parse[] = { + {INCORRECT_REG_TYPE, WIDTH_32_BIT, "INCORRECT TYPE"}, + {TYPE_32_STATS, WIDTH_32_BIT, "32 bit statistics"}, + {TYPE_32_RUNNING_STATUS, WIDTH_32_BIT, "32 bit running status"}, + {TYPE_64_STATS, WIDTH_64_BIT, "64 bit statistics"}, +}; + +static void dfx_help_info(const struct major_cmd_ctrl *self) +{ + printf("\n Usage: %s %s\n", self->cmd_ptr->name, "-i <interface>\n"); + printf("\n %s\n", self->cmd_ptr->help_info); + printf(" Options:\n\n"); + printf(" %s, %-25s %s\n", "-h", "--help", "display this help and exit"); + printf(" %s, %-25s %s\n", "-i", "--interface=<interface>", + "device target or bdf id, e.g. ubn0 or 0000:35:00.0"); + printf(" %s\n", " [-m/--module LRB/PFA/PM] : this is necessary param\n"); +} + +static int hikp_ub_dfx_help(struct major_cmd_ctrl *self, const char *argv) +{ + dfx_help_info(self); + return 0; +} + +static int hikp_ub_dfx_target(struct major_cmd_ctrl *self, const char *argv) +{ + self->err_no = tool_check_and_get_valid_bdf_id(argv, &(g_ub_dfx_param.target)); + if (self->err_no != 0) { + snprintf(self->err_str, sizeof(self->err_str), "Unknown device %s.", argv); + return self->err_no; + } + + return 0; +} + +static int hikp_ub_dfx_module_select(struct major_cmd_ctrl *self, const char *argv) +{ + size_t arr_size = HIKP_ARRAY_SIZE(g_ub_dfx_module_parse); + bool is_found; + size_t i; + + for (i = 0; i < arr_size; i++) { + is_found = strncmp(argv, (const char *)g_ub_dfx_module_parse[i].module_name, + sizeof(g_ub_dfx_module_parse[i].module_name)) == 0; + if (is_found) { + g_ub_dfx_param.sub_cmd_code = g_ub_dfx_module_parse[i].sub_cmd_code; + g_ub_dfx_param.module_idx = i; + g_ub_dfx_param.flag |= MODULE_SET_FLAG; + return 0; + } + } + dfx_help_info(self); + snprintf(self->err_str, sizeof(self->err_str), "-m/--module param error!!!"); + self->err_no = -EINVAL; + + return -EINVAL; +} + +static int hikp_ub_dfx_get_blk_data(struct hikp_cmd_ret **cmd_ret, + uint32_t blk_id, uint32_t sub_cmd_code) +{ + struct hikp_cmd_header req_header = { 0 }; + struct ub_dfx_req_para req_data = { 0 }; + + req_data.bdf = g_ub_dfx_param.target.bdf; + req_data.block_id = blk_id; + hikp_cmd_init(&req_header, UB_MOD, GET_UB_DFX_INFO_CMD, sub_cmd_code); + *cmd_ret = hikp_cmd_alloc(&req_header, &req_data, sizeof(req_data)); + + return hikp_rsp_normal_check(*cmd_ret); +} + +static int hikp_ub_get_first_blk_dfx(struct ub_dfx_rsp_head *rsp_head, uint32_t **reg_data, + uint32_t *max_dfx_size, uint32_t *version) +{ + struct ub_dfx_rsp *dfx_rsp = NULL; + struct hikp_cmd_ret *cmd_ret; + int ret; + + ret = hikp_ub_dfx_get_blk_data(&cmd_ret, 0, g_ub_dfx_param.sub_cmd_code); + if (ret < 0) + goto err_out; + + dfx_rsp = (struct ub_dfx_rsp *)(cmd_ret->rsp_data); + *version = cmd_ret->version; + *rsp_head = dfx_rsp->rsp_head; + if (rsp_head->total_blk_num == 0) { + /* if total block number is zero, set total type number to zero anyway */ + 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)); + *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); + ret = -ENOMEM; + goto err_out; + } + + if (rsp_head->cur_blk_size > *max_dfx_size) { + free(*reg_data); + *reg_data = NULL; + HIKP_ERROR_PRINT("blk0 reg_data copy size error, data size: 0x%x, max size: 0x%x\n", + rsp_head->cur_blk_size, *max_dfx_size); + ret = -EINVAL; + goto err_out; + } + memcpy(*reg_data, dfx_rsp->reg_data, rsp_head->cur_blk_size); + + *max_dfx_size -= (uint32_t)rsp_head->cur_blk_size; +err_out: + free(cmd_ret); + cmd_ret = NULL; + + return ret; +} + +static int hikp_ub_get_blk_dfx(struct ub_dfx_rsp_head *rsp_head, uint32_t blk_id, + uint32_t *reg_data, uint32_t *max_dfx_size) +{ + struct ub_dfx_rsp *dfx_rsp = NULL; + struct hikp_cmd_ret *cmd_ret; + int ret; + + ret = hikp_ub_dfx_get_blk_data(&cmd_ret, blk_id, g_ub_dfx_param.sub_cmd_code); + if (ret < 0) + goto err_out; + + dfx_rsp = (struct ub_dfx_rsp *)(cmd_ret->rsp_data); + *rsp_head = dfx_rsp->rsp_head; + if (rsp_head->cur_blk_size > *max_dfx_size) { + HIKP_ERROR_PRINT("blk%u reg_data copy size error, " + "data size: 0x%x, max size: 0x%x\n", + blk_id, rsp_head->cur_blk_size, *max_dfx_size); + ret = -EINVAL; + goto err_out; + } + memcpy(reg_data, dfx_rsp->reg_data, rsp_head->cur_blk_size); + *max_dfx_size -= (uint32_t)rsp_head->cur_blk_size; + +err_out: + free(cmd_ret); + cmd_ret = NULL; + + return ret; +} + +static bool is_type_found(uint16_t type_id, uint32_t *index) +{ + size_t arr_size = HIKP_ARRAY_SIZE(g_dfx_type_parse); + size_t i; + + for (i = 0; i < arr_size; i++) { + if (g_dfx_type_parse[i].type_id == type_id) { + *index = i; + return true; + } + } + + return false; +} + +static void hikp_ub_dfx_print_type_head(uint8_t type_id, uint8_t *last_type_id) +{ + uint32_t index = 0; + + if (type_id != *last_type_id) { + printf("-----------------------------------------------------\n"); + if (is_type_found(type_id, &index)) + printf("type name: %s\n\n", g_dfx_type_parse[index].type_name); + else + HIKP_WARN_PRINT("type name: unknown type, type id is %u\n\n", type_id); + + *last_type_id = type_id; + } +} + +static void hikp_ub_dfx_print_b32(uint32_t num, uint32_t *reg_data) +{ + uint32_t word_num = num * WORD_NUM_PER_REG; + uint16_t offset; + uint32_t value; + uint32_t index; + uint32_t i; + + 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); + } +} + +static void hikp_ub_dfx_print_b64(uint32_t num, uint32_t *reg_data) +{ + uint32_t word_num = num * WORD_NUM_PER_REG; + uint16_t offset; + uint64_t value; + uint32_t index; + uint32_t i; + + 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); + } +} + +static void hikp_ub_dfx_print(const struct ub_dfx_rsp_head *rsp_head, uint32_t *reg_data) +{ + struct ub_dfx_type_head *type_head; + uint8_t last_type_id = 0; + uint32_t *ptr = reg_data; + uint8_t i; + + printf("****************** module %s reg dump start ********************\n", + g_ub_dfx_module_parse[g_ub_dfx_param.module_idx].module_name); + for (i = 0; i < rsp_head->total_type_num; i++) { + type_head = (struct ub_dfx_type_head *)ptr; + if (type_head->type_id == INCORRECT_REG_TYPE) { + HIKP_ERROR_PRINT("No.%u type is incorrect reg type\n", i + 1u); + break; + } + hikp_ub_dfx_print_type_head(type_head->type_id, &last_type_id); + ptr++; + if (type_head->bit_width == WIDTH_32_BIT) { + hikp_ub_dfx_print_b32((uint32_t)type_head->reg_num, ptr); + } else if (type_head->bit_width == WIDTH_64_BIT) { + hikp_ub_dfx_print_b64((uint32_t)type_head->reg_num, ptr); + } else { + HIKP_ERROR_PRINT("type%u's bit width error.\n", type_head->type_id); + break; + } + ptr += (uint32_t)type_head->reg_num * WORD_NUM_PER_REG; + } + printf("################### ====== dump end ====== ######################\n"); +} + +static void hikp_ub_dfx_execute(struct major_cmd_ctrl *self) +{ + struct ub_dfx_rsp_head rsp_head = { 0 }; + struct ub_dfx_rsp_head tmp_head = { 0 }; + uint32_t *reg_data = NULL; + uint32_t max_dfx_size = 0; + uint32_t real_reg_size; + uint32_t version; + uint32_t i; + + if (!(g_ub_dfx_param.flag & MODULE_SET_FLAG)) { + self->err_no = -EINVAL; + snprintf(self->err_str, sizeof(self->err_str), "Please specify a module."); + dfx_help_info(self); + return; + } + + self->err_no = hikp_ub_get_first_blk_dfx(&rsp_head, ®_data, &max_dfx_size, &version); + if (self->err_no != 0) { + snprintf(self->err_str, sizeof(self->err_str), "get the first block dfx fail."); + return; + } + real_reg_size = (uint32_t)rsp_head.cur_blk_size; + for (i = 1; i < rsp_head.total_blk_num; i++) { + self->err_no = hikp_ub_get_blk_dfx(&tmp_head, i, + reg_data + (real_reg_size / sizeof(uint32_t)), + &max_dfx_size); + if (self->err_no != 0) { + snprintf(self->err_str, sizeof(self->err_str), + "getting block%u reg fail.", i); + free(reg_data); + return; + } + real_reg_size += (uint32_t)tmp_head.cur_blk_size; + memset(&tmp_head, 0, sizeof(struct ub_dfx_rsp_head)); + } + + printf("DFX cmd version: 0x%x\n\n", version); + hikp_ub_dfx_print((const struct ub_dfx_rsp_head *)&rsp_head, reg_data); + free(reg_data); +} + +static void cmd_ub_dfx_init(void) +{ + struct major_cmd_ctrl *major_cmd = get_major_cmd(); + + major_cmd->option_count = 0; + major_cmd->execute = hikp_ub_dfx_execute; + + cmd_option_register("-h", "--help", false, hikp_ub_dfx_help); + cmd_option_register("-i", "--interface", true, hikp_ub_dfx_target); + cmd_option_register("-m", "--module", true, hikp_ub_dfx_module_select); +} + +HIKP_CMD_DECLARE("ub_dfx", "dump ub dfx info of hardware", cmd_ub_dfx_init); diff --git a/net/ub/ub_dfx/hikp_ub_dfx.h b/net/ub/ub_dfx/hikp_ub_dfx.h new file mode 100644 index 0000000..4ba37a1 --- /dev/null +++ b/net/ub/ub_dfx/hikp_ub_dfx.h @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2023 Hisilicon Technologies Co., Ltd. + * Hikptool is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * + * See the Mulan PSL v2 for more details. + */ + +#ifndef HIKP_UB_DFX_H +#define HIKP_UB_DFX_H + +#include "hikp_net_lib.h" + +#define MAX_DFX_DATA_NUM 59 +#define MODULE_SET_FLAG 0x1 + +enum ub_dfx_cmd_type { + LRB_DFX_REG_DUMP = 0, + PFA_DFX_REG_DUMP = 1, + PM_DFX_REG_DUMP = 2, + INVALID_MODULE = 0xFFFFFFFF, +}; + +enum ub_dfx_reg_type { + INCORRECT_REG_TYPE = 0, + TYPE_32_STATS = 1, + TYPE_32_RUNNING_STATUS = 2, + TYPE_64_STATS = 3, + TYPE_INVALID = 255, +}; + +#define MAX_TYPE_NAME_LEN 40 + +enum ub_dfx_reg_width { + WIDTH_32_BIT = 32, + WIDTH_64_BIT = 64, +}; + +struct dfx_type_parse { + uint8_t type_id; + uint8_t bit_width; + uint8_t type_name[MAX_TYPE_NAME_LEN]; +}; + +struct ub_dfx_param { + struct tool_target target; + uint32_t sub_cmd_code; + uint8_t module_idx; + uint8_t flag; +}; + +#define MAX_MODULE_NAME_LEN 20 +struct dfx_module_cmd { + uint8_t module_name[MAX_MODULE_NAME_LEN]; + uint32_t sub_cmd_code; +}; + +struct ub_dfx_req_para { + struct bdf_t bdf; + uint8_t block_id; +}; + +struct ub_dfx_type_head { + uint8_t type_id; + uint8_t bit_width; + uint8_t reg_num; + uint8_t flag; +}; + +struct ub_dfx_rsp_head { + uint8_t total_blk_num; + uint8_t total_type_num; + uint8_t cur_blk_size; + uint8_t rsvd; +}; + +/********************************************************* + * All registers are returned as key-value pairs, and divided + * into three groups of data. + * 1. 32bit regs: R0 bit0~bit15: offset, R1 bit0~bit31: value + * 2. 64bit regs: R0 bit0~bit15: offset, R0 bit16~bit31 high16 value, R1 bit0~bit31: low32 value + *********************************************************/ +#define DFX_REG_VALUE_OFF 16 +#define DFX_REG_VALUE_MASK 0xFFFF +#define DFX_REG_ADDR_MASK 0xFFFF + +#define WORD_NUM_PER_REG 2 +#define BIT_NUM_OF_WORD 32 + +struct ub_dfx_rsp { + struct ub_dfx_rsp_head rsp_head; + uint32_t reg_data[MAX_DFX_DATA_NUM]; +}; + +#endif /* HIKP_UB_DFX_H */ diff --git a/tool_lib/tool_lib.h b/tool_lib/tool_lib.h index b211175..bf37465 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.0.13" +#define TOOL_VER "1.0.14"
#define HI_GET_BITFIELD(value, start, mask) (((value) >> (start)) & (mask)) #define HI_SET_FIELD(origin, shift, val) ((origin) |= (val) << (shift))
From: veega2022 zhuweijia@huawei.com
if reg dump block data num is 0, print not support dump and return. hikptool version: 1.0.15
Signed-off-by: veega2022 zhuweijia@huawei.com --- net/nic/nic_mac/hikp_nic_mac_dump.c | 5 +++++ tool_lib/tool_lib.h | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/net/nic/nic_mac/hikp_nic_mac_dump.c b/net/nic/nic_mac/hikp_nic_mac_dump.c index 6e856a8..3e818cd 100644 --- a/net/nic/nic_mac/hikp_nic_mac_dump.c +++ b/net/nic/nic_mac/hikp_nic_mac_dump.c @@ -64,6 +64,11 @@ static int mac_cmd_dump_mod(struct major_cmd_ctrl *self, const char *name, uint32_t i; int ret;
+ if (blk_num == 0) { + printf("%s module is not support dump.\n", name); + return 0; + } + printf("============ %10s REG INFO ==============\n", name); printf("\t %s :\t%10s\n", "offset", "value");
diff --git a/tool_lib/tool_lib.h b/tool_lib/tool_lib.h index bf37465..9766a7e 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.0.14" +#define TOOL_VER "1.0.15"
#define HI_GET_BITFIELD(value, start, mask) (((value) >> (start)) & (mask)) #define HI_SET_FIELD(origin, shift, val) ((origin) |= (val) << (shift))
From: veega2022 zhuweijia@huawei.com
The hikptool ub_link command is submitted for the first time. This command can be used to query the link state machine and status statistics during link establishment.
Signed-off-by: Jianqiang Li lijianqiang16@huawei.com --- net/ub/ub_link/hikp_ub_link.c | 98 +++++++++++++++++++++++++++++++++++ net/ub/ub_link/hikp_ub_link.h | 53 +++++++++++++++++++ 2 files changed, 151 insertions(+) create mode 100644 net/ub/ub_link/hikp_ub_link.c create mode 100644 net/ub/ub_link/hikp_ub_link.h
diff --git a/net/ub/ub_link/hikp_ub_link.c b/net/ub/ub_link/hikp_ub_link.c new file mode 100644 index 0000000..b6353f7 --- /dev/null +++ b/net/ub/ub_link/hikp_ub_link.c @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2023 Hisilicon Technologies Co., Ltd. + * Hikptool is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * + * See the Mulan PSL v2 for more details. + */ + +#include "hikp_ub_link.h" + +static struct ub_link_param g_ub_link_param = { 0 }; + +static int hikp_ub_link_help(struct major_cmd_ctrl *self, const char *argv) +{ + printf("\n Usage: %s %s\n", self->cmd_ptr->name, "-i <interface>\n"); + printf("\n %s\n", self->cmd_ptr->help_info); + printf(" Options:\n\n"); + printf(" %s, %-25s %s\n", "-h", "--help", "display this help and exit"); + printf(" %s, %-25s %s\n", "-i", "--interface=<interface>", + "device target or bdf id, e.g. ubn0 or 0000:35:00.0"); + printf("\n"); + return 0; +} + +static int hikp_ub_link_target(struct major_cmd_ctrl *self, const char *argv) +{ + self->err_no = tool_check_and_get_valid_bdf_id(argv, &(g_ub_link_param.target)); + if (self->err_no != 0) { + snprintf(self->err_str, sizeof(self->err_str), "Unknown device %s.", argv); + return self->err_no; + } + + return 0; +} + +static void hikp_ub_link_info_show(const struct ub_link_rsp *info) +{ + printf("%-32s %u\n", "mac id:", info->mac_id); + printf("%-32s %s\n", "hdlc link status:", info->hdlc_link ? "true" : "false"); + printf("%-32s %s\n", "hpcs link status:", info->hpcs_link ? "true" : "false"); + printf("%-32s 0x%08x\n", "hdlc_link_fsm register value:", info->hdlc_link_fsm); + printf("%-32s 0x%08x\n", "hpcs_link_fsm register value:", info->hpcs_link_fsm); +} + +static int hikp_ub_query_link_info(const struct bdf_t *bdf) +{ + struct hikp_cmd_header header = { 0 }; + struct ub_link_req_paras req = { 0 }; + struct hikp_cmd_ret *cmd_ret; + struct ub_link_rsp *rsp; + + req.bdf = *bdf; + hikp_cmd_init(&header, UB_MOD, GET_UB_LINK_INFO_CMD, UB_LINK_INFO_DUMP); + cmd_ret = hikp_cmd_alloc(&header, &req, sizeof(req)); + if (cmd_ret == NULL || cmd_ret->status != 0) { + free(cmd_ret); + cmd_ret = NULL; + return -EIO; + } + + rsp = (struct ub_link_rsp *)cmd_ret->rsp_data; + hikp_ub_link_info_show(rsp); + + free(cmd_ret); + cmd_ret = NULL; + return 0; +} + +static void hikp_ub_link_cmd_execute(struct major_cmd_ctrl *self) +{ + struct bdf_t *bdf = &g_ub_link_param.target.bdf; + int ret; + + ret = hikp_ub_query_link_info(bdf); + if (ret != 0) { + snprintf(self->err_str, sizeof(self->err_str), "fail to get link info."); + self->err_no = ret; + return; + } +} + +static void cmd_ub_link_init(void) +{ + struct major_cmd_ctrl *major_cmd = get_major_cmd(); + + major_cmd->option_count = 0; + major_cmd->execute = hikp_ub_link_cmd_execute; + + cmd_option_register("-h", "--help", false, hikp_ub_link_help); + cmd_option_register("-i", "--interface", true, hikp_ub_link_target); +} + +HIKP_CMD_DECLARE("ub_link", "get ub link information", cmd_ub_link_init); diff --git a/net/ub/ub_link/hikp_ub_link.h b/net/ub/ub_link/hikp_ub_link.h new file mode 100644 index 0000000..dec5129 --- /dev/null +++ b/net/ub/ub_link/hikp_ub_link.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2023 Hisilicon Technologies Co., Ltd. + * Hikptool is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * + * See the Mulan PSL v2 for more details. + */ + +/* + * Copyright (c) 2023 Hisilicon Technologies Co., Ltd. + * Hikptool is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * + * See the Mulan PSL v2 for more details. + */ + +#ifndef HIKP_UB_LINK_H +#define HIKP_UB_LINK_H + +#include "hikp_net_lib.h" + +enum ub_link_sub_cmd_type { + UB_LINK_INFO_DUMP = 0, +}; + +struct ub_link_param { + struct tool_target target; +}; + +struct ub_link_req_paras { + struct bdf_t bdf; +}; + +struct ub_link_rsp { + uint8_t mac_id; + uint8_t hdlc_link; + uint8_t hpcs_link; + uint8_t rsvd; + uint32_t hdlc_link_fsm; + uint32_t hpcs_link_fsm; +}; + +#endif /* HIKP_UB_LINK_H */
From: veega2022 zhuweijia@huawei.com
The hikptool ub_bp command is submitted for the first time. This command can be used to query the back pressure status of the VL in the UB-N.
Signed-off-by: Jianqiang Li lijianqiang16@huawei.com --- net/ub/ub_bp/hikp_ub_bp.c | 102 ++++++++++++++++++++++++++++++++++++++ net/ub/ub_bp/hikp_ub_bp.h | 39 +++++++++++++++ 2 files changed, 141 insertions(+) create mode 100644 net/ub/ub_bp/hikp_ub_bp.c create mode 100644 net/ub/ub_bp/hikp_ub_bp.h
diff --git a/net/ub/ub_bp/hikp_ub_bp.c b/net/ub/ub_bp/hikp_ub_bp.c new file mode 100644 index 0000000..70a9a4b --- /dev/null +++ b/net/ub/ub_bp/hikp_ub_bp.c @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2023 Hisilicon Technologies Co., Ltd. + * Hikptool is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * + * See the Mulan PSL v2 for more details. + */ + +#include "hikp_ub_bp.h" + +static struct ub_bp_param g_ub_bp_param = { 0 }; + +static int hikp_ub_bp_help(struct major_cmd_ctrl *self, const char *argv) +{ + printf("\n Usage: %s %s\n", self->cmd_ptr->name, "-i <interface>\n"); + printf("\n %s\n", self->cmd_ptr->help_info); + printf(" Options:\n\n"); + printf(" %s, %-25s %s\n", "-h", "--help", "display this help and exit"); + printf(" %s, %-25s %s\n", "-i", "--interface=<interface>", + "device target or bdf id, e.g. ubn0 or 0000:35:00.0"); + printf("\n"); + return 0; +} + +static int hikp_ub_bp_target(struct major_cmd_ctrl *self, const char *argv) +{ + self->err_no = tool_check_and_get_valid_bdf_id(argv, &(g_ub_bp_param.target)); + if (self->err_no) { + snprintf(self->err_str, sizeof(self->err_str), "Unknown device %s.", argv); + return self->err_no; + } + return 0; +} + +static void hikp_ub_bp_info_show(const struct ub_bp_rsp *info) +{ + int bp_val_offset; + + printf("%-28s : %u\n", "mac id", info->mac_id); + printf("%-28s : ", "back pressure status"); + + for (bp_val_offset = MAX_VL_NUM; bp_val_offset >= 0; bp_val_offset--) { + printf("%d", HI_GETBIT(info->bp_val, bp_val_offset) ? 1 : 0); + } + printf("\n"); +} + + +static int hikp_ub_query_bp(const struct bdf_t *bdf) +{ + struct hikp_cmd_header header = { 0 }; + struct ub_bp_req_para req = { 0 }; + struct hikp_cmd_ret *cmd_ret; + struct ub_bp_rsp *rsp; + + req.bdf = *bdf; + hikp_cmd_init(&header, UB_MOD, GET_UB_BP_INFO_CMD, UB_BP_INFO_DUMP); + cmd_ret = hikp_cmd_alloc(&header, &req, sizeof(req)); + if (cmd_ret == NULL || cmd_ret->status != 0) { + free(cmd_ret); + cmd_ret = NULL; + return -EIO; + } + + rsp = (struct ub_bp_rsp *)cmd_ret->rsp_data; + hikp_ub_bp_info_show(rsp); + + free(cmd_ret); + cmd_ret = NULL; + return 0; +} + +static void hikp_ub_bp_cmd_execute(struct major_cmd_ctrl *self) +{ + struct bdf_t *bdf = &g_ub_bp_param.target.bdf; + int ret; + + ret = hikp_ub_query_bp(bdf); + if (ret != 0) { + snprintf(self->err_str, sizeof(self->err_str), "fail to get ub bp info."); + self->err_no = ret; + return; + } +} + +static void cmd_ub_bp_init(void) +{ + struct major_cmd_ctrl *major_cmd = get_major_cmd(); + + major_cmd->option_count = 0; + major_cmd->execute = hikp_ub_bp_cmd_execute; + + cmd_option_register("-h", "--help", false, hikp_ub_bp_help); + cmd_option_register("-i", "--interface", true, hikp_ub_bp_target); +} + +HIKP_CMD_DECLARE("ub_bp", "get ub bp information", cmd_ub_bp_init); diff --git a/net/ub/ub_bp/hikp_ub_bp.h b/net/ub/ub_bp/hikp_ub_bp.h new file mode 100644 index 0000000..0bd4740 --- /dev/null +++ b/net/ub/ub_bp/hikp_ub_bp.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2023 Hisilicon Technologies Co., Ltd. + * Hikptool is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * + * See the Mulan PSL v2 for more details. + */ + +#ifndef HIKP_UB_BP_H +#define HIKP_UB_BP_H + +#include "hikp_net_lib.h" + +#define MAX_VL_NUM 17 + +enum ub_bp_sub_cmd_type { + UB_BP_INFO_DUMP = 0, +}; + +struct ub_bp_param { + struct tool_target target; +}; + +struct ub_bp_req_para { + struct bdf_t bdf; +}; + +struct ub_bp_rsp { + uint8_t mac_id; + uint8_t rsvd[3]; + uint32_t bp_val; +}; + +#endif /* HIKP_UB_BP_H */
From: veega2022 zhuweijia@huawei.com
The hikptool ub_crd command is submitted for the first time. This command is used to query the letter of credit status by reading the register value.
Signed-off-by: Jianqiang Li lijianqiang16@huawei.com --- net/ub/ub_crd/hikp_ub_crd.c | 133 ++++++++++++++++++++++++++++++++++++ net/ub/ub_crd/hikp_ub_crd.h | 44 ++++++++++++ 2 files changed, 177 insertions(+) create mode 100644 net/ub/ub_crd/hikp_ub_crd.c create mode 100644 net/ub/ub_crd/hikp_ub_crd.h
diff --git a/net/ub/ub_crd/hikp_ub_crd.c b/net/ub/ub_crd/hikp_ub_crd.c new file mode 100644 index 0000000..d5d0015 --- /dev/null +++ b/net/ub/ub_crd/hikp_ub_crd.c @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2023 Hisilicon Technologies Co., Ltd. + * Hikptool is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * + * See the Mulan PSL v2 for more details. + */ + +#include "hikp_ub_crd.h" + +static struct ub_crd_param g_ub_crd_param = { 0 }; + +static int hikp_ub_crd_help(struct major_cmd_ctrl *self, const char *argv) +{ + printf("\n Usage: %s %s\n", self->cmd_ptr->name, "-i <interface>\n"); + printf("\n %s\n", self->cmd_ptr->help_info); + printf(" Options:\n\n"); + printf(" %s, %-25s %s\n", "-h", "--help", "display this help and exit"); + printf(" %s, %-25s %s\n", "-i", "--interface=<interface>", + "device target or bdf id, e.g. ubn0 or 0000:35:00.0"); + printf("\n"); + return 0; +} + +static int hikp_ub_crd_target(struct major_cmd_ctrl *self, const char *argv) +{ + self->err_no = tool_check_and_get_valid_bdf_id(argv, &(g_ub_crd_param.target)); + if (self->err_no) { + snprintf(self->err_str, sizeof(self->err_str), "Unknown device %s.", argv); + return self->err_no; + } + return 0; +} + +static int 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; + + for (i = 0; i < num_rows; i++) { + union cut_reg reg; + + reg_index = off + i; + reg.value = crd_rsp->cut_reg_value[reg_index]; + if (strcmp(crds[i][0], "NULL") != 0) + printf("%-28s : %#x\n", crds[i][0], reg.cut[0]); + + if (strcmp(crds[i][1], "NULL") != 0) + printf("%-28s : %#x\n", crds[i][1], reg.cut[1]); + } + return off + num_rows; +} + +static int hikp_ub_query_crd(void) +{ + struct hikp_cmd_header req_header = { 0 }; + struct ub_crd_req_para req_data = { 0 }; + struct hikp_cmd_ret *cmd_ret = NULL; + struct ub_crd_rsp *crd_rsp = NULL; + int offset; + int ret; + + char const *init_crds[][2] = { + {"CFG_REMOTE_ICRD", "CFG_REMOTE_LCRD"}, + {"CFG_REMOTE_CRD_VL6", "CFG_REMOTE_CRD_VL7"}, + {"CFG_REMOTE_CRD_VL4", "CFG_REMOTE_CRD_VL5"}, + {"CFG_REMOTE_CRD_VL2", "CFG_REMOTE_CRD_VL3"}, + {"CFG_REMOTE_CRD_VL0", "CFG_REMOTE_CRD_VL1"}, + {"CFG_REMOTE_CRD_VL8", "NULL"} }; + + char const *temp_crds[][2] = { + {"TX_LCRD_VNA_EXIST_NUM", "NULL"}, {"TX_ICRD_VNA_EXIST_NUM", "NULL"}, + {"TX_CRD_VN0_EXIST_NUM", "NULL"}, {"TX_CRD_VN1_EXIST_NUM", "NULL"}, + {"TX_CRD_VN2_EXIST_NUM", "NULL"}, {"TX_CRD_VN3_EXIST_NUM", "NULL"}, + {"TX_CRD_VN4_EXIST_NUM", "NULL"}, {"TX_CRD_VN5_EXIST_NUM", "NULL"}, + {"TX_CRD_VN6_EXIST_NUM", "NULL"}, {"TX_CRD_VN7_EXIST_NUM", "NULL"}, + {"TX_ACK_EXIST_NUM", "NULL"}, {"TX_ROH_LCRD_LOCAL_NUM", "NULL"} }; + + hikp_cmd_init(&req_header, UB_MOD, GET_UB_CRD_INFO_CMD, UB_CRD_INFO_DUMP); + req_data.bdf = g_ub_crd_param.target.bdf; + cmd_ret = hikp_cmd_alloc(&req_header, &req_data, sizeof(req_data)); + if (cmd_ret == NULL || cmd_ret->status != 0) { + free(cmd_ret); + cmd_ret = NULL; + return -EIO; + } + + crd_rsp = (struct ub_crd_rsp *)(cmd_ret->rsp_data); + + printf("******************** CREDIT CNT START ********************\n"); + printf("------------------- INIT CREDIT START -----------------\n"); + offset = hikp_ub_show_crd(0, crd_rsp, NUM_ROWS_INIT_CRDS, init_crds); + printf("------------------- INIT CREDIT END --------------------\n"); + printf("------------------- TEMP CREDIT START ------------------\n"); + offset = hikp_ub_show_crd(offset, crd_rsp, NUM_ROWS_TEMP_CRDS, temp_crds); + printf("------------------- TEMP CREDIT END --------------------\n"); + printf("********************* CREDIT CNT END *********************\n"); + + free(cmd_ret); + cmd_ret = NULL; + return 0; +} + +static void hikp_ub_crd_cmd_execute(struct major_cmd_ctrl *self) +{ + int ret; + + ret = hikp_ub_query_crd(); + if (ret != 0) { + snprintf(self->err_str, sizeof(self->err_str), "fail to get ub crd info."); + self->err_no = ret; + return; + } +} + +static void cmd_ub_crd_init(void) +{ + struct major_cmd_ctrl *major_cmd = get_major_cmd(); + + major_cmd->option_count = 0; + major_cmd->execute = hikp_ub_crd_cmd_execute; + + cmd_option_register("-h", "--help", false, hikp_ub_crd_help); + cmd_option_register("-i", "--interface", true, hikp_ub_crd_target); +} + +HIKP_CMD_DECLARE("ub_crd", "get ub crd information", cmd_ub_crd_init); diff --git a/net/ub/ub_crd/hikp_ub_crd.h b/net/ub/ub_crd/hikp_ub_crd.h new file mode 100644 index 0000000..5dfa38a --- /dev/null +++ b/net/ub/ub_crd/hikp_ub_crd.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2023 Hisilicon Technologies Co., Ltd. + * Hikptool is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * + * See the Mulan PSL v2 for more details. + */ + +#ifndef HIKP_UB_CRD_H +#define HIKP_UB_CRD_H + +#include "hikp_net_lib.h" + +#define MAX_CRD_SIZE 20 +#define NUM_ROWS_INIT_CRDS 6 +#define NUM_ROWS_TEMP_CRDS 12 + +enum ub_crd_sub_cmd_type { + UB_CRD_INFO_DUMP = 0, +}; + +union cut_reg { + uint32_t value; + uint16_t cut[2]; +}; + +struct ub_crd_param { + struct tool_target target; +}; + +struct ub_crd_req_para { + struct bdf_t bdf; +}; + +struct ub_crd_rsp { + uint32_t cut_reg_value[MAX_CRD_SIZE]; +}; + +#endif /* HIKP_UB_CRD_H */
From: veega2022 zhuweijia@huawei.com
The hikptool ub_info command is submitted for the first time. This command is used to query whether the cloud attack defense function is enabled and query the single-port multi-stack working mode.
Signed-off-by: Jianqiang Li lijianqiang16@huawei.com --- net/ub/ub_info/hikp_ub_info.c | 96 +++++++++++++++++++++++++++++++++++ net/ub/ub_info/hikp_ub_info.h | 37 ++++++++++++++ 2 files changed, 133 insertions(+) create mode 100644 net/ub/ub_info/hikp_ub_info.c create mode 100644 net/ub/ub_info/hikp_ub_info.h
diff --git a/net/ub/ub_info/hikp_ub_info.c b/net/ub/ub_info/hikp_ub_info.c new file mode 100644 index 0000000..3b354dd --- /dev/null +++ b/net/ub/ub_info/hikp_ub_info.c @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2023 Hisilicon Technologies Co., Ltd. + * Hikptool is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * + * See the Mulan PSL v2 for more details. + */ + +#include "hikp_ub_info.h" + +static struct ub_info_param g_ub_info_param = { 0 }; + +static int hikp_ub_info_help(struct major_cmd_ctrl *self, const char *argv) +{ + printf("\n Usage: %s %s\n", self->cmd_ptr->name, "-i <interface>\n"); + printf("\n %s\n", self->cmd_ptr->help_info); + printf(" Options:\n\n"); + printf(" %s, %-25s %s\n", "-h", "--help", "display this help and exit"); + printf(" %s, %-25s %s\n", "-i", "--interface=<interface>", + "device target or bdf id, e.g. ubn0 or 0000:35:00.0"); + printf("\n"); + return 0; +} + +static int hikp_ub_info_target(struct major_cmd_ctrl *self, const char *argv) +{ + self->err_no = tool_check_and_get_valid_bdf_id(argv, &(g_ub_info_param.target)); + if (self->err_no != 0) { + snprintf(self->err_str, sizeof(self->err_str), "Unknown device %s.", argv); + return self->err_no; + } + + return 0; +} + +static void hikp_ub_basic_info_show(const struct ub_info_rsp *info) +{ + printf("%-32s : %s\n", "cloud-based attack defense", info->cloud_mode ? "YES" : "NO"); + printf("%-32s : %s\n", "pf working mode", info->pf_drv_type ? "UB" : "RDMA"); + printf("%-32s : %s\n", "vf working mode", info->vf_drv_type ? "UB" : "RDMA"); +} + +static int hikp_ub_query_basic_info(const struct bdf_t *bdf) +{ + struct hikp_cmd_header header = { 0 }; + struct ub_info_req_para req = { 0 }; + struct hikp_cmd_ret *cmd_ret; + struct ub_info_rsp *rsp; + + req.bdf = *bdf; + hikp_cmd_init(&header, UB_MOD, GET_UB_BASIC_INFO_CMD, UB_BASIC_INFO_DUMP); + cmd_ret = hikp_cmd_alloc(&header, &req, sizeof(req)); + if (cmd_ret == NULL || cmd_ret->status != 0) { + free(cmd_ret); + cmd_ret = NULL; + return -EIO; + } + + rsp = (struct ub_info_rsp *)cmd_ret->rsp_data; + hikp_ub_basic_info_show(rsp); + + free(cmd_ret); + cmd_ret = NULL; + return 0; +} + +static void hikp_ub_info_cmd_execute(struct major_cmd_ctrl *self) +{ + struct bdf_t *bdf = &g_ub_info_param.target.bdf; + int ret; + + ret = hikp_ub_query_basic_info(bdf); + if (ret != 0) { + snprintf(self->err_str, sizeof(self->err_str), "fail to get basic info."); + self->err_no = ret; + return; + } +} + +static void cmd_ub_info_init(void) +{ + struct major_cmd_ctrl *major_cmd = get_major_cmd(); + + major_cmd->option_count = 0; + major_cmd->execute = hikp_ub_info_cmd_execute; + + cmd_option_register("-h", "--help", false, hikp_ub_info_help); + cmd_option_register("-i", "--interface", true, hikp_ub_info_target); +} + +HIKP_CMD_DECLARE("ub_info", "get ub basic information", cmd_ub_info_init); diff --git a/net/ub/ub_info/hikp_ub_info.h b/net/ub/ub_info/hikp_ub_info.h new file mode 100644 index 0000000..a9cb858 --- /dev/null +++ b/net/ub/ub_info/hikp_ub_info.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2023 Hisilicon Technologies Co., Ltd. + * Hikptool is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * + * See the Mulan PSL v2 for more details. + */ + +#ifndef HIKP_UB_INFO_H +#define HIKP_UB_INFO_H + +#include "hikp_net_lib.h" + +enum ub_info_sub_cmd_type { + UB_BASIC_INFO_DUMP = 0, +}; + +struct ub_info_param { + struct tool_target target; +}; + +struct ub_info_req_para { + struct bdf_t bdf; +}; + +struct ub_info_rsp { + uint32_t cloud_mode; + uint32_t pf_drv_type; + uint32_t vf_drv_type; +}; + +#endif /* HIKP_UB_INFO_H */
From: veega2022 zhuweijia@huawei.com
The function of reading IP and guid entries through the imp command is added.
Signed-off-by: Jianqiang Li lijianqiang16@huawei.com --- net/ub/ub_unic/hikp_unic_ppp.c | 468 +++++++++++++++++++++++++++++++++ net/ub/ub_unic/hikp_unic_ppp.h | 139 ++++++++++ 2 files changed, 607 insertions(+) create mode 100644 net/ub/ub_unic/hikp_unic_ppp.c create mode 100644 net/ub/ub_unic/hikp_unic_ppp.h
diff --git a/net/ub/ub_unic/hikp_unic_ppp.c b/net/ub/ub_unic/hikp_unic_ppp.c new file mode 100644 index 0000000..5325b03 --- /dev/null +++ b/net/ub/ub_unic/hikp_unic_ppp.c @@ -0,0 +1,468 @@ +/* + * Copyright (c) 2023 Hisilicon Technologies Co., Ltd. + * Hikptool is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * + * See the Mulan PSL v2 for more details. + */ + +#include <string.h> +#include <stdio.h> +#include <sys/types.h> +#include <arpa/inet.h> +#include <unistd.h> +#include "hikp_unic_ppp.h" + +static struct hikp_unic_ppp_hw_resources g_unic_ppp_hw_res = { 0 }; +static struct unic_ppp_param g_unic_ppp_param = { 0 }; + +static void hikp_unic_ppp_show_ip_tbl(const void *data); +static void hikp_unic_ppp_show_guid_tbl(const void *data); + +static int hikp_unic_query_ppp_ip_tbl(struct hikp_cmd_header *req_header, + const struct bdf_t *bdf, void *data); +static int hikp_unic_query_ppp_guid_tbl(struct hikp_cmd_header *req_header, + const struct bdf_t *bdf, void *data); + +static const struct unic_ppp_feature_cmd g_unic_ppp_feature_cmd[] = { + { UNIC_PPP_IP_TBL_NAME, UNIC_IP_TBL_DUMP, true, + hikp_unic_query_ppp_ip_tbl, hikp_unic_ppp_show_ip_tbl }, + { UNIC_PPP_GUID_TBL_NAME, UNIC_GUID_TBL_DUMP, true, + hikp_unic_query_ppp_guid_tbl, hikp_unic_ppp_show_guid_tbl }, +}; + +static int hikp_unic_ppp_cmd_help(struct major_cmd_ctrl *self, const char *argv) +{ + printf("\n Usage: %s %s\n", self->cmd_ptr->name, "-i <interface>"); + printf("\n %s\n", self->cmd_ptr->help_info); + printf("\n Options:\n\n"); + printf(" %s, %-25s %s\n", "-h", "--help", "display this help and exit"); + printf(" %s, %-25s %s\n", "-i", "--interface=<interface>", + "device target or bdf id, e.g. ubn0 or 0000:35:00.0"); + printf(" %s, %-24s %s\n", "-du", "--dump", "dump ip or guid table info."); + + return 0; +} + +static int hikp_unic_cmd_get_ppp_target(struct major_cmd_ctrl *self, const char *argv) +{ + self->err_no = tool_check_and_get_valid_bdf_id(argv, &(g_unic_ppp_param.target)); + if (self->err_no != 0) { + snprintf(self->err_str, sizeof(self->err_str), "unknown device!"); + return self->err_no; + } + + return 0; +} + +static int hikp_unic_cmd_ppp_feature_select(struct major_cmd_ctrl *self, const char *argv) +{ + size_t feat_size = HIKP_ARRAY_SIZE(g_unic_ppp_feature_cmd); + size_t i; + + 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; + return 0; + } + } + + hikp_unic_ppp_cmd_help(self, NULL); + snprintf(self->err_str, sizeof(self->err_str), "please input valid dump type."); + self->err_no = -EINVAL; + + return self->err_no; +} + +static int hikp_unic_ppp_get_blk(struct hikp_cmd_header *req_header, + const struct unic_ppp_req_para *req_data, void *buf, + size_t buf_len, struct unic_ppp_rsp_head *rsp_head) +{ + struct hikp_cmd_ret *cmd_ret; + struct unic_ppp_rsp *rsp; + int ret = 0; + + cmd_ret = hikp_cmd_alloc(req_header, req_data, sizeof(*req_data)); + if (cmd_ret == NULL || cmd_ret->status != 0) { + ret = -EIO; + goto out; + } + + rsp = (struct unic_ppp_rsp *)cmd_ret->rsp_data; + if (rsp->rsp_head.cur_blk_size > buf_len) { + HIKP_ERROR_PRINT("unic_ppp block context copy size error, " + "buffer size=%llu, data size=%u.\n", + buf_len, rsp->rsp_head.cur_blk_size); + ret = -EINVAL; + goto out; + } + memcpy(buf, rsp->rsp_data, rsp->rsp_head.cur_blk_size); + memcpy(rsp_head, &rsp->rsp_head, sizeof(struct unic_ppp_rsp_head)); + +out: + free(cmd_ret); + return ret; +} + +static int hikp_unic_query_ppp_by_blkid(struct hikp_cmd_header *req_header, const struct bdf_t *bdf, + void *data, size_t len) +{ + struct unic_ppp_rsp_head rsp_head = { 0 }; + struct unic_ppp_req_para req_data = { 0 }; + uint32_t total_blk_size; + uint8_t blk_id = 0; + int ret = 0; + + req_data.bdf = *bdf; + req_data.block_id = blk_id; + ret = hikp_unic_ppp_get_blk(req_header, &req_data, data, len, &rsp_head); + if (ret != 0) { + HIKP_ERROR_PRINT("Fail to get block-%u context.\n", blk_id); + return ret; + } + total_blk_size = rsp_head.cur_blk_size; + + for (blk_id = 1; blk_id < rsp_head.total_blk_num; blk_id++) { + req_data.block_id = blk_id; + ret = hikp_unic_ppp_get_blk(req_header, &req_data, (uint8_t *)data + total_blk_size, + len - total_blk_size, &rsp_head); + if (ret != 0) { + HIKP_ERROR_PRINT("Fail to get block-%u context.\n", blk_id); + return ret; + } + total_blk_size += rsp_head.cur_blk_size; + } + + return ret; +} + +static int hikp_unic_get_ppp_entry_hw_res(const struct bdf_t *bdf, + struct hikp_unic_ppp_hw_resources *hw_res) +{ + struct hikp_cmd_header req_header = { 0 }; + + hikp_cmd_init(&req_header, UB_MOD, GET_UNIC_PPP_CMD, UNIC_PPP_ENTRY_HW_SPEC_GET); + return hikp_unic_query_ppp_by_blkid(&req_header, bdf, hw_res, + sizeof(struct hikp_unic_ppp_hw_resources)); +} + +static int hikp_unic_ppp_alloc_ip_tbl_entry(const struct hikp_unic_ppp_hw_resources *hw_res, + struct unic_ip_tbl *ip_tbl) +{ + uint32_t max_ip_entry_size; + + max_ip_entry_size = hw_res->ip_max_mem_size + hw_res->ip_overflow_size; + if (max_ip_entry_size == 0) { + HIKP_ERROR_PRINT("ip tbl query is not supported\n"); + return -EIO; + } + ip_tbl->entry = (struct unic_ip_entry *)calloc(max_ip_entry_size, + sizeof(struct unic_ip_entry)); + if (ip_tbl->entry == NULL) { + HIKP_ERROR_PRINT("fail to alloc ip_table_entry memory.\n"); + return -ENOMEM; + } + + return 0; +} + +static int hikp_unic_ppp_alloc_guid_tbl_entry(const struct hikp_unic_ppp_hw_resources *hw_res, + struct unic_guid_tbl *guid_tbl) +{ + if (hw_res->uc_guid_tbl_size == 0 && hw_res->mc_guid_tbl_size == 0) { + HIKP_ERROR_PRINT("guid tbl query is not supported\n"); + return -EIO; + } + guid_tbl->uc_tbl.entry = (struct unic_guid_uc_entry *)calloc(hw_res->uc_guid_tbl_size, + sizeof(struct unic_guid_uc_entry)); + if (guid_tbl->uc_tbl.entry == NULL) { + HIKP_ERROR_PRINT("fail to alloc uc_guid_entry_table memory.\n"); + return -ENOMEM; + } + + guid_tbl->mc_tbl.entry = (struct unic_guid_mc_entry *)calloc(hw_res->mc_guid_tbl_size, + sizeof(struct unic_guid_mc_entry)); + if (guid_tbl->mc_tbl.entry == NULL) { + HIKP_ERROR_PRINT("fail to alloc mc_guid_entry_table memory.\n"); + free(guid_tbl->uc_tbl.entry); + return -ENOMEM; + } + + return 0; +} + +static union unic_ppp_feature_info* +hikp_unic_ppp_data_alloc(const struct unic_ppp_feature_cmd *unic_ppp_cmd, + const struct hikp_unic_ppp_hw_resources *hw_res) +{ + union unic_ppp_feature_info *unic_ppp_data; + int ret = -1; + + unic_ppp_data = (union unic_ppp_feature_info *)calloc(1, + sizeof(union unic_ppp_feature_info)); + if (unic_ppp_data == NULL) { + HIKP_ERROR_PRINT("Fail to allocate unic_ppp_feature_info memory.\n"); + return NULL; + } + + if (g_unic_ppp_param.feature_idx == UNIC_PPP_IP_FEATURE_IDX) { + ret = hikp_unic_ppp_alloc_ip_tbl_entry(hw_res, &unic_ppp_data->ip_tbl); + } else if (g_unic_ppp_param.feature_idx == UNIC_PPP_GUID_FEATURE_IDX) { + ret = hikp_unic_ppp_alloc_guid_tbl_entry(hw_res, &unic_ppp_data->guid_tbl); + } + + if (ret != 0) { + goto out; + } + + return unic_ppp_data; +out: + free(unic_ppp_data); + return NULL; +} + +static int hikp_unic_query_ppp_ip_tbl(struct hikp_cmd_header *req_header, const struct bdf_t *bdf, + void *data) +{ + struct unic_ip_tbl *ip_tbl = (struct unic_ip_tbl *)data; + struct unic_ppp_rsp_head unic_rsp_head = { 0 }; + struct unic_ppp_req_para req_data = { 0 }; + uint32_t max_ip_entry_size; + uint32_t entry_size = 0; + size_t left_buf_len = 0; + uint32_t index = 0; + int ret = -1; + + max_ip_entry_size = g_unic_ppp_hw_res.ip_max_mem_size + g_unic_ppp_hw_res.ip_overflow_size; + req_data.bdf = *bdf; + while (index < max_ip_entry_size) { + req_data.cur_entry_idx = index; + left_buf_len = sizeof(struct unic_ip_entry) * (max_ip_entry_size - entry_size); + ret = hikp_unic_ppp_get_blk(req_header, &req_data, ip_tbl->entry + entry_size, + left_buf_len, &unic_rsp_head); + if (ret != 0) { + HIKP_ERROR_PRINT("Fail to get the ip entry after index=%u, ret=%d.\n", + index, ret); + return ret; + } + entry_size += unic_rsp_head.cur_blk_entry_cnt; + index = unic_rsp_head.next_entry_idx; + } + ip_tbl->entry_size = entry_size; + + return ret; +} + +static int hikp_unic_query_ppp_guid_tbl(struct hikp_cmd_header *req_header, + const struct bdf_t *bdf, void *data) +{ + struct unic_guid_tbl *guid_tbl = (struct unic_guid_tbl*)data; + struct unic_ppp_rsp_head unic_rsp_head = { 0 }; + struct unic_ppp_req_para req_data = { 0 }; + uint32_t entry_size = 0; + size_t left_buf_len = 0; + uint32_t index = 0; + int ret = -1; + + req_data.bdf = *bdf; + req_data.is_unicast = 1; + while (index < g_unic_ppp_hw_res.uc_guid_tbl_size) { + req_data.cur_entry_idx = index; + left_buf_len = sizeof(struct unic_guid_uc_entry) * + (g_unic_ppp_hw_res.uc_guid_tbl_size - entry_size); + ret = hikp_unic_ppp_get_blk(req_header, &req_data, + guid_tbl->uc_tbl.entry + entry_size, + left_buf_len, &unic_rsp_head); + if (ret != 0) { + HIKP_ERROR_PRINT("Fail to get the uc_guid entry after index=%u, ret=%d.\n", + index, ret); + return ret; + } + entry_size += unic_rsp_head.cur_blk_entry_cnt; + index = unic_rsp_head.next_entry_idx; + } + guid_tbl->uc_tbl.entry_size = entry_size; + + left_buf_len = 0; + entry_size = 0; + index = 0; + req_data.is_unicast = 0; + + while (index < g_unic_ppp_hw_res.mc_guid_tbl_size) { + req_data.cur_entry_idx = index; + left_buf_len = sizeof(struct unic_guid_mc_entry) * + (g_unic_ppp_hw_res.mc_guid_tbl_size - entry_size); + ret = hikp_unic_ppp_get_blk(req_header, &req_data, + guid_tbl->mc_tbl.entry + entry_size, + left_buf_len, &unic_rsp_head); + if (ret != 0) { + HIKP_ERROR_PRINT("Fail to get the mc_guid entry after index=%u, ret=%d.\n", + index, ret); + return ret; + } + entry_size += unic_rsp_head.cur_blk_entry_cnt; + index = unic_rsp_head.next_entry_idx; + } + guid_tbl->mc_tbl.entry_size = entry_size; + + return ret; +} + +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; + + printf("ip_table_size = %u\n", ip_tbl->entry_size); + printf("index\t| func_id\t| ip_addr\n"); + for (i = 0; i < ip_tbl->entry_size; i++) { + entry = &ip_tbl->entry[i]; + ip_addr_tbl_str = (uint16_t *)entry->ip_addr; + printf("%-4u\t| %-3u\t\t| ", entry->index, entry->function_id); + for (j = 0; j < IP_ADDR_TBL_LEN - 1; j++) + printf("%04x:" , ntohs(ip_addr_tbl_str[j])); + printf("%04x\n", ntohs(ip_addr_tbl_str[IP_ADDR_TBL_LEN - 1])); + } +} + +static void hikp_unic_ppp_show_guid_tbl(const void *data) +{ + struct unic_guid_tbl *guid_tbl = (struct unic_guid_tbl *)data; + uint32_t cnt; + int i; + + printf("unicast guid num : %u\n", guid_tbl->uc_tbl.entry_size); + if (guid_tbl->uc_tbl.entry_size > 0) { + printf("| num\t| func id | GUID \n"); + for (cnt = 0; cnt < guid_tbl->uc_tbl.entry_size; cnt++) { + printf("| %3u\t| %7u | ", cnt, guid_tbl->uc_tbl.entry[cnt].function_id); + for (i = 0; i < HIKP_UNIC_GUID_ADDR_LEN - 1; i++) { + printf("%02x:", guid_tbl->uc_tbl.entry[cnt].guid_addr[i]); + } + printf("%02x\n", + guid_tbl->uc_tbl.entry[cnt].guid_addr[HIKP_UNIC_GUID_ADDR_LEN - 1]); + } + } + + printf("multicast guid num : %u\n", guid_tbl->mc_tbl.entry_size); + if (guid_tbl->mc_tbl.entry_size > 0) { + printf("| num\t| idx\t| %-48s\t| bitmap\n", "GUID"); + for (cnt = 0; cnt < guid_tbl->mc_tbl.entry_size; cnt++) { + printf("| %3u\t| %4u\t| ", cnt, guid_tbl->mc_tbl.entry[cnt].idx); + for (i = 0; i < HIKP_UNIC_GUID_ADDR_LEN - 1; i++) { + printf("%02x:", guid_tbl->mc_tbl.entry[cnt].guid_addr[i]); + } + printf("%02x\t| ", + guid_tbl->mc_tbl.entry[cnt].guid_addr[HIKP_UNIC_GUID_ADDR_LEN - 1]); + for (i = HIKP_UNIC_GUID_BITMAP_LEN - 1; i > 0; i--) { + printf("%08x:", guid_tbl->mc_tbl.entry[cnt].function_bitmap[i]); + } + printf("%08x\n", guid_tbl->mc_tbl.entry[cnt].function_bitmap[0]); + } + } +} + +static int hikp_unic_ppp_check_input_param(struct major_cmd_ctrl *self, + const struct unic_ppp_param *ppp_param) +{ + const struct bdf_t *bdf = &ppp_param->target.bdf; + + if (bdf->dev_id != 0) { + snprintf(self->err_str, sizeof(self->err_str), "VF does not support query!"); + self->err_no = -EINVAL; + return self->err_no; + } + + if (ppp_param->feature_idx == UNIC_PPP_INIT_FEATURE_IDX) { + hikp_unic_ppp_cmd_help(self, NULL); + snprintf(self->err_str, sizeof(self->err_str), "-du/--dump parameter error!"); + self->err_no = -EINVAL; + return self->err_no; + } + + return 0; +} + +static void hikp_unic_ppp_data_free(union unic_ppp_feature_info *unic_ppp_data) +{ + struct unic_guid_tbl *guid_tbl; + struct unic_ip_tbl *ip_tbl; + + if (g_unic_ppp_param.feature_idx == UNIC_PPP_IP_FEATURE_IDX) { + ip_tbl = &unic_ppp_data->ip_tbl; + free(ip_tbl->entry); + } else if (g_unic_ppp_param.feature_idx == UNIC_PPP_GUID_FEATURE_IDX) { + guid_tbl = &unic_ppp_data->guid_tbl; + free(guid_tbl->uc_tbl.entry); + free(guid_tbl->mc_tbl.entry); + } + + free(unic_ppp_data); +} + +static void hikp_unic_ppp_cmd_execute(struct major_cmd_ctrl *self) +{ + const struct unic_ppp_feature_cmd *unic_ppp_cmd; + union unic_ppp_feature_info *unic_ppp_data; + struct hikp_cmd_header req_header = {0}; + int ret; + + ret = hikp_unic_ppp_check_input_param(self, &g_unic_ppp_param); + if (ret != 0) + return; + + ret = hikp_unic_get_ppp_entry_hw_res(&g_unic_ppp_param.target.bdf, &g_unic_ppp_hw_res); + if (ret != 0) { + snprintf(self->err_str, sizeof(self->err_str), + "fail to obtain unic_ppp hardware resources."); + self->err_no = ret; + return; + } + + unic_ppp_cmd = &g_unic_ppp_feature_cmd[g_unic_ppp_param.feature_idx]; + unic_ppp_data = hikp_unic_ppp_data_alloc(unic_ppp_cmd, &g_unic_ppp_hw_res); + if (unic_ppp_data == NULL) { + snprintf(self->err_str, sizeof(self->err_str), + "failed to allocate unic_ppp_data memory!"); + self->err_no = -ENOMEM; + return; + } + + hikp_cmd_init(&req_header, UB_MOD, GET_UNIC_PPP_CMD, unic_ppp_cmd->sub_cmd_code); + ret = unic_ppp_cmd->query(&req_header, &g_unic_ppp_param.target.bdf, unic_ppp_data); + if (ret != 0) { + snprintf(self->err_str, sizeof(self->err_str), + "failed to query %s info, ret = %d.", unic_ppp_cmd->feature_name, ret); + self->err_no = ret; + goto out; + } + + printf("############## UNIC_PPP: %s info ############\n", unic_ppp_cmd->feature_name); + unic_ppp_cmd->show(unic_ppp_data); + printf("#################### END #######################\n"); + +out: + hikp_unic_ppp_data_free(unic_ppp_data); +} + +static void cmd_unic_get_ppp_init(void) +{ + struct major_cmd_ctrl *major_cmd = get_major_cmd(); + + g_unic_ppp_param.feature_idx = UNIC_PPP_INIT_FEATURE_IDX; + major_cmd->execute = hikp_unic_ppp_cmd_execute; + + cmd_option_register("-h", "--help", false, hikp_unic_ppp_cmd_help); + cmd_option_register("-i", "--interface", true, hikp_unic_cmd_get_ppp_target); + cmd_option_register("-du", "--dump", true, hikp_unic_cmd_ppp_feature_select); +} + +HIKP_CMD_DECLARE("unic_ppp", "dump ppp info of unic!", cmd_unic_get_ppp_init); \ No newline at end of file diff --git a/net/ub/ub_unic/hikp_unic_ppp.h b/net/ub/ub_unic/hikp_unic_ppp.h new file mode 100644 index 0000000..c25fabd --- /dev/null +++ b/net/ub/ub_unic/hikp_unic_ppp.h @@ -0,0 +1,139 @@ +/* + * Copyright (c) 2023 Hisilicon Technologies Co., Ltd. + * Hikptool is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * + * See the Mulan PSL v2 for more details. + */ + +#ifndef HIKP_UNIC_PPP_H +#define HIKP_UNIC_PPP_H + +#include "hikp_net_lib.h" + +#define HIKP_UNIC_IP_ADDR_FMT_SIZE 50 +#define MAX_IP_ADDR_STR_LEN 50 +#define IP_ADDR_LEN 16 +#define IP_ADDR_TBL_LEN 8 + +#define HIKP_UNIC_IP_ADDR_LEN 4 +#define HIKP_UNIC_GUID_BITMAP_LEN 8 +#define HIKP_UNIC_GUID_ADDR_LEN 16 + +#define UNIC_PPP_MAX_RSP_DATA 57 +#define HIKP_UNIC_PPP_MAX_FEATURE_NAME_LEN 20 + +#define UNIC_PPP_IP_TBL_NAME "ip" +#define UNIC_PPP_GUID_TBL_NAME "guid" + +enum unic_ppp_sub_cmd_type { + UNIC_PPP_ENTRY_HW_SPEC_GET = 0, + UNIC_IP_TBL_DUMP, + UNIC_GUID_TBL_DUMP, +}; + +enum unic_ppp_feature_idx { + UNIC_PPP_IP_FEATURE_IDX = 0, + UNIC_PPP_GUID_FEATURE_IDX, + UNIC_PPP_INIT_FEATURE_IDX = -1, +}; + +struct hikp_unic_ppp_hw_resources { + uint16_t uc_guid_tbl_size; + uint16_t mc_guid_tbl_size; + uint32_t ip_max_mem_size; + uint32_t ip_overflow_size; + uint32_t rsv; + /* port information */ + uint16_t total_func_num; /* contain PF and VF. */ + uint16_t abs_func_id_base; /* The absolute func_id of the first VF in this port. */ + uint32_t rsv1[11]; +}; + +struct unic_ip_entry { + uint32_t index; + uint32_t function_id; + uint32_t ip_addr[HIKP_UNIC_IP_ADDR_LEN]; +}; + +struct unic_ip_tbl { + uint32_t entry_size; + struct unic_ip_entry *entry; +}; + +struct unic_guid_uc_entry { + uint32_t function_id; + uint8_t guid_addr[HIKP_UNIC_GUID_ADDR_LEN]; +}; + +struct unic_guid_uc_tbl { + uint32_t entry_size; + struct unic_guid_uc_entry *entry; +}; + +struct unic_guid_mc_entry { + uint32_t idx; + uint8_t guid_addr[HIKP_UNIC_GUID_ADDR_LEN]; + uint32_t function_bitmap[8]; +}; + +struct unic_guid_mc_tbl { + uint32_t entry_size; + struct unic_guid_mc_entry *entry; +}; + +struct unic_guid_tbl { + struct unic_guid_uc_tbl uc_tbl; + struct unic_guid_mc_tbl mc_tbl; +}; + +union unic_ppp_feature_info { + struct unic_guid_tbl guid_tbl; + struct unic_ip_tbl ip_tbl; +}; + +struct unic_ppp_feature_cmd { + const char feature_name[HIKP_UNIC_PPP_MAX_FEATURE_NAME_LEN]; + uint32_t sub_cmd_code; + bool need_query_hw_res; + int (*query)(struct hikp_cmd_header *req_header, + const struct bdf_t *bdf, void *data); + void (*show)(const void *data); +}; + +struct unic_ppp_param { + struct tool_target target; + int feature_idx; +}; + +struct unic_ppp_req_para { + struct bdf_t bdf; + uint8_t block_id; + union { + uint8_t is_unicast; /* 1: uc GUID, 0: mc GUID. */ + uint8_t rsv; /* firmware ignores it if isn't used to query GUID table. */ + }; + uint8_t rsv1[2]; + uint32_t cur_entry_idx; /* firmware queries GUID/IP table from the value. */ +}; + +struct unic_ppp_rsp_head { + uint8_t total_blk_num; + uint8_t cur_blk_size; /* real data size, not contain head size. */ + uint16_t rsv; + /* firmware must set following fields when query GUID/IP table. */ + uint32_t next_entry_idx; + uint32_t cur_blk_entry_cnt; +}; + +typedef struct unic_ppp_rsp { + struct unic_ppp_rsp_head rsp_head; /* 12 Byte */ + uint32_t rsp_data[UNIC_PPP_MAX_RSP_DATA]; +} unic_ppp_rsp_t; + +#endif /* HIKP_UNIC_PPP_H */
From: veega2022 zhuweijia@huawei.com
Fix a resource release bug in hikp_roh_get_cam_reg_num
Signed-off-by: chenke chenke54@huawei.com --- net/roh/hikp_roh_mac.c | 6 +++++- net/roh/hikp_roh_show_bp.c | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/net/roh/hikp_roh_mac.c b/net/roh/hikp_roh_mac.c index 90708b1..43f954c 100644 --- a/net/roh/hikp_roh_mac.c +++ b/net/roh/hikp_roh_mac.c @@ -141,6 +141,7 @@ static int hikp_roh_get_cam_reg_num(struct major_cmd_ctrl *self) struct roh_mac_req_para req_data = { 0 }; struct hikp_cmd_header req_header = { 0 }; struct hikp_cmd_ret *cmd_ret = NULL; + uint32_t cam_reg_num;
req_data.bdf = g_roh_mac_param.target.bdf; hikp_cmd_init(&req_header, ROH_MOD, HIKP_ROH_MAC, CMD_GET_CAM_REG_NUM); @@ -153,7 +154,10 @@ static int hikp_roh_get_cam_reg_num(struct major_cmd_ctrl *self) return -EIO; } mac_rsp = (struct roh_mac_cam_reg_num *)(cmd_ret->rsp_data); - return mac_rsp->cam_reg_num; + cam_reg_num = mac_rsp->cam_reg_num; + free(cmd_ret); + cmd_ret = NULL; + return cam_reg_num; }
static int hikp_roh_build_cam(struct major_cmd_ctrl *self, struct cam_table_entry_t *cam_table) diff --git a/net/roh/hikp_roh_show_bp.c b/net/roh/hikp_roh_show_bp.c index c89e98b..73a53d8 100644 --- a/net/roh/hikp_roh_show_bp.c +++ b/net/roh/hikp_roh_show_bp.c @@ -44,7 +44,7 @@ static int hikp_roh_show_bp(struct major_cmd_ctrl *self) union bp_val res; uint8_t flit_bp; int mac_id; - int ret; + int ret = 0;
struct hikp_cmd_ret *cmd_ret = NULL; struct hikp_cmd_header req_header = { 0 };
From: veega2022 zhuweijia@huawei.com
Add a space on the left and right of the "="
Signed-off-by: veega2022 zhuweijia@huawei.com --- socip/hikp_socip_dumpreg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/socip/hikp_socip_dumpreg.c b/socip/hikp_socip_dumpreg.c index b74dac8..32325bb 100644 --- a/socip/hikp_socip_dumpreg.c +++ b/socip/hikp_socip_dumpreg.c @@ -142,7 +142,7 @@ static void hikp_socip_dumpreg_execute(struct major_cmd_ctrl *self) hikp_cmd_init(&req_header, SOCIP_MOD, HIKP_SOCIP_CMD_DUMPREG, param[MODULE_ID_INDEX].val); cmd_ret = hikp_cmd_alloc(&req_header, &req_data, sizeof(req_data)); if (!cmd_ret) { - self->err_no=-EINVAL; + self->err_no = -EINVAL; HIKP_ERROR_PRINT("hikp_cmd_alloc\n"); return; }
Delete redundant copyright notices in hikp_ub_link.h
Signed-off-by: veega zhuweijia@huawei.com --- net/ub/ub_link/hikp_ub_link.h | 13 ------------- tool_lib/tool_lib.h | 2 +- 2 files changed, 1 insertion(+), 14 deletions(-)
diff --git a/net/ub/ub_link/hikp_ub_link.h b/net/ub/ub_link/hikp_ub_link.h index 14ee912..7c71cb2 100644 --- a/net/ub/ub_link/hikp_ub_link.h +++ b/net/ub/ub_link/hikp_ub_link.h @@ -11,19 +11,6 @@ * See the Mulan PSL v2 for more details. */
-/* - * Copyright (c) 2023 Hisilicon Technologies Co., Ltd. - * Hikptool is licensed under Mulan PSL v2. - * You can use this software according to the terms and conditions of the Mulan PSL v2. - * You may obtain a copy of Mulan PSL v2 at: - * http://license.coscl.org.cn/MulanPSL2 - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, - * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, - * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * - * See the Mulan PSL v2 for more details. - */ - #ifndef HIKP_UB_LINK_H #define HIKP_UB_LINK_H
diff --git a/tool_lib/tool_lib.h b/tool_lib/tool_lib.h index 9766a7e..6548b57 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.0.15" +#define TOOL_VER "1.0.16"
#define HI_GET_BITFIELD(value, start, mask) (((value) >> (start)) & (mask)) #define HI_SET_FIELD(origin, shift, val) ((origin) |= (val) << (shift))
From: huangguanhua huangguanhua3@huawei.com
Signed-off-by: huangguanhua huangguanhua3@huawei.com --- serdes/hikp_serdes.c | 12 ++++++++---- serdes/hikp_serdes.h | 3 ++- tool_lib/op_logs.c | 6 +++--- 3 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/serdes/hikp_serdes.c b/serdes/hikp_serdes.c index dd9eee3..527fd53 100644 --- a/serdes/hikp_serdes.c +++ b/serdes/hikp_serdes.c @@ -184,21 +184,22 @@ static void hikp_serdes_brief_info_print(struct major_cmd_ctrl *self, "Tap16,Tap17,Tap18,Tap19,Tap20]\n" \ "FWFourEye: It only takes effect when the firmware is running and " \ "continuous adaptation is turned on\n" \ + "Snr: [SNR_METRIC,SNR_METRIC_HIS_MIN,SNR_CYCLES,HEH,SNR_METRIC_SW]\n" \ "-----------------------------------------------------" \ "------------------------------------------------" \ "-----------------------------------------------------" \ "------------------------------------------------" \ - "-------------------\n" \ + "--------------------------------\n" \ " [ FFE ]" \ "[ CTLE ]" \ "[ " \ "DFE ]" \ - "[ FWFourEye ][ snr ]\n" \ + "[ FWFourEye ][ Snr ]\n" \ "-----------------------------------------------------" \ "-------------------------------------------------" \ "-----------------------------------------------------" \ "-------------------------------------------------" \ - "------------------\n") + "--------------------------------\n")
static void hikp_serdes_detail_info_print(struct major_cmd_ctrl *self, const struct hilink_detail_info *data, @@ -233,7 +234,10 @@ static void hikp_serdes_detail_info_print(struct major_cmd_ctrl *self, printf("][%4d,%4d,%4d,%4d]", data[ds_id].eye_diagram.top, data[ds_id].eye_diagram.bottom, data[ds_id].eye_diagram.left, data[ds_id].eye_diagram.right); - printf("[%7d]\n", data[ds_id].snr); + /* 0: SNR_METRIC, 1:SNR_METRIC_HIS_MIN */ + printf("[%3d,%3d,%3d,%3d,%3d]\n", data[ds_id].snr_para[0], data[ds_id].snr_para[1], + /* 2:SNR_CYCLES, 3:HEH, 4:SNR_METRIC_SW */ + data[ds_id].snr_para[2], data[ds_id].snr_para[3], data[ds_id].snr_para[4]); } }
diff --git a/serdes/hikp_serdes.h b/serdes/hikp_serdes.h index 99b9b15..83c28b8 100644 --- a/serdes/hikp_serdes.h +++ b/serdes/hikp_serdes.h @@ -192,7 +192,8 @@ struct hilink_detail_info { struct hilink_rx_param rx_ctle_cfg; struct hilink_serdes_rx_tap rx_tap_cfg; struct hilink_4p_eye_result eye_diagram; - uint32_t snr; + /* 5: (0: SNR_METRIC, 1:SNR_METRIC_HIS_MIN, 2:SNR_CYCLES, 3:HEH, 4:SNR_METRIC_SW) */ + int32_t snr_para[5]; };
struct hilink_brief_info { diff --git a/tool_lib/op_logs.c b/tool_lib/op_logs.c index 069428d..d91ddb0 100644 --- a/tool_lib/op_logs.c +++ b/tool_lib/op_logs.c @@ -431,7 +431,7 @@ void sig_init(void) (void)signal(SIGHUP, signal_handle); (void)signal(SIGSEGV, signal_handle); (void)signal(SIGBUS, signal_handle); - (void)signal(SIGFPE, signal_handle); - (void)signal(SIGABRT, signal_handle); - (void)signal(SIGTSTP, signal_handle); /* Stop process */ + (void)signal(SIGFPE, signal_handle); + (void)signal(SIGABRT, signal_handle); + (void)signal(SIGTSTP, signal_handle); /* Stop process */ }
From: FuJia Ni nifujia1@hisilicon.com
the volatile modifier is added because the O2 compilation optimization is enbaled. As a result, the pointer data is not updated.
Signed-off-by: FuJia Ni nifujia1@hisilicon.com --- sas/sas_func/sas_read_dqe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sas/sas_func/sas_read_dqe.c b/sas/sas_func/sas_read_dqe.c index fc04682..2f653df 100644 --- a/sas/sas_func/sas_read_dqe.c +++ b/sas/sas_func/sas_read_dqe.c @@ -47,7 +47,7 @@ static int sas_get_dqe(const struct tool_sas_cmd *cmd, uint32_t *reg_save, uint3
static void print_dqe_info(const void *reg_save, uint32_t reg_num) { - struct hisi_sas_dq_info *dqe = (struct hisi_sas_dq_info *)(reg_save); + volatile struct hisi_sas_dq_info *dqe = (volatile struct hisi_sas_dq_info *)(reg_save);
printf("The dqe dw0 information as below:\n"); printf("abort_flag: %u\n", dqe->dw0.abort_flag);
delete -g option for release vesion and add compile option: -Wextra -fno-common -std=gnu11 -Wfloat-equal
Signed-off-by: veega zhuweijia@huawei.com --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt index 6a396e7..174dd8f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,8 @@
project(hikptool C)
-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O2 -fPIC -fPIE -Wall") +set(CMAKE_C_FLAGS + "${CMAKE_C_FLAGS} -O2 -fPIC -fPIE -Wall -Wextra -fno-common -std=gnu11 -Wfloat-equal") set(CMAKE_SKIP_RPATH TRUE)
macro(get_header_dir_recurse HEADER_DIR_LIST)
From: m30045533 moubingquan@huawei.com
--- pcie/func_lib/pcie_func/pcie_common.h | 1 + pcie/func_lib/pcie_func/pcie_link_ltssm.c | 180 +++++++++++++++++++++ pcie/func_lib/pcie_func/pcie_link_ltssm.h | 7 + pcie/usr_cmd/cmd_analysis/pcie_cmd_trace.c | 17 +- pcie/usr_cmd/interface/pcie_common_api.c | 1 + pcie/usr_cmd/interface/pcie_common_api.h | 1 + 6 files changed, 205 insertions(+), 2 deletions(-)
diff --git a/pcie/func_lib/pcie_func/pcie_common.h b/pcie/func_lib/pcie_func/pcie_common.h index 434b4ed..98d9e25 100644 --- a/pcie/func_lib/pcie_func/pcie_common.h +++ b/pcie/func_lib/pcie_func/pcie_common.h @@ -28,6 +28,7 @@ enum pcie_trace_cmd_type { TRACE_CLEAR = 2, TRACE_INFO = 3, TRACE_MODE = 4, + TRACE_PM = 5, };
enum pcie_info_cmd_type { diff --git a/pcie/func_lib/pcie_func/pcie_link_ltssm.c b/pcie/func_lib/pcie_func/pcie_link_ltssm.c index d57688b..9c4b70c 100644 --- a/pcie/func_lib/pcie_func/pcie_link_ltssm.c +++ b/pcie/func_lib/pcie_func/pcie_link_ltssm.c @@ -43,6 +43,31 @@ union ltssm_state_reg { uint64_t val; };
+union pm_state_reg { + struct { + uint64_t pm_state : 6; /* [0:5] */ + uint64_t pm_clock : 18; /* [6:23] */ + uint64_t reserved1 : 8; /* [24:31] */ + uint64_t refclk_stable_vld : 1; /* [32] */ + uint64_t enter_l12_case : 1; /* [33] */ + uint64_t pm_t_dl_l2_gnt_timeout : 1; /* [34] */ + uint64_t pm_t_dl_l1_gnt_timeout : 1; /* [35] */ + uint64_t pm_t_dl_l0s_gnt_timeout : 1; /* [36] */ + uint64_t pm_t_dl_lastack_timeout : 1; /* [37] */ + uint64_t pme_turn_off_vld_hold : 1; /* [38] */ + uint64_t pm_blk_tlp_timeout : 1; /* [39] */ + uint64_t aspm_nak_vld : 1; /* [40] */ + uint64_t retrain_link_vld : 1; /* [41] */ + uint64_t pending_dllp_vld : 1; /* [42] */ + uint64_t pm_wakeup_tol0_en : 1; /* [43] */ + uint64_t mac2pm_rx_data_vld : 1; /* [44] */ + uint64_t dfe_req : 1; /* [45] */ + uint64_t pm_t_dfe_time_meet : 1; /* [46] */ + uint64_t reserved2 : 17; /* [47:63] */ + } bits; + uint64_t val; +}; + static int pcie_get_ltssm_trace(uint32_t port_id, uint64_t *ltssm_status, uint32_t *ltssm_num) { struct hikp_cmd_header req_header; @@ -280,3 +305,158 @@ free_cmd_ret:
return ret; } + +static int pcie_get_pm_trace(uint32_t port_id, uint64_t *pm_status, uint32_t *pm_num) +{ + struct hikp_cmd_header req_header; + struct hikp_cmd_ret *cmd_ret = NULL; + struct pcie_trace_req_para req_data = { 0 }; + size_t src_size, dst_size; + int ret; + + req_data.port_id = port_id; + hikp_cmd_init(&req_header, PCIE_MOD, PCIE_TRACE, TRACE_PM); + cmd_ret = hikp_cmd_alloc(&req_header, &req_data, sizeof(req_data)); + ret = hikp_rsp_normal_check(cmd_ret); + if (ret) { + Err("PCIe Base", "pcie pm trace cmd_ret check failed, ret: %d.\n", ret); + goto free_cmd_ret; + } + + if (cmd_ret->rsp_data_num == 0) { + Err("PCIe Base", "without rsp data.\n"); + ret = -EINVAL; + goto free_cmd_ret; + } + /* 0: First uint32_t is pm trace num received from TF */ + *pm_num = cmd_ret->rsp_data[0]; + + if ((cmd_ret->rsp_data_num - 1) * sizeof(uint32_t) != (*pm_num) * sizeof(uint64_t)) { + Err("PCIe Base", "rsp data number check failed, rsp_data_num: %u, pm_num: %u.\n", + cmd_ret->rsp_data_num, *pm_num); + ret = -EINVAL; + goto free_cmd_ret; + } + + src_size = (*pm_num) * sizeof(uint64_t); + dst_size = TRACER_DEPTH * sizeof(uint64_t); + if (src_size > dst_size) { + Err("PCIe Base", "size check failed, %u > %u.\n", src_size, dst_size); + ret = -EINVAL; + goto free_cmd_ret; + } + memcpy(pm_status, (cmd_ret->rsp_data + 1), src_size); + +free_cmd_ret: + free(cmd_ret); + return ret; +} + +struct pcie_pm_num_string g_pm_string_table[] = { + {0x0, "pm_pme_idle"}, + {0x1, "pm_wait_dc_pme_msg_send_out"}, + {0x2, "pm_wait_dc_tl_enter_l2"}, + {0x3, "pm_wait_dc_dl_enter_l2"}, + {0x4, "pm_wait_dc_mac_enter_l2"}, + {0x5, "pm_dc_enter_l2"}, + {0x6, "pm_wait_dc_tl_enter_pcipm_l1"}, + {0x7, "pm_wait_dc_dl_enter_pcipm_l1"}, + {0x8, "pm_wait_dc_tl_enter_aspm_l1"}, + {0x9, "pm_wait_dc_dl_enter_aspm_l1"}, + {0xa, "pm_wait_tl_enter_aspm_l0"}, + {0xb, "pm_wait_dl_enter_aspm_l0"}, + {0xc, "pm_wait_dc_mac_enter_l1"}, + {0xd, "pm_wait_mac_enter_l0s"}, + {0xe, "pm_device_in_l0s"}, + {0xf, "pm_dc_device_in_l1"}, + {0x10, "pm_wait_dc_enter_l0"}, + {0x11, "pm_wait_uc_tl_enter_l2"}, + {0x12, "pm_wait_uc_dl_enter_l2"}, + {0x13, "pm_wait_uc_mac_enter_l2"}, + {0x15, "pm_wait_uc_tl_enter_pcipm_l1"}, + {0x17, "pm_wait_uc_dl_enter_aspm_l1"}, + {0x18, "pm_wait_uc_tl_enter_aspm_l1"}, + {0x1a, "pm_wait_uc_dl_enter_pcipm_l1"}, + {0x1c, "pm_wait_uc_mac_enter_l1"}, + {0x1d, "pm_wait_uc_pme_enter_l1_nak_sent_out"}, + {0x1e, "pm_wait_uc_enter_l0"}, + {0x20, "pm_device_will_enter_l1_substate"}, + {0x21, "pm_device_in_l1_1"}, + {0x22, "pm_device_will_exit_l1_substate"}, + {0x23, "pm_device_in_l1_2_entry"}, + {0x24, "pm_device_in_l1_2_idle"}, + {0x25, "pm_device_in_l1_2_exit"}, + {-1, "unknown"} /* end of array */ +}; + +static char *hisi_pcie_pm_string_get(uint32_t pm) +{ + int i = 0; + + while (g_pm_string_table[i].pm >= 0) { + if ((uint32_t)g_pm_string_table[i].pm != pm) { + i++; + continue; + } + break; + } + + return g_pm_string_table[i].pm_c; +} + +static int pcie_print_pm_trace(const uint64_t *pm_status, uint32_t pm_num) +{ + uint32_t i; + char *pm_c = NULL; + union pm_state_reg pm_val; + + if (pm_num > TRACER_DEPTH || pm_num == 0) { + Err("PCIe Base", "pm_num(%u) is over range or zero\n", pm_num); + return -EINVAL; + } + Info("PCIe Base", "pm tracer:\n"); + Info("PCIe Base", "\ttrace state: %llx\n", pm_status[0]); + Info("PCIe Base", + "\tpm[ii]: BE8: 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 " + "BD8: 23:6 5:0 : pm state\n"); + for (i = 1; i < pm_num; i++) { + pm_val.val = pm_status[i]; + pm_c = hisi_pcie_pm_string_get((uint32_t)pm_val.bits.pm_state); + Info("PCIe Base", + "\tpm[%02u]:\t %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x 0x%06x 0x%02x %s\n", + i, + (uint32_t)pm_val.bits.pm_t_dfe_time_meet, + (uint32_t)pm_val.bits.dfe_req, + (uint32_t)pm_val.bits.mac2pm_rx_data_vld, + (uint32_t)pm_val.bits.pm_wakeup_tol0_en, + (uint32_t)pm_val.bits.pending_dllp_vld, + (uint32_t)pm_val.bits.retrain_link_vld, + (uint32_t)pm_val.bits.aspm_nak_vld, + (uint32_t)pm_val.bits.pm_blk_tlp_timeout, + (uint32_t)pm_val.bits.pme_turn_off_vld_hold, + (uint32_t)pm_val.bits.pm_t_dl_lastack_timeout, + (uint32_t)pm_val.bits.pm_t_dl_l0s_gnt_timeout, + (uint32_t)pm_val.bits.pm_t_dl_l1_gnt_timeout, + (uint32_t)pm_val.bits.pm_t_dl_l2_gnt_timeout, + (uint32_t)pm_val.bits.enter_l12_case, + (uint32_t)pm_val.bits.refclk_stable_vld, + (uint32_t)pm_val.bits.pm_clock, + (uint32_t)pm_val.bits.pm_state, + pm_c); + } + + return 0; +} + +int pcie_pm_trace(uint32_t port_id) +{ + int ret; + uint32_t pm_num = 0; + uint64_t pm_st_save[TRACER_DEPTH]; + + ret = pcie_get_pm_trace(port_id, pm_st_save, &pm_num); + if (ret) + return ret; + + return pcie_print_pm_trace(pm_st_save, pm_num); +} \ No newline at end of file diff --git a/pcie/func_lib/pcie_func/pcie_link_ltssm.h b/pcie/func_lib/pcie_func/pcie_link_ltssm.h index eb57ead..8f3502b 100644 --- a/pcie/func_lib/pcie_func/pcie_link_ltssm.h +++ b/pcie/func_lib/pcie_func/pcie_link_ltssm.h @@ -18,12 +18,18 @@
#define TRACE_STR_NUM 0x20 #define TRACER_DEPTH 65 +#define PM_TRACE_STR_NUM 0x28
struct pcie_ltssm_num_string { int ltssm; char ltssm_c[TRACE_STR_NUM]; };
+struct pcie_pm_num_string { + int pm; + char pm_c[PM_TRACE_STR_NUM]; +}; + struct pcie_trace_req_para { uint32_t port_id; uint32_t trace_mode; @@ -51,5 +57,6 @@ int pcie_ltssm_trace_show(uint32_t port_id); int pcie_ltssm_trace_clear(uint32_t port_id); int pcie_ltssm_trace_mode_set(uint32_t port_id, uint32_t mode); int pcie_ltssm_link_status_get(uint32_t port_id); +int pcie_pm_trace(uint32_t port_id);
#endif diff --git a/pcie/usr_cmd/cmd_analysis/pcie_cmd_trace.c b/pcie/usr_cmd/cmd_analysis/pcie_cmd_trace.c index e50b434..8ceb85a 100644 --- a/pcie/usr_cmd/cmd_analysis/pcie_cmd_trace.c +++ b/pcie/usr_cmd/cmd_analysis/pcie_cmd_trace.c @@ -37,6 +37,7 @@ static int pcie_trace_help(struct major_cmd_ctrl *self, const char *argv) printf(" %s, %-25s %s\n", "-m", "--mode", "set ltssm trace mode val 1:recver_en 0:recver_dis\n"); printf(" %s, %-25s %s\n", "-f", "--information", "display link information\n"); + printf(" %s, %-25s %s\n", "-pm", "--pm-state", "show pm status\n"); printf("\n");
return 0; @@ -57,6 +58,13 @@ static int pcie_trace_show(struct major_cmd_ctrl *self, const char *argv) return 0; }
+static int pcie_pm_show(struct major_cmd_ctrl *self, const char *argv) +{ + g_trace_cmd.cmd_type = TRACE_PM; + + return 0; +} + static int pcie_trace_mode_set(struct major_cmd_ctrl *self, const char *argv) { int ret; @@ -108,6 +116,8 @@ static int pcie_trace_excute_funs_call(int cmd_type) return comm_api->ltssm_trace_mode_set(port_id, recover_en); else if (cmd_type == TRACE_INFO) return comm_api->ltssm_link_information_get(port_id); + else if (cmd_type == TRACE_PM) + return comm_api->pm_trace(port_id); else return -EINVAL; } @@ -120,14 +130,16 @@ static void pcie_trace_execute(struct major_cmd_ctrl *self) "pcie_trace_show success.", "pcie_trace_clear success.", "get mac link information success.", - "pcie_trace_mode_set success." + "pcie_trace_mode_set success.", + "pcie_pm_trace success." }; const char *err_msg[] = { "pcie_trace sub command type error.", "pcie_trace_show error.", "pcie_trace_clear error.", "get mac link information error.", - "pcie_trace_mode_set error." + "pcie_trace_mode_set error.", + "pcie_pm_trace error" };
ret = pcie_trace_excute_funs_call(g_trace_cmd.cmd_type); @@ -153,6 +165,7 @@ static void cmd_pcie_trace_init(void) cmd_option_register("-m", "--mode", true, pcie_trace_mode_set); cmd_option_register("-f", "--information", false, pcie_link_information_get); cmd_option_register("-i", "--interface", true, pcie_port_id_set); + cmd_option_register("-pm", "--pm-state", false, pcie_pm_show); }
HIKP_CMD_DECLARE("pcie_trace", "pcie ltssm trace", cmd_pcie_trace_init); diff --git a/pcie/usr_cmd/interface/pcie_common_api.c b/pcie/usr_cmd/interface/pcie_common_api.c index 491daf2..8875481 100644 --- a/pcie/usr_cmd/interface/pcie_common_api.c +++ b/pcie/usr_cmd/interface/pcie_common_api.c @@ -27,6 +27,7 @@ struct pcie_comm_api g_tools_api = { .err_status_clear = pcie_error_state_clear, .reg_dump = pcie_dumpreg_do_dump, .reg_read = pcie_reg_read, + .pm_trace = pcie_pm_trace, };
diff --git a/pcie/usr_cmd/interface/pcie_common_api.h b/pcie/usr_cmd/interface/pcie_common_api.h index 9809575..08d4403 100644 --- a/pcie/usr_cmd/interface/pcie_common_api.h +++ b/pcie/usr_cmd/interface/pcie_common_api.h @@ -37,6 +37,7 @@ struct pcie_comm_api { int (*err_status_clear)(uint32_t port_id); int (*reg_dump)(uint32_t port_id, uint32_t dump_level); int (*reg_read)(uint32_t port_id, uint32_t moudle_id, uint32_t offset); + int (*pm_trace)(uint32_t port_id); };
struct pcie_comm_api *pcie_get_comm_api(void);
add -fstack-protector-strong and -D_FORTIFY_SOURCE=2 compiler options for SP and FS. add -s link options for Strip.
Signed-off-by: veega zhuweijia@huawei.com --- CMakeLists.txt | 6 +++--- libhikptdev/src/rciep/CMakeLists.txt | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt index 174dd8f..cbd063c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,8 +11,8 @@
project(hikptool C)
-set(CMAKE_C_FLAGS - "${CMAKE_C_FLAGS} -O2 -fPIC -fPIE -Wall -Wextra -fno-common -std=gnu11 -Wfloat-equal") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 -fPIC -fPIE -Wall -Wextra -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)
macro(get_header_dir_recurse HEADER_DIR_LIST) @@ -46,5 +46,5 @@ target_link_directories(hikptool PRIVATE ${CMAKE_INSTALL_PREFIX}/lib) target_link_libraries(hikptool PRIVATE KPTDEV_SO) target_link_options(hikptool PRIVATE -Wl,-z,relro,-z,now -Wl,-z,noexecstack -fPIE -pie - -g -lpthread -ldl -lm -lrt -T ${CMAKE_CURRENT_SOURCE_DIR}/hikp_register.ld) + -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 b96d621..5017f5b 100644 --- a/libhikptdev/src/rciep/CMakeLists.txt +++ b/libhikptdev/src/rciep/CMakeLists.txt @@ -17,5 +17,7 @@ add_library(KPTDEV_SO SHARED hikpt_rciep.c)
target_include_directories(KPTDEV_SO PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../include)
+target_link_options(KPTDEV_SO PRIVATE -Wl,-z,relro,-z,now -Wl,-z,noexecstack -fPIE -pie -s) + set_target_properties(KPTDEV_SO PROPERTIES OUTPUT_NAME ${KPTDEV_SO_NAME} SOVERSION 1 VERSION 1.0.0) -install(TARGETS KPTDEV_SO LIBRARY DESTINATION lib OPTIONAL) \ No newline at end of file +install(TARGETS KPTDEV_SO LIBRARY DESTINATION lib OPTIONAL)
add arbitration information print in port ARB LINK INFO display area, and PHY INFO display area for print PHY config and regs
Signed-off-by: veega zhuweijia@huawei.com --- net/nic/nic_mac/hikp_nic_port.c | 4 +++- net/nic/nic_mac/hikp_nic_port.h | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/net/nic/nic_mac/hikp_nic_port.c b/net/nic/nic_mac/hikp_nic_port.c index 1ff3569..22a6467 100644 --- a/net/nic/nic_mac/hikp_nic_port.c +++ b/net/nic/nic_mac/hikp_nic_port.c @@ -355,6 +355,7 @@ static void mac_cmd_disp_arb_info(const struct mac_cmd_arb_dfx *arb_dfx) mac_cmd_disp_port_param("Default", &arb_dfx->default_cfg); mac_cmd_disp_port_param("BIOS", &arb_dfx->bios_cfg); mac_cmd_disp_port_param("TOOL", &arb_dfx->user_cfg); + mac_cmd_disp_port_param("ARB", &arb_dfx->arb_cfg); mac_cmd_disp_port_param("Final", &arb_dfx->port_cfg); }
@@ -443,7 +444,8 @@ static void mac_cmd_port_execute(struct major_cmd_ctrl *self) }
port_hw = (struct mac_cmd_port_hardware *)(hw_cmd_ret->rsp_data); - if (port_hw->port_type == 1) + if (port_hw->port_type == HIKP_PORT_TYPE_PHY || + port_hw->port_type == HIKP_PORT_TYPE_PHY_SDS) mask |= MAC_LSPORT_PHY;
mac_cmd_show_port_dfx(self, mask); diff --git a/net/nic/nic_mac/hikp_nic_port.h b/net/nic/nic_mac/hikp_nic_port.h index ac00f55..f6334d0 100644 --- a/net/nic/nic_mac/hikp_nic_port.h +++ b/net/nic/nic_mac/hikp_nic_port.h @@ -95,6 +95,9 @@ enum { #define HIKP_MAC_PHY_ABI_PAUSE HI_BIT(13) #define HIKP_MAC_PHY_ABI_ASYM_PAUSE HI_BIT(14)
+#define HIKP_PORT_TYPE_PHY 1 +#define HIKP_PORT_TYPE_PHY_SDS 3 + struct mac_item { uint32_t key; const char *name; @@ -151,6 +154,7 @@ struct mac_cmd_arb_dfx { struct mac_port_param bios_cfg; struct mac_port_param user_cfg; struct mac_port_param port_cfg; + struct mac_port_param arb_cfg; };
#define MAC_PHY_DFX_REG_NUM 12
From: m30045533 moubingquan@huawei.com
--- pcie/func_lib/pcie_func/pcie_link_ltssm.c | 41 ++-- pcie/func_lib/pcie_func/pcie_reg_dump.c | 235 +++++++++++++++------- pcie/func_lib/pcie_func/pcie_reg_dump.h | 5 + 3 files changed, 189 insertions(+), 92 deletions(-)
diff --git a/pcie/func_lib/pcie_func/pcie_link_ltssm.c b/pcie/func_lib/pcie_func/pcie_link_ltssm.c index 9c4b70c..09d3b5e 100644 --- a/pcie/func_lib/pcie_func/pcie_link_ltssm.c +++ b/pcie/func_lib/pcie_func/pcie_link_ltssm.c @@ -45,25 +45,25 @@ union ltssm_state_reg {
union pm_state_reg { struct { - uint64_t pm_state : 6; /* [0:5] */ - uint64_t pm_clock : 18; /* [6:23] */ - uint64_t reserved1 : 8; /* [24:31] */ - uint64_t refclk_stable_vld : 1; /* [32] */ - uint64_t enter_l12_case : 1; /* [33] */ - uint64_t pm_t_dl_l2_gnt_timeout : 1; /* [34] */ - uint64_t pm_t_dl_l1_gnt_timeout : 1; /* [35] */ - uint64_t pm_t_dl_l0s_gnt_timeout : 1; /* [36] */ - uint64_t pm_t_dl_lastack_timeout : 1; /* [37] */ - uint64_t pme_turn_off_vld_hold : 1; /* [38] */ - uint64_t pm_blk_tlp_timeout : 1; /* [39] */ - uint64_t aspm_nak_vld : 1; /* [40] */ - uint64_t retrain_link_vld : 1; /* [41] */ - uint64_t pending_dllp_vld : 1; /* [42] */ - uint64_t pm_wakeup_tol0_en : 1; /* [43] */ - uint64_t mac2pm_rx_data_vld : 1; /* [44] */ - uint64_t dfe_req : 1; /* [45] */ - uint64_t pm_t_dfe_time_meet : 1; /* [46] */ - uint64_t reserved2 : 17; /* [47:63] */ + uint64_t pm_state : 6; /* [0:5] */ + uint64_t pm_clock : 18; /* [6:23] */ + uint64_t reserved1 : 8; /* [24:31] */ + uint64_t refclk_stable_vld : 1; /* [32] */ + uint64_t enter_l12_case : 1; /* [33] */ + uint64_t pm_t_dl_l2_gnt_timeout : 1; /* [34] */ + uint64_t pm_t_dl_l1_gnt_timeout : 1; /* [35] */ + uint64_t pm_t_dl_l0s_gnt_timeout : 1; /* [36] */ + uint64_t pm_t_dl_lastack_timeout : 1; /* [37] */ + uint64_t pme_turn_off_vld_hold : 1; /* [38] */ + uint64_t pm_blk_tlp_timeout : 1; /* [39] */ + uint64_t aspm_nak_vld : 1; /* [40] */ + uint64_t retrain_link_vld : 1; /* [41] */ + uint64_t pending_dllp_vld : 1; /* [42] */ + uint64_t pm_wakeup_tol0_en : 1; /* [43] */ + uint64_t mac2pm_rx_data_vld : 1; /* [44] */ + uint64_t dfe_req : 1; /* [45] */ + uint64_t pm_t_dfe_time_meet : 1; /* [46] */ + uint64_t reserved2 : 17; /* [47:63] */ } bits; uint64_t val; }; @@ -423,7 +423,8 @@ static int pcie_print_pm_trace(const uint64_t *pm_status, uint32_t pm_num) pm_val.val = pm_status[i]; pm_c = hisi_pcie_pm_string_get((uint32_t)pm_val.bits.pm_state); Info("PCIe Base", - "\tpm[%02u]:\t %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x 0x%06x 0x%02x %s\n", + "\tpm[%02u]:\t %x %x %x %x %x %x %x %x %x %x %x " + "%x %x %x %x 0x%06x 0x%02x %s\n", i, (uint32_t)pm_val.bits.pm_t_dfe_time_meet, (uint32_t)pm_val.bits.dfe_req, diff --git a/pcie/func_lib/pcie_func/pcie_reg_dump.c b/pcie/func_lib/pcie_func/pcie_reg_dump.c index e10ff7e..aac3843 100644 --- a/pcie/func_lib/pcie_func/pcie_reg_dump.c +++ b/pcie/func_lib/pcie_func/pcie_reg_dump.c @@ -66,6 +66,8 @@ struct pcie_dumpreg_info g_reg_table_tl[] = { {0, "TL_RX_LOC_TLP_CNT"}, {0, "TL_RX_ERR_STATUS"}, {0, "TL_CFGSPACE_BDF"}, + {0, "TL_TX_UR_CNT"}, + {0, "TL_RX_ERR_STATUS"}, };
struct pcie_dumpreg_info g_reg_table_dl[] = { @@ -105,6 +107,28 @@ struct pcie_dumpreg_info g_reg_table_mac[] = { {0, "MAC_REG_FE_INT_RO"}, {0, "MAC_REG_CE_INT_RO"}, {0, "MAC_REG_NFE_INT_RO"}, + {0, "MAC_REG_EQ_FIX_LP_TX_PRESET"}, + {0, "MAC_REG_ESM_32G_EQ_FIX_LP_TX_PRESET"}, + {0, "MAC_REG_ADJ_HILINK_MODE_EN"}, + {0, "MAC_REG_EQ_OPT_TX_PRESET_1"}, + {0, "MAC_REG_LP_GEN3_TX_PRESET_P1_2"}, + {0, "MAC_REG_GEN3_EQ_OPT_TX_PRESET_2"}, + {0, "MAC_REG_GEN4_EQ_OPT_TX_PRESET_1"}, + {0, "MAC_REG_GEN4_EQ_OPT_TX_PRESET_2"}, + {0, "MAC_REG_LP_GEN4_TX_PRESET_P1_1"}, + {0, "MAC_REG_LP_GEN4_TX_PRESET_P1_2"}, + {0, "MAC_REG_DEBUG_PIPE1"}, + {0, "MAC_REG_DEBUG_PIPE2"}, + {0, "MAC_REG_DEBUG_PIPE3"}, + {0, "MAC_REG_DEBUG_PIPE5"}, + {0, "MAC_REG_DEBUG_PIPE7"}, + {0, "MAC_REG_DEBUG_PIPE8"}, + {0, "MAC_REG_DEBUG_PIPE9"}, + {0, "MAC_REG_DEBUG_PIPE10"}, + {0, "MAC_REG_DEBUG_PIPE11"}, + {0, "MAC_LEAVE_L0_INFO"}, + {0, "DFX_APB_LANE_ERROR_STATUS_0"}, + {0, "DFX_APB_LANE_ERROR_STATUS_1"}, };
struct pcie_dumpreg_info g_reg_table_pcs[] = { @@ -115,6 +139,8 @@ struct pcie_dumpreg_info g_reg_table_pcs[] = { HIKP_PCIE_PCS_LANE_TBL_ENTRY(RECV_DET_OR_PWR_CHAGE), HIKP_PCIE_PCS_LANE_TBL_ENTRY(EQEVAL_STATUS), 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), };
struct pcie_dumpreg_info g_reg_table_iob_tx[] = { @@ -141,6 +167,71 @@ struct pcie_dumpreg_info g_reg_table_iob_tx[] = { {0, "IOB_TX_INT_SEVERITY3"}, {0, "IOB_TX_INT_SEVERITY4"}, {0, "IOB_TX_INT_SEVERITY5"}, + {0, "IOB_TX_TCS_DEC_ERR_INFO_L"}, + {0, "IOB_TX_TCS_DEC_ERR_INFO_H"}, + {0, "DFX_IOB_TX_P_CNT_0"}, + {0, "DFX_IOB_TX_P_CNT_1"}, + {0, "DFX_IOB_TX_P_CNT_2"}, + {0, "DFX_IOB_TX_P_CNT_3"}, + {0, "DFX_IOB_TX_P_CNT_4"}, + {0, "DFX_IOB_TX_NP_CNT_0"}, + {0, "DFX_IOB_TX_NP_CNT_1"}, + {0, "DFX_IOB_TX_NP_CNT_2"}, + {0, "DFX_IOB_TX_NP_CNT_3"}, + {0, "DFX_IOB_TX_NP_CNT_4"}, + {0, "DFX_IOB_TX_NP_CNT_5"}, + {0, "DFX_IOB_TX_NP_CNT_6"}, + {0, "DFX_IOB_TX_NP_CNT_7"}, + {0, "DFX_IOB_TX_NP_CNT_8"}, + {0, "DFX_IOB_TX_NP_CNT_9"}, + {0, "DFX_IOB_TX_NP_CNT_10"}, + {0, "DFX_IOB_TX_NP_CNT_11"}, + {0, "DFX_IOB_TX_CPL_CNT_0"}, + {0, "DFX_IOB_TX_CPL_CNT_1"}, + {0, "DFX_IOB_TX_CPL_CNT_2"}, + {0, "DFX_IOB_TX_REQ_CNT"}, + {0, "DFX_IOB_TX_STATUS0"}, + {0, "DFX_IOB_TX_STATUS1"}, + {0, "DFX_IOB_TX_STATUS2"}, + {0, "DFX_IOB_TX_STATUS3"}, + {0, "DFX_IOB_TX_STATUS4"}, + {0, "DFX_IOB_TX_STATUS5"}, + {0, "DFX_IOB_TX_ABNORMAL_CNT_0"}, + {0, "DFX_IOB_TX_ABNORMAL_CNT_1"}, + {0, "DFX_IOB_TX_ABNORMAL_CNT_2"}, + {0, "DFX_IOB_TX_ABNORMAL_CNT_3"}, + {0, "DFX_IOB_TX_ERROR0"}, + {0, "DFX_IOB_TX_ERROR1"}, + {0, "DFX_IOB_TX_TCS_NORMAL_CNT_0"}, + {0, "DFX_IOB_TX_TCS_NORMAL_CNT_1"}, + {0, "DFX_IOB_TX_TCS_NORMAL_CNT_2"}, + {0, "DFX_IOB_TX_TCS_NORMAL_CNT_3"}, + {0, "DFX_IOB_TX_TCS_NORMAL_CNT_4"}, + {0, "DFX_IOB_TX_TCS_NORMAL_CNT_5"}, + {0, "DFX_IOB_TX_TCS_NORMAL_CNT_6"}, + {0, "DFX_IOB_TX_TCS_NORMAL_CNT_7"}, + {0, "DFX_IOB_TX_TCS_NORMAL_CNT_8"}, + {0, "DFX_IOB_TX_TCS_NORMAL_CNT_9"}, + {0, "DFX_IOB_TX_TCS_NORMAL_CNT_10"}, + {0, "DFX_IOB_TX_TCS_NORMAL_CNT_11"}, + {0, "DFX_IOB_TX_TCS_NORMAL_CNT_12"}, + {0, "DFX_IOB_TX_TCS_NORMAL_CNT_13"}, + {0, "DFX_IOB_TX_TCS_NORMAL_CNT_14"}, + {0, "DFX_IOB_TX_TCS_NORMAL_CNT_15"}, + {0, "DFX_IOB_TX_TCS_P2P_CNT_0"}, + {0, "DFX_IOB_TX_TCS_P2P_CNT_1"}, + {0, "DFX_IOB_TX_TCS_P2P_CNT_2"}, + {0, "DFX_IOB_TX_TCS_P2P_CNT_3"}, + {0, "DFX_IOB_TX_TCS_P2P_CNT_4"}, + {0, "DFX_IOB_TX_TCS_P2P_CNT_5"}, + {0, "DFX_IOB_TX_TCS_P2P_CNT_6"}, + {0, "DFX_IOB_TX_TCS_P2P_CNT_7"}, + {0, "DFX_IOB_TX_TCS_ARNORAML_CNT_0"}, + {0, "DFX_IOB_TX_TCS_ARNORAML_CNT_1"}, + {0, "DFX_IOB_TX_TCS_STATUS0"}, + {0, "DFX_IOB_TX_TCS_STATUS1"}, + {0, "DFX_IOB_TX_TCS_STATUS2"}, + {0, "DFX_IOB_TX_TCS_IDLE"}, };
struct pcie_dumpreg_info g_reg_table_iob_rx[] = { @@ -150,6 +241,19 @@ struct pcie_dumpreg_info g_reg_table_iob_rx[] = { {0, "IOB_RX_MSI_MSIX_CTRL_0"}, {0, "IOB_RX_MSI_MSIX_ADDR_HIGH_0"}, {0, "IOB_RX_MSI_MSIX_ADDR_LOW_0"}, + {0, "DFX_IOB_RX_CNT_RX_REQ"}, + {0, "DFX_IOB_RX_CNT_LOC_REQ"}, + {0, "DFX_IOB_RX_CNT_SEND_AM"}, + {0, "DFX_IOB_RX_CNT_SEND_LOC"}, + {0, "DFX_IOB_RX_CNT_RESP_RX"}, + {0, "DFX_IOB_RX_CNT_RESP_LOC"}, + {0, "DFX_IOB_RX_CNT_RESP_RECV"}, + {0, "IOB_RX_INT_STATUS"}, + {0, "DFX_IOB_RX_AMB_WR_CNT_0"}, + {0, "DFX_IOB_RX_AMB_WR_CNT_1"}, + {0, "DFX_IOB_RX_AMB_RD_CNT_0"}, + {0, "DFX_IOB_RX_AMB_RD_CNT_1"}, + {0, "DFX_IOB_RX_AMB_INT_NUM"}, };
struct pcie_dumpreg_info g_reg_table_ap_glb[] = { @@ -256,6 +360,30 @@ struct pcie_dumpreg_info g_reg_table_core_glb[] = { {0, "CORE_INT_FE_MSK_2"}, {0, "CORE_INT_FE_STATUS_2"}, {0, "CORE_INT_FE_RO_2"}, + {0, "PORT07_LINK_MODE"}, + {0, "PORT815_LINK_MODE"}, +}; + +struct pcie_dumpreg_info g_reg_table_core_tl[] = { + {0, "TL_PM_AUTO_EXIT_TIME_VALUE"}, + {0, "TL_DFX_PM_CORE_FUNC_EN"}, + {0, "TL_PM_DFE_TIME_VALUE"}, +}; + +struct pcie_dumpreg_info g_reg_table_dfx_core_tl[] = { + {0, "TL_TX_ASYN_FIFO_ST"}, + {0, "TL_TX_INGRESS_CNT"}, + {0, "TL_TX_CTRL_EGRESS_CNT"}, + {0, "TL_TX_CFG_CNT"}, + {0, "TL_TX_MEM_RD_CNT"}, + {0, "TL_TX_MEM_WR_CNT"}, + {0, "TL_TX_IO_RD_CNT"}, + {0, "TL_TX_IO_WR_CNT"}, + {0, "TL_TX_MSG_CNT"}, + {0, "TL_TX_CPL_CNT"}, + {0, "TL_TX_ATOMIC_CNT"}, + {0, "TL_TX_CFG_TX_CNT"}, + {0, "TL_TX_GEN_CPL_CNT"}, };
static int pcie_create_dumpreg_log_file(uint32_t port_id, uint32_t dump_level) @@ -315,73 +443,33 @@ static void pcie_dumpreg_write_value_to_file(const char *reg_name, uint32_t val) } }
-static void pcie_dumpreg_save_glb_analysis_log(const uint32_t *data, uint32_t data_num) -{ - uint32_t item_i, data_i; - - data_i = 0; - /* IOB_TX REG */ - for (item_i = 0; item_i < HIKP_ARRAY_SIZE(g_reg_table_iob_tx) && - data_i < data_num; item_i++, data_i++) { - g_reg_table_iob_tx[item_i].val = data[data_i]; - pcie_dumpreg_write_value_to_file(g_reg_table_iob_tx[item_i].name, - g_reg_table_iob_tx[item_i].val); - } - /* IOB_RX REG */ - for (item_i = 0; item_i < HIKP_ARRAY_SIZE(g_reg_table_iob_rx) && - data_i < data_num; item_i++, data_i++) { - g_reg_table_iob_rx[item_i].val = data[data_i]; - pcie_dumpreg_write_value_to_file(g_reg_table_iob_rx[item_i].name, - g_reg_table_iob_rx[item_i].val); - } - /* AP_GLB REG */ - for (item_i = 0; item_i < HIKP_ARRAY_SIZE(g_reg_table_ap_glb) && - data_i < data_num; item_i++, data_i++) { - g_reg_table_ap_glb[item_i].val = data[data_i]; - pcie_dumpreg_write_value_to_file(g_reg_table_ap_glb[item_i].name, - g_reg_table_ap_glb[item_i].val); - } - /* CORE_GLB REG */ - for (item_i = 0; item_i < HIKP_ARRAY_SIZE(g_reg_table_core_glb) && - data_i < data_num; item_i++, data_i++) { - g_reg_table_core_glb[item_i].val = data[data_i]; - pcie_dumpreg_write_value_to_file(g_reg_table_core_glb[item_i].name, - g_reg_table_core_glb[item_i].val); - } - /* PCS REG */ - for (item_i = 0; item_i < HIKP_ARRAY_SIZE(g_reg_table_pcs) && - data_i < data_num; item_i++, data_i++) { - g_reg_table_pcs[item_i].val = data[data_i]; - pcie_dumpreg_write_value_to_file(g_reg_table_pcs[item_i].name, - g_reg_table_pcs[item_i].val); - } -} +struct pcie_dumpreg_table g_dump_info_glb[] = { + {HIKP_ARRAY_SIZE(g_reg_table_iob_tx), g_reg_table_iob_tx}, + {HIKP_ARRAY_SIZE(g_reg_table_iob_rx), g_reg_table_iob_rx}, + {HIKP_ARRAY_SIZE(g_reg_table_ap_glb), g_reg_table_ap_glb}, + {HIKP_ARRAY_SIZE(g_reg_table_core_glb), g_reg_table_core_glb}, + {HIKP_ARRAY_SIZE(g_reg_table_pcs), g_reg_table_pcs}, + {HIKP_ARRAY_SIZE(g_reg_table_core_tl), g_reg_table_core_tl}, + {HIKP_ARRAY_SIZE(g_reg_table_dfx_core_tl), g_reg_table_dfx_core_tl}, +};
-static void pcie_dumpreg_save_port_analysis_log(uint32_t *data, uint32_t data_num) +struct pcie_dumpreg_table g_dump_info_port[] = { + {HIKP_ARRAY_SIZE(g_reg_table_tl), g_reg_table_tl}, + {HIKP_ARRAY_SIZE(g_reg_table_dl), g_reg_table_dl}, + {HIKP_ARRAY_SIZE(g_reg_table_mac), g_reg_table_mac}, +}; + +static void pcie_dumpreg_save_analysis_log(const uint32_t *data, uint32_t data_num, + struct pcie_dumpreg_table *table, uint32_t size) { - uint32_t item_i, data_i; - - data_i = 0; - /* TL REG */ - for (item_i = 0; item_i < HIKP_ARRAY_SIZE(g_reg_table_tl) && - data_i < data_num; item_i++, data_i++) { - g_reg_table_tl[item_i].val = data[data_i]; - pcie_dumpreg_write_value_to_file(g_reg_table_tl[item_i].name, - g_reg_table_tl[item_i].val); - } - /* DL REG */ - for (item_i = 0; item_i < HIKP_ARRAY_SIZE(g_reg_table_dl) && - data_i < data_num; item_i++, data_i++) { - g_reg_table_dl[item_i].val = data[data_i]; - pcie_dumpreg_write_value_to_file(g_reg_table_dl[item_i].name, - g_reg_table_dl[item_i].val); - } - /* MAC REG */ - for (item_i = 0; item_i < HIKP_ARRAY_SIZE(g_reg_table_mac) && - data_i < data_num; item_i++, data_i++) { - g_reg_table_mac[item_i].val = data[data_i]; - pcie_dumpreg_write_value_to_file(g_reg_table_mac[item_i].name, - g_reg_table_mac[item_i].val); + uint32_t i, j, data_i = 0; + + for (i = 0; i < size; i++) { + struct pcie_dumpreg_info *info = table[i].dump_info; + for (j = 0; j < table[i].size && data_i < data_num; j++, data_i++) { + info[j].val = data[data_i]; + pcie_dumpreg_write_value_to_file(info[j].name, info[j].val); + } } }
@@ -420,13 +508,14 @@ static int pcie_dumpreg_save_log(uint32_t *data, uint32_t data_num,
switch (req_data->level) { case DUMP_GLOBAL_LEVEL: - expect_data_num = HIKP_ARRAY_SIZE(g_reg_table_iob_tx) + - HIKP_ARRAY_SIZE(g_reg_table_iob_rx) + HIKP_ARRAY_SIZE(g_reg_table_ap_glb) + - HIKP_ARRAY_SIZE(g_reg_table_core_glb) + HIKP_ARRAY_SIZE(g_reg_table_pcs); + for (i = 0; i < HIKP_ARRAY_SIZE(g_dump_info_glb); i++) { + expect_data_num += g_dump_info_glb[i].size; + } break; case DUMP_PORT_LEVEL: - expect_data_num = HIKP_ARRAY_SIZE(g_reg_table_tl) + - HIKP_ARRAY_SIZE(g_reg_table_dl) + HIKP_ARRAY_SIZE(g_reg_table_mac); + for (i = 0; i < HIKP_ARRAY_SIZE(g_dump_info_port); i++) { + expect_data_num += g_dump_info_port[i].size; + } break; default: Err("PCIe DUMPREG", "check dump level failed.\n"); @@ -441,9 +530,11 @@ static int pcie_dumpreg_save_log(uint32_t *data, uint32_t data_num, pcie_dumpreg_write_value_to_file(reg_name, data[i]); } } else if (req_data->level == DUMP_GLOBAL_LEVEL) { - pcie_dumpreg_save_glb_analysis_log(data, data_num); + pcie_dumpreg_save_analysis_log(data, data_num, + g_dump_info_glb, HIKP_ARRAY_SIZE(g_dump_info_glb)); } else { - pcie_dumpreg_save_port_analysis_log(data, data_num); + pcie_dumpreg_save_analysis_log(data, data_num, + g_dump_info_port, HIKP_ARRAY_SIZE(g_dump_info_port)); }
return 0; diff --git a/pcie/func_lib/pcie_func/pcie_reg_dump.h b/pcie/func_lib/pcie_func/pcie_reg_dump.h index 4ec1909..cbea2f6 100644 --- a/pcie/func_lib/pcie_func/pcie_reg_dump.h +++ b/pcie/func_lib/pcie_func/pcie_reg_dump.h @@ -49,6 +49,11 @@ struct pcie_dump_req_para { uint32_t level; };
+struct pcie_dumpreg_table { + uint32_t size; + struct pcie_dumpreg_info *dump_info; +}; + int pcie_dumpreg_do_dump(uint32_t port_id, uint32_t dump_level);
#endif
If the port contains CDRs, the nic_port command displays the hardware information of the CDRs, which helps locate port link setup faults.
Signed-off-by: veega zhuweijia@huawei.com --- net/nic/nic_mac/hikp_mac_cmd.h | 1 + net/nic/nic_mac/hikp_nic_port.c | 72 ++++++++++++++++++++++++++++++++- net/nic/nic_mac/hikp_nic_port.h | 49 +++++++++++++++++++--- 3 files changed, 116 insertions(+), 6 deletions(-)
diff --git a/net/nic/nic_mac/hikp_mac_cmd.h b/net/nic/nic_mac/hikp_mac_cmd.h index 5f0450a..adaadf4 100644 --- a/net/nic/nic_mac/hikp_mac_cmd.h +++ b/net/nic/nic_mac/hikp_mac_cmd.h @@ -30,6 +30,7 @@ enum mac_port_sub_cmd { QUERY_PORT_ADAPT_DFX, QUERY_PORT_PHY_DFX, QUERY_HOT_PLUG_CARD_DFX, + QUERY_PORT_CDR_DFX, };
enum mac_dump_reg_sub_cmd { diff --git a/net/nic/nic_mac/hikp_nic_port.c b/net/nic/nic_mac/hikp_nic_port.c index 22a6467..c9f46fc 100644 --- a/net/nic/nic_mac/hikp_nic_port.c +++ b/net/nic/nic_mac/hikp_nic_port.c @@ -405,6 +405,73 @@ static void mac_cmd_show_hot_plug_card(struct major_cmd_ctrl *self) free(cmd_ret); }
+static void mac_cmd_print_cdr_dfx(struct mac_cmd_cdr_dfx *cdr_dfx, struct mac_port_cdr_dfx *info) +{ + struct mac_item type_table[] = { + {PORT_CDR_SD5902, "sd5902"}, {PORT_CDR_SD5901, "sd5901"}, + }; + struct mac_item sd5902_mode[] = { + {SD5902_MODE_2PLL, "2pll"}, {SD5902_MODE_FASTPI, "fastpi"}, + }; + struct mac_item sd5901_mode[] = { + {SD5901_MODE_PCS, "pcs"}, {SD5901_MODE_CDR, "cdr"}, + }; + struct mac_item status_table[] = { + {CDR_STATUS_NORMAL, "normal"}, {CDR_STATUS_ERROR, "error"}, + }; + const char *type_str = mac_get_str(cdr_dfx->cdr_type, + type_table, HIKP_ARRAY_SIZE(type_table), "unknown"); + const char *mode_str = "NA"; + + for (uint32_t i = 0; i < cdr_dfx->cdr_num; i++) { + if (cdr_dfx->cdr_type == PORT_CDR_SD5902) { + mode_str = mac_get_str(info->dfx[i].cdr_mode, sd5902_mode, + HIKP_ARRAY_SIZE(sd5902_mode), "unknown"); + } else if (cdr_dfx->cdr_type == PORT_CDR_SD5901) { + mode_str = mac_get_str(info->dfx[i].cdr_mode, sd5901_mode, + HIKP_ARRAY_SIZE(sd5901_mode), "unknown"); + } + printf("\t|0x%-8x%-9u%-10s%-10s%-10s\n", info->dfx[i].cdr_addr, + info->dfx[i].cdr_start_lane, type_str, mode_str, + mac_get_str(info->dfx[i].cdr_err, + status_table, HIKP_ARRAY_SIZE(status_table), "unknown")); + } +} + +static void mac_cmd_disp_cdr_info(struct mac_cmd_cdr_dfx *cdr_dfx) +{ + if (!cdr_dfx->cdr_num) + return; + + printf("\n======================== PORT CDR INFO =======================\n"); + printf("direct\t|addr |lane |type |mode |status \n"); + printf("----------------------------------------------------------------------------\n"); + + printf("WIRE"); + mac_cmd_print_cdr_dfx(cdr_dfx, &cdr_dfx->wire_cdr); + + printf("HOST"); + mac_cmd_print_cdr_dfx(cdr_dfx, &cdr_dfx->host_cdr); +} + +static void mac_cmd_show_cdr(struct major_cmd_ctrl *self) +{ + struct mac_cmd_cdr_dfx *cdr_dfx = NULL; + struct hikp_cmd_ret *cmd_ret = NULL; + int ret; + + ret = mac_cmd_get_dfx_cfg(QUERY_PORT_CDR_DFX, &cmd_ret); + if (ret != 0) { + self->err_no = -ENOSPC; + snprintf(self->err_str, sizeof(self->err_str), "mac get cdr dfx failed."); + return; + } + + cdr_dfx = (struct mac_cmd_cdr_dfx *)(cmd_ret->rsp_data); + mac_cmd_disp_cdr_info(cdr_dfx); + free(cmd_ret); +} + static void mac_cmd_show_port_dfx(struct major_cmd_ctrl *self, uint32_t mask) { struct mac_cmd_dfx_callback dfx_cb[] = { @@ -413,6 +480,7 @@ static void mac_cmd_show_port_dfx(struct major_cmd_ctrl *self, uint32_t mask) {MAC_LSPORT_PHY, mac_cmd_show_phy}, {MAC_LSPORT_ARB, mac_cmd_show_arb}, {MAC_HOT_PLUG_CARD, mac_cmd_show_hot_plug_card}, + {MAC_LSPORT_CDR, mac_cmd_show_cdr} }; size_t size = HIKP_ARRAY_SIZE(dfx_cb); size_t i; @@ -425,9 +493,9 @@ static void mac_cmd_show_port_dfx(struct major_cmd_ctrl *self, uint32_t mask)
static void mac_cmd_port_execute(struct major_cmd_ctrl *self) { - uint32_t mask = MAC_LSPORT_LINK | MAC_LSPORT_MAC | MAC_LSPORT_ARB | MAC_HOT_PLUG_CARD; struct mac_cmd_port_hardware *port_hw = NULL; struct hikp_cmd_ret *hw_cmd_ret = NULL; + uint32_t mask; int ret;
if (!g_port_info.port_flag) { @@ -443,6 +511,8 @@ static void mac_cmd_port_execute(struct major_cmd_ctrl *self) return; }
+ mask = MAC_LSPORT_LINK | MAC_LSPORT_MAC | + MAC_LSPORT_ARB | MAC_HOT_PLUG_CARD | MAC_LSPORT_CDR; port_hw = (struct mac_cmd_port_hardware *)(hw_cmd_ret->rsp_data); if (port_hw->port_type == HIKP_PORT_TYPE_PHY || port_hw->port_type == HIKP_PORT_TYPE_PHY_SDS) diff --git a/net/nic/nic_mac/hikp_nic_port.h b/net/nic/nic_mac/hikp_nic_port.h index f6334d0..42ab3f9 100644 --- a/net/nic/nic_mac/hikp_nic_port.h +++ b/net/nic/nic_mac/hikp_nic_port.h @@ -16,11 +16,12 @@
#include "hikp_net_lib.h"
-#define MAC_LSPORT_LINK HI_BIT(0) -#define MAC_LSPORT_MAC HI_BIT(1) -#define MAC_LSPORT_PHY HI_BIT(2) -#define MAC_LSPORT_ARB HI_BIT(3) -#define MAC_HOT_PLUG_CARD HI_BIT(4) +#define MAC_LSPORT_LINK HI_BIT(0) +#define MAC_LSPORT_MAC HI_BIT(1) +#define MAC_LSPORT_PHY HI_BIT(2) +#define MAC_LSPORT_ARB HI_BIT(3) +#define MAC_HOT_PLUG_CARD HI_BIT(4) +#define MAC_LSPORT_CDR HI_BIT(5)
enum { PORT_CFG_NOT_SET = 0, @@ -186,6 +187,44 @@ struct mac_cmd_phy_info { struct mac_cmd_phy_dfx phy_dfx; };
+enum { + PORT_CDR_SD5902 = 0, + PORT_CDR_SD5901, +}; + +enum { + SD5902_MODE_2PLL = 0, + SD5902_MODE_FASTPI, +}; + +enum { + SD5901_MODE_PCS = 0, + SD5901_MODE_CDR, +}; + +enum { + CDR_STATUS_NORMAL = 0, + CDR_STATUS_ERROR, +}; + +struct cdr_dfx_info { + uint8_t cdr_mode; + uint8_t cdr_addr; + uint8_t cdr_start_lane; + uint8_t cdr_err; /* 0:normal, 1:error */ +}; + +struct mac_port_cdr_dfx { + struct cdr_dfx_info dfx[2]; /* one side reserved max 2 cdr */ +}; + +struct mac_cmd_cdr_dfx { + uint8_t cdr_num; + uint8_t cdr_type; + struct mac_port_cdr_dfx wire_cdr; + struct mac_port_cdr_dfx host_cdr; +}; + struct mac_cmd_dfx_callback { uint32_t mask; void (*show_dfx)(struct major_cmd_ctrl *self);
add nic_ncsi cmd for query nic port number of NCSI packets processed by software
Signed-off-by: veega zhuweijia@huawei.com --- net/hikp_net_lib.h | 5 ++ net/nic/nic_ncsi/hikp_nic_ncsi.c | 116 +++++++++++++++++++++++++++++++ net/nic/nic_ncsi/hikp_nic_ncsi.h | 57 +++++++++++++++ 3 files changed, 178 insertions(+) create mode 100644 net/nic/nic_ncsi/hikp_nic_ncsi.c create mode 100644 net/nic/nic_ncsi/hikp_nic_ncsi.h
diff --git a/net/hikp_net_lib.h b/net/hikp_net_lib.h index af0a51d..ed984ce 100644 --- a/net/hikp_net_lib.h +++ b/net/hikp_net_lib.h @@ -78,6 +78,7 @@ enum nic_cmd_type { GET_FD_INFO_CMD, GET_FEC_INFO_CMD, GET_GRO_INFO_CMD, + GET_NCSI_INFO_CMD, };
enum roh_cmd_type { @@ -107,6 +108,10 @@ enum ub_cmd_type { GET_UB_BASIC_INFO_CMD, };
+enum nic_get_ncsi_sub_cmd { + NIC_NCSI_GET_DFX_INFO, +}; + #define HIKP_MAX_PF_NUM 8 #define HIKP_NIC_MAX_FUNC_NUM 256
diff --git a/net/nic/nic_ncsi/hikp_nic_ncsi.c b/net/nic/nic_ncsi/hikp_nic_ncsi.c new file mode 100644 index 0000000..d09e16f --- /dev/null +++ b/net/nic/nic_ncsi/hikp_nic_ncsi.c @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2022 Hisilicon Technologies Co., Ltd. + * Hikptool is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * + * See the Mulan PSL v2 for more details. + */ + +#include <unistd.h> +#include "tool_cmd.h" +#include "hikp_net_lib.h" +#include "hikptdev_plug.h" +#include "hikp_nic_ncsi.h" + +static struct nic_ncsi_cmd_info g_ncsi_cmd_info = {0}; + +static void nic_ncsi_cmd_print_dfx_info(struct nic_ncsi_cmd_resp *ncsi_info) +{ + printf("port ncsi: %s\n", ncsi_info->ncsi_en ? "enable" : "disable"); + if (!ncsi_info->ncsi_en) + return; /* ncsi not enable do not print dfx info */ + + printf("processing packet statistics\n"); + printf("\tncsi_control_total: %u\n", ncsi_info->ncsi_dfx.ncsi_control_total); + printf("\tncsi_eth_to_ub_total: %u\n", ncsi_info->ncsi_dfx.ncsi_eth_to_ub_total); + printf("\tncsi_ub_to_eth_total: %u\n", ncsi_info->ncsi_dfx.ncsi_ub_to_eth_total); + printf("\tncsi_control_good: %u\n", ncsi_info->ncsi_dfx.ncsi_control_good); + printf("\tncsi_eth_to_ub_good: %u\n", ncsi_info->ncsi_dfx.ncsi_eth_to_ub_good); + printf("\tncsi_ub_to_eth_good: %u\n", ncsi_info->ncsi_dfx.ncsi_ub_to_eth_good); + + printf("\tncsi_eth_to_ub_arp: %u\n", ncsi_info->ncsi_dfx.ncsi_eth_to_ub_arp); + printf("\tncsi_eth_to_ub_free_arp: %u\n", ncsi_info->ncsi_dfx.ncsi_eth_to_ub_free_arp); + printf("\tncsi_eth_to_ub_ipv6_ra: %u\n", ncsi_info->ncsi_dfx.ncsi_eth_to_ub_ipv6_ra); + printf("\tncsi_eth_to_ub_dhcpv4: %u\n", ncsi_info->ncsi_dfx.ncsi_eth_to_ub_dhcpv4); + printf("\tncsi_eth_to_ub_dhcpv6: %u\n", ncsi_info->ncsi_dfx.ncsi_eth_to_ub_dhcpv6); + printf("\tncsi_eth_to_ub_lldp: %u\n", ncsi_info->ncsi_dfx.ncsi_eth_to_ub_lldp); + + printf("\tncsi_ub_to_eth_ipv4: %u\n", ncsi_info->ncsi_dfx.ncsi_ub_to_eth_ipv4); + printf("\tncsi_ub_to_eth_ipv6: %u\n", ncsi_info->ncsi_dfx.ncsi_ub_to_eth_ipv6); + printf("\tncsi_ub_to_eth_ipnotify: %u\n", ncsi_info->ncsi_dfx.ncsi_ub_to_eth_ipnotify); + printf("\tncsi_ub_to_eth_dhcpv4: %u\n", ncsi_info->ncsi_dfx.ncsi_ub_to_eth_dhcpv4); + printf("\tncsi_ub_to_eth_dhcpv6: %u\n", ncsi_info->ncsi_dfx.ncsi_ub_to_eth_dhcpv6); + printf("\tncsi_ub_to_eth_lldp: %u\n", ncsi_info->ncsi_dfx.ncsi_ub_to_eth_lldp); +} + +static void nic_ncsi_cmd_execute(struct major_cmd_ctrl *self) +{ + struct hikp_cmd_ret *cmd_resp = NULL; + struct hikp_cmd_header req_header = {0}; + struct nic_ncsi_cmd_req ncsi_req = {0}; + + if (!g_ncsi_cmd_info.port_flag) { + self->err_no = -EINVAL; + snprintf(self->err_str, sizeof(self->err_str), "Need port id."); + return; + } + + memcpy(&ncsi_req.bdf, &g_ncsi_cmd_info.target.bdf, sizeof(ncsi_req.bdf)); + hikp_cmd_init(&req_header, NIC_MOD, GET_NCSI_INFO_CMD, NIC_NCSI_GET_DFX_INFO); + cmd_resp = hikp_cmd_alloc(&req_header, &ncsi_req, sizeof(ncsi_req)); + self->err_no = hikp_rsp_normal_check(cmd_resp); + if (self->err_no) { + snprintf(self->err_str, sizeof(self->err_str), "Get ncsi dfx info failed."); + goto ERR_OUT; + } + + nic_ncsi_cmd_print_dfx_info((struct nic_ncsi_cmd_resp *)cmd_resp->rsp_data); + +ERR_OUT: + free(cmd_resp); + cmd_resp = NULL; +} + +static int nic_ncsi_cmd_get_port_info(struct major_cmd_ctrl *self, const char *argv) +{ + self->err_no = tool_check_and_get_valid_bdf_id(argv, &g_ncsi_cmd_info.target); + if (self->err_no) { + snprintf(self->err_str, sizeof(self->err_str), "Unknown device %s.", argv); + return self->err_no; + } + g_ncsi_cmd_info.port_flag = true; + + return 0; +} + +static int nic_ncsi_cmd_show_help(struct major_cmd_ctrl *self, const char *argv) +{ + printf("\n Usage: %s %s\n", self->cmd_ptr->name, "-i <interface>"); + printf("\n %s\n", self->cmd_ptr->help_info); + printf("\n Options:\n\n"); + printf(" %s, %-25s %s\n", "-h", "--help", "display this help and exit"); + printf(" %s, %-25s %s\n", "-i", "--interface=<interface>", + "device target or bdf id, e.g. eth0~3 or 0000:35:00.0"); + printf("\n"); + + return 0; +} + +static void cmd_nic_get_ncsi_init(void) +{ + struct major_cmd_ctrl *major_cmd = get_major_cmd(); + + g_ncsi_cmd_info.port_flag = false; + major_cmd->option_count = 0; + major_cmd->execute = nic_ncsi_cmd_execute; + + cmd_option_register("-h", "--help", false, nic_ncsi_cmd_show_help); + cmd_option_register("-i", "--interface", true, nic_ncsi_cmd_get_port_info); +} + +HIKP_CMD_DECLARE("nic_ncsi", "query nic port ncsi information", cmd_nic_get_ncsi_init); diff --git a/net/nic/nic_ncsi/hikp_nic_ncsi.h b/net/nic/nic_ncsi/hikp_nic_ncsi.h new file mode 100644 index 0000000..a391d20 --- /dev/null +++ b/net/nic/nic_ncsi/hikp_nic_ncsi.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2022 Hisilicon Technologies Co., Ltd. + * Hikptool is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * + * See the Mulan PSL v2 for more details. + */ + +#ifndef HIKP_NIC_NCSI_H +#define HIKP_NIC_NCSI_H + +#include "hikp_net_lib.h" + +struct nic_ncsi_dfx_info { + uint16_t ncsi_control_total; + uint16_t ncsi_eth_to_ub_total; + uint16_t ncsi_ub_to_eth_total; + uint16_t ncsi_control_good; + uint16_t ncsi_eth_to_ub_good; + uint16_t ncsi_ub_to_eth_good; + uint16_t ncsi_eth_to_ub_arp; + uint16_t ncsi_eth_to_ub_free_arp; + uint16_t ncsi_eth_to_ub_ipv6_ra; + uint16_t ncsi_eth_to_ub_dhcpv4; + uint16_t ncsi_eth_to_ub_dhcpv6; + uint16_t ncsi_eth_to_ub_lldp; + uint16_t ncsi_ub_to_eth_ipv4; + uint16_t ncsi_ub_to_eth_ipv6; + uint16_t ncsi_ub_to_eth_ipnotify; + uint16_t ncsi_ub_to_eth_dhcpv4; + uint16_t ncsi_ub_to_eth_dhcpv6; + uint16_t ncsi_ub_to_eth_lldp; +}; + +struct nic_ncsi_cmd_resp { + uint8_t ncsi_en; + uint8_t rsv0[3]; + struct nic_ncsi_dfx_info ncsi_dfx; + uint32_t rsv1[50]; /* max resp data: 240 Bytes */ +}; + +struct nic_ncsi_cmd_req { + struct bdf_t bdf; + uint32_t rsv0[30]; /* max req data: 128 Bytes */ +}; + +struct nic_ncsi_cmd_info { + struct tool_target target; + bool port_flag; +}; + +#endif /* HIKP_NIC_NCSI_H */
From: m30045533 moubingquan@huawei.com
--- pcie/func_lib/pcie_func/pcie_link_ltssm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/pcie/func_lib/pcie_func/pcie_link_ltssm.c b/pcie/func_lib/pcie_func/pcie_link_ltssm.c index 09d3b5e..156f4be 100644 --- a/pcie/func_lib/pcie_func/pcie_link_ltssm.c +++ b/pcie/func_lib/pcie_func/pcie_link_ltssm.c @@ -213,7 +213,8 @@ 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.mac_rate, + (((uint32_t)ltssm_val.bits.rxl0s_st) << 2) | + ((uint32_t)ltssm_val.bits.mac_rate), (uint32_t)ltssm_val.bits.duration_counter, (uint32_t)ltssm_val.bits.ltssm_state, ltssm_c);
From: Junxian Huang huangjunxian6@hisilicon.com
Upstream: Yes AR20220105919341
Currently hikptool only accepts bank ID 0 and 1 for roce_trp GEN_AC. The firmware then multiplies the bank ID received from hikptool by 2 and converts it to 0 and 2. But actually there are 4 banks in GEN_AC and each of them is independent.
To fix the problem, both hikptool and firmware should be modified. This patch modifies the bank ID limit form 2 to 4 in hikptool.
Signed-off-by: Junxian Huang huangjunxian6@hisilicon.com --- net/roce/roce_trp/hikp_roce_trp.c | 2 +- net/roce/roce_trp/hikp_roce_trp.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/net/roce/roce_trp/hikp_roce_trp.c b/net/roce/roce_trp/hikp_roce_trp.c index 8befb06..bf22484 100644 --- a/net/roce/roce_trp/hikp_roce_trp.c +++ b/net/roce/roce_trp/hikp_roce_trp.c @@ -32,7 +32,7 @@ static int hikp_roce_trp_help(struct major_cmd_ctrl *self, const char *argv) "this is necessary param COMMON/TRP_RX/GEN_AC/PAYL"); printf(" %s, %-25s %s\n", "-b", "--bank=<bank>", "[option]set which bank to read. (default 0) " - "COMMON : 0~3\n PAYL: 0~1\n GEN_AC : 0~1\n "); + "COMMON : 0~3\n PAYL: 0~1\n GEN_AC : 0~3\n "); printf("\n");
return 0; diff --git a/net/roce/roce_trp/hikp_roce_trp.h b/net/roce/roce_trp/hikp_roce_trp.h index db58216..80d28af 100644 --- a/net/roce/roce_trp/hikp_roce_trp.h +++ b/net/roce/roce_trp/hikp_roce_trp.h @@ -25,7 +25,7 @@ } #define TRP_MAX_BANK_NUM 0x3 #define PAYL_MAX_BANK_NUM 0x1 -#define GAC_MAX_BANK_NUM 0x1 +#define GAC_MAX_BANK_NUM 0x3 #define PER_TRP_DATA_NUM 2
struct roce_trp_req_param {
After the framework fails to apply for memory, the memory needs to be released. The framework returns a processing failure message. The module needs to exit and release the memory.
Signed-off-by: veega zhuweijia@huawei.com --- net/nic/nic_dfx/hikp_nic_dfx.c | 17 +++++++++-------- net/nic/nic_fd/hikp_nic_fd.c | 6 ++++-- net/nic/nic_info/hikp_nic_info.c | 4 +++- net/nic/nic_log/hikp_nic_log.c | 8 ++++---- net/nic/nic_ppp/hikp_nic_ppp.c | 5 +++-- net/nic/nic_qos/hikp_nic_qos.c | 5 +++-- net/nic/nic_queue/hikp_nic_queue.c | 5 +++-- net/nic/nic_rss/hikp_nic_rss.c | 5 +++-- net/roce/roce_pkt/hikp_roce_pkt.c | 11 +++++++---- net/roce/roce_scc/hikp_roce_scc.c | 11 +++++++---- net/roce/roce_trp/hikp_roce_trp.c | 11 +++++++---- net/roce/roce_tsp/hikp_roce_tsp.c | 11 +++++++---- sas/sas_func/sas_analy_queue.c | 3 ++- sas/sas_func/sas_dump_reg.c | 3 ++- sas/sas_func/sas_read_dev.c | 3 ++- sas/sas_func/sas_read_dqe.c | 3 ++- sas/sas_func/sas_read_errcode.c | 3 ++- sata/sata_func/sata_dump_reg.c | 3 ++- serdes/hikp_serdes.c | 8 ++++---- socip/hikp_socip_dumpreg.c | 4 +++- 20 files changed, 79 insertions(+), 50 deletions(-)
diff --git a/net/nic/nic_dfx/hikp_nic_dfx.c b/net/nic/nic_dfx/hikp_nic_dfx.c index 3584493..c734ce0 100644 --- a/net/nic/nic_dfx/hikp_nic_dfx.c +++ b/net/nic/nic_dfx/hikp_nic_dfx.c @@ -123,12 +123,12 @@ static int hikp_nic_get_first_blk_dfx(struct nic_dfx_rsp_head_t *rsp_head, uint3 uint32_t *max_dfx_size, uint32_t *version) { struct nic_dfx_rsp_t *dfx_rsp = NULL; - struct hikp_cmd_ret *cmd_ret; + struct hikp_cmd_ret *cmd_ret = NULL; int ret;
ret = hikp_nic_dfx_get_blk(&cmd_ret, 0, g_dfx_param.sub_cmd_code); if (ret < 0) - return ret; + goto err_out;
dfx_rsp = (struct nic_dfx_rsp_t *)(cmd_ret->rsp_data); *version = cmd_ret->version; @@ -168,12 +168,12 @@ static int hikp_nic_get_blk_dfx(struct nic_dfx_rsp_head_t *rsp_head, uint32_t bl uint32_t *reg_data, uint32_t *max_dfx_size) { struct nic_dfx_rsp_t *dfx_rsp = NULL; - struct hikp_cmd_ret *cmd_ret; + struct hikp_cmd_ret *cmd_ret = NULL; int ret;
ret = hikp_nic_dfx_get_blk(&cmd_ret, blk_id, g_dfx_param.sub_cmd_code); if (ret < 0) - return ret; + goto err_out;
dfx_rsp = (struct nic_dfx_rsp_t *)(cmd_ret->rsp_data); *rsp_head = dfx_rsp->rsp_head; @@ -181,16 +181,17 @@ static int hikp_nic_get_blk_dfx(struct nic_dfx_rsp_head_t *rsp_head, uint32_t bl HIKP_ERROR_PRINT("blk%u reg_data copy size error, " "data size: 0x%x, max size: 0x%x\n", blk_id, rsp_head->cur_blk_size, *max_dfx_size); - free(cmd_ret); - cmd_ret = NULL; - return -EINVAL; + ret = -EINVAL; + goto err_out; } memcpy(reg_data, dfx_rsp->reg_data, rsp_head->cur_blk_size); *max_dfx_size -= (uint32_t)rsp_head->cur_blk_size; + +err_out: free(cmd_ret); cmd_ret = NULL;
- return 0; + return ret; }
static int cmd_dfx_module_select(struct major_cmd_ctrl *self, const char *argv) diff --git a/net/nic/nic_fd/hikp_nic_fd.c b/net/nic/nic_fd/hikp_nic_fd.c index 5a87c30..57bc94b 100644 --- a/net/nic/nic_fd/hikp_nic_fd.c +++ b/net/nic/nic_fd/hikp_nic_fd.c @@ -558,8 +558,10 @@ static int hikp_nic_fd_get_blk(struct hikp_cmd_header *req_header, int ret = 0;
cmd_ret = hikp_cmd_alloc(req_header, req_data, sizeof(*req_data)); - if (cmd_ret == NULL) - return -EIO; + if (hikp_rsp_normal_check(cmd_ret)) { + ret = -EIO; + goto out; + }
rsp = (struct nic_fd_rsp *)cmd_ret->rsp_data; if (rsp->rsp_head.cur_blk_size > buf_len) { diff --git a/net/nic/nic_info/hikp_nic_info.c b/net/nic/nic_info/hikp_nic_info.c index 1853d95..d84ca18 100644 --- a/net/nic/nic_info/hikp_nic_info.c +++ b/net/nic/nic_info/hikp_nic_info.c @@ -64,12 +64,14 @@ static int hikp_nic_get_hw_info(struct hikp_cmd_ret **cmd_ret) static int hikp_nic_get_curr_die_info(void) { struct nic_info_rsp_t *info_rsp = NULL; - struct hikp_cmd_ret *cmd_ret; + struct hikp_cmd_ret *cmd_ret = NULL; int ret;
ret = hikp_nic_get_hw_info(&cmd_ret); if (ret != 0) { HIKP_ERROR_PRINT("Get chip info fail.\n"); + free(cmd_ret); + cmd_ret = NULL; return ret; } info_rsp = (struct nic_info_rsp_t *)(cmd_ret->rsp_data); diff --git a/net/nic/nic_log/hikp_nic_log.c b/net/nic/nic_log/hikp_nic_log.c index 527f9e9..5cafe4e 100644 --- a/net/nic/nic_log/hikp_nic_log.c +++ b/net/nic/nic_log/hikp_nic_log.c @@ -96,13 +96,13 @@ static int hikp_nic_get_first_blk_info(uint32_t *total_blk_num, uint32_t *cur_blk_size, uint8_t **log_data) { struct nic_log_rsp_data *log_rsp = NULL; - struct hikp_cmd_ret *cmd_ret; + struct hikp_cmd_ret *cmd_ret = NULL; uint32_t log_size; int ret;
ret = hikp_nic_get_blk_log(&cmd_ret, 0); if (ret < 0) - return ret; + goto err_out;
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)); @@ -132,12 +132,12 @@ static int hikp_nic_get_log_info(uint32_t blk_id, uint32_t *cur_blk_size, uint8_ uint32_t max_log_size, uint32_t *blk_num) { struct nic_log_rsp_data *log_rsp = NULL; - struct hikp_cmd_ret *cmd_ret; + struct hikp_cmd_ret *cmd_ret = NULL; int ret;
ret = hikp_nic_get_blk_log(&cmd_ret, blk_id); if (ret) - return ret; + goto err_out;
log_rsp = (struct nic_log_rsp_data *)(cmd_ret->rsp_data); *cur_blk_size = (uint32_t)log_rsp->cur_blk_size; diff --git a/net/nic/nic_ppp/hikp_nic_ppp.c b/net/nic/nic_ppp/hikp_nic_ppp.c index 28c867d..b71fc48 100644 --- a/net/nic/nic_ppp/hikp_nic_ppp.c +++ b/net/nic/nic_ppp/hikp_nic_ppp.c @@ -482,8 +482,9 @@ static int hikp_nic_ppp_get_blk(struct hikp_cmd_header *req_header, int ret = 0;
cmd_ret = hikp_cmd_alloc(req_header, req_data, sizeof(*req_data)); - if (cmd_ret == NULL) - return -EIO; + ret = hikp_rsp_normal_check(cmd_ret); + if (ret) + goto out;
rsp = (struct nic_ppp_rsp *)cmd_ret->rsp_data; if (rsp->rsp_head.cur_blk_size > buf_len) { diff --git a/net/nic/nic_qos/hikp_nic_qos.c b/net/nic/nic_qos/hikp_nic_qos.c index 2d55e45..6c2db1d 100644 --- a/net/nic/nic_qos/hikp_nic_qos.c +++ b/net/nic/nic_qos/hikp_nic_qos.c @@ -143,9 +143,10 @@ static int hikp_nic_qos_get_blk(struct hikp_cmd_header *req_header, int ret = 0;
cmd_ret = hikp_cmd_alloc(req_header, req_data, sizeof(*req_data)); - if (cmd_ret == NULL) { + ret = hikp_rsp_normal_check(cmd_ret); + if (ret) { HIKP_ERROR_PRINT("failed to get block-%u context.\n", req_data->block_id); - return -EIO; + goto out; }
rsp = (struct nic_qos_rsp *)cmd_ret->rsp_data; diff --git a/net/nic/nic_queue/hikp_nic_queue.c b/net/nic/nic_queue/hikp_nic_queue.c index 37460c0..f229e09 100644 --- a/net/nic/nic_queue/hikp_nic_queue.c +++ b/net/nic/nic_queue/hikp_nic_queue.c @@ -239,9 +239,10 @@ static int hikp_nic_queue_get_blk(struct hikp_cmd_header *req_header, int ret = 0;
cmd_ret = hikp_cmd_alloc(req_header, req_data, sizeof(*req_data)); - if (cmd_ret == NULL) { + ret = hikp_rsp_normal_check(cmd_ret); + if (ret) { HIKP_ERROR_PRINT("failed to get block-%u context.\n", req_data->block_id); - return -EIO; + goto out; }
rsp = (struct nic_queue_rsp *)cmd_ret->rsp_data; diff --git a/net/nic/nic_rss/hikp_nic_rss.c b/net/nic/nic_rss/hikp_nic_rss.c index b785ba4..5e4d261 100644 --- a/net/nic/nic_rss/hikp_nic_rss.c +++ b/net/nic/nic_rss/hikp_nic_rss.c @@ -357,9 +357,10 @@ static int hikp_nic_rss_get_blk(struct hikp_cmd_header *req_header, int ret = 0;
cmd_ret = hikp_cmd_alloc(req_header, req_data, sizeof(*req_data)); - if (cmd_ret == NULL) { + ret = hikp_rsp_normal_check(cmd_ret); + if (ret) { HIKP_ERROR_PRINT("failed to get block-%u context.\n", req_data->block_id); - return -EIO; + goto out; }
rsp = (struct nic_rss_rsp *)cmd_ret->rsp_data; diff --git a/net/roce/roce_pkt/hikp_roce_pkt.c b/net/roce/roce_pkt/hikp_roce_pkt.c index abfc526..d3bf885 100644 --- a/net/roce/roce_pkt/hikp_roce_pkt.c +++ b/net/roce/roce_pkt/hikp_roce_pkt.c @@ -48,15 +48,18 @@ static int hikp_roce_pkt_clear_set(struct major_cmd_ctrl *self, const char *argv static int hikp_roce_pkt_get_data(struct hikp_cmd_ret **cmd_ret, struct roce_pkt_req_param req_data) { struct hikp_cmd_header req_header = { 0 }; + int ret;
hikp_cmd_init(&req_header, ROCE_MOD, GET_ROCEE_PKT_CMD, 0); *cmd_ret = hikp_cmd_alloc(&req_header, &req_data, sizeof(req_data)); - if (*cmd_ret == NULL) { - printf("hikptool roce_pkt cmd_ret malloc failed\n"); - return -EIO; + ret = hikp_rsp_normal_check(*cmd_ret); + if (ret) { + printf("hikptool roce_pkt get cmd data failed, ret: %d\n", ret); + free(*cmd_ret); + *cmd_ret = NULL; }
- return 0; + return ret; }
static void hikp_roce_pkt_print(uint32_t total_block_num, diff --git a/net/roce/roce_scc/hikp_roce_scc.c b/net/roce/roce_scc/hikp_roce_scc.c index 1011814..e8e166d 100644 --- a/net/roce/roce_scc/hikp_roce_scc.c +++ b/net/roce/roce_scc/hikp_roce_scc.c @@ -88,6 +88,7 @@ static int hikp_roce_scc_get_data(struct hikp_cmd_ret **cmd_ret, const uint32_t { struct roce_scc_req_param req_data = { 0 }; struct hikp_cmd_header req_header = { 0 }; + int ret;
req_data.block_id = *block_id; req_data.bdf = g_roce_scc_param_t.target.bdf; @@ -99,12 +100,14 @@ static int hikp_roce_scc_get_data(struct hikp_cmd_ret **cmd_ret, const uint32_t
hikp_cmd_init(&req_header, ROCE_MOD, GET_ROCEE_SCC_CMD, g_roce_scc_param_t.sub_cmd); *cmd_ret = hikp_cmd_alloc(&req_header, &req_data, sizeof(req_data)); - if (*cmd_ret == NULL) { - printf("hikptool roce_scc cmd_ret malloc failed\n"); - return -EIO; + ret = hikp_rsp_normal_check(*cmd_ret); + if (ret) { + printf("hikptool roce_scc get cmd data failed, ret: %d\n", ret); + free(*cmd_ret); + *cmd_ret = NULL; }
- return 0; + return ret; }
static void hikp_roce_scc_reg_data_free(uint32_t **offset, uint32_t **data) diff --git a/net/roce/roce_trp/hikp_roce_trp.c b/net/roce/roce_trp/hikp_roce_trp.c index bf22484..4591a47 100644 --- a/net/roce/roce_trp/hikp_roce_trp.c +++ b/net/roce/roce_trp/hikp_roce_trp.c @@ -112,6 +112,7 @@ static int hikp_roce_trp_get_data(struct hikp_cmd_ret **cmd_ret, const uint32_t { struct roce_trp_req_param req_data = { 0 }; struct hikp_cmd_header req_header = { 0 }; + int ret;
req_data.block_id = *block_id; req_data.bdf = g_roce_trp_param_t.target.bdf; @@ -122,12 +123,14 @@ static int hikp_roce_trp_get_data(struct hikp_cmd_ret **cmd_ret, const uint32_t } hikp_cmd_init(&req_header, ROCE_MOD, GET_ROCEE_TRP_CMD, g_roce_trp_param_t.sub_cmd); *cmd_ret = hikp_cmd_alloc(&req_header, &req_data, sizeof(req_data)); - if (*cmd_ret == NULL) { - printf("hikptool roce_trp cmd_ret malloc failed\n"); - return -EIO; + ret = hikp_rsp_normal_check(*cmd_ret); + if (ret) { + printf("hikptool roce_trp get cmd data failed, ret: %d\n", ret); + free(*cmd_ret); + *cmd_ret = NULL; }
- return 0; + return ret; }
static void hikp_roce_trp_reg_data_free(uint32_t **offset, uint32_t **data) diff --git a/net/roce/roce_tsp/hikp_roce_tsp.c b/net/roce/roce_tsp/hikp_roce_tsp.c index 5d06ede..ca3126b 100644 --- a/net/roce/roce_tsp/hikp_roce_tsp.c +++ b/net/roce/roce_tsp/hikp_roce_tsp.c @@ -122,6 +122,7 @@ static int hikp_roce_tsp_get_data(struct hikp_cmd_ret **cmd_ret, struct roce_tsp_req_param req_data, uint32_t sub_cmd_code) { struct hikp_cmd_header req_header = { 0 }; + int ret;
if (g_roce_tsp_param_t.sub_cmd_code == 0) { printf("please enter module name: -m/--modlue\n"); @@ -129,12 +130,14 @@ static int hikp_roce_tsp_get_data(struct hikp_cmd_ret **cmd_ret, } hikp_cmd_init(&req_header, ROCE_MOD, GET_ROCEE_TSP_CMD, sub_cmd_code); *cmd_ret = hikp_cmd_alloc(&req_header, &req_data, sizeof(req_data)); - if (*cmd_ret == NULL) { - printf("hikptool roce_tsp cmd_ret malloc failed\n"); - return -EIO; + ret = hikp_rsp_normal_check(*cmd_ret); + if (ret) { + printf("hikptool roce_tsp get cmd data failed, ret: %d\n", ret); + free(*cmd_ret); + *cmd_ret = NULL; }
- return 0; + return ret; }
static void hikp_roce_tsp_print(uint32_t total_block_num, diff --git a/sas/sas_func/sas_analy_queue.c b/sas/sas_func/sas_analy_queue.c index ce886b9..8fca197 100644 --- a/sas/sas_func/sas_analy_queue.c +++ b/sas/sas_func/sas_analy_queue.c @@ -40,8 +40,9 @@ static int sas_get_res(const struct tool_sas_cmd *cmd, uint32_t *reg_save, uint3 hikp_cmd_init(&req_header, SAS_MOD, SAS_ANACQ, ANACQ_PRT);
cmd_ret = hikp_cmd_alloc(&req_header, &req_data, sizeof(req_data)); - if (cmd_ret == NULL) { + if (cmd_ret == NULL || cmd_ret->status != 0) { printf("sas_analy excutes hikp_cmd_alloc err\n"); + free(cmd_ret); return -EINVAL; } *reg_num = cmd_ret->rsp_data_num; diff --git a/sas/sas_func/sas_dump_reg.c b/sas/sas_func/sas_dump_reg.c index d012aa1..5736726 100644 --- a/sas/sas_func/sas_dump_reg.c +++ b/sas/sas_func/sas_dump_reg.c @@ -32,8 +32,9 @@ static int sas_get_reg(const struct tool_sas_cmd *cmd, uint32_t *reg_save, uint3
hikp_cmd_init(&req_header, SAS_MOD, SAS_DUMP, cmd->sas_cmd_type); cmd_ret = hikp_cmd_alloc(&req_header, &req_data, sizeof(req_data)); - if (cmd_ret == NULL) { + if (cmd_ret == NULL || cmd_ret->status != 0) { printf("sas_dump excutes hikp_cmd_alloc err\n"); + free(cmd_ret); return -1; } *reg_num = cmd_ret->rsp_data_num; diff --git a/sas/sas_func/sas_read_dev.c b/sas/sas_func/sas_read_dev.c index d01f95f..8b9b58d 100644 --- a/sas/sas_func/sas_read_dev.c +++ b/sas/sas_func/sas_read_dev.c @@ -33,8 +33,9 @@ static int sas_get_dev(const struct tool_sas_cmd *cmd, uint32_t *reg_save, uint3
hikp_cmd_init(&req_header, SAS_MOD, SAS_DEV, cmd->sas_cmd_type); cmd_ret = hikp_cmd_alloc(&req_header, &req_data, sizeof(req_data)); - if (cmd_ret == NULL) { + if (cmd_ret == NULL || cmd_ret->status != 0) { printf("sas_dqe excutes hikp_cmd_alloc err\n"); + free(cmd_ret); return -EINVAL; } *reg_num = cmd_ret->rsp_data_num; diff --git a/sas/sas_func/sas_read_dqe.c b/sas/sas_func/sas_read_dqe.c index 2f653df..dbd30f3 100644 --- a/sas/sas_func/sas_read_dqe.c +++ b/sas/sas_func/sas_read_dqe.c @@ -33,8 +33,9 @@ static int sas_get_dqe(const struct tool_sas_cmd *cmd, uint32_t *reg_save, uint3
hikp_cmd_init(&req_header, SAS_MOD, SAS_DQE, cmd->sas_cmd_type); cmd_ret = hikp_cmd_alloc(&req_header, &req_data, sizeof(req_data)); - if (cmd_ret == NULL) { + if (cmd_ret == NULL || cmd_ret->status != 0) { printf("sas_dqe excutes hikp_cmd_alloc err\n"); + free(cmd_ret); return -EINVAL; } *reg_num = cmd_ret->rsp_data_num; diff --git a/sas/sas_func/sas_read_errcode.c b/sas/sas_func/sas_read_errcode.c index 4f89bda..6c7850e 100644 --- a/sas/sas_func/sas_read_errcode.c +++ b/sas/sas_func/sas_read_errcode.c @@ -31,8 +31,9 @@ static int sas_get_errcode(const struct tool_sas_cmd *cmd, uint32_t *reg_save, u
hikp_cmd_init(&req_header, SAS_MOD, SAS_ERRCODE, cmd->sas_cmd_type); cmd_ret = hikp_cmd_alloc(&req_header, &req_data, sizeof(req_data)); - if (cmd_ret == NULL) { + if (cmd_ret == NULL || cmd_ret->status != 0) { printf("sas_errcode excutes hikp_cmd_alloc err\n"); + free(cmd_ret); return -EINVAL; } *reg_num = cmd_ret->rsp_data_num; diff --git a/sata/sata_func/sata_dump_reg.c b/sata/sata_func/sata_dump_reg.c index 86f6760..b4ff35f 100644 --- a/sata/sata_func/sata_dump_reg.c +++ b/sata/sata_func/sata_dump_reg.c @@ -33,8 +33,9 @@ static int sata_get_reg(const struct tool_sata_cmd *cmd, uint32_t *reg_save, uin
hikp_cmd_init(&req_header, SATA_MOD, SATA_DUMP, cmd->sata_cmd_type); cmd_ret = hikp_cmd_alloc(&req_header, &req_data, sizeof(req_data)); - if (cmd_ret == NULL) { + if (cmd_ret == NULL || cmd_ret->status != 0) { printf("hikp_data_proc err\n"); + free(cmd_ret); return -1; } *reg_num = cmd_ret->rsp_data_num; diff --git a/serdes/hikp_serdes.c b/serdes/hikp_serdes.c index 527fd53..320ded2 100644 --- a/serdes/hikp_serdes.c +++ b/serdes/hikp_serdes.c @@ -309,10 +309,10 @@ static void hikp_serdes_info_cmd_execute(struct major_cmd_ctrl *self)
hikp_cmd_init(&req_header, SERDES_MOD, SERDES_KEY_INFO, g_serdes_param.sub_cmd); cmd_ret = hikp_cmd_alloc(&req_header, &hilink_cmd, sizeof(hilink_cmd)); - if (cmd_ret == NULL) { + if (cmd_ret == NULL || cmd_ret->status != 0) { snprintf(self->err_str, sizeof(self->err_str), "hikp_cmd_alloc err."); self->err_no = -EINVAL; - return; + goto err_out; } out_out_header_size = sizeof(out_put.str_len) + sizeof(out_put.result_offset) + sizeof(out_put.type) + sizeof(out_put.ret_val); @@ -467,10 +467,10 @@ static void hikp_serdes_dump_cmd_execute(struct major_cmd_ctrl *self)
hikp_cmd_init(&req_header, SERDES_MOD, SERDES_DUMP_REG, g_serdes_param.sub_cmd); cmd_ret = hikp_cmd_alloc(&req_header, &hilink_cmd, sizeof(hilink_cmd)); - if (cmd_ret == NULL) { + if (cmd_ret == NULL || cmd_ret->status != 0) { self->err_no = -EINVAL; snprintf(self->err_str, sizeof(self->err_str), "hikp_cmd_alloc err."); - return; + goto err_out; } out_out_header_size = sizeof(out_put.str_len) + sizeof(out_put.result_offset) + sizeof(out_put.type) + sizeof(out_put.ret_val); diff --git a/socip/hikp_socip_dumpreg.c b/socip/hikp_socip_dumpreg.c index 32325bb..0153dd9 100644 --- a/socip/hikp_socip_dumpreg.c +++ b/socip/hikp_socip_dumpreg.c @@ -141,9 +141,11 @@ static void hikp_socip_dumpreg_execute(struct major_cmd_ctrl *self) req_data.controller_id = param[CONTROLLER_ID_INDEX].val; hikp_cmd_init(&req_header, SOCIP_MOD, HIKP_SOCIP_CMD_DUMPREG, param[MODULE_ID_INDEX].val); cmd_ret = hikp_cmd_alloc(&req_header, &req_data, sizeof(req_data)); - if (!cmd_ret) { + if (!cmd_ret || cmd_ret->status != 0) { self->err_no = -EINVAL; HIKP_ERROR_PRINT("hikp_cmd_alloc\n"); + free(cmd_ret); + cmd_ret = NULL; return; }
From: Jijie Shao shaojijie@huawei.com
add nic_notify_pkt cmd for query fault notify pkt info
AR:AR20230712025695 Bugfix or Feature: Feature
Signed-off-by: Jijie Shao shaojijie@huawei.com --- net/hikp_net_lib.h | 1 + net/nic/nic_notify_pkt/hikp_nic_notify_pkt.c | 126 +++++++++++++++++++ net/nic/nic_notify_pkt/hikp_nic_notify_pkt.h | 52 ++++++++ 3 files changed, 179 insertions(+) create mode 100644 net/nic/nic_notify_pkt/hikp_nic_notify_pkt.c create mode 100644 net/nic/nic_notify_pkt/hikp_nic_notify_pkt.h
diff --git a/net/hikp_net_lib.h b/net/hikp_net_lib.h index ed984ce..06ae598 100644 --- a/net/hikp_net_lib.h +++ b/net/hikp_net_lib.h @@ -79,6 +79,7 @@ enum nic_cmd_type { GET_FEC_INFO_CMD, GET_GRO_INFO_CMD, GET_NCSI_INFO_CMD, + GET_NOTIFY_PKT_CMD, };
enum roh_cmd_type { diff --git a/net/nic/nic_notify_pkt/hikp_nic_notify_pkt.c b/net/nic/nic_notify_pkt/hikp_nic_notify_pkt.c new file mode 100644 index 0000000..307d336 --- /dev/null +++ b/net/nic/nic_notify_pkt/hikp_nic_notify_pkt.c @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2023 Hisilicon Technologies Co., Ltd. + * Hikptool is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * + * See the Mulan PSL v2 for more details. + */ + +#include <stdio.h> +#include <string.h> +#include <sys/types.h> +#include <unistd.h> +#include "hikp_nic_notify_pkt.h" + +static struct tool_target g_notify_pkt_target; + +static int hikp_nic_notify_pkt_query(struct major_cmd_ctrl *self, const struct bdf_t *bdf, + struct nic_notify_pkt_info *info) +{ + struct nic_notify_pkt_req_para req = { 0 }; + struct hikp_cmd_header header = { 0 }; + struct nic_notify_pkt_rsp *rsp; + struct hikp_cmd_ret *cmd_resp; + + req.bdf = *bdf; + hikp_cmd_init(&header, NIC_MOD, GET_NOTIFY_PKT_CMD, GET_NOTIFY_PKT_CMD); + cmd_resp = hikp_cmd_alloc(&header, &req, sizeof(req)); + self->err_no = hikp_rsp_normal_check(cmd_resp); + if (self->err_no) { + snprintf(self->err_str, sizeof(self->err_str), "get notify pkt failed."); + if (cmd_resp) + free(cmd_resp); + return self->err_no; + } + + rsp = (struct nic_notify_pkt_rsp *)cmd_resp->rsp_data; + *info = *(struct nic_notify_pkt_info *)rsp->data; + free(cmd_resp); + + return 0; +} + +static void hikp_nic_notify_pkt_show(const struct nic_notify_pkt_info *info) +{ +#define HIKP_NIC_NOFITY_PKT_DATA_PEER_LINE_MAX_CNT 16 + + uint32_t pkt_start_en = hikp_get_bit(info->cfg, HIKP_NOTIFY_PKT_CFG_START_EN); + uint32_t pkt_num = hikp_get_field(info->cfg, HIKP_NOTIFY_PKT_CFG_PKT_NUM_M, + HIKP_NOTIFY_PKT_CFG_PKT_NUM_S); + uint32_t pkt_en = hikp_get_bit(info->cfg, HIKP_NOTIFY_PKT_CFG_PKT_EN); + uint32_t i; + + printf("################ NIC notify pkt info ##################\n"); + printf("pkt_en : %u\n", pkt_en); + printf("pkt_start_en : %u\n", pkt_start_en); + printf("pkt_num : %u\n", pkt_num); + printf("pkt_ipg : %u %s\n", info->ipg, info->ipg > 1 ? + "clock cycles" : "clock cycle"); + + printf("pkt_data:\n"); + for (i = 1; i <= NIC_NOTIFY_PKT_DATA_LEN; i++) { + printf("%02x ", info->data[i - 1]); + if (i % HIKP_NIC_NOFITY_PKT_DATA_PEER_LINE_MAX_CNT == 0) + printf("\n"); + } + printf("####################### END ###########################\n"); +} + +static void hikp_nic_notify_pkt_cmd_execute(struct major_cmd_ctrl *self) +{ + struct bdf_t *bdf = &g_notify_pkt_target.bdf; + struct nic_notify_pkt_info info; + + self->err_no = hikp_nic_notify_pkt_query(self, bdf, &info); + if (self->err_no) + return; + + hikp_nic_notify_pkt_show(&info); +} + +static int hikp_nic_notify_pkt_cmd_help(struct major_cmd_ctrl *self, const char *argv) +{ + printf("\n Usage: %s %s\n", self->cmd_ptr->name, "-i <device>"); + printf("\n %s\n", self->cmd_ptr->help_info); + printf("\n Options:\n\n"); + printf(" %s, %-25s %s\n", "-h", "--help", "display this help and exit"); + printf(" %s, %-25s %s\n", "-i", "--interface=<interface>", + "device target or bdf id, e.g. eth0~7 or 0000:35:00.0"); + + return 0; +} + +static int hikp_nic_notify_pkt_get_target(struct major_cmd_ctrl *self, const char *argv) +{ + self->err_no = tool_check_and_get_valid_bdf_id(argv, &g_notify_pkt_target); + if (self->err_no != 0) { + snprintf(self->err_str, sizeof(self->err_str), "unknown device!"); + return self->err_no; + } + + if (g_notify_pkt_target.bdf.dev_id != 0) { + snprintf(self->err_str, sizeof(self->err_str), "VF does not support query!"); + self->err_no = -EOPNOTSUPP; + return self->err_no; + } + + return 0; +} + +static void cmd_nic_notify_pkt_init(void) +{ + struct major_cmd_ctrl *major_cmd = get_major_cmd(); + + major_cmd->option_count = 0; + major_cmd->execute = hikp_nic_notify_pkt_cmd_execute; + + cmd_option_register("-h", "--help", false, hikp_nic_notify_pkt_cmd_help); + cmd_option_register("-i", "--interface", true, hikp_nic_notify_pkt_get_target); +} + +HIKP_CMD_DECLARE("nic_notify_pkt", "dump notify pkt info of nic!", cmd_nic_notify_pkt_init); diff --git a/net/nic/nic_notify_pkt/hikp_nic_notify_pkt.h b/net/nic/nic_notify_pkt/hikp_nic_notify_pkt.h new file mode 100644 index 0000000..8bdb795 --- /dev/null +++ b/net/nic/nic_notify_pkt/hikp_nic_notify_pkt.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2023 Hisilicon Technologies Co., Ltd. + * Hikptool is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * + * See the Mulan PSL v2 for more details. + */ + +#ifndef HIKP_NIC_NOTIFY_PKT_H +#define HIKP_NIC_NOTIFY_PKT_H + +#include "hikp_net_lib.h" + +enum nic_notify_pkt_sub_cmd_type { + NIC_NOTIFY_PKT_DUMP = 0, +}; + +struct nic_notify_pkt_req_para { + struct bdf_t bdf; + uint32_t block_id; +}; + +struct nic_notify_pkt_rsp_head { + uint8_t total_blk_num; + uint8_t curr_blk_size; /* real data size, not contain head size. */ + uint16_t rsv; +}; + +#define NIC_NOTIFY_PKT_MAX_RSP_DATA 18 +struct nic_notify_pkt_rsp { + struct nic_notify_pkt_rsp_head head; + uint32_t data[NIC_NOTIFY_PKT_MAX_RSP_DATA]; +}; + +#define NIC_NOTIFY_PKT_DATA_LEN 64 +struct nic_notify_pkt_info { + uint32_t cfg; + uint32_t ipg; + uint8_t data[NIC_NOTIFY_PKT_DATA_LEN]; +}; + +#define HIKP_NOTIFY_PKT_CFG_PKT_EN 0 +#define HIKP_NOTIFY_PKT_CFG_START_EN 1 +#define HIKP_NOTIFY_PKT_CFG_PKT_NUM_M GENMASK(5, 2) +#define HIKP_NOTIFY_PKT_CFG_PKT_NUM_S 2 + +#endif /* HIKP_NIC_NOTIFY_PKT_H */
From: Jie Wang wangjie125@huawei.com
Add nic port fault cmd for query nic port fault status.
AR:AR20230712025691 Bugfix or Feature: Feature
Signed-off-by: Jie Wang wangjie125@huawei.com --- net/hikp_net_lib.h | 1 + net/nic/nic_ft/hikp_nic_port_fault.c | 139 +++++++++++++++++++++++++++ net/nic/nic_ft/hikp_nic_port_fault.h | 54 +++++++++++ 3 files changed, 194 insertions(+) create mode 100644 net/nic/nic_ft/hikp_nic_port_fault.c create mode 100644 net/nic/nic_ft/hikp_nic_port_fault.h
diff --git a/net/hikp_net_lib.h b/net/hikp_net_lib.h index 06ae598..cb537ff 100644 --- a/net/hikp_net_lib.h +++ b/net/hikp_net_lib.h @@ -80,6 +80,7 @@ enum nic_cmd_type { GET_GRO_INFO_CMD, GET_NCSI_INFO_CMD, GET_NOTIFY_PKT_CMD, + GET_PORT_FAULT_STATUS = 0xE, };
enum roh_cmd_type { diff --git a/net/nic/nic_ft/hikp_nic_port_fault.c b/net/nic/nic_ft/hikp_nic_port_fault.c new file mode 100644 index 0000000..fd94214 --- /dev/null +++ b/net/nic/nic_ft/hikp_nic_port_fault.c @@ -0,0 +1,139 @@ +/* + * Copyright (c) 2023 Hisilicon Technologies Co., Ltd. + * Hikptool is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * + * See the Mulan PSL v2 for more details. + */ + +#include <stdio.h> +#include <string.h> +#include <sys/types.h> +#include <unistd.h> +#include "hikp_nic_port_fault.h" + +static struct tool_target g_port_fault_target; + +static int hikp_nic_port_fault_query(const struct bdf_t *bdf, + struct nic_port_fault_status *info) +{ + struct nic_port_fault_req_para req = { 0 }; + struct hikp_cmd_header header = { 0 }; + struct nic_port_fault_rsp *rsp; + struct hikp_cmd_ret *cmd_ret; + + 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); + if (cmd_ret != NULL) + free(cmd_ret); + + return -EIO; + } + + rsp = (struct nic_port_fault_rsp *)cmd_ret->rsp_data; + *info = *(struct nic_port_fault_status *)rsp->data; + free(cmd_ret); + + return 0; +} + +static void hikp_nic_format_port_fault_info(struct nic_port_fault_status *info) +{ + if (info->cdr_core_status > NIC_PORT_FAULT_INVALID) + info->cdr_core_status = NIC_PORT_FAULT_INVALID; + + if (info->cdr_flash_status > NIC_PORT_FAULT_INVALID) + info->cdr_flash_status = NIC_PORT_FAULT_INVALID; + + if (info->fault_9545_status > NIC_PORT_FAULT_INVALID) + info->fault_9545_status = NIC_PORT_FAULT_INVALID; + + if (info->hilink_ref_status > NIC_PORT_FAULT_INVALID) + info->hilink_ref_status = NIC_PORT_FAULT_INVALID; +} + +static void hikp_nic_port_fault_show(struct nic_port_fault_status *info) +{ + const char *port_fault_info[] = { + "OK", + "Device error", + "Device not support", + "Invalid" + }; + + hikp_nic_format_port_fault_info(info); + printf("############ NIC port fault status ###############\n"); + printf("cdr flash : %s.\n", port_fault_info[info->cdr_flash_status]); + printf("cdr core : %s.\n", port_fault_info[info->cdr_core_status]); + printf("9545 fault: %s.\n", port_fault_info[info->fault_9545_status]); + printf("hilink ref: %s.\n", port_fault_info[info->hilink_ref_status]); + printf("#################### END #######################\n"); +} + +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; + int ret; + + ret = hikp_nic_port_fault_query(bdf, &info); + if (ret != 0) { + snprintf(self->err_str, sizeof(self->err_str), "fail to get fault info."); + self->err_no = ret; + return; + } + + hikp_nic_port_fault_show(&info); +} + +static int hikp_nic_port_fault_cmd_help(struct major_cmd_ctrl *self, const char *argv) +{ + printf("\n Usage: %s %s\n", self->cmd_ptr->name, "-i <device>"); + printf("\n %s\n", self->cmd_ptr->help_info); + printf("\n Options:\n\n"); + printf(" %s, %-25s %s\n", "-h", "--help", "display this help and exit"); + printf(" %s, %-25s %s\n", "-i", "--interface=<interface>", + "device target or bdf id, e.g. eth0~7 or 0000:35:00.0"); + + return 0; +} + +static int hikp_nic_port_fault_get_target(struct major_cmd_ctrl *self, const char *argv) +{ + self->err_no = tool_check_and_get_valid_bdf_id(argv, &g_port_fault_target); + if (self->err_no != 0) { + snprintf(self->err_str, sizeof(self->err_str), "unknown device!"); + return self->err_no; + } + + if (g_port_fault_target.bdf.dev_id != 0) { + snprintf(self->err_str, sizeof(self->err_str), "VF is not supported!"); + self->err_no = -EOPNOTSUPP; + return self->err_no; + } + + return 0; +} + +static void cmd_nic_port_fault_init(void) +{ + struct major_cmd_ctrl *major_cmd = get_major_cmd(); + + major_cmd->option_count = 0; + major_cmd->execute = hikp_nic_port_fault_cmd_execute; + + cmd_option_register("-h", "--help", false, hikp_nic_port_fault_cmd_help); + cmd_option_register("-i", "--interface", true, hikp_nic_port_fault_get_target); +} + +HIKP_CMD_DECLARE("nic_port_fault", "dump port fault of nic!", cmd_nic_port_fault_init); diff --git a/net/nic/nic_ft/hikp_nic_port_fault.h b/net/nic/nic_ft/hikp_nic_port_fault.h new file mode 100644 index 0000000..7db54f7 --- /dev/null +++ b/net/nic/nic_ft/hikp_nic_port_fault.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2023 Hisilicon Technologies Co., Ltd. + * Hikptool is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * + * See the Mulan PSL v2 for more details. + */ + +#ifndef HIKP_NIC_PORT_FAULT_H +#define HIKP_NIC_PORT_FAULT_H + +#include "hikp_net_lib.h" + +enum nic_port_fault_sub_cmd_type { + NIC_PORT_FAULT_INFO_DUMP, +}; + +enum nic_port_fault_info_type { + NIC_PORT_FAULT_OK, + NIC_PORT_FAULT_ERR, + NIC_PORT_FAULT_NOTSUP, + NIC_PORT_FAULT_INVALID +}; + +struct nic_port_fault_req_para { + struct bdf_t bdf; + uint8_t block_id; +}; + +struct nic_port_fault_rsp_head { + uint8_t total_blk_num; + uint8_t curr_blk_size; + uint16_t rsv; +}; + +#define NIC_PORT_FAULT_MAX_RSP_DATA 1 +struct nic_port_fault_rsp { + struct nic_port_fault_rsp_head head; + uint32_t data[NIC_PORT_FAULT_MAX_RSP_DATA]; +}; + +struct nic_port_fault_status { + uint8_t cdr_flash_status; + uint8_t fault_9545_status; + uint8_t cdr_core_status; + uint8_t hilink_ref_status; +}; + +#endif /* HIKP_NIC_PORT_FAULT_H */
From: Peiyang Wang wangpeiyang1@huawei.com
Add new feature in nic_qos to support query pfc storm parameters info.
AR:AR20230712033518
Bugfix or Feature: Feature
Signed-off-by: Peiyang Wang wangpeiyang1@huawei.com --- net/nic/nic_qos/hikp_nic_qos.c | 72 ++++++++++++++++++++++++++++++++-- net/nic/nic_qos/hikp_nic_qos.h | 20 ++++++++++ 2 files changed, 89 insertions(+), 3 deletions(-)
diff --git a/net/nic/nic_qos/hikp_nic_qos.c b/net/nic/nic_qos/hikp_nic_qos.c index 6c2db1d..e3f0e9c 100644 --- a/net/nic/nic_qos/hikp_nic_qos.c +++ b/net/nic/nic_qos/hikp_nic_qos.c @@ -17,17 +17,21 @@ #include <unistd.h>
#include "hikp_nic_qos.h" +#include "hikpt_rciep.h"
static struct nic_qos_param g_qos_param = { 0 };
static void hikp_nic_qos_show_pkt_buf(const void *data); static void hikp_nic_qos_show_dcb_info(const void *data); static void hikp_nic_qos_show_pause_info(const void *data); +static void hikp_nic_qos_show_pfc_storm_para(const void *data);
static const struct qos_feature_cmd g_qos_feature_cmd[] = { {"pkt_buf", NIC_PACKET_BUFFER_DUMP, hikp_nic_qos_show_pkt_buf}, {"dcb", NIC_DCB_DUMP, hikp_nic_qos_show_dcb_info}, {"pause", NIC_PAUSE_DUMP, hikp_nic_qos_show_pause_info}, + {"pfc_storm_para", NIC_PFC_STORM_PARA_DUMP, + hikp_nic_qos_show_pfc_storm_para}, };
static int hikp_nic_qos_cmd_help(struct major_cmd_ctrl *self, const char *argv) @@ -42,8 +46,12 @@ static int hikp_nic_qos_cmd_help(struct major_cmd_ctrl *self, const char *argv) "[-g/--get <options>]\n" " pkt_buf : get nic packet buffer.\n" " dcb : get dcb information.\n" - " pause : get pause information\n"); - + " pause : get pause information\n" + " pfc_storm_para : get pfc storm configuration parameters\n"); + printf(" %s\n", + "[-d/--dir <options>]\n" + " tx : transmit.\n" + " rx : receive.\n"); return 0; }
@@ -134,6 +142,22 @@ static void hikp_nic_qos_show_pause_info(const void *data) printf("pause gap: 0x%x\n", pause->pause_gap); }
+static void hikp_nic_qos_show_pfc_storm_para(const void *data) +{ + struct nic_pfc_storm_para *pfc_storm_para = + (struct nic_pfc_storm_para *)data; + + printf("PFC STORM Information:\n"); + printf("direction: %s\n", pfc_storm_para->dir ? "tx" : "rx"); + printf("enabled: %s\n", pfc_storm_para->enable ? "on" : "off"); + printf("period: %ums\n", pfc_storm_para->period_ms); + strncmp(g_qos_param.revision_id, HIKP_IEP_REVISION, + MAX_PCI_REVISION_LEN) ? + 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); +} + static int hikp_nic_qos_get_blk(struct hikp_cmd_header *req_header, const struct nic_qos_req_para *req_data, void *buf, size_t buf_len, struct nic_qos_rsp_head *rsp_head) @@ -181,6 +205,8 @@ static int hikp_nic_query_qos_feature(struct hikp_cmd_header *req_header, const req_data.bdf = *bdf;
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); if (ret != 0) return ret; @@ -191,6 +217,8 @@ static int hikp_nic_query_qos_feature(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; + req_data.dir = g_qos_param.dir; + ret = hikp_nic_qos_get_blk(req_header, &req_data, (uint8_t *)data + total_blk_size, buf_len - total_blk_size, &rsp_head); @@ -204,10 +232,11 @@ static int hikp_nic_query_qos_feature(struct hikp_cmd_header *req_header, const
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}; - const struct qos_feature_cmd *qos_cmd; struct hikp_cmd_header req_header = {0}; + const struct qos_feature_cmd *qos_cmd; int ret;
if (bdf->dev_id != 0) { @@ -223,6 +252,15 @@ static void hikp_nic_qos_cmd_execute(struct major_cmd_ctrl *self) return; }
+ if (g_qos_param.feature_idx == NIC_PFC_STORM_PARA_DUMP && + g_qos_param.dir == NIC_QUEUE_DIR_NONE) { + hikp_nic_qos_cmd_help(self, NULL); + snprintf(self->err_str, sizeof(self->err_str), + "-d/--dir param error!"); + self->err_no = -EINVAL; + return; + } + qos_cmd = &g_qos_feature_cmd[g_qos_param.feature_idx]; hikp_cmd_init(&req_header, NIC_MOD, GET_QOS_INFO_CMD, qos_cmd->sub_cmd_code); ret = hikp_nic_query_qos_feature(&req_header, &g_qos_param.target.bdf, &qos_data); @@ -233,6 +271,13 @@ static void hikp_nic_qos_cmd_execute(struct major_cmd_ctrl *self) return; }
+ memset(revision_id, 0, MAX_PCI_ID_LEN + 1); + ret = get_revision_id_by_bdf(bdf, 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); + printf("############## NIC QOS: %s info ############\n", qos_cmd->feature_name); qos_cmd->show(&qos_data); printf("#################### END #######################\n"); @@ -268,11 +313,31 @@ static int hikp_nic_cmd_qos_feature_select(struct major_cmd_ctrl *self, const ch return self->err_no; }
+static int hikp_nic_cmd_qos_direct(struct major_cmd_ctrl *self, + const char *argv) +{ + if (strcmp(argv, "rx") == 0) { + g_qos_param.dir = NIC_RX_QUEUE; + return 0; + } + if (strcmp(argv, "tx") == 0) { + g_qos_param.dir = NIC_TX_QUEUE; + return 0; + } + + snprintf(self->err_str, sizeof(self->err_str), + "-d/--dir option is invalid."); + self->err_no = -EINVAL; + + return self->err_no; +} + static void cmd_nic_get_qos_init(void) { struct major_cmd_ctrl *major_cmd = get_major_cmd();
g_qos_param.feature_idx = -1; + g_qos_param.dir = NIC_QUEUE_DIR_NONE;
major_cmd->option_count = 0; major_cmd->execute = hikp_nic_qos_cmd_execute; @@ -280,6 +345,7 @@ static void cmd_nic_get_qos_init(void) cmd_option_register("-h", "--help", false, hikp_nic_qos_cmd_help); cmd_option_register("-i", "--interface", true, hikp_nic_cmd_get_qos_target); cmd_option_register("-g", "--get", true, hikp_nic_cmd_qos_feature_select); + cmd_option_register("-d", "--dir", true, hikp_nic_cmd_qos_direct); }
HIKP_CMD_DECLARE("nic_qos", "show qos info of nic!", cmd_nic_get_qos_init); diff --git a/net/nic/nic_qos/hikp_nic_qos.h b/net/nic/nic_qos/hikp_nic_qos.h index b5481f5..d55970a 100644 --- a/net/nic/nic_qos/hikp_nic_qos.h +++ b/net/nic/nic_qos/hikp_nic_qos.h @@ -20,6 +20,7 @@ enum nic_qos_sub_cmd_type { NIC_PACKET_BUFFER_DUMP = 0, NIC_DCB_DUMP, NIC_PAUSE_DUMP, + NIC_PFC_STORM_PARA_DUMP, };
struct nic_buf_waterline { @@ -50,6 +51,14 @@ struct nic_pfc_info { uint8_t rsv[2]; };
+struct nic_pfc_storm_para { + uint32_t dir; + uint32_t enable; + uint32_t period_ms; + uint32_t times; + uint32_t recovery_period_ms; +}; + struct nic_ets_info { uint8_t prio_tc[HIKP_NIC_MAX_USER_PRIO_NUM]; uint8_t tc_bw[HIKP_NIC_MAX_TC_NUM]; @@ -82,6 +91,7 @@ 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 nic_qos_rsp_head { @@ -99,11 +109,21 @@ struct nic_qos_rsp { struct nic_qos_req_para { struct bdf_t bdf; uint8_t block_id; + uint8_t dir; + uint8_t rsv[2]; +}; + +enum nic_pfc_dir { + NIC_RX_QUEUE = 0, + NIC_TX_QUEUE, + NIC_QUEUE_DIR_NONE, };
struct nic_qos_param { struct tool_target target; int feature_idx; + enum nic_pfc_dir dir; + char revision_id[MAX_PCI_ID_LEN + 1]; };
#define HIKP_QOS_MAX_FEATURE_NAME_LEN 20
From: Hao Chen chenhao418@huawei.com
add nic_torus cmd for query 1D torus setting info
AR:AR20230712033425 Bugfix or Feature: Feature
Signed-off-by: Hao Chen chenhao418@huawei.com --- net/hikp_net_lib.h | 1 + net/nic/nic_torus/hikp_nic_torus.c | 189 +++++++++++++++++++++++++++++ net/nic/nic_torus/hikp_nic_torus.h | 76 ++++++++++++ 3 files changed, 266 insertions(+) create mode 100644 net/nic/nic_torus/hikp_nic_torus.c create mode 100644 net/nic/nic_torus/hikp_nic_torus.h
diff --git a/net/hikp_net_lib.h b/net/hikp_net_lib.h index cb537ff..21b5357 100644 --- a/net/hikp_net_lib.h +++ b/net/hikp_net_lib.h @@ -80,6 +80,7 @@ enum nic_cmd_type { GET_GRO_INFO_CMD, GET_NCSI_INFO_CMD, GET_NOTIFY_PKT_CMD, + GET_TORUS_INFO_CMD = 0xD, GET_PORT_FAULT_STATUS = 0xE, };
diff --git a/net/nic/nic_torus/hikp_nic_torus.c b/net/nic/nic_torus/hikp_nic_torus.c new file mode 100644 index 0000000..4baede6 --- /dev/null +++ b/net/nic/nic_torus/hikp_nic_torus.c @@ -0,0 +1,189 @@ +/* + * Copyright (c) 2023 Hisilicon Technologies Co., Ltd. + * Hikptool is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * + * See the Mulan PSL v2 for more details. + */ + +#include <stdio.h> +#include <string.h> +#include <sys/types.h> +#include <unistd.h> + +#include "hikp_nic_torus.h" + +static struct tool_target g_torus_target; + +static int hikp_nic_torus_query(const struct bdf_t *bdf, + struct nic_torus_info *info) +{ + struct nic_torus_req_para req = { 0 }; + struct hikp_cmd_header header = { 0 }; + struct hikp_cmd_ret *cmd_ret; + struct nic_torus_rsp *rsp; + + 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); + if (cmd_ret) + free(cmd_ret); + return -EIO; + } + + rsp = (struct nic_torus_rsp *)cmd_ret->rsp_data; + *info = *(struct nic_torus_info *)rsp->data; + free(cmd_ret); + + return 0; +} + +static void hikp_nic_torus_lan_prt_pair_show(const struct nic_torus_info *info) +{ + uint32_t mac_id = hikp_get_field(info->lan_prt_pair, NIC_TORUS_MAC_ID_M, + NIC_TORUS_MAC_ID_S); + uint32_t uc_lan_pair_en = hikp_get_bit(info->lan_prt_pair, + NIC_TORUS_UC_LAN_PAIR_EN); + uint32_t mc_bc_lan_pair_en = hikp_get_bit(info->lan_prt_pair, + NIC_TORUS_MC_BC_LAN_PAIR_EN); + uint32_t lldp_lan_pair_en = hikp_get_bit(info->lan_prt_pair, + NIC_TORUS_LLDP_LAN_PAIR_EN); + uint32_t tc2vlanpri_mapping_en = hikp_get_bit(info->lan_prt_pair, + NIC_TORUS_TC2VLANPRI_MAPPING_EN); + uint32_t torus_lpbk_drop_en = hikp_get_bit(info->lan_prt_pair, + NIC_TORUS_LPBK_DROP_EN); + + printf("dst mac id: %u\n", mac_id); + printf("uc_lan_pair_en: %u\n", uc_lan_pair_en); + printf("mc_bc_lan_pair_en: %u\n", mc_bc_lan_pair_en); + printf("lldp_lan_pair_en: %u\n", lldp_lan_pair_en); + printf("tc2vlanpri_mapping_en: %u\n", tc2vlanpri_mapping_en); + printf("torus_lpbk_drop_en: %u\n", torus_lpbk_drop_en); +} + +static void hikp_nic_torus_lan_fwd_tc_cfg_show(const struct nic_torus_info *info) +{ + uint32_t tc0_map_tc = hikp_get_field(info->lan_fwd_tc_cfg, + NIC_TORUS_TC0_MAP_TC_M, + NIC_TORUS_TC0_MAP_TC_S); + uint32_t tc1_map_tc = hikp_get_field(info->lan_fwd_tc_cfg, + NIC_TORUS_TC1_MAP_TC_M, + NIC_TORUS_TC1_MAP_TC_S); + uint32_t tc2_map_tc = hikp_get_field(info->lan_fwd_tc_cfg, + NIC_TORUS_TC2_MAP_TC_M, + NIC_TORUS_TC2_MAP_TC_S); + uint32_t tc3_map_tc = hikp_get_field(info->lan_fwd_tc_cfg, + NIC_TORUS_TC3_MAP_TC_M, + NIC_TORUS_TC3_MAP_TC_S); + + printf("tc0_map_tc : %u\n", tc0_map_tc); + printf("tc1_map_tc : %u\n", tc1_map_tc); + printf("tc2_map_tc : %u\n", tc2_map_tc); + printf("tc3_map_tc : %u\n", tc3_map_tc); +} + +static void hikp_nic_torus_switch_param_show(const struct nic_torus_info *info) +{ + printf("nic_mac_anti_spoof_en: %s\n", info->nic_switch_param & + NIC_TORUS_MAC_ANTI_SPOOF_EN_MASK ? "enable" : "disable"); + printf("nic_alw_lpbk: %s\n", info->nic_switch_param & + NIC_TORUS_ALW_LPBK_MASK ? "enable" : "disable"); + printf("nic_alw_lcl_lpbk: %s\n", info->nic_switch_param & + NIC_TORUS_ALW_LCL_LPBK_MASK ? "enable" : "disable"); + printf("nic_alw_dst_ovrd: %s\n", info->nic_switch_param & + NIC_TORUS_ALW_DST_OVRD_MASK ? "enable" : "disable"); + printf("roce_mac_anti_spoof_en: %s\n", info->roce_switch_param & + NIC_TORUS_MAC_ANTI_SPOOF_EN_MASK ? "enable" : "disable"); + printf("roce_alw_lpbk: %s\n", info->roce_switch_param & + NIC_TORUS_ALW_LPBK_MASK ? "enable" : "disable"); + printf("roce_alw_lcl_lpbk: %s\n", info->roce_switch_param & + NIC_TORUS_ALW_LCL_LPBK_MASK ? "enable" : "disable"); + printf("roce_alw_dst_ovrd: %s\n", info->roce_switch_param & + NIC_TORUS_ALW_DST_OVRD_MASK ? "enable" : "disable"); +} + +static void hikp_nic_torus_show(const struct nic_torus_info *info) +{ + printf("################ NIC TORUS info ##################\n"); + printf("enable: %s\n", info->enable ? "true" : "false"); + + hikp_nic_torus_lan_prt_pair_show(info); + + hikp_nic_torus_lan_fwd_tc_cfg_show(info); + + printf("ssu_pause_time_out: %uus\n", info->pause_time_out); + printf("ssu_pause_time_out_en: %u\n", info->pause_time_out_en); + printf("vlan_fe: 0x%x (for port vlan)\n", info->vlan_fe); + printf("ets_tcg0_mapping: 0x%x\n", info->ets_tcg0_mapping); + printf("ets_tcg0_mapping is showed as 0xff if ncl_config forward bit is setted to 1\n"); + + hikp_nic_torus_switch_param_show(info); + + printf("#################### END ##########################\n"); +} + +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; + int ret; + + ret = hikp_nic_torus_query(bdf, &info); + if (ret != 0) { + snprintf(self->err_str, sizeof(self->err_str), "fail to obtain torus info."); + self->err_no = ret; + return; + } + + hikp_nic_torus_show(&info); +} + +static int hikp_nic_torus_cmd_help(struct major_cmd_ctrl *self, const char *argv) +{ + printf("\n Usage: %s %s\n", self->cmd_ptr->name, "-i <device>"); + printf("\n %s\n", self->cmd_ptr->help_info); + printf("\n Options:\n\n"); + printf(" %s, %-25s %s\n", "-h", "--help", "display this help and exit"); + printf(" %s, %-25s %s\n", "-i", "--interface=<interface>", + "device target or bdf id, e.g. eth0~7 or 0000:35:00.0"); + + return 0; +} + +static int hikp_nic_torus_get_target(struct major_cmd_ctrl *self, const char *argv) +{ + self->err_no = tool_check_and_get_valid_bdf_id(argv, &g_torus_target); + if (self->err_no != 0) { + snprintf(self->err_str, sizeof(self->err_str), "unknown device!"); + return self->err_no; + } + + if (g_torus_target.bdf.dev_id != 0) { + snprintf(self->err_str, sizeof(self->err_str), "VF does not support query!"); + self->err_no = -EOPNOTSUPP; + return self->err_no; + } + + return 0; +} + +static void cmd_nic_torus_init(void) +{ + struct major_cmd_ctrl *major_cmd = get_major_cmd(); + + major_cmd->option_count = 0; + major_cmd->execute = hikp_nic_torus_cmd_execute; + + cmd_option_register("-h", "--help", false, hikp_nic_torus_cmd_help); + cmd_option_register("-i", "--interface", true, hikp_nic_torus_get_target); +} + +HIKP_CMD_DECLARE("nic_torus", "dump torus info of nic!", cmd_nic_torus_init); diff --git a/net/nic/nic_torus/hikp_nic_torus.h b/net/nic/nic_torus/hikp_nic_torus.h new file mode 100644 index 0000000..e6b6552 --- /dev/null +++ b/net/nic/nic_torus/hikp_nic_torus.h @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2023 Hisilicon Technologies Co., Ltd. + * Hikptool is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * + * See the Mulan PSL v2 for more details. + */ + +#ifndef HIKP_NIC_TORUS_H +#define HIKP_NIC_TORUS_H + +#include "hikp_net_lib.h" + +#define NIC_TORUS_MAC_ANTI_SPOOF_EN_MASK 0x1 +#define NIC_TORUS_ALW_LPBK_MASK 0x2 +#define NIC_TORUS_ALW_LCL_LPBK_MASK 0x4 +#define NIC_TORUS_ALW_DST_OVRD_MASK 0x8 + +#define NIC_TORUS_UC_LAN_PAIR_EN 16 +#define NIC_TORUS_MC_BC_LAN_PAIR_EN 17 +#define NIC_TORUS_LLDP_LAN_PAIR_EN 18 +#define NIC_TORUS_TC2VLANPRI_MAPPING_EN 19 +#define NIC_TORUS_LPBK_DROP_EN 20 + +#define NIC_TORUS_MAC_ID_M GENMASK(1, 0) +#define NIC_TORUS_MAC_ID_S 0 + +#define NIC_TORUS_TC0_MAP_TC_M GENMASK(2, 0) +#define NIC_TORUS_TC0_MAP_TC_S 0 +#define NIC_TORUS_TC1_MAP_TC_M GENMASK(8, 6) +#define NIC_TORUS_TC1_MAP_TC_S 6 +#define NIC_TORUS_TC2_MAP_TC_M GENMASK(14, 12) +#define NIC_TORUS_TC2_MAP_TC_S 12 +#define NIC_TORUS_TC3_MAP_TC_M GENMASK(20, 18) +#define NIC_TORUS_TC3_MAP_TC_S 18 + +enum nic_torus_sub_cmd_type { + NIC_TORUS_INFO_DUMP, +}; + +struct nic_torus_req_para { + struct bdf_t bdf; + uint8_t block_id; + uint8_t rsv[3]; +}; + +struct nic_torus_rsp_head { + uint8_t total_blk_num; + uint8_t curr_blk_size; /* real data size, not contain head size. */ + uint16_t rsv; +}; + +#define NIC_TORUS_MAX_RSP_DATA 6 +struct nic_torus_rsp { + struct nic_torus_rsp_head head; + uint32_t data[NIC_TORUS_MAX_RSP_DATA]; +}; + +struct nic_torus_info { + uint32_t enable; + uint32_t lan_prt_pair; + uint32_t lan_fwd_tc_cfg; + uint32_t pause_time_out; + uint8_t pause_time_out_en; + uint8_t vlan_fe; + uint8_t nic_switch_param; + uint8_t roce_switch_param; + uint32_t ets_tcg0_mapping; +}; + +#endif /* HIKP_NIC_TORUS_H */
A command word was added to query the port information display capability. If a port does not support a flexible card, the card information is not displayed.
Signed-off-by: veega zhuweijia@huawei.com --- net/nic/nic_mac/hikp_mac_cmd.h | 1 + net/nic/nic_mac/hikp_nic_port.c | 81 +++++++++++++++++++++------------ net/nic/nic_mac/hikp_nic_port.h | 17 ++++--- 3 files changed, 65 insertions(+), 34 deletions(-)
diff --git a/net/nic/nic_mac/hikp_mac_cmd.h b/net/nic/nic_mac/hikp_mac_cmd.h index adaadf4..f74fd2a 100644 --- a/net/nic/nic_mac/hikp_mac_cmd.h +++ b/net/nic/nic_mac/hikp_mac_cmd.h @@ -31,6 +31,7 @@ enum mac_port_sub_cmd { QUERY_PORT_PHY_DFX, QUERY_HOT_PLUG_CARD_DFX, QUERY_PORT_CDR_DFX, + QUERY_PORT_INFO_DFX_CAP, };
enum mac_dump_reg_sub_cmd { diff --git a/net/nic/nic_mac/hikp_nic_port.c b/net/nic/nic_mac/hikp_nic_port.c index c9f46fc..5ba6927 100644 --- a/net/nic/nic_mac/hikp_nic_port.c +++ b/net/nic/nic_mac/hikp_nic_port.c @@ -361,11 +361,12 @@ static void mac_cmd_disp_arb_info(const struct mac_cmd_arb_dfx *arb_dfx)
static void mac_cmd_disp_hot_plug_card_info(const struct cmd_hot_plug_card_info *hpc_dfx) { - printf("\n======================== HOT PLUG CARD INFO =======================\n"); + printf("\n===================== HOT PLUG CARD INFO =====================\n");
printf("hot plug card in position: 0x%x\n", hpc_dfx->in_pos); printf("support type: 0x%x\n", hpc_dfx->support_type); - printf("current type: 0x%x\n", hpc_dfx->cur_type); + if (hpc_dfx->in_pos) + printf("current type: 0x%x\n", hpc_dfx->cur_type); printf("----------------------------------------------------------------------------\n"); }
@@ -408,13 +409,13 @@ static void mac_cmd_show_hot_plug_card(struct major_cmd_ctrl *self) static void mac_cmd_print_cdr_dfx(struct mac_cmd_cdr_dfx *cdr_dfx, struct mac_port_cdr_dfx *info) { struct mac_item type_table[] = { - {PORT_CDR_SD5902, "sd5902"}, {PORT_CDR_SD5901, "sd5901"}, + {PORT_CDR_TYPE_A, "cdr_a"}, {PORT_CDR_TYPE_B, "cdr_b"}, }; - struct mac_item sd5902_mode[] = { - {SD5902_MODE_2PLL, "2pll"}, {SD5902_MODE_FASTPI, "fastpi"}, + struct mac_item cdr_a_mode[] = { + {CDR_A_MODE_2PLL, "2pll"}, {CDR_A_MODE_FASTPI, "fastpi"}, }; - struct mac_item sd5901_mode[] = { - {SD5901_MODE_PCS, "pcs"}, {SD5901_MODE_CDR, "cdr"}, + struct mac_item cdr_b_mode[] = { + {CDR_B_MODE_PCS, "pcs"}, {CDR_B_MODE_CDR, "cdr"}, }; struct mac_item status_table[] = { {CDR_STATUS_NORMAL, "normal"}, {CDR_STATUS_ERROR, "error"}, @@ -424,12 +425,12 @@ static void mac_cmd_print_cdr_dfx(struct mac_cmd_cdr_dfx *cdr_dfx, struct mac_po const char *mode_str = "NA";
for (uint32_t i = 0; i < cdr_dfx->cdr_num; i++) { - if (cdr_dfx->cdr_type == PORT_CDR_SD5902) { - mode_str = mac_get_str(info->dfx[i].cdr_mode, sd5902_mode, - HIKP_ARRAY_SIZE(sd5902_mode), "unknown"); - } else if (cdr_dfx->cdr_type == PORT_CDR_SD5901) { - mode_str = mac_get_str(info->dfx[i].cdr_mode, sd5901_mode, - HIKP_ARRAY_SIZE(sd5901_mode), "unknown"); + if (cdr_dfx->cdr_type == PORT_CDR_TYPE_A) { + mode_str = mac_get_str(info->dfx[i].cdr_mode, cdr_a_mode, + HIKP_ARRAY_SIZE(cdr_a_mode), "unknown"); + } else if (cdr_dfx->cdr_type == PORT_CDR_TYPE_B) { + mode_str = mac_get_str(info->dfx[i].cdr_mode, cdr_b_mode, + HIKP_ARRAY_SIZE(cdr_b_mode), "unknown"); } printf("\t|0x%-8x%-9u%-10s%-10s%-10s\n", info->dfx[i].cdr_addr, info->dfx[i].cdr_start_lane, type_str, mode_str, @@ -491,35 +492,59 @@ static void mac_cmd_show_port_dfx(struct major_cmd_ctrl *self, uint32_t mask) } }
-static void mac_cmd_port_execute(struct major_cmd_ctrl *self) +static int mac_cmd_get_port_dfx_cap(uint32_t *cap) { struct mac_cmd_port_hardware *port_hw = NULL; + struct mac_cmd_port_dfx_cap *dfx_cap = NULL; + struct hikp_cmd_ret *dfx_cap_resp = NULL; struct hikp_cmd_ret *hw_cmd_ret = NULL; - uint32_t mask; int ret;
- if (!g_port_info.port_flag) { - self->err_no = -EINVAL; - snprintf(self->err_str, sizeof(self->err_str), "Need port id."); - return; + ret = mac_cmd_get_dfx_cfg(QUERY_PORT_INFO_DFX_CAP, &dfx_cap_resp); + if (ret == 0) { + dfx_cap = (struct mac_cmd_port_dfx_cap *)dfx_cap_resp->rsp_data; + *cap = dfx_cap->cap_bit_map; + free(dfx_cap_resp); + dfx_cap_resp = NULL; + return ret; }
+ /* not support get capability, so use old process */ ret = mac_cmd_get_dfx_cfg(QUERY_PORT_HARDWARE, &hw_cmd_ret); - if (ret != 0) { - printf("hikp_data_proc get port hw failed.\n"); - self->err_no = -ENOSPC; - return; - } + if (ret) + return ret;
- mask = MAC_LSPORT_LINK | MAC_LSPORT_MAC | - MAC_LSPORT_ARB | MAC_HOT_PLUG_CARD | MAC_LSPORT_CDR; + *cap = MAC_LSPORT_LINK | MAC_LSPORT_MAC | MAC_LSPORT_ARB | + MAC_HOT_PLUG_CARD | MAC_LSPORT_CDR; port_hw = (struct mac_cmd_port_hardware *)(hw_cmd_ret->rsp_data); if (port_hw->port_type == HIKP_PORT_TYPE_PHY || port_hw->port_type == HIKP_PORT_TYPE_PHY_SDS) - mask |= MAC_LSPORT_PHY; + *cap |= MAC_LSPORT_PHY;
- mac_cmd_show_port_dfx(self, mask); free(hw_cmd_ret); + hw_cmd_ret = NULL; + return ret; +} + +static void mac_cmd_port_execute(struct major_cmd_ctrl *self) +{ + uint32_t dfx_cap; + int ret; + + if (!g_port_info.port_flag) { + self->err_no = -EINVAL; + snprintf(self->err_str, sizeof(self->err_str), "Need port id."); + return; + } + + ret = mac_cmd_get_port_dfx_cap(&dfx_cap); + if (ret) { + self->err_no = ret; + snprintf(self->err_str, sizeof(self->err_str), "Get DFX capability failed."); + return; + } + + mac_cmd_show_port_dfx(self, dfx_cap); }
static int mac_cmd_get_port_target(struct major_cmd_ctrl *self, const char *argv) diff --git a/net/nic/nic_mac/hikp_nic_port.h b/net/nic/nic_mac/hikp_nic_port.h index 42ab3f9..78928b3 100644 --- a/net/nic/nic_mac/hikp_nic_port.h +++ b/net/nic/nic_mac/hikp_nic_port.h @@ -188,18 +188,18 @@ struct mac_cmd_phy_info { };
enum { - PORT_CDR_SD5902 = 0, - PORT_CDR_SD5901, + PORT_CDR_TYPE_A = 0, + PORT_CDR_TYPE_B, };
enum { - SD5902_MODE_2PLL = 0, - SD5902_MODE_FASTPI, + CDR_A_MODE_2PLL = 0, + CDR_A_MODE_FASTPI, };
enum { - SD5901_MODE_PCS = 0, - SD5901_MODE_CDR, + CDR_B_MODE_PCS = 0, + CDR_B_MODE_CDR, };
enum { @@ -225,6 +225,11 @@ struct mac_cmd_cdr_dfx { struct mac_port_cdr_dfx host_cdr; };
+struct mac_cmd_port_dfx_cap { + uint32_t cap_bit_map; + uint32_t rsvd[3]; +}; + struct mac_cmd_dfx_callback { uint32_t mask; void (*show_dfx)(struct major_cmd_ctrl *self);