1 /******************************************************************************
5 * Copyright(c) 2008 - 2011 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 *****************************************************************************/
28 #include <linux/ieee80211.h>
29 #include <net/mac80211.h>
32 #include "iwl-debug.h"
35 /* create and remove of files */
36 #define DEBUGFS_ADD_FILE(name, parent, mode) do { \
37 if (!debugfs_create_file(#name, mode, parent, il, \
38 &il_dbgfs_##name##_ops)) \
42 #define DEBUGFS_ADD_BOOL(name, parent, ptr) do { \
43 struct dentry *__tmp; \
44 __tmp = debugfs_create_bool(#name, S_IWUSR | S_IRUSR, \
46 if (IS_ERR(__tmp) || !__tmp) \
50 #define DEBUGFS_ADD_X32(name, parent, ptr) do { \
51 struct dentry *__tmp; \
52 __tmp = debugfs_create_x32(#name, S_IWUSR | S_IRUSR, \
54 if (IS_ERR(__tmp) || !__tmp) \
59 #define DEBUGFS_READ_FUNC(name) \
60 static ssize_t il_dbgfs_##name##_read(struct file *file, \
61 char __user *user_buf, \
62 size_t count, loff_t *ppos);
64 #define DEBUGFS_WRITE_FUNC(name) \
65 static ssize_t il_dbgfs_##name##_write(struct file *file, \
66 const char __user *user_buf, \
67 size_t count, loff_t *ppos);
71 il_dbgfs_open_file_generic(struct inode *inode, struct file *file)
73 file->private_data = inode->i_private;
77 #define DEBUGFS_READ_FILE_OPS(name) \
78 DEBUGFS_READ_FUNC(name); \
79 static const struct file_operations il_dbgfs_##name##_ops = { \
80 .read = il_dbgfs_##name##_read, \
81 .open = il_dbgfs_open_file_generic, \
82 .llseek = generic_file_llseek, \
85 #define DEBUGFS_WRITE_FILE_OPS(name) \
86 DEBUGFS_WRITE_FUNC(name); \
87 static const struct file_operations il_dbgfs_##name##_ops = { \
88 .write = il_dbgfs_##name##_write, \
89 .open = il_dbgfs_open_file_generic, \
90 .llseek = generic_file_llseek, \
93 #define DEBUGFS_READ_WRITE_FILE_OPS(name) \
94 DEBUGFS_READ_FUNC(name); \
95 DEBUGFS_WRITE_FUNC(name); \
96 static const struct file_operations il_dbgfs_##name##_ops = { \
97 .write = il_dbgfs_##name##_write, \
98 .read = il_dbgfs_##name##_read, \
99 .open = il_dbgfs_open_file_generic, \
100 .llseek = generic_file_llseek, \
103 static ssize_t il_dbgfs_tx_stats_read(struct file *file,
104 char __user *user_buf,
105 size_t count, loff_t *ppos) {
107 struct il_priv *il = file->private_data;
113 const size_t bufsz = 100 +
114 sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
115 buf = kzalloc(bufsz, GFP_KERNEL);
118 pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
119 for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
120 pos += scnprintf(buf + pos, bufsz - pos,
122 il_get_mgmt_string(cnt),
123 il->tx_stats.mgmt[cnt]);
125 pos += scnprintf(buf + pos, bufsz - pos, "Control\n");
126 for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
127 pos += scnprintf(buf + pos, bufsz - pos,
129 il_get_ctrl_string(cnt),
130 il->tx_stats.ctrl[cnt]);
132 pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
133 pos += scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
134 il->tx_stats.data_cnt);
135 pos += scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
136 il->tx_stats.data_bytes);
137 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
143 il_dbgfs_clear_traffic_stats_write(struct file *file,
144 const char __user *user_buf,
145 size_t count, loff_t *ppos)
147 struct il_priv *il = file->private_data;
152 memset(buf, 0, sizeof(buf));
153 buf_size = min(count, sizeof(buf) - 1);
154 if (copy_from_user(buf, user_buf, buf_size))
156 if (sscanf(buf, "%x", &clear_flag) != 1)
158 il_clear_traffic_stats(il);
163 static ssize_t il_dbgfs_rx_stats_read(struct file *file,
164 char __user *user_buf,
165 size_t count, loff_t *ppos) {
167 struct il_priv *il = file->private_data;
172 const size_t bufsz = 100 +
173 sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
174 buf = kzalloc(bufsz, GFP_KERNEL);
178 pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
179 for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
180 pos += scnprintf(buf + pos, bufsz - pos,
182 il_get_mgmt_string(cnt),
183 il->rx_stats.mgmt[cnt]);
185 pos += scnprintf(buf + pos, bufsz - pos, "Control:\n");
186 for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
187 pos += scnprintf(buf + pos, bufsz - pos,
189 il_get_ctrl_string(cnt),
190 il->rx_stats.ctrl[cnt]);
192 pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
193 pos += scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
194 il->rx_stats.data_cnt);
195 pos += scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
196 il->rx_stats.data_bytes);
198 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
203 #define BYTE1_MASK 0x000000ff;
204 #define BYTE2_MASK 0x0000ffff;
205 #define BYTE3_MASK 0x00ffffff;
206 static ssize_t il_dbgfs_sram_read(struct file *file,
207 char __user *user_buf,
208 size_t count, loff_t *ppos)
215 struct il_priv *il = file->private_data;
218 /* default is to dump the entire data segment */
219 if (!il->dbgfs_sram_offset && !il->dbgfs_sram_len) {
220 il->dbgfs_sram_offset = 0x800000;
221 if (il->ucode_type == UCODE_INIT)
222 il->dbgfs_sram_len = il->ucode_init_data.len;
224 il->dbgfs_sram_len = il->ucode_data.len;
226 bufsz = 30 + il->dbgfs_sram_len * sizeof(char) * 10;
227 buf = kmalloc(bufsz, GFP_KERNEL);
230 pos += scnprintf(buf + pos, bufsz - pos, "sram_len: 0x%x\n",
232 pos += scnprintf(buf + pos, bufsz - pos, "sram_offset: 0x%x\n",
233 il->dbgfs_sram_offset);
234 for (i = il->dbgfs_sram_len; i > 0; i -= 4) {
235 val = il_read_targ_mem(il, il->dbgfs_sram_offset + \
236 il->dbgfs_sram_len - i);
251 pos += scnprintf(buf + pos, bufsz - pos, "\n");
252 pos += scnprintf(buf + pos, bufsz - pos, "0x%08x ", val);
254 pos += scnprintf(buf + pos, bufsz - pos, "\n");
256 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
261 static ssize_t il_dbgfs_sram_write(struct file *file,
262 const char __user *user_buf,
263 size_t count, loff_t *ppos)
265 struct il_priv *il = file->private_data;
270 memset(buf, 0, sizeof(buf));
271 buf_size = min(count, sizeof(buf) - 1);
272 if (copy_from_user(buf, user_buf, buf_size))
275 if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
276 il->dbgfs_sram_offset = offset;
277 il->dbgfs_sram_len = len;
279 il->dbgfs_sram_offset = 0;
280 il->dbgfs_sram_len = 0;
287 il_dbgfs_stations_read(struct file *file, char __user *user_buf,
288 size_t count, loff_t *ppos)
290 struct il_priv *il = file->private_data;
291 struct il_station_entry *station;
292 int max_sta = il->hw_params.max_stations;
296 /* Add 30 for initial string */
297 const size_t bufsz = 30 + sizeof(char) * 500 * (il->num_stations);
299 buf = kmalloc(bufsz, GFP_KERNEL);
303 pos += scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n",
306 for (i = 0; i < max_sta; i++) {
307 station = &il->stations[i];
310 pos += scnprintf(buf + pos, bufsz - pos,
311 "station %d - addr: %pM, flags: %#x\n",
312 i, station->sta.sta.addr,
313 station->sta.station_flags_msk);
314 pos += scnprintf(buf + pos, bufsz - pos,
315 "TID\tseq_num\ttxq_id\tframes\ttfds\t");
316 pos += scnprintf(buf + pos, bufsz - pos,
317 "start_idx\tbitmap\t\t\trate_n_flags\n");
319 for (j = 0; j < MAX_TID_COUNT; j++) {
320 pos += scnprintf(buf + pos, bufsz - pos,
321 "%d:\t%#x\t%#x\t%u\t%u\t%u\t\t%#.16llx\t%#x",
322 j, station->tid[j].seq_number,
323 station->tid[j].agg.txq_id,
324 station->tid[j].agg.frame_count,
325 station->tid[j].tfds_in_queue,
326 station->tid[j].agg.start_idx,
327 station->tid[j].agg.bitmap,
328 station->tid[j].agg.rate_n_flags);
330 if (station->tid[j].agg.wait_for_ba)
331 pos += scnprintf(buf + pos, bufsz - pos,
333 pos += scnprintf(buf + pos, bufsz - pos, "\n");
336 pos += scnprintf(buf + pos, bufsz - pos, "\n");
339 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
344 static ssize_t il_dbgfs_nvm_read(struct file *file,
345 char __user *user_buf,
350 struct il_priv *il = file->private_data;
351 int pos = 0, ofs = 0, buf_size = 0;
355 size_t eeprom_len = il->cfg->base_params->eeprom_size;
356 buf_size = 4 * eeprom_len + 256;
358 if (eeprom_len % 16) {
359 IL_ERR("NVM size is not multiple of 16.\n");
365 IL_ERR("Invalid EEPROM memory\n");
369 /* 4 characters for byte 0xYY */
370 buf = kzalloc(buf_size, GFP_KERNEL);
372 IL_ERR("Can not allocate Buffer\n");
375 eeprom_ver = il_eeprom_query16(il, EEPROM_VERSION);
376 pos += scnprintf(buf + pos, buf_size - pos, "EEPROM "
377 "version: 0x%x\n", eeprom_ver);
378 for (ofs = 0 ; ofs < eeprom_len ; ofs += 16) {
379 pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x ", ofs);
380 hex_dump_to_buffer(ptr + ofs, 16 , 16, 2, buf + pos,
382 pos += strlen(buf + pos);
383 if (buf_size - pos > 0)
387 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
393 il_dbgfs_channels_read(struct file *file, char __user *user_buf,
394 size_t count, loff_t *ppos)
396 struct il_priv *il = file->private_data;
397 struct ieee80211_channel *channels = NULL;
398 const struct ieee80211_supported_band *supp_band = NULL;
399 int pos = 0, i, bufsz = PAGE_SIZE;
403 if (!test_bit(S_GEO_CONFIGURED, &il->status))
406 buf = kzalloc(bufsz, GFP_KERNEL);
408 IL_ERR("Can not allocate Buffer\n");
412 supp_band = il_get_hw_mode(il, IEEE80211_BAND_2GHZ);
414 channels = supp_band->channels;
416 pos += scnprintf(buf + pos, bufsz - pos,
417 "Displaying %d channels in 2.4GHz band 802.11bg):\n",
418 supp_band->n_channels);
420 for (i = 0; i < supp_band->n_channels; i++)
421 pos += scnprintf(buf + pos, bufsz - pos,
422 "%d: %ddBm: BSS%s%s, %s.\n",
423 channels[i].hw_value,
424 channels[i].max_power,
425 channels[i].flags & IEEE80211_CHAN_RADAR ?
426 " (IEEE 802.11h required)" : "",
427 ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
428 || (channels[i].flags &
429 IEEE80211_CHAN_RADAR)) ? "" :
432 IEEE80211_CHAN_PASSIVE_SCAN ?
433 "passive only" : "active/passive");
435 supp_band = il_get_hw_mode(il, IEEE80211_BAND_5GHZ);
437 channels = supp_band->channels;
439 pos += scnprintf(buf + pos, bufsz - pos,
440 "Displaying %d channels in 5.2GHz band (802.11a)\n",
441 supp_band->n_channels);
443 for (i = 0; i < supp_band->n_channels; i++)
444 pos += scnprintf(buf + pos, bufsz - pos,
445 "%d: %ddBm: BSS%s%s, %s.\n",
446 channels[i].hw_value,
447 channels[i].max_power,
448 channels[i].flags & IEEE80211_CHAN_RADAR ?
449 " (IEEE 802.11h required)" : "",
450 ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
451 || (channels[i].flags &
452 IEEE80211_CHAN_RADAR)) ? "" :
455 IEEE80211_CHAN_PASSIVE_SCAN ?
456 "passive only" : "active/passive");
458 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
463 static ssize_t il_dbgfs_status_read(struct file *file,
464 char __user *user_buf,
465 size_t count, loff_t *ppos) {
467 struct il_priv *il = file->private_data;
470 const size_t bufsz = sizeof(buf);
472 pos += scnprintf(buf + pos, bufsz - pos, "S_HCMD_ACTIVE:\t %d\n",
473 test_bit(S_HCMD_ACTIVE, &il->status));
474 pos += scnprintf(buf + pos, bufsz - pos, "S_INT_ENABLED:\t %d\n",
475 test_bit(S_INT_ENABLED, &il->status));
476 pos += scnprintf(buf + pos, bufsz - pos, "S_RF_KILL_HW:\t %d\n",
477 test_bit(S_RF_KILL_HW, &il->status));
478 pos += scnprintf(buf + pos, bufsz - pos, "S_CT_KILL:\t\t %d\n",
479 test_bit(S_CT_KILL, &il->status));
480 pos += scnprintf(buf + pos, bufsz - pos, "S_INIT:\t\t %d\n",
481 test_bit(S_INIT, &il->status));
482 pos += scnprintf(buf + pos, bufsz - pos, "S_ALIVE:\t\t %d\n",
483 test_bit(S_ALIVE, &il->status));
484 pos += scnprintf(buf + pos, bufsz - pos, "S_READY:\t\t %d\n",
485 test_bit(S_READY, &il->status));
486 pos += scnprintf(buf + pos, bufsz - pos, "S_TEMPERATURE:\t %d\n",
487 test_bit(S_TEMPERATURE, &il->status));
488 pos += scnprintf(buf + pos, bufsz - pos, "S_GEO_CONFIGURED:\t %d\n",
489 test_bit(S_GEO_CONFIGURED, &il->status));
490 pos += scnprintf(buf + pos, bufsz - pos, "S_EXIT_PENDING:\t %d\n",
491 test_bit(S_EXIT_PENDING, &il->status));
492 pos += scnprintf(buf + pos, bufsz - pos, "S_STATS:\t %d\n",
493 test_bit(S_STATS, &il->status));
494 pos += scnprintf(buf + pos, bufsz - pos, "S_SCANNING:\t %d\n",
495 test_bit(S_SCANNING, &il->status));
496 pos += scnprintf(buf + pos, bufsz - pos, "S_SCAN_ABORTING:\t %d\n",
497 test_bit(S_SCAN_ABORTING, &il->status));
498 pos += scnprintf(buf + pos, bufsz - pos, "S_SCAN_HW:\t\t %d\n",
499 test_bit(S_SCAN_HW, &il->status));
500 pos += scnprintf(buf + pos, bufsz - pos, "S_POWER_PMI:\t %d\n",
501 test_bit(S_POWER_PMI, &il->status));
502 pos += scnprintf(buf + pos, bufsz - pos, "S_FW_ERROR:\t %d\n",
503 test_bit(S_FW_ERROR, &il->status));
504 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
507 static ssize_t il_dbgfs_interrupt_read(struct file *file,
508 char __user *user_buf,
509 size_t count, loff_t *ppos) {
511 struct il_priv *il = file->private_data;
515 int bufsz = 24 * 64; /* 24 items * 64 char per item */
518 buf = kzalloc(bufsz, GFP_KERNEL);
520 IL_ERR("Can not allocate Buffer\n");
524 pos += scnprintf(buf + pos, bufsz - pos,
525 "Interrupt Statistics Report:\n");
527 pos += scnprintf(buf + pos, bufsz - pos, "HW Error:\t\t\t %u\n",
529 pos += scnprintf(buf + pos, bufsz - pos, "SW Error:\t\t\t %u\n",
531 if (il->isr_stats.sw || il->isr_stats.hw) {
532 pos += scnprintf(buf + pos, bufsz - pos,
533 "\tLast Restarting Code: 0x%X\n",
534 il->isr_stats.err_code);
536 #ifdef CONFIG_IWLEGACY_DEBUG
537 pos += scnprintf(buf + pos, bufsz - pos, "Frame transmitted:\t\t %u\n",
539 pos += scnprintf(buf + pos, bufsz - pos, "Alive interrupt:\t\t %u\n",
540 il->isr_stats.alive);
542 pos += scnprintf(buf + pos, bufsz - pos,
543 "HW RF KILL switch toggled:\t %u\n",
544 il->isr_stats.rfkill);
546 pos += scnprintf(buf + pos, bufsz - pos, "CT KILL:\t\t\t %u\n",
547 il->isr_stats.ctkill);
549 pos += scnprintf(buf + pos, bufsz - pos, "Wakeup Interrupt:\t\t %u\n",
550 il->isr_stats.wakeup);
552 pos += scnprintf(buf + pos, bufsz - pos,
553 "Rx command responses:\t\t %u\n",
555 for (cnt = 0; cnt < IL_CN_MAX; cnt++) {
556 if (il->isr_stats.handlers[cnt] > 0)
557 pos += scnprintf(buf + pos, bufsz - pos,
558 "\tRx handler[%36s]:\t\t %u\n",
559 il_get_cmd_string(cnt),
560 il->isr_stats.handlers[cnt]);
563 pos += scnprintf(buf + pos, bufsz - pos, "Tx/FH interrupt:\t\t %u\n",
566 pos += scnprintf(buf + pos, bufsz - pos, "Unexpected INTA:\t\t %u\n",
567 il->isr_stats.unhandled);
569 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
574 static ssize_t il_dbgfs_interrupt_write(struct file *file,
575 const char __user *user_buf,
576 size_t count, loff_t *ppos)
578 struct il_priv *il = file->private_data;
583 memset(buf, 0, sizeof(buf));
584 buf_size = min(count, sizeof(buf) - 1);
585 if (copy_from_user(buf, user_buf, buf_size))
587 if (sscanf(buf, "%x", &reset_flag) != 1)
590 il_clear_isr_stats(il);
596 il_dbgfs_qos_read(struct file *file, char __user *user_buf,
597 size_t count, loff_t *ppos)
599 struct il_priv *il = file->private_data;
600 struct il_rxon_context *ctx = &il->ctx;
603 const size_t bufsz = sizeof(buf);
605 pos += scnprintf(buf + pos, bufsz - pos, "context %d:\n",
607 for (i = 0; i < AC_NUM; i++) {
608 pos += scnprintf(buf + pos, bufsz - pos,
609 "\tcw_min\tcw_max\taifsn\ttxop\n");
610 pos += scnprintf(buf + pos, bufsz - pos,
611 "AC[%d]\t%u\t%u\t%u\t%u\n", i,
612 ctx->qos_data.def_qos_parm.ac[i].cw_min,
613 ctx->qos_data.def_qos_parm.ac[i].cw_max,
614 ctx->qos_data.def_qos_parm.ac[i].aifsn,
615 ctx->qos_data.def_qos_parm.ac[i].edca_txop);
618 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
621 static ssize_t il_dbgfs_disable_ht40_write(struct file *file,
622 const char __user *user_buf,
623 size_t count, loff_t *ppos)
625 struct il_priv *il = file->private_data;
630 memset(buf, 0, sizeof(buf));
631 buf_size = min(count, sizeof(buf) - 1);
632 if (copy_from_user(buf, user_buf, buf_size))
634 if (sscanf(buf, "%d", &ht40) != 1)
636 if (!il_is_any_associated(il))
637 il->disable_ht40 = ht40 ? true : false;
639 IL_ERR("Sta associated with AP - "
640 "Change to 40MHz channel support is not allowed\n");
647 static ssize_t il_dbgfs_disable_ht40_read(struct file *file,
648 char __user *user_buf,
649 size_t count, loff_t *ppos)
651 struct il_priv *il = file->private_data;
654 const size_t bufsz = sizeof(buf);
656 pos += scnprintf(buf + pos, bufsz - pos,
657 "11n 40MHz Mode: %s\n",
658 il->disable_ht40 ? "Disabled" : "Enabled");
659 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
662 DEBUGFS_READ_WRITE_FILE_OPS(sram);
663 DEBUGFS_READ_FILE_OPS(nvm);
664 DEBUGFS_READ_FILE_OPS(stations);
665 DEBUGFS_READ_FILE_OPS(channels);
666 DEBUGFS_READ_FILE_OPS(status);
667 DEBUGFS_READ_WRITE_FILE_OPS(interrupt);
668 DEBUGFS_READ_FILE_OPS(qos);
669 DEBUGFS_READ_WRITE_FILE_OPS(disable_ht40);
671 static ssize_t il_dbgfs_traffic_log_read(struct file *file,
672 char __user *user_buf,
673 size_t count, loff_t *ppos)
675 struct il_priv *il = file->private_data;
676 int pos = 0, ofs = 0;
678 struct il_tx_queue *txq;
680 struct il_rx_queue *rxq = &il->rxq;
682 int bufsz = ((IL_TRAFFIC_ENTRIES * IL_TRAFFIC_ENTRY_SIZE * 64) * 2) +
683 (il->cfg->base_params->num_of_queues * 32 * 8) + 400;
688 IL_ERR("txq not ready\n");
691 buf = kzalloc(bufsz, GFP_KERNEL);
693 IL_ERR("Can not allocate buffer\n");
696 pos += scnprintf(buf + pos, bufsz - pos, "Tx Queue\n");
697 for (cnt = 0; cnt < il->hw_params.max_txq_num; cnt++) {
700 pos += scnprintf(buf + pos, bufsz - pos,
701 "q[%d]: read_ptr: %u, write_ptr: %u\n",
702 cnt, q->read_ptr, q->write_ptr);
704 if (il->tx_traffic && (il_debug_level & IL_DL_TX)) {
705 ptr = il->tx_traffic;
706 pos += scnprintf(buf + pos, bufsz - pos,
707 "Tx Traffic idx: %u\n", il->tx_traffic_idx);
708 for (cnt = 0, ofs = 0; cnt < IL_TRAFFIC_ENTRIES; cnt++) {
709 for (entry = 0; entry < IL_TRAFFIC_ENTRY_SIZE / 16;
710 entry++, ofs += 16) {
711 pos += scnprintf(buf + pos, bufsz - pos,
713 hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
714 buf + pos, bufsz - pos, 0);
715 pos += strlen(buf + pos);
722 pos += scnprintf(buf + pos, bufsz - pos, "Rx Queue\n");
723 pos += scnprintf(buf + pos, bufsz - pos,
724 "read: %u, write: %u\n",
725 rxq->read, rxq->write);
727 if (il->rx_traffic && (il_debug_level & IL_DL_RX)) {
728 ptr = il->rx_traffic;
729 pos += scnprintf(buf + pos, bufsz - pos,
730 "Rx Traffic idx: %u\n", il->rx_traffic_idx);
731 for (cnt = 0, ofs = 0; cnt < IL_TRAFFIC_ENTRIES; cnt++) {
732 for (entry = 0; entry < IL_TRAFFIC_ENTRY_SIZE / 16;
733 entry++, ofs += 16) {
734 pos += scnprintf(buf + pos, bufsz - pos,
736 hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
737 buf + pos, bufsz - pos, 0);
738 pos += strlen(buf + pos);
745 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
750 static ssize_t il_dbgfs_traffic_log_write(struct file *file,
751 const char __user *user_buf,
752 size_t count, loff_t *ppos)
754 struct il_priv *il = file->private_data;
759 memset(buf, 0, sizeof(buf));
760 buf_size = min(count, sizeof(buf) - 1);
761 if (copy_from_user(buf, user_buf, buf_size))
763 if (sscanf(buf, "%d", &traffic_log) != 1)
765 if (traffic_log == 0)
766 il_reset_traffic_log(il);
771 static ssize_t il_dbgfs_tx_queue_read(struct file *file,
772 char __user *user_buf,
773 size_t count, loff_t *ppos) {
775 struct il_priv *il = file->private_data;
776 struct il_tx_queue *txq;
782 const size_t bufsz = sizeof(char) * 64 *
783 il->cfg->base_params->num_of_queues;
786 IL_ERR("txq not ready\n");
789 buf = kzalloc(bufsz, GFP_KERNEL);
793 for (cnt = 0; cnt < il->hw_params.max_txq_num; cnt++) {
796 pos += scnprintf(buf + pos, bufsz - pos,
797 "hwq %.2d: read=%u write=%u stop=%d"
798 " swq_id=%#.2x (ac %d/hwq %d)\n",
799 cnt, q->read_ptr, q->write_ptr,
800 !!test_bit(cnt, il->queue_stopped),
801 txq->swq_id, txq->swq_id & 3,
802 (txq->swq_id >> 2) & 0x1f);
805 /* for the ACs, display the stop count too */
806 pos += scnprintf(buf + pos, bufsz - pos,
808 atomic_read(&il->queue_stop_count[cnt]));
810 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
815 static ssize_t il_dbgfs_rx_queue_read(struct file *file,
816 char __user *user_buf,
817 size_t count, loff_t *ppos) {
819 struct il_priv *il = file->private_data;
820 struct il_rx_queue *rxq = &il->rxq;
823 const size_t bufsz = sizeof(buf);
825 pos += scnprintf(buf + pos, bufsz - pos, "read: %u\n",
827 pos += scnprintf(buf + pos, bufsz - pos, "write: %u\n",
829 pos += scnprintf(buf + pos, bufsz - pos, "free_count: %u\n",
832 pos += scnprintf(buf + pos, bufsz - pos, "closed_rb_num: %u\n",
833 le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF);
835 pos += scnprintf(buf + pos, bufsz - pos,
836 "closed_rb_num: Not Allocated\n");
838 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
841 static ssize_t il_dbgfs_ucode_rx_stats_read(struct file *file,
842 char __user *user_buf,
843 size_t count, loff_t *ppos)
845 struct il_priv *il = file->private_data;
846 return il->cfg->ops->lib->debugfs_ops.rx_stats_read(file,
847 user_buf, count, ppos);
850 static ssize_t il_dbgfs_ucode_tx_stats_read(struct file *file,
851 char __user *user_buf,
852 size_t count, loff_t *ppos)
854 struct il_priv *il = file->private_data;
855 return il->cfg->ops->lib->debugfs_ops.tx_stats_read(file,
856 user_buf, count, ppos);
859 static ssize_t il_dbgfs_ucode_general_stats_read(struct file *file,
860 char __user *user_buf,
861 size_t count, loff_t *ppos)
863 struct il_priv *il = file->private_data;
864 return il->cfg->ops->lib->debugfs_ops.general_stats_read(file,
865 user_buf, count, ppos);
868 static ssize_t il_dbgfs_sensitivity_read(struct file *file,
869 char __user *user_buf,
870 size_t count, loff_t *ppos) {
872 struct il_priv *il = file->private_data;
876 int bufsz = sizeof(struct il_sensitivity_data) * 4 + 100;
878 struct il_sensitivity_data *data;
880 data = &il->sensitivity_data;
881 buf = kzalloc(bufsz, GFP_KERNEL);
883 IL_ERR("Can not allocate Buffer\n");
887 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm:\t\t\t %u\n",
888 data->auto_corr_ofdm);
889 pos += scnprintf(buf + pos, bufsz - pos,
890 "auto_corr_ofdm_mrc:\t\t %u\n",
891 data->auto_corr_ofdm_mrc);
892 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_x1:\t\t %u\n",
893 data->auto_corr_ofdm_x1);
894 pos += scnprintf(buf + pos, bufsz - pos,
895 "auto_corr_ofdm_mrc_x1:\t\t %u\n",
896 data->auto_corr_ofdm_mrc_x1);
897 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck:\t\t\t %u\n",
898 data->auto_corr_cck);
899 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck_mrc:\t\t %u\n",
900 data->auto_corr_cck_mrc);
901 pos += scnprintf(buf + pos, bufsz - pos,
902 "last_bad_plcp_cnt_ofdm:\t\t %u\n",
903 data->last_bad_plcp_cnt_ofdm);
904 pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_ofdm:\t\t %u\n",
905 data->last_fa_cnt_ofdm);
906 pos += scnprintf(buf + pos, bufsz - pos,
907 "last_bad_plcp_cnt_cck:\t\t %u\n",
908 data->last_bad_plcp_cnt_cck);
909 pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_cck:\t\t %u\n",
910 data->last_fa_cnt_cck);
911 pos += scnprintf(buf + pos, bufsz - pos, "nrg_curr_state:\t\t\t %u\n",
912 data->nrg_curr_state);
913 pos += scnprintf(buf + pos, bufsz - pos, "nrg_prev_state:\t\t\t %u\n",
914 data->nrg_prev_state);
915 pos += scnprintf(buf + pos, bufsz - pos, "nrg_value:\t\t\t");
916 for (cnt = 0; cnt < 10; cnt++) {
917 pos += scnprintf(buf + pos, bufsz - pos, " %u",
918 data->nrg_value[cnt]);
920 pos += scnprintf(buf + pos, bufsz - pos, "\n");
921 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_rssi:\t\t");
922 for (cnt = 0; cnt < NRG_NUM_PREV_STAT_L; cnt++) {
923 pos += scnprintf(buf + pos, bufsz - pos, " %u",
924 data->nrg_silence_rssi[cnt]);
926 pos += scnprintf(buf + pos, bufsz - pos, "\n");
927 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_ref:\t\t %u\n",
928 data->nrg_silence_ref);
929 pos += scnprintf(buf + pos, bufsz - pos, "nrg_energy_idx:\t\t\t %u\n",
930 data->nrg_energy_idx);
931 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_idx:\t\t %u\n",
932 data->nrg_silence_idx);
933 pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_cck:\t\t\t %u\n",
935 pos += scnprintf(buf + pos, bufsz - pos,
936 "nrg_auto_corr_silence_diff:\t %u\n",
937 data->nrg_auto_corr_silence_diff);
938 pos += scnprintf(buf + pos, bufsz - pos, "num_in_cck_no_fa:\t\t %u\n",
939 data->num_in_cck_no_fa);
940 pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_ofdm:\t\t\t %u\n",
943 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
949 static ssize_t il_dbgfs_chain_noise_read(struct file *file,
950 char __user *user_buf,
951 size_t count, loff_t *ppos) {
953 struct il_priv *il = file->private_data;
957 int bufsz = sizeof(struct il_chain_noise_data) * 4 + 100;
959 struct il_chain_noise_data *data;
961 data = &il->chain_noise_data;
962 buf = kzalloc(bufsz, GFP_KERNEL);
964 IL_ERR("Can not allocate Buffer\n");
968 pos += scnprintf(buf + pos, bufsz - pos, "active_chains:\t\t\t %u\n",
969 data->active_chains);
970 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_a:\t\t\t %u\n",
971 data->chain_noise_a);
972 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_b:\t\t\t %u\n",
973 data->chain_noise_b);
974 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_c:\t\t\t %u\n",
975 data->chain_noise_c);
976 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_a:\t\t\t %u\n",
977 data->chain_signal_a);
978 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_b:\t\t\t %u\n",
979 data->chain_signal_b);
980 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_c:\t\t\t %u\n",
981 data->chain_signal_c);
982 pos += scnprintf(buf + pos, bufsz - pos, "beacon_count:\t\t\t %u\n",
985 pos += scnprintf(buf + pos, bufsz - pos, "disconn_array:\t\t\t");
986 for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
987 pos += scnprintf(buf + pos, bufsz - pos, " %u",
988 data->disconn_array[cnt]);
990 pos += scnprintf(buf + pos, bufsz - pos, "\n");
991 pos += scnprintf(buf + pos, bufsz - pos, "delta_gain_code:\t\t");
992 for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
993 pos += scnprintf(buf + pos, bufsz - pos, " %u",
994 data->delta_gain_code[cnt]);
996 pos += scnprintf(buf + pos, bufsz - pos, "\n");
997 pos += scnprintf(buf + pos, bufsz - pos, "radio_write:\t\t\t %u\n",
999 pos += scnprintf(buf + pos, bufsz - pos, "state:\t\t\t\t %u\n",
1002 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1007 static ssize_t il_dbgfs_power_save_status_read(struct file *file,
1008 char __user *user_buf,
1009 size_t count, loff_t *ppos)
1011 struct il_priv *il = file->private_data;
1014 const size_t bufsz = sizeof(buf);
1017 pwrsave_status = _il_rd(il, CSR_GP_CNTRL) &
1018 CSR_GP_REG_POWER_SAVE_STATUS_MSK;
1020 pos += scnprintf(buf + pos, bufsz - pos, "Power Save Status: ");
1021 pos += scnprintf(buf + pos, bufsz - pos, "%s\n",
1022 (pwrsave_status == CSR_GP_REG_NO_POWER_SAVE) ? "none" :
1023 (pwrsave_status == CSR_GP_REG_MAC_POWER_SAVE) ? "MAC" :
1024 (pwrsave_status == CSR_GP_REG_PHY_POWER_SAVE) ? "PHY" :
1027 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1030 static ssize_t il_dbgfs_clear_ucode_stats_write(struct file *file,
1031 const char __user *user_buf,
1032 size_t count, loff_t *ppos)
1034 struct il_priv *il = file->private_data;
1039 memset(buf, 0, sizeof(buf));
1040 buf_size = min(count, sizeof(buf) - 1);
1041 if (copy_from_user(buf, user_buf, buf_size))
1043 if (sscanf(buf, "%d", &clear) != 1)
1046 /* make request to uCode to retrieve stats information */
1047 mutex_lock(&il->mutex);
1048 il_send_stats_request(il, CMD_SYNC, true);
1049 mutex_unlock(&il->mutex);
1054 static ssize_t il_dbgfs_rxon_flags_read(struct file *file,
1055 char __user *user_buf,
1056 size_t count, loff_t *ppos) {
1058 struct il_priv *il = file->private_data;
1062 len = sprintf(buf, "0x%04X\n",
1063 le32_to_cpu(il->ctx.active.flags));
1064 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1067 static ssize_t il_dbgfs_rxon_filter_flags_read(struct file *file,
1068 char __user *user_buf,
1069 size_t count, loff_t *ppos) {
1071 struct il_priv *il = file->private_data;
1075 len = sprintf(buf, "0x%04X\n",
1076 le32_to_cpu(il->ctx.active.filter_flags));
1077 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1080 static ssize_t il_dbgfs_fh_reg_read(struct file *file,
1081 char __user *user_buf,
1082 size_t count, loff_t *ppos)
1084 struct il_priv *il = file->private_data;
1087 ssize_t ret = -EFAULT;
1089 if (il->cfg->ops->lib->dump_fh) {
1090 ret = pos = il->cfg->ops->lib->dump_fh(il, &buf, true);
1092 ret = simple_read_from_buffer(user_buf,
1093 count, ppos, buf, pos);
1101 static ssize_t il_dbgfs_missed_beacon_read(struct file *file,
1102 char __user *user_buf,
1103 size_t count, loff_t *ppos) {
1105 struct il_priv *il = file->private_data;
1108 const size_t bufsz = sizeof(buf);
1110 pos += scnprintf(buf + pos, bufsz - pos, "%d\n",
1111 il->missed_beacon_threshold);
1113 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1116 static ssize_t il_dbgfs_missed_beacon_write(struct file *file,
1117 const char __user *user_buf,
1118 size_t count, loff_t *ppos)
1120 struct il_priv *il = file->private_data;
1125 memset(buf, 0, sizeof(buf));
1126 buf_size = min(count, sizeof(buf) - 1);
1127 if (copy_from_user(buf, user_buf, buf_size))
1129 if (sscanf(buf, "%d", &missed) != 1)
1132 if (missed < IL_MISSED_BEACON_THRESHOLD_MIN ||
1133 missed > IL_MISSED_BEACON_THRESHOLD_MAX)
1134 il->missed_beacon_threshold =
1135 IL_MISSED_BEACON_THRESHOLD_DEF;
1137 il->missed_beacon_threshold = missed;
1142 static ssize_t il_dbgfs_force_reset_read(struct file *file,
1143 char __user *user_buf,
1144 size_t count, loff_t *ppos) {
1146 struct il_priv *il = file->private_data;
1149 const size_t bufsz = sizeof(buf);
1150 struct il_force_reset *force_reset;
1152 force_reset = &il->force_reset;
1154 pos += scnprintf(buf + pos, bufsz - pos,
1155 "\tnumber of reset request: %d\n",
1156 force_reset->reset_request_count);
1157 pos += scnprintf(buf + pos, bufsz - pos,
1158 "\tnumber of reset request success: %d\n",
1159 force_reset->reset_success_count);
1160 pos += scnprintf(buf + pos, bufsz - pos,
1161 "\tnumber of reset request reject: %d\n",
1162 force_reset->reset_reject_count);
1163 pos += scnprintf(buf + pos, bufsz - pos,
1164 "\treset duration: %lu\n",
1165 force_reset->reset_duration);
1167 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1170 static ssize_t il_dbgfs_force_reset_write(struct file *file,
1171 const char __user *user_buf,
1172 size_t count, loff_t *ppos) {
1175 struct il_priv *il = file->private_data;
1177 ret = il_force_reset(il, true);
1179 return ret ? ret : count;
1182 static ssize_t il_dbgfs_wd_timeout_write(struct file *file,
1183 const char __user *user_buf,
1184 size_t count, loff_t *ppos) {
1186 struct il_priv *il = file->private_data;
1191 memset(buf, 0, sizeof(buf));
1192 buf_size = min(count, sizeof(buf) - 1);
1193 if (copy_from_user(buf, user_buf, buf_size))
1195 if (sscanf(buf, "%d", &timeout) != 1)
1197 if (timeout < 0 || timeout > IL_MAX_WD_TIMEOUT)
1198 timeout = IL_DEF_WD_TIMEOUT;
1200 il->cfg->base_params->wd_timeout = timeout;
1201 il_setup_watchdog(il);
1205 DEBUGFS_READ_FILE_OPS(rx_stats);
1206 DEBUGFS_READ_FILE_OPS(tx_stats);
1207 DEBUGFS_READ_WRITE_FILE_OPS(traffic_log);
1208 DEBUGFS_READ_FILE_OPS(rx_queue);
1209 DEBUGFS_READ_FILE_OPS(tx_queue);
1210 DEBUGFS_READ_FILE_OPS(ucode_rx_stats);
1211 DEBUGFS_READ_FILE_OPS(ucode_tx_stats);
1212 DEBUGFS_READ_FILE_OPS(ucode_general_stats);
1213 DEBUGFS_READ_FILE_OPS(sensitivity);
1214 DEBUGFS_READ_FILE_OPS(chain_noise);
1215 DEBUGFS_READ_FILE_OPS(power_save_status);
1216 DEBUGFS_WRITE_FILE_OPS(clear_ucode_stats);
1217 DEBUGFS_WRITE_FILE_OPS(clear_traffic_stats);
1218 DEBUGFS_READ_FILE_OPS(fh_reg);
1219 DEBUGFS_READ_WRITE_FILE_OPS(missed_beacon);
1220 DEBUGFS_READ_WRITE_FILE_OPS(force_reset);
1221 DEBUGFS_READ_FILE_OPS(rxon_flags);
1222 DEBUGFS_READ_FILE_OPS(rxon_filter_flags);
1223 DEBUGFS_WRITE_FILE_OPS(wd_timeout);
1226 * Create the debugfs files and directories
1229 int il_dbgfs_register(struct il_priv *il, const char *name)
1231 struct dentry *phyd = il->hw->wiphy->debugfsdir;
1232 struct dentry *dir_drv, *dir_data, *dir_rf, *dir_debug;
1234 dir_drv = debugfs_create_dir(name, phyd);
1238 il->debugfs_dir = dir_drv;
1240 dir_data = debugfs_create_dir("data", dir_drv);
1243 dir_rf = debugfs_create_dir("rf", dir_drv);
1246 dir_debug = debugfs_create_dir("debug", dir_drv);
1250 DEBUGFS_ADD_FILE(nvm, dir_data, S_IRUSR);
1251 DEBUGFS_ADD_FILE(sram, dir_data, S_IWUSR | S_IRUSR);
1252 DEBUGFS_ADD_FILE(stations, dir_data, S_IRUSR);
1253 DEBUGFS_ADD_FILE(channels, dir_data, S_IRUSR);
1254 DEBUGFS_ADD_FILE(status, dir_data, S_IRUSR);
1255 DEBUGFS_ADD_FILE(interrupt, dir_data, S_IWUSR | S_IRUSR);
1256 DEBUGFS_ADD_FILE(qos, dir_data, S_IRUSR);
1257 DEBUGFS_ADD_FILE(disable_ht40, dir_data, S_IWUSR | S_IRUSR);
1258 DEBUGFS_ADD_FILE(rx_stats, dir_debug, S_IRUSR);
1259 DEBUGFS_ADD_FILE(tx_stats, dir_debug, S_IRUSR);
1260 DEBUGFS_ADD_FILE(traffic_log, dir_debug, S_IWUSR | S_IRUSR);
1261 DEBUGFS_ADD_FILE(rx_queue, dir_debug, S_IRUSR);
1262 DEBUGFS_ADD_FILE(tx_queue, dir_debug, S_IRUSR);
1263 DEBUGFS_ADD_FILE(power_save_status, dir_debug, S_IRUSR);
1264 DEBUGFS_ADD_FILE(clear_ucode_stats, dir_debug, S_IWUSR);
1265 DEBUGFS_ADD_FILE(clear_traffic_stats, dir_debug, S_IWUSR);
1266 DEBUGFS_ADD_FILE(fh_reg, dir_debug, S_IRUSR);
1267 DEBUGFS_ADD_FILE(missed_beacon, dir_debug, S_IWUSR);
1268 DEBUGFS_ADD_FILE(force_reset, dir_debug, S_IWUSR | S_IRUSR);
1269 DEBUGFS_ADD_FILE(ucode_rx_stats, dir_debug, S_IRUSR);
1270 DEBUGFS_ADD_FILE(ucode_tx_stats, dir_debug, S_IRUSR);
1271 DEBUGFS_ADD_FILE(ucode_general_stats, dir_debug, S_IRUSR);
1273 if (il->cfg->base_params->sensitivity_calib_by_driver)
1274 DEBUGFS_ADD_FILE(sensitivity, dir_debug, S_IRUSR);
1275 if (il->cfg->base_params->chain_noise_calib_by_driver)
1276 DEBUGFS_ADD_FILE(chain_noise, dir_debug, S_IRUSR);
1277 DEBUGFS_ADD_FILE(rxon_flags, dir_debug, S_IWUSR);
1278 DEBUGFS_ADD_FILE(rxon_filter_flags, dir_debug, S_IWUSR);
1279 DEBUGFS_ADD_FILE(wd_timeout, dir_debug, S_IWUSR);
1280 if (il->cfg->base_params->sensitivity_calib_by_driver)
1281 DEBUGFS_ADD_BOOL(disable_sensitivity, dir_rf,
1282 &il->disable_sens_cal);
1283 if (il->cfg->base_params->chain_noise_calib_by_driver)
1284 DEBUGFS_ADD_BOOL(disable_chain_noise, dir_rf,
1285 &il->disable_chain_noise_cal);
1286 DEBUGFS_ADD_BOOL(disable_tx_power, dir_rf,
1287 &il->disable_tx_power_cal);
1291 IL_ERR("Can't create the debugfs directory\n");
1292 il_dbgfs_unregister(il);
1295 EXPORT_SYMBOL(il_dbgfs_register);
1298 * Remove the debugfs files and directories
1301 void il_dbgfs_unregister(struct il_priv *il)
1303 if (!il->debugfs_dir)
1306 debugfs_remove_recursive(il->debugfs_dir);
1307 il->debugfs_dir = NULL;
1309 EXPORT_SYMBOL(il_dbgfs_unregister);