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 |
Bruno Randolf | ccfe555 | 2010-03-09 16:55:38 +0900 | [diff] [blame] | 42 | * @op_mode: &enum nl80211_iftype operating mode |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 43 | * |
| 44 | * Initialize PCU for the various operating modes (AP/STA etc) |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 45 | */ |
Bruno Randolf | ccfe555 | 2010-03-09 16:55:38 +0900 | [diff] [blame] | 46 | int ath5k_hw_set_opmode(struct ath5k_hw *ah, enum nl80211_iftype op_mode) |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 47 | { |
Luis R. Rodriguez | 954fece | 2009-09-10 10:51:33 -0700 | [diff] [blame] | 48 | struct ath_common *common = ath5k_hw_common(ah); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 49 | u32 pcu_reg, beacon_reg, low_id, high_id; |
| 50 | |
Bruno Randolf | ccfe555 | 2010-03-09 16:55:38 +0900 | [diff] [blame] | 51 | ATH5K_DBG(ah->ah_sc, ATH5K_DEBUG_MODE, "mode %d\n", op_mode); |
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 | |
Bruno Randolf | ccfe555 | 2010-03-09 16:55:38 +0900 | [diff] [blame] | 64 | switch (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 | /** |
Bruno Randolf | 495391d | 2010-03-25 14:49:36 +0900 | [diff] [blame^] | 116 | * ath5k_hw_update - Update MIB counters (mac layer statistics) |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 117 | * |
| 118 | * @ah: The &struct ath5k_hw |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 119 | * |
Bruno Randolf | 495391d | 2010-03-25 14:49:36 +0900 | [diff] [blame^] | 120 | * Reads MIB counters from PCU and updates sw statistics. Is called after a |
| 121 | * MIB interrupt, because one of these counters might have reached their maximum |
| 122 | * and triggered the MIB interrupt, to let us read and clear the counter. |
| 123 | * |
| 124 | * Is called in interrupt context! |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 125 | */ |
Bruno Randolf | 495391d | 2010-03-25 14:49:36 +0900 | [diff] [blame^] | 126 | void ath5k_hw_update_mib_counters(struct ath5k_hw *ah) |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 127 | { |
Bruno Randolf | 495391d | 2010-03-25 14:49:36 +0900 | [diff] [blame^] | 128 | struct ath5k_statistics *stats = &ah->ah_sc->stats; |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 129 | |
| 130 | /* Read-And-Clear */ |
Bruno Randolf | 495391d | 2010-03-25 14:49:36 +0900 | [diff] [blame^] | 131 | stats->ack_fail += ath5k_hw_reg_read(ah, AR5K_ACK_FAIL); |
| 132 | stats->rts_fail += ath5k_hw_reg_read(ah, AR5K_RTS_FAIL); |
| 133 | stats->rts_ok += ath5k_hw_reg_read(ah, AR5K_RTS_OK); |
| 134 | stats->fcs_error += ath5k_hw_reg_read(ah, AR5K_FCS_FAIL); |
| 135 | stats->beacons += ath5k_hw_reg_read(ah, AR5K_BEACON_CNT); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | /** |
| 139 | * ath5k_hw_set_ack_bitrate - set bitrate for ACKs |
| 140 | * |
| 141 | * @ah: The &struct ath5k_hw |
| 142 | * @high: Flag to determine if we want to use high transmition rate |
| 143 | * for ACKs or not |
| 144 | * |
| 145 | * If high flag is set, we tell hw to use a set of control rates based on |
| 146 | * the current transmition rate (check out control_rates array inside reset.c). |
| 147 | * If not hw just uses the lowest rate available for the current modulation |
| 148 | * scheme being used (1Mbit for CCK and 6Mbits for OFDM). |
| 149 | */ |
| 150 | void ath5k_hw_set_ack_bitrate_high(struct ath5k_hw *ah, bool high) |
| 151 | { |
| 152 | if (ah->ah_version != AR5K_AR5212) |
| 153 | return; |
| 154 | else { |
| 155 | u32 val = AR5K_STA_ID1_BASE_RATE_11B | AR5K_STA_ID1_ACKCTS_6MB; |
| 156 | if (high) |
| 157 | AR5K_REG_ENABLE_BITS(ah, AR5K_STA_ID1, val); |
| 158 | else |
| 159 | AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1, val); |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | |
| 164 | /******************\ |
| 165 | * ACK/CTS Timeouts * |
| 166 | \******************/ |
| 167 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 168 | /** |
| 169 | * ath5k_hw_set_ack_timeout - Set ACK timeout on PCU |
| 170 | * |
| 171 | * @ah: The &struct ath5k_hw |
| 172 | * @timeout: Timeout in usec |
| 173 | */ |
Pavel Roskin | 626ede6 | 2010-02-18 20:28:02 -0500 | [diff] [blame] | 174 | 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] | 175 | { |
| 176 | ATH5K_TRACE(ah->ah_sc); |
Lukáš Turek | 3578e6e | 2009-12-21 22:50:50 +0100 | [diff] [blame] | 177 | if (ath5k_hw_clocktoh(ah, AR5K_REG_MS(0xffffffff, AR5K_TIME_OUT_ACK)) |
| 178 | <= timeout) |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 179 | return -EINVAL; |
| 180 | |
| 181 | AR5K_REG_WRITE_BITS(ah, AR5K_TIME_OUT, AR5K_TIME_OUT_ACK, |
Lukáš Turek | 3578e6e | 2009-12-21 22:50:50 +0100 | [diff] [blame] | 182 | ath5k_hw_htoclock(ah, timeout)); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 183 | |
| 184 | return 0; |
| 185 | } |
| 186 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 187 | /** |
| 188 | * ath5k_hw_set_cts_timeout - Set CTS timeout on PCU |
| 189 | * |
| 190 | * @ah: The &struct ath5k_hw |
| 191 | * @timeout: Timeout in usec |
| 192 | */ |
Pavel Roskin | 626ede6 | 2010-02-18 20:28:02 -0500 | [diff] [blame] | 193 | 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] | 194 | { |
| 195 | ATH5K_TRACE(ah->ah_sc); |
Lukáš Turek | 3578e6e | 2009-12-21 22:50:50 +0100 | [diff] [blame] | 196 | if (ath5k_hw_clocktoh(ah, AR5K_REG_MS(0xffffffff, AR5K_TIME_OUT_CTS)) |
| 197 | <= timeout) |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 198 | return -EINVAL; |
| 199 | |
| 200 | AR5K_REG_WRITE_BITS(ah, AR5K_TIME_OUT, AR5K_TIME_OUT_CTS, |
Lukáš Turek | 3578e6e | 2009-12-21 22:50:50 +0100 | [diff] [blame] | 201 | ath5k_hw_htoclock(ah, timeout)); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 202 | |
| 203 | return 0; |
| 204 | } |
| 205 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 206 | /** |
Lukáš Turek | 3578e6e | 2009-12-21 22:50:50 +0100 | [diff] [blame] | 207 | * ath5k_hw_htoclock - Translate usec to hw clock units |
| 208 | * |
| 209 | * @ah: The &struct ath5k_hw |
| 210 | * @usec: value in microseconds |
| 211 | */ |
| 212 | unsigned int ath5k_hw_htoclock(struct ath5k_hw *ah, unsigned int usec) |
| 213 | { |
| 214 | return usec * ath5k_hw_get_clockrate(ah); |
| 215 | } |
| 216 | |
| 217 | /** |
| 218 | * ath5k_hw_clocktoh - Translate hw clock units to usec |
| 219 | * @clock: value in hw clock units |
| 220 | */ |
| 221 | unsigned int ath5k_hw_clocktoh(struct ath5k_hw *ah, unsigned int clock) |
| 222 | { |
| 223 | return clock / ath5k_hw_get_clockrate(ah); |
| 224 | } |
| 225 | |
| 226 | /** |
| 227 | * ath5k_hw_get_clockrate - Get the clock rate for current mode |
| 228 | * |
| 229 | * @ah: The &struct ath5k_hw |
| 230 | */ |
| 231 | unsigned int ath5k_hw_get_clockrate(struct ath5k_hw *ah) |
| 232 | { |
| 233 | struct ieee80211_channel *channel = ah->ah_current_channel; |
| 234 | int clock; |
| 235 | |
| 236 | if (channel->hw_value & CHANNEL_5GHZ) |
| 237 | clock = 40; /* 802.11a */ |
| 238 | else if (channel->hw_value & CHANNEL_CCK) |
| 239 | clock = 22; /* 802.11b */ |
| 240 | else |
| 241 | clock = 44; /* 802.11g */ |
| 242 | |
| 243 | /* Clock rate in turbo modes is twice the normal rate */ |
| 244 | if (channel->hw_value & CHANNEL_TURBO) |
| 245 | clock *= 2; |
| 246 | |
| 247 | return clock; |
| 248 | } |
| 249 | |
| 250 | /** |
Lukáš Turek | 6e08d22 | 2009-12-21 22:50:51 +0100 | [diff] [blame] | 251 | * ath5k_hw_get_default_slottime - Get the default slot time for current mode |
| 252 | * |
| 253 | * @ah: The &struct ath5k_hw |
| 254 | */ |
Pavel Roskin | 626ede6 | 2010-02-18 20:28:02 -0500 | [diff] [blame] | 255 | static unsigned int ath5k_hw_get_default_slottime(struct ath5k_hw *ah) |
Lukáš Turek | 6e08d22 | 2009-12-21 22:50:51 +0100 | [diff] [blame] | 256 | { |
| 257 | struct ieee80211_channel *channel = ah->ah_current_channel; |
| 258 | |
| 259 | if (channel->hw_value & CHANNEL_TURBO) |
| 260 | return 6; /* both turbo modes */ |
| 261 | |
| 262 | if (channel->hw_value & CHANNEL_CCK) |
| 263 | return 20; /* 802.11b */ |
| 264 | |
| 265 | return 9; /* 802.11 a/g */ |
| 266 | } |
| 267 | |
| 268 | /** |
| 269 | * ath5k_hw_get_default_sifs - Get the default SIFS for current mode |
| 270 | * |
| 271 | * @ah: The &struct ath5k_hw |
| 272 | */ |
Pavel Roskin | 626ede6 | 2010-02-18 20:28:02 -0500 | [diff] [blame] | 273 | static unsigned int ath5k_hw_get_default_sifs(struct ath5k_hw *ah) |
Lukáš Turek | 6e08d22 | 2009-12-21 22:50:51 +0100 | [diff] [blame] | 274 | { |
| 275 | struct ieee80211_channel *channel = ah->ah_current_channel; |
| 276 | |
| 277 | if (channel->hw_value & CHANNEL_TURBO) |
| 278 | return 8; /* both turbo modes */ |
| 279 | |
| 280 | if (channel->hw_value & CHANNEL_5GHZ) |
| 281 | return 16; /* 802.11a */ |
| 282 | |
| 283 | return 10; /* 802.11 b/g */ |
| 284 | } |
| 285 | |
| 286 | /** |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 287 | * ath5k_hw_set_lladdr - Set station id |
| 288 | * |
| 289 | * @ah: The &struct ath5k_hw |
| 290 | * @mac: The card's mac address |
| 291 | * |
| 292 | * Set station id on hw using the provided mac address |
| 293 | */ |
| 294 | int ath5k_hw_set_lladdr(struct ath5k_hw *ah, const u8 *mac) |
| 295 | { |
Luis R. Rodriguez | 954fece | 2009-09-10 10:51:33 -0700 | [diff] [blame] | 296 | struct ath_common *common = ath5k_hw_common(ah); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 297 | u32 low_id, high_id; |
Bob Copeland | f6bac3e | 2008-11-26 16:17:11 -0500 | [diff] [blame] | 298 | u32 pcu_reg; |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 299 | |
| 300 | ATH5K_TRACE(ah->ah_sc); |
| 301 | /* Set new station ID */ |
Luis R. Rodriguez | 954fece | 2009-09-10 10:51:33 -0700 | [diff] [blame] | 302 | memcpy(common->macaddr, mac, ETH_ALEN); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 303 | |
Bob Copeland | f6bac3e | 2008-11-26 16:17:11 -0500 | [diff] [blame] | 304 | pcu_reg = ath5k_hw_reg_read(ah, AR5K_STA_ID1) & 0xffff0000; |
| 305 | |
Luis R. Rodriguez | bcd8f54 | 2009-09-09 22:43:17 -0700 | [diff] [blame] | 306 | low_id = get_unaligned_le32(mac); |
| 307 | high_id = get_unaligned_le16(mac + 4); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 308 | |
| 309 | ath5k_hw_reg_write(ah, low_id, AR5K_STA_ID0); |
Bob Copeland | f6bac3e | 2008-11-26 16:17:11 -0500 | [diff] [blame] | 310 | ath5k_hw_reg_write(ah, pcu_reg | high_id, AR5K_STA_ID1); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 311 | |
| 312 | return 0; |
| 313 | } |
| 314 | |
| 315 | /** |
| 316 | * ath5k_hw_set_associd - Set BSSID for association |
| 317 | * |
| 318 | * @ah: The &struct ath5k_hw |
| 319 | * @bssid: BSSID |
| 320 | * @assoc_id: Assoc id |
| 321 | * |
| 322 | * Sets the BSSID which trigers the "SME Join" operation |
| 323 | */ |
Luis R. Rodriguez | be5d6b7 | 2009-10-06 20:44:31 -0400 | [diff] [blame] | 324 | void ath5k_hw_set_associd(struct ath5k_hw *ah) |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 325 | { |
Luis R. Rodriguez | 954fece | 2009-09-10 10:51:33 -0700 | [diff] [blame] | 326 | struct ath_common *common = ath5k_hw_common(ah); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 327 | u16 tim_offset = 0; |
| 328 | |
| 329 | /* |
| 330 | * Set simple BSSID mask on 5212 |
| 331 | */ |
Luis R. Rodriguez | a72d57a | 2009-10-06 20:44:29 -0400 | [diff] [blame] | 332 | if (ah->ah_version == AR5K_AR5212) |
| 333 | ath_hw_setbssidmask(common); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 334 | |
| 335 | /* |
| 336 | * Set BSSID which triggers the "SME Join" operation |
| 337 | */ |
Luis R. Rodriguez | abba068 | 2009-10-06 20:44:32 -0400 | [diff] [blame] | 338 | ath5k_hw_reg_write(ah, |
| 339 | get_unaligned_le32(common->curbssid), |
Luis R. Rodriguez | a3f86bf | 2009-10-06 20:44:33 -0400 | [diff] [blame] | 340 | AR5K_BSS_ID0); |
Luis R. Rodriguez | abba068 | 2009-10-06 20:44:32 -0400 | [diff] [blame] | 341 | ath5k_hw_reg_write(ah, |
| 342 | get_unaligned_le16(common->curbssid + 4) | |
| 343 | ((common->curaid & 0x3fff) << AR5K_BSS_ID1_AID_S), |
Luis R. Rodriguez | a3f86bf | 2009-10-06 20:44:33 -0400 | [diff] [blame] | 344 | AR5K_BSS_ID1); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 345 | |
Luis R. Rodriguez | be5d6b7 | 2009-10-06 20:44:31 -0400 | [diff] [blame] | 346 | if (common->curaid == 0) { |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 347 | ath5k_hw_disable_pspoll(ah); |
| 348 | return; |
| 349 | } |
| 350 | |
| 351 | AR5K_REG_WRITE_BITS(ah, AR5K_BEACON, AR5K_BEACON_TIM, |
Luis R. Rodriguez | abba068 | 2009-10-06 20:44:32 -0400 | [diff] [blame] | 352 | tim_offset ? tim_offset + 4 : 0); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 353 | |
| 354 | ath5k_hw_enable_pspoll(ah, NULL, 0); |
| 355 | } |
| 356 | |
Luis R. Rodriguez | 13b8155 | 2009-09-10 17:52:45 -0700 | [diff] [blame] | 357 | 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] | 358 | { |
Luis R. Rodriguez | 954fece | 2009-09-10 10:51:33 -0700 | [diff] [blame] | 359 | struct ath_common *common = ath5k_hw_common(ah); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 360 | ATH5K_TRACE(ah->ah_sc); |
| 361 | |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 362 | /* Cache bssid mask so that we can restore it |
| 363 | * on reset */ |
Luis R. Rodriguez | 954fece | 2009-09-10 10:51:33 -0700 | [diff] [blame] | 364 | memcpy(common->bssidmask, mask, ETH_ALEN); |
Luis R. Rodriguez | 13b8155 | 2009-09-10 17:52:45 -0700 | [diff] [blame] | 365 | if (ah->ah_version == AR5K_AR5212) |
| 366 | ath_hw_setbssidmask(common); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 367 | } |
| 368 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 369 | /************\ |
| 370 | * RX Control * |
| 371 | \************/ |
| 372 | |
| 373 | /** |
| 374 | * ath5k_hw_start_rx_pcu - Start RX engine |
| 375 | * |
| 376 | * @ah: The &struct ath5k_hw |
| 377 | * |
| 378 | * Starts RX engine on PCU so that hw can process RXed frames |
| 379 | * (ACK etc). |
| 380 | * |
| 381 | * NOTE: RX DMA should be already enabled using ath5k_hw_start_rx_dma |
| 382 | * TODO: Init ANI here |
| 383 | */ |
| 384 | void ath5k_hw_start_rx_pcu(struct ath5k_hw *ah) |
| 385 | { |
| 386 | ATH5K_TRACE(ah->ah_sc); |
| 387 | AR5K_REG_DISABLE_BITS(ah, AR5K_DIAG_SW, AR5K_DIAG_SW_DIS_RX); |
| 388 | } |
| 389 | |
| 390 | /** |
| 391 | * at5k_hw_stop_rx_pcu - Stop RX engine |
| 392 | * |
| 393 | * @ah: The &struct ath5k_hw |
| 394 | * |
| 395 | * Stops RX engine on PCU |
| 396 | * |
| 397 | * TODO: Detach ANI here |
| 398 | */ |
| 399 | void ath5k_hw_stop_rx_pcu(struct ath5k_hw *ah) |
| 400 | { |
| 401 | ATH5K_TRACE(ah->ah_sc); |
| 402 | AR5K_REG_ENABLE_BITS(ah, AR5K_DIAG_SW, AR5K_DIAG_SW_DIS_RX); |
| 403 | } |
| 404 | |
| 405 | /* |
| 406 | * Set multicast filter |
| 407 | */ |
| 408 | void ath5k_hw_set_mcast_filter(struct ath5k_hw *ah, u32 filter0, u32 filter1) |
| 409 | { |
| 410 | ATH5K_TRACE(ah->ah_sc); |
| 411 | /* Set the multicat filter */ |
| 412 | ath5k_hw_reg_write(ah, filter0, AR5K_MCAST_FILTER0); |
| 413 | ath5k_hw_reg_write(ah, filter1, AR5K_MCAST_FILTER1); |
| 414 | } |
| 415 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 416 | /** |
| 417 | * ath5k_hw_get_rx_filter - Get current rx filter |
| 418 | * |
| 419 | * @ah: The &struct ath5k_hw |
| 420 | * |
| 421 | * Returns the RX filter by reading rx filter and |
| 422 | * phy error filter registers. RX filter is used |
| 423 | * to set the allowed frame types that PCU will accept |
| 424 | * and pass to the driver. For a list of frame types |
| 425 | * check out reg.h. |
| 426 | */ |
| 427 | u32 ath5k_hw_get_rx_filter(struct ath5k_hw *ah) |
| 428 | { |
| 429 | u32 data, filter = 0; |
| 430 | |
| 431 | ATH5K_TRACE(ah->ah_sc); |
| 432 | filter = ath5k_hw_reg_read(ah, AR5K_RX_FILTER); |
| 433 | |
| 434 | /*Radar detection for 5212*/ |
| 435 | if (ah->ah_version == AR5K_AR5212) { |
| 436 | data = ath5k_hw_reg_read(ah, AR5K_PHY_ERR_FIL); |
| 437 | |
| 438 | if (data & AR5K_PHY_ERR_FIL_RADAR) |
| 439 | filter |= AR5K_RX_FILTER_RADARERR; |
| 440 | if (data & (AR5K_PHY_ERR_FIL_OFDM | AR5K_PHY_ERR_FIL_CCK)) |
| 441 | filter |= AR5K_RX_FILTER_PHYERR; |
| 442 | } |
| 443 | |
| 444 | return filter; |
| 445 | } |
| 446 | |
| 447 | /** |
| 448 | * ath5k_hw_set_rx_filter - Set rx filter |
| 449 | * |
| 450 | * @ah: The &struct ath5k_hw |
| 451 | * @filter: RX filter mask (see reg.h) |
| 452 | * |
| 453 | * Sets RX filter register and also handles PHY error filter |
| 454 | * register on 5212 and newer chips so that we have proper PHY |
| 455 | * error reporting. |
| 456 | */ |
| 457 | void ath5k_hw_set_rx_filter(struct ath5k_hw *ah, u32 filter) |
| 458 | { |
| 459 | u32 data = 0; |
| 460 | |
| 461 | ATH5K_TRACE(ah->ah_sc); |
| 462 | |
| 463 | /* Set PHY error filter register on 5212*/ |
| 464 | if (ah->ah_version == AR5K_AR5212) { |
| 465 | if (filter & AR5K_RX_FILTER_RADARERR) |
| 466 | data |= AR5K_PHY_ERR_FIL_RADAR; |
| 467 | if (filter & AR5K_RX_FILTER_PHYERR) |
| 468 | data |= AR5K_PHY_ERR_FIL_OFDM | AR5K_PHY_ERR_FIL_CCK; |
| 469 | } |
| 470 | |
| 471 | /* |
| 472 | * The AR5210 uses promiscous mode to detect radar activity |
| 473 | */ |
| 474 | if (ah->ah_version == AR5K_AR5210 && |
| 475 | (filter & AR5K_RX_FILTER_RADARERR)) { |
| 476 | filter &= ~AR5K_RX_FILTER_RADARERR; |
| 477 | filter |= AR5K_RX_FILTER_PROM; |
| 478 | } |
| 479 | |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 480 | /*Zero length DMA (phy error reporting) */ |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 481 | if (data) |
| 482 | AR5K_REG_ENABLE_BITS(ah, AR5K_RXCFG, AR5K_RXCFG_ZLFDMA); |
| 483 | else |
| 484 | AR5K_REG_DISABLE_BITS(ah, AR5K_RXCFG, AR5K_RXCFG_ZLFDMA); |
| 485 | |
| 486 | /*Write RX Filter register*/ |
| 487 | ath5k_hw_reg_write(ah, filter & 0xff, AR5K_RX_FILTER); |
| 488 | |
| 489 | /*Write PHY error filter register on 5212*/ |
| 490 | if (ah->ah_version == AR5K_AR5212) |
| 491 | ath5k_hw_reg_write(ah, data, AR5K_PHY_ERR_FIL); |
| 492 | |
| 493 | } |
| 494 | |
| 495 | |
| 496 | /****************\ |
| 497 | * Beacon control * |
| 498 | \****************/ |
| 499 | |
| 500 | /** |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 501 | * ath5k_hw_get_tsf64 - Get the full 64bit TSF |
| 502 | * |
| 503 | * @ah: The &struct ath5k_hw |
| 504 | * |
| 505 | * Returns the current TSF |
| 506 | */ |
| 507 | u64 ath5k_hw_get_tsf64(struct ath5k_hw *ah) |
| 508 | { |
| 509 | u64 tsf = ath5k_hw_reg_read(ah, AR5K_TSF_U32); |
| 510 | ATH5K_TRACE(ah->ah_sc); |
| 511 | |
| 512 | return ath5k_hw_reg_read(ah, AR5K_TSF_L32) | (tsf << 32); |
| 513 | } |
| 514 | |
| 515 | /** |
Alina Friedrichsen | 8cab758 | 2009-01-23 05:39:13 +0100 | [diff] [blame] | 516 | * ath5k_hw_set_tsf64 - Set a new 64bit TSF |
| 517 | * |
| 518 | * @ah: The &struct ath5k_hw |
| 519 | * @tsf64: The new 64bit TSF |
| 520 | * |
| 521 | * Sets the new TSF |
| 522 | */ |
| 523 | void ath5k_hw_set_tsf64(struct ath5k_hw *ah, u64 tsf64) |
| 524 | { |
| 525 | ATH5K_TRACE(ah->ah_sc); |
| 526 | |
Alina Friedrichsen | 8cab758 | 2009-01-23 05:39:13 +0100 | [diff] [blame] | 527 | ath5k_hw_reg_write(ah, tsf64 & 0xffffffff, AR5K_TSF_L32); |
Alina Friedrichsen | 0ad65bd | 2009-03-02 23:29:48 +0100 | [diff] [blame] | 528 | ath5k_hw_reg_write(ah, (tsf64 >> 32) & 0xffffffff, AR5K_TSF_U32); |
Alina Friedrichsen | 8cab758 | 2009-01-23 05:39:13 +0100 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | /** |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 532 | * ath5k_hw_reset_tsf - Force a TSF reset |
| 533 | * |
| 534 | * @ah: The &struct ath5k_hw |
| 535 | * |
| 536 | * Forces a TSF reset on PCU |
| 537 | */ |
| 538 | void ath5k_hw_reset_tsf(struct ath5k_hw *ah) |
| 539 | { |
Bob Copeland | 14be994 | 2008-09-28 12:09:43 -0400 | [diff] [blame] | 540 | u32 val; |
| 541 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 542 | ATH5K_TRACE(ah->ah_sc); |
Bob Copeland | 14be994 | 2008-09-28 12:09:43 -0400 | [diff] [blame] | 543 | |
| 544 | val = ath5k_hw_reg_read(ah, AR5K_BEACON) | AR5K_BEACON_RESET_TSF; |
| 545 | |
| 546 | /* |
| 547 | * Each write to the RESET_TSF bit toggles a hardware internal |
| 548 | * signal to reset TSF, but if left high it will cause a TSF reset |
| 549 | * on the next chip reset as well. Thus we always write the value |
| 550 | * twice to clear the signal. |
| 551 | */ |
| 552 | ath5k_hw_reg_write(ah, val, AR5K_BEACON); |
| 553 | ath5k_hw_reg_write(ah, val, AR5K_BEACON); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | /* |
| 557 | * Initialize beacon timers |
| 558 | */ |
| 559 | void ath5k_hw_init_beacon(struct ath5k_hw *ah, u32 next_beacon, u32 interval) |
| 560 | { |
| 561 | u32 timer1, timer2, timer3; |
| 562 | |
| 563 | ATH5K_TRACE(ah->ah_sc); |
| 564 | /* |
| 565 | * Set the additional timers by mode |
| 566 | */ |
Bruno Randolf | ccfe555 | 2010-03-09 16:55:38 +0900 | [diff] [blame] | 567 | switch (ah->ah_sc->opmode) { |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 568 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 569 | case NL80211_IFTYPE_STATION: |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 570 | /* In STA mode timer1 is used as next wakeup |
| 571 | * timer and timer2 as next CFP duration start |
| 572 | * timer. Both in 1/8TUs. */ |
| 573 | /* TODO: PCF handling */ |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 574 | if (ah->ah_version == AR5K_AR5210) { |
| 575 | timer1 = 0xffffffff; |
| 576 | timer2 = 0xffffffff; |
| 577 | } else { |
| 578 | timer1 = 0x0000ffff; |
| 579 | timer2 = 0x0007ffff; |
| 580 | } |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 581 | /* Mark associated AP as PCF incapable for now */ |
| 582 | AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1, AR5K_STA_ID1_PCF); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 583 | break; |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 584 | case NL80211_IFTYPE_ADHOC: |
| 585 | AR5K_REG_ENABLE_BITS(ah, AR5K_TXCFG, AR5K_TXCFG_ADHOC_BCN_ATIM); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 586 | default: |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 587 | /* On non-STA modes timer1 is used as next DMA |
| 588 | * beacon alert (DBA) timer and timer2 as next |
| 589 | * software beacon alert. Both in 1/8TUs. */ |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 590 | timer1 = (next_beacon - AR5K_TUNE_DMA_BEACON_RESP) << 3; |
| 591 | timer2 = (next_beacon - AR5K_TUNE_SW_BEACON_RESP) << 3; |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 592 | break; |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 593 | } |
| 594 | |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 595 | /* Timer3 marks the end of our ATIM window |
| 596 | * a zero length window is not allowed because |
| 597 | * we 'll get no beacons */ |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 598 | timer3 = next_beacon + (ah->ah_atim_window ? ah->ah_atim_window : 1); |
| 599 | |
| 600 | /* |
| 601 | * Set the beacon register and enable all timers. |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 602 | */ |
Nick Kossifidis | 35edf8a | 2009-06-12 16:09:53 -0700 | [diff] [blame] | 603 | /* When in AP or Mesh Point mode zero timer0 to start TSF */ |
Bruno Randolf | ccfe555 | 2010-03-09 16:55:38 +0900 | [diff] [blame] | 604 | if (ah->ah_sc->opmode == NL80211_IFTYPE_AP || |
| 605 | ah->ah_sc->opmode == NL80211_IFTYPE_MESH_POINT) |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 606 | ath5k_hw_reg_write(ah, 0, AR5K_TIMER0); |
Nick Kossifidis | 428cbd4 | 2009-04-30 15:55:47 -0400 | [diff] [blame] | 607 | |
| 608 | ath5k_hw_reg_write(ah, next_beacon, AR5K_TIMER0); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 609 | ath5k_hw_reg_write(ah, timer1, AR5K_TIMER1); |
| 610 | ath5k_hw_reg_write(ah, timer2, AR5K_TIMER2); |
| 611 | ath5k_hw_reg_write(ah, timer3, AR5K_TIMER3); |
| 612 | |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 613 | /* Force a TSF reset if requested and enable beacons */ |
| 614 | if (interval & AR5K_BEACON_RESET_TSF) |
| 615 | ath5k_hw_reset_tsf(ah); |
| 616 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 617 | ath5k_hw_reg_write(ah, interval & (AR5K_BEACON_PERIOD | |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 618 | AR5K_BEACON_ENABLE), |
| 619 | AR5K_BEACON); |
| 620 | |
| 621 | /* Flush any pending BMISS interrupts on ISR by |
| 622 | * performing a clear-on-write operation on PISR |
| 623 | * register for the BMISS bit (writing a bit on |
| 624 | * ISR togles a reset for that bit and leaves |
| 625 | * the rest bits intact) */ |
| 626 | if (ah->ah_version == AR5K_AR5210) |
| 627 | ath5k_hw_reg_write(ah, AR5K_ISR_BMISS, AR5K_ISR); |
| 628 | else |
| 629 | ath5k_hw_reg_write(ah, AR5K_ISR_BMISS, AR5K_PISR); |
| 630 | |
| 631 | /* TODO: Set enchanced sleep registers on AR5212 |
| 632 | * based on vif->bss_conf params, until then |
| 633 | * disable power save reporting.*/ |
| 634 | AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1, AR5K_STA_ID1_PWR_SV); |
| 635 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 636 | } |
| 637 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 638 | |
| 639 | /*********************\ |
| 640 | * Key table functions * |
| 641 | \*********************/ |
| 642 | |
| 643 | /* |
| 644 | * Reset a key entry on the table |
| 645 | */ |
| 646 | int ath5k_hw_reset_key(struct ath5k_hw *ah, u16 entry) |
| 647 | { |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 648 | unsigned int i, type; |
Bob Copeland | 17683c6 | 2008-10-29 23:24:26 -0400 | [diff] [blame] | 649 | u16 micentry = entry + AR5K_KEYTABLE_MIC_OFFSET; |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 650 | |
| 651 | ATH5K_TRACE(ah->ah_sc); |
| 652 | AR5K_ASSERT_ENTRY(entry, AR5K_KEYTABLE_SIZE); |
| 653 | |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 654 | type = ath5k_hw_reg_read(ah, AR5K_KEYTABLE_TYPE(entry)); |
| 655 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 656 | for (i = 0; i < AR5K_KEYCACHE_SIZE; i++) |
| 657 | ath5k_hw_reg_write(ah, 0, AR5K_KEYTABLE_OFF(entry, i)); |
| 658 | |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 659 | /* Reset associated MIC entry if TKIP |
| 660 | * is enabled located at offset (entry + 64) */ |
| 661 | if (type == AR5K_KEYTABLE_TYPE_TKIP) { |
Bob Copeland | 17683c6 | 2008-10-29 23:24:26 -0400 | [diff] [blame] | 662 | AR5K_ASSERT_ENTRY(micentry, AR5K_KEYTABLE_SIZE); |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 663 | for (i = 0; i < AR5K_KEYCACHE_SIZE / 2 ; i++) |
Bob Copeland | 17683c6 | 2008-10-29 23:24:26 -0400 | [diff] [blame] | 664 | ath5k_hw_reg_write(ah, 0, |
| 665 | AR5K_KEYTABLE_OFF(micentry, i)); |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 666 | } |
| 667 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 668 | /* |
| 669 | * Set NULL encryption on AR5212+ |
| 670 | * |
| 671 | * Note: AR5K_KEYTABLE_TYPE -> AR5K_KEYTABLE_OFF(entry, 5) |
| 672 | * AR5K_KEYTABLE_TYPE_NULL -> 0x00000007 |
| 673 | * |
| 674 | * Note2: Windows driver (ndiswrapper) sets this to |
| 675 | * 0x00000714 instead of 0x00000007 |
| 676 | */ |
Jiri Slaby | ded7a7e | 2009-04-25 14:09:23 +0200 | [diff] [blame] | 677 | if (ah->ah_version >= AR5K_AR5211) { |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 678 | ath5k_hw_reg_write(ah, AR5K_KEYTABLE_TYPE_NULL, |
| 679 | AR5K_KEYTABLE_TYPE(entry)); |
| 680 | |
Bob Copeland | 17683c6 | 2008-10-29 23:24:26 -0400 | [diff] [blame] | 681 | if (type == AR5K_KEYTABLE_TYPE_TKIP) { |
| 682 | ath5k_hw_reg_write(ah, AR5K_KEYTABLE_TYPE_NULL, |
| 683 | AR5K_KEYTABLE_TYPE(micentry)); |
| 684 | } |
| 685 | } |
| 686 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 687 | return 0; |
| 688 | } |
| 689 | |
Bob Copeland | 6714349 | 2008-11-25 20:55:21 -0500 | [diff] [blame] | 690 | static |
| 691 | int ath5k_keycache_type(const struct ieee80211_key_conf *key) |
| 692 | { |
| 693 | switch (key->alg) { |
| 694 | case ALG_TKIP: |
| 695 | return AR5K_KEYTABLE_TYPE_TKIP; |
| 696 | case ALG_CCMP: |
| 697 | return AR5K_KEYTABLE_TYPE_CCM; |
| 698 | case ALG_WEP: |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 699 | if (key->keylen == WLAN_KEY_LEN_WEP40) |
Bob Copeland | 6714349 | 2008-11-25 20:55:21 -0500 | [diff] [blame] | 700 | return AR5K_KEYTABLE_TYPE_40; |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 701 | else if (key->keylen == WLAN_KEY_LEN_WEP104) |
Bob Copeland | 6714349 | 2008-11-25 20:55:21 -0500 | [diff] [blame] | 702 | return AR5K_KEYTABLE_TYPE_104; |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 703 | return -EINVAL; |
| 704 | default: |
| 705 | return -EINVAL; |
Bob Copeland | 6714349 | 2008-11-25 20:55:21 -0500 | [diff] [blame] | 706 | } |
| 707 | return -EINVAL; |
| 708 | } |
| 709 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 710 | /* |
| 711 | * Set a key entry on the table |
| 712 | */ |
| 713 | int ath5k_hw_set_key(struct ath5k_hw *ah, u16 entry, |
| 714 | const struct ieee80211_key_conf *key, const u8 *mac) |
| 715 | { |
| 716 | unsigned int i; |
Bob Copeland | 3f64b43 | 2008-10-29 23:19:14 -0400 | [diff] [blame] | 717 | int keylen; |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 718 | __le32 key_v[5] = {}; |
Bob Copeland | 3f64b43 | 2008-10-29 23:19:14 -0400 | [diff] [blame] | 719 | __le32 key0 = 0, key1 = 0; |
| 720 | __le32 *rxmic, *txmic; |
Roel Kluin | 672cf3c | 2009-01-18 23:50:27 +0100 | [diff] [blame] | 721 | int keytype; |
Bob Copeland | 3f64b43 | 2008-10-29 23:19:14 -0400 | [diff] [blame] | 722 | u16 micentry = entry + AR5K_KEYTABLE_MIC_OFFSET; |
| 723 | bool is_tkip; |
Bob Copeland | 6714349 | 2008-11-25 20:55:21 -0500 | [diff] [blame] | 724 | const u8 *key_ptr; |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 725 | |
| 726 | ATH5K_TRACE(ah->ah_sc); |
| 727 | |
Bob Copeland | 3f64b43 | 2008-10-29 23:19:14 -0400 | [diff] [blame] | 728 | is_tkip = (key->alg == ALG_TKIP); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 729 | |
Bob Copeland | 3f64b43 | 2008-10-29 23:19:14 -0400 | [diff] [blame] | 730 | /* |
| 731 | * key->keylen comes in from mac80211 in bytes. |
| 732 | * TKIP is 128 bit + 128 bit mic |
| 733 | */ |
| 734 | keylen = (is_tkip) ? (128 / 8) : key->keylen; |
| 735 | |
| 736 | if (entry > AR5K_KEYTABLE_SIZE || |
| 737 | (is_tkip && micentry > AR5K_KEYTABLE_SIZE)) |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 738 | return -EOPNOTSUPP; |
| 739 | |
Bob Copeland | 6714349 | 2008-11-25 20:55:21 -0500 | [diff] [blame] | 740 | if (unlikely(keylen > 16)) |
| 741 | return -EOPNOTSUPP; |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 742 | |
Bob Copeland | 6714349 | 2008-11-25 20:55:21 -0500 | [diff] [blame] | 743 | keytype = ath5k_keycache_type(key); |
| 744 | if (keytype < 0) |
| 745 | return keytype; |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 746 | |
Bob Copeland | 6714349 | 2008-11-25 20:55:21 -0500 | [diff] [blame] | 747 | /* |
| 748 | * each key block is 6 bytes wide, written as pairs of |
| 749 | * alternating 32 and 16 bit le values. |
| 750 | */ |
| 751 | key_ptr = key->key; |
| 752 | for (i = 0; keylen >= 6; keylen -= 6) { |
| 753 | memcpy(&key_v[i], key_ptr, 6); |
| 754 | i += 2; |
| 755 | key_ptr += 6; |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 756 | } |
Bob Copeland | 6714349 | 2008-11-25 20:55:21 -0500 | [diff] [blame] | 757 | if (keylen) |
| 758 | memcpy(&key_v[i], key_ptr, keylen); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 759 | |
Bob Copeland | 3f64b43 | 2008-10-29 23:19:14 -0400 | [diff] [blame] | 760 | /* intentionally corrupt key until mic is installed */ |
| 761 | if (is_tkip) { |
| 762 | key0 = key_v[0] = ~key_v[0]; |
| 763 | key1 = key_v[1] = ~key_v[1]; |
| 764 | } |
| 765 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 766 | for (i = 0; i < ARRAY_SIZE(key_v); i++) |
| 767 | ath5k_hw_reg_write(ah, le32_to_cpu(key_v[i]), |
| 768 | AR5K_KEYTABLE_OFF(entry, i)); |
| 769 | |
| 770 | ath5k_hw_reg_write(ah, keytype, AR5K_KEYTABLE_TYPE(entry)); |
| 771 | |
Bob Copeland | 3f64b43 | 2008-10-29 23:19:14 -0400 | [diff] [blame] | 772 | if (is_tkip) { |
| 773 | /* Install rx/tx MIC */ |
| 774 | rxmic = (__le32 *) &key->key[16]; |
| 775 | txmic = (__le32 *) &key->key[24]; |
Bob Copeland | f650470 | 2008-11-26 16:17:25 -0500 | [diff] [blame] | 776 | |
| 777 | if (ah->ah_combined_mic) { |
| 778 | key_v[0] = rxmic[0]; |
Bob Copeland | 388cdf3 | 2008-12-09 23:05:38 -0500 | [diff] [blame] | 779 | key_v[1] = cpu_to_le32(le32_to_cpu(txmic[0]) >> 16); |
Bob Copeland | f650470 | 2008-11-26 16:17:25 -0500 | [diff] [blame] | 780 | key_v[2] = rxmic[1]; |
Bob Copeland | 388cdf3 | 2008-12-09 23:05:38 -0500 | [diff] [blame] | 781 | key_v[3] = cpu_to_le32(le32_to_cpu(txmic[0]) & 0xffff); |
Bob Copeland | f650470 | 2008-11-26 16:17:25 -0500 | [diff] [blame] | 782 | key_v[4] = txmic[1]; |
| 783 | } else { |
| 784 | key_v[0] = rxmic[0]; |
| 785 | key_v[1] = 0; |
| 786 | key_v[2] = rxmic[1]; |
| 787 | key_v[3] = 0; |
| 788 | key_v[4] = 0; |
| 789 | } |
Bob Copeland | 3f64b43 | 2008-10-29 23:19:14 -0400 | [diff] [blame] | 790 | for (i = 0; i < ARRAY_SIZE(key_v); i++) |
| 791 | ath5k_hw_reg_write(ah, le32_to_cpu(key_v[i]), |
| 792 | AR5K_KEYTABLE_OFF(micentry, i)); |
| 793 | |
| 794 | ath5k_hw_reg_write(ah, AR5K_KEYTABLE_TYPE_NULL, |
| 795 | AR5K_KEYTABLE_TYPE(micentry)); |
| 796 | ath5k_hw_reg_write(ah, 0, AR5K_KEYTABLE_MAC0(micentry)); |
| 797 | ath5k_hw_reg_write(ah, 0, AR5K_KEYTABLE_MAC1(micentry)); |
| 798 | |
| 799 | /* restore first 2 words of key */ |
| 800 | ath5k_hw_reg_write(ah, le32_to_cpu(~key0), |
| 801 | AR5K_KEYTABLE_OFF(entry, 0)); |
| 802 | ath5k_hw_reg_write(ah, le32_to_cpu(~key1), |
| 803 | AR5K_KEYTABLE_OFF(entry, 1)); |
| 804 | } |
| 805 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 806 | return ath5k_hw_set_key_lladdr(ah, entry, mac); |
| 807 | } |
| 808 | |
| 809 | int ath5k_hw_set_key_lladdr(struct ath5k_hw *ah, u16 entry, const u8 *mac) |
| 810 | { |
| 811 | u32 low_id, high_id; |
| 812 | |
| 813 | ATH5K_TRACE(ah->ah_sc); |
| 814 | /* Invalid entry (key table overflow) */ |
| 815 | AR5K_ASSERT_ENTRY(entry, AR5K_KEYTABLE_SIZE); |
| 816 | |
Luis R. Rodriguez | bcd8f54 | 2009-09-09 22:43:17 -0700 | [diff] [blame] | 817 | /* |
| 818 | * MAC may be NULL if it's a broadcast key. In this case no need to |
| 819 | * to compute get_unaligned_le32 and get_unaligned_le16 as we |
| 820 | * already know it. |
| 821 | */ |
Johannes Berg | dc822b5 | 2008-12-29 12:55:09 +0100 | [diff] [blame] | 822 | if (!mac) { |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 823 | low_id = 0xffffffff; |
| 824 | high_id = 0xffff | AR5K_KEYTABLE_VALID; |
| 825 | } else { |
Luis R. Rodriguez | bcd8f54 | 2009-09-09 22:43:17 -0700 | [diff] [blame] | 826 | low_id = get_unaligned_le32(mac); |
| 827 | high_id = get_unaligned_le16(mac + 4) | AR5K_KEYTABLE_VALID; |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | ath5k_hw_reg_write(ah, low_id, AR5K_KEYTABLE_MAC0(entry)); |
| 831 | ath5k_hw_reg_write(ah, high_id, AR5K_KEYTABLE_MAC1(entry)); |
| 832 | |
| 833 | return 0; |
| 834 | } |
| 835 | |
Lukáš Turek | 6e08d22 | 2009-12-21 22:50:51 +0100 | [diff] [blame] | 836 | /** |
| 837 | * ath5k_hw_set_coverage_class - Set IEEE 802.11 coverage class |
| 838 | * |
| 839 | * @ah: The &struct ath5k_hw |
| 840 | * @coverage_class: IEEE 802.11 coverage class number |
| 841 | * |
| 842 | * Sets slot time, ACK timeout and CTS timeout for given coverage class. |
| 843 | */ |
| 844 | void ath5k_hw_set_coverage_class(struct ath5k_hw *ah, u8 coverage_class) |
| 845 | { |
| 846 | /* As defined by IEEE 802.11-2007 17.3.8.6 */ |
| 847 | int slot_time = ath5k_hw_get_default_slottime(ah) + 3 * coverage_class; |
| 848 | int ack_timeout = ath5k_hw_get_default_sifs(ah) + slot_time; |
| 849 | int cts_timeout = ack_timeout; |
| 850 | |
| 851 | ath5k_hw_set_slot_time(ah, slot_time); |
| 852 | ath5k_hw_set_ack_timeout(ah, ack_timeout); |
| 853 | ath5k_hw_set_cts_timeout(ah, cts_timeout); |
| 854 | |
| 855 | ah->ah_coverage_class = coverage_class; |
| 856 | } |