From 8dafd3c2cd0bfbbb93b022b7fd17aa7093b1ef18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=97=AD=E8=88=92=E7=A3=8A?= <892114948@qq.com> Date: Thu, 18 Dec 2025 16:03:45 +0800 Subject: [PATCH] urma: add supporting for creating and deleting aggregation devices, and for retrieving device name by eid. --- src/urma/lib/uvs/core/include/uvs_api.h | 23 +++++++ src/urma/lib/uvs/core/tpsa_api.c | 44 ++++++++++++ src/urma/lib/uvs/core/uvs_ubagg_ioctl.c | 91 ++++++++++++++++++++++++- src/urma/lib/uvs/core/uvs_ubagg_ioctl.h | 29 +++++++- 4 files changed, 185 insertions(+), 2 deletions(-) diff --git a/src/urma/lib/uvs/core/include/uvs_api.h b/src/urma/lib/uvs/core/include/uvs_api.h index 2021807..5ce4d28 100644 --- a/src/urma/lib/uvs/core/include/uvs_api.h +++ b/src/urma/lib/uvs/core/include/uvs_api.h @@ -42,6 +42,29 @@ typedef struct uvs_route_list { uvs_route_t buf[UVS_MAX_ROUTES]; } uvs_route_list_t; +/** + * Create an aggregation device in UVS. + * @param[in] aggr_eid EID of the aggregation device to be created. + * @return 0 on success, other value on error. + */ +int uvs_create_aggr_dev(uvs_eid_t aggr_eid); + +/** + * Delete an aggregation device from UVS. + * @param[in] aggr_eid EID of the aggregation device to be deleted. + * @return 0 on success, other value on error. + */ +int uvs_delete_aggr_dev(uvs_eid_t aggr_eid); + +/** + * Get device name by EID. + * @param[in] eid EID of the device. + * @param[out] buf Buffer to hold the device name. + * @param[in] len Length of the buffer. + * @return 0 on success, other value on error. + */ +int uvs_get_dev_name_by_eid(uvs_eid_t eid, void *buf, uint32_t len); + /** * UVS set topo info which gets from MXE module. * @param[in] topo: topo info of one bonding device diff --git a/src/urma/lib/uvs/core/tpsa_api.c b/src/urma/lib/uvs/core/tpsa_api.c index 51fef12..c23f630 100644 --- a/src/urma/lib/uvs/core/tpsa_api.c +++ b/src/urma/lib/uvs/core/tpsa_api.c @@ -18,6 +18,50 @@ #define UVS_MAX_TOPO_NUM 16 +int uvs_create_aggr_dev(uvs_eid_t aggr_eid) +{ + int ret = 0; + + ret = uvs_ubagg_ioctl_create_aggr_dev(aggr_eid); + if (ret != 0) { + TPSA_LOG_ERR("failed to create aggr dev in ubagg.\n"); + return ret; + } + + return ret; +} + +int uvs_delete_aggr_dev(uvs_eid_t aggr_eid) +{ + int ret = 0; + + ret = uvs_ubagg_ioctl_delete_aggr_dev(aggr_eid); + if (ret != 0) { + TPSA_LOG_ERR("failed to delete aggr dev in ubagg.\n"); + return ret; + } + + return ret; +} + +int uvs_get_dev_name_by_eid(uvs_eid_t eid, void *buf, uint32_t len) +{ + int ret = 0; + + if (buf == NULL || len == 0) { + TPSA_LOG_ERR("Invalid parameter.\n"); + return -EINVAL; + } + + ret = uvs_ubagg_ioctl_get_dev_name_by_eid(eid, buf, len); + if (ret != 0) { + TPSA_LOG_ERR("failed to get dev name by eid in ubagg.\n"); + return ret; + } + + return 0; +} + int uvs_set_topo_info_inner(void *topo, uint32_t topo_num) { int ret; diff --git a/src/urma/lib/uvs/core/uvs_ubagg_ioctl.c b/src/urma/lib/uvs/core/uvs_ubagg_ioctl.c index cceb391..9d37660 100644 --- a/src/urma/lib/uvs/core/uvs_ubagg_ioctl.c +++ b/src/urma/lib/uvs/core/uvs_ubagg_ioctl.c @@ -20,6 +20,95 @@ #define UVS_UBAGG_DEVICE_PATH "/dev/ubagg" #define UVS_UBCORE_DEVICE_PATH "/dev/ubcore/ubcore" +int uvs_ubagg_ioctl_create_aggr_dev(uvs_eid_t aggr_eid) +{ + struct uvs_ubagg_create_dev_arg args = {0}; + struct uvs_ubagg_cmd_hdr hdr = {0}; + int ret; + + args.in.aggr_eid = aggr_eid; + + hdr.command = UVS_UBAGG_CMD_CREATE_DEV; + hdr.args_addr = (uint64_t)(uintptr_t)&args; + hdr.args_len = sizeof(args); + + int dev_fd = open(UVS_UBAGG_DEVICE_PATH, O_RDWR); + if (dev_fd < 0) { + TPSA_LOG_ERR("Failed to open dev_fd err: %s.\n", ub_strerror(errno)); + return -1; + } + + ret = ioctl(dev_fd, UVS_UBAGG_CMD, &hdr); + if (ret != 0) { + TPSA_LOG_ERR("ioctl to create aggr dev fail\n"); + close(dev_fd); + return -1; + } + + close(dev_fd); + return 0; +} + +int uvs_ubagg_ioctl_delete_aggr_dev(uvs_eid_t aggr_eid) +{ + struct uvs_ubagg_delete_dev_arg args = {0}; + struct uvs_ubagg_cmd_hdr hdr = {0}; + int ret; + + args.in.aggr_eid = aggr_eid; + + hdr.command = UVS_UBAGG_CMD_DELETE_DEV; + hdr.args_addr = (uint64_t)(uintptr_t)&args; + hdr.args_len = sizeof(args); + + int dev_fd = open(UVS_UBAGG_DEVICE_PATH, O_RDWR); + if (dev_fd < 0) { + TPSA_LOG_ERR("Failed to open dev_fd err: %s.\n", ub_strerror(errno)); + return -1; + } + + ret = ioctl(dev_fd, UVS_UBAGG_CMD, &hdr); + if (ret != 0) { + TPSA_LOG_ERR("ioctl to remove aggr dev fail\n"); + close(dev_fd); + return -1; + } + + close(dev_fd); + return 0; +} + +int uvs_ubagg_ioctl_get_dev_name_by_eid(uvs_eid_t eid, void *buf, uint32_t len) +{ + struct uvs_ubagg_get_dev_name_arg args = {0}; + struct uvs_ubagg_cmd_hdr hdr = {0}; + int ret; + + args.in.eid = eid; + args.in.buf = buf; + args.in.len = len; + + hdr.command = UVS_UBAGG_CMD_GET_DEV_NAME; + hdr.args_addr = (uint64_t)(uintptr_t)&args; + hdr.args_len = sizeof(args); + + int dev_fd = open(UVS_UBAGG_DEVICE_PATH, O_RDWR); + if (dev_fd < 0) { + TPSA_LOG_ERR("Failed to open dev_fd err: %s.\n", ub_strerror(errno)); + return -1; + } + + ret = ioctl(dev_fd, UVS_UBAGG_CMD, &hdr); + if (ret != 0) { + TPSA_LOG_ERR("ioctl to get dev name by eid fail\n"); + close(dev_fd); + return -1; + } + + close(dev_fd); + return 0; +} + int uvs_ubagg_ioctl_set_topo(void *topo_info, int topo_num) { struct uvs_ubagg_set_topo_info args = {0}; @@ -29,7 +118,7 @@ int uvs_ubagg_ioctl_set_topo(void *topo_info, int topo_num) args.in.topo = topo_info; args.in.topo_num = (uint32_t)topo_num; - hdr.command = UVS_UBAGG_CMD_SET_TOPO; + hdr.command = UVS_UBAGG_CMD_SET_TOPO_INFO; hdr.args_addr = (uint64_t)(uintptr_t)&args; hdr.args_len = sizeof(args); diff --git a/src/urma/lib/uvs/core/uvs_ubagg_ioctl.h b/src/urma/lib/uvs/core/uvs_ubagg_ioctl.h index d36df30..8306331 100644 --- a/src/urma/lib/uvs/core/uvs_ubagg_ioctl.h +++ b/src/urma/lib/uvs/core/uvs_ubagg_ioctl.h @@ -10,11 +10,15 @@ #ifndef UVS_UBAGG_IOCTL_H #define UVS_UBAGG_IOCTL_H #include +#include "uvs_types.h" typedef enum uvs_ubagg_cmd { UVS_UBAGG_CMD_ADD_DEV = 1, UVS_UBAGG_CMD_RMV_DEV, - UVS_UBAGG_CMD_SET_TOPO, + UVS_UBAGG_CMD_SET_TOPO_INFO, + UVS_UBAGG_CMD_CREATE_DEV, + UVS_UBAGG_CMD_DELETE_DEV, + UVS_UBAGG_CMD_GET_DEV_NAME, } uvs_ubagg_cmd_t; struct uvs_ubagg_cmd_hdr { @@ -26,6 +30,26 @@ struct uvs_ubagg_cmd_hdr { #define UVS_UBAGG_CMD_MAGIC 'B' #define UVS_UBAGG_CMD _IOWR(UVS_UBAGG_CMD_MAGIC, 1, struct uvs_ubagg_cmd_hdr) +struct uvs_ubagg_create_dev_arg { + struct { + uvs_eid_t aggr_eid; + } in; +}; + +struct uvs_ubagg_delete_dev_arg { + struct { + uvs_eid_t aggr_eid; + } in; +}; + +struct uvs_ubagg_get_dev_name_arg { + struct { + uvs_eid_t eid; + void *buf; + uint32_t len; + } in; +}; + struct uvs_ubagg_set_topo_info { struct { void *topo; @@ -33,6 +57,9 @@ struct uvs_ubagg_set_topo_info { } in; }; +int uvs_ubagg_ioctl_create_aggr_dev(uvs_eid_t aggr_eid); +int uvs_ubagg_ioctl_delete_aggr_dev(uvs_eid_t aggr_eid); +int uvs_ubagg_ioctl_get_dev_name_by_eid(uvs_eid_t eid, void *buf, uint32_t len); int uvs_ubagg_ioctl_set_topo(void *topo_info, int topo_num); int uvs_ubcore_ioctl_set_topo(void *topo_info, int topo_num); int uvs_ubcore_ioctl_get_route_list(const uvs_route_t *route, uvs_route_list_t *route_list); -- Gitee