blob: da21270183003f7202549310c36705132b13dd8f [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 Yarivbaacb9ae2011-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);
341 DRIVER_STATE_PRINT_INT(tx_allocated_blocks);
342 DRIVER_STATE_PRINT_INT(tx_frames_cnt);
343 DRIVER_STATE_PRINT_LHEX(tx_frames_map[0]);
344 DRIVER_STATE_PRINT_INT(tx_queue_count);
345 DRIVER_STATE_PRINT_INT(tx_packets_count);
346 DRIVER_STATE_PRINT_INT(tx_results_count);
347 DRIVER_STATE_PRINT_LHEX(flags);
348 DRIVER_STATE_PRINT_INT(tx_blocks_freed[0]);
349 DRIVER_STATE_PRINT_INT(tx_blocks_freed[1]);
350 DRIVER_STATE_PRINT_INT(tx_blocks_freed[2]);
351 DRIVER_STATE_PRINT_INT(tx_blocks_freed[3]);
352 DRIVER_STATE_PRINT_INT(tx_security_last_seq);
353 DRIVER_STATE_PRINT_INT(rx_counter);
354 DRIVER_STATE_PRINT_INT(session_counter);
355 DRIVER_STATE_PRINT_INT(state);
356 DRIVER_STATE_PRINT_INT(bss_type);
357 DRIVER_STATE_PRINT_INT(channel);
358 DRIVER_STATE_PRINT_HEX(rate_set);
359 DRIVER_STATE_PRINT_HEX(basic_rate_set);
360 DRIVER_STATE_PRINT_HEX(basic_rate);
361 DRIVER_STATE_PRINT_INT(band);
362 DRIVER_STATE_PRINT_INT(beacon_int);
363 DRIVER_STATE_PRINT_INT(psm_entry_retry);
364 DRIVER_STATE_PRINT_INT(ps_poll_failures);
365 DRIVER_STATE_PRINT_HEX(filters);
366 DRIVER_STATE_PRINT_HEX(rx_config);
367 DRIVER_STATE_PRINT_HEX(rx_filter);
368 DRIVER_STATE_PRINT_INT(power_level);
369 DRIVER_STATE_PRINT_INT(rssi_thold);
370 DRIVER_STATE_PRINT_INT(last_rssi_event);
371 DRIVER_STATE_PRINT_INT(sg_enabled);
372 DRIVER_STATE_PRINT_INT(enable_11a);
373 DRIVER_STATE_PRINT_INT(noise);
374 DRIVER_STATE_PRINT_LHEX(ap_hlid_map[0]);
375 DRIVER_STATE_PRINT_INT(last_tx_hlid);
376 DRIVER_STATE_PRINT_INT(ba_support);
377 DRIVER_STATE_PRINT_HEX(ba_rx_bitmap);
378 DRIVER_STATE_PRINT_HEX(ap_fw_ps_map);
379 DRIVER_STATE_PRINT_LHEX(ap_ps_map);
380 DRIVER_STATE_PRINT_HEX(quirks);
381 DRIVER_STATE_PRINT_HEX(irq);
382 DRIVER_STATE_PRINT_HEX(ref_clock);
383 DRIVER_STATE_PRINT_HEX(tcxo_clock);
384 DRIVER_STATE_PRINT_HEX(hw_pg_ver);
385 DRIVER_STATE_PRINT_HEX(platform_quirks);
386 DRIVER_STATE_PRINT_HEX(chip.id);
387 DRIVER_STATE_PRINT_STR(chip.fw_ver_str);
Luciano Coelhod3eff812011-05-10 14:47:45 +0300388 DRIVER_STATE_PRINT_INT(sched_scanning);
Arik Nemtsov2d66bee2011-04-18 14:15:29 +0300389
390#undef DRIVER_STATE_PRINT_INT
391#undef DRIVER_STATE_PRINT_LONG
392#undef DRIVER_STATE_PRINT_HEX
393#undef DRIVER_STATE_PRINT_LHEX
394#undef DRIVER_STATE_PRINT_STR
395#undef DRIVER_STATE_PRINT
396
397 mutex_unlock(&wl->mutex);
398
399 return simple_read_from_buffer(user_buf, count, ppos, buf, res);
400}
401
402static const struct file_operations driver_state_ops = {
403 .read = driver_state_read,
404 .open = wl1271_open_file_generic,
405 .llseek = default_llseek,
406};
407
Eliad Peller1fe9e242011-04-17 11:20:47 +0300408static ssize_t dtim_interval_read(struct file *file, char __user *user_buf,
409 size_t count, loff_t *ppos)
410{
411 struct wl1271 *wl = file->private_data;
412 u8 value;
413
414 if (wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_DTIM ||
415 wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_N_DTIM)
416 value = wl->conf.conn.listen_interval;
417 else
418 value = 0;
419
420 return wl1271_format_buffer(user_buf, count, ppos, "%d\n", value);
421}
422
423static ssize_t dtim_interval_write(struct file *file,
424 const char __user *user_buf,
425 size_t count, loff_t *ppos)
426{
427 struct wl1271 *wl = file->private_data;
428 char buf[10];
429 size_t len;
430 unsigned long value;
431 int ret;
432
433 len = min(count, sizeof(buf) - 1);
434 if (copy_from_user(buf, user_buf, len))
435 return -EFAULT;
436 buf[len] = '\0';
437
Luciano Coelhof7c7c7e2011-04-29 22:25:28 +0300438 ret = kstrtoul(buf, 0, &value);
Eliad Peller1fe9e242011-04-17 11:20:47 +0300439 if (ret < 0) {
440 wl1271_warning("illegal value for dtim_interval");
441 return -EINVAL;
442 }
443
444 if (value < 1 || value > 10) {
445 wl1271_warning("dtim value is not in valid range");
446 return -ERANGE;
447 }
448
449 mutex_lock(&wl->mutex);
450
451 wl->conf.conn.listen_interval = value;
452 /* for some reason there are different event types for 1 and >1 */
453 if (value == 1)
454 wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_DTIM;
455 else
456 wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_N_DTIM;
457
458 /*
459 * we don't reconfigure ACX_WAKE_UP_CONDITIONS now, so it will only
460 * take effect on the next time we enter psm.
461 */
462 mutex_unlock(&wl->mutex);
463 return count;
464}
465
466static const struct file_operations dtim_interval_ops = {
467 .read = dtim_interval_read,
468 .write = dtim_interval_write,
469 .open = wl1271_open_file_generic,
470 .llseek = default_llseek,
471};
472
473static ssize_t beacon_interval_read(struct file *file, char __user *user_buf,
474 size_t count, loff_t *ppos)
475{
476 struct wl1271 *wl = file->private_data;
477 u8 value;
478
479 if (wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_BEACON ||
480 wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_N_BEACONS)
481 value = wl->conf.conn.listen_interval;
482 else
483 value = 0;
484
485 return wl1271_format_buffer(user_buf, count, ppos, "%d\n", value);
486}
487
488static ssize_t beacon_interval_write(struct file *file,
489 const char __user *user_buf,
490 size_t count, loff_t *ppos)
491{
492 struct wl1271 *wl = file->private_data;
493 char buf[10];
494 size_t len;
495 unsigned long value;
496 int ret;
497
498 len = min(count, sizeof(buf) - 1);
499 if (copy_from_user(buf, user_buf, len))
500 return -EFAULT;
501 buf[len] = '\0';
502
Luciano Coelhof7c7c7e2011-04-29 22:25:28 +0300503 ret = kstrtoul(buf, 0, &value);
Eliad Peller1fe9e242011-04-17 11:20:47 +0300504 if (ret < 0) {
505 wl1271_warning("illegal value for beacon_interval");
506 return -EINVAL;
507 }
508
509 if (value < 1 || value > 255) {
510 wl1271_warning("beacon interval value is not in valid range");
511 return -ERANGE;
512 }
513
514 mutex_lock(&wl->mutex);
515
516 wl->conf.conn.listen_interval = value;
517 /* for some reason there are different event types for 1 and >1 */
518 if (value == 1)
519 wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_BEACON;
520 else
521 wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_N_BEACONS;
522
523 /*
524 * we don't reconfigure ACX_WAKE_UP_CONDITIONS now, so it will only
525 * take effect on the next time we enter psm.
526 */
527 mutex_unlock(&wl->mutex);
528 return count;
529}
530
531static const struct file_operations beacon_interval_ops = {
532 .read = beacon_interval_read,
533 .write = beacon_interval_write,
534 .open = wl1271_open_file_generic,
535 .llseek = default_llseek,
536};
537
Eliad Pellerc84368e2011-05-15 11:10:30 +0300538static ssize_t rx_streaming_interval_write(struct file *file,
539 const char __user *user_buf,
540 size_t count, loff_t *ppos)
541{
542 struct wl1271 *wl = file->private_data;
543 char buf[10];
544 size_t len;
545 unsigned long value;
546 int ret;
547
548 len = min(count, sizeof(buf) - 1);
549 if (copy_from_user(buf, user_buf, len))
550 return -EFAULT;
551 buf[len] = '\0';
552
553 ret = kstrtoul(buf, 0, &value);
554 if (ret < 0) {
555 wl1271_warning("illegal value in rx_streaming_interval!");
556 return -EINVAL;
557 }
558
559 /* valid values: 0, 10-100 */
560 if (value && (value < 10 || value > 100)) {
561 wl1271_warning("value is not in range!");
562 return -ERANGE;
563 }
564
565 mutex_lock(&wl->mutex);
566
567 wl->conf.rx_streaming.interval = value;
568
569 ret = wl1271_ps_elp_wakeup(wl);
570 if (ret < 0)
571 goto out;
572
573 wl1271_recalc_rx_streaming(wl);
574
575 wl1271_ps_elp_sleep(wl);
576out:
577 mutex_unlock(&wl->mutex);
578 return count;
579}
580
581static ssize_t rx_streaming_interval_read(struct file *file,
582 char __user *userbuf,
583 size_t count, loff_t *ppos)
584{
585 struct wl1271 *wl = file->private_data;
586 return wl1271_format_buffer(userbuf, count, ppos,
587 "%d\n", wl->conf.rx_streaming.interval);
588}
589
590static const struct file_operations rx_streaming_interval_ops = {
591 .read = rx_streaming_interval_read,
592 .write = rx_streaming_interval_write,
593 .open = wl1271_open_file_generic,
594 .llseek = default_llseek,
595};
596
597static ssize_t rx_streaming_always_write(struct file *file,
598 const char __user *user_buf,
599 size_t count, loff_t *ppos)
600{
601 struct wl1271 *wl = file->private_data;
602 char buf[10];
603 size_t len;
604 unsigned long value;
605 int ret;
606
607 len = min(count, sizeof(buf) - 1);
608 if (copy_from_user(buf, user_buf, len))
609 return -EFAULT;
610 buf[len] = '\0';
611
612 ret = kstrtoul(buf, 0, &value);
613 if (ret < 0) {
614 wl1271_warning("illegal value in rx_streaming_write!");
615 return -EINVAL;
616 }
617
618 /* valid values: 0, 10-100 */
619 if (!(value == 0 || value == 1)) {
620 wl1271_warning("value is not in valid!");
621 return -EINVAL;
622 }
623
624 mutex_lock(&wl->mutex);
625
626 wl->conf.rx_streaming.always = value;
627
628 ret = wl1271_ps_elp_wakeup(wl);
629 if (ret < 0)
630 goto out;
631
632 wl1271_recalc_rx_streaming(wl);
633
634 wl1271_ps_elp_sleep(wl);
635out:
636 mutex_unlock(&wl->mutex);
637 return count;
638}
639
640static ssize_t rx_streaming_always_read(struct file *file,
641 char __user *userbuf,
642 size_t count, loff_t *ppos)
643{
644 struct wl1271 *wl = file->private_data;
645 return wl1271_format_buffer(userbuf, count, ppos,
646 "%d\n", wl->conf.rx_streaming.always);
647}
648
649static const struct file_operations rx_streaming_always_ops = {
650 .read = rx_streaming_always_read,
651 .write = rx_streaming_always_write,
652 .open = wl1271_open_file_generic,
653 .llseek = default_llseek,
654};
655
Eliad Peller3c2c04a2010-12-15 11:47:54 +0200656static int wl1271_debugfs_add_files(struct wl1271 *wl,
657 struct dentry *rootdir)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300658{
659 int ret = 0;
Eliad Pellerc84368e2011-05-15 11:10:30 +0300660 struct dentry *entry, *stats, *streaming;
Eliad Peller7cb2cea2010-11-24 12:53:15 +0200661
Eliad Peller3c2c04a2010-12-15 11:47:54 +0200662 stats = debugfs_create_dir("fw-statistics", rootdir);
Eliad Peller7cb2cea2010-11-24 12:53:15 +0200663 if (!stats || IS_ERR(stats)) {
664 entry = stats;
665 goto err;
666 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300667
668 DEBUGFS_FWSTATS_ADD(tx, internal_desc_overflow);
669
670 DEBUGFS_FWSTATS_ADD(rx, out_of_mem);
671 DEBUGFS_FWSTATS_ADD(rx, hdr_overflow);
672 DEBUGFS_FWSTATS_ADD(rx, hw_stuck);
673 DEBUGFS_FWSTATS_ADD(rx, dropped);
674 DEBUGFS_FWSTATS_ADD(rx, fcs_err);
675 DEBUGFS_FWSTATS_ADD(rx, xfr_hint_trig);
676 DEBUGFS_FWSTATS_ADD(rx, path_reset);
677 DEBUGFS_FWSTATS_ADD(rx, reset_counter);
678
679 DEBUGFS_FWSTATS_ADD(dma, rx_requested);
680 DEBUGFS_FWSTATS_ADD(dma, rx_errors);
681 DEBUGFS_FWSTATS_ADD(dma, tx_requested);
682 DEBUGFS_FWSTATS_ADD(dma, tx_errors);
683
684 DEBUGFS_FWSTATS_ADD(isr, cmd_cmplt);
685 DEBUGFS_FWSTATS_ADD(isr, fiqs);
686 DEBUGFS_FWSTATS_ADD(isr, rx_headers);
687 DEBUGFS_FWSTATS_ADD(isr, rx_mem_overflow);
688 DEBUGFS_FWSTATS_ADD(isr, rx_rdys);
689 DEBUGFS_FWSTATS_ADD(isr, irqs);
690 DEBUGFS_FWSTATS_ADD(isr, tx_procs);
691 DEBUGFS_FWSTATS_ADD(isr, decrypt_done);
692 DEBUGFS_FWSTATS_ADD(isr, dma0_done);
693 DEBUGFS_FWSTATS_ADD(isr, dma1_done);
694 DEBUGFS_FWSTATS_ADD(isr, tx_exch_complete);
695 DEBUGFS_FWSTATS_ADD(isr, commands);
696 DEBUGFS_FWSTATS_ADD(isr, rx_procs);
697 DEBUGFS_FWSTATS_ADD(isr, hw_pm_mode_changes);
698 DEBUGFS_FWSTATS_ADD(isr, host_acknowledges);
699 DEBUGFS_FWSTATS_ADD(isr, pci_pm);
700 DEBUGFS_FWSTATS_ADD(isr, wakeups);
701 DEBUGFS_FWSTATS_ADD(isr, low_rssi);
702
703 DEBUGFS_FWSTATS_ADD(wep, addr_key_count);
704 DEBUGFS_FWSTATS_ADD(wep, default_key_count);
705 /* skipping wep.reserved */
706 DEBUGFS_FWSTATS_ADD(wep, key_not_found);
707 DEBUGFS_FWSTATS_ADD(wep, decrypt_fail);
708 DEBUGFS_FWSTATS_ADD(wep, packets);
709 DEBUGFS_FWSTATS_ADD(wep, interrupt);
710
711 DEBUGFS_FWSTATS_ADD(pwr, ps_enter);
712 DEBUGFS_FWSTATS_ADD(pwr, elp_enter);
713 DEBUGFS_FWSTATS_ADD(pwr, missing_bcns);
714 DEBUGFS_FWSTATS_ADD(pwr, wake_on_host);
715 DEBUGFS_FWSTATS_ADD(pwr, wake_on_timer_exp);
716 DEBUGFS_FWSTATS_ADD(pwr, tx_with_ps);
717 DEBUGFS_FWSTATS_ADD(pwr, tx_without_ps);
718 DEBUGFS_FWSTATS_ADD(pwr, rcvd_beacons);
719 DEBUGFS_FWSTATS_ADD(pwr, power_save_off);
720 DEBUGFS_FWSTATS_ADD(pwr, enable_ps);
721 DEBUGFS_FWSTATS_ADD(pwr, disable_ps);
722 DEBUGFS_FWSTATS_ADD(pwr, fix_tsf_ps);
723 /* skipping cont_miss_bcns_spread for now */
724 DEBUGFS_FWSTATS_ADD(pwr, rcvd_awake_beacons);
725
726 DEBUGFS_FWSTATS_ADD(mic, rx_pkts);
727 DEBUGFS_FWSTATS_ADD(mic, calc_failure);
728
729 DEBUGFS_FWSTATS_ADD(aes, encrypt_fail);
730 DEBUGFS_FWSTATS_ADD(aes, decrypt_fail);
731 DEBUGFS_FWSTATS_ADD(aes, encrypt_packets);
732 DEBUGFS_FWSTATS_ADD(aes, decrypt_packets);
733 DEBUGFS_FWSTATS_ADD(aes, encrypt_interrupt);
734 DEBUGFS_FWSTATS_ADD(aes, decrypt_interrupt);
735
736 DEBUGFS_FWSTATS_ADD(event, heart_beat);
737 DEBUGFS_FWSTATS_ADD(event, calibration);
738 DEBUGFS_FWSTATS_ADD(event, rx_mismatch);
739 DEBUGFS_FWSTATS_ADD(event, rx_mem_empty);
740 DEBUGFS_FWSTATS_ADD(event, rx_pool);
741 DEBUGFS_FWSTATS_ADD(event, oom_late);
742 DEBUGFS_FWSTATS_ADD(event, phy_transmit_error);
743 DEBUGFS_FWSTATS_ADD(event, tx_stuck);
744
745 DEBUGFS_FWSTATS_ADD(ps, pspoll_timeouts);
746 DEBUGFS_FWSTATS_ADD(ps, upsd_timeouts);
747 DEBUGFS_FWSTATS_ADD(ps, upsd_max_sptime);
748 DEBUGFS_FWSTATS_ADD(ps, upsd_max_apturn);
749 DEBUGFS_FWSTATS_ADD(ps, pspoll_max_apturn);
750 DEBUGFS_FWSTATS_ADD(ps, pspoll_utilization);
751 DEBUGFS_FWSTATS_ADD(ps, upsd_utilization);
752
753 DEBUGFS_FWSTATS_ADD(rxpipe, rx_prep_beacon_drop);
754 DEBUGFS_FWSTATS_ADD(rxpipe, descr_host_int_trig_rx_data);
755 DEBUGFS_FWSTATS_ADD(rxpipe, beacon_buffer_thres_host_int_trig_rx_data);
756 DEBUGFS_FWSTATS_ADD(rxpipe, missed_beacon_host_int_trig_rx_data);
757 DEBUGFS_FWSTATS_ADD(rxpipe, tx_xfr_host_int_trig_rx_data);
758
Eliad Peller3c2c04a2010-12-15 11:47:54 +0200759 DEBUGFS_ADD(tx_queue_len, rootdir);
760 DEBUGFS_ADD(retry_count, rootdir);
761 DEBUGFS_ADD(excessive_retries, rootdir);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300762
Eliad Peller3c2c04a2010-12-15 11:47:54 +0200763 DEBUGFS_ADD(gpio_power, rootdir);
Arik Nemtsov2dc5a5c2011-04-18 14:15:27 +0300764 DEBUGFS_ADD(start_recovery, rootdir);
Arik Nemtsov2d66bee2011-04-18 14:15:29 +0300765 DEBUGFS_ADD(driver_state, rootdir);
Eliad Peller1fe9e242011-04-17 11:20:47 +0300766 DEBUGFS_ADD(dtim_interval, rootdir);
767 DEBUGFS_ADD(beacon_interval, rootdir);
Luciano Coelho98b2a682009-12-11 15:40:52 +0200768
Eliad Pellerc84368e2011-05-15 11:10:30 +0300769 streaming = debugfs_create_dir("rx_streaming", rootdir);
770 if (!streaming || IS_ERR(streaming))
771 goto err;
772
773 DEBUGFS_ADD_PREFIX(rx_streaming, interval, streaming);
774 DEBUGFS_ADD_PREFIX(rx_streaming, always, streaming);
775
776
Eliad Peller7cb2cea2010-11-24 12:53:15 +0200777 return 0;
778
779err:
780 if (IS_ERR(entry))
781 ret = PTR_ERR(entry);
782 else
783 ret = -ENOMEM;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300784
785 return ret;
786}
787
788void wl1271_debugfs_reset(struct wl1271 *wl)
789{
Eliad Peller3c2c04a2010-12-15 11:47:54 +0200790 if (!wl->stats.fw_stats)
Luciano Coelho43a598d2010-11-30 14:58:46 +0200791 return;
792
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300793 memset(wl->stats.fw_stats, 0, sizeof(*wl->stats.fw_stats));
794 wl->stats.retry_count = 0;
795 wl->stats.excessive_retries = 0;
796}
797
798int wl1271_debugfs_init(struct wl1271 *wl)
799{
800 int ret;
Eliad Peller3c2c04a2010-12-15 11:47:54 +0200801 struct dentry *rootdir;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300802
Eliad Peller3c2c04a2010-12-15 11:47:54 +0200803 rootdir = debugfs_create_dir(KBUILD_MODNAME,
804 wl->hw->wiphy->debugfsdir);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300805
Eliad Peller3c2c04a2010-12-15 11:47:54 +0200806 if (IS_ERR(rootdir)) {
807 ret = PTR_ERR(rootdir);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300808 goto err;
809 }
810
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300811 wl->stats.fw_stats = kzalloc(sizeof(*wl->stats.fw_stats),
812 GFP_KERNEL);
813
814 if (!wl->stats.fw_stats) {
815 ret = -ENOMEM;
816 goto err_fw;
817 }
818
819 wl->stats.fw_stats_update = jiffies;
820
Eliad Peller3c2c04a2010-12-15 11:47:54 +0200821 ret = wl1271_debugfs_add_files(wl, rootdir);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300822
823 if (ret < 0)
824 goto err_file;
825
826 return 0;
827
828err_file:
829 kfree(wl->stats.fw_stats);
830 wl->stats.fw_stats = NULL;
831
832err_fw:
Eliad Peller3c2c04a2010-12-15 11:47:54 +0200833 debugfs_remove_recursive(rootdir);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300834
835err:
836 return ret;
837}
838
839void wl1271_debugfs_exit(struct wl1271 *wl)
840{
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300841 kfree(wl->stats.fw_stats);
842 wl->stats.fw_stats = NULL;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300843}