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