From patchwork Fri Feb 28 14:55:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Chevallier X-Patchwork-Id: 13996605 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 CD0B9C19776 for ; Fri, 28 Feb 2025 15:11:17 +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:References:In-Reply-To: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:List-Owner; bh=+J/HpjUPC0uwoncA0e+2cWmDxmgAJ4APiDJo/YhCFEg=; b=30ruvU2Aen/LRxv30CbxFPvG4J FVMOQ9MavT/PFbMXHvN3FRlDg75Iktn6nf5LIr2vZltivmF5qDUXwgLX41pw378ooMZpltJZLAs00 MgdjC+6QuCxvG2gemvFwG+2FpvWDwf27jrx7e8/5RaWsJ1+uw6I5LOd7duAH1+lPkJHV5vFfoL/Dl v6RZR8oWv6EOoWgRJrZbVZoA4jZEri43nWM0vozz/tFXM7hAuSSF5KzN+1P5U2QliwNOkpxroixr/ /Bq7zDa+rPwik19Bc65AJ6lURYpiwuP+JgCJ77TJmjKDfGGl3UI038d+PeAqQnd007bGqVzZs6wCK hMtPSsbQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1to217-0000000BOxi-44ZM; Fri, 28 Feb 2025 15:11:09 +0000 Received: from relay8-d.mail.gandi.net ([2001:4b98:dc4:8::228]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1to1mH-0000000BLg8-0Juh for linux-arm-kernel@lists.infradead.org; Fri, 28 Feb 2025 14:55:50 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id 9CF1C41DF6; Fri, 28 Feb 2025 14:55:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1740754547; 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: in-reply-to:in-reply-to:references:references; bh=+J/HpjUPC0uwoncA0e+2cWmDxmgAJ4APiDJo/YhCFEg=; b=ozLt+qPLLuklSyoRmzogznyjCRCCvbdAfKRdsF1XeXEzr82UR9Uyv76FQKlj6EkefR8NYG yT2n5ejxdjFbE6ysMIAbldmmNkk97WtoKzeDGB6eD/mtRMMP/6rWcdVEomrKsH43MWArFF J4FA2IlIbKirpht69cE65e7gW+BInXxL3BFKU9JZ1SdMgEKgxDiKjxPeEMyNAe+twgYAAY F9JQc6yRAyNYqw0VW6FDzwh6vCDSOrUinKX5ijVyB6U96EQUE+yUz4pHpjR5+ouO7AXiBc fpAADyO8g/qBD7T8jeKLAB7CFhAT8GxarIb9WgpRIIdlCNJastNeDFhmOZRg7Q== 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 v3 04/13] net: phy: phy_caps: Move __set_linkmode_max_speed to phy_caps Date: Fri, 28 Feb 2025 15:55:29 +0100 Message-ID: <20250228145540.2209551-5-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250228145540.2209551-1-maxime.chevallier@bootlin.com> References: <20250228145540.2209551-1-maxime.chevallier@bootlin.com> MIME-Version: 1.0 X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdeltdeilecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfitefpfffkpdcuggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedtudenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepofgrgihimhgvucevhhgvvhgrlhhlihgvrhcuoehmrgigihhmvgdrtghhvghvrghllhhivghrsegsohhothhlihhnrdgtohhmqeenucggtffrrghtthgvrhhnpeevgedtffelffelveeuleelgfejfeevvdejhfehgeefgfffvdefteegvedutefftdenucfkphepvdgrtddumegtsgduleemkegugegtmeelfhdttdemsggtvddumeekkeelleemheegtdgtmegvheelvgenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepihhnvghtpedvrgdtudemtggsudelmeekugegtgemlehftddtmegstgdvudemkeekleelmeehgedttgemvgehlegvpdhhvghlohepfhgvughorhgrrdhhohhmvgdpmhgrihhlfhhrohhmpehmrgigihhmvgdrtghhvghvrghllhhivghrsegsohhothhlihhnrdgtohhmpdhnsggprhgtphhtthhopedvtddprhgtphhtthhopegurghvvghmsegurghvvghmlhhofhhtrdhnvghtpdhrtghpthhtoheprghnughrvgifsehluhhnnhdrtghhpdhrtghpthhtohepkhhusggrsehkvghrnhgvlhdrohhrghdprhgtphhtthhopegvughumhgri igvthesghhoohhglhgvrdgtohhmpdhrtghpthhtohepphgrsggvnhhisehrvgguhhgrthdrtghomhdprhgtphhtthhopehlihhnuhigsegrrhhmlhhinhhugidrohhrghdruhhkpdhrtghpthhtohephhhkrghllhifvghithdusehgmhgrihhlrdgtohhmpdhrtghpthhtohepmhgrgihimhgvrdgthhgvvhgrlhhlihgvrhessghoohhtlhhinhdrtghomh X-GND-Sasl: maxime.chevallier@bootlin.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250228_065549_263348_0812641E X-CRM114-Status: GOOD ( 14.10 ) 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 Convert the __set_linkmode_max_speed to use the link_capabilities array. This makes it easy to clamp the linkmodes to a given max speed. Introduce a new helper phy_caps_linkmode_max_speed to replace the previous one that used phy_settings. Signed-off-by: Maxime Chevallier --- drivers/net/phy/phy-caps.h | 2 ++ drivers/net/phy/phy-core.c | 18 +++--------------- drivers/net/phy/phy_caps.c | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/drivers/net/phy/phy-caps.h b/drivers/net/phy/phy-caps.h index f8cdfdb09242..3f011b63a417 100644 --- a/drivers/net/phy/phy-caps.h +++ b/drivers/net/phy/phy-caps.h @@ -43,5 +43,7 @@ void phy_caps_init(void); size_t phy_caps_speeds(unsigned int *speeds, size_t size, unsigned long *linkmodes); +void phy_caps_linkmode_max_speed(u32 max_speed, unsigned long *linkmodes); + #endif /* __PHY_CAPS_H */ diff --git a/drivers/net/phy/phy-core.c b/drivers/net/phy/phy-core.c index 8533e57c3500..f62bc1be67b2 100644 --- a/drivers/net/phy/phy-core.c +++ b/drivers/net/phy/phy-core.c @@ -7,6 +7,7 @@ #include #include "phylib-internal.h" +#include "phy-caps.h" /** * phy_speed_to_str - Return a string representing the PHY link speed @@ -339,22 +340,9 @@ phy_lookup_setting(int speed, int duplex, const unsigned long *mask, bool exact) } EXPORT_SYMBOL_GPL(phy_lookup_setting); -static void __set_linkmode_max_speed(u32 max_speed, unsigned long *addr) -{ - const struct phy_setting *p; - int i; - - for (i = 0, p = settings; i < ARRAY_SIZE(settings); i++, p++) { - if (p->speed > max_speed) - linkmode_clear_bit(p->bit, addr); - else - break; - } -} - static void __set_phy_supported(struct phy_device *phydev, u32 max_speed) { - __set_linkmode_max_speed(max_speed, phydev->supported); + phy_caps_linkmode_max_speed(max_speed, phydev->supported); } /** @@ -557,7 +545,7 @@ int phy_speed_down_core(struct phy_device *phydev) if (min_common_speed == SPEED_UNKNOWN) return -EINVAL; - __set_linkmode_max_speed(min_common_speed, phydev->advertising); + phy_caps_linkmode_max_speed(min_common_speed, phydev->advertising); return 0; } diff --git a/drivers/net/phy/phy_caps.c b/drivers/net/phy/phy_caps.c index e5c716365b36..9075f9840ebd 100644 --- a/drivers/net/phy/phy_caps.c +++ b/drivers/net/phy/phy_caps.c @@ -103,3 +103,19 @@ size_t phy_caps_speeds(unsigned int *speeds, size_t size, return count; } + +/** + * phy_caps_linkmode_max_speed() - Clamp a linkmodes set to a max speed + * @max_speed: Speed limit for the linkmode set + * @linkmodes: Linkmodes to limit + */ +void phy_caps_linkmode_max_speed(u32 max_speed, unsigned long *linkmodes) +{ + int capa; + + for (capa = __LINK_CAPA_LAST; capa >= 0; capa--) + if (link_caps[capa].speed > max_speed) + linkmode_andnot(linkmodes, linkmodes, link_caps[capa].linkmodes); + else + break; +}