2 * This file is part of wl1271
4 * Copyright (C) 2009 Nokia Corporation
6 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
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.
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.
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
26 #include <linux/skbuff.h>
27 #include <linux/slab.h>
28 #include <linux/module.h>
39 #define WL1271_DEBUGFS_STATS_LIFETIME 1000
41 #define WLCORE_MAX_BLOCK_SIZE ((size_t)(4*PAGE_SIZE))
43 /* debugfs macros idea from mac80211 */
44 int wl1271_format_buffer(char __user *userbuf, size_t count,
45 loff_t *ppos, char *fmt, ...)
48 char buf[DEBUGFS_FORMAT_BUFFER_SIZE];
52 res = vscnprintf(buf, sizeof(buf), fmt, args);
55 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
57 EXPORT_SYMBOL_GPL(wl1271_format_buffer);
59 void wl1271_debugfs_update_stats(struct wl1271 *wl)
63 mutex_lock(&wl->mutex);
65 ret = wl1271_ps_elp_wakeup(wl);
69 if (wl->state == WL1271_STATE_ON && !wl->plt &&
70 time_after(jiffies, wl->stats.fw_stats_update +
71 msecs_to_jiffies(WL1271_DEBUGFS_STATS_LIFETIME))) {
72 wl1271_acx_statistics(wl, wl->stats.fw_stats);
73 wl->stats.fw_stats_update = jiffies;
76 wl1271_ps_elp_sleep(wl);
79 mutex_unlock(&wl->mutex);
81 EXPORT_SYMBOL_GPL(wl1271_debugfs_update_stats);
83 DEBUGFS_READONLY_FILE(retry_count, "%u", wl->stats.retry_count);
84 DEBUGFS_READONLY_FILE(excessive_retries, "%u",
85 wl->stats.excessive_retries);
87 static ssize_t tx_queue_len_read(struct file *file, char __user *userbuf,
88 size_t count, loff_t *ppos)
90 struct wl1271 *wl = file->private_data;
95 queue_len = wl1271_tx_total_queue_count(wl);
97 res = scnprintf(buf, sizeof(buf), "%u\n", queue_len);
98 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
101 static const struct file_operations tx_queue_len_ops = {
102 .read = tx_queue_len_read,
104 .llseek = default_llseek,
107 static void chip_op_handler(struct wl1271 *wl, unsigned long value,
111 int (*chip_op) (struct wl1271 *wl);
114 wl1271_warning("debugfs chip_op_handler with no callback");
118 ret = wl1271_ps_elp_wakeup(wl);
125 wl1271_ps_elp_sleep(wl);
129 static inline void no_write_handler(struct wl1271 *wl,
135 #define WL12XX_CONF_DEBUGFS(param, conf_sub_struct, \
136 min_val, max_val, write_handler_locked, \
138 static ssize_t param##_read(struct file *file, \
139 char __user *user_buf, \
140 size_t count, loff_t *ppos) \
142 struct wl1271 *wl = file->private_data; \
143 return wl1271_format_buffer(user_buf, count, \
145 wl->conf.conf_sub_struct.param); \
148 static ssize_t param##_write(struct file *file, \
149 const char __user *user_buf, \
150 size_t count, loff_t *ppos) \
152 struct wl1271 *wl = file->private_data; \
153 unsigned long value; \
156 ret = kstrtoul_from_user(user_buf, count, 10, &value); \
158 wl1271_warning("illegal value for " #param); \
162 if (value < min_val || value > max_val) { \
163 wl1271_warning(#param " is not in valid range"); \
167 mutex_lock(&wl->mutex); \
168 wl->conf.conf_sub_struct.param = value; \
170 write_handler_locked(wl, value, write_handler_arg); \
172 mutex_unlock(&wl->mutex); \
176 static const struct file_operations param##_ops = { \
177 .read = param##_read, \
178 .write = param##_write, \
179 .open = simple_open, \
180 .llseek = default_llseek, \
183 WL12XX_CONF_DEBUGFS(irq_pkt_threshold, rx, 0, 65535,
184 chip_op_handler, wl1271_acx_init_rx_interrupt)
185 WL12XX_CONF_DEBUGFS(irq_blk_threshold, rx, 0, 65535,
186 chip_op_handler, wl1271_acx_init_rx_interrupt)
187 WL12XX_CONF_DEBUGFS(irq_timeout, rx, 0, 100,
188 chip_op_handler, wl1271_acx_init_rx_interrupt)
190 static ssize_t gpio_power_read(struct file *file, char __user *user_buf,
191 size_t count, loff_t *ppos)
193 struct wl1271 *wl = file->private_data;
194 bool state = test_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
199 res = scnprintf(buf, sizeof(buf), "%d\n", state);
201 return simple_read_from_buffer(user_buf, count, ppos, buf, res);
204 static ssize_t gpio_power_write(struct file *file,
205 const char __user *user_buf,
206 size_t count, loff_t *ppos)
208 struct wl1271 *wl = file->private_data;
212 ret = kstrtoul_from_user(user_buf, count, 10, &value);
214 wl1271_warning("illegal value in gpio_power");
218 mutex_lock(&wl->mutex);
223 wl1271_power_off(wl);
225 mutex_unlock(&wl->mutex);
229 static const struct file_operations gpio_power_ops = {
230 .read = gpio_power_read,
231 .write = gpio_power_write,
233 .llseek = default_llseek,
236 static ssize_t start_recovery_write(struct file *file,
237 const char __user *user_buf,
238 size_t count, loff_t *ppos)
240 struct wl1271 *wl = file->private_data;
242 mutex_lock(&wl->mutex);
243 wl12xx_queue_recovery_work(wl);
244 mutex_unlock(&wl->mutex);
249 static const struct file_operations start_recovery_ops = {
250 .write = start_recovery_write,
252 .llseek = default_llseek,
255 static ssize_t dynamic_ps_timeout_read(struct file *file, char __user *user_buf,
256 size_t count, loff_t *ppos)
258 struct wl1271 *wl = file->private_data;
260 return wl1271_format_buffer(user_buf, count,
262 wl->conf.conn.dynamic_ps_timeout);
265 static ssize_t dynamic_ps_timeout_write(struct file *file,
266 const char __user *user_buf,
267 size_t count, loff_t *ppos)
269 struct wl1271 *wl = file->private_data;
270 struct wl12xx_vif *wlvif;
274 ret = kstrtoul_from_user(user_buf, count, 10, &value);
276 wl1271_warning("illegal value in dynamic_ps");
280 if (value < 1 || value > 65535) {
281 wl1271_warning("dyanmic_ps_timeout is not in valid range");
285 mutex_lock(&wl->mutex);
287 wl->conf.conn.dynamic_ps_timeout = value;
289 if (wl->state == WL1271_STATE_OFF)
292 ret = wl1271_ps_elp_wakeup(wl);
296 /* In case we're already in PSM, trigger it again to set new timeout
297 * immediately without waiting for re-association
300 wl12xx_for_each_wlvif_sta(wl, wlvif) {
301 if (test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags))
302 wl1271_ps_set_mode(wl, wlvif, STATION_AUTO_PS_MODE);
305 wl1271_ps_elp_sleep(wl);
308 mutex_unlock(&wl->mutex);
312 static const struct file_operations dynamic_ps_timeout_ops = {
313 .read = dynamic_ps_timeout_read,
314 .write = dynamic_ps_timeout_write,
316 .llseek = default_llseek,
319 static ssize_t forced_ps_read(struct file *file, char __user *user_buf,
320 size_t count, loff_t *ppos)
322 struct wl1271 *wl = file->private_data;
324 return wl1271_format_buffer(user_buf, count,
326 wl->conf.conn.forced_ps);
329 static ssize_t forced_ps_write(struct file *file,
330 const char __user *user_buf,
331 size_t count, loff_t *ppos)
333 struct wl1271 *wl = file->private_data;
334 struct wl12xx_vif *wlvif;
338 ret = kstrtoul_from_user(user_buf, count, 10, &value);
340 wl1271_warning("illegal value in forced_ps");
344 if (value != 1 && value != 0) {
345 wl1271_warning("forced_ps should be either 0 or 1");
349 mutex_lock(&wl->mutex);
351 if (wl->conf.conn.forced_ps == value)
354 wl->conf.conn.forced_ps = value;
356 if (wl->state == WL1271_STATE_OFF)
359 ret = wl1271_ps_elp_wakeup(wl);
363 /* In case we're already in PSM, trigger it again to switch mode
364 * immediately without waiting for re-association
367 ps_mode = value ? STATION_POWER_SAVE_MODE : STATION_AUTO_PS_MODE;
369 wl12xx_for_each_wlvif_sta(wl, wlvif) {
370 if (test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags))
371 wl1271_ps_set_mode(wl, wlvif, ps_mode);
374 wl1271_ps_elp_sleep(wl);
377 mutex_unlock(&wl->mutex);
381 static const struct file_operations forced_ps_ops = {
382 .read = forced_ps_read,
383 .write = forced_ps_write,
385 .llseek = default_llseek,
388 static ssize_t split_scan_timeout_read(struct file *file, char __user *user_buf,
389 size_t count, loff_t *ppos)
391 struct wl1271 *wl = file->private_data;
393 return wl1271_format_buffer(user_buf, count,
395 wl->conf.scan.split_scan_timeout / 1000);
398 static ssize_t split_scan_timeout_write(struct file *file,
399 const char __user *user_buf,
400 size_t count, loff_t *ppos)
402 struct wl1271 *wl = file->private_data;
406 ret = kstrtoul_from_user(user_buf, count, 10, &value);
408 wl1271_warning("illegal value in split_scan_timeout");
413 wl1271_info("split scan will be disabled");
415 mutex_lock(&wl->mutex);
417 wl->conf.scan.split_scan_timeout = value * 1000;
419 mutex_unlock(&wl->mutex);
423 static const struct file_operations split_scan_timeout_ops = {
424 .read = split_scan_timeout_read,
425 .write = split_scan_timeout_write,
427 .llseek = default_llseek,
430 static ssize_t driver_state_read(struct file *file, char __user *user_buf,
431 size_t count, loff_t *ppos)
433 struct wl1271 *wl = file->private_data;
438 #define DRIVER_STATE_BUF_LEN 1024
440 buf = kmalloc(DRIVER_STATE_BUF_LEN, GFP_KERNEL);
444 mutex_lock(&wl->mutex);
446 #define DRIVER_STATE_PRINT(x, fmt) \
447 (res += scnprintf(buf + res, DRIVER_STATE_BUF_LEN - res,\
448 #x " = " fmt "\n", wl->x))
450 #define DRIVER_STATE_PRINT_LONG(x) DRIVER_STATE_PRINT(x, "%ld")
451 #define DRIVER_STATE_PRINT_INT(x) DRIVER_STATE_PRINT(x, "%d")
452 #define DRIVER_STATE_PRINT_STR(x) DRIVER_STATE_PRINT(x, "%s")
453 #define DRIVER_STATE_PRINT_LHEX(x) DRIVER_STATE_PRINT(x, "0x%lx")
454 #define DRIVER_STATE_PRINT_HEX(x) DRIVER_STATE_PRINT(x, "0x%x")
456 DRIVER_STATE_PRINT_INT(tx_blocks_available);
457 DRIVER_STATE_PRINT_INT(tx_allocated_blocks);
458 DRIVER_STATE_PRINT_INT(tx_allocated_pkts[0]);
459 DRIVER_STATE_PRINT_INT(tx_allocated_pkts[1]);
460 DRIVER_STATE_PRINT_INT(tx_allocated_pkts[2]);
461 DRIVER_STATE_PRINT_INT(tx_allocated_pkts[3]);
462 DRIVER_STATE_PRINT_INT(tx_frames_cnt);
463 DRIVER_STATE_PRINT_LHEX(tx_frames_map[0]);
464 DRIVER_STATE_PRINT_INT(tx_queue_count[0]);
465 DRIVER_STATE_PRINT_INT(tx_queue_count[1]);
466 DRIVER_STATE_PRINT_INT(tx_queue_count[2]);
467 DRIVER_STATE_PRINT_INT(tx_queue_count[3]);
468 DRIVER_STATE_PRINT_INT(tx_packets_count);
469 DRIVER_STATE_PRINT_INT(tx_results_count);
470 DRIVER_STATE_PRINT_LHEX(flags);
471 DRIVER_STATE_PRINT_INT(tx_blocks_freed);
472 DRIVER_STATE_PRINT_INT(rx_counter);
473 DRIVER_STATE_PRINT_INT(state);
474 DRIVER_STATE_PRINT_INT(channel);
475 DRIVER_STATE_PRINT_INT(band);
476 DRIVER_STATE_PRINT_INT(power_level);
477 DRIVER_STATE_PRINT_INT(sg_enabled);
478 DRIVER_STATE_PRINT_INT(enable_11a);
479 DRIVER_STATE_PRINT_INT(noise);
480 DRIVER_STATE_PRINT_HEX(ap_fw_ps_map);
481 DRIVER_STATE_PRINT_LHEX(ap_ps_map);
482 DRIVER_STATE_PRINT_HEX(quirks);
483 DRIVER_STATE_PRINT_HEX(irq);
484 /* TODO: ref_clock and tcxo_clock were moved to wl12xx priv */
485 DRIVER_STATE_PRINT_HEX(hw_pg_ver);
486 DRIVER_STATE_PRINT_HEX(platform_quirks);
487 DRIVER_STATE_PRINT_HEX(chip.id);
488 DRIVER_STATE_PRINT_STR(chip.fw_ver_str);
489 DRIVER_STATE_PRINT_INT(sched_scanning);
491 #undef DRIVER_STATE_PRINT_INT
492 #undef DRIVER_STATE_PRINT_LONG
493 #undef DRIVER_STATE_PRINT_HEX
494 #undef DRIVER_STATE_PRINT_LHEX
495 #undef DRIVER_STATE_PRINT_STR
496 #undef DRIVER_STATE_PRINT
497 #undef DRIVER_STATE_BUF_LEN
499 mutex_unlock(&wl->mutex);
501 ret = simple_read_from_buffer(user_buf, count, ppos, buf, res);
506 static const struct file_operations driver_state_ops = {
507 .read = driver_state_read,
509 .llseek = default_llseek,
512 static ssize_t vifs_state_read(struct file *file, char __user *user_buf,
513 size_t count, loff_t *ppos)
515 struct wl1271 *wl = file->private_data;
516 struct wl12xx_vif *wlvif;
518 const int buf_size = 4096;
522 buf = kzalloc(buf_size, GFP_KERNEL);
526 mutex_lock(&wl->mutex);
528 #define VIF_STATE_PRINT(x, fmt) \
529 (res += scnprintf(buf + res, buf_size - res, \
530 #x " = " fmt "\n", wlvif->x))
532 #define VIF_STATE_PRINT_LONG(x) VIF_STATE_PRINT(x, "%ld")
533 #define VIF_STATE_PRINT_INT(x) VIF_STATE_PRINT(x, "%d")
534 #define VIF_STATE_PRINT_STR(x) VIF_STATE_PRINT(x, "%s")
535 #define VIF_STATE_PRINT_LHEX(x) VIF_STATE_PRINT(x, "0x%lx")
536 #define VIF_STATE_PRINT_LLHEX(x) VIF_STATE_PRINT(x, "0x%llx")
537 #define VIF_STATE_PRINT_HEX(x) VIF_STATE_PRINT(x, "0x%x")
539 #define VIF_STATE_PRINT_NSTR(x, len) \
541 memset(tmp_buf, 0, sizeof(tmp_buf)); \
542 memcpy(tmp_buf, wlvif->x, \
543 min_t(u8, len, sizeof(tmp_buf) - 1)); \
544 res += scnprintf(buf + res, buf_size - res, \
545 #x " = %s\n", tmp_buf); \
548 wl12xx_for_each_wlvif(wl, wlvif) {
549 VIF_STATE_PRINT_INT(role_id);
550 VIF_STATE_PRINT_INT(bss_type);
551 VIF_STATE_PRINT_LHEX(flags);
552 VIF_STATE_PRINT_INT(p2p);
553 VIF_STATE_PRINT_INT(dev_role_id);
554 VIF_STATE_PRINT_INT(dev_hlid);
556 if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
557 wlvif->bss_type == BSS_TYPE_IBSS) {
558 VIF_STATE_PRINT_INT(sta.hlid);
559 VIF_STATE_PRINT_INT(sta.ba_rx_bitmap);
560 VIF_STATE_PRINT_INT(sta.basic_rate_idx);
561 VIF_STATE_PRINT_INT(sta.ap_rate_idx);
562 VIF_STATE_PRINT_INT(sta.p2p_rate_idx);
563 VIF_STATE_PRINT_INT(sta.qos);
565 VIF_STATE_PRINT_INT(ap.global_hlid);
566 VIF_STATE_PRINT_INT(ap.bcast_hlid);
567 VIF_STATE_PRINT_LHEX(ap.sta_hlid_map[0]);
568 VIF_STATE_PRINT_INT(ap.mgmt_rate_idx);
569 VIF_STATE_PRINT_INT(ap.bcast_rate_idx);
570 VIF_STATE_PRINT_INT(ap.ucast_rate_idx[0]);
571 VIF_STATE_PRINT_INT(ap.ucast_rate_idx[1]);
572 VIF_STATE_PRINT_INT(ap.ucast_rate_idx[2]);
573 VIF_STATE_PRINT_INT(ap.ucast_rate_idx[3]);
575 VIF_STATE_PRINT_INT(last_tx_hlid);
576 VIF_STATE_PRINT_LHEX(links_map[0]);
577 VIF_STATE_PRINT_NSTR(ssid, wlvif->ssid_len);
578 VIF_STATE_PRINT_INT(band);
579 VIF_STATE_PRINT_INT(channel);
580 VIF_STATE_PRINT_HEX(bitrate_masks[0]);
581 VIF_STATE_PRINT_HEX(bitrate_masks[1]);
582 VIF_STATE_PRINT_HEX(basic_rate_set);
583 VIF_STATE_PRINT_HEX(basic_rate);
584 VIF_STATE_PRINT_HEX(rate_set);
585 VIF_STATE_PRINT_INT(beacon_int);
586 VIF_STATE_PRINT_INT(default_key);
587 VIF_STATE_PRINT_INT(aid);
588 VIF_STATE_PRINT_INT(session_counter);
589 VIF_STATE_PRINT_INT(psm_entry_retry);
590 VIF_STATE_PRINT_INT(power_level);
591 VIF_STATE_PRINT_INT(rssi_thold);
592 VIF_STATE_PRINT_INT(last_rssi_event);
593 VIF_STATE_PRINT_INT(ba_support);
594 VIF_STATE_PRINT_INT(ba_allowed);
595 VIF_STATE_PRINT_LLHEX(tx_security_seq);
596 VIF_STATE_PRINT_INT(tx_security_last_seq_lsb);
599 #undef VIF_STATE_PRINT_INT
600 #undef VIF_STATE_PRINT_LONG
601 #undef VIF_STATE_PRINT_HEX
602 #undef VIF_STATE_PRINT_LHEX
603 #undef VIF_STATE_PRINT_LLHEX
604 #undef VIF_STATE_PRINT_STR
605 #undef VIF_STATE_PRINT_NSTR
606 #undef VIF_STATE_PRINT
608 mutex_unlock(&wl->mutex);
610 ret = simple_read_from_buffer(user_buf, count, ppos, buf, res);
615 static const struct file_operations vifs_state_ops = {
616 .read = vifs_state_read,
618 .llseek = default_llseek,
621 static ssize_t dtim_interval_read(struct file *file, char __user *user_buf,
622 size_t count, loff_t *ppos)
624 struct wl1271 *wl = file->private_data;
627 if (wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_DTIM ||
628 wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_N_DTIM)
629 value = wl->conf.conn.listen_interval;
633 return wl1271_format_buffer(user_buf, count, ppos, "%d\n", value);
636 static ssize_t dtim_interval_write(struct file *file,
637 const char __user *user_buf,
638 size_t count, loff_t *ppos)
640 struct wl1271 *wl = file->private_data;
644 ret = kstrtoul_from_user(user_buf, count, 10, &value);
646 wl1271_warning("illegal value for dtim_interval");
650 if (value < 1 || value > 10) {
651 wl1271_warning("dtim value is not in valid range");
655 mutex_lock(&wl->mutex);
657 wl->conf.conn.listen_interval = value;
658 /* for some reason there are different event types for 1 and >1 */
660 wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_DTIM;
662 wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_N_DTIM;
665 * we don't reconfigure ACX_WAKE_UP_CONDITIONS now, so it will only
666 * take effect on the next time we enter psm.
668 mutex_unlock(&wl->mutex);
672 static const struct file_operations dtim_interval_ops = {
673 .read = dtim_interval_read,
674 .write = dtim_interval_write,
676 .llseek = default_llseek,
681 static ssize_t suspend_dtim_interval_read(struct file *file,
682 char __user *user_buf,
683 size_t count, loff_t *ppos)
685 struct wl1271 *wl = file->private_data;
688 if (wl->conf.conn.suspend_wake_up_event == CONF_WAKE_UP_EVENT_DTIM ||
689 wl->conf.conn.suspend_wake_up_event == CONF_WAKE_UP_EVENT_N_DTIM)
690 value = wl->conf.conn.suspend_listen_interval;
694 return wl1271_format_buffer(user_buf, count, ppos, "%d\n", value);
697 static ssize_t suspend_dtim_interval_write(struct file *file,
698 const char __user *user_buf,
699 size_t count, loff_t *ppos)
701 struct wl1271 *wl = file->private_data;
705 ret = kstrtoul_from_user(user_buf, count, 10, &value);
707 wl1271_warning("illegal value for suspend_dtim_interval");
711 if (value < 1 || value > 10) {
712 wl1271_warning("suspend_dtim value is not in valid range");
716 mutex_lock(&wl->mutex);
718 wl->conf.conn.suspend_listen_interval = value;
719 /* for some reason there are different event types for 1 and >1 */
721 wl->conf.conn.suspend_wake_up_event = CONF_WAKE_UP_EVENT_DTIM;
723 wl->conf.conn.suspend_wake_up_event = CONF_WAKE_UP_EVENT_N_DTIM;
725 mutex_unlock(&wl->mutex);
730 static const struct file_operations suspend_dtim_interval_ops = {
731 .read = suspend_dtim_interval_read,
732 .write = suspend_dtim_interval_write,
734 .llseek = default_llseek,
737 static ssize_t beacon_interval_read(struct file *file, char __user *user_buf,
738 size_t count, loff_t *ppos)
740 struct wl1271 *wl = file->private_data;
743 if (wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_BEACON ||
744 wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_N_BEACONS)
745 value = wl->conf.conn.listen_interval;
749 return wl1271_format_buffer(user_buf, count, ppos, "%d\n", value);
752 static ssize_t beacon_interval_write(struct file *file,
753 const char __user *user_buf,
754 size_t count, loff_t *ppos)
756 struct wl1271 *wl = file->private_data;
760 ret = kstrtoul_from_user(user_buf, count, 10, &value);
762 wl1271_warning("illegal value for beacon_interval");
766 if (value < 1 || value > 255) {
767 wl1271_warning("beacon interval value is not in valid range");
771 mutex_lock(&wl->mutex);
773 wl->conf.conn.listen_interval = value;
774 /* for some reason there are different event types for 1 and >1 */
776 wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_BEACON;
778 wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_N_BEACONS;
781 * we don't reconfigure ACX_WAKE_UP_CONDITIONS now, so it will only
782 * take effect on the next time we enter psm.
784 mutex_unlock(&wl->mutex);
788 static const struct file_operations beacon_interval_ops = {
789 .read = beacon_interval_read,
790 .write = beacon_interval_write,
792 .llseek = default_llseek,
795 static ssize_t rx_streaming_interval_write(struct file *file,
796 const char __user *user_buf,
797 size_t count, loff_t *ppos)
799 struct wl1271 *wl = file->private_data;
800 struct wl12xx_vif *wlvif;
804 ret = kstrtoul_from_user(user_buf, count, 10, &value);
806 wl1271_warning("illegal value in rx_streaming_interval!");
810 /* valid values: 0, 10-100 */
811 if (value && (value < 10 || value > 100)) {
812 wl1271_warning("value is not in range!");
816 mutex_lock(&wl->mutex);
818 wl->conf.rx_streaming.interval = value;
820 ret = wl1271_ps_elp_wakeup(wl);
824 wl12xx_for_each_wlvif_sta(wl, wlvif) {
825 wl1271_recalc_rx_streaming(wl, wlvif);
828 wl1271_ps_elp_sleep(wl);
830 mutex_unlock(&wl->mutex);
834 static ssize_t rx_streaming_interval_read(struct file *file,
835 char __user *userbuf,
836 size_t count, loff_t *ppos)
838 struct wl1271 *wl = file->private_data;
839 return wl1271_format_buffer(userbuf, count, ppos,
840 "%d\n", wl->conf.rx_streaming.interval);
843 static const struct file_operations rx_streaming_interval_ops = {
844 .read = rx_streaming_interval_read,
845 .write = rx_streaming_interval_write,
847 .llseek = default_llseek,
850 static ssize_t rx_streaming_always_write(struct file *file,
851 const char __user *user_buf,
852 size_t count, loff_t *ppos)
854 struct wl1271 *wl = file->private_data;
855 struct wl12xx_vif *wlvif;
859 ret = kstrtoul_from_user(user_buf, count, 10, &value);
861 wl1271_warning("illegal value in rx_streaming_write!");
865 /* valid values: 0, 10-100 */
866 if (!(value == 0 || value == 1)) {
867 wl1271_warning("value is not in valid!");
871 mutex_lock(&wl->mutex);
873 wl->conf.rx_streaming.always = value;
875 ret = wl1271_ps_elp_wakeup(wl);
879 wl12xx_for_each_wlvif_sta(wl, wlvif) {
880 wl1271_recalc_rx_streaming(wl, wlvif);
883 wl1271_ps_elp_sleep(wl);
885 mutex_unlock(&wl->mutex);
889 static ssize_t rx_streaming_always_read(struct file *file,
890 char __user *userbuf,
891 size_t count, loff_t *ppos)
893 struct wl1271 *wl = file->private_data;
894 return wl1271_format_buffer(userbuf, count, ppos,
895 "%d\n", wl->conf.rx_streaming.always);
898 static const struct file_operations rx_streaming_always_ops = {
899 .read = rx_streaming_always_read,
900 .write = rx_streaming_always_write,
902 .llseek = default_llseek,
905 static ssize_t beacon_filtering_write(struct file *file,
906 const char __user *user_buf,
907 size_t count, loff_t *ppos)
909 struct wl1271 *wl = file->private_data;
910 struct wl12xx_vif *wlvif;
916 len = min(count, sizeof(buf) - 1);
917 if (copy_from_user(buf, user_buf, len))
921 ret = kstrtoul(buf, 0, &value);
923 wl1271_warning("illegal value for beacon_filtering!");
927 mutex_lock(&wl->mutex);
929 ret = wl1271_ps_elp_wakeup(wl);
933 wl12xx_for_each_wlvif(wl, wlvif) {
934 ret = wl1271_acx_beacon_filter_opt(wl, wlvif, !!value);
937 wl1271_ps_elp_sleep(wl);
939 mutex_unlock(&wl->mutex);
943 static const struct file_operations beacon_filtering_ops = {
944 .write = beacon_filtering_write,
946 .llseek = default_llseek,
949 static ssize_t fw_stats_raw_read(struct file *file,
950 char __user *userbuf,
951 size_t count, loff_t *ppos)
953 struct wl1271 *wl = file->private_data;
955 wl1271_debugfs_update_stats(wl);
957 return simple_read_from_buffer(userbuf, count, ppos,
959 wl->stats.fw_stats_len);
962 static const struct file_operations fw_stats_raw_ops = {
963 .read = fw_stats_raw_read,
965 .llseek = default_llseek,
968 static ssize_t sleep_auth_read(struct file *file, char __user *user_buf,
969 size_t count, loff_t *ppos)
971 struct wl1271 *wl = file->private_data;
973 return wl1271_format_buffer(user_buf, count,
978 static ssize_t sleep_auth_write(struct file *file,
979 const char __user *user_buf,
980 size_t count, loff_t *ppos)
982 struct wl1271 *wl = file->private_data;
986 ret = kstrtoul_from_user(user_buf, count, 0, &value);
988 wl1271_warning("illegal value in sleep_auth");
992 if (value < 0 || value > WL1271_PSM_MAX) {
993 wl1271_warning("sleep_auth must be between 0 and %d",
998 mutex_lock(&wl->mutex);
1000 wl->conf.conn.sta_sleep_auth = value;
1002 if (wl->state == WL1271_STATE_OFF) {
1003 /* this will show up on "read" in case we are off */
1004 wl->sleep_auth = value;
1008 ret = wl1271_ps_elp_wakeup(wl);
1012 ret = wl1271_acx_sleep_auth(wl, value);
1017 wl1271_ps_elp_sleep(wl);
1019 mutex_unlock(&wl->mutex);
1023 static const struct file_operations sleep_auth_ops = {
1024 .read = sleep_auth_read,
1025 .write = sleep_auth_write,
1026 .open = simple_open,
1027 .llseek = default_llseek,
1030 static ssize_t dev_mem_read(struct file *file,
1031 char __user *user_buf, size_t count,
1034 struct wl1271 *wl = file->private_data;
1035 struct wlcore_partition_set part, old_part;
1036 size_t bytes = count;
1040 /* only requests of dword-aligned size and offset are supported */
1047 /* function should return in reasonable time */
1048 bytes = min(bytes, WLCORE_MAX_BLOCK_SIZE);
1053 memset(&part, 0, sizeof(part));
1054 part.mem.start = file->f_pos;
1055 part.mem.size = bytes;
1057 buf = kmalloc(bytes, GFP_KERNEL);
1061 mutex_lock(&wl->mutex);
1063 if (wl->state == WL1271_STATE_OFF) {
1068 ret = wl1271_ps_elp_wakeup(wl);
1072 /* store current partition and switch partition */
1073 memcpy(&old_part, &wl->curr_part, sizeof(old_part));
1074 ret = wlcore_set_partition(wl, &part);
1078 ret = wlcore_raw_read(wl, 0, buf, bytes, false);
1083 /* recover partition */
1084 ret = wlcore_set_partition(wl, &old_part);
1089 wl1271_ps_elp_sleep(wl);
1092 mutex_unlock(&wl->mutex);
1095 ret = copy_to_user(user_buf, buf, bytes);
1107 return ((ret == 0) ? bytes : ret);
1110 static ssize_t dev_mem_write(struct file *file, const char __user *user_buf,
1111 size_t count, loff_t *ppos)
1113 struct wl1271 *wl = file->private_data;
1114 struct wlcore_partition_set part, old_part;
1115 size_t bytes = count;
1119 /* only requests of dword-aligned size and offset are supported */
1126 /* function should return in reasonable time */
1127 bytes = min(bytes, WLCORE_MAX_BLOCK_SIZE);
1132 memset(&part, 0, sizeof(part));
1133 part.mem.start = file->f_pos;
1134 part.mem.size = bytes;
1136 buf = kmalloc(bytes, GFP_KERNEL);
1140 ret = copy_from_user(buf, user_buf, bytes);
1146 mutex_lock(&wl->mutex);
1148 if (wl->state == WL1271_STATE_OFF) {
1153 ret = wl1271_ps_elp_wakeup(wl);
1157 /* store current partition and switch partition */
1158 memcpy(&old_part, &wl->curr_part, sizeof(old_part));
1159 ret = wlcore_set_partition(wl, &part);
1163 ret = wlcore_raw_write(wl, 0, buf, bytes, false);
1168 /* recover partition */
1169 ret = wlcore_set_partition(wl, &old_part);
1174 wl1271_ps_elp_sleep(wl);
1177 mutex_unlock(&wl->mutex);
1185 return ((ret == 0) ? bytes : ret);
1188 static loff_t dev_mem_seek(struct file *file, loff_t offset, int orig)
1192 /* only requests of dword-aligned size and offset are supported */
1198 file->f_pos = offset;
1202 file->f_pos += offset;
1212 static const struct file_operations dev_mem_ops = {
1213 .open = simple_open,
1214 .read = dev_mem_read,
1215 .write = dev_mem_write,
1216 .llseek = dev_mem_seek,
1219 static int wl1271_debugfs_add_files(struct wl1271 *wl,
1220 struct dentry *rootdir)
1223 struct dentry *entry, *streaming;
1225 DEBUGFS_ADD(tx_queue_len, rootdir);
1226 DEBUGFS_ADD(retry_count, rootdir);
1227 DEBUGFS_ADD(excessive_retries, rootdir);
1229 DEBUGFS_ADD(gpio_power, rootdir);
1230 DEBUGFS_ADD(start_recovery, rootdir);
1231 DEBUGFS_ADD(driver_state, rootdir);
1232 DEBUGFS_ADD(vifs_state, rootdir);
1233 DEBUGFS_ADD(dtim_interval, rootdir);
1234 DEBUGFS_ADD(suspend_dtim_interval, rootdir);
1235 DEBUGFS_ADD(beacon_interval, rootdir);
1236 DEBUGFS_ADD(beacon_filtering, rootdir);
1237 DEBUGFS_ADD(dynamic_ps_timeout, rootdir);
1238 DEBUGFS_ADD(forced_ps, rootdir);
1239 DEBUGFS_ADD(split_scan_timeout, rootdir);
1240 DEBUGFS_ADD(irq_pkt_threshold, rootdir);
1241 DEBUGFS_ADD(irq_blk_threshold, rootdir);
1242 DEBUGFS_ADD(irq_timeout, rootdir);
1243 DEBUGFS_ADD(fw_stats_raw, rootdir);
1244 DEBUGFS_ADD(sleep_auth, rootdir);
1246 streaming = debugfs_create_dir("rx_streaming", rootdir);
1247 if (!streaming || IS_ERR(streaming))
1250 DEBUGFS_ADD_PREFIX(rx_streaming, interval, streaming);
1251 DEBUGFS_ADD_PREFIX(rx_streaming, always, streaming);
1253 DEBUGFS_ADD_PREFIX(dev, mem, rootdir);
1259 ret = PTR_ERR(entry);
1266 void wl1271_debugfs_reset(struct wl1271 *wl)
1268 if (!wl->stats.fw_stats)
1271 memset(wl->stats.fw_stats, 0, wl->stats.fw_stats_len);
1272 wl->stats.retry_count = 0;
1273 wl->stats.excessive_retries = 0;
1276 int wl1271_debugfs_init(struct wl1271 *wl)
1279 struct dentry *rootdir;
1281 rootdir = debugfs_create_dir(KBUILD_MODNAME,
1282 wl->hw->wiphy->debugfsdir);
1284 if (IS_ERR(rootdir)) {
1285 ret = PTR_ERR(rootdir);
1289 wl->stats.fw_stats = kzalloc(wl->stats.fw_stats_len, GFP_KERNEL);
1290 if (!wl->stats.fw_stats) {
1295 wl->stats.fw_stats_update = jiffies;
1297 ret = wl1271_debugfs_add_files(wl, rootdir);
1301 ret = wlcore_debugfs_init(wl, rootdir);
1308 wl1271_debugfs_exit(wl);
1311 debugfs_remove_recursive(rootdir);
1317 void wl1271_debugfs_exit(struct wl1271 *wl)
1319 kfree(wl->stats.fw_stats);
1320 wl->stats.fw_stats = NULL;