1 // SPDX-License-Identifier: GPL-2.0-only
2 /******************************************************************************
4 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
8 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
9 *****************************************************************************/
10 #include <linux/ieee80211.h>
11 #include <linux/export.h>
12 #include <net/mac80211.h>
17 il_clear_traffic_stats(struct il_priv *il)
19 memset(&il->tx_stats, 0, sizeof(struct traffic_stats));
20 memset(&il->rx_stats, 0, sizeof(struct traffic_stats));
24 * il_update_stats function record all the MGMT, CTRL and DATA pkt for
25 * both TX and Rx . Use debugfs to display the rx/rx_stats
28 il_update_stats(struct il_priv *il, bool is_tx, __le16 fc, u16 len)
30 struct traffic_stats *stats;
33 stats = &il->tx_stats;
35 stats = &il->rx_stats;
37 if (ieee80211_is_mgmt(fc)) {
38 switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
39 case cpu_to_le16(IEEE80211_STYPE_ASSOC_REQ):
40 stats->mgmt[MANAGEMENT_ASSOC_REQ]++;
42 case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
43 stats->mgmt[MANAGEMENT_ASSOC_RESP]++;
45 case cpu_to_le16(IEEE80211_STYPE_REASSOC_REQ):
46 stats->mgmt[MANAGEMENT_REASSOC_REQ]++;
48 case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
49 stats->mgmt[MANAGEMENT_REASSOC_RESP]++;
51 case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ):
52 stats->mgmt[MANAGEMENT_PROBE_REQ]++;
54 case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
55 stats->mgmt[MANAGEMENT_PROBE_RESP]++;
57 case cpu_to_le16(IEEE80211_STYPE_BEACON):
58 stats->mgmt[MANAGEMENT_BEACON]++;
60 case cpu_to_le16(IEEE80211_STYPE_ATIM):
61 stats->mgmt[MANAGEMENT_ATIM]++;
63 case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
64 stats->mgmt[MANAGEMENT_DISASSOC]++;
66 case cpu_to_le16(IEEE80211_STYPE_AUTH):
67 stats->mgmt[MANAGEMENT_AUTH]++;
69 case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
70 stats->mgmt[MANAGEMENT_DEAUTH]++;
72 case cpu_to_le16(IEEE80211_STYPE_ACTION):
73 stats->mgmt[MANAGEMENT_ACTION]++;
76 } else if (ieee80211_is_ctl(fc)) {
77 switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
78 case cpu_to_le16(IEEE80211_STYPE_BACK_REQ):
79 stats->ctrl[CONTROL_BACK_REQ]++;
81 case cpu_to_le16(IEEE80211_STYPE_BACK):
82 stats->ctrl[CONTROL_BACK]++;
84 case cpu_to_le16(IEEE80211_STYPE_PSPOLL):
85 stats->ctrl[CONTROL_PSPOLL]++;
87 case cpu_to_le16(IEEE80211_STYPE_RTS):
88 stats->ctrl[CONTROL_RTS]++;
90 case cpu_to_le16(IEEE80211_STYPE_CTS):
91 stats->ctrl[CONTROL_CTS]++;
93 case cpu_to_le16(IEEE80211_STYPE_ACK):
94 stats->ctrl[CONTROL_ACK]++;
96 case cpu_to_le16(IEEE80211_STYPE_CFEND):
97 stats->ctrl[CONTROL_CFEND]++;
99 case cpu_to_le16(IEEE80211_STYPE_CFENDACK):
100 stats->ctrl[CONTROL_CFENDACK]++;
106 stats->data_bytes += len;
109 EXPORT_SYMBOL(il_update_stats);
111 /* create and remove of files */
112 #define DEBUGFS_ADD_FILE(name, parent, mode) do { \
113 debugfs_create_file(#name, mode, parent, il, \
114 &il_dbgfs_##name##_ops); \
117 #define DEBUGFS_ADD_BOOL(name, parent, ptr) do { \
118 debugfs_create_bool(#name, 0600, parent, ptr); \
122 #define DEBUGFS_READ_FUNC(name) \
123 static ssize_t il_dbgfs_##name##_read(struct file *file, \
124 char __user *user_buf, \
125 size_t count, loff_t *ppos);
127 #define DEBUGFS_WRITE_FUNC(name) \
128 static ssize_t il_dbgfs_##name##_write(struct file *file, \
129 const char __user *user_buf, \
130 size_t count, loff_t *ppos);
133 #define DEBUGFS_READ_FILE_OPS(name) \
134 DEBUGFS_READ_FUNC(name); \
135 static const struct file_operations il_dbgfs_##name##_ops = { \
136 .read = il_dbgfs_##name##_read, \
137 .open = simple_open, \
138 .llseek = generic_file_llseek, \
141 #define DEBUGFS_WRITE_FILE_OPS(name) \
142 DEBUGFS_WRITE_FUNC(name); \
143 static const struct file_operations il_dbgfs_##name##_ops = { \
144 .write = il_dbgfs_##name##_write, \
145 .open = simple_open, \
146 .llseek = generic_file_llseek, \
149 #define DEBUGFS_READ_WRITE_FILE_OPS(name) \
150 DEBUGFS_READ_FUNC(name); \
151 DEBUGFS_WRITE_FUNC(name); \
152 static const struct file_operations il_dbgfs_##name##_ops = { \
153 .write = il_dbgfs_##name##_write, \
154 .read = il_dbgfs_##name##_read, \
155 .open = simple_open, \
156 .llseek = generic_file_llseek, \
160 il_get_mgmt_string(int cmd)
163 IL_CMD(MANAGEMENT_ASSOC_REQ);
164 IL_CMD(MANAGEMENT_ASSOC_RESP);
165 IL_CMD(MANAGEMENT_REASSOC_REQ);
166 IL_CMD(MANAGEMENT_REASSOC_RESP);
167 IL_CMD(MANAGEMENT_PROBE_REQ);
168 IL_CMD(MANAGEMENT_PROBE_RESP);
169 IL_CMD(MANAGEMENT_BEACON);
170 IL_CMD(MANAGEMENT_ATIM);
171 IL_CMD(MANAGEMENT_DISASSOC);
172 IL_CMD(MANAGEMENT_AUTH);
173 IL_CMD(MANAGEMENT_DEAUTH);
174 IL_CMD(MANAGEMENT_ACTION);
182 il_get_ctrl_string(int cmd)
185 IL_CMD(CONTROL_BACK_REQ);
186 IL_CMD(CONTROL_BACK);
187 IL_CMD(CONTROL_PSPOLL);
191 IL_CMD(CONTROL_CFEND);
192 IL_CMD(CONTROL_CFENDACK);
200 il_dbgfs_tx_stats_read(struct file *file, char __user *user_buf, size_t count,
204 struct il_priv *il = file->private_data;
211 100 + sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
212 buf = kzalloc(bufsz, GFP_KERNEL);
215 pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
216 for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
218 scnprintf(buf + pos, bufsz - pos, "\t%25s\t\t: %u\n",
219 il_get_mgmt_string(cnt), il->tx_stats.mgmt[cnt]);
221 pos += scnprintf(buf + pos, bufsz - pos, "Control\n");
222 for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
224 scnprintf(buf + pos, bufsz - pos, "\t%25s\t\t: %u\n",
225 il_get_ctrl_string(cnt), il->tx_stats.ctrl[cnt]);
227 pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
229 scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
230 il->tx_stats.data_cnt);
232 scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
233 il->tx_stats.data_bytes);
234 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
240 il_dbgfs_clear_traffic_stats_write(struct file *file,
241 const char __user *user_buf, size_t count,
244 struct il_priv *il = file->private_data;
249 memset(buf, 0, sizeof(buf));
250 buf_size = min(count, sizeof(buf) - 1);
251 if (copy_from_user(buf, user_buf, buf_size))
253 if (sscanf(buf, "%x", &clear_flag) != 1)
255 il_clear_traffic_stats(il);
261 il_dbgfs_rx_stats_read(struct file *file, char __user *user_buf, size_t count,
265 struct il_priv *il = file->private_data;
271 100 + sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
272 buf = kzalloc(bufsz, GFP_KERNEL);
276 pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
277 for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
279 scnprintf(buf + pos, bufsz - pos, "\t%25s\t\t: %u\n",
280 il_get_mgmt_string(cnt), il->rx_stats.mgmt[cnt]);
282 pos += scnprintf(buf + pos, bufsz - pos, "Control:\n");
283 for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
285 scnprintf(buf + pos, bufsz - pos, "\t%25s\t\t: %u\n",
286 il_get_ctrl_string(cnt), il->rx_stats.ctrl[cnt]);
288 pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
290 scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
291 il->rx_stats.data_cnt);
293 scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
294 il->rx_stats.data_bytes);
296 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
301 #define BYTE1_MASK 0x000000ff;
302 #define BYTE2_MASK 0x0000ffff;
303 #define BYTE3_MASK 0x00ffffff;
305 il_dbgfs_sram_read(struct file *file, char __user *user_buf, size_t count,
313 struct il_priv *il = file->private_data;
316 /* default is to dump the entire data segment */
317 if (!il->dbgfs_sram_offset && !il->dbgfs_sram_len) {
318 il->dbgfs_sram_offset = 0x800000;
319 if (il->ucode_type == UCODE_INIT)
320 il->dbgfs_sram_len = il->ucode_init_data.len;
322 il->dbgfs_sram_len = il->ucode_data.len;
324 bufsz = 30 + il->dbgfs_sram_len * sizeof(char) * 10;
325 buf = kmalloc(bufsz, GFP_KERNEL);
329 scnprintf(buf + pos, bufsz - pos, "sram_len: 0x%x\n",
332 scnprintf(buf + pos, bufsz - pos, "sram_offset: 0x%x\n",
333 il->dbgfs_sram_offset);
334 for (i = il->dbgfs_sram_len; i > 0; i -= 4) {
337 il->dbgfs_sram_offset +
338 il->dbgfs_sram_len - i);
353 pos += scnprintf(buf + pos, bufsz - pos, "\n");
354 pos += scnprintf(buf + pos, bufsz - pos, "0x%08x ", val);
356 pos += scnprintf(buf + pos, bufsz - pos, "\n");
358 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
364 il_dbgfs_sram_write(struct file *file, const char __user *user_buf,
365 size_t count, loff_t *ppos)
367 struct il_priv *il = file->private_data;
372 memset(buf, 0, sizeof(buf));
373 buf_size = min(count, sizeof(buf) - 1);
374 if (copy_from_user(buf, user_buf, buf_size))
377 if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
378 il->dbgfs_sram_offset = offset;
379 il->dbgfs_sram_len = len;
381 il->dbgfs_sram_offset = 0;
382 il->dbgfs_sram_len = 0;
389 il_dbgfs_stations_read(struct file *file, char __user *user_buf, size_t count,
392 struct il_priv *il = file->private_data;
393 struct il_station_entry *station;
394 int max_sta = il->hw_params.max_stations;
398 /* Add 30 for initial string */
399 const size_t bufsz = 30 + sizeof(char) * 500 * (il->num_stations);
401 buf = kmalloc(bufsz, GFP_KERNEL);
406 scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n",
409 for (i = 0; i < max_sta; i++) {
410 station = &il->stations[i];
414 scnprintf(buf + pos, bufsz - pos,
415 "station %d - addr: %pM, flags: %#x\n", i,
416 station->sta.sta.addr,
417 station->sta.station_flags_msk);
419 scnprintf(buf + pos, bufsz - pos,
420 "TID\tseq_num\ttxq_id\tframes\ttfds\t");
422 scnprintf(buf + pos, bufsz - pos,
423 "start_idx\tbitmap\t\t\trate_n_flags\n");
425 for (j = 0; j < MAX_TID_COUNT; j++) {
427 scnprintf(buf + pos, bufsz - pos,
428 "%d:\t%#x\t%#x\t%u\t%u\t%u\t\t%#.16llx\t%#x",
429 j, station->tid[j].seq_number,
430 station->tid[j].agg.txq_id,
431 station->tid[j].agg.frame_count,
432 station->tid[j].tfds_in_queue,
433 station->tid[j].agg.start_idx,
434 station->tid[j].agg.bitmap,
435 station->tid[j].agg.rate_n_flags);
437 if (station->tid[j].agg.wait_for_ba)
439 scnprintf(buf + pos, bufsz - pos,
441 pos += scnprintf(buf + pos, bufsz - pos, "\n");
444 pos += scnprintf(buf + pos, bufsz - pos, "\n");
447 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
453 il_dbgfs_nvm_read(struct file *file, char __user *user_buf, size_t count,
457 struct il_priv *il = file->private_data;
458 int pos = 0, ofs = 0, buf_size = 0;
462 size_t eeprom_len = il->cfg->eeprom_size;
463 buf_size = 4 * eeprom_len + 256;
465 if (eeprom_len % 16) {
466 IL_ERR("NVM size is not multiple of 16.\n");
472 IL_ERR("Invalid EEPROM memory\n");
476 /* 4 characters for byte 0xYY */
477 buf = kzalloc(buf_size, GFP_KERNEL);
479 IL_ERR("Can not allocate Buffer\n");
482 eeprom_ver = il_eeprom_query16(il, EEPROM_VERSION);
484 scnprintf(buf + pos, buf_size - pos, "EEPROM " "version: 0x%x\n",
486 for (ofs = 0; ofs < eeprom_len; ofs += 16) {
487 pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x %16ph\n",
491 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
497 il_dbgfs_channels_read(struct file *file, char __user *user_buf, size_t count,
500 struct il_priv *il = file->private_data;
501 struct ieee80211_channel *channels = NULL;
502 const struct ieee80211_supported_band *supp_band = NULL;
503 int pos = 0, i, bufsz = PAGE_SIZE;
507 if (!test_bit(S_GEO_CONFIGURED, &il->status))
510 buf = kzalloc(bufsz, GFP_KERNEL);
512 IL_ERR("Can not allocate Buffer\n");
516 supp_band = il_get_hw_mode(il, NL80211_BAND_2GHZ);
518 channels = supp_band->channels;
521 scnprintf(buf + pos, bufsz - pos,
522 "Displaying %d channels in 2.4GHz band 802.11bg):\n",
523 supp_band->n_channels);
525 for (i = 0; i < supp_band->n_channels; i++)
527 scnprintf(buf + pos, bufsz - pos,
528 "%d: %ddBm: BSS%s%s, %s.\n",
529 channels[i].hw_value,
530 channels[i].max_power,
532 flags & IEEE80211_CHAN_RADAR ?
533 " (IEEE 802.11h required)" : "",
535 flags & IEEE80211_CHAN_NO_IR) ||
537 flags & IEEE80211_CHAN_RADAR)) ? "" :
540 flags & IEEE80211_CHAN_NO_IR ?
541 "passive only" : "active/passive");
543 supp_band = il_get_hw_mode(il, NL80211_BAND_5GHZ);
545 channels = supp_band->channels;
548 scnprintf(buf + pos, bufsz - pos,
549 "Displaying %d channels in 5.2GHz band (802.11a)\n",
550 supp_band->n_channels);
552 for (i = 0; i < supp_band->n_channels; i++)
554 scnprintf(buf + pos, bufsz - pos,
555 "%d: %ddBm: BSS%s%s, %s.\n",
556 channels[i].hw_value,
557 channels[i].max_power,
559 flags & IEEE80211_CHAN_RADAR ?
560 " (IEEE 802.11h required)" : "",
562 flags & IEEE80211_CHAN_NO_IR) ||
564 flags & IEEE80211_CHAN_RADAR)) ? "" :
567 flags & IEEE80211_CHAN_NO_IR ?
568 "passive only" : "active/passive");
570 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
576 il_dbgfs_status_read(struct file *file, char __user *user_buf, size_t count,
580 struct il_priv *il = file->private_data;
583 const size_t bufsz = sizeof(buf);
586 scnprintf(buf + pos, bufsz - pos, "S_HCMD_ACTIVE:\t %d\n",
587 test_bit(S_HCMD_ACTIVE, &il->status));
589 scnprintf(buf + pos, bufsz - pos, "S_INT_ENABLED:\t %d\n",
590 test_bit(S_INT_ENABLED, &il->status));
592 scnprintf(buf + pos, bufsz - pos, "S_RFKILL:\t %d\n",
593 test_bit(S_RFKILL, &il->status));
595 scnprintf(buf + pos, bufsz - pos, "S_CT_KILL:\t\t %d\n",
596 test_bit(S_CT_KILL, &il->status));
598 scnprintf(buf + pos, bufsz - pos, "S_INIT:\t\t %d\n",
599 test_bit(S_INIT, &il->status));
601 scnprintf(buf + pos, bufsz - pos, "S_ALIVE:\t\t %d\n",
602 test_bit(S_ALIVE, &il->status));
604 scnprintf(buf + pos, bufsz - pos, "S_READY:\t\t %d\n",
605 test_bit(S_READY, &il->status));
607 scnprintf(buf + pos, bufsz - pos, "S_TEMPERATURE:\t %d\n",
608 test_bit(S_TEMPERATURE, &il->status));
610 scnprintf(buf + pos, bufsz - pos, "S_GEO_CONFIGURED:\t %d\n",
611 test_bit(S_GEO_CONFIGURED, &il->status));
613 scnprintf(buf + pos, bufsz - pos, "S_EXIT_PENDING:\t %d\n",
614 test_bit(S_EXIT_PENDING, &il->status));
616 scnprintf(buf + pos, bufsz - pos, "S_STATS:\t %d\n",
617 test_bit(S_STATS, &il->status));
619 scnprintf(buf + pos, bufsz - pos, "S_SCANNING:\t %d\n",
620 test_bit(S_SCANNING, &il->status));
622 scnprintf(buf + pos, bufsz - pos, "S_SCAN_ABORTING:\t %d\n",
623 test_bit(S_SCAN_ABORTING, &il->status));
625 scnprintf(buf + pos, bufsz - pos, "S_SCAN_HW:\t\t %d\n",
626 test_bit(S_SCAN_HW, &il->status));
628 scnprintf(buf + pos, bufsz - pos, "S_POWER_PMI:\t %d\n",
629 test_bit(S_POWER_PMI, &il->status));
631 scnprintf(buf + pos, bufsz - pos, "S_FW_ERROR:\t %d\n",
632 test_bit(S_FW_ERROR, &il->status));
633 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
637 il_dbgfs_interrupt_read(struct file *file, char __user *user_buf, size_t count,
641 struct il_priv *il = file->private_data;
645 int bufsz = 24 * 64; /* 24 items * 64 char per item */
648 buf = kzalloc(bufsz, GFP_KERNEL);
650 IL_ERR("Can not allocate Buffer\n");
655 scnprintf(buf + pos, bufsz - pos, "Interrupt Statistics Report:\n");
658 scnprintf(buf + pos, bufsz - pos, "HW Error:\t\t\t %u\n",
661 scnprintf(buf + pos, bufsz - pos, "SW Error:\t\t\t %u\n",
663 if (il->isr_stats.sw || il->isr_stats.hw) {
665 scnprintf(buf + pos, bufsz - pos,
666 "\tLast Restarting Code: 0x%X\n",
667 il->isr_stats.err_code);
669 #ifdef CONFIG_IWLEGACY_DEBUG
671 scnprintf(buf + pos, bufsz - pos, "Frame transmitted:\t\t %u\n",
674 scnprintf(buf + pos, bufsz - pos, "Alive interrupt:\t\t %u\n",
675 il->isr_stats.alive);
678 scnprintf(buf + pos, bufsz - pos,
679 "HW RF KILL switch toggled:\t %u\n",
680 il->isr_stats.rfkill);
683 scnprintf(buf + pos, bufsz - pos, "CT KILL:\t\t\t %u\n",
684 il->isr_stats.ctkill);
687 scnprintf(buf + pos, bufsz - pos, "Wakeup Interrupt:\t\t %u\n",
688 il->isr_stats.wakeup);
691 scnprintf(buf + pos, bufsz - pos, "Rx command responses:\t\t %u\n",
693 for (cnt = 0; cnt < IL_CN_MAX; cnt++) {
694 if (il->isr_stats.handlers[cnt] > 0)
696 scnprintf(buf + pos, bufsz - pos,
697 "\tRx handler[%36s]:\t\t %u\n",
698 il_get_cmd_string(cnt),
699 il->isr_stats.handlers[cnt]);
703 scnprintf(buf + pos, bufsz - pos, "Tx/FH interrupt:\t\t %u\n",
707 scnprintf(buf + pos, bufsz - pos, "Unexpected INTA:\t\t %u\n",
708 il->isr_stats.unhandled);
710 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
716 il_dbgfs_interrupt_write(struct file *file, const char __user *user_buf,
717 size_t count, loff_t *ppos)
719 struct il_priv *il = file->private_data;
724 memset(buf, 0, sizeof(buf));
725 buf_size = min(count, sizeof(buf) - 1);
726 if (copy_from_user(buf, user_buf, buf_size))
728 if (sscanf(buf, "%x", &reset_flag) != 1)
731 il_clear_isr_stats(il);
737 il_dbgfs_qos_read(struct file *file, char __user *user_buf, size_t count,
740 struct il_priv *il = file->private_data;
743 const size_t bufsz = sizeof(buf);
745 for (i = 0; i < AC_NUM; i++) {
747 scnprintf(buf + pos, bufsz - pos,
748 "\tcw_min\tcw_max\taifsn\ttxop\n");
750 scnprintf(buf + pos, bufsz - pos,
751 "AC[%d]\t%u\t%u\t%u\t%u\n", i,
752 il->qos_data.def_qos_parm.ac[i].cw_min,
753 il->qos_data.def_qos_parm.ac[i].cw_max,
754 il->qos_data.def_qos_parm.ac[i].aifsn,
755 il->qos_data.def_qos_parm.ac[i].edca_txop);
758 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
762 il_dbgfs_disable_ht40_write(struct file *file, const char __user *user_buf,
763 size_t count, loff_t *ppos)
765 struct il_priv *il = file->private_data;
770 memset(buf, 0, sizeof(buf));
771 buf_size = min(count, sizeof(buf) - 1);
772 if (copy_from_user(buf, user_buf, buf_size))
774 if (sscanf(buf, "%d", &ht40) != 1)
776 if (!il_is_any_associated(il))
777 il->disable_ht40 = ht40 ? true : false;
779 IL_ERR("Sta associated with AP - "
780 "Change to 40MHz channel support is not allowed\n");
788 il_dbgfs_disable_ht40_read(struct file *file, char __user *user_buf,
789 size_t count, loff_t *ppos)
791 struct il_priv *il = file->private_data;
794 const size_t bufsz = sizeof(buf);
797 scnprintf(buf + pos, bufsz - pos, "11n 40MHz Mode: %s\n",
798 il->disable_ht40 ? "Disabled" : "Enabled");
799 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
802 DEBUGFS_READ_WRITE_FILE_OPS(sram);
803 DEBUGFS_READ_FILE_OPS(nvm);
804 DEBUGFS_READ_FILE_OPS(stations);
805 DEBUGFS_READ_FILE_OPS(channels);
806 DEBUGFS_READ_FILE_OPS(status);
807 DEBUGFS_READ_WRITE_FILE_OPS(interrupt);
808 DEBUGFS_READ_FILE_OPS(qos);
809 DEBUGFS_READ_WRITE_FILE_OPS(disable_ht40);
812 il_dbgfs_tx_queue_read(struct file *file, char __user *user_buf, size_t count,
816 struct il_priv *il = file->private_data;
817 struct il_tx_queue *txq;
824 sizeof(char) * 64 * il->cfg->num_of_queues;
827 IL_ERR("txq not ready\n");
830 buf = kzalloc(bufsz, GFP_KERNEL);
834 for (cnt = 0; cnt < il->hw_params.max_txq_num; cnt++) {
838 scnprintf(buf + pos, bufsz - pos,
839 "hwq %.2d: read=%u write=%u stop=%d"
840 " swq_id=%#.2x (ac %d/hwq %d)\n", cnt,
841 q->read_ptr, q->write_ptr,
842 !!test_bit(cnt, il->queue_stopped),
843 txq->swq_id, txq->swq_id & 3,
844 (txq->swq_id >> 2) & 0x1f);
847 /* for the ACs, display the stop count too */
849 scnprintf(buf + pos, bufsz - pos,
851 atomic_read(&il->queue_stop_count[cnt]));
853 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
859 il_dbgfs_rx_queue_read(struct file *file, char __user *user_buf, size_t count,
863 struct il_priv *il = file->private_data;
864 struct il_rx_queue *rxq = &il->rxq;
867 const size_t bufsz = sizeof(buf);
869 pos += scnprintf(buf + pos, bufsz - pos, "read: %u\n", rxq->read);
870 pos += scnprintf(buf + pos, bufsz - pos, "write: %u\n", rxq->write);
872 scnprintf(buf + pos, bufsz - pos, "free_count: %u\n",
876 scnprintf(buf + pos, bufsz - pos, "closed_rb_num: %u\n",
877 le16_to_cpu(rxq->rb_stts->
878 closed_rb_num) & 0x0FFF);
881 scnprintf(buf + pos, bufsz - pos,
882 "closed_rb_num: Not Allocated\n");
884 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
888 il_dbgfs_ucode_rx_stats_read(struct file *file, char __user *user_buf,
889 size_t count, loff_t *ppos)
891 struct il_priv *il = file->private_data;
893 return il->debugfs_ops->rx_stats_read(file, user_buf, count, ppos);
897 il_dbgfs_ucode_tx_stats_read(struct file *file, char __user *user_buf,
898 size_t count, loff_t *ppos)
900 struct il_priv *il = file->private_data;
902 return il->debugfs_ops->tx_stats_read(file, user_buf, count, ppos);
906 il_dbgfs_ucode_general_stats_read(struct file *file, char __user *user_buf,
907 size_t count, loff_t *ppos)
909 struct il_priv *il = file->private_data;
911 return il->debugfs_ops->general_stats_read(file, user_buf, count, ppos);
915 il_dbgfs_sensitivity_read(struct file *file, char __user *user_buf,
916 size_t count, loff_t *ppos)
919 struct il_priv *il = file->private_data;
923 int bufsz = sizeof(struct il_sensitivity_data) * 4 + 100;
925 struct il_sensitivity_data *data;
927 data = &il->sensitivity_data;
928 buf = kzalloc(bufsz, GFP_KERNEL);
930 IL_ERR("Can not allocate Buffer\n");
935 scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm:\t\t\t %u\n",
936 data->auto_corr_ofdm);
938 scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_mrc:\t\t %u\n",
939 data->auto_corr_ofdm_mrc);
941 scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_x1:\t\t %u\n",
942 data->auto_corr_ofdm_x1);
944 scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_mrc_x1:\t\t %u\n",
945 data->auto_corr_ofdm_mrc_x1);
947 scnprintf(buf + pos, bufsz - pos, "auto_corr_cck:\t\t\t %u\n",
948 data->auto_corr_cck);
950 scnprintf(buf + pos, bufsz - pos, "auto_corr_cck_mrc:\t\t %u\n",
951 data->auto_corr_cck_mrc);
953 scnprintf(buf + pos, bufsz - pos,
954 "last_bad_plcp_cnt_ofdm:\t\t %u\n",
955 data->last_bad_plcp_cnt_ofdm);
957 scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_ofdm:\t\t %u\n",
958 data->last_fa_cnt_ofdm);
960 scnprintf(buf + pos, bufsz - pos, "last_bad_plcp_cnt_cck:\t\t %u\n",
961 data->last_bad_plcp_cnt_cck);
963 scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_cck:\t\t %u\n",
964 data->last_fa_cnt_cck);
966 scnprintf(buf + pos, bufsz - pos, "nrg_curr_state:\t\t\t %u\n",
967 data->nrg_curr_state);
969 scnprintf(buf + pos, bufsz - pos, "nrg_prev_state:\t\t\t %u\n",
970 data->nrg_prev_state);
971 pos += scnprintf(buf + pos, bufsz - pos, "nrg_value:\t\t\t");
972 for (cnt = 0; cnt < 10; cnt++) {
974 scnprintf(buf + pos, bufsz - pos, " %u",
975 data->nrg_value[cnt]);
977 pos += scnprintf(buf + pos, bufsz - pos, "\n");
978 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_rssi:\t\t");
979 for (cnt = 0; cnt < NRG_NUM_PREV_STAT_L; cnt++) {
981 scnprintf(buf + pos, bufsz - pos, " %u",
982 data->nrg_silence_rssi[cnt]);
984 pos += scnprintf(buf + pos, bufsz - pos, "\n");
986 scnprintf(buf + pos, bufsz - pos, "nrg_silence_ref:\t\t %u\n",
987 data->nrg_silence_ref);
989 scnprintf(buf + pos, bufsz - pos, "nrg_energy_idx:\t\t\t %u\n",
990 data->nrg_energy_idx);
992 scnprintf(buf + pos, bufsz - pos, "nrg_silence_idx:\t\t %u\n",
993 data->nrg_silence_idx);
995 scnprintf(buf + pos, bufsz - pos, "nrg_th_cck:\t\t\t %u\n",
998 scnprintf(buf + pos, bufsz - pos,
999 "nrg_auto_corr_silence_diff:\t %u\n",
1000 data->nrg_auto_corr_silence_diff);
1002 scnprintf(buf + pos, bufsz - pos, "num_in_cck_no_fa:\t\t %u\n",
1003 data->num_in_cck_no_fa);
1005 scnprintf(buf + pos, bufsz - pos, "nrg_th_ofdm:\t\t\t %u\n",
1008 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1014 il_dbgfs_chain_noise_read(struct file *file, char __user *user_buf,
1015 size_t count, loff_t *ppos)
1018 struct il_priv *il = file->private_data;
1022 int bufsz = sizeof(struct il_chain_noise_data) * 4 + 100;
1024 struct il_chain_noise_data *data;
1026 data = &il->chain_noise_data;
1027 buf = kzalloc(bufsz, GFP_KERNEL);
1029 IL_ERR("Can not allocate Buffer\n");
1034 scnprintf(buf + pos, bufsz - pos, "active_chains:\t\t\t %u\n",
1035 data->active_chains);
1037 scnprintf(buf + pos, bufsz - pos, "chain_noise_a:\t\t\t %u\n",
1038 data->chain_noise_a);
1040 scnprintf(buf + pos, bufsz - pos, "chain_noise_b:\t\t\t %u\n",
1041 data->chain_noise_b);
1043 scnprintf(buf + pos, bufsz - pos, "chain_noise_c:\t\t\t %u\n",
1044 data->chain_noise_c);
1046 scnprintf(buf + pos, bufsz - pos, "chain_signal_a:\t\t\t %u\n",
1047 data->chain_signal_a);
1049 scnprintf(buf + pos, bufsz - pos, "chain_signal_b:\t\t\t %u\n",
1050 data->chain_signal_b);
1052 scnprintf(buf + pos, bufsz - pos, "chain_signal_c:\t\t\t %u\n",
1053 data->chain_signal_c);
1055 scnprintf(buf + pos, bufsz - pos, "beacon_count:\t\t\t %u\n",
1056 data->beacon_count);
1058 pos += scnprintf(buf + pos, bufsz - pos, "disconn_array:\t\t\t");
1059 for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
1061 scnprintf(buf + pos, bufsz - pos, " %u",
1062 data->disconn_array[cnt]);
1064 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1065 pos += scnprintf(buf + pos, bufsz - pos, "delta_gain_code:\t\t");
1066 for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
1068 scnprintf(buf + pos, bufsz - pos, " %u",
1069 data->delta_gain_code[cnt]);
1071 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1073 scnprintf(buf + pos, bufsz - pos, "radio_write:\t\t\t %u\n",
1076 scnprintf(buf + pos, bufsz - pos, "state:\t\t\t\t %u\n",
1079 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1085 il_dbgfs_power_save_status_read(struct file *file, char __user *user_buf,
1086 size_t count, loff_t *ppos)
1088 struct il_priv *il = file->private_data;
1091 const size_t bufsz = sizeof(buf);
1095 _il_rd(il, CSR_GP_CNTRL) & CSR_GP_REG_POWER_SAVE_STATUS_MSK;
1097 pos += scnprintf(buf + pos, bufsz - pos, "Power Save Status: ");
1099 scnprintf(buf + pos, bufsz - pos, "%s\n",
1100 (pwrsave_status == CSR_GP_REG_NO_POWER_SAVE) ? "none" :
1101 (pwrsave_status == CSR_GP_REG_MAC_POWER_SAVE) ? "MAC" :
1102 (pwrsave_status == CSR_GP_REG_PHY_POWER_SAVE) ? "PHY" :
1105 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1109 il_dbgfs_clear_ucode_stats_write(struct file *file,
1110 const char __user *user_buf, size_t count,
1113 struct il_priv *il = file->private_data;
1118 memset(buf, 0, sizeof(buf));
1119 buf_size = min(count, sizeof(buf) - 1);
1120 if (copy_from_user(buf, user_buf, buf_size))
1122 if (sscanf(buf, "%d", &clear) != 1)
1125 /* make request to uCode to retrieve stats information */
1126 mutex_lock(&il->mutex);
1127 il_send_stats_request(il, CMD_SYNC, true);
1128 mutex_unlock(&il->mutex);
1134 il_dbgfs_rxon_flags_read(struct file *file, char __user *user_buf,
1135 size_t count, loff_t *ppos)
1138 struct il_priv *il = file->private_data;
1142 len = sprintf(buf, "0x%04X\n", le32_to_cpu(il->active.flags));
1143 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1147 il_dbgfs_rxon_filter_flags_read(struct file *file, char __user *user_buf,
1148 size_t count, loff_t *ppos)
1151 struct il_priv *il = file->private_data;
1156 sprintf(buf, "0x%04X\n", le32_to_cpu(il->active.filter_flags));
1157 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1161 il_dbgfs_fh_reg_read(struct file *file, char __user *user_buf, size_t count,
1164 struct il_priv *il = file->private_data;
1167 ssize_t ret = -EFAULT;
1169 if (il->ops->dump_fh) {
1170 ret = pos = il->ops->dump_fh(il, &buf, true);
1173 simple_read_from_buffer(user_buf, count, ppos, buf,
1183 il_dbgfs_missed_beacon_read(struct file *file, char __user *user_buf,
1184 size_t count, loff_t *ppos)
1187 struct il_priv *il = file->private_data;
1190 const size_t bufsz = sizeof(buf);
1193 scnprintf(buf + pos, bufsz - pos, "%d\n",
1194 il->missed_beacon_threshold);
1196 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1200 il_dbgfs_missed_beacon_write(struct file *file, const char __user *user_buf,
1201 size_t count, loff_t *ppos)
1203 struct il_priv *il = file->private_data;
1208 memset(buf, 0, sizeof(buf));
1209 buf_size = min(count, sizeof(buf) - 1);
1210 if (copy_from_user(buf, user_buf, buf_size))
1212 if (sscanf(buf, "%d", &missed) != 1)
1215 if (missed < IL_MISSED_BEACON_THRESHOLD_MIN ||
1216 missed > IL_MISSED_BEACON_THRESHOLD_MAX)
1217 il->missed_beacon_threshold = IL_MISSED_BEACON_THRESHOLD_DEF;
1219 il->missed_beacon_threshold = missed;
1225 il_dbgfs_force_reset_read(struct file *file, char __user *user_buf,
1226 size_t count, loff_t *ppos)
1229 struct il_priv *il = file->private_data;
1232 const size_t bufsz = sizeof(buf);
1233 struct il_force_reset *force_reset;
1235 force_reset = &il->force_reset;
1238 scnprintf(buf + pos, bufsz - pos, "\tnumber of reset request: %d\n",
1239 force_reset->reset_request_count);
1241 scnprintf(buf + pos, bufsz - pos,
1242 "\tnumber of reset request success: %d\n",
1243 force_reset->reset_success_count);
1245 scnprintf(buf + pos, bufsz - pos,
1246 "\tnumber of reset request reject: %d\n",
1247 force_reset->reset_reject_count);
1249 scnprintf(buf + pos, bufsz - pos, "\treset duration: %lu\n",
1250 force_reset->reset_duration);
1252 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1256 il_dbgfs_force_reset_write(struct file *file, const char __user *user_buf,
1257 size_t count, loff_t *ppos)
1261 struct il_priv *il = file->private_data;
1263 ret = il_force_reset(il, true);
1265 return ret ? ret : count;
1269 il_dbgfs_wd_timeout_write(struct file *file, const char __user *user_buf,
1270 size_t count, loff_t *ppos)
1273 struct il_priv *il = file->private_data;
1278 memset(buf, 0, sizeof(buf));
1279 buf_size = min(count, sizeof(buf) - 1);
1280 if (copy_from_user(buf, user_buf, buf_size))
1282 if (sscanf(buf, "%d", &timeout) != 1)
1284 if (timeout < 0 || timeout > IL_MAX_WD_TIMEOUT)
1285 timeout = IL_DEF_WD_TIMEOUT;
1287 il->cfg->wd_timeout = timeout;
1288 il_setup_watchdog(il);
1292 DEBUGFS_READ_FILE_OPS(rx_stats);
1293 DEBUGFS_READ_FILE_OPS(tx_stats);
1294 DEBUGFS_READ_FILE_OPS(rx_queue);
1295 DEBUGFS_READ_FILE_OPS(tx_queue);
1296 DEBUGFS_READ_FILE_OPS(ucode_rx_stats);
1297 DEBUGFS_READ_FILE_OPS(ucode_tx_stats);
1298 DEBUGFS_READ_FILE_OPS(ucode_general_stats);
1299 DEBUGFS_READ_FILE_OPS(sensitivity);
1300 DEBUGFS_READ_FILE_OPS(chain_noise);
1301 DEBUGFS_READ_FILE_OPS(power_save_status);
1302 DEBUGFS_WRITE_FILE_OPS(clear_ucode_stats);
1303 DEBUGFS_WRITE_FILE_OPS(clear_traffic_stats);
1304 DEBUGFS_READ_FILE_OPS(fh_reg);
1305 DEBUGFS_READ_WRITE_FILE_OPS(missed_beacon);
1306 DEBUGFS_READ_WRITE_FILE_OPS(force_reset);
1307 DEBUGFS_READ_FILE_OPS(rxon_flags);
1308 DEBUGFS_READ_FILE_OPS(rxon_filter_flags);
1309 DEBUGFS_WRITE_FILE_OPS(wd_timeout);
1312 * Create the debugfs files and directories
1316 il_dbgfs_register(struct il_priv *il, const char *name)
1318 struct dentry *phyd = il->hw->wiphy->debugfsdir;
1319 struct dentry *dir_drv, *dir_data, *dir_rf, *dir_debug;
1321 dir_drv = debugfs_create_dir(name, phyd);
1322 il->debugfs_dir = dir_drv;
1324 dir_data = debugfs_create_dir("data", dir_drv);
1325 dir_rf = debugfs_create_dir("rf", dir_drv);
1326 dir_debug = debugfs_create_dir("debug", dir_drv);
1328 DEBUGFS_ADD_FILE(nvm, dir_data, 0400);
1329 DEBUGFS_ADD_FILE(sram, dir_data, 0600);
1330 DEBUGFS_ADD_FILE(stations, dir_data, 0400);
1331 DEBUGFS_ADD_FILE(channels, dir_data, 0400);
1332 DEBUGFS_ADD_FILE(status, dir_data, 0400);
1333 DEBUGFS_ADD_FILE(interrupt, dir_data, 0600);
1334 DEBUGFS_ADD_FILE(qos, dir_data, 0400);
1335 DEBUGFS_ADD_FILE(disable_ht40, dir_data, 0600);
1336 DEBUGFS_ADD_FILE(rx_stats, dir_debug, 0400);
1337 DEBUGFS_ADD_FILE(tx_stats, dir_debug, 0400);
1338 DEBUGFS_ADD_FILE(rx_queue, dir_debug, 0400);
1339 DEBUGFS_ADD_FILE(tx_queue, dir_debug, 0400);
1340 DEBUGFS_ADD_FILE(power_save_status, dir_debug, 0400);
1341 DEBUGFS_ADD_FILE(clear_ucode_stats, dir_debug, 0200);
1342 DEBUGFS_ADD_FILE(clear_traffic_stats, dir_debug, 0200);
1343 DEBUGFS_ADD_FILE(fh_reg, dir_debug, 0400);
1344 DEBUGFS_ADD_FILE(missed_beacon, dir_debug, 0200);
1345 DEBUGFS_ADD_FILE(force_reset, dir_debug, 0600);
1346 DEBUGFS_ADD_FILE(ucode_rx_stats, dir_debug, 0400);
1347 DEBUGFS_ADD_FILE(ucode_tx_stats, dir_debug, 0400);
1348 DEBUGFS_ADD_FILE(ucode_general_stats, dir_debug, 0400);
1350 if (il->cfg->sensitivity_calib_by_driver)
1351 DEBUGFS_ADD_FILE(sensitivity, dir_debug, 0400);
1352 if (il->cfg->chain_noise_calib_by_driver)
1353 DEBUGFS_ADD_FILE(chain_noise, dir_debug, 0400);
1354 DEBUGFS_ADD_FILE(rxon_flags, dir_debug, 0200);
1355 DEBUGFS_ADD_FILE(rxon_filter_flags, dir_debug, 0200);
1356 DEBUGFS_ADD_FILE(wd_timeout, dir_debug, 0200);
1357 if (il->cfg->sensitivity_calib_by_driver)
1358 DEBUGFS_ADD_BOOL(disable_sensitivity, dir_rf,
1359 &il->disable_sens_cal);
1360 if (il->cfg->chain_noise_calib_by_driver)
1361 DEBUGFS_ADD_BOOL(disable_chain_noise, dir_rf,
1362 &il->disable_chain_noise_cal);
1363 DEBUGFS_ADD_BOOL(disable_tx_power, dir_rf, &il->disable_tx_power_cal);
1365 EXPORT_SYMBOL(il_dbgfs_register);
1368 * Remove the debugfs files and directories
1371 il_dbgfs_unregister(struct il_priv *il)
1373 if (!il->debugfs_dir)
1376 debugfs_remove_recursive(il->debugfs_dir);
1377 il->debugfs_dir = NULL;
1379 EXPORT_SYMBOL(il_dbgfs_unregister);