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 83C2C3A1D02; Sun, 14 Jun 2026 17:01:05 +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=1781456465; cv=none; b=ncw4Bnk3J4YacN/6aHoJhjmRTjaTPM9PNFbKfDxfz9L0ccXlj1KTwWl5oyHHftbVcjrt20H17TFW+J+LsJreA9KwaskLUphWRp+72JkwWKFtS0oNfjm0KOqC2rS28AMo6/EiZJO2jEpnpKkmX8bxzNbUAN7O0mfdwnkK5URPwI8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781456465; c=relaxed/simple; bh=m7fMZd4QPaVgOUTOdWp9XB+S4KWmIYfMD2B1l/DfpoY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GS6K6yIXCsL6KI4LLIN4cXQEqFjZsnULvSimkEFSptTX+daqiyNnKI7vRwNgoPH8ukw6GJxFTqZA6k2yMmdN9DLRneyE40uOoilwuUMGqQ/2jUNrvG2iZt/axn2EA3ByfWolfmzEYRcfbnTUGLA52a7prGeyEDbwnhu16WrasJA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=of1Gbrwf; 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="of1Gbrwf" Received: by smtp.kernel.org (Postfix) with ESMTPS id 1AA47C2BCC7; Sun, 14 Jun 2026 17:01:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1781456465; bh=m7fMZd4QPaVgOUTOdWp9XB+S4KWmIYfMD2B1l/DfpoY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=of1GbrwfoxTFaI2ufPnnux/DDKfUBS9M5tgulD4zcp/s0WdNccxzWNLzA2xPg69PK LVHY/alW9jGHTA2cekv62wq6kxjtDSCnBE7rvoSWHs2DDakrsqXHnttG9L+Os/gWIh amtn6y4QrMFVXDyJjBFdjLdjY/ELtDzwsrvr1IVV0GwCexx/pxBAqSayybH4LFYlzJ sYGgri7R8BgHqGJ3CR59b388XJTyDWWKYyePEWT+sAerq0VtyKaaodDvtf4hPlsOlK P62CRdGYG1SUaRdKf7d9rRABG+bKf1gmVDpXOT23fENHP1szg+QeWZwMSJZVMbKVYi E4XWq+T2zfxWA== 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 079CDCD98C5; Sun, 14 Jun 2026 17:01:05 +0000 (UTC) From: Selvamani Rajagopal via B4 Relay Date: Sun, 14 Jun 2026 10:00:17 -0700 Subject: [PATCH net-next v5 01/15] net: phy: Helper to read and write through C45 without lock Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20260614-s2500-mac-phy-support-v5-1-89874b72f725@onsemi.com> References: <20260614-s2500-mac-phy-support-v5-0-89874b72f725@onsemi.com> In-Reply-To: <20260614-s2500-mac-phy-support-v5-0-89874b72f725@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.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1781456462; l=3723; i=Selvamani.Rajagopal@onsemi.com; s=20260531; h=from:subject:message-id; bh=lBQ+674jNGkyaGL8OfZpND02o9ArYGOV5TbVQ5zSlUk=; b=+DEHuzUq5wl3gnTiSd6iU2cw6QXfJxXtOe8oabCSo5/jTnputSHvB/e1MM7+8CBHqkEy4IPSu aUDumvniMZTDO4ASJqnZesfo4ig3BBnGIQwNQLKt2sVTCoJbQhsWxlh 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 initiate read and write through C45 bus protocol without mdio bus lock. This will help PHYs to avoid indirect C22 API calls for C45 bus protocol which may not be supported by the PHY. Reviewed-by: Andrew Lunn Signed-off-by: Selvamani Rajagopal --- changes in v5 - no change changes in v4 - lockdep_assert_held added to ensure correct calling convention changes in v3 - Added the genphy APIs to initiate Clause 45 register read/write - first patch --- drivers/net/phy/phy_device.c | 55 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/phy.h | 4 ++++ 2 files changed, 59 insertions(+) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 0615228459ef..b82b99d08132 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -2787,6 +2787,61 @@ int genphy_write_mmd_unsupported(struct phy_device *phdev, int devnum, } EXPORT_SYMBOL(genphy_write_mmd_unsupported); +/** + * genphy_phy_read_mmd - Helper for reading a register without lock + * from the given MMD and PHY. + * @phydev: The phy_device struct + * @devnum: The MMD to read from + * @regnum: The register on the MMD to read + * + * Description: PHYs can have both C22 and C45 registers space. Once PHY + * is discovered via C22 bus protocol, it uses C22 indirect access to + * access C45 registers. Some PHYs, like 10Base-T1S PHYs defined by OPEN + * Alliance 10BASE‑T1x, support only direct access. + * + * If PHY indicates C45 support through DTS entry, it avoid C22 APIs + * entirely and therefore generic MDIO registers are inaccessible. + * + * MDIO bus isn't locked here because when called through read_mmd + * callback of phy_driver, caller is expected to lock the bus as + * implemented in phy_read_mmd. + * + * Returns: Register value if successful, negative error code on failure. + */ +int genphy_phy_read_mmd(struct phy_device *phydev, int devnum, + u16 regnum) +{ + struct mii_bus *bus = phydev->mdio.bus; + int addr = phydev->mdio.addr; + + lockdep_assert_held(&bus->mdio_lock); + return __mdiobus_c45_read(bus, addr, devnum, regnum); +} +EXPORT_SYMBOL(genphy_phy_read_mmd); + +/** + * genphy_phy_write_mmd - Helper for writing a register without lock + * to the given MMD and PHY. + * @phydev: The phy_device struct + * @devnum: The MMD to write to + * @regnum: The register on the MMD to write + * @val: Value to write + * + * Description: Similar to genphy_phy_read_mmd + * + * Returns: 0 if successful, negative error code on failure. + */ +int genphy_phy_write_mmd(struct phy_device *phydev, int devnum, + u16 regnum, u16 val) +{ + struct mii_bus *bus = phydev->mdio.bus; + int addr = phydev->mdio.addr; + + lockdep_assert_held(&bus->mdio_lock); + return __mdiobus_c45_write(bus, addr, devnum, regnum, val); +} +EXPORT_SYMBOL(genphy_phy_write_mmd); + 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 199a7aaa341b..8266dd4a8dbe 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -2301,6 +2301,10 @@ 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_phy_write_mmd(struct phy_device *phydev, int devnum, + u16 regnum, u16 val); +int genphy_phy_read_mmd(struct phy_device *phydev, int devnum, + u16 regnum); /* Clause 37 */ int genphy_c37_config_aneg(struct phy_device *phydev); -- 2.43.0