netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christian Marangi <ansuelsmth@gmail.com>
To: Christian Marangi <ansuelsmth@gmail.com>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	Russell King <linux@armlinux.org.uk>,
	netdev@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [net-next RFC PATCH v2 1/3] net: phy: permit PHYs to register a second time
Date: Wed, 26 Mar 2025 01:23:57 +0100	[thread overview]
Message-ID: <20250326002404.25530-2-ansuelsmth@gmail.com> (raw)
In-Reply-To: <20250326002404.25530-1-ansuelsmth@gmail.com>

Some PHY might needs to register AGAIN after a firmware is loaded to
correctly provide the real PHY ID.

It was found that some PHY expose on the BUS with a PHY ID that change
as soon as the PHY firmware is loaded and started.

To better handle this case and provide to the system correct info on
what PHY is actually present on the BUS, introduce a new option for PHY
device, needs_reregister, that register the PHY device 2 times.

With needs_reregister enabled, in phy_device_register() the PHY is first
registered with the driver detected for the PHY ID. The PHY driver is
then released and the PHY ID for the PHY address is rescanned.
The phy_id and c45_ids entry are updated for the PHY device and finally
the PHY is registered again with the more specific PHY driver. (matching
the new PHY ID)

It's assumed that loading the firmware doesn't cause the PHY ID to change
to different vendor or PHY of different family (provided by different
drivers)

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
 drivers/net/phy/phy_device.c | 27 +++++++++++++++++++++++++++
 include/linux/phy.h          |  5 +++++
 2 files changed, 32 insertions(+)

diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 46713d27412b..d5938aacc0fe 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -987,6 +987,33 @@ int phy_device_register(struct phy_device *phydev)
 		goto out;
 	}
 
+	/* Some PHY might needs to register AGAIN after a firmware
+	 * is loaded to correctly provide the real PHY ID.
+	 * For PHY that needs this, release the PHY driver, rescan
+	 * the MDIO bus for the PHY address and attach a driver
+	 * again.
+	 * This second time, the real PHY is provided and the
+	 * more specific PHY driver OPs are used.
+	 */
+	if (phydev->needs_reregister) {
+		device_release_driver(&phydev->mdio.dev);
+
+		if (phydev->is_c45)
+			get_phy_c45_ids(phydev->mdio.bus,
+					phydev->mdio.addr,
+					&phydev->c45_ids);
+		else
+			get_phy_c22_id(phydev->mdio.bus,
+				       phydev->mdio.addr,
+				       &phydev->phy_id);
+
+		err = device_attach(&phydev->mdio.dev);
+		if (err <= 0) {
+			phydev_err(phydev, "failed to reattach\n");
+			goto out;
+		}
+	}
+
 	return 0;
 
  out:
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 19f076a71f94..00ddfbe7033b 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -578,6 +578,10 @@ struct macsec_ops;
  * @mac_managed_pm: Set true if MAC driver takes of suspending/resuming PHY
  * @wol_enabled: Set to true if the PHY or the attached MAC have Wake-on-LAN
  * 		 enabled.
+ * @needs_reregister: Set to true if the PHY needs to register AGAIN after
+ *		 first registration. This is to handle special case where the
+ *		 PHY needs to load a firmware to correctly communicate the
+ *		 specific PHY ID.
  * @state: State of the PHY for management purposes
  * @dev_flags: Device-specific flags used by the PHY driver.
  *
@@ -681,6 +685,7 @@ struct phy_device {
 	unsigned is_on_sfp_module:1;
 	unsigned mac_managed_pm:1;
 	unsigned wol_enabled:1;
+	unsigned needs_reregister;
 
 	unsigned autoneg:1;
 	/* The most recently read link state */
-- 
2.48.1


  reply	other threads:[~2025-03-26  0:24 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-26  0:23 [net-next RFC PATCH v2 0/3] net: phy: Add support for new Aeonsemi PHYs Christian Marangi
2025-03-26  0:23 ` Christian Marangi [this message]
2025-03-26  0:23 ` [net-next RFC PATCH v2 2/3] net: phy: Add support for Aeonsemi AS21xxx PHYs Christian Marangi
2025-03-26 13:53   ` Russell King (Oracle)
2025-03-26 13:57     ` Andrew Lunn
2025-03-26 14:47       ` Christian Marangi
2025-03-26 14:43     ` Christian Marangi
2025-03-26 18:02       ` Russell King (Oracle)
2025-03-26 14:00   ` Simon Horman
2025-03-26 14:05     ` Simon Horman
2025-03-26 14:56   ` Andrew Lunn
2025-03-26 15:09     ` Christian Marangi
2025-03-26 18:08     ` Russell King (Oracle)
2025-03-26 18:18       ` Christian Marangi
2025-03-26 18:32         ` Russell King (Oracle)
2025-03-26  0:23 ` [net-next RFC PATCH v2 3/3] dt-bindings: net: Document support for Aeonsemi PHYs Christian Marangi
2025-03-26 15:08   ` Andrew Lunn
2025-03-26 15:16     ` Christian Marangi

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=20250326002404.25530-2-ansuelsmth@gmail.com \
    --to=ansuelsmth@gmail.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=conor+dt@kernel.org \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=edumazet@google.com \
    --cc=hkallweit1@gmail.com \
    --cc=krzk+dt@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=robh@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).