The Clause 45 ability registers hold a single bit for 10BASE-T and one for 100BASE-TX, so genphy_c45_pma_read_abilities() derives both the full and half duplex link modes from each of them, even on PHYs that support neither 10BASE-T nor half duplex. Read the 2.5G, 5G and 10G abilities from the Clause 45 registers as before, then take the 10M, 100M and 1G link modes from the Clause 22 ADVERTISE and CTRL1000 registers mapped in the AN MMD. The firmware does not update the C22 BMSR/ESTATUS ability bits, but its default advertisement reflects the modes the PHY actually supports. If the advertisement reads back empty, keep the Clause 45 derived modes. Note that those registers mirror the current advertisement rather than a fixed capability set, so they reflect the supported modes only while the firmware defaults are in place. The PHY is reset when the driver is unbound, so it reports the generic pre-firmware ID again and the firmware is reloaded from .match_phy_device() before the next probe. Hence .get_features() always samples the firmware defaults. Fixes: 830877d89edc ("net: phy: Add support for Aeonsemi AS21xxx PHYs") Signed-off-by: Cristian Ciocaltea --- drivers/net/phy/as21xxx.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/drivers/net/phy/as21xxx.c b/drivers/net/phy/as21xxx.c index 1c4a808bf01e..3423448a0cb1 100644 --- a/drivers/net/phy/as21xxx.c +++ b/drivers/net/phy/as21xxx.c @@ -644,6 +644,61 @@ static int as21xxx_probe(struct phy_device *phydev) return aeon_dpc_ra_enable(phydev); } +static int as21xxx_get_features(struct phy_device *phydev) +{ + int ret, adv, ctrl1000; + + /* Only the Clause 45 ability registers describe the 2.5G, 5G and 10G + * speeds. + */ + ret = genphy_c45_pma_read_abilities(phydev); + if (ret) + return ret; + + /* The C45 registers hold a single bit each for 10BASE-T and 100BASE-TX, + * so phylib sets both duplex modes. The firmware doesn't update the + * ability bits of the C22 BMSR/ESTATUS mapped in the AN MMD, but its + * default advertisement in the mapped ADVERTISE and CTRL1000 reflects + * the modes it actually supports, so take the 10M, 100M and 1G link + * modes from there. + */ + adv = phy_read_mmd(phydev, MDIO_MMD_AN, + AS21XXX_MDIO_AN_C22 + MII_ADVERTISE); + if (adv < 0) + return adv; + + ctrl1000 = phy_read_mmd(phydev, MDIO_MMD_AN, + AS21XXX_MDIO_AN_C22 + MII_CTRL1000); + if (ctrl1000 < 0) + return ctrl1000; + + /* If the firmware defaults are not available, keep the C45-derived + * modes rather than dropping all 10/100/1000 link modes. + */ + if (!(adv & ADVERTISE_ALL) || + !(ctrl1000 & (ADVERTISE_1000HALF | ADVERTISE_1000FULL))) { + phydev_warn(phydev, + "Empty C22 advertisement, using C45 abilities\n"); + return 0; + } + + linkmode_mod_bit(ETHTOOL_LINK_MODE_10baseT_Half_BIT, + phydev->supported, adv & ADVERTISE_10HALF); + linkmode_mod_bit(ETHTOOL_LINK_MODE_10baseT_Full_BIT, + phydev->supported, adv & ADVERTISE_10FULL); + linkmode_mod_bit(ETHTOOL_LINK_MODE_100baseT_Half_BIT, + phydev->supported, adv & ADVERTISE_100HALF); + linkmode_mod_bit(ETHTOOL_LINK_MODE_100baseT_Full_BIT, + phydev->supported, adv & ADVERTISE_100FULL); + + linkmode_mod_bit(ETHTOOL_LINK_MODE_1000baseT_Half_BIT, + phydev->supported, ctrl1000 & ADVERTISE_1000HALF); + linkmode_mod_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT, + phydev->supported, ctrl1000 & ADVERTISE_1000FULL); + + return 0; +} + static int as21xxx_read_link(struct phy_device *phydev, int *bmcr) { int status; @@ -981,6 +1036,7 @@ static struct phy_driver as21xxx_drivers[] = { .probe = as21xxx_probe, .match_phy_device = as21xxx_match_phy_device, .read_status = as21xxx_read_status, + .get_features = as21xxx_get_features, .led_brightness_set = as21xxx_led_brightness_set, .led_hw_is_supported = as21xxx_led_hw_is_supported, .led_hw_control_set = as21xxx_led_hw_control_set, @@ -993,6 +1049,7 @@ static struct phy_driver as21xxx_drivers[] = { .probe = as21xxx_probe, .match_phy_device = as21xxx_match_phy_device, .read_status = as21xxx_read_status, + .get_features = as21xxx_get_features, .led_brightness_set = as21xxx_led_brightness_set, .led_hw_is_supported = as21xxx_led_hw_is_supported, .led_hw_control_set = as21xxx_led_hw_control_set, @@ -1005,6 +1062,7 @@ static struct phy_driver as21xxx_drivers[] = { .probe = as21xxx_probe, .match_phy_device = as21xxx_match_phy_device, .read_status = as21xxx_read_status, + .get_features = as21xxx_get_features, .led_brightness_set = as21xxx_led_brightness_set, .led_hw_is_supported = as21xxx_led_hw_is_supported, .led_hw_control_set = as21xxx_led_hw_control_set, @@ -1017,6 +1075,7 @@ static struct phy_driver as21xxx_drivers[] = { .probe = as21xxx_probe, .match_phy_device = as21xxx_match_phy_device, .read_status = as21xxx_read_status, + .get_features = as21xxx_get_features, .led_brightness_set = as21xxx_led_brightness_set, .led_hw_is_supported = as21xxx_led_hw_is_supported, .led_hw_control_set = as21xxx_led_hw_control_set, @@ -1029,6 +1088,7 @@ static struct phy_driver as21xxx_drivers[] = { .probe = as21xxx_probe, .match_phy_device = as21xxx_match_phy_device, .read_status = as21xxx_read_status, + .get_features = as21xxx_get_features, .led_brightness_set = as21xxx_led_brightness_set, .led_hw_is_supported = as21xxx_led_hw_is_supported, .led_hw_control_set = as21xxx_led_hw_control_set, @@ -1041,6 +1101,7 @@ static struct phy_driver as21xxx_drivers[] = { .probe = as21xxx_probe, .match_phy_device = as21xxx_match_phy_device, .read_status = as21xxx_read_status, + .get_features = as21xxx_get_features, .led_brightness_set = as21xxx_led_brightness_set, .led_hw_is_supported = as21xxx_led_hw_is_supported, .led_hw_control_set = as21xxx_led_hw_control_set, @@ -1053,6 +1114,7 @@ static struct phy_driver as21xxx_drivers[] = { .probe = as21xxx_probe, .match_phy_device = as21xxx_match_phy_device, .read_status = as21xxx_read_status, + .get_features = as21xxx_get_features, .led_brightness_set = as21xxx_led_brightness_set, .led_hw_is_supported = as21xxx_led_hw_is_supported, .led_hw_control_set = as21xxx_led_hw_control_set, @@ -1065,6 +1127,7 @@ static struct phy_driver as21xxx_drivers[] = { .probe = as21xxx_probe, .match_phy_device = as21xxx_match_phy_device, .read_status = as21xxx_read_status, + .get_features = as21xxx_get_features, .led_brightness_set = as21xxx_led_brightness_set, .led_hw_is_supported = as21xxx_led_hw_is_supported, .led_hw_control_set = as21xxx_led_hw_control_set, @@ -1077,6 +1140,7 @@ static struct phy_driver as21xxx_drivers[] = { .probe = as21xxx_probe, .match_phy_device = as21xxx_match_phy_device, .read_status = as21xxx_read_status, + .get_features = as21xxx_get_features, .led_brightness_set = as21xxx_led_brightness_set, .led_hw_is_supported = as21xxx_led_hw_is_supported, .led_hw_control_set = as21xxx_led_hw_control_set, @@ -1089,6 +1153,7 @@ static struct phy_driver as21xxx_drivers[] = { .probe = as21xxx_probe, .match_phy_device = as21xxx_match_phy_device, .read_status = as21xxx_read_status, + .get_features = as21xxx_get_features, .led_brightness_set = as21xxx_led_brightness_set, .led_hw_is_supported = as21xxx_led_hw_is_supported, .led_hw_control_set = as21xxx_led_hw_control_set, -- 2.56.0