Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2004-2008 Reyk Floeter <reyk@openbsd.org> |
| 3 | * Copyright (c) 2006-2008 Nick Kossifidis <mickflemm@gmail.com> |
| 4 | * Copyright (c) 2007-2008 Matthew W. S. Bell <mentor@madwifi.org> |
| 5 | * Copyright (c) 2007-2008 Luis Rodriguez <mcgrof@winlab.rutgers.edu> |
| 6 | * Copyright (c) 2007-2008 Pavel Roskin <proski@gnu.org> |
| 7 | * Copyright (c) 2007-2008 Jiri Slaby <jirislaby@gmail.com> |
| 8 | * |
| 9 | * Permission to use, copy, modify, and distribute this software for any |
| 10 | * purpose with or without fee is hereby granted, provided that the above |
| 11 | * copyright notice and this permission notice appear in all copies. |
| 12 | * |
| 13 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 14 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 15 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 16 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 17 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 18 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 19 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | /*********************************\ |
| 24 | * Protocol Control Unit Functions * |
| 25 | \*********************************/ |
| 26 | |
Luis R. Rodriguez | bcd8f54 | 2009-09-09 22:43:17 -0700 | [diff] [blame] | 27 | #include <asm/unaligned.h> |
| 28 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 29 | #include "ath5k.h" |
| 30 | #include "reg.h" |
| 31 | #include "debug.h" |
| 32 | #include "base.h" |
| 33 | |
| 34 | /*******************\ |
| 35 | * Generic functions * |
| 36 | \*******************/ |
| 37 | |
| 38 | /** |
| 39 | * ath5k_hw_set_opmode - Set PCU operating mode |
| 40 | * |
| 41 | * @ah: The &struct ath5k_hw |
| 42 | * |
| 43 | * Initialize PCU for the various operating modes (AP/STA etc) |
| 44 | * |
| 45 | * NOTE: ah->ah_op_mode must be set before calling this. |
| 46 | */ |
| 47 | int ath5k_hw_set_opmode(struct ath5k_hw *ah) |
| 48 | { |
Luis R. Rodriguez | 954fece | 2009-09-10 10:51:33 -0700 | [diff] [blame] | 49 | struct ath_common *common = ath5k_hw_common(ah); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 50 | u32 pcu_reg, beacon_reg, low_id, high_id; |
| 51 | |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 52 | |
| 53 | /* Preserve rest settings */ |
| 54 | pcu_reg = ath5k_hw_reg_read(ah, AR5K_STA_ID1) & 0xffff0000; |
| 55 | pcu_reg &= ~(AR5K_STA_ID1_ADHOC | AR5K_STA_ID1_AP |
| 56 | | AR5K_STA_ID1_KEYSRCH_MODE |
| 57 | | (ah->ah_version == AR5K_AR5210 ? |
| 58 | (AR5K_STA_ID1_PWR_SV | AR5K_STA_ID1_NO_PSPOLL) : 0)); |
| 59 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 60 | beacon_reg = 0; |
| 61 | |
| 62 | ATH5K_TRACE(ah->ah_sc); |
| 63 | |
| 64 | switch (ah->ah_op_mode) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 65 | case NL80211_IFTYPE_ADHOC: |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 66 | pcu_reg |= AR5K_STA_ID1_ADHOC | AR5K_STA_ID1_KEYSRCH_MODE; |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 67 | beacon_reg |= AR5K_BCR_ADHOC; |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 68 | if (ah->ah_version == AR5K_AR5210) |
| 69 | pcu_reg |= AR5K_STA_ID1_NO_PSPOLL; |
| 70 | else |
Steve Brown | 4fb7404 | 2008-12-23 07:57:05 -0500 | [diff] [blame] | 71 | AR5K_REG_ENABLE_BITS(ah, AR5K_CFG, AR5K_CFG_IBSS); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 72 | break; |
| 73 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 74 | case NL80211_IFTYPE_AP: |
| 75 | case NL80211_IFTYPE_MESH_POINT: |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 76 | pcu_reg |= AR5K_STA_ID1_AP | AR5K_STA_ID1_KEYSRCH_MODE; |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 77 | beacon_reg |= AR5K_BCR_AP; |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 78 | if (ah->ah_version == AR5K_AR5210) |
| 79 | pcu_reg |= AR5K_STA_ID1_NO_PSPOLL; |
| 80 | else |
Steve Brown | 4fb7404 | 2008-12-23 07:57:05 -0500 | [diff] [blame] | 81 | AR5K_REG_DISABLE_BITS(ah, AR5K_CFG, AR5K_CFG_IBSS); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 82 | break; |
| 83 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 84 | case NL80211_IFTYPE_STATION: |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 85 | pcu_reg |= AR5K_STA_ID1_KEYSRCH_MODE |
| 86 | | (ah->ah_version == AR5K_AR5210 ? |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 87 | AR5K_STA_ID1_PWR_SV : 0); |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 88 | case NL80211_IFTYPE_MONITOR: |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 89 | pcu_reg |= AR5K_STA_ID1_KEYSRCH_MODE |
| 90 | | (ah->ah_version == AR5K_AR5210 ? |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 91 | AR5K_STA_ID1_NO_PSPOLL : 0); |
| 92 | break; |
| 93 | |
| 94 | default: |
| 95 | return -EINVAL; |
| 96 | } |
| 97 | |
| 98 | /* |
| 99 | * Set PCU registers |
| 100 | */ |
Luis R. Rodriguez | 954fece | 2009-09-10 10:51:33 -0700 | [diff] [blame] | 101 | low_id = get_unaligned_le32(common->macaddr); |
| 102 | high_id = get_unaligned_le16(common->macaddr + 4); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 103 | ath5k_hw_reg_write(ah, low_id, AR5K_STA_ID0); |
| 104 | ath5k_hw_reg_write(ah, pcu_reg | high_id, AR5K_STA_ID1); |
| 105 | |
| 106 | /* |
| 107 | * Set Beacon Control Register on 5210 |
| 108 | */ |
| 109 | if (ah->ah_version == AR5K_AR5210) |
| 110 | ath5k_hw_reg_write(ah, beacon_reg, AR5K_BCR); |
| 111 | |
| 112 | return 0; |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * ath5k_hw_update - Update mib counters (mac layer statistics) |
| 117 | * |
| 118 | * @ah: The &struct ath5k_hw |
| 119 | * @stats: The &struct ieee80211_low_level_stats we use to track |
| 120 | * statistics on the driver |
| 121 | * |
| 122 | * Reads MIB counters from PCU and updates sw statistics. Must be |
| 123 | * called after a MIB interrupt. |
| 124 | */ |
| 125 | void ath5k_hw_update_mib_counters(struct ath5k_hw *ah, |
| 126 | struct ieee80211_low_level_stats *stats) |
| 127 | { |
| 128 | ATH5K_TRACE(ah->ah_sc); |
| 129 | |
| 130 | /* Read-And-Clear */ |
| 131 | stats->dot11ACKFailureCount += ath5k_hw_reg_read(ah, AR5K_ACK_FAIL); |
| 132 | stats->dot11RTSFailureCount += ath5k_hw_reg_read(ah, AR5K_RTS_FAIL); |
| 133 | stats->dot11RTSSuccessCount += ath5k_hw_reg_read(ah, AR5K_RTS_OK); |
| 134 | stats->dot11FCSErrorCount += ath5k_hw_reg_read(ah, AR5K_FCS_FAIL); |
| 135 | |
| 136 | /* XXX: Should we use this to track beacon count ? |
| 137 | * -we read it anyway to clear the register */ |
| 138 | ath5k_hw_reg_read(ah, AR5K_BEACON_CNT); |
| 139 | |
| 140 | /* Reset profile count registers on 5212*/ |
| 141 | if (ah->ah_version == AR5K_AR5212) { |
| 142 | ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_TX); |
| 143 | ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_RX); |
| 144 | ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_RXCLR); |
| 145 | ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_CYCLE); |
| 146 | } |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 147 | |
| 148 | /* TODO: Handle ANI stats */ |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | /** |
| 152 | * ath5k_hw_set_ack_bitrate - set bitrate for ACKs |
| 153 | * |
| 154 | * @ah: The &struct ath5k_hw |
| 155 | * @high: Flag to determine if we want to use high transmition rate |
| 156 | * for ACKs or not |
| 157 | * |
| 158 | * If high flag is set, we tell hw to use a set of control rates based on |
| 159 | * the current transmition rate (check out control_rates array inside reset.c). |
| 160 | * If not hw just uses the lowest rate available for the current modulation |
| 161 | * scheme being used (1Mbit for CCK and 6Mbits for OFDM). |
| 162 | */ |
| 163 | void ath5k_hw_set_ack_bitrate_high(struct ath5k_hw *ah, bool high) |
| 164 | { |
| 165 | if (ah->ah_version != AR5K_AR5212) |
| 166 | return; |
| 167 | else { |
| 168 | u32 val = AR5K_STA_ID1_BASE_RATE_11B | AR5K_STA_ID1_ACKCTS_6MB; |
| 169 | if (high) |
| 170 | AR5K_REG_ENABLE_BITS(ah, AR5K_STA_ID1, val); |
| 171 | else |
| 172 | AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1, val); |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | |
| 177 | /******************\ |
| 178 | * ACK/CTS Timeouts * |
| 179 | \******************/ |
| 180 | |
| 181 | /** |
| 182 | * ath5k_hw_het_ack_timeout - Get ACK timeout from PCU in usec |
| 183 | * |
| 184 | * @ah: The &struct ath5k_hw |
| 185 | */ |
| 186 | unsigned int ath5k_hw_get_ack_timeout(struct ath5k_hw *ah) |
| 187 | { |
| 188 | ATH5K_TRACE(ah->ah_sc); |
| 189 | |
Lukáš Turek | 3578e6e | 2009-12-21 22:50:50 +0100 | [diff] [blame^] | 190 | return ath5k_hw_clocktoh(ah, AR5K_REG_MS(ath5k_hw_reg_read(ah, |
| 191 | AR5K_TIME_OUT), AR5K_TIME_OUT_ACK)); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | /** |
| 195 | * ath5k_hw_set_ack_timeout - Set ACK timeout on PCU |
| 196 | * |
| 197 | * @ah: The &struct ath5k_hw |
| 198 | * @timeout: Timeout in usec |
| 199 | */ |
| 200 | int ath5k_hw_set_ack_timeout(struct ath5k_hw *ah, unsigned int timeout) |
| 201 | { |
| 202 | ATH5K_TRACE(ah->ah_sc); |
Lukáš Turek | 3578e6e | 2009-12-21 22:50:50 +0100 | [diff] [blame^] | 203 | if (ath5k_hw_clocktoh(ah, AR5K_REG_MS(0xffffffff, AR5K_TIME_OUT_ACK)) |
| 204 | <= timeout) |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 205 | return -EINVAL; |
| 206 | |
| 207 | AR5K_REG_WRITE_BITS(ah, AR5K_TIME_OUT, AR5K_TIME_OUT_ACK, |
Lukáš Turek | 3578e6e | 2009-12-21 22:50:50 +0100 | [diff] [blame^] | 208 | ath5k_hw_htoclock(ah, timeout)); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 209 | |
| 210 | return 0; |
| 211 | } |
| 212 | |
| 213 | /** |
| 214 | * ath5k_hw_get_cts_timeout - Get CTS timeout from PCU in usec |
| 215 | * |
| 216 | * @ah: The &struct ath5k_hw |
| 217 | */ |
| 218 | unsigned int ath5k_hw_get_cts_timeout(struct ath5k_hw *ah) |
| 219 | { |
| 220 | ATH5K_TRACE(ah->ah_sc); |
Lukáš Turek | 3578e6e | 2009-12-21 22:50:50 +0100 | [diff] [blame^] | 221 | return ath5k_hw_clocktoh(ah, AR5K_REG_MS(ath5k_hw_reg_read(ah, |
| 222 | AR5K_TIME_OUT), AR5K_TIME_OUT_CTS)); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | /** |
| 226 | * ath5k_hw_set_cts_timeout - Set CTS timeout on PCU |
| 227 | * |
| 228 | * @ah: The &struct ath5k_hw |
| 229 | * @timeout: Timeout in usec |
| 230 | */ |
| 231 | int ath5k_hw_set_cts_timeout(struct ath5k_hw *ah, unsigned int timeout) |
| 232 | { |
| 233 | ATH5K_TRACE(ah->ah_sc); |
Lukáš Turek | 3578e6e | 2009-12-21 22:50:50 +0100 | [diff] [blame^] | 234 | if (ath5k_hw_clocktoh(ah, AR5K_REG_MS(0xffffffff, AR5K_TIME_OUT_CTS)) |
| 235 | <= timeout) |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 236 | return -EINVAL; |
| 237 | |
| 238 | AR5K_REG_WRITE_BITS(ah, AR5K_TIME_OUT, AR5K_TIME_OUT_CTS, |
Lukáš Turek | 3578e6e | 2009-12-21 22:50:50 +0100 | [diff] [blame^] | 239 | ath5k_hw_htoclock(ah, timeout)); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 240 | |
| 241 | return 0; |
| 242 | } |
| 243 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 244 | /** |
Lukáš Turek | 3578e6e | 2009-12-21 22:50:50 +0100 | [diff] [blame^] | 245 | * ath5k_hw_htoclock - Translate usec to hw clock units |
| 246 | * |
| 247 | * @ah: The &struct ath5k_hw |
| 248 | * @usec: value in microseconds |
| 249 | */ |
| 250 | unsigned int ath5k_hw_htoclock(struct ath5k_hw *ah, unsigned int usec) |
| 251 | { |
| 252 | return usec * ath5k_hw_get_clockrate(ah); |
| 253 | } |
| 254 | |
| 255 | /** |
| 256 | * ath5k_hw_clocktoh - Translate hw clock units to usec |
| 257 | * @clock: value in hw clock units |
| 258 | */ |
| 259 | unsigned int ath5k_hw_clocktoh(struct ath5k_hw *ah, unsigned int clock) |
| 260 | { |
| 261 | return clock / ath5k_hw_get_clockrate(ah); |
| 262 | } |
| 263 | |
| 264 | /** |
| 265 | * ath5k_hw_get_clockrate - Get the clock rate for current mode |
| 266 | * |
| 267 | * @ah: The &struct ath5k_hw |
| 268 | */ |
| 269 | unsigned int ath5k_hw_get_clockrate(struct ath5k_hw *ah) |
| 270 | { |
| 271 | struct ieee80211_channel *channel = ah->ah_current_channel; |
| 272 | int clock; |
| 273 | |
| 274 | if (channel->hw_value & CHANNEL_5GHZ) |
| 275 | clock = 40; /* 802.11a */ |
| 276 | else if (channel->hw_value & CHANNEL_CCK) |
| 277 | clock = 22; /* 802.11b */ |
| 278 | else |
| 279 | clock = 44; /* 802.11g */ |
| 280 | |
| 281 | /* Clock rate in turbo modes is twice the normal rate */ |
| 282 | if (channel->hw_value & CHANNEL_TURBO) |
| 283 | clock *= 2; |
| 284 | |
| 285 | return clock; |
| 286 | } |
| 287 | |
| 288 | /** |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 289 | * ath5k_hw_set_lladdr - Set station id |
| 290 | * |
| 291 | * @ah: The &struct ath5k_hw |
| 292 | * @mac: The card's mac address |
| 293 | * |
| 294 | * Set station id on hw using the provided mac address |
| 295 | */ |
| 296 | int ath5k_hw_set_lladdr(struct ath5k_hw *ah, const u8 *mac) |
| 297 | { |
Luis R. Rodriguez | 954fece | 2009-09-10 10:51:33 -0700 | [diff] [blame] | 298 | struct ath_common *common = ath5k_hw_common(ah); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 299 | u32 low_id, high_id; |
Bob Copeland | f6bac3e | 2008-11-26 16:17:11 -0500 | [diff] [blame] | 300 | u32 pcu_reg; |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 301 | |
| 302 | ATH5K_TRACE(ah->ah_sc); |
| 303 | /* Set new station ID */ |
Luis R. Rodriguez | 954fece | 2009-09-10 10:51:33 -0700 | [diff] [blame] | 304 | memcpy(common->macaddr, mac, ETH_ALEN); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 305 | |
Bob Copeland | f6bac3e | 2008-11-26 16:17:11 -0500 | [diff] [blame] | 306 | pcu_reg = ath5k_hw_reg_read(ah, AR5K_STA_ID1) & 0xffff0000; |
| 307 | |
Luis R. Rodriguez | bcd8f54 | 2009-09-09 22:43:17 -0700 | [diff] [blame] | 308 | low_id = get_unaligned_le32(mac); |
| 309 | high_id = get_unaligned_le16(mac + 4); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 310 | |
| 311 | ath5k_hw_reg_write(ah, low_id, AR5K_STA_ID0); |
Bob Copeland | f6bac3e | 2008-11-26 16:17:11 -0500 | [diff] [blame] | 312 | ath5k_hw_reg_write(ah, pcu_reg | high_id, AR5K_STA_ID1); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 313 | |
| 314 | return 0; |
| 315 | } |
| 316 | |
| 317 | /** |
| 318 | * ath5k_hw_set_associd - Set BSSID for association |
| 319 | * |
| 320 | * @ah: The &struct ath5k_hw |
| 321 | * @bssid: BSSID |
| 322 | * @assoc_id: Assoc id |
| 323 | * |
| 324 | * Sets the BSSID which trigers the "SME Join" operation |
| 325 | */ |
Luis R. Rodriguez | be5d6b7 | 2009-10-06 20:44:31 -0400 | [diff] [blame] | 326 | void ath5k_hw_set_associd(struct ath5k_hw *ah) |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 327 | { |
Luis R. Rodriguez | 954fece | 2009-09-10 10:51:33 -0700 | [diff] [blame] | 328 | struct ath_common *common = ath5k_hw_common(ah); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 329 | u16 tim_offset = 0; |
| 330 | |
| 331 | /* |
| 332 | * Set simple BSSID mask on 5212 |
| 333 | */ |
Luis R. Rodriguez | a72d57a | 2009-10-06 20:44:29 -0400 | [diff] [blame] | 334 | if (ah->ah_version == AR5K_AR5212) |
| 335 | ath_hw_setbssidmask(common); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 336 | |
| 337 | /* |
| 338 | * Set BSSID which triggers the "SME Join" operation |
| 339 | */ |
Luis R. Rodriguez | abba068 | 2009-10-06 20:44:32 -0400 | [diff] [blame] | 340 | ath5k_hw_reg_write(ah, |
| 341 | get_unaligned_le32(common->curbssid), |
Luis R. Rodriguez | a3f86bf | 2009-10-06 20:44:33 -0400 | [diff] [blame] | 342 | AR5K_BSS_ID0); |
Luis R. Rodriguez | abba068 | 2009-10-06 20:44:32 -0400 | [diff] [blame] | 343 | ath5k_hw_reg_write(ah, |
| 344 | get_unaligned_le16(common->curbssid + 4) | |
| 345 | ((common->curaid & 0x3fff) << AR5K_BSS_ID1_AID_S), |
Luis R. Rodriguez | a3f86bf | 2009-10-06 20:44:33 -0400 | [diff] [blame] | 346 | AR5K_BSS_ID1); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 347 | |
Luis R. Rodriguez | be5d6b7 | 2009-10-06 20:44:31 -0400 | [diff] [blame] | 348 | if (common->curaid == 0) { |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 349 | ath5k_hw_disable_pspoll(ah); |
| 350 | return; |
| 351 | } |
| 352 | |
| 353 | AR5K_REG_WRITE_BITS(ah, AR5K_BEACON, AR5K_BEACON_TIM, |
Luis R. Rodriguez | abba068 | 2009-10-06 20:44:32 -0400 | [diff] [blame] | 354 | tim_offset ? tim_offset + 4 : 0); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 355 | |
| 356 | ath5k_hw_enable_pspoll(ah, NULL, 0); |
| 357 | } |
| 358 | |
Luis R. Rodriguez | 13b8155 | 2009-09-10 17:52:45 -0700 | [diff] [blame] | 359 | void ath5k_hw_set_bssid_mask(struct ath5k_hw *ah, const u8 *mask) |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 360 | { |
Luis R. Rodriguez | 954fece | 2009-09-10 10:51:33 -0700 | [diff] [blame] | 361 | struct ath_common *common = ath5k_hw_common(ah); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 362 | ATH5K_TRACE(ah->ah_sc); |
| 363 | |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 364 | /* Cache bssid mask so that we can restore it |
| 365 | * on reset */ |
Luis R. Rodriguez | 954fece | 2009-09-10 10:51:33 -0700 | [diff] [blame] | 366 | memcpy(common->bssidmask, mask, ETH_ALEN); |
Luis R. Rodriguez | 13b8155 | 2009-09-10 17:52:45 -0700 | [diff] [blame] | 367 | if (ah->ah_version == AR5K_AR5212) |
| 368 | ath_hw_setbssidmask(common); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 369 | } |
| 370 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 371 | /************\ |
| 372 | * RX Control * |
| 373 | \************/ |
| 374 | |
| 375 | /** |
| 376 | * ath5k_hw_start_rx_pcu - Start RX engine |
| 377 | * |
| 378 | * @ah: The &struct ath5k_hw |
| 379 | * |
| 380 | * Starts RX engine on PCU so that hw can process RXed frames |
| 381 | * (ACK etc). |
| 382 | * |
| 383 | * NOTE: RX DMA should be already enabled using ath5k_hw_start_rx_dma |
| 384 | * TODO: Init ANI here |
| 385 | */ |
| 386 | void ath5k_hw_start_rx_pcu(struct ath5k_hw *ah) |
| 387 | { |
| 388 | ATH5K_TRACE(ah->ah_sc); |
| 389 | AR5K_REG_DISABLE_BITS(ah, AR5K_DIAG_SW, AR5K_DIAG_SW_DIS_RX); |
| 390 | } |
| 391 | |
| 392 | /** |
| 393 | * at5k_hw_stop_rx_pcu - Stop RX engine |
| 394 | * |
| 395 | * @ah: The &struct ath5k_hw |
| 396 | * |
| 397 | * Stops RX engine on PCU |
| 398 | * |
| 399 | * TODO: Detach ANI here |
| 400 | */ |
| 401 | void ath5k_hw_stop_rx_pcu(struct ath5k_hw *ah) |
| 402 | { |
| 403 | ATH5K_TRACE(ah->ah_sc); |
| 404 | AR5K_REG_ENABLE_BITS(ah, AR5K_DIAG_SW, AR5K_DIAG_SW_DIS_RX); |
| 405 | } |
| 406 | |
| 407 | /* |
| 408 | * Set multicast filter |
| 409 | */ |
| 410 | void ath5k_hw_set_mcast_filter(struct ath5k_hw *ah, u32 filter0, u32 filter1) |
| 411 | { |
| 412 | ATH5K_TRACE(ah->ah_sc); |
| 413 | /* Set the multicat filter */ |
| 414 | ath5k_hw_reg_write(ah, filter0, AR5K_MCAST_FILTER0); |
| 415 | ath5k_hw_reg_write(ah, filter1, AR5K_MCAST_FILTER1); |
| 416 | } |
| 417 | |
| 418 | /* |
| 419 | * Set multicast filter by index |
| 420 | */ |
| 421 | int ath5k_hw_set_mcast_filter_idx(struct ath5k_hw *ah, u32 index) |
| 422 | { |
| 423 | |
| 424 | ATH5K_TRACE(ah->ah_sc); |
| 425 | if (index >= 64) |
| 426 | return -EINVAL; |
| 427 | else if (index >= 32) |
| 428 | AR5K_REG_ENABLE_BITS(ah, AR5K_MCAST_FILTER1, |
| 429 | (1 << (index - 32))); |
| 430 | else |
| 431 | AR5K_REG_ENABLE_BITS(ah, AR5K_MCAST_FILTER0, (1 << index)); |
| 432 | |
| 433 | return 0; |
| 434 | } |
| 435 | |
| 436 | /* |
| 437 | * Clear Multicast filter by index |
| 438 | */ |
| 439 | int ath5k_hw_clear_mcast_filter_idx(struct ath5k_hw *ah, u32 index) |
| 440 | { |
| 441 | |
| 442 | ATH5K_TRACE(ah->ah_sc); |
| 443 | if (index >= 64) |
| 444 | return -EINVAL; |
| 445 | else if (index >= 32) |
| 446 | AR5K_REG_DISABLE_BITS(ah, AR5K_MCAST_FILTER1, |
| 447 | (1 << (index - 32))); |
| 448 | else |
| 449 | AR5K_REG_DISABLE_BITS(ah, AR5K_MCAST_FILTER0, (1 << index)); |
| 450 | |
| 451 | return 0; |
| 452 | } |
| 453 | |
| 454 | /** |
| 455 | * ath5k_hw_get_rx_filter - Get current rx filter |
| 456 | * |
| 457 | * @ah: The &struct ath5k_hw |
| 458 | * |
| 459 | * Returns the RX filter by reading rx filter and |
| 460 | * phy error filter registers. RX filter is used |
| 461 | * to set the allowed frame types that PCU will accept |
| 462 | * and pass to the driver. For a list of frame types |
| 463 | * check out reg.h. |
| 464 | */ |
| 465 | u32 ath5k_hw_get_rx_filter(struct ath5k_hw *ah) |
| 466 | { |
| 467 | u32 data, filter = 0; |
| 468 | |
| 469 | ATH5K_TRACE(ah->ah_sc); |
| 470 | filter = ath5k_hw_reg_read(ah, AR5K_RX_FILTER); |
| 471 | |
| 472 | /*Radar detection for 5212*/ |
| 473 | if (ah->ah_version == AR5K_AR5212) { |
| 474 | data = ath5k_hw_reg_read(ah, AR5K_PHY_ERR_FIL); |
| 475 | |
| 476 | if (data & AR5K_PHY_ERR_FIL_RADAR) |
| 477 | filter |= AR5K_RX_FILTER_RADARERR; |
| 478 | if (data & (AR5K_PHY_ERR_FIL_OFDM | AR5K_PHY_ERR_FIL_CCK)) |
| 479 | filter |= AR5K_RX_FILTER_PHYERR; |
| 480 | } |
| 481 | |
| 482 | return filter; |
| 483 | } |
| 484 | |
| 485 | /** |
| 486 | * ath5k_hw_set_rx_filter - Set rx filter |
| 487 | * |
| 488 | * @ah: The &struct ath5k_hw |
| 489 | * @filter: RX filter mask (see reg.h) |
| 490 | * |
| 491 | * Sets RX filter register and also handles PHY error filter |
| 492 | * register on 5212 and newer chips so that we have proper PHY |
| 493 | * error reporting. |
| 494 | */ |
| 495 | void ath5k_hw_set_rx_filter(struct ath5k_hw *ah, u32 filter) |
| 496 | { |
| 497 | u32 data = 0; |
| 498 | |
| 499 | ATH5K_TRACE(ah->ah_sc); |
| 500 | |
| 501 | /* Set PHY error filter register on 5212*/ |
| 502 | if (ah->ah_version == AR5K_AR5212) { |
| 503 | if (filter & AR5K_RX_FILTER_RADARERR) |
| 504 | data |= AR5K_PHY_ERR_FIL_RADAR; |
| 505 | if (filter & AR5K_RX_FILTER_PHYERR) |
| 506 | data |= AR5K_PHY_ERR_FIL_OFDM | AR5K_PHY_ERR_FIL_CCK; |
| 507 | } |
| 508 | |
| 509 | /* |
| 510 | * The AR5210 uses promiscous mode to detect radar activity |
| 511 | */ |
| 512 | if (ah->ah_version == AR5K_AR5210 && |
| 513 | (filter & AR5K_RX_FILTER_RADARERR)) { |
| 514 | filter &= ~AR5K_RX_FILTER_RADARERR; |
| 515 | filter |= AR5K_RX_FILTER_PROM; |
| 516 | } |
| 517 | |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 518 | /*Zero length DMA (phy error reporting) */ |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 519 | if (data) |
| 520 | AR5K_REG_ENABLE_BITS(ah, AR5K_RXCFG, AR5K_RXCFG_ZLFDMA); |
| 521 | else |
| 522 | AR5K_REG_DISABLE_BITS(ah, AR5K_RXCFG, AR5K_RXCFG_ZLFDMA); |
| 523 | |
| 524 | /*Write RX Filter register*/ |
| 525 | ath5k_hw_reg_write(ah, filter & 0xff, AR5K_RX_FILTER); |
| 526 | |
| 527 | /*Write PHY error filter register on 5212*/ |
| 528 | if (ah->ah_version == AR5K_AR5212) |
| 529 | ath5k_hw_reg_write(ah, data, AR5K_PHY_ERR_FIL); |
| 530 | |
| 531 | } |
| 532 | |
| 533 | |
| 534 | /****************\ |
| 535 | * Beacon control * |
| 536 | \****************/ |
| 537 | |
| 538 | /** |
| 539 | * ath5k_hw_get_tsf32 - Get a 32bit TSF |
| 540 | * |
| 541 | * @ah: The &struct ath5k_hw |
| 542 | * |
| 543 | * Returns lower 32 bits of current TSF |
| 544 | */ |
| 545 | u32 ath5k_hw_get_tsf32(struct ath5k_hw *ah) |
| 546 | { |
| 547 | ATH5K_TRACE(ah->ah_sc); |
| 548 | return ath5k_hw_reg_read(ah, AR5K_TSF_L32); |
| 549 | } |
| 550 | |
| 551 | /** |
| 552 | * ath5k_hw_get_tsf64 - Get the full 64bit TSF |
| 553 | * |
| 554 | * @ah: The &struct ath5k_hw |
| 555 | * |
| 556 | * Returns the current TSF |
| 557 | */ |
| 558 | u64 ath5k_hw_get_tsf64(struct ath5k_hw *ah) |
| 559 | { |
| 560 | u64 tsf = ath5k_hw_reg_read(ah, AR5K_TSF_U32); |
| 561 | ATH5K_TRACE(ah->ah_sc); |
| 562 | |
| 563 | return ath5k_hw_reg_read(ah, AR5K_TSF_L32) | (tsf << 32); |
| 564 | } |
| 565 | |
| 566 | /** |
Alina Friedrichsen | 8cab758 | 2009-01-23 05:39:13 +0100 | [diff] [blame] | 567 | * ath5k_hw_set_tsf64 - Set a new 64bit TSF |
| 568 | * |
| 569 | * @ah: The &struct ath5k_hw |
| 570 | * @tsf64: The new 64bit TSF |
| 571 | * |
| 572 | * Sets the new TSF |
| 573 | */ |
| 574 | void ath5k_hw_set_tsf64(struct ath5k_hw *ah, u64 tsf64) |
| 575 | { |
| 576 | ATH5K_TRACE(ah->ah_sc); |
| 577 | |
Alina Friedrichsen | 8cab758 | 2009-01-23 05:39:13 +0100 | [diff] [blame] | 578 | ath5k_hw_reg_write(ah, tsf64 & 0xffffffff, AR5K_TSF_L32); |
Alina Friedrichsen | 0ad65bd | 2009-03-02 23:29:48 +0100 | [diff] [blame] | 579 | ath5k_hw_reg_write(ah, (tsf64 >> 32) & 0xffffffff, AR5K_TSF_U32); |
Alina Friedrichsen | 8cab758 | 2009-01-23 05:39:13 +0100 | [diff] [blame] | 580 | } |
| 581 | |
| 582 | /** |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 583 | * ath5k_hw_reset_tsf - Force a TSF reset |
| 584 | * |
| 585 | * @ah: The &struct ath5k_hw |
| 586 | * |
| 587 | * Forces a TSF reset on PCU |
| 588 | */ |
| 589 | void ath5k_hw_reset_tsf(struct ath5k_hw *ah) |
| 590 | { |
Bob Copeland | 14be994 | 2008-09-28 12:09:43 -0400 | [diff] [blame] | 591 | u32 val; |
| 592 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 593 | ATH5K_TRACE(ah->ah_sc); |
Bob Copeland | 14be994 | 2008-09-28 12:09:43 -0400 | [diff] [blame] | 594 | |
| 595 | val = ath5k_hw_reg_read(ah, AR5K_BEACON) | AR5K_BEACON_RESET_TSF; |
| 596 | |
| 597 | /* |
| 598 | * Each write to the RESET_TSF bit toggles a hardware internal |
| 599 | * signal to reset TSF, but if left high it will cause a TSF reset |
| 600 | * on the next chip reset as well. Thus we always write the value |
| 601 | * twice to clear the signal. |
| 602 | */ |
| 603 | ath5k_hw_reg_write(ah, val, AR5K_BEACON); |
| 604 | ath5k_hw_reg_write(ah, val, AR5K_BEACON); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 605 | } |
| 606 | |
| 607 | /* |
| 608 | * Initialize beacon timers |
| 609 | */ |
| 610 | void ath5k_hw_init_beacon(struct ath5k_hw *ah, u32 next_beacon, u32 interval) |
| 611 | { |
| 612 | u32 timer1, timer2, timer3; |
| 613 | |
| 614 | ATH5K_TRACE(ah->ah_sc); |
| 615 | /* |
| 616 | * Set the additional timers by mode |
| 617 | */ |
| 618 | switch (ah->ah_op_mode) { |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 619 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 620 | case NL80211_IFTYPE_STATION: |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 621 | /* In STA mode timer1 is used as next wakeup |
| 622 | * timer and timer2 as next CFP duration start |
| 623 | * timer. Both in 1/8TUs. */ |
| 624 | /* TODO: PCF handling */ |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 625 | if (ah->ah_version == AR5K_AR5210) { |
| 626 | timer1 = 0xffffffff; |
| 627 | timer2 = 0xffffffff; |
| 628 | } else { |
| 629 | timer1 = 0x0000ffff; |
| 630 | timer2 = 0x0007ffff; |
| 631 | } |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 632 | /* Mark associated AP as PCF incapable for now */ |
| 633 | AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1, AR5K_STA_ID1_PCF); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 634 | break; |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 635 | case NL80211_IFTYPE_ADHOC: |
| 636 | AR5K_REG_ENABLE_BITS(ah, AR5K_TXCFG, AR5K_TXCFG_ADHOC_BCN_ATIM); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 637 | default: |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 638 | /* On non-STA modes timer1 is used as next DMA |
| 639 | * beacon alert (DBA) timer and timer2 as next |
| 640 | * software beacon alert. Both in 1/8TUs. */ |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 641 | timer1 = (next_beacon - AR5K_TUNE_DMA_BEACON_RESP) << 3; |
| 642 | timer2 = (next_beacon - AR5K_TUNE_SW_BEACON_RESP) << 3; |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 643 | break; |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 644 | } |
| 645 | |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 646 | /* Timer3 marks the end of our ATIM window |
| 647 | * a zero length window is not allowed because |
| 648 | * we 'll get no beacons */ |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 649 | timer3 = next_beacon + (ah->ah_atim_window ? ah->ah_atim_window : 1); |
| 650 | |
| 651 | /* |
| 652 | * Set the beacon register and enable all timers. |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 653 | */ |
Nick Kossifidis | 35edf8a | 2009-06-12 16:09:53 -0700 | [diff] [blame] | 654 | /* When in AP or Mesh Point mode zero timer0 to start TSF */ |
| 655 | if (ah->ah_op_mode == NL80211_IFTYPE_AP || |
| 656 | ah->ah_op_mode == NL80211_IFTYPE_MESH_POINT) |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 657 | ath5k_hw_reg_write(ah, 0, AR5K_TIMER0); |
Nick Kossifidis | 428cbd4 | 2009-04-30 15:55:47 -0400 | [diff] [blame] | 658 | |
| 659 | ath5k_hw_reg_write(ah, next_beacon, AR5K_TIMER0); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 660 | ath5k_hw_reg_write(ah, timer1, AR5K_TIMER1); |
| 661 | ath5k_hw_reg_write(ah, timer2, AR5K_TIMER2); |
| 662 | ath5k_hw_reg_write(ah, timer3, AR5K_TIMER3); |
| 663 | |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 664 | /* Force a TSF reset if requested and enable beacons */ |
| 665 | if (interval & AR5K_BEACON_RESET_TSF) |
| 666 | ath5k_hw_reset_tsf(ah); |
| 667 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 668 | ath5k_hw_reg_write(ah, interval & (AR5K_BEACON_PERIOD | |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 669 | AR5K_BEACON_ENABLE), |
| 670 | AR5K_BEACON); |
| 671 | |
| 672 | /* Flush any pending BMISS interrupts on ISR by |
| 673 | * performing a clear-on-write operation on PISR |
| 674 | * register for the BMISS bit (writing a bit on |
| 675 | * ISR togles a reset for that bit and leaves |
| 676 | * the rest bits intact) */ |
| 677 | if (ah->ah_version == AR5K_AR5210) |
| 678 | ath5k_hw_reg_write(ah, AR5K_ISR_BMISS, AR5K_ISR); |
| 679 | else |
| 680 | ath5k_hw_reg_write(ah, AR5K_ISR_BMISS, AR5K_PISR); |
| 681 | |
| 682 | /* TODO: Set enchanced sleep registers on AR5212 |
| 683 | * based on vif->bss_conf params, until then |
| 684 | * disable power save reporting.*/ |
| 685 | AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1, AR5K_STA_ID1_PWR_SV); |
| 686 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | #if 0 |
| 690 | /* |
| 691 | * Set beacon timers |
| 692 | */ |
| 693 | int ath5k_hw_set_beacon_timers(struct ath5k_hw *ah, |
| 694 | const struct ath5k_beacon_state *state) |
| 695 | { |
| 696 | u32 cfp_period, next_cfp, dtim, interval, next_beacon; |
| 697 | |
| 698 | /* |
| 699 | * TODO: should be changed through *state |
| 700 | * review struct ath5k_beacon_state struct |
| 701 | * |
| 702 | * XXX: These are used for cfp period bellow, are they |
| 703 | * ok ? Is it O.K. for tsf here to be 0 or should we use |
| 704 | * get_tsf ? |
| 705 | */ |
| 706 | u32 dtim_count = 0; /* XXX */ |
| 707 | u32 cfp_count = 0; /* XXX */ |
| 708 | u32 tsf = 0; /* XXX */ |
| 709 | |
| 710 | ATH5K_TRACE(ah->ah_sc); |
| 711 | /* Return on an invalid beacon state */ |
| 712 | if (state->bs_interval < 1) |
| 713 | return -EINVAL; |
| 714 | |
| 715 | interval = state->bs_interval; |
| 716 | dtim = state->bs_dtim_period; |
| 717 | |
| 718 | /* |
| 719 | * PCF support? |
| 720 | */ |
| 721 | if (state->bs_cfp_period > 0) { |
| 722 | /* |
| 723 | * Enable PCF mode and set the CFP |
| 724 | * (Contention Free Period) and timer registers |
| 725 | */ |
| 726 | cfp_period = state->bs_cfp_period * state->bs_dtim_period * |
| 727 | state->bs_interval; |
| 728 | next_cfp = (cfp_count * state->bs_dtim_period + dtim_count) * |
| 729 | state->bs_interval; |
| 730 | |
| 731 | AR5K_REG_ENABLE_BITS(ah, AR5K_STA_ID1, |
| 732 | AR5K_STA_ID1_DEFAULT_ANTENNA | |
| 733 | AR5K_STA_ID1_PCF); |
| 734 | ath5k_hw_reg_write(ah, cfp_period, AR5K_CFP_PERIOD); |
| 735 | ath5k_hw_reg_write(ah, state->bs_cfp_max_duration, |
| 736 | AR5K_CFP_DUR); |
| 737 | ath5k_hw_reg_write(ah, (tsf + (next_cfp == 0 ? cfp_period : |
| 738 | next_cfp)) << 3, AR5K_TIMER2); |
| 739 | } else { |
| 740 | /* Disable PCF mode */ |
| 741 | AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1, |
| 742 | AR5K_STA_ID1_DEFAULT_ANTENNA | |
| 743 | AR5K_STA_ID1_PCF); |
| 744 | } |
| 745 | |
| 746 | /* |
| 747 | * Enable the beacon timer register |
| 748 | */ |
| 749 | ath5k_hw_reg_write(ah, state->bs_next_beacon, AR5K_TIMER0); |
| 750 | |
| 751 | /* |
| 752 | * Start the beacon timers |
| 753 | */ |
| 754 | ath5k_hw_reg_write(ah, (ath5k_hw_reg_read(ah, AR5K_BEACON) & |
| 755 | ~(AR5K_BEACON_PERIOD | AR5K_BEACON_TIM)) | |
| 756 | AR5K_REG_SM(state->bs_tim_offset ? state->bs_tim_offset + 4 : 0, |
| 757 | AR5K_BEACON_TIM) | AR5K_REG_SM(state->bs_interval, |
| 758 | AR5K_BEACON_PERIOD), AR5K_BEACON); |
| 759 | |
| 760 | /* |
| 761 | * Write new beacon miss threshold, if it appears to be valid |
| 762 | * XXX: Figure out right values for min <= bs_bmiss_threshold <= max |
| 763 | * and return if its not in range. We can test this by reading value and |
| 764 | * setting value to a largest value and seeing which values register. |
| 765 | */ |
| 766 | |
| 767 | AR5K_REG_WRITE_BITS(ah, AR5K_RSSI_THR, AR5K_RSSI_THR_BMISS, |
| 768 | state->bs_bmiss_threshold); |
| 769 | |
| 770 | /* |
| 771 | * Set sleep control register |
| 772 | * XXX: Didn't find this in 5210 code but since this register |
| 773 | * exists also in ar5k's 5210 headers i leave it as common code. |
| 774 | */ |
| 775 | AR5K_REG_WRITE_BITS(ah, AR5K_SLEEP_CTL, AR5K_SLEEP_CTL_SLDUR, |
| 776 | (state->bs_sleep_duration - 3) << 3); |
| 777 | |
| 778 | /* |
| 779 | * Set enhanced sleep registers on 5212 |
| 780 | */ |
| 781 | if (ah->ah_version == AR5K_AR5212) { |
| 782 | if (state->bs_sleep_duration > state->bs_interval && |
| 783 | roundup(state->bs_sleep_duration, interval) == |
| 784 | state->bs_sleep_duration) |
| 785 | interval = state->bs_sleep_duration; |
| 786 | |
| 787 | if (state->bs_sleep_duration > dtim && (dtim == 0 || |
| 788 | roundup(state->bs_sleep_duration, dtim) == |
| 789 | state->bs_sleep_duration)) |
| 790 | dtim = state->bs_sleep_duration; |
| 791 | |
| 792 | if (interval > dtim) |
| 793 | return -EINVAL; |
| 794 | |
| 795 | next_beacon = interval == dtim ? state->bs_next_dtim : |
| 796 | state->bs_next_beacon; |
| 797 | |
| 798 | ath5k_hw_reg_write(ah, |
| 799 | AR5K_REG_SM((state->bs_next_dtim - 3) << 3, |
| 800 | AR5K_SLEEP0_NEXT_DTIM) | |
| 801 | AR5K_REG_SM(10, AR5K_SLEEP0_CABTO) | |
| 802 | AR5K_SLEEP0_ENH_SLEEP_EN | |
| 803 | AR5K_SLEEP0_ASSUME_DTIM, AR5K_SLEEP0); |
| 804 | |
| 805 | ath5k_hw_reg_write(ah, AR5K_REG_SM((next_beacon - 3) << 3, |
| 806 | AR5K_SLEEP1_NEXT_TIM) | |
| 807 | AR5K_REG_SM(10, AR5K_SLEEP1_BEACON_TO), AR5K_SLEEP1); |
| 808 | |
| 809 | ath5k_hw_reg_write(ah, |
| 810 | AR5K_REG_SM(interval, AR5K_SLEEP2_TIM_PER) | |
| 811 | AR5K_REG_SM(dtim, AR5K_SLEEP2_DTIM_PER), AR5K_SLEEP2); |
| 812 | } |
| 813 | |
| 814 | return 0; |
| 815 | } |
| 816 | |
| 817 | /* |
| 818 | * Reset beacon timers |
| 819 | */ |
| 820 | void ath5k_hw_reset_beacon(struct ath5k_hw *ah) |
| 821 | { |
| 822 | ATH5K_TRACE(ah->ah_sc); |
| 823 | /* |
| 824 | * Disable beacon timer |
| 825 | */ |
| 826 | ath5k_hw_reg_write(ah, 0, AR5K_TIMER0); |
| 827 | |
| 828 | /* |
| 829 | * Disable some beacon register values |
| 830 | */ |
| 831 | AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1, |
| 832 | AR5K_STA_ID1_DEFAULT_ANTENNA | AR5K_STA_ID1_PCF); |
| 833 | ath5k_hw_reg_write(ah, AR5K_BEACON_PERIOD, AR5K_BEACON); |
| 834 | } |
| 835 | |
| 836 | /* |
| 837 | * Wait for beacon queue to finish |
| 838 | */ |
| 839 | int ath5k_hw_beaconq_finish(struct ath5k_hw *ah, unsigned long phys_addr) |
| 840 | { |
| 841 | unsigned int i; |
| 842 | int ret; |
| 843 | |
| 844 | ATH5K_TRACE(ah->ah_sc); |
| 845 | |
| 846 | /* 5210 doesn't have QCU*/ |
| 847 | if (ah->ah_version == AR5K_AR5210) { |
| 848 | /* |
| 849 | * Wait for beaconn queue to finish by checking |
| 850 | * Control Register and Beacon Status Register. |
| 851 | */ |
| 852 | for (i = AR5K_TUNE_BEACON_INTERVAL / 2; i > 0; i--) { |
| 853 | if (!(ath5k_hw_reg_read(ah, AR5K_BSR) & AR5K_BSR_TXQ1F) |
| 854 | || |
| 855 | !(ath5k_hw_reg_read(ah, AR5K_CR) & AR5K_BSR_TXQ1F)) |
| 856 | break; |
| 857 | udelay(10); |
| 858 | } |
| 859 | |
| 860 | /* Timeout... */ |
| 861 | if (i <= 0) { |
| 862 | /* |
| 863 | * Re-schedule the beacon queue |
| 864 | */ |
| 865 | ath5k_hw_reg_write(ah, phys_addr, AR5K_NOQCU_TXDP1); |
| 866 | ath5k_hw_reg_write(ah, AR5K_BCR_TQ1V | AR5K_BCR_BDMAE, |
| 867 | AR5K_BCR); |
| 868 | |
| 869 | return -EIO; |
| 870 | } |
| 871 | ret = 0; |
| 872 | } else { |
| 873 | /*5211/5212*/ |
| 874 | ret = ath5k_hw_register_timeout(ah, |
| 875 | AR5K_QUEUE_STATUS(AR5K_TX_QUEUE_ID_BEACON), |
| 876 | AR5K_QCU_STS_FRMPENDCNT, 0, false); |
| 877 | |
| 878 | if (AR5K_REG_READ_Q(ah, AR5K_QCU_TXE, AR5K_TX_QUEUE_ID_BEACON)) |
| 879 | return -EIO; |
| 880 | } |
| 881 | |
| 882 | return ret; |
| 883 | } |
| 884 | #endif |
| 885 | |
| 886 | |
| 887 | /*********************\ |
| 888 | * Key table functions * |
| 889 | \*********************/ |
| 890 | |
| 891 | /* |
| 892 | * Reset a key entry on the table |
| 893 | */ |
| 894 | int ath5k_hw_reset_key(struct ath5k_hw *ah, u16 entry) |
| 895 | { |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 896 | unsigned int i, type; |
Bob Copeland | 17683c6 | 2008-10-29 23:24:26 -0400 | [diff] [blame] | 897 | u16 micentry = entry + AR5K_KEYTABLE_MIC_OFFSET; |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 898 | |
| 899 | ATH5K_TRACE(ah->ah_sc); |
| 900 | AR5K_ASSERT_ENTRY(entry, AR5K_KEYTABLE_SIZE); |
| 901 | |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 902 | type = ath5k_hw_reg_read(ah, AR5K_KEYTABLE_TYPE(entry)); |
| 903 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 904 | for (i = 0; i < AR5K_KEYCACHE_SIZE; i++) |
| 905 | ath5k_hw_reg_write(ah, 0, AR5K_KEYTABLE_OFF(entry, i)); |
| 906 | |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 907 | /* Reset associated MIC entry if TKIP |
| 908 | * is enabled located at offset (entry + 64) */ |
| 909 | if (type == AR5K_KEYTABLE_TYPE_TKIP) { |
Bob Copeland | 17683c6 | 2008-10-29 23:24:26 -0400 | [diff] [blame] | 910 | AR5K_ASSERT_ENTRY(micentry, AR5K_KEYTABLE_SIZE); |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 911 | for (i = 0; i < AR5K_KEYCACHE_SIZE / 2 ; i++) |
Bob Copeland | 17683c6 | 2008-10-29 23:24:26 -0400 | [diff] [blame] | 912 | ath5k_hw_reg_write(ah, 0, |
| 913 | AR5K_KEYTABLE_OFF(micentry, i)); |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 914 | } |
| 915 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 916 | /* |
| 917 | * Set NULL encryption on AR5212+ |
| 918 | * |
| 919 | * Note: AR5K_KEYTABLE_TYPE -> AR5K_KEYTABLE_OFF(entry, 5) |
| 920 | * AR5K_KEYTABLE_TYPE_NULL -> 0x00000007 |
| 921 | * |
| 922 | * Note2: Windows driver (ndiswrapper) sets this to |
| 923 | * 0x00000714 instead of 0x00000007 |
| 924 | */ |
Jiri Slaby | ded7a7e | 2009-04-25 14:09:23 +0200 | [diff] [blame] | 925 | if (ah->ah_version >= AR5K_AR5211) { |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 926 | ath5k_hw_reg_write(ah, AR5K_KEYTABLE_TYPE_NULL, |
| 927 | AR5K_KEYTABLE_TYPE(entry)); |
| 928 | |
Bob Copeland | 17683c6 | 2008-10-29 23:24:26 -0400 | [diff] [blame] | 929 | if (type == AR5K_KEYTABLE_TYPE_TKIP) { |
| 930 | ath5k_hw_reg_write(ah, AR5K_KEYTABLE_TYPE_NULL, |
| 931 | AR5K_KEYTABLE_TYPE(micentry)); |
| 932 | } |
| 933 | } |
| 934 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 935 | return 0; |
| 936 | } |
| 937 | |
| 938 | /* |
| 939 | * Check if a table entry is valid |
| 940 | */ |
| 941 | int ath5k_hw_is_key_valid(struct ath5k_hw *ah, u16 entry) |
| 942 | { |
| 943 | ATH5K_TRACE(ah->ah_sc); |
| 944 | AR5K_ASSERT_ENTRY(entry, AR5K_KEYTABLE_SIZE); |
| 945 | |
| 946 | /* Check the validation flag at the end of the entry */ |
| 947 | return ath5k_hw_reg_read(ah, AR5K_KEYTABLE_MAC1(entry)) & |
| 948 | AR5K_KEYTABLE_VALID; |
| 949 | } |
| 950 | |
Bob Copeland | 6714349 | 2008-11-25 20:55:21 -0500 | [diff] [blame] | 951 | static |
| 952 | int ath5k_keycache_type(const struct ieee80211_key_conf *key) |
| 953 | { |
| 954 | switch (key->alg) { |
| 955 | case ALG_TKIP: |
| 956 | return AR5K_KEYTABLE_TYPE_TKIP; |
| 957 | case ALG_CCMP: |
| 958 | return AR5K_KEYTABLE_TYPE_CCM; |
| 959 | case ALG_WEP: |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 960 | if (key->keylen == WLAN_KEY_LEN_WEP40) |
Bob Copeland | 6714349 | 2008-11-25 20:55:21 -0500 | [diff] [blame] | 961 | return AR5K_KEYTABLE_TYPE_40; |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 962 | else if (key->keylen == WLAN_KEY_LEN_WEP104) |
Bob Copeland | 6714349 | 2008-11-25 20:55:21 -0500 | [diff] [blame] | 963 | return AR5K_KEYTABLE_TYPE_104; |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 964 | return -EINVAL; |
| 965 | default: |
| 966 | return -EINVAL; |
Bob Copeland | 6714349 | 2008-11-25 20:55:21 -0500 | [diff] [blame] | 967 | } |
| 968 | return -EINVAL; |
| 969 | } |
| 970 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 971 | /* |
| 972 | * Set a key entry on the table |
| 973 | */ |
| 974 | int ath5k_hw_set_key(struct ath5k_hw *ah, u16 entry, |
| 975 | const struct ieee80211_key_conf *key, const u8 *mac) |
| 976 | { |
| 977 | unsigned int i; |
Bob Copeland | 3f64b43 | 2008-10-29 23:19:14 -0400 | [diff] [blame] | 978 | int keylen; |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 979 | __le32 key_v[5] = {}; |
Bob Copeland | 3f64b43 | 2008-10-29 23:19:14 -0400 | [diff] [blame] | 980 | __le32 key0 = 0, key1 = 0; |
| 981 | __le32 *rxmic, *txmic; |
Roel Kluin | 672cf3c | 2009-01-18 23:50:27 +0100 | [diff] [blame] | 982 | int keytype; |
Bob Copeland | 3f64b43 | 2008-10-29 23:19:14 -0400 | [diff] [blame] | 983 | u16 micentry = entry + AR5K_KEYTABLE_MIC_OFFSET; |
| 984 | bool is_tkip; |
Bob Copeland | 6714349 | 2008-11-25 20:55:21 -0500 | [diff] [blame] | 985 | const u8 *key_ptr; |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 986 | |
| 987 | ATH5K_TRACE(ah->ah_sc); |
| 988 | |
Bob Copeland | 3f64b43 | 2008-10-29 23:19:14 -0400 | [diff] [blame] | 989 | is_tkip = (key->alg == ALG_TKIP); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 990 | |
Bob Copeland | 3f64b43 | 2008-10-29 23:19:14 -0400 | [diff] [blame] | 991 | /* |
| 992 | * key->keylen comes in from mac80211 in bytes. |
| 993 | * TKIP is 128 bit + 128 bit mic |
| 994 | */ |
| 995 | keylen = (is_tkip) ? (128 / 8) : key->keylen; |
| 996 | |
| 997 | if (entry > AR5K_KEYTABLE_SIZE || |
| 998 | (is_tkip && micentry > AR5K_KEYTABLE_SIZE)) |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 999 | return -EOPNOTSUPP; |
| 1000 | |
Bob Copeland | 6714349 | 2008-11-25 20:55:21 -0500 | [diff] [blame] | 1001 | if (unlikely(keylen > 16)) |
| 1002 | return -EOPNOTSUPP; |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 1003 | |
Bob Copeland | 6714349 | 2008-11-25 20:55:21 -0500 | [diff] [blame] | 1004 | keytype = ath5k_keycache_type(key); |
| 1005 | if (keytype < 0) |
| 1006 | return keytype; |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 1007 | |
Bob Copeland | 6714349 | 2008-11-25 20:55:21 -0500 | [diff] [blame] | 1008 | /* |
| 1009 | * each key block is 6 bytes wide, written as pairs of |
| 1010 | * alternating 32 and 16 bit le values. |
| 1011 | */ |
| 1012 | key_ptr = key->key; |
| 1013 | for (i = 0; keylen >= 6; keylen -= 6) { |
| 1014 | memcpy(&key_v[i], key_ptr, 6); |
| 1015 | i += 2; |
| 1016 | key_ptr += 6; |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 1017 | } |
Bob Copeland | 6714349 | 2008-11-25 20:55:21 -0500 | [diff] [blame] | 1018 | if (keylen) |
| 1019 | memcpy(&key_v[i], key_ptr, keylen); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 1020 | |
Bob Copeland | 3f64b43 | 2008-10-29 23:19:14 -0400 | [diff] [blame] | 1021 | /* intentionally corrupt key until mic is installed */ |
| 1022 | if (is_tkip) { |
| 1023 | key0 = key_v[0] = ~key_v[0]; |
| 1024 | key1 = key_v[1] = ~key_v[1]; |
| 1025 | } |
| 1026 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 1027 | for (i = 0; i < ARRAY_SIZE(key_v); i++) |
| 1028 | ath5k_hw_reg_write(ah, le32_to_cpu(key_v[i]), |
| 1029 | AR5K_KEYTABLE_OFF(entry, i)); |
| 1030 | |
| 1031 | ath5k_hw_reg_write(ah, keytype, AR5K_KEYTABLE_TYPE(entry)); |
| 1032 | |
Bob Copeland | 3f64b43 | 2008-10-29 23:19:14 -0400 | [diff] [blame] | 1033 | if (is_tkip) { |
| 1034 | /* Install rx/tx MIC */ |
| 1035 | rxmic = (__le32 *) &key->key[16]; |
| 1036 | txmic = (__le32 *) &key->key[24]; |
Bob Copeland | f650470 | 2008-11-26 16:17:25 -0500 | [diff] [blame] | 1037 | |
| 1038 | if (ah->ah_combined_mic) { |
| 1039 | key_v[0] = rxmic[0]; |
Bob Copeland | 388cdf3 | 2008-12-09 23:05:38 -0500 | [diff] [blame] | 1040 | key_v[1] = cpu_to_le32(le32_to_cpu(txmic[0]) >> 16); |
Bob Copeland | f650470 | 2008-11-26 16:17:25 -0500 | [diff] [blame] | 1041 | key_v[2] = rxmic[1]; |
Bob Copeland | 388cdf3 | 2008-12-09 23:05:38 -0500 | [diff] [blame] | 1042 | key_v[3] = cpu_to_le32(le32_to_cpu(txmic[0]) & 0xffff); |
Bob Copeland | f650470 | 2008-11-26 16:17:25 -0500 | [diff] [blame] | 1043 | key_v[4] = txmic[1]; |
| 1044 | } else { |
| 1045 | key_v[0] = rxmic[0]; |
| 1046 | key_v[1] = 0; |
| 1047 | key_v[2] = rxmic[1]; |
| 1048 | key_v[3] = 0; |
| 1049 | key_v[4] = 0; |
| 1050 | } |
Bob Copeland | 3f64b43 | 2008-10-29 23:19:14 -0400 | [diff] [blame] | 1051 | for (i = 0; i < ARRAY_SIZE(key_v); i++) |
| 1052 | ath5k_hw_reg_write(ah, le32_to_cpu(key_v[i]), |
| 1053 | AR5K_KEYTABLE_OFF(micentry, i)); |
| 1054 | |
| 1055 | ath5k_hw_reg_write(ah, AR5K_KEYTABLE_TYPE_NULL, |
| 1056 | AR5K_KEYTABLE_TYPE(micentry)); |
| 1057 | ath5k_hw_reg_write(ah, 0, AR5K_KEYTABLE_MAC0(micentry)); |
| 1058 | ath5k_hw_reg_write(ah, 0, AR5K_KEYTABLE_MAC1(micentry)); |
| 1059 | |
| 1060 | /* restore first 2 words of key */ |
| 1061 | ath5k_hw_reg_write(ah, le32_to_cpu(~key0), |
| 1062 | AR5K_KEYTABLE_OFF(entry, 0)); |
| 1063 | ath5k_hw_reg_write(ah, le32_to_cpu(~key1), |
| 1064 | AR5K_KEYTABLE_OFF(entry, 1)); |
| 1065 | } |
| 1066 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 1067 | return ath5k_hw_set_key_lladdr(ah, entry, mac); |
| 1068 | } |
| 1069 | |
| 1070 | int ath5k_hw_set_key_lladdr(struct ath5k_hw *ah, u16 entry, const u8 *mac) |
| 1071 | { |
| 1072 | u32 low_id, high_id; |
| 1073 | |
| 1074 | ATH5K_TRACE(ah->ah_sc); |
| 1075 | /* Invalid entry (key table overflow) */ |
| 1076 | AR5K_ASSERT_ENTRY(entry, AR5K_KEYTABLE_SIZE); |
| 1077 | |
Luis R. Rodriguez | bcd8f54 | 2009-09-09 22:43:17 -0700 | [diff] [blame] | 1078 | /* |
| 1079 | * MAC may be NULL if it's a broadcast key. In this case no need to |
| 1080 | * to compute get_unaligned_le32 and get_unaligned_le16 as we |
| 1081 | * already know it. |
| 1082 | */ |
Johannes Berg | dc822b5 | 2008-12-29 12:55:09 +0100 | [diff] [blame] | 1083 | if (!mac) { |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 1084 | low_id = 0xffffffff; |
| 1085 | high_id = 0xffff | AR5K_KEYTABLE_VALID; |
| 1086 | } else { |
Luis R. Rodriguez | bcd8f54 | 2009-09-09 22:43:17 -0700 | [diff] [blame] | 1087 | low_id = get_unaligned_le32(mac); |
| 1088 | high_id = get_unaligned_le16(mac + 4) | AR5K_KEYTABLE_VALID; |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 1089 | } |
| 1090 | |
| 1091 | ath5k_hw_reg_write(ah, low_id, AR5K_KEYTABLE_MAC0(entry)); |
| 1092 | ath5k_hw_reg_write(ah, high_id, AR5K_KEYTABLE_MAC1(entry)); |
| 1093 | |
| 1094 | return 0; |
| 1095 | } |
| 1096 | |