xref: /OK3568_Linux_fs/kernel/drivers/net/wireless/intel/iwlegacy/debug.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun /******************************************************************************
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  * Contact Information:
7*4882a593Smuzhiyun  *  Intel Linux Wireless <ilw@linux.intel.com>
8*4882a593Smuzhiyun  * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
9*4882a593Smuzhiyun  *****************************************************************************/
10*4882a593Smuzhiyun #include <linux/ieee80211.h>
11*4882a593Smuzhiyun #include <linux/export.h>
12*4882a593Smuzhiyun #include <net/mac80211.h>
13*4882a593Smuzhiyun 
14*4882a593Smuzhiyun #include "common.h"
15*4882a593Smuzhiyun 
16*4882a593Smuzhiyun static void
il_clear_traffic_stats(struct il_priv * il)17*4882a593Smuzhiyun il_clear_traffic_stats(struct il_priv *il)
18*4882a593Smuzhiyun {
19*4882a593Smuzhiyun 	memset(&il->tx_stats, 0, sizeof(struct traffic_stats));
20*4882a593Smuzhiyun 	memset(&il->rx_stats, 0, sizeof(struct traffic_stats));
21*4882a593Smuzhiyun }
22*4882a593Smuzhiyun 
23*4882a593Smuzhiyun /*
24*4882a593Smuzhiyun  * il_update_stats function record all the MGMT, CTRL and DATA pkt for
25*4882a593Smuzhiyun  * both TX and Rx . Use debugfs to display the rx/rx_stats
26*4882a593Smuzhiyun  */
27*4882a593Smuzhiyun void
il_update_stats(struct il_priv * il,bool is_tx,__le16 fc,u16 len)28*4882a593Smuzhiyun il_update_stats(struct il_priv *il, bool is_tx, __le16 fc, u16 len)
29*4882a593Smuzhiyun {
30*4882a593Smuzhiyun 	struct traffic_stats *stats;
31*4882a593Smuzhiyun 
32*4882a593Smuzhiyun 	if (is_tx)
33*4882a593Smuzhiyun 		stats = &il->tx_stats;
34*4882a593Smuzhiyun 	else
35*4882a593Smuzhiyun 		stats = &il->rx_stats;
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun 	if (ieee80211_is_mgmt(fc)) {
38*4882a593Smuzhiyun 		switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
39*4882a593Smuzhiyun 		case cpu_to_le16(IEEE80211_STYPE_ASSOC_REQ):
40*4882a593Smuzhiyun 			stats->mgmt[MANAGEMENT_ASSOC_REQ]++;
41*4882a593Smuzhiyun 			break;
42*4882a593Smuzhiyun 		case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
43*4882a593Smuzhiyun 			stats->mgmt[MANAGEMENT_ASSOC_RESP]++;
44*4882a593Smuzhiyun 			break;
45*4882a593Smuzhiyun 		case cpu_to_le16(IEEE80211_STYPE_REASSOC_REQ):
46*4882a593Smuzhiyun 			stats->mgmt[MANAGEMENT_REASSOC_REQ]++;
47*4882a593Smuzhiyun 			break;
48*4882a593Smuzhiyun 		case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
49*4882a593Smuzhiyun 			stats->mgmt[MANAGEMENT_REASSOC_RESP]++;
50*4882a593Smuzhiyun 			break;
51*4882a593Smuzhiyun 		case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ):
52*4882a593Smuzhiyun 			stats->mgmt[MANAGEMENT_PROBE_REQ]++;
53*4882a593Smuzhiyun 			break;
54*4882a593Smuzhiyun 		case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
55*4882a593Smuzhiyun 			stats->mgmt[MANAGEMENT_PROBE_RESP]++;
56*4882a593Smuzhiyun 			break;
57*4882a593Smuzhiyun 		case cpu_to_le16(IEEE80211_STYPE_BEACON):
58*4882a593Smuzhiyun 			stats->mgmt[MANAGEMENT_BEACON]++;
59*4882a593Smuzhiyun 			break;
60*4882a593Smuzhiyun 		case cpu_to_le16(IEEE80211_STYPE_ATIM):
61*4882a593Smuzhiyun 			stats->mgmt[MANAGEMENT_ATIM]++;
62*4882a593Smuzhiyun 			break;
63*4882a593Smuzhiyun 		case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
64*4882a593Smuzhiyun 			stats->mgmt[MANAGEMENT_DISASSOC]++;
65*4882a593Smuzhiyun 			break;
66*4882a593Smuzhiyun 		case cpu_to_le16(IEEE80211_STYPE_AUTH):
67*4882a593Smuzhiyun 			stats->mgmt[MANAGEMENT_AUTH]++;
68*4882a593Smuzhiyun 			break;
69*4882a593Smuzhiyun 		case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
70*4882a593Smuzhiyun 			stats->mgmt[MANAGEMENT_DEAUTH]++;
71*4882a593Smuzhiyun 			break;
72*4882a593Smuzhiyun 		case cpu_to_le16(IEEE80211_STYPE_ACTION):
73*4882a593Smuzhiyun 			stats->mgmt[MANAGEMENT_ACTION]++;
74*4882a593Smuzhiyun 			break;
75*4882a593Smuzhiyun 		}
76*4882a593Smuzhiyun 	} else if (ieee80211_is_ctl(fc)) {
77*4882a593Smuzhiyun 		switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
78*4882a593Smuzhiyun 		case cpu_to_le16(IEEE80211_STYPE_BACK_REQ):
79*4882a593Smuzhiyun 			stats->ctrl[CONTROL_BACK_REQ]++;
80*4882a593Smuzhiyun 			break;
81*4882a593Smuzhiyun 		case cpu_to_le16(IEEE80211_STYPE_BACK):
82*4882a593Smuzhiyun 			stats->ctrl[CONTROL_BACK]++;
83*4882a593Smuzhiyun 			break;
84*4882a593Smuzhiyun 		case cpu_to_le16(IEEE80211_STYPE_PSPOLL):
85*4882a593Smuzhiyun 			stats->ctrl[CONTROL_PSPOLL]++;
86*4882a593Smuzhiyun 			break;
87*4882a593Smuzhiyun 		case cpu_to_le16(IEEE80211_STYPE_RTS):
88*4882a593Smuzhiyun 			stats->ctrl[CONTROL_RTS]++;
89*4882a593Smuzhiyun 			break;
90*4882a593Smuzhiyun 		case cpu_to_le16(IEEE80211_STYPE_CTS):
91*4882a593Smuzhiyun 			stats->ctrl[CONTROL_CTS]++;
92*4882a593Smuzhiyun 			break;
93*4882a593Smuzhiyun 		case cpu_to_le16(IEEE80211_STYPE_ACK):
94*4882a593Smuzhiyun 			stats->ctrl[CONTROL_ACK]++;
95*4882a593Smuzhiyun 			break;
96*4882a593Smuzhiyun 		case cpu_to_le16(IEEE80211_STYPE_CFEND):
97*4882a593Smuzhiyun 			stats->ctrl[CONTROL_CFEND]++;
98*4882a593Smuzhiyun 			break;
99*4882a593Smuzhiyun 		case cpu_to_le16(IEEE80211_STYPE_CFENDACK):
100*4882a593Smuzhiyun 			stats->ctrl[CONTROL_CFENDACK]++;
101*4882a593Smuzhiyun 			break;
102*4882a593Smuzhiyun 		}
103*4882a593Smuzhiyun 	} else {
104*4882a593Smuzhiyun 		/* data */
105*4882a593Smuzhiyun 		stats->data_cnt++;
106*4882a593Smuzhiyun 		stats->data_bytes += len;
107*4882a593Smuzhiyun 	}
108*4882a593Smuzhiyun }
109*4882a593Smuzhiyun EXPORT_SYMBOL(il_update_stats);
110*4882a593Smuzhiyun 
111*4882a593Smuzhiyun /* create and remove of files */
112*4882a593Smuzhiyun #define DEBUGFS_ADD_FILE(name, parent, mode) do {			\
113*4882a593Smuzhiyun 	debugfs_create_file(#name, mode, parent, il,			\
114*4882a593Smuzhiyun 			    &il_dbgfs_##name##_ops);			\
115*4882a593Smuzhiyun } while (0)
116*4882a593Smuzhiyun 
117*4882a593Smuzhiyun #define DEBUGFS_ADD_BOOL(name, parent, ptr) do {			\
118*4882a593Smuzhiyun 	debugfs_create_bool(#name, 0600, parent, ptr);			\
119*4882a593Smuzhiyun } while (0)
120*4882a593Smuzhiyun 
121*4882a593Smuzhiyun /* file operation */
122*4882a593Smuzhiyun #define DEBUGFS_READ_FUNC(name)                                         \
123*4882a593Smuzhiyun static ssize_t il_dbgfs_##name##_read(struct file *file,               \
124*4882a593Smuzhiyun 					char __user *user_buf,          \
125*4882a593Smuzhiyun 					size_t count, loff_t *ppos);
126*4882a593Smuzhiyun 
127*4882a593Smuzhiyun #define DEBUGFS_WRITE_FUNC(name)                                        \
128*4882a593Smuzhiyun static ssize_t il_dbgfs_##name##_write(struct file *file,              \
129*4882a593Smuzhiyun 					const char __user *user_buf,    \
130*4882a593Smuzhiyun 					size_t count, loff_t *ppos);
131*4882a593Smuzhiyun 
132*4882a593Smuzhiyun 
133*4882a593Smuzhiyun #define DEBUGFS_READ_FILE_OPS(name)				\
134*4882a593Smuzhiyun 	DEBUGFS_READ_FUNC(name);				\
135*4882a593Smuzhiyun static const struct file_operations il_dbgfs_##name##_ops = {	\
136*4882a593Smuzhiyun 	.read = il_dbgfs_##name##_read,				\
137*4882a593Smuzhiyun 	.open = simple_open,					\
138*4882a593Smuzhiyun 	.llseek = generic_file_llseek,				\
139*4882a593Smuzhiyun };
140*4882a593Smuzhiyun 
141*4882a593Smuzhiyun #define DEBUGFS_WRITE_FILE_OPS(name)				\
142*4882a593Smuzhiyun 	DEBUGFS_WRITE_FUNC(name);				\
143*4882a593Smuzhiyun static const struct file_operations il_dbgfs_##name##_ops = {	\
144*4882a593Smuzhiyun 	.write = il_dbgfs_##name##_write,			\
145*4882a593Smuzhiyun 	.open = simple_open,					\
146*4882a593Smuzhiyun 	.llseek = generic_file_llseek,				\
147*4882a593Smuzhiyun };
148*4882a593Smuzhiyun 
149*4882a593Smuzhiyun #define DEBUGFS_READ_WRITE_FILE_OPS(name)			\
150*4882a593Smuzhiyun 	DEBUGFS_READ_FUNC(name);				\
151*4882a593Smuzhiyun 	DEBUGFS_WRITE_FUNC(name);				\
152*4882a593Smuzhiyun static const struct file_operations il_dbgfs_##name##_ops = {	\
153*4882a593Smuzhiyun 	.write = il_dbgfs_##name##_write,			\
154*4882a593Smuzhiyun 	.read = il_dbgfs_##name##_read,				\
155*4882a593Smuzhiyun 	.open = simple_open,					\
156*4882a593Smuzhiyun 	.llseek = generic_file_llseek,				\
157*4882a593Smuzhiyun };
158*4882a593Smuzhiyun 
159*4882a593Smuzhiyun static const char *
il_get_mgmt_string(int cmd)160*4882a593Smuzhiyun il_get_mgmt_string(int cmd)
161*4882a593Smuzhiyun {
162*4882a593Smuzhiyun 	switch (cmd) {
163*4882a593Smuzhiyun 	IL_CMD(MANAGEMENT_ASSOC_REQ);
164*4882a593Smuzhiyun 	IL_CMD(MANAGEMENT_ASSOC_RESP);
165*4882a593Smuzhiyun 	IL_CMD(MANAGEMENT_REASSOC_REQ);
166*4882a593Smuzhiyun 	IL_CMD(MANAGEMENT_REASSOC_RESP);
167*4882a593Smuzhiyun 	IL_CMD(MANAGEMENT_PROBE_REQ);
168*4882a593Smuzhiyun 	IL_CMD(MANAGEMENT_PROBE_RESP);
169*4882a593Smuzhiyun 	IL_CMD(MANAGEMENT_BEACON);
170*4882a593Smuzhiyun 	IL_CMD(MANAGEMENT_ATIM);
171*4882a593Smuzhiyun 	IL_CMD(MANAGEMENT_DISASSOC);
172*4882a593Smuzhiyun 	IL_CMD(MANAGEMENT_AUTH);
173*4882a593Smuzhiyun 	IL_CMD(MANAGEMENT_DEAUTH);
174*4882a593Smuzhiyun 	IL_CMD(MANAGEMENT_ACTION);
175*4882a593Smuzhiyun 	default:
176*4882a593Smuzhiyun 		return "UNKNOWN";
177*4882a593Smuzhiyun 
178*4882a593Smuzhiyun 	}
179*4882a593Smuzhiyun }
180*4882a593Smuzhiyun 
181*4882a593Smuzhiyun static const char *
il_get_ctrl_string(int cmd)182*4882a593Smuzhiyun il_get_ctrl_string(int cmd)
183*4882a593Smuzhiyun {
184*4882a593Smuzhiyun 	switch (cmd) {
185*4882a593Smuzhiyun 	IL_CMD(CONTROL_BACK_REQ);
186*4882a593Smuzhiyun 	IL_CMD(CONTROL_BACK);
187*4882a593Smuzhiyun 	IL_CMD(CONTROL_PSPOLL);
188*4882a593Smuzhiyun 	IL_CMD(CONTROL_RTS);
189*4882a593Smuzhiyun 	IL_CMD(CONTROL_CTS);
190*4882a593Smuzhiyun 	IL_CMD(CONTROL_ACK);
191*4882a593Smuzhiyun 	IL_CMD(CONTROL_CFEND);
192*4882a593Smuzhiyun 	IL_CMD(CONTROL_CFENDACK);
193*4882a593Smuzhiyun 	default:
194*4882a593Smuzhiyun 		return "UNKNOWN";
195*4882a593Smuzhiyun 
196*4882a593Smuzhiyun 	}
197*4882a593Smuzhiyun }
198*4882a593Smuzhiyun 
199*4882a593Smuzhiyun static ssize_t
il_dbgfs_tx_stats_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)200*4882a593Smuzhiyun il_dbgfs_tx_stats_read(struct file *file, char __user *user_buf, size_t count,
201*4882a593Smuzhiyun 		       loff_t *ppos)
202*4882a593Smuzhiyun {
203*4882a593Smuzhiyun 
204*4882a593Smuzhiyun 	struct il_priv *il = file->private_data;
205*4882a593Smuzhiyun 	char *buf;
206*4882a593Smuzhiyun 	int pos = 0;
207*4882a593Smuzhiyun 
208*4882a593Smuzhiyun 	int cnt;
209*4882a593Smuzhiyun 	ssize_t ret;
210*4882a593Smuzhiyun 	const size_t bufsz =
211*4882a593Smuzhiyun 	    100 + sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
212*4882a593Smuzhiyun 	buf = kzalloc(bufsz, GFP_KERNEL);
213*4882a593Smuzhiyun 	if (!buf)
214*4882a593Smuzhiyun 		return -ENOMEM;
215*4882a593Smuzhiyun 	pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
216*4882a593Smuzhiyun 	for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
217*4882a593Smuzhiyun 		pos +=
218*4882a593Smuzhiyun 		    scnprintf(buf + pos, bufsz - pos, "\t%25s\t\t: %u\n",
219*4882a593Smuzhiyun 			      il_get_mgmt_string(cnt), il->tx_stats.mgmt[cnt]);
220*4882a593Smuzhiyun 	}
221*4882a593Smuzhiyun 	pos += scnprintf(buf + pos, bufsz - pos, "Control\n");
222*4882a593Smuzhiyun 	for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
223*4882a593Smuzhiyun 		pos +=
224*4882a593Smuzhiyun 		    scnprintf(buf + pos, bufsz - pos, "\t%25s\t\t: %u\n",
225*4882a593Smuzhiyun 			      il_get_ctrl_string(cnt), il->tx_stats.ctrl[cnt]);
226*4882a593Smuzhiyun 	}
227*4882a593Smuzhiyun 	pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
228*4882a593Smuzhiyun 	pos +=
229*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
230*4882a593Smuzhiyun 		      il->tx_stats.data_cnt);
231*4882a593Smuzhiyun 	pos +=
232*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
233*4882a593Smuzhiyun 		      il->tx_stats.data_bytes);
234*4882a593Smuzhiyun 	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
235*4882a593Smuzhiyun 	kfree(buf);
236*4882a593Smuzhiyun 	return ret;
237*4882a593Smuzhiyun }
238*4882a593Smuzhiyun 
239*4882a593Smuzhiyun static ssize_t
il_dbgfs_clear_traffic_stats_write(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)240*4882a593Smuzhiyun il_dbgfs_clear_traffic_stats_write(struct file *file,
241*4882a593Smuzhiyun 				   const char __user *user_buf, size_t count,
242*4882a593Smuzhiyun 				   loff_t *ppos)
243*4882a593Smuzhiyun {
244*4882a593Smuzhiyun 	struct il_priv *il = file->private_data;
245*4882a593Smuzhiyun 	u32 clear_flag;
246*4882a593Smuzhiyun 	char buf[8];
247*4882a593Smuzhiyun 	int buf_size;
248*4882a593Smuzhiyun 
249*4882a593Smuzhiyun 	memset(buf, 0, sizeof(buf));
250*4882a593Smuzhiyun 	buf_size = min(count, sizeof(buf) - 1);
251*4882a593Smuzhiyun 	if (copy_from_user(buf, user_buf, buf_size))
252*4882a593Smuzhiyun 		return -EFAULT;
253*4882a593Smuzhiyun 	if (sscanf(buf, "%x", &clear_flag) != 1)
254*4882a593Smuzhiyun 		return -EFAULT;
255*4882a593Smuzhiyun 	il_clear_traffic_stats(il);
256*4882a593Smuzhiyun 
257*4882a593Smuzhiyun 	return count;
258*4882a593Smuzhiyun }
259*4882a593Smuzhiyun 
260*4882a593Smuzhiyun static ssize_t
il_dbgfs_rx_stats_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)261*4882a593Smuzhiyun il_dbgfs_rx_stats_read(struct file *file, char __user *user_buf, size_t count,
262*4882a593Smuzhiyun 		       loff_t *ppos)
263*4882a593Smuzhiyun {
264*4882a593Smuzhiyun 
265*4882a593Smuzhiyun 	struct il_priv *il = file->private_data;
266*4882a593Smuzhiyun 	char *buf;
267*4882a593Smuzhiyun 	int pos = 0;
268*4882a593Smuzhiyun 	int cnt;
269*4882a593Smuzhiyun 	ssize_t ret;
270*4882a593Smuzhiyun 	const size_t bufsz =
271*4882a593Smuzhiyun 	    100 + sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
272*4882a593Smuzhiyun 	buf = kzalloc(bufsz, GFP_KERNEL);
273*4882a593Smuzhiyun 	if (!buf)
274*4882a593Smuzhiyun 		return -ENOMEM;
275*4882a593Smuzhiyun 
276*4882a593Smuzhiyun 	pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
277*4882a593Smuzhiyun 	for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
278*4882a593Smuzhiyun 		pos +=
279*4882a593Smuzhiyun 		    scnprintf(buf + pos, bufsz - pos, "\t%25s\t\t: %u\n",
280*4882a593Smuzhiyun 			      il_get_mgmt_string(cnt), il->rx_stats.mgmt[cnt]);
281*4882a593Smuzhiyun 	}
282*4882a593Smuzhiyun 	pos += scnprintf(buf + pos, bufsz - pos, "Control:\n");
283*4882a593Smuzhiyun 	for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
284*4882a593Smuzhiyun 		pos +=
285*4882a593Smuzhiyun 		    scnprintf(buf + pos, bufsz - pos, "\t%25s\t\t: %u\n",
286*4882a593Smuzhiyun 			      il_get_ctrl_string(cnt), il->rx_stats.ctrl[cnt]);
287*4882a593Smuzhiyun 	}
288*4882a593Smuzhiyun 	pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
289*4882a593Smuzhiyun 	pos +=
290*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
291*4882a593Smuzhiyun 		      il->rx_stats.data_cnt);
292*4882a593Smuzhiyun 	pos +=
293*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
294*4882a593Smuzhiyun 		      il->rx_stats.data_bytes);
295*4882a593Smuzhiyun 
296*4882a593Smuzhiyun 	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
297*4882a593Smuzhiyun 	kfree(buf);
298*4882a593Smuzhiyun 	return ret;
299*4882a593Smuzhiyun }
300*4882a593Smuzhiyun 
301*4882a593Smuzhiyun #define BYTE1_MASK 0x000000ff;
302*4882a593Smuzhiyun #define BYTE2_MASK 0x0000ffff;
303*4882a593Smuzhiyun #define BYTE3_MASK 0x00ffffff;
304*4882a593Smuzhiyun static ssize_t
il_dbgfs_sram_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)305*4882a593Smuzhiyun il_dbgfs_sram_read(struct file *file, char __user *user_buf, size_t count,
306*4882a593Smuzhiyun 		   loff_t *ppos)
307*4882a593Smuzhiyun {
308*4882a593Smuzhiyun 	u32 val;
309*4882a593Smuzhiyun 	char *buf;
310*4882a593Smuzhiyun 	ssize_t ret;
311*4882a593Smuzhiyun 	int i;
312*4882a593Smuzhiyun 	int pos = 0;
313*4882a593Smuzhiyun 	struct il_priv *il = file->private_data;
314*4882a593Smuzhiyun 	size_t bufsz;
315*4882a593Smuzhiyun 
316*4882a593Smuzhiyun 	/* default is to dump the entire data segment */
317*4882a593Smuzhiyun 	if (!il->dbgfs_sram_offset && !il->dbgfs_sram_len) {
318*4882a593Smuzhiyun 		il->dbgfs_sram_offset = 0x800000;
319*4882a593Smuzhiyun 		if (il->ucode_type == UCODE_INIT)
320*4882a593Smuzhiyun 			il->dbgfs_sram_len = il->ucode_init_data.len;
321*4882a593Smuzhiyun 		else
322*4882a593Smuzhiyun 			il->dbgfs_sram_len = il->ucode_data.len;
323*4882a593Smuzhiyun 	}
324*4882a593Smuzhiyun 	bufsz = 30 + il->dbgfs_sram_len * sizeof(char) * 10;
325*4882a593Smuzhiyun 	buf = kmalloc(bufsz, GFP_KERNEL);
326*4882a593Smuzhiyun 	if (!buf)
327*4882a593Smuzhiyun 		return -ENOMEM;
328*4882a593Smuzhiyun 	pos +=
329*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "sram_len: 0x%x\n",
330*4882a593Smuzhiyun 		      il->dbgfs_sram_len);
331*4882a593Smuzhiyun 	pos +=
332*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "sram_offset: 0x%x\n",
333*4882a593Smuzhiyun 		      il->dbgfs_sram_offset);
334*4882a593Smuzhiyun 	for (i = il->dbgfs_sram_len; i > 0; i -= 4) {
335*4882a593Smuzhiyun 		val =
336*4882a593Smuzhiyun 		    il_read_targ_mem(il,
337*4882a593Smuzhiyun 				     il->dbgfs_sram_offset +
338*4882a593Smuzhiyun 				     il->dbgfs_sram_len - i);
339*4882a593Smuzhiyun 		if (i < 4) {
340*4882a593Smuzhiyun 			switch (i) {
341*4882a593Smuzhiyun 			case 1:
342*4882a593Smuzhiyun 				val &= BYTE1_MASK;
343*4882a593Smuzhiyun 				break;
344*4882a593Smuzhiyun 			case 2:
345*4882a593Smuzhiyun 				val &= BYTE2_MASK;
346*4882a593Smuzhiyun 				break;
347*4882a593Smuzhiyun 			case 3:
348*4882a593Smuzhiyun 				val &= BYTE3_MASK;
349*4882a593Smuzhiyun 				break;
350*4882a593Smuzhiyun 			}
351*4882a593Smuzhiyun 		}
352*4882a593Smuzhiyun 		if (!(i % 16))
353*4882a593Smuzhiyun 			pos += scnprintf(buf + pos, bufsz - pos, "\n");
354*4882a593Smuzhiyun 		pos += scnprintf(buf + pos, bufsz - pos, "0x%08x ", val);
355*4882a593Smuzhiyun 	}
356*4882a593Smuzhiyun 	pos += scnprintf(buf + pos, bufsz - pos, "\n");
357*4882a593Smuzhiyun 
358*4882a593Smuzhiyun 	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
359*4882a593Smuzhiyun 	kfree(buf);
360*4882a593Smuzhiyun 	return ret;
361*4882a593Smuzhiyun }
362*4882a593Smuzhiyun 
363*4882a593Smuzhiyun static ssize_t
il_dbgfs_sram_write(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)364*4882a593Smuzhiyun il_dbgfs_sram_write(struct file *file, const char __user *user_buf,
365*4882a593Smuzhiyun 		    size_t count, loff_t *ppos)
366*4882a593Smuzhiyun {
367*4882a593Smuzhiyun 	struct il_priv *il = file->private_data;
368*4882a593Smuzhiyun 	char buf[64];
369*4882a593Smuzhiyun 	int buf_size;
370*4882a593Smuzhiyun 	u32 offset, len;
371*4882a593Smuzhiyun 
372*4882a593Smuzhiyun 	memset(buf, 0, sizeof(buf));
373*4882a593Smuzhiyun 	buf_size = min(count, sizeof(buf) - 1);
374*4882a593Smuzhiyun 	if (copy_from_user(buf, user_buf, buf_size))
375*4882a593Smuzhiyun 		return -EFAULT;
376*4882a593Smuzhiyun 
377*4882a593Smuzhiyun 	if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
378*4882a593Smuzhiyun 		il->dbgfs_sram_offset = offset;
379*4882a593Smuzhiyun 		il->dbgfs_sram_len = len;
380*4882a593Smuzhiyun 	} else {
381*4882a593Smuzhiyun 		il->dbgfs_sram_offset = 0;
382*4882a593Smuzhiyun 		il->dbgfs_sram_len = 0;
383*4882a593Smuzhiyun 	}
384*4882a593Smuzhiyun 
385*4882a593Smuzhiyun 	return count;
386*4882a593Smuzhiyun }
387*4882a593Smuzhiyun 
388*4882a593Smuzhiyun static ssize_t
il_dbgfs_stations_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)389*4882a593Smuzhiyun il_dbgfs_stations_read(struct file *file, char __user *user_buf, size_t count,
390*4882a593Smuzhiyun 		       loff_t *ppos)
391*4882a593Smuzhiyun {
392*4882a593Smuzhiyun 	struct il_priv *il = file->private_data;
393*4882a593Smuzhiyun 	struct il_station_entry *station;
394*4882a593Smuzhiyun 	int max_sta = il->hw_params.max_stations;
395*4882a593Smuzhiyun 	char *buf;
396*4882a593Smuzhiyun 	int i, j, pos = 0;
397*4882a593Smuzhiyun 	ssize_t ret;
398*4882a593Smuzhiyun 	/* Add 30 for initial string */
399*4882a593Smuzhiyun 	const size_t bufsz = 30 + sizeof(char) * 500 * (il->num_stations);
400*4882a593Smuzhiyun 
401*4882a593Smuzhiyun 	buf = kmalloc(bufsz, GFP_KERNEL);
402*4882a593Smuzhiyun 	if (!buf)
403*4882a593Smuzhiyun 		return -ENOMEM;
404*4882a593Smuzhiyun 
405*4882a593Smuzhiyun 	pos +=
406*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n",
407*4882a593Smuzhiyun 		      il->num_stations);
408*4882a593Smuzhiyun 
409*4882a593Smuzhiyun 	for (i = 0; i < max_sta; i++) {
410*4882a593Smuzhiyun 		station = &il->stations[i];
411*4882a593Smuzhiyun 		if (!station->used)
412*4882a593Smuzhiyun 			continue;
413*4882a593Smuzhiyun 		pos +=
414*4882a593Smuzhiyun 		    scnprintf(buf + pos, bufsz - pos,
415*4882a593Smuzhiyun 			      "station %d - addr: %pM, flags: %#x\n", i,
416*4882a593Smuzhiyun 			      station->sta.sta.addr,
417*4882a593Smuzhiyun 			      station->sta.station_flags_msk);
418*4882a593Smuzhiyun 		pos +=
419*4882a593Smuzhiyun 		    scnprintf(buf + pos, bufsz - pos,
420*4882a593Smuzhiyun 			      "TID\tseq_num\ttxq_id\tframes\ttfds\t");
421*4882a593Smuzhiyun 		pos +=
422*4882a593Smuzhiyun 		    scnprintf(buf + pos, bufsz - pos,
423*4882a593Smuzhiyun 			      "start_idx\tbitmap\t\t\trate_n_flags\n");
424*4882a593Smuzhiyun 
425*4882a593Smuzhiyun 		for (j = 0; j < MAX_TID_COUNT; j++) {
426*4882a593Smuzhiyun 			pos +=
427*4882a593Smuzhiyun 			    scnprintf(buf + pos, bufsz - pos,
428*4882a593Smuzhiyun 				      "%d:\t%#x\t%#x\t%u\t%u\t%u\t\t%#.16llx\t%#x",
429*4882a593Smuzhiyun 				      j, station->tid[j].seq_number,
430*4882a593Smuzhiyun 				      station->tid[j].agg.txq_id,
431*4882a593Smuzhiyun 				      station->tid[j].agg.frame_count,
432*4882a593Smuzhiyun 				      station->tid[j].tfds_in_queue,
433*4882a593Smuzhiyun 				      station->tid[j].agg.start_idx,
434*4882a593Smuzhiyun 				      station->tid[j].agg.bitmap,
435*4882a593Smuzhiyun 				      station->tid[j].agg.rate_n_flags);
436*4882a593Smuzhiyun 
437*4882a593Smuzhiyun 			if (station->tid[j].agg.wait_for_ba)
438*4882a593Smuzhiyun 				pos +=
439*4882a593Smuzhiyun 				    scnprintf(buf + pos, bufsz - pos,
440*4882a593Smuzhiyun 					      " - waitforba");
441*4882a593Smuzhiyun 			pos += scnprintf(buf + pos, bufsz - pos, "\n");
442*4882a593Smuzhiyun 		}
443*4882a593Smuzhiyun 
444*4882a593Smuzhiyun 		pos += scnprintf(buf + pos, bufsz - pos, "\n");
445*4882a593Smuzhiyun 	}
446*4882a593Smuzhiyun 
447*4882a593Smuzhiyun 	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
448*4882a593Smuzhiyun 	kfree(buf);
449*4882a593Smuzhiyun 	return ret;
450*4882a593Smuzhiyun }
451*4882a593Smuzhiyun 
452*4882a593Smuzhiyun static ssize_t
il_dbgfs_nvm_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)453*4882a593Smuzhiyun il_dbgfs_nvm_read(struct file *file, char __user *user_buf, size_t count,
454*4882a593Smuzhiyun 		  loff_t *ppos)
455*4882a593Smuzhiyun {
456*4882a593Smuzhiyun 	ssize_t ret;
457*4882a593Smuzhiyun 	struct il_priv *il = file->private_data;
458*4882a593Smuzhiyun 	int pos = 0, ofs = 0, buf_size = 0;
459*4882a593Smuzhiyun 	const u8 *ptr;
460*4882a593Smuzhiyun 	char *buf;
461*4882a593Smuzhiyun 	u16 eeprom_ver;
462*4882a593Smuzhiyun 	size_t eeprom_len = il->cfg->eeprom_size;
463*4882a593Smuzhiyun 	buf_size = 4 * eeprom_len + 256;
464*4882a593Smuzhiyun 
465*4882a593Smuzhiyun 	if (eeprom_len % 16) {
466*4882a593Smuzhiyun 		IL_ERR("NVM size is not multiple of 16.\n");
467*4882a593Smuzhiyun 		return -ENODATA;
468*4882a593Smuzhiyun 	}
469*4882a593Smuzhiyun 
470*4882a593Smuzhiyun 	ptr = il->eeprom;
471*4882a593Smuzhiyun 	if (!ptr) {
472*4882a593Smuzhiyun 		IL_ERR("Invalid EEPROM memory\n");
473*4882a593Smuzhiyun 		return -ENOMEM;
474*4882a593Smuzhiyun 	}
475*4882a593Smuzhiyun 
476*4882a593Smuzhiyun 	/* 4 characters for byte 0xYY */
477*4882a593Smuzhiyun 	buf = kzalloc(buf_size, GFP_KERNEL);
478*4882a593Smuzhiyun 	if (!buf) {
479*4882a593Smuzhiyun 		IL_ERR("Can not allocate Buffer\n");
480*4882a593Smuzhiyun 		return -ENOMEM;
481*4882a593Smuzhiyun 	}
482*4882a593Smuzhiyun 	eeprom_ver = il_eeprom_query16(il, EEPROM_VERSION);
483*4882a593Smuzhiyun 	pos +=
484*4882a593Smuzhiyun 	    scnprintf(buf + pos, buf_size - pos, "EEPROM " "version: 0x%x\n",
485*4882a593Smuzhiyun 		      eeprom_ver);
486*4882a593Smuzhiyun 	for (ofs = 0; ofs < eeprom_len; ofs += 16) {
487*4882a593Smuzhiyun 		pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x %16ph\n",
488*4882a593Smuzhiyun 				 ofs, ptr + ofs);
489*4882a593Smuzhiyun 	}
490*4882a593Smuzhiyun 
491*4882a593Smuzhiyun 	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
492*4882a593Smuzhiyun 	kfree(buf);
493*4882a593Smuzhiyun 	return ret;
494*4882a593Smuzhiyun }
495*4882a593Smuzhiyun 
496*4882a593Smuzhiyun static ssize_t
il_dbgfs_channels_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)497*4882a593Smuzhiyun il_dbgfs_channels_read(struct file *file, char __user *user_buf, size_t count,
498*4882a593Smuzhiyun 		       loff_t *ppos)
499*4882a593Smuzhiyun {
500*4882a593Smuzhiyun 	struct il_priv *il = file->private_data;
501*4882a593Smuzhiyun 	struct ieee80211_channel *channels = NULL;
502*4882a593Smuzhiyun 	const struct ieee80211_supported_band *supp_band = NULL;
503*4882a593Smuzhiyun 	int pos = 0, i, bufsz = PAGE_SIZE;
504*4882a593Smuzhiyun 	char *buf;
505*4882a593Smuzhiyun 	ssize_t ret;
506*4882a593Smuzhiyun 
507*4882a593Smuzhiyun 	if (!test_bit(S_GEO_CONFIGURED, &il->status))
508*4882a593Smuzhiyun 		return -EAGAIN;
509*4882a593Smuzhiyun 
510*4882a593Smuzhiyun 	buf = kzalloc(bufsz, GFP_KERNEL);
511*4882a593Smuzhiyun 	if (!buf) {
512*4882a593Smuzhiyun 		IL_ERR("Can not allocate Buffer\n");
513*4882a593Smuzhiyun 		return -ENOMEM;
514*4882a593Smuzhiyun 	}
515*4882a593Smuzhiyun 
516*4882a593Smuzhiyun 	supp_band = il_get_hw_mode(il, NL80211_BAND_2GHZ);
517*4882a593Smuzhiyun 	if (supp_band) {
518*4882a593Smuzhiyun 		channels = supp_band->channels;
519*4882a593Smuzhiyun 
520*4882a593Smuzhiyun 		pos +=
521*4882a593Smuzhiyun 		    scnprintf(buf + pos, bufsz - pos,
522*4882a593Smuzhiyun 			      "Displaying %d channels in 2.4GHz band 802.11bg):\n",
523*4882a593Smuzhiyun 			      supp_band->n_channels);
524*4882a593Smuzhiyun 
525*4882a593Smuzhiyun 		for (i = 0; i < supp_band->n_channels; i++)
526*4882a593Smuzhiyun 			pos +=
527*4882a593Smuzhiyun 			    scnprintf(buf + pos, bufsz - pos,
528*4882a593Smuzhiyun 				      "%d: %ddBm: BSS%s%s, %s.\n",
529*4882a593Smuzhiyun 				      channels[i].hw_value,
530*4882a593Smuzhiyun 				      channels[i].max_power,
531*4882a593Smuzhiyun 				      channels[i].
532*4882a593Smuzhiyun 				      flags & IEEE80211_CHAN_RADAR ?
533*4882a593Smuzhiyun 				      " (IEEE 802.11h required)" : "",
534*4882a593Smuzhiyun 				      ((channels[i].
535*4882a593Smuzhiyun 					flags & IEEE80211_CHAN_NO_IR) ||
536*4882a593Smuzhiyun 				       (channels[i].
537*4882a593Smuzhiyun 					flags & IEEE80211_CHAN_RADAR)) ? "" :
538*4882a593Smuzhiyun 				      ", IBSS",
539*4882a593Smuzhiyun 				      channels[i].
540*4882a593Smuzhiyun 				      flags & IEEE80211_CHAN_NO_IR ?
541*4882a593Smuzhiyun 				      "passive only" : "active/passive");
542*4882a593Smuzhiyun 	}
543*4882a593Smuzhiyun 	supp_band = il_get_hw_mode(il, NL80211_BAND_5GHZ);
544*4882a593Smuzhiyun 	if (supp_band) {
545*4882a593Smuzhiyun 		channels = supp_band->channels;
546*4882a593Smuzhiyun 
547*4882a593Smuzhiyun 		pos +=
548*4882a593Smuzhiyun 		    scnprintf(buf + pos, bufsz - pos,
549*4882a593Smuzhiyun 			      "Displaying %d channels in 5.2GHz band (802.11a)\n",
550*4882a593Smuzhiyun 			      supp_band->n_channels);
551*4882a593Smuzhiyun 
552*4882a593Smuzhiyun 		for (i = 0; i < supp_band->n_channels; i++)
553*4882a593Smuzhiyun 			pos +=
554*4882a593Smuzhiyun 			    scnprintf(buf + pos, bufsz - pos,
555*4882a593Smuzhiyun 				      "%d: %ddBm: BSS%s%s, %s.\n",
556*4882a593Smuzhiyun 				      channels[i].hw_value,
557*4882a593Smuzhiyun 				      channels[i].max_power,
558*4882a593Smuzhiyun 				      channels[i].
559*4882a593Smuzhiyun 				      flags & IEEE80211_CHAN_RADAR ?
560*4882a593Smuzhiyun 				      " (IEEE 802.11h required)" : "",
561*4882a593Smuzhiyun 				      ((channels[i].
562*4882a593Smuzhiyun 					flags & IEEE80211_CHAN_NO_IR) ||
563*4882a593Smuzhiyun 				       (channels[i].
564*4882a593Smuzhiyun 					flags & IEEE80211_CHAN_RADAR)) ? "" :
565*4882a593Smuzhiyun 				      ", IBSS",
566*4882a593Smuzhiyun 				      channels[i].
567*4882a593Smuzhiyun 				      flags & IEEE80211_CHAN_NO_IR ?
568*4882a593Smuzhiyun 				      "passive only" : "active/passive");
569*4882a593Smuzhiyun 	}
570*4882a593Smuzhiyun 	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
571*4882a593Smuzhiyun 	kfree(buf);
572*4882a593Smuzhiyun 	return ret;
573*4882a593Smuzhiyun }
574*4882a593Smuzhiyun 
575*4882a593Smuzhiyun static ssize_t
il_dbgfs_status_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)576*4882a593Smuzhiyun il_dbgfs_status_read(struct file *file, char __user *user_buf, size_t count,
577*4882a593Smuzhiyun 		     loff_t *ppos)
578*4882a593Smuzhiyun {
579*4882a593Smuzhiyun 
580*4882a593Smuzhiyun 	struct il_priv *il = file->private_data;
581*4882a593Smuzhiyun 	char buf[512];
582*4882a593Smuzhiyun 	int pos = 0;
583*4882a593Smuzhiyun 	const size_t bufsz = sizeof(buf);
584*4882a593Smuzhiyun 
585*4882a593Smuzhiyun 	pos +=
586*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "S_HCMD_ACTIVE:\t %d\n",
587*4882a593Smuzhiyun 		      test_bit(S_HCMD_ACTIVE, &il->status));
588*4882a593Smuzhiyun 	pos +=
589*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "S_INT_ENABLED:\t %d\n",
590*4882a593Smuzhiyun 		      test_bit(S_INT_ENABLED, &il->status));
591*4882a593Smuzhiyun 	pos +=
592*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "S_RFKILL:\t %d\n",
593*4882a593Smuzhiyun 		      test_bit(S_RFKILL, &il->status));
594*4882a593Smuzhiyun 	pos +=
595*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "S_CT_KILL:\t\t %d\n",
596*4882a593Smuzhiyun 		      test_bit(S_CT_KILL, &il->status));
597*4882a593Smuzhiyun 	pos +=
598*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "S_INIT:\t\t %d\n",
599*4882a593Smuzhiyun 		      test_bit(S_INIT, &il->status));
600*4882a593Smuzhiyun 	pos +=
601*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "S_ALIVE:\t\t %d\n",
602*4882a593Smuzhiyun 		      test_bit(S_ALIVE, &il->status));
603*4882a593Smuzhiyun 	pos +=
604*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "S_READY:\t\t %d\n",
605*4882a593Smuzhiyun 		      test_bit(S_READY, &il->status));
606*4882a593Smuzhiyun 	pos +=
607*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "S_TEMPERATURE:\t %d\n",
608*4882a593Smuzhiyun 		      test_bit(S_TEMPERATURE, &il->status));
609*4882a593Smuzhiyun 	pos +=
610*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "S_GEO_CONFIGURED:\t %d\n",
611*4882a593Smuzhiyun 		      test_bit(S_GEO_CONFIGURED, &il->status));
612*4882a593Smuzhiyun 	pos +=
613*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "S_EXIT_PENDING:\t %d\n",
614*4882a593Smuzhiyun 		      test_bit(S_EXIT_PENDING, &il->status));
615*4882a593Smuzhiyun 	pos +=
616*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "S_STATS:\t %d\n",
617*4882a593Smuzhiyun 		      test_bit(S_STATS, &il->status));
618*4882a593Smuzhiyun 	pos +=
619*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "S_SCANNING:\t %d\n",
620*4882a593Smuzhiyun 		      test_bit(S_SCANNING, &il->status));
621*4882a593Smuzhiyun 	pos +=
622*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "S_SCAN_ABORTING:\t %d\n",
623*4882a593Smuzhiyun 		      test_bit(S_SCAN_ABORTING, &il->status));
624*4882a593Smuzhiyun 	pos +=
625*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "S_SCAN_HW:\t\t %d\n",
626*4882a593Smuzhiyun 		      test_bit(S_SCAN_HW, &il->status));
627*4882a593Smuzhiyun 	pos +=
628*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "S_POWER_PMI:\t %d\n",
629*4882a593Smuzhiyun 		      test_bit(S_POWER_PMI, &il->status));
630*4882a593Smuzhiyun 	pos +=
631*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "S_FW_ERROR:\t %d\n",
632*4882a593Smuzhiyun 		      test_bit(S_FW_ERROR, &il->status));
633*4882a593Smuzhiyun 	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
634*4882a593Smuzhiyun }
635*4882a593Smuzhiyun 
636*4882a593Smuzhiyun static ssize_t
il_dbgfs_interrupt_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)637*4882a593Smuzhiyun il_dbgfs_interrupt_read(struct file *file, char __user *user_buf, size_t count,
638*4882a593Smuzhiyun 			loff_t *ppos)
639*4882a593Smuzhiyun {
640*4882a593Smuzhiyun 
641*4882a593Smuzhiyun 	struct il_priv *il = file->private_data;
642*4882a593Smuzhiyun 	int pos = 0;
643*4882a593Smuzhiyun 	int cnt = 0;
644*4882a593Smuzhiyun 	char *buf;
645*4882a593Smuzhiyun 	int bufsz = 24 * 64;	/* 24 items * 64 char per item */
646*4882a593Smuzhiyun 	ssize_t ret;
647*4882a593Smuzhiyun 
648*4882a593Smuzhiyun 	buf = kzalloc(bufsz, GFP_KERNEL);
649*4882a593Smuzhiyun 	if (!buf) {
650*4882a593Smuzhiyun 		IL_ERR("Can not allocate Buffer\n");
651*4882a593Smuzhiyun 		return -ENOMEM;
652*4882a593Smuzhiyun 	}
653*4882a593Smuzhiyun 
654*4882a593Smuzhiyun 	pos +=
655*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "Interrupt Statistics Report:\n");
656*4882a593Smuzhiyun 
657*4882a593Smuzhiyun 	pos +=
658*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "HW Error:\t\t\t %u\n",
659*4882a593Smuzhiyun 		      il->isr_stats.hw);
660*4882a593Smuzhiyun 	pos +=
661*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "SW Error:\t\t\t %u\n",
662*4882a593Smuzhiyun 		      il->isr_stats.sw);
663*4882a593Smuzhiyun 	if (il->isr_stats.sw || il->isr_stats.hw) {
664*4882a593Smuzhiyun 		pos +=
665*4882a593Smuzhiyun 		    scnprintf(buf + pos, bufsz - pos,
666*4882a593Smuzhiyun 			      "\tLast Restarting Code:  0x%X\n",
667*4882a593Smuzhiyun 			      il->isr_stats.err_code);
668*4882a593Smuzhiyun 	}
669*4882a593Smuzhiyun #ifdef CONFIG_IWLEGACY_DEBUG
670*4882a593Smuzhiyun 	pos +=
671*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "Frame transmitted:\t\t %u\n",
672*4882a593Smuzhiyun 		      il->isr_stats.sch);
673*4882a593Smuzhiyun 	pos +=
674*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "Alive interrupt:\t\t %u\n",
675*4882a593Smuzhiyun 		      il->isr_stats.alive);
676*4882a593Smuzhiyun #endif
677*4882a593Smuzhiyun 	pos +=
678*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos,
679*4882a593Smuzhiyun 		      "HW RF KILL switch toggled:\t %u\n",
680*4882a593Smuzhiyun 		      il->isr_stats.rfkill);
681*4882a593Smuzhiyun 
682*4882a593Smuzhiyun 	pos +=
683*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "CT KILL:\t\t\t %u\n",
684*4882a593Smuzhiyun 		      il->isr_stats.ctkill);
685*4882a593Smuzhiyun 
686*4882a593Smuzhiyun 	pos +=
687*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "Wakeup Interrupt:\t\t %u\n",
688*4882a593Smuzhiyun 		      il->isr_stats.wakeup);
689*4882a593Smuzhiyun 
690*4882a593Smuzhiyun 	pos +=
691*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "Rx command responses:\t\t %u\n",
692*4882a593Smuzhiyun 		      il->isr_stats.rx);
693*4882a593Smuzhiyun 	for (cnt = 0; cnt < IL_CN_MAX; cnt++) {
694*4882a593Smuzhiyun 		if (il->isr_stats.handlers[cnt] > 0)
695*4882a593Smuzhiyun 			pos +=
696*4882a593Smuzhiyun 			    scnprintf(buf + pos, bufsz - pos,
697*4882a593Smuzhiyun 				      "\tRx handler[%36s]:\t\t %u\n",
698*4882a593Smuzhiyun 				      il_get_cmd_string(cnt),
699*4882a593Smuzhiyun 				      il->isr_stats.handlers[cnt]);
700*4882a593Smuzhiyun 	}
701*4882a593Smuzhiyun 
702*4882a593Smuzhiyun 	pos +=
703*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "Tx/FH interrupt:\t\t %u\n",
704*4882a593Smuzhiyun 		      il->isr_stats.tx);
705*4882a593Smuzhiyun 
706*4882a593Smuzhiyun 	pos +=
707*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "Unexpected INTA:\t\t %u\n",
708*4882a593Smuzhiyun 		      il->isr_stats.unhandled);
709*4882a593Smuzhiyun 
710*4882a593Smuzhiyun 	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
711*4882a593Smuzhiyun 	kfree(buf);
712*4882a593Smuzhiyun 	return ret;
713*4882a593Smuzhiyun }
714*4882a593Smuzhiyun 
715*4882a593Smuzhiyun static ssize_t
il_dbgfs_interrupt_write(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)716*4882a593Smuzhiyun il_dbgfs_interrupt_write(struct file *file, const char __user *user_buf,
717*4882a593Smuzhiyun 			 size_t count, loff_t *ppos)
718*4882a593Smuzhiyun {
719*4882a593Smuzhiyun 	struct il_priv *il = file->private_data;
720*4882a593Smuzhiyun 	char buf[8];
721*4882a593Smuzhiyun 	int buf_size;
722*4882a593Smuzhiyun 	u32 reset_flag;
723*4882a593Smuzhiyun 
724*4882a593Smuzhiyun 	memset(buf, 0, sizeof(buf));
725*4882a593Smuzhiyun 	buf_size = min(count, sizeof(buf) - 1);
726*4882a593Smuzhiyun 	if (copy_from_user(buf, user_buf, buf_size))
727*4882a593Smuzhiyun 		return -EFAULT;
728*4882a593Smuzhiyun 	if (sscanf(buf, "%x", &reset_flag) != 1)
729*4882a593Smuzhiyun 		return -EFAULT;
730*4882a593Smuzhiyun 	if (reset_flag == 0)
731*4882a593Smuzhiyun 		il_clear_isr_stats(il);
732*4882a593Smuzhiyun 
733*4882a593Smuzhiyun 	return count;
734*4882a593Smuzhiyun }
735*4882a593Smuzhiyun 
736*4882a593Smuzhiyun static ssize_t
il_dbgfs_qos_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)737*4882a593Smuzhiyun il_dbgfs_qos_read(struct file *file, char __user *user_buf, size_t count,
738*4882a593Smuzhiyun 		  loff_t *ppos)
739*4882a593Smuzhiyun {
740*4882a593Smuzhiyun 	struct il_priv *il = file->private_data;
741*4882a593Smuzhiyun 	int pos = 0, i;
742*4882a593Smuzhiyun 	char buf[256];
743*4882a593Smuzhiyun 	const size_t bufsz = sizeof(buf);
744*4882a593Smuzhiyun 
745*4882a593Smuzhiyun 	for (i = 0; i < AC_NUM; i++) {
746*4882a593Smuzhiyun 		pos +=
747*4882a593Smuzhiyun 		    scnprintf(buf + pos, bufsz - pos,
748*4882a593Smuzhiyun 			      "\tcw_min\tcw_max\taifsn\ttxop\n");
749*4882a593Smuzhiyun 		pos +=
750*4882a593Smuzhiyun 		    scnprintf(buf + pos, bufsz - pos,
751*4882a593Smuzhiyun 			      "AC[%d]\t%u\t%u\t%u\t%u\n", i,
752*4882a593Smuzhiyun 			      il->qos_data.def_qos_parm.ac[i].cw_min,
753*4882a593Smuzhiyun 			      il->qos_data.def_qos_parm.ac[i].cw_max,
754*4882a593Smuzhiyun 			      il->qos_data.def_qos_parm.ac[i].aifsn,
755*4882a593Smuzhiyun 			      il->qos_data.def_qos_parm.ac[i].edca_txop);
756*4882a593Smuzhiyun 	}
757*4882a593Smuzhiyun 
758*4882a593Smuzhiyun 	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
759*4882a593Smuzhiyun }
760*4882a593Smuzhiyun 
761*4882a593Smuzhiyun static ssize_t
il_dbgfs_disable_ht40_write(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)762*4882a593Smuzhiyun il_dbgfs_disable_ht40_write(struct file *file, const char __user *user_buf,
763*4882a593Smuzhiyun 			    size_t count, loff_t *ppos)
764*4882a593Smuzhiyun {
765*4882a593Smuzhiyun 	struct il_priv *il = file->private_data;
766*4882a593Smuzhiyun 	char buf[8];
767*4882a593Smuzhiyun 	int buf_size;
768*4882a593Smuzhiyun 	int ht40;
769*4882a593Smuzhiyun 
770*4882a593Smuzhiyun 	memset(buf, 0, sizeof(buf));
771*4882a593Smuzhiyun 	buf_size = min(count, sizeof(buf) - 1);
772*4882a593Smuzhiyun 	if (copy_from_user(buf, user_buf, buf_size))
773*4882a593Smuzhiyun 		return -EFAULT;
774*4882a593Smuzhiyun 	if (sscanf(buf, "%d", &ht40) != 1)
775*4882a593Smuzhiyun 		return -EFAULT;
776*4882a593Smuzhiyun 	if (!il_is_any_associated(il))
777*4882a593Smuzhiyun 		il->disable_ht40 = ht40 ? true : false;
778*4882a593Smuzhiyun 	else {
779*4882a593Smuzhiyun 		IL_ERR("Sta associated with AP - "
780*4882a593Smuzhiyun 		       "Change to 40MHz channel support is not allowed\n");
781*4882a593Smuzhiyun 		return -EINVAL;
782*4882a593Smuzhiyun 	}
783*4882a593Smuzhiyun 
784*4882a593Smuzhiyun 	return count;
785*4882a593Smuzhiyun }
786*4882a593Smuzhiyun 
787*4882a593Smuzhiyun static ssize_t
il_dbgfs_disable_ht40_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)788*4882a593Smuzhiyun il_dbgfs_disable_ht40_read(struct file *file, char __user *user_buf,
789*4882a593Smuzhiyun 			   size_t count, loff_t *ppos)
790*4882a593Smuzhiyun {
791*4882a593Smuzhiyun 	struct il_priv *il = file->private_data;
792*4882a593Smuzhiyun 	char buf[100];
793*4882a593Smuzhiyun 	int pos = 0;
794*4882a593Smuzhiyun 	const size_t bufsz = sizeof(buf);
795*4882a593Smuzhiyun 
796*4882a593Smuzhiyun 	pos +=
797*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "11n 40MHz Mode: %s\n",
798*4882a593Smuzhiyun 		      il->disable_ht40 ? "Disabled" : "Enabled");
799*4882a593Smuzhiyun 	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
800*4882a593Smuzhiyun }
801*4882a593Smuzhiyun 
802*4882a593Smuzhiyun DEBUGFS_READ_WRITE_FILE_OPS(sram);
803*4882a593Smuzhiyun DEBUGFS_READ_FILE_OPS(nvm);
804*4882a593Smuzhiyun DEBUGFS_READ_FILE_OPS(stations);
805*4882a593Smuzhiyun DEBUGFS_READ_FILE_OPS(channels);
806*4882a593Smuzhiyun DEBUGFS_READ_FILE_OPS(status);
807*4882a593Smuzhiyun DEBUGFS_READ_WRITE_FILE_OPS(interrupt);
808*4882a593Smuzhiyun DEBUGFS_READ_FILE_OPS(qos);
809*4882a593Smuzhiyun DEBUGFS_READ_WRITE_FILE_OPS(disable_ht40);
810*4882a593Smuzhiyun 
811*4882a593Smuzhiyun static ssize_t
il_dbgfs_tx_queue_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)812*4882a593Smuzhiyun il_dbgfs_tx_queue_read(struct file *file, char __user *user_buf, size_t count,
813*4882a593Smuzhiyun 		       loff_t *ppos)
814*4882a593Smuzhiyun {
815*4882a593Smuzhiyun 
816*4882a593Smuzhiyun 	struct il_priv *il = file->private_data;
817*4882a593Smuzhiyun 	struct il_tx_queue *txq;
818*4882a593Smuzhiyun 	struct il_queue *q;
819*4882a593Smuzhiyun 	char *buf;
820*4882a593Smuzhiyun 	int pos = 0;
821*4882a593Smuzhiyun 	int cnt;
822*4882a593Smuzhiyun 	int ret;
823*4882a593Smuzhiyun 	const size_t bufsz =
824*4882a593Smuzhiyun 	    sizeof(char) * 64 * il->cfg->num_of_queues;
825*4882a593Smuzhiyun 
826*4882a593Smuzhiyun 	if (!il->txq) {
827*4882a593Smuzhiyun 		IL_ERR("txq not ready\n");
828*4882a593Smuzhiyun 		return -EAGAIN;
829*4882a593Smuzhiyun 	}
830*4882a593Smuzhiyun 	buf = kzalloc(bufsz, GFP_KERNEL);
831*4882a593Smuzhiyun 	if (!buf)
832*4882a593Smuzhiyun 		return -ENOMEM;
833*4882a593Smuzhiyun 
834*4882a593Smuzhiyun 	for (cnt = 0; cnt < il->hw_params.max_txq_num; cnt++) {
835*4882a593Smuzhiyun 		txq = &il->txq[cnt];
836*4882a593Smuzhiyun 		q = &txq->q;
837*4882a593Smuzhiyun 		pos +=
838*4882a593Smuzhiyun 		    scnprintf(buf + pos, bufsz - pos,
839*4882a593Smuzhiyun 			      "hwq %.2d: read=%u write=%u stop=%d"
840*4882a593Smuzhiyun 			      " swq_id=%#.2x (ac %d/hwq %d)\n", cnt,
841*4882a593Smuzhiyun 			      q->read_ptr, q->write_ptr,
842*4882a593Smuzhiyun 			      !!test_bit(cnt, il->queue_stopped),
843*4882a593Smuzhiyun 			      txq->swq_id, txq->swq_id & 3,
844*4882a593Smuzhiyun 			      (txq->swq_id >> 2) & 0x1f);
845*4882a593Smuzhiyun 		if (cnt >= 4)
846*4882a593Smuzhiyun 			continue;
847*4882a593Smuzhiyun 		/* for the ACs, display the stop count too */
848*4882a593Smuzhiyun 		pos +=
849*4882a593Smuzhiyun 		    scnprintf(buf + pos, bufsz - pos,
850*4882a593Smuzhiyun 			      "        stop-count: %d\n",
851*4882a593Smuzhiyun 			      atomic_read(&il->queue_stop_count[cnt]));
852*4882a593Smuzhiyun 	}
853*4882a593Smuzhiyun 	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
854*4882a593Smuzhiyun 	kfree(buf);
855*4882a593Smuzhiyun 	return ret;
856*4882a593Smuzhiyun }
857*4882a593Smuzhiyun 
858*4882a593Smuzhiyun static ssize_t
il_dbgfs_rx_queue_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)859*4882a593Smuzhiyun il_dbgfs_rx_queue_read(struct file *file, char __user *user_buf, size_t count,
860*4882a593Smuzhiyun 		       loff_t *ppos)
861*4882a593Smuzhiyun {
862*4882a593Smuzhiyun 
863*4882a593Smuzhiyun 	struct il_priv *il = file->private_data;
864*4882a593Smuzhiyun 	struct il_rx_queue *rxq = &il->rxq;
865*4882a593Smuzhiyun 	char buf[256];
866*4882a593Smuzhiyun 	int pos = 0;
867*4882a593Smuzhiyun 	const size_t bufsz = sizeof(buf);
868*4882a593Smuzhiyun 
869*4882a593Smuzhiyun 	pos += scnprintf(buf + pos, bufsz - pos, "read: %u\n", rxq->read);
870*4882a593Smuzhiyun 	pos += scnprintf(buf + pos, bufsz - pos, "write: %u\n", rxq->write);
871*4882a593Smuzhiyun 	pos +=
872*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "free_count: %u\n",
873*4882a593Smuzhiyun 		      rxq->free_count);
874*4882a593Smuzhiyun 	if (rxq->rb_stts) {
875*4882a593Smuzhiyun 		pos +=
876*4882a593Smuzhiyun 		    scnprintf(buf + pos, bufsz - pos, "closed_rb_num: %u\n",
877*4882a593Smuzhiyun 			      le16_to_cpu(rxq->rb_stts->
878*4882a593Smuzhiyun 					  closed_rb_num) & 0x0FFF);
879*4882a593Smuzhiyun 	} else {
880*4882a593Smuzhiyun 		pos +=
881*4882a593Smuzhiyun 		    scnprintf(buf + pos, bufsz - pos,
882*4882a593Smuzhiyun 			      "closed_rb_num: Not Allocated\n");
883*4882a593Smuzhiyun 	}
884*4882a593Smuzhiyun 	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
885*4882a593Smuzhiyun }
886*4882a593Smuzhiyun 
887*4882a593Smuzhiyun static ssize_t
il_dbgfs_ucode_rx_stats_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)888*4882a593Smuzhiyun il_dbgfs_ucode_rx_stats_read(struct file *file, char __user *user_buf,
889*4882a593Smuzhiyun 			     size_t count, loff_t *ppos)
890*4882a593Smuzhiyun {
891*4882a593Smuzhiyun 	struct il_priv *il = file->private_data;
892*4882a593Smuzhiyun 
893*4882a593Smuzhiyun 	return il->debugfs_ops->rx_stats_read(file, user_buf, count, ppos);
894*4882a593Smuzhiyun }
895*4882a593Smuzhiyun 
896*4882a593Smuzhiyun static ssize_t
il_dbgfs_ucode_tx_stats_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)897*4882a593Smuzhiyun il_dbgfs_ucode_tx_stats_read(struct file *file, char __user *user_buf,
898*4882a593Smuzhiyun 			     size_t count, loff_t *ppos)
899*4882a593Smuzhiyun {
900*4882a593Smuzhiyun 	struct il_priv *il = file->private_data;
901*4882a593Smuzhiyun 
902*4882a593Smuzhiyun 	return il->debugfs_ops->tx_stats_read(file, user_buf, count, ppos);
903*4882a593Smuzhiyun }
904*4882a593Smuzhiyun 
905*4882a593Smuzhiyun static ssize_t
il_dbgfs_ucode_general_stats_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)906*4882a593Smuzhiyun il_dbgfs_ucode_general_stats_read(struct file *file, char __user *user_buf,
907*4882a593Smuzhiyun 				  size_t count, loff_t *ppos)
908*4882a593Smuzhiyun {
909*4882a593Smuzhiyun 	struct il_priv *il = file->private_data;
910*4882a593Smuzhiyun 
911*4882a593Smuzhiyun 	return il->debugfs_ops->general_stats_read(file, user_buf, count, ppos);
912*4882a593Smuzhiyun }
913*4882a593Smuzhiyun 
914*4882a593Smuzhiyun static ssize_t
il_dbgfs_sensitivity_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)915*4882a593Smuzhiyun il_dbgfs_sensitivity_read(struct file *file, char __user *user_buf,
916*4882a593Smuzhiyun 			  size_t count, loff_t *ppos)
917*4882a593Smuzhiyun {
918*4882a593Smuzhiyun 
919*4882a593Smuzhiyun 	struct il_priv *il = file->private_data;
920*4882a593Smuzhiyun 	int pos = 0;
921*4882a593Smuzhiyun 	int cnt = 0;
922*4882a593Smuzhiyun 	char *buf;
923*4882a593Smuzhiyun 	int bufsz = sizeof(struct il_sensitivity_data) * 4 + 100;
924*4882a593Smuzhiyun 	ssize_t ret;
925*4882a593Smuzhiyun 	struct il_sensitivity_data *data;
926*4882a593Smuzhiyun 
927*4882a593Smuzhiyun 	data = &il->sensitivity_data;
928*4882a593Smuzhiyun 	buf = kzalloc(bufsz, GFP_KERNEL);
929*4882a593Smuzhiyun 	if (!buf) {
930*4882a593Smuzhiyun 		IL_ERR("Can not allocate Buffer\n");
931*4882a593Smuzhiyun 		return -ENOMEM;
932*4882a593Smuzhiyun 	}
933*4882a593Smuzhiyun 
934*4882a593Smuzhiyun 	pos +=
935*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm:\t\t\t %u\n",
936*4882a593Smuzhiyun 		      data->auto_corr_ofdm);
937*4882a593Smuzhiyun 	pos +=
938*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_mrc:\t\t %u\n",
939*4882a593Smuzhiyun 		      data->auto_corr_ofdm_mrc);
940*4882a593Smuzhiyun 	pos +=
941*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_x1:\t\t %u\n",
942*4882a593Smuzhiyun 		      data->auto_corr_ofdm_x1);
943*4882a593Smuzhiyun 	pos +=
944*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_mrc_x1:\t\t %u\n",
945*4882a593Smuzhiyun 		      data->auto_corr_ofdm_mrc_x1);
946*4882a593Smuzhiyun 	pos +=
947*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "auto_corr_cck:\t\t\t %u\n",
948*4882a593Smuzhiyun 		      data->auto_corr_cck);
949*4882a593Smuzhiyun 	pos +=
950*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "auto_corr_cck_mrc:\t\t %u\n",
951*4882a593Smuzhiyun 		      data->auto_corr_cck_mrc);
952*4882a593Smuzhiyun 	pos +=
953*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos,
954*4882a593Smuzhiyun 		      "last_bad_plcp_cnt_ofdm:\t\t %u\n",
955*4882a593Smuzhiyun 		      data->last_bad_plcp_cnt_ofdm);
956*4882a593Smuzhiyun 	pos +=
957*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_ofdm:\t\t %u\n",
958*4882a593Smuzhiyun 		      data->last_fa_cnt_ofdm);
959*4882a593Smuzhiyun 	pos +=
960*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "last_bad_plcp_cnt_cck:\t\t %u\n",
961*4882a593Smuzhiyun 		      data->last_bad_plcp_cnt_cck);
962*4882a593Smuzhiyun 	pos +=
963*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_cck:\t\t %u\n",
964*4882a593Smuzhiyun 		      data->last_fa_cnt_cck);
965*4882a593Smuzhiyun 	pos +=
966*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "nrg_curr_state:\t\t\t %u\n",
967*4882a593Smuzhiyun 		      data->nrg_curr_state);
968*4882a593Smuzhiyun 	pos +=
969*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "nrg_prev_state:\t\t\t %u\n",
970*4882a593Smuzhiyun 		      data->nrg_prev_state);
971*4882a593Smuzhiyun 	pos += scnprintf(buf + pos, bufsz - pos, "nrg_value:\t\t\t");
972*4882a593Smuzhiyun 	for (cnt = 0; cnt < 10; cnt++) {
973*4882a593Smuzhiyun 		pos +=
974*4882a593Smuzhiyun 		    scnprintf(buf + pos, bufsz - pos, " %u",
975*4882a593Smuzhiyun 			      data->nrg_value[cnt]);
976*4882a593Smuzhiyun 	}
977*4882a593Smuzhiyun 	pos += scnprintf(buf + pos, bufsz - pos, "\n");
978*4882a593Smuzhiyun 	pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_rssi:\t\t");
979*4882a593Smuzhiyun 	for (cnt = 0; cnt < NRG_NUM_PREV_STAT_L; cnt++) {
980*4882a593Smuzhiyun 		pos +=
981*4882a593Smuzhiyun 		    scnprintf(buf + pos, bufsz - pos, " %u",
982*4882a593Smuzhiyun 			      data->nrg_silence_rssi[cnt]);
983*4882a593Smuzhiyun 	}
984*4882a593Smuzhiyun 	pos += scnprintf(buf + pos, bufsz - pos, "\n");
985*4882a593Smuzhiyun 	pos +=
986*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "nrg_silence_ref:\t\t %u\n",
987*4882a593Smuzhiyun 		      data->nrg_silence_ref);
988*4882a593Smuzhiyun 	pos +=
989*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "nrg_energy_idx:\t\t\t %u\n",
990*4882a593Smuzhiyun 		      data->nrg_energy_idx);
991*4882a593Smuzhiyun 	pos +=
992*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "nrg_silence_idx:\t\t %u\n",
993*4882a593Smuzhiyun 		      data->nrg_silence_idx);
994*4882a593Smuzhiyun 	pos +=
995*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "nrg_th_cck:\t\t\t %u\n",
996*4882a593Smuzhiyun 		      data->nrg_th_cck);
997*4882a593Smuzhiyun 	pos +=
998*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos,
999*4882a593Smuzhiyun 		      "nrg_auto_corr_silence_diff:\t %u\n",
1000*4882a593Smuzhiyun 		      data->nrg_auto_corr_silence_diff);
1001*4882a593Smuzhiyun 	pos +=
1002*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "num_in_cck_no_fa:\t\t %u\n",
1003*4882a593Smuzhiyun 		      data->num_in_cck_no_fa);
1004*4882a593Smuzhiyun 	pos +=
1005*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "nrg_th_ofdm:\t\t\t %u\n",
1006*4882a593Smuzhiyun 		      data->nrg_th_ofdm);
1007*4882a593Smuzhiyun 
1008*4882a593Smuzhiyun 	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1009*4882a593Smuzhiyun 	kfree(buf);
1010*4882a593Smuzhiyun 	return ret;
1011*4882a593Smuzhiyun }
1012*4882a593Smuzhiyun 
1013*4882a593Smuzhiyun static ssize_t
il_dbgfs_chain_noise_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)1014*4882a593Smuzhiyun il_dbgfs_chain_noise_read(struct file *file, char __user *user_buf,
1015*4882a593Smuzhiyun 			  size_t count, loff_t *ppos)
1016*4882a593Smuzhiyun {
1017*4882a593Smuzhiyun 
1018*4882a593Smuzhiyun 	struct il_priv *il = file->private_data;
1019*4882a593Smuzhiyun 	int pos = 0;
1020*4882a593Smuzhiyun 	int cnt = 0;
1021*4882a593Smuzhiyun 	char *buf;
1022*4882a593Smuzhiyun 	int bufsz = sizeof(struct il_chain_noise_data) * 4 + 100;
1023*4882a593Smuzhiyun 	ssize_t ret;
1024*4882a593Smuzhiyun 	struct il_chain_noise_data *data;
1025*4882a593Smuzhiyun 
1026*4882a593Smuzhiyun 	data = &il->chain_noise_data;
1027*4882a593Smuzhiyun 	buf = kzalloc(bufsz, GFP_KERNEL);
1028*4882a593Smuzhiyun 	if (!buf) {
1029*4882a593Smuzhiyun 		IL_ERR("Can not allocate Buffer\n");
1030*4882a593Smuzhiyun 		return -ENOMEM;
1031*4882a593Smuzhiyun 	}
1032*4882a593Smuzhiyun 
1033*4882a593Smuzhiyun 	pos +=
1034*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "active_chains:\t\t\t %u\n",
1035*4882a593Smuzhiyun 		      data->active_chains);
1036*4882a593Smuzhiyun 	pos +=
1037*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "chain_noise_a:\t\t\t %u\n",
1038*4882a593Smuzhiyun 		      data->chain_noise_a);
1039*4882a593Smuzhiyun 	pos +=
1040*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "chain_noise_b:\t\t\t %u\n",
1041*4882a593Smuzhiyun 		      data->chain_noise_b);
1042*4882a593Smuzhiyun 	pos +=
1043*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "chain_noise_c:\t\t\t %u\n",
1044*4882a593Smuzhiyun 		      data->chain_noise_c);
1045*4882a593Smuzhiyun 	pos +=
1046*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "chain_signal_a:\t\t\t %u\n",
1047*4882a593Smuzhiyun 		      data->chain_signal_a);
1048*4882a593Smuzhiyun 	pos +=
1049*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "chain_signal_b:\t\t\t %u\n",
1050*4882a593Smuzhiyun 		      data->chain_signal_b);
1051*4882a593Smuzhiyun 	pos +=
1052*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "chain_signal_c:\t\t\t %u\n",
1053*4882a593Smuzhiyun 		      data->chain_signal_c);
1054*4882a593Smuzhiyun 	pos +=
1055*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "beacon_count:\t\t\t %u\n",
1056*4882a593Smuzhiyun 		      data->beacon_count);
1057*4882a593Smuzhiyun 
1058*4882a593Smuzhiyun 	pos += scnprintf(buf + pos, bufsz - pos, "disconn_array:\t\t\t");
1059*4882a593Smuzhiyun 	for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
1060*4882a593Smuzhiyun 		pos +=
1061*4882a593Smuzhiyun 		    scnprintf(buf + pos, bufsz - pos, " %u",
1062*4882a593Smuzhiyun 			      data->disconn_array[cnt]);
1063*4882a593Smuzhiyun 	}
1064*4882a593Smuzhiyun 	pos += scnprintf(buf + pos, bufsz - pos, "\n");
1065*4882a593Smuzhiyun 	pos += scnprintf(buf + pos, bufsz - pos, "delta_gain_code:\t\t");
1066*4882a593Smuzhiyun 	for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
1067*4882a593Smuzhiyun 		pos +=
1068*4882a593Smuzhiyun 		    scnprintf(buf + pos, bufsz - pos, " %u",
1069*4882a593Smuzhiyun 			      data->delta_gain_code[cnt]);
1070*4882a593Smuzhiyun 	}
1071*4882a593Smuzhiyun 	pos += scnprintf(buf + pos, bufsz - pos, "\n");
1072*4882a593Smuzhiyun 	pos +=
1073*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "radio_write:\t\t\t %u\n",
1074*4882a593Smuzhiyun 		      data->radio_write);
1075*4882a593Smuzhiyun 	pos +=
1076*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "state:\t\t\t\t %u\n",
1077*4882a593Smuzhiyun 		      data->state);
1078*4882a593Smuzhiyun 
1079*4882a593Smuzhiyun 	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1080*4882a593Smuzhiyun 	kfree(buf);
1081*4882a593Smuzhiyun 	return ret;
1082*4882a593Smuzhiyun }
1083*4882a593Smuzhiyun 
1084*4882a593Smuzhiyun static ssize_t
il_dbgfs_power_save_status_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)1085*4882a593Smuzhiyun il_dbgfs_power_save_status_read(struct file *file, char __user *user_buf,
1086*4882a593Smuzhiyun 				size_t count, loff_t *ppos)
1087*4882a593Smuzhiyun {
1088*4882a593Smuzhiyun 	struct il_priv *il = file->private_data;
1089*4882a593Smuzhiyun 	char buf[60];
1090*4882a593Smuzhiyun 	int pos = 0;
1091*4882a593Smuzhiyun 	const size_t bufsz = sizeof(buf);
1092*4882a593Smuzhiyun 	u32 pwrsave_status;
1093*4882a593Smuzhiyun 
1094*4882a593Smuzhiyun 	pwrsave_status =
1095*4882a593Smuzhiyun 	    _il_rd(il, CSR_GP_CNTRL) & CSR_GP_REG_POWER_SAVE_STATUS_MSK;
1096*4882a593Smuzhiyun 
1097*4882a593Smuzhiyun 	pos += scnprintf(buf + pos, bufsz - pos, "Power Save Status: ");
1098*4882a593Smuzhiyun 	pos +=
1099*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "%s\n",
1100*4882a593Smuzhiyun 		      (pwrsave_status == CSR_GP_REG_NO_POWER_SAVE) ? "none" :
1101*4882a593Smuzhiyun 		      (pwrsave_status == CSR_GP_REG_MAC_POWER_SAVE) ? "MAC" :
1102*4882a593Smuzhiyun 		      (pwrsave_status == CSR_GP_REG_PHY_POWER_SAVE) ? "PHY" :
1103*4882a593Smuzhiyun 		      "error");
1104*4882a593Smuzhiyun 
1105*4882a593Smuzhiyun 	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1106*4882a593Smuzhiyun }
1107*4882a593Smuzhiyun 
1108*4882a593Smuzhiyun static ssize_t
il_dbgfs_clear_ucode_stats_write(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)1109*4882a593Smuzhiyun il_dbgfs_clear_ucode_stats_write(struct file *file,
1110*4882a593Smuzhiyun 				 const char __user *user_buf, size_t count,
1111*4882a593Smuzhiyun 				 loff_t *ppos)
1112*4882a593Smuzhiyun {
1113*4882a593Smuzhiyun 	struct il_priv *il = file->private_data;
1114*4882a593Smuzhiyun 	char buf[8];
1115*4882a593Smuzhiyun 	int buf_size;
1116*4882a593Smuzhiyun 	int clear;
1117*4882a593Smuzhiyun 
1118*4882a593Smuzhiyun 	memset(buf, 0, sizeof(buf));
1119*4882a593Smuzhiyun 	buf_size = min(count, sizeof(buf) - 1);
1120*4882a593Smuzhiyun 	if (copy_from_user(buf, user_buf, buf_size))
1121*4882a593Smuzhiyun 		return -EFAULT;
1122*4882a593Smuzhiyun 	if (sscanf(buf, "%d", &clear) != 1)
1123*4882a593Smuzhiyun 		return -EFAULT;
1124*4882a593Smuzhiyun 
1125*4882a593Smuzhiyun 	/* make request to uCode to retrieve stats information */
1126*4882a593Smuzhiyun 	mutex_lock(&il->mutex);
1127*4882a593Smuzhiyun 	il_send_stats_request(il, CMD_SYNC, true);
1128*4882a593Smuzhiyun 	mutex_unlock(&il->mutex);
1129*4882a593Smuzhiyun 
1130*4882a593Smuzhiyun 	return count;
1131*4882a593Smuzhiyun }
1132*4882a593Smuzhiyun 
1133*4882a593Smuzhiyun static ssize_t
il_dbgfs_rxon_flags_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)1134*4882a593Smuzhiyun il_dbgfs_rxon_flags_read(struct file *file, char __user *user_buf,
1135*4882a593Smuzhiyun 			 size_t count, loff_t *ppos)
1136*4882a593Smuzhiyun {
1137*4882a593Smuzhiyun 
1138*4882a593Smuzhiyun 	struct il_priv *il = file->private_data;
1139*4882a593Smuzhiyun 	int len = 0;
1140*4882a593Smuzhiyun 	char buf[20];
1141*4882a593Smuzhiyun 
1142*4882a593Smuzhiyun 	len = sprintf(buf, "0x%04X\n", le32_to_cpu(il->active.flags));
1143*4882a593Smuzhiyun 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1144*4882a593Smuzhiyun }
1145*4882a593Smuzhiyun 
1146*4882a593Smuzhiyun static ssize_t
il_dbgfs_rxon_filter_flags_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)1147*4882a593Smuzhiyun il_dbgfs_rxon_filter_flags_read(struct file *file, char __user *user_buf,
1148*4882a593Smuzhiyun 				size_t count, loff_t *ppos)
1149*4882a593Smuzhiyun {
1150*4882a593Smuzhiyun 
1151*4882a593Smuzhiyun 	struct il_priv *il = file->private_data;
1152*4882a593Smuzhiyun 	int len = 0;
1153*4882a593Smuzhiyun 	char buf[20];
1154*4882a593Smuzhiyun 
1155*4882a593Smuzhiyun 	len =
1156*4882a593Smuzhiyun 	    sprintf(buf, "0x%04X\n", le32_to_cpu(il->active.filter_flags));
1157*4882a593Smuzhiyun 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1158*4882a593Smuzhiyun }
1159*4882a593Smuzhiyun 
1160*4882a593Smuzhiyun static ssize_t
il_dbgfs_fh_reg_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)1161*4882a593Smuzhiyun il_dbgfs_fh_reg_read(struct file *file, char __user *user_buf, size_t count,
1162*4882a593Smuzhiyun 		     loff_t *ppos)
1163*4882a593Smuzhiyun {
1164*4882a593Smuzhiyun 	struct il_priv *il = file->private_data;
1165*4882a593Smuzhiyun 	char *buf;
1166*4882a593Smuzhiyun 	int pos = 0;
1167*4882a593Smuzhiyun 	ssize_t ret = -EFAULT;
1168*4882a593Smuzhiyun 
1169*4882a593Smuzhiyun 	if (il->ops->dump_fh) {
1170*4882a593Smuzhiyun 		ret = pos = il->ops->dump_fh(il, &buf, true);
1171*4882a593Smuzhiyun 		if (buf) {
1172*4882a593Smuzhiyun 			ret =
1173*4882a593Smuzhiyun 			    simple_read_from_buffer(user_buf, count, ppos, buf,
1174*4882a593Smuzhiyun 						    pos);
1175*4882a593Smuzhiyun 			kfree(buf);
1176*4882a593Smuzhiyun 		}
1177*4882a593Smuzhiyun 	}
1178*4882a593Smuzhiyun 
1179*4882a593Smuzhiyun 	return ret;
1180*4882a593Smuzhiyun }
1181*4882a593Smuzhiyun 
1182*4882a593Smuzhiyun static ssize_t
il_dbgfs_missed_beacon_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)1183*4882a593Smuzhiyun il_dbgfs_missed_beacon_read(struct file *file, char __user *user_buf,
1184*4882a593Smuzhiyun 			    size_t count, loff_t *ppos)
1185*4882a593Smuzhiyun {
1186*4882a593Smuzhiyun 
1187*4882a593Smuzhiyun 	struct il_priv *il = file->private_data;
1188*4882a593Smuzhiyun 	int pos = 0;
1189*4882a593Smuzhiyun 	char buf[12];
1190*4882a593Smuzhiyun 	const size_t bufsz = sizeof(buf);
1191*4882a593Smuzhiyun 
1192*4882a593Smuzhiyun 	pos +=
1193*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "%d\n",
1194*4882a593Smuzhiyun 		      il->missed_beacon_threshold);
1195*4882a593Smuzhiyun 
1196*4882a593Smuzhiyun 	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1197*4882a593Smuzhiyun }
1198*4882a593Smuzhiyun 
1199*4882a593Smuzhiyun static ssize_t
il_dbgfs_missed_beacon_write(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)1200*4882a593Smuzhiyun il_dbgfs_missed_beacon_write(struct file *file, const char __user *user_buf,
1201*4882a593Smuzhiyun 			     size_t count, loff_t *ppos)
1202*4882a593Smuzhiyun {
1203*4882a593Smuzhiyun 	struct il_priv *il = file->private_data;
1204*4882a593Smuzhiyun 	char buf[8];
1205*4882a593Smuzhiyun 	int buf_size;
1206*4882a593Smuzhiyun 	int missed;
1207*4882a593Smuzhiyun 
1208*4882a593Smuzhiyun 	memset(buf, 0, sizeof(buf));
1209*4882a593Smuzhiyun 	buf_size = min(count, sizeof(buf) - 1);
1210*4882a593Smuzhiyun 	if (copy_from_user(buf, user_buf, buf_size))
1211*4882a593Smuzhiyun 		return -EFAULT;
1212*4882a593Smuzhiyun 	if (sscanf(buf, "%d", &missed) != 1)
1213*4882a593Smuzhiyun 		return -EINVAL;
1214*4882a593Smuzhiyun 
1215*4882a593Smuzhiyun 	if (missed < IL_MISSED_BEACON_THRESHOLD_MIN ||
1216*4882a593Smuzhiyun 	    missed > IL_MISSED_BEACON_THRESHOLD_MAX)
1217*4882a593Smuzhiyun 		il->missed_beacon_threshold = IL_MISSED_BEACON_THRESHOLD_DEF;
1218*4882a593Smuzhiyun 	else
1219*4882a593Smuzhiyun 		il->missed_beacon_threshold = missed;
1220*4882a593Smuzhiyun 
1221*4882a593Smuzhiyun 	return count;
1222*4882a593Smuzhiyun }
1223*4882a593Smuzhiyun 
1224*4882a593Smuzhiyun static ssize_t
il_dbgfs_force_reset_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)1225*4882a593Smuzhiyun il_dbgfs_force_reset_read(struct file *file, char __user *user_buf,
1226*4882a593Smuzhiyun 			  size_t count, loff_t *ppos)
1227*4882a593Smuzhiyun {
1228*4882a593Smuzhiyun 
1229*4882a593Smuzhiyun 	struct il_priv *il = file->private_data;
1230*4882a593Smuzhiyun 	int pos = 0;
1231*4882a593Smuzhiyun 	char buf[300];
1232*4882a593Smuzhiyun 	const size_t bufsz = sizeof(buf);
1233*4882a593Smuzhiyun 	struct il_force_reset *force_reset;
1234*4882a593Smuzhiyun 
1235*4882a593Smuzhiyun 	force_reset = &il->force_reset;
1236*4882a593Smuzhiyun 
1237*4882a593Smuzhiyun 	pos +=
1238*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "\tnumber of reset request: %d\n",
1239*4882a593Smuzhiyun 		      force_reset->reset_request_count);
1240*4882a593Smuzhiyun 	pos +=
1241*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos,
1242*4882a593Smuzhiyun 		      "\tnumber of reset request success: %d\n",
1243*4882a593Smuzhiyun 		      force_reset->reset_success_count);
1244*4882a593Smuzhiyun 	pos +=
1245*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos,
1246*4882a593Smuzhiyun 		      "\tnumber of reset request reject: %d\n",
1247*4882a593Smuzhiyun 		      force_reset->reset_reject_count);
1248*4882a593Smuzhiyun 	pos +=
1249*4882a593Smuzhiyun 	    scnprintf(buf + pos, bufsz - pos, "\treset duration: %lu\n",
1250*4882a593Smuzhiyun 		      force_reset->reset_duration);
1251*4882a593Smuzhiyun 
1252*4882a593Smuzhiyun 	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1253*4882a593Smuzhiyun }
1254*4882a593Smuzhiyun 
1255*4882a593Smuzhiyun static ssize_t
il_dbgfs_force_reset_write(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)1256*4882a593Smuzhiyun il_dbgfs_force_reset_write(struct file *file, const char __user *user_buf,
1257*4882a593Smuzhiyun 			   size_t count, loff_t *ppos)
1258*4882a593Smuzhiyun {
1259*4882a593Smuzhiyun 
1260*4882a593Smuzhiyun 	int ret;
1261*4882a593Smuzhiyun 	struct il_priv *il = file->private_data;
1262*4882a593Smuzhiyun 
1263*4882a593Smuzhiyun 	ret = il_force_reset(il, true);
1264*4882a593Smuzhiyun 
1265*4882a593Smuzhiyun 	return ret ? ret : count;
1266*4882a593Smuzhiyun }
1267*4882a593Smuzhiyun 
1268*4882a593Smuzhiyun static ssize_t
il_dbgfs_wd_timeout_write(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)1269*4882a593Smuzhiyun il_dbgfs_wd_timeout_write(struct file *file, const char __user *user_buf,
1270*4882a593Smuzhiyun 			  size_t count, loff_t *ppos)
1271*4882a593Smuzhiyun {
1272*4882a593Smuzhiyun 
1273*4882a593Smuzhiyun 	struct il_priv *il = file->private_data;
1274*4882a593Smuzhiyun 	char buf[8];
1275*4882a593Smuzhiyun 	int buf_size;
1276*4882a593Smuzhiyun 	int timeout;
1277*4882a593Smuzhiyun 
1278*4882a593Smuzhiyun 	memset(buf, 0, sizeof(buf));
1279*4882a593Smuzhiyun 	buf_size = min(count, sizeof(buf) - 1);
1280*4882a593Smuzhiyun 	if (copy_from_user(buf, user_buf, buf_size))
1281*4882a593Smuzhiyun 		return -EFAULT;
1282*4882a593Smuzhiyun 	if (sscanf(buf, "%d", &timeout) != 1)
1283*4882a593Smuzhiyun 		return -EINVAL;
1284*4882a593Smuzhiyun 	if (timeout < 0 || timeout > IL_MAX_WD_TIMEOUT)
1285*4882a593Smuzhiyun 		timeout = IL_DEF_WD_TIMEOUT;
1286*4882a593Smuzhiyun 
1287*4882a593Smuzhiyun 	il->cfg->wd_timeout = timeout;
1288*4882a593Smuzhiyun 	il_setup_watchdog(il);
1289*4882a593Smuzhiyun 	return count;
1290*4882a593Smuzhiyun }
1291*4882a593Smuzhiyun 
1292*4882a593Smuzhiyun DEBUGFS_READ_FILE_OPS(rx_stats);
1293*4882a593Smuzhiyun DEBUGFS_READ_FILE_OPS(tx_stats);
1294*4882a593Smuzhiyun DEBUGFS_READ_FILE_OPS(rx_queue);
1295*4882a593Smuzhiyun DEBUGFS_READ_FILE_OPS(tx_queue);
1296*4882a593Smuzhiyun DEBUGFS_READ_FILE_OPS(ucode_rx_stats);
1297*4882a593Smuzhiyun DEBUGFS_READ_FILE_OPS(ucode_tx_stats);
1298*4882a593Smuzhiyun DEBUGFS_READ_FILE_OPS(ucode_general_stats);
1299*4882a593Smuzhiyun DEBUGFS_READ_FILE_OPS(sensitivity);
1300*4882a593Smuzhiyun DEBUGFS_READ_FILE_OPS(chain_noise);
1301*4882a593Smuzhiyun DEBUGFS_READ_FILE_OPS(power_save_status);
1302*4882a593Smuzhiyun DEBUGFS_WRITE_FILE_OPS(clear_ucode_stats);
1303*4882a593Smuzhiyun DEBUGFS_WRITE_FILE_OPS(clear_traffic_stats);
1304*4882a593Smuzhiyun DEBUGFS_READ_FILE_OPS(fh_reg);
1305*4882a593Smuzhiyun DEBUGFS_READ_WRITE_FILE_OPS(missed_beacon);
1306*4882a593Smuzhiyun DEBUGFS_READ_WRITE_FILE_OPS(force_reset);
1307*4882a593Smuzhiyun DEBUGFS_READ_FILE_OPS(rxon_flags);
1308*4882a593Smuzhiyun DEBUGFS_READ_FILE_OPS(rxon_filter_flags);
1309*4882a593Smuzhiyun DEBUGFS_WRITE_FILE_OPS(wd_timeout);
1310*4882a593Smuzhiyun 
1311*4882a593Smuzhiyun /*
1312*4882a593Smuzhiyun  * Create the debugfs files and directories
1313*4882a593Smuzhiyun  *
1314*4882a593Smuzhiyun  */
1315*4882a593Smuzhiyun void
il_dbgfs_register(struct il_priv * il,const char * name)1316*4882a593Smuzhiyun il_dbgfs_register(struct il_priv *il, const char *name)
1317*4882a593Smuzhiyun {
1318*4882a593Smuzhiyun 	struct dentry *phyd = il->hw->wiphy->debugfsdir;
1319*4882a593Smuzhiyun 	struct dentry *dir_drv, *dir_data, *dir_rf, *dir_debug;
1320*4882a593Smuzhiyun 
1321*4882a593Smuzhiyun 	dir_drv = debugfs_create_dir(name, phyd);
1322*4882a593Smuzhiyun 	il->debugfs_dir = dir_drv;
1323*4882a593Smuzhiyun 
1324*4882a593Smuzhiyun 	dir_data = debugfs_create_dir("data", dir_drv);
1325*4882a593Smuzhiyun 	dir_rf = debugfs_create_dir("rf", dir_drv);
1326*4882a593Smuzhiyun 	dir_debug = debugfs_create_dir("debug", dir_drv);
1327*4882a593Smuzhiyun 
1328*4882a593Smuzhiyun 	DEBUGFS_ADD_FILE(nvm, dir_data, 0400);
1329*4882a593Smuzhiyun 	DEBUGFS_ADD_FILE(sram, dir_data, 0600);
1330*4882a593Smuzhiyun 	DEBUGFS_ADD_FILE(stations, dir_data, 0400);
1331*4882a593Smuzhiyun 	DEBUGFS_ADD_FILE(channels, dir_data, 0400);
1332*4882a593Smuzhiyun 	DEBUGFS_ADD_FILE(status, dir_data, 0400);
1333*4882a593Smuzhiyun 	DEBUGFS_ADD_FILE(interrupt, dir_data, 0600);
1334*4882a593Smuzhiyun 	DEBUGFS_ADD_FILE(qos, dir_data, 0400);
1335*4882a593Smuzhiyun 	DEBUGFS_ADD_FILE(disable_ht40, dir_data, 0600);
1336*4882a593Smuzhiyun 	DEBUGFS_ADD_FILE(rx_stats, dir_debug, 0400);
1337*4882a593Smuzhiyun 	DEBUGFS_ADD_FILE(tx_stats, dir_debug, 0400);
1338*4882a593Smuzhiyun 	DEBUGFS_ADD_FILE(rx_queue, dir_debug, 0400);
1339*4882a593Smuzhiyun 	DEBUGFS_ADD_FILE(tx_queue, dir_debug, 0400);
1340*4882a593Smuzhiyun 	DEBUGFS_ADD_FILE(power_save_status, dir_debug, 0400);
1341*4882a593Smuzhiyun 	DEBUGFS_ADD_FILE(clear_ucode_stats, dir_debug, 0200);
1342*4882a593Smuzhiyun 	DEBUGFS_ADD_FILE(clear_traffic_stats, dir_debug, 0200);
1343*4882a593Smuzhiyun 	DEBUGFS_ADD_FILE(fh_reg, dir_debug, 0400);
1344*4882a593Smuzhiyun 	DEBUGFS_ADD_FILE(missed_beacon, dir_debug, 0200);
1345*4882a593Smuzhiyun 	DEBUGFS_ADD_FILE(force_reset, dir_debug, 0600);
1346*4882a593Smuzhiyun 	DEBUGFS_ADD_FILE(ucode_rx_stats, dir_debug, 0400);
1347*4882a593Smuzhiyun 	DEBUGFS_ADD_FILE(ucode_tx_stats, dir_debug, 0400);
1348*4882a593Smuzhiyun 	DEBUGFS_ADD_FILE(ucode_general_stats, dir_debug, 0400);
1349*4882a593Smuzhiyun 
1350*4882a593Smuzhiyun 	if (il->cfg->sensitivity_calib_by_driver)
1351*4882a593Smuzhiyun 		DEBUGFS_ADD_FILE(sensitivity, dir_debug, 0400);
1352*4882a593Smuzhiyun 	if (il->cfg->chain_noise_calib_by_driver)
1353*4882a593Smuzhiyun 		DEBUGFS_ADD_FILE(chain_noise, dir_debug, 0400);
1354*4882a593Smuzhiyun 	DEBUGFS_ADD_FILE(rxon_flags, dir_debug, 0200);
1355*4882a593Smuzhiyun 	DEBUGFS_ADD_FILE(rxon_filter_flags, dir_debug, 0200);
1356*4882a593Smuzhiyun 	DEBUGFS_ADD_FILE(wd_timeout, dir_debug, 0200);
1357*4882a593Smuzhiyun 	if (il->cfg->sensitivity_calib_by_driver)
1358*4882a593Smuzhiyun 		DEBUGFS_ADD_BOOL(disable_sensitivity, dir_rf,
1359*4882a593Smuzhiyun 				 &il->disable_sens_cal);
1360*4882a593Smuzhiyun 	if (il->cfg->chain_noise_calib_by_driver)
1361*4882a593Smuzhiyun 		DEBUGFS_ADD_BOOL(disable_chain_noise, dir_rf,
1362*4882a593Smuzhiyun 				 &il->disable_chain_noise_cal);
1363*4882a593Smuzhiyun 	DEBUGFS_ADD_BOOL(disable_tx_power, dir_rf, &il->disable_tx_power_cal);
1364*4882a593Smuzhiyun }
1365*4882a593Smuzhiyun EXPORT_SYMBOL(il_dbgfs_register);
1366*4882a593Smuzhiyun 
1367*4882a593Smuzhiyun /*
1368*4882a593Smuzhiyun  * Remove the debugfs files and directories
1369*4882a593Smuzhiyun  */
1370*4882a593Smuzhiyun void
il_dbgfs_unregister(struct il_priv * il)1371*4882a593Smuzhiyun il_dbgfs_unregister(struct il_priv *il)
1372*4882a593Smuzhiyun {
1373*4882a593Smuzhiyun 	if (!il->debugfs_dir)
1374*4882a593Smuzhiyun 		return;
1375*4882a593Smuzhiyun 
1376*4882a593Smuzhiyun 	debugfs_remove_recursive(il->debugfs_dir);
1377*4882a593Smuzhiyun 	il->debugfs_dir = NULL;
1378*4882a593Smuzhiyun }
1379*4882a593Smuzhiyun EXPORT_SYMBOL(il_dbgfs_unregister);
1380