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