* [PATCH net-next 0/3] net: phy: Cable tests for BCM54210E
@ 2026-12-03 0:47 Florian Fainelli
2026-12-03 0:48 ` [PATCH net-next 1/3] net: phy: broadcom: Implement cable test initialization Florian Fainelli
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: Florian Fainelli @ 2026-12-03 0:47 UTC (permalink / raw)
To: netdev
Cc: Florian Fainelli, Florian Fainelli,
Broadcom internal kernel review list, Andrew Lunn,
Heiner Kallweit, Russell King, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni
From: Florian Fainelli <f.fainelli@gmail.com>
This patch series adds support for Cable tests and wires it up to the
BCM54210E PHY entry which is used on the Raspberry Pi 4 Model B and CM4
boards.
Nicolas helped me with cleaning up the code and as a second person
testing on his own systems.
Florian Fainelli (2):
net: phy: broadcom: Implement cable test initialization
net: phy: broadcom: Wire-up cable tests for BCM54210E
Nicolai Buchwitz (1):
net: phy: broadcom: Time out a stuck cable test
drivers/net/phy/bcm-phy-lib.c | 198 +++++++++++++++++++++++++++++-----
drivers/net/phy/broadcom.c | 67 +++++++++++-
include/linux/brcmphy.h | 1 +
3 files changed, 238 insertions(+), 28 deletions(-)
--
2.53.0
^ permalink raw reply [flat|nested] 9+ messages in thread* [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-04 1:29 ` netdev-bot+sashiko 2026-12-03 0:48 ` [PATCH net-next 2/3] net: phy: broadcom: Wire-up cable tests for BCM54210E Florian Fainelli ` (2 subsequent siblings) 3 siblings, 1 reply; 9+ 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] 9+ messages in thread
* Re: [PATCH net-next 1/3] net: phy: broadcom: Implement cable test initialization 2026-12-03 0:48 ` [PATCH net-next 1/3] net: phy: broadcom: Implement cable test initialization Florian Fainelli @ 2026-12-04 1:29 ` netdev-bot+sashiko 0 siblings, 0 replies; 9+ messages in thread From: netdev-bot+sashiko @ 2026-12-04 1:29 UTC (permalink / raw) To: florian.fainelli Cc: netdev, nb, f.fainelli, bcm-kernel-feedback-list, andrew, hkallweit1, linux, davem, edumazet, kuba, pabeni Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider. Critical: 0 · High: 0 · Medium: 2 · Low: 1 If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough). - [Medium] _bcm_phy_cable_test_start() in drivers/net/phy/bcm-phy-lib.c (lines 827-829) now calls __bcm_phy_cable_test_init() every time, for… - [Medium] The commit message only describes adding an ECD initialization sequence. - [Low] In _bcm_phy_load_values() (drivers/net/phy/bcm-phy- lib.c:665-709), the 0xEF write is commented "Specify the number of E*… -- net: phy: broadcom: Implement cable test initialization This patch adds an ECD initialization sequence to bcm-phy-lib. Before every cable test starts, the sequence loads a fixed set of vendor values into the expansion registers. It also moves per-pair result reporting into bcm_phy_cable_test_report_pair() and adds a new BCM54XX_ECD_LENGTH_RESULTS_FAILED sentinel. > diff --git a/drivers/net/phy/bcm-phy-lib.c b/drivers/net/phy/bcm-phy-lib.c > index b64beade8dd93..9571928db0291 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)); [Severity: Low] This isn't a bug, but the comment says this writes the number of E* registers. The value written is actually a bitmask built only from num_regs: page_num << 14 | GENMASK(num_regs - 1, 0) The regs[i].reg offsets are not used here. That means this is only correct when regs[] covers 0xe0, 0xe1, ... in order with no gaps. Both current callers meet that requirement: page 1 is 0xe0-0xe7 and page 2 is 0xe0-0xe2. The page0_init_regs table in __bcm_phy_cable_test_init() does not (0xe0-0xe4, 0xe8-0xea). If that table were passed to this helper, it would enable E5-E7 instead of E8-EA. Could this comment, and the one above _bcm_phy_load_values(), call the value an enable mask and state the contiguity requirement? [ ... ] > @@ -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; [Severity: Medium] This now runs the vendor init sequence every time, for every PHY that uses the shared ECD helpers. There is no PHY ID, revision or flag check. At this point in the series, the only in-tree user is the BCM54140 (bcm54140_drivers in bcm54140.c, via bcm_phy_cable_test_start_rdb()). Its cable test already worked without this sequence: ethtool --cable-test phy_start_cable_test() bcm_phy_cable_test_start_rdb() _bcm_phy_cable_test_start(phydev, true) __bcm_phy_cable_test_init() The commit message only says "a number of PHYs" and does not name them. Were the register tables in __bcm_phy_cable_test_init(), and the new 0x47ae failed value, validated on the BCM54140? The later patch that wires up the BCM54210E says it was tested on that PHY (RPi 4B). Nothing seems to cover the BCM54140, and no later patch in the series gates this init. Should this be limited to the PHYs it is known to apply to? If not, could the commit message say which PHYs it was verified on? [ ... ] > @@ -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); > } [Severity: Medium] The commit message only describes the new ECD initialization sequence. This hunk also changes what gets reported to user space. When a pair's length register reads 0x47ae, the fault code from the hardware (OPEN, SAME_SHORT or CROSS_SHORT) is now replaced with ETHTOOL_A_CABLE_RESULT_CODE_UNSPEC, and no length is reported. Before this patch, the translated fault code was always reported. The length was skipped only for 0xffff, so 0x47ae reached user space as a fault length of 18350 cm. This changes ethtool --cable-test output on hardware that is already supported, such as the BCM54140. Could the commit message describe this change and say where the 0x47ae value comes from? Would it make sense to split it into its own patch, possibly with a Fixes: tag? [ ... ] -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261203004802.85707-1-florian.fainelli%40broadcom.com ^ permalink raw reply [flat|nested] 9+ 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 12:59 ` Nicolai Buchwitz 2026-12-04 1:29 ` netdev-bot+sashiko 2026-12-03 0:48 ` [PATCH net-next 3/3] net: phy: broadcom: Time out a stuck cable test Florian Fainelli 2026-12-03 21:20 ` [PATCH net-next 0/3] net: phy: Cable tests for BCM54210E Nicolai Buchwitz 3 siblings, 2 replies; 9+ 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] 9+ messages in thread
* Re: [PATCH net-next 2/3] net: phy: broadcom: Wire-up cable tests for BCM54210E 2026-12-03 0:48 ` [PATCH net-next 2/3] net: phy: broadcom: Wire-up cable tests for BCM54210E Florian Fainelli @ 2026-12-03 12:59 ` Nicolai Buchwitz 2026-12-04 1:29 ` netdev-bot+sashiko 1 sibling, 0 replies; 9+ messages in thread From: Nicolai Buchwitz @ 2026-12-03 12:59 UTC (permalink / raw) To: Florian Fainelli Cc: netdev, Broadcom internal kernel review list, Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni On 3.12.2026 01:48, Florian Fainelli wrote: > 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> > [...] Reviewed-by: Nicolai Buchwitz <nb@tipi-net.de> Thanks, Nicolai ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH net-next 2/3] net: phy: broadcom: Wire-up cable tests for BCM54210E 2026-12-03 0:48 ` [PATCH net-next 2/3] net: phy: broadcom: Wire-up cable tests for BCM54210E Florian Fainelli 2026-12-03 12:59 ` Nicolai Buchwitz @ 2026-12-04 1:29 ` netdev-bot+sashiko 1 sibling, 0 replies; 9+ messages in thread From: netdev-bot+sashiko @ 2026-12-04 1:29 UTC (permalink / raw) To: florian.fainelli Cc: netdev, nb, f.fainelli, bcm-kernel-feedback-list, andrew, hkallweit1, linux, davem, edumazet, kuba, pabeni Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin. Low priority / nit picks for your consideration: - [Low] The commit message for "net: phy: broadcom: Wire-up cable tests for BCM54210E" is cut off and leaves out what the patch actually… -- net: phy: broadcom: Wire-up cable tests for BCM54210E This commit enables cable diagnostics on the BCM54210E PHY. It sets PHY_POLL_CABLE_TEST and adds bcm54xx_cable_test_start() and bcm54xx_cable_test_get_status(). These wrappers turn off auto power-down while the ECD test runs and restore it afterwards. > 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> [Severity: Low] This isn't a bug, but the commit message looks cut off. It ends with "using a BCM54210E PHY:" and then goes straight to the Signed-off-by. Was the verification output, for example the ethtool --cable-test results, meant to go after that colon? The message also says the patch only wires up existing helpers. It actually adds two wrappers in drivers/net/phy/broadcom.c that change the PHY power management state during the test. bcm54xx_cable_test_start() clears BCM54XX_SHD_APD_EN before it starts ECD: /* 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); ... ret = bcm_phy_write_shadow(phydev, BCM54XX_SHD_APD, val & ~BCM54XX_SHD_APD_EN); The SCR3 and APD shadow registers are then rewritten through bcm54xx_adjust_rxrefclk() in two places: - in bcm54xx_cable_test_start(), when bcm_phy_cable_test_start() fails - in bcm54xx_cable_test_get_status(), once the test finishes Could the commit message describe this auto power-down workaround and the reason for it? Right now the code comment is the only record of it. Also, PHY_ID_MATCH_MODEL(PHY_ID_BCM54210E) masks the revision nibble. That means cable test is enabled for every PHY matching this model ID. This includes the Raspberry Pi 4B PHY, which is usually called a BCM54213PE. Could the message say so? -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261203004802.85707-1-florian.fainelli%40broadcom.com ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH net-next 3/3] net: phy: broadcom: Time out a stuck cable test 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 ` [PATCH net-next 2/3] net: phy: broadcom: Wire-up cable tests for BCM54210E Florian Fainelli @ 2026-12-03 0:48 ` Florian Fainelli 2026-12-04 1:29 ` netdev-bot+sashiko 2026-12-03 21:20 ` [PATCH net-next 0/3] net: phy: Cable tests for BCM54210E Nicolai Buchwitz 3 siblings, 1 reply; 9+ messages in thread From: Florian Fainelli @ 2026-12-03 0:48 UTC (permalink / raw) To: netdev Cc: Nicolai Buchwitz, Florian Fainelli, Florian Fainelli, Broadcom internal kernel review list, Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni From: Nicolai Buchwitz <nb@tipi-net.de> A stuck ECD run leaves the PHY in PHY_CABLETEST for good. Give up after 5 seconds and reset the PHY so the link can come back. Signed-off-by: Nicolai Buchwitz <nb@tipi-net.de> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com> --- drivers/net/phy/broadcom.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/drivers/net/phy/broadcom.c b/drivers/net/phy/broadcom.c index 19b97beb8be8..776a88caae9b 100644 --- a/drivers/net/phy/broadcom.c +++ b/drivers/net/phy/broadcom.c @@ -30,12 +30,16 @@ MODULE_DESCRIPTION("Broadcom PHY driver"); MODULE_AUTHOR("Maciej W. Rozycki"); MODULE_LICENSE("GPL"); +/* An ECD run takes less than a second */ +#define BCM54XX_CABLE_TEST_TIMEOUT_MS 5000 + struct bcm54xx_phy_priv { u64 *stats; struct bcm_ptp_private *ptp; int wake_irq; bool wake_irq_enabled; bool brr_mode; + unsigned long cable_test_timeout; }; /* Link modes for BCM58411 PHY */ @@ -1471,6 +1475,7 @@ static int bcm54xx_disable_autonomous_eee(struct phy_device *phydev) static int bcm54xx_cable_test_start(struct phy_device *phydev) { + struct bcm54xx_phy_priv *priv = phydev->priv; int val, ret; /* The ECD run never finishes on a line without energy while auto @@ -1486,21 +1491,40 @@ static int bcm54xx_cable_test_start(struct phy_device *phydev) return ret; ret = bcm_phy_cable_test_start(phydev); - if (ret < 0) + if (ret < 0) { bcm54xx_adjust_rxrefclk(phydev); + return ret; + } - return ret; + priv->cable_test_timeout = jiffies + + msecs_to_jiffies(BCM54XX_CABLE_TEST_TIMEOUT_MS); + + return 0; } static int bcm54xx_cable_test_get_status(struct phy_device *phydev, bool *finished) { + struct bcm54xx_phy_priv *priv = phydev->priv; int ret; ret = bcm_phy_cable_test_get_status(phydev, finished); - if (ret < 0 || !*finished) + if (ret < 0) return ret; + if (!*finished) { + if (time_before(jiffies, priv->cable_test_timeout)) + return 0; + + /* A stuck ECD run cannot be stopped through ECD_CTRL, only a + * reset gets the PHY back. phylib reruns config_init() when + * it aborts the test. + */ + genphy_soft_reset(phydev); + + return -ETIMEDOUT; + } + /* Put auto power-down back the way config_init() left it */ bcm54xx_adjust_rxrefclk(phydev); -- 2.53.0 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH net-next 3/3] net: phy: broadcom: Time out a stuck cable test 2026-12-03 0:48 ` [PATCH net-next 3/3] net: phy: broadcom: Time out a stuck cable test Florian Fainelli @ 2026-12-04 1:29 ` netdev-bot+sashiko 0 siblings, 0 replies; 9+ messages in thread From: netdev-bot+sashiko @ 2026-12-04 1:29 UTC (permalink / raw) To: florian.fainelli Cc: netdev, nb, f.fainelli, bcm-kernel-feedback-list, andrew, hkallweit1, linux, davem, edumazet, kuba, pabeni Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider. Critical: 0 · High: 0 · Medium: 1 · Low: 2 If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough). - [Medium] The patch resets the PHY only in the timeout branch of bcm54xx_cable_test_get_status() (drivers/net/phy/broadcom.c:1523),… - [Low] The timeout branch in bcm54xx_cable_test_get_status() (drivers/net/phy/broadcom.c:1523) adds a runtime BMCR_RESET for… - [Low] When a cable test times out, bcm54xx_cable_test_get_status() (drivers/net/phy/broadcom.c:1515-1526) resets the PHY with… -- net: phy: broadcom: Time out a stuck cable test This commit adds a 5 second timeout to bcm54xx_cable_test_get_status(). If the ECD run has not finished by then, the PHY is soft-reset and -ETIMEDOUT is returned, so phylib aborts the test and reruns config_init(). > diff --git a/drivers/net/phy/broadcom.c b/drivers/net/phy/broadcom.c > index 19b97beb8be8d..776a88caae9ba 100644 > --- a/drivers/net/phy/broadcom.c > +++ b/drivers/net/phy/broadcom.c [ ... ] > @@ -1486,21 +1491,40 @@ static int bcm54xx_cable_test_start(struct phy_device *phydev) [ ... ] > static int bcm54xx_cable_test_get_status(struct phy_device *phydev, > bool *finished) > { > + struct bcm54xx_phy_priv *priv = phydev->priv; > int ret; > > ret = bcm_phy_cable_test_get_status(phydev, finished); > - if (ret < 0 || !*finished) > + if (ret < 0) > return ret; > > + if (!*finished) { > + if (time_before(jiffies, priv->cable_test_timeout)) > + return 0; > + > + /* A stuck ECD run cannot be stopped through ECD_CTRL, only a > + * reset gets the PHY back. phylib reruns config_init() when > + * it aborts the test. > + */ > + genphy_soft_reset(phydev); [Severity: Medium] Is this the only place that resets the PHY after an ECD run has started? Only the polling state machine reaches it, and only after the 5 second timeout expires. Two other paths in drivers/net/phy/phy.c leave PHY_CABLETEST. The first is phy_stop(), for example "ip link set dev X down" while a test is running: if (phydev->state == PHY_CABLETEST) { phy_abort_cable_test(phydev); netif_testing_off(dev); } The second is _phy_state_machine(), when cable_test_get_status() takes the ret < 0 path above: err = phydev->drv->cable_test_get_status(phydev, &finished); if (err) { phy_abort_cable_test(phydev); netif_testing_off(dev); state_work = PHY_STATE_WORK_ANEG; phydev->state = PHY_UP; break; } phy_abort_cable_test() only calls ethnl_cable_test_finished() and phy_init_hw(). The BCM54210E entry in broadcom_drivers[] has no .soft_reset callback, so phy_init_hw() skips the reset and goes straight to bcm54xx_config_init(). bcm54xx_config_init() then calls bcm54xx_adjust_rxrefclk(). That sets BCM54XX_SHD_APD_EN again when clk125 is disabled or PHY_BRCM_AUTO_PWRDWN_ENABLE is set. At that point ECD_CTRL still has RUN and BREAK_LINK set from _bcm_phy_cable_test_start(). The comment in bcm54xx_cable_test_start() says an ECD run never finishes on a line without energy while auto power-down is enabled. The new comment here says only a reset clears a stuck run. Could aborting a test partway through therefore create the same stuck state this patch tries to recover from? After the abort the state is PHY_UP or PHY_HALTED. Nothing polls cable_test_get_status() again, so this timeout never fires. On the phy_stop() path with WoL enabled, bcm54xx_suspend() returns before it writes BMCR_PDOWN: if (phydev->wol_enabled) return bcm54xx_set_wakeup_irq(phydev, true); bcm54xx_resume() soft-resets only when PHY_BRCM_IDDQ_SUSPEND is set. A down/up cycle would therefore not clear the stuck run either. The error path goes straight to PHY_UP without any suspend. This depends on two hardware behaviours I could not verify. One is that the ECD run stays stuck through config_init() with APD re-enabled. The other is that the later BMCR writes from config_aneg do not clear it. Could the reset go somewhere that every abort passes through? One option is ".soft_reset = genphy_soft_reset" in the BCM54210E entry. Another is a reset in bcm54xx_config_init() when ECD_CTRL still reads in progress. [Severity: Low] Can this reset wipe state that config_init() does not restore? The comment says phylib reruns config_init() when it aborts the test. That is true, through phy_abort_cable_test()->phy_init_hw()-> bcm54xx_config_init(). But config_init() only restores the settings it makes itself. An earlier commit in this series, "net: phy: broadcom: Implement cable test initialization", left the soft reset out of the reference ECD sequence for exactly this reason: drivers/net/phy/bcm-phy-lib.c:__bcm_phy_cable_test_init() { ... /* 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. */ ... } Wake-on-LAN, for example, is written directly to hardware by bcm54xx_phy_set_wol()->bcm_phy_set_wol(), and no copy is kept. bcm54xx_config_init() only reads and acknowledges BCM54XX_WOL_INT_STATUS. Suppose BMCR_RESET clears the WoL registers on BCM54210E. Would WoL set with "ethtool -s ethX wol g" then stop working after a timed-out cable test, with no message, while the kernel still reports it as enabled? I could not confirm this on the hardware. bcm54xx_resume() already soft-resets on PHY_BRCM_IDDQ_SUSPEND platforms without reprogramming WoL, which may mean the registers survive a reset. The commit message also doesn't mention this side effect of the reset. Could it be added? > + > + return -ETIMEDOUT; > + } [Severity: Low] Should this timeout branch log something? The return value of genphy_soft_reset() is ignored, and nothing is printed. _phy_state_machine() handles -ETIMEDOUT by calling phy_abort_cable_test(). That sends the notification created by ethnl_cable_test_alloc() with ETHTOOL_A_CABLE_TEST_NTF_STATUS_COMPLETED and no pair results, and phylib then drops the error code. As a result, "ethtool --cable-test" reports a completed test with no results. Nothing in dmesg says the ECD run hung or that the PHY was reset. Would a phydev_warn() here help? The commit message also doesn't say what the user sees in this case. > + > /* Put auto power-down back the way config_init() left it */ > bcm54xx_adjust_rxrefclk(phydev); [ ... ] -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261203004802.85707-1-florian.fainelli%40broadcom.com ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH net-next 0/3] net: phy: Cable tests for BCM54210E 2026-12-03 0:47 [PATCH net-next 0/3] net: phy: Cable tests for BCM54210E Florian Fainelli ` (2 preceding siblings ...) 2026-12-03 0:48 ` [PATCH net-next 3/3] net: phy: broadcom: Time out a stuck cable test Florian Fainelli @ 2026-12-03 21:20 ` Nicolai Buchwitz 3 siblings, 0 replies; 9+ messages in thread From: Nicolai Buchwitz @ 2026-12-03 21:20 UTC (permalink / raw) To: Florian Fainelli Cc: netdev, Florian Fainelli, Broadcom internal kernel review list, Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni On 3.12.2026 01:47, Florian Fainelli wrote: > From: Florian Fainelli <f.fainelli@gmail.com> > > This patch series adds support for Cable tests and wires it up to the > BCM54210E PHY entry which is used on the Raspberry Pi 4 Model B and CM4 > boards. > > Nicolas helped me with cleaning up the code and as a second person > testing on his own systems. > > Florian Fainelli (2): > net: phy: broadcom: Implement cable test initialization > net: phy: broadcom: Wire-up cable tests for BCM54210E > > Nicolai Buchwitz (1): > net: phy: broadcom: Time out a stuck cable test > > drivers/net/phy/bcm-phy-lib.c | 198 +++++++++++++++++++++++++++++----- > drivers/net/phy/broadcom.c | 67 +++++++++++- > include/linux/brcmphy.h | 1 + > 3 files changed, 238 insertions(+), 28 deletions(-) For the series: Tested-by: Nicolai Buchwitz <nb@tipi-net.de> # Raspberry Pi CM4 + CM5 (BCM54210PE) ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-12-04 1:29 UTC | newest] Thread overview: 9+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 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-04 1:29 ` netdev-bot+sashiko 2026-12-03 0:48 ` [PATCH net-next 2/3] net: phy: broadcom: Wire-up cable tests for BCM54210E Florian Fainelli 2026-12-03 12:59 ` Nicolai Buchwitz 2026-12-04 1:29 ` netdev-bot+sashiko 2026-12-03 0:48 ` [PATCH net-next 3/3] net: phy: broadcom: Time out a stuck cable test Florian Fainelli 2026-12-04 1:29 ` netdev-bot+sashiko 2026-12-03 21:20 ` [PATCH net-next 0/3] net: phy: Cable tests for BCM54210E Nicolai Buchwitz
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox