ethtool.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. "tx_failed_cnt"
  20. };
  21. static void libertas_ethtool_get_drvinfo(struct net_device *dev,
  22. struct ethtool_drvinfo *info)
  23. {
  24. wlan_private *priv = (wlan_private *) dev->priv;
  25. char fwver[32];
  26. libertas_get_fwversion(priv->adapter, fwver, sizeof(fwver) - 1);
  27. strcpy(info->driver, "libertas");
  28. strcpy(info->version, libertas_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 LIBERTAS_EEPROM_LEN 16384
  35. static int libertas_ethtool_get_eeprom_len(struct net_device *dev)
  36. {
  37. return LIBERTAS_EEPROM_LEN;
  38. }
  39. static int libertas_ethtool_get_eeprom(struct net_device *dev,
  40. struct ethtool_eeprom *eeprom, u8 * bytes)
  41. {
  42. wlan_private *priv = (wlan_private *) dev->priv;
  43. wlan_adapter *adapter = priv->adapter;
  44. struct wlan_ioctl_regrdwr regctrl;
  45. char *ptr;
  46. int ret;
  47. regctrl.action = 0;
  48. regctrl.offset = eeprom->offset;
  49. regctrl.NOB = eeprom->len;
  50. if (eeprom->offset + eeprom->len > LIBERTAS_EEPROM_LEN)
  51. return -EINVAL;
  52. // mutex_lock(&priv->mutex);
  53. adapter->prdeeprom =
  54. (char *)kmalloc(eeprom->len+sizeof(regctrl), GFP_KERNEL);
  55. if (!adapter->prdeeprom)
  56. return -ENOMEM;
  57. memcpy(adapter->prdeeprom, &regctrl, sizeof(regctrl));
  58. /* +14 is for action, offset, and NOB in
  59. * response */
  60. lbs_deb_ethtool("action:%d offset: %x NOB: %02x\n",
  61. regctrl.action, regctrl.offset, regctrl.NOB);
  62. ret = libertas_prepare_and_send_command(priv,
  63. cmd_802_11_eeprom_access,
  64. regctrl.action,
  65. cmd_option_waitforrsp, 0,
  66. &regctrl);
  67. if (ret) {
  68. if (adapter->prdeeprom)
  69. kfree(adapter->prdeeprom);
  70. goto done;
  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. ret = 0;
  84. done:
  85. lbs_deb_enter_args(LBS_DEB_ETHTOOL, "ret %d", ret);
  86. return ret;
  87. }
  88. static void libertas_ethtool_get_stats(struct net_device * dev,
  89. struct ethtool_stats * stats, u64 * data)
  90. {
  91. wlan_private *priv = dev->priv;
  92. lbs_deb_enter(LBS_DEB_ETHTOOL);
  93. stats->cmd = ETHTOOL_GSTATS;
  94. BUG_ON(stats->n_stats != MESH_STATS_NUM);
  95. data[0] = priv->mstats.fwd_drop_rbt;
  96. data[1] = priv->mstats.fwd_drop_ttl;
  97. data[2] = priv->mstats.fwd_drop_noroute;
  98. data[3] = priv->mstats.fwd_drop_nobuf;
  99. data[4] = priv->mstats.fwd_unicast_cnt;
  100. data[5] = priv->mstats.fwd_bcast_cnt;
  101. data[6] = priv->mstats.drop_blind;
  102. data[7] = priv->mstats.tx_failed_cnt;
  103. lbs_deb_enter(LBS_DEB_ETHTOOL);
  104. }
  105. static int libertas_ethtool_get_stats_count(struct net_device * dev)
  106. {
  107. int ret;
  108. wlan_private *priv = dev->priv;
  109. struct cmd_ds_mesh_access mesh_access;
  110. lbs_deb_enter(LBS_DEB_ETHTOOL);
  111. /* Get Mesh Statistics */
  112. ret = libertas_prepare_and_send_command(priv,
  113. cmd_mesh_access, cmd_act_mesh_get_stats,
  114. cmd_option_waitforrsp, 0, &mesh_access);
  115. if (ret) {
  116. ret = 0;
  117. goto done;
  118. }
  119. priv->mstats.fwd_drop_rbt = mesh_access.data[0];
  120. priv->mstats.fwd_drop_ttl = mesh_access.data[1];
  121. priv->mstats.fwd_drop_noroute = mesh_access.data[2];
  122. priv->mstats.fwd_drop_nobuf = mesh_access.data[3];
  123. priv->mstats.fwd_unicast_cnt = mesh_access.data[4];
  124. priv->mstats.fwd_bcast_cnt = mesh_access.data[5];
  125. priv->mstats.drop_blind = mesh_access.data[6];
  126. priv->mstats.tx_failed_cnt = mesh_access.data[7];
  127. ret = MESH_STATS_NUM;
  128. done:
  129. lbs_deb_enter_args(LBS_DEB_ETHTOOL, "ret %d", ret);
  130. return ret;
  131. }
  132. static void libertas_ethtool_get_strings (struct net_device * dev,
  133. u32 stringset,
  134. u8 * s)
  135. {
  136. int i;
  137. lbs_deb_enter(LBS_DEB_ETHTOOL);
  138. switch (stringset) {
  139. case ETH_SS_STATS:
  140. for (i=0; i < MESH_STATS_NUM; i++) {
  141. memcpy(s + i * ETH_GSTRING_LEN,
  142. mesh_stat_strings[i],
  143. ETH_GSTRING_LEN);
  144. }
  145. break;
  146. }
  147. lbs_deb_enter(LBS_DEB_ETHTOOL);
  148. }
  149. struct ethtool_ops libertas_ethtool_ops = {
  150. .get_drvinfo = libertas_ethtool_get_drvinfo,
  151. .get_eeprom = libertas_ethtool_get_eeprom,
  152. .get_eeprom_len = libertas_ethtool_get_eeprom_len,
  153. .get_stats_count = libertas_ethtool_get_stats_count,
  154. .get_ethtool_stats = libertas_ethtool_get_stats,
  155. .get_strings = libertas_ethtool_get_strings,
  156. };