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 40D7E43BCF; Fri, 1 Mar 2024 14:12:44 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 12D5C4335A; Fri, 1 Mar 2024 14:12:44 +0100 (CET) Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2041.outbound.protection.outlook.com [40.107.220.41]) by mails.dpdk.org (Postfix) with ESMTP id 7E93A4026C for ; Fri, 1 Mar 2024 14:12:42 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Qr40ggTK3dT44WPrchNxKegLEc05IuKiO1DYWULAKVbaBoN/kHTXLJ20avJ4zRpy8uxOM6uYAYWbDmX4nrBgu4ywXjY1JVfkK2wNmQiWv7svEKoDQg8l/VZbYPAMJyXJ/R93RQVjrDJr1H0yicQH8mgkIPCa3/nkySb0zPNboqFzClR65QO6bobwFTwLtSNqy+obwsZxwLkIoFfh3ewI18uJc0W4Ms3yIbB2sL7DK5SPyd91T9zZG/mdfefOhA05nLBDBe1cw2mAch8/rDd6d61FZFwZE/BVQLx0jZK3qHjtal4/5SxUM7AHDKilVYN8rHSQmQUhpyI0e9efCIwJ+Q== 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=+VlfMIuBFxgx/vfF8cfckrYQ2MFlmjteIe9XU0IlOKM=; b=U2r+S3VytiT3C9FOxSmff4MWauUCs2gvMcea1eNyGxe163VeVFydpUNQAm06sv3f8RT+82ZB8NyLRjgvLzivIsNZDVo7maiu+24XPC8qdenwJyjAq3+WfPdTpKg7hz6dA/DpD9iOOn9TYjMRoHdcqk94BA2JLF5g0P3WbXJMT9Vwdpu8+AoJOWFRmAtmCJTvKlx+JHhqs1bxnF2l6vJKBsh8HuhYHbA6TJeCLrdXzZlDY52p7RMOdB/DsjhKVC29yFjIHUs/qKCwMWTtCiLYL7/+f7B421NrLu+ZsUcO/DtldCZWlQBZLatzLb1s4ZvXlexXQfpW9tPFOowIj2IBAg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=+VlfMIuBFxgx/vfF8cfckrYQ2MFlmjteIe9XU0IlOKM=; b=ThoSh/vJV4fS88V9SgG32F6xo6Lcat2Z5IALZfbb3Gij+aNGP+JP1hmJZGkMKYLDsS73+9e3fTRDNTHvAPRjmVi+ZCSXXK2fKGFm5UWg9QrgerLOxq382JXe7q0+BsFLUv8inyYSGN5ukUPrfvAmxa/tGsLdXhXGy+LwTfMkvjA= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from CH2PR12MB4294.namprd12.prod.outlook.com (2603:10b6:610:a9::11) by PH7PR12MB8780.namprd12.prod.outlook.com (2603:10b6:510:26b::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.36; Fri, 1 Mar 2024 13:12:39 +0000 Received: from CH2PR12MB4294.namprd12.prod.outlook.com ([fe80::3ec7:6339:1c14:c529]) by CH2PR12MB4294.namprd12.prod.outlook.com ([fe80::3ec7:6339:1c14:c529%5]) with mapi id 15.20.7316.039; Fri, 1 Mar 2024 13:12:39 +0000 Message-ID: <14dc648a-dc45-4308-b096-cd1a189a2e80@amd.com> Date: Fri, 1 Mar 2024 13:12:35 +0000 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] ethdev: add Linux ethtool link mode conversion Content-Language: en-US To: Thomas Monjalon , dev@dpdk.org Cc: Andrew Rybchenko References: <20240229123653.1379466-1-thomas@monjalon.net> <20240229154343.1752555-1-thomas@monjalon.net> From: Ferruh Yigit Autocrypt: addr=ferruh.yigit@amd.com; keydata= xsFNBGJDD3EBEAC/M7Tk/DfQSmP1K96vyzdhfSBzlCaGtcxNXorq4fALruqVsD3oi0yfyEz9 4YN8x7py0o9EL8ZdpOX0skc0AMCDAaw033uWhCn0GLMeGRKUbfOAPvL6ecSDvGD7CJIO9j0J eZUvasBgPdM/435PEr9DmC6Ggzdzt8IuG4PoLi5jpFSfcqxZFCCxLUDEo/w0nuguk2FTuYJg B2zEZ4JTBZrw7hIHiFh8D8hr6YA6a5uTofq1tr+l048lbtdFUl8TR0aIExVzE4Z8qKZlcE+9 RQaewjK5Al1jLE4sHdmd3GN+IvgDF3D/fLsi25SKJDeGSdeHkOmaX0qGeM4WKIfU6iARRCiQ N3AmBIxZ/A7UXBKLaOyZ+/i3sE6Wb53nrO4i8+0K2Qwyh6LjTeiJAIjYKN43ppxz3DaI+QwQ vI+uyHr4Gg0Da9EPPz/YyKauSeOZCfCB5gIfICO0j6x0SCl8uQ2nLpjxcZkf0gjcwUzP3h+S 3x6NfDji9YEij0zczW/dcSpGgZ6vsFpPrtnP9ZXy6J53yp0kJtOJoOlkEFFdU2yCZnCDseum CoudmGLZVvS0/DzHDJejq+3kK3FDGktZBOxZIIpal+nFqS7lVgOZc4+huVv3jyhzoAUOEyXA XK5j6o7g8STUY+z33QNnHpdLvecMwuzmvqy0jR54yAbZ64mB9QARAQABzSNGZXJydWggWWln aXQgPGZlcnJ1aC55aWdpdEBhbWQuY29tPsLBlwQTAQgAQQIbAwULCQgHAgYVCgkICwIEFgID AQIeAQIXgAIZARYhBEm7aYjps5XGsPHCElRTPtCKKm/6BQJkdyEEBQkE3meNAAoJ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BZNVM1l3NAdK+DLHqNxKuyO 8Zk= In-Reply-To: <20240229154343.1752555-1-thomas@monjalon.net> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-ClientProxiedBy: LO4P123CA0498.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:1ab::17) To CH2PR12MB4294.namprd12.prod.outlook.com (2603:10b6:610:a9::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PR12MB4294:EE_|PH7PR12MB8780:EE_ X-MS-Office365-Filtering-Correlation-Id: 25c5adf8-e7d3-4f01-98b0-08dc39f14515 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: oev1puJ+9DM5/a6IY7r1P8drIVaE9FKuJcR3IqBBwio+FXnxVElcjD6UwE7icns6zXZJtUxwbX+lhLOnSEWY5edPRqyDyqZHTGmNVl+weJ2JipIuwETwobrJq3HHcymvB9TeP0/nHZEkVzO7So2nNnOBMNcEQj5bptCoiptexx8dpRmY/8zuDR/1uSV37+eHxlVSEMcPKPV4uO7URTWbFoqUU4MlkfvfygJgKSXDaRDuuy2jTobTE2kbjaAKqv9t2YAr4xz3JQ+V8qqzYw2FgfPyqCqptFO6W6jaj+6HUKHSbdaSx7hkTBjskiQJWoirzTRcJ+P0HcVhOiKPOU0Vt68Vy2OMMHY1u4SWPjGk4rR6+R5ATBw3rwk1nwZrttpDn6SaAWMU30/6ira/u88tbTw4OIaEi03KJ58pSLWnwhMknH31PyO6FA9KtGPruYfs4o3OEaMdA/UKck0VHiYi0lkv1bRyCAS8tv5CQUtEgDA5LKdg0KGZ0JEP9l2c82DNLjU7erseOgr0EsDHFhXqLVUM3sz6YXiv2GvQvXf5u9PaVLrhtwZKguiBkGTsmpP/+29GJY8MXIyWw7+vaVBICUaE/PVeLcaJnj2A11GPjQXHXaYDYWG7Vb9ZmRMMwDAwhqjz7F7QC9HFrjunaBkH4Q== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH2PR12MB4294.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?bk5xSU9UY3hpQmQwRmJLNzhuSzdha0JRdlZ2eEhwRXpFUU43RGJVRlNlRWJQ?= =?utf-8?B?Y3ZpN0pNNmU5b0YwS1FGWURlSWd4dkJCcWxxaWFwNHJxeTZadnovaUEwZksr?= =?utf-8?B?S1NPMmFiV1M3QkxvdEtjWERzOXFNM0d2OEFUSTJBWGFGd0wwMmxJMVhoTEFY?= =?utf-8?B?aW1rN0N4NlNtd2ZxeUxxcWJydE9UL2VpNDYvdEVJbjQyM3VvWERCVmxkako0?= =?utf-8?B?RXhFNFF6T0orR1hCbWJwUm5MRmczckNDTzJRUzRiQ0lrVnlrVTk4Ym9EUDNr?= =?utf-8?B?Snk3ZlB0RVBaa3hGMWdIWWdKYlJjRnI2TE1MeTNpSlppQVV2emRiN09zME5L?= =?utf-8?B?Z2JsbEVCa0ZTS2FKRSs2eERJb29CdUR4SjVHQnNwVWtxV0lrVTVVNEV2b0Ny?= =?utf-8?B?MHFKL0JhbXV6d3Izc3E2VTJZMlpnbEVmeDlXT09xcFhEUGQ0bkJVYmtrd1Rj?= =?utf-8?B?czZNclZFak9jRU5XSS83ZmFJRjZSMFE5d0dHZlJyZ25PVUpZQ0RjMGw1N2s4?= =?utf-8?B?SXVuL3ltQ29UR2ZtS1RDSHlDWkNYRDhMY0kvMjJmSmFIeTZCMngwTmpmTTRM?= =?utf-8?B?STZtakxDeUZxOVBQOWxGNEFBWWVwUGMzSzN3bnBUY3BpaHJGQVo1QlZHUXVW?= =?utf-8?B?RnBkMnJUaFNTRVNKeG0rT0UzaTZtWFBhdnVEN3d4ZExpd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ZN0krTmhqMnlWRW5GNVRlakN4?= =?utf-8?B?UkRRVTl3MGphdkJWUHpIc0tXMUpwZGZIS3dGT2w0Y1lvQnNHK1h0T3E1TUJq?= =?utf-8?B?TGRWdGMvVHRMWXZmdWJKTDIwckJLbE9aRGlYTFBnTmN1T203RkZGUWQ4Ny9Z?= =?utf-8?B?RERzMGNLZ2Z3TDVDTG9XNWtrZUpRY20wZ1FiNUs2MkxmZ1cwNzdac1V1VlZv?= =?utf-8?B?WFVPcUpTVlJna08zdDF2dmUvcU0xMUd3T3RxZmJ2aHM5WXAyR0JDZ3pSdVUz?= =?utf-8?B?aGtGMlE3cUVrR2JuMCtpTFZyUGJkT1o2RzdROVp3SHZ5SDNkSFMrUjhYYjVT?= =?utf-8?B?RWlYT243aFJRdTdTVVJWWFFPMzRNdXJ4UjZrRVZqSmpOUlVMWVlWYUhxNFBj?= =?utf-8?B?MVQ5c0FyckEzMWNYT0RCOStsUFRGSVpPOTZGQ0Z4Q0ZOYWRRV01iQlBZejBj?= =?utf-8?B?ZWVXRWp5ZUN0UzlOOGpTSDl2bUtpSit5K3N6Q2N6VG5lN3RPcHk4eU1Ick8v?= =?utf-8?Q?BrqM6daNzwEzqsh3Or7+ixyHI?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 25c5adf8-e7d3-4f01-98b0-08dc39f14515 X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB4294.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Mar 2024 13:12:39.0071 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: YTwkzAG9OSXmlK4XS80QO4CJY9HNfuXiNnXtT7EXphuLcL2KU5xJ6FGOOdlFK1EJ X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB8780 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 On 2/29/2024 3:42 PM, Thomas Monjalon wrote: > Speed capabilities of a NIC may be discovered through its Linux > kernel driver. It is especially useful for bifurcated drivers, > so they don't have to duplicate the same logic in the DPDK driver. > > Parsing ethtool speed capabilities is made easy thanks to > the functions added in ethdev for internal usage only. > Of course these functions work only on Linux, > so they are not compiled in other environments. > > In order to ease parsing, the ethtool macro names are parsed > externally in a shell command which generates a C array > included in this patch. > It also avoids to depend on a kernel version. > This C array should be updated in future to get latest ethtool bits. > Note it is easier to update this array than adding new cases > in a parsing code. > > The types in the functions are following the ethtool type: > uint32_t for bitmaps, and int8_t for the number of 32-bitmaps. > > Signed-off-by: Thomas Monjalon > --- > > A follow-up patch will be sent to use these functions in mlx5. > I suspect mana could use this parsing as well. > Is the usecase driver get link info via ibverbs and convert it to DPDK link info? How complex or duplicated effort to get link info directly via DPDK functions? Because this approach is can be applied to only limited devices in DPDK and solving an issue DPDK already has a solution, does it worth to the code it adds? > --- > lib/ethdev/ethdev_linux_ethtool.c | 161 ++++++++++++++++++++++++++++++ > lib/ethdev/ethdev_linux_ethtool.h | 41 ++++++++ > lib/ethdev/meson.build | 9 ++ > lib/ethdev/version.map | 3 + > 4 files changed, 214 insertions(+) > create mode 100644 lib/ethdev/ethdev_linux_ethtool.c > create mode 100644 lib/ethdev/ethdev_linux_ethtool.h > > diff --git a/lib/ethdev/ethdev_linux_ethtool.c b/lib/ethdev/ethdev_linux_ethtool.c > new file mode 100644 > index 0000000000..0ece172a75 > --- /dev/null > +++ b/lib/ethdev/ethdev_linux_ethtool.c > @@ -0,0 +1,161 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright (c) 2024 NVIDIA Corporation & Affiliates > + */ > + > +#include > + > +#include "rte_ethdev.h" > +#include "ethdev_linux_ethtool.h" > + > +/* Link modes sorted with index as defined in ethtool. > + * Values are speed in Mbps with LSB indicating duplex. > + * > + * The ethtool bits definition should not change as it is a kernel API. > + * Using raw numbers directly avoids checking API availability > + * and allows to compile with new bits included even on an old kernel. > + * > + * The array below is built from bit definitions with this shell command: > + * sed -rn 's;.*(ETHTOOL_LINK_MODE_)([0-9]+)([0-9a-zA-Z_]*).*= *([0-9]*).*;'\ > + * '[\4] = \2, /\* \1\2\3 *\/;p' /usr/include/linux/ethtool.h | > + * awk '/_Half_/{$3=$3+1","}1' > + */ > +static uint32_t link_modes[] = { > + [0] = 11, /* ETHTOOL_LINK_MODE_10baseT_Half_BIT */ > + [1] = 10, /* ETHTOOL_LINK_MODE_10baseT_Full_BIT */ > + [2] = 101, /* ETHTOOL_LINK_MODE_100baseT_Half_BIT */ > + [3] = 100, /* ETHTOOL_LINK_MODE_100baseT_Full_BIT */ > + [4] = 1001, /* ETHTOOL_LINK_MODE_1000baseT_Half_BIT */ > + [5] = 1000, /* ETHTOOL_LINK_MODE_1000baseT_Full_BIT */ > + [12] = 10000, /* ETHTOOL_LINK_MODE_10000baseT_Full_BIT */ > + [15] = 2500, /* ETHTOOL_LINK_MODE_2500baseX_Full_BIT */ > + [17] = 1000, /* ETHTOOL_LINK_MODE_1000baseKX_Full_BIT */ > + [18] = 10000, /* ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT */ > + [19] = 10000, /* ETHTOOL_LINK_MODE_10000baseKR_Full_BIT */ > + [20] = 10000, /* ETHTOOL_LINK_MODE_10000baseR_FEC_BIT */ > + [21] = 20000, /* ETHTOOL_LINK_MODE_20000baseMLD2_Full_BIT */ > + [22] = 20000, /* ETHTOOL_LINK_MODE_20000baseKR2_Full_BIT */ > + [23] = 40000, /* ETHTOOL_LINK_MODE_40000baseKR4_Full_BIT */ > + [24] = 40000, /* ETHTOOL_LINK_MODE_40000baseCR4_Full_BIT */ > + [25] = 40000, /* ETHTOOL_LINK_MODE_40000baseSR4_Full_BIT */ > + [26] = 40000, /* ETHTOOL_LINK_MODE_40000baseLR4_Full_BIT */ > + [27] = 56000, /* ETHTOOL_LINK_MODE_56000baseKR4_Full_BIT */ > + [28] = 56000, /* ETHTOOL_LINK_MODE_56000baseCR4_Full_BIT */ > + [29] = 56000, /* ETHTOOL_LINK_MODE_56000baseSR4_Full_BIT */ > + [30] = 56000, /* ETHTOOL_LINK_MODE_56000baseLR4_Full_BIT */ > + [31] = 25000, /* ETHTOOL_LINK_MODE_25000baseCR_Full_BIT */ > + [32] = 25000, /* ETHTOOL_LINK_MODE_25000baseKR_Full_BIT */ > + [33] = 25000, /* ETHTOOL_LINK_MODE_25000baseSR_Full_BIT */ > + [34] = 50000, /* ETHTOOL_LINK_MODE_50000baseCR2_Full_BIT */ > + [35] = 50000, /* ETHTOOL_LINK_MODE_50000baseKR2_Full_BIT */ > + [36] = 100000, /* ETHTOOL_LINK_MODE_100000baseKR4_Full_BIT */ > + [37] = 100000, /* ETHTOOL_LINK_MODE_100000baseSR4_Full_BIT */ > + [38] = 100000, /* ETHTOOL_LINK_MODE_100000baseCR4_Full_BIT */ > + [39] = 100000, /* ETHTOOL_LINK_MODE_100000baseLR4_ER4_Full_BIT */ > + [40] = 50000, /* ETHTOOL_LINK_MODE_50000baseSR2_Full_BIT */ > + [41] = 1000, /* ETHTOOL_LINK_MODE_1000baseX_Full_BIT */ > + [42] = 10000, /* ETHTOOL_LINK_MODE_10000baseCR_Full_BIT */ > + [43] = 10000, /* ETHTOOL_LINK_MODE_10000baseSR_Full_BIT */ > + [44] = 10000, /* ETHTOOL_LINK_MODE_10000baseLR_Full_BIT */ > + [45] = 10000, /* ETHTOOL_LINK_MODE_10000baseLRM_Full_BIT */ > + [46] = 10000, /* ETHTOOL_LINK_MODE_10000baseER_Full_BIT */ > + [47] = 2500, /* ETHTOOL_LINK_MODE_2500baseT_Full_BIT */ > + [48] = 5000, /* ETHTOOL_LINK_MODE_5000baseT_Full_BIT */ > + [52] = 50000, /* ETHTOOL_LINK_MODE_50000baseKR_Full_BIT */ > + [53] = 50000, /* ETHTOOL_LINK_MODE_50000baseSR_Full_BIT */ > + [54] = 50000, /* ETHTOOL_LINK_MODE_50000baseCR_Full_BIT */ > + [55] = 50000, /* ETHTOOL_LINK_MODE_50000baseLR_ER_FR_Full_BIT */ > + [56] = 50000, /* ETHTOOL_LINK_MODE_50000baseDR_Full_BIT */ > + [57] = 100000, /* ETHTOOL_LINK_MODE_100000baseKR2_Full_BIT */ > + [58] = 100000, /* ETHTOOL_LINK_MODE_100000baseSR2_Full_BIT */ > + [59] = 100000, /* ETHTOOL_LINK_MODE_100000baseCR2_Full_BIT */ > + [60] = 100000, /* ETHTOOL_LINK_MODE_100000baseLR2_ER2_FR2_Full_BIT */ > + [61] = 100000, /* ETHTOOL_LINK_MODE_100000baseDR2_Full_BIT */ > + [62] = 200000, /* ETHTOOL_LINK_MODE_200000baseKR4_Full_BIT */ > + [63] = 200000, /* ETHTOOL_LINK_MODE_200000baseSR4_Full_BIT */ > + [64] = 200000, /* ETHTOOL_LINK_MODE_200000baseLR4_ER4_FR4_Full_BIT */ > + [65] = 200000, /* ETHTOOL_LINK_MODE_200000baseDR4_Full_BIT */ > + [66] = 200000, /* ETHTOOL_LINK_MODE_200000baseCR4_Full_BIT */ > + [67] = 100, /* ETHTOOL_LINK_MODE_100baseT1_Full_BIT */ > + [68] = 1000, /* ETHTOOL_LINK_MODE_1000baseT1_Full_BIT */ > + [69] = 400000, /* ETHTOOL_LINK_MODE_400000baseKR8_Full_BIT */ > + [70] = 400000, /* ETHTOOL_LINK_MODE_400000baseSR8_Full_BIT */ > + [71] = 400000, /* ETHTOOL_LINK_MODE_400000baseLR8_ER8_FR8_Full_BIT */ > + [72] = 400000, /* ETHTOOL_LINK_MODE_400000baseDR8_Full_BIT */ > + [73] = 400000, /* ETHTOOL_LINK_MODE_400000baseCR8_Full_BIT */ > + [75] = 100000, /* ETHTOOL_LINK_MODE_100000baseKR_Full_BIT */ > + [76] = 100000, /* ETHTOOL_LINK_MODE_100000baseSR_Full_BIT */ > + [77] = 100000, /* ETHTOOL_LINK_MODE_100000baseLR_ER_FR_Full_BIT */ > + [78] = 100000, /* ETHTOOL_LINK_MODE_100000baseCR_Full_BIT */ > + [79] = 100000, /* ETHTOOL_LINK_MODE_100000baseDR_Full_BIT */ > + [80] = 200000, /* ETHTOOL_LINK_MODE_200000baseKR2_Full_BIT */ > + [81] = 200000, /* ETHTOOL_LINK_MODE_200000baseSR2_Full_BIT */ > + [82] = 200000, /* ETHTOOL_LINK_MODE_200000baseLR2_ER2_FR2_Full_BIT */ > + [83] = 200000, /* ETHTOOL_LINK_MODE_200000baseDR2_Full_BIT */ > + [84] = 200000, /* ETHTOOL_LINK_MODE_200000baseCR2_Full_BIT */ > + [85] = 400000, /* ETHTOOL_LINK_MODE_400000baseKR4_Full_BIT */ > + [86] = 400000, /* ETHTOOL_LINK_MODE_400000baseSR4_Full_BIT */ > + [87] = 400000, /* ETHTOOL_LINK_MODE_400000baseLR4_ER4_FR4_Full_BIT */ > + [88] = 400000, /* ETHTOOL_LINK_MODE_400000baseDR4_Full_BIT */ > + [89] = 400000, /* ETHTOOL_LINK_MODE_400000baseCR4_Full_BIT */ > + [90] = 101, /* ETHTOOL_LINK_MODE_100baseFX_Half_BIT */ > + [91] = 100, /* ETHTOOL_LINK_MODE_100baseFX_Full_BIT */ > + [92] = 10, /* ETHTOOL_LINK_MODE_10baseT1L_Full_BIT */ > + [93] = 800000, /* ETHTOOL_LINK_MODE_800000baseCR8_Full_BIT */ > + [94] = 800000, /* ETHTOOL_LINK_MODE_800000baseKR8_Full_BIT */ > + [95] = 800000, /* ETHTOOL_LINK_MODE_800000baseDR8_Full_BIT */ > + [96] = 800000, /* ETHTOOL_LINK_MODE_800000baseDR8_2_Full_BIT */ > + [97] = 800000, /* ETHTOOL_LINK_MODE_800000baseSR8_Full_BIT */ > + [98] = 800000, /* ETHTOOL_LINK_MODE_800000baseVR8_Full_BIT */ > + [99] = 10, /* ETHTOOL_LINK_MODE_10baseT1S_Full_BIT */ > + [100] = 11, /* ETHTOOL_LINK_MODE_10baseT1S_Half_BIT */ > + [101] = 11, /* ETHTOOL_LINK_MODE_10baseT1S_P2MP_Half_BIT */ > +}; > + > +uint32_t > +rte_eth_link_speed_ethtool(enum ethtool_link_mode_bit_indices bit) > +{ > + uint32_t speed; > + int duplex; > + > + /* get mode from array */ > + if (bit >= RTE_DIM(link_modes)) > + return RTE_ETH_LINK_SPEED_AUTONEG; > + speed = link_modes[bit]; > + if (speed == 0) > + return RTE_ETH_LINK_SPEED_AUTONEG; > + RTE_BUILD_BUG_ON(RTE_ETH_LINK_SPEED_AUTONEG != 0); > I think for above two checks, we can't really get the speed from provided ethtool enum, and intention is to return something ineffective, intention is not really return AUTONEG, right? If so why not directly return 0? > + > + /* duplex is LSB */ > + duplex = (speed & 1) ? > + RTE_ETH_LINK_HALF_DUPLEX : > + RTE_ETH_LINK_FULL_DUPLEX; > + speed &= RTE_GENMASK32(31, 1); > As trying to zero the LSB, following also work, speed &= ~UINT32_C(1) > + > + return rte_eth_speed_bitflag(speed, duplex); > +} > + > +uint32_t > +rte_eth_link_speed_glink(const uint32_t *bitmap, int8_t nwords) > +{ > + uint8_t word, bit; > + uint32_t ethdev_bitmap = 0; > + > + if (nwords < 1) > + return 0; > + > + for (word = 0; word < nwords; word++) { > + for (bit = 0; bit < 32; bit++) { > May be (sizeof(bitmap) * CHAR_BIT) instead of hardcoded 32, although not sure if it is required. > + if ((bitmap[word] & RTE_BIT32(bit)) == 0) > + continue; > + ethdev_bitmap |= rte_eth_link_speed_ethtool(word * 32 + bit); > + } > + } > + > + return ethdev_bitmap; > +} > + > +uint32_t > +rte_eth_link_speed_gset(uint32_t legacy_bitmap) > +{ > + return rte_eth_link_speed_glink(&legacy_bitmap, 1); > +} > diff --git a/lib/ethdev/ethdev_linux_ethtool.h b/lib/ethdev/ethdev_linux_ethtool.h > new file mode 100644 > index 0000000000..de235bd5f4 > --- /dev/null > +++ b/lib/ethdev/ethdev_linux_ethtool.h > @@ -0,0 +1,41 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright (c) 2024 NVIDIA Corporation & Affiliates > + */ > + > +#ifndef ETHDEV_ETHTOOL_H > +#define ETHDEV_ETHTOOL_H > + > +#include > +#include > + > +#include > + > +#ifdef __cplusplus > +extern "C" { > +#endif > + > +/* > + * Convert bit from ETHTOOL_LINK_MODE_* to RTE_ETH_LINK_SPEED_* > + */ > +__rte_internal > +uint32_t rte_eth_link_speed_ethtool(enum ethtool_link_mode_bit_indices bit); > + > +/* > + * Convert bitmap from ETHTOOL_GLINKSETTINGS ethtool_link_settings::link_mode_masks > + * to bitmap RTE_ETH_LINK_SPEED_* > + */ > +__rte_internal > +uint32_t rte_eth_link_speed_glink(const uint32_t *bitmap, int8_t nwords); > + > +/* > + * Convert bitmap from deprecated ETHTOOL_GSET ethtool_cmd::supported > + * to bitmap RTE_ETH_LINK_SPEED_* > + */ > +__rte_internal > +uint32_t rte_eth_link_speed_gset(uint32_t legacy_bitmap); > + > +#ifdef __cplusplus > +} > +#endif > + > +#endif /* ETHDEV_ETHTOOL_H */ > diff --git a/lib/ethdev/meson.build b/lib/ethdev/meson.build > index d11f06bc88..f1d2586591 100644 > --- a/lib/ethdev/meson.build > +++ b/lib/ethdev/meson.build > @@ -44,6 +44,15 @@ driver_sdk_headers += files( > 'ethdev_vdev.h', > ) > > +if is_linux > + driver_sdk_headers += files( > + 'ethdev_linux_ethtool.h', > + ) > + sources += files( > + 'ethdev_linux_ethtool.c', > + ) > +endif > + > Should meson check if 'linux/ethtool.h' exists, for anycase?