blob: 4d9c8cc076ec47fdc8aeb6abe11192f816aecf6c [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 Pellerc84368e2011-05-15 11:10:30 +030074#define DEBUGFS_ADD_PREFIX(prefix, name, parent) \
75 do { \
76 entry = debugfs_create_file(#name, 0400, parent, \
77 wl, &prefix## _## name## _ops); \
78 if (!entry || IS_ERR(entry)) \
79 goto err; \
80 } while (0);
81
Eliad Peller03107a42010-10-27 14:58:30 +020082#define DEBUGFS_FWSTATS_FILE(sub, name, fmt) \
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030083static ssize_t sub## _ ##name## _read(struct file *file, \
84 char __user *userbuf, \
85 size_t count, loff_t *ppos) \
86{ \
87 struct wl1271 *wl = file->private_data; \
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030088 \
89 wl1271_debugfs_update_stats(wl); \
90 \
Eliad Peller03107a42010-10-27 14:58:30 +020091 return wl1271_format_buffer(userbuf, count, ppos, fmt "\n", \
92 wl->stats.fw_stats->sub.name); \
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030093} \
94 \
95static const struct file_operations sub## _ ##name## _ops = { \
96 .read = sub## _ ##name## _read, \
97 .open = wl1271_open_file_generic, \
Arnd Bergmann2b18ab362010-07-06 19:05:31 +020098 .llseek = generic_file_llseek, \
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030099};
100
101#define DEBUGFS_FWSTATS_ADD(sub, name) \
Eliad Peller7cb2cea2010-11-24 12:53:15 +0200102 DEBUGFS_ADD(sub## _ ##name, stats)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300103
104static void wl1271_debugfs_update_stats(struct wl1271 *wl)
105{
106 int ret;
107
108 mutex_lock(&wl->mutex);
109
Ido Yariva6208652011-03-01 15:14:41 +0200110 ret = wl1271_ps_elp_wakeup(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300111 if (ret < 0)
112 goto out;
113
114 if (wl->state == WL1271_STATE_ON &&
115 time_after(jiffies, wl->stats.fw_stats_update +
116 msecs_to_jiffies(WL1271_DEBUGFS_STATS_LIFETIME))) {
117 wl1271_acx_statistics(wl, wl->stats.fw_stats);
118 wl->stats.fw_stats_update = jiffies;
119 }
120
121 wl1271_ps_elp_sleep(wl);
122
123out:
124 mutex_unlock(&wl->mutex);
125}
126
127static int wl1271_open_file_generic(struct inode *inode, struct file *file)
128{
129 file->private_data = inode->i_private;
130 return 0;
131}
132
Eliad Peller03107a42010-10-27 14:58:30 +0200133DEBUGFS_FWSTATS_FILE(tx, internal_desc_overflow, "%u");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300134
Eliad Peller03107a42010-10-27 14:58:30 +0200135DEBUGFS_FWSTATS_FILE(rx, out_of_mem, "%u");
136DEBUGFS_FWSTATS_FILE(rx, hdr_overflow, "%u");
137DEBUGFS_FWSTATS_FILE(rx, hw_stuck, "%u");
138DEBUGFS_FWSTATS_FILE(rx, dropped, "%u");
139DEBUGFS_FWSTATS_FILE(rx, fcs_err, "%u");
140DEBUGFS_FWSTATS_FILE(rx, xfr_hint_trig, "%u");
141DEBUGFS_FWSTATS_FILE(rx, path_reset, "%u");
142DEBUGFS_FWSTATS_FILE(rx, reset_counter, "%u");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300143
Eliad Peller03107a42010-10-27 14:58:30 +0200144DEBUGFS_FWSTATS_FILE(dma, rx_requested, "%u");
145DEBUGFS_FWSTATS_FILE(dma, rx_errors, "%u");
146DEBUGFS_FWSTATS_FILE(dma, tx_requested, "%u");
147DEBUGFS_FWSTATS_FILE(dma, tx_errors, "%u");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300148
Eliad Peller03107a42010-10-27 14:58:30 +0200149DEBUGFS_FWSTATS_FILE(isr, cmd_cmplt, "%u");
150DEBUGFS_FWSTATS_FILE(isr, fiqs, "%u");
151DEBUGFS_FWSTATS_FILE(isr, rx_headers, "%u");
152DEBUGFS_FWSTATS_FILE(isr, rx_mem_overflow, "%u");
153DEBUGFS_FWSTATS_FILE(isr, rx_rdys, "%u");
154DEBUGFS_FWSTATS_FILE(isr, irqs, "%u");
155DEBUGFS_FWSTATS_FILE(isr, tx_procs, "%u");
156DEBUGFS_FWSTATS_FILE(isr, decrypt_done, "%u");
157DEBUGFS_FWSTATS_FILE(isr, dma0_done, "%u");
158DEBUGFS_FWSTATS_FILE(isr, dma1_done, "%u");
159DEBUGFS_FWSTATS_FILE(isr, tx_exch_complete, "%u");
160DEBUGFS_FWSTATS_FILE(isr, commands, "%u");
161DEBUGFS_FWSTATS_FILE(isr, rx_procs, "%u");
162DEBUGFS_FWSTATS_FILE(isr, hw_pm_mode_changes, "%u");
163DEBUGFS_FWSTATS_FILE(isr, host_acknowledges, "%u");
164DEBUGFS_FWSTATS_FILE(isr, pci_pm, "%u");
165DEBUGFS_FWSTATS_FILE(isr, wakeups, "%u");
166DEBUGFS_FWSTATS_FILE(isr, low_rssi, "%u");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300167
Eliad Peller03107a42010-10-27 14:58:30 +0200168DEBUGFS_FWSTATS_FILE(wep, addr_key_count, "%u");
169DEBUGFS_FWSTATS_FILE(wep, default_key_count, "%u");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300170/* skipping wep.reserved */
Eliad Peller03107a42010-10-27 14:58:30 +0200171DEBUGFS_FWSTATS_FILE(wep, key_not_found, "%u");
172DEBUGFS_FWSTATS_FILE(wep, decrypt_fail, "%u");
173DEBUGFS_FWSTATS_FILE(wep, packets, "%u");
174DEBUGFS_FWSTATS_FILE(wep, interrupt, "%u");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300175
Eliad Peller03107a42010-10-27 14:58:30 +0200176DEBUGFS_FWSTATS_FILE(pwr, ps_enter, "%u");
177DEBUGFS_FWSTATS_FILE(pwr, elp_enter, "%u");
178DEBUGFS_FWSTATS_FILE(pwr, missing_bcns, "%u");
179DEBUGFS_FWSTATS_FILE(pwr, wake_on_host, "%u");
180DEBUGFS_FWSTATS_FILE(pwr, wake_on_timer_exp, "%u");
181DEBUGFS_FWSTATS_FILE(pwr, tx_with_ps, "%u");
182DEBUGFS_FWSTATS_FILE(pwr, tx_without_ps, "%u");
183DEBUGFS_FWSTATS_FILE(pwr, rcvd_beacons, "%u");
184DEBUGFS_FWSTATS_FILE(pwr, power_save_off, "%u");
185DEBUGFS_FWSTATS_FILE(pwr, enable_ps, "%u");
186DEBUGFS_FWSTATS_FILE(pwr, disable_ps, "%u");
187DEBUGFS_FWSTATS_FILE(pwr, fix_tsf_ps, "%u");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300188/* skipping cont_miss_bcns_spread for now */
Eliad Peller03107a42010-10-27 14:58:30 +0200189DEBUGFS_FWSTATS_FILE(pwr, rcvd_awake_beacons, "%u");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300190
Eliad Peller03107a42010-10-27 14:58:30 +0200191DEBUGFS_FWSTATS_FILE(mic, rx_pkts, "%u");
192DEBUGFS_FWSTATS_FILE(mic, calc_failure, "%u");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300193
Eliad Peller03107a42010-10-27 14:58:30 +0200194DEBUGFS_FWSTATS_FILE(aes, encrypt_fail, "%u");
195DEBUGFS_FWSTATS_FILE(aes, decrypt_fail, "%u");
196DEBUGFS_FWSTATS_FILE(aes, encrypt_packets, "%u");
197DEBUGFS_FWSTATS_FILE(aes, decrypt_packets, "%u");
198DEBUGFS_FWSTATS_FILE(aes, encrypt_interrupt, "%u");
199DEBUGFS_FWSTATS_FILE(aes, decrypt_interrupt, "%u");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300200
Eliad Peller03107a42010-10-27 14:58:30 +0200201DEBUGFS_FWSTATS_FILE(event, heart_beat, "%u");
202DEBUGFS_FWSTATS_FILE(event, calibration, "%u");
203DEBUGFS_FWSTATS_FILE(event, rx_mismatch, "%u");
204DEBUGFS_FWSTATS_FILE(event, rx_mem_empty, "%u");
205DEBUGFS_FWSTATS_FILE(event, rx_pool, "%u");
206DEBUGFS_FWSTATS_FILE(event, oom_late, "%u");
207DEBUGFS_FWSTATS_FILE(event, phy_transmit_error, "%u");
208DEBUGFS_FWSTATS_FILE(event, tx_stuck, "%u");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300209
Eliad Peller03107a42010-10-27 14:58:30 +0200210DEBUGFS_FWSTATS_FILE(ps, pspoll_timeouts, "%u");
211DEBUGFS_FWSTATS_FILE(ps, upsd_timeouts, "%u");
212DEBUGFS_FWSTATS_FILE(ps, upsd_max_sptime, "%u");
213DEBUGFS_FWSTATS_FILE(ps, upsd_max_apturn, "%u");
214DEBUGFS_FWSTATS_FILE(ps, pspoll_max_apturn, "%u");
215DEBUGFS_FWSTATS_FILE(ps, pspoll_utilization, "%u");
216DEBUGFS_FWSTATS_FILE(ps, upsd_utilization, "%u");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300217
Eliad Peller03107a42010-10-27 14:58:30 +0200218DEBUGFS_FWSTATS_FILE(rxpipe, rx_prep_beacon_drop, "%u");
219DEBUGFS_FWSTATS_FILE(rxpipe, descr_host_int_trig_rx_data, "%u");
220DEBUGFS_FWSTATS_FILE(rxpipe, beacon_buffer_thres_host_int_trig_rx_data, "%u");
221DEBUGFS_FWSTATS_FILE(rxpipe, missed_beacon_host_int_trig_rx_data, "%u");
222DEBUGFS_FWSTATS_FILE(rxpipe, tx_xfr_host_int_trig_rx_data, "%u");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300223
Eliad Peller03107a42010-10-27 14:58:30 +0200224DEBUGFS_READONLY_FILE(retry_count, "%u", wl->stats.retry_count);
225DEBUGFS_READONLY_FILE(excessive_retries, "%u",
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300226 wl->stats.excessive_retries);
227
228static ssize_t tx_queue_len_read(struct file *file, char __user *userbuf,
229 size_t count, loff_t *ppos)
230{
231 struct wl1271 *wl = file->private_data;
232 u32 queue_len;
233 char buf[20];
234 int res;
235
Juuso Oikarinen6742f552010-12-13 09:52:37 +0200236 queue_len = wl->tx_queue_count;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300237
238 res = scnprintf(buf, sizeof(buf), "%u\n", queue_len);
239 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
240}
241
242static const struct file_operations tx_queue_len_ops = {
243 .read = tx_queue_len_read,
244 .open = wl1271_open_file_generic,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200245 .llseek = default_llseek,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300246};
247
Luciano Coelho98b2a682009-12-11 15:40:52 +0200248static ssize_t gpio_power_read(struct file *file, char __user *user_buf,
249 size_t count, loff_t *ppos)
250{
251 struct wl1271 *wl = file->private_data;
Juuso Oikarinen71449f82009-12-11 15:41:07 +0200252 bool state = test_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
253
Luciano Coelho98b2a682009-12-11 15:40:52 +0200254 int res;
255 char buf[10];
256
Juuso Oikarinen71449f82009-12-11 15:41:07 +0200257 res = scnprintf(buf, sizeof(buf), "%d\n", state);
Luciano Coelho98b2a682009-12-11 15:40:52 +0200258
259 return simple_read_from_buffer(user_buf, count, ppos, buf, res);
260}
261
262static ssize_t gpio_power_write(struct file *file,
263 const char __user *user_buf,
264 size_t count, loff_t *ppos)
265{
266 struct wl1271 *wl = file->private_data;
267 char buf[10];
268 size_t len;
269 unsigned long value;
270 int ret;
271
Luciano Coelho98b2a682009-12-11 15:40:52 +0200272 len = min(count, sizeof(buf) - 1);
273 if (copy_from_user(buf, user_buf, len)) {
Eliad Peller8e2de742011-01-23 11:25:27 +0100274 return -EFAULT;
Luciano Coelho98b2a682009-12-11 15:40:52 +0200275 }
276 buf[len] = '\0';
277
Luciano Coelho6277ed62011-04-01 17:49:54 +0300278 ret = kstrtoul(buf, 0, &value);
Luciano Coelho98b2a682009-12-11 15:40:52 +0200279 if (ret < 0) {
280 wl1271_warning("illegal value in gpio_power");
Eliad Peller8e2de742011-01-23 11:25:27 +0100281 return -EINVAL;
Luciano Coelho98b2a682009-12-11 15:40:52 +0200282 }
283
Eliad Peller8e2de742011-01-23 11:25:27 +0100284 mutex_lock(&wl->mutex);
285
Teemu Paasikivibecd5512010-03-18 12:26:27 +0200286 if (value)
287 wl1271_power_on(wl);
288 else
289 wl1271_power_off(wl);
Luciano Coelho98b2a682009-12-11 15:40:52 +0200290
Luciano Coelho98b2a682009-12-11 15:40:52 +0200291 mutex_unlock(&wl->mutex);
292 return count;
293}
294
295static const struct file_operations gpio_power_ops = {
296 .read = gpio_power_read,
297 .write = gpio_power_write,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200298 .open = wl1271_open_file_generic,
299 .llseek = default_llseek,
Luciano Coelho98b2a682009-12-11 15:40:52 +0200300};
301
Arik Nemtsov2dc5a5c2011-04-18 14:15:27 +0300302static ssize_t start_recovery_write(struct file *file,
303 const char __user *user_buf,
304 size_t count, loff_t *ppos)
305{
306 struct wl1271 *wl = file->private_data;
307
308 mutex_lock(&wl->mutex);
Ido Yarivbaacb9a2011-06-06 14:57:05 +0300309 wl12xx_queue_recovery_work(wl);
Arik Nemtsov2dc5a5c2011-04-18 14:15:27 +0300310 mutex_unlock(&wl->mutex);
311
312 return count;
313}
314
315static const struct file_operations start_recovery_ops = {
316 .write = start_recovery_write,
317 .open = wl1271_open_file_generic,
318 .llseek = default_llseek,
319};
320
Arik Nemtsov2d66bee2011-04-18 14:15:29 +0300321static ssize_t driver_state_read(struct file *file, char __user *user_buf,
322 size_t count, loff_t *ppos)
323{
324 struct wl1271 *wl = file->private_data;
325 int res = 0;
326 char buf[1024];
327
328 mutex_lock(&wl->mutex);
329
330#define DRIVER_STATE_PRINT(x, fmt) \
331 (res += scnprintf(buf + res, sizeof(buf) - res,\
332 #x " = " fmt "\n", wl->x))
333
334#define DRIVER_STATE_PRINT_LONG(x) DRIVER_STATE_PRINT(x, "%ld")
335#define DRIVER_STATE_PRINT_INT(x) DRIVER_STATE_PRINT(x, "%d")
336#define DRIVER_STATE_PRINT_STR(x) DRIVER_STATE_PRINT(x, "%s")
337#define DRIVER_STATE_PRINT_LHEX(x) DRIVER_STATE_PRINT(x, "0x%lx")
338#define DRIVER_STATE_PRINT_HEX(x) DRIVER_STATE_PRINT(x, "0x%x")
339
340 DRIVER_STATE_PRINT_INT(tx_blocks_available);
Arik Nemtsov9e374a32011-06-24 13:03:35 +0300341 DRIVER_STATE_PRINT_INT(tx_allocated_blocks[0]);
342 DRIVER_STATE_PRINT_INT(tx_allocated_blocks[1]);
343 DRIVER_STATE_PRINT_INT(tx_allocated_blocks[2]);
344 DRIVER_STATE_PRINT_INT(tx_allocated_blocks[3]);
Arik Nemtsov2d66bee2011-04-18 14:15:29 +0300345 DRIVER_STATE_PRINT_INT(tx_frames_cnt);
346 DRIVER_STATE_PRINT_LHEX(tx_frames_map[0]);
347 DRIVER_STATE_PRINT_INT(tx_queue_count);
348 DRIVER_STATE_PRINT_INT(tx_packets_count);
349 DRIVER_STATE_PRINT_INT(tx_results_count);
350 DRIVER_STATE_PRINT_LHEX(flags);
351 DRIVER_STATE_PRINT_INT(tx_blocks_freed[0]);
352 DRIVER_STATE_PRINT_INT(tx_blocks_freed[1]);
353 DRIVER_STATE_PRINT_INT(tx_blocks_freed[2]);
354 DRIVER_STATE_PRINT_INT(tx_blocks_freed[3]);
Oz Krakowskib992c682011-06-26 10:36:02 +0300355 DRIVER_STATE_PRINT_INT(tx_security_last_seq_lsb);
Arik Nemtsov2d66bee2011-04-18 14:15:29 +0300356 DRIVER_STATE_PRINT_INT(rx_counter);
357 DRIVER_STATE_PRINT_INT(session_counter);
358 DRIVER_STATE_PRINT_INT(state);
359 DRIVER_STATE_PRINT_INT(bss_type);
360 DRIVER_STATE_PRINT_INT(channel);
361 DRIVER_STATE_PRINT_HEX(rate_set);
362 DRIVER_STATE_PRINT_HEX(basic_rate_set);
363 DRIVER_STATE_PRINT_HEX(basic_rate);
364 DRIVER_STATE_PRINT_INT(band);
365 DRIVER_STATE_PRINT_INT(beacon_int);
366 DRIVER_STATE_PRINT_INT(psm_entry_retry);
367 DRIVER_STATE_PRINT_INT(ps_poll_failures);
368 DRIVER_STATE_PRINT_HEX(filters);
369 DRIVER_STATE_PRINT_HEX(rx_config);
370 DRIVER_STATE_PRINT_HEX(rx_filter);
371 DRIVER_STATE_PRINT_INT(power_level);
372 DRIVER_STATE_PRINT_INT(rssi_thold);
373 DRIVER_STATE_PRINT_INT(last_rssi_event);
374 DRIVER_STATE_PRINT_INT(sg_enabled);
375 DRIVER_STATE_PRINT_INT(enable_11a);
376 DRIVER_STATE_PRINT_INT(noise);
377 DRIVER_STATE_PRINT_LHEX(ap_hlid_map[0]);
378 DRIVER_STATE_PRINT_INT(last_tx_hlid);
379 DRIVER_STATE_PRINT_INT(ba_support);
380 DRIVER_STATE_PRINT_HEX(ba_rx_bitmap);
381 DRIVER_STATE_PRINT_HEX(ap_fw_ps_map);
382 DRIVER_STATE_PRINT_LHEX(ap_ps_map);
383 DRIVER_STATE_PRINT_HEX(quirks);
384 DRIVER_STATE_PRINT_HEX(irq);
385 DRIVER_STATE_PRINT_HEX(ref_clock);
386 DRIVER_STATE_PRINT_HEX(tcxo_clock);
387 DRIVER_STATE_PRINT_HEX(hw_pg_ver);
388 DRIVER_STATE_PRINT_HEX(platform_quirks);
389 DRIVER_STATE_PRINT_HEX(chip.id);
390 DRIVER_STATE_PRINT_STR(chip.fw_ver_str);
Luciano Coelhod3eff812011-05-10 14:47:45 +0300391 DRIVER_STATE_PRINT_INT(sched_scanning);
Arik Nemtsov2d66bee2011-04-18 14:15:29 +0300392
393#undef DRIVER_STATE_PRINT_INT
394#undef DRIVER_STATE_PRINT_LONG
395#undef DRIVER_STATE_PRINT_HEX
396#undef DRIVER_STATE_PRINT_LHEX
397#undef DRIVER_STATE_PRINT_STR
398#undef DRIVER_STATE_PRINT
399
400 mutex_unlock(&wl->mutex);
401
402 return simple_read_from_buffer(user_buf, count, ppos, buf, res);
403}
404
405static const struct file_operations driver_state_ops = {
406 .read = driver_state_read,
407 .open = wl1271_open_file_generic,
408 .llseek = default_llseek,
409};
410
Eliad Peller1fe9e242011-04-17 11:20:47 +0300411static ssize_t dtim_interval_read(struct file *file, char __user *user_buf,
412 size_t count, loff_t *ppos)
413{
414 struct wl1271 *wl = file->private_data;
415 u8 value;
416
417 if (wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_DTIM ||
418 wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_N_DTIM)
419 value = wl->conf.conn.listen_interval;
420 else
421 value = 0;
422
423 return wl1271_format_buffer(user_buf, count, ppos, "%d\n", value);
424}
425
426static ssize_t dtim_interval_write(struct file *file,
427 const char __user *user_buf,
428 size_t count, loff_t *ppos)
429{
430 struct wl1271 *wl = file->private_data;
431 char buf[10];
432 size_t len;
433 unsigned long value;
434 int ret;
435
436 len = min(count, sizeof(buf) - 1);
437 if (copy_from_user(buf, user_buf, len))
438 return -EFAULT;
439 buf[len] = '\0';
440
Luciano Coelhof7c7c7e2011-04-29 22:25:28 +0300441 ret = kstrtoul(buf, 0, &value);
Eliad Peller1fe9e242011-04-17 11:20:47 +0300442 if (ret < 0) {
443 wl1271_warning("illegal value for dtim_interval");
444 return -EINVAL;
445 }
446
447 if (value < 1 || value > 10) {
448 wl1271_warning("dtim value is not in valid range");
449 return -ERANGE;
450 }
451
452 mutex_lock(&wl->mutex);
453
454 wl->conf.conn.listen_interval = value;
455 /* for some reason there are different event types for 1 and >1 */
456 if (value == 1)
457 wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_DTIM;
458 else
459 wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_N_DTIM;
460
461 /*
462 * we don't reconfigure ACX_WAKE_UP_CONDITIONS now, so it will only
463 * take effect on the next time we enter psm.
464 */
465 mutex_unlock(&wl->mutex);
466 return count;
467}
468
469static const struct file_operations dtim_interval_ops = {
470 .read = dtim_interval_read,
471 .write = dtim_interval_write,
472 .open = wl1271_open_file_generic,
473 .llseek = default_llseek,
474};
475
476static ssize_t beacon_interval_read(struct file *file, char __user *user_buf,
477 size_t count, loff_t *ppos)
478{
479 struct wl1271 *wl = file->private_data;
480 u8 value;
481
482 if (wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_BEACON ||
483 wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_N_BEACONS)
484 value = wl->conf.conn.listen_interval;
485 else
486 value = 0;
487
488 return wl1271_format_buffer(user_buf, count, ppos, "%d\n", value);
489}
490
491static ssize_t beacon_interval_write(struct file *file,
492 const char __user *user_buf,
493 size_t count, loff_t *ppos)
494{
495 struct wl1271 *wl = file->private_data;
496 char buf[10];
497 size_t len;
498 unsigned long value;
499 int ret;
500
501 len = min(count, sizeof(buf) - 1);
502 if (copy_from_user(buf, user_buf, len))
503 return -EFAULT;
504 buf[len] = '\0';
505
Luciano Coelhof7c7c7e2011-04-29 22:25:28 +0300506 ret = kstrtoul(buf, 0, &value);
Eliad Peller1fe9e242011-04-17 11:20:47 +0300507 if (ret < 0) {
508 wl1271_warning("illegal value for beacon_interval");
509 return -EINVAL;
510 }
511
512 if (value < 1 || value > 255) {
513 wl1271_warning("beacon interval value is not in valid range");
514 return -ERANGE;
515 }
516
517 mutex_lock(&wl->mutex);
518
519 wl->conf.conn.listen_interval = value;
520 /* for some reason there are different event types for 1 and >1 */
521 if (value == 1)
522 wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_BEACON;
523 else
524 wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_N_BEACONS;
525
526 /*
527 * we don't reconfigure ACX_WAKE_UP_CONDITIONS now, so it will only
528 * take effect on the next time we enter psm.
529 */
530 mutex_unlock(&wl->mutex);
531 return count;
532}
533
534static const struct file_operations beacon_interval_ops = {
535 .read = beacon_interval_read,
536 .write = beacon_interval_write,
537 .open = wl1271_open_file_generic,
538 .llseek = default_llseek,
539};
540
Eliad Pellerc84368e2011-05-15 11:10:30 +0300541static ssize_t rx_streaming_interval_write(struct file *file,
542 const char __user *user_buf,
543 size_t count, loff_t *ppos)
544{
545 struct wl1271 *wl = file->private_data;
546 char buf[10];
547 size_t len;
548 unsigned long value;
549 int ret;
550
551 len = min(count, sizeof(buf) - 1);
552 if (copy_from_user(buf, user_buf, len))
553 return -EFAULT;
554 buf[len] = '\0';
555
556 ret = kstrtoul(buf, 0, &value);
557 if (ret < 0) {
558 wl1271_warning("illegal value in rx_streaming_interval!");
559 return -EINVAL;
560 }
561
562 /* valid values: 0, 10-100 */
563 if (value && (value < 10 || value > 100)) {
564 wl1271_warning("value is not in range!");
565 return -ERANGE;
566 }
567
568 mutex_lock(&wl->mutex);
569
570 wl->conf.rx_streaming.interval = value;
571
572 ret = wl1271_ps_elp_wakeup(wl);
573 if (ret < 0)
574 goto out;
575
576 wl1271_recalc_rx_streaming(wl);
577
578 wl1271_ps_elp_sleep(wl);
579out:
580 mutex_unlock(&wl->mutex);
581 return count;
582}
583
584static ssize_t rx_streaming_interval_read(struct file *file,
585 char __user *userbuf,
586 size_t count, loff_t *ppos)
587{
588 struct wl1271 *wl = file->private_data;
589 return wl1271_format_buffer(userbuf, count, ppos,
590 "%d\n", wl->conf.rx_streaming.interval);
591}
592
593static const struct file_operations rx_streaming_interval_ops = {
594 .read = rx_streaming_interval_read,
595 .write = rx_streaming_interval_write,
596 .open = wl1271_open_file_generic,
597 .llseek = default_llseek,
598};
599
600static ssize_t rx_streaming_always_write(struct file *file,
601 const char __user *user_buf,
602 size_t count, loff_t *ppos)
603{
604 struct wl1271 *wl = file->private_data;
605 char buf[10];
606 size_t len;
607 unsigned long value;
608 int ret;
609
610 len = min(count, sizeof(buf) - 1);
611 if (copy_from_user(buf, user_buf, len))
612 return -EFAULT;
613 buf[len] = '\0';
614
615 ret = kstrtoul(buf, 0, &value);
616 if (ret < 0) {
617 wl1271_warning("illegal value in rx_streaming_write!");
618 return -EINVAL;
619 }
620
621 /* valid values: 0, 10-100 */
622 if (!(value == 0 || value == 1)) {
623 wl1271_warning("value is not in valid!");
624 return -EINVAL;
625 }
626
627 mutex_lock(&wl->mutex);
628
629 wl->conf.rx_streaming.always = value;
630
631 ret = wl1271_ps_elp_wakeup(wl);
632 if (ret < 0)
633 goto out;
634
635 wl1271_recalc_rx_streaming(wl);
636
637 wl1271_ps_elp_sleep(wl);
638out:
639 mutex_unlock(&wl->mutex);
640 return count;
641}
642
643static ssize_t rx_streaming_always_read(struct file *file,
644 char __user *userbuf,
645 size_t count, loff_t *ppos)
646{
647 struct wl1271 *wl = file->private_data;
648 return wl1271_format_buffer(userbuf, count, ppos,
649 "%d\n", wl->conf.rx_streaming.always);
650}
651
652static const struct file_operations rx_streaming_always_ops = {
653 .read = rx_streaming_always_read,
654 .write = rx_streaming_always_write,
655 .open = wl1271_open_file_generic,
656 .llseek = default_llseek,
657};
658
Eliad Peller3c2c04a2010-12-15 11:47:54 +0200659static int wl1271_debugfs_add_files(struct wl1271 *wl,
660 struct dentry *rootdir)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300661{
662 int ret = 0;
Eliad Pellerc84368e2011-05-15 11:10:30 +0300663 struct dentry *entry, *stats, *streaming;
Eliad Peller7cb2cea2010-11-24 12:53:15 +0200664
Eliad Peller3c2c04a2010-12-15 11:47:54 +0200665 stats = debugfs_create_dir("fw-statistics", rootdir);
Eliad Peller7cb2cea2010-11-24 12:53:15 +0200666 if (!stats || IS_ERR(stats)) {
667 entry = stats;
668 goto err;
669 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300670
671 DEBUGFS_FWSTATS_ADD(tx, internal_desc_overflow);
672
673 DEBUGFS_FWSTATS_ADD(rx, out_of_mem);
674 DEBUGFS_FWSTATS_ADD(rx, hdr_overflow);
675 DEBUGFS_FWSTATS_ADD(rx, hw_stuck);
676 DEBUGFS_FWSTATS_ADD(rx, dropped);
677 DEBUGFS_FWSTATS_ADD(rx, fcs_err);
678 DEBUGFS_FWSTATS_ADD(rx, xfr_hint_trig);
679 DEBUGFS_FWSTATS_ADD(rx, path_reset);
680 DEBUGFS_FWSTATS_ADD(rx, reset_counter);
681
682 DEBUGFS_FWSTATS_ADD(dma, rx_requested);
683 DEBUGFS_FWSTATS_ADD(dma, rx_errors);
684 DEBUGFS_FWSTATS_ADD(dma, tx_requested);
685 DEBUGFS_FWSTATS_ADD(dma, tx_errors);
686
687 DEBUGFS_FWSTATS_ADD(isr, cmd_cmplt);
688 DEBUGFS_FWSTATS_ADD(isr, fiqs);
689 DEBUGFS_FWSTATS_ADD(isr, rx_headers);
690 DEBUGFS_FWSTATS_ADD(isr, rx_mem_overflow);
691 DEBUGFS_FWSTATS_ADD(isr, rx_rdys);
692 DEBUGFS_FWSTATS_ADD(isr, irqs);
693 DEBUGFS_FWSTATS_ADD(isr, tx_procs);
694 DEBUGFS_FWSTATS_ADD(isr, decrypt_done);
695 DEBUGFS_FWSTATS_ADD(isr, dma0_done);
696 DEBUGFS_FWSTATS_ADD(isr, dma1_done);
697 DEBUGFS_FWSTATS_ADD(isr, tx_exch_complete);
698 DEBUGFS_FWSTATS_ADD(isr, commands);
699 DEBUGFS_FWSTATS_ADD(isr, rx_procs);
700 DEBUGFS_FWSTATS_ADD(isr, hw_pm_mode_changes);
701 DEBUGFS_FWSTATS_ADD(isr, host_acknowledges);
702 DEBUGFS_FWSTATS_ADD(isr, pci_pm);
703 DEBUGFS_FWSTATS_ADD(isr, wakeups);
704 DEBUGFS_FWSTATS_ADD(isr, low_rssi);
705
706 DEBUGFS_FWSTATS_ADD(wep, addr_key_count);
707 DEBUGFS_FWSTATS_ADD(wep, default_key_count);
708 /* skipping wep.reserved */
709 DEBUGFS_FWSTATS_ADD(wep, key_not_found);
710 DEBUGFS_FWSTATS_ADD(wep, decrypt_fail);
711 DEBUGFS_FWSTATS_ADD(wep, packets);
712 DEBUGFS_FWSTATS_ADD(wep, interrupt);
713
714 DEBUGFS_FWSTATS_ADD(pwr, ps_enter);
715 DEBUGFS_FWSTATS_ADD(pwr, elp_enter);
716 DEBUGFS_FWSTATS_ADD(pwr, missing_bcns);
717 DEBUGFS_FWSTATS_ADD(pwr, wake_on_host);
718 DEBUGFS_FWSTATS_ADD(pwr, wake_on_timer_exp);
719 DEBUGFS_FWSTATS_ADD(pwr, tx_with_ps);
720 DEBUGFS_FWSTATS_ADD(pwr, tx_without_ps);
721 DEBUGFS_FWSTATS_ADD(pwr, rcvd_beacons);
722 DEBUGFS_FWSTATS_ADD(pwr, power_save_off);
723 DEBUGFS_FWSTATS_ADD(pwr, enable_ps);
724 DEBUGFS_FWSTATS_ADD(pwr, disable_ps);
725 DEBUGFS_FWSTATS_ADD(pwr, fix_tsf_ps);
726 /* skipping cont_miss_bcns_spread for now */
727 DEBUGFS_FWSTATS_ADD(pwr, rcvd_awake_beacons);
728
729 DEBUGFS_FWSTATS_ADD(mic, rx_pkts);
730 DEBUGFS_FWSTATS_ADD(mic, calc_failure);
731
732 DEBUGFS_FWSTATS_ADD(aes, encrypt_fail);
733 DEBUGFS_FWSTATS_ADD(aes, decrypt_fail);
734 DEBUGFS_FWSTATS_ADD(aes, encrypt_packets);
735 DEBUGFS_FWSTATS_ADD(aes, decrypt_packets);
736 DEBUGFS_FWSTATS_ADD(aes, encrypt_interrupt);
737 DEBUGFS_FWSTATS_ADD(aes, decrypt_interrupt);
738
739 DEBUGFS_FWSTATS_ADD(event, heart_beat);
740 DEBUGFS_FWSTATS_ADD(event, calibration);
741 DEBUGFS_FWSTATS_ADD(event, rx_mismatch);
742 DEBUGFS_FWSTATS_ADD(event, rx_mem_empty);
743 DEBUGFS_FWSTATS_ADD(event, rx_pool);
744 DEBUGFS_FWSTATS_ADD(event, oom_late);
745 DEBUGFS_FWSTATS_ADD(event, phy_transmit_error);
746 DEBUGFS_FWSTATS_ADD(event, tx_stuck);
747
748 DEBUGFS_FWSTATS_ADD(ps, pspoll_timeouts);
749 DEBUGFS_FWSTATS_ADD(ps, upsd_timeouts);
750 DEBUGFS_FWSTATS_ADD(ps, upsd_max_sptime);
751 DEBUGFS_FWSTATS_ADD(ps, upsd_max_apturn);
752 DEBUGFS_FWSTATS_ADD(ps, pspoll_max_apturn);
753 DEBUGFS_FWSTATS_ADD(ps, pspoll_utilization);
754 DEBUGFS_FWSTATS_ADD(ps, upsd_utilization);
755
756 DEBUGFS_FWSTATS_ADD(rxpipe, rx_prep_beacon_drop);
757 DEBUGFS_FWSTATS_ADD(rxpipe, descr_host_int_trig_rx_data);
758 DEBUGFS_FWSTATS_ADD(rxpipe, beacon_buffer_thres_host_int_trig_rx_data);
759 DEBUGFS_FWSTATS_ADD(rxpipe, missed_beacon_host_int_trig_rx_data);
760 DEBUGFS_FWSTATS_ADD(rxpipe, tx_xfr_host_int_trig_rx_data);
761
Eliad Peller3c2c04a2010-12-15 11:47:54 +0200762 DEBUGFS_ADD(tx_queue_len, rootdir);
763 DEBUGFS_ADD(retry_count, rootdir);
764 DEBUGFS_ADD(excessive_retries, rootdir);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300765
Eliad Peller3c2c04a2010-12-15 11:47:54 +0200766 DEBUGFS_ADD(gpio_power, rootdir);
Arik Nemtsov2dc5a5c2011-04-18 14:15:27 +0300767 DEBUGFS_ADD(start_recovery, rootdir);
Arik Nemtsov2d66bee2011-04-18 14:15:29 +0300768 DEBUGFS_ADD(driver_state, rootdir);
Eliad Peller1fe9e242011-04-17 11:20:47 +0300769 DEBUGFS_ADD(dtim_interval, rootdir);
770 DEBUGFS_ADD(beacon_interval, rootdir);
Luciano Coelho98b2a682009-12-11 15:40:52 +0200771
Eliad Pellerc84368e2011-05-15 11:10:30 +0300772 streaming = debugfs_create_dir("rx_streaming", rootdir);
773 if (!streaming || IS_ERR(streaming))
774 goto err;
775
776 DEBUGFS_ADD_PREFIX(rx_streaming, interval, streaming);
777 DEBUGFS_ADD_PREFIX(rx_streaming, always, streaming);
778
779
Eliad Peller7cb2cea2010-11-24 12:53:15 +0200780 return 0;
781
782err:
783 if (IS_ERR(entry))
784 ret = PTR_ERR(entry);
785 else
786 ret = -ENOMEM;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300787
788 return ret;
789}
790
791void wl1271_debugfs_reset(struct wl1271 *wl)
792{
Eliad Peller3c2c04a2010-12-15 11:47:54 +0200793 if (!wl->stats.fw_stats)
Luciano Coelho43a598d2010-11-30 14:58:46 +0200794 return;
795
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300796 memset(wl->stats.fw_stats, 0, sizeof(*wl->stats.fw_stats));
797 wl->stats.retry_count = 0;
798 wl->stats.excessive_retries = 0;
799}
800
801int wl1271_debugfs_init(struct wl1271 *wl)
802{
803 int ret;
Eliad Peller3c2c04a2010-12-15 11:47:54 +0200804 struct dentry *rootdir;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300805
Eliad Peller3c2c04a2010-12-15 11:47:54 +0200806 rootdir = debugfs_create_dir(KBUILD_MODNAME,
807 wl->hw->wiphy->debugfsdir);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300808
Eliad Peller3c2c04a2010-12-15 11:47:54 +0200809 if (IS_ERR(rootdir)) {
810 ret = PTR_ERR(rootdir);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300811 goto err;
812 }
813
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300814 wl->stats.fw_stats = kzalloc(sizeof(*wl->stats.fw_stats),
815 GFP_KERNEL);
816
817 if (!wl->stats.fw_stats) {
818 ret = -ENOMEM;
819 goto err_fw;
820 }
821
822 wl->stats.fw_stats_update = jiffies;
823
Eliad Peller3c2c04a2010-12-15 11:47:54 +0200824 ret = wl1271_debugfs_add_files(wl, rootdir);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300825
826 if (ret < 0)
827 goto err_file;
828
829 return 0;
830
831err_file:
832 kfree(wl->stats.fw_stats);
833 wl->stats.fw_stats = NULL;
834
835err_fw:
Eliad Peller3c2c04a2010-12-15 11:47:54 +0200836 debugfs_remove_recursive(rootdir);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300837
838err:
839 return ret;
840}
841
842void wl1271_debugfs_exit(struct wl1271 *wl)
843{
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300844 kfree(wl->stats.fw_stats);
845 wl->stats.fw_stats = NULL;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300846}