ethtool.c 3.2 KB

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