1
0

701-phy_extension.patch 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. @@ -382,6 +382,73 @@ void phy_ethtool_ksettings_get(struct ph
  11. }
  12. EXPORT_SYMBOL(phy_ethtool_ksettings_get);
  13. +static int phy_ethtool_gset(struct phy_device *phydev, struct ethtool_cmd *cmd)
  14. +{
  15. + cmd->supported = phydev->supported;
  16. +
  17. + cmd->advertising = phydev->advertising;
  18. + cmd->lp_advertising = phydev->lp_advertising;
  19. +
  20. + ethtool_cmd_speed_set(cmd, phydev->speed);
  21. + cmd->duplex = phydev->duplex;
  22. + if (phydev->interface == PHY_INTERFACE_MODE_MOCA)
  23. + cmd->port = PORT_BNC;
  24. + else
  25. + cmd->port = PORT_MII;
  26. + cmd->phy_address = phydev->mdio.addr;
  27. + cmd->transceiver = phy_is_internal(phydev) ?
  28. + XCVR_INTERNAL : XCVR_EXTERNAL;
  29. + cmd->autoneg = phydev->autoneg;
  30. + cmd->eth_tp_mdix_ctrl = phydev->mdix_ctrl;
  31. + cmd->eth_tp_mdix = phydev->mdix;
  32. +
  33. + return 0;
  34. +}
  35. +
  36. +int phy_ethtool_ioctl(struct phy_device *phydev, void *useraddr)
  37. +{
  38. + u32 cmd;
  39. + int tmp;
  40. + struct ethtool_cmd ecmd = { ETHTOOL_GSET };
  41. + struct ethtool_value edata = { ETHTOOL_GLINK };
  42. +
  43. + if (get_user(cmd, (u32 *) useraddr))
  44. + return -EFAULT;
  45. +
  46. + switch (cmd) {
  47. + case ETHTOOL_GSET:
  48. + phy_ethtool_gset(phydev, &ecmd);
  49. + if (copy_to_user(useraddr, &ecmd, sizeof(ecmd)))
  50. + return -EFAULT;
  51. + return 0;
  52. +
  53. + case ETHTOOL_SSET:
  54. + if (copy_from_user(&ecmd, useraddr, sizeof(ecmd)))
  55. + return -EFAULT;
  56. + return phy_ethtool_sset(phydev, &ecmd);
  57. +
  58. + case ETHTOOL_NWAY_RST:
  59. + /* if autoneg is off, it's an error */
  60. + tmp = phy_read(phydev, MII_BMCR);
  61. + if (tmp & BMCR_ANENABLE) {
  62. + tmp |= (BMCR_ANRESTART);
  63. + phy_write(phydev, MII_BMCR, tmp);
  64. + return 0;
  65. + }
  66. + return -EINVAL;
  67. +
  68. + case ETHTOOL_GLINK:
  69. + edata.data = (phy_read(phydev,
  70. + MII_BMSR) & BMSR_LSTATUS) ? 1 : 0;
  71. + if (copy_to_user(useraddr, &edata, sizeof(edata)))
  72. + return -EFAULT;
  73. + return 0;
  74. + }
  75. +
  76. + return -EOPNOTSUPP;
  77. +}
  78. +EXPORT_SYMBOL(phy_ethtool_ioctl);
  79. +
  80. /**
  81. * phy_mii_ioctl - generic PHY MII ioctl interface
  82. * @phydev: the phy_device struct
  83. --- a/include/linux/phy.h
  84. +++ b/include/linux/phy.h
  85. @@ -909,6 +909,7 @@ void phy_ethtool_ksettings_get(struct ph
  86. struct ethtool_link_ksettings *cmd);
  87. int phy_ethtool_ksettings_set(struct phy_device *phydev,
  88. const struct ethtool_link_ksettings *cmd);
  89. +int phy_ethtool_ioctl(struct phy_device *phydev, void *useraddr);
  90. int phy_mii_ioctl(struct phy_device *phydev, struct ifreq *ifr, int cmd);
  91. int phy_start_interrupts(struct phy_device *phydev);
  92. void phy_print_status(struct phy_device *phydev);