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