]>
Commit | Line | Data |
---|---|---|
95ea3627 | 1 | /* |
9c9a0d14 | 2 | Copyright (C) 2004 - 2009 Ivo van Doorn <IvDoorn@gmail.com> |
95ea3627 ID |
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 | ||
ac9d1a7b GW |
29 | #include <linux/usb.h> |
30 | ||
c1d35dfa ID |
31 | #define to_usb_device_intf(d) \ |
32 | ({ \ | |
33 | struct usb_interface *intf = to_usb_interface(d); \ | |
34 | interface_to_usbdev(intf); \ | |
35 | }) | |
36 | ||
95ea3627 ID |
37 | /* |
38 | * This variable should be used with the | |
39 | * usb_driver structure initialization. | |
40 | */ | |
41 | #define USB_DEVICE_DATA(__ops) .driver_info = (kernel_ulong_t)(__ops) | |
42 | ||
43 | /* | |
95ea3627 ID |
44 | * For USB vendor requests we need to pass a timeout |
45 | * time in ms, for this we use the REGISTER_TIMEOUT, | |
46 | * however when loading firmware a higher value is | |
47 | * required. In that case we use the REGISTER_TIMEOUT_FIRMWARE. | |
48 | */ | |
e9136550 | 49 | #define REGISTER_TIMEOUT 500 |
95ea3627 ID |
50 | #define REGISTER_TIMEOUT_FIRMWARE 1000 |
51 | ||
bd394a74 ID |
52 | /** |
53 | * REGISTER_TIMEOUT16 - Determine the timeout for 16bit register access | |
54 | * @__datalen: Data length | |
55 | */ | |
56 | #define REGISTER_TIMEOUT16(__datalen) \ | |
57 | ( REGISTER_TIMEOUT * ((__datalen) / sizeof(u16)) ) | |
58 | ||
59 | /** | |
60 | * REGISTER_TIMEOUT32 - Determine the timeout for 32bit register access | |
61 | * @__datalen: Data length | |
62 | */ | |
63 | #define REGISTER_TIMEOUT32(__datalen) \ | |
64 | ( REGISTER_TIMEOUT * ((__datalen) / sizeof(u32)) ) | |
65 | ||
95ea3627 ID |
66 | /* |
67 | * Cache size | |
68 | */ | |
ed0dbeeb | 69 | #define CSR_CACHE_SIZE 64 |
95ea3627 ID |
70 | |
71 | /* | |
72 | * USB request types. | |
73 | */ | |
74 | #define USB_VENDOR_REQUEST ( USB_TYPE_VENDOR | USB_RECIP_DEVICE ) | |
75 | #define USB_VENDOR_REQUEST_IN ( USB_DIR_IN | USB_VENDOR_REQUEST ) | |
76 | #define USB_VENDOR_REQUEST_OUT ( USB_DIR_OUT | USB_VENDOR_REQUEST ) | |
77 | ||
3b640f21 ID |
78 | /** |
79 | * enum rt2x00usb_vendor_request: USB vendor commands. | |
95ea3627 | 80 | */ |
3b640f21 ID |
81 | enum rt2x00usb_vendor_request { |
82 | USB_DEVICE_MODE = 1, | |
83 | USB_SINGLE_WRITE = 2, | |
84 | USB_SINGLE_READ = 3, | |
85 | USB_MULTI_WRITE = 6, | |
86 | USB_MULTI_READ = 7, | |
87 | USB_EEPROM_WRITE = 8, | |
88 | USB_EEPROM_READ = 9, | |
89 | USB_LED_CONTROL = 10, /* RT73USB */ | |
90 | USB_RX_CONTROL = 12, | |
91 | }; | |
92 | ||
93 | /** | |
94 | * enum rt2x00usb_mode_offset: Device modes offset. | |
95 | */ | |
96 | enum rt2x00usb_mode_offset { | |
97 | USB_MODE_RESET = 1, | |
98 | USB_MODE_UNPLUG = 2, | |
99 | USB_MODE_FUNCTION = 3, | |
100 | USB_MODE_TEST = 4, | |
101 | USB_MODE_SLEEP = 7, /* RT73USB */ | |
102 | USB_MODE_FIRMWARE = 8, /* RT73USB */ | |
103 | USB_MODE_WAKEUP = 9, /* RT73USB */ | |
104 | }; | |
105 | ||
106 | /** | |
107 | * rt2x00usb_vendor_request - Send register command to device | |
108 | * @rt2x00dev: Pointer to &struct rt2x00_dev | |
109 | * @request: USB vendor command (See &enum rt2x00usb_vendor_request) | |
110 | * @requesttype: Request type &USB_VENDOR_REQUEST_* | |
111 | * @offset: Register offset to perform action on | |
112 | * @value: Value to write to device | |
113 | * @buffer: Buffer where information will be read/written to by device | |
114 | * @buffer_length: Size of &buffer | |
115 | * @timeout: Operation timeout | |
116 | * | |
95ea3627 | 117 | * This is the main function to communicate with the device, |
3b640f21 | 118 | * the &buffer argument _must_ either be NULL or point to |
95ea3627 ID |
119 | * a buffer allocated by kmalloc. Failure to do so can lead |
120 | * to unexpected behavior depending on the architecture. | |
121 | */ | |
0e14f6d3 | 122 | int rt2x00usb_vendor_request(struct rt2x00_dev *rt2x00dev, |
95ea3627 ID |
123 | const u8 request, const u8 requesttype, |
124 | const u16 offset, const u16 value, | |
125 | void *buffer, const u16 buffer_length, | |
e9136550 | 126 | const int timeout); |
95ea3627 | 127 | |
3b640f21 ID |
128 | /** |
129 | * rt2x00usb_vendor_request_buff - Send register command to device (buffered) | |
130 | * @rt2x00dev: Pointer to &struct rt2x00_dev | |
131 | * @request: USB vendor command (See &enum rt2x00usb_vendor_request) | |
132 | * @requesttype: Request type &USB_VENDOR_REQUEST_* | |
133 | * @offset: Register offset to perform action on | |
134 | * @buffer: Buffer where information will be read/written to by device | |
135 | * @buffer_length: Size of &buffer | |
136 | * @timeout: Operation timeout | |
137 | * | |
95ea3627 ID |
138 | * This function will use a previously with kmalloc allocated cache |
139 | * to communicate with the device. The contents of the buffer pointer | |
140 | * will be copied to this cache when writing, or read from the cache | |
141 | * when reading. | |
3b640f21 | 142 | * Buffers send to &rt2x00usb_vendor_request _must_ be allocated with |
95ea3627 ID |
143 | * kmalloc. Hence the reason for using a previously allocated cache |
144 | * which has been allocated properly. | |
145 | */ | |
0e14f6d3 | 146 | int rt2x00usb_vendor_request_buff(struct rt2x00_dev *rt2x00dev, |
95ea3627 ID |
147 | const u8 request, const u8 requesttype, |
148 | const u16 offset, void *buffer, | |
e9136550 | 149 | const u16 buffer_length, const int timeout); |
95ea3627 | 150 | |
3b640f21 ID |
151 | /** |
152 | * rt2x00usb_vendor_request_buff - Send register command to device (buffered) | |
153 | * @rt2x00dev: Pointer to &struct rt2x00_dev | |
154 | * @request: USB vendor command (See &enum rt2x00usb_vendor_request) | |
155 | * @requesttype: Request type &USB_VENDOR_REQUEST_* | |
156 | * @offset: Register offset to perform action on | |
157 | * @buffer: Buffer where information will be read/written to by device | |
158 | * @buffer_length: Size of &buffer | |
159 | * @timeout: Operation timeout | |
160 | * | |
161 | * A version of &rt2x00usb_vendor_request_buff which must be called | |
162 | * if the usb_cache_mutex is already held. | |
163 | */ | |
3d82346c AB |
164 | int rt2x00usb_vendor_req_buff_lock(struct rt2x00_dev *rt2x00dev, |
165 | const u8 request, const u8 requesttype, | |
166 | const u16 offset, void *buffer, | |
167 | const u16 buffer_length, const int timeout); | |
168 | ||
3b640f21 ID |
169 | /** |
170 | * rt2x00usb_vendor_request_sw - Send single register command to device | |
171 | * @rt2x00dev: Pointer to &struct rt2x00_dev | |
172 | * @request: USB vendor command (See &enum rt2x00usb_vendor_request) | |
173 | * @offset: Register offset to perform action on | |
174 | * @value: Value to write to device | |
175 | * @timeout: Operation timeout | |
176 | * | |
95ea3627 ID |
177 | * Simple wrapper around rt2x00usb_vendor_request to write a single |
178 | * command to the device. Since we don't use the buffer argument we | |
179 | * don't have to worry about kmalloc here. | |
180 | */ | |
0e14f6d3 | 181 | static inline int rt2x00usb_vendor_request_sw(struct rt2x00_dev *rt2x00dev, |
95ea3627 ID |
182 | const u8 request, |
183 | const u16 offset, | |
184 | const u16 value, | |
e9136550 | 185 | const int timeout) |
95ea3627 ID |
186 | { |
187 | return rt2x00usb_vendor_request(rt2x00dev, request, | |
188 | USB_VENDOR_REQUEST_OUT, offset, | |
189 | value, NULL, 0, timeout); | |
190 | } | |
191 | ||
3b640f21 ID |
192 | /** |
193 | * rt2x00usb_eeprom_read - Read eeprom from device | |
194 | * @rt2x00dev: Pointer to &struct rt2x00_dev | |
195 | * @eeprom: Pointer to eeprom array to store the information in | |
196 | * @length: Number of bytes to read from the eeprom | |
197 | * | |
95ea3627 ID |
198 | * Simple wrapper around rt2x00usb_vendor_request to read the eeprom |
199 | * from the device. Note that the eeprom argument _must_ be allocated using | |
200 | * kmalloc for correct handling inside the kernel USB layer. | |
201 | */ | |
0e14f6d3 | 202 | static inline int rt2x00usb_eeprom_read(struct rt2x00_dev *rt2x00dev, |
9a46d44e | 203 | __le16 *eeprom, const u16 length) |
95ea3627 | 204 | { |
95ea3627 | 205 | return rt2x00usb_vendor_request(rt2x00dev, USB_EEPROM_READ, |
3b640f21 | 206 | USB_VENDOR_REQUEST_IN, 0, 0, |
9a46d44e ID |
207 | eeprom, length, |
208 | REGISTER_TIMEOUT16(length)); | |
95ea3627 ID |
209 | } |
210 | ||
0f829b1d | 211 | /** |
02a39c20 | 212 | * rt2x00usb_register_read - Read 32bit register word |
0f829b1d ID |
213 | * @rt2x00dev: Device pointer, see &struct rt2x00_dev. |
214 | * @offset: Register offset | |
215 | * @value: Pointer to where register contents should be stored | |
216 | * | |
217 | * This function is a simple wrapper for 32bit register access | |
218 | * through rt2x00usb_vendor_request_buff(). | |
219 | */ | |
220 | static inline void rt2x00usb_register_read(struct rt2x00_dev *rt2x00dev, | |
221 | const unsigned int offset, | |
222 | u32 *value) | |
223 | { | |
224 | __le32 reg; | |
225 | rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_READ, | |
226 | USB_VENDOR_REQUEST_IN, offset, | |
227 | ®, sizeof(reg), REGISTER_TIMEOUT); | |
228 | *value = le32_to_cpu(reg); | |
229 | } | |
230 | ||
231 | /** | |
232 | * rt2x00usb_register_read_lock - Read 32bit register word | |
233 | * @rt2x00dev: Device pointer, see &struct rt2x00_dev. | |
234 | * @offset: Register offset | |
235 | * @value: Pointer to where register contents should be stored | |
236 | * | |
237 | * This function is a simple wrapper for 32bit register access | |
238 | * through rt2x00usb_vendor_req_buff_lock(). | |
239 | */ | |
240 | static inline void rt2x00usb_register_read_lock(struct rt2x00_dev *rt2x00dev, | |
241 | const unsigned int offset, | |
242 | u32 *value) | |
243 | { | |
244 | __le32 reg; | |
245 | rt2x00usb_vendor_req_buff_lock(rt2x00dev, USB_MULTI_READ, | |
246 | USB_VENDOR_REQUEST_IN, offset, | |
247 | ®, sizeof(reg), REGISTER_TIMEOUT); | |
248 | *value = le32_to_cpu(reg); | |
249 | } | |
250 | ||
251 | /** | |
252 | * rt2x00usb_register_multiread - Read 32bit register words | |
253 | * @rt2x00dev: Device pointer, see &struct rt2x00_dev. | |
254 | * @offset: Register offset | |
255 | * @value: Pointer to where register contents should be stored | |
256 | * @length: Length of the data | |
257 | * | |
258 | * This function is a simple wrapper for 32bit register access | |
259 | * through rt2x00usb_vendor_request_buff(). | |
260 | */ | |
261 | static inline void rt2x00usb_register_multiread(struct rt2x00_dev *rt2x00dev, | |
262 | const unsigned int offset, | |
263 | void *value, const u32 length) | |
264 | { | |
265 | rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_READ, | |
266 | USB_VENDOR_REQUEST_IN, offset, | |
267 | value, length, | |
268 | REGISTER_TIMEOUT32(length)); | |
269 | } | |
270 | ||
271 | /** | |
272 | * rt2x00usb_register_write - Write 32bit register word | |
273 | * @rt2x00dev: Device pointer, see &struct rt2x00_dev. | |
274 | * @offset: Register offset | |
275 | * @value: Data which should be written | |
276 | * | |
277 | * This function is a simple wrapper for 32bit register access | |
278 | * through rt2x00usb_vendor_request_buff(). | |
279 | */ | |
280 | static inline void rt2x00usb_register_write(struct rt2x00_dev *rt2x00dev, | |
281 | const unsigned int offset, | |
282 | u32 value) | |
283 | { | |
284 | __le32 reg = cpu_to_le32(value); | |
285 | rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_WRITE, | |
286 | USB_VENDOR_REQUEST_OUT, offset, | |
287 | ®, sizeof(reg), REGISTER_TIMEOUT); | |
288 | } | |
289 | ||
290 | /** | |
291 | * rt2x00usb_register_write_lock - Write 32bit register word | |
292 | * @rt2x00dev: Device pointer, see &struct rt2x00_dev. | |
293 | * @offset: Register offset | |
294 | * @value: Data which should be written | |
295 | * | |
296 | * This function is a simple wrapper for 32bit register access | |
297 | * through rt2x00usb_vendor_req_buff_lock(). | |
298 | */ | |
299 | static inline void rt2x00usb_register_write_lock(struct rt2x00_dev *rt2x00dev, | |
300 | const unsigned int offset, | |
301 | u32 value) | |
302 | { | |
303 | __le32 reg = cpu_to_le32(value); | |
304 | rt2x00usb_vendor_req_buff_lock(rt2x00dev, USB_MULTI_WRITE, | |
305 | USB_VENDOR_REQUEST_OUT, offset, | |
306 | ®, sizeof(reg), REGISTER_TIMEOUT); | |
307 | } | |
308 | ||
309 | /** | |
310 | * rt2x00usb_register_multiwrite - Write 32bit register words | |
311 | * @rt2x00dev: Device pointer, see &struct rt2x00_dev. | |
312 | * @offset: Register offset | |
313 | * @value: Data which should be written | |
314 | * @length: Length of the data | |
315 | * | |
316 | * This function is a simple wrapper for 32bit register access | |
317 | * through rt2x00usb_vendor_request_buff(). | |
318 | */ | |
319 | static inline void rt2x00usb_register_multiwrite(struct rt2x00_dev *rt2x00dev, | |
5b10b098 BZ |
320 | const unsigned int offset, |
321 | const void *value, | |
322 | const u32 length) | |
0f829b1d ID |
323 | { |
324 | rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_WRITE, | |
325 | USB_VENDOR_REQUEST_OUT, offset, | |
5b10b098 | 326 | (void *)value, length, |
0f829b1d ID |
327 | REGISTER_TIMEOUT32(length)); |
328 | } | |
329 | ||
330 | /** | |
331 | * rt2x00usb_regbusy_read - Read from register with busy check | |
332 | * @rt2x00dev: Device pointer, see &struct rt2x00_dev. | |
333 | * @offset: Register offset | |
334 | * @field: Field to check if register is busy | |
335 | * @reg: Pointer to where register contents should be stored | |
336 | * | |
337 | * This function will read the given register, and checks if the | |
338 | * register is busy. If it is, it will sleep for a couple of | |
339 | * microseconds before reading the register again. If the register | |
340 | * is not read after a certain timeout, this function will return | |
341 | * FALSE. | |
342 | */ | |
343 | int rt2x00usb_regbusy_read(struct rt2x00_dev *rt2x00dev, | |
344 | const unsigned int offset, | |
f255b92b | 345 | const struct rt2x00_field32 field, |
0f829b1d ID |
346 | u32 *reg); |
347 | ||
95ea3627 ID |
348 | /* |
349 | * Radio handlers | |
350 | */ | |
95ea3627 ID |
351 | void rt2x00usb_disable_radio(struct rt2x00_dev *rt2x00dev); |
352 | ||
181d6902 | 353 | /** |
b8be63ff | 354 | * struct queue_entry_priv_usb: Per entry USB specific information |
181d6902 ID |
355 | * |
356 | * @urb: Urb structure used for device communication. | |
181d6902 | 357 | */ |
b8be63ff | 358 | struct queue_entry_priv_usb { |
181d6902 | 359 | struct urb *urb; |
181d6902 ID |
360 | }; |
361 | ||
362 | /** | |
b8be63ff | 363 | * struct queue_entry_priv_usb_bcn: Per TX entry USB specific information |
181d6902 | 364 | * |
b8be63ff | 365 | * The first section should match &struct queue_entry_priv_usb exactly. |
181d6902 ID |
366 | * rt2500usb can use this structure to send a guardian byte when working |
367 | * with beacons. | |
368 | * | |
369 | * @urb: Urb structure used for device communication. | |
181d6902 ID |
370 | * @guardian_data: Set to 0, used for sending the guardian data. |
371 | * @guardian_urb: Urb structure used to send the guardian data. | |
372 | */ | |
373 | struct queue_entry_priv_usb_bcn { | |
374 | struct urb *urb; | |
375 | ||
181d6902 ID |
376 | unsigned int guardian_data; |
377 | struct urb *guardian_urb; | |
378 | }; | |
379 | ||
f019d514 | 380 | /** |
dbba306f | 381 | * rt2x00usb_kick_queue - Kick data queue |
93331458 | 382 | * @queue: Data queue to kick |
f019d514 ID |
383 | * |
384 | * This will walk through all entries of the queue and push all pending | |
385 | * frames to the hardware as a single burst. | |
386 | */ | |
dbba306f | 387 | void rt2x00usb_kick_queue(struct data_queue *queue); |
f019d514 | 388 | |
a2c9b652 | 389 | /** |
5be65609 | 390 | * rt2x00usb_flush_queue - Flush data queue |
5450b7e2 | 391 | * @queue: Data queue to stop |
a2c9b652 ID |
392 | * |
393 | * This will walk through all entries of the queue and kill all | |
5450b7e2 | 394 | * URB's which were send to the device. |
a2c9b652 | 395 | */ |
5be65609 | 396 | void rt2x00usb_flush_queue(struct data_queue *queue); |
a2c9b652 | 397 | |
c965c74b ID |
398 | /** |
399 | * rt2x00usb_watchdog - Watchdog for USB communication | |
400 | * @rt2x00dev: Pointer to &struct rt2x00_dev | |
401 | * | |
402 | * Check the health of the USB communication and determine | |
403 | * if timeouts have occured. If this is the case, this function | |
404 | * will reset all communication to restore functionality again. | |
405 | */ | |
406 | void rt2x00usb_watchdog(struct rt2x00_dev *rt2x00dev); | |
407 | ||
95ea3627 ID |
408 | /* |
409 | * Device initialization handlers. | |
410 | */ | |
798b7adb | 411 | void rt2x00usb_clear_entry(struct queue_entry *entry); |
95ea3627 ID |
412 | int rt2x00usb_initialize(struct rt2x00_dev *rt2x00dev); |
413 | void rt2x00usb_uninitialize(struct rt2x00_dev *rt2x00dev); | |
414 | ||
415 | /* | |
416 | * USB driver handlers. | |
417 | */ | |
418 | int rt2x00usb_probe(struct usb_interface *usb_intf, | |
419 | const struct usb_device_id *id); | |
420 | void rt2x00usb_disconnect(struct usb_interface *usb_intf); | |
421 | #ifdef CONFIG_PM | |
422 | int rt2x00usb_suspend(struct usb_interface *usb_intf, pm_message_t state); | |
423 | int rt2x00usb_resume(struct usb_interface *usb_intf); | |
424 | #else | |
425 | #define rt2x00usb_suspend NULL | |
426 | #define rt2x00usb_resume NULL | |
427 | #endif /* CONFIG_PM */ | |
428 | ||
429 | #endif /* RT2X00USB_H */ |