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