ethtool.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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 lbs_ioctl_regrdwr regctrl;
  44. char *ptr;
  45. int ret;
  46. regctrl.action = 0;
  47. regctrl.offset = eeprom->offset;
  48. regctrl.NOB = eeprom->len;
  49. if (eeprom->offset + eeprom->len > LBS_EEPROM_LEN)
  50. return -EINVAL;
  51. // mutex_lock(&priv->mutex);
  52. priv->prdeeprom = kmalloc(eeprom->len+sizeof(regctrl), GFP_KERNEL);
  53. if (!priv->prdeeprom)
  54. return -ENOMEM;
  55. memcpy(priv->prdeeprom, &regctrl, sizeof(regctrl));
  56. /* +14 is for action, offset, and NOB in
  57. * response */
  58. lbs_deb_ethtool("action:%d offset: %x NOB: %02x\n",
  59. regctrl.action, regctrl.offset, regctrl.NOB);
  60. ret = lbs_prepare_and_send_command(priv,
  61. CMD_802_11_EEPROM_ACCESS,
  62. regctrl.action,
  63. CMD_OPTION_WAITFORRSP, 0,
  64. &regctrl);
  65. if (ret) {
  66. if (priv->prdeeprom)
  67. kfree(priv->prdeeprom);
  68. goto done;
  69. }
  70. mdelay(10);
  71. ptr = (char *)priv->prdeeprom;
  72. /* skip the command header, but include the "value" u32 variable */
  73. ptr = ptr + sizeof(struct lbs_ioctl_regrdwr) - 4;
  74. /*
  75. * Return the result back to the user
  76. */
  77. memcpy(bytes, ptr, eeprom->len);
  78. if (priv->prdeeprom)
  79. kfree(priv->prdeeprom);
  80. // mutex_unlock(&priv->mutex);
  81. ret = 0;
  82. done:
  83. lbs_deb_enter_args(LBS_DEB_ETHTOOL, "ret %d", ret);
  84. return ret;
  85. }
  86. static void lbs_ethtool_get_stats(struct net_device * dev,
  87. struct ethtool_stats * stats, u64 * data)
  88. {
  89. struct lbs_private *priv = dev->priv;
  90. struct cmd_ds_mesh_access mesh_access;
  91. int ret;
  92. lbs_deb_enter(LBS_DEB_ETHTOOL);
  93. /* Get Mesh Statistics */
  94. ret = lbs_prepare_and_send_command(priv,
  95. CMD_MESH_ACCESS, CMD_ACT_MESH_GET_STATS,
  96. CMD_OPTION_WAITFORRSP, 0, &mesh_access);
  97. if (ret)
  98. return;
  99. priv->mstats.fwd_drop_rbt = le32_to_cpu(mesh_access.data[0]);
  100. priv->mstats.fwd_drop_ttl = le32_to_cpu(mesh_access.data[1]);
  101. priv->mstats.fwd_drop_noroute = le32_to_cpu(mesh_access.data[2]);
  102. priv->mstats.fwd_drop_nobuf = le32_to_cpu(mesh_access.data[3]);
  103. priv->mstats.fwd_unicast_cnt = le32_to_cpu(mesh_access.data[4]);
  104. priv->mstats.fwd_bcast_cnt = le32_to_cpu(mesh_access.data[5]);
  105. priv->mstats.drop_blind = le32_to_cpu(mesh_access.data[6]);
  106. priv->mstats.tx_failed_cnt = le32_to_cpu(mesh_access.data[7]);
  107. data[0] = priv->mstats.fwd_drop_rbt;
  108. data[1] = priv->mstats.fwd_drop_ttl;
  109. data[2] = priv->mstats.fwd_drop_noroute;
  110. data[3] = priv->mstats.fwd_drop_nobuf;
  111. data[4] = priv->mstats.fwd_unicast_cnt;
  112. data[5] = priv->mstats.fwd_bcast_cnt;
  113. data[6] = priv->mstats.drop_blind;
  114. data[7] = priv->mstats.tx_failed_cnt;
  115. lbs_deb_enter(LBS_DEB_ETHTOOL);
  116. }
  117. static int lbs_ethtool_get_sset_count(struct net_device * dev, int sset)
  118. {
  119. switch (sset) {
  120. case ETH_SS_STATS:
  121. return MESH_STATS_NUM;
  122. default:
  123. return -EOPNOTSUPP;
  124. }
  125. }
  126. static void lbs_ethtool_get_strings(struct net_device *dev,
  127. u32 stringset,
  128. u8 * s)
  129. {
  130. int i;
  131. lbs_deb_enter(LBS_DEB_ETHTOOL);
  132. switch (stringset) {
  133. case ETH_SS_STATS:
  134. for (i=0; i < MESH_STATS_NUM; i++) {
  135. memcpy(s + i * ETH_GSTRING_LEN,
  136. mesh_stat_strings[i],
  137. ETH_GSTRING_LEN);
  138. }
  139. break;
  140. }
  141. lbs_deb_enter(LBS_DEB_ETHTOOL);
  142. }
  143. static void lbs_ethtool_get_wol(struct net_device *dev,
  144. struct ethtool_wolinfo *wol)
  145. {
  146. struct lbs_private *priv = dev->priv;
  147. if (priv->wol_criteria == 0xffffffff) {
  148. /* Interface driver didn't configure wake */
  149. wol->supported = wol->wolopts = 0;
  150. return;
  151. }
  152. wol->supported = WAKE_UCAST|WAKE_MCAST|WAKE_BCAST|WAKE_PHY;
  153. if (priv->wol_criteria & EHS_WAKE_ON_UNICAST_DATA)
  154. wol->wolopts |= WAKE_UCAST;
  155. if (priv->wol_criteria & EHS_WAKE_ON_MULTICAST_DATA)
  156. wol->wolopts |= WAKE_MCAST;
  157. if (priv->wol_criteria & EHS_WAKE_ON_BROADCAST_DATA)
  158. wol->wolopts |= WAKE_BCAST;
  159. if (priv->wol_criteria & EHS_WAKE_ON_MAC_EVENT)
  160. wol->wolopts |= WAKE_PHY;
  161. }
  162. static int lbs_ethtool_set_wol(struct net_device *dev,
  163. struct ethtool_wolinfo *wol)
  164. {
  165. struct lbs_private *priv = dev->priv;
  166. uint32_t criteria = 0;
  167. if (priv->wol_criteria == 0xffffffff && wol->wolopts)
  168. return -EOPNOTSUPP;
  169. if (wol->wolopts & ~(WAKE_UCAST|WAKE_MCAST|WAKE_BCAST|WAKE_PHY))
  170. return -EOPNOTSUPP;
  171. if (wol->wolopts & WAKE_UCAST) criteria |= EHS_WAKE_ON_UNICAST_DATA;
  172. if (wol->wolopts & WAKE_MCAST) criteria |= EHS_WAKE_ON_MULTICAST_DATA;
  173. if (wol->wolopts & WAKE_BCAST) criteria |= EHS_WAKE_ON_BROADCAST_DATA;
  174. if (wol->wolopts & WAKE_PHY) criteria |= EHS_WAKE_ON_MAC_EVENT;
  175. return lbs_host_sleep_cfg(priv, criteria);
  176. }
  177. struct ethtool_ops lbs_ethtool_ops = {
  178. .get_drvinfo = lbs_ethtool_get_drvinfo,
  179. .get_eeprom = lbs_ethtool_get_eeprom,
  180. .get_eeprom_len = lbs_ethtool_get_eeprom_len,
  181. .get_sset_count = lbs_ethtool_get_sset_count,
  182. .get_ethtool_stats = lbs_ethtool_get_stats,
  183. .get_strings = lbs_ethtool_get_strings,
  184. .get_wol = lbs_ethtool_get_wol,
  185. .set_wol = lbs_ethtool_set_wol,
  186. };