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