ethtool.c 3.2 KB

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