scripts/coccinelle/api/simple_open.cocci: semantic patch for simple_open()
[deliverable/linux.git] / net / mac80211 / debugfs.c
CommitLineData
7bcfaf2f 1
e9f207f0
JB
2/*
3 * mac80211 debugfs for wireless PHYs
4 *
5 * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
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
18int mac80211_open_file_generic(struct inode *inode, struct file *file)
19{
20 file->private_data = inode->i_private;
21 return 0;
22}
23
07caf9d6
EP
24#define DEBUGFS_FORMAT_BUFFER_SIZE 100
25
26int mac80211_format_buffer(char __user *userbuf, size_t count,
27 loff_t *ppos, char *fmt, ...)
28{
29 va_list args;
30 char buf[DEBUGFS_FORMAT_BUFFER_SIZE];
31 int res;
32
33 va_start(args, fmt);
34 res = vscnprintf(buf, sizeof(buf), fmt, args);
35 va_end(args);
36
37 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
38}
39
279daf64 40#define DEBUGFS_READONLY_FILE_FN(name, fmt, value...) \
e9f207f0
JB
41static ssize_t name## _read(struct file *file, char __user *userbuf, \
42 size_t count, loff_t *ppos) \
43{ \
44 struct ieee80211_local *local = file->private_data; \
e9f207f0 45 \
07caf9d6
EP
46 return mac80211_format_buffer(userbuf, count, ppos, \
47 fmt "\n", ##value); \
279daf64
BG
48}
49
50#define DEBUGFS_READONLY_FILE_OPS(name) \
e9f207f0
JB
51static const struct file_operations name## _ops = { \
52 .read = name## _read, \
53 .open = mac80211_open_file_generic, \
2b18ab36 54 .llseek = generic_file_llseek, \
e9f207f0
JB
55};
56
279daf64
BG
57#define DEBUGFS_READONLY_FILE(name, fmt, value...) \
58 DEBUGFS_READONLY_FILE_FN(name, fmt, value) \
59 DEBUGFS_READONLY_FILE_OPS(name)
60
e9f207f0 61#define DEBUGFS_ADD(name) \
7bcfaf2f 62 debugfs_create_file(#name, 0400, phyd, local, &name## _ops);
e9f207f0 63
827b1fb4 64#define DEBUGFS_ADD_MODE(name, mode) \
7bcfaf2f 65 debugfs_create_file(#name, mode, phyd, local, &name## _ops);
e9f207f0
JB
66
67
83bdf2a1
BG
68DEBUGFS_READONLY_FILE(user_power, "%d",
69 local->user_power_level);
70DEBUGFS_READONLY_FILE(power, "%d",
71 local->hw.conf.power_level);
07caf9d6 72DEBUGFS_READONLY_FILE(frequency, "%d",
8318d78a 73 local->hw.conf.channel->center_freq);
07caf9d6 74DEBUGFS_READONLY_FILE(total_ps_buffered, "%d",
e9f207f0 75 local->total_ps_buffered);
07caf9d6 76DEBUGFS_READONLY_FILE(wep_iv, "%#08x",
e9f207f0 77 local->wep_iv & 0xffffff);
07caf9d6 78DEBUGFS_READONLY_FILE(rate_ctrl_alg, "%s",
af65cd96 79 local->rate_ctrl ? local->rate_ctrl->ops->name : "hw/driver");
3b5d665b 80
827b1fb4
JB
81static ssize_t reset_write(struct file *file, const char __user *user_buf,
82 size_t count, loff_t *ppos)
83{
84 struct ieee80211_local *local = file->private_data;
85
86 rtnl_lock();
eecc4800 87 __ieee80211_suspend(&local->hw, NULL);
827b1fb4
JB
88 __ieee80211_resume(&local->hw);
89 rtnl_unlock();
90
91 return count;
92}
93
94static const struct file_operations reset_ops = {
95 .write = reset_write,
96 .open = mac80211_open_file_generic,
6038f373 97 .llseek = noop_llseek,
827b1fb4
JB
98};
99
199d69f2
BP
100static ssize_t channel_type_read(struct file *file, char __user *user_buf,
101 size_t count, loff_t *ppos)
102{
103 struct ieee80211_local *local = file->private_data;
104 const char *buf;
105
106 switch (local->hw.conf.channel_type) {
107 case NL80211_CHAN_NO_HT:
108 buf = "no ht\n";
109 break;
110 case NL80211_CHAN_HT20:
111 buf = "ht20\n";
112 break;
113 case NL80211_CHAN_HT40MINUS:
114 buf = "ht40-\n";
115 break;
116 case NL80211_CHAN_HT40PLUS:
117 buf = "ht40+\n";
118 break;
119 default:
120 buf = "???";
121 break;
122 }
123
124 return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
125}
126
279daf64
BG
127static ssize_t hwflags_read(struct file *file, char __user *user_buf,
128 size_t count, loff_t *ppos)
129{
130 struct ieee80211_local *local = file->private_data;
131 int mxln = 500;
132 ssize_t rv;
133 char *buf = kzalloc(mxln, GFP_KERNEL);
134 int sf = 0; /* how many written so far */
135
d15b8459
JP
136 if (!buf)
137 return 0;
138
279daf64
BG
139 sf += snprintf(buf, mxln - sf, "0x%x\n", local->hw.flags);
140 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL)
141 sf += snprintf(buf + sf, mxln - sf, "HAS_RATE_CONTROL\n");
142 if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)
143 sf += snprintf(buf + sf, mxln - sf, "RX_INCLUDES_FCS\n");
144 if (local->hw.flags & IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING)
145 sf += snprintf(buf + sf, mxln - sf,
146 "HOST_BCAST_PS_BUFFERING\n");
147 if (local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE)
148 sf += snprintf(buf + sf, mxln - sf,
149 "2GHZ_SHORT_SLOT_INCAPABLE\n");
150 if (local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE)
151 sf += snprintf(buf + sf, mxln - sf,
152 "2GHZ_SHORT_PREAMBLE_INCAPABLE\n");
153 if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)
154 sf += snprintf(buf + sf, mxln - sf, "SIGNAL_UNSPEC\n");
155 if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
156 sf += snprintf(buf + sf, mxln - sf, "SIGNAL_DBM\n");
157 if (local->hw.flags & IEEE80211_HW_NEED_DTIM_PERIOD)
158 sf += snprintf(buf + sf, mxln - sf, "NEED_DTIM_PERIOD\n");
159 if (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT)
160 sf += snprintf(buf + sf, mxln - sf, "SPECTRUM_MGMT\n");
161 if (local->hw.flags & IEEE80211_HW_AMPDU_AGGREGATION)
162 sf += snprintf(buf + sf, mxln - sf, "AMPDU_AGGREGATION\n");
163 if (local->hw.flags & IEEE80211_HW_SUPPORTS_PS)
164 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_PS\n");
165 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
166 sf += snprintf(buf + sf, mxln - sf, "PS_NULLFUNC_STACK\n");
167 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
168 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_DYNAMIC_PS\n");
169 if (local->hw.flags & IEEE80211_HW_MFP_CAPABLE)
170 sf += snprintf(buf + sf, mxln - sf, "MFP_CAPABLE\n");
279daf64
BG
171 if (local->hw.flags & IEEE80211_HW_SUPPORTS_STATIC_SMPS)
172 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_STATIC_SMPS\n");
173 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS)
174 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_DYNAMIC_SMPS\n");
175 if (local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD)
176 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_UAPSD\n");
177 if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
178 sf += snprintf(buf + sf, mxln - sf, "REPORTS_TX_ACK_STATUS\n");
179 if (local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
180 sf += snprintf(buf + sf, mxln - sf, "CONNECTION_MONITOR\n");
279daf64
BG
181 if (local->hw.flags & IEEE80211_HW_SUPPORTS_PER_STA_GTK)
182 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_PER_STA_GTK\n");
183 if (local->hw.flags & IEEE80211_HW_AP_LINK_PS)
184 sf += snprintf(buf + sf, mxln - sf, "AP_LINK_PS\n");
edf6b784
AN
185 if (local->hw.flags & IEEE80211_HW_TX_AMPDU_SETUP_IN_HW)
186 sf += snprintf(buf + sf, mxln - sf, "TX_AMPDU_SETUP_IN_HW\n");
885bd8ec
EP
187 if (local->hw.flags & IEEE80211_HW_SCAN_WHILE_IDLE)
188 sf += snprintf(buf + sf, mxln - sf, "SCAN_WHILE_IDLE\n");
279daf64
BG
189
190 rv = simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
191 kfree(buf);
192 return rv;
193}
199d69f2 194
db2e6bd4
JB
195static ssize_t queues_read(struct file *file, char __user *user_buf,
196 size_t count, loff_t *ppos)
197{
198 struct ieee80211_local *local = file->private_data;
199 unsigned long flags;
200 char buf[IEEE80211_MAX_QUEUES * 20];
201 int q, res = 0;
202
203 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
204 for (q = 0; q < local->hw.queues; q++)
205 res += sprintf(buf + res, "%02d: %#.8lx/%d\n", q,
206 local->queue_stop_reasons[q],
3b8d81e0 207 skb_queue_len(&local->pending[q]));
db2e6bd4
JB
208 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
209
210 return simple_read_from_buffer(user_buf, count, ppos, buf, res);
211}
212
279daf64
BG
213DEBUGFS_READONLY_FILE_OPS(hwflags);
214DEBUGFS_READONLY_FILE_OPS(channel_type);
215DEBUGFS_READONLY_FILE_OPS(queues);
db2e6bd4 216
e9f207f0
JB
217/* statistics stuff */
218
e9f207f0
JB
219static ssize_t format_devstat_counter(struct ieee80211_local *local,
220 char __user *userbuf,
221 size_t count, loff_t *ppos,
222 int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf,
223 int buflen))
224{
225 struct ieee80211_low_level_stats stats;
226 char buf[20];
227 int res;
228
75636525 229 rtnl_lock();
24487981 230 res = drv_get_stats(local, &stats);
e9f207f0 231 rtnl_unlock();
24487981
JB
232 if (res)
233 return res;
234 res = printvalue(&stats, buf, sizeof(buf));
e9f207f0
JB
235 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
236}
237
238#define DEBUGFS_DEVSTATS_FILE(name) \
239static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\
240 char *buf, int buflen) \
241{ \
242 return scnprintf(buf, buflen, "%u\n", stats->name); \
243} \
244static ssize_t stats_ ##name## _read(struct file *file, \
245 char __user *userbuf, \
246 size_t count, loff_t *ppos) \
247{ \
248 return format_devstat_counter(file->private_data, \
249 userbuf, \
250 count, \
251 ppos, \
252 print_devstats_##name); \
253} \
254 \
255static const struct file_operations stats_ ##name## _ops = { \
256 .read = stats_ ##name## _read, \
257 .open = mac80211_open_file_generic, \
2b18ab36 258 .llseek = generic_file_llseek, \
e9f207f0
JB
259};
260
2826bcd8
FF
261#define DEBUGFS_STATS_ADD(name, field) \
262 debugfs_create_u32(#name, 0400, statsd, (u32 *) &field);
263#define DEBUGFS_DEVSTATS_ADD(name) \
7bcfaf2f 264 debugfs_create_file(#name, 0400, statsd, local, &stats_ ##name## _ops);
e9f207f0 265
e9f207f0
JB
266DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount);
267DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount);
268DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount);
269DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount);
270
e9f207f0
JB
271void debugfs_hw_add(struct ieee80211_local *local)
272{
273 struct dentry *phyd = local->hw.wiphy->debugfsdir;
274 struct dentry *statsd;
275
276 if (!phyd)
277 return;
278
e9f207f0
JB
279 local->debugfs.keys = debugfs_create_dir("keys", phyd);
280
e9f207f0 281 DEBUGFS_ADD(frequency);
e9f207f0 282 DEBUGFS_ADD(total_ps_buffered);
e9f207f0 283 DEBUGFS_ADD(wep_iv);
db2e6bd4 284 DEBUGFS_ADD(queues);
827b1fb4 285 DEBUGFS_ADD_MODE(reset, 0200);
199d69f2 286 DEBUGFS_ADD(channel_type);
279daf64 287 DEBUGFS_ADD(hwflags);
83bdf2a1
BG
288 DEBUGFS_ADD(user_power);
289 DEBUGFS_ADD(power);
e9f207f0
JB
290
291 statsd = debugfs_create_dir("statistics", phyd);
e9f207f0
JB
292
293 /* if the dir failed, don't put all the other things into the root! */
294 if (!statsd)
295 return;
296
2826bcd8
FF
297 DEBUGFS_STATS_ADD(transmitted_fragment_count,
298 local->dot11TransmittedFragmentCount);
299 DEBUGFS_STATS_ADD(multicast_transmitted_frame_count,
300 local->dot11MulticastTransmittedFrameCount);
301 DEBUGFS_STATS_ADD(failed_count, local->dot11FailedCount);
302 DEBUGFS_STATS_ADD(retry_count, local->dot11RetryCount);
303 DEBUGFS_STATS_ADD(multiple_retry_count,
304 local->dot11MultipleRetryCount);
305 DEBUGFS_STATS_ADD(frame_duplicate_count,
306 local->dot11FrameDuplicateCount);
307 DEBUGFS_STATS_ADD(received_fragment_count,
308 local->dot11ReceivedFragmentCount);
309 DEBUGFS_STATS_ADD(multicast_received_frame_count,
310 local->dot11MulticastReceivedFrameCount);
311 DEBUGFS_STATS_ADD(transmitted_frame_count,
312 local->dot11TransmittedFrameCount);
e9f207f0 313#ifdef CONFIG_MAC80211_DEBUG_COUNTERS
2826bcd8
FF
314 DEBUGFS_STATS_ADD(tx_handlers_drop, local->tx_handlers_drop);
315 DEBUGFS_STATS_ADD(tx_handlers_queued, local->tx_handlers_queued);
316 DEBUGFS_STATS_ADD(tx_handlers_drop_unencrypted,
317 local->tx_handlers_drop_unencrypted);
318 DEBUGFS_STATS_ADD(tx_handlers_drop_fragment,
319 local->tx_handlers_drop_fragment);
320 DEBUGFS_STATS_ADD(tx_handlers_drop_wep,
321 local->tx_handlers_drop_wep);
322 DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc,
323 local->tx_handlers_drop_not_assoc);
324 DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port,
325 local->tx_handlers_drop_unauth_port);
326 DEBUGFS_STATS_ADD(rx_handlers_drop, local->rx_handlers_drop);
327 DEBUGFS_STATS_ADD(rx_handlers_queued, local->rx_handlers_queued);
328 DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc,
329 local->rx_handlers_drop_nullfunc);
330 DEBUGFS_STATS_ADD(rx_handlers_drop_defrag,
331 local->rx_handlers_drop_defrag);
332 DEBUGFS_STATS_ADD(rx_handlers_drop_short,
333 local->rx_handlers_drop_short);
334 DEBUGFS_STATS_ADD(rx_handlers_drop_passive_scan,
335 local->rx_handlers_drop_passive_scan);
336 DEBUGFS_STATS_ADD(tx_expand_skb_head,
337 local->tx_expand_skb_head);
338 DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned,
339 local->tx_expand_skb_head_cloned);
340 DEBUGFS_STATS_ADD(rx_expand_skb_head,
341 local->rx_expand_skb_head);
342 DEBUGFS_STATS_ADD(rx_expand_skb_head2,
343 local->rx_expand_skb_head2);
344 DEBUGFS_STATS_ADD(rx_handlers_fragments,
345 local->rx_handlers_fragments);
346 DEBUGFS_STATS_ADD(tx_status_drop,
347 local->tx_status_drop);
e9f207f0 348#endif
2826bcd8
FF
349 DEBUGFS_DEVSTATS_ADD(dot11ACKFailureCount);
350 DEBUGFS_DEVSTATS_ADD(dot11RTSFailureCount);
351 DEBUGFS_DEVSTATS_ADD(dot11FCSErrorCount);
352 DEBUGFS_DEVSTATS_ADD(dot11RTSSuccessCount);
e9f207f0 353}
This page took 0.535563 seconds and 5 git commands to generate.