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