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