linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next v1] net: phy: tja11xx: execute cable test on link up
@ 2020-05-14 19:42 Oleksij Rempel
  2020-05-15 17:56 ` Andrew Lunn
  2020-05-15 18:03 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Oleksij Rempel @ 2020-05-14 19:42 UTC (permalink / raw)
  To: Andrew Lunn, Florian Fainelli, Heiner Kallweit
  Cc: Oleksij Rempel, Pengutronix Kernel Team, linux-kernel,
	David S. Miller, netdev, Marek Vasut, David Jander

A typical 100Base-T1 link should be always connected. If the link is in
a shot or open state, it is a failure. In most cases, we won't be able
to automatically handle this issue, but we need to log it or notify user
(if possible).

With this patch, the cable will be tested on "ip l s dev .. up" attempt
and send ethnl notification to the user space.

This patch was tested with TJA1102 PHY and "ethtool --monitor" command.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/net/phy/nxp-tja11xx.c | 48 +++++++++++++++++++++++++++++++----
 1 file changed, 43 insertions(+), 5 deletions(-)

diff --git a/drivers/net/phy/nxp-tja11xx.c b/drivers/net/phy/nxp-tja11xx.c
index 8b743d25002b9..0d4f9067ca715 100644
--- a/drivers/net/phy/nxp-tja11xx.c
+++ b/drivers/net/phy/nxp-tja11xx.c
@@ -180,10 +180,43 @@ static int tja11xx_soft_reset(struct phy_device *phydev)
 	return genphy_soft_reset(phydev);
 }
 
+static int tja11xx_config_aneg_cable_test(struct phy_device *phydev)
+{
+	bool finished = false;
+	int ret;
+
+	if (phydev->link)
+		return 0;
+
+	if (!phydev->drv->cable_test_start ||
+	    !phydev->drv->cable_test_get_status)
+		return 0;
+
+	ret = ethnl_cable_test_alloc(phydev);
+	if (ret)
+		return ret;
+
+	ret = phydev->drv->cable_test_start(phydev);
+	if (ret)
+		return ret;
+
+	/* According to the documentation this test takes 100 usec */
+	usleep_range(100, 200);
+
+	ret = phydev->drv->cable_test_get_status(phydev, &finished);
+	if (ret)
+		return ret;
+
+	if (finished)
+		ethnl_cable_test_finished(phydev);
+
+	return 0;
+}
+
 static int tja11xx_config_aneg(struct phy_device *phydev)
 {
+	int ret, changed = 0;
 	u16 ctl = 0;
-	int ret;
 
 	switch (phydev->master_slave_set) {
 	case MASTER_SLAVE_CFG_MASTER_FORCE:
@@ -193,17 +226,22 @@ static int tja11xx_config_aneg(struct phy_device *phydev)
 		break;
 	case MASTER_SLAVE_CFG_UNKNOWN:
 	case MASTER_SLAVE_CFG_UNSUPPORTED:
-		return 0;
+		goto do_test;
 	default:
 		phydev_warn(phydev, "Unsupported Master/Slave mode\n");
 		return -ENOTSUPP;
 	}
 
-	ret = phy_modify_changed(phydev, MII_CFG1, MII_CFG1_MASTER_SLAVE, ctl);
-	if (ret < 0)
+	changed = phy_modify_changed(phydev, MII_CFG1, MII_CFG1_MASTER_SLAVE, ctl);
+	if (changed < 0)
+		return changed;
+
+do_test:
+	ret = tja11xx_config_aneg_cable_test(phydev);
+	if (ret)
 		return ret;
 
-	return __genphy_config_aneg(phydev, ret);
+	return __genphy_config_aneg(phydev, changed);
 }
 
 static int tja11xx_config_init(struct phy_device *phydev)
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net-next v1] net: phy: tja11xx: execute cable test on link up
  2020-05-14 19:42 [PATCH net-next v1] net: phy: tja11xx: execute cable test on link up Oleksij Rempel
@ 2020-05-15 17:56 ` Andrew Lunn
  2020-05-15 18:03 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: Andrew Lunn @ 2020-05-15 17:56 UTC (permalink / raw)
  To: Oleksij Rempel
  Cc: Florian Fainelli, Heiner Kallweit, Pengutronix Kernel Team,
	linux-kernel, David S. Miller, netdev, Marek Vasut, David Jander

On Thu, May 14, 2020 at 09:42:18PM +0200, Oleksij Rempel wrote:
> A typical 100Base-T1 link should be always connected. If the link is in
> a shot or open state, it is a failure. In most cases, we won't be able
> to automatically handle this issue, but we need to log it or notify user
> (if possible).
> 
> With this patch, the cable will be tested on "ip l s dev .. up" attempt
> and send ethnl notification to the user space.
> 
> This patch was tested with TJA1102 PHY and "ethtool --monitor" command.
> 
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net-next v1] net: phy: tja11xx: execute cable test on link up
  2020-05-14 19:42 [PATCH net-next v1] net: phy: tja11xx: execute cable test on link up Oleksij Rempel
  2020-05-15 17:56 ` Andrew Lunn
@ 2020-05-15 18:03 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2020-05-15 18:03 UTC (permalink / raw)
  To: o.rempel
  Cc: andrew, f.fainelli, hkallweit1, kernel, linux-kernel, netdev,
	marex, david

From: Oleksij Rempel <o.rempel@pengutronix.de>
Date: Thu, 14 May 2020 21:42:18 +0200

> A typical 100Base-T1 link should be always connected. If the link is in
> a shot or open state, it is a failure. In most cases, we won't be able
> to automatically handle this issue, but we need to log it or notify user
> (if possible).
> 
> With this patch, the cable will be tested on "ip l s dev .. up" attempt
> and send ethnl notification to the user space.
> 
> This patch was tested with TJA1102 PHY and "ethtool --monitor" command.
> 
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>

Applied, thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-05-15 18:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-14 19:42 [PATCH net-next v1] net: phy: tja11xx: execute cable test on link up Oleksij Rempel
2020-05-15 17:56 ` Andrew Lunn
2020-05-15 18:03 ` David Miller

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).