blob: e4a1a858a2fdbde9bda69471a817bd349dce0417 [file] [log] [blame]
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +02001/*
2 Copyright (C) 2004 - 2009 rt2x00 SourceForge Project
3 <http://rt2x00.serialmonkey.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the
17 Free Software Foundation, Inc.,
18 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21/*
22 Module: rt2800pci
23 Abstract: rt2800pci device specific routines.
24 Supported chipsets: RT2800E & RT2800ED.
25 */
26
27#include <linux/crc-ccitt.h>
28#include <linux/delay.h>
29#include <linux/etherdevice.h>
30#include <linux/init.h>
31#include <linux/kernel.h>
32#include <linux/module.h>
33#include <linux/pci.h>
34#include <linux/platform_device.h>
35#include <linux/eeprom_93cx6.h>
36
37#include "rt2x00.h"
38#include "rt2x00pci.h"
39#include "rt2x00soc.h"
40#include "rt2800pci.h"
41
42#ifdef CONFIG_RT2800PCI_PCI_MODULE
43#define CONFIG_RT2800PCI_PCI
44#endif
45
46#ifdef CONFIG_RT2800PCI_WISOC_MODULE
47#define CONFIG_RT2800PCI_WISOC
48#endif
49
50/*
51 * Allow hardware encryption to be disabled.
52 */
53static int modparam_nohwcrypt = 1;
54module_param_named(nohwcrypt, modparam_nohwcrypt, bool, S_IRUGO);
55MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption.");
56
57/*
58 * Register access.
Bartlomiej Zolnierkiewicz8807bb82009-11-04 18:32:32 +010059 * All access to the CSR registers will go through the methods
60 * rt2x00pci_register_read and rt2x00pci_register_write.
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +020061 * BBP and RF register require indirect register access,
Bartlomiej Zolnierkiewicz8807bb82009-11-04 18:32:32 +010062 * and use the CSR registers BBPCSR and RFCSR to achieve this.
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +020063 * These indirect registers work with busy bits,
64 * and we will try maximal REGISTER_BUSY_COUNT times to access
65 * the register while taking a REGISTER_BUSY_DELAY us delay
66 * between each attampt. When the busy bit is still set at that time,
67 * the access attempt is considered to have failed,
68 * and we will print an error.
69 */
70#define WAIT_FOR_BBP(__dev, __reg) \
71 rt2x00pci_regbusy_read((__dev), BBP_CSR_CFG, BBP_CSR_CFG_BUSY, (__reg))
72#define WAIT_FOR_RFCSR(__dev, __reg) \
73 rt2x00pci_regbusy_read((__dev), RF_CSR_CFG, RF_CSR_CFG_BUSY, (__reg))
74#define WAIT_FOR_RF(__dev, __reg) \
75 rt2x00pci_regbusy_read((__dev), RF_CSR_CFG0, RF_CSR_CFG0_BUSY, (__reg))
76#define WAIT_FOR_MCU(__dev, __reg) \
77 rt2x00pci_regbusy_read((__dev), H2M_MAILBOX_CSR, \
78 H2M_MAILBOX_CSR_OWNER, (__reg))
79
80static void rt2800pci_bbp_write(struct rt2x00_dev *rt2x00dev,
81 const unsigned int word, const u8 value)
82{
83 u32 reg;
84
85 mutex_lock(&rt2x00dev->csr_mutex);
86
87 /*
88 * Wait until the BBP becomes available, afterwards we
89 * can safely write the new data into the register.
90 */
91 if (WAIT_FOR_BBP(rt2x00dev, &reg)) {
92 reg = 0;
93 rt2x00_set_field32(&reg, BBP_CSR_CFG_VALUE, value);
94 rt2x00_set_field32(&reg, BBP_CSR_CFG_REGNUM, word);
95 rt2x00_set_field32(&reg, BBP_CSR_CFG_BUSY, 1);
96 rt2x00_set_field32(&reg, BBP_CSR_CFG_READ_CONTROL, 0);
97 rt2x00_set_field32(&reg, BBP_CSR_CFG_BBP_RW_MODE, 1);
98
99 rt2x00pci_register_write(rt2x00dev, BBP_CSR_CFG, reg);
100 }
101
102 mutex_unlock(&rt2x00dev->csr_mutex);
103}
104
105static void rt2800pci_bbp_read(struct rt2x00_dev *rt2x00dev,
106 const unsigned int word, u8 *value)
107{
108 u32 reg;
109
110 mutex_lock(&rt2x00dev->csr_mutex);
111
112 /*
113 * Wait until the BBP becomes available, afterwards we
114 * can safely write the read request into the register.
115 * After the data has been written, we wait until hardware
116 * returns the correct value, if at any time the register
117 * doesn't become available in time, reg will be 0xffffffff
118 * which means we return 0xff to the caller.
119 */
120 if (WAIT_FOR_BBP(rt2x00dev, &reg)) {
121 reg = 0;
122 rt2x00_set_field32(&reg, BBP_CSR_CFG_REGNUM, word);
123 rt2x00_set_field32(&reg, BBP_CSR_CFG_BUSY, 1);
124 rt2x00_set_field32(&reg, BBP_CSR_CFG_READ_CONTROL, 1);
125 rt2x00_set_field32(&reg, BBP_CSR_CFG_BBP_RW_MODE, 1);
126
127 rt2x00pci_register_write(rt2x00dev, BBP_CSR_CFG, reg);
128
129 WAIT_FOR_BBP(rt2x00dev, &reg);
130 }
131
132 *value = rt2x00_get_field32(reg, BBP_CSR_CFG_VALUE);
133
134 mutex_unlock(&rt2x00dev->csr_mutex);
135}
136
137static void rt2800pci_rfcsr_write(struct rt2x00_dev *rt2x00dev,
138 const unsigned int word, const u8 value)
139{
140 u32 reg;
141
142 mutex_lock(&rt2x00dev->csr_mutex);
143
144 /*
145 * Wait until the RFCSR becomes available, afterwards we
146 * can safely write the new data into the register.
147 */
148 if (WAIT_FOR_RFCSR(rt2x00dev, &reg)) {
149 reg = 0;
150 rt2x00_set_field32(&reg, RF_CSR_CFG_DATA, value);
151 rt2x00_set_field32(&reg, RF_CSR_CFG_REGNUM, word);
152 rt2x00_set_field32(&reg, RF_CSR_CFG_WRITE, 1);
153 rt2x00_set_field32(&reg, RF_CSR_CFG_BUSY, 1);
154
155 rt2x00pci_register_write(rt2x00dev, RF_CSR_CFG, reg);
156 }
157
158 mutex_unlock(&rt2x00dev->csr_mutex);
159}
160
161static void rt2800pci_rfcsr_read(struct rt2x00_dev *rt2x00dev,
162 const unsigned int word, u8 *value)
163{
164 u32 reg;
165
166 mutex_lock(&rt2x00dev->csr_mutex);
167
168 /*
169 * Wait until the RFCSR becomes available, afterwards we
170 * can safely write the read request into the register.
171 * After the data has been written, we wait until hardware
172 * returns the correct value, if at any time the register
173 * doesn't become available in time, reg will be 0xffffffff
174 * which means we return 0xff to the caller.
175 */
176 if (WAIT_FOR_RFCSR(rt2x00dev, &reg)) {
177 reg = 0;
178 rt2x00_set_field32(&reg, RF_CSR_CFG_REGNUM, word);
179 rt2x00_set_field32(&reg, RF_CSR_CFG_WRITE, 0);
180 rt2x00_set_field32(&reg, RF_CSR_CFG_BUSY, 1);
181
182 rt2x00pci_register_write(rt2x00dev, RF_CSR_CFG, reg);
183
184 WAIT_FOR_RFCSR(rt2x00dev, &reg);
185 }
186
187 *value = rt2x00_get_field32(reg, RF_CSR_CFG_DATA);
188
189 mutex_unlock(&rt2x00dev->csr_mutex);
190}
191
192static void rt2800pci_rf_write(struct rt2x00_dev *rt2x00dev,
193 const unsigned int word, const u32 value)
194{
195 u32 reg;
196
197 mutex_lock(&rt2x00dev->csr_mutex);
198
199 /*
200 * Wait until the RF becomes available, afterwards we
201 * can safely write the new data into the register.
202 */
203 if (WAIT_FOR_RF(rt2x00dev, &reg)) {
204 reg = 0;
205 rt2x00_set_field32(&reg, RF_CSR_CFG0_REG_VALUE_BW, value);
206 rt2x00_set_field32(&reg, RF_CSR_CFG0_STANDBYMODE, 0);
207 rt2x00_set_field32(&reg, RF_CSR_CFG0_SEL, 0);
208 rt2x00_set_field32(&reg, RF_CSR_CFG0_BUSY, 1);
209
210 rt2x00pci_register_write(rt2x00dev, RF_CSR_CFG0, reg);
211 rt2x00_rf_write(rt2x00dev, word, value);
212 }
213
214 mutex_unlock(&rt2x00dev->csr_mutex);
215}
216
217static void rt2800pci_mcu_request(struct rt2x00_dev *rt2x00dev,
218 const u8 command, const u8 token,
219 const u8 arg0, const u8 arg1)
220{
221 u32 reg;
222
223 /*
224 * RT2880 and RT3052 don't support MCU requests.
225 */
226 if (rt2x00_rt(&rt2x00dev->chip, RT2880) ||
227 rt2x00_rt(&rt2x00dev->chip, RT3052))
228 return;
229
230 mutex_lock(&rt2x00dev->csr_mutex);
231
232 /*
233 * Wait until the MCU becomes available, afterwards we
234 * can safely write the new data into the register.
235 */
236 if (WAIT_FOR_MCU(rt2x00dev, &reg)) {
237 rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_OWNER, 1);
238 rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_CMD_TOKEN, token);
239 rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_ARG0, arg0);
240 rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_ARG1, arg1);
241 rt2x00pci_register_write(rt2x00dev, H2M_MAILBOX_CSR, reg);
242
243 reg = 0;
244 rt2x00_set_field32(&reg, HOST_CMD_CSR_HOST_COMMAND, command);
245 rt2x00pci_register_write(rt2x00dev, HOST_CMD_CSR, reg);
246 }
247
248 mutex_unlock(&rt2x00dev->csr_mutex);
249}
250
251static void rt2800pci_mcu_status(struct rt2x00_dev *rt2x00dev, const u8 token)
252{
253 unsigned int i;
254 u32 reg;
255
256 for (i = 0; i < 200; i++) {
257 rt2x00pci_register_read(rt2x00dev, H2M_MAILBOX_CID, &reg);
258
259 if ((rt2x00_get_field32(reg, H2M_MAILBOX_CID_CMD0) == token) ||
260 (rt2x00_get_field32(reg, H2M_MAILBOX_CID_CMD1) == token) ||
261 (rt2x00_get_field32(reg, H2M_MAILBOX_CID_CMD2) == token) ||
262 (rt2x00_get_field32(reg, H2M_MAILBOX_CID_CMD3) == token))
263 break;
264
265 udelay(REGISTER_BUSY_DELAY);
266 }
267
268 if (i == 200)
269 ERROR(rt2x00dev, "MCU request failed, no response from hardware\n");
270
271 rt2x00pci_register_write(rt2x00dev, H2M_MAILBOX_STATUS, ~0);
272 rt2x00pci_register_write(rt2x00dev, H2M_MAILBOX_CID, ~0);
273}
274
275#ifdef CONFIG_RT2800PCI_WISOC
276static void rt2800pci_read_eeprom_soc(struct rt2x00_dev *rt2x00dev)
277{
278 u32 *base_addr = (u32 *) KSEG1ADDR(0x1F040000); /* XXX for RT3052 */
279
280 memcpy_fromio(rt2x00dev->eeprom, base_addr, EEPROM_SIZE);
281}
282#else
283static inline void rt2800pci_read_eeprom_soc(struct rt2x00_dev *rt2x00dev)
284{
285}
286#endif /* CONFIG_RT2800PCI_WISOC */
287
288#ifdef CONFIG_RT2800PCI_PCI
289static void rt2800pci_eepromregister_read(struct eeprom_93cx6 *eeprom)
290{
291 struct rt2x00_dev *rt2x00dev = eeprom->data;
292 u32 reg;
293
294 rt2x00pci_register_read(rt2x00dev, E2PROM_CSR, &reg);
295
296 eeprom->reg_data_in = !!rt2x00_get_field32(reg, E2PROM_CSR_DATA_IN);
297 eeprom->reg_data_out = !!rt2x00_get_field32(reg, E2PROM_CSR_DATA_OUT);
298 eeprom->reg_data_clock =
299 !!rt2x00_get_field32(reg, E2PROM_CSR_DATA_CLOCK);
300 eeprom->reg_chip_select =
301 !!rt2x00_get_field32(reg, E2PROM_CSR_CHIP_SELECT);
302}
303
304static void rt2800pci_eepromregister_write(struct eeprom_93cx6 *eeprom)
305{
306 struct rt2x00_dev *rt2x00dev = eeprom->data;
307 u32 reg = 0;
308
309 rt2x00_set_field32(&reg, E2PROM_CSR_DATA_IN, !!eeprom->reg_data_in);
310 rt2x00_set_field32(&reg, E2PROM_CSR_DATA_OUT, !!eeprom->reg_data_out);
311 rt2x00_set_field32(&reg, E2PROM_CSR_DATA_CLOCK,
312 !!eeprom->reg_data_clock);
313 rt2x00_set_field32(&reg, E2PROM_CSR_CHIP_SELECT,
314 !!eeprom->reg_chip_select);
315
316 rt2x00pci_register_write(rt2x00dev, E2PROM_CSR, reg);
317}
318
319static void rt2800pci_read_eeprom_pci(struct rt2x00_dev *rt2x00dev)
320{
321 struct eeprom_93cx6 eeprom;
322 u32 reg;
323
324 rt2x00pci_register_read(rt2x00dev, E2PROM_CSR, &reg);
325
326 eeprom.data = rt2x00dev;
327 eeprom.register_read = rt2800pci_eepromregister_read;
328 eeprom.register_write = rt2800pci_eepromregister_write;
329 eeprom.width = !rt2x00_get_field32(reg, E2PROM_CSR_TYPE) ?
330 PCI_EEPROM_WIDTH_93C46 : PCI_EEPROM_WIDTH_93C66;
331 eeprom.reg_data_in = 0;
332 eeprom.reg_data_out = 0;
333 eeprom.reg_data_clock = 0;
334 eeprom.reg_chip_select = 0;
335
336 eeprom_93cx6_multiread(&eeprom, EEPROM_BASE, rt2x00dev->eeprom,
337 EEPROM_SIZE / sizeof(u16));
338}
339
340static void rt2800pci_efuse_read(struct rt2x00_dev *rt2x00dev,
341 unsigned int i)
342{
343 u32 reg;
344
345 rt2x00pci_register_read(rt2x00dev, EFUSE_CTRL, &reg);
346 rt2x00_set_field32(&reg, EFUSE_CTRL_ADDRESS_IN, i);
347 rt2x00_set_field32(&reg, EFUSE_CTRL_MODE, 0);
348 rt2x00_set_field32(&reg, EFUSE_CTRL_KICK, 1);
349 rt2x00pci_register_write(rt2x00dev, EFUSE_CTRL, reg);
350
351 /* Wait until the EEPROM has been loaded */
352 rt2x00pci_regbusy_read(rt2x00dev, EFUSE_CTRL, EFUSE_CTRL_KICK, &reg);
353
354 /* Apparently the data is read from end to start */
355 rt2x00pci_register_read(rt2x00dev, EFUSE_DATA3,
356 (u32 *)&rt2x00dev->eeprom[i]);
357 rt2x00pci_register_read(rt2x00dev, EFUSE_DATA2,
358 (u32 *)&rt2x00dev->eeprom[i + 2]);
359 rt2x00pci_register_read(rt2x00dev, EFUSE_DATA1,
360 (u32 *)&rt2x00dev->eeprom[i + 4]);
361 rt2x00pci_register_read(rt2x00dev, EFUSE_DATA0,
362 (u32 *)&rt2x00dev->eeprom[i + 6]);
363}
364
365static void rt2800pci_read_eeprom_efuse(struct rt2x00_dev *rt2x00dev)
366{
367 unsigned int i;
368
369 for (i = 0; i < EEPROM_SIZE / sizeof(u16); i += 8)
370 rt2800pci_efuse_read(rt2x00dev, i);
371}
372#else
373static inline void rt2800pci_read_eeprom_pci(struct rt2x00_dev *rt2x00dev)
374{
375}
376
377static inline void rt2800pci_read_eeprom_efuse(struct rt2x00_dev *rt2x00dev)
378{
379}
380#endif /* CONFIG_RT2800PCI_PCI */
381
382#ifdef CONFIG_RT2X00_LIB_DEBUGFS
383static const struct rt2x00debug rt2800pci_rt2x00debug = {
384 .owner = THIS_MODULE,
385 .csr = {
386 .read = rt2x00pci_register_read,
387 .write = rt2x00pci_register_write,
388 .flags = RT2X00DEBUGFS_OFFSET,
389 .word_base = CSR_REG_BASE,
390 .word_size = sizeof(u32),
391 .word_count = CSR_REG_SIZE / sizeof(u32),
392 },
393 .eeprom = {
394 .read = rt2x00_eeprom_read,
395 .write = rt2x00_eeprom_write,
396 .word_base = EEPROM_BASE,
397 .word_size = sizeof(u16),
398 .word_count = EEPROM_SIZE / sizeof(u16),
399 },
400 .bbp = {
401 .read = rt2800pci_bbp_read,
402 .write = rt2800pci_bbp_write,
403 .word_base = BBP_BASE,
404 .word_size = sizeof(u8),
405 .word_count = BBP_SIZE / sizeof(u8),
406 },
407 .rf = {
408 .read = rt2x00_rf_read,
409 .write = rt2800pci_rf_write,
410 .word_base = RF_BASE,
411 .word_size = sizeof(u32),
412 .word_count = RF_SIZE / sizeof(u32),
413 },
414};
415#endif /* CONFIG_RT2X00_LIB_DEBUGFS */
416
417static int rt2800pci_rfkill_poll(struct rt2x00_dev *rt2x00dev)
418{
419 u32 reg;
420
421 rt2x00pci_register_read(rt2x00dev, GPIO_CTRL_CFG, &reg);
422 return rt2x00_get_field32(reg, GPIO_CTRL_CFG_BIT2);
423}
424
425#ifdef CONFIG_RT2X00_LIB_LEDS
426static void rt2800pci_brightness_set(struct led_classdev *led_cdev,
427 enum led_brightness brightness)
428{
429 struct rt2x00_led *led =
430 container_of(led_cdev, struct rt2x00_led, led_dev);
431 unsigned int enabled = brightness != LED_OFF;
432 unsigned int bg_mode =
433 (enabled && led->rt2x00dev->curr_band == IEEE80211_BAND_2GHZ);
434 unsigned int polarity =
435 rt2x00_get_field16(led->rt2x00dev->led_mcu_reg,
436 EEPROM_FREQ_LED_POLARITY);
437 unsigned int ledmode =
438 rt2x00_get_field16(led->rt2x00dev->led_mcu_reg,
439 EEPROM_FREQ_LED_MODE);
440
441 if (led->type == LED_TYPE_RADIO) {
442 rt2800pci_mcu_request(led->rt2x00dev, MCU_LED, 0xff, ledmode,
443 enabled ? 0x20 : 0);
444 } else if (led->type == LED_TYPE_ASSOC) {
445 rt2800pci_mcu_request(led->rt2x00dev, MCU_LED, 0xff, ledmode,
446 enabled ? (bg_mode ? 0x60 : 0xa0) : 0x20);
447 } else if (led->type == LED_TYPE_QUALITY) {
448 /*
449 * The brightness is divided into 6 levels (0 - 5),
450 * The specs tell us the following levels:
451 * 0, 1 ,3, 7, 15, 31
452 * to determine the level in a simple way we can simply
453 * work with bitshifting:
454 * (1 << level) - 1
455 */
456 rt2800pci_mcu_request(led->rt2x00dev, MCU_LED_STRENGTH, 0xff,
457 (1 << brightness / (LED_FULL / 6)) - 1,
458 polarity);
459 }
460}
461
462static int rt2800pci_blink_set(struct led_classdev *led_cdev,
463 unsigned long *delay_on,
464 unsigned long *delay_off)
465{
466 struct rt2x00_led *led =
467 container_of(led_cdev, struct rt2x00_led, led_dev);
468 u32 reg;
469
470 rt2x00pci_register_read(led->rt2x00dev, LED_CFG, &reg);
471 rt2x00_set_field32(&reg, LED_CFG_ON_PERIOD, *delay_on);
472 rt2x00_set_field32(&reg, LED_CFG_OFF_PERIOD, *delay_off);
473 rt2x00_set_field32(&reg, LED_CFG_SLOW_BLINK_PERIOD, 3);
474 rt2x00_set_field32(&reg, LED_CFG_R_LED_MODE, 3);
475 rt2x00_set_field32(&reg, LED_CFG_G_LED_MODE, 12);
476 rt2x00_set_field32(&reg, LED_CFG_Y_LED_MODE, 3);
477 rt2x00_set_field32(&reg, LED_CFG_LED_POLAR, 1);
478 rt2x00pci_register_write(led->rt2x00dev, LED_CFG, reg);
479
480 return 0;
481}
482
483static void rt2800pci_init_led(struct rt2x00_dev *rt2x00dev,
484 struct rt2x00_led *led,
485 enum led_type type)
486{
487 led->rt2x00dev = rt2x00dev;
488 led->type = type;
489 led->led_dev.brightness_set = rt2800pci_brightness_set;
490 led->led_dev.blink_set = rt2800pci_blink_set;
491 led->flags = LED_INITIALIZED;
492}
493#endif /* CONFIG_RT2X00_LIB_LEDS */
494
495/*
496 * Configuration handlers.
497 */
498static void rt2800pci_config_wcid_attr(struct rt2x00_dev *rt2x00dev,
499 struct rt2x00lib_crypto *crypto,
500 struct ieee80211_key_conf *key)
501{
502 struct mac_wcid_entry wcid_entry;
503 struct mac_iveiv_entry iveiv_entry;
504 u32 offset;
505 u32 reg;
506
507 offset = MAC_WCID_ATTR_ENTRY(key->hw_key_idx);
508
509 rt2x00pci_register_read(rt2x00dev, offset, &reg);
510 rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_KEYTAB,
511 !!(key->flags & IEEE80211_KEY_FLAG_PAIRWISE));
512 rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_CIPHER,
513 (crypto->cmd == SET_KEY) * crypto->cipher);
514 rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_BSS_IDX,
515 (crypto->cmd == SET_KEY) * crypto->bssidx);
516 rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_RX_WIUDF, crypto->cipher);
517 rt2x00pci_register_write(rt2x00dev, offset, reg);
518
519 offset = MAC_IVEIV_ENTRY(key->hw_key_idx);
520
521 memset(&iveiv_entry, 0, sizeof(iveiv_entry));
522 if ((crypto->cipher == CIPHER_TKIP) ||
523 (crypto->cipher == CIPHER_TKIP_NO_MIC) ||
524 (crypto->cipher == CIPHER_AES))
525 iveiv_entry.iv[3] |= 0x20;
526 iveiv_entry.iv[3] |= key->keyidx << 6;
527 rt2x00pci_register_multiwrite(rt2x00dev, offset,
528 &iveiv_entry, sizeof(iveiv_entry));
529
530 offset = MAC_WCID_ENTRY(key->hw_key_idx);
531
532 memset(&wcid_entry, 0, sizeof(wcid_entry));
533 if (crypto->cmd == SET_KEY)
534 memcpy(&wcid_entry, crypto->address, ETH_ALEN);
535 rt2x00pci_register_multiwrite(rt2x00dev, offset,
536 &wcid_entry, sizeof(wcid_entry));
537}
538
539static int rt2800pci_config_shared_key(struct rt2x00_dev *rt2x00dev,
540 struct rt2x00lib_crypto *crypto,
541 struct ieee80211_key_conf *key)
542{
543 struct hw_key_entry key_entry;
544 struct rt2x00_field32 field;
545 u32 offset;
546 u32 reg;
547
548 if (crypto->cmd == SET_KEY) {
549 key->hw_key_idx = (4 * crypto->bssidx) + key->keyidx;
550
551 memcpy(key_entry.key, crypto->key,
552 sizeof(key_entry.key));
553 memcpy(key_entry.tx_mic, crypto->tx_mic,
554 sizeof(key_entry.tx_mic));
555 memcpy(key_entry.rx_mic, crypto->rx_mic,
556 sizeof(key_entry.rx_mic));
557
558 offset = SHARED_KEY_ENTRY(key->hw_key_idx);
559 rt2x00pci_register_multiwrite(rt2x00dev, offset,
560 &key_entry, sizeof(key_entry));
561 }
562
563 /*
564 * The cipher types are stored over multiple registers
565 * starting with SHARED_KEY_MODE_BASE each word will have
566 * 32 bits and contains the cipher types for 2 bssidx each.
567 * Using the correct defines correctly will cause overhead,
568 * so just calculate the correct offset.
569 */
570 field.bit_offset = 4 * (key->hw_key_idx % 8);
571 field.bit_mask = 0x7 << field.bit_offset;
572
573 offset = SHARED_KEY_MODE_ENTRY(key->hw_key_idx / 8);
574
575 rt2x00pci_register_read(rt2x00dev, offset, &reg);
576 rt2x00_set_field32(&reg, field,
577 (crypto->cmd == SET_KEY) * crypto->cipher);
578 rt2x00pci_register_write(rt2x00dev, offset, reg);
579
580 /*
581 * Update WCID information
582 */
583 rt2800pci_config_wcid_attr(rt2x00dev, crypto, key);
584
585 return 0;
586}
587
588static int rt2800pci_config_pairwise_key(struct rt2x00_dev *rt2x00dev,
589 struct rt2x00lib_crypto *crypto,
590 struct ieee80211_key_conf *key)
591{
592 struct hw_key_entry key_entry;
593 u32 offset;
594
595 if (crypto->cmd == SET_KEY) {
596 /*
597 * 1 pairwise key is possible per AID, this means that the AID
598 * equals our hw_key_idx. Make sure the WCID starts _after_ the
599 * last possible shared key entry.
600 */
601 if (crypto->aid > (256 - 32))
602 return -ENOSPC;
603
604 key->hw_key_idx = 32 + crypto->aid;
605
606
607 memcpy(key_entry.key, crypto->key,
608 sizeof(key_entry.key));
609 memcpy(key_entry.tx_mic, crypto->tx_mic,
610 sizeof(key_entry.tx_mic));
611 memcpy(key_entry.rx_mic, crypto->rx_mic,
612 sizeof(key_entry.rx_mic));
613
614 offset = PAIRWISE_KEY_ENTRY(key->hw_key_idx);
615 rt2x00pci_register_multiwrite(rt2x00dev, offset,
616 &key_entry, sizeof(key_entry));
617 }
618
619 /*
620 * Update WCID information
621 */
622 rt2800pci_config_wcid_attr(rt2x00dev, crypto, key);
623
624 return 0;
625}
626
627static void rt2800pci_config_filter(struct rt2x00_dev *rt2x00dev,
628 const unsigned int filter_flags)
629{
630 u32 reg;
631
632 /*
633 * Start configuration steps.
634 * Note that the version error will always be dropped
635 * and broadcast frames will always be accepted since
636 * there is no filter for it at this time.
637 */
638 rt2x00pci_register_read(rt2x00dev, RX_FILTER_CFG, &reg);
639 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CRC_ERROR,
640 !(filter_flags & FIF_FCSFAIL));
641 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_PHY_ERROR,
642 !(filter_flags & FIF_PLCPFAIL));
643 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_NOT_TO_ME,
644 !(filter_flags & FIF_PROMISC_IN_BSS));
645 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_NOT_MY_BSSD, 0);
646 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_VER_ERROR, 1);
647 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_MULTICAST,
648 !(filter_flags & FIF_ALLMULTI));
649 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_BROADCAST, 0);
650 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_DUPLICATE, 1);
651 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CF_END_ACK,
652 !(filter_flags & FIF_CONTROL));
653 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CF_END,
654 !(filter_flags & FIF_CONTROL));
655 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_ACK,
656 !(filter_flags & FIF_CONTROL));
657 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CTS,
658 !(filter_flags & FIF_CONTROL));
659 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_RTS,
660 !(filter_flags & FIF_CONTROL));
661 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_PSPOLL,
662 !(filter_flags & FIF_PSPOLL));
663 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_BA, 1);
664 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_BAR, 0);
665 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CNTL,
666 !(filter_flags & FIF_CONTROL));
667 rt2x00pci_register_write(rt2x00dev, RX_FILTER_CFG, reg);
668}
669
670static void rt2800pci_config_intf(struct rt2x00_dev *rt2x00dev,
671 struct rt2x00_intf *intf,
672 struct rt2x00intf_conf *conf,
673 const unsigned int flags)
674{
675 unsigned int beacon_base;
676 u32 reg;
677
678 if (flags & CONFIG_UPDATE_TYPE) {
679 /*
680 * Clear current synchronisation setup.
681 * For the Beacon base registers we only need to clear
682 * the first byte since that byte contains the VALID and OWNER
683 * bits which (when set to 0) will invalidate the entire beacon.
684 */
685 beacon_base = HW_BEACON_OFFSET(intf->beacon->entry_idx);
686 rt2x00pci_register_write(rt2x00dev, beacon_base, 0);
687
688 /*
689 * Enable synchronisation.
690 */
691 rt2x00pci_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
692 rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_TICKING, 1);
693 rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_SYNC, conf->sync);
694 rt2x00_set_field32(&reg, BCN_TIME_CFG_TBTT_ENABLE, 1);
695 rt2x00pci_register_write(rt2x00dev, BCN_TIME_CFG, reg);
696 }
697
698 if (flags & CONFIG_UPDATE_MAC) {
699 reg = le32_to_cpu(conf->mac[1]);
700 rt2x00_set_field32(&reg, MAC_ADDR_DW1_UNICAST_TO_ME_MASK, 0xff);
701 conf->mac[1] = cpu_to_le32(reg);
702
703 rt2x00pci_register_multiwrite(rt2x00dev, MAC_ADDR_DW0,
704 conf->mac, sizeof(conf->mac));
705 }
706
707 if (flags & CONFIG_UPDATE_BSSID) {
708 reg = le32_to_cpu(conf->bssid[1]);
709 rt2x00_set_field32(&reg, MAC_BSSID_DW1_BSS_ID_MASK, 0);
710 rt2x00_set_field32(&reg, MAC_BSSID_DW1_BSS_BCN_NUM, 0);
711 conf->bssid[1] = cpu_to_le32(reg);
712
713 rt2x00pci_register_multiwrite(rt2x00dev, MAC_BSSID_DW0,
714 conf->bssid, sizeof(conf->bssid));
715 }
716}
717
718static void rt2800pci_config_erp(struct rt2x00_dev *rt2x00dev,
719 struct rt2x00lib_erp *erp)
720{
721 u32 reg;
722
723 rt2x00pci_register_read(rt2x00dev, TX_TIMEOUT_CFG, &reg);
724 rt2x00_set_field32(&reg, TX_TIMEOUT_CFG_RX_ACK_TIMEOUT, 0x20);
725 rt2x00pci_register_write(rt2x00dev, TX_TIMEOUT_CFG, reg);
726
727 rt2x00pci_register_read(rt2x00dev, AUTO_RSP_CFG, &reg);
728 rt2x00_set_field32(&reg, AUTO_RSP_CFG_BAC_ACK_POLICY,
729 !!erp->short_preamble);
730 rt2x00_set_field32(&reg, AUTO_RSP_CFG_AR_PREAMBLE,
731 !!erp->short_preamble);
732 rt2x00pci_register_write(rt2x00dev, AUTO_RSP_CFG, reg);
733
734 rt2x00pci_register_read(rt2x00dev, OFDM_PROT_CFG, &reg);
735 rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_CTRL,
736 erp->cts_protection ? 2 : 0);
737 rt2x00pci_register_write(rt2x00dev, OFDM_PROT_CFG, reg);
738
739 rt2x00pci_register_write(rt2x00dev, LEGACY_BASIC_RATE,
740 erp->basic_rates);
741 rt2x00pci_register_write(rt2x00dev, HT_BASIC_RATE, 0x00008003);
742
743 rt2x00pci_register_read(rt2x00dev, BKOFF_SLOT_CFG, &reg);
744 rt2x00_set_field32(&reg, BKOFF_SLOT_CFG_SLOT_TIME, erp->slot_time);
745 rt2x00_set_field32(&reg, BKOFF_SLOT_CFG_CC_DELAY_TIME, 2);
746 rt2x00pci_register_write(rt2x00dev, BKOFF_SLOT_CFG, reg);
747
748 rt2x00pci_register_read(rt2x00dev, XIFS_TIME_CFG, &reg);
749 rt2x00_set_field32(&reg, XIFS_TIME_CFG_CCKM_SIFS_TIME, erp->sifs);
750 rt2x00_set_field32(&reg, XIFS_TIME_CFG_OFDM_SIFS_TIME, erp->sifs);
751 rt2x00_set_field32(&reg, XIFS_TIME_CFG_OFDM_XIFS_TIME, 4);
752 rt2x00_set_field32(&reg, XIFS_TIME_CFG_EIFS, erp->eifs);
753 rt2x00_set_field32(&reg, XIFS_TIME_CFG_BB_RXEND_ENABLE, 1);
754 rt2x00pci_register_write(rt2x00dev, XIFS_TIME_CFG, reg);
755
756 rt2x00pci_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
757 rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_INTERVAL,
758 erp->beacon_int * 16);
759 rt2x00pci_register_write(rt2x00dev, BCN_TIME_CFG, reg);
760}
761
762static void rt2800pci_config_ant(struct rt2x00_dev *rt2x00dev,
763 struct antenna_setup *ant)
764{
765 u8 r1;
766 u8 r3;
767
768 rt2800pci_bbp_read(rt2x00dev, 1, &r1);
769 rt2800pci_bbp_read(rt2x00dev, 3, &r3);
770
771 /*
772 * Configure the TX antenna.
773 */
774 switch ((int)ant->tx) {
775 case 1:
776 rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 0);
777 rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 0);
778 break;
779 case 2:
780 rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 2);
781 break;
782 case 3:
783 /* Do nothing */
784 break;
785 }
786
787 /*
788 * Configure the RX antenna.
789 */
790 switch ((int)ant->rx) {
791 case 1:
792 rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 0);
793 break;
794 case 2:
795 rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 1);
796 break;
797 case 3:
798 rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 2);
799 break;
800 }
801
802 rt2800pci_bbp_write(rt2x00dev, 3, r3);
803 rt2800pci_bbp_write(rt2x00dev, 1, r1);
804}
805
806static void rt2800pci_config_lna_gain(struct rt2x00_dev *rt2x00dev,
807 struct rt2x00lib_conf *libconf)
808{
809 u16 eeprom;
810 short lna_gain;
811
812 if (libconf->rf.channel <= 14) {
813 rt2x00_eeprom_read(rt2x00dev, EEPROM_LNA, &eeprom);
814 lna_gain = rt2x00_get_field16(eeprom, EEPROM_LNA_BG);
815 } else if (libconf->rf.channel <= 64) {
816 rt2x00_eeprom_read(rt2x00dev, EEPROM_LNA, &eeprom);
817 lna_gain = rt2x00_get_field16(eeprom, EEPROM_LNA_A0);
818 } else if (libconf->rf.channel <= 128) {
819 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_BG2, &eeprom);
820 lna_gain = rt2x00_get_field16(eeprom, EEPROM_RSSI_BG2_LNA_A1);
821 } else {
822 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_A2, &eeprom);
823 lna_gain = rt2x00_get_field16(eeprom, EEPROM_RSSI_A2_LNA_A2);
824 }
825
826 rt2x00dev->lna_gain = lna_gain;
827}
828
829static void rt2800pci_config_channel_rt2x(struct rt2x00_dev *rt2x00dev,
830 struct ieee80211_conf *conf,
831 struct rf_channel *rf,
832 struct channel_info *info)
833{
834 rt2x00_set_field32(&rf->rf4, RF4_FREQ_OFFSET, rt2x00dev->freq_offset);
835
836 if (rt2x00dev->default_ant.tx == 1)
837 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_TX1, 1);
838
839 if (rt2x00dev->default_ant.rx == 1) {
840 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX1, 1);
841 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX2, 1);
842 } else if (rt2x00dev->default_ant.rx == 2)
843 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX2, 1);
844
845 if (rf->channel > 14) {
846 /*
847 * When TX power is below 0, we should increase it by 7 to
848 * make it a positive value (Minumum value is -7).
849 * However this means that values between 0 and 7 have
850 * double meaning, and we should set a 7DBm boost flag.
851 */
852 rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_A_7DBM_BOOST,
853 (info->tx_power1 >= 0));
854
855 if (info->tx_power1 < 0)
856 info->tx_power1 += 7;
857
858 rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_A,
859 TXPOWER_A_TO_DEV(info->tx_power1));
860
861 rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_A_7DBM_BOOST,
862 (info->tx_power2 >= 0));
863
864 if (info->tx_power2 < 0)
865 info->tx_power2 += 7;
866
867 rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_A,
868 TXPOWER_A_TO_DEV(info->tx_power2));
869 } else {
870 rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_G,
871 TXPOWER_G_TO_DEV(info->tx_power1));
872 rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_G,
873 TXPOWER_G_TO_DEV(info->tx_power2));
874 }
875
876 rt2x00_set_field32(&rf->rf4, RF4_HT40, conf_is_ht40(conf));
877
878 rt2800pci_rf_write(rt2x00dev, 1, rf->rf1);
879 rt2800pci_rf_write(rt2x00dev, 2, rf->rf2);
880 rt2800pci_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
881 rt2800pci_rf_write(rt2x00dev, 4, rf->rf4);
882
883 udelay(200);
884
885 rt2800pci_rf_write(rt2x00dev, 1, rf->rf1);
886 rt2800pci_rf_write(rt2x00dev, 2, rf->rf2);
887 rt2800pci_rf_write(rt2x00dev, 3, rf->rf3 | 0x00000004);
888 rt2800pci_rf_write(rt2x00dev, 4, rf->rf4);
889
890 udelay(200);
891
892 rt2800pci_rf_write(rt2x00dev, 1, rf->rf1);
893 rt2800pci_rf_write(rt2x00dev, 2, rf->rf2);
894 rt2800pci_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
895 rt2800pci_rf_write(rt2x00dev, 4, rf->rf4);
896}
897
898static void rt2800pci_config_channel_rt3x(struct rt2x00_dev *rt2x00dev,
899 struct ieee80211_conf *conf,
900 struct rf_channel *rf,
901 struct channel_info *info)
902{
903 u8 rfcsr;
904
905 rt2800pci_rfcsr_write(rt2x00dev, 2, rf->rf1);
906 rt2800pci_rfcsr_write(rt2x00dev, 2, rf->rf3);
907
908 rt2800pci_rfcsr_read(rt2x00dev, 6, &rfcsr);
909 rt2x00_set_field8(&rfcsr, RFCSR6_R, rf->rf2);
910 rt2800pci_rfcsr_write(rt2x00dev, 6, rfcsr);
911
912 rt2800pci_rfcsr_read(rt2x00dev, 12, &rfcsr);
913 rt2x00_set_field8(&rfcsr, RFCSR12_TX_POWER,
914 TXPOWER_G_TO_DEV(info->tx_power1));
915 rt2800pci_rfcsr_write(rt2x00dev, 12, rfcsr);
916
917 rt2800pci_rfcsr_read(rt2x00dev, 23, &rfcsr);
918 rt2x00_set_field8(&rfcsr, RFCSR23_FREQ_OFFSET, rt2x00dev->freq_offset);
919 rt2800pci_rfcsr_write(rt2x00dev, 23, rfcsr);
920
921 rt2800pci_rfcsr_write(rt2x00dev, 24,
922 rt2x00dev->calibration[conf_is_ht40(conf)]);
923
924 rt2800pci_rfcsr_read(rt2x00dev, 23, &rfcsr);
925 rt2x00_set_field8(&rfcsr, RFCSR7_RF_TUNING, 1);
926 rt2800pci_rfcsr_write(rt2x00dev, 23, rfcsr);
927}
928
929static void rt2800pci_config_channel(struct rt2x00_dev *rt2x00dev,
930 struct ieee80211_conf *conf,
931 struct rf_channel *rf,
932 struct channel_info *info)
933{
934 u32 reg;
935 unsigned int tx_pin;
936 u8 bbp;
937
938 if (rt2x00_rev(&rt2x00dev->chip) != RT3070_VERSION)
939 rt2800pci_config_channel_rt2x(rt2x00dev, conf, rf, info);
940 else
941 rt2800pci_config_channel_rt3x(rt2x00dev, conf, rf, info);
942
943 /*
944 * Change BBP settings
945 */
946 rt2800pci_bbp_write(rt2x00dev, 62, 0x37 - rt2x00dev->lna_gain);
947 rt2800pci_bbp_write(rt2x00dev, 63, 0x37 - rt2x00dev->lna_gain);
948 rt2800pci_bbp_write(rt2x00dev, 64, 0x37 - rt2x00dev->lna_gain);
949 rt2800pci_bbp_write(rt2x00dev, 86, 0);
950
951 if (rf->channel <= 14) {
952 if (test_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags)) {
953 rt2800pci_bbp_write(rt2x00dev, 82, 0x62);
954 rt2800pci_bbp_write(rt2x00dev, 75, 0x46);
955 } else {
956 rt2800pci_bbp_write(rt2x00dev, 82, 0x84);
957 rt2800pci_bbp_write(rt2x00dev, 75, 0x50);
958 }
959 } else {
960 rt2800pci_bbp_write(rt2x00dev, 82, 0xf2);
961
962 if (test_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags))
963 rt2800pci_bbp_write(rt2x00dev, 75, 0x46);
964 else
965 rt2800pci_bbp_write(rt2x00dev, 75, 0x50);
966 }
967
968 rt2x00pci_register_read(rt2x00dev, TX_BAND_CFG, &reg);
969 rt2x00_set_field32(&reg, TX_BAND_CFG_HT40_PLUS, conf_is_ht40_plus(conf));
970 rt2x00_set_field32(&reg, TX_BAND_CFG_A, rf->channel > 14);
971 rt2x00_set_field32(&reg, TX_BAND_CFG_BG, rf->channel <= 14);
972 rt2x00pci_register_write(rt2x00dev, TX_BAND_CFG, reg);
973
974 tx_pin = 0;
975
976 /* Turn on unused PA or LNA when not using 1T or 1R */
977 if (rt2x00dev->default_ant.tx != 1) {
978 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A1_EN, 1);
979 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G1_EN, 1);
980 }
981
982 /* Turn on unused PA or LNA when not using 1T or 1R */
983 if (rt2x00dev->default_ant.rx != 1) {
984 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A1_EN, 1);
985 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G1_EN, 1);
986 }
987
988 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A0_EN, 1);
989 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G0_EN, 1);
990 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_RFTR_EN, 1);
991 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_TRSW_EN, 1);
992 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G0_EN, rf->channel <= 14);
993 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A0_EN, rf->channel > 14);
994
995 rt2x00pci_register_write(rt2x00dev, TX_PIN_CFG, tx_pin);
996
997 rt2800pci_bbp_read(rt2x00dev, 4, &bbp);
998 rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 2 * conf_is_ht40(conf));
999 rt2800pci_bbp_write(rt2x00dev, 4, bbp);
1000
1001 rt2800pci_bbp_read(rt2x00dev, 3, &bbp);
1002 rt2x00_set_field8(&bbp, BBP3_HT40_PLUS, conf_is_ht40_plus(conf));
1003 rt2800pci_bbp_write(rt2x00dev, 3, bbp);
1004
1005 if (rt2x00_rev(&rt2x00dev->chip) == RT2860C_VERSION) {
1006 if (conf_is_ht40(conf)) {
1007 rt2800pci_bbp_write(rt2x00dev, 69, 0x1a);
1008 rt2800pci_bbp_write(rt2x00dev, 70, 0x0a);
1009 rt2800pci_bbp_write(rt2x00dev, 73, 0x16);
1010 } else {
1011 rt2800pci_bbp_write(rt2x00dev, 69, 0x16);
1012 rt2800pci_bbp_write(rt2x00dev, 70, 0x08);
1013 rt2800pci_bbp_write(rt2x00dev, 73, 0x11);
1014 }
1015 }
1016
1017 msleep(1);
1018}
1019
1020static void rt2800pci_config_txpower(struct rt2x00_dev *rt2x00dev,
1021 const int txpower)
1022{
1023 u32 reg;
1024 u32 value = TXPOWER_G_TO_DEV(txpower);
1025 u8 r1;
1026
1027 rt2800pci_bbp_read(rt2x00dev, 1, &r1);
1028 rt2x00_set_field8(&reg, BBP1_TX_POWER, 0);
1029 rt2800pci_bbp_write(rt2x00dev, 1, r1);
1030
1031 rt2x00pci_register_read(rt2x00dev, TX_PWR_CFG_0, &reg);
1032 rt2x00_set_field32(&reg, TX_PWR_CFG_0_1MBS, value);
1033 rt2x00_set_field32(&reg, TX_PWR_CFG_0_2MBS, value);
1034 rt2x00_set_field32(&reg, TX_PWR_CFG_0_55MBS, value);
1035 rt2x00_set_field32(&reg, TX_PWR_CFG_0_11MBS, value);
1036 rt2x00_set_field32(&reg, TX_PWR_CFG_0_6MBS, value);
1037 rt2x00_set_field32(&reg, TX_PWR_CFG_0_9MBS, value);
1038 rt2x00_set_field32(&reg, TX_PWR_CFG_0_12MBS, value);
1039 rt2x00_set_field32(&reg, TX_PWR_CFG_0_18MBS, value);
1040 rt2x00pci_register_write(rt2x00dev, TX_PWR_CFG_0, reg);
1041
1042 rt2x00pci_register_read(rt2x00dev, TX_PWR_CFG_1, &reg);
1043 rt2x00_set_field32(&reg, TX_PWR_CFG_1_24MBS, value);
1044 rt2x00_set_field32(&reg, TX_PWR_CFG_1_36MBS, value);
1045 rt2x00_set_field32(&reg, TX_PWR_CFG_1_48MBS, value);
1046 rt2x00_set_field32(&reg, TX_PWR_CFG_1_54MBS, value);
1047 rt2x00_set_field32(&reg, TX_PWR_CFG_1_MCS0, value);
1048 rt2x00_set_field32(&reg, TX_PWR_CFG_1_MCS1, value);
1049 rt2x00_set_field32(&reg, TX_PWR_CFG_1_MCS2, value);
1050 rt2x00_set_field32(&reg, TX_PWR_CFG_1_MCS3, value);
1051 rt2x00pci_register_write(rt2x00dev, TX_PWR_CFG_1, reg);
1052
1053 rt2x00pci_register_read(rt2x00dev, TX_PWR_CFG_2, &reg);
1054 rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS4, value);
1055 rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS5, value);
1056 rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS6, value);
1057 rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS7, value);
1058 rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS8, value);
1059 rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS9, value);
1060 rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS10, value);
1061 rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS11, value);
1062 rt2x00pci_register_write(rt2x00dev, TX_PWR_CFG_2, reg);
1063
1064 rt2x00pci_register_read(rt2x00dev, TX_PWR_CFG_3, &reg);
1065 rt2x00_set_field32(&reg, TX_PWR_CFG_3_MCS12, value);
1066 rt2x00_set_field32(&reg, TX_PWR_CFG_3_MCS13, value);
1067 rt2x00_set_field32(&reg, TX_PWR_CFG_3_MCS14, value);
1068 rt2x00_set_field32(&reg, TX_PWR_CFG_3_MCS15, value);
1069 rt2x00_set_field32(&reg, TX_PWR_CFG_3_UKNOWN1, value);
1070 rt2x00_set_field32(&reg, TX_PWR_CFG_3_UKNOWN2, value);
1071 rt2x00_set_field32(&reg, TX_PWR_CFG_3_UKNOWN3, value);
1072 rt2x00_set_field32(&reg, TX_PWR_CFG_3_UKNOWN4, value);
1073 rt2x00pci_register_write(rt2x00dev, TX_PWR_CFG_3, reg);
1074
1075 rt2x00pci_register_read(rt2x00dev, TX_PWR_CFG_4, &reg);
1076 rt2x00_set_field32(&reg, TX_PWR_CFG_4_UKNOWN5, value);
1077 rt2x00_set_field32(&reg, TX_PWR_CFG_4_UKNOWN6, value);
1078 rt2x00_set_field32(&reg, TX_PWR_CFG_4_UKNOWN7, value);
1079 rt2x00_set_field32(&reg, TX_PWR_CFG_4_UKNOWN8, value);
1080 rt2x00pci_register_write(rt2x00dev, TX_PWR_CFG_4, reg);
1081}
1082
1083static void rt2800pci_config_retry_limit(struct rt2x00_dev *rt2x00dev,
1084 struct rt2x00lib_conf *libconf)
1085{
1086 u32 reg;
1087
1088 rt2x00pci_register_read(rt2x00dev, TX_RTY_CFG, &reg);
1089 rt2x00_set_field32(&reg, TX_RTY_CFG_SHORT_RTY_LIMIT,
1090 libconf->conf->short_frame_max_tx_count);
1091 rt2x00_set_field32(&reg, TX_RTY_CFG_LONG_RTY_LIMIT,
1092 libconf->conf->long_frame_max_tx_count);
1093 rt2x00_set_field32(&reg, TX_RTY_CFG_LONG_RTY_THRE, 2000);
1094 rt2x00_set_field32(&reg, TX_RTY_CFG_NON_AGG_RTY_MODE, 0);
1095 rt2x00_set_field32(&reg, TX_RTY_CFG_AGG_RTY_MODE, 0);
1096 rt2x00_set_field32(&reg, TX_RTY_CFG_TX_AUTO_FB_ENABLE, 1);
1097 rt2x00pci_register_write(rt2x00dev, TX_RTY_CFG, reg);
1098}
1099
1100static void rt2800pci_config_ps(struct rt2x00_dev *rt2x00dev,
1101 struct rt2x00lib_conf *libconf)
1102{
1103 enum dev_state state =
1104 (libconf->conf->flags & IEEE80211_CONF_PS) ?
1105 STATE_SLEEP : STATE_AWAKE;
1106 u32 reg;
1107
1108 if (state == STATE_SLEEP) {
1109 rt2x00pci_register_write(rt2x00dev, AUTOWAKEUP_CFG, 0);
1110
1111 rt2x00pci_register_read(rt2x00dev, AUTOWAKEUP_CFG, &reg);
1112 rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_AUTO_LEAD_TIME, 5);
1113 rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_TBCN_BEFORE_WAKE,
1114 libconf->conf->listen_interval - 1);
1115 rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_AUTOWAKE, 1);
1116 rt2x00pci_register_write(rt2x00dev, AUTOWAKEUP_CFG, reg);
1117
1118 rt2x00dev->ops->lib->set_device_state(rt2x00dev, state);
1119 } else {
1120 rt2x00dev->ops->lib->set_device_state(rt2x00dev, state);
1121
1122 rt2x00pci_register_read(rt2x00dev, AUTOWAKEUP_CFG, &reg);
1123 rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_AUTO_LEAD_TIME, 0);
1124 rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_TBCN_BEFORE_WAKE, 0);
1125 rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_AUTOWAKE, 0);
1126 rt2x00pci_register_write(rt2x00dev, AUTOWAKEUP_CFG, reg);
1127 }
1128}
1129
1130static void rt2800pci_config(struct rt2x00_dev *rt2x00dev,
1131 struct rt2x00lib_conf *libconf,
1132 const unsigned int flags)
1133{
1134 /* Always recalculate LNA gain before changing configuration */
1135 rt2800pci_config_lna_gain(rt2x00dev, libconf);
1136
1137 if (flags & IEEE80211_CONF_CHANGE_CHANNEL)
1138 rt2800pci_config_channel(rt2x00dev, libconf->conf,
1139 &libconf->rf, &libconf->channel);
1140 if (flags & IEEE80211_CONF_CHANGE_POWER)
1141 rt2800pci_config_txpower(rt2x00dev, libconf->conf->power_level);
1142 if (flags & IEEE80211_CONF_CHANGE_RETRY_LIMITS)
1143 rt2800pci_config_retry_limit(rt2x00dev, libconf);
1144 if (flags & IEEE80211_CONF_CHANGE_PS)
1145 rt2800pci_config_ps(rt2x00dev, libconf);
1146}
1147
1148/*
1149 * Link tuning
1150 */
1151static void rt2800pci_link_stats(struct rt2x00_dev *rt2x00dev,
1152 struct link_qual *qual)
1153{
1154 u32 reg;
1155
1156 /*
1157 * Update FCS error count from register.
1158 */
1159 rt2x00pci_register_read(rt2x00dev, RX_STA_CNT0, &reg);
1160 qual->rx_failed = rt2x00_get_field32(reg, RX_STA_CNT0_CRC_ERR);
1161}
1162
1163static u8 rt2800pci_get_default_vgc(struct rt2x00_dev *rt2x00dev)
1164{
1165 if (rt2x00dev->curr_band == IEEE80211_BAND_2GHZ)
1166 return 0x2e + rt2x00dev->lna_gain;
1167
1168 if (!test_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags))
1169 return 0x32 + (rt2x00dev->lna_gain * 5) / 3;
1170 else
1171 return 0x3a + (rt2x00dev->lna_gain * 5) / 3;
1172}
1173
1174static inline void rt2800pci_set_vgc(struct rt2x00_dev *rt2x00dev,
1175 struct link_qual *qual, u8 vgc_level)
1176{
1177 if (qual->vgc_level != vgc_level) {
1178 rt2800pci_bbp_write(rt2x00dev, 66, vgc_level);
1179 qual->vgc_level = vgc_level;
1180 qual->vgc_level_reg = vgc_level;
1181 }
1182}
1183
1184static void rt2800pci_reset_tuner(struct rt2x00_dev *rt2x00dev,
1185 struct link_qual *qual)
1186{
1187 rt2800pci_set_vgc(rt2x00dev, qual,
1188 rt2800pci_get_default_vgc(rt2x00dev));
1189}
1190
1191static void rt2800pci_link_tuner(struct rt2x00_dev *rt2x00dev,
1192 struct link_qual *qual, const u32 count)
1193{
1194 if (rt2x00_rev(&rt2x00dev->chip) == RT2860C_VERSION)
1195 return;
1196
1197 /*
1198 * When RSSI is better then -80 increase VGC level with 0x10
1199 */
1200 rt2800pci_set_vgc(rt2x00dev, qual,
1201 rt2800pci_get_default_vgc(rt2x00dev) +
1202 ((qual->rssi > -80) * 0x10));
1203}
1204
1205/*
1206 * Firmware functions
1207 */
1208static char *rt2800pci_get_firmware_name(struct rt2x00_dev *rt2x00dev)
1209{
1210 return FIRMWARE_RT2860;
1211}
1212
1213static int rt2800pci_check_firmware(struct rt2x00_dev *rt2x00dev,
1214 const u8 *data, const size_t len)
1215{
1216 u16 fw_crc;
1217 u16 crc;
1218
1219 /*
1220 * Only support 8kb firmware files.
1221 */
1222 if (len != 8192)
1223 return FW_BAD_LENGTH;
1224
1225 /*
1226 * The last 2 bytes in the firmware array are the crc checksum itself,
1227 * this means that we should never pass those 2 bytes to the crc
1228 * algorithm.
1229 */
1230 fw_crc = (data[len - 2] << 8 | data[len - 1]);
1231
1232 /*
1233 * Use the crc ccitt algorithm.
1234 * This will return the same value as the legacy driver which
1235 * used bit ordering reversion on the both the firmware bytes
1236 * before input input as well as on the final output.
1237 * Obviously using crc ccitt directly is much more efficient.
1238 */
1239 crc = crc_ccitt(~0, data, len - 2);
1240
1241 /*
1242 * There is a small difference between the crc-itu-t + bitrev and
1243 * the crc-ccitt crc calculation. In the latter method the 2 bytes
1244 * will be swapped, use swab16 to convert the crc to the correct
1245 * value.
1246 */
1247 crc = swab16(crc);
1248
1249 return (fw_crc == crc) ? FW_OK : FW_BAD_CRC;
1250}
1251
1252static int rt2800pci_load_firmware(struct rt2x00_dev *rt2x00dev,
1253 const u8 *data, const size_t len)
1254{
1255 unsigned int i;
1256 u32 reg;
1257
1258 /*
1259 * Wait for stable hardware.
1260 */
1261 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
1262 rt2x00pci_register_read(rt2x00dev, MAC_CSR0, &reg);
1263 if (reg && reg != ~0)
1264 break;
1265 msleep(1);
1266 }
1267
1268 if (i == REGISTER_BUSY_COUNT) {
1269 ERROR(rt2x00dev, "Unstable hardware.\n");
1270 return -EBUSY;
1271 }
1272
1273 rt2x00pci_register_write(rt2x00dev, PWR_PIN_CFG, 0x00000002);
1274 rt2x00pci_register_write(rt2x00dev, AUTOWAKEUP_CFG, 0x00000000);
1275
1276 /*
1277 * Disable DMA, will be reenabled later when enabling
1278 * the radio.
1279 */
1280 rt2x00pci_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
1281 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0);
1282 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_DMA_BUSY, 0);
1283 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0);
1284 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_RX_DMA_BUSY, 0);
1285 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1);
1286 rt2x00pci_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
1287
1288 /*
1289 * enable Host program ram write selection
1290 */
1291 reg = 0;
1292 rt2x00_set_field32(&reg, PBF_SYS_CTRL_HOST_RAM_WRITE, 1);
1293 rt2x00pci_register_write(rt2x00dev, PBF_SYS_CTRL, reg);
1294
1295 /*
1296 * Write firmware to device.
1297 */
1298 rt2x00pci_register_multiwrite(rt2x00dev, FIRMWARE_IMAGE_BASE,
1299 data, len);
1300
1301 rt2x00pci_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00000);
1302 rt2x00pci_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00001);
1303
1304 /*
1305 * Wait for device to stabilize.
1306 */
1307 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
1308 rt2x00pci_register_read(rt2x00dev, PBF_SYS_CTRL, &reg);
1309 if (rt2x00_get_field32(reg, PBF_SYS_CTRL_READY))
1310 break;
1311 msleep(1);
1312 }
1313
1314 if (i == REGISTER_BUSY_COUNT) {
1315 ERROR(rt2x00dev, "PBF system register not ready.\n");
1316 return -EBUSY;
1317 }
1318
1319 /*
1320 * Disable interrupts
1321 */
1322 rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_RADIO_IRQ_OFF);
1323
1324 /*
1325 * Initialize BBP R/W access agent
1326 */
1327 rt2x00pci_register_write(rt2x00dev, H2M_BBP_AGENT, 0);
1328 rt2x00pci_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
1329
1330 return 0;
1331}
1332
1333/*
1334 * Initialization functions.
1335 */
1336static bool rt2800pci_get_entry_state(struct queue_entry *entry)
1337{
1338 struct queue_entry_priv_pci *entry_priv = entry->priv_data;
1339 u32 word;
1340
1341 if (entry->queue->qid == QID_RX) {
1342 rt2x00_desc_read(entry_priv->desc, 1, &word);
1343
1344 return (!rt2x00_get_field32(word, RXD_W1_DMA_DONE));
1345 } else {
1346 rt2x00_desc_read(entry_priv->desc, 1, &word);
1347
1348 return (!rt2x00_get_field32(word, TXD_W1_DMA_DONE));
1349 }
1350}
1351
1352static void rt2800pci_clear_entry(struct queue_entry *entry)
1353{
1354 struct queue_entry_priv_pci *entry_priv = entry->priv_data;
1355 struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
1356 u32 word;
1357
1358 if (entry->queue->qid == QID_RX) {
1359 rt2x00_desc_read(entry_priv->desc, 0, &word);
1360 rt2x00_set_field32(&word, RXD_W0_SDP0, skbdesc->skb_dma);
1361 rt2x00_desc_write(entry_priv->desc, 0, word);
1362
1363 rt2x00_desc_read(entry_priv->desc, 1, &word);
1364 rt2x00_set_field32(&word, RXD_W1_DMA_DONE, 0);
1365 rt2x00_desc_write(entry_priv->desc, 1, word);
1366 } else {
1367 rt2x00_desc_read(entry_priv->desc, 1, &word);
1368 rt2x00_set_field32(&word, TXD_W1_DMA_DONE, 1);
1369 rt2x00_desc_write(entry_priv->desc, 1, word);
1370 }
1371}
1372
1373static int rt2800pci_init_queues(struct rt2x00_dev *rt2x00dev)
1374{
1375 struct queue_entry_priv_pci *entry_priv;
1376 u32 reg;
1377
1378 rt2x00pci_register_read(rt2x00dev, WPDMA_RST_IDX, &reg);
1379 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX0, 1);
1380 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX1, 1);
1381 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX2, 1);
1382 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX3, 1);
1383 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX4, 1);
1384 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX5, 1);
1385 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DRX_IDX0, 1);
1386 rt2x00pci_register_write(rt2x00dev, WPDMA_RST_IDX, reg);
1387
1388 rt2x00pci_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00000e1f);
1389 rt2x00pci_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00000e00);
1390
1391 /*
1392 * Initialize registers.
1393 */
1394 entry_priv = rt2x00dev->tx[0].entries[0].priv_data;
1395 rt2x00pci_register_write(rt2x00dev, TX_BASE_PTR0, entry_priv->desc_dma);
1396 rt2x00pci_register_write(rt2x00dev, TX_MAX_CNT0, rt2x00dev->tx[0].limit);
1397 rt2x00pci_register_write(rt2x00dev, TX_CTX_IDX0, 0);
1398 rt2x00pci_register_write(rt2x00dev, TX_DTX_IDX0, 0);
1399
1400 entry_priv = rt2x00dev->tx[1].entries[0].priv_data;
1401 rt2x00pci_register_write(rt2x00dev, TX_BASE_PTR1, entry_priv->desc_dma);
1402 rt2x00pci_register_write(rt2x00dev, TX_MAX_CNT1, rt2x00dev->tx[1].limit);
1403 rt2x00pci_register_write(rt2x00dev, TX_CTX_IDX1, 0);
1404 rt2x00pci_register_write(rt2x00dev, TX_DTX_IDX1, 0);
1405
1406 entry_priv = rt2x00dev->tx[2].entries[0].priv_data;
1407 rt2x00pci_register_write(rt2x00dev, TX_BASE_PTR2, entry_priv->desc_dma);
1408 rt2x00pci_register_write(rt2x00dev, TX_MAX_CNT2, rt2x00dev->tx[2].limit);
1409 rt2x00pci_register_write(rt2x00dev, TX_CTX_IDX2, 0);
1410 rt2x00pci_register_write(rt2x00dev, TX_DTX_IDX2, 0);
1411
1412 entry_priv = rt2x00dev->tx[3].entries[0].priv_data;
1413 rt2x00pci_register_write(rt2x00dev, TX_BASE_PTR3, entry_priv->desc_dma);
1414 rt2x00pci_register_write(rt2x00dev, TX_MAX_CNT3, rt2x00dev->tx[3].limit);
1415 rt2x00pci_register_write(rt2x00dev, TX_CTX_IDX3, 0);
1416 rt2x00pci_register_write(rt2x00dev, TX_DTX_IDX3, 0);
1417
1418 entry_priv = rt2x00dev->rx->entries[0].priv_data;
1419 rt2x00pci_register_write(rt2x00dev, RX_BASE_PTR, entry_priv->desc_dma);
1420 rt2x00pci_register_write(rt2x00dev, RX_MAX_CNT, rt2x00dev->rx[0].limit);
1421 rt2x00pci_register_write(rt2x00dev, RX_CRX_IDX, rt2x00dev->rx[0].limit - 1);
1422 rt2x00pci_register_write(rt2x00dev, RX_DRX_IDX, 0);
1423
1424 /*
1425 * Enable global DMA configuration
1426 */
1427 rt2x00pci_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
1428 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0);
1429 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0);
1430 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1);
1431 rt2x00pci_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
1432
1433 rt2x00pci_register_write(rt2x00dev, DELAY_INT_CFG, 0);
1434
1435 return 0;
1436}
1437
1438static int rt2800pci_init_registers(struct rt2x00_dev *rt2x00dev)
1439{
1440 u32 reg;
1441 unsigned int i;
1442
1443 rt2x00pci_register_write(rt2x00dev, PWR_PIN_CFG, 0x00000003);
1444
1445 rt2x00pci_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
1446 rt2x00_set_field32(&reg, MAC_SYS_CTRL_RESET_CSR, 1);
1447 rt2x00_set_field32(&reg, MAC_SYS_CTRL_RESET_BBP, 1);
1448 rt2x00pci_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
1449
1450 rt2x00pci_register_write(rt2x00dev, MAC_SYS_CTRL, 0x00000000);
1451
1452 rt2x00pci_register_read(rt2x00dev, BCN_OFFSET0, &reg);
1453 rt2x00_set_field32(&reg, BCN_OFFSET0_BCN0, 0xe0); /* 0x3800 */
1454 rt2x00_set_field32(&reg, BCN_OFFSET0_BCN1, 0xe8); /* 0x3a00 */
1455 rt2x00_set_field32(&reg, BCN_OFFSET0_BCN2, 0xf0); /* 0x3c00 */
1456 rt2x00_set_field32(&reg, BCN_OFFSET0_BCN3, 0xf8); /* 0x3e00 */
1457 rt2x00pci_register_write(rt2x00dev, BCN_OFFSET0, reg);
1458
1459 rt2x00pci_register_read(rt2x00dev, BCN_OFFSET1, &reg);
1460 rt2x00_set_field32(&reg, BCN_OFFSET1_BCN4, 0xc8); /* 0x3200 */
1461 rt2x00_set_field32(&reg, BCN_OFFSET1_BCN5, 0xd0); /* 0x3400 */
1462 rt2x00_set_field32(&reg, BCN_OFFSET1_BCN6, 0x77); /* 0x1dc0 */
1463 rt2x00_set_field32(&reg, BCN_OFFSET1_BCN7, 0x6f); /* 0x1bc0 */
1464 rt2x00pci_register_write(rt2x00dev, BCN_OFFSET1, reg);
1465
1466 rt2x00pci_register_write(rt2x00dev, LEGACY_BASIC_RATE, 0x0000013f);
1467 rt2x00pci_register_write(rt2x00dev, HT_BASIC_RATE, 0x00008003);
1468
1469 rt2x00pci_register_write(rt2x00dev, MAC_SYS_CTRL, 0x00000000);
1470
1471 rt2x00pci_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
1472 rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_INTERVAL, 0);
1473 rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_TICKING, 0);
1474 rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_SYNC, 0);
1475 rt2x00_set_field32(&reg, BCN_TIME_CFG_TBTT_ENABLE, 0);
1476 rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 0);
1477 rt2x00_set_field32(&reg, BCN_TIME_CFG_TX_TIME_COMPENSATE, 0);
1478 rt2x00pci_register_write(rt2x00dev, BCN_TIME_CFG, reg);
1479
1480 rt2x00pci_register_write(rt2x00dev, TX_SW_CFG0, 0x00000000);
1481 rt2x00pci_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606);
1482
1483 rt2x00pci_register_read(rt2x00dev, TX_LINK_CFG, &reg);
1484 rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_MFB_LIFETIME, 32);
1485 rt2x00_set_field32(&reg, TX_LINK_CFG_MFB_ENABLE, 0);
1486 rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_UMFS_ENABLE, 0);
1487 rt2x00_set_field32(&reg, TX_LINK_CFG_TX_MRQ_EN, 0);
1488 rt2x00_set_field32(&reg, TX_LINK_CFG_TX_RDG_EN, 0);
1489 rt2x00_set_field32(&reg, TX_LINK_CFG_TX_CF_ACK_EN, 1);
1490 rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_MFB, 0);
1491 rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_MFS, 0);
1492 rt2x00pci_register_write(rt2x00dev, TX_LINK_CFG, reg);
1493
1494 rt2x00pci_register_read(rt2x00dev, TX_TIMEOUT_CFG, &reg);
1495 rt2x00_set_field32(&reg, TX_TIMEOUT_CFG_MPDU_LIFETIME, 9);
1496 rt2x00_set_field32(&reg, TX_TIMEOUT_CFG_TX_OP_TIMEOUT, 10);
1497 rt2x00pci_register_write(rt2x00dev, TX_TIMEOUT_CFG, reg);
1498
1499 rt2x00pci_register_read(rt2x00dev, MAX_LEN_CFG, &reg);
1500 rt2x00_set_field32(&reg, MAX_LEN_CFG_MAX_MPDU, AGGREGATION_SIZE);
1501 if (rt2x00_rev(&rt2x00dev->chip) >= RT2880E_VERSION &&
1502 rt2x00_rev(&rt2x00dev->chip) < RT3070_VERSION)
1503 rt2x00_set_field32(&reg, MAX_LEN_CFG_MAX_PSDU, 2);
1504 else
1505 rt2x00_set_field32(&reg, MAX_LEN_CFG_MAX_PSDU, 1);
1506 rt2x00_set_field32(&reg, MAX_LEN_CFG_MIN_PSDU, 0);
1507 rt2x00_set_field32(&reg, MAX_LEN_CFG_MIN_MPDU, 0);
1508 rt2x00pci_register_write(rt2x00dev, MAX_LEN_CFG, reg);
1509
1510 rt2x00pci_register_write(rt2x00dev, PBF_MAX_PCNT, 0x1f3fbf9f);
1511
1512 rt2x00pci_register_read(rt2x00dev, AUTO_RSP_CFG, &reg);
1513 rt2x00_set_field32(&reg, AUTO_RSP_CFG_AUTORESPONDER, 1);
1514 rt2x00_set_field32(&reg, AUTO_RSP_CFG_CTS_40_MMODE, 0);
1515 rt2x00_set_field32(&reg, AUTO_RSP_CFG_CTS_40_MREF, 0);
1516 rt2x00_set_field32(&reg, AUTO_RSP_CFG_DUAL_CTS_EN, 0);
1517 rt2x00_set_field32(&reg, AUTO_RSP_CFG_ACK_CTS_PSM_BIT, 0);
1518 rt2x00pci_register_write(rt2x00dev, AUTO_RSP_CFG, reg);
1519
1520 rt2x00pci_register_read(rt2x00dev, CCK_PROT_CFG, &reg);
1521 rt2x00_set_field32(&reg, CCK_PROT_CFG_PROTECT_RATE, 8);
1522 rt2x00_set_field32(&reg, CCK_PROT_CFG_PROTECT_CTRL, 0);
1523 rt2x00_set_field32(&reg, CCK_PROT_CFG_PROTECT_NAV, 1);
1524 rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_CCK, 1);
1525 rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
1526 rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_MM20, 1);
1527 rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_MM40, 1);
1528 rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_GF20, 1);
1529 rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_GF40, 1);
1530 rt2x00pci_register_write(rt2x00dev, CCK_PROT_CFG, reg);
1531
1532 rt2x00pci_register_read(rt2x00dev, OFDM_PROT_CFG, &reg);
1533 rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_RATE, 8);
1534 rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_CTRL, 0);
1535 rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_NAV, 1);
1536 rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_CCK, 1);
1537 rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
1538 rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_MM20, 1);
1539 rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_MM40, 1);
1540 rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_GF20, 1);
1541 rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_GF40, 1);
1542 rt2x00pci_register_write(rt2x00dev, OFDM_PROT_CFG, reg);
1543
1544 rt2x00pci_register_read(rt2x00dev, MM20_PROT_CFG, &reg);
1545 rt2x00_set_field32(&reg, MM20_PROT_CFG_PROTECT_RATE, 0x4004);
1546 rt2x00_set_field32(&reg, MM20_PROT_CFG_PROTECT_CTRL, 0);
1547 rt2x00_set_field32(&reg, MM20_PROT_CFG_PROTECT_NAV, 1);
1548 rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_CCK, 1);
1549 rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
1550 rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_MM20, 1);
1551 rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_MM40, 0);
1552 rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_GF20, 1);
1553 rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_GF40, 0);
1554 rt2x00pci_register_write(rt2x00dev, MM20_PROT_CFG, reg);
1555
1556 rt2x00pci_register_read(rt2x00dev, MM40_PROT_CFG, &reg);
1557 rt2x00_set_field32(&reg, MM40_PROT_CFG_PROTECT_RATE, 0x4084);
1558 rt2x00_set_field32(&reg, MM40_PROT_CFG_PROTECT_CTRL, 0);
1559 rt2x00_set_field32(&reg, MM40_PROT_CFG_PROTECT_NAV, 1);
1560 rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_CCK, 1);
1561 rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
1562 rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_MM20, 1);
1563 rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_MM40, 1);
1564 rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_GF20, 1);
1565 rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_GF40, 1);
1566 rt2x00pci_register_write(rt2x00dev, MM40_PROT_CFG, reg);
1567
1568 rt2x00pci_register_read(rt2x00dev, GF20_PROT_CFG, &reg);
1569 rt2x00_set_field32(&reg, GF20_PROT_CFG_PROTECT_RATE, 0x4004);
1570 rt2x00_set_field32(&reg, GF20_PROT_CFG_PROTECT_CTRL, 0);
1571 rt2x00_set_field32(&reg, GF20_PROT_CFG_PROTECT_NAV, 1);
1572 rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_CCK, 1);
1573 rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
1574 rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_MM20, 1);
1575 rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_MM40, 0);
1576 rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_GF20, 1);
1577 rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_GF40, 0);
1578 rt2x00pci_register_write(rt2x00dev, GF20_PROT_CFG, reg);
1579
1580 rt2x00pci_register_read(rt2x00dev, GF40_PROT_CFG, &reg);
1581 rt2x00_set_field32(&reg, GF40_PROT_CFG_PROTECT_RATE, 0x4084);
1582 rt2x00_set_field32(&reg, GF40_PROT_CFG_PROTECT_CTRL, 0);
1583 rt2x00_set_field32(&reg, GF40_PROT_CFG_PROTECT_NAV, 1);
1584 rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_CCK, 1);
1585 rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
1586 rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_MM20, 1);
1587 rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_MM40, 1);
1588 rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_GF20, 1);
1589 rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_GF40, 1);
1590 rt2x00pci_register_write(rt2x00dev, GF40_PROT_CFG, reg);
1591
1592 rt2x00pci_register_write(rt2x00dev, TXOP_CTRL_CFG, 0x0000583f);
1593 rt2x00pci_register_write(rt2x00dev, TXOP_HLDR_ET, 0x00000002);
1594
1595 rt2x00pci_register_read(rt2x00dev, TX_RTS_CFG, &reg);
1596 rt2x00_set_field32(&reg, TX_RTS_CFG_AUTO_RTS_RETRY_LIMIT, 32);
1597 rt2x00_set_field32(&reg, TX_RTS_CFG_RTS_THRES,
1598 IEEE80211_MAX_RTS_THRESHOLD);
1599 rt2x00_set_field32(&reg, TX_RTS_CFG_RTS_FBK_EN, 0);
1600 rt2x00pci_register_write(rt2x00dev, TX_RTS_CFG, reg);
1601
1602 rt2x00pci_register_write(rt2x00dev, EXP_ACK_TIME, 0x002400ca);
1603 rt2x00pci_register_write(rt2x00dev, PWR_PIN_CFG, 0x00000003);
1604
1605 /*
1606 * ASIC will keep garbage value after boot, clear encryption keys.
1607 */
1608 for (i = 0; i < 4; i++)
1609 rt2x00pci_register_write(rt2x00dev,
1610 SHARED_KEY_MODE_ENTRY(i), 0);
1611
1612 for (i = 0; i < 256; i++) {
1613 u32 wcid[2] = { 0xffffffff, 0x00ffffff };
1614 rt2x00pci_register_multiwrite(rt2x00dev, MAC_WCID_ENTRY(i),
1615 wcid, sizeof(wcid));
1616
1617 rt2x00pci_register_write(rt2x00dev, MAC_WCID_ATTR_ENTRY(i), 1);
1618 rt2x00pci_register_write(rt2x00dev, MAC_IVEIV_ENTRY(i), 0);
1619 }
1620
1621 /*
1622 * Clear all beacons
1623 * For the Beacon base registers we only need to clear
1624 * the first byte since that byte contains the VALID and OWNER
1625 * bits which (when set to 0) will invalidate the entire beacon.
1626 */
1627 rt2x00pci_register_write(rt2x00dev, HW_BEACON_BASE0, 0);
1628 rt2x00pci_register_write(rt2x00dev, HW_BEACON_BASE1, 0);
1629 rt2x00pci_register_write(rt2x00dev, HW_BEACON_BASE2, 0);
1630 rt2x00pci_register_write(rt2x00dev, HW_BEACON_BASE3, 0);
1631 rt2x00pci_register_write(rt2x00dev, HW_BEACON_BASE4, 0);
1632 rt2x00pci_register_write(rt2x00dev, HW_BEACON_BASE5, 0);
1633 rt2x00pci_register_write(rt2x00dev, HW_BEACON_BASE6, 0);
1634 rt2x00pci_register_write(rt2x00dev, HW_BEACON_BASE7, 0);
1635
1636 rt2x00pci_register_read(rt2x00dev, HT_FBK_CFG0, &reg);
1637 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS0FBK, 0);
1638 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS1FBK, 0);
1639 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS2FBK, 1);
1640 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS3FBK, 2);
1641 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS4FBK, 3);
1642 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS5FBK, 4);
1643 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS6FBK, 5);
1644 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS7FBK, 6);
1645 rt2x00pci_register_write(rt2x00dev, HT_FBK_CFG0, reg);
1646
1647 rt2x00pci_register_read(rt2x00dev, HT_FBK_CFG1, &reg);
1648 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS8FBK, 8);
1649 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS9FBK, 8);
1650 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS10FBK, 9);
1651 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS11FBK, 10);
1652 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS12FBK, 11);
1653 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS13FBK, 12);
1654 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS14FBK, 13);
1655 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS15FBK, 14);
1656 rt2x00pci_register_write(rt2x00dev, HT_FBK_CFG1, reg);
1657
1658 rt2x00pci_register_read(rt2x00dev, LG_FBK_CFG0, &reg);
1659 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS0FBK, 8);
1660 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS1FBK, 8);
1661 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS2FBK, 9);
1662 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS3FBK, 10);
1663 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS4FBK, 11);
1664 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS5FBK, 12);
1665 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS6FBK, 13);
1666 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS7FBK, 14);
1667 rt2x00pci_register_write(rt2x00dev, LG_FBK_CFG0, reg);
1668
1669 rt2x00pci_register_read(rt2x00dev, LG_FBK_CFG1, &reg);
1670 rt2x00_set_field32(&reg, LG_FBK_CFG0_CCKMCS0FBK, 0);
1671 rt2x00_set_field32(&reg, LG_FBK_CFG0_CCKMCS1FBK, 0);
1672 rt2x00_set_field32(&reg, LG_FBK_CFG0_CCKMCS2FBK, 1);
1673 rt2x00_set_field32(&reg, LG_FBK_CFG0_CCKMCS3FBK, 2);
1674 rt2x00pci_register_write(rt2x00dev, LG_FBK_CFG1, reg);
1675
1676 /*
1677 * We must clear the error counters.
1678 * These registers are cleared on read,
1679 * so we may pass a useless variable to store the value.
1680 */
1681 rt2x00pci_register_read(rt2x00dev, RX_STA_CNT0, &reg);
1682 rt2x00pci_register_read(rt2x00dev, RX_STA_CNT1, &reg);
1683 rt2x00pci_register_read(rt2x00dev, RX_STA_CNT2, &reg);
1684 rt2x00pci_register_read(rt2x00dev, TX_STA_CNT0, &reg);
1685 rt2x00pci_register_read(rt2x00dev, TX_STA_CNT1, &reg);
1686 rt2x00pci_register_read(rt2x00dev, TX_STA_CNT2, &reg);
1687
1688 return 0;
1689}
1690
1691static int rt2800pci_wait_bbp_rf_ready(struct rt2x00_dev *rt2x00dev)
1692{
1693 unsigned int i;
1694 u32 reg;
1695
1696 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
1697 rt2x00pci_register_read(rt2x00dev, MAC_STATUS_CFG, &reg);
1698 if (!rt2x00_get_field32(reg, MAC_STATUS_CFG_BBP_RF_BUSY))
1699 return 0;
1700
1701 udelay(REGISTER_BUSY_DELAY);
1702 }
1703
1704 ERROR(rt2x00dev, "BBP/RF register access failed, aborting.\n");
1705 return -EACCES;
1706}
1707
1708static int rt2800pci_wait_bbp_ready(struct rt2x00_dev *rt2x00dev)
1709{
1710 unsigned int i;
1711 u8 value;
1712
1713 /*
1714 * BBP was enabled after firmware was loaded,
1715 * but we need to reactivate it now.
1716 */
1717 rt2x00pci_register_write(rt2x00dev, H2M_BBP_AGENT, 0);
1718 rt2x00pci_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
1719 msleep(1);
1720
1721 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
1722 rt2800pci_bbp_read(rt2x00dev, 0, &value);
1723 if ((value != 0xff) && (value != 0x00))
1724 return 0;
1725 udelay(REGISTER_BUSY_DELAY);
1726 }
1727
1728 ERROR(rt2x00dev, "BBP register access failed, aborting.\n");
1729 return -EACCES;
1730}
1731
1732static int rt2800pci_init_bbp(struct rt2x00_dev *rt2x00dev)
1733{
1734 unsigned int i;
1735 u16 eeprom;
1736 u8 reg_id;
1737 u8 value;
1738
1739 if (unlikely(rt2800pci_wait_bbp_rf_ready(rt2x00dev) ||
1740 rt2800pci_wait_bbp_ready(rt2x00dev)))
1741 return -EACCES;
1742
1743 rt2800pci_bbp_write(rt2x00dev, 65, 0x2c);
1744 rt2800pci_bbp_write(rt2x00dev, 66, 0x38);
1745 rt2800pci_bbp_write(rt2x00dev, 69, 0x12);
1746 rt2800pci_bbp_write(rt2x00dev, 70, 0x0a);
1747 rt2800pci_bbp_write(rt2x00dev, 73, 0x10);
1748 rt2800pci_bbp_write(rt2x00dev, 81, 0x37);
1749 rt2800pci_bbp_write(rt2x00dev, 82, 0x62);
1750 rt2800pci_bbp_write(rt2x00dev, 83, 0x6a);
1751 rt2800pci_bbp_write(rt2x00dev, 84, 0x99);
1752 rt2800pci_bbp_write(rt2x00dev, 86, 0x00);
1753 rt2800pci_bbp_write(rt2x00dev, 91, 0x04);
1754 rt2800pci_bbp_write(rt2x00dev, 92, 0x00);
1755 rt2800pci_bbp_write(rt2x00dev, 103, 0x00);
1756 rt2800pci_bbp_write(rt2x00dev, 105, 0x05);
1757
1758 if (rt2x00_rev(&rt2x00dev->chip) == RT2860C_VERSION) {
1759 rt2800pci_bbp_write(rt2x00dev, 69, 0x16);
1760 rt2800pci_bbp_write(rt2x00dev, 73, 0x12);
1761 }
1762
1763 if (rt2x00_rev(&rt2x00dev->chip) > RT2860D_VERSION)
1764 rt2800pci_bbp_write(rt2x00dev, 84, 0x19);
1765
1766 if (rt2x00_rt(&rt2x00dev->chip, RT3052)) {
1767 rt2800pci_bbp_write(rt2x00dev, 31, 0x08);
1768 rt2800pci_bbp_write(rt2x00dev, 78, 0x0e);
1769 rt2800pci_bbp_write(rt2x00dev, 80, 0x08);
1770 }
1771
1772 for (i = 0; i < EEPROM_BBP_SIZE; i++) {
1773 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBP_START + i, &eeprom);
1774
1775 if (eeprom != 0xffff && eeprom != 0x0000) {
1776 reg_id = rt2x00_get_field16(eeprom, EEPROM_BBP_REG_ID);
1777 value = rt2x00_get_field16(eeprom, EEPROM_BBP_VALUE);
1778 rt2800pci_bbp_write(rt2x00dev, reg_id, value);
1779 }
1780 }
1781
1782 return 0;
1783}
1784
1785static u8 rt2800pci_init_rx_filter(struct rt2x00_dev *rt2x00dev,
1786 bool bw40, u8 rfcsr24, u8 filter_target)
1787{
1788 unsigned int i;
1789 u8 bbp;
1790 u8 rfcsr;
1791 u8 passband;
1792 u8 stopband;
1793 u8 overtuned = 0;
1794
1795 rt2800pci_rfcsr_write(rt2x00dev, 24, rfcsr24);
1796
1797 rt2800pci_bbp_read(rt2x00dev, 4, &bbp);
1798 rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 2 * bw40);
1799 rt2800pci_bbp_write(rt2x00dev, 4, bbp);
1800
1801 rt2800pci_rfcsr_read(rt2x00dev, 22, &rfcsr);
1802 rt2x00_set_field8(&rfcsr, RFCSR22_BASEBAND_LOOPBACK, 1);
1803 rt2800pci_rfcsr_write(rt2x00dev, 22, rfcsr);
1804
1805 /*
1806 * Set power & frequency of passband test tone
1807 */
1808 rt2800pci_bbp_write(rt2x00dev, 24, 0);
1809
1810 for (i = 0; i < 100; i++) {
1811 rt2800pci_bbp_write(rt2x00dev, 25, 0x90);
1812 msleep(1);
1813
1814 rt2800pci_bbp_read(rt2x00dev, 55, &passband);
1815 if (passband)
1816 break;
1817 }
1818
1819 /*
1820 * Set power & frequency of stopband test tone
1821 */
1822 rt2800pci_bbp_write(rt2x00dev, 24, 0x06);
1823
1824 for (i = 0; i < 100; i++) {
1825 rt2800pci_bbp_write(rt2x00dev, 25, 0x90);
1826 msleep(1);
1827
1828 rt2800pci_bbp_read(rt2x00dev, 55, &stopband);
1829
1830 if ((passband - stopband) <= filter_target) {
1831 rfcsr24++;
1832 overtuned += ((passband - stopband) == filter_target);
1833 } else
1834 break;
1835
1836 rt2800pci_rfcsr_write(rt2x00dev, 24, rfcsr24);
1837 }
1838
1839 rfcsr24 -= !!overtuned;
1840
1841 rt2800pci_rfcsr_write(rt2x00dev, 24, rfcsr24);
1842 return rfcsr24;
1843}
1844
1845static int rt2800pci_init_rfcsr(struct rt2x00_dev *rt2x00dev)
1846{
1847 u8 rfcsr;
1848 u8 bbp;
1849
1850 if (!rt2x00_rf(&rt2x00dev->chip, RF3020) &&
1851 !rt2x00_rf(&rt2x00dev->chip, RF3021) &&
1852 !rt2x00_rf(&rt2x00dev->chip, RF3022))
1853 return 0;
1854
1855 /*
1856 * Init RF calibration.
1857 */
1858 rt2800pci_rfcsr_read(rt2x00dev, 30, &rfcsr);
1859 rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 1);
1860 rt2800pci_rfcsr_write(rt2x00dev, 30, rfcsr);
1861 msleep(1);
1862 rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 0);
1863 rt2800pci_rfcsr_write(rt2x00dev, 30, rfcsr);
1864
1865 rt2800pci_rfcsr_write(rt2x00dev, 0, 0x50);
1866 rt2800pci_rfcsr_write(rt2x00dev, 1, 0x01);
1867 rt2800pci_rfcsr_write(rt2x00dev, 2, 0xf7);
1868 rt2800pci_rfcsr_write(rt2x00dev, 3, 0x75);
1869 rt2800pci_rfcsr_write(rt2x00dev, 4, 0x40);
1870 rt2800pci_rfcsr_write(rt2x00dev, 5, 0x03);
1871 rt2800pci_rfcsr_write(rt2x00dev, 6, 0x02);
1872 rt2800pci_rfcsr_write(rt2x00dev, 7, 0x50);
1873 rt2800pci_rfcsr_write(rt2x00dev, 8, 0x39);
1874 rt2800pci_rfcsr_write(rt2x00dev, 9, 0x0f);
1875 rt2800pci_rfcsr_write(rt2x00dev, 10, 0x60);
1876 rt2800pci_rfcsr_write(rt2x00dev, 11, 0x21);
1877 rt2800pci_rfcsr_write(rt2x00dev, 12, 0x75);
1878 rt2800pci_rfcsr_write(rt2x00dev, 13, 0x75);
1879 rt2800pci_rfcsr_write(rt2x00dev, 14, 0x90);
1880 rt2800pci_rfcsr_write(rt2x00dev, 15, 0x58);
1881 rt2800pci_rfcsr_write(rt2x00dev, 16, 0xb3);
1882 rt2800pci_rfcsr_write(rt2x00dev, 17, 0x92);
1883 rt2800pci_rfcsr_write(rt2x00dev, 18, 0x2c);
1884 rt2800pci_rfcsr_write(rt2x00dev, 19, 0x02);
1885 rt2800pci_rfcsr_write(rt2x00dev, 20, 0xba);
1886 rt2800pci_rfcsr_write(rt2x00dev, 21, 0xdb);
1887 rt2800pci_rfcsr_write(rt2x00dev, 22, 0x00);
1888 rt2800pci_rfcsr_write(rt2x00dev, 23, 0x31);
1889 rt2800pci_rfcsr_write(rt2x00dev, 24, 0x08);
1890 rt2800pci_rfcsr_write(rt2x00dev, 25, 0x01);
1891 rt2800pci_rfcsr_write(rt2x00dev, 26, 0x25);
1892 rt2800pci_rfcsr_write(rt2x00dev, 27, 0x23);
1893 rt2800pci_rfcsr_write(rt2x00dev, 28, 0x13);
1894 rt2800pci_rfcsr_write(rt2x00dev, 29, 0x83);
1895
1896 /*
1897 * Set RX Filter calibration for 20MHz and 40MHz
1898 */
1899 rt2x00dev->calibration[0] =
1900 rt2800pci_init_rx_filter(rt2x00dev, false, 0x07, 0x16);
1901 rt2x00dev->calibration[1] =
1902 rt2800pci_init_rx_filter(rt2x00dev, true, 0x27, 0x19);
1903
1904 /*
1905 * Set back to initial state
1906 */
1907 rt2800pci_bbp_write(rt2x00dev, 24, 0);
1908
1909 rt2800pci_rfcsr_read(rt2x00dev, 22, &rfcsr);
1910 rt2x00_set_field8(&rfcsr, RFCSR22_BASEBAND_LOOPBACK, 0);
1911 rt2800pci_rfcsr_write(rt2x00dev, 22, rfcsr);
1912
1913 /*
1914 * set BBP back to BW20
1915 */
1916 rt2800pci_bbp_read(rt2x00dev, 4, &bbp);
1917 rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 0);
1918 rt2800pci_bbp_write(rt2x00dev, 4, bbp);
1919
1920 return 0;
1921}
1922
1923/*
1924 * Device state switch handlers.
1925 */
1926static void rt2800pci_toggle_rx(struct rt2x00_dev *rt2x00dev,
1927 enum dev_state state)
1928{
1929 u32 reg;
1930
1931 rt2x00pci_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
1932 rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_RX,
1933 (state == STATE_RADIO_RX_ON) ||
1934 (state == STATE_RADIO_RX_ON_LINK));
1935 rt2x00pci_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
1936}
1937
1938static void rt2800pci_toggle_irq(struct rt2x00_dev *rt2x00dev,
1939 enum dev_state state)
1940{
1941 int mask = (state == STATE_RADIO_IRQ_ON);
1942 u32 reg;
1943
1944 /*
1945 * When interrupts are being enabled, the interrupt registers
1946 * should clear the register to assure a clean state.
1947 */
1948 if (state == STATE_RADIO_IRQ_ON) {
1949 rt2x00pci_register_read(rt2x00dev, INT_SOURCE_CSR, &reg);
1950 rt2x00pci_register_write(rt2x00dev, INT_SOURCE_CSR, reg);
1951 }
1952
1953 rt2x00pci_register_read(rt2x00dev, INT_MASK_CSR, &reg);
1954 rt2x00_set_field32(&reg, INT_MASK_CSR_RXDELAYINT, mask);
1955 rt2x00_set_field32(&reg, INT_MASK_CSR_TXDELAYINT, mask);
1956 rt2x00_set_field32(&reg, INT_MASK_CSR_RX_DONE, mask);
1957 rt2x00_set_field32(&reg, INT_MASK_CSR_AC0_DMA_DONE, mask);
1958 rt2x00_set_field32(&reg, INT_MASK_CSR_AC1_DMA_DONE, mask);
1959 rt2x00_set_field32(&reg, INT_MASK_CSR_AC2_DMA_DONE, mask);
1960 rt2x00_set_field32(&reg, INT_MASK_CSR_AC3_DMA_DONE, mask);
1961 rt2x00_set_field32(&reg, INT_MASK_CSR_HCCA_DMA_DONE, mask);
1962 rt2x00_set_field32(&reg, INT_MASK_CSR_MGMT_DMA_DONE, mask);
1963 rt2x00_set_field32(&reg, INT_MASK_CSR_MCU_COMMAND, mask);
1964 rt2x00_set_field32(&reg, INT_MASK_CSR_RXTX_COHERENT, mask);
1965 rt2x00_set_field32(&reg, INT_MASK_CSR_TBTT, mask);
1966 rt2x00_set_field32(&reg, INT_MASK_CSR_PRE_TBTT, mask);
1967 rt2x00_set_field32(&reg, INT_MASK_CSR_TX_FIFO_STATUS, mask);
1968 rt2x00_set_field32(&reg, INT_MASK_CSR_AUTO_WAKEUP, mask);
1969 rt2x00_set_field32(&reg, INT_MASK_CSR_GPTIMER, mask);
1970 rt2x00_set_field32(&reg, INT_MASK_CSR_RX_COHERENT, mask);
1971 rt2x00_set_field32(&reg, INT_MASK_CSR_TX_COHERENT, mask);
1972 rt2x00pci_register_write(rt2x00dev, INT_MASK_CSR, reg);
1973}
1974
1975static int rt2800pci_wait_wpdma_ready(struct rt2x00_dev *rt2x00dev)
1976{
1977 unsigned int i;
1978 u32 reg;
1979
1980 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
1981 rt2x00pci_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
1982 if (!rt2x00_get_field32(reg, WPDMA_GLO_CFG_TX_DMA_BUSY) &&
1983 !rt2x00_get_field32(reg, WPDMA_GLO_CFG_RX_DMA_BUSY))
1984 return 0;
1985
1986 msleep(1);
1987 }
1988
1989 ERROR(rt2x00dev, "WPDMA TX/RX busy, aborting.\n");
1990 return -EACCES;
1991}
1992
1993static int rt2800pci_enable_radio(struct rt2x00_dev *rt2x00dev)
1994{
1995 u32 reg;
1996 u16 word;
1997
1998 /*
1999 * Initialize all registers.
2000 */
2001 if (unlikely(rt2800pci_wait_wpdma_ready(rt2x00dev) ||
2002 rt2800pci_init_queues(rt2x00dev) ||
2003 rt2800pci_init_registers(rt2x00dev) ||
2004 rt2800pci_wait_wpdma_ready(rt2x00dev) ||
2005 rt2800pci_init_bbp(rt2x00dev) ||
2006 rt2800pci_init_rfcsr(rt2x00dev)))
2007 return -EIO;
2008
2009 /*
2010 * Send signal to firmware during boot time.
2011 */
2012 rt2800pci_mcu_request(rt2x00dev, MCU_BOOT_SIGNAL, 0xff, 0, 0);
2013
2014 /*
2015 * Enable RX.
2016 */
2017 rt2x00pci_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
2018 rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_TX, 1);
2019 rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_RX, 0);
2020 rt2x00pci_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
2021
2022 rt2x00pci_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
2023 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 1);
2024 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 1);
2025 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_WP_DMA_BURST_SIZE, 2);
2026 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1);
2027 rt2x00pci_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
2028
2029 rt2x00pci_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
2030 rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_TX, 1);
2031 rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_RX, 1);
2032 rt2x00pci_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
2033
2034 /*
2035 * Initialize LED control
2036 */
2037 rt2x00_eeprom_read(rt2x00dev, EEPROM_LED1, &word);
2038 rt2800pci_mcu_request(rt2x00dev, MCU_LED_1, 0xff,
2039 word & 0xff, (word >> 8) & 0xff);
2040
2041 rt2x00_eeprom_read(rt2x00dev, EEPROM_LED2, &word);
2042 rt2800pci_mcu_request(rt2x00dev, MCU_LED_2, 0xff,
2043 word & 0xff, (word >> 8) & 0xff);
2044
2045 rt2x00_eeprom_read(rt2x00dev, EEPROM_LED3, &word);
2046 rt2800pci_mcu_request(rt2x00dev, MCU_LED_3, 0xff,
2047 word & 0xff, (word >> 8) & 0xff);
2048
2049 return 0;
2050}
2051
2052static void rt2800pci_disable_radio(struct rt2x00_dev *rt2x00dev)
2053{
2054 u32 reg;
2055
2056 rt2x00pci_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
2057 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0);
2058 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_DMA_BUSY, 0);
2059 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0);
2060 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_RX_DMA_BUSY, 0);
2061 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1);
2062 rt2x00pci_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
2063
2064 rt2x00pci_register_write(rt2x00dev, MAC_SYS_CTRL, 0);
2065 rt2x00pci_register_write(rt2x00dev, PWR_PIN_CFG, 0);
2066 rt2x00pci_register_write(rt2x00dev, TX_PIN_CFG, 0);
2067
2068 rt2x00pci_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00001280);
2069
2070 rt2x00pci_register_read(rt2x00dev, WPDMA_RST_IDX, &reg);
2071 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX0, 1);
2072 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX1, 1);
2073 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX2, 1);
2074 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX3, 1);
2075 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX4, 1);
2076 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX5, 1);
2077 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DRX_IDX0, 1);
2078 rt2x00pci_register_write(rt2x00dev, WPDMA_RST_IDX, reg);
2079
2080 rt2x00pci_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00000e1f);
2081 rt2x00pci_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00000e00);
2082
2083 /* Wait for DMA, ignore error */
2084 rt2800pci_wait_wpdma_ready(rt2x00dev);
2085}
2086
2087static int rt2800pci_set_state(struct rt2x00_dev *rt2x00dev,
2088 enum dev_state state)
2089{
2090 /*
2091 * Always put the device to sleep (even when we intend to wakeup!)
2092 * if the device is booting and wasn't asleep it will return
2093 * failure when attempting to wakeup.
2094 */
2095 rt2800pci_mcu_request(rt2x00dev, MCU_SLEEP, 0xff, 0, 2);
2096
2097 if (state == STATE_AWAKE) {
2098 rt2800pci_mcu_request(rt2x00dev, MCU_WAKEUP, TOKEN_WAKUP, 0, 0);
2099 rt2800pci_mcu_status(rt2x00dev, TOKEN_WAKUP);
2100 }
2101
2102 return 0;
2103}
2104
2105static int rt2800pci_set_device_state(struct rt2x00_dev *rt2x00dev,
2106 enum dev_state state)
2107{
2108 int retval = 0;
2109
2110 switch (state) {
2111 case STATE_RADIO_ON:
2112 /*
2113 * Before the radio can be enabled, the device first has
2114 * to be woken up. After that it needs a bit of time
2115 * to be fully awake and then the radio can be enabled.
2116 */
2117 rt2800pci_set_state(rt2x00dev, STATE_AWAKE);
2118 msleep(1);
2119 retval = rt2800pci_enable_radio(rt2x00dev);
2120 break;
2121 case STATE_RADIO_OFF:
2122 /*
2123 * After the radio has been disabled, the device should
2124 * be put to sleep for powersaving.
2125 */
2126 rt2800pci_disable_radio(rt2x00dev);
2127 rt2800pci_set_state(rt2x00dev, STATE_SLEEP);
2128 break;
2129 case STATE_RADIO_RX_ON:
2130 case STATE_RADIO_RX_ON_LINK:
2131 case STATE_RADIO_RX_OFF:
2132 case STATE_RADIO_RX_OFF_LINK:
2133 rt2800pci_toggle_rx(rt2x00dev, state);
2134 break;
2135 case STATE_RADIO_IRQ_ON:
2136 case STATE_RADIO_IRQ_OFF:
2137 rt2800pci_toggle_irq(rt2x00dev, state);
2138 break;
2139 case STATE_DEEP_SLEEP:
2140 case STATE_SLEEP:
2141 case STATE_STANDBY:
2142 case STATE_AWAKE:
2143 retval = rt2800pci_set_state(rt2x00dev, state);
2144 break;
2145 default:
2146 retval = -ENOTSUPP;
2147 break;
2148 }
2149
2150 if (unlikely(retval))
2151 ERROR(rt2x00dev, "Device failed to enter state %d (%d).\n",
2152 state, retval);
2153
2154 return retval;
2155}
2156
2157/*
2158 * TX descriptor initialization
2159 */
2160static void rt2800pci_write_tx_desc(struct rt2x00_dev *rt2x00dev,
2161 struct sk_buff *skb,
2162 struct txentry_desc *txdesc)
2163{
2164 struct skb_frame_desc *skbdesc = get_skb_frame_desc(skb);
2165 __le32 *txd = skbdesc->desc;
2166 __le32 *txwi = (__le32 *)(skb->data - rt2x00dev->hw->extra_tx_headroom);
2167 u32 word;
2168
2169 /*
2170 * Initialize TX Info descriptor
2171 */
2172 rt2x00_desc_read(txwi, 0, &word);
2173 rt2x00_set_field32(&word, TXWI_W0_FRAG,
2174 test_bit(ENTRY_TXD_MORE_FRAG, &txdesc->flags));
2175 rt2x00_set_field32(&word, TXWI_W0_MIMO_PS, 0);
2176 rt2x00_set_field32(&word, TXWI_W0_CF_ACK, 0);
2177 rt2x00_set_field32(&word, TXWI_W0_TS,
2178 test_bit(ENTRY_TXD_REQ_TIMESTAMP, &txdesc->flags));
2179 rt2x00_set_field32(&word, TXWI_W0_AMPDU,
2180 test_bit(ENTRY_TXD_HT_AMPDU, &txdesc->flags));
2181 rt2x00_set_field32(&word, TXWI_W0_MPDU_DENSITY, txdesc->mpdu_density);
2182 rt2x00_set_field32(&word, TXWI_W0_TX_OP, txdesc->ifs);
2183 rt2x00_set_field32(&word, TXWI_W0_MCS, txdesc->mcs);
2184 rt2x00_set_field32(&word, TXWI_W0_BW,
2185 test_bit(ENTRY_TXD_HT_BW_40, &txdesc->flags));
2186 rt2x00_set_field32(&word, TXWI_W0_SHORT_GI,
2187 test_bit(ENTRY_TXD_HT_SHORT_GI, &txdesc->flags));
2188 rt2x00_set_field32(&word, TXWI_W0_STBC, txdesc->stbc);
2189 rt2x00_set_field32(&word, TXWI_W0_PHYMODE, txdesc->rate_mode);
2190 rt2x00_desc_write(txwi, 0, word);
2191
2192 rt2x00_desc_read(txwi, 1, &word);
2193 rt2x00_set_field32(&word, TXWI_W1_ACK,
2194 test_bit(ENTRY_TXD_ACK, &txdesc->flags));
2195 rt2x00_set_field32(&word, TXWI_W1_NSEQ,
2196 test_bit(ENTRY_TXD_GENERATE_SEQ, &txdesc->flags));
2197 rt2x00_set_field32(&word, TXWI_W1_BW_WIN_SIZE, txdesc->ba_size);
2198 rt2x00_set_field32(&word, TXWI_W1_WIRELESS_CLI_ID,
2199 test_bit(ENTRY_TXD_ENCRYPT, &txdesc->flags) ?
Bartlomiej Zolnierkiewiczf644fea2009-11-04 18:32:24 +01002200 txdesc->key_idx : 0xff);
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +02002201 rt2x00_set_field32(&word, TXWI_W1_MPDU_TOTAL_BYTE_COUNT,
2202 skb->len - txdesc->l2pad);
2203 rt2x00_set_field32(&word, TXWI_W1_PACKETID,
2204 skbdesc->entry->queue->qid + 1);
2205 rt2x00_desc_write(txwi, 1, word);
2206
2207 /*
2208 * Always write 0 to IV/EIV fields, hardware will insert the IV
2209 * from the IVEIV register when ENTRY_TXD_ENCRYPT_IV is set to 0.
2210 * When ENTRY_TXD_ENCRYPT_IV is set to 1 it will use the IV data
2211 * from the descriptor. The TXWI_W1_WIRELESS_CLI_ID indicates which
2212 * crypto entry in the registers should be used to encrypt the frame.
2213 */
2214 _rt2x00_desc_write(txwi, 2, 0 /* skbdesc->iv[0] */);
2215 _rt2x00_desc_write(txwi, 3, 0 /* skbdesc->iv[1] */);
2216
2217 /*
2218 * The buffers pointed by SD_PTR0/SD_LEN0 and SD_PTR1/SD_LEN1
2219 * must contains a TXWI structure + 802.11 header + padding + 802.11
2220 * data. We choose to have SD_PTR0/SD_LEN0 only contains TXWI and
2221 * SD_PTR1/SD_LEN1 contains 802.11 header + padding + 802.11
2222 * data. It means that LAST_SEC0 is always 0.
2223 */
2224
2225 /*
2226 * Initialize TX descriptor
2227 */
2228 rt2x00_desc_read(txd, 0, &word);
2229 rt2x00_set_field32(&word, TXD_W0_SD_PTR0, skbdesc->skb_dma);
2230 rt2x00_desc_write(txd, 0, word);
2231
2232 rt2x00_desc_read(txd, 1, &word);
2233 rt2x00_set_field32(&word, TXD_W1_SD_LEN1, skb->len);
2234 rt2x00_set_field32(&word, TXD_W1_LAST_SEC1,
2235 !test_bit(ENTRY_TXD_MORE_FRAG, &txdesc->flags));
2236 rt2x00_set_field32(&word, TXD_W1_BURST,
2237 test_bit(ENTRY_TXD_BURST, &txdesc->flags));
2238 rt2x00_set_field32(&word, TXD_W1_SD_LEN0,
2239 rt2x00dev->hw->extra_tx_headroom);
2240 rt2x00_set_field32(&word, TXD_W1_LAST_SEC0, 0);
2241 rt2x00_set_field32(&word, TXD_W1_DMA_DONE, 0);
2242 rt2x00_desc_write(txd, 1, word);
2243
2244 rt2x00_desc_read(txd, 2, &word);
2245 rt2x00_set_field32(&word, TXD_W2_SD_PTR1,
2246 skbdesc->skb_dma + rt2x00dev->hw->extra_tx_headroom);
2247 rt2x00_desc_write(txd, 2, word);
2248
2249 rt2x00_desc_read(txd, 3, &word);
2250 rt2x00_set_field32(&word, TXD_W3_WIV,
2251 !test_bit(ENTRY_TXD_ENCRYPT_IV, &txdesc->flags));
2252 rt2x00_set_field32(&word, TXD_W3_QSEL, 2);
2253 rt2x00_desc_write(txd, 3, word);
2254}
2255
2256/*
2257 * TX data initialization
2258 */
2259static void rt2800pci_write_beacon(struct queue_entry *entry)
2260{
2261 struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
2262 struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
2263 unsigned int beacon_base;
2264 u32 reg;
2265
2266 /*
2267 * Disable beaconing while we are reloading the beacon data,
2268 * otherwise we might be sending out invalid data.
2269 */
2270 rt2x00pci_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
2271 rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 0);
2272 rt2x00pci_register_write(rt2x00dev, BCN_TIME_CFG, reg);
2273
2274 /*
2275 * Write entire beacon with descriptor to register.
2276 */
2277 beacon_base = HW_BEACON_OFFSET(entry->entry_idx);
2278 rt2x00pci_register_multiwrite(rt2x00dev,
2279 beacon_base,
2280 skbdesc->desc, skbdesc->desc_len);
2281 rt2x00pci_register_multiwrite(rt2x00dev,
2282 beacon_base + skbdesc->desc_len,
2283 entry->skb->data, entry->skb->len);
2284
2285 /*
2286 * Clean up beacon skb.
2287 */
2288 dev_kfree_skb_any(entry->skb);
2289 entry->skb = NULL;
2290}
2291
2292static void rt2800pci_kick_tx_queue(struct rt2x00_dev *rt2x00dev,
2293 const enum data_queue_qid queue_idx)
2294{
2295 struct data_queue *queue;
2296 unsigned int idx, qidx = 0;
2297 u32 reg;
2298
2299 if (queue_idx == QID_BEACON) {
2300 rt2x00pci_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
2301 if (!rt2x00_get_field32(reg, BCN_TIME_CFG_BEACON_GEN)) {
2302 rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_TICKING, 1);
2303 rt2x00_set_field32(&reg, BCN_TIME_CFG_TBTT_ENABLE, 1);
2304 rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 1);
2305 rt2x00pci_register_write(rt2x00dev, BCN_TIME_CFG, reg);
2306 }
2307 return;
2308 }
2309
2310 if (queue_idx > QID_HCCA && queue_idx != QID_MGMT)
2311 return;
2312
2313 queue = rt2x00queue_get_queue(rt2x00dev, queue_idx);
2314 idx = queue->index[Q_INDEX];
2315
2316 if (queue_idx == QID_MGMT)
2317 qidx = 5;
2318 else
2319 qidx = queue_idx;
2320
2321 rt2x00pci_register_write(rt2x00dev, TX_CTX_IDX(qidx), idx);
2322}
2323
2324static void rt2800pci_kill_tx_queue(struct rt2x00_dev *rt2x00dev,
2325 const enum data_queue_qid qid)
2326{
2327 u32 reg;
2328
2329 if (qid == QID_BEACON) {
2330 rt2x00pci_register_write(rt2x00dev, BCN_TIME_CFG, 0);
2331 return;
2332 }
2333
2334 rt2x00pci_register_read(rt2x00dev, WPDMA_RST_IDX, &reg);
2335 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX0, (qid == QID_AC_BE));
2336 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX1, (qid == QID_AC_BK));
2337 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX2, (qid == QID_AC_VI));
2338 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX3, (qid == QID_AC_VO));
2339 rt2x00pci_register_write(rt2x00dev, WPDMA_RST_IDX, reg);
2340}
2341
2342/*
2343 * RX control handlers
2344 */
2345static void rt2800pci_fill_rxdone(struct queue_entry *entry,
2346 struct rxdone_entry_desc *rxdesc)
2347{
2348 struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
2349 struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
2350 struct queue_entry_priv_pci *entry_priv = entry->priv_data;
2351 __le32 *rxd = entry_priv->desc;
2352 __le32 *rxwi = (__le32 *)entry->skb->data;
2353 u32 rxd3;
2354 u32 rxwi0;
2355 u32 rxwi1;
2356 u32 rxwi2;
2357 u32 rxwi3;
2358
2359 rt2x00_desc_read(rxd, 3, &rxd3);
2360 rt2x00_desc_read(rxwi, 0, &rxwi0);
2361 rt2x00_desc_read(rxwi, 1, &rxwi1);
2362 rt2x00_desc_read(rxwi, 2, &rxwi2);
2363 rt2x00_desc_read(rxwi, 3, &rxwi3);
2364
2365 if (rt2x00_get_field32(rxd3, RXD_W3_CRC_ERROR))
2366 rxdesc->flags |= RX_FLAG_FAILED_FCS_CRC;
2367
2368 if (test_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags)) {
2369 /*
2370 * Unfortunately we don't know the cipher type used during
2371 * decryption. This prevents us from correct providing
2372 * correct statistics through debugfs.
2373 */
2374 rxdesc->cipher = rt2x00_get_field32(rxwi0, RXWI_W0_UDF);
2375 rxdesc->cipher_status =
2376 rt2x00_get_field32(rxd3, RXD_W3_CIPHER_ERROR);
2377 }
2378
2379 if (rt2x00_get_field32(rxd3, RXD_W3_DECRYPTED)) {
2380 /*
2381 * Hardware has stripped IV/EIV data from 802.11 frame during
2382 * decryption. Unfortunately the descriptor doesn't contain
2383 * any fields with the EIV/IV data either, so they can't
2384 * be restored by rt2x00lib.
2385 */
2386 rxdesc->flags |= RX_FLAG_IV_STRIPPED;
2387
2388 if (rxdesc->cipher_status == RX_CRYPTO_SUCCESS)
2389 rxdesc->flags |= RX_FLAG_DECRYPTED;
2390 else if (rxdesc->cipher_status == RX_CRYPTO_FAIL_MIC)
2391 rxdesc->flags |= RX_FLAG_MMIC_ERROR;
2392 }
2393
2394 if (rt2x00_get_field32(rxd3, RXD_W3_MY_BSS))
2395 rxdesc->dev_flags |= RXDONE_MY_BSS;
2396
2397 if (rt2x00_get_field32(rxd3, RXD_W3_L2PAD)) {
2398 rxdesc->dev_flags |= RXDONE_L2PAD;
2399 skbdesc->flags |= SKBDESC_L2_PADDED;
2400 }
2401
2402 if (rt2x00_get_field32(rxwi1, RXWI_W1_SHORT_GI))
2403 rxdesc->flags |= RX_FLAG_SHORT_GI;
2404
2405 if (rt2x00_get_field32(rxwi1, RXWI_W1_BW))
2406 rxdesc->flags |= RX_FLAG_40MHZ;
2407
2408 /*
2409 * Detect RX rate, always use MCS as signal type.
2410 */
2411 rxdesc->dev_flags |= RXDONE_SIGNAL_MCS;
2412 rxdesc->rate_mode = rt2x00_get_field32(rxwi1, RXWI_W1_PHYMODE);
2413 rxdesc->signal = rt2x00_get_field32(rxwi1, RXWI_W1_MCS);
2414
2415 /*
2416 * Mask of 0x8 bit to remove the short preamble flag.
2417 */
2418 if (rxdesc->rate_mode == RATE_MODE_CCK)
2419 rxdesc->signal &= ~0x8;
2420
2421 rxdesc->rssi =
2422 (rt2x00_get_field32(rxwi2, RXWI_W2_RSSI0) +
2423 rt2x00_get_field32(rxwi2, RXWI_W2_RSSI1)) / 2;
2424
2425 rxdesc->noise =
2426 (rt2x00_get_field32(rxwi3, RXWI_W3_SNR0) +
2427 rt2x00_get_field32(rxwi3, RXWI_W3_SNR1)) / 2;
2428
2429 rxdesc->size = rt2x00_get_field32(rxwi0, RXWI_W0_MPDU_TOTAL_BYTE_COUNT);
2430
2431 /*
2432 * Set RX IDX in register to inform hardware that we have handled
2433 * this entry and it is available for reuse again.
2434 */
2435 rt2x00pci_register_write(rt2x00dev, RX_CRX_IDX, entry->entry_idx);
2436
2437 /*
2438 * Remove TXWI descriptor from start of buffer.
2439 */
2440 skb_pull(entry->skb, RXWI_DESC_SIZE);
2441 skb_trim(entry->skb, rxdesc->size);
2442}
2443
2444/*
2445 * Interrupt functions.
2446 */
2447static void rt2800pci_txdone(struct rt2x00_dev *rt2x00dev)
2448{
2449 struct data_queue *queue;
2450 struct queue_entry *entry;
2451 struct queue_entry *entry_done;
2452 struct queue_entry_priv_pci *entry_priv;
2453 struct txdone_entry_desc txdesc;
2454 u32 word;
2455 u32 reg;
2456 u32 old_reg;
2457 unsigned int type;
2458 unsigned int index;
2459 u16 mcs, real_mcs;
2460
2461 /*
2462 * During each loop we will compare the freshly read
2463 * TX_STA_FIFO register value with the value read from
2464 * the previous loop. If the 2 values are equal then
2465 * we should stop processing because the chance it
2466 * quite big that the device has been unplugged and
2467 * we risk going into an endless loop.
2468 */
2469 old_reg = 0;
2470
2471 while (1) {
2472 rt2x00pci_register_read(rt2x00dev, TX_STA_FIFO, &reg);
2473 if (!rt2x00_get_field32(reg, TX_STA_FIFO_VALID))
2474 break;
2475
2476 if (old_reg == reg)
2477 break;
2478 old_reg = reg;
2479
2480 /*
2481 * Skip this entry when it contains an invalid
2482 * queue identication number.
2483 */
2484 type = rt2x00_get_field32(reg, TX_STA_FIFO_PID_TYPE) - 1;
2485 if (type >= QID_RX)
2486 continue;
2487
2488 queue = rt2x00queue_get_queue(rt2x00dev, type);
2489 if (unlikely(!queue))
2490 continue;
2491
2492 /*
2493 * Skip this entry when it contains an invalid
2494 * index number.
2495 */
2496 index = rt2x00_get_field32(reg, TX_STA_FIFO_WCID) - 1;
2497 if (unlikely(index >= queue->limit))
2498 continue;
2499
2500 entry = &queue->entries[index];
2501 entry_priv = entry->priv_data;
2502 rt2x00_desc_read((__le32 *)entry->skb->data, 0, &word);
2503
2504 entry_done = rt2x00queue_get_entry(queue, Q_INDEX_DONE);
2505 while (entry != entry_done) {
2506 /*
2507 * Catch up.
2508 * Just report any entries we missed as failed.
2509 */
2510 WARNING(rt2x00dev,
2511 "TX status report missed for entry %d\n",
2512 entry_done->entry_idx);
2513
2514 txdesc.flags = 0;
2515 __set_bit(TXDONE_UNKNOWN, &txdesc.flags);
2516 txdesc.retry = 0;
2517
2518 rt2x00lib_txdone(entry_done, &txdesc);
2519 entry_done = rt2x00queue_get_entry(queue, Q_INDEX_DONE);
2520 }
2521
2522 /*
2523 * Obtain the status about this packet.
2524 */
2525 txdesc.flags = 0;
2526 if (rt2x00_get_field32(reg, TX_STA_FIFO_TX_SUCCESS))
2527 __set_bit(TXDONE_SUCCESS, &txdesc.flags);
2528 else
2529 __set_bit(TXDONE_FAILURE, &txdesc.flags);
2530
2531 /*
2532 * Ralink has a retry mechanism using a global fallback
2533 * table. We setup this fallback table to try immediate
2534 * lower rate for all rates. In the TX_STA_FIFO,
2535 * the MCS field contains the MCS used for the successfull
2536 * transmission. If the first transmission succeed,
2537 * we have mcs == tx_mcs. On the second transmission,
2538 * we have mcs = tx_mcs - 1. So the number of
2539 * retry is (tx_mcs - mcs).
2540 */
2541 mcs = rt2x00_get_field32(word, TXWI_W0_MCS);
2542 real_mcs = rt2x00_get_field32(reg, TX_STA_FIFO_MCS);
2543 __set_bit(TXDONE_FALLBACK, &txdesc.flags);
2544 txdesc.retry = mcs - min(mcs, real_mcs);
2545
2546 rt2x00lib_txdone(entry, &txdesc);
2547 }
2548}
2549
2550static irqreturn_t rt2800pci_interrupt(int irq, void *dev_instance)
2551{
2552 struct rt2x00_dev *rt2x00dev = dev_instance;
2553 u32 reg;
2554
2555 /* Read status and ACK all interrupts */
2556 rt2x00pci_register_read(rt2x00dev, INT_SOURCE_CSR, &reg);
2557 rt2x00pci_register_write(rt2x00dev, INT_SOURCE_CSR, reg);
2558
2559 if (!reg)
2560 return IRQ_NONE;
2561
2562 if (!test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
2563 return IRQ_HANDLED;
2564
2565 /*
2566 * 1 - Rx ring done interrupt.
2567 */
2568 if (rt2x00_get_field32(reg, INT_SOURCE_CSR_RX_DONE))
2569 rt2x00pci_rxdone(rt2x00dev);
2570
2571 if (rt2x00_get_field32(reg, INT_SOURCE_CSR_TX_FIFO_STATUS))
2572 rt2800pci_txdone(rt2x00dev);
2573
2574 return IRQ_HANDLED;
2575}
2576
2577/*
2578 * Device probe functions.
2579 */
2580static int rt2800pci_validate_eeprom(struct rt2x00_dev *rt2x00dev)
2581{
2582 u16 word;
2583 u8 *mac;
2584 u8 default_lna_gain;
2585
2586 /*
2587 * Read EEPROM into buffer
2588 */
2589 switch(rt2x00dev->chip.rt) {
2590 case RT2880:
2591 case RT3052:
2592 rt2800pci_read_eeprom_soc(rt2x00dev);
2593 break;
2594 case RT3090:
2595 rt2800pci_read_eeprom_efuse(rt2x00dev);
2596 break;
2597 default:
2598 rt2800pci_read_eeprom_pci(rt2x00dev);
2599 break;
2600 }
2601
2602 /*
2603 * Start validation of the data that has been read.
2604 */
2605 mac = rt2x00_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0);
2606 if (!is_valid_ether_addr(mac)) {
2607 random_ether_addr(mac);
2608 EEPROM(rt2x00dev, "MAC: %pM\n", mac);
2609 }
2610
2611 rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &word);
2612 if (word == 0xffff) {
2613 rt2x00_set_field16(&word, EEPROM_ANTENNA_RXPATH, 2);
2614 rt2x00_set_field16(&word, EEPROM_ANTENNA_TXPATH, 1);
2615 rt2x00_set_field16(&word, EEPROM_ANTENNA_RF_TYPE, RF2820);
2616 rt2x00_eeprom_write(rt2x00dev, EEPROM_ANTENNA, word);
2617 EEPROM(rt2x00dev, "Antenna: 0x%04x\n", word);
2618 } else if (rt2x00_rev(&rt2x00dev->chip) < RT2883_VERSION) {
2619 /*
2620 * There is a max of 2 RX streams for RT2860 series
2621 */
2622 if (rt2x00_get_field16(word, EEPROM_ANTENNA_RXPATH) > 2)
2623 rt2x00_set_field16(&word, EEPROM_ANTENNA_RXPATH, 2);
2624 rt2x00_eeprom_write(rt2x00dev, EEPROM_ANTENNA, word);
2625 }
2626
2627 rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &word);
2628 if (word == 0xffff) {
2629 rt2x00_set_field16(&word, EEPROM_NIC_HW_RADIO, 0);
2630 rt2x00_set_field16(&word, EEPROM_NIC_DYNAMIC_TX_AGC, 0);
2631 rt2x00_set_field16(&word, EEPROM_NIC_EXTERNAL_LNA_BG, 0);
2632 rt2x00_set_field16(&word, EEPROM_NIC_EXTERNAL_LNA_A, 0);
2633 rt2x00_set_field16(&word, EEPROM_NIC_CARDBUS_ACCEL, 0);
2634 rt2x00_set_field16(&word, EEPROM_NIC_BW40M_SB_BG, 0);
2635 rt2x00_set_field16(&word, EEPROM_NIC_BW40M_SB_A, 0);
2636 rt2x00_set_field16(&word, EEPROM_NIC_WPS_PBC, 0);
2637 rt2x00_set_field16(&word, EEPROM_NIC_BW40M_BG, 0);
2638 rt2x00_set_field16(&word, EEPROM_NIC_BW40M_A, 0);
2639 rt2x00_eeprom_write(rt2x00dev, EEPROM_NIC, word);
2640 EEPROM(rt2x00dev, "NIC: 0x%04x\n", word);
2641 }
2642
2643 rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &word);
2644 if ((word & 0x00ff) == 0x00ff) {
2645 rt2x00_set_field16(&word, EEPROM_FREQ_OFFSET, 0);
2646 rt2x00_set_field16(&word, EEPROM_FREQ_LED_MODE,
2647 LED_MODE_TXRX_ACTIVITY);
2648 rt2x00_set_field16(&word, EEPROM_FREQ_LED_POLARITY, 0);
2649 rt2x00_eeprom_write(rt2x00dev, EEPROM_FREQ, word);
2650 rt2x00_eeprom_write(rt2x00dev, EEPROM_LED1, 0x5555);
2651 rt2x00_eeprom_write(rt2x00dev, EEPROM_LED2, 0x2221);
2652 rt2x00_eeprom_write(rt2x00dev, EEPROM_LED3, 0xa9f8);
2653 EEPROM(rt2x00dev, "Freq: 0x%04x\n", word);
2654 }
2655
2656 /*
2657 * During the LNA validation we are going to use
2658 * lna0 as correct value. Note that EEPROM_LNA
2659 * is never validated.
2660 */
2661 rt2x00_eeprom_read(rt2x00dev, EEPROM_LNA, &word);
2662 default_lna_gain = rt2x00_get_field16(word, EEPROM_LNA_A0);
2663
2664 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_BG, &word);
2665 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG_OFFSET0)) > 10)
2666 rt2x00_set_field16(&word, EEPROM_RSSI_BG_OFFSET0, 0);
2667 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG_OFFSET1)) > 10)
2668 rt2x00_set_field16(&word, EEPROM_RSSI_BG_OFFSET1, 0);
2669 rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_BG, word);
2670
2671 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_BG2, &word);
2672 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG2_OFFSET2)) > 10)
2673 rt2x00_set_field16(&word, EEPROM_RSSI_BG2_OFFSET2, 0);
2674 if (rt2x00_get_field16(word, EEPROM_RSSI_BG2_LNA_A1) == 0x00 ||
2675 rt2x00_get_field16(word, EEPROM_RSSI_BG2_LNA_A1) == 0xff)
2676 rt2x00_set_field16(&word, EEPROM_RSSI_BG2_LNA_A1,
2677 default_lna_gain);
2678 rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_BG2, word);
2679
2680 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_A, &word);
2681 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A_OFFSET0)) > 10)
2682 rt2x00_set_field16(&word, EEPROM_RSSI_A_OFFSET0, 0);
2683 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A_OFFSET1)) > 10)
2684 rt2x00_set_field16(&word, EEPROM_RSSI_A_OFFSET1, 0);
2685 rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_A, word);
2686
2687 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_A2, &word);
2688 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A2_OFFSET2)) > 10)
2689 rt2x00_set_field16(&word, EEPROM_RSSI_A2_OFFSET2, 0);
2690 if (rt2x00_get_field16(word, EEPROM_RSSI_A2_LNA_A2) == 0x00 ||
2691 rt2x00_get_field16(word, EEPROM_RSSI_A2_LNA_A2) == 0xff)
2692 rt2x00_set_field16(&word, EEPROM_RSSI_A2_LNA_A2,
2693 default_lna_gain);
2694 rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_A2, word);
2695
2696 return 0;
2697}
2698
2699static int rt2800pci_init_eeprom(struct rt2x00_dev *rt2x00dev)
2700{
2701 u32 reg;
2702 u16 value;
2703 u16 eeprom;
2704
2705 /*
2706 * Read EEPROM word for configuration.
2707 */
2708 rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &eeprom);
2709
2710 /*
2711 * Identify RF chipset.
2712 */
2713 value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RF_TYPE);
2714 rt2x00pci_register_read(rt2x00dev, MAC_CSR0, &reg);
2715 rt2x00_set_chip_rf(rt2x00dev, value, reg);
2716
2717 if (!rt2x00_rf(&rt2x00dev->chip, RF2820) &&
2718 !rt2x00_rf(&rt2x00dev->chip, RF2850) &&
2719 !rt2x00_rf(&rt2x00dev->chip, RF2720) &&
2720 !rt2x00_rf(&rt2x00dev->chip, RF2750) &&
2721 !rt2x00_rf(&rt2x00dev->chip, RF3020) &&
2722 !rt2x00_rf(&rt2x00dev->chip, RF2020) &&
2723 !rt2x00_rf(&rt2x00dev->chip, RF3021) &&
2724 !rt2x00_rf(&rt2x00dev->chip, RF3022)) {
2725 ERROR(rt2x00dev, "Invalid RF chipset detected.\n");
2726 return -ENODEV;
2727 }
2728
2729 /*
2730 * Identify default antenna configuration.
2731 */
2732 rt2x00dev->default_ant.tx =
2733 rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TXPATH);
2734 rt2x00dev->default_ant.rx =
2735 rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RXPATH);
2736
2737 /*
2738 * Read frequency offset and RF programming sequence.
2739 */
2740 rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &eeprom);
2741 rt2x00dev->freq_offset = rt2x00_get_field16(eeprom, EEPROM_FREQ_OFFSET);
2742
2743 /*
2744 * Read external LNA informations.
2745 */
2746 rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &eeprom);
2747
2748 if (rt2x00_get_field16(eeprom, EEPROM_NIC_EXTERNAL_LNA_A))
2749 __set_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags);
2750 if (rt2x00_get_field16(eeprom, EEPROM_NIC_EXTERNAL_LNA_BG))
2751 __set_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags);
2752
2753 /*
2754 * Detect if this device has an hardware controlled radio.
2755 */
2756 if (rt2x00_get_field16(eeprom, EEPROM_NIC_HW_RADIO))
2757 __set_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags);
2758
2759 /*
2760 * Store led settings, for correct led behaviour.
2761 */
2762#ifdef CONFIG_RT2X00_LIB_LEDS
2763 rt2800pci_init_led(rt2x00dev, &rt2x00dev->led_radio, LED_TYPE_RADIO);
2764 rt2800pci_init_led(rt2x00dev, &rt2x00dev->led_assoc, LED_TYPE_ASSOC);
2765 rt2800pci_init_led(rt2x00dev, &rt2x00dev->led_qual, LED_TYPE_QUALITY);
2766
2767 rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &rt2x00dev->led_mcu_reg);
2768#endif /* CONFIG_RT2X00_LIB_LEDS */
2769
2770 return 0;
2771}
2772
2773/*
2774 * RF value list for rt2860
2775 * Supports: 2.4 GHz (all) & 5.2 GHz (RF2850 & RF2750)
2776 */
2777static const struct rf_channel rf_vals[] = {
2778 { 1, 0x18402ecc, 0x184c0786, 0x1816b455, 0x1800510b },
2779 { 2, 0x18402ecc, 0x184c0786, 0x18168a55, 0x1800519f },
2780 { 3, 0x18402ecc, 0x184c078a, 0x18168a55, 0x1800518b },
2781 { 4, 0x18402ecc, 0x184c078a, 0x18168a55, 0x1800519f },
2782 { 5, 0x18402ecc, 0x184c078e, 0x18168a55, 0x1800518b },
2783 { 6, 0x18402ecc, 0x184c078e, 0x18168a55, 0x1800519f },
2784 { 7, 0x18402ecc, 0x184c0792, 0x18168a55, 0x1800518b },
2785 { 8, 0x18402ecc, 0x184c0792, 0x18168a55, 0x1800519f },
2786 { 9, 0x18402ecc, 0x184c0796, 0x18168a55, 0x1800518b },
2787 { 10, 0x18402ecc, 0x184c0796, 0x18168a55, 0x1800519f },
2788 { 11, 0x18402ecc, 0x184c079a, 0x18168a55, 0x1800518b },
2789 { 12, 0x18402ecc, 0x184c079a, 0x18168a55, 0x1800519f },
2790 { 13, 0x18402ecc, 0x184c079e, 0x18168a55, 0x1800518b },
2791 { 14, 0x18402ecc, 0x184c07a2, 0x18168a55, 0x18005193 },
2792
2793 /* 802.11 UNI / HyperLan 2 */
2794 { 36, 0x18402ecc, 0x184c099a, 0x18158a55, 0x180ed1a3 },
2795 { 38, 0x18402ecc, 0x184c099e, 0x18158a55, 0x180ed193 },
2796 { 40, 0x18402ec8, 0x184c0682, 0x18158a55, 0x180ed183 },
2797 { 44, 0x18402ec8, 0x184c0682, 0x18158a55, 0x180ed1a3 },
2798 { 46, 0x18402ec8, 0x184c0686, 0x18158a55, 0x180ed18b },
2799 { 48, 0x18402ec8, 0x184c0686, 0x18158a55, 0x180ed19b },
2800 { 52, 0x18402ec8, 0x184c068a, 0x18158a55, 0x180ed193 },
2801 { 54, 0x18402ec8, 0x184c068a, 0x18158a55, 0x180ed1a3 },
2802 { 56, 0x18402ec8, 0x184c068e, 0x18158a55, 0x180ed18b },
2803 { 60, 0x18402ec8, 0x184c0692, 0x18158a55, 0x180ed183 },
2804 { 62, 0x18402ec8, 0x184c0692, 0x18158a55, 0x180ed193 },
2805 { 64, 0x18402ec8, 0x184c0692, 0x18158a55, 0x180ed1a3 },
2806
2807 /* 802.11 HyperLan 2 */
2808 { 100, 0x18402ec8, 0x184c06b2, 0x18178a55, 0x180ed783 },
2809 { 102, 0x18402ec8, 0x184c06b2, 0x18578a55, 0x180ed793 },
2810 { 104, 0x18402ec8, 0x185c06b2, 0x18578a55, 0x180ed1a3 },
2811 { 108, 0x18402ecc, 0x185c0a32, 0x18578a55, 0x180ed193 },
2812 { 110, 0x18402ecc, 0x184c0a36, 0x18178a55, 0x180ed183 },
2813 { 112, 0x18402ecc, 0x184c0a36, 0x18178a55, 0x180ed19b },
2814 { 116, 0x18402ecc, 0x184c0a3a, 0x18178a55, 0x180ed1a3 },
2815 { 118, 0x18402ecc, 0x184c0a3e, 0x18178a55, 0x180ed193 },
2816 { 120, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed183 },
2817 { 124, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed193 },
2818 { 126, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed15b },
2819 { 128, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed1a3 },
2820 { 132, 0x18402ec4, 0x184c0386, 0x18178a55, 0x180ed18b },
2821 { 134, 0x18402ec4, 0x184c0386, 0x18178a55, 0x180ed193 },
2822 { 136, 0x18402ec4, 0x184c0386, 0x18178a55, 0x180ed19b },
2823 { 140, 0x18402ec4, 0x184c038a, 0x18178a55, 0x180ed183 },
2824
2825 /* 802.11 UNII */
2826 { 149, 0x18402ec4, 0x184c038a, 0x18178a55, 0x180ed1a7 },
2827 { 151, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed187 },
2828 { 153, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed18f },
2829 { 157, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed19f },
2830 { 159, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed1a7 },
2831 { 161, 0x18402ec4, 0x184c0392, 0x18178a55, 0x180ed187 },
2832 { 165, 0x18402ec4, 0x184c0392, 0x18178a55, 0x180ed197 },
2833
2834 /* 802.11 Japan */
2835 { 184, 0x15002ccc, 0x1500491e, 0x1509be55, 0x150c0a0b },
2836 { 188, 0x15002ccc, 0x15004922, 0x1509be55, 0x150c0a13 },
2837 { 192, 0x15002ccc, 0x15004926, 0x1509be55, 0x150c0a1b },
2838 { 196, 0x15002ccc, 0x1500492a, 0x1509be55, 0x150c0a23 },
2839 { 208, 0x15002ccc, 0x1500493a, 0x1509be55, 0x150c0a13 },
2840 { 212, 0x15002ccc, 0x1500493e, 0x1509be55, 0x150c0a1b },
2841 { 216, 0x15002ccc, 0x15004982, 0x1509be55, 0x150c0a23 },
2842};
2843
2844static int rt2800pci_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
2845{
2846 struct hw_mode_spec *spec = &rt2x00dev->spec;
2847 struct channel_info *info;
2848 char *tx_power1;
2849 char *tx_power2;
2850 unsigned int i;
2851 u16 eeprom;
2852
2853 /*
2854 * Initialize all hw fields.
2855 */
2856 rt2x00dev->hw->flags =
2857 IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
2858 IEEE80211_HW_SIGNAL_DBM |
2859 IEEE80211_HW_SUPPORTS_PS |
2860 IEEE80211_HW_PS_NULLFUNC_STACK;
2861 rt2x00dev->hw->extra_tx_headroom = TXWI_DESC_SIZE;
2862
2863 SET_IEEE80211_DEV(rt2x00dev->hw, rt2x00dev->dev);
2864 SET_IEEE80211_PERM_ADDR(rt2x00dev->hw,
2865 rt2x00_eeprom_addr(rt2x00dev,
2866 EEPROM_MAC_ADDR_0));
2867
2868 rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &eeprom);
2869
2870 /*
2871 * Initialize hw_mode information.
2872 */
2873 spec->supported_bands = SUPPORT_BAND_2GHZ;
2874 spec->supported_rates = SUPPORT_RATE_CCK | SUPPORT_RATE_OFDM;
2875
2876 if (rt2x00_rf(&rt2x00dev->chip, RF2820) ||
2877 rt2x00_rf(&rt2x00dev->chip, RF2720) ||
2878 rt2x00_rf(&rt2x00dev->chip, RF3020) ||
2879 rt2x00_rf(&rt2x00dev->chip, RF3021) ||
2880 rt2x00_rf(&rt2x00dev->chip, RF3022) ||
2881 rt2x00_rf(&rt2x00dev->chip, RF2020) ||
2882 rt2x00_rf(&rt2x00dev->chip, RF3052)) {
2883 spec->num_channels = 14;
2884 spec->channels = rf_vals;
2885 } else if (rt2x00_rf(&rt2x00dev->chip, RF2850) ||
2886 rt2x00_rf(&rt2x00dev->chip, RF2750)) {
2887 spec->supported_bands |= SUPPORT_BAND_5GHZ;
2888 spec->num_channels = ARRAY_SIZE(rf_vals);
2889 spec->channels = rf_vals;
2890 }
2891
2892 /*
2893 * Initialize HT information.
2894 */
2895 spec->ht.ht_supported = true;
2896 spec->ht.cap =
2897 IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
2898 IEEE80211_HT_CAP_GRN_FLD |
2899 IEEE80211_HT_CAP_SGI_20 |
2900 IEEE80211_HT_CAP_SGI_40 |
2901 IEEE80211_HT_CAP_TX_STBC |
2902 IEEE80211_HT_CAP_RX_STBC |
2903 IEEE80211_HT_CAP_PSMP_SUPPORT;
2904 spec->ht.ampdu_factor = 3;
2905 spec->ht.ampdu_density = 4;
2906 spec->ht.mcs.tx_params =
2907 IEEE80211_HT_MCS_TX_DEFINED |
2908 IEEE80211_HT_MCS_TX_RX_DIFF |
2909 ((rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TXPATH) - 1) <<
2910 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT);
2911
2912 switch (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RXPATH)) {
2913 case 3:
2914 spec->ht.mcs.rx_mask[2] = 0xff;
2915 case 2:
2916 spec->ht.mcs.rx_mask[1] = 0xff;
2917 case 1:
2918 spec->ht.mcs.rx_mask[0] = 0xff;
2919 spec->ht.mcs.rx_mask[4] = 0x1; /* MCS32 */
2920 break;
2921 }
2922
2923 /*
2924 * Create channel information array
2925 */
2926 info = kzalloc(spec->num_channels * sizeof(*info), GFP_KERNEL);
2927 if (!info)
2928 return -ENOMEM;
2929
2930 spec->channels_info = info;
2931
2932 tx_power1 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_BG1);
2933 tx_power2 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_BG2);
2934
2935 for (i = 0; i < 14; i++) {
2936 info[i].tx_power1 = TXPOWER_G_FROM_DEV(tx_power1[i]);
2937 info[i].tx_power2 = TXPOWER_G_FROM_DEV(tx_power2[i]);
2938 }
2939
2940 if (spec->num_channels > 14) {
2941 tx_power1 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_A1);
2942 tx_power2 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_A2);
2943
2944 for (i = 14; i < spec->num_channels; i++) {
2945 info[i].tx_power1 = TXPOWER_A_FROM_DEV(tx_power1[i]);
2946 info[i].tx_power2 = TXPOWER_A_FROM_DEV(tx_power2[i]);
2947 }
2948 }
2949
2950 return 0;
2951}
2952
2953static int rt2800pci_probe_hw(struct rt2x00_dev *rt2x00dev)
2954{
2955 int retval;
2956
2957 /*
2958 * Allocate eeprom data.
2959 */
2960 retval = rt2800pci_validate_eeprom(rt2x00dev);
2961 if (retval)
2962 return retval;
2963
2964 retval = rt2800pci_init_eeprom(rt2x00dev);
2965 if (retval)
2966 return retval;
2967
2968 /*
2969 * Initialize hw specifications.
2970 */
2971 retval = rt2800pci_probe_hw_mode(rt2x00dev);
2972 if (retval)
2973 return retval;
2974
2975 /*
2976 * This device has multiple filters for control frames
2977 * and has a separate filter for PS Poll frames.
2978 */
2979 __set_bit(DRIVER_SUPPORT_CONTROL_FILTERS, &rt2x00dev->flags);
2980 __set_bit(DRIVER_SUPPORT_CONTROL_FILTER_PSPOLL, &rt2x00dev->flags);
2981
2982 /*
2983 * This device requires firmware.
2984 */
2985 if (!rt2x00_rt(&rt2x00dev->chip, RT2880) &&
2986 !rt2x00_rt(&rt2x00dev->chip, RT3052))
2987 __set_bit(DRIVER_REQUIRE_FIRMWARE, &rt2x00dev->flags);
2988 __set_bit(DRIVER_REQUIRE_DMA, &rt2x00dev->flags);
2989 __set_bit(DRIVER_REQUIRE_L2PAD, &rt2x00dev->flags);
2990 if (!modparam_nohwcrypt)
2991 __set_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags);
2992
2993 /*
2994 * Set the rssi offset.
2995 */
2996 rt2x00dev->rssi_offset = DEFAULT_RSSI_OFFSET;
2997
2998 return 0;
2999}
3000
3001/*
3002 * IEEE80211 stack callback functions.
3003 */
3004static void rt2800pci_get_tkip_seq(struct ieee80211_hw *hw, u8 hw_key_idx,
3005 u32 *iv32, u16 *iv16)
3006{
3007 struct rt2x00_dev *rt2x00dev = hw->priv;
3008 struct mac_iveiv_entry iveiv_entry;
3009 u32 offset;
3010
3011 offset = MAC_IVEIV_ENTRY(hw_key_idx);
3012 rt2x00pci_register_multiread(rt2x00dev, offset,
3013 &iveiv_entry, sizeof(iveiv_entry));
3014
3015 memcpy(&iveiv_entry.iv[0], iv16, sizeof(iv16));
3016 memcpy(&iveiv_entry.iv[4], iv32, sizeof(iv32));
3017}
3018
3019static int rt2800pci_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3020{
3021 struct rt2x00_dev *rt2x00dev = hw->priv;
3022 u32 reg;
3023 bool enabled = (value < IEEE80211_MAX_RTS_THRESHOLD);
3024
3025 rt2x00pci_register_read(rt2x00dev, TX_RTS_CFG, &reg);
3026 rt2x00_set_field32(&reg, TX_RTS_CFG_RTS_THRES, value);
3027 rt2x00pci_register_write(rt2x00dev, TX_RTS_CFG, reg);
3028
3029 rt2x00pci_register_read(rt2x00dev, CCK_PROT_CFG, &reg);
3030 rt2x00_set_field32(&reg, CCK_PROT_CFG_RTS_TH_EN, enabled);
3031 rt2x00pci_register_write(rt2x00dev, CCK_PROT_CFG, reg);
3032
3033 rt2x00pci_register_read(rt2x00dev, OFDM_PROT_CFG, &reg);
3034 rt2x00_set_field32(&reg, OFDM_PROT_CFG_RTS_TH_EN, enabled);
3035 rt2x00pci_register_write(rt2x00dev, OFDM_PROT_CFG, reg);
3036
3037 rt2x00pci_register_read(rt2x00dev, MM20_PROT_CFG, &reg);
3038 rt2x00_set_field32(&reg, MM20_PROT_CFG_RTS_TH_EN, enabled);
3039 rt2x00pci_register_write(rt2x00dev, MM20_PROT_CFG, reg);
3040
3041 rt2x00pci_register_read(rt2x00dev, MM40_PROT_CFG, &reg);
3042 rt2x00_set_field32(&reg, MM40_PROT_CFG_RTS_TH_EN, enabled);
3043 rt2x00pci_register_write(rt2x00dev, MM40_PROT_CFG, reg);
3044
3045 rt2x00pci_register_read(rt2x00dev, GF20_PROT_CFG, &reg);
3046 rt2x00_set_field32(&reg, GF20_PROT_CFG_RTS_TH_EN, enabled);
3047 rt2x00pci_register_write(rt2x00dev, GF20_PROT_CFG, reg);
3048
3049 rt2x00pci_register_read(rt2x00dev, GF40_PROT_CFG, &reg);
3050 rt2x00_set_field32(&reg, GF40_PROT_CFG_RTS_TH_EN, enabled);
3051 rt2x00pci_register_write(rt2x00dev, GF40_PROT_CFG, reg);
3052
3053 return 0;
3054}
3055
3056static int rt2800pci_conf_tx(struct ieee80211_hw *hw, u16 queue_idx,
3057 const struct ieee80211_tx_queue_params *params)
3058{
3059 struct rt2x00_dev *rt2x00dev = hw->priv;
3060 struct data_queue *queue;
3061 struct rt2x00_field32 field;
3062 int retval;
3063 u32 reg;
3064 u32 offset;
3065
3066 /*
3067 * First pass the configuration through rt2x00lib, that will
3068 * update the queue settings and validate the input. After that
3069 * we are free to update the registers based on the value
3070 * in the queue parameter.
3071 */
3072 retval = rt2x00mac_conf_tx(hw, queue_idx, params);
3073 if (retval)
3074 return retval;
3075
3076 /*
3077 * We only need to perform additional register initialization
3078 * for WMM queues/
3079 */
3080 if (queue_idx >= 4)
3081 return 0;
3082
3083 queue = rt2x00queue_get_queue(rt2x00dev, queue_idx);
3084
3085 /* Update WMM TXOP register */
3086 offset = WMM_TXOP0_CFG + (sizeof(u32) * (!!(queue_idx & 2)));
3087 field.bit_offset = (queue_idx & 1) * 16;
3088 field.bit_mask = 0xffff << field.bit_offset;
3089
3090 rt2x00pci_register_read(rt2x00dev, offset, &reg);
3091 rt2x00_set_field32(&reg, field, queue->txop);
3092 rt2x00pci_register_write(rt2x00dev, offset, reg);
3093
3094 /* Update WMM registers */
3095 field.bit_offset = queue_idx * 4;
3096 field.bit_mask = 0xf << field.bit_offset;
3097
3098 rt2x00pci_register_read(rt2x00dev, WMM_AIFSN_CFG, &reg);
3099 rt2x00_set_field32(&reg, field, queue->aifs);
3100 rt2x00pci_register_write(rt2x00dev, WMM_AIFSN_CFG, reg);
3101
3102 rt2x00pci_register_read(rt2x00dev, WMM_CWMIN_CFG, &reg);
3103 rt2x00_set_field32(&reg, field, queue->cw_min);
3104 rt2x00pci_register_write(rt2x00dev, WMM_CWMIN_CFG, reg);
3105
3106 rt2x00pci_register_read(rt2x00dev, WMM_CWMAX_CFG, &reg);
3107 rt2x00_set_field32(&reg, field, queue->cw_max);
3108 rt2x00pci_register_write(rt2x00dev, WMM_CWMAX_CFG, reg);
3109
3110 /* Update EDCA registers */
3111 offset = EDCA_AC0_CFG + (sizeof(u32) * queue_idx);
3112
3113 rt2x00pci_register_read(rt2x00dev, offset, &reg);
3114 rt2x00_set_field32(&reg, EDCA_AC0_CFG_TX_OP, queue->txop);
3115 rt2x00_set_field32(&reg, EDCA_AC0_CFG_AIFSN, queue->aifs);
3116 rt2x00_set_field32(&reg, EDCA_AC0_CFG_CWMIN, queue->cw_min);
3117 rt2x00_set_field32(&reg, EDCA_AC0_CFG_CWMAX, queue->cw_max);
3118 rt2x00pci_register_write(rt2x00dev, offset, reg);
3119
3120 return 0;
3121}
3122
3123static u64 rt2800pci_get_tsf(struct ieee80211_hw *hw)
3124{
3125 struct rt2x00_dev *rt2x00dev = hw->priv;
3126 u64 tsf;
3127 u32 reg;
3128
3129 rt2x00pci_register_read(rt2x00dev, TSF_TIMER_DW1, &reg);
3130 tsf = (u64) rt2x00_get_field32(reg, TSF_TIMER_DW1_HIGH_WORD) << 32;
3131 rt2x00pci_register_read(rt2x00dev, TSF_TIMER_DW0, &reg);
3132 tsf |= rt2x00_get_field32(reg, TSF_TIMER_DW0_LOW_WORD);
3133
3134 return tsf;
3135}
3136
3137static const struct ieee80211_ops rt2800pci_mac80211_ops = {
3138 .tx = rt2x00mac_tx,
3139 .start = rt2x00mac_start,
3140 .stop = rt2x00mac_stop,
3141 .add_interface = rt2x00mac_add_interface,
3142 .remove_interface = rt2x00mac_remove_interface,
3143 .config = rt2x00mac_config,
3144 .configure_filter = rt2x00mac_configure_filter,
3145 .set_key = rt2x00mac_set_key,
3146 .get_stats = rt2x00mac_get_stats,
3147 .get_tkip_seq = rt2800pci_get_tkip_seq,
3148 .set_rts_threshold = rt2800pci_set_rts_threshold,
3149 .bss_info_changed = rt2x00mac_bss_info_changed,
3150 .conf_tx = rt2800pci_conf_tx,
3151 .get_tx_stats = rt2x00mac_get_tx_stats,
3152 .get_tsf = rt2800pci_get_tsf,
3153 .rfkill_poll = rt2x00mac_rfkill_poll,
3154};
3155
3156static const struct rt2x00lib_ops rt2800pci_rt2x00_ops = {
3157 .irq_handler = rt2800pci_interrupt,
3158 .probe_hw = rt2800pci_probe_hw,
3159 .get_firmware_name = rt2800pci_get_firmware_name,
3160 .check_firmware = rt2800pci_check_firmware,
3161 .load_firmware = rt2800pci_load_firmware,
3162 .initialize = rt2x00pci_initialize,
3163 .uninitialize = rt2x00pci_uninitialize,
3164 .get_entry_state = rt2800pci_get_entry_state,
3165 .clear_entry = rt2800pci_clear_entry,
3166 .set_device_state = rt2800pci_set_device_state,
3167 .rfkill_poll = rt2800pci_rfkill_poll,
3168 .link_stats = rt2800pci_link_stats,
3169 .reset_tuner = rt2800pci_reset_tuner,
3170 .link_tuner = rt2800pci_link_tuner,
3171 .write_tx_desc = rt2800pci_write_tx_desc,
3172 .write_tx_data = rt2x00pci_write_tx_data,
3173 .write_beacon = rt2800pci_write_beacon,
3174 .kick_tx_queue = rt2800pci_kick_tx_queue,
3175 .kill_tx_queue = rt2800pci_kill_tx_queue,
3176 .fill_rxdone = rt2800pci_fill_rxdone,
3177 .config_shared_key = rt2800pci_config_shared_key,
3178 .config_pairwise_key = rt2800pci_config_pairwise_key,
3179 .config_filter = rt2800pci_config_filter,
3180 .config_intf = rt2800pci_config_intf,
3181 .config_erp = rt2800pci_config_erp,
3182 .config_ant = rt2800pci_config_ant,
3183 .config = rt2800pci_config,
3184};
3185
3186static const struct data_queue_desc rt2800pci_queue_rx = {
3187 .entry_num = RX_ENTRIES,
3188 .data_size = AGGREGATION_SIZE,
3189 .desc_size = RXD_DESC_SIZE,
3190 .priv_size = sizeof(struct queue_entry_priv_pci),
3191};
3192
3193static const struct data_queue_desc rt2800pci_queue_tx = {
3194 .entry_num = TX_ENTRIES,
3195 .data_size = AGGREGATION_SIZE,
3196 .desc_size = TXD_DESC_SIZE,
3197 .priv_size = sizeof(struct queue_entry_priv_pci),
3198};
3199
3200static const struct data_queue_desc rt2800pci_queue_bcn = {
3201 .entry_num = 8 * BEACON_ENTRIES,
3202 .data_size = 0, /* No DMA required for beacons */
3203 .desc_size = TXWI_DESC_SIZE,
3204 .priv_size = sizeof(struct queue_entry_priv_pci),
3205};
3206
3207static const struct rt2x00_ops rt2800pci_ops = {
3208 .name = KBUILD_MODNAME,
3209 .max_sta_intf = 1,
3210 .max_ap_intf = 8,
3211 .eeprom_size = EEPROM_SIZE,
3212 .rf_size = RF_SIZE,
3213 .tx_queues = NUM_TX_QUEUES,
3214 .rx = &rt2800pci_queue_rx,
3215 .tx = &rt2800pci_queue_tx,
3216 .bcn = &rt2800pci_queue_bcn,
3217 .lib = &rt2800pci_rt2x00_ops,
3218 .hw = &rt2800pci_mac80211_ops,
3219#ifdef CONFIG_RT2X00_LIB_DEBUGFS
3220 .debugfs = &rt2800pci_rt2x00debug,
3221#endif /* CONFIG_RT2X00_LIB_DEBUGFS */
3222};
3223
3224/*
3225 * RT2800pci module information.
3226 */
3227static struct pci_device_id rt2800pci_device_table[] = {
3228 { PCI_DEVICE(0x1462, 0x891a), PCI_DEVICE_DATA(&rt2800pci_ops) },
3229 { PCI_DEVICE(0x1432, 0x7708), PCI_DEVICE_DATA(&rt2800pci_ops) },
3230 { PCI_DEVICE(0x1432, 0x7727), PCI_DEVICE_DATA(&rt2800pci_ops) },
3231 { PCI_DEVICE(0x1432, 0x7728), PCI_DEVICE_DATA(&rt2800pci_ops) },
3232 { PCI_DEVICE(0x1432, 0x7738), PCI_DEVICE_DATA(&rt2800pci_ops) },
3233 { PCI_DEVICE(0x1432, 0x7748), PCI_DEVICE_DATA(&rt2800pci_ops) },
3234 { PCI_DEVICE(0x1432, 0x7758), PCI_DEVICE_DATA(&rt2800pci_ops) },
3235 { PCI_DEVICE(0x1432, 0x7768), PCI_DEVICE_DATA(&rt2800pci_ops) },
3236 { PCI_DEVICE(0x1814, 0x0601), PCI_DEVICE_DATA(&rt2800pci_ops) },
3237 { PCI_DEVICE(0x1814, 0x0681), PCI_DEVICE_DATA(&rt2800pci_ops) },
3238 { PCI_DEVICE(0x1814, 0x0701), PCI_DEVICE_DATA(&rt2800pci_ops) },
3239 { PCI_DEVICE(0x1814, 0x0781), PCI_DEVICE_DATA(&rt2800pci_ops) },
3240 { PCI_DEVICE(0x1814, 0x3060), PCI_DEVICE_DATA(&rt2800pci_ops) },
3241 { PCI_DEVICE(0x1814, 0x3062), PCI_DEVICE_DATA(&rt2800pci_ops) },
3242 { PCI_DEVICE(0x1814, 0x3090), PCI_DEVICE_DATA(&rt2800pci_ops) },
3243 { PCI_DEVICE(0x1814, 0x3091), PCI_DEVICE_DATA(&rt2800pci_ops) },
3244 { PCI_DEVICE(0x1814, 0x3092), PCI_DEVICE_DATA(&rt2800pci_ops) },
3245 { PCI_DEVICE(0x1814, 0x3562), PCI_DEVICE_DATA(&rt2800pci_ops) },
3246 { PCI_DEVICE(0x1814, 0x3592), PCI_DEVICE_DATA(&rt2800pci_ops) },
3247 { PCI_DEVICE(0x1a3b, 0x1059), PCI_DEVICE_DATA(&rt2800pci_ops) },
3248 { 0, }
3249};
3250
3251MODULE_AUTHOR(DRV_PROJECT);
3252MODULE_VERSION(DRV_VERSION);
3253MODULE_DESCRIPTION("Ralink RT2800 PCI & PCMCIA Wireless LAN driver.");
3254MODULE_SUPPORTED_DEVICE("Ralink RT2860 PCI & PCMCIA chipset based cards");
3255#ifdef CONFIG_RT2800PCI_PCI
3256MODULE_FIRMWARE(FIRMWARE_RT2860);
3257MODULE_DEVICE_TABLE(pci, rt2800pci_device_table);
3258#endif /* CONFIG_RT2800PCI_PCI */
3259MODULE_LICENSE("GPL");
3260
3261#ifdef CONFIG_RT2800PCI_WISOC
3262#if defined(CONFIG_RALINK_RT288X)
3263__rt2x00soc_probe(RT2880, &rt2800pci_ops);
3264#elif defined(CONFIG_RALINK_RT305X)
3265__rt2x00soc_probe(RT3052, &rt2800pci_ops);
3266#endif
3267
3268static struct platform_driver rt2800soc_driver = {
3269 .driver = {
3270 .name = "rt2800_wmac",
3271 .owner = THIS_MODULE,
3272 .mod_name = KBUILD_MODNAME,
3273 },
3274 .probe = __rt2x00soc_probe,
3275 .remove = __devexit_p(rt2x00soc_remove),
3276 .suspend = rt2x00soc_suspend,
3277 .resume = rt2x00soc_resume,
3278};
3279#endif /* CONFIG_RT2800PCI_WISOC */
3280
3281#ifdef CONFIG_RT2800PCI_PCI
3282static struct pci_driver rt2800pci_driver = {
3283 .name = KBUILD_MODNAME,
3284 .id_table = rt2800pci_device_table,
3285 .probe = rt2x00pci_probe,
3286 .remove = __devexit_p(rt2x00pci_remove),
3287 .suspend = rt2x00pci_suspend,
3288 .resume = rt2x00pci_resume,
3289};
3290#endif /* CONFIG_RT2800PCI_PCI */
3291
3292static int __init rt2800pci_init(void)
3293{
3294 int ret = 0;
3295
3296#ifdef CONFIG_RT2800PCI_WISOC
3297 ret = platform_driver_register(&rt2800soc_driver);
3298 if (ret)
3299 return ret;
3300#endif
3301#ifdef CONFIG_RT2800PCI_PCI
3302 ret = pci_register_driver(&rt2800pci_driver);
3303 if (ret) {
3304#ifdef CONFIG_RT2800PCI_WISOC
3305 platform_driver_unregister(&rt2800soc_driver);
3306#endif
3307 return ret;
3308 }
3309#endif
3310
3311 return ret;
3312}
3313
3314static void __exit rt2800pci_exit(void)
3315{
3316#ifdef CONFIG_RT2800PCI_PCI
3317 pci_unregister_driver(&rt2800pci_driver);
3318#endif
3319#ifdef CONFIG_RT2800PCI_WISOC
3320 platform_driver_unregister(&rt2800soc_driver);
3321#endif
3322}
3323
3324module_init(rt2800pci_init);
3325module_exit(rt2800pci_exit);