ethtool.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #include <linux/netdevice.h>
  2. #include <linux/ethtool.h>
  3. #include <linux/delay.h>
  4. #include "host.h"
  5. #include "decl.h"
  6. #include "defs.h"
  7. #include "dev.h"
  8. #include "wext.h"
  9. #include "cmd.h"
  10. #include "mesh.h"
  11. static void lbs_ethtool_get_drvinfo(struct net_device *dev,
  12. struct ethtool_drvinfo *info)
  13. {
  14. struct lbs_private *priv = dev->ml_priv;
  15. snprintf(info->fw_version, 32, "%u.%u.%u.p%u",
  16. priv->fwrelease >> 24 & 0xff,
  17. priv->fwrelease >> 16 & 0xff,
  18. priv->fwrelease >> 8 & 0xff,
  19. priv->fwrelease & 0xff);
  20. strcpy(info->driver, "libertas");
  21. strcpy(info->version, lbs_driver_version);
  22. }
  23. /* All 8388 parts have 16KiB EEPROM size at the time of writing.
  24. * In case that changes this needs fixing.
  25. */
  26. #define LBS_EEPROM_LEN 16384
  27. static int lbs_ethtool_get_eeprom_len(struct net_device *dev)
  28. {
  29. return LBS_EEPROM_LEN;
  30. }
  31. static int lbs_ethtool_get_eeprom(struct net_device *dev,
  32. struct ethtool_eeprom *eeprom, u8 * bytes)
  33. {
  34. struct lbs_private *priv = dev->ml_priv;
  35. struct cmd_ds_802_11_eeprom_access cmd;
  36. int ret;
  37. lbs_deb_enter(LBS_DEB_ETHTOOL);
  38. if (eeprom->offset + eeprom->len > LBS_EEPROM_LEN ||
  39. eeprom->len > LBS_EEPROM_READ_LEN) {
  40. ret = -EINVAL;
  41. goto out;
  42. }
  43. cmd.hdr.size = cpu_to_le16(sizeof(struct cmd_ds_802_11_eeprom_access) -
  44. LBS_EEPROM_READ_LEN + eeprom->len);
  45. cmd.action = cpu_to_le16(CMD_ACT_GET);
  46. cmd.offset = cpu_to_le16(eeprom->offset);
  47. cmd.len = cpu_to_le16(eeprom->len);
  48. ret = lbs_cmd_with_response(priv, CMD_802_11_EEPROM_ACCESS, &cmd);
  49. if (!ret)
  50. memcpy(bytes, cmd.value, eeprom->len);
  51. out:
  52. lbs_deb_leave_args(LBS_DEB_ETHTOOL, "ret %d", ret);
  53. return ret;
  54. }
  55. static void lbs_ethtool_get_wol(struct net_device *dev,
  56. struct ethtool_wolinfo *wol)
  57. {
  58. struct lbs_private *priv = dev->ml_priv;
  59. if (priv->wol_criteria == 0xffffffff) {
  60. /* Interface driver didn't configure wake */
  61. wol->supported = wol->wolopts = 0;
  62. return;
  63. }
  64. wol->supported = WAKE_UCAST|WAKE_MCAST|WAKE_BCAST|WAKE_PHY;
  65. if (priv->wol_criteria & EHS_WAKE_ON_UNICAST_DATA)
  66. wol->wolopts |= WAKE_UCAST;
  67. if (priv->wol_criteria & EHS_WAKE_ON_MULTICAST_DATA)
  68. wol->wolopts |= WAKE_MCAST;
  69. if (priv->wol_criteria & EHS_WAKE_ON_BROADCAST_DATA)
  70. wol->wolopts |= WAKE_BCAST;
  71. if (priv->wol_criteria & EHS_WAKE_ON_MAC_EVENT)
  72. wol->wolopts |= WAKE_PHY;
  73. }
  74. static int lbs_ethtool_set_wol(struct net_device *dev,
  75. struct ethtool_wolinfo *wol)
  76. {
  77. struct lbs_private *priv = dev->ml_priv;
  78. uint32_t criteria = 0;
  79. if (wol->wolopts & ~(WAKE_UCAST|WAKE_MCAST|WAKE_BCAST|WAKE_PHY))
  80. return -EOPNOTSUPP;
  81. if (wol->wolopts & WAKE_UCAST)
  82. criteria |= EHS_WAKE_ON_UNICAST_DATA;
  83. if (wol->wolopts & WAKE_MCAST)
  84. criteria |= EHS_WAKE_ON_MULTICAST_DATA;
  85. if (wol->wolopts & WAKE_BCAST)
  86. criteria |= EHS_WAKE_ON_BROADCAST_DATA;
  87. if (wol->wolopts & WAKE_PHY)
  88. criteria |= EHS_WAKE_ON_MAC_EVENT;
  89. if (wol->wolopts == 0)
  90. criteria |= EHS_REMOVE_WAKEUP;
  91. return lbs_host_sleep_cfg(priv, criteria, (struct wol_config *)NULL);
  92. }
  93. const struct ethtool_ops lbs_ethtool_ops = {
  94. .get_drvinfo = lbs_ethtool_get_drvinfo,
  95. .get_eeprom = lbs_ethtool_get_eeprom,
  96. .get_eeprom_len = lbs_ethtool_get_eeprom_len,
  97. .get_sset_count = lbs_mesh_ethtool_get_sset_count,
  98. .get_ethtool_stats = lbs_mesh_ethtool_get_stats,
  99. .get_strings = lbs_mesh_ethtool_get_strings,
  100. .get_wol = lbs_ethtool_get_wol,
  101. .set_wol = lbs_ethtool_set_wol,
  102. };