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