* [PATCH net-next v1 1/1] phy: dp83td510: Utilize ALCD for cable length measurement when link is active
@ 2024-08-16 10:51 Oleksij Rempel
2024-08-16 13:10 ` Andrew Lunn
0 siblings, 1 reply; 3+ messages in thread
From: Oleksij Rempel @ 2024-08-16 10:51 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni
Cc: Oleksij Rempel, kernel, linux-kernel, netdev
In industrial environments where 10BaseT1L PHYs are replacing existing
field bus systems like CAN, it's often essential to retain the existing
cable infrastructure. After installation, collecting metrics such as
cable length is crucial for assessing the quality of the infrastructure.
Traditionally, TDR (Time Domain Reflectometry) is used for this purpose.
However, TDR requires interrupting the link, and if the link partner
remains active, the TDR measurement will fail.
Unlike multi-pair systems, where TDR can be attempted during the MDI-X
switching window, 10BaseT1L systems face greater challenges. The TDR
sequence on 10BaseT1L is longer and coincides with uninterrupted
autonegotiation pulses, making TDR impossible when the link partner is
active.
The DP83TD510 PHY provides an alternative through ALCD (Active Link
Cable Diagnostics), which allows for cable length measurement without
disrupting an active link. Since a live link indicates no short or open
cable states, ALCD can be used effectively to gather cable length
information.
Enhance the dp83td510 driver by:
- Leveraging ALCD to measure cable length when the link is active.
- Bypassing TDR when a link is detected, as ALCD provides the required
information without disruption.
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
drivers/net/phy/dp83td510.c | 80 ++++++++++++++++++++++++++++++++++---
1 file changed, 74 insertions(+), 6 deletions(-)
diff --git a/drivers/net/phy/dp83td510.c b/drivers/net/phy/dp83td510.c
index 551e37786c2da..72c33079fc665 100644
--- a/drivers/net/phy/dp83td510.c
+++ b/drivers/net/phy/dp83td510.c
@@ -169,6 +169,10 @@ static const u16 dp83td510_mse_sqi_map[] = {
#define DP83TD510E_UNKN_030E 0x30e
#define DP83TD510E_030E_VAL 0x2520
+#define DP83TD510E_ALCD_STAT 0xa9f
+#define DP83TD510E_ALCD_COMPLETE BIT(15)
+#define DP83TD510E_ALCD_CABLE_LENGTH GENMASK(10, 0)
+
static int dp83td510_config_intr(struct phy_device *phydev)
{
int ret;
@@ -327,6 +331,16 @@ static int dp83td510_cable_test_start(struct phy_device *phydev)
{
int ret;
+ /* If link partner is active, we won't be able to use TDR, since
+ * we can't force link partner to be silent. The autonegotiation
+ * pulses will be too frequent and the TDR sequence will be
+ * too long. So, TDR will always fail. Since the link is established
+ * we already know that the cable is working, so we can get some
+ * extra information line the cable length using ALCD.
+ */
+ if (phydev->link)
+ return 0;
+
ret = phy_set_bits_mmd(phydev, MDIO_MMD_VEND2, DP83TD510E_CTRL,
DP83TD510E_CTRL_HW_RESET);
if (ret)
@@ -402,8 +416,8 @@ static int dp83td510_cable_test_start(struct phy_device *phydev)
}
/**
- * dp83td510_cable_test_get_status - Get the status of the cable test for the
- * DP83TD510 PHY.
+ * dp83td510_cable_test_get_tdr_status - Get the status of the TDR test for the
+ * DP83TD510 PHY.
* @phydev: Pointer to the phy_device structure.
* @finished: Pointer to a boolean that indicates whether the test is finished.
*
@@ -411,13 +425,11 @@ static int dp83td510_cable_test_start(struct phy_device *phydev)
*
* Returns: 0 on success or a negative error code on failure.
*/
-static int dp83td510_cable_test_get_status(struct phy_device *phydev,
- bool *finished)
+static int dp83td510_cable_test_get_tdr_status(struct phy_device *phydev,
+ bool *finished)
{
int ret, stat;
- *finished = false;
-
ret = phy_read_mmd(phydev, MDIO_MMD_VEND2, DP83TD510E_TDR_CFG);
if (ret < 0)
return ret;
@@ -459,6 +471,62 @@ static int dp83td510_cable_test_get_status(struct phy_device *phydev,
return phy_init_hw(phydev);
}
+/**
+ * dp83td510_cable_test_get_alcd_status - Get the status of the ALCD test for the
+ * DP83TD510 PHY.
+ * @phydev: Pointer to the phy_device structure.
+ * @finished: Pointer to a boolean that indicates whether the test is finished.
+ *
+ * The function sets the @finished flag to true if the test is complete.
+ * The function reads the cable length and reports it to the user.
+ *
+ * Returns: 0 on success or a negative error code on failure.
+ */
+static int dp83td510_cable_test_get_alcd_status(struct phy_device *phydev,
+ bool *finished)
+{
+ unsigned int location;
+ int ret;
+
+ ret = phy_read_mmd(phydev, MDIO_MMD_VEND2, DP83TD510E_ALCD_STAT);
+ if (ret < 0)
+ return ret;
+
+ if (!(ret & DP83TD510E_ALCD_COMPLETE))
+ return 0;
+
+ location = FIELD_GET(DP83TD510E_ALCD_CABLE_LENGTH, ret) * 100;
+
+ ethnl_cable_test_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_A, location);
+
+ ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_A,
+ ETHTOOL_A_CABLE_RESULT_CODE_OK);
+ *finished = true;
+
+ return 0;
+}
+
+/**
+ * dp83td510_cable_test_get_status - Get the status of the cable test for the
+ * DP83TD510 PHY.
+ * @phydev: Pointer to the phy_device structure.
+ * @finished: Pointer to a boolean that indicates whether the test is finished.
+ *
+ * The function sets the @finished flag to true if the test is complete.
+ *
+ * Returns: 0 on success or a negative error code on failure.
+ */
+static int dp83td510_cable_test_get_status(struct phy_device *phydev,
+ bool *finished)
+{
+ *finished = false;
+
+ if (!phydev->link)
+ return dp83td510_cable_test_get_tdr_status(phydev, finished);
+
+ return dp83td510_cable_test_get_alcd_status(phydev, finished);
+}
+
static int dp83td510_get_features(struct phy_device *phydev)
{
/* This PHY can't respond on MDIO bus if no RMII clock is enabled.
--
2.39.2
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH net-next v1 1/1] phy: dp83td510: Utilize ALCD for cable length measurement when link is active
2024-08-16 10:51 [PATCH net-next v1 1/1] phy: dp83td510: Utilize ALCD for cable length measurement when link is active Oleksij Rempel
@ 2024-08-16 13:10 ` Andrew Lunn
2024-08-16 14:00 ` Oleksij Rempel
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Lunn @ 2024-08-16 13:10 UTC (permalink / raw)
To: Oleksij Rempel
Cc: Heiner Kallweit, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, kernel, linux-kernel, netdev
> The DP83TD510 PHY provides an alternative through ALCD (Active Link
> Cable Diagnostics), which allows for cable length measurement without
> disrupting an active link. Since a live link indicates no short or open
> cable states, ALCD can be used effectively to gather cable length
> information.
Is this specific to TI?
Did you compare ALCD to TDR length measurement? Are they about the
same? I'm just thinking about if we want to include an additional
attribute in ethnl_cable_test_fault_length() to indicate how the
measurement was performed.
Andrew
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net-next v1 1/1] phy: dp83td510: Utilize ALCD for cable length measurement when link is active
2024-08-16 13:10 ` Andrew Lunn
@ 2024-08-16 14:00 ` Oleksij Rempel
0 siblings, 0 replies; 3+ messages in thread
From: Oleksij Rempel @ 2024-08-16 14:00 UTC (permalink / raw)
To: Andrew Lunn
Cc: Heiner Kallweit, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, kernel, linux-kernel, netdev
On Fri, Aug 16, 2024 at 03:10:35PM +0200, Andrew Lunn wrote:
> > The DP83TD510 PHY provides an alternative through ALCD (Active Link
> > Cable Diagnostics), which allows for cable length measurement without
> > disrupting an active link. Since a live link indicates no short or open
> > cable states, ALCD can be used effectively to gather cable length
> > information.
>
> Is this specific to TI?
It seems to be, yes. I assume they are using echo cancellation values or
some thing like this.
> Did you compare ALCD to TDR length measurement? Are they about the
> same?
Default ALCD values are about 20meters off. Which seems to be ok for
1000meter cable. TI describes calibration procedure for ALCD to provide
better measurements, but so far it was good enough. The problem with
this calibration is: it seems to be different for different cables, so
it make no sense to integrate it in kernel.
> I'm just thinking about if we want to include an additional
> attribute in ethnl_cable_test_fault_length() to indicate how the
> measurement was performed.
Sounds good. In this case user space will be able to know how to correct
this values.
Regards,
Oleksij
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-08-16 14:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-16 10:51 [PATCH net-next v1 1/1] phy: dp83td510: Utilize ALCD for cable length measurement when link is active Oleksij Rempel
2024-08-16 13:10 ` Andrew Lunn
2024-08-16 14:00 ` Oleksij Rempel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox