From patchwork Mon Mar 3 09:03:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Chevallier X-Patchwork-Id: 13998412 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 917AAC282C5 for ; Mon, 3 Mar 2025 09:08:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=FNu5/p3bCwoZIxM3jDsSahP+LbfLGMyqj/lEeyoOvo4=; b=Zes9nBkwNhxbZUMKAxtYL98kBG FiAhXWxNR0cvvQSaXfeqdi5IuBfVtWyNxqryqmsaUHJIDAt7K2OKDQJTU1JK2Xr3UN17iE+Mjr5jE GhWW7lLEoRyv0McO/oqgTC9Wns2uk2GMsNnzNyYtc+NMx8w8a58d5tH/21KjcDqjQFZIxtf07bs/E CtGAfXWGf5v4oKClnkxmX3XHLIh/Azo2k8Gt5v1dUoQGSwZgJxLqG/aHK+iq4qYJxsVrcJ2YzYrhA Arf6vi27oaRX6MxRqAMvH1KFbelOTRqcyj4oq8v0hBbLiOz6k36lDGUC2/UWuogqX0n3Mg69jv7dV GF5sNY/Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tp1mP-000000004N4-0LQQ; Mon, 03 Mar 2025 09:08:05 +0000 Received: from relay4-d.mail.gandi.net ([2001:4b98:dc4:8::224]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tp1i0-000000003LE-3PW4 for linux-arm-kernel@lists.infradead.org; Mon, 03 Mar 2025 09:03:35 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id DBACC443F3; Mon, 3 Mar 2025 09:03:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1740992608; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=FNu5/p3bCwoZIxM3jDsSahP+LbfLGMyqj/lEeyoOvo4=; b=iWDAoiCqy4wWy4T2UzzwTqScC1wvB1GCJnSfQc+WKDXBbhFQQd9QxZrkNBaYRybitxKl4E i5aVk8aA4XGh7pjcQwwVyPFSpZHGkI39kLd8c+oefb/lH/ihzJ7QGAmPyrpSCrIbz8I1LT XkNPimrmK0GbDinVjckp6Dwzp41VM55Oios8KpM2+rnvCA+Y3Jo98mR9kGIrMwzYQ83Unr ORvgCuGjMF09CvwzZcnFsScHUchszwbVP3rcHgWNU4JB9ofVAWtqU3a7mAkm0fEQvBFY+7 1gm+cSWtxrMieMRbG7XZmoEzb8rgdbJOthIsznLiv64UOtROvRU9nhnWy4t7bA== From: Maxime Chevallier To: davem@davemloft.net, Andrew Lunn , Jakub Kicinski , Eric Dumazet , Paolo Abeni , Russell King , Heiner Kallweit Cc: Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, thomas.petazzoni@bootlin.com, linux-arm-kernel@lists.infradead.org, Christophe Leroy , Herve Codina , Florian Fainelli , Vladimir Oltean , =?utf-8?q?K=C3=B6ry_Maincent?= , Oleksij Rempel , Simon Horman , Romain Gantois Subject: [PATCH net-next v4 00/13] net: phy: Rework linkmodes handling in a dedicated file Date: Mon, 3 Mar 2025 10:03:06 +0100 Message-ID: <20250303090321.805785-1-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.48.1 MIME-Version: 1.0 X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdelkeejudcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfitefpfffkpdcuggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedtudenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkofgggfestdekredtredttdenucfhrhhomhepofgrgihimhgvucevhhgvvhgrlhhlihgvrhcuoehmrgigihhmvgdrtghhvghvrghllhhivghrsegsohhothhlihhnrdgtohhmqeenucggtffrrghtthgvrhhnpeejhfelieehgfffiefftdffiedvheefteehkedukefgteffteevffeuueejiedtveenucffohhmrghinhepkhgvrhhnvghlrdhorhhgnecukfhppedvrgdtudemtggsudelmeekugegtgemlehftddtmegstgdvudemkeekleelmeehgedttgemvgehlegvnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepvdgrtddumegtsgduleemkegugegtmeelfhdttdemsggtvddumeekkeelleemheegtdgtmegvheelvgdphhgvlhhopehfvgguohhrrgdrhhhomhgvpdhmrghilhhfrhhomhepmhgrgihimhgvrdgthhgvvhgrlhhlihgvrhessghoohhtlhhinhdrtghomhdpnhgspghrtghpthhtohepvddtpdhrtghpthhtohepuggrvhgvmhesuggrvhgvmhhlohhfthdrnhgvthdprhgtphhtthhopegrnhgurhgvfieslhhunhhnrdgthhdprhgtphhtthhopehkuhgsrgeskhgvrhhnvghlr dhorhhgpdhrtghpthhtohepvgguuhhmrgiivghtsehgohhoghhlvgdrtghomhdprhgtphhtthhopehprggsvghnihesrhgvughhrghtrdgtohhmpdhrtghpthhtoheplhhinhhugiesrghrmhhlihhnuhigrdhorhhgrdhukhdprhgtphhtthhopehhkhgrlhhlfigvihhtudesghhmrghilhdrtghomhdprhgtphhtthhopehmrgigihhmvgdrtghhvghvrghllhhivghrsegsohhothhlihhnrdgtohhm X-GND-Sasl: maxime.chevallier@bootlin.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250303_010333_089785_7DCCE896 X-CRM114-Status: GOOD ( 25.06 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hello everyone, This is V4 of the phy_caps series. In a nutshell, this series reworks the way we maintain the list of speed/duplex capablities for each linkmode so that we no longer have multiple definition of these associations. That will help making sure that when people add new linkmodes in include/uapi/linux/ethtool.h, they don't have to update phylib and phylink as well, making the process more straightforward and less error-prone. It also generalises the phy_caps interface to be able to lookup linkmodes from phy_interface_t, which is needed for the multi-port work I've been working on for a while. This V4 addresses Russell's reviews, namely : - Introduce new iterators to traverse the link_caps array in ascending and descending order, making it more explicit and simple. - Remove an unneeded linkmode_zero in patch 9 V1 : https://lore.kernel.org/netdev/20250222142727.894124-1-maxime.chevallier@bootlin.com/ V2 : https://lore.kernel.org/netdev/20250226100929.1646454-1-maxime.chevallier@bootlin.com/ V3 : https://lore.kernel.org/netdev/20250228145540.2209551-1-maxime.chevallier@bootlin.com/ For context, The text below is an extract from the V1 cover : Following the V4 of the phy_port series [1] we've discussed about attempting to extract some of the linkmode <-> capabilities (speed/duplex) <-> interface logic into a dedicated file, so that we can re-use that logic out of phylink. While trying to do that, I might have gotten a bit carried-away, and I'm therefore submitting this series to rework the way we are currently managing the linkmodes <-> capabilities handling. We are currently defining all the possible Ethernet linkmodes in an enum ethtool_link_mode_bit_indices value defined in uapi/linux/ethtool.h : ETHTOOL_LINK_MODE_10baseT_Half_BIT = 0, ETHTOOL_LINK_MODE_10baseT_Full_BIT = 1, ... Each of these modes represents a media-side link definition, and runs at a given speed and duplex. Specific attributes for each modes are stored in net/ethtool/common.c, as an array of struct link_mode_info : struct link_mode_info { int speed; u8 lanes; u8 duplex; } The link_mode_params[] array is the canonical definition for these modes, as (1) there are build-time checks to make sure any new linkmode definition is also defined in this array and (2) this array is always compiled-in, as it's part of the net stack (i.e. it is not phylib-specific). This array is however not optimized for lookups, as it is not ordered in any particular fashion (new modes go at the end, regardless of their speed and duplex). Phylib also includes a similar array, in the form of the phy_settings array in drivers/net/phy/phy-core.c : struct phy_setting { u32 speed; u8 duplex; u8 bit; // The enum index for the linkmode }; The phy_settings array however is ordered by descending speeds. A variety of helpers in phylib rely on that ordering to perform lookups, usually to get one or any linkmode corresponding to a requested speed and duplex. Finally, we have some helpers in phylink (phylink_caps_to_linkmodes) that allows getting the list of linkmodes that match a set of speed and duplex value, all at once. While the phylink and phylib helpers allows for efficient lookups, they have some drawbacks as well : (1) : It's easy to forget updating of all of these helpers and structures when adding a new linkmode. New linkmodes are actually added fairly often, lately either for slow BaseT1 flavours, or for crazy-fast modes (800Gbps modes, but I guess people won't stop there) (2) : Even though the phylink and phylib modes use carefull sorting to speed-up the lookup process, the phylib lookups are usually done in descending speed order and will therefore get slower as people add even faster link speeds. This series introduces a new "link_capabilities" structure that is used to build an array of link_caps : struct link_capabilities { int speed; unsigned int duplex; __ETHTOOL_DECLARE_LINK_MODE_MASK(linkmodes); }; We group these in an array, indexed with LINK_CAPA enums that are basically identical to the phylink MAC_CAPS : ... LINK_CAPA_1000HD, LINK_CAPA_1000FD, LINK_CAPA_2500FD, LINK_CAPA_5000FD, ... We now have an associative array of <-> All compatible linkmodes This array is initialized at phylib-init time based on the content of the link_mode_params[] array from net/ethtool/common.c, that way it is always up-to-date with new modes, and always properly ordered. Patches 3 to 8 then convert all lookups from the phy_settings array into lookups from this link_caps array, hopefully speeding-up lookups in the meantime (we iterate over possible speeds instead of individual linkmodes) This series is not meant to introduce changes in behaviour, however patches 9 and 10 do introduce functionnal changes. When configuring the advert for speeds >= 1G in PHY devices, as well as when constructing the link parameters for fixed links in phylink, we used to rely on phy_settings lookups returning one, and only one, compatible linkmode. This series will make so that the lookups will result on all matching linkmodes being returned, and MAY cause advert/fixed-link configuring more linkmodes. Patches 12 and 13 extract the conversion logic for interface <-> caps from phylink. There are cons as well for this, as this is a bit more init time for phylib, but maybe more importantly, we lose in the precision for the lookups in phy_settings. However, given all the uses for phy_settings (most are just to get speed/duplex), I think this is actually ok, but any comment would be very welcome. This series was tested with : - 10/100/1000M links - 2,5, 5, 10G BaseT links - 1G Fixed link I also made sure that this compiles with the following options : CONFIG_PHYLIB=n CNFIG_PHYLINK=m CONFIG_PHYLIB=m CNFIG_PHYLINK=m CONFIG_PHYLIB=y CNFIG_PHYLINK=y CONFIG_PHYLIB=y All the new helpers that were introduced (in drivers/net/phy/phy-caps.h) are for internal use only (only users should be core stuff, such as phylib and phylink, and in the future, phy_port). Thanks, Maxime [1]: https://lore.kernel.org/netdev/20250213101606.1154014-1-maxime.chevallier@bootlin.com/ Maxime Chevallier (13): net: ethtool: Export the link_mode_params definitions net: phy: Use an internal, searchable storage for the linkmodes net: phy: phy_caps: Move phy_speeds to phy_caps net: phy: phy_caps: Move __set_linkmode_max_speed to phy_caps net: phy: phy_caps: Introduce phy_caps_valid net: phy: phy_caps: Implement link_capabilities lookup by linkmode net: phy: phy_caps: Allow looking-up link caps based on speed and duplex net: phy: phy_device: Use link_capabilities lookup for PHY aneg config net: phylink: Use phy_caps_lookup for fixed-link configuration net: phy: drop phy_settings and the associated lookup helpers net: phylink: Add a mapping between MAC_CAPS and LINK_CAPS net: phylink: Convert capabilities to linkmodes using phy_caps net: phy: phy_caps: Allow getting an phy_interface's capabilities drivers/net/phy/Makefile | 2 +- drivers/net/phy/phy-caps.h | 63 +++++++ drivers/net/phy/phy-core.c | 253 ++----------------------- drivers/net/phy/phy.c | 37 +--- drivers/net/phy/phy_caps.c | 347 +++++++++++++++++++++++++++++++++++ drivers/net/phy/phy_device.c | 13 +- drivers/net/phy/phylink.c | 338 +++++++++------------------------- include/linux/ethtool.h | 8 + include/linux/phy.h | 15 -- net/ethtool/common.c | 1 + net/ethtool/common.h | 7 - 11 files changed, 540 insertions(+), 544 deletions(-) create mode 100644 drivers/net/phy/phy-caps.h create mode 100644 drivers/net/phy/phy_caps.c