ethtool.c 3.3 KB

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