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 41B3AA034F; Fri, 8 Oct 2021 12:05:53 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CC1F6410DA; Fri, 8 Oct 2021 12:05:49 +0200 (CEST) Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2074.outbound.protection.outlook.com [40.107.94.74]) by mails.dpdk.org (Postfix) with ESMTP id 219A340DF8 for ; Fri, 8 Oct 2021 12:05:48 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ASdl0Pt80+KW6CZIESPvEOjnfwj6UtYnPDlfBlGra43NPe7Ut+RPlxNSzVQJCPCWVLReYYTBNX0DB23OrTJXS7qgDriScplEwi41rcY1oJICJfgqgjba16cR4uvkBoYQyPjPGJv9Ek66/bwPzD+89bsR3zY/BU+KaUsaTXzXK5yILZLEZaplCaXSPOf99nJtGl6Qtc5ojIW9pihK5Lc8+zSC+qDABE/GeAXfll2y0QkzM2Ym4OUOGRQmm8UJho2OYVqA2Fp9DyM+K51Z577GKaUzvZQTmWEwSRsVWpbljvU5iKZlrkkWpr5MPMzB1vE+Sad+JVGrvOK9K7LJV+6IHg== 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=j/V2kfoRBbHMsbeirRkaq1t0rbeGx/P3sbfa9jXWTfAMDuvG9KUsZ2iTM7HUE0MrpnRrZNZEL73k5Z7dNB1IAU6AaYklgFLnwxx7/lcH/c1VKXdcyFwXA64CGfJ2mKu+eWlrL2bsnKQklTGq3XFkRDhFgE4PiChUFwlVle2HJbYEKzBRoYiUGdX0NyP60Dz4R3KrjU85l2yarSiAkstS65hqhnhD4k6EePSRfaWQjqLVvCAqc7N/PtWcPZeuk+7AVLiy8qbTT4FHea28Odmzu9w7nOYl1y3SMpxkXyDr5JbQQS3YoOk6isKiWx+WQqKgVO61sPauc3O+0AvyS7iXTw== 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=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=HeStO2a21BwaQn3Bz9o7trAiTpnll9djHZzGKS2D8yo=; b=UrFa+KkgulTEQumXAHK43nXUK1lSUfywvaYLyeSaC8kimBIP1AICSp4kX2eh7oWto7LJIGuM0MyHCgDhoXZrS/MwHqbg+nWBeSKAGP30oy2VeLRiwDGGbnjIrsZpd+w6iK6kENV+LCf/PTwNV95sAw01wchh8nYvLSXki09ZV+mOkVAGPp4xMmDDWtVClXo8NJ72dUht59nzm7JrUqL0unWo8UOybfmOW8SgCIBaaOaW8El/Djrbh0SngVQXvHT7iU2dvOToBcoBeAwHUIUuSEyRyx2FsHcXPHbhAsd1ZYwGo1EzqfvUm6SN2u3My0kpbLvNbPvHgUTyUtotBlHVXg== Received: from MW3PR05CA0012.namprd05.prod.outlook.com (2603:10b6:303:2b::17) by DM6PR12MB3468.namprd12.prod.outlook.com (2603:10b6:5:38::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.17; Fri, 8 Oct 2021 10:05:46 +0000 Received: from CO1NAM11FT058.eop-nam11.prod.protection.outlook.com (2603:10b6:303:2b:cafe::8f) by MW3PR05CA0012.outlook.office365.com (2603:10b6:303:2b::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.4 via Frontend Transport; Fri, 8 Oct 2021 10:05:46 +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 CO1NAM11FT058.mail.protection.outlook.com (10.13.174.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4587.18 via Frontend Transport; Fri, 8 Oct 2021 10:05:46 +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.18; Fri, 8 Oct 2021 10:05:43 +0000 From: Rongwei Liu To: , , , CC: , Date: Fri, 8 Oct 2021 13:05:28 +0300 Message-ID: <20211008100529.2423738-2-rongweil@nvidia.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211008100529.2423738-1-rongweil@nvidia.com> References: <2308701.4c83qqXp4g@thomas> <20211008100529.2423738-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 HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a8d572e3-7b68-4d28-cef1-08d98a43325e X-MS-TrafficTypeDiagnostic: DM6PR12MB3468: 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: y6jm1qxjQnY5zuDINxtVQG9L4eP5rwbsNgm6X4Co58KTtQcU3+88K+k2jmOd0RGVMIBKMIkjf1hu0Fw0CaMTNmpbDx9nqdc90aU/JMR3D64ymZZS//1Bd3P/Bo1jOBy3dBvLuhWyj/Bkkq4PfKyDV6WFrJ3jVvSyhTNn5KhxvpZTeJMji8+pMai/qt59nvZxnF7s2BMqIXT2gP+WHGN/jH81wUva0RIH36xDwZXZS5+3vmgaTQ+n0bXvzGq0TUBMoAZ/iRLOGi/YPRMPHww05XwVx62AFCNdCiG1UFnH+GkxZXsE1wKysdB9DrjOEXR9orUHzkF3WgcQ28kLnp4a22iu61tSausvS7ZtN1Lzo/0o14gutIH0yWQMC1co48S8fbrgc7atKNxnTbyzj7uAEoycJ6OM6jSUYwZZ0cRsVZ3TMOeSGXNvlm5FAtM5SWM/rr/QXMvEasuFNLgftcMeX5ZddS5Lzejr6TLIk/oIY09sEPrSPda3F/GhGhqglmFzbRK0eOdp34gM98Db/7BhFQThdwEzdBT6Pl15/AemBBVW+F/5o3C3xd25P73iVM+Y84IJVPEMFyzqX4+0HQonrwJbBeXJyX0HQQG4NS02b5lJpIaz8u5DCS4lEcghRZdx6Dm133hTMca+ZY+Fitbl+PeGdBxplXdJbXyY2TchdM6waqxZeihQed9PhEhe+ckfTFVHq3dz/YsgybfhVicp1g== 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)(186003)(36756003)(336012)(6666004)(4326008)(356005)(47076005)(7636003)(83380400001)(508600001)(55016002)(70586007)(2616005)(82310400003)(26005)(107886003)(110136005)(5660300002)(16526019)(316002)(36860700001)(54906003)(6286002)(86362001)(8936002)(1076003)(2906002)(7696005)(70206006)(8676002)(426003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Oct 2021 10:05:46.0772 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a8d572e3-7b68-4d28-cef1-08d98a43325e 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: CO1NAM11FT058.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3468 Subject: [dpdk-dev] [PATCH v3 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