diff --git a/0108-hikptool-solve-some-code-review-comments.patch b/0108-hikptool-solve-some-code-review-comments.patch new file mode 100644 index 0000000000000000000000000000000000000000..70c0a82ce1b0b4d192387f51be96125a6fab8b13 --- /dev/null +++ b/0108-hikptool-solve-some-code-review-comments.patch @@ -0,0 +1,881 @@ +From 8f79cb062d73d3926c202ef0405aba10a0238609 Mon Sep 17 00:00:00 2001 +From: veega2022 +Date: Tue, 26 Aug 2025 19:15:14 +0800 +Subject: [PATCH] hikptool: solve some code review comments + +Code review comments include: +1. Spelling errors in words +2. Unreasonable buffer validation +3. Insufficiently clear print information for exception branches +4. No validation of function return values +5. Optimization of large functions + +Signed-off-by: veega2022 +--- + CMakeLists.txt | 4 +- + hccs/hikp_hccs.c | 26 ++- + info_collect/hikp_collect_serdes.c | 2 +- + libhikptdev/src/rciep/hikpt_rciep.c | 5 +- + net/hikp_net_lib.c | 2 +- + net/nic/nic_fd/hikp_nic_fd.c | 18 +- + net/nic/nic_fd/hikp_nic_fd.h | 2 +- + net/nic/nic_info/hikp_nic_info.c | 2 +- + net/nic/nic_log/hikp_nic_log.c | 2 +- + net/nic/nic_ppp/hikp_nic_ppp.c | 10 +- + net/nic/nic_ppp/hikp_nic_ppp.h | 4 +- + net/nic/nic_torus/hikp_nic_torus.c | 2 +- + .../roce_ext_common/hikp_roce_ext_common.c | 162 +++++++++++------- + net/roce/roce_scc/hikp_roce_scc.c | 2 +- + net/roce/roce_scc/hikp_roce_scc.h | 1 - + net/roce/roce_trp/hikp_roce_trp.c | 2 +- + net/roh/hikp_roh_mac.c | 6 +- + pcie/func_lib/pcie_func/pcie_reg_dump.c | 5 +- + pcie/func_lib/pcie_func/pcie_reg_read.c | 2 +- + pcie/usr_cmd/cmd_analysis/pcie_cmd_trace.c | 2 +- + sas/user_cmd/cmd_code/sas_cmd_anacq.c | 4 +- + sas/user_cmd/cmd_code/sas_cmd_anadq.c | 4 +- + sas/user_cmd/cmd_code/sas_cmd_dev.c | 2 +- + sas/user_cmd/cmd_code/sas_cmd_dqe.c | 2 +- + serdes/hikp_serdes.c | 28 ++- + socip/hikp_socip_dumpreg.c | 6 +- + tool_lib/tool_lib.c | 8 +- + 27 files changed, 178 insertions(+), 137 deletions(-) + +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 386cc28..86053a1 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -9,6 +9,8 @@ + # + # See the Mulan PSL v2 for more details. + ++cmake_minimum_required(VERSION 3.0.0) ++ + project(hikptool C) + + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} \ +@@ -61,7 +63,7 @@ target_include_directories(hikptool PRIVATE ${HIKPTOOL_HEADER_DIR}) + target_link_directories(hikptool PRIVATE ${CMAKE_INSTALL_PREFIX}/lib) + target_link_libraries(hikptool PRIVATE KPTDEV_SO) + if (ENABLE_STATIC) +- # I don¡¯t know why, but once you add double quotes to these ++ # I don't know why, but once you add double quotes to these + # link parameters, an error will be reported. + set(EXT_LINK_FLAGS -static-libgcc -static-libstdc++ -static) + set_target_properties(hikptool PROPERTIES LINK_SEARCH_START_STATIC ON) +diff --git a/hccs/hikp_hccs.c b/hccs/hikp_hccs.c +index d979aad..f6ef003 100644 +--- a/hccs/hikp_hccs.c ++++ b/hccs/hikp_hccs.c +@@ -11,6 +11,7 @@ + * See the Mulan PSL v2 for more details. + */ + ++#include + #include + #include + #include +@@ -613,39 +614,32 @@ static void hikp_hccs_show_port_dfx_info(union hccs_feature_info *feature_info) + size_t vld_size; + + vld_size = (size_t)info_vld->vld_size; +- if (vld_size >= sizeof(info->link_fsm)) { ++ if (vld_size > offsetof(struct hccs_port_dfx_info, link_fsm)) { + printf("%-16s\t%s\n", "link_fsm", hikp_hccs_link_fsm_to_str(info->link_fsm)); +- vld_size -= sizeof(info->link_fsm); + } + +- if (vld_size >= sizeof(info->cur_lane_num)) { ++ if (vld_size > offsetof(struct hccs_port_dfx_info, cur_lane_num)) { + printf("%-16s\t%u\n", "cur_lane_num", info->cur_lane_num); +- vld_size -= sizeof(info->cur_lane_num); + } + +- if (vld_size >= sizeof(info->lane_mask)) { ++ if (vld_size > offsetof(struct hccs_port_dfx_info, lane_mask)) { + printf("%-16s\t0x%x\n", "lane_mask", info->lane_mask); +- vld_size -= sizeof(info->lane_mask); + } + +- if (vld_size >= sizeof(info->crc_err_cnt)) { ++ if (vld_size > offsetof(struct hccs_port_dfx_info, crc_err_cnt)) { + printf("%-16s\t%u\n", "crc_err_cnt", info->crc_err_cnt); +- vld_size -= sizeof(info->crc_err_cnt); + } + +- if (vld_size >= sizeof(info->retry_cnt)) { ++ if (vld_size > offsetof(struct hccs_port_dfx_info, retry_cnt)) { + printf("%-16s\t%u\n", "retry_cnt", info->retry_cnt); +- vld_size -= sizeof(info->retry_cnt); + } + +- if (vld_size >= sizeof(info->phy_reinit_cnt)) { ++ if (vld_size > offsetof(struct hccs_port_dfx_info, phy_reinit_cnt)) { + printf("%-16s\t%u\n", "phy_reinit_cnt", info->phy_reinit_cnt); +- vld_size -= sizeof(info->phy_reinit_cnt); + } + +- if (vld_size >= sizeof(info->tx_credit)) { ++ if (vld_size > offsetof(struct hccs_port_dfx_info, tx_credit)) { + printf("%-16s\t%u\n", "tx_credit", info->tx_credit); +- vld_size -= sizeof(info->tx_credit); + } + } + +@@ -748,7 +742,7 @@ static int hikp_hccs_cmd_parse_die(struct major_cmd_ctrl *self, const char *argv + self->err_no = string_toui(argv, &die_id); + if (self->err_no) { + snprintf(self->err_str, sizeof(self->err_str), +- "Failed to parse -d/--die_id parameter."); ++ "Failed to parse -d/--die_id parameter."); + return self->err_no; + } + +@@ -778,7 +772,7 @@ static int hikp_hccs_cmd_parse_port(struct major_cmd_ctrl *self, const char *arg + + if (port_id > UINT8_MAX) { + snprintf(self->err_str, sizeof(self->err_str), +- "port id should not be greater %u.", UINT8_MAX); ++ "port id should not be greater than %u.", UINT8_MAX); + self->err_no = -EINVAL; + return self->err_no; + } +diff --git a/info_collect/hikp_collect_serdes.c b/info_collect/hikp_collect_serdes.c +index 31f29b3..ff58629 100644 +--- a/info_collect/hikp_collect_serdes.c ++++ b/info_collect/hikp_collect_serdes.c +@@ -210,7 +210,7 @@ static void collect_serdes_dump_log(void) + log_cmd.die_id = j; + ret = snprintf(log_name, MAX_LOG_NAME_LEN, "serdes_dump_c%ud%u", i, j); + if (ret < 0 || (uint32_t)(ret) >= MAX_LOG_NAME_LEN) { +- HIKP_ERROR_PRINT("create serdes_info log name failed\n"); ++ HIKP_ERROR_PRINT("create serdes_dump log name failed\n"); + break; + } + ret = hikp_collect_log(GROUP_SERDES, log_name, +diff --git a/libhikptdev/src/rciep/hikpt_rciep.c b/libhikptdev/src/rciep/hikpt_rciep.c +index 88ac16e..5cdf258 100644 +--- a/libhikptdev/src/rciep/hikpt_rciep.c ++++ b/libhikptdev/src/rciep/hikpt_rciep.c +@@ -73,7 +73,8 @@ static int hikp_try_lock(void) + count--; + usleep(LOCK_CHECK_GAP_US); + } while (count); +- printf("dev lock by other process:%u.\n", g_hikp_req->field.pid_record); ++ printf("try to lock failed, lock may be occupied by another process: %u, error: %s\n", ++ g_hikp_req->field.pid_record, strerror(errno)); + + return -EBUSY; + } +@@ -187,7 +188,7 @@ static int hikp_req_first_round(uint32_t *req_data, uint32_t rep_num, uint32_t * + req_issue(); /* On the first round, an interrupt is triggered. */ + *cpl_status = hikp_wait_for_cpl_status(); + if (*cpl_status != HIKP_CPL_BY_TF && *cpl_status != HIKP_CPL_BY_IMU) { +- printf("First round failed. Error code:%u.\n", *cpl_status); ++ printf("First round failed. Error code:0x%X.\n", *cpl_status); + return RCIEP_FAIL; + } + +diff --git a/net/hikp_net_lib.c b/net/hikp_net_lib.c +index 7646aad..91c00d9 100644 +--- a/net/hikp_net_lib.c ++++ b/net/hikp_net_lib.c +@@ -97,7 +97,7 @@ static bool check_and_parse_domain_bdf_id(const char *bus_info, struct bdf_t *bd + if (strlen(bus_info) >= IFNAMSIZ) + return false; + +- /* pci_id: 0000:bd:00.0 ==> doman:bus:device.function add ++ /* pci_id: 0000:bd:00.0 ==> domain:bus:device.function add + * remains here to solve such input: 0000:bd:00.0abcdef + */ + retval = sscanf(bus_info, "%x:%x:%x.%u%s", &domain, &bus, &dev, &fun, remains); +diff --git a/net/nic/nic_fd/hikp_nic_fd.c b/net/nic/nic_fd/hikp_nic_fd.c +index 891368a..8a2bfb3 100644 +--- a/net/nic/nic_fd/hikp_nic_fd.c ++++ b/net/nic/nic_fd/hikp_nic_fd.c +@@ -26,7 +26,7 @@ struct key_info { + + static const struct key_info g_meta_data_key_info[] = { + {"packet_type_id", PACKET_TYPE_ID, 6}, +- {"fragement", IP_FRAGEMENT, 1}, ++ {"fragment", IP_FRAGMENT, 1}, + {"roce_type", ROCE_TYPE, 1}, + {"next_key", NEXT_KEY, 5}, + {"vlan_num", VLAN_NUMBER, 2}, +@@ -169,7 +169,7 @@ static void hikp_nic_show_fd_key_info(struct nic_fd_hw_info *hw_info) + printf(" outer_dest_ipv6_word_en: 0x%x\n", key_cfg->outer_dest_ipv6_word_en); + + if (key_cfg->key_select == HNS3_FD_KEY_BASE_ON_PTYPE) { +- HIKP_WARN_PRINT("Unsupport for parsing packet type key.\n"); ++ HIKP_WARN_PRINT("Unsupported for parsing packet type key.\n"); + continue; + } + +@@ -333,7 +333,7 @@ static void hikp_nic_print_meta_data(uint16_t type, uint32_t val) + case NEXT_KEY: + printf("%u", val); + break; +- case IP_FRAGEMENT: ++ case IP_FRAGMENT: + printf("%s", val == 0 ? "NON-IP frag packet" : "IP frag packet"); + break; + case ROCE_TYPE: +@@ -676,14 +676,14 @@ static int hikp_nic_query_fd_rules(struct hikp_cmd_header *req_header, const str + } + if (rsp_head.cur_blk_entry_cnt + entry_cnt > g_fd_hw_info.alloc.stage_entry_num[stage]) { + HIKP_ERROR_PRINT("The sum of entry number (%u) after block-%u " +- "is over the maximum entry nubmer (%u) of this stage.", ++ "is over the maximum entry number (%u) of this stage.", + rsp_head.cur_blk_entry_cnt + entry_cnt, idx, + g_fd_hw_info.alloc.stage_entry_num[stage]); + return -EINVAL; + } + entry_cnt += rsp_head.cur_blk_entry_cnt; + if (rsp_head.next_entry_idx <= idx) { +- HIKP_ERROR_PRINT("The next entry index (%u) is less than or equal with the curent(%u).\n", ++ HIKP_ERROR_PRINT("The next entry index (%u) is less than or equal with the current(%u).\n", + rsp_head.next_entry_idx, idx); + return -EINVAL; + } +@@ -735,14 +735,14 @@ static int hikp_nic_query_fd_counter(struct hikp_cmd_header *req_header, const s + } + if (rsp_head.cur_blk_entry_cnt + entry_size > g_fd_hw_info.alloc.stage_counter_num[stage]) { + HIKP_ERROR_PRINT("The sum of entry number (%u) after block-%u " +- "is over the maximum counter nubmer (%u) of this stage.", ++ "is over the maximum counter number (%u) of this stage.", + rsp_head.cur_blk_entry_cnt + entry_size, idx, + g_fd_hw_info.alloc.stage_counter_num[stage]); + return -EINVAL; + } + entry_size += rsp_head.cur_blk_entry_cnt; + if (rsp_head.next_entry_idx <= idx) { +- HIKP_ERROR_PRINT("The next entry index (%u) is less than or equal with the curent(%u).\n", ++ HIKP_ERROR_PRINT("The next entry index (%u) is less than or equal with the current(%u).\n", + rsp_head.next_entry_idx, idx); + return -EINVAL; + } +@@ -856,7 +856,7 @@ static int hikp_nic_check_fd_hw_info(const struct nic_fd_hw_info *hw_info, + } + if (hw_info->mode > FD_MODE_DEPTH_2K_WIDTH_200B_STAGE_2) + HIKP_WARN_PRINT("Unknown fd mode(%u), " +- "unsupport for displaying meta data info.\n", ++ "unsupported for displaying meta data info.\n", + hw_info->mode); + + for (i = 0; i < NIC_FD_STAGE_NUM; i++) { +@@ -1080,7 +1080,7 @@ static int hikp_nic_cmd_fd_parse_stage(struct major_cmd_ctrl *self, const char * + + if (stage_no - 1 == NIC_FD_STAGE_2) { + snprintf(self->err_str, sizeof(self->err_str), +- "unsupport for querying stage%u entry!", stage_no); ++ "unsupported for querying stage%u entry!", stage_no); + self->err_no = -EOPNOTSUPP; + return self->err_no; + } +diff --git a/net/nic/nic_fd/hikp_nic_fd.h b/net/nic/nic_fd/hikp_nic_fd.h +index 98577ff..7b1331d 100644 +--- a/net/nic/nic_fd/hikp_nic_fd.h ++++ b/net/nic/nic_fd/hikp_nic_fd.h +@@ -56,7 +56,7 @@ enum nic_fd_tuple { + + enum nic_fd_meta_data { + PACKET_TYPE_ID = 0, +- IP_FRAGEMENT, ++ IP_FRAGMENT, + ROCE_TYPE, + NEXT_KEY, + VLAN_NUMBER, +diff --git a/net/nic/nic_info/hikp_nic_info.c b/net/nic/nic_info/hikp_nic_info.c +index b05d6ef..a1985a9 100644 +--- a/net/nic/nic_info/hikp_nic_info.c ++++ b/net/nic/nic_info/hikp_nic_info.c +@@ -249,7 +249,7 @@ static int hikp_nic_traverse_all_hns3_dev_and_get_info(void) + + sockfd = hikp_net_creat_sock(); + if (sockfd < MIN_SOCKFD) { +- HIKP_ERROR_PRINT("creat sockfd failed, sockfd is %d.\n", sockfd); ++ HIKP_ERROR_PRINT("create sockfd failed, sockfd is %d.\n", sockfd); + return -EIO; + } + ret = getifaddrs(&ifa_lst); +diff --git a/net/nic/nic_log/hikp_nic_log.c b/net/nic/nic_log/hikp_nic_log.c +index 4dd2721..d2af181 100644 +--- a/net/nic/nic_log/hikp_nic_log.c ++++ b/net/nic/nic_log/hikp_nic_log.c +@@ -64,7 +64,7 @@ static int hikp_nic_write_data_to_file(uint8_t *data, uint32_t len) + + rc = snprintf(g_log_path, sizeof(g_log_path), HIKP_LOG_DIR_PATH"%s", file_name); + if (rc < 0) { +- HIKP_ERROR_PRINT("creat log file path fail.\n"); ++ HIKP_ERROR_PRINT("create log file path fail.\n"); + return -EIO; + } + +diff --git a/net/nic/nic_ppp/hikp_nic_ppp.c b/net/nic/nic_ppp/hikp_nic_ppp.c +index 43a9000..d5cf61f 100644 +--- a/net/nic/nic_ppp/hikp_nic_ppp.c ++++ b/net/nic/nic_ppp/hikp_nic_ppp.c +@@ -555,7 +555,7 @@ static int hikp_nic_ppp_query_uc_mac_addr(struct hikp_cmd_header *req_header, + } + if (entry_size + rsp_head.cur_blk_entry_cnt > max_hw_entry_size) { + HIKP_ERROR_PRINT("The sum of entry number (%u) after block-%u " +- "is over the maximum entry nubmer (%u) of unicast MAC table.\n", ++ "is over the maximum entry number (%u) of unicast MAC table.\n", + entry_size + rsp_head.cur_blk_entry_cnt, idx, max_hw_entry_size); + return -EINVAL; + } +@@ -597,7 +597,7 @@ static int hikp_nic_ppp_query_mc_mac_addr(struct hikp_cmd_header *req_header, + } + if (entry_size + rsp_head.cur_blk_entry_cnt > max_hw_entry_size) { + HIKP_ERROR_PRINT("The sum of entry number (%u) after block-%u " +- "is over the maximum entry nubmer (%u) of multicast MAC table.\n", ++ "is over the maximum entry number (%u) of multicast MAC table.\n", + entry_size + rsp_head.cur_blk_entry_cnt, idx, max_hw_entry_size); + return -EINVAL; + } +@@ -668,7 +668,7 @@ static int hikp_nic_ppp_query_vf_vlan_tbl(struct hikp_cmd_header *req_header, + } + if (entry_size + rsp_head.cur_blk_entry_cnt > hw_entry_size) { + HIKP_ERROR_PRINT("The sum of entry number (%u) after block-%u " +- "is over the maximum entry nubmer (%u) of VF VLAN table.\n", ++ "is over the maximum entry number (%u) of VF VLAN table.\n", + entry_size + rsp_head.cur_blk_entry_cnt, idx, hw_entry_size); + return -EINVAL; + } +@@ -709,7 +709,7 @@ static int hikp_nic_ppp_query_port_vlan_tbl(struct hikp_cmd_header *req_header, + } + if (entry_size + rsp_head.cur_blk_entry_cnt > hw_entry_size) { + HIKP_ERROR_PRINT("The sum of entry number (%u) after block-%u " +- "is over the maximum entry nubmer (%u) of port VLAN table.\n", ++ "is over the maximum entry number (%u) of port VLAN table.\n", + entry_size + rsp_head.cur_blk_entry_cnt, idx, hw_entry_size); + return -EINVAL; + } +@@ -771,7 +771,7 @@ static int hikp_nic_query_mng_tbl(struct hikp_cmd_header *req_header, + } + if (entry_size + rsp_head.cur_blk_entry_cnt > g_ppp_hw_res.mng_tbl_size) { + HIKP_ERROR_PRINT("The sum of entry number (%u) after block-%u " +- "is over the maximum entry nubmer (%u) of manager table.\n", ++ "is over the maximum entry number (%u) of manager table.\n", + entry_size + rsp_head.cur_blk_entry_cnt, idx, g_ppp_hw_res.mng_tbl_size); + return -EINVAL; + } +diff --git a/net/nic/nic_ppp/hikp_nic_ppp.h b/net/nic/nic_ppp/hikp_nic_ppp.h +index 229e019..e2ee79b 100644 +--- a/net/nic/nic_ppp/hikp_nic_ppp.h ++++ b/net/nic/nic_ppp/hikp_nic_ppp.h +@@ -40,7 +40,7 @@ struct hikp_nic_ppp_hw_resources { + uint32_t rsv1[10]; + }; + +-/* struct mac_vlan_uc_entry::e_vport field defination: ++/* struct mac_vlan_uc_entry::e_vport field definition: + * bit[0-2]: pf_id + * bit[3-10]: vf_id + */ +@@ -148,7 +148,7 @@ struct nic_mng_tbl { + struct func_vlan_offload_cfg { + uint16_t vlan_fe; + uint16_t pvid; +- uint8_t port_vlan_bypass; /* 0: off, 1: on, 2: unsupport port vlan */ ++ uint8_t port_vlan_bypass; /* 0: off, 1: on, 2: unsupported port vlan */ + uint8_t accept_tag1; + uint8_t accept_tag2; + uint8_t accept_untag1; +diff --git a/net/nic/nic_torus/hikp_nic_torus.c b/net/nic/nic_torus/hikp_nic_torus.c +index 7ad5211..ef8454f 100644 +--- a/net/nic/nic_torus/hikp_nic_torus.c ++++ b/net/nic/nic_torus/hikp_nic_torus.c +@@ -123,7 +123,7 @@ static void hikp_nic_torus_show(const struct nic_torus_info *info) + 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"); ++ printf("ets_tcg0_mapping is showed as 0xff if ncl_config forward bit is set to 1\n"); + + hikp_nic_torus_switch_param_show(info); + +diff --git a/net/roce/roce_ext_common/hikp_roce_ext_common.c b/net/roce/roce_ext_common/hikp_roce_ext_common.c +index ac6c8fb..102a0dc 100644 +--- a/net/roce/roce_ext_common/hikp_roce_ext_common.c ++++ b/net/roce/roce_ext_common/hikp_roce_ext_common.c +@@ -83,6 +83,100 @@ static int get_cmd_reg_array_length(enum roce_cmd_type cmd_type) + return idx; + } + ++static int fill_output(struct hikp_cmd_ret *cmd_ret, ++ const char *cmd_name, ++ uint32_t block_id, ++ struct roce_ext_res_output *output) ++{ ++ struct roce_ext_res_param *roce_ext_res = (struct roce_ext_res_param *)cmd_ret->rsp_data; ++ struct roce_ext_head *res_head = &output->res_head; ++ struct reg_data *reg = &output->reg; ++ ++ res_head->cur_block_num = roce_ext_res->head.cur_block_num; ++ ++ if (block_id != 0) ++ return 0; ++ ++ res_head->total_block_num = roce_ext_res->head.total_block_num; ++ res_head->flags = roce_ext_res->head.flags; ++ if (!res_head->total_block_num) { ++ printf("hikptool roce_%s total_block_num error!\n", cmd_name); ++ return -EINVAL; ++ } ++ ++ size_t per_val_size = res_head->flags & ROCE_HIKP_DATA_U64_FLAG ? ++ sizeof(uint64_t) : sizeof(uint32_t); ++ reg->offset = (uint32_t *)calloc(res_head->total_block_num, sizeof(uint32_t)); ++ output->per_val_size = per_val_size; ++ reg->data = calloc(res_head->total_block_num, per_val_size); ++ if (!reg->offset || !reg->data) { ++ printf("hikptool roce_%s alloc log memory failed!\n", cmd_name); ++ hikp_roce_ext_reg_data_free(reg); ++ return -ENOMEM; ++ } ++ ++ return 0; ++} ++ ++static int validate_block_numbers(const struct roce_ext_head *res_head, ++ const char *cmd_name, ++ uint32_t block_id) ++{ ++ uint32_t remain_block = res_head->total_block_num - block_id; ++ ++ if (!res_head->cur_block_num || res_head->cur_block_num > remain_block) { ++ printf("hikptool roce_%s block size error, cur: %u, total: %u, remain: %u.\n", ++ cmd_name, res_head->cur_block_num, ++ res_head->total_block_num, remain_block); ++ return -EINVAL; ++ } ++ ++ return 0; ++} ++ ++static int copy_data_from_response(struct hikp_cmd_ret *cmd_ret, ++ struct roce_ext_res_output *output, ++ int reg_array_length, ++ const char *cmd_name, ++ uint32_t block_id) ++{ ++ struct roce_ext_res_param *roce_ext_res = (struct roce_ext_res_param *)cmd_ret->rsp_data; ++ struct roce_ext_head *res_head = &output->res_head; ++ struct reg_data *reg = &output->reg; ++ size_t reg_data_offset; ++ size_t offset_size; ++ size_t data_size; ++ void *dst_data; ++ ++ /* ++ * The data structure `roce_ext_res_param_u64` returned by the ++ * firmware is 8-byte aligned, so the offset of the `reg_data` ++ * member needs to be adjusted accordingly. ++ */ ++ if (res_head->flags & ROCE_HIKP_DATA_U64_FLAG) ++ reg_data_offset = offsetof(struct roce_ext_res_param_u64, reg_data); ++ else ++ reg_data_offset = offsetof(struct roce_ext_res_param, reg_data); ++ ++ offset_size = res_head->cur_block_num * sizeof(uint32_t); ++ data_size = res_head->cur_block_num * output->per_val_size; ++ dst_data = reg->data_u32 + block_id * output->per_val_size / sizeof(uint32_t); ++ if ((reg_data_offset + data_size) / sizeof(uint32_t) + (size_t)reg_array_length > cmd_ret->rsp_data_num) { ++ printf("hikptool roce_%s cur size error, data_size: %zu, rsp_data_num: %u.\n", ++ cmd_name, data_size, cmd_ret->rsp_data_num); ++ return -EINVAL; ++ } ++ ++ memcpy(reg->offset + block_id, ++ (uint32_t *)&roce_ext_res->head + reg_data_offset / sizeof(uint32_t), ++ offset_size); ++ ++ memcpy(dst_data, (uint32_t *)&roce_ext_res->head + reg_data_offset / sizeof(uint32_t) + reg_array_length, ++ data_size); ++ ++ return 0; ++} ++ + static int hikp_roce_ext_get_res(enum roce_cmd_type cmd_type, + uint32_t block_id, + struct roce_ext_res_output *output, +@@ -94,14 +188,8 @@ static int hikp_roce_ext_get_res(enum roce_cmd_type cmd_type, + struct roce_ext_reg_name *reg_name = &output->reg_name; + struct roce_ext_head *res_head = &output->res_head; + const char *cmd_name = get_cmd_name(cmd_type); +- struct roce_ext_res_param *roce_ext_res; + struct reg_data *reg = &output->reg; + struct hikp_cmd_ret *cmd_ret; +- size_t reg_data_offset; +- uint32_t remain_block; +- size_t offset_size; +- size_t data_size; +- void *dst_data; + int ret; + + /* reg_array_length greater than or equal to 0 ensures that cmd_name +@@ -116,67 +204,19 @@ static int hikp_roce_ext_get_res(enum roce_cmd_type cmd_type, + goto get_data_error; + } + +- roce_ext_res = (struct roce_ext_res_param *)cmd_ret->rsp_data; +- res_head->cur_block_num = roce_ext_res->head.cur_block_num; +- +- if (block_id == 0) { +- res_head->total_block_num = roce_ext_res->head.total_block_num; +- res_head->flags = roce_ext_res->head.flags; +- if (!res_head->total_block_num) { +- printf("hikptool roce_%s total_block_num error!\n", +- cmd_name); +- ret = -EINVAL; +- goto get_data_error; +- } +- reg->offset = (uint32_t *)calloc(res_head->total_block_num, sizeof(uint32_t)); +- output->per_val_size = res_head->flags & ROCE_HIKP_DATA_U64_FLAG ? +- sizeof(uint64_t) : sizeof(uint32_t); +- reg->data = calloc(res_head->total_block_num, output->per_val_size); +- if ((reg->offset == NULL) || (reg->data == NULL)) { +- printf("hikptool roce_%s alloc log memmory failed!\n", +- cmd_name); +- ret = -ENOMEM; +- hikp_roce_ext_reg_data_free(reg); +- goto get_data_error; +- } +- } ++ ret = fill_output(cmd_ret, cmd_name, block_id, output); ++ if (ret) ++ goto get_data_error; + +- remain_block = res_head->total_block_num - block_id; +- if (!res_head->cur_block_num || res_head->cur_block_num > remain_block) { +- printf("hikptool roce_%s block size error, cur: %u, total: %u, remain: %u.\n", +- cmd_name, res_head->cur_block_num, +- res_head->total_block_num, remain_block); +- ret = -EINVAL; ++ ret = validate_block_numbers(res_head, cmd_name, block_id); ++ if (ret) { + hikp_roce_ext_reg_data_free(reg); + goto get_data_error; + } + +- /* +- * The data structure `roce_ext_res_param_u64` returned by the +- * firmware is 8-byte aligned, so the offset of the `reg_data` +- * member needs to be adjusted accordingly. +- */ +- if (res_head->flags & ROCE_HIKP_DATA_U64_FLAG) +- reg_data_offset = offsetof(struct roce_ext_res_param_u64, reg_data); +- else +- reg_data_offset = offsetof(struct roce_ext_res_param, reg_data); +- +- offset_size = res_head->cur_block_num * sizeof(uint32_t); +- data_size = res_head->cur_block_num * output->per_val_size; +- dst_data = reg->data_u32 + block_id * output->per_val_size / sizeof(uint32_t); +- /* Avoid memcpy out-of-bounds. */ +- if ((reg_data_offset + data_size) / sizeof(uint32_t) + reg_array_length > cmd_ret->rsp_data_num) { +- printf("hikptool roce_%s cur size error, data_size: %zu, rsp_data_num: %u.\n", +- cmd_name, data_size, cmd_ret->rsp_data_num); +- ret = -EINVAL; ++ ret = copy_data_from_response(cmd_ret, output, reg_array_length, cmd_name, block_id); ++ if (ret) + hikp_roce_ext_reg_data_free(reg); +- goto get_data_error; +- } +- memcpy(reg->offset + block_id, +- (uint32_t *)&roce_ext_res->head + reg_data_offset / sizeof(uint32_t), +- offset_size); +- memcpy(dst_data, (uint32_t *)&roce_ext_res->head + reg_data_offset +- / sizeof(uint32_t) + reg_array_length, data_size); + + get_data_error: + hikp_cmd_free(&cmd_ret); +diff --git a/net/roce/roce_scc/hikp_roce_scc.c b/net/roce/roce_scc/hikp_roce_scc.c +index b03ba07..9440180 100644 +--- a/net/roce/roce_scc/hikp_roce_scc.c ++++ b/net/roce/roce_scc/hikp_roce_scc.c +@@ -187,7 +187,7 @@ static int hikp_roce_scc_get_total_data_num(struct roce_scc_head *res_head, + *offset = (uint32_t *)calloc(1, max_size); + *data = (uint32_t *)calloc(1, max_size); + if ((*offset == NULL) || (*data == NULL)) { +- printf("hikptool roce_scc alloc log memmory 0x%zx failed\n", max_size); ++ printf("hikptool roce_scc alloc log memory 0x%zx failed\n", max_size); + ret = -ENOMEM; + goto get_data_error; + } +diff --git a/net/roce/roce_scc/hikp_roce_scc.h b/net/roce/roce_scc/hikp_roce_scc.h +index 8e56146..f6f3ec4 100644 +--- a/net/roce/roce_scc/hikp_roce_scc.h ++++ b/net/roce/roce_scc/hikp_roce_scc.h +@@ -77,7 +77,6 @@ enum roce_scc_type { + HC3, + LDCP, + CFG, +- VERBOSE, + }; + + int hikp_roce_set_scc_bdf(char *nic_name); +diff --git a/net/roce/roce_trp/hikp_roce_trp.c b/net/roce/roce_trp/hikp_roce_trp.c +index 8b34409..2c52822 100644 +--- a/net/roce/roce_trp/hikp_roce_trp.c ++++ b/net/roce/roce_trp/hikp_roce_trp.c +@@ -185,7 +185,7 @@ static int hikp_roce_trp_get_total_data_num(struct roce_trp_head *res_head, + *offset = (uint32_t *)calloc(1, max_size); + *data = (uint32_t *)calloc(1, max_size); + if ((*offset == NULL) || (*data == NULL)) { +- printf("hikptool roce_trp alloc log memmory 0x%zx failed\n", max_size); ++ printf("hikptool roce_trp alloc log memory 0x%zx failed\n", max_size); + hikp_roce_trp_reg_data_free(offset, data); + ret = -ENOMEM; + goto get_data_error; +diff --git a/net/roh/hikp_roh_mac.c b/net/roh/hikp_roh_mac.c +index e16a3db..81334da 100644 +--- a/net/roh/hikp_roh_mac.c ++++ b/net/roh/hikp_roh_mac.c +@@ -162,16 +162,16 @@ static int hikp_roh_build_cam(struct major_cmd_ctrl *self, struct cam_table_entr + struct hikp_cmd_header req_header = { 0 }; + struct hikp_cmd_ret *cmd_ret = NULL; + int block_num; ++ int addition; + int reg_num; +- int addtion; + int index; + + reg_num = hikp_roh_get_cam_reg_num(self); + if (reg_num < 0) + return -EIO; + +- addtion = reg_num % RESPONSE_DATA_NUMBER_MAX ? 1 : 0; +- block_num = reg_num / RESPONSE_DATA_NUMBER_MAX + addtion; ++ addition = reg_num % RESPONSE_DATA_NUMBER_MAX ? 1 : 0; ++ block_num = reg_num / RESPONSE_DATA_NUMBER_MAX + addition; + + for (int i = 0; i < block_num; i++) { + req_data.bdf = g_roh_mac_param.target.bdf; +diff --git a/pcie/func_lib/pcie_func/pcie_reg_dump.c b/pcie/func_lib/pcie_func/pcie_reg_dump.c +index f7ec2b3..c38d0e5 100644 +--- a/pcie/func_lib/pcie_func/pcie_reg_dump.c ++++ b/pcie/func_lib/pcie_func/pcie_reg_dump.c +@@ -417,8 +417,9 @@ static int pcie_create_dumpreg_log_file(uint32_t port_id, uint32_t dump_level) + static void pcie_close_dumpreg_log_file(void) + { + fclose(g_pcie_dumpreg_fd); +- /* Revoke write permission of file */ +- chmod(dumpreg_log_file, 0400); ++ /* Set the file permission to 0400 */ ++ if (chmod(dumpreg_log_file, 0400)) ++ Err("chmod %s failed, errno is %d\n", dumpreg_log_file, errno); + g_pcie_dumpreg_fd = NULL; + } + +diff --git a/pcie/func_lib/pcie_func/pcie_reg_read.c b/pcie/func_lib/pcie_func/pcie_reg_read.c +index c04c3d9..619f8e8 100644 +--- a/pcie/func_lib/pcie_func/pcie_reg_read.c ++++ b/pcie/func_lib/pcie_func/pcie_reg_read.c +@@ -70,7 +70,7 @@ static int pcie_reg_read_result_show(const struct hikp_cmd_ret *cmd_ret) + cmd_ret->rsp_data_num); + return -EINVAL; + } +- Info("RIGISTER VALUE[0x%08x].\n", cmd_ret->rsp_data[0]); ++ Info("REGISTER VALUE[0x%08x].\n", cmd_ret->rsp_data[0]); + + return 0; + } +diff --git a/pcie/usr_cmd/cmd_analysis/pcie_cmd_trace.c b/pcie/usr_cmd/cmd_analysis/pcie_cmd_trace.c +index 7b0efde..d89f223 100644 +--- a/pcie/usr_cmd/cmd_analysis/pcie_cmd_trace.c ++++ b/pcie/usr_cmd/cmd_analysis/pcie_cmd_trace.c +@@ -86,7 +86,7 @@ static int pcie_trace_mode_set(struct major_cmd_ctrl *self, const char *argv) + g_trace_cmd.cmd_type = TRACE_MODE; + ret = string_toui(argv, &val); + if (ret || val > 1) { +- printf("tarce mode set err %d\n", ret); ++ printf("trace mode set err %d\n", ret); + return -EINVAL; + } + g_trace_cmd.trace_mode_val = val; +diff --git a/sas/user_cmd/cmd_code/sas_cmd_anacq.c b/sas/user_cmd/cmd_code/sas_cmd_anacq.c +index bdaaa42..4d9a750 100644 +--- a/sas/user_cmd/cmd_code/sas_cmd_anacq.c ++++ b/sas/user_cmd/cmd_code/sas_cmd_anacq.c +@@ -27,8 +27,8 @@ static int sas_anacq_help(struct major_cmd_ctrl *self, const char *argv) + printf(" %s, %-25s %s\n", "-d", "--dieid", "please input die id[x] first\n"); + printf("\n Options:\n\n"); + printf(" %s, %-25s %s\n", "-h", "--help", "display this help and exit\n"); +- printf(" %s, %-25s %s\n", "-p", "--pointer", "dispaly cq queue read/write pointer\n"); +- printf(" %s, %-25s %s\n", "-s", "--number", "dispaly cq number\n"); ++ printf(" %s, %-25s %s\n", "-p", "--pointer", "display cq queue read/write pointer\n"); ++ printf(" %s, %-25s %s\n", "-s", "--number", "display cq number\n"); + printf("\n"); + + return 0; +diff --git a/sas/user_cmd/cmd_code/sas_cmd_anadq.c b/sas/user_cmd/cmd_code/sas_cmd_anadq.c +index bff2c71..176cfa3 100644 +--- a/sas/user_cmd/cmd_code/sas_cmd_anadq.c ++++ b/sas/user_cmd/cmd_code/sas_cmd_anadq.c +@@ -27,8 +27,8 @@ static int sas_anadq_help(struct major_cmd_ctrl *self, const char *argv) + printf(" %s, %-25s %s\n", "-d", "--dieid", "please input die id[x] first\n"); + printf("\n Options:\n\n"); + printf(" %s, %-25s %s\n", "-h", "--help", "display this help and exit\n"); +- printf(" %s, %-25s %s\n", "-p", "--pointer", "dispaly dq queue read/write pointer\n"); +- printf(" %s, %-25s %s\n", "-s", "--number", "dispaly dq number\n"); ++ printf(" %s, %-25s %s\n", "-p", "--pointer", "display dq queue read/write pointer\n"); ++ printf(" %s, %-25s %s\n", "-s", "--number", "display dq number\n"); + printf("\n"); + + return 0; +diff --git a/sas/user_cmd/cmd_code/sas_cmd_dev.c b/sas/user_cmd/cmd_code/sas_cmd_dev.c +index 879e764..06832ce 100644 +--- a/sas/user_cmd/cmd_code/sas_cmd_dev.c ++++ b/sas/user_cmd/cmd_code/sas_cmd_dev.c +@@ -27,7 +27,7 @@ static int sas_dev_help(struct major_cmd_ctrl *self, const char *argv) + printf(" %s, %-25s %s\n", "-d", "--dieid", "please input die id[x] first\n"); + printf("\n Options:\n\n"); + printf(" %s, %-25s %s\n", "-h", "--help", "display this help and exit\n"); +- printf(" %s, %-25s %s\n", "-l", "--link", "dispaly device type and speed\n"); ++ printf(" %s, %-25s %s\n", "-l", "--link", "display device type and speed\n"); + printf("\n"); + + return 0; +diff --git a/sas/user_cmd/cmd_code/sas_cmd_dqe.c b/sas/user_cmd/cmd_code/sas_cmd_dqe.c +index 5a85468..b914f54 100644 +--- a/sas/user_cmd/cmd_code/sas_cmd_dqe.c ++++ b/sas/user_cmd/cmd_code/sas_cmd_dqe.c +@@ -28,7 +28,7 @@ static int sas_dqe_help(struct major_cmd_ctrl *self, const char *argv) + printf(" %s, %-25s %s\n", "-q", "--queue", "please input queue id[x] first\n"); + printf("\n Options:\n\n"); + printf(" %s, %-25s %s\n", "-h", "--help", "display this help and exit\n"); +- printf(" %s, %-25s %s\n", "-i", "--info", "dispaly the dqe detail information\n"); ++ printf(" %s, %-25s %s\n", "-i", "--info", "display the dqe detail information\n"); + printf("\n"); + + return 0; +diff --git a/serdes/hikp_serdes.c b/serdes/hikp_serdes.c +index f07f1b6..39d46af 100644 +--- a/serdes/hikp_serdes.c ++++ b/serdes/hikp_serdes.c +@@ -130,7 +130,7 @@ static int cmd_serdes_key_info_pro(struct major_cmd_ctrl *self, const char *argv + + #define USEMODE_SSC_STR_MAXLEN 20 + static void hikp_serdes_brief_info_print(struct cmd_serdes_param *cmd, +- const struct hilink_brief_info *data, uint32_t data_size) ++ const struct hilink_brief_info *data) + { + uint8_t ds_id; + uint8_t start_sds_id = cmd->start_sds_id; +@@ -144,11 +144,6 @@ static void hikp_serdes_brief_info_print(struct cmd_serdes_param *cmd, + "nossc", "ssc", "mssc_in", "mssc_s", "mssc_n", "mssc_w", "mssc_e" + }; + +- if (data_size != sds_num) { +- printf("serdes brief info data size is wrong.\n"); +- return; +- } +- + for (ds_id = 0; ds_id < sds_num; ds_id++) { + if (data[ds_id].usemode >= HILINK_USE_MODE_END) { + printf("usemode[%u] is out of range.\n", data[ds_id].usemode); +@@ -204,17 +199,13 @@ static void hikp_serdes_brief_info_print(struct cmd_serdes_param *cmd, + "--------------------------------\n") + + static void hikp_serdes_detail_info_print(struct cmd_serdes_param *cmd, +- const struct hilink_detail_info *data, uint32_t data_size) ++ const struct hilink_detail_info *data) + { + uint32_t i; + uint8_t ds_id; + uint8_t start_sds_id = cmd->start_sds_id; + uint8_t sds_num = cmd->sds_num; + +- if (data_size != sds_num) { +- printf("serdes detail info data size is wrong.\n"); +- return; +- } + printf(KEY_INFO_TITLE); + for (ds_id = 0; ds_id < sds_num; ds_id++) { + printf("chip%u (M%u,ds%d) [%3d,%3d,%3u,%3d,%3d]", +@@ -341,13 +332,20 @@ static void hikp_serdes_info_print(struct cmd_serdes_param *cmd) + struct hilink_detail_info *detail_info_data = NULL; + + if (cmd->sub_cmd > 0) { ++ if (g_out_put.result_offset != cmd->sds_num * sizeof(struct hilink_detail_info)) { ++ printf("serdes detail info data size is wrong.\n"); ++ return; ++ } + detail_info_data = (struct hilink_detail_info *)g_out_put.out_str; +- hikp_serdes_detail_info_print(cmd, detail_info_data, +- g_out_put.result_offset / sizeof(struct hilink_detail_info)); ++ hikp_serdes_detail_info_print(cmd, detail_info_data); + } else { ++ if (g_out_put.result_offset != cmd->sds_num * sizeof(struct hilink_brief_info)) { ++ printf("serdes brief info data size is wrong.\n"); ++ return; ++ } ++ + brief_info_data = (struct hilink_brief_info *)g_out_put.out_str; +- hikp_serdes_brief_info_print(cmd, brief_info_data, +- g_out_put.result_offset / sizeof(struct hilink_brief_info)); ++ hikp_serdes_brief_info_print(cmd, brief_info_data); + } + } + +diff --git a/socip/hikp_socip_dumpreg.c b/socip/hikp_socip_dumpreg.c +index b3b3ed7..6d94f4a 100644 +--- a/socip/hikp_socip_dumpreg.c ++++ b/socip/hikp_socip_dumpreg.c +@@ -25,7 +25,7 @@ enum { + + struct dump_reg_param_t { + uint8_t val; +- bool is_vaild; ++ bool is_valid; + }; + + static const char *g_param_desc[SOCIP_DUMP_REG_PARAM_NUM] = { +@@ -65,7 +65,7 @@ static int get_param(struct major_cmd_ctrl *self, const char *argv, uint32_t ind + self->err_no = -EINVAL; + return -EINVAL; + } +- param->is_vaild = true; ++ param->is_valid = true; + + return 0; + } +@@ -97,7 +97,7 @@ static bool check_socip_dumpreg_param(void) + uint32_t i; + + for (i = 0; i < HIKP_ARRAY_SIZE(g_dump_reg_param); i++) { +- if (!param->is_vaild) { ++ if (!param->is_valid) { + ret = false; + HIKP_ERROR_PRINT("%s is not set\n", g_param_desc[i]); + } +diff --git a/tool_lib/tool_lib.c b/tool_lib/tool_lib.c +index 3dc5dad..559c558 100644 +--- a/tool_lib/tool_lib.c ++++ b/tool_lib/tool_lib.c +@@ -23,6 +23,7 @@ uint32_t get_chip_type(void) + uint32_t chip_type = CHIP_UNKNOW; + uint64_t midr_el1; + uint32_t part_num; ++ char *end = NULL; + FILE *file; + + file = fopen(MIDR_EL1_PATH, "r"); +@@ -38,7 +39,12 @@ uint32_t get_chip_type(void) + } + + fclose(file); +- midr_el1 = strtoul(midr_buffer, NULL, MIDR_HEX_TYPE); ++ midr_el1 = strtoul(midr_buffer, &end, MIDR_HEX_TYPE); ++ if ((end <= midr_buffer) || (midr_el1 == ULONG_MAX)) { ++ HIKP_ERROR_PRINT("Get chip type failed: %d\n", errno); ++ return chip_type; ++ } ++ + part_num = (midr_el1 & 0xffff) >> PART_NUM_OFFSET; + (void)snprintf(part_num_str, MIDR_BUFFER_SIZE, "%x", part_num); + +-- +2.25.1 + diff --git a/0109-hikptool-optimization-tool-help-information.patch b/0109-hikptool-optimization-tool-help-information.patch new file mode 100644 index 0000000000000000000000000000000000000000..9be43fd5b0d91957a4c6b07d9541d5c7af15cfec --- /dev/null +++ b/0109-hikptool-optimization-tool-help-information.patch @@ -0,0 +1,238 @@ +From c72ca6bfc60bca9543beb4f39328099cac094c15 Mon Sep 17 00:00:00 2001 +From: veega2022 +Date: Tue, 26 Aug 2025 19:29:41 +0800 +Subject: [PATCH 2/2] hikptool: optimization tool help information + +Based on the actual hardware platform, +display the supported commands; +if the current hardware does not support a command, +it will not be displayed, and the user will +be prompted with an error message if they input that command. + +Signed-off-by: veega2022 +--- + hikp_init_main.c | 148 +++++++++++++++++++++++++++++++++++++++++++- + tool_lib/tool_cmd.h | 5 ++ + tool_lib/tool_lib.c | 2 + + tool_lib/tool_lib.h | 1 + + 4 files changed, 154 insertions(+), 2 deletions(-) + +diff --git a/hikp_init_main.c b/hikp_init_main.c +index e159ad9..7b63e9b 100644 +--- a/hikp_init_main.c ++++ b/hikp_init_main.c +@@ -19,9 +19,149 @@ + /* hikptool command adapter */ + struct cmd_adapter g_tool = { 0 }; + ++static const char *g_cxl_cmd_list[] = { ++ "cxl_cpa", "cxl_dl", "cxl_membar", "cxl_rcrb", ++}; ++ ++static const char *g_hccs_cmd_list[] = { ++ "hccs", ++}; ++ ++static const char *g_log_collect_cmd_list[] = { ++ "info_collect", ++}; ++ ++static const char *g_nic_cmd_list[] = { ++ "nic_dfx", "nic_fd", "nic_fec", "nic_gro", "nic_info", ++ "nic_log", "nic_mac", "nic_ncsi", "nic_notify_pkt", "nic_port", ++ "nic_port_fault", "nic_ppp", "nic_qos", "nic_queue", "nic_rss", ++ "nic_torus", "nic_xsfp", ++}; ++ ++static const char *g_pcie_cmd_list[] = { ++ "pcie_dumpreg", "pcie_info", "pcie_regrd", "pcie_trace", ++}; ++ ++static const char *g_roce_cmd_list[] = { ++ "roce_bond", "roce_caep", "roce_dfx_sta", "roce_global_cfg", "roce_gmv", ++ "roce_mdb", "roce_pkt", "roce_qmm", "roce_rst", "roce_scc", ++ "roce_timer", "roce_trp", "roce_tsp", ++}; ++ ++static const char *g_roh_cmd_list[] = { ++ "roh_mac", "roh_show_bp", "roh_show_mib", ++}; ++ ++static const char *g_sas_cmd_list[] = { ++ "sas_anacq", "sas_anadq", "sas_dev", "sas_dqe", "sas_dump", "sas_errcode", ++}; ++ ++static const char *g_sata_cmd_list[] = { ++ "sata_dump", ++}; ++ ++static const char *g_serdes_cmd_list[] = { ++ "serdes_dump", "serdes_info", ++}; ++ ++static const char *g_socip_cmd_list[] = { ++ "socip_dumpreg", ++}; ++ ++static const char *g_core_ring_cmd_list[] = { ++ "cpu_ring", ++}; ++ ++static const char *g_sdma_cmd_list[] = { ++ "sdma_dump", ++}; ++ ++static const char *g_ub_cmd_list[] = { ++ "ub_bp", "ub_crd", "ub_dfx", "ub_info", "ub_link", "unic_ppp", ++}; ++ ++static const char *g_ras_cmd_list[] = { ++ "bbox_export", ++}; ++ ++const struct cmd_list_info g_chip_hip09_hip10_cmd_list[] = { ++ {g_cxl_cmd_list, HIKP_ARRAY_SIZE(g_cxl_cmd_list)}, ++ {g_hccs_cmd_list, HIKP_ARRAY_SIZE(g_hccs_cmd_list)}, ++ {g_log_collect_cmd_list, HIKP_ARRAY_SIZE(g_log_collect_cmd_list)}, ++ {g_nic_cmd_list, HIKP_ARRAY_SIZE(g_nic_cmd_list)}, ++ {g_pcie_cmd_list, HIKP_ARRAY_SIZE(g_pcie_cmd_list)}, ++ {g_roce_cmd_list, HIKP_ARRAY_SIZE(g_roce_cmd_list)}, ++ {g_roh_cmd_list, HIKP_ARRAY_SIZE(g_roh_cmd_list)}, ++ {g_sas_cmd_list, HIKP_ARRAY_SIZE(g_sas_cmd_list)}, ++ {g_sata_cmd_list, HIKP_ARRAY_SIZE(g_sata_cmd_list)}, ++ {g_serdes_cmd_list, HIKP_ARRAY_SIZE(g_serdes_cmd_list)}, ++ {g_socip_cmd_list, HIKP_ARRAY_SIZE(g_socip_cmd_list)}, ++}; ++ ++const struct cmd_list_info g_chip_hip11_cmd_list[] = { ++ {g_core_ring_cmd_list, HIKP_ARRAY_SIZE(g_core_ring_cmd_list)}, ++ {g_log_collect_cmd_list, HIKP_ARRAY_SIZE(g_log_collect_cmd_list)}, ++ {g_nic_cmd_list, HIKP_ARRAY_SIZE(g_nic_cmd_list)}, ++ {g_pcie_cmd_list, HIKP_ARRAY_SIZE(g_pcie_cmd_list)}, ++ {g_roce_cmd_list, HIKP_ARRAY_SIZE(g_roce_cmd_list)}, ++ {g_roh_cmd_list, HIKP_ARRAY_SIZE(g_roh_cmd_list)}, ++ {g_sata_cmd_list, HIKP_ARRAY_SIZE(g_sata_cmd_list)}, ++ {g_sdma_cmd_list, HIKP_ARRAY_SIZE(g_sdma_cmd_list)}, ++ {g_serdes_cmd_list, HIKP_ARRAY_SIZE(g_serdes_cmd_list)}, ++ {g_socip_cmd_list, HIKP_ARRAY_SIZE(g_socip_cmd_list)}, ++ {g_ub_cmd_list, HIKP_ARRAY_SIZE(g_ub_cmd_list)}, ++}; ++ ++const struct cmd_list_info g_chip_hip12_cmd_list[] = { ++ {g_ras_cmd_list, HIKP_ARRAY_SIZE(g_ras_cmd_list)}, ++ {g_hccs_cmd_list, HIKP_ARRAY_SIZE(g_hccs_cmd_list)}, ++ {g_log_collect_cmd_list, HIKP_ARRAY_SIZE(g_log_collect_cmd_list)}, ++ {g_pcie_cmd_list, HIKP_ARRAY_SIZE(g_pcie_cmd_list)}, ++ {g_serdes_cmd_list, HIKP_ARRAY_SIZE(g_serdes_cmd_list)}, ++ {g_socip_cmd_list, HIKP_ARRAY_SIZE(g_socip_cmd_list)}, ++}; ++ ++static bool cmd_is_support(const char *cmd_name, struct cmd_list_info *cmd_info, size_t len) ++{ ++ for (size_t i = 0; i < len; i++) ++ for (size_t j = 0; j < cmd_info[i].list_len; j++) ++ if (strcmp(cmd_info[i].cmd_list[j], cmd_name) == 0) ++ return true; ++ ++ return false; ++} ++ ++static bool check_cmd_is_support(const char *cmd_name) ++{ ++ uint32_t chip_type = get_chip_type(); ++ bool is_support = true; ++ ++ switch (chip_type) { ++ case CHIP_HIP09: ++ case CHIP_HIP10: ++ case CHIP_HIP10C: ++ is_support = cmd_is_support(cmd_name, g_chip_hip09_hip10_cmd_list, ++ HIKP_ARRAY_SIZE(g_chip_hip09_hip10_cmd_list)); ++ break; ++ case CHIP_HIP11: ++ is_support = cmd_is_support(cmd_name, g_chip_hip11_cmd_list, ++ HIKP_ARRAY_SIZE(g_chip_hip11_cmd_list)); ++ break; ++ case CHIP_HIP12: ++ is_support = cmd_is_support(cmd_name, g_chip_hip12_cmd_list, ++ HIKP_ARRAY_SIZE(g_chip_hip12_cmd_list)); ++ break; ++ default: ++ break; ++ } ++ ++ /* Unrecognized hardware type, default display supported */ ++ return is_support; ++} ++ + static void show_tool_version(const struct cmd_adapter *adapter) + { +- printf("%s version %s Huawei\n", adapter->name, adapter->version); ++ printf("%s version %s Huawei HW(%u)\n", adapter->name, adapter->version, get_chip_type()); + } + + static int cmp(const void *a, const void *b) +@@ -52,7 +192,8 @@ static void show_tool_help(const struct cmd_adapter *adapter) + qsort(start_cmd_ptr, end_cmd_ptr - start_cmd_ptr, + sizeof(struct hikp_cmd_type), (const void *)cmp); + for (cmd_ptr = start_cmd_ptr; cmd_ptr < end_cmd_ptr; cmd_ptr++) +- printf(" %-23s %s\n", cmd_ptr->name, cmd_ptr->help_info); ++ if (check_cmd_is_support(cmd_ptr->name)) ++ printf(" %-23s %s\n", cmd_ptr->name, cmd_ptr->help_info); + + printf("\n"); + } +@@ -92,6 +233,9 @@ static int parse_and_init_cmd(const char *arg) + if (strnlen(cmd_ptr->name, MAX_CMD_LEN) != strnlen(arg, MAX_CMD_LEN)) + continue; + ++ if (!check_cmd_is_support(cmd_ptr->name)) ++ continue; ++ + if ((strncmp(arg, cmd_ptr->name, + strnlen(cmd_ptr->name, MAX_CMD_LEN - 1) + 1) == 0) && cmd_ptr->cmd_init) { + g_tool.p_major_cmd.cmd_ptr = cmd_ptr; +diff --git a/tool_lib/tool_cmd.h b/tool_lib/tool_cmd.h +index 1aaaf22..87df2d7 100644 +--- a/tool_lib/tool_cmd.h ++++ b/tool_lib/tool_cmd.h +@@ -67,6 +67,11 @@ struct cmd_adapter { + struct major_cmd_ctrl p_major_cmd; + }; + ++struct cmd_list_info { ++ const char **cmd_list; ++ size_t list_len; ++}; ++ + extern int _s_cmd_data; + extern int _e_cmd_data; + extern struct cmd_adapter g_tool; +diff --git a/tool_lib/tool_lib.c b/tool_lib/tool_lib.c +index 559c558..f5facd5 100644 +--- a/tool_lib/tool_lib.c ++++ b/tool_lib/tool_lib.c +@@ -56,6 +56,8 @@ uint32_t get_chip_type(void) + chip_type = CHIP_HIP10C; + else if (strcmp(part_num_str, "d22") == 0) + chip_type = CHIP_HIP11; ++ else if (strcmp(part_num_str, "d06") == 0) ++ chip_type = CHIP_HIP12; + else + chip_type = CHIP_UNKNOW; + +diff --git a/tool_lib/tool_lib.h b/tool_lib/tool_lib.h +index d4accf1..b7b756c 100644 +--- a/tool_lib/tool_lib.h ++++ b/tool_lib/tool_lib.h +@@ -106,6 +106,7 @@ enum chip_type { + CHIP_HIP10, + CHIP_HIP10C, + CHIP_HIP11, ++ CHIP_HIP12, + CHIP_UNKNOW, + }; + +-- +2.45.0.windows.1 + diff --git a/hikptool.spec b/hikptool.spec index c955477117ac1043209e2edd0be0859e95209b52..beeb35eb0a58699e12546cecd7c776128139aa8a 100644 --- a/hikptool.spec +++ b/hikptool.spec @@ -3,7 +3,7 @@ Name: hikptool Summary: A userspace tool for Linux providing problem location on Kunpeng chips Version: 1.0.0 -Release: 22 +Release: 23 License: MulanPSL2 Source: %{name}-%{version}.tar.gz ExclusiveOS: linux @@ -123,6 +123,8 @@ Patch0104: 0104-hikptool-roce-Add-roce_dfx_sta-cmd-for-RoCE-DFX-stat.patch Patch0105: 0105-hikptool-Fix-ASAN-compilation-warnings.patch Patch0106: 0106-hikptool-Add-serdes-module-submodule-dump-types.patch Patch0107: 0107-hikptool-Optimize-the-ROCE-SCC-module-register-dump-.patch +Patch0108: 0108-hikptool-solve-some-code-review-comments.patch +Patch0109: 0109-hikptool-optimization-tool-help-information.patch %description This package contains the hikptool @@ -175,6 +177,9 @@ fi /sbin/ldconfig %changelog +* Thu Aug 28 2025 veega2022 1.0.0-23 +- Optimize help information and modify code review comments + * Mon Jul 28 2025 veega2022 1.0.0-22 - Optimize the ROCE SCC module register dump display