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%8d\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. tid->paused);
  75. }
  76. ath_txq_unlock(sc, txq);
  77. }
  78. exit:
  79. retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
  80. kfree(buf);
  81. return retval;
  82. }
  83. static const struct file_operations fops_node_aggr = {
  84. .read = read_file_node_aggr,
  85. .open = simple_open,
  86. .owner = THIS_MODULE,
  87. .llseek = default_llseek,
  88. };
  89. /*************/
  90. /* node_recv */
  91. /*************/
  92. void ath_debug_rate_stats(struct ath_softc *sc,
  93. struct ath_rx_status *rs,
  94. struct sk_buff *skb)
  95. {
  96. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  97. struct ath_hw *ah = sc->sc_ah;
  98. struct ieee80211_rx_status *rxs;
  99. struct ath_rx_rate_stats *rstats;
  100. struct ieee80211_sta *sta;
  101. struct ath_node *an;
  102. if (!ieee80211_is_data(hdr->frame_control))
  103. return;
  104. rcu_read_lock();
  105. sta = ieee80211_find_sta_by_ifaddr(sc->hw, hdr->addr2, NULL);
  106. if (!sta)
  107. goto exit;
  108. an = (struct ath_node *) sta->drv_priv;
  109. rstats = &an->rx_rate_stats;
  110. rxs = IEEE80211_SKB_RXCB(skb);
  111. if (IS_HT_RATE(rs->rs_rate)) {
  112. if (rxs->rate_idx >= ARRAY_SIZE(rstats->ht_stats))
  113. goto exit;
  114. if (rxs->flag & RX_FLAG_40MHZ)
  115. rstats->ht_stats[rxs->rate_idx].ht40_cnt++;
  116. else
  117. rstats->ht_stats[rxs->rate_idx].ht20_cnt++;
  118. if (rxs->flag & RX_FLAG_SHORT_GI)
  119. rstats->ht_stats[rxs->rate_idx].sgi_cnt++;
  120. else
  121. rstats->ht_stats[rxs->rate_idx].lgi_cnt++;
  122. goto exit;
  123. }
  124. if (IS_CCK_RATE(rs->rs_rate)) {
  125. if (rxs->flag & RX_FLAG_SHORTPRE)
  126. rstats->cck_stats[rxs->rate_idx].cck_sp_cnt++;
  127. else
  128. rstats->cck_stats[rxs->rate_idx].cck_lp_cnt++;
  129. goto exit;
  130. }
  131. if (IS_OFDM_RATE(rs->rs_rate)) {
  132. if (ah->curchan->chan->band == IEEE80211_BAND_2GHZ)
  133. rstats->ofdm_stats[rxs->rate_idx - 4].ofdm_cnt++;
  134. else
  135. rstats->ofdm_stats[rxs->rate_idx].ofdm_cnt++;
  136. }
  137. exit:
  138. rcu_read_unlock();
  139. }
  140. #define PRINT_CCK_RATE(str, i, sp) \
  141. do { \
  142. len += scnprintf(buf + len, size - len, \
  143. "%11s : %10u\n", \
  144. str, \
  145. (sp) ? rstats->cck_stats[i].cck_sp_cnt : \
  146. rstats->cck_stats[i].cck_lp_cnt); \
  147. } while (0)
  148. #define PRINT_OFDM_RATE(str, i) \
  149. do { \
  150. len += scnprintf(buf + len, size - len, \
  151. "%11s : %10u\n", \
  152. str, \
  153. rstats->ofdm_stats[i].ofdm_cnt); \
  154. } while (0)
  155. static ssize_t read_file_node_recv(struct file *file, char __user *user_buf,
  156. size_t count, loff_t *ppos)
  157. {
  158. struct ath_node *an = file->private_data;
  159. struct ath_softc *sc = an->sc;
  160. struct ath_hw *ah = sc->sc_ah;
  161. struct ath_rx_rate_stats *rstats;
  162. struct ieee80211_sta *sta = an->sta;
  163. enum ieee80211_band band;
  164. u32 len = 0, size = 4096;
  165. char *buf;
  166. size_t retval;
  167. int i;
  168. buf = kzalloc(size, GFP_KERNEL);
  169. if (buf == NULL)
  170. return -ENOMEM;
  171. band = ah->curchan->chan->band;
  172. rstats = &an->rx_rate_stats;
  173. if (!sta->ht_cap.ht_supported)
  174. goto legacy;
  175. len += scnprintf(buf + len, size - len,
  176. "%24s%10s%10s%10s\n",
  177. "HT20", "HT40", "SGI", "LGI");
  178. for (i = 0; i < 24; i++) {
  179. len += scnprintf(buf + len, size - len,
  180. "%8s%3u : %10u%10u%10u%10u\n",
  181. "MCS", i,
  182. rstats->ht_stats[i].ht20_cnt,
  183. rstats->ht_stats[i].ht40_cnt,
  184. rstats->ht_stats[i].sgi_cnt,
  185. rstats->ht_stats[i].lgi_cnt);
  186. }
  187. len += scnprintf(buf + len, size - len, "\n");
  188. legacy:
  189. if (band == IEEE80211_BAND_2GHZ) {
  190. PRINT_CCK_RATE("CCK-1M/LP", 0, false);
  191. PRINT_CCK_RATE("CCK-2M/LP", 1, false);
  192. PRINT_CCK_RATE("CCK-5.5M/LP", 2, false);
  193. PRINT_CCK_RATE("CCK-11M/LP", 3, false);
  194. PRINT_CCK_RATE("CCK-2M/SP", 1, true);
  195. PRINT_CCK_RATE("CCK-5.5M/SP", 2, true);
  196. PRINT_CCK_RATE("CCK-11M/SP", 3, true);
  197. }
  198. PRINT_OFDM_RATE("OFDM-6M", 0);
  199. PRINT_OFDM_RATE("OFDM-9M", 1);
  200. PRINT_OFDM_RATE("OFDM-12M", 2);
  201. PRINT_OFDM_RATE("OFDM-18M", 3);
  202. PRINT_OFDM_RATE("OFDM-24M", 4);
  203. PRINT_OFDM_RATE("OFDM-36M", 5);
  204. PRINT_OFDM_RATE("OFDM-48M", 6);
  205. PRINT_OFDM_RATE("OFDM-54M", 7);
  206. retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
  207. kfree(buf);
  208. return retval;
  209. }
  210. #undef PRINT_OFDM_RATE
  211. #undef PRINT_CCK_RATE
  212. static const struct file_operations fops_node_recv = {
  213. .read = read_file_node_recv,
  214. .open = simple_open,
  215. .owner = THIS_MODULE,
  216. .llseek = default_llseek,
  217. };
  218. void ath9k_sta_add_debugfs(struct ieee80211_hw *hw,
  219. struct ieee80211_vif *vif,
  220. struct ieee80211_sta *sta,
  221. struct dentry *dir)
  222. {
  223. struct ath_node *an = (struct ath_node *)sta->drv_priv;
  224. debugfs_create_file("node_aggr", S_IRUGO, dir, an, &fops_node_aggr);
  225. debugfs_create_file("node_recv", S_IRUGO, dir, an, &fops_node_recv);
  226. }