1
2
3
4
5
6
7
8
9
10
11
12
13#if defined(WILC_DEBUGFS)
14#include <linux/module.h>
15#include <linux/debugfs.h>
16#include <linux/poll.h>
17#include <linux/sched.h>
18
19#include "wilc_wlan_if.h"
20
21static struct dentry *wilc_dir;
22
23
24
25
26#define DEBUG BIT(0)
27#define INFO BIT(1)
28#define WRN BIT(2)
29#define ERR BIT(3)
30
31#define DBG_LEVEL_ALL (DEBUG | INFO | WRN | ERR)
32static atomic_t WILC_DEBUG_LEVEL = ATOMIC_INIT(ERR);
33EXPORT_SYMBOL_GPL(WILC_DEBUG_LEVEL);
34
35
36
37
38
39static ssize_t wilc_debug_level_read(struct file *file, char __user *userbuf,
40 size_t count, loff_t *ppos)
41{
42 char buf[128];
43 int res = 0;
44
45
46 if (*ppos > 0)
47 return 0;
48
49 res = scnprintf(buf, sizeof(buf), "Debug Level: %x\n",
50 atomic_read(&WILC_DEBUG_LEVEL));
51
52 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
53}
54
55static ssize_t wilc_debug_level_write(struct file *filp,
56 const char __user *buf, size_t count,
57 loff_t *ppos)
58{
59 int flag = 0;
60 int ret;
61
62 ret = kstrtouint_from_user(buf, count, 16, &flag);
63 if (ret)
64 return ret;
65
66 if (flag > DBG_LEVEL_ALL) {
67 pr_info("%s, value (0x%08x) is out of range, stay previous flag (0x%08x)\n",
68 __func__, flag, atomic_read(&WILC_DEBUG_LEVEL));
69 return -EINVAL;
70 }
71
72 atomic_set(&WILC_DEBUG_LEVEL, (int)flag);
73
74 if (flag == 0)
75 pr_info("Debug-level disabled\n");
76 else
77 pr_info("Debug-level enabled\n");
78
79 return count;
80}
81
82
83
84
85
86#define FOPS(_open, _read, _write, _poll) { \
87 .owner = THIS_MODULE, \
88 .open = (_open), \
89 .read = (_read), \
90 .write = (_write), \
91 .poll = (_poll), \
92}
93
94struct wilc_debugfs_info_t {
95 const char *name;
96 int perm;
97 unsigned int data;
98 const struct file_operations fops;
99};
100
101static struct wilc_debugfs_info_t debugfs_info[] = {
102 {
103 "wilc_debug_level",
104 0666,
105 (DEBUG | ERR),
106 FOPS(NULL, wilc_debug_level_read, wilc_debug_level_write, NULL),
107 },
108};
109
110static int __init wilc_debugfs_init(void)
111{
112 int i;
113 struct wilc_debugfs_info_t *info;
114
115 wilc_dir = debugfs_create_dir("wilc_wifi", NULL);
116 for (i = 0; i < ARRAY_SIZE(debugfs_info); i++) {
117 info = &debugfs_info[i];
118 debugfs_create_file(info->name,
119 info->perm,
120 wilc_dir,
121 &info->data,
122 &info->fops);
123 }
124 return 0;
125}
126module_init(wilc_debugfs_init);
127
128static void __exit wilc_debugfs_remove(void)
129{
130 debugfs_remove_recursive(wilc_dir);
131}
132module_exit(wilc_debugfs_remove);
133
134#endif
135