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];
307 pos += scnprintf(buf + pos, bufsz - pos,
308 "station %d:\ngeneral data:\n", i+1);
309 pos += scnprintf(buf + pos, bufsz - pos, "id: %u\n",
310 station->sta.sta.sta_id);
311 pos += scnprintf(buf + pos, bufsz - pos, "mode: %u\n",
313 pos += scnprintf(buf + pos, bufsz - pos,
315 station->sta.station_flags_msk);
316 pos += scnprintf(buf + pos, bufsz - pos, "tid data:\n");
317 pos += scnprintf(buf + pos, bufsz - pos,
318 "seq_num\t\ttxq_id");
319 pos += scnprintf(buf + pos, bufsz - pos,
320 "\tframe_count\twait_for_ba\t");
321 pos += scnprintf(buf + pos, bufsz - pos,
322 "start_idx\tbitmap0\t");
323 pos += scnprintf(buf + pos, bufsz - pos,
324 "bitmap1\trate_n_flags");
325 pos += scnprintf(buf + pos, bufsz - pos, "\n");
327 for (j = 0; j < MAX_TID_COUNT; j++) {
328 pos += scnprintf(buf + pos, bufsz - pos,
330 station->tid[j].seq_number);
331 pos += scnprintf(buf + pos, bufsz - pos,
332 "\t%u\t\t%u\t\t%u\t\t",
333 station->tid[j].agg.txq_id,
334 station->tid[j].agg.frame_count,
335 station->tid[j].agg.wait_for_ba);
336 pos += scnprintf(buf + pos, bufsz - pos,
338 station->tid[j].agg.start_idx,
339 (unsigned long long)station->tid[j].agg.bitmap,
340 station->tid[j].agg.rate_n_flags);
341 pos += scnprintf(buf + pos, bufsz - pos, "\n");
343 pos += scnprintf(buf + pos, bufsz - pos, "\n");
347 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
352 static ssize_t iwl_dbgfs_nvm_read(struct file *file,
353 char __user *user_buf,
358 struct iwl_priv *priv = file->private_data;
359 int pos = 0, ofs = 0, buf_size = 0;
363 size_t eeprom_len = priv->cfg->eeprom_size;
364 buf_size = 4 * eeprom_len + 256;
366 if (eeprom_len % 16) {
367 IWL_ERR(priv, "NVM size is not multiple of 16.\n");
373 IWL_ERR(priv, "Invalid EEPROM/OTP memory\n");
377 /* 4 characters for byte 0xYY */
378 buf = kzalloc(buf_size, GFP_KERNEL);
380 IWL_ERR(priv, "Can not allocate Buffer\n");
383 eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
384 pos += scnprintf(buf + pos, buf_size - pos, "NVM Type: %s, "
386 (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP)
387 ? "OTP" : "EEPROM", eeprom_ver);
388 for (ofs = 0 ; ofs < eeprom_len ; ofs += 16) {
389 pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x ", ofs);
390 hex_dump_to_buffer(ptr + ofs, 16 , 16, 2, buf + pos,
392 pos += strlen(buf + pos);
393 if (buf_size - pos > 0)
397 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
402 static ssize_t iwl_dbgfs_log_event_read(struct file *file,
403 char __user *user_buf,
404 size_t count, loff_t *ppos)
406 struct iwl_priv *priv = file->private_data;
409 ssize_t ret = -ENOMEM;
411 ret = pos = priv->cfg->ops->lib->dump_nic_event_log(
412 priv, true, &buf, true);
414 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
420 static ssize_t iwl_dbgfs_log_event_write(struct file *file,
421 const char __user *user_buf,
422 size_t count, loff_t *ppos)
424 struct iwl_priv *priv = file->private_data;
429 memset(buf, 0, sizeof(buf));
430 buf_size = min(count, sizeof(buf) - 1);
431 if (copy_from_user(buf, user_buf, buf_size))
433 if (sscanf(buf, "%d", &event_log_flag) != 1)
435 if (event_log_flag == 1)
436 priv->cfg->ops->lib->dump_nic_event_log(priv, true,
444 static ssize_t iwl_dbgfs_channels_read(struct file *file, char __user *user_buf,
445 size_t count, loff_t *ppos)
447 struct iwl_priv *priv = file->private_data;
448 struct ieee80211_channel *channels = NULL;
449 const struct ieee80211_supported_band *supp_band = NULL;
450 int pos = 0, i, bufsz = PAGE_SIZE;
454 if (!test_bit(STATUS_GEO_CONFIGURED, &priv->status))
457 buf = kzalloc(bufsz, GFP_KERNEL);
459 IWL_ERR(priv, "Can not allocate Buffer\n");
463 supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_2GHZ);
465 channels = supp_band->channels;
467 pos += scnprintf(buf + pos, bufsz - pos,
468 "Displaying %d channels in 2.4GHz band 802.11bg):\n",
469 supp_band->n_channels);
471 for (i = 0; i < supp_band->n_channels; i++)
472 pos += scnprintf(buf + pos, bufsz - pos,
473 "%d: %ddBm: BSS%s%s, %s.\n",
474 ieee80211_frequency_to_channel(
475 channels[i].center_freq),
476 channels[i].max_power,
477 channels[i].flags & IEEE80211_CHAN_RADAR ?
478 " (IEEE 802.11h required)" : "",
479 ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
480 || (channels[i].flags &
481 IEEE80211_CHAN_RADAR)) ? "" :
484 IEEE80211_CHAN_PASSIVE_SCAN ?
485 "passive only" : "active/passive");
487 supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_5GHZ);
489 channels = supp_band->channels;
491 pos += scnprintf(buf + pos, bufsz - pos,
492 "Displaying %d channels in 5.2GHz band (802.11a)\n",
493 supp_band->n_channels);
495 for (i = 0; i < supp_band->n_channels; i++)
496 pos += scnprintf(buf + pos, bufsz - pos,
497 "%d: %ddBm: BSS%s%s, %s.\n",
498 ieee80211_frequency_to_channel(
499 channels[i].center_freq),
500 channels[i].max_power,
501 channels[i].flags & IEEE80211_CHAN_RADAR ?
502 " (IEEE 802.11h required)" : "",
503 ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
504 || (channels[i].flags &
505 IEEE80211_CHAN_RADAR)) ? "" :
508 IEEE80211_CHAN_PASSIVE_SCAN ?
509 "passive only" : "active/passive");
511 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
516 static ssize_t iwl_dbgfs_status_read(struct file *file,
517 char __user *user_buf,
518 size_t count, loff_t *ppos) {
520 struct iwl_priv *priv = file->private_data;
523 const size_t bufsz = sizeof(buf);
525 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_ACTIVE:\t %d\n",
526 test_bit(STATUS_HCMD_ACTIVE, &priv->status));
527 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INT_ENABLED:\t %d\n",
528 test_bit(STATUS_INT_ENABLED, &priv->status));
529 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_RF_KILL_HW:\t %d\n",
530 test_bit(STATUS_RF_KILL_HW, &priv->status));
531 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_CT_KILL:\t\t %d\n",
532 test_bit(STATUS_CT_KILL, &priv->status));
533 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INIT:\t\t %d\n",
534 test_bit(STATUS_INIT, &priv->status));
535 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_ALIVE:\t\t %d\n",
536 test_bit(STATUS_ALIVE, &priv->status));
537 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_READY:\t\t %d\n",
538 test_bit(STATUS_READY, &priv->status));
539 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_TEMPERATURE:\t %d\n",
540 test_bit(STATUS_TEMPERATURE, &priv->status));
541 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_GEO_CONFIGURED:\t %d\n",
542 test_bit(STATUS_GEO_CONFIGURED, &priv->status));
543 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_EXIT_PENDING:\t %d\n",
544 test_bit(STATUS_EXIT_PENDING, &priv->status));
545 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_STATISTICS:\t %d\n",
546 test_bit(STATUS_STATISTICS, &priv->status));
547 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCANNING:\t %d\n",
548 test_bit(STATUS_SCANNING, &priv->status));
549 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_ABORTING:\t %d\n",
550 test_bit(STATUS_SCAN_ABORTING, &priv->status));
551 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_HW:\t\t %d\n",
552 test_bit(STATUS_SCAN_HW, &priv->status));
553 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_POWER_PMI:\t %d\n",
554 test_bit(STATUS_POWER_PMI, &priv->status));
555 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_FW_ERROR:\t %d\n",
556 test_bit(STATUS_FW_ERROR, &priv->status));
557 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
560 static ssize_t iwl_dbgfs_interrupt_read(struct file *file,
561 char __user *user_buf,
562 size_t count, loff_t *ppos) {
564 struct iwl_priv *priv = file->private_data;
568 int bufsz = 24 * 64; /* 24 items * 64 char per item */
571 buf = kzalloc(bufsz, GFP_KERNEL);
573 IWL_ERR(priv, "Can not allocate Buffer\n");
577 pos += scnprintf(buf + pos, bufsz - pos,
578 "Interrupt Statistics Report:\n");
580 pos += scnprintf(buf + pos, bufsz - pos, "HW Error:\t\t\t %u\n",
582 pos += scnprintf(buf + pos, bufsz - pos, "SW Error:\t\t\t %u\n",
584 if (priv->isr_stats.sw > 0) {
585 pos += scnprintf(buf + pos, bufsz - pos,
586 "\tLast Restarting Code: 0x%X\n",
587 priv->isr_stats.sw_err);
589 #ifdef CONFIG_IWLWIFI_DEBUG
590 pos += scnprintf(buf + pos, bufsz - pos, "Frame transmitted:\t\t %u\n",
591 priv->isr_stats.sch);
592 pos += scnprintf(buf + pos, bufsz - pos, "Alive interrupt:\t\t %u\n",
593 priv->isr_stats.alive);
595 pos += scnprintf(buf + pos, bufsz - pos,
596 "HW RF KILL switch toggled:\t %u\n",
597 priv->isr_stats.rfkill);
599 pos += scnprintf(buf + pos, bufsz - pos, "CT KILL:\t\t\t %u\n",
600 priv->isr_stats.ctkill);
602 pos += scnprintf(buf + pos, bufsz - pos, "Wakeup Interrupt:\t\t %u\n",
603 priv->isr_stats.wakeup);
605 pos += scnprintf(buf + pos, bufsz - pos,
606 "Rx command responses:\t\t %u\n",
608 for (cnt = 0; cnt < REPLY_MAX; cnt++) {
609 if (priv->isr_stats.rx_handlers[cnt] > 0)
610 pos += scnprintf(buf + pos, bufsz - pos,
611 "\tRx handler[%36s]:\t\t %u\n",
613 priv->isr_stats.rx_handlers[cnt]);
616 pos += scnprintf(buf + pos, bufsz - pos, "Tx/FH interrupt:\t\t %u\n",
619 pos += scnprintf(buf + pos, bufsz - pos, "Unexpected INTA:\t\t %u\n",
620 priv->isr_stats.unhandled);
622 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
627 static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
628 const char __user *user_buf,
629 size_t count, loff_t *ppos)
631 struct iwl_priv *priv = file->private_data;
636 memset(buf, 0, sizeof(buf));
637 buf_size = min(count, sizeof(buf) - 1);
638 if (copy_from_user(buf, user_buf, buf_size))
640 if (sscanf(buf, "%x", &reset_flag) != 1)
643 iwl_clear_isr_stats(priv);
648 static ssize_t iwl_dbgfs_qos_read(struct file *file, char __user *user_buf,
649 size_t count, loff_t *ppos)
651 struct iwl_priv *priv = file->private_data;
654 const size_t bufsz = sizeof(buf);
656 for (i = 0; i < AC_NUM; i++) {
657 pos += scnprintf(buf + pos, bufsz - pos,
658 "\tcw_min\tcw_max\taifsn\ttxop\n");
659 pos += scnprintf(buf + pos, bufsz - pos,
660 "AC[%d]\t%u\t%u\t%u\t%u\n", i,
661 priv->qos_data.def_qos_parm.ac[i].cw_min,
662 priv->qos_data.def_qos_parm.ac[i].cw_max,
663 priv->qos_data.def_qos_parm.ac[i].aifsn,
664 priv->qos_data.def_qos_parm.ac[i].edca_txop);
666 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
669 static ssize_t iwl_dbgfs_led_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 pos += scnprintf(buf + pos, bufsz - pos,
678 "allow blinking: %s\n",
679 (priv->allow_blinking) ? "True" : "False");
680 if (priv->allow_blinking) {
681 pos += scnprintf(buf + pos, bufsz - pos,
682 "Led blinking rate: %u\n",
683 priv->last_blink_rate);
684 pos += scnprintf(buf + pos, bufsz - pos,
685 "Last blink time: %lu\n",
686 priv->last_blink_time);
689 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
692 static ssize_t iwl_dbgfs_thermal_throttling_read(struct file *file,
693 char __user *user_buf,
694 size_t count, loff_t *ppos)
696 struct iwl_priv *priv = file->private_data;
697 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
698 struct iwl_tt_restriction *restriction;
701 const size_t bufsz = sizeof(buf);
703 pos += scnprintf(buf + pos, bufsz - pos,
704 "Thermal Throttling Mode: %s\n",
705 tt->advanced_tt ? "Advance" : "Legacy");
706 pos += scnprintf(buf + pos, bufsz - pos,
707 "Thermal Throttling State: %d\n",
709 if (tt->advanced_tt) {
710 restriction = tt->restriction + tt->state;
711 pos += scnprintf(buf + pos, bufsz - pos,
713 restriction->tx_stream);
714 pos += scnprintf(buf + pos, bufsz - pos,
716 restriction->rx_stream);
717 pos += scnprintf(buf + pos, bufsz - pos,
721 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
724 static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
725 const char __user *user_buf,
726 size_t count, loff_t *ppos)
728 struct iwl_priv *priv = file->private_data;
733 memset(buf, 0, sizeof(buf));
734 buf_size = min(count, sizeof(buf) - 1);
735 if (copy_from_user(buf, user_buf, buf_size))
737 if (sscanf(buf, "%d", &ht40) != 1)
739 if (!iwl_is_associated(priv))
740 priv->disable_ht40 = ht40 ? true : false;
742 IWL_ERR(priv, "Sta associated with AP - "
743 "Change to 40MHz channel support is not allowed\n");
750 static ssize_t iwl_dbgfs_disable_ht40_read(struct file *file,
751 char __user *user_buf,
752 size_t count, loff_t *ppos)
754 struct iwl_priv *priv = file->private_data;
757 const size_t bufsz = sizeof(buf);
759 pos += scnprintf(buf + pos, bufsz - pos,
760 "11n 40MHz Mode: %s\n",
761 priv->disable_ht40 ? "Disabled" : "Enabled");
762 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
765 static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
766 const char __user *user_buf,
767 size_t count, loff_t *ppos)
769 struct iwl_priv *priv = file->private_data;
774 memset(buf, 0, sizeof(buf));
775 buf_size = min(count, sizeof(buf) - 1);
776 if (copy_from_user(buf, user_buf, buf_size))
779 if (sscanf(buf, "%d", &value) != 1)
783 * Our users expect 0 to be "CAM", but 0 isn't actually
784 * valid here. However, let's not confuse them and present
785 * IWL_POWER_INDEX_1 as "1", not "0".
792 if (value != -1 && (value < 0 || value >= IWL_POWER_NUM))
795 if (!iwl_is_ready_rf(priv))
798 priv->power_data.debug_sleep_level_override = value;
800 mutex_lock(&priv->mutex);
801 iwl_power_update_mode(priv, true);
802 mutex_unlock(&priv->mutex);
807 static ssize_t iwl_dbgfs_sleep_level_override_read(struct file *file,
808 char __user *user_buf,
809 size_t count, loff_t *ppos)
811 struct iwl_priv *priv = file->private_data;
814 const size_t bufsz = sizeof(buf);
816 /* see the write function */
817 value = priv->power_data.debug_sleep_level_override;
821 pos = scnprintf(buf, bufsz, "%d\n", value);
822 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
825 static ssize_t iwl_dbgfs_current_sleep_command_read(struct file *file,
826 char __user *user_buf,
827 size_t count, loff_t *ppos)
829 struct iwl_priv *priv = file->private_data;
832 const size_t bufsz = sizeof(buf);
833 struct iwl_powertable_cmd *cmd = &priv->power_data.sleep_cmd;
835 pos += scnprintf(buf + pos, bufsz - pos,
836 "flags: %#.2x\n", le16_to_cpu(cmd->flags));
837 pos += scnprintf(buf + pos, bufsz - pos,
838 "RX/TX timeout: %d/%d usec\n",
839 le32_to_cpu(cmd->rx_data_timeout),
840 le32_to_cpu(cmd->tx_data_timeout));
841 for (i = 0; i < IWL_POWER_VEC_SIZE; i++)
842 pos += scnprintf(buf + pos, bufsz - pos,
843 "sleep_interval[%d]: %d\n", i,
844 le32_to_cpu(cmd->sleep_interval[i]));
846 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
849 DEBUGFS_READ_WRITE_FILE_OPS(sram);
850 DEBUGFS_READ_WRITE_FILE_OPS(log_event);
851 DEBUGFS_READ_FILE_OPS(nvm);
852 DEBUGFS_READ_FILE_OPS(stations);
853 DEBUGFS_READ_FILE_OPS(channels);
854 DEBUGFS_READ_FILE_OPS(status);
855 DEBUGFS_READ_WRITE_FILE_OPS(interrupt);
856 DEBUGFS_READ_FILE_OPS(qos);
857 DEBUGFS_READ_FILE_OPS(led);
858 DEBUGFS_READ_FILE_OPS(thermal_throttling);
859 DEBUGFS_READ_WRITE_FILE_OPS(disable_ht40);
860 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
861 DEBUGFS_READ_FILE_OPS(current_sleep_command);
863 static ssize_t iwl_dbgfs_traffic_log_read(struct file *file,
864 char __user *user_buf,
865 size_t count, loff_t *ppos)
867 struct iwl_priv *priv = file->private_data;
868 int pos = 0, ofs = 0;
870 struct iwl_tx_queue *txq;
872 struct iwl_rx_queue *rxq = &priv->rxq;
874 int bufsz = ((IWL_TRAFFIC_ENTRIES * IWL_TRAFFIC_ENTRY_SIZE * 64) * 2) +
875 (priv->cfg->num_of_queues * 32 * 8) + 400;
880 IWL_ERR(priv, "txq not ready\n");
883 buf = kzalloc(bufsz, GFP_KERNEL);
885 IWL_ERR(priv, "Can not allocate buffer\n");
888 pos += scnprintf(buf + pos, bufsz - pos, "Tx Queue\n");
889 for (cnt = 0; cnt < priv->hw_params.max_txq_num; cnt++) {
890 txq = &priv->txq[cnt];
892 pos += scnprintf(buf + pos, bufsz - pos,
893 "q[%d]: read_ptr: %u, write_ptr: %u\n",
894 cnt, q->read_ptr, q->write_ptr);
896 if (priv->tx_traffic && (iwl_debug_level & IWL_DL_TX)) {
897 ptr = priv->tx_traffic;
898 pos += scnprintf(buf + pos, bufsz - pos,
899 "Tx Traffic idx: %u\n", priv->tx_traffic_idx);
900 for (cnt = 0, ofs = 0; cnt < IWL_TRAFFIC_ENTRIES; cnt++) {
901 for (entry = 0; entry < IWL_TRAFFIC_ENTRY_SIZE / 16;
902 entry++, ofs += 16) {
903 pos += scnprintf(buf + pos, bufsz - pos,
905 hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
906 buf + pos, bufsz - pos, 0);
907 pos += strlen(buf + pos);
914 pos += scnprintf(buf + pos, bufsz - pos, "Rx Queue\n");
915 pos += scnprintf(buf + pos, bufsz - pos,
916 "read: %u, write: %u\n",
917 rxq->read, rxq->write);
919 if (priv->rx_traffic && (iwl_debug_level & IWL_DL_RX)) {
920 ptr = priv->rx_traffic;
921 pos += scnprintf(buf + pos, bufsz - pos,
922 "Rx Traffic idx: %u\n", priv->rx_traffic_idx);
923 for (cnt = 0, ofs = 0; cnt < IWL_TRAFFIC_ENTRIES; cnt++) {
924 for (entry = 0; entry < IWL_TRAFFIC_ENTRY_SIZE / 16;
925 entry++, ofs += 16) {
926 pos += scnprintf(buf + pos, bufsz - pos,
928 hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
929 buf + pos, bufsz - pos, 0);
930 pos += strlen(buf + pos);
937 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
942 static ssize_t iwl_dbgfs_traffic_log_write(struct file *file,
943 const char __user *user_buf,
944 size_t count, loff_t *ppos)
946 struct iwl_priv *priv = file->private_data;
951 memset(buf, 0, sizeof(buf));
952 buf_size = min(count, sizeof(buf) - 1);
953 if (copy_from_user(buf, user_buf, buf_size))
955 if (sscanf(buf, "%d", &traffic_log) != 1)
957 if (traffic_log == 0)
958 iwl_reset_traffic_log(priv);
963 static ssize_t iwl_dbgfs_tx_queue_read(struct file *file,
964 char __user *user_buf,
965 size_t count, loff_t *ppos) {
967 struct iwl_priv *priv = file->private_data;
968 struct iwl_tx_queue *txq;
974 const size_t bufsz = sizeof(char) * 64 * priv->cfg->num_of_queues;
977 IWL_ERR(priv, "txq not ready\n");
980 buf = kzalloc(bufsz, GFP_KERNEL);
984 for (cnt = 0; cnt < priv->hw_params.max_txq_num; cnt++) {
985 txq = &priv->txq[cnt];
987 pos += scnprintf(buf + pos, bufsz - pos,
988 "hwq %.2d: read=%u write=%u stop=%d"
989 " swq_id=%#.2x (ac %d/hwq %d)\n",
990 cnt, q->read_ptr, q->write_ptr,
991 !!test_bit(cnt, priv->queue_stopped),
993 txq->swq_id & 0x80 ? txq->swq_id & 3 :
995 txq->swq_id & 0x80 ? (txq->swq_id >> 2) &
999 /* for the ACs, display the stop count too */
1000 pos += scnprintf(buf + pos, bufsz - pos,
1001 " stop-count: %d\n",
1002 atomic_read(&priv->queue_stop_count[cnt]));
1004 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1009 static ssize_t iwl_dbgfs_rx_queue_read(struct file *file,
1010 char __user *user_buf,
1011 size_t count, loff_t *ppos) {
1013 struct iwl_priv *priv = file->private_data;
1014 struct iwl_rx_queue *rxq = &priv->rxq;
1017 const size_t bufsz = sizeof(buf);
1019 pos += scnprintf(buf + pos, bufsz - pos, "read: %u\n",
1021 pos += scnprintf(buf + pos, bufsz - pos, "write: %u\n",
1023 pos += scnprintf(buf + pos, bufsz - pos, "free_count: %u\n",
1025 pos += scnprintf(buf + pos, bufsz - pos, "closed_rb_num: %u\n",
1026 le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF);
1027 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1030 static ssize_t iwl_dbgfs_ucode_rx_stats_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 return priv->cfg->ops->lib->debugfs_ops.rx_stats_read(file,
1036 user_buf, count, ppos);
1039 static ssize_t iwl_dbgfs_ucode_tx_stats_read(struct file *file,
1040 char __user *user_buf,
1041 size_t count, loff_t *ppos)
1043 struct iwl_priv *priv = file->private_data;
1044 return priv->cfg->ops->lib->debugfs_ops.tx_stats_read(file,
1045 user_buf, count, ppos);
1048 static ssize_t iwl_dbgfs_ucode_general_stats_read(struct file *file,
1049 char __user *user_buf,
1050 size_t count, loff_t *ppos)
1052 struct iwl_priv *priv = file->private_data;
1053 return priv->cfg->ops->lib->debugfs_ops.general_stats_read(file,
1054 user_buf, count, ppos);
1057 static ssize_t iwl_dbgfs_sensitivity_read(struct file *file,
1058 char __user *user_buf,
1059 size_t count, loff_t *ppos) {
1061 struct iwl_priv *priv = file->private_data;
1065 int bufsz = sizeof(struct iwl_sensitivity_data) * 4 + 100;
1067 struct iwl_sensitivity_data *data;
1069 data = &priv->sensitivity_data;
1070 buf = kzalloc(bufsz, GFP_KERNEL);
1072 IWL_ERR(priv, "Can not allocate Buffer\n");
1076 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm:\t\t\t %u\n",
1077 data->auto_corr_ofdm);
1078 pos += scnprintf(buf + pos, bufsz - pos,
1079 "auto_corr_ofdm_mrc:\t\t %u\n",
1080 data->auto_corr_ofdm_mrc);
1081 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_x1:\t\t %u\n",
1082 data->auto_corr_ofdm_x1);
1083 pos += scnprintf(buf + pos, bufsz - pos,
1084 "auto_corr_ofdm_mrc_x1:\t\t %u\n",
1085 data->auto_corr_ofdm_mrc_x1);
1086 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck:\t\t\t %u\n",
1087 data->auto_corr_cck);
1088 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck_mrc:\t\t %u\n",
1089 data->auto_corr_cck_mrc);
1090 pos += scnprintf(buf + pos, bufsz - pos,
1091 "last_bad_plcp_cnt_ofdm:\t\t %u\n",
1092 data->last_bad_plcp_cnt_ofdm);
1093 pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_ofdm:\t\t %u\n",
1094 data->last_fa_cnt_ofdm);
1095 pos += scnprintf(buf + pos, bufsz - pos,
1096 "last_bad_plcp_cnt_cck:\t\t %u\n",
1097 data->last_bad_plcp_cnt_cck);
1098 pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_cck:\t\t %u\n",
1099 data->last_fa_cnt_cck);
1100 pos += scnprintf(buf + pos, bufsz - pos, "nrg_curr_state:\t\t\t %u\n",
1101 data->nrg_curr_state);
1102 pos += scnprintf(buf + pos, bufsz - pos, "nrg_prev_state:\t\t\t %u\n",
1103 data->nrg_prev_state);
1104 pos += scnprintf(buf + pos, bufsz - pos, "nrg_value:\t\t\t");
1105 for (cnt = 0; cnt < 10; cnt++) {
1106 pos += scnprintf(buf + pos, bufsz - pos, " %u",
1107 data->nrg_value[cnt]);
1109 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1110 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_rssi:\t\t");
1111 for (cnt = 0; cnt < NRG_NUM_PREV_STAT_L; cnt++) {
1112 pos += scnprintf(buf + pos, bufsz - pos, " %u",
1113 data->nrg_silence_rssi[cnt]);
1115 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1116 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_ref:\t\t %u\n",
1117 data->nrg_silence_ref);
1118 pos += scnprintf(buf + pos, bufsz - pos, "nrg_energy_idx:\t\t\t %u\n",
1119 data->nrg_energy_idx);
1120 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_idx:\t\t %u\n",
1121 data->nrg_silence_idx);
1122 pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_cck:\t\t\t %u\n",
1124 pos += scnprintf(buf + pos, bufsz - pos,
1125 "nrg_auto_corr_silence_diff:\t %u\n",
1126 data->nrg_auto_corr_silence_diff);
1127 pos += scnprintf(buf + pos, bufsz - pos, "num_in_cck_no_fa:\t\t %u\n",
1128 data->num_in_cck_no_fa);
1129 pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_ofdm:\t\t\t %u\n",
1132 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1138 static ssize_t iwl_dbgfs_chain_noise_read(struct file *file,
1139 char __user *user_buf,
1140 size_t count, loff_t *ppos) {
1142 struct iwl_priv *priv = file->private_data;
1146 int bufsz = sizeof(struct iwl_chain_noise_data) * 4 + 100;
1148 struct iwl_chain_noise_data *data;
1150 data = &priv->chain_noise_data;
1151 buf = kzalloc(bufsz, GFP_KERNEL);
1153 IWL_ERR(priv, "Can not allocate Buffer\n");
1157 pos += scnprintf(buf + pos, bufsz - pos, "active_chains:\t\t\t %u\n",
1158 data->active_chains);
1159 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_a:\t\t\t %u\n",
1160 data->chain_noise_a);
1161 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_b:\t\t\t %u\n",
1162 data->chain_noise_b);
1163 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_c:\t\t\t %u\n",
1164 data->chain_noise_c);
1165 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_a:\t\t\t %u\n",
1166 data->chain_signal_a);
1167 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_b:\t\t\t %u\n",
1168 data->chain_signal_b);
1169 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_c:\t\t\t %u\n",
1170 data->chain_signal_c);
1171 pos += scnprintf(buf + pos, bufsz - pos, "beacon_count:\t\t\t %u\n",
1172 data->beacon_count);
1174 pos += scnprintf(buf + pos, bufsz - pos, "disconn_array:\t\t\t");
1175 for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
1176 pos += scnprintf(buf + pos, bufsz - pos, " %u",
1177 data->disconn_array[cnt]);
1179 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1180 pos += scnprintf(buf + pos, bufsz - pos, "delta_gain_code:\t\t");
1181 for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
1182 pos += scnprintf(buf + pos, bufsz - pos, " %u",
1183 data->delta_gain_code[cnt]);
1185 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1186 pos += scnprintf(buf + pos, bufsz - pos, "radio_write:\t\t\t %u\n",
1188 pos += scnprintf(buf + pos, bufsz - pos, "state:\t\t\t\t %u\n",
1191 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1196 static ssize_t iwl_dbgfs_power_save_status_read(struct file *file,
1197 char __user *user_buf,
1198 size_t count, loff_t *ppos)
1200 struct iwl_priv *priv = file->private_data;
1203 const size_t bufsz = sizeof(buf);
1206 pwrsave_status = iwl_read32(priv, CSR_GP_CNTRL) &
1207 CSR_GP_REG_POWER_SAVE_STATUS_MSK;
1209 pos += scnprintf(buf + pos, bufsz - pos, "Power Save Status: ");
1210 pos += scnprintf(buf + pos, bufsz - pos, "%s\n",
1211 (pwrsave_status == CSR_GP_REG_NO_POWER_SAVE) ? "none" :
1212 (pwrsave_status == CSR_GP_REG_MAC_POWER_SAVE) ? "MAC" :
1213 (pwrsave_status == CSR_GP_REG_PHY_POWER_SAVE) ? "PHY" :
1216 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1219 static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
1220 const char __user *user_buf,
1221 size_t count, loff_t *ppos)
1223 struct iwl_priv *priv = file->private_data;
1228 memset(buf, 0, sizeof(buf));
1229 buf_size = min(count, sizeof(buf) - 1);
1230 if (copy_from_user(buf, user_buf, buf_size))
1232 if (sscanf(buf, "%d", &clear) != 1)
1235 /* make request to uCode to retrieve statistics information */
1236 mutex_lock(&priv->mutex);
1237 iwl_send_statistics_request(priv, CMD_SYNC, true);
1238 mutex_unlock(&priv->mutex);
1243 static ssize_t iwl_dbgfs_csr_write(struct file *file,
1244 const char __user *user_buf,
1245 size_t count, loff_t *ppos)
1247 struct iwl_priv *priv = file->private_data;
1252 memset(buf, 0, sizeof(buf));
1253 buf_size = min(count, sizeof(buf) - 1);
1254 if (copy_from_user(buf, user_buf, buf_size))
1256 if (sscanf(buf, "%d", &csr) != 1)
1259 if (priv->cfg->ops->lib->dump_csr)
1260 priv->cfg->ops->lib->dump_csr(priv);
1265 static ssize_t iwl_dbgfs_ucode_tracing_read(struct file *file,
1266 char __user *user_buf,
1267 size_t count, loff_t *ppos) {
1269 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1272 const size_t bufsz = sizeof(buf);
1274 pos += scnprintf(buf + pos, bufsz - pos, "ucode trace timer is %s\n",
1275 priv->event_log.ucode_trace ? "On" : "Off");
1276 pos += scnprintf(buf + pos, bufsz - pos, "non_wraps_count:\t\t %u\n",
1277 priv->event_log.non_wraps_count);
1278 pos += scnprintf(buf + pos, bufsz - pos, "wraps_once_count:\t\t %u\n",
1279 priv->event_log.wraps_once_count);
1280 pos += scnprintf(buf + pos, bufsz - pos, "wraps_more_count:\t\t %u\n",
1281 priv->event_log.wraps_more_count);
1283 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1286 static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
1287 const char __user *user_buf,
1288 size_t count, loff_t *ppos)
1290 struct iwl_priv *priv = file->private_data;
1295 memset(buf, 0, sizeof(buf));
1296 buf_size = min(count, sizeof(buf) - 1);
1297 if (copy_from_user(buf, user_buf, buf_size))
1299 if (sscanf(buf, "%d", &trace) != 1)
1303 priv->event_log.ucode_trace = true;
1304 /* schedule the ucode timer to occur in UCODE_TRACE_PERIOD */
1305 mod_timer(&priv->ucode_trace,
1306 jiffies + msecs_to_jiffies(UCODE_TRACE_PERIOD));
1308 priv->event_log.ucode_trace = false;
1309 del_timer_sync(&priv->ucode_trace);
1315 static ssize_t iwl_dbgfs_rxon_flags_read(struct file *file,
1316 char __user *user_buf,
1317 size_t count, loff_t *ppos) {
1319 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1323 len = sprintf(buf, "0x%04X\n", le32_to_cpu(priv->active_rxon.flags));
1324 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1327 static ssize_t iwl_dbgfs_rxon_filter_flags_read(struct file *file,
1328 char __user *user_buf,
1329 size_t count, loff_t *ppos) {
1331 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1335 len = sprintf(buf, "0x%04X\n",
1336 le32_to_cpu(priv->active_rxon.filter_flags));
1337 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1340 static ssize_t iwl_dbgfs_fh_reg_read(struct file *file,
1341 char __user *user_buf,
1342 size_t count, loff_t *ppos)
1344 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1347 ssize_t ret = -EFAULT;
1349 if (priv->cfg->ops->lib->dump_fh) {
1350 ret = pos = priv->cfg->ops->lib->dump_fh(priv, &buf, true);
1352 ret = simple_read_from_buffer(user_buf,
1353 count, ppos, buf, pos);
1361 static ssize_t iwl_dbgfs_missed_beacon_read(struct file *file,
1362 char __user *user_buf,
1363 size_t count, loff_t *ppos) {
1365 struct iwl_priv *priv = file->private_data;
1368 const size_t bufsz = sizeof(buf);
1370 pos += scnprintf(buf + pos, bufsz - pos, "%d\n",
1371 priv->missed_beacon_threshold);
1373 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1376 static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
1377 const char __user *user_buf,
1378 size_t count, loff_t *ppos)
1380 struct iwl_priv *priv = file->private_data;
1385 memset(buf, 0, sizeof(buf));
1386 buf_size = min(count, sizeof(buf) - 1);
1387 if (copy_from_user(buf, user_buf, buf_size))
1389 if (sscanf(buf, "%d", &missed) != 1)
1392 if (missed < IWL_MISSED_BEACON_THRESHOLD_MIN ||
1393 missed > IWL_MISSED_BEACON_THRESHOLD_MAX)
1394 priv->missed_beacon_threshold =
1395 IWL_MISSED_BEACON_THRESHOLD_DEF;
1397 priv->missed_beacon_threshold = missed;
1402 static ssize_t iwl_dbgfs_plcp_delta_read(struct file *file,
1403 char __user *user_buf,
1404 size_t count, loff_t *ppos) {
1406 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1409 const size_t bufsz = sizeof(buf);
1411 pos += scnprintf(buf + pos, bufsz - pos, "%u\n",
1412 priv->cfg->plcp_delta_threshold);
1414 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1417 static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
1418 const char __user *user_buf,
1419 size_t count, loff_t *ppos) {
1421 struct iwl_priv *priv = file->private_data;
1426 memset(buf, 0, sizeof(buf));
1427 buf_size = min(count, sizeof(buf) - 1);
1428 if (copy_from_user(buf, user_buf, buf_size))
1430 if (sscanf(buf, "%d", &plcp) != 1)
1432 if ((plcp <= IWL_MAX_PLCP_ERR_THRESHOLD_MIN) ||
1433 (plcp > IWL_MAX_PLCP_ERR_THRESHOLD_MAX))
1434 priv->cfg->plcp_delta_threshold =
1435 IWL_MAX_PLCP_ERR_THRESHOLD_DEF;
1437 priv->cfg->plcp_delta_threshold = plcp;
1441 static ssize_t iwl_dbgfs_force_reset_read(struct file *file,
1442 char __user *user_buf,
1443 size_t count, loff_t *ppos) {
1445 struct iwl_priv *priv = file->private_data;
1448 const size_t bufsz = sizeof(buf);
1449 struct iwl_force_reset *force_reset;
1451 for (i = 0; i < IWL_MAX_FORCE_RESET; i++) {
1452 force_reset = &priv->force_reset[i];
1453 pos += scnprintf(buf + pos, bufsz - pos,
1454 "Force reset method %d\n", i);
1455 pos += scnprintf(buf + pos, bufsz - pos,
1456 "\tnumber of reset request: %d\n",
1457 force_reset->reset_request_count);
1458 pos += scnprintf(buf + pos, bufsz - pos,
1459 "\tnumber of reset request success: %d\n",
1460 force_reset->reset_success_count);
1461 pos += scnprintf(buf + pos, bufsz - pos,
1462 "\tnumber of reset request reject: %d\n",
1463 force_reset->reset_reject_count);
1464 pos += scnprintf(buf + pos, bufsz - pos,
1465 "\treset duration: %lu\n",
1466 force_reset->reset_duration);
1468 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1471 static ssize_t iwl_dbgfs_force_reset_write(struct file *file,
1472 const char __user *user_buf,
1473 size_t count, loff_t *ppos) {
1475 struct iwl_priv *priv = file->private_data;
1480 memset(buf, 0, sizeof(buf));
1481 buf_size = min(count, sizeof(buf) - 1);
1482 if (copy_from_user(buf, user_buf, buf_size))
1484 if (sscanf(buf, "%d", &reset) != 1)
1489 ret = iwl_force_reset(priv, reset);
1494 return ret ? ret : count;
1497 DEBUGFS_READ_FILE_OPS(rx_statistics);
1498 DEBUGFS_READ_FILE_OPS(tx_statistics);
1499 DEBUGFS_READ_WRITE_FILE_OPS(traffic_log);
1500 DEBUGFS_READ_FILE_OPS(rx_queue);
1501 DEBUGFS_READ_FILE_OPS(tx_queue);
1502 DEBUGFS_READ_FILE_OPS(ucode_rx_stats);
1503 DEBUGFS_READ_FILE_OPS(ucode_tx_stats);
1504 DEBUGFS_READ_FILE_OPS(ucode_general_stats);
1505 DEBUGFS_READ_FILE_OPS(sensitivity);
1506 DEBUGFS_READ_FILE_OPS(chain_noise);
1507 DEBUGFS_READ_FILE_OPS(power_save_status);
1508 DEBUGFS_WRITE_FILE_OPS(clear_ucode_statistics);
1509 DEBUGFS_WRITE_FILE_OPS(clear_traffic_statistics);
1510 DEBUGFS_WRITE_FILE_OPS(csr);
1511 DEBUGFS_READ_WRITE_FILE_OPS(ucode_tracing);
1512 DEBUGFS_READ_FILE_OPS(fh_reg);
1513 DEBUGFS_READ_WRITE_FILE_OPS(missed_beacon);
1514 DEBUGFS_READ_WRITE_FILE_OPS(plcp_delta);
1515 DEBUGFS_READ_WRITE_FILE_OPS(force_reset);
1516 DEBUGFS_READ_FILE_OPS(rxon_flags);
1517 DEBUGFS_READ_FILE_OPS(rxon_filter_flags);
1520 * Create the debugfs files and directories
1523 int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
1525 struct dentry *phyd = priv->hw->wiphy->debugfsdir;
1526 struct dentry *dir_drv, *dir_data, *dir_rf, *dir_debug;
1528 dir_drv = debugfs_create_dir(name, phyd);
1532 priv->debugfs_dir = dir_drv;
1534 dir_data = debugfs_create_dir("data", dir_drv);
1537 dir_rf = debugfs_create_dir("rf", dir_drv);
1540 dir_debug = debugfs_create_dir("debug", dir_drv);
1544 DEBUGFS_ADD_FILE(nvm, dir_data, S_IRUSR);
1545 DEBUGFS_ADD_FILE(sram, dir_data, S_IWUSR | S_IRUSR);
1546 DEBUGFS_ADD_FILE(log_event, dir_data, S_IWUSR | S_IRUSR);
1547 DEBUGFS_ADD_FILE(stations, dir_data, S_IRUSR);
1548 DEBUGFS_ADD_FILE(channels, dir_data, S_IRUSR);
1549 DEBUGFS_ADD_FILE(status, dir_data, S_IRUSR);
1550 DEBUGFS_ADD_FILE(interrupt, dir_data, S_IWUSR | S_IRUSR);
1551 DEBUGFS_ADD_FILE(qos, dir_data, S_IRUSR);
1552 DEBUGFS_ADD_FILE(led, dir_data, S_IRUSR);
1553 if (!priv->cfg->broken_powersave) {
1554 DEBUGFS_ADD_FILE(sleep_level_override, dir_data,
1556 DEBUGFS_ADD_FILE(current_sleep_command, dir_data, S_IRUSR);
1558 DEBUGFS_ADD_FILE(thermal_throttling, dir_data, S_IRUSR);
1559 DEBUGFS_ADD_FILE(disable_ht40, dir_data, S_IWUSR | S_IRUSR);
1560 DEBUGFS_ADD_FILE(rx_statistics, dir_debug, S_IRUSR);
1561 DEBUGFS_ADD_FILE(tx_statistics, dir_debug, S_IRUSR);
1562 DEBUGFS_ADD_FILE(traffic_log, dir_debug, S_IWUSR | S_IRUSR);
1563 DEBUGFS_ADD_FILE(rx_queue, dir_debug, S_IRUSR);
1564 DEBUGFS_ADD_FILE(tx_queue, dir_debug, S_IRUSR);
1565 DEBUGFS_ADD_FILE(power_save_status, dir_debug, S_IRUSR);
1566 DEBUGFS_ADD_FILE(clear_ucode_statistics, dir_debug, S_IWUSR);
1567 DEBUGFS_ADD_FILE(clear_traffic_statistics, dir_debug, S_IWUSR);
1568 DEBUGFS_ADD_FILE(csr, dir_debug, S_IWUSR);
1569 DEBUGFS_ADD_FILE(fh_reg, dir_debug, S_IRUSR);
1570 DEBUGFS_ADD_FILE(missed_beacon, dir_debug, S_IWUSR);
1571 DEBUGFS_ADD_FILE(plcp_delta, dir_debug, S_IWUSR | S_IRUSR);
1572 DEBUGFS_ADD_FILE(force_reset, dir_debug, S_IWUSR | S_IRUSR);
1573 DEBUGFS_ADD_FILE(ucode_rx_stats, dir_debug, S_IRUSR);
1574 DEBUGFS_ADD_FILE(ucode_tx_stats, dir_debug, S_IRUSR);
1575 DEBUGFS_ADD_FILE(ucode_general_stats, dir_debug, S_IRUSR);
1577 if (priv->cfg->sensitivity_calib_by_driver)
1578 DEBUGFS_ADD_FILE(sensitivity, dir_debug, S_IRUSR);
1579 if (priv->cfg->chain_noise_calib_by_driver)
1580 DEBUGFS_ADD_FILE(chain_noise, dir_debug, S_IRUSR);
1581 if (priv->cfg->ucode_tracing)
1582 DEBUGFS_ADD_FILE(ucode_tracing, dir_debug, S_IWUSR | S_IRUSR);
1583 DEBUGFS_ADD_FILE(rxon_flags, dir_debug, S_IWUSR);
1584 DEBUGFS_ADD_FILE(rxon_filter_flags, dir_debug, S_IWUSR);
1585 if (priv->cfg->sensitivity_calib_by_driver)
1586 DEBUGFS_ADD_BOOL(disable_sensitivity, dir_rf,
1587 &priv->disable_sens_cal);
1588 if (priv->cfg->chain_noise_calib_by_driver)
1589 DEBUGFS_ADD_BOOL(disable_chain_noise, dir_rf,
1590 &priv->disable_chain_noise_cal);
1591 if (priv->cfg->tx_power_by_driver)
1592 DEBUGFS_ADD_BOOL(disable_tx_power, dir_rf,
1593 &priv->disable_tx_power_cal);
1597 IWL_ERR(priv, "Can't create the debugfs directory\n");
1598 iwl_dbgfs_unregister(priv);
1601 EXPORT_SYMBOL(iwl_dbgfs_register);
1604 * Remove the debugfs files and directories
1607 void iwl_dbgfs_unregister(struct iwl_priv *priv)
1609 if (!priv->debugfs_dir)
1612 debugfs_remove_recursive(priv->debugfs_dir);
1613 priv->debugfs_dir = NULL;
1615 EXPORT_SYMBOL(iwl_dbgfs_unregister);