iwlwifi: remove device type checking for tx power in debugfs
[safe/jmp/linux-2.6] / drivers / net / wireless / iwlwifi / iwl-debugfs.c
1 /******************************************************************************
2  *
3  * GPL LICENSE SUMMARY
4  *
5  * Copyright(c) 2008 - 2010 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 #include <linux/ieee80211.h>
29 #include <net/mac80211.h>
30
31
32 #include "iwl-dev.h"
33 #include "iwl-debug.h"
34 #include "iwl-core.h"
35 #include "iwl-io.h"
36 #include "iwl-calib.h"
37
38 /* create and remove of files */
39 #define DEBUGFS_ADD_FILE(name, parent, mode) do {                       \
40         if (!debugfs_create_file(#name, mode, parent, priv,             \
41                                  &iwl_dbgfs_##name##_ops))              \
42                 goto err;                                               \
43 } while (0)
44
45 #define DEBUGFS_ADD_BOOL(name, parent, ptr) do {                        \
46         struct dentry *__tmp;                                           \
47         __tmp = debugfs_create_bool(#name, S_IWUSR | S_IRUSR,           \
48                                     parent, ptr);                       \
49         if (IS_ERR(__tmp) || !__tmp)                                    \
50                 goto err;                                               \
51 } while (0)
52
53 #define DEBUGFS_ADD_X32(name, parent, ptr) do {                         \
54         struct dentry *__tmp;                                           \
55         __tmp = debugfs_create_x32(#name, S_IWUSR | S_IRUSR,            \
56                                    parent, ptr);                        \
57         if (IS_ERR(__tmp) || !__tmp)                                    \
58                 goto err;                                               \
59 } while (0)
60
61 /* file operation */
62 #define DEBUGFS_READ_FUNC(name)                                         \
63 static ssize_t iwl_dbgfs_##name##_read(struct file *file,               \
64                                         char __user *user_buf,          \
65                                         size_t count, loff_t *ppos);
66
67 #define DEBUGFS_WRITE_FUNC(name)                                        \
68 static ssize_t iwl_dbgfs_##name##_write(struct file *file,              \
69                                         const char __user *user_buf,    \
70                                         size_t count, loff_t *ppos);
71
72
73 static int iwl_dbgfs_open_file_generic(struct inode *inode, struct file *file)
74 {
75         file->private_data = inode->i_private;
76         return 0;
77 }
78
79 #define DEBUGFS_READ_FILE_OPS(name)                                     \
80         DEBUGFS_READ_FUNC(name);                                        \
81 static const struct file_operations iwl_dbgfs_##name##_ops = {          \
82         .read = iwl_dbgfs_##name##_read,                                \
83         .open = iwl_dbgfs_open_file_generic,                            \
84 };
85
86 #define DEBUGFS_WRITE_FILE_OPS(name)                                    \
87         DEBUGFS_WRITE_FUNC(name);                                       \
88 static const struct file_operations iwl_dbgfs_##name##_ops = {          \
89         .write = iwl_dbgfs_##name##_write,                              \
90         .open = iwl_dbgfs_open_file_generic,                            \
91 };
92
93
94 #define DEBUGFS_READ_WRITE_FILE_OPS(name)                               \
95         DEBUGFS_READ_FUNC(name);                                        \
96         DEBUGFS_WRITE_FUNC(name);                                       \
97 static const struct file_operations iwl_dbgfs_##name##_ops = {          \
98         .write = iwl_dbgfs_##name##_write,                              \
99         .read = iwl_dbgfs_##name##_read,                                \
100         .open = iwl_dbgfs_open_file_generic,                            \
101 };
102
103 int iwl_dbgfs_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
104 {
105         int p = 0;
106
107         p += scnprintf(buf + p, bufsz - p, "Statistics Flag(0x%X):\n",
108                        le32_to_cpu(priv->statistics.flag));
109         if (le32_to_cpu(priv->statistics.flag) & UCODE_STATISTICS_CLEAR_MSK)
110                 p += scnprintf(buf + p, bufsz - p,
111                                "\tStatistics have been cleared\n");
112         p += scnprintf(buf + p, bufsz - p, "\tOperational Frequency: %s\n",
113                        (le32_to_cpu(priv->statistics.flag) &
114                         UCODE_STATISTICS_FREQUENCY_MSK)
115                         ? "2.4 GHz" : "5.2 GHz");
116         p += scnprintf(buf + p, bufsz - p, "\tTGj Narrow Band: %s\n",
117                        (le32_to_cpu(priv->statistics.flag) &
118                         UCODE_STATISTICS_NARROW_BAND_MSK)
119                         ? "enabled" : "disabled");
120         return p;
121 }
122 EXPORT_SYMBOL(iwl_dbgfs_statistics_flag);
123
124 static ssize_t iwl_dbgfs_tx_statistics_read(struct file *file,
125                                                 char __user *user_buf,
126                                                 size_t count, loff_t *ppos) {
127
128         struct iwl_priv *priv = file->private_data;
129         char *buf;
130         int pos = 0;
131
132         int cnt;
133         ssize_t ret;
134         const size_t bufsz = 100 +
135                 sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
136         buf = kzalloc(bufsz, GFP_KERNEL);
137         if (!buf)
138                 return -ENOMEM;
139         pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
140         for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
141                 pos += scnprintf(buf + pos, bufsz - pos,
142                                  "\t%25s\t\t: %u\n",
143                                  get_mgmt_string(cnt),
144                                  priv->tx_stats.mgmt[cnt]);
145         }
146         pos += scnprintf(buf + pos, bufsz - pos, "Control\n");
147         for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
148                 pos += scnprintf(buf + pos, bufsz - pos,
149                                  "\t%25s\t\t: %u\n",
150                                  get_ctrl_string(cnt),
151                                  priv->tx_stats.ctrl[cnt]);
152         }
153         pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
154         pos += scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
155                          priv->tx_stats.data_cnt);
156         pos += scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
157                          priv->tx_stats.data_bytes);
158         ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
159         kfree(buf);
160         return ret;
161 }
162
163 static ssize_t iwl_dbgfs_clear_traffic_statistics_write(struct file *file,
164                                         const char __user *user_buf,
165                                         size_t count, loff_t *ppos)
166 {
167         struct iwl_priv *priv = file->private_data;
168         u32 clear_flag;
169         char buf[8];
170         int buf_size;
171
172         memset(buf, 0, sizeof(buf));
173         buf_size = min(count, sizeof(buf) -  1);
174         if (copy_from_user(buf, user_buf, buf_size))
175                 return -EFAULT;
176         if (sscanf(buf, "%x", &clear_flag) != 1)
177                 return -EFAULT;
178         iwl_clear_traffic_stats(priv);
179
180         return count;
181 }
182
183 static ssize_t iwl_dbgfs_rx_statistics_read(struct file *file,
184                                                 char __user *user_buf,
185                                                 size_t count, loff_t *ppos) {
186
187         struct iwl_priv *priv = file->private_data;
188         char *buf;
189         int pos = 0;
190         int cnt;
191         ssize_t ret;
192         const size_t bufsz = 100 +
193                 sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
194         buf = kzalloc(bufsz, GFP_KERNEL);
195         if (!buf)
196                 return -ENOMEM;
197
198         pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
199         for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
200                 pos += scnprintf(buf + pos, bufsz - pos,
201                                  "\t%25s\t\t: %u\n",
202                                  get_mgmt_string(cnt),
203                                  priv->rx_stats.mgmt[cnt]);
204         }
205         pos += scnprintf(buf + pos, bufsz - pos, "Control:\n");
206         for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
207                 pos += scnprintf(buf + pos, bufsz - pos,
208                                  "\t%25s\t\t: %u\n",
209                                  get_ctrl_string(cnt),
210                                  priv->rx_stats.ctrl[cnt]);
211         }
212         pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
213         pos += scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
214                          priv->rx_stats.data_cnt);
215         pos += scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
216                          priv->rx_stats.data_bytes);
217
218         ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
219         kfree(buf);
220         return ret;
221 }
222
223 #define BYTE1_MASK 0x000000ff;
224 #define BYTE2_MASK 0x0000ffff;
225 #define BYTE3_MASK 0x00ffffff;
226 static ssize_t iwl_dbgfs_sram_read(struct file *file,
227                                         char __user *user_buf,
228                                         size_t count, loff_t *ppos)
229 {
230         u32 val;
231         char *buf;
232         ssize_t ret;
233         int i;
234         int pos = 0;
235         struct iwl_priv *priv = file->private_data;
236         size_t bufsz;
237
238         /* default is to dump the entire data segment */
239         if (!priv->dbgfs_sram_offset && !priv->dbgfs_sram_len) {
240                 priv->dbgfs_sram_offset = 0x800000;
241                 if (priv->ucode_type == UCODE_INIT)
242                         priv->dbgfs_sram_len = priv->ucode_init_data.len;
243                 else
244                         priv->dbgfs_sram_len = priv->ucode_data.len;
245         }
246         bufsz =  30 + priv->dbgfs_sram_len * sizeof(char) * 10;
247         buf = kmalloc(bufsz, GFP_KERNEL);
248         if (!buf)
249                 return -ENOMEM;
250         pos += scnprintf(buf + pos, bufsz - pos, "sram_len: 0x%x\n",
251                         priv->dbgfs_sram_len);
252         pos += scnprintf(buf + pos, bufsz - pos, "sram_offset: 0x%x\n",
253                         priv->dbgfs_sram_offset);
254         for (i = priv->dbgfs_sram_len; i > 0; i -= 4) {
255                 val = iwl_read_targ_mem(priv, priv->dbgfs_sram_offset + \
256                                         priv->dbgfs_sram_len - i);
257                 if (i < 4) {
258                         switch (i) {
259                         case 1:
260                                 val &= BYTE1_MASK;
261                                 break;
262                         case 2:
263                                 val &= BYTE2_MASK;
264                                 break;
265                         case 3:
266                                 val &= BYTE3_MASK;
267                                 break;
268                         }
269                 }
270                 if (!(i % 16))
271                         pos += scnprintf(buf + pos, bufsz - pos, "\n");
272                 pos += scnprintf(buf + pos, bufsz - pos, "0x%08x ", val);
273         }
274         pos += scnprintf(buf + pos, bufsz - pos, "\n");
275
276         ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
277         kfree(buf);
278         return ret;
279 }
280
281 static ssize_t iwl_dbgfs_sram_write(struct file *file,
282                                         const char __user *user_buf,
283                                         size_t count, loff_t *ppos)
284 {
285         struct iwl_priv *priv = file->private_data;
286         char buf[64];
287         int buf_size;
288         u32 offset, len;
289
290         memset(buf, 0, sizeof(buf));
291         buf_size = min(count, sizeof(buf) -  1);
292         if (copy_from_user(buf, user_buf, buf_size))
293                 return -EFAULT;
294
295         if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
296                 priv->dbgfs_sram_offset = offset;
297                 priv->dbgfs_sram_len = len;
298         } else {
299                 priv->dbgfs_sram_offset = 0;
300                 priv->dbgfs_sram_len = 0;
301         }
302
303         return count;
304 }
305
306 static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
307                                         size_t count, loff_t *ppos)
308 {
309         struct iwl_priv *priv = file->private_data;
310         struct iwl_station_entry *station;
311         int max_sta = priv->hw_params.max_stations;
312         char *buf;
313         int i, j, pos = 0;
314         ssize_t ret;
315         /* Add 30 for initial string */
316         const size_t bufsz = 30 + sizeof(char) * 500 * (priv->num_stations);
317
318         buf = kmalloc(bufsz, GFP_KERNEL);
319         if (!buf)
320                 return -ENOMEM;
321
322         pos += scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n",
323                         priv->num_stations);
324
325         for (i = 0; i < max_sta; i++) {
326                 station = &priv->stations[i];
327                 if (station->used) {
328                         pos += scnprintf(buf + pos, bufsz - pos,
329                                         "station %d:\ngeneral data:\n", i+1);
330                         pos += scnprintf(buf + pos, bufsz - pos, "id: %u\n",
331                                         station->sta.sta.sta_id);
332                         pos += scnprintf(buf + pos, bufsz - pos, "mode: %u\n",
333                                         station->sta.mode);
334                         pos += scnprintf(buf + pos, bufsz - pos,
335                                         "flags: 0x%x\n",
336                                         station->sta.station_flags_msk);
337                         pos += scnprintf(buf + pos, bufsz - pos, "tid data:\n");
338                         pos += scnprintf(buf + pos, bufsz - pos,
339                                         "seq_num\t\ttxq_id");
340                         pos += scnprintf(buf + pos, bufsz - pos,
341                                         "\tframe_count\twait_for_ba\t");
342                         pos += scnprintf(buf + pos, bufsz - pos,
343                                         "start_idx\tbitmap0\t");
344                         pos += scnprintf(buf + pos, bufsz - pos,
345                                         "bitmap1\trate_n_flags");
346                         pos += scnprintf(buf + pos, bufsz - pos, "\n");
347
348                         for (j = 0; j < MAX_TID_COUNT; j++) {
349                                 pos += scnprintf(buf + pos, bufsz - pos,
350                                                 "[%d]:\t\t%u", j,
351                                                 station->tid[j].seq_number);
352                                 pos += scnprintf(buf + pos, bufsz - pos,
353                                                 "\t%u\t\t%u\t\t%u\t\t",
354                                                 station->tid[j].agg.txq_id,
355                                                 station->tid[j].agg.frame_count,
356                                                 station->tid[j].agg.wait_for_ba);
357                                 pos += scnprintf(buf + pos, bufsz - pos,
358                                                 "%u\t%llu\t%u",
359                                                 station->tid[j].agg.start_idx,
360                                                 (unsigned long long)station->tid[j].agg.bitmap,
361                                                 station->tid[j].agg.rate_n_flags);
362                                 pos += scnprintf(buf + pos, bufsz - pos, "\n");
363                         }
364                         pos += scnprintf(buf + pos, bufsz - pos, "\n");
365                 }
366         }
367
368         ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
369         kfree(buf);
370         return ret;
371 }
372
373 static ssize_t iwl_dbgfs_nvm_read(struct file *file,
374                                        char __user *user_buf,
375                                        size_t count,
376                                        loff_t *ppos)
377 {
378         ssize_t ret;
379         struct iwl_priv *priv = file->private_data;
380         int pos = 0, ofs = 0, buf_size = 0;
381         const u8 *ptr;
382         char *buf;
383         u16 eeprom_ver;
384         size_t eeprom_len = priv->cfg->eeprom_size;
385         buf_size = 4 * eeprom_len + 256;
386
387         if (eeprom_len % 16) {
388                 IWL_ERR(priv, "NVM size is not multiple of 16.\n");
389                 return -ENODATA;
390         }
391
392         ptr = priv->eeprom;
393         if (!ptr) {
394                 IWL_ERR(priv, "Invalid EEPROM/OTP memory\n");
395                 return -ENOMEM;
396         }
397
398         /* 4 characters for byte 0xYY */
399         buf = kzalloc(buf_size, GFP_KERNEL);
400         if (!buf) {
401                 IWL_ERR(priv, "Can not allocate Buffer\n");
402                 return -ENOMEM;
403         }
404         eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
405         pos += scnprintf(buf + pos, buf_size - pos, "NVM Type: %s, "
406                         "version: 0x%x\n",
407                         (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP)
408                          ? "OTP" : "EEPROM", eeprom_ver);
409         for (ofs = 0 ; ofs < eeprom_len ; ofs += 16) {
410                 pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x ", ofs);
411                 hex_dump_to_buffer(ptr + ofs, 16 , 16, 2, buf + pos,
412                                    buf_size - pos, 0);
413                 pos += strlen(buf + pos);
414                 if (buf_size - pos > 0)
415                         buf[pos++] = '\n';
416         }
417
418         ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
419         kfree(buf);
420         return ret;
421 }
422
423 static ssize_t iwl_dbgfs_log_event_read(struct file *file,
424                                          char __user *user_buf,
425                                          size_t count, loff_t *ppos)
426 {
427         struct iwl_priv *priv = file->private_data;
428         char *buf;
429         int pos = 0;
430         ssize_t ret = -ENOMEM;
431
432         ret = pos = priv->cfg->ops->lib->dump_nic_event_log(
433                                         priv, true, &buf, true);
434         if (buf) {
435                 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
436                 kfree(buf);
437         }
438         return ret;
439 }
440
441 static ssize_t iwl_dbgfs_log_event_write(struct file *file,
442                                         const char __user *user_buf,
443                                         size_t count, loff_t *ppos)
444 {
445         struct iwl_priv *priv = file->private_data;
446         u32 event_log_flag;
447         char buf[8];
448         int buf_size;
449
450         memset(buf, 0, sizeof(buf));
451         buf_size = min(count, sizeof(buf) -  1);
452         if (copy_from_user(buf, user_buf, buf_size))
453                 return -EFAULT;
454         if (sscanf(buf, "%d", &event_log_flag) != 1)
455                 return -EFAULT;
456         if (event_log_flag == 1)
457                 priv->cfg->ops->lib->dump_nic_event_log(priv, true,
458                                                         NULL, false);
459
460         return count;
461 }
462
463
464
465 static ssize_t iwl_dbgfs_channels_read(struct file *file, char __user *user_buf,
466                                        size_t count, loff_t *ppos)
467 {
468         struct iwl_priv *priv = file->private_data;
469         struct ieee80211_channel *channels = NULL;
470         const struct ieee80211_supported_band *supp_band = NULL;
471         int pos = 0, i, bufsz = PAGE_SIZE;
472         char *buf;
473         ssize_t ret;
474
475         if (!test_bit(STATUS_GEO_CONFIGURED, &priv->status))
476                 return -EAGAIN;
477
478         buf = kzalloc(bufsz, GFP_KERNEL);
479         if (!buf) {
480                 IWL_ERR(priv, "Can not allocate Buffer\n");
481                 return -ENOMEM;
482         }
483
484         supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_2GHZ);
485         if (supp_band) {
486                 channels = supp_band->channels;
487
488                 pos += scnprintf(buf + pos, bufsz - pos,
489                                 "Displaying %d channels in 2.4GHz band 802.11bg):\n",
490                                 supp_band->n_channels);
491
492                 for (i = 0; i < supp_band->n_channels; i++)
493                         pos += scnprintf(buf + pos, bufsz - pos,
494                                         "%d: %ddBm: BSS%s%s, %s.\n",
495                                         ieee80211_frequency_to_channel(
496                                         channels[i].center_freq),
497                                         channels[i].max_power,
498                                         channels[i].flags & IEEE80211_CHAN_RADAR ?
499                                         " (IEEE 802.11h required)" : "",
500                                         ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
501                                         || (channels[i].flags &
502                                         IEEE80211_CHAN_RADAR)) ? "" :
503                                         ", IBSS",
504                                         channels[i].flags &
505                                         IEEE80211_CHAN_PASSIVE_SCAN ?
506                                         "passive only" : "active/passive");
507         }
508         supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_5GHZ);
509         if (supp_band) {
510                 channels = supp_band->channels;
511
512                 pos += scnprintf(buf + pos, bufsz - pos,
513                                 "Displaying %d channels in 5.2GHz band (802.11a)\n",
514                                 supp_band->n_channels);
515
516                 for (i = 0; i < supp_band->n_channels; i++)
517                         pos += scnprintf(buf + pos, bufsz - pos,
518                                         "%d: %ddBm: BSS%s%s, %s.\n",
519                                         ieee80211_frequency_to_channel(
520                                         channels[i].center_freq),
521                                         channels[i].max_power,
522                                         channels[i].flags & IEEE80211_CHAN_RADAR ?
523                                         " (IEEE 802.11h required)" : "",
524                                         ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
525                                         || (channels[i].flags &
526                                         IEEE80211_CHAN_RADAR)) ? "" :
527                                         ", IBSS",
528                                         channels[i].flags &
529                                         IEEE80211_CHAN_PASSIVE_SCAN ?
530                                         "passive only" : "active/passive");
531         }
532         ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
533         kfree(buf);
534         return ret;
535 }
536
537 static ssize_t iwl_dbgfs_status_read(struct file *file,
538                                                 char __user *user_buf,
539                                                 size_t count, loff_t *ppos) {
540
541         struct iwl_priv *priv = file->private_data;
542         char buf[512];
543         int pos = 0;
544         const size_t bufsz = sizeof(buf);
545
546         pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_ACTIVE:\t %d\n",
547                 test_bit(STATUS_HCMD_ACTIVE, &priv->status));
548         pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INT_ENABLED:\t %d\n",
549                 test_bit(STATUS_INT_ENABLED, &priv->status));
550         pos += scnprintf(buf + pos, bufsz - pos, "STATUS_RF_KILL_HW:\t %d\n",
551                 test_bit(STATUS_RF_KILL_HW, &priv->status));
552         pos += scnprintf(buf + pos, bufsz - pos, "STATUS_CT_KILL:\t\t %d\n",
553                 test_bit(STATUS_CT_KILL, &priv->status));
554         pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INIT:\t\t %d\n",
555                 test_bit(STATUS_INIT, &priv->status));
556         pos += scnprintf(buf + pos, bufsz - pos, "STATUS_ALIVE:\t\t %d\n",
557                 test_bit(STATUS_ALIVE, &priv->status));
558         pos += scnprintf(buf + pos, bufsz - pos, "STATUS_READY:\t\t %d\n",
559                 test_bit(STATUS_READY, &priv->status));
560         pos += scnprintf(buf + pos, bufsz - pos, "STATUS_TEMPERATURE:\t %d\n",
561                 test_bit(STATUS_TEMPERATURE, &priv->status));
562         pos += scnprintf(buf + pos, bufsz - pos, "STATUS_GEO_CONFIGURED:\t %d\n",
563                 test_bit(STATUS_GEO_CONFIGURED, &priv->status));
564         pos += scnprintf(buf + pos, bufsz - pos, "STATUS_EXIT_PENDING:\t %d\n",
565                 test_bit(STATUS_EXIT_PENDING, &priv->status));
566         pos += scnprintf(buf + pos, bufsz - pos, "STATUS_STATISTICS:\t %d\n",
567                 test_bit(STATUS_STATISTICS, &priv->status));
568         pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCANNING:\t %d\n",
569                 test_bit(STATUS_SCANNING, &priv->status));
570         pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_ABORTING:\t %d\n",
571                 test_bit(STATUS_SCAN_ABORTING, &priv->status));
572         pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_HW:\t\t %d\n",
573                 test_bit(STATUS_SCAN_HW, &priv->status));
574         pos += scnprintf(buf + pos, bufsz - pos, "STATUS_POWER_PMI:\t %d\n",
575                 test_bit(STATUS_POWER_PMI, &priv->status));
576         pos += scnprintf(buf + pos, bufsz - pos, "STATUS_FW_ERROR:\t %d\n",
577                 test_bit(STATUS_FW_ERROR, &priv->status));
578         return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
579 }
580
581 static ssize_t iwl_dbgfs_interrupt_read(struct file *file,
582                                         char __user *user_buf,
583                                         size_t count, loff_t *ppos) {
584
585         struct iwl_priv *priv = file->private_data;
586         int pos = 0;
587         int cnt = 0;
588         char *buf;
589         int bufsz = 24 * 64; /* 24 items * 64 char per item */
590         ssize_t ret;
591
592         buf = kzalloc(bufsz, GFP_KERNEL);
593         if (!buf) {
594                 IWL_ERR(priv, "Can not allocate Buffer\n");
595                 return -ENOMEM;
596         }
597
598         pos += scnprintf(buf + pos, bufsz - pos,
599                         "Interrupt Statistics Report:\n");
600
601         pos += scnprintf(buf + pos, bufsz - pos, "HW Error:\t\t\t %u\n",
602                 priv->isr_stats.hw);
603         pos += scnprintf(buf + pos, bufsz - pos, "SW Error:\t\t\t %u\n",
604                 priv->isr_stats.sw);
605         if (priv->isr_stats.sw > 0) {
606                 pos += scnprintf(buf + pos, bufsz - pos,
607                         "\tLast Restarting Code:  0x%X\n",
608                         priv->isr_stats.sw_err);
609         }
610 #ifdef CONFIG_IWLWIFI_DEBUG
611         pos += scnprintf(buf + pos, bufsz - pos, "Frame transmitted:\t\t %u\n",
612                 priv->isr_stats.sch);
613         pos += scnprintf(buf + pos, bufsz - pos, "Alive interrupt:\t\t %u\n",
614                 priv->isr_stats.alive);
615 #endif
616         pos += scnprintf(buf + pos, bufsz - pos,
617                 "HW RF KILL switch toggled:\t %u\n",
618                 priv->isr_stats.rfkill);
619
620         pos += scnprintf(buf + pos, bufsz - pos, "CT KILL:\t\t\t %u\n",
621                 priv->isr_stats.ctkill);
622
623         pos += scnprintf(buf + pos, bufsz - pos, "Wakeup Interrupt:\t\t %u\n",
624                 priv->isr_stats.wakeup);
625
626         pos += scnprintf(buf + pos, bufsz - pos,
627                 "Rx command responses:\t\t %u\n",
628                 priv->isr_stats.rx);
629         for (cnt = 0; cnt < REPLY_MAX; cnt++) {
630                 if (priv->isr_stats.rx_handlers[cnt] > 0)
631                         pos += scnprintf(buf + pos, bufsz - pos,
632                                 "\tRx handler[%36s]:\t\t %u\n",
633                                 get_cmd_string(cnt),
634                                 priv->isr_stats.rx_handlers[cnt]);
635         }
636
637         pos += scnprintf(buf + pos, bufsz - pos, "Tx/FH interrupt:\t\t %u\n",
638                 priv->isr_stats.tx);
639
640         pos += scnprintf(buf + pos, bufsz - pos, "Unexpected INTA:\t\t %u\n",
641                 priv->isr_stats.unhandled);
642
643         ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
644         kfree(buf);
645         return ret;
646 }
647
648 static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
649                                          const char __user *user_buf,
650                                          size_t count, loff_t *ppos)
651 {
652         struct iwl_priv *priv = file->private_data;
653         char buf[8];
654         int buf_size;
655         u32 reset_flag;
656
657         memset(buf, 0, sizeof(buf));
658         buf_size = min(count, sizeof(buf) -  1);
659         if (copy_from_user(buf, user_buf, buf_size))
660                 return -EFAULT;
661         if (sscanf(buf, "%x", &reset_flag) != 1)
662                 return -EFAULT;
663         if (reset_flag == 0)
664                 iwl_clear_isr_stats(priv);
665
666         return count;
667 }
668
669 static ssize_t iwl_dbgfs_qos_read(struct file *file, char __user *user_buf,
670                                        size_t count, loff_t *ppos)
671 {
672         struct iwl_priv *priv = file->private_data;
673         int pos = 0, i;
674         char buf[256];
675         const size_t bufsz = sizeof(buf);
676
677         for (i = 0; i < AC_NUM; i++) {
678                 pos += scnprintf(buf + pos, bufsz - pos,
679                         "\tcw_min\tcw_max\taifsn\ttxop\n");
680                 pos += scnprintf(buf + pos, bufsz - pos,
681                                 "AC[%d]\t%u\t%u\t%u\t%u\n", i,
682                                 priv->qos_data.def_qos_parm.ac[i].cw_min,
683                                 priv->qos_data.def_qos_parm.ac[i].cw_max,
684                                 priv->qos_data.def_qos_parm.ac[i].aifsn,
685                                 priv->qos_data.def_qos_parm.ac[i].edca_txop);
686         }
687         return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
688 }
689
690 static ssize_t iwl_dbgfs_led_read(struct file *file, char __user *user_buf,
691                                   size_t count, loff_t *ppos)
692 {
693         struct iwl_priv *priv = file->private_data;
694         int pos = 0;
695         char buf[256];
696         const size_t bufsz = sizeof(buf);
697
698         pos += scnprintf(buf + pos, bufsz - pos,
699                          "allow blinking: %s\n",
700                          (priv->allow_blinking) ? "True" : "False");
701         if (priv->allow_blinking) {
702                 pos += scnprintf(buf + pos, bufsz - pos,
703                                  "Led blinking rate: %u\n",
704                                  priv->last_blink_rate);
705                 pos += scnprintf(buf + pos, bufsz - pos,
706                                  "Last blink time: %lu\n",
707                                  priv->last_blink_time);
708         }
709
710         return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
711 }
712
713 static ssize_t iwl_dbgfs_thermal_throttling_read(struct file *file,
714                                 char __user *user_buf,
715                                 size_t count, loff_t *ppos)
716 {
717         struct iwl_priv *priv = file->private_data;
718         struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
719         struct iwl_tt_restriction *restriction;
720         char buf[100];
721         int pos = 0;
722         const size_t bufsz = sizeof(buf);
723
724         pos += scnprintf(buf + pos, bufsz - pos,
725                         "Thermal Throttling Mode: %s\n",
726                         tt->advanced_tt ? "Advance" : "Legacy");
727         pos += scnprintf(buf + pos, bufsz - pos,
728                         "Thermal Throttling State: %d\n",
729                         tt->state);
730         if (tt->advanced_tt) {
731                 restriction = tt->restriction + tt->state;
732                 pos += scnprintf(buf + pos, bufsz - pos,
733                                 "Tx mode: %d\n",
734                                 restriction->tx_stream);
735                 pos += scnprintf(buf + pos, bufsz - pos,
736                                 "Rx mode: %d\n",
737                                 restriction->rx_stream);
738                 pos += scnprintf(buf + pos, bufsz - pos,
739                                 "HT mode: %d\n",
740                                 restriction->is_ht);
741         }
742         return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
743 }
744
745 static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
746                                          const char __user *user_buf,
747                                          size_t count, loff_t *ppos)
748 {
749         struct iwl_priv *priv = file->private_data;
750         char buf[8];
751         int buf_size;
752         int ht40;
753
754         memset(buf, 0, sizeof(buf));
755         buf_size = min(count, sizeof(buf) -  1);
756         if (copy_from_user(buf, user_buf, buf_size))
757                 return -EFAULT;
758         if (sscanf(buf, "%d", &ht40) != 1)
759                 return -EFAULT;
760         if (!iwl_is_associated(priv))
761                 priv->disable_ht40 = ht40 ? true : false;
762         else {
763                 IWL_ERR(priv, "Sta associated with AP - "
764                         "Change to 40MHz channel support is not allowed\n");
765                 return -EINVAL;
766         }
767
768         return count;
769 }
770
771 static ssize_t iwl_dbgfs_disable_ht40_read(struct file *file,
772                                          char __user *user_buf,
773                                          size_t count, loff_t *ppos)
774 {
775         struct iwl_priv *priv = file->private_data;
776         char buf[100];
777         int pos = 0;
778         const size_t bufsz = sizeof(buf);
779
780         pos += scnprintf(buf + pos, bufsz - pos,
781                         "11n 40MHz Mode: %s\n",
782                         priv->disable_ht40 ? "Disabled" : "Enabled");
783         return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
784 }
785
786 static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
787                                                     const char __user *user_buf,
788                                                     size_t count, loff_t *ppos)
789 {
790         struct iwl_priv *priv = file->private_data;
791         char buf[8];
792         int buf_size;
793         int value;
794
795         memset(buf, 0, sizeof(buf));
796         buf_size = min(count, sizeof(buf) -  1);
797         if (copy_from_user(buf, user_buf, buf_size))
798                 return -EFAULT;
799
800         if (sscanf(buf, "%d", &value) != 1)
801                 return -EINVAL;
802
803         /*
804          * Our users expect 0 to be "CAM", but 0 isn't actually
805          * valid here. However, let's not confuse them and present
806          * IWL_POWER_INDEX_1 as "1", not "0".
807          */
808         if (value == 0)
809                 return -EINVAL;
810         else if (value > 0)
811                 value -= 1;
812
813         if (value != -1 && (value < 0 || value >= IWL_POWER_NUM))
814                 return -EINVAL;
815
816         if (!iwl_is_ready_rf(priv))
817                 return -EAGAIN;
818
819         priv->power_data.debug_sleep_level_override = value;
820
821         mutex_lock(&priv->mutex);
822         iwl_power_update_mode(priv, true);
823         mutex_unlock(&priv->mutex);
824
825         return count;
826 }
827
828 static ssize_t iwl_dbgfs_sleep_level_override_read(struct file *file,
829                                                    char __user *user_buf,
830                                                    size_t count, loff_t *ppos)
831 {
832         struct iwl_priv *priv = file->private_data;
833         char buf[10];
834         int pos, value;
835         const size_t bufsz = sizeof(buf);
836
837         /* see the write function */
838         value = priv->power_data.debug_sleep_level_override;
839         if (value >= 0)
840                 value += 1;
841
842         pos = scnprintf(buf, bufsz, "%d\n", value);
843         return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
844 }
845
846 static ssize_t iwl_dbgfs_current_sleep_command_read(struct file *file,
847                                                     char __user *user_buf,
848                                                     size_t count, loff_t *ppos)
849 {
850         struct iwl_priv *priv = file->private_data;
851         char buf[200];
852         int pos = 0, i;
853         const size_t bufsz = sizeof(buf);
854         struct iwl_powertable_cmd *cmd = &priv->power_data.sleep_cmd;
855
856         pos += scnprintf(buf + pos, bufsz - pos,
857                          "flags: %#.2x\n", le16_to_cpu(cmd->flags));
858         pos += scnprintf(buf + pos, bufsz - pos,
859                          "RX/TX timeout: %d/%d usec\n",
860                          le32_to_cpu(cmd->rx_data_timeout),
861                          le32_to_cpu(cmd->tx_data_timeout));
862         for (i = 0; i < IWL_POWER_VEC_SIZE; i++)
863                 pos += scnprintf(buf + pos, bufsz - pos,
864                                  "sleep_interval[%d]: %d\n", i,
865                                  le32_to_cpu(cmd->sleep_interval[i]));
866
867         return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
868 }
869
870 DEBUGFS_READ_WRITE_FILE_OPS(sram);
871 DEBUGFS_READ_WRITE_FILE_OPS(log_event);
872 DEBUGFS_READ_FILE_OPS(nvm);
873 DEBUGFS_READ_FILE_OPS(stations);
874 DEBUGFS_READ_FILE_OPS(channels);
875 DEBUGFS_READ_FILE_OPS(status);
876 DEBUGFS_READ_WRITE_FILE_OPS(interrupt);
877 DEBUGFS_READ_FILE_OPS(qos);
878 DEBUGFS_READ_FILE_OPS(led);
879 DEBUGFS_READ_FILE_OPS(thermal_throttling);
880 DEBUGFS_READ_WRITE_FILE_OPS(disable_ht40);
881 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
882 DEBUGFS_READ_FILE_OPS(current_sleep_command);
883
884 static ssize_t iwl_dbgfs_traffic_log_read(struct file *file,
885                                          char __user *user_buf,
886                                          size_t count, loff_t *ppos)
887 {
888         struct iwl_priv *priv = file->private_data;
889         int pos = 0, ofs = 0;
890         int cnt = 0, entry;
891         struct iwl_tx_queue *txq;
892         struct iwl_queue *q;
893         struct iwl_rx_queue *rxq = &priv->rxq;
894         char *buf;
895         int bufsz = ((IWL_TRAFFIC_ENTRIES * IWL_TRAFFIC_ENTRY_SIZE * 64) * 2) +
896                 (priv->cfg->num_of_queues * 32 * 8) + 400;
897         const u8 *ptr;
898         ssize_t ret;
899
900         if (!priv->txq) {
901                 IWL_ERR(priv, "txq not ready\n");
902                 return -EAGAIN;
903         }
904         buf = kzalloc(bufsz, GFP_KERNEL);
905         if (!buf) {
906                 IWL_ERR(priv, "Can not allocate buffer\n");
907                 return -ENOMEM;
908         }
909         pos += scnprintf(buf + pos, bufsz - pos, "Tx Queue\n");
910         for (cnt = 0; cnt < priv->hw_params.max_txq_num; cnt++) {
911                 txq = &priv->txq[cnt];
912                 q = &txq->q;
913                 pos += scnprintf(buf + pos, bufsz - pos,
914                                 "q[%d]: read_ptr: %u, write_ptr: %u\n",
915                                 cnt, q->read_ptr, q->write_ptr);
916         }
917         if (priv->tx_traffic && (iwl_debug_level & IWL_DL_TX)) {
918                 ptr = priv->tx_traffic;
919                 pos += scnprintf(buf + pos, bufsz - pos,
920                                 "Tx Traffic idx: %u\n", priv->tx_traffic_idx);
921                 for (cnt = 0, ofs = 0; cnt < IWL_TRAFFIC_ENTRIES; cnt++) {
922                         for (entry = 0; entry < IWL_TRAFFIC_ENTRY_SIZE / 16;
923                              entry++,  ofs += 16) {
924                                 pos += scnprintf(buf + pos, bufsz - pos,
925                                                 "0x%.4x ", ofs);
926                                 hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
927                                                    buf + pos, bufsz - pos, 0);
928                                 pos += strlen(buf + pos);
929                                 if (bufsz - pos > 0)
930                                         buf[pos++] = '\n';
931                         }
932                 }
933         }
934
935         pos += scnprintf(buf + pos, bufsz - pos, "Rx Queue\n");
936         pos += scnprintf(buf + pos, bufsz - pos,
937                         "read: %u, write: %u\n",
938                          rxq->read, rxq->write);
939
940         if (priv->rx_traffic && (iwl_debug_level & IWL_DL_RX)) {
941                 ptr = priv->rx_traffic;
942                 pos += scnprintf(buf + pos, bufsz - pos,
943                                 "Rx Traffic idx: %u\n", priv->rx_traffic_idx);
944                 for (cnt = 0, ofs = 0; cnt < IWL_TRAFFIC_ENTRIES; cnt++) {
945                         for (entry = 0; entry < IWL_TRAFFIC_ENTRY_SIZE / 16;
946                              entry++,  ofs += 16) {
947                                 pos += scnprintf(buf + pos, bufsz - pos,
948                                                 "0x%.4x ", ofs);
949                                 hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
950                                                    buf + pos, bufsz - pos, 0);
951                                 pos += strlen(buf + pos);
952                                 if (bufsz - pos > 0)
953                                         buf[pos++] = '\n';
954                         }
955                 }
956         }
957
958         ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
959         kfree(buf);
960         return ret;
961 }
962
963 static ssize_t iwl_dbgfs_traffic_log_write(struct file *file,
964                                          const char __user *user_buf,
965                                          size_t count, loff_t *ppos)
966 {
967         struct iwl_priv *priv = file->private_data;
968         char buf[8];
969         int buf_size;
970         int traffic_log;
971
972         memset(buf, 0, sizeof(buf));
973         buf_size = min(count, sizeof(buf) -  1);
974         if (copy_from_user(buf, user_buf, buf_size))
975                 return -EFAULT;
976         if (sscanf(buf, "%d", &traffic_log) != 1)
977                 return -EFAULT;
978         if (traffic_log == 0)
979                 iwl_reset_traffic_log(priv);
980
981         return count;
982 }
983
984 static ssize_t iwl_dbgfs_tx_queue_read(struct file *file,
985                                                 char __user *user_buf,
986                                                 size_t count, loff_t *ppos) {
987
988         struct iwl_priv *priv = file->private_data;
989         struct iwl_tx_queue *txq;
990         struct iwl_queue *q;
991         char *buf;
992         int pos = 0;
993         int cnt;
994         int ret;
995         const size_t bufsz = sizeof(char) * 64 * priv->cfg->num_of_queues;
996
997         if (!priv->txq) {
998                 IWL_ERR(priv, "txq not ready\n");
999                 return -EAGAIN;
1000         }
1001         buf = kzalloc(bufsz, GFP_KERNEL);
1002         if (!buf)
1003                 return -ENOMEM;
1004
1005         for (cnt = 0; cnt < priv->hw_params.max_txq_num; cnt++) {
1006                 txq = &priv->txq[cnt];
1007                 q = &txq->q;
1008                 pos += scnprintf(buf + pos, bufsz - pos,
1009                                 "hwq %.2d: read=%u write=%u stop=%d"
1010                                 " swq_id=%#.2x (ac %d/hwq %d)\n",
1011                                 cnt, q->read_ptr, q->write_ptr,
1012                                 !!test_bit(cnt, priv->queue_stopped),
1013                                 txq->swq_id,
1014                                 txq->swq_id & 0x80 ? txq->swq_id & 3 :
1015                                 txq->swq_id,
1016                                 txq->swq_id & 0x80 ? (txq->swq_id >> 2) &
1017                                 0x1f : txq->swq_id);
1018                 if (cnt >= 4)
1019                         continue;
1020                 /* for the ACs, display the stop count too */
1021                 pos += scnprintf(buf + pos, bufsz - pos,
1022                                 "        stop-count: %d\n",
1023                                 atomic_read(&priv->queue_stop_count[cnt]));
1024         }
1025         ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1026         kfree(buf);
1027         return ret;
1028 }
1029
1030 static ssize_t iwl_dbgfs_rx_queue_read(struct file *file,
1031                                                 char __user *user_buf,
1032                                                 size_t count, loff_t *ppos) {
1033
1034         struct iwl_priv *priv = file->private_data;
1035         struct iwl_rx_queue *rxq = &priv->rxq;
1036         char buf[256];
1037         int pos = 0;
1038         const size_t bufsz = sizeof(buf);
1039
1040         pos += scnprintf(buf + pos, bufsz - pos, "read: %u\n",
1041                                                 rxq->read);
1042         pos += scnprintf(buf + pos, bufsz - pos, "write: %u\n",
1043                                                 rxq->write);
1044         pos += scnprintf(buf + pos, bufsz - pos, "free_count: %u\n",
1045                                                 rxq->free_count);
1046         pos += scnprintf(buf + pos, bufsz - pos, "closed_rb_num: %u\n",
1047                          le16_to_cpu(rxq->rb_stts->closed_rb_num) &  0x0FFF);
1048         return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1049 }
1050
1051 static ssize_t iwl_dbgfs_ucode_rx_stats_read(struct file *file,
1052                                         char __user *user_buf,
1053                                         size_t count, loff_t *ppos)
1054 {
1055         struct iwl_priv *priv = file->private_data;
1056         return priv->cfg->ops->lib->debugfs_ops.rx_stats_read(file,
1057                         user_buf, count, ppos);
1058 }
1059
1060 static ssize_t iwl_dbgfs_ucode_tx_stats_read(struct file *file,
1061                                         char __user *user_buf,
1062                                         size_t count, loff_t *ppos)
1063 {
1064         struct iwl_priv *priv = file->private_data;
1065         return priv->cfg->ops->lib->debugfs_ops.tx_stats_read(file,
1066                         user_buf, count, ppos);
1067 }
1068
1069 static ssize_t iwl_dbgfs_ucode_general_stats_read(struct file *file,
1070                                         char __user *user_buf,
1071                                         size_t count, loff_t *ppos)
1072 {
1073         struct iwl_priv *priv = file->private_data;
1074         return priv->cfg->ops->lib->debugfs_ops.general_stats_read(file,
1075                         user_buf, count, ppos);
1076 }
1077
1078 static ssize_t iwl_dbgfs_sensitivity_read(struct file *file,
1079                                         char __user *user_buf,
1080                                         size_t count, loff_t *ppos) {
1081
1082         struct iwl_priv *priv = file->private_data;
1083         int pos = 0;
1084         int cnt = 0;
1085         char *buf;
1086         int bufsz = sizeof(struct iwl_sensitivity_data) * 4 + 100;
1087         ssize_t ret;
1088         struct iwl_sensitivity_data *data;
1089
1090         data = &priv->sensitivity_data;
1091         buf = kzalloc(bufsz, GFP_KERNEL);
1092         if (!buf) {
1093                 IWL_ERR(priv, "Can not allocate Buffer\n");
1094                 return -ENOMEM;
1095         }
1096
1097         pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm:\t\t\t %u\n",
1098                         data->auto_corr_ofdm);
1099         pos += scnprintf(buf + pos, bufsz - pos,
1100                         "auto_corr_ofdm_mrc:\t\t %u\n",
1101                         data->auto_corr_ofdm_mrc);
1102         pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_x1:\t\t %u\n",
1103                         data->auto_corr_ofdm_x1);
1104         pos += scnprintf(buf + pos, bufsz - pos,
1105                         "auto_corr_ofdm_mrc_x1:\t\t %u\n",
1106                         data->auto_corr_ofdm_mrc_x1);
1107         pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck:\t\t\t %u\n",
1108                         data->auto_corr_cck);
1109         pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck_mrc:\t\t %u\n",
1110                         data->auto_corr_cck_mrc);
1111         pos += scnprintf(buf + pos, bufsz - pos,
1112                         "last_bad_plcp_cnt_ofdm:\t\t %u\n",
1113                         data->last_bad_plcp_cnt_ofdm);
1114         pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_ofdm:\t\t %u\n",
1115                         data->last_fa_cnt_ofdm);
1116         pos += scnprintf(buf + pos, bufsz - pos,
1117                         "last_bad_plcp_cnt_cck:\t\t %u\n",
1118                         data->last_bad_plcp_cnt_cck);
1119         pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_cck:\t\t %u\n",
1120                         data->last_fa_cnt_cck);
1121         pos += scnprintf(buf + pos, bufsz - pos, "nrg_curr_state:\t\t\t %u\n",
1122                         data->nrg_curr_state);
1123         pos += scnprintf(buf + pos, bufsz - pos, "nrg_prev_state:\t\t\t %u\n",
1124                         data->nrg_prev_state);
1125         pos += scnprintf(buf + pos, bufsz - pos, "nrg_value:\t\t\t");
1126         for (cnt = 0; cnt < 10; cnt++) {
1127                 pos += scnprintf(buf + pos, bufsz - pos, " %u",
1128                                 data->nrg_value[cnt]);
1129         }
1130         pos += scnprintf(buf + pos, bufsz - pos, "\n");
1131         pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_rssi:\t\t");
1132         for (cnt = 0; cnt < NRG_NUM_PREV_STAT_L; cnt++) {
1133                 pos += scnprintf(buf + pos, bufsz - pos, " %u",
1134                                 data->nrg_silence_rssi[cnt]);
1135         }
1136         pos += scnprintf(buf + pos, bufsz - pos, "\n");
1137         pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_ref:\t\t %u\n",
1138                         data->nrg_silence_ref);
1139         pos += scnprintf(buf + pos, bufsz - pos, "nrg_energy_idx:\t\t\t %u\n",
1140                         data->nrg_energy_idx);
1141         pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_idx:\t\t %u\n",
1142                         data->nrg_silence_idx);
1143         pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_cck:\t\t\t %u\n",
1144                         data->nrg_th_cck);
1145         pos += scnprintf(buf + pos, bufsz - pos,
1146                         "nrg_auto_corr_silence_diff:\t %u\n",
1147                         data->nrg_auto_corr_silence_diff);
1148         pos += scnprintf(buf + pos, bufsz - pos, "num_in_cck_no_fa:\t\t %u\n",
1149                         data->num_in_cck_no_fa);
1150         pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_ofdm:\t\t\t %u\n",
1151                         data->nrg_th_ofdm);
1152
1153         ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1154         kfree(buf);
1155         return ret;
1156 }
1157
1158
1159 static ssize_t iwl_dbgfs_chain_noise_read(struct file *file,
1160                                         char __user *user_buf,
1161                                         size_t count, loff_t *ppos) {
1162
1163         struct iwl_priv *priv = file->private_data;
1164         int pos = 0;
1165         int cnt = 0;
1166         char *buf;
1167         int bufsz = sizeof(struct iwl_chain_noise_data) * 4 + 100;
1168         ssize_t ret;
1169         struct iwl_chain_noise_data *data;
1170
1171         data = &priv->chain_noise_data;
1172         buf = kzalloc(bufsz, GFP_KERNEL);
1173         if (!buf) {
1174                 IWL_ERR(priv, "Can not allocate Buffer\n");
1175                 return -ENOMEM;
1176         }
1177
1178         pos += scnprintf(buf + pos, bufsz - pos, "active_chains:\t\t\t %u\n",
1179                         data->active_chains);
1180         pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_a:\t\t\t %u\n",
1181                         data->chain_noise_a);
1182         pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_b:\t\t\t %u\n",
1183                         data->chain_noise_b);
1184         pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_c:\t\t\t %u\n",
1185                         data->chain_noise_c);
1186         pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_a:\t\t\t %u\n",
1187                         data->chain_signal_a);
1188         pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_b:\t\t\t %u\n",
1189                         data->chain_signal_b);
1190         pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_c:\t\t\t %u\n",
1191                         data->chain_signal_c);
1192         pos += scnprintf(buf + pos, bufsz - pos, "beacon_count:\t\t\t %u\n",
1193                         data->beacon_count);
1194
1195         pos += scnprintf(buf + pos, bufsz - pos, "disconn_array:\t\t\t");
1196         for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
1197                 pos += scnprintf(buf + pos, bufsz - pos, " %u",
1198                                 data->disconn_array[cnt]);
1199         }
1200         pos += scnprintf(buf + pos, bufsz - pos, "\n");
1201         pos += scnprintf(buf + pos, bufsz - pos, "delta_gain_code:\t\t");
1202         for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
1203                 pos += scnprintf(buf + pos, bufsz - pos, " %u",
1204                                 data->delta_gain_code[cnt]);
1205         }
1206         pos += scnprintf(buf + pos, bufsz - pos, "\n");
1207         pos += scnprintf(buf + pos, bufsz - pos, "radio_write:\t\t\t %u\n",
1208                         data->radio_write);
1209         pos += scnprintf(buf + pos, bufsz - pos, "state:\t\t\t\t %u\n",
1210                         data->state);
1211
1212         ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1213         kfree(buf);
1214         return ret;
1215 }
1216
1217 static ssize_t iwl_dbgfs_chain_tx_power_read(struct file *file,
1218                                         char __user *user_buf,
1219                                         size_t count, loff_t *ppos) {
1220
1221         struct iwl_priv *priv = file->private_data;
1222         char buf[128];
1223         int pos = 0;
1224         const size_t bufsz = sizeof(buf);
1225         struct statistics_tx *tx;
1226
1227         if (!iwl_is_alive(priv))
1228                 pos += scnprintf(buf + pos, bufsz - pos, "N/A\n");
1229         else {
1230                 tx = &priv->statistics.tx;
1231                 if (tx->tx_power.ant_a ||
1232                     tx->tx_power.ant_b ||
1233                     tx->tx_power.ant_c) {
1234                         pos += scnprintf(buf + pos, bufsz - pos,
1235                                 "tx power: (1/2 dB step)\n");
1236                         if ((priv->cfg->valid_tx_ant & ANT_A) &&
1237                             tx->tx_power.ant_a)
1238                                 pos += scnprintf(buf + pos, bufsz - pos,
1239                                                 "\tantenna A: 0x%X\n",
1240                                                 tx->tx_power.ant_a);
1241                         if ((priv->cfg->valid_tx_ant & ANT_B) &&
1242                             tx->tx_power.ant_b)
1243                                 pos += scnprintf(buf + pos, bufsz - pos,
1244                                                 "\tantenna B: 0x%X\n",
1245                                                 tx->tx_power.ant_b);
1246                         if ((priv->cfg->valid_tx_ant & ANT_C) &&
1247                             tx->tx_power.ant_c)
1248                                 pos += scnprintf(buf + pos, bufsz - pos,
1249                                                 "\tantenna C: 0x%X\n",
1250                                                 tx->tx_power.ant_c);
1251                 } else
1252                         pos += scnprintf(buf + pos, bufsz - pos, "N/A\n");
1253         }
1254         return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1255 }
1256
1257 static ssize_t iwl_dbgfs_power_save_status_read(struct file *file,
1258                                                     char __user *user_buf,
1259                                                     size_t count, loff_t *ppos)
1260 {
1261         struct iwl_priv *priv = file->private_data;
1262         char buf[60];
1263         int pos = 0;
1264         const size_t bufsz = sizeof(buf);
1265         u32 pwrsave_status;
1266
1267         pwrsave_status = iwl_read32(priv, CSR_GP_CNTRL) &
1268                         CSR_GP_REG_POWER_SAVE_STATUS_MSK;
1269
1270         pos += scnprintf(buf + pos, bufsz - pos, "Power Save Status: ");
1271         pos += scnprintf(buf + pos, bufsz - pos, "%s\n",
1272                 (pwrsave_status == CSR_GP_REG_NO_POWER_SAVE) ? "none" :
1273                 (pwrsave_status == CSR_GP_REG_MAC_POWER_SAVE) ? "MAC" :
1274                 (pwrsave_status == CSR_GP_REG_PHY_POWER_SAVE) ? "PHY" :
1275                 "error");
1276
1277         return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1278 }
1279
1280 static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
1281                                          const char __user *user_buf,
1282                                          size_t count, loff_t *ppos)
1283 {
1284         struct iwl_priv *priv = file->private_data;
1285         char buf[8];
1286         int buf_size;
1287         int clear;
1288
1289         memset(buf, 0, sizeof(buf));
1290         buf_size = min(count, sizeof(buf) -  1);
1291         if (copy_from_user(buf, user_buf, buf_size))
1292                 return -EFAULT;
1293         if (sscanf(buf, "%d", &clear) != 1)
1294                 return -EFAULT;
1295
1296         /* make request to uCode to retrieve statistics information */
1297         mutex_lock(&priv->mutex);
1298         iwl_send_statistics_request(priv, CMD_SYNC, true);
1299         mutex_unlock(&priv->mutex);
1300
1301         return count;
1302 }
1303
1304 static ssize_t iwl_dbgfs_csr_write(struct file *file,
1305                                          const char __user *user_buf,
1306                                          size_t count, loff_t *ppos)
1307 {
1308         struct iwl_priv *priv = file->private_data;
1309         char buf[8];
1310         int buf_size;
1311         int csr;
1312
1313         memset(buf, 0, sizeof(buf));
1314         buf_size = min(count, sizeof(buf) -  1);
1315         if (copy_from_user(buf, user_buf, buf_size))
1316                 return -EFAULT;
1317         if (sscanf(buf, "%d", &csr) != 1)
1318                 return -EFAULT;
1319
1320         if (priv->cfg->ops->lib->dump_csr)
1321                 priv->cfg->ops->lib->dump_csr(priv);
1322
1323         return count;
1324 }
1325
1326 static ssize_t iwl_dbgfs_ucode_tracing_read(struct file *file,
1327                                         char __user *user_buf,
1328                                         size_t count, loff_t *ppos) {
1329
1330         struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1331         int pos = 0;
1332         char buf[128];
1333         const size_t bufsz = sizeof(buf);
1334
1335         pos += scnprintf(buf + pos, bufsz - pos, "ucode trace timer is %s\n",
1336                         priv->event_log.ucode_trace ? "On" : "Off");
1337         pos += scnprintf(buf + pos, bufsz - pos, "non_wraps_count:\t\t %u\n",
1338                         priv->event_log.non_wraps_count);
1339         pos += scnprintf(buf + pos, bufsz - pos, "wraps_once_count:\t\t %u\n",
1340                         priv->event_log.wraps_once_count);
1341         pos += scnprintf(buf + pos, bufsz - pos, "wraps_more_count:\t\t %u\n",
1342                         priv->event_log.wraps_more_count);
1343
1344         return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1345 }
1346
1347 static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
1348                                          const char __user *user_buf,
1349                                          size_t count, loff_t *ppos)
1350 {
1351         struct iwl_priv *priv = file->private_data;
1352         char buf[8];
1353         int buf_size;
1354         int trace;
1355
1356         memset(buf, 0, sizeof(buf));
1357         buf_size = min(count, sizeof(buf) -  1);
1358         if (copy_from_user(buf, user_buf, buf_size))
1359                 return -EFAULT;
1360         if (sscanf(buf, "%d", &trace) != 1)
1361                 return -EFAULT;
1362
1363         if (trace) {
1364                 priv->event_log.ucode_trace = true;
1365                 /* schedule the ucode timer to occur in UCODE_TRACE_PERIOD */
1366                 mod_timer(&priv->ucode_trace,
1367                         jiffies + msecs_to_jiffies(UCODE_TRACE_PERIOD));
1368         } else {
1369                 priv->event_log.ucode_trace = false;
1370                 del_timer_sync(&priv->ucode_trace);
1371         }
1372
1373         return count;
1374 }
1375
1376 static ssize_t iwl_dbgfs_rxon_flags_read(struct file *file,
1377                                          char __user *user_buf,
1378                                          size_t count, loff_t *ppos) {
1379
1380         struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1381         int len = 0;
1382         char buf[20];
1383
1384         len = sprintf(buf, "0x%04X\n", le32_to_cpu(priv->active_rxon.flags));
1385         return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1386 }
1387
1388 static ssize_t iwl_dbgfs_rxon_filter_flags_read(struct file *file,
1389                                                 char __user *user_buf,
1390                                                 size_t count, loff_t *ppos) {
1391
1392         struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1393         int len = 0;
1394         char buf[20];
1395
1396         len = sprintf(buf, "0x%04X\n",
1397                       le32_to_cpu(priv->active_rxon.filter_flags));
1398         return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1399 }
1400
1401 static ssize_t iwl_dbgfs_fh_reg_read(struct file *file,
1402                                          char __user *user_buf,
1403                                          size_t count, loff_t *ppos)
1404 {
1405         struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1406         char *buf;
1407         int pos = 0;
1408         ssize_t ret = -EFAULT;
1409
1410         if (priv->cfg->ops->lib->dump_fh) {
1411                 ret = pos = priv->cfg->ops->lib->dump_fh(priv, &buf, true);
1412                 if (buf) {
1413                         ret = simple_read_from_buffer(user_buf,
1414                                                       count, ppos, buf, pos);
1415                         kfree(buf);
1416                 }
1417         }
1418
1419         return ret;
1420 }
1421
1422 static ssize_t iwl_dbgfs_missed_beacon_read(struct file *file,
1423                                         char __user *user_buf,
1424                                         size_t count, loff_t *ppos) {
1425
1426         struct iwl_priv *priv = file->private_data;
1427         int pos = 0;
1428         char buf[12];
1429         const size_t bufsz = sizeof(buf);
1430
1431         pos += scnprintf(buf + pos, bufsz - pos, "%d\n",
1432                         priv->missed_beacon_threshold);
1433
1434         return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1435 }
1436
1437 static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
1438                                          const char __user *user_buf,
1439                                          size_t count, loff_t *ppos)
1440 {
1441         struct iwl_priv *priv = file->private_data;
1442         char buf[8];
1443         int buf_size;
1444         int missed;
1445
1446         memset(buf, 0, sizeof(buf));
1447         buf_size = min(count, sizeof(buf) -  1);
1448         if (copy_from_user(buf, user_buf, buf_size))
1449                 return -EFAULT;
1450         if (sscanf(buf, "%d", &missed) != 1)
1451                 return -EINVAL;
1452
1453         if (missed < IWL_MISSED_BEACON_THRESHOLD_MIN ||
1454             missed > IWL_MISSED_BEACON_THRESHOLD_MAX)
1455                 priv->missed_beacon_threshold =
1456                         IWL_MISSED_BEACON_THRESHOLD_DEF;
1457         else
1458                 priv->missed_beacon_threshold = missed;
1459
1460         return count;
1461 }
1462
1463 static ssize_t iwl_dbgfs_plcp_delta_read(struct file *file,
1464                                         char __user *user_buf,
1465                                         size_t count, loff_t *ppos) {
1466
1467         struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1468         int pos = 0;
1469         char buf[12];
1470         const size_t bufsz = sizeof(buf);
1471
1472         pos += scnprintf(buf + pos, bufsz - pos, "%u\n",
1473                         priv->cfg->plcp_delta_threshold);
1474
1475         return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1476 }
1477
1478 static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
1479                                         const char __user *user_buf,
1480                                         size_t count, loff_t *ppos) {
1481
1482         struct iwl_priv *priv = file->private_data;
1483         char buf[8];
1484         int buf_size;
1485         int plcp;
1486
1487         memset(buf, 0, sizeof(buf));
1488         buf_size = min(count, sizeof(buf) -  1);
1489         if (copy_from_user(buf, user_buf, buf_size))
1490                 return -EFAULT;
1491         if (sscanf(buf, "%d", &plcp) != 1)
1492                 return -EINVAL;
1493         if ((plcp <= IWL_MAX_PLCP_ERR_THRESHOLD_MIN) ||
1494                 (plcp > IWL_MAX_PLCP_ERR_THRESHOLD_MAX))
1495                 priv->cfg->plcp_delta_threshold =
1496                         IWL_MAX_PLCP_ERR_THRESHOLD_DEF;
1497         else
1498                 priv->cfg->plcp_delta_threshold = plcp;
1499         return count;
1500 }
1501
1502 static ssize_t iwl_dbgfs_force_reset_read(struct file *file,
1503                                         char __user *user_buf,
1504                                         size_t count, loff_t *ppos) {
1505
1506         struct iwl_priv *priv = file->private_data;
1507         int i, pos = 0;
1508         char buf[300];
1509         const size_t bufsz = sizeof(buf);
1510         struct iwl_force_reset *force_reset;
1511
1512         for (i = 0; i < IWL_MAX_FORCE_RESET; i++) {
1513                 force_reset = &priv->force_reset[i];
1514                 pos += scnprintf(buf + pos, bufsz - pos,
1515                                 "Force reset method %d\n", i);
1516                 pos += scnprintf(buf + pos, bufsz - pos,
1517                                 "\tnumber of reset request: %d\n",
1518                                 force_reset->reset_request_count);
1519                 pos += scnprintf(buf + pos, bufsz - pos,
1520                                 "\tnumber of reset request success: %d\n",
1521                                 force_reset->reset_success_count);
1522                 pos += scnprintf(buf + pos, bufsz - pos,
1523                                 "\tnumber of reset request reject: %d\n",
1524                                 force_reset->reset_reject_count);
1525                 pos += scnprintf(buf + pos, bufsz - pos,
1526                                 "\treset duration: %lu\n",
1527                                 force_reset->reset_duration);
1528         }
1529         return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1530 }
1531
1532 static ssize_t iwl_dbgfs_force_reset_write(struct file *file,
1533                                         const char __user *user_buf,
1534                                         size_t count, loff_t *ppos) {
1535
1536         struct iwl_priv *priv = file->private_data;
1537         char buf[8];
1538         int buf_size;
1539         int reset, ret;
1540
1541         memset(buf, 0, sizeof(buf));
1542         buf_size = min(count, sizeof(buf) -  1);
1543         if (copy_from_user(buf, user_buf, buf_size))
1544                 return -EFAULT;
1545         if (sscanf(buf, "%d", &reset) != 1)
1546                 return -EINVAL;
1547         switch (reset) {
1548         case IWL_RF_RESET:
1549         case IWL_FW_RESET:
1550                 ret = iwl_force_reset(priv, reset);
1551                 break;
1552         default:
1553                 return -EINVAL;
1554         }
1555         return ret ? ret : count;
1556 }
1557
1558 DEBUGFS_READ_FILE_OPS(rx_statistics);
1559 DEBUGFS_READ_FILE_OPS(tx_statistics);
1560 DEBUGFS_READ_WRITE_FILE_OPS(traffic_log);
1561 DEBUGFS_READ_FILE_OPS(rx_queue);
1562 DEBUGFS_READ_FILE_OPS(tx_queue);
1563 DEBUGFS_READ_FILE_OPS(ucode_rx_stats);
1564 DEBUGFS_READ_FILE_OPS(ucode_tx_stats);
1565 DEBUGFS_READ_FILE_OPS(ucode_general_stats);
1566 DEBUGFS_READ_FILE_OPS(sensitivity);
1567 DEBUGFS_READ_FILE_OPS(chain_noise);
1568 DEBUGFS_READ_FILE_OPS(chain_tx_power);
1569 DEBUGFS_READ_FILE_OPS(power_save_status);
1570 DEBUGFS_WRITE_FILE_OPS(clear_ucode_statistics);
1571 DEBUGFS_WRITE_FILE_OPS(clear_traffic_statistics);
1572 DEBUGFS_WRITE_FILE_OPS(csr);
1573 DEBUGFS_READ_WRITE_FILE_OPS(ucode_tracing);
1574 DEBUGFS_READ_FILE_OPS(fh_reg);
1575 DEBUGFS_READ_WRITE_FILE_OPS(missed_beacon);
1576 DEBUGFS_READ_WRITE_FILE_OPS(plcp_delta);
1577 DEBUGFS_READ_WRITE_FILE_OPS(force_reset);
1578 DEBUGFS_READ_FILE_OPS(rxon_flags);
1579 DEBUGFS_READ_FILE_OPS(rxon_filter_flags);
1580
1581 /*
1582  * Create the debugfs files and directories
1583  *
1584  */
1585 int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
1586 {
1587         struct dentry *phyd = priv->hw->wiphy->debugfsdir;
1588         struct dentry *dir_drv, *dir_data, *dir_rf, *dir_debug;
1589
1590         dir_drv = debugfs_create_dir(name, phyd);
1591         if (!dir_drv)
1592                 return -ENOMEM;
1593
1594         priv->debugfs_dir = dir_drv;
1595
1596         dir_data = debugfs_create_dir("data", dir_drv);
1597         if (!dir_data)
1598                 goto err;
1599         dir_rf = debugfs_create_dir("rf", dir_drv);
1600         if (!dir_rf)
1601                 goto err;
1602         dir_debug = debugfs_create_dir("debug", dir_drv);
1603         if (!dir_debug)
1604                 goto err;
1605
1606         DEBUGFS_ADD_FILE(nvm, dir_data, S_IRUSR);
1607         DEBUGFS_ADD_FILE(sram, dir_data, S_IWUSR | S_IRUSR);
1608         DEBUGFS_ADD_FILE(log_event, dir_data, S_IWUSR | S_IRUSR);
1609         DEBUGFS_ADD_FILE(stations, dir_data, S_IRUSR);
1610         DEBUGFS_ADD_FILE(channels, dir_data, S_IRUSR);
1611         DEBUGFS_ADD_FILE(status, dir_data, S_IRUSR);
1612         DEBUGFS_ADD_FILE(interrupt, dir_data, S_IWUSR | S_IRUSR);
1613         DEBUGFS_ADD_FILE(qos, dir_data, S_IRUSR);
1614         DEBUGFS_ADD_FILE(led, dir_data, S_IRUSR);
1615         if (!priv->cfg->broken_powersave) {
1616                 DEBUGFS_ADD_FILE(sleep_level_override, dir_data,
1617                                  S_IWUSR | S_IRUSR);
1618                 DEBUGFS_ADD_FILE(current_sleep_command, dir_data, S_IRUSR);
1619         }
1620         DEBUGFS_ADD_FILE(thermal_throttling, dir_data, S_IRUSR);
1621         DEBUGFS_ADD_FILE(disable_ht40, dir_data, S_IWUSR | S_IRUSR);
1622         DEBUGFS_ADD_FILE(rx_statistics, dir_debug, S_IRUSR);
1623         DEBUGFS_ADD_FILE(tx_statistics, dir_debug, S_IRUSR);
1624         DEBUGFS_ADD_FILE(traffic_log, dir_debug, S_IWUSR | S_IRUSR);
1625         DEBUGFS_ADD_FILE(rx_queue, dir_debug, S_IRUSR);
1626         DEBUGFS_ADD_FILE(tx_queue, dir_debug, S_IRUSR);
1627         DEBUGFS_ADD_FILE(chain_tx_power, dir_debug, S_IRUSR);
1628         DEBUGFS_ADD_FILE(power_save_status, dir_debug, S_IRUSR);
1629         DEBUGFS_ADD_FILE(clear_ucode_statistics, dir_debug, S_IWUSR);
1630         DEBUGFS_ADD_FILE(clear_traffic_statistics, dir_debug, S_IWUSR);
1631         DEBUGFS_ADD_FILE(csr, dir_debug, S_IWUSR);
1632         DEBUGFS_ADD_FILE(fh_reg, dir_debug, S_IRUSR);
1633         DEBUGFS_ADD_FILE(missed_beacon, dir_debug, S_IWUSR);
1634         DEBUGFS_ADD_FILE(plcp_delta, dir_debug, S_IWUSR | S_IRUSR);
1635         DEBUGFS_ADD_FILE(force_reset, dir_debug, S_IWUSR | S_IRUSR);
1636         DEBUGFS_ADD_FILE(ucode_rx_stats, dir_debug, S_IRUSR);
1637         DEBUGFS_ADD_FILE(ucode_tx_stats, dir_debug, S_IRUSR);
1638         DEBUGFS_ADD_FILE(ucode_general_stats, dir_debug, S_IRUSR);
1639
1640         if ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) != CSR_HW_REV_TYPE_3945) {
1641                 DEBUGFS_ADD_FILE(sensitivity, dir_debug, S_IRUSR);
1642                 DEBUGFS_ADD_FILE(chain_noise, dir_debug, S_IRUSR);
1643                 DEBUGFS_ADD_FILE(ucode_tracing, dir_debug, S_IWUSR | S_IRUSR);
1644         }
1645         DEBUGFS_ADD_FILE(rxon_flags, dir_debug, S_IWUSR);
1646         DEBUGFS_ADD_FILE(rxon_filter_flags, dir_debug, S_IWUSR);
1647         DEBUGFS_ADD_BOOL(disable_sensitivity, dir_rf, &priv->disable_sens_cal);
1648         DEBUGFS_ADD_BOOL(disable_chain_noise, dir_rf,
1649                          &priv->disable_chain_noise_cal);
1650         if (priv->cfg->tx_power_by_driver)
1651                 DEBUGFS_ADD_BOOL(disable_tx_power, dir_rf,
1652                                 &priv->disable_tx_power_cal);
1653         return 0;
1654
1655 err:
1656         IWL_ERR(priv, "Can't create the debugfs directory\n");
1657         iwl_dbgfs_unregister(priv);
1658         return -ENOMEM;
1659 }
1660 EXPORT_SYMBOL(iwl_dbgfs_register);
1661
1662 /**
1663  * Remove the debugfs files and directories
1664  *
1665  */
1666 void iwl_dbgfs_unregister(struct iwl_priv *priv)
1667 {
1668         if (!priv->debugfs_dir)
1669                 return;
1670
1671         debugfs_remove_recursive(priv->debugfs_dir);
1672         priv->debugfs_dir = NULL;
1673 }
1674 EXPORT_SYMBOL(iwl_dbgfs_unregister);
1675
1676
1677