hikptool/0018-Complete-the-developing-of-hikptool-ub_link-function.patch

183 lines
5.7 KiB
Diff
Raw Permalink Normal View History

From a9a370cf2127f8317759ef3d963c4c7db89c499c Mon Sep 17 00:00:00 2001
From: veega2022 <zhuweijia@huawei.com>
Date: Thu, 11 May 2023 08:56:30 +0800
Subject: [PATCH 09/15] Complete the developing of hikptool ub_link function
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 */
--
2.36.1.windows.1