ethtool.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/hardirq.h>
  3. #include <linux/netdevice.h>
  4. #include <linux/ethtool.h>
  5. #include <linux/delay.h>
  6. #include "decl.h"
  7. #include "cmd.h"
  8. #include "mesh.h"
  9. static void lbs_ethtool_get_drvinfo(struct net_device *dev,
  10. struct ethtool_drvinfo *info)
  11. {
  12. struct lbs_private *priv = dev->ml_priv;
  13. snprintf(info->fw_version, sizeof(info->fw_version),
  14. "%u.%u.%u.p%u",
  15. priv->fwrelease >> 24 & 0xff,
  16. priv->fwrelease >> 16 & 0xff,
  17. priv->fwrelease >> 8 & 0xff,
  18. priv->fwrelease & 0xff);
  19. strscpy(info->driver, "libertas", sizeof(info->driver));
  20. strscpy(info->version, lbs_driver_version, sizeof(info->version));
  21. }
  22. /*
  23. * All 8388 parts have 16KiB EEPROM size at the time of writing.
  24. * In case that changes this needs fixing.
  25. */
  26. #define LBS_EEPROM_LEN 16384
  27. static int lbs_ethtool_get_eeprom_len(struct net_device *dev)
  28. {
  29. return LBS_EEPROM_LEN;
  30. }
  31. static int lbs_ethtool_get_eeprom(struct net_device *dev,
  32. struct ethtool_eeprom *eeprom, u8 * bytes)
  33. {
  34. struct lbs_private *priv = dev->ml_priv;
  35. struct cmd_ds_802_11_eeprom_access cmd;
  36. int ret;
  37. if (eeprom->offset + eeprom->len > LBS_EEPROM_LEN ||
  38. eeprom->len > LBS_EEPROM_READ_LEN)
  39. return -EINVAL;
  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. 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. };