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.
Unified · Split
| @@ -2236,7 +2236,14 @@ static int phy_probe(struct device *dev) · 2235 unmodified lines | |||
| 2236 | * a controller will attach, and may modify one | 2236 | * a controller will attach, and may modify one |
| 2237 | * or both of these values | 2237 | * or both of these values |
| 2238 | */ | 2238 | */ |
| 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 | |||
| 2240 | of_set_phy_supported(phydev); | 2247 | of_set_phy_supported(phydev); |
| 2241 | linkmode_copy(phydev->advertising, phydev->supported); | 2248 | linkmode_copy(phydev->advertising, phydev->supported); |
| 2242 | 2249 | ||
| @@ -2256,20 +2263,8 @@ static int phy_probe(struct device *dev) · 13 unmodified lines | |||
| 2256 | * (e.g. hardware erratum) where the driver wants to set only one | 2263 | * (e.g. hardware erratum) where the driver wants to set only one |
| 2257 | * of these bits. | 2264 | * of these bits. |
| 2258 | */ | 2265 | */ |
| 2259 | if (test_bit(ETHTOOL_LINK_MODE_Pause_BIT, phydrv->features) || | 2266 | if (!test_bit(ETHTOOL_LINK_MODE_Pause_BIT, phydev->supported) && |
| 2260 | test_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, phydrv->features)) { | 2267 | !test_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, phydev->supported)) { |
| 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 { | ||
| 2273 | linkmode_set_bit(ETHTOOL_LINK_MODE_Pause_BIT, | 2268 | linkmode_set_bit(ETHTOOL_LINK_MODE_Pause_BIT, |
| 2274 | phydev->supported); | 2269 | phydev->supported); |
| 2275 | linkmode_set_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, | 2270 | 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 | |||
| 2315 | { | 2310 | { |
| 2316 | int retval; | 2311 | int retval; |
| 2317 | 2312 | ||
| 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))) { | ||
| 2319 | pr_err("%s: Driver features are missing\n", new_driver->name); | 2318 | pr_err("%s: Driver features are missing\n", new_driver->name); |
| 2320 | return -EINVAL; | 2319 | return -EINVAL; |
| 2321 | } | 2320 | } |
| @@ -502,6 +502,12 @@ struct phy_driver { · 501 unmodified lines | |||
| 502 | */ | 502 | */ |
| 503 | int (*probe)(struct phy_device *phydev); | 503 | int (*probe)(struct phy_device *phydev); |
| 504 | 504 | ||
| 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 | |||
| 505 | /* PHY Power Management */ | 511 | /* PHY Power Management */ |
| 506 | int (*suspend)(struct phy_device *phydev); | 512 | int (*suspend)(struct phy_device *phydev); |
| 507 | int (*resume)(struct phy_device *phydev); | 513 | int (*resume)(struct phy_device *phydev); |