From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 2060543252; Tue, 31 Oct 2023 15:28:56 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 490EC41156; Tue, 31 Oct 2023 15:28:27 +0100 (CET) Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on2088.outbound.protection.outlook.com [40.107.102.88]) by mails.dpdk.org (Postfix) with ESMTP id 62C6641143 for ; Tue, 31 Oct 2023 15:28:25 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=P1rzKC9+hG7FRxJIvvib5YCJzP5T2mSkWWXHuwH30shyi8Nfpb2cAiI123KCknwrT47YJB1nrk6vxoMG8V+0GK/VCYXiYRYkmtKIg6UssH3TxY7CsHtj/xMIlaZpyRmqapX3qiNb2ExU9pL9x4rSN+XaAir91sTyejyxMnwkRLWaFa75/n66ngbeIAfZbXmeaYnDKYcmPzajCxEbrq9liy2yeTCI2Q7rhOEWGvtlovNCLtAlf9cEhgRIA7QSLtRsOHwk+7hD8/j9RSGwjB8NEuH3zx4UM5rhRuksypuu5ZAYDhQvLxCwHTeXGgTYUz/nOLXLXBMZcO0l+B6a28HI1g== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=f2IWVZ+r4heu6N2b1j5k7HjoUmSHE8myAezAUanMOgY=; b=nMZX/prWoRURHY4ErdvPM2jWQMIrGhSzrqE2ITgZsn01qkTLfR5iijo+M9+s5gkJspZQ1fm3TN/io6Mvh3lVNyyBCQ7uI36n6WCD5DQtSyvJ/vk5PahohgzfsCu7/CHL890sxFa5yRx87cqoOzQrqiz9BKSF5nNW7SuUSspeZQ3LwgCn5MfFfEwvzSs8Nz4FikTDnRD/QyKYjmdn2xy12gkYZsiJbZEu5As7BGv8x6vQAT5MBVE43KXFLlm+2JwveS8mXX9Hg9IuzZaFc/DiII8TYOgNfjQ1O6nRB9O4JwpI9acesxXFEtt7LfswmHCYBu2TkhAd2JhVuGOpQYinPQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=dpdk.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=f2IWVZ+r4heu6N2b1j5k7HjoUmSHE8myAezAUanMOgY=; b=eD8DMGdU0RcVs+B4pnZu4zrfKfuYBcpAgB1EwObTJ254jcBUKD7RSdq/m3G06WWO2vPAOn/vx71H+IEsSv/N1s9v5lRMMifwDqDCJfS/LSknVhtGc5Pv6D9tzyjh2n3gAoFz1SrrZZIMSMLqED6hl7x+IRpjE4NgpJl2+qUGMZAZz9vzW6dypCTON7kMUzNC7cwDONRLu0B1sK7riqVpQNS89AluZ0MzY72CF66EkqnDoT+Iz80GZQYv6L+gRfBlpt5iD+cV2RT8Mzj2/XoZMXQUOJ9dpudnIooksS3y+paYIOtSkZF4b5rYiRhxliMnBskdjv+5oYoRxq1y8ZO8KA== Received: from MWH0EPF00056D1A.namprd21.prod.outlook.com (2603:10b6:30f:fff2:0:1:0:17) by PH8PR12MB7183.namprd12.prod.outlook.com (2603:10b6:510:228::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.25; Tue, 31 Oct 2023 14:28:22 +0000 Received: from MWH0EPF000971E7.namprd02.prod.outlook.com (2a01:111:f403:c903::1) by MWH0EPF00056D1A.outlook.office365.com (2603:1036:d20::b) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6954.8 via Frontend Transport; Tue, 31 Oct 2023 14:28:22 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by MWH0EPF000971E7.mail.protection.outlook.com (10.167.243.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6954.19 via Frontend Transport; Tue, 31 Oct 2023 14:28:21 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Tue, 31 Oct 2023 07:27:59 -0700 Received: from nvidia.com (10.126.231.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Tue, 31 Oct 2023 07:27:57 -0700 From: Dariusz Sosnowski To: Matan Azrad , Viacheslav Ovsiienko , Ori Kam , Suanming Mou CC: , Raslan Darawsheh Subject: [PATCH 3/8] common/mlx5: add Netlink check for Multiport E-Switch Date: Tue, 31 Oct 2023 16:27:28 +0200 Message-ID: <20231031142733.2009166-4-dsosnowski@nvidia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231031142733.2009166-1-dsosnowski@nvidia.com> References: <20231031142733.2009166-1-dsosnowski@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.126.231.35] X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWH0EPF000971E7:EE_|PH8PR12MB7183:EE_ X-MS-Office365-Filtering-Correlation-Id: 198f5600-e0f1-423c-f42d-08dbda1da2a4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sZ5ApEgBpvNnEX86ZgDLwNbABgrU7ttbEU3B+vUMUWKDV47XGFsP96QIygbkrkJmySjcg+Q71ovAbXa+gpVtPvQy6hDGq8Ltfu88YtdFWugzRBr8UfM0HtARGrV8ecEyP6JEHC7P5rqWvnEQMvTkBCqgjeaXvS3oJpo0nfAhdecGMtf4GvBIgT4rc9ffafYmcQDfpfC8f7FVsIMmAO9PaZrJMFLjcGh8laalYxz+XmI2EmckGVxrEj7xddTHzo7Hijm1N8hYiE9GTNRPIEfuqkAmEMWWMhQnmy1uL9qRBbuMhI33bMXhQJR3LAZ8A2QtfSnkloJgN22HvsWSeQxDRKdKfyq4fvI+hVSWNcOXZCbtMuppPGV1bCOmccLyMWxVfTmRISDB3rFxvskSHxPILuS1y3VjECl7hGt1Qknts3AZPDtBs0yhiZ1uZVV1LKxklFeX5tMC3w94wTdDSoUE0ZDNRcW7ZXV7UvgUnJ6YTL4HwoRz/Vv8IwP9wbL9JpdOkGupO2IbZWCk+IgF0N++2IQcWhZaRMILCY849rcLXmjZacbqWGDQ4sZyGnATMkAy76rUK8WDkJnshq7phQ9VFTOuzOAO4ZQjkv5v/zp3H4/SpVncyrOD1fUvQsdH06NWZIUvvwQx+OcR/zPsXZLZBxBks3eAWep9nh7UtOEWNm8Vqo/t0PBG82Fr4DpPxLv7tyxiCVsPS5S32Vb6uDkSj8+InoTg3bu8LEpL0c/RYVnRgQgMh3ux5wZrlJrA/OAc X-Forefront-Antispam-Report: CIP:216.228.117.160; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge1.nvidia.com; CAT:NONE; SFS:(13230031)(4636009)(136003)(39860400002)(376002)(396003)(346002)(230922051799003)(82310400011)(1800799009)(451199024)(186009)(64100799003)(40470700004)(46966006)(36840700001)(2906002)(6286002)(26005)(1076003)(16526019)(2616005)(336012)(83380400001)(478600001)(7696005)(36860700001)(6666004)(426003)(47076005)(5660300002)(41300700001)(70206006)(70586007)(110136005)(107886003)(8676002)(4326008)(8936002)(316002)(54906003)(6636002)(40460700003)(356005)(7636003)(82740400003)(86362001)(36756003)(55016003)(40480700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Oct 2023 14:28:21.9120 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 198f5600-e0f1-423c-f42d-08dbda1da2a4 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.117.160]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: MWH0EPF000971E7.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB7183 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org This patch implements checking if Multiport E-Switch is enabled on a given PCI device using Devlink Linux kernel interface. This facility will be used in follow up commits, which add support for such configuration to mlx5 PMD. If mlx5_core Linux kernel module supports Multiport E-Switch, then it can be configured through a Devlink boolean parameter "esw_multiport". Checking the value of this parameter is implemented in mlx5_nl_devlink_esw_multiport_get() function. If such parameter does not exist, this function returns -EINVAL. To manually check if mlx5_core kernel module supports "esw_multiport" parameter, and check if Multiport E-Switch is enabled, one can use the following command: # should be substituted with PCI device address # in format :::. $ devlink dev param show pci/0000:08:00.0 name esw_multiport pci/0000:08:00.0: name esw_multiport type driver-specific values: cmode runtime value true If parameter is not supported, Devlink command fails with "Invalid argument" error. Signed-off-by: Dariusz Sosnowski Acked-by: Viacheslav Ovsiienko --- drivers/common/mlx5/linux/mlx5_nl.c | 70 +++++++++++++++++++++++++++++ drivers/common/mlx5/linux/mlx5_nl.h | 5 +++ drivers/common/mlx5/version.map | 2 + 3 files changed, 77 insertions(+) diff --git a/drivers/common/mlx5/linux/mlx5_nl.c b/drivers/common/mlx5/linux/mlx5_nl.c index 33670bb5c8..28a1f56dba 100644 --- a/drivers/common/mlx5/linux/mlx5_nl.c +++ b/drivers/common/mlx5/linux/mlx5_nl.c @@ -1962,3 +1962,73 @@ mlx5_nl_read_events(int nlsk_fd, mlx5_nl_event_cb *cb, void *cb_arg) } return 0; } + +static int +mlx5_nl_esw_multiport_cb(struct nlmsghdr *nh, void *arg) +{ + + int ret = -EINVAL; + int *enable = arg; + struct nlattr *tail = RTE_PTR_ADD(nh, nh->nlmsg_len); + struct nlattr *nla = RTE_PTR_ADD(nh, NLMSG_ALIGN(sizeof(*nh)) + + NLMSG_ALIGN(sizeof(struct genlmsghdr))); + + while (nla->nla_len && nla < tail) { + switch (nla->nla_type) { + /* Expected nested attributes case. */ + case DEVLINK_ATTR_PARAM: + case DEVLINK_ATTR_PARAM_VALUES_LIST: + case DEVLINK_ATTR_PARAM_VALUE: + ret = 0; + nla += 1; + break; + case DEVLINK_ATTR_PARAM_VALUE_DATA: + *enable = 1; + return 0; + default: + nla = RTE_PTR_ADD(nla, NLMSG_ALIGN(nla->nla_len)); + } + } + *enable = 0; + return ret; +} + +#define NL_ESW_MULTIPORT_PARAM "esw_multiport" + +int +mlx5_nl_devlink_esw_multiport_get(int nlsk_fd, int family_id, const char *pci_addr, int *enable) +{ + struct nlmsghdr *nlh; + struct genlmsghdr *genl; + uint32_t sn = MLX5_NL_SN_GENERATE; + int ret; + uint8_t buf[NLMSG_ALIGN(sizeof(struct nlmsghdr)) + + NLMSG_ALIGN(sizeof(struct genlmsghdr)) + + NLMSG_ALIGN(sizeof(struct nlattr)) * 4 + + NLMSG_ALIGN(MLX5_NL_MAX_ATTR_SIZE) * 4]; + + memset(buf, 0, sizeof(buf)); + nlh = (struct nlmsghdr *)buf; + nlh->nlmsg_len = sizeof(struct nlmsghdr); + nlh->nlmsg_type = family_id; + nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK; + genl = (struct genlmsghdr *)nl_msg_tail(nlh); + nlh->nlmsg_len += sizeof(struct genlmsghdr); + genl->cmd = DEVLINK_CMD_PARAM_GET; + genl->version = DEVLINK_GENL_VERSION; + nl_attr_put(nlh, DEVLINK_ATTR_BUS_NAME, "pci", 4); + nl_attr_put(nlh, DEVLINK_ATTR_DEV_NAME, pci_addr, strlen(pci_addr) + 1); + nl_attr_put(nlh, DEVLINK_ATTR_PARAM_NAME, + NL_ESW_MULTIPORT_PARAM, sizeof(NL_ESW_MULTIPORT_PARAM)); + ret = mlx5_nl_send(nlsk_fd, nlh, sn); + if (ret >= 0) + ret = mlx5_nl_recv(nlsk_fd, sn, mlx5_nl_esw_multiport_cb, enable); + if (ret < 0) { + DRV_LOG(DEBUG, "Failed to get Multiport E-Switch enable on device %s: %d.", + pci_addr, ret); + return ret; + } + DRV_LOG(DEBUG, "Multiport E-Switch is %sabled for device \"%s\".", + *enable ? "en" : "dis", pci_addr); + return ret; +} diff --git a/drivers/common/mlx5/linux/mlx5_nl.h b/drivers/common/mlx5/linux/mlx5_nl.h index db01d7323e..580de3b769 100644 --- a/drivers/common/mlx5/linux/mlx5_nl.h +++ b/drivers/common/mlx5/linux/mlx5_nl.h @@ -71,6 +71,7 @@ __rte_internal uint32_t mlx5_nl_vlan_vmwa_create(struct mlx5_nl_vlan_vmwa_context *vmwa, uint32_t ifindex, uint16_t tag); +__rte_internal int mlx5_nl_devlink_family_id_get(int nlsk_fd); int mlx5_nl_enable_roce_get(int nlsk_fd, int family_id, const char *pci_addr, int *enable); @@ -82,4 +83,8 @@ int mlx5_nl_read_events(int nlsk_fd, mlx5_nl_event_cb *cb, void *cb_arg); __rte_internal int mlx5_nl_parse_link_status_update(struct nlmsghdr *hdr, uint32_t *ifindex); +__rte_internal +int mlx5_nl_devlink_esw_multiport_get(int nlsk_fd, int family_id, + const char *pci_addr, int *enable); + #endif /* RTE_PMD_MLX5_NL_H_ */ diff --git a/drivers/common/mlx5/version.map b/drivers/common/mlx5/version.map index 0758ba76de..074eed46fd 100644 --- a/drivers/common/mlx5/version.map +++ b/drivers/common/mlx5/version.map @@ -125,6 +125,8 @@ INTERNAL { mlx5_mr_addr2mr_bh; mlx5_nl_allmulti; # WINDOWS_NO_EXPORT + mlx5_nl_devlink_esw_multiport_get; # WINDOWS_NO_EXPORT + mlx5_nl_devlink_family_id_get; # WINDOWS_NO_EXPORT mlx5_nl_ifindex; # WINDOWS_NO_EXPORT mlx5_nl_init; # WINDOWS_NO_EXPORT mlx5_nl_mac_addr_add; # WINDOWS_NO_EXPORT -- 2.25.1