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 C1479A0C51; Wed, 21 Jul 2021 16:39:04 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 59BCE410E1; Wed, 21 Jul 2021 16:39:04 +0200 (CEST) Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2040.outbound.protection.outlook.com [40.107.236.40]) by mails.dpdk.org (Postfix) with ESMTP id DD840410DB for ; Wed, 21 Jul 2021 16:39:02 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=if9sQ3fL3SJCcMCQ+odHWryIKRaeLt48Wf7egXCcde5iuI2oKTRVRvRf94jY++ciEt8gJc1mZRt7b4O7NH8w14q0inqSPb4YHVoP7e0ylMRy3vOdRgkzvUL9TEZ1yFTmMnBcODupcF11sor1maEQRlf6YcPc5lu0hxTKeD+AlpIUfz9g3xB2R8XLZGPIhdpsNeEZb8W2vIlfPdDOJGsNrhm1gDNSSm/BrlNHsCEj4orVfaW0UHFv+8lqkXQryD9bgXu8Cp1P27hYXrJEeOTUKf27+CSxE6018gexPtVKfi7GTMD1KaIoBbQS2RbpIaBjA8mgqYpWv22YOWOqlvGDTg== 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=U3IsrHB9RAtOGxRs5J3xi6MtDZIhoUxBfEBFBApCmEY=; b=SlULtB2xkgm/7A1V+vcARCEmEb/SX8rXuDjKLY6NrOq0zj4+g0JW8wHFAdRTkG+01oOJolBQOEZrcnin3mkRMNSv2DWtcNlZRwu+LG87o5jhQq1mi3raXCI3KrJyEaUoHbA2OLVnzEkbVY3DTSupEmS6Au3VPy6CPsvpUTYACKl1DuaFl1MedBMhS/a9i/6QyA1ty868JGl8hjhKX7b3pHCnflyf3N8bMCCBTI1q46shtyc6qkcVHkxeiXCJrhs5OqgFm6rFO/eA9qUeLxk4hh5ZONMyUfC4OGlvJ2RUw353LEfVKuWrzFMdPFu8YryW3yJLoF0LeoYPyKOIlwB6Sg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=ashroe.eu smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none 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=U3IsrHB9RAtOGxRs5J3xi6MtDZIhoUxBfEBFBApCmEY=; b=nzDqSnatgjCnw8YtYJrVB5eFusL1rrHQuBOHfaMjd7xqyRsJM1eO2Kf9UxqOcSGOzZKGqM1DbTOEeIPjq/fNIkB3R2Sgba3WaDWtgaynwJ2VTTgiYhDYXOdSjAe584XPYujmlM3TxiP+U35XKvZ7x+3iR8dR8B7w0DmUiD+vlqwkWHNY6MPpy0+Hjxn1pBVCSndECFczc+hF/TXI0ctAksdpUK0lQYRMLeOSqp+Yq9FWMbpggoB4n1cqATGqo+eDiGyFvxVinleByxj57rkcvZ6Ky2z5XqxBJySYg0dBSiF26dDpWGHsjky5B3IHcErOUtfOBxGYDTltCYGblHf91w== Received: from BN9PR03CA0275.namprd03.prod.outlook.com (2603:10b6:408:f5::10) by BY5PR12MB3697.namprd12.prod.outlook.com (2603:10b6:a03:1a2::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.23; Wed, 21 Jul 2021 14:39:01 +0000 Received: from BN8NAM11FT005.eop-nam11.prod.protection.outlook.com (2603:10b6:408:f5:cafe::3d) by BN9PR03CA0275.outlook.office365.com (2603:10b6:408:f5::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.24 via Frontend Transport; Wed, 21 Jul 2021 14:39:01 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; ashroe.eu; dkim=none (message not signed) header.d=none;ashroe.eu; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by BN8NAM11FT005.mail.protection.outlook.com (10.13.176.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4352.24 via Frontend Transport; Wed, 21 Jul 2021 14:39:00 +0000 Received: from nvidia.com (172.20.187.5) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 21 Jul 2021 14:38:58 +0000 From: Xueming Li To: Viacheslav Ovsiienko CC: Thomas Monjalon , , , Matan Azrad , Shahaf Shuler , Ray Kinsella Date: Wed, 21 Jul 2021 22:37:32 +0800 Message-ID: <20210721143743.24626-6-xuemingl@nvidia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210721143743.24626-1-xuemingl@nvidia.com> References: <20210616040935.311733-1-xuemingl@nvidia.com> <20210721143743.24626-1-xuemingl@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [172.20.187.5] X-ClientProxiedBy: HQMAIL105.nvidia.com (172.20.187.12) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3704efa9-a8c9-4e16-a15a-08d94c5547ad X-MS-TrafficTypeDiagnostic: BY5PR12MB3697: X-LD-Processed: 43083d15-7273-40c1-b7db-39efd9ccc17a,ExtAddr X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:568; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MgUZtUjg38cvco78yfVsS6jiyryJzH4bs1DmAXJgLik3Tq7vKPsCNPndP//i63+lpyDssO5ulTesyb9ZA6eTjMUGIPY9S/Ulp0LCAWYMuU8d57BcvxUzl/V9MzVX5J9ESgF3RoheFkeM5SQo1HKpeceBVcNpAMFp9WhIRkB1Q7O1OO1jwkfuWPuQgBuVNQ6sfcqftTsZeSo1dqH9U3geULiEBGVamKs14jmqx2HkdzXoERUWIqnMgJzJhtC5ZZYq5IQ72K1p8miOdKoGhc+fyUKGqAVb6hgrtc/gvY4MdxfR4hy4mMKZRRUK3i7p6xVoA1PVGdtZ75TsD7AnOf8tbSfIDhu9JsCyYltGUL7s5hvOy1FpwTPg0opYeOA9piZqO6uucp8DSdn1NCvPvJvM28R6DtwPRtlcyUP1fMPB0JFIXbA4bSQi9+jd5sc3j/yRUwFwQiC0JXCkAQZT1lbsuszQSDJpYueacRJcnZpoilUnPmX8qiLlnYX7uxtxGwmkjteoVUc8C1ulFhsq6Z+EgC2/ualW6qowi/NsuBJwuXoGjLG0UlbUUR4biGS4dVTuVP7/7Ln6+q/Ya/2CAL5q8ASmA4taVi4JSSj/nlLMvoU2/JxBLs6VS/dDh40vL/anIlsRkAFHkzQKMyiBgkFP0XXg9PU++jAMUSOfH7dEmbBp5lz/+Pe1U4f4uM+uWMtD4emm5uxUETC3xrualNia9g== X-Forefront-Antispam-Report: CIP:216.228.112.34; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid03.nvidia.com; CAT:NONE; SFS:(4636009)(376002)(346002)(39860400002)(136003)(396003)(36840700001)(46966006)(82310400003)(316002)(37006003)(83380400001)(6286002)(8936002)(36906005)(336012)(16526019)(426003)(1076003)(186003)(2616005)(70206006)(47076005)(478600001)(55016002)(54906003)(70586007)(356005)(7636003)(26005)(4326008)(36860700001)(5660300002)(86362001)(2906002)(6862004)(36756003)(7696005)(6666004)(8676002)(82740400003)(6636002); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jul 2021 14:39:00.6509 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3704efa9-a8c9-4e16-a15a-08d94c5547ad X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.34]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT005.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB3697 Subject: [dpdk-dev] [PATCH v4 05/16] common/mlx5: get PCI device address from any bus 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 Sender: "dev" From: Thomas Monjalon A function is exported to allow retrieving the PCI address of the parent PCI device of a Sub-Function in auxiliary bus sysfs. The function mlx5_dev_to_pci_str() is accepting both PCI and auxiliary devices. In case of a PCI device, it is simply using the device name. The function mlx5_dev_to_pci_addr(), which is based on sysfs path and do not use any device object, is renamed to mlx5_get_pci_addr() for clarity purpose. Signed-off-by: Thomas Monjalon Acked-by: Viacheslav Ovsiienko --- .../common/mlx5/linux/mlx5_common_auxiliary.c | 19 +++++++++++++++ drivers/common/mlx5/linux/mlx5_common_os.c | 5 ++-- drivers/common/mlx5/mlx5_common.c | 23 +++++++++++++++++++ drivers/common/mlx5/mlx5_common.h | 16 ++++++++++++- drivers/common/mlx5/mlx5_common_private.h | 2 ++ drivers/common/mlx5/version.map | 3 ++- drivers/net/mlx5/linux/mlx5_os.c | 6 ++--- 7 files changed, 66 insertions(+), 8 deletions(-) diff --git a/drivers/common/mlx5/linux/mlx5_common_auxiliary.c b/drivers/common/mlx5/linux/mlx5_common_auxiliary.c index 4ca27cd281..6584aeb18e 100644 --- a/drivers/common/mlx5/linux/mlx5_common_auxiliary.c +++ b/drivers/common/mlx5/linux/mlx5_common_auxiliary.c @@ -4,6 +4,8 @@ #include #include +#include + #include #include #include @@ -66,6 +68,23 @@ mlx5_auxiliary_get_pci_path(const struct rte_auxiliary_device *dev, return 0; } +int +mlx5_auxiliary_get_pci_str(const struct rte_auxiliary_device *dev, + char *addr, size_t size) +{ + char sysfs_pci[PATH_MAX]; + char *base; + + if (mlx5_auxiliary_get_pci_path(dev, sysfs_pci, sizeof(sysfs_pci)) != 0) + return -ENODEV; + base = basename(sysfs_pci); + if (base == NULL) + return -errno; + if (rte_strscpy(addr, base, size) < 0) + return -rte_errno; + return 0; +} + static int mlx5_auxiliary_get_numa(const struct rte_auxiliary_device *dev) { diff --git a/drivers/common/mlx5/linux/mlx5_common_os.c b/drivers/common/mlx5/linux/mlx5_common_os.c index 337e9df8cb..9e0c823c97 100644 --- a/drivers/common/mlx5/linux/mlx5_common_os.c +++ b/drivers/common/mlx5/linux/mlx5_common_os.c @@ -24,8 +24,7 @@ const struct mlx5_glue *mlx5_glue; #endif int -mlx5_dev_to_pci_addr(const char *dev_path, - struct rte_pci_addr *pci_addr) +mlx5_get_pci_addr(const char *dev_path, struct rte_pci_addr *pci_addr) { FILE *file; char line[32]; @@ -417,7 +416,7 @@ mlx5_os_get_ibv_device(const struct rte_pci_addr *addr) struct rte_pci_addr paddr; DRV_LOG(DEBUG, "Checking device \"%s\"..", ibv_list[n]->name); - if (mlx5_dev_to_pci_addr(ibv_list[n]->ibdev_path, &paddr) != 0) + if (mlx5_get_pci_addr(ibv_list[n]->ibdev_path, &paddr) != 0) continue; if (rte_pci_addr_cmp(addr, &paddr) != 0) continue; diff --git a/drivers/common/mlx5/mlx5_common.c b/drivers/common/mlx5/mlx5_common.c index 94f858a9bd..8fe36f7077 100644 --- a/drivers/common/mlx5/mlx5_common.c +++ b/drivers/common/mlx5/mlx5_common.c @@ -197,6 +197,29 @@ to_mlx5_device(const struct rte_device *rte_dev) return NULL; } +int +mlx5_dev_to_pci_str(const struct rte_device *dev, char *addr, size_t size) +{ + struct rte_pci_addr pci_addr = { 0 }; + int ret; + + if (mlx5_dev_is_pci(dev)) { + /* Input might be , format PCI address to . */ + ret = rte_pci_addr_parse(dev->name, &pci_addr); + if (ret != 0) + return -ENODEV; + rte_pci_device_name(&pci_addr, addr, size); + return 0; + } +#ifdef RTE_EXEC_ENV_LINUX + return mlx5_auxiliary_get_pci_str(RTE_DEV_TO_AUXILIARY_CONST(dev), + addr, size); +#else + rte_errno = ENODEV; + return -rte_errno; +#endif +} + static void dev_release(struct mlx5_common_device *dev) { diff --git a/drivers/common/mlx5/mlx5_common.h b/drivers/common/mlx5/mlx5_common.h index 3cb961f495..66c83047a1 100644 --- a/drivers/common/mlx5/mlx5_common.h +++ b/drivers/common/mlx5/mlx5_common.h @@ -210,6 +210,20 @@ check_cqe(volatile struct mlx5_cqe *cqe, const uint16_t cqes_n, return MLX5_CQE_STATUS_SW_OWN; } +/* + * Get PCI address string from EAL device. + * + * @param[out] addr + * The output address buffer string + * @param[in] size + * The output buffer size + * @return + * - 0 on success. + * - Negative value and rte_errno is set otherwise. + */ +__rte_internal +int mlx5_dev_to_pci_str(const struct rte_device *dev, char *addr, size_t size); + /* * Get PCI address from sysfs of a PCI-related device. * @@ -224,7 +238,7 @@ check_cqe(volatile struct mlx5_cqe *cqe, const uint16_t cqes_n, * - Negative value and rte_errno is set otherwise. */ __rte_internal -int mlx5_dev_to_pci_addr(const char *dev_path, struct rte_pci_addr *pci_addr); +int mlx5_get_pci_addr(const char *dev_path, struct rte_pci_addr *pci_addr); /* * Get kernel network interface name from sysfs IB device path. diff --git a/drivers/common/mlx5/mlx5_common_private.h b/drivers/common/mlx5/mlx5_common_private.h index 9f00a6c54d..1096fa85e7 100644 --- a/drivers/common/mlx5/mlx5_common_private.h +++ b/drivers/common/mlx5/mlx5_common_private.h @@ -39,6 +39,8 @@ bool mlx5_dev_pci_match(const struct mlx5_class_driver *drv, void mlx5_common_auxiliary_init(void); struct ibv_device *mlx5_get_aux_ibv_device( const struct rte_auxiliary_device *dev); +int mlx5_auxiliary_get_pci_str(const struct rte_auxiliary_device *dev, + char *addr, size_t size); #ifdef __cplusplus } diff --git a/drivers/common/mlx5/version.map b/drivers/common/mlx5/version.map index b47d73b425..a47c86e354 100644 --- a/drivers/common/mlx5/version.map +++ b/drivers/common/mlx5/version.map @@ -15,7 +15,7 @@ INTERNAL { mlx5_create_mr_ext; mlx5_dev_is_pci; # WINDOWS_NO_EXPORT - mlx5_dev_to_pci_addr; # WINDOWS_NO_EXPORT + mlx5_dev_to_pci_str; # WINDOWS_NO_EXPORT mlx5_devx_alloc_uar; # WINDOWS_NO_EXPORT @@ -75,6 +75,7 @@ INTERNAL { mlx5_free; mlx5_get_ifname_sysfs; # WINDOWS_NO_EXPORT + mlx5_get_pci_addr; # WINDOWS_NO_EXPORT mlx5_glue; diff --git a/drivers/net/mlx5/linux/mlx5_os.c b/drivers/net/mlx5/linux/mlx5_os.c index aa5210fa45..05b1761f6b 100644 --- a/drivers/net/mlx5/linux/mlx5_os.c +++ b/drivers/net/mlx5/linux/mlx5_os.c @@ -1995,7 +1995,7 @@ mlx5_device_bond_pci_match(const struct ibv_device *ibv_dev, /* Process slave interface names in the loop. */ snprintf(tmp_str, sizeof(tmp_str), "/sys/class/net/%s", ifname); - if (mlx5_dev_to_pci_addr(tmp_str, &pci_addr)) { + if (mlx5_get_pci_addr(tmp_str, &pci_addr)) { DRV_LOG(WARNING, "can not get PCI address" " for netdev \"%s\"", ifname); continue; @@ -2172,8 +2172,8 @@ mlx5_os_pci_probe_pf(struct rte_pci_device *pci_dev, break; } else { /* Bonding device not found. */ - if (mlx5_dev_to_pci_addr - (ibv_list[ret]->ibdev_path, &pci_addr)) + if (mlx5_get_pci_addr(ibv_list[ret]->ibdev_path, + &pci_addr)) continue; if (owner_pci.domain != pci_addr.domain || owner_pci.bus != pci_addr.bus || -- 2.25.1