wl12xx: update fw status struct
[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"
f1a46384 33#include "tx.h"
f5fc0f86
LC
34
35/* ms */
36#define WL1271_DEBUGFS_STATS_LIFETIME 1000
37
38/* debugfs macros idea from mac80211 */
03107a4b
EP
39#define DEBUGFS_FORMAT_BUFFER_SIZE 100
40static int wl1271_format_buffer(char __user *userbuf, size_t count,
41 loff_t *ppos, char *fmt, ...)
42{
43 va_list args;
44 char buf[DEBUGFS_FORMAT_BUFFER_SIZE];
45 int res;
46
47 va_start(args, fmt);
48 res = vscnprintf(buf, sizeof(buf), fmt, args);
49 va_end(args);
f5fc0f86 50
03107a4b
EP
51 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
52}
53
54#define DEBUGFS_READONLY_FILE(name, fmt, value...) \
f5fc0f86
LC
55static ssize_t name## _read(struct file *file, char __user *userbuf, \
56 size_t count, loff_t *ppos) \
57{ \
58 struct wl1271 *wl = file->private_data; \
03107a4b
EP
59 return wl1271_format_buffer(userbuf, count, ppos, \
60 fmt "\n", ##value); \
f5fc0f86
LC
61} \
62 \
63static const struct file_operations name## _ops = { \
64 .read = name## _read, \
65 .open = wl1271_open_file_generic, \
2b18ab36 66 .llseek = generic_file_llseek, \
f5fc0f86
LC
67};
68
69#define DEBUGFS_ADD(name, parent) \
7cb2cea9
EP
70 entry = debugfs_create_file(#name, 0400, parent, \
71 wl, &name## _ops); \
72 if (!entry || IS_ERR(entry)) \
73 goto err; \
f5fc0f86 74
c84368e0
EP
75#define DEBUGFS_ADD_PREFIX(prefix, name, parent) \
76 do { \
77 entry = debugfs_create_file(#name, 0400, parent, \
78 wl, &prefix## _## name## _ops); \
79 if (!entry || IS_ERR(entry)) \
80 goto err; \
81 } while (0);
82
03107a4b 83#define DEBUGFS_FWSTATS_FILE(sub, name, fmt) \
f5fc0f86
LC
84static ssize_t sub## _ ##name## _read(struct file *file, \
85 char __user *userbuf, \
86 size_t count, loff_t *ppos) \
87{ \
88 struct wl1271 *wl = file->private_data; \
f5fc0f86
LC
89 \
90 wl1271_debugfs_update_stats(wl); \
91 \
03107a4b
EP
92 return wl1271_format_buffer(userbuf, count, ppos, fmt "\n", \
93 wl->stats.fw_stats->sub.name); \
f5fc0f86
LC
94} \
95 \
96static const struct file_operations sub## _ ##name## _ops = { \
97 .read = sub## _ ##name## _read, \
98 .open = wl1271_open_file_generic, \
2b18ab36 99 .llseek = generic_file_llseek, \
f5fc0f86
LC
100};
101
102#define DEBUGFS_FWSTATS_ADD(sub, name) \
7cb2cea9 103 DEBUGFS_ADD(sub## _ ##name, stats)
f5fc0f86
LC
104
105static void wl1271_debugfs_update_stats(struct wl1271 *wl)
106{
107 int ret;
108
109 mutex_lock(&wl->mutex);
110
a620865e 111 ret = wl1271_ps_elp_wakeup(wl);
f5fc0f86
LC
112 if (ret < 0)
113 goto out;
114
115 if (wl->state == WL1271_STATE_ON &&
116 time_after(jiffies, wl->stats.fw_stats_update +
117 msecs_to_jiffies(WL1271_DEBUGFS_STATS_LIFETIME))) {
118 wl1271_acx_statistics(wl, wl->stats.fw_stats);
119 wl->stats.fw_stats_update = jiffies;
120 }
121
122 wl1271_ps_elp_sleep(wl);
123
124out:
125 mutex_unlock(&wl->mutex);
126}
127
128static int wl1271_open_file_generic(struct inode *inode, struct file *file)
129{
130 file->private_data = inode->i_private;
131 return 0;
132}
133
03107a4b
EP
134DEBUGFS_FWSTATS_FILE(tx, internal_desc_overflow, "%u");
135
136DEBUGFS_FWSTATS_FILE(rx, out_of_mem, "%u");
137DEBUGFS_FWSTATS_FILE(rx, hdr_overflow, "%u");
138DEBUGFS_FWSTATS_FILE(rx, hw_stuck, "%u");
139DEBUGFS_FWSTATS_FILE(rx, dropped, "%u");
140DEBUGFS_FWSTATS_FILE(rx, fcs_err, "%u");
141DEBUGFS_FWSTATS_FILE(rx, xfr_hint_trig, "%u");
142DEBUGFS_FWSTATS_FILE(rx, path_reset, "%u");
143DEBUGFS_FWSTATS_FILE(rx, reset_counter, "%u");
144
145DEBUGFS_FWSTATS_FILE(dma, rx_requested, "%u");
146DEBUGFS_FWSTATS_FILE(dma, rx_errors, "%u");
147DEBUGFS_FWSTATS_FILE(dma, tx_requested, "%u");
148DEBUGFS_FWSTATS_FILE(dma, tx_errors, "%u");
149
150DEBUGFS_FWSTATS_FILE(isr, cmd_cmplt, "%u");
151DEBUGFS_FWSTATS_FILE(isr, fiqs, "%u");
152DEBUGFS_FWSTATS_FILE(isr, rx_headers, "%u");
153DEBUGFS_FWSTATS_FILE(isr, rx_mem_overflow, "%u");
154DEBUGFS_FWSTATS_FILE(isr, rx_rdys, "%u");
155DEBUGFS_FWSTATS_FILE(isr, irqs, "%u");
156DEBUGFS_FWSTATS_FILE(isr, tx_procs, "%u");
157DEBUGFS_FWSTATS_FILE(isr, decrypt_done, "%u");
158DEBUGFS_FWSTATS_FILE(isr, dma0_done, "%u");
159DEBUGFS_FWSTATS_FILE(isr, dma1_done, "%u");
160DEBUGFS_FWSTATS_FILE(isr, tx_exch_complete, "%u");
161DEBUGFS_FWSTATS_FILE(isr, commands, "%u");
162DEBUGFS_FWSTATS_FILE(isr, rx_procs, "%u");
163DEBUGFS_FWSTATS_FILE(isr, hw_pm_mode_changes, "%u");
164DEBUGFS_FWSTATS_FILE(isr, host_acknowledges, "%u");
165DEBUGFS_FWSTATS_FILE(isr, pci_pm, "%u");
166DEBUGFS_FWSTATS_FILE(isr, wakeups, "%u");
167DEBUGFS_FWSTATS_FILE(isr, low_rssi, "%u");
168
169DEBUGFS_FWSTATS_FILE(wep, addr_key_count, "%u");
170DEBUGFS_FWSTATS_FILE(wep, default_key_count, "%u");
f5fc0f86 171/* skipping wep.reserved */
03107a4b
EP
172DEBUGFS_FWSTATS_FILE(wep, key_not_found, "%u");
173DEBUGFS_FWSTATS_FILE(wep, decrypt_fail, "%u");
174DEBUGFS_FWSTATS_FILE(wep, packets, "%u");
175DEBUGFS_FWSTATS_FILE(wep, interrupt, "%u");
176
177DEBUGFS_FWSTATS_FILE(pwr, ps_enter, "%u");
178DEBUGFS_FWSTATS_FILE(pwr, elp_enter, "%u");
179DEBUGFS_FWSTATS_FILE(pwr, missing_bcns, "%u");
180DEBUGFS_FWSTATS_FILE(pwr, wake_on_host, "%u");
181DEBUGFS_FWSTATS_FILE(pwr, wake_on_timer_exp, "%u");
182DEBUGFS_FWSTATS_FILE(pwr, tx_with_ps, "%u");
183DEBUGFS_FWSTATS_FILE(pwr, tx_without_ps, "%u");
184DEBUGFS_FWSTATS_FILE(pwr, rcvd_beacons, "%u");
185DEBUGFS_FWSTATS_FILE(pwr, power_save_off, "%u");
186DEBUGFS_FWSTATS_FILE(pwr, enable_ps, "%u");
187DEBUGFS_FWSTATS_FILE(pwr, disable_ps, "%u");
188DEBUGFS_FWSTATS_FILE(pwr, fix_tsf_ps, "%u");
f5fc0f86 189/* skipping cont_miss_bcns_spread for now */
03107a4b
EP
190DEBUGFS_FWSTATS_FILE(pwr, rcvd_awake_beacons, "%u");
191
192DEBUGFS_FWSTATS_FILE(mic, rx_pkts, "%u");
193DEBUGFS_FWSTATS_FILE(mic, calc_failure, "%u");
194
195DEBUGFS_FWSTATS_FILE(aes, encrypt_fail, "%u");
196DEBUGFS_FWSTATS_FILE(aes, decrypt_fail, "%u");
197DEBUGFS_FWSTATS_FILE(aes, encrypt_packets, "%u");
198DEBUGFS_FWSTATS_FILE(aes, decrypt_packets, "%u");
199DEBUGFS_FWSTATS_FILE(aes, encrypt_interrupt, "%u");
200DEBUGFS_FWSTATS_FILE(aes, decrypt_interrupt, "%u");
201
202DEBUGFS_FWSTATS_FILE(event, heart_beat, "%u");
203DEBUGFS_FWSTATS_FILE(event, calibration, "%u");
204DEBUGFS_FWSTATS_FILE(event, rx_mismatch, "%u");
205DEBUGFS_FWSTATS_FILE(event, rx_mem_empty, "%u");
206DEBUGFS_FWSTATS_FILE(event, rx_pool, "%u");
207DEBUGFS_FWSTATS_FILE(event, oom_late, "%u");
208DEBUGFS_FWSTATS_FILE(event, phy_transmit_error, "%u");
209DEBUGFS_FWSTATS_FILE(event, tx_stuck, "%u");
210
211DEBUGFS_FWSTATS_FILE(ps, pspoll_timeouts, "%u");
212DEBUGFS_FWSTATS_FILE(ps, upsd_timeouts, "%u");
213DEBUGFS_FWSTATS_FILE(ps, upsd_max_sptime, "%u");
214DEBUGFS_FWSTATS_FILE(ps, upsd_max_apturn, "%u");
215DEBUGFS_FWSTATS_FILE(ps, pspoll_max_apturn, "%u");
216DEBUGFS_FWSTATS_FILE(ps, pspoll_utilization, "%u");
217DEBUGFS_FWSTATS_FILE(ps, upsd_utilization, "%u");
218
219DEBUGFS_FWSTATS_FILE(rxpipe, rx_prep_beacon_drop, "%u");
220DEBUGFS_FWSTATS_FILE(rxpipe, descr_host_int_trig_rx_data, "%u");
221DEBUGFS_FWSTATS_FILE(rxpipe, beacon_buffer_thres_host_int_trig_rx_data, "%u");
222DEBUGFS_FWSTATS_FILE(rxpipe, missed_beacon_host_int_trig_rx_data, "%u");
223DEBUGFS_FWSTATS_FILE(rxpipe, tx_xfr_host_int_trig_rx_data, "%u");
224
225DEBUGFS_READONLY_FILE(retry_count, "%u", wl->stats.retry_count);
226DEBUGFS_READONLY_FILE(excessive_retries, "%u",
f5fc0f86
LC
227 wl->stats.excessive_retries);
228
229static ssize_t tx_queue_len_read(struct file *file, char __user *userbuf,
230 size_t count, loff_t *ppos)
231{
232 struct wl1271 *wl = file->private_data;
233 u32 queue_len;
234 char buf[20];
235 int res;
236
f1a46384 237 queue_len = wl1271_tx_total_queue_count(wl);
f5fc0f86
LC
238
239 res = scnprintf(buf, sizeof(buf), "%u\n", queue_len);
240 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
241}
242
243static const struct file_operations tx_queue_len_ops = {
244 .read = tx_queue_len_read,
245 .open = wl1271_open_file_generic,
6038f373 246 .llseek = default_llseek,
f5fc0f86
LC
247};
248
98b2a684
LC
249static ssize_t gpio_power_read(struct file *file, char __user *user_buf,
250 size_t count, loff_t *ppos)
251{
252 struct wl1271 *wl = file->private_data;
71449f8d
JO
253 bool state = test_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
254
98b2a684
LC
255 int res;
256 char buf[10];
257
71449f8d 258 res = scnprintf(buf, sizeof(buf), "%d\n", state);
98b2a684
LC
259
260 return simple_read_from_buffer(user_buf, count, ppos, buf, res);
261}
262
263static ssize_t gpio_power_write(struct file *file,
264 const char __user *user_buf,
265 size_t count, loff_t *ppos)
266{
267 struct wl1271 *wl = file->private_data;
268 char buf[10];
269 size_t len;
270 unsigned long value;
271 int ret;
272
98b2a684
LC
273 len = min(count, sizeof(buf) - 1);
274 if (copy_from_user(buf, user_buf, len)) {
8e2de74e 275 return -EFAULT;
98b2a684
LC
276 }
277 buf[len] = '\0';
278
6277ed65 279 ret = kstrtoul(buf, 0, &value);
98b2a684
LC
280 if (ret < 0) {
281 wl1271_warning("illegal value in gpio_power");
8e2de74e 282 return -EINVAL;
98b2a684
LC
283 }
284
8e2de74e
EP
285 mutex_lock(&wl->mutex);
286
becd551c
TP
287 if (value)
288 wl1271_power_on(wl);
289 else
290 wl1271_power_off(wl);
98b2a684 291
98b2a684
LC
292 mutex_unlock(&wl->mutex);
293 return count;
294}
295
296static const struct file_operations gpio_power_ops = {
297 .read = gpio_power_read,
298 .write = gpio_power_write,
6038f373
AB
299 .open = wl1271_open_file_generic,
300 .llseek = default_llseek,
98b2a684
LC
301};
302
2dc5a5c2
AN
303static ssize_t start_recovery_write(struct file *file,
304 const char __user *user_buf,
305 size_t count, loff_t *ppos)
306{
307 struct wl1271 *wl = file->private_data;
308
309 mutex_lock(&wl->mutex);
baacb9ae 310 wl12xx_queue_recovery_work(wl);
2dc5a5c2
AN
311 mutex_unlock(&wl->mutex);
312
313 return count;
314}
315
316static const struct file_operations start_recovery_ops = {
317 .write = start_recovery_write,
318 .open = wl1271_open_file_generic,
319 .llseek = default_llseek,
320};
321
2d66bee7
AN
322static ssize_t driver_state_read(struct file *file, char __user *user_buf,
323 size_t count, loff_t *ppos)
324{
325 struct wl1271 *wl = file->private_data;
326 int res = 0;
327 char buf[1024];
328
329 mutex_lock(&wl->mutex);
330
331#define DRIVER_STATE_PRINT(x, fmt) \
332 (res += scnprintf(buf + res, sizeof(buf) - res,\
333 #x " = " fmt "\n", wl->x))
334
335#define DRIVER_STATE_PRINT_LONG(x) DRIVER_STATE_PRINT(x, "%ld")
336#define DRIVER_STATE_PRINT_INT(x) DRIVER_STATE_PRINT(x, "%d")
337#define DRIVER_STATE_PRINT_STR(x) DRIVER_STATE_PRINT(x, "%s")
338#define DRIVER_STATE_PRINT_LHEX(x) DRIVER_STATE_PRINT(x, "0x%lx")
339#define DRIVER_STATE_PRINT_HEX(x) DRIVER_STATE_PRINT(x, "0x%x")
340
341 DRIVER_STATE_PRINT_INT(tx_blocks_available);
7bb5d6ce 342 DRIVER_STATE_PRINT_INT(tx_allocated_blocks);
2d66bee7
AN
343 DRIVER_STATE_PRINT_INT(tx_frames_cnt);
344 DRIVER_STATE_PRINT_LHEX(tx_frames_map[0]);
f1a46384
AN
345 DRIVER_STATE_PRINT_INT(tx_queue_count[0]);
346 DRIVER_STATE_PRINT_INT(tx_queue_count[1]);
347 DRIVER_STATE_PRINT_INT(tx_queue_count[2]);
348 DRIVER_STATE_PRINT_INT(tx_queue_count[3]);
2d66bee7
AN
349 DRIVER_STATE_PRINT_INT(tx_packets_count);
350 DRIVER_STATE_PRINT_INT(tx_results_count);
351 DRIVER_STATE_PRINT_LHEX(flags);
4d56ad9c 352 DRIVER_STATE_PRINT_INT(tx_blocks_freed);
b992c682 353 DRIVER_STATE_PRINT_INT(tx_security_last_seq_lsb);
2d66bee7
AN
354 DRIVER_STATE_PRINT_INT(rx_counter);
355 DRIVER_STATE_PRINT_INT(session_counter);
356 DRIVER_STATE_PRINT_INT(state);
357 DRIVER_STATE_PRINT_INT(bss_type);
358 DRIVER_STATE_PRINT_INT(channel);
359 DRIVER_STATE_PRINT_HEX(rate_set);
360 DRIVER_STATE_PRINT_HEX(basic_rate_set);
361 DRIVER_STATE_PRINT_HEX(basic_rate);
362 DRIVER_STATE_PRINT_INT(band);
363 DRIVER_STATE_PRINT_INT(beacon_int);
364 DRIVER_STATE_PRINT_INT(psm_entry_retry);
365 DRIVER_STATE_PRINT_INT(ps_poll_failures);
2d66bee7
AN
366 DRIVER_STATE_PRINT_INT(power_level);
367 DRIVER_STATE_PRINT_INT(rssi_thold);
368 DRIVER_STATE_PRINT_INT(last_rssi_event);
369 DRIVER_STATE_PRINT_INT(sg_enabled);
370 DRIVER_STATE_PRINT_INT(enable_11a);
371 DRIVER_STATE_PRINT_INT(noise);
372 DRIVER_STATE_PRINT_LHEX(ap_hlid_map[0]);
373 DRIVER_STATE_PRINT_INT(last_tx_hlid);
374 DRIVER_STATE_PRINT_INT(ba_support);
375 DRIVER_STATE_PRINT_HEX(ba_rx_bitmap);
376 DRIVER_STATE_PRINT_HEX(ap_fw_ps_map);
377 DRIVER_STATE_PRINT_LHEX(ap_ps_map);
378 DRIVER_STATE_PRINT_HEX(quirks);
379 DRIVER_STATE_PRINT_HEX(irq);
380 DRIVER_STATE_PRINT_HEX(ref_clock);
381 DRIVER_STATE_PRINT_HEX(tcxo_clock);
382 DRIVER_STATE_PRINT_HEX(hw_pg_ver);
383 DRIVER_STATE_PRINT_HEX(platform_quirks);
384 DRIVER_STATE_PRINT_HEX(chip.id);
385 DRIVER_STATE_PRINT_STR(chip.fw_ver_str);
d3eff81d 386 DRIVER_STATE_PRINT_INT(sched_scanning);
2d66bee7
AN
387
388#undef DRIVER_STATE_PRINT_INT
389#undef DRIVER_STATE_PRINT_LONG
390#undef DRIVER_STATE_PRINT_HEX
391#undef DRIVER_STATE_PRINT_LHEX
392#undef DRIVER_STATE_PRINT_STR
393#undef DRIVER_STATE_PRINT
394
395 mutex_unlock(&wl->mutex);
396
397 return simple_read_from_buffer(user_buf, count, ppos, buf, res);
398}
399
400static const struct file_operations driver_state_ops = {
401 .read = driver_state_read,
402 .open = wl1271_open_file_generic,
403 .llseek = default_llseek,
404};
405
1fe9e246
EP
406static ssize_t dtim_interval_read(struct file *file, char __user *user_buf,
407 size_t count, loff_t *ppos)
408{
409 struct wl1271 *wl = file->private_data;
410 u8 value;
411
412 if (wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_DTIM ||
413 wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_N_DTIM)
414 value = wl->conf.conn.listen_interval;
415 else
416 value = 0;
417
418 return wl1271_format_buffer(user_buf, count, ppos, "%d\n", value);
419}
420
421static ssize_t dtim_interval_write(struct file *file,
422 const char __user *user_buf,
423 size_t count, loff_t *ppos)
424{
425 struct wl1271 *wl = file->private_data;
426 char buf[10];
427 size_t len;
428 unsigned long value;
429 int ret;
430
431 len = min(count, sizeof(buf) - 1);
432 if (copy_from_user(buf, user_buf, len))
433 return -EFAULT;
434 buf[len] = '\0';
435
f7c7c7e6 436 ret = kstrtoul(buf, 0, &value);
1fe9e246
EP
437 if (ret < 0) {
438 wl1271_warning("illegal value for dtim_interval");
439 return -EINVAL;
440 }
441
442 if (value < 1 || value > 10) {
443 wl1271_warning("dtim value is not in valid range");
444 return -ERANGE;
445 }
446
447 mutex_lock(&wl->mutex);
448
449 wl->conf.conn.listen_interval = value;
450 /* for some reason there are different event types for 1 and >1 */
451 if (value == 1)
452 wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_DTIM;
453 else
454 wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_N_DTIM;
455
456 /*
457 * we don't reconfigure ACX_WAKE_UP_CONDITIONS now, so it will only
458 * take effect on the next time we enter psm.
459 */
460 mutex_unlock(&wl->mutex);
461 return count;
462}
463
464static const struct file_operations dtim_interval_ops = {
465 .read = dtim_interval_read,
466 .write = dtim_interval_write,
467 .open = wl1271_open_file_generic,
468 .llseek = default_llseek,
469};
470
471static ssize_t beacon_interval_read(struct file *file, char __user *user_buf,
472 size_t count, loff_t *ppos)
473{
474 struct wl1271 *wl = file->private_data;
475 u8 value;
476
477 if (wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_BEACON ||
478 wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_N_BEACONS)
479 value = wl->conf.conn.listen_interval;
480 else
481 value = 0;
482
483 return wl1271_format_buffer(user_buf, count, ppos, "%d\n", value);
484}
485
486static ssize_t beacon_interval_write(struct file *file,
487 const char __user *user_buf,
488 size_t count, loff_t *ppos)
489{
490 struct wl1271 *wl = file->private_data;
491 char buf[10];
492 size_t len;
493 unsigned long value;
494 int ret;
495
496 len = min(count, sizeof(buf) - 1);
497 if (copy_from_user(buf, user_buf, len))
498 return -EFAULT;
499 buf[len] = '\0';
500
f7c7c7e6 501 ret = kstrtoul(buf, 0, &value);
1fe9e246
EP
502 if (ret < 0) {
503 wl1271_warning("illegal value for beacon_interval");
504 return -EINVAL;
505 }
506
507 if (value < 1 || value > 255) {
508 wl1271_warning("beacon interval value is not in valid range");
509 return -ERANGE;
510 }
511
512 mutex_lock(&wl->mutex);
513
514 wl->conf.conn.listen_interval = value;
515 /* for some reason there are different event types for 1 and >1 */
516 if (value == 1)
517 wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_BEACON;
518 else
519 wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_N_BEACONS;
520
521 /*
522 * we don't reconfigure ACX_WAKE_UP_CONDITIONS now, so it will only
523 * take effect on the next time we enter psm.
524 */
525 mutex_unlock(&wl->mutex);
526 return count;
527}
528
529static const struct file_operations beacon_interval_ops = {
530 .read = beacon_interval_read,
531 .write = beacon_interval_write,
532 .open = wl1271_open_file_generic,
533 .llseek = default_llseek,
534};
535
c84368e0
EP
536static ssize_t rx_streaming_interval_write(struct file *file,
537 const char __user *user_buf,
538 size_t count, loff_t *ppos)
539{
540 struct wl1271 *wl = file->private_data;
541 char buf[10];
542 size_t len;
543 unsigned long value;
544 int ret;
545
546 len = min(count, sizeof(buf) - 1);
547 if (copy_from_user(buf, user_buf, len))
548 return -EFAULT;
549 buf[len] = '\0';
550
551 ret = kstrtoul(buf, 0, &value);
552 if (ret < 0) {
553 wl1271_warning("illegal value in rx_streaming_interval!");
554 return -EINVAL;
555 }
556
557 /* valid values: 0, 10-100 */
558 if (value && (value < 10 || value > 100)) {
559 wl1271_warning("value is not in range!");
560 return -ERANGE;
561 }
562
563 mutex_lock(&wl->mutex);
564
565 wl->conf.rx_streaming.interval = value;
566
567 ret = wl1271_ps_elp_wakeup(wl);
568 if (ret < 0)
569 goto out;
570
571 wl1271_recalc_rx_streaming(wl);
572
573 wl1271_ps_elp_sleep(wl);
574out:
575 mutex_unlock(&wl->mutex);
576 return count;
577}
578
579static ssize_t rx_streaming_interval_read(struct file *file,
580 char __user *userbuf,
581 size_t count, loff_t *ppos)
582{
583 struct wl1271 *wl = file->private_data;
584 return wl1271_format_buffer(userbuf, count, ppos,
585 "%d\n", wl->conf.rx_streaming.interval);
586}
587
588static const struct file_operations rx_streaming_interval_ops = {
589 .read = rx_streaming_interval_read,
590 .write = rx_streaming_interval_write,
591 .open = wl1271_open_file_generic,
592 .llseek = default_llseek,
593};
594
595static ssize_t rx_streaming_always_write(struct file *file,
596 const char __user *user_buf,
597 size_t count, loff_t *ppos)
598{
599 struct wl1271 *wl = file->private_data;
600 char buf[10];
601 size_t len;
602 unsigned long value;
603 int ret;
604
605 len = min(count, sizeof(buf) - 1);
606 if (copy_from_user(buf, user_buf, len))
607 return -EFAULT;
608 buf[len] = '\0';
609
610 ret = kstrtoul(buf, 0, &value);
611 if (ret < 0) {
612 wl1271_warning("illegal value in rx_streaming_write!");
613 return -EINVAL;
614 }
615
616 /* valid values: 0, 10-100 */
617 if (!(value == 0 || value == 1)) {
618 wl1271_warning("value is not in valid!");
619 return -EINVAL;
620 }
621
622 mutex_lock(&wl->mutex);
623
624 wl->conf.rx_streaming.always = value;
625
626 ret = wl1271_ps_elp_wakeup(wl);
627 if (ret < 0)
628 goto out;
629
630 wl1271_recalc_rx_streaming(wl);
631
632 wl1271_ps_elp_sleep(wl);
633out:
634 mutex_unlock(&wl->mutex);
635 return count;
636}
637
638static ssize_t rx_streaming_always_read(struct file *file,
639 char __user *userbuf,
640 size_t count, loff_t *ppos)
641{
642 struct wl1271 *wl = file->private_data;
643 return wl1271_format_buffer(userbuf, count, ppos,
644 "%d\n", wl->conf.rx_streaming.always);
645}
646
647static const struct file_operations rx_streaming_always_ops = {
648 .read = rx_streaming_always_read,
649 .write = rx_streaming_always_write,
650 .open = wl1271_open_file_generic,
651 .llseek = default_llseek,
652};
653
3c2c04a1
EP
654static int wl1271_debugfs_add_files(struct wl1271 *wl,
655 struct dentry *rootdir)
f5fc0f86
LC
656{
657 int ret = 0;
c84368e0 658 struct dentry *entry, *stats, *streaming;
7cb2cea9 659
3c2c04a1 660 stats = debugfs_create_dir("fw-statistics", rootdir);
7cb2cea9
EP
661 if (!stats || IS_ERR(stats)) {
662 entry = stats;
663 goto err;
664 }
f5fc0f86
LC
665
666 DEBUGFS_FWSTATS_ADD(tx, internal_desc_overflow);
667
668 DEBUGFS_FWSTATS_ADD(rx, out_of_mem);
669 DEBUGFS_FWSTATS_ADD(rx, hdr_overflow);
670 DEBUGFS_FWSTATS_ADD(rx, hw_stuck);
671 DEBUGFS_FWSTATS_ADD(rx, dropped);
672 DEBUGFS_FWSTATS_ADD(rx, fcs_err);
673 DEBUGFS_FWSTATS_ADD(rx, xfr_hint_trig);
674 DEBUGFS_FWSTATS_ADD(rx, path_reset);
675 DEBUGFS_FWSTATS_ADD(rx, reset_counter);
676
677 DEBUGFS_FWSTATS_ADD(dma, rx_requested);
678 DEBUGFS_FWSTATS_ADD(dma, rx_errors);
679 DEBUGFS_FWSTATS_ADD(dma, tx_requested);
680 DEBUGFS_FWSTATS_ADD(dma, tx_errors);
681
682 DEBUGFS_FWSTATS_ADD(isr, cmd_cmplt);
683 DEBUGFS_FWSTATS_ADD(isr, fiqs);
684 DEBUGFS_FWSTATS_ADD(isr, rx_headers);
685 DEBUGFS_FWSTATS_ADD(isr, rx_mem_overflow);
686 DEBUGFS_FWSTATS_ADD(isr, rx_rdys);
687 DEBUGFS_FWSTATS_ADD(isr, irqs);
688 DEBUGFS_FWSTATS_ADD(isr, tx_procs);
689 DEBUGFS_FWSTATS_ADD(isr, decrypt_done);
690 DEBUGFS_FWSTATS_ADD(isr, dma0_done);
691 DEBUGFS_FWSTATS_ADD(isr, dma1_done);
692 DEBUGFS_FWSTATS_ADD(isr, tx_exch_complete);
693 DEBUGFS_FWSTATS_ADD(isr, commands);
694 DEBUGFS_FWSTATS_ADD(isr, rx_procs);
695 DEBUGFS_FWSTATS_ADD(isr, hw_pm_mode_changes);
696 DEBUGFS_FWSTATS_ADD(isr, host_acknowledges);
697 DEBUGFS_FWSTATS_ADD(isr, pci_pm);
698 DEBUGFS_FWSTATS_ADD(isr, wakeups);
699 DEBUGFS_FWSTATS_ADD(isr, low_rssi);
700
701 DEBUGFS_FWSTATS_ADD(wep, addr_key_count);
702 DEBUGFS_FWSTATS_ADD(wep, default_key_count);
703 /* skipping wep.reserved */
704 DEBUGFS_FWSTATS_ADD(wep, key_not_found);
705 DEBUGFS_FWSTATS_ADD(wep, decrypt_fail);
706 DEBUGFS_FWSTATS_ADD(wep, packets);
707 DEBUGFS_FWSTATS_ADD(wep, interrupt);
708
709 DEBUGFS_FWSTATS_ADD(pwr, ps_enter);
710 DEBUGFS_FWSTATS_ADD(pwr, elp_enter);
711 DEBUGFS_FWSTATS_ADD(pwr, missing_bcns);
712 DEBUGFS_FWSTATS_ADD(pwr, wake_on_host);
713 DEBUGFS_FWSTATS_ADD(pwr, wake_on_timer_exp);
714 DEBUGFS_FWSTATS_ADD(pwr, tx_with_ps);
715 DEBUGFS_FWSTATS_ADD(pwr, tx_without_ps);
716 DEBUGFS_FWSTATS_ADD(pwr, rcvd_beacons);
717 DEBUGFS_FWSTATS_ADD(pwr, power_save_off);
718 DEBUGFS_FWSTATS_ADD(pwr, enable_ps);
719 DEBUGFS_FWSTATS_ADD(pwr, disable_ps);
720 DEBUGFS_FWSTATS_ADD(pwr, fix_tsf_ps);
721 /* skipping cont_miss_bcns_spread for now */
722 DEBUGFS_FWSTATS_ADD(pwr, rcvd_awake_beacons);
723
724 DEBUGFS_FWSTATS_ADD(mic, rx_pkts);
725 DEBUGFS_FWSTATS_ADD(mic, calc_failure);
726
727 DEBUGFS_FWSTATS_ADD(aes, encrypt_fail);
728 DEBUGFS_FWSTATS_ADD(aes, decrypt_fail);
729 DEBUGFS_FWSTATS_ADD(aes, encrypt_packets);
730 DEBUGFS_FWSTATS_ADD(aes, decrypt_packets);
731 DEBUGFS_FWSTATS_ADD(aes, encrypt_interrupt);
732 DEBUGFS_FWSTATS_ADD(aes, decrypt_interrupt);
733
734 DEBUGFS_FWSTATS_ADD(event, heart_beat);
735 DEBUGFS_FWSTATS_ADD(event, calibration);
736 DEBUGFS_FWSTATS_ADD(event, rx_mismatch);
737 DEBUGFS_FWSTATS_ADD(event, rx_mem_empty);
738 DEBUGFS_FWSTATS_ADD(event, rx_pool);
739 DEBUGFS_FWSTATS_ADD(event, oom_late);
740 DEBUGFS_FWSTATS_ADD(event, phy_transmit_error);
741 DEBUGFS_FWSTATS_ADD(event, tx_stuck);
742
743 DEBUGFS_FWSTATS_ADD(ps, pspoll_timeouts);
744 DEBUGFS_FWSTATS_ADD(ps, upsd_timeouts);
745 DEBUGFS_FWSTATS_ADD(ps, upsd_max_sptime);
746 DEBUGFS_FWSTATS_ADD(ps, upsd_max_apturn);
747 DEBUGFS_FWSTATS_ADD(ps, pspoll_max_apturn);
748 DEBUGFS_FWSTATS_ADD(ps, pspoll_utilization);
749 DEBUGFS_FWSTATS_ADD(ps, upsd_utilization);
750
751 DEBUGFS_FWSTATS_ADD(rxpipe, rx_prep_beacon_drop);
752 DEBUGFS_FWSTATS_ADD(rxpipe, descr_host_int_trig_rx_data);
753 DEBUGFS_FWSTATS_ADD(rxpipe, beacon_buffer_thres_host_int_trig_rx_data);
754 DEBUGFS_FWSTATS_ADD(rxpipe, missed_beacon_host_int_trig_rx_data);
755 DEBUGFS_FWSTATS_ADD(rxpipe, tx_xfr_host_int_trig_rx_data);
756
3c2c04a1
EP
757 DEBUGFS_ADD(tx_queue_len, rootdir);
758 DEBUGFS_ADD(retry_count, rootdir);
759 DEBUGFS_ADD(excessive_retries, rootdir);
f5fc0f86 760
3c2c04a1 761 DEBUGFS_ADD(gpio_power, rootdir);
2dc5a5c2 762 DEBUGFS_ADD(start_recovery, rootdir);
2d66bee7 763 DEBUGFS_ADD(driver_state, rootdir);
1fe9e246
EP
764 DEBUGFS_ADD(dtim_interval, rootdir);
765 DEBUGFS_ADD(beacon_interval, rootdir);
98b2a684 766
c84368e0
EP
767 streaming = debugfs_create_dir("rx_streaming", rootdir);
768 if (!streaming || IS_ERR(streaming))
769 goto err;
770
771 DEBUGFS_ADD_PREFIX(rx_streaming, interval, streaming);
772 DEBUGFS_ADD_PREFIX(rx_streaming, always, streaming);
773
774
7cb2cea9
EP
775 return 0;
776
777err:
778 if (IS_ERR(entry))
779 ret = PTR_ERR(entry);
780 else
781 ret = -ENOMEM;
f5fc0f86
LC
782
783 return ret;
784}
785
786void wl1271_debugfs_reset(struct wl1271 *wl)
787{
3c2c04a1 788 if (!wl->stats.fw_stats)
43a598d5
LC
789 return;
790
f5fc0f86
LC
791 memset(wl->stats.fw_stats, 0, sizeof(*wl->stats.fw_stats));
792 wl->stats.retry_count = 0;
793 wl->stats.excessive_retries = 0;
794}
795
796int wl1271_debugfs_init(struct wl1271 *wl)
797{
798 int ret;
3c2c04a1 799 struct dentry *rootdir;
f5fc0f86 800
3c2c04a1
EP
801 rootdir = debugfs_create_dir(KBUILD_MODNAME,
802 wl->hw->wiphy->debugfsdir);
f5fc0f86 803
3c2c04a1
EP
804 if (IS_ERR(rootdir)) {
805 ret = PTR_ERR(rootdir);
f5fc0f86
LC
806 goto err;
807 }
808
f5fc0f86
LC
809 wl->stats.fw_stats = kzalloc(sizeof(*wl->stats.fw_stats),
810 GFP_KERNEL);
811
812 if (!wl->stats.fw_stats) {
813 ret = -ENOMEM;
814 goto err_fw;
815 }
816
817 wl->stats.fw_stats_update = jiffies;
818
3c2c04a1 819 ret = wl1271_debugfs_add_files(wl, rootdir);
f5fc0f86
LC
820
821 if (ret < 0)
822 goto err_file;
823
824 return 0;
825
826err_file:
827 kfree(wl->stats.fw_stats);
828 wl->stats.fw_stats = NULL;
829
830err_fw:
3c2c04a1 831 debugfs_remove_recursive(rootdir);
f5fc0f86
LC
832
833err:
834 return ret;
835}
836
837void wl1271_debugfs_exit(struct wl1271 *wl)
838{
f5fc0f86
LC
839 kfree(wl->stats.fw_stats);
840 wl->stats.fw_stats = NULL;
f5fc0f86 841}
This page took 0.303816 seconds and 5 git commands to generate.