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