rt2x00: Enable LED class support for rt2500usb/rt73usb
[pandora-kernel.git] / drivers / net / wireless / rt2x00 / rt2x00usb.h
1 /*
2         Copyright (C) 2004 - 2008 rt2x00 SourceForge Project
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
47 #define REGISTER_TIMEOUT                500
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
63 /**
64  * enum rt2x00usb_vendor_request: USB vendor commands.
65  */
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 };
77
78 /**
79  * enum rt2x00usb_mode_offset: Device modes offset.
80  */
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 };
90
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  *
102  * This is the main function to communicate with the device,
103  * the &buffer argument _must_ either be NULL or point to
104  * a buffer allocated by kmalloc. Failure to do so can lead
105  * to unexpected behavior depending on the architecture.
106  */
107 int rt2x00usb_vendor_request(struct rt2x00_dev *rt2x00dev,
108                              const u8 request, const u8 requesttype,
109                              const u16 offset, const u16 value,
110                              void *buffer, const u16 buffer_length,
111                              const int timeout);
112
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  *
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.
127  * Buffers send to &rt2x00usb_vendor_request _must_ be allocated with
128  * kmalloc. Hence the reason for using a previously allocated cache
129  * which has been allocated properly.
130  */
131 int rt2x00usb_vendor_request_buff(struct rt2x00_dev *rt2x00dev,
132                                   const u8 request, const u8 requesttype,
133                                   const u16 offset, void *buffer,
134                                   const u16 buffer_length, const int timeout);
135
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  */
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
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  *
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  */
166 static inline int rt2x00usb_vendor_request_sw(struct rt2x00_dev *rt2x00dev,
167                                               const u8 request,
168                                               const u16 offset,
169                                               const u16 value,
170                                               const int timeout)
171 {
172         return rt2x00usb_vendor_request(rt2x00dev, request,
173                                         USB_VENDOR_REQUEST_OUT, offset,
174                                         value, NULL, 0, timeout);
175 }
176
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  *
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  */
187 static inline int rt2x00usb_eeprom_read(struct rt2x00_dev *rt2x00dev,
188                                         __le16 *eeprom, const u16 lenght)
189 {
190         int timeout = REGISTER_TIMEOUT * (lenght / sizeof(u16));
191
192         return rt2x00usb_vendor_request(rt2x00dev, USB_EEPROM_READ,
193                                         USB_VENDOR_REQUEST_IN, 0, 0,
194                                         eeprom, lenght, timeout);
195 }
196
197 /**
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  */
211 int rt2x00usb_vendor_request_async(struct rt2x00_dev *rt2x00dev,
212                                    const u8 request, const u16 offset,
213                                    const u16 value);
214
215 /*
216  * Radio handlers
217  */
218 void rt2x00usb_disable_radio(struct rt2x00_dev *rt2x00dev);
219
220 /*
221  * TX data handlers.
222  */
223 int rt2x00usb_write_tx_data(struct rt2x00_dev *rt2x00dev,
224                             struct data_queue *queue, struct sk_buff *skb,
225                             struct ieee80211_tx_control *control);
226
227 /**
228  * struct queue_entry_priv_usb_rx: Per RX entry USB specific information
229  *
230  * @urb: Urb structure used for device communication.
231  */
232 struct 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  */
242 struct 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  */
260 struct 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
269 /*
270  * Device initialization handlers.
271  */
272 void rt2x00usb_init_rxentry(struct rt2x00_dev *rt2x00dev,
273                             struct queue_entry *entry);
274 void rt2x00usb_init_txentry(struct rt2x00_dev *rt2x00dev,
275                             struct queue_entry *entry);
276 int rt2x00usb_initialize(struct rt2x00_dev *rt2x00dev);
277 void rt2x00usb_uninitialize(struct rt2x00_dev *rt2x00dev);
278
279 /*
280  * USB driver handlers.
281  */
282 int rt2x00usb_probe(struct usb_interface *usb_intf,
283                     const struct usb_device_id *id);
284 void rt2x00usb_disconnect(struct usb_interface *usb_intf);
285 #ifdef CONFIG_PM
286 int rt2x00usb_suspend(struct usb_interface *usb_intf, pm_message_t state);
287 int 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 */