2 Copyright (C) 2004 - 2008 rt2x00 SourceForge Project
3 <http://rt2x00.serialmonkey.com>
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.
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.
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.
23 Abstract: Data structures for the rt2x00usb module.
29 #define to_usb_device_intf(d) \
31 struct usb_interface *intf = to_usb_interface(d); \
32 interface_to_usbdev(intf); \
36 * This variable should be used with the
37 * usb_driver structure initialization.
39 #define USB_DEVICE_DATA(__ops) .driver_info = (kernel_ulong_t)(__ops)
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.
51 #define REGISTER_BUSY_COUNT 5
52 #define REGISTER_BUSY_DELAY 100
53 #define REGISTER_TIMEOUT 500
54 #define REGISTER_TIMEOUT_FIRMWARE 1000
57 * REGISTER_TIMEOUT16 - Determine the timeout for 16bit register access
58 * @__datalen: Data length
60 #define REGISTER_TIMEOUT16(__datalen) \
61 ( REGISTER_TIMEOUT * ((__datalen) / sizeof(u16)) )
64 * REGISTER_TIMEOUT32 - Determine the timeout for 32bit register access
65 * @__datalen: Data length
67 #define REGISTER_TIMEOUT32(__datalen) \
68 ( REGISTER_TIMEOUT * ((__datalen) / sizeof(u32)) )
73 #define CSR_CACHE_SIZE 8
74 #define CSR_CACHE_SIZE_FIRMWARE 64
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 )
84 * enum rt2x00usb_vendor_request: USB vendor commands.
86 enum rt2x00usb_vendor_request {
94 USB_LED_CONTROL = 10, /* RT73USB */
99 * enum rt2x00usb_mode_offset: Device modes offset.
101 enum rt2x00usb_mode_offset {
104 USB_MODE_FUNCTION = 3,
106 USB_MODE_SLEEP = 7, /* RT73USB */
107 USB_MODE_FIRMWARE = 8, /* RT73USB */
108 USB_MODE_WAKEUP = 9, /* RT73USB */
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
122 * This is the main function to communicate with the device,
123 * the &buffer argument _must_ either be NULL or point to
124 * a buffer allocated by kmalloc. Failure to do so can lead
125 * to unexpected behavior depending on the architecture.
127 int rt2x00usb_vendor_request(struct rt2x00_dev *rt2x00dev,
128 const u8 request, const u8 requesttype,
129 const u16 offset, const u16 value,
130 void *buffer, const u16 buffer_length,
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
143 * 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
147 * Buffers send to &rt2x00usb_vendor_request _must_ be allocated with
148 * kmalloc. Hence the reason for using a previously allocated cache
149 * which has been allocated properly.
151 int rt2x00usb_vendor_request_buff(struct rt2x00_dev *rt2x00dev,
152 const u8 request, const u8 requesttype,
153 const u16 offset, void *buffer,
154 const u16 buffer_length, const int timeout);
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
166 * A version of &rt2x00usb_vendor_request_buff which must be called
167 * if the usb_cache_mutex is already held.
169 int 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);
175 * rt2x00usb_vendor_request_sw - Send single register command to device
176 * @rt2x00dev: Pointer to &struct rt2x00_dev
177 * @request: USB vendor command (See &enum rt2x00usb_vendor_request)
178 * @offset: Register offset to perform action on
179 * @value: Value to write to device
180 * @timeout: Operation timeout
182 * Simple wrapper around rt2x00usb_vendor_request to write a single
183 * command to the device. Since we don't use the buffer argument we
184 * don't have to worry about kmalloc here.
186 static inline int rt2x00usb_vendor_request_sw(struct rt2x00_dev *rt2x00dev,
192 return rt2x00usb_vendor_request(rt2x00dev, request,
193 USB_VENDOR_REQUEST_OUT, offset,
194 value, NULL, 0, timeout);
198 * rt2x00usb_eeprom_read - Read eeprom from device
199 * @rt2x00dev: Pointer to &struct rt2x00_dev
200 * @eeprom: Pointer to eeprom array to store the information in
201 * @length: Number of bytes to read from the eeprom
203 * Simple wrapper around rt2x00usb_vendor_request to read the eeprom
204 * from the device. Note that the eeprom argument _must_ be allocated using
205 * kmalloc for correct handling inside the kernel USB layer.
207 static inline int rt2x00usb_eeprom_read(struct rt2x00_dev *rt2x00dev,
208 __le16 *eeprom, const u16 length)
210 return rt2x00usb_vendor_request(rt2x00dev, USB_EEPROM_READ,
211 USB_VENDOR_REQUEST_IN, 0, 0,
213 REGISTER_TIMEOUT16(length));
219 void rt2x00usb_disable_radio(struct rt2x00_dev *rt2x00dev);
222 * rt2x00usb_write_tx_data - Initialize URB for TX operation
223 * @entry: The entry where the frame is located
225 * This function will initialize the URB and skb descriptor
226 * to prepare the entry for the actual TX operation.
228 int rt2x00usb_write_tx_data(struct queue_entry *entry);
231 * struct queue_entry_priv_usb: Per entry USB specific information
233 * @urb: Urb structure used for device communication.
235 struct queue_entry_priv_usb {
240 * struct queue_entry_priv_usb_bcn: Per TX entry USB specific information
242 * The first section should match &struct queue_entry_priv_usb exactly.
243 * rt2500usb can use this structure to send a guardian byte when working
246 * @urb: Urb structure used for device communication.
247 * @guardian_data: Set to 0, used for sending the guardian data.
248 * @guardian_urb: Urb structure used to send the guardian data.
250 struct queue_entry_priv_usb_bcn {
253 unsigned int guardian_data;
254 struct urb *guardian_urb;
258 * rt2x00usb_kick_tx_queue - Kick data queue
259 * @rt2x00dev: Pointer to &struct rt2x00_dev
260 * @qid: Data queue to kick
262 * This will walk through all entries of the queue and push all pending
263 * frames to the hardware as a single burst.
265 void rt2x00usb_kick_tx_queue(struct rt2x00_dev *rt2x00dev,
266 const enum data_queue_qid qid);
269 * Device initialization handlers.
271 void rt2x00usb_init_rxentry(struct rt2x00_dev *rt2x00dev,
272 struct queue_entry *entry);
273 void rt2x00usb_init_txentry(struct rt2x00_dev *rt2x00dev,
274 struct queue_entry *entry);
275 int rt2x00usb_initialize(struct rt2x00_dev *rt2x00dev);
276 void rt2x00usb_uninitialize(struct rt2x00_dev *rt2x00dev);
279 * USB driver handlers.
281 int rt2x00usb_probe(struct usb_interface *usb_intf,
282 const struct usb_device_id *id);
283 void rt2x00usb_disconnect(struct usb_interface *usb_intf);
285 int rt2x00usb_suspend(struct usb_interface *usb_intf, pm_message_t state);
286 int rt2x00usb_resume(struct usb_interface *usb_intf);
288 #define rt2x00usb_suspend NULL
289 #define rt2x00usb_resume NULL
290 #endif /* CONFIG_PM */
292 #endif /* RT2X00USB_H */