debug_sta.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. /*
  2. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include "ath9k.h"
  17. /*************/
  18. /* node_aggr */
  19. /*************/
  20. static ssize_t read_file_node_aggr(struct file *file, char __user *user_buf,
  21. size_t count, loff_t *ppos)
  22. {
  23. struct ath_node *an = file->private_data;
  24. struct ath_softc *sc = an->sc;
  25. struct ath_atx_tid *tid;
  26. struct ath_atx_ac *ac;
  27. struct ath_txq *txq;
  28. u32 len = 0, size = 4096;
  29. char *buf;
  30. size_t retval;
  31. int tidno, acno;
  32. buf = kzalloc(size, GFP_KERNEL);
  33. if (buf == NULL)
  34. return -ENOMEM;
  35. if (!an->sta->ht_cap.ht_supported) {
  36. len = scnprintf(buf, size, "%s\n",
  37. "HT not supported");
  38. goto exit;
  39. }
  40. len = scnprintf(buf, size, "Max-AMPDU: %d\n",
  41. an->maxampdu);
  42. len += scnprintf(buf + len, size - len, "MPDU Density: %d\n\n",
  43. an->mpdudensity);
  44. len += scnprintf(buf + len, size - len,
  45. "%2s%7s\n", "AC", "SCHED");
  46. for (acno = 0, ac = &an->ac[acno];
  47. acno < IEEE80211_NUM_ACS; acno++, ac++) {
  48. txq = ac->txq;
  49. ath_txq_lock(sc, txq);
  50. len += scnprintf(buf + len, size - len,
  51. "%2d%7d\n",
  52. acno, ac->sched);
  53. ath_txq_unlock(sc, txq);
  54. }
  55. len += scnprintf(buf + len, size - len,
  56. "\n%3s%11s%10s%10s%10s%10s%9s%6s%8s\n",
  57. "TID", "SEQ_START", "SEQ_NEXT", "BAW_SIZE",
  58. "BAW_HEAD", "BAW_TAIL", "BAR_IDX", "SCHED", "PAUSED");
  59. for (tidno = 0, tid = &an->tid[tidno];
  60. tidno < IEEE80211_NUM_TIDS; tidno++, tid++) {
  61. txq = tid->ac->txq;
  62. ath_txq_lock(sc, txq);
  63. if (tid->active) {
  64. len += scnprintf(buf + len, size - len,
  65. "%3d%11d%10d%10d%10d%10d%9d%6d\n",
  66. tid->tidno,
  67. tid->seq_start,
  68. tid->seq_next,
  69. tid->baw_size,
  70. tid->baw_head,
  71. tid->baw_tail,
  72. tid->bar_index,
  73. tid->sched);
  74. }
  75. ath_txq_unlock(sc, txq);
  76. }
  77. exit:
  78. retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
  79. kfree(buf);
  80. return retval;
  81. }
  82. static const struct file_operations fops_node_aggr = {
  83. .read = read_file_node_aggr,
  84. .open = simple_open,
  85. .owner = THIS_MODULE,
  86. .llseek = default_llseek,
  87. };
  88. /*************/
  89. /* node_recv */
  90. /*************/
  91. void ath_debug_rate_stats(struct ath_softc *sc,
  92. struct ath_rx_status *rs,
  93. struct sk_buff *skb)
  94. {
  95. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  96. struct ath_hw *ah = sc->sc_ah;
  97. struct ieee80211_rx_status *rxs;
  98. struct ath_rx_rate_stats *rstats;
  99. struct ieee80211_sta *sta;
  100. struct ath_node *an;
  101. if (!ieee80211_is_data(hdr->frame_control))
  102. return;
  103. rcu_read_lock();
  104. sta = ieee80211_find_sta_by_ifaddr(sc->hw, hdr->addr2, NULL);
  105. if (!sta)
  106. goto exit;
  107. an = (struct ath_node *) sta->drv_priv;
  108. rstats = &an->rx_rate_stats;
  109. rxs = IEEE80211_SKB_RXCB(skb);
  110. if (IS_HT_RATE(rs->rs_rate)) {
  111. if (rxs->rate_idx >= ARRAY_SIZE(rstats->ht_stats))
  112. goto exit;
  113. if (rxs->flag & RX_FLAG_40MHZ)
  114. rstats->ht_stats[rxs->rate_idx].ht40_cnt++;
  115. else
  116. rstats->ht_stats[rxs->rate_idx].ht20_cnt++;
  117. if (rxs->flag & RX_FLAG_SHORT_GI)
  118. rstats->ht_stats[rxs->rate_idx].sgi_cnt++;
  119. else
  120. rstats->ht_stats[rxs->rate_idx].lgi_cnt++;
  121. goto exit;
  122. }
  123. if (IS_CCK_RATE(rs->rs_rate)) {
  124. if (rxs->flag & RX_FLAG_SHORTPRE)
  125. rstats->cck_stats[rxs->rate_idx].cck_sp_cnt++;
  126. else
  127. rstats->cck_stats[rxs->rate_idx].cck_lp_cnt++;
  128. goto exit;
  129. }
  130. if (IS_OFDM_RATE(rs->rs_rate)) {
  131. if (ah->curchan->chan->band == IEEE80211_BAND_2GHZ)
  132. rstats->ofdm_stats[rxs->rate_idx - 4].ofdm_cnt++;
  133. else
  134. rstats->ofdm_stats[rxs->rate_idx].ofdm_cnt++;
  135. }
  136. exit:
  137. rcu_read_unlock();
  138. }
  139. #define PRINT_CCK_RATE(str, i, sp) \
  140. do { \
  141. len += scnprintf(buf + len, size - len, \
  142. "%11s : %10u\n", \
  143. str, \
  144. (sp) ? rstats->cck_stats[i].cck_sp_cnt : \
  145. rstats->cck_stats[i].cck_lp_cnt); \
  146. } while (0)
  147. #define PRINT_OFDM_RATE(str, i) \
  148. do { \
  149. len += scnprintf(buf + len, size - len, \
  150. "%11s : %10u\n", \
  151. str, \
  152. rstats->ofdm_stats[i].ofdm_cnt); \
  153. } while (0)
  154. static ssize_t read_file_node_recv(struct file *file, char __user *user_buf,
  155. size_t count, loff_t *ppos)
  156. {
  157. struct ath_node *an = file->private_data;
  158. struct ath_softc *sc = an->sc;
  159. struct ath_hw *ah = sc->sc_ah;
  160. struct ath_rx_rate_stats *rstats;
  161. struct ieee80211_sta *sta = an->sta;
  162. enum ieee80211_band band;
  163. u32 len = 0, size = 4096;
  164. char *buf;
  165. size_t retval;
  166. int i;
  167. buf = kzalloc(size, GFP_KERNEL);
  168. if (buf == NULL)
  169. return -ENOMEM;
  170. band = ah->curchan->chan->band;
  171. rstats = &an->rx_rate_stats;
  172. if (!sta->ht_cap.ht_supported)
  173. goto legacy;
  174. len += scnprintf(buf + len, size - len,
  175. "%24s%10s%10s%10s\n",
  176. "HT20", "HT40", "SGI", "LGI");
  177. for (i = 0; i < 24; i++) {
  178. len += scnprintf(buf + len, size - len,
  179. "%8s%3u : %10u%10u%10u%10u\n",
  180. "MCS", i,
  181. rstats->ht_stats[i].ht20_cnt,
  182. rstats->ht_stats[i].ht40_cnt,
  183. rstats->ht_stats[i].sgi_cnt,
  184. rstats->ht_stats[i].lgi_cnt);
  185. }
  186. len += scnprintf(buf + len, size - len, "\n");
  187. legacy:
  188. if (band == IEEE80211_BAND_2GHZ) {
  189. PRINT_CCK_RATE("CCK-1M/LP", 0, false);
  190. PRINT_CCK_RATE("CCK-2M/LP", 1, false);
  191. PRINT_CCK_RATE("CCK-5.5M/LP", 2, false);
  192. PRINT_CCK_RATE("CCK-11M/LP", 3, false);
  193. PRINT_CCK_RATE("CCK-2M/SP", 1, true);
  194. PRINT_CCK_RATE("CCK-5.5M/SP", 2, true);
  195. PRINT_CCK_RATE("CCK-11M/SP", 3, true);
  196. }
  197. PRINT_OFDM_RATE("OFDM-6M", 0);
  198. PRINT_OFDM_RATE("OFDM-9M", 1);
  199. PRINT_OFDM_RATE("OFDM-12M", 2);
  200. PRINT_OFDM_RATE("OFDM-18M", 3);
  201. PRINT_OFDM_RATE("OFDM-24M", 4);
  202. PRINT_OFDM_RATE("OFDM-36M", 5);
  203. PRINT_OFDM_RATE("OFDM-48M", 6);
  204. PRINT_OFDM_RATE("OFDM-54M", 7);
  205. retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
  206. kfree(buf);
  207. return retval;
  208. }
  209. #undef PRINT_OFDM_RATE
  210. #undef PRINT_CCK_RATE
  211. static const struct file_operations fops_node_recv = {
  212. .read = read_file_node_recv,
  213. .open = simple_open,
  214. .owner = THIS_MODULE,
  215. .llseek = default_llseek,
  216. };
  217. void ath9k_sta_add_debugfs(struct ieee80211_hw *hw,
  218. struct ieee80211_vif *vif,
  219. struct ieee80211_sta *sta,
  220. struct dentry *dir)
  221. {
  222. struct ath_node *an = (struct ath_node *)sta->drv_priv;
  223. debugfs_create_file("node_aggr", S_IRUGO, dir, an, &fops_node_aggr);
  224. debugfs_create_file("node_recv", S_IRUGO, dir, an, &fops_node_recv);
  225. }