blob: 4da9eb376ebda561177cc5dd626680b7722c8401 [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
Ivo van Doornbd394a72008-04-21 19:01:58 +020050/**
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 Doorn95ea3622007-09-25 17:57:13 -070064/*
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 Doorn3b640f22008-02-03 15:54:11 +010077/**
78 * enum rt2x00usb_vendor_request: USB vendor commands.
Ivo van Doorn95ea3622007-09-25 17:57:13 -070079 */
Ivo van Doorn3b640f22008-02-03 15:54:11 +010080enum 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 Doorn95ea3622007-09-25 17:57:13 -070091
Ivo van Doorn3b640f22008-02-03 15:54:11 +010092/**
93 * enum rt2x00usb_mode_offset: Device modes offset.
Ivo van Doorn95ea3622007-09-25 17:57:13 -070094 */
Ivo van Doorn3b640f22008-02-03 15:54:11 +010095enum 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 Doorn95ea3622007-09-25 17:57:13 -0700104
Ivo van Doorn3b640f22008-02-03 15:54:11 +0100105/**
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 Doorn95ea3622007-09-25 17:57:13 -0700116 * This is the main function to communicate with the device,
Ivo van Doorn3b640f22008-02-03 15:54:11 +0100117 * the &buffer argument _must_ either be NULL or point to
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700118 * a buffer allocated by kmalloc. Failure to do so can lead
119 * to unexpected behavior depending on the architecture.
120 */
Adam Baker0e14f6d2007-10-27 13:41:25 +0200121int rt2x00usb_vendor_request(struct rt2x00_dev *rt2x00dev,
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700122 const u8 request, const u8 requesttype,
123 const u16 offset, const u16 value,
124 void *buffer, const u16 buffer_length,
Ivo van Doorne9136552007-09-25 20:54:20 +0200125 const int timeout);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700126
Ivo van Doorn3b640f22008-02-03 15:54:11 +0100127/**
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 Doorn95ea3622007-09-25 17:57:13 -0700137 * 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 Doorn3b640f22008-02-03 15:54:11 +0100141 * Buffers send to &rt2x00usb_vendor_request _must_ be allocated with
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700142 * kmalloc. Hence the reason for using a previously allocated cache
143 * which has been allocated properly.
144 */
Adam Baker0e14f6d2007-10-27 13:41:25 +0200145int rt2x00usb_vendor_request_buff(struct rt2x00_dev *rt2x00dev,
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700146 const u8 request, const u8 requesttype,
147 const u16 offset, void *buffer,
Ivo van Doorne9136552007-09-25 20:54:20 +0200148 const u16 buffer_length, const int timeout);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700149
Ivo van Doorn3b640f22008-02-03 15:54:11 +0100150/**
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 Baker3d823462007-10-27 13:43:29 +0200163int 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 Doorn3b640f22008-02-03 15:54:11 +0100168/**
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 Doorn95ea3622007-09-25 17:57:13 -0700176 * 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 Baker0e14f6d2007-10-27 13:41:25 +0200180static inline int rt2x00usb_vendor_request_sw(struct rt2x00_dev *rt2x00dev,
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700181 const u8 request,
182 const u16 offset,
183 const u16 value,
Ivo van Doorne9136552007-09-25 20:54:20 +0200184 const int timeout)
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700185{
186 return rt2x00usb_vendor_request(rt2x00dev, request,
187 USB_VENDOR_REQUEST_OUT, offset,
188 value, NULL, 0, timeout);
189}
190
Ivo van Doorn3b640f22008-02-03 15:54:11 +0100191/**
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 Doorn95ea3622007-09-25 17:57:13 -0700197 * 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 Baker0e14f6d2007-10-27 13:41:25 +0200201static inline int rt2x00usb_eeprom_read(struct rt2x00_dev *rt2x00dev,
Ivo van Doorn9a46d442008-04-21 19:02:17 +0200202 __le16 *eeprom, const u16 length)
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700203{
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700204 return rt2x00usb_vendor_request(rt2x00dev, USB_EEPROM_READ,
Ivo van Doorn3b640f22008-02-03 15:54:11 +0100205 USB_VENDOR_REQUEST_IN, 0, 0,
Ivo van Doorn9a46d442008-04-21 19:02:17 +0200206 eeprom, length,
207 REGISTER_TIMEOUT16(length));
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700208}
209
210/*
211 * Radio handlers
212 */
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700213void rt2x00usb_disable_radio(struct rt2x00_dev *rt2x00dev);
214
215/*
216 * TX data handlers.
217 */
218int rt2x00usb_write_tx_data(struct rt2x00_dev *rt2x00dev,
Ivo van Doorn181d6902008-02-05 16:42:23 -0500219 struct data_queue *queue, struct sk_buff *skb,
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700220 struct ieee80211_tx_control *control);
221
Ivo van Doorn181d6902008-02-05 16:42:23 -0500222/**
223 * struct queue_entry_priv_usb_rx: Per RX entry USB specific information
224 *
225 * @urb: Urb structure used for device communication.
226 */
227struct queue_entry_priv_usb_rx {
228 struct urb *urb;
229};
230
231/**
232 * struct queue_entry_priv_usb_tx: Per TX entry USB specific information
233 *
234 * @urb: Urb structure used for device communication.
235 * @control: mac80211 control structure used to transmit data.
236 */
237struct queue_entry_priv_usb_tx {
238 struct urb *urb;
239
240 struct ieee80211_tx_control control;
241};
242
243/**
244 * struct queue_entry_priv_usb_tx: Per TX entry USB specific information
245 *
246 * The first section should match &struct queue_entry_priv_usb_tx exactly.
247 * rt2500usb can use this structure to send a guardian byte when working
248 * with beacons.
249 *
250 * @urb: Urb structure used for device communication.
251 * @control: mac80211 control structure used to transmit data.
252 * @guardian_data: Set to 0, used for sending the guardian data.
253 * @guardian_urb: Urb structure used to send the guardian data.
254 */
255struct queue_entry_priv_usb_bcn {
256 struct urb *urb;
257
258 struct ieee80211_tx_control control;
259
260 unsigned int guardian_data;
261 struct urb *guardian_urb;
262};
263
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700264/*
265 * Device initialization handlers.
266 */
Ivo van Doorn837e7f22008-01-06 23:41:45 +0100267void rt2x00usb_init_rxentry(struct rt2x00_dev *rt2x00dev,
Ivo van Doorn181d6902008-02-05 16:42:23 -0500268 struct queue_entry *entry);
Ivo van Doorn837e7f22008-01-06 23:41:45 +0100269void rt2x00usb_init_txentry(struct rt2x00_dev *rt2x00dev,
Ivo van Doorn181d6902008-02-05 16:42:23 -0500270 struct queue_entry *entry);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700271int rt2x00usb_initialize(struct rt2x00_dev *rt2x00dev);
272void rt2x00usb_uninitialize(struct rt2x00_dev *rt2x00dev);
273
274/*
275 * USB driver handlers.
276 */
277int rt2x00usb_probe(struct usb_interface *usb_intf,
278 const struct usb_device_id *id);
279void rt2x00usb_disconnect(struct usb_interface *usb_intf);
280#ifdef CONFIG_PM
281int rt2x00usb_suspend(struct usb_interface *usb_intf, pm_message_t state);
282int rt2x00usb_resume(struct usb_interface *usb_intf);
283#else
284#define rt2x00usb_suspend NULL
285#define rt2x00usb_resume NULL
286#endif /* CONFIG_PM */
287
288#endif /* RT2X00USB_H */