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 59D1FA0C4B; Thu, 14 Oct 2021 04:58:24 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 57A9341134; Thu, 14 Oct 2021 04:58:21 +0200 (CEST) Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2050.outbound.protection.outlook.com [40.107.223.50]) by mails.dpdk.org (Postfix) with ESMTP id C00D94112E for ; Thu, 14 Oct 2021 04:58:20 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dNIT7++wjQcxQ8OF8EMv9m0kgq8dE21XaYI6mgRrq+oGoL4B7Pj86D9sGwKQDA7U5pAdDPSsa7XCtCl6BznzsQKuhNUHOMLMN2Ef3hEtz5ZCV+rPuMo5+IOz6jKJB146c7UFmxiFKQKsrrc3sqi0DNSpzOhypUDYdHShTtPU0eg6Ho6bFTFT/S79Ie6qOQEA0bLeHH0fdj/So1Nt1WmqFrz9aJEs3N+7wAxMqnMvVk8CytC+8gp7BnVFigqWluc70BzBewhKBhQI2cW6Ofr7Gwx7P6NEhMozXJscfgsVs/Sva+GjcueZb1M4kwuaTGPSKVo2Vh0f/b5ZUCWRUdKZ1A== 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=HeStO2a21BwaQn3Bz9o7trAiTpnll9djHZzGKS2D8yo=; b=I0iD8yT4yd6AJXcDZaXhOADuttdlOk3iC9PsDHY123+GuTJF5dV4idFRYIPYT/uOSuDebf/qqQzRlX9Kmgr3HbTuSfOMpGcHZTzsd0UCHwdJxsNPbkbSgJ2CEZti4vsyrnE93cRn5FDXEJS22jf/sNciW+BblHFQKqlnua+mn2K5wX6fiDl9aOeXrTT0z/z25I3PtBCTCzyUQHij5zwwO4a4S892KxDLKiL8kL/EQWmSMyArx3H/an7jXqPyVYPSuJ7s2QK6v8rrE98M/rlrB04raMWv4+W9TH/jnzHja6K6eijRH6u9oTmLLPdBLP4IkD6t/XWOh203YYow0czN+w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=dpdk.org smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=quarantine 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=HeStO2a21BwaQn3Bz9o7trAiTpnll9djHZzGKS2D8yo=; b=ulZtqI4IEVMIWj5y5aNtIXlcHh8J8jwi7HljUytq9GrD7hZdWPHeD22qkuslsucH1jFKbs3R865ZxWX3uvG8zt5oC9iT5GI5NAcy/vLjLcELhmrnB7+xU89GRw+9USGhTJG4bb+cG4k3/vMglYzNf3JAj8GQ94Q9T0057chb8/qpDCHYefyxqaM7XrAgyMPrbvZeMug4HZ/pL9wnxkRmGiFwfQilPWQUF5PsH1hbAWSmxvJW19X8licS2YssRr2lP0v2mKrbTXKd7uvKeyWfNwXnw8Itbl5Ws9W6wsUkIFaifbAyfOgXD6gExaTQnW6SMmzgegh4LKMsCUmgnqqmvA== Received: from CO2PR04CA0176.namprd04.prod.outlook.com (2603:10b6:104:4::30) by MW3PR12MB4427.namprd12.prod.outlook.com (2603:10b6:303:52::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.22; Thu, 14 Oct 2021 02:58:18 +0000 Received: from CO1NAM11FT051.eop-nam11.prod.protection.outlook.com (2603:10b6:104:4:cafe::b5) by CO2PR04CA0176.outlook.office365.com (2603:10b6:104:4::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.15 via Frontend Transport; Thu, 14 Oct 2021 02:58:18 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) 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.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 CO1NAM11FT051.mail.protection.outlook.com (10.13.174.114) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4608.15 via Frontend Transport; Thu, 14 Oct 2021 02:58:18 +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.18; Thu, 14 Oct 2021 02:58:16 +0000 From: Rongwei Liu To: , , , CC: , Date: Thu, 14 Oct 2021 05:58:00 +0300 Message-ID: <20211014025801.3055244-2-rongweil@nvidia.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211014025801.3055244-1-rongweil@nvidia.com> References: <2308701.4c83qqXp4g@thomas> <20211014025801.3055244-1-rongweil@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: 45c37d77-e477-4be4-6e92-08d98ebe7994 X-MS-TrafficTypeDiagnostic: MW3PR12MB4427: 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: MdnpxppIz2K5W6ptKi1LCkWIqDNU+LAdmxpmi6MWMabem8RoCzaDaPRGQ4dOfSHUNvO7yFS+TYzgJzGkokCIju6BHmFNx3R2O/WOAv8QdCJIYyUkAssQ6VT4OeOXfzVIcnc9I+c2vIOWuYERPnnwzckZrk9HrA50juWQjeVdRmdX3uO5m5CfnH5Ohv5ZH6pSJOHcpTOKoQ/2hWhTjIBw3ujMjRwuYOe6ZKseXtrezGFEocEPAtQfRasH3YNKOPRQ1D0caW0U9f86I0xQAymxC4SnSEuabQFHTSrIDopbLZ5fwCGR2jKoLaqIpNR7gkhipEu3cx6hpckTT46G4ZFknZjplk6/4sljXKy5pzxQRK0gPnlVVv/jqudx8dwFMeIJfQSN86GNg/uvd1XTO/nbhM6dAK0EqsviFJoe8UjN7S+19dDElfu7v/JKNB2OBA7Xd3ITYQWXD5TqIRSKYqxN0rjHw4SZ2oe9eXcbRpCgFWVlNLQgAqPzBeRhfR0QmaWK+DPXXUF/ZVMd89OOBlkm5gzfSBmSD6ZI7Wvel6KkRm4KFbqwdD/Gfuiy04Q1yxn4arL/0crxTweEb0QaBkHtle6ZTnx6TVx2ieEx8aBKIlVNfmEDfzaCHFvhiinXZgjVj/19KoB+dOoPVvafxO10e57qbcFltOEMxQnhL20xlVKALnNhU2uLkAgSV/iSm0xiYdJcXiMO810FPoAQ6Wp5iA== 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)(46966006)(36840700001)(8676002)(6666004)(86362001)(47076005)(508600001)(36756003)(316002)(426003)(4326008)(83380400001)(55016002)(1076003)(36860700001)(110136005)(82310400003)(336012)(186003)(8936002)(6286002)(2616005)(70206006)(5660300002)(70586007)(16526019)(107886003)(7696005)(54906003)(26005)(356005)(7636003)(2906002); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Oct 2021 02:58:18.3217 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 45c37d77-e477-4be4-6e92-08d98ebe7994 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: CO1NAM11FT051.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW3PR12MB4427 Subject: [dpdk-dev] [PATCH v4 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 --- 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..3cdea75373 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] + * Pointer 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