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_tx_power_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
);
1231 struct statistics_tx
*tx
;
1233 if (!iwl_is_alive(priv
))
1234 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "N/A\n");
1236 tx
= &priv
->statistics
.tx
;
1237 if (tx
->tx_power
.ant_a
||
1238 tx
->tx_power
.ant_b
||
1239 tx
->tx_power
.ant_c
) {
1240 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
1241 "tx power: (1/2 dB step)\n");
1242 if ((priv
->cfg
->valid_tx_ant
& ANT_A
) &&
1244 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
1245 "\tantenna A: 0x%X\n",
1246 tx
->tx_power
.ant_a
);
1247 if ((priv
->cfg
->valid_tx_ant
& ANT_B
) &&
1249 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
1250 "\tantenna B: 0x%X\n",
1251 tx
->tx_power
.ant_b
);
1252 if ((priv
->cfg
->valid_tx_ant
& ANT_C
) &&
1254 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
1255 "\tantenna C: 0x%X\n",
1256 tx
->tx_power
.ant_c
);
1258 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "N/A\n");
1260 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
1263 static ssize_t
iwl_dbgfs_power_save_status_read(struct file
*file
,
1264 char __user
*user_buf
,
1265 size_t count
, loff_t
*ppos
)
1267 struct iwl_priv
*priv
= file
->private_data
;
1270 const size_t bufsz
= sizeof(buf
);
1273 pwrsave_status
= iwl_read32(priv
, CSR_GP_CNTRL
) &
1274 CSR_GP_REG_POWER_SAVE_STATUS_MSK
;
1276 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "Power Save Status: ");
1277 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "%s\n",
1278 (pwrsave_status
== CSR_GP_REG_NO_POWER_SAVE
) ? "none" :
1279 (pwrsave_status
== CSR_GP_REG_MAC_POWER_SAVE
) ? "MAC" :
1280 (pwrsave_status
== CSR_GP_REG_PHY_POWER_SAVE
) ? "PHY" :
1283 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
1286 static ssize_t
iwl_dbgfs_clear_ucode_statistics_write(struct file
*file
,
1287 const char __user
*user_buf
,
1288 size_t count
, loff_t
*ppos
)
1290 struct iwl_priv
*priv
= file
->private_data
;
1295 memset(buf
, 0, sizeof(buf
));
1296 buf_size
= min(count
, sizeof(buf
) - 1);
1297 if (copy_from_user(buf
, user_buf
, buf_size
))
1299 if (sscanf(buf
, "%d", &clear
) != 1)
1302 /* make request to uCode to retrieve statistics information */
1303 mutex_lock(&priv
->mutex
);
1304 iwl_send_statistics_request(priv
, CMD_SYNC
, true);
1305 mutex_unlock(&priv
->mutex
);
1310 static ssize_t
iwl_dbgfs_csr_write(struct file
*file
,
1311 const char __user
*user_buf
,
1312 size_t count
, loff_t
*ppos
)
1314 struct iwl_priv
*priv
= file
->private_data
;
1319 memset(buf
, 0, sizeof(buf
));
1320 buf_size
= min(count
, sizeof(buf
) - 1);
1321 if (copy_from_user(buf
, user_buf
, buf_size
))
1323 if (sscanf(buf
, "%d", &csr
) != 1)
1326 if (priv
->cfg
->ops
->lib
->dump_csr
)
1327 priv
->cfg
->ops
->lib
->dump_csr(priv
);
1332 static ssize_t
iwl_dbgfs_ucode_tracing_read(struct file
*file
,
1333 char __user
*user_buf
,
1334 size_t count
, loff_t
*ppos
) {
1336 struct iwl_priv
*priv
= (struct iwl_priv
*)file
->private_data
;
1339 const size_t bufsz
= sizeof(buf
);
1341 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "ucode trace timer is %s\n",
1342 priv
->event_log
.ucode_trace
? "On" : "Off");
1343 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "non_wraps_count:\t\t %u\n",
1344 priv
->event_log
.non_wraps_count
);
1345 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "wraps_once_count:\t\t %u\n",
1346 priv
->event_log
.wraps_once_count
);
1347 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "wraps_more_count:\t\t %u\n",
1348 priv
->event_log
.wraps_more_count
);
1350 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
1353 static ssize_t
iwl_dbgfs_ucode_tracing_write(struct file
*file
,
1354 const char __user
*user_buf
,
1355 size_t count
, loff_t
*ppos
)
1357 struct iwl_priv
*priv
= file
->private_data
;
1362 memset(buf
, 0, sizeof(buf
));
1363 buf_size
= min(count
, sizeof(buf
) - 1);
1364 if (copy_from_user(buf
, user_buf
, buf_size
))
1366 if (sscanf(buf
, "%d", &trace
) != 1)
1370 priv
->event_log
.ucode_trace
= true;
1371 /* schedule the ucode timer to occur in UCODE_TRACE_PERIOD */
1372 mod_timer(&priv
->ucode_trace
,
1373 jiffies
+ msecs_to_jiffies(UCODE_TRACE_PERIOD
));
1375 priv
->event_log
.ucode_trace
= false;
1376 del_timer_sync(&priv
->ucode_trace
);
1382 static ssize_t
iwl_dbgfs_rxon_flags_read(struct file
*file
,
1383 char __user
*user_buf
,
1384 size_t count
, loff_t
*ppos
) {
1386 struct iwl_priv
*priv
= (struct iwl_priv
*)file
->private_data
;
1390 len
= sprintf(buf
, "0x%04X\n", le32_to_cpu(priv
->active_rxon
.flags
));
1391 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
1394 static ssize_t
iwl_dbgfs_rxon_filter_flags_read(struct file
*file
,
1395 char __user
*user_buf
,
1396 size_t count
, loff_t
*ppos
) {
1398 struct iwl_priv
*priv
= (struct iwl_priv
*)file
->private_data
;
1402 len
= sprintf(buf
, "0x%04X\n",
1403 le32_to_cpu(priv
->active_rxon
.filter_flags
));
1404 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
1407 static ssize_t
iwl_dbgfs_fh_reg_read(struct file
*file
,
1408 char __user
*user_buf
,
1409 size_t count
, loff_t
*ppos
)
1411 struct iwl_priv
*priv
= (struct iwl_priv
*)file
->private_data
;
1414 ssize_t ret
= -EFAULT
;
1416 if (priv
->cfg
->ops
->lib
->dump_fh
) {
1417 ret
= pos
= priv
->cfg
->ops
->lib
->dump_fh(priv
, &buf
, true);
1419 ret
= simple_read_from_buffer(user_buf
,
1420 count
, ppos
, buf
, pos
);
1428 static ssize_t
iwl_dbgfs_missed_beacon_read(struct file
*file
,
1429 char __user
*user_buf
,
1430 size_t count
, loff_t
*ppos
) {
1432 struct iwl_priv
*priv
= file
->private_data
;
1435 const size_t bufsz
= sizeof(buf
);
1437 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "%d\n",
1438 priv
->missed_beacon_threshold
);
1440 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
1443 static ssize_t
iwl_dbgfs_missed_beacon_write(struct file
*file
,
1444 const char __user
*user_buf
,
1445 size_t count
, loff_t
*ppos
)
1447 struct iwl_priv
*priv
= file
->private_data
;
1452 memset(buf
, 0, sizeof(buf
));
1453 buf_size
= min(count
, sizeof(buf
) - 1);
1454 if (copy_from_user(buf
, user_buf
, buf_size
))
1456 if (sscanf(buf
, "%d", &missed
) != 1)
1459 if (missed
< IWL_MISSED_BEACON_THRESHOLD_MIN
||
1460 missed
> IWL_MISSED_BEACON_THRESHOLD_MAX
)
1461 priv
->missed_beacon_threshold
=
1462 IWL_MISSED_BEACON_THRESHOLD_DEF
;
1464 priv
->missed_beacon_threshold
= missed
;
1469 static ssize_t
iwl_dbgfs_plcp_delta_read(struct file
*file
,
1470 char __user
*user_buf
,
1471 size_t count
, loff_t
*ppos
) {
1473 struct iwl_priv
*priv
= (struct iwl_priv
*)file
->private_data
;
1476 const size_t bufsz
= sizeof(buf
);
1478 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "%u\n",
1479 priv
->cfg
->plcp_delta_threshold
);
1481 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
1484 static ssize_t
iwl_dbgfs_plcp_delta_write(struct file
*file
,
1485 const char __user
*user_buf
,
1486 size_t count
, loff_t
*ppos
) {
1488 struct iwl_priv
*priv
= file
->private_data
;
1493 memset(buf
, 0, sizeof(buf
));
1494 buf_size
= min(count
, sizeof(buf
) - 1);
1495 if (copy_from_user(buf
, user_buf
, buf_size
))
1497 if (sscanf(buf
, "%d", &plcp
) != 1)
1499 if ((plcp
<= IWL_MAX_PLCP_ERR_THRESHOLD_MIN
) ||
1500 (plcp
> IWL_MAX_PLCP_ERR_THRESHOLD_MAX
))
1501 priv
->cfg
->plcp_delta_threshold
=
1502 IWL_MAX_PLCP_ERR_THRESHOLD_DEF
;
1504 priv
->cfg
->plcp_delta_threshold
= plcp
;
1508 static ssize_t
iwl_dbgfs_force_reset_read(struct file
*file
,
1509 char __user
*user_buf
,
1510 size_t count
, loff_t
*ppos
) {
1512 struct iwl_priv
*priv
= file
->private_data
;
1515 const size_t bufsz
= sizeof(buf
);
1516 struct iwl_force_reset
*force_reset
;
1518 for (i
= 0; i
< IWL_MAX_FORCE_RESET
; i
++) {
1519 force_reset
= &priv
->force_reset
[i
];
1520 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
1521 "Force reset method %d\n", i
);
1522 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
1523 "\tnumber of reset request: %d\n",
1524 force_reset
->reset_request_count
);
1525 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
1526 "\tnumber of reset request success: %d\n",
1527 force_reset
->reset_success_count
);
1528 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
1529 "\tnumber of reset request reject: %d\n",
1530 force_reset
->reset_reject_count
);
1531 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
1532 "\treset duration: %lu\n",
1533 force_reset
->reset_duration
);
1535 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
1538 static ssize_t
iwl_dbgfs_force_reset_write(struct file
*file
,
1539 const char __user
*user_buf
,
1540 size_t count
, loff_t
*ppos
) {
1542 struct iwl_priv
*priv
= file
->private_data
;
1547 memset(buf
, 0, sizeof(buf
));
1548 buf_size
= min(count
, sizeof(buf
) - 1);
1549 if (copy_from_user(buf
, user_buf
, buf_size
))
1551 if (sscanf(buf
, "%d", &reset
) != 1)
1556 ret
= iwl_force_reset(priv
, reset
);
1561 return ret
? ret
: count
;
1564 DEBUGFS_READ_FILE_OPS(rx_statistics
);
1565 DEBUGFS_READ_FILE_OPS(tx_statistics
);
1566 DEBUGFS_READ_WRITE_FILE_OPS(traffic_log
);
1567 DEBUGFS_READ_FILE_OPS(rx_queue
);
1568 DEBUGFS_READ_FILE_OPS(tx_queue
);
1569 DEBUGFS_READ_FILE_OPS(ucode_rx_stats
);
1570 DEBUGFS_READ_FILE_OPS(ucode_tx_stats
);
1571 DEBUGFS_READ_FILE_OPS(ucode_general_stats
);
1572 DEBUGFS_READ_FILE_OPS(sensitivity
);
1573 DEBUGFS_READ_FILE_OPS(chain_noise
);
1574 DEBUGFS_READ_FILE_OPS(tx_power
);
1575 DEBUGFS_READ_FILE_OPS(power_save_status
);
1576 DEBUGFS_WRITE_FILE_OPS(clear_ucode_statistics
);
1577 DEBUGFS_WRITE_FILE_OPS(clear_traffic_statistics
);
1578 DEBUGFS_WRITE_FILE_OPS(csr
);
1579 DEBUGFS_READ_WRITE_FILE_OPS(ucode_tracing
);
1580 DEBUGFS_READ_FILE_OPS(fh_reg
);
1581 DEBUGFS_READ_WRITE_FILE_OPS(missed_beacon
);
1582 DEBUGFS_READ_WRITE_FILE_OPS(plcp_delta
);
1583 DEBUGFS_READ_WRITE_FILE_OPS(force_reset
);
1584 DEBUGFS_READ_FILE_OPS(rxon_flags
);
1585 DEBUGFS_READ_FILE_OPS(rxon_filter_flags
);
1588 * Create the debugfs files and directories
1591 int iwl_dbgfs_register(struct iwl_priv
*priv
, const char *name
)
1593 struct dentry
*phyd
= priv
->hw
->wiphy
->debugfsdir
;
1594 struct dentry
*dir_drv
, *dir_data
, *dir_rf
, *dir_debug
;
1596 dir_drv
= debugfs_create_dir(name
, phyd
);
1600 priv
->debugfs_dir
= dir_drv
;
1602 dir_data
= debugfs_create_dir("data", dir_drv
);
1605 dir_rf
= debugfs_create_dir("rf", dir_drv
);
1608 dir_debug
= debugfs_create_dir("debug", dir_drv
);
1612 DEBUGFS_ADD_FILE(nvm
, dir_data
, S_IRUSR
);
1613 DEBUGFS_ADD_FILE(sram
, dir_data
, S_IWUSR
| S_IRUSR
);
1614 DEBUGFS_ADD_FILE(log_event
, dir_data
, S_IWUSR
| S_IRUSR
);
1615 DEBUGFS_ADD_FILE(stations
, dir_data
, S_IRUSR
);
1616 DEBUGFS_ADD_FILE(channels
, dir_data
, S_IRUSR
);
1617 DEBUGFS_ADD_FILE(status
, dir_data
, S_IRUSR
);
1618 DEBUGFS_ADD_FILE(interrupt
, dir_data
, S_IWUSR
| S_IRUSR
);
1619 DEBUGFS_ADD_FILE(qos
, dir_data
, S_IRUSR
);
1620 DEBUGFS_ADD_FILE(led
, dir_data
, S_IRUSR
);
1621 DEBUGFS_ADD_FILE(sleep_level_override
, dir_data
, S_IWUSR
| S_IRUSR
);
1622 DEBUGFS_ADD_FILE(current_sleep_command
, dir_data
, S_IRUSR
);
1623 DEBUGFS_ADD_FILE(thermal_throttling
, dir_data
, S_IRUSR
);
1624 DEBUGFS_ADD_FILE(disable_ht40
, dir_data
, S_IWUSR
| S_IRUSR
);
1625 DEBUGFS_ADD_FILE(rx_statistics
, dir_debug
, S_IRUSR
);
1626 DEBUGFS_ADD_FILE(tx_statistics
, dir_debug
, S_IRUSR
);
1627 DEBUGFS_ADD_FILE(traffic_log
, dir_debug
, S_IWUSR
| S_IRUSR
);
1628 DEBUGFS_ADD_FILE(rx_queue
, dir_debug
, S_IRUSR
);
1629 DEBUGFS_ADD_FILE(tx_queue
, dir_debug
, S_IRUSR
);
1630 DEBUGFS_ADD_FILE(tx_power
, dir_debug
, S_IRUSR
);
1631 DEBUGFS_ADD_FILE(power_save_status
, dir_debug
, S_IRUSR
);
1632 DEBUGFS_ADD_FILE(clear_ucode_statistics
, dir_debug
, S_IWUSR
);
1633 DEBUGFS_ADD_FILE(clear_traffic_statistics
, dir_debug
, S_IWUSR
);
1634 DEBUGFS_ADD_FILE(csr
, dir_debug
, S_IWUSR
);
1635 DEBUGFS_ADD_FILE(fh_reg
, dir_debug
, S_IRUSR
);
1636 DEBUGFS_ADD_FILE(missed_beacon
, dir_debug
, S_IWUSR
);
1637 DEBUGFS_ADD_FILE(plcp_delta
, dir_debug
, S_IWUSR
| S_IRUSR
);
1638 DEBUGFS_ADD_FILE(force_reset
, dir_debug
, S_IWUSR
| S_IRUSR
);
1639 DEBUGFS_ADD_FILE(ucode_rx_stats
, dir_debug
, S_IRUSR
);
1640 DEBUGFS_ADD_FILE(ucode_tx_stats
, dir_debug
, S_IRUSR
);
1641 DEBUGFS_ADD_FILE(ucode_general_stats
, dir_debug
, S_IRUSR
);
1643 if ((priv
->hw_rev
& CSR_HW_REV_TYPE_MSK
) != CSR_HW_REV_TYPE_3945
) {
1644 DEBUGFS_ADD_FILE(sensitivity
, dir_debug
, S_IRUSR
);
1645 DEBUGFS_ADD_FILE(chain_noise
, dir_debug
, S_IRUSR
);
1646 DEBUGFS_ADD_FILE(ucode_tracing
, dir_debug
, S_IWUSR
| S_IRUSR
);
1648 DEBUGFS_ADD_FILE(rxon_flags
, dir_debug
, S_IWUSR
);
1649 DEBUGFS_ADD_FILE(rxon_filter_flags
, dir_debug
, S_IWUSR
);
1650 DEBUGFS_ADD_BOOL(disable_sensitivity
, dir_rf
, &priv
->disable_sens_cal
);
1651 DEBUGFS_ADD_BOOL(disable_chain_noise
, dir_rf
,
1652 &priv
->disable_chain_noise_cal
);
1653 if (((priv
->hw_rev
& CSR_HW_REV_TYPE_MSK
) == CSR_HW_REV_TYPE_4965
) ||
1654 ((priv
->hw_rev
& CSR_HW_REV_TYPE_MSK
) == CSR_HW_REV_TYPE_3945
))
1655 DEBUGFS_ADD_BOOL(disable_tx_power
, dir_rf
,
1656 &priv
->disable_tx_power_cal
);
1660 IWL_ERR(priv
, "Can't create the debugfs directory\n");
1661 iwl_dbgfs_unregister(priv
);
1664 EXPORT_SYMBOL(iwl_dbgfs_register
);
1667 * Remove the debugfs files and directories
1670 void iwl_dbgfs_unregister(struct iwl_priv
*priv
)
1672 if (!priv
->debugfs_dir
)
1675 debugfs_remove_recursive(priv
->debugfs_dir
);
1676 priv
->debugfs_dir
= NULL
;
1678 EXPORT_SYMBOL(iwl_dbgfs_unregister
);