blob: 8d5d4272e88f8f7528b8101c9bd4614496d2544c [file] [log] [blame]
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001/*
Ivo van Doorn811aa9c2008-02-03 15:42:53 +01002 Copyright (C) 2004 - 2008 rt2x00 SourceForge Project
Ivo van Doorn95ea3622007-09-25 17:57:13 -07003 <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 Doornc1d35df2008-06-16 19:57:11 +020029#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 Doorn95ea3622007-09-25 17:57:13 -070035/*
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 Doorne9136552007-09-25 20:54:20 +020053#define REGISTER_TIMEOUT 500
Ivo van Doorn95ea3622007-09-25 17:57:13 -070054#define REGISTER_TIMEOUT_FIRMWARE 1000
55
Ivo van Doornbd394a72008-04-21 19:01:58 +020056/**
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 Doorn95ea3622007-09-25 17:57:13 -070070/*
71 * Cache size
72 */
Iwo Merglered0dbee2008-07-19 16:16:54 +020073#define CSR_CACHE_SIZE 64
Ivo van Doorn95ea3622007-09-25 17:57:13 -070074#define CSR_CACHE_SIZE_FIRMWARE 64
75
76/*
77 * USB request types.
78 */
79#define USB_VENDOR_REQUEST ( USB_TYPE_VENDOR | USB_RECIP_DEVICE )
80#define USB_VENDOR_REQUEST_IN ( USB_DIR_IN | USB_VENDOR_REQUEST )
81#define USB_VENDOR_REQUEST_OUT ( USB_DIR_OUT | USB_VENDOR_REQUEST )
82
Ivo van Doorn3b640f22008-02-03 15:54:11 +010083/**
84 * enum rt2x00usb_vendor_request: USB vendor commands.
Ivo van Doorn95ea3622007-09-25 17:57:13 -070085 */
Ivo van Doorn3b640f22008-02-03 15:54:11 +010086enum rt2x00usb_vendor_request {
87 USB_DEVICE_MODE = 1,
88 USB_SINGLE_WRITE = 2,
89 USB_SINGLE_READ = 3,
90 USB_MULTI_WRITE = 6,
91 USB_MULTI_READ = 7,
92 USB_EEPROM_WRITE = 8,
93 USB_EEPROM_READ = 9,
94 USB_LED_CONTROL = 10, /* RT73USB */
95 USB_RX_CONTROL = 12,
96};
Ivo van Doorn95ea3622007-09-25 17:57:13 -070097
Ivo van Doorn3b640f22008-02-03 15:54:11 +010098/**
99 * enum rt2x00usb_mode_offset: Device modes offset.
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700100 */
Ivo van Doorn3b640f22008-02-03 15:54:11 +0100101enum rt2x00usb_mode_offset {
102 USB_MODE_RESET = 1,
103 USB_MODE_UNPLUG = 2,
104 USB_MODE_FUNCTION = 3,
105 USB_MODE_TEST = 4,
106 USB_MODE_SLEEP = 7, /* RT73USB */
107 USB_MODE_FIRMWARE = 8, /* RT73USB */
108 USB_MODE_WAKEUP = 9, /* RT73USB */
109};
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700110
Ivo van Doorn3b640f22008-02-03 15:54:11 +0100111/**
112 * rt2x00usb_vendor_request - Send register command to device
113 * @rt2x00dev: Pointer to &struct rt2x00_dev
114 * @request: USB vendor command (See &enum rt2x00usb_vendor_request)
115 * @requesttype: Request type &USB_VENDOR_REQUEST_*
116 * @offset: Register offset to perform action on
117 * @value: Value to write to device
118 * @buffer: Buffer where information will be read/written to by device
119 * @buffer_length: Size of &buffer
120 * @timeout: Operation timeout
121 *
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700122 * This is the main function to communicate with the device,
Ivo van Doorn3b640f22008-02-03 15:54:11 +0100123 * the &buffer argument _must_ either be NULL or point to
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700124 * a buffer allocated by kmalloc. Failure to do so can lead
125 * to unexpected behavior depending on the architecture.
126 */
Adam Baker0e14f6d2007-10-27 13:41:25 +0200127int rt2x00usb_vendor_request(struct rt2x00_dev *rt2x00dev,
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700128 const u8 request, const u8 requesttype,
129 const u16 offset, const u16 value,
130 void *buffer, const u16 buffer_length,
Ivo van Doorne9136552007-09-25 20:54:20 +0200131 const int timeout);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700132
Ivo van Doorn3b640f22008-02-03 15:54:11 +0100133/**
134 * rt2x00usb_vendor_request_buff - Send register command to device (buffered)
135 * @rt2x00dev: Pointer to &struct rt2x00_dev
136 * @request: USB vendor command (See &enum rt2x00usb_vendor_request)
137 * @requesttype: Request type &USB_VENDOR_REQUEST_*
138 * @offset: Register offset to perform action on
139 * @buffer: Buffer where information will be read/written to by device
140 * @buffer_length: Size of &buffer
141 * @timeout: Operation timeout
142 *
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700143 * This function will use a previously with kmalloc allocated cache
144 * to communicate with the device. The contents of the buffer pointer
145 * will be copied to this cache when writing, or read from the cache
146 * when reading.
Ivo van Doorn3b640f22008-02-03 15:54:11 +0100147 * Buffers send to &rt2x00usb_vendor_request _must_ be allocated with
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700148 * kmalloc. Hence the reason for using a previously allocated cache
149 * which has been allocated properly.
150 */
Adam Baker0e14f6d2007-10-27 13:41:25 +0200151int rt2x00usb_vendor_request_buff(struct rt2x00_dev *rt2x00dev,
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700152 const u8 request, const u8 requesttype,
153 const u16 offset, void *buffer,
Ivo van Doorne9136552007-09-25 20:54:20 +0200154 const u16 buffer_length, const int timeout);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700155
Ivo van Doorn3b640f22008-02-03 15:54:11 +0100156/**
157 * rt2x00usb_vendor_request_buff - Send register command to device (buffered)
158 * @rt2x00dev: Pointer to &struct rt2x00_dev
159 * @request: USB vendor command (See &enum rt2x00usb_vendor_request)
160 * @requesttype: Request type &USB_VENDOR_REQUEST_*
161 * @offset: Register offset to perform action on
162 * @buffer: Buffer where information will be read/written to by device
163 * @buffer_length: Size of &buffer
164 * @timeout: Operation timeout
165 *
166 * A version of &rt2x00usb_vendor_request_buff which must be called
167 * if the usb_cache_mutex is already held.
168 */
Adam Baker3d823462007-10-27 13:43:29 +0200169int rt2x00usb_vendor_req_buff_lock(struct rt2x00_dev *rt2x00dev,
170 const u8 request, const u8 requesttype,
171 const u16 offset, void *buffer,
172 const u16 buffer_length, const int timeout);
173
Ivo van Doorn3b640f22008-02-03 15:54:11 +0100174/**
Iwo Merglered0dbee2008-07-19 16:16:54 +0200175 * rt2x00usb_vendor_request_large_buff - Send register command to device (buffered)
176 * @rt2x00dev: Pointer to &struct rt2x00_dev
177 * @request: USB vendor command (See &enum rt2x00usb_vendor_request)
178 * @requesttype: Request type &USB_VENDOR_REQUEST_*
179 * @offset: Register start offset to perform action on
180 * @buffer: Buffer where information will be read/written to by device
181 * @buffer_length: Size of &buffer
182 * @timeout: Operation timeout
183 *
184 * This function is used to transfer register data in blocks larger
185 * then CSR_CACHE_SIZE. Use for firmware upload, keys and beacons.
186 */
187int rt2x00usb_vendor_request_large_buff(struct rt2x00_dev *rt2x00dev,
188 const u8 request, const u8 requesttype,
189 const u16 offset, void *buffer,
190 const u16 buffer_length,
191 const int timeout);
192
193/**
Ivo van Doorn3b640f22008-02-03 15:54:11 +0100194 * rt2x00usb_vendor_request_sw - Send single register command to device
195 * @rt2x00dev: Pointer to &struct rt2x00_dev
196 * @request: USB vendor command (See &enum rt2x00usb_vendor_request)
197 * @offset: Register offset to perform action on
198 * @value: Value to write to device
199 * @timeout: Operation timeout
200 *
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700201 * Simple wrapper around rt2x00usb_vendor_request to write a single
202 * command to the device. Since we don't use the buffer argument we
203 * don't have to worry about kmalloc here.
204 */
Adam Baker0e14f6d2007-10-27 13:41:25 +0200205static inline int rt2x00usb_vendor_request_sw(struct rt2x00_dev *rt2x00dev,
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700206 const u8 request,
207 const u16 offset,
208 const u16 value,
Ivo van Doorne9136552007-09-25 20:54:20 +0200209 const int timeout)
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700210{
211 return rt2x00usb_vendor_request(rt2x00dev, request,
212 USB_VENDOR_REQUEST_OUT, offset,
213 value, NULL, 0, timeout);
214}
215
Ivo van Doorn3b640f22008-02-03 15:54:11 +0100216/**
217 * rt2x00usb_eeprom_read - Read eeprom from device
218 * @rt2x00dev: Pointer to &struct rt2x00_dev
219 * @eeprom: Pointer to eeprom array to store the information in
220 * @length: Number of bytes to read from the eeprom
221 *
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700222 * Simple wrapper around rt2x00usb_vendor_request to read the eeprom
223 * from the device. Note that the eeprom argument _must_ be allocated using
224 * kmalloc for correct handling inside the kernel USB layer.
225 */
Adam Baker0e14f6d2007-10-27 13:41:25 +0200226static inline int rt2x00usb_eeprom_read(struct rt2x00_dev *rt2x00dev,
Ivo van Doorn9a46d442008-04-21 19:02:17 +0200227 __le16 *eeprom, const u16 length)
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700228{
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700229 return rt2x00usb_vendor_request(rt2x00dev, USB_EEPROM_READ,
Ivo van Doorn3b640f22008-02-03 15:54:11 +0100230 USB_VENDOR_REQUEST_IN, 0, 0,
Ivo van Doorn9a46d442008-04-21 19:02:17 +0200231 eeprom, length,
232 REGISTER_TIMEOUT16(length));
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700233}
234
235/*
236 * Radio handlers
237 */
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700238void rt2x00usb_disable_radio(struct rt2x00_dev *rt2x00dev);
239
Ivo van Doorn6db37862008-06-06 22:50:28 +0200240/**
241 * rt2x00usb_write_tx_data - Initialize URB for TX operation
242 * @entry: The entry where the frame is located
243 *
244 * This function will initialize the URB and skb descriptor
245 * to prepare the entry for the actual TX operation.
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700246 */
Ivo van Doorn6db37862008-06-06 22:50:28 +0200247int rt2x00usb_write_tx_data(struct queue_entry *entry);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700248
Ivo van Doorn181d6902008-02-05 16:42:23 -0500249/**
Ivo van Doornb8be63f2008-05-10 13:46:03 +0200250 * struct queue_entry_priv_usb: Per entry USB specific information
Ivo van Doorn181d6902008-02-05 16:42:23 -0500251 *
252 * @urb: Urb structure used for device communication.
Ivo van Doorn181d6902008-02-05 16:42:23 -0500253 */
Ivo van Doornb8be63f2008-05-10 13:46:03 +0200254struct queue_entry_priv_usb {
Ivo van Doorn181d6902008-02-05 16:42:23 -0500255 struct urb *urb;
Ivo van Doorn181d6902008-02-05 16:42:23 -0500256};
257
258/**
Ivo van Doornb8be63f2008-05-10 13:46:03 +0200259 * struct queue_entry_priv_usb_bcn: Per TX entry USB specific information
Ivo van Doorn181d6902008-02-05 16:42:23 -0500260 *
Ivo van Doornb8be63f2008-05-10 13:46:03 +0200261 * The first section should match &struct queue_entry_priv_usb exactly.
Ivo van Doorn181d6902008-02-05 16:42:23 -0500262 * rt2500usb can use this structure to send a guardian byte when working
263 * with beacons.
264 *
265 * @urb: Urb structure used for device communication.
Ivo van Doorn181d6902008-02-05 16:42:23 -0500266 * @guardian_data: Set to 0, used for sending the guardian data.
267 * @guardian_urb: Urb structure used to send the guardian data.
268 */
269struct queue_entry_priv_usb_bcn {
270 struct urb *urb;
271
Ivo van Doorn181d6902008-02-05 16:42:23 -0500272 unsigned int guardian_data;
273 struct urb *guardian_urb;
274};
275
Ivo van Doornf019d512008-06-06 22:47:39 +0200276/**
277 * rt2x00usb_kick_tx_queue - Kick data queue
278 * @rt2x00dev: Pointer to &struct rt2x00_dev
279 * @qid: Data queue to kick
280 *
281 * This will walk through all entries of the queue and push all pending
282 * frames to the hardware as a single burst.
283 */
284void rt2x00usb_kick_tx_queue(struct rt2x00_dev *rt2x00dev,
285 const enum data_queue_qid qid);
286
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700287/*
288 * Device initialization handlers.
289 */
Ivo van Doorn837e7f22008-01-06 23:41:45 +0100290void rt2x00usb_init_rxentry(struct rt2x00_dev *rt2x00dev,
Ivo van Doorn181d6902008-02-05 16:42:23 -0500291 struct queue_entry *entry);
Ivo van Doorn837e7f22008-01-06 23:41:45 +0100292void rt2x00usb_init_txentry(struct rt2x00_dev *rt2x00dev,
Ivo van Doorn181d6902008-02-05 16:42:23 -0500293 struct queue_entry *entry);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700294int rt2x00usb_initialize(struct rt2x00_dev *rt2x00dev);
295void rt2x00usb_uninitialize(struct rt2x00_dev *rt2x00dev);
296
297/*
298 * USB driver handlers.
299 */
300int rt2x00usb_probe(struct usb_interface *usb_intf,
301 const struct usb_device_id *id);
302void rt2x00usb_disconnect(struct usb_interface *usb_intf);
303#ifdef CONFIG_PM
304int rt2x00usb_suspend(struct usb_interface *usb_intf, pm_message_t state);
305int rt2x00usb_resume(struct usb_interface *usb_intf);
306#else
307#define rt2x00usb_suspend NULL
308#define rt2x00usb_resume NULL
309#endif /* CONFIG_PM */
310
311#endif /* RT2X00USB_H */