Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 1 | /* |
| 2 | Copyright (C) 2004 - 2009 rt2x00 SourceForge Project |
| 3 | <http://rt2x00.serialmonkey.com> |
| 4 | |
| 5 | This program is free software; you can redistribute it and/or modify |
| 6 | it under the terms of the GNU General Public License as published by |
| 7 | the Free Software Foundation; either version 2 of the License, or |
| 8 | (at your option) any later version. |
| 9 | |
| 10 | This program is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | GNU General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License |
| 16 | along with this program; if not, write to the |
| 17 | Free Software Foundation, Inc., |
| 18 | 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 19 | */ |
| 20 | |
| 21 | /* |
| 22 | Module: rt2800pci |
| 23 | Abstract: rt2800pci device specific routines. |
| 24 | Supported chipsets: RT2800E & RT2800ED. |
| 25 | */ |
| 26 | |
| 27 | #include <linux/crc-ccitt.h> |
| 28 | #include <linux/delay.h> |
| 29 | #include <linux/etherdevice.h> |
| 30 | #include <linux/init.h> |
| 31 | #include <linux/kernel.h> |
| 32 | #include <linux/module.h> |
| 33 | #include <linux/pci.h> |
| 34 | #include <linux/platform_device.h> |
| 35 | #include <linux/eeprom_93cx6.h> |
| 36 | |
| 37 | #include "rt2x00.h" |
| 38 | #include "rt2x00pci.h" |
| 39 | #include "rt2x00soc.h" |
Bartlomiej Zolnierkiewicz | 7ef5cc9 | 2009-11-04 18:35:32 +0100 | [diff] [blame] | 40 | #include "rt2800lib.h" |
Bartlomiej Zolnierkiewicz | b54f78a | 2009-11-04 18:35:54 +0100 | [diff] [blame] | 41 | #include "rt2800.h" |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 42 | #include "rt2800pci.h" |
| 43 | |
| 44 | #ifdef CONFIG_RT2800PCI_PCI_MODULE |
| 45 | #define CONFIG_RT2800PCI_PCI |
| 46 | #endif |
| 47 | |
| 48 | #ifdef CONFIG_RT2800PCI_WISOC_MODULE |
| 49 | #define CONFIG_RT2800PCI_WISOC |
| 50 | #endif |
| 51 | |
| 52 | /* |
| 53 | * Allow hardware encryption to be disabled. |
| 54 | */ |
| 55 | static int modparam_nohwcrypt = 1; |
| 56 | module_param_named(nohwcrypt, modparam_nohwcrypt, bool, S_IRUGO); |
| 57 | MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption."); |
| 58 | |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 59 | static void rt2800pci_mcu_status(struct rt2x00_dev *rt2x00dev, const u8 token) |
| 60 | { |
| 61 | unsigned int i; |
| 62 | u32 reg; |
| 63 | |
| 64 | for (i = 0; i < 200; i++) { |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 65 | rt2800_register_read(rt2x00dev, H2M_MAILBOX_CID, ®); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 66 | |
| 67 | if ((rt2x00_get_field32(reg, H2M_MAILBOX_CID_CMD0) == token) || |
| 68 | (rt2x00_get_field32(reg, H2M_MAILBOX_CID_CMD1) == token) || |
| 69 | (rt2x00_get_field32(reg, H2M_MAILBOX_CID_CMD2) == token) || |
| 70 | (rt2x00_get_field32(reg, H2M_MAILBOX_CID_CMD3) == token)) |
| 71 | break; |
| 72 | |
| 73 | udelay(REGISTER_BUSY_DELAY); |
| 74 | } |
| 75 | |
| 76 | if (i == 200) |
| 77 | ERROR(rt2x00dev, "MCU request failed, no response from hardware\n"); |
| 78 | |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 79 | rt2800_register_write(rt2x00dev, H2M_MAILBOX_STATUS, ~0); |
| 80 | rt2800_register_write(rt2x00dev, H2M_MAILBOX_CID, ~0); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | #ifdef CONFIG_RT2800PCI_WISOC |
| 84 | static void rt2800pci_read_eeprom_soc(struct rt2x00_dev *rt2x00dev) |
| 85 | { |
| 86 | u32 *base_addr = (u32 *) KSEG1ADDR(0x1F040000); /* XXX for RT3052 */ |
| 87 | |
| 88 | memcpy_fromio(rt2x00dev->eeprom, base_addr, EEPROM_SIZE); |
| 89 | } |
| 90 | #else |
| 91 | static inline void rt2800pci_read_eeprom_soc(struct rt2x00_dev *rt2x00dev) |
| 92 | { |
| 93 | } |
| 94 | #endif /* CONFIG_RT2800PCI_WISOC */ |
| 95 | |
| 96 | #ifdef CONFIG_RT2800PCI_PCI |
| 97 | static void rt2800pci_eepromregister_read(struct eeprom_93cx6 *eeprom) |
| 98 | { |
| 99 | struct rt2x00_dev *rt2x00dev = eeprom->data; |
| 100 | u32 reg; |
| 101 | |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 102 | rt2800_register_read(rt2x00dev, E2PROM_CSR, ®); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 103 | |
| 104 | eeprom->reg_data_in = !!rt2x00_get_field32(reg, E2PROM_CSR_DATA_IN); |
| 105 | eeprom->reg_data_out = !!rt2x00_get_field32(reg, E2PROM_CSR_DATA_OUT); |
| 106 | eeprom->reg_data_clock = |
| 107 | !!rt2x00_get_field32(reg, E2PROM_CSR_DATA_CLOCK); |
| 108 | eeprom->reg_chip_select = |
| 109 | !!rt2x00_get_field32(reg, E2PROM_CSR_CHIP_SELECT); |
| 110 | } |
| 111 | |
| 112 | static void rt2800pci_eepromregister_write(struct eeprom_93cx6 *eeprom) |
| 113 | { |
| 114 | struct rt2x00_dev *rt2x00dev = eeprom->data; |
| 115 | u32 reg = 0; |
| 116 | |
| 117 | rt2x00_set_field32(®, E2PROM_CSR_DATA_IN, !!eeprom->reg_data_in); |
| 118 | rt2x00_set_field32(®, E2PROM_CSR_DATA_OUT, !!eeprom->reg_data_out); |
| 119 | rt2x00_set_field32(®, E2PROM_CSR_DATA_CLOCK, |
| 120 | !!eeprom->reg_data_clock); |
| 121 | rt2x00_set_field32(®, E2PROM_CSR_CHIP_SELECT, |
| 122 | !!eeprom->reg_chip_select); |
| 123 | |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 124 | rt2800_register_write(rt2x00dev, E2PROM_CSR, reg); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | static void rt2800pci_read_eeprom_pci(struct rt2x00_dev *rt2x00dev) |
| 128 | { |
| 129 | struct eeprom_93cx6 eeprom; |
| 130 | u32 reg; |
| 131 | |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 132 | rt2800_register_read(rt2x00dev, E2PROM_CSR, ®); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 133 | |
| 134 | eeprom.data = rt2x00dev; |
| 135 | eeprom.register_read = rt2800pci_eepromregister_read; |
| 136 | eeprom.register_write = rt2800pci_eepromregister_write; |
| 137 | eeprom.width = !rt2x00_get_field32(reg, E2PROM_CSR_TYPE) ? |
| 138 | PCI_EEPROM_WIDTH_93C46 : PCI_EEPROM_WIDTH_93C66; |
| 139 | eeprom.reg_data_in = 0; |
| 140 | eeprom.reg_data_out = 0; |
| 141 | eeprom.reg_data_clock = 0; |
| 142 | eeprom.reg_chip_select = 0; |
| 143 | |
| 144 | eeprom_93cx6_multiread(&eeprom, EEPROM_BASE, rt2x00dev->eeprom, |
| 145 | EEPROM_SIZE / sizeof(u16)); |
| 146 | } |
| 147 | |
Gertjan van Wingerde | a659868 | 2009-11-08 12:30:35 +0100 | [diff] [blame] | 148 | static int rt2800pci_efuse_detect(struct rt2x00_dev *rt2x00dev) |
| 149 | { |
| 150 | u32 reg; |
| 151 | |
| 152 | rt2800_register_read(rt2x00dev, EFUSE_CTRL, ®); |
| 153 | |
| 154 | return rt2x00_get_field32(reg, EFUSE_CTRL_PRESENT); |
| 155 | } |
| 156 | |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 157 | static void rt2800pci_efuse_read(struct rt2x00_dev *rt2x00dev, |
| 158 | unsigned int i) |
| 159 | { |
| 160 | u32 reg; |
| 161 | |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 162 | rt2800_register_read(rt2x00dev, EFUSE_CTRL, ®); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 163 | rt2x00_set_field32(®, EFUSE_CTRL_ADDRESS_IN, i); |
| 164 | rt2x00_set_field32(®, EFUSE_CTRL_MODE, 0); |
| 165 | rt2x00_set_field32(®, EFUSE_CTRL_KICK, 1); |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 166 | rt2800_register_write(rt2x00dev, EFUSE_CTRL, reg); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 167 | |
| 168 | /* Wait until the EEPROM has been loaded */ |
Bartlomiej Zolnierkiewicz | b4a77d0d | 2009-11-04 18:33:41 +0100 | [diff] [blame] | 169 | rt2800_regbusy_read(rt2x00dev, EFUSE_CTRL, EFUSE_CTRL_KICK, ®); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 170 | |
| 171 | /* Apparently the data is read from end to start */ |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 172 | rt2800_register_read(rt2x00dev, EFUSE_DATA3, |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 173 | (u32 *)&rt2x00dev->eeprom[i]); |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 174 | rt2800_register_read(rt2x00dev, EFUSE_DATA2, |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 175 | (u32 *)&rt2x00dev->eeprom[i + 2]); |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 176 | rt2800_register_read(rt2x00dev, EFUSE_DATA1, |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 177 | (u32 *)&rt2x00dev->eeprom[i + 4]); |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 178 | rt2800_register_read(rt2x00dev, EFUSE_DATA0, |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 179 | (u32 *)&rt2x00dev->eeprom[i + 6]); |
| 180 | } |
| 181 | |
| 182 | static void rt2800pci_read_eeprom_efuse(struct rt2x00_dev *rt2x00dev) |
| 183 | { |
| 184 | unsigned int i; |
| 185 | |
| 186 | for (i = 0; i < EEPROM_SIZE / sizeof(u16); i += 8) |
| 187 | rt2800pci_efuse_read(rt2x00dev, i); |
| 188 | } |
| 189 | #else |
| 190 | static inline void rt2800pci_read_eeprom_pci(struct rt2x00_dev *rt2x00dev) |
| 191 | { |
| 192 | } |
| 193 | |
Gertjan van Wingerde | a659868 | 2009-11-08 12:30:35 +0100 | [diff] [blame] | 194 | static inline int rt2800pci_efuse_detect(struct rt2x00_dev *rt2x00dev) |
| 195 | { |
| 196 | return 0; |
| 197 | } |
| 198 | |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 199 | static inline void rt2800pci_read_eeprom_efuse(struct rt2x00_dev *rt2x00dev) |
| 200 | { |
| 201 | } |
| 202 | #endif /* CONFIG_RT2800PCI_PCI */ |
| 203 | |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 204 | /* |
| 205 | * Firmware functions |
| 206 | */ |
| 207 | static char *rt2800pci_get_firmware_name(struct rt2x00_dev *rt2x00dev) |
| 208 | { |
| 209 | return FIRMWARE_RT2860; |
| 210 | } |
| 211 | |
| 212 | static int rt2800pci_check_firmware(struct rt2x00_dev *rt2x00dev, |
| 213 | const u8 *data, const size_t len) |
| 214 | { |
| 215 | u16 fw_crc; |
| 216 | u16 crc; |
| 217 | |
| 218 | /* |
| 219 | * Only support 8kb firmware files. |
| 220 | */ |
| 221 | if (len != 8192) |
| 222 | return FW_BAD_LENGTH; |
| 223 | |
| 224 | /* |
| 225 | * The last 2 bytes in the firmware array are the crc checksum itself, |
| 226 | * this means that we should never pass those 2 bytes to the crc |
| 227 | * algorithm. |
| 228 | */ |
| 229 | fw_crc = (data[len - 2] << 8 | data[len - 1]); |
| 230 | |
| 231 | /* |
| 232 | * Use the crc ccitt algorithm. |
| 233 | * This will return the same value as the legacy driver which |
| 234 | * used bit ordering reversion on the both the firmware bytes |
| 235 | * before input input as well as on the final output. |
| 236 | * Obviously using crc ccitt directly is much more efficient. |
| 237 | */ |
| 238 | crc = crc_ccitt(~0, data, len - 2); |
| 239 | |
| 240 | /* |
| 241 | * There is a small difference between the crc-itu-t + bitrev and |
| 242 | * the crc-ccitt crc calculation. In the latter method the 2 bytes |
| 243 | * will be swapped, use swab16 to convert the crc to the correct |
| 244 | * value. |
| 245 | */ |
| 246 | crc = swab16(crc); |
| 247 | |
| 248 | return (fw_crc == crc) ? FW_OK : FW_BAD_CRC; |
| 249 | } |
| 250 | |
| 251 | static int rt2800pci_load_firmware(struct rt2x00_dev *rt2x00dev, |
| 252 | const u8 *data, const size_t len) |
| 253 | { |
| 254 | unsigned int i; |
| 255 | u32 reg; |
| 256 | |
| 257 | /* |
| 258 | * Wait for stable hardware. |
| 259 | */ |
| 260 | for (i = 0; i < REGISTER_BUSY_COUNT; i++) { |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 261 | rt2800_register_read(rt2x00dev, MAC_CSR0, ®); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 262 | if (reg && reg != ~0) |
| 263 | break; |
| 264 | msleep(1); |
| 265 | } |
| 266 | |
| 267 | if (i == REGISTER_BUSY_COUNT) { |
| 268 | ERROR(rt2x00dev, "Unstable hardware.\n"); |
| 269 | return -EBUSY; |
| 270 | } |
| 271 | |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 272 | rt2800_register_write(rt2x00dev, PWR_PIN_CFG, 0x00000002); |
| 273 | rt2800_register_write(rt2x00dev, AUTOWAKEUP_CFG, 0x00000000); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 274 | |
| 275 | /* |
| 276 | * Disable DMA, will be reenabled later when enabling |
| 277 | * the radio. |
| 278 | */ |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 279 | rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, ®); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 280 | rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0); |
| 281 | rt2x00_set_field32(®, WPDMA_GLO_CFG_TX_DMA_BUSY, 0); |
| 282 | rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0); |
| 283 | rt2x00_set_field32(®, WPDMA_GLO_CFG_RX_DMA_BUSY, 0); |
| 284 | rt2x00_set_field32(®, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1); |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 285 | rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 286 | |
| 287 | /* |
| 288 | * enable Host program ram write selection |
| 289 | */ |
| 290 | reg = 0; |
| 291 | rt2x00_set_field32(®, PBF_SYS_CTRL_HOST_RAM_WRITE, 1); |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 292 | rt2800_register_write(rt2x00dev, PBF_SYS_CTRL, reg); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 293 | |
| 294 | /* |
| 295 | * Write firmware to device. |
| 296 | */ |
Bartlomiej Zolnierkiewicz | 4f2732c | 2009-11-04 18:33:27 +0100 | [diff] [blame] | 297 | rt2800_register_multiwrite(rt2x00dev, FIRMWARE_IMAGE_BASE, |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 298 | data, len); |
| 299 | |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 300 | rt2800_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00000); |
| 301 | rt2800_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00001); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 302 | |
| 303 | /* |
| 304 | * Wait for device to stabilize. |
| 305 | */ |
| 306 | for (i = 0; i < REGISTER_BUSY_COUNT; i++) { |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 307 | rt2800_register_read(rt2x00dev, PBF_SYS_CTRL, ®); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 308 | if (rt2x00_get_field32(reg, PBF_SYS_CTRL_READY)) |
| 309 | break; |
| 310 | msleep(1); |
| 311 | } |
| 312 | |
| 313 | if (i == REGISTER_BUSY_COUNT) { |
| 314 | ERROR(rt2x00dev, "PBF system register not ready.\n"); |
| 315 | return -EBUSY; |
| 316 | } |
| 317 | |
| 318 | /* |
| 319 | * Disable interrupts |
| 320 | */ |
| 321 | rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_RADIO_IRQ_OFF); |
| 322 | |
| 323 | /* |
| 324 | * Initialize BBP R/W access agent |
| 325 | */ |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 326 | rt2800_register_write(rt2x00dev, H2M_BBP_AGENT, 0); |
| 327 | rt2800_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 328 | |
| 329 | return 0; |
| 330 | } |
| 331 | |
| 332 | /* |
| 333 | * Initialization functions. |
| 334 | */ |
| 335 | static bool rt2800pci_get_entry_state(struct queue_entry *entry) |
| 336 | { |
| 337 | struct queue_entry_priv_pci *entry_priv = entry->priv_data; |
| 338 | u32 word; |
| 339 | |
| 340 | if (entry->queue->qid == QID_RX) { |
| 341 | rt2x00_desc_read(entry_priv->desc, 1, &word); |
| 342 | |
| 343 | return (!rt2x00_get_field32(word, RXD_W1_DMA_DONE)); |
| 344 | } else { |
| 345 | rt2x00_desc_read(entry_priv->desc, 1, &word); |
| 346 | |
| 347 | return (!rt2x00_get_field32(word, TXD_W1_DMA_DONE)); |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | static void rt2800pci_clear_entry(struct queue_entry *entry) |
| 352 | { |
| 353 | struct queue_entry_priv_pci *entry_priv = entry->priv_data; |
| 354 | struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb); |
| 355 | u32 word; |
| 356 | |
| 357 | if (entry->queue->qid == QID_RX) { |
| 358 | rt2x00_desc_read(entry_priv->desc, 0, &word); |
| 359 | rt2x00_set_field32(&word, RXD_W0_SDP0, skbdesc->skb_dma); |
| 360 | rt2x00_desc_write(entry_priv->desc, 0, word); |
| 361 | |
| 362 | rt2x00_desc_read(entry_priv->desc, 1, &word); |
| 363 | rt2x00_set_field32(&word, RXD_W1_DMA_DONE, 0); |
| 364 | rt2x00_desc_write(entry_priv->desc, 1, word); |
| 365 | } else { |
| 366 | rt2x00_desc_read(entry_priv->desc, 1, &word); |
| 367 | rt2x00_set_field32(&word, TXD_W1_DMA_DONE, 1); |
| 368 | rt2x00_desc_write(entry_priv->desc, 1, word); |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | static int rt2800pci_init_queues(struct rt2x00_dev *rt2x00dev) |
| 373 | { |
| 374 | struct queue_entry_priv_pci *entry_priv; |
| 375 | u32 reg; |
| 376 | |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 377 | rt2800_register_read(rt2x00dev, WPDMA_RST_IDX, ®); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 378 | rt2x00_set_field32(®, WPDMA_RST_IDX_DTX_IDX0, 1); |
| 379 | rt2x00_set_field32(®, WPDMA_RST_IDX_DTX_IDX1, 1); |
| 380 | rt2x00_set_field32(®, WPDMA_RST_IDX_DTX_IDX2, 1); |
| 381 | rt2x00_set_field32(®, WPDMA_RST_IDX_DTX_IDX3, 1); |
| 382 | rt2x00_set_field32(®, WPDMA_RST_IDX_DTX_IDX4, 1); |
| 383 | rt2x00_set_field32(®, WPDMA_RST_IDX_DTX_IDX5, 1); |
| 384 | rt2x00_set_field32(®, WPDMA_RST_IDX_DRX_IDX0, 1); |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 385 | rt2800_register_write(rt2x00dev, WPDMA_RST_IDX, reg); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 386 | |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 387 | rt2800_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00000e1f); |
| 388 | rt2800_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00000e00); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 389 | |
| 390 | /* |
| 391 | * Initialize registers. |
| 392 | */ |
| 393 | entry_priv = rt2x00dev->tx[0].entries[0].priv_data; |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 394 | rt2800_register_write(rt2x00dev, TX_BASE_PTR0, entry_priv->desc_dma); |
| 395 | rt2800_register_write(rt2x00dev, TX_MAX_CNT0, rt2x00dev->tx[0].limit); |
| 396 | rt2800_register_write(rt2x00dev, TX_CTX_IDX0, 0); |
| 397 | rt2800_register_write(rt2x00dev, TX_DTX_IDX0, 0); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 398 | |
| 399 | entry_priv = rt2x00dev->tx[1].entries[0].priv_data; |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 400 | rt2800_register_write(rt2x00dev, TX_BASE_PTR1, entry_priv->desc_dma); |
| 401 | rt2800_register_write(rt2x00dev, TX_MAX_CNT1, rt2x00dev->tx[1].limit); |
| 402 | rt2800_register_write(rt2x00dev, TX_CTX_IDX1, 0); |
| 403 | rt2800_register_write(rt2x00dev, TX_DTX_IDX1, 0); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 404 | |
| 405 | entry_priv = rt2x00dev->tx[2].entries[0].priv_data; |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 406 | rt2800_register_write(rt2x00dev, TX_BASE_PTR2, entry_priv->desc_dma); |
| 407 | rt2800_register_write(rt2x00dev, TX_MAX_CNT2, rt2x00dev->tx[2].limit); |
| 408 | rt2800_register_write(rt2x00dev, TX_CTX_IDX2, 0); |
| 409 | rt2800_register_write(rt2x00dev, TX_DTX_IDX2, 0); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 410 | |
| 411 | entry_priv = rt2x00dev->tx[3].entries[0].priv_data; |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 412 | rt2800_register_write(rt2x00dev, TX_BASE_PTR3, entry_priv->desc_dma); |
| 413 | rt2800_register_write(rt2x00dev, TX_MAX_CNT3, rt2x00dev->tx[3].limit); |
| 414 | rt2800_register_write(rt2x00dev, TX_CTX_IDX3, 0); |
| 415 | rt2800_register_write(rt2x00dev, TX_DTX_IDX3, 0); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 416 | |
| 417 | entry_priv = rt2x00dev->rx->entries[0].priv_data; |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 418 | rt2800_register_write(rt2x00dev, RX_BASE_PTR, entry_priv->desc_dma); |
| 419 | rt2800_register_write(rt2x00dev, RX_MAX_CNT, rt2x00dev->rx[0].limit); |
| 420 | rt2800_register_write(rt2x00dev, RX_CRX_IDX, rt2x00dev->rx[0].limit - 1); |
| 421 | rt2800_register_write(rt2x00dev, RX_DRX_IDX, 0); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 422 | |
| 423 | /* |
| 424 | * Enable global DMA configuration |
| 425 | */ |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 426 | rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, ®); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 427 | rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0); |
| 428 | rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0); |
| 429 | rt2x00_set_field32(®, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1); |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 430 | rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 431 | |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 432 | rt2800_register_write(rt2x00dev, DELAY_INT_CFG, 0); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 433 | |
| 434 | return 0; |
| 435 | } |
| 436 | |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 437 | /* |
| 438 | * Device state switch handlers. |
| 439 | */ |
| 440 | static void rt2800pci_toggle_rx(struct rt2x00_dev *rt2x00dev, |
| 441 | enum dev_state state) |
| 442 | { |
| 443 | u32 reg; |
| 444 | |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 445 | rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, ®); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 446 | rt2x00_set_field32(®, MAC_SYS_CTRL_ENABLE_RX, |
| 447 | (state == STATE_RADIO_RX_ON) || |
| 448 | (state == STATE_RADIO_RX_ON_LINK)); |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 449 | rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | static void rt2800pci_toggle_irq(struct rt2x00_dev *rt2x00dev, |
| 453 | enum dev_state state) |
| 454 | { |
| 455 | int mask = (state == STATE_RADIO_IRQ_ON); |
| 456 | u32 reg; |
| 457 | |
| 458 | /* |
| 459 | * When interrupts are being enabled, the interrupt registers |
| 460 | * should clear the register to assure a clean state. |
| 461 | */ |
| 462 | if (state == STATE_RADIO_IRQ_ON) { |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 463 | rt2800_register_read(rt2x00dev, INT_SOURCE_CSR, ®); |
| 464 | rt2800_register_write(rt2x00dev, INT_SOURCE_CSR, reg); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 465 | } |
| 466 | |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 467 | rt2800_register_read(rt2x00dev, INT_MASK_CSR, ®); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 468 | rt2x00_set_field32(®, INT_MASK_CSR_RXDELAYINT, mask); |
| 469 | rt2x00_set_field32(®, INT_MASK_CSR_TXDELAYINT, mask); |
| 470 | rt2x00_set_field32(®, INT_MASK_CSR_RX_DONE, mask); |
| 471 | rt2x00_set_field32(®, INT_MASK_CSR_AC0_DMA_DONE, mask); |
| 472 | rt2x00_set_field32(®, INT_MASK_CSR_AC1_DMA_DONE, mask); |
| 473 | rt2x00_set_field32(®, INT_MASK_CSR_AC2_DMA_DONE, mask); |
| 474 | rt2x00_set_field32(®, INT_MASK_CSR_AC3_DMA_DONE, mask); |
| 475 | rt2x00_set_field32(®, INT_MASK_CSR_HCCA_DMA_DONE, mask); |
| 476 | rt2x00_set_field32(®, INT_MASK_CSR_MGMT_DMA_DONE, mask); |
| 477 | rt2x00_set_field32(®, INT_MASK_CSR_MCU_COMMAND, mask); |
| 478 | rt2x00_set_field32(®, INT_MASK_CSR_RXTX_COHERENT, mask); |
| 479 | rt2x00_set_field32(®, INT_MASK_CSR_TBTT, mask); |
| 480 | rt2x00_set_field32(®, INT_MASK_CSR_PRE_TBTT, mask); |
| 481 | rt2x00_set_field32(®, INT_MASK_CSR_TX_FIFO_STATUS, mask); |
| 482 | rt2x00_set_field32(®, INT_MASK_CSR_AUTO_WAKEUP, mask); |
| 483 | rt2x00_set_field32(®, INT_MASK_CSR_GPTIMER, mask); |
| 484 | rt2x00_set_field32(®, INT_MASK_CSR_RX_COHERENT, mask); |
| 485 | rt2x00_set_field32(®, INT_MASK_CSR_TX_COHERENT, mask); |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 486 | rt2800_register_write(rt2x00dev, INT_MASK_CSR, reg); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | static int rt2800pci_wait_wpdma_ready(struct rt2x00_dev *rt2x00dev) |
| 490 | { |
| 491 | unsigned int i; |
| 492 | u32 reg; |
| 493 | |
| 494 | for (i = 0; i < REGISTER_BUSY_COUNT; i++) { |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 495 | rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, ®); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 496 | if (!rt2x00_get_field32(reg, WPDMA_GLO_CFG_TX_DMA_BUSY) && |
| 497 | !rt2x00_get_field32(reg, WPDMA_GLO_CFG_RX_DMA_BUSY)) |
| 498 | return 0; |
| 499 | |
| 500 | msleep(1); |
| 501 | } |
| 502 | |
| 503 | ERROR(rt2x00dev, "WPDMA TX/RX busy, aborting.\n"); |
| 504 | return -EACCES; |
| 505 | } |
| 506 | |
| 507 | static int rt2800pci_enable_radio(struct rt2x00_dev *rt2x00dev) |
| 508 | { |
| 509 | u32 reg; |
| 510 | u16 word; |
| 511 | |
| 512 | /* |
| 513 | * Initialize all registers. |
| 514 | */ |
| 515 | if (unlikely(rt2800pci_wait_wpdma_ready(rt2x00dev) || |
| 516 | rt2800pci_init_queues(rt2x00dev) || |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 517 | rt2800_init_registers(rt2x00dev) || |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 518 | rt2800pci_wait_wpdma_ready(rt2x00dev) || |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 519 | rt2800_init_bbp(rt2x00dev) || |
| 520 | rt2800_init_rfcsr(rt2x00dev))) |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 521 | return -EIO; |
| 522 | |
| 523 | /* |
| 524 | * Send signal to firmware during boot time. |
| 525 | */ |
Bartlomiej Zolnierkiewicz | 3a9e5b0 | 2009-11-04 18:34:39 +0100 | [diff] [blame] | 526 | rt2800_mcu_request(rt2x00dev, MCU_BOOT_SIGNAL, 0xff, 0, 0); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 527 | |
| 528 | /* |
| 529 | * Enable RX. |
| 530 | */ |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 531 | rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, ®); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 532 | rt2x00_set_field32(®, MAC_SYS_CTRL_ENABLE_TX, 1); |
| 533 | rt2x00_set_field32(®, MAC_SYS_CTRL_ENABLE_RX, 0); |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 534 | rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 535 | |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 536 | rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, ®); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 537 | rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_TX_DMA, 1); |
| 538 | rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_RX_DMA, 1); |
| 539 | rt2x00_set_field32(®, WPDMA_GLO_CFG_WP_DMA_BURST_SIZE, 2); |
| 540 | rt2x00_set_field32(®, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1); |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 541 | rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 542 | |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 543 | rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, ®); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 544 | rt2x00_set_field32(®, MAC_SYS_CTRL_ENABLE_TX, 1); |
| 545 | rt2x00_set_field32(®, MAC_SYS_CTRL_ENABLE_RX, 1); |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 546 | rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 547 | |
| 548 | /* |
| 549 | * Initialize LED control |
| 550 | */ |
| 551 | rt2x00_eeprom_read(rt2x00dev, EEPROM_LED1, &word); |
Bartlomiej Zolnierkiewicz | 3a9e5b0 | 2009-11-04 18:34:39 +0100 | [diff] [blame] | 552 | rt2800_mcu_request(rt2x00dev, MCU_LED_1, 0xff, |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 553 | word & 0xff, (word >> 8) & 0xff); |
| 554 | |
| 555 | rt2x00_eeprom_read(rt2x00dev, EEPROM_LED2, &word); |
Bartlomiej Zolnierkiewicz | 3a9e5b0 | 2009-11-04 18:34:39 +0100 | [diff] [blame] | 556 | rt2800_mcu_request(rt2x00dev, MCU_LED_2, 0xff, |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 557 | word & 0xff, (word >> 8) & 0xff); |
| 558 | |
| 559 | rt2x00_eeprom_read(rt2x00dev, EEPROM_LED3, &word); |
Bartlomiej Zolnierkiewicz | 3a9e5b0 | 2009-11-04 18:34:39 +0100 | [diff] [blame] | 560 | rt2800_mcu_request(rt2x00dev, MCU_LED_3, 0xff, |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 561 | word & 0xff, (word >> 8) & 0xff); |
| 562 | |
| 563 | return 0; |
| 564 | } |
| 565 | |
| 566 | static void rt2800pci_disable_radio(struct rt2x00_dev *rt2x00dev) |
| 567 | { |
| 568 | u32 reg; |
| 569 | |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 570 | rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, ®); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 571 | rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0); |
| 572 | rt2x00_set_field32(®, WPDMA_GLO_CFG_TX_DMA_BUSY, 0); |
| 573 | rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0); |
| 574 | rt2x00_set_field32(®, WPDMA_GLO_CFG_RX_DMA_BUSY, 0); |
| 575 | rt2x00_set_field32(®, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1); |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 576 | rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 577 | |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 578 | rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, 0); |
| 579 | rt2800_register_write(rt2x00dev, PWR_PIN_CFG, 0); |
| 580 | rt2800_register_write(rt2x00dev, TX_PIN_CFG, 0); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 581 | |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 582 | rt2800_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00001280); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 583 | |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 584 | rt2800_register_read(rt2x00dev, WPDMA_RST_IDX, ®); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 585 | rt2x00_set_field32(®, WPDMA_RST_IDX_DTX_IDX0, 1); |
| 586 | rt2x00_set_field32(®, WPDMA_RST_IDX_DTX_IDX1, 1); |
| 587 | rt2x00_set_field32(®, WPDMA_RST_IDX_DTX_IDX2, 1); |
| 588 | rt2x00_set_field32(®, WPDMA_RST_IDX_DTX_IDX3, 1); |
| 589 | rt2x00_set_field32(®, WPDMA_RST_IDX_DTX_IDX4, 1); |
| 590 | rt2x00_set_field32(®, WPDMA_RST_IDX_DTX_IDX5, 1); |
| 591 | rt2x00_set_field32(®, WPDMA_RST_IDX_DRX_IDX0, 1); |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 592 | rt2800_register_write(rt2x00dev, WPDMA_RST_IDX, reg); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 593 | |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 594 | rt2800_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00000e1f); |
| 595 | rt2800_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00000e00); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 596 | |
| 597 | /* Wait for DMA, ignore error */ |
| 598 | rt2800pci_wait_wpdma_ready(rt2x00dev); |
| 599 | } |
| 600 | |
| 601 | static int rt2800pci_set_state(struct rt2x00_dev *rt2x00dev, |
| 602 | enum dev_state state) |
| 603 | { |
| 604 | /* |
| 605 | * Always put the device to sleep (even when we intend to wakeup!) |
| 606 | * if the device is booting and wasn't asleep it will return |
| 607 | * failure when attempting to wakeup. |
| 608 | */ |
Bartlomiej Zolnierkiewicz | 3a9e5b0 | 2009-11-04 18:34:39 +0100 | [diff] [blame] | 609 | rt2800_mcu_request(rt2x00dev, MCU_SLEEP, 0xff, 0, 2); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 610 | |
| 611 | if (state == STATE_AWAKE) { |
Bartlomiej Zolnierkiewicz | 3a9e5b0 | 2009-11-04 18:34:39 +0100 | [diff] [blame] | 612 | rt2800_mcu_request(rt2x00dev, MCU_WAKEUP, TOKEN_WAKUP, 0, 0); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 613 | rt2800pci_mcu_status(rt2x00dev, TOKEN_WAKUP); |
| 614 | } |
| 615 | |
| 616 | return 0; |
| 617 | } |
| 618 | |
| 619 | static int rt2800pci_set_device_state(struct rt2x00_dev *rt2x00dev, |
| 620 | enum dev_state state) |
| 621 | { |
| 622 | int retval = 0; |
| 623 | |
| 624 | switch (state) { |
| 625 | case STATE_RADIO_ON: |
| 626 | /* |
| 627 | * Before the radio can be enabled, the device first has |
| 628 | * to be woken up. After that it needs a bit of time |
| 629 | * to be fully awake and then the radio can be enabled. |
| 630 | */ |
| 631 | rt2800pci_set_state(rt2x00dev, STATE_AWAKE); |
| 632 | msleep(1); |
| 633 | retval = rt2800pci_enable_radio(rt2x00dev); |
| 634 | break; |
| 635 | case STATE_RADIO_OFF: |
| 636 | /* |
| 637 | * After the radio has been disabled, the device should |
| 638 | * be put to sleep for powersaving. |
| 639 | */ |
| 640 | rt2800pci_disable_radio(rt2x00dev); |
| 641 | rt2800pci_set_state(rt2x00dev, STATE_SLEEP); |
| 642 | break; |
| 643 | case STATE_RADIO_RX_ON: |
| 644 | case STATE_RADIO_RX_ON_LINK: |
| 645 | case STATE_RADIO_RX_OFF: |
| 646 | case STATE_RADIO_RX_OFF_LINK: |
| 647 | rt2800pci_toggle_rx(rt2x00dev, state); |
| 648 | break; |
| 649 | case STATE_RADIO_IRQ_ON: |
| 650 | case STATE_RADIO_IRQ_OFF: |
| 651 | rt2800pci_toggle_irq(rt2x00dev, state); |
| 652 | break; |
| 653 | case STATE_DEEP_SLEEP: |
| 654 | case STATE_SLEEP: |
| 655 | case STATE_STANDBY: |
| 656 | case STATE_AWAKE: |
| 657 | retval = rt2800pci_set_state(rt2x00dev, state); |
| 658 | break; |
| 659 | default: |
| 660 | retval = -ENOTSUPP; |
| 661 | break; |
| 662 | } |
| 663 | |
| 664 | if (unlikely(retval)) |
| 665 | ERROR(rt2x00dev, "Device failed to enter state %d (%d).\n", |
| 666 | state, retval); |
| 667 | |
| 668 | return retval; |
| 669 | } |
| 670 | |
| 671 | /* |
| 672 | * TX descriptor initialization |
| 673 | */ |
| 674 | static void rt2800pci_write_tx_desc(struct rt2x00_dev *rt2x00dev, |
| 675 | struct sk_buff *skb, |
| 676 | struct txentry_desc *txdesc) |
| 677 | { |
| 678 | struct skb_frame_desc *skbdesc = get_skb_frame_desc(skb); |
| 679 | __le32 *txd = skbdesc->desc; |
| 680 | __le32 *txwi = (__le32 *)(skb->data - rt2x00dev->hw->extra_tx_headroom); |
| 681 | u32 word; |
| 682 | |
| 683 | /* |
| 684 | * Initialize TX Info descriptor |
| 685 | */ |
| 686 | rt2x00_desc_read(txwi, 0, &word); |
| 687 | rt2x00_set_field32(&word, TXWI_W0_FRAG, |
| 688 | test_bit(ENTRY_TXD_MORE_FRAG, &txdesc->flags)); |
| 689 | rt2x00_set_field32(&word, TXWI_W0_MIMO_PS, 0); |
| 690 | rt2x00_set_field32(&word, TXWI_W0_CF_ACK, 0); |
| 691 | rt2x00_set_field32(&word, TXWI_W0_TS, |
| 692 | test_bit(ENTRY_TXD_REQ_TIMESTAMP, &txdesc->flags)); |
| 693 | rt2x00_set_field32(&word, TXWI_W0_AMPDU, |
| 694 | test_bit(ENTRY_TXD_HT_AMPDU, &txdesc->flags)); |
| 695 | rt2x00_set_field32(&word, TXWI_W0_MPDU_DENSITY, txdesc->mpdu_density); |
| 696 | rt2x00_set_field32(&word, TXWI_W0_TX_OP, txdesc->ifs); |
| 697 | rt2x00_set_field32(&word, TXWI_W0_MCS, txdesc->mcs); |
| 698 | rt2x00_set_field32(&word, TXWI_W0_BW, |
| 699 | test_bit(ENTRY_TXD_HT_BW_40, &txdesc->flags)); |
| 700 | rt2x00_set_field32(&word, TXWI_W0_SHORT_GI, |
| 701 | test_bit(ENTRY_TXD_HT_SHORT_GI, &txdesc->flags)); |
| 702 | rt2x00_set_field32(&word, TXWI_W0_STBC, txdesc->stbc); |
| 703 | rt2x00_set_field32(&word, TXWI_W0_PHYMODE, txdesc->rate_mode); |
| 704 | rt2x00_desc_write(txwi, 0, word); |
| 705 | |
| 706 | rt2x00_desc_read(txwi, 1, &word); |
| 707 | rt2x00_set_field32(&word, TXWI_W1_ACK, |
| 708 | test_bit(ENTRY_TXD_ACK, &txdesc->flags)); |
| 709 | rt2x00_set_field32(&word, TXWI_W1_NSEQ, |
| 710 | test_bit(ENTRY_TXD_GENERATE_SEQ, &txdesc->flags)); |
| 711 | rt2x00_set_field32(&word, TXWI_W1_BW_WIN_SIZE, txdesc->ba_size); |
| 712 | rt2x00_set_field32(&word, TXWI_W1_WIRELESS_CLI_ID, |
| 713 | test_bit(ENTRY_TXD_ENCRYPT, &txdesc->flags) ? |
Bartlomiej Zolnierkiewicz | f644fea | 2009-11-04 18:32:24 +0100 | [diff] [blame] | 714 | txdesc->key_idx : 0xff); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 715 | rt2x00_set_field32(&word, TXWI_W1_MPDU_TOTAL_BYTE_COUNT, |
| 716 | skb->len - txdesc->l2pad); |
| 717 | rt2x00_set_field32(&word, TXWI_W1_PACKETID, |
| 718 | skbdesc->entry->queue->qid + 1); |
| 719 | rt2x00_desc_write(txwi, 1, word); |
| 720 | |
| 721 | /* |
| 722 | * Always write 0 to IV/EIV fields, hardware will insert the IV |
Bartlomiej Zolnierkiewicz | 77dba49 | 2009-11-04 18:32:40 +0100 | [diff] [blame] | 723 | * from the IVEIV register when TXD_W3_WIV is set to 0. |
| 724 | * When TXD_W3_WIV is set to 1 it will use the IV data |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 725 | * from the descriptor. The TXWI_W1_WIRELESS_CLI_ID indicates which |
| 726 | * crypto entry in the registers should be used to encrypt the frame. |
| 727 | */ |
| 728 | _rt2x00_desc_write(txwi, 2, 0 /* skbdesc->iv[0] */); |
| 729 | _rt2x00_desc_write(txwi, 3, 0 /* skbdesc->iv[1] */); |
| 730 | |
| 731 | /* |
| 732 | * The buffers pointed by SD_PTR0/SD_LEN0 and SD_PTR1/SD_LEN1 |
| 733 | * must contains a TXWI structure + 802.11 header + padding + 802.11 |
| 734 | * data. We choose to have SD_PTR0/SD_LEN0 only contains TXWI and |
| 735 | * SD_PTR1/SD_LEN1 contains 802.11 header + padding + 802.11 |
| 736 | * data. It means that LAST_SEC0 is always 0. |
| 737 | */ |
| 738 | |
| 739 | /* |
| 740 | * Initialize TX descriptor |
| 741 | */ |
| 742 | rt2x00_desc_read(txd, 0, &word); |
| 743 | rt2x00_set_field32(&word, TXD_W0_SD_PTR0, skbdesc->skb_dma); |
| 744 | rt2x00_desc_write(txd, 0, word); |
| 745 | |
| 746 | rt2x00_desc_read(txd, 1, &word); |
| 747 | rt2x00_set_field32(&word, TXD_W1_SD_LEN1, skb->len); |
| 748 | rt2x00_set_field32(&word, TXD_W1_LAST_SEC1, |
| 749 | !test_bit(ENTRY_TXD_MORE_FRAG, &txdesc->flags)); |
| 750 | rt2x00_set_field32(&word, TXD_W1_BURST, |
| 751 | test_bit(ENTRY_TXD_BURST, &txdesc->flags)); |
| 752 | rt2x00_set_field32(&word, TXD_W1_SD_LEN0, |
| 753 | rt2x00dev->hw->extra_tx_headroom); |
| 754 | rt2x00_set_field32(&word, TXD_W1_LAST_SEC0, 0); |
| 755 | rt2x00_set_field32(&word, TXD_W1_DMA_DONE, 0); |
| 756 | rt2x00_desc_write(txd, 1, word); |
| 757 | |
| 758 | rt2x00_desc_read(txd, 2, &word); |
| 759 | rt2x00_set_field32(&word, TXD_W2_SD_PTR1, |
| 760 | skbdesc->skb_dma + rt2x00dev->hw->extra_tx_headroom); |
| 761 | rt2x00_desc_write(txd, 2, word); |
| 762 | |
| 763 | rt2x00_desc_read(txd, 3, &word); |
| 764 | rt2x00_set_field32(&word, TXD_W3_WIV, |
| 765 | !test_bit(ENTRY_TXD_ENCRYPT_IV, &txdesc->flags)); |
| 766 | rt2x00_set_field32(&word, TXD_W3_QSEL, 2); |
| 767 | rt2x00_desc_write(txd, 3, word); |
| 768 | } |
| 769 | |
| 770 | /* |
| 771 | * TX data initialization |
| 772 | */ |
| 773 | static void rt2800pci_write_beacon(struct queue_entry *entry) |
| 774 | { |
| 775 | struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev; |
| 776 | struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb); |
| 777 | unsigned int beacon_base; |
| 778 | u32 reg; |
| 779 | |
| 780 | /* |
| 781 | * Disable beaconing while we are reloading the beacon data, |
| 782 | * otherwise we might be sending out invalid data. |
| 783 | */ |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 784 | rt2800_register_read(rt2x00dev, BCN_TIME_CFG, ®); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 785 | rt2x00_set_field32(®, BCN_TIME_CFG_BEACON_GEN, 0); |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 786 | rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 787 | |
| 788 | /* |
| 789 | * Write entire beacon with descriptor to register. |
| 790 | */ |
| 791 | beacon_base = HW_BEACON_OFFSET(entry->entry_idx); |
Bartlomiej Zolnierkiewicz | 4f2732c | 2009-11-04 18:33:27 +0100 | [diff] [blame] | 792 | rt2800_register_multiwrite(rt2x00dev, |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 793 | beacon_base, |
| 794 | skbdesc->desc, skbdesc->desc_len); |
Bartlomiej Zolnierkiewicz | 4f2732c | 2009-11-04 18:33:27 +0100 | [diff] [blame] | 795 | rt2800_register_multiwrite(rt2x00dev, |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 796 | beacon_base + skbdesc->desc_len, |
| 797 | entry->skb->data, entry->skb->len); |
| 798 | |
| 799 | /* |
| 800 | * Clean up beacon skb. |
| 801 | */ |
| 802 | dev_kfree_skb_any(entry->skb); |
| 803 | entry->skb = NULL; |
| 804 | } |
| 805 | |
| 806 | static void rt2800pci_kick_tx_queue(struct rt2x00_dev *rt2x00dev, |
| 807 | const enum data_queue_qid queue_idx) |
| 808 | { |
| 809 | struct data_queue *queue; |
| 810 | unsigned int idx, qidx = 0; |
| 811 | u32 reg; |
| 812 | |
| 813 | if (queue_idx == QID_BEACON) { |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 814 | rt2800_register_read(rt2x00dev, BCN_TIME_CFG, ®); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 815 | if (!rt2x00_get_field32(reg, BCN_TIME_CFG_BEACON_GEN)) { |
| 816 | rt2x00_set_field32(®, BCN_TIME_CFG_TSF_TICKING, 1); |
| 817 | rt2x00_set_field32(®, BCN_TIME_CFG_TBTT_ENABLE, 1); |
| 818 | rt2x00_set_field32(®, BCN_TIME_CFG_BEACON_GEN, 1); |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 819 | rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 820 | } |
| 821 | return; |
| 822 | } |
| 823 | |
| 824 | if (queue_idx > QID_HCCA && queue_idx != QID_MGMT) |
| 825 | return; |
| 826 | |
| 827 | queue = rt2x00queue_get_queue(rt2x00dev, queue_idx); |
| 828 | idx = queue->index[Q_INDEX]; |
| 829 | |
| 830 | if (queue_idx == QID_MGMT) |
| 831 | qidx = 5; |
| 832 | else |
| 833 | qidx = queue_idx; |
| 834 | |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 835 | rt2800_register_write(rt2x00dev, TX_CTX_IDX(qidx), idx); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 836 | } |
| 837 | |
| 838 | static void rt2800pci_kill_tx_queue(struct rt2x00_dev *rt2x00dev, |
| 839 | const enum data_queue_qid qid) |
| 840 | { |
| 841 | u32 reg; |
| 842 | |
| 843 | if (qid == QID_BEACON) { |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 844 | rt2800_register_write(rt2x00dev, BCN_TIME_CFG, 0); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 845 | return; |
| 846 | } |
| 847 | |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 848 | rt2800_register_read(rt2x00dev, WPDMA_RST_IDX, ®); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 849 | rt2x00_set_field32(®, WPDMA_RST_IDX_DTX_IDX0, (qid == QID_AC_BE)); |
| 850 | rt2x00_set_field32(®, WPDMA_RST_IDX_DTX_IDX1, (qid == QID_AC_BK)); |
| 851 | rt2x00_set_field32(®, WPDMA_RST_IDX_DTX_IDX2, (qid == QID_AC_VI)); |
| 852 | rt2x00_set_field32(®, WPDMA_RST_IDX_DTX_IDX3, (qid == QID_AC_VO)); |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 853 | rt2800_register_write(rt2x00dev, WPDMA_RST_IDX, reg); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 854 | } |
| 855 | |
| 856 | /* |
| 857 | * RX control handlers |
| 858 | */ |
| 859 | static void rt2800pci_fill_rxdone(struct queue_entry *entry, |
| 860 | struct rxdone_entry_desc *rxdesc) |
| 861 | { |
| 862 | struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev; |
| 863 | struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb); |
| 864 | struct queue_entry_priv_pci *entry_priv = entry->priv_data; |
| 865 | __le32 *rxd = entry_priv->desc; |
| 866 | __le32 *rxwi = (__le32 *)entry->skb->data; |
| 867 | u32 rxd3; |
| 868 | u32 rxwi0; |
| 869 | u32 rxwi1; |
| 870 | u32 rxwi2; |
| 871 | u32 rxwi3; |
| 872 | |
| 873 | rt2x00_desc_read(rxd, 3, &rxd3); |
| 874 | rt2x00_desc_read(rxwi, 0, &rxwi0); |
| 875 | rt2x00_desc_read(rxwi, 1, &rxwi1); |
| 876 | rt2x00_desc_read(rxwi, 2, &rxwi2); |
| 877 | rt2x00_desc_read(rxwi, 3, &rxwi3); |
| 878 | |
| 879 | if (rt2x00_get_field32(rxd3, RXD_W3_CRC_ERROR)) |
| 880 | rxdesc->flags |= RX_FLAG_FAILED_FCS_CRC; |
| 881 | |
| 882 | if (test_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags)) { |
| 883 | /* |
| 884 | * Unfortunately we don't know the cipher type used during |
| 885 | * decryption. This prevents us from correct providing |
| 886 | * correct statistics through debugfs. |
| 887 | */ |
| 888 | rxdesc->cipher = rt2x00_get_field32(rxwi0, RXWI_W0_UDF); |
| 889 | rxdesc->cipher_status = |
| 890 | rt2x00_get_field32(rxd3, RXD_W3_CIPHER_ERROR); |
| 891 | } |
| 892 | |
| 893 | if (rt2x00_get_field32(rxd3, RXD_W3_DECRYPTED)) { |
| 894 | /* |
| 895 | * Hardware has stripped IV/EIV data from 802.11 frame during |
| 896 | * decryption. Unfortunately the descriptor doesn't contain |
| 897 | * any fields with the EIV/IV data either, so they can't |
| 898 | * be restored by rt2x00lib. |
| 899 | */ |
| 900 | rxdesc->flags |= RX_FLAG_IV_STRIPPED; |
| 901 | |
| 902 | if (rxdesc->cipher_status == RX_CRYPTO_SUCCESS) |
| 903 | rxdesc->flags |= RX_FLAG_DECRYPTED; |
| 904 | else if (rxdesc->cipher_status == RX_CRYPTO_FAIL_MIC) |
| 905 | rxdesc->flags |= RX_FLAG_MMIC_ERROR; |
| 906 | } |
| 907 | |
| 908 | if (rt2x00_get_field32(rxd3, RXD_W3_MY_BSS)) |
| 909 | rxdesc->dev_flags |= RXDONE_MY_BSS; |
| 910 | |
| 911 | if (rt2x00_get_field32(rxd3, RXD_W3_L2PAD)) { |
| 912 | rxdesc->dev_flags |= RXDONE_L2PAD; |
| 913 | skbdesc->flags |= SKBDESC_L2_PADDED; |
| 914 | } |
| 915 | |
| 916 | if (rt2x00_get_field32(rxwi1, RXWI_W1_SHORT_GI)) |
| 917 | rxdesc->flags |= RX_FLAG_SHORT_GI; |
| 918 | |
| 919 | if (rt2x00_get_field32(rxwi1, RXWI_W1_BW)) |
| 920 | rxdesc->flags |= RX_FLAG_40MHZ; |
| 921 | |
| 922 | /* |
| 923 | * Detect RX rate, always use MCS as signal type. |
| 924 | */ |
| 925 | rxdesc->dev_flags |= RXDONE_SIGNAL_MCS; |
| 926 | rxdesc->rate_mode = rt2x00_get_field32(rxwi1, RXWI_W1_PHYMODE); |
| 927 | rxdesc->signal = rt2x00_get_field32(rxwi1, RXWI_W1_MCS); |
| 928 | |
| 929 | /* |
| 930 | * Mask of 0x8 bit to remove the short preamble flag. |
| 931 | */ |
| 932 | if (rxdesc->rate_mode == RATE_MODE_CCK) |
| 933 | rxdesc->signal &= ~0x8; |
| 934 | |
| 935 | rxdesc->rssi = |
| 936 | (rt2x00_get_field32(rxwi2, RXWI_W2_RSSI0) + |
| 937 | rt2x00_get_field32(rxwi2, RXWI_W2_RSSI1)) / 2; |
| 938 | |
| 939 | rxdesc->noise = |
| 940 | (rt2x00_get_field32(rxwi3, RXWI_W3_SNR0) + |
| 941 | rt2x00_get_field32(rxwi3, RXWI_W3_SNR1)) / 2; |
| 942 | |
| 943 | rxdesc->size = rt2x00_get_field32(rxwi0, RXWI_W0_MPDU_TOTAL_BYTE_COUNT); |
| 944 | |
| 945 | /* |
| 946 | * Set RX IDX in register to inform hardware that we have handled |
| 947 | * this entry and it is available for reuse again. |
| 948 | */ |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 949 | rt2800_register_write(rt2x00dev, RX_CRX_IDX, entry->entry_idx); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 950 | |
| 951 | /* |
| 952 | * Remove TXWI descriptor from start of buffer. |
| 953 | */ |
| 954 | skb_pull(entry->skb, RXWI_DESC_SIZE); |
| 955 | skb_trim(entry->skb, rxdesc->size); |
| 956 | } |
| 957 | |
| 958 | /* |
| 959 | * Interrupt functions. |
| 960 | */ |
| 961 | static void rt2800pci_txdone(struct rt2x00_dev *rt2x00dev) |
| 962 | { |
| 963 | struct data_queue *queue; |
| 964 | struct queue_entry *entry; |
| 965 | struct queue_entry *entry_done; |
| 966 | struct queue_entry_priv_pci *entry_priv; |
| 967 | struct txdone_entry_desc txdesc; |
| 968 | u32 word; |
| 969 | u32 reg; |
| 970 | u32 old_reg; |
| 971 | unsigned int type; |
| 972 | unsigned int index; |
| 973 | u16 mcs, real_mcs; |
| 974 | |
| 975 | /* |
| 976 | * During each loop we will compare the freshly read |
| 977 | * TX_STA_FIFO register value with the value read from |
| 978 | * the previous loop. If the 2 values are equal then |
| 979 | * we should stop processing because the chance it |
| 980 | * quite big that the device has been unplugged and |
| 981 | * we risk going into an endless loop. |
| 982 | */ |
| 983 | old_reg = 0; |
| 984 | |
| 985 | while (1) { |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 986 | rt2800_register_read(rt2x00dev, TX_STA_FIFO, ®); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 987 | if (!rt2x00_get_field32(reg, TX_STA_FIFO_VALID)) |
| 988 | break; |
| 989 | |
| 990 | if (old_reg == reg) |
| 991 | break; |
| 992 | old_reg = reg; |
| 993 | |
| 994 | /* |
| 995 | * Skip this entry when it contains an invalid |
| 996 | * queue identication number. |
| 997 | */ |
| 998 | type = rt2x00_get_field32(reg, TX_STA_FIFO_PID_TYPE) - 1; |
| 999 | if (type >= QID_RX) |
| 1000 | continue; |
| 1001 | |
| 1002 | queue = rt2x00queue_get_queue(rt2x00dev, type); |
| 1003 | if (unlikely(!queue)) |
| 1004 | continue; |
| 1005 | |
| 1006 | /* |
| 1007 | * Skip this entry when it contains an invalid |
| 1008 | * index number. |
| 1009 | */ |
| 1010 | index = rt2x00_get_field32(reg, TX_STA_FIFO_WCID) - 1; |
| 1011 | if (unlikely(index >= queue->limit)) |
| 1012 | continue; |
| 1013 | |
| 1014 | entry = &queue->entries[index]; |
| 1015 | entry_priv = entry->priv_data; |
| 1016 | rt2x00_desc_read((__le32 *)entry->skb->data, 0, &word); |
| 1017 | |
| 1018 | entry_done = rt2x00queue_get_entry(queue, Q_INDEX_DONE); |
| 1019 | while (entry != entry_done) { |
| 1020 | /* |
| 1021 | * Catch up. |
| 1022 | * Just report any entries we missed as failed. |
| 1023 | */ |
| 1024 | WARNING(rt2x00dev, |
| 1025 | "TX status report missed for entry %d\n", |
| 1026 | entry_done->entry_idx); |
| 1027 | |
| 1028 | txdesc.flags = 0; |
| 1029 | __set_bit(TXDONE_UNKNOWN, &txdesc.flags); |
| 1030 | txdesc.retry = 0; |
| 1031 | |
| 1032 | rt2x00lib_txdone(entry_done, &txdesc); |
| 1033 | entry_done = rt2x00queue_get_entry(queue, Q_INDEX_DONE); |
| 1034 | } |
| 1035 | |
| 1036 | /* |
| 1037 | * Obtain the status about this packet. |
| 1038 | */ |
| 1039 | txdesc.flags = 0; |
| 1040 | if (rt2x00_get_field32(reg, TX_STA_FIFO_TX_SUCCESS)) |
| 1041 | __set_bit(TXDONE_SUCCESS, &txdesc.flags); |
| 1042 | else |
| 1043 | __set_bit(TXDONE_FAILURE, &txdesc.flags); |
| 1044 | |
| 1045 | /* |
| 1046 | * Ralink has a retry mechanism using a global fallback |
| 1047 | * table. We setup this fallback table to try immediate |
| 1048 | * lower rate for all rates. In the TX_STA_FIFO, |
| 1049 | * the MCS field contains the MCS used for the successfull |
| 1050 | * transmission. If the first transmission succeed, |
| 1051 | * we have mcs == tx_mcs. On the second transmission, |
| 1052 | * we have mcs = tx_mcs - 1. So the number of |
| 1053 | * retry is (tx_mcs - mcs). |
| 1054 | */ |
| 1055 | mcs = rt2x00_get_field32(word, TXWI_W0_MCS); |
| 1056 | real_mcs = rt2x00_get_field32(reg, TX_STA_FIFO_MCS); |
| 1057 | __set_bit(TXDONE_FALLBACK, &txdesc.flags); |
| 1058 | txdesc.retry = mcs - min(mcs, real_mcs); |
| 1059 | |
| 1060 | rt2x00lib_txdone(entry, &txdesc); |
| 1061 | } |
| 1062 | } |
| 1063 | |
| 1064 | static irqreturn_t rt2800pci_interrupt(int irq, void *dev_instance) |
| 1065 | { |
| 1066 | struct rt2x00_dev *rt2x00dev = dev_instance; |
| 1067 | u32 reg; |
| 1068 | |
| 1069 | /* Read status and ACK all interrupts */ |
Bartlomiej Zolnierkiewicz | 9ca21eb | 2009-11-04 18:33:13 +0100 | [diff] [blame] | 1070 | rt2800_register_read(rt2x00dev, INT_SOURCE_CSR, ®); |
| 1071 | rt2800_register_write(rt2x00dev, INT_SOURCE_CSR, reg); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 1072 | |
| 1073 | if (!reg) |
| 1074 | return IRQ_NONE; |
| 1075 | |
| 1076 | if (!test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags)) |
| 1077 | return IRQ_HANDLED; |
| 1078 | |
| 1079 | /* |
| 1080 | * 1 - Rx ring done interrupt. |
| 1081 | */ |
| 1082 | if (rt2x00_get_field32(reg, INT_SOURCE_CSR_RX_DONE)) |
| 1083 | rt2x00pci_rxdone(rt2x00dev); |
| 1084 | |
| 1085 | if (rt2x00_get_field32(reg, INT_SOURCE_CSR_TX_FIFO_STATUS)) |
| 1086 | rt2800pci_txdone(rt2x00dev); |
| 1087 | |
| 1088 | return IRQ_HANDLED; |
| 1089 | } |
| 1090 | |
| 1091 | /* |
| 1092 | * Device probe functions. |
| 1093 | */ |
Bartlomiej Zolnierkiewicz | 7ab7132 | 2009-11-08 14:38:54 +0100 | [diff] [blame] | 1094 | static int rt2800pci_validate_eeprom(struct rt2x00_dev *rt2x00dev) |
| 1095 | { |
| 1096 | /* |
| 1097 | * Read EEPROM into buffer |
| 1098 | */ |
| 1099 | switch (rt2x00dev->chip.rt) { |
| 1100 | case RT2880: |
| 1101 | case RT3052: |
| 1102 | rt2800pci_read_eeprom_soc(rt2x00dev); |
| 1103 | break; |
| 1104 | default: |
| 1105 | if (rt2800pci_efuse_detect(rt2x00dev)) |
| 1106 | rt2800pci_read_eeprom_efuse(rt2x00dev); |
| 1107 | else |
| 1108 | rt2800pci_read_eeprom_pci(rt2x00dev); |
| 1109 | break; |
| 1110 | } |
| 1111 | |
| 1112 | return rt2800_validate_eeprom(rt2x00dev); |
| 1113 | } |
| 1114 | |
Bartlomiej Zolnierkiewicz | b0a1eda | 2009-11-04 18:35:00 +0100 | [diff] [blame] | 1115 | static const struct rt2800_ops rt2800pci_rt2800_ops = { |
| 1116 | .register_read = rt2x00pci_register_read, |
| 1117 | .register_write = rt2x00pci_register_write, |
| 1118 | .register_write_lock = rt2x00pci_register_write, /* same for PCI */ |
| 1119 | |
| 1120 | .register_multiread = rt2x00pci_register_multiread, |
| 1121 | .register_multiwrite = rt2x00pci_register_multiwrite, |
| 1122 | |
| 1123 | .regbusy_read = rt2x00pci_regbusy_read, |
| 1124 | }; |
| 1125 | |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 1126 | static int rt2800pci_probe_hw(struct rt2x00_dev *rt2x00dev) |
| 1127 | { |
| 1128 | int retval; |
| 1129 | |
Bartlomiej Zolnierkiewicz | b0a1eda | 2009-11-04 18:35:00 +0100 | [diff] [blame] | 1130 | rt2x00dev->priv = (void *)&rt2800pci_rt2800_ops; |
| 1131 | |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 1132 | /* |
| 1133 | * Allocate eeprom data. |
| 1134 | */ |
| 1135 | retval = rt2800pci_validate_eeprom(rt2x00dev); |
| 1136 | if (retval) |
| 1137 | return retval; |
| 1138 | |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 1139 | retval = rt2800_init_eeprom(rt2x00dev); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 1140 | if (retval) |
| 1141 | return retval; |
| 1142 | |
| 1143 | /* |
| 1144 | * Initialize hw specifications. |
| 1145 | */ |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 1146 | retval = rt2800_probe_hw_mode(rt2x00dev); |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 1147 | if (retval) |
| 1148 | return retval; |
| 1149 | |
| 1150 | /* |
| 1151 | * This device has multiple filters for control frames |
| 1152 | * and has a separate filter for PS Poll frames. |
| 1153 | */ |
| 1154 | __set_bit(DRIVER_SUPPORT_CONTROL_FILTERS, &rt2x00dev->flags); |
| 1155 | __set_bit(DRIVER_SUPPORT_CONTROL_FILTER_PSPOLL, &rt2x00dev->flags); |
| 1156 | |
| 1157 | /* |
| 1158 | * This device requires firmware. |
| 1159 | */ |
| 1160 | if (!rt2x00_rt(&rt2x00dev->chip, RT2880) && |
| 1161 | !rt2x00_rt(&rt2x00dev->chip, RT3052)) |
| 1162 | __set_bit(DRIVER_REQUIRE_FIRMWARE, &rt2x00dev->flags); |
| 1163 | __set_bit(DRIVER_REQUIRE_DMA, &rt2x00dev->flags); |
| 1164 | __set_bit(DRIVER_REQUIRE_L2PAD, &rt2x00dev->flags); |
| 1165 | if (!modparam_nohwcrypt) |
| 1166 | __set_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags); |
| 1167 | |
| 1168 | /* |
| 1169 | * Set the rssi offset. |
| 1170 | */ |
| 1171 | rt2x00dev->rssi_offset = DEFAULT_RSSI_OFFSET; |
| 1172 | |
| 1173 | return 0; |
| 1174 | } |
| 1175 | |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 1176 | static const struct rt2x00lib_ops rt2800pci_rt2x00_ops = { |
| 1177 | .irq_handler = rt2800pci_interrupt, |
| 1178 | .probe_hw = rt2800pci_probe_hw, |
| 1179 | .get_firmware_name = rt2800pci_get_firmware_name, |
| 1180 | .check_firmware = rt2800pci_check_firmware, |
| 1181 | .load_firmware = rt2800pci_load_firmware, |
| 1182 | .initialize = rt2x00pci_initialize, |
| 1183 | .uninitialize = rt2x00pci_uninitialize, |
| 1184 | .get_entry_state = rt2800pci_get_entry_state, |
| 1185 | .clear_entry = rt2800pci_clear_entry, |
| 1186 | .set_device_state = rt2800pci_set_device_state, |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1187 | .rfkill_poll = rt2800_rfkill_poll, |
| 1188 | .link_stats = rt2800_link_stats, |
| 1189 | .reset_tuner = rt2800_reset_tuner, |
| 1190 | .link_tuner = rt2800_link_tuner, |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 1191 | .write_tx_desc = rt2800pci_write_tx_desc, |
| 1192 | .write_tx_data = rt2x00pci_write_tx_data, |
| 1193 | .write_beacon = rt2800pci_write_beacon, |
| 1194 | .kick_tx_queue = rt2800pci_kick_tx_queue, |
| 1195 | .kill_tx_queue = rt2800pci_kill_tx_queue, |
| 1196 | .fill_rxdone = rt2800pci_fill_rxdone, |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1197 | .config_shared_key = rt2800_config_shared_key, |
| 1198 | .config_pairwise_key = rt2800_config_pairwise_key, |
| 1199 | .config_filter = rt2800_config_filter, |
| 1200 | .config_intf = rt2800_config_intf, |
| 1201 | .config_erp = rt2800_config_erp, |
| 1202 | .config_ant = rt2800_config_ant, |
| 1203 | .config = rt2800_config, |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 1204 | }; |
| 1205 | |
| 1206 | static const struct data_queue_desc rt2800pci_queue_rx = { |
| 1207 | .entry_num = RX_ENTRIES, |
| 1208 | .data_size = AGGREGATION_SIZE, |
| 1209 | .desc_size = RXD_DESC_SIZE, |
| 1210 | .priv_size = sizeof(struct queue_entry_priv_pci), |
| 1211 | }; |
| 1212 | |
| 1213 | static const struct data_queue_desc rt2800pci_queue_tx = { |
| 1214 | .entry_num = TX_ENTRIES, |
| 1215 | .data_size = AGGREGATION_SIZE, |
| 1216 | .desc_size = TXD_DESC_SIZE, |
| 1217 | .priv_size = sizeof(struct queue_entry_priv_pci), |
| 1218 | }; |
| 1219 | |
| 1220 | static const struct data_queue_desc rt2800pci_queue_bcn = { |
| 1221 | .entry_num = 8 * BEACON_ENTRIES, |
| 1222 | .data_size = 0, /* No DMA required for beacons */ |
| 1223 | .desc_size = TXWI_DESC_SIZE, |
| 1224 | .priv_size = sizeof(struct queue_entry_priv_pci), |
| 1225 | }; |
| 1226 | |
| 1227 | static const struct rt2x00_ops rt2800pci_ops = { |
| 1228 | .name = KBUILD_MODNAME, |
| 1229 | .max_sta_intf = 1, |
| 1230 | .max_ap_intf = 8, |
| 1231 | .eeprom_size = EEPROM_SIZE, |
| 1232 | .rf_size = RF_SIZE, |
| 1233 | .tx_queues = NUM_TX_QUEUES, |
| 1234 | .rx = &rt2800pci_queue_rx, |
| 1235 | .tx = &rt2800pci_queue_tx, |
| 1236 | .bcn = &rt2800pci_queue_bcn, |
| 1237 | .lib = &rt2800pci_rt2x00_ops, |
Bartlomiej Zolnierkiewicz | 2ce3399 | 2009-11-04 18:37:05 +0100 | [diff] [blame] | 1238 | .hw = &rt2800_mac80211_ops, |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 1239 | #ifdef CONFIG_RT2X00_LIB_DEBUGFS |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1240 | .debugfs = &rt2800_rt2x00debug, |
Ivo van Doorn | a9b3a9f | 2009-10-15 22:04:14 +0200 | [diff] [blame] | 1241 | #endif /* CONFIG_RT2X00_LIB_DEBUGFS */ |
| 1242 | }; |
| 1243 | |
| 1244 | /* |
| 1245 | * RT2800pci module information. |
| 1246 | */ |
| 1247 | static struct pci_device_id rt2800pci_device_table[] = { |
| 1248 | { PCI_DEVICE(0x1462, 0x891a), PCI_DEVICE_DATA(&rt2800pci_ops) }, |
| 1249 | { PCI_DEVICE(0x1432, 0x7708), PCI_DEVICE_DATA(&rt2800pci_ops) }, |
| 1250 | { PCI_DEVICE(0x1432, 0x7727), PCI_DEVICE_DATA(&rt2800pci_ops) }, |
| 1251 | { PCI_DEVICE(0x1432, 0x7728), PCI_DEVICE_DATA(&rt2800pci_ops) }, |
| 1252 | { PCI_DEVICE(0x1432, 0x7738), PCI_DEVICE_DATA(&rt2800pci_ops) }, |
| 1253 | { PCI_DEVICE(0x1432, 0x7748), PCI_DEVICE_DATA(&rt2800pci_ops) }, |
| 1254 | { PCI_DEVICE(0x1432, 0x7758), PCI_DEVICE_DATA(&rt2800pci_ops) }, |
| 1255 | { PCI_DEVICE(0x1432, 0x7768), PCI_DEVICE_DATA(&rt2800pci_ops) }, |
| 1256 | { PCI_DEVICE(0x1814, 0x0601), PCI_DEVICE_DATA(&rt2800pci_ops) }, |
| 1257 | { PCI_DEVICE(0x1814, 0x0681), PCI_DEVICE_DATA(&rt2800pci_ops) }, |
| 1258 | { PCI_DEVICE(0x1814, 0x0701), PCI_DEVICE_DATA(&rt2800pci_ops) }, |
| 1259 | { PCI_DEVICE(0x1814, 0x0781), PCI_DEVICE_DATA(&rt2800pci_ops) }, |
| 1260 | { PCI_DEVICE(0x1814, 0x3060), PCI_DEVICE_DATA(&rt2800pci_ops) }, |
| 1261 | { PCI_DEVICE(0x1814, 0x3062), PCI_DEVICE_DATA(&rt2800pci_ops) }, |
| 1262 | { PCI_DEVICE(0x1814, 0x3090), PCI_DEVICE_DATA(&rt2800pci_ops) }, |
| 1263 | { PCI_DEVICE(0x1814, 0x3091), PCI_DEVICE_DATA(&rt2800pci_ops) }, |
| 1264 | { PCI_DEVICE(0x1814, 0x3092), PCI_DEVICE_DATA(&rt2800pci_ops) }, |
| 1265 | { PCI_DEVICE(0x1814, 0x3562), PCI_DEVICE_DATA(&rt2800pci_ops) }, |
| 1266 | { PCI_DEVICE(0x1814, 0x3592), PCI_DEVICE_DATA(&rt2800pci_ops) }, |
| 1267 | { PCI_DEVICE(0x1a3b, 0x1059), PCI_DEVICE_DATA(&rt2800pci_ops) }, |
| 1268 | { 0, } |
| 1269 | }; |
| 1270 | |
| 1271 | MODULE_AUTHOR(DRV_PROJECT); |
| 1272 | MODULE_VERSION(DRV_VERSION); |
| 1273 | MODULE_DESCRIPTION("Ralink RT2800 PCI & PCMCIA Wireless LAN driver."); |
| 1274 | MODULE_SUPPORTED_DEVICE("Ralink RT2860 PCI & PCMCIA chipset based cards"); |
| 1275 | #ifdef CONFIG_RT2800PCI_PCI |
| 1276 | MODULE_FIRMWARE(FIRMWARE_RT2860); |
| 1277 | MODULE_DEVICE_TABLE(pci, rt2800pci_device_table); |
| 1278 | #endif /* CONFIG_RT2800PCI_PCI */ |
| 1279 | MODULE_LICENSE("GPL"); |
| 1280 | |
| 1281 | #ifdef CONFIG_RT2800PCI_WISOC |
| 1282 | #if defined(CONFIG_RALINK_RT288X) |
| 1283 | __rt2x00soc_probe(RT2880, &rt2800pci_ops); |
| 1284 | #elif defined(CONFIG_RALINK_RT305X) |
| 1285 | __rt2x00soc_probe(RT3052, &rt2800pci_ops); |
| 1286 | #endif |
| 1287 | |
| 1288 | static struct platform_driver rt2800soc_driver = { |
| 1289 | .driver = { |
| 1290 | .name = "rt2800_wmac", |
| 1291 | .owner = THIS_MODULE, |
| 1292 | .mod_name = KBUILD_MODNAME, |
| 1293 | }, |
| 1294 | .probe = __rt2x00soc_probe, |
| 1295 | .remove = __devexit_p(rt2x00soc_remove), |
| 1296 | .suspend = rt2x00soc_suspend, |
| 1297 | .resume = rt2x00soc_resume, |
| 1298 | }; |
| 1299 | #endif /* CONFIG_RT2800PCI_WISOC */ |
| 1300 | |
| 1301 | #ifdef CONFIG_RT2800PCI_PCI |
| 1302 | static struct pci_driver rt2800pci_driver = { |
| 1303 | .name = KBUILD_MODNAME, |
| 1304 | .id_table = rt2800pci_device_table, |
| 1305 | .probe = rt2x00pci_probe, |
| 1306 | .remove = __devexit_p(rt2x00pci_remove), |
| 1307 | .suspend = rt2x00pci_suspend, |
| 1308 | .resume = rt2x00pci_resume, |
| 1309 | }; |
| 1310 | #endif /* CONFIG_RT2800PCI_PCI */ |
| 1311 | |
| 1312 | static int __init rt2800pci_init(void) |
| 1313 | { |
| 1314 | int ret = 0; |
| 1315 | |
| 1316 | #ifdef CONFIG_RT2800PCI_WISOC |
| 1317 | ret = platform_driver_register(&rt2800soc_driver); |
| 1318 | if (ret) |
| 1319 | return ret; |
| 1320 | #endif |
| 1321 | #ifdef CONFIG_RT2800PCI_PCI |
| 1322 | ret = pci_register_driver(&rt2800pci_driver); |
| 1323 | if (ret) { |
| 1324 | #ifdef CONFIG_RT2800PCI_WISOC |
| 1325 | platform_driver_unregister(&rt2800soc_driver); |
| 1326 | #endif |
| 1327 | return ret; |
| 1328 | } |
| 1329 | #endif |
| 1330 | |
| 1331 | return ret; |
| 1332 | } |
| 1333 | |
| 1334 | static void __exit rt2800pci_exit(void) |
| 1335 | { |
| 1336 | #ifdef CONFIG_RT2800PCI_PCI |
| 1337 | pci_unregister_driver(&rt2800pci_driver); |
| 1338 | #endif |
| 1339 | #ifdef CONFIG_RT2800PCI_WISOC |
| 1340 | platform_driver_unregister(&rt2800soc_driver); |
| 1341 | #endif |
| 1342 | } |
| 1343 | |
| 1344 | module_init(rt2800pci_init); |
| 1345 | module_exit(rt2800pci_exit); |