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 static ssize_t iwl_dbgfs_tx_statistics_read(struct file *file,
104 char __user *user_buf,
105 size_t count, loff_t *ppos) {
107 struct iwl_priv *priv = 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 get_mgmt_string(cnt),
123 priv->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 get_ctrl_string(cnt),
130 priv->tx_stats.ctrl[cnt]);
132 pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
133 pos += scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
134 priv->tx_stats.data_cnt);
135 pos += scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
136 priv->tx_stats.data_bytes);
137 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
142 static ssize_t iwl_dbgfs_clear_traffic_statistics_write(struct file *file,
143 const char __user *user_buf,
144 size_t count, loff_t *ppos)
146 struct iwl_priv *priv = file->private_data;
151 memset(buf, 0, sizeof(buf));
152 buf_size = min(count, sizeof(buf) - 1);
153 if (copy_from_user(buf, user_buf, buf_size))
155 if (sscanf(buf, "%x", &clear_flag) != 1)
157 iwl_clear_traffic_stats(priv);
162 static ssize_t iwl_dbgfs_rx_statistics_read(struct file *file,
163 char __user *user_buf,
164 size_t count, loff_t *ppos) {
166 struct iwl_priv *priv = file->private_data;
171 const size_t bufsz = 100 +
172 sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
173 buf = kzalloc(bufsz, GFP_KERNEL);
177 pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
178 for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
179 pos += scnprintf(buf + pos, bufsz - pos,
181 get_mgmt_string(cnt),
182 priv->rx_stats.mgmt[cnt]);
184 pos += scnprintf(buf + pos, bufsz - pos, "Control:\n");
185 for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
186 pos += scnprintf(buf + pos, bufsz - pos,
188 get_ctrl_string(cnt),
189 priv->rx_stats.ctrl[cnt]);
191 pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
192 pos += scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
193 priv->rx_stats.data_cnt);
194 pos += scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
195 priv->rx_stats.data_bytes);
197 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
202 #define BYTE1_MASK 0x000000ff;
203 #define BYTE2_MASK 0x0000ffff;
204 #define BYTE3_MASK 0x00ffffff;
205 static ssize_t iwl_dbgfs_sram_read(struct file *file,
206 char __user *user_buf,
207 size_t count, loff_t *ppos)
214 struct iwl_priv *priv = file->private_data;
217 /* default is to dump the entire data segment */
218 if (!priv->dbgfs_sram_offset && !priv->dbgfs_sram_len) {
219 priv->dbgfs_sram_offset = 0x800000;
220 if (priv->ucode_type == UCODE_INIT)
221 priv->dbgfs_sram_len = priv->ucode_init_data.len;
223 priv->dbgfs_sram_len = priv->ucode_data.len;
225 bufsz = 30 + priv->dbgfs_sram_len * sizeof(char) * 10;
226 buf = kmalloc(bufsz, GFP_KERNEL);
229 pos += scnprintf(buf + pos, bufsz - pos, "sram_len: 0x%x\n",
230 priv->dbgfs_sram_len);
231 pos += scnprintf(buf + pos, bufsz - pos, "sram_offset: 0x%x\n",
232 priv->dbgfs_sram_offset);
233 for (i = priv->dbgfs_sram_len; i > 0; i -= 4) {
234 val = iwl_read_targ_mem(priv, priv->dbgfs_sram_offset + \
235 priv->dbgfs_sram_len - i);
250 pos += scnprintf(buf + pos, bufsz - pos, "\n");
251 pos += scnprintf(buf + pos, bufsz - pos, "0x%08x ", val);
253 pos += scnprintf(buf + pos, bufsz - pos, "\n");
255 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
260 static ssize_t iwl_dbgfs_sram_write(struct file *file,
261 const char __user *user_buf,
262 size_t count, loff_t *ppos)
264 struct iwl_priv *priv = file->private_data;
269 memset(buf, 0, sizeof(buf));
270 buf_size = min(count, sizeof(buf) - 1);
271 if (copy_from_user(buf, user_buf, buf_size))
274 if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
275 priv->dbgfs_sram_offset = offset;
276 priv->dbgfs_sram_len = len;
278 priv->dbgfs_sram_offset = 0;
279 priv->dbgfs_sram_len = 0;
285 static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
286 size_t count, loff_t *ppos)
288 struct iwl_priv *priv = file->private_data;
289 struct iwl_station_entry *station;
290 int max_sta = priv->hw_params.max_stations;
294 /* Add 30 for initial string */
295 const size_t bufsz = 30 + sizeof(char) * 500 * (priv->num_stations);
297 buf = kmalloc(bufsz, GFP_KERNEL);
301 pos += scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n",
304 for (i = 0; i < max_sta; i++) {
305 station = &priv->stations[i];
308 pos += scnprintf(buf + pos, bufsz - pos,
309 "station %d - addr: %pM, flags: %#x\n",
310 i, station->sta.sta.addr,
311 station->sta.station_flags_msk);
312 pos += scnprintf(buf + pos, bufsz - pos,
313 "TID\tseq_num\ttxq_id\tframes\ttfds\t");
314 pos += scnprintf(buf + pos, bufsz - pos,
315 "start_idx\tbitmap\t\t\trate_n_flags\n");
317 for (j = 0; j < MAX_TID_COUNT; j++) {
318 pos += scnprintf(buf + pos, bufsz - pos,
319 "%d:\t%#x\t%#x\t%u\t%u\t%u\t\t%#.16llx\t%#x",
320 j, station->tid[j].seq_number,
321 station->tid[j].agg.txq_id,
322 station->tid[j].agg.frame_count,
323 station->tid[j].tfds_in_queue,
324 station->tid[j].agg.start_idx,
325 station->tid[j].agg.bitmap,
326 station->tid[j].agg.rate_n_flags);
328 if (station->tid[j].agg.wait_for_ba)
329 pos += scnprintf(buf + pos, bufsz - pos,
331 pos += scnprintf(buf + pos, bufsz - pos, "\n");
334 pos += scnprintf(buf + pos, bufsz - pos, "\n");
337 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
342 static ssize_t iwl_dbgfs_nvm_read(struct file *file,
343 char __user *user_buf,
348 struct iwl_priv *priv = file->private_data;
349 int pos = 0, ofs = 0, buf_size = 0;
353 size_t eeprom_len = priv->cfg->eeprom_size;
354 buf_size = 4 * eeprom_len + 256;
356 if (eeprom_len % 16) {
357 IWL_ERR(priv, "NVM size is not multiple of 16.\n");
363 IWL_ERR(priv, "Invalid EEPROM/OTP memory\n");
367 /* 4 characters for byte 0xYY */
368 buf = kzalloc(buf_size, GFP_KERNEL);
370 IWL_ERR(priv, "Can not allocate Buffer\n");
373 eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
374 pos += scnprintf(buf + pos, buf_size - pos, "NVM Type: %s, "
376 (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP)
377 ? "OTP" : "EEPROM", 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);
392 static ssize_t iwl_dbgfs_log_event_read(struct file *file,
393 char __user *user_buf,
394 size_t count, loff_t *ppos)
396 struct iwl_priv *priv = file->private_data;
399 ssize_t ret = -ENOMEM;
401 ret = pos = priv->cfg->ops->lib->dump_nic_event_log(
402 priv, true, &buf, true);
404 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
410 static ssize_t iwl_dbgfs_log_event_write(struct file *file,
411 const char __user *user_buf,
412 size_t count, loff_t *ppos)
414 struct iwl_priv *priv = file->private_data;
419 memset(buf, 0, sizeof(buf));
420 buf_size = min(count, sizeof(buf) - 1);
421 if (copy_from_user(buf, user_buf, buf_size))
423 if (sscanf(buf, "%d", &event_log_flag) != 1)
425 if (event_log_flag == 1)
426 priv->cfg->ops->lib->dump_nic_event_log(priv, true,
434 static ssize_t iwl_dbgfs_channels_read(struct file *file, char __user *user_buf,
435 size_t count, loff_t *ppos)
437 struct iwl_priv *priv = file->private_data;
438 struct ieee80211_channel *channels = NULL;
439 const struct ieee80211_supported_band *supp_band = NULL;
440 int pos = 0, i, bufsz = PAGE_SIZE;
444 if (!test_bit(STATUS_GEO_CONFIGURED, &priv->status))
447 buf = kzalloc(bufsz, GFP_KERNEL);
449 IWL_ERR(priv, "Can not allocate Buffer\n");
453 supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_2GHZ);
455 channels = supp_band->channels;
457 pos += scnprintf(buf + pos, bufsz - pos,
458 "Displaying %d channels in 2.4GHz band 802.11bg):\n",
459 supp_band->n_channels);
461 for (i = 0; i < supp_band->n_channels; i++)
462 pos += scnprintf(buf + pos, bufsz - pos,
463 "%d: %ddBm: BSS%s%s, %s.\n",
464 ieee80211_frequency_to_channel(
465 channels[i].center_freq),
466 channels[i].max_power,
467 channels[i].flags & IEEE80211_CHAN_RADAR ?
468 " (IEEE 802.11h required)" : "",
469 ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
470 || (channels[i].flags &
471 IEEE80211_CHAN_RADAR)) ? "" :
474 IEEE80211_CHAN_PASSIVE_SCAN ?
475 "passive only" : "active/passive");
477 supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_5GHZ);
479 channels = supp_band->channels;
481 pos += scnprintf(buf + pos, bufsz - pos,
482 "Displaying %d channels in 5.2GHz band (802.11a)\n",
483 supp_band->n_channels);
485 for (i = 0; i < supp_band->n_channels; i++)
486 pos += scnprintf(buf + pos, bufsz - pos,
487 "%d: %ddBm: BSS%s%s, %s.\n",
488 ieee80211_frequency_to_channel(
489 channels[i].center_freq),
490 channels[i].max_power,
491 channels[i].flags & IEEE80211_CHAN_RADAR ?
492 " (IEEE 802.11h required)" : "",
493 ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
494 || (channels[i].flags &
495 IEEE80211_CHAN_RADAR)) ? "" :
498 IEEE80211_CHAN_PASSIVE_SCAN ?
499 "passive only" : "active/passive");
501 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
506 static ssize_t iwl_dbgfs_status_read(struct file *file,
507 char __user *user_buf,
508 size_t count, loff_t *ppos) {
510 struct iwl_priv *priv = file->private_data;
513 const size_t bufsz = sizeof(buf);
515 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_ACTIVE:\t %d\n",
516 test_bit(STATUS_HCMD_ACTIVE, &priv->status));
517 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INT_ENABLED:\t %d\n",
518 test_bit(STATUS_INT_ENABLED, &priv->status));
519 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_RF_KILL_HW:\t %d\n",
520 test_bit(STATUS_RF_KILL_HW, &priv->status));
521 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_CT_KILL:\t\t %d\n",
522 test_bit(STATUS_CT_KILL, &priv->status));
523 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INIT:\t\t %d\n",
524 test_bit(STATUS_INIT, &priv->status));
525 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_ALIVE:\t\t %d\n",
526 test_bit(STATUS_ALIVE, &priv->status));
527 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_READY:\t\t %d\n",
528 test_bit(STATUS_READY, &priv->status));
529 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_TEMPERATURE:\t %d\n",
530 test_bit(STATUS_TEMPERATURE, &priv->status));
531 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_GEO_CONFIGURED:\t %d\n",
532 test_bit(STATUS_GEO_CONFIGURED, &priv->status));
533 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_EXIT_PENDING:\t %d\n",
534 test_bit(STATUS_EXIT_PENDING, &priv->status));
535 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_STATISTICS:\t %d\n",
536 test_bit(STATUS_STATISTICS, &priv->status));
537 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCANNING:\t %d\n",
538 test_bit(STATUS_SCANNING, &priv->status));
539 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_ABORTING:\t %d\n",
540 test_bit(STATUS_SCAN_ABORTING, &priv->status));
541 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_HW:\t\t %d\n",
542 test_bit(STATUS_SCAN_HW, &priv->status));
543 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_POWER_PMI:\t %d\n",
544 test_bit(STATUS_POWER_PMI, &priv->status));
545 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_FW_ERROR:\t %d\n",
546 test_bit(STATUS_FW_ERROR, &priv->status));
547 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
550 static ssize_t iwl_dbgfs_interrupt_read(struct file *file,
551 char __user *user_buf,
552 size_t count, loff_t *ppos) {
554 struct iwl_priv *priv = file->private_data;
558 int bufsz = 24 * 64; /* 24 items * 64 char per item */
561 buf = kzalloc(bufsz, GFP_KERNEL);
563 IWL_ERR(priv, "Can not allocate Buffer\n");
567 pos += scnprintf(buf + pos, bufsz - pos,
568 "Interrupt Statistics Report:\n");
570 pos += scnprintf(buf + pos, bufsz - pos, "HW Error:\t\t\t %u\n",
572 pos += scnprintf(buf + pos, bufsz - pos, "SW Error:\t\t\t %u\n",
574 if (priv->isr_stats.sw > 0) {
575 pos += scnprintf(buf + pos, bufsz - pos,
576 "\tLast Restarting Code: 0x%X\n",
577 priv->isr_stats.sw_err);
579 #ifdef CONFIG_IWLWIFI_DEBUG
580 pos += scnprintf(buf + pos, bufsz - pos, "Frame transmitted:\t\t %u\n",
581 priv->isr_stats.sch);
582 pos += scnprintf(buf + pos, bufsz - pos, "Alive interrupt:\t\t %u\n",
583 priv->isr_stats.alive);
585 pos += scnprintf(buf + pos, bufsz - pos,
586 "HW RF KILL switch toggled:\t %u\n",
587 priv->isr_stats.rfkill);
589 pos += scnprintf(buf + pos, bufsz - pos, "CT KILL:\t\t\t %u\n",
590 priv->isr_stats.ctkill);
592 pos += scnprintf(buf + pos, bufsz - pos, "Wakeup Interrupt:\t\t %u\n",
593 priv->isr_stats.wakeup);
595 pos += scnprintf(buf + pos, bufsz - pos,
596 "Rx command responses:\t\t %u\n",
598 for (cnt = 0; cnt < REPLY_MAX; cnt++) {
599 if (priv->isr_stats.rx_handlers[cnt] > 0)
600 pos += scnprintf(buf + pos, bufsz - pos,
601 "\tRx handler[%36s]:\t\t %u\n",
603 priv->isr_stats.rx_handlers[cnt]);
606 pos += scnprintf(buf + pos, bufsz - pos, "Tx/FH interrupt:\t\t %u\n",
609 pos += scnprintf(buf + pos, bufsz - pos, "Unexpected INTA:\t\t %u\n",
610 priv->isr_stats.unhandled);
612 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
617 static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
618 const char __user *user_buf,
619 size_t count, loff_t *ppos)
621 struct iwl_priv *priv = file->private_data;
626 memset(buf, 0, sizeof(buf));
627 buf_size = min(count, sizeof(buf) - 1);
628 if (copy_from_user(buf, user_buf, buf_size))
630 if (sscanf(buf, "%x", &reset_flag) != 1)
633 iwl_clear_isr_stats(priv);
638 static ssize_t iwl_dbgfs_qos_read(struct file *file, char __user *user_buf,
639 size_t count, loff_t *ppos)
641 struct iwl_priv *priv = file->private_data;
644 const size_t bufsz = sizeof(buf);
646 for (i = 0; i < AC_NUM; i++) {
647 pos += scnprintf(buf + pos, bufsz - pos,
648 "\tcw_min\tcw_max\taifsn\ttxop\n");
649 pos += scnprintf(buf + pos, bufsz - pos,
650 "AC[%d]\t%u\t%u\t%u\t%u\n", i,
651 priv->qos_data.def_qos_parm.ac[i].cw_min,
652 priv->qos_data.def_qos_parm.ac[i].cw_max,
653 priv->qos_data.def_qos_parm.ac[i].aifsn,
654 priv->qos_data.def_qos_parm.ac[i].edca_txop);
656 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
659 static ssize_t iwl_dbgfs_led_read(struct file *file, char __user *user_buf,
660 size_t count, loff_t *ppos)
662 struct iwl_priv *priv = file->private_data;
665 const size_t bufsz = sizeof(buf);
667 pos += scnprintf(buf + pos, bufsz - pos,
668 "allow blinking: %s\n",
669 (priv->allow_blinking) ? "True" : "False");
670 if (priv->allow_blinking) {
671 pos += scnprintf(buf + pos, bufsz - pos,
672 "Led blinking rate: %u\n",
673 priv->last_blink_rate);
674 pos += scnprintf(buf + pos, bufsz - pos,
675 "Last blink time: %lu\n",
676 priv->last_blink_time);
679 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
682 static ssize_t iwl_dbgfs_thermal_throttling_read(struct file *file,
683 char __user *user_buf,
684 size_t count, loff_t *ppos)
686 struct iwl_priv *priv = file->private_data;
687 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
688 struct iwl_tt_restriction *restriction;
691 const size_t bufsz = sizeof(buf);
693 pos += scnprintf(buf + pos, bufsz - pos,
694 "Thermal Throttling Mode: %s\n",
695 tt->advanced_tt ? "Advance" : "Legacy");
696 pos += scnprintf(buf + pos, bufsz - pos,
697 "Thermal Throttling State: %d\n",
699 if (tt->advanced_tt) {
700 restriction = tt->restriction + tt->state;
701 pos += scnprintf(buf + pos, bufsz - pos,
703 restriction->tx_stream);
704 pos += scnprintf(buf + pos, bufsz - pos,
706 restriction->rx_stream);
707 pos += scnprintf(buf + pos, bufsz - pos,
711 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
714 static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
715 const char __user *user_buf,
716 size_t count, loff_t *ppos)
718 struct iwl_priv *priv = file->private_data;
723 memset(buf, 0, sizeof(buf));
724 buf_size = min(count, sizeof(buf) - 1);
725 if (copy_from_user(buf, user_buf, buf_size))
727 if (sscanf(buf, "%d", &ht40) != 1)
729 if (!iwl_is_associated(priv))
730 priv->disable_ht40 = ht40 ? true : false;
732 IWL_ERR(priv, "Sta associated with AP - "
733 "Change to 40MHz channel support is not allowed\n");
740 static ssize_t iwl_dbgfs_disable_ht40_read(struct file *file,
741 char __user *user_buf,
742 size_t count, loff_t *ppos)
744 struct iwl_priv *priv = file->private_data;
747 const size_t bufsz = sizeof(buf);
749 pos += scnprintf(buf + pos, bufsz - pos,
750 "11n 40MHz Mode: %s\n",
751 priv->disable_ht40 ? "Disabled" : "Enabled");
752 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
755 static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
756 const char __user *user_buf,
757 size_t count, loff_t *ppos)
759 struct iwl_priv *priv = file->private_data;
764 memset(buf, 0, sizeof(buf));
765 buf_size = min(count, sizeof(buf) - 1);
766 if (copy_from_user(buf, user_buf, buf_size))
769 if (sscanf(buf, "%d", &value) != 1)
773 * Our users expect 0 to be "CAM", but 0 isn't actually
774 * valid here. However, let's not confuse them and present
775 * IWL_POWER_INDEX_1 as "1", not "0".
782 if (value != -1 && (value < 0 || value >= IWL_POWER_NUM))
785 if (!iwl_is_ready_rf(priv))
788 priv->power_data.debug_sleep_level_override = value;
790 mutex_lock(&priv->mutex);
791 iwl_power_update_mode(priv, true);
792 mutex_unlock(&priv->mutex);
797 static ssize_t iwl_dbgfs_sleep_level_override_read(struct file *file,
798 char __user *user_buf,
799 size_t count, loff_t *ppos)
801 struct iwl_priv *priv = file->private_data;
804 const size_t bufsz = sizeof(buf);
806 /* see the write function */
807 value = priv->power_data.debug_sleep_level_override;
811 pos = scnprintf(buf, bufsz, "%d\n", value);
812 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
815 static ssize_t iwl_dbgfs_current_sleep_command_read(struct file *file,
816 char __user *user_buf,
817 size_t count, loff_t *ppos)
819 struct iwl_priv *priv = file->private_data;
822 const size_t bufsz = sizeof(buf);
823 struct iwl_powertable_cmd *cmd = &priv->power_data.sleep_cmd;
825 pos += scnprintf(buf + pos, bufsz - pos,
826 "flags: %#.2x\n", le16_to_cpu(cmd->flags));
827 pos += scnprintf(buf + pos, bufsz - pos,
828 "RX/TX timeout: %d/%d usec\n",
829 le32_to_cpu(cmd->rx_data_timeout),
830 le32_to_cpu(cmd->tx_data_timeout));
831 for (i = 0; i < IWL_POWER_VEC_SIZE; i++)
832 pos += scnprintf(buf + pos, bufsz - pos,
833 "sleep_interval[%d]: %d\n", i,
834 le32_to_cpu(cmd->sleep_interval[i]));
836 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
839 DEBUGFS_READ_WRITE_FILE_OPS(sram);
840 DEBUGFS_READ_WRITE_FILE_OPS(log_event);
841 DEBUGFS_READ_FILE_OPS(nvm);
842 DEBUGFS_READ_FILE_OPS(stations);
843 DEBUGFS_READ_FILE_OPS(channels);
844 DEBUGFS_READ_FILE_OPS(status);
845 DEBUGFS_READ_WRITE_FILE_OPS(interrupt);
846 DEBUGFS_READ_FILE_OPS(qos);
847 DEBUGFS_READ_FILE_OPS(led);
848 DEBUGFS_READ_FILE_OPS(thermal_throttling);
849 DEBUGFS_READ_WRITE_FILE_OPS(disable_ht40);
850 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
851 DEBUGFS_READ_FILE_OPS(current_sleep_command);
853 static ssize_t iwl_dbgfs_traffic_log_read(struct file *file,
854 char __user *user_buf,
855 size_t count, loff_t *ppos)
857 struct iwl_priv *priv = file->private_data;
858 int pos = 0, ofs = 0;
860 struct iwl_tx_queue *txq;
862 struct iwl_rx_queue *rxq = &priv->rxq;
864 int bufsz = ((IWL_TRAFFIC_ENTRIES * IWL_TRAFFIC_ENTRY_SIZE * 64) * 2) +
865 (priv->cfg->num_of_queues * 32 * 8) + 400;
870 IWL_ERR(priv, "txq not ready\n");
873 buf = kzalloc(bufsz, GFP_KERNEL);
875 IWL_ERR(priv, "Can not allocate buffer\n");
878 pos += scnprintf(buf + pos, bufsz - pos, "Tx Queue\n");
879 for (cnt = 0; cnt < priv->hw_params.max_txq_num; cnt++) {
880 txq = &priv->txq[cnt];
882 pos += scnprintf(buf + pos, bufsz - pos,
883 "q[%d]: read_ptr: %u, write_ptr: %u\n",
884 cnt, q->read_ptr, q->write_ptr);
886 if (priv->tx_traffic && (iwl_debug_level & IWL_DL_TX)) {
887 ptr = priv->tx_traffic;
888 pos += scnprintf(buf + pos, bufsz - pos,
889 "Tx Traffic idx: %u\n", priv->tx_traffic_idx);
890 for (cnt = 0, ofs = 0; cnt < IWL_TRAFFIC_ENTRIES; cnt++) {
891 for (entry = 0; entry < IWL_TRAFFIC_ENTRY_SIZE / 16;
892 entry++, ofs += 16) {
893 pos += scnprintf(buf + pos, bufsz - pos,
895 hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
896 buf + pos, bufsz - pos, 0);
897 pos += strlen(buf + pos);
904 pos += scnprintf(buf + pos, bufsz - pos, "Rx Queue\n");
905 pos += scnprintf(buf + pos, bufsz - pos,
906 "read: %u, write: %u\n",
907 rxq->read, rxq->write);
909 if (priv->rx_traffic && (iwl_debug_level & IWL_DL_RX)) {
910 ptr = priv->rx_traffic;
911 pos += scnprintf(buf + pos, bufsz - pos,
912 "Rx Traffic idx: %u\n", priv->rx_traffic_idx);
913 for (cnt = 0, ofs = 0; cnt < IWL_TRAFFIC_ENTRIES; cnt++) {
914 for (entry = 0; entry < IWL_TRAFFIC_ENTRY_SIZE / 16;
915 entry++, ofs += 16) {
916 pos += scnprintf(buf + pos, bufsz - pos,
918 hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
919 buf + pos, bufsz - pos, 0);
920 pos += strlen(buf + pos);
927 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
932 static ssize_t iwl_dbgfs_traffic_log_write(struct file *file,
933 const char __user *user_buf,
934 size_t count, loff_t *ppos)
936 struct iwl_priv *priv = file->private_data;
941 memset(buf, 0, sizeof(buf));
942 buf_size = min(count, sizeof(buf) - 1);
943 if (copy_from_user(buf, user_buf, buf_size))
945 if (sscanf(buf, "%d", &traffic_log) != 1)
947 if (traffic_log == 0)
948 iwl_reset_traffic_log(priv);
953 static ssize_t iwl_dbgfs_tx_queue_read(struct file *file,
954 char __user *user_buf,
955 size_t count, loff_t *ppos) {
957 struct iwl_priv *priv = file->private_data;
958 struct iwl_tx_queue *txq;
964 const size_t bufsz = sizeof(char) * 64 * priv->cfg->num_of_queues;
967 IWL_ERR(priv, "txq not ready\n");
970 buf = kzalloc(bufsz, GFP_KERNEL);
974 for (cnt = 0; cnt < priv->hw_params.max_txq_num; cnt++) {
975 txq = &priv->txq[cnt];
977 pos += scnprintf(buf + pos, bufsz - pos,
978 "hwq %.2d: read=%u write=%u stop=%d"
979 " swq_id=%#.2x (ac %d/hwq %d)\n",
980 cnt, q->read_ptr, q->write_ptr,
981 !!test_bit(cnt, priv->queue_stopped),
983 txq->swq_id & 0x80 ? txq->swq_id & 3 :
985 txq->swq_id & 0x80 ? (txq->swq_id >> 2) &
989 /* for the ACs, display the stop count too */
990 pos += scnprintf(buf + pos, bufsz - pos,
992 atomic_read(&priv->queue_stop_count[cnt]));
994 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
999 static ssize_t iwl_dbgfs_rx_queue_read(struct file *file,
1000 char __user *user_buf,
1001 size_t count, loff_t *ppos) {
1003 struct iwl_priv *priv = file->private_data;
1004 struct iwl_rx_queue *rxq = &priv->rxq;
1007 const size_t bufsz = sizeof(buf);
1009 pos += scnprintf(buf + pos, bufsz - pos, "read: %u\n",
1011 pos += scnprintf(buf + pos, bufsz - pos, "write: %u\n",
1013 pos += scnprintf(buf + pos, bufsz - pos, "free_count: %u\n",
1015 pos += scnprintf(buf + pos, bufsz - pos, "closed_rb_num: %u\n",
1016 le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF);
1017 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1020 static ssize_t iwl_dbgfs_ucode_rx_stats_read(struct file *file,
1021 char __user *user_buf,
1022 size_t count, loff_t *ppos)
1024 struct iwl_priv *priv = file->private_data;
1025 return priv->cfg->ops->lib->debugfs_ops.rx_stats_read(file,
1026 user_buf, count, ppos);
1029 static ssize_t iwl_dbgfs_ucode_tx_stats_read(struct file *file,
1030 char __user *user_buf,
1031 size_t count, loff_t *ppos)
1033 struct iwl_priv *priv = file->private_data;
1034 return priv->cfg->ops->lib->debugfs_ops.tx_stats_read(file,
1035 user_buf, count, ppos);
1038 static ssize_t iwl_dbgfs_ucode_general_stats_read(struct file *file,
1039 char __user *user_buf,
1040 size_t count, loff_t *ppos)
1042 struct iwl_priv *priv = file->private_data;
1043 return priv->cfg->ops->lib->debugfs_ops.general_stats_read(file,
1044 user_buf, count, ppos);
1047 static ssize_t iwl_dbgfs_sensitivity_read(struct file *file,
1048 char __user *user_buf,
1049 size_t count, loff_t *ppos) {
1051 struct iwl_priv *priv = file->private_data;
1055 int bufsz = sizeof(struct iwl_sensitivity_data) * 4 + 100;
1057 struct iwl_sensitivity_data *data;
1059 data = &priv->sensitivity_data;
1060 buf = kzalloc(bufsz, GFP_KERNEL);
1062 IWL_ERR(priv, "Can not allocate Buffer\n");
1066 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm:\t\t\t %u\n",
1067 data->auto_corr_ofdm);
1068 pos += scnprintf(buf + pos, bufsz - pos,
1069 "auto_corr_ofdm_mrc:\t\t %u\n",
1070 data->auto_corr_ofdm_mrc);
1071 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_x1:\t\t %u\n",
1072 data->auto_corr_ofdm_x1);
1073 pos += scnprintf(buf + pos, bufsz - pos,
1074 "auto_corr_ofdm_mrc_x1:\t\t %u\n",
1075 data->auto_corr_ofdm_mrc_x1);
1076 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck:\t\t\t %u\n",
1077 data->auto_corr_cck);
1078 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck_mrc:\t\t %u\n",
1079 data->auto_corr_cck_mrc);
1080 pos += scnprintf(buf + pos, bufsz - pos,
1081 "last_bad_plcp_cnt_ofdm:\t\t %u\n",
1082 data->last_bad_plcp_cnt_ofdm);
1083 pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_ofdm:\t\t %u\n",
1084 data->last_fa_cnt_ofdm);
1085 pos += scnprintf(buf + pos, bufsz - pos,
1086 "last_bad_plcp_cnt_cck:\t\t %u\n",
1087 data->last_bad_plcp_cnt_cck);
1088 pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_cck:\t\t %u\n",
1089 data->last_fa_cnt_cck);
1090 pos += scnprintf(buf + pos, bufsz - pos, "nrg_curr_state:\t\t\t %u\n",
1091 data->nrg_curr_state);
1092 pos += scnprintf(buf + pos, bufsz - pos, "nrg_prev_state:\t\t\t %u\n",
1093 data->nrg_prev_state);
1094 pos += scnprintf(buf + pos, bufsz - pos, "nrg_value:\t\t\t");
1095 for (cnt = 0; cnt < 10; cnt++) {
1096 pos += scnprintf(buf + pos, bufsz - pos, " %u",
1097 data->nrg_value[cnt]);
1099 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1100 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_rssi:\t\t");
1101 for (cnt = 0; cnt < NRG_NUM_PREV_STAT_L; cnt++) {
1102 pos += scnprintf(buf + pos, bufsz - pos, " %u",
1103 data->nrg_silence_rssi[cnt]);
1105 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1106 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_ref:\t\t %u\n",
1107 data->nrg_silence_ref);
1108 pos += scnprintf(buf + pos, bufsz - pos, "nrg_energy_idx:\t\t\t %u\n",
1109 data->nrg_energy_idx);
1110 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_idx:\t\t %u\n",
1111 data->nrg_silence_idx);
1112 pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_cck:\t\t\t %u\n",
1114 pos += scnprintf(buf + pos, bufsz - pos,
1115 "nrg_auto_corr_silence_diff:\t %u\n",
1116 data->nrg_auto_corr_silence_diff);
1117 pos += scnprintf(buf + pos, bufsz - pos, "num_in_cck_no_fa:\t\t %u\n",
1118 data->num_in_cck_no_fa);
1119 pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_ofdm:\t\t\t %u\n",
1122 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1128 static ssize_t iwl_dbgfs_chain_noise_read(struct file *file,
1129 char __user *user_buf,
1130 size_t count, loff_t *ppos) {
1132 struct iwl_priv *priv = file->private_data;
1136 int bufsz = sizeof(struct iwl_chain_noise_data) * 4 + 100;
1138 struct iwl_chain_noise_data *data;
1140 data = &priv->chain_noise_data;
1141 buf = kzalloc(bufsz, GFP_KERNEL);
1143 IWL_ERR(priv, "Can not allocate Buffer\n");
1147 pos += scnprintf(buf + pos, bufsz - pos, "active_chains:\t\t\t %u\n",
1148 data->active_chains);
1149 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_a:\t\t\t %u\n",
1150 data->chain_noise_a);
1151 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_b:\t\t\t %u\n",
1152 data->chain_noise_b);
1153 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_c:\t\t\t %u\n",
1154 data->chain_noise_c);
1155 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_a:\t\t\t %u\n",
1156 data->chain_signal_a);
1157 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_b:\t\t\t %u\n",
1158 data->chain_signal_b);
1159 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_c:\t\t\t %u\n",
1160 data->chain_signal_c);
1161 pos += scnprintf(buf + pos, bufsz - pos, "beacon_count:\t\t\t %u\n",
1162 data->beacon_count);
1164 pos += scnprintf(buf + pos, bufsz - pos, "disconn_array:\t\t\t");
1165 for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
1166 pos += scnprintf(buf + pos, bufsz - pos, " %u",
1167 data->disconn_array[cnt]);
1169 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1170 pos += scnprintf(buf + pos, bufsz - pos, "delta_gain_code:\t\t");
1171 for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
1172 pos += scnprintf(buf + pos, bufsz - pos, " %u",
1173 data->delta_gain_code[cnt]);
1175 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1176 pos += scnprintf(buf + pos, bufsz - pos, "radio_write:\t\t\t %u\n",
1178 pos += scnprintf(buf + pos, bufsz - pos, "state:\t\t\t\t %u\n",
1181 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1186 static ssize_t iwl_dbgfs_power_save_status_read(struct file *file,
1187 char __user *user_buf,
1188 size_t count, loff_t *ppos)
1190 struct iwl_priv *priv = file->private_data;
1193 const size_t bufsz = sizeof(buf);
1196 pwrsave_status = iwl_read32(priv, CSR_GP_CNTRL) &
1197 CSR_GP_REG_POWER_SAVE_STATUS_MSK;
1199 pos += scnprintf(buf + pos, bufsz - pos, "Power Save Status: ");
1200 pos += scnprintf(buf + pos, bufsz - pos, "%s\n",
1201 (pwrsave_status == CSR_GP_REG_NO_POWER_SAVE) ? "none" :
1202 (pwrsave_status == CSR_GP_REG_MAC_POWER_SAVE) ? "MAC" :
1203 (pwrsave_status == CSR_GP_REG_PHY_POWER_SAVE) ? "PHY" :
1206 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1209 static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
1210 const char __user *user_buf,
1211 size_t count, loff_t *ppos)
1213 struct iwl_priv *priv = file->private_data;
1218 memset(buf, 0, sizeof(buf));
1219 buf_size = min(count, sizeof(buf) - 1);
1220 if (copy_from_user(buf, user_buf, buf_size))
1222 if (sscanf(buf, "%d", &clear) != 1)
1225 /* make request to uCode to retrieve statistics information */
1226 mutex_lock(&priv->mutex);
1227 iwl_send_statistics_request(priv, CMD_SYNC, true);
1228 mutex_unlock(&priv->mutex);
1233 static ssize_t iwl_dbgfs_csr_write(struct file *file,
1234 const char __user *user_buf,
1235 size_t count, loff_t *ppos)
1237 struct iwl_priv *priv = file->private_data;
1242 memset(buf, 0, sizeof(buf));
1243 buf_size = min(count, sizeof(buf) - 1);
1244 if (copy_from_user(buf, user_buf, buf_size))
1246 if (sscanf(buf, "%d", &csr) != 1)
1249 if (priv->cfg->ops->lib->dump_csr)
1250 priv->cfg->ops->lib->dump_csr(priv);
1255 static ssize_t iwl_dbgfs_ucode_tracing_read(struct file *file,
1256 char __user *user_buf,
1257 size_t count, loff_t *ppos) {
1259 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1262 const size_t bufsz = sizeof(buf);
1264 pos += scnprintf(buf + pos, bufsz - pos, "ucode trace timer is %s\n",
1265 priv->event_log.ucode_trace ? "On" : "Off");
1266 pos += scnprintf(buf + pos, bufsz - pos, "non_wraps_count:\t\t %u\n",
1267 priv->event_log.non_wraps_count);
1268 pos += scnprintf(buf + pos, bufsz - pos, "wraps_once_count:\t\t %u\n",
1269 priv->event_log.wraps_once_count);
1270 pos += scnprintf(buf + pos, bufsz - pos, "wraps_more_count:\t\t %u\n",
1271 priv->event_log.wraps_more_count);
1273 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1276 static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
1277 const char __user *user_buf,
1278 size_t count, loff_t *ppos)
1280 struct iwl_priv *priv = file->private_data;
1285 memset(buf, 0, sizeof(buf));
1286 buf_size = min(count, sizeof(buf) - 1);
1287 if (copy_from_user(buf, user_buf, buf_size))
1289 if (sscanf(buf, "%d", &trace) != 1)
1293 priv->event_log.ucode_trace = true;
1294 /* schedule the ucode timer to occur in UCODE_TRACE_PERIOD */
1295 mod_timer(&priv->ucode_trace,
1296 jiffies + msecs_to_jiffies(UCODE_TRACE_PERIOD));
1298 priv->event_log.ucode_trace = false;
1299 del_timer_sync(&priv->ucode_trace);
1305 static ssize_t iwl_dbgfs_rxon_flags_read(struct file *file,
1306 char __user *user_buf,
1307 size_t count, loff_t *ppos) {
1309 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1313 len = sprintf(buf, "0x%04X\n", le32_to_cpu(priv->active_rxon.flags));
1314 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1317 static ssize_t iwl_dbgfs_rxon_filter_flags_read(struct file *file,
1318 char __user *user_buf,
1319 size_t count, loff_t *ppos) {
1321 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1325 len = sprintf(buf, "0x%04X\n",
1326 le32_to_cpu(priv->active_rxon.filter_flags));
1327 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1330 static ssize_t iwl_dbgfs_fh_reg_read(struct file *file,
1331 char __user *user_buf,
1332 size_t count, loff_t *ppos)
1334 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1337 ssize_t ret = -EFAULT;
1339 if (priv->cfg->ops->lib->dump_fh) {
1340 ret = pos = priv->cfg->ops->lib->dump_fh(priv, &buf, true);
1342 ret = simple_read_from_buffer(user_buf,
1343 count, ppos, buf, pos);
1351 static ssize_t iwl_dbgfs_missed_beacon_read(struct file *file,
1352 char __user *user_buf,
1353 size_t count, loff_t *ppos) {
1355 struct iwl_priv *priv = file->private_data;
1358 const size_t bufsz = sizeof(buf);
1360 pos += scnprintf(buf + pos, bufsz - pos, "%d\n",
1361 priv->missed_beacon_threshold);
1363 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1366 static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
1367 const char __user *user_buf,
1368 size_t count, loff_t *ppos)
1370 struct iwl_priv *priv = file->private_data;
1375 memset(buf, 0, sizeof(buf));
1376 buf_size = min(count, sizeof(buf) - 1);
1377 if (copy_from_user(buf, user_buf, buf_size))
1379 if (sscanf(buf, "%d", &missed) != 1)
1382 if (missed < IWL_MISSED_BEACON_THRESHOLD_MIN ||
1383 missed > IWL_MISSED_BEACON_THRESHOLD_MAX)
1384 priv->missed_beacon_threshold =
1385 IWL_MISSED_BEACON_THRESHOLD_DEF;
1387 priv->missed_beacon_threshold = missed;
1392 static ssize_t iwl_dbgfs_plcp_delta_read(struct file *file,
1393 char __user *user_buf,
1394 size_t count, loff_t *ppos) {
1396 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1399 const size_t bufsz = sizeof(buf);
1401 pos += scnprintf(buf + pos, bufsz - pos, "%u\n",
1402 priv->cfg->plcp_delta_threshold);
1404 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1407 static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
1408 const char __user *user_buf,
1409 size_t count, loff_t *ppos) {
1411 struct iwl_priv *priv = file->private_data;
1416 memset(buf, 0, sizeof(buf));
1417 buf_size = min(count, sizeof(buf) - 1);
1418 if (copy_from_user(buf, user_buf, buf_size))
1420 if (sscanf(buf, "%d", &plcp) != 1)
1422 if ((plcp <= IWL_MAX_PLCP_ERR_THRESHOLD_MIN) ||
1423 (plcp > IWL_MAX_PLCP_ERR_THRESHOLD_MAX))
1424 priv->cfg->plcp_delta_threshold =
1425 IWL_MAX_PLCP_ERR_THRESHOLD_DEF;
1427 priv->cfg->plcp_delta_threshold = plcp;
1431 static ssize_t iwl_dbgfs_force_reset_read(struct file *file,
1432 char __user *user_buf,
1433 size_t count, loff_t *ppos) {
1435 struct iwl_priv *priv = file->private_data;
1438 const size_t bufsz = sizeof(buf);
1439 struct iwl_force_reset *force_reset;
1441 for (i = 0; i < IWL_MAX_FORCE_RESET; i++) {
1442 force_reset = &priv->force_reset[i];
1443 pos += scnprintf(buf + pos, bufsz - pos,
1444 "Force reset method %d\n", i);
1445 pos += scnprintf(buf + pos, bufsz - pos,
1446 "\tnumber of reset request: %d\n",
1447 force_reset->reset_request_count);
1448 pos += scnprintf(buf + pos, bufsz - pos,
1449 "\tnumber of reset request success: %d\n",
1450 force_reset->reset_success_count);
1451 pos += scnprintf(buf + pos, bufsz - pos,
1452 "\tnumber of reset request reject: %d\n",
1453 force_reset->reset_reject_count);
1454 pos += scnprintf(buf + pos, bufsz - pos,
1455 "\treset duration: %lu\n",
1456 force_reset->reset_duration);
1458 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1461 static ssize_t iwl_dbgfs_force_reset_write(struct file *file,
1462 const char __user *user_buf,
1463 size_t count, loff_t *ppos) {
1465 struct iwl_priv *priv = file->private_data;
1470 memset(buf, 0, sizeof(buf));
1471 buf_size = min(count, sizeof(buf) - 1);
1472 if (copy_from_user(buf, user_buf, buf_size))
1474 if (sscanf(buf, "%d", &reset) != 1)
1479 ret = iwl_force_reset(priv, reset);
1484 return ret ? ret : count;
1487 DEBUGFS_READ_FILE_OPS(rx_statistics);
1488 DEBUGFS_READ_FILE_OPS(tx_statistics);
1489 DEBUGFS_READ_WRITE_FILE_OPS(traffic_log);
1490 DEBUGFS_READ_FILE_OPS(rx_queue);
1491 DEBUGFS_READ_FILE_OPS(tx_queue);
1492 DEBUGFS_READ_FILE_OPS(ucode_rx_stats);
1493 DEBUGFS_READ_FILE_OPS(ucode_tx_stats);
1494 DEBUGFS_READ_FILE_OPS(ucode_general_stats);
1495 DEBUGFS_READ_FILE_OPS(sensitivity);
1496 DEBUGFS_READ_FILE_OPS(chain_noise);
1497 DEBUGFS_READ_FILE_OPS(power_save_status);
1498 DEBUGFS_WRITE_FILE_OPS(clear_ucode_statistics);
1499 DEBUGFS_WRITE_FILE_OPS(clear_traffic_statistics);
1500 DEBUGFS_WRITE_FILE_OPS(csr);
1501 DEBUGFS_READ_WRITE_FILE_OPS(ucode_tracing);
1502 DEBUGFS_READ_FILE_OPS(fh_reg);
1503 DEBUGFS_READ_WRITE_FILE_OPS(missed_beacon);
1504 DEBUGFS_READ_WRITE_FILE_OPS(plcp_delta);
1505 DEBUGFS_READ_WRITE_FILE_OPS(force_reset);
1506 DEBUGFS_READ_FILE_OPS(rxon_flags);
1507 DEBUGFS_READ_FILE_OPS(rxon_filter_flags);
1510 * Create the debugfs files and directories
1513 int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
1515 struct dentry *phyd = priv->hw->wiphy->debugfsdir;
1516 struct dentry *dir_drv, *dir_data, *dir_rf, *dir_debug;
1518 dir_drv = debugfs_create_dir(name, phyd);
1522 priv->debugfs_dir = dir_drv;
1524 dir_data = debugfs_create_dir("data", dir_drv);
1527 dir_rf = debugfs_create_dir("rf", dir_drv);
1530 dir_debug = debugfs_create_dir("debug", dir_drv);
1534 DEBUGFS_ADD_FILE(nvm, dir_data, S_IRUSR);
1535 DEBUGFS_ADD_FILE(sram, dir_data, S_IWUSR | S_IRUSR);
1536 DEBUGFS_ADD_FILE(log_event, dir_data, S_IWUSR | S_IRUSR);
1537 DEBUGFS_ADD_FILE(stations, dir_data, S_IRUSR);
1538 DEBUGFS_ADD_FILE(channels, dir_data, S_IRUSR);
1539 DEBUGFS_ADD_FILE(status, dir_data, S_IRUSR);
1540 DEBUGFS_ADD_FILE(interrupt, dir_data, S_IWUSR | S_IRUSR);
1541 DEBUGFS_ADD_FILE(qos, dir_data, S_IRUSR);
1542 DEBUGFS_ADD_FILE(led, dir_data, S_IRUSR);
1543 if (!priv->cfg->broken_powersave) {
1544 DEBUGFS_ADD_FILE(sleep_level_override, dir_data,
1546 DEBUGFS_ADD_FILE(current_sleep_command, dir_data, S_IRUSR);
1548 DEBUGFS_ADD_FILE(thermal_throttling, dir_data, S_IRUSR);
1549 DEBUGFS_ADD_FILE(disable_ht40, dir_data, S_IWUSR | S_IRUSR);
1550 DEBUGFS_ADD_FILE(rx_statistics, dir_debug, S_IRUSR);
1551 DEBUGFS_ADD_FILE(tx_statistics, dir_debug, S_IRUSR);
1552 DEBUGFS_ADD_FILE(traffic_log, dir_debug, S_IWUSR | S_IRUSR);
1553 DEBUGFS_ADD_FILE(rx_queue, dir_debug, S_IRUSR);
1554 DEBUGFS_ADD_FILE(tx_queue, dir_debug, S_IRUSR);
1555 DEBUGFS_ADD_FILE(power_save_status, dir_debug, S_IRUSR);
1556 DEBUGFS_ADD_FILE(clear_ucode_statistics, dir_debug, S_IWUSR);
1557 DEBUGFS_ADD_FILE(clear_traffic_statistics, dir_debug, S_IWUSR);
1558 DEBUGFS_ADD_FILE(csr, dir_debug, S_IWUSR);
1559 DEBUGFS_ADD_FILE(fh_reg, dir_debug, S_IRUSR);
1560 DEBUGFS_ADD_FILE(missed_beacon, dir_debug, S_IWUSR);
1561 DEBUGFS_ADD_FILE(plcp_delta, dir_debug, S_IWUSR | S_IRUSR);
1562 DEBUGFS_ADD_FILE(force_reset, dir_debug, S_IWUSR | S_IRUSR);
1563 DEBUGFS_ADD_FILE(ucode_rx_stats, dir_debug, S_IRUSR);
1564 DEBUGFS_ADD_FILE(ucode_tx_stats, dir_debug, S_IRUSR);
1565 DEBUGFS_ADD_FILE(ucode_general_stats, dir_debug, S_IRUSR);
1567 if (priv->cfg->sensitivity_calib_by_driver)
1568 DEBUGFS_ADD_FILE(sensitivity, dir_debug, S_IRUSR);
1569 if (priv->cfg->chain_noise_calib_by_driver)
1570 DEBUGFS_ADD_FILE(chain_noise, dir_debug, S_IRUSR);
1571 if (priv->cfg->ucode_tracing)
1572 DEBUGFS_ADD_FILE(ucode_tracing, dir_debug, S_IWUSR | S_IRUSR);
1573 DEBUGFS_ADD_FILE(rxon_flags, dir_debug, S_IWUSR);
1574 DEBUGFS_ADD_FILE(rxon_filter_flags, dir_debug, S_IWUSR);
1575 if (priv->cfg->sensitivity_calib_by_driver)
1576 DEBUGFS_ADD_BOOL(disable_sensitivity, dir_rf,
1577 &priv->disable_sens_cal);
1578 if (priv->cfg->chain_noise_calib_by_driver)
1579 DEBUGFS_ADD_BOOL(disable_chain_noise, dir_rf,
1580 &priv->disable_chain_noise_cal);
1581 if (priv->cfg->tx_power_by_driver)
1582 DEBUGFS_ADD_BOOL(disable_tx_power, dir_rf,
1583 &priv->disable_tx_power_cal);
1587 IWL_ERR(priv, "Can't create the debugfs directory\n");
1588 iwl_dbgfs_unregister(priv);
1591 EXPORT_SYMBOL(iwl_dbgfs_register);
1594 * Remove the debugfs files and directories
1597 void iwl_dbgfs_unregister(struct iwl_priv *priv)
1599 if (!priv->debugfs_dir)
1602 debugfs_remove_recursive(priv->debugfs_dir);
1603 priv->debugfs_dir = NULL;
1605 EXPORT_SYMBOL(iwl_dbgfs_unregister);