ethtool.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /*
  2. * mac80211 ethtool hooks for cfg80211
  3. *
  4. * Copied from cfg.c - originally
  5. * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
  6. * Copyright 2014 Intel Corporation (Author: Johannes Berg)
  7. *
  8. * This file is GPLv2 as found in COPYING.
  9. */
  10. #include <linux/types.h>
  11. #include <net/cfg80211.h>
  12. #include "ieee80211_i.h"
  13. #include "sta_info.h"
  14. #include "driver-ops.h"
  15. static int ieee80211_set_ringparam(struct net_device *dev,
  16. struct ethtool_ringparam *rp)
  17. {
  18. struct ieee80211_local *local = wiphy_priv(dev->ieee80211_ptr->wiphy);
  19. if (rp->rx_mini_pending != 0 || rp->rx_jumbo_pending != 0)
  20. return -EINVAL;
  21. return drv_set_ringparam(local, rp->tx_pending, rp->rx_pending);
  22. }
  23. static void ieee80211_get_ringparam(struct net_device *dev,
  24. struct ethtool_ringparam *rp)
  25. {
  26. struct ieee80211_local *local = wiphy_priv(dev->ieee80211_ptr->wiphy);
  27. memset(rp, 0, sizeof(*rp));
  28. drv_get_ringparam(local, &rp->tx_pending, &rp->tx_max_pending,
  29. &rp->rx_pending, &rp->rx_max_pending);
  30. }
  31. static const char ieee80211_gstrings_sta_stats[][ETH_GSTRING_LEN] = {
  32. "rx_packets", "rx_bytes",
  33. "rx_duplicates", "rx_fragments", "rx_dropped",
  34. "tx_packets", "tx_bytes", "tx_fragments",
  35. "tx_filtered", "tx_retry_failed", "tx_retries",
  36. "beacon_loss", "sta_state", "txrate", "rxrate", "signal",
  37. "channel", "noise", "ch_time", "ch_time_busy",
  38. "ch_time_ext_busy", "ch_time_rx", "ch_time_tx"
  39. };
  40. #define STA_STATS_LEN ARRAY_SIZE(ieee80211_gstrings_sta_stats)
  41. static int ieee80211_get_sset_count(struct net_device *dev, int sset)
  42. {
  43. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  44. int rv = 0;
  45. if (sset == ETH_SS_STATS)
  46. rv += STA_STATS_LEN;
  47. rv += drv_get_et_sset_count(sdata, sset);
  48. if (rv == 0)
  49. return -EOPNOTSUPP;
  50. return rv;
  51. }
  52. static void ieee80211_get_stats(struct net_device *dev,
  53. struct ethtool_stats *stats,
  54. u64 *data)
  55. {
  56. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  57. struct ieee80211_chanctx_conf *chanctx_conf;
  58. struct ieee80211_channel *channel;
  59. struct sta_info *sta;
  60. struct ieee80211_local *local = sdata->local;
  61. struct station_info sinfo;
  62. struct survey_info survey;
  63. int i, q;
  64. #define STA_STATS_SURVEY_LEN 7
  65. memset(data, 0, sizeof(u64) * STA_STATS_LEN);
  66. #define ADD_STA_STATS(sta) \
  67. do { \
  68. data[i++] += sta->rx_packets; \
  69. data[i++] += sta->rx_bytes; \
  70. data[i++] += sta->num_duplicates; \
  71. data[i++] += sta->rx_fragments; \
  72. data[i++] += sta->rx_dropped; \
  73. \
  74. data[i++] += sinfo.tx_packets; \
  75. data[i++] += sinfo.tx_bytes; \
  76. data[i++] += sta->tx_fragments; \
  77. data[i++] += sta->tx_filtered_count; \
  78. data[i++] += sta->tx_retry_failed; \
  79. data[i++] += sta->tx_retry_count; \
  80. data[i++] += sta->beacon_loss_count; \
  81. } while (0)
  82. /* For Managed stations, find the single station based on BSSID
  83. * and use that. For interface types, iterate through all available
  84. * stations and add stats for any station that is assigned to this
  85. * network device.
  86. */
  87. mutex_lock(&local->sta_mtx);
  88. if (sdata->vif.type == NL80211_IFTYPE_STATION) {
  89. sta = sta_info_get_bss(sdata, sdata->u.mgd.bssid);
  90. if (!(sta && !WARN_ON(sta->sdata->dev != dev)))
  91. goto do_survey;
  92. sinfo.filled = 0;
  93. sta_set_sinfo(sta, &sinfo);
  94. i = 0;
  95. ADD_STA_STATS(sta);
  96. data[i++] = sta->sta_state;
  97. if (sinfo.filled & BIT(NL80211_STA_INFO_TX_BITRATE))
  98. data[i] = 100000 *
  99. cfg80211_calculate_bitrate(&sinfo.txrate);
  100. i++;
  101. if (sinfo.filled & BIT(NL80211_STA_INFO_RX_BITRATE))
  102. data[i] = 100000 *
  103. cfg80211_calculate_bitrate(&sinfo.rxrate);
  104. i++;
  105. if (sinfo.filled & BIT(NL80211_STA_INFO_SIGNAL_AVG))
  106. data[i] = (u8)sinfo.signal_avg;
  107. i++;
  108. } else {
  109. list_for_each_entry(sta, &local->sta_list, list) {
  110. /* Make sure this station belongs to the proper dev */
  111. if (sta->sdata->dev != dev)
  112. continue;
  113. sinfo.filled = 0;
  114. sta_set_sinfo(sta, &sinfo);
  115. i = 0;
  116. ADD_STA_STATS(sta);
  117. }
  118. }
  119. do_survey:
  120. i = STA_STATS_LEN - STA_STATS_SURVEY_LEN;
  121. /* Get survey stats for current channel */
  122. survey.filled = 0;
  123. rcu_read_lock();
  124. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  125. if (chanctx_conf)
  126. channel = chanctx_conf->def.chan;
  127. else
  128. channel = NULL;
  129. rcu_read_unlock();
  130. if (channel) {
  131. q = 0;
  132. do {
  133. survey.filled = 0;
  134. if (drv_get_survey(local, q, &survey) != 0) {
  135. survey.filled = 0;
  136. break;
  137. }
  138. q++;
  139. } while (channel != survey.channel);
  140. }
  141. if (survey.filled)
  142. data[i++] = survey.channel->center_freq;
  143. else
  144. data[i++] = 0;
  145. if (survey.filled & SURVEY_INFO_NOISE_DBM)
  146. data[i++] = (u8)survey.noise;
  147. else
  148. data[i++] = -1LL;
  149. if (survey.filled & SURVEY_INFO_TIME)
  150. data[i++] = survey.time;
  151. else
  152. data[i++] = -1LL;
  153. if (survey.filled & SURVEY_INFO_TIME_BUSY)
  154. data[i++] = survey.time_busy;
  155. else
  156. data[i++] = -1LL;
  157. if (survey.filled & SURVEY_INFO_TIME_EXT_BUSY)
  158. data[i++] = survey.time_ext_busy;
  159. else
  160. data[i++] = -1LL;
  161. if (survey.filled & SURVEY_INFO_TIME_RX)
  162. data[i++] = survey.time_rx;
  163. else
  164. data[i++] = -1LL;
  165. if (survey.filled & SURVEY_INFO_TIME_TX)
  166. data[i++] = survey.time_tx;
  167. else
  168. data[i++] = -1LL;
  169. mutex_unlock(&local->sta_mtx);
  170. if (WARN_ON(i != STA_STATS_LEN))
  171. return;
  172. drv_get_et_stats(sdata, stats, &(data[STA_STATS_LEN]));
  173. }
  174. static void ieee80211_get_strings(struct net_device *dev, u32 sset, u8 *data)
  175. {
  176. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  177. int sz_sta_stats = 0;
  178. if (sset == ETH_SS_STATS) {
  179. sz_sta_stats = sizeof(ieee80211_gstrings_sta_stats);
  180. memcpy(data, ieee80211_gstrings_sta_stats, sz_sta_stats);
  181. }
  182. drv_get_et_strings(sdata, sset, &(data[sz_sta_stats]));
  183. }
  184. static int ieee80211_get_regs_len(struct net_device *dev)
  185. {
  186. return 0;
  187. }
  188. static void ieee80211_get_regs(struct net_device *dev,
  189. struct ethtool_regs *regs,
  190. void *data)
  191. {
  192. struct wireless_dev *wdev = dev->ieee80211_ptr;
  193. regs->version = wdev->wiphy->hw_version;
  194. regs->len = 0;
  195. }
  196. const struct ethtool_ops ieee80211_ethtool_ops = {
  197. .get_drvinfo = cfg80211_get_drvinfo,
  198. .get_regs_len = ieee80211_get_regs_len,
  199. .get_regs = ieee80211_get_regs,
  200. .get_link = ethtool_op_get_link,
  201. .get_ringparam = ieee80211_get_ringparam,
  202. .set_ringparam = ieee80211_set_ringparam,
  203. .get_strings = ieee80211_get_strings,
  204. .get_ethtool_stats = ieee80211_get_stats,
  205. .get_sset_count = ieee80211_get_sset_count,
  206. };