From mboxrd@z Thu Jan 1 00:00:00 1970 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 25870C282C5 for ; Mon, 3 Mar 2025 09:13:03 +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=srKaH+dUPNcj7myLBF3rWvtWswbd4aKF0FGqhtNPS/A=; b=migcrLzwh3he4T8aNy34t6+cUN ZIDDD3UlB79bnsQ2nWi+yOVnX/udGU5+Khl7BQxumUG90f5/H8pUiAIc8CnBM11z7MW2RXuu8ChkB exp9DRIlnw/UPI1WJQpVUt9xas6+T+bkjZpdNBkWPIagJl3E6t9/qNIfWxMrkDC0yZhA/1+B92DRD 4+lbxnbGURtDrHyEqwo33gkFnTeyFmHyIQF0G0Fvp+h9YlhasuAAmIkv9JKTzNfMlHXpQaJEfAoVX 9F2XhaRdJWi4O7jAWvcc42WZVRTHri6MT6KUzEoo98W82G2TnNow/x7PVDHHFA72tJrMRyhEpV5Qs bYUkto9w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tp1r1-000000005QI-0vAl; Mon, 03 Mar 2025 09:12:51 +0000 Received: from relay4-d.mail.gandi.net ([217.70.183.196]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tp1i3-000000003NL-0ea9 for linux-arm-kernel@lists.infradead.org; Mon, 03 Mar 2025 09:03:36 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id CB4FF433D6; Mon, 3 Mar 2025 09:03:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1740992613; 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=srKaH+dUPNcj7myLBF3rWvtWswbd4aKF0FGqhtNPS/A=; b=Xth63yyVKef/3QCJn/XXggPX9L2ePfszv42r5rzFuDUcWBvJtzlCnfsrHYL5Pdv650CCjx E4I7BsxEhNCdBHSzAGiUwVm9QNILcyE8XBvDwsNH809XDY5xewyGQFCmgtvqzBWcLNqRtm x8wKmQ6N1CGA7vYceLZ7GrJbVfzVWyqzvZLg6b0QIdqqDpc9f5pA2bUNxvnVizHy4qrXdU +41Zt+fgTBIXyyYsJY2IEY9Ez57niUgCwxc1aAXzSVtZy8eDoIkHwKFDsgjsE12Gi5VdwJ GFpRRQFVoE19X7lKYZohG3TLKNYezvYflrz7VmdcTnN4CkNn/Dzmd+Kqfe739g== 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=20Maincent?= , Oleksij Rempel , Simon Horman , Romain Gantois Subject: [PATCH net-next v4 05/13] net: phy: phy_caps: Introduce phy_caps_valid Date: Mon, 3 Mar 2025 10:03:11 +0100 Message-ID: <20250303090321.805785-6-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250303090321.805785-1-maxime.chevallier@bootlin.com> References: <20250303090321.805785-1-maxime.chevallier@bootlin.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdelkeejudcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfitefpfffkpdcuggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedtudenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepofgrgihimhgvucevhhgvvhgrlhhlihgvrhcuoehmrgigihhmvgdrtghhvghvrghllhhivghrsegsohhothhlihhnrdgtohhmqeenucggtffrrghtthgvrhhnpeevgedtffelffelveeuleelgfejfeevvdejhfehgeefgfffvdefteegvedutefftdenucfkphepvdgrtddumegtsgduleemkegugegtmeelfhdttdemsggtvddumeekkeelleemheegtdgtmegvheelvgenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpedvrgdtudemtggsudelmeekugegtgemlehftddtmegstgdvudemkeekleelmeehgedttgemvgehlegvpdhhvghlohepfhgvughorhgrrdhhohhmvgdpmhgrihhlfhhrohhmpehmrgigihhmvgdrtghhvghvrghllhhivghrsegsohhothhlihhnrdgtohhmpdhnsggprhgtphhtthhopedvtddprhgtphhtthhopegurghvvghmsegurghvvghmlhhofhhtrdhnvghtpdhrtghpthhtoheprghnughrvgifsehluhhnnhdrtghhpdhrtghpthhtohepkhhusggrsehkvghrnhgvlhdrohhrghdprhgtphhtthhopegvughumhgri igvthesghhoohhglhgvrdgtohhmpdhrtghpthhtohepphgrsggvnhhisehrvgguhhgrthdrtghomhdprhgtphhtthhopehlihhnuhigsegrrhhmlhhinhhugidrohhrghdruhhkpdhrtghpthhtohephhhkrghllhifvghithdusehgmhgrihhlrdgtohhmpdhrtghpthhtohepmhgrgihimhgvrdgthhgvvhgrlhhlihgvrhessghoohhtlhhinhdrtghomh X-GND-Sasl: maxime.chevallier@bootlin.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250303_010335_332544_27E59230 X-CRM114-Status: GOOD ( 13.36 ) 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 With the link_capabilities array, it's trivial to validate a given mask againts a tuple. Create a helper for that purpose, and use it to replace a phy_settings lookup in phy_check_valid(); Signed-off-by: Maxime Chevallier --- V4: No changes drivers/net/phy/phy-caps.h | 1 + drivers/net/phy/phy.c | 2 +- drivers/net/phy/phy_caps.c | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/drivers/net/phy/phy-caps.h b/drivers/net/phy/phy-caps.h index a44d983eaed8..f35ede4e557d 100644 --- a/drivers/net/phy/phy-caps.h +++ b/drivers/net/phy/phy-caps.h @@ -43,6 +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); +bool phy_caps_valid(int speed, int duplex, const unsigned long *linkmodes); #endif /* __PHY_CAPS_H */ diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index 3128df03feda..8df37d221fba 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -260,7 +260,7 @@ unsigned int phy_supported_speeds(struct phy_device *phy, */ bool phy_check_valid(int speed, int duplex, unsigned long *features) { - return !!phy_lookup_setting(speed, duplex, features, true); + return phy_caps_valid(speed, duplex, features); } EXPORT_SYMBOL(phy_check_valid); diff --git a/drivers/net/phy/phy_caps.c b/drivers/net/phy/phy_caps.c index 132758d2eb8d..8ce7dca1acd0 100644 --- a/drivers/net/phy/phy_caps.c +++ b/drivers/net/phy/phy_caps.c @@ -128,3 +128,22 @@ void phy_caps_linkmode_max_speed(u32 max_speed, unsigned long *linkmodes) else break; } + +/** + * phy_caps_valid() - Validate a linkmodes set agains given speed and duplex + * @speed: input speed to validate + * @duplex: input duplex to validate. Passing DUPLEX_UNKNOWN is always not valid + * @linkmodes: The linkmodes to validate + * + * Returns: True if at least one of the linkmodes in @linkmodes can function at + * the given speed and duplex, false otherwise. + */ +bool phy_caps_valid(int speed, int duplex, const unsigned long *linkmodes) +{ + int capa = speed_duplex_to_capa(speed, duplex); + + if (capa < 0) + return false; + + return linkmode_intersects(link_caps[capa].linkmodes, linkmodes); +} -- 2.48.1