net: phy: bcm5481x: add support for BroadR-Reach mode
Subsystems (6)
v11 cover net: phy: bcm5481x: add support for BroadR-Reach mode
PATCH 1 - Add the 10baseT1BRR_Full link mode
PATCH 2 - Add the definitions of LRE registers, necessary to use
BroadR-Reach modes on the BCM5481x PHY
PATCH 3 - Add brr-mode flag to switch between IEEE802.3 and BroadR-Reach
PATCH 4 - Implementation of the BroadR-Reach modes for the Broadcom
PHYs
Changes in v2:
- Divided into multiple patches, removed useless link modes
Changes in v3:
- Fixed uninitialized variable in bcm5481x_config_delay_swap function
Changes in v4:
- Improved the division of functions between bcm-phy library and broadcom.c
- Changed the BroadR-Reach / IEEE mode switching to device tree boolean as these modes are mutually exclusive and barely could coexist in one hardware
- Made the link mode selection compatible with current ethtool (i.e. the linkmode is selected by choosing speed and master-slave)
Changes in v5:
- Fixed the operator precedence as reported by the kernel test robot
- Fixed doc of bcm_linkmode_adv_to_mii_adv_t function
Changes in v6:
- Moved the brr-mode flag to separate commit as required by the rules for DT binding patches
- Renamed some functions to make clear they handle LRE-related stuff
- Reordered variable definitions to match the coding style requirements
Changes in v7:
- Fixed the changes distribution into patches (first one was not buildable)
Changes in v8:
- Fixed coding style and did other changes on behalf of the reviewers
Changes in v9:
- Applied reviewed tags to unchanged commits, reformatted the submitter's address
Changes in v10:
- Fixed minor CR issues, clarified the embedded documentation and the commit message
Changes in v11:
- Reworded the brr-mode flag documentation
Kamil Horák (2N) (4):
net: phy: bcm54811: New link mode for BroadR-Reach
net: phy: bcm54811: Add LRE registers definitions
dt-bindings: ethernet-phy: add optional brr-mode flag
net: phy: bcm-phy-lib: Implement BroadR-Reach link modes
.../devicetree/bindings/net/ethernet-phy.yaml | 8 + drivers/net/phy/bcm-phy-lib.c | 115 +++++ drivers/net/phy/bcm-phy-lib.h | 4 + drivers/net/phy/broadcom.c | 405 +++++++++++++++++- drivers/net/phy/phy-core.c | 3 +- include/linux/brcmphy.h | 88 ++++ include/uapi/linux/ethtool.h | 1 + net/ethtool/common.c | 3 + 8 files changed, 608 insertions(+), 19 deletions(-)
Signature · 1 line
2.39.2
PATCH v11 1/4 net: phy: bcm54811: New link mode for BroadR-Reach
Introduce a new link mode necessary for 10 MBit single-pair connection in BroadR-Reach mode on bcm5481x PHY by Broadcom. This new link mode, 10baseT1BRR, is known as 1BR10 in the Broadcom terminology. Another link mode to be used is 1BR100 and it is already present as 100baseT1, because Broadcom's 1BR100 became 100baseT1 (IEEE 802.3bw).
--- drivers/net/phy/phy-core.c | 3 ++- include/uapi/linux/ethtool.h | 1 + net/ethtool/common.c | 3 +++ 3 files changed, 6 insertions(+), 1 deletion(-)
drivers/net/phy/phy-core.c +2 -1
@@ -13,7 +13,7 @@*/ const char *phy_speed_to_str (int speed) { -BUILD_BUG_ON_MSG (__ETHTOOL_LINK_MODE_MASK_NBITS !=102 , +BUILD_BUG_ON_MSG (__ETHTOOL_LINK_MODE_MASK_NBITS !=103 ,"Enum ethtool_link_mode_bit_indices and phylib are out of sync. " "If a speed or mode has been added please update phy_speed_to_str " "and the PHY settings array.\n" );
@@ -266,6 +266,7 @@ static const struct phy_setting settings[] = { PHY_SETTING( 10, FULL, 10baseT1S_Full ), PHY_SETTING( 10, HALF, 10baseT1S_Half ), PHY_SETTING( 10, HALF, 10baseT1S_P2MP_Half ), + PHY_SETTING( 10, FULL, 10baseT1BRR_Full ), };#undef PHY_SETTING
include/uapi/linux/ethtool.h +1 -0
@@ -1863,6 +1863,7 @@ enum ethtool_link_mode_bit_indices { ETHTOOL_LINK_MODE_10baseT1S_Full_BIT =99 , ETHTOOL_LINK_MODE_10baseT1S_Half_BIT =100 , ETHTOOL_LINK_MODE_10baseT1S_P2MP_Half_BIT =101 , + ETHTOOL_LINK_MODE_10baseT1BRR_Full_BIT =102 ,/* must be last entry */ __ETHTOOL_LINK_MODE_MASK_NBITS
net/ethtool/common.c +3 -0
@@ -211,6 +211,7 @@ const char link_mode_names[][ETH_GSTRING_LEN] = {__DEFINE_LINK_MODE_NAME (10 ,T1S , Full),__DEFINE_LINK_MODE_NAME (10 ,T1S , Half),__DEFINE_LINK_MODE_NAME (10 ,T1S_P2MP , Half), +__DEFINE_LINK_MODE_NAME (10 ,T1BRR , Full), };static_assert (ARRAY_SIZE (link_mode_names) == __ETHTOOL_LINK_MODE_MASK_NBITS);
@@ -251,6 +252,7 @@ static_assert(ARRAY_SIZE(link_mode_names) == __ETHTOOL_LINK_MODE_MASK_NBITS);#define __LINK_MODE_LANES_T1S_P2MP 1#define __LINK_MODE_LANES_VR8 8#define __LINK_MODE_LANES_DR8_2 8 +#define __LINK_MODE_LANES_T1BRR 1#define __DEFINE_LINK_MODE_PARAMS (_speed, _type, _duplex) \ [ETHTOOL_LINK_MODE(_speed, _type, _duplex)] = { \
@@ -374,6 +376,7 @@ const struct link_mode_info link_mode_params[] = {__DEFINE_LINK_MODE_PARAMS (10 ,T1S , Full),__DEFINE_LINK_MODE_PARAMS (10 ,T1S , Half),__DEFINE_LINK_MODE_PARAMS (10 ,T1S_P2MP , Half), +__DEFINE_LINK_MODE_PARAMS (10 ,T1BRR , Full), };static_assert (ARRAY_SIZE (link_mode_params) == __ETHTOOL_LINK_MODE_MASK_NBITS);
Signature · 1 line
2.39.2
PATCH v11 2/4 net: phy: bcm54811: Add LRE registers definitions
In reply to Kamil Horák (2N)Add the definitions of LRE registers for Broadcom BCM5481x PHY
--- include/linux/brcmphy.h | 88 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+)
include/linux/brcmphy.h +88 -0
@@ -271,12 +271,100 @@#define BCM5482_SSD_SGMII_SLAVE_EN 0x0002/* Slave mode enable */ #define BCM5482_SSD_SGMII_SLAVE_AD 0x0001/* Slave auto-detection */ +/* BroadR-Reach LRE Registers. */ +#define MII_BCM54XX_LRECR 0x00/* LRE Control Register */ +#define MII_BCM54XX_LRESR 0x01/* LRE Status Register */ +#define MII_BCM54XX_LREPHYSID1 0x02/* LRE PHYS ID 1 */ +#define MII_BCM54XX_LREPHYSID2 0x03/* LRE PHYS ID 2 */ +#define MII_BCM54XX_LREANAA 0x04/* LDS Auto-Negotiation Advertised Ability */ +#define MII_BCM54XX_LREANAC 0x05/* LDS Auto-Negotiation Advertised Control */ +#define MII_BCM54XX_LREANPT 0x06/* LDS Ability Next Page Transmit */ +#define MII_BCM54XX_LRELPA 0x07/* LDS Link Partner Ability */ +#define MII_BCM54XX_LRELPNPM 0x08/* LDS Link Partner Next Page Message */ +#define MII_BCM54XX_LRELPNPC 0x09/* LDS Link Partner Next Page Control */ +#define MII_BCM54XX_LRELDSE 0x0a/* LDS Expansion Register */ +#define MII_BCM54XX_LREES 0x0f/* LRE Extended Status */ + +/* LRE control register. */ +#define LRECR_RESET 0x8000/* Reset to default state */ +#define LRECR_LOOPBACK 0x4000/* Internal Loopback */ +#define LRECR_LDSRES 0x2000/* Restart LDS Process */ +#define LRECR_LDSEN 0x1000/* LDS Enable */ +#define LRECR_PDOWN 0x0800/* Enable low power state */ +#define LRECR_ISOLATE 0x0400/* Isolate data paths from MII */ +#define LRECR_SPEED100 0x0200/* Select 100 Mbps */ +#define LRECR_SPEED10 0x0000/* Select 10 Mbps */ +#define LRECR_4PAIRS 0x0020/* Select 4 Pairs */ +#define LRECR_2PAIRS 0x0010/* Select 2 Pairs */ +#define LRECR_1PAIR 0x0000/* Select 1 Pair */ +#define LRECR_MASTER 0x0008/* Force Master when LDS disabled */ +#define LRECR_SLAVE 0x0000/* Force Slave when LDS disabled */ + +/* LRE status register. */ +#define LRESR_100_1PAIR 0x2000/* Can do 100Mbps 1 Pair */ +#define LRESR_100_4PAIR 0x1000/* Can do 100Mbps 4 Pairs */ +#define LRESR_100_2PAIR 0x0800/* Can do 100Mbps 2 Pairs */ +#define LRESR_10_2PAIR 0x0400/* Can do 10Mbps 2 Pairs */ +#define LRESR_10_1PAIR 0x0200/* Can do 10Mbps 1 Pair */ +#define LRESR_ESTATEN 0x0100/* Extended Status in R15 */ +#define LRESR_RESV 0x0080/* Unused... */ +#define LRESR_MFPS 0x0040/* Can suppress Management Frames Preamble */ +#define LRESR_LDSCOMPLETE 0x0020/* LDS Auto-negotiation complete */ +#define LRESR_8023 0x0010/* Has IEEE 802.3 Support */ +#define LRESR_LDSABILITY 0x0008/* LDS auto-negotiation capable */ +#define LRESR_LSTATUS 0x0004/* Link status */ +#define LRESR_JCD 0x0002/* Jabber detected */ +#define LRESR_ERCAP 0x0001/* Ext-reg capability */ + +/* LDS Auto-Negotiation Advertised Ability. */ +#define LREANAA_PAUSE_ASYM 0x8000/* Can pause asymmetrically */ +#define LREANAA_PAUSE 0x4000/* Can pause */ +#define LREANAA_100_1PAIR 0x0020/* Can do 100Mbps 1 Pair */ +#define LREANAA_100_4PAIR 0x0010/* Can do 100Mbps 4 Pair */ +#define LREANAA_100_2PAIR 0x0008/* Can do 100Mbps 2 Pair */ +#define LREANAA_10_2PAIR 0x0004/* Can do 10Mbps 2 Pair */ +#define LREANAA_10_1PAIR 0x0002/* Can do 10Mbps 1 Pair */ + +#define LRE_ADVERTISE_FULL (LREANAA_100_1PAIR | LREANAA_100_4PAIR | \ + LREANAA_100_2PAIR | LREANAA_10_2PAIR | \ + LREANAA_10_1PAIR) + +#define LRE_ADVERTISE_ALL LRE_ADVERTISE_FULL + +/* LDS Link Partner Ability. */ +#define LRELPA_PAUSE_ASYM 0x8000/* Supports asymmetric pause */ +#define LRELPA_PAUSE 0x4000/* Supports pause capability */ +#define LRELPA_100_1PAIR 0x0020/* 100Mbps 1 Pair capable */ +#define LRELPA_100_4PAIR 0x0010/* 100Mbps 4 Pair capable */ +#define LRELPA_100_2PAIR 0x0008/* 100Mbps 2 Pair capable */ +#define LRELPA_10_2PAIR 0x0004/* 10Mbps 2 Pair capable */ +#define LRELPA_10_1PAIR 0x0002/* 10Mbps 1 Pair capable */ + +/* LDS Expansion register. */ +#define LDSE_DOWNGRADE 0x8000/* Can do LDS Speed Downgrade */ +#define LDSE_MASTER 0x4000/* Master / Slave */ +#define LDSE_PAIRS_MASK 0x3000/* Pair Count Mask */ +#define LDSE_PAIRS_SHIFT 12 +#define LDSE_4PAIRS (2 << LDSE_PAIRS_SHIFT)/* 4 Pairs Connection */ +#define LDSE_2PAIRS (1 << LDSE_PAIRS_SHIFT)/* 2 Pairs Connection */ +#define LDSE_1PAIR (0 << LDSE_PAIRS_SHIFT)/* 1 Pair Connection */ +#define LDSE_CABLEN_MASK 0x0FFF/* Cable Length Mask */ +/* BCM54810 Registers */ #define BCM54810_EXP_BROADREACH_LRE_MISC_CTL (MII_BCM54XX_EXP_SEL_ER + 0x90)#define BCM54810_EXP_BROADREACH_LRE_MISC_CTL_EN (1 << 0)#define BCM54810_SHD_CLK_CTL 0x3#define BCM54810_SHD_CLK_CTL_GTXCLK_EN (1 << 9) +/* BCM54811 Registers */ +#define BCM54811_EXP_BROADREACH_LRE_OVERLAY_CTL (MII_BCM54XX_EXP_SEL_ER + 0x9A) +/* Access Control Override Enable */ +#define BCM54811_EXP_BROADREACH_LRE_OVERLAY_CTL_EN BIT(15) +/* Access Control Override Value */ +#define BCM54811_EXP_BROADREACH_LRE_OVERLAY_CTL_OVERRIDE_VAL BIT(14) +/* Access Control Value */ +#define BCM54811_EXP_BROADREACH_LRE_OVERLAY_CTL_VAL BIT(13) +/* BCM54612E Registers */ #define BCM54612E_EXP_SPARE0 (MII_BCM54XX_EXP_SEL_ETC + 0x34)#define BCM54612E_LED4_CLK125OUT_EN (1 << 1)
Signature · 1 line
2.39.2
PATCH v11 4/4 net: phy: bcm-phy-lib: Implement BroadR-Reach link modes
In reply to Kamil Horák (2N)Implement single-pair BroadR-Reach modes on bcm5481x PHY by Broadcom. Create set of functions alternative to IEEE 802.3 to handle configuration of these modes on compatible Broadcom PHYs. There is only subset of capabilities supported because of limited collection of hardware available for the development.
For BroadR-Reach capable PHYs, the LRE (Long Reach Ethernet) alternative register set is handled. Only bcm54811 PHY is verified, for bcm54810, there is some support possible but untested. There is no auto-negotiation of the link parameters (called LDS in the Broadcom terminology, Long-Distance Signaling) for bcm54811. It should be possible to enable LDS for bcm54810.
--- drivers/net/phy/bcm-phy-lib.c | 115 ++++++++++ drivers/net/phy/bcm-phy-lib.h | 4 + drivers/net/phy/broadcom.c | 405 ++++++++++++++++++++++++++++++++-- 3 files changed, 506 insertions(+), 18 deletions(-)
drivers/net/phy/bcm-phy-lib.c +115 -0
@@ -794,6 +794,49 @@ static int _bcm_phy_cable_test_get_status(struct phy_device *phydev,return ret; } +static int bcm_setup_lre_forced (struct phy_device *phydev) +{ +u16 ctl =0 ; + + phydev->pause =0 ; + phydev->asym_pause =0 ; + +if (phydev->speed ==SPEED_100 ) + ctl |=LRECR_SPEED100 ; + +if (phydev->duplex !=DUPLEX_FULL ) +return -EOPNOTSUPP ; + +return phy_modify (phydev,MII_BCM54XX_LRECR ,LRECR_SPEED100 , ctl); +} + +/** +* bcm_linkmode_adv_to_lre_adv_t - translate linkmode advertisement to LDS +* @advertising: the linkmode advertisement settings +* Return: LDS Auto-Negotiation Advertised Ability register value +* +* A small helper function that translates linkmode advertisement +* settings to phy LDS autonegotiation advertisements for the +* MII_BCM54XX_LREANAA register of Broadcom PHYs capable of LDS +*/ +static u32 bcm_linkmode_adv_to_lre_adv_t (unsigned long *advertising) +{ +u32 result =0 ; + +if (linkmode_test_bit (ETHTOOL_LINK_MODE_10baseT1BRR_Full_BIT, + advertising)) + result |=LREANAA_10_1PAIR ; +if (linkmode_test_bit (ETHTOOL_LINK_MODE_100baseT1_Full_BIT, + advertising)) + result |=LREANAA_100_1PAIR ; +if (linkmode_test_bit (ETHTOOL_LINK_MODE_Pause_BIT, advertising)) + result |=LRELPA_PAUSE ; +if (linkmode_test_bit (ETHTOOL_LINK_MODE_Asym_Pause_BIT, advertising)) + result |=LRELPA_PAUSE_ASYM ; + +return result; +} +int bcm_phy_cable_test_start (struct phy_device *phydev) {return _bcm_phy_cable_test_start (phydev, false);
@@ -1066,6 +1109,78 @@ int bcm_phy_led_brightness_set(struct phy_device *phydev, }EXPORT_SYMBOL_GPL (bcm_phy_led_brightness_set); +int bcm_setup_lre_master_slave (struct phy_device *phydev) +{ +u16 ctl =0 ; + +switch (phydev->master_slave_set) { +case MASTER_SLAVE_CFG_MASTER_PREFERRED : +case MASTER_SLAVE_CFG_MASTER_FORCE : + ctl =LRECR_MASTER ; +break ; +case MASTER_SLAVE_CFG_SLAVE_PREFERRED : +case MASTER_SLAVE_CFG_SLAVE_FORCE : +break ; +case MASTER_SLAVE_CFG_UNKNOWN : +case MASTER_SLAVE_CFG_UNSUPPORTED : +return 0 ; +default : +phydev_warn (phydev,"Unsupported Master/Slave mode\n" ); +return -EOPNOTSUPP ; + } + +return phy_modify_changed (phydev,MII_BCM54XX_LRECR ,LRECR_MASTER , ctl); +} +EXPORT_SYMBOL_GPL (bcm_setup_lre_master_slave); + +int bcm_config_lre_aneg (struct phy_device *phydev,bool changed) +{ +int err; + +if (genphy_config_eee_advert (phydev)) + changed = true; + + err =bcm_setup_lre_master_slave (phydev); +if (err <0 ) +return err; +else if (err) + changed = true; + +if (phydev->autoneg !=AUTONEG_ENABLE ) +return bcm_setup_lre_forced (phydev); + + err =bcm_config_lre_advert (phydev); +if (err <0 ) +return err; +else if (err) + changed = true; + +return genphy_check_and_restart_aneg (phydev, changed); +} +EXPORT_SYMBOL_GPL (bcm_config_lre_aneg); + +/** +* bcm_config_lre_advert - sanitize and advertise Long-Distance Signaling +* auto-negotiation parameters +* @phydev: target phy_device struct +* Return: 0 if the PHY's advertisement hasn't changed, < 0 on error, +* > 0 if it has changed +* +* Writes MII_BCM54XX_LREANAA with the appropriate values. The values are to be +* sanitized before, to make sure we only advertise what is supported. +* The sanitization is done already in phy_ethtool_ksettings_set() +*/ +int bcm_config_lre_advert (struct phy_device *phydev) +{ +u32 adv =bcm_linkmode_adv_to_lre_adv_t (phydev->advertising); + +/* Setup BroadR-Reach mode advertisement */ +return phy_modify_changed (phydev,MII_BCM54XX_LREANAA , +LRE_ADVERTISE_ALL |LREANAA_PAUSE | +LREANAA_PAUSE_ASYM , adv); +} +EXPORT_SYMBOL_GPL (bcm_config_lre_advert); +MODULE_DESCRIPTION ("Broadcom PHY Library" );MODULE_LICENSE ("GPL v2" );MODULE_AUTHOR ("Broadcom Corporation" );
drivers/net/phy/bcm-phy-lib.h +4 -0
@@ -121,4 +121,8 @@ irqreturn_t bcm_phy_wol_isr(int irq, void *dev_id);int bcm_phy_led_brightness_set (struct phy_device *phydev,u8 index,enum led_brightness value); +int bcm_setup_lre_master_slave (struct phy_device *phydev); +int bcm_config_lre_aneg (struct phy_device *phydev,bool changed); +int bcm_config_lre_advert (struct phy_device *phydev); +#endif /* _LINUX_BCM_PHY_LIB_H */
drivers/net/phy/broadcom.c +387 -18
461 lines not on this page · raw message
Signature · 1 line
2.39.2
PATCH v11 3/4 dt-bindings: ethernet-phy: add optional brr-mode flag
In reply to Kamil Horák (2N)There is a group of PHY chips supporting BroadR-Reach link modes in a manner allowing for more or less identical register usage as standard Clause 22 PHY.
These chips support standard Ethernet link modes as well, however, the circuitry is mutually exclusive and cannot be auto-detected. The link modes in question are 100Base-T1 as defined in IEEE802.3bw, based on Broadcom's 1BR-100 link mode, and newly defined 10Base-T1BRR (1BR-10 in Broadcom documents).
Add optional brr-mode flag to switch the PHY to BroadR-Reach mode.
--- Documentation/devicetree/bindings/net/ethernet-phy.yaml | 8 ++++++++ 1 file changed, 8 insertions(+)
Documentation/devicetree/bindings/net/ethernet-phy.yaml +8 -0
@@ -93,6 +93,14 @@ properties: the turn around line low at end of the control phase of the MDIO transaction. + brr-mode: + $ref: /schemas/types.yaml#/definitions/flag + description: + If set, indicates the network cable interface is an alternative one as + defined in the BroadR-Reach link mode specification under 1BR-100 and + 1BR-10 names. The PHY must be configured to operate in BroadR-Reach mode + by software. + clocks: maxItems: 1 description:
Signature · 1 line
2.39.2
Re: [PATCH v11 3/4] dt-bindings: ethernet-phy: add optional brr-mode flag
Quoted 9 lines · On Mon, 08 Jul 2024 12:27:15 +0200, Kamil Horák (2N) wrote:
There is a group of PHY chips supporting BroadR-Reach link modes in a manner allowing for more or less identical register usage as standard Clause 22 PHY.
These chips support standard Ethernet link modes as well, however, the circuitry is mutually exclusive and cannot be auto-detected. The link modes in question are 100Base-T1 as defined in IEEE802.3bw, based on Broadcom's 1BR-100 link mode, and newly defined 10Base-T1BRR (1BR-10 in Broadcom documents).
Quoted 7 lines
Add optional brr-mode flag to switch the PHY to BroadR-Reach mode.
Signed-off-by Kamil Horák (2N) <[email protected]>--- Documentation/devicetree/bindings/net/ethernet-phy.yaml | 8 ++++++++ 1 file changed, 8 insertions(+)
Jakub Kicinski
maintainerRe: [PATCH v11 1/4] net: phy: bcm54811: New link mode for BroadR-Reach
In reply to Kamil Horák (2N)Quoted 14 lines · On Mon, 8 Jul 2024 12:27:13 +0200 Kamil Horák (2N) wrote:
Introduce a new link mode necessary for 10 MBit single-pair connection in BroadR-Reach mode on bcm5481x PHY by Broadcom. This new link mode, 10baseT1BRR, is known as 1BR10 in the Broadcom terminology. Another link mode to be used is 1BR100 and it is already present as 100baseT1, because Broadcom's 1BR100 became 100baseT1 (IEEE 802.3bw).
Signed-off-by Kamil Horák (2N) <[email protected]>Reviewed-by Florian Fainelli <[email protected]>--- drivers/net/phy/phy-core.c | 3 ++- include/uapi/linux/ethtool.h | 1 + net/ethtool/common.c | 3 +++
include/uapi/linux/ethtool.h enum ethtool_link_mode_bit_indices { · line 1866
Quoted 1 line
include/uapi/linux/ethtool.h +1
-0+ ETHTOOL_LINK_MODE_10baseT1BRR_Full_BIT = 102,
Could we get an ack from phylib maintainers for the new mode?
Re: [PATCH v11 1/4] net: phy: bcm54811: New link mode for BroadR-Reach
In reply to Kamil Horák (2N)Quoted 9 lines · On Mon, Jul 08, 2024 at 12:27:13PM +0200, Kamil Horák (2N) wrote:
Introduce a new link mode necessary for 10 MBit single-pair connection in BroadR-Reach mode on bcm5481x PHY by Broadcom. This new link mode, 10baseT1BRR, is known as 1BR10 in the Broadcom terminology. Another link mode to be used is 1BR100 and it is already present as 100baseT1, because Broadcom's 1BR100 became 100baseT1 (IEEE 802.3bw).
Signed-off-by Kamil Horák (2N) <[email protected]>Reviewed-by Florian Fainelli <[email protected]>
Andrew
Andrew Lunn
maintainerRe: [PATCH v11 4/4] net: phy: bcm-phy-lib: Implement BroadR-Reach link modes
In reply to Kamil Horák (2N)drivers/net/phy/broadcom.c static int bcm54810_write_mmd(struct phy_device *phydev, int devnum, u16 regnum, · line 565
Quoted 11 lines
drivers/net/phy/broadcom.c +2
-6+static int bcm5481x_get_brrmode (struct phy_device *phydev,u8 *data) { -int err, reg; +int reg; -/* Disable BroadR-Reach function. */ reg =bcm_phy_read_exp (phydev,BCM54810_EXP_BROADREACH_LRE_MISC_CTL ); - reg &= ~BCM54810_EXP_BROADREACH_LRE_MISC_CTL_EN ; - err =bcm_phy_write_exp (phydev,BCM54810_EXP_BROADREACH_LRE_MISC_CTL , - reg); -if (err <0 )
bcm_phy_read_exp() could fail. So you should keep the test. Also, the caller of this function does look at the return value.
Quoted 49 lines
drivers/net/phy/broadcom.c +40
-0+/** +* bcm5481x_read_abilities - read PHY abilities from LRESR or Clause 22 +* (BMSR) registers, based on whether the PHY is in BroadR-Reach or IEEE mode +* @phydev: target phy_device struct +* +* Description: Reads the PHY's abilities and populates +* phydev->supported accordingly. The register to read the abilities from is +* determined by current brr mode setting of the PHY. +* Note that the LRE and IEEE sets of abilities are disjunct. +* +* Returns: 0 on success, < 0 on failure +*/ +static int bcm5481x_read_abilities (struct phy_device *phydev) +{ +int i, val, err; +u8 brr_mode; + +for (i =0 ; i <ARRAY_SIZE (bcm54811_linkmodes); i++) +linkmode_clear_bit (bcm54811_linkmodes[i], phydev->supported); + + err =bcm5481x_get_brrmode (phydev, &brr_mode); +static int bcm5481x_set_brrmode (struct phy_device *phydev,bool on) +{ +int reg; +int err; +u16 val; + + reg =bcm_phy_read_exp (phydev,BCM54810_EXP_BROADREACH_LRE_MISC_CTL ); + +if (on) + reg |=BCM54810_EXP_BROADREACH_LRE_MISC_CTL_EN ; +else + reg &= ~BCM54810_EXP_BROADREACH_LRE_MISC_CTL_EN ; + +static int bcm54811_config_init (struct phy_device *phydev) +{ +struct device_node *np = phydev->mdio.dev.of_node; +bool brr = false; +int err, reg; + err =bcm54xx_config_init (phydev);/* Enable CLK125 MUX on LED4 if ref clock is enabled. */ @@ -576,29 +687,80 @@ static int bcm54811_config_init(struct phy_device *phydev)return err; }
drivers/net/phy/broadcom.c static int bcm54811_config_init(struct phy_device *phydev) · line 698
Quoted 10 lines
drivers/net/phy/broadcom.c +8
-1-return err; +/* Configure BroadR-Reach function. */ + brr =of_property_read_bool (np,"brr-mode" ); + +/* With BCM54811, BroadR-Reach implies no autoneg */ +if (brr) + phydev->autoneg =0 ; + +return bcm5481x_set_brrmode (phydev, brr); }
The ordering seems a bit strange here.
phy_probe() will call phydrv->get_features. At this point, the PHY is in whatever mode it resets to, or maybe what it is strapped to. phydev->supported could thus be set to standard IEEE modes, despite the board design is actually for BroadR-Reach.
Sometime later, when the MAC is connected to the PHY config_init() is called. At that point, you poke around in DT and find how the PHY is connected to the cable. At that point, you set the PHY mode, and change phydev->supported to reflect reality.
I really think that reading DT should be done much earlier, maybe in the driver probe function, or maybe get_features. get_features should always return the correct values from the board.
drivers/net/phy/broadcom.c static int bcm54811_config_init(struct phy_device *phydev) · line 724
Quoted 6 lines
drivers/net/phy/broadcom.c +6
-0+static int bcm5481_config_aneg (struct phy_device *phydev) +{ +u8 brr_mode; +int ret; + + ret =bcm5481x_get_brrmode (phydev, &brr_mode);
Rather than read it from the hardware every single time, could you store the DT value in bcm54xx_phy_priv ?
drivers/net/phy/broadcom.c static void bcm54xx_link_change_notify(struct phy_device *phydev) · line 1265
Quoted 2 lines
drivers/net/phy/broadcom.c +2
-0+/* Read LDS Link Partner Ability in BroadR-Reach mode */ +static int bcm_read_lpa (struct phy_device *phydev)
This function seems to be missing an lds or lre prefix.
drivers/net/phy/broadcom.c static void bcm54xx_link_change_notify(struct phy_device *phydev) · line 1303
Quoted 1 line
drivers/net/phy/broadcom.c +1
-0+static int bcm_read_status_fixed (struct phy_device *phydev)
and here. Please make sure the naming is consistent. Anything which only accesses lre or lds registers should make that clear in its name.
Quoted 40 lines
drivers/net/phy/broadcom.c +40
-0+static int bcm54811_read_status (struct phy_device *phydev) +{ +u8 brr_mode; +int err; + + err =bcm5481x_get_brrmode (phydev, &brr_mode); + +if (err) +return err; + +if (brr_mode) { +/* Get the status in BroadRReach mode just like +* genphy_read_status does in normal mode +*/ + +int err, old_link = phydev->link; + +/* Update the link, but return if there was an error */ + + err =lre_update_link (phydev); +if (err) +return err; + +/* why bother the PHY if nothing can have changed */ +if (phydev->autoneg == +AUTONEG_ENABLE && old_link && phydev->link) +return 0 ; + + phydev->speed =SPEED_UNKNOWN ; + phydev->duplex =DUPLEX_UNKNOWN ; + phydev->pause =0 ; + phydev->asym_pause =0 ; + + err =bcm_read_master_slave (phydev); +if (err <0 ) +return err; + +/* Read LDS Link Partner Ability */ + err =bcm_read_lpa (phydev); +if (err <0 )
drivers/net/phy/broadcom.c static void bcm54xx_link_change_notify(struct phy_device *phydev) · line 1424
Quoted 10 lines
drivers/net/phy/broadcom.c +10
-0+return err; + +if (phydev->autoneg == +AUTONEG_ENABLE && phydev->autoneg_complete) { +phy_resolve_aneg_linkmode (phydev); + }else if (phydev->autoneg ==AUTONEG_DISABLE ) { + err =bcm_read_status_fixed (phydev); +if (err <0 ) +return err; + }
This would probably look better if you pulled this code out into a helper bcm54811_lre_read_status().
Andrew
---
pw-bot: cr
Re: [PATCH v11 4/4] net: phy: bcm-phy-lib: Implement BroadR-Reach link modes
Quoted 5 lines · Andrew Lunn
Quoted 5 lines
drivers/net/phy/broadcom.c +2
-1+static int bcm5481x_get_brrmode (struct phy_device *phydev,u8 *data) { -int err, reg; +int reg;
Quoted 8 lines
drivers/net/phy/broadcom.c static int bcm54810_write_mmd(struct phy_device *phydev, int devnum, u16 regnum, · line 565
Quoted 6 lines
drivers/net/phy/broadcom.c +0
-5-/* Disable BroadR-Reach function. */ reg =bcm_phy_read_exp (phydev,BCM54810_EXP_BROADREACH_LRE_MISC_CTL ); - reg &= ~BCM54810_EXP_BROADREACH_LRE_MISC_CTL_EN ; - err =bcm_phy_write_exp (phydev,BCM54810_EXP_BROADREACH_LRE_MISC_CTL , - reg); -if (err <0 )
bcm_phy_read_exp()could fail. So you should keep the test. Also, the caller of this function does look at the return value.
True - it can at least return -EOPNOTSUPP from __mdiobus_read() Trying to handle it.
This neglect can be found elsewhere such as bcm-phy-ptp.c and eg. bcm54xx_config_init()
function. I feel that at least the latest one should be fixed but it would be unrelated to bcm54811,
so leaving it as-is for now.
Quoted 65 lines
Quoted 48 lines
drivers/net/phy/broadcom.c +40
-0+/** +* bcm5481x_read_abilities - read PHY abilities from LRESR or Clause 22 +* (BMSR) registers, based on whether the PHY is in BroadR-Reach or IEEE mode +* @phydev: target phy_device struct +* +* Description: Reads the PHY's abilities and populates +* phydev->supported accordingly. The register to read the abilities from is +* determined by current brr mode setting of the PHY. +* Note that the LRE and IEEE sets of abilities are disjunct. +* +* Returns: 0 on success, < 0 on failure +*/ +static int bcm5481x_read_abilities (struct phy_device *phydev) +{ +int i, val, err; +u8 brr_mode; + +for (i =0 ; i <ARRAY_SIZE (bcm54811_linkmodes); i++) +linkmode_clear_bit (bcm54811_linkmodes[i], phydev->supported); + + err =bcm5481x_get_brrmode (phydev, &brr_mode); +static int bcm5481x_set_brrmode (struct phy_device *phydev,bool on) +{ +int reg; +int err; +u16 val; + + reg =bcm_phy_read_exp (phydev,BCM54810_EXP_BROADREACH_LRE_MISC_CTL ); + +if (on) + reg |=BCM54810_EXP_BROADREACH_LRE_MISC_CTL_EN ; +else + reg &= ~BCM54810_EXP_BROADREACH_LRE_MISC_CTL_EN ; + +static int bcm54811_config_init (struct phy_device *phydev) +{ +struct device_node *np = phydev->mdio.dev.of_node; +bool brr = false; +int err, reg; + err =bcm54xx_config_init (phydev);/* Enable CLK125 MUX on LED4 if ref clock is enabled. */ @@ -576,29 +687,80 @@ static int bcm54811_config_init(struct phy_device *phydev)return err; }drivers/net/phy/broadcom.c static int bcm54811_config_init(struct phy_device *phydev) · line 698
Quoted 10 lines
drivers/net/phy/broadcom.c +8
-1-return err; +/* Configure BroadR-Reach function. */ + brr =of_property_read_bool (np,"brr-mode" ); + +/* With BCM54811, BroadR-Reach implies no autoneg */ +if (brr) + phydev->autoneg =0 ; + +return bcm5481x_set_brrmode (phydev, brr); }The ordering seems a bit strange here.
phy_probe()will callphydrv->get_features. At this point, the PHY is in whatever mode it resets to, or maybe what it is strapped to.phydev->supportedcould thus be set to standard IEEE modes, despite the board design is actually for BroadR-Reach.
Quoted 8 lines
Sometime later, when the MAC is connected to the PHY
config_init()is called. At that point, you poke around in DT and find how the PHY is connected to the cable. At that point, you set the PHY mode, and changephydev->supportedto reflect reality.I really think that reading DT should be done much earlier, maybe in the driver probe function, or maybe
get_features.get_featuresshould always return the correct values from the board.
Also true. This is a remnant of original approach using phy-tunable rather than dt to select the mode.
I do not expect a hot swappable design to be possible to appear, so fixing the logic as suggested.
Quoted 9 lines
drivers/net/phy/broadcom.c static int bcm54811_config_init(struct phy_device *phydev) · line 724
Quoted 7 lines
drivers/net/phy/broadcom.c +6
-0+static int bcm5481_config_aneg (struct phy_device *phydev) +{ +u8 brr_mode; +int ret; + + ret =bcm5481x_get_brrmode (phydev, &brr_mode);Rather than read it from the hardware every single time, could you store the DT value in
bcm54xx_phy_priv?
Done. Now we rely on the DT setting and never read the PHY state. It is vulnerable to external manipulation
of MDIO registers and PHY reset as both hardware and software (bit 15 of register 0 in both
IEEE and LRE modes) reset switch to IEEE mode.
Quoted 8 lines
drivers/net/phy/broadcom.c static void bcm54xx_link_change_notify(struct phy_device *phydev) · line 1265
Quoted 3 lines
drivers/net/phy/broadcom.c +2
-0+/* Read LDS Link Partner Ability in BroadR-Reach mode */ +static int bcm_read_lpa (struct phy_device *phydev)This function seems to be missing an lds or lre prefix.
drivers/net/phy/broadcom.c static void bcm54xx_link_change_notify(struct phy_device *phydev) · line 1303
Quoted 1 line
drivers/net/phy/broadcom.c +1
-0+static int bcm_read_status_fixed (struct phy_device *phydev)and here. Please make sure the naming is consistent. Anything which only accesses lre or lds registers should make that clear in its name.
I feel this requires renaming stuff like bcm_read_status_fixed to lre_read_status_fixed etc. in every location
only handling LRE stuff, same logic already applied to eg. lre_update_link.
Quoted 45 lines
Quoted 45 lines
drivers/net/phy/broadcom.c +44
-0+static int bcm54811_read_status (struct phy_device *phydev) +{ +u8 brr_mode; +int err; + + err =bcm5481x_get_brrmode (phydev, &brr_mode); + +if (err) +return err; + +if (brr_mode) { +/* Get the status in BroadRReach mode just like +* genphy_read_status does in normal mode +*/ + +int err, old_link = phydev->link; + +/* Update the link, but return if there was an error */ + + err =lre_update_link (phydev); +if (err) +return err; + +/* why bother the PHY if nothing can have changed */ +if (phydev->autoneg == +AUTONEG_ENABLE && old_link && phydev->link) +return 0 ; + + phydev->speed =SPEED_UNKNOWN ; + phydev->duplex =DUPLEX_UNKNOWN ; + phydev->pause =0 ; + phydev->asym_pause =0 ; + + err =bcm_read_master_slave (phydev); +if (err <0 ) +return err; + +/* Read LDS Link Partner Ability */ + err =bcm_read_lpa (phydev); +if (err <0 ) +return err; + +if (phydev->autoneg == +AUTONEG_ENABLE && phydev->autoneg_complete) {
Quoted 8 lines
drivers/net/phy/broadcom.c static void bcm54xx_link_change_notify(struct phy_device *phydev) · line 1424
Quoted 6 lines
drivers/net/phy/broadcom.c +6
-0+phy_resolve_aneg_linkmode (phydev); + }else if (phydev->autoneg ==AUTONEG_DISABLE ) { + err =bcm_read_status_fixed (phydev); +if (err <0 ) +return err; + }This would probably look better if you pulled this code out into a helper
bcm54811_lre_read_status().
done
I've of course verified again that it works on the target device but unfortunately, I have no possibility
to test it on anything using BCM54811 in IEEE mode and with BCM54810 which might be interesting for
someone using that PHY.
Kamil
Quoted 5 lines
Andrew
---
pw-bot: cr
Andrew Lunn
maintainerRe: [PATCH v11 4/4] net: phy: bcm-phy-lib: Implement BroadR-Reach link modes
Quoted 17 lines · On Fri, Jul 12, 2024 at 05:10:48PM +0200, Kamil Horák (2N) wrote:
Quoted 4 lines · Andrew Lunn
Quoted 4 lines
drivers/net/phy/broadcom.c +2
-1+static int bcm5481x_get_brrmode (struct phy_device *phydev,u8 *data) { -int err, reg; +int reg;Quoted 8 lines
drivers/net/phy/broadcom.c static int bcm54810_write_mmd(struct phy_device *phydev, int devnum, u16 regnum, · line 565
Quoted 6 lines
drivers/net/phy/broadcom.c +0
-5-/* Disable BroadR-Reach function. */ reg =bcm_phy_read_exp (phydev,BCM54810_EXP_BROADREACH_LRE_MISC_CTL ); - reg &= ~BCM54810_EXP_BROADREACH_LRE_MISC_CTL_EN ; - err =bcm_phy_write_exp (phydev,BCM54810_EXP_BROADREACH_LRE_MISC_CTL , - reg); -if (err <0 )
bcm_phy_read_exp()could fail. So you should keep the test. Also, the caller of this function does look at the return value.True - it can at least return
-EOPNOTSUPPfrom__mdiobus_read()Trying to handle it.
Quoted 7 lines
This neglect can be found elsewhere such as bcm-phy-ptp.c and eg.
bcm54xx_config_init()function. I feel that at least the latest one should be fixed but it would be unrelated to bcm54811,
so leaving it as-is for now.
In general PHY drivers are a bit hit and miss with checking error codes. If the first access works, it is very likely all further accesses will work. If they fail, the hardware is probably dead and there is little you can do about it other than report the error. So i would say probe, suspend and resume should always check the error codes, since that is where clock problems are likely to be. But after that it is good practice to check error codes, but a driver is unlikely to be NACKed because of missing checks.
Quoted 7 lines
Done. Now we rely on the DT setting and never read the PHY state. It is vulnerable to external manipulation
of MDIO registers and PHY reset as both hardware and software (bit 15 of register 0 in both
IEEE and LRE modes) reset switch to IEEE mode.
I don't think this is any worse. With the old code you would of silently swapped to standard IEEE modes, which cannot work. Now you continue programming BRR registers, which just get ignored because it is no longer in that mode.
But if somebody performed some sort of external manipulation, all bets are off anyway.
Andrew
Russell King (Oracle)
reviewerRe: [PATCH v11 1/4] net: phy: bcm54811: New link mode for BroadR-Reach
In reply to Kamil Horák (2N)Quoted 9 lines · On Mon, Jul 08, 2024 at 12:27:13PM +0200, Kamil Horák (2N) wrote:
Introduce a new link mode necessary for 10 MBit single-pair connection in BroadR-Reach mode on bcm5481x PHY by Broadcom. This new link mode, 10baseT1BRR, is known as 1BR10 in the Broadcom terminology. Another link mode to be used is 1BR100 and it is already present as 100baseT1, because Broadcom's 1BR100 became 100baseT1 (IEEE 802.3bw).
Signed-off-by Kamil Horák (2N) <[email protected]>Reviewed-by Florian Fainelli <[email protected]>
Does phylink also need to be updated? E.g. phylink_caps_to_linkmodes()
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!