xref: /OK3568_Linux_fs/kernel/drivers/net/wireless/ath/ath9k/debug.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Copyright (c) 2008-2011 Atheros Communications Inc.
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Permission to use, copy, modify, and/or distribute this software for any
5*4882a593Smuzhiyun  * purpose with or without fee is hereby granted, provided that the above
6*4882a593Smuzhiyun  * copyright notice and this permission notice appear in all copies.
7*4882a593Smuzhiyun  *
8*4882a593Smuzhiyun  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9*4882a593Smuzhiyun  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10*4882a593Smuzhiyun  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11*4882a593Smuzhiyun  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12*4882a593Smuzhiyun  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13*4882a593Smuzhiyun  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14*4882a593Smuzhiyun  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15*4882a593Smuzhiyun  */
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun #include <linux/slab.h>
18*4882a593Smuzhiyun #include <linux/vmalloc.h>
19*4882a593Smuzhiyun #include <linux/export.h>
20*4882a593Smuzhiyun #include <asm/unaligned.h>
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun #include "ath9k.h"
23*4882a593Smuzhiyun 
24*4882a593Smuzhiyun #define REG_WRITE_D(_ah, _reg, _val) \
25*4882a593Smuzhiyun 	ath9k_hw_common(_ah)->ops->write((_ah), (_val), (_reg))
26*4882a593Smuzhiyun #define REG_READ_D(_ah, _reg) \
27*4882a593Smuzhiyun 	ath9k_hw_common(_ah)->ops->read((_ah), (_reg))
28*4882a593Smuzhiyun 
ath9k_debug_sync_cause(struct ath_softc * sc,u32 sync_cause)29*4882a593Smuzhiyun void ath9k_debug_sync_cause(struct ath_softc *sc, u32 sync_cause)
30*4882a593Smuzhiyun {
31*4882a593Smuzhiyun 	if (sync_cause)
32*4882a593Smuzhiyun 		sc->debug.stats.istats.sync_cause_all++;
33*4882a593Smuzhiyun 	if (sync_cause & AR_INTR_SYNC_RTC_IRQ)
34*4882a593Smuzhiyun 		sc->debug.stats.istats.sync_rtc_irq++;
35*4882a593Smuzhiyun 	if (sync_cause & AR_INTR_SYNC_MAC_IRQ)
36*4882a593Smuzhiyun 		sc->debug.stats.istats.sync_mac_irq++;
37*4882a593Smuzhiyun 	if (sync_cause & AR_INTR_SYNC_EEPROM_ILLEGAL_ACCESS)
38*4882a593Smuzhiyun 		sc->debug.stats.istats.eeprom_illegal_access++;
39*4882a593Smuzhiyun 	if (sync_cause & AR_INTR_SYNC_APB_TIMEOUT)
40*4882a593Smuzhiyun 		sc->debug.stats.istats.apb_timeout++;
41*4882a593Smuzhiyun 	if (sync_cause & AR_INTR_SYNC_PCI_MODE_CONFLICT)
42*4882a593Smuzhiyun 		sc->debug.stats.istats.pci_mode_conflict++;
43*4882a593Smuzhiyun 	if (sync_cause & AR_INTR_SYNC_HOST1_FATAL)
44*4882a593Smuzhiyun 		sc->debug.stats.istats.host1_fatal++;
45*4882a593Smuzhiyun 	if (sync_cause & AR_INTR_SYNC_HOST1_PERR)
46*4882a593Smuzhiyun 		sc->debug.stats.istats.host1_perr++;
47*4882a593Smuzhiyun 	if (sync_cause & AR_INTR_SYNC_TRCV_FIFO_PERR)
48*4882a593Smuzhiyun 		sc->debug.stats.istats.trcv_fifo_perr++;
49*4882a593Smuzhiyun 	if (sync_cause & AR_INTR_SYNC_RADM_CPL_EP)
50*4882a593Smuzhiyun 		sc->debug.stats.istats.radm_cpl_ep++;
51*4882a593Smuzhiyun 	if (sync_cause & AR_INTR_SYNC_RADM_CPL_DLLP_ABORT)
52*4882a593Smuzhiyun 		sc->debug.stats.istats.radm_cpl_dllp_abort++;
53*4882a593Smuzhiyun 	if (sync_cause & AR_INTR_SYNC_RADM_CPL_TLP_ABORT)
54*4882a593Smuzhiyun 		sc->debug.stats.istats.radm_cpl_tlp_abort++;
55*4882a593Smuzhiyun 	if (sync_cause & AR_INTR_SYNC_RADM_CPL_ECRC_ERR)
56*4882a593Smuzhiyun 		sc->debug.stats.istats.radm_cpl_ecrc_err++;
57*4882a593Smuzhiyun 	if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT)
58*4882a593Smuzhiyun 		sc->debug.stats.istats.radm_cpl_timeout++;
59*4882a593Smuzhiyun 	if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT)
60*4882a593Smuzhiyun 		sc->debug.stats.istats.local_timeout++;
61*4882a593Smuzhiyun 	if (sync_cause & AR_INTR_SYNC_PM_ACCESS)
62*4882a593Smuzhiyun 		sc->debug.stats.istats.pm_access++;
63*4882a593Smuzhiyun 	if (sync_cause & AR_INTR_SYNC_MAC_AWAKE)
64*4882a593Smuzhiyun 		sc->debug.stats.istats.mac_awake++;
65*4882a593Smuzhiyun 	if (sync_cause & AR_INTR_SYNC_MAC_ASLEEP)
66*4882a593Smuzhiyun 		sc->debug.stats.istats.mac_asleep++;
67*4882a593Smuzhiyun 	if (sync_cause & AR_INTR_SYNC_MAC_SLEEP_ACCESS)
68*4882a593Smuzhiyun 		sc->debug.stats.istats.mac_sleep_access++;
69*4882a593Smuzhiyun }
70*4882a593Smuzhiyun 
ath9k_debugfs_read_buf(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)71*4882a593Smuzhiyun static ssize_t ath9k_debugfs_read_buf(struct file *file, char __user *user_buf,
72*4882a593Smuzhiyun 				      size_t count, loff_t *ppos)
73*4882a593Smuzhiyun {
74*4882a593Smuzhiyun 	u8 *buf = file->private_data;
75*4882a593Smuzhiyun 	return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
76*4882a593Smuzhiyun }
77*4882a593Smuzhiyun 
ath9k_debugfs_release_buf(struct inode * inode,struct file * file)78*4882a593Smuzhiyun static int ath9k_debugfs_release_buf(struct inode *inode, struct file *file)
79*4882a593Smuzhiyun {
80*4882a593Smuzhiyun 	vfree(file->private_data);
81*4882a593Smuzhiyun 	return 0;
82*4882a593Smuzhiyun }
83*4882a593Smuzhiyun 
84*4882a593Smuzhiyun #ifdef CONFIG_ATH_DEBUG
85*4882a593Smuzhiyun 
read_file_debug(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)86*4882a593Smuzhiyun static ssize_t read_file_debug(struct file *file, char __user *user_buf,
87*4882a593Smuzhiyun 			     size_t count, loff_t *ppos)
88*4882a593Smuzhiyun {
89*4882a593Smuzhiyun 	struct ath_softc *sc = file->private_data;
90*4882a593Smuzhiyun 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
91*4882a593Smuzhiyun 	char buf[32];
92*4882a593Smuzhiyun 	unsigned int len;
93*4882a593Smuzhiyun 
94*4882a593Smuzhiyun 	len = sprintf(buf, "0x%08x\n", common->debug_mask);
95*4882a593Smuzhiyun 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
96*4882a593Smuzhiyun }
97*4882a593Smuzhiyun 
write_file_debug(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)98*4882a593Smuzhiyun static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
99*4882a593Smuzhiyun 			     size_t count, loff_t *ppos)
100*4882a593Smuzhiyun {
101*4882a593Smuzhiyun 	struct ath_softc *sc = file->private_data;
102*4882a593Smuzhiyun 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
103*4882a593Smuzhiyun 	unsigned long mask;
104*4882a593Smuzhiyun 	char buf[32];
105*4882a593Smuzhiyun 	ssize_t len;
106*4882a593Smuzhiyun 
107*4882a593Smuzhiyun 	len = min(count, sizeof(buf) - 1);
108*4882a593Smuzhiyun 	if (copy_from_user(buf, user_buf, len))
109*4882a593Smuzhiyun 		return -EFAULT;
110*4882a593Smuzhiyun 
111*4882a593Smuzhiyun 	buf[len] = '\0';
112*4882a593Smuzhiyun 	if (kstrtoul(buf, 0, &mask))
113*4882a593Smuzhiyun 		return -EINVAL;
114*4882a593Smuzhiyun 
115*4882a593Smuzhiyun 	common->debug_mask = mask;
116*4882a593Smuzhiyun 	return count;
117*4882a593Smuzhiyun }
118*4882a593Smuzhiyun 
119*4882a593Smuzhiyun static const struct file_operations fops_debug = {
120*4882a593Smuzhiyun 	.read = read_file_debug,
121*4882a593Smuzhiyun 	.write = write_file_debug,
122*4882a593Smuzhiyun 	.open = simple_open,
123*4882a593Smuzhiyun 	.owner = THIS_MODULE,
124*4882a593Smuzhiyun 	.llseek = default_llseek,
125*4882a593Smuzhiyun };
126*4882a593Smuzhiyun 
127*4882a593Smuzhiyun #endif
128*4882a593Smuzhiyun 
129*4882a593Smuzhiyun #define DMA_BUF_LEN 1024
130*4882a593Smuzhiyun 
131*4882a593Smuzhiyun 
read_file_ani(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)132*4882a593Smuzhiyun static ssize_t read_file_ani(struct file *file, char __user *user_buf,
133*4882a593Smuzhiyun 			     size_t count, loff_t *ppos)
134*4882a593Smuzhiyun {
135*4882a593Smuzhiyun 	struct ath_softc *sc = file->private_data;
136*4882a593Smuzhiyun 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
137*4882a593Smuzhiyun 	struct ath_hw *ah = sc->sc_ah;
138*4882a593Smuzhiyun 	unsigned int len = 0;
139*4882a593Smuzhiyun 	const unsigned int size = 1024;
140*4882a593Smuzhiyun 	ssize_t retval = 0;
141*4882a593Smuzhiyun 	char *buf;
142*4882a593Smuzhiyun 	int i;
143*4882a593Smuzhiyun 	struct {
144*4882a593Smuzhiyun 		const char *name;
145*4882a593Smuzhiyun 		unsigned int val;
146*4882a593Smuzhiyun 	} ani_info[] = {
147*4882a593Smuzhiyun 		{ "ANI RESET", ah->stats.ast_ani_reset },
148*4882a593Smuzhiyun 		{ "OFDM LEVEL", ah->ani.ofdmNoiseImmunityLevel },
149*4882a593Smuzhiyun 		{ "CCK LEVEL", ah->ani.cckNoiseImmunityLevel },
150*4882a593Smuzhiyun 		{ "SPUR UP", ah->stats.ast_ani_spurup },
151*4882a593Smuzhiyun 		{ "SPUR DOWN", ah->stats.ast_ani_spurdown },
152*4882a593Smuzhiyun 		{ "OFDM WS-DET ON", ah->stats.ast_ani_ofdmon },
153*4882a593Smuzhiyun 		{ "OFDM WS-DET OFF", ah->stats.ast_ani_ofdmoff },
154*4882a593Smuzhiyun 		{ "MRC-CCK ON", ah->stats.ast_ani_ccklow },
155*4882a593Smuzhiyun 		{ "MRC-CCK OFF", ah->stats.ast_ani_cckhigh },
156*4882a593Smuzhiyun 		{ "FIR-STEP UP", ah->stats.ast_ani_stepup },
157*4882a593Smuzhiyun 		{ "FIR-STEP DOWN", ah->stats.ast_ani_stepdown },
158*4882a593Smuzhiyun 		{ "INV LISTENTIME", ah->stats.ast_ani_lneg_or_lzero },
159*4882a593Smuzhiyun 		{ "OFDM ERRORS", ah->stats.ast_ani_ofdmerrs },
160*4882a593Smuzhiyun 		{ "CCK ERRORS", ah->stats.ast_ani_cckerrs },
161*4882a593Smuzhiyun 	};
162*4882a593Smuzhiyun 
163*4882a593Smuzhiyun 	buf = kzalloc(size, GFP_KERNEL);
164*4882a593Smuzhiyun 	if (buf == NULL)
165*4882a593Smuzhiyun 		return -ENOMEM;
166*4882a593Smuzhiyun 
167*4882a593Smuzhiyun 	len += scnprintf(buf + len, size - len, "%15s: %s\n", "ANI",
168*4882a593Smuzhiyun 			 common->disable_ani ? "DISABLED" : "ENABLED");
169*4882a593Smuzhiyun 
170*4882a593Smuzhiyun 	if (common->disable_ani)
171*4882a593Smuzhiyun 		goto exit;
172*4882a593Smuzhiyun 
173*4882a593Smuzhiyun 	for (i = 0; i < ARRAY_SIZE(ani_info); i++)
174*4882a593Smuzhiyun 		len += scnprintf(buf + len, size - len, "%15s: %u\n",
175*4882a593Smuzhiyun 				 ani_info[i].name, ani_info[i].val);
176*4882a593Smuzhiyun 
177*4882a593Smuzhiyun exit:
178*4882a593Smuzhiyun 	if (len > size)
179*4882a593Smuzhiyun 		len = size;
180*4882a593Smuzhiyun 
181*4882a593Smuzhiyun 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
182*4882a593Smuzhiyun 	kfree(buf);
183*4882a593Smuzhiyun 
184*4882a593Smuzhiyun 	return retval;
185*4882a593Smuzhiyun }
186*4882a593Smuzhiyun 
write_file_ani(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)187*4882a593Smuzhiyun static ssize_t write_file_ani(struct file *file,
188*4882a593Smuzhiyun 			      const char __user *user_buf,
189*4882a593Smuzhiyun 			      size_t count, loff_t *ppos)
190*4882a593Smuzhiyun {
191*4882a593Smuzhiyun 	struct ath_softc *sc = file->private_data;
192*4882a593Smuzhiyun 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
193*4882a593Smuzhiyun 	unsigned long ani;
194*4882a593Smuzhiyun 	char buf[32];
195*4882a593Smuzhiyun 	ssize_t len;
196*4882a593Smuzhiyun 
197*4882a593Smuzhiyun 	len = min(count, sizeof(buf) - 1);
198*4882a593Smuzhiyun 	if (copy_from_user(buf, user_buf, len))
199*4882a593Smuzhiyun 		return -EFAULT;
200*4882a593Smuzhiyun 
201*4882a593Smuzhiyun 	buf[len] = '\0';
202*4882a593Smuzhiyun 	if (kstrtoul(buf, 0, &ani))
203*4882a593Smuzhiyun 		return -EINVAL;
204*4882a593Smuzhiyun 
205*4882a593Smuzhiyun 	if (ani > 1)
206*4882a593Smuzhiyun 		return -EINVAL;
207*4882a593Smuzhiyun 
208*4882a593Smuzhiyun 	common->disable_ani = !ani;
209*4882a593Smuzhiyun 
210*4882a593Smuzhiyun 	if (common->disable_ani) {
211*4882a593Smuzhiyun 		clear_bit(ATH_OP_ANI_RUN, &common->op_flags);
212*4882a593Smuzhiyun 		ath_stop_ani(sc);
213*4882a593Smuzhiyun 	} else {
214*4882a593Smuzhiyun 		ath_check_ani(sc);
215*4882a593Smuzhiyun 	}
216*4882a593Smuzhiyun 
217*4882a593Smuzhiyun 	return count;
218*4882a593Smuzhiyun }
219*4882a593Smuzhiyun 
220*4882a593Smuzhiyun static const struct file_operations fops_ani = {
221*4882a593Smuzhiyun 	.read = read_file_ani,
222*4882a593Smuzhiyun 	.write = write_file_ani,
223*4882a593Smuzhiyun 	.open = simple_open,
224*4882a593Smuzhiyun 	.owner = THIS_MODULE,
225*4882a593Smuzhiyun 	.llseek = default_llseek,
226*4882a593Smuzhiyun };
227*4882a593Smuzhiyun 
228*4882a593Smuzhiyun #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
229*4882a593Smuzhiyun 
read_file_bt_ant_diversity(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)230*4882a593Smuzhiyun static ssize_t read_file_bt_ant_diversity(struct file *file,
231*4882a593Smuzhiyun 					  char __user *user_buf,
232*4882a593Smuzhiyun 					  size_t count, loff_t *ppos)
233*4882a593Smuzhiyun {
234*4882a593Smuzhiyun 	struct ath_softc *sc = file->private_data;
235*4882a593Smuzhiyun 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
236*4882a593Smuzhiyun 	char buf[32];
237*4882a593Smuzhiyun 	unsigned int len;
238*4882a593Smuzhiyun 
239*4882a593Smuzhiyun 	len = sprintf(buf, "%d\n", common->bt_ant_diversity);
240*4882a593Smuzhiyun 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
241*4882a593Smuzhiyun }
242*4882a593Smuzhiyun 
write_file_bt_ant_diversity(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)243*4882a593Smuzhiyun static ssize_t write_file_bt_ant_diversity(struct file *file,
244*4882a593Smuzhiyun 					   const char __user *user_buf,
245*4882a593Smuzhiyun 					   size_t count, loff_t *ppos)
246*4882a593Smuzhiyun {
247*4882a593Smuzhiyun 	struct ath_softc *sc = file->private_data;
248*4882a593Smuzhiyun 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
249*4882a593Smuzhiyun 	struct ath9k_hw_capabilities *pCap = &sc->sc_ah->caps;
250*4882a593Smuzhiyun 	unsigned long bt_ant_diversity;
251*4882a593Smuzhiyun 	char buf[32];
252*4882a593Smuzhiyun 	ssize_t len;
253*4882a593Smuzhiyun 
254*4882a593Smuzhiyun 	len = min(count, sizeof(buf) - 1);
255*4882a593Smuzhiyun 	if (copy_from_user(buf, user_buf, len))
256*4882a593Smuzhiyun 		return -EFAULT;
257*4882a593Smuzhiyun 
258*4882a593Smuzhiyun 	if (!(pCap->hw_caps & ATH9K_HW_CAP_BT_ANT_DIV))
259*4882a593Smuzhiyun 		goto exit;
260*4882a593Smuzhiyun 
261*4882a593Smuzhiyun 	buf[len] = '\0';
262*4882a593Smuzhiyun 	if (kstrtoul(buf, 0, &bt_ant_diversity))
263*4882a593Smuzhiyun 		return -EINVAL;
264*4882a593Smuzhiyun 
265*4882a593Smuzhiyun 	common->bt_ant_diversity = !!bt_ant_diversity;
266*4882a593Smuzhiyun 	ath9k_ps_wakeup(sc);
267*4882a593Smuzhiyun 	ath9k_hw_set_bt_ant_diversity(sc->sc_ah, common->bt_ant_diversity);
268*4882a593Smuzhiyun 	ath_dbg(common, CONFIG, "Enable WLAN/BT RX Antenna diversity: %d\n",
269*4882a593Smuzhiyun 		common->bt_ant_diversity);
270*4882a593Smuzhiyun 	ath9k_ps_restore(sc);
271*4882a593Smuzhiyun exit:
272*4882a593Smuzhiyun 	return count;
273*4882a593Smuzhiyun }
274*4882a593Smuzhiyun 
275*4882a593Smuzhiyun static const struct file_operations fops_bt_ant_diversity = {
276*4882a593Smuzhiyun 	.read = read_file_bt_ant_diversity,
277*4882a593Smuzhiyun 	.write = write_file_bt_ant_diversity,
278*4882a593Smuzhiyun 	.open = simple_open,
279*4882a593Smuzhiyun 	.owner = THIS_MODULE,
280*4882a593Smuzhiyun 	.llseek = default_llseek,
281*4882a593Smuzhiyun };
282*4882a593Smuzhiyun 
283*4882a593Smuzhiyun #endif
284*4882a593Smuzhiyun 
ath9k_debug_stat_ant(struct ath_softc * sc,struct ath_hw_antcomb_conf * div_ant_conf,int main_rssi_avg,int alt_rssi_avg)285*4882a593Smuzhiyun void ath9k_debug_stat_ant(struct ath_softc *sc,
286*4882a593Smuzhiyun 			  struct ath_hw_antcomb_conf *div_ant_conf,
287*4882a593Smuzhiyun 			  int main_rssi_avg, int alt_rssi_avg)
288*4882a593Smuzhiyun {
289*4882a593Smuzhiyun 	struct ath_antenna_stats *as_main = &sc->debug.stats.ant_stats[ANT_MAIN];
290*4882a593Smuzhiyun 	struct ath_antenna_stats *as_alt = &sc->debug.stats.ant_stats[ANT_ALT];
291*4882a593Smuzhiyun 
292*4882a593Smuzhiyun 	as_main->lna_attempt_cnt[div_ant_conf->main_lna_conf]++;
293*4882a593Smuzhiyun 	as_alt->lna_attempt_cnt[div_ant_conf->alt_lna_conf]++;
294*4882a593Smuzhiyun 
295*4882a593Smuzhiyun 	as_main->rssi_avg = main_rssi_avg;
296*4882a593Smuzhiyun 	as_alt->rssi_avg = alt_rssi_avg;
297*4882a593Smuzhiyun }
298*4882a593Smuzhiyun 
read_file_antenna_diversity(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)299*4882a593Smuzhiyun static ssize_t read_file_antenna_diversity(struct file *file,
300*4882a593Smuzhiyun 					   char __user *user_buf,
301*4882a593Smuzhiyun 					   size_t count, loff_t *ppos)
302*4882a593Smuzhiyun {
303*4882a593Smuzhiyun 	struct ath_softc *sc = file->private_data;
304*4882a593Smuzhiyun 	struct ath_hw *ah = sc->sc_ah;
305*4882a593Smuzhiyun 	struct ath9k_hw_capabilities *pCap = &ah->caps;
306*4882a593Smuzhiyun 	struct ath_antenna_stats *as_main = &sc->debug.stats.ant_stats[ANT_MAIN];
307*4882a593Smuzhiyun 	struct ath_antenna_stats *as_alt = &sc->debug.stats.ant_stats[ANT_ALT];
308*4882a593Smuzhiyun 	struct ath_hw_antcomb_conf div_ant_conf;
309*4882a593Smuzhiyun 	unsigned int len = 0;
310*4882a593Smuzhiyun 	const unsigned int size = 1024;
311*4882a593Smuzhiyun 	ssize_t retval = 0;
312*4882a593Smuzhiyun 	char *buf;
313*4882a593Smuzhiyun 	static const char *lna_conf_str[4] = {
314*4882a593Smuzhiyun 		"LNA1_MINUS_LNA2", "LNA2", "LNA1", "LNA1_PLUS_LNA2"
315*4882a593Smuzhiyun 	};
316*4882a593Smuzhiyun 
317*4882a593Smuzhiyun 	buf = kzalloc(size, GFP_KERNEL);
318*4882a593Smuzhiyun 	if (buf == NULL)
319*4882a593Smuzhiyun 		return -ENOMEM;
320*4882a593Smuzhiyun 
321*4882a593Smuzhiyun 	if (!(pCap->hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)) {
322*4882a593Smuzhiyun 		len += scnprintf(buf + len, size - len, "%s\n",
323*4882a593Smuzhiyun 				 "Antenna Diversity Combining is disabled");
324*4882a593Smuzhiyun 		goto exit;
325*4882a593Smuzhiyun 	}
326*4882a593Smuzhiyun 
327*4882a593Smuzhiyun 	ath9k_ps_wakeup(sc);
328*4882a593Smuzhiyun 	ath9k_hw_antdiv_comb_conf_get(ah, &div_ant_conf);
329*4882a593Smuzhiyun 	len += scnprintf(buf + len, size - len, "Current MAIN config : %s\n",
330*4882a593Smuzhiyun 			 lna_conf_str[div_ant_conf.main_lna_conf]);
331*4882a593Smuzhiyun 	len += scnprintf(buf + len, size - len, "Current ALT config  : %s\n",
332*4882a593Smuzhiyun 			 lna_conf_str[div_ant_conf.alt_lna_conf]);
333*4882a593Smuzhiyun 	len += scnprintf(buf + len, size - len, "Average MAIN RSSI   : %d\n",
334*4882a593Smuzhiyun 			 as_main->rssi_avg);
335*4882a593Smuzhiyun 	len += scnprintf(buf + len, size - len, "Average ALT RSSI    : %d\n\n",
336*4882a593Smuzhiyun 			 as_alt->rssi_avg);
337*4882a593Smuzhiyun 	ath9k_ps_restore(sc);
338*4882a593Smuzhiyun 
339*4882a593Smuzhiyun 	len += scnprintf(buf + len, size - len, "Packet Receive Cnt:\n");
340*4882a593Smuzhiyun 	len += scnprintf(buf + len, size - len, "-------------------\n");
341*4882a593Smuzhiyun 
342*4882a593Smuzhiyun 	len += scnprintf(buf + len, size - len, "%30s%15s\n",
343*4882a593Smuzhiyun 			 "MAIN", "ALT");
344*4882a593Smuzhiyun 	len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
345*4882a593Smuzhiyun 			 "TOTAL COUNT",
346*4882a593Smuzhiyun 			 as_main->recv_cnt,
347*4882a593Smuzhiyun 			 as_alt->recv_cnt);
348*4882a593Smuzhiyun 	len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
349*4882a593Smuzhiyun 			 "LNA1",
350*4882a593Smuzhiyun 			 as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1],
351*4882a593Smuzhiyun 			 as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1]);
352*4882a593Smuzhiyun 	len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
353*4882a593Smuzhiyun 			 "LNA2",
354*4882a593Smuzhiyun 			 as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA2],
355*4882a593Smuzhiyun 			 as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA2]);
356*4882a593Smuzhiyun 	len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
357*4882a593Smuzhiyun 			 "LNA1 + LNA2",
358*4882a593Smuzhiyun 			 as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2],
359*4882a593Smuzhiyun 			 as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2]);
360*4882a593Smuzhiyun 	len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
361*4882a593Smuzhiyun 			 "LNA1 - LNA2",
362*4882a593Smuzhiyun 			 as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2],
363*4882a593Smuzhiyun 			 as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2]);
364*4882a593Smuzhiyun 
365*4882a593Smuzhiyun 	len += scnprintf(buf + len, size - len, "\nLNA Config Attempts:\n");
366*4882a593Smuzhiyun 	len += scnprintf(buf + len, size - len, "--------------------\n");
367*4882a593Smuzhiyun 
368*4882a593Smuzhiyun 	len += scnprintf(buf + len, size - len, "%30s%15s\n",
369*4882a593Smuzhiyun 			 "MAIN", "ALT");
370*4882a593Smuzhiyun 	len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
371*4882a593Smuzhiyun 			 "LNA1",
372*4882a593Smuzhiyun 			 as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1],
373*4882a593Smuzhiyun 			 as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1]);
374*4882a593Smuzhiyun 	len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
375*4882a593Smuzhiyun 			 "LNA2",
376*4882a593Smuzhiyun 			 as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA2],
377*4882a593Smuzhiyun 			 as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA2]);
378*4882a593Smuzhiyun 	len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
379*4882a593Smuzhiyun 			 "LNA1 + LNA2",
380*4882a593Smuzhiyun 			 as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2],
381*4882a593Smuzhiyun 			 as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2]);
382*4882a593Smuzhiyun 	len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
383*4882a593Smuzhiyun 			 "LNA1 - LNA2",
384*4882a593Smuzhiyun 			 as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2],
385*4882a593Smuzhiyun 			 as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2]);
386*4882a593Smuzhiyun 
387*4882a593Smuzhiyun exit:
388*4882a593Smuzhiyun 	if (len > size)
389*4882a593Smuzhiyun 		len = size;
390*4882a593Smuzhiyun 
391*4882a593Smuzhiyun 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
392*4882a593Smuzhiyun 	kfree(buf);
393*4882a593Smuzhiyun 
394*4882a593Smuzhiyun 	return retval;
395*4882a593Smuzhiyun }
396*4882a593Smuzhiyun 
397*4882a593Smuzhiyun static const struct file_operations fops_antenna_diversity = {
398*4882a593Smuzhiyun 	.read = read_file_antenna_diversity,
399*4882a593Smuzhiyun 	.open = simple_open,
400*4882a593Smuzhiyun 	.owner = THIS_MODULE,
401*4882a593Smuzhiyun 	.llseek = default_llseek,
402*4882a593Smuzhiyun };
403*4882a593Smuzhiyun 
read_file_dma(struct seq_file * file,void * data)404*4882a593Smuzhiyun static int read_file_dma(struct seq_file *file, void *data)
405*4882a593Smuzhiyun {
406*4882a593Smuzhiyun 	struct ieee80211_hw *hw = dev_get_drvdata(file->private);
407*4882a593Smuzhiyun 	struct ath_softc *sc = hw->priv;
408*4882a593Smuzhiyun 	struct ath_hw *ah = sc->sc_ah;
409*4882a593Smuzhiyun 	u32 val[ATH9K_NUM_DMA_DEBUG_REGS];
410*4882a593Smuzhiyun 	int i, qcuOffset = 0, dcuOffset = 0;
411*4882a593Smuzhiyun 	u32 *qcuBase = &val[0], *dcuBase = &val[4];
412*4882a593Smuzhiyun 
413*4882a593Smuzhiyun 	ath9k_ps_wakeup(sc);
414*4882a593Smuzhiyun 
415*4882a593Smuzhiyun 	REG_WRITE_D(ah, AR_MACMISC,
416*4882a593Smuzhiyun 		  ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) |
417*4882a593Smuzhiyun 		   (AR_MACMISC_MISC_OBS_BUS_1 <<
418*4882a593Smuzhiyun 		    AR_MACMISC_MISC_OBS_BUS_MSB_S)));
419*4882a593Smuzhiyun 
420*4882a593Smuzhiyun 	seq_puts(file, "Raw DMA Debug values:\n");
421*4882a593Smuzhiyun 
422*4882a593Smuzhiyun 	for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) {
423*4882a593Smuzhiyun 		if (i % 4 == 0)
424*4882a593Smuzhiyun 			seq_puts(file, "\n");
425*4882a593Smuzhiyun 
426*4882a593Smuzhiyun 		val[i] = REG_READ_D(ah, AR_DMADBG_0 + (i * sizeof(u32)));
427*4882a593Smuzhiyun 		seq_printf(file, "%d: %08x ", i, val[i]);
428*4882a593Smuzhiyun 	}
429*4882a593Smuzhiyun 
430*4882a593Smuzhiyun 	seq_puts(file, "\n\n");
431*4882a593Smuzhiyun 	seq_puts(file, "Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n");
432*4882a593Smuzhiyun 
433*4882a593Smuzhiyun 	for (i = 0; i < ATH9K_NUM_QUEUES; i++, qcuOffset += 4, dcuOffset += 5) {
434*4882a593Smuzhiyun 		if (i == 8) {
435*4882a593Smuzhiyun 			qcuOffset = 0;
436*4882a593Smuzhiyun 			qcuBase++;
437*4882a593Smuzhiyun 		}
438*4882a593Smuzhiyun 
439*4882a593Smuzhiyun 		if (i == 6) {
440*4882a593Smuzhiyun 			dcuOffset = 0;
441*4882a593Smuzhiyun 			dcuBase++;
442*4882a593Smuzhiyun 		}
443*4882a593Smuzhiyun 
444*4882a593Smuzhiyun 		seq_printf(file, "%2d          %2x      %1x     %2x           %2x\n",
445*4882a593Smuzhiyun 			   i, (*qcuBase & (0x7 << qcuOffset)) >> qcuOffset,
446*4882a593Smuzhiyun 			   (*qcuBase & (0x8 << qcuOffset)) >> (qcuOffset + 3),
447*4882a593Smuzhiyun 			   (val[2] & (0x7 << (i * 3))) >> (i * 3),
448*4882a593Smuzhiyun 			   (*dcuBase & (0x1f << dcuOffset)) >> dcuOffset);
449*4882a593Smuzhiyun 	}
450*4882a593Smuzhiyun 
451*4882a593Smuzhiyun 	seq_puts(file, "\n");
452*4882a593Smuzhiyun 
453*4882a593Smuzhiyun 	seq_printf(file, "qcu_stitch state:   %2x    qcu_fetch state:        %2x\n",
454*4882a593Smuzhiyun 		   (val[3] & 0x003c0000) >> 18, (val[3] & 0x03c00000) >> 22);
455*4882a593Smuzhiyun 	seq_printf(file, "qcu_complete state: %2x    dcu_complete state:     %2x\n",
456*4882a593Smuzhiyun 		   (val[3] & 0x1c000000) >> 26, (val[6] & 0x3));
457*4882a593Smuzhiyun 	seq_printf(file, "dcu_arb state:      %2x    dcu_fp state:           %2x\n",
458*4882a593Smuzhiyun 		   (val[5] & 0x06000000) >> 25, (val[5] & 0x38000000) >> 27);
459*4882a593Smuzhiyun 	seq_printf(file, "chan_idle_dur:     %3d    chan_idle_dur_valid:     %1d\n",
460*4882a593Smuzhiyun 		   (val[6] & 0x000003fc) >> 2, (val[6] & 0x00000400) >> 10);
461*4882a593Smuzhiyun 	seq_printf(file, "txfifo_valid_0:      %1d    txfifo_valid_1:          %1d\n",
462*4882a593Smuzhiyun 		   (val[6] & 0x00000800) >> 11, (val[6] & 0x00001000) >> 12);
463*4882a593Smuzhiyun 	seq_printf(file, "txfifo_dcu_num_0:   %2d    txfifo_dcu_num_1:       %2d\n",
464*4882a593Smuzhiyun 		   (val[6] & 0x0001e000) >> 13, (val[6] & 0x001e0000) >> 17);
465*4882a593Smuzhiyun 
466*4882a593Smuzhiyun 	seq_printf(file, "pcu observe: 0x%x\n", REG_READ_D(ah, AR_OBS_BUS_1));
467*4882a593Smuzhiyun 	seq_printf(file, "AR_CR: 0x%x\n", REG_READ_D(ah, AR_CR));
468*4882a593Smuzhiyun 
469*4882a593Smuzhiyun 	ath9k_ps_restore(sc);
470*4882a593Smuzhiyun 
471*4882a593Smuzhiyun 	return 0;
472*4882a593Smuzhiyun }
473*4882a593Smuzhiyun 
ath_debug_stat_interrupt(struct ath_softc * sc,enum ath9k_int status)474*4882a593Smuzhiyun void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status)
475*4882a593Smuzhiyun {
476*4882a593Smuzhiyun 	if (status)
477*4882a593Smuzhiyun 		sc->debug.stats.istats.total++;
478*4882a593Smuzhiyun 	if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
479*4882a593Smuzhiyun 		if (status & ATH9K_INT_RXLP)
480*4882a593Smuzhiyun 			sc->debug.stats.istats.rxlp++;
481*4882a593Smuzhiyun 		if (status & ATH9K_INT_RXHP)
482*4882a593Smuzhiyun 			sc->debug.stats.istats.rxhp++;
483*4882a593Smuzhiyun 		if (status & ATH9K_INT_BB_WATCHDOG)
484*4882a593Smuzhiyun 			sc->debug.stats.istats.bb_watchdog++;
485*4882a593Smuzhiyun 	} else {
486*4882a593Smuzhiyun 		if (status & ATH9K_INT_RX)
487*4882a593Smuzhiyun 			sc->debug.stats.istats.rxok++;
488*4882a593Smuzhiyun 	}
489*4882a593Smuzhiyun 	if (status & ATH9K_INT_RXEOL)
490*4882a593Smuzhiyun 		sc->debug.stats.istats.rxeol++;
491*4882a593Smuzhiyun 	if (status & ATH9K_INT_RXORN)
492*4882a593Smuzhiyun 		sc->debug.stats.istats.rxorn++;
493*4882a593Smuzhiyun 	if (status & ATH9K_INT_TX)
494*4882a593Smuzhiyun 		sc->debug.stats.istats.txok++;
495*4882a593Smuzhiyun 	if (status & ATH9K_INT_TXURN)
496*4882a593Smuzhiyun 		sc->debug.stats.istats.txurn++;
497*4882a593Smuzhiyun 	if (status & ATH9K_INT_RXPHY)
498*4882a593Smuzhiyun 		sc->debug.stats.istats.rxphyerr++;
499*4882a593Smuzhiyun 	if (status & ATH9K_INT_RXKCM)
500*4882a593Smuzhiyun 		sc->debug.stats.istats.rx_keycache_miss++;
501*4882a593Smuzhiyun 	if (status & ATH9K_INT_SWBA)
502*4882a593Smuzhiyun 		sc->debug.stats.istats.swba++;
503*4882a593Smuzhiyun 	if (status & ATH9K_INT_BMISS)
504*4882a593Smuzhiyun 		sc->debug.stats.istats.bmiss++;
505*4882a593Smuzhiyun 	if (status & ATH9K_INT_BNR)
506*4882a593Smuzhiyun 		sc->debug.stats.istats.bnr++;
507*4882a593Smuzhiyun 	if (status & ATH9K_INT_CST)
508*4882a593Smuzhiyun 		sc->debug.stats.istats.cst++;
509*4882a593Smuzhiyun 	if (status & ATH9K_INT_GTT)
510*4882a593Smuzhiyun 		sc->debug.stats.istats.gtt++;
511*4882a593Smuzhiyun 	if (status & ATH9K_INT_TIM)
512*4882a593Smuzhiyun 		sc->debug.stats.istats.tim++;
513*4882a593Smuzhiyun 	if (status & ATH9K_INT_CABEND)
514*4882a593Smuzhiyun 		sc->debug.stats.istats.cabend++;
515*4882a593Smuzhiyun 	if (status & ATH9K_INT_DTIMSYNC)
516*4882a593Smuzhiyun 		sc->debug.stats.istats.dtimsync++;
517*4882a593Smuzhiyun 	if (status & ATH9K_INT_DTIM)
518*4882a593Smuzhiyun 		sc->debug.stats.istats.dtim++;
519*4882a593Smuzhiyun 	if (status & ATH9K_INT_TSFOOR)
520*4882a593Smuzhiyun 		sc->debug.stats.istats.tsfoor++;
521*4882a593Smuzhiyun 	if (status & ATH9K_INT_MCI)
522*4882a593Smuzhiyun 		sc->debug.stats.istats.mci++;
523*4882a593Smuzhiyun 	if (status & ATH9K_INT_GENTIMER)
524*4882a593Smuzhiyun 		sc->debug.stats.istats.gen_timer++;
525*4882a593Smuzhiyun }
526*4882a593Smuzhiyun 
read_file_interrupt(struct seq_file * file,void * data)527*4882a593Smuzhiyun static int read_file_interrupt(struct seq_file *file, void *data)
528*4882a593Smuzhiyun {
529*4882a593Smuzhiyun 	struct ieee80211_hw *hw = dev_get_drvdata(file->private);
530*4882a593Smuzhiyun 	struct ath_softc *sc = hw->priv;
531*4882a593Smuzhiyun 
532*4882a593Smuzhiyun #define PR_IS(a, s)						\
533*4882a593Smuzhiyun 	do {							\
534*4882a593Smuzhiyun 		seq_printf(file, "%21s: %10u\n", a,		\
535*4882a593Smuzhiyun 			   sc->debug.stats.istats.s);		\
536*4882a593Smuzhiyun 	} while (0)
537*4882a593Smuzhiyun 
538*4882a593Smuzhiyun 	if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
539*4882a593Smuzhiyun 		PR_IS("RXLP", rxlp);
540*4882a593Smuzhiyun 		PR_IS("RXHP", rxhp);
541*4882a593Smuzhiyun 		PR_IS("WATCHDOG", bb_watchdog);
542*4882a593Smuzhiyun 	} else {
543*4882a593Smuzhiyun 		PR_IS("RX", rxok);
544*4882a593Smuzhiyun 	}
545*4882a593Smuzhiyun 	PR_IS("RXEOL", rxeol);
546*4882a593Smuzhiyun 	PR_IS("RXORN", rxorn);
547*4882a593Smuzhiyun 	PR_IS("TX", txok);
548*4882a593Smuzhiyun 	PR_IS("TXURN", txurn);
549*4882a593Smuzhiyun 	PR_IS("MIB", mib);
550*4882a593Smuzhiyun 	PR_IS("RXPHY", rxphyerr);
551*4882a593Smuzhiyun 	PR_IS("RXKCM", rx_keycache_miss);
552*4882a593Smuzhiyun 	PR_IS("SWBA", swba);
553*4882a593Smuzhiyun 	PR_IS("BMISS", bmiss);
554*4882a593Smuzhiyun 	PR_IS("BNR", bnr);
555*4882a593Smuzhiyun 	PR_IS("CST", cst);
556*4882a593Smuzhiyun 	PR_IS("GTT", gtt);
557*4882a593Smuzhiyun 	PR_IS("TIM", tim);
558*4882a593Smuzhiyun 	PR_IS("CABEND", cabend);
559*4882a593Smuzhiyun 	PR_IS("DTIMSYNC", dtimsync);
560*4882a593Smuzhiyun 	PR_IS("DTIM", dtim);
561*4882a593Smuzhiyun 	PR_IS("TSFOOR", tsfoor);
562*4882a593Smuzhiyun 	PR_IS("MCI", mci);
563*4882a593Smuzhiyun 	PR_IS("GENTIMER", gen_timer);
564*4882a593Smuzhiyun 	PR_IS("TOTAL", total);
565*4882a593Smuzhiyun 
566*4882a593Smuzhiyun 	seq_puts(file, "SYNC_CAUSE stats:\n");
567*4882a593Smuzhiyun 
568*4882a593Smuzhiyun 	PR_IS("Sync-All", sync_cause_all);
569*4882a593Smuzhiyun 	PR_IS("RTC-IRQ", sync_rtc_irq);
570*4882a593Smuzhiyun 	PR_IS("MAC-IRQ", sync_mac_irq);
571*4882a593Smuzhiyun 	PR_IS("EEPROM-Illegal-Access", eeprom_illegal_access);
572*4882a593Smuzhiyun 	PR_IS("APB-Timeout", apb_timeout);
573*4882a593Smuzhiyun 	PR_IS("PCI-Mode-Conflict", pci_mode_conflict);
574*4882a593Smuzhiyun 	PR_IS("HOST1-Fatal", host1_fatal);
575*4882a593Smuzhiyun 	PR_IS("HOST1-Perr", host1_perr);
576*4882a593Smuzhiyun 	PR_IS("TRCV-FIFO-Perr", trcv_fifo_perr);
577*4882a593Smuzhiyun 	PR_IS("RADM-CPL-EP", radm_cpl_ep);
578*4882a593Smuzhiyun 	PR_IS("RADM-CPL-DLLP-Abort", radm_cpl_dllp_abort);
579*4882a593Smuzhiyun 	PR_IS("RADM-CPL-TLP-Abort", radm_cpl_tlp_abort);
580*4882a593Smuzhiyun 	PR_IS("RADM-CPL-ECRC-Err", radm_cpl_ecrc_err);
581*4882a593Smuzhiyun 	PR_IS("RADM-CPL-Timeout", radm_cpl_timeout);
582*4882a593Smuzhiyun 	PR_IS("Local-Bus-Timeout", local_timeout);
583*4882a593Smuzhiyun 	PR_IS("PM-Access", pm_access);
584*4882a593Smuzhiyun 	PR_IS("MAC-Awake", mac_awake);
585*4882a593Smuzhiyun 	PR_IS("MAC-Asleep", mac_asleep);
586*4882a593Smuzhiyun 	PR_IS("MAC-Sleep-Access", mac_sleep_access);
587*4882a593Smuzhiyun 
588*4882a593Smuzhiyun 	return 0;
589*4882a593Smuzhiyun }
590*4882a593Smuzhiyun 
read_file_xmit(struct seq_file * file,void * data)591*4882a593Smuzhiyun static int read_file_xmit(struct seq_file *file, void *data)
592*4882a593Smuzhiyun {
593*4882a593Smuzhiyun 	struct ieee80211_hw *hw = dev_get_drvdata(file->private);
594*4882a593Smuzhiyun 	struct ath_softc *sc = hw->priv;
595*4882a593Smuzhiyun 
596*4882a593Smuzhiyun 	seq_printf(file, "%30s %10s%10s%10s\n\n", "BE", "BK", "VI", "VO");
597*4882a593Smuzhiyun 
598*4882a593Smuzhiyun 	PR("MPDUs Queued:    ", queued);
599*4882a593Smuzhiyun 	PR("MPDUs Completed: ", completed);
600*4882a593Smuzhiyun 	PR("MPDUs XRetried:  ", xretries);
601*4882a593Smuzhiyun 	PR("Aggregates:      ", a_aggr);
602*4882a593Smuzhiyun 	PR("AMPDUs Queued HW:", a_queued_hw);
603*4882a593Smuzhiyun 	PR("AMPDUs Completed:", a_completed);
604*4882a593Smuzhiyun 	PR("AMPDUs Retried:  ", a_retries);
605*4882a593Smuzhiyun 	PR("AMPDUs XRetried: ", a_xretries);
606*4882a593Smuzhiyun 	PR("TXERR Filtered:  ", txerr_filtered);
607*4882a593Smuzhiyun 	PR("FIFO Underrun:   ", fifo_underrun);
608*4882a593Smuzhiyun 	PR("TXOP Exceeded:   ", xtxop);
609*4882a593Smuzhiyun 	PR("TXTIMER Expiry:  ", timer_exp);
610*4882a593Smuzhiyun 	PR("DESC CFG Error:  ", desc_cfg_err);
611*4882a593Smuzhiyun 	PR("DATA Underrun:   ", data_underrun);
612*4882a593Smuzhiyun 	PR("DELIM Underrun:  ", delim_underrun);
613*4882a593Smuzhiyun 	PR("TX-Pkts-All:     ", tx_pkts_all);
614*4882a593Smuzhiyun 	PR("TX-Bytes-All:    ", tx_bytes_all);
615*4882a593Smuzhiyun 	PR("HW-put-tx-buf:   ", puttxbuf);
616*4882a593Smuzhiyun 	PR("HW-tx-start:     ", txstart);
617*4882a593Smuzhiyun 	PR("HW-tx-proc-desc: ", txprocdesc);
618*4882a593Smuzhiyun 	PR("TX-Failed:       ", txfailed);
619*4882a593Smuzhiyun 
620*4882a593Smuzhiyun 	return 0;
621*4882a593Smuzhiyun }
622*4882a593Smuzhiyun 
print_queue(struct ath_softc * sc,struct ath_txq * txq,struct seq_file * file)623*4882a593Smuzhiyun static void print_queue(struct ath_softc *sc, struct ath_txq *txq,
624*4882a593Smuzhiyun 			struct seq_file *file)
625*4882a593Smuzhiyun {
626*4882a593Smuzhiyun 	ath_txq_lock(sc, txq);
627*4882a593Smuzhiyun 
628*4882a593Smuzhiyun 	seq_printf(file, "%s: %d ", "qnum", txq->axq_qnum);
629*4882a593Smuzhiyun 	seq_printf(file, "%s: %2d ", "qdepth", txq->axq_depth);
630*4882a593Smuzhiyun 	seq_printf(file, "%s: %2d ", "ampdu-depth", txq->axq_ampdu_depth);
631*4882a593Smuzhiyun 	seq_printf(file, "%s: %3d\n", "pending", txq->pending_frames);
632*4882a593Smuzhiyun 
633*4882a593Smuzhiyun 	ath_txq_unlock(sc, txq);
634*4882a593Smuzhiyun }
635*4882a593Smuzhiyun 
read_file_queues(struct seq_file * file,void * data)636*4882a593Smuzhiyun static int read_file_queues(struct seq_file *file, void *data)
637*4882a593Smuzhiyun {
638*4882a593Smuzhiyun 	struct ieee80211_hw *hw = dev_get_drvdata(file->private);
639*4882a593Smuzhiyun 	struct ath_softc *sc = hw->priv;
640*4882a593Smuzhiyun 	struct ath_txq *txq;
641*4882a593Smuzhiyun 	int i;
642*4882a593Smuzhiyun 	static const char *qname[4] = {
643*4882a593Smuzhiyun 		"VO", "VI", "BE", "BK"
644*4882a593Smuzhiyun 	};
645*4882a593Smuzhiyun 
646*4882a593Smuzhiyun 	for (i = 0; i < IEEE80211_NUM_ACS; i++) {
647*4882a593Smuzhiyun 		txq = sc->tx.txq_map[i];
648*4882a593Smuzhiyun 		seq_printf(file, "(%s):  ", qname[i]);
649*4882a593Smuzhiyun 		print_queue(sc, txq, file);
650*4882a593Smuzhiyun 	}
651*4882a593Smuzhiyun 
652*4882a593Smuzhiyun 	seq_puts(file, "(CAB): ");
653*4882a593Smuzhiyun 	print_queue(sc, sc->beacon.cabq, file);
654*4882a593Smuzhiyun 
655*4882a593Smuzhiyun 	return 0;
656*4882a593Smuzhiyun }
657*4882a593Smuzhiyun 
read_file_misc(struct seq_file * file,void * data)658*4882a593Smuzhiyun static int read_file_misc(struct seq_file *file, void *data)
659*4882a593Smuzhiyun {
660*4882a593Smuzhiyun 	struct ieee80211_hw *hw = dev_get_drvdata(file->private);
661*4882a593Smuzhiyun 	struct ath_softc *sc = hw->priv;
662*4882a593Smuzhiyun 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
663*4882a593Smuzhiyun 	struct ath9k_vif_iter_data iter_data;
664*4882a593Smuzhiyun 	struct ath_chanctx *ctx;
665*4882a593Smuzhiyun 	unsigned int reg;
666*4882a593Smuzhiyun 	u32 rxfilter, i;
667*4882a593Smuzhiyun 
668*4882a593Smuzhiyun 	seq_printf(file, "BSSID: %pM\n", common->curbssid);
669*4882a593Smuzhiyun 	seq_printf(file, "BSSID-MASK: %pM\n", common->bssidmask);
670*4882a593Smuzhiyun 	seq_printf(file, "OPMODE: %s\n",
671*4882a593Smuzhiyun 		   ath_opmode_to_string(sc->sc_ah->opmode));
672*4882a593Smuzhiyun 
673*4882a593Smuzhiyun 	ath9k_ps_wakeup(sc);
674*4882a593Smuzhiyun 	rxfilter = ath9k_hw_getrxfilter(sc->sc_ah);
675*4882a593Smuzhiyun 	ath9k_ps_restore(sc);
676*4882a593Smuzhiyun 
677*4882a593Smuzhiyun 	seq_printf(file, "RXFILTER: 0x%x", rxfilter);
678*4882a593Smuzhiyun 
679*4882a593Smuzhiyun 	if (rxfilter & ATH9K_RX_FILTER_UCAST)
680*4882a593Smuzhiyun 		seq_puts(file, " UCAST");
681*4882a593Smuzhiyun 	if (rxfilter & ATH9K_RX_FILTER_MCAST)
682*4882a593Smuzhiyun 		seq_puts(file, " MCAST");
683*4882a593Smuzhiyun 	if (rxfilter & ATH9K_RX_FILTER_BCAST)
684*4882a593Smuzhiyun 		seq_puts(file, " BCAST");
685*4882a593Smuzhiyun 	if (rxfilter & ATH9K_RX_FILTER_CONTROL)
686*4882a593Smuzhiyun 		seq_puts(file, " CONTROL");
687*4882a593Smuzhiyun 	if (rxfilter & ATH9K_RX_FILTER_BEACON)
688*4882a593Smuzhiyun 		seq_puts(file, " BEACON");
689*4882a593Smuzhiyun 	if (rxfilter & ATH9K_RX_FILTER_PROM)
690*4882a593Smuzhiyun 		seq_puts(file, " PROM");
691*4882a593Smuzhiyun 	if (rxfilter & ATH9K_RX_FILTER_PROBEREQ)
692*4882a593Smuzhiyun 		seq_puts(file, " PROBEREQ");
693*4882a593Smuzhiyun 	if (rxfilter & ATH9K_RX_FILTER_PHYERR)
694*4882a593Smuzhiyun 		seq_puts(file, " PHYERR");
695*4882a593Smuzhiyun 	if (rxfilter & ATH9K_RX_FILTER_MYBEACON)
696*4882a593Smuzhiyun 		seq_puts(file, " MYBEACON");
697*4882a593Smuzhiyun 	if (rxfilter & ATH9K_RX_FILTER_COMP_BAR)
698*4882a593Smuzhiyun 		seq_puts(file, " COMP_BAR");
699*4882a593Smuzhiyun 	if (rxfilter & ATH9K_RX_FILTER_PSPOLL)
700*4882a593Smuzhiyun 		seq_puts(file, " PSPOLL");
701*4882a593Smuzhiyun 	if (rxfilter & ATH9K_RX_FILTER_PHYRADAR)
702*4882a593Smuzhiyun 		seq_puts(file, " PHYRADAR");
703*4882a593Smuzhiyun 	if (rxfilter & ATH9K_RX_FILTER_MCAST_BCAST_ALL)
704*4882a593Smuzhiyun 		seq_puts(file, " MCAST_BCAST_ALL");
705*4882a593Smuzhiyun 	if (rxfilter & ATH9K_RX_FILTER_CONTROL_WRAPPER)
706*4882a593Smuzhiyun 		seq_puts(file, " CONTROL_WRAPPER");
707*4882a593Smuzhiyun 
708*4882a593Smuzhiyun 	seq_puts(file, "\n");
709*4882a593Smuzhiyun 
710*4882a593Smuzhiyun 	reg = sc->sc_ah->imask;
711*4882a593Smuzhiyun 
712*4882a593Smuzhiyun 	seq_printf(file, "INTERRUPT-MASK: 0x%x", reg);
713*4882a593Smuzhiyun 
714*4882a593Smuzhiyun 	if (reg & ATH9K_INT_SWBA)
715*4882a593Smuzhiyun 		seq_puts(file, " SWBA");
716*4882a593Smuzhiyun 	if (reg & ATH9K_INT_BMISS)
717*4882a593Smuzhiyun 		seq_puts(file, " BMISS");
718*4882a593Smuzhiyun 	if (reg & ATH9K_INT_CST)
719*4882a593Smuzhiyun 		seq_puts(file, " CST");
720*4882a593Smuzhiyun 	if (reg & ATH9K_INT_RX)
721*4882a593Smuzhiyun 		seq_puts(file, " RX");
722*4882a593Smuzhiyun 	if (reg & ATH9K_INT_RXHP)
723*4882a593Smuzhiyun 		seq_puts(file, " RXHP");
724*4882a593Smuzhiyun 	if (reg & ATH9K_INT_RXLP)
725*4882a593Smuzhiyun 		seq_puts(file, " RXLP");
726*4882a593Smuzhiyun 	if (reg & ATH9K_INT_BB_WATCHDOG)
727*4882a593Smuzhiyun 		seq_puts(file, " BB_WATCHDOG");
728*4882a593Smuzhiyun 
729*4882a593Smuzhiyun 	seq_puts(file, "\n");
730*4882a593Smuzhiyun 
731*4882a593Smuzhiyun 	i = 0;
732*4882a593Smuzhiyun 	ath_for_each_chanctx(sc, ctx) {
733*4882a593Smuzhiyun 		if (list_empty(&ctx->vifs))
734*4882a593Smuzhiyun 			continue;
735*4882a593Smuzhiyun 		ath9k_calculate_iter_data(sc, ctx, &iter_data);
736*4882a593Smuzhiyun 
737*4882a593Smuzhiyun 		seq_printf(file,
738*4882a593Smuzhiyun 			   "VIFS: CTX %i(%i) AP: %i STA: %i MESH: %i WDS: %i",
739*4882a593Smuzhiyun 			   i++, (int)(ctx->assigned), iter_data.naps,
740*4882a593Smuzhiyun 			   iter_data.nstations,
741*4882a593Smuzhiyun 			   iter_data.nmeshes, iter_data.nwds);
742*4882a593Smuzhiyun 		seq_printf(file, " ADHOC: %i OCB: %i TOTAL: %hi BEACON-VIF: %hi\n",
743*4882a593Smuzhiyun 			   iter_data.nadhocs, iter_data.nocbs, sc->cur_chan->nvifs,
744*4882a593Smuzhiyun 			   sc->nbcnvifs);
745*4882a593Smuzhiyun 	}
746*4882a593Smuzhiyun 
747*4882a593Smuzhiyun 	return 0;
748*4882a593Smuzhiyun }
749*4882a593Smuzhiyun 
read_file_reset(struct seq_file * file,void * data)750*4882a593Smuzhiyun static int read_file_reset(struct seq_file *file, void *data)
751*4882a593Smuzhiyun {
752*4882a593Smuzhiyun 	struct ieee80211_hw *hw = dev_get_drvdata(file->private);
753*4882a593Smuzhiyun 	struct ath_softc *sc = hw->priv;
754*4882a593Smuzhiyun 	static const char * const reset_cause[__RESET_TYPE_MAX] = {
755*4882a593Smuzhiyun 		[RESET_TYPE_BB_HANG] = "Baseband Hang",
756*4882a593Smuzhiyun 		[RESET_TYPE_BB_WATCHDOG] = "Baseband Watchdog",
757*4882a593Smuzhiyun 		[RESET_TYPE_FATAL_INT] = "Fatal HW Error",
758*4882a593Smuzhiyun 		[RESET_TYPE_TX_ERROR] = "TX HW error",
759*4882a593Smuzhiyun 		[RESET_TYPE_TX_GTT] = "Transmit timeout",
760*4882a593Smuzhiyun 		[RESET_TYPE_TX_HANG] = "TX Path Hang",
761*4882a593Smuzhiyun 		[RESET_TYPE_PLL_HANG] = "PLL RX Hang",
762*4882a593Smuzhiyun 		[RESET_TYPE_MAC_HANG] = "MAC Hang",
763*4882a593Smuzhiyun 		[RESET_TYPE_BEACON_STUCK] = "Stuck Beacon",
764*4882a593Smuzhiyun 		[RESET_TYPE_MCI] = "MCI Reset",
765*4882a593Smuzhiyun 		[RESET_TYPE_CALIBRATION] = "Calibration error",
766*4882a593Smuzhiyun 		[RESET_TX_DMA_ERROR] = "Tx DMA stop error",
767*4882a593Smuzhiyun 		[RESET_RX_DMA_ERROR] = "Rx DMA stop error",
768*4882a593Smuzhiyun 	};
769*4882a593Smuzhiyun 	int i;
770*4882a593Smuzhiyun 
771*4882a593Smuzhiyun 	for (i = 0; i < ARRAY_SIZE(reset_cause); i++) {
772*4882a593Smuzhiyun 		if (!reset_cause[i])
773*4882a593Smuzhiyun 		    continue;
774*4882a593Smuzhiyun 
775*4882a593Smuzhiyun 		seq_printf(file, "%17s: %2d\n", reset_cause[i],
776*4882a593Smuzhiyun 			   sc->debug.stats.reset[i]);
777*4882a593Smuzhiyun 	}
778*4882a593Smuzhiyun 
779*4882a593Smuzhiyun 	return 0;
780*4882a593Smuzhiyun }
781*4882a593Smuzhiyun 
ath_debug_stat_tx(struct ath_softc * sc,struct ath_buf * bf,struct ath_tx_status * ts,struct ath_txq * txq,unsigned int flags)782*4882a593Smuzhiyun void ath_debug_stat_tx(struct ath_softc *sc, struct ath_buf *bf,
783*4882a593Smuzhiyun 		       struct ath_tx_status *ts, struct ath_txq *txq,
784*4882a593Smuzhiyun 		       unsigned int flags)
785*4882a593Smuzhiyun {
786*4882a593Smuzhiyun 	int qnum = txq->axq_qnum;
787*4882a593Smuzhiyun 
788*4882a593Smuzhiyun 	TX_STAT_INC(sc, qnum, tx_pkts_all);
789*4882a593Smuzhiyun 	sc->debug.stats.txstats[qnum].tx_bytes_all += bf->bf_mpdu->len;
790*4882a593Smuzhiyun 
791*4882a593Smuzhiyun 	if (bf_isampdu(bf)) {
792*4882a593Smuzhiyun 		if (flags & ATH_TX_ERROR)
793*4882a593Smuzhiyun 			TX_STAT_INC(sc, qnum, a_xretries);
794*4882a593Smuzhiyun 		else
795*4882a593Smuzhiyun 			TX_STAT_INC(sc, qnum, a_completed);
796*4882a593Smuzhiyun 	} else {
797*4882a593Smuzhiyun 		if (ts->ts_status & ATH9K_TXERR_XRETRY)
798*4882a593Smuzhiyun 			TX_STAT_INC(sc, qnum, xretries);
799*4882a593Smuzhiyun 		else
800*4882a593Smuzhiyun 			TX_STAT_INC(sc, qnum, completed);
801*4882a593Smuzhiyun 	}
802*4882a593Smuzhiyun 
803*4882a593Smuzhiyun 	if (ts->ts_status & ATH9K_TXERR_FILT)
804*4882a593Smuzhiyun 		TX_STAT_INC(sc, qnum, txerr_filtered);
805*4882a593Smuzhiyun 	if (ts->ts_status & ATH9K_TXERR_FIFO)
806*4882a593Smuzhiyun 		TX_STAT_INC(sc, qnum, fifo_underrun);
807*4882a593Smuzhiyun 	if (ts->ts_status & ATH9K_TXERR_XTXOP)
808*4882a593Smuzhiyun 		TX_STAT_INC(sc, qnum, xtxop);
809*4882a593Smuzhiyun 	if (ts->ts_status & ATH9K_TXERR_TIMER_EXPIRED)
810*4882a593Smuzhiyun 		TX_STAT_INC(sc, qnum, timer_exp);
811*4882a593Smuzhiyun 	if (ts->ts_flags & ATH9K_TX_DESC_CFG_ERR)
812*4882a593Smuzhiyun 		TX_STAT_INC(sc, qnum, desc_cfg_err);
813*4882a593Smuzhiyun 	if (ts->ts_flags & ATH9K_TX_DATA_UNDERRUN)
814*4882a593Smuzhiyun 		TX_STAT_INC(sc, qnum, data_underrun);
815*4882a593Smuzhiyun 	if (ts->ts_flags & ATH9K_TX_DELIM_UNDERRUN)
816*4882a593Smuzhiyun 		TX_STAT_INC(sc, qnum, delim_underrun);
817*4882a593Smuzhiyun }
818*4882a593Smuzhiyun 
ath_debug_stat_rx(struct ath_softc * sc,struct ath_rx_status * rs)819*4882a593Smuzhiyun void ath_debug_stat_rx(struct ath_softc *sc, struct ath_rx_status *rs)
820*4882a593Smuzhiyun {
821*4882a593Smuzhiyun 	ath9k_cmn_debug_stat_rx(&sc->debug.stats.rxstats, rs);
822*4882a593Smuzhiyun }
823*4882a593Smuzhiyun 
read_file_regidx(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)824*4882a593Smuzhiyun static ssize_t read_file_regidx(struct file *file, char __user *user_buf,
825*4882a593Smuzhiyun 				size_t count, loff_t *ppos)
826*4882a593Smuzhiyun {
827*4882a593Smuzhiyun 	struct ath_softc *sc = file->private_data;
828*4882a593Smuzhiyun 	char buf[32];
829*4882a593Smuzhiyun 	unsigned int len;
830*4882a593Smuzhiyun 
831*4882a593Smuzhiyun 	len = sprintf(buf, "0x%08x\n", sc->debug.regidx);
832*4882a593Smuzhiyun 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
833*4882a593Smuzhiyun }
834*4882a593Smuzhiyun 
write_file_regidx(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)835*4882a593Smuzhiyun static ssize_t write_file_regidx(struct file *file, const char __user *user_buf,
836*4882a593Smuzhiyun 				 size_t count, loff_t *ppos)
837*4882a593Smuzhiyun {
838*4882a593Smuzhiyun 	struct ath_softc *sc = file->private_data;
839*4882a593Smuzhiyun 	unsigned long regidx;
840*4882a593Smuzhiyun 	char buf[32];
841*4882a593Smuzhiyun 	ssize_t len;
842*4882a593Smuzhiyun 
843*4882a593Smuzhiyun 	len = min(count, sizeof(buf) - 1);
844*4882a593Smuzhiyun 	if (copy_from_user(buf, user_buf, len))
845*4882a593Smuzhiyun 		return -EFAULT;
846*4882a593Smuzhiyun 
847*4882a593Smuzhiyun 	buf[len] = '\0';
848*4882a593Smuzhiyun 	if (kstrtoul(buf, 0, &regidx))
849*4882a593Smuzhiyun 		return -EINVAL;
850*4882a593Smuzhiyun 
851*4882a593Smuzhiyun 	sc->debug.regidx = regidx;
852*4882a593Smuzhiyun 	return count;
853*4882a593Smuzhiyun }
854*4882a593Smuzhiyun 
855*4882a593Smuzhiyun static const struct file_operations fops_regidx = {
856*4882a593Smuzhiyun 	.read = read_file_regidx,
857*4882a593Smuzhiyun 	.write = write_file_regidx,
858*4882a593Smuzhiyun 	.open = simple_open,
859*4882a593Smuzhiyun 	.owner = THIS_MODULE,
860*4882a593Smuzhiyun 	.llseek = default_llseek,
861*4882a593Smuzhiyun };
862*4882a593Smuzhiyun 
read_file_regval(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)863*4882a593Smuzhiyun static ssize_t read_file_regval(struct file *file, char __user *user_buf,
864*4882a593Smuzhiyun 				size_t count, loff_t *ppos)
865*4882a593Smuzhiyun {
866*4882a593Smuzhiyun 	struct ath_softc *sc = file->private_data;
867*4882a593Smuzhiyun 	struct ath_hw *ah = sc->sc_ah;
868*4882a593Smuzhiyun 	char buf[32];
869*4882a593Smuzhiyun 	unsigned int len;
870*4882a593Smuzhiyun 	u32 regval;
871*4882a593Smuzhiyun 
872*4882a593Smuzhiyun 	ath9k_ps_wakeup(sc);
873*4882a593Smuzhiyun 	regval = REG_READ_D(ah, sc->debug.regidx);
874*4882a593Smuzhiyun 	ath9k_ps_restore(sc);
875*4882a593Smuzhiyun 	len = sprintf(buf, "0x%08x\n", regval);
876*4882a593Smuzhiyun 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
877*4882a593Smuzhiyun }
878*4882a593Smuzhiyun 
write_file_regval(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)879*4882a593Smuzhiyun static ssize_t write_file_regval(struct file *file, const char __user *user_buf,
880*4882a593Smuzhiyun 				 size_t count, loff_t *ppos)
881*4882a593Smuzhiyun {
882*4882a593Smuzhiyun 	struct ath_softc *sc = file->private_data;
883*4882a593Smuzhiyun 	struct ath_hw *ah = sc->sc_ah;
884*4882a593Smuzhiyun 	unsigned long regval;
885*4882a593Smuzhiyun 	char buf[32];
886*4882a593Smuzhiyun 	ssize_t len;
887*4882a593Smuzhiyun 
888*4882a593Smuzhiyun 	len = min(count, sizeof(buf) - 1);
889*4882a593Smuzhiyun 	if (copy_from_user(buf, user_buf, len))
890*4882a593Smuzhiyun 		return -EFAULT;
891*4882a593Smuzhiyun 
892*4882a593Smuzhiyun 	buf[len] = '\0';
893*4882a593Smuzhiyun 	if (kstrtoul(buf, 0, &regval))
894*4882a593Smuzhiyun 		return -EINVAL;
895*4882a593Smuzhiyun 
896*4882a593Smuzhiyun 	ath9k_ps_wakeup(sc);
897*4882a593Smuzhiyun 	REG_WRITE_D(ah, sc->debug.regidx, regval);
898*4882a593Smuzhiyun 	ath9k_ps_restore(sc);
899*4882a593Smuzhiyun 	return count;
900*4882a593Smuzhiyun }
901*4882a593Smuzhiyun 
902*4882a593Smuzhiyun static const struct file_operations fops_regval = {
903*4882a593Smuzhiyun 	.read = read_file_regval,
904*4882a593Smuzhiyun 	.write = write_file_regval,
905*4882a593Smuzhiyun 	.open = simple_open,
906*4882a593Smuzhiyun 	.owner = THIS_MODULE,
907*4882a593Smuzhiyun 	.llseek = default_llseek,
908*4882a593Smuzhiyun };
909*4882a593Smuzhiyun 
910*4882a593Smuzhiyun #define REGDUMP_LINE_SIZE	20
911*4882a593Smuzhiyun 
open_file_regdump(struct inode * inode,struct file * file)912*4882a593Smuzhiyun static int open_file_regdump(struct inode *inode, struct file *file)
913*4882a593Smuzhiyun {
914*4882a593Smuzhiyun 	struct ath_softc *sc = inode->i_private;
915*4882a593Smuzhiyun 	unsigned int len = 0;
916*4882a593Smuzhiyun 	u8 *buf;
917*4882a593Smuzhiyun 	int i, j = 0;
918*4882a593Smuzhiyun 	unsigned long num_regs, regdump_len, max_reg_offset;
919*4882a593Smuzhiyun 	static const struct reg_hole {
920*4882a593Smuzhiyun 		u32 start;
921*4882a593Smuzhiyun 		u32 end;
922*4882a593Smuzhiyun 	} reg_hole_list[] = {
923*4882a593Smuzhiyun 		{0x0200, 0x07fc},
924*4882a593Smuzhiyun 		{0x0c00, 0x0ffc},
925*4882a593Smuzhiyun 		{0x2000, 0x3ffc},
926*4882a593Smuzhiyun 		{0x4100, 0x6ffc},
927*4882a593Smuzhiyun 		{0x705c, 0x7ffc},
928*4882a593Smuzhiyun 		{0x0000, 0x0000}
929*4882a593Smuzhiyun 	};
930*4882a593Smuzhiyun 
931*4882a593Smuzhiyun 	max_reg_offset = AR_SREV_9300_20_OR_LATER(sc->sc_ah) ? 0x8800 : 0xb500;
932*4882a593Smuzhiyun 	num_regs = max_reg_offset / 4 + 1;
933*4882a593Smuzhiyun 	regdump_len = num_regs * REGDUMP_LINE_SIZE + 1;
934*4882a593Smuzhiyun 	buf = vmalloc(regdump_len);
935*4882a593Smuzhiyun 	if (!buf)
936*4882a593Smuzhiyun 		return -ENOMEM;
937*4882a593Smuzhiyun 
938*4882a593Smuzhiyun 	ath9k_ps_wakeup(sc);
939*4882a593Smuzhiyun 	for (i = 0; i < num_regs; i++) {
940*4882a593Smuzhiyun 		if (reg_hole_list[j].start == i << 2) {
941*4882a593Smuzhiyun 			i = reg_hole_list[j].end >> 2;
942*4882a593Smuzhiyun 			j++;
943*4882a593Smuzhiyun 			continue;
944*4882a593Smuzhiyun 		}
945*4882a593Smuzhiyun 
946*4882a593Smuzhiyun 		len += scnprintf(buf + len, regdump_len - len,
947*4882a593Smuzhiyun 			"0x%06x 0x%08x\n", i << 2, REG_READ(sc->sc_ah, i << 2));
948*4882a593Smuzhiyun 	}
949*4882a593Smuzhiyun 	ath9k_ps_restore(sc);
950*4882a593Smuzhiyun 
951*4882a593Smuzhiyun 	file->private_data = buf;
952*4882a593Smuzhiyun 
953*4882a593Smuzhiyun 	return 0;
954*4882a593Smuzhiyun }
955*4882a593Smuzhiyun 
956*4882a593Smuzhiyun static const struct file_operations fops_regdump = {
957*4882a593Smuzhiyun 	.open = open_file_regdump,
958*4882a593Smuzhiyun 	.read = ath9k_debugfs_read_buf,
959*4882a593Smuzhiyun 	.release = ath9k_debugfs_release_buf,
960*4882a593Smuzhiyun 	.owner = THIS_MODULE,
961*4882a593Smuzhiyun 	.llseek = default_llseek,/* read accesses f_pos */
962*4882a593Smuzhiyun };
963*4882a593Smuzhiyun 
read_file_dump_nfcal(struct seq_file * file,void * data)964*4882a593Smuzhiyun static int read_file_dump_nfcal(struct seq_file *file, void *data)
965*4882a593Smuzhiyun {
966*4882a593Smuzhiyun 	struct ieee80211_hw *hw = dev_get_drvdata(file->private);
967*4882a593Smuzhiyun 	struct ath_softc *sc = hw->priv;
968*4882a593Smuzhiyun 	struct ath_hw *ah = sc->sc_ah;
969*4882a593Smuzhiyun 	struct ath9k_nfcal_hist *h = sc->cur_chan->caldata.nfCalHist;
970*4882a593Smuzhiyun 	struct ath_common *common = ath9k_hw_common(ah);
971*4882a593Smuzhiyun 	struct ieee80211_conf *conf = &common->hw->conf;
972*4882a593Smuzhiyun 	u32 i, j;
973*4882a593Smuzhiyun 	u8 chainmask = (ah->rxchainmask << 3) | ah->rxchainmask;
974*4882a593Smuzhiyun 	u8 nread;
975*4882a593Smuzhiyun 
976*4882a593Smuzhiyun 	seq_printf(file, "Channel Noise Floor : %d\n", ah->noise);
977*4882a593Smuzhiyun 	seq_puts(file, "Chain | privNF | # Readings | NF Readings\n");
978*4882a593Smuzhiyun 	for (i = 0; i < NUM_NF_READINGS; i++) {
979*4882a593Smuzhiyun 		if (!(chainmask & (1 << i)) ||
980*4882a593Smuzhiyun 		    ((i >= AR5416_MAX_CHAINS) && !conf_is_ht40(conf)))
981*4882a593Smuzhiyun 			continue;
982*4882a593Smuzhiyun 
983*4882a593Smuzhiyun 		nread = AR_PHY_CCA_FILTERWINDOW_LENGTH - h[i].invalidNFcount;
984*4882a593Smuzhiyun 		seq_printf(file, " %d\t %d\t %d\t\t", i, h[i].privNF, nread);
985*4882a593Smuzhiyun 		for (j = 0; j < nread; j++)
986*4882a593Smuzhiyun 			seq_printf(file, " %d", h[i].nfCalBuffer[j]);
987*4882a593Smuzhiyun 		seq_puts(file, "\n");
988*4882a593Smuzhiyun 	}
989*4882a593Smuzhiyun 
990*4882a593Smuzhiyun 	return 0;
991*4882a593Smuzhiyun }
992*4882a593Smuzhiyun 
993*4882a593Smuzhiyun #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
read_file_btcoex(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)994*4882a593Smuzhiyun static ssize_t read_file_btcoex(struct file *file, char __user *user_buf,
995*4882a593Smuzhiyun 				size_t count, loff_t *ppos)
996*4882a593Smuzhiyun {
997*4882a593Smuzhiyun 	struct ath_softc *sc = file->private_data;
998*4882a593Smuzhiyun 	u32 len = 0, size = 1500;
999*4882a593Smuzhiyun 	char *buf;
1000*4882a593Smuzhiyun 	size_t retval;
1001*4882a593Smuzhiyun 
1002*4882a593Smuzhiyun 	buf = kzalloc(size, GFP_KERNEL);
1003*4882a593Smuzhiyun 	if (buf == NULL)
1004*4882a593Smuzhiyun 		return -ENOMEM;
1005*4882a593Smuzhiyun 
1006*4882a593Smuzhiyun 	if (!sc->sc_ah->common.btcoex_enabled) {
1007*4882a593Smuzhiyun 		len = scnprintf(buf, size, "%s\n",
1008*4882a593Smuzhiyun 				"BTCOEX is disabled");
1009*4882a593Smuzhiyun 		goto exit;
1010*4882a593Smuzhiyun 	}
1011*4882a593Smuzhiyun 
1012*4882a593Smuzhiyun 	len = ath9k_dump_btcoex(sc, buf, size);
1013*4882a593Smuzhiyun exit:
1014*4882a593Smuzhiyun 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1015*4882a593Smuzhiyun 	kfree(buf);
1016*4882a593Smuzhiyun 
1017*4882a593Smuzhiyun 	return retval;
1018*4882a593Smuzhiyun }
1019*4882a593Smuzhiyun 
1020*4882a593Smuzhiyun static const struct file_operations fops_btcoex = {
1021*4882a593Smuzhiyun 	.read = read_file_btcoex,
1022*4882a593Smuzhiyun 	.open = simple_open,
1023*4882a593Smuzhiyun 	.owner = THIS_MODULE,
1024*4882a593Smuzhiyun 	.llseek = default_llseek,
1025*4882a593Smuzhiyun };
1026*4882a593Smuzhiyun #endif
1027*4882a593Smuzhiyun 
1028*4882a593Smuzhiyun #ifdef CONFIG_ATH9K_DYNACK
read_file_ackto(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)1029*4882a593Smuzhiyun static ssize_t read_file_ackto(struct file *file, char __user *user_buf,
1030*4882a593Smuzhiyun 			       size_t count, loff_t *ppos)
1031*4882a593Smuzhiyun {
1032*4882a593Smuzhiyun 	struct ath_softc *sc = file->private_data;
1033*4882a593Smuzhiyun 	struct ath_hw *ah = sc->sc_ah;
1034*4882a593Smuzhiyun 	char buf[32];
1035*4882a593Smuzhiyun 	unsigned int len;
1036*4882a593Smuzhiyun 
1037*4882a593Smuzhiyun 	len = sprintf(buf, "%u %c\n", ah->dynack.ackto,
1038*4882a593Smuzhiyun 		      (ah->dynack.enabled) ? 'A' : 'S');
1039*4882a593Smuzhiyun 
1040*4882a593Smuzhiyun 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1041*4882a593Smuzhiyun }
1042*4882a593Smuzhiyun 
1043*4882a593Smuzhiyun static const struct file_operations fops_ackto = {
1044*4882a593Smuzhiyun 	.read = read_file_ackto,
1045*4882a593Smuzhiyun 	.open = simple_open,
1046*4882a593Smuzhiyun 	.owner = THIS_MODULE,
1047*4882a593Smuzhiyun 	.llseek = default_llseek,
1048*4882a593Smuzhiyun };
1049*4882a593Smuzhiyun #endif
1050*4882a593Smuzhiyun 
1051*4882a593Smuzhiyun #ifdef CONFIG_ATH9K_WOW
1052*4882a593Smuzhiyun 
read_file_wow(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)1053*4882a593Smuzhiyun static ssize_t read_file_wow(struct file *file, char __user *user_buf,
1054*4882a593Smuzhiyun 			     size_t count, loff_t *ppos)
1055*4882a593Smuzhiyun {
1056*4882a593Smuzhiyun 	struct ath_softc *sc = file->private_data;
1057*4882a593Smuzhiyun 	unsigned int len = 0, size = 32;
1058*4882a593Smuzhiyun 	ssize_t retval;
1059*4882a593Smuzhiyun 	char *buf;
1060*4882a593Smuzhiyun 
1061*4882a593Smuzhiyun 	buf = kzalloc(size, GFP_KERNEL);
1062*4882a593Smuzhiyun 	if (!buf)
1063*4882a593Smuzhiyun 		return -ENOMEM;
1064*4882a593Smuzhiyun 
1065*4882a593Smuzhiyun 	len += scnprintf(buf + len, size - len, "WOW: %s\n",
1066*4882a593Smuzhiyun 			 sc->force_wow ? "ENABLED" : "DISABLED");
1067*4882a593Smuzhiyun 
1068*4882a593Smuzhiyun 	if (len > size)
1069*4882a593Smuzhiyun 		len = size;
1070*4882a593Smuzhiyun 
1071*4882a593Smuzhiyun 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1072*4882a593Smuzhiyun 	kfree(buf);
1073*4882a593Smuzhiyun 
1074*4882a593Smuzhiyun 	return retval;
1075*4882a593Smuzhiyun }
1076*4882a593Smuzhiyun 
write_file_wow(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)1077*4882a593Smuzhiyun static ssize_t write_file_wow(struct file *file, const char __user *user_buf,
1078*4882a593Smuzhiyun 			      size_t count, loff_t *ppos)
1079*4882a593Smuzhiyun {
1080*4882a593Smuzhiyun 	struct ath_softc *sc = file->private_data;
1081*4882a593Smuzhiyun 	unsigned long val;
1082*4882a593Smuzhiyun 	char buf[32];
1083*4882a593Smuzhiyun 	ssize_t len;
1084*4882a593Smuzhiyun 
1085*4882a593Smuzhiyun 	len = min(count, sizeof(buf) - 1);
1086*4882a593Smuzhiyun 	if (copy_from_user(buf, user_buf, len))
1087*4882a593Smuzhiyun 		return -EFAULT;
1088*4882a593Smuzhiyun 
1089*4882a593Smuzhiyun 	buf[len] = '\0';
1090*4882a593Smuzhiyun 	if (kstrtoul(buf, 0, &val))
1091*4882a593Smuzhiyun 		return -EINVAL;
1092*4882a593Smuzhiyun 
1093*4882a593Smuzhiyun 	if (val != 1)
1094*4882a593Smuzhiyun 		return -EINVAL;
1095*4882a593Smuzhiyun 
1096*4882a593Smuzhiyun 	if (!sc->force_wow) {
1097*4882a593Smuzhiyun 		sc->force_wow = true;
1098*4882a593Smuzhiyun 		ath9k_init_wow(sc->hw);
1099*4882a593Smuzhiyun 	}
1100*4882a593Smuzhiyun 
1101*4882a593Smuzhiyun 	return count;
1102*4882a593Smuzhiyun }
1103*4882a593Smuzhiyun 
1104*4882a593Smuzhiyun static const struct file_operations fops_wow = {
1105*4882a593Smuzhiyun 	.read = read_file_wow,
1106*4882a593Smuzhiyun 	.write = write_file_wow,
1107*4882a593Smuzhiyun 	.open = simple_open,
1108*4882a593Smuzhiyun 	.owner = THIS_MODULE,
1109*4882a593Smuzhiyun 	.llseek = default_llseek,
1110*4882a593Smuzhiyun };
1111*4882a593Smuzhiyun 
1112*4882a593Smuzhiyun #endif
1113*4882a593Smuzhiyun 
read_file_tpc(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)1114*4882a593Smuzhiyun static ssize_t read_file_tpc(struct file *file, char __user *user_buf,
1115*4882a593Smuzhiyun 			     size_t count, loff_t *ppos)
1116*4882a593Smuzhiyun {
1117*4882a593Smuzhiyun 	struct ath_softc *sc = file->private_data;
1118*4882a593Smuzhiyun 	struct ath_hw *ah = sc->sc_ah;
1119*4882a593Smuzhiyun 	unsigned int len = 0, size = 32;
1120*4882a593Smuzhiyun 	ssize_t retval;
1121*4882a593Smuzhiyun 	char *buf;
1122*4882a593Smuzhiyun 
1123*4882a593Smuzhiyun 	buf = kzalloc(size, GFP_KERNEL);
1124*4882a593Smuzhiyun 	if (!buf)
1125*4882a593Smuzhiyun 		return -ENOMEM;
1126*4882a593Smuzhiyun 
1127*4882a593Smuzhiyun 	len += scnprintf(buf + len, size - len, "%s\n",
1128*4882a593Smuzhiyun 			 ah->tpc_enabled ? "ENABLED" : "DISABLED");
1129*4882a593Smuzhiyun 
1130*4882a593Smuzhiyun 	if (len > size)
1131*4882a593Smuzhiyun 		len = size;
1132*4882a593Smuzhiyun 
1133*4882a593Smuzhiyun 	retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1134*4882a593Smuzhiyun 	kfree(buf);
1135*4882a593Smuzhiyun 
1136*4882a593Smuzhiyun 	return retval;
1137*4882a593Smuzhiyun }
1138*4882a593Smuzhiyun 
write_file_tpc(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)1139*4882a593Smuzhiyun static ssize_t write_file_tpc(struct file *file, const char __user *user_buf,
1140*4882a593Smuzhiyun 			      size_t count, loff_t *ppos)
1141*4882a593Smuzhiyun {
1142*4882a593Smuzhiyun 	struct ath_softc *sc = file->private_data;
1143*4882a593Smuzhiyun 	struct ath_hw *ah = sc->sc_ah;
1144*4882a593Smuzhiyun 	unsigned long val;
1145*4882a593Smuzhiyun 	char buf[32];
1146*4882a593Smuzhiyun 	ssize_t len;
1147*4882a593Smuzhiyun 	bool tpc_enabled;
1148*4882a593Smuzhiyun 
1149*4882a593Smuzhiyun 	len = min(count, sizeof(buf) - 1);
1150*4882a593Smuzhiyun 	if (copy_from_user(buf, user_buf, len))
1151*4882a593Smuzhiyun 		return -EFAULT;
1152*4882a593Smuzhiyun 
1153*4882a593Smuzhiyun 	buf[len] = '\0';
1154*4882a593Smuzhiyun 	if (kstrtoul(buf, 0, &val))
1155*4882a593Smuzhiyun 		return -EINVAL;
1156*4882a593Smuzhiyun 
1157*4882a593Smuzhiyun 	if (val > 1)
1158*4882a593Smuzhiyun 		return -EINVAL;
1159*4882a593Smuzhiyun 
1160*4882a593Smuzhiyun 	tpc_enabled = !!val;
1161*4882a593Smuzhiyun 
1162*4882a593Smuzhiyun 	if (tpc_enabled != ah->tpc_enabled) {
1163*4882a593Smuzhiyun 		ah->tpc_enabled = tpc_enabled;
1164*4882a593Smuzhiyun 
1165*4882a593Smuzhiyun 		mutex_lock(&sc->mutex);
1166*4882a593Smuzhiyun 		ath9k_set_txpower(sc, NULL);
1167*4882a593Smuzhiyun 		mutex_unlock(&sc->mutex);
1168*4882a593Smuzhiyun 	}
1169*4882a593Smuzhiyun 
1170*4882a593Smuzhiyun 	return count;
1171*4882a593Smuzhiyun }
1172*4882a593Smuzhiyun 
1173*4882a593Smuzhiyun static const struct file_operations fops_tpc = {
1174*4882a593Smuzhiyun 	.read = read_file_tpc,
1175*4882a593Smuzhiyun 	.write = write_file_tpc,
1176*4882a593Smuzhiyun 	.open = simple_open,
1177*4882a593Smuzhiyun 	.owner = THIS_MODULE,
1178*4882a593Smuzhiyun 	.llseek = default_llseek,
1179*4882a593Smuzhiyun };
1180*4882a593Smuzhiyun 
read_file_nf_override(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)1181*4882a593Smuzhiyun static ssize_t read_file_nf_override(struct file *file,
1182*4882a593Smuzhiyun 				     char __user *user_buf,
1183*4882a593Smuzhiyun 				     size_t count, loff_t *ppos)
1184*4882a593Smuzhiyun {
1185*4882a593Smuzhiyun 	struct ath_softc *sc = file->private_data;
1186*4882a593Smuzhiyun 	struct ath_hw *ah = sc->sc_ah;
1187*4882a593Smuzhiyun 	char buf[32];
1188*4882a593Smuzhiyun 	unsigned int len;
1189*4882a593Smuzhiyun 
1190*4882a593Smuzhiyun 	if (ah->nf_override == 0)
1191*4882a593Smuzhiyun 		len = sprintf(buf, "off\n");
1192*4882a593Smuzhiyun 	else
1193*4882a593Smuzhiyun 		len = sprintf(buf, "%d\n", ah->nf_override);
1194*4882a593Smuzhiyun 
1195*4882a593Smuzhiyun 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1196*4882a593Smuzhiyun }
1197*4882a593Smuzhiyun 
write_file_nf_override(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)1198*4882a593Smuzhiyun static ssize_t write_file_nf_override(struct file *file,
1199*4882a593Smuzhiyun 				      const char __user *user_buf,
1200*4882a593Smuzhiyun 				      size_t count, loff_t *ppos)
1201*4882a593Smuzhiyun {
1202*4882a593Smuzhiyun 	struct ath_softc *sc = file->private_data;
1203*4882a593Smuzhiyun 	struct ath_hw *ah = sc->sc_ah;
1204*4882a593Smuzhiyun 	long val;
1205*4882a593Smuzhiyun 	char buf[32];
1206*4882a593Smuzhiyun 	ssize_t len;
1207*4882a593Smuzhiyun 
1208*4882a593Smuzhiyun 	len = min(count, sizeof(buf) - 1);
1209*4882a593Smuzhiyun 	if (copy_from_user(buf, user_buf, len))
1210*4882a593Smuzhiyun 		return -EFAULT;
1211*4882a593Smuzhiyun 
1212*4882a593Smuzhiyun 	buf[len] = '\0';
1213*4882a593Smuzhiyun 	if (strncmp("off", buf, 3) == 0)
1214*4882a593Smuzhiyun 		val = 0;
1215*4882a593Smuzhiyun 	else if (kstrtol(buf, 0, &val))
1216*4882a593Smuzhiyun 		return -EINVAL;
1217*4882a593Smuzhiyun 
1218*4882a593Smuzhiyun 	if (val > 0)
1219*4882a593Smuzhiyun 		return -EINVAL;
1220*4882a593Smuzhiyun 
1221*4882a593Smuzhiyun 	if (val < -120)
1222*4882a593Smuzhiyun 		return -EINVAL;
1223*4882a593Smuzhiyun 
1224*4882a593Smuzhiyun 	ah->nf_override = val;
1225*4882a593Smuzhiyun 
1226*4882a593Smuzhiyun 	if (ah->curchan) {
1227*4882a593Smuzhiyun 		ath9k_ps_wakeup(sc);
1228*4882a593Smuzhiyun 		ath9k_hw_loadnf(ah, ah->curchan);
1229*4882a593Smuzhiyun 		ath9k_ps_restore(sc);
1230*4882a593Smuzhiyun 	}
1231*4882a593Smuzhiyun 
1232*4882a593Smuzhiyun 	return count;
1233*4882a593Smuzhiyun }
1234*4882a593Smuzhiyun 
1235*4882a593Smuzhiyun static const struct file_operations fops_nf_override = {
1236*4882a593Smuzhiyun 	.read = read_file_nf_override,
1237*4882a593Smuzhiyun 	.write = write_file_nf_override,
1238*4882a593Smuzhiyun 	.open = simple_open,
1239*4882a593Smuzhiyun 	.owner = THIS_MODULE,
1240*4882a593Smuzhiyun 	.llseek = default_llseek,
1241*4882a593Smuzhiyun };
1242*4882a593Smuzhiyun 
1243*4882a593Smuzhiyun /* Ethtool support for get-stats */
1244*4882a593Smuzhiyun 
1245*4882a593Smuzhiyun #define AMKSTR(nm) #nm "_BE", #nm "_BK", #nm "_VI", #nm "_VO"
1246*4882a593Smuzhiyun static const char ath9k_gstrings_stats[][ETH_GSTRING_LEN] = {
1247*4882a593Smuzhiyun 	"tx_pkts_nic",
1248*4882a593Smuzhiyun 	"tx_bytes_nic",
1249*4882a593Smuzhiyun 	"rx_pkts_nic",
1250*4882a593Smuzhiyun 	"rx_bytes_nic",
1251*4882a593Smuzhiyun 	AMKSTR(d_tx_pkts),
1252*4882a593Smuzhiyun 	AMKSTR(d_tx_bytes),
1253*4882a593Smuzhiyun 	AMKSTR(d_tx_mpdus_queued),
1254*4882a593Smuzhiyun 	AMKSTR(d_tx_mpdus_completed),
1255*4882a593Smuzhiyun 	AMKSTR(d_tx_mpdu_xretries),
1256*4882a593Smuzhiyun 	AMKSTR(d_tx_aggregates),
1257*4882a593Smuzhiyun 	AMKSTR(d_tx_ampdus_queued_hw),
1258*4882a593Smuzhiyun 	AMKSTR(d_tx_ampdus_completed),
1259*4882a593Smuzhiyun 	AMKSTR(d_tx_ampdu_retries),
1260*4882a593Smuzhiyun 	AMKSTR(d_tx_ampdu_xretries),
1261*4882a593Smuzhiyun 	AMKSTR(d_tx_fifo_underrun),
1262*4882a593Smuzhiyun 	AMKSTR(d_tx_op_exceeded),
1263*4882a593Smuzhiyun 	AMKSTR(d_tx_timer_expiry),
1264*4882a593Smuzhiyun 	AMKSTR(d_tx_desc_cfg_err),
1265*4882a593Smuzhiyun 	AMKSTR(d_tx_data_underrun),
1266*4882a593Smuzhiyun 	AMKSTR(d_tx_delim_underrun),
1267*4882a593Smuzhiyun 	"d_rx_crc_err",
1268*4882a593Smuzhiyun 	"d_rx_decrypt_crc_err",
1269*4882a593Smuzhiyun 	"d_rx_phy_err",
1270*4882a593Smuzhiyun 	"d_rx_mic_err",
1271*4882a593Smuzhiyun 	"d_rx_pre_delim_crc_err",
1272*4882a593Smuzhiyun 	"d_rx_post_delim_crc_err",
1273*4882a593Smuzhiyun 	"d_rx_decrypt_busy_err",
1274*4882a593Smuzhiyun 
1275*4882a593Smuzhiyun 	"d_rx_phyerr_radar",
1276*4882a593Smuzhiyun 	"d_rx_phyerr_ofdm_timing",
1277*4882a593Smuzhiyun 	"d_rx_phyerr_cck_timing",
1278*4882a593Smuzhiyun 
1279*4882a593Smuzhiyun };
1280*4882a593Smuzhiyun #define ATH9K_SSTATS_LEN ARRAY_SIZE(ath9k_gstrings_stats)
1281*4882a593Smuzhiyun 
ath9k_get_et_strings(struct ieee80211_hw * hw,struct ieee80211_vif * vif,u32 sset,u8 * data)1282*4882a593Smuzhiyun void ath9k_get_et_strings(struct ieee80211_hw *hw,
1283*4882a593Smuzhiyun 			  struct ieee80211_vif *vif,
1284*4882a593Smuzhiyun 			  u32 sset, u8 *data)
1285*4882a593Smuzhiyun {
1286*4882a593Smuzhiyun 	if (sset == ETH_SS_STATS)
1287*4882a593Smuzhiyun 		memcpy(data, *ath9k_gstrings_stats,
1288*4882a593Smuzhiyun 		       sizeof(ath9k_gstrings_stats));
1289*4882a593Smuzhiyun }
1290*4882a593Smuzhiyun 
ath9k_get_et_sset_count(struct ieee80211_hw * hw,struct ieee80211_vif * vif,int sset)1291*4882a593Smuzhiyun int ath9k_get_et_sset_count(struct ieee80211_hw *hw,
1292*4882a593Smuzhiyun 			    struct ieee80211_vif *vif, int sset)
1293*4882a593Smuzhiyun {
1294*4882a593Smuzhiyun 	if (sset == ETH_SS_STATS)
1295*4882a593Smuzhiyun 		return ATH9K_SSTATS_LEN;
1296*4882a593Smuzhiyun 	return 0;
1297*4882a593Smuzhiyun }
1298*4882a593Smuzhiyun 
1299*4882a593Smuzhiyun #define AWDATA(elem)							\
1300*4882a593Smuzhiyun 	do {								\
1301*4882a593Smuzhiyun 		data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].elem; \
1302*4882a593Smuzhiyun 		data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].elem; \
1303*4882a593Smuzhiyun 		data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].elem; \
1304*4882a593Smuzhiyun 		data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].elem; \
1305*4882a593Smuzhiyun 	} while (0)
1306*4882a593Smuzhiyun 
1307*4882a593Smuzhiyun #define AWDATA_RX(elem)						\
1308*4882a593Smuzhiyun 	do {							\
1309*4882a593Smuzhiyun 		data[i++] = sc->debug.stats.rxstats.elem;	\
1310*4882a593Smuzhiyun 	} while (0)
1311*4882a593Smuzhiyun 
ath9k_get_et_stats(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ethtool_stats * stats,u64 * data)1312*4882a593Smuzhiyun void ath9k_get_et_stats(struct ieee80211_hw *hw,
1313*4882a593Smuzhiyun 			struct ieee80211_vif *vif,
1314*4882a593Smuzhiyun 			struct ethtool_stats *stats, u64 *data)
1315*4882a593Smuzhiyun {
1316*4882a593Smuzhiyun 	struct ath_softc *sc = hw->priv;
1317*4882a593Smuzhiyun 	int i = 0;
1318*4882a593Smuzhiyun 
1319*4882a593Smuzhiyun 	data[i++] = (sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].tx_pkts_all +
1320*4882a593Smuzhiyun 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].tx_pkts_all +
1321*4882a593Smuzhiyun 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].tx_pkts_all +
1322*4882a593Smuzhiyun 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].tx_pkts_all);
1323*4882a593Smuzhiyun 	data[i++] = (sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].tx_bytes_all +
1324*4882a593Smuzhiyun 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].tx_bytes_all +
1325*4882a593Smuzhiyun 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].tx_bytes_all +
1326*4882a593Smuzhiyun 		     sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].tx_bytes_all);
1327*4882a593Smuzhiyun 	AWDATA_RX(rx_pkts_all);
1328*4882a593Smuzhiyun 	AWDATA_RX(rx_bytes_all);
1329*4882a593Smuzhiyun 
1330*4882a593Smuzhiyun 	AWDATA(tx_pkts_all);
1331*4882a593Smuzhiyun 	AWDATA(tx_bytes_all);
1332*4882a593Smuzhiyun 	AWDATA(queued);
1333*4882a593Smuzhiyun 	AWDATA(completed);
1334*4882a593Smuzhiyun 	AWDATA(xretries);
1335*4882a593Smuzhiyun 	AWDATA(a_aggr);
1336*4882a593Smuzhiyun 	AWDATA(a_queued_hw);
1337*4882a593Smuzhiyun 	AWDATA(a_completed);
1338*4882a593Smuzhiyun 	AWDATA(a_retries);
1339*4882a593Smuzhiyun 	AWDATA(a_xretries);
1340*4882a593Smuzhiyun 	AWDATA(fifo_underrun);
1341*4882a593Smuzhiyun 	AWDATA(xtxop);
1342*4882a593Smuzhiyun 	AWDATA(timer_exp);
1343*4882a593Smuzhiyun 	AWDATA(desc_cfg_err);
1344*4882a593Smuzhiyun 	AWDATA(data_underrun);
1345*4882a593Smuzhiyun 	AWDATA(delim_underrun);
1346*4882a593Smuzhiyun 
1347*4882a593Smuzhiyun 	AWDATA_RX(crc_err);
1348*4882a593Smuzhiyun 	AWDATA_RX(decrypt_crc_err);
1349*4882a593Smuzhiyun 	AWDATA_RX(phy_err);
1350*4882a593Smuzhiyun 	AWDATA_RX(mic_err);
1351*4882a593Smuzhiyun 	AWDATA_RX(pre_delim_crc_err);
1352*4882a593Smuzhiyun 	AWDATA_RX(post_delim_crc_err);
1353*4882a593Smuzhiyun 	AWDATA_RX(decrypt_busy_err);
1354*4882a593Smuzhiyun 
1355*4882a593Smuzhiyun 	AWDATA_RX(phy_err_stats[ATH9K_PHYERR_RADAR]);
1356*4882a593Smuzhiyun 	AWDATA_RX(phy_err_stats[ATH9K_PHYERR_OFDM_TIMING]);
1357*4882a593Smuzhiyun 	AWDATA_RX(phy_err_stats[ATH9K_PHYERR_CCK_TIMING]);
1358*4882a593Smuzhiyun 
1359*4882a593Smuzhiyun 	WARN_ON(i != ATH9K_SSTATS_LEN);
1360*4882a593Smuzhiyun }
1361*4882a593Smuzhiyun 
ath9k_deinit_debug(struct ath_softc * sc)1362*4882a593Smuzhiyun void ath9k_deinit_debug(struct ath_softc *sc)
1363*4882a593Smuzhiyun {
1364*4882a593Smuzhiyun 	ath9k_cmn_spectral_deinit_debug(&sc->spec_priv);
1365*4882a593Smuzhiyun }
1366*4882a593Smuzhiyun 
ath9k_init_debug(struct ath_hw * ah)1367*4882a593Smuzhiyun int ath9k_init_debug(struct ath_hw *ah)
1368*4882a593Smuzhiyun {
1369*4882a593Smuzhiyun 	struct ath_common *common = ath9k_hw_common(ah);
1370*4882a593Smuzhiyun 	struct ath_softc *sc = (struct ath_softc *) common->priv;
1371*4882a593Smuzhiyun 
1372*4882a593Smuzhiyun 	sc->debug.debugfs_phy = debugfs_create_dir("ath9k",
1373*4882a593Smuzhiyun 						   sc->hw->wiphy->debugfsdir);
1374*4882a593Smuzhiyun 	if (!sc->debug.debugfs_phy)
1375*4882a593Smuzhiyun 		return -ENOMEM;
1376*4882a593Smuzhiyun 
1377*4882a593Smuzhiyun #ifdef CONFIG_ATH_DEBUG
1378*4882a593Smuzhiyun 	debugfs_create_file("debug", 0600, sc->debug.debugfs_phy,
1379*4882a593Smuzhiyun 			    sc, &fops_debug);
1380*4882a593Smuzhiyun #endif
1381*4882a593Smuzhiyun 
1382*4882a593Smuzhiyun 	ath9k_dfs_init_debug(sc);
1383*4882a593Smuzhiyun 	ath9k_tx99_init_debug(sc);
1384*4882a593Smuzhiyun 	ath9k_cmn_spectral_init_debug(&sc->spec_priv, sc->debug.debugfs_phy);
1385*4882a593Smuzhiyun 
1386*4882a593Smuzhiyun 	debugfs_create_devm_seqfile(sc->dev, "dma", sc->debug.debugfs_phy,
1387*4882a593Smuzhiyun 				    read_file_dma);
1388*4882a593Smuzhiyun 	debugfs_create_devm_seqfile(sc->dev, "interrupt", sc->debug.debugfs_phy,
1389*4882a593Smuzhiyun 				    read_file_interrupt);
1390*4882a593Smuzhiyun 	debugfs_create_devm_seqfile(sc->dev, "xmit", sc->debug.debugfs_phy,
1391*4882a593Smuzhiyun 				    read_file_xmit);
1392*4882a593Smuzhiyun 	debugfs_create_devm_seqfile(sc->dev, "queues", sc->debug.debugfs_phy,
1393*4882a593Smuzhiyun 				    read_file_queues);
1394*4882a593Smuzhiyun 	debugfs_create_devm_seqfile(sc->dev, "misc", sc->debug.debugfs_phy,
1395*4882a593Smuzhiyun 				    read_file_misc);
1396*4882a593Smuzhiyun 	debugfs_create_devm_seqfile(sc->dev, "reset", sc->debug.debugfs_phy,
1397*4882a593Smuzhiyun 				    read_file_reset);
1398*4882a593Smuzhiyun 
1399*4882a593Smuzhiyun 	ath9k_cmn_debug_recv(sc->debug.debugfs_phy, &sc->debug.stats.rxstats);
1400*4882a593Smuzhiyun 	ath9k_cmn_debug_phy_err(sc->debug.debugfs_phy, &sc->debug.stats.rxstats);
1401*4882a593Smuzhiyun 
1402*4882a593Smuzhiyun 	debugfs_create_u8("rx_chainmask", 0400, sc->debug.debugfs_phy,
1403*4882a593Smuzhiyun 			  &ah->rxchainmask);
1404*4882a593Smuzhiyun 	debugfs_create_u8("tx_chainmask", 0400, sc->debug.debugfs_phy,
1405*4882a593Smuzhiyun 			  &ah->txchainmask);
1406*4882a593Smuzhiyun 	debugfs_create_file("ani", 0600,
1407*4882a593Smuzhiyun 			    sc->debug.debugfs_phy, sc, &fops_ani);
1408*4882a593Smuzhiyun 	debugfs_create_bool("paprd", 0600, sc->debug.debugfs_phy,
1409*4882a593Smuzhiyun 			    &sc->sc_ah->config.enable_paprd);
1410*4882a593Smuzhiyun 	debugfs_create_file("regidx", 0600, sc->debug.debugfs_phy,
1411*4882a593Smuzhiyun 			    sc, &fops_regidx);
1412*4882a593Smuzhiyun 	debugfs_create_file("regval", 0600, sc->debug.debugfs_phy,
1413*4882a593Smuzhiyun 			    sc, &fops_regval);
1414*4882a593Smuzhiyun 	debugfs_create_bool("ignore_extcca", 0600,
1415*4882a593Smuzhiyun 			    sc->debug.debugfs_phy,
1416*4882a593Smuzhiyun 			    &ah->config.cwm_ignore_extcca);
1417*4882a593Smuzhiyun 	debugfs_create_file("regdump", 0400, sc->debug.debugfs_phy, sc,
1418*4882a593Smuzhiyun 			    &fops_regdump);
1419*4882a593Smuzhiyun 	debugfs_create_devm_seqfile(sc->dev, "dump_nfcal",
1420*4882a593Smuzhiyun 				    sc->debug.debugfs_phy,
1421*4882a593Smuzhiyun 				    read_file_dump_nfcal);
1422*4882a593Smuzhiyun 
1423*4882a593Smuzhiyun 	ath9k_cmn_debug_base_eeprom(sc->debug.debugfs_phy, sc->sc_ah);
1424*4882a593Smuzhiyun 	ath9k_cmn_debug_modal_eeprom(sc->debug.debugfs_phy, sc->sc_ah);
1425*4882a593Smuzhiyun 
1426*4882a593Smuzhiyun 	debugfs_create_u32("gpio_mask", 0600,
1427*4882a593Smuzhiyun 			   sc->debug.debugfs_phy, &sc->sc_ah->gpio_mask);
1428*4882a593Smuzhiyun 	debugfs_create_u32("gpio_val", 0600,
1429*4882a593Smuzhiyun 			   sc->debug.debugfs_phy, &sc->sc_ah->gpio_val);
1430*4882a593Smuzhiyun 	debugfs_create_file("antenna_diversity", 0400,
1431*4882a593Smuzhiyun 			    sc->debug.debugfs_phy, sc, &fops_antenna_diversity);
1432*4882a593Smuzhiyun #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
1433*4882a593Smuzhiyun 	debugfs_create_file("bt_ant_diversity", 0600,
1434*4882a593Smuzhiyun 			    sc->debug.debugfs_phy, sc, &fops_bt_ant_diversity);
1435*4882a593Smuzhiyun 	debugfs_create_file("btcoex", 0400, sc->debug.debugfs_phy, sc,
1436*4882a593Smuzhiyun 			    &fops_btcoex);
1437*4882a593Smuzhiyun #endif
1438*4882a593Smuzhiyun 
1439*4882a593Smuzhiyun #ifdef CONFIG_ATH9K_WOW
1440*4882a593Smuzhiyun 	debugfs_create_file("wow", 0600, sc->debug.debugfs_phy, sc, &fops_wow);
1441*4882a593Smuzhiyun #endif
1442*4882a593Smuzhiyun 
1443*4882a593Smuzhiyun #ifdef CONFIG_ATH9K_DYNACK
1444*4882a593Smuzhiyun 	debugfs_create_file("ack_to", 0400, sc->debug.debugfs_phy,
1445*4882a593Smuzhiyun 			    sc, &fops_ackto);
1446*4882a593Smuzhiyun #endif
1447*4882a593Smuzhiyun 	debugfs_create_file("tpc", 0600, sc->debug.debugfs_phy, sc, &fops_tpc);
1448*4882a593Smuzhiyun 
1449*4882a593Smuzhiyun 	debugfs_create_file("nf_override", 0600,
1450*4882a593Smuzhiyun 			    sc->debug.debugfs_phy, sc, &fops_nf_override);
1451*4882a593Smuzhiyun 
1452*4882a593Smuzhiyun 	return 0;
1453*4882a593Smuzhiyun }
1454