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
4 */4 */
5#include <linux/export.h>5#include <linux/export.h>
6#include <linux/phy.h>6#include <linux/phy.h>
7#include <linux/of.h>
7 8
8const char *phy_speed_to_str(int speed)9const 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 return count;339 return count;
339}340}
340 341
342static 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
357int 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}
369EXPORT_SYMBOL(phy_set_max_speed);
370
371void 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 * phy_resolve_aneg_linkmode - resolve the advertisements into phy settings387 * phy_resolve_aneg_linkmode - resolve the advertisements into phy settings
343 * @phydev: The phy_device struct388 * @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
1949}1949}
1950EXPORT_SYMBOL(genphy_loopback);1950EXPORT_SYMBOL(genphy_loopback);
1951 1951
1952static 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
1976int 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}
1988EXPORT_SYMBOL(phy_set_max_speed);
1989
1990/**1952/**
1991 * phy_remove_link_mode - Remove a supported link mode1953 * phy_remove_link_mode - Remove a supported link mode
1992 * @phydev: phy_device structure to remove link mode from1954 * @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}
2118EXPORT_SYMBOL(phy_validate_pause);2080EXPORT_SYMBOL(phy_validate_pause);
2119 2081
2120static 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
2135static void of_set_phy_eee_broken(struct phy_device *phydev)2082static void of_set_phy_eee_broken(struct phy_device *phydev)
2136{2083{
2137 struct device_node *node = phydev->mdio.dev.of_node;2084 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
673 bool exact);673 bool exact);
674size_t phy_speeds(unsigned int *speeds, size_t size,674size_t phy_speeds(unsigned int *speeds, size_t size,
675 unsigned long *mask);675 unsigned long *mask);
676void of_set_phy_supported(struct phy_device *phydev);
676 677
677static inline bool __phy_is_started(struct phy_device *phydev)678static inline bool __phy_is_started(struct phy_device *phydev)
678{679{

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