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 9DF5EA0C45; Mon, 19 Jul 2021 04:55:27 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8B769410FC; Mon, 19 Jul 2021 04:55:27 +0200 (CEST) Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2077.outbound.protection.outlook.com [40.107.236.77]) by mails.dpdk.org (Postfix) with ESMTP id C854F40E46 for ; Mon, 19 Jul 2021 04:55:25 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Yb+UsPA7hQIEDTAp2SIAiC96PZwmYioPBjzzHUL4VkCPXS9x8CdTqQc6LIRW56CxXNMtUPp2P1Wyy3iF1nFKaqxx9NR6guZ/PPa8TMAgBjd4SPHaIRVs2jZV8RM8RZ0EEp+quoMrDIhw1mCb6oFyCckRsbfQk5eub9KGqaBtiD68N3cHsVzbNt8Zk+y+sHZn/8KTEwdCe8ZApZ/hrq7ozCIEKh8WsyC3tmqLLLn5hQ/20Ov5gv+PX84NPvFxWghb7GfEZ+bcQWGQZlvamO2xCGgNxBpd4HFzRgZOZWtV/RNAkczema8xQ2d0h1AXRoaCjodvI59pjGPIVBbSYtDjdA== 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=2+44jL2AC6vkvM40Nt348PGgLrZLT2FS5c93rDZ04yo=; b=eGoSybR//CMVur5L/u68KNY/pvkNaNb6Vtn3YDPx553ywvJll11/r9xDe4l2s8MktlbNY01IGMNNNHusM7BurZ8kpnudXXHlkAv80q7JXVHSjJPxE7OEpGaKC5agp267zRwXqWHDXQi8bAlFgjS65U+ZnJhIxshsNSARrfZ64dBcSMVfeZOaU8/ugTWIrCdV6f0wAoFAGloh7TtBk/MKxnlM7i82lsLSTwaivQjPaf2IyHDbhSFO6dOlSup3xTgU/J6A5jcxLxKkWMZB9zCqYx1MUa93XbUgnz1bn/5se8UKrtAkxWHpcqUX18bzVH8AE6kurzAZ45Q0AmLjZvgtqw== 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=2+44jL2AC6vkvM40Nt348PGgLrZLT2FS5c93rDZ04yo=; b=jiKI6o3/gt5tAQpqO1Dz+WVPB4j9tvw5cqkSjBYCRzL+bhaDkFhCvxCNJuoLuzUa4XQtYJxEdzwQexROY8PM/s4AOSwM6Un+Lm61dV6BtKJCAnoe+sOzMEoo3/MuzIGwfU3Q+Bv62rMPrOm3hi8/kX2gmgxXNzis5MdvI2wPAf/f/m+hbdTJtTzpZDRtdyMjCdDkMfzbY+rtFXQowYoHZUR/bafEr21+AfvbRIDYL+n7AUFgIv3c34szLpE1REkhmTjJTTOSJI0YUWMBlMagxvWQCHGUXnaV9kXakzifNILrWP138s4dwod7YQdnQxU7ogrlYrTwjZ1HSYUs9XMyvQ== Received: from MW4PR04CA0084.namprd04.prod.outlook.com (2603:10b6:303:6b::29) by CY4PR1201MB0039.namprd12.prod.outlook.com (2603:10b6:910:1e::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.29; Mon, 19 Jul 2021 02:55:23 +0000 Received: from CO1NAM11FT006.eop-nam11.prod.protection.outlook.com (2603:10b6:303:6b:cafe::29) by MW4PR04CA0084.outlook.office365.com (2603:10b6:303:6b::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21 via Frontend Transport; Mon, 19 Jul 2021 02:55:23 +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 CO1NAM11FT006.mail.protection.outlook.com (10.13.174.246) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4331.21 via Frontend Transport; Mon, 19 Jul 2021 02:55:22 +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; Mon, 19 Jul 2021 02:55:20 +0000 From: Xueming Li To: Viacheslav Ovsiienko CC: Thomas Monjalon , , , Matan Azrad , Shahaf Shuler , Ray Kinsella Date: Mon, 19 Jul 2021 10:54:00 +0800 Message-ID: <20210719025410.15483-6-xuemingl@nvidia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210713131437.30170-2-xuemingl@nvidia.com> References: <20210713131437.30170-2-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: ac5b08c2-e303-4bf6-1429-08d94a60a701 X-MS-TrafficTypeDiagnostic: CY4PR1201MB0039: 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: 3V2cBeTuZ/a5yUlCIlWUCbHXLBz6LWzm4y2OMKoLaddZ0Dr3IPZbJKMc1wI+Tc56CRvhItC4z9SO0wG7863/c+JzED/FlH3515ZzGt50/FAMJyTAnSSnXgIStTu2s+887vWYSK0nYMUllpDvfqmIgXY8BstePyvPiS6nzURDVe2+KATI+u0CAQL2NsE7SStHkEy0g9jKgz7GennJ9TTx16LEKpyo9/3B0vl7rt5R1qngQUIUSHj80AW7v1Rr/WJGjiAm3jW8k3Y/3wPsUYtI9EH4+2swVpUOrhQ3U5vIPOpZdfn6PorV3kufYfZd9llm5cmPjGWlf7jOUcEHtwXiwy7I2nxM38MxrwXJgVlLD4YULxS4DX3X8tsjzHfPoP5EzBzfomzeRJOZnRnXA8h44XALgbTlkiXzWcF4MM6GPKINYpLp+PKDx9oWecLl9+N75g5KsueQpSMzgxwtAvA4xeiMY5xz6Er6hKpQCeZgBwQyRROvpMVFZBz7jElXpPjugZIj7IbqEErRfdEK4NBKAsGy6nU9nWiAnJpxqhKhDh0rFgHn1KNKtdcr9ADlYfymXBaROGYnpRqlzol1dgVkM8LA62Xjj3bLHtyHaF+bFev33rSbg6eL3Ra9bb2wGs9jC9KkCDqc1dw/733ndBWDkp7NY3APb5e5myD/YK1bFnHsdgE7qwTMblLYedRDutby3rWUMAF/u0+jzMzEvmEyIg== 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)(36840700001)(46966006)(54906003)(6636002)(36860700001)(83380400001)(70586007)(47076005)(86362001)(8676002)(7636003)(356005)(5660300002)(6862004)(1076003)(2906002)(26005)(16526019)(36906005)(82310400003)(8936002)(7696005)(316002)(70206006)(36756003)(4326008)(2616005)(336012)(6666004)(186003)(6286002)(55016002)(508600001)(426003)(37006003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jul 2021 02:55:22.7718 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ac5b08c2-e303-4bf6-1429-08d94a60a701 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: CO1NAM11FT006.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR1201MB0039 Subject: [dpdk-dev] [PATCH v3 05/15] 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 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 6544e664ce..c258cd127a 100644 --- a/drivers/common/mlx5/mlx5_common.c +++ b/drivers/common/mlx5/mlx5_common.c @@ -196,6 +196,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 5a027903b3..26d1b58853 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