netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michael Walle <michael@walle.cc>
To: Andrew Lunn <andrew@lunn.ch>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	Russell King <linux@armlinux.org.uk>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: "David S . Miller" <davem@davemloft.net>,
	Xu Liang <lxu@maxlinear.com>,
	Alexandre Belloni <alexandre.belloni@bootlin.com>,
	Florian Fainelli <f.fainelli@gmail.com>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	Michael Walle <michael@walle.cc>
Subject: [PATCH RFC net-next v2 7/8] phy: net: introduce phy_promote_to_c45()
Date: Fri, 25 Mar 2022 22:35:17 +0100	[thread overview]
Message-ID: <20220325213518.2668832-8-michael@walle.cc> (raw)
In-Reply-To: <20220325213518.2668832-1-michael@walle.cc>

If not explitly asked to be probed as a C45 PHY, on a bus which is
capable of doing both C22 and C45 transfers, C45 PHYs are first tried to
be probed as C22 PHYs. To be able to promote the PHY to be a C45 one,
the driver can call phy_promote_to_c45() in its probe function.

This was already done in the mxl-gpy driver by the following snippet:

   if (!phydev->has_c45) {
	   phydev->has_c45 = true;
           ret = phy_get_c45_ids(phydev);
           if (ret < 0)
                   return ret;
   }

Move that code into the core by creating a new function
phy_promote_to_c45().

Signed-off-by: Michael Walle <michael@walle.cc>
---
 drivers/net/phy/mxl-gpy.c    |  8 ++------
 drivers/net/phy/phy_device.c | 19 +++++++++++++++----
 include/linux/phy.h          |  2 +-
 3 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/drivers/net/phy/mxl-gpy.c b/drivers/net/phy/mxl-gpy.c
index 2a19905984fc..fe9417528444 100644
--- a/drivers/net/phy/mxl-gpy.c
+++ b/drivers/net/phy/mxl-gpy.c
@@ -98,12 +98,8 @@ static int gpy_probe(struct phy_device *phydev)
 {
 	int ret;
 
-	if (!phydev->has_c45) {
-		phydev->has_c45 = true;
-		ret = phy_get_c45_ids(phydev);
-		if (ret < 0)
-			return ret;
-	}
+	/* This might have been probed as a C22 PHY, but this is a C45 PHY */
+	phy_promote_to_c45(phydev);
 
 	/* Show GPY PHY FW version in dmesg */
 	ret = phy_read(phydev, PHY_FWV);
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 920bc8859069..3dc7d012051d 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -1007,18 +1007,29 @@ void phy_device_remove(struct phy_device *phydev)
 EXPORT_SYMBOL(phy_device_remove);
 
 /**
- * phy_get_c45_ids - Read 802.3-c45 IDs for phy device.
- * @phydev: phy_device structure to read 802.3-c45 IDs
+ * phy_promote_to_c45 - Promote to a C45 PHY
+ * @phydev: phy_device structure
+ *
+ * If a PHY supports both C22 and C45 and it isn't specifically asked to probe
+ * as a C45 PHY it might be probed as a C22 PHY. The driver can call this
+ * function to promote a PHY from C22 to C45.
+ *
+ * Can also be called if a PHY is already a C45 one. In this case this does
+ * nothing.
  *
  * Returns zero on success, %-EIO on bus access error, or %-ENODEV if
  * the "devices in package" is invalid.
  */
-int phy_get_c45_ids(struct phy_device *phydev)
+int phy_promote_to_c45(struct phy_device *phydev)
 {
+	if (phydev->has_c45)
+		return 0;
+
+	phydev->has_c45 = true;
 	return get_phy_c45_ids(phydev->mdio.bus, phydev->mdio.addr,
 			       &phydev->c45_ids);
 }
-EXPORT_SYMBOL(phy_get_c45_ids);
+EXPORT_SYMBOL(phy_promote_to_c45);
 
 /**
  * phy_find_first - finds the first PHY device on the bus
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 64f2dff2f125..4473e760264a 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -1470,7 +1470,7 @@ static inline int phy_device_register(struct phy_device *phy)
 static inline void phy_device_free(struct phy_device *phydev) { }
 #endif /* CONFIG_PHYLIB */
 void phy_device_remove(struct phy_device *phydev);
-int phy_get_c45_ids(struct phy_device *phydev);
+int phy_promote_to_c45(struct phy_device *phydev);
 int phy_init_hw(struct phy_device *phydev);
 int phy_suspend(struct phy_device *phydev);
 int phy_resume(struct phy_device *phydev);
-- 
2.30.2


  parent reply	other threads:[~2022-03-25 21:35 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-25 21:35 [PATCH RFC net-next v2 0/8] net: phy: C45-over-C22 access Michael Walle
2022-03-25 21:35 ` [PATCH RFC net-next v2 1/8] net: phy: mscc-miim: reject clause 45 register accesses Michael Walle
2022-03-25 21:35 ` [PATCH RFC net-next v2 2/8] net: phy: mscc-miim: add probe_capabilities Michael Walle
2022-03-25 21:35 ` [PATCH RFC net-next v2 3/8] net: phy: add error checks in __phy_mmd_indirect() and export it Michael Walle
2022-03-25 21:35 ` [PATCH RFC net-next v2 4/8] net: phy: add error handling for __phy_{read,write}_mmd Michael Walle
2022-03-25 21:35 ` [PATCH RFC net-next v2 5/8] net: phy: support indirect c45 access in get_phy_c45_ids() Michael Walle
2022-03-25 21:35 ` [PATCH RFC net-next v2 6/8] net: phy: add support for C45-over-C22 transfers Michael Walle
2022-03-25 21:35 ` Michael Walle [this message]
2022-03-25 21:35 ` [PATCH RFC net-next v2 8/8] net: phy: mxl-gpy: remove unneeded ops Michael Walle

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=20220325213518.2668832-8-michael@walle.cc \
    --to=michael@walle.cc \
    --cc=alexandre.belloni@bootlin.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=f.fainelli@gmail.com \
    --cc=hkallweit1@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=lxu@maxlinear.com \
    --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;
as well as URLs for NNTP newsgroup(s).