ethtool.c 3.2 KB

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