Merge branch 'x86-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[pandora-kernel.git] / drivers / net / wireless / wl12xx / debugfs.c
1 /*
2  * This file is part of wl1271
3  *
4  * Copyright (C) 2009 Nokia Corporation
5  *
6  * Contact: Luciano Coelho <luciano.coelho@nokia.com>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * version 2 as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA
21  *
22  */
23
24 #include "debugfs.h"
25
26 #include <linux/skbuff.h>
27 #include <linux/slab.h>
28
29 #include "wl12xx.h"
30 #include "acx.h"
31 #include "ps.h"
32 #include "io.h"
33
34 /* ms */
35 #define WL1271_DEBUGFS_STATS_LIFETIME 1000
36
37 /* debugfs macros idea from mac80211 */
38 #define DEBUGFS_FORMAT_BUFFER_SIZE 100
39 static int wl1271_format_buffer(char __user *userbuf, size_t count,
40                                     loff_t *ppos, char *fmt, ...)
41 {
42         va_list args;
43         char buf[DEBUGFS_FORMAT_BUFFER_SIZE];
44         int res;
45
46         va_start(args, fmt);
47         res = vscnprintf(buf, sizeof(buf), fmt, args);
48         va_end(args);
49
50         return simple_read_from_buffer(userbuf, count, ppos, buf, res);
51 }
52
53 #define DEBUGFS_READONLY_FILE(name, fmt, value...)                      \
54 static ssize_t name## _read(struct file *file, char __user *userbuf,    \
55                             size_t count, loff_t *ppos)                 \
56 {                                                                       \
57         struct wl1271 *wl = file->private_data;                         \
58         return wl1271_format_buffer(userbuf, count, ppos,               \
59                                     fmt "\n", ##value);                 \
60 }                                                                       \
61                                                                         \
62 static const struct file_operations name## _ops = {                     \
63         .read = name## _read,                                           \
64         .open = wl1271_open_file_generic,                               \
65         .llseek = generic_file_llseek,                                  \
66 };
67
68 #define DEBUGFS_ADD(name, parent)                                       \
69         entry = debugfs_create_file(#name, 0400, parent,                \
70                                     wl, &name## _ops);                  \
71         if (!entry || IS_ERR(entry))                                    \
72                 goto err;                                               \
73
74 #define DEBUGFS_FWSTATS_FILE(sub, name, fmt)                            \
75 static ssize_t sub## _ ##name## _read(struct file *file,                \
76                                       char __user *userbuf,             \
77                                       size_t count, loff_t *ppos)       \
78 {                                                                       \
79         struct wl1271 *wl = file->private_data;                         \
80                                                                         \
81         wl1271_debugfs_update_stats(wl);                                \
82                                                                         \
83         return wl1271_format_buffer(userbuf, count, ppos, fmt "\n",     \
84                                     wl->stats.fw_stats->sub.name);      \
85 }                                                                       \
86                                                                         \
87 static const struct file_operations sub## _ ##name## _ops = {           \
88         .read = sub## _ ##name## _read,                                 \
89         .open = wl1271_open_file_generic,                               \
90         .llseek = generic_file_llseek,                                  \
91 };
92
93 #define DEBUGFS_FWSTATS_ADD(sub, name)                          \
94         DEBUGFS_ADD(sub## _ ##name, stats)
95
96 static void wl1271_debugfs_update_stats(struct wl1271 *wl)
97 {
98         int ret;
99
100         mutex_lock(&wl->mutex);
101
102         ret = wl1271_ps_elp_wakeup(wl);
103         if (ret < 0)
104                 goto out;
105
106         if (wl->state == WL1271_STATE_ON &&
107             time_after(jiffies, wl->stats.fw_stats_update +
108                        msecs_to_jiffies(WL1271_DEBUGFS_STATS_LIFETIME))) {
109                 wl1271_acx_statistics(wl, wl->stats.fw_stats);
110                 wl->stats.fw_stats_update = jiffies;
111         }
112
113         wl1271_ps_elp_sleep(wl);
114
115 out:
116         mutex_unlock(&wl->mutex);
117 }
118
119 static int wl1271_open_file_generic(struct inode *inode, struct file *file)
120 {
121         file->private_data = inode->i_private;
122         return 0;
123 }
124
125 DEBUGFS_FWSTATS_FILE(tx, internal_desc_overflow, "%u");
126
127 DEBUGFS_FWSTATS_FILE(rx, out_of_mem, "%u");
128 DEBUGFS_FWSTATS_FILE(rx, hdr_overflow, "%u");
129 DEBUGFS_FWSTATS_FILE(rx, hw_stuck, "%u");
130 DEBUGFS_FWSTATS_FILE(rx, dropped, "%u");
131 DEBUGFS_FWSTATS_FILE(rx, fcs_err, "%u");
132 DEBUGFS_FWSTATS_FILE(rx, xfr_hint_trig, "%u");
133 DEBUGFS_FWSTATS_FILE(rx, path_reset, "%u");
134 DEBUGFS_FWSTATS_FILE(rx, reset_counter, "%u");
135
136 DEBUGFS_FWSTATS_FILE(dma, rx_requested, "%u");
137 DEBUGFS_FWSTATS_FILE(dma, rx_errors, "%u");
138 DEBUGFS_FWSTATS_FILE(dma, tx_requested, "%u");
139 DEBUGFS_FWSTATS_FILE(dma, tx_errors, "%u");
140
141 DEBUGFS_FWSTATS_FILE(isr, cmd_cmplt, "%u");
142 DEBUGFS_FWSTATS_FILE(isr, fiqs, "%u");
143 DEBUGFS_FWSTATS_FILE(isr, rx_headers, "%u");
144 DEBUGFS_FWSTATS_FILE(isr, rx_mem_overflow, "%u");
145 DEBUGFS_FWSTATS_FILE(isr, rx_rdys, "%u");
146 DEBUGFS_FWSTATS_FILE(isr, irqs, "%u");
147 DEBUGFS_FWSTATS_FILE(isr, tx_procs, "%u");
148 DEBUGFS_FWSTATS_FILE(isr, decrypt_done, "%u");
149 DEBUGFS_FWSTATS_FILE(isr, dma0_done, "%u");
150 DEBUGFS_FWSTATS_FILE(isr, dma1_done, "%u");
151 DEBUGFS_FWSTATS_FILE(isr, tx_exch_complete, "%u");
152 DEBUGFS_FWSTATS_FILE(isr, commands, "%u");
153 DEBUGFS_FWSTATS_FILE(isr, rx_procs, "%u");
154 DEBUGFS_FWSTATS_FILE(isr, hw_pm_mode_changes, "%u");
155 DEBUGFS_FWSTATS_FILE(isr, host_acknowledges, "%u");
156 DEBUGFS_FWSTATS_FILE(isr, pci_pm, "%u");
157 DEBUGFS_FWSTATS_FILE(isr, wakeups, "%u");
158 DEBUGFS_FWSTATS_FILE(isr, low_rssi, "%u");
159
160 DEBUGFS_FWSTATS_FILE(wep, addr_key_count, "%u");
161 DEBUGFS_FWSTATS_FILE(wep, default_key_count, "%u");
162 /* skipping wep.reserved */
163 DEBUGFS_FWSTATS_FILE(wep, key_not_found, "%u");
164 DEBUGFS_FWSTATS_FILE(wep, decrypt_fail, "%u");
165 DEBUGFS_FWSTATS_FILE(wep, packets, "%u");
166 DEBUGFS_FWSTATS_FILE(wep, interrupt, "%u");
167
168 DEBUGFS_FWSTATS_FILE(pwr, ps_enter, "%u");
169 DEBUGFS_FWSTATS_FILE(pwr, elp_enter, "%u");
170 DEBUGFS_FWSTATS_FILE(pwr, missing_bcns, "%u");
171 DEBUGFS_FWSTATS_FILE(pwr, wake_on_host, "%u");
172 DEBUGFS_FWSTATS_FILE(pwr, wake_on_timer_exp, "%u");
173 DEBUGFS_FWSTATS_FILE(pwr, tx_with_ps, "%u");
174 DEBUGFS_FWSTATS_FILE(pwr, tx_without_ps, "%u");
175 DEBUGFS_FWSTATS_FILE(pwr, rcvd_beacons, "%u");
176 DEBUGFS_FWSTATS_FILE(pwr, power_save_off, "%u");
177 DEBUGFS_FWSTATS_FILE(pwr, enable_ps, "%u");
178 DEBUGFS_FWSTATS_FILE(pwr, disable_ps, "%u");
179 DEBUGFS_FWSTATS_FILE(pwr, fix_tsf_ps, "%u");
180 /* skipping cont_miss_bcns_spread for now */
181 DEBUGFS_FWSTATS_FILE(pwr, rcvd_awake_beacons, "%u");
182
183 DEBUGFS_FWSTATS_FILE(mic, rx_pkts, "%u");
184 DEBUGFS_FWSTATS_FILE(mic, calc_failure, "%u");
185
186 DEBUGFS_FWSTATS_FILE(aes, encrypt_fail, "%u");
187 DEBUGFS_FWSTATS_FILE(aes, decrypt_fail, "%u");
188 DEBUGFS_FWSTATS_FILE(aes, encrypt_packets, "%u");
189 DEBUGFS_FWSTATS_FILE(aes, decrypt_packets, "%u");
190 DEBUGFS_FWSTATS_FILE(aes, encrypt_interrupt, "%u");
191 DEBUGFS_FWSTATS_FILE(aes, decrypt_interrupt, "%u");
192
193 DEBUGFS_FWSTATS_FILE(event, heart_beat, "%u");
194 DEBUGFS_FWSTATS_FILE(event, calibration, "%u");
195 DEBUGFS_FWSTATS_FILE(event, rx_mismatch, "%u");
196 DEBUGFS_FWSTATS_FILE(event, rx_mem_empty, "%u");
197 DEBUGFS_FWSTATS_FILE(event, rx_pool, "%u");
198 DEBUGFS_FWSTATS_FILE(event, oom_late, "%u");
199 DEBUGFS_FWSTATS_FILE(event, phy_transmit_error, "%u");
200 DEBUGFS_FWSTATS_FILE(event, tx_stuck, "%u");
201
202 DEBUGFS_FWSTATS_FILE(ps, pspoll_timeouts, "%u");
203 DEBUGFS_FWSTATS_FILE(ps, upsd_timeouts, "%u");
204 DEBUGFS_FWSTATS_FILE(ps, upsd_max_sptime, "%u");
205 DEBUGFS_FWSTATS_FILE(ps, upsd_max_apturn, "%u");
206 DEBUGFS_FWSTATS_FILE(ps, pspoll_max_apturn, "%u");
207 DEBUGFS_FWSTATS_FILE(ps, pspoll_utilization, "%u");
208 DEBUGFS_FWSTATS_FILE(ps, upsd_utilization, "%u");
209
210 DEBUGFS_FWSTATS_FILE(rxpipe, rx_prep_beacon_drop, "%u");
211 DEBUGFS_FWSTATS_FILE(rxpipe, descr_host_int_trig_rx_data, "%u");
212 DEBUGFS_FWSTATS_FILE(rxpipe, beacon_buffer_thres_host_int_trig_rx_data, "%u");
213 DEBUGFS_FWSTATS_FILE(rxpipe, missed_beacon_host_int_trig_rx_data, "%u");
214 DEBUGFS_FWSTATS_FILE(rxpipe, tx_xfr_host_int_trig_rx_data, "%u");
215
216 DEBUGFS_READONLY_FILE(retry_count, "%u", wl->stats.retry_count);
217 DEBUGFS_READONLY_FILE(excessive_retries, "%u",
218                       wl->stats.excessive_retries);
219
220 static ssize_t tx_queue_len_read(struct file *file, char __user *userbuf,
221                                  size_t count, loff_t *ppos)
222 {
223         struct wl1271 *wl = file->private_data;
224         u32 queue_len;
225         char buf[20];
226         int res;
227
228         queue_len = wl->tx_queue_count;
229
230         res = scnprintf(buf, sizeof(buf), "%u\n", queue_len);
231         return simple_read_from_buffer(userbuf, count, ppos, buf, res);
232 }
233
234 static const struct file_operations tx_queue_len_ops = {
235         .read = tx_queue_len_read,
236         .open = wl1271_open_file_generic,
237         .llseek = default_llseek,
238 };
239
240 static ssize_t gpio_power_read(struct file *file, char __user *user_buf,
241                           size_t count, loff_t *ppos)
242 {
243         struct wl1271 *wl = file->private_data;
244         bool state = test_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
245
246         int res;
247         char buf[10];
248
249         res = scnprintf(buf, sizeof(buf), "%d\n", state);
250
251         return simple_read_from_buffer(user_buf, count, ppos, buf, res);
252 }
253
254 static ssize_t gpio_power_write(struct file *file,
255                            const char __user *user_buf,
256                            size_t count, loff_t *ppos)
257 {
258         struct wl1271 *wl = file->private_data;
259         char buf[10];
260         size_t len;
261         unsigned long value;
262         int ret;
263
264         len = min(count, sizeof(buf) - 1);
265         if (copy_from_user(buf, user_buf, len)) {
266                 return -EFAULT;
267         }
268         buf[len] = '\0';
269
270         ret = kstrtoul(buf, 0, &value);
271         if (ret < 0) {
272                 wl1271_warning("illegal value in gpio_power");
273                 return -EINVAL;
274         }
275
276         mutex_lock(&wl->mutex);
277
278         if (value)
279                 wl1271_power_on(wl);
280         else
281                 wl1271_power_off(wl);
282
283         mutex_unlock(&wl->mutex);
284         return count;
285 }
286
287 static const struct file_operations gpio_power_ops = {
288         .read = gpio_power_read,
289         .write = gpio_power_write,
290         .open = wl1271_open_file_generic,
291         .llseek = default_llseek,
292 };
293
294 static ssize_t start_recovery_write(struct file *file,
295                                     const char __user *user_buf,
296                                     size_t count, loff_t *ppos)
297 {
298         struct wl1271 *wl = file->private_data;
299
300         mutex_lock(&wl->mutex);
301         ieee80211_queue_work(wl->hw, &wl->recovery_work);
302         mutex_unlock(&wl->mutex);
303
304         return count;
305 }
306
307 static const struct file_operations start_recovery_ops = {
308         .write = start_recovery_write,
309         .open = wl1271_open_file_generic,
310         .llseek = default_llseek,
311 };
312
313 static ssize_t driver_state_read(struct file *file, char __user *user_buf,
314                                  size_t count, loff_t *ppos)
315 {
316         struct wl1271 *wl = file->private_data;
317         int res = 0;
318         char buf[1024];
319
320         mutex_lock(&wl->mutex);
321
322 #define DRIVER_STATE_PRINT(x, fmt)   \
323         (res += scnprintf(buf + res, sizeof(buf) - res,\
324                           #x " = " fmt "\n", wl->x))
325
326 #define DRIVER_STATE_PRINT_LONG(x) DRIVER_STATE_PRINT(x, "%ld")
327 #define DRIVER_STATE_PRINT_INT(x)  DRIVER_STATE_PRINT(x, "%d")
328 #define DRIVER_STATE_PRINT_STR(x)  DRIVER_STATE_PRINT(x, "%s")
329 #define DRIVER_STATE_PRINT_LHEX(x) DRIVER_STATE_PRINT(x, "0x%lx")
330 #define DRIVER_STATE_PRINT_HEX(x)  DRIVER_STATE_PRINT(x, "0x%x")
331
332         DRIVER_STATE_PRINT_INT(tx_blocks_available);
333         DRIVER_STATE_PRINT_INT(tx_allocated_blocks);
334         DRIVER_STATE_PRINT_INT(tx_frames_cnt);
335         DRIVER_STATE_PRINT_LHEX(tx_frames_map[0]);
336         DRIVER_STATE_PRINT_INT(tx_queue_count);
337         DRIVER_STATE_PRINT_INT(tx_packets_count);
338         DRIVER_STATE_PRINT_INT(tx_results_count);
339         DRIVER_STATE_PRINT_LHEX(flags);
340         DRIVER_STATE_PRINT_INT(tx_blocks_freed[0]);
341         DRIVER_STATE_PRINT_INT(tx_blocks_freed[1]);
342         DRIVER_STATE_PRINT_INT(tx_blocks_freed[2]);
343         DRIVER_STATE_PRINT_INT(tx_blocks_freed[3]);
344         DRIVER_STATE_PRINT_INT(tx_security_last_seq);
345         DRIVER_STATE_PRINT_INT(rx_counter);
346         DRIVER_STATE_PRINT_INT(session_counter);
347         DRIVER_STATE_PRINT_INT(state);
348         DRIVER_STATE_PRINT_INT(bss_type);
349         DRIVER_STATE_PRINT_INT(channel);
350         DRIVER_STATE_PRINT_HEX(rate_set);
351         DRIVER_STATE_PRINT_HEX(basic_rate_set);
352         DRIVER_STATE_PRINT_HEX(basic_rate);
353         DRIVER_STATE_PRINT_INT(band);
354         DRIVER_STATE_PRINT_INT(beacon_int);
355         DRIVER_STATE_PRINT_INT(psm_entry_retry);
356         DRIVER_STATE_PRINT_INT(ps_poll_failures);
357         DRIVER_STATE_PRINT_HEX(filters);
358         DRIVER_STATE_PRINT_HEX(rx_config);
359         DRIVER_STATE_PRINT_HEX(rx_filter);
360         DRIVER_STATE_PRINT_INT(power_level);
361         DRIVER_STATE_PRINT_INT(rssi_thold);
362         DRIVER_STATE_PRINT_INT(last_rssi_event);
363         DRIVER_STATE_PRINT_INT(sg_enabled);
364         DRIVER_STATE_PRINT_INT(enable_11a);
365         DRIVER_STATE_PRINT_INT(noise);
366         DRIVER_STATE_PRINT_LHEX(ap_hlid_map[0]);
367         DRIVER_STATE_PRINT_INT(last_tx_hlid);
368         DRIVER_STATE_PRINT_INT(ba_support);
369         DRIVER_STATE_PRINT_HEX(ba_rx_bitmap);
370         DRIVER_STATE_PRINT_HEX(ap_fw_ps_map);
371         DRIVER_STATE_PRINT_LHEX(ap_ps_map);
372         DRIVER_STATE_PRINT_HEX(quirks);
373         DRIVER_STATE_PRINT_HEX(irq);
374         DRIVER_STATE_PRINT_HEX(ref_clock);
375         DRIVER_STATE_PRINT_HEX(tcxo_clock);
376         DRIVER_STATE_PRINT_HEX(hw_pg_ver);
377         DRIVER_STATE_PRINT_HEX(platform_quirks);
378         DRIVER_STATE_PRINT_HEX(chip.id);
379         DRIVER_STATE_PRINT_STR(chip.fw_ver_str);
380         DRIVER_STATE_PRINT_INT(sched_scanning);
381
382 #undef DRIVER_STATE_PRINT_INT
383 #undef DRIVER_STATE_PRINT_LONG
384 #undef DRIVER_STATE_PRINT_HEX
385 #undef DRIVER_STATE_PRINT_LHEX
386 #undef DRIVER_STATE_PRINT_STR
387 #undef DRIVER_STATE_PRINT
388
389         mutex_unlock(&wl->mutex);
390
391         return simple_read_from_buffer(user_buf, count, ppos, buf, res);
392 }
393
394 static const struct file_operations driver_state_ops = {
395         .read = driver_state_read,
396         .open = wl1271_open_file_generic,
397         .llseek = default_llseek,
398 };
399
400 static ssize_t dtim_interval_read(struct file *file, char __user *user_buf,
401                                   size_t count, loff_t *ppos)
402 {
403         struct wl1271 *wl = file->private_data;
404         u8 value;
405
406         if (wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_DTIM ||
407             wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_N_DTIM)
408                 value = wl->conf.conn.listen_interval;
409         else
410                 value = 0;
411
412         return wl1271_format_buffer(user_buf, count, ppos, "%d\n", value);
413 }
414
415 static ssize_t dtim_interval_write(struct file *file,
416                                    const char __user *user_buf,
417                                    size_t count, loff_t *ppos)
418 {
419         struct wl1271 *wl = file->private_data;
420         char buf[10];
421         size_t len;
422         unsigned long value;
423         int ret;
424
425         len = min(count, sizeof(buf) - 1);
426         if (copy_from_user(buf, user_buf, len))
427                 return -EFAULT;
428         buf[len] = '\0';
429
430         ret = kstrtoul(buf, 0, &value);
431         if (ret < 0) {
432                 wl1271_warning("illegal value for dtim_interval");
433                 return -EINVAL;
434         }
435
436         if (value < 1 || value > 10) {
437                 wl1271_warning("dtim value is not in valid range");
438                 return -ERANGE;
439         }
440
441         mutex_lock(&wl->mutex);
442
443         wl->conf.conn.listen_interval = value;
444         /* for some reason there are different event types for 1 and >1 */
445         if (value == 1)
446                 wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_DTIM;
447         else
448                 wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_N_DTIM;
449
450         /*
451          * we don't reconfigure ACX_WAKE_UP_CONDITIONS now, so it will only
452          * take effect on the next time we enter psm.
453          */
454         mutex_unlock(&wl->mutex);
455         return count;
456 }
457
458 static const struct file_operations dtim_interval_ops = {
459         .read = dtim_interval_read,
460         .write = dtim_interval_write,
461         .open = wl1271_open_file_generic,
462         .llseek = default_llseek,
463 };
464
465 static ssize_t beacon_interval_read(struct file *file, char __user *user_buf,
466                                     size_t count, loff_t *ppos)
467 {
468         struct wl1271 *wl = file->private_data;
469         u8 value;
470
471         if (wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_BEACON ||
472             wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_N_BEACONS)
473                 value = wl->conf.conn.listen_interval;
474         else
475                 value = 0;
476
477         return wl1271_format_buffer(user_buf, count, ppos, "%d\n", value);
478 }
479
480 static ssize_t beacon_interval_write(struct file *file,
481                                      const char __user *user_buf,
482                                      size_t count, loff_t *ppos)
483 {
484         struct wl1271 *wl = file->private_data;
485         char buf[10];
486         size_t len;
487         unsigned long value;
488         int ret;
489
490         len = min(count, sizeof(buf) - 1);
491         if (copy_from_user(buf, user_buf, len))
492                 return -EFAULT;
493         buf[len] = '\0';
494
495         ret = kstrtoul(buf, 0, &value);
496         if (ret < 0) {
497                 wl1271_warning("illegal value for beacon_interval");
498                 return -EINVAL;
499         }
500
501         if (value < 1 || value > 255) {
502                 wl1271_warning("beacon interval value is not in valid range");
503                 return -ERANGE;
504         }
505
506         mutex_lock(&wl->mutex);
507
508         wl->conf.conn.listen_interval = value;
509         /* for some reason there are different event types for 1 and >1 */
510         if (value == 1)
511                 wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_BEACON;
512         else
513                 wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_N_BEACONS;
514
515         /*
516          * we don't reconfigure ACX_WAKE_UP_CONDITIONS now, so it will only
517          * take effect on the next time we enter psm.
518          */
519         mutex_unlock(&wl->mutex);
520         return count;
521 }
522
523 static const struct file_operations beacon_interval_ops = {
524         .read = beacon_interval_read,
525         .write = beacon_interval_write,
526         .open = wl1271_open_file_generic,
527         .llseek = default_llseek,
528 };
529
530 static int wl1271_debugfs_add_files(struct wl1271 *wl,
531                                      struct dentry *rootdir)
532 {
533         int ret = 0;
534         struct dentry *entry, *stats;
535
536         stats = debugfs_create_dir("fw-statistics", rootdir);
537         if (!stats || IS_ERR(stats)) {
538                 entry = stats;
539                 goto err;
540         }
541
542         DEBUGFS_FWSTATS_ADD(tx, internal_desc_overflow);
543
544         DEBUGFS_FWSTATS_ADD(rx, out_of_mem);
545         DEBUGFS_FWSTATS_ADD(rx, hdr_overflow);
546         DEBUGFS_FWSTATS_ADD(rx, hw_stuck);
547         DEBUGFS_FWSTATS_ADD(rx, dropped);
548         DEBUGFS_FWSTATS_ADD(rx, fcs_err);
549         DEBUGFS_FWSTATS_ADD(rx, xfr_hint_trig);
550         DEBUGFS_FWSTATS_ADD(rx, path_reset);
551         DEBUGFS_FWSTATS_ADD(rx, reset_counter);
552
553         DEBUGFS_FWSTATS_ADD(dma, rx_requested);
554         DEBUGFS_FWSTATS_ADD(dma, rx_errors);
555         DEBUGFS_FWSTATS_ADD(dma, tx_requested);
556         DEBUGFS_FWSTATS_ADD(dma, tx_errors);
557
558         DEBUGFS_FWSTATS_ADD(isr, cmd_cmplt);
559         DEBUGFS_FWSTATS_ADD(isr, fiqs);
560         DEBUGFS_FWSTATS_ADD(isr, rx_headers);
561         DEBUGFS_FWSTATS_ADD(isr, rx_mem_overflow);
562         DEBUGFS_FWSTATS_ADD(isr, rx_rdys);
563         DEBUGFS_FWSTATS_ADD(isr, irqs);
564         DEBUGFS_FWSTATS_ADD(isr, tx_procs);
565         DEBUGFS_FWSTATS_ADD(isr, decrypt_done);
566         DEBUGFS_FWSTATS_ADD(isr, dma0_done);
567         DEBUGFS_FWSTATS_ADD(isr, dma1_done);
568         DEBUGFS_FWSTATS_ADD(isr, tx_exch_complete);
569         DEBUGFS_FWSTATS_ADD(isr, commands);
570         DEBUGFS_FWSTATS_ADD(isr, rx_procs);
571         DEBUGFS_FWSTATS_ADD(isr, hw_pm_mode_changes);
572         DEBUGFS_FWSTATS_ADD(isr, host_acknowledges);
573         DEBUGFS_FWSTATS_ADD(isr, pci_pm);
574         DEBUGFS_FWSTATS_ADD(isr, wakeups);
575         DEBUGFS_FWSTATS_ADD(isr, low_rssi);
576
577         DEBUGFS_FWSTATS_ADD(wep, addr_key_count);
578         DEBUGFS_FWSTATS_ADD(wep, default_key_count);
579         /* skipping wep.reserved */
580         DEBUGFS_FWSTATS_ADD(wep, key_not_found);
581         DEBUGFS_FWSTATS_ADD(wep, decrypt_fail);
582         DEBUGFS_FWSTATS_ADD(wep, packets);
583         DEBUGFS_FWSTATS_ADD(wep, interrupt);
584
585         DEBUGFS_FWSTATS_ADD(pwr, ps_enter);
586         DEBUGFS_FWSTATS_ADD(pwr, elp_enter);
587         DEBUGFS_FWSTATS_ADD(pwr, missing_bcns);
588         DEBUGFS_FWSTATS_ADD(pwr, wake_on_host);
589         DEBUGFS_FWSTATS_ADD(pwr, wake_on_timer_exp);
590         DEBUGFS_FWSTATS_ADD(pwr, tx_with_ps);
591         DEBUGFS_FWSTATS_ADD(pwr, tx_without_ps);
592         DEBUGFS_FWSTATS_ADD(pwr, rcvd_beacons);
593         DEBUGFS_FWSTATS_ADD(pwr, power_save_off);
594         DEBUGFS_FWSTATS_ADD(pwr, enable_ps);
595         DEBUGFS_FWSTATS_ADD(pwr, disable_ps);
596         DEBUGFS_FWSTATS_ADD(pwr, fix_tsf_ps);
597         /* skipping cont_miss_bcns_spread for now */
598         DEBUGFS_FWSTATS_ADD(pwr, rcvd_awake_beacons);
599
600         DEBUGFS_FWSTATS_ADD(mic, rx_pkts);
601         DEBUGFS_FWSTATS_ADD(mic, calc_failure);
602
603         DEBUGFS_FWSTATS_ADD(aes, encrypt_fail);
604         DEBUGFS_FWSTATS_ADD(aes, decrypt_fail);
605         DEBUGFS_FWSTATS_ADD(aes, encrypt_packets);
606         DEBUGFS_FWSTATS_ADD(aes, decrypt_packets);
607         DEBUGFS_FWSTATS_ADD(aes, encrypt_interrupt);
608         DEBUGFS_FWSTATS_ADD(aes, decrypt_interrupt);
609
610         DEBUGFS_FWSTATS_ADD(event, heart_beat);
611         DEBUGFS_FWSTATS_ADD(event, calibration);
612         DEBUGFS_FWSTATS_ADD(event, rx_mismatch);
613         DEBUGFS_FWSTATS_ADD(event, rx_mem_empty);
614         DEBUGFS_FWSTATS_ADD(event, rx_pool);
615         DEBUGFS_FWSTATS_ADD(event, oom_late);
616         DEBUGFS_FWSTATS_ADD(event, phy_transmit_error);
617         DEBUGFS_FWSTATS_ADD(event, tx_stuck);
618
619         DEBUGFS_FWSTATS_ADD(ps, pspoll_timeouts);
620         DEBUGFS_FWSTATS_ADD(ps, upsd_timeouts);
621         DEBUGFS_FWSTATS_ADD(ps, upsd_max_sptime);
622         DEBUGFS_FWSTATS_ADD(ps, upsd_max_apturn);
623         DEBUGFS_FWSTATS_ADD(ps, pspoll_max_apturn);
624         DEBUGFS_FWSTATS_ADD(ps, pspoll_utilization);
625         DEBUGFS_FWSTATS_ADD(ps, upsd_utilization);
626
627         DEBUGFS_FWSTATS_ADD(rxpipe, rx_prep_beacon_drop);
628         DEBUGFS_FWSTATS_ADD(rxpipe, descr_host_int_trig_rx_data);
629         DEBUGFS_FWSTATS_ADD(rxpipe, beacon_buffer_thres_host_int_trig_rx_data);
630         DEBUGFS_FWSTATS_ADD(rxpipe, missed_beacon_host_int_trig_rx_data);
631         DEBUGFS_FWSTATS_ADD(rxpipe, tx_xfr_host_int_trig_rx_data);
632
633         DEBUGFS_ADD(tx_queue_len, rootdir);
634         DEBUGFS_ADD(retry_count, rootdir);
635         DEBUGFS_ADD(excessive_retries, rootdir);
636
637         DEBUGFS_ADD(gpio_power, rootdir);
638         DEBUGFS_ADD(start_recovery, rootdir);
639         DEBUGFS_ADD(driver_state, rootdir);
640         DEBUGFS_ADD(dtim_interval, rootdir);
641         DEBUGFS_ADD(beacon_interval, rootdir);
642
643         return 0;
644
645 err:
646         if (IS_ERR(entry))
647                 ret = PTR_ERR(entry);
648         else
649                 ret = -ENOMEM;
650
651         return ret;
652 }
653
654 void wl1271_debugfs_reset(struct wl1271 *wl)
655 {
656         if (!wl->stats.fw_stats)
657                 return;
658
659         memset(wl->stats.fw_stats, 0, sizeof(*wl->stats.fw_stats));
660         wl->stats.retry_count = 0;
661         wl->stats.excessive_retries = 0;
662 }
663
664 int wl1271_debugfs_init(struct wl1271 *wl)
665 {
666         int ret;
667         struct dentry *rootdir;
668
669         rootdir = debugfs_create_dir(KBUILD_MODNAME,
670                                      wl->hw->wiphy->debugfsdir);
671
672         if (IS_ERR(rootdir)) {
673                 ret = PTR_ERR(rootdir);
674                 goto err;
675         }
676
677         wl->stats.fw_stats = kzalloc(sizeof(*wl->stats.fw_stats),
678                                       GFP_KERNEL);
679
680         if (!wl->stats.fw_stats) {
681                 ret = -ENOMEM;
682                 goto err_fw;
683         }
684
685         wl->stats.fw_stats_update = jiffies;
686
687         ret = wl1271_debugfs_add_files(wl, rootdir);
688
689         if (ret < 0)
690                 goto err_file;
691
692         return 0;
693
694 err_file:
695         kfree(wl->stats.fw_stats);
696         wl->stats.fw_stats = NULL;
697
698 err_fw:
699         debugfs_remove_recursive(rootdir);
700
701 err:
702         return ret;
703 }
704
705 void wl1271_debugfs_exit(struct wl1271 *wl)
706 {
707         kfree(wl->stats.fw_stats);
708         wl->stats.fw_stats = NULL;
709 }