]>
Commit | Line | Data |
---|---|---|
e9f207f0 JB |
1 | /* |
2 | * mac80211 debugfs for wireless PHYs | |
3 | * | |
4 | * Copyright 2007 Johannes Berg <johannes@sipsolutions.net> | |
d98ad83e | 5 | * Copyright 2013-2014 Intel Mobile Communications GmbH |
e9f207f0 JB |
6 | * |
7 | * GPLv2 | |
8 | * | |
9 | */ | |
10 | ||
11 | #include <linux/debugfs.h> | |
12 | #include <linux/rtnetlink.h> | |
13 | #include "ieee80211_i.h" | |
24487981 | 14 | #include "driver-ops.h" |
2c8dccc7 | 15 | #include "rate.h" |
e9f207f0 JB |
16 | #include "debugfs.h" |
17 | ||
07caf9d6 EP |
18 | #define DEBUGFS_FORMAT_BUFFER_SIZE 100 |
19 | ||
20 | int mac80211_format_buffer(char __user *userbuf, size_t count, | |
21 | loff_t *ppos, char *fmt, ...) | |
22 | { | |
23 | va_list args; | |
24 | char buf[DEBUGFS_FORMAT_BUFFER_SIZE]; | |
25 | int res; | |
26 | ||
27 | va_start(args, fmt); | |
28 | res = vscnprintf(buf, sizeof(buf), fmt, args); | |
29 | va_end(args); | |
30 | ||
31 | return simple_read_from_buffer(userbuf, count, ppos, buf, res); | |
32 | } | |
33 | ||
279daf64 | 34 | #define DEBUGFS_READONLY_FILE_FN(name, fmt, value...) \ |
e9f207f0 JB |
35 | static ssize_t name## _read(struct file *file, char __user *userbuf, \ |
36 | size_t count, loff_t *ppos) \ | |
37 | { \ | |
38 | struct ieee80211_local *local = file->private_data; \ | |
e9f207f0 | 39 | \ |
07caf9d6 EP |
40 | return mac80211_format_buffer(userbuf, count, ppos, \ |
41 | fmt "\n", ##value); \ | |
279daf64 BG |
42 | } |
43 | ||
44 | #define DEBUGFS_READONLY_FILE_OPS(name) \ | |
e9f207f0 JB |
45 | static const struct file_operations name## _ops = { \ |
46 | .read = name## _read, \ | |
234e3405 | 47 | .open = simple_open, \ |
2b18ab36 | 48 | .llseek = generic_file_llseek, \ |
e9f207f0 JB |
49 | }; |
50 | ||
279daf64 BG |
51 | #define DEBUGFS_READONLY_FILE(name, fmt, value...) \ |
52 | DEBUGFS_READONLY_FILE_FN(name, fmt, value) \ | |
53 | DEBUGFS_READONLY_FILE_OPS(name) | |
54 | ||
e9f207f0 | 55 | #define DEBUGFS_ADD(name) \ |
7bcfaf2f | 56 | debugfs_create_file(#name, 0400, phyd, local, &name## _ops); |
e9f207f0 | 57 | |
827b1fb4 | 58 | #define DEBUGFS_ADD_MODE(name, mode) \ |
7bcfaf2f | 59 | debugfs_create_file(#name, mode, phyd, local, &name## _ops); |
e9f207f0 JB |
60 | |
61 | ||
83bdf2a1 BG |
62 | DEBUGFS_READONLY_FILE(user_power, "%d", |
63 | local->user_power_level); | |
64 | DEBUGFS_READONLY_FILE(power, "%d", | |
65 | local->hw.conf.power_level); | |
07caf9d6 | 66 | DEBUGFS_READONLY_FILE(total_ps_buffered, "%d", |
e9f207f0 | 67 | local->total_ps_buffered); |
07caf9d6 | 68 | DEBUGFS_READONLY_FILE(wep_iv, "%#08x", |
e9f207f0 | 69 | local->wep_iv & 0xffffff); |
07caf9d6 | 70 | DEBUGFS_READONLY_FILE(rate_ctrl_alg, "%s", |
af65cd96 | 71 | local->rate_ctrl ? local->rate_ctrl->ops->name : "hw/driver"); |
3b5d665b | 72 | |
2ad4814f | 73 | #ifdef CONFIG_PM |
827b1fb4 JB |
74 | static ssize_t reset_write(struct file *file, const char __user *user_buf, |
75 | size_t count, loff_t *ppos) | |
76 | { | |
77 | struct ieee80211_local *local = file->private_data; | |
78 | ||
79 | rtnl_lock(); | |
eecc4800 | 80 | __ieee80211_suspend(&local->hw, NULL); |
827b1fb4 JB |
81 | __ieee80211_resume(&local->hw); |
82 | rtnl_unlock(); | |
83 | ||
84 | return count; | |
85 | } | |
86 | ||
87 | static const struct file_operations reset_ops = { | |
88 | .write = reset_write, | |
234e3405 | 89 | .open = simple_open, |
6038f373 | 90 | .llseek = noop_llseek, |
827b1fb4 | 91 | }; |
2ad4814f | 92 | #endif |
827b1fb4 | 93 | |
279daf64 BG |
94 | static ssize_t hwflags_read(struct file *file, char __user *user_buf, |
95 | size_t count, loff_t *ppos) | |
96 | { | |
97 | struct ieee80211_local *local = file->private_data; | |
98 | int mxln = 500; | |
99 | ssize_t rv; | |
100 | char *buf = kzalloc(mxln, GFP_KERNEL); | |
101 | int sf = 0; /* how many written so far */ | |
102 | ||
d15b8459 JP |
103 | if (!buf) |
104 | return 0; | |
105 | ||
f364ef99 | 106 | sf += scnprintf(buf, mxln - sf, "0x%x\n", local->hw.flags); |
279daf64 | 107 | if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) |
f364ef99 | 108 | sf += scnprintf(buf + sf, mxln - sf, "HAS_RATE_CONTROL\n"); |
279daf64 | 109 | if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS) |
f364ef99 | 110 | sf += scnprintf(buf + sf, mxln - sf, "RX_INCLUDES_FCS\n"); |
279daf64 | 111 | if (local->hw.flags & IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING) |
f364ef99 EP |
112 | sf += scnprintf(buf + sf, mxln - sf, |
113 | "HOST_BCAST_PS_BUFFERING\n"); | |
279daf64 | 114 | if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC) |
f364ef99 | 115 | sf += scnprintf(buf + sf, mxln - sf, "SIGNAL_UNSPEC\n"); |
279daf64 | 116 | if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM) |
f364ef99 | 117 | sf += scnprintf(buf + sf, mxln - sf, "SIGNAL_DBM\n"); |
c65dd147 | 118 | if (local->hw.flags & IEEE80211_HW_NEED_DTIM_BEFORE_ASSOC) |
f364ef99 EP |
119 | sf += scnprintf(buf + sf, mxln - sf, |
120 | "NEED_DTIM_BEFORE_ASSOC\n"); | |
279daf64 | 121 | if (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT) |
f364ef99 | 122 | sf += scnprintf(buf + sf, mxln - sf, "SPECTRUM_MGMT\n"); |
279daf64 | 123 | if (local->hw.flags & IEEE80211_HW_AMPDU_AGGREGATION) |
f364ef99 | 124 | sf += scnprintf(buf + sf, mxln - sf, "AMPDU_AGGREGATION\n"); |
279daf64 | 125 | if (local->hw.flags & IEEE80211_HW_SUPPORTS_PS) |
f364ef99 | 126 | sf += scnprintf(buf + sf, mxln - sf, "SUPPORTS_PS\n"); |
279daf64 | 127 | if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) |
f364ef99 | 128 | sf += scnprintf(buf + sf, mxln - sf, "PS_NULLFUNC_STACK\n"); |
279daf64 | 129 | if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS) |
f364ef99 | 130 | sf += scnprintf(buf + sf, mxln - sf, "SUPPORTS_DYNAMIC_PS\n"); |
279daf64 | 131 | if (local->hw.flags & IEEE80211_HW_MFP_CAPABLE) |
f364ef99 | 132 | sf += scnprintf(buf + sf, mxln - sf, "MFP_CAPABLE\n"); |
279daf64 | 133 | if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) |
f364ef99 EP |
134 | sf += scnprintf(buf + sf, mxln - sf, |
135 | "REPORTS_TX_ACK_STATUS\n"); | |
279daf64 | 136 | if (local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR) |
f364ef99 | 137 | sf += scnprintf(buf + sf, mxln - sf, "CONNECTION_MONITOR\n"); |
279daf64 | 138 | if (local->hw.flags & IEEE80211_HW_SUPPORTS_PER_STA_GTK) |
f364ef99 | 139 | sf += scnprintf(buf + sf, mxln - sf, "SUPPORTS_PER_STA_GTK\n"); |
279daf64 | 140 | if (local->hw.flags & IEEE80211_HW_AP_LINK_PS) |
f364ef99 | 141 | sf += scnprintf(buf + sf, mxln - sf, "AP_LINK_PS\n"); |
edf6b784 | 142 | if (local->hw.flags & IEEE80211_HW_TX_AMPDU_SETUP_IN_HW) |
f364ef99 | 143 | sf += scnprintf(buf + sf, mxln - sf, "TX_AMPDU_SETUP_IN_HW\n"); |
279daf64 BG |
144 | |
145 | rv = simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf)); | |
146 | kfree(buf); | |
147 | return rv; | |
148 | } | |
199d69f2 | 149 | |
db2e6bd4 JB |
150 | static ssize_t queues_read(struct file *file, char __user *user_buf, |
151 | size_t count, loff_t *ppos) | |
152 | { | |
153 | struct ieee80211_local *local = file->private_data; | |
154 | unsigned long flags; | |
155 | char buf[IEEE80211_MAX_QUEUES * 20]; | |
156 | int q, res = 0; | |
157 | ||
158 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); | |
159 | for (q = 0; q < local->hw.queues; q++) | |
160 | res += sprintf(buf + res, "%02d: %#.8lx/%d\n", q, | |
161 | local->queue_stop_reasons[q], | |
3b8d81e0 | 162 | skb_queue_len(&local->pending[q])); |
db2e6bd4 JB |
163 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); |
164 | ||
165 | return simple_read_from_buffer(user_buf, count, ppos, buf, res); | |
166 | } | |
167 | ||
279daf64 | 168 | DEBUGFS_READONLY_FILE_OPS(hwflags); |
279daf64 | 169 | DEBUGFS_READONLY_FILE_OPS(queues); |
db2e6bd4 | 170 | |
e9f207f0 JB |
171 | /* statistics stuff */ |
172 | ||
e9f207f0 JB |
173 | static ssize_t format_devstat_counter(struct ieee80211_local *local, |
174 | char __user *userbuf, | |
175 | size_t count, loff_t *ppos, | |
176 | int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf, | |
177 | int buflen)) | |
178 | { | |
179 | struct ieee80211_low_level_stats stats; | |
180 | char buf[20]; | |
181 | int res; | |
182 | ||
75636525 | 183 | rtnl_lock(); |
24487981 | 184 | res = drv_get_stats(local, &stats); |
e9f207f0 | 185 | rtnl_unlock(); |
24487981 JB |
186 | if (res) |
187 | return res; | |
188 | res = printvalue(&stats, buf, sizeof(buf)); | |
e9f207f0 JB |
189 | return simple_read_from_buffer(userbuf, count, ppos, buf, res); |
190 | } | |
191 | ||
192 | #define DEBUGFS_DEVSTATS_FILE(name) \ | |
193 | static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\ | |
194 | char *buf, int buflen) \ | |
195 | { \ | |
196 | return scnprintf(buf, buflen, "%u\n", stats->name); \ | |
197 | } \ | |
198 | static ssize_t stats_ ##name## _read(struct file *file, \ | |
199 | char __user *userbuf, \ | |
200 | size_t count, loff_t *ppos) \ | |
201 | { \ | |
202 | return format_devstat_counter(file->private_data, \ | |
203 | userbuf, \ | |
204 | count, \ | |
205 | ppos, \ | |
206 | print_devstats_##name); \ | |
207 | } \ | |
208 | \ | |
209 | static const struct file_operations stats_ ##name## _ops = { \ | |
210 | .read = stats_ ##name## _read, \ | |
234e3405 | 211 | .open = simple_open, \ |
2b18ab36 | 212 | .llseek = generic_file_llseek, \ |
e9f207f0 JB |
213 | }; |
214 | ||
f1160434 JB |
215 | #define DEBUGFS_STATS_ADD(name) \ |
216 | debugfs_create_u32(#name, 0400, statsd, &local->name); | |
2826bcd8 | 217 | #define DEBUGFS_DEVSTATS_ADD(name) \ |
7bcfaf2f | 218 | debugfs_create_file(#name, 0400, statsd, local, &stats_ ##name## _ops); |
e9f207f0 | 219 | |
e9f207f0 JB |
220 | DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount); |
221 | DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount); | |
222 | DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount); | |
223 | DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount); | |
224 | ||
e9f207f0 JB |
225 | void debugfs_hw_add(struct ieee80211_local *local) |
226 | { | |
227 | struct dentry *phyd = local->hw.wiphy->debugfsdir; | |
228 | struct dentry *statsd; | |
229 | ||
230 | if (!phyd) | |
231 | return; | |
232 | ||
e9f207f0 JB |
233 | local->debugfs.keys = debugfs_create_dir("keys", phyd); |
234 | ||
e9f207f0 | 235 | DEBUGFS_ADD(total_ps_buffered); |
e9f207f0 | 236 | DEBUGFS_ADD(wep_iv); |
db2e6bd4 | 237 | DEBUGFS_ADD(queues); |
2ad4814f | 238 | #ifdef CONFIG_PM |
827b1fb4 | 239 | DEBUGFS_ADD_MODE(reset, 0200); |
2ad4814f | 240 | #endif |
279daf64 | 241 | DEBUGFS_ADD(hwflags); |
83bdf2a1 BG |
242 | DEBUGFS_ADD(user_power); |
243 | DEBUGFS_ADD(power); | |
e9f207f0 JB |
244 | |
245 | statsd = debugfs_create_dir("statistics", phyd); | |
e9f207f0 JB |
246 | |
247 | /* if the dir failed, don't put all the other things into the root! */ | |
248 | if (!statsd) | |
249 | return; | |
250 | ||
c206ca67 | 251 | #ifdef CONFIG_MAC80211_DEBUG_COUNTERS |
f1160434 JB |
252 | DEBUGFS_STATS_ADD(dot11TransmittedFragmentCount); |
253 | DEBUGFS_STATS_ADD(dot11MulticastTransmittedFrameCount); | |
254 | DEBUGFS_STATS_ADD(dot11FailedCount); | |
255 | DEBUGFS_STATS_ADD(dot11RetryCount); | |
256 | DEBUGFS_STATS_ADD(dot11MultipleRetryCount); | |
257 | DEBUGFS_STATS_ADD(dot11FrameDuplicateCount); | |
258 | DEBUGFS_STATS_ADD(dot11ReceivedFragmentCount); | |
259 | DEBUGFS_STATS_ADD(dot11MulticastReceivedFrameCount); | |
260 | DEBUGFS_STATS_ADD(dot11TransmittedFrameCount); | |
f1160434 JB |
261 | DEBUGFS_STATS_ADD(tx_handlers_drop); |
262 | DEBUGFS_STATS_ADD(tx_handlers_queued); | |
263 | DEBUGFS_STATS_ADD(tx_handlers_drop_wep); | |
264 | DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc); | |
265 | DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port); | |
266 | DEBUGFS_STATS_ADD(rx_handlers_drop); | |
267 | DEBUGFS_STATS_ADD(rx_handlers_queued); | |
268 | DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc); | |
269 | DEBUGFS_STATS_ADD(rx_handlers_drop_defrag); | |
270 | DEBUGFS_STATS_ADD(rx_handlers_drop_short); | |
271 | DEBUGFS_STATS_ADD(tx_expand_skb_head); | |
272 | DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned); | |
273 | DEBUGFS_STATS_ADD(rx_expand_skb_head_defrag); | |
274 | DEBUGFS_STATS_ADD(rx_handlers_fragments); | |
275 | DEBUGFS_STATS_ADD(tx_status_drop); | |
e9f207f0 | 276 | #endif |
2826bcd8 FF |
277 | DEBUGFS_DEVSTATS_ADD(dot11ACKFailureCount); |
278 | DEBUGFS_DEVSTATS_ADD(dot11RTSFailureCount); | |
279 | DEBUGFS_DEVSTATS_ADD(dot11FCSErrorCount); | |
280 | DEBUGFS_DEVSTATS_ADD(dot11RTSSuccessCount); | |
e9f207f0 | 281 | } |