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