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