]>
Commit | Line | Data |
---|---|---|
95ea3627 | 1 | /* |
811aa9ca | 2 | Copyright (C) 2004 - 2008 rt2x00 SourceForge Project |
95ea3627 ID |
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 | |
e9136550 | 47 | #define REGISTER_TIMEOUT 500 |
95ea3627 ID |
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 | * USB vendor commands. | |
65 | */ | |
66 | #define USB_DEVICE_MODE 0x01 | |
67 | #define USB_SINGLE_WRITE 0x02 | |
68 | #define USB_SINGLE_READ 0x03 | |
69 | #define USB_MULTI_WRITE 0x06 | |
70 | #define USB_MULTI_READ 0x07 | |
71 | #define USB_EEPROM_WRITE 0x08 | |
72 | #define USB_EEPROM_READ 0x09 | |
73 | #define USB_LED_CONTROL 0x0a /* RT73USB */ | |
74 | #define USB_RX_CONTROL 0x0c | |
75 | ||
76 | /* | |
77 | * Device modes offset | |
78 | */ | |
79 | #define USB_MODE_RESET 0x01 | |
80 | #define USB_MODE_UNPLUG 0x02 | |
81 | #define USB_MODE_FUNCTION 0x03 | |
82 | #define USB_MODE_TEST 0x04 | |
83 | #define USB_MODE_SLEEP 0x07 /* RT73USB */ | |
84 | #define USB_MODE_FIRMWARE 0x08 /* RT73USB */ | |
85 | #define USB_MODE_WAKEUP 0x09 /* RT73USB */ | |
86 | ||
87 | /* | |
88 | * Used to read/write from/to the device. | |
89 | * This is the main function to communicate with the device, | |
90 | * the buffer argument _must_ either be NULL or point to | |
91 | * a buffer allocated by kmalloc. Failure to do so can lead | |
92 | * to unexpected behavior depending on the architecture. | |
93 | */ | |
0e14f6d3 | 94 | int rt2x00usb_vendor_request(struct rt2x00_dev *rt2x00dev, |
95ea3627 ID |
95 | const u8 request, const u8 requesttype, |
96 | const u16 offset, const u16 value, | |
97 | void *buffer, const u16 buffer_length, | |
e9136550 | 98 | const int timeout); |
95ea3627 ID |
99 | |
100 | /* | |
101 | * Used to read/write from/to the device. | |
102 | * This function will use a previously with kmalloc allocated cache | |
103 | * to communicate with the device. The contents of the buffer pointer | |
104 | * will be copied to this cache when writing, or read from the cache | |
105 | * when reading. | |
106 | * Buffers send to rt2x00usb_vendor_request _must_ be allocated with | |
107 | * kmalloc. Hence the reason for using a previously allocated cache | |
108 | * which has been allocated properly. | |
109 | */ | |
0e14f6d3 | 110 | int rt2x00usb_vendor_request_buff(struct rt2x00_dev *rt2x00dev, |
95ea3627 ID |
111 | const u8 request, const u8 requesttype, |
112 | const u16 offset, void *buffer, | |
e9136550 | 113 | const u16 buffer_length, const int timeout); |
95ea3627 | 114 | |
3d82346c AB |
115 | /* |
116 | * A version of rt2x00usb_vendor_request_buff which must be called | |
117 | * if the usb_cache_mutex is already held. */ | |
118 | int rt2x00usb_vendor_req_buff_lock(struct rt2x00_dev *rt2x00dev, | |
119 | const u8 request, const u8 requesttype, | |
120 | const u16 offset, void *buffer, | |
121 | const u16 buffer_length, const int timeout); | |
122 | ||
95ea3627 ID |
123 | /* |
124 | * Simple wrapper around rt2x00usb_vendor_request to write a single | |
125 | * command to the device. Since we don't use the buffer argument we | |
126 | * don't have to worry about kmalloc here. | |
127 | */ | |
0e14f6d3 | 128 | static inline int rt2x00usb_vendor_request_sw(struct rt2x00_dev *rt2x00dev, |
95ea3627 ID |
129 | const u8 request, |
130 | const u16 offset, | |
131 | const u16 value, | |
e9136550 | 132 | const int timeout) |
95ea3627 ID |
133 | { |
134 | return rt2x00usb_vendor_request(rt2x00dev, request, | |
135 | USB_VENDOR_REQUEST_OUT, offset, | |
136 | value, NULL, 0, timeout); | |
137 | } | |
138 | ||
139 | /* | |
140 | * Simple wrapper around rt2x00usb_vendor_request to read the eeprom | |
141 | * from the device. Note that the eeprom argument _must_ be allocated using | |
142 | * kmalloc for correct handling inside the kernel USB layer. | |
143 | */ | |
0e14f6d3 AB |
144 | static inline int rt2x00usb_eeprom_read(struct rt2x00_dev *rt2x00dev, |
145 | __le16 *eeprom, const u16 lenght) | |
95ea3627 ID |
146 | { |
147 | int timeout = REGISTER_TIMEOUT * (lenght / sizeof(u16)); | |
148 | ||
149 | return rt2x00usb_vendor_request(rt2x00dev, USB_EEPROM_READ, | |
150 | USB_VENDOR_REQUEST_IN, 0x0000, | |
151 | 0x0000, eeprom, lenght, timeout); | |
152 | } | |
153 | ||
154 | /* | |
155 | * Radio handlers | |
156 | */ | |
95ea3627 ID |
157 | void rt2x00usb_disable_radio(struct rt2x00_dev *rt2x00dev); |
158 | ||
159 | /* | |
160 | * TX data handlers. | |
161 | */ | |
162 | int rt2x00usb_write_tx_data(struct rt2x00_dev *rt2x00dev, | |
181d6902 | 163 | struct data_queue *queue, struct sk_buff *skb, |
95ea3627 ID |
164 | struct ieee80211_tx_control *control); |
165 | ||
181d6902 ID |
166 | /** |
167 | * struct queue_entry_priv_usb_rx: Per RX entry USB specific information | |
168 | * | |
169 | * @urb: Urb structure used for device communication. | |
170 | */ | |
171 | struct queue_entry_priv_usb_rx { | |
172 | struct urb *urb; | |
173 | }; | |
174 | ||
175 | /** | |
176 | * struct queue_entry_priv_usb_tx: Per TX entry USB specific information | |
177 | * | |
178 | * @urb: Urb structure used for device communication. | |
179 | * @control: mac80211 control structure used to transmit data. | |
180 | */ | |
181 | struct queue_entry_priv_usb_tx { | |
182 | struct urb *urb; | |
183 | ||
184 | struct ieee80211_tx_control control; | |
185 | }; | |
186 | ||
187 | /** | |
188 | * struct queue_entry_priv_usb_tx: Per TX entry USB specific information | |
189 | * | |
190 | * The first section should match &struct queue_entry_priv_usb_tx exactly. | |
191 | * rt2500usb can use this structure to send a guardian byte when working | |
192 | * with beacons. | |
193 | * | |
194 | * @urb: Urb structure used for device communication. | |
195 | * @control: mac80211 control structure used to transmit data. | |
196 | * @guardian_data: Set to 0, used for sending the guardian data. | |
197 | * @guardian_urb: Urb structure used to send the guardian data. | |
198 | */ | |
199 | struct queue_entry_priv_usb_bcn { | |
200 | struct urb *urb; | |
201 | ||
202 | struct ieee80211_tx_control control; | |
203 | ||
204 | unsigned int guardian_data; | |
205 | struct urb *guardian_urb; | |
206 | }; | |
207 | ||
95ea3627 ID |
208 | /* |
209 | * Device initialization handlers. | |
210 | */ | |
837e7f24 | 211 | void rt2x00usb_init_rxentry(struct rt2x00_dev *rt2x00dev, |
181d6902 | 212 | struct queue_entry *entry); |
837e7f24 | 213 | void rt2x00usb_init_txentry(struct rt2x00_dev *rt2x00dev, |
181d6902 | 214 | struct queue_entry *entry); |
95ea3627 ID |
215 | int rt2x00usb_initialize(struct rt2x00_dev *rt2x00dev); |
216 | void rt2x00usb_uninitialize(struct rt2x00_dev *rt2x00dev); | |
217 | ||
218 | /* | |
219 | * USB driver handlers. | |
220 | */ | |
221 | int rt2x00usb_probe(struct usb_interface *usb_intf, | |
222 | const struct usb_device_id *id); | |
223 | void rt2x00usb_disconnect(struct usb_interface *usb_intf); | |
224 | #ifdef CONFIG_PM | |
225 | int rt2x00usb_suspend(struct usb_interface *usb_intf, pm_message_t state); | |
226 | int rt2x00usb_resume(struct usb_interface *usb_intf); | |
227 | #else | |
228 | #define rt2x00usb_suspend NULL | |
229 | #define rt2x00usb_resume NULL | |
230 | #endif /* CONFIG_PM */ | |
231 | ||
232 | #endif /* RT2X00USB_H */ |