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 0E9A543252; Tue, 31 Oct 2023 15:28:22 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CA86240A81; Tue, 31 Oct 2023 15:28:17 +0100 (CET) Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam02on2041.outbound.protection.outlook.com [40.107.212.41]) by mails.dpdk.org (Postfix) with ESMTP id 7FD2A40A7F for ; Tue, 31 Oct 2023 15:28:16 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=R81e+0mXltx7HBT5t0iGEhNoBgxABVtgZRWx6C9v5gT3VFfu143GlKB/Zp89/L7E4BVd0ZOsdh3Fgv5pVD7wdqwg1fqlnV+ds/nkr23Oqomjj732nvu2qBwdBgSuAZ3qAN0km02kc5CxeWILoyrLZvpvolq2z0B97SUCvU26oapJ7gLnPEg316D09H7Y4iPnVcHce72FL7ppB/HEgZDPxJNSe6X/+xc7LzRVn0hjGFJAaQav+CGrA1WUg4dox5yV9/ijg9q5R7DBdW4QFMI0WU2miruio3ic7v6u74+lUupKxKHBKtligszG326OrMROtk8xfr7qVPWR7cApNX8wrw== 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=zOKjEQafrLqsslnyzkHPVnIJ/xff7ZrPPWuQ4NnbUBY=; b=FrElpFxjik6WJIXZOLyk2Sk/BRKV2cdWU1XJaj7TtUG30fyI50wyblmpuq4pBd73er3VvnoAgO5qwXNFn5UTdsKvPpGRUxDGIr6qKU26L2M1SPdg5wx1ScwbvOPuPH0krBwlHRuQ+DEuTwj4Al8Y/PbBaObyLMG76J9qlZpF/h5zIkPqNN6VeDNX/HszEhzLu7usQKorbf7PreZlkwqotSDZGpwNBTWFz0ZkGd12T2tWVAfdZRTJ/mKc3kb5t6XRUZGuHytmP+xMZmZbGl+Qijil3N6JOSsbJ09Q7UrP2QRf/E/29eTLuQUFythxc4Y3XQkBmSmYFJUW5n/sISriIg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) 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=zOKjEQafrLqsslnyzkHPVnIJ/xff7ZrPPWuQ4NnbUBY=; b=JDXXEl8zjJmIa41UmI6GOVIiNbxE80JAJVIj5r99p52P3cyuqk06LsUtsTyqh28XFopK9lsteri3wYe8GAp9ZCMzd2Tru3Rihto+hifeJ7EQkbFJJTgnwrhmoEN2XsyvRQGNTmoDSgkE4LqZrBX3s0W1Xif+fZsN98d4nY7/CUdlnxgTIqRMeT60BffO9WGdSNGUufLAWsS2c4bzU+hpgKixtTebzy4J7w2OTse2KEvsUMjzvhm9h7jZNpA89Q7rjVH2+xUciXLleTcxN0a/8nj9dz+CuYfhKHwNBj6Qtxjq8HTTv/S6/+MF8LBDZ+HlEDShFI/IIzHVqyxErrmr+w== Received: from DS7PR03CA0296.namprd03.prod.outlook.com (2603:10b6:5:3ad::31) by CY8PR12MB7756.namprd12.prod.outlook.com (2603:10b6:930:85::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.28; Tue, 31 Oct 2023 14:28:14 +0000 Received: from CY4PEPF0000EDD3.namprd03.prod.outlook.com (2603:10b6:5:3ad:cafe::60) by DS7PR03CA0296.outlook.office365.com (2603:10b6:5:3ad::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.29 via Frontend Transport; Tue, 31 Oct 2023 14:28:14 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) 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.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by CY4PEPF0000EDD3.mail.protection.outlook.com (10.167.241.207) 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:14 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) 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:28:03 -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:28:01 -0700 From: Dariusz Sosnowski To: Matan Azrad , Viacheslav Ovsiienko , Ori Kam , Suanming Mou CC: , Raslan Darawsheh Subject: [PATCH 5/8] net/mlx5: add checking Multiport E-Switch state Date: Tue, 31 Oct 2023 16:27:30 +0200 Message-ID: <20231031142733.2009166-6-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: CY4PEPF0000EDD3:EE_|CY8PR12MB7756:EE_ X-MS-Office365-Filtering-Correlation-Id: 8bf4fa95-d234-4f78-1a83-08dbda1d9e0f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4tw8FZk2e4qF/jlmBY2Xep1IvBqouFgBKPRXYnn7ZdoHsRgX3+DBnedCo/dqByS0xcuTzMj3p7OcGz1NriwmgFDuudmaVFM0h0/GaboK/hAax1y2IxjbETz2OkOGWOVtBKjM7l2li+wJD8XvoakGyp8OQBLMYITOrJDl32KkCvi/PqOhuf6MNK0Aro9j0e7hfTpIpsqVPp8+YEZF0KzrQfi75xhdf48Zuo+KD3+2aNTLcDOe7tXifawdGktFKOLBgSq5E9w0aU7u8T99UZiKae/dmS4yV7R6HlmtuqVdhLN9GY6SCOI9kztOjuvnnW/XFFJDxtexO7I3GMrKZbAVkDAUfTv2V7gZIyvGUWZC6p6y3t5atoPf8yCTSMUFyRkNXZsiWhVSgeeoRRzrLtVl3XniTRVMB5Rq4/WSmi6OACej5KYsz4G893sDozSCeTORskGwGWQzrSdnNACCMKvHHzX9/oat7y6RjbzbcYp0I/sCRsJbG2+AvqWUDsG/GouAjQDnMDcLpC1wAnHNGlcCqUAlDHCgic5uEfb5jSO+tjbvvyBLShAmUxk//4DyIGlZDDubjcghYoZekaXsDPfW1BuXg+dix75rR8S4vfwUBwLLrVWEhH4IFLTFem8ZaKpAt44TqZo9BQygpl2Y/JCaFdG8tY+fBQ/Vbg6taMPl4fBHe9Bb4GCEYDZsbGAcluWBoPt0lfrIS5uy5s0rPUoOrwR8azb4jceH+aDj9etxgAQLmShbKjUiSKUKqJnHpoE/ X-Forefront-Antispam-Report: CIP:216.228.117.161; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge2.nvidia.com; CAT:NONE; SFS:(13230031)(4636009)(346002)(39860400002)(136003)(376002)(396003)(230922051799003)(451199024)(1800799009)(82310400011)(64100799003)(186009)(36840700001)(46966006)(40470700004)(40480700001)(55016003)(40460700003)(6286002)(2616005)(1076003)(26005)(16526019)(478600001)(6666004)(7696005)(36860700001)(426003)(336012)(47076005)(83380400001)(2906002)(70586007)(110136005)(41300700001)(70206006)(107886003)(8676002)(4326008)(54906003)(316002)(6636002)(5660300002)(8936002)(356005)(7636003)(82740400003)(86362001)(36756003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Oct 2023 14:28:14.2660 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8bf4fa95-d234-4f78-1a83-08dbda1d9e0f 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.161]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EDD3.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7756 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. mlx5_is_mpesw_enabled() implements this functionality and it will be used in a follow up commit. mlx5_is_mpesw_enabled() first checks if E-Switch state can be probed using Devlink device parameter. If it cannot be checked or there was an error, then sysfs interface will be probed. If that fails, mlx5_is_mpesw_enabled() assumes that Multiport E-Switch is disabled and returns an error. Signed-off-by: Dariusz Sosnowski Acked-by: Viacheslav Ovsiienko --- drivers/net/mlx5/linux/mlx5_os.c | 51 +++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/drivers/net/mlx5/linux/mlx5_os.c b/drivers/net/mlx5/linux/mlx5_os.c index 7a656a7237..8a57edc470 100644 --- a/drivers/net/mlx5/linux/mlx5_os.c +++ b/drivers/net/mlx5/linux/mlx5_os.c @@ -1931,9 +1931,38 @@ mlx5_device_bond_pci_match(const char *ibdev_name, return pf; } +static int +mlx5_nl_esw_multiport_get(struct rte_pci_addr *pci_addr, int *enabled) +{ + char pci_addr_str[PCI_PRI_STR_SIZE] = { 0 }; + int nlsk_fd; + int devlink_id; + int ret; + + /* Provide correct value to have defined enabled state in case of an error. */ + *enabled = 0; + rte_pci_device_name(pci_addr, pci_addr_str, sizeof(pci_addr_str)); + nlsk_fd = mlx5_nl_init(NETLINK_GENERIC, 0); + if (nlsk_fd < 0) + return nlsk_fd; + devlink_id = mlx5_nl_devlink_family_id_get(nlsk_fd); + if (devlink_id < 0) { + ret = devlink_id; + DRV_LOG(DEBUG, "Unable to get devlink family id for Multiport E-Switch checks " + "by netlink, for PCI device %s", pci_addr_str); + goto close_nlsk_fd; + } + ret = mlx5_nl_devlink_esw_multiport_get(nlsk_fd, devlink_id, pci_addr_str, enabled); + if (ret < 0) + DRV_LOG(DEBUG, "Unable to get Multiport E-Switch state by Netlink."); +close_nlsk_fd: + close(nlsk_fd); + return ret; +} + #define SYSFS_MPESW_PARAM_MAX_LEN 16 -static __rte_unused int +static int mlx5_sysfs_esw_multiport_get(struct ibv_device *ibv, struct rte_pci_addr *pci_addr, int *enabled) { int nl_rdma; @@ -2000,6 +2029,26 @@ mlx5_sysfs_esw_multiport_get(struct ibv_device *ibv, struct rte_pci_addr *pci_ad return ret; } +static __rte_unused int +mlx5_is_mpesw_enabled(struct ibv_device *ibv, struct rte_pci_addr *ibv_pci_addr, int *enabled) +{ + /* + * Try getting Multiport E-Switch state through netlink interface + * If unable, try sysfs interface. If that is unable as well, + * assume that Multiport E-Switch is disabled and return an error. + */ + if (mlx5_nl_esw_multiport_get(ibv_pci_addr, enabled) >= 0 || + mlx5_sysfs_esw_multiport_get(ibv, ibv_pci_addr, enabled) >= 0) + return 0; + DRV_LOG(DEBUG, "Unable to check MPESW state for IB device %s " + "(PCI: " PCI_PRI_FMT ")", + ibv->name, + ibv_pci_addr->domain, ibv_pci_addr->bus, + ibv_pci_addr->devid, ibv_pci_addr->function); + *enabled = 0; + return -rte_errno; +} + /** * Register a PCI device within bonding. * -- 2.25.1