debug_sta.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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_txq *txq;
  27. u32 len = 0, size = 4096;
  28. char *buf;
  29. size_t retval;
  30. int tidno;
  31. buf = kzalloc(size, GFP_KERNEL);
  32. if (buf == NULL)
  33. return -ENOMEM;
  34. if (!an->sta->ht_cap.ht_supported) {
  35. len = scnprintf(buf, size, "%s\n",
  36. "HT not supported");
  37. goto exit;
  38. }
  39. len = scnprintf(buf, size, "Max-AMPDU: %d\n",
  40. an->maxampdu);
  41. len += scnprintf(buf + len, size - len, "MPDU Density: %d\n\n",
  42. an->mpdudensity);
  43. len += scnprintf(buf + len, size - len,
  44. "\n%3s%11s%10s%10s%10s%10s%9s%6s%8s\n",
  45. "TID", "SEQ_START", "SEQ_NEXT", "BAW_SIZE",
  46. "BAW_HEAD", "BAW_TAIL", "BAR_IDX", "SCHED", "PAUSED");
  47. for (tidno = 0, tid = &an->tid[tidno];
  48. tidno < IEEE80211_NUM_TIDS; tidno++, tid++) {
  49. txq = tid->txq;
  50. ath_txq_lock(sc, txq);
  51. if (tid->active) {
  52. len += scnprintf(buf + len, size - len,
  53. "%3d%11d%10d%10d%10d%10d%9d%6d\n",
  54. tid->tidno,
  55. tid->seq_start,
  56. tid->seq_next,
  57. tid->baw_size,
  58. tid->baw_head,
  59. tid->baw_tail,
  60. tid->bar_index,
  61. !list_empty(&tid->list));
  62. }
  63. ath_txq_unlock(sc, txq);
  64. }
  65. exit:
  66. retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
  67. kfree(buf);
  68. return retval;
  69. }
  70. static const struct file_operations fops_node_aggr = {
  71. .read = read_file_node_aggr,
  72. .open = simple_open,
  73. .owner = THIS_MODULE,
  74. .llseek = default_llseek,
  75. };
  76. /*************/
  77. /* node_recv */
  78. /*************/
  79. void ath_debug_rate_stats(struct ath_softc *sc,
  80. struct ath_rx_status *rs,
  81. struct sk_buff *skb)
  82. {
  83. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  84. struct ath_hw *ah = sc->sc_ah;
  85. struct ieee80211_rx_status *rxs;
  86. struct ath_rx_rate_stats *rstats;
  87. struct ieee80211_sta *sta;
  88. struct ath_node *an;
  89. if (!ieee80211_is_data(hdr->frame_control))
  90. return;
  91. rcu_read_lock();
  92. sta = ieee80211_find_sta_by_ifaddr(sc->hw, hdr->addr2, NULL);
  93. if (!sta)
  94. goto exit;
  95. an = (struct ath_node *) sta->drv_priv;
  96. rstats = &an->rx_rate_stats;
  97. rxs = IEEE80211_SKB_RXCB(skb);
  98. if (IS_HT_RATE(rs->rs_rate)) {
  99. if (rxs->rate_idx >= ARRAY_SIZE(rstats->ht_stats))
  100. goto exit;
  101. if (rxs->flag & RX_FLAG_40MHZ)
  102. rstats->ht_stats[rxs->rate_idx].ht40_cnt++;
  103. else
  104. rstats->ht_stats[rxs->rate_idx].ht20_cnt++;
  105. if (rxs->flag & RX_FLAG_SHORT_GI)
  106. rstats->ht_stats[rxs->rate_idx].sgi_cnt++;
  107. else
  108. rstats->ht_stats[rxs->rate_idx].lgi_cnt++;
  109. goto exit;
  110. }
  111. if (IS_CCK_RATE(rs->rs_rate)) {
  112. if (rxs->flag & RX_FLAG_SHORTPRE)
  113. rstats->cck_stats[rxs->rate_idx].cck_sp_cnt++;
  114. else
  115. rstats->cck_stats[rxs->rate_idx].cck_lp_cnt++;
  116. goto exit;
  117. }
  118. if (IS_OFDM_RATE(rs->rs_rate)) {
  119. if (ah->curchan->chan->band == IEEE80211_BAND_2GHZ)
  120. rstats->ofdm_stats[rxs->rate_idx - 4].ofdm_cnt++;
  121. else
  122. rstats->ofdm_stats[rxs->rate_idx].ofdm_cnt++;
  123. }
  124. exit:
  125. rcu_read_unlock();
  126. }
  127. #define PRINT_CCK_RATE(str, i, sp) \
  128. do { \
  129. len += scnprintf(buf + len, size - len, \
  130. "%11s : %10u\n", \
  131. str, \
  132. (sp) ? rstats->cck_stats[i].cck_sp_cnt : \
  133. rstats->cck_stats[i].cck_lp_cnt); \
  134. } while (0)
  135. #define PRINT_OFDM_RATE(str, i) \
  136. do { \
  137. len += scnprintf(buf + len, size - len, \
  138. "%11s : %10u\n", \
  139. str, \
  140. rstats->ofdm_stats[i].ofdm_cnt); \
  141. } while (0)
  142. static ssize_t read_file_node_recv(struct file *file, char __user *user_buf,
  143. size_t count, loff_t *ppos)
  144. {
  145. struct ath_node *an = file->private_data;
  146. struct ath_softc *sc = an->sc;
  147. struct ath_hw *ah = sc->sc_ah;
  148. struct ath_rx_rate_stats *rstats;
  149. struct ieee80211_sta *sta = an->sta;
  150. enum ieee80211_band band;
  151. u32 len = 0, size = 4096;
  152. char *buf;
  153. size_t retval;
  154. int i;
  155. buf = kzalloc(size, GFP_KERNEL);
  156. if (buf == NULL)
  157. return -ENOMEM;
  158. band = ah->curchan->chan->band;
  159. rstats = &an->rx_rate_stats;
  160. if (!sta->ht_cap.ht_supported)
  161. goto legacy;
  162. len += scnprintf(buf + len, size - len,
  163. "%24s%10s%10s%10s\n",
  164. "HT20", "HT40", "SGI", "LGI");
  165. for (i = 0; i < 24; i++) {
  166. len += scnprintf(buf + len, size - len,
  167. "%8s%3u : %10u%10u%10u%10u\n",
  168. "MCS", i,
  169. rstats->ht_stats[i].ht20_cnt,
  170. rstats->ht_stats[i].ht40_cnt,
  171. rstats->ht_stats[i].sgi_cnt,
  172. rstats->ht_stats[i].lgi_cnt);
  173. }
  174. len += scnprintf(buf + len, size - len, "\n");
  175. legacy:
  176. if (band == IEEE80211_BAND_2GHZ) {
  177. PRINT_CCK_RATE("CCK-1M/LP", 0, false);
  178. PRINT_CCK_RATE("CCK-2M/LP", 1, false);
  179. PRINT_CCK_RATE("CCK-5.5M/LP", 2, false);
  180. PRINT_CCK_RATE("CCK-11M/LP", 3, false);
  181. PRINT_CCK_RATE("CCK-2M/SP", 1, true);
  182. PRINT_CCK_RATE("CCK-5.5M/SP", 2, true);
  183. PRINT_CCK_RATE("CCK-11M/SP", 3, true);
  184. }
  185. PRINT_OFDM_RATE("OFDM-6M", 0);
  186. PRINT_OFDM_RATE("OFDM-9M", 1);
  187. PRINT_OFDM_RATE("OFDM-12M", 2);
  188. PRINT_OFDM_RATE("OFDM-18M", 3);
  189. PRINT_OFDM_RATE("OFDM-24M", 4);
  190. PRINT_OFDM_RATE("OFDM-36M", 5);
  191. PRINT_OFDM_RATE("OFDM-48M", 6);
  192. PRINT_OFDM_RATE("OFDM-54M", 7);
  193. retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
  194. kfree(buf);
  195. return retval;
  196. }
  197. #undef PRINT_OFDM_RATE
  198. #undef PRINT_CCK_RATE
  199. static const struct file_operations fops_node_recv = {
  200. .read = read_file_node_recv,
  201. .open = simple_open,
  202. .owner = THIS_MODULE,
  203. .llseek = default_llseek,
  204. };
  205. void ath9k_sta_add_debugfs(struct ieee80211_hw *hw,
  206. struct ieee80211_vif *vif,
  207. struct ieee80211_sta *sta,
  208. struct dentry *dir)
  209. {
  210. struct ath_node *an = (struct ath_node *)sta->drv_priv;
  211. debugfs_create_file("node_aggr", S_IRUGO, dir, an, &fops_node_aggr);
  212. debugfs_create_file("node_recv", S_IRUGO, dir, an, &fops_node_recv);
  213. }