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