net: phy: as21xxx: handle corner case with link and autoneg complete
Subsystems (4)
Christian Marangi
maintainerPATCH 1/3 net: phy: as21xxx: handle corner case with link and autoneg complete
Add missing case in custom read_link, when autoneg is started, autoneg complete bit is reset but link is still not up.
--- drivers/net/phy/as21xxx.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/net/phy/as21xxx.c +7 -0
@@ -658,6 +658,13 @@ static int as21xxx_read_link(struct phy_device *phydev, int *bmcr)return status; phydev->link = !!(status &MDIO_STAT1_LSTATUS ); + phydev->autoneg_complete = !!(status &MDIO_AN_STAT1_COMPLETE ); + +/* Consider the case that autoneg was started and "aneg complete" +* bit has been reset, but "link up" bit not yet. +*/ +if (phydev->autoneg ==AUTONEG_ENABLE && !phydev->autoneg_complete) + phydev->link =0 ;return 0 ; }
Signature · 1 line
2.53.0
Christian Marangi
maintainerPATCH 2/3 net: phy: as21xxx: fix read_status speed handling
With further test with 2.5G NIC it was discovered that phy_resolve_aneg_linkmode is not enough to detect speed higher that 1G when autoneg is enabled.
Also in the switch case there is a typo where the speed mask is AND with VEND1_SPEED_STATUS instead of the correct mask VEND1_SPEED_MASK.
Rework the read_status code to always read the speed from the vendor register and parse the generic bit only for the pause frame.
--- drivers/net/phy/as21xxx.c | 96 +++++++++++++++++++++------------------ 1 file changed, 53 insertions(+), 43 deletions(-)
drivers/net/phy/as21xxx.c +53 -43
@@ -671,7 +671,7 @@ static int as21xxx_read_link(struct phy_device *phydev, int *bmcr)static int as21xxx_read_c22_lpa (struct phy_device *phydev) { -int lpagb; +int lpagb, lpa;/* MII_STAT1000 are only filled in the mapped C22 * in C45, use that to fill lpagb values and check.
@@ -698,12 +698,20 @@ static int as21xxx_read_c22_lpa(struct phy_device *phydev)mii_stat1000_mod_linkmode_lpa_t (phydev->lp_advertising, lpagb); + lpa =phy_read_mmd (phydev,MDIO_MMD_AN , +AS21XXX_MDIO_AN_C22 +MII_LPA ); +if (lpa <0 ) +return lpa; + +mii_lpa_mod_linkmode_lpa_t (phydev->lp_advertising, lpa); +return 0 ; }static int as21xxx_read_status (struct phy_device *phydev) {int bmcr, old_link = phydev->link; +int speed;int ret; ret =as21xxx_read_link (phydev, &bmcr);
@@ -720,58 +728,60 @@ static int as21xxx_read_status(struct phy_device *phydev) phydev->asym_pause =0 ;if (phydev->autoneg ==AUTONEG_ENABLE ) { - ret =genphy_c45_read_lpa (phydev); -if (ret) -return ret; +if (!phydev->autoneg_complete) { +mii_stat1000_mod_linkmode_lpa_t (phydev->lp_advertising, +0 ); +mii_lpa_mod_linkmode_lpa_t (phydev->lp_advertising,0 ); +return 0 ; + } ret =as21xxx_read_c22_lpa (phydev);if (ret)return ret; - -phy_resolve_aneg_linkmode (phydev); }else { -int speed; -linkmode_zero (phydev->lp_advertising); + } - speed =phy_read_mmd (phydev,MDIO_MMD_VEND1 , -VEND1_SPEED_STATUS ); -if (speed <0 ) -return speed; - -switch (speed &VEND1_SPEED_STATUS ) { -case VEND1_SPEED_10000 : - phydev->speed =SPEED_10000 ; - phydev->duplex =DUPLEX_FULL ; -break ; -case VEND1_SPEED_5000 : - phydev->speed =SPEED_5000 ; - phydev->duplex =DUPLEX_FULL ; -break ; -case VEND1_SPEED_2500 : - phydev->speed =SPEED_2500 ; - phydev->duplex =DUPLEX_FULL ; -break ; -case VEND1_SPEED_1000 : - phydev->speed =SPEED_1000 ; -if (bmcr &BMCR_FULLDPLX ) - phydev->duplex =DUPLEX_FULL ; -else - phydev->duplex =DUPLEX_HALF ; -break ; -case VEND1_SPEED_100 : - phydev->speed =SPEED_100 ; + speed =phy_read_mmd (phydev,MDIO_MMD_VEND1 , +VEND1_SPEED_STATUS ); +if (speed <0 ) +return speed; + +switch (speed &VEND1_SPEED_MASK ) { +case VEND1_SPEED_10000 : + phydev->speed =SPEED_10000 ; + phydev->duplex =DUPLEX_FULL ; +break ; +case VEND1_SPEED_5000 : + phydev->speed =SPEED_5000 ; + phydev->duplex =DUPLEX_FULL ; +break ; +case VEND1_SPEED_2500 : + phydev->speed =SPEED_2500 ; + phydev->duplex =DUPLEX_FULL ; +break ; +case VEND1_SPEED_1000 : + phydev->speed =SPEED_1000 ; +if (bmcr &BMCR_FULLDPLX ) phydev->duplex =DUPLEX_FULL ; -break ; -case VEND1_SPEED_10 : - phydev->speed =SPEED_10 ; - phydev->duplex =DUPLEX_FULL ; -break ; -default : -return -EINVAL ; - } +else + phydev->duplex =DUPLEX_HALF ; +break ; +case VEND1_SPEED_100 : + phydev->speed =SPEED_100 ; + phydev->duplex =DUPLEX_FULL ; +break ; +case VEND1_SPEED_10 : + phydev->speed =SPEED_10 ; + phydev->duplex =DUPLEX_FULL ; +break ; +default : +return -EINVAL ; } +if (phydev->autoneg ==AUTONEG_ENABLE ) +phy_resolve_aneg_pause (phydev); +return 0 ; }
Signature · 1 line
2.53.0
Christian Marangi
maintainerPATCH 3/3 net: phy: as21xxx: force C45 OPs for AUTONEG
In reply to Christian MarangiWith further testing with 2.5G NIC, it was discovered that the PHY require the C45 OPs to configure and restart ANEG or speed higher than 1G doesn't function correctly.
To force C45 OPs with generic PHY function, clear the C22 bit from devices_in_package bitmask.
--- drivers/net/phy/as21xxx.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/net/phy/as21xxx.c +7 -0
@@ -616,6 +616,13 @@ static int as21xxx_probe(struct phy_device *phydev)if (ret)return ret; +/* Even if PHY declare support for Clause 22 register, +* Clause 45 register should be used for ANEG configuration +* and restart. Clear the C22 bit for devices_in_package to +* force C45 generic OPs in generic PHY ANGE OPs. +*/ + phydev->c45_ids.devices_in_package &= ~BIT (0 ); + ret =aeon_ipc_sync_parity (phydev, priv);if (ret)return ret;
Signature · 1 line
2.53.0
Quoted 5 lines · Christian Marangi
Add missing case in custom
read_link, when autoneg is started, autoneg complete bit is reset but link is still not up.Fixes 830877d89edc ("net: phy: Add support for Aeonsemi AS21xxx PHYs")Signed-off-by Christian Marangi <[email protected]>
Looks like the same approach as in genphy_update_link()
Maxime
Quoted 22 lines
--- drivers/net/phy/as21xxx.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/net/phy/as21xxx.c +7
-0@@ -658,6 +658,13 @@ static int as21xxx_read_link(struct phy_device *phydev, int *bmcr)return status; phydev->link = !!(status &MDIO_STAT1_LSTATUS ); + phydev->autoneg_complete = !!(status &MDIO_AN_STAT1_COMPLETE ); + +/* Consider the case that autoneg was started and "aneg complete" +* bit has been reset, but "link up" bit not yet. +*/ +if (phydev->autoneg ==AUTONEG_ENABLE && !phydev->autoneg_complete) + phydev->link =0 ;return 0 ; }
Re: [PATCH net 2/3] net: phy: as21xxx: fix read_status speed handling
In reply to Christian MarangiQuoted 4 lines · Christian Marangi
With further test with 2.5G NIC it was discovered that
phy_resolve_aneg_linkmodeis not enough to detect speed higher that 1G when autoneg is enabled.
Quoted 8 lines
Also in the switch case there is a typo where the speed mask is AND with
VEND1_SPEED_STATUSinstead of the correct maskVEND1_SPEED_MASK.Rework the
read_statuscode to always read the speed from the vendor register and parse the generic bit only for the pause frame.Fixes 830877d89edc ("net: phy: Add support for Aeonsemi AS21xxx PHYs")Signed-off-by Christian Marangi <[email protected]>
Maxime
Quoted 141 lines
--- drivers/net/phy/as21xxx.c | 96 +++++++++++++++++++++------------------ 1 file changed, 53 insertions(+), 43 deletions(-)drivers/net/phy/as21xxx.c +53
-43@@ -671,7 +671,7 @@ static int as21xxx_read_link(struct phy_device *phydev, int *bmcr)static int as21xxx_read_c22_lpa (struct phy_device *phydev) { -int lpagb; +int lpagb, lpa;/* MII_STAT1000 are only filled in the mapped C22 * in C45, use that to fill lpagb values and check. @@ -698,12 +698,20 @@ static int as21xxx_read_c22_lpa(struct phy_device *phydev)mii_stat1000_mod_linkmode_lpa_t (phydev->lp_advertising, lpagb); + lpa =phy_read_mmd (phydev,MDIO_MMD_AN , +AS21XXX_MDIO_AN_C22 +MII_LPA ); +if (lpa <0 ) +return lpa; + +mii_lpa_mod_linkmode_lpa_t (phydev->lp_advertising, lpa); +return 0 ; }static int as21xxx_read_status (struct phy_device *phydev) {int bmcr, old_link = phydev->link; +int speed;int ret; ret =as21xxx_read_link (phydev, &bmcr);@@ -720,58 +728,60 @@ static int as21xxx_read_status(struct phy_device *phydev) phydev->asym_pause =0 ;if (phydev->autoneg ==AUTONEG_ENABLE ) { - ret =genphy_c45_read_lpa (phydev); -if (ret) -return ret; +if (!phydev->autoneg_complete) { +mii_stat1000_mod_linkmode_lpa_t (phydev->lp_advertising, +0 ); +mii_lpa_mod_linkmode_lpa_t (phydev->lp_advertising,0 ); +return 0 ; + } ret =as21xxx_read_c22_lpa (phydev);if (ret)return ret; - -phy_resolve_aneg_linkmode (phydev); }else { -int speed; -linkmode_zero (phydev->lp_advertising); + } - speed =phy_read_mmd (phydev,MDIO_MMD_VEND1 , -VEND1_SPEED_STATUS ); -if (speed <0 ) -return speed; - -switch (speed &VEND1_SPEED_STATUS ) { -case VEND1_SPEED_10000 : - phydev->speed =SPEED_10000 ; - phydev->duplex =DUPLEX_FULL ; -break ; -case VEND1_SPEED_5000 : - phydev->speed =SPEED_5000 ; - phydev->duplex =DUPLEX_FULL ; -break ; -case VEND1_SPEED_2500 : - phydev->speed =SPEED_2500 ; - phydev->duplex =DUPLEX_FULL ; -break ; -case VEND1_SPEED_1000 : - phydev->speed =SPEED_1000 ; -if (bmcr &BMCR_FULLDPLX ) - phydev->duplex =DUPLEX_FULL ; -else - phydev->duplex =DUPLEX_HALF ; -break ; -case VEND1_SPEED_100 : - phydev->speed =SPEED_100 ; + speed =phy_read_mmd (phydev,MDIO_MMD_VEND1 , +VEND1_SPEED_STATUS ); +if (speed <0 ) +return speed; + +switch (speed &VEND1_SPEED_MASK ) { +case VEND1_SPEED_10000 : + phydev->speed =SPEED_10000 ; + phydev->duplex =DUPLEX_FULL ; +break ; +case VEND1_SPEED_5000 : + phydev->speed =SPEED_5000 ; + phydev->duplex =DUPLEX_FULL ; +break ; +case VEND1_SPEED_2500 : + phydev->speed =SPEED_2500 ; + phydev->duplex =DUPLEX_FULL ; +break ; +case VEND1_SPEED_1000 : + phydev->speed =SPEED_1000 ; +if (bmcr &BMCR_FULLDPLX ) phydev->duplex =DUPLEX_FULL ; -break ; -case VEND1_SPEED_10 : - phydev->speed =SPEED_10 ; - phydev->duplex =DUPLEX_FULL ; -break ; -default : -return -EINVAL ; - } +else + phydev->duplex =DUPLEX_HALF ; +break ; +case VEND1_SPEED_100 : + phydev->speed =SPEED_100 ; + phydev->duplex =DUPLEX_FULL ; +break ; +case VEND1_SPEED_10 : + phydev->speed =SPEED_10 ; + phydev->duplex =DUPLEX_FULL ; +break ; +default : +return -EINVAL ; } +if (phydev->autoneg ==AUTONEG_ENABLE ) +phy_resolve_aneg_pause (phydev); +return 0 ; }
Re: [PATCH net 3/3] net: phy: as21xxx: force C45 OPs for AUTONEG
In reply to Christian MarangiQuoted 9 lines · Christian Marangi
With further testing with 2.5G NIC, it was discovered that the PHY require the C45 OPs to configure and restart ANEG or speed higher than 1G doesn't function correctly.
To force C45 OPs with generic PHY function, clear the C22 bit from
devices_in_packagebitmask.Fixes 830877d89edc ("net: phy: Add support for Aeonsemi AS21xxx PHYs")Signed-off-by Christian Marangi <[email protected]>
Maxime
Quoted 22 lines
--- drivers/net/phy/as21xxx.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/net/phy/as21xxx.c +7
-0@@ -616,6 +616,13 @@ static int as21xxx_probe(struct phy_device *phydev)if (ret)return ret; +/* Even if PHY declare support for Clause 22 register, +* Clause 45 register should be used for ANEG configuration +* and restart. Clear the C22 bit for devices_in_package to +* force C45 generic OPs in generic PHY ANGE OPs. +*/ + phydev->c45_ids.devices_in_package &= ~BIT (0 ); + ret =aeon_ipc_sync_parity (phydev, priv);if (ret)return ret;
Paolo Abeni
maintainerRe: [PATCH net 3/3] net: phy: as21xxx: force C45 OPs for AUTONEG
In reply to Christian MarangiQuoted 9 lines · Christian Marangi
With further testing with 2.5G NIC, it was discovered that the PHY require the C45 OPs to configure and restart ANEG or speed higher than 1G doesn't function correctly.
To force C45 OPs with generic PHY function, clear the C22 bit from
devices_in_packagebitmask.Fixes 830877d89edc ("net: phy: Add support for Aeonsemi AS21xxx PHYs")Signed-off-by Christian Marangi <[email protected]>
Sashiko has a few comments here and on the previous patch:
https://sashiko.dev/#/patchset/20260601105342.28865-1-ansuelsmth%40gmail.com
could you please double check them?