History

net: phy: Add support for asking the PHY its abilities

Add support for runtime determination of what the PHY supports, by adding a new function to the phy driver. The get_features call should set the phydev->supported member with the features the PHY supports. It is only called if phydrv->features is NULL. This requires minor changes to pause. The PHY driver should not set pause abilities, except for when it has odd cause capabilities, e.g. pause cannot be disabled. With this change, phydev->supported already contains the drivers abilities, including pause. So rather than considering phydrv->features, look at the phydev->supported, and enable pause if neither of the pause bits are already set.

Andrew Lunn committed 7 years ago

Commit efbdfdc1 parent 92ed2eb2 files · +21 −16Browse files

Unified · Split

2 files
  1. drivers/net/phy/phy_device.c +15 −16
  2. include/linux/phy.h +6 −0
drivers/net/phy/phy_device.c+15−16
@@ -2236,7 +2236,14 @@ static int phy_probe(struct device *dev) · 2235 unmodified lines
22362236 * a controller will attach, and may modify one
22372237 * or both of these values
22382238 */
2239− linkmode_copy(phydev->supported, phydrv->features);
2239+ if (phydrv->features) {
2240+ linkmode_copy(phydev->supported, phydrv->features);
2241+ } else {
2242+ err = phydrv->get_features(phydev);
2243+ if (err)
2244+ goto out;
2245+ }
2246+
22402247 of_set_phy_supported(phydev);
22412248 linkmode_copy(phydev->advertising, phydev->supported);
22422249
@@ -2256,20 +2263,8 @@ static int phy_probe(struct device *dev) · 13 unmodified lines
22562263 * (e.g. hardware erratum) where the driver wants to set only one
22572264 * of these bits.
22582265 */
2259− if (test_bit(ETHTOOL_LINK_MODE_Pause_BIT, phydrv->features) ||
2260− test_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, phydrv->features)) {
2261− linkmode_clear_bit(ETHTOOL_LINK_MODE_Pause_BIT,
2262− phydev->supported);
2263− linkmode_clear_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT,
2264− phydev->supported);
2265− if (test_bit(ETHTOOL_LINK_MODE_Pause_BIT, phydrv->features))
2266− linkmode_set_bit(ETHTOOL_LINK_MODE_Pause_BIT,
2267− phydev->supported);
2268− if (test_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT,
2269− phydrv->features))
2270− linkmode_set_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT,
2271− phydev->supported);
2272− } else {
2266+ if (!test_bit(ETHTOOL_LINK_MODE_Pause_BIT, phydev->supported) &&
2267+ !test_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, phydev->supported)) {
22732268 linkmode_set_bit(ETHTOOL_LINK_MODE_Pause_BIT,
22742269 phydev->supported);
22752270 linkmode_set_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT,
@@ -2315,7 +2310,11 @@ int phy_driver_register(struct phy_driver *new_driver, struct module *owner) · 39 unmodified lines
23152310 {
23162311 int retval;
23172312
2318− if (WARN_ON(!new_driver->features)) {
2313+ /* Either the features are hard coded, or dynamically
2314+ * determine. It cannot be both or neither
2315+ */
2316+ if (WARN_ON((!new_driver->features && !new_driver->get_features) ||
2317+ (new_driver->features && new_driver->get_features))) {
23192318 pr_err("%s: Driver features are missing\n", new_driver->name);
23202319 return -EINVAL;
23212320 }
include/linux/phy.h+6−0
@@ -502,6 +502,12 @@ struct phy_driver { · 501 unmodified lines
502502 */
503503 int (*probe)(struct phy_device *phydev);
504504
505+ /*
506+ * Probe the hardware to determine what abilities it has.
507+ * Should only set phydev->supported.
508+ */
509+ int (*get_features)(struct phy_device *phydev);
510+
505511 /* PHY Power Management */
506512 int (*suspend)(struct phy_device *phydev);
507513 int (*resume)(struct phy_device *phydev);

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