History

net: phy: Mask-out non-compatible modes when setting the max-speed

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.

Maxime Chevallier committed 7 years ago

Commit a4eaed91 parent d2d37443 files · +46 −53Browse files

Unified · Split

3 files
  1. drivers/net/phy/phy-core.c +45 −0
  2. drivers/net/phy/phy_device.c +0 −53
  3. include/linux/phy.h +1 −0
drivers/net/phy/phy-core.c+45−0
@@ -4,6 +4,7 @@ · 3 unmodified lines
44 */
55 #include <linux/export.h>
66 #include <linux/phy.h>
7+#include <linux/of.h>
78
89 const char *phy_speed_to_str(int speed)
910 {
@@ -338,6 +339,50 @@ size_t phy_speeds(unsigned int *speeds, size_t size, · 328 unmodified lines
338339 return count;
339340 }
340341
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+
341386 /**
342387 * phy_resolve_aneg_linkmode - resolve the advertisements into phy settings
343388 * @phydev: The phy_device struct
drivers/net/phy/phy_device.c+0−53
@@ -1949,44 +1949,6 @@ int genphy_loopback(struct phy_device *phydev, bool enable) · 1948 unmodified lines
19491949 }
19501950 EXPORT_SYMBOL(genphy_loopback);
19511951
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−
19901952 /**
19911953 * phy_remove_link_mode - Remove a supported link mode
19921954 * @phydev: phy_device structure to remove link mode from
@@ -2117,21 +2079,6 @@ bool phy_validate_pause(struct phy_device *phydev, · 124 unmodified lines
21172079 }
21182080 EXPORT_SYMBOL(phy_validate_pause);
21192081
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−
21352082 static void of_set_phy_eee_broken(struct phy_device *phydev)
21362083 {
21372084 struct device_node *node = phydev->mdio.dev.of_node;
include/linux/phy.h+1−0
@@ -673,6 +673,7 @@ phy_lookup_setting(int speed, int duplex, const unsigned long *mask, · 672 unmodified lines
673673 bool exact);
674674 size_t phy_speeds(unsigned int *speeds, size_t size,
675675 unsigned long *mask);
676+void of_set_phy_supported(struct phy_device *phydev);
676677
677678 static inline bool __phy_is_started(struct phy_device *phydev)
678679 {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t