From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 3238EA04EF; Mon, 1 Jun 2020 07:51:21 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 625DF1D529; Mon, 1 Jun 2020 07:51:00 +0200 (CEST) Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2083.outbound.protection.outlook.com [40.107.20.83]) by dpdk.org (Postfix) with ESMTP id 296EF1D451 for ; Mon, 1 Jun 2020 07:50:58 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UnWcrRfOFCahdb2K2G+LgqdX6nJWJJtYgm472eLxQhoQRW/YpM9U6WPcgAZUa61LiNEiedE2kjKO+CQ9COH27lHeDdv2i8AZOpElTcH8Gc655rzZPOLcz6vsDTyisas7PoEFoy5BVvW494BZ6oKCoG3/XScLZRbhvKbPvNRXyxq2GgOUtgulUvq4vepskd3kVPhBIIxnq5erOM7C68Wailgnpj7Dg/QwJ8IsqECx7pTJUhfz8Bt1Sl5Kkgh72Vk1+BzB2BAWGO4USXhFdDdcxnQzv97Qg1euVW2c0Is8ET4xo1TPx6yIGGpXj2i2ooVa3qwFgryjHGGCsIeVpQ2eCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=DxeSoul1I/MHmMhmeDLMIIqTS8R3ccHCo+xaM1lmkys=; b=oAwyt9X8vvvGA9HnuMV+A33gQTO1yBEtQ5HMfAxFMYTVishixPqU2AFlKcX8xs70jfySOfYpIUx74lMBoHUGKfE+aUxWC7coA/oN57xbcVQupz+g0atGK0sS9pyiB8u1eZN4tb8jmRCG0KZSmwUH2ch9s1+04SUhdPIyaWBdh3Gyua66ZXZ8WbxvEmbtU7q99PqdoF/MwK0qyBbkiAmrTU4FQ9+K5crm105nj7AZbbaO3u5bhBfT/tugtigR5IxQrPr+1OtZvR5IHzVKLNM/Lp9+Bb3hWlRPahFskp0Bmqe+hGaWqZD78VC+Zg8j78xDTNtQahOmOkNDN9rnuVJpaA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=mellanox.com; dmarc=pass action=none header.from=mellanox.com; dkim=pass header.d=mellanox.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=DxeSoul1I/MHmMhmeDLMIIqTS8R3ccHCo+xaM1lmkys=; b=YdXYXR41sRstP7FNF//V3ehSw5/GTBLK2ZmxzrDkojRgwbBS/5rOAWcBEb2l0BDY1HH2cAj3hMBzVRR1gSj2gMt6H2qOg9TByJOind45NGnAuyYuVLKPqZsbCOaNKMxqQk9X7zO5NDxP7fj48xsgz/NW9ES4P9bbCdv9drqO4H4= Authentication-Results: dpdk.org; dkim=none (message not signed) header.d=none;dpdk.org; dmarc=none action=none header.from=mellanox.com; Received: from AM0PR05MB4209.eurprd05.prod.outlook.com (2603:10a6:208:61::22) by AM0PR05MB5953.eurprd05.prod.outlook.com (2603:10a6:208:12f::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3045.21; Mon, 1 Jun 2020 05:50:56 +0000 Received: from AM0PR05MB4209.eurprd05.prod.outlook.com ([fe80::1068:89a9:41d3:b14a]) by AM0PR05MB4209.eurprd05.prod.outlook.com ([fe80::1068:89a9:41d3:b14a%3]) with mapi id 15.20.3045.024; Mon, 1 Jun 2020 05:50:56 +0000 From: Ophir Munk To: dev@dpdk.org, Matan Azrad Cc: Ophir Munk Date: Mon, 1 Jun 2020 05:50:47 +0000 Message-Id: <20200601055047.5108-4-ophirmu@mellanox.com> X-Mailer: git-send-email 2.8.4 In-Reply-To: <20200601055047.5108-1-ophirmu@mellanox.com> References: <20200527161425.22944-1-ophirmu@mellanox.com> <20200601055047.5108-1-ophirmu@mellanox.com> Content-Type: text/plain X-ClientProxiedBy: AM0PR06CA0110.eurprd06.prod.outlook.com (2603:10a6:208:ab::15) To AM0PR05MB4209.eurprd05.prod.outlook.com (2603:10a6:208:61::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mellanox.com (37.142.13.130) by AM0PR06CA0110.eurprd06.prod.outlook.com (2603:10a6:208:ab::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3045.17 via Frontend Transport; Mon, 1 Jun 2020 05:50:55 +0000 X-Mailer: git-send-email 2.8.4 X-Originating-IP: [37.142.13.130] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 1db35432-05e7-4735-e2d7-08d805efc06c X-MS-TrafficTypeDiagnostic: AM0PR05MB5953: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:265; X-Forefront-PRVS: 0421BF7135 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rq52jgZS6KBM1/is0QaQ++jvGZbT7q38jPok7MEBiGNnUUwA+wvg1twd4bqmwRfTKmLCEuK7xMRNg67CZwMdJZrzlcUv9NlroLXXI2aXZ/FTxS7rt5ABopsrjJC8uRvzzdqp4wW6YVQ+IqwsIKQ55uMWp60XFsImMdrp6ORkzZWdJ22ue36pZPSmxXpCxMluI539kvwXTo1FIg9IzZOf4GjdszW/QEC7yFpyh90cIL9jm4bE6iob0XDT7GTSLwy3T2JPmZiU09Mu+p9sihdx4GIy0WMSULludWVYmbnGgLjgaeDSvZ3aoaIJbR3ZTw339yPf02Wxgr/7erXDO4ESmg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR05MB4209.eurprd05.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(4636009)(396003)(376002)(346002)(136003)(366004)(39860400002)(6666004)(36756003)(6862004)(66556008)(66476007)(37006003)(7696005)(52116002)(8886007)(1076003)(66946007)(107886003)(83380400001)(8936002)(86362001)(30864003)(2616005)(5660300002)(316002)(26005)(8676002)(16526019)(478600001)(186003)(956004)(4326008)(6636002)(55016002)(2906002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: aihS1mrqMznQeb1Lkp1sv4uGJiHITClxaL5xBQyakhOjHSqQKCDwWdYpsV+YuO+55Gfpr8mM8lPd9DKVEuerg5pGO8yPS3In4xRUVUub9EUsWkjIQOBv2zLqPCPFhy9Fk1FSIhnF/Ne5dsMDBsMcc21LoI9yFbJIlJ4govVgMynMrYtGpMPHYktk9NNnB4E0jHs1zYk4WigMEHtfsA5PXnv/VXIfRCZ13GowrCKccTaRPGIB57d23xhPyX2FB8T2t8K4XDaOWeKqEyqssVZ4rXxO8JUth3Xpd/Je7W+9U40VcdJr43bqNlxw3JU7nP4OjWmP6cbBB6WgwtsKsM0kKiSUMgyCIp6ZVvQchE8U2tYK0k8dFgbC0clr9V9s1THoGoCgp87hsZoodFReYj4aaS9nuSGrjWrkB+vRUNkyTOxcmjFZ0Bw2RhiRrEksaJGJ7bPecapdhRnJlw3E7S+qTmjMAcEDwzdxFwV5Q8eErsPHLabnB09gkvQowPu9BA9N X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1db35432-05e7-4735-e2d7-08d805efc06c X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Jun 2020 05:50:55.9227 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: jwdZddr1yFGcvzWvlD+mCw1Ov0xMCI5g6hfZFbDi/kCQ83oDiGkxPLwklhW9fmFr+yhubm6iuxJuHLswkFWy8w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR05MB5953 Subject: [dpdk-dev] [PATCH v2 3/3] common/mlx5: split common file under Linux directory X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" File mlx5_common.c includes both specific and non-specific Linux APIs. Move the Linux specific APIS into a new file named linux/mlx5_common_os.c. Signed-off-by: Ophir Munk --- drivers/common/mlx5/Makefile | 1 + drivers/common/mlx5/linux/meson.build | 1 + drivers/common/mlx5/linux/mlx5_common_os.c | 305 +++++++++++++++++++++++++++++ drivers/common/mlx5/mlx5_common.c | 286 +-------------------------- drivers/common/mlx5/mlx5_common.h | 1 + 5 files changed, 310 insertions(+), 284 deletions(-) create mode 100644 drivers/common/mlx5/linux/mlx5_common_os.c diff --git a/drivers/common/mlx5/Makefile b/drivers/common/mlx5/Makefile index 40bf2a5..e9863b5 100644 --- a/drivers/common/mlx5/Makefile +++ b/drivers/common/mlx5/Makefile @@ -16,6 +16,7 @@ SRCS-y += linux/mlx5_glue.c endif SRCS-y += mlx5_devx_cmds.c SRCS-y += mlx5_common.c +SRCS-y += linux/mlx5_common_os.c SRCS-y += linux/mlx5_nl.c SRCS-y += mlx5_common_mp.c SRCS-y += mlx5_common_mr.c diff --git a/drivers/common/mlx5/linux/meson.build b/drivers/common/mlx5/linux/meson.build index 04f7e03..f0016fa 100644 --- a/drivers/common/mlx5/linux/meson.build +++ b/drivers/common/mlx5/linux/meson.build @@ -46,6 +46,7 @@ if static_ibverbs endif sources += files('mlx5_nl.c') +sources += files('mlx5_common_os.c') if not dlopen_ibverbs sources += files('mlx5_glue.c') endif diff --git a/drivers/common/mlx5/linux/mlx5_common_os.c b/drivers/common/mlx5/linux/mlx5_common_os.c new file mode 100644 index 0000000..4e04d70 --- /dev/null +++ b/drivers/common/mlx5/linux/mlx5_common_os.c @@ -0,0 +1,305 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright 2020 Mellanox Technologies, Ltd + */ + +#include +#include +#include +#ifdef RTE_IBVERBS_LINK_DLOPEN +#include +#endif + +#include + +#include "mlx5_common.h" +#include "mlx5_common_utils.h" +#include "mlx5_glue.h" + +#ifdef MLX5_GLUE +const struct mlx5_glue *mlx5_glue; +#endif + +/** + * Get PCI information by sysfs device path. + * + * @param dev_path + * Pointer to device sysfs folder name. + * @param[out] pci_addr + * PCI bus address output buffer. + * + * @return + * 0 on success, a negative errno value otherwise and rte_errno is set. + */ +int +mlx5_dev_to_pci_addr(const char *dev_path, + struct rte_pci_addr *pci_addr) +{ + FILE *file; + char line[32]; + MKSTR(path, "%s/device/uevent", dev_path); + + file = fopen(path, "rb"); + if (file == NULL) { + rte_errno = errno; + return -rte_errno; + } + while (fgets(line, sizeof(line), file) == line) { + size_t len = strlen(line); + int ret; + + /* Truncate long lines. */ + if (len == (sizeof(line) - 1)) + while (line[(len - 1)] != '\n') { + ret = fgetc(file); + if (ret == EOF) + break; + line[(len - 1)] = ret; + } + /* Extract information. */ + if (sscanf(line, + "PCI_SLOT_NAME=" + "%" SCNx32 ":%" SCNx8 ":%" SCNx8 ".%" SCNx8 "\n", + &pci_addr->domain, + &pci_addr->bus, + &pci_addr->devid, + &pci_addr->function) == 4) { + ret = 0; + break; + } + } + fclose(file); + return 0; +} + +/** + * Extract port name, as a number, from sysfs or netlink information. + * + * @param[in] port_name_in + * String representing the port name. + * @param[out] port_info_out + * Port information, including port name as a number and port name + * type if recognized + * + * @return + * port_name field set according to recognized name format. + */ +void +mlx5_translate_port_name(const char *port_name_in, + struct mlx5_switch_info *port_info_out) +{ + char pf_c1, pf_c2, vf_c1, vf_c2; + char *end; + int sc_items; + + /* + * Check for port-name as a string of the form pf0vf0 + * (support kernel ver >= 5.0 or OFED ver >= 4.6). + */ + sc_items = sscanf(port_name_in, "%c%c%d%c%c%d", + &pf_c1, &pf_c2, &port_info_out->pf_num, + &vf_c1, &vf_c2, &port_info_out->port_name); + if (sc_items == 6 && + pf_c1 == 'p' && pf_c2 == 'f' && + vf_c1 == 'v' && vf_c2 == 'f') { + port_info_out->name_type = MLX5_PHYS_PORT_NAME_TYPE_PFVF; + return; + } + /* + * Check for port-name as a string of the form p0 + * (support kernel ver >= 5.0, or OFED ver >= 4.6). + */ + sc_items = sscanf(port_name_in, "%c%d", + &pf_c1, &port_info_out->port_name); + if (sc_items == 2 && pf_c1 == 'p') { + port_info_out->name_type = MLX5_PHYS_PORT_NAME_TYPE_UPLINK; + return; + } + /* Check for port-name as a number (support kernel ver < 5.0 */ + errno = 0; + port_info_out->port_name = strtol(port_name_in, &end, 0); + if (!errno && + (size_t)(end - port_name_in) == strlen(port_name_in)) { + port_info_out->name_type = MLX5_PHYS_PORT_NAME_TYPE_LEGACY; + return; + } + port_info_out->name_type = MLX5_PHYS_PORT_NAME_TYPE_UNKNOWN; +} + +#ifdef MLX5_GLUE + +/** + * Suffix RTE_EAL_PMD_PATH with "-glue". + * + * This function performs a sanity check on RTE_EAL_PMD_PATH before + * suffixing its last component. + * + * @param buf[out] + * Output buffer, should be large enough otherwise NULL is returned. + * @param size + * Size of @p out. + * + * @return + * Pointer to @p buf or @p NULL in case suffix cannot be appended. + */ +static char * +mlx5_glue_path(char *buf, size_t size) +{ + static const char *const bad[] = { "/", ".", "..", NULL }; + const char *path = RTE_EAL_PMD_PATH; + size_t len = strlen(path); + size_t off; + int i; + + while (len && path[len - 1] == '/') + --len; + for (off = len; off && path[off - 1] != '/'; --off) + ; + for (i = 0; bad[i]; ++i) + if (!strncmp(path + off, bad[i], (int)(len - off))) + goto error; + i = snprintf(buf, size, "%.*s-glue", (int)len, path); + if (i == -1 || (size_t)i >= size) + goto error; + return buf; +error: + RTE_LOG(ERR, PMD, "unable to append \"-glue\" to last component of" + " RTE_EAL_PMD_PATH (\"" RTE_EAL_PMD_PATH "\"), please" + " re-configure DPDK"); + return NULL; +} + +static int +mlx5_glue_dlopen(void) +{ + char glue_path[sizeof(RTE_EAL_PMD_PATH) - 1 + sizeof("-glue")]; + void *handle = NULL; + + char const *path[] = { + /* + * A basic security check is necessary before trusting + * MLX5_GLUE_PATH, which may override RTE_EAL_PMD_PATH. + */ + (geteuid() == getuid() && getegid() == getgid() ? + getenv("MLX5_GLUE_PATH") : NULL), + /* + * When RTE_EAL_PMD_PATH is set, use its glue-suffixed + * variant, otherwise let dlopen() look up libraries on its + * own. + */ + (*RTE_EAL_PMD_PATH ? + mlx5_glue_path(glue_path, sizeof(glue_path)) : ""), + }; + unsigned int i = 0; + void **sym; + const char *dlmsg; + + while (!handle && i != RTE_DIM(path)) { + const char *end; + size_t len; + int ret; + + if (!path[i]) { + ++i; + continue; + } + end = strpbrk(path[i], ":;"); + if (!end) + end = path[i] + strlen(path[i]); + len = end - path[i]; + ret = 0; + do { + char name[ret + 1]; + + ret = snprintf(name, sizeof(name), "%.*s%s" MLX5_GLUE, + (int)len, path[i], + (!len || *(end - 1) == '/') ? "" : "/"); + if (ret == -1) + break; + if (sizeof(name) != (size_t)ret + 1) + continue; + DRV_LOG(DEBUG, "Looking for rdma-core glue as " + "\"%s\"", name); + handle = dlopen(name, RTLD_LAZY); + break; + } while (1); + path[i] = end + 1; + if (!*end) + ++i; + } + if (!handle) { + rte_errno = EINVAL; + dlmsg = dlerror(); + if (dlmsg) + DRV_LOG(WARNING, "Cannot load glue library: %s", dlmsg); + goto glue_error; + } + sym = dlsym(handle, "mlx5_glue"); + if (!sym || !*sym) { + rte_errno = EINVAL; + dlmsg = dlerror(); + if (dlmsg) + DRV_LOG(ERR, "Cannot resolve glue symbol: %s", dlmsg); + goto glue_error; + } + mlx5_glue = *sym; + return 0; + +glue_error: + if (handle) + dlclose(handle); + return -1; +} + +#endif + +/** + * Initialization routine for run-time dependency on rdma-core. + */ +void +mlx5_glue_constructor(void) +{ + /* + * RDMAV_HUGEPAGES_SAFE tells ibv_fork_init() we intend to use + * huge pages. Calling ibv_fork_init() during init allows + * applications to use fork() safely for purposes other than + * using this PMD, which is not supported in forked processes. + */ + setenv("RDMAV_HUGEPAGES_SAFE", "1", 1); + /* Match the size of Rx completion entry to the size of a cacheline. */ + if (RTE_CACHE_LINE_SIZE == 128) + setenv("MLX5_CQE_SIZE", "128", 0); + /* + * MLX5_DEVICE_FATAL_CLEANUP tells ibv_destroy functions to + * cleanup all the Verbs resources even when the device was removed. + */ + setenv("MLX5_DEVICE_FATAL_CLEANUP", "1", 1); + +#ifdef MLX5_GLUE + if (mlx5_glue_dlopen() != 0) + goto glue_error; +#endif + +#ifdef RTE_LIBRTE_MLX5_DEBUG + /* Glue structure must not contain any NULL pointers. */ + { + unsigned int i; + + for (i = 0; i != sizeof(*mlx5_glue) / sizeof(void *); ++i) + MLX5_ASSERT(((const void *const *)mlx5_glue)[i]); + } +#endif + if (strcmp(mlx5_glue->version, MLX5_GLUE_VERSION)) { + rte_errno = EINVAL; + DRV_LOG(ERR, "rdma-core glue \"%s\" mismatch: \"%s\" is " + "required", mlx5_glue->version, MLX5_GLUE_VERSION); + goto glue_error; + } + mlx5_glue->fork_init(); + return; + +glue_error: + DRV_LOG(WARNING, "Cannot initialize MLX5 common due to missing" + " run-time dependency on rdma-core libraries (libibverbs," + " libmlx5)"); + mlx5_glue = NULL; +} diff --git a/drivers/common/mlx5/mlx5_common.c b/drivers/common/mlx5/mlx5_common.c index 1c77763..db94d4a 100644 --- a/drivers/common/mlx5/mlx5_common.c +++ b/drivers/common/mlx5/mlx5_common.c @@ -5,16 +5,11 @@ #include #include #include -#ifdef RTE_IBVERBS_LINK_DLOPEN -#include -#endif #include #include "mlx5_common.h" #include "mlx5_common_utils.h" -#include "mlx5_glue.h" - int mlx5_common_logtype; @@ -24,58 +19,6 @@ const struct mlx5_glue *mlx5_glue; uint8_t haswell_broadwell_cpu; -/** - * Get PCI information by sysfs device path. - * - * @param dev_path - * Pointer to device sysfs folder name. - * @param[out] pci_addr - * PCI bus address output buffer. - * - * @return - * 0 on success, a negative errno value otherwise and rte_errno is set. - */ -int -mlx5_dev_to_pci_addr(const char *dev_path, - struct rte_pci_addr *pci_addr) -{ - FILE *file; - char line[32]; - MKSTR(path, "%s/device/uevent", dev_path); - - file = fopen(path, "rb"); - if (file == NULL) { - rte_errno = errno; - return -rte_errno; - } - while (fgets(line, sizeof(line), file) == line) { - size_t len = strlen(line); - int ret; - - /* Truncate long lines. */ - if (len == (sizeof(line) - 1)) - while (line[(len - 1)] != '\n') { - ret = fgetc(file); - if (ret == EOF) - break; - line[(len - 1)] = ret; - } - /* Extract information. */ - if (sscanf(line, - "PCI_SLOT_NAME=" - "%" SCNx32 ":%" SCNx8 ":%" SCNx8 ".%" SCNx8 "\n", - &pci_addr->domain, - &pci_addr->bus, - &pci_addr->devid, - &pci_addr->function) == 4) { - ret = 0; - break; - } - } - fclose(file); - return 0; -} - static int mlx5_class_check_handler(__rte_unused const char *key, const char *value, void *opaque) @@ -112,187 +55,6 @@ mlx5_class_get(struct rte_devargs *devargs) return ret; } -/** - * Extract port name, as a number, from sysfs or netlink information. - * - * @param[in] port_name_in - * String representing the port name. - * @param[out] port_info_out - * Port information, including port name as a number and port name - * type if recognized - * - * @return - * port_name field set according to recognized name format. - */ -void -mlx5_translate_port_name(const char *port_name_in, - struct mlx5_switch_info *port_info_out) -{ - char pf_c1, pf_c2, vf_c1, vf_c2; - char *end; - int sc_items; - - /* - * Check for port-name as a string of the form pf0vf0 - * (support kernel ver >= 5.0 or OFED ver >= 4.6). - */ - sc_items = sscanf(port_name_in, "%c%c%d%c%c%d", - &pf_c1, &pf_c2, &port_info_out->pf_num, - &vf_c1, &vf_c2, &port_info_out->port_name); - if (sc_items == 6 && - pf_c1 == 'p' && pf_c2 == 'f' && - vf_c1 == 'v' && vf_c2 == 'f') { - port_info_out->name_type = MLX5_PHYS_PORT_NAME_TYPE_PFVF; - return; - } - /* - * Check for port-name as a string of the form p0 - * (support kernel ver >= 5.0, or OFED ver >= 4.6). - */ - sc_items = sscanf(port_name_in, "%c%d", - &pf_c1, &port_info_out->port_name); - if (sc_items == 2 && pf_c1 == 'p') { - port_info_out->name_type = MLX5_PHYS_PORT_NAME_TYPE_UPLINK; - return; - } - /* Check for port-name as a number (support kernel ver < 5.0 */ - errno = 0; - port_info_out->port_name = strtol(port_name_in, &end, 0); - if (!errno && - (size_t)(end - port_name_in) == strlen(port_name_in)) { - port_info_out->name_type = MLX5_PHYS_PORT_NAME_TYPE_LEGACY; - return; - } - port_info_out->name_type = MLX5_PHYS_PORT_NAME_TYPE_UNKNOWN; - return; -} - -#ifdef MLX5_GLUE - -/** - * Suffix RTE_EAL_PMD_PATH with "-glue". - * - * This function performs a sanity check on RTE_EAL_PMD_PATH before - * suffixing its last component. - * - * @param buf[out] - * Output buffer, should be large enough otherwise NULL is returned. - * @param size - * Size of @p out. - * - * @return - * Pointer to @p buf or @p NULL in case suffix cannot be appended. - */ -static char * -mlx5_glue_path(char *buf, size_t size) -{ - static const char *const bad[] = { "/", ".", "..", NULL }; - const char *path = RTE_EAL_PMD_PATH; - size_t len = strlen(path); - size_t off; - int i; - - while (len && path[len - 1] == '/') - --len; - for (off = len; off && path[off - 1] != '/'; --off) - ; - for (i = 0; bad[i]; ++i) - if (!strncmp(path + off, bad[i], (int)(len - off))) - goto error; - i = snprintf(buf, size, "%.*s-glue", (int)len, path); - if (i == -1 || (size_t)i >= size) - goto error; - return buf; -error: - RTE_LOG(ERR, PMD, "unable to append \"-glue\" to last component of" - " RTE_EAL_PMD_PATH (\"" RTE_EAL_PMD_PATH "\"), please" - " re-configure DPDK"); - return NULL; -} - -static int -mlx5_glue_dlopen(void) -{ - char glue_path[sizeof(RTE_EAL_PMD_PATH) - 1 + sizeof("-glue")]; - void *handle = NULL; - - const char *path[] = { - /* - * A basic security check is necessary before trusting - * MLX5_GLUE_PATH, which may override RTE_EAL_PMD_PATH. - */ - (geteuid() == getuid() && getegid() == getgid() ? - getenv("MLX5_GLUE_PATH") : NULL), - /* - * When RTE_EAL_PMD_PATH is set, use its glue-suffixed - * variant, otherwise let dlopen() look up libraries on its - * own. - */ - (*RTE_EAL_PMD_PATH ? - mlx5_glue_path(glue_path, sizeof(glue_path)) : ""), - }; - unsigned int i = 0; - void **sym; - const char *dlmsg; - - while (!handle && i != RTE_DIM(path)) { - const char *end; - size_t len; - int ret; - - if (!path[i]) { - ++i; - continue; - } - end = strpbrk(path[i], ":;"); - if (!end) - end = path[i] + strlen(path[i]); - len = end - path[i]; - ret = 0; - do { - char name[ret + 1]; - - ret = snprintf(name, sizeof(name), "%.*s%s" MLX5_GLUE, - (int)len, path[i], - (!len || *(end - 1) == '/') ? "" : "/"); - if (ret == -1) - break; - if (sizeof(name) != (size_t)ret + 1) - continue; - DRV_LOG(DEBUG, "Looking for rdma-core glue as " - "\"%s\"", name); - handle = dlopen(name, RTLD_LAZY); - break; - } while (1); - path[i] = end + 1; - if (!*end) - ++i; - } - if (!handle) { - rte_errno = EINVAL; - dlmsg = dlerror(); - if (dlmsg) - DRV_LOG(WARNING, "Cannot load glue library: %s", dlmsg); - goto glue_error; - } - sym = dlsym(handle, "mlx5_glue"); - if (!sym || !*sym) { - rte_errno = EINVAL; - dlmsg = dlerror(); - if (dlmsg) - DRV_LOG(ERR, "Cannot resolve glue symbol: %s", dlmsg); - goto glue_error; - } - mlx5_glue = *sym; - return 0; - -glue_error: - if (handle) - dlclose(handle); - return -1; -} - -#endif /* In case this is an x86_64 intel processor to check if * we should use relaxed ordering. @@ -325,55 +87,11 @@ RTE_INIT_PRIO(mlx5_log_init, LOG) } /** - * Initialization routine for run-time dependency on rdma-core. + * Initialization routine for run-time dependency on glue library. */ RTE_INIT_PRIO(mlx5_glue_init, CLASS) { - /* - * RDMAV_HUGEPAGES_SAFE tells ibv_fork_init() we intend to use - * huge pages. Calling ibv_fork_init() during init allows - * applications to use fork() safely for purposes other than - * using this PMD, which is not supported in forked processes. - */ - setenv("RDMAV_HUGEPAGES_SAFE", "1", 1); - /* Match the size of Rx completion entry to the size of a cacheline. */ - if (RTE_CACHE_LINE_SIZE == 128) - setenv("MLX5_CQE_SIZE", "128", 0); - /* - * MLX5_DEVICE_FATAL_CLEANUP tells ibv_destroy functions to - * cleanup all the Verbs resources even when the device was removed. - */ - setenv("MLX5_DEVICE_FATAL_CLEANUP", "1", 1); - -#ifdef MLX5_GLUE - if (mlx5_glue_dlopen() != 0) - goto glue_error; -#endif - -#ifdef RTE_LIBRTE_MLX5_DEBUG - /* Glue structure must not contain any NULL pointers. */ - { - unsigned int i; - - for (i = 0; i != sizeof(*mlx5_glue) / sizeof(void *); ++i) - MLX5_ASSERT(((const void *const *)mlx5_glue)[i]); - } -#endif - if (strcmp(mlx5_glue->version, MLX5_GLUE_VERSION)) { - rte_errno = EINVAL; - DRV_LOG(ERR, "rdma-core glue \"%s\" mismatch: \"%s\" is " - "required", mlx5_glue->version, MLX5_GLUE_VERSION); - goto glue_error; - } - mlx5_glue->fork_init(); - return; - -glue_error: - DRV_LOG(WARNING, "Cannot initialize MLX5 common due to missing" - " run-time dependency on rdma-core libraries (libibverbs," - " libmlx5)"); - mlx5_glue = NULL; - return; + mlx5_glue_constructor(); } /** diff --git a/drivers/common/mlx5/mlx5_common.h b/drivers/common/mlx5/mlx5_common.h index 8cd3ea5..8e679c6 100644 --- a/drivers/common/mlx5/mlx5_common.h +++ b/drivers/common/mlx5/mlx5_common.h @@ -212,6 +212,7 @@ enum mlx5_class mlx5_class_get(struct rte_devargs *devargs); __rte_internal void mlx5_translate_port_name(const char *port_name_in, struct mlx5_switch_info *port_info_out); +void mlx5_glue_constructor(void); extern uint8_t haswell_broadwell_cpu; -- 2.8.4