blob: 83f2592c59def385091a81e5e070d184d7a0260e [file] [log] [blame]
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001/*
Gertjan van Wingerde9c9a0d12009-11-08 16:39:55 +01002 Copyright (C) 2004 - 2009 Ivo van Doorn <IvDoorn@gmail.com>
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: rt2500usb
23 Abstract: rt2500usb device specific routines.
24 Supported chipsets: RT2570.
25 */
26
Ivo van Doorn95ea3622007-09-25 17:57:13 -070027#include <linux/delay.h>
28#include <linux/etherdevice.h>
29#include <linux/init.h>
30#include <linux/kernel.h>
31#include <linux/module.h>
32#include <linux/usb.h>
33
34#include "rt2x00.h"
35#include "rt2x00usb.h"
36#include "rt2500usb.h"
37
38/*
Ivo van Doorndddfb472008-12-02 18:20:42 +010039 * Allow hardware encryption to be disabled.
40 */
Ivo van Doornf1dd2b22009-01-03 16:27:14 +010041static int modparam_nohwcrypt = 0;
Ivo van Doorndddfb472008-12-02 18:20:42 +010042module_param_named(nohwcrypt, modparam_nohwcrypt, bool, S_IRUGO);
43MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption.");
44
45/*
Ivo van Doorn95ea3622007-09-25 17:57:13 -070046 * Register access.
47 * All access to the CSR registers will go through the methods
48 * rt2500usb_register_read and rt2500usb_register_write.
49 * BBP and RF register require indirect register access,
50 * and use the CSR registers BBPCSR and RFCSR to achieve this.
51 * These indirect registers work with busy bits,
52 * and we will try maximal REGISTER_BUSY_COUNT times to access
53 * the register while taking a REGISTER_BUSY_DELAY us delay
54 * between each attampt. When the busy bit is still set at that time,
55 * the access attempt is considered to have failed,
56 * and we will print an error.
Ivo van Doorn8ff48a82008-11-09 23:40:46 +010057 * If the csr_mutex is already held then the _lock variants must
Adam Baker3d823462007-10-27 13:43:29 +020058 * be used instead.
Ivo van Doorn95ea3622007-09-25 17:57:13 -070059 */
Adam Baker0e14f6d2007-10-27 13:41:25 +020060static inline void rt2500usb_register_read(struct rt2x00_dev *rt2x00dev,
Ivo van Doorn95ea3622007-09-25 17:57:13 -070061 const unsigned int offset,
62 u16 *value)
63{
64 __le16 reg;
65 rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_READ,
66 USB_VENDOR_REQUEST_IN, offset,
Ivo van Doornc9c3b1a2008-11-10 19:41:40 +010067 &reg, sizeof(reg), REGISTER_TIMEOUT);
Ivo van Doorn95ea3622007-09-25 17:57:13 -070068 *value = le16_to_cpu(reg);
69}
70
Adam Baker3d823462007-10-27 13:43:29 +020071static inline void rt2500usb_register_read_lock(struct rt2x00_dev *rt2x00dev,
72 const unsigned int offset,
73 u16 *value)
74{
75 __le16 reg;
76 rt2x00usb_vendor_req_buff_lock(rt2x00dev, USB_MULTI_READ,
77 USB_VENDOR_REQUEST_IN, offset,
Ivo van Doornc9c3b1a2008-11-10 19:41:40 +010078 &reg, sizeof(reg), REGISTER_TIMEOUT);
Adam Baker3d823462007-10-27 13:43:29 +020079 *value = le16_to_cpu(reg);
80}
81
Adam Baker0e14f6d2007-10-27 13:41:25 +020082static inline void rt2500usb_register_multiread(struct rt2x00_dev *rt2x00dev,
Ivo van Doorn95ea3622007-09-25 17:57:13 -070083 const unsigned int offset,
84 void *value, const u16 length)
85{
Ivo van Doorn95ea3622007-09-25 17:57:13 -070086 rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_READ,
87 USB_VENDOR_REQUEST_IN, offset,
Ivo van Doornbd394a72008-04-21 19:01:58 +020088 value, length,
89 REGISTER_TIMEOUT16(length));
Ivo van Doorn95ea3622007-09-25 17:57:13 -070090}
91
Adam Baker0e14f6d2007-10-27 13:41:25 +020092static inline void rt2500usb_register_write(struct rt2x00_dev *rt2x00dev,
Ivo van Doorn95ea3622007-09-25 17:57:13 -070093 const unsigned int offset,
94 u16 value)
95{
96 __le16 reg = cpu_to_le16(value);
97 rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_WRITE,
98 USB_VENDOR_REQUEST_OUT, offset,
Ivo van Doornc9c3b1a2008-11-10 19:41:40 +010099 &reg, sizeof(reg), REGISTER_TIMEOUT);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700100}
101
Adam Baker3d823462007-10-27 13:43:29 +0200102static inline void rt2500usb_register_write_lock(struct rt2x00_dev *rt2x00dev,
103 const unsigned int offset,
104 u16 value)
105{
106 __le16 reg = cpu_to_le16(value);
107 rt2x00usb_vendor_req_buff_lock(rt2x00dev, USB_MULTI_WRITE,
108 USB_VENDOR_REQUEST_OUT, offset,
Ivo van Doornc9c3b1a2008-11-10 19:41:40 +0100109 &reg, sizeof(reg), REGISTER_TIMEOUT);
Adam Baker3d823462007-10-27 13:43:29 +0200110}
111
Adam Baker0e14f6d2007-10-27 13:41:25 +0200112static inline void rt2500usb_register_multiwrite(struct rt2x00_dev *rt2x00dev,
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700113 const unsigned int offset,
114 void *value, const u16 length)
115{
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700116 rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_WRITE,
117 USB_VENDOR_REQUEST_OUT, offset,
Ivo van Doornbd394a72008-04-21 19:01:58 +0200118 value, length,
119 REGISTER_TIMEOUT16(length));
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700120}
121
Ivo van Doornc9c3b1a2008-11-10 19:41:40 +0100122static int rt2500usb_regbusy_read(struct rt2x00_dev *rt2x00dev,
123 const unsigned int offset,
124 struct rt2x00_field16 field,
125 u16 *reg)
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700126{
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700127 unsigned int i;
128
129 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
Ivo van Doornc9c3b1a2008-11-10 19:41:40 +0100130 rt2500usb_register_read_lock(rt2x00dev, offset, reg);
131 if (!rt2x00_get_field16(*reg, field))
132 return 1;
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700133 udelay(REGISTER_BUSY_DELAY);
134 }
135
Ivo van Doornc9c3b1a2008-11-10 19:41:40 +0100136 ERROR(rt2x00dev, "Indirect register access failed: "
137 "offset=0x%.08x, value=0x%.08x\n", offset, *reg);
138 *reg = ~0;
139
140 return 0;
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700141}
142
Ivo van Doornc9c3b1a2008-11-10 19:41:40 +0100143#define WAIT_FOR_BBP(__dev, __reg) \
144 rt2500usb_regbusy_read((__dev), PHY_CSR8, PHY_CSR8_BUSY, (__reg))
145#define WAIT_FOR_RF(__dev, __reg) \
146 rt2500usb_regbusy_read((__dev), PHY_CSR10, PHY_CSR10_RF_BUSY, (__reg))
147
Adam Baker0e14f6d2007-10-27 13:41:25 +0200148static void rt2500usb_bbp_write(struct rt2x00_dev *rt2x00dev,
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700149 const unsigned int word, const u8 value)
150{
151 u16 reg;
152
Ivo van Doorn8ff48a82008-11-09 23:40:46 +0100153 mutex_lock(&rt2x00dev->csr_mutex);
Adam Baker3d823462007-10-27 13:43:29 +0200154
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700155 /*
Ivo van Doornc9c3b1a2008-11-10 19:41:40 +0100156 * Wait until the BBP becomes available, afterwards we
157 * can safely write the new data into the register.
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700158 */
Ivo van Doornc9c3b1a2008-11-10 19:41:40 +0100159 if (WAIT_FOR_BBP(rt2x00dev, &reg)) {
160 reg = 0;
161 rt2x00_set_field16(&reg, PHY_CSR7_DATA, value);
162 rt2x00_set_field16(&reg, PHY_CSR7_REG_ID, word);
163 rt2x00_set_field16(&reg, PHY_CSR7_READ_CONTROL, 0);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700164
Ivo van Doornc9c3b1a2008-11-10 19:41:40 +0100165 rt2500usb_register_write_lock(rt2x00dev, PHY_CSR7, reg);
166 }
Adam Baker3d823462007-10-27 13:43:29 +0200167
Ivo van Doorn8ff48a82008-11-09 23:40:46 +0100168 mutex_unlock(&rt2x00dev->csr_mutex);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700169}
170
Adam Baker0e14f6d2007-10-27 13:41:25 +0200171static void rt2500usb_bbp_read(struct rt2x00_dev *rt2x00dev,
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700172 const unsigned int word, u8 *value)
173{
174 u16 reg;
175
Ivo van Doorn8ff48a82008-11-09 23:40:46 +0100176 mutex_lock(&rt2x00dev->csr_mutex);
Adam Baker3d823462007-10-27 13:43:29 +0200177
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700178 /*
Ivo van Doornc9c3b1a2008-11-10 19:41:40 +0100179 * Wait until the BBP becomes available, afterwards we
180 * can safely write the read request into the register.
181 * After the data has been written, we wait until hardware
182 * returns the correct value, if at any time the register
183 * doesn't become available in time, reg will be 0xffffffff
184 * which means we return 0xff to the caller.
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700185 */
Ivo van Doornc9c3b1a2008-11-10 19:41:40 +0100186 if (WAIT_FOR_BBP(rt2x00dev, &reg)) {
187 reg = 0;
188 rt2x00_set_field16(&reg, PHY_CSR7_REG_ID, word);
189 rt2x00_set_field16(&reg, PHY_CSR7_READ_CONTROL, 1);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700190
Ivo van Doornc9c3b1a2008-11-10 19:41:40 +0100191 rt2500usb_register_write_lock(rt2x00dev, PHY_CSR7, reg);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700192
Ivo van Doornc9c3b1a2008-11-10 19:41:40 +0100193 if (WAIT_FOR_BBP(rt2x00dev, &reg))
194 rt2500usb_register_read_lock(rt2x00dev, PHY_CSR7, &reg);
195 }
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700196
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700197 *value = rt2x00_get_field16(reg, PHY_CSR7_DATA);
Adam Baker3d823462007-10-27 13:43:29 +0200198
Ivo van Doorn8ff48a82008-11-09 23:40:46 +0100199 mutex_unlock(&rt2x00dev->csr_mutex);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700200}
201
Adam Baker0e14f6d2007-10-27 13:41:25 +0200202static void rt2500usb_rf_write(struct rt2x00_dev *rt2x00dev,
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700203 const unsigned int word, const u32 value)
204{
205 u16 reg;
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700206
Ivo van Doorn8ff48a82008-11-09 23:40:46 +0100207 mutex_lock(&rt2x00dev->csr_mutex);
Adam Baker3d823462007-10-27 13:43:29 +0200208
Ivo van Doornc9c3b1a2008-11-10 19:41:40 +0100209 /*
210 * Wait until the RF becomes available, afterwards we
211 * can safely write the new data into the register.
212 */
213 if (WAIT_FOR_RF(rt2x00dev, &reg)) {
214 reg = 0;
215 rt2x00_set_field16(&reg, PHY_CSR9_RF_VALUE, value);
216 rt2500usb_register_write_lock(rt2x00dev, PHY_CSR9, reg);
217
218 reg = 0;
219 rt2x00_set_field16(&reg, PHY_CSR10_RF_VALUE, value >> 16);
220 rt2x00_set_field16(&reg, PHY_CSR10_RF_NUMBER_OF_BITS, 20);
221 rt2x00_set_field16(&reg, PHY_CSR10_RF_IF_SELECT, 0);
222 rt2x00_set_field16(&reg, PHY_CSR10_RF_BUSY, 1);
223
224 rt2500usb_register_write_lock(rt2x00dev, PHY_CSR10, reg);
225 rt2x00_rf_write(rt2x00dev, word, value);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700226 }
227
Ivo van Doorn8ff48a82008-11-09 23:40:46 +0100228 mutex_unlock(&rt2x00dev->csr_mutex);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700229}
230
231#ifdef CONFIG_RT2X00_LIB_DEBUGFS
Ivo van Doorn743b97c2008-10-29 19:41:03 +0100232static void _rt2500usb_register_read(struct rt2x00_dev *rt2x00dev,
233 const unsigned int offset,
234 u32 *value)
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700235{
Ivo van Doorn743b97c2008-10-29 19:41:03 +0100236 rt2500usb_register_read(rt2x00dev, offset, (u16 *)value);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700237}
238
Ivo van Doorn743b97c2008-10-29 19:41:03 +0100239static void _rt2500usb_register_write(struct rt2x00_dev *rt2x00dev,
240 const unsigned int offset,
241 u32 value)
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700242{
Ivo van Doorn743b97c2008-10-29 19:41:03 +0100243 rt2500usb_register_write(rt2x00dev, offset, value);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700244}
245
246static const struct rt2x00debug rt2500usb_rt2x00debug = {
247 .owner = THIS_MODULE,
248 .csr = {
Ivo van Doorn743b97c2008-10-29 19:41:03 +0100249 .read = _rt2500usb_register_read,
250 .write = _rt2500usb_register_write,
251 .flags = RT2X00DEBUGFS_OFFSET,
252 .word_base = CSR_REG_BASE,
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700253 .word_size = sizeof(u16),
254 .word_count = CSR_REG_SIZE / sizeof(u16),
255 },
256 .eeprom = {
257 .read = rt2x00_eeprom_read,
258 .write = rt2x00_eeprom_write,
Ivo van Doorn743b97c2008-10-29 19:41:03 +0100259 .word_base = EEPROM_BASE,
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700260 .word_size = sizeof(u16),
261 .word_count = EEPROM_SIZE / sizeof(u16),
262 },
263 .bbp = {
264 .read = rt2500usb_bbp_read,
265 .write = rt2500usb_bbp_write,
Ivo van Doorn743b97c2008-10-29 19:41:03 +0100266 .word_base = BBP_BASE,
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700267 .word_size = sizeof(u8),
268 .word_count = BBP_SIZE / sizeof(u8),
269 },
270 .rf = {
271 .read = rt2x00_rf_read,
272 .write = rt2500usb_rf_write,
Ivo van Doorn743b97c2008-10-29 19:41:03 +0100273 .word_base = RF_BASE,
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700274 .word_size = sizeof(u32),
275 .word_count = RF_SIZE / sizeof(u32),
276 },
277};
278#endif /* CONFIG_RT2X00_LIB_DEBUGFS */
279
Ivo van Doorn7396faf2008-12-20 10:55:57 +0100280static int rt2500usb_rfkill_poll(struct rt2x00_dev *rt2x00dev)
281{
282 u16 reg;
283
284 rt2500usb_register_read(rt2x00dev, MAC_CSR19, &reg);
285 return rt2x00_get_field32(reg, MAC_CSR19_BIT7);
286}
Ivo van Doorn7396faf2008-12-20 10:55:57 +0100287
Ivo van Doorn771fd562008-09-08 19:07:15 +0200288#ifdef CONFIG_RT2X00_LIB_LEDS
Ivo van Doorna2e1d522008-03-31 15:53:44 +0200289static void rt2500usb_brightness_set(struct led_classdev *led_cdev,
Ivo van Doorna9450b72008-02-03 15:53:40 +0100290 enum led_brightness brightness)
291{
292 struct rt2x00_led *led =
293 container_of(led_cdev, struct rt2x00_led, led_dev);
294 unsigned int enabled = brightness != LED_OFF;
Ivo van Doorna2e1d522008-03-31 15:53:44 +0200295 u16 reg;
Ivo van Doorna9450b72008-02-03 15:53:40 +0100296
Ivo van Doorna2e1d522008-03-31 15:53:44 +0200297 rt2500usb_register_read(led->rt2x00dev, MAC_CSR20, &reg);
Ivo van Doorn47b10cd2008-02-17 17:35:28 +0100298
Ivo van Doorna2e1d522008-03-31 15:53:44 +0200299 if (led->type == LED_TYPE_RADIO || led->type == LED_TYPE_ASSOC)
300 rt2x00_set_field16(&reg, MAC_CSR20_LINK, enabled);
301 else if (led->type == LED_TYPE_ACTIVITY)
302 rt2x00_set_field16(&reg, MAC_CSR20_ACTIVITY, enabled);
Ivo van Doorna9450b72008-02-03 15:53:40 +0100303
Ivo van Doorna2e1d522008-03-31 15:53:44 +0200304 rt2500usb_register_write(led->rt2x00dev, MAC_CSR20, reg);
Ivo van Doorna9450b72008-02-03 15:53:40 +0100305}
Ivo van Doorna2e1d522008-03-31 15:53:44 +0200306
307static int rt2500usb_blink_set(struct led_classdev *led_cdev,
308 unsigned long *delay_on,
309 unsigned long *delay_off)
310{
311 struct rt2x00_led *led =
312 container_of(led_cdev, struct rt2x00_led, led_dev);
313 u16 reg;
314
315 rt2500usb_register_read(led->rt2x00dev, MAC_CSR21, &reg);
316 rt2x00_set_field16(&reg, MAC_CSR21_ON_PERIOD, *delay_on);
317 rt2x00_set_field16(&reg, MAC_CSR21_OFF_PERIOD, *delay_off);
318 rt2500usb_register_write(led->rt2x00dev, MAC_CSR21, reg);
319
320 return 0;
321}
Ivo van Doorn475433b2008-06-03 20:30:01 +0200322
323static void rt2500usb_init_led(struct rt2x00_dev *rt2x00dev,
324 struct rt2x00_led *led,
325 enum led_type type)
326{
327 led->rt2x00dev = rt2x00dev;
328 led->type = type;
329 led->led_dev.brightness_set = rt2500usb_brightness_set;
330 led->led_dev.blink_set = rt2500usb_blink_set;
331 led->flags = LED_INITIALIZED;
332}
Ivo van Doorn771fd562008-09-08 19:07:15 +0200333#endif /* CONFIG_RT2X00_LIB_LEDS */
Ivo van Doorna9450b72008-02-03 15:53:40 +0100334
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700335/*
336 * Configuration handlers.
337 */
Ivo van Doorndddfb472008-12-02 18:20:42 +0100338
339/*
340 * rt2500usb does not differentiate between shared and pairwise
341 * keys, so we should use the same function for both key types.
342 */
343static int rt2500usb_config_key(struct rt2x00_dev *rt2x00dev,
344 struct rt2x00lib_crypto *crypto,
345 struct ieee80211_key_conf *key)
346{
347 int timeout;
348 u32 mask;
349 u16 reg;
350
351 if (crypto->cmd == SET_KEY) {
352 /*
353 * Pairwise key will always be entry 0, but this
354 * could collide with a shared key on the same
355 * position...
356 */
357 mask = TXRX_CSR0_KEY_ID.bit_mask;
358
359 rt2500usb_register_read(rt2x00dev, TXRX_CSR0, &reg);
360 reg &= mask;
361
362 if (reg && reg == mask)
363 return -ENOSPC;
364
365 reg = rt2x00_get_field16(reg, TXRX_CSR0_KEY_ID);
366
367 key->hw_key_idx += reg ? ffz(reg) : 0;
368
369 /*
370 * The encryption key doesn't fit within the CSR cache,
371 * this means we should allocate it seperately and use
372 * rt2x00usb_vendor_request() to send the key to the hardware.
373 */
374 reg = KEY_ENTRY(key->hw_key_idx);
375 timeout = REGISTER_TIMEOUT32(sizeof(crypto->key));
376 rt2x00usb_vendor_request_large_buff(rt2x00dev, USB_MULTI_WRITE,
377 USB_VENDOR_REQUEST_OUT, reg,
378 crypto->key,
379 sizeof(crypto->key),
380 timeout);
381
382 /*
383 * The driver does not support the IV/EIV generation
Ivo van Doornf3d340c2008-12-21 23:19:17 +0100384 * in hardware. However it demands the data to be provided
385 * both seperately as well as inside the frame.
386 * We already provided the CONFIG_CRYPTO_COPY_IV to rt2x00lib
387 * to ensure rt2x00lib will not strip the data from the
388 * frame after the copy, now we must tell mac80211
Ivo van Doorndddfb472008-12-02 18:20:42 +0100389 * to generate the IV/EIV data.
390 */
391 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
392 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
393 }
394
395 /*
396 * TXRX_CSR0_KEY_ID contains only single-bit fields to indicate
397 * a particular key is valid.
398 */
399 rt2500usb_register_read(rt2x00dev, TXRX_CSR0, &reg);
400 rt2x00_set_field16(&reg, TXRX_CSR0_ALGORITHM, crypto->cipher);
401 rt2x00_set_field16(&reg, TXRX_CSR0_IV_OFFSET, IEEE80211_HEADER);
402
403 mask = rt2x00_get_field16(reg, TXRX_CSR0_KEY_ID);
404 if (crypto->cmd == SET_KEY)
405 mask |= 1 << key->hw_key_idx;
406 else if (crypto->cmd == DISABLE_KEY)
407 mask &= ~(1 << key->hw_key_idx);
408 rt2x00_set_field16(&reg, TXRX_CSR0_KEY_ID, mask);
409 rt2500usb_register_write(rt2x00dev, TXRX_CSR0, reg);
410
411 return 0;
412}
413
Ivo van Doorn3a643d22008-03-25 14:13:18 +0100414static void rt2500usb_config_filter(struct rt2x00_dev *rt2x00dev,
415 const unsigned int filter_flags)
416{
417 u16 reg;
418
419 /*
420 * Start configuration steps.
421 * Note that the version error will always be dropped
422 * and broadcast frames will always be accepted since
423 * there is no filter for it at this time.
424 */
425 rt2500usb_register_read(rt2x00dev, TXRX_CSR2, &reg);
426 rt2x00_set_field16(&reg, TXRX_CSR2_DROP_CRC,
427 !(filter_flags & FIF_FCSFAIL));
428 rt2x00_set_field16(&reg, TXRX_CSR2_DROP_PHYSICAL,
429 !(filter_flags & FIF_PLCPFAIL));
430 rt2x00_set_field16(&reg, TXRX_CSR2_DROP_CONTROL,
431 !(filter_flags & FIF_CONTROL));
432 rt2x00_set_field16(&reg, TXRX_CSR2_DROP_NOT_TO_ME,
433 !(filter_flags & FIF_PROMISC_IN_BSS));
434 rt2x00_set_field16(&reg, TXRX_CSR2_DROP_TODS,
Ivo van Doorne0b005f2008-03-31 15:24:53 +0200435 !(filter_flags & FIF_PROMISC_IN_BSS) &&
436 !rt2x00dev->intf_ap_count);
Ivo van Doorn3a643d22008-03-25 14:13:18 +0100437 rt2x00_set_field16(&reg, TXRX_CSR2_DROP_VERSION_ERROR, 1);
438 rt2x00_set_field16(&reg, TXRX_CSR2_DROP_MULTICAST,
439 !(filter_flags & FIF_ALLMULTI));
440 rt2x00_set_field16(&reg, TXRX_CSR2_DROP_BROADCAST, 0);
441 rt2500usb_register_write(rt2x00dev, TXRX_CSR2, reg);
442}
443
Ivo van Doorn6bb40dd2008-02-03 15:49:59 +0100444static void rt2500usb_config_intf(struct rt2x00_dev *rt2x00dev,
445 struct rt2x00_intf *intf,
446 struct rt2x00intf_conf *conf,
447 const unsigned int flags)
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700448{
Ivo van Doorn6bb40dd2008-02-03 15:49:59 +0100449 unsigned int bcn_preload;
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700450 u16 reg;
451
Ivo van Doorn6bb40dd2008-02-03 15:49:59 +0100452 if (flags & CONFIG_UPDATE_TYPE) {
Ivo van Doorn6bb40dd2008-02-03 15:49:59 +0100453 /*
454 * Enable beacon config
455 */
Ivo van Doornbad13632008-11-09 20:47:00 +0100456 bcn_preload = PREAMBLE + GET_DURATION(IEEE80211_HEADER, 20);
Ivo van Doorn6bb40dd2008-02-03 15:49:59 +0100457 rt2500usb_register_read(rt2x00dev, TXRX_CSR20, &reg);
458 rt2x00_set_field16(&reg, TXRX_CSR20_OFFSET, bcn_preload >> 6);
459 rt2x00_set_field16(&reg, TXRX_CSR20_BCN_EXPECT_WINDOW,
Johannes Berg05c914f2008-09-11 00:01:58 +0200460 2 * (conf->type != NL80211_IFTYPE_STATION));
Ivo van Doorn6bb40dd2008-02-03 15:49:59 +0100461 rt2500usb_register_write(rt2x00dev, TXRX_CSR20, reg);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700462
Ivo van Doorn6bb40dd2008-02-03 15:49:59 +0100463 /*
464 * Enable synchronisation.
465 */
466 rt2500usb_register_read(rt2x00dev, TXRX_CSR18, &reg);
467 rt2x00_set_field16(&reg, TXRX_CSR18_OFFSET, 0);
468 rt2500usb_register_write(rt2x00dev, TXRX_CSR18, reg);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700469
Ivo van Doorn6bb40dd2008-02-03 15:49:59 +0100470 rt2500usb_register_read(rt2x00dev, TXRX_CSR19, &reg);
Ivo van Doornfd3c91c2008-03-09 22:47:43 +0100471 rt2x00_set_field16(&reg, TXRX_CSR19_TSF_COUNT, 1);
Ivo van Doorn6bb40dd2008-02-03 15:49:59 +0100472 rt2x00_set_field16(&reg, TXRX_CSR19_TSF_SYNC, conf->sync);
Ivo van Doornfd3c91c2008-03-09 22:47:43 +0100473 rt2x00_set_field16(&reg, TXRX_CSR19_TBCN, 1);
Ivo van Doorn6bb40dd2008-02-03 15:49:59 +0100474 rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg);
Ivo van Doorn5c58ee52007-10-06 13:34:52 +0200475 }
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700476
Ivo van Doorn6bb40dd2008-02-03 15:49:59 +0100477 if (flags & CONFIG_UPDATE_MAC)
478 rt2500usb_register_multiwrite(rt2x00dev, MAC_CSR2, conf->mac,
479 (3 * sizeof(__le16)));
480
481 if (flags & CONFIG_UPDATE_BSSID)
482 rt2500usb_register_multiwrite(rt2x00dev, MAC_CSR5, conf->bssid,
483 (3 * sizeof(__le16)));
484}
485
Ivo van Doorn3a643d22008-03-25 14:13:18 +0100486static void rt2500usb_config_erp(struct rt2x00_dev *rt2x00dev,
487 struct rt2x00lib_erp *erp)
Ivo van Doorn6bb40dd2008-02-03 15:49:59 +0100488{
489 u16 reg;
490
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700491 rt2500usb_register_read(rt2x00dev, TXRX_CSR10, &reg);
Ivo van Doorn4f5af6e2007-10-06 14:16:30 +0200492 rt2x00_set_field16(&reg, TXRX_CSR10_AUTORESPOND_PREAMBLE,
Ivo van Doorn72810372008-03-09 22:46:18 +0100493 !!erp->short_preamble);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700494 rt2500usb_register_write(rt2x00dev, TXRX_CSR10, reg);
Ivo van Doorne4ea1c42008-10-29 17:17:57 +0100495
496 rt2500usb_register_write(rt2x00dev, TXRX_CSR11, erp->basic_rates);
497
Ivo van Doorn8a566af2009-05-21 19:16:46 +0200498 rt2500usb_register_read(rt2x00dev, TXRX_CSR18, &reg);
499 rt2x00_set_field16(&reg, TXRX_CSR18_INTERVAL, erp->beacon_int * 4);
500 rt2500usb_register_write(rt2x00dev, TXRX_CSR18, reg);
501
Ivo van Doorne4ea1c42008-10-29 17:17:57 +0100502 rt2500usb_register_write(rt2x00dev, MAC_CSR10, erp->slot_time);
503 rt2500usb_register_write(rt2x00dev, MAC_CSR11, erp->sifs);
504 rt2500usb_register_write(rt2x00dev, MAC_CSR12, erp->eifs);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700505}
506
Ivo van Doorne4ea1c42008-10-29 17:17:57 +0100507static void rt2500usb_config_ant(struct rt2x00_dev *rt2x00dev,
508 struct antenna_setup *ant)
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700509{
510 u8 r2;
511 u8 r14;
512 u16 csr5;
513 u16 csr6;
514
Ivo van Doorna4fe07d2008-03-09 22:45:21 +0100515 /*
516 * We should never come here because rt2x00lib is supposed
517 * to catch this and send us the correct antenna explicitely.
518 */
519 BUG_ON(ant->rx == ANTENNA_SW_DIVERSITY ||
520 ant->tx == ANTENNA_SW_DIVERSITY);
521
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700522 rt2500usb_bbp_read(rt2x00dev, 2, &r2);
523 rt2500usb_bbp_read(rt2x00dev, 14, &r14);
524 rt2500usb_register_read(rt2x00dev, PHY_CSR5, &csr5);
525 rt2500usb_register_read(rt2x00dev, PHY_CSR6, &csr6);
526
527 /*
528 * Configure the TX antenna.
529 */
Ivo van Doornaddc81b2007-10-13 16:26:23 +0200530 switch (ant->tx) {
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700531 case ANTENNA_HW_DIVERSITY:
532 rt2x00_set_field8(&r2, BBP_R2_TX_ANTENNA, 1);
533 rt2x00_set_field16(&csr5, PHY_CSR5_CCK, 1);
534 rt2x00_set_field16(&csr6, PHY_CSR6_OFDM, 1);
535 break;
536 case ANTENNA_A:
537 rt2x00_set_field8(&r2, BBP_R2_TX_ANTENNA, 0);
538 rt2x00_set_field16(&csr5, PHY_CSR5_CCK, 0);
539 rt2x00_set_field16(&csr6, PHY_CSR6_OFDM, 0);
540 break;
541 case ANTENNA_B:
Ivo van Doorna4fe07d2008-03-09 22:45:21 +0100542 default:
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700543 rt2x00_set_field8(&r2, BBP_R2_TX_ANTENNA, 2);
544 rt2x00_set_field16(&csr5, PHY_CSR5_CCK, 2);
545 rt2x00_set_field16(&csr6, PHY_CSR6_OFDM, 2);
546 break;
547 }
548
549 /*
550 * Configure the RX antenna.
551 */
Ivo van Doornaddc81b2007-10-13 16:26:23 +0200552 switch (ant->rx) {
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700553 case ANTENNA_HW_DIVERSITY:
554 rt2x00_set_field8(&r14, BBP_R14_RX_ANTENNA, 1);
555 break;
556 case ANTENNA_A:
557 rt2x00_set_field8(&r14, BBP_R14_RX_ANTENNA, 0);
558 break;
559 case ANTENNA_B:
Ivo van Doorna4fe07d2008-03-09 22:45:21 +0100560 default:
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700561 rt2x00_set_field8(&r14, BBP_R14_RX_ANTENNA, 2);
562 break;
563 }
564
565 /*
566 * RT2525E and RT5222 need to flip TX I/Q
567 */
568 if (rt2x00_rf(&rt2x00dev->chip, RF2525E) ||
569 rt2x00_rf(&rt2x00dev->chip, RF5222)) {
570 rt2x00_set_field8(&r2, BBP_R2_TX_IQ_FLIP, 1);
571 rt2x00_set_field16(&csr5, PHY_CSR5_CCK_FLIP, 1);
572 rt2x00_set_field16(&csr6, PHY_CSR6_OFDM_FLIP, 1);
573
574 /*
575 * RT2525E does not need RX I/Q Flip.
576 */
577 if (rt2x00_rf(&rt2x00dev->chip, RF2525E))
578 rt2x00_set_field8(&r14, BBP_R14_RX_IQ_FLIP, 0);
579 } else {
580 rt2x00_set_field16(&csr5, PHY_CSR5_CCK_FLIP, 0);
581 rt2x00_set_field16(&csr6, PHY_CSR6_OFDM_FLIP, 0);
582 }
583
584 rt2500usb_bbp_write(rt2x00dev, 2, r2);
585 rt2500usb_bbp_write(rt2x00dev, 14, r14);
586 rt2500usb_register_write(rt2x00dev, PHY_CSR5, csr5);
587 rt2500usb_register_write(rt2x00dev, PHY_CSR6, csr6);
588}
589
Ivo van Doorne4ea1c42008-10-29 17:17:57 +0100590static void rt2500usb_config_channel(struct rt2x00_dev *rt2x00dev,
591 struct rf_channel *rf, const int txpower)
592{
593 /*
594 * Set TXpower.
595 */
596 rt2x00_set_field32(&rf->rf3, RF3_TXPOWER, TXPOWER_TO_DEV(txpower));
597
598 /*
599 * For RT2525E we should first set the channel to half band higher.
600 */
601 if (rt2x00_rf(&rt2x00dev->chip, RF2525E)) {
602 static const u32 vals[] = {
603 0x000008aa, 0x000008ae, 0x000008ae, 0x000008b2,
604 0x000008b2, 0x000008b6, 0x000008b6, 0x000008ba,
605 0x000008ba, 0x000008be, 0x000008b7, 0x00000902,
606 0x00000902, 0x00000906
607 };
608
609 rt2500usb_rf_write(rt2x00dev, 2, vals[rf->channel - 1]);
610 if (rf->rf4)
611 rt2500usb_rf_write(rt2x00dev, 4, rf->rf4);
612 }
613
614 rt2500usb_rf_write(rt2x00dev, 1, rf->rf1);
615 rt2500usb_rf_write(rt2x00dev, 2, rf->rf2);
616 rt2500usb_rf_write(rt2x00dev, 3, rf->rf3);
617 if (rf->rf4)
618 rt2500usb_rf_write(rt2x00dev, 4, rf->rf4);
619}
620
621static void rt2500usb_config_txpower(struct rt2x00_dev *rt2x00dev,
622 const int txpower)
623{
624 u32 rf3;
625
626 rt2x00_rf_read(rt2x00dev, 3, &rf3);
627 rt2x00_set_field32(&rf3, RF3_TXPOWER, TXPOWER_TO_DEV(txpower));
628 rt2500usb_rf_write(rt2x00dev, 3, rf3);
629}
630
Ivo van Doorn7d7f19c2008-12-20 10:52:42 +0100631static void rt2500usb_config_ps(struct rt2x00_dev *rt2x00dev,
632 struct rt2x00lib_conf *libconf)
633{
634 enum dev_state state =
635 (libconf->conf->flags & IEEE80211_CONF_PS) ?
636 STATE_SLEEP : STATE_AWAKE;
637 u16 reg;
638
639 if (state == STATE_SLEEP) {
640 rt2500usb_register_read(rt2x00dev, MAC_CSR18, &reg);
641 rt2x00_set_field16(&reg, MAC_CSR18_DELAY_AFTER_BEACON,
Ivo van Doorn6b347bf2009-05-23 21:09:28 +0200642 rt2x00dev->beacon_int - 20);
Ivo van Doorn7d7f19c2008-12-20 10:52:42 +0100643 rt2x00_set_field16(&reg, MAC_CSR18_BEACONS_BEFORE_WAKEUP,
644 libconf->conf->listen_interval - 1);
645
646 /* We must first disable autowake before it can be enabled */
647 rt2x00_set_field16(&reg, MAC_CSR18_AUTO_WAKE, 0);
648 rt2500usb_register_write(rt2x00dev, MAC_CSR18, reg);
649
650 rt2x00_set_field16(&reg, MAC_CSR18_AUTO_WAKE, 1);
651 rt2500usb_register_write(rt2x00dev, MAC_CSR18, reg);
652 }
653
654 rt2x00dev->ops->lib->set_device_state(rt2x00dev, state);
655}
656
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700657static void rt2500usb_config(struct rt2x00_dev *rt2x00dev,
Ivo van Doorn6bb40dd2008-02-03 15:49:59 +0100658 struct rt2x00lib_conf *libconf,
659 const unsigned int flags)
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700660{
Ivo van Doorne4ea1c42008-10-29 17:17:57 +0100661 if (flags & IEEE80211_CONF_CHANGE_CHANNEL)
Ivo van Doorn5c58ee52007-10-06 13:34:52 +0200662 rt2500usb_config_channel(rt2x00dev, &libconf->rf,
663 libconf->conf->power_level);
Ivo van Doorne4ea1c42008-10-29 17:17:57 +0100664 if ((flags & IEEE80211_CONF_CHANGE_POWER) &&
665 !(flags & IEEE80211_CONF_CHANGE_CHANNEL))
Ivo van Doorn5c58ee52007-10-06 13:34:52 +0200666 rt2500usb_config_txpower(rt2x00dev,
667 libconf->conf->power_level);
Ivo van Doorn7d7f19c2008-12-20 10:52:42 +0100668 if (flags & IEEE80211_CONF_CHANGE_PS)
669 rt2500usb_config_ps(rt2x00dev, libconf);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700670}
671
672/*
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700673 * Link tuning
674 */
Ivo van Doornebcf26d2007-10-13 16:26:12 +0200675static void rt2500usb_link_stats(struct rt2x00_dev *rt2x00dev,
676 struct link_qual *qual)
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700677{
678 u16 reg;
679
680 /*
681 * Update FCS error count from register.
682 */
683 rt2500usb_register_read(rt2x00dev, STA_CSR0, &reg);
Ivo van Doornebcf26d2007-10-13 16:26:12 +0200684 qual->rx_failed = rt2x00_get_field16(reg, STA_CSR0_FCS_ERROR);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700685
686 /*
687 * Update False CCA count from register.
688 */
689 rt2500usb_register_read(rt2x00dev, STA_CSR3, &reg);
Ivo van Doornebcf26d2007-10-13 16:26:12 +0200690 qual->false_cca = rt2x00_get_field16(reg, STA_CSR3_FALSE_CCA_ERROR);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700691}
692
Ivo van Doorn5352ff62008-12-20 10:54:54 +0100693static void rt2500usb_reset_tuner(struct rt2x00_dev *rt2x00dev,
694 struct link_qual *qual)
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700695{
696 u16 eeprom;
697 u16 value;
698
699 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R24, &eeprom);
700 value = rt2x00_get_field16(eeprom, EEPROM_BBPTUNE_R24_LOW);
701 rt2500usb_bbp_write(rt2x00dev, 24, value);
702
703 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R25, &eeprom);
704 value = rt2x00_get_field16(eeprom, EEPROM_BBPTUNE_R25_LOW);
705 rt2500usb_bbp_write(rt2x00dev, 25, value);
706
707 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R61, &eeprom);
708 value = rt2x00_get_field16(eeprom, EEPROM_BBPTUNE_R61_LOW);
709 rt2500usb_bbp_write(rt2x00dev, 61, value);
710
711 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_VGC, &eeprom);
712 value = rt2x00_get_field16(eeprom, EEPROM_BBPTUNE_VGCUPPER);
713 rt2500usb_bbp_write(rt2x00dev, 17, value);
714
Ivo van Doorn5352ff62008-12-20 10:54:54 +0100715 qual->vgc_level = value;
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700716}
717
Ivo van Doornd06193f2008-08-03 23:36:01 +0200718/*
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700719 * Initialization functions.
720 */
721static int rt2500usb_init_registers(struct rt2x00_dev *rt2x00dev)
722{
723 u16 reg;
724
725 rt2x00usb_vendor_request_sw(rt2x00dev, USB_DEVICE_MODE, 0x0001,
726 USB_MODE_TEST, REGISTER_TIMEOUT);
727 rt2x00usb_vendor_request_sw(rt2x00dev, USB_SINGLE_WRITE, 0x0308,
728 0x00f0, REGISTER_TIMEOUT);
729
730 rt2500usb_register_read(rt2x00dev, TXRX_CSR2, &reg);
731 rt2x00_set_field16(&reg, TXRX_CSR2_DISABLE_RX, 1);
732 rt2500usb_register_write(rt2x00dev, TXRX_CSR2, reg);
733
734 rt2500usb_register_write(rt2x00dev, MAC_CSR13, 0x1111);
735 rt2500usb_register_write(rt2x00dev, MAC_CSR14, 0x1e11);
736
737 rt2500usb_register_read(rt2x00dev, MAC_CSR1, &reg);
738 rt2x00_set_field16(&reg, MAC_CSR1_SOFT_RESET, 1);
739 rt2x00_set_field16(&reg, MAC_CSR1_BBP_RESET, 1);
740 rt2x00_set_field16(&reg, MAC_CSR1_HOST_READY, 0);
741 rt2500usb_register_write(rt2x00dev, MAC_CSR1, reg);
742
743 rt2500usb_register_read(rt2x00dev, MAC_CSR1, &reg);
744 rt2x00_set_field16(&reg, MAC_CSR1_SOFT_RESET, 0);
745 rt2x00_set_field16(&reg, MAC_CSR1_BBP_RESET, 0);
746 rt2x00_set_field16(&reg, MAC_CSR1_HOST_READY, 0);
747 rt2500usb_register_write(rt2x00dev, MAC_CSR1, reg);
748
749 rt2500usb_register_read(rt2x00dev, TXRX_CSR5, &reg);
750 rt2x00_set_field16(&reg, TXRX_CSR5_BBP_ID0, 13);
751 rt2x00_set_field16(&reg, TXRX_CSR5_BBP_ID0_VALID, 1);
752 rt2x00_set_field16(&reg, TXRX_CSR5_BBP_ID1, 12);
753 rt2x00_set_field16(&reg, TXRX_CSR5_BBP_ID1_VALID, 1);
754 rt2500usb_register_write(rt2x00dev, TXRX_CSR5, reg);
755
756 rt2500usb_register_read(rt2x00dev, TXRX_CSR6, &reg);
757 rt2x00_set_field16(&reg, TXRX_CSR6_BBP_ID0, 10);
758 rt2x00_set_field16(&reg, TXRX_CSR6_BBP_ID0_VALID, 1);
759 rt2x00_set_field16(&reg, TXRX_CSR6_BBP_ID1, 11);
760 rt2x00_set_field16(&reg, TXRX_CSR6_BBP_ID1_VALID, 1);
761 rt2500usb_register_write(rt2x00dev, TXRX_CSR6, reg);
762
763 rt2500usb_register_read(rt2x00dev, TXRX_CSR7, &reg);
764 rt2x00_set_field16(&reg, TXRX_CSR7_BBP_ID0, 7);
765 rt2x00_set_field16(&reg, TXRX_CSR7_BBP_ID0_VALID, 1);
766 rt2x00_set_field16(&reg, TXRX_CSR7_BBP_ID1, 6);
767 rt2x00_set_field16(&reg, TXRX_CSR7_BBP_ID1_VALID, 1);
768 rt2500usb_register_write(rt2x00dev, TXRX_CSR7, reg);
769
770 rt2500usb_register_read(rt2x00dev, TXRX_CSR8, &reg);
771 rt2x00_set_field16(&reg, TXRX_CSR8_BBP_ID0, 5);
772 rt2x00_set_field16(&reg, TXRX_CSR8_BBP_ID0_VALID, 1);
773 rt2x00_set_field16(&reg, TXRX_CSR8_BBP_ID1, 0);
774 rt2x00_set_field16(&reg, TXRX_CSR8_BBP_ID1_VALID, 0);
775 rt2500usb_register_write(rt2x00dev, TXRX_CSR8, reg);
776
Ivo van Doorn1f909162008-07-08 13:45:20 +0200777 rt2500usb_register_read(rt2x00dev, TXRX_CSR19, &reg);
778 rt2x00_set_field16(&reg, TXRX_CSR19_TSF_COUNT, 0);
779 rt2x00_set_field16(&reg, TXRX_CSR19_TSF_SYNC, 0);
780 rt2x00_set_field16(&reg, TXRX_CSR19_TBCN, 0);
781 rt2x00_set_field16(&reg, TXRX_CSR19_BEACON_GEN, 0);
782 rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg);
783
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700784 rt2500usb_register_write(rt2x00dev, TXRX_CSR21, 0xe78f);
785 rt2500usb_register_write(rt2x00dev, MAC_CSR9, 0xff1d);
786
787 if (rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_AWAKE))
788 return -EBUSY;
789
790 rt2500usb_register_read(rt2x00dev, MAC_CSR1, &reg);
791 rt2x00_set_field16(&reg, MAC_CSR1_SOFT_RESET, 0);
792 rt2x00_set_field16(&reg, MAC_CSR1_BBP_RESET, 0);
793 rt2x00_set_field16(&reg, MAC_CSR1_HOST_READY, 1);
794 rt2500usb_register_write(rt2x00dev, MAC_CSR1, reg);
795
Ivo van Doorn755a9572007-11-12 15:02:22 +0100796 if (rt2x00_rev(&rt2x00dev->chip) >= RT2570_VERSION_C) {
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700797 rt2500usb_register_read(rt2x00dev, PHY_CSR2, &reg);
Ivo van Doornddc827f2007-10-13 16:26:42 +0200798 rt2x00_set_field16(&reg, PHY_CSR2_LNA, 0);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700799 } else {
Ivo van Doornddc827f2007-10-13 16:26:42 +0200800 reg = 0;
801 rt2x00_set_field16(&reg, PHY_CSR2_LNA, 1);
802 rt2x00_set_field16(&reg, PHY_CSR2_LNA_MODE, 3);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700803 }
804 rt2500usb_register_write(rt2x00dev, PHY_CSR2, reg);
805
806 rt2500usb_register_write(rt2x00dev, MAC_CSR11, 0x0002);
807 rt2500usb_register_write(rt2x00dev, MAC_CSR22, 0x0053);
808 rt2500usb_register_write(rt2x00dev, MAC_CSR15, 0x01ee);
809 rt2500usb_register_write(rt2x00dev, MAC_CSR16, 0x0000);
810
811 rt2500usb_register_read(rt2x00dev, MAC_CSR8, &reg);
812 rt2x00_set_field16(&reg, MAC_CSR8_MAX_FRAME_UNIT,
813 rt2x00dev->rx->data_size);
814 rt2500usb_register_write(rt2x00dev, MAC_CSR8, reg);
815
816 rt2500usb_register_read(rt2x00dev, TXRX_CSR0, &reg);
817 rt2x00_set_field16(&reg, TXRX_CSR0_IV_OFFSET, IEEE80211_HEADER);
Ivo van Doorndddfb472008-12-02 18:20:42 +0100818 rt2x00_set_field16(&reg, TXRX_CSR0_KEY_ID, 0);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700819 rt2500usb_register_write(rt2x00dev, TXRX_CSR0, reg);
820
821 rt2500usb_register_read(rt2x00dev, MAC_CSR18, &reg);
822 rt2x00_set_field16(&reg, MAC_CSR18_DELAY_AFTER_BEACON, 90);
823 rt2500usb_register_write(rt2x00dev, MAC_CSR18, reg);
824
825 rt2500usb_register_read(rt2x00dev, PHY_CSR4, &reg);
826 rt2x00_set_field16(&reg, PHY_CSR4_LOW_RF_LE, 1);
827 rt2500usb_register_write(rt2x00dev, PHY_CSR4, reg);
828
829 rt2500usb_register_read(rt2x00dev, TXRX_CSR1, &reg);
830 rt2x00_set_field16(&reg, TXRX_CSR1_AUTO_SEQUENCE, 1);
831 rt2500usb_register_write(rt2x00dev, TXRX_CSR1, reg);
832
833 return 0;
834}
835
Ivo van Doorn2b08da32008-06-03 18:58:56 +0200836static int rt2500usb_wait_bbp_ready(struct rt2x00_dev *rt2x00dev)
837{
838 unsigned int i;
839 u8 value;
840
841 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
842 rt2500usb_bbp_read(rt2x00dev, 0, &value);
843 if ((value != 0xff) && (value != 0x00))
844 return 0;
845 udelay(REGISTER_BUSY_DELAY);
846 }
847
848 ERROR(rt2x00dev, "BBP register access failed, aborting.\n");
849 return -EACCES;
850}
851
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700852static int rt2500usb_init_bbp(struct rt2x00_dev *rt2x00dev)
853{
854 unsigned int i;
855 u16 eeprom;
856 u8 value;
857 u8 reg_id;
858
Ivo van Doorn2b08da32008-06-03 18:58:56 +0200859 if (unlikely(rt2500usb_wait_bbp_ready(rt2x00dev)))
860 return -EACCES;
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700861
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700862 rt2500usb_bbp_write(rt2x00dev, 3, 0x02);
863 rt2500usb_bbp_write(rt2x00dev, 4, 0x19);
864 rt2500usb_bbp_write(rt2x00dev, 14, 0x1c);
865 rt2500usb_bbp_write(rt2x00dev, 15, 0x30);
866 rt2500usb_bbp_write(rt2x00dev, 16, 0xac);
867 rt2500usb_bbp_write(rt2x00dev, 18, 0x18);
868 rt2500usb_bbp_write(rt2x00dev, 19, 0xff);
869 rt2500usb_bbp_write(rt2x00dev, 20, 0x1e);
870 rt2500usb_bbp_write(rt2x00dev, 21, 0x08);
871 rt2500usb_bbp_write(rt2x00dev, 22, 0x08);
872 rt2500usb_bbp_write(rt2x00dev, 23, 0x08);
873 rt2500usb_bbp_write(rt2x00dev, 24, 0x80);
874 rt2500usb_bbp_write(rt2x00dev, 25, 0x50);
875 rt2500usb_bbp_write(rt2x00dev, 26, 0x08);
876 rt2500usb_bbp_write(rt2x00dev, 27, 0x23);
877 rt2500usb_bbp_write(rt2x00dev, 30, 0x10);
878 rt2500usb_bbp_write(rt2x00dev, 31, 0x2b);
879 rt2500usb_bbp_write(rt2x00dev, 32, 0xb9);
880 rt2500usb_bbp_write(rt2x00dev, 34, 0x12);
881 rt2500usb_bbp_write(rt2x00dev, 35, 0x50);
882 rt2500usb_bbp_write(rt2x00dev, 39, 0xc4);
883 rt2500usb_bbp_write(rt2x00dev, 40, 0x02);
884 rt2500usb_bbp_write(rt2x00dev, 41, 0x60);
885 rt2500usb_bbp_write(rt2x00dev, 53, 0x10);
886 rt2500usb_bbp_write(rt2x00dev, 54, 0x18);
887 rt2500usb_bbp_write(rt2x00dev, 56, 0x08);
888 rt2500usb_bbp_write(rt2x00dev, 57, 0x10);
889 rt2500usb_bbp_write(rt2x00dev, 58, 0x08);
890 rt2500usb_bbp_write(rt2x00dev, 61, 0x60);
891 rt2500usb_bbp_write(rt2x00dev, 62, 0x10);
892 rt2500usb_bbp_write(rt2x00dev, 75, 0xff);
893
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700894 for (i = 0; i < EEPROM_BBP_SIZE; i++) {
895 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBP_START + i, &eeprom);
896
897 if (eeprom != 0xffff && eeprom != 0x0000) {
898 reg_id = rt2x00_get_field16(eeprom, EEPROM_BBP_REG_ID);
899 value = rt2x00_get_field16(eeprom, EEPROM_BBP_VALUE);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700900 rt2500usb_bbp_write(rt2x00dev, reg_id, value);
901 }
902 }
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700903
904 return 0;
905}
906
907/*
908 * Device state switch handlers.
909 */
910static void rt2500usb_toggle_rx(struct rt2x00_dev *rt2x00dev,
911 enum dev_state state)
912{
913 u16 reg;
914
915 rt2500usb_register_read(rt2x00dev, TXRX_CSR2, &reg);
916 rt2x00_set_field16(&reg, TXRX_CSR2_DISABLE_RX,
Ivo van Doorn2b08da32008-06-03 18:58:56 +0200917 (state == STATE_RADIO_RX_OFF) ||
918 (state == STATE_RADIO_RX_OFF_LINK));
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700919 rt2500usb_register_write(rt2x00dev, TXRX_CSR2, reg);
920}
921
922static int rt2500usb_enable_radio(struct rt2x00_dev *rt2x00dev)
923{
924 /*
925 * Initialize all registers.
926 */
Ivo van Doorn2b08da32008-06-03 18:58:56 +0200927 if (unlikely(rt2500usb_init_registers(rt2x00dev) ||
928 rt2500usb_init_bbp(rt2x00dev)))
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700929 return -EIO;
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700930
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700931 return 0;
932}
933
934static void rt2500usb_disable_radio(struct rt2x00_dev *rt2x00dev)
935{
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700936 rt2500usb_register_write(rt2x00dev, MAC_CSR13, 0x2121);
937 rt2500usb_register_write(rt2x00dev, MAC_CSR14, 0x2121);
938
939 /*
940 * Disable synchronisation.
941 */
942 rt2500usb_register_write(rt2x00dev, TXRX_CSR19, 0);
943
944 rt2x00usb_disable_radio(rt2x00dev);
945}
946
947static int rt2500usb_set_state(struct rt2x00_dev *rt2x00dev,
948 enum dev_state state)
949{
950 u16 reg;
951 u16 reg2;
952 unsigned int i;
953 char put_to_sleep;
954 char bbp_state;
955 char rf_state;
956
957 put_to_sleep = (state != STATE_AWAKE);
958
959 reg = 0;
960 rt2x00_set_field16(&reg, MAC_CSR17_BBP_DESIRE_STATE, state);
961 rt2x00_set_field16(&reg, MAC_CSR17_RF_DESIRE_STATE, state);
962 rt2x00_set_field16(&reg, MAC_CSR17_PUT_TO_SLEEP, put_to_sleep);
963 rt2500usb_register_write(rt2x00dev, MAC_CSR17, reg);
964 rt2x00_set_field16(&reg, MAC_CSR17_SET_STATE, 1);
965 rt2500usb_register_write(rt2x00dev, MAC_CSR17, reg);
966
967 /*
968 * Device is not guaranteed to be in the requested state yet.
969 * We must wait until the register indicates that the
970 * device has entered the correct state.
971 */
972 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
973 rt2500usb_register_read(rt2x00dev, MAC_CSR17, &reg2);
974 bbp_state = rt2x00_get_field16(reg2, MAC_CSR17_BBP_CURR_STATE);
975 rf_state = rt2x00_get_field16(reg2, MAC_CSR17_RF_CURR_STATE);
976 if (bbp_state == state && rf_state == state)
977 return 0;
978 rt2500usb_register_write(rt2x00dev, MAC_CSR17, reg);
979 msleep(30);
980 }
981
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700982 return -EBUSY;
983}
984
985static int rt2500usb_set_device_state(struct rt2x00_dev *rt2x00dev,
986 enum dev_state state)
987{
988 int retval = 0;
989
990 switch (state) {
991 case STATE_RADIO_ON:
992 retval = rt2500usb_enable_radio(rt2x00dev);
993 break;
994 case STATE_RADIO_OFF:
995 rt2500usb_disable_radio(rt2x00dev);
996 break;
997 case STATE_RADIO_RX_ON:
Ivo van Doorn61667d82008-02-25 23:15:05 +0100998 case STATE_RADIO_RX_ON_LINK:
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700999 case STATE_RADIO_RX_OFF:
Ivo van Doorn61667d82008-02-25 23:15:05 +01001000 case STATE_RADIO_RX_OFF_LINK:
Ivo van Doorn2b08da32008-06-03 18:58:56 +02001001 rt2500usb_toggle_rx(rt2x00dev, state);
1002 break;
1003 case STATE_RADIO_IRQ_ON:
1004 case STATE_RADIO_IRQ_OFF:
1005 /* No support, but no error either */
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001006 break;
1007 case STATE_DEEP_SLEEP:
1008 case STATE_SLEEP:
1009 case STATE_STANDBY:
1010 case STATE_AWAKE:
1011 retval = rt2500usb_set_state(rt2x00dev, state);
1012 break;
1013 default:
1014 retval = -ENOTSUPP;
1015 break;
1016 }
1017
Ivo van Doorn2b08da32008-06-03 18:58:56 +02001018 if (unlikely(retval))
1019 ERROR(rt2x00dev, "Device failed to enter state %d (%d).\n",
1020 state, retval);
1021
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001022 return retval;
1023}
1024
1025/*
1026 * TX descriptor initialization
1027 */
1028static void rt2500usb_write_tx_desc(struct rt2x00_dev *rt2x00dev,
Ivo van Doorndd3193e2008-01-06 23:41:10 +01001029 struct sk_buff *skb,
Ivo van Doorn61486e02008-05-10 13:42:31 +02001030 struct txentry_desc *txdesc)
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001031{
Ivo van Doorn181d6902008-02-05 16:42:23 -05001032 struct skb_frame_desc *skbdesc = get_skb_frame_desc(skb);
Ivo van Doorndd3193e2008-01-06 23:41:10 +01001033 __le32 *txd = skbdesc->desc;
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001034 u32 word;
1035
1036 /*
1037 * Start writing the descriptor words.
1038 */
1039 rt2x00_desc_read(txd, 1, &word);
Ivo van Doorndddfb472008-12-02 18:20:42 +01001040 rt2x00_set_field32(&word, TXD_W1_IV_OFFSET, txdesc->iv_offset);
Ivo van Doorn181d6902008-02-05 16:42:23 -05001041 rt2x00_set_field32(&word, TXD_W1_AIFS, txdesc->aifs);
1042 rt2x00_set_field32(&word, TXD_W1_CWMIN, txdesc->cw_min);
1043 rt2x00_set_field32(&word, TXD_W1_CWMAX, txdesc->cw_max);
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001044 rt2x00_desc_write(txd, 1, word);
1045
1046 rt2x00_desc_read(txd, 2, &word);
Ivo van Doorn181d6902008-02-05 16:42:23 -05001047 rt2x00_set_field32(&word, TXD_W2_PLCP_SIGNAL, txdesc->signal);
1048 rt2x00_set_field32(&word, TXD_W2_PLCP_SERVICE, txdesc->service);
1049 rt2x00_set_field32(&word, TXD_W2_PLCP_LENGTH_LOW, txdesc->length_low);
1050 rt2x00_set_field32(&word, TXD_W2_PLCP_LENGTH_HIGH, txdesc->length_high);
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001051 rt2x00_desc_write(txd, 2, word);
1052
Ivo van Doorndddfb472008-12-02 18:20:42 +01001053 if (test_bit(ENTRY_TXD_ENCRYPT, &txdesc->flags)) {
1054 _rt2x00_desc_write(txd, 3, skbdesc->iv[0]);
1055 _rt2x00_desc_write(txd, 4, skbdesc->iv[1]);
1056 }
1057
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001058 rt2x00_desc_read(txd, 0, &word);
Ivo van Doorn61486e02008-05-10 13:42:31 +02001059 rt2x00_set_field32(&word, TXD_W0_RETRY_LIMIT, txdesc->retry_limit);
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001060 rt2x00_set_field32(&word, TXD_W0_MORE_FRAG,
Ivo van Doorn181d6902008-02-05 16:42:23 -05001061 test_bit(ENTRY_TXD_MORE_FRAG, &txdesc->flags));
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001062 rt2x00_set_field32(&word, TXD_W0_ACK,
Ivo van Doorn181d6902008-02-05 16:42:23 -05001063 test_bit(ENTRY_TXD_ACK, &txdesc->flags));
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001064 rt2x00_set_field32(&word, TXD_W0_TIMESTAMP,
Ivo van Doorn181d6902008-02-05 16:42:23 -05001065 test_bit(ENTRY_TXD_REQ_TIMESTAMP, &txdesc->flags));
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001066 rt2x00_set_field32(&word, TXD_W0_OFDM,
Ivo van Doorn076f9582008-12-20 10:59:02 +01001067 (txdesc->rate_mode == RATE_MODE_OFDM));
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001068 rt2x00_set_field32(&word, TXD_W0_NEW_SEQ,
Ivo van Doorn61486e02008-05-10 13:42:31 +02001069 test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags));
Ivo van Doorn181d6902008-02-05 16:42:23 -05001070 rt2x00_set_field32(&word, TXD_W0_IFS, txdesc->ifs);
Mattias Nissler1abc3652008-08-29 21:07:20 +02001071 rt2x00_set_field32(&word, TXD_W0_DATABYTE_COUNT, skb->len);
Ivo van Doornf1dd2b22009-01-03 16:27:14 +01001072 rt2x00_set_field32(&word, TXD_W0_CIPHER, !!txdesc->cipher);
Ivo van Doorndddfb472008-12-02 18:20:42 +01001073 rt2x00_set_field32(&word, TXD_W0_KEY_ID, txdesc->key_idx);
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001074 rt2x00_desc_write(txd, 0, word);
1075}
1076
Ivo van Doornbd88a782008-07-09 15:12:44 +02001077/*
1078 * TX data initialization
1079 */
1080static void rt2500usb_beacondone(struct urb *urb);
1081
1082static void rt2500usb_write_beacon(struct queue_entry *entry)
1083{
1084 struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
1085 struct usb_device *usb_dev = to_usb_device_intf(rt2x00dev->dev);
1086 struct queue_entry_priv_usb_bcn *bcn_priv = entry->priv_data;
1087 struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
Ivo van Doornf1ca2162008-11-13 23:07:33 +01001088 int pipe = usb_sndbulkpipe(usb_dev, entry->queue->usb_endpoint);
Ivo van Doornbd88a782008-07-09 15:12:44 +02001089 int length;
1090 u16 reg;
1091
1092 /*
1093 * Add the descriptor in front of the skb.
1094 */
1095 skb_push(entry->skb, entry->queue->desc_size);
1096 memcpy(entry->skb->data, skbdesc->desc, skbdesc->desc_len);
1097 skbdesc->desc = entry->skb->data;
1098
1099 /*
1100 * Disable beaconing while we are reloading the beacon data,
1101 * otherwise we might be sending out invalid data.
1102 */
1103 rt2500usb_register_read(rt2x00dev, TXRX_CSR19, &reg);
Ivo van Doornbd88a782008-07-09 15:12:44 +02001104 rt2x00_set_field16(&reg, TXRX_CSR19_BEACON_GEN, 0);
1105 rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg);
1106
1107 /*
1108 * USB devices cannot blindly pass the skb->len as the
1109 * length of the data to usb_fill_bulk_urb. Pass the skb
1110 * to the driver to determine what the length should be.
1111 */
Ivo van Doornf1ca2162008-11-13 23:07:33 +01001112 length = rt2x00dev->ops->lib->get_tx_data_len(entry);
Ivo van Doornbd88a782008-07-09 15:12:44 +02001113
1114 usb_fill_bulk_urb(bcn_priv->urb, usb_dev, pipe,
1115 entry->skb->data, length, rt2500usb_beacondone,
1116 entry);
1117
1118 /*
1119 * Second we need to create the guardian byte.
1120 * We only need a single byte, so lets recycle
1121 * the 'flags' field we are not using for beacons.
1122 */
1123 bcn_priv->guardian_data = 0;
1124 usb_fill_bulk_urb(bcn_priv->guardian_urb, usb_dev, pipe,
1125 &bcn_priv->guardian_data, 1, rt2500usb_beacondone,
1126 entry);
1127
1128 /*
1129 * Send out the guardian byte.
1130 */
1131 usb_submit_urb(bcn_priv->guardian_urb, GFP_ATOMIC);
1132}
1133
Ivo van Doornf1ca2162008-11-13 23:07:33 +01001134static int rt2500usb_get_tx_data_len(struct queue_entry *entry)
Ivo van Doorndd9fa2d2007-10-06 14:15:46 +02001135{
1136 int length;
1137
1138 /*
1139 * The length _must_ be a multiple of 2,
1140 * but it must _not_ be a multiple of the USB packet size.
1141 */
Ivo van Doornf1ca2162008-11-13 23:07:33 +01001142 length = roundup(entry->skb->len, 2);
1143 length += (2 * !(length % entry->queue->usb_maxpacket));
Ivo van Doorndd9fa2d2007-10-06 14:15:46 +02001144
1145 return length;
1146}
1147
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001148static void rt2500usb_kick_tx_queue(struct rt2x00_dev *rt2x00dev,
Ivo van Doorne58c6ac2008-04-21 19:00:47 +02001149 const enum data_queue_qid queue)
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001150{
Igor Perminovd6756d02009-08-10 00:58:54 +02001151 u16 reg, reg0;
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001152
Ivo van Doornf019d512008-06-06 22:47:39 +02001153 if (queue != QID_BEACON) {
1154 rt2x00usb_kick_tx_queue(rt2x00dev, queue);
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001155 return;
Ivo van Doornf019d512008-06-06 22:47:39 +02001156 }
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001157
1158 rt2500usb_register_read(rt2x00dev, TXRX_CSR19, &reg);
1159 if (!rt2x00_get_field16(reg, TXRX_CSR19_BEACON_GEN)) {
Ivo van Doorn8af244c2008-03-09 22:42:59 +01001160 rt2x00_set_field16(&reg, TXRX_CSR19_TSF_COUNT, 1);
1161 rt2x00_set_field16(&reg, TXRX_CSR19_TBCN, 1);
Igor Perminovd6756d02009-08-10 00:58:54 +02001162 reg0 = reg;
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001163 rt2x00_set_field16(&reg, TXRX_CSR19_BEACON_GEN, 1);
1164 /*
1165 * Beacon generation will fail initially.
Igor Perminovd6756d02009-08-10 00:58:54 +02001166 * To prevent this we need to change the TXRX_CSR19
1167 * register several times (reg0 is the same as reg
1168 * except for TXRX_CSR19_BEACON_GEN, which is 0 in reg0
1169 * and 1 in reg).
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001170 */
1171 rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg);
Igor Perminovd6756d02009-08-10 00:58:54 +02001172 rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg0);
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001173 rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg);
Igor Perminovd6756d02009-08-10 00:58:54 +02001174 rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg0);
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001175 rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg);
1176 }
1177}
1178
1179/*
1180 * RX control handlers
1181 */
Ivo van Doorn181d6902008-02-05 16:42:23 -05001182static void rt2500usb_fill_rxdone(struct queue_entry *entry,
1183 struct rxdone_entry_desc *rxdesc)
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001184{
Ivo van Doorndddfb472008-12-02 18:20:42 +01001185 struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
Ivo van Doornb8be63f2008-05-10 13:46:03 +02001186 struct queue_entry_priv_usb *entry_priv = entry->priv_data;
Ivo van Doorn181d6902008-02-05 16:42:23 -05001187 struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
1188 __le32 *rxd =
1189 (__le32 *)(entry->skb->data +
Ivo van Doornb8be63f2008-05-10 13:46:03 +02001190 (entry_priv->urb->actual_length -
1191 entry->queue->desc_size));
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001192 u32 word0;
1193 u32 word1;
1194
Ivo van Doornf855c102008-03-09 22:38:18 +01001195 /*
Gertjan van Wingerdea26cbc62008-06-06 22:54:28 +02001196 * Copy descriptor to the skbdesc->desc buffer, making it safe from moving of
1197 * frame data in rt2x00usb.
Ivo van Doornf855c102008-03-09 22:38:18 +01001198 */
Gertjan van Wingerdea26cbc62008-06-06 22:54:28 +02001199 memcpy(skbdesc->desc, rxd, skbdesc->desc_len);
Ivo van Doorn70a96102008-05-10 13:43:38 +02001200 rxd = (__le32 *)skbdesc->desc;
Ivo van Doornf855c102008-03-09 22:38:18 +01001201
1202 /*
Ivo van Doorn70a96102008-05-10 13:43:38 +02001203 * It is now safe to read the descriptor on all architectures.
Ivo van Doornf855c102008-03-09 22:38:18 +01001204 */
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001205 rt2x00_desc_read(rxd, 0, &word0);
1206 rt2x00_desc_read(rxd, 1, &word1);
1207
Johannes Berg4150c572007-09-17 01:29:23 -04001208 if (rt2x00_get_field32(word0, RXD_W0_CRC_ERROR))
Ivo van Doorn181d6902008-02-05 16:42:23 -05001209 rxdesc->flags |= RX_FLAG_FAILED_FCS_CRC;
Johannes Berg4150c572007-09-17 01:29:23 -04001210 if (rt2x00_get_field32(word0, RXD_W0_PHYSICAL_ERROR))
Ivo van Doorn181d6902008-02-05 16:42:23 -05001211 rxdesc->flags |= RX_FLAG_FAILED_PLCP_CRC;
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001212
Ivo van Doorndddfb472008-12-02 18:20:42 +01001213 if (test_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags)) {
1214 rxdesc->cipher = rt2x00_get_field32(word0, RXD_W0_CIPHER);
1215 if (rt2x00_get_field32(word0, RXD_W0_CIPHER_ERROR))
1216 rxdesc->cipher_status = RX_CRYPTO_FAIL_KEY;
1217 }
1218
1219 if (rxdesc->cipher != CIPHER_NONE) {
1220 _rt2x00_desc_read(rxd, 2, &rxdesc->iv[0]);
1221 _rt2x00_desc_read(rxd, 3, &rxdesc->iv[1]);
Ivo van Doorn74415ed2008-12-02 22:50:33 +01001222 rxdesc->dev_flags |= RXDONE_CRYPTO_IV;
1223
Ivo van Doorndddfb472008-12-02 18:20:42 +01001224 /* ICV is located at the end of frame */
1225
Ivo van Doornf3d340c2008-12-21 23:19:17 +01001226 rxdesc->flags |= RX_FLAG_MMIC_STRIPPED;
Ivo van Doorndddfb472008-12-02 18:20:42 +01001227 if (rxdesc->cipher_status == RX_CRYPTO_SUCCESS)
1228 rxdesc->flags |= RX_FLAG_DECRYPTED;
1229 else if (rxdesc->cipher_status == RX_CRYPTO_FAIL_MIC)
1230 rxdesc->flags |= RX_FLAG_MMIC_ERROR;
1231 }
1232
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001233 /*
1234 * Obtain the status about this packet.
Ivo van Doorn89993892008-03-09 22:49:04 +01001235 * When frame was received with an OFDM bitrate,
1236 * the signal is the PLCP value. If it was received with
1237 * a CCK bitrate the signal is the rate in 100kbit/s.
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001238 */
Ivo van Doorn181d6902008-02-05 16:42:23 -05001239 rxdesc->signal = rt2x00_get_field32(word1, RXD_W1_SIGNAL);
Ivo van Doorndddfb472008-12-02 18:20:42 +01001240 rxdesc->rssi =
1241 rt2x00_get_field32(word1, RXD_W1_RSSI) - rt2x00dev->rssi_offset;
Ivo van Doorn181d6902008-02-05 16:42:23 -05001242 rxdesc->size = rt2x00_get_field32(word0, RXD_W0_DATABYTE_COUNT);
Ivo van Doorn19d30e02008-03-15 21:38:07 +01001243
Ivo van Doorn19d30e02008-03-15 21:38:07 +01001244 if (rt2x00_get_field32(word0, RXD_W0_OFDM))
1245 rxdesc->dev_flags |= RXDONE_SIGNAL_PLCP;
Ivo van Doorn6c6aa3c2008-08-29 21:07:16 +02001246 else
1247 rxdesc->dev_flags |= RXDONE_SIGNAL_BITRATE;
Ivo van Doorn19d30e02008-03-15 21:38:07 +01001248 if (rt2x00_get_field32(word0, RXD_W0_MY_BSS))
1249 rxdesc->dev_flags |= RXDONE_MY_BSS;
Ivo van Doorn7d1de802008-01-06 23:42:04 +01001250
1251 /*
Mattias Nissler2ae23852008-03-09 22:41:22 +01001252 * Adjust the skb memory window to the frame boundaries.
1253 */
Mattias Nissler2ae23852008-03-09 22:41:22 +01001254 skb_trim(entry->skb, rxdesc->size);
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001255}
1256
1257/*
1258 * Interrupt functions.
1259 */
1260static void rt2500usb_beacondone(struct urb *urb)
1261{
Ivo van Doorn181d6902008-02-05 16:42:23 -05001262 struct queue_entry *entry = (struct queue_entry *)urb->context;
Ivo van Doornb8be63f2008-05-10 13:46:03 +02001263 struct queue_entry_priv_usb_bcn *bcn_priv = entry->priv_data;
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001264
Ivo van Doorn0262ab02008-08-29 21:04:26 +02001265 if (!test_bit(DEVICE_STATE_ENABLED_RADIO, &entry->queue->rt2x00dev->flags))
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001266 return;
1267
1268 /*
1269 * Check if this was the guardian beacon,
1270 * if that was the case we need to send the real beacon now.
1271 * Otherwise we should free the sk_buffer, the device
1272 * should be doing the rest of the work now.
1273 */
Ivo van Doornb8be63f2008-05-10 13:46:03 +02001274 if (bcn_priv->guardian_urb == urb) {
1275 usb_submit_urb(bcn_priv->urb, GFP_ATOMIC);
1276 } else if (bcn_priv->urb == urb) {
Ivo van Doorn181d6902008-02-05 16:42:23 -05001277 dev_kfree_skb(entry->skb);
1278 entry->skb = NULL;
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001279 }
1280}
1281
1282/*
1283 * Device probe functions.
1284 */
1285static int rt2500usb_validate_eeprom(struct rt2x00_dev *rt2x00dev)
1286{
1287 u16 word;
1288 u8 *mac;
Ivo van Doorn6bb40dd2008-02-03 15:49:59 +01001289 u8 bbp;
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001290
1291 rt2x00usb_eeprom_read(rt2x00dev, rt2x00dev->eeprom, EEPROM_SIZE);
1292
1293 /*
1294 * Start validation of the data that has been read.
1295 */
1296 mac = rt2x00_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0);
1297 if (!is_valid_ether_addr(mac)) {
1298 random_ether_addr(mac);
Johannes Berge1749612008-10-27 15:59:26 -07001299 EEPROM(rt2x00dev, "MAC: %pM\n", mac);
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001300 }
1301
1302 rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &word);
1303 if (word == 0xffff) {
1304 rt2x00_set_field16(&word, EEPROM_ANTENNA_NUM, 2);
Ivo van Doorn362f3b62007-10-13 16:26:18 +02001305 rt2x00_set_field16(&word, EEPROM_ANTENNA_TX_DEFAULT,
1306 ANTENNA_SW_DIVERSITY);
1307 rt2x00_set_field16(&word, EEPROM_ANTENNA_RX_DEFAULT,
1308 ANTENNA_SW_DIVERSITY);
1309 rt2x00_set_field16(&word, EEPROM_ANTENNA_LED_MODE,
1310 LED_MODE_DEFAULT);
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001311 rt2x00_set_field16(&word, EEPROM_ANTENNA_DYN_TXAGC, 0);
1312 rt2x00_set_field16(&word, EEPROM_ANTENNA_HARDWARE_RADIO, 0);
1313 rt2x00_set_field16(&word, EEPROM_ANTENNA_RF_TYPE, RF2522);
1314 rt2x00_eeprom_write(rt2x00dev, EEPROM_ANTENNA, word);
1315 EEPROM(rt2x00dev, "Antenna: 0x%04x\n", word);
1316 }
1317
1318 rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &word);
1319 if (word == 0xffff) {
1320 rt2x00_set_field16(&word, EEPROM_NIC_CARDBUS_ACCEL, 0);
1321 rt2x00_set_field16(&word, EEPROM_NIC_DYN_BBP_TUNE, 0);
1322 rt2x00_set_field16(&word, EEPROM_NIC_CCK_TX_POWER, 0);
1323 rt2x00_eeprom_write(rt2x00dev, EEPROM_NIC, word);
1324 EEPROM(rt2x00dev, "NIC: 0x%04x\n", word);
1325 }
1326
1327 rt2x00_eeprom_read(rt2x00dev, EEPROM_CALIBRATE_OFFSET, &word);
1328 if (word == 0xffff) {
1329 rt2x00_set_field16(&word, EEPROM_CALIBRATE_OFFSET_RSSI,
1330 DEFAULT_RSSI_OFFSET);
1331 rt2x00_eeprom_write(rt2x00dev, EEPROM_CALIBRATE_OFFSET, word);
1332 EEPROM(rt2x00dev, "Calibrate offset: 0x%04x\n", word);
1333 }
1334
1335 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE, &word);
1336 if (word == 0xffff) {
1337 rt2x00_set_field16(&word, EEPROM_BBPTUNE_THRESHOLD, 45);
1338 rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE, word);
1339 EEPROM(rt2x00dev, "BBPtune: 0x%04x\n", word);
1340 }
1341
Ivo van Doorn6bb40dd2008-02-03 15:49:59 +01001342 /*
1343 * Switch lower vgc bound to current BBP R17 value,
1344 * lower the value a bit for better quality.
1345 */
1346 rt2500usb_bbp_read(rt2x00dev, 17, &bbp);
1347 bbp -= 6;
1348
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001349 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_VGC, &word);
1350 if (word == 0xffff) {
1351 rt2x00_set_field16(&word, EEPROM_BBPTUNE_VGCUPPER, 0x40);
Ivo van Doorn6bb40dd2008-02-03 15:49:59 +01001352 rt2x00_set_field16(&word, EEPROM_BBPTUNE_VGCLOWER, bbp);
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001353 rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_VGC, word);
1354 EEPROM(rt2x00dev, "BBPtune vgc: 0x%04x\n", word);
Ivo van Doorn8d8acd42008-07-28 10:20:12 +02001355 } else {
1356 rt2x00_set_field16(&word, EEPROM_BBPTUNE_VGCLOWER, bbp);
1357 rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_VGC, word);
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001358 }
1359
1360 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R17, &word);
1361 if (word == 0xffff) {
1362 rt2x00_set_field16(&word, EEPROM_BBPTUNE_R17_LOW, 0x48);
1363 rt2x00_set_field16(&word, EEPROM_BBPTUNE_R17_HIGH, 0x41);
1364 rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_R17, word);
1365 EEPROM(rt2x00dev, "BBPtune r17: 0x%04x\n", word);
1366 }
1367
1368 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R24, &word);
1369 if (word == 0xffff) {
1370 rt2x00_set_field16(&word, EEPROM_BBPTUNE_R24_LOW, 0x40);
1371 rt2x00_set_field16(&word, EEPROM_BBPTUNE_R24_HIGH, 0x80);
1372 rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_R24, word);
1373 EEPROM(rt2x00dev, "BBPtune r24: 0x%04x\n", word);
1374 }
1375
1376 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R25, &word);
1377 if (word == 0xffff) {
1378 rt2x00_set_field16(&word, EEPROM_BBPTUNE_R25_LOW, 0x40);
1379 rt2x00_set_field16(&word, EEPROM_BBPTUNE_R25_HIGH, 0x50);
1380 rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_R25, word);
1381 EEPROM(rt2x00dev, "BBPtune r25: 0x%04x\n", word);
1382 }
1383
1384 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R61, &word);
1385 if (word == 0xffff) {
1386 rt2x00_set_field16(&word, EEPROM_BBPTUNE_R61_LOW, 0x60);
1387 rt2x00_set_field16(&word, EEPROM_BBPTUNE_R61_HIGH, 0x6d);
1388 rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_R61, word);
1389 EEPROM(rt2x00dev, "BBPtune r61: 0x%04x\n", word);
1390 }
1391
1392 return 0;
1393}
1394
1395static int rt2500usb_init_eeprom(struct rt2x00_dev *rt2x00dev)
1396{
1397 u16 reg;
1398 u16 value;
1399 u16 eeprom;
1400
1401 /*
1402 * Read EEPROM word for configuration.
1403 */
1404 rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &eeprom);
1405
1406 /*
1407 * Identify RF chipset.
1408 */
1409 value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RF_TYPE);
1410 rt2500usb_register_read(rt2x00dev, MAC_CSR0, &reg);
1411 rt2x00_set_chip(rt2x00dev, RT2570, value, reg);
Gertjan van Wingerde16475b02009-11-14 20:20:35 +01001412 rt2x00_print_chip(rt2x00dev);
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001413
Andy Whitcroft7adfd5c2009-07-16 16:28:11 +01001414 if (!rt2x00_check_rev(&rt2x00dev->chip, 0x000ffff0, 0) ||
1415 rt2x00_check_rev(&rt2x00dev->chip, 0x0000000f, 0)) {
1416
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001417 ERROR(rt2x00dev, "Invalid RT chipset detected.\n");
1418 return -ENODEV;
1419 }
1420
1421 if (!rt2x00_rf(&rt2x00dev->chip, RF2522) &&
1422 !rt2x00_rf(&rt2x00dev->chip, RF2523) &&
1423 !rt2x00_rf(&rt2x00dev->chip, RF2524) &&
1424 !rt2x00_rf(&rt2x00dev->chip, RF2525) &&
1425 !rt2x00_rf(&rt2x00dev->chip, RF2525E) &&
1426 !rt2x00_rf(&rt2x00dev->chip, RF5222)) {
1427 ERROR(rt2x00dev, "Invalid RF chipset detected.\n");
1428 return -ENODEV;
1429 }
1430
1431 /*
1432 * Identify default antenna configuration.
1433 */
Ivo van Doornaddc81b2007-10-13 16:26:23 +02001434 rt2x00dev->default_ant.tx =
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001435 rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TX_DEFAULT);
Ivo van Doornaddc81b2007-10-13 16:26:23 +02001436 rt2x00dev->default_ant.rx =
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001437 rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RX_DEFAULT);
1438
1439 /*
Ivo van Doornaddc81b2007-10-13 16:26:23 +02001440 * When the eeprom indicates SW_DIVERSITY use HW_DIVERSITY instead.
1441 * I am not 100% sure about this, but the legacy drivers do not
1442 * indicate antenna swapping in software is required when
1443 * diversity is enabled.
1444 */
1445 if (rt2x00dev->default_ant.tx == ANTENNA_SW_DIVERSITY)
1446 rt2x00dev->default_ant.tx = ANTENNA_HW_DIVERSITY;
1447 if (rt2x00dev->default_ant.rx == ANTENNA_SW_DIVERSITY)
1448 rt2x00dev->default_ant.rx = ANTENNA_HW_DIVERSITY;
1449
1450 /*
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001451 * Store led mode, for correct led behaviour.
1452 */
Ivo van Doorn771fd562008-09-08 19:07:15 +02001453#ifdef CONFIG_RT2X00_LIB_LEDS
Ivo van Doorna9450b72008-02-03 15:53:40 +01001454 value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_LED_MODE);
1455
Ivo van Doorn475433b2008-06-03 20:30:01 +02001456 rt2500usb_init_led(rt2x00dev, &rt2x00dev->led_radio, LED_TYPE_RADIO);
Ivo van Doorn3d3e4512009-01-17 20:44:08 +01001457 if (value == LED_MODE_TXRX_ACTIVITY ||
1458 value == LED_MODE_DEFAULT ||
1459 value == LED_MODE_ASUS)
Ivo van Doorn475433b2008-06-03 20:30:01 +02001460 rt2500usb_init_led(rt2x00dev, &rt2x00dev->led_qual,
1461 LED_TYPE_ACTIVITY);
Ivo van Doorn771fd562008-09-08 19:07:15 +02001462#endif /* CONFIG_RT2X00_LIB_LEDS */
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001463
1464 /*
Ivo van Doorn7396faf2008-12-20 10:55:57 +01001465 * Detect if this device has an hardware controlled radio.
1466 */
Ivo van Doorn7396faf2008-12-20 10:55:57 +01001467 if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_HARDWARE_RADIO))
1468 __set_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags);
Ivo van Doorn7396faf2008-12-20 10:55:57 +01001469
1470 /*
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001471 * Check if the BBP tuning should be disabled.
1472 */
1473 rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &eeprom);
1474 if (rt2x00_get_field16(eeprom, EEPROM_NIC_DYN_BBP_TUNE))
1475 __set_bit(CONFIG_DISABLE_LINK_TUNING, &rt2x00dev->flags);
1476
1477 /*
1478 * Read the RSSI <-> dBm offset information.
1479 */
1480 rt2x00_eeprom_read(rt2x00dev, EEPROM_CALIBRATE_OFFSET, &eeprom);
1481 rt2x00dev->rssi_offset =
1482 rt2x00_get_field16(eeprom, EEPROM_CALIBRATE_OFFSET_RSSI);
1483
1484 return 0;
1485}
1486
1487/*
1488 * RF value list for RF2522
1489 * Supports: 2.4 GHz
1490 */
1491static const struct rf_channel rf_vals_bg_2522[] = {
1492 { 1, 0x00002050, 0x000c1fda, 0x00000101, 0 },
1493 { 2, 0x00002050, 0x000c1fee, 0x00000101, 0 },
1494 { 3, 0x00002050, 0x000c2002, 0x00000101, 0 },
1495 { 4, 0x00002050, 0x000c2016, 0x00000101, 0 },
1496 { 5, 0x00002050, 0x000c202a, 0x00000101, 0 },
1497 { 6, 0x00002050, 0x000c203e, 0x00000101, 0 },
1498 { 7, 0x00002050, 0x000c2052, 0x00000101, 0 },
1499 { 8, 0x00002050, 0x000c2066, 0x00000101, 0 },
1500 { 9, 0x00002050, 0x000c207a, 0x00000101, 0 },
1501 { 10, 0x00002050, 0x000c208e, 0x00000101, 0 },
1502 { 11, 0x00002050, 0x000c20a2, 0x00000101, 0 },
1503 { 12, 0x00002050, 0x000c20b6, 0x00000101, 0 },
1504 { 13, 0x00002050, 0x000c20ca, 0x00000101, 0 },
1505 { 14, 0x00002050, 0x000c20fa, 0x00000101, 0 },
1506};
1507
1508/*
1509 * RF value list for RF2523
1510 * Supports: 2.4 GHz
1511 */
1512static const struct rf_channel rf_vals_bg_2523[] = {
1513 { 1, 0x00022010, 0x00000c9e, 0x000e0111, 0x00000a1b },
1514 { 2, 0x00022010, 0x00000ca2, 0x000e0111, 0x00000a1b },
1515 { 3, 0x00022010, 0x00000ca6, 0x000e0111, 0x00000a1b },
1516 { 4, 0x00022010, 0x00000caa, 0x000e0111, 0x00000a1b },
1517 { 5, 0x00022010, 0x00000cae, 0x000e0111, 0x00000a1b },
1518 { 6, 0x00022010, 0x00000cb2, 0x000e0111, 0x00000a1b },
1519 { 7, 0x00022010, 0x00000cb6, 0x000e0111, 0x00000a1b },
1520 { 8, 0x00022010, 0x00000cba, 0x000e0111, 0x00000a1b },
1521 { 9, 0x00022010, 0x00000cbe, 0x000e0111, 0x00000a1b },
1522 { 10, 0x00022010, 0x00000d02, 0x000e0111, 0x00000a1b },
1523 { 11, 0x00022010, 0x00000d06, 0x000e0111, 0x00000a1b },
1524 { 12, 0x00022010, 0x00000d0a, 0x000e0111, 0x00000a1b },
1525 { 13, 0x00022010, 0x00000d0e, 0x000e0111, 0x00000a1b },
1526 { 14, 0x00022010, 0x00000d1a, 0x000e0111, 0x00000a03 },
1527};
1528
1529/*
1530 * RF value list for RF2524
1531 * Supports: 2.4 GHz
1532 */
1533static const struct rf_channel rf_vals_bg_2524[] = {
1534 { 1, 0x00032020, 0x00000c9e, 0x00000101, 0x00000a1b },
1535 { 2, 0x00032020, 0x00000ca2, 0x00000101, 0x00000a1b },
1536 { 3, 0x00032020, 0x00000ca6, 0x00000101, 0x00000a1b },
1537 { 4, 0x00032020, 0x00000caa, 0x00000101, 0x00000a1b },
1538 { 5, 0x00032020, 0x00000cae, 0x00000101, 0x00000a1b },
1539 { 6, 0x00032020, 0x00000cb2, 0x00000101, 0x00000a1b },
1540 { 7, 0x00032020, 0x00000cb6, 0x00000101, 0x00000a1b },
1541 { 8, 0x00032020, 0x00000cba, 0x00000101, 0x00000a1b },
1542 { 9, 0x00032020, 0x00000cbe, 0x00000101, 0x00000a1b },
1543 { 10, 0x00032020, 0x00000d02, 0x00000101, 0x00000a1b },
1544 { 11, 0x00032020, 0x00000d06, 0x00000101, 0x00000a1b },
1545 { 12, 0x00032020, 0x00000d0a, 0x00000101, 0x00000a1b },
1546 { 13, 0x00032020, 0x00000d0e, 0x00000101, 0x00000a1b },
1547 { 14, 0x00032020, 0x00000d1a, 0x00000101, 0x00000a03 },
1548};
1549
1550/*
1551 * RF value list for RF2525
1552 * Supports: 2.4 GHz
1553 */
1554static const struct rf_channel rf_vals_bg_2525[] = {
1555 { 1, 0x00022020, 0x00080c9e, 0x00060111, 0x00000a1b },
1556 { 2, 0x00022020, 0x00080ca2, 0x00060111, 0x00000a1b },
1557 { 3, 0x00022020, 0x00080ca6, 0x00060111, 0x00000a1b },
1558 { 4, 0x00022020, 0x00080caa, 0x00060111, 0x00000a1b },
1559 { 5, 0x00022020, 0x00080cae, 0x00060111, 0x00000a1b },
1560 { 6, 0x00022020, 0x00080cb2, 0x00060111, 0x00000a1b },
1561 { 7, 0x00022020, 0x00080cb6, 0x00060111, 0x00000a1b },
1562 { 8, 0x00022020, 0x00080cba, 0x00060111, 0x00000a1b },
1563 { 9, 0x00022020, 0x00080cbe, 0x00060111, 0x00000a1b },
1564 { 10, 0x00022020, 0x00080d02, 0x00060111, 0x00000a1b },
1565 { 11, 0x00022020, 0x00080d06, 0x00060111, 0x00000a1b },
1566 { 12, 0x00022020, 0x00080d0a, 0x00060111, 0x00000a1b },
1567 { 13, 0x00022020, 0x00080d0e, 0x00060111, 0x00000a1b },
1568 { 14, 0x00022020, 0x00080d1a, 0x00060111, 0x00000a03 },
1569};
1570
1571/*
1572 * RF value list for RF2525e
1573 * Supports: 2.4 GHz
1574 */
1575static const struct rf_channel rf_vals_bg_2525e[] = {
1576 { 1, 0x00022010, 0x0000089a, 0x00060111, 0x00000e1b },
1577 { 2, 0x00022010, 0x0000089e, 0x00060111, 0x00000e07 },
1578 { 3, 0x00022010, 0x0000089e, 0x00060111, 0x00000e1b },
1579 { 4, 0x00022010, 0x000008a2, 0x00060111, 0x00000e07 },
1580 { 5, 0x00022010, 0x000008a2, 0x00060111, 0x00000e1b },
1581 { 6, 0x00022010, 0x000008a6, 0x00060111, 0x00000e07 },
1582 { 7, 0x00022010, 0x000008a6, 0x00060111, 0x00000e1b },
1583 { 8, 0x00022010, 0x000008aa, 0x00060111, 0x00000e07 },
1584 { 9, 0x00022010, 0x000008aa, 0x00060111, 0x00000e1b },
1585 { 10, 0x00022010, 0x000008ae, 0x00060111, 0x00000e07 },
1586 { 11, 0x00022010, 0x000008ae, 0x00060111, 0x00000e1b },
1587 { 12, 0x00022010, 0x000008b2, 0x00060111, 0x00000e07 },
1588 { 13, 0x00022010, 0x000008b2, 0x00060111, 0x00000e1b },
1589 { 14, 0x00022010, 0x000008b6, 0x00060111, 0x00000e23 },
1590};
1591
1592/*
1593 * RF value list for RF5222
1594 * Supports: 2.4 GHz & 5.2 GHz
1595 */
1596static const struct rf_channel rf_vals_5222[] = {
1597 { 1, 0x00022020, 0x00001136, 0x00000101, 0x00000a0b },
1598 { 2, 0x00022020, 0x0000113a, 0x00000101, 0x00000a0b },
1599 { 3, 0x00022020, 0x0000113e, 0x00000101, 0x00000a0b },
1600 { 4, 0x00022020, 0x00001182, 0x00000101, 0x00000a0b },
1601 { 5, 0x00022020, 0x00001186, 0x00000101, 0x00000a0b },
1602 { 6, 0x00022020, 0x0000118a, 0x00000101, 0x00000a0b },
1603 { 7, 0x00022020, 0x0000118e, 0x00000101, 0x00000a0b },
1604 { 8, 0x00022020, 0x00001192, 0x00000101, 0x00000a0b },
1605 { 9, 0x00022020, 0x00001196, 0x00000101, 0x00000a0b },
1606 { 10, 0x00022020, 0x0000119a, 0x00000101, 0x00000a0b },
1607 { 11, 0x00022020, 0x0000119e, 0x00000101, 0x00000a0b },
1608 { 12, 0x00022020, 0x000011a2, 0x00000101, 0x00000a0b },
1609 { 13, 0x00022020, 0x000011a6, 0x00000101, 0x00000a0b },
1610 { 14, 0x00022020, 0x000011ae, 0x00000101, 0x00000a1b },
1611
1612 /* 802.11 UNI / HyperLan 2 */
1613 { 36, 0x00022010, 0x00018896, 0x00000101, 0x00000a1f },
1614 { 40, 0x00022010, 0x0001889a, 0x00000101, 0x00000a1f },
1615 { 44, 0x00022010, 0x0001889e, 0x00000101, 0x00000a1f },
1616 { 48, 0x00022010, 0x000188a2, 0x00000101, 0x00000a1f },
1617 { 52, 0x00022010, 0x000188a6, 0x00000101, 0x00000a1f },
1618 { 66, 0x00022010, 0x000188aa, 0x00000101, 0x00000a1f },
1619 { 60, 0x00022010, 0x000188ae, 0x00000101, 0x00000a1f },
1620 { 64, 0x00022010, 0x000188b2, 0x00000101, 0x00000a1f },
1621
1622 /* 802.11 HyperLan 2 */
1623 { 100, 0x00022010, 0x00008802, 0x00000101, 0x00000a0f },
1624 { 104, 0x00022010, 0x00008806, 0x00000101, 0x00000a0f },
1625 { 108, 0x00022010, 0x0000880a, 0x00000101, 0x00000a0f },
1626 { 112, 0x00022010, 0x0000880e, 0x00000101, 0x00000a0f },
1627 { 116, 0x00022010, 0x00008812, 0x00000101, 0x00000a0f },
1628 { 120, 0x00022010, 0x00008816, 0x00000101, 0x00000a0f },
1629 { 124, 0x00022010, 0x0000881a, 0x00000101, 0x00000a0f },
1630 { 128, 0x00022010, 0x0000881e, 0x00000101, 0x00000a0f },
1631 { 132, 0x00022010, 0x00008822, 0x00000101, 0x00000a0f },
1632 { 136, 0x00022010, 0x00008826, 0x00000101, 0x00000a0f },
1633
1634 /* 802.11 UNII */
1635 { 140, 0x00022010, 0x0000882a, 0x00000101, 0x00000a0f },
1636 { 149, 0x00022020, 0x000090a6, 0x00000101, 0x00000a07 },
1637 { 153, 0x00022020, 0x000090ae, 0x00000101, 0x00000a07 },
1638 { 157, 0x00022020, 0x000090b6, 0x00000101, 0x00000a07 },
1639 { 161, 0x00022020, 0x000090be, 0x00000101, 0x00000a07 },
1640};
1641
Ivo van Doorn8c5e7a52008-08-04 16:38:47 +02001642static int rt2500usb_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001643{
1644 struct hw_mode_spec *spec = &rt2x00dev->spec;
Ivo van Doorn8c5e7a52008-08-04 16:38:47 +02001645 struct channel_info *info;
1646 char *tx_power;
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001647 unsigned int i;
1648
1649 /*
1650 * Initialize all hw fields.
1651 */
1652 rt2x00dev->hw->flags =
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001653 IEEE80211_HW_RX_INCLUDES_FCS |
Bruno Randolf566bfe52008-05-08 19:15:40 +02001654 IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
Johannes Berg4be8c382009-01-07 18:28:20 +01001655 IEEE80211_HW_SIGNAL_DBM |
1656 IEEE80211_HW_SUPPORTS_PS |
1657 IEEE80211_HW_PS_NULLFUNC_STACK;
Bruno Randolf566bfe52008-05-08 19:15:40 +02001658
Gertjan van Wingerde14a3bf82008-06-16 19:55:43 +02001659 SET_IEEE80211_DEV(rt2x00dev->hw, rt2x00dev->dev);
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001660 SET_IEEE80211_PERM_ADDR(rt2x00dev->hw,
1661 rt2x00_eeprom_addr(rt2x00dev,
1662 EEPROM_MAC_ADDR_0));
1663
1664 /*
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001665 * Initialize hw_mode information.
1666 */
Ivo van Doorn31562e82008-02-17 17:35:05 +01001667 spec->supported_bands = SUPPORT_BAND_2GHZ;
1668 spec->supported_rates = SUPPORT_RATE_CCK | SUPPORT_RATE_OFDM;
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001669
1670 if (rt2x00_rf(&rt2x00dev->chip, RF2522)) {
1671 spec->num_channels = ARRAY_SIZE(rf_vals_bg_2522);
1672 spec->channels = rf_vals_bg_2522;
1673 } else if (rt2x00_rf(&rt2x00dev->chip, RF2523)) {
1674 spec->num_channels = ARRAY_SIZE(rf_vals_bg_2523);
1675 spec->channels = rf_vals_bg_2523;
1676 } else if (rt2x00_rf(&rt2x00dev->chip, RF2524)) {
1677 spec->num_channels = ARRAY_SIZE(rf_vals_bg_2524);
1678 spec->channels = rf_vals_bg_2524;
1679 } else if (rt2x00_rf(&rt2x00dev->chip, RF2525)) {
1680 spec->num_channels = ARRAY_SIZE(rf_vals_bg_2525);
1681 spec->channels = rf_vals_bg_2525;
1682 } else if (rt2x00_rf(&rt2x00dev->chip, RF2525E)) {
1683 spec->num_channels = ARRAY_SIZE(rf_vals_bg_2525e);
1684 spec->channels = rf_vals_bg_2525e;
1685 } else if (rt2x00_rf(&rt2x00dev->chip, RF5222)) {
Ivo van Doorn31562e82008-02-17 17:35:05 +01001686 spec->supported_bands |= SUPPORT_BAND_5GHZ;
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001687 spec->num_channels = ARRAY_SIZE(rf_vals_5222);
1688 spec->channels = rf_vals_5222;
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001689 }
Ivo van Doorn8c5e7a52008-08-04 16:38:47 +02001690
1691 /*
1692 * Create channel information array
1693 */
1694 info = kzalloc(spec->num_channels * sizeof(*info), GFP_KERNEL);
1695 if (!info)
1696 return -ENOMEM;
1697
1698 spec->channels_info = info;
1699
1700 tx_power = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_START);
1701 for (i = 0; i < 14; i++)
1702 info[i].tx_power1 = TXPOWER_FROM_DEV(tx_power[i]);
1703
1704 if (spec->num_channels > 14) {
1705 for (i = 14; i < spec->num_channels; i++)
1706 info[i].tx_power1 = DEFAULT_TXPOWER;
1707 }
1708
1709 return 0;
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001710}
1711
1712static int rt2500usb_probe_hw(struct rt2x00_dev *rt2x00dev)
1713{
1714 int retval;
1715
1716 /*
1717 * Allocate eeprom data.
1718 */
1719 retval = rt2500usb_validate_eeprom(rt2x00dev);
1720 if (retval)
1721 return retval;
1722
1723 retval = rt2500usb_init_eeprom(rt2x00dev);
1724 if (retval)
1725 return retval;
1726
1727 /*
1728 * Initialize hw specifications.
1729 */
Ivo van Doorn8c5e7a52008-08-04 16:38:47 +02001730 retval = rt2500usb_probe_hw_mode(rt2x00dev);
1731 if (retval)
1732 return retval;
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001733
1734 /*
Ivo van Doorn181d6902008-02-05 16:42:23 -05001735 * This device requires the atim queue
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001736 */
Ivo van Doorn181d6902008-02-05 16:42:23 -05001737 __set_bit(DRIVER_REQUIRE_ATIM_QUEUE, &rt2x00dev->flags);
1738 __set_bit(DRIVER_REQUIRE_BEACON_GUARD, &rt2x00dev->flags);
Ivo van Doorndddfb472008-12-02 18:20:42 +01001739 if (!modparam_nohwcrypt) {
1740 __set_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags);
Ivo van Doorn3f787bd2008-12-20 10:56:36 +01001741 __set_bit(DRIVER_REQUIRE_COPY_IV, &rt2x00dev->flags);
Ivo van Doorndddfb472008-12-02 18:20:42 +01001742 }
Ivo van Doornd06193f2008-08-03 23:36:01 +02001743 __set_bit(CONFIG_DISABLE_LINK_TUNING, &rt2x00dev->flags);
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001744
1745 /*
1746 * Set the rssi offset.
1747 */
1748 rt2x00dev->rssi_offset = DEFAULT_RSSI_OFFSET;
1749
1750 return 0;
1751}
1752
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001753static const struct ieee80211_ops rt2500usb_mac80211_ops = {
1754 .tx = rt2x00mac_tx,
Johannes Berg4150c572007-09-17 01:29:23 -04001755 .start = rt2x00mac_start,
1756 .stop = rt2x00mac_stop,
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001757 .add_interface = rt2x00mac_add_interface,
1758 .remove_interface = rt2x00mac_remove_interface,
1759 .config = rt2x00mac_config,
Ivo van Doorn3a643d22008-03-25 14:13:18 +01001760 .configure_filter = rt2x00mac_configure_filter,
Stefan Steuerwald930c06f2009-07-10 20:42:55 +02001761 .set_tim = rt2x00mac_set_tim,
Ivo van Doorndddfb472008-12-02 18:20:42 +01001762 .set_key = rt2x00mac_set_key,
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001763 .get_stats = rt2x00mac_get_stats,
Johannes Berg471b3ef2007-12-28 14:32:58 +01001764 .bss_info_changed = rt2x00mac_bss_info_changed,
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001765 .conf_tx = rt2x00mac_conf_tx,
1766 .get_tx_stats = rt2x00mac_get_tx_stats,
Ivo van Doorne47a5cd2009-07-01 15:17:35 +02001767 .rfkill_poll = rt2x00mac_rfkill_poll,
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001768};
1769
1770static const struct rt2x00lib_ops rt2500usb_rt2x00_ops = {
1771 .probe_hw = rt2500usb_probe_hw,
1772 .initialize = rt2x00usb_initialize,
1773 .uninitialize = rt2x00usb_uninitialize,
Ivo van Doorn798b7ad2008-11-08 15:25:33 +01001774 .clear_entry = rt2x00usb_clear_entry,
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001775 .set_device_state = rt2500usb_set_device_state,
Ivo van Doorn7396faf2008-12-20 10:55:57 +01001776 .rfkill_poll = rt2500usb_rfkill_poll,
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001777 .link_stats = rt2500usb_link_stats,
1778 .reset_tuner = rt2500usb_reset_tuner,
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001779 .write_tx_desc = rt2500usb_write_tx_desc,
1780 .write_tx_data = rt2x00usb_write_tx_data,
Ivo van Doornbd88a782008-07-09 15:12:44 +02001781 .write_beacon = rt2500usb_write_beacon,
Ivo van Doorndd9fa2d2007-10-06 14:15:46 +02001782 .get_tx_data_len = rt2500usb_get_tx_data_len,
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001783 .kick_tx_queue = rt2500usb_kick_tx_queue,
Ivo van Doorna2c9b652009-01-28 00:32:33 +01001784 .kill_tx_queue = rt2x00usb_kill_tx_queue,
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001785 .fill_rxdone = rt2500usb_fill_rxdone,
Ivo van Doorndddfb472008-12-02 18:20:42 +01001786 .config_shared_key = rt2500usb_config_key,
1787 .config_pairwise_key = rt2500usb_config_key,
Ivo van Doorn3a643d22008-03-25 14:13:18 +01001788 .config_filter = rt2500usb_config_filter,
Ivo van Doorn6bb40dd2008-02-03 15:49:59 +01001789 .config_intf = rt2500usb_config_intf,
Ivo van Doorn72810372008-03-09 22:46:18 +01001790 .config_erp = rt2500usb_config_erp,
Ivo van Doorne4ea1c42008-10-29 17:17:57 +01001791 .config_ant = rt2500usb_config_ant,
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001792 .config = rt2500usb_config,
1793};
1794
Ivo van Doorn181d6902008-02-05 16:42:23 -05001795static const struct data_queue_desc rt2500usb_queue_rx = {
1796 .entry_num = RX_ENTRIES,
1797 .data_size = DATA_FRAME_SIZE,
1798 .desc_size = RXD_DESC_SIZE,
Ivo van Doornb8be63f2008-05-10 13:46:03 +02001799 .priv_size = sizeof(struct queue_entry_priv_usb),
Ivo van Doorn181d6902008-02-05 16:42:23 -05001800};
1801
1802static const struct data_queue_desc rt2500usb_queue_tx = {
1803 .entry_num = TX_ENTRIES,
1804 .data_size = DATA_FRAME_SIZE,
1805 .desc_size = TXD_DESC_SIZE,
Ivo van Doornb8be63f2008-05-10 13:46:03 +02001806 .priv_size = sizeof(struct queue_entry_priv_usb),
Ivo van Doorn181d6902008-02-05 16:42:23 -05001807};
1808
1809static const struct data_queue_desc rt2500usb_queue_bcn = {
1810 .entry_num = BEACON_ENTRIES,
1811 .data_size = MGMT_FRAME_SIZE,
1812 .desc_size = TXD_DESC_SIZE,
1813 .priv_size = sizeof(struct queue_entry_priv_usb_bcn),
1814};
1815
1816static const struct data_queue_desc rt2500usb_queue_atim = {
1817 .entry_num = ATIM_ENTRIES,
1818 .data_size = DATA_FRAME_SIZE,
1819 .desc_size = TXD_DESC_SIZE,
Ivo van Doornb8be63f2008-05-10 13:46:03 +02001820 .priv_size = sizeof(struct queue_entry_priv_usb),
Ivo van Doorn181d6902008-02-05 16:42:23 -05001821};
1822
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001823static const struct rt2x00_ops rt2500usb_ops = {
Gertjan van Wingerde04d03622009-11-23 22:44:51 +01001824 .name = KBUILD_MODNAME,
1825 .max_sta_intf = 1,
1826 .max_ap_intf = 1,
1827 .eeprom_size = EEPROM_SIZE,
1828 .rf_size = RF_SIZE,
1829 .tx_queues = NUM_TX_QUEUES,
Gertjan van Wingerdee6218cc2009-11-23 22:44:52 +01001830 .extra_tx_headroom = TXD_DESC_SIZE,
Gertjan van Wingerde04d03622009-11-23 22:44:51 +01001831 .rx = &rt2500usb_queue_rx,
1832 .tx = &rt2500usb_queue_tx,
1833 .bcn = &rt2500usb_queue_bcn,
1834 .atim = &rt2500usb_queue_atim,
1835 .lib = &rt2500usb_rt2x00_ops,
1836 .hw = &rt2500usb_mac80211_ops,
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001837#ifdef CONFIG_RT2X00_LIB_DEBUGFS
Gertjan van Wingerde04d03622009-11-23 22:44:51 +01001838 .debugfs = &rt2500usb_rt2x00debug,
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001839#endif /* CONFIG_RT2X00_LIB_DEBUGFS */
1840};
1841
1842/*
1843 * rt2500usb module information.
1844 */
1845static struct usb_device_id rt2500usb_device_table[] = {
1846 /* ASUS */
1847 { USB_DEVICE(0x0b05, 0x1706), USB_DEVICE_DATA(&rt2500usb_ops) },
1848 { USB_DEVICE(0x0b05, 0x1707), USB_DEVICE_DATA(&rt2500usb_ops) },
1849 /* Belkin */
1850 { USB_DEVICE(0x050d, 0x7050), USB_DEVICE_DATA(&rt2500usb_ops) },
1851 { USB_DEVICE(0x050d, 0x7051), USB_DEVICE_DATA(&rt2500usb_ops) },
1852 { USB_DEVICE(0x050d, 0x705a), USB_DEVICE_DATA(&rt2500usb_ops) },
1853 /* Cisco Systems */
1854 { USB_DEVICE(0x13b1, 0x000d), USB_DEVICE_DATA(&rt2500usb_ops) },
1855 { USB_DEVICE(0x13b1, 0x0011), USB_DEVICE_DATA(&rt2500usb_ops) },
1856 { USB_DEVICE(0x13b1, 0x001a), USB_DEVICE_DATA(&rt2500usb_ops) },
Xose Vazquez Perez9eb77ab2009-02-28 00:26:09 +01001857 /* CNet */
1858 { USB_DEVICE(0x1371, 0x9022), USB_DEVICE_DATA(&rt2500usb_ops) },
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001859 /* Conceptronic */
1860 { USB_DEVICE(0x14b2, 0x3c02), USB_DEVICE_DATA(&rt2500usb_ops) },
1861 /* D-LINK */
1862 { USB_DEVICE(0x2001, 0x3c00), USB_DEVICE_DATA(&rt2500usb_ops) },
1863 /* Gigabyte */
1864 { USB_DEVICE(0x1044, 0x8001), USB_DEVICE_DATA(&rt2500usb_ops) },
1865 { USB_DEVICE(0x1044, 0x8007), USB_DEVICE_DATA(&rt2500usb_ops) },
1866 /* Hercules */
1867 { USB_DEVICE(0x06f8, 0xe000), USB_DEVICE_DATA(&rt2500usb_ops) },
1868 /* Melco */
Ivo van Doorndb433fe2008-02-10 11:21:57 +01001869 { USB_DEVICE(0x0411, 0x005e), USB_DEVICE_DATA(&rt2500usb_ops) },
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001870 { USB_DEVICE(0x0411, 0x0066), USB_DEVICE_DATA(&rt2500usb_ops) },
1871 { USB_DEVICE(0x0411, 0x0067), USB_DEVICE_DATA(&rt2500usb_ops) },
1872 { USB_DEVICE(0x0411, 0x008b), USB_DEVICE_DATA(&rt2500usb_ops) },
1873 { USB_DEVICE(0x0411, 0x0097), USB_DEVICE_DATA(&rt2500usb_ops) },
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001874 /* MSI */
1875 { USB_DEVICE(0x0db0, 0x6861), USB_DEVICE_DATA(&rt2500usb_ops) },
1876 { USB_DEVICE(0x0db0, 0x6865), USB_DEVICE_DATA(&rt2500usb_ops) },
1877 { USB_DEVICE(0x0db0, 0x6869), USB_DEVICE_DATA(&rt2500usb_ops) },
1878 /* Ralink */
1879 { USB_DEVICE(0x148f, 0x1706), USB_DEVICE_DATA(&rt2500usb_ops) },
1880 { USB_DEVICE(0x148f, 0x2570), USB_DEVICE_DATA(&rt2500usb_ops) },
1881 { USB_DEVICE(0x148f, 0x2573), USB_DEVICE_DATA(&rt2500usb_ops) },
1882 { USB_DEVICE(0x148f, 0x9020), USB_DEVICE_DATA(&rt2500usb_ops) },
Xose Vazquez Perez9eb77ab2009-02-28 00:26:09 +01001883 /* Sagem */
1884 { USB_DEVICE(0x079b, 0x004b), USB_DEVICE_DATA(&rt2500usb_ops) },
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001885 /* Siemens */
1886 { USB_DEVICE(0x0681, 0x3c06), USB_DEVICE_DATA(&rt2500usb_ops) },
1887 /* SMC */
1888 { USB_DEVICE(0x0707, 0xee13), USB_DEVICE_DATA(&rt2500usb_ops) },
1889 /* Spairon */
1890 { USB_DEVICE(0x114b, 0x0110), USB_DEVICE_DATA(&rt2500usb_ops) },
Xose Vazquez Perez9eb77ab2009-02-28 00:26:09 +01001891 /* SURECOM */
1892 { USB_DEVICE(0x0769, 0x11f3), USB_DEVICE_DATA(&rt2500usb_ops) },
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001893 /* Trust */
1894 { USB_DEVICE(0x0eb0, 0x9020), USB_DEVICE_DATA(&rt2500usb_ops) },
Xose Vazquez Perez9eb77ab2009-02-28 00:26:09 +01001895 /* VTech */
1896 { USB_DEVICE(0x0f88, 0x3012), USB_DEVICE_DATA(&rt2500usb_ops) },
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001897 /* Zinwell */
1898 { USB_DEVICE(0x5a57, 0x0260), USB_DEVICE_DATA(&rt2500usb_ops) },
1899 { 0, }
1900};
1901
1902MODULE_AUTHOR(DRV_PROJECT);
1903MODULE_VERSION(DRV_VERSION);
1904MODULE_DESCRIPTION("Ralink RT2500 USB Wireless LAN driver.");
1905MODULE_SUPPORTED_DEVICE("Ralink RT2570 USB chipset based cards");
1906MODULE_DEVICE_TABLE(usb, rt2500usb_device_table);
1907MODULE_LICENSE("GPL");
1908
1909static struct usb_driver rt2500usb_driver = {
Ivo van Doorn23601572007-11-27 21:47:34 +01001910 .name = KBUILD_MODNAME,
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001911 .id_table = rt2500usb_device_table,
1912 .probe = rt2x00usb_probe,
1913 .disconnect = rt2x00usb_disconnect,
1914 .suspend = rt2x00usb_suspend,
1915 .resume = rt2x00usb_resume,
1916};
1917
1918static int __init rt2500usb_init(void)
1919{
1920 return usb_register(&rt2500usb_driver);
1921}
1922
1923static void __exit rt2500usb_exit(void)
1924{
1925 usb_deregister(&rt2500usb_driver);
1926}
1927
1928module_init(rt2500usb_init);
1929module_exit(rt2500usb_exit);