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 *****************************************************************************/
28 #include <linux/ieee80211.h>
29 #include <net/mac80211.h>
33 #include "iwl-debug.h"
36 #include "iwl-calib.h"
38 /* create and remove of files */
39 #define DEBUGFS_ADD_FILE(name, parent, mode) do { \
40 if (!debugfs_create_file(#name, mode, parent, priv, \
41 &iwl_dbgfs_##name##_ops)) \
45 #define DEBUGFS_ADD_BOOL(name, parent, ptr) do { \
46 struct dentry *__tmp; \
47 __tmp = debugfs_create_bool(#name, S_IWUSR | S_IRUSR, \
49 if (IS_ERR(__tmp) || !__tmp) \
53 #define DEBUGFS_ADD_X32(name, parent, ptr) do { \
54 struct dentry *__tmp; \
55 __tmp = debugfs_create_x32(#name, S_IWUSR | S_IRUSR, \
57 if (IS_ERR(__tmp) || !__tmp) \
62 #define DEBUGFS_READ_FUNC(name) \
63 static ssize_t iwl_dbgfs_##name##_read(struct file *file, \
64 char __user *user_buf, \
65 size_t count, loff_t *ppos);
67 #define DEBUGFS_WRITE_FUNC(name) \
68 static ssize_t iwl_dbgfs_##name##_write(struct file *file, \
69 const char __user *user_buf, \
70 size_t count, loff_t *ppos);
73 static int iwl_dbgfs_open_file_generic(struct inode *inode, struct file *file)
75 file->private_data = inode->i_private;
79 #define DEBUGFS_READ_FILE_OPS(name) \
80 DEBUGFS_READ_FUNC(name); \
81 static const struct file_operations iwl_dbgfs_##name##_ops = { \
82 .read = iwl_dbgfs_##name##_read, \
83 .open = iwl_dbgfs_open_file_generic, \
86 #define DEBUGFS_WRITE_FILE_OPS(name) \
87 DEBUGFS_WRITE_FUNC(name); \
88 static const struct file_operations iwl_dbgfs_##name##_ops = { \
89 .write = iwl_dbgfs_##name##_write, \
90 .open = iwl_dbgfs_open_file_generic, \
94 #define DEBUGFS_READ_WRITE_FILE_OPS(name) \
95 DEBUGFS_READ_FUNC(name); \
96 DEBUGFS_WRITE_FUNC(name); \
97 static const struct file_operations iwl_dbgfs_##name##_ops = { \
98 .write = iwl_dbgfs_##name##_write, \
99 .read = iwl_dbgfs_##name##_read, \
100 .open = iwl_dbgfs_open_file_generic, \
103 int iwl_dbgfs_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
107 p += scnprintf(buf + p, bufsz - p, "Statistics Flag(0x%X):\n",
108 le32_to_cpu(priv->statistics.flag));
109 if (le32_to_cpu(priv->statistics.flag) & UCODE_STATISTICS_CLEAR_MSK)
110 p += scnprintf(buf + p, bufsz - p,
111 "\tStatistics have been cleared\n");
112 p += scnprintf(buf + p, bufsz - p, "\tOperational Frequency: %s\n",
113 (le32_to_cpu(priv->statistics.flag) &
114 UCODE_STATISTICS_FREQUENCY_MSK)
115 ? "2.4 GHz" : "5.2 GHz");
116 p += scnprintf(buf + p, bufsz - p, "\tTGj Narrow Band: %s\n",
117 (le32_to_cpu(priv->statistics.flag) &
118 UCODE_STATISTICS_NARROW_BAND_MSK)
119 ? "enabled" : "disabled");
122 EXPORT_SYMBOL(iwl_dbgfs_statistics_flag);
124 static ssize_t iwl_dbgfs_tx_statistics_read(struct file *file,
125 char __user *user_buf,
126 size_t count, loff_t *ppos) {
128 struct iwl_priv *priv = file->private_data;
134 const size_t bufsz = 100 +
135 sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
136 buf = kzalloc(bufsz, GFP_KERNEL);
139 pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
140 for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
141 pos += scnprintf(buf + pos, bufsz - pos,
143 get_mgmt_string(cnt),
144 priv->tx_stats.mgmt[cnt]);
146 pos += scnprintf(buf + pos, bufsz - pos, "Control\n");
147 for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
148 pos += scnprintf(buf + pos, bufsz - pos,
150 get_ctrl_string(cnt),
151 priv->tx_stats.ctrl[cnt]);
153 pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
154 pos += scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
155 priv->tx_stats.data_cnt);
156 pos += scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
157 priv->tx_stats.data_bytes);
158 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
163 static ssize_t iwl_dbgfs_clear_traffic_statistics_write(struct file *file,
164 const char __user *user_buf,
165 size_t count, loff_t *ppos)
167 struct iwl_priv *priv = file->private_data;
172 memset(buf, 0, sizeof(buf));
173 buf_size = min(count, sizeof(buf) - 1);
174 if (copy_from_user(buf, user_buf, buf_size))
176 if (sscanf(buf, "%x", &clear_flag) != 1)
178 iwl_clear_traffic_stats(priv);
183 static ssize_t iwl_dbgfs_rx_statistics_read(struct file *file,
184 char __user *user_buf,
185 size_t count, loff_t *ppos) {
187 struct iwl_priv *priv = file->private_data;
192 const size_t bufsz = 100 +
193 sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
194 buf = kzalloc(bufsz, GFP_KERNEL);
198 pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
199 for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
200 pos += scnprintf(buf + pos, bufsz - pos,
202 get_mgmt_string(cnt),
203 priv->rx_stats.mgmt[cnt]);
205 pos += scnprintf(buf + pos, bufsz - pos, "Control:\n");
206 for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
207 pos += scnprintf(buf + pos, bufsz - pos,
209 get_ctrl_string(cnt),
210 priv->rx_stats.ctrl[cnt]);
212 pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
213 pos += scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
214 priv->rx_stats.data_cnt);
215 pos += scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
216 priv->rx_stats.data_bytes);
218 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
223 #define BYTE1_MASK 0x000000ff;
224 #define BYTE2_MASK 0x0000ffff;
225 #define BYTE3_MASK 0x00ffffff;
226 static ssize_t iwl_dbgfs_sram_read(struct file *file,
227 char __user *user_buf,
228 size_t count, loff_t *ppos)
235 struct iwl_priv *priv = file->private_data;
238 /* default is to dump the entire data segment */
239 if (!priv->dbgfs_sram_offset && !priv->dbgfs_sram_len) {
240 priv->dbgfs_sram_offset = 0x800000;
241 if (priv->ucode_type == UCODE_INIT)
242 priv->dbgfs_sram_len = priv->ucode_init_data.len;
244 priv->dbgfs_sram_len = priv->ucode_data.len;
246 bufsz = 30 + priv->dbgfs_sram_len * sizeof(char) * 10;
247 buf = kmalloc(bufsz, GFP_KERNEL);
250 pos += scnprintf(buf + pos, bufsz - pos, "sram_len: 0x%x\n",
251 priv->dbgfs_sram_len);
252 pos += scnprintf(buf + pos, bufsz - pos, "sram_offset: 0x%x\n",
253 priv->dbgfs_sram_offset);
254 for (i = priv->dbgfs_sram_len; i > 0; i -= 4) {
255 val = iwl_read_targ_mem(priv, priv->dbgfs_sram_offset + \
256 priv->dbgfs_sram_len - i);
271 pos += scnprintf(buf + pos, bufsz - pos, "\n");
272 pos += scnprintf(buf + pos, bufsz - pos, "0x%08x ", val);
274 pos += scnprintf(buf + pos, bufsz - pos, "\n");
276 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
281 static ssize_t iwl_dbgfs_sram_write(struct file *file,
282 const char __user *user_buf,
283 size_t count, loff_t *ppos)
285 struct iwl_priv *priv = file->private_data;
290 memset(buf, 0, sizeof(buf));
291 buf_size = min(count, sizeof(buf) - 1);
292 if (copy_from_user(buf, user_buf, buf_size))
295 if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
296 priv->dbgfs_sram_offset = offset;
297 priv->dbgfs_sram_len = len;
299 priv->dbgfs_sram_offset = 0;
300 priv->dbgfs_sram_len = 0;
306 static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
307 size_t count, loff_t *ppos)
309 struct iwl_priv *priv = file->private_data;
310 struct iwl_station_entry *station;
311 int max_sta = priv->hw_params.max_stations;
315 /* Add 30 for initial string */
316 const size_t bufsz = 30 + sizeof(char) * 500 * (priv->num_stations);
318 buf = kmalloc(bufsz, GFP_KERNEL);
322 pos += scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n",
325 for (i = 0; i < max_sta; i++) {
326 station = &priv->stations[i];
328 pos += scnprintf(buf + pos, bufsz - pos,
329 "station %d:\ngeneral data:\n", i+1);
330 pos += scnprintf(buf + pos, bufsz - pos, "id: %u\n",
331 station->sta.sta.sta_id);
332 pos += scnprintf(buf + pos, bufsz - pos, "mode: %u\n",
334 pos += scnprintf(buf + pos, bufsz - pos,
336 station->sta.station_flags_msk);
337 pos += scnprintf(buf + pos, bufsz - pos, "tid data:\n");
338 pos += scnprintf(buf + pos, bufsz - pos,
339 "seq_num\t\ttxq_id");
340 pos += scnprintf(buf + pos, bufsz - pos,
341 "\tframe_count\twait_for_ba\t");
342 pos += scnprintf(buf + pos, bufsz - pos,
343 "start_idx\tbitmap0\t");
344 pos += scnprintf(buf + pos, bufsz - pos,
345 "bitmap1\trate_n_flags");
346 pos += scnprintf(buf + pos, bufsz - pos, "\n");
348 for (j = 0; j < MAX_TID_COUNT; j++) {
349 pos += scnprintf(buf + pos, bufsz - pos,
351 station->tid[j].seq_number);
352 pos += scnprintf(buf + pos, bufsz - pos,
353 "\t%u\t\t%u\t\t%u\t\t",
354 station->tid[j].agg.txq_id,
355 station->tid[j].agg.frame_count,
356 station->tid[j].agg.wait_for_ba);
357 pos += scnprintf(buf + pos, bufsz - pos,
359 station->tid[j].agg.start_idx,
360 (unsigned long long)station->tid[j].agg.bitmap,
361 station->tid[j].agg.rate_n_flags);
362 pos += scnprintf(buf + pos, bufsz - pos, "\n");
364 pos += scnprintf(buf + pos, bufsz - pos, "\n");
368 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
373 static ssize_t iwl_dbgfs_nvm_read(struct file *file,
374 char __user *user_buf,
379 struct iwl_priv *priv = file->private_data;
380 int pos = 0, ofs = 0, buf_size = 0;
384 size_t eeprom_len = priv->cfg->eeprom_size;
385 buf_size = 4 * eeprom_len + 256;
387 if (eeprom_len % 16) {
388 IWL_ERR(priv, "NVM size is not multiple of 16.\n");
394 IWL_ERR(priv, "Invalid EEPROM/OTP memory\n");
398 /* 4 characters for byte 0xYY */
399 buf = kzalloc(buf_size, GFP_KERNEL);
401 IWL_ERR(priv, "Can not allocate Buffer\n");
404 eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
405 pos += scnprintf(buf + pos, buf_size - pos, "NVM Type: %s, "
407 (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP)
408 ? "OTP" : "EEPROM", eeprom_ver);
409 for (ofs = 0 ; ofs < eeprom_len ; ofs += 16) {
410 pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x ", ofs);
411 hex_dump_to_buffer(ptr + ofs, 16 , 16, 2, buf + pos,
413 pos += strlen(buf + pos);
414 if (buf_size - pos > 0)
418 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
423 static ssize_t iwl_dbgfs_log_event_read(struct file *file,
424 char __user *user_buf,
425 size_t count, loff_t *ppos)
427 struct iwl_priv *priv = file->private_data;
430 ssize_t ret = -ENOMEM;
432 ret = pos = priv->cfg->ops->lib->dump_nic_event_log(
433 priv, true, &buf, true);
435 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
441 static ssize_t iwl_dbgfs_log_event_write(struct file *file,
442 const char __user *user_buf,
443 size_t count, loff_t *ppos)
445 struct iwl_priv *priv = file->private_data;
450 memset(buf, 0, sizeof(buf));
451 buf_size = min(count, sizeof(buf) - 1);
452 if (copy_from_user(buf, user_buf, buf_size))
454 if (sscanf(buf, "%d", &event_log_flag) != 1)
456 if (event_log_flag == 1)
457 priv->cfg->ops->lib->dump_nic_event_log(priv, true,
465 static ssize_t iwl_dbgfs_channels_read(struct file *file, char __user *user_buf,
466 size_t count, loff_t *ppos)
468 struct iwl_priv *priv = file->private_data;
469 struct ieee80211_channel *channels = NULL;
470 const struct ieee80211_supported_band *supp_band = NULL;
471 int pos = 0, i, bufsz = PAGE_SIZE;
475 if (!test_bit(STATUS_GEO_CONFIGURED, &priv->status))
478 buf = kzalloc(bufsz, GFP_KERNEL);
480 IWL_ERR(priv, "Can not allocate Buffer\n");
484 supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_2GHZ);
486 channels = supp_band->channels;
488 pos += scnprintf(buf + pos, bufsz - pos,
489 "Displaying %d channels in 2.4GHz band 802.11bg):\n",
490 supp_band->n_channels);
492 for (i = 0; i < supp_band->n_channels; i++)
493 pos += scnprintf(buf + pos, bufsz - pos,
494 "%d: %ddBm: BSS%s%s, %s.\n",
495 ieee80211_frequency_to_channel(
496 channels[i].center_freq),
497 channels[i].max_power,
498 channels[i].flags & IEEE80211_CHAN_RADAR ?
499 " (IEEE 802.11h required)" : "",
500 ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
501 || (channels[i].flags &
502 IEEE80211_CHAN_RADAR)) ? "" :
505 IEEE80211_CHAN_PASSIVE_SCAN ?
506 "passive only" : "active/passive");
508 supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_5GHZ);
510 channels = supp_band->channels;
512 pos += scnprintf(buf + pos, bufsz - pos,
513 "Displaying %d channels in 5.2GHz band (802.11a)\n",
514 supp_band->n_channels);
516 for (i = 0; i < supp_band->n_channels; i++)
517 pos += scnprintf(buf + pos, bufsz - pos,
518 "%d: %ddBm: BSS%s%s, %s.\n",
519 ieee80211_frequency_to_channel(
520 channels[i].center_freq),
521 channels[i].max_power,
522 channels[i].flags & IEEE80211_CHAN_RADAR ?
523 " (IEEE 802.11h required)" : "",
524 ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
525 || (channels[i].flags &
526 IEEE80211_CHAN_RADAR)) ? "" :
529 IEEE80211_CHAN_PASSIVE_SCAN ?
530 "passive only" : "active/passive");
532 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
537 static ssize_t iwl_dbgfs_status_read(struct file *file,
538 char __user *user_buf,
539 size_t count, loff_t *ppos) {
541 struct iwl_priv *priv = file->private_data;
544 const size_t bufsz = sizeof(buf);
546 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_ACTIVE:\t %d\n",
547 test_bit(STATUS_HCMD_ACTIVE, &priv->status));
548 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INT_ENABLED:\t %d\n",
549 test_bit(STATUS_INT_ENABLED, &priv->status));
550 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_RF_KILL_HW:\t %d\n",
551 test_bit(STATUS_RF_KILL_HW, &priv->status));
552 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_CT_KILL:\t\t %d\n",
553 test_bit(STATUS_CT_KILL, &priv->status));
554 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INIT:\t\t %d\n",
555 test_bit(STATUS_INIT, &priv->status));
556 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_ALIVE:\t\t %d\n",
557 test_bit(STATUS_ALIVE, &priv->status));
558 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_READY:\t\t %d\n",
559 test_bit(STATUS_READY, &priv->status));
560 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_TEMPERATURE:\t %d\n",
561 test_bit(STATUS_TEMPERATURE, &priv->status));
562 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_GEO_CONFIGURED:\t %d\n",
563 test_bit(STATUS_GEO_CONFIGURED, &priv->status));
564 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_EXIT_PENDING:\t %d\n",
565 test_bit(STATUS_EXIT_PENDING, &priv->status));
566 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_STATISTICS:\t %d\n",
567 test_bit(STATUS_STATISTICS, &priv->status));
568 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCANNING:\t %d\n",
569 test_bit(STATUS_SCANNING, &priv->status));
570 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_ABORTING:\t %d\n",
571 test_bit(STATUS_SCAN_ABORTING, &priv->status));
572 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_HW:\t\t %d\n",
573 test_bit(STATUS_SCAN_HW, &priv->status));
574 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_POWER_PMI:\t %d\n",
575 test_bit(STATUS_POWER_PMI, &priv->status));
576 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_FW_ERROR:\t %d\n",
577 test_bit(STATUS_FW_ERROR, &priv->status));
578 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
581 static ssize_t iwl_dbgfs_interrupt_read(struct file *file,
582 char __user *user_buf,
583 size_t count, loff_t *ppos) {
585 struct iwl_priv *priv = file->private_data;
589 int bufsz = 24 * 64; /* 24 items * 64 char per item */
592 buf = kzalloc(bufsz, GFP_KERNEL);
594 IWL_ERR(priv, "Can not allocate Buffer\n");
598 pos += scnprintf(buf + pos, bufsz - pos,
599 "Interrupt Statistics Report:\n");
601 pos += scnprintf(buf + pos, bufsz - pos, "HW Error:\t\t\t %u\n",
603 pos += scnprintf(buf + pos, bufsz - pos, "SW Error:\t\t\t %u\n",
605 if (priv->isr_stats.sw > 0) {
606 pos += scnprintf(buf + pos, bufsz - pos,
607 "\tLast Restarting Code: 0x%X\n",
608 priv->isr_stats.sw_err);
610 #ifdef CONFIG_IWLWIFI_DEBUG
611 pos += scnprintf(buf + pos, bufsz - pos, "Frame transmitted:\t\t %u\n",
612 priv->isr_stats.sch);
613 pos += scnprintf(buf + pos, bufsz - pos, "Alive interrupt:\t\t %u\n",
614 priv->isr_stats.alive);
616 pos += scnprintf(buf + pos, bufsz - pos,
617 "HW RF KILL switch toggled:\t %u\n",
618 priv->isr_stats.rfkill);
620 pos += scnprintf(buf + pos, bufsz - pos, "CT KILL:\t\t\t %u\n",
621 priv->isr_stats.ctkill);
623 pos += scnprintf(buf + pos, bufsz - pos, "Wakeup Interrupt:\t\t %u\n",
624 priv->isr_stats.wakeup);
626 pos += scnprintf(buf + pos, bufsz - pos,
627 "Rx command responses:\t\t %u\n",
629 for (cnt = 0; cnt < REPLY_MAX; cnt++) {
630 if (priv->isr_stats.rx_handlers[cnt] > 0)
631 pos += scnprintf(buf + pos, bufsz - pos,
632 "\tRx handler[%36s]:\t\t %u\n",
634 priv->isr_stats.rx_handlers[cnt]);
637 pos += scnprintf(buf + pos, bufsz - pos, "Tx/FH interrupt:\t\t %u\n",
640 pos += scnprintf(buf + pos, bufsz - pos, "Unexpected INTA:\t\t %u\n",
641 priv->isr_stats.unhandled);
643 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
648 static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
649 const char __user *user_buf,
650 size_t count, loff_t *ppos)
652 struct iwl_priv *priv = file->private_data;
657 memset(buf, 0, sizeof(buf));
658 buf_size = min(count, sizeof(buf) - 1);
659 if (copy_from_user(buf, user_buf, buf_size))
661 if (sscanf(buf, "%x", &reset_flag) != 1)
664 iwl_clear_isr_stats(priv);
669 static ssize_t iwl_dbgfs_qos_read(struct file *file, char __user *user_buf,
670 size_t count, loff_t *ppos)
672 struct iwl_priv *priv = file->private_data;
675 const size_t bufsz = sizeof(buf);
677 for (i = 0; i < AC_NUM; i++) {
678 pos += scnprintf(buf + pos, bufsz - pos,
679 "\tcw_min\tcw_max\taifsn\ttxop\n");
680 pos += scnprintf(buf + pos, bufsz - pos,
681 "AC[%d]\t%u\t%u\t%u\t%u\n", i,
682 priv->qos_data.def_qos_parm.ac[i].cw_min,
683 priv->qos_data.def_qos_parm.ac[i].cw_max,
684 priv->qos_data.def_qos_parm.ac[i].aifsn,
685 priv->qos_data.def_qos_parm.ac[i].edca_txop);
687 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
690 static ssize_t iwl_dbgfs_led_read(struct file *file, char __user *user_buf,
691 size_t count, loff_t *ppos)
693 struct iwl_priv *priv = file->private_data;
696 const size_t bufsz = sizeof(buf);
698 pos += scnprintf(buf + pos, bufsz - pos,
699 "allow blinking: %s\n",
700 (priv->allow_blinking) ? "True" : "False");
701 if (priv->allow_blinking) {
702 pos += scnprintf(buf + pos, bufsz - pos,
703 "Led blinking rate: %u\n",
704 priv->last_blink_rate);
705 pos += scnprintf(buf + pos, bufsz - pos,
706 "Last blink time: %lu\n",
707 priv->last_blink_time);
710 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
713 static ssize_t iwl_dbgfs_thermal_throttling_read(struct file *file,
714 char __user *user_buf,
715 size_t count, loff_t *ppos)
717 struct iwl_priv *priv = file->private_data;
718 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
719 struct iwl_tt_restriction *restriction;
722 const size_t bufsz = sizeof(buf);
724 pos += scnprintf(buf + pos, bufsz - pos,
725 "Thermal Throttling Mode: %s\n",
726 tt->advanced_tt ? "Advance" : "Legacy");
727 pos += scnprintf(buf + pos, bufsz - pos,
728 "Thermal Throttling State: %d\n",
730 if (tt->advanced_tt) {
731 restriction = tt->restriction + tt->state;
732 pos += scnprintf(buf + pos, bufsz - pos,
734 restriction->tx_stream);
735 pos += scnprintf(buf + pos, bufsz - pos,
737 restriction->rx_stream);
738 pos += scnprintf(buf + pos, bufsz - pos,
742 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
745 static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
746 const char __user *user_buf,
747 size_t count, loff_t *ppos)
749 struct iwl_priv *priv = file->private_data;
754 memset(buf, 0, sizeof(buf));
755 buf_size = min(count, sizeof(buf) - 1);
756 if (copy_from_user(buf, user_buf, buf_size))
758 if (sscanf(buf, "%d", &ht40) != 1)
760 if (!iwl_is_associated(priv))
761 priv->disable_ht40 = ht40 ? true : false;
763 IWL_ERR(priv, "Sta associated with AP - "
764 "Change to 40MHz channel support is not allowed\n");
771 static ssize_t iwl_dbgfs_disable_ht40_read(struct file *file,
772 char __user *user_buf,
773 size_t count, loff_t *ppos)
775 struct iwl_priv *priv = file->private_data;
778 const size_t bufsz = sizeof(buf);
780 pos += scnprintf(buf + pos, bufsz - pos,
781 "11n 40MHz Mode: %s\n",
782 priv->disable_ht40 ? "Disabled" : "Enabled");
783 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
786 static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
787 const char __user *user_buf,
788 size_t count, loff_t *ppos)
790 struct iwl_priv *priv = file->private_data;
795 memset(buf, 0, sizeof(buf));
796 buf_size = min(count, sizeof(buf) - 1);
797 if (copy_from_user(buf, user_buf, buf_size))
800 if (sscanf(buf, "%d", &value) != 1)
804 * Our users expect 0 to be "CAM", but 0 isn't actually
805 * valid here. However, let's not confuse them and present
806 * IWL_POWER_INDEX_1 as "1", not "0".
813 if (value != -1 && (value < 0 || value >= IWL_POWER_NUM))
816 if (!iwl_is_ready_rf(priv))
819 priv->power_data.debug_sleep_level_override = value;
821 mutex_lock(&priv->mutex);
822 iwl_power_update_mode(priv, true);
823 mutex_unlock(&priv->mutex);
828 static ssize_t iwl_dbgfs_sleep_level_override_read(struct file *file,
829 char __user *user_buf,
830 size_t count, loff_t *ppos)
832 struct iwl_priv *priv = file->private_data;
835 const size_t bufsz = sizeof(buf);
837 /* see the write function */
838 value = priv->power_data.debug_sleep_level_override;
842 pos = scnprintf(buf, bufsz, "%d\n", value);
843 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
846 static ssize_t iwl_dbgfs_current_sleep_command_read(struct file *file,
847 char __user *user_buf,
848 size_t count, loff_t *ppos)
850 struct iwl_priv *priv = file->private_data;
853 const size_t bufsz = sizeof(buf);
854 struct iwl_powertable_cmd *cmd = &priv->power_data.sleep_cmd;
856 pos += scnprintf(buf + pos, bufsz - pos,
857 "flags: %#.2x\n", le16_to_cpu(cmd->flags));
858 pos += scnprintf(buf + pos, bufsz - pos,
859 "RX/TX timeout: %d/%d usec\n",
860 le32_to_cpu(cmd->rx_data_timeout),
861 le32_to_cpu(cmd->tx_data_timeout));
862 for (i = 0; i < IWL_POWER_VEC_SIZE; i++)
863 pos += scnprintf(buf + pos, bufsz - pos,
864 "sleep_interval[%d]: %d\n", i,
865 le32_to_cpu(cmd->sleep_interval[i]));
867 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
870 DEBUGFS_READ_WRITE_FILE_OPS(sram);
871 DEBUGFS_READ_WRITE_FILE_OPS(log_event);
872 DEBUGFS_READ_FILE_OPS(nvm);
873 DEBUGFS_READ_FILE_OPS(stations);
874 DEBUGFS_READ_FILE_OPS(channels);
875 DEBUGFS_READ_FILE_OPS(status);
876 DEBUGFS_READ_WRITE_FILE_OPS(interrupt);
877 DEBUGFS_READ_FILE_OPS(qos);
878 DEBUGFS_READ_FILE_OPS(led);
879 DEBUGFS_READ_FILE_OPS(thermal_throttling);
880 DEBUGFS_READ_WRITE_FILE_OPS(disable_ht40);
881 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
882 DEBUGFS_READ_FILE_OPS(current_sleep_command);
884 static ssize_t iwl_dbgfs_traffic_log_read(struct file *file,
885 char __user *user_buf,
886 size_t count, loff_t *ppos)
888 struct iwl_priv *priv = file->private_data;
889 int pos = 0, ofs = 0;
891 struct iwl_tx_queue *txq;
893 struct iwl_rx_queue *rxq = &priv->rxq;
895 int bufsz = ((IWL_TRAFFIC_ENTRIES * IWL_TRAFFIC_ENTRY_SIZE * 64) * 2) +
896 (priv->cfg->num_of_queues * 32 * 8) + 400;
901 IWL_ERR(priv, "txq not ready\n");
904 buf = kzalloc(bufsz, GFP_KERNEL);
906 IWL_ERR(priv, "Can not allocate buffer\n");
909 pos += scnprintf(buf + pos, bufsz - pos, "Tx Queue\n");
910 for (cnt = 0; cnt < priv->hw_params.max_txq_num; cnt++) {
911 txq = &priv->txq[cnt];
913 pos += scnprintf(buf + pos, bufsz - pos,
914 "q[%d]: read_ptr: %u, write_ptr: %u\n",
915 cnt, q->read_ptr, q->write_ptr);
917 if (priv->tx_traffic && (iwl_debug_level & IWL_DL_TX)) {
918 ptr = priv->tx_traffic;
919 pos += scnprintf(buf + pos, bufsz - pos,
920 "Tx Traffic idx: %u\n", priv->tx_traffic_idx);
921 for (cnt = 0, ofs = 0; cnt < IWL_TRAFFIC_ENTRIES; cnt++) {
922 for (entry = 0; entry < IWL_TRAFFIC_ENTRY_SIZE / 16;
923 entry++, ofs += 16) {
924 pos += scnprintf(buf + pos, bufsz - pos,
926 hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
927 buf + pos, bufsz - pos, 0);
928 pos += strlen(buf + pos);
935 pos += scnprintf(buf + pos, bufsz - pos, "Rx Queue\n");
936 pos += scnprintf(buf + pos, bufsz - pos,
937 "read: %u, write: %u\n",
938 rxq->read, rxq->write);
940 if (priv->rx_traffic && (iwl_debug_level & IWL_DL_RX)) {
941 ptr = priv->rx_traffic;
942 pos += scnprintf(buf + pos, bufsz - pos,
943 "Rx Traffic idx: %u\n", priv->rx_traffic_idx);
944 for (cnt = 0, ofs = 0; cnt < IWL_TRAFFIC_ENTRIES; cnt++) {
945 for (entry = 0; entry < IWL_TRAFFIC_ENTRY_SIZE / 16;
946 entry++, ofs += 16) {
947 pos += scnprintf(buf + pos, bufsz - pos,
949 hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
950 buf + pos, bufsz - pos, 0);
951 pos += strlen(buf + pos);
958 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
963 static ssize_t iwl_dbgfs_traffic_log_write(struct file *file,
964 const char __user *user_buf,
965 size_t count, loff_t *ppos)
967 struct iwl_priv *priv = file->private_data;
972 memset(buf, 0, sizeof(buf));
973 buf_size = min(count, sizeof(buf) - 1);
974 if (copy_from_user(buf, user_buf, buf_size))
976 if (sscanf(buf, "%d", &traffic_log) != 1)
978 if (traffic_log == 0)
979 iwl_reset_traffic_log(priv);
984 static ssize_t iwl_dbgfs_tx_queue_read(struct file *file,
985 char __user *user_buf,
986 size_t count, loff_t *ppos) {
988 struct iwl_priv *priv = file->private_data;
989 struct iwl_tx_queue *txq;
995 const size_t bufsz = sizeof(char) * 64 * priv->cfg->num_of_queues;
998 IWL_ERR(priv, "txq not ready\n");
1001 buf = kzalloc(bufsz, GFP_KERNEL);
1005 for (cnt = 0; cnt < priv->hw_params.max_txq_num; cnt++) {
1006 txq = &priv->txq[cnt];
1008 pos += scnprintf(buf + pos, bufsz - pos,
1009 "hwq %.2d: read=%u write=%u stop=%d"
1010 " swq_id=%#.2x (ac %d/hwq %d)\n",
1011 cnt, q->read_ptr, q->write_ptr,
1012 !!test_bit(cnt, priv->queue_stopped),
1014 txq->swq_id & 0x80 ? txq->swq_id & 3 :
1016 txq->swq_id & 0x80 ? (txq->swq_id >> 2) &
1017 0x1f : txq->swq_id);
1020 /* for the ACs, display the stop count too */
1021 pos += scnprintf(buf + pos, bufsz - pos,
1022 " stop-count: %d\n",
1023 atomic_read(&priv->queue_stop_count[cnt]));
1025 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1030 static ssize_t iwl_dbgfs_rx_queue_read(struct file *file,
1031 char __user *user_buf,
1032 size_t count, loff_t *ppos) {
1034 struct iwl_priv *priv = file->private_data;
1035 struct iwl_rx_queue *rxq = &priv->rxq;
1038 const size_t bufsz = sizeof(buf);
1040 pos += scnprintf(buf + pos, bufsz - pos, "read: %u\n",
1042 pos += scnprintf(buf + pos, bufsz - pos, "write: %u\n",
1044 pos += scnprintf(buf + pos, bufsz - pos, "free_count: %u\n",
1046 pos += scnprintf(buf + pos, bufsz - pos, "closed_rb_num: %u\n",
1047 le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF);
1048 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1051 static ssize_t iwl_dbgfs_ucode_rx_stats_read(struct file *file,
1052 char __user *user_buf,
1053 size_t count, loff_t *ppos)
1055 struct iwl_priv *priv = file->private_data;
1056 return priv->cfg->ops->lib->debugfs_ops.rx_stats_read(file,
1057 user_buf, count, ppos);
1060 static ssize_t iwl_dbgfs_ucode_tx_stats_read(struct file *file,
1061 char __user *user_buf,
1062 size_t count, loff_t *ppos)
1064 struct iwl_priv *priv = file->private_data;
1065 return priv->cfg->ops->lib->debugfs_ops.tx_stats_read(file,
1066 user_buf, count, ppos);
1069 static ssize_t iwl_dbgfs_ucode_general_stats_read(struct file *file,
1070 char __user *user_buf,
1071 size_t count, loff_t *ppos)
1073 struct iwl_priv *priv = file->private_data;
1074 return priv->cfg->ops->lib->debugfs_ops.general_stats_read(file,
1075 user_buf, count, ppos);
1078 static ssize_t iwl_dbgfs_sensitivity_read(struct file *file,
1079 char __user *user_buf,
1080 size_t count, loff_t *ppos) {
1082 struct iwl_priv *priv = file->private_data;
1086 int bufsz = sizeof(struct iwl_sensitivity_data) * 4 + 100;
1088 struct iwl_sensitivity_data *data;
1090 data = &priv->sensitivity_data;
1091 buf = kzalloc(bufsz, GFP_KERNEL);
1093 IWL_ERR(priv, "Can not allocate Buffer\n");
1097 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm:\t\t\t %u\n",
1098 data->auto_corr_ofdm);
1099 pos += scnprintf(buf + pos, bufsz - pos,
1100 "auto_corr_ofdm_mrc:\t\t %u\n",
1101 data->auto_corr_ofdm_mrc);
1102 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_x1:\t\t %u\n",
1103 data->auto_corr_ofdm_x1);
1104 pos += scnprintf(buf + pos, bufsz - pos,
1105 "auto_corr_ofdm_mrc_x1:\t\t %u\n",
1106 data->auto_corr_ofdm_mrc_x1);
1107 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck:\t\t\t %u\n",
1108 data->auto_corr_cck);
1109 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck_mrc:\t\t %u\n",
1110 data->auto_corr_cck_mrc);
1111 pos += scnprintf(buf + pos, bufsz - pos,
1112 "last_bad_plcp_cnt_ofdm:\t\t %u\n",
1113 data->last_bad_plcp_cnt_ofdm);
1114 pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_ofdm:\t\t %u\n",
1115 data->last_fa_cnt_ofdm);
1116 pos += scnprintf(buf + pos, bufsz - pos,
1117 "last_bad_plcp_cnt_cck:\t\t %u\n",
1118 data->last_bad_plcp_cnt_cck);
1119 pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_cck:\t\t %u\n",
1120 data->last_fa_cnt_cck);
1121 pos += scnprintf(buf + pos, bufsz - pos, "nrg_curr_state:\t\t\t %u\n",
1122 data->nrg_curr_state);
1123 pos += scnprintf(buf + pos, bufsz - pos, "nrg_prev_state:\t\t\t %u\n",
1124 data->nrg_prev_state);
1125 pos += scnprintf(buf + pos, bufsz - pos, "nrg_value:\t\t\t");
1126 for (cnt = 0; cnt < 10; cnt++) {
1127 pos += scnprintf(buf + pos, bufsz - pos, " %u",
1128 data->nrg_value[cnt]);
1130 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1131 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_rssi:\t\t");
1132 for (cnt = 0; cnt < NRG_NUM_PREV_STAT_L; cnt++) {
1133 pos += scnprintf(buf + pos, bufsz - pos, " %u",
1134 data->nrg_silence_rssi[cnt]);
1136 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1137 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_ref:\t\t %u\n",
1138 data->nrg_silence_ref);
1139 pos += scnprintf(buf + pos, bufsz - pos, "nrg_energy_idx:\t\t\t %u\n",
1140 data->nrg_energy_idx);
1141 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_idx:\t\t %u\n",
1142 data->nrg_silence_idx);
1143 pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_cck:\t\t\t %u\n",
1145 pos += scnprintf(buf + pos, bufsz - pos,
1146 "nrg_auto_corr_silence_diff:\t %u\n",
1147 data->nrg_auto_corr_silence_diff);
1148 pos += scnprintf(buf + pos, bufsz - pos, "num_in_cck_no_fa:\t\t %u\n",
1149 data->num_in_cck_no_fa);
1150 pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_ofdm:\t\t\t %u\n",
1153 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1159 static ssize_t iwl_dbgfs_chain_noise_read(struct file *file,
1160 char __user *user_buf,
1161 size_t count, loff_t *ppos) {
1163 struct iwl_priv *priv = file->private_data;
1167 int bufsz = sizeof(struct iwl_chain_noise_data) * 4 + 100;
1169 struct iwl_chain_noise_data *data;
1171 data = &priv->chain_noise_data;
1172 buf = kzalloc(bufsz, GFP_KERNEL);
1174 IWL_ERR(priv, "Can not allocate Buffer\n");
1178 pos += scnprintf(buf + pos, bufsz - pos, "active_chains:\t\t\t %u\n",
1179 data->active_chains);
1180 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_a:\t\t\t %u\n",
1181 data->chain_noise_a);
1182 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_b:\t\t\t %u\n",
1183 data->chain_noise_b);
1184 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_c:\t\t\t %u\n",
1185 data->chain_noise_c);
1186 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_a:\t\t\t %u\n",
1187 data->chain_signal_a);
1188 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_b:\t\t\t %u\n",
1189 data->chain_signal_b);
1190 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_c:\t\t\t %u\n",
1191 data->chain_signal_c);
1192 pos += scnprintf(buf + pos, bufsz - pos, "beacon_count:\t\t\t %u\n",
1193 data->beacon_count);
1195 pos += scnprintf(buf + pos, bufsz - pos, "disconn_array:\t\t\t");
1196 for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
1197 pos += scnprintf(buf + pos, bufsz - pos, " %u",
1198 data->disconn_array[cnt]);
1200 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1201 pos += scnprintf(buf + pos, bufsz - pos, "delta_gain_code:\t\t");
1202 for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
1203 pos += scnprintf(buf + pos, bufsz - pos, " %u",
1204 data->delta_gain_code[cnt]);
1206 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1207 pos += scnprintf(buf + pos, bufsz - pos, "radio_write:\t\t\t %u\n",
1209 pos += scnprintf(buf + pos, bufsz - pos, "state:\t\t\t\t %u\n",
1212 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1217 static ssize_t iwl_dbgfs_chain_tx_power_read(struct file *file,
1218 char __user *user_buf,
1219 size_t count, loff_t *ppos) {
1221 struct iwl_priv *priv = file->private_data;
1224 const size_t bufsz = sizeof(buf);
1225 struct statistics_tx *tx;
1227 if (!iwl_is_alive(priv))
1228 pos += scnprintf(buf + pos, bufsz - pos, "N/A\n");
1230 tx = &priv->statistics.tx;
1231 if (tx->tx_power.ant_a ||
1232 tx->tx_power.ant_b ||
1233 tx->tx_power.ant_c) {
1234 pos += scnprintf(buf + pos, bufsz - pos,
1235 "tx power: (1/2 dB step)\n");
1236 if ((priv->cfg->valid_tx_ant & ANT_A) &&
1238 pos += scnprintf(buf + pos, bufsz - pos,
1239 "\tantenna A: 0x%X\n",
1240 tx->tx_power.ant_a);
1241 if ((priv->cfg->valid_tx_ant & ANT_B) &&
1243 pos += scnprintf(buf + pos, bufsz - pos,
1244 "\tantenna B: 0x%X\n",
1245 tx->tx_power.ant_b);
1246 if ((priv->cfg->valid_tx_ant & ANT_C) &&
1248 pos += scnprintf(buf + pos, bufsz - pos,
1249 "\tantenna C: 0x%X\n",
1250 tx->tx_power.ant_c);
1252 pos += scnprintf(buf + pos, bufsz - pos, "N/A\n");
1254 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1257 static ssize_t iwl_dbgfs_power_save_status_read(struct file *file,
1258 char __user *user_buf,
1259 size_t count, loff_t *ppos)
1261 struct iwl_priv *priv = file->private_data;
1264 const size_t bufsz = sizeof(buf);
1267 pwrsave_status = iwl_read32(priv, CSR_GP_CNTRL) &
1268 CSR_GP_REG_POWER_SAVE_STATUS_MSK;
1270 pos += scnprintf(buf + pos, bufsz - pos, "Power Save Status: ");
1271 pos += scnprintf(buf + pos, bufsz - pos, "%s\n",
1272 (pwrsave_status == CSR_GP_REG_NO_POWER_SAVE) ? "none" :
1273 (pwrsave_status == CSR_GP_REG_MAC_POWER_SAVE) ? "MAC" :
1274 (pwrsave_status == CSR_GP_REG_PHY_POWER_SAVE) ? "PHY" :
1277 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1280 static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
1281 const char __user *user_buf,
1282 size_t count, loff_t *ppos)
1284 struct iwl_priv *priv = file->private_data;
1289 memset(buf, 0, sizeof(buf));
1290 buf_size = min(count, sizeof(buf) - 1);
1291 if (copy_from_user(buf, user_buf, buf_size))
1293 if (sscanf(buf, "%d", &clear) != 1)
1296 /* make request to uCode to retrieve statistics information */
1297 mutex_lock(&priv->mutex);
1298 iwl_send_statistics_request(priv, CMD_SYNC, true);
1299 mutex_unlock(&priv->mutex);
1304 static ssize_t iwl_dbgfs_csr_write(struct file *file,
1305 const char __user *user_buf,
1306 size_t count, loff_t *ppos)
1308 struct iwl_priv *priv = file->private_data;
1313 memset(buf, 0, sizeof(buf));
1314 buf_size = min(count, sizeof(buf) - 1);
1315 if (copy_from_user(buf, user_buf, buf_size))
1317 if (sscanf(buf, "%d", &csr) != 1)
1320 if (priv->cfg->ops->lib->dump_csr)
1321 priv->cfg->ops->lib->dump_csr(priv);
1326 static ssize_t iwl_dbgfs_ucode_tracing_read(struct file *file,
1327 char __user *user_buf,
1328 size_t count, loff_t *ppos) {
1330 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1333 const size_t bufsz = sizeof(buf);
1335 pos += scnprintf(buf + pos, bufsz - pos, "ucode trace timer is %s\n",
1336 priv->event_log.ucode_trace ? "On" : "Off");
1337 pos += scnprintf(buf + pos, bufsz - pos, "non_wraps_count:\t\t %u\n",
1338 priv->event_log.non_wraps_count);
1339 pos += scnprintf(buf + pos, bufsz - pos, "wraps_once_count:\t\t %u\n",
1340 priv->event_log.wraps_once_count);
1341 pos += scnprintf(buf + pos, bufsz - pos, "wraps_more_count:\t\t %u\n",
1342 priv->event_log.wraps_more_count);
1344 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1347 static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
1348 const char __user *user_buf,
1349 size_t count, loff_t *ppos)
1351 struct iwl_priv *priv = file->private_data;
1356 memset(buf, 0, sizeof(buf));
1357 buf_size = min(count, sizeof(buf) - 1);
1358 if (copy_from_user(buf, user_buf, buf_size))
1360 if (sscanf(buf, "%d", &trace) != 1)
1364 priv->event_log.ucode_trace = true;
1365 /* schedule the ucode timer to occur in UCODE_TRACE_PERIOD */
1366 mod_timer(&priv->ucode_trace,
1367 jiffies + msecs_to_jiffies(UCODE_TRACE_PERIOD));
1369 priv->event_log.ucode_trace = false;
1370 del_timer_sync(&priv->ucode_trace);
1376 static ssize_t iwl_dbgfs_rxon_flags_read(struct file *file,
1377 char __user *user_buf,
1378 size_t count, loff_t *ppos) {
1380 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1384 len = sprintf(buf, "0x%04X\n", le32_to_cpu(priv->active_rxon.flags));
1385 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1388 static ssize_t iwl_dbgfs_rxon_filter_flags_read(struct file *file,
1389 char __user *user_buf,
1390 size_t count, loff_t *ppos) {
1392 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1396 len = sprintf(buf, "0x%04X\n",
1397 le32_to_cpu(priv->active_rxon.filter_flags));
1398 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1401 static ssize_t iwl_dbgfs_fh_reg_read(struct file *file,
1402 char __user *user_buf,
1403 size_t count, loff_t *ppos)
1405 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1408 ssize_t ret = -EFAULT;
1410 if (priv->cfg->ops->lib->dump_fh) {
1411 ret = pos = priv->cfg->ops->lib->dump_fh(priv, &buf, true);
1413 ret = simple_read_from_buffer(user_buf,
1414 count, ppos, buf, pos);
1422 static ssize_t iwl_dbgfs_missed_beacon_read(struct file *file,
1423 char __user *user_buf,
1424 size_t count, loff_t *ppos) {
1426 struct iwl_priv *priv = file->private_data;
1429 const size_t bufsz = sizeof(buf);
1431 pos += scnprintf(buf + pos, bufsz - pos, "%d\n",
1432 priv->missed_beacon_threshold);
1434 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1437 static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
1438 const char __user *user_buf,
1439 size_t count, loff_t *ppos)
1441 struct iwl_priv *priv = file->private_data;
1446 memset(buf, 0, sizeof(buf));
1447 buf_size = min(count, sizeof(buf) - 1);
1448 if (copy_from_user(buf, user_buf, buf_size))
1450 if (sscanf(buf, "%d", &missed) != 1)
1453 if (missed < IWL_MISSED_BEACON_THRESHOLD_MIN ||
1454 missed > IWL_MISSED_BEACON_THRESHOLD_MAX)
1455 priv->missed_beacon_threshold =
1456 IWL_MISSED_BEACON_THRESHOLD_DEF;
1458 priv->missed_beacon_threshold = missed;
1463 static ssize_t iwl_dbgfs_plcp_delta_read(struct file *file,
1464 char __user *user_buf,
1465 size_t count, loff_t *ppos) {
1467 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1470 const size_t bufsz = sizeof(buf);
1472 pos += scnprintf(buf + pos, bufsz - pos, "%u\n",
1473 priv->cfg->plcp_delta_threshold);
1475 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1478 static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
1479 const char __user *user_buf,
1480 size_t count, loff_t *ppos) {
1482 struct iwl_priv *priv = file->private_data;
1487 memset(buf, 0, sizeof(buf));
1488 buf_size = min(count, sizeof(buf) - 1);
1489 if (copy_from_user(buf, user_buf, buf_size))
1491 if (sscanf(buf, "%d", &plcp) != 1)
1493 if ((plcp <= IWL_MAX_PLCP_ERR_THRESHOLD_MIN) ||
1494 (plcp > IWL_MAX_PLCP_ERR_THRESHOLD_MAX))
1495 priv->cfg->plcp_delta_threshold =
1496 IWL_MAX_PLCP_ERR_THRESHOLD_DEF;
1498 priv->cfg->plcp_delta_threshold = plcp;
1502 static ssize_t iwl_dbgfs_force_reset_read(struct file *file,
1503 char __user *user_buf,
1504 size_t count, loff_t *ppos) {
1506 struct iwl_priv *priv = file->private_data;
1509 const size_t bufsz = sizeof(buf);
1510 struct iwl_force_reset *force_reset;
1512 for (i = 0; i < IWL_MAX_FORCE_RESET; i++) {
1513 force_reset = &priv->force_reset[i];
1514 pos += scnprintf(buf + pos, bufsz - pos,
1515 "Force reset method %d\n", i);
1516 pos += scnprintf(buf + pos, bufsz - pos,
1517 "\tnumber of reset request: %d\n",
1518 force_reset->reset_request_count);
1519 pos += scnprintf(buf + pos, bufsz - pos,
1520 "\tnumber of reset request success: %d\n",
1521 force_reset->reset_success_count);
1522 pos += scnprintf(buf + pos, bufsz - pos,
1523 "\tnumber of reset request reject: %d\n",
1524 force_reset->reset_reject_count);
1525 pos += scnprintf(buf + pos, bufsz - pos,
1526 "\treset duration: %lu\n",
1527 force_reset->reset_duration);
1529 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1532 static ssize_t iwl_dbgfs_force_reset_write(struct file *file,
1533 const char __user *user_buf,
1534 size_t count, loff_t *ppos) {
1536 struct iwl_priv *priv = file->private_data;
1541 memset(buf, 0, sizeof(buf));
1542 buf_size = min(count, sizeof(buf) - 1);
1543 if (copy_from_user(buf, user_buf, buf_size))
1545 if (sscanf(buf, "%d", &reset) != 1)
1550 ret = iwl_force_reset(priv, reset);
1555 return ret ? ret : count;
1558 DEBUGFS_READ_FILE_OPS(rx_statistics);
1559 DEBUGFS_READ_FILE_OPS(tx_statistics);
1560 DEBUGFS_READ_WRITE_FILE_OPS(traffic_log);
1561 DEBUGFS_READ_FILE_OPS(rx_queue);
1562 DEBUGFS_READ_FILE_OPS(tx_queue);
1563 DEBUGFS_READ_FILE_OPS(ucode_rx_stats);
1564 DEBUGFS_READ_FILE_OPS(ucode_tx_stats);
1565 DEBUGFS_READ_FILE_OPS(ucode_general_stats);
1566 DEBUGFS_READ_FILE_OPS(sensitivity);
1567 DEBUGFS_READ_FILE_OPS(chain_noise);
1568 DEBUGFS_READ_FILE_OPS(chain_tx_power);
1569 DEBUGFS_READ_FILE_OPS(power_save_status);
1570 DEBUGFS_WRITE_FILE_OPS(clear_ucode_statistics);
1571 DEBUGFS_WRITE_FILE_OPS(clear_traffic_statistics);
1572 DEBUGFS_WRITE_FILE_OPS(csr);
1573 DEBUGFS_READ_WRITE_FILE_OPS(ucode_tracing);
1574 DEBUGFS_READ_FILE_OPS(fh_reg);
1575 DEBUGFS_READ_WRITE_FILE_OPS(missed_beacon);
1576 DEBUGFS_READ_WRITE_FILE_OPS(plcp_delta);
1577 DEBUGFS_READ_WRITE_FILE_OPS(force_reset);
1578 DEBUGFS_READ_FILE_OPS(rxon_flags);
1579 DEBUGFS_READ_FILE_OPS(rxon_filter_flags);
1582 * Create the debugfs files and directories
1585 int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
1587 struct dentry *phyd = priv->hw->wiphy->debugfsdir;
1588 struct dentry *dir_drv, *dir_data, *dir_rf, *dir_debug;
1590 dir_drv = debugfs_create_dir(name, phyd);
1594 priv->debugfs_dir = dir_drv;
1596 dir_data = debugfs_create_dir("data", dir_drv);
1599 dir_rf = debugfs_create_dir("rf", dir_drv);
1602 dir_debug = debugfs_create_dir("debug", dir_drv);
1606 DEBUGFS_ADD_FILE(nvm, dir_data, S_IRUSR);
1607 DEBUGFS_ADD_FILE(sram, dir_data, S_IWUSR | S_IRUSR);
1608 DEBUGFS_ADD_FILE(log_event, dir_data, S_IWUSR | S_IRUSR);
1609 DEBUGFS_ADD_FILE(stations, dir_data, S_IRUSR);
1610 DEBUGFS_ADD_FILE(channels, dir_data, S_IRUSR);
1611 DEBUGFS_ADD_FILE(status, dir_data, S_IRUSR);
1612 DEBUGFS_ADD_FILE(interrupt, dir_data, S_IWUSR | S_IRUSR);
1613 DEBUGFS_ADD_FILE(qos, dir_data, S_IRUSR);
1614 DEBUGFS_ADD_FILE(led, dir_data, S_IRUSR);
1615 if (!priv->cfg->broken_powersave) {
1616 DEBUGFS_ADD_FILE(sleep_level_override, dir_data,
1618 DEBUGFS_ADD_FILE(current_sleep_command, dir_data, S_IRUSR);
1620 DEBUGFS_ADD_FILE(thermal_throttling, dir_data, S_IRUSR);
1621 DEBUGFS_ADD_FILE(disable_ht40, dir_data, S_IWUSR | S_IRUSR);
1622 DEBUGFS_ADD_FILE(rx_statistics, dir_debug, S_IRUSR);
1623 DEBUGFS_ADD_FILE(tx_statistics, dir_debug, S_IRUSR);
1624 DEBUGFS_ADD_FILE(traffic_log, dir_debug, S_IWUSR | S_IRUSR);
1625 DEBUGFS_ADD_FILE(rx_queue, dir_debug, S_IRUSR);
1626 DEBUGFS_ADD_FILE(tx_queue, dir_debug, S_IRUSR);
1627 DEBUGFS_ADD_FILE(chain_tx_power, dir_debug, S_IRUSR);
1628 DEBUGFS_ADD_FILE(power_save_status, dir_debug, S_IRUSR);
1629 DEBUGFS_ADD_FILE(clear_ucode_statistics, dir_debug, S_IWUSR);
1630 DEBUGFS_ADD_FILE(clear_traffic_statistics, dir_debug, S_IWUSR);
1631 DEBUGFS_ADD_FILE(csr, dir_debug, S_IWUSR);
1632 DEBUGFS_ADD_FILE(fh_reg, dir_debug, S_IRUSR);
1633 DEBUGFS_ADD_FILE(missed_beacon, dir_debug, S_IWUSR);
1634 DEBUGFS_ADD_FILE(plcp_delta, dir_debug, S_IWUSR | S_IRUSR);
1635 DEBUGFS_ADD_FILE(force_reset, dir_debug, S_IWUSR | S_IRUSR);
1636 DEBUGFS_ADD_FILE(ucode_rx_stats, dir_debug, S_IRUSR);
1637 DEBUGFS_ADD_FILE(ucode_tx_stats, dir_debug, S_IRUSR);
1638 DEBUGFS_ADD_FILE(ucode_general_stats, dir_debug, S_IRUSR);
1640 if ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) != CSR_HW_REV_TYPE_3945) {
1641 DEBUGFS_ADD_FILE(sensitivity, dir_debug, S_IRUSR);
1642 DEBUGFS_ADD_FILE(chain_noise, dir_debug, S_IRUSR);
1643 DEBUGFS_ADD_FILE(ucode_tracing, dir_debug, S_IWUSR | S_IRUSR);
1645 DEBUGFS_ADD_FILE(rxon_flags, dir_debug, S_IWUSR);
1646 DEBUGFS_ADD_FILE(rxon_filter_flags, dir_debug, S_IWUSR);
1647 DEBUGFS_ADD_BOOL(disable_sensitivity, dir_rf, &priv->disable_sens_cal);
1648 DEBUGFS_ADD_BOOL(disable_chain_noise, dir_rf,
1649 &priv->disable_chain_noise_cal);
1650 if (priv->cfg->tx_power_by_driver)
1651 DEBUGFS_ADD_BOOL(disable_tx_power, dir_rf,
1652 &priv->disable_tx_power_cal);
1656 IWL_ERR(priv, "Can't create the debugfs directory\n");
1657 iwl_dbgfs_unregister(priv);
1660 EXPORT_SYMBOL(iwl_dbgfs_register);
1663 * Remove the debugfs files and directories
1666 void iwl_dbgfs_unregister(struct iwl_priv *priv)
1668 if (!priv->debugfs_dir)
1671 debugfs_remove_recursive(priv->debugfs_dir);
1672 priv->debugfs_dir = NULL;
1674 EXPORT_SYMBOL(iwl_dbgfs_unregister);