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 0AD92A0C45; Wed, 16 Jun 2021 06:10:24 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 047DC410FC; Wed, 16 Jun 2021 06:10:03 +0200 (CEST) Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2071.outbound.protection.outlook.com [40.107.94.71]) by mails.dpdk.org (Postfix) with ESMTP id 0AD12410FB for ; Wed, 16 Jun 2021 06:10:02 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=W7u8T+CTRmvLHubCGgiGWqLAwQ5Yvt6R2zNUjgfzwTxEujm7bL1a8GS95UvhETH8OVCP+VkGKI5zV0EBBOUb4SXtQGOQFi3XwWV4QZoxyoSLX1CfxQa5EeWmE87MXLlFgFjBEe2KjC4K8XZ9r8Tn4gRu4eiDjakygNDf6KoNUuswbrOpPET19+ljZob2WtAgRo0FGTa0LlWsk8QVcedxZ9ZBMn8mp0h5tyRP5Y7A+lQV/ORlWcAu/qBI1sryWp7utfFPXbtb7xKxddHjd3vn+O8pzLWgp0WcyDFxeEs3HEEp/CzmdHfLSp3vlHI081s9dM1x29wDe0X4Ae6CAJd4gw== 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=g5+gWEMH9BBbVC3em1aSIYobdQWex94Kb/cAd1rAmGE=; b=lm7aUA3k+Kc6oiX+MW2kDWCaba5xkNWDMh0OlirLjSZ9kCKGAr0HZPj6E7uSDIY8R+3TGTq73RSVHp5Ij2XmmQLIrKnGKPQEW+WibXdyN8Zy38GdIOFh4dcVNKiDWw8ySFFJUhz6dxV87idCznEsE/oPAz03R8yyO1vdR28bHsTTrye5VDyva4ISWURy4+qqfME+JnqIcrIRmvzn42S3KKoxb890XZyBaipUC534UO0uI4eKH1LhwGV40V0FXs1oO5UPpCcjI457IgBO3vHcYwhPoB88BGND06KGjEqTrLehmsXA7VvBuqOvbxcYSQMHgc+I15dskLtGCcEAho7/Ng== 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=none 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=g5+gWEMH9BBbVC3em1aSIYobdQWex94Kb/cAd1rAmGE=; b=Ci/20FfrsLGvazYXqKwxl1tc6eiPP/0rt8PwmQE3f5ZRF1rX2MlmS0SJfeQTNBe7cfBHorAtXucCmUYLkCdAXVscVvq1oGWMyZ8+daAFsoCRiAmiwYhO+wX6EFBKEO535G49QN/vQUSpm5lisyzL40kYtnVudHiahL7ubK/Bqt8pIZifDRtU0VR+SIDO5xoPn217g71r3zB2N1Yk+4GFE+lK/aT2F7tHHbE6S3LVDPGyIn7D+QngOif3x7g3ceNdNccQeM76IDZoSMVCwEhD2S/R7H2s5wX5cgNnrZjkje4XS1tgpQg4lJxOWs7udXY+h+1MYZn6i1YirM/EZBLWdg== Received: from DM6PR06CA0101.namprd06.prod.outlook.com (2603:10b6:5:336::34) by MWHPR12MB1198.namprd12.prod.outlook.com (2603:10b6:300:d::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4219.24; Wed, 16 Jun 2021 04:10:00 +0000 Received: from DM6NAM11FT031.eop-nam11.prod.protection.outlook.com (2603:10b6:5:336:cafe::28) by DM6PR06CA0101.outlook.office365.com (2603:10b6:5:336::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4219.21 via Frontend Transport; Wed, 16 Jun 2021 04:10:00 +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 DM6NAM11FT031.mail.protection.outlook.com (10.13.172.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4242.16 via Frontend Transport; Wed, 16 Jun 2021 04:09:59 +0000 Received: from nvidia.com (172.20.187.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 16 Jun 2021 04:09:57 +0000 From: Xueming Li To: Viacheslav Ovsiienko CC: Thomas Monjalon , , , Matan Azrad , Shahaf Shuler , Ray Kinsella , Neil Horman Date: Wed, 16 Jun 2021 07:09:25 +0300 Message-ID: <20210616040935.311733-5-xuemingl@nvidia.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210527133759.17401-2-xuemingl@nvidia.com> References: <20210527133759.17401-2-xuemingl@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [172.20.187.6] X-ClientProxiedBy: HQMAIL111.nvidia.com (172.20.187.18) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c62a2125-aabc-40e8-1fc5-08d9307c9bde X-MS-TrafficTypeDiagnostic: MWHPR12MB1198: 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-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: q/MmiNkke5Om+wO1AqlxdFntpXRfF0bPhXrkkosGg7+BnkRuehq8zh8HtjR4U5SkE6HlSDjBFkA1ZLGY6CKL9dZcYexDxhMlEFXKEYt1UFDffDmut64zxH3l+EtF1xNmEQMTENxyL9s5JNQnPHj+1EhbzD69Gx4BCTBuWqH9GmEeEpmOZanNYi4OC94ydEKoOHUaY9+3B2LVdd5MKApoJg3WGDMFL9ukzKlPOsp17D32Kd09QKJcNqYeVR1nvTRppf0KkGXbiTg5gc+5nRzkiGnTfliPUtLmn7FYa2VZtjZ1hnrHJY5YXTiEK93lNi9a/0hws4dgVhc7RVDRtlJ973Fv3y+A8H/rDM/PpvUv4hyCTdRQ1BOsSIcqZobNHsSGY6lYXueLJb6Fvzsv2fCA+79fMeTVNCRVe9KtRZUACQQJm/fmG+ed5RaF3SFP5s7W38p/9Ct5O34KmzSaDP1DJWiHA7cf3J7SjS94VjsLSNdRDIeT32Yp/VpFJ2uMeIyso4TYOc1AuFzMBCpGkgcE+HMnxxv2gMlD7fJJNrLz2o1zCA76oeD7uCWpXXr7fkP3yNdklJ3UPKHFynjBs+mSMYiQaOO3IRrv+SGR1i2LQ0A8vDy3kK5Ipg1ECEgoE5v/8XCsHpc+gzhKzUU7LCe5/w== 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)(39860400002)(136003)(376002)(396003)(346002)(46966006)(36840700001)(86362001)(7696005)(37006003)(83380400001)(6636002)(478600001)(2906002)(36756003)(55016002)(54906003)(82740400003)(26005)(316002)(186003)(16526019)(1076003)(36906005)(8676002)(6862004)(356005)(2616005)(70206006)(7636003)(70586007)(6666004)(5660300002)(47076005)(82310400003)(36860700001)(4326008)(336012)(426003)(8936002)(6286002); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jun 2021 04:09:59.7650 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c62a2125-aabc-40e8-1fc5-08d9307c9bde 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: DM6NAM11FT031.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1198 Subject: [dpdk-dev] [PATCH v1 04/14] 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 --- .../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 79d567087c..aaa2407ded 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 b4ca0a9fe1..4ff13cb461 100644 --- a/drivers/common/mlx5/mlx5_common.c +++ b/drivers/common/mlx5/mlx5_common.c @@ -198,6 +198,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 439f16cde1..7d7b896517 100644 --- a/drivers/common/mlx5/mlx5_common.h +++ b/drivers/common/mlx5/mlx5_common.h @@ -208,6 +208,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. * @@ -222,7 +236,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 edfd3792e0..ea4c49b7e7 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 54e4a1fe60..78e101d649 100644 --- a/drivers/net/mlx5/linux/mlx5_os.c +++ b/drivers/net/mlx5/linux/mlx5_os.c @@ -1848,7 +1848,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; @@ -2025,8 +2025,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