blob: 9e630e70fc976d9d6da06c42ab80bf6970a81778 [file] [log] [blame]
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001/*
Ivo van Doorn4e54c712009-01-17 20:42:32 +01002 Copyright (C) 2004 - 2009 rt2x00 SourceForge Project
Ivo van Doorn95ea3622007-09-25 17:57:13 -07003 <http://rt2x00.serialmonkey.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the
17 Free Software Foundation, Inc.,
18 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21/*
22 Module: 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 +0100280#ifdef CONFIG_RT2X00_LIB_RFKILL
281static int rt2500usb_rfkill_poll(struct rt2x00_dev *rt2x00dev)
282{
283 u16 reg;
284
285 rt2500usb_register_read(rt2x00dev, MAC_CSR19, &reg);
286 return rt2x00_get_field32(reg, MAC_CSR19_BIT7);
287}
288#else
289#define rt2500usb_rfkill_poll NULL
290#endif /* CONFIG_RT2X00_LIB_RFKILL */
291
Ivo van Doorn771fd562008-09-08 19:07:15 +0200292#ifdef CONFIG_RT2X00_LIB_LEDS
Ivo van Doorna2e1d522008-03-31 15:53:44 +0200293static void rt2500usb_brightness_set(struct led_classdev *led_cdev,
Ivo van Doorna9450b72008-02-03 15:53:40 +0100294 enum led_brightness brightness)
295{
296 struct rt2x00_led *led =
297 container_of(led_cdev, struct rt2x00_led, led_dev);
298 unsigned int enabled = brightness != LED_OFF;
Ivo van Doorna2e1d522008-03-31 15:53:44 +0200299 u16 reg;
Ivo van Doorna9450b72008-02-03 15:53:40 +0100300
Ivo van Doorna2e1d522008-03-31 15:53:44 +0200301 rt2500usb_register_read(led->rt2x00dev, MAC_CSR20, &reg);
Ivo van Doorn47b10cd2008-02-17 17:35:28 +0100302
Ivo van Doorna2e1d522008-03-31 15:53:44 +0200303 if (led->type == LED_TYPE_RADIO || led->type == LED_TYPE_ASSOC)
304 rt2x00_set_field16(&reg, MAC_CSR20_LINK, enabled);
305 else if (led->type == LED_TYPE_ACTIVITY)
306 rt2x00_set_field16(&reg, MAC_CSR20_ACTIVITY, enabled);
Ivo van Doorna9450b72008-02-03 15:53:40 +0100307
Ivo van Doorna2e1d522008-03-31 15:53:44 +0200308 rt2500usb_register_write(led->rt2x00dev, MAC_CSR20, reg);
Ivo van Doorna9450b72008-02-03 15:53:40 +0100309}
Ivo van Doorna2e1d522008-03-31 15:53:44 +0200310
311static int rt2500usb_blink_set(struct led_classdev *led_cdev,
312 unsigned long *delay_on,
313 unsigned long *delay_off)
314{
315 struct rt2x00_led *led =
316 container_of(led_cdev, struct rt2x00_led, led_dev);
317 u16 reg;
318
319 rt2500usb_register_read(led->rt2x00dev, MAC_CSR21, &reg);
320 rt2x00_set_field16(&reg, MAC_CSR21_ON_PERIOD, *delay_on);
321 rt2x00_set_field16(&reg, MAC_CSR21_OFF_PERIOD, *delay_off);
322 rt2500usb_register_write(led->rt2x00dev, MAC_CSR21, reg);
323
324 return 0;
325}
Ivo van Doorn475433b2008-06-03 20:30:01 +0200326
327static void rt2500usb_init_led(struct rt2x00_dev *rt2x00dev,
328 struct rt2x00_led *led,
329 enum led_type type)
330{
331 led->rt2x00dev = rt2x00dev;
332 led->type = type;
333 led->led_dev.brightness_set = rt2500usb_brightness_set;
334 led->led_dev.blink_set = rt2500usb_blink_set;
335 led->flags = LED_INITIALIZED;
336}
Ivo van Doorn771fd562008-09-08 19:07:15 +0200337#endif /* CONFIG_RT2X00_LIB_LEDS */
Ivo van Doorna9450b72008-02-03 15:53:40 +0100338
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700339/*
340 * Configuration handlers.
341 */
Ivo van Doorndddfb472008-12-02 18:20:42 +0100342
343/*
344 * rt2500usb does not differentiate between shared and pairwise
345 * keys, so we should use the same function for both key types.
346 */
347static int rt2500usb_config_key(struct rt2x00_dev *rt2x00dev,
348 struct rt2x00lib_crypto *crypto,
349 struct ieee80211_key_conf *key)
350{
351 int timeout;
352 u32 mask;
353 u16 reg;
354
355 if (crypto->cmd == SET_KEY) {
356 /*
357 * Pairwise key will always be entry 0, but this
358 * could collide with a shared key on the same
359 * position...
360 */
361 mask = TXRX_CSR0_KEY_ID.bit_mask;
362
363 rt2500usb_register_read(rt2x00dev, TXRX_CSR0, &reg);
364 reg &= mask;
365
366 if (reg && reg == mask)
367 return -ENOSPC;
368
369 reg = rt2x00_get_field16(reg, TXRX_CSR0_KEY_ID);
370
371 key->hw_key_idx += reg ? ffz(reg) : 0;
372
373 /*
374 * The encryption key doesn't fit within the CSR cache,
375 * this means we should allocate it seperately and use
376 * rt2x00usb_vendor_request() to send the key to the hardware.
377 */
378 reg = KEY_ENTRY(key->hw_key_idx);
379 timeout = REGISTER_TIMEOUT32(sizeof(crypto->key));
380 rt2x00usb_vendor_request_large_buff(rt2x00dev, USB_MULTI_WRITE,
381 USB_VENDOR_REQUEST_OUT, reg,
382 crypto->key,
383 sizeof(crypto->key),
384 timeout);
385
386 /*
387 * The driver does not support the IV/EIV generation
Ivo van Doornf3d340c2008-12-21 23:19:17 +0100388 * in hardware. However it demands the data to be provided
389 * both seperately as well as inside the frame.
390 * We already provided the CONFIG_CRYPTO_COPY_IV to rt2x00lib
391 * to ensure rt2x00lib will not strip the data from the
392 * frame after the copy, now we must tell mac80211
Ivo van Doorndddfb472008-12-02 18:20:42 +0100393 * to generate the IV/EIV data.
394 */
395 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
396 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
397 }
398
399 /*
400 * TXRX_CSR0_KEY_ID contains only single-bit fields to indicate
401 * a particular key is valid.
402 */
403 rt2500usb_register_read(rt2x00dev, TXRX_CSR0, &reg);
404 rt2x00_set_field16(&reg, TXRX_CSR0_ALGORITHM, crypto->cipher);
405 rt2x00_set_field16(&reg, TXRX_CSR0_IV_OFFSET, IEEE80211_HEADER);
406
407 mask = rt2x00_get_field16(reg, TXRX_CSR0_KEY_ID);
408 if (crypto->cmd == SET_KEY)
409 mask |= 1 << key->hw_key_idx;
410 else if (crypto->cmd == DISABLE_KEY)
411 mask &= ~(1 << key->hw_key_idx);
412 rt2x00_set_field16(&reg, TXRX_CSR0_KEY_ID, mask);
413 rt2500usb_register_write(rt2x00dev, TXRX_CSR0, reg);
414
415 return 0;
416}
417
Ivo van Doorn3a643d22008-03-25 14:13:18 +0100418static void rt2500usb_config_filter(struct rt2x00_dev *rt2x00dev,
419 const unsigned int filter_flags)
420{
421 u16 reg;
422
423 /*
424 * Start configuration steps.
425 * Note that the version error will always be dropped
426 * and broadcast frames will always be accepted since
427 * there is no filter for it at this time.
428 */
429 rt2500usb_register_read(rt2x00dev, TXRX_CSR2, &reg);
430 rt2x00_set_field16(&reg, TXRX_CSR2_DROP_CRC,
431 !(filter_flags & FIF_FCSFAIL));
432 rt2x00_set_field16(&reg, TXRX_CSR2_DROP_PHYSICAL,
433 !(filter_flags & FIF_PLCPFAIL));
434 rt2x00_set_field16(&reg, TXRX_CSR2_DROP_CONTROL,
435 !(filter_flags & FIF_CONTROL));
436 rt2x00_set_field16(&reg, TXRX_CSR2_DROP_NOT_TO_ME,
437 !(filter_flags & FIF_PROMISC_IN_BSS));
438 rt2x00_set_field16(&reg, TXRX_CSR2_DROP_TODS,
Ivo van Doorne0b005f2008-03-31 15:24:53 +0200439 !(filter_flags & FIF_PROMISC_IN_BSS) &&
440 !rt2x00dev->intf_ap_count);
Ivo van Doorn3a643d22008-03-25 14:13:18 +0100441 rt2x00_set_field16(&reg, TXRX_CSR2_DROP_VERSION_ERROR, 1);
442 rt2x00_set_field16(&reg, TXRX_CSR2_DROP_MULTICAST,
443 !(filter_flags & FIF_ALLMULTI));
444 rt2x00_set_field16(&reg, TXRX_CSR2_DROP_BROADCAST, 0);
445 rt2500usb_register_write(rt2x00dev, TXRX_CSR2, reg);
446}
447
Ivo van Doorn6bb40dd2008-02-03 15:49:59 +0100448static void rt2500usb_config_intf(struct rt2x00_dev *rt2x00dev,
449 struct rt2x00_intf *intf,
450 struct rt2x00intf_conf *conf,
451 const unsigned int flags)
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700452{
Ivo van Doorn6bb40dd2008-02-03 15:49:59 +0100453 unsigned int bcn_preload;
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700454 u16 reg;
455
Ivo van Doorn6bb40dd2008-02-03 15:49:59 +0100456 if (flags & CONFIG_UPDATE_TYPE) {
Ivo van Doorn6bb40dd2008-02-03 15:49:59 +0100457 /*
458 * Enable beacon config
459 */
Ivo van Doornbad13632008-11-09 20:47:00 +0100460 bcn_preload = PREAMBLE + GET_DURATION(IEEE80211_HEADER, 20);
Ivo van Doorn6bb40dd2008-02-03 15:49:59 +0100461 rt2500usb_register_read(rt2x00dev, TXRX_CSR20, &reg);
462 rt2x00_set_field16(&reg, TXRX_CSR20_OFFSET, bcn_preload >> 6);
463 rt2x00_set_field16(&reg, TXRX_CSR20_BCN_EXPECT_WINDOW,
Johannes Berg05c914f2008-09-11 00:01:58 +0200464 2 * (conf->type != NL80211_IFTYPE_STATION));
Ivo van Doorn6bb40dd2008-02-03 15:49:59 +0100465 rt2500usb_register_write(rt2x00dev, TXRX_CSR20, reg);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700466
Ivo van Doorn6bb40dd2008-02-03 15:49:59 +0100467 /*
468 * Enable synchronisation.
469 */
470 rt2500usb_register_read(rt2x00dev, TXRX_CSR18, &reg);
471 rt2x00_set_field16(&reg, TXRX_CSR18_OFFSET, 0);
472 rt2500usb_register_write(rt2x00dev, TXRX_CSR18, reg);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700473
Ivo van Doorn6bb40dd2008-02-03 15:49:59 +0100474 rt2500usb_register_read(rt2x00dev, TXRX_CSR19, &reg);
Ivo van Doornfd3c91c2008-03-09 22:47:43 +0100475 rt2x00_set_field16(&reg, TXRX_CSR19_TSF_COUNT, 1);
Ivo van Doorn6bb40dd2008-02-03 15:49:59 +0100476 rt2x00_set_field16(&reg, TXRX_CSR19_TSF_SYNC, conf->sync);
Ivo van Doornfd3c91c2008-03-09 22:47:43 +0100477 rt2x00_set_field16(&reg, TXRX_CSR19_TBCN, 1);
Ivo van Doorn6bb40dd2008-02-03 15:49:59 +0100478 rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg);
Ivo van Doorn5c58ee52007-10-06 13:34:52 +0200479 }
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700480
Ivo van Doorn6bb40dd2008-02-03 15:49:59 +0100481 if (flags & CONFIG_UPDATE_MAC)
482 rt2500usb_register_multiwrite(rt2x00dev, MAC_CSR2, conf->mac,
483 (3 * sizeof(__le16)));
484
485 if (flags & CONFIG_UPDATE_BSSID)
486 rt2500usb_register_multiwrite(rt2x00dev, MAC_CSR5, conf->bssid,
487 (3 * sizeof(__le16)));
488}
489
Ivo van Doorn3a643d22008-03-25 14:13:18 +0100490static void rt2500usb_config_erp(struct rt2x00_dev *rt2x00dev,
491 struct rt2x00lib_erp *erp)
Ivo van Doorn6bb40dd2008-02-03 15:49:59 +0100492{
493 u16 reg;
494
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700495 rt2500usb_register_read(rt2x00dev, TXRX_CSR1, &reg);
Ivo van Doorn72810372008-03-09 22:46:18 +0100496 rt2x00_set_field16(&reg, TXRX_CSR1_ACK_TIMEOUT, erp->ack_timeout);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700497 rt2500usb_register_write(rt2x00dev, TXRX_CSR1, reg);
498
499 rt2500usb_register_read(rt2x00dev, TXRX_CSR10, &reg);
Ivo van Doorn4f5af6eb2007-10-06 14:16:30 +0200500 rt2x00_set_field16(&reg, TXRX_CSR10_AUTORESPOND_PREAMBLE,
Ivo van Doorn72810372008-03-09 22:46:18 +0100501 !!erp->short_preamble);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700502 rt2500usb_register_write(rt2x00dev, TXRX_CSR10, reg);
Ivo van Doorne4ea1c42008-10-29 17:17:57 +0100503
504 rt2500usb_register_write(rt2x00dev, TXRX_CSR11, erp->basic_rates);
505
506 rt2500usb_register_write(rt2x00dev, MAC_CSR10, erp->slot_time);
507 rt2500usb_register_write(rt2x00dev, MAC_CSR11, erp->sifs);
508 rt2500usb_register_write(rt2x00dev, MAC_CSR12, erp->eifs);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700509}
510
Ivo van Doorne4ea1c42008-10-29 17:17:57 +0100511static void rt2500usb_config_ant(struct rt2x00_dev *rt2x00dev,
512 struct antenna_setup *ant)
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700513{
514 u8 r2;
515 u8 r14;
516 u16 csr5;
517 u16 csr6;
518
Ivo van Doorna4fe07d2008-03-09 22:45:21 +0100519 /*
520 * We should never come here because rt2x00lib is supposed
521 * to catch this and send us the correct antenna explicitely.
522 */
523 BUG_ON(ant->rx == ANTENNA_SW_DIVERSITY ||
524 ant->tx == ANTENNA_SW_DIVERSITY);
525
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700526 rt2500usb_bbp_read(rt2x00dev, 2, &r2);
527 rt2500usb_bbp_read(rt2x00dev, 14, &r14);
528 rt2500usb_register_read(rt2x00dev, PHY_CSR5, &csr5);
529 rt2500usb_register_read(rt2x00dev, PHY_CSR6, &csr6);
530
531 /*
532 * Configure the TX antenna.
533 */
Ivo van Doornaddc81bd2007-10-13 16:26:23 +0200534 switch (ant->tx) {
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700535 case ANTENNA_HW_DIVERSITY:
536 rt2x00_set_field8(&r2, BBP_R2_TX_ANTENNA, 1);
537 rt2x00_set_field16(&csr5, PHY_CSR5_CCK, 1);
538 rt2x00_set_field16(&csr6, PHY_CSR6_OFDM, 1);
539 break;
540 case ANTENNA_A:
541 rt2x00_set_field8(&r2, BBP_R2_TX_ANTENNA, 0);
542 rt2x00_set_field16(&csr5, PHY_CSR5_CCK, 0);
543 rt2x00_set_field16(&csr6, PHY_CSR6_OFDM, 0);
544 break;
545 case ANTENNA_B:
Ivo van Doorna4fe07d2008-03-09 22:45:21 +0100546 default:
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700547 rt2x00_set_field8(&r2, BBP_R2_TX_ANTENNA, 2);
548 rt2x00_set_field16(&csr5, PHY_CSR5_CCK, 2);
549 rt2x00_set_field16(&csr6, PHY_CSR6_OFDM, 2);
550 break;
551 }
552
553 /*
554 * Configure the RX antenna.
555 */
Ivo van Doornaddc81bd2007-10-13 16:26:23 +0200556 switch (ant->rx) {
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700557 case ANTENNA_HW_DIVERSITY:
558 rt2x00_set_field8(&r14, BBP_R14_RX_ANTENNA, 1);
559 break;
560 case ANTENNA_A:
561 rt2x00_set_field8(&r14, BBP_R14_RX_ANTENNA, 0);
562 break;
563 case ANTENNA_B:
Ivo van Doorna4fe07d2008-03-09 22:45:21 +0100564 default:
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700565 rt2x00_set_field8(&r14, BBP_R14_RX_ANTENNA, 2);
566 break;
567 }
568
569 /*
570 * RT2525E and RT5222 need to flip TX I/Q
571 */
572 if (rt2x00_rf(&rt2x00dev->chip, RF2525E) ||
573 rt2x00_rf(&rt2x00dev->chip, RF5222)) {
574 rt2x00_set_field8(&r2, BBP_R2_TX_IQ_FLIP, 1);
575 rt2x00_set_field16(&csr5, PHY_CSR5_CCK_FLIP, 1);
576 rt2x00_set_field16(&csr6, PHY_CSR6_OFDM_FLIP, 1);
577
578 /*
579 * RT2525E does not need RX I/Q Flip.
580 */
581 if (rt2x00_rf(&rt2x00dev->chip, RF2525E))
582 rt2x00_set_field8(&r14, BBP_R14_RX_IQ_FLIP, 0);
583 } else {
584 rt2x00_set_field16(&csr5, PHY_CSR5_CCK_FLIP, 0);
585 rt2x00_set_field16(&csr6, PHY_CSR6_OFDM_FLIP, 0);
586 }
587
588 rt2500usb_bbp_write(rt2x00dev, 2, r2);
589 rt2500usb_bbp_write(rt2x00dev, 14, r14);
590 rt2500usb_register_write(rt2x00dev, PHY_CSR5, csr5);
591 rt2500usb_register_write(rt2x00dev, PHY_CSR6, csr6);
592}
593
Ivo van Doorne4ea1c42008-10-29 17:17:57 +0100594static void rt2500usb_config_channel(struct rt2x00_dev *rt2x00dev,
595 struct rf_channel *rf, const int txpower)
596{
597 /*
598 * Set TXpower.
599 */
600 rt2x00_set_field32(&rf->rf3, RF3_TXPOWER, TXPOWER_TO_DEV(txpower));
601
602 /*
603 * For RT2525E we should first set the channel to half band higher.
604 */
605 if (rt2x00_rf(&rt2x00dev->chip, RF2525E)) {
606 static const u32 vals[] = {
607 0x000008aa, 0x000008ae, 0x000008ae, 0x000008b2,
608 0x000008b2, 0x000008b6, 0x000008b6, 0x000008ba,
609 0x000008ba, 0x000008be, 0x000008b7, 0x00000902,
610 0x00000902, 0x00000906
611 };
612
613 rt2500usb_rf_write(rt2x00dev, 2, vals[rf->channel - 1]);
614 if (rf->rf4)
615 rt2500usb_rf_write(rt2x00dev, 4, rf->rf4);
616 }
617
618 rt2500usb_rf_write(rt2x00dev, 1, rf->rf1);
619 rt2500usb_rf_write(rt2x00dev, 2, rf->rf2);
620 rt2500usb_rf_write(rt2x00dev, 3, rf->rf3);
621 if (rf->rf4)
622 rt2500usb_rf_write(rt2x00dev, 4, rf->rf4);
623}
624
625static void rt2500usb_config_txpower(struct rt2x00_dev *rt2x00dev,
626 const int txpower)
627{
628 u32 rf3;
629
630 rt2x00_rf_read(rt2x00dev, 3, &rf3);
631 rt2x00_set_field32(&rf3, RF3_TXPOWER, TXPOWER_TO_DEV(txpower));
632 rt2500usb_rf_write(rt2x00dev, 3, rf3);
633}
634
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700635static void rt2500usb_config_duration(struct rt2x00_dev *rt2x00dev,
Ivo van Doorn5c58ee52007-10-06 13:34:52 +0200636 struct rt2x00lib_conf *libconf)
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700637{
638 u16 reg;
639
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700640 rt2500usb_register_read(rt2x00dev, TXRX_CSR18, &reg);
Ivo van Doorn5c58ee52007-10-06 13:34:52 +0200641 rt2x00_set_field16(&reg, TXRX_CSR18_INTERVAL,
642 libconf->conf->beacon_int * 4);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700643 rt2500usb_register_write(rt2x00dev, TXRX_CSR18, reg);
644}
645
Ivo van Doorn7d7f19c2008-12-20 10:52:42 +0100646static void rt2500usb_config_ps(struct rt2x00_dev *rt2x00dev,
647 struct rt2x00lib_conf *libconf)
648{
649 enum dev_state state =
650 (libconf->conf->flags & IEEE80211_CONF_PS) ?
651 STATE_SLEEP : STATE_AWAKE;
652 u16 reg;
653
654 if (state == STATE_SLEEP) {
655 rt2500usb_register_read(rt2x00dev, MAC_CSR18, &reg);
656 rt2x00_set_field16(&reg, MAC_CSR18_DELAY_AFTER_BEACON,
657 libconf->conf->beacon_int - 20);
658 rt2x00_set_field16(&reg, MAC_CSR18_BEACONS_BEFORE_WAKEUP,
659 libconf->conf->listen_interval - 1);
660
661 /* We must first disable autowake before it can be enabled */
662 rt2x00_set_field16(&reg, MAC_CSR18_AUTO_WAKE, 0);
663 rt2500usb_register_write(rt2x00dev, MAC_CSR18, reg);
664
665 rt2x00_set_field16(&reg, MAC_CSR18_AUTO_WAKE, 1);
666 rt2500usb_register_write(rt2x00dev, MAC_CSR18, reg);
667 }
668
669 rt2x00dev->ops->lib->set_device_state(rt2x00dev, state);
670}
671
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700672static void rt2500usb_config(struct rt2x00_dev *rt2x00dev,
Ivo van Doorn6bb40dd2008-02-03 15:49:59 +0100673 struct rt2x00lib_conf *libconf,
674 const unsigned int flags)
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700675{
Ivo van Doorne4ea1c42008-10-29 17:17:57 +0100676 if (flags & IEEE80211_CONF_CHANGE_CHANNEL)
Ivo van Doorn5c58ee52007-10-06 13:34:52 +0200677 rt2500usb_config_channel(rt2x00dev, &libconf->rf,
678 libconf->conf->power_level);
Ivo van Doorne4ea1c42008-10-29 17:17:57 +0100679 if ((flags & IEEE80211_CONF_CHANGE_POWER) &&
680 !(flags & IEEE80211_CONF_CHANGE_CHANNEL))
Ivo van Doorn5c58ee52007-10-06 13:34:52 +0200681 rt2500usb_config_txpower(rt2x00dev,
682 libconf->conf->power_level);
Ivo van Doorne4ea1c42008-10-29 17:17:57 +0100683 if (flags & IEEE80211_CONF_CHANGE_BEACON_INTERVAL)
Ivo van Doorn5c58ee52007-10-06 13:34:52 +0200684 rt2500usb_config_duration(rt2x00dev, libconf);
Ivo van Doorn7d7f19c2008-12-20 10:52:42 +0100685 if (flags & IEEE80211_CONF_CHANGE_PS)
686 rt2500usb_config_ps(rt2x00dev, libconf);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700687}
688
689/*
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700690 * Link tuning
691 */
Ivo van Doornebcf26da2007-10-13 16:26:12 +0200692static void rt2500usb_link_stats(struct rt2x00_dev *rt2x00dev,
693 struct link_qual *qual)
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700694{
695 u16 reg;
696
697 /*
698 * Update FCS error count from register.
699 */
700 rt2500usb_register_read(rt2x00dev, STA_CSR0, &reg);
Ivo van Doornebcf26da2007-10-13 16:26:12 +0200701 qual->rx_failed = rt2x00_get_field16(reg, STA_CSR0_FCS_ERROR);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700702
703 /*
704 * Update False CCA count from register.
705 */
706 rt2500usb_register_read(rt2x00dev, STA_CSR3, &reg);
Ivo van Doornebcf26da2007-10-13 16:26:12 +0200707 qual->false_cca = rt2x00_get_field16(reg, STA_CSR3_FALSE_CCA_ERROR);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700708}
709
Ivo van Doorn5352ff62008-12-20 10:54:54 +0100710static void rt2500usb_reset_tuner(struct rt2x00_dev *rt2x00dev,
711 struct link_qual *qual)
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700712{
713 u16 eeprom;
714 u16 value;
715
716 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R24, &eeprom);
717 value = rt2x00_get_field16(eeprom, EEPROM_BBPTUNE_R24_LOW);
718 rt2500usb_bbp_write(rt2x00dev, 24, value);
719
720 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R25, &eeprom);
721 value = rt2x00_get_field16(eeprom, EEPROM_BBPTUNE_R25_LOW);
722 rt2500usb_bbp_write(rt2x00dev, 25, value);
723
724 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R61, &eeprom);
725 value = rt2x00_get_field16(eeprom, EEPROM_BBPTUNE_R61_LOW);
726 rt2500usb_bbp_write(rt2x00dev, 61, value);
727
728 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_VGC, &eeprom);
729 value = rt2x00_get_field16(eeprom, EEPROM_BBPTUNE_VGCUPPER);
730 rt2500usb_bbp_write(rt2x00dev, 17, value);
731
Ivo van Doorn5352ff62008-12-20 10:54:54 +0100732 qual->vgc_level = value;
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700733}
734
Ivo van Doornd06193f2008-08-03 23:36:01 +0200735/*
736 * NOTE: This function is directly ported from legacy driver, but
737 * despite it being declared it was never called. Although link tuning
738 * sounds like a good idea, and usually works well for the other drivers,
739 * it does _not_ work with rt2500usb. Enabling this function will result
740 * in TX capabilities only until association kicks in. Immediately
741 * after the successful association all TX frames will be kept in the
742 * hardware queue and never transmitted.
743 */
744#if 0
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700745static void rt2500usb_link_tuner(struct rt2x00_dev *rt2x00dev)
746{
747 int rssi = rt2x00_get_link_rssi(&rt2x00dev->link);
748 u16 bbp_thresh;
749 u16 vgc_bound;
750 u16 sens;
751 u16 r24;
752 u16 r25;
753 u16 r61;
754 u16 r17_sens;
755 u8 r17;
756 u8 up_bound;
757 u8 low_bound;
758
759 /*
Ivo van Doorn6bb40dd2008-02-03 15:49:59 +0100760 * Read current r17 value, as well as the sensitivity values
761 * for the r17 register.
762 */
763 rt2500usb_bbp_read(rt2x00dev, 17, &r17);
764 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R17, &r17_sens);
765
766 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_VGC, &vgc_bound);
767 up_bound = rt2x00_get_field16(vgc_bound, EEPROM_BBPTUNE_VGCUPPER);
768 low_bound = rt2x00_get_field16(vgc_bound, EEPROM_BBPTUNE_VGCLOWER);
769
770 /*
771 * If we are not associated, we should go straight to the
772 * dynamic CCA tuning.
773 */
774 if (!rt2x00dev->intf_associated)
775 goto dynamic_cca_tune;
776
777 /*
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700778 * Determine the BBP tuning threshold and correctly
779 * set BBP 24, 25 and 61.
780 */
781 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE, &bbp_thresh);
782 bbp_thresh = rt2x00_get_field16(bbp_thresh, EEPROM_BBPTUNE_THRESHOLD);
783
784 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R24, &r24);
785 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R25, &r25);
786 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R61, &r61);
787
788 if ((rssi + bbp_thresh) > 0) {
789 r24 = rt2x00_get_field16(r24, EEPROM_BBPTUNE_R24_HIGH);
790 r25 = rt2x00_get_field16(r25, EEPROM_BBPTUNE_R25_HIGH);
791 r61 = rt2x00_get_field16(r61, EEPROM_BBPTUNE_R61_HIGH);
792 } else {
793 r24 = rt2x00_get_field16(r24, EEPROM_BBPTUNE_R24_LOW);
794 r25 = rt2x00_get_field16(r25, EEPROM_BBPTUNE_R25_LOW);
795 r61 = rt2x00_get_field16(r61, EEPROM_BBPTUNE_R61_LOW);
796 }
797
798 rt2500usb_bbp_write(rt2x00dev, 24, r24);
799 rt2500usb_bbp_write(rt2x00dev, 25, r25);
800 rt2500usb_bbp_write(rt2x00dev, 61, r61);
801
802 /*
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700803 * A too low RSSI will cause too much false CCA which will
804 * then corrupt the R17 tuning. To remidy this the tuning should
805 * be stopped (While making sure the R17 value will not exceed limits)
806 */
807 if (rssi >= -40) {
808 if (r17 != 0x60)
809 rt2500usb_bbp_write(rt2x00dev, 17, 0x60);
810 return;
811 }
812
813 /*
814 * Special big-R17 for short distance
815 */
816 if (rssi >= -58) {
817 sens = rt2x00_get_field16(r17_sens, EEPROM_BBPTUNE_R17_LOW);
818 if (r17 != sens)
819 rt2500usb_bbp_write(rt2x00dev, 17, sens);
820 return;
821 }
822
823 /*
824 * Special mid-R17 for middle distance
825 */
826 if (rssi >= -74) {
827 sens = rt2x00_get_field16(r17_sens, EEPROM_BBPTUNE_R17_HIGH);
828 if (r17 != sens)
829 rt2500usb_bbp_write(rt2x00dev, 17, sens);
830 return;
831 }
832
833 /*
834 * Leave short or middle distance condition, restore r17
835 * to the dynamic tuning range.
836 */
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700837 low_bound = 0x32;
Ivo van Doorn6bb40dd2008-02-03 15:49:59 +0100838 if (rssi < -77)
839 up_bound -= (-77 - rssi);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700840
841 if (up_bound < low_bound)
842 up_bound = low_bound;
843
844 if (r17 > up_bound) {
845 rt2500usb_bbp_write(rt2x00dev, 17, up_bound);
846 rt2x00dev->link.vgc_level = up_bound;
Ivo van Doorn6bb40dd2008-02-03 15:49:59 +0100847 return;
848 }
849
850dynamic_cca_tune:
851
852 /*
853 * R17 is inside the dynamic tuning range,
854 * start tuning the link based on the false cca counter.
855 */
856 if (rt2x00dev->link.qual.false_cca > 512 && r17 < up_bound) {
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700857 rt2500usb_bbp_write(rt2x00dev, 17, ++r17);
858 rt2x00dev->link.vgc_level = r17;
Ivo van Doornebcf26da2007-10-13 16:26:12 +0200859 } else if (rt2x00dev->link.qual.false_cca < 100 && r17 > low_bound) {
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700860 rt2500usb_bbp_write(rt2x00dev, 17, --r17);
861 rt2x00dev->link.vgc_level = r17;
862 }
863}
Ivo van Doornd06193f2008-08-03 23:36:01 +0200864#else
865#define rt2500usb_link_tuner NULL
866#endif
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700867
868/*
869 * Initialization functions.
870 */
871static int rt2500usb_init_registers(struct rt2x00_dev *rt2x00dev)
872{
873 u16 reg;
874
875 rt2x00usb_vendor_request_sw(rt2x00dev, USB_DEVICE_MODE, 0x0001,
876 USB_MODE_TEST, REGISTER_TIMEOUT);
877 rt2x00usb_vendor_request_sw(rt2x00dev, USB_SINGLE_WRITE, 0x0308,
878 0x00f0, REGISTER_TIMEOUT);
879
880 rt2500usb_register_read(rt2x00dev, TXRX_CSR2, &reg);
881 rt2x00_set_field16(&reg, TXRX_CSR2_DISABLE_RX, 1);
882 rt2500usb_register_write(rt2x00dev, TXRX_CSR2, reg);
883
884 rt2500usb_register_write(rt2x00dev, MAC_CSR13, 0x1111);
885 rt2500usb_register_write(rt2x00dev, MAC_CSR14, 0x1e11);
886
887 rt2500usb_register_read(rt2x00dev, MAC_CSR1, &reg);
888 rt2x00_set_field16(&reg, MAC_CSR1_SOFT_RESET, 1);
889 rt2x00_set_field16(&reg, MAC_CSR1_BBP_RESET, 1);
890 rt2x00_set_field16(&reg, MAC_CSR1_HOST_READY, 0);
891 rt2500usb_register_write(rt2x00dev, MAC_CSR1, reg);
892
893 rt2500usb_register_read(rt2x00dev, MAC_CSR1, &reg);
894 rt2x00_set_field16(&reg, MAC_CSR1_SOFT_RESET, 0);
895 rt2x00_set_field16(&reg, MAC_CSR1_BBP_RESET, 0);
896 rt2x00_set_field16(&reg, MAC_CSR1_HOST_READY, 0);
897 rt2500usb_register_write(rt2x00dev, MAC_CSR1, reg);
898
899 rt2500usb_register_read(rt2x00dev, TXRX_CSR5, &reg);
900 rt2x00_set_field16(&reg, TXRX_CSR5_BBP_ID0, 13);
901 rt2x00_set_field16(&reg, TXRX_CSR5_BBP_ID0_VALID, 1);
902 rt2x00_set_field16(&reg, TXRX_CSR5_BBP_ID1, 12);
903 rt2x00_set_field16(&reg, TXRX_CSR5_BBP_ID1_VALID, 1);
904 rt2500usb_register_write(rt2x00dev, TXRX_CSR5, reg);
905
906 rt2500usb_register_read(rt2x00dev, TXRX_CSR6, &reg);
907 rt2x00_set_field16(&reg, TXRX_CSR6_BBP_ID0, 10);
908 rt2x00_set_field16(&reg, TXRX_CSR6_BBP_ID0_VALID, 1);
909 rt2x00_set_field16(&reg, TXRX_CSR6_BBP_ID1, 11);
910 rt2x00_set_field16(&reg, TXRX_CSR6_BBP_ID1_VALID, 1);
911 rt2500usb_register_write(rt2x00dev, TXRX_CSR6, reg);
912
913 rt2500usb_register_read(rt2x00dev, TXRX_CSR7, &reg);
914 rt2x00_set_field16(&reg, TXRX_CSR7_BBP_ID0, 7);
915 rt2x00_set_field16(&reg, TXRX_CSR7_BBP_ID0_VALID, 1);
916 rt2x00_set_field16(&reg, TXRX_CSR7_BBP_ID1, 6);
917 rt2x00_set_field16(&reg, TXRX_CSR7_BBP_ID1_VALID, 1);
918 rt2500usb_register_write(rt2x00dev, TXRX_CSR7, reg);
919
920 rt2500usb_register_read(rt2x00dev, TXRX_CSR8, &reg);
921 rt2x00_set_field16(&reg, TXRX_CSR8_BBP_ID0, 5);
922 rt2x00_set_field16(&reg, TXRX_CSR8_BBP_ID0_VALID, 1);
923 rt2x00_set_field16(&reg, TXRX_CSR8_BBP_ID1, 0);
924 rt2x00_set_field16(&reg, TXRX_CSR8_BBP_ID1_VALID, 0);
925 rt2500usb_register_write(rt2x00dev, TXRX_CSR8, reg);
926
Ivo van Doorn1f909162008-07-08 13:45:20 +0200927 rt2500usb_register_read(rt2x00dev, TXRX_CSR19, &reg);
928 rt2x00_set_field16(&reg, TXRX_CSR19_TSF_COUNT, 0);
929 rt2x00_set_field16(&reg, TXRX_CSR19_TSF_SYNC, 0);
930 rt2x00_set_field16(&reg, TXRX_CSR19_TBCN, 0);
931 rt2x00_set_field16(&reg, TXRX_CSR19_BEACON_GEN, 0);
932 rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg);
933
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700934 rt2500usb_register_write(rt2x00dev, TXRX_CSR21, 0xe78f);
935 rt2500usb_register_write(rt2x00dev, MAC_CSR9, 0xff1d);
936
937 if (rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_AWAKE))
938 return -EBUSY;
939
940 rt2500usb_register_read(rt2x00dev, MAC_CSR1, &reg);
941 rt2x00_set_field16(&reg, MAC_CSR1_SOFT_RESET, 0);
942 rt2x00_set_field16(&reg, MAC_CSR1_BBP_RESET, 0);
943 rt2x00_set_field16(&reg, MAC_CSR1_HOST_READY, 1);
944 rt2500usb_register_write(rt2x00dev, MAC_CSR1, reg);
945
Ivo van Doorn755a9572007-11-12 15:02:22 +0100946 if (rt2x00_rev(&rt2x00dev->chip) >= RT2570_VERSION_C) {
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700947 rt2500usb_register_read(rt2x00dev, PHY_CSR2, &reg);
Ivo van Doornddc827f2007-10-13 16:26:42 +0200948 rt2x00_set_field16(&reg, PHY_CSR2_LNA, 0);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700949 } else {
Ivo van Doornddc827f2007-10-13 16:26:42 +0200950 reg = 0;
951 rt2x00_set_field16(&reg, PHY_CSR2_LNA, 1);
952 rt2x00_set_field16(&reg, PHY_CSR2_LNA_MODE, 3);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700953 }
954 rt2500usb_register_write(rt2x00dev, PHY_CSR2, reg);
955
956 rt2500usb_register_write(rt2x00dev, MAC_CSR11, 0x0002);
957 rt2500usb_register_write(rt2x00dev, MAC_CSR22, 0x0053);
958 rt2500usb_register_write(rt2x00dev, MAC_CSR15, 0x01ee);
959 rt2500usb_register_write(rt2x00dev, MAC_CSR16, 0x0000);
960
961 rt2500usb_register_read(rt2x00dev, MAC_CSR8, &reg);
962 rt2x00_set_field16(&reg, MAC_CSR8_MAX_FRAME_UNIT,
963 rt2x00dev->rx->data_size);
964 rt2500usb_register_write(rt2x00dev, MAC_CSR8, reg);
965
966 rt2500usb_register_read(rt2x00dev, TXRX_CSR0, &reg);
967 rt2x00_set_field16(&reg, TXRX_CSR0_IV_OFFSET, IEEE80211_HEADER);
Ivo van Doorndddfb472008-12-02 18:20:42 +0100968 rt2x00_set_field16(&reg, TXRX_CSR0_KEY_ID, 0);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700969 rt2500usb_register_write(rt2x00dev, TXRX_CSR0, reg);
970
971 rt2500usb_register_read(rt2x00dev, MAC_CSR18, &reg);
972 rt2x00_set_field16(&reg, MAC_CSR18_DELAY_AFTER_BEACON, 90);
973 rt2500usb_register_write(rt2x00dev, MAC_CSR18, reg);
974
975 rt2500usb_register_read(rt2x00dev, PHY_CSR4, &reg);
976 rt2x00_set_field16(&reg, PHY_CSR4_LOW_RF_LE, 1);
977 rt2500usb_register_write(rt2x00dev, PHY_CSR4, reg);
978
979 rt2500usb_register_read(rt2x00dev, TXRX_CSR1, &reg);
980 rt2x00_set_field16(&reg, TXRX_CSR1_AUTO_SEQUENCE, 1);
981 rt2500usb_register_write(rt2x00dev, TXRX_CSR1, reg);
982
983 return 0;
984}
985
Ivo van Doorn2b08da32008-06-03 18:58:56 +0200986static int rt2500usb_wait_bbp_ready(struct rt2x00_dev *rt2x00dev)
987{
988 unsigned int i;
989 u8 value;
990
991 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
992 rt2500usb_bbp_read(rt2x00dev, 0, &value);
993 if ((value != 0xff) && (value != 0x00))
994 return 0;
995 udelay(REGISTER_BUSY_DELAY);
996 }
997
998 ERROR(rt2x00dev, "BBP register access failed, aborting.\n");
999 return -EACCES;
1000}
1001
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001002static int rt2500usb_init_bbp(struct rt2x00_dev *rt2x00dev)
1003{
1004 unsigned int i;
1005 u16 eeprom;
1006 u8 value;
1007 u8 reg_id;
1008
Ivo van Doorn2b08da32008-06-03 18:58:56 +02001009 if (unlikely(rt2500usb_wait_bbp_ready(rt2x00dev)))
1010 return -EACCES;
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001011
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001012 rt2500usb_bbp_write(rt2x00dev, 3, 0x02);
1013 rt2500usb_bbp_write(rt2x00dev, 4, 0x19);
1014 rt2500usb_bbp_write(rt2x00dev, 14, 0x1c);
1015 rt2500usb_bbp_write(rt2x00dev, 15, 0x30);
1016 rt2500usb_bbp_write(rt2x00dev, 16, 0xac);
1017 rt2500usb_bbp_write(rt2x00dev, 18, 0x18);
1018 rt2500usb_bbp_write(rt2x00dev, 19, 0xff);
1019 rt2500usb_bbp_write(rt2x00dev, 20, 0x1e);
1020 rt2500usb_bbp_write(rt2x00dev, 21, 0x08);
1021 rt2500usb_bbp_write(rt2x00dev, 22, 0x08);
1022 rt2500usb_bbp_write(rt2x00dev, 23, 0x08);
1023 rt2500usb_bbp_write(rt2x00dev, 24, 0x80);
1024 rt2500usb_bbp_write(rt2x00dev, 25, 0x50);
1025 rt2500usb_bbp_write(rt2x00dev, 26, 0x08);
1026 rt2500usb_bbp_write(rt2x00dev, 27, 0x23);
1027 rt2500usb_bbp_write(rt2x00dev, 30, 0x10);
1028 rt2500usb_bbp_write(rt2x00dev, 31, 0x2b);
1029 rt2500usb_bbp_write(rt2x00dev, 32, 0xb9);
1030 rt2500usb_bbp_write(rt2x00dev, 34, 0x12);
1031 rt2500usb_bbp_write(rt2x00dev, 35, 0x50);
1032 rt2500usb_bbp_write(rt2x00dev, 39, 0xc4);
1033 rt2500usb_bbp_write(rt2x00dev, 40, 0x02);
1034 rt2500usb_bbp_write(rt2x00dev, 41, 0x60);
1035 rt2500usb_bbp_write(rt2x00dev, 53, 0x10);
1036 rt2500usb_bbp_write(rt2x00dev, 54, 0x18);
1037 rt2500usb_bbp_write(rt2x00dev, 56, 0x08);
1038 rt2500usb_bbp_write(rt2x00dev, 57, 0x10);
1039 rt2500usb_bbp_write(rt2x00dev, 58, 0x08);
1040 rt2500usb_bbp_write(rt2x00dev, 61, 0x60);
1041 rt2500usb_bbp_write(rt2x00dev, 62, 0x10);
1042 rt2500usb_bbp_write(rt2x00dev, 75, 0xff);
1043
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001044 for (i = 0; i < EEPROM_BBP_SIZE; i++) {
1045 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBP_START + i, &eeprom);
1046
1047 if (eeprom != 0xffff && eeprom != 0x0000) {
1048 reg_id = rt2x00_get_field16(eeprom, EEPROM_BBP_REG_ID);
1049 value = rt2x00_get_field16(eeprom, EEPROM_BBP_VALUE);
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001050 rt2500usb_bbp_write(rt2x00dev, reg_id, value);
1051 }
1052 }
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001053
1054 return 0;
1055}
1056
1057/*
1058 * Device state switch handlers.
1059 */
1060static void rt2500usb_toggle_rx(struct rt2x00_dev *rt2x00dev,
1061 enum dev_state state)
1062{
1063 u16 reg;
1064
1065 rt2500usb_register_read(rt2x00dev, TXRX_CSR2, &reg);
1066 rt2x00_set_field16(&reg, TXRX_CSR2_DISABLE_RX,
Ivo van Doorn2b08da32008-06-03 18:58:56 +02001067 (state == STATE_RADIO_RX_OFF) ||
1068 (state == STATE_RADIO_RX_OFF_LINK));
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001069 rt2500usb_register_write(rt2x00dev, TXRX_CSR2, reg);
1070}
1071
1072static int rt2500usb_enable_radio(struct rt2x00_dev *rt2x00dev)
1073{
1074 /*
1075 * Initialize all registers.
1076 */
Ivo van Doorn2b08da32008-06-03 18:58:56 +02001077 if (unlikely(rt2500usb_init_registers(rt2x00dev) ||
1078 rt2500usb_init_bbp(rt2x00dev)))
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001079 return -EIO;
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001080
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001081 return 0;
1082}
1083
1084static void rt2500usb_disable_radio(struct rt2x00_dev *rt2x00dev)
1085{
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001086 rt2500usb_register_write(rt2x00dev, MAC_CSR13, 0x2121);
1087 rt2500usb_register_write(rt2x00dev, MAC_CSR14, 0x2121);
1088
1089 /*
1090 * Disable synchronisation.
1091 */
1092 rt2500usb_register_write(rt2x00dev, TXRX_CSR19, 0);
1093
1094 rt2x00usb_disable_radio(rt2x00dev);
1095}
1096
1097static int rt2500usb_set_state(struct rt2x00_dev *rt2x00dev,
1098 enum dev_state state)
1099{
1100 u16 reg;
1101 u16 reg2;
1102 unsigned int i;
1103 char put_to_sleep;
1104 char bbp_state;
1105 char rf_state;
1106
1107 put_to_sleep = (state != STATE_AWAKE);
1108
1109 reg = 0;
1110 rt2x00_set_field16(&reg, MAC_CSR17_BBP_DESIRE_STATE, state);
1111 rt2x00_set_field16(&reg, MAC_CSR17_RF_DESIRE_STATE, state);
1112 rt2x00_set_field16(&reg, MAC_CSR17_PUT_TO_SLEEP, put_to_sleep);
1113 rt2500usb_register_write(rt2x00dev, MAC_CSR17, reg);
1114 rt2x00_set_field16(&reg, MAC_CSR17_SET_STATE, 1);
1115 rt2500usb_register_write(rt2x00dev, MAC_CSR17, reg);
1116
1117 /*
1118 * Device is not guaranteed to be in the requested state yet.
1119 * We must wait until the register indicates that the
1120 * device has entered the correct state.
1121 */
1122 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
1123 rt2500usb_register_read(rt2x00dev, MAC_CSR17, &reg2);
1124 bbp_state = rt2x00_get_field16(reg2, MAC_CSR17_BBP_CURR_STATE);
1125 rf_state = rt2x00_get_field16(reg2, MAC_CSR17_RF_CURR_STATE);
1126 if (bbp_state == state && rf_state == state)
1127 return 0;
1128 rt2500usb_register_write(rt2x00dev, MAC_CSR17, reg);
1129 msleep(30);
1130 }
1131
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001132 return -EBUSY;
1133}
1134
1135static int rt2500usb_set_device_state(struct rt2x00_dev *rt2x00dev,
1136 enum dev_state state)
1137{
1138 int retval = 0;
1139
1140 switch (state) {
1141 case STATE_RADIO_ON:
1142 retval = rt2500usb_enable_radio(rt2x00dev);
1143 break;
1144 case STATE_RADIO_OFF:
1145 rt2500usb_disable_radio(rt2x00dev);
1146 break;
1147 case STATE_RADIO_RX_ON:
Ivo van Doorn61667d82008-02-25 23:15:05 +01001148 case STATE_RADIO_RX_ON_LINK:
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001149 case STATE_RADIO_RX_OFF:
Ivo van Doorn61667d82008-02-25 23:15:05 +01001150 case STATE_RADIO_RX_OFF_LINK:
Ivo van Doorn2b08da32008-06-03 18:58:56 +02001151 rt2500usb_toggle_rx(rt2x00dev, state);
1152 break;
1153 case STATE_RADIO_IRQ_ON:
1154 case STATE_RADIO_IRQ_OFF:
1155 /* No support, but no error either */
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001156 break;
1157 case STATE_DEEP_SLEEP:
1158 case STATE_SLEEP:
1159 case STATE_STANDBY:
1160 case STATE_AWAKE:
1161 retval = rt2500usb_set_state(rt2x00dev, state);
1162 break;
1163 default:
1164 retval = -ENOTSUPP;
1165 break;
1166 }
1167
Ivo van Doorn2b08da32008-06-03 18:58:56 +02001168 if (unlikely(retval))
1169 ERROR(rt2x00dev, "Device failed to enter state %d (%d).\n",
1170 state, retval);
1171
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001172 return retval;
1173}
1174
1175/*
1176 * TX descriptor initialization
1177 */
1178static void rt2500usb_write_tx_desc(struct rt2x00_dev *rt2x00dev,
Ivo van Doorndd3193e2008-01-06 23:41:10 +01001179 struct sk_buff *skb,
Ivo van Doorn61486e02008-05-10 13:42:31 +02001180 struct txentry_desc *txdesc)
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001181{
Ivo van Doorn181d6902008-02-05 16:42:23 -05001182 struct skb_frame_desc *skbdesc = get_skb_frame_desc(skb);
Ivo van Doorndd3193e2008-01-06 23:41:10 +01001183 __le32 *txd = skbdesc->desc;
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001184 u32 word;
1185
1186 /*
1187 * Start writing the descriptor words.
1188 */
1189 rt2x00_desc_read(txd, 1, &word);
Ivo van Doorndddfb472008-12-02 18:20:42 +01001190 rt2x00_set_field32(&word, TXD_W1_IV_OFFSET, txdesc->iv_offset);
Ivo van Doorn181d6902008-02-05 16:42:23 -05001191 rt2x00_set_field32(&word, TXD_W1_AIFS, txdesc->aifs);
1192 rt2x00_set_field32(&word, TXD_W1_CWMIN, txdesc->cw_min);
1193 rt2x00_set_field32(&word, TXD_W1_CWMAX, txdesc->cw_max);
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001194 rt2x00_desc_write(txd, 1, word);
1195
1196 rt2x00_desc_read(txd, 2, &word);
Ivo van Doorn181d6902008-02-05 16:42:23 -05001197 rt2x00_set_field32(&word, TXD_W2_PLCP_SIGNAL, txdesc->signal);
1198 rt2x00_set_field32(&word, TXD_W2_PLCP_SERVICE, txdesc->service);
1199 rt2x00_set_field32(&word, TXD_W2_PLCP_LENGTH_LOW, txdesc->length_low);
1200 rt2x00_set_field32(&word, TXD_W2_PLCP_LENGTH_HIGH, txdesc->length_high);
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001201 rt2x00_desc_write(txd, 2, word);
1202
Ivo van Doorndddfb472008-12-02 18:20:42 +01001203 if (test_bit(ENTRY_TXD_ENCRYPT, &txdesc->flags)) {
1204 _rt2x00_desc_write(txd, 3, skbdesc->iv[0]);
1205 _rt2x00_desc_write(txd, 4, skbdesc->iv[1]);
1206 }
1207
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001208 rt2x00_desc_read(txd, 0, &word);
Ivo van Doorn61486e02008-05-10 13:42:31 +02001209 rt2x00_set_field32(&word, TXD_W0_RETRY_LIMIT, txdesc->retry_limit);
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001210 rt2x00_set_field32(&word, TXD_W0_MORE_FRAG,
Ivo van Doorn181d6902008-02-05 16:42:23 -05001211 test_bit(ENTRY_TXD_MORE_FRAG, &txdesc->flags));
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001212 rt2x00_set_field32(&word, TXD_W0_ACK,
Ivo van Doorn181d6902008-02-05 16:42:23 -05001213 test_bit(ENTRY_TXD_ACK, &txdesc->flags));
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001214 rt2x00_set_field32(&word, TXD_W0_TIMESTAMP,
Ivo van Doorn181d6902008-02-05 16:42:23 -05001215 test_bit(ENTRY_TXD_REQ_TIMESTAMP, &txdesc->flags));
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001216 rt2x00_set_field32(&word, TXD_W0_OFDM,
Ivo van Doorn076f9582008-12-20 10:59:02 +01001217 (txdesc->rate_mode == RATE_MODE_OFDM));
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001218 rt2x00_set_field32(&word, TXD_W0_NEW_SEQ,
Ivo van Doorn61486e02008-05-10 13:42:31 +02001219 test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags));
Ivo van Doorn181d6902008-02-05 16:42:23 -05001220 rt2x00_set_field32(&word, TXD_W0_IFS, txdesc->ifs);
Mattias Nissler1abc3652008-08-29 21:07:20 +02001221 rt2x00_set_field32(&word, TXD_W0_DATABYTE_COUNT, skb->len);
Ivo van Doornf1dd2b22009-01-03 16:27:14 +01001222 rt2x00_set_field32(&word, TXD_W0_CIPHER, !!txdesc->cipher);
Ivo van Doorndddfb472008-12-02 18:20:42 +01001223 rt2x00_set_field32(&word, TXD_W0_KEY_ID, txdesc->key_idx);
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001224 rt2x00_desc_write(txd, 0, word);
1225}
1226
Ivo van Doornbd88a782008-07-09 15:12:44 +02001227/*
1228 * TX data initialization
1229 */
1230static void rt2500usb_beacondone(struct urb *urb);
1231
1232static void rt2500usb_write_beacon(struct queue_entry *entry)
1233{
1234 struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
1235 struct usb_device *usb_dev = to_usb_device_intf(rt2x00dev->dev);
1236 struct queue_entry_priv_usb_bcn *bcn_priv = entry->priv_data;
1237 struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
Ivo van Doornf1ca2162008-11-13 23:07:33 +01001238 int pipe = usb_sndbulkpipe(usb_dev, entry->queue->usb_endpoint);
Ivo van Doornbd88a782008-07-09 15:12:44 +02001239 int length;
1240 u16 reg;
1241
1242 /*
1243 * Add the descriptor in front of the skb.
1244 */
1245 skb_push(entry->skb, entry->queue->desc_size);
1246 memcpy(entry->skb->data, skbdesc->desc, skbdesc->desc_len);
1247 skbdesc->desc = entry->skb->data;
1248
1249 /*
1250 * Disable beaconing while we are reloading the beacon data,
1251 * otherwise we might be sending out invalid data.
1252 */
1253 rt2500usb_register_read(rt2x00dev, TXRX_CSR19, &reg);
1254 rt2x00_set_field16(&reg, TXRX_CSR19_TSF_COUNT, 0);
1255 rt2x00_set_field16(&reg, TXRX_CSR19_TBCN, 0);
1256 rt2x00_set_field16(&reg, TXRX_CSR19_BEACON_GEN, 0);
1257 rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg);
1258
1259 /*
1260 * USB devices cannot blindly pass the skb->len as the
1261 * length of the data to usb_fill_bulk_urb. Pass the skb
1262 * to the driver to determine what the length should be.
1263 */
Ivo van Doornf1ca2162008-11-13 23:07:33 +01001264 length = rt2x00dev->ops->lib->get_tx_data_len(entry);
Ivo van Doornbd88a782008-07-09 15:12:44 +02001265
1266 usb_fill_bulk_urb(bcn_priv->urb, usb_dev, pipe,
1267 entry->skb->data, length, rt2500usb_beacondone,
1268 entry);
1269
1270 /*
1271 * Second we need to create the guardian byte.
1272 * We only need a single byte, so lets recycle
1273 * the 'flags' field we are not using for beacons.
1274 */
1275 bcn_priv->guardian_data = 0;
1276 usb_fill_bulk_urb(bcn_priv->guardian_urb, usb_dev, pipe,
1277 &bcn_priv->guardian_data, 1, rt2500usb_beacondone,
1278 entry);
1279
1280 /*
1281 * Send out the guardian byte.
1282 */
1283 usb_submit_urb(bcn_priv->guardian_urb, GFP_ATOMIC);
1284}
1285
Ivo van Doornf1ca2162008-11-13 23:07:33 +01001286static int rt2500usb_get_tx_data_len(struct queue_entry *entry)
Ivo van Doorndd9fa2d2007-10-06 14:15:46 +02001287{
1288 int length;
1289
1290 /*
1291 * The length _must_ be a multiple of 2,
1292 * but it must _not_ be a multiple of the USB packet size.
1293 */
Ivo van Doornf1ca2162008-11-13 23:07:33 +01001294 length = roundup(entry->skb->len, 2);
1295 length += (2 * !(length % entry->queue->usb_maxpacket));
Ivo van Doorndd9fa2d2007-10-06 14:15:46 +02001296
1297 return length;
1298}
1299
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001300static void rt2500usb_kick_tx_queue(struct rt2x00_dev *rt2x00dev,
Ivo van Doorne58c6ac2008-04-21 19:00:47 +02001301 const enum data_queue_qid queue)
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001302{
1303 u16 reg;
1304
Ivo van Doornf019d512008-06-06 22:47:39 +02001305 if (queue != QID_BEACON) {
1306 rt2x00usb_kick_tx_queue(rt2x00dev, queue);
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001307 return;
Ivo van Doornf019d512008-06-06 22:47:39 +02001308 }
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001309
1310 rt2500usb_register_read(rt2x00dev, TXRX_CSR19, &reg);
1311 if (!rt2x00_get_field16(reg, TXRX_CSR19_BEACON_GEN)) {
Ivo van Doorn8af244c2008-03-09 22:42:59 +01001312 rt2x00_set_field16(&reg, TXRX_CSR19_TSF_COUNT, 1);
1313 rt2x00_set_field16(&reg, TXRX_CSR19_TBCN, 1);
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001314 rt2x00_set_field16(&reg, TXRX_CSR19_BEACON_GEN, 1);
1315 /*
1316 * Beacon generation will fail initially.
1317 * To prevent this we need to register the TXRX_CSR19
1318 * register several times.
1319 */
1320 rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg);
1321 rt2500usb_register_write(rt2x00dev, TXRX_CSR19, 0);
1322 rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg);
1323 rt2500usb_register_write(rt2x00dev, TXRX_CSR19, 0);
1324 rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg);
1325 }
1326}
1327
1328/*
1329 * RX control handlers
1330 */
Ivo van Doorn181d6902008-02-05 16:42:23 -05001331static void rt2500usb_fill_rxdone(struct queue_entry *entry,
1332 struct rxdone_entry_desc *rxdesc)
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001333{
Ivo van Doorndddfb472008-12-02 18:20:42 +01001334 struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
Ivo van Doornb8be63f2008-05-10 13:46:03 +02001335 struct queue_entry_priv_usb *entry_priv = entry->priv_data;
Ivo van Doorn181d6902008-02-05 16:42:23 -05001336 struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
1337 __le32 *rxd =
1338 (__le32 *)(entry->skb->data +
Ivo van Doornb8be63f2008-05-10 13:46:03 +02001339 (entry_priv->urb->actual_length -
1340 entry->queue->desc_size));
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001341 u32 word0;
1342 u32 word1;
1343
Ivo van Doornf855c102008-03-09 22:38:18 +01001344 /*
Gertjan van Wingerdea26cbc62008-06-06 22:54:28 +02001345 * Copy descriptor to the skbdesc->desc buffer, making it safe from moving of
1346 * frame data in rt2x00usb.
Ivo van Doornf855c102008-03-09 22:38:18 +01001347 */
Gertjan van Wingerdea26cbc62008-06-06 22:54:28 +02001348 memcpy(skbdesc->desc, rxd, skbdesc->desc_len);
Ivo van Doorn70a96102008-05-10 13:43:38 +02001349 rxd = (__le32 *)skbdesc->desc;
Ivo van Doornf855c102008-03-09 22:38:18 +01001350
1351 /*
Ivo van Doorn70a96102008-05-10 13:43:38 +02001352 * It is now safe to read the descriptor on all architectures.
Ivo van Doornf855c102008-03-09 22:38:18 +01001353 */
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001354 rt2x00_desc_read(rxd, 0, &word0);
1355 rt2x00_desc_read(rxd, 1, &word1);
1356
Johannes Berg4150c572007-09-17 01:29:23 -04001357 if (rt2x00_get_field32(word0, RXD_W0_CRC_ERROR))
Ivo van Doorn181d6902008-02-05 16:42:23 -05001358 rxdesc->flags |= RX_FLAG_FAILED_FCS_CRC;
Johannes Berg4150c572007-09-17 01:29:23 -04001359 if (rt2x00_get_field32(word0, RXD_W0_PHYSICAL_ERROR))
Ivo van Doorn181d6902008-02-05 16:42:23 -05001360 rxdesc->flags |= RX_FLAG_FAILED_PLCP_CRC;
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001361
Ivo van Doorndddfb472008-12-02 18:20:42 +01001362 if (test_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags)) {
1363 rxdesc->cipher = rt2x00_get_field32(word0, RXD_W0_CIPHER);
1364 if (rt2x00_get_field32(word0, RXD_W0_CIPHER_ERROR))
1365 rxdesc->cipher_status = RX_CRYPTO_FAIL_KEY;
1366 }
1367
1368 if (rxdesc->cipher != CIPHER_NONE) {
1369 _rt2x00_desc_read(rxd, 2, &rxdesc->iv[0]);
1370 _rt2x00_desc_read(rxd, 3, &rxdesc->iv[1]);
Ivo van Doorn74415ed2008-12-02 22:50:33 +01001371 rxdesc->dev_flags |= RXDONE_CRYPTO_IV;
1372
Ivo van Doorndddfb472008-12-02 18:20:42 +01001373 /* ICV is located at the end of frame */
1374
Ivo van Doornf3d340c2008-12-21 23:19:17 +01001375 rxdesc->flags |= RX_FLAG_MMIC_STRIPPED;
Ivo van Doorndddfb472008-12-02 18:20:42 +01001376 if (rxdesc->cipher_status == RX_CRYPTO_SUCCESS)
1377 rxdesc->flags |= RX_FLAG_DECRYPTED;
1378 else if (rxdesc->cipher_status == RX_CRYPTO_FAIL_MIC)
1379 rxdesc->flags |= RX_FLAG_MMIC_ERROR;
1380 }
1381
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001382 /*
1383 * Obtain the status about this packet.
Ivo van Doorn89993892008-03-09 22:49:04 +01001384 * When frame was received with an OFDM bitrate,
1385 * the signal is the PLCP value. If it was received with
1386 * a CCK bitrate the signal is the rate in 100kbit/s.
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001387 */
Ivo van Doorn181d6902008-02-05 16:42:23 -05001388 rxdesc->signal = rt2x00_get_field32(word1, RXD_W1_SIGNAL);
Ivo van Doorndddfb472008-12-02 18:20:42 +01001389 rxdesc->rssi =
1390 rt2x00_get_field32(word1, RXD_W1_RSSI) - rt2x00dev->rssi_offset;
Ivo van Doorn181d6902008-02-05 16:42:23 -05001391 rxdesc->size = rt2x00_get_field32(word0, RXD_W0_DATABYTE_COUNT);
Ivo van Doorn19d30e02008-03-15 21:38:07 +01001392
Ivo van Doorn19d30e02008-03-15 21:38:07 +01001393 if (rt2x00_get_field32(word0, RXD_W0_OFDM))
1394 rxdesc->dev_flags |= RXDONE_SIGNAL_PLCP;
Ivo van Doorn6c6aa3c2008-08-29 21:07:16 +02001395 else
1396 rxdesc->dev_flags |= RXDONE_SIGNAL_BITRATE;
Ivo van Doorn19d30e02008-03-15 21:38:07 +01001397 if (rt2x00_get_field32(word0, RXD_W0_MY_BSS))
1398 rxdesc->dev_flags |= RXDONE_MY_BSS;
Ivo van Doorn7d1de802008-01-06 23:42:04 +01001399
1400 /*
Mattias Nissler2ae23852008-03-09 22:41:22 +01001401 * Adjust the skb memory window to the frame boundaries.
1402 */
Mattias Nissler2ae23852008-03-09 22:41:22 +01001403 skb_trim(entry->skb, rxdesc->size);
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001404}
1405
1406/*
1407 * Interrupt functions.
1408 */
1409static void rt2500usb_beacondone(struct urb *urb)
1410{
Ivo van Doorn181d6902008-02-05 16:42:23 -05001411 struct queue_entry *entry = (struct queue_entry *)urb->context;
Ivo van Doornb8be63f2008-05-10 13:46:03 +02001412 struct queue_entry_priv_usb_bcn *bcn_priv = entry->priv_data;
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001413
Ivo van Doorn0262ab02008-08-29 21:04:26 +02001414 if (!test_bit(DEVICE_STATE_ENABLED_RADIO, &entry->queue->rt2x00dev->flags))
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001415 return;
1416
1417 /*
1418 * Check if this was the guardian beacon,
1419 * if that was the case we need to send the real beacon now.
1420 * Otherwise we should free the sk_buffer, the device
1421 * should be doing the rest of the work now.
1422 */
Ivo van Doornb8be63f2008-05-10 13:46:03 +02001423 if (bcn_priv->guardian_urb == urb) {
1424 usb_submit_urb(bcn_priv->urb, GFP_ATOMIC);
1425 } else if (bcn_priv->urb == urb) {
Ivo van Doorn181d6902008-02-05 16:42:23 -05001426 dev_kfree_skb(entry->skb);
1427 entry->skb = NULL;
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001428 }
1429}
1430
1431/*
1432 * Device probe functions.
1433 */
1434static int rt2500usb_validate_eeprom(struct rt2x00_dev *rt2x00dev)
1435{
1436 u16 word;
1437 u8 *mac;
Ivo van Doorn6bb40dd2008-02-03 15:49:59 +01001438 u8 bbp;
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001439
1440 rt2x00usb_eeprom_read(rt2x00dev, rt2x00dev->eeprom, EEPROM_SIZE);
1441
1442 /*
1443 * Start validation of the data that has been read.
1444 */
1445 mac = rt2x00_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0);
1446 if (!is_valid_ether_addr(mac)) {
1447 random_ether_addr(mac);
Johannes Berge1749612008-10-27 15:59:26 -07001448 EEPROM(rt2x00dev, "MAC: %pM\n", mac);
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001449 }
1450
1451 rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &word);
1452 if (word == 0xffff) {
1453 rt2x00_set_field16(&word, EEPROM_ANTENNA_NUM, 2);
Ivo van Doorn362f3b62007-10-13 16:26:18 +02001454 rt2x00_set_field16(&word, EEPROM_ANTENNA_TX_DEFAULT,
1455 ANTENNA_SW_DIVERSITY);
1456 rt2x00_set_field16(&word, EEPROM_ANTENNA_RX_DEFAULT,
1457 ANTENNA_SW_DIVERSITY);
1458 rt2x00_set_field16(&word, EEPROM_ANTENNA_LED_MODE,
1459 LED_MODE_DEFAULT);
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001460 rt2x00_set_field16(&word, EEPROM_ANTENNA_DYN_TXAGC, 0);
1461 rt2x00_set_field16(&word, EEPROM_ANTENNA_HARDWARE_RADIO, 0);
1462 rt2x00_set_field16(&word, EEPROM_ANTENNA_RF_TYPE, RF2522);
1463 rt2x00_eeprom_write(rt2x00dev, EEPROM_ANTENNA, word);
1464 EEPROM(rt2x00dev, "Antenna: 0x%04x\n", word);
1465 }
1466
1467 rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &word);
1468 if (word == 0xffff) {
1469 rt2x00_set_field16(&word, EEPROM_NIC_CARDBUS_ACCEL, 0);
1470 rt2x00_set_field16(&word, EEPROM_NIC_DYN_BBP_TUNE, 0);
1471 rt2x00_set_field16(&word, EEPROM_NIC_CCK_TX_POWER, 0);
1472 rt2x00_eeprom_write(rt2x00dev, EEPROM_NIC, word);
1473 EEPROM(rt2x00dev, "NIC: 0x%04x\n", word);
1474 }
1475
1476 rt2x00_eeprom_read(rt2x00dev, EEPROM_CALIBRATE_OFFSET, &word);
1477 if (word == 0xffff) {
1478 rt2x00_set_field16(&word, EEPROM_CALIBRATE_OFFSET_RSSI,
1479 DEFAULT_RSSI_OFFSET);
1480 rt2x00_eeprom_write(rt2x00dev, EEPROM_CALIBRATE_OFFSET, word);
1481 EEPROM(rt2x00dev, "Calibrate offset: 0x%04x\n", word);
1482 }
1483
1484 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE, &word);
1485 if (word == 0xffff) {
1486 rt2x00_set_field16(&word, EEPROM_BBPTUNE_THRESHOLD, 45);
1487 rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE, word);
1488 EEPROM(rt2x00dev, "BBPtune: 0x%04x\n", word);
1489 }
1490
Ivo van Doorn6bb40dd2008-02-03 15:49:59 +01001491 /*
1492 * Switch lower vgc bound to current BBP R17 value,
1493 * lower the value a bit for better quality.
1494 */
1495 rt2500usb_bbp_read(rt2x00dev, 17, &bbp);
1496 bbp -= 6;
1497
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001498 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_VGC, &word);
1499 if (word == 0xffff) {
1500 rt2x00_set_field16(&word, EEPROM_BBPTUNE_VGCUPPER, 0x40);
Ivo van Doorn6bb40dd2008-02-03 15:49:59 +01001501 rt2x00_set_field16(&word, EEPROM_BBPTUNE_VGCLOWER, bbp);
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001502 rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_VGC, word);
1503 EEPROM(rt2x00dev, "BBPtune vgc: 0x%04x\n", word);
Ivo van Doorn8d8acd42008-07-28 10:20:12 +02001504 } else {
1505 rt2x00_set_field16(&word, EEPROM_BBPTUNE_VGCLOWER, bbp);
1506 rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_VGC, word);
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001507 }
1508
1509 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R17, &word);
1510 if (word == 0xffff) {
1511 rt2x00_set_field16(&word, EEPROM_BBPTUNE_R17_LOW, 0x48);
1512 rt2x00_set_field16(&word, EEPROM_BBPTUNE_R17_HIGH, 0x41);
1513 rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_R17, word);
1514 EEPROM(rt2x00dev, "BBPtune r17: 0x%04x\n", word);
1515 }
1516
1517 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R24, &word);
1518 if (word == 0xffff) {
1519 rt2x00_set_field16(&word, EEPROM_BBPTUNE_R24_LOW, 0x40);
1520 rt2x00_set_field16(&word, EEPROM_BBPTUNE_R24_HIGH, 0x80);
1521 rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_R24, word);
1522 EEPROM(rt2x00dev, "BBPtune r24: 0x%04x\n", word);
1523 }
1524
1525 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R25, &word);
1526 if (word == 0xffff) {
1527 rt2x00_set_field16(&word, EEPROM_BBPTUNE_R25_LOW, 0x40);
1528 rt2x00_set_field16(&word, EEPROM_BBPTUNE_R25_HIGH, 0x50);
1529 rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_R25, word);
1530 EEPROM(rt2x00dev, "BBPtune r25: 0x%04x\n", word);
1531 }
1532
1533 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R61, &word);
1534 if (word == 0xffff) {
1535 rt2x00_set_field16(&word, EEPROM_BBPTUNE_R61_LOW, 0x60);
1536 rt2x00_set_field16(&word, EEPROM_BBPTUNE_R61_HIGH, 0x6d);
1537 rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_R61, word);
1538 EEPROM(rt2x00dev, "BBPtune r61: 0x%04x\n", word);
1539 }
1540
1541 return 0;
1542}
1543
1544static int rt2500usb_init_eeprom(struct rt2x00_dev *rt2x00dev)
1545{
1546 u16 reg;
1547 u16 value;
1548 u16 eeprom;
1549
1550 /*
1551 * Read EEPROM word for configuration.
1552 */
1553 rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &eeprom);
1554
1555 /*
1556 * Identify RF chipset.
1557 */
1558 value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RF_TYPE);
1559 rt2500usb_register_read(rt2x00dev, MAC_CSR0, &reg);
1560 rt2x00_set_chip(rt2x00dev, RT2570, value, reg);
1561
Ivo van Doorn755a9572007-11-12 15:02:22 +01001562 if (!rt2x00_check_rev(&rt2x00dev->chip, 0)) {
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001563 ERROR(rt2x00dev, "Invalid RT chipset detected.\n");
1564 return -ENODEV;
1565 }
1566
1567 if (!rt2x00_rf(&rt2x00dev->chip, RF2522) &&
1568 !rt2x00_rf(&rt2x00dev->chip, RF2523) &&
1569 !rt2x00_rf(&rt2x00dev->chip, RF2524) &&
1570 !rt2x00_rf(&rt2x00dev->chip, RF2525) &&
1571 !rt2x00_rf(&rt2x00dev->chip, RF2525E) &&
1572 !rt2x00_rf(&rt2x00dev->chip, RF5222)) {
1573 ERROR(rt2x00dev, "Invalid RF chipset detected.\n");
1574 return -ENODEV;
1575 }
1576
1577 /*
1578 * Identify default antenna configuration.
1579 */
Ivo van Doornaddc81bd2007-10-13 16:26:23 +02001580 rt2x00dev->default_ant.tx =
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001581 rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TX_DEFAULT);
Ivo van Doornaddc81bd2007-10-13 16:26:23 +02001582 rt2x00dev->default_ant.rx =
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001583 rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RX_DEFAULT);
1584
1585 /*
Ivo van Doornaddc81bd2007-10-13 16:26:23 +02001586 * When the eeprom indicates SW_DIVERSITY use HW_DIVERSITY instead.
1587 * I am not 100% sure about this, but the legacy drivers do not
1588 * indicate antenna swapping in software is required when
1589 * diversity is enabled.
1590 */
1591 if (rt2x00dev->default_ant.tx == ANTENNA_SW_DIVERSITY)
1592 rt2x00dev->default_ant.tx = ANTENNA_HW_DIVERSITY;
1593 if (rt2x00dev->default_ant.rx == ANTENNA_SW_DIVERSITY)
1594 rt2x00dev->default_ant.rx = ANTENNA_HW_DIVERSITY;
1595
1596 /*
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001597 * Store led mode, for correct led behaviour.
1598 */
Ivo van Doorn771fd562008-09-08 19:07:15 +02001599#ifdef CONFIG_RT2X00_LIB_LEDS
Ivo van Doorna9450b72008-02-03 15:53:40 +01001600 value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_LED_MODE);
1601
Ivo van Doorn475433b2008-06-03 20:30:01 +02001602 rt2500usb_init_led(rt2x00dev, &rt2x00dev->led_radio, LED_TYPE_RADIO);
Ivo van Doorn3d3e4512009-01-17 20:44:08 +01001603 if (value == LED_MODE_TXRX_ACTIVITY ||
1604 value == LED_MODE_DEFAULT ||
1605 value == LED_MODE_ASUS)
Ivo van Doorn475433b2008-06-03 20:30:01 +02001606 rt2500usb_init_led(rt2x00dev, &rt2x00dev->led_qual,
1607 LED_TYPE_ACTIVITY);
Ivo van Doorn771fd562008-09-08 19:07:15 +02001608#endif /* CONFIG_RT2X00_LIB_LEDS */
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001609
1610 /*
Ivo van Doorn7396faf2008-12-20 10:55:57 +01001611 * Detect if this device has an hardware controlled radio.
1612 */
1613#ifdef CONFIG_RT2X00_LIB_RFKILL
1614 if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_HARDWARE_RADIO))
1615 __set_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags);
1616#endif /* CONFIG_RT2X00_LIB_RFKILL */
1617
1618 /*
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001619 * Check if the BBP tuning should be disabled.
1620 */
1621 rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &eeprom);
1622 if (rt2x00_get_field16(eeprom, EEPROM_NIC_DYN_BBP_TUNE))
1623 __set_bit(CONFIG_DISABLE_LINK_TUNING, &rt2x00dev->flags);
1624
1625 /*
1626 * Read the RSSI <-> dBm offset information.
1627 */
1628 rt2x00_eeprom_read(rt2x00dev, EEPROM_CALIBRATE_OFFSET, &eeprom);
1629 rt2x00dev->rssi_offset =
1630 rt2x00_get_field16(eeprom, EEPROM_CALIBRATE_OFFSET_RSSI);
1631
1632 return 0;
1633}
1634
1635/*
1636 * RF value list for RF2522
1637 * Supports: 2.4 GHz
1638 */
1639static const struct rf_channel rf_vals_bg_2522[] = {
1640 { 1, 0x00002050, 0x000c1fda, 0x00000101, 0 },
1641 { 2, 0x00002050, 0x000c1fee, 0x00000101, 0 },
1642 { 3, 0x00002050, 0x000c2002, 0x00000101, 0 },
1643 { 4, 0x00002050, 0x000c2016, 0x00000101, 0 },
1644 { 5, 0x00002050, 0x000c202a, 0x00000101, 0 },
1645 { 6, 0x00002050, 0x000c203e, 0x00000101, 0 },
1646 { 7, 0x00002050, 0x000c2052, 0x00000101, 0 },
1647 { 8, 0x00002050, 0x000c2066, 0x00000101, 0 },
1648 { 9, 0x00002050, 0x000c207a, 0x00000101, 0 },
1649 { 10, 0x00002050, 0x000c208e, 0x00000101, 0 },
1650 { 11, 0x00002050, 0x000c20a2, 0x00000101, 0 },
1651 { 12, 0x00002050, 0x000c20b6, 0x00000101, 0 },
1652 { 13, 0x00002050, 0x000c20ca, 0x00000101, 0 },
1653 { 14, 0x00002050, 0x000c20fa, 0x00000101, 0 },
1654};
1655
1656/*
1657 * RF value list for RF2523
1658 * Supports: 2.4 GHz
1659 */
1660static const struct rf_channel rf_vals_bg_2523[] = {
1661 { 1, 0x00022010, 0x00000c9e, 0x000e0111, 0x00000a1b },
1662 { 2, 0x00022010, 0x00000ca2, 0x000e0111, 0x00000a1b },
1663 { 3, 0x00022010, 0x00000ca6, 0x000e0111, 0x00000a1b },
1664 { 4, 0x00022010, 0x00000caa, 0x000e0111, 0x00000a1b },
1665 { 5, 0x00022010, 0x00000cae, 0x000e0111, 0x00000a1b },
1666 { 6, 0x00022010, 0x00000cb2, 0x000e0111, 0x00000a1b },
1667 { 7, 0x00022010, 0x00000cb6, 0x000e0111, 0x00000a1b },
1668 { 8, 0x00022010, 0x00000cba, 0x000e0111, 0x00000a1b },
1669 { 9, 0x00022010, 0x00000cbe, 0x000e0111, 0x00000a1b },
1670 { 10, 0x00022010, 0x00000d02, 0x000e0111, 0x00000a1b },
1671 { 11, 0x00022010, 0x00000d06, 0x000e0111, 0x00000a1b },
1672 { 12, 0x00022010, 0x00000d0a, 0x000e0111, 0x00000a1b },
1673 { 13, 0x00022010, 0x00000d0e, 0x000e0111, 0x00000a1b },
1674 { 14, 0x00022010, 0x00000d1a, 0x000e0111, 0x00000a03 },
1675};
1676
1677/*
1678 * RF value list for RF2524
1679 * Supports: 2.4 GHz
1680 */
1681static const struct rf_channel rf_vals_bg_2524[] = {
1682 { 1, 0x00032020, 0x00000c9e, 0x00000101, 0x00000a1b },
1683 { 2, 0x00032020, 0x00000ca2, 0x00000101, 0x00000a1b },
1684 { 3, 0x00032020, 0x00000ca6, 0x00000101, 0x00000a1b },
1685 { 4, 0x00032020, 0x00000caa, 0x00000101, 0x00000a1b },
1686 { 5, 0x00032020, 0x00000cae, 0x00000101, 0x00000a1b },
1687 { 6, 0x00032020, 0x00000cb2, 0x00000101, 0x00000a1b },
1688 { 7, 0x00032020, 0x00000cb6, 0x00000101, 0x00000a1b },
1689 { 8, 0x00032020, 0x00000cba, 0x00000101, 0x00000a1b },
1690 { 9, 0x00032020, 0x00000cbe, 0x00000101, 0x00000a1b },
1691 { 10, 0x00032020, 0x00000d02, 0x00000101, 0x00000a1b },
1692 { 11, 0x00032020, 0x00000d06, 0x00000101, 0x00000a1b },
1693 { 12, 0x00032020, 0x00000d0a, 0x00000101, 0x00000a1b },
1694 { 13, 0x00032020, 0x00000d0e, 0x00000101, 0x00000a1b },
1695 { 14, 0x00032020, 0x00000d1a, 0x00000101, 0x00000a03 },
1696};
1697
1698/*
1699 * RF value list for RF2525
1700 * Supports: 2.4 GHz
1701 */
1702static const struct rf_channel rf_vals_bg_2525[] = {
1703 { 1, 0x00022020, 0x00080c9e, 0x00060111, 0x00000a1b },
1704 { 2, 0x00022020, 0x00080ca2, 0x00060111, 0x00000a1b },
1705 { 3, 0x00022020, 0x00080ca6, 0x00060111, 0x00000a1b },
1706 { 4, 0x00022020, 0x00080caa, 0x00060111, 0x00000a1b },
1707 { 5, 0x00022020, 0x00080cae, 0x00060111, 0x00000a1b },
1708 { 6, 0x00022020, 0x00080cb2, 0x00060111, 0x00000a1b },
1709 { 7, 0x00022020, 0x00080cb6, 0x00060111, 0x00000a1b },
1710 { 8, 0x00022020, 0x00080cba, 0x00060111, 0x00000a1b },
1711 { 9, 0x00022020, 0x00080cbe, 0x00060111, 0x00000a1b },
1712 { 10, 0x00022020, 0x00080d02, 0x00060111, 0x00000a1b },
1713 { 11, 0x00022020, 0x00080d06, 0x00060111, 0x00000a1b },
1714 { 12, 0x00022020, 0x00080d0a, 0x00060111, 0x00000a1b },
1715 { 13, 0x00022020, 0x00080d0e, 0x00060111, 0x00000a1b },
1716 { 14, 0x00022020, 0x00080d1a, 0x00060111, 0x00000a03 },
1717};
1718
1719/*
1720 * RF value list for RF2525e
1721 * Supports: 2.4 GHz
1722 */
1723static const struct rf_channel rf_vals_bg_2525e[] = {
1724 { 1, 0x00022010, 0x0000089a, 0x00060111, 0x00000e1b },
1725 { 2, 0x00022010, 0x0000089e, 0x00060111, 0x00000e07 },
1726 { 3, 0x00022010, 0x0000089e, 0x00060111, 0x00000e1b },
1727 { 4, 0x00022010, 0x000008a2, 0x00060111, 0x00000e07 },
1728 { 5, 0x00022010, 0x000008a2, 0x00060111, 0x00000e1b },
1729 { 6, 0x00022010, 0x000008a6, 0x00060111, 0x00000e07 },
1730 { 7, 0x00022010, 0x000008a6, 0x00060111, 0x00000e1b },
1731 { 8, 0x00022010, 0x000008aa, 0x00060111, 0x00000e07 },
1732 { 9, 0x00022010, 0x000008aa, 0x00060111, 0x00000e1b },
1733 { 10, 0x00022010, 0x000008ae, 0x00060111, 0x00000e07 },
1734 { 11, 0x00022010, 0x000008ae, 0x00060111, 0x00000e1b },
1735 { 12, 0x00022010, 0x000008b2, 0x00060111, 0x00000e07 },
1736 { 13, 0x00022010, 0x000008b2, 0x00060111, 0x00000e1b },
1737 { 14, 0x00022010, 0x000008b6, 0x00060111, 0x00000e23 },
1738};
1739
1740/*
1741 * RF value list for RF5222
1742 * Supports: 2.4 GHz & 5.2 GHz
1743 */
1744static const struct rf_channel rf_vals_5222[] = {
1745 { 1, 0x00022020, 0x00001136, 0x00000101, 0x00000a0b },
1746 { 2, 0x00022020, 0x0000113a, 0x00000101, 0x00000a0b },
1747 { 3, 0x00022020, 0x0000113e, 0x00000101, 0x00000a0b },
1748 { 4, 0x00022020, 0x00001182, 0x00000101, 0x00000a0b },
1749 { 5, 0x00022020, 0x00001186, 0x00000101, 0x00000a0b },
1750 { 6, 0x00022020, 0x0000118a, 0x00000101, 0x00000a0b },
1751 { 7, 0x00022020, 0x0000118e, 0x00000101, 0x00000a0b },
1752 { 8, 0x00022020, 0x00001192, 0x00000101, 0x00000a0b },
1753 { 9, 0x00022020, 0x00001196, 0x00000101, 0x00000a0b },
1754 { 10, 0x00022020, 0x0000119a, 0x00000101, 0x00000a0b },
1755 { 11, 0x00022020, 0x0000119e, 0x00000101, 0x00000a0b },
1756 { 12, 0x00022020, 0x000011a2, 0x00000101, 0x00000a0b },
1757 { 13, 0x00022020, 0x000011a6, 0x00000101, 0x00000a0b },
1758 { 14, 0x00022020, 0x000011ae, 0x00000101, 0x00000a1b },
1759
1760 /* 802.11 UNI / HyperLan 2 */
1761 { 36, 0x00022010, 0x00018896, 0x00000101, 0x00000a1f },
1762 { 40, 0x00022010, 0x0001889a, 0x00000101, 0x00000a1f },
1763 { 44, 0x00022010, 0x0001889e, 0x00000101, 0x00000a1f },
1764 { 48, 0x00022010, 0x000188a2, 0x00000101, 0x00000a1f },
1765 { 52, 0x00022010, 0x000188a6, 0x00000101, 0x00000a1f },
1766 { 66, 0x00022010, 0x000188aa, 0x00000101, 0x00000a1f },
1767 { 60, 0x00022010, 0x000188ae, 0x00000101, 0x00000a1f },
1768 { 64, 0x00022010, 0x000188b2, 0x00000101, 0x00000a1f },
1769
1770 /* 802.11 HyperLan 2 */
1771 { 100, 0x00022010, 0x00008802, 0x00000101, 0x00000a0f },
1772 { 104, 0x00022010, 0x00008806, 0x00000101, 0x00000a0f },
1773 { 108, 0x00022010, 0x0000880a, 0x00000101, 0x00000a0f },
1774 { 112, 0x00022010, 0x0000880e, 0x00000101, 0x00000a0f },
1775 { 116, 0x00022010, 0x00008812, 0x00000101, 0x00000a0f },
1776 { 120, 0x00022010, 0x00008816, 0x00000101, 0x00000a0f },
1777 { 124, 0x00022010, 0x0000881a, 0x00000101, 0x00000a0f },
1778 { 128, 0x00022010, 0x0000881e, 0x00000101, 0x00000a0f },
1779 { 132, 0x00022010, 0x00008822, 0x00000101, 0x00000a0f },
1780 { 136, 0x00022010, 0x00008826, 0x00000101, 0x00000a0f },
1781
1782 /* 802.11 UNII */
1783 { 140, 0x00022010, 0x0000882a, 0x00000101, 0x00000a0f },
1784 { 149, 0x00022020, 0x000090a6, 0x00000101, 0x00000a07 },
1785 { 153, 0x00022020, 0x000090ae, 0x00000101, 0x00000a07 },
1786 { 157, 0x00022020, 0x000090b6, 0x00000101, 0x00000a07 },
1787 { 161, 0x00022020, 0x000090be, 0x00000101, 0x00000a07 },
1788};
1789
Ivo van Doorn8c5e7a52008-08-04 16:38:47 +02001790static int rt2500usb_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001791{
1792 struct hw_mode_spec *spec = &rt2x00dev->spec;
Ivo van Doorn8c5e7a52008-08-04 16:38:47 +02001793 struct channel_info *info;
1794 char *tx_power;
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001795 unsigned int i;
1796
1797 /*
1798 * Initialize all hw fields.
1799 */
1800 rt2x00dev->hw->flags =
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001801 IEEE80211_HW_RX_INCLUDES_FCS |
Bruno Randolf566bfe52008-05-08 19:15:40 +02001802 IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
Johannes Berg4be8c382009-01-07 18:28:20 +01001803 IEEE80211_HW_SIGNAL_DBM |
1804 IEEE80211_HW_SUPPORTS_PS |
1805 IEEE80211_HW_PS_NULLFUNC_STACK;
Bruno Randolf566bfe52008-05-08 19:15:40 +02001806
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001807 rt2x00dev->hw->extra_tx_headroom = TXD_DESC_SIZE;
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001808
Gertjan van Wingerde14a3bf82008-06-16 19:55:43 +02001809 SET_IEEE80211_DEV(rt2x00dev->hw, rt2x00dev->dev);
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001810 SET_IEEE80211_PERM_ADDR(rt2x00dev->hw,
1811 rt2x00_eeprom_addr(rt2x00dev,
1812 EEPROM_MAC_ADDR_0));
1813
1814 /*
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001815 * Initialize hw_mode information.
1816 */
Ivo van Doorn31562e82008-02-17 17:35:05 +01001817 spec->supported_bands = SUPPORT_BAND_2GHZ;
1818 spec->supported_rates = SUPPORT_RATE_CCK | SUPPORT_RATE_OFDM;
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001819
1820 if (rt2x00_rf(&rt2x00dev->chip, RF2522)) {
1821 spec->num_channels = ARRAY_SIZE(rf_vals_bg_2522);
1822 spec->channels = rf_vals_bg_2522;
1823 } else if (rt2x00_rf(&rt2x00dev->chip, RF2523)) {
1824 spec->num_channels = ARRAY_SIZE(rf_vals_bg_2523);
1825 spec->channels = rf_vals_bg_2523;
1826 } else if (rt2x00_rf(&rt2x00dev->chip, RF2524)) {
1827 spec->num_channels = ARRAY_SIZE(rf_vals_bg_2524);
1828 spec->channels = rf_vals_bg_2524;
1829 } else if (rt2x00_rf(&rt2x00dev->chip, RF2525)) {
1830 spec->num_channels = ARRAY_SIZE(rf_vals_bg_2525);
1831 spec->channels = rf_vals_bg_2525;
1832 } else if (rt2x00_rf(&rt2x00dev->chip, RF2525E)) {
1833 spec->num_channels = ARRAY_SIZE(rf_vals_bg_2525e);
1834 spec->channels = rf_vals_bg_2525e;
1835 } else if (rt2x00_rf(&rt2x00dev->chip, RF5222)) {
Ivo van Doorn31562e82008-02-17 17:35:05 +01001836 spec->supported_bands |= SUPPORT_BAND_5GHZ;
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001837 spec->num_channels = ARRAY_SIZE(rf_vals_5222);
1838 spec->channels = rf_vals_5222;
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001839 }
Ivo van Doorn8c5e7a52008-08-04 16:38:47 +02001840
1841 /*
1842 * Create channel information array
1843 */
1844 info = kzalloc(spec->num_channels * sizeof(*info), GFP_KERNEL);
1845 if (!info)
1846 return -ENOMEM;
1847
1848 spec->channels_info = info;
1849
1850 tx_power = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_START);
1851 for (i = 0; i < 14; i++)
1852 info[i].tx_power1 = TXPOWER_FROM_DEV(tx_power[i]);
1853
1854 if (spec->num_channels > 14) {
1855 for (i = 14; i < spec->num_channels; i++)
1856 info[i].tx_power1 = DEFAULT_TXPOWER;
1857 }
1858
1859 return 0;
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001860}
1861
1862static int rt2500usb_probe_hw(struct rt2x00_dev *rt2x00dev)
1863{
1864 int retval;
1865
1866 /*
1867 * Allocate eeprom data.
1868 */
1869 retval = rt2500usb_validate_eeprom(rt2x00dev);
1870 if (retval)
1871 return retval;
1872
1873 retval = rt2500usb_init_eeprom(rt2x00dev);
1874 if (retval)
1875 return retval;
1876
1877 /*
1878 * Initialize hw specifications.
1879 */
Ivo van Doorn8c5e7a52008-08-04 16:38:47 +02001880 retval = rt2500usb_probe_hw_mode(rt2x00dev);
1881 if (retval)
1882 return retval;
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001883
1884 /*
Ivo van Doorn181d6902008-02-05 16:42:23 -05001885 * This device requires the atim queue
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001886 */
Ivo van Doorn181d6902008-02-05 16:42:23 -05001887 __set_bit(DRIVER_REQUIRE_ATIM_QUEUE, &rt2x00dev->flags);
1888 __set_bit(DRIVER_REQUIRE_BEACON_GUARD, &rt2x00dev->flags);
Ivo van Doorn3a643d22008-03-25 14:13:18 +01001889 __set_bit(DRIVER_REQUIRE_SCHEDULED, &rt2x00dev->flags);
Ivo van Doorndddfb472008-12-02 18:20:42 +01001890 if (!modparam_nohwcrypt) {
1891 __set_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags);
Ivo van Doorn3f787bd2008-12-20 10:56:36 +01001892 __set_bit(DRIVER_REQUIRE_COPY_IV, &rt2x00dev->flags);
Ivo van Doorndddfb472008-12-02 18:20:42 +01001893 }
Ivo van Doornd06193f2008-08-03 23:36:01 +02001894 __set_bit(CONFIG_DISABLE_LINK_TUNING, &rt2x00dev->flags);
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001895
1896 /*
1897 * Set the rssi offset.
1898 */
1899 rt2x00dev->rssi_offset = DEFAULT_RSSI_OFFSET;
1900
1901 return 0;
1902}
1903
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001904static const struct ieee80211_ops rt2500usb_mac80211_ops = {
1905 .tx = rt2x00mac_tx,
Johannes Berg4150c572007-09-17 01:29:23 -04001906 .start = rt2x00mac_start,
1907 .stop = rt2x00mac_stop,
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001908 .add_interface = rt2x00mac_add_interface,
1909 .remove_interface = rt2x00mac_remove_interface,
1910 .config = rt2x00mac_config,
1911 .config_interface = rt2x00mac_config_interface,
Ivo van Doorn3a643d22008-03-25 14:13:18 +01001912 .configure_filter = rt2x00mac_configure_filter,
Ivo van Doorndddfb472008-12-02 18:20:42 +01001913 .set_key = rt2x00mac_set_key,
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001914 .get_stats = rt2x00mac_get_stats,
Johannes Berg471b3ef2007-12-28 14:32:58 +01001915 .bss_info_changed = rt2x00mac_bss_info_changed,
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001916 .conf_tx = rt2x00mac_conf_tx,
1917 .get_tx_stats = rt2x00mac_get_tx_stats,
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001918};
1919
1920static const struct rt2x00lib_ops rt2500usb_rt2x00_ops = {
1921 .probe_hw = rt2500usb_probe_hw,
1922 .initialize = rt2x00usb_initialize,
1923 .uninitialize = rt2x00usb_uninitialize,
Ivo van Doorn798b7ad2008-11-08 15:25:33 +01001924 .clear_entry = rt2x00usb_clear_entry,
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001925 .set_device_state = rt2500usb_set_device_state,
Ivo van Doorn7396faf2008-12-20 10:55:57 +01001926 .rfkill_poll = rt2500usb_rfkill_poll,
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001927 .link_stats = rt2500usb_link_stats,
1928 .reset_tuner = rt2500usb_reset_tuner,
1929 .link_tuner = rt2500usb_link_tuner,
1930 .write_tx_desc = rt2500usb_write_tx_desc,
1931 .write_tx_data = rt2x00usb_write_tx_data,
Ivo van Doornbd88a782008-07-09 15:12:44 +02001932 .write_beacon = rt2500usb_write_beacon,
Ivo van Doorndd9fa2d2007-10-06 14:15:46 +02001933 .get_tx_data_len = rt2500usb_get_tx_data_len,
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001934 .kick_tx_queue = rt2500usb_kick_tx_queue,
Ivo van Doorna2c9b652009-01-28 00:32:33 +01001935 .kill_tx_queue = rt2x00usb_kill_tx_queue,
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001936 .fill_rxdone = rt2500usb_fill_rxdone,
Ivo van Doorndddfb472008-12-02 18:20:42 +01001937 .config_shared_key = rt2500usb_config_key,
1938 .config_pairwise_key = rt2500usb_config_key,
Ivo van Doorn3a643d22008-03-25 14:13:18 +01001939 .config_filter = rt2500usb_config_filter,
Ivo van Doorn6bb40dd2008-02-03 15:49:59 +01001940 .config_intf = rt2500usb_config_intf,
Ivo van Doorn72810372008-03-09 22:46:18 +01001941 .config_erp = rt2500usb_config_erp,
Ivo van Doorne4ea1c42008-10-29 17:17:57 +01001942 .config_ant = rt2500usb_config_ant,
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001943 .config = rt2500usb_config,
1944};
1945
Ivo van Doorn181d6902008-02-05 16:42:23 -05001946static const struct data_queue_desc rt2500usb_queue_rx = {
1947 .entry_num = RX_ENTRIES,
1948 .data_size = DATA_FRAME_SIZE,
1949 .desc_size = RXD_DESC_SIZE,
Ivo van Doornb8be63f2008-05-10 13:46:03 +02001950 .priv_size = sizeof(struct queue_entry_priv_usb),
Ivo van Doorn181d6902008-02-05 16:42:23 -05001951};
1952
1953static const struct data_queue_desc rt2500usb_queue_tx = {
1954 .entry_num = TX_ENTRIES,
1955 .data_size = DATA_FRAME_SIZE,
1956 .desc_size = TXD_DESC_SIZE,
Ivo van Doornb8be63f2008-05-10 13:46:03 +02001957 .priv_size = sizeof(struct queue_entry_priv_usb),
Ivo van Doorn181d6902008-02-05 16:42:23 -05001958};
1959
1960static const struct data_queue_desc rt2500usb_queue_bcn = {
1961 .entry_num = BEACON_ENTRIES,
1962 .data_size = MGMT_FRAME_SIZE,
1963 .desc_size = TXD_DESC_SIZE,
1964 .priv_size = sizeof(struct queue_entry_priv_usb_bcn),
1965};
1966
1967static const struct data_queue_desc rt2500usb_queue_atim = {
1968 .entry_num = ATIM_ENTRIES,
1969 .data_size = DATA_FRAME_SIZE,
1970 .desc_size = TXD_DESC_SIZE,
Ivo van Doornb8be63f2008-05-10 13:46:03 +02001971 .priv_size = sizeof(struct queue_entry_priv_usb),
Ivo van Doorn181d6902008-02-05 16:42:23 -05001972};
1973
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001974static const struct rt2x00_ops rt2500usb_ops = {
Ivo van Doorn23601572007-11-27 21:47:34 +01001975 .name = KBUILD_MODNAME,
Ivo van Doorn6bb40dd2008-02-03 15:49:59 +01001976 .max_sta_intf = 1,
1977 .max_ap_intf = 1,
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001978 .eeprom_size = EEPROM_SIZE,
1979 .rf_size = RF_SIZE,
Gertjan van Wingerde61448f82008-05-10 13:43:33 +02001980 .tx_queues = NUM_TX_QUEUES,
Ivo van Doorn181d6902008-02-05 16:42:23 -05001981 .rx = &rt2500usb_queue_rx,
1982 .tx = &rt2500usb_queue_tx,
1983 .bcn = &rt2500usb_queue_bcn,
1984 .atim = &rt2500usb_queue_atim,
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001985 .lib = &rt2500usb_rt2x00_ops,
1986 .hw = &rt2500usb_mac80211_ops,
1987#ifdef CONFIG_RT2X00_LIB_DEBUGFS
1988 .debugfs = &rt2500usb_rt2x00debug,
1989#endif /* CONFIG_RT2X00_LIB_DEBUGFS */
1990};
1991
1992/*
1993 * rt2500usb module information.
1994 */
1995static struct usb_device_id rt2500usb_device_table[] = {
1996 /* ASUS */
1997 { USB_DEVICE(0x0b05, 0x1706), USB_DEVICE_DATA(&rt2500usb_ops) },
1998 { USB_DEVICE(0x0b05, 0x1707), USB_DEVICE_DATA(&rt2500usb_ops) },
1999 /* Belkin */
2000 { USB_DEVICE(0x050d, 0x7050), USB_DEVICE_DATA(&rt2500usb_ops) },
2001 { USB_DEVICE(0x050d, 0x7051), USB_DEVICE_DATA(&rt2500usb_ops) },
2002 { USB_DEVICE(0x050d, 0x705a), USB_DEVICE_DATA(&rt2500usb_ops) },
2003 /* Cisco Systems */
2004 { USB_DEVICE(0x13b1, 0x000d), USB_DEVICE_DATA(&rt2500usb_ops) },
2005 { USB_DEVICE(0x13b1, 0x0011), USB_DEVICE_DATA(&rt2500usb_ops) },
2006 { USB_DEVICE(0x13b1, 0x001a), USB_DEVICE_DATA(&rt2500usb_ops) },
Xose Vazquez Perez9eb77ab2009-02-28 00:26:09 +01002007 /* CNet */
2008 { USB_DEVICE(0x1371, 0x9022), USB_DEVICE_DATA(&rt2500usb_ops) },
Ivo van Doorn95ea3622007-09-25 17:57:13 -07002009 /* Conceptronic */
2010 { USB_DEVICE(0x14b2, 0x3c02), USB_DEVICE_DATA(&rt2500usb_ops) },
2011 /* D-LINK */
2012 { USB_DEVICE(0x2001, 0x3c00), USB_DEVICE_DATA(&rt2500usb_ops) },
2013 /* Gigabyte */
2014 { USB_DEVICE(0x1044, 0x8001), USB_DEVICE_DATA(&rt2500usb_ops) },
2015 { USB_DEVICE(0x1044, 0x8007), USB_DEVICE_DATA(&rt2500usb_ops) },
2016 /* Hercules */
2017 { USB_DEVICE(0x06f8, 0xe000), USB_DEVICE_DATA(&rt2500usb_ops) },
2018 /* Melco */
Ivo van Doorndb433fe2008-02-10 11:21:57 +01002019 { USB_DEVICE(0x0411, 0x005e), USB_DEVICE_DATA(&rt2500usb_ops) },
Ivo van Doorn95ea3622007-09-25 17:57:13 -07002020 { USB_DEVICE(0x0411, 0x0066), USB_DEVICE_DATA(&rt2500usb_ops) },
2021 { USB_DEVICE(0x0411, 0x0067), USB_DEVICE_DATA(&rt2500usb_ops) },
2022 { USB_DEVICE(0x0411, 0x008b), USB_DEVICE_DATA(&rt2500usb_ops) },
2023 { USB_DEVICE(0x0411, 0x0097), USB_DEVICE_DATA(&rt2500usb_ops) },
Ivo van Doorn95ea3622007-09-25 17:57:13 -07002024 /* MSI */
2025 { USB_DEVICE(0x0db0, 0x6861), USB_DEVICE_DATA(&rt2500usb_ops) },
2026 { USB_DEVICE(0x0db0, 0x6865), USB_DEVICE_DATA(&rt2500usb_ops) },
2027 { USB_DEVICE(0x0db0, 0x6869), USB_DEVICE_DATA(&rt2500usb_ops) },
2028 /* Ralink */
2029 { USB_DEVICE(0x148f, 0x1706), USB_DEVICE_DATA(&rt2500usb_ops) },
2030 { USB_DEVICE(0x148f, 0x2570), USB_DEVICE_DATA(&rt2500usb_ops) },
2031 { USB_DEVICE(0x148f, 0x2573), USB_DEVICE_DATA(&rt2500usb_ops) },
2032 { USB_DEVICE(0x148f, 0x9020), USB_DEVICE_DATA(&rt2500usb_ops) },
Xose Vazquez Perez9eb77ab2009-02-28 00:26:09 +01002033 /* Sagem */
2034 { USB_DEVICE(0x079b, 0x004b), USB_DEVICE_DATA(&rt2500usb_ops) },
Ivo van Doorn95ea3622007-09-25 17:57:13 -07002035 /* Siemens */
2036 { USB_DEVICE(0x0681, 0x3c06), USB_DEVICE_DATA(&rt2500usb_ops) },
2037 /* SMC */
2038 { USB_DEVICE(0x0707, 0xee13), USB_DEVICE_DATA(&rt2500usb_ops) },
2039 /* Spairon */
2040 { USB_DEVICE(0x114b, 0x0110), USB_DEVICE_DATA(&rt2500usb_ops) },
Xose Vazquez Perez9eb77ab2009-02-28 00:26:09 +01002041 /* SURECOM */
2042 { USB_DEVICE(0x0769, 0x11f3), USB_DEVICE_DATA(&rt2500usb_ops) },
Ivo van Doorn95ea3622007-09-25 17:57:13 -07002043 /* Trust */
2044 { USB_DEVICE(0x0eb0, 0x9020), USB_DEVICE_DATA(&rt2500usb_ops) },
Xose Vazquez Perez9eb77ab2009-02-28 00:26:09 +01002045 /* VTech */
2046 { USB_DEVICE(0x0f88, 0x3012), USB_DEVICE_DATA(&rt2500usb_ops) },
Ivo van Doorn95ea3622007-09-25 17:57:13 -07002047 /* Zinwell */
2048 { USB_DEVICE(0x5a57, 0x0260), USB_DEVICE_DATA(&rt2500usb_ops) },
2049 { 0, }
2050};
2051
2052MODULE_AUTHOR(DRV_PROJECT);
2053MODULE_VERSION(DRV_VERSION);
2054MODULE_DESCRIPTION("Ralink RT2500 USB Wireless LAN driver.");
2055MODULE_SUPPORTED_DEVICE("Ralink RT2570 USB chipset based cards");
2056MODULE_DEVICE_TABLE(usb, rt2500usb_device_table);
2057MODULE_LICENSE("GPL");
2058
2059static struct usb_driver rt2500usb_driver = {
Ivo van Doorn23601572007-11-27 21:47:34 +01002060 .name = KBUILD_MODNAME,
Ivo van Doorn95ea3622007-09-25 17:57:13 -07002061 .id_table = rt2500usb_device_table,
2062 .probe = rt2x00usb_probe,
2063 .disconnect = rt2x00usb_disconnect,
2064 .suspend = rt2x00usb_suspend,
2065 .resume = rt2x00usb_resume,
2066};
2067
2068static int __init rt2500usb_init(void)
2069{
2070 return usb_register(&rt2500usb_driver);
2071}
2072
2073static void __exit rt2500usb_exit(void)
2074{
2075 usb_deregister(&rt2500usb_driver);
2076}
2077
2078module_init(rt2500usb_init);
2079module_exit(rt2500usb_exit);