2
0

403-net-phy-avoid-setting-unsupported-EEE-advertisments.patch 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. From: Russell King <[email protected]>
  2. Date: Wed, 4 Jan 2017 21:00:51 +0000
  3. Subject: [PATCH] net: phy: avoid setting unsupported EEE advertisments
  4. We currently allow userspace to set any EEE advertisments it desires,
  5. whether or not the PHY supports them. For example:
  6. # ethtool --set-eee eth1 advertise 0xffffffff
  7. # ethtool --show-eee eth1
  8. EEE Settings for eth1:
  9. EEE status: disabled
  10. Tx LPI: disabled
  11. Supported EEE link modes: 100baseT/Full
  12. 1000baseT/Full
  13. 10000baseT/Full
  14. Advertised EEE link modes: 100baseT/Full
  15. 1000baseT/Full
  16. 1000baseKX/Full
  17. 10000baseT/Full
  18. 10000baseKX4/Full
  19. 10000baseKR/Full
  20. Clearly, this is not sane, we should only allow link modes that are
  21. supported to be advertised (as we do elsewhere.) Ensure that we mask
  22. the MDIO_AN_EEE_ADV value with the capabilities retrieved from the
  23. MDIO_PCS_EEE_ABLE register.
  24. Signed-off-by: Russell King <[email protected]>
  25. ---
  26. --- a/drivers/net/phy/phy.c
  27. +++ b/drivers/net/phy/phy.c
  28. @@ -1343,14 +1343,19 @@ EXPORT_SYMBOL(phy_ethtool_get_eee);
  29. */
  30. int phy_ethtool_set_eee(struct phy_device *phydev, struct ethtool_eee *data)
  31. {
  32. - int val = ethtool_adv_to_mmd_eee_adv_t(data->advertised);
  33. + int cap, adv;
  34. - /* Mask prohibited EEE modes */
  35. - val &= ~phydev->eee_broken_modes;
  36. + /* Get Supported EEE */
  37. + cap = phy_read_mmd(phydev, MDIO_MMD_PCS, MDIO_PCS_EEE_ABLE);
  38. + if (cap < 0)
  39. + return cap;
  40. +
  41. + adv = ethtool_adv_to_mmd_eee_adv_t(data->advertised) & cap;
  42. - phy_write_mmd_indirect(phydev, MDIO_AN_EEE_ADV, MDIO_MMD_AN, val);
  43. + /* Mask prohibited EEE modes */
  44. + adv &= ~phydev->eee_broken_modes;
  45. - return 0;
  46. + return phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_EEE_ADV, adv);
  47. }
  48. EXPORT_SYMBOL(phy_ethtool_set_eee);