blob: 275b089a2a4d969a910cc90b8dbb194388d69cf5 [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
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 Doorne9136552007-09-25 20:54:20 +020047#define REGISTER_TIMEOUT 500
Ivo van Doorn95ea3622007-09-25 17:57:13 -070048#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 Doorn3b640f22008-02-03 15:54:11 +010063/**
64 * enum rt2x00usb_vendor_request: USB vendor commands.
Ivo van Doorn95ea3622007-09-25 17:57:13 -070065 */
Ivo van Doorn3b640f22008-02-03 15:54:11 +010066enum 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 Doorn95ea3622007-09-25 17:57:13 -070077
Ivo van Doorn3b640f22008-02-03 15:54:11 +010078/**
79 * enum rt2x00usb_mode_offset: Device modes offset.
Ivo van Doorn95ea3622007-09-25 17:57:13 -070080 */
Ivo van Doorn3b640f22008-02-03 15:54:11 +010081enum 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 Doorn95ea3622007-09-25 17:57:13 -070090
Ivo van Doorn3b640f22008-02-03 15:54:11 +010091/**
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 Doorn95ea3622007-09-25 17:57:13 -0700102 * This is the main function to communicate with the device,
Ivo van Doorn3b640f22008-02-03 15:54:11 +0100103 * the &buffer argument _must_ either be NULL or point to
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700104 * a buffer allocated by kmalloc. Failure to do so can lead
105 * to unexpected behavior depending on the architecture.
106 */
Adam Baker0e14f6d2007-10-27 13:41:25 +0200107int rt2x00usb_vendor_request(struct rt2x00_dev *rt2x00dev,
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700108 const u8 request, const u8 requesttype,
109 const u16 offset, const u16 value,
110 void *buffer, const u16 buffer_length,
Ivo van Doorne9136552007-09-25 20:54:20 +0200111 const int timeout);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700112
Ivo van Doorn3b640f22008-02-03 15:54:11 +0100113/**
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 Doorn95ea3622007-09-25 17:57:13 -0700123 * 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 Doorn3b640f22008-02-03 15:54:11 +0100127 * Buffers send to &rt2x00usb_vendor_request _must_ be allocated with
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700128 * kmalloc. Hence the reason for using a previously allocated cache
129 * which has been allocated properly.
130 */
Adam Baker0e14f6d2007-10-27 13:41:25 +0200131int rt2x00usb_vendor_request_buff(struct rt2x00_dev *rt2x00dev,
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700132 const u8 request, const u8 requesttype,
133 const u16 offset, void *buffer,
Ivo van Doorne9136552007-09-25 20:54:20 +0200134 const u16 buffer_length, const int timeout);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700135
Ivo van Doorn3b640f22008-02-03 15:54:11 +0100136/**
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 Baker3d823462007-10-27 13:43:29 +0200149int 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 Doorn3b640f22008-02-03 15:54:11 +0100154/**
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 Doorn95ea3622007-09-25 17:57:13 -0700162 * 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 Baker0e14f6d2007-10-27 13:41:25 +0200166static inline int rt2x00usb_vendor_request_sw(struct rt2x00_dev *rt2x00dev,
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700167 const u8 request,
168 const u16 offset,
169 const u16 value,
Ivo van Doorne9136552007-09-25 20:54:20 +0200170 const int timeout)
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700171{
172 return rt2x00usb_vendor_request(rt2x00dev, request,
173 USB_VENDOR_REQUEST_OUT, offset,
174 value, NULL, 0, timeout);
175}
176
Ivo van Doorn3b640f22008-02-03 15:54:11 +0100177/**
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 Doorn95ea3622007-09-25 17:57:13 -0700183 * 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 Baker0e14f6d2007-10-27 13:41:25 +0200187static inline int rt2x00usb_eeprom_read(struct rt2x00_dev *rt2x00dev,
188 __le16 *eeprom, const u16 lenght)
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700189{
190 int timeout = REGISTER_TIMEOUT * (lenght / sizeof(u16));
191
192 return rt2x00usb_vendor_request(rt2x00dev, USB_EEPROM_READ,
Ivo van Doorn3b640f22008-02-03 15:54:11 +0100193 USB_VENDOR_REQUEST_IN, 0, 0,
194 eeprom, lenght, timeout);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700195}
196
Ivo van Doorn3b640f22008-02-03 15:54:11 +0100197/**
198 * rt2x00usb_vendor_request_async - Send register command to device (async)
199 * @rt2x00dev: Pointer to &struct rt2x00_dev
200 * @request: USB vendor command (See &enum rt2x00usb_vendor_request)
201 * @offset: Register offset to perform action on
202 * @value: Value to write to device
203 *
204 * Asynchroneous version of &rt2x00usb_vendor_request this is required
205 * for some routines where the driver cannot sleep because it is in
206 * irq context. Note that with this function the driver will not be
207 * notified on failure or timeout of the command. It will only be notified
208 * if the start of the command succeeded or not. This means it should not be
209 * used when the command must succeed.
210 */
211int rt2x00usb_vendor_request_async(struct rt2x00_dev *rt2x00dev,
212 const u8 request, const u16 offset,
213 const u16 value);
214
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700215/*
216 * Radio handlers
217 */
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700218void rt2x00usb_disable_radio(struct rt2x00_dev *rt2x00dev);
219
220/*
221 * TX data handlers.
222 */
223int rt2x00usb_write_tx_data(struct rt2x00_dev *rt2x00dev,
Ivo van Doorn181d6902008-02-05 16:42:23 -0500224 struct data_queue *queue, struct sk_buff *skb,
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700225 struct ieee80211_tx_control *control);
226
Ivo van Doorn181d6902008-02-05 16:42:23 -0500227/**
228 * struct queue_entry_priv_usb_rx: Per RX entry USB specific information
229 *
230 * @urb: Urb structure used for device communication.
231 */
232struct queue_entry_priv_usb_rx {
233 struct urb *urb;
234};
235
236/**
237 * struct queue_entry_priv_usb_tx: Per TX entry USB specific information
238 *
239 * @urb: Urb structure used for device communication.
240 * @control: mac80211 control structure used to transmit data.
241 */
242struct queue_entry_priv_usb_tx {
243 struct urb *urb;
244
245 struct ieee80211_tx_control control;
246};
247
248/**
249 * struct queue_entry_priv_usb_tx: Per TX entry USB specific information
250 *
251 * The first section should match &struct queue_entry_priv_usb_tx exactly.
252 * rt2500usb can use this structure to send a guardian byte when working
253 * with beacons.
254 *
255 * @urb: Urb structure used for device communication.
256 * @control: mac80211 control structure used to transmit data.
257 * @guardian_data: Set to 0, used for sending the guardian data.
258 * @guardian_urb: Urb structure used to send the guardian data.
259 */
260struct queue_entry_priv_usb_bcn {
261 struct urb *urb;
262
263 struct ieee80211_tx_control control;
264
265 unsigned int guardian_data;
266 struct urb *guardian_urb;
267};
268
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700269/*
270 * Device initialization handlers.
271 */
Ivo van Doorn837e7f22008-01-06 23:41:45 +0100272void rt2x00usb_init_rxentry(struct rt2x00_dev *rt2x00dev,
Ivo van Doorn181d6902008-02-05 16:42:23 -0500273 struct queue_entry *entry);
Ivo van Doorn837e7f22008-01-06 23:41:45 +0100274void rt2x00usb_init_txentry(struct rt2x00_dev *rt2x00dev,
Ivo van Doorn181d6902008-02-05 16:42:23 -0500275 struct queue_entry *entry);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700276int rt2x00usb_initialize(struct rt2x00_dev *rt2x00dev);
277void rt2x00usb_uninitialize(struct rt2x00_dev *rt2x00dev);
278
279/*
280 * USB driver handlers.
281 */
282int rt2x00usb_probe(struct usb_interface *usb_intf,
283 const struct usb_device_id *id);
284void rt2x00usb_disconnect(struct usb_interface *usb_intf);
285#ifdef CONFIG_PM
286int rt2x00usb_suspend(struct usb_interface *usb_intf, pm_message_t state);
287int rt2x00usb_resume(struct usb_interface *usb_intf);
288#else
289#define rt2x00usb_suspend NULL
290#define rt2x00usb_resume NULL
291#endif /* CONFIG_PM */
292
293#endif /* RT2X00USB_H */