From patchwork Sat Feb 22 14:27:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Chevallier X-Patchwork-Id: 13986647 X-Patchwork-Delegate: kuba@kernel.org Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 50D5E15697B; Sat, 22 Feb 2025 14:27:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.199 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740234465; cv=none; b=mLXcAof8iuDA57EhulhZCjQZljv0319AgkcLGhqFB9xxHQ2zgPe96kFlwt8D+NsAHFkL+01nT9vub1bJYEuDFHJA0LlGMVDrzH+aYvqzxKVCdbujsUjqufk0h1oU2i5mt57P6fmyGVnDmIEhwxpfX4ptxfgU+LXRbeBdtzF9mY8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740234465; c=relaxed/simple; bh=+YvIktCb/fVxFNwww8PxXVaxOoa3sY0Nr0wVO//AqfE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OWDajw2VxcUeGn/0gd7Dz1o6k4/1Fl8zuRwEyA4RuWeysHw9ErlK8dgokfgXzt4CNZtrdil+ErVbwEAfwalFFBukDGmJS4rMUtafMXny6MeG1+aEVdOLmcCLoS67Zhity2JEAuUBYONboBxbOVSwxv5+A25hBtlS2Oafcz5mZIQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=CvH19zSB; arc=none smtp.client-ip=217.70.183.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="CvH19zSB" Received: by mail.gandi.net (Postfix) with ESMTPSA id 6DAA344283; Sat, 22 Feb 2025 14:27:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1740234461; 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=X2UNvCkN0fpzej3UIf5ymdteSShbZX9J1yWWnwvU8K0=; b=CvH19zSBYeFJTapfQEc9NnLd8JrQTqMhtcOH3XB9gIZUnjRH3LOwGNa+3axH+xOvqnULK4 gxAhKEJ3PGRJtnwlf+8QgcurMoq4BBGU2X+gTE1Cbc7z6hGneQVMNcrf4HXIOCO0bGaSy3 FcOGRWiBukPbUFMvCG05f8ygzegU3a8vHjsYlX6G+E3fO2bjuWom8oFE8tmPokLcf0Aqdd ZKWBpwa7Ygdi0XI3DuqsoQrrrRHkmUJ2QC7CFpPrJ+s+G971LiWWNtE8T/QY1jFOPR2Y5K +csuvGUZs7Ohwitl+aHHdEwDfMPLZtv2GeuBh3x6qGvWMnE9DsA1JAK2+BiqeQ== 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 07/13] net: phy: phy_caps: Move __set_linkmode_max_speed to phy_caps Date: Sat, 22 Feb 2025 15:27:19 +0100 Message-ID: <20250222142727.894124-8-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250222142727.894124-1-maxime.chevallier@bootlin.com> References: <20250222142727.894124-1-maxime.chevallier@bootlin.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdejfeduiecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfitefpfffkpdcuggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedtudenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepofgrgihimhgvucevhhgvvhgrlhhlihgvrhcuoehmrgigihhmvgdrtghhvghvrghllhhivghrsegsohhothhlihhnrdgtohhmqeenucggtffrrghtthgvrhhnpeevgedtffelffelveeuleelgfejfeevvdejhfehgeefgfffvdefteegvedutefftdenucfkphepvdgrtddumegtsgduleemkegugegtmeelfhdttdemsggtvddumeekkeelleemheegtdgtmegvheelvgenucevlhhushhtvghrufhiiigvpeegnecurfgrrhgrmhepihhnvghtpedvrgdtudemtggsudelmeekugegtgemlehftddtmegstgdvudemkeekleelmeehgedttgemvgehlegvpdhhvghlohepfhgvughorhgrrdhhohhmvgdpmhgrihhlfhhrohhmpehmrgigihhmvgdrtghhvghvrghllhhivghrsegsohhothhlihhnrdgtohhmpdhnsggprhgtphhtthhopedvtddprhgtphhtthhopegurghvvghmsegurghvvghmlhhofhhtrdhnvghtpdhrtghpthhtoheprghnughrvgifsehluhhnnhdrtghhpdhrtghpthhtohepkhhusggrsehkvghrnhgvlhdrohhrghdprhgtphhtthhopegvughumhgri igvthesghhoohhglhgvrdgtohhmpdhrtghpthhtohepphgrsggvnhhisehrvgguhhgrthdrtghomhdprhgtphhtthhopehlihhnuhigsegrrhhmlhhinhhugidrohhrghdruhhkpdhrtghpthhtohephhhkrghllhifvghithdusehgmhgrihhlrdgtohhmpdhrtghpthhtohepmhgrgihimhgvrdgthhgvvhgrlhhlihgvrhessghoohhtlhhinhdrtghomh X-GND-Sasl: maxime.chevallier@bootlin.com X-Patchwork-Delegate: kuba@kernel.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 | 19 ++++--------------- drivers/net/phy/phy_caps.c | 16 ++++++++++++++++ 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/drivers/net/phy/phy-caps.h b/drivers/net/phy/phy-caps.h index d4cd91fd0911..55d83661fa18 100644 --- a/drivers/net/phy/phy-caps.h +++ b/drivers/net/phy/phy-caps.h @@ -23,5 +23,7 @@ int phy_interface_max_speed(phy_interface_t interface); 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 e2850d6fe158..300d47d4fd3c 100644 --- a/drivers/net/phy/phy-core.c +++ b/drivers/net/phy/phy-core.c @@ -6,6 +6,8 @@ #include #include +#include "phy-caps.h" + /** * phy_speed_to_str - Return a string representing the PHY link speed * @@ -337,22 +339,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); } /** @@ -556,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 ee8aa1217a6e..cb7a5fa177b1 100644 --- a/drivers/net/phy/phy_caps.c +++ b/drivers/net/phy/phy_caps.c @@ -129,6 +129,22 @@ 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; +} + /** * linkmode_from_caps() - Convert capabilities to ethtool link modes * @linkmodes: ethtool linkmode mask (must be already initialised)