Fix common misspellings
[deliverable/linux.git] / drivers / net / wireless / wl12xx / debugfs.c
CommitLineData
f5fc0f86
LC
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
00d20100 24#include "debugfs.h"
f5fc0f86
LC
25
26#include <linux/skbuff.h>
5a0e3ad6 27#include <linux/slab.h>
f5fc0f86 28
00d20100
SL
29#include "wl12xx.h"
30#include "acx.h"
31#include "ps.h"
32#include "io.h"
f5fc0f86
LC
33
34/* ms */
35#define WL1271_DEBUGFS_STATS_LIFETIME 1000
36
37/* debugfs macros idea from mac80211 */
03107a4b
EP
38#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;
45
46 va_start(args, fmt);
47 res = vscnprintf(buf, sizeof(buf), fmt, args);
48 va_end(args);
f5fc0f86 49
03107a4b
EP
50 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
51}
52
53#define DEBUGFS_READONLY_FILE(name, fmt, value...) \
f5fc0f86
LC
54static 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; \
03107a4b
EP
58 return wl1271_format_buffer(userbuf, count, ppos, \
59 fmt "\n", ##value); \
f5fc0f86
LC
60} \
61 \
62static const struct file_operations name## _ops = { \
63 .read = name## _read, \
64 .open = wl1271_open_file_generic, \
2b18ab36 65 .llseek = generic_file_llseek, \
f5fc0f86
LC
66};
67
68#define DEBUGFS_ADD(name, parent) \
7cb2cea9
EP
69 entry = debugfs_create_file(#name, 0400, parent, \
70 wl, &name## _ops); \
71 if (!entry || IS_ERR(entry)) \
72 goto err; \
f5fc0f86 73
03107a4b 74#define DEBUGFS_FWSTATS_FILE(sub, name, fmt) \
f5fc0f86
LC
75static 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; \
f5fc0f86
LC
80 \
81 wl1271_debugfs_update_stats(wl); \
82 \
03107a4b
EP
83 return wl1271_format_buffer(userbuf, count, ppos, fmt "\n", \
84 wl->stats.fw_stats->sub.name); \
f5fc0f86
LC
85} \
86 \
87static const struct file_operations sub## _ ##name## _ops = { \
88 .read = sub## _ ##name## _read, \
89 .open = wl1271_open_file_generic, \
2b18ab36 90 .llseek = generic_file_llseek, \
f5fc0f86
LC
91};
92
93#define DEBUGFS_FWSTATS_ADD(sub, name) \
7cb2cea9 94 DEBUGFS_ADD(sub## _ ##name, stats)
f5fc0f86
LC
95
96static void wl1271_debugfs_update_stats(struct wl1271 *wl)
97{
98 int ret;
99
100 mutex_lock(&wl->mutex);
101
a620865e 102 ret = wl1271_ps_elp_wakeup(wl);
f5fc0f86
LC
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
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
03107a4b
EP
125DEBUGFS_FWSTATS_FILE(tx, internal_desc_overflow, "%u");
126
127DEBUGFS_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");
135
136DEBUGFS_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");
140
141DEBUGFS_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");
159
160DEBUGFS_FWSTATS_FILE(wep, addr_key_count, "%u");
161DEBUGFS_FWSTATS_FILE(wep, default_key_count, "%u");
f5fc0f86 162/* skipping wep.reserved */
03107a4b
EP
163DEBUGFS_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");
167
168DEBUGFS_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");
f5fc0f86 180/* skipping cont_miss_bcns_spread for now */
03107a4b
EP
181DEBUGFS_FWSTATS_FILE(pwr, rcvd_awake_beacons, "%u");
182
183DEBUGFS_FWSTATS_FILE(mic, rx_pkts, "%u");
184DEBUGFS_FWSTATS_FILE(mic, calc_failure, "%u");
185
186DEBUGFS_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");
192
193DEBUGFS_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");
201
202DEBUGFS_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");
209
210DEBUGFS_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");
215
216DEBUGFS_READONLY_FILE(retry_count, "%u", wl->stats.retry_count);
217DEBUGFS_READONLY_FILE(excessive_retries, "%u",
f5fc0f86
LC
218 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
6742f554 228 queue_len = wl->tx_queue_count;
f5fc0f86
LC
229
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,
6038f373 237 .llseek = default_llseek,
f5fc0f86
LC
238};
239
98b2a684
LC
240static 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;
71449f8d
JO
244 bool state = test_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
245
98b2a684
LC
246 int res;
247 char buf[10];
248
71449f8d 249 res = scnprintf(buf, sizeof(buf), "%d\n", state);
98b2a684
LC
250
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
98b2a684
LC
264 len = min(count, sizeof(buf) - 1);
265 if (copy_from_user(buf, user_buf, len)) {
8e2de74e 266 return -EFAULT;
98b2a684
LC
267 }
268 buf[len] = '\0';
269
270 ret = strict_strtoul(buf, 0, &value);
271 if (ret < 0) {
272 wl1271_warning("illegal value in gpio_power");
8e2de74e 273 return -EINVAL;
98b2a684
LC
274 }
275
8e2de74e
EP
276 mutex_lock(&wl->mutex);
277
becd551c
TP
278 if (value)
279 wl1271_power_on(wl);
280 else
281 wl1271_power_off(wl);
98b2a684 282
98b2a684
LC
283 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,
6038f373
AB
290 .open = wl1271_open_file_generic,
291 .llseek = default_llseek,
98b2a684
LC
292};
293
3c2c04a1
EP
294static int wl1271_debugfs_add_files(struct wl1271 *wl,
295 struct dentry *rootdir)
f5fc0f86
LC
296{
297 int ret = 0;
7cb2cea9
EP
298 struct dentry *entry, *stats;
299
3c2c04a1 300 stats = debugfs_create_dir("fw-statistics", rootdir);
7cb2cea9
EP
301 if (!stats || IS_ERR(stats)) {
302 entry = stats;
303 goto err;
304 }
f5fc0f86
LC
305
306 DEBUGFS_FWSTATS_ADD(tx, internal_desc_overflow);
307
308 DEBUGFS_FWSTATS_ADD(rx, out_of_mem);
309 DEBUGFS_FWSTATS_ADD(rx, hdr_overflow);
310 DEBUGFS_FWSTATS_ADD(rx, hw_stuck);
311 DEBUGFS_FWSTATS_ADD(rx, dropped);
312 DEBUGFS_FWSTATS_ADD(rx, fcs_err);
313 DEBUGFS_FWSTATS_ADD(rx, xfr_hint_trig);
314 DEBUGFS_FWSTATS_ADD(rx, path_reset);
315 DEBUGFS_FWSTATS_ADD(rx, reset_counter);
316
317 DEBUGFS_FWSTATS_ADD(dma, rx_requested);
318 DEBUGFS_FWSTATS_ADD(dma, rx_errors);
319 DEBUGFS_FWSTATS_ADD(dma, tx_requested);
320 DEBUGFS_FWSTATS_ADD(dma, tx_errors);
321
322 DEBUGFS_FWSTATS_ADD(isr, cmd_cmplt);
323 DEBUGFS_FWSTATS_ADD(isr, fiqs);
324 DEBUGFS_FWSTATS_ADD(isr, rx_headers);
325 DEBUGFS_FWSTATS_ADD(isr, rx_mem_overflow);
326 DEBUGFS_FWSTATS_ADD(isr, rx_rdys);
327 DEBUGFS_FWSTATS_ADD(isr, irqs);
328 DEBUGFS_FWSTATS_ADD(isr, tx_procs);
329 DEBUGFS_FWSTATS_ADD(isr, decrypt_done);
330 DEBUGFS_FWSTATS_ADD(isr, dma0_done);
331 DEBUGFS_FWSTATS_ADD(isr, dma1_done);
332 DEBUGFS_FWSTATS_ADD(isr, tx_exch_complete);
333 DEBUGFS_FWSTATS_ADD(isr, commands);
334 DEBUGFS_FWSTATS_ADD(isr, rx_procs);
335 DEBUGFS_FWSTATS_ADD(isr, hw_pm_mode_changes);
336 DEBUGFS_FWSTATS_ADD(isr, host_acknowledges);
337 DEBUGFS_FWSTATS_ADD(isr, pci_pm);
338 DEBUGFS_FWSTATS_ADD(isr, wakeups);
339 DEBUGFS_FWSTATS_ADD(isr, low_rssi);
340
341 DEBUGFS_FWSTATS_ADD(wep, addr_key_count);
342 DEBUGFS_FWSTATS_ADD(wep, default_key_count);
343 /* skipping wep.reserved */
344 DEBUGFS_FWSTATS_ADD(wep, key_not_found);
345 DEBUGFS_FWSTATS_ADD(wep, decrypt_fail);
346 DEBUGFS_FWSTATS_ADD(wep, packets);
347 DEBUGFS_FWSTATS_ADD(wep, interrupt);
348
349 DEBUGFS_FWSTATS_ADD(pwr, ps_enter);
350 DEBUGFS_FWSTATS_ADD(pwr, elp_enter);
351 DEBUGFS_FWSTATS_ADD(pwr, missing_bcns);
352 DEBUGFS_FWSTATS_ADD(pwr, wake_on_host);
353 DEBUGFS_FWSTATS_ADD(pwr, wake_on_timer_exp);
354 DEBUGFS_FWSTATS_ADD(pwr, tx_with_ps);
355 DEBUGFS_FWSTATS_ADD(pwr, tx_without_ps);
356 DEBUGFS_FWSTATS_ADD(pwr, rcvd_beacons);
357 DEBUGFS_FWSTATS_ADD(pwr, power_save_off);
358 DEBUGFS_FWSTATS_ADD(pwr, enable_ps);
359 DEBUGFS_FWSTATS_ADD(pwr, disable_ps);
360 DEBUGFS_FWSTATS_ADD(pwr, fix_tsf_ps);
361 /* skipping cont_miss_bcns_spread for now */
362 DEBUGFS_FWSTATS_ADD(pwr, rcvd_awake_beacons);
363
364 DEBUGFS_FWSTATS_ADD(mic, rx_pkts);
365 DEBUGFS_FWSTATS_ADD(mic, calc_failure);
366
367 DEBUGFS_FWSTATS_ADD(aes, encrypt_fail);
368 DEBUGFS_FWSTATS_ADD(aes, decrypt_fail);
369 DEBUGFS_FWSTATS_ADD(aes, encrypt_packets);
370 DEBUGFS_FWSTATS_ADD(aes, decrypt_packets);
371 DEBUGFS_FWSTATS_ADD(aes, encrypt_interrupt);
372 DEBUGFS_FWSTATS_ADD(aes, decrypt_interrupt);
373
374 DEBUGFS_FWSTATS_ADD(event, heart_beat);
375 DEBUGFS_FWSTATS_ADD(event, calibration);
376 DEBUGFS_FWSTATS_ADD(event, rx_mismatch);
377 DEBUGFS_FWSTATS_ADD(event, rx_mem_empty);
378 DEBUGFS_FWSTATS_ADD(event, rx_pool);
379 DEBUGFS_FWSTATS_ADD(event, oom_late);
380 DEBUGFS_FWSTATS_ADD(event, phy_transmit_error);
381 DEBUGFS_FWSTATS_ADD(event, tx_stuck);
382
383 DEBUGFS_FWSTATS_ADD(ps, pspoll_timeouts);
384 DEBUGFS_FWSTATS_ADD(ps, upsd_timeouts);
385 DEBUGFS_FWSTATS_ADD(ps, upsd_max_sptime);
386 DEBUGFS_FWSTATS_ADD(ps, upsd_max_apturn);
387 DEBUGFS_FWSTATS_ADD(ps, pspoll_max_apturn);
388 DEBUGFS_FWSTATS_ADD(ps, pspoll_utilization);
389 DEBUGFS_FWSTATS_ADD(ps, upsd_utilization);
390
391 DEBUGFS_FWSTATS_ADD(rxpipe, rx_prep_beacon_drop);
392 DEBUGFS_FWSTATS_ADD(rxpipe, descr_host_int_trig_rx_data);
393 DEBUGFS_FWSTATS_ADD(rxpipe, beacon_buffer_thres_host_int_trig_rx_data);
394 DEBUGFS_FWSTATS_ADD(rxpipe, missed_beacon_host_int_trig_rx_data);
395 DEBUGFS_FWSTATS_ADD(rxpipe, tx_xfr_host_int_trig_rx_data);
396
3c2c04a1
EP
397 DEBUGFS_ADD(tx_queue_len, rootdir);
398 DEBUGFS_ADD(retry_count, rootdir);
399 DEBUGFS_ADD(excessive_retries, rootdir);
f5fc0f86 400
3c2c04a1 401 DEBUGFS_ADD(gpio_power, rootdir);
98b2a684 402
7cb2cea9
EP
403 return 0;
404
405err:
406 if (IS_ERR(entry))
407 ret = PTR_ERR(entry);
408 else
409 ret = -ENOMEM;
f5fc0f86
LC
410
411 return ret;
412}
413
414void wl1271_debugfs_reset(struct wl1271 *wl)
415{
3c2c04a1 416 if (!wl->stats.fw_stats)
43a598d5
LC
417 return;
418
f5fc0f86
LC
419 memset(wl->stats.fw_stats, 0, sizeof(*wl->stats.fw_stats));
420 wl->stats.retry_count = 0;
421 wl->stats.excessive_retries = 0;
422}
423
424int wl1271_debugfs_init(struct wl1271 *wl)
425{
426 int ret;
3c2c04a1 427 struct dentry *rootdir;
f5fc0f86 428
3c2c04a1
EP
429 rootdir = debugfs_create_dir(KBUILD_MODNAME,
430 wl->hw->wiphy->debugfsdir);
f5fc0f86 431
3c2c04a1
EP
432 if (IS_ERR(rootdir)) {
433 ret = PTR_ERR(rootdir);
f5fc0f86
LC
434 goto err;
435 }
436
f5fc0f86
LC
437 wl->stats.fw_stats = kzalloc(sizeof(*wl->stats.fw_stats),
438 GFP_KERNEL);
439
440 if (!wl->stats.fw_stats) {
441 ret = -ENOMEM;
442 goto err_fw;
443 }
444
445 wl->stats.fw_stats_update = jiffies;
446
3c2c04a1 447 ret = wl1271_debugfs_add_files(wl, rootdir);
f5fc0f86
LC
448
449 if (ret < 0)
450 goto err_file;
451
452 return 0;
453
454err_file:
455 kfree(wl->stats.fw_stats);
456 wl->stats.fw_stats = NULL;
457
458err_fw:
3c2c04a1 459 debugfs_remove_recursive(rootdir);
f5fc0f86
LC
460
461err:
462 return ret;
463}
464
465void wl1271_debugfs_exit(struct wl1271 *wl)
466{
f5fc0f86
LC
467 kfree(wl->stats.fw_stats);
468 wl->stats.fw_stats = NULL;
f5fc0f86 469}
This page took 0.258745 seconds and 5 git commands to generate.