iwl-debugfs.c revision 8f7ffbe2b275e5315773322161945a24518e31f4
1/******************************************************************************
2 *
3 * GPL LICENSE SUMMARY
4 *
5 * Copyright(c) 2008 - 2012 Intel Corporation. All rights reserved.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
19 * USA
20 *
21 * The full GNU General Public License is included in this distribution
22 * in the file called LICENSE.GPL.
23 *
24 * Contact Information:
25 *  Intel Linux Wireless <ilw@linux.intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *****************************************************************************/
28
29#include <linux/slab.h>
30#include <linux/kernel.h>
31#include <linux/module.h>
32#include <linux/debugfs.h>
33
34#include <linux/ieee80211.h>
35#include <net/mac80211.h>
36
37
38#include "iwl-dev.h"
39#include "iwl-debug.h"
40#include "iwl-core.h"
41#include "iwl-io.h"
42#include "iwl-agn.h"
43
44/* create and remove of files */
45#define DEBUGFS_ADD_FILE(name, parent, mode) do {			\
46	if (!debugfs_create_file(#name, mode, parent, priv,		\
47				 &iwl_dbgfs_##name##_ops))		\
48		goto err;						\
49} while (0)
50
51#define DEBUGFS_ADD_BOOL(name, parent, ptr) do {			\
52	struct dentry *__tmp;						\
53	__tmp = debugfs_create_bool(#name, S_IWUSR | S_IRUSR,		\
54				    parent, ptr);			\
55	if (IS_ERR(__tmp) || !__tmp)					\
56		goto err;						\
57} while (0)
58
59#define DEBUGFS_ADD_X32(name, parent, ptr) do {				\
60	struct dentry *__tmp;						\
61	__tmp = debugfs_create_x32(#name, S_IWUSR | S_IRUSR,		\
62				   parent, ptr);			\
63	if (IS_ERR(__tmp) || !__tmp)					\
64		goto err;						\
65} while (0)
66
67#define DEBUGFS_ADD_U32(name, parent, ptr, mode) do {			\
68	struct dentry *__tmp;						\
69	__tmp = debugfs_create_u32(#name, mode,				\
70				   parent, ptr);			\
71	if (IS_ERR(__tmp) || !__tmp)					\
72		goto err;						\
73} while (0)
74
75/* file operation */
76#define DEBUGFS_READ_FUNC(name)                                         \
77static ssize_t iwl_dbgfs_##name##_read(struct file *file,               \
78					char __user *user_buf,          \
79					size_t count, loff_t *ppos);
80
81#define DEBUGFS_WRITE_FUNC(name)                                        \
82static ssize_t iwl_dbgfs_##name##_write(struct file *file,              \
83					const char __user *user_buf,    \
84					size_t count, loff_t *ppos);
85
86
87static int iwl_dbgfs_open_file_generic(struct inode *inode, struct file *file)
88{
89	file->private_data = inode->i_private;
90	return 0;
91}
92
93#define DEBUGFS_READ_FILE_OPS(name)                                     \
94	DEBUGFS_READ_FUNC(name);                                        \
95static const struct file_operations iwl_dbgfs_##name##_ops = {          \
96	.read = iwl_dbgfs_##name##_read,                       		\
97	.open = iwl_dbgfs_open_file_generic,                    	\
98	.llseek = generic_file_llseek,					\
99};
100
101#define DEBUGFS_WRITE_FILE_OPS(name)                                    \
102	DEBUGFS_WRITE_FUNC(name);                                       \
103static const struct file_operations iwl_dbgfs_##name##_ops = {          \
104	.write = iwl_dbgfs_##name##_write,                              \
105	.open = iwl_dbgfs_open_file_generic,                    	\
106	.llseek = generic_file_llseek,					\
107};
108
109
110#define DEBUGFS_READ_WRITE_FILE_OPS(name)                               \
111	DEBUGFS_READ_FUNC(name);                                        \
112	DEBUGFS_WRITE_FUNC(name);                                       \
113static const struct file_operations iwl_dbgfs_##name##_ops = {          \
114	.write = iwl_dbgfs_##name##_write,                              \
115	.read = iwl_dbgfs_##name##_read,                                \
116	.open = iwl_dbgfs_open_file_generic,                            \
117	.llseek = generic_file_llseek,					\
118};
119
120static ssize_t iwl_dbgfs_tx_statistics_read(struct file *file,
121						char __user *user_buf,
122						size_t count, loff_t *ppos) {
123
124	struct iwl_priv *priv = file->private_data;
125	char *buf;
126	int pos = 0;
127
128	int cnt;
129	ssize_t ret;
130	const size_t bufsz = 100 +
131		sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
132	buf = kzalloc(bufsz, GFP_KERNEL);
133	if (!buf)
134		return -ENOMEM;
135	pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
136	for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
137		pos += scnprintf(buf + pos, bufsz - pos,
138				 "\t%25s\t\t: %u\n",
139				 get_mgmt_string(cnt),
140				 priv->tx_stats.mgmt[cnt]);
141	}
142	pos += scnprintf(buf + pos, bufsz - pos, "Control\n");
143	for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
144		pos += scnprintf(buf + pos, bufsz - pos,
145				 "\t%25s\t\t: %u\n",
146				 get_ctrl_string(cnt),
147				 priv->tx_stats.ctrl[cnt]);
148	}
149	pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
150	pos += scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
151			 priv->tx_stats.data_cnt);
152	pos += scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
153			 priv->tx_stats.data_bytes);
154	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
155	kfree(buf);
156	return ret;
157}
158
159static ssize_t iwl_dbgfs_clear_traffic_statistics_write(struct file *file,
160					const char __user *user_buf,
161					size_t count, loff_t *ppos)
162{
163	struct iwl_priv *priv = file->private_data;
164	u32 clear_flag;
165	char buf[8];
166	int buf_size;
167
168	memset(buf, 0, sizeof(buf));
169	buf_size = min(count, sizeof(buf) -  1);
170	if (copy_from_user(buf, user_buf, buf_size))
171		return -EFAULT;
172	if (sscanf(buf, "%x", &clear_flag) != 1)
173		return -EFAULT;
174	iwl_clear_traffic_stats(priv);
175
176	return count;
177}
178
179static ssize_t iwl_dbgfs_rx_statistics_read(struct file *file,
180						char __user *user_buf,
181						size_t count, loff_t *ppos) {
182
183	struct iwl_priv *priv = file->private_data;
184	char *buf;
185	int pos = 0;
186	int cnt;
187	ssize_t ret;
188	const size_t bufsz = 100 +
189		sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
190	buf = kzalloc(bufsz, GFP_KERNEL);
191	if (!buf)
192		return -ENOMEM;
193
194	pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
195	for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
196		pos += scnprintf(buf + pos, bufsz - pos,
197				 "\t%25s\t\t: %u\n",
198				 get_mgmt_string(cnt),
199				 priv->rx_stats.mgmt[cnt]);
200	}
201	pos += scnprintf(buf + pos, bufsz - pos, "Control:\n");
202	for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
203		pos += scnprintf(buf + pos, bufsz - pos,
204				 "\t%25s\t\t: %u\n",
205				 get_ctrl_string(cnt),
206				 priv->rx_stats.ctrl[cnt]);
207	}
208	pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
209	pos += scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
210			 priv->rx_stats.data_cnt);
211	pos += scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
212			 priv->rx_stats.data_bytes);
213
214	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
215	kfree(buf);
216	return ret;
217}
218
219static ssize_t iwl_dbgfs_sram_read(struct file *file,
220					char __user *user_buf,
221					size_t count, loff_t *ppos)
222{
223	u32 val = 0;
224	char *buf;
225	ssize_t ret;
226	int i = 0;
227	bool device_format = false;
228	int offset = 0;
229	int len = 0;
230	int pos = 0;
231	int sram;
232	struct iwl_priv *priv = file->private_data;
233	size_t bufsz;
234
235	/* default is to dump the entire data segment */
236	if (!priv->dbgfs_sram_offset && !priv->dbgfs_sram_len) {
237		priv->dbgfs_sram_offset = 0x800000;
238		if (!priv->ucode_loaded) {
239			IWL_ERR(priv, "No uCode has been loadded.\n");
240			return -EINVAL;
241		}
242		if (priv->shrd->ucode_type == IWL_UCODE_INIT) {
243			priv->dbgfs_sram_len = priv->fw->ucode_init.data.len;
244		} else if (priv->shrd->ucode_type == IWL_UCODE_REGULAR) {
245			priv->dbgfs_sram_len = priv->fw->ucode_rt.data.len;
246		} else if (priv->shrd->ucode_type == IWL_UCODE_WOWLAN) {
247			priv->dbgfs_sram_len = priv->fw->ucode_wowlan.data.len;
248		} else {
249			IWL_ERR(priv, "Unsupported type of uCode loaded?"
250					" that shouldn't happen.\n");
251			return -EINVAL;
252		}
253	}
254	len = priv->dbgfs_sram_len;
255
256	if (len == -4) {
257		device_format = true;
258		len = 4;
259	}
260
261	bufsz =  50 + len * 4;
262	buf = kmalloc(bufsz, GFP_KERNEL);
263	if (!buf)
264		return -ENOMEM;
265
266	pos += scnprintf(buf + pos, bufsz - pos, "sram_len: 0x%x\n",
267			 len);
268	pos += scnprintf(buf + pos, bufsz - pos, "sram_offset: 0x%x\n",
269			priv->dbgfs_sram_offset);
270
271	/* adjust sram address since reads are only on even u32 boundaries */
272	offset = priv->dbgfs_sram_offset & 0x3;
273	sram = priv->dbgfs_sram_offset & ~0x3;
274
275	/* read the first u32 from sram */
276	val = iwl_read_targ_mem(trans(priv), sram);
277
278	for (; len; len--) {
279		/* put the address at the start of every line */
280		if (i == 0)
281			pos += scnprintf(buf + pos, bufsz - pos,
282				"%08X: ", sram + offset);
283
284		if (device_format)
285			pos += scnprintf(buf + pos, bufsz - pos,
286				"%02x", (val >> (8 * (3 - offset))) & 0xff);
287		else
288			pos += scnprintf(buf + pos, bufsz - pos,
289				"%02x ", (val >> (8 * offset)) & 0xff);
290
291		/* if all bytes processed, read the next u32 from sram */
292		if (++offset == 4) {
293			sram += 4;
294			offset = 0;
295			val = iwl_read_targ_mem(trans(priv), sram);
296		}
297
298		/* put in extra spaces and split lines for human readability */
299		if (++i == 16) {
300			i = 0;
301			pos += scnprintf(buf + pos, bufsz - pos, "\n");
302		} else if (!(i & 7)) {
303			pos += scnprintf(buf + pos, bufsz - pos, "   ");
304		} else if (!(i & 3)) {
305			pos += scnprintf(buf + pos, bufsz - pos, " ");
306		}
307	}
308	if (i)
309		pos += scnprintf(buf + pos, bufsz - pos, "\n");
310
311	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
312	kfree(buf);
313	return ret;
314}
315
316static ssize_t iwl_dbgfs_sram_write(struct file *file,
317					const char __user *user_buf,
318					size_t count, loff_t *ppos)
319{
320	struct iwl_priv *priv = file->private_data;
321	char buf[64];
322	int buf_size;
323	u32 offset, len;
324
325	memset(buf, 0, sizeof(buf));
326	buf_size = min(count, sizeof(buf) -  1);
327	if (copy_from_user(buf, user_buf, buf_size))
328		return -EFAULT;
329
330	if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
331		priv->dbgfs_sram_offset = offset;
332		priv->dbgfs_sram_len = len;
333	} else if (sscanf(buf, "%x", &offset) == 1) {
334		priv->dbgfs_sram_offset = offset;
335		priv->dbgfs_sram_len = -4;
336	} else {
337		priv->dbgfs_sram_offset = 0;
338		priv->dbgfs_sram_len = 0;
339	}
340
341	return count;
342}
343
344static ssize_t iwl_dbgfs_wowlan_sram_read(struct file *file,
345					  char __user *user_buf,
346					  size_t count, loff_t *ppos)
347{
348	struct iwl_priv *priv = file->private_data;
349
350	if (!priv->wowlan_sram)
351		return -ENODATA;
352
353	return simple_read_from_buffer(user_buf, count, ppos,
354				       priv->wowlan_sram,
355				       priv->fw->ucode_wowlan.data.len);
356}
357static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
358					size_t count, loff_t *ppos)
359{
360	struct iwl_priv *priv = file->private_data;
361	struct iwl_station_entry *station;
362	struct iwl_tid_data *tid_data;
363	char *buf;
364	int i, j, pos = 0;
365	ssize_t ret;
366	/* Add 30 for initial string */
367	const size_t bufsz = 30 + sizeof(char) * 500 * (priv->num_stations);
368
369	buf = kmalloc(bufsz, GFP_KERNEL);
370	if (!buf)
371		return -ENOMEM;
372
373	pos += scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n",
374			priv->num_stations);
375
376	for (i = 0; i < IWLAGN_STATION_COUNT; i++) {
377		station = &priv->stations[i];
378		if (!station->used)
379			continue;
380		pos += scnprintf(buf + pos, bufsz - pos,
381				 "station %d - addr: %pM, flags: %#x\n",
382				 i, station->sta.sta.addr,
383				 station->sta.station_flags_msk);
384		pos += scnprintf(buf + pos, bufsz - pos,
385				"TID\tseq_num\trate_n_flags\n");
386
387		for (j = 0; j < IWL_MAX_TID_COUNT; j++) {
388			tid_data = &priv->tid_data[i][j];
389			pos += scnprintf(buf + pos, bufsz - pos,
390				"%d:\t%#x\t%#x",
391				j, tid_data->seq_number,
392				tid_data->agg.rate_n_flags);
393
394			if (tid_data->agg.wait_for_ba)
395				pos += scnprintf(buf + pos, bufsz - pos,
396						 " - waitforba");
397			pos += scnprintf(buf + pos, bufsz - pos, "\n");
398		}
399
400		pos += scnprintf(buf + pos, bufsz - pos, "\n");
401	}
402
403	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
404	kfree(buf);
405	return ret;
406}
407
408static ssize_t iwl_dbgfs_nvm_read(struct file *file,
409				       char __user *user_buf,
410				       size_t count,
411				       loff_t *ppos)
412{
413	ssize_t ret;
414	struct iwl_priv *priv = file->private_data;
415	int pos = 0, ofs = 0, buf_size = 0;
416	const u8 *ptr;
417	char *buf;
418	u16 eeprom_ver;
419	size_t eeprom_len = cfg(priv)->base_params->eeprom_size;
420	buf_size = 4 * eeprom_len + 256;
421
422	if (eeprom_len % 16) {
423		IWL_ERR(priv, "NVM size is not multiple of 16.\n");
424		return -ENODATA;
425	}
426
427	ptr = priv->shrd->eeprom;
428	if (!ptr) {
429		IWL_ERR(priv, "Invalid EEPROM/OTP memory\n");
430		return -ENOMEM;
431	}
432
433	/* 4 characters for byte 0xYY */
434	buf = kzalloc(buf_size, GFP_KERNEL);
435	if (!buf) {
436		IWL_ERR(priv, "Can not allocate Buffer\n");
437		return -ENOMEM;
438	}
439	eeprom_ver = iwl_eeprom_query16(priv->shrd, EEPROM_VERSION);
440	pos += scnprintf(buf + pos, buf_size - pos, "NVM Type: %s, "
441			"version: 0x%x\n",
442			(trans(priv)->nvm_device_type == NVM_DEVICE_TYPE_OTP)
443			 ? "OTP" : "EEPROM", eeprom_ver);
444	for (ofs = 0 ; ofs < eeprom_len ; ofs += 16) {
445		pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x ", ofs);
446		hex_dump_to_buffer(ptr + ofs, 16 , 16, 2, buf + pos,
447				   buf_size - pos, 0);
448		pos += strlen(buf + pos);
449		if (buf_size - pos > 0)
450			buf[pos++] = '\n';
451	}
452
453	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
454	kfree(buf);
455	return ret;
456}
457
458static ssize_t iwl_dbgfs_channels_read(struct file *file, char __user *user_buf,
459				       size_t count, loff_t *ppos)
460{
461	struct iwl_priv *priv = file->private_data;
462	struct ieee80211_channel *channels = NULL;
463	const struct ieee80211_supported_band *supp_band = NULL;
464	int pos = 0, i, bufsz = PAGE_SIZE;
465	char *buf;
466	ssize_t ret;
467
468	if (!test_bit(STATUS_GEO_CONFIGURED, &priv->status))
469		return -EAGAIN;
470
471	buf = kzalloc(bufsz, GFP_KERNEL);
472	if (!buf) {
473		IWL_ERR(priv, "Can not allocate Buffer\n");
474		return -ENOMEM;
475	}
476
477	supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_2GHZ);
478	if (supp_band) {
479		channels = supp_band->channels;
480
481		pos += scnprintf(buf + pos, bufsz - pos,
482				"Displaying %d channels in 2.4GHz band 802.11bg):\n",
483				supp_band->n_channels);
484
485		for (i = 0; i < supp_band->n_channels; i++)
486			pos += scnprintf(buf + pos, bufsz - pos,
487					"%d: %ddBm: BSS%s%s, %s.\n",
488					channels[i].hw_value,
489					channels[i].max_power,
490					channels[i].flags & IEEE80211_CHAN_RADAR ?
491					" (IEEE 802.11h required)" : "",
492					((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
493					|| (channels[i].flags &
494					IEEE80211_CHAN_RADAR)) ? "" :
495					", IBSS",
496					channels[i].flags &
497					IEEE80211_CHAN_PASSIVE_SCAN ?
498					"passive only" : "active/passive");
499	}
500	supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_5GHZ);
501	if (supp_band) {
502		channels = supp_band->channels;
503
504		pos += scnprintf(buf + pos, bufsz - pos,
505				"Displaying %d channels in 5.2GHz band (802.11a)\n",
506				supp_band->n_channels);
507
508		for (i = 0; i < supp_band->n_channels; i++)
509			pos += scnprintf(buf + pos, bufsz - pos,
510					"%d: %ddBm: BSS%s%s, %s.\n",
511					channels[i].hw_value,
512					channels[i].max_power,
513					channels[i].flags & IEEE80211_CHAN_RADAR ?
514					" (IEEE 802.11h required)" : "",
515					((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
516					|| (channels[i].flags &
517					IEEE80211_CHAN_RADAR)) ? "" :
518					", IBSS",
519					channels[i].flags &
520					IEEE80211_CHAN_PASSIVE_SCAN ?
521					"passive only" : "active/passive");
522	}
523	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
524	kfree(buf);
525	return ret;
526}
527
528static ssize_t iwl_dbgfs_status_read(struct file *file,
529						char __user *user_buf,
530						size_t count, loff_t *ppos) {
531
532	struct iwl_priv *priv = file->private_data;
533	char buf[512];
534	int pos = 0;
535	const size_t bufsz = sizeof(buf);
536
537	pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_ACTIVE:\t %d\n",
538		test_bit(STATUS_HCMD_ACTIVE, &priv->shrd->status));
539	pos += scnprintf(buf + pos, bufsz - pos, "STATUS_RF_KILL_HW:\t %d\n",
540		test_bit(STATUS_RF_KILL_HW, &priv->status));
541	pos += scnprintf(buf + pos, bufsz - pos, "STATUS_CT_KILL:\t\t %d\n",
542		test_bit(STATUS_CT_KILL, &priv->status));
543	pos += scnprintf(buf + pos, bufsz - pos, "STATUS_ALIVE:\t\t %d\n",
544		test_bit(STATUS_ALIVE, &priv->status));
545	pos += scnprintf(buf + pos, bufsz - pos, "STATUS_READY:\t\t %d\n",
546		test_bit(STATUS_READY, &priv->status));
547	pos += scnprintf(buf + pos, bufsz - pos, "STATUS_GEO_CONFIGURED:\t %d\n",
548		test_bit(STATUS_GEO_CONFIGURED, &priv->status));
549	pos += scnprintf(buf + pos, bufsz - pos, "STATUS_EXIT_PENDING:\t %d\n",
550		test_bit(STATUS_EXIT_PENDING, &priv->status));
551	pos += scnprintf(buf + pos, bufsz - pos, "STATUS_STATISTICS:\t %d\n",
552		test_bit(STATUS_STATISTICS, &priv->status));
553	pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCANNING:\t %d\n",
554		test_bit(STATUS_SCANNING, &priv->status));
555	pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_ABORTING:\t %d\n",
556		test_bit(STATUS_SCAN_ABORTING, &priv->status));
557	pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_HW:\t\t %d\n",
558		test_bit(STATUS_SCAN_HW, &priv->status));
559	pos += scnprintf(buf + pos, bufsz - pos, "STATUS_POWER_PMI:\t %d\n",
560		test_bit(STATUS_POWER_PMI, &priv->shrd->status));
561	pos += scnprintf(buf + pos, bufsz - pos, "STATUS_FW_ERROR:\t %d\n",
562		test_bit(STATUS_FW_ERROR, &priv->shrd->status));
563	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
564}
565
566static ssize_t iwl_dbgfs_rx_handlers_read(struct file *file,
567					char __user *user_buf,
568					size_t count, loff_t *ppos) {
569
570	struct iwl_priv *priv = file->private_data;
571
572	int pos = 0;
573	int cnt = 0;
574	char *buf;
575	int bufsz = 24 * 64; /* 24 items * 64 char per item */
576	ssize_t ret;
577
578	buf = kzalloc(bufsz, GFP_KERNEL);
579	if (!buf) {
580		IWL_ERR(priv, "Can not allocate Buffer\n");
581		return -ENOMEM;
582	}
583
584	for (cnt = 0; cnt < REPLY_MAX; cnt++) {
585		if (priv->rx_handlers_stats[cnt] > 0)
586			pos += scnprintf(buf + pos, bufsz - pos,
587				"\tRx handler[%36s]:\t\t %u\n",
588				get_cmd_string(cnt),
589				priv->rx_handlers_stats[cnt]);
590	}
591
592	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
593	kfree(buf);
594	return ret;
595}
596
597static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
598					 const char __user *user_buf,
599					 size_t count, loff_t *ppos)
600{
601	struct iwl_priv *priv = file->private_data;
602
603	char buf[8];
604	int buf_size;
605	u32 reset_flag;
606
607	memset(buf, 0, sizeof(buf));
608	buf_size = min(count, sizeof(buf) -  1);
609	if (copy_from_user(buf, user_buf, buf_size))
610		return -EFAULT;
611	if (sscanf(buf, "%x", &reset_flag) != 1)
612		return -EFAULT;
613	if (reset_flag == 0)
614		memset(&priv->rx_handlers_stats[0], 0,
615			sizeof(priv->rx_handlers_stats));
616
617	return count;
618}
619
620static ssize_t iwl_dbgfs_qos_read(struct file *file, char __user *user_buf,
621				       size_t count, loff_t *ppos)
622{
623	struct iwl_priv *priv = file->private_data;
624	struct iwl_rxon_context *ctx;
625	int pos = 0, i;
626	char buf[256 * NUM_IWL_RXON_CTX];
627	const size_t bufsz = sizeof(buf);
628
629	for_each_context(priv, ctx) {
630		pos += scnprintf(buf + pos, bufsz - pos, "context %d:\n",
631				 ctx->ctxid);
632		for (i = 0; i < AC_NUM; i++) {
633			pos += scnprintf(buf + pos, bufsz - pos,
634				"\tcw_min\tcw_max\taifsn\ttxop\n");
635			pos += scnprintf(buf + pos, bufsz - pos,
636				"AC[%d]\t%u\t%u\t%u\t%u\n", i,
637				ctx->qos_data.def_qos_parm.ac[i].cw_min,
638				ctx->qos_data.def_qos_parm.ac[i].cw_max,
639				ctx->qos_data.def_qos_parm.ac[i].aifsn,
640				ctx->qos_data.def_qos_parm.ac[i].edca_txop);
641		}
642		pos += scnprintf(buf + pos, bufsz - pos, "\n");
643	}
644	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
645}
646
647static ssize_t iwl_dbgfs_thermal_throttling_read(struct file *file,
648				char __user *user_buf,
649				size_t count, loff_t *ppos)
650{
651	struct iwl_priv *priv = file->private_data;
652	struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
653	struct iwl_tt_restriction *restriction;
654	char buf[100];
655	int pos = 0;
656	const size_t bufsz = sizeof(buf);
657
658	pos += scnprintf(buf + pos, bufsz - pos,
659			"Thermal Throttling Mode: %s\n",
660			tt->advanced_tt ? "Advance" : "Legacy");
661	pos += scnprintf(buf + pos, bufsz - pos,
662			"Thermal Throttling State: %d\n",
663			tt->state);
664	if (tt->advanced_tt) {
665		restriction = tt->restriction + tt->state;
666		pos += scnprintf(buf + pos, bufsz - pos,
667				"Tx mode: %d\n",
668				restriction->tx_stream);
669		pos += scnprintf(buf + pos, bufsz - pos,
670				"Rx mode: %d\n",
671				restriction->rx_stream);
672		pos += scnprintf(buf + pos, bufsz - pos,
673				"HT mode: %d\n",
674				restriction->is_ht);
675	}
676	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
677}
678
679static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
680					 const char __user *user_buf,
681					 size_t count, loff_t *ppos)
682{
683	struct iwl_priv *priv = file->private_data;
684	char buf[8];
685	int buf_size;
686	int ht40;
687
688	memset(buf, 0, sizeof(buf));
689	buf_size = min(count, sizeof(buf) -  1);
690	if (copy_from_user(buf, user_buf, buf_size))
691		return -EFAULT;
692	if (sscanf(buf, "%d", &ht40) != 1)
693		return -EFAULT;
694	if (!iwl_is_any_associated(priv))
695		priv->disable_ht40 = ht40 ? true : false;
696	else {
697		IWL_ERR(priv, "Sta associated with AP - "
698			"Change to 40MHz channel support is not allowed\n");
699		return -EINVAL;
700	}
701
702	return count;
703}
704
705static ssize_t iwl_dbgfs_disable_ht40_read(struct file *file,
706					 char __user *user_buf,
707					 size_t count, loff_t *ppos)
708{
709	struct iwl_priv *priv = file->private_data;
710	char buf[100];
711	int pos = 0;
712	const size_t bufsz = sizeof(buf);
713
714	pos += scnprintf(buf + pos, bufsz - pos,
715			"11n 40MHz Mode: %s\n",
716			priv->disable_ht40 ? "Disabled" : "Enabled");
717	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
718}
719
720static ssize_t iwl_dbgfs_temperature_read(struct file *file,
721					 char __user *user_buf,
722					 size_t count, loff_t *ppos)
723{
724	struct iwl_priv *priv = file->private_data;
725	char buf[8];
726	int pos = 0;
727	const size_t bufsz = sizeof(buf);
728
729	pos += scnprintf(buf + pos, bufsz - pos, "%d\n", priv->temperature);
730	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
731}
732
733
734static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
735						    const char __user *user_buf,
736						    size_t count, loff_t *ppos)
737{
738	struct iwl_priv *priv = file->private_data;
739	char buf[8];
740	int buf_size;
741	int value;
742
743	memset(buf, 0, sizeof(buf));
744	buf_size = min(count, sizeof(buf) -  1);
745	if (copy_from_user(buf, user_buf, buf_size))
746		return -EFAULT;
747
748	if (sscanf(buf, "%d", &value) != 1)
749		return -EINVAL;
750
751	/*
752	 * Our users expect 0 to be "CAM", but 0 isn't actually
753	 * valid here. However, let's not confuse them and present
754	 * IWL_POWER_INDEX_1 as "1", not "0".
755	 */
756	if (value == 0)
757		return -EINVAL;
758	else if (value > 0)
759		value -= 1;
760
761	if (value != -1 && (value < 0 || value >= IWL_POWER_NUM))
762		return -EINVAL;
763
764	if (!iwl_is_ready_rf(priv))
765		return -EAGAIN;
766
767	priv->power_data.debug_sleep_level_override = value;
768
769	mutex_lock(&priv->mutex);
770	iwl_power_update_mode(priv, true);
771	mutex_unlock(&priv->mutex);
772
773	return count;
774}
775
776static ssize_t iwl_dbgfs_sleep_level_override_read(struct file *file,
777						   char __user *user_buf,
778						   size_t count, loff_t *ppos)
779{
780	struct iwl_priv *priv = file->private_data;
781	char buf[10];
782	int pos, value;
783	const size_t bufsz = sizeof(buf);
784
785	/* see the write function */
786	value = priv->power_data.debug_sleep_level_override;
787	if (value >= 0)
788		value += 1;
789
790	pos = scnprintf(buf, bufsz, "%d\n", value);
791	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
792}
793
794static ssize_t iwl_dbgfs_current_sleep_command_read(struct file *file,
795						    char __user *user_buf,
796						    size_t count, loff_t *ppos)
797{
798	struct iwl_priv *priv = file->private_data;
799	char buf[200];
800	int pos = 0, i;
801	const size_t bufsz = sizeof(buf);
802	struct iwl_powertable_cmd *cmd = &priv->power_data.sleep_cmd;
803
804	pos += scnprintf(buf + pos, bufsz - pos,
805			 "flags: %#.2x\n", le16_to_cpu(cmd->flags));
806	pos += scnprintf(buf + pos, bufsz - pos,
807			 "RX/TX timeout: %d/%d usec\n",
808			 le32_to_cpu(cmd->rx_data_timeout),
809			 le32_to_cpu(cmd->tx_data_timeout));
810	for (i = 0; i < IWL_POWER_VEC_SIZE; i++)
811		pos += scnprintf(buf + pos, bufsz - pos,
812				 "sleep_interval[%d]: %d\n", i,
813				 le32_to_cpu(cmd->sleep_interval[i]));
814
815	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
816}
817
818DEBUGFS_READ_WRITE_FILE_OPS(sram);
819DEBUGFS_READ_FILE_OPS(wowlan_sram);
820DEBUGFS_READ_FILE_OPS(nvm);
821DEBUGFS_READ_FILE_OPS(stations);
822DEBUGFS_READ_FILE_OPS(channels);
823DEBUGFS_READ_FILE_OPS(status);
824DEBUGFS_READ_WRITE_FILE_OPS(rx_handlers);
825DEBUGFS_READ_FILE_OPS(qos);
826DEBUGFS_READ_FILE_OPS(thermal_throttling);
827DEBUGFS_READ_WRITE_FILE_OPS(disable_ht40);
828DEBUGFS_READ_FILE_OPS(temperature);
829DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
830DEBUGFS_READ_FILE_OPS(current_sleep_command);
831
832static ssize_t iwl_dbgfs_traffic_log_read(struct file *file,
833					 char __user *user_buf,
834					 size_t count, loff_t *ppos)
835{
836	struct iwl_priv *priv = file->private_data;
837	int pos = 0, ofs = 0;
838	int cnt = 0, entry;
839
840	char *buf;
841	int bufsz = ((IWL_TRAFFIC_ENTRIES * IWL_TRAFFIC_ENTRY_SIZE * 64) * 2) +
842		(cfg(priv)->base_params->num_of_queues * 32 * 8) + 400;
843	const u8 *ptr;
844	ssize_t ret;
845
846	buf = kzalloc(bufsz, GFP_KERNEL);
847	if (!buf) {
848		IWL_ERR(priv, "Can not allocate buffer\n");
849		return -ENOMEM;
850	}
851	if (priv->tx_traffic && iwl_have_debug_level(IWL_DL_TX)) {
852		ptr = priv->tx_traffic;
853		pos += scnprintf(buf + pos, bufsz - pos,
854				"Tx Traffic idx: %u\n", priv->tx_traffic_idx);
855		for (cnt = 0, ofs = 0; cnt < IWL_TRAFFIC_ENTRIES; cnt++) {
856			for (entry = 0; entry < IWL_TRAFFIC_ENTRY_SIZE / 16;
857			     entry++,  ofs += 16) {
858				pos += scnprintf(buf + pos, bufsz - pos,
859						"0x%.4x ", ofs);
860				hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
861						   buf + pos, bufsz - pos, 0);
862				pos += strlen(buf + pos);
863				if (bufsz - pos > 0)
864					buf[pos++] = '\n';
865			}
866		}
867	}
868
869	if (priv->rx_traffic && iwl_have_debug_level(IWL_DL_RX)) {
870		ptr = priv->rx_traffic;
871		pos += scnprintf(buf + pos, bufsz - pos,
872				"Rx Traffic idx: %u\n", priv->rx_traffic_idx);
873		for (cnt = 0, ofs = 0; cnt < IWL_TRAFFIC_ENTRIES; cnt++) {
874			for (entry = 0; entry < IWL_TRAFFIC_ENTRY_SIZE / 16;
875			     entry++,  ofs += 16) {
876				pos += scnprintf(buf + pos, bufsz - pos,
877						"0x%.4x ", ofs);
878				hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
879						   buf + pos, bufsz - pos, 0);
880				pos += strlen(buf + pos);
881				if (bufsz - pos > 0)
882					buf[pos++] = '\n';
883			}
884		}
885	}
886
887	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
888	kfree(buf);
889	return ret;
890}
891
892static ssize_t iwl_dbgfs_traffic_log_write(struct file *file,
893					 const char __user *user_buf,
894					 size_t count, loff_t *ppos)
895{
896	struct iwl_priv *priv = file->private_data;
897	char buf[8];
898	int buf_size;
899	int traffic_log;
900
901	memset(buf, 0, sizeof(buf));
902	buf_size = min(count, sizeof(buf) -  1);
903	if (copy_from_user(buf, user_buf, buf_size))
904		return -EFAULT;
905	if (sscanf(buf, "%d", &traffic_log) != 1)
906		return -EFAULT;
907	if (traffic_log == 0)
908		iwl_reset_traffic_log(priv);
909
910	return count;
911}
912
913static const char *fmt_value = "  %-30s %10u\n";
914static const char *fmt_hex   = "  %-30s       0x%02X\n";
915static const char *fmt_table = "  %-30s %10u  %10u  %10u  %10u\n";
916static const char *fmt_header =
917	"%-32s    current  cumulative       delta         max\n";
918
919static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
920{
921	int p = 0;
922	u32 flag;
923
924	lockdep_assert_held(&priv->statistics.lock);
925
926	flag = le32_to_cpu(priv->statistics.flag);
927
928	p += scnprintf(buf + p, bufsz - p, "Statistics Flag(0x%X):\n", flag);
929	if (flag & UCODE_STATISTICS_CLEAR_MSK)
930		p += scnprintf(buf + p, bufsz - p,
931		"\tStatistics have been cleared\n");
932	p += scnprintf(buf + p, bufsz - p, "\tOperational Frequency: %s\n",
933		(flag & UCODE_STATISTICS_FREQUENCY_MSK)
934		? "2.4 GHz" : "5.2 GHz");
935	p += scnprintf(buf + p, bufsz - p, "\tTGj Narrow Band: %s\n",
936		(flag & UCODE_STATISTICS_NARROW_BAND_MSK)
937		 ? "enabled" : "disabled");
938
939	return p;
940}
941
942static ssize_t iwl_dbgfs_ucode_rx_stats_read(struct file *file,
943					char __user *user_buf,
944					size_t count, loff_t *ppos)
945{
946	struct iwl_priv *priv = file->private_data;
947	int pos = 0;
948	char *buf;
949	int bufsz = sizeof(struct statistics_rx_phy) * 40 +
950		    sizeof(struct statistics_rx_non_phy) * 40 +
951		    sizeof(struct statistics_rx_ht_phy) * 40 + 400;
952	ssize_t ret;
953	struct statistics_rx_phy *ofdm, *accum_ofdm, *delta_ofdm, *max_ofdm;
954	struct statistics_rx_phy *cck, *accum_cck, *delta_cck, *max_cck;
955	struct statistics_rx_non_phy *general, *accum_general;
956	struct statistics_rx_non_phy *delta_general, *max_general;
957	struct statistics_rx_ht_phy *ht, *accum_ht, *delta_ht, *max_ht;
958
959	if (!iwl_is_alive(priv))
960		return -EAGAIN;
961
962	buf = kzalloc(bufsz, GFP_KERNEL);
963	if (!buf) {
964		IWL_ERR(priv, "Can not allocate Buffer\n");
965		return -ENOMEM;
966	}
967
968	/*
969	 * the statistic information display here is based on
970	 * the last statistics notification from uCode
971	 * might not reflect the current uCode activity
972	 */
973	spin_lock_bh(&priv->statistics.lock);
974	ofdm = &priv->statistics.rx_ofdm;
975	cck = &priv->statistics.rx_cck;
976	general = &priv->statistics.rx_non_phy;
977	ht = &priv->statistics.rx_ofdm_ht;
978	accum_ofdm = &priv->accum_stats.rx_ofdm;
979	accum_cck = &priv->accum_stats.rx_cck;
980	accum_general = &priv->accum_stats.rx_non_phy;
981	accum_ht = &priv->accum_stats.rx_ofdm_ht;
982	delta_ofdm = &priv->delta_stats.rx_ofdm;
983	delta_cck = &priv->delta_stats.rx_cck;
984	delta_general = &priv->delta_stats.rx_non_phy;
985	delta_ht = &priv->delta_stats.rx_ofdm_ht;
986	max_ofdm = &priv->max_delta_stats.rx_ofdm;
987	max_cck = &priv->max_delta_stats.rx_cck;
988	max_general = &priv->max_delta_stats.rx_non_phy;
989	max_ht = &priv->max_delta_stats.rx_ofdm_ht;
990
991	pos += iwl_statistics_flag(priv, buf, bufsz);
992	pos += scnprintf(buf + pos, bufsz - pos,
993			 fmt_header, "Statistics_Rx - OFDM:");
994	pos += scnprintf(buf + pos, bufsz - pos,
995			 fmt_table, "ina_cnt:",
996			 le32_to_cpu(ofdm->ina_cnt),
997			 accum_ofdm->ina_cnt,
998			 delta_ofdm->ina_cnt, max_ofdm->ina_cnt);
999	pos += scnprintf(buf + pos, bufsz - pos,
1000			 fmt_table, "fina_cnt:",
1001			 le32_to_cpu(ofdm->fina_cnt), accum_ofdm->fina_cnt,
1002			 delta_ofdm->fina_cnt, max_ofdm->fina_cnt);
1003	pos += scnprintf(buf + pos, bufsz - pos,
1004			 fmt_table, "plcp_err:",
1005			 le32_to_cpu(ofdm->plcp_err), accum_ofdm->plcp_err,
1006			 delta_ofdm->plcp_err, max_ofdm->plcp_err);
1007	pos += scnprintf(buf + pos, bufsz - pos,
1008			 fmt_table, "crc32_err:",
1009			 le32_to_cpu(ofdm->crc32_err), accum_ofdm->crc32_err,
1010			 delta_ofdm->crc32_err, max_ofdm->crc32_err);
1011	pos += scnprintf(buf + pos, bufsz - pos,
1012			 fmt_table, "overrun_err:",
1013			 le32_to_cpu(ofdm->overrun_err),
1014			 accum_ofdm->overrun_err, delta_ofdm->overrun_err,
1015			 max_ofdm->overrun_err);
1016	pos += scnprintf(buf + pos, bufsz - pos,
1017			 fmt_table, "early_overrun_err:",
1018			 le32_to_cpu(ofdm->early_overrun_err),
1019			 accum_ofdm->early_overrun_err,
1020			 delta_ofdm->early_overrun_err,
1021			 max_ofdm->early_overrun_err);
1022	pos += scnprintf(buf + pos, bufsz - pos,
1023			 fmt_table, "crc32_good:",
1024			 le32_to_cpu(ofdm->crc32_good),
1025			 accum_ofdm->crc32_good, delta_ofdm->crc32_good,
1026			 max_ofdm->crc32_good);
1027	pos += scnprintf(buf + pos, bufsz - pos,
1028			 fmt_table, "false_alarm_cnt:",
1029			 le32_to_cpu(ofdm->false_alarm_cnt),
1030			 accum_ofdm->false_alarm_cnt,
1031			 delta_ofdm->false_alarm_cnt,
1032			 max_ofdm->false_alarm_cnt);
1033	pos += scnprintf(buf + pos, bufsz - pos,
1034			 fmt_table, "fina_sync_err_cnt:",
1035			 le32_to_cpu(ofdm->fina_sync_err_cnt),
1036			 accum_ofdm->fina_sync_err_cnt,
1037			 delta_ofdm->fina_sync_err_cnt,
1038			 max_ofdm->fina_sync_err_cnt);
1039	pos += scnprintf(buf + pos, bufsz - pos,
1040			 fmt_table, "sfd_timeout:",
1041			 le32_to_cpu(ofdm->sfd_timeout),
1042			 accum_ofdm->sfd_timeout, delta_ofdm->sfd_timeout,
1043			 max_ofdm->sfd_timeout);
1044	pos += scnprintf(buf + pos, bufsz - pos,
1045			 fmt_table, "fina_timeout:",
1046			 le32_to_cpu(ofdm->fina_timeout),
1047			 accum_ofdm->fina_timeout, delta_ofdm->fina_timeout,
1048			 max_ofdm->fina_timeout);
1049	pos += scnprintf(buf + pos, bufsz - pos,
1050			 fmt_table, "unresponded_rts:",
1051			 le32_to_cpu(ofdm->unresponded_rts),
1052			 accum_ofdm->unresponded_rts,
1053			 delta_ofdm->unresponded_rts,
1054			 max_ofdm->unresponded_rts);
1055	pos += scnprintf(buf + pos, bufsz - pos,
1056			 fmt_table, "rxe_frame_lmt_ovrun:",
1057			 le32_to_cpu(ofdm->rxe_frame_limit_overrun),
1058			 accum_ofdm->rxe_frame_limit_overrun,
1059			 delta_ofdm->rxe_frame_limit_overrun,
1060			 max_ofdm->rxe_frame_limit_overrun);
1061	pos += scnprintf(buf + pos, bufsz - pos,
1062			 fmt_table, "sent_ack_cnt:",
1063			 le32_to_cpu(ofdm->sent_ack_cnt),
1064			 accum_ofdm->sent_ack_cnt, delta_ofdm->sent_ack_cnt,
1065			 max_ofdm->sent_ack_cnt);
1066	pos += scnprintf(buf + pos, bufsz - pos,
1067			 fmt_table, "sent_cts_cnt:",
1068			 le32_to_cpu(ofdm->sent_cts_cnt),
1069			 accum_ofdm->sent_cts_cnt, delta_ofdm->sent_cts_cnt,
1070			 max_ofdm->sent_cts_cnt);
1071	pos += scnprintf(buf + pos, bufsz - pos,
1072			 fmt_table, "sent_ba_rsp_cnt:",
1073			 le32_to_cpu(ofdm->sent_ba_rsp_cnt),
1074			 accum_ofdm->sent_ba_rsp_cnt,
1075			 delta_ofdm->sent_ba_rsp_cnt,
1076			 max_ofdm->sent_ba_rsp_cnt);
1077	pos += scnprintf(buf + pos, bufsz - pos,
1078			 fmt_table, "dsp_self_kill:",
1079			 le32_to_cpu(ofdm->dsp_self_kill),
1080			 accum_ofdm->dsp_self_kill,
1081			 delta_ofdm->dsp_self_kill,
1082			 max_ofdm->dsp_self_kill);
1083	pos += scnprintf(buf + pos, bufsz - pos,
1084			 fmt_table, "mh_format_err:",
1085			 le32_to_cpu(ofdm->mh_format_err),
1086			 accum_ofdm->mh_format_err,
1087			 delta_ofdm->mh_format_err,
1088			 max_ofdm->mh_format_err);
1089	pos += scnprintf(buf + pos, bufsz - pos,
1090			 fmt_table, "re_acq_main_rssi_sum:",
1091			 le32_to_cpu(ofdm->re_acq_main_rssi_sum),
1092			 accum_ofdm->re_acq_main_rssi_sum,
1093			 delta_ofdm->re_acq_main_rssi_sum,
1094			 max_ofdm->re_acq_main_rssi_sum);
1095
1096	pos += scnprintf(buf + pos, bufsz - pos,
1097			 fmt_header, "Statistics_Rx - CCK:");
1098	pos += scnprintf(buf + pos, bufsz - pos,
1099			 fmt_table, "ina_cnt:",
1100			 le32_to_cpu(cck->ina_cnt), accum_cck->ina_cnt,
1101			 delta_cck->ina_cnt, max_cck->ina_cnt);
1102	pos += scnprintf(buf + pos, bufsz - pos,
1103			 fmt_table, "fina_cnt:",
1104			 le32_to_cpu(cck->fina_cnt), accum_cck->fina_cnt,
1105			 delta_cck->fina_cnt, max_cck->fina_cnt);
1106	pos += scnprintf(buf + pos, bufsz - pos,
1107			 fmt_table, "plcp_err:",
1108			 le32_to_cpu(cck->plcp_err), accum_cck->plcp_err,
1109			 delta_cck->plcp_err, max_cck->plcp_err);
1110	pos += scnprintf(buf + pos, bufsz - pos,
1111			 fmt_table, "crc32_err:",
1112			 le32_to_cpu(cck->crc32_err), accum_cck->crc32_err,
1113			 delta_cck->crc32_err, max_cck->crc32_err);
1114	pos += scnprintf(buf + pos, bufsz - pos,
1115			 fmt_table, "overrun_err:",
1116			 le32_to_cpu(cck->overrun_err),
1117			 accum_cck->overrun_err, delta_cck->overrun_err,
1118			 max_cck->overrun_err);
1119	pos += scnprintf(buf + pos, bufsz - pos,
1120			 fmt_table, "early_overrun_err:",
1121			 le32_to_cpu(cck->early_overrun_err),
1122			 accum_cck->early_overrun_err,
1123			 delta_cck->early_overrun_err,
1124			 max_cck->early_overrun_err);
1125	pos += scnprintf(buf + pos, bufsz - pos,
1126			 fmt_table, "crc32_good:",
1127			 le32_to_cpu(cck->crc32_good), accum_cck->crc32_good,
1128			 delta_cck->crc32_good, max_cck->crc32_good);
1129	pos += scnprintf(buf + pos, bufsz - pos,
1130			 fmt_table, "false_alarm_cnt:",
1131			 le32_to_cpu(cck->false_alarm_cnt),
1132			 accum_cck->false_alarm_cnt,
1133			 delta_cck->false_alarm_cnt, max_cck->false_alarm_cnt);
1134	pos += scnprintf(buf + pos, bufsz - pos,
1135			 fmt_table, "fina_sync_err_cnt:",
1136			 le32_to_cpu(cck->fina_sync_err_cnt),
1137			 accum_cck->fina_sync_err_cnt,
1138			 delta_cck->fina_sync_err_cnt,
1139			 max_cck->fina_sync_err_cnt);
1140	pos += scnprintf(buf + pos, bufsz - pos,
1141			 fmt_table, "sfd_timeout:",
1142			 le32_to_cpu(cck->sfd_timeout),
1143			 accum_cck->sfd_timeout, delta_cck->sfd_timeout,
1144			 max_cck->sfd_timeout);
1145	pos += scnprintf(buf + pos, bufsz - pos,
1146			 fmt_table, "fina_timeout:",
1147			 le32_to_cpu(cck->fina_timeout),
1148			 accum_cck->fina_timeout, delta_cck->fina_timeout,
1149			 max_cck->fina_timeout);
1150	pos += scnprintf(buf + pos, bufsz - pos,
1151			 fmt_table, "unresponded_rts:",
1152			 le32_to_cpu(cck->unresponded_rts),
1153			 accum_cck->unresponded_rts, delta_cck->unresponded_rts,
1154			 max_cck->unresponded_rts);
1155	pos += scnprintf(buf + pos, bufsz - pos,
1156			 fmt_table, "rxe_frame_lmt_ovrun:",
1157			 le32_to_cpu(cck->rxe_frame_limit_overrun),
1158			 accum_cck->rxe_frame_limit_overrun,
1159			 delta_cck->rxe_frame_limit_overrun,
1160			 max_cck->rxe_frame_limit_overrun);
1161	pos += scnprintf(buf + pos, bufsz - pos,
1162			 fmt_table, "sent_ack_cnt:",
1163			 le32_to_cpu(cck->sent_ack_cnt),
1164			 accum_cck->sent_ack_cnt, delta_cck->sent_ack_cnt,
1165			 max_cck->sent_ack_cnt);
1166	pos += scnprintf(buf + pos, bufsz - pos,
1167			 fmt_table, "sent_cts_cnt:",
1168			 le32_to_cpu(cck->sent_cts_cnt),
1169			 accum_cck->sent_cts_cnt, delta_cck->sent_cts_cnt,
1170			 max_cck->sent_cts_cnt);
1171	pos += scnprintf(buf + pos, bufsz - pos,
1172			 fmt_table, "sent_ba_rsp_cnt:",
1173			 le32_to_cpu(cck->sent_ba_rsp_cnt),
1174			 accum_cck->sent_ba_rsp_cnt,
1175			 delta_cck->sent_ba_rsp_cnt,
1176			 max_cck->sent_ba_rsp_cnt);
1177	pos += scnprintf(buf + pos, bufsz - pos,
1178			 fmt_table, "dsp_self_kill:",
1179			 le32_to_cpu(cck->dsp_self_kill),
1180			 accum_cck->dsp_self_kill, delta_cck->dsp_self_kill,
1181			 max_cck->dsp_self_kill);
1182	pos += scnprintf(buf + pos, bufsz - pos,
1183			 fmt_table, "mh_format_err:",
1184			 le32_to_cpu(cck->mh_format_err),
1185			 accum_cck->mh_format_err, delta_cck->mh_format_err,
1186			 max_cck->mh_format_err);
1187	pos += scnprintf(buf + pos, bufsz - pos,
1188			 fmt_table, "re_acq_main_rssi_sum:",
1189			 le32_to_cpu(cck->re_acq_main_rssi_sum),
1190			 accum_cck->re_acq_main_rssi_sum,
1191			 delta_cck->re_acq_main_rssi_sum,
1192			 max_cck->re_acq_main_rssi_sum);
1193
1194	pos += scnprintf(buf + pos, bufsz - pos,
1195			 fmt_header, "Statistics_Rx - GENERAL:");
1196	pos += scnprintf(buf + pos, bufsz - pos,
1197			 fmt_table, "bogus_cts:",
1198			 le32_to_cpu(general->bogus_cts),
1199			 accum_general->bogus_cts, delta_general->bogus_cts,
1200			 max_general->bogus_cts);
1201	pos += scnprintf(buf + pos, bufsz - pos,
1202			 fmt_table, "bogus_ack:",
1203			 le32_to_cpu(general->bogus_ack),
1204			 accum_general->bogus_ack, delta_general->bogus_ack,
1205			 max_general->bogus_ack);
1206	pos += scnprintf(buf + pos, bufsz - pos,
1207			 fmt_table, "non_bssid_frames:",
1208			 le32_to_cpu(general->non_bssid_frames),
1209			 accum_general->non_bssid_frames,
1210			 delta_general->non_bssid_frames,
1211			 max_general->non_bssid_frames);
1212	pos += scnprintf(buf + pos, bufsz - pos,
1213			 fmt_table, "filtered_frames:",
1214			 le32_to_cpu(general->filtered_frames),
1215			 accum_general->filtered_frames,
1216			 delta_general->filtered_frames,
1217			 max_general->filtered_frames);
1218	pos += scnprintf(buf + pos, bufsz - pos,
1219			 fmt_table, "non_channel_beacons:",
1220			 le32_to_cpu(general->non_channel_beacons),
1221			 accum_general->non_channel_beacons,
1222			 delta_general->non_channel_beacons,
1223			 max_general->non_channel_beacons);
1224	pos += scnprintf(buf + pos, bufsz - pos,
1225			 fmt_table, "channel_beacons:",
1226			 le32_to_cpu(general->channel_beacons),
1227			 accum_general->channel_beacons,
1228			 delta_general->channel_beacons,
1229			 max_general->channel_beacons);
1230	pos += scnprintf(buf + pos, bufsz - pos,
1231			 fmt_table, "num_missed_bcon:",
1232			 le32_to_cpu(general->num_missed_bcon),
1233			 accum_general->num_missed_bcon,
1234			 delta_general->num_missed_bcon,
1235			 max_general->num_missed_bcon);
1236	pos += scnprintf(buf + pos, bufsz - pos,
1237			 fmt_table, "adc_rx_saturation_time:",
1238			 le32_to_cpu(general->adc_rx_saturation_time),
1239			 accum_general->adc_rx_saturation_time,
1240			 delta_general->adc_rx_saturation_time,
1241			 max_general->adc_rx_saturation_time);
1242	pos += scnprintf(buf + pos, bufsz - pos,
1243			 fmt_table, "ina_detect_search_tm:",
1244			 le32_to_cpu(general->ina_detection_search_time),
1245			 accum_general->ina_detection_search_time,
1246			 delta_general->ina_detection_search_time,
1247			 max_general->ina_detection_search_time);
1248	pos += scnprintf(buf + pos, bufsz - pos,
1249			 fmt_table, "beacon_silence_rssi_a:",
1250			 le32_to_cpu(general->beacon_silence_rssi_a),
1251			 accum_general->beacon_silence_rssi_a,
1252			 delta_general->beacon_silence_rssi_a,
1253			 max_general->beacon_silence_rssi_a);
1254	pos += scnprintf(buf + pos, bufsz - pos,
1255			 fmt_table, "beacon_silence_rssi_b:",
1256			 le32_to_cpu(general->beacon_silence_rssi_b),
1257			 accum_general->beacon_silence_rssi_b,
1258			 delta_general->beacon_silence_rssi_b,
1259			 max_general->beacon_silence_rssi_b);
1260	pos += scnprintf(buf + pos, bufsz - pos,
1261			 fmt_table, "beacon_silence_rssi_c:",
1262			 le32_to_cpu(general->beacon_silence_rssi_c),
1263			 accum_general->beacon_silence_rssi_c,
1264			 delta_general->beacon_silence_rssi_c,
1265			 max_general->beacon_silence_rssi_c);
1266	pos += scnprintf(buf + pos, bufsz - pos,
1267			 fmt_table, "interference_data_flag:",
1268			 le32_to_cpu(general->interference_data_flag),
1269			 accum_general->interference_data_flag,
1270			 delta_general->interference_data_flag,
1271			 max_general->interference_data_flag);
1272	pos += scnprintf(buf + pos, bufsz - pos,
1273			 fmt_table, "channel_load:",
1274			 le32_to_cpu(general->channel_load),
1275			 accum_general->channel_load,
1276			 delta_general->channel_load,
1277			 max_general->channel_load);
1278	pos += scnprintf(buf + pos, bufsz - pos,
1279			 fmt_table, "dsp_false_alarms:",
1280			 le32_to_cpu(general->dsp_false_alarms),
1281			 accum_general->dsp_false_alarms,
1282			 delta_general->dsp_false_alarms,
1283			 max_general->dsp_false_alarms);
1284	pos += scnprintf(buf + pos, bufsz - pos,
1285			 fmt_table, "beacon_rssi_a:",
1286			 le32_to_cpu(general->beacon_rssi_a),
1287			 accum_general->beacon_rssi_a,
1288			 delta_general->beacon_rssi_a,
1289			 max_general->beacon_rssi_a);
1290	pos += scnprintf(buf + pos, bufsz - pos,
1291			 fmt_table, "beacon_rssi_b:",
1292			 le32_to_cpu(general->beacon_rssi_b),
1293			 accum_general->beacon_rssi_b,
1294			 delta_general->beacon_rssi_b,
1295			 max_general->beacon_rssi_b);
1296	pos += scnprintf(buf + pos, bufsz - pos,
1297			 fmt_table, "beacon_rssi_c:",
1298			 le32_to_cpu(general->beacon_rssi_c),
1299			 accum_general->beacon_rssi_c,
1300			 delta_general->beacon_rssi_c,
1301			 max_general->beacon_rssi_c);
1302	pos += scnprintf(buf + pos, bufsz - pos,
1303			 fmt_table, "beacon_energy_a:",
1304			 le32_to_cpu(general->beacon_energy_a),
1305			 accum_general->beacon_energy_a,
1306			 delta_general->beacon_energy_a,
1307			 max_general->beacon_energy_a);
1308	pos += scnprintf(buf + pos, bufsz - pos,
1309			 fmt_table, "beacon_energy_b:",
1310			 le32_to_cpu(general->beacon_energy_b),
1311			 accum_general->beacon_energy_b,
1312			 delta_general->beacon_energy_b,
1313			 max_general->beacon_energy_b);
1314	pos += scnprintf(buf + pos, bufsz - pos,
1315			 fmt_table, "beacon_energy_c:",
1316			 le32_to_cpu(general->beacon_energy_c),
1317			 accum_general->beacon_energy_c,
1318			 delta_general->beacon_energy_c,
1319			 max_general->beacon_energy_c);
1320
1321	pos += scnprintf(buf + pos, bufsz - pos,
1322			 fmt_header, "Statistics_Rx - OFDM_HT:");
1323	pos += scnprintf(buf + pos, bufsz - pos,
1324			 fmt_table, "plcp_err:",
1325			 le32_to_cpu(ht->plcp_err), accum_ht->plcp_err,
1326			 delta_ht->plcp_err, max_ht->plcp_err);
1327	pos += scnprintf(buf + pos, bufsz - pos,
1328			 fmt_table, "overrun_err:",
1329			 le32_to_cpu(ht->overrun_err), accum_ht->overrun_err,
1330			 delta_ht->overrun_err, max_ht->overrun_err);
1331	pos += scnprintf(buf + pos, bufsz - pos,
1332			 fmt_table, "early_overrun_err:",
1333			 le32_to_cpu(ht->early_overrun_err),
1334			 accum_ht->early_overrun_err,
1335			 delta_ht->early_overrun_err,
1336			 max_ht->early_overrun_err);
1337	pos += scnprintf(buf + pos, bufsz - pos,
1338			 fmt_table, "crc32_good:",
1339			 le32_to_cpu(ht->crc32_good), accum_ht->crc32_good,
1340			 delta_ht->crc32_good, max_ht->crc32_good);
1341	pos += scnprintf(buf + pos, bufsz - pos,
1342			 fmt_table, "crc32_err:",
1343			 le32_to_cpu(ht->crc32_err), accum_ht->crc32_err,
1344			 delta_ht->crc32_err, max_ht->crc32_err);
1345	pos += scnprintf(buf + pos, bufsz - pos,
1346			 fmt_table, "mh_format_err:",
1347			 le32_to_cpu(ht->mh_format_err),
1348			 accum_ht->mh_format_err,
1349			 delta_ht->mh_format_err, max_ht->mh_format_err);
1350	pos += scnprintf(buf + pos, bufsz - pos,
1351			 fmt_table, "agg_crc32_good:",
1352			 le32_to_cpu(ht->agg_crc32_good),
1353			 accum_ht->agg_crc32_good,
1354			 delta_ht->agg_crc32_good, max_ht->agg_crc32_good);
1355	pos += scnprintf(buf + pos, bufsz - pos,
1356			 fmt_table, "agg_mpdu_cnt:",
1357			 le32_to_cpu(ht->agg_mpdu_cnt),
1358			 accum_ht->agg_mpdu_cnt,
1359			 delta_ht->agg_mpdu_cnt, max_ht->agg_mpdu_cnt);
1360	pos += scnprintf(buf + pos, bufsz - pos,
1361			 fmt_table, "agg_cnt:",
1362			 le32_to_cpu(ht->agg_cnt), accum_ht->agg_cnt,
1363			 delta_ht->agg_cnt, max_ht->agg_cnt);
1364	pos += scnprintf(buf + pos, bufsz - pos,
1365			 fmt_table, "unsupport_mcs:",
1366			 le32_to_cpu(ht->unsupport_mcs),
1367			 accum_ht->unsupport_mcs,
1368			 delta_ht->unsupport_mcs, max_ht->unsupport_mcs);
1369
1370	spin_unlock_bh(&priv->statistics.lock);
1371
1372	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1373	kfree(buf);
1374	return ret;
1375}
1376
1377static ssize_t iwl_dbgfs_ucode_tx_stats_read(struct file *file,
1378					char __user *user_buf,
1379					size_t count, loff_t *ppos)
1380{
1381	struct iwl_priv *priv = file->private_data;
1382	int pos = 0;
1383	char *buf;
1384	int bufsz = (sizeof(struct statistics_tx) * 48) + 250;
1385	ssize_t ret;
1386	struct statistics_tx *tx, *accum_tx, *delta_tx, *max_tx;
1387
1388	if (!iwl_is_alive(priv))
1389		return -EAGAIN;
1390
1391	buf = kzalloc(bufsz, GFP_KERNEL);
1392	if (!buf) {
1393		IWL_ERR(priv, "Can not allocate Buffer\n");
1394		return -ENOMEM;
1395	}
1396
1397	/* the statistic information display here is based on
1398	 * the last statistics notification from uCode
1399	 * might not reflect the current uCode activity
1400	 */
1401	spin_lock_bh(&priv->statistics.lock);
1402
1403	tx = &priv->statistics.tx;
1404	accum_tx = &priv->accum_stats.tx;
1405	delta_tx = &priv->delta_stats.tx;
1406	max_tx = &priv->max_delta_stats.tx;
1407
1408	pos += iwl_statistics_flag(priv, buf, bufsz);
1409	pos += scnprintf(buf + pos, bufsz - pos,
1410			 fmt_header, "Statistics_Tx:");
1411	pos += scnprintf(buf + pos, bufsz - pos,
1412			 fmt_table, "preamble:",
1413			 le32_to_cpu(tx->preamble_cnt),
1414			 accum_tx->preamble_cnt,
1415			 delta_tx->preamble_cnt, max_tx->preamble_cnt);
1416	pos += scnprintf(buf + pos, bufsz - pos,
1417			 fmt_table, "rx_detected_cnt:",
1418			 le32_to_cpu(tx->rx_detected_cnt),
1419			 accum_tx->rx_detected_cnt,
1420			 delta_tx->rx_detected_cnt, max_tx->rx_detected_cnt);
1421	pos += scnprintf(buf + pos, bufsz - pos,
1422			 fmt_table, "bt_prio_defer_cnt:",
1423			 le32_to_cpu(tx->bt_prio_defer_cnt),
1424			 accum_tx->bt_prio_defer_cnt,
1425			 delta_tx->bt_prio_defer_cnt,
1426			 max_tx->bt_prio_defer_cnt);
1427	pos += scnprintf(buf + pos, bufsz - pos,
1428			 fmt_table, "bt_prio_kill_cnt:",
1429			 le32_to_cpu(tx->bt_prio_kill_cnt),
1430			 accum_tx->bt_prio_kill_cnt,
1431			 delta_tx->bt_prio_kill_cnt,
1432			 max_tx->bt_prio_kill_cnt);
1433	pos += scnprintf(buf + pos, bufsz - pos,
1434			 fmt_table, "few_bytes_cnt:",
1435			 le32_to_cpu(tx->few_bytes_cnt),
1436			 accum_tx->few_bytes_cnt,
1437			 delta_tx->few_bytes_cnt, max_tx->few_bytes_cnt);
1438	pos += scnprintf(buf + pos, bufsz - pos,
1439			 fmt_table, "cts_timeout:",
1440			 le32_to_cpu(tx->cts_timeout), accum_tx->cts_timeout,
1441			 delta_tx->cts_timeout, max_tx->cts_timeout);
1442	pos += scnprintf(buf + pos, bufsz - pos,
1443			 fmt_table, "ack_timeout:",
1444			 le32_to_cpu(tx->ack_timeout),
1445			 accum_tx->ack_timeout,
1446			 delta_tx->ack_timeout, max_tx->ack_timeout);
1447	pos += scnprintf(buf + pos, bufsz - pos,
1448			 fmt_table, "expected_ack_cnt:",
1449			 le32_to_cpu(tx->expected_ack_cnt),
1450			 accum_tx->expected_ack_cnt,
1451			 delta_tx->expected_ack_cnt,
1452			 max_tx->expected_ack_cnt);
1453	pos += scnprintf(buf + pos, bufsz - pos,
1454			 fmt_table, "actual_ack_cnt:",
1455			 le32_to_cpu(tx->actual_ack_cnt),
1456			 accum_tx->actual_ack_cnt,
1457			 delta_tx->actual_ack_cnt,
1458			 max_tx->actual_ack_cnt);
1459	pos += scnprintf(buf + pos, bufsz - pos,
1460			 fmt_table, "dump_msdu_cnt:",
1461			 le32_to_cpu(tx->dump_msdu_cnt),
1462			 accum_tx->dump_msdu_cnt,
1463			 delta_tx->dump_msdu_cnt,
1464			 max_tx->dump_msdu_cnt);
1465	pos += scnprintf(buf + pos, bufsz - pos,
1466			 fmt_table, "abort_nxt_frame_mismatch:",
1467			 le32_to_cpu(tx->burst_abort_next_frame_mismatch_cnt),
1468			 accum_tx->burst_abort_next_frame_mismatch_cnt,
1469			 delta_tx->burst_abort_next_frame_mismatch_cnt,
1470			 max_tx->burst_abort_next_frame_mismatch_cnt);
1471	pos += scnprintf(buf + pos, bufsz - pos,
1472			 fmt_table, "abort_missing_nxt_frame:",
1473			 le32_to_cpu(tx->burst_abort_missing_next_frame_cnt),
1474			 accum_tx->burst_abort_missing_next_frame_cnt,
1475			 delta_tx->burst_abort_missing_next_frame_cnt,
1476			 max_tx->burst_abort_missing_next_frame_cnt);
1477	pos += scnprintf(buf + pos, bufsz - pos,
1478			 fmt_table, "cts_timeout_collision:",
1479			 le32_to_cpu(tx->cts_timeout_collision),
1480			 accum_tx->cts_timeout_collision,
1481			 delta_tx->cts_timeout_collision,
1482			 max_tx->cts_timeout_collision);
1483	pos += scnprintf(buf + pos, bufsz - pos,
1484			 fmt_table, "ack_ba_timeout_collision:",
1485			 le32_to_cpu(tx->ack_or_ba_timeout_collision),
1486			 accum_tx->ack_or_ba_timeout_collision,
1487			 delta_tx->ack_or_ba_timeout_collision,
1488			 max_tx->ack_or_ba_timeout_collision);
1489	pos += scnprintf(buf + pos, bufsz - pos,
1490			 fmt_table, "agg ba_timeout:",
1491			 le32_to_cpu(tx->agg.ba_timeout),
1492			 accum_tx->agg.ba_timeout,
1493			 delta_tx->agg.ba_timeout,
1494			 max_tx->agg.ba_timeout);
1495	pos += scnprintf(buf + pos, bufsz - pos,
1496			 fmt_table, "agg ba_resched_frames:",
1497			 le32_to_cpu(tx->agg.ba_reschedule_frames),
1498			 accum_tx->agg.ba_reschedule_frames,
1499			 delta_tx->agg.ba_reschedule_frames,
1500			 max_tx->agg.ba_reschedule_frames);
1501	pos += scnprintf(buf + pos, bufsz - pos,
1502			 fmt_table, "agg scd_query_agg_frame:",
1503			 le32_to_cpu(tx->agg.scd_query_agg_frame_cnt),
1504			 accum_tx->agg.scd_query_agg_frame_cnt,
1505			 delta_tx->agg.scd_query_agg_frame_cnt,
1506			 max_tx->agg.scd_query_agg_frame_cnt);
1507	pos += scnprintf(buf + pos, bufsz - pos,
1508			 fmt_table, "agg scd_query_no_agg:",
1509			 le32_to_cpu(tx->agg.scd_query_no_agg),
1510			 accum_tx->agg.scd_query_no_agg,
1511			 delta_tx->agg.scd_query_no_agg,
1512			 max_tx->agg.scd_query_no_agg);
1513	pos += scnprintf(buf + pos, bufsz - pos,
1514			 fmt_table, "agg scd_query_agg:",
1515			 le32_to_cpu(tx->agg.scd_query_agg),
1516			 accum_tx->agg.scd_query_agg,
1517			 delta_tx->agg.scd_query_agg,
1518			 max_tx->agg.scd_query_agg);
1519	pos += scnprintf(buf + pos, bufsz - pos,
1520			 fmt_table, "agg scd_query_mismatch:",
1521			 le32_to_cpu(tx->agg.scd_query_mismatch),
1522			 accum_tx->agg.scd_query_mismatch,
1523			 delta_tx->agg.scd_query_mismatch,
1524			 max_tx->agg.scd_query_mismatch);
1525	pos += scnprintf(buf + pos, bufsz - pos,
1526			 fmt_table, "agg frame_not_ready:",
1527			 le32_to_cpu(tx->agg.frame_not_ready),
1528			 accum_tx->agg.frame_not_ready,
1529			 delta_tx->agg.frame_not_ready,
1530			 max_tx->agg.frame_not_ready);
1531	pos += scnprintf(buf + pos, bufsz - pos,
1532			 fmt_table, "agg underrun:",
1533			 le32_to_cpu(tx->agg.underrun),
1534			 accum_tx->agg.underrun,
1535			 delta_tx->agg.underrun, max_tx->agg.underrun);
1536	pos += scnprintf(buf + pos, bufsz - pos,
1537			 fmt_table, "agg bt_prio_kill:",
1538			 le32_to_cpu(tx->agg.bt_prio_kill),
1539			 accum_tx->agg.bt_prio_kill,
1540			 delta_tx->agg.bt_prio_kill,
1541			 max_tx->agg.bt_prio_kill);
1542	pos += scnprintf(buf + pos, bufsz - pos,
1543			 fmt_table, "agg rx_ba_rsp_cnt:",
1544			 le32_to_cpu(tx->agg.rx_ba_rsp_cnt),
1545			 accum_tx->agg.rx_ba_rsp_cnt,
1546			 delta_tx->agg.rx_ba_rsp_cnt,
1547			 max_tx->agg.rx_ba_rsp_cnt);
1548
1549	if (tx->tx_power.ant_a || tx->tx_power.ant_b || tx->tx_power.ant_c) {
1550		pos += scnprintf(buf + pos, bufsz - pos,
1551			"tx power: (1/2 dB step)\n");
1552		if ((hw_params(priv).valid_tx_ant & ANT_A) &&
1553		    tx->tx_power.ant_a)
1554			pos += scnprintf(buf + pos, bufsz - pos,
1555					fmt_hex, "antenna A:",
1556					tx->tx_power.ant_a);
1557		if ((hw_params(priv).valid_tx_ant & ANT_B) &&
1558		    tx->tx_power.ant_b)
1559			pos += scnprintf(buf + pos, bufsz - pos,
1560					fmt_hex, "antenna B:",
1561					tx->tx_power.ant_b);
1562		if ((hw_params(priv).valid_tx_ant & ANT_C) &&
1563		    tx->tx_power.ant_c)
1564			pos += scnprintf(buf + pos, bufsz - pos,
1565					fmt_hex, "antenna C:",
1566					tx->tx_power.ant_c);
1567	}
1568
1569	spin_unlock_bh(&priv->statistics.lock);
1570
1571	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1572	kfree(buf);
1573	return ret;
1574}
1575
1576static ssize_t iwl_dbgfs_ucode_general_stats_read(struct file *file,
1577					char __user *user_buf,
1578					size_t count, loff_t *ppos)
1579{
1580	struct iwl_priv *priv = file->private_data;
1581	int pos = 0;
1582	char *buf;
1583	int bufsz = sizeof(struct statistics_general) * 10 + 300;
1584	ssize_t ret;
1585	struct statistics_general_common *general, *accum_general;
1586	struct statistics_general_common *delta_general, *max_general;
1587	struct statistics_dbg *dbg, *accum_dbg, *delta_dbg, *max_dbg;
1588	struct statistics_div *div, *accum_div, *delta_div, *max_div;
1589
1590	if (!iwl_is_alive(priv))
1591		return -EAGAIN;
1592
1593	buf = kzalloc(bufsz, GFP_KERNEL);
1594	if (!buf) {
1595		IWL_ERR(priv, "Can not allocate Buffer\n");
1596		return -ENOMEM;
1597	}
1598
1599	/* the statistic information display here is based on
1600	 * the last statistics notification from uCode
1601	 * might not reflect the current uCode activity
1602	 */
1603
1604	spin_lock_bh(&priv->statistics.lock);
1605
1606	general = &priv->statistics.common;
1607	dbg = &priv->statistics.common.dbg;
1608	div = &priv->statistics.common.div;
1609	accum_general = &priv->accum_stats.common;
1610	accum_dbg = &priv->accum_stats.common.dbg;
1611	accum_div = &priv->accum_stats.common.div;
1612	delta_general = &priv->delta_stats.common;
1613	max_general = &priv->max_delta_stats.common;
1614	delta_dbg = &priv->delta_stats.common.dbg;
1615	max_dbg = &priv->max_delta_stats.common.dbg;
1616	delta_div = &priv->delta_stats.common.div;
1617	max_div = &priv->max_delta_stats.common.div;
1618
1619	pos += iwl_statistics_flag(priv, buf, bufsz);
1620	pos += scnprintf(buf + pos, bufsz - pos,
1621			 fmt_header, "Statistics_General:");
1622	pos += scnprintf(buf + pos, bufsz - pos,
1623			 fmt_value, "temperature:",
1624			 le32_to_cpu(general->temperature));
1625	pos += scnprintf(buf + pos, bufsz - pos,
1626			 fmt_value, "temperature_m:",
1627			 le32_to_cpu(general->temperature_m));
1628	pos += scnprintf(buf + pos, bufsz - pos,
1629			 fmt_value, "ttl_timestamp:",
1630			 le32_to_cpu(general->ttl_timestamp));
1631	pos += scnprintf(buf + pos, bufsz - pos,
1632			 fmt_table, "burst_check:",
1633			 le32_to_cpu(dbg->burst_check),
1634			 accum_dbg->burst_check,
1635			 delta_dbg->burst_check, max_dbg->burst_check);
1636	pos += scnprintf(buf + pos, bufsz - pos,
1637			 fmt_table, "burst_count:",
1638			 le32_to_cpu(dbg->burst_count),
1639			 accum_dbg->burst_count,
1640			 delta_dbg->burst_count, max_dbg->burst_count);
1641	pos += scnprintf(buf + pos, bufsz - pos,
1642			 fmt_table, "wait_for_silence_timeout_count:",
1643			 le32_to_cpu(dbg->wait_for_silence_timeout_cnt),
1644			 accum_dbg->wait_for_silence_timeout_cnt,
1645			 delta_dbg->wait_for_silence_timeout_cnt,
1646			 max_dbg->wait_for_silence_timeout_cnt);
1647	pos += scnprintf(buf + pos, bufsz - pos,
1648			 fmt_table, "sleep_time:",
1649			 le32_to_cpu(general->sleep_time),
1650			 accum_general->sleep_time,
1651			 delta_general->sleep_time, max_general->sleep_time);
1652	pos += scnprintf(buf + pos, bufsz - pos,
1653			 fmt_table, "slots_out:",
1654			 le32_to_cpu(general->slots_out),
1655			 accum_general->slots_out,
1656			 delta_general->slots_out, max_general->slots_out);
1657	pos += scnprintf(buf + pos, bufsz - pos,
1658			 fmt_table, "slots_idle:",
1659			 le32_to_cpu(general->slots_idle),
1660			 accum_general->slots_idle,
1661			 delta_general->slots_idle, max_general->slots_idle);
1662	pos += scnprintf(buf + pos, bufsz - pos,
1663			 fmt_table, "tx_on_a:",
1664			 le32_to_cpu(div->tx_on_a), accum_div->tx_on_a,
1665			 delta_div->tx_on_a, max_div->tx_on_a);
1666	pos += scnprintf(buf + pos, bufsz - pos,
1667			 fmt_table, "tx_on_b:",
1668			 le32_to_cpu(div->tx_on_b), accum_div->tx_on_b,
1669			 delta_div->tx_on_b, max_div->tx_on_b);
1670	pos += scnprintf(buf + pos, bufsz - pos,
1671			 fmt_table, "exec_time:",
1672			 le32_to_cpu(div->exec_time), accum_div->exec_time,
1673			 delta_div->exec_time, max_div->exec_time);
1674	pos += scnprintf(buf + pos, bufsz - pos,
1675			 fmt_table, "probe_time:",
1676			 le32_to_cpu(div->probe_time), accum_div->probe_time,
1677			 delta_div->probe_time, max_div->probe_time);
1678	pos += scnprintf(buf + pos, bufsz - pos,
1679			 fmt_table, "rx_enable_counter:",
1680			 le32_to_cpu(general->rx_enable_counter),
1681			 accum_general->rx_enable_counter,
1682			 delta_general->rx_enable_counter,
1683			 max_general->rx_enable_counter);
1684	pos += scnprintf(buf + pos, bufsz - pos,
1685			 fmt_table, "num_of_sos_states:",
1686			 le32_to_cpu(general->num_of_sos_states),
1687			 accum_general->num_of_sos_states,
1688			 delta_general->num_of_sos_states,
1689			 max_general->num_of_sos_states);
1690
1691	spin_unlock_bh(&priv->statistics.lock);
1692
1693	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1694	kfree(buf);
1695	return ret;
1696}
1697
1698static ssize_t iwl_dbgfs_ucode_bt_stats_read(struct file *file,
1699					char __user *user_buf,
1700					size_t count, loff_t *ppos)
1701{
1702	struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1703	int pos = 0;
1704	char *buf;
1705	int bufsz = (sizeof(struct statistics_bt_activity) * 24) + 200;
1706	ssize_t ret;
1707	struct statistics_bt_activity *bt, *accum_bt;
1708
1709	if (!iwl_is_alive(priv))
1710		return -EAGAIN;
1711
1712	if (!priv->bt_enable_flag)
1713		return -EINVAL;
1714
1715	/* make request to uCode to retrieve statistics information */
1716	mutex_lock(&priv->mutex);
1717	ret = iwl_send_statistics_request(priv, CMD_SYNC, false);
1718	mutex_unlock(&priv->mutex);
1719
1720	if (ret) {
1721		IWL_ERR(priv,
1722			"Error sending statistics request: %zd\n", ret);
1723		return -EAGAIN;
1724	}
1725	buf = kzalloc(bufsz, GFP_KERNEL);
1726	if (!buf) {
1727		IWL_ERR(priv, "Can not allocate Buffer\n");
1728		return -ENOMEM;
1729	}
1730
1731	/*
1732	 * the statistic information display here is based on
1733	 * the last statistics notification from uCode
1734	 * might not reflect the current uCode activity
1735	 */
1736
1737	spin_lock_bh(&priv->statistics.lock);
1738
1739	bt = &priv->statistics.bt_activity;
1740	accum_bt = &priv->accum_stats.bt_activity;
1741
1742	pos += iwl_statistics_flag(priv, buf, bufsz);
1743	pos += scnprintf(buf + pos, bufsz - pos, "Statistics_BT:\n");
1744	pos += scnprintf(buf + pos, bufsz - pos,
1745			"\t\t\tcurrent\t\t\taccumulative\n");
1746	pos += scnprintf(buf + pos, bufsz - pos,
1747			 "hi_priority_tx_req_cnt:\t\t%u\t\t\t%u\n",
1748			 le32_to_cpu(bt->hi_priority_tx_req_cnt),
1749			 accum_bt->hi_priority_tx_req_cnt);
1750	pos += scnprintf(buf + pos, bufsz - pos,
1751			 "hi_priority_tx_denied_cnt:\t%u\t\t\t%u\n",
1752			 le32_to_cpu(bt->hi_priority_tx_denied_cnt),
1753			 accum_bt->hi_priority_tx_denied_cnt);
1754	pos += scnprintf(buf + pos, bufsz - pos,
1755			 "lo_priority_tx_req_cnt:\t\t%u\t\t\t%u\n",
1756			 le32_to_cpu(bt->lo_priority_tx_req_cnt),
1757			 accum_bt->lo_priority_tx_req_cnt);
1758	pos += scnprintf(buf + pos, bufsz - pos,
1759			 "lo_priority_tx_denied_cnt:\t%u\t\t\t%u\n",
1760			 le32_to_cpu(bt->lo_priority_tx_denied_cnt),
1761			 accum_bt->lo_priority_tx_denied_cnt);
1762	pos += scnprintf(buf + pos, bufsz - pos,
1763			 "hi_priority_rx_req_cnt:\t\t%u\t\t\t%u\n",
1764			 le32_to_cpu(bt->hi_priority_rx_req_cnt),
1765			 accum_bt->hi_priority_rx_req_cnt);
1766	pos += scnprintf(buf + pos, bufsz - pos,
1767			 "hi_priority_rx_denied_cnt:\t%u\t\t\t%u\n",
1768			 le32_to_cpu(bt->hi_priority_rx_denied_cnt),
1769			 accum_bt->hi_priority_rx_denied_cnt);
1770	pos += scnprintf(buf + pos, bufsz - pos,
1771			 "lo_priority_rx_req_cnt:\t\t%u\t\t\t%u\n",
1772			 le32_to_cpu(bt->lo_priority_rx_req_cnt),
1773			 accum_bt->lo_priority_rx_req_cnt);
1774	pos += scnprintf(buf + pos, bufsz - pos,
1775			 "lo_priority_rx_denied_cnt:\t%u\t\t\t%u\n",
1776			 le32_to_cpu(bt->lo_priority_rx_denied_cnt),
1777			 accum_bt->lo_priority_rx_denied_cnt);
1778
1779	pos += scnprintf(buf + pos, bufsz - pos,
1780			 "(rx)num_bt_kills:\t\t%u\t\t\t%u\n",
1781			 le32_to_cpu(priv->statistics.num_bt_kills),
1782			 priv->statistics.accum_num_bt_kills);
1783
1784	spin_unlock_bh(&priv->statistics.lock);
1785
1786	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1787	kfree(buf);
1788	return ret;
1789}
1790
1791static ssize_t iwl_dbgfs_reply_tx_error_read(struct file *file,
1792					char __user *user_buf,
1793					size_t count, loff_t *ppos)
1794{
1795	struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1796	int pos = 0;
1797	char *buf;
1798	int bufsz = (sizeof(struct reply_tx_error_statistics) * 24) +
1799		(sizeof(struct reply_agg_tx_error_statistics) * 24) + 200;
1800	ssize_t ret;
1801
1802	if (!iwl_is_alive(priv))
1803		return -EAGAIN;
1804
1805	buf = kzalloc(bufsz, GFP_KERNEL);
1806	if (!buf) {
1807		IWL_ERR(priv, "Can not allocate Buffer\n");
1808		return -ENOMEM;
1809	}
1810
1811	pos += scnprintf(buf + pos, bufsz - pos, "Statistics_TX_Error:\n");
1812	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t\t%u\n",
1813			 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_DELAY),
1814			 priv->reply_tx_stats.pp_delay);
1815	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1816			 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_FEW_BYTES),
1817			 priv->reply_tx_stats.pp_few_bytes);
1818	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1819			 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_BT_PRIO),
1820			 priv->reply_tx_stats.pp_bt_prio);
1821	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1822			 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_QUIET_PERIOD),
1823			 priv->reply_tx_stats.pp_quiet_period);
1824	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1825			 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_CALC_TTAK),
1826			 priv->reply_tx_stats.pp_calc_ttak);
1827	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1828			 iwl_get_tx_fail_reason(
1829				TX_STATUS_FAIL_INTERNAL_CROSSED_RETRY),
1830			 priv->reply_tx_stats.int_crossed_retry);
1831	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1832			 iwl_get_tx_fail_reason(TX_STATUS_FAIL_SHORT_LIMIT),
1833			 priv->reply_tx_stats.short_limit);
1834	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1835			 iwl_get_tx_fail_reason(TX_STATUS_FAIL_LONG_LIMIT),
1836			 priv->reply_tx_stats.long_limit);
1837	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1838			 iwl_get_tx_fail_reason(TX_STATUS_FAIL_FIFO_UNDERRUN),
1839			 priv->reply_tx_stats.fifo_underrun);
1840	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1841			 iwl_get_tx_fail_reason(TX_STATUS_FAIL_DRAIN_FLOW),
1842			 priv->reply_tx_stats.drain_flow);
1843	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1844			 iwl_get_tx_fail_reason(TX_STATUS_FAIL_RFKILL_FLUSH),
1845			 priv->reply_tx_stats.rfkill_flush);
1846	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1847			 iwl_get_tx_fail_reason(TX_STATUS_FAIL_LIFE_EXPIRE),
1848			 priv->reply_tx_stats.life_expire);
1849	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1850			 iwl_get_tx_fail_reason(TX_STATUS_FAIL_DEST_PS),
1851			 priv->reply_tx_stats.dest_ps);
1852	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1853			 iwl_get_tx_fail_reason(TX_STATUS_FAIL_HOST_ABORTED),
1854			 priv->reply_tx_stats.host_abort);
1855	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1856			 iwl_get_tx_fail_reason(TX_STATUS_FAIL_BT_RETRY),
1857			 priv->reply_tx_stats.pp_delay);
1858	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1859			 iwl_get_tx_fail_reason(TX_STATUS_FAIL_STA_INVALID),
1860			 priv->reply_tx_stats.sta_invalid);
1861	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1862			 iwl_get_tx_fail_reason(TX_STATUS_FAIL_FRAG_DROPPED),
1863			 priv->reply_tx_stats.frag_drop);
1864	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1865			 iwl_get_tx_fail_reason(TX_STATUS_FAIL_TID_DISABLE),
1866			 priv->reply_tx_stats.tid_disable);
1867	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1868			 iwl_get_tx_fail_reason(TX_STATUS_FAIL_FIFO_FLUSHED),
1869			 priv->reply_tx_stats.fifo_flush);
1870	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1871			 iwl_get_tx_fail_reason(
1872				TX_STATUS_FAIL_INSUFFICIENT_CF_POLL),
1873			 priv->reply_tx_stats.insuff_cf_poll);
1874	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1875			 iwl_get_tx_fail_reason(TX_STATUS_FAIL_PASSIVE_NO_RX),
1876			 priv->reply_tx_stats.fail_hw_drop);
1877	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1878			 iwl_get_tx_fail_reason(
1879				TX_STATUS_FAIL_NO_BEACON_ON_RADAR),
1880			 priv->reply_tx_stats.sta_color_mismatch);
1881	pos += scnprintf(buf + pos, bufsz - pos, "UNKNOWN:\t\t\t%u\n",
1882			 priv->reply_tx_stats.unknown);
1883
1884	pos += scnprintf(buf + pos, bufsz - pos,
1885			 "\nStatistics_Agg_TX_Error:\n");
1886
1887	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1888			 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_UNDERRUN_MSK),
1889			 priv->reply_agg_tx_stats.underrun);
1890	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1891			 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_BT_PRIO_MSK),
1892			 priv->reply_agg_tx_stats.bt_prio);
1893	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1894			 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_FEW_BYTES_MSK),
1895			 priv->reply_agg_tx_stats.few_bytes);
1896	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1897			 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_ABORT_MSK),
1898			 priv->reply_agg_tx_stats.abort);
1899	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1900			 iwl_get_agg_tx_fail_reason(
1901				AGG_TX_STATE_LAST_SENT_TTL_MSK),
1902			 priv->reply_agg_tx_stats.last_sent_ttl);
1903	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1904			 iwl_get_agg_tx_fail_reason(
1905				AGG_TX_STATE_LAST_SENT_TRY_CNT_MSK),
1906			 priv->reply_agg_tx_stats.last_sent_try);
1907	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1908			 iwl_get_agg_tx_fail_reason(
1909				AGG_TX_STATE_LAST_SENT_BT_KILL_MSK),
1910			 priv->reply_agg_tx_stats.last_sent_bt_kill);
1911	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1912			 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_SCD_QUERY_MSK),
1913			 priv->reply_agg_tx_stats.scd_query);
1914	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1915			 iwl_get_agg_tx_fail_reason(
1916				AGG_TX_STATE_TEST_BAD_CRC32_MSK),
1917			 priv->reply_agg_tx_stats.bad_crc32);
1918	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1919			 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_RESPONSE_MSK),
1920			 priv->reply_agg_tx_stats.response);
1921	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1922			 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_DUMP_TX_MSK),
1923			 priv->reply_agg_tx_stats.dump_tx);
1924	pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1925			 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_DELAY_TX_MSK),
1926			 priv->reply_agg_tx_stats.delay_tx);
1927	pos += scnprintf(buf + pos, bufsz - pos, "UNKNOWN:\t\t\t%u\n",
1928			 priv->reply_agg_tx_stats.unknown);
1929
1930	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1931	kfree(buf);
1932	return ret;
1933}
1934
1935static ssize_t iwl_dbgfs_sensitivity_read(struct file *file,
1936					char __user *user_buf,
1937					size_t count, loff_t *ppos) {
1938
1939	struct iwl_priv *priv = file->private_data;
1940	int pos = 0;
1941	int cnt = 0;
1942	char *buf;
1943	int bufsz = sizeof(struct iwl_sensitivity_data) * 4 + 100;
1944	ssize_t ret;
1945	struct iwl_sensitivity_data *data;
1946
1947	data = &priv->sensitivity_data;
1948	buf = kzalloc(bufsz, GFP_KERNEL);
1949	if (!buf) {
1950		IWL_ERR(priv, "Can not allocate Buffer\n");
1951		return -ENOMEM;
1952	}
1953
1954	pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm:\t\t\t %u\n",
1955			data->auto_corr_ofdm);
1956	pos += scnprintf(buf + pos, bufsz - pos,
1957			"auto_corr_ofdm_mrc:\t\t %u\n",
1958			data->auto_corr_ofdm_mrc);
1959	pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_x1:\t\t %u\n",
1960			data->auto_corr_ofdm_x1);
1961	pos += scnprintf(buf + pos, bufsz - pos,
1962			"auto_corr_ofdm_mrc_x1:\t\t %u\n",
1963			data->auto_corr_ofdm_mrc_x1);
1964	pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck:\t\t\t %u\n",
1965			data->auto_corr_cck);
1966	pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck_mrc:\t\t %u\n",
1967			data->auto_corr_cck_mrc);
1968	pos += scnprintf(buf + pos, bufsz - pos,
1969			"last_bad_plcp_cnt_ofdm:\t\t %u\n",
1970			data->last_bad_plcp_cnt_ofdm);
1971	pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_ofdm:\t\t %u\n",
1972			data->last_fa_cnt_ofdm);
1973	pos += scnprintf(buf + pos, bufsz - pos,
1974			"last_bad_plcp_cnt_cck:\t\t %u\n",
1975			data->last_bad_plcp_cnt_cck);
1976	pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_cck:\t\t %u\n",
1977			data->last_fa_cnt_cck);
1978	pos += scnprintf(buf + pos, bufsz - pos, "nrg_curr_state:\t\t\t %u\n",
1979			data->nrg_curr_state);
1980	pos += scnprintf(buf + pos, bufsz - pos, "nrg_prev_state:\t\t\t %u\n",
1981			data->nrg_prev_state);
1982	pos += scnprintf(buf + pos, bufsz - pos, "nrg_value:\t\t\t");
1983	for (cnt = 0; cnt < 10; cnt++) {
1984		pos += scnprintf(buf + pos, bufsz - pos, " %u",
1985				data->nrg_value[cnt]);
1986	}
1987	pos += scnprintf(buf + pos, bufsz - pos, "\n");
1988	pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_rssi:\t\t");
1989	for (cnt = 0; cnt < NRG_NUM_PREV_STAT_L; cnt++) {
1990		pos += scnprintf(buf + pos, bufsz - pos, " %u",
1991				data->nrg_silence_rssi[cnt]);
1992	}
1993	pos += scnprintf(buf + pos, bufsz - pos, "\n");
1994	pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_ref:\t\t %u\n",
1995			data->nrg_silence_ref);
1996	pos += scnprintf(buf + pos, bufsz - pos, "nrg_energy_idx:\t\t\t %u\n",
1997			data->nrg_energy_idx);
1998	pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_idx:\t\t %u\n",
1999			data->nrg_silence_idx);
2000	pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_cck:\t\t\t %u\n",
2001			data->nrg_th_cck);
2002	pos += scnprintf(buf + pos, bufsz - pos,
2003			"nrg_auto_corr_silence_diff:\t %u\n",
2004			data->nrg_auto_corr_silence_diff);
2005	pos += scnprintf(buf + pos, bufsz - pos, "num_in_cck_no_fa:\t\t %u\n",
2006			data->num_in_cck_no_fa);
2007	pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_ofdm:\t\t\t %u\n",
2008			data->nrg_th_ofdm);
2009
2010	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2011	kfree(buf);
2012	return ret;
2013}
2014
2015
2016static ssize_t iwl_dbgfs_chain_noise_read(struct file *file,
2017					char __user *user_buf,
2018					size_t count, loff_t *ppos) {
2019
2020	struct iwl_priv *priv = file->private_data;
2021	int pos = 0;
2022	int cnt = 0;
2023	char *buf;
2024	int bufsz = sizeof(struct iwl_chain_noise_data) * 4 + 100;
2025	ssize_t ret;
2026	struct iwl_chain_noise_data *data;
2027
2028	data = &priv->chain_noise_data;
2029	buf = kzalloc(bufsz, GFP_KERNEL);
2030	if (!buf) {
2031		IWL_ERR(priv, "Can not allocate Buffer\n");
2032		return -ENOMEM;
2033	}
2034
2035	pos += scnprintf(buf + pos, bufsz - pos, "active_chains:\t\t\t %u\n",
2036			data->active_chains);
2037	pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_a:\t\t\t %u\n",
2038			data->chain_noise_a);
2039	pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_b:\t\t\t %u\n",
2040			data->chain_noise_b);
2041	pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_c:\t\t\t %u\n",
2042			data->chain_noise_c);
2043	pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_a:\t\t\t %u\n",
2044			data->chain_signal_a);
2045	pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_b:\t\t\t %u\n",
2046			data->chain_signal_b);
2047	pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_c:\t\t\t %u\n",
2048			data->chain_signal_c);
2049	pos += scnprintf(buf + pos, bufsz - pos, "beacon_count:\t\t\t %u\n",
2050			data->beacon_count);
2051
2052	pos += scnprintf(buf + pos, bufsz - pos, "disconn_array:\t\t\t");
2053	for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
2054		pos += scnprintf(buf + pos, bufsz - pos, " %u",
2055				data->disconn_array[cnt]);
2056	}
2057	pos += scnprintf(buf + pos, bufsz - pos, "\n");
2058	pos += scnprintf(buf + pos, bufsz - pos, "delta_gain_code:\t\t");
2059	for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
2060		pos += scnprintf(buf + pos, bufsz - pos, " %u",
2061				data->delta_gain_code[cnt]);
2062	}
2063	pos += scnprintf(buf + pos, bufsz - pos, "\n");
2064	pos += scnprintf(buf + pos, bufsz - pos, "radio_write:\t\t\t %u\n",
2065			data->radio_write);
2066	pos += scnprintf(buf + pos, bufsz - pos, "state:\t\t\t\t %u\n",
2067			data->state);
2068
2069	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2070	kfree(buf);
2071	return ret;
2072}
2073
2074static ssize_t iwl_dbgfs_power_save_status_read(struct file *file,
2075						    char __user *user_buf,
2076						    size_t count, loff_t *ppos)
2077{
2078	struct iwl_priv *priv = file->private_data;
2079	char buf[60];
2080	int pos = 0;
2081	const size_t bufsz = sizeof(buf);
2082	u32 pwrsave_status;
2083
2084	pwrsave_status = iwl_read32(trans(priv), CSR_GP_CNTRL) &
2085			CSR_GP_REG_POWER_SAVE_STATUS_MSK;
2086
2087	pos += scnprintf(buf + pos, bufsz - pos, "Power Save Status: ");
2088	pos += scnprintf(buf + pos, bufsz - pos, "%s\n",
2089		(pwrsave_status == CSR_GP_REG_NO_POWER_SAVE) ? "none" :
2090		(pwrsave_status == CSR_GP_REG_MAC_POWER_SAVE) ? "MAC" :
2091		(pwrsave_status == CSR_GP_REG_PHY_POWER_SAVE) ? "PHY" :
2092		"error");
2093
2094	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2095}
2096
2097static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
2098					 const char __user *user_buf,
2099					 size_t count, loff_t *ppos)
2100{
2101	struct iwl_priv *priv = file->private_data;
2102	char buf[8];
2103	int buf_size;
2104	int clear;
2105
2106	memset(buf, 0, sizeof(buf));
2107	buf_size = min(count, sizeof(buf) -  1);
2108	if (copy_from_user(buf, user_buf, buf_size))
2109		return -EFAULT;
2110	if (sscanf(buf, "%d", &clear) != 1)
2111		return -EFAULT;
2112
2113	/* make request to uCode to retrieve statistics information */
2114	mutex_lock(&priv->mutex);
2115	iwl_send_statistics_request(priv, CMD_SYNC, true);
2116	mutex_unlock(&priv->mutex);
2117
2118	return count;
2119}
2120
2121static ssize_t iwl_dbgfs_ucode_tracing_read(struct file *file,
2122					char __user *user_buf,
2123					size_t count, loff_t *ppos) {
2124
2125	struct iwl_priv *priv = file->private_data;
2126	int pos = 0;
2127	char buf[128];
2128	const size_t bufsz = sizeof(buf);
2129
2130	pos += scnprintf(buf + pos, bufsz - pos, "ucode trace timer is %s\n",
2131			priv->event_log.ucode_trace ? "On" : "Off");
2132	pos += scnprintf(buf + pos, bufsz - pos, "non_wraps_count:\t\t %u\n",
2133			priv->event_log.non_wraps_count);
2134	pos += scnprintf(buf + pos, bufsz - pos, "wraps_once_count:\t\t %u\n",
2135			priv->event_log.wraps_once_count);
2136	pos += scnprintf(buf + pos, bufsz - pos, "wraps_more_count:\t\t %u\n",
2137			priv->event_log.wraps_more_count);
2138
2139	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2140}
2141
2142static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
2143					 const char __user *user_buf,
2144					 size_t count, loff_t *ppos)
2145{
2146	struct iwl_priv *priv = file->private_data;
2147	char buf[8];
2148	int buf_size;
2149	int trace;
2150
2151	memset(buf, 0, sizeof(buf));
2152	buf_size = min(count, sizeof(buf) -  1);
2153	if (copy_from_user(buf, user_buf, buf_size))
2154		return -EFAULT;
2155	if (sscanf(buf, "%d", &trace) != 1)
2156		return -EFAULT;
2157
2158	if (trace) {
2159		priv->event_log.ucode_trace = true;
2160		if (iwl_is_alive(priv)) {
2161			/* start collecting data now */
2162			mod_timer(&priv->ucode_trace, jiffies);
2163		}
2164	} else {
2165		priv->event_log.ucode_trace = false;
2166		del_timer_sync(&priv->ucode_trace);
2167	}
2168
2169	return count;
2170}
2171
2172static ssize_t iwl_dbgfs_rxon_flags_read(struct file *file,
2173					 char __user *user_buf,
2174					 size_t count, loff_t *ppos) {
2175
2176	struct iwl_priv *priv = file->private_data;
2177	int len = 0;
2178	char buf[20];
2179
2180	len = sprintf(buf, "0x%04X\n",
2181		le32_to_cpu(priv->contexts[IWL_RXON_CTX_BSS].active.flags));
2182	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
2183}
2184
2185static ssize_t iwl_dbgfs_rxon_filter_flags_read(struct file *file,
2186						char __user *user_buf,
2187						size_t count, loff_t *ppos) {
2188
2189	struct iwl_priv *priv = file->private_data;
2190	int len = 0;
2191	char buf[20];
2192
2193	len = sprintf(buf, "0x%04X\n",
2194		le32_to_cpu(priv->contexts[IWL_RXON_CTX_BSS].active.filter_flags));
2195	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
2196}
2197
2198static ssize_t iwl_dbgfs_missed_beacon_read(struct file *file,
2199					char __user *user_buf,
2200					size_t count, loff_t *ppos) {
2201
2202	struct iwl_priv *priv = file->private_data;
2203	int pos = 0;
2204	char buf[12];
2205	const size_t bufsz = sizeof(buf);
2206
2207	pos += scnprintf(buf + pos, bufsz - pos, "%d\n",
2208			priv->missed_beacon_threshold);
2209
2210	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2211}
2212
2213static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
2214					 const char __user *user_buf,
2215					 size_t count, loff_t *ppos)
2216{
2217	struct iwl_priv *priv = file->private_data;
2218	char buf[8];
2219	int buf_size;
2220	int missed;
2221
2222	memset(buf, 0, sizeof(buf));
2223	buf_size = min(count, sizeof(buf) -  1);
2224	if (copy_from_user(buf, user_buf, buf_size))
2225		return -EFAULT;
2226	if (sscanf(buf, "%d", &missed) != 1)
2227		return -EINVAL;
2228
2229	if (missed < IWL_MISSED_BEACON_THRESHOLD_MIN ||
2230	    missed > IWL_MISSED_BEACON_THRESHOLD_MAX)
2231		priv->missed_beacon_threshold =
2232			IWL_MISSED_BEACON_THRESHOLD_DEF;
2233	else
2234		priv->missed_beacon_threshold = missed;
2235
2236	return count;
2237}
2238
2239static ssize_t iwl_dbgfs_plcp_delta_read(struct file *file,
2240					char __user *user_buf,
2241					size_t count, loff_t *ppos) {
2242
2243	struct iwl_priv *priv = file->private_data;
2244	int pos = 0;
2245	char buf[12];
2246	const size_t bufsz = sizeof(buf);
2247
2248	pos += scnprintf(buf + pos, bufsz - pos, "%u\n",
2249			priv->plcp_delta_threshold);
2250
2251	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2252}
2253
2254static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
2255					const char __user *user_buf,
2256					size_t count, loff_t *ppos) {
2257
2258	struct iwl_priv *priv = file->private_data;
2259	char buf[8];
2260	int buf_size;
2261	int plcp;
2262
2263	memset(buf, 0, sizeof(buf));
2264	buf_size = min(count, sizeof(buf) -  1);
2265	if (copy_from_user(buf, user_buf, buf_size))
2266		return -EFAULT;
2267	if (sscanf(buf, "%d", &plcp) != 1)
2268		return -EINVAL;
2269	if ((plcp < IWL_MAX_PLCP_ERR_THRESHOLD_MIN) ||
2270		(plcp > IWL_MAX_PLCP_ERR_THRESHOLD_MAX))
2271		priv->plcp_delta_threshold =
2272			IWL_MAX_PLCP_ERR_THRESHOLD_DISABLE;
2273	else
2274		priv->plcp_delta_threshold = plcp;
2275	return count;
2276}
2277
2278static ssize_t iwl_dbgfs_force_reset_read(struct file *file,
2279					char __user *user_buf,
2280					size_t count, loff_t *ppos)
2281{
2282	struct iwl_priv *priv = file->private_data;
2283	int i, pos = 0;
2284	char buf[300];
2285	const size_t bufsz = sizeof(buf);
2286	struct iwl_force_reset *force_reset;
2287
2288	for (i = 0; i < IWL_MAX_FORCE_RESET; i++) {
2289		force_reset = &priv->force_reset[i];
2290		pos += scnprintf(buf + pos, bufsz - pos,
2291				"Force reset method %d\n", i);
2292		pos += scnprintf(buf + pos, bufsz - pos,
2293				"\tnumber of reset request: %d\n",
2294				force_reset->reset_request_count);
2295		pos += scnprintf(buf + pos, bufsz - pos,
2296				"\tnumber of reset request success: %d\n",
2297				force_reset->reset_success_count);
2298		pos += scnprintf(buf + pos, bufsz - pos,
2299				"\tnumber of reset request reject: %d\n",
2300				force_reset->reset_reject_count);
2301		pos += scnprintf(buf + pos, bufsz - pos,
2302				"\treset duration: %lu\n",
2303				force_reset->reset_duration);
2304	}
2305	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2306}
2307
2308static ssize_t iwl_dbgfs_force_reset_write(struct file *file,
2309					const char __user *user_buf,
2310					size_t count, loff_t *ppos) {
2311
2312	struct iwl_priv *priv = file->private_data;
2313	char buf[8];
2314	int buf_size;
2315	int reset, ret;
2316
2317	memset(buf, 0, sizeof(buf));
2318	buf_size = min(count, sizeof(buf) -  1);
2319	if (copy_from_user(buf, user_buf, buf_size))
2320		return -EFAULT;
2321	if (sscanf(buf, "%d", &reset) != 1)
2322		return -EINVAL;
2323	switch (reset) {
2324	case IWL_RF_RESET:
2325	case IWL_FW_RESET:
2326		ret = iwl_force_reset(priv, reset, true);
2327		break;
2328	default:
2329		return -EINVAL;
2330	}
2331	return ret ? ret : count;
2332}
2333
2334static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
2335					const char __user *user_buf,
2336					size_t count, loff_t *ppos) {
2337
2338	struct iwl_priv *priv = file->private_data;
2339	char buf[8];
2340	int buf_size;
2341	int flush;
2342
2343	memset(buf, 0, sizeof(buf));
2344	buf_size = min(count, sizeof(buf) -  1);
2345	if (copy_from_user(buf, user_buf, buf_size))
2346		return -EFAULT;
2347	if (sscanf(buf, "%d", &flush) != 1)
2348		return -EINVAL;
2349
2350	if (iwl_is_rfkill(priv))
2351		return -EFAULT;
2352
2353	iwlagn_dev_txfifo_flush(priv, IWL_DROP_ALL);
2354
2355	return count;
2356}
2357
2358static ssize_t iwl_dbgfs_wd_timeout_write(struct file *file,
2359					const char __user *user_buf,
2360					size_t count, loff_t *ppos)
2361{
2362	struct iwl_priv *priv = file->private_data;
2363	char buf[8];
2364	int buf_size;
2365	int timeout;
2366
2367	memset(buf, 0, sizeof(buf));
2368	buf_size = min(count, sizeof(buf) -  1);
2369	if (copy_from_user(buf, user_buf, buf_size))
2370		return -EFAULT;
2371	if (sscanf(buf, "%d", &timeout) != 1)
2372		return -EINVAL;
2373	if (timeout < 0 || timeout > IWL_MAX_WD_TIMEOUT)
2374		timeout = IWL_DEF_WD_TIMEOUT;
2375
2376	hw_params(priv).wd_timeout = timeout;
2377	iwl_setup_watchdog(priv);
2378	return count;
2379}
2380
2381static ssize_t iwl_dbgfs_bt_traffic_read(struct file *file,
2382					char __user *user_buf,
2383					size_t count, loff_t *ppos) {
2384
2385	struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
2386	int pos = 0;
2387	char buf[200];
2388	const size_t bufsz = sizeof(buf);
2389
2390	if (!priv->bt_enable_flag) {
2391		pos += scnprintf(buf + pos, bufsz - pos, "BT coex disabled\n");
2392		return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2393	}
2394	pos += scnprintf(buf + pos, bufsz - pos, "BT enable flag: 0x%x\n",
2395		priv->bt_enable_flag);
2396	pos += scnprintf(buf + pos, bufsz - pos, "BT in %s mode\n",
2397		priv->bt_full_concurrent ? "full concurrency" : "3-wire");
2398	pos += scnprintf(buf + pos, bufsz - pos, "BT status: %s, "
2399			 "last traffic notif: %d\n",
2400		priv->bt_status ? "On" : "Off", priv->last_bt_traffic_load);
2401	pos += scnprintf(buf + pos, bufsz - pos, "ch_announcement: %d, "
2402			 "kill_ack_mask: %x, kill_cts_mask: %x\n",
2403		priv->bt_ch_announce, priv->kill_ack_mask,
2404		priv->kill_cts_mask);
2405
2406	pos += scnprintf(buf + pos, bufsz - pos, "bluetooth traffic load: ");
2407	switch (priv->bt_traffic_load) {
2408	case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS:
2409		pos += scnprintf(buf + pos, bufsz - pos, "Continuous\n");
2410		break;
2411	case IWL_BT_COEX_TRAFFIC_LOAD_HIGH:
2412		pos += scnprintf(buf + pos, bufsz - pos, "High\n");
2413		break;
2414	case IWL_BT_COEX_TRAFFIC_LOAD_LOW:
2415		pos += scnprintf(buf + pos, bufsz - pos, "Low\n");
2416		break;
2417	case IWL_BT_COEX_TRAFFIC_LOAD_NONE:
2418	default:
2419		pos += scnprintf(buf + pos, bufsz - pos, "None\n");
2420		break;
2421	}
2422
2423	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2424}
2425
2426static ssize_t iwl_dbgfs_protection_mode_read(struct file *file,
2427					char __user *user_buf,
2428					size_t count, loff_t *ppos)
2429{
2430	struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
2431
2432	int pos = 0;
2433	char buf[40];
2434	const size_t bufsz = sizeof(buf);
2435
2436	if (cfg(priv)->ht_params)
2437		pos += scnprintf(buf + pos, bufsz - pos,
2438			 "use %s for aggregation\n",
2439			 (hw_params(priv).use_rts_for_aggregation) ?
2440				"rts/cts" : "cts-to-self");
2441	else
2442		pos += scnprintf(buf + pos, bufsz - pos, "N/A");
2443
2444	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2445}
2446
2447static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
2448					const char __user *user_buf,
2449					size_t count, loff_t *ppos) {
2450
2451	struct iwl_priv *priv = file->private_data;
2452	char buf[8];
2453	int buf_size;
2454	int rts;
2455
2456	if (!cfg(priv)->ht_params)
2457		return -EINVAL;
2458
2459	memset(buf, 0, sizeof(buf));
2460	buf_size = min(count, sizeof(buf) -  1);
2461	if (copy_from_user(buf, user_buf, buf_size))
2462		return -EFAULT;
2463	if (sscanf(buf, "%d", &rts) != 1)
2464		return -EINVAL;
2465	if (rts)
2466		hw_params(priv).use_rts_for_aggregation = true;
2467	else
2468		hw_params(priv).use_rts_for_aggregation = false;
2469	return count;
2470}
2471
2472static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
2473					const char __user *user_buf,
2474					size_t count, loff_t *ppos)
2475{
2476	struct iwl_priv *priv = file->private_data;
2477	char buf[8];
2478	int buf_size;
2479
2480	memset(buf, 0, sizeof(buf));
2481	buf_size = min(count, sizeof(buf) -  1);
2482	if (copy_from_user(buf, user_buf, buf_size))
2483		return -EFAULT;
2484
2485	iwl_cmd_echo_test(priv);
2486	return count;
2487}
2488
2489DEBUGFS_READ_FILE_OPS(rx_statistics);
2490DEBUGFS_READ_FILE_OPS(tx_statistics);
2491DEBUGFS_READ_WRITE_FILE_OPS(traffic_log);
2492DEBUGFS_READ_FILE_OPS(ucode_rx_stats);
2493DEBUGFS_READ_FILE_OPS(ucode_tx_stats);
2494DEBUGFS_READ_FILE_OPS(ucode_general_stats);
2495DEBUGFS_READ_FILE_OPS(sensitivity);
2496DEBUGFS_READ_FILE_OPS(chain_noise);
2497DEBUGFS_READ_FILE_OPS(power_save_status);
2498DEBUGFS_WRITE_FILE_OPS(clear_ucode_statistics);
2499DEBUGFS_WRITE_FILE_OPS(clear_traffic_statistics);
2500DEBUGFS_READ_WRITE_FILE_OPS(ucode_tracing);
2501DEBUGFS_READ_WRITE_FILE_OPS(missed_beacon);
2502DEBUGFS_READ_WRITE_FILE_OPS(plcp_delta);
2503DEBUGFS_READ_WRITE_FILE_OPS(force_reset);
2504DEBUGFS_READ_FILE_OPS(rxon_flags);
2505DEBUGFS_READ_FILE_OPS(rxon_filter_flags);
2506DEBUGFS_WRITE_FILE_OPS(txfifo_flush);
2507DEBUGFS_READ_FILE_OPS(ucode_bt_stats);
2508DEBUGFS_WRITE_FILE_OPS(wd_timeout);
2509DEBUGFS_READ_FILE_OPS(bt_traffic);
2510DEBUGFS_READ_WRITE_FILE_OPS(protection_mode);
2511DEBUGFS_READ_FILE_OPS(reply_tx_error);
2512DEBUGFS_WRITE_FILE_OPS(echo_test);
2513
2514/*
2515 * Create the debugfs files and directories
2516 *
2517 */
2518int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
2519{
2520	struct dentry *phyd = priv->hw->wiphy->debugfsdir;
2521	struct dentry *dir_drv, *dir_data, *dir_rf, *dir_debug;
2522
2523	dir_drv = debugfs_create_dir(name, phyd);
2524	if (!dir_drv)
2525		return -ENOMEM;
2526
2527	priv->debugfs_dir = dir_drv;
2528
2529	dir_data = debugfs_create_dir("data", dir_drv);
2530	if (!dir_data)
2531		goto err;
2532	dir_rf = debugfs_create_dir("rf", dir_drv);
2533	if (!dir_rf)
2534		goto err;
2535	dir_debug = debugfs_create_dir("debug", dir_drv);
2536	if (!dir_debug)
2537		goto err;
2538
2539	DEBUGFS_ADD_FILE(nvm, dir_data, S_IRUSR);
2540	DEBUGFS_ADD_FILE(sram, dir_data, S_IWUSR | S_IRUSR);
2541	DEBUGFS_ADD_FILE(wowlan_sram, dir_data, S_IRUSR);
2542	DEBUGFS_ADD_FILE(stations, dir_data, S_IRUSR);
2543	DEBUGFS_ADD_FILE(channels, dir_data, S_IRUSR);
2544	DEBUGFS_ADD_FILE(status, dir_data, S_IRUSR);
2545	DEBUGFS_ADD_FILE(rx_handlers, dir_data, S_IWUSR | S_IRUSR);
2546	DEBUGFS_ADD_FILE(qos, dir_data, S_IRUSR);
2547	DEBUGFS_ADD_FILE(sleep_level_override, dir_data, S_IWUSR | S_IRUSR);
2548	DEBUGFS_ADD_FILE(current_sleep_command, dir_data, S_IRUSR);
2549	DEBUGFS_ADD_FILE(thermal_throttling, dir_data, S_IRUSR);
2550	DEBUGFS_ADD_FILE(disable_ht40, dir_data, S_IWUSR | S_IRUSR);
2551	DEBUGFS_ADD_FILE(temperature, dir_data, S_IRUSR);
2552
2553	DEBUGFS_ADD_FILE(rx_statistics, dir_debug, S_IRUSR);
2554	DEBUGFS_ADD_FILE(tx_statistics, dir_debug, S_IRUSR);
2555	DEBUGFS_ADD_FILE(traffic_log, dir_debug, S_IWUSR | S_IRUSR);
2556	DEBUGFS_ADD_FILE(power_save_status, dir_debug, S_IRUSR);
2557	DEBUGFS_ADD_FILE(clear_ucode_statistics, dir_debug, S_IWUSR);
2558	DEBUGFS_ADD_FILE(clear_traffic_statistics, dir_debug, S_IWUSR);
2559	DEBUGFS_ADD_FILE(missed_beacon, dir_debug, S_IWUSR);
2560	DEBUGFS_ADD_FILE(plcp_delta, dir_debug, S_IWUSR | S_IRUSR);
2561	DEBUGFS_ADD_FILE(force_reset, dir_debug, S_IWUSR | S_IRUSR);
2562	DEBUGFS_ADD_FILE(ucode_rx_stats, dir_debug, S_IRUSR);
2563	DEBUGFS_ADD_FILE(ucode_tx_stats, dir_debug, S_IRUSR);
2564	DEBUGFS_ADD_FILE(ucode_general_stats, dir_debug, S_IRUSR);
2565	DEBUGFS_ADD_FILE(txfifo_flush, dir_debug, S_IWUSR);
2566	DEBUGFS_ADD_FILE(protection_mode, dir_debug, S_IWUSR | S_IRUSR);
2567	DEBUGFS_ADD_FILE(sensitivity, dir_debug, S_IRUSR);
2568	DEBUGFS_ADD_FILE(chain_noise, dir_debug, S_IRUSR);
2569	DEBUGFS_ADD_FILE(ucode_tracing, dir_debug, S_IWUSR | S_IRUSR);
2570	DEBUGFS_ADD_FILE(ucode_bt_stats, dir_debug, S_IRUSR);
2571	DEBUGFS_ADD_FILE(reply_tx_error, dir_debug, S_IRUSR);
2572	DEBUGFS_ADD_FILE(rxon_flags, dir_debug, S_IWUSR);
2573	DEBUGFS_ADD_FILE(rxon_filter_flags, dir_debug, S_IWUSR);
2574	DEBUGFS_ADD_FILE(wd_timeout, dir_debug, S_IWUSR);
2575	DEBUGFS_ADD_FILE(echo_test, dir_debug, S_IWUSR);
2576	if (iwl_advanced_bt_coexist(priv))
2577		DEBUGFS_ADD_FILE(bt_traffic, dir_debug, S_IRUSR);
2578
2579	DEBUGFS_ADD_BOOL(disable_sensitivity, dir_rf,
2580			 &priv->disable_sens_cal);
2581	DEBUGFS_ADD_BOOL(disable_chain_noise, dir_rf,
2582			 &priv->disable_chain_noise_cal);
2583
2584	if (iwl_trans_dbgfs_register(trans(priv), dir_debug))
2585		goto err;
2586	return 0;
2587
2588err:
2589	IWL_ERR(priv, "Can't create the debugfs directory\n");
2590	iwl_dbgfs_unregister(priv);
2591	return -ENOMEM;
2592}
2593
2594/**
2595 * Remove the debugfs files and directories
2596 *
2597 */
2598void iwl_dbgfs_unregister(struct iwl_priv *priv)
2599{
2600	if (!priv->debugfs_dir)
2601		return;
2602
2603	debugfs_remove_recursive(priv->debugfs_dir);
2604	priv->debugfs_dir = NULL;
2605}
2606