]>
Commit | Line | Data |
---|---|---|
95ea3627 | 1 | /* |
9c9a0d14 | 2 | Copyright (C) 2004 - 2009 Ivo van Doorn <IvDoorn@gmail.com> |
95ea3627 ID |
3 | <http://rt2x00.serialmonkey.com> |
4 | ||
5 | This program is free software; you can redistribute it and/or modify | |
6 | it under the terms of the GNU General Public License as published by | |
7 | the Free Software Foundation; either version 2 of the License, or | |
8 | (at your option) any later version. | |
9 | ||
10 | This program is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | GNU General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU General Public License | |
16 | along with this program; if not, write to the | |
17 | Free Software Foundation, Inc., | |
18 | 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
19 | */ | |
20 | ||
21 | /* | |
22 | Module: rt2x00lib | |
23 | Abstract: rt2x00 debugfs specific routines. | |
24 | */ | |
25 | ||
95ea3627 ID |
26 | #include <linux/debugfs.h> |
27 | #include <linux/kernel.h> | |
28 | #include <linux/module.h> | |
4d8dd66c | 29 | #include <linux/poll.h> |
d43c36dc | 30 | #include <linux/sched.h> |
5a0e3ad6 | 31 | #include <linux/slab.h> |
95ea3627 ID |
32 | #include <linux/uaccess.h> |
33 | ||
34 | #include "rt2x00.h" | |
35 | #include "rt2x00lib.h" | |
4d8dd66c | 36 | #include "rt2x00dump.h" |
95ea3627 | 37 | |
68598d29 | 38 | #define MAX_LINE_LENGTH 64 |
95ea3627 | 39 | |
2bb057d0 ID |
40 | struct rt2x00debug_crypto { |
41 | unsigned long success; | |
42 | unsigned long icv_error; | |
43 | unsigned long mic_error; | |
44 | unsigned long key_error; | |
45 | }; | |
46 | ||
95ea3627 ID |
47 | struct rt2x00debug_intf { |
48 | /* | |
49 | * Pointer to driver structure where | |
50 | * this debugfs entry belongs to. | |
51 | */ | |
52 | struct rt2x00_dev *rt2x00dev; | |
53 | ||
54 | /* | |
55 | * Reference to the rt2x00debug structure | |
56 | * which can be used to communicate with | |
57 | * the registers. | |
58 | */ | |
59 | const struct rt2x00debug *debug; | |
60 | ||
61 | /* | |
62 | * Debugfs entries for: | |
63 | * - driver folder | |
91921a4e ID |
64 | * - driver file |
65 | * - chipset file | |
66 | * - device flags file | |
67 | * - register folder | |
68 | * - csr offset/value files | |
69 | * - eeprom offset/value files | |
70 | * - bbp offset/value files | |
71 | * - rf offset/value files | |
68598d29 | 72 | * - queue folder |
4d8dd66c | 73 | * - frame dump file |
68598d29 | 74 | * - queue stats file |
2bb057d0 | 75 | * - crypto stats file |
95ea3627 ID |
76 | */ |
77 | struct dentry *driver_folder; | |
78 | struct dentry *driver_entry; | |
79 | struct dentry *chipset_entry; | |
643b2521 | 80 | struct dentry *dev_flags; |
91921a4e | 81 | struct dentry *register_folder; |
95ea3627 ID |
82 | struct dentry *csr_off_entry; |
83 | struct dentry *csr_val_entry; | |
84 | struct dentry *eeprom_off_entry; | |
85 | struct dentry *eeprom_val_entry; | |
86 | struct dentry *bbp_off_entry; | |
87 | struct dentry *bbp_val_entry; | |
88 | struct dentry *rf_off_entry; | |
89 | struct dentry *rf_val_entry; | |
68598d29 ID |
90 | struct dentry *queue_folder; |
91 | struct dentry *queue_frame_dump_entry; | |
92 | struct dentry *queue_stats_entry; | |
2bb057d0 | 93 | struct dentry *crypto_stats_entry; |
4d8dd66c ID |
94 | |
95 | /* | |
96 | * The frame dump file only allows a single reader, | |
97 | * so we need to store the current state here. | |
98 | */ | |
99 | unsigned long frame_dump_flags; | |
100 | #define FRAME_DUMP_FILE_OPEN 1 | |
101 | ||
102 | /* | |
103 | * We queue each frame before dumping it to the user, | |
104 | * per read command we will pass a single skb structure | |
105 | * so we should be prepared to queue multiple sk buffers | |
106 | * before sending it to userspace. | |
107 | */ | |
108 | struct sk_buff_head frame_dump_skbqueue; | |
109 | wait_queue_head_t frame_dump_waitqueue; | |
95ea3627 | 110 | |
2bb057d0 ID |
111 | /* |
112 | * HW crypto statistics. | |
3ad2f3fb | 113 | * All statistics are stored separately per cipher type. |
2bb057d0 ID |
114 | */ |
115 | struct rt2x00debug_crypto crypto_stats[CIPHER_MAX]; | |
116 | ||
95ea3627 ID |
117 | /* |
118 | * Driver and chipset files will use a data buffer | |
119 | * that has been created in advance. This will simplify | |
120 | * the code since we can use the debugfs functions. | |
121 | */ | |
122 | struct debugfs_blob_wrapper driver_blob; | |
123 | struct debugfs_blob_wrapper chipset_blob; | |
124 | ||
125 | /* | |
126 | * Requested offset for each register type. | |
127 | */ | |
128 | unsigned int offset_csr; | |
129 | unsigned int offset_eeprom; | |
130 | unsigned int offset_bbp; | |
131 | unsigned int offset_rf; | |
132 | }; | |
133 | ||
2bb057d0 | 134 | void rt2x00debug_update_crypto(struct rt2x00_dev *rt2x00dev, |
84e3196f | 135 | struct rxdone_entry_desc *rxdesc) |
2bb057d0 ID |
136 | { |
137 | struct rt2x00debug_intf *intf = rt2x00dev->debugfs_intf; | |
84e3196f ID |
138 | enum cipher cipher = rxdesc->cipher; |
139 | enum rx_crypto status = rxdesc->cipher_status; | |
2bb057d0 ID |
140 | |
141 | if (cipher == CIPHER_TKIP_NO_MIC) | |
142 | cipher = CIPHER_TKIP; | |
a6c67339 | 143 | if (cipher == CIPHER_NONE || cipher >= CIPHER_MAX) |
2bb057d0 ID |
144 | return; |
145 | ||
146 | /* Remove CIPHER_NONE index */ | |
147 | cipher--; | |
148 | ||
149 | intf->crypto_stats[cipher].success += (status == RX_CRYPTO_SUCCESS); | |
150 | intf->crypto_stats[cipher].icv_error += (status == RX_CRYPTO_FAIL_ICV); | |
151 | intf->crypto_stats[cipher].mic_error += (status == RX_CRYPTO_FAIL_MIC); | |
152 | intf->crypto_stats[cipher].key_error += (status == RX_CRYPTO_FAIL_KEY); | |
153 | } | |
154 | ||
4d8dd66c | 155 | void rt2x00debug_dump_frame(struct rt2x00_dev *rt2x00dev, |
5a6e5999 | 156 | enum rt2x00_dump_type type, struct sk_buff *skb) |
4d8dd66c ID |
157 | { |
158 | struct rt2x00debug_intf *intf = rt2x00dev->debugfs_intf; | |
878f7045 | 159 | struct skb_frame_desc *skbdesc = get_skb_frame_desc(skb); |
4d8dd66c ID |
160 | struct sk_buff *skbcopy; |
161 | struct rt2x00dump_hdr *dump_hdr; | |
162 | struct timeval timestamp; | |
fd76f148 | 163 | u32 data_len; |
4d8dd66c ID |
164 | |
165 | do_gettimeofday(×tamp); | |
4d8dd66c ID |
166 | |
167 | if (!test_bit(FRAME_DUMP_FILE_OPEN, &intf->frame_dump_flags)) | |
168 | return; | |
169 | ||
170 | if (skb_queue_len(&intf->frame_dump_skbqueue) > 20) { | |
171 | DEBUG(rt2x00dev, "txrx dump queue length exceeded.\n"); | |
172 | return; | |
173 | } | |
174 | ||
fd76f148 GW |
175 | data_len = skb->len; |
176 | if (skbdesc->flags & SKBDESC_DESC_IN_SKB) | |
177 | data_len -= skbdesc->desc_len; | |
178 | ||
179 | skbcopy = alloc_skb(sizeof(*dump_hdr) + skbdesc->desc_len + data_len, | |
4d8dd66c ID |
180 | GFP_ATOMIC); |
181 | if (!skbcopy) { | |
182 | DEBUG(rt2x00dev, "Failed to copy skb for dump.\n"); | |
183 | return; | |
184 | } | |
185 | ||
186 | dump_hdr = (struct rt2x00dump_hdr *)skb_put(skbcopy, sizeof(*dump_hdr)); | |
187 | dump_hdr->version = cpu_to_le32(DUMP_HEADER_VERSION); | |
188 | dump_hdr->header_length = cpu_to_le32(sizeof(*dump_hdr)); | |
878f7045 | 189 | dump_hdr->desc_length = cpu_to_le32(skbdesc->desc_len); |
fd76f148 | 190 | dump_hdr->data_length = cpu_to_le32(data_len); |
4d8dd66c ID |
191 | dump_hdr->chip_rt = cpu_to_le16(rt2x00dev->chip.rt); |
192 | dump_hdr->chip_rf = cpu_to_le16(rt2x00dev->chip.rf); | |
49e721ec | 193 | dump_hdr->chip_rev = cpu_to_le16(rt2x00dev->chip.rev); |
5a6e5999 | 194 | dump_hdr->type = cpu_to_le16(type); |
878f7045 GW |
195 | dump_hdr->queue_index = skbdesc->entry->queue->qid; |
196 | dump_hdr->entry_index = skbdesc->entry->entry_idx; | |
4d8dd66c ID |
197 | dump_hdr->timestamp_sec = cpu_to_le32(timestamp.tv_sec); |
198 | dump_hdr->timestamp_usec = cpu_to_le32(timestamp.tv_usec); | |
199 | ||
fd76f148 GW |
200 | if (!(skbdesc->flags & SKBDESC_DESC_IN_SKB)) |
201 | memcpy(skb_put(skbcopy, skbdesc->desc_len), skbdesc->desc, | |
202 | skbdesc->desc_len); | |
d56d453a | 203 | memcpy(skb_put(skbcopy, skb->len), skb->data, skb->len); |
4d8dd66c ID |
204 | |
205 | skb_queue_tail(&intf->frame_dump_skbqueue, skbcopy); | |
206 | wake_up_interruptible(&intf->frame_dump_waitqueue); | |
207 | ||
208 | /* | |
209 | * Verify that the file has not been closed while we were working. | |
210 | */ | |
211 | if (!test_bit(FRAME_DUMP_FILE_OPEN, &intf->frame_dump_flags)) | |
212 | skb_queue_purge(&intf->frame_dump_skbqueue); | |
213 | } | |
b4df4708 | 214 | EXPORT_SYMBOL_GPL(rt2x00debug_dump_frame); |
4d8dd66c | 215 | |
95ea3627 ID |
216 | static int rt2x00debug_file_open(struct inode *inode, struct file *file) |
217 | { | |
218 | struct rt2x00debug_intf *intf = inode->i_private; | |
219 | ||
220 | file->private_data = inode->i_private; | |
221 | ||
222 | if (!try_module_get(intf->debug->owner)) | |
223 | return -EBUSY; | |
224 | ||
225 | return 0; | |
226 | } | |
227 | ||
228 | static int rt2x00debug_file_release(struct inode *inode, struct file *file) | |
229 | { | |
230 | struct rt2x00debug_intf *intf = file->private_data; | |
231 | ||
232 | module_put(intf->debug->owner); | |
233 | ||
234 | return 0; | |
235 | } | |
236 | ||
181d6902 | 237 | static int rt2x00debug_open_queue_dump(struct inode *inode, struct file *file) |
4d8dd66c ID |
238 | { |
239 | struct rt2x00debug_intf *intf = inode->i_private; | |
240 | int retval; | |
241 | ||
242 | retval = rt2x00debug_file_open(inode, file); | |
243 | if (retval) | |
244 | return retval; | |
245 | ||
246 | if (test_and_set_bit(FRAME_DUMP_FILE_OPEN, &intf->frame_dump_flags)) { | |
247 | rt2x00debug_file_release(inode, file); | |
248 | return -EBUSY; | |
249 | } | |
250 | ||
251 | return 0; | |
252 | } | |
253 | ||
181d6902 | 254 | static int rt2x00debug_release_queue_dump(struct inode *inode, struct file *file) |
4d8dd66c ID |
255 | { |
256 | struct rt2x00debug_intf *intf = inode->i_private; | |
257 | ||
258 | skb_queue_purge(&intf->frame_dump_skbqueue); | |
259 | ||
260 | clear_bit(FRAME_DUMP_FILE_OPEN, &intf->frame_dump_flags); | |
261 | ||
262 | return rt2x00debug_file_release(inode, file); | |
263 | } | |
264 | ||
181d6902 ID |
265 | static ssize_t rt2x00debug_read_queue_dump(struct file *file, |
266 | char __user *buf, | |
267 | size_t length, | |
268 | loff_t *offset) | |
4d8dd66c ID |
269 | { |
270 | struct rt2x00debug_intf *intf = file->private_data; | |
271 | struct sk_buff *skb; | |
272 | size_t status; | |
273 | int retval; | |
274 | ||
275 | if (file->f_flags & O_NONBLOCK) | |
276 | return -EAGAIN; | |
277 | ||
278 | retval = | |
279 | wait_event_interruptible(intf->frame_dump_waitqueue, | |
280 | (skb = | |
281 | skb_dequeue(&intf->frame_dump_skbqueue))); | |
282 | if (retval) | |
283 | return retval; | |
284 | ||
285 | status = min((size_t)skb->len, length); | |
286 | if (copy_to_user(buf, skb->data, status)) { | |
287 | status = -EFAULT; | |
288 | goto exit; | |
289 | } | |
290 | ||
291 | *offset += status; | |
292 | ||
293 | exit: | |
294 | kfree_skb(skb); | |
295 | ||
296 | return status; | |
297 | } | |
298 | ||
181d6902 | 299 | static unsigned int rt2x00debug_poll_queue_dump(struct file *file, |
55887511 | 300 | poll_table *wait) |
4d8dd66c ID |
301 | { |
302 | struct rt2x00debug_intf *intf = file->private_data; | |
303 | ||
304 | poll_wait(file, &intf->frame_dump_waitqueue, wait); | |
305 | ||
306 | if (!skb_queue_empty(&intf->frame_dump_skbqueue)) | |
307 | return POLLOUT | POLLWRNORM; | |
308 | ||
309 | return 0; | |
310 | } | |
311 | ||
181d6902 | 312 | static const struct file_operations rt2x00debug_fop_queue_dump = { |
4d8dd66c | 313 | .owner = THIS_MODULE, |
181d6902 ID |
314 | .read = rt2x00debug_read_queue_dump, |
315 | .poll = rt2x00debug_poll_queue_dump, | |
316 | .open = rt2x00debug_open_queue_dump, | |
317 | .release = rt2x00debug_release_queue_dump, | |
6038f373 | 318 | .llseek = default_llseek, |
4d8dd66c ID |
319 | }; |
320 | ||
68598d29 ID |
321 | static ssize_t rt2x00debug_read_queue_stats(struct file *file, |
322 | char __user *buf, | |
323 | size_t length, | |
324 | loff_t *offset) | |
325 | { | |
326 | struct rt2x00debug_intf *intf = file->private_data; | |
327 | struct data_queue *queue; | |
5f46c4d0 | 328 | unsigned long irqflags; |
68598d29 ID |
329 | unsigned int lines = 1 + intf->rt2x00dev->data_queues; |
330 | size_t size; | |
331 | char *data; | |
332 | char *temp; | |
333 | ||
334 | if (*offset) | |
335 | return 0; | |
336 | ||
337 | data = kzalloc(lines * MAX_LINE_LENGTH, GFP_KERNEL); | |
338 | if (!data) | |
339 | return -ENOMEM; | |
340 | ||
341 | temp = data + | |
342 | sprintf(data, "qid\tcount\tlimit\tlength\tindex\tdone\tcrypto\n"); | |
343 | ||
344 | queue_for_each(intf->rt2x00dev, queue) { | |
5f46c4d0 | 345 | spin_lock_irqsave(&queue->lock, irqflags); |
68598d29 ID |
346 | |
347 | temp += sprintf(temp, "%d\t%d\t%d\t%d\t%d\t%d\t%d\n", queue->qid, | |
348 | queue->count, queue->limit, queue->length, | |
349 | queue->index[Q_INDEX], | |
350 | queue->index[Q_INDEX_DONE], | |
351 | queue->index[Q_INDEX_CRYPTO]); | |
352 | ||
5f46c4d0 | 353 | spin_unlock_irqrestore(&queue->lock, irqflags); |
68598d29 ID |
354 | } |
355 | ||
356 | size = strlen(data); | |
357 | size = min(size, length); | |
358 | ||
359 | if (copy_to_user(buf, data, size)) { | |
360 | kfree(data); | |
361 | return -EFAULT; | |
362 | } | |
363 | ||
364 | kfree(data); | |
365 | ||
366 | *offset += size; | |
367 | return size; | |
368 | } | |
369 | ||
370 | static const struct file_operations rt2x00debug_fop_queue_stats = { | |
371 | .owner = THIS_MODULE, | |
372 | .read = rt2x00debug_read_queue_stats, | |
373 | .open = rt2x00debug_file_open, | |
374 | .release = rt2x00debug_file_release, | |
6038f373 | 375 | .llseek = default_llseek, |
68598d29 ID |
376 | }; |
377 | ||
2bb057d0 ID |
378 | #ifdef CONFIG_RT2X00_LIB_CRYPTO |
379 | static ssize_t rt2x00debug_read_crypto_stats(struct file *file, | |
380 | char __user *buf, | |
381 | size_t length, | |
382 | loff_t *offset) | |
383 | { | |
384 | struct rt2x00debug_intf *intf = file->private_data; | |
385 | char *name[] = { "WEP64", "WEP128", "TKIP", "AES" }; | |
386 | char *data; | |
387 | char *temp; | |
388 | size_t size; | |
389 | unsigned int i; | |
390 | ||
391 | if (*offset) | |
392 | return 0; | |
393 | ||
55887511 | 394 | data = kzalloc((1 + CIPHER_MAX) * MAX_LINE_LENGTH, GFP_KERNEL); |
2bb057d0 ID |
395 | if (!data) |
396 | return -ENOMEM; | |
397 | ||
398 | temp = data; | |
399 | temp += sprintf(data, "cipher\tsuccess\ticv err\tmic err\tkey err\n"); | |
400 | ||
401 | for (i = 0; i < CIPHER_MAX; i++) { | |
402 | temp += sprintf(temp, "%s\t%lu\t%lu\t%lu\t%lu\n", name[i], | |
403 | intf->crypto_stats[i].success, | |
404 | intf->crypto_stats[i].icv_error, | |
405 | intf->crypto_stats[i].mic_error, | |
406 | intf->crypto_stats[i].key_error); | |
407 | } | |
408 | ||
409 | size = strlen(data); | |
410 | size = min(size, length); | |
411 | ||
412 | if (copy_to_user(buf, data, size)) { | |
413 | kfree(data); | |
414 | return -EFAULT; | |
415 | } | |
416 | ||
417 | kfree(data); | |
418 | ||
419 | *offset += size; | |
420 | return size; | |
421 | } | |
422 | ||
423 | static const struct file_operations rt2x00debug_fop_crypto_stats = { | |
424 | .owner = THIS_MODULE, | |
425 | .read = rt2x00debug_read_crypto_stats, | |
426 | .open = rt2x00debug_file_open, | |
427 | .release = rt2x00debug_file_release, | |
6038f373 | 428 | .llseek = default_llseek, |
2bb057d0 ID |
429 | }; |
430 | #endif | |
431 | ||
95ea3627 ID |
432 | #define RT2X00DEBUGFS_OPS_READ(__name, __format, __type) \ |
433 | static ssize_t rt2x00debug_read_##__name(struct file *file, \ | |
434 | char __user *buf, \ | |
435 | size_t length, \ | |
436 | loff_t *offset) \ | |
437 | { \ | |
91921a4e | 438 | struct rt2x00debug_intf *intf = file->private_data; \ |
95ea3627 ID |
439 | const struct rt2x00debug *debug = intf->debug; \ |
440 | char line[16]; \ | |
441 | size_t size; \ | |
743b97ca | 442 | unsigned int index = intf->offset_##__name; \ |
95ea3627 ID |
443 | __type value; \ |
444 | \ | |
445 | if (*offset) \ | |
446 | return 0; \ | |
447 | \ | |
743b97ca | 448 | if (index >= debug->__name.word_count) \ |
95ea3627 ID |
449 | return -EINVAL; \ |
450 | \ | |
abd2fdb4 ID |
451 | index += (debug->__name.word_base / \ |
452 | debug->__name.word_size); \ | |
453 | \ | |
743b97ca ID |
454 | if (debug->__name.flags & RT2X00DEBUGFS_OFFSET) \ |
455 | index *= debug->__name.word_size; \ | |
456 | \ | |
743b97ca | 457 | debug->__name.read(intf->rt2x00dev, index, &value); \ |
95ea3627 ID |
458 | \ |
459 | size = sprintf(line, __format, value); \ | |
460 | \ | |
461 | if (copy_to_user(buf, line, size)) \ | |
462 | return -EFAULT; \ | |
463 | \ | |
464 | *offset += size; \ | |
465 | return size; \ | |
466 | } | |
467 | ||
468 | #define RT2X00DEBUGFS_OPS_WRITE(__name, __type) \ | |
469 | static ssize_t rt2x00debug_write_##__name(struct file *file, \ | |
470 | const char __user *buf,\ | |
471 | size_t length, \ | |
472 | loff_t *offset) \ | |
473 | { \ | |
91921a4e | 474 | struct rt2x00debug_intf *intf = file->private_data; \ |
95ea3627 ID |
475 | const struct rt2x00debug *debug = intf->debug; \ |
476 | char line[16]; \ | |
477 | size_t size; \ | |
743b97ca | 478 | unsigned int index = intf->offset_##__name; \ |
95ea3627 ID |
479 | __type value; \ |
480 | \ | |
481 | if (*offset) \ | |
482 | return 0; \ | |
483 | \ | |
743b97ca | 484 | if (index >= debug->__name.word_count) \ |
95ea3627 ID |
485 | return -EINVAL; \ |
486 | \ | |
487 | if (copy_from_user(line, buf, length)) \ | |
488 | return -EFAULT; \ | |
489 | \ | |
490 | size = strlen(line); \ | |
491 | value = simple_strtoul(line, NULL, 0); \ | |
492 | \ | |
abd2fdb4 ID |
493 | index += (debug->__name.word_base / \ |
494 | debug->__name.word_size); \ | |
495 | \ | |
743b97ca ID |
496 | if (debug->__name.flags & RT2X00DEBUGFS_OFFSET) \ |
497 | index *= debug->__name.word_size; \ | |
498 | \ | |
743b97ca | 499 | debug->__name.write(intf->rt2x00dev, index, value); \ |
95ea3627 ID |
500 | \ |
501 | *offset += size; \ | |
502 | return size; \ | |
503 | } | |
504 | ||
505 | #define RT2X00DEBUGFS_OPS(__name, __format, __type) \ | |
506 | RT2X00DEBUGFS_OPS_READ(__name, __format, __type); \ | |
507 | RT2X00DEBUGFS_OPS_WRITE(__name, __type); \ | |
508 | \ | |
509 | static const struct file_operations rt2x00debug_fop_##__name = {\ | |
510 | .owner = THIS_MODULE, \ | |
511 | .read = rt2x00debug_read_##__name, \ | |
512 | .write = rt2x00debug_write_##__name, \ | |
513 | .open = rt2x00debug_file_open, \ | |
514 | .release = rt2x00debug_file_release, \ | |
2b18ab36 | 515 | .llseek = generic_file_llseek, \ |
95ea3627 ID |
516 | }; |
517 | ||
518 | RT2X00DEBUGFS_OPS(csr, "0x%.8x\n", u32); | |
519 | RT2X00DEBUGFS_OPS(eeprom, "0x%.4x\n", u16); | |
520 | RT2X00DEBUGFS_OPS(bbp, "0x%.2x\n", u8); | |
521 | RT2X00DEBUGFS_OPS(rf, "0x%.8x\n", u32); | |
522 | ||
643b2521 ID |
523 | static ssize_t rt2x00debug_read_dev_flags(struct file *file, |
524 | char __user *buf, | |
525 | size_t length, | |
526 | loff_t *offset) | |
527 | { | |
528 | struct rt2x00debug_intf *intf = file->private_data; | |
529 | char line[16]; | |
530 | size_t size; | |
531 | ||
532 | if (*offset) | |
533 | return 0; | |
534 | ||
535 | size = sprintf(line, "0x%.8x\n", (unsigned int)intf->rt2x00dev->flags); | |
536 | ||
537 | if (copy_to_user(buf, line, size)) | |
538 | return -EFAULT; | |
539 | ||
540 | *offset += size; | |
541 | return size; | |
542 | } | |
543 | ||
544 | static const struct file_operations rt2x00debug_fop_dev_flags = { | |
545 | .owner = THIS_MODULE, | |
546 | .read = rt2x00debug_read_dev_flags, | |
547 | .open = rt2x00debug_file_open, | |
548 | .release = rt2x00debug_file_release, | |
6038f373 | 549 | .llseek = default_llseek, |
643b2521 ID |
550 | }; |
551 | ||
95ea3627 ID |
552 | static struct dentry *rt2x00debug_create_file_driver(const char *name, |
553 | struct rt2x00debug_intf | |
554 | *intf, | |
555 | struct debugfs_blob_wrapper | |
556 | *blob) | |
557 | { | |
558 | char *data; | |
559 | ||
68598d29 | 560 | data = kzalloc(3 * MAX_LINE_LENGTH, GFP_KERNEL); |
95ea3627 ID |
561 | if (!data) |
562 | return NULL; | |
563 | ||
564 | blob->data = data; | |
860559fe ID |
565 | data += sprintf(data, "driver:\t%s\n", intf->rt2x00dev->ops->name); |
566 | data += sprintf(data, "version:\t%s\n", DRV_VERSION); | |
567 | data += sprintf(data, "compiled:\t%s %s\n", __DATE__, __TIME__); | |
95ea3627 ID |
568 | blob->size = strlen(blob->data); |
569 | ||
d2b69071 | 570 | return debugfs_create_blob(name, S_IRUSR, intf->driver_folder, blob); |
95ea3627 ID |
571 | } |
572 | ||
573 | static struct dentry *rt2x00debug_create_file_chipset(const char *name, | |
574 | struct rt2x00debug_intf | |
575 | *intf, | |
576 | struct | |
577 | debugfs_blob_wrapper | |
578 | *blob) | |
579 | { | |
580 | const struct rt2x00debug *debug = intf->debug; | |
581 | char *data; | |
582 | ||
68598d29 | 583 | data = kzalloc(8 * MAX_LINE_LENGTH, GFP_KERNEL); |
95ea3627 ID |
584 | if (!data) |
585 | return NULL; | |
586 | ||
3e34c6dc | 587 | blob->data = data; |
860559fe ID |
588 | data += sprintf(data, "rt chip:\t%04x\n", intf->rt2x00dev->chip.rt); |
589 | data += sprintf(data, "rf chip:\t%04x\n", intf->rt2x00dev->chip.rf); | |
49e721ec | 590 | data += sprintf(data, "revision:\t%04x\n", intf->rt2x00dev->chip.rev); |
22c96c28 | 591 | data += sprintf(data, "\n"); |
860559fe ID |
592 | data += sprintf(data, "register\tbase\twords\twordsize\n"); |
593 | data += sprintf(data, "csr\t%d\t%d\t%d\n", | |
594 | debug->csr.word_base, | |
595 | debug->csr.word_count, | |
596 | debug->csr.word_size); | |
597 | data += sprintf(data, "eeprom\t%d\t%d\t%d\n", | |
598 | debug->eeprom.word_base, | |
599 | debug->eeprom.word_count, | |
600 | debug->eeprom.word_size); | |
601 | data += sprintf(data, "bbp\t%d\t%d\t%d\n", | |
602 | debug->bbp.word_base, | |
603 | debug->bbp.word_count, | |
604 | debug->bbp.word_size); | |
605 | data += sprintf(data, "rf\t%d\t%d\t%d\n", | |
606 | debug->rf.word_base, | |
607 | debug->rf.word_count, | |
608 | debug->rf.word_size); | |
3e34c6dc | 609 | blob->size = strlen(blob->data); |
95ea3627 | 610 | |
d2b69071 | 611 | return debugfs_create_blob(name, S_IRUSR, intf->driver_folder, blob); |
95ea3627 ID |
612 | } |
613 | ||
614 | void rt2x00debug_register(struct rt2x00_dev *rt2x00dev) | |
615 | { | |
616 | const struct rt2x00debug *debug = rt2x00dev->ops->debugfs; | |
617 | struct rt2x00debug_intf *intf; | |
618 | ||
619 | intf = kzalloc(sizeof(struct rt2x00debug_intf), GFP_KERNEL); | |
620 | if (!intf) { | |
621 | ERROR(rt2x00dev, "Failed to allocate debug handler.\n"); | |
622 | return; | |
623 | } | |
624 | ||
625 | intf->debug = debug; | |
626 | intf->rt2x00dev = rt2x00dev; | |
627 | rt2x00dev->debugfs_intf = intf; | |
628 | ||
629 | intf->driver_folder = | |
630 | debugfs_create_dir(intf->rt2x00dev->ops->name, | |
631 | rt2x00dev->hw->wiphy->debugfsdir); | |
cfa3fa40 | 632 | if (IS_ERR(intf->driver_folder) || !intf->driver_folder) |
95ea3627 ID |
633 | goto exit; |
634 | ||
635 | intf->driver_entry = | |
636 | rt2x00debug_create_file_driver("driver", intf, &intf->driver_blob); | |
cfa3fa40 | 637 | if (IS_ERR(intf->driver_entry) || !intf->driver_entry) |
95ea3627 ID |
638 | goto exit; |
639 | ||
640 | intf->chipset_entry = | |
641 | rt2x00debug_create_file_chipset("chipset", | |
642 | intf, &intf->chipset_blob); | |
cfa3fa40 | 643 | if (IS_ERR(intf->chipset_entry) || !intf->chipset_entry) |
95ea3627 ID |
644 | goto exit; |
645 | ||
d2b69071 | 646 | intf->dev_flags = debugfs_create_file("dev_flags", S_IRUSR, |
643b2521 ID |
647 | intf->driver_folder, intf, |
648 | &rt2x00debug_fop_dev_flags); | |
cfa3fa40 | 649 | if (IS_ERR(intf->dev_flags) || !intf->dev_flags) |
643b2521 ID |
650 | goto exit; |
651 | ||
91921a4e ID |
652 | intf->register_folder = |
653 | debugfs_create_dir("register", intf->driver_folder); | |
cfa3fa40 | 654 | if (IS_ERR(intf->register_folder) || !intf->register_folder) |
91921a4e ID |
655 | goto exit; |
656 | ||
657 | #define RT2X00DEBUGFS_CREATE_REGISTER_ENTRY(__intf, __name) \ | |
95ea3627 ID |
658 | ({ \ |
659 | (__intf)->__name##_off_entry = \ | |
660 | debugfs_create_u32(__stringify(__name) "_offset", \ | |
d2b69071 | 661 | S_IRUSR | S_IWUSR, \ |
91921a4e | 662 | (__intf)->register_folder, \ |
95ea3627 | 663 | &(__intf)->offset_##__name); \ |
cfa3fa40 Z |
664 | if (IS_ERR((__intf)->__name##_off_entry) \ |
665 | || !(__intf)->__name##_off_entry) \ | |
95ea3627 ID |
666 | goto exit; \ |
667 | \ | |
668 | (__intf)->__name##_val_entry = \ | |
669 | debugfs_create_file(__stringify(__name) "_value", \ | |
d2b69071 | 670 | S_IRUSR | S_IWUSR, \ |
91921a4e | 671 | (__intf)->register_folder, \ |
95ea3627 | 672 | (__intf), &rt2x00debug_fop_##__name);\ |
cfa3fa40 Z |
673 | if (IS_ERR((__intf)->__name##_val_entry) \ |
674 | || !(__intf)->__name##_val_entry) \ | |
95ea3627 ID |
675 | goto exit; \ |
676 | }) | |
677 | ||
91921a4e ID |
678 | RT2X00DEBUGFS_CREATE_REGISTER_ENTRY(intf, csr); |
679 | RT2X00DEBUGFS_CREATE_REGISTER_ENTRY(intf, eeprom); | |
680 | RT2X00DEBUGFS_CREATE_REGISTER_ENTRY(intf, bbp); | |
681 | RT2X00DEBUGFS_CREATE_REGISTER_ENTRY(intf, rf); | |
95ea3627 | 682 | |
91921a4e | 683 | #undef RT2X00DEBUGFS_CREATE_REGISTER_ENTRY |
95ea3627 | 684 | |
68598d29 ID |
685 | intf->queue_folder = |
686 | debugfs_create_dir("queue", intf->driver_folder); | |
cfa3fa40 | 687 | if (IS_ERR(intf->queue_folder) || !intf->queue_folder) |
4d8dd66c ID |
688 | goto exit; |
689 | ||
68598d29 | 690 | intf->queue_frame_dump_entry = |
d2b69071 | 691 | debugfs_create_file("dump", S_IRUSR, intf->queue_folder, |
181d6902 | 692 | intf, &rt2x00debug_fop_queue_dump); |
cfa3fa40 Z |
693 | if (IS_ERR(intf->queue_frame_dump_entry) |
694 | || !intf->queue_frame_dump_entry) | |
4d8dd66c ID |
695 | goto exit; |
696 | ||
697 | skb_queue_head_init(&intf->frame_dump_skbqueue); | |
698 | init_waitqueue_head(&intf->frame_dump_waitqueue); | |
699 | ||
68598d29 | 700 | intf->queue_stats_entry = |
d2b69071 | 701 | debugfs_create_file("queue", S_IRUSR, intf->queue_folder, |
68598d29 ID |
702 | intf, &rt2x00debug_fop_queue_stats); |
703 | ||
2bb057d0 ID |
704 | #ifdef CONFIG_RT2X00_LIB_CRYPTO |
705 | if (test_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags)) | |
706 | intf->crypto_stats_entry = | |
707 | debugfs_create_file("crypto", S_IRUGO, intf->queue_folder, | |
708 | intf, &rt2x00debug_fop_crypto_stats); | |
709 | #endif | |
710 | ||
95ea3627 ID |
711 | return; |
712 | ||
713 | exit: | |
714 | rt2x00debug_deregister(rt2x00dev); | |
715 | ERROR(rt2x00dev, "Failed to register debug handler.\n"); | |
95ea3627 ID |
716 | } |
717 | ||
718 | void rt2x00debug_deregister(struct rt2x00_dev *rt2x00dev) | |
719 | { | |
4d8dd66c | 720 | struct rt2x00debug_intf *intf = rt2x00dev->debugfs_intf; |
95ea3627 ID |
721 | |
722 | if (unlikely(!intf)) | |
723 | return; | |
724 | ||
4d8dd66c ID |
725 | skb_queue_purge(&intf->frame_dump_skbqueue); |
726 | ||
2bb057d0 ID |
727 | #ifdef CONFIG_RT2X00_LIB_CRYPTO |
728 | debugfs_remove(intf->crypto_stats_entry); | |
729 | #endif | |
68598d29 ID |
730 | debugfs_remove(intf->queue_stats_entry); |
731 | debugfs_remove(intf->queue_frame_dump_entry); | |
732 | debugfs_remove(intf->queue_folder); | |
95ea3627 ID |
733 | debugfs_remove(intf->rf_val_entry); |
734 | debugfs_remove(intf->rf_off_entry); | |
735 | debugfs_remove(intf->bbp_val_entry); | |
736 | debugfs_remove(intf->bbp_off_entry); | |
737 | debugfs_remove(intf->eeprom_val_entry); | |
738 | debugfs_remove(intf->eeprom_off_entry); | |
739 | debugfs_remove(intf->csr_val_entry); | |
740 | debugfs_remove(intf->csr_off_entry); | |
91921a4e | 741 | debugfs_remove(intf->register_folder); |
643b2521 | 742 | debugfs_remove(intf->dev_flags); |
95ea3627 ID |
743 | debugfs_remove(intf->chipset_entry); |
744 | debugfs_remove(intf->driver_entry); | |
745 | debugfs_remove(intf->driver_folder); | |
746 | kfree(intf->chipset_blob.data); | |
747 | kfree(intf->driver_blob.data); | |
748 | kfree(intf); | |
749 | ||
750 | rt2x00dev->debugfs_intf = NULL; | |
751 | } |