Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1 | /* |
Ivo van Doorn | 811aa9c | 2008-02-03 15:42:53 +0100 | [diff] [blame] | 2 | Copyright (C) 2004 - 2008 rt2x00 SourceForge Project |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 3 | <http://rt2x00.serialmonkey.com> |
| 4 | |
| 5 | This program is free software; you can redistribute it and/or modify |
| 6 | it under the terms of the GNU General Public License as published by |
| 7 | the Free Software Foundation; either version 2 of the License, or |
| 8 | (at your option) any later version. |
| 9 | |
| 10 | This program is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | GNU General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License |
| 16 | along with this program; if not, write to the |
| 17 | Free Software Foundation, Inc., |
| 18 | 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 19 | */ |
| 20 | |
| 21 | /* |
| 22 | Module: rt2x00usb |
| 23 | Abstract: Data structures for the rt2x00usb module. |
| 24 | */ |
| 25 | |
| 26 | #ifndef RT2X00USB_H |
| 27 | #define RT2X00USB_H |
| 28 | |
Ivo van Doorn | c1d35df | 2008-06-16 19:57:11 +0200 | [diff] [blame] | 29 | #define to_usb_device_intf(d) \ |
| 30 | ({ \ |
| 31 | struct usb_interface *intf = to_usb_interface(d); \ |
| 32 | interface_to_usbdev(intf); \ |
| 33 | }) |
| 34 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 35 | /* |
| 36 | * This variable should be used with the |
| 37 | * usb_driver structure initialization. |
| 38 | */ |
| 39 | #define USB_DEVICE_DATA(__ops) .driver_info = (kernel_ulong_t)(__ops) |
| 40 | |
| 41 | /* |
| 42 | * Register defines. |
| 43 | * Some registers require multiple attempts before success, |
| 44 | * in those cases REGISTER_BUSY_COUNT attempts should be |
| 45 | * taken with a REGISTER_BUSY_DELAY interval. |
| 46 | * For USB vendor requests we need to pass a timeout |
| 47 | * time in ms, for this we use the REGISTER_TIMEOUT, |
| 48 | * however when loading firmware a higher value is |
| 49 | * required. In that case we use the REGISTER_TIMEOUT_FIRMWARE. |
| 50 | */ |
| 51 | #define REGISTER_BUSY_COUNT 5 |
| 52 | #define REGISTER_BUSY_DELAY 100 |
Ivo van Doorn | e913655 | 2007-09-25 20:54:20 +0200 | [diff] [blame] | 53 | #define REGISTER_TIMEOUT 500 |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 54 | #define REGISTER_TIMEOUT_FIRMWARE 1000 |
| 55 | |
Ivo van Doorn | bd394a7 | 2008-04-21 19:01:58 +0200 | [diff] [blame] | 56 | /** |
| 57 | * REGISTER_TIMEOUT16 - Determine the timeout for 16bit register access |
| 58 | * @__datalen: Data length |
| 59 | */ |
| 60 | #define REGISTER_TIMEOUT16(__datalen) \ |
| 61 | ( REGISTER_TIMEOUT * ((__datalen) / sizeof(u16)) ) |
| 62 | |
| 63 | /** |
| 64 | * REGISTER_TIMEOUT32 - Determine the timeout for 32bit register access |
| 65 | * @__datalen: Data length |
| 66 | */ |
| 67 | #define REGISTER_TIMEOUT32(__datalen) \ |
| 68 | ( REGISTER_TIMEOUT * ((__datalen) / sizeof(u32)) ) |
| 69 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 70 | /* |
| 71 | * Cache size |
| 72 | */ |
Iwo Mergler | ed0dbee | 2008-07-19 16:16:54 +0200 | [diff] [blame] | 73 | #define CSR_CACHE_SIZE 64 |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 74 | |
| 75 | /* |
| 76 | * USB request types. |
| 77 | */ |
| 78 | #define USB_VENDOR_REQUEST ( USB_TYPE_VENDOR | USB_RECIP_DEVICE ) |
| 79 | #define USB_VENDOR_REQUEST_IN ( USB_DIR_IN | USB_VENDOR_REQUEST ) |
| 80 | #define USB_VENDOR_REQUEST_OUT ( USB_DIR_OUT | USB_VENDOR_REQUEST ) |
| 81 | |
Ivo van Doorn | 3b640f2 | 2008-02-03 15:54:11 +0100 | [diff] [blame] | 82 | /** |
| 83 | * enum rt2x00usb_vendor_request: USB vendor commands. |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 84 | */ |
Ivo van Doorn | 3b640f2 | 2008-02-03 15:54:11 +0100 | [diff] [blame] | 85 | enum rt2x00usb_vendor_request { |
| 86 | USB_DEVICE_MODE = 1, |
| 87 | USB_SINGLE_WRITE = 2, |
| 88 | USB_SINGLE_READ = 3, |
| 89 | USB_MULTI_WRITE = 6, |
| 90 | USB_MULTI_READ = 7, |
| 91 | USB_EEPROM_WRITE = 8, |
| 92 | USB_EEPROM_READ = 9, |
| 93 | USB_LED_CONTROL = 10, /* RT73USB */ |
| 94 | USB_RX_CONTROL = 12, |
| 95 | }; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 96 | |
Ivo van Doorn | 3b640f2 | 2008-02-03 15:54:11 +0100 | [diff] [blame] | 97 | /** |
| 98 | * enum rt2x00usb_mode_offset: Device modes offset. |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 99 | */ |
Ivo van Doorn | 3b640f2 | 2008-02-03 15:54:11 +0100 | [diff] [blame] | 100 | enum rt2x00usb_mode_offset { |
| 101 | USB_MODE_RESET = 1, |
| 102 | USB_MODE_UNPLUG = 2, |
| 103 | USB_MODE_FUNCTION = 3, |
| 104 | USB_MODE_TEST = 4, |
| 105 | USB_MODE_SLEEP = 7, /* RT73USB */ |
| 106 | USB_MODE_FIRMWARE = 8, /* RT73USB */ |
| 107 | USB_MODE_WAKEUP = 9, /* RT73USB */ |
| 108 | }; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 109 | |
Ivo van Doorn | 3b640f2 | 2008-02-03 15:54:11 +0100 | [diff] [blame] | 110 | /** |
| 111 | * rt2x00usb_vendor_request - Send register command to device |
| 112 | * @rt2x00dev: Pointer to &struct rt2x00_dev |
| 113 | * @request: USB vendor command (See &enum rt2x00usb_vendor_request) |
| 114 | * @requesttype: Request type &USB_VENDOR_REQUEST_* |
| 115 | * @offset: Register offset to perform action on |
| 116 | * @value: Value to write to device |
| 117 | * @buffer: Buffer where information will be read/written to by device |
| 118 | * @buffer_length: Size of &buffer |
| 119 | * @timeout: Operation timeout |
| 120 | * |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 121 | * This is the main function to communicate with the device, |
Ivo van Doorn | 3b640f2 | 2008-02-03 15:54:11 +0100 | [diff] [blame] | 122 | * the &buffer argument _must_ either be NULL or point to |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 123 | * a buffer allocated by kmalloc. Failure to do so can lead |
| 124 | * to unexpected behavior depending on the architecture. |
| 125 | */ |
Adam Baker | 0e14f6d | 2007-10-27 13:41:25 +0200 | [diff] [blame] | 126 | int rt2x00usb_vendor_request(struct rt2x00_dev *rt2x00dev, |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 127 | const u8 request, const u8 requesttype, |
| 128 | const u16 offset, const u16 value, |
| 129 | void *buffer, const u16 buffer_length, |
Ivo van Doorn | e913655 | 2007-09-25 20:54:20 +0200 | [diff] [blame] | 130 | const int timeout); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 131 | |
Ivo van Doorn | 3b640f2 | 2008-02-03 15:54:11 +0100 | [diff] [blame] | 132 | /** |
| 133 | * rt2x00usb_vendor_request_buff - Send register command to device (buffered) |
| 134 | * @rt2x00dev: Pointer to &struct rt2x00_dev |
| 135 | * @request: USB vendor command (See &enum rt2x00usb_vendor_request) |
| 136 | * @requesttype: Request type &USB_VENDOR_REQUEST_* |
| 137 | * @offset: Register offset to perform action on |
| 138 | * @buffer: Buffer where information will be read/written to by device |
| 139 | * @buffer_length: Size of &buffer |
| 140 | * @timeout: Operation timeout |
| 141 | * |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 142 | * This function will use a previously with kmalloc allocated cache |
| 143 | * to communicate with the device. The contents of the buffer pointer |
| 144 | * will be copied to this cache when writing, or read from the cache |
| 145 | * when reading. |
Ivo van Doorn | 3b640f2 | 2008-02-03 15:54:11 +0100 | [diff] [blame] | 146 | * Buffers send to &rt2x00usb_vendor_request _must_ be allocated with |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 147 | * kmalloc. Hence the reason for using a previously allocated cache |
| 148 | * which has been allocated properly. |
| 149 | */ |
Adam Baker | 0e14f6d | 2007-10-27 13:41:25 +0200 | [diff] [blame] | 150 | int rt2x00usb_vendor_request_buff(struct rt2x00_dev *rt2x00dev, |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 151 | const u8 request, const u8 requesttype, |
| 152 | const u16 offset, void *buffer, |
Ivo van Doorn | e913655 | 2007-09-25 20:54:20 +0200 | [diff] [blame] | 153 | const u16 buffer_length, const int timeout); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 154 | |
Ivo van Doorn | 3b640f2 | 2008-02-03 15:54:11 +0100 | [diff] [blame] | 155 | /** |
| 156 | * rt2x00usb_vendor_request_buff - Send register command to device (buffered) |
| 157 | * @rt2x00dev: Pointer to &struct rt2x00_dev |
| 158 | * @request: USB vendor command (See &enum rt2x00usb_vendor_request) |
| 159 | * @requesttype: Request type &USB_VENDOR_REQUEST_* |
| 160 | * @offset: Register offset to perform action on |
| 161 | * @buffer: Buffer where information will be read/written to by device |
| 162 | * @buffer_length: Size of &buffer |
| 163 | * @timeout: Operation timeout |
| 164 | * |
| 165 | * A version of &rt2x00usb_vendor_request_buff which must be called |
| 166 | * if the usb_cache_mutex is already held. |
| 167 | */ |
Adam Baker | 3d82346 | 2007-10-27 13:43:29 +0200 | [diff] [blame] | 168 | int rt2x00usb_vendor_req_buff_lock(struct rt2x00_dev *rt2x00dev, |
| 169 | const u8 request, const u8 requesttype, |
| 170 | const u16 offset, void *buffer, |
| 171 | const u16 buffer_length, const int timeout); |
| 172 | |
Ivo van Doorn | 3b640f2 | 2008-02-03 15:54:11 +0100 | [diff] [blame] | 173 | /** |
Iwo Mergler | ed0dbee | 2008-07-19 16:16:54 +0200 | [diff] [blame] | 174 | * rt2x00usb_vendor_request_large_buff - Send register command to device (buffered) |
| 175 | * @rt2x00dev: Pointer to &struct rt2x00_dev |
| 176 | * @request: USB vendor command (See &enum rt2x00usb_vendor_request) |
| 177 | * @requesttype: Request type &USB_VENDOR_REQUEST_* |
| 178 | * @offset: Register start offset to perform action on |
| 179 | * @buffer: Buffer where information will be read/written to by device |
| 180 | * @buffer_length: Size of &buffer |
| 181 | * @timeout: Operation timeout |
| 182 | * |
| 183 | * This function is used to transfer register data in blocks larger |
| 184 | * then CSR_CACHE_SIZE. Use for firmware upload, keys and beacons. |
| 185 | */ |
| 186 | int rt2x00usb_vendor_request_large_buff(struct rt2x00_dev *rt2x00dev, |
| 187 | const u8 request, const u8 requesttype, |
| 188 | const u16 offset, void *buffer, |
| 189 | const u16 buffer_length, |
| 190 | const int timeout); |
| 191 | |
| 192 | /** |
Ivo van Doorn | 3b640f2 | 2008-02-03 15:54:11 +0100 | [diff] [blame] | 193 | * rt2x00usb_vendor_request_sw - Send single register command to device |
| 194 | * @rt2x00dev: Pointer to &struct rt2x00_dev |
| 195 | * @request: USB vendor command (See &enum rt2x00usb_vendor_request) |
| 196 | * @offset: Register offset to perform action on |
| 197 | * @value: Value to write to device |
| 198 | * @timeout: Operation timeout |
| 199 | * |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 200 | * Simple wrapper around rt2x00usb_vendor_request to write a single |
| 201 | * command to the device. Since we don't use the buffer argument we |
| 202 | * don't have to worry about kmalloc here. |
| 203 | */ |
Adam Baker | 0e14f6d | 2007-10-27 13:41:25 +0200 | [diff] [blame] | 204 | static inline int rt2x00usb_vendor_request_sw(struct rt2x00_dev *rt2x00dev, |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 205 | const u8 request, |
| 206 | const u16 offset, |
| 207 | const u16 value, |
Ivo van Doorn | e913655 | 2007-09-25 20:54:20 +0200 | [diff] [blame] | 208 | const int timeout) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 209 | { |
| 210 | return rt2x00usb_vendor_request(rt2x00dev, request, |
| 211 | USB_VENDOR_REQUEST_OUT, offset, |
| 212 | value, NULL, 0, timeout); |
| 213 | } |
| 214 | |
Ivo van Doorn | 3b640f2 | 2008-02-03 15:54:11 +0100 | [diff] [blame] | 215 | /** |
| 216 | * rt2x00usb_eeprom_read - Read eeprom from device |
| 217 | * @rt2x00dev: Pointer to &struct rt2x00_dev |
| 218 | * @eeprom: Pointer to eeprom array to store the information in |
| 219 | * @length: Number of bytes to read from the eeprom |
| 220 | * |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 221 | * Simple wrapper around rt2x00usb_vendor_request to read the eeprom |
| 222 | * from the device. Note that the eeprom argument _must_ be allocated using |
| 223 | * kmalloc for correct handling inside the kernel USB layer. |
| 224 | */ |
Adam Baker | 0e14f6d | 2007-10-27 13:41:25 +0200 | [diff] [blame] | 225 | static inline int rt2x00usb_eeprom_read(struct rt2x00_dev *rt2x00dev, |
Ivo van Doorn | 9a46d44 | 2008-04-21 19:02:17 +0200 | [diff] [blame] | 226 | __le16 *eeprom, const u16 length) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 227 | { |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 228 | return rt2x00usb_vendor_request(rt2x00dev, USB_EEPROM_READ, |
Ivo van Doorn | 3b640f2 | 2008-02-03 15:54:11 +0100 | [diff] [blame] | 229 | USB_VENDOR_REQUEST_IN, 0, 0, |
Ivo van Doorn | 9a46d44 | 2008-04-21 19:02:17 +0200 | [diff] [blame] | 230 | eeprom, length, |
| 231 | REGISTER_TIMEOUT16(length)); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | /* |
| 235 | * Radio handlers |
| 236 | */ |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 237 | void rt2x00usb_disable_radio(struct rt2x00_dev *rt2x00dev); |
| 238 | |
Ivo van Doorn | 6db3786 | 2008-06-06 22:50:28 +0200 | [diff] [blame] | 239 | /** |
| 240 | * rt2x00usb_write_tx_data - Initialize URB for TX operation |
| 241 | * @entry: The entry where the frame is located |
| 242 | * |
| 243 | * This function will initialize the URB and skb descriptor |
| 244 | * to prepare the entry for the actual TX operation. |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 245 | */ |
Ivo van Doorn | 6db3786 | 2008-06-06 22:50:28 +0200 | [diff] [blame] | 246 | int rt2x00usb_write_tx_data(struct queue_entry *entry); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 247 | |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 248 | /** |
Ivo van Doorn | b8be63f | 2008-05-10 13:46:03 +0200 | [diff] [blame] | 249 | * struct queue_entry_priv_usb: Per entry USB specific information |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 250 | * |
| 251 | * @urb: Urb structure used for device communication. |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 252 | */ |
Ivo van Doorn | b8be63f | 2008-05-10 13:46:03 +0200 | [diff] [blame] | 253 | struct queue_entry_priv_usb { |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 254 | struct urb *urb; |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 255 | }; |
| 256 | |
| 257 | /** |
Ivo van Doorn | b8be63f | 2008-05-10 13:46:03 +0200 | [diff] [blame] | 258 | * struct queue_entry_priv_usb_bcn: Per TX entry USB specific information |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 259 | * |
Ivo van Doorn | b8be63f | 2008-05-10 13:46:03 +0200 | [diff] [blame] | 260 | * The first section should match &struct queue_entry_priv_usb exactly. |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 261 | * rt2500usb can use this structure to send a guardian byte when working |
| 262 | * with beacons. |
| 263 | * |
| 264 | * @urb: Urb structure used for device communication. |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 265 | * @guardian_data: Set to 0, used for sending the guardian data. |
| 266 | * @guardian_urb: Urb structure used to send the guardian data. |
| 267 | */ |
| 268 | struct queue_entry_priv_usb_bcn { |
| 269 | struct urb *urb; |
| 270 | |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 271 | unsigned int guardian_data; |
| 272 | struct urb *guardian_urb; |
| 273 | }; |
| 274 | |
Ivo van Doorn | f019d51 | 2008-06-06 22:47:39 +0200 | [diff] [blame] | 275 | /** |
| 276 | * rt2x00usb_kick_tx_queue - Kick data queue |
| 277 | * @rt2x00dev: Pointer to &struct rt2x00_dev |
| 278 | * @qid: Data queue to kick |
| 279 | * |
| 280 | * This will walk through all entries of the queue and push all pending |
| 281 | * frames to the hardware as a single burst. |
| 282 | */ |
| 283 | void rt2x00usb_kick_tx_queue(struct rt2x00_dev *rt2x00dev, |
| 284 | const enum data_queue_qid qid); |
| 285 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 286 | /* |
| 287 | * Device initialization handlers. |
| 288 | */ |
Ivo van Doorn | 837e7f2 | 2008-01-06 23:41:45 +0100 | [diff] [blame] | 289 | void rt2x00usb_init_rxentry(struct rt2x00_dev *rt2x00dev, |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 290 | struct queue_entry *entry); |
Ivo van Doorn | 837e7f2 | 2008-01-06 23:41:45 +0100 | [diff] [blame] | 291 | void rt2x00usb_init_txentry(struct rt2x00_dev *rt2x00dev, |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 292 | struct queue_entry *entry); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 293 | int rt2x00usb_initialize(struct rt2x00_dev *rt2x00dev); |
| 294 | void rt2x00usb_uninitialize(struct rt2x00_dev *rt2x00dev); |
| 295 | |
| 296 | /* |
| 297 | * USB driver handlers. |
| 298 | */ |
| 299 | int rt2x00usb_probe(struct usb_interface *usb_intf, |
| 300 | const struct usb_device_id *id); |
| 301 | void rt2x00usb_disconnect(struct usb_interface *usb_intf); |
| 302 | #ifdef CONFIG_PM |
| 303 | int rt2x00usb_suspend(struct usb_interface *usb_intf, pm_message_t state); |
| 304 | int rt2x00usb_resume(struct usb_interface *usb_intf); |
| 305 | #else |
| 306 | #define rt2x00usb_suspend NULL |
| 307 | #define rt2x00usb_resume NULL |
| 308 | #endif /* CONFIG_PM */ |
| 309 | |
| 310 | #endif /* RT2X00USB_H */ |