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 F1984A0C4C; Tue, 28 Sep 2021 10:35:07 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CB84F410E6; Tue, 28 Sep 2021 10:24:18 +0200 (CEST) Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2063.outbound.protection.outlook.com [40.107.220.63]) by mails.dpdk.org (Postfix) with ESMTP id 04858410E6 for ; Tue, 28 Sep 2021 10:24:17 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=m2Br7zOk4u+xsHpqC9yFttX6SjB32RdmAfvnmxYB84+kZsVKoGHkRt+au5hQfiT7pqKZndVmnFGNhrqT5GcJUiMFrjWAeGAoySh2a2N/LW5WX1F4gvCOJXBOkolE3Imfw6da6/G3hcIGtMJroyaO+3Hd2+n08CWMjQ/ISSGATz/3pzLqGpo8xadlN2GsDNrFMsM30L5J0w76/05EH4xyDEC6n3K5Jpad2i6YNHuR1lMrmw0qUZKgi9U8yyp5V9SRA6RCOGh6kDHSWE4/gKV0XaxgTUTq2Qs29R6x1vv1e81DV1hC1Vz2+4jCmdvQJVsPo88aLcQ+JaEJnpjyPr/R9g== 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; bh=Pus5Ss3hfBmTz9SGmxXLaIpDOaeEAabjpQfXvnQcpnI=; b=BeoLzz2bp07GFbBDMHh+ome5Rxqvf34ZXnWmYr0ssZ15uzJxdXEeTDZsZgCq9Qc/NWaZx9Mw7EtUxn1bEBWBxTgH8P/kqrevFDAImlcuPSempN9o4B8SZ6GGQGzUwEgxh4piJKz98c6hT7LSPcSt1WaFeTAMRubVR04IyTP7o/jdIlVe+EM7Hvtwy/01SSZvNd5gmAkrXiB+afwsebyn8jKAbD1YLpTkKGQcOHQUa3mMPiLLP7XN2P7ztGBxcisqcSHzQkwJEPNZBENEOYee/DOTE444FCbsVn4DJJrHlnLb1NRot3iuRQyXQ5yxazKG/FYMk2XDFwR5AM+be0uEPQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.36) smtp.rcpttodomain=dpdk.org 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=Pus5Ss3hfBmTz9SGmxXLaIpDOaeEAabjpQfXvnQcpnI=; b=EzxmzBOkQSuo87sTFjypo2wnhtuiEMw/Zm86NkOS8kzGmOB7zkPlIWJd1xuDX5lUPXFAbjjPQ1pjGSIav9iXdaAuDaI3iAKXxkylbaK4INR2u3fjugax+1zjujqt4f43u0ORPVnob9CpcWWrAYEjjNPkLIZORi/IaXL6gWg61afHLihC6K+w5l9k0nUhHaqPdZCNcfWxb6kdityE4oOjyQOgj6I2U3e2rg7U7AnGVrAT6FElqWXT4Qehs28NaDuXTYwsfGA8yywHB8wmdpxwOnjod5MzW4ykaadn5oPrJMKXy0tafGyRFvVpKY4pXTHfJFp9zcO6uqUMieueLcNkBw== Received: from BN1PR12CA0017.namprd12.prod.outlook.com (2603:10b6:408:e1::22) by BL1PR12MB5207.namprd12.prod.outlook.com (2603:10b6:208:318::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4544.13; Tue, 28 Sep 2021 08:24:15 +0000 Received: from BN8NAM11FT035.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e1:cafe::b1) by BN1PR12CA0017.outlook.office365.com (2603:10b6:408:e1::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4544.15 via Frontend Transport; Tue, 28 Sep 2021 08:24:15 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.36) smtp.mailfrom=nvidia.com; dpdk.org; dkim=none (message not signed) header.d=none;dpdk.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.36 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.36; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.36) by BN8NAM11FT035.mail.protection.outlook.com (10.13.177.116) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4544.13 via Frontend Transport; Tue, 28 Sep 2021 08:24:14 +0000 Received: from DRHQMAIL107.nvidia.com (10.27.9.16) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Tue, 28 Sep 2021 08:24:13 +0000 Received: from nvidia.com (172.20.187.5) by DRHQMAIL107.nvidia.com (10.27.9.16) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Tue, 28 Sep 2021 08:24:11 +0000 From: Rongwei Liu To: , , , CC: , Date: Tue, 28 Sep 2021 11:23:54 +0300 Message-ID: <20210928082355.1616087-2-rongweil@nvidia.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210928082355.1616087-1-rongweil@nvidia.com> References: <20210928082355.1616087-1-rongweil@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 DRHQMAIL107.nvidia.com (10.27.9.16) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c429220b-33e0-42c6-f0ff-08d982595ba7 X-MS-TrafficTypeDiagnostic: BL1PR12MB5207: X-LD-Processed: 43083d15-7273-40c1-b7db-39efd9ccc17a,ExtAddr X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:595; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qMelf3GjdrIefrPEPdStf7M7HaOMIU+lfrxzGnF50T3lK8fc3jZYmSgzjVMJAyK8CkSBzMkRqkrrZoBMqGtL//JosbyqBtjWXP4nlTgeM3kMGrb4S5TJFPn89t3VNUd5FYH441XwrjCU1TCoQF/yuKj6btwlZBPH/efiMfBOA16I4cdfL04qPYiqHDjywZtCvBi5SMuJPehrfLMLm2mVSQ5n6gQuOxotqYmet27qsx/seBhXmHft4U8tIqArIpEJPVtkqlcAkWup8MPBl6mr0DG+22XSjYiIkLF8ursObLiHBSnVp6a1Cn8GoqXGw/5RFA8Gcxhe7/RXELyaDRbdri/3n/vmOHJX8/B3XZEXdPGMbjD1VgTFmOyJ1oZOtkp+dZEz7V4Jy3KbnEMgK32lAQpj+iam2AJ1sDfwOTIBLL7VGLcG0IkKdWopjJicXZwNBR+Yz6pKHIi6YzCR0kjkNvgdwqoAcRWifMkLOvo7UEAWvXlHxQtifQ5v493QkFkAXXgxXKFdCMGBD+qmDBJ3Uzbg1WqNvxd+iKyO58ptoHNdCUE/9e+E2bw/ZsvIiAGlYvk1LSQm55Dm3sTUuR6iPhGMGeisjZSyjOC+tNxcsx5dl2CSeblk/CHH40MxR43GK/PVkrI01ny8cDcwl5yPLIvJuZVO5mL6Gue2zKGb4omSiu/IIj+EHijE4oGGQ7PqizF5wS2JBV6mIHEVIU6qxQ== X-Forefront-Antispam-Report: CIP:216.228.112.36; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid05.nvidia.com; CAT:NONE; SFS:(4636009)(46966006)(36840700001)(8676002)(356005)(8936002)(26005)(426003)(47076005)(336012)(83380400001)(508600001)(6286002)(186003)(36860700001)(7636003)(36756003)(6666004)(107886003)(16526019)(1076003)(2616005)(70586007)(55016002)(70206006)(4326008)(5660300002)(54906003)(82310400003)(2906002)(316002)(7696005)(110136005)(86362001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Sep 2021 08:24:14.8700 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c429220b-33e0-42c6-f0ff-08d982595ba7 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.36]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT035.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5207 Subject: [dpdk-dev] [PATCH 1/2] common/mlx5: support pcie device guid query 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" sysfs entry "phys_switch_id" holds each PCIe device' guid. The devices which reside in the same physical NIC should have the same guid. Signed-off-by: Rongwei Liu Acked-by: Viacheslav Ovsiienko viacheslavo@nvidia.com --- drivers/common/mlx5/linux/mlx5_common_os.c | 41 ++++++++++++++++++++++ drivers/common/mlx5/linux/mlx5_common_os.h | 19 ++++++++++ 2 files changed, 60 insertions(+) diff --git a/drivers/common/mlx5/linux/mlx5_common_os.c b/drivers/common/mlx5/linux/mlx5_common_os.c index 9e0c823c97..8b3ee2baea 100644 --- a/drivers/common/mlx5/linux/mlx5_common_os.c +++ b/drivers/common/mlx5/linux/mlx5_common_os.c @@ -2,6 +2,7 @@ * Copyright 2020 Mellanox Technologies, Ltd */ +#include #include #include #include @@ -428,3 +429,43 @@ mlx5_os_get_ibv_device(const struct rte_pci_addr *addr) mlx5_glue->free_device_list(ibv_list); return ibv_match; } + +int +mlx5_get_device_guid(const struct rte_pci_addr *dev, uint8_t *guid, size_t len) +{ + char tmp[512]; + char cur_ifname[IF_NAMESIZE + 1]; + FILE *id_file; + DIR *dir; + struct dirent *ptr; + int ret; + + if (guid == NULL || len < sizeof(u_int64_t) + 1) + return -1; + memset(guid, 0, len); + snprintf(tmp, sizeof(tmp), "/sys/bus/pci/devices/%04x:%02x:%02x.%x/net", + dev->domain, dev->bus, dev->devid, dev->function); + dir = opendir(tmp); + if (dir == NULL) + return -1; + /* Traverse to identify PF interface */ + do { + ptr = readdir(dir); + if (ptr == NULL || ptr->d_type != DT_DIR) { + closedir(dir); + return -1; + } + } while (strchr(ptr->d_name, '.') || strchr(ptr->d_name, '_') || + strchr(ptr->d_name, 'v')); + snprintf(cur_ifname, sizeof(cur_ifname), "%s", ptr->d_name); + closedir(dir); + snprintf(tmp + strlen(tmp), sizeof(tmp) - strlen(tmp), + "/%s/phys_switch_id", cur_ifname); + /* Older OFED like 5.3 doesn't support read */ + id_file = fopen(tmp, "r"); + if (!id_file) + return 0; + ret = fscanf(id_file, "%16s", guid); + fclose(id_file); + return ret; +} diff --git a/drivers/common/mlx5/linux/mlx5_common_os.h b/drivers/common/mlx5/linux/mlx5_common_os.h index c3202b6786..ea0467f507 100644 --- a/drivers/common/mlx5/linux/mlx5_common_os.h +++ b/drivers/common/mlx5/linux/mlx5_common_os.h @@ -296,4 +296,23 @@ __rte_internal struct ibv_device * mlx5_os_get_ibv_dev(const struct rte_device *dev); +/** + * This is used to query system_image_guid as describing in PRM. + * + * @param dev[in] + * Pionter to a device instance as PCIe id. + * @param guid[out] + * Pointer to the buffer to hold device guid. + * Guid is uint64_t and corresponding to 17 bytes string. + * @param len[in] + * Guid buffer length, 17 bytes at least. + * + * @return + * -1 if internal failure. + * 0 if OFED doesn't support. + * >0 if success. + */ +int +mlx5_get_device_guid(const struct rte_pci_addr *dev, uint8_t *guid, size_t len); + #endif /* RTE_PMD_MLX5_COMMON_OS_H_ */ -- 2.27.0