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