When setting a PHY's max speed using either the max-speed DT property or ethtool, we should mask-out all non-compatible modes according to the settings table, instead of just the 10/100BASET modes.
Unified · Split
| @@ -4,6 +4,7 @@ · 3 unmodified lines | ||
| 4 | 4 | */ |
| 5 | 5 | #include <linux/export.h> |
| 6 | 6 | #include <linux/phy.h> |
| 7 | +#include <linux/of.h> | |
| 7 | 8 | |
| 8 | 9 | const char *phy_speed_to_str(int speed) |
| 9 | 10 | { |
| @@ -338,6 +339,50 @@ size_t phy_speeds(unsigned int *speeds, size_t size, · 328 unmodified lines | ||
| 338 | 339 | return count; |
| 339 | 340 | } |
| 340 | 341 | |
| 342 | +static int __set_phy_supported(struct phy_device *phydev, u32 max_speed) | |
| 343 | +{ | |
| 344 | + const struct phy_setting *p; | |
| 345 | + int i; | |
| 346 | + | |
| 347 | + for (i = 0, p = settings; i < ARRAY_SIZE(settings); i++, p++) { | |
| 348 | + if (p->speed > max_speed) | |
| 349 | + linkmode_clear_bit(p->bit, phydev->supported); | |
| 350 | + else | |
| 351 | + break; | |
| 352 | + } | |
| 353 | + | |
| 354 | + return 0; | |
| 355 | +} | |
| 356 | + | |
| 357 | +int phy_set_max_speed(struct phy_device *phydev, u32 max_speed) | |
| 358 | +{ | |
| 359 | + int err; | |
| 360 | + | |
| 361 | + err = __set_phy_supported(phydev, max_speed); | |
| 362 | + if (err) | |
| 363 | + return err; | |
| 364 | + | |
| 365 | + linkmode_copy(phydev->advertising, phydev->supported); | |
| 366 | + | |
| 367 | + return 0; | |
| 368 | +} | |
| 369 | +EXPORT_SYMBOL(phy_set_max_speed); | |
| 370 | + | |
| 371 | +void of_set_phy_supported(struct phy_device *phydev) | |
| 372 | +{ | |
| 373 | + struct device_node *node = phydev->mdio.dev.of_node; | |
| 374 | + u32 max_speed; | |
| 375 | + | |
| 376 | + if (!IS_ENABLED(CONFIG_OF_MDIO)) | |
| 377 | + return; | |
| 378 | + | |
| 379 | + if (!node) | |
| 380 | + return; | |
| 381 | + | |
| 382 | + if (!of_property_read_u32(node, "max-speed", &max_speed)) | |
| 383 | + __set_phy_supported(phydev, max_speed); | |
| 384 | +} | |
| 385 | + | |
| 341 | 386 | /** |
| 342 | 387 | * phy_resolve_aneg_linkmode - resolve the advertisements into phy settings |
| 343 | 388 | * @phydev: The phy_device struct |
| @@ -1949,44 +1949,6 @@ int genphy_loopback(struct phy_device *phydev, bool enable) · 1948 unmodified lines | ||
| 1949 | 1949 | } |
| 1950 | 1950 | EXPORT_SYMBOL(genphy_loopback); |
| 1951 | 1951 | |
| 1952 | −static int __set_phy_supported(struct phy_device *phydev, u32 max_speed) | |
| 1953 | −{ | |
| 1954 | − switch (max_speed) { | |
| 1955 | − case SPEED_10: | |
| 1956 | − linkmode_clear_bit(ETHTOOL_LINK_MODE_100baseT_Half_BIT, | |
| 1957 | − phydev->supported); | |
| 1958 | − linkmode_clear_bit(ETHTOOL_LINK_MODE_100baseT_Full_BIT, | |
| 1959 | − phydev->supported); | |
| 1960 | − /* fall through */ | |
| 1961 | − case SPEED_100: | |
| 1962 | − linkmode_clear_bit(ETHTOOL_LINK_MODE_1000baseT_Half_BIT, | |
| 1963 | − phydev->supported); | |
| 1964 | − linkmode_clear_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT, | |
| 1965 | − phydev->supported); | |
| 1966 | − break; | |
| 1967 | − case SPEED_1000: | |
| 1968 | − break; | |
| 1969 | − default: | |
| 1970 | − return -ENOTSUPP; | |
| 1971 | − } | |
| 1972 | − | |
| 1973 | − return 0; | |
| 1974 | −} | |
| 1975 | − | |
| 1976 | −int phy_set_max_speed(struct phy_device *phydev, u32 max_speed) | |
| 1977 | −{ | |
| 1978 | − int err; | |
| 1979 | − | |
| 1980 | − err = __set_phy_supported(phydev, max_speed); | |
| 1981 | − if (err) | |
| 1982 | − return err; | |
| 1983 | − | |
| 1984 | − linkmode_copy(phydev->advertising, phydev->supported); | |
| 1985 | − | |
| 1986 | − return 0; | |
| 1987 | −} | |
| 1988 | −EXPORT_SYMBOL(phy_set_max_speed); | |
| 1989 | − | |
| 1990 | 1952 | /** |
| 1991 | 1953 | * phy_remove_link_mode - Remove a supported link mode |
| 1992 | 1954 | * @phydev: phy_device structure to remove link mode from |
| @@ -2117,21 +2079,6 @@ bool phy_validate_pause(struct phy_device *phydev, · 124 unmodified lines | ||
| 2117 | 2079 | } |
| 2118 | 2080 | EXPORT_SYMBOL(phy_validate_pause); |
| 2119 | 2081 | |
| 2120 | −static void of_set_phy_supported(struct phy_device *phydev) | |
| 2121 | −{ | |
| 2122 | − struct device_node *node = phydev->mdio.dev.of_node; | |
| 2123 | − u32 max_speed; | |
| 2124 | − | |
| 2125 | − if (!IS_ENABLED(CONFIG_OF_MDIO)) | |
| 2126 | − return; | |
| 2127 | − | |
| 2128 | − if (!node) | |
| 2129 | − return; | |
| 2130 | − | |
| 2131 | − if (!of_property_read_u32(node, "max-speed", &max_speed)) | |
| 2132 | − __set_phy_supported(phydev, max_speed); | |
| 2133 | −} | |
| 2134 | − | |
| 2135 | 2082 | static void of_set_phy_eee_broken(struct phy_device *phydev) |
| 2136 | 2083 | { |
| 2137 | 2084 | struct device_node *node = phydev->mdio.dev.of_node; |
| @@ -673,6 +673,7 @@ phy_lookup_setting(int speed, int duplex, const unsigned long *mask, · 672 unmodified lines | ||
| 673 | 673 | bool exact); |
| 674 | 674 | size_t phy_speeds(unsigned int *speeds, size_t size, |
| 675 | 675 | unsigned long *mask); |
| 676 | +void of_set_phy_supported(struct phy_device *phydev); | |
| 676 | 677 | |
| 677 | 678 | static inline bool __phy_is_started(struct phy_device *phydev) |
| 678 | 679 | { |