ethtool.c 3.2 KB

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