From: Buday Csaba <buday.csaba@prolan.hu>
To: <netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Cc: "Buday Csaba" <buday.csaba@prolan.hu>,
"Csókás Bence" <csokas.bence@prolan.hu>,
"Andrew Lunn" <andrew@lunn.ch>,
"Heiner Kallweit" <hkallweit1@gmail.com>,
"Russell King" <linux@armlinux.org.uk>,
"David S. Miller" <davem@davemloft.net>,
"Eric Dumazet" <edumazet@google.com>,
"Jakub Kicinski" <kuba@kernel.org>,
"Paolo Abeni" <pabeni@redhat.com>
Subject: [PATCH 3/3] net: mdio: reset PHY before attempting to access registers in fwnode_mdiobus_register_phy
Date: Wed, 9 Jul 2025 15:32:22 +0200 [thread overview]
Message-ID: <20250709133222.48802-4-buday.csaba@prolan.hu> (raw)
In-Reply-To: <20250709133222.48802-1-buday.csaba@prolan.hu>
Some PHYs (e.g. LAN8710A) require a reset after power-on,even for
MDIO register access.
The current implementation of fwnode_mdiobus_register_phy() and
get_phy_device() attempt to read the id registers without ensuring
that the PHY had a reset before, which can fail on these devices.
This patch addresses that shortcoming, by always resetting the PHY
(when such property is given in the device tree). To keep the code
impact minimal, a change was also needed in phy_device_remove() to
prevent asserting the reset on device removal.
According to the documentation of phy_device_remove(), it should
reverse the effect of phy_device_register(). Since the reset GPIO
is in undefined state before that, it should be acceptable to leave
it unchanged during removal.
Signed-off-by: Buday Csaba <buday.csaba@prolan.hu>
Cc: Csókás Bence <csokas.bence@prolan.hu>
---
drivers/net/mdio/fwnode_mdio.c | 20 ++++++++++++++++++--
drivers/net/phy/phy_device.c | 3 ---
2 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/drivers/net/mdio/fwnode_mdio.c b/drivers/net/mdio/fwnode_mdio.c
index aea0f03575689..36b60544327b6 100644
--- a/drivers/net/mdio/fwnode_mdio.c
+++ b/drivers/net/mdio/fwnode_mdio.c
@@ -139,8 +139,24 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus,
}
is_c45 = fwnode_device_is_compatible(child, "ethernet-phy-ieee802.3-c45");
- if (is_c45 || fwnode_get_phy_id(child, &phy_id))
- phy = get_phy_device(bus, addr, is_c45);
+ if (is_c45 || fwnode_get_phy_id(child, &phy_id)) {
+ /* get_phy_device is NOT SAFE HERE, since the PHY may need a HW RESET.
+ * First create a dummy PHY device, reset the PHY, then call
+ * get_phy_device.
+ */
+ phy = phy_device_create(bus, addr, 0, 0, NULL);
+ if (!IS_ERR(phy)) {
+ if (is_of_node(child)) {
+ /* fwnode_mdiobus_phy_device_register performs the reset */
+ rc = fwnode_mdiobus_phy_device_register(bus, phy, child, addr);
+ if (!rc)
+ phy_device_remove(phy);
+ /* PHY has been reset at this point. */
+ }
+ phy_device_free(phy);
+ phy = get_phy_device(bus, addr, is_c45);
+ }
+ }
else
phy = phy_device_create(bus, addr, phy_id, 0, NULL);
if (IS_ERR(phy)) {
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 13dea33d86ffa..da4ddce04e5fb 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -1102,9 +1102,6 @@ void phy_device_remove(struct phy_device *phydev)
device_del(&phydev->mdio.dev);
- /* Assert the reset signal */
- phy_device_reset(phydev, 1);
-
mdiobus_unregister_device(&phydev->mdio);
}
EXPORT_SYMBOL(phy_device_remove);
--
2.39.5
next prev parent reply other threads:[~2025-07-09 13:32 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20250709133222.48802-1-buday.csaba@prolan.hu>
2025-07-09 13:32 ` [PATCH 1/3] net: phy: smsc: add proper reset flags for LAN8710A Buday Csaba
2025-07-09 13:40 ` Andrew Lunn
2025-07-09 13:32 ` [PATCH 2/3] net: mdiobus: release reset_gpio in mdiobus_unregister_device() Buday Csaba
2025-07-09 13:38 ` Andrew Lunn
2025-07-09 13:32 ` Buday Csaba [this message]
2025-07-09 13:41 ` [PATCH 3/3] net: mdio: reset PHY before attempting to access registers in fwnode_mdiobus_register_phy Andrew Lunn
2025-07-10 10:11 ` Buday Csaba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250709133222.48802-4-buday.csaba@prolan.hu \
--to=buday.csaba@prolan.hu \
--cc=andrew@lunn.ch \
--cc=csokas.bence@prolan.hu \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hkallweit1@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox