6 #include <linux/string.h>
7 #include <linux/slab.h>
8 #include <linux/export.h>
14 static struct dentry *lbs_dir;
15 static char *szStates[] = {
25 size_t count, loff_t *ppos)
33 size_t count, loff_t *ppos)
38 char *
buf = (
char *)addr;
43 pos +=
snprintf(buf+pos, len-pos,
"state = %s\n",
45 pos +=
snprintf(buf+pos, len-pos,
"region_code = %02x\n",
54 static ssize_t lbs_sleepparams_write(
struct file *file,
55 const char __user *user_buf,
size_t count,
61 int p1, p2, p3, p4, p5, p6;
63 char *buf = (
char *)addr;
67 buf_size =
min(count, len - 1);
72 ret =
sscanf(buf,
"%d %d %d %d %d %d", &p1, &p2, &p3, &p4, &p5, &p6);
79 sp.sp_stabletime = p3;
80 sp.sp_calcontrol = p4;
81 sp.sp_extsleepclk = p5;
95 static ssize_t lbs_sleepparams_read(
struct file *file,
char __user *userbuf,
96 size_t count, loff_t *ppos)
103 char *buf = (
char *)addr;
111 pos +=
snprintf(buf, len,
"%d %d %d %d %d %d\n",
sp.sp_error,
112 sp.sp_offset,
sp.sp_stabletime,
113 sp.sp_calcontrol,
sp.sp_extsleepclk,
123 static ssize_t lbs_host_sleep_write(
struct file *file,
124 const char __user *user_buf,
size_t count,
131 char *buf = (
char *)addr;
135 buf_size =
min(count, len - 1);
140 ret =
sscanf(buf,
"%d", &host_sleep);
148 else if (host_sleep == 1) {
150 netdev_info(priv->
dev,
151 "wake parameters not configured\n");
157 netdev_err(priv->
dev,
"invalid option\n");
169 static ssize_t lbs_host_sleep_read(
struct file *file,
char __user *userbuf,
170 size_t count, loff_t *ppos)
176 char *buf = (
char *)addr;
225 struct file *file,
char __user *userbuf,
226 size_t count, loff_t *ppos)
242 subscribed = kzalloc(
sizeof(*subscribed),
GFP_KERNEL);
255 got = lbs_tlv_find(tlv_type, subscribed->
tlv,
sizeof(subscribed->
tlv));
261 pos +=
snprintf(buf, len,
"%d %d %d\n", value, freq,
262 !!(events & event_mask));
278 const char __user *userbuf,
size_t count,
294 buf_size =
min(count, len - 1);
299 ret =
sscanf(buf,
"%d %d %d", &value, &freq, &new_mask);
304 events = kzalloc(
sizeof(*events),
GFP_KERNEL);
320 new_mask = curr_mask | event_mask;
322 new_mask = curr_mask & ~event_mask;
326 tlv = (
void *)events->
tlv;
351 static ssize_t lbs_lowrssi_read(
struct file *file,
char __user *userbuf,
352 size_t count, loff_t *ppos)
355 file, userbuf, count, ppos);
359 static ssize_t lbs_lowrssi_write(
struct file *file,
const char __user *userbuf,
360 size_t count, loff_t *ppos)
363 file, userbuf, count, ppos);
367 static ssize_t lbs_lowsnr_read(
struct file *file,
char __user *userbuf,
368 size_t count, loff_t *ppos)
371 file, userbuf, count, ppos);
375 static ssize_t lbs_lowsnr_write(
struct file *file,
const char __user *userbuf,
376 size_t count, loff_t *ppos)
379 file, userbuf, count, ppos);
383 static ssize_t lbs_failcount_read(
struct file *file,
char __user *userbuf,
384 size_t count, loff_t *ppos)
387 file, userbuf, count, ppos);
391 static ssize_t lbs_failcount_write(
struct file *file,
const char __user *userbuf,
392 size_t count, loff_t *ppos)
395 file, userbuf, count, ppos);
399 static ssize_t lbs_highrssi_read(
struct file *file,
char __user *userbuf,
400 size_t count, loff_t *ppos)
403 file, userbuf, count, ppos);
407 static ssize_t lbs_highrssi_write(
struct file *file,
const char __user *userbuf,
408 size_t count, loff_t *ppos)
411 file, userbuf, count, ppos);
415 static ssize_t lbs_highsnr_read(
struct file *file,
char __user *userbuf,
416 size_t count, loff_t *ppos)
419 file, userbuf, count, ppos);
423 static ssize_t lbs_highsnr_write(
struct file *file,
const char __user *userbuf,
424 size_t count, loff_t *ppos)
427 file, userbuf, count, ppos);
430 static ssize_t lbs_bcnmiss_read(
struct file *file,
char __user *userbuf,
431 size_t count, loff_t *ppos)
434 file, userbuf, count, ppos);
438 static ssize_t lbs_bcnmiss_write(
struct file *file,
const char __user *userbuf,
439 size_t count, loff_t *ppos)
442 file, userbuf, count, ppos);
446 static ssize_t lbs_rdmac_read(
struct file *file,
char __user *userbuf,
447 size_t count, loff_t *ppos)
453 char *buf = (
char *)addr;
462 pos =
snprintf(buf, len,
"MAC[0x%x] = 0x%08x\n",
470 static ssize_t lbs_rdmac_write(
struct file *file,
471 const char __user *userbuf,
472 size_t count, loff_t *ppos)
477 char *buf = (
char *)addr;
481 buf_size =
min(count, len - 1);
493 static ssize_t lbs_wrmac_write(
struct file *file,
494 const char __user *userbuf,
495 size_t count, loff_t *ppos)
502 char *buf = (
char *)addr;
506 buf_size =
min(count, len - 1);
511 res =
sscanf(buf,
"%x %x", &offset, &value);
527 static ssize_t lbs_rdbbp_read(
struct file *file,
char __user *userbuf,
528 size_t count, loff_t *ppos)
534 char *buf = (
char *)addr;
543 pos =
snprintf(buf, len,
"BBP[0x%x] = 0x%08x\n",
552 static ssize_t lbs_rdbbp_write(
struct file *file,
553 const char __user *userbuf,
554 size_t count, loff_t *ppos)
559 char *buf = (
char *)addr;
563 buf_size =
min(count, len - 1);
575 static ssize_t lbs_wrbbp_write(
struct file *file,
576 const char __user *userbuf,
577 size_t count, loff_t *ppos)
584 char *buf = (
char *)addr;
588 buf_size =
min(count, len - 1);
593 res =
sscanf(buf,
"%x %x", &offset, &value);
609 static ssize_t lbs_rdrf_read(
struct file *file,
char __user *userbuf,
610 size_t count, loff_t *ppos)
616 char *buf = (
char *)addr;
625 pos =
snprintf(buf, len,
"RF[0x%x] = 0x%08x\n",
634 static ssize_t lbs_rdrf_write(
struct file *file,
635 const char __user *userbuf,
636 size_t count, loff_t *ppos)
641 char *buf = (
char *)addr;
645 buf_size =
min(count, len - 1);
657 static ssize_t lbs_wrrf_write(
struct file *file,
658 const char __user *userbuf,
659 size_t count, loff_t *ppos)
666 char *buf = (
char *)addr;
670 buf_size =
min(count, len - 1);
675 res =
sscanf(buf,
"%x %x", &offset, &value);
691 #define FOPS(fread, fwrite) { \
692 .owner = THIS_MODULE, \
693 .open = simple_open, \
696 .llseek = generic_file_llseek, \
706 {
"info", 0444,
FOPS(lbs_dev_info, write_file_dummy), },
707 {
"sleepparams", 0644,
FOPS(lbs_sleepparams_read,
708 lbs_sleepparams_write), },
709 {
"hostsleep", 0644,
FOPS(lbs_host_sleep_read,
710 lbs_host_sleep_write), },
714 {
"low_rssi", 0644,
FOPS(lbs_lowrssi_read,
715 lbs_lowrssi_write), },
716 {
"low_snr", 0644,
FOPS(lbs_lowsnr_read,
717 lbs_lowsnr_write), },
718 {
"failure_count", 0644,
FOPS(lbs_failcount_read,
719 lbs_failcount_write), },
720 {
"beacon_missed", 0644,
FOPS(lbs_bcnmiss_read,
721 lbs_bcnmiss_write), },
722 {
"high_rssi", 0644,
FOPS(lbs_highrssi_read,
723 lbs_highrssi_write), },
724 {
"high_snr", 0644,
FOPS(lbs_highsnr_read,
725 lbs_highsnr_write), },
729 {
"rdmac", 0644,
FOPS(lbs_rdmac_read, lbs_rdmac_write), },
730 {
"wrmac", 0600,
FOPS(
NULL, lbs_wrmac_write), },
731 {
"rdbbp", 0644,
FOPS(lbs_rdbbp_read, lbs_rdbbp_write), },
732 {
"wrbbp", 0600,
FOPS(
NULL, lbs_wrbbp_write), },
733 {
"rdrf", 0644,
FOPS(lbs_rdrf_read, lbs_rdrf_write), },
734 {
"wrrf", 0600,
FOPS(
NULL, lbs_wrrf_write), },
761 files = &debugfs_files[
i];
773 for (i=0; i<
ARRAY_SIZE(debugfs_events_files); i++) {
774 files = &debugfs_events_files[
i];
786 for (i=0; i<
ARRAY_SIZE(debugfs_regs_files); i++) {
787 files = &debugfs_regs_files[
i];
796 lbs_debug_init(priv);
806 for(i=0; i<
ARRAY_SIZE(debugfs_regs_files); i++)
811 for(i=0; i<
ARRAY_SIZE(debugfs_events_files); i++)
829 #define item_size(n) (FIELD_SIZEOF(struct lbs_private, n))
830 #define item_addr(n) (offsetof(struct lbs_private, n))
841 static struct debug_data
items[] = {
858 static ssize_t lbs_debugfs_read(
struct file *file,
char __user *userbuf,
859 size_t count, loff_t *ppos)
866 struct debug_data *
d;
868 char *buf = (
char *)addr;
876 for (i = 0; i < num_of_items; i++) {
878 val = *((
u8 *) d[i].addr);
879 else if (d[i].size == 2)
880 val = *((
u16 *) d[i].addr);
881 else if (d[i].size == 4)
882 val = *((
u32 *) d[i].addr);
883 else if (d[i].size == 8)
884 val = *((
u64 *) d[i].addr);
886 pos +=
sprintf(p + pos,
"%s=%d\n", d[i].
name, val);
905 static ssize_t lbs_debugfs_write(
struct file *
f,
const char __user *buf,
906 size_t cnt, loff_t *ppos)
927 for (i = 0; i < num_of_items; i++) {
942 *((
u8 *) d[i].addr) = (
u8) r;
943 else if (d[i].size == 2)
944 *((
u16 *) d[i].addr) = (
u16) r;
945 else if (d[i].size == 4)
946 *((
u32 *) d[i].addr) = (
u32) r;
947 else if (d[i].size == 8)
948 *((
u64 *) d[i].addr) = (
u64) r;
960 .write = lbs_debugfs_write,
961 .read = lbs_debugfs_read,
972 static void lbs_debug_init(
struct lbs_private *priv)
979 for (i = 0; i < num_of_items; i++)
980 items[i].addr += (
size_t)
priv;