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