All of lore.kernel.org
 help / color / mirror / Atom feed
From: Raju Lakkaraju <Raju.Lakkaraju@microchip.com>
To: <netdev@vger.kernel.org>
Cc: <davem@davemloft.net>, <kuba@kernel.org>,
	<linux-kernel@vger.kernel.org>, <bryan.whitehead@microchip.com>,
	<lxu@maxlinear.com>, <richardcochran@gmail.com>,
	<UNGLinuxDriver@microchip.com>, <Ian.Saturley@microchip.com>
Subject: [PATCH net-next 5/5] net: phy: add support to get Master-Slave configuration
Date: Tue, 14 Jun 2022 16:04:24 +0530	[thread overview]
Message-ID: <20220614103424.58971-6-Raju.Lakkaraju@microchip.com> (raw)
In-Reply-To: <20220614103424.58971-1-Raju.Lakkaraju@microchip.com>

Implement reporting the Master-Slave configuration and state

Signed-off-by: Raju Lakkaraju <Raju.Lakkaraju@microchip.com>
---
 drivers/net/phy/mxl-gpy.c | 55 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)

diff --git a/drivers/net/phy/mxl-gpy.c b/drivers/net/phy/mxl-gpy.c
index 5ce1bf03bbd7..cf625ced4ec1 100644
--- a/drivers/net/phy/mxl-gpy.c
+++ b/drivers/net/phy/mxl-gpy.c
@@ -27,11 +27,19 @@
 #define PHY_ID_GPY241BM		0x67C9DE80
 #define PHY_ID_GPY245B		0x67C9DEC0
 
+#define PHY_STD_GCTRL		0x09	/* Gbit ctrl */
+#define PHY_STD_GSTAT		0x0A	/* Gbit status */
 #define PHY_MIISTAT		0x18	/* MII state */
 #define PHY_IMASK		0x19	/* interrupt mask */
 #define PHY_ISTAT		0x1A	/* interrupt status */
 #define PHY_FWV			0x1E	/* firmware version */
 
+#define PHY_STD_GCTRL_MS	BIT(11)
+#define PHY_STD_GCTRL_MSEN	BIT(12)
+
+#define PHY_STD_GSTAT_MSRES	BIT(14)
+#define PHY_STD_GSTAT_MSFAULT	BIT(15)
+
 #define PHY_MIISTAT_SPD_MASK	GENMASK(2, 0)
 #define PHY_MIISTAT_DPX		BIT(3)
 #define PHY_MIISTAT_LS		BIT(10)
@@ -160,6 +168,48 @@ static bool gpy_2500basex_chk(struct phy_device *phydev)
 	return true;
 }
 
+static int gpy_master_slave_cfg_get(struct phy_device *phydev)
+{
+	int state;
+	int cfg;
+	int ret;
+
+	ret = phy_read(phydev, PHY_STD_GCTRL);
+	if (ret < 0) {
+		phydev_err(phydev, "Error: MDIO register access failed: %d\n",
+			   ret);
+		return ret;
+	}
+
+	if (ret & PHY_STD_GCTRL_MSEN)
+		if (ret & PHY_STD_GCTRL_MS)
+			cfg = MASTER_SLAVE_CFG_MASTER_FORCE;
+		else
+			cfg = MASTER_SLAVE_CFG_SLAVE_FORCE;
+	else
+		cfg = MASTER_SLAVE_CFG_MASTER_PREFERRED;
+
+	ret = phy_read(phydev, PHY_STD_GSTAT);
+	if (ret < 0) {
+		phydev_err(phydev, "Error: MDIO register access failed: %d\n",
+			   ret);
+		return ret;
+	}
+
+	if (ret & PHY_STD_GSTAT_MSFAULT)
+		state = MASTER_SLAVE_STATE_ERR;
+	else
+		if (ret & PHY_STD_GSTAT_MSRES)
+			state = MASTER_SLAVE_STATE_MASTER;
+		else
+			state = MASTER_SLAVE_STATE_SLAVE;
+
+	phydev->master_slave_get = cfg;
+	phydev->master_slave_state = state;
+
+	return 0;
+}
+
 static bool gpy_sgmii_aneg_en(struct phy_device *phydev)
 {
 	int ret;
@@ -295,6 +345,9 @@ static void gpy_update_interface(struct phy_device *phydev)
 				   ret);
 		break;
 	}
+
+	if (phydev->speed == SPEED_2500 || phydev->speed == SPEED_1000)
+		gpy_master_slave_cfg_get(phydev);
 }
 
 static int gpy_read_status(struct phy_device *phydev)
@@ -309,6 +362,8 @@ static int gpy_read_status(struct phy_device *phydev)
 	phydev->duplex = DUPLEX_UNKNOWN;
 	phydev->pause = 0;
 	phydev->asym_pause = 0;
+	phydev->master_slave_get = MASTER_SLAVE_CFG_UNKNOWN;
+	phydev->master_slave_state = MASTER_SLAVE_STATE_UNKNOWN;
 
 	if (phydev->autoneg == AUTONEG_ENABLE && phydev->autoneg_complete) {
 		ret = genphy_c45_read_lpa(phydev);
-- 
2.25.1


  parent reply	other threads:[~2022-06-14 10:35 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-14 10:34 [PATCH net-next 0/5] net: lan743x: PCI11010 / PCI11414 devices Enhancements Raju Lakkaraju
2022-06-14 10:34 ` [PATCH net-next 1/5] net: lan743x: Add support to LAN743x register dump Raju Lakkaraju
2022-06-14 10:34 ` [PATCH net-next 2/5] net: lan743x: Add support to Secure-ON WOL Raju Lakkaraju
2022-06-14 20:59   ` Andrew Lunn
2022-06-15  9:44     ` Raju Lakkaraju
2022-06-14 10:34 ` [PATCH net-next 3/5] net: lan743x: Add support to SGMII block access functions Raju Lakkaraju
2022-06-14 21:03   ` Andrew Lunn
2022-06-15  9:36     ` Raju Lakkaraju
2022-06-14 10:34 ` [PATCH net-next 4/5] net: lan743x: Add support to SGMII 1G and 2.5G Raju Lakkaraju
2022-06-14 21:13   ` Andrew Lunn
2022-06-15  9:39     ` Raju Lakkaraju
2022-06-14 10:34 ` Raju Lakkaraju [this message]
2022-06-14 21:21   ` [PATCH net-next 5/5] net: phy: add support to get Master-Slave configuration Andrew Lunn
2022-06-15  9:43     ` Raju Lakkaraju

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=20220614103424.58971-6-Raju.Lakkaraju@microchip.com \
    --to=raju.lakkaraju@microchip.com \
    --cc=Ian.Saturley@microchip.com \
    --cc=UNGLinuxDriver@microchip.com \
    --cc=bryan.whitehead@microchip.com \
    --cc=davem@davemloft.net \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lxu@maxlinear.com \
    --cc=netdev@vger.kernel.org \
    --cc=richardcochran@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.