Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1 | /* |
Ivo van Doorn | 811aa9c | 2008-02-03 15:42:53 +0100 | [diff] [blame] | 2 | Copyright (C) 2004 - 2008 rt2x00 SourceForge Project |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 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: rt73usb |
| 23 | Abstract: rt73usb device specific routines. |
| 24 | Supported chipsets: rt2571W & rt2671. |
| 25 | */ |
| 26 | |
Ivo van Doorn | a7f3a06 | 2008-03-09 22:44:54 +0100 | [diff] [blame] | 27 | #include <linux/crc-itu-t.h> |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 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/usb.h> |
| 34 | |
| 35 | #include "rt2x00.h" |
| 36 | #include "rt2x00usb.h" |
| 37 | #include "rt73usb.h" |
| 38 | |
| 39 | /* |
| 40 | * Register access. |
| 41 | * All access to the CSR registers will go through the methods |
| 42 | * rt73usb_register_read and rt73usb_register_write. |
| 43 | * BBP and RF register require indirect register access, |
| 44 | * and use the CSR registers BBPCSR and RFCSR to achieve this. |
| 45 | * These indirect registers work with busy bits, |
| 46 | * and we will try maximal REGISTER_BUSY_COUNT times to access |
| 47 | * the register while taking a REGISTER_BUSY_DELAY us delay |
| 48 | * between each attampt. When the busy bit is still set at that time, |
| 49 | * the access attempt is considered to have failed, |
| 50 | * and we will print an error. |
Adam Baker | 3d82346 | 2007-10-27 13:43:29 +0200 | [diff] [blame] | 51 | * The _lock versions must be used if you already hold the usb_cache_mutex |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 52 | */ |
Adam Baker | 0e14f6d | 2007-10-27 13:41:25 +0200 | [diff] [blame] | 53 | static inline void rt73usb_register_read(struct rt2x00_dev *rt2x00dev, |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 54 | const unsigned int offset, u32 *value) |
| 55 | { |
| 56 | __le32 reg; |
| 57 | rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_READ, |
| 58 | USB_VENDOR_REQUEST_IN, offset, |
| 59 | ®, sizeof(u32), REGISTER_TIMEOUT); |
| 60 | *value = le32_to_cpu(reg); |
| 61 | } |
| 62 | |
Adam Baker | 3d82346 | 2007-10-27 13:43:29 +0200 | [diff] [blame] | 63 | static inline void rt73usb_register_read_lock(struct rt2x00_dev *rt2x00dev, |
| 64 | const unsigned int offset, u32 *value) |
| 65 | { |
| 66 | __le32 reg; |
| 67 | rt2x00usb_vendor_req_buff_lock(rt2x00dev, USB_MULTI_READ, |
| 68 | USB_VENDOR_REQUEST_IN, offset, |
| 69 | ®, sizeof(u32), REGISTER_TIMEOUT); |
| 70 | *value = le32_to_cpu(reg); |
| 71 | } |
| 72 | |
Adam Baker | 0e14f6d | 2007-10-27 13:41:25 +0200 | [diff] [blame] | 73 | static inline void rt73usb_register_multiread(struct rt2x00_dev *rt2x00dev, |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 74 | const unsigned int offset, |
| 75 | void *value, const u32 length) |
| 76 | { |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 77 | rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_READ, |
| 78 | USB_VENDOR_REQUEST_IN, offset, |
Ivo van Doorn | bd394a7 | 2008-04-21 19:01:58 +0200 | [diff] [blame] | 79 | value, length, |
| 80 | REGISTER_TIMEOUT32(length)); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 81 | } |
| 82 | |
Adam Baker | 0e14f6d | 2007-10-27 13:41:25 +0200 | [diff] [blame] | 83 | static inline void rt73usb_register_write(struct rt2x00_dev *rt2x00dev, |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 84 | const unsigned int offset, u32 value) |
| 85 | { |
| 86 | __le32 reg = cpu_to_le32(value); |
| 87 | rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_WRITE, |
| 88 | USB_VENDOR_REQUEST_OUT, offset, |
| 89 | ®, sizeof(u32), REGISTER_TIMEOUT); |
| 90 | } |
| 91 | |
Adam Baker | 3d82346 | 2007-10-27 13:43:29 +0200 | [diff] [blame] | 92 | static inline void rt73usb_register_write_lock(struct rt2x00_dev *rt2x00dev, |
| 93 | const unsigned int offset, u32 value) |
| 94 | { |
| 95 | __le32 reg = cpu_to_le32(value); |
| 96 | rt2x00usb_vendor_req_buff_lock(rt2x00dev, USB_MULTI_WRITE, |
| 97 | USB_VENDOR_REQUEST_OUT, offset, |
| 98 | ®, sizeof(u32), REGISTER_TIMEOUT); |
| 99 | } |
| 100 | |
Adam Baker | 0e14f6d | 2007-10-27 13:41:25 +0200 | [diff] [blame] | 101 | static inline void rt73usb_register_multiwrite(struct rt2x00_dev *rt2x00dev, |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 102 | const unsigned int offset, |
| 103 | void *value, const u32 length) |
| 104 | { |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 105 | rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_WRITE, |
| 106 | USB_VENDOR_REQUEST_OUT, offset, |
Ivo van Doorn | bd394a7 | 2008-04-21 19:01:58 +0200 | [diff] [blame] | 107 | value, length, |
| 108 | REGISTER_TIMEOUT32(length)); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Adam Baker | 0e14f6d | 2007-10-27 13:41:25 +0200 | [diff] [blame] | 111 | static u32 rt73usb_bbp_check(struct rt2x00_dev *rt2x00dev) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 112 | { |
| 113 | u32 reg; |
| 114 | unsigned int i; |
| 115 | |
| 116 | for (i = 0; i < REGISTER_BUSY_COUNT; i++) { |
Adam Baker | 3d82346 | 2007-10-27 13:43:29 +0200 | [diff] [blame] | 117 | rt73usb_register_read_lock(rt2x00dev, PHY_CSR3, ®); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 118 | if (!rt2x00_get_field32(reg, PHY_CSR3_BUSY)) |
| 119 | break; |
| 120 | udelay(REGISTER_BUSY_DELAY); |
| 121 | } |
| 122 | |
| 123 | return reg; |
| 124 | } |
| 125 | |
Adam Baker | 0e14f6d | 2007-10-27 13:41:25 +0200 | [diff] [blame] | 126 | static void rt73usb_bbp_write(struct rt2x00_dev *rt2x00dev, |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 127 | const unsigned int word, const u8 value) |
| 128 | { |
| 129 | u32 reg; |
| 130 | |
Adam Baker | 3d82346 | 2007-10-27 13:43:29 +0200 | [diff] [blame] | 131 | mutex_lock(&rt2x00dev->usb_cache_mutex); |
| 132 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 133 | /* |
| 134 | * Wait until the BBP becomes ready. |
| 135 | */ |
| 136 | reg = rt73usb_bbp_check(rt2x00dev); |
Ivo van Doorn | 99ade25 | 2008-06-20 22:11:00 +0200 | [diff] [blame] | 137 | if (rt2x00_get_field32(reg, PHY_CSR3_BUSY)) |
| 138 | goto exit_fail; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 139 | |
| 140 | /* |
| 141 | * Write the data into the BBP. |
| 142 | */ |
| 143 | reg = 0; |
| 144 | rt2x00_set_field32(®, PHY_CSR3_VALUE, value); |
| 145 | rt2x00_set_field32(®, PHY_CSR3_REGNUM, word); |
| 146 | rt2x00_set_field32(®, PHY_CSR3_BUSY, 1); |
| 147 | rt2x00_set_field32(®, PHY_CSR3_READ_CONTROL, 0); |
| 148 | |
Adam Baker | 3d82346 | 2007-10-27 13:43:29 +0200 | [diff] [blame] | 149 | rt73usb_register_write_lock(rt2x00dev, PHY_CSR3, reg); |
| 150 | mutex_unlock(&rt2x00dev->usb_cache_mutex); |
Ivo van Doorn | 99ade25 | 2008-06-20 22:11:00 +0200 | [diff] [blame] | 151 | |
| 152 | return; |
| 153 | |
| 154 | exit_fail: |
| 155 | mutex_unlock(&rt2x00dev->usb_cache_mutex); |
| 156 | |
| 157 | ERROR(rt2x00dev, "PHY_CSR3 register busy. Write failed.\n"); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 158 | } |
| 159 | |
Adam Baker | 0e14f6d | 2007-10-27 13:41:25 +0200 | [diff] [blame] | 160 | static void rt73usb_bbp_read(struct rt2x00_dev *rt2x00dev, |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 161 | const unsigned int word, u8 *value) |
| 162 | { |
| 163 | u32 reg; |
| 164 | |
Adam Baker | 3d82346 | 2007-10-27 13:43:29 +0200 | [diff] [blame] | 165 | mutex_lock(&rt2x00dev->usb_cache_mutex); |
| 166 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 167 | /* |
| 168 | * Wait until the BBP becomes ready. |
| 169 | */ |
| 170 | reg = rt73usb_bbp_check(rt2x00dev); |
Ivo van Doorn | 99ade25 | 2008-06-20 22:11:00 +0200 | [diff] [blame] | 171 | if (rt2x00_get_field32(reg, PHY_CSR3_BUSY)) |
| 172 | goto exit_fail; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 173 | |
| 174 | /* |
| 175 | * Write the request into the BBP. |
| 176 | */ |
| 177 | reg = 0; |
| 178 | rt2x00_set_field32(®, PHY_CSR3_REGNUM, word); |
| 179 | rt2x00_set_field32(®, PHY_CSR3_BUSY, 1); |
| 180 | rt2x00_set_field32(®, PHY_CSR3_READ_CONTROL, 1); |
| 181 | |
Adam Baker | 3d82346 | 2007-10-27 13:43:29 +0200 | [diff] [blame] | 182 | rt73usb_register_write_lock(rt2x00dev, PHY_CSR3, reg); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 183 | |
| 184 | /* |
| 185 | * Wait until the BBP becomes ready. |
| 186 | */ |
| 187 | reg = rt73usb_bbp_check(rt2x00dev); |
Ivo van Doorn | 99ade25 | 2008-06-20 22:11:00 +0200 | [diff] [blame] | 188 | if (rt2x00_get_field32(reg, PHY_CSR3_BUSY)) |
| 189 | goto exit_fail; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 190 | |
| 191 | *value = rt2x00_get_field32(reg, PHY_CSR3_VALUE); |
Adam Baker | 3d82346 | 2007-10-27 13:43:29 +0200 | [diff] [blame] | 192 | mutex_unlock(&rt2x00dev->usb_cache_mutex); |
Ivo van Doorn | 99ade25 | 2008-06-20 22:11:00 +0200 | [diff] [blame] | 193 | |
| 194 | return; |
| 195 | |
| 196 | exit_fail: |
| 197 | mutex_unlock(&rt2x00dev->usb_cache_mutex); |
| 198 | |
| 199 | ERROR(rt2x00dev, "PHY_CSR3 register busy. Read failed.\n"); |
| 200 | *value = 0xff; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 201 | } |
| 202 | |
Adam Baker | 0e14f6d | 2007-10-27 13:41:25 +0200 | [diff] [blame] | 203 | static void rt73usb_rf_write(struct rt2x00_dev *rt2x00dev, |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 204 | const unsigned int word, const u32 value) |
| 205 | { |
| 206 | u32 reg; |
| 207 | unsigned int i; |
| 208 | |
| 209 | if (!word) |
| 210 | return; |
| 211 | |
Adam Baker | 3d82346 | 2007-10-27 13:43:29 +0200 | [diff] [blame] | 212 | mutex_lock(&rt2x00dev->usb_cache_mutex); |
| 213 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 214 | for (i = 0; i < REGISTER_BUSY_COUNT; i++) { |
Adam Baker | 3d82346 | 2007-10-27 13:43:29 +0200 | [diff] [blame] | 215 | rt73usb_register_read_lock(rt2x00dev, PHY_CSR4, ®); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 216 | if (!rt2x00_get_field32(reg, PHY_CSR4_BUSY)) |
| 217 | goto rf_write; |
| 218 | udelay(REGISTER_BUSY_DELAY); |
| 219 | } |
| 220 | |
Adam Baker | 3d82346 | 2007-10-27 13:43:29 +0200 | [diff] [blame] | 221 | mutex_unlock(&rt2x00dev->usb_cache_mutex); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 222 | ERROR(rt2x00dev, "PHY_CSR4 register busy. Write failed.\n"); |
| 223 | return; |
| 224 | |
| 225 | rf_write: |
| 226 | reg = 0; |
| 227 | rt2x00_set_field32(®, PHY_CSR4_VALUE, value); |
| 228 | |
Ivo van Doorn | 4f5af6eb | 2007-10-06 14:16:30 +0200 | [diff] [blame] | 229 | /* |
| 230 | * RF5225 and RF2527 contain 21 bits per RF register value, |
| 231 | * all others contain 20 bits. |
| 232 | */ |
| 233 | rt2x00_set_field32(®, PHY_CSR4_NUMBER_OF_BITS, |
Ivo van Doorn | ddc827f | 2007-10-13 16:26:42 +0200 | [diff] [blame] | 234 | 20 + (rt2x00_rf(&rt2x00dev->chip, RF5225) || |
| 235 | rt2x00_rf(&rt2x00dev->chip, RF2527))); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 236 | rt2x00_set_field32(®, PHY_CSR4_IF_SELECT, 0); |
| 237 | rt2x00_set_field32(®, PHY_CSR4_BUSY, 1); |
| 238 | |
Adam Baker | 3d82346 | 2007-10-27 13:43:29 +0200 | [diff] [blame] | 239 | rt73usb_register_write_lock(rt2x00dev, PHY_CSR4, reg); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 240 | rt2x00_rf_write(rt2x00dev, word, value); |
Adam Baker | 3d82346 | 2007-10-27 13:43:29 +0200 | [diff] [blame] | 241 | mutex_unlock(&rt2x00dev->usb_cache_mutex); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | #ifdef CONFIG_RT2X00_LIB_DEBUGFS |
| 245 | #define CSR_OFFSET(__word) ( CSR_REG_BASE + ((__word) * sizeof(u32)) ) |
| 246 | |
Adam Baker | 0e14f6d | 2007-10-27 13:41:25 +0200 | [diff] [blame] | 247 | static void rt73usb_read_csr(struct rt2x00_dev *rt2x00dev, |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 248 | const unsigned int word, u32 *data) |
| 249 | { |
| 250 | rt73usb_register_read(rt2x00dev, CSR_OFFSET(word), data); |
| 251 | } |
| 252 | |
Adam Baker | 0e14f6d | 2007-10-27 13:41:25 +0200 | [diff] [blame] | 253 | static void rt73usb_write_csr(struct rt2x00_dev *rt2x00dev, |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 254 | const unsigned int word, u32 data) |
| 255 | { |
| 256 | rt73usb_register_write(rt2x00dev, CSR_OFFSET(word), data); |
| 257 | } |
| 258 | |
| 259 | static const struct rt2x00debug rt73usb_rt2x00debug = { |
| 260 | .owner = THIS_MODULE, |
| 261 | .csr = { |
| 262 | .read = rt73usb_read_csr, |
| 263 | .write = rt73usb_write_csr, |
| 264 | .word_size = sizeof(u32), |
| 265 | .word_count = CSR_REG_SIZE / sizeof(u32), |
| 266 | }, |
| 267 | .eeprom = { |
| 268 | .read = rt2x00_eeprom_read, |
| 269 | .write = rt2x00_eeprom_write, |
| 270 | .word_size = sizeof(u16), |
| 271 | .word_count = EEPROM_SIZE / sizeof(u16), |
| 272 | }, |
| 273 | .bbp = { |
| 274 | .read = rt73usb_bbp_read, |
| 275 | .write = rt73usb_bbp_write, |
| 276 | .word_size = sizeof(u8), |
| 277 | .word_count = BBP_SIZE / sizeof(u8), |
| 278 | }, |
| 279 | .rf = { |
| 280 | .read = rt2x00_rf_read, |
| 281 | .write = rt73usb_rf_write, |
| 282 | .word_size = sizeof(u32), |
| 283 | .word_count = RF_SIZE / sizeof(u32), |
| 284 | }, |
| 285 | }; |
| 286 | #endif /* CONFIG_RT2X00_LIB_DEBUGFS */ |
| 287 | |
Ivo van Doorn | a9450b7 | 2008-02-03 15:53:40 +0100 | [diff] [blame] | 288 | #ifdef CONFIG_RT73USB_LEDS |
Ivo van Doorn | a2e1d52 | 2008-03-31 15:53:44 +0200 | [diff] [blame] | 289 | static void rt73usb_brightness_set(struct led_classdev *led_cdev, |
Ivo van Doorn | a9450b7 | 2008-02-03 15:53:40 +0100 | [diff] [blame] | 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 a_mode = |
| 296 | (enabled && led->rt2x00dev->curr_band == IEEE80211_BAND_5GHZ); |
| 297 | unsigned int bg_mode = |
| 298 | (enabled && led->rt2x00dev->curr_band == IEEE80211_BAND_2GHZ); |
| 299 | |
| 300 | if (led->type == LED_TYPE_RADIO) { |
| 301 | rt2x00_set_field16(&led->rt2x00dev->led_mcu_reg, |
| 302 | MCU_LEDCS_RADIO_STATUS, enabled); |
| 303 | |
Ivo van Doorn | 47b10cd | 2008-02-17 17:35:28 +0100 | [diff] [blame] | 304 | rt2x00usb_vendor_request_sw(led->rt2x00dev, USB_LED_CONTROL, |
| 305 | 0, led->rt2x00dev->led_mcu_reg, |
| 306 | REGISTER_TIMEOUT); |
Ivo van Doorn | a9450b7 | 2008-02-03 15:53:40 +0100 | [diff] [blame] | 307 | } else if (led->type == LED_TYPE_ASSOC) { |
| 308 | rt2x00_set_field16(&led->rt2x00dev->led_mcu_reg, |
| 309 | MCU_LEDCS_LINK_BG_STATUS, bg_mode); |
| 310 | rt2x00_set_field16(&led->rt2x00dev->led_mcu_reg, |
| 311 | MCU_LEDCS_LINK_A_STATUS, a_mode); |
| 312 | |
Ivo van Doorn | 47b10cd | 2008-02-17 17:35:28 +0100 | [diff] [blame] | 313 | rt2x00usb_vendor_request_sw(led->rt2x00dev, USB_LED_CONTROL, |
| 314 | 0, led->rt2x00dev->led_mcu_reg, |
| 315 | REGISTER_TIMEOUT); |
Ivo van Doorn | a9450b7 | 2008-02-03 15:53:40 +0100 | [diff] [blame] | 316 | } else if (led->type == LED_TYPE_QUALITY) { |
| 317 | /* |
| 318 | * The brightness is divided into 6 levels (0 - 5), |
| 319 | * this means we need to convert the brightness |
| 320 | * argument into the matching level within that range. |
| 321 | */ |
Ivo van Doorn | 47b10cd | 2008-02-17 17:35:28 +0100 | [diff] [blame] | 322 | rt2x00usb_vendor_request_sw(led->rt2x00dev, USB_LED_CONTROL, |
| 323 | brightness / (LED_FULL / 6), |
| 324 | led->rt2x00dev->led_mcu_reg, |
| 325 | REGISTER_TIMEOUT); |
Ivo van Doorn | a9450b7 | 2008-02-03 15:53:40 +0100 | [diff] [blame] | 326 | } |
| 327 | } |
Ivo van Doorn | a2e1d52 | 2008-03-31 15:53:44 +0200 | [diff] [blame] | 328 | |
| 329 | static int rt73usb_blink_set(struct led_classdev *led_cdev, |
| 330 | unsigned long *delay_on, |
| 331 | unsigned long *delay_off) |
| 332 | { |
| 333 | struct rt2x00_led *led = |
| 334 | container_of(led_cdev, struct rt2x00_led, led_dev); |
| 335 | u32 reg; |
| 336 | |
| 337 | rt73usb_register_read(led->rt2x00dev, MAC_CSR14, ®); |
| 338 | rt2x00_set_field32(®, MAC_CSR14_ON_PERIOD, *delay_on); |
| 339 | rt2x00_set_field32(®, MAC_CSR14_OFF_PERIOD, *delay_off); |
| 340 | rt73usb_register_write(led->rt2x00dev, MAC_CSR14, reg); |
| 341 | |
| 342 | return 0; |
| 343 | } |
Ivo van Doorn | 475433b | 2008-06-03 20:30:01 +0200 | [diff] [blame] | 344 | |
| 345 | static void rt73usb_init_led(struct rt2x00_dev *rt2x00dev, |
| 346 | struct rt2x00_led *led, |
| 347 | enum led_type type) |
| 348 | { |
| 349 | led->rt2x00dev = rt2x00dev; |
| 350 | led->type = type; |
| 351 | led->led_dev.brightness_set = rt73usb_brightness_set; |
| 352 | led->led_dev.blink_set = rt73usb_blink_set; |
| 353 | led->flags = LED_INITIALIZED; |
| 354 | } |
Ivo van Doorn | a9450b7 | 2008-02-03 15:53:40 +0100 | [diff] [blame] | 355 | #endif /* CONFIG_RT73USB_LEDS */ |
| 356 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 357 | /* |
| 358 | * Configuration handlers. |
| 359 | */ |
Ivo van Doorn | 906c110 | 2008-08-04 16:38:24 +0200 | [diff] [blame] | 360 | static int rt73usb_config_shared_key(struct rt2x00_dev *rt2x00dev, |
| 361 | struct rt2x00lib_crypto *crypto, |
| 362 | struct ieee80211_key_conf *key) |
| 363 | { |
| 364 | struct hw_key_entry key_entry; |
| 365 | struct rt2x00_field32 field; |
| 366 | int timeout; |
| 367 | u32 mask; |
| 368 | u32 reg; |
| 369 | |
| 370 | if (crypto->cmd == SET_KEY) { |
| 371 | /* |
| 372 | * rt2x00lib can't determine the correct free |
| 373 | * key_idx for shared keys. We have 1 register |
| 374 | * with key valid bits. The goal is simple, read |
| 375 | * the register, if that is full we have no slots |
| 376 | * left. |
| 377 | * Note that each BSS is allowed to have up to 4 |
| 378 | * shared keys, so put a mask over the allowed |
| 379 | * entries. |
| 380 | */ |
| 381 | mask = (0xf << crypto->bssidx); |
| 382 | |
| 383 | rt73usb_register_read(rt2x00dev, SEC_CSR0, ®); |
| 384 | reg &= mask; |
| 385 | |
| 386 | if (reg && reg == mask) |
| 387 | return -ENOSPC; |
| 388 | |
| 389 | key->hw_key_idx += reg ? (ffz(reg) - 1) : 0; |
| 390 | |
| 391 | /* |
| 392 | * Upload key to hardware |
| 393 | */ |
| 394 | memcpy(key_entry.key, crypto->key, |
| 395 | sizeof(key_entry.key)); |
| 396 | memcpy(key_entry.tx_mic, crypto->tx_mic, |
| 397 | sizeof(key_entry.tx_mic)); |
| 398 | memcpy(key_entry.rx_mic, crypto->rx_mic, |
| 399 | sizeof(key_entry.rx_mic)); |
| 400 | |
| 401 | reg = SHARED_KEY_ENTRY(key->hw_key_idx); |
| 402 | timeout = REGISTER_TIMEOUT32(sizeof(key_entry)); |
| 403 | rt2x00usb_vendor_request_large_buff(rt2x00dev, USB_MULTI_WRITE, |
| 404 | USB_VENDOR_REQUEST_OUT, reg, |
| 405 | &key_entry, |
| 406 | sizeof(key_entry), |
| 407 | timeout); |
| 408 | |
| 409 | /* |
| 410 | * The cipher types are stored over 2 registers. |
| 411 | * bssidx 0 and 1 keys are stored in SEC_CSR1 and |
| 412 | * bssidx 1 and 2 keys are stored in SEC_CSR5. |
| 413 | * Using the correct defines correctly will cause overhead, |
| 414 | * so just calculate the correct offset. |
| 415 | */ |
| 416 | if (key->hw_key_idx < 8) { |
| 417 | field.bit_offset = (3 * key->hw_key_idx); |
| 418 | field.bit_mask = 0x7 << field.bit_offset; |
| 419 | |
| 420 | rt73usb_register_read(rt2x00dev, SEC_CSR1, ®); |
| 421 | rt2x00_set_field32(®, field, crypto->cipher); |
| 422 | rt73usb_register_write(rt2x00dev, SEC_CSR1, reg); |
| 423 | } else { |
| 424 | field.bit_offset = (3 * (key->hw_key_idx - 8)); |
| 425 | field.bit_mask = 0x7 << field.bit_offset; |
| 426 | |
| 427 | rt73usb_register_read(rt2x00dev, SEC_CSR5, ®); |
| 428 | rt2x00_set_field32(®, field, crypto->cipher); |
| 429 | rt73usb_register_write(rt2x00dev, SEC_CSR5, reg); |
| 430 | } |
| 431 | |
| 432 | /* |
| 433 | * The driver does not support the IV/EIV generation |
| 434 | * in hardware. However it doesn't support the IV/EIV |
| 435 | * inside the ieee80211 frame either, but requires it |
| 436 | * to be provided seperately for the descriptor. |
| 437 | * rt2x00lib will cut the IV/EIV data out of all frames |
| 438 | * given to us by mac80211, but we must tell mac80211 |
| 439 | * to generate the IV/EIV data. |
| 440 | */ |
| 441 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
| 442 | } |
| 443 | |
| 444 | /* |
| 445 | * SEC_CSR0 contains only single-bit fields to indicate |
| 446 | * a particular key is valid. Because using the FIELD32() |
| 447 | * defines directly will cause a lot of overhead we use |
| 448 | * a calculation to determine the correct bit directly. |
| 449 | */ |
| 450 | mask = 1 << key->hw_key_idx; |
| 451 | |
| 452 | rt73usb_register_read(rt2x00dev, SEC_CSR0, ®); |
| 453 | if (crypto->cmd == SET_KEY) |
| 454 | reg |= mask; |
| 455 | else if (crypto->cmd == DISABLE_KEY) |
| 456 | reg &= ~mask; |
| 457 | rt73usb_register_write(rt2x00dev, SEC_CSR0, reg); |
| 458 | |
| 459 | return 0; |
| 460 | } |
| 461 | |
| 462 | static int rt73usb_config_pairwise_key(struct rt2x00_dev *rt2x00dev, |
| 463 | struct rt2x00lib_crypto *crypto, |
| 464 | struct ieee80211_key_conf *key) |
| 465 | { |
| 466 | struct hw_pairwise_ta_entry addr_entry; |
| 467 | struct hw_key_entry key_entry; |
| 468 | int timeout; |
| 469 | u32 mask; |
| 470 | u32 reg; |
| 471 | |
| 472 | if (crypto->cmd == SET_KEY) { |
| 473 | /* |
| 474 | * rt2x00lib can't determine the correct free |
| 475 | * key_idx for pairwise keys. We have 2 registers |
| 476 | * with key valid bits. The goal is simple, read |
| 477 | * the first register, if that is full move to |
| 478 | * the next register. |
| 479 | * When both registers are full, we drop the key, |
| 480 | * otherwise we use the first invalid entry. |
| 481 | */ |
| 482 | rt73usb_register_read(rt2x00dev, SEC_CSR2, ®); |
| 483 | if (reg && reg == ~0) { |
| 484 | key->hw_key_idx = 32; |
| 485 | rt73usb_register_read(rt2x00dev, SEC_CSR3, ®); |
| 486 | if (reg && reg == ~0) |
| 487 | return -ENOSPC; |
| 488 | } |
| 489 | |
| 490 | key->hw_key_idx += reg ? (ffz(reg) - 1) : 0; |
| 491 | |
| 492 | /* |
| 493 | * Upload key to hardware |
| 494 | */ |
| 495 | memcpy(key_entry.key, crypto->key, |
| 496 | sizeof(key_entry.key)); |
| 497 | memcpy(key_entry.tx_mic, crypto->tx_mic, |
| 498 | sizeof(key_entry.tx_mic)); |
| 499 | memcpy(key_entry.rx_mic, crypto->rx_mic, |
| 500 | sizeof(key_entry.rx_mic)); |
| 501 | |
| 502 | reg = PAIRWISE_KEY_ENTRY(key->hw_key_idx); |
| 503 | timeout = REGISTER_TIMEOUT32(sizeof(key_entry)); |
| 504 | rt2x00usb_vendor_request_large_buff(rt2x00dev, USB_MULTI_WRITE, |
| 505 | USB_VENDOR_REQUEST_OUT, reg, |
| 506 | &key_entry, |
| 507 | sizeof(key_entry), |
| 508 | timeout); |
| 509 | |
| 510 | /* |
| 511 | * Send the address and cipher type to the hardware register. |
| 512 | * This data fits within the CSR cache size, so we can use |
| 513 | * rt73usb_register_multiwrite() directly. |
| 514 | */ |
| 515 | memset(&addr_entry, 0, sizeof(addr_entry)); |
| 516 | memcpy(&addr_entry, crypto->address, ETH_ALEN); |
| 517 | addr_entry.cipher = crypto->cipher; |
| 518 | |
| 519 | reg = PAIRWISE_TA_ENTRY(key->hw_key_idx); |
| 520 | rt73usb_register_multiwrite(rt2x00dev, reg, |
| 521 | &addr_entry, sizeof(addr_entry)); |
| 522 | |
| 523 | /* |
| 524 | * Enable pairwise lookup table for given BSS idx, |
| 525 | * without this received frames will not be decrypted |
| 526 | * by the hardware. |
| 527 | */ |
| 528 | rt73usb_register_read(rt2x00dev, SEC_CSR4, ®); |
| 529 | reg |= (1 << crypto->bssidx); |
| 530 | rt73usb_register_write(rt2x00dev, SEC_CSR4, reg); |
| 531 | |
| 532 | /* |
| 533 | * The driver does not support the IV/EIV generation |
| 534 | * in hardware. However it doesn't support the IV/EIV |
| 535 | * inside the ieee80211 frame either, but requires it |
| 536 | * to be provided seperately for the descriptor. |
| 537 | * rt2x00lib will cut the IV/EIV data out of all frames |
| 538 | * given to us by mac80211, but we must tell mac80211 |
| 539 | * to generate the IV/EIV data. |
| 540 | */ |
| 541 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
| 542 | } |
| 543 | |
| 544 | /* |
| 545 | * SEC_CSR2 and SEC_CSR3 contain only single-bit fields to indicate |
| 546 | * a particular key is valid. Because using the FIELD32() |
| 547 | * defines directly will cause a lot of overhead we use |
| 548 | * a calculation to determine the correct bit directly. |
| 549 | */ |
| 550 | if (key->hw_key_idx < 32) { |
| 551 | mask = 1 << key->hw_key_idx; |
| 552 | |
| 553 | rt73usb_register_read(rt2x00dev, SEC_CSR2, ®); |
| 554 | if (crypto->cmd == SET_KEY) |
| 555 | reg |= mask; |
| 556 | else if (crypto->cmd == DISABLE_KEY) |
| 557 | reg &= ~mask; |
| 558 | rt73usb_register_write(rt2x00dev, SEC_CSR2, reg); |
| 559 | } else { |
| 560 | mask = 1 << (key->hw_key_idx - 32); |
| 561 | |
| 562 | rt73usb_register_read(rt2x00dev, SEC_CSR3, ®); |
| 563 | if (crypto->cmd == SET_KEY) |
| 564 | reg |= mask; |
| 565 | else if (crypto->cmd == DISABLE_KEY) |
| 566 | reg &= ~mask; |
| 567 | rt73usb_register_write(rt2x00dev, SEC_CSR3, reg); |
| 568 | } |
| 569 | |
| 570 | return 0; |
| 571 | } |
| 572 | |
Ivo van Doorn | 3a643d2 | 2008-03-25 14:13:18 +0100 | [diff] [blame] | 573 | static void rt73usb_config_filter(struct rt2x00_dev *rt2x00dev, |
| 574 | const unsigned int filter_flags) |
| 575 | { |
| 576 | u32 reg; |
| 577 | |
| 578 | /* |
| 579 | * Start configuration steps. |
| 580 | * Note that the version error will always be dropped |
| 581 | * and broadcast frames will always be accepted since |
| 582 | * there is no filter for it at this time. |
| 583 | */ |
| 584 | rt73usb_register_read(rt2x00dev, TXRX_CSR0, ®); |
| 585 | rt2x00_set_field32(®, TXRX_CSR0_DROP_CRC, |
| 586 | !(filter_flags & FIF_FCSFAIL)); |
| 587 | rt2x00_set_field32(®, TXRX_CSR0_DROP_PHYSICAL, |
| 588 | !(filter_flags & FIF_PLCPFAIL)); |
| 589 | rt2x00_set_field32(®, TXRX_CSR0_DROP_CONTROL, |
| 590 | !(filter_flags & FIF_CONTROL)); |
| 591 | rt2x00_set_field32(®, TXRX_CSR0_DROP_NOT_TO_ME, |
| 592 | !(filter_flags & FIF_PROMISC_IN_BSS)); |
| 593 | rt2x00_set_field32(®, TXRX_CSR0_DROP_TO_DS, |
Ivo van Doorn | e0b005f | 2008-03-31 15:24:53 +0200 | [diff] [blame] | 594 | !(filter_flags & FIF_PROMISC_IN_BSS) && |
| 595 | !rt2x00dev->intf_ap_count); |
Ivo van Doorn | 3a643d2 | 2008-03-25 14:13:18 +0100 | [diff] [blame] | 596 | rt2x00_set_field32(®, TXRX_CSR0_DROP_VERSION_ERROR, 1); |
| 597 | rt2x00_set_field32(®, TXRX_CSR0_DROP_MULTICAST, |
| 598 | !(filter_flags & FIF_ALLMULTI)); |
| 599 | rt2x00_set_field32(®, TXRX_CSR0_DROP_BROADCAST, 0); |
| 600 | rt2x00_set_field32(®, TXRX_CSR0_DROP_ACK_CTS, |
| 601 | !(filter_flags & FIF_CONTROL)); |
| 602 | rt73usb_register_write(rt2x00dev, TXRX_CSR0, reg); |
| 603 | } |
| 604 | |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame] | 605 | static void rt73usb_config_intf(struct rt2x00_dev *rt2x00dev, |
| 606 | struct rt2x00_intf *intf, |
| 607 | struct rt2x00intf_conf *conf, |
| 608 | const unsigned int flags) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 609 | { |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame] | 610 | unsigned int beacon_base; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 611 | u32 reg; |
| 612 | |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame] | 613 | if (flags & CONFIG_UPDATE_TYPE) { |
| 614 | /* |
| 615 | * Clear current synchronisation setup. |
| 616 | * For the Beacon base registers we only need to clear |
| 617 | * the first byte since that byte contains the VALID and OWNER |
| 618 | * bits which (when set to 0) will invalidate the entire beacon. |
| 619 | */ |
| 620 | beacon_base = HW_BEACON_OFFSET(intf->beacon->entry_idx); |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame] | 621 | rt73usb_register_write(rt2x00dev, beacon_base, 0); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 622 | |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame] | 623 | /* |
| 624 | * Enable synchronisation. |
| 625 | */ |
| 626 | rt73usb_register_read(rt2x00dev, TXRX_CSR9, ®); |
Ivo van Doorn | fd3c91c | 2008-03-09 22:47:43 +0100 | [diff] [blame] | 627 | rt2x00_set_field32(®, TXRX_CSR9_TSF_TICKING, 1); |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame] | 628 | rt2x00_set_field32(®, TXRX_CSR9_TSF_SYNC, conf->sync); |
Ivo van Doorn | fd3c91c | 2008-03-09 22:47:43 +0100 | [diff] [blame] | 629 | rt2x00_set_field32(®, TXRX_CSR9_TBTT_ENABLE, 1); |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame] | 630 | rt73usb_register_write(rt2x00dev, TXRX_CSR9, reg); |
Ivo van Doorn | 5c58ee5 | 2007-10-06 13:34:52 +0200 | [diff] [blame] | 631 | } |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 632 | |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame] | 633 | if (flags & CONFIG_UPDATE_MAC) { |
| 634 | reg = le32_to_cpu(conf->mac[1]); |
| 635 | rt2x00_set_field32(®, MAC_CSR3_UNICAST_TO_ME_MASK, 0xff); |
| 636 | conf->mac[1] = cpu_to_le32(reg); |
| 637 | |
| 638 | rt73usb_register_multiwrite(rt2x00dev, MAC_CSR2, |
| 639 | conf->mac, sizeof(conf->mac)); |
| 640 | } |
| 641 | |
| 642 | if (flags & CONFIG_UPDATE_BSSID) { |
| 643 | reg = le32_to_cpu(conf->bssid[1]); |
| 644 | rt2x00_set_field32(®, MAC_CSR5_BSS_ID_MASK, 3); |
| 645 | conf->bssid[1] = cpu_to_le32(reg); |
| 646 | |
| 647 | rt73usb_register_multiwrite(rt2x00dev, MAC_CSR4, |
| 648 | conf->bssid, sizeof(conf->bssid)); |
| 649 | } |
| 650 | } |
| 651 | |
Ivo van Doorn | 3a643d2 | 2008-03-25 14:13:18 +0100 | [diff] [blame] | 652 | static void rt73usb_config_erp(struct rt2x00_dev *rt2x00dev, |
| 653 | struct rt2x00lib_erp *erp) |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame] | 654 | { |
| 655 | u32 reg; |
| 656 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 657 | rt73usb_register_read(rt2x00dev, TXRX_CSR0, ®); |
Ivo van Doorn | 7281037 | 2008-03-09 22:46:18 +0100 | [diff] [blame] | 658 | rt2x00_set_field32(®, TXRX_CSR0_RX_ACK_TIMEOUT, erp->ack_timeout); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 659 | rt73usb_register_write(rt2x00dev, TXRX_CSR0, reg); |
| 660 | |
| 661 | rt73usb_register_read(rt2x00dev, TXRX_CSR4, ®); |
Ivo van Doorn | 4f5af6eb | 2007-10-06 14:16:30 +0200 | [diff] [blame] | 662 | rt2x00_set_field32(®, TXRX_CSR4_AUTORESPOND_PREAMBLE, |
Ivo van Doorn | 7281037 | 2008-03-09 22:46:18 +0100 | [diff] [blame] | 663 | !!erp->short_preamble); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 664 | rt73usb_register_write(rt2x00dev, TXRX_CSR4, reg); |
| 665 | } |
| 666 | |
| 667 | static void rt73usb_config_phymode(struct rt2x00_dev *rt2x00dev, |
Ivo van Doorn | 5c58ee5 | 2007-10-06 13:34:52 +0200 | [diff] [blame] | 668 | const int basic_rate_mask) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 669 | { |
Ivo van Doorn | 5c58ee5 | 2007-10-06 13:34:52 +0200 | [diff] [blame] | 670 | rt73usb_register_write(rt2x00dev, TXRX_CSR5, basic_rate_mask); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 671 | } |
| 672 | |
Ivo van Doorn | 5c58ee5 | 2007-10-06 13:34:52 +0200 | [diff] [blame] | 673 | static void rt73usb_config_channel(struct rt2x00_dev *rt2x00dev, |
| 674 | struct rf_channel *rf, const int txpower) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 675 | { |
| 676 | u8 r3; |
| 677 | u8 r94; |
| 678 | u8 smart; |
| 679 | |
| 680 | rt2x00_set_field32(&rf->rf3, RF3_TXPOWER, TXPOWER_TO_DEV(txpower)); |
| 681 | rt2x00_set_field32(&rf->rf4, RF4_FREQ_OFFSET, rt2x00dev->freq_offset); |
| 682 | |
| 683 | smart = !(rt2x00_rf(&rt2x00dev->chip, RF5225) || |
| 684 | rt2x00_rf(&rt2x00dev->chip, RF2527)); |
| 685 | |
| 686 | rt73usb_bbp_read(rt2x00dev, 3, &r3); |
| 687 | rt2x00_set_field8(&r3, BBP_R3_SMART_MODE, smart); |
| 688 | rt73usb_bbp_write(rt2x00dev, 3, r3); |
| 689 | |
| 690 | r94 = 6; |
| 691 | if (txpower > MAX_TXPOWER && txpower <= (MAX_TXPOWER + r94)) |
| 692 | r94 += txpower - MAX_TXPOWER; |
| 693 | else if (txpower < MIN_TXPOWER && txpower >= (MIN_TXPOWER - r94)) |
| 694 | r94 += txpower; |
| 695 | rt73usb_bbp_write(rt2x00dev, 94, r94); |
| 696 | |
| 697 | rt73usb_rf_write(rt2x00dev, 1, rf->rf1); |
| 698 | rt73usb_rf_write(rt2x00dev, 2, rf->rf2); |
| 699 | rt73usb_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004); |
| 700 | rt73usb_rf_write(rt2x00dev, 4, rf->rf4); |
| 701 | |
| 702 | rt73usb_rf_write(rt2x00dev, 1, rf->rf1); |
| 703 | rt73usb_rf_write(rt2x00dev, 2, rf->rf2); |
| 704 | rt73usb_rf_write(rt2x00dev, 3, rf->rf3 | 0x00000004); |
| 705 | rt73usb_rf_write(rt2x00dev, 4, rf->rf4); |
| 706 | |
| 707 | rt73usb_rf_write(rt2x00dev, 1, rf->rf1); |
| 708 | rt73usb_rf_write(rt2x00dev, 2, rf->rf2); |
| 709 | rt73usb_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004); |
| 710 | rt73usb_rf_write(rt2x00dev, 4, rf->rf4); |
| 711 | |
| 712 | udelay(10); |
| 713 | } |
| 714 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 715 | static void rt73usb_config_txpower(struct rt2x00_dev *rt2x00dev, |
| 716 | const int txpower) |
| 717 | { |
| 718 | struct rf_channel rf; |
| 719 | |
| 720 | rt2x00_rf_read(rt2x00dev, 1, &rf.rf1); |
| 721 | rt2x00_rf_read(rt2x00dev, 2, &rf.rf2); |
| 722 | rt2x00_rf_read(rt2x00dev, 3, &rf.rf3); |
| 723 | rt2x00_rf_read(rt2x00dev, 4, &rf.rf4); |
| 724 | |
Ivo van Doorn | 5c58ee5 | 2007-10-06 13:34:52 +0200 | [diff] [blame] | 725 | rt73usb_config_channel(rt2x00dev, &rf, txpower); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | static void rt73usb_config_antenna_5x(struct rt2x00_dev *rt2x00dev, |
Ivo van Doorn | addc81bd | 2007-10-13 16:26:23 +0200 | [diff] [blame] | 729 | struct antenna_setup *ant) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 730 | { |
| 731 | u8 r3; |
| 732 | u8 r4; |
| 733 | u8 r77; |
Mattias Nissler | 2676c94 | 2007-10-27 13:42:37 +0200 | [diff] [blame] | 734 | u8 temp; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 735 | |
| 736 | rt73usb_bbp_read(rt2x00dev, 3, &r3); |
| 737 | rt73usb_bbp_read(rt2x00dev, 4, &r4); |
| 738 | rt73usb_bbp_read(rt2x00dev, 77, &r77); |
| 739 | |
| 740 | rt2x00_set_field8(&r3, BBP_R3_SMART_MODE, 0); |
| 741 | |
Ivo van Doorn | e4cd2ff | 2007-10-27 13:39:57 +0200 | [diff] [blame] | 742 | /* |
Ivo van Doorn | e4cd2ff | 2007-10-27 13:39:57 +0200 | [diff] [blame] | 743 | * Configure the RX antenna. |
| 744 | */ |
Ivo van Doorn | addc81bd | 2007-10-13 16:26:23 +0200 | [diff] [blame] | 745 | switch (ant->rx) { |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 746 | case ANTENNA_HW_DIVERSITY: |
Mattias Nissler | 2676c94 | 2007-10-27 13:42:37 +0200 | [diff] [blame] | 747 | rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 2); |
| 748 | temp = !test_bit(CONFIG_FRAME_TYPE, &rt2x00dev->flags) |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 749 | && (rt2x00dev->curr_band != IEEE80211_BAND_5GHZ); |
Mattias Nissler | 2676c94 | 2007-10-27 13:42:37 +0200 | [diff] [blame] | 750 | rt2x00_set_field8(&r4, BBP_R4_RX_FRAME_END, temp); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 751 | break; |
| 752 | case ANTENNA_A: |
Mattias Nissler | 2676c94 | 2007-10-27 13:42:37 +0200 | [diff] [blame] | 753 | rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 1); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 754 | rt2x00_set_field8(&r4, BBP_R4_RX_FRAME_END, 0); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 755 | if (rt2x00dev->curr_band == IEEE80211_BAND_5GHZ) |
Mattias Nissler | 2676c94 | 2007-10-27 13:42:37 +0200 | [diff] [blame] | 756 | rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 0); |
| 757 | else |
| 758 | rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 3); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 759 | break; |
| 760 | case ANTENNA_B: |
Ivo van Doorn | a4fe07d | 2008-03-09 22:45:21 +0100 | [diff] [blame] | 761 | default: |
Mattias Nissler | 2676c94 | 2007-10-27 13:42:37 +0200 | [diff] [blame] | 762 | rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 1); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 763 | rt2x00_set_field8(&r4, BBP_R4_RX_FRAME_END, 0); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 764 | if (rt2x00dev->curr_band == IEEE80211_BAND_5GHZ) |
Mattias Nissler | 2676c94 | 2007-10-27 13:42:37 +0200 | [diff] [blame] | 765 | rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 3); |
| 766 | else |
| 767 | rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 0); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 768 | break; |
| 769 | } |
| 770 | |
| 771 | rt73usb_bbp_write(rt2x00dev, 77, r77); |
| 772 | rt73usb_bbp_write(rt2x00dev, 3, r3); |
| 773 | rt73usb_bbp_write(rt2x00dev, 4, r4); |
| 774 | } |
| 775 | |
| 776 | static void rt73usb_config_antenna_2x(struct rt2x00_dev *rt2x00dev, |
Ivo van Doorn | addc81bd | 2007-10-13 16:26:23 +0200 | [diff] [blame] | 777 | struct antenna_setup *ant) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 778 | { |
| 779 | u8 r3; |
| 780 | u8 r4; |
| 781 | u8 r77; |
| 782 | |
| 783 | rt73usb_bbp_read(rt2x00dev, 3, &r3); |
| 784 | rt73usb_bbp_read(rt2x00dev, 4, &r4); |
| 785 | rt73usb_bbp_read(rt2x00dev, 77, &r77); |
| 786 | |
| 787 | rt2x00_set_field8(&r3, BBP_R3_SMART_MODE, 0); |
| 788 | rt2x00_set_field8(&r4, BBP_R4_RX_FRAME_END, |
| 789 | !test_bit(CONFIG_FRAME_TYPE, &rt2x00dev->flags)); |
| 790 | |
Ivo van Doorn | e4cd2ff | 2007-10-27 13:39:57 +0200 | [diff] [blame] | 791 | /* |
Ivo van Doorn | e4cd2ff | 2007-10-27 13:39:57 +0200 | [diff] [blame] | 792 | * Configure the RX antenna. |
| 793 | */ |
Ivo van Doorn | addc81bd | 2007-10-13 16:26:23 +0200 | [diff] [blame] | 794 | switch (ant->rx) { |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 795 | case ANTENNA_HW_DIVERSITY: |
Mattias Nissler | 2676c94 | 2007-10-27 13:42:37 +0200 | [diff] [blame] | 796 | rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 2); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 797 | break; |
| 798 | case ANTENNA_A: |
Mattias Nissler | 2676c94 | 2007-10-27 13:42:37 +0200 | [diff] [blame] | 799 | rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 3); |
| 800 | rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 1); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 801 | break; |
| 802 | case ANTENNA_B: |
Ivo van Doorn | a4fe07d | 2008-03-09 22:45:21 +0100 | [diff] [blame] | 803 | default: |
Mattias Nissler | 2676c94 | 2007-10-27 13:42:37 +0200 | [diff] [blame] | 804 | rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 0); |
| 805 | rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 1); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 806 | break; |
| 807 | } |
| 808 | |
| 809 | rt73usb_bbp_write(rt2x00dev, 77, r77); |
| 810 | rt73usb_bbp_write(rt2x00dev, 3, r3); |
| 811 | rt73usb_bbp_write(rt2x00dev, 4, r4); |
| 812 | } |
| 813 | |
| 814 | struct antenna_sel { |
| 815 | u8 word; |
| 816 | /* |
| 817 | * value[0] -> non-LNA |
| 818 | * value[1] -> LNA |
| 819 | */ |
| 820 | u8 value[2]; |
| 821 | }; |
| 822 | |
| 823 | static const struct antenna_sel antenna_sel_a[] = { |
| 824 | { 96, { 0x58, 0x78 } }, |
| 825 | { 104, { 0x38, 0x48 } }, |
| 826 | { 75, { 0xfe, 0x80 } }, |
| 827 | { 86, { 0xfe, 0x80 } }, |
| 828 | { 88, { 0xfe, 0x80 } }, |
| 829 | { 35, { 0x60, 0x60 } }, |
| 830 | { 97, { 0x58, 0x58 } }, |
| 831 | { 98, { 0x58, 0x58 } }, |
| 832 | }; |
| 833 | |
| 834 | static const struct antenna_sel antenna_sel_bg[] = { |
| 835 | { 96, { 0x48, 0x68 } }, |
| 836 | { 104, { 0x2c, 0x3c } }, |
| 837 | { 75, { 0xfe, 0x80 } }, |
| 838 | { 86, { 0xfe, 0x80 } }, |
| 839 | { 88, { 0xfe, 0x80 } }, |
| 840 | { 35, { 0x50, 0x50 } }, |
| 841 | { 97, { 0x48, 0x48 } }, |
| 842 | { 98, { 0x48, 0x48 } }, |
| 843 | }; |
| 844 | |
| 845 | static void rt73usb_config_antenna(struct rt2x00_dev *rt2x00dev, |
Ivo van Doorn | addc81bd | 2007-10-13 16:26:23 +0200 | [diff] [blame] | 846 | struct antenna_setup *ant) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 847 | { |
| 848 | const struct antenna_sel *sel; |
| 849 | unsigned int lna; |
| 850 | unsigned int i; |
| 851 | u32 reg; |
| 852 | |
Ivo van Doorn | a4fe07d | 2008-03-09 22:45:21 +0100 | [diff] [blame] | 853 | /* |
| 854 | * We should never come here because rt2x00lib is supposed |
| 855 | * to catch this and send us the correct antenna explicitely. |
| 856 | */ |
| 857 | BUG_ON(ant->rx == ANTENNA_SW_DIVERSITY || |
| 858 | ant->tx == ANTENNA_SW_DIVERSITY); |
| 859 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 860 | if (rt2x00dev->curr_band == IEEE80211_BAND_5GHZ) { |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 861 | sel = antenna_sel_a; |
| 862 | lna = test_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 863 | } else { |
| 864 | sel = antenna_sel_bg; |
| 865 | lna = test_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 866 | } |
| 867 | |
Mattias Nissler | 2676c94 | 2007-10-27 13:42:37 +0200 | [diff] [blame] | 868 | for (i = 0; i < ARRAY_SIZE(antenna_sel_a); i++) |
| 869 | rt73usb_bbp_write(rt2x00dev, sel[i].word, sel[i].value[lna]); |
| 870 | |
| 871 | rt73usb_register_read(rt2x00dev, PHY_CSR0, ®); |
| 872 | |
Ivo van Doorn | ddc827f | 2007-10-13 16:26:42 +0200 | [diff] [blame] | 873 | rt2x00_set_field32(®, PHY_CSR0_PA_PE_BG, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 874 | (rt2x00dev->curr_band == IEEE80211_BAND_2GHZ)); |
Ivo van Doorn | ddc827f | 2007-10-13 16:26:42 +0200 | [diff] [blame] | 875 | rt2x00_set_field32(®, PHY_CSR0_PA_PE_A, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 876 | (rt2x00dev->curr_band == IEEE80211_BAND_5GHZ)); |
Ivo van Doorn | ddc827f | 2007-10-13 16:26:42 +0200 | [diff] [blame] | 877 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 878 | rt73usb_register_write(rt2x00dev, PHY_CSR0, reg); |
| 879 | |
| 880 | if (rt2x00_rf(&rt2x00dev->chip, RF5226) || |
| 881 | rt2x00_rf(&rt2x00dev->chip, RF5225)) |
Ivo van Doorn | addc81bd | 2007-10-13 16:26:23 +0200 | [diff] [blame] | 882 | rt73usb_config_antenna_5x(rt2x00dev, ant); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 883 | else if (rt2x00_rf(&rt2x00dev->chip, RF2528) || |
| 884 | rt2x00_rf(&rt2x00dev->chip, RF2527)) |
Ivo van Doorn | addc81bd | 2007-10-13 16:26:23 +0200 | [diff] [blame] | 885 | rt73usb_config_antenna_2x(rt2x00dev, ant); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 886 | } |
| 887 | |
| 888 | static void rt73usb_config_duration(struct rt2x00_dev *rt2x00dev, |
Ivo van Doorn | 5c58ee5 | 2007-10-06 13:34:52 +0200 | [diff] [blame] | 889 | struct rt2x00lib_conf *libconf) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 890 | { |
| 891 | u32 reg; |
| 892 | |
| 893 | rt73usb_register_read(rt2x00dev, MAC_CSR9, ®); |
Ivo van Doorn | 5c58ee5 | 2007-10-06 13:34:52 +0200 | [diff] [blame] | 894 | rt2x00_set_field32(®, MAC_CSR9_SLOT_TIME, libconf->slot_time); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 895 | rt73usb_register_write(rt2x00dev, MAC_CSR9, reg); |
| 896 | |
| 897 | rt73usb_register_read(rt2x00dev, MAC_CSR8, ®); |
Ivo van Doorn | 5c58ee5 | 2007-10-06 13:34:52 +0200 | [diff] [blame] | 898 | rt2x00_set_field32(®, MAC_CSR8_SIFS, libconf->sifs); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 899 | rt2x00_set_field32(®, MAC_CSR8_SIFS_AFTER_RX_OFDM, 3); |
Ivo van Doorn | 5c58ee5 | 2007-10-06 13:34:52 +0200 | [diff] [blame] | 900 | rt2x00_set_field32(®, MAC_CSR8_EIFS, libconf->eifs); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 901 | rt73usb_register_write(rt2x00dev, MAC_CSR8, reg); |
| 902 | |
| 903 | rt73usb_register_read(rt2x00dev, TXRX_CSR0, ®); |
| 904 | rt2x00_set_field32(®, TXRX_CSR0_TSF_OFFSET, IEEE80211_HEADER); |
| 905 | rt73usb_register_write(rt2x00dev, TXRX_CSR0, reg); |
| 906 | |
| 907 | rt73usb_register_read(rt2x00dev, TXRX_CSR4, ®); |
| 908 | rt2x00_set_field32(®, TXRX_CSR4_AUTORESPOND_ENABLE, 1); |
| 909 | rt73usb_register_write(rt2x00dev, TXRX_CSR4, reg); |
| 910 | |
| 911 | rt73usb_register_read(rt2x00dev, TXRX_CSR9, ®); |
Ivo van Doorn | 5c58ee5 | 2007-10-06 13:34:52 +0200 | [diff] [blame] | 912 | rt2x00_set_field32(®, TXRX_CSR9_BEACON_INTERVAL, |
| 913 | libconf->conf->beacon_int * 16); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 914 | rt73usb_register_write(rt2x00dev, TXRX_CSR9, reg); |
| 915 | } |
| 916 | |
| 917 | static void rt73usb_config(struct rt2x00_dev *rt2x00dev, |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame] | 918 | struct rt2x00lib_conf *libconf, |
| 919 | const unsigned int flags) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 920 | { |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 921 | if (flags & CONFIG_UPDATE_PHYMODE) |
Ivo van Doorn | 5c58ee5 | 2007-10-06 13:34:52 +0200 | [diff] [blame] | 922 | rt73usb_config_phymode(rt2x00dev, libconf->basic_rates); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 923 | if (flags & CONFIG_UPDATE_CHANNEL) |
Ivo van Doorn | 5c58ee5 | 2007-10-06 13:34:52 +0200 | [diff] [blame] | 924 | rt73usb_config_channel(rt2x00dev, &libconf->rf, |
| 925 | libconf->conf->power_level); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 926 | if ((flags & CONFIG_UPDATE_TXPOWER) && !(flags & CONFIG_UPDATE_CHANNEL)) |
Ivo van Doorn | 5c58ee5 | 2007-10-06 13:34:52 +0200 | [diff] [blame] | 927 | rt73usb_config_txpower(rt2x00dev, libconf->conf->power_level); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 928 | if (flags & CONFIG_UPDATE_ANTENNA) |
Ivo van Doorn | addc81bd | 2007-10-13 16:26:23 +0200 | [diff] [blame] | 929 | rt73usb_config_antenna(rt2x00dev, &libconf->ant); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 930 | if (flags & (CONFIG_UPDATE_SLOT_TIME | CONFIG_UPDATE_BEACON_INT)) |
Ivo van Doorn | 5c58ee5 | 2007-10-06 13:34:52 +0200 | [diff] [blame] | 931 | rt73usb_config_duration(rt2x00dev, libconf); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 932 | } |
| 933 | |
| 934 | /* |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 935 | * Link tuning |
| 936 | */ |
Ivo van Doorn | ebcf26d | 2007-10-13 16:26:12 +0200 | [diff] [blame] | 937 | static void rt73usb_link_stats(struct rt2x00_dev *rt2x00dev, |
| 938 | struct link_qual *qual) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 939 | { |
| 940 | u32 reg; |
| 941 | |
| 942 | /* |
| 943 | * Update FCS error count from register. |
| 944 | */ |
| 945 | rt73usb_register_read(rt2x00dev, STA_CSR0, ®); |
Ivo van Doorn | ebcf26d | 2007-10-13 16:26:12 +0200 | [diff] [blame] | 946 | qual->rx_failed = rt2x00_get_field32(reg, STA_CSR0_FCS_ERROR); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 947 | |
| 948 | /* |
| 949 | * Update False CCA count from register. |
| 950 | */ |
| 951 | rt73usb_register_read(rt2x00dev, STA_CSR1, ®); |
Ivo van Doorn | ebcf26d | 2007-10-13 16:26:12 +0200 | [diff] [blame] | 952 | qual->false_cca = rt2x00_get_field32(reg, STA_CSR1_FALSE_CCA_ERROR); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 953 | } |
| 954 | |
| 955 | static void rt73usb_reset_tuner(struct rt2x00_dev *rt2x00dev) |
| 956 | { |
| 957 | rt73usb_bbp_write(rt2x00dev, 17, 0x20); |
| 958 | rt2x00dev->link.vgc_level = 0x20; |
| 959 | } |
| 960 | |
| 961 | static void rt73usb_link_tuner(struct rt2x00_dev *rt2x00dev) |
| 962 | { |
| 963 | int rssi = rt2x00_get_link_rssi(&rt2x00dev->link); |
| 964 | u8 r17; |
| 965 | u8 up_bound; |
| 966 | u8 low_bound; |
| 967 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 968 | rt73usb_bbp_read(rt2x00dev, 17, &r17); |
| 969 | |
| 970 | /* |
| 971 | * Determine r17 bounds. |
| 972 | */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 973 | if (rt2x00dev->rx_status.band == IEEE80211_BAND_5GHZ) { |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 974 | low_bound = 0x28; |
| 975 | up_bound = 0x48; |
| 976 | |
| 977 | if (test_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags)) { |
| 978 | low_bound += 0x10; |
| 979 | up_bound += 0x10; |
| 980 | } |
| 981 | } else { |
| 982 | if (rssi > -82) { |
| 983 | low_bound = 0x1c; |
| 984 | up_bound = 0x40; |
| 985 | } else if (rssi > -84) { |
| 986 | low_bound = 0x1c; |
| 987 | up_bound = 0x20; |
| 988 | } else { |
| 989 | low_bound = 0x1c; |
| 990 | up_bound = 0x1c; |
| 991 | } |
| 992 | |
| 993 | if (test_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags)) { |
| 994 | low_bound += 0x14; |
| 995 | up_bound += 0x10; |
| 996 | } |
| 997 | } |
| 998 | |
| 999 | /* |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame] | 1000 | * If we are not associated, we should go straight to the |
| 1001 | * dynamic CCA tuning. |
| 1002 | */ |
| 1003 | if (!rt2x00dev->intf_associated) |
| 1004 | goto dynamic_cca_tune; |
| 1005 | |
| 1006 | /* |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1007 | * Special big-R17 for very short distance |
| 1008 | */ |
| 1009 | if (rssi > -35) { |
| 1010 | if (r17 != 0x60) |
| 1011 | rt73usb_bbp_write(rt2x00dev, 17, 0x60); |
| 1012 | return; |
| 1013 | } |
| 1014 | |
| 1015 | /* |
| 1016 | * Special big-R17 for short distance |
| 1017 | */ |
| 1018 | if (rssi >= -58) { |
| 1019 | if (r17 != up_bound) |
| 1020 | rt73usb_bbp_write(rt2x00dev, 17, up_bound); |
| 1021 | return; |
| 1022 | } |
| 1023 | |
| 1024 | /* |
| 1025 | * Special big-R17 for middle-short distance |
| 1026 | */ |
| 1027 | if (rssi >= -66) { |
| 1028 | low_bound += 0x10; |
| 1029 | if (r17 != low_bound) |
| 1030 | rt73usb_bbp_write(rt2x00dev, 17, low_bound); |
| 1031 | return; |
| 1032 | } |
| 1033 | |
| 1034 | /* |
| 1035 | * Special mid-R17 for middle distance |
| 1036 | */ |
| 1037 | if (rssi >= -74) { |
| 1038 | if (r17 != (low_bound + 0x10)) |
| 1039 | rt73usb_bbp_write(rt2x00dev, 17, low_bound + 0x08); |
| 1040 | return; |
| 1041 | } |
| 1042 | |
| 1043 | /* |
| 1044 | * Special case: Change up_bound based on the rssi. |
| 1045 | * Lower up_bound when rssi is weaker then -74 dBm. |
| 1046 | */ |
| 1047 | up_bound -= 2 * (-74 - rssi); |
| 1048 | if (low_bound > up_bound) |
| 1049 | up_bound = low_bound; |
| 1050 | |
| 1051 | if (r17 > up_bound) { |
| 1052 | rt73usb_bbp_write(rt2x00dev, 17, up_bound); |
| 1053 | return; |
| 1054 | } |
| 1055 | |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame] | 1056 | dynamic_cca_tune: |
| 1057 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1058 | /* |
| 1059 | * r17 does not yet exceed upper limit, continue and base |
| 1060 | * the r17 tuning on the false CCA count. |
| 1061 | */ |
Ivo van Doorn | ebcf26d | 2007-10-13 16:26:12 +0200 | [diff] [blame] | 1062 | if (rt2x00dev->link.qual.false_cca > 512 && r17 < up_bound) { |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1063 | r17 += 4; |
| 1064 | if (r17 > up_bound) |
| 1065 | r17 = up_bound; |
| 1066 | rt73usb_bbp_write(rt2x00dev, 17, r17); |
Ivo van Doorn | ebcf26d | 2007-10-13 16:26:12 +0200 | [diff] [blame] | 1067 | } else if (rt2x00dev->link.qual.false_cca < 100 && r17 > low_bound) { |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1068 | r17 -= 4; |
| 1069 | if (r17 < low_bound) |
| 1070 | r17 = low_bound; |
| 1071 | rt73usb_bbp_write(rt2x00dev, 17, r17); |
| 1072 | } |
| 1073 | } |
| 1074 | |
| 1075 | /* |
Ivo van Doorn | a7f3a06 | 2008-03-09 22:44:54 +0100 | [diff] [blame] | 1076 | * Firmware functions |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1077 | */ |
| 1078 | static char *rt73usb_get_firmware_name(struct rt2x00_dev *rt2x00dev) |
| 1079 | { |
| 1080 | return FIRMWARE_RT2571; |
| 1081 | } |
| 1082 | |
David Woodhouse | f160ebc | 2008-05-24 00:08:39 +0100 | [diff] [blame] | 1083 | static u16 rt73usb_get_firmware_crc(const void *data, const size_t len) |
Ivo van Doorn | a7f3a06 | 2008-03-09 22:44:54 +0100 | [diff] [blame] | 1084 | { |
| 1085 | u16 crc; |
| 1086 | |
| 1087 | /* |
| 1088 | * Use the crc itu-t algorithm. |
| 1089 | * The last 2 bytes in the firmware array are the crc checksum itself, |
| 1090 | * this means that we should never pass those 2 bytes to the crc |
| 1091 | * algorithm. |
| 1092 | */ |
| 1093 | crc = crc_itu_t(0, data, len - 2); |
| 1094 | crc = crc_itu_t_byte(crc, 0); |
| 1095 | crc = crc_itu_t_byte(crc, 0); |
| 1096 | |
| 1097 | return crc; |
| 1098 | } |
| 1099 | |
David Woodhouse | f160ebc | 2008-05-24 00:08:39 +0100 | [diff] [blame] | 1100 | static int rt73usb_load_firmware(struct rt2x00_dev *rt2x00dev, const void *data, |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1101 | const size_t len) |
| 1102 | { |
| 1103 | unsigned int i; |
| 1104 | int status; |
| 1105 | u32 reg; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1106 | |
| 1107 | /* |
| 1108 | * Wait for stable hardware. |
| 1109 | */ |
| 1110 | for (i = 0; i < 100; i++) { |
| 1111 | rt73usb_register_read(rt2x00dev, MAC_CSR0, ®); |
| 1112 | if (reg) |
| 1113 | break; |
| 1114 | msleep(1); |
| 1115 | } |
| 1116 | |
| 1117 | if (!reg) { |
| 1118 | ERROR(rt2x00dev, "Unstable hardware.\n"); |
| 1119 | return -EBUSY; |
| 1120 | } |
| 1121 | |
| 1122 | /* |
| 1123 | * Write firmware to device. |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1124 | */ |
Iwo Mergler | 3e0c1abe | 2008-07-19 16:17:16 +0200 | [diff] [blame] | 1125 | rt2x00usb_vendor_request_large_buff(rt2x00dev, USB_MULTI_WRITE, |
| 1126 | USB_VENDOR_REQUEST_OUT, |
| 1127 | FIRMWARE_IMAGE_BASE, |
| 1128 | data, len, |
| 1129 | REGISTER_TIMEOUT32(len)); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1130 | |
| 1131 | /* |
| 1132 | * Send firmware request to device to load firmware, |
| 1133 | * we need to specify a long timeout time. |
| 1134 | */ |
| 1135 | status = rt2x00usb_vendor_request_sw(rt2x00dev, USB_DEVICE_MODE, |
Ivo van Doorn | 3b640f2 | 2008-02-03 15:54:11 +0100 | [diff] [blame] | 1136 | 0, USB_MODE_FIRMWARE, |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1137 | REGISTER_TIMEOUT_FIRMWARE); |
| 1138 | if (status < 0) { |
| 1139 | ERROR(rt2x00dev, "Failed to write Firmware to device.\n"); |
| 1140 | return status; |
| 1141 | } |
| 1142 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1143 | return 0; |
| 1144 | } |
| 1145 | |
Ivo van Doorn | a7f3a06 | 2008-03-09 22:44:54 +0100 | [diff] [blame] | 1146 | /* |
| 1147 | * Initialization functions. |
| 1148 | */ |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1149 | static int rt73usb_init_registers(struct rt2x00_dev *rt2x00dev) |
| 1150 | { |
| 1151 | u32 reg; |
| 1152 | |
| 1153 | rt73usb_register_read(rt2x00dev, TXRX_CSR0, ®); |
| 1154 | rt2x00_set_field32(®, TXRX_CSR0_AUTO_TX_SEQ, 1); |
| 1155 | rt2x00_set_field32(®, TXRX_CSR0_DISABLE_RX, 0); |
| 1156 | rt2x00_set_field32(®, TXRX_CSR0_TX_WITHOUT_WAITING, 0); |
| 1157 | rt73usb_register_write(rt2x00dev, TXRX_CSR0, reg); |
| 1158 | |
| 1159 | rt73usb_register_read(rt2x00dev, TXRX_CSR1, ®); |
| 1160 | rt2x00_set_field32(®, TXRX_CSR1_BBP_ID0, 47); /* CCK Signal */ |
| 1161 | rt2x00_set_field32(®, TXRX_CSR1_BBP_ID0_VALID, 1); |
| 1162 | rt2x00_set_field32(®, TXRX_CSR1_BBP_ID1, 30); /* Rssi */ |
| 1163 | rt2x00_set_field32(®, TXRX_CSR1_BBP_ID1_VALID, 1); |
| 1164 | rt2x00_set_field32(®, TXRX_CSR1_BBP_ID2, 42); /* OFDM Rate */ |
| 1165 | rt2x00_set_field32(®, TXRX_CSR1_BBP_ID2_VALID, 1); |
| 1166 | rt2x00_set_field32(®, TXRX_CSR1_BBP_ID3, 30); /* Rssi */ |
| 1167 | rt2x00_set_field32(®, TXRX_CSR1_BBP_ID3_VALID, 1); |
| 1168 | rt73usb_register_write(rt2x00dev, TXRX_CSR1, reg); |
| 1169 | |
| 1170 | /* |
| 1171 | * CCK TXD BBP registers |
| 1172 | */ |
| 1173 | rt73usb_register_read(rt2x00dev, TXRX_CSR2, ®); |
| 1174 | rt2x00_set_field32(®, TXRX_CSR2_BBP_ID0, 13); |
| 1175 | rt2x00_set_field32(®, TXRX_CSR2_BBP_ID0_VALID, 1); |
| 1176 | rt2x00_set_field32(®, TXRX_CSR2_BBP_ID1, 12); |
| 1177 | rt2x00_set_field32(®, TXRX_CSR2_BBP_ID1_VALID, 1); |
| 1178 | rt2x00_set_field32(®, TXRX_CSR2_BBP_ID2, 11); |
| 1179 | rt2x00_set_field32(®, TXRX_CSR2_BBP_ID2_VALID, 1); |
| 1180 | rt2x00_set_field32(®, TXRX_CSR2_BBP_ID3, 10); |
| 1181 | rt2x00_set_field32(®, TXRX_CSR2_BBP_ID3_VALID, 1); |
| 1182 | rt73usb_register_write(rt2x00dev, TXRX_CSR2, reg); |
| 1183 | |
| 1184 | /* |
| 1185 | * OFDM TXD BBP registers |
| 1186 | */ |
| 1187 | rt73usb_register_read(rt2x00dev, TXRX_CSR3, ®); |
| 1188 | rt2x00_set_field32(®, TXRX_CSR3_BBP_ID0, 7); |
| 1189 | rt2x00_set_field32(®, TXRX_CSR3_BBP_ID0_VALID, 1); |
| 1190 | rt2x00_set_field32(®, TXRX_CSR3_BBP_ID1, 6); |
| 1191 | rt2x00_set_field32(®, TXRX_CSR3_BBP_ID1_VALID, 1); |
| 1192 | rt2x00_set_field32(®, TXRX_CSR3_BBP_ID2, 5); |
| 1193 | rt2x00_set_field32(®, TXRX_CSR3_BBP_ID2_VALID, 1); |
| 1194 | rt73usb_register_write(rt2x00dev, TXRX_CSR3, reg); |
| 1195 | |
| 1196 | rt73usb_register_read(rt2x00dev, TXRX_CSR7, ®); |
| 1197 | rt2x00_set_field32(®, TXRX_CSR7_ACK_CTS_6MBS, 59); |
| 1198 | rt2x00_set_field32(®, TXRX_CSR7_ACK_CTS_9MBS, 53); |
| 1199 | rt2x00_set_field32(®, TXRX_CSR7_ACK_CTS_12MBS, 49); |
| 1200 | rt2x00_set_field32(®, TXRX_CSR7_ACK_CTS_18MBS, 46); |
| 1201 | rt73usb_register_write(rt2x00dev, TXRX_CSR7, reg); |
| 1202 | |
| 1203 | rt73usb_register_read(rt2x00dev, TXRX_CSR8, ®); |
| 1204 | rt2x00_set_field32(®, TXRX_CSR8_ACK_CTS_24MBS, 44); |
| 1205 | rt2x00_set_field32(®, TXRX_CSR8_ACK_CTS_36MBS, 42); |
| 1206 | rt2x00_set_field32(®, TXRX_CSR8_ACK_CTS_48MBS, 42); |
| 1207 | rt2x00_set_field32(®, TXRX_CSR8_ACK_CTS_54MBS, 42); |
| 1208 | rt73usb_register_write(rt2x00dev, TXRX_CSR8, reg); |
| 1209 | |
Ivo van Doorn | 1f90916 | 2008-07-08 13:45:20 +0200 | [diff] [blame] | 1210 | rt73usb_register_read(rt2x00dev, TXRX_CSR9, ®); |
| 1211 | rt2x00_set_field32(®, TXRX_CSR9_BEACON_INTERVAL, 0); |
| 1212 | rt2x00_set_field32(®, TXRX_CSR9_TSF_TICKING, 0); |
| 1213 | rt2x00_set_field32(®, TXRX_CSR9_TSF_SYNC, 0); |
| 1214 | rt2x00_set_field32(®, TXRX_CSR9_TBTT_ENABLE, 0); |
| 1215 | rt2x00_set_field32(®, TXRX_CSR9_BEACON_GEN, 0); |
| 1216 | rt2x00_set_field32(®, TXRX_CSR9_TIMESTAMP_COMPENSATE, 0); |
| 1217 | rt73usb_register_write(rt2x00dev, TXRX_CSR9, reg); |
| 1218 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1219 | rt73usb_register_write(rt2x00dev, TXRX_CSR15, 0x0000000f); |
| 1220 | |
| 1221 | rt73usb_register_read(rt2x00dev, MAC_CSR6, ®); |
| 1222 | rt2x00_set_field32(®, MAC_CSR6_MAX_FRAME_UNIT, 0xfff); |
| 1223 | rt73usb_register_write(rt2x00dev, MAC_CSR6, reg); |
| 1224 | |
| 1225 | rt73usb_register_write(rt2x00dev, MAC_CSR10, 0x00000718); |
| 1226 | |
| 1227 | if (rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_AWAKE)) |
| 1228 | return -EBUSY; |
| 1229 | |
| 1230 | rt73usb_register_write(rt2x00dev, MAC_CSR13, 0x00007f00); |
| 1231 | |
| 1232 | /* |
| 1233 | * Invalidate all Shared Keys (SEC_CSR0), |
| 1234 | * and clear the Shared key Cipher algorithms (SEC_CSR1 & SEC_CSR5) |
| 1235 | */ |
| 1236 | rt73usb_register_write(rt2x00dev, SEC_CSR0, 0x00000000); |
| 1237 | rt73usb_register_write(rt2x00dev, SEC_CSR1, 0x00000000); |
| 1238 | rt73usb_register_write(rt2x00dev, SEC_CSR5, 0x00000000); |
| 1239 | |
| 1240 | reg = 0x000023b0; |
| 1241 | if (rt2x00_rf(&rt2x00dev->chip, RF5225) || |
| 1242 | rt2x00_rf(&rt2x00dev->chip, RF2527)) |
| 1243 | rt2x00_set_field32(®, PHY_CSR1_RF_RPI, 1); |
| 1244 | rt73usb_register_write(rt2x00dev, PHY_CSR1, reg); |
| 1245 | |
| 1246 | rt73usb_register_write(rt2x00dev, PHY_CSR5, 0x00040a06); |
| 1247 | rt73usb_register_write(rt2x00dev, PHY_CSR6, 0x00080606); |
| 1248 | rt73usb_register_write(rt2x00dev, PHY_CSR7, 0x00000408); |
| 1249 | |
| 1250 | rt73usb_register_read(rt2x00dev, AC_TXOP_CSR0, ®); |
| 1251 | rt2x00_set_field32(®, AC_TXOP_CSR0_AC0_TX_OP, 0); |
| 1252 | rt2x00_set_field32(®, AC_TXOP_CSR0_AC1_TX_OP, 0); |
| 1253 | rt73usb_register_write(rt2x00dev, AC_TXOP_CSR0, reg); |
| 1254 | |
| 1255 | rt73usb_register_read(rt2x00dev, AC_TXOP_CSR1, ®); |
| 1256 | rt2x00_set_field32(®, AC_TXOP_CSR1_AC2_TX_OP, 192); |
| 1257 | rt2x00_set_field32(®, AC_TXOP_CSR1_AC3_TX_OP, 48); |
| 1258 | rt73usb_register_write(rt2x00dev, AC_TXOP_CSR1, reg); |
| 1259 | |
| 1260 | rt73usb_register_read(rt2x00dev, MAC_CSR9, ®); |
| 1261 | rt2x00_set_field32(®, MAC_CSR9_CW_SELECT, 0); |
| 1262 | rt73usb_register_write(rt2x00dev, MAC_CSR9, reg); |
| 1263 | |
| 1264 | /* |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame] | 1265 | * Clear all beacons |
| 1266 | * For the Beacon base registers we only need to clear |
| 1267 | * the first byte since that byte contains the VALID and OWNER |
| 1268 | * bits which (when set to 0) will invalidate the entire beacon. |
| 1269 | */ |
| 1270 | rt73usb_register_write(rt2x00dev, HW_BEACON_BASE0, 0); |
| 1271 | rt73usb_register_write(rt2x00dev, HW_BEACON_BASE1, 0); |
| 1272 | rt73usb_register_write(rt2x00dev, HW_BEACON_BASE2, 0); |
| 1273 | rt73usb_register_write(rt2x00dev, HW_BEACON_BASE3, 0); |
| 1274 | |
| 1275 | /* |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1276 | * We must clear the error counters. |
| 1277 | * These registers are cleared on read, |
| 1278 | * so we may pass a useless variable to store the value. |
| 1279 | */ |
| 1280 | rt73usb_register_read(rt2x00dev, STA_CSR0, ®); |
| 1281 | rt73usb_register_read(rt2x00dev, STA_CSR1, ®); |
| 1282 | rt73usb_register_read(rt2x00dev, STA_CSR2, ®); |
| 1283 | |
| 1284 | /* |
| 1285 | * Reset MAC and BBP registers. |
| 1286 | */ |
| 1287 | rt73usb_register_read(rt2x00dev, MAC_CSR1, ®); |
| 1288 | rt2x00_set_field32(®, MAC_CSR1_SOFT_RESET, 1); |
| 1289 | rt2x00_set_field32(®, MAC_CSR1_BBP_RESET, 1); |
| 1290 | rt73usb_register_write(rt2x00dev, MAC_CSR1, reg); |
| 1291 | |
| 1292 | rt73usb_register_read(rt2x00dev, MAC_CSR1, ®); |
| 1293 | rt2x00_set_field32(®, MAC_CSR1_SOFT_RESET, 0); |
| 1294 | rt2x00_set_field32(®, MAC_CSR1_BBP_RESET, 0); |
| 1295 | rt73usb_register_write(rt2x00dev, MAC_CSR1, reg); |
| 1296 | |
| 1297 | rt73usb_register_read(rt2x00dev, MAC_CSR1, ®); |
| 1298 | rt2x00_set_field32(®, MAC_CSR1_HOST_READY, 1); |
| 1299 | rt73usb_register_write(rt2x00dev, MAC_CSR1, reg); |
| 1300 | |
| 1301 | return 0; |
| 1302 | } |
| 1303 | |
Ivo van Doorn | 2b08da3 | 2008-06-03 18:58:56 +0200 | [diff] [blame] | 1304 | static int rt73usb_wait_bbp_ready(struct rt2x00_dev *rt2x00dev) |
| 1305 | { |
| 1306 | unsigned int i; |
| 1307 | u8 value; |
| 1308 | |
| 1309 | for (i = 0; i < REGISTER_BUSY_COUNT; i++) { |
| 1310 | rt73usb_bbp_read(rt2x00dev, 0, &value); |
| 1311 | if ((value != 0xff) && (value != 0x00)) |
| 1312 | return 0; |
| 1313 | udelay(REGISTER_BUSY_DELAY); |
| 1314 | } |
| 1315 | |
| 1316 | ERROR(rt2x00dev, "BBP register access failed, aborting.\n"); |
| 1317 | return -EACCES; |
| 1318 | } |
| 1319 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1320 | static int rt73usb_init_bbp(struct rt2x00_dev *rt2x00dev) |
| 1321 | { |
| 1322 | unsigned int i; |
| 1323 | u16 eeprom; |
| 1324 | u8 reg_id; |
| 1325 | u8 value; |
| 1326 | |
Ivo van Doorn | 2b08da3 | 2008-06-03 18:58:56 +0200 | [diff] [blame] | 1327 | if (unlikely(rt73usb_wait_bbp_ready(rt2x00dev))) |
| 1328 | return -EACCES; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1329 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1330 | rt73usb_bbp_write(rt2x00dev, 3, 0x80); |
| 1331 | rt73usb_bbp_write(rt2x00dev, 15, 0x30); |
| 1332 | rt73usb_bbp_write(rt2x00dev, 21, 0xc8); |
| 1333 | rt73usb_bbp_write(rt2x00dev, 22, 0x38); |
| 1334 | rt73usb_bbp_write(rt2x00dev, 23, 0x06); |
| 1335 | rt73usb_bbp_write(rt2x00dev, 24, 0xfe); |
| 1336 | rt73usb_bbp_write(rt2x00dev, 25, 0x0a); |
| 1337 | rt73usb_bbp_write(rt2x00dev, 26, 0x0d); |
| 1338 | rt73usb_bbp_write(rt2x00dev, 32, 0x0b); |
| 1339 | rt73usb_bbp_write(rt2x00dev, 34, 0x12); |
| 1340 | rt73usb_bbp_write(rt2x00dev, 37, 0x07); |
| 1341 | rt73usb_bbp_write(rt2x00dev, 39, 0xf8); |
| 1342 | rt73usb_bbp_write(rt2x00dev, 41, 0x60); |
| 1343 | rt73usb_bbp_write(rt2x00dev, 53, 0x10); |
| 1344 | rt73usb_bbp_write(rt2x00dev, 54, 0x18); |
| 1345 | rt73usb_bbp_write(rt2x00dev, 60, 0x10); |
| 1346 | rt73usb_bbp_write(rt2x00dev, 61, 0x04); |
| 1347 | rt73usb_bbp_write(rt2x00dev, 62, 0x04); |
| 1348 | rt73usb_bbp_write(rt2x00dev, 75, 0xfe); |
| 1349 | rt73usb_bbp_write(rt2x00dev, 86, 0xfe); |
| 1350 | rt73usb_bbp_write(rt2x00dev, 88, 0xfe); |
| 1351 | rt73usb_bbp_write(rt2x00dev, 90, 0x0f); |
| 1352 | rt73usb_bbp_write(rt2x00dev, 99, 0x00); |
| 1353 | rt73usb_bbp_write(rt2x00dev, 102, 0x16); |
| 1354 | rt73usb_bbp_write(rt2x00dev, 107, 0x04); |
| 1355 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1356 | for (i = 0; i < EEPROM_BBP_SIZE; i++) { |
| 1357 | rt2x00_eeprom_read(rt2x00dev, EEPROM_BBP_START + i, &eeprom); |
| 1358 | |
| 1359 | if (eeprom != 0xffff && eeprom != 0x0000) { |
| 1360 | reg_id = rt2x00_get_field16(eeprom, EEPROM_BBP_REG_ID); |
| 1361 | value = rt2x00_get_field16(eeprom, EEPROM_BBP_VALUE); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1362 | rt73usb_bbp_write(rt2x00dev, reg_id, value); |
| 1363 | } |
| 1364 | } |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1365 | |
| 1366 | return 0; |
| 1367 | } |
| 1368 | |
| 1369 | /* |
| 1370 | * Device state switch handlers. |
| 1371 | */ |
| 1372 | static void rt73usb_toggle_rx(struct rt2x00_dev *rt2x00dev, |
| 1373 | enum dev_state state) |
| 1374 | { |
| 1375 | u32 reg; |
| 1376 | |
| 1377 | rt73usb_register_read(rt2x00dev, TXRX_CSR0, ®); |
| 1378 | rt2x00_set_field32(®, TXRX_CSR0_DISABLE_RX, |
Ivo van Doorn | 2b08da3 | 2008-06-03 18:58:56 +0200 | [diff] [blame] | 1379 | (state == STATE_RADIO_RX_OFF) || |
| 1380 | (state == STATE_RADIO_RX_OFF_LINK)); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1381 | rt73usb_register_write(rt2x00dev, TXRX_CSR0, reg); |
| 1382 | } |
| 1383 | |
| 1384 | static int rt73usb_enable_radio(struct rt2x00_dev *rt2x00dev) |
| 1385 | { |
| 1386 | /* |
| 1387 | * Initialize all registers. |
| 1388 | */ |
Ivo van Doorn | 2b08da3 | 2008-06-03 18:58:56 +0200 | [diff] [blame] | 1389 | if (unlikely(rt73usb_init_registers(rt2x00dev) || |
| 1390 | rt73usb_init_bbp(rt2x00dev))) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1391 | return -EIO; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1392 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1393 | return 0; |
| 1394 | } |
| 1395 | |
| 1396 | static void rt73usb_disable_radio(struct rt2x00_dev *rt2x00dev) |
| 1397 | { |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1398 | rt73usb_register_write(rt2x00dev, MAC_CSR10, 0x00001818); |
| 1399 | |
| 1400 | /* |
| 1401 | * Disable synchronisation. |
| 1402 | */ |
| 1403 | rt73usb_register_write(rt2x00dev, TXRX_CSR9, 0); |
| 1404 | |
| 1405 | rt2x00usb_disable_radio(rt2x00dev); |
| 1406 | } |
| 1407 | |
| 1408 | static int rt73usb_set_state(struct rt2x00_dev *rt2x00dev, enum dev_state state) |
| 1409 | { |
| 1410 | u32 reg; |
| 1411 | unsigned int i; |
| 1412 | char put_to_sleep; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1413 | |
| 1414 | put_to_sleep = (state != STATE_AWAKE); |
| 1415 | |
| 1416 | rt73usb_register_read(rt2x00dev, MAC_CSR12, ®); |
| 1417 | rt2x00_set_field32(®, MAC_CSR12_FORCE_WAKEUP, !put_to_sleep); |
| 1418 | rt2x00_set_field32(®, MAC_CSR12_PUT_TO_SLEEP, put_to_sleep); |
| 1419 | rt73usb_register_write(rt2x00dev, MAC_CSR12, reg); |
| 1420 | |
| 1421 | /* |
| 1422 | * Device is not guaranteed to be in the requested state yet. |
| 1423 | * We must wait until the register indicates that the |
| 1424 | * device has entered the correct state. |
| 1425 | */ |
| 1426 | for (i = 0; i < REGISTER_BUSY_COUNT; i++) { |
| 1427 | rt73usb_register_read(rt2x00dev, MAC_CSR12, ®); |
Ivo van Doorn | 2b08da3 | 2008-06-03 18:58:56 +0200 | [diff] [blame] | 1428 | state = rt2x00_get_field32(reg, MAC_CSR12_BBP_CURRENT_STATE); |
| 1429 | if (state == !put_to_sleep) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1430 | return 0; |
| 1431 | msleep(10); |
| 1432 | } |
| 1433 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1434 | return -EBUSY; |
| 1435 | } |
| 1436 | |
| 1437 | static int rt73usb_set_device_state(struct rt2x00_dev *rt2x00dev, |
| 1438 | enum dev_state state) |
| 1439 | { |
| 1440 | int retval = 0; |
| 1441 | |
| 1442 | switch (state) { |
| 1443 | case STATE_RADIO_ON: |
| 1444 | retval = rt73usb_enable_radio(rt2x00dev); |
| 1445 | break; |
| 1446 | case STATE_RADIO_OFF: |
| 1447 | rt73usb_disable_radio(rt2x00dev); |
| 1448 | break; |
| 1449 | case STATE_RADIO_RX_ON: |
Ivo van Doorn | 61667d8 | 2008-02-25 23:15:05 +0100 | [diff] [blame] | 1450 | case STATE_RADIO_RX_ON_LINK: |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1451 | case STATE_RADIO_RX_OFF: |
Ivo van Doorn | 61667d8 | 2008-02-25 23:15:05 +0100 | [diff] [blame] | 1452 | case STATE_RADIO_RX_OFF_LINK: |
Ivo van Doorn | 2b08da3 | 2008-06-03 18:58:56 +0200 | [diff] [blame] | 1453 | rt73usb_toggle_rx(rt2x00dev, state); |
| 1454 | break; |
| 1455 | case STATE_RADIO_IRQ_ON: |
| 1456 | case STATE_RADIO_IRQ_OFF: |
| 1457 | /* No support, but no error either */ |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1458 | break; |
| 1459 | case STATE_DEEP_SLEEP: |
| 1460 | case STATE_SLEEP: |
| 1461 | case STATE_STANDBY: |
| 1462 | case STATE_AWAKE: |
| 1463 | retval = rt73usb_set_state(rt2x00dev, state); |
| 1464 | break; |
| 1465 | default: |
| 1466 | retval = -ENOTSUPP; |
| 1467 | break; |
| 1468 | } |
| 1469 | |
Ivo van Doorn | 2b08da3 | 2008-06-03 18:58:56 +0200 | [diff] [blame] | 1470 | if (unlikely(retval)) |
| 1471 | ERROR(rt2x00dev, "Device failed to enter state %d (%d).\n", |
| 1472 | state, retval); |
| 1473 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1474 | return retval; |
| 1475 | } |
| 1476 | |
| 1477 | /* |
| 1478 | * TX descriptor initialization |
| 1479 | */ |
| 1480 | static void rt73usb_write_tx_desc(struct rt2x00_dev *rt2x00dev, |
Ivo van Doorn | 906c110 | 2008-08-04 16:38:24 +0200 | [diff] [blame] | 1481 | struct sk_buff *skb, |
| 1482 | struct txentry_desc *txdesc) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1483 | { |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 1484 | struct skb_frame_desc *skbdesc = get_skb_frame_desc(skb); |
Ivo van Doorn | dd3193e | 2008-01-06 23:41:10 +0100 | [diff] [blame] | 1485 | __le32 *txd = skbdesc->desc; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1486 | u32 word; |
| 1487 | |
| 1488 | /* |
| 1489 | * Start writing the descriptor words. |
| 1490 | */ |
| 1491 | rt2x00_desc_read(txd, 1, &word); |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 1492 | rt2x00_set_field32(&word, TXD_W1_HOST_Q_ID, txdesc->queue); |
| 1493 | rt2x00_set_field32(&word, TXD_W1_AIFSN, txdesc->aifs); |
| 1494 | rt2x00_set_field32(&word, TXD_W1_CWMIN, txdesc->cw_min); |
| 1495 | rt2x00_set_field32(&word, TXD_W1_CWMAX, txdesc->cw_max); |
Ivo van Doorn | 906c110 | 2008-08-04 16:38:24 +0200 | [diff] [blame] | 1496 | rt2x00_set_field32(&word, TXD_W1_IV_OFFSET, txdesc->iv_offset); |
Ivo van Doorn | 5adf6d6 | 2008-07-20 18:03:38 +0200 | [diff] [blame] | 1497 | rt2x00_set_field32(&word, TXD_W1_HW_SEQUENCE, |
| 1498 | test_bit(ENTRY_TXD_GENERATE_SEQ, &txdesc->flags)); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1499 | rt2x00_desc_write(txd, 1, word); |
| 1500 | |
| 1501 | rt2x00_desc_read(txd, 2, &word); |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 1502 | rt2x00_set_field32(&word, TXD_W2_PLCP_SIGNAL, txdesc->signal); |
| 1503 | rt2x00_set_field32(&word, TXD_W2_PLCP_SERVICE, txdesc->service); |
| 1504 | rt2x00_set_field32(&word, TXD_W2_PLCP_LENGTH_LOW, txdesc->length_low); |
| 1505 | rt2x00_set_field32(&word, TXD_W2_PLCP_LENGTH_HIGH, txdesc->length_high); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1506 | rt2x00_desc_write(txd, 2, word); |
| 1507 | |
Ivo van Doorn | 906c110 | 2008-08-04 16:38:24 +0200 | [diff] [blame] | 1508 | if (test_bit(ENTRY_TXD_ENCRYPT, &txdesc->flags)) { |
| 1509 | _rt2x00_desc_write(txd, 3, skbdesc->iv); |
| 1510 | _rt2x00_desc_write(txd, 4, skbdesc->eiv); |
| 1511 | } |
| 1512 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1513 | rt2x00_desc_read(txd, 5, &word); |
| 1514 | rt2x00_set_field32(&word, TXD_W5_TX_POWER, |
Ivo van Doorn | ac1aa7e | 2008-02-17 17:31:48 +0100 | [diff] [blame] | 1515 | TXPOWER_TO_DEV(rt2x00dev->tx_power)); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1516 | rt2x00_set_field32(&word, TXD_W5_WAITING_DMA_DONE_INT, 1); |
| 1517 | rt2x00_desc_write(txd, 5, word); |
| 1518 | |
| 1519 | rt2x00_desc_read(txd, 0, &word); |
| 1520 | rt2x00_set_field32(&word, TXD_W0_BURST, |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 1521 | test_bit(ENTRY_TXD_BURST, &txdesc->flags)); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1522 | rt2x00_set_field32(&word, TXD_W0_VALID, 1); |
| 1523 | rt2x00_set_field32(&word, TXD_W0_MORE_FRAG, |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 1524 | test_bit(ENTRY_TXD_MORE_FRAG, &txdesc->flags)); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1525 | rt2x00_set_field32(&word, TXD_W0_ACK, |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 1526 | test_bit(ENTRY_TXD_ACK, &txdesc->flags)); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1527 | rt2x00_set_field32(&word, TXD_W0_TIMESTAMP, |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 1528 | test_bit(ENTRY_TXD_REQ_TIMESTAMP, &txdesc->flags)); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1529 | rt2x00_set_field32(&word, TXD_W0_OFDM, |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 1530 | test_bit(ENTRY_TXD_OFDM_RATE, &txdesc->flags)); |
| 1531 | rt2x00_set_field32(&word, TXD_W0_IFS, txdesc->ifs); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1532 | rt2x00_set_field32(&word, TXD_W0_RETRY_MODE, |
Ivo van Doorn | 61486e0 | 2008-05-10 13:42:31 +0200 | [diff] [blame] | 1533 | test_bit(ENTRY_TXD_RETRY_MODE, &txdesc->flags)); |
Ivo van Doorn | 906c110 | 2008-08-04 16:38:24 +0200 | [diff] [blame] | 1534 | rt2x00_set_field32(&word, TXD_W0_TKIP_MIC, |
| 1535 | test_bit(ENTRY_TXD_ENCRYPT_MMIC, &txdesc->flags)); |
| 1536 | rt2x00_set_field32(&word, TXD_W0_KEY_TABLE, |
| 1537 | test_bit(ENTRY_TXD_ENCRYPT_PAIRWISE, &txdesc->flags)); |
| 1538 | rt2x00_set_field32(&word, TXD_W0_KEY_INDEX, txdesc->key_idx); |
Gertjan van Wingerde | d56d453 | 2008-06-06 22:54:08 +0200 | [diff] [blame] | 1539 | rt2x00_set_field32(&word, TXD_W0_DATABYTE_COUNT, |
| 1540 | skb->len - skbdesc->desc_len); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1541 | rt2x00_set_field32(&word, TXD_W0_BURST2, |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 1542 | test_bit(ENTRY_TXD_BURST, &txdesc->flags)); |
Ivo van Doorn | 906c110 | 2008-08-04 16:38:24 +0200 | [diff] [blame] | 1543 | rt2x00_set_field32(&word, TXD_W0_CIPHER_ALG, txdesc->cipher); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1544 | rt2x00_desc_write(txd, 0, word); |
| 1545 | } |
| 1546 | |
Ivo van Doorn | bd88a78 | 2008-07-09 15:12:44 +0200 | [diff] [blame] | 1547 | /* |
| 1548 | * TX data initialization |
| 1549 | */ |
| 1550 | static void rt73usb_write_beacon(struct queue_entry *entry) |
| 1551 | { |
| 1552 | struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev; |
| 1553 | struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb); |
| 1554 | unsigned int beacon_base; |
| 1555 | u32 reg; |
Iwo Mergler | b93ce43 | 2008-07-19 16:17:40 +0200 | [diff] [blame] | 1556 | u32 word, len; |
Ivo van Doorn | bd88a78 | 2008-07-09 15:12:44 +0200 | [diff] [blame] | 1557 | |
| 1558 | /* |
| 1559 | * Add the descriptor in front of the skb. |
| 1560 | */ |
| 1561 | skb_push(entry->skb, entry->queue->desc_size); |
| 1562 | memcpy(entry->skb->data, skbdesc->desc, skbdesc->desc_len); |
| 1563 | skbdesc->desc = entry->skb->data; |
| 1564 | |
| 1565 | /* |
Iwo Mergler | b93ce43 | 2008-07-19 16:17:40 +0200 | [diff] [blame] | 1566 | * Adjust the beacon databyte count. The current number is |
| 1567 | * calculated before this function gets called, but falsely |
| 1568 | * assumes that the descriptor was already present in the SKB. |
| 1569 | */ |
| 1570 | rt2x00_desc_read(skbdesc->desc, 0, &word); |
| 1571 | len = rt2x00_get_field32(word, TXD_W0_DATABYTE_COUNT); |
| 1572 | len += skbdesc->desc_len; |
| 1573 | rt2x00_set_field32(&word, TXD_W0_DATABYTE_COUNT, len); |
| 1574 | rt2x00_desc_write(skbdesc->desc, 0, word); |
| 1575 | |
| 1576 | /* |
Ivo van Doorn | bd88a78 | 2008-07-09 15:12:44 +0200 | [diff] [blame] | 1577 | * Disable beaconing while we are reloading the beacon data, |
| 1578 | * otherwise we might be sending out invalid data. |
| 1579 | */ |
| 1580 | rt73usb_register_read(rt2x00dev, TXRX_CSR9, ®); |
| 1581 | rt2x00_set_field32(®, TXRX_CSR9_TSF_TICKING, 0); |
| 1582 | rt2x00_set_field32(®, TXRX_CSR9_TBTT_ENABLE, 0); |
| 1583 | rt2x00_set_field32(®, TXRX_CSR9_BEACON_GEN, 0); |
| 1584 | rt73usb_register_write(rt2x00dev, TXRX_CSR9, reg); |
| 1585 | |
| 1586 | /* |
| 1587 | * Write entire beacon with descriptor to register. |
| 1588 | */ |
| 1589 | beacon_base = HW_BEACON_OFFSET(entry->entry_idx); |
Iwo Mergler | 3e0c1abe | 2008-07-19 16:17:16 +0200 | [diff] [blame] | 1590 | rt2x00usb_vendor_request_large_buff(rt2x00dev, USB_MULTI_WRITE, |
| 1591 | USB_VENDOR_REQUEST_OUT, beacon_base, |
| 1592 | entry->skb->data, entry->skb->len, |
| 1593 | REGISTER_TIMEOUT32(entry->skb->len)); |
Ivo van Doorn | bd88a78 | 2008-07-09 15:12:44 +0200 | [diff] [blame] | 1594 | |
| 1595 | /* |
| 1596 | * Clean up the beacon skb. |
| 1597 | */ |
| 1598 | dev_kfree_skb(entry->skb); |
| 1599 | entry->skb = NULL; |
| 1600 | } |
| 1601 | |
Ivo van Doorn | dd9fa2d | 2007-10-06 14:15:46 +0200 | [diff] [blame] | 1602 | static int rt73usb_get_tx_data_len(struct rt2x00_dev *rt2x00dev, |
Ivo van Doorn | b242e89 | 2007-11-15 23:41:31 +0100 | [diff] [blame] | 1603 | struct sk_buff *skb) |
Ivo van Doorn | dd9fa2d | 2007-10-06 14:15:46 +0200 | [diff] [blame] | 1604 | { |
| 1605 | int length; |
| 1606 | |
| 1607 | /* |
| 1608 | * The length _must_ be a multiple of 4, |
| 1609 | * but it must _not_ be a multiple of the USB packet size. |
| 1610 | */ |
| 1611 | length = roundup(skb->len, 4); |
Ivo van Doorn | b242e89 | 2007-11-15 23:41:31 +0100 | [diff] [blame] | 1612 | length += (4 * !(length % rt2x00dev->usb_maxpacket)); |
Ivo van Doorn | dd9fa2d | 2007-10-06 14:15:46 +0200 | [diff] [blame] | 1613 | |
| 1614 | return length; |
| 1615 | } |
| 1616 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1617 | static void rt73usb_kick_tx_queue(struct rt2x00_dev *rt2x00dev, |
Ivo van Doorn | e58c6ac | 2008-04-21 19:00:47 +0200 | [diff] [blame] | 1618 | const enum data_queue_qid queue) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1619 | { |
| 1620 | u32 reg; |
| 1621 | |
Ivo van Doorn | f019d51 | 2008-06-06 22:47:39 +0200 | [diff] [blame] | 1622 | if (queue != QID_BEACON) { |
| 1623 | rt2x00usb_kick_tx_queue(rt2x00dev, queue); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1624 | return; |
Ivo van Doorn | f019d51 | 2008-06-06 22:47:39 +0200 | [diff] [blame] | 1625 | } |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1626 | |
| 1627 | /* |
| 1628 | * For Wi-Fi faily generated beacons between participating stations. |
| 1629 | * Set TBTT phase adaptive adjustment step to 8us (default 16us) |
| 1630 | */ |
| 1631 | rt73usb_register_write(rt2x00dev, TXRX_CSR10, 0x00001008); |
| 1632 | |
| 1633 | rt73usb_register_read(rt2x00dev, TXRX_CSR9, ®); |
| 1634 | if (!rt2x00_get_field32(reg, TXRX_CSR9_BEACON_GEN)) { |
Ivo van Doorn | 8af244c | 2008-03-09 22:42:59 +0100 | [diff] [blame] | 1635 | rt2x00_set_field32(®, TXRX_CSR9_TSF_TICKING, 1); |
| 1636 | rt2x00_set_field32(®, TXRX_CSR9_TBTT_ENABLE, 1); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1637 | rt2x00_set_field32(®, TXRX_CSR9_BEACON_GEN, 1); |
| 1638 | rt73usb_register_write(rt2x00dev, TXRX_CSR9, reg); |
| 1639 | } |
| 1640 | } |
| 1641 | |
| 1642 | /* |
| 1643 | * RX control handlers |
| 1644 | */ |
| 1645 | static int rt73usb_agc_to_rssi(struct rt2x00_dev *rt2x00dev, int rxd_w1) |
| 1646 | { |
| 1647 | u16 eeprom; |
| 1648 | u8 offset; |
| 1649 | u8 lna; |
| 1650 | |
| 1651 | lna = rt2x00_get_field32(rxd_w1, RXD_W1_RSSI_LNA); |
| 1652 | switch (lna) { |
| 1653 | case 3: |
| 1654 | offset = 90; |
| 1655 | break; |
| 1656 | case 2: |
| 1657 | offset = 74; |
| 1658 | break; |
| 1659 | case 1: |
| 1660 | offset = 64; |
| 1661 | break; |
| 1662 | default: |
| 1663 | return 0; |
| 1664 | } |
| 1665 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1666 | if (rt2x00dev->rx_status.band == IEEE80211_BAND_5GHZ) { |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1667 | if (test_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags)) { |
| 1668 | if (lna == 3 || lna == 2) |
| 1669 | offset += 10; |
| 1670 | } else { |
| 1671 | if (lna == 3) |
| 1672 | offset += 6; |
| 1673 | else if (lna == 2) |
| 1674 | offset += 8; |
| 1675 | } |
| 1676 | |
| 1677 | rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_A, &eeprom); |
| 1678 | offset -= rt2x00_get_field16(eeprom, EEPROM_RSSI_OFFSET_A_1); |
| 1679 | } else { |
| 1680 | if (test_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags)) |
| 1681 | offset += 14; |
| 1682 | |
| 1683 | rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_BG, &eeprom); |
| 1684 | offset -= rt2x00_get_field16(eeprom, EEPROM_RSSI_OFFSET_BG_1); |
| 1685 | } |
| 1686 | |
| 1687 | return rt2x00_get_field32(rxd_w1, RXD_W1_RSSI_AGC) * 2 - offset; |
| 1688 | } |
| 1689 | |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 1690 | static void rt73usb_fill_rxdone(struct queue_entry *entry, |
| 1691 | struct rxdone_entry_desc *rxdesc) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1692 | { |
Ivo van Doorn | 906c110 | 2008-08-04 16:38:24 +0200 | [diff] [blame] | 1693 | struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev; |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 1694 | struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb); |
Ivo van Doorn | 4bd7c45 | 2008-01-24 00:48:03 -0800 | [diff] [blame] | 1695 | __le32 *rxd = (__le32 *)entry->skb->data; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1696 | u32 word0; |
| 1697 | u32 word1; |
| 1698 | |
Ivo van Doorn | f855c10 | 2008-03-09 22:38:18 +0100 | [diff] [blame] | 1699 | /* |
Gertjan van Wingerde | a26cbc6 | 2008-06-06 22:54:28 +0200 | [diff] [blame] | 1700 | * Copy descriptor to the skbdesc->desc buffer, making it safe from moving of |
| 1701 | * frame data in rt2x00usb. |
Ivo van Doorn | f855c10 | 2008-03-09 22:38:18 +0100 | [diff] [blame] | 1702 | */ |
Gertjan van Wingerde | a26cbc6 | 2008-06-06 22:54:28 +0200 | [diff] [blame] | 1703 | memcpy(skbdesc->desc, rxd, skbdesc->desc_len); |
Ivo van Doorn | 70a9610 | 2008-05-10 13:43:38 +0200 | [diff] [blame] | 1704 | rxd = (__le32 *)skbdesc->desc; |
Ivo van Doorn | f855c10 | 2008-03-09 22:38:18 +0100 | [diff] [blame] | 1705 | |
| 1706 | /* |
Ivo van Doorn | 70a9610 | 2008-05-10 13:43:38 +0200 | [diff] [blame] | 1707 | * It is now safe to read the descriptor on all architectures. |
Ivo van Doorn | f855c10 | 2008-03-09 22:38:18 +0100 | [diff] [blame] | 1708 | */ |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1709 | rt2x00_desc_read(rxd, 0, &word0); |
| 1710 | rt2x00_desc_read(rxd, 1, &word1); |
| 1711 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 1712 | if (rt2x00_get_field32(word0, RXD_W0_CRC_ERROR)) |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 1713 | rxdesc->flags |= RX_FLAG_FAILED_FCS_CRC; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1714 | |
Ivo van Doorn | 906c110 | 2008-08-04 16:38:24 +0200 | [diff] [blame] | 1715 | if (test_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags)) { |
| 1716 | rxdesc->cipher = |
| 1717 | rt2x00_get_field32(word0, RXD_W0_CIPHER_ALG); |
| 1718 | rxdesc->cipher_status = |
| 1719 | rt2x00_get_field32(word0, RXD_W0_CIPHER_ERROR); |
| 1720 | } |
| 1721 | |
| 1722 | if (rxdesc->cipher != CIPHER_NONE) { |
| 1723 | _rt2x00_desc_read(rxd, 2, &rxdesc->iv); |
| 1724 | _rt2x00_desc_read(rxd, 3, &rxdesc->eiv); |
| 1725 | _rt2x00_desc_read(rxd, 4, &rxdesc->icv); |
| 1726 | |
| 1727 | /* |
| 1728 | * Hardware has stripped IV/EIV data from 802.11 frame during |
| 1729 | * decryption. It has provided the data seperately but rt2x00lib |
| 1730 | * should decide if it should be reinserted. |
| 1731 | */ |
| 1732 | rxdesc->flags |= RX_FLAG_IV_STRIPPED; |
| 1733 | |
| 1734 | /* |
| 1735 | * FIXME: Legacy driver indicates that the frame does |
| 1736 | * contain the Michael Mic. Unfortunately, in rt2x00 |
| 1737 | * the MIC seems to be missing completely... |
| 1738 | */ |
| 1739 | rxdesc->flags |= RX_FLAG_MMIC_STRIPPED; |
| 1740 | |
| 1741 | if (rxdesc->cipher_status == RX_CRYPTO_SUCCESS) |
| 1742 | rxdesc->flags |= RX_FLAG_DECRYPTED; |
| 1743 | else if (rxdesc->cipher_status == RX_CRYPTO_FAIL_MIC) |
| 1744 | rxdesc->flags |= RX_FLAG_MMIC_ERROR; |
| 1745 | } |
| 1746 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1747 | /* |
| 1748 | * Obtain the status about this packet. |
Ivo van Doorn | 8999389 | 2008-03-09 22:49:04 +0100 | [diff] [blame] | 1749 | * When frame was received with an OFDM bitrate, |
| 1750 | * the signal is the PLCP value. If it was received with |
| 1751 | * a CCK bitrate the signal is the rate in 100kbit/s. |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1752 | */ |
Ivo van Doorn | 8999389 | 2008-03-09 22:49:04 +0100 | [diff] [blame] | 1753 | rxdesc->signal = rt2x00_get_field32(word1, RXD_W1_SIGNAL); |
Ivo van Doorn | 906c110 | 2008-08-04 16:38:24 +0200 | [diff] [blame] | 1754 | rxdesc->rssi = rt73usb_agc_to_rssi(rt2x00dev, word1); |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 1755 | rxdesc->size = rt2x00_get_field32(word0, RXD_W0_DATABYTE_COUNT); |
Ivo van Doorn | 19d30e0 | 2008-03-15 21:38:07 +0100 | [diff] [blame] | 1756 | |
Ivo van Doorn | 19d30e0 | 2008-03-15 21:38:07 +0100 | [diff] [blame] | 1757 | if (rt2x00_get_field32(word0, RXD_W0_OFDM)) |
| 1758 | rxdesc->dev_flags |= RXDONE_SIGNAL_PLCP; |
| 1759 | if (rt2x00_get_field32(word0, RXD_W0_MY_BSS)) |
| 1760 | rxdesc->dev_flags |= RXDONE_MY_BSS; |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 1761 | |
| 1762 | /* |
Ivo van Doorn | 70a9610 | 2008-05-10 13:43:38 +0200 | [diff] [blame] | 1763 | * Set skb pointers, and update frame information. |
Mattias Nissler | 2ae2385 | 2008-03-09 22:41:22 +0100 | [diff] [blame] | 1764 | */ |
Ivo van Doorn | 70a9610 | 2008-05-10 13:43:38 +0200 | [diff] [blame] | 1765 | skb_pull(entry->skb, entry->queue->desc_size); |
Mattias Nissler | 2ae2385 | 2008-03-09 22:41:22 +0100 | [diff] [blame] | 1766 | skb_trim(entry->skb, rxdesc->size); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1767 | } |
| 1768 | |
| 1769 | /* |
| 1770 | * Device probe functions. |
| 1771 | */ |
| 1772 | static int rt73usb_validate_eeprom(struct rt2x00_dev *rt2x00dev) |
| 1773 | { |
| 1774 | u16 word; |
| 1775 | u8 *mac; |
| 1776 | s8 value; |
| 1777 | |
| 1778 | rt2x00usb_eeprom_read(rt2x00dev, rt2x00dev->eeprom, EEPROM_SIZE); |
| 1779 | |
| 1780 | /* |
| 1781 | * Start validation of the data that has been read. |
| 1782 | */ |
| 1783 | mac = rt2x00_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0); |
| 1784 | if (!is_valid_ether_addr(mac)) { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1785 | DECLARE_MAC_BUF(macbuf); |
| 1786 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1787 | random_ether_addr(mac); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1788 | EEPROM(rt2x00dev, "MAC: %s\n", print_mac(macbuf, mac)); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1789 | } |
| 1790 | |
| 1791 | rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &word); |
| 1792 | if (word == 0xffff) { |
| 1793 | rt2x00_set_field16(&word, EEPROM_ANTENNA_NUM, 2); |
Ivo van Doorn | 362f3b6 | 2007-10-13 16:26:18 +0200 | [diff] [blame] | 1794 | rt2x00_set_field16(&word, EEPROM_ANTENNA_TX_DEFAULT, |
| 1795 | ANTENNA_B); |
| 1796 | rt2x00_set_field16(&word, EEPROM_ANTENNA_RX_DEFAULT, |
| 1797 | ANTENNA_B); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1798 | rt2x00_set_field16(&word, EEPROM_ANTENNA_FRAME_TYPE, 0); |
| 1799 | rt2x00_set_field16(&word, EEPROM_ANTENNA_DYN_TXAGC, 0); |
| 1800 | rt2x00_set_field16(&word, EEPROM_ANTENNA_HARDWARE_RADIO, 0); |
| 1801 | rt2x00_set_field16(&word, EEPROM_ANTENNA_RF_TYPE, RF5226); |
| 1802 | rt2x00_eeprom_write(rt2x00dev, EEPROM_ANTENNA, word); |
| 1803 | EEPROM(rt2x00dev, "Antenna: 0x%04x\n", word); |
| 1804 | } |
| 1805 | |
| 1806 | rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &word); |
| 1807 | if (word == 0xffff) { |
| 1808 | rt2x00_set_field16(&word, EEPROM_NIC_EXTERNAL_LNA, 0); |
| 1809 | rt2x00_eeprom_write(rt2x00dev, EEPROM_NIC, word); |
| 1810 | EEPROM(rt2x00dev, "NIC: 0x%04x\n", word); |
| 1811 | } |
| 1812 | |
| 1813 | rt2x00_eeprom_read(rt2x00dev, EEPROM_LED, &word); |
| 1814 | if (word == 0xffff) { |
| 1815 | rt2x00_set_field16(&word, EEPROM_LED_POLARITY_RDY_G, 0); |
| 1816 | rt2x00_set_field16(&word, EEPROM_LED_POLARITY_RDY_A, 0); |
| 1817 | rt2x00_set_field16(&word, EEPROM_LED_POLARITY_ACT, 0); |
| 1818 | rt2x00_set_field16(&word, EEPROM_LED_POLARITY_GPIO_0, 0); |
| 1819 | rt2x00_set_field16(&word, EEPROM_LED_POLARITY_GPIO_1, 0); |
| 1820 | rt2x00_set_field16(&word, EEPROM_LED_POLARITY_GPIO_2, 0); |
| 1821 | rt2x00_set_field16(&word, EEPROM_LED_POLARITY_GPIO_3, 0); |
| 1822 | rt2x00_set_field16(&word, EEPROM_LED_POLARITY_GPIO_4, 0); |
| 1823 | rt2x00_set_field16(&word, EEPROM_LED_LED_MODE, |
| 1824 | LED_MODE_DEFAULT); |
| 1825 | rt2x00_eeprom_write(rt2x00dev, EEPROM_LED, word); |
| 1826 | EEPROM(rt2x00dev, "Led: 0x%04x\n", word); |
| 1827 | } |
| 1828 | |
| 1829 | rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &word); |
| 1830 | if (word == 0xffff) { |
| 1831 | rt2x00_set_field16(&word, EEPROM_FREQ_OFFSET, 0); |
| 1832 | rt2x00_set_field16(&word, EEPROM_FREQ_SEQ, 0); |
| 1833 | rt2x00_eeprom_write(rt2x00dev, EEPROM_FREQ, word); |
| 1834 | EEPROM(rt2x00dev, "Freq: 0x%04x\n", word); |
| 1835 | } |
| 1836 | |
| 1837 | rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_BG, &word); |
| 1838 | if (word == 0xffff) { |
| 1839 | rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_BG_1, 0); |
| 1840 | rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_BG_2, 0); |
| 1841 | rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_OFFSET_BG, word); |
| 1842 | EEPROM(rt2x00dev, "RSSI OFFSET BG: 0x%04x\n", word); |
| 1843 | } else { |
| 1844 | value = rt2x00_get_field16(word, EEPROM_RSSI_OFFSET_BG_1); |
| 1845 | if (value < -10 || value > 10) |
| 1846 | rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_BG_1, 0); |
| 1847 | value = rt2x00_get_field16(word, EEPROM_RSSI_OFFSET_BG_2); |
| 1848 | if (value < -10 || value > 10) |
| 1849 | rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_BG_2, 0); |
| 1850 | rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_OFFSET_BG, word); |
| 1851 | } |
| 1852 | |
| 1853 | rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_A, &word); |
| 1854 | if (word == 0xffff) { |
| 1855 | rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_A_1, 0); |
| 1856 | rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_A_2, 0); |
| 1857 | rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_OFFSET_A, word); |
Ivo van Doorn | 417f412 | 2008-02-10 22:50:58 +0100 | [diff] [blame] | 1858 | EEPROM(rt2x00dev, "RSSI OFFSET A: 0x%04x\n", word); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1859 | } else { |
| 1860 | value = rt2x00_get_field16(word, EEPROM_RSSI_OFFSET_A_1); |
| 1861 | if (value < -10 || value > 10) |
| 1862 | rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_A_1, 0); |
| 1863 | value = rt2x00_get_field16(word, EEPROM_RSSI_OFFSET_A_2); |
| 1864 | if (value < -10 || value > 10) |
| 1865 | rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_A_2, 0); |
| 1866 | rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_OFFSET_A, word); |
| 1867 | } |
| 1868 | |
| 1869 | return 0; |
| 1870 | } |
| 1871 | |
| 1872 | static int rt73usb_init_eeprom(struct rt2x00_dev *rt2x00dev) |
| 1873 | { |
| 1874 | u32 reg; |
| 1875 | u16 value; |
| 1876 | u16 eeprom; |
| 1877 | |
| 1878 | /* |
| 1879 | * Read EEPROM word for configuration. |
| 1880 | */ |
| 1881 | rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &eeprom); |
| 1882 | |
| 1883 | /* |
| 1884 | * Identify RF chipset. |
| 1885 | */ |
| 1886 | value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RF_TYPE); |
| 1887 | rt73usb_register_read(rt2x00dev, MAC_CSR0, ®); |
| 1888 | rt2x00_set_chip(rt2x00dev, RT2571, value, reg); |
| 1889 | |
Ivo van Doorn | 755a957 | 2007-11-12 15:02:22 +0100 | [diff] [blame] | 1890 | if (!rt2x00_check_rev(&rt2x00dev->chip, 0x25730)) { |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1891 | ERROR(rt2x00dev, "Invalid RT chipset detected.\n"); |
| 1892 | return -ENODEV; |
| 1893 | } |
| 1894 | |
| 1895 | if (!rt2x00_rf(&rt2x00dev->chip, RF5226) && |
| 1896 | !rt2x00_rf(&rt2x00dev->chip, RF2528) && |
| 1897 | !rt2x00_rf(&rt2x00dev->chip, RF5225) && |
| 1898 | !rt2x00_rf(&rt2x00dev->chip, RF2527)) { |
| 1899 | ERROR(rt2x00dev, "Invalid RF chipset detected.\n"); |
| 1900 | return -ENODEV; |
| 1901 | } |
| 1902 | |
| 1903 | /* |
| 1904 | * Identify default antenna configuration. |
| 1905 | */ |
Ivo van Doorn | addc81bd | 2007-10-13 16:26:23 +0200 | [diff] [blame] | 1906 | rt2x00dev->default_ant.tx = |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1907 | rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TX_DEFAULT); |
Ivo van Doorn | addc81bd | 2007-10-13 16:26:23 +0200 | [diff] [blame] | 1908 | rt2x00dev->default_ant.rx = |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1909 | rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RX_DEFAULT); |
| 1910 | |
| 1911 | /* |
| 1912 | * Read the Frame type. |
| 1913 | */ |
| 1914 | if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_FRAME_TYPE)) |
| 1915 | __set_bit(CONFIG_FRAME_TYPE, &rt2x00dev->flags); |
| 1916 | |
| 1917 | /* |
| 1918 | * Read frequency offset. |
| 1919 | */ |
| 1920 | rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &eeprom); |
| 1921 | rt2x00dev->freq_offset = rt2x00_get_field16(eeprom, EEPROM_FREQ_OFFSET); |
| 1922 | |
| 1923 | /* |
| 1924 | * Read external LNA informations. |
| 1925 | */ |
| 1926 | rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &eeprom); |
| 1927 | |
| 1928 | if (rt2x00_get_field16(eeprom, EEPROM_NIC_EXTERNAL_LNA)) { |
| 1929 | __set_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags); |
| 1930 | __set_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags); |
| 1931 | } |
| 1932 | |
| 1933 | /* |
| 1934 | * Store led settings, for correct led behaviour. |
| 1935 | */ |
Ivo van Doorn | a9450b7 | 2008-02-03 15:53:40 +0100 | [diff] [blame] | 1936 | #ifdef CONFIG_RT73USB_LEDS |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1937 | rt2x00_eeprom_read(rt2x00dev, EEPROM_LED, &eeprom); |
| 1938 | |
Ivo van Doorn | 475433b | 2008-06-03 20:30:01 +0200 | [diff] [blame] | 1939 | rt73usb_init_led(rt2x00dev, &rt2x00dev->led_radio, LED_TYPE_RADIO); |
| 1940 | rt73usb_init_led(rt2x00dev, &rt2x00dev->led_assoc, LED_TYPE_ASSOC); |
| 1941 | if (value == LED_MODE_SIGNAL_STRENGTH) |
| 1942 | rt73usb_init_led(rt2x00dev, &rt2x00dev->led_qual, |
| 1943 | LED_TYPE_QUALITY); |
Ivo van Doorn | a9450b7 | 2008-02-03 15:53:40 +0100 | [diff] [blame] | 1944 | |
| 1945 | rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_LED_MODE, value); |
| 1946 | rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_GPIO_0, |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1947 | rt2x00_get_field16(eeprom, |
| 1948 | EEPROM_LED_POLARITY_GPIO_0)); |
Ivo van Doorn | a9450b7 | 2008-02-03 15:53:40 +0100 | [diff] [blame] | 1949 | rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_GPIO_1, |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1950 | rt2x00_get_field16(eeprom, |
| 1951 | EEPROM_LED_POLARITY_GPIO_1)); |
Ivo van Doorn | a9450b7 | 2008-02-03 15:53:40 +0100 | [diff] [blame] | 1952 | rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_GPIO_2, |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1953 | rt2x00_get_field16(eeprom, |
| 1954 | EEPROM_LED_POLARITY_GPIO_2)); |
Ivo van Doorn | a9450b7 | 2008-02-03 15:53:40 +0100 | [diff] [blame] | 1955 | rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_GPIO_3, |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1956 | rt2x00_get_field16(eeprom, |
| 1957 | EEPROM_LED_POLARITY_GPIO_3)); |
Ivo van Doorn | a9450b7 | 2008-02-03 15:53:40 +0100 | [diff] [blame] | 1958 | rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_GPIO_4, |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1959 | rt2x00_get_field16(eeprom, |
| 1960 | EEPROM_LED_POLARITY_GPIO_4)); |
Ivo van Doorn | a9450b7 | 2008-02-03 15:53:40 +0100 | [diff] [blame] | 1961 | rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_ACT, |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1962 | rt2x00_get_field16(eeprom, EEPROM_LED_POLARITY_ACT)); |
Ivo van Doorn | a9450b7 | 2008-02-03 15:53:40 +0100 | [diff] [blame] | 1963 | rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_READY_BG, |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1964 | rt2x00_get_field16(eeprom, |
| 1965 | EEPROM_LED_POLARITY_RDY_G)); |
Ivo van Doorn | a9450b7 | 2008-02-03 15:53:40 +0100 | [diff] [blame] | 1966 | rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_READY_A, |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1967 | rt2x00_get_field16(eeprom, |
| 1968 | EEPROM_LED_POLARITY_RDY_A)); |
Ivo van Doorn | a9450b7 | 2008-02-03 15:53:40 +0100 | [diff] [blame] | 1969 | #endif /* CONFIG_RT73USB_LEDS */ |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1970 | |
| 1971 | return 0; |
| 1972 | } |
| 1973 | |
| 1974 | /* |
| 1975 | * RF value list for RF2528 |
| 1976 | * Supports: 2.4 GHz |
| 1977 | */ |
| 1978 | static const struct rf_channel rf_vals_bg_2528[] = { |
| 1979 | { 1, 0x00002c0c, 0x00000786, 0x00068255, 0x000fea0b }, |
| 1980 | { 2, 0x00002c0c, 0x00000786, 0x00068255, 0x000fea1f }, |
| 1981 | { 3, 0x00002c0c, 0x0000078a, 0x00068255, 0x000fea0b }, |
| 1982 | { 4, 0x00002c0c, 0x0000078a, 0x00068255, 0x000fea1f }, |
| 1983 | { 5, 0x00002c0c, 0x0000078e, 0x00068255, 0x000fea0b }, |
| 1984 | { 6, 0x00002c0c, 0x0000078e, 0x00068255, 0x000fea1f }, |
| 1985 | { 7, 0x00002c0c, 0x00000792, 0x00068255, 0x000fea0b }, |
| 1986 | { 8, 0x00002c0c, 0x00000792, 0x00068255, 0x000fea1f }, |
| 1987 | { 9, 0x00002c0c, 0x00000796, 0x00068255, 0x000fea0b }, |
| 1988 | { 10, 0x00002c0c, 0x00000796, 0x00068255, 0x000fea1f }, |
| 1989 | { 11, 0x00002c0c, 0x0000079a, 0x00068255, 0x000fea0b }, |
| 1990 | { 12, 0x00002c0c, 0x0000079a, 0x00068255, 0x000fea1f }, |
| 1991 | { 13, 0x00002c0c, 0x0000079e, 0x00068255, 0x000fea0b }, |
| 1992 | { 14, 0x00002c0c, 0x000007a2, 0x00068255, 0x000fea13 }, |
| 1993 | }; |
| 1994 | |
| 1995 | /* |
| 1996 | * RF value list for RF5226 |
| 1997 | * Supports: 2.4 GHz & 5.2 GHz |
| 1998 | */ |
| 1999 | static const struct rf_channel rf_vals_5226[] = { |
| 2000 | { 1, 0x00002c0c, 0x00000786, 0x00068255, 0x000fea0b }, |
| 2001 | { 2, 0x00002c0c, 0x00000786, 0x00068255, 0x000fea1f }, |
| 2002 | { 3, 0x00002c0c, 0x0000078a, 0x00068255, 0x000fea0b }, |
| 2003 | { 4, 0x00002c0c, 0x0000078a, 0x00068255, 0x000fea1f }, |
| 2004 | { 5, 0x00002c0c, 0x0000078e, 0x00068255, 0x000fea0b }, |
| 2005 | { 6, 0x00002c0c, 0x0000078e, 0x00068255, 0x000fea1f }, |
| 2006 | { 7, 0x00002c0c, 0x00000792, 0x00068255, 0x000fea0b }, |
| 2007 | { 8, 0x00002c0c, 0x00000792, 0x00068255, 0x000fea1f }, |
| 2008 | { 9, 0x00002c0c, 0x00000796, 0x00068255, 0x000fea0b }, |
| 2009 | { 10, 0x00002c0c, 0x00000796, 0x00068255, 0x000fea1f }, |
| 2010 | { 11, 0x00002c0c, 0x0000079a, 0x00068255, 0x000fea0b }, |
| 2011 | { 12, 0x00002c0c, 0x0000079a, 0x00068255, 0x000fea1f }, |
| 2012 | { 13, 0x00002c0c, 0x0000079e, 0x00068255, 0x000fea0b }, |
| 2013 | { 14, 0x00002c0c, 0x000007a2, 0x00068255, 0x000fea13 }, |
| 2014 | |
| 2015 | /* 802.11 UNI / HyperLan 2 */ |
| 2016 | { 36, 0x00002c0c, 0x0000099a, 0x00098255, 0x000fea23 }, |
| 2017 | { 40, 0x00002c0c, 0x000009a2, 0x00098255, 0x000fea03 }, |
| 2018 | { 44, 0x00002c0c, 0x000009a6, 0x00098255, 0x000fea0b }, |
| 2019 | { 48, 0x00002c0c, 0x000009aa, 0x00098255, 0x000fea13 }, |
| 2020 | { 52, 0x00002c0c, 0x000009ae, 0x00098255, 0x000fea1b }, |
| 2021 | { 56, 0x00002c0c, 0x000009b2, 0x00098255, 0x000fea23 }, |
| 2022 | { 60, 0x00002c0c, 0x000009ba, 0x00098255, 0x000fea03 }, |
| 2023 | { 64, 0x00002c0c, 0x000009be, 0x00098255, 0x000fea0b }, |
| 2024 | |
| 2025 | /* 802.11 HyperLan 2 */ |
| 2026 | { 100, 0x00002c0c, 0x00000a2a, 0x000b8255, 0x000fea03 }, |
| 2027 | { 104, 0x00002c0c, 0x00000a2e, 0x000b8255, 0x000fea0b }, |
| 2028 | { 108, 0x00002c0c, 0x00000a32, 0x000b8255, 0x000fea13 }, |
| 2029 | { 112, 0x00002c0c, 0x00000a36, 0x000b8255, 0x000fea1b }, |
| 2030 | { 116, 0x00002c0c, 0x00000a3a, 0x000b8255, 0x000fea23 }, |
| 2031 | { 120, 0x00002c0c, 0x00000a82, 0x000b8255, 0x000fea03 }, |
| 2032 | { 124, 0x00002c0c, 0x00000a86, 0x000b8255, 0x000fea0b }, |
| 2033 | { 128, 0x00002c0c, 0x00000a8a, 0x000b8255, 0x000fea13 }, |
| 2034 | { 132, 0x00002c0c, 0x00000a8e, 0x000b8255, 0x000fea1b }, |
| 2035 | { 136, 0x00002c0c, 0x00000a92, 0x000b8255, 0x000fea23 }, |
| 2036 | |
| 2037 | /* 802.11 UNII */ |
| 2038 | { 140, 0x00002c0c, 0x00000a9a, 0x000b8255, 0x000fea03 }, |
| 2039 | { 149, 0x00002c0c, 0x00000aa2, 0x000b8255, 0x000fea1f }, |
| 2040 | { 153, 0x00002c0c, 0x00000aa6, 0x000b8255, 0x000fea27 }, |
| 2041 | { 157, 0x00002c0c, 0x00000aae, 0x000b8255, 0x000fea07 }, |
| 2042 | { 161, 0x00002c0c, 0x00000ab2, 0x000b8255, 0x000fea0f }, |
| 2043 | { 165, 0x00002c0c, 0x00000ab6, 0x000b8255, 0x000fea17 }, |
| 2044 | |
| 2045 | /* MMAC(Japan)J52 ch 34,38,42,46 */ |
| 2046 | { 34, 0x00002c0c, 0x0008099a, 0x000da255, 0x000d3a0b }, |
| 2047 | { 38, 0x00002c0c, 0x0008099e, 0x000da255, 0x000d3a13 }, |
| 2048 | { 42, 0x00002c0c, 0x000809a2, 0x000da255, 0x000d3a1b }, |
| 2049 | { 46, 0x00002c0c, 0x000809a6, 0x000da255, 0x000d3a23 }, |
| 2050 | }; |
| 2051 | |
| 2052 | /* |
| 2053 | * RF value list for RF5225 & RF2527 |
| 2054 | * Supports: 2.4 GHz & 5.2 GHz |
| 2055 | */ |
| 2056 | static const struct rf_channel rf_vals_5225_2527[] = { |
| 2057 | { 1, 0x00002ccc, 0x00004786, 0x00068455, 0x000ffa0b }, |
| 2058 | { 2, 0x00002ccc, 0x00004786, 0x00068455, 0x000ffa1f }, |
| 2059 | { 3, 0x00002ccc, 0x0000478a, 0x00068455, 0x000ffa0b }, |
| 2060 | { 4, 0x00002ccc, 0x0000478a, 0x00068455, 0x000ffa1f }, |
| 2061 | { 5, 0x00002ccc, 0x0000478e, 0x00068455, 0x000ffa0b }, |
| 2062 | { 6, 0x00002ccc, 0x0000478e, 0x00068455, 0x000ffa1f }, |
| 2063 | { 7, 0x00002ccc, 0x00004792, 0x00068455, 0x000ffa0b }, |
| 2064 | { 8, 0x00002ccc, 0x00004792, 0x00068455, 0x000ffa1f }, |
| 2065 | { 9, 0x00002ccc, 0x00004796, 0x00068455, 0x000ffa0b }, |
| 2066 | { 10, 0x00002ccc, 0x00004796, 0x00068455, 0x000ffa1f }, |
| 2067 | { 11, 0x00002ccc, 0x0000479a, 0x00068455, 0x000ffa0b }, |
| 2068 | { 12, 0x00002ccc, 0x0000479a, 0x00068455, 0x000ffa1f }, |
| 2069 | { 13, 0x00002ccc, 0x0000479e, 0x00068455, 0x000ffa0b }, |
| 2070 | { 14, 0x00002ccc, 0x000047a2, 0x00068455, 0x000ffa13 }, |
| 2071 | |
| 2072 | /* 802.11 UNI / HyperLan 2 */ |
| 2073 | { 36, 0x00002ccc, 0x0000499a, 0x0009be55, 0x000ffa23 }, |
| 2074 | { 40, 0x00002ccc, 0x000049a2, 0x0009be55, 0x000ffa03 }, |
| 2075 | { 44, 0x00002ccc, 0x000049a6, 0x0009be55, 0x000ffa0b }, |
| 2076 | { 48, 0x00002ccc, 0x000049aa, 0x0009be55, 0x000ffa13 }, |
| 2077 | { 52, 0x00002ccc, 0x000049ae, 0x0009ae55, 0x000ffa1b }, |
| 2078 | { 56, 0x00002ccc, 0x000049b2, 0x0009ae55, 0x000ffa23 }, |
| 2079 | { 60, 0x00002ccc, 0x000049ba, 0x0009ae55, 0x000ffa03 }, |
| 2080 | { 64, 0x00002ccc, 0x000049be, 0x0009ae55, 0x000ffa0b }, |
| 2081 | |
| 2082 | /* 802.11 HyperLan 2 */ |
| 2083 | { 100, 0x00002ccc, 0x00004a2a, 0x000bae55, 0x000ffa03 }, |
| 2084 | { 104, 0x00002ccc, 0x00004a2e, 0x000bae55, 0x000ffa0b }, |
| 2085 | { 108, 0x00002ccc, 0x00004a32, 0x000bae55, 0x000ffa13 }, |
| 2086 | { 112, 0x00002ccc, 0x00004a36, 0x000bae55, 0x000ffa1b }, |
| 2087 | { 116, 0x00002ccc, 0x00004a3a, 0x000bbe55, 0x000ffa23 }, |
| 2088 | { 120, 0x00002ccc, 0x00004a82, 0x000bbe55, 0x000ffa03 }, |
| 2089 | { 124, 0x00002ccc, 0x00004a86, 0x000bbe55, 0x000ffa0b }, |
| 2090 | { 128, 0x00002ccc, 0x00004a8a, 0x000bbe55, 0x000ffa13 }, |
| 2091 | { 132, 0x00002ccc, 0x00004a8e, 0x000bbe55, 0x000ffa1b }, |
| 2092 | { 136, 0x00002ccc, 0x00004a92, 0x000bbe55, 0x000ffa23 }, |
| 2093 | |
| 2094 | /* 802.11 UNII */ |
| 2095 | { 140, 0x00002ccc, 0x00004a9a, 0x000bbe55, 0x000ffa03 }, |
| 2096 | { 149, 0x00002ccc, 0x00004aa2, 0x000bbe55, 0x000ffa1f }, |
| 2097 | { 153, 0x00002ccc, 0x00004aa6, 0x000bbe55, 0x000ffa27 }, |
| 2098 | { 157, 0x00002ccc, 0x00004aae, 0x000bbe55, 0x000ffa07 }, |
| 2099 | { 161, 0x00002ccc, 0x00004ab2, 0x000bbe55, 0x000ffa0f }, |
| 2100 | { 165, 0x00002ccc, 0x00004ab6, 0x000bbe55, 0x000ffa17 }, |
| 2101 | |
| 2102 | /* MMAC(Japan)J52 ch 34,38,42,46 */ |
| 2103 | { 34, 0x00002ccc, 0x0000499a, 0x0009be55, 0x000ffa0b }, |
| 2104 | { 38, 0x00002ccc, 0x0000499e, 0x0009be55, 0x000ffa13 }, |
| 2105 | { 42, 0x00002ccc, 0x000049a2, 0x0009be55, 0x000ffa1b }, |
| 2106 | { 46, 0x00002ccc, 0x000049a6, 0x0009be55, 0x000ffa23 }, |
| 2107 | }; |
| 2108 | |
| 2109 | |
Ivo van Doorn | 8c5e7a5 | 2008-08-04 16:38:47 +0200 | [diff] [blame^] | 2110 | static int rt73usb_probe_hw_mode(struct rt2x00_dev *rt2x00dev) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 2111 | { |
| 2112 | struct hw_mode_spec *spec = &rt2x00dev->spec; |
Ivo van Doorn | 8c5e7a5 | 2008-08-04 16:38:47 +0200 | [diff] [blame^] | 2113 | struct channel_info *info; |
| 2114 | char *tx_power; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 2115 | unsigned int i; |
| 2116 | |
| 2117 | /* |
| 2118 | * Initialize all hw fields. |
| 2119 | */ |
| 2120 | rt2x00dev->hw->flags = |
Bruno Randolf | 566bfe5 | 2008-05-08 19:15:40 +0200 | [diff] [blame] | 2121 | IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING | |
| 2122 | IEEE80211_HW_SIGNAL_DBM; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 2123 | rt2x00dev->hw->extra_tx_headroom = TXD_DESC_SIZE; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 2124 | |
Gertjan van Wingerde | 14a3bf8 | 2008-06-16 19:55:43 +0200 | [diff] [blame] | 2125 | SET_IEEE80211_DEV(rt2x00dev->hw, rt2x00dev->dev); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 2126 | SET_IEEE80211_PERM_ADDR(rt2x00dev->hw, |
| 2127 | rt2x00_eeprom_addr(rt2x00dev, |
| 2128 | EEPROM_MAC_ADDR_0)); |
| 2129 | |
| 2130 | /* |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 2131 | * Initialize hw_mode information. |
| 2132 | */ |
Ivo van Doorn | 31562e8 | 2008-02-17 17:35:05 +0100 | [diff] [blame] | 2133 | spec->supported_bands = SUPPORT_BAND_2GHZ; |
| 2134 | spec->supported_rates = SUPPORT_RATE_CCK | SUPPORT_RATE_OFDM; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 2135 | |
| 2136 | if (rt2x00_rf(&rt2x00dev->chip, RF2528)) { |
| 2137 | spec->num_channels = ARRAY_SIZE(rf_vals_bg_2528); |
| 2138 | spec->channels = rf_vals_bg_2528; |
| 2139 | } else if (rt2x00_rf(&rt2x00dev->chip, RF5226)) { |
Ivo van Doorn | 31562e8 | 2008-02-17 17:35:05 +0100 | [diff] [blame] | 2140 | spec->supported_bands |= SUPPORT_BAND_5GHZ; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 2141 | spec->num_channels = ARRAY_SIZE(rf_vals_5226); |
| 2142 | spec->channels = rf_vals_5226; |
| 2143 | } else if (rt2x00_rf(&rt2x00dev->chip, RF2527)) { |
| 2144 | spec->num_channels = 14; |
| 2145 | spec->channels = rf_vals_5225_2527; |
| 2146 | } else if (rt2x00_rf(&rt2x00dev->chip, RF5225)) { |
Ivo van Doorn | 31562e8 | 2008-02-17 17:35:05 +0100 | [diff] [blame] | 2147 | spec->supported_bands |= SUPPORT_BAND_5GHZ; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 2148 | spec->num_channels = ARRAY_SIZE(rf_vals_5225_2527); |
| 2149 | spec->channels = rf_vals_5225_2527; |
| 2150 | } |
| 2151 | |
Ivo van Doorn | 8c5e7a5 | 2008-08-04 16:38:47 +0200 | [diff] [blame^] | 2152 | /* |
| 2153 | * Create channel information array |
| 2154 | */ |
| 2155 | info = kzalloc(spec->num_channels * sizeof(*info), GFP_KERNEL); |
| 2156 | if (!info) |
| 2157 | return -ENOMEM; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 2158 | |
Ivo van Doorn | 8c5e7a5 | 2008-08-04 16:38:47 +0200 | [diff] [blame^] | 2159 | spec->channels_info = info; |
| 2160 | |
| 2161 | tx_power = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_G_START); |
| 2162 | for (i = 0; i < 14; i++) |
| 2163 | info[i].tx_power1 = TXPOWER_FROM_DEV(tx_power[i]); |
| 2164 | |
| 2165 | if (spec->num_channels > 14) { |
| 2166 | tx_power = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_A_START); |
| 2167 | for (i = 14; i < spec->num_channels; i++) |
| 2168 | info[i].tx_power1 = TXPOWER_FROM_DEV(tx_power[i]); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 2169 | } |
Ivo van Doorn | 8c5e7a5 | 2008-08-04 16:38:47 +0200 | [diff] [blame^] | 2170 | |
| 2171 | return 0; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 2172 | } |
| 2173 | |
| 2174 | static int rt73usb_probe_hw(struct rt2x00_dev *rt2x00dev) |
| 2175 | { |
| 2176 | int retval; |
| 2177 | |
| 2178 | /* |
| 2179 | * Allocate eeprom data. |
| 2180 | */ |
| 2181 | retval = rt73usb_validate_eeprom(rt2x00dev); |
| 2182 | if (retval) |
| 2183 | return retval; |
| 2184 | |
| 2185 | retval = rt73usb_init_eeprom(rt2x00dev); |
| 2186 | if (retval) |
| 2187 | return retval; |
| 2188 | |
| 2189 | /* |
| 2190 | * Initialize hw specifications. |
| 2191 | */ |
Ivo van Doorn | 8c5e7a5 | 2008-08-04 16:38:47 +0200 | [diff] [blame^] | 2192 | retval = rt73usb_probe_hw_mode(rt2x00dev); |
| 2193 | if (retval) |
| 2194 | return retval; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 2195 | |
| 2196 | /* |
Ivo van Doorn | 9404ef3 | 2008-02-03 15:48:38 +0100 | [diff] [blame] | 2197 | * This device requires firmware. |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 2198 | */ |
Ivo van Doorn | 066cb63 | 2007-09-25 20:55:39 +0200 | [diff] [blame] | 2199 | __set_bit(DRIVER_REQUIRE_FIRMWARE, &rt2x00dev->flags); |
Ivo van Doorn | 3a643d2 | 2008-03-25 14:13:18 +0100 | [diff] [blame] | 2200 | __set_bit(DRIVER_REQUIRE_SCHEDULED, &rt2x00dev->flags); |
Ivo van Doorn | 906c110 | 2008-08-04 16:38:24 +0200 | [diff] [blame] | 2201 | __set_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 2202 | |
| 2203 | /* |
| 2204 | * Set the rssi offset. |
| 2205 | */ |
| 2206 | rt2x00dev->rssi_offset = DEFAULT_RSSI_OFFSET; |
| 2207 | |
| 2208 | return 0; |
| 2209 | } |
| 2210 | |
| 2211 | /* |
| 2212 | * IEEE80211 stack callback functions. |
| 2213 | */ |
| 2214 | static int rt73usb_set_retry_limit(struct ieee80211_hw *hw, |
| 2215 | u32 short_retry, u32 long_retry) |
| 2216 | { |
| 2217 | struct rt2x00_dev *rt2x00dev = hw->priv; |
| 2218 | u32 reg; |
| 2219 | |
| 2220 | rt73usb_register_read(rt2x00dev, TXRX_CSR4, ®); |
| 2221 | rt2x00_set_field32(®, TXRX_CSR4_LONG_RETRY_LIMIT, long_retry); |
| 2222 | rt2x00_set_field32(®, TXRX_CSR4_SHORT_RETRY_LIMIT, short_retry); |
| 2223 | rt73usb_register_write(rt2x00dev, TXRX_CSR4, reg); |
| 2224 | |
| 2225 | return 0; |
| 2226 | } |
| 2227 | |
| 2228 | #if 0 |
| 2229 | /* |
| 2230 | * Mac80211 demands get_tsf must be atomic. |
| 2231 | * This is not possible for rt73usb since all register access |
| 2232 | * functions require sleeping. Untill mac80211 no longer needs |
| 2233 | * get_tsf to be atomic, this function should be disabled. |
| 2234 | */ |
| 2235 | static u64 rt73usb_get_tsf(struct ieee80211_hw *hw) |
| 2236 | { |
| 2237 | struct rt2x00_dev *rt2x00dev = hw->priv; |
| 2238 | u64 tsf; |
| 2239 | u32 reg; |
| 2240 | |
| 2241 | rt73usb_register_read(rt2x00dev, TXRX_CSR13, ®); |
| 2242 | tsf = (u64) rt2x00_get_field32(reg, TXRX_CSR13_HIGH_TSFTIMER) << 32; |
| 2243 | rt73usb_register_read(rt2x00dev, TXRX_CSR12, ®); |
| 2244 | tsf |= rt2x00_get_field32(reg, TXRX_CSR12_LOW_TSFTIMER); |
| 2245 | |
| 2246 | return tsf; |
| 2247 | } |
Ivo van Doorn | 3789447 | 2007-10-06 14:18:00 +0200 | [diff] [blame] | 2248 | #else |
| 2249 | #define rt73usb_get_tsf NULL |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 2250 | #endif |
| 2251 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 2252 | static const struct ieee80211_ops rt73usb_mac80211_ops = { |
| 2253 | .tx = rt2x00mac_tx, |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 2254 | .start = rt2x00mac_start, |
| 2255 | .stop = rt2x00mac_stop, |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 2256 | .add_interface = rt2x00mac_add_interface, |
| 2257 | .remove_interface = rt2x00mac_remove_interface, |
| 2258 | .config = rt2x00mac_config, |
| 2259 | .config_interface = rt2x00mac_config_interface, |
Ivo van Doorn | 3a643d2 | 2008-03-25 14:13:18 +0100 | [diff] [blame] | 2260 | .configure_filter = rt2x00mac_configure_filter, |
Ivo van Doorn | 906c110 | 2008-08-04 16:38:24 +0200 | [diff] [blame] | 2261 | .set_key = rt2x00mac_set_key, |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 2262 | .get_stats = rt2x00mac_get_stats, |
| 2263 | .set_retry_limit = rt73usb_set_retry_limit, |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 2264 | .bss_info_changed = rt2x00mac_bss_info_changed, |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 2265 | .conf_tx = rt2x00mac_conf_tx, |
| 2266 | .get_tx_stats = rt2x00mac_get_tx_stats, |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 2267 | .get_tsf = rt73usb_get_tsf, |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 2268 | }; |
| 2269 | |
| 2270 | static const struct rt2x00lib_ops rt73usb_rt2x00_ops = { |
| 2271 | .probe_hw = rt73usb_probe_hw, |
| 2272 | .get_firmware_name = rt73usb_get_firmware_name, |
Ivo van Doorn | a7f3a06 | 2008-03-09 22:44:54 +0100 | [diff] [blame] | 2273 | .get_firmware_crc = rt73usb_get_firmware_crc, |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 2274 | .load_firmware = rt73usb_load_firmware, |
| 2275 | .initialize = rt2x00usb_initialize, |
| 2276 | .uninitialize = rt2x00usb_uninitialize, |
Ivo van Doorn | 837e7f2 | 2008-01-06 23:41:45 +0100 | [diff] [blame] | 2277 | .init_rxentry = rt2x00usb_init_rxentry, |
| 2278 | .init_txentry = rt2x00usb_init_txentry, |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 2279 | .set_device_state = rt73usb_set_device_state, |
| 2280 | .link_stats = rt73usb_link_stats, |
| 2281 | .reset_tuner = rt73usb_reset_tuner, |
| 2282 | .link_tuner = rt73usb_link_tuner, |
| 2283 | .write_tx_desc = rt73usb_write_tx_desc, |
| 2284 | .write_tx_data = rt2x00usb_write_tx_data, |
Ivo van Doorn | bd88a78 | 2008-07-09 15:12:44 +0200 | [diff] [blame] | 2285 | .write_beacon = rt73usb_write_beacon, |
Ivo van Doorn | dd9fa2d | 2007-10-06 14:15:46 +0200 | [diff] [blame] | 2286 | .get_tx_data_len = rt73usb_get_tx_data_len, |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 2287 | .kick_tx_queue = rt73usb_kick_tx_queue, |
| 2288 | .fill_rxdone = rt73usb_fill_rxdone, |
Ivo van Doorn | 906c110 | 2008-08-04 16:38:24 +0200 | [diff] [blame] | 2289 | .config_shared_key = rt73usb_config_shared_key, |
| 2290 | .config_pairwise_key = rt73usb_config_pairwise_key, |
Ivo van Doorn | 3a643d2 | 2008-03-25 14:13:18 +0100 | [diff] [blame] | 2291 | .config_filter = rt73usb_config_filter, |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame] | 2292 | .config_intf = rt73usb_config_intf, |
Ivo van Doorn | 7281037 | 2008-03-09 22:46:18 +0100 | [diff] [blame] | 2293 | .config_erp = rt73usb_config_erp, |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 2294 | .config = rt73usb_config, |
| 2295 | }; |
| 2296 | |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 2297 | static const struct data_queue_desc rt73usb_queue_rx = { |
| 2298 | .entry_num = RX_ENTRIES, |
| 2299 | .data_size = DATA_FRAME_SIZE, |
| 2300 | .desc_size = RXD_DESC_SIZE, |
Ivo van Doorn | b8be63f | 2008-05-10 13:46:03 +0200 | [diff] [blame] | 2301 | .priv_size = sizeof(struct queue_entry_priv_usb), |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 2302 | }; |
| 2303 | |
| 2304 | static const struct data_queue_desc rt73usb_queue_tx = { |
| 2305 | .entry_num = TX_ENTRIES, |
| 2306 | .data_size = DATA_FRAME_SIZE, |
| 2307 | .desc_size = TXD_DESC_SIZE, |
Ivo van Doorn | b8be63f | 2008-05-10 13:46:03 +0200 | [diff] [blame] | 2308 | .priv_size = sizeof(struct queue_entry_priv_usb), |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 2309 | }; |
| 2310 | |
| 2311 | static const struct data_queue_desc rt73usb_queue_bcn = { |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame] | 2312 | .entry_num = 4 * BEACON_ENTRIES, |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 2313 | .data_size = MGMT_FRAME_SIZE, |
| 2314 | .desc_size = TXINFO_SIZE, |
Ivo van Doorn | b8be63f | 2008-05-10 13:46:03 +0200 | [diff] [blame] | 2315 | .priv_size = sizeof(struct queue_entry_priv_usb), |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 2316 | }; |
| 2317 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 2318 | static const struct rt2x00_ops rt73usb_ops = { |
Ivo van Doorn | 2360157 | 2007-11-27 21:47:34 +0100 | [diff] [blame] | 2319 | .name = KBUILD_MODNAME, |
Ivo van Doorn | 6bb40dd | 2008-02-03 15:49:59 +0100 | [diff] [blame] | 2320 | .max_sta_intf = 1, |
| 2321 | .max_ap_intf = 4, |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 2322 | .eeprom_size = EEPROM_SIZE, |
| 2323 | .rf_size = RF_SIZE, |
Gertjan van Wingerde | 61448f8 | 2008-05-10 13:43:33 +0200 | [diff] [blame] | 2324 | .tx_queues = NUM_TX_QUEUES, |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 2325 | .rx = &rt73usb_queue_rx, |
| 2326 | .tx = &rt73usb_queue_tx, |
| 2327 | .bcn = &rt73usb_queue_bcn, |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 2328 | .lib = &rt73usb_rt2x00_ops, |
| 2329 | .hw = &rt73usb_mac80211_ops, |
| 2330 | #ifdef CONFIG_RT2X00_LIB_DEBUGFS |
| 2331 | .debugfs = &rt73usb_rt2x00debug, |
| 2332 | #endif /* CONFIG_RT2X00_LIB_DEBUGFS */ |
| 2333 | }; |
| 2334 | |
| 2335 | /* |
| 2336 | * rt73usb module information. |
| 2337 | */ |
| 2338 | static struct usb_device_id rt73usb_device_table[] = { |
| 2339 | /* AboCom */ |
| 2340 | { USB_DEVICE(0x07b8, 0xb21d), USB_DEVICE_DATA(&rt73usb_ops) }, |
| 2341 | /* Askey */ |
| 2342 | { USB_DEVICE(0x1690, 0x0722), USB_DEVICE_DATA(&rt73usb_ops) }, |
| 2343 | /* ASUS */ |
| 2344 | { USB_DEVICE(0x0b05, 0x1723), USB_DEVICE_DATA(&rt73usb_ops) }, |
| 2345 | { USB_DEVICE(0x0b05, 0x1724), USB_DEVICE_DATA(&rt73usb_ops) }, |
| 2346 | /* Belkin */ |
| 2347 | { USB_DEVICE(0x050d, 0x7050), USB_DEVICE_DATA(&rt73usb_ops) }, |
| 2348 | { USB_DEVICE(0x050d, 0x705a), USB_DEVICE_DATA(&rt73usb_ops) }, |
| 2349 | { USB_DEVICE(0x050d, 0x905b), USB_DEVICE_DATA(&rt73usb_ops) }, |
Ivo van Doorn | 1f06862 | 2007-10-13 16:27:13 +0200 | [diff] [blame] | 2350 | { USB_DEVICE(0x050d, 0x905c), USB_DEVICE_DATA(&rt73usb_ops) }, |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 2351 | /* Billionton */ |
| 2352 | { USB_DEVICE(0x1631, 0xc019), USB_DEVICE_DATA(&rt73usb_ops) }, |
| 2353 | /* Buffalo */ |
| 2354 | { USB_DEVICE(0x0411, 0x00f4), USB_DEVICE_DATA(&rt73usb_ops) }, |
| 2355 | /* CNet */ |
| 2356 | { USB_DEVICE(0x1371, 0x9022), USB_DEVICE_DATA(&rt73usb_ops) }, |
| 2357 | { USB_DEVICE(0x1371, 0x9032), USB_DEVICE_DATA(&rt73usb_ops) }, |
| 2358 | /* Conceptronic */ |
| 2359 | { USB_DEVICE(0x14b2, 0x3c22), USB_DEVICE_DATA(&rt73usb_ops) }, |
Masakazu Mokuno | 0a74892 | 2008-03-15 21:38:29 +0100 | [diff] [blame] | 2360 | /* Corega */ |
| 2361 | { USB_DEVICE(0x07aa, 0x002e), USB_DEVICE_DATA(&rt73usb_ops) }, |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 2362 | /* D-Link */ |
| 2363 | { USB_DEVICE(0x07d1, 0x3c03), USB_DEVICE_DATA(&rt73usb_ops) }, |
| 2364 | { USB_DEVICE(0x07d1, 0x3c04), USB_DEVICE_DATA(&rt73usb_ops) }, |
Ivo van Doorn | cb62ecc | 2008-06-12 20:47:17 +0200 | [diff] [blame] | 2365 | { USB_DEVICE(0x07d1, 0x3c06), USB_DEVICE_DATA(&rt73usb_ops) }, |
Ivo van Doorn | 445815d | 2008-03-09 22:42:32 +0100 | [diff] [blame] | 2366 | { USB_DEVICE(0x07d1, 0x3c07), USB_DEVICE_DATA(&rt73usb_ops) }, |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 2367 | /* Gemtek */ |
| 2368 | { USB_DEVICE(0x15a9, 0x0004), USB_DEVICE_DATA(&rt73usb_ops) }, |
| 2369 | /* Gigabyte */ |
| 2370 | { USB_DEVICE(0x1044, 0x8008), USB_DEVICE_DATA(&rt73usb_ops) }, |
| 2371 | { USB_DEVICE(0x1044, 0x800a), USB_DEVICE_DATA(&rt73usb_ops) }, |
| 2372 | /* Huawei-3Com */ |
| 2373 | { USB_DEVICE(0x1472, 0x0009), USB_DEVICE_DATA(&rt73usb_ops) }, |
| 2374 | /* Hercules */ |
| 2375 | { USB_DEVICE(0x06f8, 0xe010), USB_DEVICE_DATA(&rt73usb_ops) }, |
| 2376 | { USB_DEVICE(0x06f8, 0xe020), USB_DEVICE_DATA(&rt73usb_ops) }, |
| 2377 | /* Linksys */ |
| 2378 | { USB_DEVICE(0x13b1, 0x0020), USB_DEVICE_DATA(&rt73usb_ops) }, |
| 2379 | { USB_DEVICE(0x13b1, 0x0023), USB_DEVICE_DATA(&rt73usb_ops) }, |
| 2380 | /* MSI */ |
| 2381 | { USB_DEVICE(0x0db0, 0x6877), USB_DEVICE_DATA(&rt73usb_ops) }, |
| 2382 | { USB_DEVICE(0x0db0, 0x6874), USB_DEVICE_DATA(&rt73usb_ops) }, |
| 2383 | { USB_DEVICE(0x0db0, 0xa861), USB_DEVICE_DATA(&rt73usb_ops) }, |
| 2384 | { USB_DEVICE(0x0db0, 0xa874), USB_DEVICE_DATA(&rt73usb_ops) }, |
| 2385 | /* Ralink */ |
| 2386 | { USB_DEVICE(0x148f, 0x2573), USB_DEVICE_DATA(&rt73usb_ops) }, |
| 2387 | { USB_DEVICE(0x148f, 0x2671), USB_DEVICE_DATA(&rt73usb_ops) }, |
| 2388 | /* Qcom */ |
| 2389 | { USB_DEVICE(0x18e8, 0x6196), USB_DEVICE_DATA(&rt73usb_ops) }, |
| 2390 | { USB_DEVICE(0x18e8, 0x6229), USB_DEVICE_DATA(&rt73usb_ops) }, |
| 2391 | { USB_DEVICE(0x18e8, 0x6238), USB_DEVICE_DATA(&rt73usb_ops) }, |
| 2392 | /* Senao */ |
| 2393 | { USB_DEVICE(0x1740, 0x7100), USB_DEVICE_DATA(&rt73usb_ops) }, |
| 2394 | /* Sitecom */ |
| 2395 | { USB_DEVICE(0x0df6, 0x9712), USB_DEVICE_DATA(&rt73usb_ops) }, |
| 2396 | { USB_DEVICE(0x0df6, 0x90ac), USB_DEVICE_DATA(&rt73usb_ops) }, |
| 2397 | /* Surecom */ |
| 2398 | { USB_DEVICE(0x0769, 0x31f3), USB_DEVICE_DATA(&rt73usb_ops) }, |
| 2399 | /* Planex */ |
| 2400 | { USB_DEVICE(0x2019, 0xab01), USB_DEVICE_DATA(&rt73usb_ops) }, |
| 2401 | { USB_DEVICE(0x2019, 0xab50), USB_DEVICE_DATA(&rt73usb_ops) }, |
| 2402 | { 0, } |
| 2403 | }; |
| 2404 | |
| 2405 | MODULE_AUTHOR(DRV_PROJECT); |
| 2406 | MODULE_VERSION(DRV_VERSION); |
| 2407 | MODULE_DESCRIPTION("Ralink RT73 USB Wireless LAN driver."); |
| 2408 | MODULE_SUPPORTED_DEVICE("Ralink RT2571W & RT2671 USB chipset based cards"); |
| 2409 | MODULE_DEVICE_TABLE(usb, rt73usb_device_table); |
| 2410 | MODULE_FIRMWARE(FIRMWARE_RT2571); |
| 2411 | MODULE_LICENSE("GPL"); |
| 2412 | |
| 2413 | static struct usb_driver rt73usb_driver = { |
Ivo van Doorn | 2360157 | 2007-11-27 21:47:34 +0100 | [diff] [blame] | 2414 | .name = KBUILD_MODNAME, |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 2415 | .id_table = rt73usb_device_table, |
| 2416 | .probe = rt2x00usb_probe, |
| 2417 | .disconnect = rt2x00usb_disconnect, |
| 2418 | .suspend = rt2x00usb_suspend, |
| 2419 | .resume = rt2x00usb_resume, |
| 2420 | }; |
| 2421 | |
| 2422 | static int __init rt73usb_init(void) |
| 2423 | { |
| 2424 | return usb_register(&rt73usb_driver); |
| 2425 | } |
| 2426 | |
| 2427 | static void __exit rt73usb_exit(void) |
| 2428 | { |
| 2429 | usb_deregister(&rt73usb_driver); |
| 2430 | } |
| 2431 | |
| 2432 | module_init(rt73usb_init); |
| 2433 | module_exit(rt73usb_exit); |