2 * mac80211 debugfs for wireless PHYs
4 * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
5 * Copyright 2013-2014 Intel Mobile Communications GmbH
11 #include <linux/debugfs.h>
12 #include <linux/rtnetlink.h>
13 #include "ieee80211_i.h"
14 #include "driver-ops.h"
18 #define DEBUGFS_FORMAT_BUFFER_SIZE 100
20 int mac80211_format_buffer(char __user
*userbuf
, size_t count
,
21 loff_t
*ppos
, char *fmt
, ...)
24 char buf
[DEBUGFS_FORMAT_BUFFER_SIZE
];
28 res
= vscnprintf(buf
, sizeof(buf
), fmt
, args
);
31 return simple_read_from_buffer(userbuf
, count
, ppos
, buf
, res
);
34 #define DEBUGFS_READONLY_FILE_FN(name, fmt, value...) \
35 static ssize_t name## _read(struct file *file, char __user *userbuf, \
36 size_t count, loff_t *ppos) \
38 struct ieee80211_local *local = file->private_data; \
40 return mac80211_format_buffer(userbuf, count, ppos, \
44 #define DEBUGFS_READONLY_FILE_OPS(name) \
45 static const struct file_operations name## _ops = { \
46 .read = name## _read, \
47 .open = simple_open, \
48 .llseek = generic_file_llseek, \
51 #define DEBUGFS_READONLY_FILE(name, fmt, value...) \
52 DEBUGFS_READONLY_FILE_FN(name, fmt, value) \
53 DEBUGFS_READONLY_FILE_OPS(name)
55 #define DEBUGFS_ADD(name) \
56 debugfs_create_file(#name, 0400, phyd, local, &name## _ops);
58 #define DEBUGFS_ADD_MODE(name, mode) \
59 debugfs_create_file(#name, mode, phyd, local, &name## _ops);
62 DEBUGFS_READONLY_FILE(user_power
, "%d",
63 local
->user_power_level
);
64 DEBUGFS_READONLY_FILE(power
, "%d",
65 local
->hw
.conf
.power_level
);
66 DEBUGFS_READONLY_FILE(total_ps_buffered
, "%d",
67 local
->total_ps_buffered
);
68 DEBUGFS_READONLY_FILE(wep_iv
, "%#08x",
69 local
->wep_iv
& 0xffffff);
70 DEBUGFS_READONLY_FILE(rate_ctrl_alg
, "%s",
71 local
->rate_ctrl
? local
->rate_ctrl
->ops
->name
: "hw/driver");
74 static ssize_t
reset_write(struct file
*file
, const char __user
*user_buf
,
75 size_t count
, loff_t
*ppos
)
77 struct ieee80211_local
*local
= file
->private_data
;
80 __ieee80211_suspend(&local
->hw
, NULL
);
81 __ieee80211_resume(&local
->hw
);
87 static const struct file_operations reset_ops
= {
90 .llseek
= noop_llseek
,
94 static const char *hw_flag_names
[NUM_IEEE80211_HW_FLAGS
+ 1] = {
95 #define FLAG(F) [IEEE80211_HW_##F] = #F
96 FLAG(HAS_RATE_CONTROL
),
97 FLAG(RX_INCLUDES_FCS
),
98 FLAG(HOST_BROADCAST_PS_BUFFERING
),
101 FLAG(NEED_DTIM_BEFORE_ASSOC
),
103 FLAG(AMPDU_AGGREGATION
),
105 FLAG(PS_NULLFUNC_STACK
),
106 FLAG(SUPPORTS_DYNAMIC_PS
),
108 FLAG(WANT_MONITOR_VIF
),
110 FLAG(SW_CRYPTO_CONTROL
),
111 FLAG(SUPPORT_FAST_XMIT
),
112 FLAG(REPORTS_TX_ACK_STATUS
),
113 FLAG(CONNECTION_MONITOR
),
115 FLAG(SUPPORTS_PER_STA_GTK
),
117 FLAG(TX_AMPDU_SETUP_IN_HW
),
118 FLAG(SUPPORTS_RC_TABLE
),
119 FLAG(P2P_DEV_ADDR_FOR_INTF
),
120 FLAG(TIMING_BEACON_ONLY
),
121 FLAG(SUPPORTS_HT_CCK_RATES
),
122 FLAG(CHANCTX_STA_CSA
),
123 FLAG(SUPPORTS_CLONED_SKBS
),
124 FLAG(SINGLE_SCAN_ON_ALL_BANDS
),
126 FLAG(SUPPORTS_AMSDU_IN_AMPDU
),
127 FLAG(BEACON_TX_STATUS
),
129 /* keep last for the build bug below */
134 static ssize_t
hwflags_read(struct file
*file
, char __user
*user_buf
,
135 size_t count
, loff_t
*ppos
)
137 struct ieee80211_local
*local
= file
->private_data
;
138 size_t bufsz
= 30 * NUM_IEEE80211_HW_FLAGS
;
139 char *buf
= kzalloc(bufsz
, GFP_KERNEL
);
140 char *pos
= buf
, *end
= buf
+ bufsz
- 1;
147 /* fail compilation if somebody adds or removes
148 * a flag without updating the name array above
150 BUILD_BUG_ON(hw_flag_names
[NUM_IEEE80211_HW_FLAGS
] != (void *)0x1);
152 for (i
= 0; i
< NUM_IEEE80211_HW_FLAGS
; i
++) {
153 if (test_bit(i
, local
->hw
.flags
))
154 pos
+= scnprintf(pos
, end
- pos
, "%s\n",
158 rv
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, strlen(buf
));
163 static ssize_t
queues_read(struct file
*file
, char __user
*user_buf
,
164 size_t count
, loff_t
*ppos
)
166 struct ieee80211_local
*local
= file
->private_data
;
168 char buf
[IEEE80211_MAX_QUEUES
* 20];
171 spin_lock_irqsave(&local
->queue_stop_reason_lock
, flags
);
172 for (q
= 0; q
< local
->hw
.queues
; q
++)
173 res
+= sprintf(buf
+ res
, "%02d: %#.8lx/%d\n", q
,
174 local
->queue_stop_reasons
[q
],
175 skb_queue_len(&local
->pending
[q
]));
176 spin_unlock_irqrestore(&local
->queue_stop_reason_lock
, flags
);
178 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, res
);
181 DEBUGFS_READONLY_FILE_OPS(hwflags
);
182 DEBUGFS_READONLY_FILE_OPS(queues
);
184 /* statistics stuff */
186 static ssize_t
format_devstat_counter(struct ieee80211_local
*local
,
187 char __user
*userbuf
,
188 size_t count
, loff_t
*ppos
,
189 int (*printvalue
)(struct ieee80211_low_level_stats
*stats
, char *buf
,
192 struct ieee80211_low_level_stats stats
;
197 res
= drv_get_stats(local
, &stats
);
201 res
= printvalue(&stats
, buf
, sizeof(buf
));
202 return simple_read_from_buffer(userbuf
, count
, ppos
, buf
, res
);
205 #define DEBUGFS_DEVSTATS_FILE(name) \
206 static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\
207 char *buf, int buflen) \
209 return scnprintf(buf, buflen, "%u\n", stats->name); \
211 static ssize_t stats_ ##name## _read(struct file *file, \
212 char __user *userbuf, \
213 size_t count, loff_t *ppos) \
215 return format_devstat_counter(file->private_data, \
219 print_devstats_##name); \
222 static const struct file_operations stats_ ##name## _ops = { \
223 .read = stats_ ##name## _read, \
224 .open = simple_open, \
225 .llseek = generic_file_llseek, \
228 #define DEBUGFS_STATS_ADD(name) \
229 debugfs_create_u32(#name, 0400, statsd, &local->name);
230 #define DEBUGFS_DEVSTATS_ADD(name) \
231 debugfs_create_file(#name, 0400, statsd, local, &stats_ ##name## _ops);
233 DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount
);
234 DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount
);
235 DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount
);
236 DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount
);
238 void debugfs_hw_add(struct ieee80211_local
*local
)
240 struct dentry
*phyd
= local
->hw
.wiphy
->debugfsdir
;
241 struct dentry
*statsd
;
246 local
->debugfs
.keys
= debugfs_create_dir("keys", phyd
);
248 DEBUGFS_ADD(total_ps_buffered
);
252 DEBUGFS_ADD_MODE(reset
, 0200);
254 DEBUGFS_ADD(hwflags
);
255 DEBUGFS_ADD(user_power
);
258 statsd
= debugfs_create_dir("statistics", phyd
);
260 /* if the dir failed, don't put all the other things into the root! */
264 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
265 DEBUGFS_STATS_ADD(dot11TransmittedFragmentCount
);
266 DEBUGFS_STATS_ADD(dot11MulticastTransmittedFrameCount
);
267 DEBUGFS_STATS_ADD(dot11FailedCount
);
268 DEBUGFS_STATS_ADD(dot11RetryCount
);
269 DEBUGFS_STATS_ADD(dot11MultipleRetryCount
);
270 DEBUGFS_STATS_ADD(dot11FrameDuplicateCount
);
271 DEBUGFS_STATS_ADD(dot11ReceivedFragmentCount
);
272 DEBUGFS_STATS_ADD(dot11MulticastReceivedFrameCount
);
273 DEBUGFS_STATS_ADD(dot11TransmittedFrameCount
);
274 DEBUGFS_STATS_ADD(tx_handlers_drop
);
275 DEBUGFS_STATS_ADD(tx_handlers_queued
);
276 DEBUGFS_STATS_ADD(tx_handlers_drop_wep
);
277 DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc
);
278 DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port
);
279 DEBUGFS_STATS_ADD(rx_handlers_drop
);
280 DEBUGFS_STATS_ADD(rx_handlers_queued
);
281 DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc
);
282 DEBUGFS_STATS_ADD(rx_handlers_drop_defrag
);
283 DEBUGFS_STATS_ADD(tx_expand_skb_head
);
284 DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned
);
285 DEBUGFS_STATS_ADD(rx_expand_skb_head_defrag
);
286 DEBUGFS_STATS_ADD(rx_handlers_fragments
);
287 DEBUGFS_STATS_ADD(tx_status_drop
);
289 DEBUGFS_DEVSTATS_ADD(dot11ACKFailureCount
);
290 DEBUGFS_DEVSTATS_ADD(dot11RTSFailureCount
);
291 DEBUGFS_DEVSTATS_ADD(dot11FCSErrorCount
);
292 DEBUGFS_DEVSTATS_ADD(dot11RTSSuccessCount
);