ethtool.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. static const char * mesh_stat_strings[]= {
  11. "drop_duplicate_bcast",
  12. "drop_ttl_zero",
  13. "drop_no_fwd_route",
  14. "drop_no_buffers",
  15. "fwded_unicast_cnt",
  16. "fwded_bcast_cnt",
  17. "drop_blind_table",
  18. "tx_failed_cnt"
  19. };
  20. static void libertas_ethtool_get_drvinfo(struct net_device *dev,
  21. struct ethtool_drvinfo *info)
  22. {
  23. wlan_private *priv = (wlan_private *) dev->priv;
  24. char fwver[32];
  25. libertas_get_fwversion(priv->adapter, fwver, sizeof(fwver) - 1);
  26. strcpy(info->driver, "libertas");
  27. strcpy(info->version, libertas_driver_version);
  28. strcpy(info->fw_version, fwver);
  29. }
  30. /* All 8388 parts have 16KiB EEPROM size at the time of writing.
  31. * In case that changes this needs fixing.
  32. */
  33. #define LIBERTAS_EEPROM_LEN 16384
  34. static int libertas_ethtool_get_eeprom_len(struct net_device *dev)
  35. {
  36. return LIBERTAS_EEPROM_LEN;
  37. }
  38. static int libertas_ethtool_get_eeprom(struct net_device *dev,
  39. struct ethtool_eeprom *eeprom, u8 * bytes)
  40. {
  41. wlan_private *priv = (wlan_private *) dev->priv;
  42. wlan_adapter *adapter = priv->adapter;
  43. struct wlan_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 > LIBERTAS_EEPROM_LEN)
  50. return -EINVAL;
  51. // mutex_lock(&priv->mutex);
  52. adapter->prdeeprom = kmalloc(eeprom->len+sizeof(regctrl), GFP_KERNEL);
  53. if (!adapter->prdeeprom)
  54. return -ENOMEM;
  55. memcpy(adapter->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 = libertas_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 (adapter->prdeeprom)
  67. kfree(adapter->prdeeprom);
  68. goto done;
  69. }
  70. mdelay(10);
  71. ptr = (char *)adapter->prdeeprom;
  72. /* skip the command header, but include the "value" u32 variable */
  73. ptr = ptr + sizeof(struct wlan_ioctl_regrdwr) - 4;
  74. /*
  75. * Return the result back to the user
  76. */
  77. memcpy(bytes, ptr, eeprom->len);
  78. if (adapter->prdeeprom)
  79. kfree(adapter->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 libertas_ethtool_get_stats(struct net_device * dev,
  87. struct ethtool_stats * stats, u64 * data)
  88. {
  89. wlan_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 = libertas_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 libertas_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 libertas_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. struct ethtool_ops libertas_ethtool_ops = {
  144. .get_drvinfo = libertas_ethtool_get_drvinfo,
  145. .get_eeprom = libertas_ethtool_get_eeprom,
  146. .get_eeprom_len = libertas_ethtool_get_eeprom_len,
  147. .get_sset_count = libertas_ethtool_get_sset_count,
  148. .get_ethtool_stats = libertas_ethtool_get_stats,
  149. .get_strings = libertas_ethtool_get_strings,
  150. };