* [PATCH net-next 1/3] net: phy: broadcom: Implement cable test initialization
2026-12-03 0:47 [PATCH net-next 0/3] net: phy: Cable tests for BCM54210E Florian Fainelli
@ 2026-12-03 0:48 ` Florian Fainelli
2026-12-03 0:48 ` [PATCH net-next 2/3] net: phy: broadcom: Wire-up cable tests for BCM54210E Florian Fainelli
2026-12-03 0:48 ` [PATCH net-next 3/3] net: phy: broadcom: Time out a stuck cable test Florian Fainelli
2 siblings, 0 replies; 4+ messages in thread
From: Florian Fainelli @ 2026-12-03 0:48 UTC (permalink / raw)
To: netdev
Cc: Florian Fainelli, Nicolai Buchwitz,
Broadcom internal kernel review list, Andrew Lunn,
Heiner Kallweit, Russell King, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni
In order to utilize the Enhanced Cable Diagnostics (ECD) feature of a
number of PHYs, we need to perform an initialization that will load the
PHY with a set of pre-defined values.
Signed-off-by: Florian Fainelli <florian.fainelli@broadcom.com>
Co-developed-by: Nicolai Buchwitz <nb@tipi-net.de>
Signed-off-by: Nicolai Buchwitz <nb@tipi-net.de>
---
drivers/net/phy/bcm-phy-lib.c | 198 +++++++++++++++++++++++++++++-----
include/linux/brcmphy.h | 1 +
2 files changed, 172 insertions(+), 27 deletions(-)
diff --git a/drivers/net/phy/bcm-phy-lib.c b/drivers/net/phy/bcm-phy-lib.c
index b64beade8dd9..9571928db029 100644
--- a/drivers/net/phy/bcm-phy-lib.c
+++ b/drivers/net/phy/bcm-phy-lib.c
@@ -657,6 +657,154 @@ static int __bcm_phy_enable_legacy_access(struct phy_device *phydev)
BCM54XX_ACCESS_MODE_LEGACY_EN);
}
+struct __bcm_phy_regs {
+ u16 reg;
+ u16 val;
+};
+
+/* Load values from an array of registers and then restores those registers back to 0 */
+static int _bcm_phy_load_values(struct phy_device *phydev,
+ const struct __bcm_phy_regs *regs,
+ size_t num_regs,
+ u16 page_num)
+{
+ unsigned int i;
+ int ret;
+
+ /* Load the registers into the expansion E* registers */
+ for (i = 0; i < num_regs; i++) {
+ ret = __bcm_phy_write_exp(phydev, MII_BCM54XX_EXP_SEL_ER +
+ regs[i].reg, regs[i].val);
+ if (ret < 0)
+ return ret;
+ }
+
+ /* Specify the number of E* registers to write and the page number */
+ ret = __bcm_phy_write_exp(phydev, MII_BCM54XX_EXP_SEL_ER + 0xef,
+ page_num << 14 | GENMASK(num_regs - 1, 0));
+ if (ret < 0)
+ return ret;
+
+ /* Write strobe 1 */
+ ret = __bcm_phy_write_exp(phydev, MII_BCM54XX_EXP_SEL_ER + 0xcd,
+ 0x1000);
+ if (ret < 0)
+ return ret;
+
+ /* Write strobe 0 */
+ ret = __bcm_phy_write_exp(phydev, MII_BCM54XX_EXP_SEL_ER + 0xcd, 0);
+ if (ret < 0)
+ return ret;
+
+ /* Restore expansion E* register values */
+ for (i = 0; i < num_regs; i++) {
+ ret = __bcm_phy_write_exp(phydev, MII_BCM54XX_EXP_SEL_ER +
+ regs[i].reg, 0);
+ if (ret < 0)
+ return ret;
+ }
+
+ /* And restore 0xEF register */
+ return __bcm_phy_write_exp(phydev, MII_BCM54XX_EXP_SEL_ER + 0xef, 0);
+}
+
+/* Must be called with the MDIO bus lock held and legacy expansion register
+ * access enabled.
+ */
+static int __bcm_phy_cable_test_init(struct phy_device *phydev)
+{
+ static const struct __bcm_phy_regs init_regs[] = {
+ { 0xc7, 0xA01A },
+ { 0xc8, 0x0300 },
+ { 0xc9, 0x00EF },
+ { 0xcb, 0x1304 },
+ { 0xcc, 0x0180 },
+ { 0xce, 0x4000 },
+ { 0xcf, 0x3000 },
+ };
+ static const struct __bcm_phy_regs page1_init_regs[] = {
+ /* Page 1 */
+ { 0xe0, 0x0119 },
+ { 0xe1, 0x0202 },
+ { 0xe2, 0x000F },
+ { 0xe3, 0x5000 },
+ { 0xe4, 0x738E },
+ { 0xe5, 0x1000 },
+ { 0xe6, 0x1000 },
+ { 0xe7, 0xAA00 },
+ };
+ static const struct __bcm_phy_regs page2_init_regs[] = {
+ /* page 2 */
+ { 0xe0, 0x0B00 },
+ { 0xe1, 0x313D },
+ { 0xe2, 0x007C },
+ };
+ static const struct __bcm_phy_regs page0_init_regs[] = {
+ /* page 0 */
+ { 0xe0, 0x0001 },
+ { 0xe1, 0x0540 },
+ { 0xe2, 0x0E40 },
+ { 0xe3, 0x0841 },
+ { 0xe4, 0x1344 },
+ { 0xe8, 0x8760 },
+ { 0xe9, 0x4B33 },
+ { 0xea, 0x0400 },
+ };
+ unsigned int i;
+ int ret;
+
+ /* Disable ECD to load parameters. Note that the reference sequence
+ * soft-resets the PHY first, but that is only needed for the Broadcom
+ * DVT process and would discard the configuration done at
+ * config_init() time.
+ */
+ ret = __bcm_phy_write_exp(phydev, BCM54XX_EXP_ECD_CTRL, 0);
+ if (ret < 0)
+ return ret;
+
+ /* Prepare for loading value */
+ for (i = 0; i < ARRAY_SIZE(init_regs); i++) {
+ ret = __bcm_phy_write_exp(phydev, MII_BCM54XX_EXP_SEL_ER +
+ init_regs[i].reg,
+ init_regs[i].val);
+ if (ret < 0)
+ return ret;
+ }
+
+ /* Load page 1 values */
+ ret = _bcm_phy_load_values(phydev, page1_init_regs,
+ ARRAY_SIZE(page1_init_regs), 1);
+ if (ret < 0)
+ return ret;
+
+ /* Load page 2 values */
+ ret = _bcm_phy_load_values(phydev, page2_init_regs,
+ ARRAY_SIZE(page2_init_regs), 2);
+ if (ret < 0)
+ return ret;
+
+ /* Load the page 0 values */
+ for (i = 0; i < ARRAY_SIZE(page0_init_regs); i++) {
+ ret = __bcm_phy_write_exp(phydev, MII_BCM54XX_EXP_SEL_ER +
+ page0_init_regs[i].reg,
+ page0_init_regs[i].val);
+ if (ret < 0)
+ return ret;
+ }
+
+ /* Finish loading */
+ ret = __bcm_phy_write_exp(phydev, MII_BCM54XX_EXP_SEL_ER + 0xcd, 0xd0);
+ if (ret < 0)
+ return ret;
+
+ /* Dummy read to flush the ECD register */
+ ret = __bcm_phy_read_exp(phydev, BCM54XX_EXP_ECD_CTRL);
+ if (ret < 0)
+ return ret;
+
+ return __bcm_phy_write_exp(phydev, BCM54XX_EXP_ECD_CTRL, 0);
+}
+
static int _bcm_phy_cable_test_start(struct phy_device *phydev, bool is_rdb)
{
u16 mask, set;
@@ -676,6 +824,10 @@ static int _bcm_phy_cable_test_start(struct phy_device *phydev, bool is_rdb)
goto out;
}
+ ret = __bcm_phy_cable_test_init(phydev);
+ if (ret < 0)
+ goto out;
+
mask = BCM54XX_ECD_CTRL_CROSS_SHORT_DIS | BCM54XX_ECD_CTRL_UNIT_MASK;
set = BCM54XX_ECD_CTRL_RUN | BCM54XX_ECD_CTRL_BREAK_LINK |
FIELD_PREP(BCM54XX_ECD_CTRL_UNIT_MASK,
@@ -722,21 +874,26 @@ static bool bcm_phy_distance_valid(int result)
return false;
}
-static int bcm_phy_report_length(struct phy_device *phydev, int pair)
+static void bcm_phy_cable_test_report_pair(struct phy_device *phydev, u8 pair,
+ int fault)
{
- int val;
+ int code = bcm_phy_cable_test_report_trans(fault);
+ int len = -ENODATA;
- val = __bcm_phy_read_exp(phydev,
- BCM54XX_EXP_ECD_PAIR_A_LENGTH_RESULTS + pair);
- if (val < 0)
- return val;
+ if (bcm_phy_distance_valid(fault))
+ len = __bcm_phy_read_exp(phydev,
+ BCM54XX_EXP_ECD_PAIR_A_LENGTH_RESULTS +
+ pair);
- if (val == BCM54XX_ECD_LENGTH_RESULTS_INVALID)
- return 0;
+ /* The fault type is not valid either when the engine failed */
+ if (len == BCM54XX_ECD_LENGTH_RESULTS_FAILED)
+ code = ETHTOOL_A_CABLE_RESULT_CODE_UNSPEC;
- ethnl_cable_test_fault_length(phydev, pair, val);
+ ethnl_cable_test_result(phydev, pair, code);
- return 0;
+ if (len >= 0 && len != BCM54XX_ECD_LENGTH_RESULTS_INVALID &&
+ len != BCM54XX_ECD_LENGTH_RESULTS_FAILED)
+ ethnl_cable_test_fault_length(phydev, pair, len);
}
static int _bcm_phy_cable_test_get_status(struct phy_device *phydev,
@@ -772,23 +929,10 @@ static int _bcm_phy_cable_test_get_status(struct phy_device *phydev,
pair_c = FIELD_GET(BCM54XX_ECD_FAULT_TYPE_PAIR_C_MASK, ret);
pair_d = FIELD_GET(BCM54XX_ECD_FAULT_TYPE_PAIR_D_MASK, ret);
- ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_A,
- bcm_phy_cable_test_report_trans(pair_a));
- ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_B,
- bcm_phy_cable_test_report_trans(pair_b));
- ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_C,
- bcm_phy_cable_test_report_trans(pair_c));
- ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_D,
- bcm_phy_cable_test_report_trans(pair_d));
-
- if (bcm_phy_distance_valid(pair_a))
- bcm_phy_report_length(phydev, 0);
- if (bcm_phy_distance_valid(pair_b))
- bcm_phy_report_length(phydev, 1);
- if (bcm_phy_distance_valid(pair_c))
- bcm_phy_report_length(phydev, 2);
- if (bcm_phy_distance_valid(pair_d))
- bcm_phy_report_length(phydev, 3);
+ bcm_phy_cable_test_report_pair(phydev, ETHTOOL_A_CABLE_PAIR_A, pair_a);
+ bcm_phy_cable_test_report_pair(phydev, ETHTOOL_A_CABLE_PAIR_B, pair_b);
+ bcm_phy_cable_test_report_pair(phydev, ETHTOOL_A_CABLE_PAIR_C, pair_c);
+ bcm_phy_cable_test_report_pair(phydev, ETHTOOL_A_CABLE_PAIR_D, pair_d);
ret = 0;
*finished = true;
diff --git a/include/linux/brcmphy.h b/include/linux/brcmphy.h
index 174687c4c80a..e90b0f7fc7b8 100644
--- a/include/linux/brcmphy.h
+++ b/include/linux/brcmphy.h
@@ -527,5 +527,6 @@
#define BCM54XX_RDB_ECD_PAIR_D_LENGTH_RESULTS 0x2a5
#define BCM54XX_EXP_ECD_PAIR_D_LENGTH_RESULTS (MII_BCM54XX_EXP_SEL_ER + 0xc5)
#define BCM54XX_ECD_LENGTH_RESULTS_INVALID 0xffff
+#define BCM54XX_ECD_LENGTH_RESULTS_FAILED 0x47ae /* saturated, ECD failure */
#endif /* _LINUX_BRCMPHY_H */
--
2.53.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH net-next 2/3] net: phy: broadcom: Wire-up cable tests for BCM54210E
2026-12-03 0:47 [PATCH net-next 0/3] net: phy: Cable tests for BCM54210E Florian Fainelli
2026-12-03 0:48 ` [PATCH net-next 1/3] net: phy: broadcom: Implement cable test initialization Florian Fainelli
@ 2026-12-03 0:48 ` Florian Fainelli
2026-12-03 0:48 ` [PATCH net-next 3/3] net: phy: broadcom: Time out a stuck cable test Florian Fainelli
2 siblings, 0 replies; 4+ messages in thread
From: Florian Fainelli @ 2026-12-03 0:48 UTC (permalink / raw)
To: netdev
Cc: Florian Fainelli, Broadcom internal kernel review list,
Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni
Wire up the cable diagnostics now that we have implemented the cable
test feature, this was verified with a Raspberry Pi 4B using a BCM54210E
PHY:
Signed-off-by: Florian Fainelli <florian.fainelli@broadcom.com>
---
drivers/net/phy/broadcom.c | 43 +++++++++++++++++++++++++++++++++++++-
1 file changed, 42 insertions(+), 1 deletion(-)
diff --git a/drivers/net/phy/broadcom.c b/drivers/net/phy/broadcom.c
index 9085b72e322f..19b97beb8be8 100644
--- a/drivers/net/phy/broadcom.c
+++ b/drivers/net/phy/broadcom.c
@@ -1469,6 +1469,44 @@ static int bcm54xx_disable_autonomous_eee(struct phy_device *phydev)
BCM54XX_MII_BUF_CNTL0_AUTOGREEEN_EN, 0);
}
+static int bcm54xx_cable_test_start(struct phy_device *phydev)
+{
+ int val, ret;
+
+ /* The ECD run never finishes on a line without energy while auto
+ * power-down is enabled.
+ */
+ val = bcm_phy_read_shadow(phydev, BCM54XX_SHD_APD);
+ if (val < 0)
+ return val;
+
+ ret = bcm_phy_write_shadow(phydev, BCM54XX_SHD_APD,
+ val & ~BCM54XX_SHD_APD_EN);
+ if (ret < 0)
+ return ret;
+
+ ret = bcm_phy_cable_test_start(phydev);
+ if (ret < 0)
+ bcm54xx_adjust_rxrefclk(phydev);
+
+ return ret;
+}
+
+static int bcm54xx_cable_test_get_status(struct phy_device *phydev,
+ bool *finished)
+{
+ int ret;
+
+ ret = bcm_phy_cable_test_get_status(phydev, finished);
+ if (ret < 0 || !*finished)
+ return ret;
+
+ /* Put auto power-down back the way config_init() left it */
+ bcm54xx_adjust_rxrefclk(phydev);
+
+ return 0;
+}
+
static struct phy_driver broadcom_drivers[] = {
{
PHY_ID_MATCH_MODEL(PHY_ID_BCM5411),
@@ -1498,7 +1536,8 @@ static struct phy_driver broadcom_drivers[] = {
PHY_ID_MATCH_MODEL(PHY_ID_BCM54210E),
.name = "Broadcom BCM54210E",
/* PHY_GBIT_FEATURES */
- .flags = PHY_ALWAYS_CALL_SUSPEND,
+ .flags = PHY_ALWAYS_CALL_SUSPEND |
+ PHY_POLL_CABLE_TEST,
.get_sset_count = bcm_phy_get_sset_count,
.get_strings = bcm_phy_get_strings,
.get_stats = bcm54xx_get_stats,
@@ -1513,6 +1552,8 @@ static struct phy_driver broadcom_drivers[] = {
.set_wol = bcm54xx_phy_set_wol,
.led_brightness_set = bcm_phy_led_brightness_set,
.disable_autonomous_eee = bcm54xx_disable_autonomous_eee,
+ .cable_test_start = bcm54xx_cable_test_start,
+ .cable_test_get_status = bcm54xx_cable_test_get_status,
}, {
PHY_ID_MATCH_MODEL(PHY_ID_BCM5461),
.name = "Broadcom BCM5461",
--
2.53.0
^ permalink raw reply related [flat|nested] 4+ messages in thread