1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#include <linux/slab.h>
26#include <linux/kernel.h>
27#include <linux/module.h>
28#include <linux/debugfs.h>
29#include <linux/ieee80211.h>
30#include <net/mac80211.h>
31
32#include "iwl-debug.h"
33#include "iwl-trans.h"
34#include "iwl-io.h"
35#include "dev.h"
36#include "agn.h"
37
38
39#define DEBUGFS_ADD_FILE(name, parent, mode) do { \
40 debugfs_create_file(#name, mode, parent, priv, \
41 &iwl_dbgfs_##name##_ops); \
42} while (0)
43
44
45#define DEBUGFS_READ_FILE_OPS(name) \
46static const struct file_operations iwl_dbgfs_##name##_ops = { \
47 .read = iwl_dbgfs_##name##_read, \
48 .open = simple_open, \
49 .llseek = generic_file_llseek, \
50};
51
52#define DEBUGFS_WRITE_FILE_OPS(name) \
53static const struct file_operations iwl_dbgfs_##name##_ops = { \
54 .write = iwl_dbgfs_##name##_write, \
55 .open = simple_open, \
56 .llseek = generic_file_llseek, \
57};
58
59
60#define DEBUGFS_READ_WRITE_FILE_OPS(name) \
61static const struct file_operations iwl_dbgfs_##name##_ops = { \
62 .write = iwl_dbgfs_##name##_write, \
63 .read = iwl_dbgfs_##name##_read, \
64 .open = simple_open, \
65 .llseek = generic_file_llseek, \
66};
67
68static ssize_t iwl_dbgfs_sram_read(struct file *file,
69 char __user *user_buf,
70 size_t count, loff_t *ppos)
71{
72 u32 val = 0;
73 char *buf;
74 ssize_t ret;
75 int i = 0;
76 bool device_format = false;
77 int offset = 0;
78 int len = 0;
79 int pos = 0;
80 int sram;
81 struct iwl_priv *priv = file->private_data;
82 const struct fw_img *img;
83 size_t bufsz;
84
85 if (!iwl_is_ready_rf(priv))
86 return -EAGAIN;
87
88
89 if (!priv->dbgfs_sram_offset && !priv->dbgfs_sram_len) {
90 priv->dbgfs_sram_offset = 0x800000;
91 if (!priv->ucode_loaded)
92 return -EINVAL;
93 img = &priv->fw->img[priv->cur_ucode];
94 priv->dbgfs_sram_len = img->sec[IWL_UCODE_SECTION_DATA].len;
95 }
96 len = priv->dbgfs_sram_len;
97
98 if (len == -4) {
99 device_format = true;
100 len = 4;
101 }
102
103 bufsz = 50 + len * 4;
104 buf = kmalloc(bufsz, GFP_KERNEL);
105 if (!buf)
106 return -ENOMEM;
107
108 pos += scnprintf(buf + pos, bufsz - pos, "sram_len: 0x%x\n",
109 len);
110 pos += scnprintf(buf + pos, bufsz - pos, "sram_offset: 0x%x\n",
111 priv->dbgfs_sram_offset);
112
113
114 offset = priv->dbgfs_sram_offset & 0x3;
115 sram = priv->dbgfs_sram_offset & ~0x3;
116
117
118 val = iwl_trans_read_mem32(priv->trans, sram);
119
120 for (; len; len--) {
121
122 if (i == 0)
123 pos += scnprintf(buf + pos, bufsz - pos,
124 "%08X: ", sram + offset);
125
126 if (device_format)
127 pos += scnprintf(buf + pos, bufsz - pos,
128 "%02x", (val >> (8 * (3 - offset))) & 0xff);
129 else
130 pos += scnprintf(buf + pos, bufsz - pos,
131 "%02x ", (val >> (8 * offset)) & 0xff);
132
133
134 if (++offset == 4) {
135 sram += 4;
136 offset = 0;
137 val = iwl_trans_read_mem32(priv->trans, sram);
138 }
139
140
141 if (++i == 16) {
142 i = 0;
143 pos += scnprintf(buf + pos, bufsz - pos, "\n");
144 } else if (!(i & 7)) {
145 pos += scnprintf(buf + pos, bufsz - pos, " ");
146 } else if (!(i & 3)) {
147 pos += scnprintf(buf + pos, bufsz - pos, " ");
148 }
149 }
150 if (i)
151 pos += scnprintf(buf + pos, bufsz - pos, "\n");
152
153 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
154 kfree(buf);
155 return ret;
156}
157
158static ssize_t iwl_dbgfs_sram_write(struct file *file,
159 const char __user *user_buf,
160 size_t count, loff_t *ppos)
161{
162 struct iwl_priv *priv = file->private_data;
163 char buf[64];
164 int buf_size;
165 u32 offset, len;
166
167 memset(buf, 0, sizeof(buf));
168 buf_size = min(count, sizeof(buf) - 1);
169 if (copy_from_user(buf, user_buf, buf_size))
170 return -EFAULT;
171
172 if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
173 priv->dbgfs_sram_offset = offset;
174 priv->dbgfs_sram_len = len;
175 } else if (sscanf(buf, "%x", &offset) == 1) {
176 priv->dbgfs_sram_offset = offset;
177 priv->dbgfs_sram_len = -4;
178 } else {
179 priv->dbgfs_sram_offset = 0;
180 priv->dbgfs_sram_len = 0;
181 }
182
183 return count;
184}
185
186static ssize_t iwl_dbgfs_wowlan_sram_read(struct file *file,
187 char __user *user_buf,
188 size_t count, loff_t *ppos)
189{
190 struct iwl_priv *priv = file->private_data;
191 const struct fw_img *img = &priv->fw->img[IWL_UCODE_WOWLAN];
192
193 if (!priv->wowlan_sram)
194 return -ENODATA;
195
196 return simple_read_from_buffer(user_buf, count, ppos,
197 priv->wowlan_sram,
198 img->sec[IWL_UCODE_SECTION_DATA].len);
199}
200static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
201 size_t count, loff_t *ppos)
202{
203 struct iwl_priv *priv = file->private_data;
204 struct iwl_station_entry *station;
205 struct iwl_tid_data *tid_data;
206 char *buf;
207 int i, j, pos = 0;
208 ssize_t ret;
209
210 const size_t bufsz = 30 + sizeof(char) * 500 * (priv->num_stations);
211
212 buf = kmalloc(bufsz, GFP_KERNEL);
213 if (!buf)
214 return -ENOMEM;
215
216 pos += scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n",
217 priv->num_stations);
218
219 for (i = 0; i < IWLAGN_STATION_COUNT; i++) {
220 station = &priv->stations[i];
221 if (!station->used)
222 continue;
223 pos += scnprintf(buf + pos, bufsz - pos,
224 "station %d - addr: %pM, flags: %#x\n",
225 i, station->sta.sta.addr,
226 station->sta.station_flags_msk);
227 pos += scnprintf(buf + pos, bufsz - pos,
228 "TID seqno next_rclmd "
229 "rate_n_flags state txq\n");
230
231 for (j = 0; j < IWL_MAX_TID_COUNT; j++) {
232 tid_data = &priv->tid_data[i][j];
233 pos += scnprintf(buf + pos, bufsz - pos,
234 "%d: 0x%.4x 0x%.4x 0x%.8x "
235 "%d %.2d",
236 j, tid_data->seq_number,
237 tid_data->next_reclaimed,
238 tid_data->agg.rate_n_flags,
239 tid_data->agg.state,
240 tid_data->agg.txq_id);
241
242 if (tid_data->agg.wait_for_ba)
243 pos += scnprintf(buf + pos, bufsz - pos,
244 " - waitforba");
245 pos += scnprintf(buf + pos, bufsz - pos, "\n");
246 }
247
248 pos += scnprintf(buf + pos, bufsz - pos, "\n");
249 }
250
251 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
252 kfree(buf);
253 return ret;
254}
255
256static ssize_t iwl_dbgfs_nvm_read(struct file *file,
257 char __user *user_buf,
258 size_t count,
259 loff_t *ppos)
260{
261 ssize_t ret;
262 struct iwl_priv *priv = file->private_data;
263 int pos = 0, ofs = 0, buf_size = 0;
264 const u8 *ptr;
265 char *buf;
266 u16 nvm_ver;
267 size_t eeprom_len = priv->eeprom_blob_size;
268 buf_size = 4 * eeprom_len + 256;
269
270 if (eeprom_len % 16)
271 return -ENODATA;
272
273 ptr = priv->eeprom_blob;
274 if (!ptr)
275 return -ENOMEM;
276
277
278 buf = kzalloc(buf_size, GFP_KERNEL);
279 if (!buf)
280 return -ENOMEM;
281
282 nvm_ver = priv->nvm_data->nvm_version;
283 pos += scnprintf(buf + pos, buf_size - pos,
284 "NVM version: 0x%x\n", nvm_ver);
285 for (ofs = 0 ; ofs < eeprom_len ; ofs += 16) {
286 pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x %16ph\n",
287 ofs, ptr + ofs);
288 }
289
290 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
291 kfree(buf);
292 return ret;
293}
294
295static ssize_t iwl_dbgfs_channels_read(struct file *file, char __user *user_buf,
296 size_t count, loff_t *ppos)
297{
298 struct iwl_priv *priv = file->private_data;
299 struct ieee80211_channel *channels = NULL;
300 const struct ieee80211_supported_band *supp_band = NULL;
301 int pos = 0, i, bufsz = PAGE_SIZE;
302 char *buf;
303 ssize_t ret;
304
305 buf = kzalloc(bufsz, GFP_KERNEL);
306 if (!buf)
307 return -ENOMEM;
308
309 supp_band = iwl_get_hw_mode(priv, NL80211_BAND_2GHZ);
310 if (supp_band) {
311 channels = supp_band->channels;
312
313 pos += scnprintf(buf + pos, bufsz - pos,
314 "Displaying %d channels in 2.4GHz band 802.11bg):\n",
315 supp_band->n_channels);
316
317 for (i = 0; i < supp_band->n_channels; i++)
318 pos += scnprintf(buf + pos, bufsz - pos,
319 "%d: %ddBm: BSS%s%s, %s.\n",
320 channels[i].hw_value,
321 channels[i].max_power,
322 channels[i].flags & IEEE80211_CHAN_RADAR ?
323 " (IEEE 802.11h required)" : "",
324 ((channels[i].flags & IEEE80211_CHAN_NO_IR)
325 || (channels[i].flags &
326 IEEE80211_CHAN_RADAR)) ? "" :
327 ", IBSS",
328 channels[i].flags &
329 IEEE80211_CHAN_NO_IR ?
330 "passive only" : "active/passive");
331 }
332 supp_band = iwl_get_hw_mode(priv, NL80211_BAND_5GHZ);
333 if (supp_band) {
334 channels = supp_band->channels;
335
336 pos += scnprintf(buf + pos, bufsz - pos,
337 "Displaying %d channels in 5.2GHz band (802.11a)\n",
338 supp_band->n_channels);
339
340 for (i = 0; i < supp_band->n_channels; i++)
341 pos += scnprintf(buf + pos, bufsz - pos,
342 "%d: %ddBm: BSS%s%s, %s.\n",
343 channels[i].hw_value,
344 channels[i].max_power,
345 channels[i].flags & IEEE80211_CHAN_RADAR ?
346 " (IEEE 802.11h required)" : "",
347 ((channels[i].flags & IEEE80211_CHAN_NO_IR)
348 || (channels[i].flags &
349 IEEE80211_CHAN_RADAR)) ? "" :
350 ", IBSS",
351 channels[i].flags &
352 IEEE80211_CHAN_NO_IR ?
353 "passive only" : "active/passive");
354 }
355 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
356 kfree(buf);
357 return ret;
358}
359
360static ssize_t iwl_dbgfs_status_read(struct file *file,
361 char __user *user_buf,
362 size_t count, loff_t *ppos) {
363
364 struct iwl_priv *priv = file->private_data;
365 char buf[512];
366 int pos = 0;
367 const size_t bufsz = sizeof(buf);
368
369 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_RF_KILL_HW:\t %d\n",
370 test_bit(STATUS_RF_KILL_HW, &priv->status));
371 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_CT_KILL:\t\t %d\n",
372 test_bit(STATUS_CT_KILL, &priv->status));
373 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_ALIVE:\t\t %d\n",
374 test_bit(STATUS_ALIVE, &priv->status));
375 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_READY:\t\t %d\n",
376 test_bit(STATUS_READY, &priv->status));
377 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_EXIT_PENDING:\t %d\n",
378 test_bit(STATUS_EXIT_PENDING, &priv->status));
379 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_STATISTICS:\t %d\n",
380 test_bit(STATUS_STATISTICS, &priv->status));
381 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCANNING:\t %d\n",
382 test_bit(STATUS_SCANNING, &priv->status));
383 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_ABORTING:\t %d\n",
384 test_bit(STATUS_SCAN_ABORTING, &priv->status));
385 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_HW:\t\t %d\n",
386 test_bit(STATUS_SCAN_HW, &priv->status));
387 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_POWER_PMI:\t %d\n",
388 test_bit(STATUS_POWER_PMI, &priv->status));
389 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_FW_ERROR:\t %d\n",
390 test_bit(STATUS_FW_ERROR, &priv->status));
391 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
392}
393
394static ssize_t iwl_dbgfs_rx_handlers_read(struct file *file,
395 char __user *user_buf,
396 size_t count, loff_t *ppos) {
397
398 struct iwl_priv *priv = file->private_data;
399
400 int pos = 0;
401 int cnt = 0;
402 char *buf;
403 int bufsz = 24 * 64;
404 ssize_t ret;
405
406 buf = kzalloc(bufsz, GFP_KERNEL);
407 if (!buf)
408 return -ENOMEM;
409
410 for (cnt = 0; cnt < REPLY_MAX; cnt++) {
411 if (priv->rx_handlers_stats[cnt] > 0)
412 pos += scnprintf(buf + pos, bufsz - pos,
413 "\tRx handler[%36s]:\t\t %u\n",
414 iwl_get_cmd_string(priv->trans, (u32)cnt),
415 priv->rx_handlers_stats[cnt]);
416 }
417
418 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
419 kfree(buf);
420 return ret;
421}
422
423static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
424 const char __user *user_buf,
425 size_t count, loff_t *ppos)
426{
427 struct iwl_priv *priv = file->private_data;
428
429 char buf[8];
430 int buf_size;
431 u32 reset_flag;
432
433 memset(buf, 0, sizeof(buf));
434 buf_size = min(count, sizeof(buf) - 1);
435 if (copy_from_user(buf, user_buf, buf_size))
436 return -EFAULT;
437 if (sscanf(buf, "%x", &reset_flag) != 1)
438 return -EFAULT;
439 if (reset_flag == 0)
440 memset(&priv->rx_handlers_stats[0], 0,
441 sizeof(priv->rx_handlers_stats));
442
443 return count;
444}
445
446static ssize_t iwl_dbgfs_qos_read(struct file *file, char __user *user_buf,
447 size_t count, loff_t *ppos)
448{
449 struct iwl_priv *priv = file->private_data;
450 struct iwl_rxon_context *ctx;
451 int pos = 0, i;
452 char buf[256 * NUM_IWL_RXON_CTX];
453 const size_t bufsz = sizeof(buf);
454
455 for_each_context(priv, ctx) {
456 pos += scnprintf(buf + pos, bufsz - pos, "context %d:\n",
457 ctx->ctxid);
458 for (i = 0; i < AC_NUM; i++) {
459 pos += scnprintf(buf + pos, bufsz - pos,
460 "\tcw_min\tcw_max\taifsn\ttxop\n");
461 pos += scnprintf(buf + pos, bufsz - pos,
462 "AC[%d]\t%u\t%u\t%u\t%u\n", i,
463 ctx->qos_data.def_qos_parm.ac[i].cw_min,
464 ctx->qos_data.def_qos_parm.ac[i].cw_max,
465 ctx->qos_data.def_qos_parm.ac[i].aifsn,
466 ctx->qos_data.def_qos_parm.ac[i].edca_txop);
467 }
468 pos += scnprintf(buf + pos, bufsz - pos, "\n");
469 }
470 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
471}
472
473static ssize_t iwl_dbgfs_thermal_throttling_read(struct file *file,
474 char __user *user_buf,
475 size_t count, loff_t *ppos)
476{
477 struct iwl_priv *priv = file->private_data;
478 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
479 struct iwl_tt_restriction *restriction;
480 char buf[100];
481 int pos = 0;
482 const size_t bufsz = sizeof(buf);
483
484 pos += scnprintf(buf + pos, bufsz - pos,
485 "Thermal Throttling Mode: %s\n",
486 tt->advanced_tt ? "Advance" : "Legacy");
487 pos += scnprintf(buf + pos, bufsz - pos,
488 "Thermal Throttling State: %d\n",
489 tt->state);
490 if (tt->advanced_tt) {
491 restriction = tt->restriction + tt->state;
492 pos += scnprintf(buf + pos, bufsz - pos,
493 "Tx mode: %d\n",
494 restriction->tx_stream);
495 pos += scnprintf(buf + pos, bufsz - pos,
496 "Rx mode: %d\n",
497 restriction->rx_stream);
498 pos += scnprintf(buf + pos, bufsz - pos,
499 "HT mode: %d\n",
500 restriction->is_ht);
501 }
502 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
503}
504
505static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
506 const char __user *user_buf,
507 size_t count, loff_t *ppos)
508{
509 struct iwl_priv *priv = file->private_data;
510 char buf[8];
511 int buf_size;
512 int ht40;
513
514 memset(buf, 0, sizeof(buf));
515 buf_size = min(count, sizeof(buf) - 1);
516 if (copy_from_user(buf, user_buf, buf_size))
517 return -EFAULT;
518 if (sscanf(buf, "%d", &ht40) != 1)
519 return -EFAULT;
520 if (!iwl_is_any_associated(priv))
521 priv->disable_ht40 = ht40 ? true : false;
522 else
523 return -EINVAL;
524
525 return count;
526}
527
528static ssize_t iwl_dbgfs_disable_ht40_read(struct file *file,
529 char __user *user_buf,
530 size_t count, loff_t *ppos)
531{
532 struct iwl_priv *priv = file->private_data;
533 char buf[100];
534 int pos = 0;
535 const size_t bufsz = sizeof(buf);
536
537 pos += scnprintf(buf + pos, bufsz - pos,
538 "11n 40MHz Mode: %s\n",
539 priv->disable_ht40 ? "Disabled" : "Enabled");
540 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
541}
542
543static ssize_t iwl_dbgfs_temperature_read(struct file *file,
544 char __user *user_buf,
545 size_t count, loff_t *ppos)
546{
547 struct iwl_priv *priv = file->private_data;
548 char buf[8];
549 int pos = 0;
550 const size_t bufsz = sizeof(buf);
551
552 pos += scnprintf(buf + pos, bufsz - pos, "%d\n", priv->temperature);
553 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
554}
555
556
557static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
558 const char __user *user_buf,
559 size_t count, loff_t *ppos)
560{
561 struct iwl_priv *priv = file->private_data;
562 char buf[8];
563 int buf_size;
564 int value;
565
566 memset(buf, 0, sizeof(buf));
567 buf_size = min(count, sizeof(buf) - 1);
568 if (copy_from_user(buf, user_buf, buf_size))
569 return -EFAULT;
570
571 if (sscanf(buf, "%d", &value) != 1)
572 return -EINVAL;
573
574
575
576
577
578
579 if (value == 0)
580 return -EINVAL;
581 else if (value > 0)
582 value -= 1;
583
584 if (value != -1 && (value < 0 || value >= IWL_POWER_NUM))
585 return -EINVAL;
586
587 if (!iwl_is_ready_rf(priv))
588 return -EAGAIN;
589
590 priv->power_data.debug_sleep_level_override = value;
591
592 mutex_lock(&priv->mutex);
593 iwl_power_update_mode(priv, true);
594 mutex_unlock(&priv->mutex);
595
596 return count;
597}
598
599static ssize_t iwl_dbgfs_sleep_level_override_read(struct file *file,
600 char __user *user_buf,
601 size_t count, loff_t *ppos)
602{
603 struct iwl_priv *priv = file->private_data;
604 char buf[10];
605 int pos, value;
606 const size_t bufsz = sizeof(buf);
607
608
609 value = priv->power_data.debug_sleep_level_override;
610 if (value >= 0)
611 value += 1;
612
613 pos = scnprintf(buf, bufsz, "%d\n", value);
614 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
615}
616
617static ssize_t iwl_dbgfs_current_sleep_command_read(struct file *file,
618 char __user *user_buf,
619 size_t count, loff_t *ppos)
620{
621 struct iwl_priv *priv = file->private_data;
622 char buf[200];
623 int pos = 0, i;
624 const size_t bufsz = sizeof(buf);
625 struct iwl_powertable_cmd *cmd = &priv->power_data.sleep_cmd;
626
627 pos += scnprintf(buf + pos, bufsz - pos,
628 "flags: %#.2x\n", le16_to_cpu(cmd->flags));
629 pos += scnprintf(buf + pos, bufsz - pos,
630 "RX/TX timeout: %d/%d usec\n",
631 le32_to_cpu(cmd->rx_data_timeout),
632 le32_to_cpu(cmd->tx_data_timeout));
633 for (i = 0; i < IWL_POWER_VEC_SIZE; i++)
634 pos += scnprintf(buf + pos, bufsz - pos,
635 "sleep_interval[%d]: %d\n", i,
636 le32_to_cpu(cmd->sleep_interval[i]));
637
638 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
639}
640
641DEBUGFS_READ_WRITE_FILE_OPS(sram);
642DEBUGFS_READ_FILE_OPS(wowlan_sram);
643DEBUGFS_READ_FILE_OPS(nvm);
644DEBUGFS_READ_FILE_OPS(stations);
645DEBUGFS_READ_FILE_OPS(channels);
646DEBUGFS_READ_FILE_OPS(status);
647DEBUGFS_READ_WRITE_FILE_OPS(rx_handlers);
648DEBUGFS_READ_FILE_OPS(qos);
649DEBUGFS_READ_FILE_OPS(thermal_throttling);
650DEBUGFS_READ_WRITE_FILE_OPS(disable_ht40);
651DEBUGFS_READ_FILE_OPS(temperature);
652DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
653DEBUGFS_READ_FILE_OPS(current_sleep_command);
654
655#define fmt_value " %-30s %10u\n"
656#define fmt_hex " %-30s 0x%02X\n"
657#define fmt_table " %-30s %10u %10u %10u %10u\n"
658#define fmt_header "%-32s current cumulative delta max\n"
659
660static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
661{
662 int p = 0;
663 u32 flag;
664
665 lockdep_assert_held(&priv->statistics.lock);
666
667 flag = le32_to_cpu(priv->statistics.flag);
668
669 p += scnprintf(buf + p, bufsz - p, "Statistics Flag(0x%X):\n", flag);
670 if (flag & UCODE_STATISTICS_CLEAR_MSK)
671 p += scnprintf(buf + p, bufsz - p,
672 "\tStatistics have been cleared\n");
673 p += scnprintf(buf + p, bufsz - p, "\tOperational Frequency: %s\n",
674 (flag & UCODE_STATISTICS_FREQUENCY_MSK)
675 ? "2.4 GHz" : "5.2 GHz");
676 p += scnprintf(buf + p, bufsz - p, "\tTGj Narrow Band: %s\n",
677 (flag & UCODE_STATISTICS_NARROW_BAND_MSK)
678 ? "enabled" : "disabled");
679
680 return p;
681}
682
683static ssize_t iwl_dbgfs_ucode_rx_stats_read(struct file *file,
684 char __user *user_buf,
685 size_t count, loff_t *ppos)
686{
687 struct iwl_priv *priv = file->private_data;
688 int pos = 0;
689 char *buf;
690 int bufsz = sizeof(struct statistics_rx_phy) * 40 +
691 sizeof(struct statistics_rx_non_phy) * 40 +
692 sizeof(struct statistics_rx_ht_phy) * 40 + 400;
693 ssize_t ret;
694 struct statistics_rx_phy *ofdm, *accum_ofdm, *delta_ofdm, *max_ofdm;
695 struct statistics_rx_phy *cck, *accum_cck, *delta_cck, *max_cck;
696 struct statistics_rx_non_phy *general, *accum_general;
697 struct statistics_rx_non_phy *delta_general, *max_general;
698 struct statistics_rx_ht_phy *ht, *accum_ht, *delta_ht, *max_ht;
699
700 if (!iwl_is_alive(priv))
701 return -EAGAIN;
702
703 buf = kzalloc(bufsz, GFP_KERNEL);
704 if (!buf)
705 return -ENOMEM;
706
707
708
709
710
711
712 spin_lock_bh(&priv->statistics.lock);
713 ofdm = &priv->statistics.rx_ofdm;
714 cck = &priv->statistics.rx_cck;
715 general = &priv->statistics.rx_non_phy;
716 ht = &priv->statistics.rx_ofdm_ht;
717 accum_ofdm = &priv->accum_stats.rx_ofdm;
718 accum_cck = &priv->accum_stats.rx_cck;
719 accum_general = &priv->accum_stats.rx_non_phy;
720 accum_ht = &priv->accum_stats.rx_ofdm_ht;
721 delta_ofdm = &priv->delta_stats.rx_ofdm;
722 delta_cck = &priv->delta_stats.rx_cck;
723 delta_general = &priv->delta_stats.rx_non_phy;
724 delta_ht = &priv->delta_stats.rx_ofdm_ht;
725 max_ofdm = &priv->max_delta_stats.rx_ofdm;
726 max_cck = &priv->max_delta_stats.rx_cck;
727 max_general = &priv->max_delta_stats.rx_non_phy;
728 max_ht = &priv->max_delta_stats.rx_ofdm_ht;
729
730 pos += iwl_statistics_flag(priv, buf, bufsz);
731 pos += scnprintf(buf + pos, bufsz - pos,
732 fmt_header, "Statistics_Rx - OFDM:");
733 pos += scnprintf(buf + pos, bufsz - pos,
734 fmt_table, "ina_cnt:",
735 le32_to_cpu(ofdm->ina_cnt),
736 accum_ofdm->ina_cnt,
737 delta_ofdm->ina_cnt, max_ofdm->ina_cnt);
738 pos += scnprintf(buf + pos, bufsz - pos,
739 fmt_table, "fina_cnt:",
740 le32_to_cpu(ofdm->fina_cnt), accum_ofdm->fina_cnt,
741 delta_ofdm->fina_cnt, max_ofdm->fina_cnt);
742 pos += scnprintf(buf + pos, bufsz - pos,
743 fmt_table, "plcp_err:",
744 le32_to_cpu(ofdm->plcp_err), accum_ofdm->plcp_err,
745 delta_ofdm->plcp_err, max_ofdm->plcp_err);
746 pos += scnprintf(buf + pos, bufsz - pos,
747 fmt_table, "crc32_err:",
748 le32_to_cpu(ofdm->crc32_err), accum_ofdm->crc32_err,
749 delta_ofdm->crc32_err, max_ofdm->crc32_err);
750 pos += scnprintf(buf + pos, bufsz - pos,
751 fmt_table, "overrun_err:",
752 le32_to_cpu(ofdm->overrun_err),
753 accum_ofdm->overrun_err, delta_ofdm->overrun_err,
754 max_ofdm->overrun_err);
755 pos += scnprintf(buf + pos, bufsz - pos,
756 fmt_table, "early_overrun_err:",
757 le32_to_cpu(ofdm->early_overrun_err),
758 accum_ofdm->early_overrun_err,
759 delta_ofdm->early_overrun_err,
760 max_ofdm->early_overrun_err);
761 pos += scnprintf(buf + pos, bufsz - pos,
762 fmt_table, "crc32_good:",
763 le32_to_cpu(ofdm->crc32_good),
764 accum_ofdm->crc32_good, delta_ofdm->crc32_good,
765 max_ofdm->crc32_good);
766 pos += scnprintf(buf + pos, bufsz - pos,
767 fmt_table, "false_alarm_cnt:",
768 le32_to_cpu(ofdm->false_alarm_cnt),
769 accum_ofdm->false_alarm_cnt,
770 delta_ofdm->false_alarm_cnt,
771 max_ofdm->false_alarm_cnt);
772 pos += scnprintf(buf + pos, bufsz - pos,
773 fmt_table, "fina_sync_err_cnt:",
774 le32_to_cpu(ofdm->fina_sync_err_cnt),
775 accum_ofdm->fina_sync_err_cnt,
776 delta_ofdm->fina_sync_err_cnt,
777 max_ofdm->fina_sync_err_cnt);
778 pos += scnprintf(buf + pos, bufsz - pos,
779 fmt_table, "sfd_timeout:",
780 le32_to_cpu(ofdm->sfd_timeout),
781 accum_ofdm->sfd_timeout, delta_ofdm->sfd_timeout,
782 max_ofdm->sfd_timeout);
783 pos += scnprintf(buf + pos, bufsz - pos,
784 fmt_table, "fina_timeout:",
785 le32_to_cpu(ofdm->fina_timeout),
786 accum_ofdm->fina_timeout, delta_ofdm->fina_timeout,
787 max_ofdm->fina_timeout);
788 pos += scnprintf(buf + pos, bufsz - pos,
789 fmt_table, "unresponded_rts:",
790 le32_to_cpu(ofdm->unresponded_rts),
791 accum_ofdm->unresponded_rts,
792 delta_ofdm->unresponded_rts,
793 max_ofdm->unresponded_rts);
794 pos += scnprintf(buf + pos, bufsz - pos,
795 fmt_table, "rxe_frame_lmt_ovrun:",
796 le32_to_cpu(ofdm->rxe_frame_limit_overrun),
797 accum_ofdm->rxe_frame_limit_overrun,
798 delta_ofdm->rxe_frame_limit_overrun,
799 max_ofdm->rxe_frame_limit_overrun);
800 pos += scnprintf(buf + pos, bufsz - pos,
801 fmt_table, "sent_ack_cnt:",
802 le32_to_cpu(ofdm->sent_ack_cnt),
803 accum_ofdm->sent_ack_cnt, delta_ofdm->sent_ack_cnt,
804 max_ofdm->sent_ack_cnt);
805 pos += scnprintf(buf + pos, bufsz - pos,
806 fmt_table, "sent_cts_cnt:",
807 le32_to_cpu(ofdm->sent_cts_cnt),
808 accum_ofdm->sent_cts_cnt, delta_ofdm->sent_cts_cnt,
809 max_ofdm->sent_cts_cnt);
810 pos += scnprintf(buf + pos, bufsz - pos,
811 fmt_table, "sent_ba_rsp_cnt:",
812 le32_to_cpu(ofdm->sent_ba_rsp_cnt),
813 accum_ofdm->sent_ba_rsp_cnt,
814 delta_ofdm->sent_ba_rsp_cnt,
815 max_ofdm->sent_ba_rsp_cnt);
816 pos += scnprintf(buf + pos, bufsz - pos,
817 fmt_table, "dsp_self_kill:",
818 le32_to_cpu(ofdm->dsp_self_kill),
819 accum_ofdm->dsp_self_kill,
820 delta_ofdm->dsp_self_kill,
821 max_ofdm->dsp_self_kill);
822 pos += scnprintf(buf + pos, bufsz - pos,
823 fmt_table, "mh_format_err:",
824 le32_to_cpu(ofdm->mh_format_err),
825 accum_ofdm->mh_format_err,
826 delta_ofdm->mh_format_err,
827 max_ofdm->mh_format_err);
828 pos += scnprintf(buf + pos, bufsz - pos,
829 fmt_table, "re_acq_main_rssi_sum:",
830 le32_to_cpu(ofdm->re_acq_main_rssi_sum),
831 accum_ofdm->re_acq_main_rssi_sum,
832 delta_ofdm->re_acq_main_rssi_sum,
833 max_ofdm->re_acq_main_rssi_sum);
834
835 pos += scnprintf(buf + pos, bufsz - pos,
836 fmt_header, "Statistics_Rx - CCK:");
837 pos += scnprintf(buf + pos, bufsz - pos,
838 fmt_table, "ina_cnt:",
839 le32_to_cpu(cck->ina_cnt), accum_cck->ina_cnt,
840 delta_cck->ina_cnt, max_cck->ina_cnt);
841 pos += scnprintf(buf + pos, bufsz - pos,
842 fmt_table, "fina_cnt:",
843 le32_to_cpu(cck->fina_cnt), accum_cck->fina_cnt,
844 delta_cck->fina_cnt, max_cck->fina_cnt);
845 pos += scnprintf(buf + pos, bufsz - pos,
846 fmt_table, "plcp_err:",
847 le32_to_cpu(cck->plcp_err), accum_cck->plcp_err,
848 delta_cck->plcp_err, max_cck->plcp_err);
849 pos += scnprintf(buf + pos, bufsz - pos,
850 fmt_table, "crc32_err:",
851 le32_to_cpu(cck->crc32_err), accum_cck->crc32_err,
852 delta_cck->crc32_err, max_cck->crc32_err);
853 pos += scnprintf(buf + pos, bufsz - pos,
854 fmt_table, "overrun_err:",
855 le32_to_cpu(cck->overrun_err),
856 accum_cck->overrun_err, delta_cck->overrun_err,
857 max_cck->overrun_err);
858 pos += scnprintf(buf + pos, bufsz - pos,
859 fmt_table, "early_overrun_err:",
860 le32_to_cpu(cck->early_overrun_err),
861 accum_cck->early_overrun_err,
862 delta_cck->early_overrun_err,
863 max_cck->early_overrun_err);
864 pos += scnprintf(buf + pos, bufsz - pos,
865 fmt_table, "crc32_good:",
866 le32_to_cpu(cck->crc32_good), accum_cck->crc32_good,
867 delta_cck->crc32_good, max_cck->crc32_good);
868 pos += scnprintf(buf + pos, bufsz - pos,
869 fmt_table, "false_alarm_cnt:",
870 le32_to_cpu(cck->false_alarm_cnt),
871 accum_cck->false_alarm_cnt,
872 delta_cck->false_alarm_cnt, max_cck->false_alarm_cnt);
873 pos += scnprintf(buf + pos, bufsz - pos,
874 fmt_table, "fina_sync_err_cnt:",
875 le32_to_cpu(cck->fina_sync_err_cnt),
876 accum_cck->fina_sync_err_cnt,
877 delta_cck->fina_sync_err_cnt,
878 max_cck->fina_sync_err_cnt);
879 pos += scnprintf(buf + pos, bufsz - pos,
880 fmt_table, "sfd_timeout:",
881 le32_to_cpu(cck->sfd_timeout),
882 accum_cck->sfd_timeout, delta_cck->sfd_timeout,
883 max_cck->sfd_timeout);
884 pos += scnprintf(buf + pos, bufsz - pos,
885 fmt_table, "fina_timeout:",
886 le32_to_cpu(cck->fina_timeout),
887 accum_cck->fina_timeout, delta_cck->fina_timeout,
888 max_cck->fina_timeout);
889 pos += scnprintf(buf + pos, bufsz - pos,
890 fmt_table, "unresponded_rts:",
891 le32_to_cpu(cck->unresponded_rts),
892 accum_cck->unresponded_rts, delta_cck->unresponded_rts,
893 max_cck->unresponded_rts);
894 pos += scnprintf(buf + pos, bufsz - pos,
895 fmt_table, "rxe_frame_lmt_ovrun:",
896 le32_to_cpu(cck->rxe_frame_limit_overrun),
897 accum_cck->rxe_frame_limit_overrun,
898 delta_cck->rxe_frame_limit_overrun,
899 max_cck->rxe_frame_limit_overrun);
900 pos += scnprintf(buf + pos, bufsz - pos,
901 fmt_table, "sent_ack_cnt:",
902 le32_to_cpu(cck->sent_ack_cnt),
903 accum_cck->sent_ack_cnt, delta_cck->sent_ack_cnt,
904 max_cck->sent_ack_cnt);
905 pos += scnprintf(buf + pos, bufsz - pos,
906 fmt_table, "sent_cts_cnt:",
907 le32_to_cpu(cck->sent_cts_cnt),
908 accum_cck->sent_cts_cnt, delta_cck->sent_cts_cnt,
909 max_cck->sent_cts_cnt);
910 pos += scnprintf(buf + pos, bufsz - pos,
911 fmt_table, "sent_ba_rsp_cnt:",
912 le32_to_cpu(cck->sent_ba_rsp_cnt),
913 accum_cck->sent_ba_rsp_cnt,
914 delta_cck->sent_ba_rsp_cnt,
915 max_cck->sent_ba_rsp_cnt);
916 pos += scnprintf(buf + pos, bufsz - pos,
917 fmt_table, "dsp_self_kill:",
918 le32_to_cpu(cck->dsp_self_kill),
919 accum_cck->dsp_self_kill, delta_cck->dsp_self_kill,
920 max_cck->dsp_self_kill);
921 pos += scnprintf(buf + pos, bufsz - pos,
922 fmt_table, "mh_format_err:",
923 le32_to_cpu(cck->mh_format_err),
924 accum_cck->mh_format_err, delta_cck->mh_format_err,
925 max_cck->mh_format_err);
926 pos += scnprintf(buf + pos, bufsz - pos,
927 fmt_table, "re_acq_main_rssi_sum:",
928 le32_to_cpu(cck->re_acq_main_rssi_sum),
929 accum_cck->re_acq_main_rssi_sum,
930 delta_cck->re_acq_main_rssi_sum,
931 max_cck->re_acq_main_rssi_sum);
932
933 pos += scnprintf(buf + pos, bufsz - pos,
934 fmt_header, "Statistics_Rx - GENERAL:");
935 pos += scnprintf(buf + pos, bufsz - pos,
936 fmt_table, "bogus_cts:",
937 le32_to_cpu(general->bogus_cts),
938 accum_general->bogus_cts, delta_general->bogus_cts,
939 max_general->bogus_cts);
940 pos += scnprintf(buf + pos, bufsz - pos,
941 fmt_table, "bogus_ack:",
942 le32_to_cpu(general->bogus_ack),
943 accum_general->bogus_ack, delta_general->bogus_ack,
944 max_general->bogus_ack);
945 pos += scnprintf(buf + pos, bufsz - pos,
946 fmt_table, "non_bssid_frames:",
947 le32_to_cpu(general->non_bssid_frames),
948 accum_general->non_bssid_frames,
949 delta_general->non_bssid_frames,
950 max_general->non_bssid_frames);
951 pos += scnprintf(buf + pos, bufsz - pos,
952 fmt_table, "filtered_frames:",
953 le32_to_cpu(general->filtered_frames),
954 accum_general->filtered_frames,
955 delta_general->filtered_frames,
956 max_general->filtered_frames);
957 pos += scnprintf(buf + pos, bufsz - pos,
958 fmt_table, "non_channel_beacons:",
959 le32_to_cpu(general->non_channel_beacons),
960 accum_general->non_channel_beacons,
961 delta_general->non_channel_beacons,
962 max_general->non_channel_beacons);
963 pos += scnprintf(buf + pos, bufsz - pos,
964 fmt_table, "channel_beacons:",
965 le32_to_cpu(general->channel_beacons),
966 accum_general->channel_beacons,
967 delta_general->channel_beacons,
968 max_general->channel_beacons);
969 pos += scnprintf(buf + pos, bufsz - pos,
970 fmt_table, "num_missed_bcon:",
971 le32_to_cpu(general->num_missed_bcon),
972 accum_general->num_missed_bcon,
973 delta_general->num_missed_bcon,
974 max_general->num_missed_bcon);
975 pos += scnprintf(buf + pos, bufsz - pos,
976 fmt_table, "adc_rx_saturation_time:",
977 le32_to_cpu(general->adc_rx_saturation_time),
978 accum_general->adc_rx_saturation_time,
979 delta_general->adc_rx_saturation_time,
980 max_general->adc_rx_saturation_time);
981 pos += scnprintf(buf + pos, bufsz - pos,
982 fmt_table, "ina_detect_search_tm:",
983 le32_to_cpu(general->ina_detection_search_time),
984 accum_general->ina_detection_search_time,
985 delta_general->ina_detection_search_time,
986 max_general->ina_detection_search_time);
987 pos += scnprintf(buf + pos, bufsz - pos,
988 fmt_table, "beacon_silence_rssi_a:",
989 le32_to_cpu(general->beacon_silence_rssi_a),
990 accum_general->beacon_silence_rssi_a,
991 delta_general->beacon_silence_rssi_a,
992 max_general->beacon_silence_rssi_a);
993 pos += scnprintf(buf + pos, bufsz - pos,
994 fmt_table, "beacon_silence_rssi_b:",
995 le32_to_cpu(general->beacon_silence_rssi_b),
996 accum_general->beacon_silence_rssi_b,
997 delta_general->beacon_silence_rssi_b,
998 max_general->beacon_silence_rssi_b);
999 pos += scnprintf(buf + pos, bufsz - pos,
1000 fmt_table, "beacon_silence_rssi_c:",
1001 le32_to_cpu(general->beacon_silence_rssi_c),
1002 accum_general->beacon_silence_rssi_c,
1003 delta_general->beacon_silence_rssi_c,
1004 max_general->beacon_silence_rssi_c);
1005 pos += scnprintf(buf + pos, bufsz - pos,
1006 fmt_table, "interference_data_flag:",
1007 le32_to_cpu(general->interference_data_flag),
1008 accum_general->interference_data_flag,
1009 delta_general->interference_data_flag,
1010 max_general->interference_data_flag);
1011 pos += scnprintf(buf + pos, bufsz - pos,
1012 fmt_table, "channel_load:",
1013 le32_to_cpu(general->channel_load),
1014 accum_general->channel_load,
1015 delta_general->channel_load,
1016 max_general->channel_load);
1017 pos += scnprintf(buf + pos, bufsz - pos,
1018 fmt_table, "dsp_false_alarms:",
1019 le32_to_cpu(general->dsp_false_alarms),
1020 accum_general->dsp_false_alarms,
1021 delta_general->dsp_false_alarms,
1022 max_general->dsp_false_alarms);
1023 pos += scnprintf(buf + pos, bufsz - pos,
1024 fmt_table, "beacon_rssi_a:",
1025 le32_to_cpu(general->beacon_rssi_a),
1026 accum_general->beacon_rssi_a,
1027 delta_general->beacon_rssi_a,
1028 max_general->beacon_rssi_a);
1029 pos += scnprintf(buf + pos, bufsz - pos,
1030 fmt_table, "beacon_rssi_b:",
1031 le32_to_cpu(general->beacon_rssi_b),
1032 accum_general->beacon_rssi_b,
1033 delta_general->beacon_rssi_b,
1034 max_general->beacon_rssi_b);
1035 pos += scnprintf(buf + pos, bufsz - pos,
1036 fmt_table, "beacon_rssi_c:",
1037 le32_to_cpu(general->beacon_rssi_c),
1038 accum_general->beacon_rssi_c,
1039 delta_general->beacon_rssi_c,
1040 max_general->beacon_rssi_c);
1041 pos += scnprintf(buf + pos, bufsz - pos,
1042 fmt_table, "beacon_energy_a:",
1043 le32_to_cpu(general->beacon_energy_a),
1044 accum_general->beacon_energy_a,
1045 delta_general->beacon_energy_a,
1046 max_general->beacon_energy_a);
1047 pos += scnprintf(buf + pos, bufsz - pos,
1048 fmt_table, "beacon_energy_b:",
1049 le32_to_cpu(general->beacon_energy_b),
1050 accum_general->beacon_energy_b,
1051 delta_general->beacon_energy_b,
1052 max_general->beacon_energy_b);
1053 pos += scnprintf(buf + pos, bufsz - pos,
1054 fmt_table, "beacon_energy_c:",
1055 le32_to_cpu(general->beacon_energy_c),
1056 accum_general->beacon_energy_c,
1057 delta_general->beacon_energy_c,
1058 max_general->beacon_energy_c);
1059
1060 pos += scnprintf(buf + pos, bufsz - pos,
1061 fmt_header, "Statistics_Rx - OFDM_HT:");
1062 pos += scnprintf(buf + pos, bufsz - pos,
1063 fmt_table, "plcp_err:",
1064 le32_to_cpu(ht->plcp_err), accum_ht->plcp_err,
1065 delta_ht->plcp_err, max_ht->plcp_err);
1066 pos += scnprintf(buf + pos, bufsz - pos,
1067 fmt_table, "overrun_err:",
1068 le32_to_cpu(ht->overrun_err), accum_ht->overrun_err,
1069 delta_ht->overrun_err, max_ht->overrun_err);
1070 pos += scnprintf(buf + pos, bufsz - pos,
1071 fmt_table, "early_overrun_err:",
1072 le32_to_cpu(ht->early_overrun_err),
1073 accum_ht->early_overrun_err,
1074 delta_ht->early_overrun_err,
1075 max_ht->early_overrun_err);
1076 pos += scnprintf(buf + pos, bufsz - pos,
1077 fmt_table, "crc32_good:",
1078 le32_to_cpu(ht->crc32_good), accum_ht->crc32_good,
1079 delta_ht->crc32_good, max_ht->crc32_good);
1080 pos += scnprintf(buf + pos, bufsz - pos,
1081 fmt_table, "crc32_err:",
1082 le32_to_cpu(ht->crc32_err), accum_ht->crc32_err,
1083 delta_ht->crc32_err, max_ht->crc32_err);
1084 pos += scnprintf(buf + pos, bufsz - pos,
1085 fmt_table, "mh_format_err:",
1086 le32_to_cpu(ht->mh_format_err),
1087 accum_ht->mh_format_err,
1088 delta_ht->mh_format_err, max_ht->mh_format_err);
1089 pos += scnprintf(buf + pos, bufsz - pos,
1090 fmt_table, "agg_crc32_good:",
1091 le32_to_cpu(ht->agg_crc32_good),
1092 accum_ht->agg_crc32_good,
1093 delta_ht->agg_crc32_good, max_ht->agg_crc32_good);
1094 pos += scnprintf(buf + pos, bufsz - pos,
1095 fmt_table, "agg_mpdu_cnt:",
1096 le32_to_cpu(ht->agg_mpdu_cnt),
1097 accum_ht->agg_mpdu_cnt,
1098 delta_ht->agg_mpdu_cnt, max_ht->agg_mpdu_cnt);
1099 pos += scnprintf(buf + pos, bufsz - pos,
1100 fmt_table, "agg_cnt:",
1101 le32_to_cpu(ht->agg_cnt), accum_ht->agg_cnt,
1102 delta_ht->agg_cnt, max_ht->agg_cnt);
1103 pos += scnprintf(buf + pos, bufsz - pos,
1104 fmt_table, "unsupport_mcs:",
1105 le32_to_cpu(ht->unsupport_mcs),
1106 accum_ht->unsupport_mcs,
1107 delta_ht->unsupport_mcs, max_ht->unsupport_mcs);
1108
1109 spin_unlock_bh(&priv->statistics.lock);
1110
1111 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1112 kfree(buf);
1113 return ret;
1114}
1115
1116static ssize_t iwl_dbgfs_ucode_tx_stats_read(struct file *file,
1117 char __user *user_buf,
1118 size_t count, loff_t *ppos)
1119{
1120 struct iwl_priv *priv = file->private_data;
1121 int pos = 0;
1122 char *buf;
1123 int bufsz = (sizeof(struct statistics_tx) * 48) + 250;
1124 ssize_t ret;
1125 struct statistics_tx *tx, *accum_tx, *delta_tx, *max_tx;
1126
1127 if (!iwl_is_alive(priv))
1128 return -EAGAIN;
1129
1130 buf = kzalloc(bufsz, GFP_KERNEL);
1131 if (!buf)
1132 return -ENOMEM;
1133
1134
1135
1136
1137
1138 spin_lock_bh(&priv->statistics.lock);
1139
1140 tx = &priv->statistics.tx;
1141 accum_tx = &priv->accum_stats.tx;
1142 delta_tx = &priv->delta_stats.tx;
1143 max_tx = &priv->max_delta_stats.tx;
1144
1145 pos += iwl_statistics_flag(priv, buf, bufsz);
1146 pos += scnprintf(buf + pos, bufsz - pos,
1147 fmt_header, "Statistics_Tx:");
1148 pos += scnprintf(buf + pos, bufsz - pos,
1149 fmt_table, "preamble:",
1150 le32_to_cpu(tx->preamble_cnt),
1151 accum_tx->preamble_cnt,
1152 delta_tx->preamble_cnt, max_tx->preamble_cnt);
1153 pos += scnprintf(buf + pos, bufsz - pos,
1154 fmt_table, "rx_detected_cnt:",
1155 le32_to_cpu(tx->rx_detected_cnt),
1156 accum_tx->rx_detected_cnt,
1157 delta_tx->rx_detected_cnt, max_tx->rx_detected_cnt);
1158 pos += scnprintf(buf + pos, bufsz - pos,
1159 fmt_table, "bt_prio_defer_cnt:",
1160 le32_to_cpu(tx->bt_prio_defer_cnt),
1161 accum_tx->bt_prio_defer_cnt,
1162 delta_tx->bt_prio_defer_cnt,
1163 max_tx->bt_prio_defer_cnt);
1164 pos += scnprintf(buf + pos, bufsz - pos,
1165 fmt_table, "bt_prio_kill_cnt:",
1166 le32_to_cpu(tx->bt_prio_kill_cnt),
1167 accum_tx->bt_prio_kill_cnt,
1168 delta_tx->bt_prio_kill_cnt,
1169 max_tx->bt_prio_kill_cnt);
1170 pos += scnprintf(buf + pos, bufsz - pos,
1171 fmt_table, "few_bytes_cnt:",
1172 le32_to_cpu(tx->few_bytes_cnt),
1173 accum_tx->few_bytes_cnt,
1174 delta_tx->few_bytes_cnt, max_tx->few_bytes_cnt);
1175 pos += scnprintf(buf + pos, bufsz - pos,
1176 fmt_table, "cts_timeout:",
1177 le32_to_cpu(tx->cts_timeout), accum_tx->cts_timeout,
1178 delta_tx->cts_timeout, max_tx->cts_timeout);
1179 pos += scnprintf(buf + pos, bufsz - pos,
1180 fmt_table, "ack_timeout:",
1181 le32_to_cpu(tx->ack_timeout),
1182 accum_tx->ack_timeout,
1183 delta_tx->ack_timeout, max_tx->ack_timeout);
1184 pos += scnprintf(buf + pos, bufsz - pos,
1185 fmt_table, "expected_ack_cnt:",
1186 le32_to_cpu(tx->expected_ack_cnt),
1187 accum_tx->expected_ack_cnt,
1188 delta_tx->expected_ack_cnt,
1189 max_tx->expected_ack_cnt);
1190 pos += scnprintf(buf + pos, bufsz - pos,
1191 fmt_table, "actual_ack_cnt:",
1192 le32_to_cpu(tx->actual_ack_cnt),
1193 accum_tx->actual_ack_cnt,
1194 delta_tx->actual_ack_cnt,
1195 max_tx->actual_ack_cnt);
1196 pos += scnprintf(buf + pos, bufsz - pos,
1197 fmt_table, "dump_msdu_cnt:",
1198 le32_to_cpu(tx->dump_msdu_cnt),
1199 accum_tx->dump_msdu_cnt,
1200 delta_tx->dump_msdu_cnt,
1201 max_tx->dump_msdu_cnt);
1202 pos += scnprintf(buf + pos, bufsz - pos,
1203 fmt_table, "abort_nxt_frame_mismatch:",
1204 le32_to_cpu(tx->burst_abort_next_frame_mismatch_cnt),
1205 accum_tx->burst_abort_next_frame_mismatch_cnt,
1206 delta_tx->burst_abort_next_frame_mismatch_cnt,
1207 max_tx->burst_abort_next_frame_mismatch_cnt);
1208 pos += scnprintf(buf + pos, bufsz - pos,
1209 fmt_table, "abort_missing_nxt_frame:",
1210 le32_to_cpu(tx->burst_abort_missing_next_frame_cnt),
1211 accum_tx->burst_abort_missing_next_frame_cnt,
1212 delta_tx->burst_abort_missing_next_frame_cnt,
1213 max_tx->burst_abort_missing_next_frame_cnt);
1214 pos += scnprintf(buf + pos, bufsz - pos,
1215 fmt_table, "cts_timeout_collision:",
1216 le32_to_cpu(tx->cts_timeout_collision),
1217 accum_tx->cts_timeout_collision,
1218 delta_tx->cts_timeout_collision,
1219 max_tx->cts_timeout_collision);
1220 pos += scnprintf(buf + pos, bufsz - pos,
1221 fmt_table, "ack_ba_timeout_collision:",
1222 le32_to_cpu(tx->ack_or_ba_timeout_collision),
1223 accum_tx->ack_or_ba_timeout_collision,
1224 delta_tx->ack_or_ba_timeout_collision,
1225 max_tx->ack_or_ba_timeout_collision);
1226 pos += scnprintf(buf + pos, bufsz - pos,
1227 fmt_table, "agg ba_timeout:",
1228 le32_to_cpu(tx->agg.ba_timeout),
1229 accum_tx->agg.ba_timeout,
1230 delta_tx->agg.ba_timeout,
1231 max_tx->agg.ba_timeout);
1232 pos += scnprintf(buf + pos, bufsz - pos,
1233 fmt_table, "agg ba_resched_frames:",
1234 le32_to_cpu(tx->agg.ba_reschedule_frames),
1235 accum_tx->agg.ba_reschedule_frames,
1236 delta_tx->agg.ba_reschedule_frames,
1237 max_tx->agg.ba_reschedule_frames);
1238 pos += scnprintf(buf + pos, bufsz - pos,
1239 fmt_table, "agg scd_query_agg_frame:",
1240 le32_to_cpu(tx->agg.scd_query_agg_frame_cnt),
1241 accum_tx->agg.scd_query_agg_frame_cnt,
1242 delta_tx->agg.scd_query_agg_frame_cnt,
1243 max_tx->agg.scd_query_agg_frame_cnt);
1244 pos += scnprintf(buf + pos, bufsz - pos,
1245 fmt_table, "agg scd_query_no_agg:",
1246 le32_to_cpu(tx->agg.scd_query_no_agg),
1247 accum_tx->agg.scd_query_no_agg,
1248 delta_tx->agg.scd_query_no_agg,
1249 max_tx->agg.scd_query_no_agg);
1250 pos += scnprintf(buf + pos, bufsz - pos,
1251 fmt_table, "agg scd_query_agg:",
1252 le32_to_cpu(tx->agg.scd_query_agg),
1253 accum_tx->agg.scd_query_agg,
1254 delta_tx->agg.scd_query_agg,
1255 max_tx->agg.scd_query_agg);
1256 pos += scnprintf(buf + pos, bufsz - pos,
1257 fmt_table, "agg scd_query_mismatch:",
1258 le32_to_cpu(tx->agg.scd_query_mismatch),
1259 accum_tx->agg.scd_query_mismatch,
1260 delta_tx->agg.scd_query_mismatch,
1261 max_tx->agg.scd_query_mismatch);
1262 pos += scnprintf(buf + pos, bufsz - pos,
1263 fmt_table, "agg frame_not_ready:",
1264 le32_to_cpu(tx->agg.frame_not_ready),
1265 accum_tx->agg.frame_not_ready,
1266 delta_tx->agg.frame_not_ready,
1267 max_tx->agg.frame_not_ready);
1268 pos += scnprintf(buf + pos, bufsz - pos,
1269 fmt_table, "agg underrun:",
1270 le32_to_cpu(tx->agg.underrun),
1271 accum_tx->agg.underrun,
1272 delta_tx->agg.underrun, max_tx->agg.underrun);
1273 pos += scnprintf(buf + pos, bufsz - pos,
1274 fmt_table, "agg bt_prio_kill:",
1275 le32_to_cpu(tx->agg.bt_prio_kill),
1276 accum_tx->agg.bt_prio_kill,
1277 delta_tx->agg.bt_prio_kill,
1278 max_tx->agg.bt_prio_kill);
1279 pos += scnprintf(buf + pos, bufsz - pos,
1280 fmt_table, "agg rx_ba_rsp_cnt:",
1281 le32_to_cpu(tx->agg.rx_ba_rsp_cnt),
1282 accum_tx->agg.rx_ba_rsp_cnt,
1283 delta_tx->agg.rx_ba_rsp_cnt,
1284 max_tx->agg.rx_ba_rsp_cnt);
1285
1286 if (tx->tx_power.ant_a || tx->tx_power.ant_b || tx->tx_power.ant_c) {
1287 pos += scnprintf(buf + pos, bufsz - pos,
1288 "tx power: (1/2 dB step)\n");
1289 if ((priv->nvm_data->valid_tx_ant & ANT_A) &&
1290 tx->tx_power.ant_a)
1291 pos += scnprintf(buf + pos, bufsz - pos,
1292 fmt_hex, "antenna A:",
1293 tx->tx_power.ant_a);
1294 if ((priv->nvm_data->valid_tx_ant & ANT_B) &&
1295 tx->tx_power.ant_b)
1296 pos += scnprintf(buf + pos, bufsz - pos,
1297 fmt_hex, "antenna B:",
1298 tx->tx_power.ant_b);
1299 if ((priv->nvm_data->valid_tx_ant & ANT_C) &&
1300 tx->tx_power.ant_c)
1301 pos += scnprintf(buf + pos, bufsz - pos,
1302 fmt_hex, "antenna C:",
1303 tx->tx_power.ant_c);
1304 }
1305
1306 spin_unlock_bh(&priv->statistics.lock);
1307
1308 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1309 kfree(buf);
1310 return ret;
1311}
1312
1313static ssize_t iwl_dbgfs_ucode_general_stats_read(struct file *file,
1314 char __user *user_buf,
1315 size_t count, loff_t *ppos)
1316{
1317 struct iwl_priv *priv = file->private_data;
1318 int pos = 0;
1319 char *buf;
1320 int bufsz = sizeof(struct statistics_general) * 10 + 300;
1321 ssize_t ret;
1322 struct statistics_general_common *general, *accum_general;
1323 struct statistics_general_common *delta_general, *max_general;
1324 struct statistics_dbg *dbg, *accum_dbg, *delta_dbg, *max_dbg;
1325 struct statistics_div *div, *accum_div, *delta_div, *max_div;
1326
1327 if (!iwl_is_alive(priv))
1328 return -EAGAIN;
1329
1330 buf = kzalloc(bufsz, GFP_KERNEL);
1331 if (!buf)
1332 return -ENOMEM;
1333
1334
1335
1336
1337
1338
1339 spin_lock_bh(&priv->statistics.lock);
1340
1341 general = &priv->statistics.common;
1342 dbg = &priv->statistics.common.dbg;
1343 div = &priv->statistics.common.div;
1344 accum_general = &priv->accum_stats.common;
1345 accum_dbg = &priv->accum_stats.common.dbg;
1346 accum_div = &priv->accum_stats.common.div;
1347 delta_general = &priv->delta_stats.common;
1348 max_general = &priv->max_delta_stats.common;
1349 delta_dbg = &priv->delta_stats.common.dbg;
1350 max_dbg = &priv->max_delta_stats.common.dbg;
1351 delta_div = &priv->delta_stats.common.div;
1352 max_div = &priv->max_delta_stats.common.div;
1353
1354 pos += iwl_statistics_flag(priv, buf, bufsz);
1355 pos += scnprintf(buf + pos, bufsz - pos,
1356 fmt_header, "Statistics_General:");
1357 pos += scnprintf(buf + pos, bufsz - pos,
1358 fmt_value, "temperature:",
1359 le32_to_cpu(general->temperature));
1360 pos += scnprintf(buf + pos, bufsz - pos,
1361 fmt_value, "temperature_m:",
1362 le32_to_cpu(general->temperature_m));
1363 pos += scnprintf(buf + pos, bufsz - pos,
1364 fmt_value, "ttl_timestamp:",
1365 le32_to_cpu(general->ttl_timestamp));
1366 pos += scnprintf(buf + pos, bufsz - pos,
1367 fmt_table, "burst_check:",
1368 le32_to_cpu(dbg->burst_check),
1369 accum_dbg->burst_check,
1370 delta_dbg->burst_check, max_dbg->burst_check);
1371 pos += scnprintf(buf + pos, bufsz - pos,
1372 fmt_table, "burst_count:",
1373 le32_to_cpu(dbg->burst_count),
1374 accum_dbg->burst_count,
1375 delta_dbg->burst_count, max_dbg->burst_count);
1376 pos += scnprintf(buf + pos, bufsz - pos,
1377 fmt_table, "wait_for_silence_timeout_count:",
1378 le32_to_cpu(dbg->wait_for_silence_timeout_cnt),
1379 accum_dbg->wait_for_silence_timeout_cnt,
1380 delta_dbg->wait_for_silence_timeout_cnt,
1381 max_dbg->wait_for_silence_timeout_cnt);
1382 pos += scnprintf(buf + pos, bufsz - pos,
1383 fmt_table, "sleep_time:",
1384 le32_to_cpu(general->sleep_time),
1385 accum_general->sleep_time,
1386 delta_general->sleep_time, max_general->sleep_time);
1387 pos += scnprintf(buf + pos, bufsz - pos,
1388 fmt_table, "slots_out:",
1389 le32_to_cpu(general->slots_out),
1390 accum_general->slots_out,
1391 delta_general->slots_out, max_general->slots_out);
1392 pos += scnprintf(buf + pos, bufsz - pos,
1393 fmt_table, "slots_idle:",
1394 le32_to_cpu(general->slots_idle),
1395 accum_general->slots_idle,
1396 delta_general->slots_idle, max_general->slots_idle);
1397 pos += scnprintf(buf + pos, bufsz - pos,
1398 fmt_table, "tx_on_a:",
1399 le32_to_cpu(div->tx_on_a), accum_div->tx_on_a,
1400 delta_div->tx_on_a, max_div->tx_on_a);
1401 pos += scnprintf(buf + pos, bufsz - pos,
1402 fmt_table, "tx_on_b:",
1403 le32_to_cpu(div->tx_on_b), accum_div->tx_on_b,
1404 delta_div->tx_on_b, max_div->tx_on_b);
1405 pos += scnprintf(buf + pos, bufsz - pos,
1406 fmt_table, "exec_time:",
1407 le32_to_cpu(div->exec_time), accum_div->exec_time,
1408 delta_div->exec_time, max_div->exec_time);
1409 pos += scnprintf(buf + pos, bufsz - pos,
1410 fmt_table, "probe_time:",
1411 le32_to_cpu(div->probe_time), accum_div->probe_time,
1412 delta_div->probe_time, max_div->probe_time);
1413 pos += scnprintf(buf + pos, bufsz - pos,
1414 fmt_table, "rx_enable_counter:",
1415 le32_to_cpu(general->rx_enable_counter),
1416 accum_general->rx_enable_counter,
1417 delta_general->rx_enable_counter,
1418 max_general->rx_enable_counter);
1419 pos += scnprintf(buf + pos, bufsz - pos,
1420 fmt_table, "num_of_sos_states:",
1421 le32_to_cpu(general->num_of_sos_states),
1422 accum_general->num_of_sos_states,
1423 delta_general->num_of_sos_states,
1424 max_general->num_of_sos_states);
1425
1426 spin_unlock_bh(&priv->statistics.lock);
1427
1428 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1429 kfree(buf);
1430 return ret;
1431}
1432
1433static ssize_t iwl_dbgfs_ucode_bt_stats_read(struct file *file,
1434 char __user *user_buf,
1435 size_t count, loff_t *ppos)
1436{
1437 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1438 int pos = 0;
1439 char *buf;
1440 int bufsz = (sizeof(struct statistics_bt_activity) * 24) + 200;
1441 ssize_t ret;
1442 struct statistics_bt_activity *bt, *accum_bt;
1443
1444 if (!iwl_is_alive(priv))
1445 return -EAGAIN;
1446
1447 if (!priv->bt_enable_flag)
1448 return -EINVAL;
1449
1450
1451 mutex_lock(&priv->mutex);
1452 ret = iwl_send_statistics_request(priv, 0, false);
1453 mutex_unlock(&priv->mutex);
1454
1455 if (ret)
1456 return -EAGAIN;
1457 buf = kzalloc(bufsz, GFP_KERNEL);
1458 if (!buf)
1459 return -ENOMEM;
1460
1461
1462
1463
1464
1465
1466
1467 spin_lock_bh(&priv->statistics.lock);
1468
1469 bt = &priv->statistics.bt_activity;
1470 accum_bt = &priv->accum_stats.bt_activity;
1471
1472 pos += iwl_statistics_flag(priv, buf, bufsz);
1473 pos += scnprintf(buf + pos, bufsz - pos, "Statistics_BT:\n");
1474 pos += scnprintf(buf + pos, bufsz - pos,
1475 "\t\t\tcurrent\t\t\taccumulative\n");
1476 pos += scnprintf(buf + pos, bufsz - pos,
1477 "hi_priority_tx_req_cnt:\t\t%u\t\t\t%u\n",
1478 le32_to_cpu(bt->hi_priority_tx_req_cnt),
1479 accum_bt->hi_priority_tx_req_cnt);
1480 pos += scnprintf(buf + pos, bufsz - pos,
1481 "hi_priority_tx_denied_cnt:\t%u\t\t\t%u\n",
1482 le32_to_cpu(bt->hi_priority_tx_denied_cnt),
1483 accum_bt->hi_priority_tx_denied_cnt);
1484 pos += scnprintf(buf + pos, bufsz - pos,
1485 "lo_priority_tx_req_cnt:\t\t%u\t\t\t%u\n",
1486 le32_to_cpu(bt->lo_priority_tx_req_cnt),
1487 accum_bt->lo_priority_tx_req_cnt);
1488 pos += scnprintf(buf + pos, bufsz - pos,
1489 "lo_priority_tx_denied_cnt:\t%u\t\t\t%u\n",
1490 le32_to_cpu(bt->lo_priority_tx_denied_cnt),
1491 accum_bt->lo_priority_tx_denied_cnt);
1492 pos += scnprintf(buf + pos, bufsz - pos,
1493 "hi_priority_rx_req_cnt:\t\t%u\t\t\t%u\n",
1494 le32_to_cpu(bt->hi_priority_rx_req_cnt),
1495 accum_bt->hi_priority_rx_req_cnt);
1496 pos += scnprintf(buf + pos, bufsz - pos,
1497 "hi_priority_rx_denied_cnt:\t%u\t\t\t%u\n",
1498 le32_to_cpu(bt->hi_priority_rx_denied_cnt),
1499 accum_bt->hi_priority_rx_denied_cnt);
1500 pos += scnprintf(buf + pos, bufsz - pos,
1501 "lo_priority_rx_req_cnt:\t\t%u\t\t\t%u\n",
1502 le32_to_cpu(bt->lo_priority_rx_req_cnt),
1503 accum_bt->lo_priority_rx_req_cnt);
1504 pos += scnprintf(buf + pos, bufsz - pos,
1505 "lo_priority_rx_denied_cnt:\t%u\t\t\t%u\n",
1506 le32_to_cpu(bt->lo_priority_rx_denied_cnt),
1507 accum_bt->lo_priority_rx_denied_cnt);
1508
1509 pos += scnprintf(buf + pos, bufsz - pos,
1510 "(rx)num_bt_kills:\t\t%u\t\t\t%u\n",
1511 le32_to_cpu(priv->statistics.num_bt_kills),
1512 priv->statistics.accum_num_bt_kills);
1513
1514 spin_unlock_bh(&priv->statistics.lock);
1515
1516 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1517 kfree(buf);
1518 return ret;
1519}
1520
1521static ssize_t iwl_dbgfs_reply_tx_error_read(struct file *file,
1522 char __user *user_buf,
1523 size_t count, loff_t *ppos)
1524{
1525 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1526 int pos = 0;
1527 char *buf;
1528 int bufsz = (sizeof(struct reply_tx_error_statistics) * 24) +
1529 (sizeof(struct reply_agg_tx_error_statistics) * 24) + 200;
1530 ssize_t ret;
1531
1532 if (!iwl_is_alive(priv))
1533 return -EAGAIN;
1534
1535 buf = kzalloc(bufsz, GFP_KERNEL);
1536 if (!buf)
1537 return -ENOMEM;
1538
1539 pos += scnprintf(buf + pos, bufsz - pos, "Statistics_TX_Error:\n");
1540 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t\t%u\n",
1541 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_DELAY),
1542 priv->reply_tx_stats.pp_delay);
1543 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1544 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_FEW_BYTES),
1545 priv->reply_tx_stats.pp_few_bytes);
1546 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1547 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_BT_PRIO),
1548 priv->reply_tx_stats.pp_bt_prio);
1549 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1550 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_QUIET_PERIOD),
1551 priv->reply_tx_stats.pp_quiet_period);
1552 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1553 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_CALC_TTAK),
1554 priv->reply_tx_stats.pp_calc_ttak);
1555 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1556 iwl_get_tx_fail_reason(
1557 TX_STATUS_FAIL_INTERNAL_CROSSED_RETRY),
1558 priv->reply_tx_stats.int_crossed_retry);
1559 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1560 iwl_get_tx_fail_reason(TX_STATUS_FAIL_SHORT_LIMIT),
1561 priv->reply_tx_stats.short_limit);
1562 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1563 iwl_get_tx_fail_reason(TX_STATUS_FAIL_LONG_LIMIT),
1564 priv->reply_tx_stats.long_limit);
1565 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1566 iwl_get_tx_fail_reason(TX_STATUS_FAIL_FIFO_UNDERRUN),
1567 priv->reply_tx_stats.fifo_underrun);
1568 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1569 iwl_get_tx_fail_reason(TX_STATUS_FAIL_DRAIN_FLOW),
1570 priv->reply_tx_stats.drain_flow);
1571 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1572 iwl_get_tx_fail_reason(TX_STATUS_FAIL_RFKILL_FLUSH),
1573 priv->reply_tx_stats.rfkill_flush);
1574 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1575 iwl_get_tx_fail_reason(TX_STATUS_FAIL_LIFE_EXPIRE),
1576 priv->reply_tx_stats.life_expire);
1577 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1578 iwl_get_tx_fail_reason(TX_STATUS_FAIL_DEST_PS),
1579 priv->reply_tx_stats.dest_ps);
1580 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1581 iwl_get_tx_fail_reason(TX_STATUS_FAIL_HOST_ABORTED),
1582 priv->reply_tx_stats.host_abort);
1583 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1584 iwl_get_tx_fail_reason(TX_STATUS_FAIL_BT_RETRY),
1585 priv->reply_tx_stats.pp_delay);
1586 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1587 iwl_get_tx_fail_reason(TX_STATUS_FAIL_STA_INVALID),
1588 priv->reply_tx_stats.sta_invalid);
1589 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1590 iwl_get_tx_fail_reason(TX_STATUS_FAIL_FRAG_DROPPED),
1591 priv->reply_tx_stats.frag_drop);
1592 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1593 iwl_get_tx_fail_reason(TX_STATUS_FAIL_TID_DISABLE),
1594 priv->reply_tx_stats.tid_disable);
1595 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1596 iwl_get_tx_fail_reason(TX_STATUS_FAIL_FIFO_FLUSHED),
1597 priv->reply_tx_stats.fifo_flush);
1598 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1599 iwl_get_tx_fail_reason(
1600 TX_STATUS_FAIL_INSUFFICIENT_CF_POLL),
1601 priv->reply_tx_stats.insuff_cf_poll);
1602 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1603 iwl_get_tx_fail_reason(TX_STATUS_FAIL_PASSIVE_NO_RX),
1604 priv->reply_tx_stats.fail_hw_drop);
1605 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1606 iwl_get_tx_fail_reason(
1607 TX_STATUS_FAIL_NO_BEACON_ON_RADAR),
1608 priv->reply_tx_stats.sta_color_mismatch);
1609 pos += scnprintf(buf + pos, bufsz - pos, "UNKNOWN:\t\t\t%u\n",
1610 priv->reply_tx_stats.unknown);
1611
1612 pos += scnprintf(buf + pos, bufsz - pos,
1613 "\nStatistics_Agg_TX_Error:\n");
1614
1615 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1616 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_UNDERRUN_MSK),
1617 priv->reply_agg_tx_stats.underrun);
1618 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1619 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_BT_PRIO_MSK),
1620 priv->reply_agg_tx_stats.bt_prio);
1621 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1622 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_FEW_BYTES_MSK),
1623 priv->reply_agg_tx_stats.few_bytes);
1624 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1625 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_ABORT_MSK),
1626 priv->reply_agg_tx_stats.abort);
1627 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1628 iwl_get_agg_tx_fail_reason(
1629 AGG_TX_STATE_LAST_SENT_TTL_MSK),
1630 priv->reply_agg_tx_stats.last_sent_ttl);
1631 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1632 iwl_get_agg_tx_fail_reason(
1633 AGG_TX_STATE_LAST_SENT_TRY_CNT_MSK),
1634 priv->reply_agg_tx_stats.last_sent_try);
1635 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1636 iwl_get_agg_tx_fail_reason(
1637 AGG_TX_STATE_LAST_SENT_BT_KILL_MSK),
1638 priv->reply_agg_tx_stats.last_sent_bt_kill);
1639 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1640 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_SCD_QUERY_MSK),
1641 priv->reply_agg_tx_stats.scd_query);
1642 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1643 iwl_get_agg_tx_fail_reason(
1644 AGG_TX_STATE_TEST_BAD_CRC32_MSK),
1645 priv->reply_agg_tx_stats.bad_crc32);
1646 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1647 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_RESPONSE_MSK),
1648 priv->reply_agg_tx_stats.response);
1649 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1650 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_DUMP_TX_MSK),
1651 priv->reply_agg_tx_stats.dump_tx);
1652 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1653 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_DELAY_TX_MSK),
1654 priv->reply_agg_tx_stats.delay_tx);
1655 pos += scnprintf(buf + pos, bufsz - pos, "UNKNOWN:\t\t\t%u\n",
1656 priv->reply_agg_tx_stats.unknown);
1657
1658 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1659 kfree(buf);
1660 return ret;
1661}
1662
1663static ssize_t iwl_dbgfs_sensitivity_read(struct file *file,
1664 char __user *user_buf,
1665 size_t count, loff_t *ppos) {
1666
1667 struct iwl_priv *priv = file->private_data;
1668 int pos = 0;
1669 int cnt = 0;
1670 char *buf;
1671 int bufsz = sizeof(struct iwl_sensitivity_data) * 4 + 100;
1672 ssize_t ret;
1673 struct iwl_sensitivity_data *data;
1674
1675 data = &priv->sensitivity_data;
1676 buf = kzalloc(bufsz, GFP_KERNEL);
1677 if (!buf)
1678 return -ENOMEM;
1679
1680 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm:\t\t\t %u\n",
1681 data->auto_corr_ofdm);
1682 pos += scnprintf(buf + pos, bufsz - pos,
1683 "auto_corr_ofdm_mrc:\t\t %u\n",
1684 data->auto_corr_ofdm_mrc);
1685 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_x1:\t\t %u\n",
1686 data->auto_corr_ofdm_x1);
1687 pos += scnprintf(buf + pos, bufsz - pos,
1688 "auto_corr_ofdm_mrc_x1:\t\t %u\n",
1689 data->auto_corr_ofdm_mrc_x1);
1690 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck:\t\t\t %u\n",
1691 data->auto_corr_cck);
1692 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck_mrc:\t\t %u\n",
1693 data->auto_corr_cck_mrc);
1694 pos += scnprintf(buf + pos, bufsz - pos,
1695 "last_bad_plcp_cnt_ofdm:\t\t %u\n",
1696 data->last_bad_plcp_cnt_ofdm);
1697 pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_ofdm:\t\t %u\n",
1698 data->last_fa_cnt_ofdm);
1699 pos += scnprintf(buf + pos, bufsz - pos,
1700 "last_bad_plcp_cnt_cck:\t\t %u\n",
1701 data->last_bad_plcp_cnt_cck);
1702 pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_cck:\t\t %u\n",
1703 data->last_fa_cnt_cck);
1704 pos += scnprintf(buf + pos, bufsz - pos, "nrg_curr_state:\t\t\t %u\n",
1705 data->nrg_curr_state);
1706 pos += scnprintf(buf + pos, bufsz - pos, "nrg_prev_state:\t\t\t %u\n",
1707 data->nrg_prev_state);
1708 pos += scnprintf(buf + pos, bufsz - pos, "nrg_value:\t\t\t");
1709 for (cnt = 0; cnt < 10; cnt++) {
1710 pos += scnprintf(buf + pos, bufsz - pos, " %u",
1711 data->nrg_value[cnt]);
1712 }
1713 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1714 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_rssi:\t\t");
1715 for (cnt = 0; cnt < NRG_NUM_PREV_STAT_L; cnt++) {
1716 pos += scnprintf(buf + pos, bufsz - pos, " %u",
1717 data->nrg_silence_rssi[cnt]);
1718 }
1719 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1720 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_ref:\t\t %u\n",
1721 data->nrg_silence_ref);
1722 pos += scnprintf(buf + pos, bufsz - pos, "nrg_energy_idx:\t\t\t %u\n",
1723 data->nrg_energy_idx);
1724 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_idx:\t\t %u\n",
1725 data->nrg_silence_idx);
1726 pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_cck:\t\t\t %u\n",
1727 data->nrg_th_cck);
1728 pos += scnprintf(buf + pos, bufsz - pos,
1729 "nrg_auto_corr_silence_diff:\t %u\n",
1730 data->nrg_auto_corr_silence_diff);
1731 pos += scnprintf(buf + pos, bufsz - pos, "num_in_cck_no_fa:\t\t %u\n",
1732 data->num_in_cck_no_fa);
1733 pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_ofdm:\t\t\t %u\n",
1734 data->nrg_th_ofdm);
1735
1736 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1737 kfree(buf);
1738 return ret;
1739}
1740
1741
1742static ssize_t iwl_dbgfs_chain_noise_read(struct file *file,
1743 char __user *user_buf,
1744 size_t count, loff_t *ppos) {
1745
1746 struct iwl_priv *priv = file->private_data;
1747 int pos = 0;
1748 int cnt = 0;
1749 char *buf;
1750 int bufsz = sizeof(struct iwl_chain_noise_data) * 4 + 100;
1751 ssize_t ret;
1752 struct iwl_chain_noise_data *data;
1753
1754 data = &priv->chain_noise_data;
1755 buf = kzalloc(bufsz, GFP_KERNEL);
1756 if (!buf)
1757 return -ENOMEM;
1758
1759 pos += scnprintf(buf + pos, bufsz - pos, "active_chains:\t\t\t %u\n",
1760 data->active_chains);
1761 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_a:\t\t\t %u\n",
1762 data->chain_noise_a);
1763 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_b:\t\t\t %u\n",
1764 data->chain_noise_b);
1765 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_c:\t\t\t %u\n",
1766 data->chain_noise_c);
1767 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_a:\t\t\t %u\n",
1768 data->chain_signal_a);
1769 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_b:\t\t\t %u\n",
1770 data->chain_signal_b);
1771 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_c:\t\t\t %u\n",
1772 data->chain_signal_c);
1773 pos += scnprintf(buf + pos, bufsz - pos, "beacon_count:\t\t\t %u\n",
1774 data->beacon_count);
1775
1776 pos += scnprintf(buf + pos, bufsz - pos, "disconn_array:\t\t\t");
1777 for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
1778 pos += scnprintf(buf + pos, bufsz - pos, " %u",
1779 data->disconn_array[cnt]);
1780 }
1781 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1782 pos += scnprintf(buf + pos, bufsz - pos, "delta_gain_code:\t\t");
1783 for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
1784 pos += scnprintf(buf + pos, bufsz - pos, " %u",
1785 data->delta_gain_code[cnt]);
1786 }
1787 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1788 pos += scnprintf(buf + pos, bufsz - pos, "radio_write:\t\t\t %u\n",
1789 data->radio_write);
1790 pos += scnprintf(buf + pos, bufsz - pos, "state:\t\t\t\t %u\n",
1791 data->state);
1792
1793 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1794 kfree(buf);
1795 return ret;
1796}
1797
1798static ssize_t iwl_dbgfs_power_save_status_read(struct file *file,
1799 char __user *user_buf,
1800 size_t count, loff_t *ppos)
1801{
1802 struct iwl_priv *priv = file->private_data;
1803 char buf[60];
1804 int pos = 0;
1805 const size_t bufsz = sizeof(buf);
1806 u32 pwrsave_status;
1807
1808 pwrsave_status = iwl_read32(priv->trans, CSR_GP_CNTRL) &
1809 CSR_GP_REG_POWER_SAVE_STATUS_MSK;
1810
1811 pos += scnprintf(buf + pos, bufsz - pos, "Power Save Status: ");
1812 pos += scnprintf(buf + pos, bufsz - pos, "%s\n",
1813 (pwrsave_status == CSR_GP_REG_NO_POWER_SAVE) ? "none" :
1814 (pwrsave_status == CSR_GP_REG_MAC_POWER_SAVE) ? "MAC" :
1815 (pwrsave_status == CSR_GP_REG_PHY_POWER_SAVE) ? "PHY" :
1816 "error");
1817
1818 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1819}
1820
1821static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
1822 const char __user *user_buf,
1823 size_t count, loff_t *ppos)
1824{
1825 struct iwl_priv *priv = file->private_data;
1826 char buf[8];
1827 int buf_size;
1828 int clear;
1829
1830 memset(buf, 0, sizeof(buf));
1831 buf_size = min(count, sizeof(buf) - 1);
1832 if (copy_from_user(buf, user_buf, buf_size))
1833 return -EFAULT;
1834 if (sscanf(buf, "%d", &clear) != 1)
1835 return -EFAULT;
1836
1837
1838 mutex_lock(&priv->mutex);
1839 iwl_send_statistics_request(priv, 0, true);
1840 mutex_unlock(&priv->mutex);
1841
1842 return count;
1843}
1844
1845static ssize_t iwl_dbgfs_ucode_tracing_read(struct file *file,
1846 char __user *user_buf,
1847 size_t count, loff_t *ppos) {
1848
1849 struct iwl_priv *priv = file->private_data;
1850 int pos = 0;
1851 char buf[128];
1852 const size_t bufsz = sizeof(buf);
1853
1854 pos += scnprintf(buf + pos, bufsz - pos, "ucode trace timer is %s\n",
1855 priv->event_log.ucode_trace ? "On" : "Off");
1856 pos += scnprintf(buf + pos, bufsz - pos, "non_wraps_count:\t\t %u\n",
1857 priv->event_log.non_wraps_count);
1858 pos += scnprintf(buf + pos, bufsz - pos, "wraps_once_count:\t\t %u\n",
1859 priv->event_log.wraps_once_count);
1860 pos += scnprintf(buf + pos, bufsz - pos, "wraps_more_count:\t\t %u\n",
1861 priv->event_log.wraps_more_count);
1862
1863 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1864}
1865
1866static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
1867 const char __user *user_buf,
1868 size_t count, loff_t *ppos)
1869{
1870 struct iwl_priv *priv = file->private_data;
1871 char buf[8];
1872 int buf_size;
1873 int trace;
1874
1875 memset(buf, 0, sizeof(buf));
1876 buf_size = min(count, sizeof(buf) - 1);
1877 if (copy_from_user(buf, user_buf, buf_size))
1878 return -EFAULT;
1879 if (sscanf(buf, "%d", &trace) != 1)
1880 return -EFAULT;
1881
1882 if (trace) {
1883 priv->event_log.ucode_trace = true;
1884 if (iwl_is_alive(priv)) {
1885
1886 mod_timer(&priv->ucode_trace, jiffies);
1887 }
1888 } else {
1889 priv->event_log.ucode_trace = false;
1890 del_timer_sync(&priv->ucode_trace);
1891 }
1892
1893 return count;
1894}
1895
1896static ssize_t iwl_dbgfs_rxon_flags_read(struct file *file,
1897 char __user *user_buf,
1898 size_t count, loff_t *ppos) {
1899
1900 struct iwl_priv *priv = file->private_data;
1901 int len = 0;
1902 char buf[20];
1903
1904 len = sprintf(buf, "0x%04X\n",
1905 le32_to_cpu(priv->contexts[IWL_RXON_CTX_BSS].active.flags));
1906 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1907}
1908
1909static ssize_t iwl_dbgfs_rxon_filter_flags_read(struct file *file,
1910 char __user *user_buf,
1911 size_t count, loff_t *ppos) {
1912
1913 struct iwl_priv *priv = file->private_data;
1914 int len = 0;
1915 char buf[20];
1916
1917 len = sprintf(buf, "0x%04X\n",
1918 le32_to_cpu(priv->contexts[IWL_RXON_CTX_BSS].active.filter_flags));
1919 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1920}
1921
1922static ssize_t iwl_dbgfs_missed_beacon_read(struct file *file,
1923 char __user *user_buf,
1924 size_t count, loff_t *ppos) {
1925
1926 struct iwl_priv *priv = file->private_data;
1927 int pos = 0;
1928 char buf[12];
1929 const size_t bufsz = sizeof(buf);
1930
1931 pos += scnprintf(buf + pos, bufsz - pos, "%d\n",
1932 priv->missed_beacon_threshold);
1933
1934 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1935}
1936
1937static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
1938 const char __user *user_buf,
1939 size_t count, loff_t *ppos)
1940{
1941 struct iwl_priv *priv = file->private_data;
1942 char buf[8];
1943 int buf_size;
1944 int missed;
1945
1946 memset(buf, 0, sizeof(buf));
1947 buf_size = min(count, sizeof(buf) - 1);
1948 if (copy_from_user(buf, user_buf, buf_size))
1949 return -EFAULT;
1950 if (sscanf(buf, "%d", &missed) != 1)
1951 return -EINVAL;
1952
1953 if (missed < IWL_MISSED_BEACON_THRESHOLD_MIN ||
1954 missed > IWL_MISSED_BEACON_THRESHOLD_MAX)
1955 priv->missed_beacon_threshold =
1956 IWL_MISSED_BEACON_THRESHOLD_DEF;
1957 else
1958 priv->missed_beacon_threshold = missed;
1959
1960 return count;
1961}
1962
1963static ssize_t iwl_dbgfs_plcp_delta_read(struct file *file,
1964 char __user *user_buf,
1965 size_t count, loff_t *ppos) {
1966
1967 struct iwl_priv *priv = file->private_data;
1968 int pos = 0;
1969 char buf[12];
1970 const size_t bufsz = sizeof(buf);
1971
1972 pos += scnprintf(buf + pos, bufsz - pos, "%u\n",
1973 priv->plcp_delta_threshold);
1974
1975 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1976}
1977
1978static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
1979 const char __user *user_buf,
1980 size_t count, loff_t *ppos) {
1981
1982 struct iwl_priv *priv = file->private_data;
1983 char buf[8];
1984 int buf_size;
1985 int plcp;
1986
1987 memset(buf, 0, sizeof(buf));
1988 buf_size = min(count, sizeof(buf) - 1);
1989 if (copy_from_user(buf, user_buf, buf_size))
1990 return -EFAULT;
1991 if (sscanf(buf, "%d", &plcp) != 1)
1992 return -EINVAL;
1993 if ((plcp < IWL_MAX_PLCP_ERR_THRESHOLD_MIN) ||
1994 (plcp > IWL_MAX_PLCP_ERR_THRESHOLD_MAX))
1995 priv->plcp_delta_threshold =
1996 IWL_MAX_PLCP_ERR_THRESHOLD_DISABLE;
1997 else
1998 priv->plcp_delta_threshold = plcp;
1999 return count;
2000}
2001
2002static ssize_t iwl_dbgfs_rf_reset_read(struct file *file,
2003 char __user *user_buf,
2004 size_t count, loff_t *ppos)
2005{
2006 struct iwl_priv *priv = file->private_data;
2007 int pos = 0;
2008 char buf[300];
2009 const size_t bufsz = sizeof(buf);
2010 struct iwl_rf_reset *rf_reset = &priv->rf_reset;
2011
2012 pos += scnprintf(buf + pos, bufsz - pos,
2013 "RF reset statistics\n");
2014 pos += scnprintf(buf + pos, bufsz - pos,
2015 "\tnumber of reset request: %d\n",
2016 rf_reset->reset_request_count);
2017 pos += scnprintf(buf + pos, bufsz - pos,
2018 "\tnumber of reset request success: %d\n",
2019 rf_reset->reset_success_count);
2020 pos += scnprintf(buf + pos, bufsz - pos,
2021 "\tnumber of reset request reject: %d\n",
2022 rf_reset->reset_reject_count);
2023
2024 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2025}
2026
2027static ssize_t iwl_dbgfs_rf_reset_write(struct file *file,
2028 const char __user *user_buf,
2029 size_t count, loff_t *ppos) {
2030
2031 struct iwl_priv *priv = file->private_data;
2032 int ret;
2033
2034 ret = iwl_force_rf_reset(priv, true);
2035 return ret ? ret : count;
2036}
2037
2038static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
2039 const char __user *user_buf,
2040 size_t count, loff_t *ppos) {
2041
2042 struct iwl_priv *priv = file->private_data;
2043 char buf[8];
2044 int buf_size;
2045 int flush;
2046
2047 memset(buf, 0, sizeof(buf));
2048 buf_size = min(count, sizeof(buf) - 1);
2049 if (copy_from_user(buf, user_buf, buf_size))
2050 return -EFAULT;
2051 if (sscanf(buf, "%d", &flush) != 1)
2052 return -EINVAL;
2053
2054 if (iwl_is_rfkill(priv))
2055 return -EFAULT;
2056
2057 iwlagn_dev_txfifo_flush(priv);
2058
2059 return count;
2060}
2061
2062static ssize_t iwl_dbgfs_bt_traffic_read(struct file *file,
2063 char __user *user_buf,
2064 size_t count, loff_t *ppos) {
2065
2066 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
2067 int pos = 0;
2068 char buf[200];
2069 const size_t bufsz = sizeof(buf);
2070
2071 if (!priv->bt_enable_flag) {
2072 pos += scnprintf(buf + pos, bufsz - pos, "BT coex disabled\n");
2073 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2074 }
2075 pos += scnprintf(buf + pos, bufsz - pos, "BT enable flag: 0x%x\n",
2076 priv->bt_enable_flag);
2077 pos += scnprintf(buf + pos, bufsz - pos, "BT in %s mode\n",
2078 priv->bt_full_concurrent ? "full concurrency" : "3-wire");
2079 pos += scnprintf(buf + pos, bufsz - pos, "BT status: %s, "
2080 "last traffic notif: %d\n",
2081 priv->bt_status ? "On" : "Off", priv->last_bt_traffic_load);
2082 pos += scnprintf(buf + pos, bufsz - pos, "ch_announcement: %d, "
2083 "kill_ack_mask: %x, kill_cts_mask: %x\n",
2084 priv->bt_ch_announce, priv->kill_ack_mask,
2085 priv->kill_cts_mask);
2086
2087 pos += scnprintf(buf + pos, bufsz - pos, "bluetooth traffic load: ");
2088 switch (priv->bt_traffic_load) {
2089 case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS:
2090 pos += scnprintf(buf + pos, bufsz - pos, "Continuous\n");
2091 break;
2092 case IWL_BT_COEX_TRAFFIC_LOAD_HIGH:
2093 pos += scnprintf(buf + pos, bufsz - pos, "High\n");
2094 break;
2095 case IWL_BT_COEX_TRAFFIC_LOAD_LOW:
2096 pos += scnprintf(buf + pos, bufsz - pos, "Low\n");
2097 break;
2098 case IWL_BT_COEX_TRAFFIC_LOAD_NONE:
2099 default:
2100 pos += scnprintf(buf + pos, bufsz - pos, "None\n");
2101 break;
2102 }
2103
2104 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2105}
2106
2107static ssize_t iwl_dbgfs_protection_mode_read(struct file *file,
2108 char __user *user_buf,
2109 size_t count, loff_t *ppos)
2110{
2111 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
2112
2113 int pos = 0;
2114 char buf[40];
2115 const size_t bufsz = sizeof(buf);
2116
2117 if (priv->cfg->ht_params)
2118 pos += scnprintf(buf + pos, bufsz - pos,
2119 "use %s for aggregation\n",
2120 (priv->hw_params.use_rts_for_aggregation) ?
2121 "rts/cts" : "cts-to-self");
2122 else
2123 pos += scnprintf(buf + pos, bufsz - pos, "N/A");
2124
2125 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2126}
2127
2128static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
2129 const char __user *user_buf,
2130 size_t count, loff_t *ppos) {
2131
2132 struct iwl_priv *priv = file->private_data;
2133 char buf[8];
2134 int buf_size;
2135 int rts;
2136
2137 if (!priv->cfg->ht_params)
2138 return -EINVAL;
2139
2140 memset(buf, 0, sizeof(buf));
2141 buf_size = min(count, sizeof(buf) - 1);
2142 if (copy_from_user(buf, user_buf, buf_size))
2143 return -EFAULT;
2144 if (sscanf(buf, "%d", &rts) != 1)
2145 return -EINVAL;
2146 if (rts)
2147 priv->hw_params.use_rts_for_aggregation = true;
2148 else
2149 priv->hw_params.use_rts_for_aggregation = false;
2150 return count;
2151}
2152
2153static int iwl_cmd_echo_test(struct iwl_priv *priv)
2154{
2155 int ret;
2156 struct iwl_host_cmd cmd = {
2157 .id = REPLY_ECHO,
2158 .len = { 0 },
2159 };
2160
2161 ret = iwl_dvm_send_cmd(priv, &cmd);
2162 if (ret)
2163 IWL_ERR(priv, "echo testing fail: 0X%x\n", ret);
2164 else
2165 IWL_DEBUG_INFO(priv, "echo testing pass\n");
2166 return ret;
2167}
2168
2169static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
2170 const char __user *user_buf,
2171 size_t count, loff_t *ppos)
2172{
2173 struct iwl_priv *priv = file->private_data;
2174 char buf[8];
2175 int buf_size;
2176
2177 memset(buf, 0, sizeof(buf));
2178 buf_size = min(count, sizeof(buf) - 1);
2179 if (copy_from_user(buf, user_buf, buf_size))
2180 return -EFAULT;
2181
2182 iwl_cmd_echo_test(priv);
2183 return count;
2184}
2185
2186#ifdef CONFIG_IWLWIFI_DEBUG
2187static ssize_t iwl_dbgfs_log_event_read(struct file *file,
2188 char __user *user_buf,
2189 size_t count, loff_t *ppos)
2190{
2191 struct iwl_priv *priv = file->private_data;
2192 char *buf = NULL;
2193 ssize_t ret;
2194
2195 ret = iwl_dump_nic_event_log(priv, true, &buf);
2196 if (ret > 0)
2197 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
2198 kfree(buf);
2199 return ret;
2200}
2201
2202static ssize_t iwl_dbgfs_log_event_write(struct file *file,
2203 const char __user *user_buf,
2204 size_t count, loff_t *ppos)
2205{
2206 struct iwl_priv *priv = file->private_data;
2207 u32 event_log_flag;
2208 char buf[8];
2209 int buf_size;
2210
2211
2212 if (!iwl_is_ready(priv))
2213 return -EAGAIN;
2214
2215 memset(buf, 0, sizeof(buf));
2216 buf_size = min(count, sizeof(buf) - 1);
2217 if (copy_from_user(buf, user_buf, buf_size))
2218 return -EFAULT;
2219 if (sscanf(buf, "%u", &event_log_flag) != 1)
2220 return -EFAULT;
2221 if (event_log_flag == 1)
2222 iwl_dump_nic_event_log(priv, true, NULL);
2223
2224 return count;
2225}
2226#endif
2227
2228static ssize_t iwl_dbgfs_calib_disabled_read(struct file *file,
2229 char __user *user_buf,
2230 size_t count, loff_t *ppos)
2231{
2232 struct iwl_priv *priv = file->private_data;
2233 char buf[120];
2234 int pos = 0;
2235 const size_t bufsz = sizeof(buf);
2236
2237 pos += scnprintf(buf + pos, bufsz - pos,
2238 "Sensitivity calibrations %s\n",
2239 (priv->calib_disabled &
2240 IWL_SENSITIVITY_CALIB_DISABLED) ?
2241 "DISABLED" : "ENABLED");
2242 pos += scnprintf(buf + pos, bufsz - pos,
2243 "Chain noise calibrations %s\n",
2244 (priv->calib_disabled &
2245 IWL_CHAIN_NOISE_CALIB_DISABLED) ?
2246 "DISABLED" : "ENABLED");
2247 pos += scnprintf(buf + pos, bufsz - pos,
2248 "Tx power calibrations %s\n",
2249 (priv->calib_disabled &
2250 IWL_TX_POWER_CALIB_DISABLED) ?
2251 "DISABLED" : "ENABLED");
2252
2253 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2254}
2255
2256static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
2257 const char __user *user_buf,
2258 size_t count, loff_t *ppos)
2259{
2260 struct iwl_priv *priv = file->private_data;
2261 char buf[8];
2262 u32 calib_disabled;
2263 int buf_size;
2264
2265 memset(buf, 0, sizeof(buf));
2266 buf_size = min(count, sizeof(buf) - 1);
2267 if (copy_from_user(buf, user_buf, buf_size))
2268 return -EFAULT;
2269 if (sscanf(buf, "%x", &calib_disabled) != 1)
2270 return -EFAULT;
2271
2272 priv->calib_disabled = calib_disabled;
2273
2274 return count;
2275}
2276
2277static ssize_t iwl_dbgfs_fw_restart_write(struct file *file,
2278 const char __user *user_buf,
2279 size_t count, loff_t *ppos)
2280{
2281 struct iwl_priv *priv = file->private_data;
2282 bool fw_restart = iwlwifi_mod_params.fw_restart;
2283 int __maybe_unused ret;
2284
2285 iwlwifi_mod_params.fw_restart = true;
2286
2287 mutex_lock(&priv->mutex);
2288
2289
2290 ret = iwl_dvm_send_cmd_pdu(priv, REPLY_ERROR, 0, 0, NULL);
2291
2292 mutex_unlock(&priv->mutex);
2293
2294 iwlwifi_mod_params.fw_restart = fw_restart;
2295
2296 return count;
2297}
2298
2299DEBUGFS_READ_FILE_OPS(ucode_rx_stats);
2300DEBUGFS_READ_FILE_OPS(ucode_tx_stats);
2301DEBUGFS_READ_FILE_OPS(ucode_general_stats);
2302DEBUGFS_READ_FILE_OPS(sensitivity);
2303DEBUGFS_READ_FILE_OPS(chain_noise);
2304DEBUGFS_READ_FILE_OPS(power_save_status);
2305DEBUGFS_WRITE_FILE_OPS(clear_ucode_statistics);
2306DEBUGFS_READ_WRITE_FILE_OPS(ucode_tracing);
2307DEBUGFS_READ_WRITE_FILE_OPS(missed_beacon);
2308DEBUGFS_READ_WRITE_FILE_OPS(plcp_delta);
2309DEBUGFS_READ_WRITE_FILE_OPS(rf_reset);
2310DEBUGFS_READ_FILE_OPS(rxon_flags);
2311DEBUGFS_READ_FILE_OPS(rxon_filter_flags);
2312DEBUGFS_WRITE_FILE_OPS(txfifo_flush);
2313DEBUGFS_READ_FILE_OPS(ucode_bt_stats);
2314DEBUGFS_READ_FILE_OPS(bt_traffic);
2315DEBUGFS_READ_WRITE_FILE_OPS(protection_mode);
2316DEBUGFS_READ_FILE_OPS(reply_tx_error);
2317DEBUGFS_WRITE_FILE_OPS(echo_test);
2318DEBUGFS_WRITE_FILE_OPS(fw_restart);
2319#ifdef CONFIG_IWLWIFI_DEBUG
2320DEBUGFS_READ_WRITE_FILE_OPS(log_event);
2321#endif
2322DEBUGFS_READ_WRITE_FILE_OPS(calib_disabled);
2323
2324
2325
2326
2327
2328void iwl_dbgfs_register(struct iwl_priv *priv, struct dentry *dbgfs_dir)
2329{
2330 struct dentry *dir_data, *dir_rf, *dir_debug;
2331
2332 priv->debugfs_dir = dbgfs_dir;
2333
2334 dir_data = debugfs_create_dir("data", dbgfs_dir);
2335 dir_rf = debugfs_create_dir("rf", dbgfs_dir);
2336 dir_debug = debugfs_create_dir("debug", dbgfs_dir);
2337
2338 DEBUGFS_ADD_FILE(nvm, dir_data, 0400);
2339 DEBUGFS_ADD_FILE(sram, dir_data, 0600);
2340 DEBUGFS_ADD_FILE(wowlan_sram, dir_data, 0400);
2341 DEBUGFS_ADD_FILE(stations, dir_data, 0400);
2342 DEBUGFS_ADD_FILE(channels, dir_data, 0400);
2343 DEBUGFS_ADD_FILE(status, dir_data, 0400);
2344 DEBUGFS_ADD_FILE(rx_handlers, dir_data, 0600);
2345 DEBUGFS_ADD_FILE(qos, dir_data, 0400);
2346 DEBUGFS_ADD_FILE(sleep_level_override, dir_data, 0600);
2347 DEBUGFS_ADD_FILE(current_sleep_command, dir_data, 0400);
2348 DEBUGFS_ADD_FILE(thermal_throttling, dir_data, 0400);
2349 DEBUGFS_ADD_FILE(disable_ht40, dir_data, 0600);
2350 DEBUGFS_ADD_FILE(temperature, dir_data, 0400);
2351
2352 DEBUGFS_ADD_FILE(power_save_status, dir_debug, 0400);
2353 DEBUGFS_ADD_FILE(clear_ucode_statistics, dir_debug, 0200);
2354 DEBUGFS_ADD_FILE(missed_beacon, dir_debug, 0200);
2355 DEBUGFS_ADD_FILE(plcp_delta, dir_debug, 0600);
2356 DEBUGFS_ADD_FILE(rf_reset, dir_debug, 0600);
2357 DEBUGFS_ADD_FILE(ucode_rx_stats, dir_debug, 0400);
2358 DEBUGFS_ADD_FILE(ucode_tx_stats, dir_debug, 0400);
2359 DEBUGFS_ADD_FILE(ucode_general_stats, dir_debug, 0400);
2360 DEBUGFS_ADD_FILE(txfifo_flush, dir_debug, 0200);
2361 DEBUGFS_ADD_FILE(protection_mode, dir_debug, 0600);
2362 DEBUGFS_ADD_FILE(sensitivity, dir_debug, 0400);
2363 DEBUGFS_ADD_FILE(chain_noise, dir_debug, 0400);
2364 DEBUGFS_ADD_FILE(ucode_tracing, dir_debug, 0600);
2365 DEBUGFS_ADD_FILE(ucode_bt_stats, dir_debug, 0400);
2366 DEBUGFS_ADD_FILE(reply_tx_error, dir_debug, 0400);
2367 DEBUGFS_ADD_FILE(rxon_flags, dir_debug, 0200);
2368 DEBUGFS_ADD_FILE(rxon_filter_flags, dir_debug, 0200);
2369 DEBUGFS_ADD_FILE(echo_test, dir_debug, 0200);
2370 DEBUGFS_ADD_FILE(fw_restart, dir_debug, 0200);
2371#ifdef CONFIG_IWLWIFI_DEBUG
2372 DEBUGFS_ADD_FILE(log_event, dir_debug, 0600);
2373#endif
2374
2375 if (iwl_advanced_bt_coexist(priv))
2376 DEBUGFS_ADD_FILE(bt_traffic, dir_debug, 0400);
2377
2378
2379 DEBUGFS_ADD_FILE(calib_disabled, dir_rf, 0600);
2380
2381
2382
2383
2384
2385
2386
2387 if (priv->mac80211_registered) {
2388 char buf[100];
2389 struct dentry *mac80211_dir, *dev_dir;
2390
2391 dev_dir = dbgfs_dir->d_parent;
2392 mac80211_dir = priv->hw->wiphy->debugfsdir;
2393
2394 snprintf(buf, 100, "../../%pd2", dev_dir);
2395
2396 debugfs_create_symlink("iwlwifi", mac80211_dir, buf);
2397 }
2398}
2399