]>
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; | |
181d6902 | 159 | struct skb_frame_desc *desc = get_skb_frame_desc(skb); |
4d8dd66c ID |
160 | struct sk_buff *skbcopy; |
161 | struct rt2x00dump_hdr *dump_hdr; | |
162 | struct timeval timestamp; | |
4d8dd66c ID |
163 | |
164 | do_gettimeofday(×tamp); | |
4d8dd66c ID |
165 | |
166 | if (!test_bit(FRAME_DUMP_FILE_OPEN, &intf->frame_dump_flags)) | |
167 | return; | |
168 | ||
169 | if (skb_queue_len(&intf->frame_dump_skbqueue) > 20) { | |
170 | DEBUG(rt2x00dev, "txrx dump queue length exceeded.\n"); | |
171 | return; | |
172 | } | |
173 | ||
d56d453a | 174 | skbcopy = alloc_skb(sizeof(*dump_hdr) + desc->desc_len + skb->len, |
4d8dd66c ID |
175 | GFP_ATOMIC); |
176 | if (!skbcopy) { | |
177 | DEBUG(rt2x00dev, "Failed to copy skb for dump.\n"); | |
178 | return; | |
179 | } | |
180 | ||
181 | dump_hdr = (struct rt2x00dump_hdr *)skb_put(skbcopy, sizeof(*dump_hdr)); | |
182 | dump_hdr->version = cpu_to_le32(DUMP_HEADER_VERSION); | |
183 | dump_hdr->header_length = cpu_to_le32(sizeof(*dump_hdr)); | |
184 | dump_hdr->desc_length = cpu_to_le32(desc->desc_len); | |
d56d453a | 185 | dump_hdr->data_length = cpu_to_le32(skb->len); |
4d8dd66c ID |
186 | dump_hdr->chip_rt = cpu_to_le16(rt2x00dev->chip.rt); |
187 | dump_hdr->chip_rf = cpu_to_le16(rt2x00dev->chip.rf); | |
49e721ec | 188 | dump_hdr->chip_rev = cpu_to_le16(rt2x00dev->chip.rev); |
5a6e5999 | 189 | dump_hdr->type = cpu_to_le16(type); |
181d6902 | 190 | dump_hdr->queue_index = desc->entry->queue->qid; |
04267104 | 191 | dump_hdr->entry_index = desc->entry->entry_idx; |
4d8dd66c ID |
192 | dump_hdr->timestamp_sec = cpu_to_le32(timestamp.tv_sec); |
193 | dump_hdr->timestamp_usec = cpu_to_le32(timestamp.tv_usec); | |
194 | ||
195 | memcpy(skb_put(skbcopy, desc->desc_len), desc->desc, desc->desc_len); | |
d56d453a | 196 | memcpy(skb_put(skbcopy, skb->len), skb->data, skb->len); |
4d8dd66c ID |
197 | |
198 | skb_queue_tail(&intf->frame_dump_skbqueue, skbcopy); | |
199 | wake_up_interruptible(&intf->frame_dump_waitqueue); | |
200 | ||
201 | /* | |
202 | * Verify that the file has not been closed while we were working. | |
203 | */ | |
204 | if (!test_bit(FRAME_DUMP_FILE_OPEN, &intf->frame_dump_flags)) | |
205 | skb_queue_purge(&intf->frame_dump_skbqueue); | |
206 | } | |
207 | ||
95ea3627 ID |
208 | static int rt2x00debug_file_open(struct inode *inode, struct file *file) |
209 | { | |
210 | struct rt2x00debug_intf *intf = inode->i_private; | |
211 | ||
212 | file->private_data = inode->i_private; | |
213 | ||
214 | if (!try_module_get(intf->debug->owner)) | |
215 | return -EBUSY; | |
216 | ||
217 | return 0; | |
218 | } | |
219 | ||
220 | static int rt2x00debug_file_release(struct inode *inode, struct file *file) | |
221 | { | |
222 | struct rt2x00debug_intf *intf = file->private_data; | |
223 | ||
224 | module_put(intf->debug->owner); | |
225 | ||
226 | return 0; | |
227 | } | |
228 | ||
181d6902 | 229 | static int rt2x00debug_open_queue_dump(struct inode *inode, struct file *file) |
4d8dd66c ID |
230 | { |
231 | struct rt2x00debug_intf *intf = inode->i_private; | |
232 | int retval; | |
233 | ||
234 | retval = rt2x00debug_file_open(inode, file); | |
235 | if (retval) | |
236 | return retval; | |
237 | ||
238 | if (test_and_set_bit(FRAME_DUMP_FILE_OPEN, &intf->frame_dump_flags)) { | |
239 | rt2x00debug_file_release(inode, file); | |
240 | return -EBUSY; | |
241 | } | |
242 | ||
243 | return 0; | |
244 | } | |
245 | ||
181d6902 | 246 | static int rt2x00debug_release_queue_dump(struct inode *inode, struct file *file) |
4d8dd66c ID |
247 | { |
248 | struct rt2x00debug_intf *intf = inode->i_private; | |
249 | ||
250 | skb_queue_purge(&intf->frame_dump_skbqueue); | |
251 | ||
252 | clear_bit(FRAME_DUMP_FILE_OPEN, &intf->frame_dump_flags); | |
253 | ||
254 | return rt2x00debug_file_release(inode, file); | |
255 | } | |
256 | ||
181d6902 ID |
257 | static ssize_t rt2x00debug_read_queue_dump(struct file *file, |
258 | char __user *buf, | |
259 | size_t length, | |
260 | loff_t *offset) | |
4d8dd66c ID |
261 | { |
262 | struct rt2x00debug_intf *intf = file->private_data; | |
263 | struct sk_buff *skb; | |
264 | size_t status; | |
265 | int retval; | |
266 | ||
267 | if (file->f_flags & O_NONBLOCK) | |
268 | return -EAGAIN; | |
269 | ||
270 | retval = | |
271 | wait_event_interruptible(intf->frame_dump_waitqueue, | |
272 | (skb = | |
273 | skb_dequeue(&intf->frame_dump_skbqueue))); | |
274 | if (retval) | |
275 | return retval; | |
276 | ||
277 | status = min((size_t)skb->len, length); | |
278 | if (copy_to_user(buf, skb->data, status)) { | |
279 | status = -EFAULT; | |
280 | goto exit; | |
281 | } | |
282 | ||
283 | *offset += status; | |
284 | ||
285 | exit: | |
286 | kfree_skb(skb); | |
287 | ||
288 | return status; | |
289 | } | |
290 | ||
181d6902 | 291 | static unsigned int rt2x00debug_poll_queue_dump(struct file *file, |
55887511 | 292 | poll_table *wait) |
4d8dd66c ID |
293 | { |
294 | struct rt2x00debug_intf *intf = file->private_data; | |
295 | ||
296 | poll_wait(file, &intf->frame_dump_waitqueue, wait); | |
297 | ||
298 | if (!skb_queue_empty(&intf->frame_dump_skbqueue)) | |
299 | return POLLOUT | POLLWRNORM; | |
300 | ||
301 | return 0; | |
302 | } | |
303 | ||
181d6902 | 304 | static const struct file_operations rt2x00debug_fop_queue_dump = { |
4d8dd66c | 305 | .owner = THIS_MODULE, |
181d6902 ID |
306 | .read = rt2x00debug_read_queue_dump, |
307 | .poll = rt2x00debug_poll_queue_dump, | |
308 | .open = rt2x00debug_open_queue_dump, | |
309 | .release = rt2x00debug_release_queue_dump, | |
4d8dd66c ID |
310 | }; |
311 | ||
68598d29 ID |
312 | static ssize_t rt2x00debug_read_queue_stats(struct file *file, |
313 | char __user *buf, | |
314 | size_t length, | |
315 | loff_t *offset) | |
316 | { | |
317 | struct rt2x00debug_intf *intf = file->private_data; | |
318 | struct data_queue *queue; | |
5f46c4d0 | 319 | unsigned long irqflags; |
68598d29 ID |
320 | unsigned int lines = 1 + intf->rt2x00dev->data_queues; |
321 | size_t size; | |
322 | char *data; | |
323 | char *temp; | |
324 | ||
325 | if (*offset) | |
326 | return 0; | |
327 | ||
328 | data = kzalloc(lines * MAX_LINE_LENGTH, GFP_KERNEL); | |
329 | if (!data) | |
330 | return -ENOMEM; | |
331 | ||
332 | temp = data + | |
333 | sprintf(data, "qid\tcount\tlimit\tlength\tindex\tdone\tcrypto\n"); | |
334 | ||
335 | queue_for_each(intf->rt2x00dev, queue) { | |
5f46c4d0 | 336 | spin_lock_irqsave(&queue->lock, irqflags); |
68598d29 ID |
337 | |
338 | temp += sprintf(temp, "%d\t%d\t%d\t%d\t%d\t%d\t%d\n", queue->qid, | |
339 | queue->count, queue->limit, queue->length, | |
340 | queue->index[Q_INDEX], | |
341 | queue->index[Q_INDEX_DONE], | |
342 | queue->index[Q_INDEX_CRYPTO]); | |
343 | ||
5f46c4d0 | 344 | spin_unlock_irqrestore(&queue->lock, irqflags); |
68598d29 ID |
345 | } |
346 | ||
347 | size = strlen(data); | |
348 | size = min(size, length); | |
349 | ||
350 | if (copy_to_user(buf, data, size)) { | |
351 | kfree(data); | |
352 | return -EFAULT; | |
353 | } | |
354 | ||
355 | kfree(data); | |
356 | ||
357 | *offset += size; | |
358 | return size; | |
359 | } | |
360 | ||
361 | static const struct file_operations rt2x00debug_fop_queue_stats = { | |
362 | .owner = THIS_MODULE, | |
363 | .read = rt2x00debug_read_queue_stats, | |
364 | .open = rt2x00debug_file_open, | |
365 | .release = rt2x00debug_file_release, | |
366 | }; | |
367 | ||
2bb057d0 ID |
368 | #ifdef CONFIG_RT2X00_LIB_CRYPTO |
369 | static ssize_t rt2x00debug_read_crypto_stats(struct file *file, | |
370 | char __user *buf, | |
371 | size_t length, | |
372 | loff_t *offset) | |
373 | { | |
374 | struct rt2x00debug_intf *intf = file->private_data; | |
375 | char *name[] = { "WEP64", "WEP128", "TKIP", "AES" }; | |
376 | char *data; | |
377 | char *temp; | |
378 | size_t size; | |
379 | unsigned int i; | |
380 | ||
381 | if (*offset) | |
382 | return 0; | |
383 | ||
55887511 | 384 | data = kzalloc((1 + CIPHER_MAX) * MAX_LINE_LENGTH, GFP_KERNEL); |
2bb057d0 ID |
385 | if (!data) |
386 | return -ENOMEM; | |
387 | ||
388 | temp = data; | |
389 | temp += sprintf(data, "cipher\tsuccess\ticv err\tmic err\tkey err\n"); | |
390 | ||
391 | for (i = 0; i < CIPHER_MAX; i++) { | |
392 | temp += sprintf(temp, "%s\t%lu\t%lu\t%lu\t%lu\n", name[i], | |
393 | intf->crypto_stats[i].success, | |
394 | intf->crypto_stats[i].icv_error, | |
395 | intf->crypto_stats[i].mic_error, | |
396 | intf->crypto_stats[i].key_error); | |
397 | } | |
398 | ||
399 | size = strlen(data); | |
400 | size = min(size, length); | |
401 | ||
402 | if (copy_to_user(buf, data, size)) { | |
403 | kfree(data); | |
404 | return -EFAULT; | |
405 | } | |
406 | ||
407 | kfree(data); | |
408 | ||
409 | *offset += size; | |
410 | return size; | |
411 | } | |
412 | ||
413 | static const struct file_operations rt2x00debug_fop_crypto_stats = { | |
414 | .owner = THIS_MODULE, | |
415 | .read = rt2x00debug_read_crypto_stats, | |
416 | .open = rt2x00debug_file_open, | |
417 | .release = rt2x00debug_file_release, | |
418 | }; | |
419 | #endif | |
420 | ||
95ea3627 ID |
421 | #define RT2X00DEBUGFS_OPS_READ(__name, __format, __type) \ |
422 | static ssize_t rt2x00debug_read_##__name(struct file *file, \ | |
423 | char __user *buf, \ | |
424 | size_t length, \ | |
425 | loff_t *offset) \ | |
426 | { \ | |
91921a4e | 427 | struct rt2x00debug_intf *intf = file->private_data; \ |
95ea3627 ID |
428 | const struct rt2x00debug *debug = intf->debug; \ |
429 | char line[16]; \ | |
430 | size_t size; \ | |
743b97ca | 431 | unsigned int index = intf->offset_##__name; \ |
95ea3627 ID |
432 | __type value; \ |
433 | \ | |
434 | if (*offset) \ | |
435 | return 0; \ | |
436 | \ | |
743b97ca | 437 | if (index >= debug->__name.word_count) \ |
95ea3627 ID |
438 | return -EINVAL; \ |
439 | \ | |
abd2fdb4 ID |
440 | index += (debug->__name.word_base / \ |
441 | debug->__name.word_size); \ | |
442 | \ | |
743b97ca ID |
443 | if (debug->__name.flags & RT2X00DEBUGFS_OFFSET) \ |
444 | index *= debug->__name.word_size; \ | |
445 | \ | |
743b97ca | 446 | debug->__name.read(intf->rt2x00dev, index, &value); \ |
95ea3627 ID |
447 | \ |
448 | size = sprintf(line, __format, value); \ | |
449 | \ | |
450 | if (copy_to_user(buf, line, size)) \ | |
451 | return -EFAULT; \ | |
452 | \ | |
453 | *offset += size; \ | |
454 | return size; \ | |
455 | } | |
456 | ||
457 | #define RT2X00DEBUGFS_OPS_WRITE(__name, __type) \ | |
458 | static ssize_t rt2x00debug_write_##__name(struct file *file, \ | |
459 | const char __user *buf,\ | |
460 | size_t length, \ | |
461 | loff_t *offset) \ | |
462 | { \ | |
91921a4e | 463 | struct rt2x00debug_intf *intf = file->private_data; \ |
95ea3627 ID |
464 | const struct rt2x00debug *debug = intf->debug; \ |
465 | char line[16]; \ | |
466 | size_t size; \ | |
743b97ca | 467 | unsigned int index = intf->offset_##__name; \ |
95ea3627 ID |
468 | __type value; \ |
469 | \ | |
470 | if (*offset) \ | |
471 | return 0; \ | |
472 | \ | |
743b97ca | 473 | if (index >= debug->__name.word_count) \ |
95ea3627 ID |
474 | return -EINVAL; \ |
475 | \ | |
476 | if (copy_from_user(line, buf, length)) \ | |
477 | return -EFAULT; \ | |
478 | \ | |
479 | size = strlen(line); \ | |
480 | value = simple_strtoul(line, NULL, 0); \ | |
481 | \ | |
abd2fdb4 ID |
482 | index += (debug->__name.word_base / \ |
483 | debug->__name.word_size); \ | |
484 | \ | |
743b97ca ID |
485 | if (debug->__name.flags & RT2X00DEBUGFS_OFFSET) \ |
486 | index *= debug->__name.word_size; \ | |
487 | \ | |
743b97ca | 488 | debug->__name.write(intf->rt2x00dev, index, value); \ |
95ea3627 ID |
489 | \ |
490 | *offset += size; \ | |
491 | return size; \ | |
492 | } | |
493 | ||
494 | #define RT2X00DEBUGFS_OPS(__name, __format, __type) \ | |
495 | RT2X00DEBUGFS_OPS_READ(__name, __format, __type); \ | |
496 | RT2X00DEBUGFS_OPS_WRITE(__name, __type); \ | |
497 | \ | |
498 | static const struct file_operations rt2x00debug_fop_##__name = {\ | |
499 | .owner = THIS_MODULE, \ | |
500 | .read = rt2x00debug_read_##__name, \ | |
501 | .write = rt2x00debug_write_##__name, \ | |
502 | .open = rt2x00debug_file_open, \ | |
503 | .release = rt2x00debug_file_release, \ | |
504 | }; | |
505 | ||
506 | RT2X00DEBUGFS_OPS(csr, "0x%.8x\n", u32); | |
507 | RT2X00DEBUGFS_OPS(eeprom, "0x%.4x\n", u16); | |
508 | RT2X00DEBUGFS_OPS(bbp, "0x%.2x\n", u8); | |
509 | RT2X00DEBUGFS_OPS(rf, "0x%.8x\n", u32); | |
510 | ||
643b2521 ID |
511 | static ssize_t rt2x00debug_read_dev_flags(struct file *file, |
512 | char __user *buf, | |
513 | size_t length, | |
514 | loff_t *offset) | |
515 | { | |
516 | struct rt2x00debug_intf *intf = file->private_data; | |
517 | char line[16]; | |
518 | size_t size; | |
519 | ||
520 | if (*offset) | |
521 | return 0; | |
522 | ||
523 | size = sprintf(line, "0x%.8x\n", (unsigned int)intf->rt2x00dev->flags); | |
524 | ||
525 | if (copy_to_user(buf, line, size)) | |
526 | return -EFAULT; | |
527 | ||
528 | *offset += size; | |
529 | return size; | |
530 | } | |
531 | ||
532 | static const struct file_operations rt2x00debug_fop_dev_flags = { | |
533 | .owner = THIS_MODULE, | |
534 | .read = rt2x00debug_read_dev_flags, | |
535 | .open = rt2x00debug_file_open, | |
536 | .release = rt2x00debug_file_release, | |
537 | }; | |
538 | ||
95ea3627 ID |
539 | static struct dentry *rt2x00debug_create_file_driver(const char *name, |
540 | struct rt2x00debug_intf | |
541 | *intf, | |
542 | struct debugfs_blob_wrapper | |
543 | *blob) | |
544 | { | |
545 | char *data; | |
546 | ||
68598d29 | 547 | data = kzalloc(3 * MAX_LINE_LENGTH, GFP_KERNEL); |
95ea3627 ID |
548 | if (!data) |
549 | return NULL; | |
550 | ||
551 | blob->data = data; | |
860559fe ID |
552 | data += sprintf(data, "driver:\t%s\n", intf->rt2x00dev->ops->name); |
553 | data += sprintf(data, "version:\t%s\n", DRV_VERSION); | |
554 | data += sprintf(data, "compiled:\t%s %s\n", __DATE__, __TIME__); | |
95ea3627 ID |
555 | blob->size = strlen(blob->data); |
556 | ||
d2b69071 | 557 | return debugfs_create_blob(name, S_IRUSR, intf->driver_folder, blob); |
95ea3627 ID |
558 | } |
559 | ||
560 | static struct dentry *rt2x00debug_create_file_chipset(const char *name, | |
561 | struct rt2x00debug_intf | |
562 | *intf, | |
563 | struct | |
564 | debugfs_blob_wrapper | |
565 | *blob) | |
566 | { | |
567 | const struct rt2x00debug *debug = intf->debug; | |
568 | char *data; | |
569 | ||
68598d29 | 570 | data = kzalloc(8 * MAX_LINE_LENGTH, GFP_KERNEL); |
95ea3627 ID |
571 | if (!data) |
572 | return NULL; | |
573 | ||
3e34c6dc | 574 | blob->data = data; |
860559fe ID |
575 | data += sprintf(data, "rt chip:\t%04x\n", intf->rt2x00dev->chip.rt); |
576 | data += sprintf(data, "rf chip:\t%04x\n", intf->rt2x00dev->chip.rf); | |
49e721ec | 577 | data += sprintf(data, "revision:\t%04x\n", intf->rt2x00dev->chip.rev); |
22c96c28 | 578 | data += sprintf(data, "\n"); |
860559fe ID |
579 | data += sprintf(data, "register\tbase\twords\twordsize\n"); |
580 | data += sprintf(data, "csr\t%d\t%d\t%d\n", | |
581 | debug->csr.word_base, | |
582 | debug->csr.word_count, | |
583 | debug->csr.word_size); | |
584 | data += sprintf(data, "eeprom\t%d\t%d\t%d\n", | |
585 | debug->eeprom.word_base, | |
586 | debug->eeprom.word_count, | |
587 | debug->eeprom.word_size); | |
588 | data += sprintf(data, "bbp\t%d\t%d\t%d\n", | |
589 | debug->bbp.word_base, | |
590 | debug->bbp.word_count, | |
591 | debug->bbp.word_size); | |
592 | data += sprintf(data, "rf\t%d\t%d\t%d\n", | |
593 | debug->rf.word_base, | |
594 | debug->rf.word_count, | |
595 | debug->rf.word_size); | |
3e34c6dc | 596 | blob->size = strlen(blob->data); |
95ea3627 | 597 | |
d2b69071 | 598 | return debugfs_create_blob(name, S_IRUSR, intf->driver_folder, blob); |
95ea3627 ID |
599 | } |
600 | ||
601 | void rt2x00debug_register(struct rt2x00_dev *rt2x00dev) | |
602 | { | |
603 | const struct rt2x00debug *debug = rt2x00dev->ops->debugfs; | |
604 | struct rt2x00debug_intf *intf; | |
605 | ||
606 | intf = kzalloc(sizeof(struct rt2x00debug_intf), GFP_KERNEL); | |
607 | if (!intf) { | |
608 | ERROR(rt2x00dev, "Failed to allocate debug handler.\n"); | |
609 | return; | |
610 | } | |
611 | ||
612 | intf->debug = debug; | |
613 | intf->rt2x00dev = rt2x00dev; | |
614 | rt2x00dev->debugfs_intf = intf; | |
615 | ||
616 | intf->driver_folder = | |
617 | debugfs_create_dir(intf->rt2x00dev->ops->name, | |
618 | rt2x00dev->hw->wiphy->debugfsdir); | |
cfa3fa40 | 619 | if (IS_ERR(intf->driver_folder) || !intf->driver_folder) |
95ea3627 ID |
620 | goto exit; |
621 | ||
622 | intf->driver_entry = | |
623 | rt2x00debug_create_file_driver("driver", intf, &intf->driver_blob); | |
cfa3fa40 | 624 | if (IS_ERR(intf->driver_entry) || !intf->driver_entry) |
95ea3627 ID |
625 | goto exit; |
626 | ||
627 | intf->chipset_entry = | |
628 | rt2x00debug_create_file_chipset("chipset", | |
629 | intf, &intf->chipset_blob); | |
cfa3fa40 | 630 | if (IS_ERR(intf->chipset_entry) || !intf->chipset_entry) |
95ea3627 ID |
631 | goto exit; |
632 | ||
d2b69071 | 633 | intf->dev_flags = debugfs_create_file("dev_flags", S_IRUSR, |
643b2521 ID |
634 | intf->driver_folder, intf, |
635 | &rt2x00debug_fop_dev_flags); | |
cfa3fa40 | 636 | if (IS_ERR(intf->dev_flags) || !intf->dev_flags) |
643b2521 ID |
637 | goto exit; |
638 | ||
91921a4e ID |
639 | intf->register_folder = |
640 | debugfs_create_dir("register", intf->driver_folder); | |
cfa3fa40 | 641 | if (IS_ERR(intf->register_folder) || !intf->register_folder) |
91921a4e ID |
642 | goto exit; |
643 | ||
644 | #define RT2X00DEBUGFS_CREATE_REGISTER_ENTRY(__intf, __name) \ | |
95ea3627 ID |
645 | ({ \ |
646 | (__intf)->__name##_off_entry = \ | |
647 | debugfs_create_u32(__stringify(__name) "_offset", \ | |
d2b69071 | 648 | S_IRUSR | S_IWUSR, \ |
91921a4e | 649 | (__intf)->register_folder, \ |
95ea3627 | 650 | &(__intf)->offset_##__name); \ |
cfa3fa40 Z |
651 | if (IS_ERR((__intf)->__name##_off_entry) \ |
652 | || !(__intf)->__name##_off_entry) \ | |
95ea3627 ID |
653 | goto exit; \ |
654 | \ | |
655 | (__intf)->__name##_val_entry = \ | |
656 | debugfs_create_file(__stringify(__name) "_value", \ | |
d2b69071 | 657 | S_IRUSR | S_IWUSR, \ |
91921a4e | 658 | (__intf)->register_folder, \ |
95ea3627 | 659 | (__intf), &rt2x00debug_fop_##__name);\ |
cfa3fa40 Z |
660 | if (IS_ERR((__intf)->__name##_val_entry) \ |
661 | || !(__intf)->__name##_val_entry) \ | |
95ea3627 ID |
662 | goto exit; \ |
663 | }) | |
664 | ||
91921a4e ID |
665 | RT2X00DEBUGFS_CREATE_REGISTER_ENTRY(intf, csr); |
666 | RT2X00DEBUGFS_CREATE_REGISTER_ENTRY(intf, eeprom); | |
667 | RT2X00DEBUGFS_CREATE_REGISTER_ENTRY(intf, bbp); | |
668 | RT2X00DEBUGFS_CREATE_REGISTER_ENTRY(intf, rf); | |
95ea3627 | 669 | |
91921a4e | 670 | #undef RT2X00DEBUGFS_CREATE_REGISTER_ENTRY |
95ea3627 | 671 | |
68598d29 ID |
672 | intf->queue_folder = |
673 | debugfs_create_dir("queue", intf->driver_folder); | |
cfa3fa40 | 674 | if (IS_ERR(intf->queue_folder) || !intf->queue_folder) |
4d8dd66c ID |
675 | goto exit; |
676 | ||
68598d29 | 677 | intf->queue_frame_dump_entry = |
d2b69071 | 678 | debugfs_create_file("dump", S_IRUSR, intf->queue_folder, |
181d6902 | 679 | intf, &rt2x00debug_fop_queue_dump); |
cfa3fa40 Z |
680 | if (IS_ERR(intf->queue_frame_dump_entry) |
681 | || !intf->queue_frame_dump_entry) | |
4d8dd66c ID |
682 | goto exit; |
683 | ||
684 | skb_queue_head_init(&intf->frame_dump_skbqueue); | |
685 | init_waitqueue_head(&intf->frame_dump_waitqueue); | |
686 | ||
68598d29 | 687 | intf->queue_stats_entry = |
d2b69071 | 688 | debugfs_create_file("queue", S_IRUSR, intf->queue_folder, |
68598d29 ID |
689 | intf, &rt2x00debug_fop_queue_stats); |
690 | ||
2bb057d0 ID |
691 | #ifdef CONFIG_RT2X00_LIB_CRYPTO |
692 | if (test_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags)) | |
693 | intf->crypto_stats_entry = | |
694 | debugfs_create_file("crypto", S_IRUGO, intf->queue_folder, | |
695 | intf, &rt2x00debug_fop_crypto_stats); | |
696 | #endif | |
697 | ||
95ea3627 ID |
698 | return; |
699 | ||
700 | exit: | |
701 | rt2x00debug_deregister(rt2x00dev); | |
702 | ERROR(rt2x00dev, "Failed to register debug handler.\n"); | |
95ea3627 ID |
703 | } |
704 | ||
705 | void rt2x00debug_deregister(struct rt2x00_dev *rt2x00dev) | |
706 | { | |
4d8dd66c | 707 | struct rt2x00debug_intf *intf = rt2x00dev->debugfs_intf; |
95ea3627 ID |
708 | |
709 | if (unlikely(!intf)) | |
710 | return; | |
711 | ||
4d8dd66c ID |
712 | skb_queue_purge(&intf->frame_dump_skbqueue); |
713 | ||
2bb057d0 ID |
714 | #ifdef CONFIG_RT2X00_LIB_CRYPTO |
715 | debugfs_remove(intf->crypto_stats_entry); | |
716 | #endif | |
68598d29 ID |
717 | debugfs_remove(intf->queue_stats_entry); |
718 | debugfs_remove(intf->queue_frame_dump_entry); | |
719 | debugfs_remove(intf->queue_folder); | |
95ea3627 ID |
720 | debugfs_remove(intf->rf_val_entry); |
721 | debugfs_remove(intf->rf_off_entry); | |
722 | debugfs_remove(intf->bbp_val_entry); | |
723 | debugfs_remove(intf->bbp_off_entry); | |
724 | debugfs_remove(intf->eeprom_val_entry); | |
725 | debugfs_remove(intf->eeprom_off_entry); | |
726 | debugfs_remove(intf->csr_val_entry); | |
727 | debugfs_remove(intf->csr_off_entry); | |
91921a4e | 728 | debugfs_remove(intf->register_folder); |
643b2521 | 729 | debugfs_remove(intf->dev_flags); |
95ea3627 ID |
730 | debugfs_remove(intf->chipset_entry); |
731 | debugfs_remove(intf->driver_entry); | |
732 | debugfs_remove(intf->driver_folder); | |
733 | kfree(intf->chipset_blob.data); | |
734 | kfree(intf->driver_blob.data); | |
735 | kfree(intf); | |
736 | ||
737 | rt2x00dev->debugfs_intf = NULL; | |
738 | } |