Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1 | /* |
Gertjan van Wingerde | 9c9a0d1 | 2009-11-08 16:39:55 +0100 | [diff] [blame] | 2 | Copyright (C) 2004 - 2009 Ivo van Doorn <IvDoorn@gmail.com> |
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> |
Alexey Dobriyan | d43c36d | 2009-10-07 17:09:06 +0400 | [diff] [blame] | 30 | #include <linux/sched.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 31 | #include <linux/slab.h> |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 32 | #include <linux/uaccess.h> |
| 33 | |
| 34 | #include "rt2x00.h" |
| 35 | #include "rt2x00lib.h" |
Ivo van Doorn | 4d8dd66 | 2007-11-27 21:49:29 +0100 | [diff] [blame] | 36 | #include "rt2x00dump.h" |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 37 | |
Ivo van Doorn | 68598d29 | 2008-02-10 22:50:28 +0100 | [diff] [blame] | 38 | #define MAX_LINE_LENGTH 64 |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 39 | |
Ivo van Doorn | 2bb057d | 2008-08-04 16:37:44 +0200 | [diff] [blame] | 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 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 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 |
Ivo van Doorn | 91921a4 | 2007-11-27 21:48:16 +0100 | [diff] [blame] | 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 |
Ivo van Doorn | 68598d29 | 2008-02-10 22:50:28 +0100 | [diff] [blame] | 72 | * - queue folder |
Ivo van Doorn | 4d8dd66 | 2007-11-27 21:49:29 +0100 | [diff] [blame] | 73 | * - frame dump file |
Ivo van Doorn | 68598d29 | 2008-02-10 22:50:28 +0100 | [diff] [blame] | 74 | * - queue stats file |
Ivo van Doorn | 2bb057d | 2008-08-04 16:37:44 +0200 | [diff] [blame] | 75 | * - crypto stats file |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 76 | */ |
| 77 | struct dentry *driver_folder; |
| 78 | struct dentry *driver_entry; |
| 79 | struct dentry *chipset_entry; |
Ivo van Doorn | 643b252 | 2007-09-25 20:13:51 +0200 | [diff] [blame] | 80 | struct dentry *dev_flags; |
Ivo van Doorn | 91921a4 | 2007-11-27 21:48:16 +0100 | [diff] [blame] | 81 | struct dentry *register_folder; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 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; |
Ivo van Doorn | 68598d29 | 2008-02-10 22:50:28 +0100 | [diff] [blame] | 90 | struct dentry *queue_folder; |
| 91 | struct dentry *queue_frame_dump_entry; |
| 92 | struct dentry *queue_stats_entry; |
Ivo van Doorn | 2bb057d | 2008-08-04 16:37:44 +0200 | [diff] [blame] | 93 | struct dentry *crypto_stats_entry; |
Ivo van Doorn | 4d8dd66 | 2007-11-27 21:49:29 +0100 | [diff] [blame] | 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; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 110 | |
| 111 | /* |
Ivo van Doorn | 2bb057d | 2008-08-04 16:37:44 +0200 | [diff] [blame] | 112 | * HW crypto statistics. |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 113 | * All statistics are stored separately per cipher type. |
Ivo van Doorn | 2bb057d | 2008-08-04 16:37:44 +0200 | [diff] [blame] | 114 | */ |
| 115 | struct rt2x00debug_crypto crypto_stats[CIPHER_MAX]; |
| 116 | |
| 117 | /* |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 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 | |
Ivo van Doorn | 2bb057d | 2008-08-04 16:37:44 +0200 | [diff] [blame] | 134 | void rt2x00debug_update_crypto(struct rt2x00_dev *rt2x00dev, |
Ivo van Doorn | 84e3196 | 2008-12-20 10:53:29 +0100 | [diff] [blame] | 135 | struct rxdone_entry_desc *rxdesc) |
Ivo van Doorn | 2bb057d | 2008-08-04 16:37:44 +0200 | [diff] [blame] | 136 | { |
| 137 | struct rt2x00debug_intf *intf = rt2x00dev->debugfs_intf; |
Ivo van Doorn | 84e3196 | 2008-12-20 10:53:29 +0100 | [diff] [blame] | 138 | enum cipher cipher = rxdesc->cipher; |
| 139 | enum rx_crypto status = rxdesc->cipher_status; |
Ivo van Doorn | 2bb057d | 2008-08-04 16:37:44 +0200 | [diff] [blame] | 140 | |
| 141 | if (cipher == CIPHER_TKIP_NO_MIC) |
| 142 | cipher = CIPHER_TKIP; |
Roel Kluin | a6c6733 | 2009-05-20 02:12:56 +0200 | [diff] [blame] | 143 | if (cipher == CIPHER_NONE || cipher >= CIPHER_MAX) |
Ivo van Doorn | 2bb057d | 2008-08-04 16:37:44 +0200 | [diff] [blame] | 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 | |
Ivo van Doorn | 4d8dd66 | 2007-11-27 21:49:29 +0100 | [diff] [blame] | 155 | void rt2x00debug_dump_frame(struct rt2x00_dev *rt2x00dev, |
Ivo van Doorn | 5a6e599 | 2008-05-10 13:41:32 +0200 | [diff] [blame] | 156 | enum rt2x00_dump_type type, struct sk_buff *skb) |
Ivo van Doorn | 4d8dd66 | 2007-11-27 21:49:29 +0100 | [diff] [blame] | 157 | { |
| 158 | struct rt2x00debug_intf *intf = rt2x00dev->debugfs_intf; |
Gertjan van Wingerde | 878f704 | 2010-05-11 23:51:37 +0200 | [diff] [blame] | 159 | struct skb_frame_desc *skbdesc = get_skb_frame_desc(skb); |
Ivo van Doorn | 4d8dd66 | 2007-11-27 21:49:29 +0100 | [diff] [blame] | 160 | struct sk_buff *skbcopy; |
| 161 | struct rt2x00dump_hdr *dump_hdr; |
| 162 | struct timeval timestamp; |
Gertjan van Wingerde | fd76f14 | 2010-05-11 23:51:43 +0200 | [diff] [blame] | 163 | u32 data_len; |
Ivo van Doorn | 4d8dd66 | 2007-11-27 21:49:29 +0100 | [diff] [blame] | 164 | |
Helmut Schaa | e2f8c87 | 2010-11-04 20:38:56 +0100 | [diff] [blame] | 165 | if (likely(!test_bit(FRAME_DUMP_FILE_OPEN, &intf->frame_dump_flags))) |
Ivo van Doorn | 4d8dd66 | 2007-11-27 21:49:29 +0100 | [diff] [blame] | 166 | return; |
| 167 | |
Helmut Schaa | e2f8c87 | 2010-11-04 20:38:56 +0100 | [diff] [blame] | 168 | do_gettimeofday(×tamp); |
| 169 | |
Ivo van Doorn | 4d8dd66 | 2007-11-27 21:49:29 +0100 | [diff] [blame] | 170 | if (skb_queue_len(&intf->frame_dump_skbqueue) > 20) { |
| 171 | DEBUG(rt2x00dev, "txrx dump queue length exceeded.\n"); |
| 172 | return; |
| 173 | } |
| 174 | |
Gertjan van Wingerde | fd76f14 | 2010-05-11 23:51:43 +0200 | [diff] [blame] | 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, |
Ivo van Doorn | 4d8dd66 | 2007-11-27 21:49:29 +0100 | [diff] [blame] | 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)); |
Gertjan van Wingerde | 878f704 | 2010-05-11 23:51:37 +0200 | [diff] [blame] | 189 | dump_hdr->desc_length = cpu_to_le32(skbdesc->desc_len); |
Gertjan van Wingerde | fd76f14 | 2010-05-11 23:51:43 +0200 | [diff] [blame] | 190 | dump_hdr->data_length = cpu_to_le32(data_len); |
Ivo van Doorn | 4d8dd66 | 2007-11-27 21:49:29 +0100 | [diff] [blame] | 191 | dump_hdr->chip_rt = cpu_to_le16(rt2x00dev->chip.rt); |
| 192 | dump_hdr->chip_rf = cpu_to_le16(rt2x00dev->chip.rf); |
Gertjan van Wingerde | 49e721e | 2010-02-13 20:55:49 +0100 | [diff] [blame] | 193 | dump_hdr->chip_rev = cpu_to_le16(rt2x00dev->chip.rev); |
Ivo van Doorn | 5a6e599 | 2008-05-10 13:41:32 +0200 | [diff] [blame] | 194 | dump_hdr->type = cpu_to_le16(type); |
Gertjan van Wingerde | 878f704 | 2010-05-11 23:51:37 +0200 | [diff] [blame] | 195 | dump_hdr->queue_index = skbdesc->entry->queue->qid; |
| 196 | dump_hdr->entry_index = skbdesc->entry->entry_idx; |
Ivo van Doorn | 4d8dd66 | 2007-11-27 21:49:29 +0100 | [diff] [blame] | 197 | dump_hdr->timestamp_sec = cpu_to_le32(timestamp.tv_sec); |
| 198 | dump_hdr->timestamp_usec = cpu_to_le32(timestamp.tv_usec); |
| 199 | |
Gertjan van Wingerde | fd76f14 | 2010-05-11 23:51:43 +0200 | [diff] [blame] | 200 | if (!(skbdesc->flags & SKBDESC_DESC_IN_SKB)) |
| 201 | memcpy(skb_put(skbcopy, skbdesc->desc_len), skbdesc->desc, |
| 202 | skbdesc->desc_len); |
Gertjan van Wingerde | d56d453 | 2008-06-06 22:54:08 +0200 | [diff] [blame] | 203 | memcpy(skb_put(skbcopy, skb->len), skb->data, skb->len); |
Ivo van Doorn | 4d8dd66 | 2007-11-27 21:49:29 +0100 | [diff] [blame] | 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 | } |
Gertjan van Wingerde | b4df470 | 2010-05-13 13:16:36 +0200 | [diff] [blame] | 214 | EXPORT_SYMBOL_GPL(rt2x00debug_dump_frame); |
Ivo van Doorn | 4d8dd66 | 2007-11-27 21:49:29 +0100 | [diff] [blame] | 215 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 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 | |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 237 | 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] | 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 | |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 254 | 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] | 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 | |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 265 | static ssize_t rt2x00debug_read_queue_dump(struct file *file, |
| 266 | char __user *buf, |
| 267 | size_t length, |
| 268 | loff_t *offset) |
Ivo van Doorn | 4d8dd66 | 2007-11-27 21:49:29 +0100 | [diff] [blame] | 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 | |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 299 | static unsigned int rt2x00debug_poll_queue_dump(struct file *file, |
John Daiker | 5588751 | 2008-10-17 12:16:17 -0700 | [diff] [blame] | 300 | poll_table *wait) |
Ivo van Doorn | 4d8dd66 | 2007-11-27 21:49:29 +0100 | [diff] [blame] | 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 | |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 312 | static const struct file_operations rt2x00debug_fop_queue_dump = { |
Ivo van Doorn | 4d8dd66 | 2007-11-27 21:49:29 +0100 | [diff] [blame] | 313 | .owner = THIS_MODULE, |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 314 | .read = rt2x00debug_read_queue_dump, |
| 315 | .poll = rt2x00debug_poll_queue_dump, |
| 316 | .open = rt2x00debug_open_queue_dump, |
| 317 | .release = rt2x00debug_release_queue_dump, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 318 | .llseek = default_llseek, |
Ivo van Doorn | 4d8dd66 | 2007-11-27 21:49:29 +0100 | [diff] [blame] | 319 | }; |
| 320 | |
Ivo van Doorn | 68598d29 | 2008-02-10 22:50:28 +0100 | [diff] [blame] | 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; |
Ivo van Doorn | 5f46c4d | 2008-03-09 22:44:30 +0100 | [diff] [blame] | 328 | unsigned long irqflags; |
Ivo van Doorn | 68598d29 | 2008-02-10 22:50:28 +0100 | [diff] [blame] | 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 | |
Joe Perches | baeb2ff | 2010-08-11 07:02:48 +0000 | [diff] [blame] | 337 | data = kcalloc(lines, MAX_LINE_LENGTH, GFP_KERNEL); |
Ivo van Doorn | 68598d29 | 2008-02-10 22:50:28 +0100 | [diff] [blame] | 338 | if (!data) |
| 339 | return -ENOMEM; |
| 340 | |
| 341 | temp = data + |
Ivo van Doorn | 0b7fde5 | 2010-12-13 12:35:17 +0100 | [diff] [blame] | 342 | sprintf(data, "qid\tflags\t\tcount\tlimit\tlength\tindex\tdma done\tdone\n"); |
Ivo van Doorn | 68598d29 | 2008-02-10 22:50:28 +0100 | [diff] [blame] | 343 | |
| 344 | queue_for_each(intf->rt2x00dev, queue) { |
Ivo van Doorn | 813f033 | 2010-11-06 15:48:05 +0100 | [diff] [blame] | 345 | spin_lock_irqsave(&queue->index_lock, irqflags); |
Ivo van Doorn | 68598d29 | 2008-02-10 22:50:28 +0100 | [diff] [blame] | 346 | |
Ivo van Doorn | 0b7fde5 | 2010-12-13 12:35:17 +0100 | [diff] [blame] | 347 | temp += sprintf(temp, "%d\t0x%.8x\t%d\t%d\t%d\t%d\t%d\t\t%d\n", |
| 348 | queue->qid, (unsigned int)queue->flags, |
Ivo van Doorn | 68598d29 | 2008-02-10 22:50:28 +0100 | [diff] [blame] | 349 | queue->count, queue->limit, queue->length, |
| 350 | queue->index[Q_INDEX], |
Ivo van Doorn | 652a9dd | 2010-08-30 21:15:19 +0200 | [diff] [blame] | 351 | queue->index[Q_INDEX_DMA_DONE], |
Ivo van Doorn | 54e34fb | 2010-08-23 19:54:41 +0200 | [diff] [blame] | 352 | queue->index[Q_INDEX_DONE]); |
Ivo van Doorn | 68598d29 | 2008-02-10 22:50:28 +0100 | [diff] [blame] | 353 | |
Ivo van Doorn | 813f033 | 2010-11-06 15:48:05 +0100 | [diff] [blame] | 354 | spin_unlock_irqrestore(&queue->index_lock, irqflags); |
Ivo van Doorn | 68598d29 | 2008-02-10 22:50:28 +0100 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | size = strlen(data); |
| 358 | size = min(size, length); |
| 359 | |
| 360 | if (copy_to_user(buf, data, size)) { |
| 361 | kfree(data); |
| 362 | return -EFAULT; |
| 363 | } |
| 364 | |
| 365 | kfree(data); |
| 366 | |
| 367 | *offset += size; |
| 368 | return size; |
| 369 | } |
| 370 | |
| 371 | static const struct file_operations rt2x00debug_fop_queue_stats = { |
| 372 | .owner = THIS_MODULE, |
| 373 | .read = rt2x00debug_read_queue_stats, |
| 374 | .open = rt2x00debug_file_open, |
| 375 | .release = rt2x00debug_file_release, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 376 | .llseek = default_llseek, |
Ivo van Doorn | 68598d29 | 2008-02-10 22:50:28 +0100 | [diff] [blame] | 377 | }; |
| 378 | |
Ivo van Doorn | 2bb057d | 2008-08-04 16:37:44 +0200 | [diff] [blame] | 379 | #ifdef CONFIG_RT2X00_LIB_CRYPTO |
| 380 | static ssize_t rt2x00debug_read_crypto_stats(struct file *file, |
| 381 | char __user *buf, |
| 382 | size_t length, |
| 383 | loff_t *offset) |
| 384 | { |
| 385 | struct rt2x00debug_intf *intf = file->private_data; |
Joe Perches | 030bda0 | 2010-09-13 18:23:55 +0000 | [diff] [blame] | 386 | static const char * const name[] = { "WEP64", "WEP128", "TKIP", "AES" }; |
Ivo van Doorn | 2bb057d | 2008-08-04 16:37:44 +0200 | [diff] [blame] | 387 | char *data; |
| 388 | char *temp; |
| 389 | size_t size; |
| 390 | unsigned int i; |
| 391 | |
| 392 | if (*offset) |
| 393 | return 0; |
| 394 | |
John Daiker | 5588751 | 2008-10-17 12:16:17 -0700 | [diff] [blame] | 395 | data = kzalloc((1 + CIPHER_MAX) * MAX_LINE_LENGTH, GFP_KERNEL); |
Ivo van Doorn | 2bb057d | 2008-08-04 16:37:44 +0200 | [diff] [blame] | 396 | if (!data) |
| 397 | return -ENOMEM; |
| 398 | |
| 399 | temp = data; |
| 400 | temp += sprintf(data, "cipher\tsuccess\ticv err\tmic err\tkey err\n"); |
| 401 | |
| 402 | for (i = 0; i < CIPHER_MAX; i++) { |
| 403 | temp += sprintf(temp, "%s\t%lu\t%lu\t%lu\t%lu\n", name[i], |
| 404 | intf->crypto_stats[i].success, |
| 405 | intf->crypto_stats[i].icv_error, |
| 406 | intf->crypto_stats[i].mic_error, |
| 407 | intf->crypto_stats[i].key_error); |
| 408 | } |
| 409 | |
| 410 | size = strlen(data); |
| 411 | size = min(size, length); |
| 412 | |
| 413 | if (copy_to_user(buf, data, size)) { |
| 414 | kfree(data); |
| 415 | return -EFAULT; |
| 416 | } |
| 417 | |
| 418 | kfree(data); |
| 419 | |
| 420 | *offset += size; |
| 421 | return size; |
| 422 | } |
| 423 | |
| 424 | static const struct file_operations rt2x00debug_fop_crypto_stats = { |
| 425 | .owner = THIS_MODULE, |
| 426 | .read = rt2x00debug_read_crypto_stats, |
| 427 | .open = rt2x00debug_file_open, |
| 428 | .release = rt2x00debug_file_release, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 429 | .llseek = default_llseek, |
Ivo van Doorn | 2bb057d | 2008-08-04 16:37:44 +0200 | [diff] [blame] | 430 | }; |
| 431 | #endif |
| 432 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 433 | #define RT2X00DEBUGFS_OPS_READ(__name, __format, __type) \ |
| 434 | static ssize_t rt2x00debug_read_##__name(struct file *file, \ |
| 435 | char __user *buf, \ |
| 436 | size_t length, \ |
| 437 | loff_t *offset) \ |
| 438 | { \ |
Ivo van Doorn | 91921a4 | 2007-11-27 21:48:16 +0100 | [diff] [blame] | 439 | struct rt2x00debug_intf *intf = file->private_data; \ |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 440 | const struct rt2x00debug *debug = intf->debug; \ |
| 441 | char line[16]; \ |
| 442 | size_t size; \ |
Ivo van Doorn | 743b97c | 2008-10-29 19:41:03 +0100 | [diff] [blame] | 443 | unsigned int index = intf->offset_##__name; \ |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 444 | __type value; \ |
| 445 | \ |
| 446 | if (*offset) \ |
| 447 | return 0; \ |
| 448 | \ |
Ivo van Doorn | 743b97c | 2008-10-29 19:41:03 +0100 | [diff] [blame] | 449 | if (index >= debug->__name.word_count) \ |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 450 | return -EINVAL; \ |
| 451 | \ |
Ivo van Doorn | abd2fdb | 2009-02-17 14:04:29 +0100 | [diff] [blame] | 452 | index += (debug->__name.word_base / \ |
| 453 | debug->__name.word_size); \ |
| 454 | \ |
Ivo van Doorn | 743b97c | 2008-10-29 19:41:03 +0100 | [diff] [blame] | 455 | if (debug->__name.flags & RT2X00DEBUGFS_OFFSET) \ |
| 456 | index *= debug->__name.word_size; \ |
| 457 | \ |
Ivo van Doorn | 743b97c | 2008-10-29 19:41:03 +0100 | [diff] [blame] | 458 | debug->__name.read(intf->rt2x00dev, index, &value); \ |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 459 | \ |
| 460 | size = sprintf(line, __format, value); \ |
| 461 | \ |
| 462 | if (copy_to_user(buf, line, size)) \ |
| 463 | return -EFAULT; \ |
| 464 | \ |
| 465 | *offset += size; \ |
| 466 | return size; \ |
| 467 | } |
| 468 | |
| 469 | #define RT2X00DEBUGFS_OPS_WRITE(__name, __type) \ |
| 470 | static ssize_t rt2x00debug_write_##__name(struct file *file, \ |
| 471 | const char __user *buf,\ |
| 472 | size_t length, \ |
| 473 | loff_t *offset) \ |
| 474 | { \ |
Ivo van Doorn | 91921a4 | 2007-11-27 21:48:16 +0100 | [diff] [blame] | 475 | struct rt2x00debug_intf *intf = file->private_data; \ |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 476 | const struct rt2x00debug *debug = intf->debug; \ |
| 477 | char line[16]; \ |
| 478 | size_t size; \ |
Ivo van Doorn | 743b97c | 2008-10-29 19:41:03 +0100 | [diff] [blame] | 479 | unsigned int index = intf->offset_##__name; \ |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 480 | __type value; \ |
| 481 | \ |
| 482 | if (*offset) \ |
| 483 | return 0; \ |
| 484 | \ |
Ivo van Doorn | 743b97c | 2008-10-29 19:41:03 +0100 | [diff] [blame] | 485 | if (index >= debug->__name.word_count) \ |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 486 | return -EINVAL; \ |
| 487 | \ |
Arnaud Patard (Rtp) | f8d8b7a | 2010-08-23 23:02:22 +0200 | [diff] [blame] | 488 | if (length > sizeof(line)) \ |
| 489 | return -EINVAL; \ |
| 490 | \ |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 491 | if (copy_from_user(line, buf, length)) \ |
| 492 | return -EFAULT; \ |
| 493 | \ |
| 494 | size = strlen(line); \ |
| 495 | value = simple_strtoul(line, NULL, 0); \ |
| 496 | \ |
Ivo van Doorn | abd2fdb | 2009-02-17 14:04:29 +0100 | [diff] [blame] | 497 | index += (debug->__name.word_base / \ |
| 498 | debug->__name.word_size); \ |
| 499 | \ |
Ivo van Doorn | 743b97c | 2008-10-29 19:41:03 +0100 | [diff] [blame] | 500 | if (debug->__name.flags & RT2X00DEBUGFS_OFFSET) \ |
| 501 | index *= debug->__name.word_size; \ |
| 502 | \ |
Ivo van Doorn | 743b97c | 2008-10-29 19:41:03 +0100 | [diff] [blame] | 503 | debug->__name.write(intf->rt2x00dev, index, value); \ |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 504 | \ |
| 505 | *offset += size; \ |
| 506 | return size; \ |
| 507 | } |
| 508 | |
| 509 | #define RT2X00DEBUGFS_OPS(__name, __format, __type) \ |
| 510 | RT2X00DEBUGFS_OPS_READ(__name, __format, __type); \ |
| 511 | RT2X00DEBUGFS_OPS_WRITE(__name, __type); \ |
| 512 | \ |
| 513 | static const struct file_operations rt2x00debug_fop_##__name = {\ |
| 514 | .owner = THIS_MODULE, \ |
| 515 | .read = rt2x00debug_read_##__name, \ |
| 516 | .write = rt2x00debug_write_##__name, \ |
| 517 | .open = rt2x00debug_file_open, \ |
| 518 | .release = rt2x00debug_file_release, \ |
Arnd Bergmann | 2b18ab36 | 2010-07-06 19:05:31 +0200 | [diff] [blame] | 519 | .llseek = generic_file_llseek, \ |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 520 | }; |
| 521 | |
| 522 | RT2X00DEBUGFS_OPS(csr, "0x%.8x\n", u32); |
| 523 | RT2X00DEBUGFS_OPS(eeprom, "0x%.4x\n", u16); |
| 524 | RT2X00DEBUGFS_OPS(bbp, "0x%.2x\n", u8); |
| 525 | RT2X00DEBUGFS_OPS(rf, "0x%.8x\n", u32); |
| 526 | |
Ivo van Doorn | 643b252 | 2007-09-25 20:13:51 +0200 | [diff] [blame] | 527 | static ssize_t rt2x00debug_read_dev_flags(struct file *file, |
| 528 | char __user *buf, |
| 529 | size_t length, |
| 530 | loff_t *offset) |
| 531 | { |
| 532 | struct rt2x00debug_intf *intf = file->private_data; |
| 533 | char line[16]; |
| 534 | size_t size; |
| 535 | |
| 536 | if (*offset) |
| 537 | return 0; |
| 538 | |
| 539 | size = sprintf(line, "0x%.8x\n", (unsigned int)intf->rt2x00dev->flags); |
| 540 | |
| 541 | if (copy_to_user(buf, line, size)) |
| 542 | return -EFAULT; |
| 543 | |
| 544 | *offset += size; |
| 545 | return size; |
| 546 | } |
| 547 | |
| 548 | static const struct file_operations rt2x00debug_fop_dev_flags = { |
| 549 | .owner = THIS_MODULE, |
| 550 | .read = rt2x00debug_read_dev_flags, |
| 551 | .open = rt2x00debug_file_open, |
| 552 | .release = rt2x00debug_file_release, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 553 | .llseek = default_llseek, |
Ivo van Doorn | 643b252 | 2007-09-25 20:13:51 +0200 | [diff] [blame] | 554 | }; |
| 555 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 556 | static struct dentry *rt2x00debug_create_file_driver(const char *name, |
| 557 | struct rt2x00debug_intf |
| 558 | *intf, |
| 559 | struct debugfs_blob_wrapper |
| 560 | *blob) |
| 561 | { |
| 562 | char *data; |
| 563 | |
Ivo van Doorn | 68598d29 | 2008-02-10 22:50:28 +0100 | [diff] [blame] | 564 | data = kzalloc(3 * MAX_LINE_LENGTH, GFP_KERNEL); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 565 | if (!data) |
| 566 | return NULL; |
| 567 | |
| 568 | blob->data = data; |
Ivo van Doorn | 860559f | 2009-03-03 18:14:18 +0100 | [diff] [blame] | 569 | data += sprintf(data, "driver:\t%s\n", intf->rt2x00dev->ops->name); |
| 570 | data += sprintf(data, "version:\t%s\n", DRV_VERSION); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 571 | blob->size = strlen(blob->data); |
| 572 | |
Ivo van Doorn | d2b6907 | 2008-07-27 15:06:05 +0200 | [diff] [blame] | 573 | return debugfs_create_blob(name, S_IRUSR, intf->driver_folder, blob); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | static struct dentry *rt2x00debug_create_file_chipset(const char *name, |
| 577 | struct rt2x00debug_intf |
| 578 | *intf, |
| 579 | struct |
| 580 | debugfs_blob_wrapper |
| 581 | *blob) |
| 582 | { |
| 583 | const struct rt2x00debug *debug = intf->debug; |
| 584 | char *data; |
| 585 | |
Ivo van Doorn | 68598d29 | 2008-02-10 22:50:28 +0100 | [diff] [blame] | 586 | data = kzalloc(8 * MAX_LINE_LENGTH, GFP_KERNEL); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 587 | if (!data) |
| 588 | return NULL; |
| 589 | |
Ivo van Doorn | 3e34c6d | 2008-01-06 23:38:10 +0100 | [diff] [blame] | 590 | blob->data = data; |
Ivo van Doorn | 860559f | 2009-03-03 18:14:18 +0100 | [diff] [blame] | 591 | data += sprintf(data, "rt chip:\t%04x\n", intf->rt2x00dev->chip.rt); |
| 592 | data += sprintf(data, "rf chip:\t%04x\n", intf->rt2x00dev->chip.rf); |
Gertjan van Wingerde | 49e721e | 2010-02-13 20:55:49 +0100 | [diff] [blame] | 593 | data += sprintf(data, "revision:\t%04x\n", intf->rt2x00dev->chip.rev); |
Ivo van Doorn | 22c96c2 | 2007-11-27 21:48:37 +0100 | [diff] [blame] | 594 | data += sprintf(data, "\n"); |
Ivo van Doorn | 860559f | 2009-03-03 18:14:18 +0100 | [diff] [blame] | 595 | data += sprintf(data, "register\tbase\twords\twordsize\n"); |
| 596 | data += sprintf(data, "csr\t%d\t%d\t%d\n", |
| 597 | debug->csr.word_base, |
| 598 | debug->csr.word_count, |
| 599 | debug->csr.word_size); |
| 600 | data += sprintf(data, "eeprom\t%d\t%d\t%d\n", |
| 601 | debug->eeprom.word_base, |
| 602 | debug->eeprom.word_count, |
| 603 | debug->eeprom.word_size); |
| 604 | data += sprintf(data, "bbp\t%d\t%d\t%d\n", |
| 605 | debug->bbp.word_base, |
| 606 | debug->bbp.word_count, |
| 607 | debug->bbp.word_size); |
| 608 | data += sprintf(data, "rf\t%d\t%d\t%d\n", |
| 609 | debug->rf.word_base, |
| 610 | debug->rf.word_count, |
| 611 | debug->rf.word_size); |
Ivo van Doorn | 3e34c6d | 2008-01-06 23:38:10 +0100 | [diff] [blame] | 612 | blob->size = strlen(blob->data); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 613 | |
Ivo van Doorn | d2b6907 | 2008-07-27 15:06:05 +0200 | [diff] [blame] | 614 | return debugfs_create_blob(name, S_IRUSR, intf->driver_folder, blob); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | void rt2x00debug_register(struct rt2x00_dev *rt2x00dev) |
| 618 | { |
| 619 | const struct rt2x00debug *debug = rt2x00dev->ops->debugfs; |
| 620 | struct rt2x00debug_intf *intf; |
| 621 | |
| 622 | intf = kzalloc(sizeof(struct rt2x00debug_intf), GFP_KERNEL); |
| 623 | if (!intf) { |
| 624 | ERROR(rt2x00dev, "Failed to allocate debug handler.\n"); |
| 625 | return; |
| 626 | } |
| 627 | |
| 628 | intf->debug = debug; |
| 629 | intf->rt2x00dev = rt2x00dev; |
| 630 | rt2x00dev->debugfs_intf = intf; |
| 631 | |
| 632 | intf->driver_folder = |
| 633 | debugfs_create_dir(intf->rt2x00dev->ops->name, |
| 634 | rt2x00dev->hw->wiphy->debugfsdir); |
Zhaolei | cfa3fa4 | 2008-10-22 17:07:25 +0800 | [diff] [blame] | 635 | if (IS_ERR(intf->driver_folder) || !intf->driver_folder) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 636 | goto exit; |
| 637 | |
| 638 | intf->driver_entry = |
| 639 | rt2x00debug_create_file_driver("driver", intf, &intf->driver_blob); |
Zhaolei | cfa3fa4 | 2008-10-22 17:07:25 +0800 | [diff] [blame] | 640 | if (IS_ERR(intf->driver_entry) || !intf->driver_entry) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 641 | goto exit; |
| 642 | |
| 643 | intf->chipset_entry = |
| 644 | rt2x00debug_create_file_chipset("chipset", |
| 645 | intf, &intf->chipset_blob); |
Zhaolei | cfa3fa4 | 2008-10-22 17:07:25 +0800 | [diff] [blame] | 646 | if (IS_ERR(intf->chipset_entry) || !intf->chipset_entry) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 647 | goto exit; |
| 648 | |
Ivo van Doorn | d2b6907 | 2008-07-27 15:06:05 +0200 | [diff] [blame] | 649 | intf->dev_flags = debugfs_create_file("dev_flags", S_IRUSR, |
Ivo van Doorn | 643b252 | 2007-09-25 20:13:51 +0200 | [diff] [blame] | 650 | intf->driver_folder, intf, |
| 651 | &rt2x00debug_fop_dev_flags); |
Zhaolei | cfa3fa4 | 2008-10-22 17:07:25 +0800 | [diff] [blame] | 652 | if (IS_ERR(intf->dev_flags) || !intf->dev_flags) |
Ivo van Doorn | 643b252 | 2007-09-25 20:13:51 +0200 | [diff] [blame] | 653 | goto exit; |
| 654 | |
Ivo van Doorn | 91921a4 | 2007-11-27 21:48:16 +0100 | [diff] [blame] | 655 | intf->register_folder = |
| 656 | debugfs_create_dir("register", intf->driver_folder); |
Zhaolei | cfa3fa4 | 2008-10-22 17:07:25 +0800 | [diff] [blame] | 657 | if (IS_ERR(intf->register_folder) || !intf->register_folder) |
Ivo van Doorn | 91921a4 | 2007-11-27 21:48:16 +0100 | [diff] [blame] | 658 | goto exit; |
| 659 | |
| 660 | #define RT2X00DEBUGFS_CREATE_REGISTER_ENTRY(__intf, __name) \ |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 661 | ({ \ |
| 662 | (__intf)->__name##_off_entry = \ |
| 663 | debugfs_create_u32(__stringify(__name) "_offset", \ |
Ivo van Doorn | d2b6907 | 2008-07-27 15:06:05 +0200 | [diff] [blame] | 664 | S_IRUSR | S_IWUSR, \ |
Ivo van Doorn | 91921a4 | 2007-11-27 21:48:16 +0100 | [diff] [blame] | 665 | (__intf)->register_folder, \ |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 666 | &(__intf)->offset_##__name); \ |
Zhaolei | cfa3fa4 | 2008-10-22 17:07:25 +0800 | [diff] [blame] | 667 | if (IS_ERR((__intf)->__name##_off_entry) \ |
| 668 | || !(__intf)->__name##_off_entry) \ |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 669 | goto exit; \ |
| 670 | \ |
| 671 | (__intf)->__name##_val_entry = \ |
| 672 | debugfs_create_file(__stringify(__name) "_value", \ |
Ivo van Doorn | d2b6907 | 2008-07-27 15:06:05 +0200 | [diff] [blame] | 673 | S_IRUSR | S_IWUSR, \ |
Ivo van Doorn | 91921a4 | 2007-11-27 21:48:16 +0100 | [diff] [blame] | 674 | (__intf)->register_folder, \ |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 675 | (__intf), &rt2x00debug_fop_##__name);\ |
Zhaolei | cfa3fa4 | 2008-10-22 17:07:25 +0800 | [diff] [blame] | 676 | if (IS_ERR((__intf)->__name##_val_entry) \ |
| 677 | || !(__intf)->__name##_val_entry) \ |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 678 | goto exit; \ |
| 679 | }) |
| 680 | |
Ivo van Doorn | 91921a4 | 2007-11-27 21:48:16 +0100 | [diff] [blame] | 681 | RT2X00DEBUGFS_CREATE_REGISTER_ENTRY(intf, csr); |
| 682 | RT2X00DEBUGFS_CREATE_REGISTER_ENTRY(intf, eeprom); |
| 683 | RT2X00DEBUGFS_CREATE_REGISTER_ENTRY(intf, bbp); |
| 684 | RT2X00DEBUGFS_CREATE_REGISTER_ENTRY(intf, rf); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 685 | |
Ivo van Doorn | 91921a4 | 2007-11-27 21:48:16 +0100 | [diff] [blame] | 686 | #undef RT2X00DEBUGFS_CREATE_REGISTER_ENTRY |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 687 | |
Ivo van Doorn | 68598d29 | 2008-02-10 22:50:28 +0100 | [diff] [blame] | 688 | intf->queue_folder = |
| 689 | debugfs_create_dir("queue", intf->driver_folder); |
Zhaolei | cfa3fa4 | 2008-10-22 17:07:25 +0800 | [diff] [blame] | 690 | if (IS_ERR(intf->queue_folder) || !intf->queue_folder) |
Ivo van Doorn | 4d8dd66 | 2007-11-27 21:49:29 +0100 | [diff] [blame] | 691 | goto exit; |
| 692 | |
Ivo van Doorn | 68598d29 | 2008-02-10 22:50:28 +0100 | [diff] [blame] | 693 | intf->queue_frame_dump_entry = |
Ivo van Doorn | d2b6907 | 2008-07-27 15:06:05 +0200 | [diff] [blame] | 694 | debugfs_create_file("dump", S_IRUSR, intf->queue_folder, |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 695 | intf, &rt2x00debug_fop_queue_dump); |
Zhaolei | cfa3fa4 | 2008-10-22 17:07:25 +0800 | [diff] [blame] | 696 | if (IS_ERR(intf->queue_frame_dump_entry) |
| 697 | || !intf->queue_frame_dump_entry) |
Ivo van Doorn | 4d8dd66 | 2007-11-27 21:49:29 +0100 | [diff] [blame] | 698 | goto exit; |
| 699 | |
| 700 | skb_queue_head_init(&intf->frame_dump_skbqueue); |
| 701 | init_waitqueue_head(&intf->frame_dump_waitqueue); |
| 702 | |
Ivo van Doorn | 68598d29 | 2008-02-10 22:50:28 +0100 | [diff] [blame] | 703 | intf->queue_stats_entry = |
Ivo van Doorn | d2b6907 | 2008-07-27 15:06:05 +0200 | [diff] [blame] | 704 | debugfs_create_file("queue", S_IRUSR, intf->queue_folder, |
Ivo van Doorn | 68598d29 | 2008-02-10 22:50:28 +0100 | [diff] [blame] | 705 | intf, &rt2x00debug_fop_queue_stats); |
| 706 | |
Ivo van Doorn | 2bb057d | 2008-08-04 16:37:44 +0200 | [diff] [blame] | 707 | #ifdef CONFIG_RT2X00_LIB_CRYPTO |
| 708 | if (test_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags)) |
| 709 | intf->crypto_stats_entry = |
| 710 | debugfs_create_file("crypto", S_IRUGO, intf->queue_folder, |
| 711 | intf, &rt2x00debug_fop_crypto_stats); |
| 712 | #endif |
| 713 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 714 | return; |
| 715 | |
| 716 | exit: |
| 717 | rt2x00debug_deregister(rt2x00dev); |
| 718 | ERROR(rt2x00dev, "Failed to register debug handler.\n"); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | void rt2x00debug_deregister(struct rt2x00_dev *rt2x00dev) |
| 722 | { |
Ivo van Doorn | 4d8dd66 | 2007-11-27 21:49:29 +0100 | [diff] [blame] | 723 | struct rt2x00debug_intf *intf = rt2x00dev->debugfs_intf; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 724 | |
| 725 | if (unlikely(!intf)) |
| 726 | return; |
| 727 | |
Ivo van Doorn | 4d8dd66 | 2007-11-27 21:49:29 +0100 | [diff] [blame] | 728 | skb_queue_purge(&intf->frame_dump_skbqueue); |
| 729 | |
Ivo van Doorn | 2bb057d | 2008-08-04 16:37:44 +0200 | [diff] [blame] | 730 | #ifdef CONFIG_RT2X00_LIB_CRYPTO |
| 731 | debugfs_remove(intf->crypto_stats_entry); |
| 732 | #endif |
Ivo van Doorn | 68598d29 | 2008-02-10 22:50:28 +0100 | [diff] [blame] | 733 | debugfs_remove(intf->queue_stats_entry); |
| 734 | debugfs_remove(intf->queue_frame_dump_entry); |
| 735 | debugfs_remove(intf->queue_folder); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 736 | debugfs_remove(intf->rf_val_entry); |
| 737 | debugfs_remove(intf->rf_off_entry); |
| 738 | debugfs_remove(intf->bbp_val_entry); |
| 739 | debugfs_remove(intf->bbp_off_entry); |
| 740 | debugfs_remove(intf->eeprom_val_entry); |
| 741 | debugfs_remove(intf->eeprom_off_entry); |
| 742 | debugfs_remove(intf->csr_val_entry); |
| 743 | debugfs_remove(intf->csr_off_entry); |
Ivo van Doorn | 91921a4 | 2007-11-27 21:48:16 +0100 | [diff] [blame] | 744 | debugfs_remove(intf->register_folder); |
Ivo van Doorn | 643b252 | 2007-09-25 20:13:51 +0200 | [diff] [blame] | 745 | debugfs_remove(intf->dev_flags); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 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 | } |