From a3c26afe52f585fa2d427f0cd8451a41f5861031 Mon Sep 17 00:00:00 2001 From: w00808059 Date: Wed, 31 Dec 2025 10:36:42 +0800 Subject: [PATCH 1/2] urma: add set eid ns. --- src/urma/lib/urma/core/include/urma_cmd.h | 1 + src/urma/tools/urma_admin/admin_cmd_eid.c | 34 ++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/urma/lib/urma/core/include/urma_cmd.h b/src/urma/lib/urma/core/include/urma_cmd.h index 5dda3e6..0f3db31 100644 --- a/src/urma/lib/urma/core/include/urma_cmd.h +++ b/src/urma/lib/urma/core/include/urma_cmd.h @@ -42,6 +42,7 @@ typedef enum urma_core_cmd { URMA_CORE_SET_DEV_SHARING_MODE, URMA_CORE_EXPOSE_DEV_NS, URMA_CORE_UNEXPOSE_DEV_NS, + URMA_CORE_SET_DEV_EID_NS, URMA_CORE_GET_TOPO_INFO, } urma_core_cmd_t; diff --git a/src/urma/tools/urma_admin/admin_cmd_eid.c b/src/urma/tools/urma_admin/admin_cmd_eid.c index 088c8ab..ef3df23 100644 --- a/src/urma/tools/urma_admin/admin_cmd_eid.c +++ b/src/urma/tools/urma_admin/admin_cmd_eid.c @@ -62,7 +62,39 @@ static int cmd_eid_set_mode(admin_config_t *cfg) static int cmd_eid_set_ns(admin_config_t *cfg) { printf("TODO set eid ns %s %u\n", cfg->dev_name, cfg->idx); - return 0; + + int ret; + if ((ret = pop_arg_ns(cfg)) != 0) { + return ret; + } + + int ns_fd = admin_get_ns_fd(cfg->ns); + if (ns_fd < 0) { + (void)printf("Failed to get ns fd, ns %s.\n", cfg->ns); + return ns_fd; + } + + struct nl_msg *msg = admin_nl_alloc_msg(URMA_CORE_SET_DEV_EID_NS, 0); + if (msg == NULL) { + ret = -ENOMEM; + goto close_ns_fd; + } + + admin_core_cmd_update_eid_t arg = {0}; + (void)memcpy(arg.in.dev_name, cfg->dev_name, URMA_ADMIN_MAX_DEV_NAME); + arg.in.eid_index = cfg->idx; + arg.in.ns_fd = ns_fd; + + admin_nl_put_string(msg, UBCORE_ATTR_DEV_NAME, cfg->dev_name); + admin_nl_put_u32(msg, UBCORE_ATTR_NS_FD, ns_fd); + admin_nl_put_u32(msg, UBCORE_HDR_ARGS_LEN, sizeof(admin_core_cmd_update_eid_t)); + admin_nl_put_u64(msg, UBCORE_HDR_ARGS_ADDR, (uint64_t)&arg); + ret = admin_nl_send_recv_msg_default(msg); + admin_nl_free_msg(msg); + +close_ns_fd: + (void)close(ns_fd); + return ret; } static int cmd_eid_set(admin_config_t *cfg) -- Gitee From 91beaeadec34cecc696a5ee42085c9ace7e7032f Mon Sep 17 00:00:00 2001 From: w00808059 Date: Wed, 31 Dec 2025 11:46:23 +0800 Subject: [PATCH 2/2] test: add adapat lcne. Please enter the commit message for your changes. Lines starting --- src/urma/lib/uvs/core/tpsa_api.c | 144 ++++++++++++++++++++++++++++++- 1 file changed, 142 insertions(+), 2 deletions(-) diff --git a/src/urma/lib/uvs/core/tpsa_api.c b/src/urma/lib/uvs/core/tpsa_api.c index 51fef12..641f507 100644 --- a/src/urma/lib/uvs/core/tpsa_api.c +++ b/src/urma/lib/uvs/core/tpsa_api.c @@ -18,6 +18,141 @@ #define UVS_MAX_TOPO_NUM 16 +#define EID_FMT "%2.2x%2.2x:%2.2x%2.2x:%2.2x%2.2x:%2.2x%2.2x:%2.2x%2.2x:%2.2x%2.2x:%2.2x%2.2x:%2.2x%2.2x" +#define EID_RAW_ARGS(eid) \ + eid[0], eid[1], eid[2], eid[3], eid[4], eid[5], eid[6], eid[7], eid[8], eid[9], eid[10], eid[11], eid[12], \ + eid[13], eid[14], eid[15] +#define EID_ARGS(eid) EID_RAW_ARGS((eid).raw) +#define EID_LEN (16) +#define MAX_PORT_NUM (9) +#define MAX_ALL_PORT_NUM (18) +#define MAX_NODE_NUM (16) +#define MAX_IODIE_NUM (2) +#define MAX_DEV_NUM (1) + +struct io_die_info { + int socket_id; + char primary_eid[EID_LEN]; + char port_eid[MAX_PORT_NUM][EID_LEN]; +}; + +/* Locate a specific port in topo_infos */ +/* All params set to -1 means doesn't exist */ +struct topo_map_idx { + int topo_info_idx; + int plane_idx; + int port_idx; +}; + +struct topo_dev_info { + char bonding_eid[EID_LEN]; + struct io_die_info io_die_info[MAX_IODIE_NUM]; +}; + +struct topo_info { + int id; + bool is_cur_node; + struct topo_map_idx links[MAX_IODIE_NUM][MAX_PORT_NUM]; + struct topo_dev_info dev[MAX_DEV_NUM]; +}; + +typedef struct topo_info topo_info_t; + +/* 兼容LCNE原有下发格式 */ +typedef struct old_tool_iodie_info { + char primary_eid[EID_LEN]; + char port_eid[MAX_PORT_NUM][EID_LEN]; + char peer_port_eid[MAX_PORT_NUM][EID_LEN]; + int socket_id; +} old_tool_iodie_info_t; + +typedef struct old_tool_topo_info { + char bonding_eid[EID_LEN]; + old_tool_iodie_info_t io_die_info[MAX_IODIE_NUM]; + bool is_cur_node; +} old_tool_topo_info_t; + +typedef struct old_tool_topo_map { + old_tool_topo_info_t topo_infos[MAX_NODE_NUM]; + uint32_t node_num; +} old_tool_topo_map_t; + +static inline bool is_uvs_eid_equal(uvs_eid_t *eid1, uvs_eid_t *eid2) +{ + return !memcmp(eid1, eid2, sizeof(uvs_eid_t)); +} + +static bool is_eid_valid(const char *eid) +{ + int i; + + for (i = 0; i < EID_LEN; i++) { + if (eid[i] != 0) { + return true; + } + } + return false; +} + +static struct topo_map_idx get_topo_map_idx_by_port_eid(old_tool_topo_info_t *topo_infos, uint32_t node_num, uvs_eid_t *port_eid) +{ + struct topo_map_idx idx = { + .topo_info_idx = -1, + .plane_idx = -1, + .port_idx = -1, + }; + if (is_eid_valid((char *)port_eid) == false) { + return idx; + } + for (int i = 0; i < node_num; ++i) { + old_tool_topo_info_t *topo_info = &topo_infos[i]; + for (int k = 0; k < MAX_IODIE_NUM; ++k) { + old_tool_iodie_info_t *die_info = &topo_info->io_die_info[k]; + for (int l = 0; l < MAX_PORT_NUM; ++l) { + if (is_uvs_eid_equal((uvs_eid_t *)die_info->port_eid[l], port_eid)) { + idx.topo_info_idx = i; + idx.plane_idx = k; + idx.port_idx = l; + return idx; + } + } + } + } + return idx; +} + +static int trans_old_topo(topo_info_t *new_top_info, old_tool_topo_info_t *old_topo_info, uint32_t topo_num) +{ + TPSA_LOG_ERR("Translating old topology map to new topology map, and node_num is %u\n", topo_num); + + for (int i = 0; i < (int)topo_num; ++i) { + topo_info_t *topo_info = &new_top_info[i]; + old_tool_topo_info_t *old_info = &old_topo_info[i]; + topo_info->id = i; + topo_info->is_cur_node = old_info->is_cur_node; + // 每个node只取一个dev + struct topo_dev_info *dev_info = &topo_info->dev[0]; + memcpy(dev_info->bonding_eid, old_info->bonding_eid, EID_LEN); + for (int j = 0; j < MAX_IODIE_NUM; ++j) { + struct io_die_info *die_info = &dev_info->io_die_info[j]; + die_info->socket_id = old_info->io_die_info[j].socket_id; + memcpy(die_info->primary_eid, old_info->io_die_info[j].primary_eid, EID_LEN); + for (int k = 0; k < MAX_PORT_NUM; ++k) { + memcpy(die_info->port_eid[k], old_info->io_die_info[j].port_eid[k], EID_LEN); + TPSA_LOG_ERR("****port_eid:"EID_FMT" with peer_port eid: "EID_FMT"\n", + EID_ARGS(*(uvs_eid_t *)old_info->io_die_info[j].port_eid[k]), + EID_ARGS(*(uvs_eid_t *)old_info->io_die_info[j].peer_port_eid[k])); + struct topo_map_idx idx = get_topo_map_idx_by_port_eid(old_topo_info, topo_num, (uvs_eid_t *)old_info->io_die_info[j].peer_port_eid[k]); + topo_info->links[j][k].topo_info_idx = idx.topo_info_idx; + topo_info->links[j][k].plane_idx = idx.plane_idx; + topo_info->links[j][k].port_idx = idx.port_idx; + } + } + } + + return 0; +} + int uvs_set_topo_info_inner(void *topo, uint32_t topo_num) { int ret; @@ -27,7 +162,11 @@ int uvs_set_topo_info_inner(void *topo, uint32_t topo_num) return -EINVAL; } - ret = uvs_ubagg_ioctl_set_topo(topo, topo_num); + /* 兼容LCNE旧有格式 */ + topo_info_t new_topo_infos[MAX_NODE_NUM]; + memset(new_topo_infos, 0, sizeof(topo_info_t) * MAX_NODE_NUM); + trans_old_topo(new_topo_infos, (old_tool_topo_info_t *)topo, topo_num); + ret = uvs_ubagg_ioctl_set_topo((void *)new_topo_infos, topo_num); if (ret != 0) { TPSA_LOG_ERR("failed to set topo info in ubagg.\n"); return ret; @@ -35,7 +174,8 @@ int uvs_set_topo_info_inner(void *topo, uint32_t topo_num) TPSA_LOG_INFO("success to set topo info in ubagg\n"); } - ret = uvs_ubcore_ioctl_set_topo(topo, topo_num); + TPSA_LOG_INFO("User space args size:%lu.\n", sizeof(topo_info_t) * topo_num); + ret = uvs_ubcore_ioctl_set_topo((void *)new_topo_infos, topo_num); if (ret != 0) { TPSA_LOG_ERR("failed to set topo info in ubcore.\n"); } else { -- Gitee