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 | |
Bruno Randolf | ccfe555 | 2010-03-09 16:55:38 +0900 | [diff] [blame] | 62 | switch (op_mode) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 63 | case NL80211_IFTYPE_ADHOC: |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 64 | pcu_reg |= AR5K_STA_ID1_ADHOC | AR5K_STA_ID1_KEYSRCH_MODE; |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 65 | beacon_reg |= AR5K_BCR_ADHOC; |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 66 | if (ah->ah_version == AR5K_AR5210) |
| 67 | pcu_reg |= AR5K_STA_ID1_NO_PSPOLL; |
| 68 | else |
Steve Brown | 4fb7404 | 2008-12-23 07:57:05 -0500 | [diff] [blame] | 69 | AR5K_REG_ENABLE_BITS(ah, AR5K_CFG, AR5K_CFG_IBSS); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 70 | break; |
| 71 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 72 | case NL80211_IFTYPE_AP: |
| 73 | case NL80211_IFTYPE_MESH_POINT: |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 74 | pcu_reg |= AR5K_STA_ID1_AP | AR5K_STA_ID1_KEYSRCH_MODE; |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 75 | beacon_reg |= AR5K_BCR_AP; |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 76 | if (ah->ah_version == AR5K_AR5210) |
| 77 | pcu_reg |= AR5K_STA_ID1_NO_PSPOLL; |
| 78 | else |
Steve Brown | 4fb7404 | 2008-12-23 07:57:05 -0500 | [diff] [blame] | 79 | AR5K_REG_DISABLE_BITS(ah, AR5K_CFG, AR5K_CFG_IBSS); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 80 | break; |
| 81 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 82 | case NL80211_IFTYPE_STATION: |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 83 | pcu_reg |= AR5K_STA_ID1_KEYSRCH_MODE |
| 84 | | (ah->ah_version == AR5K_AR5210 ? |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 85 | AR5K_STA_ID1_PWR_SV : 0); |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 86 | case NL80211_IFTYPE_MONITOR: |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 87 | pcu_reg |= AR5K_STA_ID1_KEYSRCH_MODE |
| 88 | | (ah->ah_version == AR5K_AR5210 ? |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 89 | AR5K_STA_ID1_NO_PSPOLL : 0); |
| 90 | break; |
| 91 | |
| 92 | default: |
| 93 | return -EINVAL; |
| 94 | } |
| 95 | |
| 96 | /* |
| 97 | * Set PCU registers |
| 98 | */ |
Luis R. Rodriguez | 954fece | 2009-09-10 10:51:33 -0700 | [diff] [blame] | 99 | low_id = get_unaligned_le32(common->macaddr); |
| 100 | high_id = get_unaligned_le16(common->macaddr + 4); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 101 | ath5k_hw_reg_write(ah, low_id, AR5K_STA_ID0); |
| 102 | ath5k_hw_reg_write(ah, pcu_reg | high_id, AR5K_STA_ID1); |
| 103 | |
| 104 | /* |
| 105 | * Set Beacon Control Register on 5210 |
| 106 | */ |
| 107 | if (ah->ah_version == AR5K_AR5210) |
| 108 | ath5k_hw_reg_write(ah, beacon_reg, AR5K_BCR); |
| 109 | |
| 110 | return 0; |
| 111 | } |
| 112 | |
| 113 | /** |
Bruno Randolf | 495391d | 2010-03-25 14:49:36 +0900 | [diff] [blame] | 114 | * ath5k_hw_update - Update MIB counters (mac layer statistics) |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 115 | * |
| 116 | * @ah: The &struct ath5k_hw |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 117 | * |
Bruno Randolf | 495391d | 2010-03-25 14:49:36 +0900 | [diff] [blame] | 118 | * Reads MIB counters from PCU and updates sw statistics. Is called after a |
| 119 | * MIB interrupt, because one of these counters might have reached their maximum |
| 120 | * and triggered the MIB interrupt, to let us read and clear the counter. |
| 121 | * |
| 122 | * Is called in interrupt context! |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 123 | */ |
Bruno Randolf | 495391d | 2010-03-25 14:49:36 +0900 | [diff] [blame] | 124 | void ath5k_hw_update_mib_counters(struct ath5k_hw *ah) |
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 | struct ath5k_statistics *stats = &ah->ah_sc->stats; |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 127 | |
| 128 | /* Read-And-Clear */ |
Bruno Randolf | 495391d | 2010-03-25 14:49:36 +0900 | [diff] [blame] | 129 | stats->ack_fail += ath5k_hw_reg_read(ah, AR5K_ACK_FAIL); |
| 130 | stats->rts_fail += ath5k_hw_reg_read(ah, AR5K_RTS_FAIL); |
| 131 | stats->rts_ok += ath5k_hw_reg_read(ah, AR5K_RTS_OK); |
| 132 | stats->fcs_error += ath5k_hw_reg_read(ah, AR5K_FCS_FAIL); |
| 133 | stats->beacons += ath5k_hw_reg_read(ah, AR5K_BEACON_CNT); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | /** |
| 137 | * ath5k_hw_set_ack_bitrate - set bitrate for ACKs |
| 138 | * |
| 139 | * @ah: The &struct ath5k_hw |
Bob Copeland | 8801df8 | 2010-08-21 16:39:02 -0400 | [diff] [blame] | 140 | * @high: Flag to determine if we want to use high transmission rate |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 141 | * for ACKs or not |
| 142 | * |
| 143 | * If high flag is set, we tell hw to use a set of control rates based on |
Bob Copeland | 8801df8 | 2010-08-21 16:39:02 -0400 | [diff] [blame] | 144 | * the current transmission rate (check out control_rates array inside reset.c). |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 145 | * If not hw just uses the lowest rate available for the current modulation |
| 146 | * scheme being used (1Mbit for CCK and 6Mbits for OFDM). |
| 147 | */ |
| 148 | void ath5k_hw_set_ack_bitrate_high(struct ath5k_hw *ah, bool high) |
| 149 | { |
| 150 | if (ah->ah_version != AR5K_AR5212) |
| 151 | return; |
| 152 | else { |
| 153 | u32 val = AR5K_STA_ID1_BASE_RATE_11B | AR5K_STA_ID1_ACKCTS_6MB; |
| 154 | if (high) |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 155 | AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1, val); |
Bruno Randolf | 0edc9a6 | 2010-04-12 16:38:47 +0900 | [diff] [blame] | 156 | else |
| 157 | AR5K_REG_ENABLE_BITS(ah, AR5K_STA_ID1, val); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 158 | } |
| 159 | } |
| 160 | |
| 161 | |
| 162 | /******************\ |
| 163 | * ACK/CTS Timeouts * |
| 164 | \******************/ |
| 165 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 166 | /** |
| 167 | * ath5k_hw_set_ack_timeout - Set ACK timeout on PCU |
| 168 | * |
| 169 | * @ah: The &struct ath5k_hw |
| 170 | * @timeout: Timeout in usec |
| 171 | */ |
Pavel Roskin | 626ede6 | 2010-02-18 20:28:02 -0500 | [diff] [blame] | 172 | 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] | 173 | { |
Lukáš Turek | 3578e6e | 2009-12-21 22:50:50 +0100 | [diff] [blame] | 174 | if (ath5k_hw_clocktoh(ah, AR5K_REG_MS(0xffffffff, AR5K_TIME_OUT_ACK)) |
| 175 | <= timeout) |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 176 | return -EINVAL; |
| 177 | |
| 178 | AR5K_REG_WRITE_BITS(ah, AR5K_TIME_OUT, AR5K_TIME_OUT_ACK, |
Lukáš Turek | 3578e6e | 2009-12-21 22:50:50 +0100 | [diff] [blame] | 179 | ath5k_hw_htoclock(ah, timeout)); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 180 | |
| 181 | return 0; |
| 182 | } |
| 183 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 184 | /** |
| 185 | * ath5k_hw_set_cts_timeout - Set CTS timeout on PCU |
| 186 | * |
| 187 | * @ah: The &struct ath5k_hw |
| 188 | * @timeout: Timeout in usec |
| 189 | */ |
Pavel Roskin | 626ede6 | 2010-02-18 20:28:02 -0500 | [diff] [blame] | 190 | 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] | 191 | { |
Lukáš Turek | 3578e6e | 2009-12-21 22:50:50 +0100 | [diff] [blame] | 192 | if (ath5k_hw_clocktoh(ah, AR5K_REG_MS(0xffffffff, AR5K_TIME_OUT_CTS)) |
| 193 | <= timeout) |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 194 | return -EINVAL; |
| 195 | |
| 196 | AR5K_REG_WRITE_BITS(ah, AR5K_TIME_OUT, AR5K_TIME_OUT_CTS, |
Lukáš Turek | 3578e6e | 2009-12-21 22:50:50 +0100 | [diff] [blame] | 197 | ath5k_hw_htoclock(ah, timeout)); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 198 | |
| 199 | return 0; |
| 200 | } |
| 201 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 202 | /** |
Lukáš Turek | 3578e6e | 2009-12-21 22:50:50 +0100 | [diff] [blame] | 203 | * ath5k_hw_htoclock - Translate usec to hw clock units |
| 204 | * |
| 205 | * @ah: The &struct ath5k_hw |
| 206 | * @usec: value in microseconds |
| 207 | */ |
| 208 | unsigned int ath5k_hw_htoclock(struct ath5k_hw *ah, unsigned int usec) |
| 209 | { |
Felix Fietkau | 9d119f3 | 2010-10-08 22:13:52 +0200 | [diff] [blame] | 210 | struct ath_common *common = ath5k_hw_common(ah); |
| 211 | return usec * common->clockrate; |
Lukáš Turek | 3578e6e | 2009-12-21 22:50:50 +0100 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | /** |
| 215 | * ath5k_hw_clocktoh - Translate hw clock units to usec |
| 216 | * @clock: value in hw clock units |
| 217 | */ |
| 218 | unsigned int ath5k_hw_clocktoh(struct ath5k_hw *ah, unsigned int clock) |
| 219 | { |
Felix Fietkau | 9d119f3 | 2010-10-08 22:13:52 +0200 | [diff] [blame] | 220 | struct ath_common *common = ath5k_hw_common(ah); |
| 221 | return clock / common->clockrate; |
Lukáš Turek | 3578e6e | 2009-12-21 22:50:50 +0100 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | /** |
Felix Fietkau | 9d119f3 | 2010-10-08 22:13:52 +0200 | [diff] [blame] | 225 | * ath5k_hw_set_clockrate - Set common->clockrate for the current channel |
Lukáš Turek | 3578e6e | 2009-12-21 22:50:50 +0100 | [diff] [blame] | 226 | * |
| 227 | * @ah: The &struct ath5k_hw |
| 228 | */ |
Felix Fietkau | 9d119f3 | 2010-10-08 22:13:52 +0200 | [diff] [blame] | 229 | void ath5k_hw_set_clockrate(struct ath5k_hw *ah) |
Lukáš Turek | 3578e6e | 2009-12-21 22:50:50 +0100 | [diff] [blame] | 230 | { |
| 231 | struct ieee80211_channel *channel = ah->ah_current_channel; |
Felix Fietkau | 9d119f3 | 2010-10-08 22:13:52 +0200 | [diff] [blame] | 232 | struct ath_common *common = ath5k_hw_common(ah); |
Lukáš Turek | 3578e6e | 2009-12-21 22:50:50 +0100 | [diff] [blame] | 233 | int clock; |
| 234 | |
| 235 | if (channel->hw_value & CHANNEL_5GHZ) |
| 236 | clock = 40; /* 802.11a */ |
| 237 | else if (channel->hw_value & CHANNEL_CCK) |
| 238 | clock = 22; /* 802.11b */ |
| 239 | else |
| 240 | clock = 44; /* 802.11g */ |
| 241 | |
| 242 | /* Clock rate in turbo modes is twice the normal rate */ |
| 243 | if (channel->hw_value & CHANNEL_TURBO) |
| 244 | clock *= 2; |
| 245 | |
Felix Fietkau | 9d119f3 | 2010-10-08 22:13:52 +0200 | [diff] [blame] | 246 | common->clockrate = clock; |
Lukáš Turek | 3578e6e | 2009-12-21 22:50:50 +0100 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | /** |
Lukáš Turek | 6e08d22 | 2009-12-21 22:50:51 +0100 | [diff] [blame] | 250 | * ath5k_hw_get_default_slottime - Get the default slot time for current mode |
| 251 | * |
| 252 | * @ah: The &struct ath5k_hw |
| 253 | */ |
Pavel Roskin | 626ede6 | 2010-02-18 20:28:02 -0500 | [diff] [blame] | 254 | static unsigned int ath5k_hw_get_default_slottime(struct ath5k_hw *ah) |
Lukáš Turek | 6e08d22 | 2009-12-21 22:50:51 +0100 | [diff] [blame] | 255 | { |
| 256 | struct ieee80211_channel *channel = ah->ah_current_channel; |
| 257 | |
| 258 | if (channel->hw_value & CHANNEL_TURBO) |
| 259 | return 6; /* both turbo modes */ |
| 260 | |
| 261 | if (channel->hw_value & CHANNEL_CCK) |
| 262 | return 20; /* 802.11b */ |
| 263 | |
| 264 | return 9; /* 802.11 a/g */ |
| 265 | } |
| 266 | |
| 267 | /** |
| 268 | * ath5k_hw_get_default_sifs - Get the default SIFS for current mode |
| 269 | * |
| 270 | * @ah: The &struct ath5k_hw |
| 271 | */ |
Pavel Roskin | 626ede6 | 2010-02-18 20:28:02 -0500 | [diff] [blame] | 272 | static unsigned int ath5k_hw_get_default_sifs(struct ath5k_hw *ah) |
Lukáš Turek | 6e08d22 | 2009-12-21 22:50:51 +0100 | [diff] [blame] | 273 | { |
| 274 | struct ieee80211_channel *channel = ah->ah_current_channel; |
| 275 | |
| 276 | if (channel->hw_value & CHANNEL_TURBO) |
| 277 | return 8; /* both turbo modes */ |
| 278 | |
| 279 | if (channel->hw_value & CHANNEL_5GHZ) |
| 280 | return 16; /* 802.11a */ |
| 281 | |
| 282 | return 10; /* 802.11 b/g */ |
| 283 | } |
| 284 | |
| 285 | /** |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 286 | * ath5k_hw_set_lladdr - Set station id |
| 287 | * |
| 288 | * @ah: The &struct ath5k_hw |
| 289 | * @mac: The card's mac address |
| 290 | * |
| 291 | * Set station id on hw using the provided mac address |
| 292 | */ |
| 293 | int ath5k_hw_set_lladdr(struct ath5k_hw *ah, const u8 *mac) |
| 294 | { |
Luis R. Rodriguez | 954fece | 2009-09-10 10:51:33 -0700 | [diff] [blame] | 295 | struct ath_common *common = ath5k_hw_common(ah); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 296 | u32 low_id, high_id; |
Bob Copeland | f6bac3e | 2008-11-26 16:17:11 -0500 | [diff] [blame] | 297 | u32 pcu_reg; |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 298 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 299 | /* Set new station ID */ |
Luis R. Rodriguez | 954fece | 2009-09-10 10:51:33 -0700 | [diff] [blame] | 300 | memcpy(common->macaddr, mac, ETH_ALEN); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 301 | |
Bob Copeland | f6bac3e | 2008-11-26 16:17:11 -0500 | [diff] [blame] | 302 | pcu_reg = ath5k_hw_reg_read(ah, AR5K_STA_ID1) & 0xffff0000; |
| 303 | |
Luis R. Rodriguez | bcd8f54 | 2009-09-09 22:43:17 -0700 | [diff] [blame] | 304 | low_id = get_unaligned_le32(mac); |
| 305 | high_id = get_unaligned_le16(mac + 4); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 306 | |
| 307 | ath5k_hw_reg_write(ah, low_id, AR5K_STA_ID0); |
Bob Copeland | f6bac3e | 2008-11-26 16:17:11 -0500 | [diff] [blame] | 308 | ath5k_hw_reg_write(ah, pcu_reg | high_id, AR5K_STA_ID1); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 309 | |
| 310 | return 0; |
| 311 | } |
| 312 | |
| 313 | /** |
Nick Kossifidis | 418de6d | 2010-08-15 13:03:10 -0400 | [diff] [blame] | 314 | * ath5k_hw_set_bssid - Set current BSSID on hw |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 315 | * |
| 316 | * @ah: The &struct ath5k_hw |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 317 | * |
Nick Kossifidis | 418de6d | 2010-08-15 13:03:10 -0400 | [diff] [blame] | 318 | * Sets the current BSSID and BSSID mask we have from the |
| 319 | * common struct into the hardware |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 320 | */ |
Nick Kossifidis | 418de6d | 2010-08-15 13:03:10 -0400 | [diff] [blame] | 321 | void ath5k_hw_set_bssid(struct ath5k_hw *ah) |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 322 | { |
Luis R. Rodriguez | 954fece | 2009-09-10 10:51:33 -0700 | [diff] [blame] | 323 | struct ath_common *common = ath5k_hw_common(ah); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 324 | u16 tim_offset = 0; |
| 325 | |
| 326 | /* |
Nick Kossifidis | 418de6d | 2010-08-15 13:03:10 -0400 | [diff] [blame] | 327 | * Set BSSID mask on 5212 |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 328 | */ |
Luis R. Rodriguez | a72d57a | 2009-10-06 20:44:29 -0400 | [diff] [blame] | 329 | if (ah->ah_version == AR5K_AR5212) |
| 330 | ath_hw_setbssidmask(common); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 331 | |
| 332 | /* |
Nick Kossifidis | 418de6d | 2010-08-15 13:03:10 -0400 | [diff] [blame] | 333 | * Set BSSID |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 334 | */ |
Luis R. Rodriguez | abba068 | 2009-10-06 20:44:32 -0400 | [diff] [blame] | 335 | ath5k_hw_reg_write(ah, |
| 336 | get_unaligned_le32(common->curbssid), |
Luis R. Rodriguez | a3f86bf | 2009-10-06 20:44:33 -0400 | [diff] [blame] | 337 | AR5K_BSS_ID0); |
Luis R. Rodriguez | abba068 | 2009-10-06 20:44:32 -0400 | [diff] [blame] | 338 | ath5k_hw_reg_write(ah, |
| 339 | get_unaligned_le16(common->curbssid + 4) | |
| 340 | ((common->curaid & 0x3fff) << AR5K_BSS_ID1_AID_S), |
Luis R. Rodriguez | a3f86bf | 2009-10-06 20:44:33 -0400 | [diff] [blame] | 341 | AR5K_BSS_ID1); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 342 | |
Luis R. Rodriguez | be5d6b7 | 2009-10-06 20:44:31 -0400 | [diff] [blame] | 343 | if (common->curaid == 0) { |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 344 | ath5k_hw_disable_pspoll(ah); |
| 345 | return; |
| 346 | } |
| 347 | |
| 348 | AR5K_REG_WRITE_BITS(ah, AR5K_BEACON, AR5K_BEACON_TIM, |
Luis R. Rodriguez | abba068 | 2009-10-06 20:44:32 -0400 | [diff] [blame] | 349 | tim_offset ? tim_offset + 4 : 0); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 350 | |
| 351 | ath5k_hw_enable_pspoll(ah, NULL, 0); |
| 352 | } |
| 353 | |
Luis R. Rodriguez | 13b8155 | 2009-09-10 17:52:45 -0700 | [diff] [blame] | 354 | 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] | 355 | { |
Luis R. Rodriguez | 954fece | 2009-09-10 10:51:33 -0700 | [diff] [blame] | 356 | struct ath_common *common = ath5k_hw_common(ah); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 357 | |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 358 | /* Cache bssid mask so that we can restore it |
| 359 | * on reset */ |
Luis R. Rodriguez | 954fece | 2009-09-10 10:51:33 -0700 | [diff] [blame] | 360 | memcpy(common->bssidmask, mask, ETH_ALEN); |
Luis R. Rodriguez | 13b8155 | 2009-09-10 17:52:45 -0700 | [diff] [blame] | 361 | if (ah->ah_version == AR5K_AR5212) |
| 362 | ath_hw_setbssidmask(common); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 363 | } |
| 364 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 365 | /************\ |
| 366 | * RX Control * |
| 367 | \************/ |
| 368 | |
| 369 | /** |
| 370 | * ath5k_hw_start_rx_pcu - Start RX engine |
| 371 | * |
| 372 | * @ah: The &struct ath5k_hw |
| 373 | * |
| 374 | * Starts RX engine on PCU so that hw can process RXed frames |
| 375 | * (ACK etc). |
| 376 | * |
| 377 | * NOTE: RX DMA should be already enabled using ath5k_hw_start_rx_dma |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 378 | */ |
| 379 | void ath5k_hw_start_rx_pcu(struct ath5k_hw *ah) |
| 380 | { |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 381 | AR5K_REG_DISABLE_BITS(ah, AR5K_DIAG_SW, AR5K_DIAG_SW_DIS_RX); |
| 382 | } |
| 383 | |
| 384 | /** |
| 385 | * at5k_hw_stop_rx_pcu - Stop RX engine |
| 386 | * |
| 387 | * @ah: The &struct ath5k_hw |
| 388 | * |
| 389 | * Stops RX engine on PCU |
| 390 | * |
| 391 | * TODO: Detach ANI here |
| 392 | */ |
| 393 | void ath5k_hw_stop_rx_pcu(struct ath5k_hw *ah) |
| 394 | { |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 395 | AR5K_REG_ENABLE_BITS(ah, AR5K_DIAG_SW, AR5K_DIAG_SW_DIS_RX); |
| 396 | } |
| 397 | |
| 398 | /* |
| 399 | * Set multicast filter |
| 400 | */ |
| 401 | void ath5k_hw_set_mcast_filter(struct ath5k_hw *ah, u32 filter0, u32 filter1) |
| 402 | { |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 403 | ath5k_hw_reg_write(ah, filter0, AR5K_MCAST_FILTER0); |
| 404 | ath5k_hw_reg_write(ah, filter1, AR5K_MCAST_FILTER1); |
| 405 | } |
| 406 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 407 | /** |
| 408 | * ath5k_hw_get_rx_filter - Get current rx filter |
| 409 | * |
| 410 | * @ah: The &struct ath5k_hw |
| 411 | * |
| 412 | * Returns the RX filter by reading rx filter and |
| 413 | * phy error filter registers. RX filter is used |
| 414 | * to set the allowed frame types that PCU will accept |
| 415 | * and pass to the driver. For a list of frame types |
| 416 | * check out reg.h. |
| 417 | */ |
| 418 | u32 ath5k_hw_get_rx_filter(struct ath5k_hw *ah) |
| 419 | { |
| 420 | u32 data, filter = 0; |
| 421 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 422 | filter = ath5k_hw_reg_read(ah, AR5K_RX_FILTER); |
| 423 | |
| 424 | /*Radar detection for 5212*/ |
| 425 | if (ah->ah_version == AR5K_AR5212) { |
| 426 | data = ath5k_hw_reg_read(ah, AR5K_PHY_ERR_FIL); |
| 427 | |
| 428 | if (data & AR5K_PHY_ERR_FIL_RADAR) |
| 429 | filter |= AR5K_RX_FILTER_RADARERR; |
| 430 | if (data & (AR5K_PHY_ERR_FIL_OFDM | AR5K_PHY_ERR_FIL_CCK)) |
| 431 | filter |= AR5K_RX_FILTER_PHYERR; |
| 432 | } |
| 433 | |
| 434 | return filter; |
| 435 | } |
| 436 | |
| 437 | /** |
| 438 | * ath5k_hw_set_rx_filter - Set rx filter |
| 439 | * |
| 440 | * @ah: The &struct ath5k_hw |
| 441 | * @filter: RX filter mask (see reg.h) |
| 442 | * |
| 443 | * Sets RX filter register and also handles PHY error filter |
| 444 | * register on 5212 and newer chips so that we have proper PHY |
| 445 | * error reporting. |
| 446 | */ |
| 447 | void ath5k_hw_set_rx_filter(struct ath5k_hw *ah, u32 filter) |
| 448 | { |
| 449 | u32 data = 0; |
| 450 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 451 | /* Set PHY error filter register on 5212*/ |
| 452 | if (ah->ah_version == AR5K_AR5212) { |
| 453 | if (filter & AR5K_RX_FILTER_RADARERR) |
| 454 | data |= AR5K_PHY_ERR_FIL_RADAR; |
| 455 | if (filter & AR5K_RX_FILTER_PHYERR) |
| 456 | data |= AR5K_PHY_ERR_FIL_OFDM | AR5K_PHY_ERR_FIL_CCK; |
| 457 | } |
| 458 | |
| 459 | /* |
| 460 | * The AR5210 uses promiscous mode to detect radar activity |
| 461 | */ |
| 462 | if (ah->ah_version == AR5K_AR5210 && |
| 463 | (filter & AR5K_RX_FILTER_RADARERR)) { |
| 464 | filter &= ~AR5K_RX_FILTER_RADARERR; |
| 465 | filter |= AR5K_RX_FILTER_PROM; |
| 466 | } |
| 467 | |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 468 | /*Zero length DMA (phy error reporting) */ |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 469 | if (data) |
| 470 | AR5K_REG_ENABLE_BITS(ah, AR5K_RXCFG, AR5K_RXCFG_ZLFDMA); |
| 471 | else |
| 472 | AR5K_REG_DISABLE_BITS(ah, AR5K_RXCFG, AR5K_RXCFG_ZLFDMA); |
| 473 | |
| 474 | /*Write RX Filter register*/ |
| 475 | ath5k_hw_reg_write(ah, filter & 0xff, AR5K_RX_FILTER); |
| 476 | |
| 477 | /*Write PHY error filter register on 5212*/ |
| 478 | if (ah->ah_version == AR5K_AR5212) |
| 479 | ath5k_hw_reg_write(ah, data, AR5K_PHY_ERR_FIL); |
| 480 | |
| 481 | } |
| 482 | |
| 483 | |
| 484 | /****************\ |
| 485 | * Beacon control * |
| 486 | \****************/ |
| 487 | |
Benoit Papillault | 1c0fc65 | 2010-04-16 00:07:26 +0200 | [diff] [blame] | 488 | #define ATH5K_MAX_TSF_READ 10 |
| 489 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 490 | /** |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 491 | * ath5k_hw_get_tsf64 - Get the full 64bit TSF |
| 492 | * |
| 493 | * @ah: The &struct ath5k_hw |
| 494 | * |
| 495 | * Returns the current TSF |
| 496 | */ |
| 497 | u64 ath5k_hw_get_tsf64(struct ath5k_hw *ah) |
| 498 | { |
Benoit Papillault | 1c0fc65 | 2010-04-16 00:07:26 +0200 | [diff] [blame] | 499 | u32 tsf_lower, tsf_upper1, tsf_upper2; |
| 500 | int i; |
Bruno Randolf | 28df897 | 2010-09-27 12:22:32 +0900 | [diff] [blame] | 501 | unsigned long flags; |
| 502 | |
| 503 | /* This code is time critical - we don't want to be interrupted here */ |
| 504 | local_irq_save(flags); |
Benoit Papillault | 1c0fc65 | 2010-04-16 00:07:26 +0200 | [diff] [blame] | 505 | |
| 506 | /* |
| 507 | * While reading TSF upper and then lower part, the clock is still |
| 508 | * counting (or jumping in case of IBSS merge) so we might get |
| 509 | * inconsistent values. To avoid this, we read the upper part again |
| 510 | * and check it has not been changed. We make the hypothesis that a |
| 511 | * maximum of 3 changes can happens in a row (we use 10 as a safe |
| 512 | * value). |
| 513 | * |
| 514 | * Impact on performance is pretty small, since in most cases, only |
| 515 | * 3 register reads are needed. |
| 516 | */ |
| 517 | |
| 518 | tsf_upper1 = ath5k_hw_reg_read(ah, AR5K_TSF_U32); |
| 519 | for (i = 0; i < ATH5K_MAX_TSF_READ; i++) { |
| 520 | tsf_lower = ath5k_hw_reg_read(ah, AR5K_TSF_L32); |
| 521 | tsf_upper2 = ath5k_hw_reg_read(ah, AR5K_TSF_U32); |
| 522 | if (tsf_upper2 == tsf_upper1) |
| 523 | break; |
| 524 | tsf_upper1 = tsf_upper2; |
| 525 | } |
| 526 | |
Bruno Randolf | 28df897 | 2010-09-27 12:22:32 +0900 | [diff] [blame] | 527 | local_irq_restore(flags); |
| 528 | |
Benoit Papillault | 1c0fc65 | 2010-04-16 00:07:26 +0200 | [diff] [blame] | 529 | WARN_ON( i == ATH5K_MAX_TSF_READ ); |
| 530 | |
Benoit Papillault | 1c0fc65 | 2010-04-16 00:07:26 +0200 | [diff] [blame] | 531 | return (((u64)tsf_upper1 << 32) | tsf_lower); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | /** |
Alina Friedrichsen | 8cab758 | 2009-01-23 05:39:13 +0100 | [diff] [blame] | 535 | * ath5k_hw_set_tsf64 - Set a new 64bit TSF |
| 536 | * |
| 537 | * @ah: The &struct ath5k_hw |
| 538 | * @tsf64: The new 64bit TSF |
| 539 | * |
| 540 | * Sets the new TSF |
| 541 | */ |
| 542 | void ath5k_hw_set_tsf64(struct ath5k_hw *ah, u64 tsf64) |
| 543 | { |
Alina Friedrichsen | 8cab758 | 2009-01-23 05:39:13 +0100 | [diff] [blame] | 544 | ath5k_hw_reg_write(ah, tsf64 & 0xffffffff, AR5K_TSF_L32); |
Alina Friedrichsen | 0ad65bd | 2009-03-02 23:29:48 +0100 | [diff] [blame] | 545 | ath5k_hw_reg_write(ah, (tsf64 >> 32) & 0xffffffff, AR5K_TSF_U32); |
Alina Friedrichsen | 8cab758 | 2009-01-23 05:39:13 +0100 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | /** |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 549 | * ath5k_hw_reset_tsf - Force a TSF reset |
| 550 | * |
| 551 | * @ah: The &struct ath5k_hw |
| 552 | * |
| 553 | * Forces a TSF reset on PCU |
| 554 | */ |
| 555 | void ath5k_hw_reset_tsf(struct ath5k_hw *ah) |
| 556 | { |
Bob Copeland | 14be994 | 2008-09-28 12:09:43 -0400 | [diff] [blame] | 557 | u32 val; |
| 558 | |
Bob Copeland | 14be994 | 2008-09-28 12:09:43 -0400 | [diff] [blame] | 559 | val = ath5k_hw_reg_read(ah, AR5K_BEACON) | AR5K_BEACON_RESET_TSF; |
| 560 | |
| 561 | /* |
| 562 | * Each write to the RESET_TSF bit toggles a hardware internal |
| 563 | * signal to reset TSF, but if left high it will cause a TSF reset |
| 564 | * on the next chip reset as well. Thus we always write the value |
| 565 | * twice to clear the signal. |
| 566 | */ |
| 567 | ath5k_hw_reg_write(ah, val, AR5K_BEACON); |
| 568 | ath5k_hw_reg_write(ah, val, AR5K_BEACON); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | /* |
| 572 | * Initialize beacon timers |
| 573 | */ |
| 574 | void ath5k_hw_init_beacon(struct ath5k_hw *ah, u32 next_beacon, u32 interval) |
| 575 | { |
| 576 | u32 timer1, timer2, timer3; |
| 577 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 578 | /* |
| 579 | * Set the additional timers by mode |
| 580 | */ |
Bruno Randolf | ccfe555 | 2010-03-09 16:55:38 +0900 | [diff] [blame] | 581 | switch (ah->ah_sc->opmode) { |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 582 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 583 | case NL80211_IFTYPE_STATION: |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 584 | /* In STA mode timer1 is used as next wakeup |
| 585 | * timer and timer2 as next CFP duration start |
| 586 | * timer. Both in 1/8TUs. */ |
| 587 | /* TODO: PCF handling */ |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 588 | if (ah->ah_version == AR5K_AR5210) { |
| 589 | timer1 = 0xffffffff; |
| 590 | timer2 = 0xffffffff; |
| 591 | } else { |
| 592 | timer1 = 0x0000ffff; |
| 593 | timer2 = 0x0007ffff; |
| 594 | } |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 595 | /* Mark associated AP as PCF incapable for now */ |
| 596 | AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1, AR5K_STA_ID1_PCF); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 597 | break; |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 598 | case NL80211_IFTYPE_ADHOC: |
| 599 | AR5K_REG_ENABLE_BITS(ah, AR5K_TXCFG, AR5K_TXCFG_ADHOC_BCN_ATIM); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 600 | default: |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 601 | /* On non-STA modes timer1 is used as next DMA |
| 602 | * beacon alert (DBA) timer and timer2 as next |
| 603 | * software beacon alert. Both in 1/8TUs. */ |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 604 | timer1 = (next_beacon - AR5K_TUNE_DMA_BEACON_RESP) << 3; |
| 605 | timer2 = (next_beacon - AR5K_TUNE_SW_BEACON_RESP) << 3; |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 606 | break; |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 607 | } |
| 608 | |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 609 | /* Timer3 marks the end of our ATIM window |
| 610 | * a zero length window is not allowed because |
| 611 | * we 'll get no beacons */ |
Bruno Randolf | 4a79f2c | 2010-09-27 12:22:16 +0900 | [diff] [blame] | 612 | timer3 = next_beacon + 1; |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 613 | |
| 614 | /* |
| 615 | * Set the beacon register and enable all timers. |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 616 | */ |
Nick Kossifidis | 35edf8a | 2009-06-12 16:09:53 -0700 | [diff] [blame] | 617 | /* When in AP or Mesh Point mode zero timer0 to start TSF */ |
Bruno Randolf | ccfe555 | 2010-03-09 16:55:38 +0900 | [diff] [blame] | 618 | if (ah->ah_sc->opmode == NL80211_IFTYPE_AP || |
| 619 | ah->ah_sc->opmode == NL80211_IFTYPE_MESH_POINT) |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 620 | ath5k_hw_reg_write(ah, 0, AR5K_TIMER0); |
Nick Kossifidis | 428cbd4 | 2009-04-30 15:55:47 -0400 | [diff] [blame] | 621 | |
| 622 | ath5k_hw_reg_write(ah, next_beacon, AR5K_TIMER0); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 623 | ath5k_hw_reg_write(ah, timer1, AR5K_TIMER1); |
| 624 | ath5k_hw_reg_write(ah, timer2, AR5K_TIMER2); |
| 625 | ath5k_hw_reg_write(ah, timer3, AR5K_TIMER3); |
| 626 | |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 627 | /* Force a TSF reset if requested and enable beacons */ |
| 628 | if (interval & AR5K_BEACON_RESET_TSF) |
| 629 | ath5k_hw_reset_tsf(ah); |
| 630 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 631 | ath5k_hw_reg_write(ah, interval & (AR5K_BEACON_PERIOD | |
Nick Kossifidis | f07a6c4 | 2008-10-29 04:28:28 +0200 | [diff] [blame] | 632 | AR5K_BEACON_ENABLE), |
| 633 | AR5K_BEACON); |
| 634 | |
| 635 | /* Flush any pending BMISS interrupts on ISR by |
| 636 | * performing a clear-on-write operation on PISR |
| 637 | * register for the BMISS bit (writing a bit on |
| 638 | * ISR togles a reset for that bit and leaves |
| 639 | * the rest bits intact) */ |
| 640 | if (ah->ah_version == AR5K_AR5210) |
| 641 | ath5k_hw_reg_write(ah, AR5K_ISR_BMISS, AR5K_ISR); |
| 642 | else |
| 643 | ath5k_hw_reg_write(ah, AR5K_ISR_BMISS, AR5K_PISR); |
| 644 | |
| 645 | /* TODO: Set enchanced sleep registers on AR5212 |
| 646 | * based on vif->bss_conf params, until then |
| 647 | * disable power save reporting.*/ |
| 648 | AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1, AR5K_STA_ID1_PWR_SV); |
| 649 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 650 | } |
| 651 | |
Lukáš Turek | 6e08d22 | 2009-12-21 22:50:51 +0100 | [diff] [blame] | 652 | /** |
Bruno Randolf | 7f89612 | 2010-09-27 12:22:21 +0900 | [diff] [blame] | 653 | * ath5k_check_timer_win - Check if timer B is timer A + window |
| 654 | * |
| 655 | * @a: timer a (before b) |
| 656 | * @b: timer b (after a) |
| 657 | * @window: difference between a and b |
| 658 | * @intval: timers are increased by this interval |
| 659 | * |
| 660 | * This helper function checks if timer B is timer A + window and covers |
| 661 | * cases where timer A or B might have already been updated or wrapped |
| 662 | * around (Timers are 16 bit). |
| 663 | * |
| 664 | * Returns true if O.K. |
| 665 | */ |
| 666 | static inline bool |
| 667 | ath5k_check_timer_win(int a, int b, int window, int intval) |
| 668 | { |
| 669 | /* |
| 670 | * 1.) usually B should be A + window |
| 671 | * 2.) A already updated, B not updated yet |
| 672 | * 3.) A already updated and has wrapped around |
| 673 | * 4.) B has wrapped around |
| 674 | */ |
| 675 | if ((b - a == window) || /* 1.) */ |
| 676 | (a - b == intval - window) || /* 2.) */ |
| 677 | ((a | 0x10000) - b == intval - window) || /* 3.) */ |
| 678 | ((b | 0x10000) - a == window)) /* 4.) */ |
| 679 | return true; /* O.K. */ |
| 680 | return false; |
| 681 | } |
| 682 | |
| 683 | /** |
| 684 | * ath5k_hw_check_beacon_timers - Check if the beacon timers are correct |
| 685 | * |
| 686 | * @ah: The &struct ath5k_hw |
| 687 | * @intval: beacon interval |
| 688 | * |
| 689 | * This is a workaround for IBSS mode: |
| 690 | * |
| 691 | * The need for this function arises from the fact that we have 4 separate |
| 692 | * HW timer registers (TIMER0 - TIMER3), which are closely related to the |
| 693 | * next beacon target time (NBTT), and that the HW updates these timers |
| 694 | * seperately based on the current TSF value. The hardware increments each |
| 695 | * timer by the beacon interval, when the local TSF coverted to TU is equal |
| 696 | * to the value stored in the timer. |
| 697 | * |
| 698 | * The reception of a beacon with the same BSSID can update the local HW TSF |
| 699 | * at any time - this is something we can't avoid. If the TSF jumps to a |
| 700 | * time which is later than the time stored in a timer, this timer will not |
| 701 | * be updated until the TSF in TU wraps around at 16 bit (the size of the |
| 702 | * timers) and reaches the time which is stored in the timer. |
| 703 | * |
| 704 | * The problem is that these timers are closely related to TIMER0 (NBTT) and |
| 705 | * that they define a time "window". When the TSF jumps between two timers |
| 706 | * (e.g. ATIM and NBTT), the one in the past will be left behind (not |
| 707 | * updated), while the one in the future will be updated every beacon |
| 708 | * interval. This causes the window to get larger, until the TSF wraps |
| 709 | * around as described above and the timer which was left behind gets |
| 710 | * updated again. But - because the beacon interval is usually not an exact |
| 711 | * divisor of the size of the timers (16 bit), an unwanted "window" between |
| 712 | * these timers has developed! |
| 713 | * |
| 714 | * This is especially important with the ATIM window, because during |
| 715 | * the ATIM window only ATIM frames and no data frames are allowed to be |
| 716 | * sent, which creates transmission pauses after each beacon. This symptom |
| 717 | * has been described as "ramping ping" because ping times increase linearly |
| 718 | * for some time and then drop down again. A wrong window on the DMA beacon |
| 719 | * timer has the same effect, so we check for these two conditions. |
| 720 | * |
| 721 | * Returns true if O.K. |
| 722 | */ |
| 723 | bool |
| 724 | ath5k_hw_check_beacon_timers(struct ath5k_hw *ah, int intval) |
| 725 | { |
| 726 | unsigned int nbtt, atim, dma; |
| 727 | |
| 728 | nbtt = ath5k_hw_reg_read(ah, AR5K_TIMER0); |
| 729 | atim = ath5k_hw_reg_read(ah, AR5K_TIMER3); |
| 730 | dma = ath5k_hw_reg_read(ah, AR5K_TIMER1) >> 3; |
| 731 | |
| 732 | /* NOTE: SWBA is different. Having a wrong window there does not |
| 733 | * stop us from sending data and this condition is catched thru |
| 734 | * other means (SWBA interrupt) */ |
| 735 | |
| 736 | if (ath5k_check_timer_win(nbtt, atim, 1, intval) && |
| 737 | ath5k_check_timer_win(dma, nbtt, AR5K_TUNE_DMA_BEACON_RESP, |
| 738 | intval)) |
| 739 | return true; /* O.K. */ |
| 740 | return false; |
| 741 | } |
| 742 | |
| 743 | /** |
Lukáš Turek | 6e08d22 | 2009-12-21 22:50:51 +0100 | [diff] [blame] | 744 | * ath5k_hw_set_coverage_class - Set IEEE 802.11 coverage class |
| 745 | * |
| 746 | * @ah: The &struct ath5k_hw |
| 747 | * @coverage_class: IEEE 802.11 coverage class number |
| 748 | * |
| 749 | * Sets slot time, ACK timeout and CTS timeout for given coverage class. |
| 750 | */ |
| 751 | void ath5k_hw_set_coverage_class(struct ath5k_hw *ah, u8 coverage_class) |
| 752 | { |
| 753 | /* As defined by IEEE 802.11-2007 17.3.8.6 */ |
| 754 | int slot_time = ath5k_hw_get_default_slottime(ah) + 3 * coverage_class; |
| 755 | int ack_timeout = ath5k_hw_get_default_sifs(ah) + slot_time; |
| 756 | int cts_timeout = ack_timeout; |
| 757 | |
| 758 | ath5k_hw_set_slot_time(ah, slot_time); |
| 759 | ath5k_hw_set_ack_timeout(ah, ack_timeout); |
| 760 | ath5k_hw_set_cts_timeout(ah, cts_timeout); |
| 761 | |
| 762 | ah->ah_coverage_class = coverage_class; |
| 763 | } |