2 * Copyright (c) 2013 Eugene Krasnikov <k.eugene.e@gmail.com>
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
19 #include <linux/debugfs.h>
20 #include <linux/uaccess.h>
25 #ifdef CONFIG_WCN36XX_DEBUGFS
27 static ssize_t
read_file_bool_bmps(struct file
*file
, char __user
*user_buf
,
28 size_t count
, loff_t
*ppos
)
30 struct wcn36xx
*wcn
= file
->private_data
;
31 struct wcn36xx_vif
*vif_priv
= NULL
;
32 struct ieee80211_vif
*vif
= NULL
;
35 list_for_each_entry(vif_priv
, &wcn
->vif_list
, list
) {
36 vif
= wcn36xx_priv_to_vif(vif_priv
);
37 if (NL80211_IFTYPE_STATION
== vif
->type
) {
38 if (vif_priv
->pw_state
== WCN36XX_BMPS
)
48 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, 2);
51 static ssize_t
write_file_bool_bmps(struct file
*file
,
52 const char __user
*user_buf
,
53 size_t count
, loff_t
*ppos
)
55 struct wcn36xx
*wcn
= file
->private_data
;
56 struct wcn36xx_vif
*vif_priv
= NULL
;
57 struct ieee80211_vif
*vif
= NULL
;
62 buf_size
= min(count
, (sizeof(buf
)-1));
63 if (copy_from_user(buf
, user_buf
, buf_size
))
70 list_for_each_entry(vif_priv
, &wcn
->vif_list
, list
) {
71 vif
= wcn36xx_priv_to_vif(vif_priv
);
72 if (NL80211_IFTYPE_STATION
== vif
->type
) {
73 wcn36xx_enable_keep_alive_null_packet(wcn
, vif
);
74 wcn36xx_pmc_enter_bmps_state(wcn
, vif
);
81 list_for_each_entry(vif_priv
, &wcn
->vif_list
, list
) {
82 vif
= wcn36xx_priv_to_vif(vif_priv
);
83 if (NL80211_IFTYPE_STATION
== vif
->type
)
84 wcn36xx_pmc_exit_bmps_state(wcn
, vif
);
92 static const struct file_operations fops_wcn36xx_bmps
= {
94 .read
= read_file_bool_bmps
,
95 .write
= write_file_bool_bmps
,
98 static ssize_t
write_file_dump(struct file
*file
,
99 const char __user
*user_buf
,
100 size_t count
, loff_t
*ppos
)
102 struct wcn36xx
*wcn
= file
->private_data
;
105 u32 arg
[WCN36xx_MAX_DUMP_ARGS
];
108 memset(buf
, 0, sizeof(buf
));
109 memset(arg
, 0, sizeof(arg
));
111 buf_size
= min(count
, (sizeof(buf
) - 1));
112 if (copy_from_user(buf
, user_buf
, buf_size
))
117 for (i
= 0; i
< WCN36xx_MAX_DUMP_ARGS
; i
++) {
119 begin
= strsep(&tmp
, " ");
123 if (kstrtou32(begin
, 0, &arg
[i
]) != 0)
127 wcn36xx_info("DUMP args is %d %d %d %d %d\n", arg
[0], arg
[1], arg
[2],
129 wcn36xx_smd_dump_cmd_req(wcn
, arg
[0], arg
[1], arg
[2], arg
[3], arg
[4]);
134 static const struct file_operations fops_wcn36xx_dump
= {
136 .write
= write_file_dump
,
139 #define ADD_FILE(name, mode, fop, priv_data) \
142 d = debugfs_create_file(__stringify(name), \
143 mode, dfs->rootdir, \
145 dfs->file_##name.dentry = d; \
147 wcn36xx_warn("Create the debugfs entry failed");\
148 dfs->file_##name.dentry = NULL; \
153 void wcn36xx_debugfs_init(struct wcn36xx
*wcn
)
155 struct wcn36xx_dfs_entry
*dfs
= &wcn
->dfs
;
157 dfs
->rootdir
= debugfs_create_dir(KBUILD_MODNAME
,
158 wcn
->hw
->wiphy
->debugfsdir
);
159 if (IS_ERR(dfs
->rootdir
)) {
160 wcn36xx_warn("Create the debugfs failed\n");
164 ADD_FILE(bmps_switcher
, S_IRUSR
| S_IWUSR
,
165 &fops_wcn36xx_bmps
, wcn
);
166 ADD_FILE(dump
, S_IWUSR
, &fops_wcn36xx_dump
, wcn
);
169 void wcn36xx_debugfs_exit(struct wcn36xx
*wcn
)
171 struct wcn36xx_dfs_entry
*dfs
= &wcn
->dfs
;
172 debugfs_remove_recursive(dfs
->rootdir
);
175 #endif /* CONFIG_WCN36XX_DEBUGFS */