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 D3B1EA0C47; Tue, 26 Oct 2021 10:48:53 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1B86B426DC; Tue, 26 Oct 2021 10:48:52 +0200 (CEST) Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2051.outbound.protection.outlook.com [40.107.94.51]) by mails.dpdk.org (Postfix) with ESMTP id A0D16426D5 for ; Tue, 26 Oct 2021 10:48:50 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YaRjvShRouM0of8SbLRStxmxraTHhMRLTH3JQlpLdeINCEsyQ4MkYIKscLizt2rY2E/SfodnOv8Azwyl1YXyyHm15Sr7nuLNietSA7QIaeDE7GfFMDwoiCpNn1oToQRffM1ffiF4e4Qrn9kh+vvGK5rUMuGOG7u0mmhH631J1g2EoCqsX7oV18+SxP4ABRO0uRKSZrwtYCfBYYkb2G5frOHwi+zVs5/deN6UtXRT2Fx6lwn4o+jshvNGBbQhh7e32RCB+REaEDZU5x4flhlOXokBLz6d3d1QzzZ+dkobtN+ecKCAo9yMUzsNWlBCTa0Aiz7IOM03CGerMPRrqq84rQ== 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=Fi/NWbBf8hYYrL56EPDGouPpO1xLXl4GQxC4cAH8Mbk=; b=OIcXrtx7H7lDnv3d7o8t/+pzR7E5Z+sLlKuB7Yr/q1MSJMk1k3OdAu65LTskEqnd/gmMZsGjOsok4XAcDFO5ix/+Loq2b/4K8Me4UqQW0vNXekCK+n88IY4Vnqsva25qqaW4L3mx2V4+0N3Wff7toz3khl52v1e1F69JjDqKGflRHop2vpCo3JWRwmo3jwnrJ9qeUMJenXGr/HcPzOX4ciloayT67sQUmYNnps1qr6jXjKxI57tTdXLmeyqv+GDdn9mto4ErmyZCSmYqoAqo8uTeB1c/t8kMYGpTqYPs/XmBBYCTGQDNRjiX7tP7OqWbgaR8vNqJUkOK9piS6grvNA== 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=Fi/NWbBf8hYYrL56EPDGouPpO1xLXl4GQxC4cAH8Mbk=; b=qJ14c4YKn2k9Z4cmB+QB74jx+Izq4Et5sQ039dTRmdQ4tYX74zHIUHqv83n1mP6Gbq7n8jAxmgwY5JdrRl/GBpccvjMIWJyLuutJJ5teYfsHc3ez3UYi6H1T1SCkiblAeDhh9vtBi7A0q1q5RNU2V+SPObHWmvVTV+y315tgRo48H8TwiAjDLv09PBADzfZ92Ja2JDim0LYbgEU6TIXCZkuXHs+jZLPyIvP5jfY7v2v0kXAr+ciazr4HjQ7HoG95bz0+PU/h7UaFkr2SCib5BdcH2Z25hDgvB6zOjI/VmB0wMQhP16tmLsoo56hCYVE3MySnaJBoSrUVJ9S/GAfJFQ== Received: from DM6PR18CA0011.namprd18.prod.outlook.com (2603:10b6:5:15b::24) by DM5PR12MB2406.namprd12.prod.outlook.com (2603:10b6:4:b7::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.16; Tue, 26 Oct 2021 08:48:48 +0000 Received: from DM6NAM11FT050.eop-nam11.prod.protection.outlook.com (2603:10b6:5:15b:cafe::b4) by DM6PR18CA0011.outlook.office365.com (2603:10b6:5:15b::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4649.13 via Frontend Transport; Tue, 26 Oct 2021 08:48:48 +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 DM6NAM11FT050.mail.protection.outlook.com (10.13.173.111) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4628.16 via Frontend Transport; Tue, 26 Oct 2021 08:48:48 +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; Tue, 26 Oct 2021 08:48:45 +0000 From: Rongwei Liu To: , , , CC: , Date: Tue, 26 Oct 2021 11:48:29 +0300 Message-ID: <20211026084830.440951-2-rongweil@nvidia.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211026084830.440951-1-rongweil@nvidia.com> References: <20211026084830.440951-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: 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: 4dc542a9-ea7c-4f56-eece-08d9985d6d64 X-MS-TrafficTypeDiagnostic: DM5PR12MB2406: 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: 4E7237/Yp9JKg6kPr/Hw5js+j+ANTnKkuUvKKEgZlQRlvTUrIWsaN1G76uQrVy92mkkjGjn25Rd4gEn6Nxp9kTFCOwBBGfBW71KdSi3BGXJogxCXG/ltKYivORaoGOVnje/AEI0OFUuL9tXwfC/HHWgPNjpXAJjIAzeUsBFwv4V92iCx+TLK5dRrJclLdeT2PkkCFX+CSpF7fDp9nBdkTNvuNBGpoa7bYO4gL/1Ntsy/Kmd1D4s7AjpKC+H+lEeByIAhpChVQxaCYG+3pFg6q82nZGS8ibidywF8LMfO2el9eXmI25O6630a5waEZ1BlkE5Sq/lBAwv2jwy5TgRsVSeb77JHdHHPKCBR9czprxMzhAMCkuyTdoGaGNR4xe5FU3WTCY93P4U5TJVGfmoSyG6x8S3lIgE9cbuJjLDXTEVtTN8pYV0bTJYIs1Cw4cAfu5iMy55xtmyn/sCDkFqfuu3MUy3Nf6ObMsgesWnw0IJX3Hp2weGe0XjMSgQUUrqEQXff8O8nxdmhfDGAFU1VuXuNdFWfipFN9gtWYbbRvpAi1OCjSzgBcW/OlhTuM9Rr7t1KE0rvumMbYDmwr/At9RoYb1bIvYswgitdcMd1qKmtxlxoZ3IUBG0WOJqaK4g+HbKoYSZNpqiOmAzch7kPf2jrrI/oVw/YkPCpWHdaFGgH0tFSr1C+g0Dx3VHDW97p2khuGrn+CNomHdN367O5MA== 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)(36860700001)(4326008)(8676002)(356005)(70586007)(47076005)(26005)(7696005)(5660300002)(186003)(16526019)(86362001)(82310400003)(70206006)(6666004)(54906003)(83380400001)(107886003)(55016002)(36756003)(2906002)(8936002)(336012)(426003)(110136005)(316002)(2616005)(7636003)(508600001)(6286002)(1076003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Oct 2021 08:48:48.3118 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4dc542a9-ea7c-4f56-eece-08d9985d6d64 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: DM6NAM11FT050.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2406 Subject: [dpdk-dev] [PATCH v5 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 | 40 ++++++++++++++++++++++ drivers/common/mlx5/linux/mlx5_common_os.h | 19 ++++++++++ 2 files changed, 59 insertions(+) diff --git a/drivers/common/mlx5/linux/mlx5_common_os.c b/drivers/common/mlx5/linux/mlx5_common_os.c index 8db3fe790a..b516564b79 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 @@ -704,3 +705,42 @@ mlx5_os_open_device(struct mlx5_common_device *cdev, uint32_t classes) DRV_LOG(ERR, "Failed to open IB device \"%s\".", ibv->name); return -rte_errno; } +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 c2957f91ec..83066e752d 100644 --- a/drivers/common/mlx5/linux/mlx5_common_os.h +++ b/drivers/common/mlx5/linux/mlx5_common_os.h @@ -284,4 +284,23 @@ mlx5_os_free(void *addr) void mlx5_set_context_attr(struct rte_device *dev, struct ibv_context *ctx); +/** + * 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