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