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