ethtool.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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 =
  53. (char *)kmalloc(eeprom->len+sizeof(regctrl), GFP_KERNEL);
  54. if (!adapter->prdeeprom)
  55. return -ENOMEM;
  56. memcpy(adapter->prdeeprom, &regctrl, sizeof(regctrl));
  57. /* +14 is for action, offset, and NOB in
  58. * response */
  59. lbs_deb_ethtool("action:%d offset: %x NOB: %02x\n",
  60. regctrl.action, regctrl.offset, regctrl.NOB);
  61. ret = libertas_prepare_and_send_command(priv,
  62. cmd_802_11_eeprom_access,
  63. regctrl.action,
  64. cmd_option_waitforrsp, 0,
  65. &regctrl);
  66. if (ret) {
  67. if (adapter->prdeeprom)
  68. kfree(adapter->prdeeprom);
  69. goto done;
  70. }
  71. mdelay(10);
  72. ptr = (char *)adapter->prdeeprom;
  73. /* skip the command header, but include the "value" u32 variable */
  74. ptr = ptr + sizeof(struct wlan_ioctl_regrdwr) - 4;
  75. /*
  76. * Return the result back to the user
  77. */
  78. memcpy(bytes, ptr, eeprom->len);
  79. if (adapter->prdeeprom)
  80. kfree(adapter->prdeeprom);
  81. // mutex_unlock(&priv->mutex);
  82. ret = 0;
  83. done:
  84. lbs_deb_enter_args(LBS_DEB_ETHTOOL, "ret %d", ret);
  85. return ret;
  86. }
  87. static void libertas_ethtool_get_stats(struct net_device * dev,
  88. struct ethtool_stats * stats, u64 * data)
  89. {
  90. wlan_private *priv = dev->priv;
  91. lbs_deb_enter(LBS_DEB_ETHTOOL);
  92. stats->cmd = ETHTOOL_GSTATS;
  93. BUG_ON(stats->n_stats != MESH_STATS_NUM);
  94. data[0] = priv->mstats.fwd_drop_rbt;
  95. data[1] = priv->mstats.fwd_drop_ttl;
  96. data[2] = priv->mstats.fwd_drop_noroute;
  97. data[3] = priv->mstats.fwd_drop_nobuf;
  98. data[4] = priv->mstats.fwd_unicast_cnt;
  99. data[5] = priv->mstats.fwd_bcast_cnt;
  100. data[6] = priv->mstats.drop_blind;
  101. data[7] = priv->mstats.tx_failed_cnt;
  102. lbs_deb_enter(LBS_DEB_ETHTOOL);
  103. }
  104. static int libertas_ethtool_get_stats_count(struct net_device * dev)
  105. {
  106. int ret;
  107. wlan_private *priv = dev->priv;
  108. struct cmd_ds_mesh_access mesh_access;
  109. lbs_deb_enter(LBS_DEB_ETHTOOL);
  110. /* Get Mesh Statistics */
  111. ret = libertas_prepare_and_send_command(priv,
  112. cmd_mesh_access, cmd_act_mesh_get_stats,
  113. cmd_option_waitforrsp, 0, &mesh_access);
  114. if (ret) {
  115. ret = 0;
  116. goto done;
  117. }
  118. priv->mstats.fwd_drop_rbt = le32_to_cpu(mesh_access.data[0]);
  119. priv->mstats.fwd_drop_ttl = le32_to_cpu(mesh_access.data[1]);
  120. priv->mstats.fwd_drop_noroute = le32_to_cpu(mesh_access.data[2]);
  121. priv->mstats.fwd_drop_nobuf = le32_to_cpu(mesh_access.data[3]);
  122. priv->mstats.fwd_unicast_cnt = le32_to_cpu(mesh_access.data[4]);
  123. priv->mstats.fwd_bcast_cnt = le32_to_cpu(mesh_access.data[5]);
  124. priv->mstats.drop_blind = le32_to_cpu(mesh_access.data[6]);
  125. priv->mstats.tx_failed_cnt = le32_to_cpu(mesh_access.data[7]);
  126. ret = MESH_STATS_NUM;
  127. done:
  128. lbs_deb_enter_args(LBS_DEB_ETHTOOL, "ret %d", ret);
  129. return ret;
  130. }
  131. static void libertas_ethtool_get_strings (struct net_device * dev,
  132. u32 stringset,
  133. u8 * s)
  134. {
  135. int i;
  136. lbs_deb_enter(LBS_DEB_ETHTOOL);
  137. switch (stringset) {
  138. case ETH_SS_STATS:
  139. for (i=0; i < MESH_STATS_NUM; i++) {
  140. memcpy(s + i * ETH_GSTRING_LEN,
  141. mesh_stat_strings[i],
  142. ETH_GSTRING_LEN);
  143. }
  144. break;
  145. }
  146. lbs_deb_enter(LBS_DEB_ETHTOOL);
  147. }
  148. struct ethtool_ops libertas_ethtool_ops = {
  149. .get_drvinfo = libertas_ethtool_get_drvinfo,
  150. .get_eeprom = libertas_ethtool_get_eeprom,
  151. .get_eeprom_len = libertas_ethtool_get_eeprom_len,
  152. .get_stats_count = libertas_ethtool_get_stats_count,
  153. .get_ethtool_stats = libertas_ethtool_get_stats,
  154. .get_strings = libertas_ethtool_get_strings,
  155. };