ethtool.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. #include <linux/netdevice.h>
  2. #include <linux/ethtool.h>
  3. #include <linux/delay.h>
  4. #include "host.h"
  5. #include "decl.h"
  6. #include "defs.h"
  7. #include "dev.h"
  8. #include "join.h"
  9. #include "wext.h"
  10. #include "cmd.h"
  11. static const char * mesh_stat_strings[]= {
  12. "drop_duplicate_bcast",
  13. "drop_ttl_zero",
  14. "drop_no_fwd_route",
  15. "drop_no_buffers",
  16. "fwded_unicast_cnt",
  17. "fwded_bcast_cnt",
  18. "drop_blind_table",
  19. "tx_failed_cnt"
  20. };
  21. static void lbs_ethtool_get_drvinfo(struct net_device *dev,
  22. struct ethtool_drvinfo *info)
  23. {
  24. struct lbs_private *priv = (struct lbs_private *) dev->priv;
  25. char fwver[32];
  26. lbs_get_fwversion(priv, fwver, sizeof(fwver) - 1);
  27. strcpy(info->driver, "libertas");
  28. strcpy(info->version, lbs_driver_version);
  29. strcpy(info->fw_version, fwver);
  30. }
  31. /* All 8388 parts have 16KiB EEPROM size at the time of writing.
  32. * In case that changes this needs fixing.
  33. */
  34. #define LBS_EEPROM_LEN 16384
  35. static int lbs_ethtool_get_eeprom_len(struct net_device *dev)
  36. {
  37. return LBS_EEPROM_LEN;
  38. }
  39. static int lbs_ethtool_get_eeprom(struct net_device *dev,
  40. struct ethtool_eeprom *eeprom, u8 * bytes)
  41. {
  42. struct lbs_private *priv = (struct lbs_private *) dev->priv;
  43. struct cmd_ds_802_11_eeprom_access cmd;
  44. int ret;
  45. lbs_deb_enter(LBS_DEB_ETHTOOL);
  46. if (eeprom->offset + eeprom->len > LBS_EEPROM_LEN ||
  47. eeprom->len > LBS_EEPROM_READ_LEN) {
  48. ret = -EINVAL;
  49. goto out;
  50. }
  51. cmd.hdr.size = cpu_to_le16(sizeof(struct cmd_ds_802_11_eeprom_access) -
  52. LBS_EEPROM_READ_LEN + eeprom->len);
  53. cmd.action = cpu_to_le16(CMD_ACT_GET);
  54. cmd.offset = cpu_to_le16(eeprom->offset);
  55. cmd.len = cpu_to_le16(eeprom->len);
  56. ret = lbs_cmd_with_response(priv, CMD_802_11_EEPROM_ACCESS, &cmd);
  57. if (!ret)
  58. memcpy(bytes, cmd.value, eeprom->len);
  59. out:
  60. lbs_deb_leave_args(LBS_DEB_ETHTOOL, "ret %d", ret);
  61. return ret;
  62. }
  63. static void lbs_ethtool_get_stats(struct net_device * dev,
  64. struct ethtool_stats * stats, u64 * data)
  65. {
  66. struct lbs_private *priv = dev->priv;
  67. struct cmd_ds_mesh_access mesh_access;
  68. int ret;
  69. lbs_deb_enter(LBS_DEB_ETHTOOL);
  70. /* Get Mesh Statistics */
  71. ret = lbs_prepare_and_send_command(priv,
  72. CMD_MESH_ACCESS, CMD_ACT_MESH_GET_STATS,
  73. CMD_OPTION_WAITFORRSP, 0, &mesh_access);
  74. if (ret)
  75. return;
  76. priv->mstats.fwd_drop_rbt = le32_to_cpu(mesh_access.data[0]);
  77. priv->mstats.fwd_drop_ttl = le32_to_cpu(mesh_access.data[1]);
  78. priv->mstats.fwd_drop_noroute = le32_to_cpu(mesh_access.data[2]);
  79. priv->mstats.fwd_drop_nobuf = le32_to_cpu(mesh_access.data[3]);
  80. priv->mstats.fwd_unicast_cnt = le32_to_cpu(mesh_access.data[4]);
  81. priv->mstats.fwd_bcast_cnt = le32_to_cpu(mesh_access.data[5]);
  82. priv->mstats.drop_blind = le32_to_cpu(mesh_access.data[6]);
  83. priv->mstats.tx_failed_cnt = le32_to_cpu(mesh_access.data[7]);
  84. data[0] = priv->mstats.fwd_drop_rbt;
  85. data[1] = priv->mstats.fwd_drop_ttl;
  86. data[2] = priv->mstats.fwd_drop_noroute;
  87. data[3] = priv->mstats.fwd_drop_nobuf;
  88. data[4] = priv->mstats.fwd_unicast_cnt;
  89. data[5] = priv->mstats.fwd_bcast_cnt;
  90. data[6] = priv->mstats.drop_blind;
  91. data[7] = priv->mstats.tx_failed_cnt;
  92. lbs_deb_enter(LBS_DEB_ETHTOOL);
  93. }
  94. static int lbs_ethtool_get_sset_count(struct net_device * dev, int sset)
  95. {
  96. switch (sset) {
  97. case ETH_SS_STATS:
  98. return MESH_STATS_NUM;
  99. default:
  100. return -EOPNOTSUPP;
  101. }
  102. }
  103. static void lbs_ethtool_get_strings(struct net_device *dev,
  104. u32 stringset,
  105. u8 * s)
  106. {
  107. int i;
  108. lbs_deb_enter(LBS_DEB_ETHTOOL);
  109. switch (stringset) {
  110. case ETH_SS_STATS:
  111. for (i=0; i < MESH_STATS_NUM; i++) {
  112. memcpy(s + i * ETH_GSTRING_LEN,
  113. mesh_stat_strings[i],
  114. ETH_GSTRING_LEN);
  115. }
  116. break;
  117. }
  118. lbs_deb_enter(LBS_DEB_ETHTOOL);
  119. }
  120. static void lbs_ethtool_get_wol(struct net_device *dev,
  121. struct ethtool_wolinfo *wol)
  122. {
  123. struct lbs_private *priv = dev->priv;
  124. if (priv->wol_criteria == 0xffffffff) {
  125. /* Interface driver didn't configure wake */
  126. wol->supported = wol->wolopts = 0;
  127. return;
  128. }
  129. wol->supported = WAKE_UCAST|WAKE_MCAST|WAKE_BCAST|WAKE_PHY;
  130. if (priv->wol_criteria & EHS_WAKE_ON_UNICAST_DATA)
  131. wol->wolopts |= WAKE_UCAST;
  132. if (priv->wol_criteria & EHS_WAKE_ON_MULTICAST_DATA)
  133. wol->wolopts |= WAKE_MCAST;
  134. if (priv->wol_criteria & EHS_WAKE_ON_BROADCAST_DATA)
  135. wol->wolopts |= WAKE_BCAST;
  136. if (priv->wol_criteria & EHS_WAKE_ON_MAC_EVENT)
  137. wol->wolopts |= WAKE_PHY;
  138. }
  139. static int lbs_ethtool_set_wol(struct net_device *dev,
  140. struct ethtool_wolinfo *wol)
  141. {
  142. struct lbs_private *priv = dev->priv;
  143. uint32_t criteria = 0;
  144. if (priv->wol_criteria == 0xffffffff && wol->wolopts)
  145. return -EOPNOTSUPP;
  146. if (wol->wolopts & ~(WAKE_UCAST|WAKE_MCAST|WAKE_BCAST|WAKE_PHY))
  147. return -EOPNOTSUPP;
  148. if (wol->wolopts & WAKE_UCAST) criteria |= EHS_WAKE_ON_UNICAST_DATA;
  149. if (wol->wolopts & WAKE_MCAST) criteria |= EHS_WAKE_ON_MULTICAST_DATA;
  150. if (wol->wolopts & WAKE_BCAST) criteria |= EHS_WAKE_ON_BROADCAST_DATA;
  151. if (wol->wolopts & WAKE_PHY) criteria |= EHS_WAKE_ON_MAC_EVENT;
  152. return lbs_host_sleep_cfg(priv, criteria);
  153. }
  154. struct ethtool_ops lbs_ethtool_ops = {
  155. .get_drvinfo = lbs_ethtool_get_drvinfo,
  156. .get_eeprom = lbs_ethtool_get_eeprom,
  157. .get_eeprom_len = lbs_ethtool_get_eeprom_len,
  158. .get_sset_count = lbs_ethtool_get_sset_count,
  159. .get_ethtool_stats = lbs_ethtool_get_stats,
  160. .get_strings = lbs_ethtool_get_strings,
  161. .get_wol = lbs_ethtool_get_wol,
  162. .set_wol = lbs_ethtool_set_wol,
  163. };