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 /* debugfs macros idea from mac80211 */
42 int wl1271_format_buffer(char __user *userbuf, size_t count,
43 loff_t *ppos, char *fmt, ...)
46 char buf[DEBUGFS_FORMAT_BUFFER_SIZE];
50 res = vscnprintf(buf, sizeof(buf), fmt, args);
53 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
55 EXPORT_SYMBOL_GPL(wl1271_format_buffer);
57 void wl1271_debugfs_update_stats(struct wl1271 *wl)
61 mutex_lock(&wl->mutex);
63 ret = wl1271_ps_elp_wakeup(wl);
67 if (wl->state == WL1271_STATE_ON && !wl->plt &&
68 time_after(jiffies, wl->stats.fw_stats_update +
69 msecs_to_jiffies(WL1271_DEBUGFS_STATS_LIFETIME))) {
70 wl1271_acx_statistics(wl, wl->stats.fw_stats);
71 wl->stats.fw_stats_update = jiffies;
74 wl1271_ps_elp_sleep(wl);
77 mutex_unlock(&wl->mutex);
79 EXPORT_SYMBOL_GPL(wl1271_debugfs_update_stats);
81 DEBUGFS_READONLY_FILE(retry_count, "%u", wl->stats.retry_count);
82 DEBUGFS_READONLY_FILE(excessive_retries, "%u",
83 wl->stats.excessive_retries);
85 static ssize_t tx_queue_len_read(struct file *file, char __user *userbuf,
86 size_t count, loff_t *ppos)
88 struct wl1271 *wl = file->private_data;
93 queue_len = wl1271_tx_total_queue_count(wl);
95 res = scnprintf(buf, sizeof(buf), "%u\n", queue_len);
96 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
99 static const struct file_operations tx_queue_len_ops = {
100 .read = tx_queue_len_read,
102 .llseek = default_llseek,
105 static void chip_op_handler(struct wl1271 *wl, unsigned long value,
109 int (*chip_op) (struct wl1271 *wl);
112 wl1271_warning("debugfs chip_op_handler with no callback");
116 ret = wl1271_ps_elp_wakeup(wl);
123 wl1271_ps_elp_sleep(wl);
127 static inline void no_write_handler(struct wl1271 *wl,
133 #define WL12XX_CONF_DEBUGFS(param, conf_sub_struct, \
134 min_val, max_val, write_handler_locked, \
136 static ssize_t param##_read(struct file *file, \
137 char __user *user_buf, \
138 size_t count, loff_t *ppos) \
140 struct wl1271 *wl = file->private_data; \
141 return wl1271_format_buffer(user_buf, count, \
143 wl->conf.conf_sub_struct.param); \
146 static ssize_t param##_write(struct file *file, \
147 const char __user *user_buf, \
148 size_t count, loff_t *ppos) \
150 struct wl1271 *wl = file->private_data; \
151 unsigned long value; \
154 ret = kstrtoul_from_user(user_buf, count, 10, &value); \
156 wl1271_warning("illegal value for " #param); \
160 if (value < min_val || value > max_val) { \
161 wl1271_warning(#param " is not in valid range"); \
165 mutex_lock(&wl->mutex); \
166 wl->conf.conf_sub_struct.param = value; \
168 write_handler_locked(wl, value, write_handler_arg); \
170 mutex_unlock(&wl->mutex); \
174 static const struct file_operations param##_ops = { \
175 .read = param##_read, \
176 .write = param##_write, \
177 .open = simple_open, \
178 .llseek = default_llseek, \
180 static ssize_t gpio_power_read(struct file *file, char __user *user_buf,
181 size_t count, loff_t *ppos)
183 struct wl1271 *wl = file->private_data;
184 bool state = test_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
189 res = scnprintf(buf, sizeof(buf), "%d\n", state);
191 return simple_read_from_buffer(user_buf, count, ppos, buf, res);
194 static ssize_t gpio_power_write(struct file *file,
195 const char __user *user_buf,
196 size_t count, loff_t *ppos)
198 struct wl1271 *wl = file->private_data;
202 ret = kstrtoul_from_user(user_buf, count, 10, &value);
204 wl1271_warning("illegal value in gpio_power");
208 mutex_lock(&wl->mutex);
213 wl1271_power_off(wl);
215 mutex_unlock(&wl->mutex);
219 static const struct file_operations gpio_power_ops = {
220 .read = gpio_power_read,
221 .write = gpio_power_write,
223 .llseek = default_llseek,
226 static ssize_t start_recovery_write(struct file *file,
227 const char __user *user_buf,
228 size_t count, loff_t *ppos)
230 struct wl1271 *wl = file->private_data;
232 mutex_lock(&wl->mutex);
233 wl12xx_queue_recovery_work(wl);
234 mutex_unlock(&wl->mutex);
239 static const struct file_operations start_recovery_ops = {
240 .write = start_recovery_write,
242 .llseek = default_llseek,
245 static ssize_t dynamic_ps_timeout_read(struct file *file, char __user *user_buf,
246 size_t count, loff_t *ppos)
248 struct wl1271 *wl = file->private_data;
250 return wl1271_format_buffer(user_buf, count,
252 wl->conf.conn.dynamic_ps_timeout);
255 static ssize_t dynamic_ps_timeout_write(struct file *file,
256 const char __user *user_buf,
257 size_t count, loff_t *ppos)
259 struct wl1271 *wl = file->private_data;
260 struct wl12xx_vif *wlvif;
264 ret = kstrtoul_from_user(user_buf, count, 10, &value);
266 wl1271_warning("illegal value in dynamic_ps");
270 if (value < 1 || value > 65535) {
271 wl1271_warning("dyanmic_ps_timeout is not in valid range");
275 mutex_lock(&wl->mutex);
277 wl->conf.conn.dynamic_ps_timeout = value;
279 if (wl->state == WL1271_STATE_OFF)
282 ret = wl1271_ps_elp_wakeup(wl);
286 /* In case we're already in PSM, trigger it again to set new timeout
287 * immediately without waiting for re-association
290 wl12xx_for_each_wlvif_sta(wl, wlvif) {
291 if (test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags))
292 wl1271_ps_set_mode(wl, wlvif, STATION_AUTO_PS_MODE);
295 wl1271_ps_elp_sleep(wl);
298 mutex_unlock(&wl->mutex);
302 static const struct file_operations dynamic_ps_timeout_ops = {
303 .read = dynamic_ps_timeout_read,
304 .write = dynamic_ps_timeout_write,
306 .llseek = default_llseek,
309 static ssize_t forced_ps_read(struct file *file, char __user *user_buf,
310 size_t count, loff_t *ppos)
312 struct wl1271 *wl = file->private_data;
314 return wl1271_format_buffer(user_buf, count,
316 wl->conf.conn.forced_ps);
319 static ssize_t forced_ps_write(struct file *file,
320 const char __user *user_buf,
321 size_t count, loff_t *ppos)
323 struct wl1271 *wl = file->private_data;
324 struct wl12xx_vif *wlvif;
328 ret = kstrtoul_from_user(user_buf, count, 10, &value);
330 wl1271_warning("illegal value in forced_ps");
334 if (value != 1 && value != 0) {
335 wl1271_warning("forced_ps should be either 0 or 1");
339 mutex_lock(&wl->mutex);
341 if (wl->conf.conn.forced_ps == value)
344 wl->conf.conn.forced_ps = value;
346 if (wl->state == WL1271_STATE_OFF)
349 ret = wl1271_ps_elp_wakeup(wl);
353 /* In case we're already in PSM, trigger it again to switch mode
354 * immediately without waiting for re-association
357 ps_mode = value ? STATION_POWER_SAVE_MODE : STATION_AUTO_PS_MODE;
359 wl12xx_for_each_wlvif_sta(wl, wlvif) {
360 if (test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags))
361 wl1271_ps_set_mode(wl, wlvif, ps_mode);
364 wl1271_ps_elp_sleep(wl);
367 mutex_unlock(&wl->mutex);
371 static const struct file_operations forced_ps_ops = {
372 .read = forced_ps_read,
373 .write = forced_ps_write,
375 .llseek = default_llseek,
378 static ssize_t split_scan_timeout_read(struct file *file, char __user *user_buf,
379 size_t count, loff_t *ppos)
381 struct wl1271 *wl = file->private_data;
383 return wl1271_format_buffer(user_buf, count,
385 wl->conf.scan.split_scan_timeout / 1000);
388 static ssize_t split_scan_timeout_write(struct file *file,
389 const char __user *user_buf,
390 size_t count, loff_t *ppos)
392 struct wl1271 *wl = file->private_data;
396 ret = kstrtoul_from_user(user_buf, count, 10, &value);
398 wl1271_warning("illegal value in split_scan_timeout");
403 wl1271_info("split scan will be disabled");
405 mutex_lock(&wl->mutex);
407 wl->conf.scan.split_scan_timeout = value * 1000;
409 mutex_unlock(&wl->mutex);
413 static const struct file_operations split_scan_timeout_ops = {
414 .read = split_scan_timeout_read,
415 .write = split_scan_timeout_write,
417 .llseek = default_llseek,
420 static ssize_t driver_state_read(struct file *file, char __user *user_buf,
421 size_t count, loff_t *ppos)
423 struct wl1271 *wl = file->private_data;
428 #define DRIVER_STATE_BUF_LEN 1024
430 buf = kmalloc(DRIVER_STATE_BUF_LEN, GFP_KERNEL);
434 mutex_lock(&wl->mutex);
436 #define DRIVER_STATE_PRINT(x, fmt) \
437 (res += scnprintf(buf + res, DRIVER_STATE_BUF_LEN - res,\
438 #x " = " fmt "\n", wl->x))
440 #define DRIVER_STATE_PRINT_LONG(x) DRIVER_STATE_PRINT(x, "%ld")
441 #define DRIVER_STATE_PRINT_INT(x) DRIVER_STATE_PRINT(x, "%d")
442 #define DRIVER_STATE_PRINT_STR(x) DRIVER_STATE_PRINT(x, "%s")
443 #define DRIVER_STATE_PRINT_LHEX(x) DRIVER_STATE_PRINT(x, "0x%lx")
444 #define DRIVER_STATE_PRINT_HEX(x) DRIVER_STATE_PRINT(x, "0x%x")
446 DRIVER_STATE_PRINT_INT(tx_blocks_available);
447 DRIVER_STATE_PRINT_INT(tx_allocated_blocks);
448 DRIVER_STATE_PRINT_INT(tx_allocated_pkts[0]);
449 DRIVER_STATE_PRINT_INT(tx_allocated_pkts[1]);
450 DRIVER_STATE_PRINT_INT(tx_allocated_pkts[2]);
451 DRIVER_STATE_PRINT_INT(tx_allocated_pkts[3]);
452 DRIVER_STATE_PRINT_INT(tx_frames_cnt);
453 DRIVER_STATE_PRINT_LHEX(tx_frames_map[0]);
454 DRIVER_STATE_PRINT_INT(tx_queue_count[0]);
455 DRIVER_STATE_PRINT_INT(tx_queue_count[1]);
456 DRIVER_STATE_PRINT_INT(tx_queue_count[2]);
457 DRIVER_STATE_PRINT_INT(tx_queue_count[3]);
458 DRIVER_STATE_PRINT_INT(tx_packets_count);
459 DRIVER_STATE_PRINT_INT(tx_results_count);
460 DRIVER_STATE_PRINT_LHEX(flags);
461 DRIVER_STATE_PRINT_INT(tx_blocks_freed);
462 DRIVER_STATE_PRINT_INT(rx_counter);
463 DRIVER_STATE_PRINT_INT(state);
464 DRIVER_STATE_PRINT_INT(channel);
465 DRIVER_STATE_PRINT_INT(band);
466 DRIVER_STATE_PRINT_INT(power_level);
467 DRIVER_STATE_PRINT_INT(sg_enabled);
468 DRIVER_STATE_PRINT_INT(enable_11a);
469 DRIVER_STATE_PRINT_INT(noise);
470 DRIVER_STATE_PRINT_HEX(ap_fw_ps_map);
471 DRIVER_STATE_PRINT_LHEX(ap_ps_map);
472 DRIVER_STATE_PRINT_HEX(quirks);
473 DRIVER_STATE_PRINT_HEX(irq);
474 /* TODO: ref_clock and tcxo_clock were moved to wl12xx priv */
475 DRIVER_STATE_PRINT_HEX(hw_pg_ver);
476 DRIVER_STATE_PRINT_HEX(platform_quirks);
477 DRIVER_STATE_PRINT_HEX(chip.id);
478 DRIVER_STATE_PRINT_STR(chip.fw_ver_str);
479 DRIVER_STATE_PRINT_INT(sched_scanning);
481 #undef DRIVER_STATE_PRINT_INT
482 #undef DRIVER_STATE_PRINT_LONG
483 #undef DRIVER_STATE_PRINT_HEX
484 #undef DRIVER_STATE_PRINT_LHEX
485 #undef DRIVER_STATE_PRINT_STR
486 #undef DRIVER_STATE_PRINT
487 #undef DRIVER_STATE_BUF_LEN
489 mutex_unlock(&wl->mutex);
491 ret = simple_read_from_buffer(user_buf, count, ppos, buf, res);
496 static const struct file_operations driver_state_ops = {
497 .read = driver_state_read,
499 .llseek = default_llseek,
502 static ssize_t vifs_state_read(struct file *file, char __user *user_buf,
503 size_t count, loff_t *ppos)
505 struct wl1271 *wl = file->private_data;
506 struct wl12xx_vif *wlvif;
508 const int buf_size = 4096;
512 buf = kzalloc(buf_size, GFP_KERNEL);
516 mutex_lock(&wl->mutex);
518 #define VIF_STATE_PRINT(x, fmt) \
519 (res += scnprintf(buf + res, buf_size - res, \
520 #x " = " fmt "\n", wlvif->x))
522 #define VIF_STATE_PRINT_LONG(x) VIF_STATE_PRINT(x, "%ld")
523 #define VIF_STATE_PRINT_INT(x) VIF_STATE_PRINT(x, "%d")
524 #define VIF_STATE_PRINT_STR(x) VIF_STATE_PRINT(x, "%s")
525 #define VIF_STATE_PRINT_LHEX(x) VIF_STATE_PRINT(x, "0x%lx")
526 #define VIF_STATE_PRINT_LLHEX(x) VIF_STATE_PRINT(x, "0x%llx")
527 #define VIF_STATE_PRINT_HEX(x) VIF_STATE_PRINT(x, "0x%x")
529 #define VIF_STATE_PRINT_NSTR(x, len) \
531 memset(tmp_buf, 0, sizeof(tmp_buf)); \
532 memcpy(tmp_buf, wlvif->x, \
533 min_t(u8, len, sizeof(tmp_buf) - 1)); \
534 res += scnprintf(buf + res, buf_size - res, \
535 #x " = %s\n", tmp_buf); \
538 wl12xx_for_each_wlvif(wl, wlvif) {
539 VIF_STATE_PRINT_INT(role_id);
540 VIF_STATE_PRINT_INT(bss_type);
541 VIF_STATE_PRINT_LHEX(flags);
542 VIF_STATE_PRINT_INT(p2p);
543 VIF_STATE_PRINT_INT(dev_role_id);
544 VIF_STATE_PRINT_INT(dev_hlid);
546 if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
547 wlvif->bss_type == BSS_TYPE_IBSS) {
548 VIF_STATE_PRINT_INT(sta.hlid);
549 VIF_STATE_PRINT_INT(sta.ba_rx_bitmap);
550 VIF_STATE_PRINT_INT(sta.basic_rate_idx);
551 VIF_STATE_PRINT_INT(sta.ap_rate_idx);
552 VIF_STATE_PRINT_INT(sta.p2p_rate_idx);
553 VIF_STATE_PRINT_INT(sta.qos);
555 VIF_STATE_PRINT_INT(ap.global_hlid);
556 VIF_STATE_PRINT_INT(ap.bcast_hlid);
557 VIF_STATE_PRINT_LHEX(ap.sta_hlid_map[0]);
558 VIF_STATE_PRINT_INT(ap.mgmt_rate_idx);
559 VIF_STATE_PRINT_INT(ap.bcast_rate_idx);
560 VIF_STATE_PRINT_INT(ap.ucast_rate_idx[0]);
561 VIF_STATE_PRINT_INT(ap.ucast_rate_idx[1]);
562 VIF_STATE_PRINT_INT(ap.ucast_rate_idx[2]);
563 VIF_STATE_PRINT_INT(ap.ucast_rate_idx[3]);
565 VIF_STATE_PRINT_INT(last_tx_hlid);
566 VIF_STATE_PRINT_LHEX(links_map[0]);
567 VIF_STATE_PRINT_NSTR(ssid, wlvif->ssid_len);
568 VIF_STATE_PRINT_INT(band);
569 VIF_STATE_PRINT_INT(channel);
570 VIF_STATE_PRINT_HEX(bitrate_masks[0]);
571 VIF_STATE_PRINT_HEX(bitrate_masks[1]);
572 VIF_STATE_PRINT_HEX(basic_rate_set);
573 VIF_STATE_PRINT_HEX(basic_rate);
574 VIF_STATE_PRINT_HEX(rate_set);
575 VIF_STATE_PRINT_INT(beacon_int);
576 VIF_STATE_PRINT_INT(default_key);
577 VIF_STATE_PRINT_INT(aid);
578 VIF_STATE_PRINT_INT(session_counter);
579 VIF_STATE_PRINT_INT(psm_entry_retry);
580 VIF_STATE_PRINT_INT(power_level);
581 VIF_STATE_PRINT_INT(rssi_thold);
582 VIF_STATE_PRINT_INT(last_rssi_event);
583 VIF_STATE_PRINT_INT(ba_support);
584 VIF_STATE_PRINT_INT(ba_allowed);
585 VIF_STATE_PRINT_LLHEX(tx_security_seq);
586 VIF_STATE_PRINT_INT(tx_security_last_seq_lsb);
589 #undef VIF_STATE_PRINT_INT
590 #undef VIF_STATE_PRINT_LONG
591 #undef VIF_STATE_PRINT_HEX
592 #undef VIF_STATE_PRINT_LHEX
593 #undef VIF_STATE_PRINT_LLHEX
594 #undef VIF_STATE_PRINT_STR
595 #undef VIF_STATE_PRINT_NSTR
596 #undef VIF_STATE_PRINT
598 mutex_unlock(&wl->mutex);
600 ret = simple_read_from_buffer(user_buf, count, ppos, buf, res);
605 static const struct file_operations vifs_state_ops = {
606 .read = vifs_state_read,
608 .llseek = default_llseek,
611 static ssize_t dtim_interval_read(struct file *file, char __user *user_buf,
612 size_t count, loff_t *ppos)
614 struct wl1271 *wl = file->private_data;
617 if (wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_DTIM ||
618 wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_N_DTIM)
619 value = wl->conf.conn.listen_interval;
623 return wl1271_format_buffer(user_buf, count, ppos, "%d\n", value);
626 static ssize_t dtim_interval_write(struct file *file,
627 const char __user *user_buf,
628 size_t count, loff_t *ppos)
630 struct wl1271 *wl = file->private_data;
634 ret = kstrtoul_from_user(user_buf, count, 10, &value);
636 wl1271_warning("illegal value for dtim_interval");
640 if (value < 1 || value > 10) {
641 wl1271_warning("dtim value is not in valid range");
645 mutex_lock(&wl->mutex);
647 wl->conf.conn.listen_interval = value;
648 /* for some reason there are different event types for 1 and >1 */
650 wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_DTIM;
652 wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_N_DTIM;
655 * we don't reconfigure ACX_WAKE_UP_CONDITIONS now, so it will only
656 * take effect on the next time we enter psm.
658 mutex_unlock(&wl->mutex);
662 static const struct file_operations dtim_interval_ops = {
663 .read = dtim_interval_read,
664 .write = dtim_interval_write,
666 .llseek = default_llseek,
671 static ssize_t suspend_dtim_interval_read(struct file *file,
672 char __user *user_buf,
673 size_t count, loff_t *ppos)
675 struct wl1271 *wl = file->private_data;
678 if (wl->conf.conn.suspend_wake_up_event == CONF_WAKE_UP_EVENT_DTIM ||
679 wl->conf.conn.suspend_wake_up_event == CONF_WAKE_UP_EVENT_N_DTIM)
680 value = wl->conf.conn.suspend_listen_interval;
684 return wl1271_format_buffer(user_buf, count, ppos, "%d\n", value);
687 static ssize_t suspend_dtim_interval_write(struct file *file,
688 const char __user *user_buf,
689 size_t count, loff_t *ppos)
691 struct wl1271 *wl = file->private_data;
695 ret = kstrtoul_from_user(user_buf, count, 10, &value);
697 wl1271_warning("illegal value for suspend_dtim_interval");
701 if (value < 1 || value > 10) {
702 wl1271_warning("suspend_dtim value is not in valid range");
706 mutex_lock(&wl->mutex);
708 wl->conf.conn.suspend_listen_interval = value;
709 /* for some reason there are different event types for 1 and >1 */
711 wl->conf.conn.suspend_wake_up_event = CONF_WAKE_UP_EVENT_DTIM;
713 wl->conf.conn.suspend_wake_up_event = CONF_WAKE_UP_EVENT_N_DTIM;
715 mutex_unlock(&wl->mutex);
720 static const struct file_operations suspend_dtim_interval_ops = {
721 .read = suspend_dtim_interval_read,
722 .write = suspend_dtim_interval_write,
724 .llseek = default_llseek,
727 static ssize_t beacon_interval_read(struct file *file, char __user *user_buf,
728 size_t count, loff_t *ppos)
730 struct wl1271 *wl = file->private_data;
733 if (wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_BEACON ||
734 wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_N_BEACONS)
735 value = wl->conf.conn.listen_interval;
739 return wl1271_format_buffer(user_buf, count, ppos, "%d\n", value);
742 static ssize_t beacon_interval_write(struct file *file,
743 const char __user *user_buf,
744 size_t count, loff_t *ppos)
746 struct wl1271 *wl = file->private_data;
750 ret = kstrtoul_from_user(user_buf, count, 10, &value);
752 wl1271_warning("illegal value for beacon_interval");
756 if (value < 1 || value > 255) {
757 wl1271_warning("beacon interval value is not in valid range");
761 mutex_lock(&wl->mutex);
763 wl->conf.conn.listen_interval = value;
764 /* for some reason there are different event types for 1 and >1 */
766 wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_BEACON;
768 wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_N_BEACONS;
771 * we don't reconfigure ACX_WAKE_UP_CONDITIONS now, so it will only
772 * take effect on the next time we enter psm.
774 mutex_unlock(&wl->mutex);
778 static const struct file_operations beacon_interval_ops = {
779 .read = beacon_interval_read,
780 .write = beacon_interval_write,
782 .llseek = default_llseek,
785 static ssize_t rx_streaming_interval_write(struct file *file,
786 const char __user *user_buf,
787 size_t count, loff_t *ppos)
789 struct wl1271 *wl = file->private_data;
790 struct wl12xx_vif *wlvif;
794 ret = kstrtoul_from_user(user_buf, count, 10, &value);
796 wl1271_warning("illegal value in rx_streaming_interval!");
800 /* valid values: 0, 10-100 */
801 if (value && (value < 10 || value > 100)) {
802 wl1271_warning("value is not in range!");
806 mutex_lock(&wl->mutex);
808 wl->conf.rx_streaming.interval = value;
810 ret = wl1271_ps_elp_wakeup(wl);
814 wl12xx_for_each_wlvif_sta(wl, wlvif) {
815 wl1271_recalc_rx_streaming(wl, wlvif);
818 wl1271_ps_elp_sleep(wl);
820 mutex_unlock(&wl->mutex);
824 static ssize_t rx_streaming_interval_read(struct file *file,
825 char __user *userbuf,
826 size_t count, loff_t *ppos)
828 struct wl1271 *wl = file->private_data;
829 return wl1271_format_buffer(userbuf, count, ppos,
830 "%d\n", wl->conf.rx_streaming.interval);
833 static const struct file_operations rx_streaming_interval_ops = {
834 .read = rx_streaming_interval_read,
835 .write = rx_streaming_interval_write,
837 .llseek = default_llseek,
840 static ssize_t rx_streaming_always_write(struct file *file,
841 const char __user *user_buf,
842 size_t count, loff_t *ppos)
844 struct wl1271 *wl = file->private_data;
845 struct wl12xx_vif *wlvif;
849 ret = kstrtoul_from_user(user_buf, count, 10, &value);
851 wl1271_warning("illegal value in rx_streaming_write!");
855 /* valid values: 0, 10-100 */
856 if (!(value == 0 || value == 1)) {
857 wl1271_warning("value is not in valid!");
861 mutex_lock(&wl->mutex);
863 wl->conf.rx_streaming.always = value;
865 ret = wl1271_ps_elp_wakeup(wl);
869 wl12xx_for_each_wlvif_sta(wl, wlvif) {
870 wl1271_recalc_rx_streaming(wl, wlvif);
873 wl1271_ps_elp_sleep(wl);
875 mutex_unlock(&wl->mutex);
879 static ssize_t rx_streaming_always_read(struct file *file,
880 char __user *userbuf,
881 size_t count, loff_t *ppos)
883 struct wl1271 *wl = file->private_data;
884 return wl1271_format_buffer(userbuf, count, ppos,
885 "%d\n", wl->conf.rx_streaming.always);
888 static const struct file_operations rx_streaming_always_ops = {
889 .read = rx_streaming_always_read,
890 .write = rx_streaming_always_write,
892 .llseek = default_llseek,
895 static ssize_t beacon_filtering_write(struct file *file,
896 const char __user *user_buf,
897 size_t count, loff_t *ppos)
899 struct wl1271 *wl = file->private_data;
900 struct wl12xx_vif *wlvif;
906 len = min(count, sizeof(buf) - 1);
907 if (copy_from_user(buf, user_buf, len))
911 ret = kstrtoul(buf, 0, &value);
913 wl1271_warning("illegal value for beacon_filtering!");
917 mutex_lock(&wl->mutex);
919 ret = wl1271_ps_elp_wakeup(wl);
923 wl12xx_for_each_wlvif(wl, wlvif) {
924 ret = wl1271_acx_beacon_filter_opt(wl, wlvif, !!value);
927 wl1271_ps_elp_sleep(wl);
929 mutex_unlock(&wl->mutex);
933 static const struct file_operations beacon_filtering_ops = {
934 .write = beacon_filtering_write,
936 .llseek = default_llseek,
939 static int wl1271_debugfs_add_files(struct wl1271 *wl,
940 struct dentry *rootdir)
943 struct dentry *entry, *streaming;
945 DEBUGFS_ADD(tx_queue_len, rootdir);
946 DEBUGFS_ADD(retry_count, rootdir);
947 DEBUGFS_ADD(excessive_retries, rootdir);
949 DEBUGFS_ADD(gpio_power, rootdir);
950 DEBUGFS_ADD(start_recovery, rootdir);
951 DEBUGFS_ADD(driver_state, rootdir);
952 DEBUGFS_ADD(vifs_state, rootdir);
953 DEBUGFS_ADD(dtim_interval, rootdir);
954 DEBUGFS_ADD(suspend_dtim_interval, rootdir);
955 DEBUGFS_ADD(beacon_interval, rootdir);
956 DEBUGFS_ADD(beacon_filtering, rootdir);
957 DEBUGFS_ADD(dynamic_ps_timeout, rootdir);
958 DEBUGFS_ADD(forced_ps, rootdir);
959 DEBUGFS_ADD(split_scan_timeout, rootdir);
961 streaming = debugfs_create_dir("rx_streaming", rootdir);
962 if (!streaming || IS_ERR(streaming))
965 DEBUGFS_ADD_PREFIX(rx_streaming, interval, streaming);
966 DEBUGFS_ADD_PREFIX(rx_streaming, always, streaming);
973 ret = PTR_ERR(entry);
980 void wl1271_debugfs_reset(struct wl1271 *wl)
982 if (!wl->stats.fw_stats)
985 memset(wl->stats.fw_stats, 0, wl->stats.fw_stats_len);
986 wl->stats.retry_count = 0;
987 wl->stats.excessive_retries = 0;
990 int wl1271_debugfs_init(struct wl1271 *wl)
993 struct dentry *rootdir;
995 rootdir = debugfs_create_dir(KBUILD_MODNAME,
996 wl->hw->wiphy->debugfsdir);
998 if (IS_ERR(rootdir)) {
999 ret = PTR_ERR(rootdir);
1003 wl->stats.fw_stats = kzalloc(wl->stats.fw_stats_len, GFP_KERNEL);
1004 if (!wl->stats.fw_stats) {
1009 wl->stats.fw_stats_update = jiffies;
1011 ret = wl1271_debugfs_add_files(wl, rootdir);
1015 ret = wlcore_debugfs_init(wl, rootdir);
1022 wl1271_debugfs_exit(wl);
1025 debugfs_remove_recursive(rootdir);
1031 void wl1271_debugfs_exit(struct wl1271 *wl)
1033 kfree(wl->stats.fw_stats);
1034 wl->stats.fw_stats = NULL;