1 /******************************************************************************
5 * Copyright(c) 2008 - 2010 Intel Corporation. All rights reserved.
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.
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.
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,
21 * The full GNU General Public License is included in this distribution
22 * in the file called LICENSE.GPL.
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 *****************************************************************************/
29 #include <linux/slab.h>
30 #include <linux/kernel.h>
31 #include <linux/module.h>
32 #include <linux/debugfs.h>
34 #include <linux/ieee80211.h>
35 #include <net/mac80211.h>
39 #include "iwl-debug.h"
42 #include "iwl-calib.h"
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)) \
51 #define DEBUGFS_ADD_BOOL(name, parent, ptr) do { \
52 struct dentry *__tmp; \
53 __tmp = debugfs_create_bool(#name, S_IWUSR | S_IRUSR, \
55 if (IS_ERR(__tmp) || !__tmp) \
59 #define DEBUGFS_ADD_X32(name, parent, ptr) do { \
60 struct dentry *__tmp; \
61 __tmp = debugfs_create_x32(#name, S_IWUSR | S_IRUSR, \
63 if (IS_ERR(__tmp) || !__tmp) \
68 #define DEBUGFS_READ_FUNC(name) \
69 static ssize_t iwl_dbgfs_##name##_read(struct file *file, \
70 char __user *user_buf, \
71 size_t count, loff_t *ppos);
73 #define DEBUGFS_WRITE_FUNC(name) \
74 static ssize_t iwl_dbgfs_##name##_write(struct file *file, \
75 const char __user *user_buf, \
76 size_t count, loff_t *ppos);
79 static int iwl_dbgfs_open_file_generic(struct inode
*inode
, struct file
*file
)
81 file
->private_data
= inode
->i_private
;
85 #define DEBUGFS_READ_FILE_OPS(name) \
86 DEBUGFS_READ_FUNC(name); \
87 static const struct file_operations iwl_dbgfs_##name##_ops = { \
88 .read = iwl_dbgfs_##name##_read, \
89 .open = iwl_dbgfs_open_file_generic, \
92 #define DEBUGFS_WRITE_FILE_OPS(name) \
93 DEBUGFS_WRITE_FUNC(name); \
94 static const struct file_operations iwl_dbgfs_##name##_ops = { \
95 .write = iwl_dbgfs_##name##_write, \
96 .open = iwl_dbgfs_open_file_generic, \
100 #define DEBUGFS_READ_WRITE_FILE_OPS(name) \
101 DEBUGFS_READ_FUNC(name); \
102 DEBUGFS_WRITE_FUNC(name); \
103 static const struct file_operations iwl_dbgfs_##name##_ops = { \
104 .write = iwl_dbgfs_##name##_write, \
105 .read = iwl_dbgfs_##name##_read, \
106 .open = iwl_dbgfs_open_file_generic, \
109 int iwl_dbgfs_statistics_flag(struct iwl_priv
*priv
, char *buf
, int bufsz
)
113 p
+= scnprintf(buf
+ p
, bufsz
- p
, "Statistics Flag(0x%X):\n",
114 le32_to_cpu(priv
->statistics
.flag
));
115 if (le32_to_cpu(priv
->statistics
.flag
) & UCODE_STATISTICS_CLEAR_MSK
)
116 p
+= scnprintf(buf
+ p
, bufsz
- p
,
117 "\tStatistics have been cleared\n");
118 p
+= scnprintf(buf
+ p
, bufsz
- p
, "\tOperational Frequency: %s\n",
119 (le32_to_cpu(priv
->statistics
.flag
) &
120 UCODE_STATISTICS_FREQUENCY_MSK
)
121 ? "2.4 GHz" : "5.2 GHz");
122 p
+= scnprintf(buf
+ p
, bufsz
- p
, "\tTGj Narrow Band: %s\n",
123 (le32_to_cpu(priv
->statistics
.flag
) &
124 UCODE_STATISTICS_NARROW_BAND_MSK
)
125 ? "enabled" : "disabled");
128 EXPORT_SYMBOL(iwl_dbgfs_statistics_flag
);
130 static ssize_t
iwl_dbgfs_tx_statistics_read(struct file
*file
,
131 char __user
*user_buf
,
132 size_t count
, loff_t
*ppos
) {
134 struct iwl_priv
*priv
= file
->private_data
;
140 const size_t bufsz
= 100 +
141 sizeof(char) * 50 * (MANAGEMENT_MAX
+ CONTROL_MAX
);
142 buf
= kzalloc(bufsz
, GFP_KERNEL
);
145 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "Management:\n");
146 for (cnt
= 0; cnt
< MANAGEMENT_MAX
; cnt
++) {
147 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
149 get_mgmt_string(cnt
),
150 priv
->tx_stats
.mgmt
[cnt
]);
152 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "Control\n");
153 for (cnt
= 0; cnt
< CONTROL_MAX
; cnt
++) {
154 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
156 get_ctrl_string(cnt
),
157 priv
->tx_stats
.ctrl
[cnt
]);
159 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "Data:\n");
160 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "\tcnt: %u\n",
161 priv
->tx_stats
.data_cnt
);
162 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "\tbytes: %llu\n",
163 priv
->tx_stats
.data_bytes
);
164 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
169 static ssize_t
iwl_dbgfs_clear_traffic_statistics_write(struct file
*file
,
170 const char __user
*user_buf
,
171 size_t count
, loff_t
*ppos
)
173 struct iwl_priv
*priv
= file
->private_data
;
178 memset(buf
, 0, sizeof(buf
));
179 buf_size
= min(count
, sizeof(buf
) - 1);
180 if (copy_from_user(buf
, user_buf
, buf_size
))
182 if (sscanf(buf
, "%x", &clear_flag
) != 1)
184 iwl_clear_traffic_stats(priv
);
189 static ssize_t
iwl_dbgfs_rx_statistics_read(struct file
*file
,
190 char __user
*user_buf
,
191 size_t count
, loff_t
*ppos
) {
193 struct iwl_priv
*priv
= file
->private_data
;
198 const size_t bufsz
= 100 +
199 sizeof(char) * 50 * (MANAGEMENT_MAX
+ CONTROL_MAX
);
200 buf
= kzalloc(bufsz
, GFP_KERNEL
);
204 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "Management:\n");
205 for (cnt
= 0; cnt
< MANAGEMENT_MAX
; cnt
++) {
206 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
208 get_mgmt_string(cnt
),
209 priv
->rx_stats
.mgmt
[cnt
]);
211 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "Control:\n");
212 for (cnt
= 0; cnt
< CONTROL_MAX
; cnt
++) {
213 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
215 get_ctrl_string(cnt
),
216 priv
->rx_stats
.ctrl
[cnt
]);
218 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "Data:\n");
219 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "\tcnt: %u\n",
220 priv
->rx_stats
.data_cnt
);
221 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "\tbytes: %llu\n",
222 priv
->rx_stats
.data_bytes
);
224 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
229 #define BYTE1_MASK 0x000000ff;
230 #define BYTE2_MASK 0x0000ffff;
231 #define BYTE3_MASK 0x00ffffff;
232 static ssize_t
iwl_dbgfs_sram_read(struct file
*file
,
233 char __user
*user_buf
,
234 size_t count
, loff_t
*ppos
)
241 struct iwl_priv
*priv
= file
->private_data
;
244 /* default is to dump the entire data segment */
245 if (!priv
->dbgfs_sram_offset
&& !priv
->dbgfs_sram_len
) {
246 priv
->dbgfs_sram_offset
= 0x800000;
247 if (priv
->ucode_type
== UCODE_INIT
)
248 priv
->dbgfs_sram_len
= priv
->ucode_init_data
.len
;
250 priv
->dbgfs_sram_len
= priv
->ucode_data
.len
;
252 bufsz
= 30 + priv
->dbgfs_sram_len
* sizeof(char) * 10;
253 buf
= kmalloc(bufsz
, GFP_KERNEL
);
256 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "sram_len: 0x%x\n",
257 priv
->dbgfs_sram_len
);
258 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "sram_offset: 0x%x\n",
259 priv
->dbgfs_sram_offset
);
260 for (i
= priv
->dbgfs_sram_len
; i
> 0; i
-= 4) {
261 val
= iwl_read_targ_mem(priv
, priv
->dbgfs_sram_offset
+ \
262 priv
->dbgfs_sram_len
- i
);
277 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "\n");
278 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "0x%08x ", val
);
280 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "\n");
282 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
287 static ssize_t
iwl_dbgfs_sram_write(struct file
*file
,
288 const char __user
*user_buf
,
289 size_t count
, loff_t
*ppos
)
291 struct iwl_priv
*priv
= file
->private_data
;
296 memset(buf
, 0, sizeof(buf
));
297 buf_size
= min(count
, sizeof(buf
) - 1);
298 if (copy_from_user(buf
, user_buf
, buf_size
))
301 if (sscanf(buf
, "%x,%x", &offset
, &len
) == 2) {
302 priv
->dbgfs_sram_offset
= offset
;
303 priv
->dbgfs_sram_len
= len
;
305 priv
->dbgfs_sram_offset
= 0;
306 priv
->dbgfs_sram_len
= 0;
312 static ssize_t
iwl_dbgfs_stations_read(struct file
*file
, char __user
*user_buf
,
313 size_t count
, loff_t
*ppos
)
315 struct iwl_priv
*priv
= file
->private_data
;
316 struct iwl_station_entry
*station
;
317 int max_sta
= priv
->hw_params
.max_stations
;
321 /* Add 30 for initial string */
322 const size_t bufsz
= 30 + sizeof(char) * 500 * (priv
->num_stations
);
324 buf
= kmalloc(bufsz
, GFP_KERNEL
);
328 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "num of stations: %d\n\n",
331 for (i
= 0; i
< max_sta
; i
++) {
332 station
= &priv
->stations
[i
];
334 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
335 "station %d:\ngeneral data:\n", i
+1);
336 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "id: %u\n",
337 station
->sta
.sta
.sta_id
);
338 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "mode: %u\n",
340 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
342 station
->sta
.station_flags_msk
);
343 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "tid data:\n");
344 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
345 "seq_num\t\ttxq_id");
346 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
347 "\tframe_count\twait_for_ba\t");
348 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
349 "start_idx\tbitmap0\t");
350 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
351 "bitmap1\trate_n_flags");
352 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "\n");
354 for (j
= 0; j
< MAX_TID_COUNT
; j
++) {
355 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
357 station
->tid
[j
].seq_number
);
358 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
359 "\t%u\t\t%u\t\t%u\t\t",
360 station
->tid
[j
].agg
.txq_id
,
361 station
->tid
[j
].agg
.frame_count
,
362 station
->tid
[j
].agg
.wait_for_ba
);
363 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
365 station
->tid
[j
].agg
.start_idx
,
366 (unsigned long long)station
->tid
[j
].agg
.bitmap
,
367 station
->tid
[j
].agg
.rate_n_flags
);
368 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "\n");
370 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "\n");
374 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
379 static ssize_t
iwl_dbgfs_nvm_read(struct file
*file
,
380 char __user
*user_buf
,
385 struct iwl_priv
*priv
= file
->private_data
;
386 int pos
= 0, ofs
= 0, buf_size
= 0;
390 size_t eeprom_len
= priv
->cfg
->eeprom_size
;
391 buf_size
= 4 * eeprom_len
+ 256;
393 if (eeprom_len
% 16) {
394 IWL_ERR(priv
, "NVM size is not multiple of 16.\n");
400 IWL_ERR(priv
, "Invalid EEPROM/OTP memory\n");
404 /* 4 characters for byte 0xYY */
405 buf
= kzalloc(buf_size
, GFP_KERNEL
);
407 IWL_ERR(priv
, "Can not allocate Buffer\n");
410 eeprom_ver
= iwl_eeprom_query16(priv
, EEPROM_VERSION
);
411 pos
+= scnprintf(buf
+ pos
, buf_size
- pos
, "NVM Type: %s, "
413 (priv
->nvm_device_type
== NVM_DEVICE_TYPE_OTP
)
414 ? "OTP" : "EEPROM", eeprom_ver
);
415 for (ofs
= 0 ; ofs
< eeprom_len
; ofs
+= 16) {
416 pos
+= scnprintf(buf
+ pos
, buf_size
- pos
, "0x%.4x ", ofs
);
417 hex_dump_to_buffer(ptr
+ ofs
, 16 , 16, 2, buf
+ pos
,
419 pos
+= strlen(buf
+ pos
);
420 if (buf_size
- pos
> 0)
424 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
429 static ssize_t
iwl_dbgfs_log_event_read(struct file
*file
,
430 char __user
*user_buf
,
431 size_t count
, loff_t
*ppos
)
433 struct iwl_priv
*priv
= file
->private_data
;
436 ssize_t ret
= -ENOMEM
;
438 ret
= pos
= priv
->cfg
->ops
->lib
->dump_nic_event_log(
439 priv
, true, &buf
, true);
441 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
447 static ssize_t
iwl_dbgfs_log_event_write(struct file
*file
,
448 const char __user
*user_buf
,
449 size_t count
, loff_t
*ppos
)
451 struct iwl_priv
*priv
= file
->private_data
;
456 memset(buf
, 0, sizeof(buf
));
457 buf_size
= min(count
, sizeof(buf
) - 1);
458 if (copy_from_user(buf
, user_buf
, buf_size
))
460 if (sscanf(buf
, "%d", &event_log_flag
) != 1)
462 if (event_log_flag
== 1)
463 priv
->cfg
->ops
->lib
->dump_nic_event_log(priv
, true,
471 static ssize_t
iwl_dbgfs_channels_read(struct file
*file
, char __user
*user_buf
,
472 size_t count
, loff_t
*ppos
)
474 struct iwl_priv
*priv
= file
->private_data
;
475 struct ieee80211_channel
*channels
= NULL
;
476 const struct ieee80211_supported_band
*supp_band
= NULL
;
477 int pos
= 0, i
, bufsz
= PAGE_SIZE
;
481 if (!test_bit(STATUS_GEO_CONFIGURED
, &priv
->status
))
484 buf
= kzalloc(bufsz
, GFP_KERNEL
);
486 IWL_ERR(priv
, "Can not allocate Buffer\n");
490 supp_band
= iwl_get_hw_mode(priv
, IEEE80211_BAND_2GHZ
);
492 channels
= supp_band
->channels
;
494 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
495 "Displaying %d channels in 2.4GHz band 802.11bg):\n",
496 supp_band
->n_channels
);
498 for (i
= 0; i
< supp_band
->n_channels
; i
++)
499 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
500 "%d: %ddBm: BSS%s%s, %s.\n",
501 ieee80211_frequency_to_channel(
502 channels
[i
].center_freq
),
503 channels
[i
].max_power
,
504 channels
[i
].flags
& IEEE80211_CHAN_RADAR
?
505 " (IEEE 802.11h required)" : "",
506 ((channels
[i
].flags
& IEEE80211_CHAN_NO_IBSS
)
507 || (channels
[i
].flags
&
508 IEEE80211_CHAN_RADAR
)) ? "" :
511 IEEE80211_CHAN_PASSIVE_SCAN
?
512 "passive only" : "active/passive");
514 supp_band
= iwl_get_hw_mode(priv
, IEEE80211_BAND_5GHZ
);
516 channels
= supp_band
->channels
;
518 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
519 "Displaying %d channels in 5.2GHz band (802.11a)\n",
520 supp_band
->n_channels
);
522 for (i
= 0; i
< supp_band
->n_channels
; i
++)
523 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
524 "%d: %ddBm: BSS%s%s, %s.\n",
525 ieee80211_frequency_to_channel(
526 channels
[i
].center_freq
),
527 channels
[i
].max_power
,
528 channels
[i
].flags
& IEEE80211_CHAN_RADAR
?
529 " (IEEE 802.11h required)" : "",
530 ((channels
[i
].flags
& IEEE80211_CHAN_NO_IBSS
)
531 || (channels
[i
].flags
&
532 IEEE80211_CHAN_RADAR
)) ? "" :
535 IEEE80211_CHAN_PASSIVE_SCAN
?
536 "passive only" : "active/passive");
538 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
543 static ssize_t
iwl_dbgfs_status_read(struct file
*file
,
544 char __user
*user_buf
,
545 size_t count
, loff_t
*ppos
) {
547 struct iwl_priv
*priv
= file
->private_data
;
550 const size_t bufsz
= sizeof(buf
);
552 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "STATUS_HCMD_ACTIVE:\t %d\n",
553 test_bit(STATUS_HCMD_ACTIVE
, &priv
->status
));
554 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "STATUS_INT_ENABLED:\t %d\n",
555 test_bit(STATUS_INT_ENABLED
, &priv
->status
));
556 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "STATUS_RF_KILL_HW:\t %d\n",
557 test_bit(STATUS_RF_KILL_HW
, &priv
->status
));
558 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "STATUS_CT_KILL:\t\t %d\n",
559 test_bit(STATUS_CT_KILL
, &priv
->status
));
560 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "STATUS_INIT:\t\t %d\n",
561 test_bit(STATUS_INIT
, &priv
->status
));
562 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "STATUS_ALIVE:\t\t %d\n",
563 test_bit(STATUS_ALIVE
, &priv
->status
));
564 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "STATUS_READY:\t\t %d\n",
565 test_bit(STATUS_READY
, &priv
->status
));
566 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "STATUS_TEMPERATURE:\t %d\n",
567 test_bit(STATUS_TEMPERATURE
, &priv
->status
));
568 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "STATUS_GEO_CONFIGURED:\t %d\n",
569 test_bit(STATUS_GEO_CONFIGURED
, &priv
->status
));
570 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "STATUS_EXIT_PENDING:\t %d\n",
571 test_bit(STATUS_EXIT_PENDING
, &priv
->status
));
572 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "STATUS_STATISTICS:\t %d\n",
573 test_bit(STATUS_STATISTICS
, &priv
->status
));
574 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "STATUS_SCANNING:\t %d\n",
575 test_bit(STATUS_SCANNING
, &priv
->status
));
576 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "STATUS_SCAN_ABORTING:\t %d\n",
577 test_bit(STATUS_SCAN_ABORTING
, &priv
->status
));
578 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "STATUS_SCAN_HW:\t\t %d\n",
579 test_bit(STATUS_SCAN_HW
, &priv
->status
));
580 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "STATUS_POWER_PMI:\t %d\n",
581 test_bit(STATUS_POWER_PMI
, &priv
->status
));
582 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "STATUS_FW_ERROR:\t %d\n",
583 test_bit(STATUS_FW_ERROR
, &priv
->status
));
584 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
587 static ssize_t
iwl_dbgfs_interrupt_read(struct file
*file
,
588 char __user
*user_buf
,
589 size_t count
, loff_t
*ppos
) {
591 struct iwl_priv
*priv
= file
->private_data
;
595 int bufsz
= 24 * 64; /* 24 items * 64 char per item */
598 buf
= kzalloc(bufsz
, GFP_KERNEL
);
600 IWL_ERR(priv
, "Can not allocate Buffer\n");
604 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
605 "Interrupt Statistics Report:\n");
607 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "HW Error:\t\t\t %u\n",
609 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "SW Error:\t\t\t %u\n",
611 if (priv
->isr_stats
.sw
> 0) {
612 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
613 "\tLast Restarting Code: 0x%X\n",
614 priv
->isr_stats
.sw_err
);
616 #ifdef CONFIG_IWLWIFI_DEBUG
617 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "Frame transmitted:\t\t %u\n",
618 priv
->isr_stats
.sch
);
619 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "Alive interrupt:\t\t %u\n",
620 priv
->isr_stats
.alive
);
622 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
623 "HW RF KILL switch toggled:\t %u\n",
624 priv
->isr_stats
.rfkill
);
626 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "CT KILL:\t\t\t %u\n",
627 priv
->isr_stats
.ctkill
);
629 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "Wakeup Interrupt:\t\t %u\n",
630 priv
->isr_stats
.wakeup
);
632 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
633 "Rx command responses:\t\t %u\n",
635 for (cnt
= 0; cnt
< REPLY_MAX
; cnt
++) {
636 if (priv
->isr_stats
.rx_handlers
[cnt
] > 0)
637 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
638 "\tRx handler[%36s]:\t\t %u\n",
640 priv
->isr_stats
.rx_handlers
[cnt
]);
643 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "Tx/FH interrupt:\t\t %u\n",
646 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "Unexpected INTA:\t\t %u\n",
647 priv
->isr_stats
.unhandled
);
649 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
654 static ssize_t
iwl_dbgfs_interrupt_write(struct file
*file
,
655 const char __user
*user_buf
,
656 size_t count
, loff_t
*ppos
)
658 struct iwl_priv
*priv
= file
->private_data
;
663 memset(buf
, 0, sizeof(buf
));
664 buf_size
= min(count
, sizeof(buf
) - 1);
665 if (copy_from_user(buf
, user_buf
, buf_size
))
667 if (sscanf(buf
, "%x", &reset_flag
) != 1)
670 iwl_clear_isr_stats(priv
);
675 static ssize_t
iwl_dbgfs_qos_read(struct file
*file
, char __user
*user_buf
,
676 size_t count
, loff_t
*ppos
)
678 struct iwl_priv
*priv
= file
->private_data
;
681 const size_t bufsz
= sizeof(buf
);
683 for (i
= 0; i
< AC_NUM
; i
++) {
684 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
685 "\tcw_min\tcw_max\taifsn\ttxop\n");
686 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
687 "AC[%d]\t%u\t%u\t%u\t%u\n", i
,
688 priv
->qos_data
.def_qos_parm
.ac
[i
].cw_min
,
689 priv
->qos_data
.def_qos_parm
.ac
[i
].cw_max
,
690 priv
->qos_data
.def_qos_parm
.ac
[i
].aifsn
,
691 priv
->qos_data
.def_qos_parm
.ac
[i
].edca_txop
);
693 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
696 static ssize_t
iwl_dbgfs_led_read(struct file
*file
, char __user
*user_buf
,
697 size_t count
, loff_t
*ppos
)
699 struct iwl_priv
*priv
= file
->private_data
;
702 const size_t bufsz
= sizeof(buf
);
704 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
705 "allow blinking: %s\n",
706 (priv
->allow_blinking
) ? "True" : "False");
707 if (priv
->allow_blinking
) {
708 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
709 "Led blinking rate: %u\n",
710 priv
->last_blink_rate
);
711 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
712 "Last blink time: %lu\n",
713 priv
->last_blink_time
);
716 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
719 static ssize_t
iwl_dbgfs_thermal_throttling_read(struct file
*file
,
720 char __user
*user_buf
,
721 size_t count
, loff_t
*ppos
)
723 struct iwl_priv
*priv
= file
->private_data
;
724 struct iwl_tt_mgmt
*tt
= &priv
->thermal_throttle
;
725 struct iwl_tt_restriction
*restriction
;
728 const size_t bufsz
= sizeof(buf
);
730 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
731 "Thermal Throttling Mode: %s\n",
732 tt
->advanced_tt
? "Advance" : "Legacy");
733 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
734 "Thermal Throttling State: %d\n",
736 if (tt
->advanced_tt
) {
737 restriction
= tt
->restriction
+ tt
->state
;
738 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
740 restriction
->tx_stream
);
741 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
743 restriction
->rx_stream
);
744 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
748 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
751 static ssize_t
iwl_dbgfs_disable_ht40_write(struct file
*file
,
752 const char __user
*user_buf
,
753 size_t count
, loff_t
*ppos
)
755 struct iwl_priv
*priv
= file
->private_data
;
760 memset(buf
, 0, sizeof(buf
));
761 buf_size
= min(count
, sizeof(buf
) - 1);
762 if (copy_from_user(buf
, user_buf
, buf_size
))
764 if (sscanf(buf
, "%d", &ht40
) != 1)
766 if (!iwl_is_associated(priv
))
767 priv
->disable_ht40
= ht40
? true : false;
769 IWL_ERR(priv
, "Sta associated with AP - "
770 "Change to 40MHz channel support is not allowed\n");
777 static ssize_t
iwl_dbgfs_disable_ht40_read(struct file
*file
,
778 char __user
*user_buf
,
779 size_t count
, loff_t
*ppos
)
781 struct iwl_priv
*priv
= file
->private_data
;
784 const size_t bufsz
= sizeof(buf
);
786 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
787 "11n 40MHz Mode: %s\n",
788 priv
->disable_ht40
? "Disabled" : "Enabled");
789 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
792 static ssize_t
iwl_dbgfs_sleep_level_override_write(struct file
*file
,
793 const char __user
*user_buf
,
794 size_t count
, loff_t
*ppos
)
796 struct iwl_priv
*priv
= file
->private_data
;
801 memset(buf
, 0, sizeof(buf
));
802 buf_size
= min(count
, sizeof(buf
) - 1);
803 if (copy_from_user(buf
, user_buf
, buf_size
))
806 if (sscanf(buf
, "%d", &value
) != 1)
810 * Our users expect 0 to be "CAM", but 0 isn't actually
811 * valid here. However, let's not confuse them and present
812 * IWL_POWER_INDEX_1 as "1", not "0".
819 if (value
!= -1 && (value
< 0 || value
>= IWL_POWER_NUM
))
822 if (!iwl_is_ready_rf(priv
))
825 priv
->power_data
.debug_sleep_level_override
= value
;
827 mutex_lock(&priv
->mutex
);
828 iwl_power_update_mode(priv
, true);
829 mutex_unlock(&priv
->mutex
);
834 static ssize_t
iwl_dbgfs_sleep_level_override_read(struct file
*file
,
835 char __user
*user_buf
,
836 size_t count
, loff_t
*ppos
)
838 struct iwl_priv
*priv
= file
->private_data
;
841 const size_t bufsz
= sizeof(buf
);
843 /* see the write function */
844 value
= priv
->power_data
.debug_sleep_level_override
;
848 pos
= scnprintf(buf
, bufsz
, "%d\n", value
);
849 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
852 static ssize_t
iwl_dbgfs_current_sleep_command_read(struct file
*file
,
853 char __user
*user_buf
,
854 size_t count
, loff_t
*ppos
)
856 struct iwl_priv
*priv
= file
->private_data
;
859 const size_t bufsz
= sizeof(buf
);
860 struct iwl_powertable_cmd
*cmd
= &priv
->power_data
.sleep_cmd
;
862 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
863 "flags: %#.2x\n", le16_to_cpu(cmd
->flags
));
864 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
865 "RX/TX timeout: %d/%d usec\n",
866 le32_to_cpu(cmd
->rx_data_timeout
),
867 le32_to_cpu(cmd
->tx_data_timeout
));
868 for (i
= 0; i
< IWL_POWER_VEC_SIZE
; i
++)
869 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
870 "sleep_interval[%d]: %d\n", i
,
871 le32_to_cpu(cmd
->sleep_interval
[i
]));
873 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
876 DEBUGFS_READ_WRITE_FILE_OPS(sram
);
877 DEBUGFS_READ_WRITE_FILE_OPS(log_event
);
878 DEBUGFS_READ_FILE_OPS(nvm
);
879 DEBUGFS_READ_FILE_OPS(stations
);
880 DEBUGFS_READ_FILE_OPS(channels
);
881 DEBUGFS_READ_FILE_OPS(status
);
882 DEBUGFS_READ_WRITE_FILE_OPS(interrupt
);
883 DEBUGFS_READ_FILE_OPS(qos
);
884 DEBUGFS_READ_FILE_OPS(led
);
885 DEBUGFS_READ_FILE_OPS(thermal_throttling
);
886 DEBUGFS_READ_WRITE_FILE_OPS(disable_ht40
);
887 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override
);
888 DEBUGFS_READ_FILE_OPS(current_sleep_command
);
890 static ssize_t
iwl_dbgfs_traffic_log_read(struct file
*file
,
891 char __user
*user_buf
,
892 size_t count
, loff_t
*ppos
)
894 struct iwl_priv
*priv
= file
->private_data
;
895 int pos
= 0, ofs
= 0;
897 struct iwl_tx_queue
*txq
;
899 struct iwl_rx_queue
*rxq
= &priv
->rxq
;
901 int bufsz
= ((IWL_TRAFFIC_ENTRIES
* IWL_TRAFFIC_ENTRY_SIZE
* 64) * 2) +
902 (priv
->cfg
->num_of_queues
* 32 * 8) + 400;
907 IWL_ERR(priv
, "txq not ready\n");
910 buf
= kzalloc(bufsz
, GFP_KERNEL
);
912 IWL_ERR(priv
, "Can not allocate buffer\n");
915 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "Tx Queue\n");
916 for (cnt
= 0; cnt
< priv
->hw_params
.max_txq_num
; cnt
++) {
917 txq
= &priv
->txq
[cnt
];
919 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
920 "q[%d]: read_ptr: %u, write_ptr: %u\n",
921 cnt
, q
->read_ptr
, q
->write_ptr
);
923 if (priv
->tx_traffic
&& (iwl_debug_level
& IWL_DL_TX
)) {
924 ptr
= priv
->tx_traffic
;
925 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
926 "Tx Traffic idx: %u\n", priv
->tx_traffic_idx
);
927 for (cnt
= 0, ofs
= 0; cnt
< IWL_TRAFFIC_ENTRIES
; cnt
++) {
928 for (entry
= 0; entry
< IWL_TRAFFIC_ENTRY_SIZE
/ 16;
929 entry
++, ofs
+= 16) {
930 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
932 hex_dump_to_buffer(ptr
+ ofs
, 16, 16, 2,
933 buf
+ pos
, bufsz
- pos
, 0);
934 pos
+= strlen(buf
+ pos
);
941 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "Rx Queue\n");
942 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
943 "read: %u, write: %u\n",
944 rxq
->read
, rxq
->write
);
946 if (priv
->rx_traffic
&& (iwl_debug_level
& IWL_DL_RX
)) {
947 ptr
= priv
->rx_traffic
;
948 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
949 "Rx Traffic idx: %u\n", priv
->rx_traffic_idx
);
950 for (cnt
= 0, ofs
= 0; cnt
< IWL_TRAFFIC_ENTRIES
; cnt
++) {
951 for (entry
= 0; entry
< IWL_TRAFFIC_ENTRY_SIZE
/ 16;
952 entry
++, ofs
+= 16) {
953 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
955 hex_dump_to_buffer(ptr
+ ofs
, 16, 16, 2,
956 buf
+ pos
, bufsz
- pos
, 0);
957 pos
+= strlen(buf
+ pos
);
964 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
969 static ssize_t
iwl_dbgfs_traffic_log_write(struct file
*file
,
970 const char __user
*user_buf
,
971 size_t count
, loff_t
*ppos
)
973 struct iwl_priv
*priv
= file
->private_data
;
978 memset(buf
, 0, sizeof(buf
));
979 buf_size
= min(count
, sizeof(buf
) - 1);
980 if (copy_from_user(buf
, user_buf
, buf_size
))
982 if (sscanf(buf
, "%d", &traffic_log
) != 1)
984 if (traffic_log
== 0)
985 iwl_reset_traffic_log(priv
);
990 static ssize_t
iwl_dbgfs_tx_queue_read(struct file
*file
,
991 char __user
*user_buf
,
992 size_t count
, loff_t
*ppos
) {
994 struct iwl_priv
*priv
= file
->private_data
;
995 struct iwl_tx_queue
*txq
;
1001 const size_t bufsz
= sizeof(char) * 64 * priv
->cfg
->num_of_queues
;
1004 IWL_ERR(priv
, "txq not ready\n");
1007 buf
= kzalloc(bufsz
, GFP_KERNEL
);
1011 for (cnt
= 0; cnt
< priv
->hw_params
.max_txq_num
; cnt
++) {
1012 txq
= &priv
->txq
[cnt
];
1014 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
1015 "hwq %.2d: read=%u write=%u stop=%d"
1016 " swq_id=%#.2x (ac %d/hwq %d)\n",
1017 cnt
, q
->read_ptr
, q
->write_ptr
,
1018 !!test_bit(cnt
, priv
->queue_stopped
),
1020 txq
->swq_id
& 0x80 ? txq
->swq_id
& 3 :
1022 txq
->swq_id
& 0x80 ? (txq
->swq_id
>> 2) &
1023 0x1f : txq
->swq_id
);
1026 /* for the ACs, display the stop count too */
1027 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
1028 " stop-count: %d\n",
1029 atomic_read(&priv
->queue_stop_count
[cnt
]));
1031 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
1036 static ssize_t
iwl_dbgfs_rx_queue_read(struct file
*file
,
1037 char __user
*user_buf
,
1038 size_t count
, loff_t
*ppos
) {
1040 struct iwl_priv
*priv
= file
->private_data
;
1041 struct iwl_rx_queue
*rxq
= &priv
->rxq
;
1044 const size_t bufsz
= sizeof(buf
);
1046 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "read: %u\n",
1048 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "write: %u\n",
1050 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "free_count: %u\n",
1052 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "closed_rb_num: %u\n",
1053 le16_to_cpu(rxq
->rb_stts
->closed_rb_num
) & 0x0FFF);
1054 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
1057 static ssize_t
iwl_dbgfs_ucode_rx_stats_read(struct file
*file
,
1058 char __user
*user_buf
,
1059 size_t count
, loff_t
*ppos
)
1061 struct iwl_priv
*priv
= file
->private_data
;
1062 return priv
->cfg
->ops
->lib
->debugfs_ops
.rx_stats_read(file
,
1063 user_buf
, count
, ppos
);
1066 static ssize_t
iwl_dbgfs_ucode_tx_stats_read(struct file
*file
,
1067 char __user
*user_buf
,
1068 size_t count
, loff_t
*ppos
)
1070 struct iwl_priv
*priv
= file
->private_data
;
1071 return priv
->cfg
->ops
->lib
->debugfs_ops
.tx_stats_read(file
,
1072 user_buf
, count
, ppos
);
1075 static ssize_t
iwl_dbgfs_ucode_general_stats_read(struct file
*file
,
1076 char __user
*user_buf
,
1077 size_t count
, loff_t
*ppos
)
1079 struct iwl_priv
*priv
= file
->private_data
;
1080 return priv
->cfg
->ops
->lib
->debugfs_ops
.general_stats_read(file
,
1081 user_buf
, count
, ppos
);
1084 static ssize_t
iwl_dbgfs_sensitivity_read(struct file
*file
,
1085 char __user
*user_buf
,
1086 size_t count
, loff_t
*ppos
) {
1088 struct iwl_priv
*priv
= file
->private_data
;
1092 int bufsz
= sizeof(struct iwl_sensitivity_data
) * 4 + 100;
1094 struct iwl_sensitivity_data
*data
;
1096 data
= &priv
->sensitivity_data
;
1097 buf
= kzalloc(bufsz
, GFP_KERNEL
);
1099 IWL_ERR(priv
, "Can not allocate Buffer\n");
1103 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "auto_corr_ofdm:\t\t\t %u\n",
1104 data
->auto_corr_ofdm
);
1105 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
1106 "auto_corr_ofdm_mrc:\t\t %u\n",
1107 data
->auto_corr_ofdm_mrc
);
1108 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "auto_corr_ofdm_x1:\t\t %u\n",
1109 data
->auto_corr_ofdm_x1
);
1110 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
1111 "auto_corr_ofdm_mrc_x1:\t\t %u\n",
1112 data
->auto_corr_ofdm_mrc_x1
);
1113 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "auto_corr_cck:\t\t\t %u\n",
1114 data
->auto_corr_cck
);
1115 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "auto_corr_cck_mrc:\t\t %u\n",
1116 data
->auto_corr_cck_mrc
);
1117 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
1118 "last_bad_plcp_cnt_ofdm:\t\t %u\n",
1119 data
->last_bad_plcp_cnt_ofdm
);
1120 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "last_fa_cnt_ofdm:\t\t %u\n",
1121 data
->last_fa_cnt_ofdm
);
1122 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
1123 "last_bad_plcp_cnt_cck:\t\t %u\n",
1124 data
->last_bad_plcp_cnt_cck
);
1125 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "last_fa_cnt_cck:\t\t %u\n",
1126 data
->last_fa_cnt_cck
);
1127 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "nrg_curr_state:\t\t\t %u\n",
1128 data
->nrg_curr_state
);
1129 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "nrg_prev_state:\t\t\t %u\n",
1130 data
->nrg_prev_state
);
1131 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "nrg_value:\t\t\t");
1132 for (cnt
= 0; cnt
< 10; cnt
++) {
1133 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, " %u",
1134 data
->nrg_value
[cnt
]);
1136 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "\n");
1137 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "nrg_silence_rssi:\t\t");
1138 for (cnt
= 0; cnt
< NRG_NUM_PREV_STAT_L
; cnt
++) {
1139 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, " %u",
1140 data
->nrg_silence_rssi
[cnt
]);
1142 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "\n");
1143 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "nrg_silence_ref:\t\t %u\n",
1144 data
->nrg_silence_ref
);
1145 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "nrg_energy_idx:\t\t\t %u\n",
1146 data
->nrg_energy_idx
);
1147 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "nrg_silence_idx:\t\t %u\n",
1148 data
->nrg_silence_idx
);
1149 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "nrg_th_cck:\t\t\t %u\n",
1151 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
1152 "nrg_auto_corr_silence_diff:\t %u\n",
1153 data
->nrg_auto_corr_silence_diff
);
1154 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "num_in_cck_no_fa:\t\t %u\n",
1155 data
->num_in_cck_no_fa
);
1156 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "nrg_th_ofdm:\t\t\t %u\n",
1159 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
1165 static ssize_t
iwl_dbgfs_chain_noise_read(struct file
*file
,
1166 char __user
*user_buf
,
1167 size_t count
, loff_t
*ppos
) {
1169 struct iwl_priv
*priv
= file
->private_data
;
1173 int bufsz
= sizeof(struct iwl_chain_noise_data
) * 4 + 100;
1175 struct iwl_chain_noise_data
*data
;
1177 data
= &priv
->chain_noise_data
;
1178 buf
= kzalloc(bufsz
, GFP_KERNEL
);
1180 IWL_ERR(priv
, "Can not allocate Buffer\n");
1184 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "active_chains:\t\t\t %u\n",
1185 data
->active_chains
);
1186 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "chain_noise_a:\t\t\t %u\n",
1187 data
->chain_noise_a
);
1188 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "chain_noise_b:\t\t\t %u\n",
1189 data
->chain_noise_b
);
1190 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "chain_noise_c:\t\t\t %u\n",
1191 data
->chain_noise_c
);
1192 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "chain_signal_a:\t\t\t %u\n",
1193 data
->chain_signal_a
);
1194 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "chain_signal_b:\t\t\t %u\n",
1195 data
->chain_signal_b
);
1196 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "chain_signal_c:\t\t\t %u\n",
1197 data
->chain_signal_c
);
1198 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "beacon_count:\t\t\t %u\n",
1199 data
->beacon_count
);
1201 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "disconn_array:\t\t\t");
1202 for (cnt
= 0; cnt
< NUM_RX_CHAINS
; cnt
++) {
1203 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, " %u",
1204 data
->disconn_array
[cnt
]);
1206 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "\n");
1207 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "delta_gain_code:\t\t");
1208 for (cnt
= 0; cnt
< NUM_RX_CHAINS
; cnt
++) {
1209 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, " %u",
1210 data
->delta_gain_code
[cnt
]);
1212 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "\n");
1213 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "radio_write:\t\t\t %u\n",
1215 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "state:\t\t\t\t %u\n",
1218 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
1223 static ssize_t
iwl_dbgfs_power_save_status_read(struct file
*file
,
1224 char __user
*user_buf
,
1225 size_t count
, loff_t
*ppos
)
1227 struct iwl_priv
*priv
= file
->private_data
;
1230 const size_t bufsz
= sizeof(buf
);
1233 pwrsave_status
= iwl_read32(priv
, CSR_GP_CNTRL
) &
1234 CSR_GP_REG_POWER_SAVE_STATUS_MSK
;
1236 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "Power Save Status: ");
1237 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "%s\n",
1238 (pwrsave_status
== CSR_GP_REG_NO_POWER_SAVE
) ? "none" :
1239 (pwrsave_status
== CSR_GP_REG_MAC_POWER_SAVE
) ? "MAC" :
1240 (pwrsave_status
== CSR_GP_REG_PHY_POWER_SAVE
) ? "PHY" :
1243 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
1246 static ssize_t
iwl_dbgfs_clear_ucode_statistics_write(struct file
*file
,
1247 const char __user
*user_buf
,
1248 size_t count
, loff_t
*ppos
)
1250 struct iwl_priv
*priv
= file
->private_data
;
1255 memset(buf
, 0, sizeof(buf
));
1256 buf_size
= min(count
, sizeof(buf
) - 1);
1257 if (copy_from_user(buf
, user_buf
, buf_size
))
1259 if (sscanf(buf
, "%d", &clear
) != 1)
1262 /* make request to uCode to retrieve statistics information */
1263 mutex_lock(&priv
->mutex
);
1264 iwl_send_statistics_request(priv
, CMD_SYNC
, true);
1265 mutex_unlock(&priv
->mutex
);
1270 static ssize_t
iwl_dbgfs_csr_write(struct file
*file
,
1271 const char __user
*user_buf
,
1272 size_t count
, loff_t
*ppos
)
1274 struct iwl_priv
*priv
= file
->private_data
;
1279 memset(buf
, 0, sizeof(buf
));
1280 buf_size
= min(count
, sizeof(buf
) - 1);
1281 if (copy_from_user(buf
, user_buf
, buf_size
))
1283 if (sscanf(buf
, "%d", &csr
) != 1)
1286 if (priv
->cfg
->ops
->lib
->dump_csr
)
1287 priv
->cfg
->ops
->lib
->dump_csr(priv
);
1292 static ssize_t
iwl_dbgfs_ucode_tracing_read(struct file
*file
,
1293 char __user
*user_buf
,
1294 size_t count
, loff_t
*ppos
) {
1296 struct iwl_priv
*priv
= (struct iwl_priv
*)file
->private_data
;
1299 const size_t bufsz
= sizeof(buf
);
1301 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "ucode trace timer is %s\n",
1302 priv
->event_log
.ucode_trace
? "On" : "Off");
1303 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "non_wraps_count:\t\t %u\n",
1304 priv
->event_log
.non_wraps_count
);
1305 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "wraps_once_count:\t\t %u\n",
1306 priv
->event_log
.wraps_once_count
);
1307 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "wraps_more_count:\t\t %u\n",
1308 priv
->event_log
.wraps_more_count
);
1310 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
1313 static ssize_t
iwl_dbgfs_ucode_tracing_write(struct file
*file
,
1314 const char __user
*user_buf
,
1315 size_t count
, loff_t
*ppos
)
1317 struct iwl_priv
*priv
= file
->private_data
;
1322 memset(buf
, 0, sizeof(buf
));
1323 buf_size
= min(count
, sizeof(buf
) - 1);
1324 if (copy_from_user(buf
, user_buf
, buf_size
))
1326 if (sscanf(buf
, "%d", &trace
) != 1)
1330 priv
->event_log
.ucode_trace
= true;
1331 /* schedule the ucode timer to occur in UCODE_TRACE_PERIOD */
1332 mod_timer(&priv
->ucode_trace
,
1333 jiffies
+ msecs_to_jiffies(UCODE_TRACE_PERIOD
));
1335 priv
->event_log
.ucode_trace
= false;
1336 del_timer_sync(&priv
->ucode_trace
);
1342 static ssize_t
iwl_dbgfs_rxon_flags_read(struct file
*file
,
1343 char __user
*user_buf
,
1344 size_t count
, loff_t
*ppos
) {
1346 struct iwl_priv
*priv
= (struct iwl_priv
*)file
->private_data
;
1350 len
= sprintf(buf
, "0x%04X\n", le32_to_cpu(priv
->active_rxon
.flags
));
1351 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
1354 static ssize_t
iwl_dbgfs_rxon_filter_flags_read(struct file
*file
,
1355 char __user
*user_buf
,
1356 size_t count
, loff_t
*ppos
) {
1358 struct iwl_priv
*priv
= (struct iwl_priv
*)file
->private_data
;
1362 len
= sprintf(buf
, "0x%04X\n",
1363 le32_to_cpu(priv
->active_rxon
.filter_flags
));
1364 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
1367 static ssize_t
iwl_dbgfs_fh_reg_read(struct file
*file
,
1368 char __user
*user_buf
,
1369 size_t count
, loff_t
*ppos
)
1371 struct iwl_priv
*priv
= (struct iwl_priv
*)file
->private_data
;
1374 ssize_t ret
= -EFAULT
;
1376 if (priv
->cfg
->ops
->lib
->dump_fh
) {
1377 ret
= pos
= priv
->cfg
->ops
->lib
->dump_fh(priv
, &buf
, true);
1379 ret
= simple_read_from_buffer(user_buf
,
1380 count
, ppos
, buf
, pos
);
1388 static ssize_t
iwl_dbgfs_missed_beacon_read(struct file
*file
,
1389 char __user
*user_buf
,
1390 size_t count
, loff_t
*ppos
) {
1392 struct iwl_priv
*priv
= file
->private_data
;
1395 const size_t bufsz
= sizeof(buf
);
1397 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "%d\n",
1398 priv
->missed_beacon_threshold
);
1400 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
1403 static ssize_t
iwl_dbgfs_missed_beacon_write(struct file
*file
,
1404 const char __user
*user_buf
,
1405 size_t count
, loff_t
*ppos
)
1407 struct iwl_priv
*priv
= file
->private_data
;
1412 memset(buf
, 0, sizeof(buf
));
1413 buf_size
= min(count
, sizeof(buf
) - 1);
1414 if (copy_from_user(buf
, user_buf
, buf_size
))
1416 if (sscanf(buf
, "%d", &missed
) != 1)
1419 if (missed
< IWL_MISSED_BEACON_THRESHOLD_MIN
||
1420 missed
> IWL_MISSED_BEACON_THRESHOLD_MAX
)
1421 priv
->missed_beacon_threshold
=
1422 IWL_MISSED_BEACON_THRESHOLD_DEF
;
1424 priv
->missed_beacon_threshold
= missed
;
1429 static ssize_t
iwl_dbgfs_plcp_delta_read(struct file
*file
,
1430 char __user
*user_buf
,
1431 size_t count
, loff_t
*ppos
) {
1433 struct iwl_priv
*priv
= (struct iwl_priv
*)file
->private_data
;
1436 const size_t bufsz
= sizeof(buf
);
1438 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "%u\n",
1439 priv
->cfg
->plcp_delta_threshold
);
1441 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
1444 static ssize_t
iwl_dbgfs_plcp_delta_write(struct file
*file
,
1445 const char __user
*user_buf
,
1446 size_t count
, loff_t
*ppos
) {
1448 struct iwl_priv
*priv
= file
->private_data
;
1453 memset(buf
, 0, sizeof(buf
));
1454 buf_size
= min(count
, sizeof(buf
) - 1);
1455 if (copy_from_user(buf
, user_buf
, buf_size
))
1457 if (sscanf(buf
, "%d", &plcp
) != 1)
1459 if ((plcp
<= IWL_MAX_PLCP_ERR_THRESHOLD_MIN
) ||
1460 (plcp
> IWL_MAX_PLCP_ERR_THRESHOLD_MAX
))
1461 priv
->cfg
->plcp_delta_threshold
=
1462 IWL_MAX_PLCP_ERR_THRESHOLD_DEF
;
1464 priv
->cfg
->plcp_delta_threshold
= plcp
;
1468 static ssize_t
iwl_dbgfs_force_reset_read(struct file
*file
,
1469 char __user
*user_buf
,
1470 size_t count
, loff_t
*ppos
) {
1472 struct iwl_priv
*priv
= file
->private_data
;
1475 const size_t bufsz
= sizeof(buf
);
1476 struct iwl_force_reset
*force_reset
;
1478 for (i
= 0; i
< IWL_MAX_FORCE_RESET
; i
++) {
1479 force_reset
= &priv
->force_reset
[i
];
1480 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
1481 "Force reset method %d\n", i
);
1482 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
1483 "\tnumber of reset request: %d\n",
1484 force_reset
->reset_request_count
);
1485 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
1486 "\tnumber of reset request success: %d\n",
1487 force_reset
->reset_success_count
);
1488 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
1489 "\tnumber of reset request reject: %d\n",
1490 force_reset
->reset_reject_count
);
1491 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
1492 "\treset duration: %lu\n",
1493 force_reset
->reset_duration
);
1495 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
1498 static ssize_t
iwl_dbgfs_force_reset_write(struct file
*file
,
1499 const char __user
*user_buf
,
1500 size_t count
, loff_t
*ppos
) {
1502 struct iwl_priv
*priv
= file
->private_data
;
1507 memset(buf
, 0, sizeof(buf
));
1508 buf_size
= min(count
, sizeof(buf
) - 1);
1509 if (copy_from_user(buf
, user_buf
, buf_size
))
1511 if (sscanf(buf
, "%d", &reset
) != 1)
1516 ret
= iwl_force_reset(priv
, reset
);
1521 return ret
? ret
: count
;
1524 DEBUGFS_READ_FILE_OPS(rx_statistics
);
1525 DEBUGFS_READ_FILE_OPS(tx_statistics
);
1526 DEBUGFS_READ_WRITE_FILE_OPS(traffic_log
);
1527 DEBUGFS_READ_FILE_OPS(rx_queue
);
1528 DEBUGFS_READ_FILE_OPS(tx_queue
);
1529 DEBUGFS_READ_FILE_OPS(ucode_rx_stats
);
1530 DEBUGFS_READ_FILE_OPS(ucode_tx_stats
);
1531 DEBUGFS_READ_FILE_OPS(ucode_general_stats
);
1532 DEBUGFS_READ_FILE_OPS(sensitivity
);
1533 DEBUGFS_READ_FILE_OPS(chain_noise
);
1534 DEBUGFS_READ_FILE_OPS(power_save_status
);
1535 DEBUGFS_WRITE_FILE_OPS(clear_ucode_statistics
);
1536 DEBUGFS_WRITE_FILE_OPS(clear_traffic_statistics
);
1537 DEBUGFS_WRITE_FILE_OPS(csr
);
1538 DEBUGFS_READ_WRITE_FILE_OPS(ucode_tracing
);
1539 DEBUGFS_READ_FILE_OPS(fh_reg
);
1540 DEBUGFS_READ_WRITE_FILE_OPS(missed_beacon
);
1541 DEBUGFS_READ_WRITE_FILE_OPS(plcp_delta
);
1542 DEBUGFS_READ_WRITE_FILE_OPS(force_reset
);
1543 DEBUGFS_READ_FILE_OPS(rxon_flags
);
1544 DEBUGFS_READ_FILE_OPS(rxon_filter_flags
);
1547 * Create the debugfs files and directories
1550 int iwl_dbgfs_register(struct iwl_priv
*priv
, const char *name
)
1552 struct dentry
*phyd
= priv
->hw
->wiphy
->debugfsdir
;
1553 struct dentry
*dir_drv
, *dir_data
, *dir_rf
, *dir_debug
;
1555 dir_drv
= debugfs_create_dir(name
, phyd
);
1559 priv
->debugfs_dir
= dir_drv
;
1561 dir_data
= debugfs_create_dir("data", dir_drv
);
1564 dir_rf
= debugfs_create_dir("rf", dir_drv
);
1567 dir_debug
= debugfs_create_dir("debug", dir_drv
);
1571 DEBUGFS_ADD_FILE(nvm
, dir_data
, S_IRUSR
);
1572 DEBUGFS_ADD_FILE(sram
, dir_data
, S_IWUSR
| S_IRUSR
);
1573 DEBUGFS_ADD_FILE(log_event
, dir_data
, S_IWUSR
| S_IRUSR
);
1574 DEBUGFS_ADD_FILE(stations
, dir_data
, S_IRUSR
);
1575 DEBUGFS_ADD_FILE(channels
, dir_data
, S_IRUSR
);
1576 DEBUGFS_ADD_FILE(status
, dir_data
, S_IRUSR
);
1577 DEBUGFS_ADD_FILE(interrupt
, dir_data
, S_IWUSR
| S_IRUSR
);
1578 DEBUGFS_ADD_FILE(qos
, dir_data
, S_IRUSR
);
1579 DEBUGFS_ADD_FILE(led
, dir_data
, S_IRUSR
);
1580 if (!priv
->cfg
->broken_powersave
) {
1581 DEBUGFS_ADD_FILE(sleep_level_override
, dir_data
,
1583 DEBUGFS_ADD_FILE(current_sleep_command
, dir_data
, S_IRUSR
);
1585 DEBUGFS_ADD_FILE(thermal_throttling
, dir_data
, S_IRUSR
);
1586 DEBUGFS_ADD_FILE(disable_ht40
, dir_data
, S_IWUSR
| S_IRUSR
);
1587 DEBUGFS_ADD_FILE(rx_statistics
, dir_debug
, S_IRUSR
);
1588 DEBUGFS_ADD_FILE(tx_statistics
, dir_debug
, S_IRUSR
);
1589 DEBUGFS_ADD_FILE(traffic_log
, dir_debug
, S_IWUSR
| S_IRUSR
);
1590 DEBUGFS_ADD_FILE(rx_queue
, dir_debug
, S_IRUSR
);
1591 DEBUGFS_ADD_FILE(tx_queue
, dir_debug
, S_IRUSR
);
1592 DEBUGFS_ADD_FILE(power_save_status
, dir_debug
, S_IRUSR
);
1593 DEBUGFS_ADD_FILE(clear_ucode_statistics
, dir_debug
, S_IWUSR
);
1594 DEBUGFS_ADD_FILE(clear_traffic_statistics
, dir_debug
, S_IWUSR
);
1595 DEBUGFS_ADD_FILE(csr
, dir_debug
, S_IWUSR
);
1596 DEBUGFS_ADD_FILE(fh_reg
, dir_debug
, S_IRUSR
);
1597 DEBUGFS_ADD_FILE(missed_beacon
, dir_debug
, S_IWUSR
);
1598 DEBUGFS_ADD_FILE(plcp_delta
, dir_debug
, S_IWUSR
| S_IRUSR
);
1599 DEBUGFS_ADD_FILE(force_reset
, dir_debug
, S_IWUSR
| S_IRUSR
);
1600 DEBUGFS_ADD_FILE(ucode_rx_stats
, dir_debug
, S_IRUSR
);
1601 DEBUGFS_ADD_FILE(ucode_tx_stats
, dir_debug
, S_IRUSR
);
1602 DEBUGFS_ADD_FILE(ucode_general_stats
, dir_debug
, S_IRUSR
);
1604 if (priv
->cfg
->sensitivity_calib_by_driver
)
1605 DEBUGFS_ADD_FILE(sensitivity
, dir_debug
, S_IRUSR
);
1606 if (priv
->cfg
->chain_noise_calib_by_driver
)
1607 DEBUGFS_ADD_FILE(chain_noise
, dir_debug
, S_IRUSR
);
1608 if (priv
->cfg
->ucode_tracing
)
1609 DEBUGFS_ADD_FILE(ucode_tracing
, dir_debug
, S_IWUSR
| S_IRUSR
);
1610 DEBUGFS_ADD_FILE(rxon_flags
, dir_debug
, S_IWUSR
);
1611 DEBUGFS_ADD_FILE(rxon_filter_flags
, dir_debug
, S_IWUSR
);
1612 if (priv
->cfg
->sensitivity_calib_by_driver
)
1613 DEBUGFS_ADD_BOOL(disable_sensitivity
, dir_rf
,
1614 &priv
->disable_sens_cal
);
1615 if (priv
->cfg
->chain_noise_calib_by_driver
)
1616 DEBUGFS_ADD_BOOL(disable_chain_noise
, dir_rf
,
1617 &priv
->disable_chain_noise_cal
);
1618 if (priv
->cfg
->tx_power_by_driver
)
1619 DEBUGFS_ADD_BOOL(disable_tx_power
, dir_rf
,
1620 &priv
->disable_tx_power_cal
);
1624 IWL_ERR(priv
, "Can't create the debugfs directory\n");
1625 iwl_dbgfs_unregister(priv
);
1628 EXPORT_SYMBOL(iwl_dbgfs_register
);
1631 * Remove the debugfs files and directories
1634 void iwl_dbgfs_unregister(struct iwl_priv
*priv
)
1636 if (!priv
->debugfs_dir
)
1639 debugfs_remove_recursive(priv
->debugfs_dir
);
1640 priv
->debugfs_dir
= NULL
;
1642 EXPORT_SYMBOL(iwl_dbgfs_unregister
);