ethtool.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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",
  35. "tx_filtered", "tx_retry_failed", "tx_retries",
  36. "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_stats.packets; \
  69. data[i++] += sta->rx_stats.bytes; \
  70. data[i++] += sta->rx_stats.num_duplicates; \
  71. data[i++] += sta->rx_stats.fragments; \
  72. data[i++] += sta->rx_stats.dropped; \
  73. \
  74. data[i++] += sinfo.tx_packets; \
  75. data[i++] += sinfo.tx_bytes; \
  76. data[i++] += sta->status_stats.filtered; \
  77. data[i++] += sta->status_stats.retry_failed; \
  78. data[i++] += sta->status_stats.retry_count; \
  79. } while (0)
  80. /* For Managed stations, find the single station based on BSSID
  81. * and use that. For interface types, iterate through all available
  82. * stations and add stats for any station that is assigned to this
  83. * network device.
  84. */
  85. mutex_lock(&local->sta_mtx);
  86. if (sdata->vif.type == NL80211_IFTYPE_STATION) {
  87. sta = sta_info_get_bss(sdata, sdata->u.mgd.bssid);
  88. if (!(sta && !WARN_ON(sta->sdata->dev != dev)))
  89. goto do_survey;
  90. sinfo.filled = 0;
  91. sta_set_sinfo(sta, &sinfo);
  92. i = 0;
  93. ADD_STA_STATS(sta);
  94. data[i++] = sta->sta_state;
  95. if (sinfo.filled & BIT(NL80211_STA_INFO_TX_BITRATE))
  96. data[i] = 100000 *
  97. cfg80211_calculate_bitrate(&sinfo.txrate);
  98. i++;
  99. if (sinfo.filled & BIT(NL80211_STA_INFO_RX_BITRATE))
  100. data[i] = 100000 *
  101. cfg80211_calculate_bitrate(&sinfo.rxrate);
  102. i++;
  103. if (sinfo.filled & BIT(NL80211_STA_INFO_SIGNAL_AVG))
  104. data[i] = (u8)sinfo.signal_avg;
  105. i++;
  106. } else {
  107. list_for_each_entry(sta, &local->sta_list, list) {
  108. /* Make sure this station belongs to the proper dev */
  109. if (sta->sdata->dev != dev)
  110. continue;
  111. sinfo.filled = 0;
  112. sta_set_sinfo(sta, &sinfo);
  113. i = 0;
  114. ADD_STA_STATS(sta);
  115. }
  116. }
  117. do_survey:
  118. i = STA_STATS_LEN - STA_STATS_SURVEY_LEN;
  119. /* Get survey stats for current channel */
  120. survey.filled = 0;
  121. rcu_read_lock();
  122. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  123. if (chanctx_conf)
  124. channel = chanctx_conf->def.chan;
  125. else
  126. channel = NULL;
  127. rcu_read_unlock();
  128. if (channel) {
  129. q = 0;
  130. do {
  131. survey.filled = 0;
  132. if (drv_get_survey(local, q, &survey) != 0) {
  133. survey.filled = 0;
  134. break;
  135. }
  136. q++;
  137. } while (channel != survey.channel);
  138. }
  139. if (survey.filled)
  140. data[i++] = survey.channel->center_freq;
  141. else
  142. data[i++] = 0;
  143. if (survey.filled & SURVEY_INFO_NOISE_DBM)
  144. data[i++] = (u8)survey.noise;
  145. else
  146. data[i++] = -1LL;
  147. if (survey.filled & SURVEY_INFO_TIME)
  148. data[i++] = survey.time;
  149. else
  150. data[i++] = -1LL;
  151. if (survey.filled & SURVEY_INFO_TIME_BUSY)
  152. data[i++] = survey.time_busy;
  153. else
  154. data[i++] = -1LL;
  155. if (survey.filled & SURVEY_INFO_TIME_EXT_BUSY)
  156. data[i++] = survey.time_ext_busy;
  157. else
  158. data[i++] = -1LL;
  159. if (survey.filled & SURVEY_INFO_TIME_RX)
  160. data[i++] = survey.time_rx;
  161. else
  162. data[i++] = -1LL;
  163. if (survey.filled & SURVEY_INFO_TIME_TX)
  164. data[i++] = survey.time_tx;
  165. else
  166. data[i++] = -1LL;
  167. mutex_unlock(&local->sta_mtx);
  168. if (WARN_ON(i != STA_STATS_LEN))
  169. return;
  170. drv_get_et_stats(sdata, stats, &(data[STA_STATS_LEN]));
  171. }
  172. static void ieee80211_get_strings(struct net_device *dev, u32 sset, u8 *data)
  173. {
  174. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  175. int sz_sta_stats = 0;
  176. if (sset == ETH_SS_STATS) {
  177. sz_sta_stats = sizeof(ieee80211_gstrings_sta_stats);
  178. memcpy(data, ieee80211_gstrings_sta_stats, sz_sta_stats);
  179. }
  180. drv_get_et_strings(sdata, sset, &(data[sz_sta_stats]));
  181. }
  182. static int ieee80211_get_regs_len(struct net_device *dev)
  183. {
  184. return 0;
  185. }
  186. static void ieee80211_get_regs(struct net_device *dev,
  187. struct ethtool_regs *regs,
  188. void *data)
  189. {
  190. struct wireless_dev *wdev = dev->ieee80211_ptr;
  191. regs->version = wdev->wiphy->hw_version;
  192. regs->len = 0;
  193. }
  194. const struct ethtool_ops ieee80211_ethtool_ops = {
  195. .get_drvinfo = cfg80211_get_drvinfo,
  196. .get_regs_len = ieee80211_get_regs_len,
  197. .get_regs = ieee80211_get_regs,
  198. .get_link = ethtool_op_get_link,
  199. .get_ringparam = ieee80211_get_ringparam,
  200. .set_ringparam = ieee80211_set_ringparam,
  201. .get_strings = ieee80211_get_strings,
  202. .get_ethtool_stats = ieee80211_get_stats,
  203. .get_sset_count = ieee80211_get_sset_count,
  204. };