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