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