blob: a2b55e556714f538957d79a81417ae72296b9ddf [file] [log] [blame]
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001/*
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
Shahar Levi00d20102010-11-08 11:20:10 +000024#include "debugfs.h"
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030025
26#include <linux/skbuff.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090027#include <linux/slab.h>
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030028
Shahar Levi00d20102010-11-08 11:20:10 +000029#include "wl12xx.h"
30#include "acx.h"
31#include "ps.h"
32#include "io.h"
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030033
34/* ms */
35#define WL1271_DEBUGFS_STATS_LIFETIME 1000
36
37/* debugfs macros idea from mac80211 */
Eliad Peller03107a42010-10-27 14:58:30 +020038#define DEBUGFS_FORMAT_BUFFER_SIZE 100
39static 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;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030045
Eliad Peller03107a42010-10-27 14:58:30 +020046 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...) \
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030054static 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; \
Eliad Peller03107a42010-10-27 14:58:30 +020058 return wl1271_format_buffer(userbuf, count, ppos, \
59 fmt "\n", ##value); \
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030060} \
61 \
62static const struct file_operations name## _ops = { \
63 .read = name## _read, \
64 .open = wl1271_open_file_generic, \
Arnd Bergmann2b18ab362010-07-06 19:05:31 +020065 .llseek = generic_file_llseek, \
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030066};
67
68#define DEBUGFS_ADD(name, parent) \
Eliad Peller7cb2cea2010-11-24 12:53:15 +020069 entry = debugfs_create_file(#name, 0400, parent, \
70 wl, &name## _ops); \
71 if (!entry || IS_ERR(entry)) \
72 goto err; \
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030073
Eliad Peller03107a42010-10-27 14:58:30 +020074#define DEBUGFS_FWSTATS_FILE(sub, name, fmt) \
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030075static 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; \
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030080 \
81 wl1271_debugfs_update_stats(wl); \
82 \
Eliad Peller03107a42010-10-27 14:58:30 +020083 return wl1271_format_buffer(userbuf, count, ppos, fmt "\n", \
84 wl->stats.fw_stats->sub.name); \
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030085} \
86 \
87static const struct file_operations sub## _ ##name## _ops = { \
88 .read = sub## _ ##name## _read, \
89 .open = wl1271_open_file_generic, \
Arnd Bergmann2b18ab362010-07-06 19:05:31 +020090 .llseek = generic_file_llseek, \
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030091};
92
93#define DEBUGFS_FWSTATS_ADD(sub, name) \
Eliad Peller7cb2cea2010-11-24 12:53:15 +020094 DEBUGFS_ADD(sub## _ ##name, stats)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030095
96static void wl1271_debugfs_update_stats(struct wl1271 *wl)
97{
98 int ret;
99
100 mutex_lock(&wl->mutex);
101
Ido Yariva6208652011-03-01 15:14:41 +0200102 ret = wl1271_ps_elp_wakeup(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300103 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
115out:
116 mutex_unlock(&wl->mutex);
117}
118
119static int wl1271_open_file_generic(struct inode *inode, struct file *file)
120{
121 file->private_data = inode->i_private;
122 return 0;
123}
124
Eliad Peller03107a42010-10-27 14:58:30 +0200125DEBUGFS_FWSTATS_FILE(tx, internal_desc_overflow, "%u");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300126
Eliad Peller03107a42010-10-27 14:58:30 +0200127DEBUGFS_FWSTATS_FILE(rx, out_of_mem, "%u");
128DEBUGFS_FWSTATS_FILE(rx, hdr_overflow, "%u");
129DEBUGFS_FWSTATS_FILE(rx, hw_stuck, "%u");
130DEBUGFS_FWSTATS_FILE(rx, dropped, "%u");
131DEBUGFS_FWSTATS_FILE(rx, fcs_err, "%u");
132DEBUGFS_FWSTATS_FILE(rx, xfr_hint_trig, "%u");
133DEBUGFS_FWSTATS_FILE(rx, path_reset, "%u");
134DEBUGFS_FWSTATS_FILE(rx, reset_counter, "%u");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300135
Eliad Peller03107a42010-10-27 14:58:30 +0200136DEBUGFS_FWSTATS_FILE(dma, rx_requested, "%u");
137DEBUGFS_FWSTATS_FILE(dma, rx_errors, "%u");
138DEBUGFS_FWSTATS_FILE(dma, tx_requested, "%u");
139DEBUGFS_FWSTATS_FILE(dma, tx_errors, "%u");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300140
Eliad Peller03107a42010-10-27 14:58:30 +0200141DEBUGFS_FWSTATS_FILE(isr, cmd_cmplt, "%u");
142DEBUGFS_FWSTATS_FILE(isr, fiqs, "%u");
143DEBUGFS_FWSTATS_FILE(isr, rx_headers, "%u");
144DEBUGFS_FWSTATS_FILE(isr, rx_mem_overflow, "%u");
145DEBUGFS_FWSTATS_FILE(isr, rx_rdys, "%u");
146DEBUGFS_FWSTATS_FILE(isr, irqs, "%u");
147DEBUGFS_FWSTATS_FILE(isr, tx_procs, "%u");
148DEBUGFS_FWSTATS_FILE(isr, decrypt_done, "%u");
149DEBUGFS_FWSTATS_FILE(isr, dma0_done, "%u");
150DEBUGFS_FWSTATS_FILE(isr, dma1_done, "%u");
151DEBUGFS_FWSTATS_FILE(isr, tx_exch_complete, "%u");
152DEBUGFS_FWSTATS_FILE(isr, commands, "%u");
153DEBUGFS_FWSTATS_FILE(isr, rx_procs, "%u");
154DEBUGFS_FWSTATS_FILE(isr, hw_pm_mode_changes, "%u");
155DEBUGFS_FWSTATS_FILE(isr, host_acknowledges, "%u");
156DEBUGFS_FWSTATS_FILE(isr, pci_pm, "%u");
157DEBUGFS_FWSTATS_FILE(isr, wakeups, "%u");
158DEBUGFS_FWSTATS_FILE(isr, low_rssi, "%u");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300159
Eliad Peller03107a42010-10-27 14:58:30 +0200160DEBUGFS_FWSTATS_FILE(wep, addr_key_count, "%u");
161DEBUGFS_FWSTATS_FILE(wep, default_key_count, "%u");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300162/* skipping wep.reserved */
Eliad Peller03107a42010-10-27 14:58:30 +0200163DEBUGFS_FWSTATS_FILE(wep, key_not_found, "%u");
164DEBUGFS_FWSTATS_FILE(wep, decrypt_fail, "%u");
165DEBUGFS_FWSTATS_FILE(wep, packets, "%u");
166DEBUGFS_FWSTATS_FILE(wep, interrupt, "%u");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300167
Eliad Peller03107a42010-10-27 14:58:30 +0200168DEBUGFS_FWSTATS_FILE(pwr, ps_enter, "%u");
169DEBUGFS_FWSTATS_FILE(pwr, elp_enter, "%u");
170DEBUGFS_FWSTATS_FILE(pwr, missing_bcns, "%u");
171DEBUGFS_FWSTATS_FILE(pwr, wake_on_host, "%u");
172DEBUGFS_FWSTATS_FILE(pwr, wake_on_timer_exp, "%u");
173DEBUGFS_FWSTATS_FILE(pwr, tx_with_ps, "%u");
174DEBUGFS_FWSTATS_FILE(pwr, tx_without_ps, "%u");
175DEBUGFS_FWSTATS_FILE(pwr, rcvd_beacons, "%u");
176DEBUGFS_FWSTATS_FILE(pwr, power_save_off, "%u");
177DEBUGFS_FWSTATS_FILE(pwr, enable_ps, "%u");
178DEBUGFS_FWSTATS_FILE(pwr, disable_ps, "%u");
179DEBUGFS_FWSTATS_FILE(pwr, fix_tsf_ps, "%u");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300180/* skipping cont_miss_bcns_spread for now */
Eliad Peller03107a42010-10-27 14:58:30 +0200181DEBUGFS_FWSTATS_FILE(pwr, rcvd_awake_beacons, "%u");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300182
Eliad Peller03107a42010-10-27 14:58:30 +0200183DEBUGFS_FWSTATS_FILE(mic, rx_pkts, "%u");
184DEBUGFS_FWSTATS_FILE(mic, calc_failure, "%u");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300185
Eliad Peller03107a42010-10-27 14:58:30 +0200186DEBUGFS_FWSTATS_FILE(aes, encrypt_fail, "%u");
187DEBUGFS_FWSTATS_FILE(aes, decrypt_fail, "%u");
188DEBUGFS_FWSTATS_FILE(aes, encrypt_packets, "%u");
189DEBUGFS_FWSTATS_FILE(aes, decrypt_packets, "%u");
190DEBUGFS_FWSTATS_FILE(aes, encrypt_interrupt, "%u");
191DEBUGFS_FWSTATS_FILE(aes, decrypt_interrupt, "%u");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300192
Eliad Peller03107a42010-10-27 14:58:30 +0200193DEBUGFS_FWSTATS_FILE(event, heart_beat, "%u");
194DEBUGFS_FWSTATS_FILE(event, calibration, "%u");
195DEBUGFS_FWSTATS_FILE(event, rx_mismatch, "%u");
196DEBUGFS_FWSTATS_FILE(event, rx_mem_empty, "%u");
197DEBUGFS_FWSTATS_FILE(event, rx_pool, "%u");
198DEBUGFS_FWSTATS_FILE(event, oom_late, "%u");
199DEBUGFS_FWSTATS_FILE(event, phy_transmit_error, "%u");
200DEBUGFS_FWSTATS_FILE(event, tx_stuck, "%u");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300201
Eliad Peller03107a42010-10-27 14:58:30 +0200202DEBUGFS_FWSTATS_FILE(ps, pspoll_timeouts, "%u");
203DEBUGFS_FWSTATS_FILE(ps, upsd_timeouts, "%u");
204DEBUGFS_FWSTATS_FILE(ps, upsd_max_sptime, "%u");
205DEBUGFS_FWSTATS_FILE(ps, upsd_max_apturn, "%u");
206DEBUGFS_FWSTATS_FILE(ps, pspoll_max_apturn, "%u");
207DEBUGFS_FWSTATS_FILE(ps, pspoll_utilization, "%u");
208DEBUGFS_FWSTATS_FILE(ps, upsd_utilization, "%u");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300209
Eliad Peller03107a42010-10-27 14:58:30 +0200210DEBUGFS_FWSTATS_FILE(rxpipe, rx_prep_beacon_drop, "%u");
211DEBUGFS_FWSTATS_FILE(rxpipe, descr_host_int_trig_rx_data, "%u");
212DEBUGFS_FWSTATS_FILE(rxpipe, beacon_buffer_thres_host_int_trig_rx_data, "%u");
213DEBUGFS_FWSTATS_FILE(rxpipe, missed_beacon_host_int_trig_rx_data, "%u");
214DEBUGFS_FWSTATS_FILE(rxpipe, tx_xfr_host_int_trig_rx_data, "%u");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300215
Eliad Peller03107a42010-10-27 14:58:30 +0200216DEBUGFS_READONLY_FILE(retry_count, "%u", wl->stats.retry_count);
217DEBUGFS_READONLY_FILE(excessive_retries, "%u",
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300218 wl->stats.excessive_retries);
219
220static 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
Juuso Oikarinen6742f552010-12-13 09:52:37 +0200228 queue_len = wl->tx_queue_count;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300229
230 res = scnprintf(buf, sizeof(buf), "%u\n", queue_len);
231 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
232}
233
234static const struct file_operations tx_queue_len_ops = {
235 .read = tx_queue_len_read,
236 .open = wl1271_open_file_generic,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200237 .llseek = default_llseek,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300238};
239
Luciano Coelho98b2a682009-12-11 15:40:52 +0200240static 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;
Juuso Oikarinen71449f82009-12-11 15:41:07 +0200244 bool state = test_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
245
Luciano Coelho98b2a682009-12-11 15:40:52 +0200246 int res;
247 char buf[10];
248
Juuso Oikarinen71449f82009-12-11 15:41:07 +0200249 res = scnprintf(buf, sizeof(buf), "%d\n", state);
Luciano Coelho98b2a682009-12-11 15:40:52 +0200250
251 return simple_read_from_buffer(user_buf, count, ppos, buf, res);
252}
253
254static 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
Luciano Coelho98b2a682009-12-11 15:40:52 +0200264 len = min(count, sizeof(buf) - 1);
265 if (copy_from_user(buf, user_buf, len)) {
Eliad Peller8e2de742011-01-23 11:25:27 +0100266 return -EFAULT;
Luciano Coelho98b2a682009-12-11 15:40:52 +0200267 }
268 buf[len] = '\0';
269
Luciano Coelho6277ed62011-04-01 17:49:54 +0300270 ret = kstrtoul(buf, 0, &value);
Luciano Coelho98b2a682009-12-11 15:40:52 +0200271 if (ret < 0) {
272 wl1271_warning("illegal value in gpio_power");
Eliad Peller8e2de742011-01-23 11:25:27 +0100273 return -EINVAL;
Luciano Coelho98b2a682009-12-11 15:40:52 +0200274 }
275
Eliad Peller8e2de742011-01-23 11:25:27 +0100276 mutex_lock(&wl->mutex);
277
Teemu Paasikivibecd5512010-03-18 12:26:27 +0200278 if (value)
279 wl1271_power_on(wl);
280 else
281 wl1271_power_off(wl);
Luciano Coelho98b2a682009-12-11 15:40:52 +0200282
Luciano Coelho98b2a682009-12-11 15:40:52 +0200283 mutex_unlock(&wl->mutex);
284 return count;
285}
286
287static const struct file_operations gpio_power_ops = {
288 .read = gpio_power_read,
289 .write = gpio_power_write,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200290 .open = wl1271_open_file_generic,
291 .llseek = default_llseek,
Luciano Coelho98b2a682009-12-11 15:40:52 +0200292};
293
Arik Nemtsov2dc5a5c2011-04-18 14:15:27 +0300294static 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
307static const struct file_operations start_recovery_ops = {
308 .write = start_recovery_write,
309 .open = wl1271_open_file_generic,
310 .llseek = default_llseek,
311};
312
Eliad Peller1fe9e242011-04-17 11:20:47 +0300313static ssize_t dtim_interval_read(struct file *file, char __user *user_buf,
314 size_t count, loff_t *ppos)
315{
316 struct wl1271 *wl = file->private_data;
317 u8 value;
318
319 if (wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_DTIM ||
320 wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_N_DTIM)
321 value = wl->conf.conn.listen_interval;
322 else
323 value = 0;
324
325 return wl1271_format_buffer(user_buf, count, ppos, "%d\n", value);
326}
327
328static ssize_t dtim_interval_write(struct file *file,
329 const char __user *user_buf,
330 size_t count, loff_t *ppos)
331{
332 struct wl1271 *wl = file->private_data;
333 char buf[10];
334 size_t len;
335 unsigned long value;
336 int ret;
337
338 len = min(count, sizeof(buf) - 1);
339 if (copy_from_user(buf, user_buf, len))
340 return -EFAULT;
341 buf[len] = '\0';
342
Luciano Coelhof7c7c7e2011-04-29 22:25:28 +0300343 ret = kstrtoul(buf, 0, &value);
Eliad Peller1fe9e242011-04-17 11:20:47 +0300344 if (ret < 0) {
345 wl1271_warning("illegal value for dtim_interval");
346 return -EINVAL;
347 }
348
349 if (value < 1 || value > 10) {
350 wl1271_warning("dtim value is not in valid range");
351 return -ERANGE;
352 }
353
354 mutex_lock(&wl->mutex);
355
356 wl->conf.conn.listen_interval = value;
357 /* for some reason there are different event types for 1 and >1 */
358 if (value == 1)
359 wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_DTIM;
360 else
361 wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_N_DTIM;
362
363 /*
364 * we don't reconfigure ACX_WAKE_UP_CONDITIONS now, so it will only
365 * take effect on the next time we enter psm.
366 */
367 mutex_unlock(&wl->mutex);
368 return count;
369}
370
371static const struct file_operations dtim_interval_ops = {
372 .read = dtim_interval_read,
373 .write = dtim_interval_write,
374 .open = wl1271_open_file_generic,
375 .llseek = default_llseek,
376};
377
378static ssize_t beacon_interval_read(struct file *file, char __user *user_buf,
379 size_t count, loff_t *ppos)
380{
381 struct wl1271 *wl = file->private_data;
382 u8 value;
383
384 if (wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_BEACON ||
385 wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_N_BEACONS)
386 value = wl->conf.conn.listen_interval;
387 else
388 value = 0;
389
390 return wl1271_format_buffer(user_buf, count, ppos, "%d\n", value);
391}
392
393static ssize_t beacon_interval_write(struct file *file,
394 const char __user *user_buf,
395 size_t count, loff_t *ppos)
396{
397 struct wl1271 *wl = file->private_data;
398 char buf[10];
399 size_t len;
400 unsigned long value;
401 int ret;
402
403 len = min(count, sizeof(buf) - 1);
404 if (copy_from_user(buf, user_buf, len))
405 return -EFAULT;
406 buf[len] = '\0';
407
Luciano Coelhof7c7c7e2011-04-29 22:25:28 +0300408 ret = kstrtoul(buf, 0, &value);
Eliad Peller1fe9e242011-04-17 11:20:47 +0300409 if (ret < 0) {
410 wl1271_warning("illegal value for beacon_interval");
411 return -EINVAL;
412 }
413
414 if (value < 1 || value > 255) {
415 wl1271_warning("beacon interval value is not in valid range");
416 return -ERANGE;
417 }
418
419 mutex_lock(&wl->mutex);
420
421 wl->conf.conn.listen_interval = value;
422 /* for some reason there are different event types for 1 and >1 */
423 if (value == 1)
424 wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_BEACON;
425 else
426 wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_N_BEACONS;
427
428 /*
429 * we don't reconfigure ACX_WAKE_UP_CONDITIONS now, so it will only
430 * take effect on the next time we enter psm.
431 */
432 mutex_unlock(&wl->mutex);
433 return count;
434}
435
436static const struct file_operations beacon_interval_ops = {
437 .read = beacon_interval_read,
438 .write = beacon_interval_write,
439 .open = wl1271_open_file_generic,
440 .llseek = default_llseek,
441};
442
Eliad Peller3c2c04a2010-12-15 11:47:54 +0200443static int wl1271_debugfs_add_files(struct wl1271 *wl,
444 struct dentry *rootdir)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300445{
446 int ret = 0;
Eliad Peller7cb2cea2010-11-24 12:53:15 +0200447 struct dentry *entry, *stats;
448
Eliad Peller3c2c04a2010-12-15 11:47:54 +0200449 stats = debugfs_create_dir("fw-statistics", rootdir);
Eliad Peller7cb2cea2010-11-24 12:53:15 +0200450 if (!stats || IS_ERR(stats)) {
451 entry = stats;
452 goto err;
453 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300454
455 DEBUGFS_FWSTATS_ADD(tx, internal_desc_overflow);
456
457 DEBUGFS_FWSTATS_ADD(rx, out_of_mem);
458 DEBUGFS_FWSTATS_ADD(rx, hdr_overflow);
459 DEBUGFS_FWSTATS_ADD(rx, hw_stuck);
460 DEBUGFS_FWSTATS_ADD(rx, dropped);
461 DEBUGFS_FWSTATS_ADD(rx, fcs_err);
462 DEBUGFS_FWSTATS_ADD(rx, xfr_hint_trig);
463 DEBUGFS_FWSTATS_ADD(rx, path_reset);
464 DEBUGFS_FWSTATS_ADD(rx, reset_counter);
465
466 DEBUGFS_FWSTATS_ADD(dma, rx_requested);
467 DEBUGFS_FWSTATS_ADD(dma, rx_errors);
468 DEBUGFS_FWSTATS_ADD(dma, tx_requested);
469 DEBUGFS_FWSTATS_ADD(dma, tx_errors);
470
471 DEBUGFS_FWSTATS_ADD(isr, cmd_cmplt);
472 DEBUGFS_FWSTATS_ADD(isr, fiqs);
473 DEBUGFS_FWSTATS_ADD(isr, rx_headers);
474 DEBUGFS_FWSTATS_ADD(isr, rx_mem_overflow);
475 DEBUGFS_FWSTATS_ADD(isr, rx_rdys);
476 DEBUGFS_FWSTATS_ADD(isr, irqs);
477 DEBUGFS_FWSTATS_ADD(isr, tx_procs);
478 DEBUGFS_FWSTATS_ADD(isr, decrypt_done);
479 DEBUGFS_FWSTATS_ADD(isr, dma0_done);
480 DEBUGFS_FWSTATS_ADD(isr, dma1_done);
481 DEBUGFS_FWSTATS_ADD(isr, tx_exch_complete);
482 DEBUGFS_FWSTATS_ADD(isr, commands);
483 DEBUGFS_FWSTATS_ADD(isr, rx_procs);
484 DEBUGFS_FWSTATS_ADD(isr, hw_pm_mode_changes);
485 DEBUGFS_FWSTATS_ADD(isr, host_acknowledges);
486 DEBUGFS_FWSTATS_ADD(isr, pci_pm);
487 DEBUGFS_FWSTATS_ADD(isr, wakeups);
488 DEBUGFS_FWSTATS_ADD(isr, low_rssi);
489
490 DEBUGFS_FWSTATS_ADD(wep, addr_key_count);
491 DEBUGFS_FWSTATS_ADD(wep, default_key_count);
492 /* skipping wep.reserved */
493 DEBUGFS_FWSTATS_ADD(wep, key_not_found);
494 DEBUGFS_FWSTATS_ADD(wep, decrypt_fail);
495 DEBUGFS_FWSTATS_ADD(wep, packets);
496 DEBUGFS_FWSTATS_ADD(wep, interrupt);
497
498 DEBUGFS_FWSTATS_ADD(pwr, ps_enter);
499 DEBUGFS_FWSTATS_ADD(pwr, elp_enter);
500 DEBUGFS_FWSTATS_ADD(pwr, missing_bcns);
501 DEBUGFS_FWSTATS_ADD(pwr, wake_on_host);
502 DEBUGFS_FWSTATS_ADD(pwr, wake_on_timer_exp);
503 DEBUGFS_FWSTATS_ADD(pwr, tx_with_ps);
504 DEBUGFS_FWSTATS_ADD(pwr, tx_without_ps);
505 DEBUGFS_FWSTATS_ADD(pwr, rcvd_beacons);
506 DEBUGFS_FWSTATS_ADD(pwr, power_save_off);
507 DEBUGFS_FWSTATS_ADD(pwr, enable_ps);
508 DEBUGFS_FWSTATS_ADD(pwr, disable_ps);
509 DEBUGFS_FWSTATS_ADD(pwr, fix_tsf_ps);
510 /* skipping cont_miss_bcns_spread for now */
511 DEBUGFS_FWSTATS_ADD(pwr, rcvd_awake_beacons);
512
513 DEBUGFS_FWSTATS_ADD(mic, rx_pkts);
514 DEBUGFS_FWSTATS_ADD(mic, calc_failure);
515
516 DEBUGFS_FWSTATS_ADD(aes, encrypt_fail);
517 DEBUGFS_FWSTATS_ADD(aes, decrypt_fail);
518 DEBUGFS_FWSTATS_ADD(aes, encrypt_packets);
519 DEBUGFS_FWSTATS_ADD(aes, decrypt_packets);
520 DEBUGFS_FWSTATS_ADD(aes, encrypt_interrupt);
521 DEBUGFS_FWSTATS_ADD(aes, decrypt_interrupt);
522
523 DEBUGFS_FWSTATS_ADD(event, heart_beat);
524 DEBUGFS_FWSTATS_ADD(event, calibration);
525 DEBUGFS_FWSTATS_ADD(event, rx_mismatch);
526 DEBUGFS_FWSTATS_ADD(event, rx_mem_empty);
527 DEBUGFS_FWSTATS_ADD(event, rx_pool);
528 DEBUGFS_FWSTATS_ADD(event, oom_late);
529 DEBUGFS_FWSTATS_ADD(event, phy_transmit_error);
530 DEBUGFS_FWSTATS_ADD(event, tx_stuck);
531
532 DEBUGFS_FWSTATS_ADD(ps, pspoll_timeouts);
533 DEBUGFS_FWSTATS_ADD(ps, upsd_timeouts);
534 DEBUGFS_FWSTATS_ADD(ps, upsd_max_sptime);
535 DEBUGFS_FWSTATS_ADD(ps, upsd_max_apturn);
536 DEBUGFS_FWSTATS_ADD(ps, pspoll_max_apturn);
537 DEBUGFS_FWSTATS_ADD(ps, pspoll_utilization);
538 DEBUGFS_FWSTATS_ADD(ps, upsd_utilization);
539
540 DEBUGFS_FWSTATS_ADD(rxpipe, rx_prep_beacon_drop);
541 DEBUGFS_FWSTATS_ADD(rxpipe, descr_host_int_trig_rx_data);
542 DEBUGFS_FWSTATS_ADD(rxpipe, beacon_buffer_thres_host_int_trig_rx_data);
543 DEBUGFS_FWSTATS_ADD(rxpipe, missed_beacon_host_int_trig_rx_data);
544 DEBUGFS_FWSTATS_ADD(rxpipe, tx_xfr_host_int_trig_rx_data);
545
Eliad Peller3c2c04a2010-12-15 11:47:54 +0200546 DEBUGFS_ADD(tx_queue_len, rootdir);
547 DEBUGFS_ADD(retry_count, rootdir);
548 DEBUGFS_ADD(excessive_retries, rootdir);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300549
Eliad Peller3c2c04a2010-12-15 11:47:54 +0200550 DEBUGFS_ADD(gpio_power, rootdir);
Arik Nemtsov2dc5a5c2011-04-18 14:15:27 +0300551 DEBUGFS_ADD(start_recovery, rootdir);
Eliad Peller1fe9e242011-04-17 11:20:47 +0300552 DEBUGFS_ADD(dtim_interval, rootdir);
553 DEBUGFS_ADD(beacon_interval, rootdir);
Luciano Coelho98b2a682009-12-11 15:40:52 +0200554
Eliad Peller7cb2cea2010-11-24 12:53:15 +0200555 return 0;
556
557err:
558 if (IS_ERR(entry))
559 ret = PTR_ERR(entry);
560 else
561 ret = -ENOMEM;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300562
563 return ret;
564}
565
566void wl1271_debugfs_reset(struct wl1271 *wl)
567{
Eliad Peller3c2c04a2010-12-15 11:47:54 +0200568 if (!wl->stats.fw_stats)
Luciano Coelho43a598d2010-11-30 14:58:46 +0200569 return;
570
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300571 memset(wl->stats.fw_stats, 0, sizeof(*wl->stats.fw_stats));
572 wl->stats.retry_count = 0;
573 wl->stats.excessive_retries = 0;
574}
575
576int wl1271_debugfs_init(struct wl1271 *wl)
577{
578 int ret;
Eliad Peller3c2c04a2010-12-15 11:47:54 +0200579 struct dentry *rootdir;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300580
Eliad Peller3c2c04a2010-12-15 11:47:54 +0200581 rootdir = debugfs_create_dir(KBUILD_MODNAME,
582 wl->hw->wiphy->debugfsdir);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300583
Eliad Peller3c2c04a2010-12-15 11:47:54 +0200584 if (IS_ERR(rootdir)) {
585 ret = PTR_ERR(rootdir);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300586 goto err;
587 }
588
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300589 wl->stats.fw_stats = kzalloc(sizeof(*wl->stats.fw_stats),
590 GFP_KERNEL);
591
592 if (!wl->stats.fw_stats) {
593 ret = -ENOMEM;
594 goto err_fw;
595 }
596
597 wl->stats.fw_stats_update = jiffies;
598
Eliad Peller3c2c04a2010-12-15 11:47:54 +0200599 ret = wl1271_debugfs_add_files(wl, rootdir);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300600
601 if (ret < 0)
602 goto err_file;
603
604 return 0;
605
606err_file:
607 kfree(wl->stats.fw_stats);
608 wl->stats.fw_stats = NULL;
609
610err_fw:
Eliad Peller3c2c04a2010-12-15 11:47:54 +0200611 debugfs_remove_recursive(rootdir);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300612
613err:
614 return ret;
615}
616
617void wl1271_debugfs_exit(struct wl1271 *wl)
618{
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300619 kfree(wl->stats.fw_stats);
620 wl->stats.fw_stats = NULL;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300621}