ethtool.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. #include <linux/netdevice.h>
  2. #include <linux/ethtool.h>
  3. #include <linux/delay.h>
  4. #include "host.h"
  5. #include "sbi.h"
  6. #include "decl.h"
  7. #include "defs.h"
  8. #include "dev.h"
  9. #include "join.h"
  10. #include "wext.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. };
  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_pr_debug(1, "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. LEAVE();
  70. return ret;
  71. }
  72. mdelay(10);
  73. ptr = (char *)adapter->prdeeprom;
  74. /* skip the command header, but include the "value" u32 variable */
  75. ptr = ptr + sizeof(struct wlan_ioctl_regrdwr) - 4;
  76. /*
  77. * Return the result back to the user
  78. */
  79. memcpy(bytes, ptr, eeprom->len);
  80. if (adapter->prdeeprom)
  81. kfree(adapter->prdeeprom);
  82. // mutex_unlock(&priv->mutex);
  83. return 0;
  84. }
  85. static void libertas_ethtool_get_stats(struct net_device * dev,
  86. struct ethtool_stats * stats, u64 * data)
  87. {
  88. wlan_private *priv = dev->priv;
  89. ENTER();
  90. stats->cmd = ETHTOOL_GSTATS;
  91. BUG_ON(stats->n_stats != MESH_STATS_NUM);
  92. data[0] = priv->mstats.fwd_drop_rbt;
  93. data[1] = priv->mstats.fwd_drop_ttl;
  94. data[2] = priv->mstats.fwd_drop_noroute;
  95. data[3] = priv->mstats.fwd_drop_nobuf;
  96. data[4] = priv->mstats.fwd_unicast_cnt;
  97. data[5] = priv->mstats.fwd_bcast_cnt;
  98. data[6] = priv->mstats.drop_blind;
  99. LEAVE();
  100. }
  101. static int libertas_ethtool_get_stats_count(struct net_device * dev)
  102. {
  103. int ret;
  104. wlan_private *priv = dev->priv;
  105. struct cmd_ds_mesh_access mesh_access;
  106. ENTER();
  107. /* Get Mesh Statistics */
  108. ret = libertas_prepare_and_send_command(priv,
  109. cmd_mesh_access, cmd_act_mesh_get_stats,
  110. cmd_option_waitforrsp, 0, &mesh_access);
  111. if (ret) {
  112. LEAVE();
  113. return 0;
  114. }
  115. priv->mstats.fwd_drop_rbt = mesh_access.data[0];
  116. priv->mstats.fwd_drop_ttl = mesh_access.data[1];
  117. priv->mstats.fwd_drop_noroute = mesh_access.data[2];
  118. priv->mstats.fwd_drop_nobuf = mesh_access.data[3];
  119. priv->mstats.fwd_unicast_cnt = mesh_access.data[4];
  120. priv->mstats.fwd_bcast_cnt = mesh_access.data[5];
  121. priv->mstats.drop_blind = mesh_access.data[6];
  122. LEAVE();
  123. return MESH_STATS_NUM;
  124. }
  125. static void libertas_ethtool_get_strings (struct net_device * dev,
  126. u32 stringset,
  127. u8 * s)
  128. {
  129. int i;
  130. ENTER();
  131. switch (stringset) {
  132. case ETH_SS_STATS:
  133. for (i=0; i < MESH_STATS_NUM; i++) {
  134. memcpy(s + i * ETH_GSTRING_LEN,
  135. mesh_stat_strings[i],
  136. ETH_GSTRING_LEN);
  137. }
  138. break;
  139. }
  140. LEAVE();
  141. }
  142. struct ethtool_ops libertas_ethtool_ops = {
  143. .get_drvinfo = libertas_ethtool_get_drvinfo,
  144. .get_eeprom = libertas_ethtool_get_eeprom,
  145. .get_eeprom_len = libertas_ethtool_get_eeprom_len,
  146. .get_stats_count = libertas_ethtool_get_stats_count,
  147. .get_ethtool_stats = libertas_ethtool_get_stats,
  148. .get_strings = libertas_ethtool_get_strings,
  149. };