701-phy_extension.patch 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. From: John Crispin <john@phrozen.org>
  2. Subject: net: phy: add phy_ethtool_ioctl()
  3. Signed-off-by: John Crispin <john@phrozen.org>
  4. ---
  5. drivers/net/phy/phy.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
  6. include/linux/phy.h | 1 +
  7. 2 files changed, 45 insertions(+)
  8. --- a/drivers/net/phy/phy.c
  9. +++ b/drivers/net/phy/phy.c
  10. @@ -472,6 +472,50 @@ int phy_ethtool_ksettings_get(struct phy
  11. }
  12. EXPORT_SYMBOL(phy_ethtool_ksettings_get);
  13. +int phy_ethtool_ioctl(struct phy_device *phydev, void *useraddr)
  14. +{
  15. + u32 cmd;
  16. + int tmp;
  17. + struct ethtool_cmd ecmd = { ETHTOOL_GSET };
  18. + struct ethtool_value edata = { ETHTOOL_GLINK };
  19. +
  20. + if (get_user(cmd, (u32 *) useraddr))
  21. + return -EFAULT;
  22. +
  23. + switch (cmd) {
  24. + case ETHTOOL_GSET:
  25. + phy_ethtool_gset(phydev, &ecmd);
  26. + if (copy_to_user(useraddr, &ecmd, sizeof(ecmd)))
  27. + return -EFAULT;
  28. + return 0;
  29. +
  30. + case ETHTOOL_SSET:
  31. + if (copy_from_user(&ecmd, useraddr, sizeof(ecmd)))
  32. + return -EFAULT;
  33. + return phy_ethtool_sset(phydev, &ecmd);
  34. +
  35. + case ETHTOOL_NWAY_RST:
  36. + /* if autoneg is off, it's an error */
  37. + tmp = phy_read(phydev, MII_BMCR);
  38. + if (tmp & BMCR_ANENABLE) {
  39. + tmp |= (BMCR_ANRESTART);
  40. + phy_write(phydev, MII_BMCR, tmp);
  41. + return 0;
  42. + }
  43. + return -EINVAL;
  44. +
  45. + case ETHTOOL_GLINK:
  46. + edata.data = (phy_read(phydev,
  47. + MII_BMSR) & BMSR_LSTATUS) ? 1 : 0;
  48. + if (copy_to_user(useraddr, &edata, sizeof(edata)))
  49. + return -EFAULT;
  50. + return 0;
  51. + }
  52. +
  53. + return -EOPNOTSUPP;
  54. +}
  55. +EXPORT_SYMBOL(phy_ethtool_ioctl);
  56. +
  57. /**
  58. * phy_mii_ioctl - generic PHY MII ioctl interface
  59. * @phydev: the phy_device struct
  60. --- a/include/linux/phy.h
  61. +++ b/include/linux/phy.h
  62. @@ -827,6 +827,7 @@ int phy_ethtool_ksettings_get(struct phy
  63. struct ethtool_link_ksettings *cmd);
  64. int phy_ethtool_ksettings_set(struct phy_device *phydev,
  65. const struct ethtool_link_ksettings *cmd);
  66. +int phy_ethtool_ioctl(struct phy_device *phydev, void *useraddr);
  67. int phy_mii_ioctl(struct phy_device *phydev, struct ifreq *ifr, int cmd);
  68. int phy_start_interrupts(struct phy_device *phydev);
  69. void phy_print_status(struct phy_device *phydev);