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