xref: /openbmc/linux/drivers/net/wireless/ath/ath9k/debug.c (revision 047dc3ac884f3285bc123461e5e3c38f44fb32a6)
1 /*
2  * Copyright (c) 2008-2011 Atheros Communications 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 <linux/slab.h>
18 #include <linux/vmalloc.h>
19 #include <linux/export.h>
20 #include <linux/relay.h>
21 #include <asm/unaligned.h>
22 
23 #include "ath9k.h"
24 
25 #define REG_WRITE_D(_ah, _reg, _val) \
26 	ath9k_hw_common(_ah)->ops->write((_ah), (_val), (_reg))
27 #define REG_READ_D(_ah, _reg) \
28 	ath9k_hw_common(_ah)->ops->read((_ah), (_reg))
29 
30 
31 static ssize_t ath9k_debugfs_read_buf(struct file *file, char __user *user_buf,
32 				      size_t count, loff_t *ppos)
33 {
34 	u8 *buf = file->private_data;
35 	return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
36 }
37 
38 static int ath9k_debugfs_release_buf(struct inode *inode, struct file *file)
39 {
40 	vfree(file->private_data);
41 	return 0;
42 }
43 
44 #ifdef CONFIG_ATH_DEBUG
45 
46 static ssize_t read_file_debug(struct file *file, char __user *user_buf,
47 			     size_t count, loff_t *ppos)
48 {
49 	struct ath_softc *sc = file->private_data;
50 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
51 	char buf[32];
52 	unsigned int len;
53 
54 	len = sprintf(buf, "0x%08x\n", common->debug_mask);
55 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
56 }
57 
58 static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
59 			     size_t count, loff_t *ppos)
60 {
61 	struct ath_softc *sc = file->private_data;
62 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
63 	unsigned long mask;
64 	char buf[32];
65 	ssize_t len;
66 
67 	len = min(count, sizeof(buf) - 1);
68 	if (copy_from_user(buf, user_buf, len))
69 		return -EFAULT;
70 
71 	buf[len] = '\0';
72 	if (kstrtoul(buf, 0, &mask))
73 		return -EINVAL;
74 
75 	common->debug_mask = mask;
76 	return count;
77 }
78 
79 static const struct file_operations fops_debug = {
80 	.read = read_file_debug,
81 	.write = write_file_debug,
82 	.open = simple_open,
83 	.owner = THIS_MODULE,
84 	.llseek = default_llseek,
85 };
86 
87 #endif
88 
89 #define DMA_BUF_LEN 1024
90 
91 static ssize_t read_file_tx_chainmask(struct file *file, char __user *user_buf,
92 			     size_t count, loff_t *ppos)
93 {
94 	struct ath_softc *sc = file->private_data;
95 	struct ath_hw *ah = sc->sc_ah;
96 	char buf[32];
97 	unsigned int len;
98 
99 	len = sprintf(buf, "0x%08x\n", ah->txchainmask);
100 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
101 }
102 
103 static ssize_t write_file_tx_chainmask(struct file *file, const char __user *user_buf,
104 			     size_t count, loff_t *ppos)
105 {
106 	struct ath_softc *sc = file->private_data;
107 	struct ath_hw *ah = sc->sc_ah;
108 	unsigned long mask;
109 	char buf[32];
110 	ssize_t len;
111 
112 	len = min(count, sizeof(buf) - 1);
113 	if (copy_from_user(buf, user_buf, len))
114 		return -EFAULT;
115 
116 	buf[len] = '\0';
117 	if (kstrtoul(buf, 0, &mask))
118 		return -EINVAL;
119 
120 	ah->txchainmask = mask;
121 	ah->caps.tx_chainmask = mask;
122 	return count;
123 }
124 
125 static const struct file_operations fops_tx_chainmask = {
126 	.read = read_file_tx_chainmask,
127 	.write = write_file_tx_chainmask,
128 	.open = simple_open,
129 	.owner = THIS_MODULE,
130 	.llseek = default_llseek,
131 };
132 
133 
134 static ssize_t read_file_rx_chainmask(struct file *file, char __user *user_buf,
135 			     size_t count, loff_t *ppos)
136 {
137 	struct ath_softc *sc = file->private_data;
138 	struct ath_hw *ah = sc->sc_ah;
139 	char buf[32];
140 	unsigned int len;
141 
142 	len = sprintf(buf, "0x%08x\n", ah->rxchainmask);
143 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
144 }
145 
146 static ssize_t write_file_rx_chainmask(struct file *file, const char __user *user_buf,
147 			     size_t count, loff_t *ppos)
148 {
149 	struct ath_softc *sc = file->private_data;
150 	struct ath_hw *ah = sc->sc_ah;
151 	unsigned long mask;
152 	char buf[32];
153 	ssize_t len;
154 
155 	len = min(count, sizeof(buf) - 1);
156 	if (copy_from_user(buf, user_buf, len))
157 		return -EFAULT;
158 
159 	buf[len] = '\0';
160 	if (kstrtoul(buf, 0, &mask))
161 		return -EINVAL;
162 
163 	ah->rxchainmask = mask;
164 	ah->caps.rx_chainmask = mask;
165 	return count;
166 }
167 
168 static const struct file_operations fops_rx_chainmask = {
169 	.read = read_file_rx_chainmask,
170 	.write = write_file_rx_chainmask,
171 	.open = simple_open,
172 	.owner = THIS_MODULE,
173 	.llseek = default_llseek,
174 };
175 
176 static ssize_t read_file_ani(struct file *file, char __user *user_buf,
177 			     size_t count, loff_t *ppos)
178 {
179 	struct ath_softc *sc = file->private_data;
180 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
181 	struct ath_hw *ah = sc->sc_ah;
182 	unsigned int len = 0, size = 1024;
183 	ssize_t retval = 0;
184 	char *buf;
185 
186 	buf = kzalloc(size, GFP_KERNEL);
187 	if (buf == NULL)
188 		return -ENOMEM;
189 
190 	if (common->disable_ani) {
191 		len += snprintf(buf + len, size - len, "%s: %s\n",
192 				"ANI", "DISABLED");
193 		goto exit;
194 	}
195 
196 	len += snprintf(buf + len, size - len, "%15s: %s\n",
197 			"ANI", "ENABLED");
198 	len += snprintf(buf + len, size - len, "%15s: %u\n",
199 			"ANI RESET", ah->stats.ast_ani_reset);
200 	len += snprintf(buf + len, size - len, "%15s: %u\n",
201 			"SPUR UP", ah->stats.ast_ani_spurup);
202 	len += snprintf(buf + len, size - len, "%15s: %u\n",
203 			"SPUR DOWN", ah->stats.ast_ani_spurup);
204 	len += snprintf(buf + len, size - len, "%15s: %u\n",
205 			"OFDM WS-DET ON", ah->stats.ast_ani_ofdmon);
206 	len += snprintf(buf + len, size - len, "%15s: %u\n",
207 			"OFDM WS-DET OFF", ah->stats.ast_ani_ofdmoff);
208 	len += snprintf(buf + len, size - len, "%15s: %u\n",
209 			"MRC-CCK ON", ah->stats.ast_ani_ccklow);
210 	len += snprintf(buf + len, size - len, "%15s: %u\n",
211 			"MRC-CCK OFF", ah->stats.ast_ani_cckhigh);
212 	len += snprintf(buf + len, size - len, "%15s: %u\n",
213 			"FIR-STEP UP", ah->stats.ast_ani_stepup);
214 	len += snprintf(buf + len, size - len, "%15s: %u\n",
215 			"FIR-STEP DOWN", ah->stats.ast_ani_stepdown);
216 	len += snprintf(buf + len, size - len, "%15s: %u\n",
217 			"INV LISTENTIME", ah->stats.ast_ani_lneg_or_lzero);
218 	len += snprintf(buf + len, size - len, "%15s: %u\n",
219 			"OFDM ERRORS", ah->stats.ast_ani_ofdmerrs);
220 	len += snprintf(buf + len, size - len, "%15s: %u\n",
221 			"CCK ERRORS", ah->stats.ast_ani_cckerrs);
222 exit:
223 	if (len > size)
224 		len = size;
225 
226 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
227 	kfree(buf);
228 
229 	return retval;
230 }
231 
232 static ssize_t write_file_ani(struct file *file,
233 			      const char __user *user_buf,
234 			      size_t count, loff_t *ppos)
235 {
236 	struct ath_softc *sc = file->private_data;
237 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
238 	unsigned long ani;
239 	char buf[32];
240 	ssize_t len;
241 
242 	len = min(count, sizeof(buf) - 1);
243 	if (copy_from_user(buf, user_buf, len))
244 		return -EFAULT;
245 
246 	buf[len] = '\0';
247 	if (kstrtoul(buf, 0, &ani))
248 		return -EINVAL;
249 
250 	if (ani < 0 || ani > 1)
251 		return -EINVAL;
252 
253 	common->disable_ani = !ani;
254 
255 	if (common->disable_ani) {
256 		clear_bit(SC_OP_ANI_RUN, &sc->sc_flags);
257 		ath_stop_ani(sc);
258 	} else {
259 		ath_check_ani(sc);
260 	}
261 
262 	return count;
263 }
264 
265 static const struct file_operations fops_ani = {
266 	.read = read_file_ani,
267 	.write = write_file_ani,
268 	.open = simple_open,
269 	.owner = THIS_MODULE,
270 	.llseek = default_llseek,
271 };
272 
273 static ssize_t read_file_bt_ant_diversity(struct file *file,
274 					  char __user *user_buf,
275 					  size_t count, loff_t *ppos)
276 {
277 	struct ath_softc *sc = file->private_data;
278 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
279 	char buf[32];
280 	unsigned int len;
281 
282 	len = sprintf(buf, "%d\n", common->bt_ant_diversity);
283 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
284 }
285 
286 static ssize_t write_file_bt_ant_diversity(struct file *file,
287 					   const char __user *user_buf,
288 					   size_t count, loff_t *ppos)
289 {
290 	struct ath_softc *sc = file->private_data;
291 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
292 	struct ath9k_hw_capabilities *pCap = &sc->sc_ah->caps;
293 	unsigned long bt_ant_diversity;
294 	char buf[32];
295 	ssize_t len;
296 
297 	len = min(count, sizeof(buf) - 1);
298 	if (copy_from_user(buf, user_buf, len))
299 		return -EFAULT;
300 
301 	if (!(pCap->hw_caps & ATH9K_HW_CAP_BT_ANT_DIV))
302 		goto exit;
303 
304 	buf[len] = '\0';
305 	if (kstrtoul(buf, 0, &bt_ant_diversity))
306 		return -EINVAL;
307 
308 	common->bt_ant_diversity = !!bt_ant_diversity;
309 	ath9k_ps_wakeup(sc);
310 	ath9k_hw_set_bt_ant_diversity(sc->sc_ah, common->bt_ant_diversity);
311 	ath_dbg(common, CONFIG, "Enable WLAN/BT RX Antenna diversity: %d\n",
312 		common->bt_ant_diversity);
313 	ath9k_ps_restore(sc);
314 exit:
315 	return count;
316 }
317 
318 static const struct file_operations fops_bt_ant_diversity = {
319 	.read = read_file_bt_ant_diversity,
320 	.write = write_file_bt_ant_diversity,
321 	.open = simple_open,
322 	.owner = THIS_MODULE,
323 	.llseek = default_llseek,
324 };
325 
326 void ath9k_debug_stat_ant(struct ath_softc *sc,
327 			  struct ath_hw_antcomb_conf *div_ant_conf,
328 			  int main_rssi_avg, int alt_rssi_avg)
329 {
330 	struct ath_antenna_stats *as_main = &sc->debug.stats.ant_stats[ANT_MAIN];
331 	struct ath_antenna_stats *as_alt = &sc->debug.stats.ant_stats[ANT_ALT];
332 
333 	as_main->lna_attempt_cnt[div_ant_conf->main_lna_conf]++;
334 	as_alt->lna_attempt_cnt[div_ant_conf->alt_lna_conf]++;
335 
336 	as_main->rssi_avg = main_rssi_avg;
337 	as_alt->rssi_avg = alt_rssi_avg;
338 }
339 
340 static ssize_t read_file_antenna_diversity(struct file *file,
341 					   char __user *user_buf,
342 					   size_t count, loff_t *ppos)
343 {
344 	struct ath_softc *sc = file->private_data;
345 	struct ath_hw *ah = sc->sc_ah;
346 	struct ath9k_hw_capabilities *pCap = &ah->caps;
347 	struct ath_antenna_stats *as_main = &sc->debug.stats.ant_stats[ANT_MAIN];
348 	struct ath_antenna_stats *as_alt = &sc->debug.stats.ant_stats[ANT_ALT];
349 	struct ath_hw_antcomb_conf div_ant_conf;
350 	unsigned int len = 0, size = 1024;
351 	ssize_t retval = 0;
352 	char *buf;
353 	char *lna_conf_str[4] = {"LNA1_MINUS_LNA2",
354 				 "LNA2",
355 				 "LNA1",
356 				 "LNA1_PLUS_LNA2"};
357 
358 	buf = kzalloc(size, GFP_KERNEL);
359 	if (buf == NULL)
360 		return -ENOMEM;
361 
362 	if (!(pCap->hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)) {
363 		len += snprintf(buf + len, size - len, "%s\n",
364 				"Antenna Diversity Combining is disabled");
365 		goto exit;
366 	}
367 
368 	ath9k_ps_wakeup(sc);
369 	ath9k_hw_antdiv_comb_conf_get(ah, &div_ant_conf);
370 	len += snprintf(buf + len, size - len, "Current MAIN config : %s\n",
371 			lna_conf_str[div_ant_conf.main_lna_conf]);
372 	len += snprintf(buf + len, size - len, "Current ALT config  : %s\n",
373 			lna_conf_str[div_ant_conf.alt_lna_conf]);
374 	len += snprintf(buf + len, size - len, "Average MAIN RSSI   : %d\n",
375 			as_main->rssi_avg);
376 	len += snprintf(buf + len, size - len, "Average ALT RSSI    : %d\n\n",
377 			as_alt->rssi_avg);
378 	ath9k_ps_restore(sc);
379 
380 	len += snprintf(buf + len, size - len, "Packet Receive Cnt:\n");
381 	len += snprintf(buf + len, size - len, "-------------------\n");
382 
383 	len += snprintf(buf + len, size - len, "%30s%15s\n",
384 			"MAIN", "ALT");
385 	len += snprintf(buf + len, size - len, "%-14s:%15d%15d\n",
386 			"TOTAL COUNT",
387 			as_main->recv_cnt,
388 			as_alt->recv_cnt);
389 	len += snprintf(buf + len, size - len, "%-14s:%15d%15d\n",
390 			"LNA1",
391 			as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1],
392 			as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1]);
393 	len += snprintf(buf + len, size - len, "%-14s:%15d%15d\n",
394 			"LNA2",
395 			as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA2],
396 			as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA2]);
397 	len += snprintf(buf + len, size - len, "%-14s:%15d%15d\n",
398 			"LNA1 + LNA2",
399 			as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2],
400 			as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2]);
401 	len += snprintf(buf + len, size - len, "%-14s:%15d%15d\n",
402 			"LNA1 - LNA2",
403 			as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2],
404 			as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2]);
405 
406 	len += snprintf(buf + len, size - len, "\nLNA Config Attempts:\n");
407 	len += snprintf(buf + len, size - len, "--------------------\n");
408 
409 	len += snprintf(buf + len, size - len, "%30s%15s\n",
410 			"MAIN", "ALT");
411 	len += snprintf(buf + len, size - len, "%-14s:%15d%15d\n",
412 			"LNA1",
413 			as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1],
414 			as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1]);
415 	len += snprintf(buf + len, size - len, "%-14s:%15d%15d\n",
416 			"LNA2",
417 			as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA2],
418 			as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA2]);
419 	len += snprintf(buf + len, size - len, "%-14s:%15d%15d\n",
420 			"LNA1 + LNA2",
421 			as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2],
422 			as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2]);
423 	len += snprintf(buf + len, size - len, "%-14s:%15d%15d\n",
424 			"LNA1 - LNA2",
425 			as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2],
426 			as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2]);
427 
428 exit:
429 	if (len > size)
430 		len = size;
431 
432 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
433 	kfree(buf);
434 
435 	return retval;
436 }
437 
438 static const struct file_operations fops_antenna_diversity = {
439 	.read = read_file_antenna_diversity,
440 	.open = simple_open,
441 	.owner = THIS_MODULE,
442 	.llseek = default_llseek,
443 };
444 
445 static ssize_t read_file_dma(struct file *file, char __user *user_buf,
446 			     size_t count, loff_t *ppos)
447 {
448 	struct ath_softc *sc = file->private_data;
449 	struct ath_hw *ah = sc->sc_ah;
450 	char *buf;
451 	int retval;
452 	unsigned int len = 0;
453 	u32 val[ATH9K_NUM_DMA_DEBUG_REGS];
454 	int i, qcuOffset = 0, dcuOffset = 0;
455 	u32 *qcuBase = &val[0], *dcuBase = &val[4];
456 
457 	buf = kmalloc(DMA_BUF_LEN, GFP_KERNEL);
458 	if (!buf)
459 		return -ENOMEM;
460 
461 	ath9k_ps_wakeup(sc);
462 
463 	REG_WRITE_D(ah, AR_MACMISC,
464 		  ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) |
465 		   (AR_MACMISC_MISC_OBS_BUS_1 <<
466 		    AR_MACMISC_MISC_OBS_BUS_MSB_S)));
467 
468 	len += snprintf(buf + len, DMA_BUF_LEN - len,
469 			"Raw DMA Debug values:\n");
470 
471 	for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) {
472 		if (i % 4 == 0)
473 			len += snprintf(buf + len, DMA_BUF_LEN - len, "\n");
474 
475 		val[i] = REG_READ_D(ah, AR_DMADBG_0 + (i * sizeof(u32)));
476 		len += snprintf(buf + len, DMA_BUF_LEN - len, "%d: %08x ",
477 				i, val[i]);
478 	}
479 
480 	len += snprintf(buf + len, DMA_BUF_LEN - len, "\n\n");
481 	len += snprintf(buf + len, DMA_BUF_LEN - len,
482 			"Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n");
483 
484 	for (i = 0; i < ATH9K_NUM_QUEUES; i++, qcuOffset += 4, dcuOffset += 5) {
485 		if (i == 8) {
486 			qcuOffset = 0;
487 			qcuBase++;
488 		}
489 
490 		if (i == 6) {
491 			dcuOffset = 0;
492 			dcuBase++;
493 		}
494 
495 		len += snprintf(buf + len, DMA_BUF_LEN - len,
496 			"%2d          %2x      %1x     %2x           %2x\n",
497 			i, (*qcuBase & (0x7 << qcuOffset)) >> qcuOffset,
498 			(*qcuBase & (0x8 << qcuOffset)) >> (qcuOffset + 3),
499 			val[2] & (0x7 << (i * 3)) >> (i * 3),
500 			(*dcuBase & (0x1f << dcuOffset)) >> dcuOffset);
501 	}
502 
503 	len += snprintf(buf + len, DMA_BUF_LEN - len, "\n");
504 
505 	len += snprintf(buf + len, DMA_BUF_LEN - len,
506 		"qcu_stitch state:   %2x    qcu_fetch state:        %2x\n",
507 		(val[3] & 0x003c0000) >> 18, (val[3] & 0x03c00000) >> 22);
508 	len += snprintf(buf + len, DMA_BUF_LEN - len,
509 		"qcu_complete state: %2x    dcu_complete state:     %2x\n",
510 		(val[3] & 0x1c000000) >> 26, (val[6] & 0x3));
511 	len += snprintf(buf + len, DMA_BUF_LEN - len,
512 		"dcu_arb state:      %2x    dcu_fp state:           %2x\n",
513 		(val[5] & 0x06000000) >> 25, (val[5] & 0x38000000) >> 27);
514 	len += snprintf(buf + len, DMA_BUF_LEN - len,
515 		"chan_idle_dur:     %3d    chan_idle_dur_valid:     %1d\n",
516 		(val[6] & 0x000003fc) >> 2, (val[6] & 0x00000400) >> 10);
517 	len += snprintf(buf + len, DMA_BUF_LEN - len,
518 		"txfifo_valid_0:      %1d    txfifo_valid_1:          %1d\n",
519 		(val[6] & 0x00000800) >> 11, (val[6] & 0x00001000) >> 12);
520 	len += snprintf(buf + len, DMA_BUF_LEN - len,
521 		"txfifo_dcu_num_0:   %2d    txfifo_dcu_num_1:       %2d\n",
522 		(val[6] & 0x0001e000) >> 13, (val[6] & 0x001e0000) >> 17);
523 
524 	len += snprintf(buf + len, DMA_BUF_LEN - len, "pcu observe: 0x%x\n",
525 			REG_READ_D(ah, AR_OBS_BUS_1));
526 	len += snprintf(buf + len, DMA_BUF_LEN - len,
527 			"AR_CR: 0x%x\n", REG_READ_D(ah, AR_CR));
528 
529 	ath9k_ps_restore(sc);
530 
531 	if (len > DMA_BUF_LEN)
532 		len = DMA_BUF_LEN;
533 
534 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
535 	kfree(buf);
536 	return retval;
537 }
538 
539 static const struct file_operations fops_dma = {
540 	.read = read_file_dma,
541 	.open = simple_open,
542 	.owner = THIS_MODULE,
543 	.llseek = default_llseek,
544 };
545 
546 
547 void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status)
548 {
549 	if (status)
550 		sc->debug.stats.istats.total++;
551 	if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
552 		if (status & ATH9K_INT_RXLP)
553 			sc->debug.stats.istats.rxlp++;
554 		if (status & ATH9K_INT_RXHP)
555 			sc->debug.stats.istats.rxhp++;
556 		if (status & ATH9K_INT_BB_WATCHDOG)
557 			sc->debug.stats.istats.bb_watchdog++;
558 	} else {
559 		if (status & ATH9K_INT_RX)
560 			sc->debug.stats.istats.rxok++;
561 	}
562 	if (status & ATH9K_INT_RXEOL)
563 		sc->debug.stats.istats.rxeol++;
564 	if (status & ATH9K_INT_RXORN)
565 		sc->debug.stats.istats.rxorn++;
566 	if (status & ATH9K_INT_TX)
567 		sc->debug.stats.istats.txok++;
568 	if (status & ATH9K_INT_TXURN)
569 		sc->debug.stats.istats.txurn++;
570 	if (status & ATH9K_INT_RXPHY)
571 		sc->debug.stats.istats.rxphyerr++;
572 	if (status & ATH9K_INT_RXKCM)
573 		sc->debug.stats.istats.rx_keycache_miss++;
574 	if (status & ATH9K_INT_SWBA)
575 		sc->debug.stats.istats.swba++;
576 	if (status & ATH9K_INT_BMISS)
577 		sc->debug.stats.istats.bmiss++;
578 	if (status & ATH9K_INT_BNR)
579 		sc->debug.stats.istats.bnr++;
580 	if (status & ATH9K_INT_CST)
581 		sc->debug.stats.istats.cst++;
582 	if (status & ATH9K_INT_GTT)
583 		sc->debug.stats.istats.gtt++;
584 	if (status & ATH9K_INT_TIM)
585 		sc->debug.stats.istats.tim++;
586 	if (status & ATH9K_INT_CABEND)
587 		sc->debug.stats.istats.cabend++;
588 	if (status & ATH9K_INT_DTIMSYNC)
589 		sc->debug.stats.istats.dtimsync++;
590 	if (status & ATH9K_INT_DTIM)
591 		sc->debug.stats.istats.dtim++;
592 	if (status & ATH9K_INT_TSFOOR)
593 		sc->debug.stats.istats.tsfoor++;
594 	if (status & ATH9K_INT_MCI)
595 		sc->debug.stats.istats.mci++;
596 	if (status & ATH9K_INT_GENTIMER)
597 		sc->debug.stats.istats.gen_timer++;
598 }
599 
600 static ssize_t read_file_interrupt(struct file *file, char __user *user_buf,
601 				   size_t count, loff_t *ppos)
602 {
603 	struct ath_softc *sc = file->private_data;
604 	unsigned int len = 0;
605 	int rv;
606 	int mxlen = 4000;
607 	char *buf = kmalloc(mxlen, GFP_KERNEL);
608 	if (!buf)
609 		return -ENOMEM;
610 
611 #define PR_IS(a, s)						\
612 	do {							\
613 		len += snprintf(buf + len, mxlen - len,		\
614 				"%21s: %10u\n", a,		\
615 				sc->debug.stats.istats.s);	\
616 	} while (0)
617 
618 	if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
619 		PR_IS("RXLP", rxlp);
620 		PR_IS("RXHP", rxhp);
621 		PR_IS("WATHDOG", bb_watchdog);
622 	} else {
623 		PR_IS("RX", rxok);
624 	}
625 	PR_IS("RXEOL", rxeol);
626 	PR_IS("RXORN", rxorn);
627 	PR_IS("TX", txok);
628 	PR_IS("TXURN", txurn);
629 	PR_IS("MIB", mib);
630 	PR_IS("RXPHY", rxphyerr);
631 	PR_IS("RXKCM", rx_keycache_miss);
632 	PR_IS("SWBA", swba);
633 	PR_IS("BMISS", bmiss);
634 	PR_IS("BNR", bnr);
635 	PR_IS("CST", cst);
636 	PR_IS("GTT", gtt);
637 	PR_IS("TIM", tim);
638 	PR_IS("CABEND", cabend);
639 	PR_IS("DTIMSYNC", dtimsync);
640 	PR_IS("DTIM", dtim);
641 	PR_IS("TSFOOR", tsfoor);
642 	PR_IS("MCI", mci);
643 	PR_IS("GENTIMER", gen_timer);
644 	PR_IS("TOTAL", total);
645 
646 	len += snprintf(buf + len, mxlen - len,
647 			"SYNC_CAUSE stats:\n");
648 
649 	PR_IS("Sync-All", sync_cause_all);
650 	PR_IS("RTC-IRQ", sync_rtc_irq);
651 	PR_IS("MAC-IRQ", sync_mac_irq);
652 	PR_IS("EEPROM-Illegal-Access", eeprom_illegal_access);
653 	PR_IS("APB-Timeout", apb_timeout);
654 	PR_IS("PCI-Mode-Conflict", pci_mode_conflict);
655 	PR_IS("HOST1-Fatal", host1_fatal);
656 	PR_IS("HOST1-Perr", host1_perr);
657 	PR_IS("TRCV-FIFO-Perr", trcv_fifo_perr);
658 	PR_IS("RADM-CPL-EP", radm_cpl_ep);
659 	PR_IS("RADM-CPL-DLLP-Abort", radm_cpl_dllp_abort);
660 	PR_IS("RADM-CPL-TLP-Abort", radm_cpl_tlp_abort);
661 	PR_IS("RADM-CPL-ECRC-Err", radm_cpl_ecrc_err);
662 	PR_IS("RADM-CPL-Timeout", radm_cpl_timeout);
663 	PR_IS("Local-Bus-Timeout", local_timeout);
664 	PR_IS("PM-Access", pm_access);
665 	PR_IS("MAC-Awake", mac_awake);
666 	PR_IS("MAC-Asleep", mac_asleep);
667 	PR_IS("MAC-Sleep-Access", mac_sleep_access);
668 
669 	if (len > mxlen)
670 		len = mxlen;
671 
672 	rv = simple_read_from_buffer(user_buf, count, ppos, buf, len);
673 	kfree(buf);
674 	return rv;
675 }
676 
677 static const struct file_operations fops_interrupt = {
678 	.read = read_file_interrupt,
679 	.open = simple_open,
680 	.owner = THIS_MODULE,
681 	.llseek = default_llseek,
682 };
683 
684 static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
685 			      size_t count, loff_t *ppos)
686 {
687 	struct ath_softc *sc = file->private_data;
688 	char *buf;
689 	unsigned int len = 0, size = 2048;
690 	ssize_t retval = 0;
691 
692 	buf = kzalloc(size, GFP_KERNEL);
693 	if (buf == NULL)
694 		return -ENOMEM;
695 
696 	len += sprintf(buf, "%30s %10s%10s%10s\n\n",
697 		       "BE", "BK", "VI", "VO");
698 
699 	PR("MPDUs Queued:    ", queued);
700 	PR("MPDUs Completed: ", completed);
701 	PR("MPDUs XRetried:  ", xretries);
702 	PR("Aggregates:      ", a_aggr);
703 	PR("AMPDUs Queued HW:", a_queued_hw);
704 	PR("AMPDUs Queued SW:", a_queued_sw);
705 	PR("AMPDUs Completed:", a_completed);
706 	PR("AMPDUs Retried:  ", a_retries);
707 	PR("AMPDUs XRetried: ", a_xretries);
708 	PR("TXERR Filtered:  ", txerr_filtered);
709 	PR("FIFO Underrun:   ", fifo_underrun);
710 	PR("TXOP Exceeded:   ", xtxop);
711 	PR("TXTIMER Expiry:  ", timer_exp);
712 	PR("DESC CFG Error:  ", desc_cfg_err);
713 	PR("DATA Underrun:   ", data_underrun);
714 	PR("DELIM Underrun:  ", delim_underrun);
715 	PR("TX-Pkts-All:     ", tx_pkts_all);
716 	PR("TX-Bytes-All:    ", tx_bytes_all);
717 	PR("HW-put-tx-buf:   ", puttxbuf);
718 	PR("HW-tx-start:     ", txstart);
719 	PR("HW-tx-proc-desc: ", txprocdesc);
720 	PR("TX-Failed:       ", txfailed);
721 
722 	if (len > size)
723 		len = size;
724 
725 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
726 	kfree(buf);
727 
728 	return retval;
729 }
730 
731 static ssize_t read_file_queues(struct file *file, char __user *user_buf,
732 				size_t count, loff_t *ppos)
733 {
734 	struct ath_softc *sc = file->private_data;
735 	struct ath_txq *txq;
736 	char *buf;
737 	unsigned int len = 0, size = 1024;
738 	ssize_t retval = 0;
739 	int i;
740 	char *qname[4] = {"VO", "VI", "BE", "BK"};
741 
742 	buf = kzalloc(size, GFP_KERNEL);
743 	if (buf == NULL)
744 		return -ENOMEM;
745 
746 	for (i = 0; i < IEEE80211_NUM_ACS; i++) {
747 		txq = sc->tx.txq_map[i];
748 		len += snprintf(buf + len, size - len, "(%s): ", qname[i]);
749 
750 		ath_txq_lock(sc, txq);
751 
752 		len += snprintf(buf + len, size - len, "%s: %d ",
753 				"qnum", txq->axq_qnum);
754 		len += snprintf(buf + len, size - len, "%s: %2d ",
755 				"qdepth", txq->axq_depth);
756 		len += snprintf(buf + len, size - len, "%s: %2d ",
757 				"ampdu-depth", txq->axq_ampdu_depth);
758 		len += snprintf(buf + len, size - len, "%s: %3d ",
759 				"pending", txq->pending_frames);
760 		len += snprintf(buf + len, size - len, "%s: %d\n",
761 				"stopped", txq->stopped);
762 
763 		ath_txq_unlock(sc, txq);
764 	}
765 
766 	if (len > size)
767 		len = size;
768 
769 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
770 	kfree(buf);
771 
772 	return retval;
773 }
774 
775 static ssize_t read_file_misc(struct file *file, char __user *user_buf,
776 			      size_t count, loff_t *ppos)
777 {
778 	struct ath_softc *sc = file->private_data;
779 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
780 	struct ieee80211_hw *hw = sc->hw;
781 	struct ath9k_vif_iter_data iter_data;
782 	char buf[512];
783 	unsigned int len = 0;
784 	ssize_t retval = 0;
785 	unsigned int reg;
786 	u32 rxfilter;
787 
788 	len += snprintf(buf + len, sizeof(buf) - len,
789 			"BSSID: %pM\n", common->curbssid);
790 	len += snprintf(buf + len, sizeof(buf) - len,
791 			"BSSID-MASK: %pM\n", common->bssidmask);
792 	len += snprintf(buf + len, sizeof(buf) - len,
793 			"OPMODE: %s\n", ath_opmode_to_string(sc->sc_ah->opmode));
794 
795 	ath9k_ps_wakeup(sc);
796 	rxfilter = ath9k_hw_getrxfilter(sc->sc_ah);
797 	ath9k_ps_restore(sc);
798 
799 	len += snprintf(buf + len, sizeof(buf) - len,
800 			"RXFILTER: 0x%x", rxfilter);
801 
802 	if (rxfilter & ATH9K_RX_FILTER_UCAST)
803 		len += snprintf(buf + len, sizeof(buf) - len, " UCAST");
804 	if (rxfilter & ATH9K_RX_FILTER_MCAST)
805 		len += snprintf(buf + len, sizeof(buf) - len, " MCAST");
806 	if (rxfilter & ATH9K_RX_FILTER_BCAST)
807 		len += snprintf(buf + len, sizeof(buf) - len, " BCAST");
808 	if (rxfilter & ATH9K_RX_FILTER_CONTROL)
809 		len += snprintf(buf + len, sizeof(buf) - len, " CONTROL");
810 	if (rxfilter & ATH9K_RX_FILTER_BEACON)
811 		len += snprintf(buf + len, sizeof(buf) - len, " BEACON");
812 	if (rxfilter & ATH9K_RX_FILTER_PROM)
813 		len += snprintf(buf + len, sizeof(buf) - len, " PROM");
814 	if (rxfilter & ATH9K_RX_FILTER_PROBEREQ)
815 		len += snprintf(buf + len, sizeof(buf) - len, " PROBEREQ");
816 	if (rxfilter & ATH9K_RX_FILTER_PHYERR)
817 		len += snprintf(buf + len, sizeof(buf) - len, " PHYERR");
818 	if (rxfilter & ATH9K_RX_FILTER_MYBEACON)
819 		len += snprintf(buf + len, sizeof(buf) - len, " MYBEACON");
820 	if (rxfilter & ATH9K_RX_FILTER_COMP_BAR)
821 		len += snprintf(buf + len, sizeof(buf) - len, " COMP_BAR");
822 	if (rxfilter & ATH9K_RX_FILTER_PSPOLL)
823 		len += snprintf(buf + len, sizeof(buf) - len, " PSPOLL");
824 	if (rxfilter & ATH9K_RX_FILTER_PHYRADAR)
825 		len += snprintf(buf + len, sizeof(buf) - len, " PHYRADAR");
826 	if (rxfilter & ATH9K_RX_FILTER_MCAST_BCAST_ALL)
827 		len += snprintf(buf + len, sizeof(buf) - len, " MCAST_BCAST_ALL");
828 	if (rxfilter & ATH9K_RX_FILTER_CONTROL_WRAPPER)
829 		len += snprintf(buf + len, sizeof(buf) - len, " CONTROL_WRAPPER");
830 
831 	len += snprintf(buf + len, sizeof(buf) - len, "\n");
832 
833 	reg = sc->sc_ah->imask;
834 
835 	len += snprintf(buf + len, sizeof(buf) - len, "INTERRUPT-MASK: 0x%x", reg);
836 
837 	if (reg & ATH9K_INT_SWBA)
838 		len += snprintf(buf + len, sizeof(buf) - len, " SWBA");
839 	if (reg & ATH9K_INT_BMISS)
840 		len += snprintf(buf + len, sizeof(buf) - len, " BMISS");
841 	if (reg & ATH9K_INT_CST)
842 		len += snprintf(buf + len, sizeof(buf) - len, " CST");
843 	if (reg & ATH9K_INT_RX)
844 		len += snprintf(buf + len, sizeof(buf) - len, " RX");
845 	if (reg & ATH9K_INT_RXHP)
846 		len += snprintf(buf + len, sizeof(buf) - len, " RXHP");
847 	if (reg & ATH9K_INT_RXLP)
848 		len += snprintf(buf + len, sizeof(buf) - len, " RXLP");
849 	if (reg & ATH9K_INT_BB_WATCHDOG)
850 		len += snprintf(buf + len, sizeof(buf) - len, " BB_WATCHDOG");
851 
852 	len += snprintf(buf + len, sizeof(buf) - len, "\n");
853 
854 	ath9k_calculate_iter_data(hw, NULL, &iter_data);
855 
856 	len += snprintf(buf + len, sizeof(buf) - len,
857 			"VIF-COUNTS: AP: %i STA: %i MESH: %i WDS: %i"
858 			" ADHOC: %i TOTAL: %hi BEACON-VIF: %hi\n",
859 			iter_data.naps, iter_data.nstations, iter_data.nmeshes,
860 			iter_data.nwds, iter_data.nadhocs,
861 			sc->nvifs, sc->nbcnvifs);
862 
863 	if (len > sizeof(buf))
864 		len = sizeof(buf);
865 
866 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
867 	return retval;
868 }
869 
870 static ssize_t read_file_reset(struct file *file, char __user *user_buf,
871 			       size_t count, loff_t *ppos)
872 {
873 	struct ath_softc *sc = file->private_data;
874 	char buf[512];
875 	unsigned int len = 0;
876 
877 	len += snprintf(buf + len, sizeof(buf) - len,
878 			"%17s: %2d\n", "Baseband Hang",
879 			sc->debug.stats.reset[RESET_TYPE_BB_HANG]);
880 	len += snprintf(buf + len, sizeof(buf) - len,
881 			"%17s: %2d\n", "Baseband Watchdog",
882 			sc->debug.stats.reset[RESET_TYPE_BB_WATCHDOG]);
883 	len += snprintf(buf + len, sizeof(buf) - len,
884 			"%17s: %2d\n", "Fatal HW Error",
885 			sc->debug.stats.reset[RESET_TYPE_FATAL_INT]);
886 	len += snprintf(buf + len, sizeof(buf) - len,
887 			"%17s: %2d\n", "TX HW error",
888 			sc->debug.stats.reset[RESET_TYPE_TX_ERROR]);
889 	len += snprintf(buf + len, sizeof(buf) - len,
890 			"%17s: %2d\n", "TX Path Hang",
891 			sc->debug.stats.reset[RESET_TYPE_TX_HANG]);
892 	len += snprintf(buf + len, sizeof(buf) - len,
893 			"%17s: %2d\n", "PLL RX Hang",
894 			sc->debug.stats.reset[RESET_TYPE_PLL_HANG]);
895 	len += snprintf(buf + len, sizeof(buf) - len,
896 			"%17s: %2d\n", "MCI Reset",
897 			sc->debug.stats.reset[RESET_TYPE_MCI]);
898 
899 	if (len > sizeof(buf))
900 		len = sizeof(buf);
901 
902 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
903 }
904 
905 void ath_debug_stat_tx(struct ath_softc *sc, struct ath_buf *bf,
906 		       struct ath_tx_status *ts, struct ath_txq *txq,
907 		       unsigned int flags)
908 {
909 	int qnum = txq->axq_qnum;
910 
911 	TX_STAT_INC(qnum, tx_pkts_all);
912 	sc->debug.stats.txstats[qnum].tx_bytes_all += bf->bf_mpdu->len;
913 
914 	if (bf_isampdu(bf)) {
915 		if (flags & ATH_TX_ERROR)
916 			TX_STAT_INC(qnum, a_xretries);
917 		else
918 			TX_STAT_INC(qnum, a_completed);
919 	} else {
920 		if (ts->ts_status & ATH9K_TXERR_XRETRY)
921 			TX_STAT_INC(qnum, xretries);
922 		else
923 			TX_STAT_INC(qnum, completed);
924 	}
925 
926 	if (ts->ts_status & ATH9K_TXERR_FILT)
927 		TX_STAT_INC(qnum, txerr_filtered);
928 	if (ts->ts_status & ATH9K_TXERR_FIFO)
929 		TX_STAT_INC(qnum, fifo_underrun);
930 	if (ts->ts_status & ATH9K_TXERR_XTXOP)
931 		TX_STAT_INC(qnum, xtxop);
932 	if (ts->ts_status & ATH9K_TXERR_TIMER_EXPIRED)
933 		TX_STAT_INC(qnum, timer_exp);
934 	if (ts->ts_flags & ATH9K_TX_DESC_CFG_ERR)
935 		TX_STAT_INC(qnum, desc_cfg_err);
936 	if (ts->ts_flags & ATH9K_TX_DATA_UNDERRUN)
937 		TX_STAT_INC(qnum, data_underrun);
938 	if (ts->ts_flags & ATH9K_TX_DELIM_UNDERRUN)
939 		TX_STAT_INC(qnum, delim_underrun);
940 }
941 
942 static const struct file_operations fops_xmit = {
943 	.read = read_file_xmit,
944 	.open = simple_open,
945 	.owner = THIS_MODULE,
946 	.llseek = default_llseek,
947 };
948 
949 static const struct file_operations fops_queues = {
950 	.read = read_file_queues,
951 	.open = simple_open,
952 	.owner = THIS_MODULE,
953 	.llseek = default_llseek,
954 };
955 
956 static const struct file_operations fops_misc = {
957 	.read = read_file_misc,
958 	.open = simple_open,
959 	.owner = THIS_MODULE,
960 	.llseek = default_llseek,
961 };
962 
963 static const struct file_operations fops_reset = {
964 	.read = read_file_reset,
965 	.open = simple_open,
966 	.owner = THIS_MODULE,
967 	.llseek = default_llseek,
968 };
969 
970 static ssize_t read_file_recv(struct file *file, char __user *user_buf,
971 			      size_t count, loff_t *ppos)
972 {
973 #define PHY_ERR(s, p) \
974 	len += snprintf(buf + len, size - len, "%22s : %10u\n", s, \
975 			sc->debug.stats.rxstats.phy_err_stats[p]);
976 
977 #define RXS_ERR(s, e)					    \
978 	do {						    \
979 		len += snprintf(buf + len, size - len,	    \
980 				"%22s : %10u\n", s,	    \
981 				sc->debug.stats.rxstats.e); \
982 	} while (0)
983 
984 	struct ath_softc *sc = file->private_data;
985 	char *buf;
986 	unsigned int len = 0, size = 1600;
987 	ssize_t retval = 0;
988 
989 	buf = kzalloc(size, GFP_KERNEL);
990 	if (buf == NULL)
991 		return -ENOMEM;
992 
993 	RXS_ERR("CRC ERR", crc_err);
994 	RXS_ERR("DECRYPT CRC ERR", decrypt_crc_err);
995 	RXS_ERR("PHY ERR", phy_err);
996 	RXS_ERR("MIC ERR", mic_err);
997 	RXS_ERR("PRE-DELIM CRC ERR", pre_delim_crc_err);
998 	RXS_ERR("POST-DELIM CRC ERR", post_delim_crc_err);
999 	RXS_ERR("DECRYPT BUSY ERR", decrypt_busy_err);
1000 	RXS_ERR("RX-LENGTH-ERR", rx_len_err);
1001 	RXS_ERR("RX-OOM-ERR", rx_oom_err);
1002 	RXS_ERR("RX-RATE-ERR", rx_rate_err);
1003 	RXS_ERR("RX-TOO-MANY-FRAGS", rx_too_many_frags_err);
1004 
1005 	PHY_ERR("UNDERRUN ERR", ATH9K_PHYERR_UNDERRUN);
1006 	PHY_ERR("TIMING ERR", ATH9K_PHYERR_TIMING);
1007 	PHY_ERR("PARITY ERR", ATH9K_PHYERR_PARITY);
1008 	PHY_ERR("RATE ERR", ATH9K_PHYERR_RATE);
1009 	PHY_ERR("LENGTH ERR", ATH9K_PHYERR_LENGTH);
1010 	PHY_ERR("RADAR ERR", ATH9K_PHYERR_RADAR);
1011 	PHY_ERR("SERVICE ERR", ATH9K_PHYERR_SERVICE);
1012 	PHY_ERR("TOR ERR", ATH9K_PHYERR_TOR);
1013 	PHY_ERR("OFDM-TIMING ERR", ATH9K_PHYERR_OFDM_TIMING);
1014 	PHY_ERR("OFDM-SIGNAL-PARITY ERR", ATH9K_PHYERR_OFDM_SIGNAL_PARITY);
1015 	PHY_ERR("OFDM-RATE ERR", ATH9K_PHYERR_OFDM_RATE_ILLEGAL);
1016 	PHY_ERR("OFDM-LENGTH ERR", ATH9K_PHYERR_OFDM_LENGTH_ILLEGAL);
1017 	PHY_ERR("OFDM-POWER-DROP ERR", ATH9K_PHYERR_OFDM_POWER_DROP);
1018 	PHY_ERR("OFDM-SERVICE ERR", ATH9K_PHYERR_OFDM_SERVICE);
1019 	PHY_ERR("OFDM-RESTART ERR", ATH9K_PHYERR_OFDM_RESTART);
1020 	PHY_ERR("FALSE-RADAR-EXT ERR", ATH9K_PHYERR_FALSE_RADAR_EXT);
1021 	PHY_ERR("CCK-TIMING ERR", ATH9K_PHYERR_CCK_TIMING);
1022 	PHY_ERR("CCK-HEADER-CRC ERR", ATH9K_PHYERR_CCK_HEADER_CRC);
1023 	PHY_ERR("CCK-RATE ERR", ATH9K_PHYERR_CCK_RATE_ILLEGAL);
1024 	PHY_ERR("CCK-SERVICE ERR", ATH9K_PHYERR_CCK_SERVICE);
1025 	PHY_ERR("CCK-RESTART ERR", ATH9K_PHYERR_CCK_RESTART);
1026 	PHY_ERR("CCK-LENGTH ERR", ATH9K_PHYERR_CCK_LENGTH_ILLEGAL);
1027 	PHY_ERR("CCK-POWER-DROP ERR", ATH9K_PHYERR_CCK_POWER_DROP);
1028 	PHY_ERR("HT-CRC ERR", ATH9K_PHYERR_HT_CRC_ERROR);
1029 	PHY_ERR("HT-LENGTH ERR", ATH9K_PHYERR_HT_LENGTH_ILLEGAL);
1030 	PHY_ERR("HT-RATE ERR", ATH9K_PHYERR_HT_RATE_ILLEGAL);
1031 
1032 	RXS_ERR("RX-Pkts-All", rx_pkts_all);
1033 	RXS_ERR("RX-Bytes-All", rx_bytes_all);
1034 	RXS_ERR("RX-Beacons", rx_beacons);
1035 	RXS_ERR("RX-Frags", rx_frags);
1036 	RXS_ERR("RX-Spectral", rx_spectral);
1037 
1038 	if (len > size)
1039 		len = size;
1040 
1041 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1042 	kfree(buf);
1043 
1044 	return retval;
1045 
1046 #undef RXS_ERR
1047 #undef PHY_ERR
1048 }
1049 
1050 void ath_debug_stat_rx(struct ath_softc *sc, struct ath_rx_status *rs)
1051 {
1052 #define RX_PHY_ERR_INC(c) sc->debug.stats.rxstats.phy_err_stats[c]++
1053 
1054 	RX_STAT_INC(rx_pkts_all);
1055 	sc->debug.stats.rxstats.rx_bytes_all += rs->rs_datalen;
1056 
1057 	if (rs->rs_status & ATH9K_RXERR_CRC)
1058 		RX_STAT_INC(crc_err);
1059 	if (rs->rs_status & ATH9K_RXERR_DECRYPT)
1060 		RX_STAT_INC(decrypt_crc_err);
1061 	if (rs->rs_status & ATH9K_RXERR_MIC)
1062 		RX_STAT_INC(mic_err);
1063 	if (rs->rs_status & ATH9K_RX_DELIM_CRC_PRE)
1064 		RX_STAT_INC(pre_delim_crc_err);
1065 	if (rs->rs_status & ATH9K_RX_DELIM_CRC_POST)
1066 		RX_STAT_INC(post_delim_crc_err);
1067 	if (rs->rs_status & ATH9K_RX_DECRYPT_BUSY)
1068 		RX_STAT_INC(decrypt_busy_err);
1069 
1070 	if (rs->rs_status & ATH9K_RXERR_PHY) {
1071 		RX_STAT_INC(phy_err);
1072 		if (rs->rs_phyerr < ATH9K_PHYERR_MAX)
1073 			RX_PHY_ERR_INC(rs->rs_phyerr);
1074 	}
1075 
1076 #undef RX_PHY_ERR_INC
1077 }
1078 
1079 static const struct file_operations fops_recv = {
1080 	.read = read_file_recv,
1081 	.open = simple_open,
1082 	.owner = THIS_MODULE,
1083 	.llseek = default_llseek,
1084 };
1085 
1086 static ssize_t read_file_spec_scan_ctl(struct file *file, char __user *user_buf,
1087 				       size_t count, loff_t *ppos)
1088 {
1089 	struct ath_softc *sc = file->private_data;
1090 	char *mode = "";
1091 	unsigned int len;
1092 
1093 	switch (sc->spectral_mode) {
1094 	case SPECTRAL_DISABLED:
1095 		mode = "disable";
1096 		break;
1097 	case SPECTRAL_BACKGROUND:
1098 		mode = "background";
1099 		break;
1100 	case SPECTRAL_CHANSCAN:
1101 		mode = "chanscan";
1102 		break;
1103 	case SPECTRAL_MANUAL:
1104 		mode = "manual";
1105 		break;
1106 	}
1107 	len = strlen(mode);
1108 	return simple_read_from_buffer(user_buf, count, ppos, mode, len);
1109 }
1110 
1111 static ssize_t write_file_spec_scan_ctl(struct file *file,
1112 					const char __user *user_buf,
1113 					size_t count, loff_t *ppos)
1114 {
1115 	struct ath_softc *sc = file->private_data;
1116 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1117 	char buf[32];
1118 	ssize_t len;
1119 
1120 	len = min(count, sizeof(buf) - 1);
1121 	if (copy_from_user(buf, user_buf, len))
1122 		return -EFAULT;
1123 
1124 	buf[len] = '\0';
1125 
1126 	if (strncmp("trigger", buf, 7) == 0) {
1127 		ath9k_spectral_scan_trigger(sc->hw);
1128 	} else if (strncmp("background", buf, 9) == 0) {
1129 		ath9k_spectral_scan_config(sc->hw, SPECTRAL_BACKGROUND);
1130 		ath_dbg(common, CONFIG, "spectral scan: background mode enabled\n");
1131 	} else if (strncmp("chanscan", buf, 8) == 0) {
1132 		ath9k_spectral_scan_config(sc->hw, SPECTRAL_CHANSCAN);
1133 		ath_dbg(common, CONFIG, "spectral scan: channel scan mode enabled\n");
1134 	} else if (strncmp("manual", buf, 6) == 0) {
1135 		ath9k_spectral_scan_config(sc->hw, SPECTRAL_MANUAL);
1136 		ath_dbg(common, CONFIG, "spectral scan: manual mode enabled\n");
1137 	} else if (strncmp("disable", buf, 7) == 0) {
1138 		ath9k_spectral_scan_config(sc->hw, SPECTRAL_DISABLED);
1139 		ath_dbg(common, CONFIG, "spectral scan: disabled\n");
1140 	} else {
1141 		return -EINVAL;
1142 	}
1143 
1144 	return count;
1145 }
1146 
1147 static const struct file_operations fops_spec_scan_ctl = {
1148 	.read = read_file_spec_scan_ctl,
1149 	.write = write_file_spec_scan_ctl,
1150 	.open = simple_open,
1151 	.owner = THIS_MODULE,
1152 	.llseek = default_llseek,
1153 };
1154 
1155 static ssize_t read_file_spectral_short_repeat(struct file *file,
1156 					       char __user *user_buf,
1157 					       size_t count, loff_t *ppos)
1158 {
1159 	struct ath_softc *sc = file->private_data;
1160 	char buf[32];
1161 	unsigned int len;
1162 
1163 	len = sprintf(buf, "%d\n", sc->spec_config.short_repeat);
1164 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1165 }
1166 
1167 static ssize_t write_file_spectral_short_repeat(struct file *file,
1168 						const char __user *user_buf,
1169 						size_t count, loff_t *ppos)
1170 {
1171 	struct ath_softc *sc = file->private_data;
1172 	unsigned long val;
1173 	char buf[32];
1174 	ssize_t len;
1175 
1176 	len = min(count, sizeof(buf) - 1);
1177 	if (copy_from_user(buf, user_buf, len))
1178 		return -EFAULT;
1179 
1180 	buf[len] = '\0';
1181 	if (kstrtoul(buf, 0, &val))
1182 		return -EINVAL;
1183 
1184 	if (val < 0 || val > 1)
1185 		return -EINVAL;
1186 
1187 	sc->spec_config.short_repeat = val;
1188 	return count;
1189 }
1190 
1191 static const struct file_operations fops_spectral_short_repeat = {
1192 	.read = read_file_spectral_short_repeat,
1193 	.write = write_file_spectral_short_repeat,
1194 	.open = simple_open,
1195 	.owner = THIS_MODULE,
1196 	.llseek = default_llseek,
1197 };
1198 
1199 static ssize_t read_file_spectral_count(struct file *file,
1200 					char __user *user_buf,
1201 					size_t count, loff_t *ppos)
1202 {
1203 	struct ath_softc *sc = file->private_data;
1204 	char buf[32];
1205 	unsigned int len;
1206 
1207 	len = sprintf(buf, "%d\n", sc->spec_config.count);
1208 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1209 }
1210 
1211 static ssize_t write_file_spectral_count(struct file *file,
1212 					 const char __user *user_buf,
1213 					 size_t count, loff_t *ppos)
1214 {
1215 	struct ath_softc *sc = file->private_data;
1216 	unsigned long val;
1217 	char buf[32];
1218 	ssize_t len;
1219 
1220 	len = min(count, sizeof(buf) - 1);
1221 	if (copy_from_user(buf, user_buf, len))
1222 		return -EFAULT;
1223 
1224 	buf[len] = '\0';
1225 	if (kstrtoul(buf, 0, &val))
1226 		return -EINVAL;
1227 
1228 	if (val < 0 || val > 255)
1229 		return -EINVAL;
1230 
1231 	sc->spec_config.count = val;
1232 	return count;
1233 }
1234 
1235 static const struct file_operations fops_spectral_count = {
1236 	.read = read_file_spectral_count,
1237 	.write = write_file_spectral_count,
1238 	.open = simple_open,
1239 	.owner = THIS_MODULE,
1240 	.llseek = default_llseek,
1241 };
1242 
1243 static ssize_t read_file_spectral_period(struct file *file,
1244 					 char __user *user_buf,
1245 					 size_t count, loff_t *ppos)
1246 {
1247 	struct ath_softc *sc = file->private_data;
1248 	char buf[32];
1249 	unsigned int len;
1250 
1251 	len = sprintf(buf, "%d\n", sc->spec_config.period);
1252 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1253 }
1254 
1255 static ssize_t write_file_spectral_period(struct file *file,
1256 					  const char __user *user_buf,
1257 					  size_t count, loff_t *ppos)
1258 {
1259 	struct ath_softc *sc = file->private_data;
1260 	unsigned long val;
1261 	char buf[32];
1262 	ssize_t len;
1263 
1264 	len = min(count, sizeof(buf) - 1);
1265 	if (copy_from_user(buf, user_buf, len))
1266 		return -EFAULT;
1267 
1268 	buf[len] = '\0';
1269 	if (kstrtoul(buf, 0, &val))
1270 		return -EINVAL;
1271 
1272 	if (val < 0 || val > 255)
1273 		return -EINVAL;
1274 
1275 	sc->spec_config.period = val;
1276 	return count;
1277 }
1278 
1279 static const struct file_operations fops_spectral_period = {
1280 	.read = read_file_spectral_period,
1281 	.write = write_file_spectral_period,
1282 	.open = simple_open,
1283 	.owner = THIS_MODULE,
1284 	.llseek = default_llseek,
1285 };
1286 
1287 static ssize_t read_file_spectral_fft_period(struct file *file,
1288 					     char __user *user_buf,
1289 					     size_t count, loff_t *ppos)
1290 {
1291 	struct ath_softc *sc = file->private_data;
1292 	char buf[32];
1293 	unsigned int len;
1294 
1295 	len = sprintf(buf, "%d\n", sc->spec_config.fft_period);
1296 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1297 }
1298 
1299 static ssize_t write_file_spectral_fft_period(struct file *file,
1300 					      const char __user *user_buf,
1301 					      size_t count, loff_t *ppos)
1302 {
1303 	struct ath_softc *sc = file->private_data;
1304 	unsigned long val;
1305 	char buf[32];
1306 	ssize_t len;
1307 
1308 	len = min(count, sizeof(buf) - 1);
1309 	if (copy_from_user(buf, user_buf, len))
1310 		return -EFAULT;
1311 
1312 	buf[len] = '\0';
1313 	if (kstrtoul(buf, 0, &val))
1314 		return -EINVAL;
1315 
1316 	if (val < 0 || val > 15)
1317 		return -EINVAL;
1318 
1319 	sc->spec_config.fft_period = val;
1320 	return count;
1321 }
1322 
1323 static const struct file_operations fops_spectral_fft_period = {
1324 	.read = read_file_spectral_fft_period,
1325 	.write = write_file_spectral_fft_period,
1326 	.open = simple_open,
1327 	.owner = THIS_MODULE,
1328 	.llseek = default_llseek,
1329 };
1330 
1331 static struct dentry *create_buf_file_handler(const char *filename,
1332 					      struct dentry *parent,
1333 					      umode_t mode,
1334 					      struct rchan_buf *buf,
1335 					      int *is_global)
1336 {
1337 	struct dentry *buf_file;
1338 
1339 	buf_file = debugfs_create_file(filename, mode, parent, buf,
1340 				       &relay_file_operations);
1341 	*is_global = 1;
1342 	return buf_file;
1343 }
1344 
1345 static int remove_buf_file_handler(struct dentry *dentry)
1346 {
1347 	debugfs_remove(dentry);
1348 
1349 	return 0;
1350 }
1351 
1352 void ath_debug_send_fft_sample(struct ath_softc *sc,
1353 			       struct fft_sample_tlv *fft_sample_tlv)
1354 {
1355 	int length;
1356 	if (!sc->rfs_chan_spec_scan)
1357 		return;
1358 
1359 	length = __be16_to_cpu(fft_sample_tlv->length) +
1360 		 sizeof(*fft_sample_tlv);
1361 	relay_write(sc->rfs_chan_spec_scan, fft_sample_tlv, length);
1362 }
1363 
1364 static struct rchan_callbacks rfs_spec_scan_cb = {
1365 	.create_buf_file = create_buf_file_handler,
1366 	.remove_buf_file = remove_buf_file_handler,
1367 };
1368 
1369 
1370 static ssize_t read_file_regidx(struct file *file, char __user *user_buf,
1371                                 size_t count, loff_t *ppos)
1372 {
1373 	struct ath_softc *sc = file->private_data;
1374 	char buf[32];
1375 	unsigned int len;
1376 
1377 	len = sprintf(buf, "0x%08x\n", sc->debug.regidx);
1378 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1379 }
1380 
1381 static ssize_t write_file_regidx(struct file *file, const char __user *user_buf,
1382 			     size_t count, loff_t *ppos)
1383 {
1384 	struct ath_softc *sc = file->private_data;
1385 	unsigned long regidx;
1386 	char buf[32];
1387 	ssize_t len;
1388 
1389 	len = min(count, sizeof(buf) - 1);
1390 	if (copy_from_user(buf, user_buf, len))
1391 		return -EFAULT;
1392 
1393 	buf[len] = '\0';
1394 	if (kstrtoul(buf, 0, &regidx))
1395 		return -EINVAL;
1396 
1397 	sc->debug.regidx = regidx;
1398 	return count;
1399 }
1400 
1401 static const struct file_operations fops_regidx = {
1402 	.read = read_file_regidx,
1403 	.write = write_file_regidx,
1404 	.open = simple_open,
1405 	.owner = THIS_MODULE,
1406 	.llseek = default_llseek,
1407 };
1408 
1409 static ssize_t read_file_regval(struct file *file, char __user *user_buf,
1410 			     size_t count, loff_t *ppos)
1411 {
1412 	struct ath_softc *sc = file->private_data;
1413 	struct ath_hw *ah = sc->sc_ah;
1414 	char buf[32];
1415 	unsigned int len;
1416 	u32 regval;
1417 
1418 	ath9k_ps_wakeup(sc);
1419 	regval = REG_READ_D(ah, sc->debug.regidx);
1420 	ath9k_ps_restore(sc);
1421 	len = sprintf(buf, "0x%08x\n", regval);
1422 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1423 }
1424 
1425 static ssize_t write_file_regval(struct file *file, const char __user *user_buf,
1426 			     size_t count, loff_t *ppos)
1427 {
1428 	struct ath_softc *sc = file->private_data;
1429 	struct ath_hw *ah = sc->sc_ah;
1430 	unsigned long regval;
1431 	char buf[32];
1432 	ssize_t len;
1433 
1434 	len = min(count, sizeof(buf) - 1);
1435 	if (copy_from_user(buf, user_buf, len))
1436 		return -EFAULT;
1437 
1438 	buf[len] = '\0';
1439 	if (kstrtoul(buf, 0, &regval))
1440 		return -EINVAL;
1441 
1442 	ath9k_ps_wakeup(sc);
1443 	REG_WRITE_D(ah, sc->debug.regidx, regval);
1444 	ath9k_ps_restore(sc);
1445 	return count;
1446 }
1447 
1448 static const struct file_operations fops_regval = {
1449 	.read = read_file_regval,
1450 	.write = write_file_regval,
1451 	.open = simple_open,
1452 	.owner = THIS_MODULE,
1453 	.llseek = default_llseek,
1454 };
1455 
1456 #define REGDUMP_LINE_SIZE	20
1457 
1458 static int open_file_regdump(struct inode *inode, struct file *file)
1459 {
1460 	struct ath_softc *sc = inode->i_private;
1461 	unsigned int len = 0;
1462 	u8 *buf;
1463 	int i;
1464 	unsigned long num_regs, regdump_len, max_reg_offset;
1465 
1466 	max_reg_offset = AR_SREV_9300_20_OR_LATER(sc->sc_ah) ? 0x16bd4 : 0xb500;
1467 	num_regs = max_reg_offset / 4 + 1;
1468 	regdump_len = num_regs * REGDUMP_LINE_SIZE + 1;
1469 	buf = vmalloc(regdump_len);
1470 	if (!buf)
1471 		return -ENOMEM;
1472 
1473 	ath9k_ps_wakeup(sc);
1474 	for (i = 0; i < num_regs; i++)
1475 		len += scnprintf(buf + len, regdump_len - len,
1476 			"0x%06x 0x%08x\n", i << 2, REG_READ(sc->sc_ah, i << 2));
1477 	ath9k_ps_restore(sc);
1478 
1479 	file->private_data = buf;
1480 
1481 	return 0;
1482 }
1483 
1484 static const struct file_operations fops_regdump = {
1485 	.open = open_file_regdump,
1486 	.read = ath9k_debugfs_read_buf,
1487 	.release = ath9k_debugfs_release_buf,
1488 	.owner = THIS_MODULE,
1489 	.llseek = default_llseek,/* read accesses f_pos */
1490 };
1491 
1492 static ssize_t read_file_dump_nfcal(struct file *file, char __user *user_buf,
1493 				    size_t count, loff_t *ppos)
1494 {
1495 	struct ath_softc *sc = file->private_data;
1496 	struct ath_hw *ah = sc->sc_ah;
1497 	struct ath9k_nfcal_hist *h = sc->caldata.nfCalHist;
1498 	struct ath_common *common = ath9k_hw_common(ah);
1499 	struct ieee80211_conf *conf = &common->hw->conf;
1500 	u32 len = 0, size = 1500;
1501 	u32 i, j;
1502 	ssize_t retval = 0;
1503 	char *buf;
1504 	u8 chainmask = (ah->rxchainmask << 3) | ah->rxchainmask;
1505 	u8 nread;
1506 
1507 	buf = kzalloc(size, GFP_KERNEL);
1508 	if (!buf)
1509 		return -ENOMEM;
1510 
1511 	len += snprintf(buf + len, size - len,
1512 			"Channel Noise Floor : %d\n", ah->noise);
1513 	len += snprintf(buf + len, size - len,
1514 			"Chain | privNF | # Readings | NF Readings\n");
1515 	for (i = 0; i < NUM_NF_READINGS; i++) {
1516 		if (!(chainmask & (1 << i)) ||
1517 		    ((i >= AR5416_MAX_CHAINS) && !conf_is_ht40(conf)))
1518 			continue;
1519 
1520 		nread = AR_PHY_CCA_FILTERWINDOW_LENGTH - h[i].invalidNFcount;
1521 		len += snprintf(buf + len, size - len, " %d\t %d\t %d\t\t",
1522 				i, h[i].privNF, nread);
1523 		for (j = 0; j < nread; j++)
1524 			len += snprintf(buf + len, size - len,
1525 					" %d", h[i].nfCalBuffer[j]);
1526 		len += snprintf(buf + len, size - len, "\n");
1527 	}
1528 
1529 	if (len > size)
1530 		len = size;
1531 
1532 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1533 	kfree(buf);
1534 
1535 	return retval;
1536 }
1537 
1538 static const struct file_operations fops_dump_nfcal = {
1539 	.read = read_file_dump_nfcal,
1540 	.open = simple_open,
1541 	.owner = THIS_MODULE,
1542 	.llseek = default_llseek,
1543 };
1544 
1545 static ssize_t read_file_base_eeprom(struct file *file, char __user *user_buf,
1546 				     size_t count, loff_t *ppos)
1547 {
1548 	struct ath_softc *sc = file->private_data;
1549 	struct ath_hw *ah = sc->sc_ah;
1550 	u32 len = 0, size = 1500;
1551 	ssize_t retval = 0;
1552 	char *buf;
1553 
1554 	buf = kzalloc(size, GFP_KERNEL);
1555 	if (!buf)
1556 		return -ENOMEM;
1557 
1558 	len = ah->eep_ops->dump_eeprom(ah, true, buf, len, size);
1559 
1560 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1561 	kfree(buf);
1562 
1563 	return retval;
1564 }
1565 
1566 static const struct file_operations fops_base_eeprom = {
1567 	.read = read_file_base_eeprom,
1568 	.open = simple_open,
1569 	.owner = THIS_MODULE,
1570 	.llseek = default_llseek,
1571 };
1572 
1573 static ssize_t read_file_modal_eeprom(struct file *file, char __user *user_buf,
1574 				      size_t count, loff_t *ppos)
1575 {
1576 	struct ath_softc *sc = file->private_data;
1577 	struct ath_hw *ah = sc->sc_ah;
1578 	u32 len = 0, size = 6000;
1579 	char *buf;
1580 	size_t retval;
1581 
1582 	buf = kzalloc(size, GFP_KERNEL);
1583 	if (buf == NULL)
1584 		return -ENOMEM;
1585 
1586 	len = ah->eep_ops->dump_eeprom(ah, false, buf, len, size);
1587 
1588 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1589 	kfree(buf);
1590 
1591 	return retval;
1592 }
1593 
1594 static const struct file_operations fops_modal_eeprom = {
1595 	.read = read_file_modal_eeprom,
1596 	.open = simple_open,
1597 	.owner = THIS_MODULE,
1598 	.llseek = default_llseek,
1599 };
1600 
1601 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
1602 static ssize_t read_file_btcoex(struct file *file, char __user *user_buf,
1603 				size_t count, loff_t *ppos)
1604 {
1605 	struct ath_softc *sc = file->private_data;
1606 	u32 len = 0, size = 1500;
1607 	char *buf;
1608 	size_t retval;
1609 
1610 	buf = kzalloc(size, GFP_KERNEL);
1611 	if (buf == NULL)
1612 		return -ENOMEM;
1613 
1614 	if (!sc->sc_ah->common.btcoex_enabled) {
1615 		len = snprintf(buf, size, "%s\n",
1616 			       "BTCOEX is disabled");
1617 		goto exit;
1618 	}
1619 
1620 	len = ath9k_dump_btcoex(sc, buf, size);
1621 exit:
1622 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1623 	kfree(buf);
1624 
1625 	return retval;
1626 }
1627 
1628 static const struct file_operations fops_btcoex = {
1629 	.read = read_file_btcoex,
1630 	.open = simple_open,
1631 	.owner = THIS_MODULE,
1632 	.llseek = default_llseek,
1633 };
1634 #endif
1635 
1636 static ssize_t read_file_node_stat(struct file *file, char __user *user_buf,
1637 				   size_t count, loff_t *ppos)
1638 {
1639 	struct ath_node *an = file->private_data;
1640 	struct ath_softc *sc = an->sc;
1641 	struct ath_atx_tid *tid;
1642 	struct ath_atx_ac *ac;
1643 	struct ath_txq *txq;
1644 	u32 len = 0, size = 4096;
1645 	char *buf;
1646 	size_t retval;
1647 	int tidno, acno;
1648 
1649 	buf = kzalloc(size, GFP_KERNEL);
1650 	if (buf == NULL)
1651 		return -ENOMEM;
1652 
1653 	if (!an->sta->ht_cap.ht_supported) {
1654 		len = snprintf(buf, size, "%s\n",
1655 			       "HT not supported");
1656 		goto exit;
1657 	}
1658 
1659 	len = snprintf(buf, size, "Max-AMPDU: %d\n",
1660 		       an->maxampdu);
1661 	len += snprintf(buf + len, size - len, "MPDU Density: %d\n\n",
1662 			an->mpdudensity);
1663 
1664 	len += snprintf(buf + len, size - len,
1665 			"%2s%7s\n", "AC", "SCHED");
1666 
1667 	for (acno = 0, ac = &an->ac[acno];
1668 	     acno < IEEE80211_NUM_ACS; acno++, ac++) {
1669 		txq = ac->txq;
1670 		ath_txq_lock(sc, txq);
1671 		len += snprintf(buf + len, size - len,
1672 				"%2d%7d\n",
1673 				acno, ac->sched);
1674 		ath_txq_unlock(sc, txq);
1675 	}
1676 
1677 	len += snprintf(buf + len, size - len,
1678 			"\n%3s%11s%10s%10s%10s%10s%9s%6s%8s\n",
1679 			"TID", "SEQ_START", "SEQ_NEXT", "BAW_SIZE",
1680 			"BAW_HEAD", "BAW_TAIL", "BAR_IDX", "SCHED", "PAUSED");
1681 
1682 	for (tidno = 0, tid = &an->tid[tidno];
1683 	     tidno < IEEE80211_NUM_TIDS; tidno++, tid++) {
1684 		txq = tid->ac->txq;
1685 		ath_txq_lock(sc, txq);
1686 		len += snprintf(buf + len, size - len,
1687 				"%3d%11d%10d%10d%10d%10d%9d%6d%8d\n",
1688 				tid->tidno, tid->seq_start, tid->seq_next,
1689 				tid->baw_size, tid->baw_head, tid->baw_tail,
1690 				tid->bar_index, tid->sched, tid->paused);
1691 		ath_txq_unlock(sc, txq);
1692 	}
1693 exit:
1694 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1695 	kfree(buf);
1696 
1697 	return retval;
1698 }
1699 
1700 static const struct file_operations fops_node_stat = {
1701 	.read = read_file_node_stat,
1702 	.open = simple_open,
1703 	.owner = THIS_MODULE,
1704 	.llseek = default_llseek,
1705 };
1706 
1707 void ath9k_sta_add_debugfs(struct ieee80211_hw *hw,
1708 			   struct ieee80211_vif *vif,
1709 			   struct ieee80211_sta *sta,
1710 			   struct dentry *dir)
1711 {
1712 	struct ath_node *an = (struct ath_node *)sta->drv_priv;
1713 	an->node_stat = debugfs_create_file("node_stat", S_IRUGO,
1714 					    dir, an, &fops_node_stat);
1715 }
1716 
1717 void ath9k_sta_remove_debugfs(struct ieee80211_hw *hw,
1718 			      struct ieee80211_vif *vif,
1719 			      struct ieee80211_sta *sta,
1720 			      struct dentry *dir)
1721 {
1722 	struct ath_node *an = (struct ath_node *)sta->drv_priv;
1723 	debugfs_remove(an->node_stat);
1724 }
1725 
1726 /* Ethtool support for get-stats */
1727 
1728 #define AMKSTR(nm) #nm "_BE", #nm "_BK", #nm "_VI", #nm "_VO"
1729 static const char ath9k_gstrings_stats[][ETH_GSTRING_LEN] = {
1730 	"tx_pkts_nic",
1731 	"tx_bytes_nic",
1732 	"rx_pkts_nic",
1733 	"rx_bytes_nic",
1734 	AMKSTR(d_tx_pkts),
1735 	AMKSTR(d_tx_bytes),
1736 	AMKSTR(d_tx_mpdus_queued),
1737 	AMKSTR(d_tx_mpdus_completed),
1738 	AMKSTR(d_tx_mpdu_xretries),
1739 	AMKSTR(d_tx_aggregates),
1740 	AMKSTR(d_tx_ampdus_queued_hw),
1741 	AMKSTR(d_tx_ampdus_queued_sw),
1742 	AMKSTR(d_tx_ampdus_completed),
1743 	AMKSTR(d_tx_ampdu_retries),
1744 	AMKSTR(d_tx_ampdu_xretries),
1745 	AMKSTR(d_tx_fifo_underrun),
1746 	AMKSTR(d_tx_op_exceeded),
1747 	AMKSTR(d_tx_timer_expiry),
1748 	AMKSTR(d_tx_desc_cfg_err),
1749 	AMKSTR(d_tx_data_underrun),
1750 	AMKSTR(d_tx_delim_underrun),
1751 	"d_rx_crc_err",
1752 	"d_rx_decrypt_crc_err",
1753 	"d_rx_phy_err",
1754 	"d_rx_mic_err",
1755 	"d_rx_pre_delim_crc_err",
1756 	"d_rx_post_delim_crc_err",
1757 	"d_rx_decrypt_busy_err",
1758 
1759 	"d_rx_phyerr_radar",
1760 	"d_rx_phyerr_ofdm_timing",
1761 	"d_rx_phyerr_cck_timing",
1762 
1763 };
1764 #define ATH9K_SSTATS_LEN ARRAY_SIZE(ath9k_gstrings_stats)
1765 
1766 void ath9k_get_et_strings(struct ieee80211_hw *hw,
1767 			  struct ieee80211_vif *vif,
1768 			  u32 sset, u8 *data)
1769 {
1770 	if (sset == ETH_SS_STATS)
1771 		memcpy(data, *ath9k_gstrings_stats,
1772 		       sizeof(ath9k_gstrings_stats));
1773 }
1774 
1775 int ath9k_get_et_sset_count(struct ieee80211_hw *hw,
1776 			    struct ieee80211_vif *vif, int sset)
1777 {
1778 	if (sset == ETH_SS_STATS)
1779 		return ATH9K_SSTATS_LEN;
1780 	return 0;
1781 }
1782 
1783 #define AWDATA(elem)							\
1784 	do {								\
1785 		data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].elem; \
1786 		data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].elem; \
1787 		data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].elem; \
1788 		data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].elem; \
1789 	} while (0)
1790 
1791 #define AWDATA_RX(elem)						\
1792 	do {							\
1793 		data[i++] = sc->debug.stats.rxstats.elem;	\
1794 	} while (0)
1795 
1796 void ath9k_get_et_stats(struct ieee80211_hw *hw,
1797 			struct ieee80211_vif *vif,
1798 			struct ethtool_stats *stats, u64 *data)
1799 {
1800 	struct ath_softc *sc = hw->priv;
1801 	int i = 0;
1802 
1803 	data[i++] = (sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].tx_pkts_all +
1804 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].tx_pkts_all +
1805 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].tx_pkts_all +
1806 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].tx_pkts_all);
1807 	data[i++] = (sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].tx_bytes_all +
1808 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].tx_bytes_all +
1809 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].tx_bytes_all +
1810 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].tx_bytes_all);
1811 	AWDATA_RX(rx_pkts_all);
1812 	AWDATA_RX(rx_bytes_all);
1813 
1814 	AWDATA(tx_pkts_all);
1815 	AWDATA(tx_bytes_all);
1816 	AWDATA(queued);
1817 	AWDATA(completed);
1818 	AWDATA(xretries);
1819 	AWDATA(a_aggr);
1820 	AWDATA(a_queued_hw);
1821 	AWDATA(a_queued_sw);
1822 	AWDATA(a_completed);
1823 	AWDATA(a_retries);
1824 	AWDATA(a_xretries);
1825 	AWDATA(fifo_underrun);
1826 	AWDATA(xtxop);
1827 	AWDATA(timer_exp);
1828 	AWDATA(desc_cfg_err);
1829 	AWDATA(data_underrun);
1830 	AWDATA(delim_underrun);
1831 
1832 	AWDATA_RX(crc_err);
1833 	AWDATA_RX(decrypt_crc_err);
1834 	AWDATA_RX(phy_err);
1835 	AWDATA_RX(mic_err);
1836 	AWDATA_RX(pre_delim_crc_err);
1837 	AWDATA_RX(post_delim_crc_err);
1838 	AWDATA_RX(decrypt_busy_err);
1839 
1840 	AWDATA_RX(phy_err_stats[ATH9K_PHYERR_RADAR]);
1841 	AWDATA_RX(phy_err_stats[ATH9K_PHYERR_OFDM_TIMING]);
1842 	AWDATA_RX(phy_err_stats[ATH9K_PHYERR_CCK_TIMING]);
1843 
1844 	WARN_ON(i != ATH9K_SSTATS_LEN);
1845 }
1846 
1847 void ath9k_deinit_debug(struct ath_softc *sc)
1848 {
1849 	if (config_enabled(CONFIG_ATH9K_DEBUGFS) && sc->rfs_chan_spec_scan) {
1850 		relay_close(sc->rfs_chan_spec_scan);
1851 		sc->rfs_chan_spec_scan = NULL;
1852 	}
1853 }
1854 
1855 int ath9k_init_debug(struct ath_hw *ah)
1856 {
1857 	struct ath_common *common = ath9k_hw_common(ah);
1858 	struct ath_softc *sc = (struct ath_softc *) common->priv;
1859 
1860 	sc->debug.debugfs_phy = debugfs_create_dir("ath9k",
1861 						   sc->hw->wiphy->debugfsdir);
1862 	if (!sc->debug.debugfs_phy)
1863 		return -ENOMEM;
1864 
1865 #ifdef CONFIG_ATH_DEBUG
1866 	debugfs_create_file("debug", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1867 			    sc, &fops_debug);
1868 #endif
1869 
1870 	ath9k_dfs_init_debug(sc);
1871 
1872 	debugfs_create_file("dma", S_IRUSR, sc->debug.debugfs_phy, sc,
1873 			    &fops_dma);
1874 	debugfs_create_file("interrupt", S_IRUSR, sc->debug.debugfs_phy, sc,
1875 			    &fops_interrupt);
1876 	debugfs_create_file("xmit", S_IRUSR, sc->debug.debugfs_phy, sc,
1877 			    &fops_xmit);
1878 	debugfs_create_file("queues", S_IRUSR, sc->debug.debugfs_phy, sc,
1879 			    &fops_queues);
1880 	debugfs_create_u32("qlen_bk", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1881 			   &sc->tx.txq_max_pending[IEEE80211_AC_BK]);
1882 	debugfs_create_u32("qlen_be", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1883 			   &sc->tx.txq_max_pending[IEEE80211_AC_BE]);
1884 	debugfs_create_u32("qlen_vi", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1885 			   &sc->tx.txq_max_pending[IEEE80211_AC_VI]);
1886 	debugfs_create_u32("qlen_vo", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1887 			   &sc->tx.txq_max_pending[IEEE80211_AC_VO]);
1888 	debugfs_create_file("misc", S_IRUSR, sc->debug.debugfs_phy, sc,
1889 			    &fops_misc);
1890 	debugfs_create_file("reset", S_IRUSR, sc->debug.debugfs_phy, sc,
1891 			    &fops_reset);
1892 	debugfs_create_file("recv", S_IRUSR, sc->debug.debugfs_phy, sc,
1893 			    &fops_recv);
1894 	debugfs_create_file("rx_chainmask", S_IRUSR | S_IWUSR,
1895 			    sc->debug.debugfs_phy, sc, &fops_rx_chainmask);
1896 	debugfs_create_file("tx_chainmask", S_IRUSR | S_IWUSR,
1897 			    sc->debug.debugfs_phy, sc, &fops_tx_chainmask);
1898 	debugfs_create_file("ani", S_IRUSR | S_IWUSR,
1899 			    sc->debug.debugfs_phy, sc, &fops_ani);
1900 	debugfs_create_bool("paprd", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1901 			    &sc->sc_ah->config.enable_paprd);
1902 	debugfs_create_file("regidx", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1903 			    sc, &fops_regidx);
1904 	debugfs_create_file("regval", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1905 			    sc, &fops_regval);
1906 	debugfs_create_bool("ignore_extcca", S_IRUSR | S_IWUSR,
1907 			    sc->debug.debugfs_phy,
1908 			    &ah->config.cwm_ignore_extcca);
1909 	debugfs_create_file("regdump", S_IRUSR, sc->debug.debugfs_phy, sc,
1910 			    &fops_regdump);
1911 	debugfs_create_file("dump_nfcal", S_IRUSR, sc->debug.debugfs_phy, sc,
1912 			    &fops_dump_nfcal);
1913 	debugfs_create_file("base_eeprom", S_IRUSR, sc->debug.debugfs_phy, sc,
1914 			    &fops_base_eeprom);
1915 	debugfs_create_file("modal_eeprom", S_IRUSR, sc->debug.debugfs_phy, sc,
1916 			    &fops_modal_eeprom);
1917 	sc->rfs_chan_spec_scan = relay_open("spectral_scan",
1918 					    sc->debug.debugfs_phy,
1919 					    1024, 256, &rfs_spec_scan_cb,
1920 					    NULL);
1921 	debugfs_create_file("spectral_scan_ctl", S_IRUSR | S_IWUSR,
1922 			    sc->debug.debugfs_phy, sc,
1923 			    &fops_spec_scan_ctl);
1924 	debugfs_create_file("spectral_short_repeat", S_IRUSR | S_IWUSR,
1925 			    sc->debug.debugfs_phy, sc,
1926 			    &fops_spectral_short_repeat);
1927 	debugfs_create_file("spectral_count", S_IRUSR | S_IWUSR,
1928 			    sc->debug.debugfs_phy, sc, &fops_spectral_count);
1929 	debugfs_create_file("spectral_period", S_IRUSR | S_IWUSR,
1930 			    sc->debug.debugfs_phy, sc, &fops_spectral_period);
1931 	debugfs_create_file("spectral_fft_period", S_IRUSR | S_IWUSR,
1932 			    sc->debug.debugfs_phy, sc,
1933 			    &fops_spectral_fft_period);
1934 	debugfs_create_u32("gpio_mask", S_IRUSR | S_IWUSR,
1935 			   sc->debug.debugfs_phy, &sc->sc_ah->gpio_mask);
1936 	debugfs_create_u32("gpio_val", S_IRUSR | S_IWUSR,
1937 			   sc->debug.debugfs_phy, &sc->sc_ah->gpio_val);
1938 	debugfs_create_file("bt_ant_diversity", S_IRUSR | S_IWUSR,
1939 			    sc->debug.debugfs_phy, sc, &fops_bt_ant_diversity);
1940 	debugfs_create_file("antenna_diversity", S_IRUSR,
1941 			    sc->debug.debugfs_phy, sc, &fops_antenna_diversity);
1942 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
1943 	debugfs_create_file("btcoex", S_IRUSR, sc->debug.debugfs_phy, sc,
1944 			    &fops_btcoex);
1945 #endif
1946 	return 0;
1947 }
1948