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))
45 loff_t *ppos,
char *
fmt, ...)
88 wl->stats.excessive_retries);
90 static ssize_t tx_queue_len_read(
struct file *
file,
char __user *userbuf,
91 size_t count, loff_t *ppos)
98 queue_len = wl1271_tx_total_queue_count(wl);
100 res =
scnprintf(buf,
sizeof(buf),
"%u\n", queue_len);
105 .read = tx_queue_len_read,
110 static void chip_op_handler(
struct wl1271 *wl,
unsigned long value,
132 static inline void no_write_handler(
struct wl1271 *wl,
138 #define WL12XX_CONF_DEBUGFS(param, conf_sub_struct, \
139 min_val, max_val, write_handler_locked, \
141 static ssize_t param##_read(struct file *file, \
142 char __user *user_buf, \
143 size_t count, loff_t *ppos) \
145 struct wl1271 *wl = file->private_data; \
146 return wl1271_format_buffer(user_buf, count, \
148 wl->conf.conf_sub_struct.param); \
151 static ssize_t param##_write(struct file *file, \
152 const char __user *user_buf, \
153 size_t count, loff_t *ppos) \
155 struct wl1271 *wl = file->private_data; \
156 unsigned long value; \
159 ret = kstrtoul_from_user(user_buf, count, 10, &value); \
161 wl1271_warning("illegal value for " #param); \
165 if (value < min_val || value > max_val) { \
166 wl1271_warning(#param " is not in valid range"); \
170 mutex_lock(&wl->mutex); \
171 wl->conf.conf_sub_struct.param = value; \
173 write_handler_locked(wl, value, write_handler_arg); \
175 mutex_unlock(&wl->mutex); \
179 static const struct file_operations param##_ops = { \
180 .read = param##_read, \
181 .write = param##_write, \
182 .open = simple_open, \
183 .llseek = default_llseek, \
193 static
ssize_t gpio_power_read(
struct file *file,
char __user *user_buf,
194 size_t count, loff_t *ppos)
196 struct wl1271 *wl = file->private_data;
202 res =
scnprintf(buf,
sizeof(buf),
"%d\n", state);
207 static ssize_t gpio_power_write(
struct file *file,
208 const char __user *user_buf,
209 size_t count, loff_t *ppos)
226 wl1271_power_off(wl);
233 .read = gpio_power_read,
234 .write = gpio_power_write,
239 static ssize_t start_recovery_write(
struct file *file,
240 const char __user *user_buf,
241 size_t count, loff_t *ppos)
253 .write = start_recovery_write,
258 static ssize_t dynamic_ps_timeout_read(
struct file *file,
char __user *user_buf,
259 size_t count, loff_t *ppos)
265 wl->
conf.conn.dynamic_ps_timeout);
268 static ssize_t dynamic_ps_timeout_write(
struct file *file,
269 const char __user *user_buf,
270 size_t count, loff_t *ppos)
283 if (value < 1 || value > 65535) {
290 wl->
conf.conn.dynamic_ps_timeout =
value;
316 .read = dynamic_ps_timeout_read,
317 .write = dynamic_ps_timeout_write,
322 static ssize_t forced_ps_read(
struct file *file,
char __user *user_buf,
323 size_t count, loff_t *ppos)
329 wl->
conf.conn.forced_ps);
332 static ssize_t forced_ps_write(
struct file *file,
333 const char __user *user_buf,
334 size_t count, loff_t *ppos)
347 if (value != 1 && value != 0) {
354 if (wl->
conf.conn.forced_ps == value)
385 .read = forced_ps_read,
386 .write = forced_ps_write,
391 static ssize_t split_scan_timeout_read(
struct file *file,
char __user *user_buf,
392 size_t count, loff_t *ppos)
398 wl->
conf.scan.split_scan_timeout / 1000);
401 static ssize_t split_scan_timeout_write(
struct file *file,
402 const char __user *user_buf,
403 size_t count, loff_t *ppos)
420 wl->
conf.scan.split_scan_timeout = value * 1000;
427 .read = split_scan_timeout_read,
428 .write = split_scan_timeout_write,
433 static ssize_t driver_state_read(
struct file *file,
char __user *user_buf,
434 size_t count, loff_t *ppos)
441 #define DRIVER_STATE_BUF_LEN 1024
449 #define DRIVER_STATE_PRINT(x, fmt) \
450 (res += scnprintf(buf + res, DRIVER_STATE_BUF_LEN - res,\
451 #x " = " fmt "\n", wl->x))
453 #define DRIVER_STATE_PRINT_LONG(x) DRIVER_STATE_PRINT(x, "%ld")
454 #define DRIVER_STATE_PRINT_INT(x) DRIVER_STATE_PRINT(x, "%d")
455 #define DRIVER_STATE_PRINT_STR(x) DRIVER_STATE_PRINT(x, "%s")
456 #define DRIVER_STATE_PRINT_LHEX(x) DRIVER_STATE_PRINT(x, "0x%lx")
457 #define DRIVER_STATE_PRINT_HEX(x) DRIVER_STATE_PRINT(x, "0x%x")
495 #undef DRIVER_STATE_PRINT_INT
496 #undef DRIVER_STATE_PRINT_LONG
497 #undef DRIVER_STATE_PRINT_HEX
498 #undef DRIVER_STATE_PRINT_LHEX
499 #undef DRIVER_STATE_PRINT_STR
500 #undef DRIVER_STATE_PRINT
501 #undef DRIVER_STATE_BUF_LEN
511 .read = driver_state_read,
516 static ssize_t vifs_state_read(
struct file *file,
char __user *user_buf,
517 size_t count, loff_t *ppos)
532 #define VIF_STATE_PRINT(x, fmt) \
533 (res += scnprintf(buf + res, buf_size - res, \
534 #x " = " fmt "\n", wlvif->x))
536 #define VIF_STATE_PRINT_LONG(x) VIF_STATE_PRINT(x, "%ld")
537 #define VIF_STATE_PRINT_INT(x) VIF_STATE_PRINT(x, "%d")
538 #define VIF_STATE_PRINT_STR(x) VIF_STATE_PRINT(x, "%s")
539 #define VIF_STATE_PRINT_LHEX(x) VIF_STATE_PRINT(x, "0x%lx")
540 #define VIF_STATE_PRINT_LLHEX(x) VIF_STATE_PRINT(x, "0x%llx")
541 #define VIF_STATE_PRINT_HEX(x) VIF_STATE_PRINT(x, "0x%x")
543 #define VIF_STATE_PRINT_NSTR(x, len) \
545 memset(tmp_buf, 0, sizeof(tmp_buf)); \
546 memcpy(tmp_buf, wlvif->x, \
547 min_t(u8, len, sizeof(tmp_buf) - 1)); \
548 res += scnprintf(buf + res, buf_size - res, \
549 #x " = %s\n", tmp_buf); \
603 #undef VIF_STATE_PRINT_INT
604 #undef VIF_STATE_PRINT_LONG
605 #undef VIF_STATE_PRINT_HEX
606 #undef VIF_STATE_PRINT_LHEX
607 #undef VIF_STATE_PRINT_LLHEX
608 #undef VIF_STATE_PRINT_STR
609 #undef VIF_STATE_PRINT_NSTR
610 #undef VIF_STATE_PRINT
620 .read = vifs_state_read,
625 static ssize_t dtim_interval_read(
struct file *file,
char __user *user_buf,
626 size_t count, loff_t *ppos)
633 value = wl->
conf.conn.listen_interval;
640 static ssize_t dtim_interval_write(
struct file *file,
641 const char __user *user_buf,
642 size_t count, loff_t *ppos)
654 if (value < 1 || value > 10) {
677 .read = dtim_interval_read,
678 .write = dtim_interval_write,
685 static ssize_t suspend_dtim_interval_read(
struct file *file,
686 char __user *user_buf,
687 size_t count, loff_t *ppos)
694 value = wl->
conf.conn.suspend_listen_interval;
701 static ssize_t suspend_dtim_interval_write(
struct file *file,
702 const char __user *user_buf,
703 size_t count, loff_t *ppos)
715 if (value < 1 || value > 10) {
722 wl->
conf.conn.suspend_listen_interval =
value;
735 .read = suspend_dtim_interval_read,
736 .write = suspend_dtim_interval_write,
741 static ssize_t beacon_interval_read(
struct file *file,
char __user *user_buf,
742 size_t count, loff_t *ppos)
749 value = wl->
conf.conn.listen_interval;
756 static ssize_t beacon_interval_write(
struct file *file,
757 const char __user *user_buf,
758 size_t count, loff_t *ppos)
770 if (value < 1 || value > 255) {
793 .read = beacon_interval_read,
794 .write = beacon_interval_write,
799 static ssize_t rx_streaming_interval_write(
struct file *file,
800 const char __user *user_buf,
801 size_t count, loff_t *ppos)
815 if (value && (value < 10 || value > 100)) {
838 static ssize_t rx_streaming_interval_read(
struct file *file,
839 char __user *userbuf,
840 size_t count, loff_t *ppos)
844 "%d\n", wl->
conf.rx_streaming.interval);
848 .read = rx_streaming_interval_read,
849 .write = rx_streaming_interval_write,
854 static ssize_t rx_streaming_always_write(
struct file *file,
855 const char __user *user_buf,
856 size_t count, loff_t *ppos)
870 if (!(value == 0 || value == 1)) {
893 static ssize_t rx_streaming_always_read(
struct file *file,
894 char __user *userbuf,
895 size_t count, loff_t *ppos)
899 "%d\n", wl->
conf.rx_streaming.always);
903 .read = rx_streaming_always_read,
904 .write = rx_streaming_always_write,
909 static ssize_t beacon_filtering_write(
struct file *file,
910 const char __user *user_buf,
911 size_t count, loff_t *ppos)
920 len =
min(count,
sizeof(buf) - 1);
925 ret = kstrtoul(buf, 0, &value);
948 .write = beacon_filtering_write,
953 static ssize_t fw_stats_raw_read(
struct file *file,
954 char __user *userbuf,
955 size_t count, loff_t *ppos)
963 wl->
stats.fw_stats_len);
967 .read = fw_stats_raw_read,
972 static ssize_t sleep_auth_read(
struct file *file,
char __user *user_buf,
973 size_t count, loff_t *ppos)
982 static ssize_t sleep_auth_write(
struct file *file,
983 const char __user *user_buf,
984 size_t count, loff_t *ppos)
1028 .read = sleep_auth_read,
1029 .write = sleep_auth_write,
1034 static ssize_t dev_mem_read(
struct file *file,
1035 char __user *user_buf,
size_t count,
1084 ret = wlcore_raw_read(wl, 0, buf, bytes,
false);
1113 return ((ret == 0) ? bytes : ret);
1116 static ssize_t dev_mem_write(
struct file *file,
const char __user *user_buf,
1117 size_t count, loff_t *ppos)
1121 size_t bytes =
count;
1171 ret = wlcore_raw_write(wl, 0, buf, bytes,
false);
1193 return ((ret == 0) ? bytes : ret);
1196 static loff_t dev_mem_seek(
struct file *file, loff_t
offset,
int orig)
1222 .read = dev_mem_read,
1223 .write = dev_mem_write,
1224 .llseek = dev_mem_seek,
1227 static int wl1271_debugfs_add_files(
struct wl1271 *wl,
1255 if (!streaming || IS_ERR(streaming))
1267 ret = PTR_ERR(entry);
1276 if (!wl->
stats.fw_stats)
1280 wl->
stats.retry_count = 0;
1281 wl->
stats.excessive_retries = 0;
1290 wl->
hw->wiphy->debugfsdir);
1292 if (IS_ERR(rootdir)) {
1293 ret = PTR_ERR(rootdir);
1298 if (!wl->
stats.fw_stats) {
1305 ret = wl1271_debugfs_add_files(wl, rootdir);
1309 ret = wlcore_debugfs_init(wl, rootdir);