net: mtk_eth_soc: improve PCS implementation
Subsystems (5)
Russell King (Oracle)
maintainercover net: mtk_eth_soc: improve PCS implementation
Hi,
As a result of invesigations from Frank Wunderlich, we know a lot more about the Mediatek "SGMII" PCS block, and can implement the PCS support correctly. This series achieves that, and Frank has tested the final result and reports that it works for him. The series could do with further testing by others, but I suspect that is unlikely to happen until it is merged based on past performances with this driver.
Briefly, the patches in order:
1. Add a new helper to get the link timer duration in nanoseconds
2. Add definitions for the newly discovered registers and updates to bit definitions, including bitmasks for the BMCR, BMSR and two advertisement registers.
3. Remove unnecessary/unused error handling (functions always returning zero.)
4. Adding the missing pcs_get_state() implementation.
5. Converting the code to use regmap_update_bits() rather than open-coding read-modify-write sequences.
6. Adding out-of-band speed and duplex forcing for all non-inband modes not just the 802.3z link modes the code currently does.
7. Moving the release of the PHY power down to the main pcs_config() function.
8. Moving the interface speed selection to the main pcs_config() function.
9. Adding advertisement programming.
10. Adding correct link timer programming using the new helper in the first patch.
11. Adding support for 802.3z negotiation.
There is one remaining issue - when configuring the PCS for in-band, for some reason the AN restart bit is always set. This should not be necessary, but requires further investigation with the hardware to find out whether it is really necessary. I suspect this was a work around for a previous poor implementation.
drivers/net/ethernet/mediatek/mtk_eth_soc.h | 13 ++- drivers/net/ethernet/mediatek/mtk_sgmii.c | 174 ++++++++++++++++------------ include/linux/phylink.h | 24 ++++ 3 files changed, 134 insertions(+), 77 deletions(-)
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
PATCH 1/11 net: phylink: add phylink_get_link_timer_ns() helper
Add a helper to convert the PHY interface mode to the required link timer setting as stated by the appropriate standard. Inappropriate interface modes return an error.
--- include/linux/phylink.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
include/linux/phylink.h +24 -0
@@ -616,6 +616,30 @@ int phylink_speed_up(struct phylink *pl);void phylink_set_port_modes (unsigned long *bits); +/** +* phylink_get_link_timer_ns - return the PCS link timer value +* @interface: link &typedef phy_interface_t mode +* +* Return the PCS link timer setting in nanoseconds for the PHY @interface +* mode, or -EINVAL if not appropriate. +*/ +static inline int phylink_get_link_timer_ns (phy_interface_t interface) +{ +switch (interface) { +case PHY_INTERFACE_MODE_SGMII : +case PHY_INTERFACE_MODE_QSGMII : +case PHY_INTERFACE_MODE_USXGMII : +return 1600000 ; + +case PHY_INTERFACE_MODE_1000BASEX : +case PHY_INTERFACE_MODE_2500BASEX : +return 10000000 ; + +default : +return -EINVAL ; + } +} +void phylink_mii_c22_pcs_decode_state (struct phylink_link_state *state,u16 bmsr,u16 lpa); void phylink_mii_c22_pcs_get_state(struct mdio_device *pcs,
Signature · 1 line
2.30.2
PATCH 2/11 net: mtk_eth_soc: add definitions for PCS
In reply to Russell King (Oracle)As a result of help from Frank Wunderlich to investigate and test, we know a bit more about the PCS on the Mediatek platforms. Update the definitions from this investigation.
This PCS appears similar, but not identical to the Lynx PCS.
Although not included in this patch, but for future reference, the PHY ID registers at offset 4 read as 0x4d544950 'MTIP'.
--- drivers/net/ethernet/mediatek/mtk_eth_soc.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/net/ethernet/mediatek/mtk_eth_soc.h +10 -3
@@ -466,8 +466,10 @@#define ETHSYS_DMA_AG_MAP_PPE BIT(2)/* SGMII subsystem config registers */ -/* Register to auto-negotiation restart */ +/* BMCR (low 16) BMSR (high 16) */ #define SGMSYS_PCS_CONTROL_1 0x0 +#define SGMII_BMCR GENMASK(15, 0) +#define SGMII_BMSR GENMASK(31, 16)#define SGMII_AN_RESTART BIT(9)#define SGMII_ISOLATE BIT(10)#define SGMII_AN_ENABLE BIT(12)
@@ -477,13 +479,18 @@#define SGMII_PCS_FAULT BIT(23)#define SGMII_AN_EXPANSION_CLR BIT(30) +#define SGMSYS_PCS_ADVERTISE 0x8 +#define SGMII_ADVERTISE GENMASK(15, 0) +#define SGMII_LPA GENMASK(31, 16) +/* Register to programmable link timer, the unit in 2 * 8ns */ #define SGMSYS_PCS_LINK_TIMER 0x18 -#define SGMII_LINK_TIMER_DEFAULT (0x186a0 & GENMASK(19, 0)) +#define SGMII_LINK_TIMER_MASK GENMASK(19, 0) +#define SGMII_LINK_TIMER_DEFAULT (0x186a0 & SGMII_LINK_TIMER_MASK)/* Register to control remote fault */ #define SGMSYS_SGMII_MODE 0x20 -#define SGMII_IF_MODE_BIT0 BIT(0) +#define SGMII_IF_MODE_SGMII BIT(0)#define SGMII_SPEED_DUPLEX_AN BIT(1)#define SGMII_SPEED_MASK GENMASK(3, 2)#define SGMII_SPEED_10 FIELD_PREP(SGMII_SPEED_MASK, 0)
Signature · 1 line
2.30.2
PATCH 3/11 net: mtk_eth_soc: eliminate unnecessary error handling
In reply to Russell King (Oracle)The functions called by the pcs_config() method always return zero, so there is no point trying to handle an error from these functions. Make these functions void, eliminate the "err" variable and simply return zero from the pcs_config() function itself.
--- drivers/net/ethernet/mediatek/mtk_sgmii.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-)
drivers/net/ethernet/mediatek/mtk_sgmii.c +6 -12
@@ -20,7 +20,7 @@ static struct mtk_pcs *pcs_to_mtk_pcs(struct phylink_pcs *pcs) }/* For SGMII interface mode */ -static int mtk_pcs_setup_mode_an (struct mtk_pcs *mpcs) +static void mtk_pcs_setup_mode_an (struct mtk_pcs *mpcs) {unsigned int val;
@@ -39,16 +39,13 @@ static int mtk_pcs_setup_mode_an(struct mtk_pcs *mpcs)regmap_read (mpcs->regmap,SGMSYS_QPHY_PWR_STATE_CTRL , &val); val &= ~SGMII_PHYA_PWD ;regmap_write (mpcs->regmap,SGMSYS_QPHY_PWR_STATE_CTRL , val); - -return 0 ; - }/* For 1000BASE-X and 2500BASE-X interface modes, which operate at a * fixed speed. */ -static int mtk_pcs_setup_mode_force (struct mtk_pcs *mpcs, -phy_interface_t interface) +static void mtk_pcs_setup_mode_force (struct mtk_pcs *mpcs, +phy_interface_t interface) {unsigned int val;
@@ -73,8 +70,6 @@ static int mtk_pcs_setup_mode_force(struct mtk_pcs *mpcs,regmap_read (mpcs->regmap,SGMSYS_QPHY_PWR_STATE_CTRL , &val); val &= ~SGMII_PHYA_PWD ;regmap_write (mpcs->regmap,SGMSYS_QPHY_PWR_STATE_CTRL , val); - -return 0 ; } static int mtk_pcs_config(struct phylink_pcs *pcs, unsigned int mode,
@@ -83,15 +78,14 @@ static int mtk_pcs_config(struct phylink_pcs *pcs, unsigned int mode, bool permit_pause_to_mac) {struct mtk_pcs *mpcs =pcs_to_mtk_pcs (pcs); -int err =0 ;/* Setup SGMIISYS with the determined property */ if (interface !=PHY_INTERFACE_MODE_SGMII ) - err =mtk_pcs_setup_mode_force (mpcs, interface); +mtk_pcs_setup_mode_force (mpcs, interface);else if (phylink_autoneg_inband (mode)) - err =mtk_pcs_setup_mode_an (mpcs); +mtk_pcs_setup_mode_an (mpcs); -return err; +return 0 ; }static void mtk_pcs_restart_an (struct phylink_pcs *pcs)
Signature · 1 line
2.30.2
PATCH 4/11 net: mtk_eth_soc: add pcs_get_state() implementation
In reply to Russell King (Oracle)Add a pcs_get_state() implementation which uses the advertisements to compute the resulting link modes, and BMSR contents to determine negotiation and link status.
--- drivers/net/ethernet/mediatek/mtk_sgmii.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
drivers/net/ethernet/mediatek/mtk_sgmii.c +15 -0
@@ -19,6 +19,20 @@ static struct mtk_pcs *pcs_to_mtk_pcs(struct phylink_pcs *pcs) return container_of(pcs, struct mtk_pcs, pcs); } +static void mtk_pcs_get_state (struct phylink_pcs *pcs, +struct phylink_link_state *state) +{ +struct mtk_pcs *mpcs =pcs_to_mtk_pcs (pcs); +unsigned int bm, adv; + +/* Read the BMSR and LPA */ +regmap_read (mpcs->regmap,SGMSYS_PCS_CONTROL_1 , &bm); +regmap_read (mpcs->regmap,SGMSYS_PCS_ADVERTISE , &adv); + +phylink_mii_c22_pcs_decode_state (state,FIELD_GET (SGMII_BMSR , bm), +FIELD_GET (SGMII_LPA , adv)); +} +/* For SGMII interface mode */ static void mtk_pcs_setup_mode_an (struct mtk_pcs *mpcs) {
@@ -117,6 +131,7 @@ static void mtk_pcs_link_up(struct phylink_pcs *pcs, unsigned int mode, }static const struct phylink_pcs_ops mtk_pcs_ops = { + .pcs_get_state = mtk_pcs_get_state, .pcs_config = mtk_pcs_config, .pcs_an_restart = mtk_pcs_restart_an, .pcs_link_up = mtk_pcs_link_up,
Signature · 1 line
2.30.2
PATCH 5/11 net: mtk_eth_soc: convert mtk_sgmii to use regmap_update_bits()
In reply to Russell King (Oracle)mtk_sgmii does a lot of read-modify-write operations, for which there is a specific regmap function. Use this function instead of open-coding the operations.
--- drivers/net/ethernet/mediatek/mtk_sgmii.c | 61 ++++++++++------------- 1 file changed, 26 insertions(+), 35 deletions(-)
drivers/net/ethernet/mediatek/mtk_sgmii.c +26 -35
@@ -36,23 +36,18 @@ static void mtk_pcs_get_state(struct phylink_pcs *pcs,/* For SGMII interface mode */ static void mtk_pcs_setup_mode_an (struct mtk_pcs *mpcs) { -unsigned int val; -/* Setup the link timer and QPHY power up inside SGMIISYS */ regmap_write (mpcs->regmap,SGMSYS_PCS_LINK_TIMER ,SGMII_LINK_TIMER_DEFAULT ); -regmap_read (mpcs->regmap,SGMSYS_SGMII_MODE , &val); - val |=SGMII_REMOTE_FAULT_DIS ; -regmap_write (mpcs->regmap,SGMSYS_SGMII_MODE , val); +regmap_update_bits (mpcs->regmap,SGMSYS_SGMII_MODE , +SGMII_REMOTE_FAULT_DIS ,SGMII_REMOTE_FAULT_DIS ); -regmap_read (mpcs->regmap,SGMSYS_PCS_CONTROL_1 , &val); - val |=SGMII_AN_RESTART ; -regmap_write (mpcs->regmap,SGMSYS_PCS_CONTROL_1 , val); +regmap_update_bits (mpcs->regmap,SGMSYS_PCS_CONTROL_1 , +SGMII_AN_RESTART ,SGMII_AN_RESTART ); -regmap_read (mpcs->regmap,SGMSYS_QPHY_PWR_STATE_CTRL , &val); - val &= ~SGMII_PHYA_PWD ; -regmap_write (mpcs->regmap,SGMSYS_QPHY_PWR_STATE_CTRL , val); +regmap_update_bits (mpcs->regmap,SGMSYS_QPHY_PWR_STATE_CTRL , +SGMII_PHYA_PWD ,0 ); }/* For 1000BASE-X and 2500BASE-X interface modes, which operate at a
@@ -61,29 +56,26 @@ static void mtk_pcs_setup_mode_an(struct mtk_pcs *mpcs)static void mtk_pcs_setup_mode_force (struct mtk_pcs *mpcs,phy_interface_t interface) { -unsigned int val; +unsigned int rgc3; -regmap_read (mpcs->regmap, mpcs->ana_rgc3, &val); - val &= ~RG_PHY_SPEED_MASK ;if (interface ==PHY_INTERFACE_MODE_2500BASEX ) - val |=RG_PHY_SPEED_3_125G ; -regmap_write (mpcs->regmap, mpcs->ana_rgc3, val); + rgc3 =RG_PHY_SPEED_3_125G ; + +regmap_update_bits (mpcs->regmap, mpcs->ana_rgc3, +RG_PHY_SPEED_3_125G , rgc3);/* Disable SGMII AN */ -regmap_read (mpcs->regmap,SGMSYS_PCS_CONTROL_1 , &val); - val &= ~SGMII_AN_ENABLE ; -regmap_write (mpcs->regmap,SGMSYS_PCS_CONTROL_1 , val); +regmap_update_bits (mpcs->regmap,SGMSYS_PCS_CONTROL_1 , +SGMII_AN_ENABLE ,0 );/* Set the speed etc but leave the duplex unchanged */ -regmap_read (mpcs->regmap,SGMSYS_SGMII_MODE , &val); - val &=SGMII_DUPLEX_FULL | ~SGMII_IF_MODE_MASK ; - val |=SGMII_SPEED_1000 ; -regmap_write (mpcs->regmap,SGMSYS_SGMII_MODE , val); +regmap_update_bits (mpcs->regmap,SGMSYS_SGMII_MODE , +SGMII_IF_MODE_MASK & ~SGMII_DUPLEX_FULL , +SGMII_SPEED_1000 );/* Release PHYA power down state */ -regmap_read (mpcs->regmap,SGMSYS_QPHY_PWR_STATE_CTRL , &val); - val &= ~SGMII_PHYA_PWD ; -regmap_write (mpcs->regmap,SGMSYS_QPHY_PWR_STATE_CTRL , val); +regmap_update_bits (mpcs->regmap,SGMSYS_QPHY_PWR_STATE_CTRL , +SGMII_PHYA_PWD ,0 ); } static int mtk_pcs_config(struct phylink_pcs *pcs, unsigned int mode,
@@ -105,29 +97,28 @@ static int mtk_pcs_config(struct phylink_pcs *pcs, unsigned int mode,static void mtk_pcs_restart_an (struct phylink_pcs *pcs) {struct mtk_pcs *mpcs =pcs_to_mtk_pcs (pcs); -unsigned int val; -regmap_read (mpcs->regmap,SGMSYS_PCS_CONTROL_1 , &val); - val |=SGMII_AN_RESTART ; -regmap_write (mpcs->regmap,SGMSYS_PCS_CONTROL_1 , val); +regmap_update_bits (mpcs->regmap,SGMSYS_PCS_CONTROL_1 , +SGMII_AN_RESTART ,SGMII_AN_RESTART ); }static void mtk_pcs_link_up (struct phylink_pcs *pcs,unsigned int mode,phy_interface_t interface,int speed,int duplex) {struct mtk_pcs *mpcs =pcs_to_mtk_pcs (pcs); -unsigned int val; +unsigned int sgm_mode;if (!phy_interface_mode_is_8023z (interface))return ;/* SGMII force duplex setting */ -regmap_read (mpcs->regmap,SGMSYS_SGMII_MODE , &val); - val &= ~SGMII_DUPLEX_FULL ;if (duplex ==DUPLEX_FULL ) - val |=SGMII_DUPLEX_FULL ; + sgm_mode =SGMII_DUPLEX_FULL ; +else + sgm_mode =0 ; -regmap_write (mpcs->regmap,SGMSYS_SGMII_MODE , val); +regmap_update_bits (mpcs->regmap,SGMSYS_SGMII_MODE , +SGMII_DUPLEX_FULL , sgm_mode); }static const struct phylink_pcs_ops mtk_pcs_ops = {
Signature · 1 line
2.30.2
PATCH 6/11 net: mtk_eth_soc: add out of band forcing of speed and duplex in pcs_link_up
In reply to Russell King (Oracle)Add support for forcing the link speed and duplex setting in the pcs_link_up() method for out of band modes, which will be useful when we finish converting the pcs_config() method. Until then, we still have to force duplex for 802.3z modes to work correctly.
--- drivers/net/ethernet/mediatek/mtk_sgmii.c | 28 ++++++++++++++--------- 1 file changed, 17 insertions(+), 11 deletions(-)
drivers/net/ethernet/mediatek/mtk_sgmii.c +17 -11
@@ -108,17 +108,23 @@ static void mtk_pcs_link_up(struct phylink_pcs *pcs, unsigned int mode,struct mtk_pcs *mpcs =pcs_to_mtk_pcs (pcs);unsigned int sgm_mode; -if (!phy_interface_mode_is_8023z (interface)) -return ; - -/* SGMII force duplex setting */ -if (duplex ==DUPLEX_FULL ) - sgm_mode =SGMII_DUPLEX_FULL ; -else - sgm_mode =0 ; - -regmap_update_bits (mpcs->regmap,SGMSYS_SGMII_MODE , -SGMII_DUPLEX_FULL , sgm_mode); +if (!phylink_autoneg_inband (mode) || +phy_interface_mode_is_8023z (interface)) { +/* Force the speed and duplex setting */ +if (speed ==SPEED_10 ) + sgm_mode =SGMII_SPEED_10 ; +else if (speed ==SPEED_100 ) + sgm_mode =SGMII_SPEED_100 ; +else + sgm_mode =SGMII_SPEED_1000 ; + +if (duplex ==DUPLEX_FULL ) + sgm_mode |=SGMII_DUPLEX_FULL ; + +regmap_update_bits (mpcs->regmap,SGMSYS_SGMII_MODE , +SGMII_DUPLEX_FULL |SGMII_SPEED_MASK , + sgm_mode); + } }static const struct phylink_pcs_ops mtk_pcs_ops = {
Signature · 1 line
2.30.2
PATCH 7/11 net: mtk_eth_soc: move PHY power up
In reply to Russell King (Oracle)The PHY power up is common to both configuration paths, so move it into the parent function. We need to do this for all serdes modes.
--- drivers/net/ethernet/mediatek/mtk_sgmii.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/net/ethernet/mediatek/mtk_sgmii.c +4 -7
@@ -45,9 +45,6 @@ static void mtk_pcs_setup_mode_an(struct mtk_pcs *mpcs)regmap_update_bits (mpcs->regmap,SGMSYS_PCS_CONTROL_1 ,SGMII_AN_RESTART ,SGMII_AN_RESTART ); - -regmap_update_bits (mpcs->regmap,SGMSYS_QPHY_PWR_STATE_CTRL , -SGMII_PHYA_PWD ,0 ); }/* For 1000BASE-X and 2500BASE-X interface modes, which operate at a
@@ -72,10 +69,6 @@ static void mtk_pcs_setup_mode_force(struct mtk_pcs *mpcs,regmap_update_bits (mpcs->regmap,SGMSYS_SGMII_MODE ,SGMII_IF_MODE_MASK & ~SGMII_DUPLEX_FULL ,SGMII_SPEED_1000 ); - -/* Release PHYA power down state */ -regmap_update_bits (mpcs->regmap,SGMSYS_QPHY_PWR_STATE_CTRL , -SGMII_PHYA_PWD ,0 ); } static int mtk_pcs_config(struct phylink_pcs *pcs, unsigned int mode,
@@ -91,6 +84,10 @@ static int mtk_pcs_config(struct phylink_pcs *pcs, unsigned int mode,else if (phylink_autoneg_inband (mode))mtk_pcs_setup_mode_an (mpcs); +/* Release PHYA power down state */ +regmap_update_bits (mpcs->regmap,SGMSYS_QPHY_PWR_STATE_CTRL , +SGMII_PHYA_PWD ,0 ); +return 0 ; }
Signature · 1 line
2.30.2
PATCH 8/11 net: mtk_eth_soc: move interface speed selection
In reply to Russell King (Oracle)Move the selection of the underlying interface speed to the pcs_config function, so we always program the interface speed.
--- drivers/net/ethernet/mediatek/mtk_sgmii.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
drivers/net/ethernet/mediatek/mtk_sgmii.c +10 -8
@@ -53,14 +53,6 @@ static void mtk_pcs_setup_mode_an(struct mtk_pcs *mpcs)static void mtk_pcs_setup_mode_force (struct mtk_pcs *mpcs,phy_interface_t interface) { -unsigned int rgc3; - -if (interface ==PHY_INTERFACE_MODE_2500BASEX ) - rgc3 =RG_PHY_SPEED_3_125G ; - -regmap_update_bits (mpcs->regmap, mpcs->ana_rgc3, -RG_PHY_SPEED_3_125G , rgc3); -/* Disable SGMII AN */ regmap_update_bits (mpcs->regmap,SGMSYS_PCS_CONTROL_1 ,SGMII_AN_ENABLE ,0 );
@@ -77,6 +69,16 @@ static int mtk_pcs_config(struct phylink_pcs *pcs, unsigned int mode, bool permit_pause_to_mac) {struct mtk_pcs *mpcs =pcs_to_mtk_pcs (pcs); +unsigned int rgc3; + +if (interface ==PHY_INTERFACE_MODE_2500BASEX ) + rgc3 =RG_PHY_SPEED_3_125G ; +else + rgc3 =0 ; + +/* Configure the underlying interface speed */ +regmap_update_bits (mpcs->regmap, mpcs->ana_rgc3, +RG_PHY_SPEED_3_125G , rgc3);/* Setup SGMIISYS with the determined property */ if (interface !=PHY_INTERFACE_MODE_SGMII )
Signature · 1 line
2.30.2
PATCH 9/11 net: mtk_eth_soc: add advertisement programming
In reply to Russell King (Oracle)Program the advertisement into the mtk PCS block.
--- drivers/net/ethernet/mediatek/mtk_sgmii.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/net/ethernet/mediatek/mtk_sgmii.c +12 -1
@@ -70,16 +70,27 @@ static int mtk_pcs_config(struct phylink_pcs *pcs, unsigned int mode, {struct mtk_pcs *mpcs =pcs_to_mtk_pcs (pcs);unsigned int rgc3; +int advertise; +bool changed;if (interface ==PHY_INTERFACE_MODE_2500BASEX ) rgc3 =RG_PHY_SPEED_3_125G ;else rgc3 =0 ; + advertise =phylink_mii_c22_pcs_encode_advertisement (interface, + advertising); +if (advertise <0 ) +return advertise; +/* Configure the underlying interface speed */ regmap_update_bits (mpcs->regmap, mpcs->ana_rgc3,RG_PHY_SPEED_3_125G , rgc3); +/* Update the advertisement, noting whether it has changed */ +regmap_update_bits_check (mpcs->regmap,SGMSYS_PCS_ADVERTISE , +SGMII_ADVERTISE , advertise, &changed); +/* Setup SGMIISYS with the determined property */ if (interface !=PHY_INTERFACE_MODE_SGMII )mtk_pcs_setup_mode_force (mpcs, interface);
@@ -90,7 +101,7 @@ static int mtk_pcs_config(struct phylink_pcs *pcs, unsigned int mode,regmap_update_bits (mpcs->regmap,SGMSYS_QPHY_PWR_STATE_CTRL ,SGMII_PHYA_PWD ,0 ); -return 0 ; +return changed; }static void mtk_pcs_restart_an (struct phylink_pcs *pcs)
Signature · 1 line
2.30.2
PATCH 10/11 net: mtk_eth_soc: move and correct link timer programming
In reply to Russell King (Oracle)Program the link timer appropriately for the interface mode being used, using the newly introduced phylink helper that provides the nanosecond link timer interval.
The intervals are 1.6ms for SGMII based protocols and 10ms for 802.3z based protocols.
--- drivers/net/ethernet/mediatek/mtk_sgmii.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/net/ethernet/mediatek/mtk_sgmii.c +8 -5
@@ -36,10 +36,6 @@ static void mtk_pcs_get_state(struct phylink_pcs *pcs,/* For SGMII interface mode */ static void mtk_pcs_setup_mode_an (struct mtk_pcs *mpcs) { -/* Setup the link timer and QPHY power up inside SGMIISYS */ -regmap_write (mpcs->regmap,SGMSYS_PCS_LINK_TIMER , -SGMII_LINK_TIMER_DEFAULT ); -regmap_update_bits (mpcs->regmap,SGMSYS_SGMII_MODE ,SGMII_REMOTE_FAULT_DIS ,SGMII_REMOTE_FAULT_DIS );
@@ -69,8 +65,8 @@ static int mtk_pcs_config(struct phylink_pcs *pcs, unsigned int mode, bool permit_pause_to_mac) {struct mtk_pcs *mpcs =pcs_to_mtk_pcs (pcs); +int advertise, link_timer;unsigned int rgc3; -int advertise;bool changed;if (interface ==PHY_INTERFACE_MODE_2500BASEX )
@@ -83,6 +79,10 @@ static int mtk_pcs_config(struct phylink_pcs *pcs, unsigned int mode,if (advertise <0 )return advertise; + link_timer =phylink_get_link_timer_ns (interface); +if (link_timer <0 ) +return link_timer; +/* Configure the underlying interface speed */ regmap_update_bits (mpcs->regmap, mpcs->ana_rgc3,RG_PHY_SPEED_3_125G , rgc3);
@@ -91,6 +91,9 @@ static int mtk_pcs_config(struct phylink_pcs *pcs, unsigned int mode,regmap_update_bits_check (mpcs->regmap,SGMSYS_PCS_ADVERTISE ,SGMII_ADVERTISE , advertise, &changed); +/* Setup the link timer and QPHY power up inside SGMIISYS */ +regmap_write (mpcs->regmap,SGMSYS_PCS_LINK_TIMER , link_timer /2 /8 ); +/* Setup SGMIISYS with the determined property */ if (interface !=PHY_INTERFACE_MODE_SGMII )mtk_pcs_setup_mode_force (mpcs, interface);
Signature · 1 line
2.30.2
PATCH 11/11 net: mtk_eth_soc: add support for in-band 802.3z negotiation
In reply to Russell King (Oracle)As a result of help from Frank Wunderlich to investigate and test, we now know how to program this PCS for in-band 802.3z negotiation. Add support for this by moving the contents of the two functions into the common mtk_pcs_config() function and adding the register settings for 802.3z negotiation.
--- drivers/net/ethernet/mediatek/mtk_sgmii.c | 77 ++++++++++++----------- 1 file changed, 42 insertions(+), 35 deletions(-)
drivers/net/ethernet/mediatek/mtk_sgmii.c +42 -35
@@ -33,41 +33,15 @@ static void mtk_pcs_get_state(struct phylink_pcs *pcs, FIELD_GET(SGMII_LPA, adv)); } -/* For SGMII interface mode */ -static void mtk_pcs_setup_mode_an (struct mtk_pcs *mpcs) -{ -regmap_update_bits (mpcs->regmap,SGMSYS_SGMII_MODE , -SGMII_REMOTE_FAULT_DIS ,SGMII_REMOTE_FAULT_DIS ); - -regmap_update_bits (mpcs->regmap,SGMSYS_PCS_CONTROL_1 , -SGMII_AN_RESTART ,SGMII_AN_RESTART ); -} - -/* For 1000BASE-X and 2500BASE-X interface modes, which operate at a -* fixed speed. -*/ -static void mtk_pcs_setup_mode_force (struct mtk_pcs *mpcs, -phy_interface_t interface) -{ -/* Disable SGMII AN */ -regmap_update_bits (mpcs->regmap,SGMSYS_PCS_CONTROL_1 , -SGMII_AN_ENABLE ,0 ); - -/* Set the speed etc but leave the duplex unchanged */ -regmap_update_bits (mpcs->regmap,SGMSYS_SGMII_MODE , -SGMII_IF_MODE_MASK & ~SGMII_DUPLEX_FULL , -SGMII_SPEED_1000 ); -} -static int mtk_pcs_config (struct phylink_pcs *pcs,unsigned int mode,phy_interface_t interface,const unsigned long *advertising,bool permit_pause_to_mac) {struct mtk_pcs *mpcs =pcs_to_mtk_pcs (pcs); +unsigned int rgc3, sgm_mode, bmcr;int advertise, link_timer; -unsigned int rgc3; -bool changed; +bool changed, use_an;if (interface ==PHY_INTERFACE_MODE_2500BASEX ) rgc3 =RG_PHY_SPEED_3_125G ;
@@ -83,6 +57,37 @@ static int mtk_pcs_config(struct phylink_pcs *pcs, unsigned int mode,if (link_timer <0 )return link_timer; +/* Clearing IF_MODE_BIT0 switches the PCS to BASE-X mode, and +* we assume that fixes it's speed at bitrate = line rate (in +* other words, 1000Mbps or 2500Mbps). +*/ +if (interface ==PHY_INTERFACE_MODE_SGMII ) { + sgm_mode =SGMII_IF_MODE_SGMII ; +if (phylink_autoneg_inband (mode)) { + sgm_mode |=SGMII_REMOTE_FAULT_DIS | +SGMII_SPEED_DUPLEX_AN ; + use_an = true; + }else { + use_an = false; + } + }else if (phylink_autoneg_inband (mode)) { +/* 1000base-X or 2500base-X autoneg */ + sgm_mode =SGMII_REMOTE_FAULT_DIS ; + use_an =linkmode_test_bit (ETHTOOL_LINK_MODE_Autoneg_BIT, + advertising); + }else { +/* 1000base-X or 2500base-X without autoneg */ + sgm_mode =0 ; + use_an = false; + } + +if (use_an) { +/* FIXME: Do we need to set AN_RESTART here? */ + bmcr =SGMII_AN_RESTART |SGMII_AN_ENABLE ; + }else { + bmcr =0 ; + } +/* Configure the underlying interface speed */ regmap_update_bits (mpcs->regmap, mpcs->ana_rgc3,RG_PHY_SPEED_3_125G , rgc3);
@@ -94,11 +99,14 @@ static int mtk_pcs_config(struct phylink_pcs *pcs, unsigned int mode,/* Setup the link timer and QPHY power up inside SGMIISYS */ regmap_write (mpcs->regmap,SGMSYS_PCS_LINK_TIMER , link_timer /2 /8 ); -/* Setup SGMIISYS with the determined property */ -if (interface !=PHY_INTERFACE_MODE_SGMII ) -mtk_pcs_setup_mode_force (mpcs, interface); -else if (phylink_autoneg_inband (mode)) -mtk_pcs_setup_mode_an (mpcs); +/* Update the sgmsys mode register */ +regmap_update_bits (mpcs->regmap,SGMSYS_SGMII_MODE , +SGMII_REMOTE_FAULT_DIS |SGMII_SPEED_DUPLEX_AN | +SGMII_IF_MODE_SGMII , sgm_mode); + +/* Update the BMCR */ +regmap_update_bits (mpcs->regmap,SGMSYS_PCS_CONTROL_1 , +SGMII_AN_RESTART |SGMII_AN_ENABLE , bmcr);/* Release PHYA power down state */ regmap_update_bits(mpcs->regmap, SGMSYS_QPHY_PWR_STATE_CTRL,
@@ -121,8 +129,7 @@ static void mtk_pcs_link_up(struct phylink_pcs *pcs, unsigned int mode,struct mtk_pcs *mpcs =pcs_to_mtk_pcs (pcs);unsigned int sgm_mode; -if (!phylink_autoneg_inband (mode) || -phy_interface_mode_is_8023z (interface)) { +if (!phylink_autoneg_inband (mode)) {/* Force the speed and duplex setting */ if (speed ==SPEED_10 ) sgm_mode =SGMII_SPEED_10 ;
Signature · 1 line
2.30.2
Russell King (Oracle)
maintainerQuoted 8 lines · Russell King (Oracle)
Hi,
As a result of invesigations from Frank Wunderlich, we know a lot more about the Mediatek "SGMII" PCS block, and can implement the PCS support correctly. This series achieves that, and Frank has tested the final result and reports that it works for him. The series could do with further testing by others, but I suspect that is unlikely to happen until it is merged based on past performances with this driver.
I forgot to say, many thanks to Frank for his efforts and patience in testing various patches to discover how this PCS works.
Quoted 38 lines
Briefly, the patches in order:
1. Add a new helper to get the link timer duration in nanoseconds
2. Add definitions for the newly discovered registers and updates to bit definitions, including bitmasks for the BMCR, BMSR and two advertisement registers.
3. Remove unnecessary/unused error handling (functions always returning zero.)
4. Adding the missingpcs_get_state()implementation.
5. Converting the code to useregmap_update_bits()rather than open-coding read-modify-write sequences.
6. Adding out-of-band speed and duplex forcing for all non-inband modes not just the 802.3z link modes the code currently does.
7. Moving the release of the PHY power down to the mainpcs_config()function.
8. Moving the interface speed selection to the mainpcs_config()function.
9. Adding advertisement programming.
10. Adding correct link timer programming using the new helper in the first patch.
11. Adding support for 802.3z negotiation.There is one remaining issue - when configuring the PCS for in-band, for some reason the AN restart bit is always set. This should not be necessary, but requires further investigation with the hardware to find out whether it is really necessary. I suspect this was a work around for a previous poor implementation.
drivers/net/ethernet/mediatek/mtk_eth_soc.h | 13 ++- drivers/net/ethernet/mediatek/mtk_sgmii.c | 174 ++++++++++++++++------------ include/linux/phylink.h | 24 ++++ 3 files changed, 134 insertions(+), 77 deletions(-)Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
This series was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:
Quoted 10 lines · On Thu, 27 Oct 2022 14:10:11 +0100 you wrote:
Hi,
As a result of invesigations from Frank Wunderlich, we know a lot more about the Mediatek "SGMII" PCS block, and can implement the PCS support correctly. This series achieves that, and Frank has tested the final result and reports that it works for him. The series could do with further testing by others, but I suspect that is unlikely to happen until it is merged based on past performances with this driver.
[...]
Here is the summary with links:
- [net-next,01/11] net: phylink: add phylink_get_link_timer_ns() helper
https://git.kernel.org/netdev/net-next/c/9c5a170677c3 - [net-next,02/11] net: mtk_eth_soc: add definitions for PCS https://git.kernel.org/netdev/net-next/c/b6a709cb51f7 - [net-next,03/11] net: mtk_eth_soc: eliminate unnecessary error handling https://git.kernel.org/netdev/net-next/c/5cf7797526ee - [net-next,04/11] net: mtk_eth_soc: add pcs_get_state() implementation https://git.kernel.org/netdev/net-next/c/c000dca09800 - [net-next,05/11] net: mtk_eth_soc: convert mtk_sgmii to use regmap_update_bits() https://git.kernel.org/netdev/net-next/c/0d2351dc2768 - [net-next,06/11] net: mtk_eth_soc: add out of band forcing of speed and duplex in pcs_link_up https://git.kernel.org/netdev/net-next/c/12198c3a410f - [net-next,07/11] net: mtk_eth_soc: move PHY power up https://git.kernel.org/netdev/net-next/c/6f38fffe2179 - [net-next,08/11] net: mtk_eth_soc: move interface speed selection https://git.kernel.org/netdev/net-next/c/f752c0df13df - [net-next,09/11] net: mtk_eth_soc: add advertisement programming https://git.kernel.org/netdev/net-next/c/c125c66ea71b - [net-next,10/11] net: mtk_eth_soc: move and correct link timer programming https://git.kernel.org/netdev/net-next/c/3027d89f8770 - [net-next,11/11] net: mtk_eth_soc: add support for in-band 802.3z negotiation https://git.kernel.org/netdev/net-next/c/81b0f12a2a8a
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html