From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 CA4E237DAB5; Wed, 8 Jul 2026 17:12:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783530756; cv=none; b=h3UEMWPVkpGAsUOnLMUf8TJpf1zA/opoCksSamilIwNjpUGMya3i07RPTCzH3tJ1NFyM2aenIVLXhJlts8tZGtBxkgEUVDEUm1FXOHKVYWsA7PA9njimtm/DJDkSRjPtEsBUJ+Viqo+tvM79s8tWVvO0+tOvNv2Wh9bM9Rmkcj8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783530756; c=relaxed/simple; bh=DKXoF2ySQ3cdP8c4lc14cctw+rliLWlJq0ZwphmqZzY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Hg3HPZvDR0DTWhC8klrgCU4i+9m7BlEkwoZFEM4byvS9kLRtLNf5NWhD6QIXsFJIOHGOZdtPBSIVtOC71f+b/z9//9GHqY+0LyjTi1Ic0jJPpbC6KFNG7g1tQLJOGBbmkbvSBtAOOzwVc9EGCswhQAndf6TuEadx6a3oVfQg9EM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mCEdRVUb; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mCEdRVUb" Received: by smtp.kernel.org (Postfix) with ESMTPS id 9411CC2BCFC; Wed, 8 Jul 2026 17:12:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1783530756; bh=DKXoF2ySQ3cdP8c4lc14cctw+rliLWlJq0ZwphmqZzY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=mCEdRVUbb8aI+DfA/Gg5ednJ1IsT4An67DyzekgfoP8qF4BXuRjryWoH1YlCw4y4z oywLGaOSMqoE3sw+QRhYdcrxYs3bPizJxLGvTOQEIqnZMxsgkgYxU7vxGpHW+I2eEA o1Y2d6+5k/iCV/KFjIoeMJDYK82fsprvbCnSqKWjz0kIBNuBAWBnf7uvu7QBNvOPuR QY90ZBS78bvPNH3ajmE6B/HIN8/NXMsxPJSngKSKjR3bPFpEaEh83lo1+Tk5pz8sL5 t0XW2NjwClUKD4yUgGhLoAZQEr88Oe/Entj53y2w6yEN7aUzq6p1Izq9Xky3z1z+h0 Eua7R38HZRBZQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 805D0C43458; Wed, 8 Jul 2026 17:12:36 +0000 (UTC) From: Selvamani Rajagopal via B4 Relay Date: Wed, 08 Jul 2026 10:12:34 -0700 Subject: [PATCH net-next v7 04/15] net: phy: Helper to modify PHY loopback mode only Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260708-s2500-mac-phy-support-v7-4-478c877aa1a9@onsemi.com> References: <20260708-s2500-mac-phy-support-v7-0-478c877aa1a9@onsemi.com> In-Reply-To: <20260708-s2500-mac-phy-support-v7-0-478c877aa1a9@onsemi.com> To: Andrew Lunn , Piergiorgio Beruto , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , Parthiban Veerasooran , Selva Rajagopal , Richard Cochran , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Simon Horman , Jonathan Corbet , Shuah Khan Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-doc@vger.kernel.org, Jerry Ray , Selvamani Rajagopal X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1783530757; l=3409; i=Selvamani.Rajagopal@onsemi.com; s=20260531; h=from:subject:message-id; bh=u0hfBz58vQHn/EuaGbrplxopzhN6yg8AWzJjwXaz/Xc=; b=VxGbkbdhTVWFaV1RdJ3/XSTcR7C9mqDEuULZetDhnTtRLeW0dKsx/FeYMU15lLiUi35e1cOMK FkU9Vzl6zyADytIiGrTNV0DEssTjDog7xgwyeJM4aSAaeii99KB4J/P X-Developer-Key: i=Selvamani.Rajagopal@onsemi.com; a=ed25519; pk=5QRdM0HS/LGWWcUZZ9hVfZ+qbPQGZCumcTXOiN7Fyug= X-Endpoint-Received: by B4 Relay for Selvamani.Rajagopal@onsemi.com/20260531 with auth_id=803 X-Original-From: Selvamani Rajagopal Reply-To: Selvamani.Rajagopal@onsemi.com From: Selvamani Rajagopal Generic helper function to modify loopback bit of the PHY without modifying any other bit. This will help the PHYs that may have fixed speed, like 10Base-T1S or PHYs that don't need any other settings to set them in loopback mode. Signed-off-by: Selvamani Rajagopal --- changes in v7 - No change changes in v6 - No change changes in v5 - No change changes in v4 - Created a new genphy API to set the loopback. No other PHY registers touched. --- drivers/net/phy/dp83867.c | 11 +---------- drivers/net/phy/phy_device.c | 20 ++++++++++++++++++++ include/linux/phy.h | 2 ++ 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/drivers/net/phy/dp83867.c b/drivers/net/phy/dp83867.c index 88255e92b4cd..01ea2e8dd253 100644 --- a/drivers/net/phy/dp83867.c +++ b/drivers/net/phy/dp83867.c @@ -991,15 +991,6 @@ static void dp83867_link_change_notify(struct phy_device *phydev) } } -static int dp83867_loopback(struct phy_device *phydev, bool enable, int speed) -{ - if (enable && speed) - return -EOPNOTSUPP; - - return phy_modify(phydev, MII_BMCR, BMCR_LOOPBACK, - enable ? BMCR_LOOPBACK : 0); -} - static int dp83867_led_brightness_set(struct phy_device *phydev, u8 index, enum led_brightness brightness) @@ -1204,7 +1195,7 @@ static struct phy_driver dp83867_driver[] = { .resume = dp83867_resume, .link_change_notify = dp83867_link_change_notify, - .set_loopback = dp83867_loopback, + .set_loopback = genphy_loopback_fixed_speed, .led_brightness_set = dp83867_led_brightness_set, .led_hw_is_supported = dp83867_led_hw_is_supported, diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index b82b99d08132..11fd204eea16 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -2842,6 +2842,26 @@ int genphy_phy_write_mmd(struct phy_device *phydev, int devnum, } EXPORT_SYMBOL(genphy_phy_write_mmd); +/** + * genphy_loopback_fixed_speed - Helper to modify the PHY loopback mode + * without affecting any other settings. + * @phydev: The phy_device struct + * @enable: Flag to enable or disable the PHY level loopback. + * @speed: Speed setting. Not expected to be set. Error if it is set. + * + * Returns: 0 if successful, negative error code on failure. + */ +int genphy_loopback_fixed_speed(struct phy_device *phydev, bool enable, + int speed) +{ + if (enable && speed) + return -EOPNOTSUPP; + + return phy_modify(phydev, MII_BMCR, BMCR_LOOPBACK, + enable ? BMCR_LOOPBACK : 0); +} +EXPORT_SYMBOL(genphy_loopback_fixed_speed); + int genphy_suspend(struct phy_device *phydev) { return phy_set_bits(phydev, MII_BMCR, BMCR_PDOWN); diff --git a/include/linux/phy.h b/include/linux/phy.h index 8266dd4a8dbe..61bcd71a3143 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -2301,6 +2301,8 @@ int genphy_read_mmd_unsupported(struct phy_device *phdev, int devad, u16 regnum); int genphy_write_mmd_unsupported(struct phy_device *phdev, int devnum, u16 regnum, u16 val); +int genphy_loopback_fixed_speed(struct phy_device *phydev, bool enable, + int speed); int genphy_phy_write_mmd(struct phy_device *phydev, int devnum, u16 regnum, u16 val); int genphy_phy_read_mmd(struct phy_device *phydev, int devnum, -- 2.43.0