Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1 | /* |
Sujith | cee075a | 2009-03-13 09:07:23 +0530 | [diff] [blame] | 2 | * Copyright (c) 2008-2009 Atheros Communications Inc. |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3 | * |
| 4 | * Permission to use, copy, modify, and/or distribute this software for any |
| 5 | * purpose with or without fee is hereby granted, provided that the above |
| 6 | * copyright notice and this permission notice appear in all copies. |
| 7 | * |
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 | */ |
| 16 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 17 | #include <linux/nl80211.h> |
Sujith | 394cf0a | 2009-02-09 13:26:54 +0530 | [diff] [blame] | 18 | #include "ath9k.h" |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 19 | #include "btcoex.h" |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 20 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 21 | static char *dev_info = "ath9k"; |
| 22 | |
| 23 | MODULE_AUTHOR("Atheros Communications"); |
| 24 | MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards."); |
| 25 | MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards"); |
| 26 | MODULE_LICENSE("Dual BSD/GPL"); |
| 27 | |
Jouni Malinen | b3bd89c | 2009-02-24 13:42:01 +0200 | [diff] [blame] | 28 | static int modparam_nohwcrypt; |
| 29 | module_param_named(nohwcrypt, modparam_nohwcrypt, int, 0444); |
| 30 | MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption"); |
| 31 | |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 32 | /* We use the hw_value as an index into our private channel structure */ |
| 33 | |
| 34 | #define CHAN2G(_freq, _idx) { \ |
| 35 | .center_freq = (_freq), \ |
| 36 | .hw_value = (_idx), \ |
Luis R. Rodriguez | eeddfd9 | 2009-05-19 17:49:46 -0400 | [diff] [blame] | 37 | .max_power = 20, \ |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | #define CHAN5G(_freq, _idx) { \ |
| 41 | .band = IEEE80211_BAND_5GHZ, \ |
| 42 | .center_freq = (_freq), \ |
| 43 | .hw_value = (_idx), \ |
Luis R. Rodriguez | eeddfd9 | 2009-05-19 17:49:46 -0400 | [diff] [blame] | 44 | .max_power = 20, \ |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | /* Some 2 GHz radios are actually tunable on 2312-2732 |
| 48 | * on 5 MHz steps, we support the channels which we know |
| 49 | * we have calibration data for all cards though to make |
| 50 | * this static */ |
| 51 | static struct ieee80211_channel ath9k_2ghz_chantable[] = { |
| 52 | CHAN2G(2412, 0), /* Channel 1 */ |
| 53 | CHAN2G(2417, 1), /* Channel 2 */ |
| 54 | CHAN2G(2422, 2), /* Channel 3 */ |
| 55 | CHAN2G(2427, 3), /* Channel 4 */ |
| 56 | CHAN2G(2432, 4), /* Channel 5 */ |
| 57 | CHAN2G(2437, 5), /* Channel 6 */ |
| 58 | CHAN2G(2442, 6), /* Channel 7 */ |
| 59 | CHAN2G(2447, 7), /* Channel 8 */ |
| 60 | CHAN2G(2452, 8), /* Channel 9 */ |
| 61 | CHAN2G(2457, 9), /* Channel 10 */ |
| 62 | CHAN2G(2462, 10), /* Channel 11 */ |
| 63 | CHAN2G(2467, 11), /* Channel 12 */ |
| 64 | CHAN2G(2472, 12), /* Channel 13 */ |
| 65 | CHAN2G(2484, 13), /* Channel 14 */ |
| 66 | }; |
| 67 | |
| 68 | /* Some 5 GHz radios are actually tunable on XXXX-YYYY |
| 69 | * on 5 MHz steps, we support the channels which we know |
| 70 | * we have calibration data for all cards though to make |
| 71 | * this static */ |
| 72 | static struct ieee80211_channel ath9k_5ghz_chantable[] = { |
| 73 | /* _We_ call this UNII 1 */ |
| 74 | CHAN5G(5180, 14), /* Channel 36 */ |
| 75 | CHAN5G(5200, 15), /* Channel 40 */ |
| 76 | CHAN5G(5220, 16), /* Channel 44 */ |
| 77 | CHAN5G(5240, 17), /* Channel 48 */ |
| 78 | /* _We_ call this UNII 2 */ |
| 79 | CHAN5G(5260, 18), /* Channel 52 */ |
| 80 | CHAN5G(5280, 19), /* Channel 56 */ |
| 81 | CHAN5G(5300, 20), /* Channel 60 */ |
| 82 | CHAN5G(5320, 21), /* Channel 64 */ |
| 83 | /* _We_ call this "Middle band" */ |
| 84 | CHAN5G(5500, 22), /* Channel 100 */ |
| 85 | CHAN5G(5520, 23), /* Channel 104 */ |
| 86 | CHAN5G(5540, 24), /* Channel 108 */ |
| 87 | CHAN5G(5560, 25), /* Channel 112 */ |
| 88 | CHAN5G(5580, 26), /* Channel 116 */ |
| 89 | CHAN5G(5600, 27), /* Channel 120 */ |
| 90 | CHAN5G(5620, 28), /* Channel 124 */ |
| 91 | CHAN5G(5640, 29), /* Channel 128 */ |
| 92 | CHAN5G(5660, 30), /* Channel 132 */ |
| 93 | CHAN5G(5680, 31), /* Channel 136 */ |
| 94 | CHAN5G(5700, 32), /* Channel 140 */ |
| 95 | /* _We_ call this UNII 3 */ |
| 96 | CHAN5G(5745, 33), /* Channel 149 */ |
| 97 | CHAN5G(5765, 34), /* Channel 153 */ |
| 98 | CHAN5G(5785, 35), /* Channel 157 */ |
| 99 | CHAN5G(5805, 36), /* Channel 161 */ |
| 100 | CHAN5G(5825, 37), /* Channel 165 */ |
| 101 | }; |
| 102 | |
Luis R. Rodriguez | ce111ba | 2008-12-23 15:58:39 -0800 | [diff] [blame] | 103 | static void ath_cache_conf_rate(struct ath_softc *sc, |
| 104 | struct ieee80211_conf *conf) |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 105 | { |
Luis R. Rodriguez | 030bb49 | 2008-12-23 15:58:37 -0800 | [diff] [blame] | 106 | switch (conf->channel->band) { |
| 107 | case IEEE80211_BAND_2GHZ: |
| 108 | if (conf_is_ht20(conf)) |
| 109 | sc->cur_rate_table = |
| 110 | sc->hw_rate_table[ATH9K_MODE_11NG_HT20]; |
| 111 | else if (conf_is_ht40_minus(conf)) |
| 112 | sc->cur_rate_table = |
| 113 | sc->hw_rate_table[ATH9K_MODE_11NG_HT40MINUS]; |
| 114 | else if (conf_is_ht40_plus(conf)) |
| 115 | sc->cur_rate_table = |
| 116 | sc->hw_rate_table[ATH9K_MODE_11NG_HT40PLUS]; |
Luis R. Rodriguez | 9674225 | 2008-12-23 15:58:38 -0800 | [diff] [blame] | 117 | else |
Luis R. Rodriguez | 030bb49 | 2008-12-23 15:58:37 -0800 | [diff] [blame] | 118 | sc->cur_rate_table = |
| 119 | sc->hw_rate_table[ATH9K_MODE_11G]; |
Luis R. Rodriguez | 030bb49 | 2008-12-23 15:58:37 -0800 | [diff] [blame] | 120 | break; |
| 121 | case IEEE80211_BAND_5GHZ: |
| 122 | if (conf_is_ht20(conf)) |
| 123 | sc->cur_rate_table = |
| 124 | sc->hw_rate_table[ATH9K_MODE_11NA_HT20]; |
| 125 | else if (conf_is_ht40_minus(conf)) |
| 126 | sc->cur_rate_table = |
| 127 | sc->hw_rate_table[ATH9K_MODE_11NA_HT40MINUS]; |
| 128 | else if (conf_is_ht40_plus(conf)) |
| 129 | sc->cur_rate_table = |
| 130 | sc->hw_rate_table[ATH9K_MODE_11NA_HT40PLUS]; |
| 131 | else |
Luis R. Rodriguez | 9674225 | 2008-12-23 15:58:38 -0800 | [diff] [blame] | 132 | sc->cur_rate_table = |
| 133 | sc->hw_rate_table[ATH9K_MODE_11A]; |
Luis R. Rodriguez | 030bb49 | 2008-12-23 15:58:37 -0800 | [diff] [blame] | 134 | break; |
| 135 | default: |
Luis R. Rodriguez | ce111ba | 2008-12-23 15:58:39 -0800 | [diff] [blame] | 136 | BUG_ON(1); |
Luis R. Rodriguez | 030bb49 | 2008-12-23 15:58:37 -0800 | [diff] [blame] | 137 | break; |
| 138 | } |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | static void ath_update_txpow(struct ath_softc *sc) |
| 142 | { |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 143 | struct ath_hw *ah = sc->sc_ah; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 144 | u32 txpow; |
| 145 | |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 146 | if (sc->curtxpow != sc->config.txpowlimit) { |
| 147 | ath9k_hw_set_txpowerlimit(ah, sc->config.txpowlimit); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 148 | /* read back in case value is clamped */ |
| 149 | ath9k_hw_getcapability(ah, ATH9K_CAP_TXPOW, 1, &txpow); |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 150 | sc->curtxpow = txpow; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 151 | } |
| 152 | } |
| 153 | |
| 154 | static u8 parse_mpdudensity(u8 mpdudensity) |
| 155 | { |
| 156 | /* |
| 157 | * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing": |
| 158 | * 0 for no restriction |
| 159 | * 1 for 1/4 us |
| 160 | * 2 for 1/2 us |
| 161 | * 3 for 1 us |
| 162 | * 4 for 2 us |
| 163 | * 5 for 4 us |
| 164 | * 6 for 8 us |
| 165 | * 7 for 16 us |
| 166 | */ |
| 167 | switch (mpdudensity) { |
| 168 | case 0: |
| 169 | return 0; |
| 170 | case 1: |
| 171 | case 2: |
| 172 | case 3: |
| 173 | /* Our lower layer calculations limit our precision to |
| 174 | 1 microsecond */ |
| 175 | return 1; |
| 176 | case 4: |
| 177 | return 2; |
| 178 | case 5: |
| 179 | return 4; |
| 180 | case 6: |
| 181 | return 8; |
| 182 | case 7: |
| 183 | return 16; |
| 184 | default: |
| 185 | return 0; |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | static void ath_setup_rates(struct ath_softc *sc, enum ieee80211_band band) |
| 190 | { |
Luis R. Rodriguez | 4f0fc7c | 2009-05-06 02:20:00 -0400 | [diff] [blame] | 191 | const struct ath_rate_table *rate_table = NULL; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 192 | struct ieee80211_supported_band *sband; |
| 193 | struct ieee80211_rate *rate; |
| 194 | int i, maxrates; |
| 195 | |
| 196 | switch (band) { |
| 197 | case IEEE80211_BAND_2GHZ: |
| 198 | rate_table = sc->hw_rate_table[ATH9K_MODE_11G]; |
| 199 | break; |
| 200 | case IEEE80211_BAND_5GHZ: |
| 201 | rate_table = sc->hw_rate_table[ATH9K_MODE_11A]; |
| 202 | break; |
| 203 | default: |
| 204 | break; |
| 205 | } |
| 206 | |
| 207 | if (rate_table == NULL) |
| 208 | return; |
| 209 | |
| 210 | sband = &sc->sbands[band]; |
| 211 | rate = sc->rates[band]; |
| 212 | |
| 213 | if (rate_table->rate_cnt > ATH_RATE_MAX) |
| 214 | maxrates = ATH_RATE_MAX; |
| 215 | else |
| 216 | maxrates = rate_table->rate_cnt; |
| 217 | |
| 218 | for (i = 0; i < maxrates; i++) { |
| 219 | rate[i].bitrate = rate_table->info[i].ratekbps / 100; |
| 220 | rate[i].hw_value = rate_table->info[i].ratecode; |
Sujith | f46730d | 2009-01-27 13:51:03 +0530 | [diff] [blame] | 221 | if (rate_table->info[i].short_preamble) { |
| 222 | rate[i].hw_value_short = rate_table->info[i].ratecode | |
| 223 | rate_table->info[i].short_preamble; |
| 224 | rate[i].flags = IEEE80211_RATE_SHORT_PREAMBLE; |
| 225 | } |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 226 | sband->n_bitrates++; |
Sujith | f46730d | 2009-01-27 13:51:03 +0530 | [diff] [blame] | 227 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 228 | ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_CONFIG, |
| 229 | "Rate: %2dMbps, ratecode: %2d\n", |
| 230 | rate[i].bitrate / 10, rate[i].hw_value); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 231 | } |
| 232 | } |
| 233 | |
Vasanthakumar Thiagarajan | 82880a7 | 2009-06-13 14:50:24 +0530 | [diff] [blame] | 234 | static struct ath9k_channel *ath_get_curchannel(struct ath_softc *sc, |
| 235 | struct ieee80211_hw *hw) |
| 236 | { |
| 237 | struct ieee80211_channel *curchan = hw->conf.channel; |
| 238 | struct ath9k_channel *channel; |
| 239 | u8 chan_idx; |
| 240 | |
| 241 | chan_idx = curchan->hw_value; |
| 242 | channel = &sc->sc_ah->channels[chan_idx]; |
| 243 | ath9k_update_ichannel(sc, hw, channel); |
| 244 | return channel; |
| 245 | } |
| 246 | |
Luis R. Rodriguez | 9ecdef4 | 2009-09-09 21:10:09 -0700 | [diff] [blame] | 247 | static bool ath9k_setpower(struct ath_softc *sc, enum ath9k_power_mode mode) |
Luis R. Rodriguez | 8c77a56 | 2009-09-09 21:02:34 -0700 | [diff] [blame] | 248 | { |
| 249 | unsigned long flags; |
| 250 | bool ret; |
| 251 | |
Luis R. Rodriguez | 9ecdef4 | 2009-09-09 21:10:09 -0700 | [diff] [blame] | 252 | spin_lock_irqsave(&sc->sc_pm_lock, flags); |
| 253 | ret = ath9k_hw_setpower(sc->sc_ah, mode); |
| 254 | spin_unlock_irqrestore(&sc->sc_pm_lock, flags); |
Luis R. Rodriguez | 8c77a56 | 2009-09-09 21:02:34 -0700 | [diff] [blame] | 255 | |
| 256 | return ret; |
| 257 | } |
| 258 | |
Luis R. Rodriguez | a91d75a | 2009-09-09 20:29:18 -0700 | [diff] [blame] | 259 | void ath9k_ps_wakeup(struct ath_softc *sc) |
| 260 | { |
| 261 | unsigned long flags; |
| 262 | |
| 263 | spin_lock_irqsave(&sc->sc_pm_lock, flags); |
| 264 | if (++sc->ps_usecount != 1) |
| 265 | goto unlock; |
| 266 | |
Luis R. Rodriguez | 9ecdef4 | 2009-09-09 21:10:09 -0700 | [diff] [blame] | 267 | ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_AWAKE); |
Luis R. Rodriguez | a91d75a | 2009-09-09 20:29:18 -0700 | [diff] [blame] | 268 | |
| 269 | unlock: |
| 270 | spin_unlock_irqrestore(&sc->sc_pm_lock, flags); |
| 271 | } |
| 272 | |
| 273 | void ath9k_ps_restore(struct ath_softc *sc) |
| 274 | { |
| 275 | unsigned long flags; |
| 276 | |
| 277 | spin_lock_irqsave(&sc->sc_pm_lock, flags); |
| 278 | if (--sc->ps_usecount != 0) |
| 279 | goto unlock; |
| 280 | |
| 281 | if (sc->ps_enabled && |
| 282 | !(sc->sc_flags & (SC_OP_WAIT_FOR_BEACON | |
| 283 | SC_OP_WAIT_FOR_CAB | |
| 284 | SC_OP_WAIT_FOR_PSPOLL_DATA | |
| 285 | SC_OP_WAIT_FOR_TX_ACK))) |
Luis R. Rodriguez | 9ecdef4 | 2009-09-09 21:10:09 -0700 | [diff] [blame] | 286 | ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_NETWORK_SLEEP); |
Luis R. Rodriguez | a91d75a | 2009-09-09 20:29:18 -0700 | [diff] [blame] | 287 | |
| 288 | unlock: |
| 289 | spin_unlock_irqrestore(&sc->sc_pm_lock, flags); |
| 290 | } |
| 291 | |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 292 | /* |
| 293 | * Set/change channels. If the channel is really being changed, it's done |
| 294 | * by reseting the chip. To accomplish this we must first cleanup any pending |
| 295 | * DMA, then restart stuff. |
| 296 | */ |
Jouni Malinen | 0e2dedf | 2009-03-03 19:23:32 +0200 | [diff] [blame] | 297 | int ath_set_channel(struct ath_softc *sc, struct ieee80211_hw *hw, |
| 298 | struct ath9k_channel *hchan) |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 299 | { |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 300 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 301 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | 25c56ee | 2009-09-13 23:04:44 -0700 | [diff] [blame] | 302 | struct ieee80211_conf *conf = &common->hw->conf; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 303 | bool fastcc = true, stopped; |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 304 | struct ieee80211_channel *channel = hw->conf.channel; |
| 305 | int r; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 306 | |
| 307 | if (sc->sc_flags & SC_OP_INVALID) |
| 308 | return -EIO; |
| 309 | |
Vivek Natarajan | 3cbb5dd | 2009-01-20 11:17:08 +0530 | [diff] [blame] | 310 | ath9k_ps_wakeup(sc); |
| 311 | |
Luis R. Rodriguez | c0d7c7a | 2008-12-23 15:58:50 -0800 | [diff] [blame] | 312 | /* |
| 313 | * This is only performed if the channel settings have |
| 314 | * actually changed. |
| 315 | * |
| 316 | * To switch channels clear any pending DMA operations; |
| 317 | * wait long enough for the RX fifo to drain, reset the |
| 318 | * hardware at the new frequency, and then re-enable |
| 319 | * the relevant bits of the h/w. |
| 320 | */ |
| 321 | ath9k_hw_set_interrupts(ah, 0); |
Sujith | 043a040 | 2009-01-16 21:38:47 +0530 | [diff] [blame] | 322 | ath_drain_all_txq(sc, false); |
Luis R. Rodriguez | c0d7c7a | 2008-12-23 15:58:50 -0800 | [diff] [blame] | 323 | stopped = ath_stoprecv(sc); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 324 | |
Luis R. Rodriguez | c0d7c7a | 2008-12-23 15:58:50 -0800 | [diff] [blame] | 325 | /* XXX: do not flush receive queue here. We don't want |
| 326 | * to flush data frames already in queue because of |
| 327 | * changing channel. */ |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 328 | |
Luis R. Rodriguez | c0d7c7a | 2008-12-23 15:58:50 -0800 | [diff] [blame] | 329 | if (!stopped || (sc->sc_flags & SC_OP_FULL_RESET)) |
| 330 | fastcc = false; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 331 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 332 | ath_print(common, ATH_DBG_CONFIG, |
Luis R. Rodriguez | 25c56ee | 2009-09-13 23:04:44 -0700 | [diff] [blame] | 333 | "(%u MHz) -> (%u MHz), conf_is_ht40: %d\n", |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 334 | sc->sc_ah->curchan->channel, |
Luis R. Rodriguez | 25c56ee | 2009-09-13 23:04:44 -0700 | [diff] [blame] | 335 | channel->center_freq, conf_is_ht40(conf)); |
Sujith | 99405f9 | 2008-11-24 12:08:35 +0530 | [diff] [blame] | 336 | |
Luis R. Rodriguez | c0d7c7a | 2008-12-23 15:58:50 -0800 | [diff] [blame] | 337 | spin_lock_bh(&sc->sc_resetlock); |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 338 | |
Luis R. Rodriguez | c0d7c7a | 2008-12-23 15:58:50 -0800 | [diff] [blame] | 339 | r = ath9k_hw_reset(ah, hchan, fastcc); |
| 340 | if (r) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 341 | ath_print(common, ATH_DBG_FATAL, |
| 342 | "Unable to reset channel (%u Mhz) " |
| 343 | "reset status %d\n", |
| 344 | channel->center_freq, r); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 345 | spin_unlock_bh(&sc->sc_resetlock); |
Gabor Juhos | 3989279 | 2009-06-15 17:49:09 +0200 | [diff] [blame] | 346 | goto ps_restore; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 347 | } |
Luis R. Rodriguez | c0d7c7a | 2008-12-23 15:58:50 -0800 | [diff] [blame] | 348 | spin_unlock_bh(&sc->sc_resetlock); |
| 349 | |
Luis R. Rodriguez | c0d7c7a | 2008-12-23 15:58:50 -0800 | [diff] [blame] | 350 | sc->sc_flags &= ~SC_OP_FULL_RESET; |
| 351 | |
| 352 | if (ath_startrecv(sc) != 0) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 353 | ath_print(common, ATH_DBG_FATAL, |
| 354 | "Unable to restart recv logic\n"); |
Gabor Juhos | 3989279 | 2009-06-15 17:49:09 +0200 | [diff] [blame] | 355 | r = -EIO; |
| 356 | goto ps_restore; |
Luis R. Rodriguez | c0d7c7a | 2008-12-23 15:58:50 -0800 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | ath_cache_conf_rate(sc, &hw->conf); |
| 360 | ath_update_txpow(sc); |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 361 | ath9k_hw_set_interrupts(ah, sc->imask); |
Gabor Juhos | 3989279 | 2009-06-15 17:49:09 +0200 | [diff] [blame] | 362 | |
| 363 | ps_restore: |
Vivek Natarajan | 3cbb5dd | 2009-01-20 11:17:08 +0530 | [diff] [blame] | 364 | ath9k_ps_restore(sc); |
Gabor Juhos | 3989279 | 2009-06-15 17:49:09 +0200 | [diff] [blame] | 365 | return r; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | /* |
| 369 | * This routine performs the periodic noise floor calibration function |
| 370 | * that is used to adjust and optimize the chip performance. This |
| 371 | * takes environmental changes (location, temperature) into account. |
| 372 | * When the task is complete, it reschedules itself depending on the |
| 373 | * appropriate interval that was calculated. |
| 374 | */ |
| 375 | static void ath_ani_calibrate(unsigned long data) |
| 376 | { |
Sujith | 20977d3 | 2009-02-20 15:13:28 +0530 | [diff] [blame] | 377 | struct ath_softc *sc = (struct ath_softc *)data; |
| 378 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 379 | struct ath_common *common = ath9k_hw_common(ah); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 380 | bool longcal = false; |
| 381 | bool shortcal = false; |
| 382 | bool aniflag = false; |
| 383 | unsigned int timestamp = jiffies_to_msecs(jiffies); |
Sujith | 20977d3 | 2009-02-20 15:13:28 +0530 | [diff] [blame] | 384 | u32 cal_interval, short_cal_interval; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 385 | |
Sujith | 20977d3 | 2009-02-20 15:13:28 +0530 | [diff] [blame] | 386 | short_cal_interval = (ah->opmode == NL80211_IFTYPE_AP) ? |
| 387 | ATH_AP_SHORT_CALINTERVAL : ATH_STA_SHORT_CALINTERVAL; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 388 | |
| 389 | /* |
| 390 | * don't calibrate when we're scanning. |
| 391 | * we are most likely not on our home channel. |
| 392 | */ |
Senthil Balasubramanian | e5f0921 | 2009-06-24 18:56:41 +0530 | [diff] [blame] | 393 | spin_lock(&sc->ani_lock); |
Sujith | 0c98de6 | 2009-03-03 10:16:45 +0530 | [diff] [blame] | 394 | if (sc->sc_flags & SC_OP_SCANNING) |
Sujith | 20977d3 | 2009-02-20 15:13:28 +0530 | [diff] [blame] | 395 | goto set_timer; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 396 | |
Jouni Malinen | 1ffc1c6 | 2009-05-19 17:01:39 +0300 | [diff] [blame] | 397 | /* Only calibrate if awake */ |
| 398 | if (sc->sc_ah->power_mode != ATH9K_PM_AWAKE) |
| 399 | goto set_timer; |
| 400 | |
| 401 | ath9k_ps_wakeup(sc); |
| 402 | |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 403 | /* Long calibration runs independently of short calibration. */ |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 404 | if ((timestamp - sc->ani.longcal_timer) >= ATH_LONG_CALINTERVAL) { |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 405 | longcal = true; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 406 | ath_print(common, ATH_DBG_ANI, "longcal @%lu\n", jiffies); |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 407 | sc->ani.longcal_timer = timestamp; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 408 | } |
| 409 | |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 410 | /* Short calibration applies only while caldone is false */ |
| 411 | if (!sc->ani.caldone) { |
Sujith | 20977d3 | 2009-02-20 15:13:28 +0530 | [diff] [blame] | 412 | if ((timestamp - sc->ani.shortcal_timer) >= short_cal_interval) { |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 413 | shortcal = true; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 414 | ath_print(common, ATH_DBG_ANI, |
| 415 | "shortcal @%lu\n", jiffies); |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 416 | sc->ani.shortcal_timer = timestamp; |
| 417 | sc->ani.resetcal_timer = timestamp; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 418 | } |
| 419 | } else { |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 420 | if ((timestamp - sc->ani.resetcal_timer) >= |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 421 | ATH_RESTART_CALINTERVAL) { |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 422 | sc->ani.caldone = ath9k_hw_reset_calvalid(ah); |
| 423 | if (sc->ani.caldone) |
| 424 | sc->ani.resetcal_timer = timestamp; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 425 | } |
| 426 | } |
| 427 | |
| 428 | /* Verify whether we must check ANI */ |
Sujith | 20977d3 | 2009-02-20 15:13:28 +0530 | [diff] [blame] | 429 | if ((timestamp - sc->ani.checkani_timer) >= ATH_ANI_POLLINTERVAL) { |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 430 | aniflag = true; |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 431 | sc->ani.checkani_timer = timestamp; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | /* Skip all processing if there's nothing to do. */ |
| 435 | if (longcal || shortcal || aniflag) { |
| 436 | /* Call ANI routine if necessary */ |
| 437 | if (aniflag) |
Vasanthakumar Thiagarajan | 22e66a4 | 2009-08-19 16:23:40 +0530 | [diff] [blame] | 438 | ath9k_hw_ani_monitor(ah, ah->curchan); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 439 | |
| 440 | /* Perform calibration if necessary */ |
| 441 | if (longcal || shortcal) { |
Luis R. Rodriguez | 43c2761 | 2009-09-13 21:07:07 -0700 | [diff] [blame] | 442 | sc->ani.caldone = |
| 443 | ath9k_hw_calibrate(ah, |
| 444 | ah->curchan, |
| 445 | common->rx_chainmask, |
| 446 | longcal); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 447 | |
Sujith | 379f044 | 2009-04-13 21:56:48 +0530 | [diff] [blame] | 448 | if (longcal) |
| 449 | sc->ani.noise_floor = ath9k_hw_getchan_noise(ah, |
| 450 | ah->curchan); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 451 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 452 | ath_print(common, ATH_DBG_ANI, |
| 453 | " calibrate chan %u/%x nf: %d\n", |
| 454 | ah->curchan->channel, |
| 455 | ah->curchan->channelFlags, |
| 456 | sc->ani.noise_floor); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 457 | } |
| 458 | } |
| 459 | |
Jouni Malinen | 1ffc1c6 | 2009-05-19 17:01:39 +0300 | [diff] [blame] | 460 | ath9k_ps_restore(sc); |
| 461 | |
Sujith | 20977d3 | 2009-02-20 15:13:28 +0530 | [diff] [blame] | 462 | set_timer: |
Senthil Balasubramanian | e5f0921 | 2009-06-24 18:56:41 +0530 | [diff] [blame] | 463 | spin_unlock(&sc->ani_lock); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 464 | /* |
| 465 | * Set timer interval based on previous results. |
| 466 | * The interval must be the shortest necessary to satisfy ANI, |
| 467 | * short calibration and long calibration. |
| 468 | */ |
Sujith | aac9207 | 2008-12-02 18:37:54 +0530 | [diff] [blame] | 469 | cal_interval = ATH_LONG_CALINTERVAL; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 470 | if (sc->sc_ah->config.enable_ani) |
Sujith | aac9207 | 2008-12-02 18:37:54 +0530 | [diff] [blame] | 471 | cal_interval = min(cal_interval, (u32)ATH_ANI_POLLINTERVAL); |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 472 | if (!sc->ani.caldone) |
Sujith | 20977d3 | 2009-02-20 15:13:28 +0530 | [diff] [blame] | 473 | cal_interval = min(cal_interval, (u32)short_cal_interval); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 474 | |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 475 | mod_timer(&sc->ani.timer, jiffies + msecs_to_jiffies(cal_interval)); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 476 | } |
| 477 | |
Sujith | 415f738 | 2009-04-13 21:56:46 +0530 | [diff] [blame] | 478 | static void ath_start_ani(struct ath_softc *sc) |
| 479 | { |
| 480 | unsigned long timestamp = jiffies_to_msecs(jiffies); |
| 481 | |
| 482 | sc->ani.longcal_timer = timestamp; |
| 483 | sc->ani.shortcal_timer = timestamp; |
| 484 | sc->ani.checkani_timer = timestamp; |
| 485 | |
| 486 | mod_timer(&sc->ani.timer, |
| 487 | jiffies + msecs_to_jiffies(ATH_ANI_POLLINTERVAL)); |
| 488 | } |
| 489 | |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 490 | /* |
| 491 | * Update tx/rx chainmask. For legacy association, |
| 492 | * hard code chainmask to 1x1, for 11n association, use |
Vasanthakumar Thiagarajan | c97c92d | 2009-01-02 15:35:46 +0530 | [diff] [blame] | 493 | * the chainmask configuration, for bt coexistence, use |
| 494 | * the chainmask configuration even in legacy mode. |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 495 | */ |
Jouni Malinen | 0e2dedf | 2009-03-03 19:23:32 +0200 | [diff] [blame] | 496 | void ath_update_chainmask(struct ath_softc *sc, int is_ht) |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 497 | { |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 498 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | 43c2761 | 2009-09-13 21:07:07 -0700 | [diff] [blame] | 499 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 500 | |
Sujith | 3d83261 | 2009-08-21 12:00:28 +0530 | [diff] [blame] | 501 | if ((sc->sc_flags & SC_OP_SCANNING) || is_ht || |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 502 | (ah->btcoex_hw.scheme != ATH_BTCOEX_CFG_NONE)) { |
Luis R. Rodriguez | 43c2761 | 2009-09-13 21:07:07 -0700 | [diff] [blame] | 503 | common->tx_chainmask = ah->caps.tx_chainmask; |
| 504 | common->rx_chainmask = ah->caps.rx_chainmask; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 505 | } else { |
Luis R. Rodriguez | 43c2761 | 2009-09-13 21:07:07 -0700 | [diff] [blame] | 506 | common->tx_chainmask = 1; |
| 507 | common->rx_chainmask = 1; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 508 | } |
| 509 | |
Luis R. Rodriguez | 43c2761 | 2009-09-13 21:07:07 -0700 | [diff] [blame] | 510 | ath_print(common, ATH_DBG_CONFIG, |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 511 | "tx chmask: %d, rx chmask: %d\n", |
Luis R. Rodriguez | 43c2761 | 2009-09-13 21:07:07 -0700 | [diff] [blame] | 512 | common->tx_chainmask, |
| 513 | common->rx_chainmask); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | static void ath_node_attach(struct ath_softc *sc, struct ieee80211_sta *sta) |
| 517 | { |
| 518 | struct ath_node *an; |
| 519 | |
| 520 | an = (struct ath_node *)sta->drv_priv; |
| 521 | |
Sujith | 87792ef | 2009-03-30 15:28:48 +0530 | [diff] [blame] | 522 | if (sc->sc_flags & SC_OP_TXAGGR) { |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 523 | ath_tx_node_init(sc, an); |
Sujith | 9e98ac6 | 2009-07-23 15:32:34 +0530 | [diff] [blame] | 524 | an->maxampdu = 1 << (IEEE80211_HT_MAX_AMPDU_FACTOR + |
Sujith | 87792ef | 2009-03-30 15:28:48 +0530 | [diff] [blame] | 525 | sta->ht_cap.ampdu_factor); |
| 526 | an->mpdudensity = parse_mpdudensity(sta->ht_cap.ampdu_density); |
Senthil Balasubramanian | a59b5a5 | 2009-07-14 20:17:07 -0400 | [diff] [blame] | 527 | an->last_rssi = ATH_RSSI_DUMMY_MARKER; |
Sujith | 87792ef | 2009-03-30 15:28:48 +0530 | [diff] [blame] | 528 | } |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | static void ath_node_detach(struct ath_softc *sc, struct ieee80211_sta *sta) |
| 532 | { |
| 533 | struct ath_node *an = (struct ath_node *)sta->drv_priv; |
| 534 | |
| 535 | if (sc->sc_flags & SC_OP_TXAGGR) |
| 536 | ath_tx_node_cleanup(sc, an); |
| 537 | } |
| 538 | |
| 539 | static void ath9k_tasklet(unsigned long data) |
| 540 | { |
| 541 | struct ath_softc *sc = (struct ath_softc *)data; |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 542 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 543 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 544 | |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 545 | u32 status = sc->intrstatus; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 546 | |
Vasanthakumar Thiagarajan | 153e080 | 2009-05-15 02:47:16 -0400 | [diff] [blame] | 547 | ath9k_ps_wakeup(sc); |
| 548 | |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 549 | if (status & ATH9K_INT_FATAL) { |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 550 | ath_reset(sc, false); |
Vasanthakumar Thiagarajan | 153e080 | 2009-05-15 02:47:16 -0400 | [diff] [blame] | 551 | ath9k_ps_restore(sc); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 552 | return; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 553 | } |
| 554 | |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 555 | if (status & (ATH9K_INT_RX | ATH9K_INT_RXEOL | ATH9K_INT_RXORN)) { |
| 556 | spin_lock_bh(&sc->rx.rxflushlock); |
| 557 | ath_rx_tasklet(sc, 0); |
| 558 | spin_unlock_bh(&sc->rx.rxflushlock); |
| 559 | } |
| 560 | |
| 561 | if (status & ATH9K_INT_TX) |
| 562 | ath_tx_tasklet(sc); |
| 563 | |
Gabor Juhos | 9614832 | 2009-07-24 17:27:21 +0200 | [diff] [blame] | 564 | if ((status & ATH9K_INT_TSFOOR) && sc->ps_enabled) { |
Jouni Malinen | 54ce846 | 2009-05-19 17:01:40 +0300 | [diff] [blame] | 565 | /* |
| 566 | * TSF sync does not look correct; remain awake to sync with |
| 567 | * the next Beacon. |
| 568 | */ |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 569 | ath_print(common, ATH_DBG_PS, |
| 570 | "TSFOOR - Sync with next Beacon\n"); |
Jouni Malinen | ccdfeab | 2009-05-20 21:59:08 +0300 | [diff] [blame] | 571 | sc->sc_flags |= SC_OP_WAIT_FOR_BEACON | SC_OP_BEACON_SYNC; |
Jouni Malinen | 54ce846 | 2009-05-19 17:01:40 +0300 | [diff] [blame] | 572 | } |
| 573 | |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 574 | if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE) |
Vasanthakumar Thiagarajan | ebb8e1d | 2009-09-01 17:46:32 +0530 | [diff] [blame] | 575 | if (status & ATH9K_INT_GENTIMER) |
| 576 | ath_gen_timer_isr(sc->sc_ah); |
| 577 | |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 578 | /* re-enable hardware interrupt */ |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 579 | ath9k_hw_set_interrupts(ah, sc->imask); |
Vasanthakumar Thiagarajan | 153e080 | 2009-05-15 02:47:16 -0400 | [diff] [blame] | 580 | ath9k_ps_restore(sc); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 581 | } |
| 582 | |
Gabor Juhos | 6baff7f | 2009-01-14 20:17:06 +0100 | [diff] [blame] | 583 | irqreturn_t ath_isr(int irq, void *dev) |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 584 | { |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 585 | #define SCHED_INTR ( \ |
| 586 | ATH9K_INT_FATAL | \ |
| 587 | ATH9K_INT_RXORN | \ |
| 588 | ATH9K_INT_RXEOL | \ |
| 589 | ATH9K_INT_RX | \ |
| 590 | ATH9K_INT_TX | \ |
| 591 | ATH9K_INT_BMISS | \ |
| 592 | ATH9K_INT_CST | \ |
Vasanthakumar Thiagarajan | ebb8e1d | 2009-09-01 17:46:32 +0530 | [diff] [blame] | 593 | ATH9K_INT_TSFOOR | \ |
| 594 | ATH9K_INT_GENTIMER) |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 595 | |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 596 | struct ath_softc *sc = dev; |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 597 | struct ath_hw *ah = sc->sc_ah; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 598 | enum ath9k_int status; |
| 599 | bool sched = false; |
| 600 | |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 601 | /* |
| 602 | * The hardware is not ready/present, don't |
| 603 | * touch anything. Note this can happen early |
| 604 | * on if the IRQ is shared. |
| 605 | */ |
| 606 | if (sc->sc_flags & SC_OP_INVALID) |
| 607 | return IRQ_NONE; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 608 | |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 609 | |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 610 | /* shared irq, not for us */ |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 611 | |
Vasanthakumar Thiagarajan | 153e080 | 2009-05-15 02:47:16 -0400 | [diff] [blame] | 612 | if (!ath9k_hw_intrpend(ah)) |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 613 | return IRQ_NONE; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 614 | |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 615 | /* |
| 616 | * Figure out the reason(s) for the interrupt. Note |
| 617 | * that the hal returns a pseudo-ISR that may include |
| 618 | * bits we haven't explicitly enabled so we mask the |
| 619 | * value to insure we only process bits we requested. |
| 620 | */ |
| 621 | ath9k_hw_getisr(ah, &status); /* NB: clears ISR too */ |
| 622 | status &= sc->imask; /* discard unasked-for bits */ |
| 623 | |
| 624 | /* |
| 625 | * If there are no status bits set, then this interrupt was not |
| 626 | * for me (should have been caught above). |
| 627 | */ |
Vasanthakumar Thiagarajan | 153e080 | 2009-05-15 02:47:16 -0400 | [diff] [blame] | 628 | if (!status) |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 629 | return IRQ_NONE; |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 630 | |
| 631 | /* Cache the status */ |
| 632 | sc->intrstatus = status; |
| 633 | |
| 634 | if (status & SCHED_INTR) |
| 635 | sched = true; |
| 636 | |
| 637 | /* |
| 638 | * If a FATAL or RXORN interrupt is received, we have to reset the |
| 639 | * chip immediately. |
| 640 | */ |
| 641 | if (status & (ATH9K_INT_FATAL | ATH9K_INT_RXORN)) |
| 642 | goto chip_reset; |
| 643 | |
| 644 | if (status & ATH9K_INT_SWBA) |
| 645 | tasklet_schedule(&sc->bcon_tasklet); |
| 646 | |
| 647 | if (status & ATH9K_INT_TXURN) |
| 648 | ath9k_hw_updatetxtriglevel(ah, true); |
| 649 | |
| 650 | if (status & ATH9K_INT_MIB) { |
| 651 | /* |
| 652 | * Disable interrupts until we service the MIB |
| 653 | * interrupt; otherwise it will continue to |
| 654 | * fire. |
| 655 | */ |
| 656 | ath9k_hw_set_interrupts(ah, 0); |
| 657 | /* |
| 658 | * Let the hal handle the event. We assume |
| 659 | * it will clear whatever condition caused |
| 660 | * the interrupt. |
| 661 | */ |
Vasanthakumar Thiagarajan | 22e66a4 | 2009-08-19 16:23:40 +0530 | [diff] [blame] | 662 | ath9k_hw_procmibevent(ah); |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 663 | ath9k_hw_set_interrupts(ah, sc->imask); |
| 664 | } |
| 665 | |
Vasanthakumar Thiagarajan | 153e080 | 2009-05-15 02:47:16 -0400 | [diff] [blame] | 666 | if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) |
| 667 | if (status & ATH9K_INT_TIM_TIMER) { |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 668 | /* Clear RxAbort bit so that we can |
| 669 | * receive frames */ |
Luis R. Rodriguez | 9ecdef4 | 2009-09-09 21:10:09 -0700 | [diff] [blame] | 670 | ath9k_setpower(sc, ATH9K_PM_AWAKE); |
Vasanthakumar Thiagarajan | 153e080 | 2009-05-15 02:47:16 -0400 | [diff] [blame] | 671 | ath9k_hw_setrxabort(sc->sc_ah, 0); |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 672 | sc->sc_flags |= SC_OP_WAIT_FOR_BEACON; |
| 673 | } |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 674 | |
| 675 | chip_reset: |
| 676 | |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 677 | ath_debug_stat_interrupt(sc, status); |
| 678 | |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 679 | if (sched) { |
| 680 | /* turn off every interrupt except SWBA */ |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 681 | ath9k_hw_set_interrupts(ah, (sc->imask & ATH9K_INT_SWBA)); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 682 | tasklet_schedule(&sc->intr_tq); |
| 683 | } |
| 684 | |
| 685 | return IRQ_HANDLED; |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 686 | |
| 687 | #undef SCHED_INTR |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 688 | } |
| 689 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 690 | static u32 ath_get_extchanmode(struct ath_softc *sc, |
Sujith | 99405f9 | 2008-11-24 12:08:35 +0530 | [diff] [blame] | 691 | struct ieee80211_channel *chan, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 692 | enum nl80211_channel_type channel_type) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 693 | { |
| 694 | u32 chanmode = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 695 | |
| 696 | switch (chan->band) { |
| 697 | case IEEE80211_BAND_2GHZ: |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 698 | switch(channel_type) { |
| 699 | case NL80211_CHAN_NO_HT: |
| 700 | case NL80211_CHAN_HT20: |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 701 | chanmode = CHANNEL_G_HT20; |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 702 | break; |
| 703 | case NL80211_CHAN_HT40PLUS: |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 704 | chanmode = CHANNEL_G_HT40PLUS; |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 705 | break; |
| 706 | case NL80211_CHAN_HT40MINUS: |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 707 | chanmode = CHANNEL_G_HT40MINUS; |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 708 | break; |
| 709 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 710 | break; |
| 711 | case IEEE80211_BAND_5GHZ: |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 712 | switch(channel_type) { |
| 713 | case NL80211_CHAN_NO_HT: |
| 714 | case NL80211_CHAN_HT20: |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 715 | chanmode = CHANNEL_A_HT20; |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 716 | break; |
| 717 | case NL80211_CHAN_HT40PLUS: |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 718 | chanmode = CHANNEL_A_HT40PLUS; |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 719 | break; |
| 720 | case NL80211_CHAN_HT40MINUS: |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 721 | chanmode = CHANNEL_A_HT40MINUS; |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 722 | break; |
| 723 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 724 | break; |
| 725 | default: |
| 726 | break; |
| 727 | } |
| 728 | |
| 729 | return chanmode; |
| 730 | } |
| 731 | |
Jouni Malinen | 6ace289 | 2008-12-17 13:32:17 +0200 | [diff] [blame] | 732 | static int ath_setkey_tkip(struct ath_softc *sc, u16 keyix, const u8 *key, |
Jouni Malinen | 3f53dd6 | 2009-02-26 11:18:46 +0200 | [diff] [blame] | 733 | struct ath9k_keyval *hk, const u8 *addr, |
| 734 | bool authenticator) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 735 | { |
Jouni Malinen | 6ace289 | 2008-12-17 13:32:17 +0200 | [diff] [blame] | 736 | const u8 *key_rxmic; |
| 737 | const u8 *key_txmic; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 738 | |
Jouni Malinen | 6ace289 | 2008-12-17 13:32:17 +0200 | [diff] [blame] | 739 | key_txmic = key + NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY; |
| 740 | key_rxmic = key + NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 741 | |
| 742 | if (addr == NULL) { |
Jouni Malinen | d216aaa | 2009-03-03 13:11:53 +0200 | [diff] [blame] | 743 | /* |
| 744 | * Group key installation - only two key cache entries are used |
| 745 | * regardless of splitmic capability since group key is only |
| 746 | * used either for TX or RX. |
| 747 | */ |
Jouni Malinen | 3f53dd6 | 2009-02-26 11:18:46 +0200 | [diff] [blame] | 748 | if (authenticator) { |
| 749 | memcpy(hk->kv_mic, key_txmic, sizeof(hk->kv_mic)); |
| 750 | memcpy(hk->kv_txmic, key_txmic, sizeof(hk->kv_mic)); |
| 751 | } else { |
| 752 | memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic)); |
| 753 | memcpy(hk->kv_txmic, key_rxmic, sizeof(hk->kv_mic)); |
| 754 | } |
Jouni Malinen | d216aaa | 2009-03-03 13:11:53 +0200 | [diff] [blame] | 755 | return ath9k_hw_set_keycache_entry(sc->sc_ah, keyix, hk, addr); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 756 | } |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 757 | if (!sc->splitmic) { |
Jouni Malinen | d216aaa | 2009-03-03 13:11:53 +0200 | [diff] [blame] | 758 | /* TX and RX keys share the same key cache entry. */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 759 | memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic)); |
| 760 | memcpy(hk->kv_txmic, key_txmic, sizeof(hk->kv_txmic)); |
Jouni Malinen | d216aaa | 2009-03-03 13:11:53 +0200 | [diff] [blame] | 761 | return ath9k_hw_set_keycache_entry(sc->sc_ah, keyix, hk, addr); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 762 | } |
Jouni Malinen | d216aaa | 2009-03-03 13:11:53 +0200 | [diff] [blame] | 763 | |
| 764 | /* Separate key cache entries for TX and RX */ |
| 765 | |
| 766 | /* TX key goes at first index, RX key at +32. */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 767 | memcpy(hk->kv_mic, key_txmic, sizeof(hk->kv_mic)); |
Jouni Malinen | d216aaa | 2009-03-03 13:11:53 +0200 | [diff] [blame] | 768 | if (!ath9k_hw_set_keycache_entry(sc->sc_ah, keyix, hk, NULL)) { |
| 769 | /* TX MIC entry failed. No need to proceed further */ |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 770 | ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_FATAL, |
| 771 | "Setting TX MIC Key Failed\n"); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 772 | return 0; |
| 773 | } |
| 774 | |
| 775 | memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic)); |
| 776 | /* XXX delete tx key on failure? */ |
Jouni Malinen | d216aaa | 2009-03-03 13:11:53 +0200 | [diff] [blame] | 777 | return ath9k_hw_set_keycache_entry(sc->sc_ah, keyix + 32, hk, addr); |
Jouni Malinen | 6ace289 | 2008-12-17 13:32:17 +0200 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | static int ath_reserve_key_cache_slot_tkip(struct ath_softc *sc) |
| 781 | { |
| 782 | int i; |
| 783 | |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 784 | for (i = IEEE80211_WEP_NKID; i < sc->keymax / 2; i++) { |
| 785 | if (test_bit(i, sc->keymap) || |
| 786 | test_bit(i + 64, sc->keymap)) |
Jouni Malinen | 6ace289 | 2008-12-17 13:32:17 +0200 | [diff] [blame] | 787 | continue; /* At least one part of TKIP key allocated */ |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 788 | if (sc->splitmic && |
| 789 | (test_bit(i + 32, sc->keymap) || |
| 790 | test_bit(i + 64 + 32, sc->keymap))) |
Jouni Malinen | 6ace289 | 2008-12-17 13:32:17 +0200 | [diff] [blame] | 791 | continue; /* At least one part of TKIP key allocated */ |
| 792 | |
| 793 | /* Found a free slot for a TKIP key */ |
| 794 | return i; |
| 795 | } |
| 796 | return -1; |
| 797 | } |
| 798 | |
| 799 | static int ath_reserve_key_cache_slot(struct ath_softc *sc) |
| 800 | { |
| 801 | int i; |
| 802 | |
| 803 | /* First, try to find slots that would not be available for TKIP. */ |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 804 | if (sc->splitmic) { |
| 805 | for (i = IEEE80211_WEP_NKID; i < sc->keymax / 4; i++) { |
| 806 | if (!test_bit(i, sc->keymap) && |
| 807 | (test_bit(i + 32, sc->keymap) || |
| 808 | test_bit(i + 64, sc->keymap) || |
| 809 | test_bit(i + 64 + 32, sc->keymap))) |
Jouni Malinen | 6ace289 | 2008-12-17 13:32:17 +0200 | [diff] [blame] | 810 | return i; |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 811 | if (!test_bit(i + 32, sc->keymap) && |
| 812 | (test_bit(i, sc->keymap) || |
| 813 | test_bit(i + 64, sc->keymap) || |
| 814 | test_bit(i + 64 + 32, sc->keymap))) |
Jouni Malinen | 6ace289 | 2008-12-17 13:32:17 +0200 | [diff] [blame] | 815 | return i + 32; |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 816 | if (!test_bit(i + 64, sc->keymap) && |
| 817 | (test_bit(i , sc->keymap) || |
| 818 | test_bit(i + 32, sc->keymap) || |
| 819 | test_bit(i + 64 + 32, sc->keymap))) |
Jouni Malinen | ea61213 | 2008-12-18 14:31:10 +0200 | [diff] [blame] | 820 | return i + 64; |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 821 | if (!test_bit(i + 64 + 32, sc->keymap) && |
| 822 | (test_bit(i, sc->keymap) || |
| 823 | test_bit(i + 32, sc->keymap) || |
| 824 | test_bit(i + 64, sc->keymap))) |
Jouni Malinen | ea61213 | 2008-12-18 14:31:10 +0200 | [diff] [blame] | 825 | return i + 64 + 32; |
Jouni Malinen | 6ace289 | 2008-12-17 13:32:17 +0200 | [diff] [blame] | 826 | } |
| 827 | } else { |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 828 | for (i = IEEE80211_WEP_NKID; i < sc->keymax / 2; i++) { |
| 829 | if (!test_bit(i, sc->keymap) && |
| 830 | test_bit(i + 64, sc->keymap)) |
Jouni Malinen | 6ace289 | 2008-12-17 13:32:17 +0200 | [diff] [blame] | 831 | return i; |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 832 | if (test_bit(i, sc->keymap) && |
| 833 | !test_bit(i + 64, sc->keymap)) |
Jouni Malinen | 6ace289 | 2008-12-17 13:32:17 +0200 | [diff] [blame] | 834 | return i + 64; |
| 835 | } |
| 836 | } |
| 837 | |
| 838 | /* No partially used TKIP slots, pick any available slot */ |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 839 | for (i = IEEE80211_WEP_NKID; i < sc->keymax; i++) { |
Jouni Malinen | be2864c | 2008-12-18 14:33:00 +0200 | [diff] [blame] | 840 | /* Do not allow slots that could be needed for TKIP group keys |
| 841 | * to be used. This limitation could be removed if we know that |
| 842 | * TKIP will not be used. */ |
| 843 | if (i >= 64 && i < 64 + IEEE80211_WEP_NKID) |
| 844 | continue; |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 845 | if (sc->splitmic) { |
Jouni Malinen | be2864c | 2008-12-18 14:33:00 +0200 | [diff] [blame] | 846 | if (i >= 32 && i < 32 + IEEE80211_WEP_NKID) |
| 847 | continue; |
| 848 | if (i >= 64 + 32 && i < 64 + 32 + IEEE80211_WEP_NKID) |
| 849 | continue; |
| 850 | } |
| 851 | |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 852 | if (!test_bit(i, sc->keymap)) |
Jouni Malinen | 6ace289 | 2008-12-17 13:32:17 +0200 | [diff] [blame] | 853 | return i; /* Found a free slot for a key */ |
| 854 | } |
| 855 | |
| 856 | /* No free slot found */ |
| 857 | return -1; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | static int ath_key_config(struct ath_softc *sc, |
Jouni Malinen | 3f53dd6 | 2009-02-26 11:18:46 +0200 | [diff] [blame] | 861 | struct ieee80211_vif *vif, |
Johannes Berg | dc822b5 | 2008-12-29 12:55:09 +0100 | [diff] [blame] | 862 | struct ieee80211_sta *sta, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 863 | struct ieee80211_key_conf *key) |
| 864 | { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 865 | struct ath9k_keyval hk; |
| 866 | const u8 *mac = NULL; |
| 867 | int ret = 0; |
Jouni Malinen | 6ace289 | 2008-12-17 13:32:17 +0200 | [diff] [blame] | 868 | int idx; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 869 | |
| 870 | memset(&hk, 0, sizeof(hk)); |
| 871 | |
| 872 | switch (key->alg) { |
| 873 | case ALG_WEP: |
| 874 | hk.kv_type = ATH9K_CIPHER_WEP; |
| 875 | break; |
| 876 | case ALG_TKIP: |
| 877 | hk.kv_type = ATH9K_CIPHER_TKIP; |
| 878 | break; |
| 879 | case ALG_CCMP: |
| 880 | hk.kv_type = ATH9K_CIPHER_AES_CCM; |
| 881 | break; |
| 882 | default: |
Jouni Malinen | ca470b2 | 2009-01-08 13:32:12 +0200 | [diff] [blame] | 883 | return -EOPNOTSUPP; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 884 | } |
| 885 | |
Jouni Malinen | 6ace289 | 2008-12-17 13:32:17 +0200 | [diff] [blame] | 886 | hk.kv_len = key->keylen; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 887 | memcpy(hk.kv_val, key->key, key->keylen); |
| 888 | |
Jouni Malinen | 6ace289 | 2008-12-17 13:32:17 +0200 | [diff] [blame] | 889 | if (!(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) { |
| 890 | /* For now, use the default keys for broadcast keys. This may |
| 891 | * need to change with virtual interfaces. */ |
| 892 | idx = key->keyidx; |
| 893 | } else if (key->keyidx) { |
Johannes Berg | dc822b5 | 2008-12-29 12:55:09 +0100 | [diff] [blame] | 894 | if (WARN_ON(!sta)) |
| 895 | return -EOPNOTSUPP; |
| 896 | mac = sta->addr; |
| 897 | |
Jouni Malinen | 6ace289 | 2008-12-17 13:32:17 +0200 | [diff] [blame] | 898 | if (vif->type != NL80211_IFTYPE_AP) { |
| 899 | /* Only keyidx 0 should be used with unicast key, but |
| 900 | * allow this for client mode for now. */ |
| 901 | idx = key->keyidx; |
| 902 | } else |
| 903 | return -EIO; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 904 | } else { |
Johannes Berg | dc822b5 | 2008-12-29 12:55:09 +0100 | [diff] [blame] | 905 | if (WARN_ON(!sta)) |
| 906 | return -EOPNOTSUPP; |
| 907 | mac = sta->addr; |
| 908 | |
Jouni Malinen | 6ace289 | 2008-12-17 13:32:17 +0200 | [diff] [blame] | 909 | if (key->alg == ALG_TKIP) |
| 910 | idx = ath_reserve_key_cache_slot_tkip(sc); |
| 911 | else |
| 912 | idx = ath_reserve_key_cache_slot(sc); |
| 913 | if (idx < 0) |
Jouni Malinen | ca470b2 | 2009-01-08 13:32:12 +0200 | [diff] [blame] | 914 | return -ENOSPC; /* no free key cache entries */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 915 | } |
| 916 | |
| 917 | if (key->alg == ALG_TKIP) |
Jouni Malinen | 3f53dd6 | 2009-02-26 11:18:46 +0200 | [diff] [blame] | 918 | ret = ath_setkey_tkip(sc, idx, key->key, &hk, mac, |
| 919 | vif->type == NL80211_IFTYPE_AP); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 920 | else |
Jouni Malinen | d216aaa | 2009-03-03 13:11:53 +0200 | [diff] [blame] | 921 | ret = ath9k_hw_set_keycache_entry(sc->sc_ah, idx, &hk, mac); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 922 | |
| 923 | if (!ret) |
| 924 | return -EIO; |
| 925 | |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 926 | set_bit(idx, sc->keymap); |
Jouni Malinen | 6ace289 | 2008-12-17 13:32:17 +0200 | [diff] [blame] | 927 | if (key->alg == ALG_TKIP) { |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 928 | set_bit(idx + 64, sc->keymap); |
| 929 | if (sc->splitmic) { |
| 930 | set_bit(idx + 32, sc->keymap); |
| 931 | set_bit(idx + 64 + 32, sc->keymap); |
Jouni Malinen | 6ace289 | 2008-12-17 13:32:17 +0200 | [diff] [blame] | 932 | } |
| 933 | } |
| 934 | |
| 935 | return idx; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 936 | } |
| 937 | |
| 938 | static void ath_key_delete(struct ath_softc *sc, struct ieee80211_key_conf *key) |
| 939 | { |
Jouni Malinen | 6ace289 | 2008-12-17 13:32:17 +0200 | [diff] [blame] | 940 | ath9k_hw_keyreset(sc->sc_ah, key->hw_key_idx); |
| 941 | if (key->hw_key_idx < IEEE80211_WEP_NKID) |
| 942 | return; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 943 | |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 944 | clear_bit(key->hw_key_idx, sc->keymap); |
Jouni Malinen | 6ace289 | 2008-12-17 13:32:17 +0200 | [diff] [blame] | 945 | if (key->alg != ALG_TKIP) |
| 946 | return; |
| 947 | |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 948 | clear_bit(key->hw_key_idx + 64, sc->keymap); |
| 949 | if (sc->splitmic) { |
| 950 | clear_bit(key->hw_key_idx + 32, sc->keymap); |
| 951 | clear_bit(key->hw_key_idx + 64 + 32, sc->keymap); |
Jouni Malinen | 6ace289 | 2008-12-17 13:32:17 +0200 | [diff] [blame] | 952 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 953 | } |
| 954 | |
Sujith | eb2599c | 2009-01-23 11:20:44 +0530 | [diff] [blame] | 955 | static void setup_ht_cap(struct ath_softc *sc, |
| 956 | struct ieee80211_sta_ht_cap *ht_info) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 957 | { |
Luis R. Rodriguez | 43c2761 | 2009-09-13 21:07:07 -0700 | [diff] [blame] | 958 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Senthil Balasubramanian | 140add2 | 2009-06-24 18:56:42 +0530 | [diff] [blame] | 959 | u8 tx_streams, rx_streams; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 960 | |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 961 | ht_info->ht_supported = true; |
| 962 | ht_info->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 | |
| 963 | IEEE80211_HT_CAP_SM_PS | |
| 964 | IEEE80211_HT_CAP_SGI_40 | |
| 965 | IEEE80211_HT_CAP_DSSSCCK40; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 966 | |
Sujith | 9e98ac6 | 2009-07-23 15:32:34 +0530 | [diff] [blame] | 967 | ht_info->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K; |
| 968 | ht_info->ampdu_density = IEEE80211_HT_MPDU_DENSITY_8; |
Sujith | eb2599c | 2009-01-23 11:20:44 +0530 | [diff] [blame] | 969 | |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 970 | /* set up supported mcs set */ |
| 971 | memset(&ht_info->mcs, 0, sizeof(ht_info->mcs)); |
Luis R. Rodriguez | 43c2761 | 2009-09-13 21:07:07 -0700 | [diff] [blame] | 972 | tx_streams = !(common->tx_chainmask & (common->tx_chainmask - 1)) ? |
| 973 | 1 : 2; |
| 974 | rx_streams = !(common->rx_chainmask & (common->rx_chainmask - 1)) ? |
| 975 | 1 : 2; |
Sujith | eb2599c | 2009-01-23 11:20:44 +0530 | [diff] [blame] | 976 | |
Senthil Balasubramanian | 140add2 | 2009-06-24 18:56:42 +0530 | [diff] [blame] | 977 | if (tx_streams != rx_streams) { |
Luis R. Rodriguez | 43c2761 | 2009-09-13 21:07:07 -0700 | [diff] [blame] | 978 | ath_print(common, ATH_DBG_CONFIG, |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 979 | "TX streams %d, RX streams: %d\n", |
| 980 | tx_streams, rx_streams); |
Senthil Balasubramanian | 140add2 | 2009-06-24 18:56:42 +0530 | [diff] [blame] | 981 | ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF; |
| 982 | ht_info->mcs.tx_params |= ((tx_streams - 1) << |
| 983 | IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT); |
Sujith | eb2599c | 2009-01-23 11:20:44 +0530 | [diff] [blame] | 984 | } |
| 985 | |
Senthil Balasubramanian | 140add2 | 2009-06-24 18:56:42 +0530 | [diff] [blame] | 986 | ht_info->mcs.rx_mask[0] = 0xff; |
| 987 | if (rx_streams >= 2) |
| 988 | ht_info->mcs.rx_mask[1] = 0xff; |
| 989 | |
| 990 | ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 991 | } |
| 992 | |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 993 | static void ath9k_bss_assoc_info(struct ath_softc *sc, |
Sujith | 5640b08 | 2008-10-29 10:16:06 +0530 | [diff] [blame] | 994 | struct ieee80211_vif *vif, |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 995 | struct ieee80211_bss_conf *bss_conf) |
| 996 | { |
Luis R. Rodriguez | f2b2143 | 2009-09-10 08:50:20 -0700 | [diff] [blame] | 997 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 998 | struct ath_common *common = ath9k_hw_common(ah); |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 999 | |
| 1000 | if (bss_conf->assoc) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1001 | ath_print(common, ATH_DBG_CONFIG, |
| 1002 | "Bss Info ASSOC %d, bssid: %pM\n", |
| 1003 | bss_conf->aid, common->curbssid); |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 1004 | |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 1005 | /* New association, store aid */ |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 1006 | common->curaid = bss_conf->aid; |
Luis R. Rodriguez | f2b2143 | 2009-09-10 08:50:20 -0700 | [diff] [blame] | 1007 | ath9k_hw_write_associd(ah); |
Jouni Malinen | ccdfeab | 2009-05-20 21:59:08 +0300 | [diff] [blame] | 1008 | |
Senthil Balasubramanian | 2664f20 | 2009-06-24 18:56:39 +0530 | [diff] [blame] | 1009 | /* |
| 1010 | * Request a re-configuration of Beacon related timers |
| 1011 | * on the receipt of the first Beacon frame (i.e., |
| 1012 | * after time sync with the AP). |
| 1013 | */ |
| 1014 | sc->sc_flags |= SC_OP_BEACON_SYNC; |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 1015 | |
| 1016 | /* Configure the beacon */ |
Jouni Malinen | 2c3db3d | 2009-03-03 19:23:26 +0200 | [diff] [blame] | 1017 | ath_beacon_config(sc, vif); |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 1018 | |
| 1019 | /* Reset rssi stats */ |
Vasanthakumar Thiagarajan | 22e66a4 | 2009-08-19 16:23:40 +0530 | [diff] [blame] | 1020 | sc->sc_ah->stats.avgbrssi = ATH_RSSI_DUMMY_MARKER; |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 1021 | |
Sujith | 415f738 | 2009-04-13 21:56:46 +0530 | [diff] [blame] | 1022 | ath_start_ani(sc); |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 1023 | } else { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1024 | ath_print(common, ATH_DBG_CONFIG, "Bss Info DISASSOC\n"); |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 1025 | common->curaid = 0; |
Senthil Balasubramanian | f38faa3 | 2009-06-24 18:56:40 +0530 | [diff] [blame] | 1026 | /* Stop ANI */ |
| 1027 | del_timer_sync(&sc->ani.timer); |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 1028 | } |
| 1029 | } |
| 1030 | |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 1031 | /********************************/ |
| 1032 | /* LED functions */ |
| 1033 | /********************************/ |
| 1034 | |
Vasanthakumar Thiagarajan | f2bffa7 | 2009-01-29 17:52:19 +0530 | [diff] [blame] | 1035 | static void ath_led_blink_work(struct work_struct *work) |
| 1036 | { |
| 1037 | struct ath_softc *sc = container_of(work, struct ath_softc, |
| 1038 | ath_led_blink_work.work); |
| 1039 | |
| 1040 | if (!(sc->sc_flags & SC_OP_LED_ASSOCIATED)) |
| 1041 | return; |
Vasanthakumar Thiagarajan | 85067c0 | 2009-03-14 19:59:41 +0530 | [diff] [blame] | 1042 | |
| 1043 | if ((sc->led_on_duration == ATH_LED_ON_DURATION_IDLE) || |
| 1044 | (sc->led_off_duration == ATH_LED_OFF_DURATION_IDLE)) |
Vivek Natarajan | 08fc5c1 | 2009-08-14 11:30:52 +0530 | [diff] [blame] | 1045 | ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 0); |
Vasanthakumar Thiagarajan | 85067c0 | 2009-03-14 19:59:41 +0530 | [diff] [blame] | 1046 | else |
Vivek Natarajan | 08fc5c1 | 2009-08-14 11:30:52 +0530 | [diff] [blame] | 1047 | ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, |
Vasanthakumar Thiagarajan | 85067c0 | 2009-03-14 19:59:41 +0530 | [diff] [blame] | 1048 | (sc->sc_flags & SC_OP_LED_ON) ? 1 : 0); |
Vasanthakumar Thiagarajan | f2bffa7 | 2009-01-29 17:52:19 +0530 | [diff] [blame] | 1049 | |
Luis R. Rodriguez | 42935ec | 2009-07-29 20:08:07 -0400 | [diff] [blame] | 1050 | ieee80211_queue_delayed_work(sc->hw, |
| 1051 | &sc->ath_led_blink_work, |
| 1052 | (sc->sc_flags & SC_OP_LED_ON) ? |
| 1053 | msecs_to_jiffies(sc->led_off_duration) : |
| 1054 | msecs_to_jiffies(sc->led_on_duration)); |
Vasanthakumar Thiagarajan | f2bffa7 | 2009-01-29 17:52:19 +0530 | [diff] [blame] | 1055 | |
Vasanthakumar Thiagarajan | 85067c0 | 2009-03-14 19:59:41 +0530 | [diff] [blame] | 1056 | sc->led_on_duration = sc->led_on_cnt ? |
| 1057 | max((ATH_LED_ON_DURATION_IDLE - sc->led_on_cnt), 25) : |
| 1058 | ATH_LED_ON_DURATION_IDLE; |
| 1059 | sc->led_off_duration = sc->led_off_cnt ? |
| 1060 | max((ATH_LED_OFF_DURATION_IDLE - sc->led_off_cnt), 10) : |
| 1061 | ATH_LED_OFF_DURATION_IDLE; |
Vasanthakumar Thiagarajan | f2bffa7 | 2009-01-29 17:52:19 +0530 | [diff] [blame] | 1062 | sc->led_on_cnt = sc->led_off_cnt = 0; |
| 1063 | if (sc->sc_flags & SC_OP_LED_ON) |
| 1064 | sc->sc_flags &= ~SC_OP_LED_ON; |
| 1065 | else |
| 1066 | sc->sc_flags |= SC_OP_LED_ON; |
| 1067 | } |
| 1068 | |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 1069 | static void ath_led_brightness(struct led_classdev *led_cdev, |
| 1070 | enum led_brightness brightness) |
| 1071 | { |
| 1072 | struct ath_led *led = container_of(led_cdev, struct ath_led, led_cdev); |
| 1073 | struct ath_softc *sc = led->sc; |
| 1074 | |
| 1075 | switch (brightness) { |
| 1076 | case LED_OFF: |
| 1077 | if (led->led_type == ATH_LED_ASSOC || |
Vasanthakumar Thiagarajan | f2bffa7 | 2009-01-29 17:52:19 +0530 | [diff] [blame] | 1078 | led->led_type == ATH_LED_RADIO) { |
Vivek Natarajan | 08fc5c1 | 2009-08-14 11:30:52 +0530 | [diff] [blame] | 1079 | ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, |
Vasanthakumar Thiagarajan | f2bffa7 | 2009-01-29 17:52:19 +0530 | [diff] [blame] | 1080 | (led->led_type == ATH_LED_RADIO)); |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 1081 | sc->sc_flags &= ~SC_OP_LED_ASSOCIATED; |
Vasanthakumar Thiagarajan | f2bffa7 | 2009-01-29 17:52:19 +0530 | [diff] [blame] | 1082 | if (led->led_type == ATH_LED_RADIO) |
| 1083 | sc->sc_flags &= ~SC_OP_LED_ON; |
| 1084 | } else { |
| 1085 | sc->led_off_cnt++; |
| 1086 | } |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 1087 | break; |
| 1088 | case LED_FULL: |
Vasanthakumar Thiagarajan | f2bffa7 | 2009-01-29 17:52:19 +0530 | [diff] [blame] | 1089 | if (led->led_type == ATH_LED_ASSOC) { |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 1090 | sc->sc_flags |= SC_OP_LED_ASSOCIATED; |
Luis R. Rodriguez | 42935ec | 2009-07-29 20:08:07 -0400 | [diff] [blame] | 1091 | ieee80211_queue_delayed_work(sc->hw, |
| 1092 | &sc->ath_led_blink_work, 0); |
Vasanthakumar Thiagarajan | f2bffa7 | 2009-01-29 17:52:19 +0530 | [diff] [blame] | 1093 | } else if (led->led_type == ATH_LED_RADIO) { |
Vivek Natarajan | 08fc5c1 | 2009-08-14 11:30:52 +0530 | [diff] [blame] | 1094 | ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 0); |
Vasanthakumar Thiagarajan | f2bffa7 | 2009-01-29 17:52:19 +0530 | [diff] [blame] | 1095 | sc->sc_flags |= SC_OP_LED_ON; |
| 1096 | } else { |
| 1097 | sc->led_on_cnt++; |
| 1098 | } |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 1099 | break; |
| 1100 | default: |
| 1101 | break; |
| 1102 | } |
| 1103 | } |
| 1104 | |
| 1105 | static int ath_register_led(struct ath_softc *sc, struct ath_led *led, |
| 1106 | char *trigger) |
| 1107 | { |
| 1108 | int ret; |
| 1109 | |
| 1110 | led->sc = sc; |
| 1111 | led->led_cdev.name = led->name; |
| 1112 | led->led_cdev.default_trigger = trigger; |
| 1113 | led->led_cdev.brightness_set = ath_led_brightness; |
| 1114 | |
| 1115 | ret = led_classdev_register(wiphy_dev(sc->hw->wiphy), &led->led_cdev); |
| 1116 | if (ret) |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1117 | ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_FATAL, |
| 1118 | "Failed to register led:%s", led->name); |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 1119 | else |
| 1120 | led->registered = 1; |
| 1121 | return ret; |
| 1122 | } |
| 1123 | |
| 1124 | static void ath_unregister_led(struct ath_led *led) |
| 1125 | { |
| 1126 | if (led->registered) { |
| 1127 | led_classdev_unregister(&led->led_cdev); |
| 1128 | led->registered = 0; |
| 1129 | } |
| 1130 | } |
| 1131 | |
| 1132 | static void ath_deinit_leds(struct ath_softc *sc) |
| 1133 | { |
| 1134 | ath_unregister_led(&sc->assoc_led); |
| 1135 | sc->sc_flags &= ~SC_OP_LED_ASSOCIATED; |
| 1136 | ath_unregister_led(&sc->tx_led); |
| 1137 | ath_unregister_led(&sc->rx_led); |
| 1138 | ath_unregister_led(&sc->radio_led); |
Vivek Natarajan | 08fc5c1 | 2009-08-14 11:30:52 +0530 | [diff] [blame] | 1139 | ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 1); |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 1140 | } |
| 1141 | |
| 1142 | static void ath_init_leds(struct ath_softc *sc) |
| 1143 | { |
| 1144 | char *trigger; |
| 1145 | int ret; |
| 1146 | |
Vivek Natarajan | 08fc5c1 | 2009-08-14 11:30:52 +0530 | [diff] [blame] | 1147 | if (AR_SREV_9287(sc->sc_ah)) |
| 1148 | sc->sc_ah->led_pin = ATH_LED_PIN_9287; |
| 1149 | else |
| 1150 | sc->sc_ah->led_pin = ATH_LED_PIN_DEF; |
| 1151 | |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 1152 | /* Configure gpio 1 for output */ |
Vivek Natarajan | 08fc5c1 | 2009-08-14 11:30:52 +0530 | [diff] [blame] | 1153 | ath9k_hw_cfg_output(sc->sc_ah, sc->sc_ah->led_pin, |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 1154 | AR_GPIO_OUTPUT_MUX_AS_OUTPUT); |
| 1155 | /* LED off, active low */ |
Vivek Natarajan | 08fc5c1 | 2009-08-14 11:30:52 +0530 | [diff] [blame] | 1156 | ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 1); |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 1157 | |
Vasanthakumar Thiagarajan | f2bffa7 | 2009-01-29 17:52:19 +0530 | [diff] [blame] | 1158 | INIT_DELAYED_WORK(&sc->ath_led_blink_work, ath_led_blink_work); |
| 1159 | |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 1160 | trigger = ieee80211_get_radio_led_name(sc->hw); |
| 1161 | snprintf(sc->radio_led.name, sizeof(sc->radio_led.name), |
Danny Kukawka | 0818cb8 | 2009-01-31 15:52:09 +0100 | [diff] [blame] | 1162 | "ath9k-%s::radio", wiphy_name(sc->hw->wiphy)); |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 1163 | ret = ath_register_led(sc, &sc->radio_led, trigger); |
| 1164 | sc->radio_led.led_type = ATH_LED_RADIO; |
| 1165 | if (ret) |
| 1166 | goto fail; |
| 1167 | |
| 1168 | trigger = ieee80211_get_assoc_led_name(sc->hw); |
| 1169 | snprintf(sc->assoc_led.name, sizeof(sc->assoc_led.name), |
Danny Kukawka | 0818cb8 | 2009-01-31 15:52:09 +0100 | [diff] [blame] | 1170 | "ath9k-%s::assoc", wiphy_name(sc->hw->wiphy)); |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 1171 | ret = ath_register_led(sc, &sc->assoc_led, trigger); |
| 1172 | sc->assoc_led.led_type = ATH_LED_ASSOC; |
| 1173 | if (ret) |
| 1174 | goto fail; |
| 1175 | |
| 1176 | trigger = ieee80211_get_tx_led_name(sc->hw); |
| 1177 | snprintf(sc->tx_led.name, sizeof(sc->tx_led.name), |
Danny Kukawka | 0818cb8 | 2009-01-31 15:52:09 +0100 | [diff] [blame] | 1178 | "ath9k-%s::tx", wiphy_name(sc->hw->wiphy)); |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 1179 | ret = ath_register_led(sc, &sc->tx_led, trigger); |
| 1180 | sc->tx_led.led_type = ATH_LED_TX; |
| 1181 | if (ret) |
| 1182 | goto fail; |
| 1183 | |
| 1184 | trigger = ieee80211_get_rx_led_name(sc->hw); |
| 1185 | snprintf(sc->rx_led.name, sizeof(sc->rx_led.name), |
Danny Kukawka | 0818cb8 | 2009-01-31 15:52:09 +0100 | [diff] [blame] | 1186 | "ath9k-%s::rx", wiphy_name(sc->hw->wiphy)); |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 1187 | ret = ath_register_led(sc, &sc->rx_led, trigger); |
| 1188 | sc->rx_led.led_type = ATH_LED_RX; |
| 1189 | if (ret) |
| 1190 | goto fail; |
| 1191 | |
| 1192 | return; |
| 1193 | |
| 1194 | fail: |
Luis R. Rodriguez | 35c95ab | 2009-07-27 11:53:03 -0700 | [diff] [blame] | 1195 | cancel_delayed_work_sync(&sc->ath_led_blink_work); |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 1196 | ath_deinit_leds(sc); |
| 1197 | } |
| 1198 | |
Jouni Malinen | 7ec3e51 | 2009-03-03 19:23:37 +0200 | [diff] [blame] | 1199 | void ath_radio_enable(struct ath_softc *sc) |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 1200 | { |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1201 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1202 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 1203 | struct ieee80211_channel *channel = sc->hw->conf.channel; |
| 1204 | int r; |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 1205 | |
Vivek Natarajan | 3cbb5dd | 2009-01-20 11:17:08 +0530 | [diff] [blame] | 1206 | ath9k_ps_wakeup(sc); |
Vivek Natarajan | 93b1b37 | 2009-09-17 09:24:58 +0530 | [diff] [blame] | 1207 | ath9k_hw_configpcipowersave(ah, 0, 0); |
Sujith | d2f5b3a | 2009-04-13 21:56:25 +0530 | [diff] [blame] | 1208 | |
Vasanthakumar Thiagarajan | 159cd46 | 2009-06-13 14:50:25 +0530 | [diff] [blame] | 1209 | if (!ah->curchan) |
| 1210 | ah->curchan = ath_get_curchannel(sc, sc->hw); |
| 1211 | |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 1212 | spin_lock_bh(&sc->sc_resetlock); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1213 | r = ath9k_hw_reset(ah, ah->curchan, false); |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 1214 | if (r) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1215 | ath_print(common, ATH_DBG_FATAL, |
| 1216 | "Unable to reset channel %u (%uMhz) ", |
| 1217 | "reset status %d\n", |
| 1218 | channel->center_freq, r); |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 1219 | } |
| 1220 | spin_unlock_bh(&sc->sc_resetlock); |
| 1221 | |
| 1222 | ath_update_txpow(sc); |
| 1223 | if (ath_startrecv(sc) != 0) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1224 | ath_print(common, ATH_DBG_FATAL, |
| 1225 | "Unable to restart recv logic\n"); |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 1226 | return; |
| 1227 | } |
| 1228 | |
| 1229 | if (sc->sc_flags & SC_OP_BEACONS) |
Jouni Malinen | 2c3db3d | 2009-03-03 19:23:26 +0200 | [diff] [blame] | 1230 | ath_beacon_config(sc, NULL); /* restart beacons */ |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 1231 | |
| 1232 | /* Re-Enable interrupts */ |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 1233 | ath9k_hw_set_interrupts(ah, sc->imask); |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 1234 | |
| 1235 | /* Enable LED */ |
Vivek Natarajan | 08fc5c1 | 2009-08-14 11:30:52 +0530 | [diff] [blame] | 1236 | ath9k_hw_cfg_output(ah, ah->led_pin, |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 1237 | AR_GPIO_OUTPUT_MUX_AS_OUTPUT); |
Vivek Natarajan | 08fc5c1 | 2009-08-14 11:30:52 +0530 | [diff] [blame] | 1238 | ath9k_hw_set_gpio(ah, ah->led_pin, 0); |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 1239 | |
| 1240 | ieee80211_wake_queues(sc->hw); |
Vivek Natarajan | 3cbb5dd | 2009-01-20 11:17:08 +0530 | [diff] [blame] | 1241 | ath9k_ps_restore(sc); |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 1242 | } |
| 1243 | |
Jouni Malinen | 7ec3e51 | 2009-03-03 19:23:37 +0200 | [diff] [blame] | 1244 | void ath_radio_disable(struct ath_softc *sc) |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 1245 | { |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1246 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 1247 | struct ieee80211_channel *channel = sc->hw->conf.channel; |
| 1248 | int r; |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 1249 | |
Vivek Natarajan | 3cbb5dd | 2009-01-20 11:17:08 +0530 | [diff] [blame] | 1250 | ath9k_ps_wakeup(sc); |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 1251 | ieee80211_stop_queues(sc->hw); |
| 1252 | |
| 1253 | /* Disable LED */ |
Vivek Natarajan | 08fc5c1 | 2009-08-14 11:30:52 +0530 | [diff] [blame] | 1254 | ath9k_hw_set_gpio(ah, ah->led_pin, 1); |
| 1255 | ath9k_hw_cfg_gpio_input(ah, ah->led_pin); |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 1256 | |
| 1257 | /* Disable interrupts */ |
| 1258 | ath9k_hw_set_interrupts(ah, 0); |
| 1259 | |
Sujith | 043a040 | 2009-01-16 21:38:47 +0530 | [diff] [blame] | 1260 | ath_drain_all_txq(sc, false); /* clear pending tx frames */ |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 1261 | ath_stoprecv(sc); /* turn off frame recv */ |
| 1262 | ath_flushrecv(sc); /* flush recv queue */ |
| 1263 | |
Vasanthakumar Thiagarajan | 159cd46 | 2009-06-13 14:50:25 +0530 | [diff] [blame] | 1264 | if (!ah->curchan) |
| 1265 | ah->curchan = ath_get_curchannel(sc, sc->hw); |
| 1266 | |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 1267 | spin_lock_bh(&sc->sc_resetlock); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1268 | r = ath9k_hw_reset(ah, ah->curchan, false); |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 1269 | if (r) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1270 | ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_FATAL, |
| 1271 | "Unable to reset channel %u (%uMhz) " |
| 1272 | "reset status %d\n", |
| 1273 | channel->center_freq, r); |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 1274 | } |
| 1275 | spin_unlock_bh(&sc->sc_resetlock); |
| 1276 | |
| 1277 | ath9k_hw_phy_disable(ah); |
Vivek Natarajan | 93b1b37 | 2009-09-17 09:24:58 +0530 | [diff] [blame] | 1278 | ath9k_hw_configpcipowersave(ah, 1, 1); |
Vivek Natarajan | 3cbb5dd | 2009-01-20 11:17:08 +0530 | [diff] [blame] | 1279 | ath9k_ps_restore(sc); |
Luis R. Rodriguez | 9ecdef4 | 2009-09-09 21:10:09 -0700 | [diff] [blame] | 1280 | ath9k_setpower(sc, ATH9K_PM_FULL_SLEEP); |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 1281 | } |
| 1282 | |
Gabor Juhos | 5077fd3 | 2009-03-06 11:17:55 +0100 | [diff] [blame] | 1283 | /*******************/ |
| 1284 | /* Rfkill */ |
| 1285 | /*******************/ |
| 1286 | |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 1287 | static bool ath_is_rfkill_set(struct ath_softc *sc) |
| 1288 | { |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1289 | struct ath_hw *ah = sc->sc_ah; |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 1290 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1291 | return ath9k_hw_gpio_get(ah, ah->rfkill_gpio) == |
| 1292 | ah->rfkill_polarity; |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 1293 | } |
| 1294 | |
Johannes Berg | 3b319aa | 2009-06-13 14:50:26 +0530 | [diff] [blame] | 1295 | static void ath9k_rfkill_poll_state(struct ieee80211_hw *hw) |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 1296 | { |
Johannes Berg | 3b319aa | 2009-06-13 14:50:26 +0530 | [diff] [blame] | 1297 | struct ath_wiphy *aphy = hw->priv; |
| 1298 | struct ath_softc *sc = aphy->sc; |
| 1299 | bool blocked = !!ath_is_rfkill_set(sc); |
| 1300 | |
| 1301 | wiphy_rfkill_set_hw_state(hw->wiphy, blocked); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1302 | } |
| 1303 | |
Johannes Berg | 3b319aa | 2009-06-13 14:50:26 +0530 | [diff] [blame] | 1304 | static void ath_start_rfkill_poll(struct ath_softc *sc) |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1305 | { |
Johannes Berg | 3b319aa | 2009-06-13 14:50:26 +0530 | [diff] [blame] | 1306 | struct ath_hw *ah = sc->sc_ah; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1307 | |
Johannes Berg | 3b319aa | 2009-06-13 14:50:26 +0530 | [diff] [blame] | 1308 | if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT) |
| 1309 | wiphy_rfkill_start_polling(sc->hw->wiphy); |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 1310 | } |
| 1311 | |
Gabor Juhos | 6baff7f | 2009-01-14 20:17:06 +0100 | [diff] [blame] | 1312 | void ath_cleanup(struct ath_softc *sc) |
Gabor Juhos | 39c3c2f | 2009-01-14 20:17:05 +0100 | [diff] [blame] | 1313 | { |
Luis R. Rodriguez | 5bb1279 | 2009-09-14 00:55:09 -0700 | [diff] [blame] | 1314 | struct ath_hw *ah = sc->sc_ah; |
| 1315 | struct ath_common *common = ath9k_hw_common(ah); |
| 1316 | |
Gabor Juhos | 39c3c2f | 2009-01-14 20:17:05 +0100 | [diff] [blame] | 1317 | ath_detach(sc); |
| 1318 | free_irq(sc->irq, sc); |
Luis R. Rodriguez | 5bb1279 | 2009-09-14 00:55:09 -0700 | [diff] [blame] | 1319 | ath_bus_cleanup(common); |
Jouni Malinen | c52f33d | 2009-03-03 19:23:29 +0200 | [diff] [blame] | 1320 | kfree(sc->sec_wiphy); |
Gabor Juhos | 39c3c2f | 2009-01-14 20:17:05 +0100 | [diff] [blame] | 1321 | ieee80211_free_hw(sc->hw); |
| 1322 | } |
| 1323 | |
Gabor Juhos | 6baff7f | 2009-01-14 20:17:06 +0100 | [diff] [blame] | 1324 | void ath_detach(struct ath_softc *sc) |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 1325 | { |
| 1326 | struct ieee80211_hw *hw = sc->hw; |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 1327 | struct ath_hw *ah = sc->sc_ah; |
Sujith | 9c84b79 | 2008-10-29 10:17:13 +0530 | [diff] [blame] | 1328 | int i = 0; |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 1329 | |
Vivek Natarajan | 3cbb5dd | 2009-01-20 11:17:08 +0530 | [diff] [blame] | 1330 | ath9k_ps_wakeup(sc); |
| 1331 | |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 1332 | dev_dbg(sc->dev, "Detach ATH hw\n"); |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 1333 | |
Luis R. Rodriguez | 35c95ab | 2009-07-27 11:53:03 -0700 | [diff] [blame] | 1334 | ath_deinit_leds(sc); |
Sujith | e31f7b9 | 2009-09-23 13:49:12 +0530 | [diff] [blame] | 1335 | wiphy_rfkill_stop_polling(sc->hw->wiphy); |
Luis R. Rodriguez | 35c95ab | 2009-07-27 11:53:03 -0700 | [diff] [blame] | 1336 | |
Jouni Malinen | c52f33d | 2009-03-03 19:23:29 +0200 | [diff] [blame] | 1337 | for (i = 0; i < sc->num_sec_wiphy; i++) { |
| 1338 | struct ath_wiphy *aphy = sc->sec_wiphy[i]; |
| 1339 | if (aphy == NULL) |
| 1340 | continue; |
| 1341 | sc->sec_wiphy[i] = NULL; |
| 1342 | ieee80211_unregister_hw(aphy->hw); |
| 1343 | ieee80211_free_hw(aphy->hw); |
| 1344 | } |
Vasanthakumar Thiagarajan | 3fcdfb4 | 2008-11-18 01:19:56 +0530 | [diff] [blame] | 1345 | ieee80211_unregister_hw(hw); |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 1346 | ath_rx_cleanup(sc); |
| 1347 | ath_tx_cleanup(sc); |
| 1348 | |
Sujith | 9c84b79 | 2008-10-29 10:17:13 +0530 | [diff] [blame] | 1349 | tasklet_kill(&sc->intr_tq); |
| 1350 | tasklet_kill(&sc->bcon_tasklet); |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 1351 | |
Sujith | 9c84b79 | 2008-10-29 10:17:13 +0530 | [diff] [blame] | 1352 | if (!(sc->sc_flags & SC_OP_INVALID)) |
Luis R. Rodriguez | 9ecdef4 | 2009-09-09 21:10:09 -0700 | [diff] [blame] | 1353 | ath9k_setpower(sc, ATH9K_PM_AWAKE); |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 1354 | |
Sujith | 9c84b79 | 2008-10-29 10:17:13 +0530 | [diff] [blame] | 1355 | /* cleanup tx queues */ |
| 1356 | for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) |
| 1357 | if (ATH_TXQ_SETUP(sc, i)) |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 1358 | ath_tx_cleanupq(sc, &sc->tx.txq[i]); |
Sujith | 9c84b79 | 2008-10-29 10:17:13 +0530 | [diff] [blame] | 1359 | |
Luis R. Rodriguez | 75d7839 | 2009-09-09 04:00:10 -0700 | [diff] [blame] | 1360 | if ((sc->btcoex.no_stomp_timer) && |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 1361 | ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE) |
Luis R. Rodriguez | 75d7839 | 2009-09-09 04:00:10 -0700 | [diff] [blame] | 1362 | ath_gen_timer_free(ah, sc->btcoex.no_stomp_timer); |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 1363 | |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 1364 | ath9k_hw_detach(ah); |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 1365 | ath9k_exit_debug(ah); |
Luis R. Rodriguez | 3ce1b1a | 2009-08-03 12:24:53 -0700 | [diff] [blame] | 1366 | sc->sc_ah = NULL; |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 1367 | } |
| 1368 | |
Bob Copeland | e3bb249 | 2009-03-30 22:30:30 -0400 | [diff] [blame] | 1369 | static int ath9k_reg_notifier(struct wiphy *wiphy, |
| 1370 | struct regulatory_request *request) |
| 1371 | { |
| 1372 | struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy); |
| 1373 | struct ath_wiphy *aphy = hw->priv; |
| 1374 | struct ath_softc *sc = aphy->sc; |
Luis R. Rodriguez | 27c51f1 | 2009-09-10 11:08:14 -0700 | [diff] [blame] | 1375 | struct ath_regulatory *reg = ath9k_hw_regulatory(sc->sc_ah); |
Bob Copeland | e3bb249 | 2009-03-30 22:30:30 -0400 | [diff] [blame] | 1376 | |
| 1377 | return ath_reg_notifier_apply(wiphy, request, reg); |
| 1378 | } |
| 1379 | |
Luis R. Rodriguez | 1e40bcf | 2009-08-03 12:24:47 -0700 | [diff] [blame] | 1380 | /* |
Luis R. Rodriguez | 75d7839 | 2009-09-09 04:00:10 -0700 | [diff] [blame] | 1381 | * Detects if there is any priority bt traffic |
| 1382 | */ |
| 1383 | static void ath_detect_bt_priority(struct ath_softc *sc) |
| 1384 | { |
| 1385 | struct ath_btcoex *btcoex = &sc->btcoex; |
| 1386 | struct ath_hw *ah = sc->sc_ah; |
| 1387 | |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 1388 | if (ath9k_hw_gpio_get(sc->sc_ah, ah->btcoex_hw.btpriority_gpio)) |
Luis R. Rodriguez | 75d7839 | 2009-09-09 04:00:10 -0700 | [diff] [blame] | 1389 | btcoex->bt_priority_cnt++; |
| 1390 | |
| 1391 | if (time_after(jiffies, btcoex->bt_priority_time + |
| 1392 | msecs_to_jiffies(ATH_BT_PRIORITY_TIME_THRESHOLD))) { |
| 1393 | if (btcoex->bt_priority_cnt >= ATH_BT_CNT_THRESHOLD) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1394 | ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_BTCOEX, |
| 1395 | "BT priority traffic detected"); |
Luis R. Rodriguez | 75d7839 | 2009-09-09 04:00:10 -0700 | [diff] [blame] | 1396 | sc->sc_flags |= SC_OP_BT_PRIORITY_DETECTED; |
| 1397 | } else { |
| 1398 | sc->sc_flags &= ~SC_OP_BT_PRIORITY_DETECTED; |
| 1399 | } |
| 1400 | |
| 1401 | btcoex->bt_priority_cnt = 0; |
| 1402 | btcoex->bt_priority_time = jiffies; |
| 1403 | } |
| 1404 | } |
| 1405 | |
Luis R. Rodriguez | 75d7839 | 2009-09-09 04:00:10 -0700 | [diff] [blame] | 1406 | /* |
| 1407 | * Configures appropriate weight based on stomp type. |
| 1408 | */ |
Luis R. Rodriguez | 269ad81 | 2009-09-09 15:05:00 -0700 | [diff] [blame] | 1409 | static void ath9k_btcoex_bt_stomp(struct ath_softc *sc, |
| 1410 | enum ath_stomp_type stomp_type) |
Luis R. Rodriguez | 75d7839 | 2009-09-09 04:00:10 -0700 | [diff] [blame] | 1411 | { |
Luis R. Rodriguez | 269ad81 | 2009-09-09 15:05:00 -0700 | [diff] [blame] | 1412 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | 75d7839 | 2009-09-09 04:00:10 -0700 | [diff] [blame] | 1413 | |
| 1414 | switch (stomp_type) { |
| 1415 | case ATH_BTCOEX_STOMP_ALL: |
Luis R. Rodriguez | 269ad81 | 2009-09-09 15:05:00 -0700 | [diff] [blame] | 1416 | ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT, |
| 1417 | AR_STOMP_ALL_WLAN_WGHT); |
Luis R. Rodriguez | 75d7839 | 2009-09-09 04:00:10 -0700 | [diff] [blame] | 1418 | break; |
| 1419 | case ATH_BTCOEX_STOMP_LOW: |
Luis R. Rodriguez | 269ad81 | 2009-09-09 15:05:00 -0700 | [diff] [blame] | 1420 | ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT, |
| 1421 | AR_STOMP_LOW_WLAN_WGHT); |
Luis R. Rodriguez | 75d7839 | 2009-09-09 04:00:10 -0700 | [diff] [blame] | 1422 | break; |
| 1423 | case ATH_BTCOEX_STOMP_NONE: |
Luis R. Rodriguez | 269ad81 | 2009-09-09 15:05:00 -0700 | [diff] [blame] | 1424 | ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT, |
| 1425 | AR_STOMP_NONE_WLAN_WGHT); |
Luis R. Rodriguez | 75d7839 | 2009-09-09 04:00:10 -0700 | [diff] [blame] | 1426 | break; |
| 1427 | default: |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1428 | ath_print(ath9k_hw_common(ah), ATH_DBG_BTCOEX, |
| 1429 | "Invalid Stomptype\n"); |
Luis R. Rodriguez | 75d7839 | 2009-09-09 04:00:10 -0700 | [diff] [blame] | 1430 | break; |
| 1431 | } |
| 1432 | |
Luis R. Rodriguez | 269ad81 | 2009-09-09 15:05:00 -0700 | [diff] [blame] | 1433 | ath9k_hw_btcoex_enable(ah); |
Luis R. Rodriguez | 75d7839 | 2009-09-09 04:00:10 -0700 | [diff] [blame] | 1434 | } |
| 1435 | |
Luis R. Rodriguez | cd9bf68 | 2009-09-13 02:08:34 -0700 | [diff] [blame] | 1436 | static void ath9k_gen_timer_start(struct ath_hw *ah, |
| 1437 | struct ath_gen_timer *timer, |
| 1438 | u32 timer_next, |
| 1439 | u32 timer_period) |
| 1440 | { |
| 1441 | ath9k_hw_gen_timer_start(ah, timer, timer_next, timer_period); |
| 1442 | |
| 1443 | if ((ah->ah_sc->imask & ATH9K_INT_GENTIMER) == 0) { |
| 1444 | ath9k_hw_set_interrupts(ah, 0); |
| 1445 | ah->ah_sc->imask |= ATH9K_INT_GENTIMER; |
| 1446 | ath9k_hw_set_interrupts(ah, ah->ah_sc->imask); |
| 1447 | } |
| 1448 | } |
| 1449 | |
| 1450 | static void ath9k_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer) |
| 1451 | { |
| 1452 | struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers; |
| 1453 | |
| 1454 | ath9k_hw_gen_timer_stop(ah, timer); |
| 1455 | |
| 1456 | /* if no timer is enabled, turn off interrupt mask */ |
| 1457 | if (timer_table->timer_mask.val == 0) { |
| 1458 | ath9k_hw_set_interrupts(ah, 0); |
| 1459 | ah->ah_sc->imask &= ~ATH9K_INT_GENTIMER; |
| 1460 | ath9k_hw_set_interrupts(ah, ah->ah_sc->imask); |
| 1461 | } |
| 1462 | } |
| 1463 | |
Luis R. Rodriguez | 75d7839 | 2009-09-09 04:00:10 -0700 | [diff] [blame] | 1464 | /* |
| 1465 | * This is the master bt coex timer which runs for every |
| 1466 | * 45ms, bt traffic will be given priority during 55% of this |
| 1467 | * period while wlan gets remaining 45% |
| 1468 | */ |
| 1469 | static void ath_btcoex_period_timer(unsigned long data) |
| 1470 | { |
| 1471 | struct ath_softc *sc = (struct ath_softc *) data; |
| 1472 | struct ath_hw *ah = sc->sc_ah; |
| 1473 | struct ath_btcoex *btcoex = &sc->btcoex; |
Luis R. Rodriguez | 75d7839 | 2009-09-09 04:00:10 -0700 | [diff] [blame] | 1474 | |
| 1475 | ath_detect_bt_priority(sc); |
| 1476 | |
| 1477 | spin_lock_bh(&btcoex->btcoex_lock); |
| 1478 | |
Luis R. Rodriguez | 269ad81 | 2009-09-09 15:05:00 -0700 | [diff] [blame] | 1479 | ath9k_btcoex_bt_stomp(sc, btcoex->bt_stomp_type); |
Luis R. Rodriguez | 75d7839 | 2009-09-09 04:00:10 -0700 | [diff] [blame] | 1480 | |
| 1481 | spin_unlock_bh(&btcoex->btcoex_lock); |
| 1482 | |
| 1483 | if (btcoex->btcoex_period != btcoex->btcoex_no_stomp) { |
| 1484 | if (btcoex->hw_timer_enabled) |
Luis R. Rodriguez | cd9bf68 | 2009-09-13 02:08:34 -0700 | [diff] [blame] | 1485 | ath9k_gen_timer_stop(ah, btcoex->no_stomp_timer); |
Luis R. Rodriguez | 75d7839 | 2009-09-09 04:00:10 -0700 | [diff] [blame] | 1486 | |
Luis R. Rodriguez | cd9bf68 | 2009-09-13 02:08:34 -0700 | [diff] [blame] | 1487 | ath9k_gen_timer_start(ah, |
| 1488 | btcoex->no_stomp_timer, |
| 1489 | (ath9k_hw_gettsf32(ah) + |
| 1490 | btcoex->btcoex_no_stomp), |
| 1491 | btcoex->btcoex_no_stomp * 10); |
Luis R. Rodriguez | 75d7839 | 2009-09-09 04:00:10 -0700 | [diff] [blame] | 1492 | btcoex->hw_timer_enabled = true; |
| 1493 | } |
| 1494 | |
| 1495 | mod_timer(&btcoex->period_timer, jiffies + |
| 1496 | msecs_to_jiffies(ATH_BTCOEX_DEF_BT_PERIOD)); |
| 1497 | } |
| 1498 | |
| 1499 | /* |
| 1500 | * Generic tsf based hw timer which configures weight |
| 1501 | * registers to time slice between wlan and bt traffic |
| 1502 | */ |
| 1503 | static void ath_btcoex_no_stomp_timer(void *arg) |
| 1504 | { |
| 1505 | struct ath_softc *sc = (struct ath_softc *)arg; |
| 1506 | struct ath_hw *ah = sc->sc_ah; |
| 1507 | struct ath_btcoex *btcoex = &sc->btcoex; |
Luis R. Rodriguez | 75d7839 | 2009-09-09 04:00:10 -0700 | [diff] [blame] | 1508 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1509 | ath_print(ath9k_hw_common(ah), ATH_DBG_BTCOEX, |
| 1510 | "no stomp timer running \n"); |
Luis R. Rodriguez | 75d7839 | 2009-09-09 04:00:10 -0700 | [diff] [blame] | 1511 | |
| 1512 | spin_lock_bh(&btcoex->btcoex_lock); |
| 1513 | |
Luis R. Rodriguez | e08a6ac | 2009-09-09 14:26:15 -0700 | [diff] [blame] | 1514 | if (btcoex->bt_stomp_type == ATH_BTCOEX_STOMP_LOW) |
Luis R. Rodriguez | 269ad81 | 2009-09-09 15:05:00 -0700 | [diff] [blame] | 1515 | ath9k_btcoex_bt_stomp(sc, ATH_BTCOEX_STOMP_NONE); |
Luis R. Rodriguez | e08a6ac | 2009-09-09 14:26:15 -0700 | [diff] [blame] | 1516 | else if (btcoex->bt_stomp_type == ATH_BTCOEX_STOMP_ALL) |
Luis R. Rodriguez | 269ad81 | 2009-09-09 15:05:00 -0700 | [diff] [blame] | 1517 | ath9k_btcoex_bt_stomp(sc, ATH_BTCOEX_STOMP_LOW); |
Luis R. Rodriguez | 75d7839 | 2009-09-09 04:00:10 -0700 | [diff] [blame] | 1518 | |
| 1519 | spin_unlock_bh(&btcoex->btcoex_lock); |
| 1520 | } |
| 1521 | |
| 1522 | static int ath_init_btcoex_timer(struct ath_softc *sc) |
| 1523 | { |
| 1524 | struct ath_btcoex *btcoex = &sc->btcoex; |
| 1525 | |
| 1526 | btcoex->btcoex_period = ATH_BTCOEX_DEF_BT_PERIOD * 1000; |
| 1527 | btcoex->btcoex_no_stomp = (100 - ATH_BTCOEX_DEF_DUTY_CYCLE) * |
| 1528 | btcoex->btcoex_period / 100; |
| 1529 | |
| 1530 | setup_timer(&btcoex->period_timer, ath_btcoex_period_timer, |
| 1531 | (unsigned long) sc); |
| 1532 | |
| 1533 | spin_lock_init(&btcoex->btcoex_lock); |
| 1534 | |
| 1535 | btcoex->no_stomp_timer = ath_gen_timer_alloc(sc->sc_ah, |
| 1536 | ath_btcoex_no_stomp_timer, |
| 1537 | ath_btcoex_no_stomp_timer, |
| 1538 | (void *) sc, AR_FIRST_NDP_TIMER); |
| 1539 | |
| 1540 | if (!btcoex->no_stomp_timer) |
| 1541 | return -ENOMEM; |
| 1542 | |
| 1543 | return 0; |
| 1544 | } |
| 1545 | |
| 1546 | /* |
Luis R. Rodriguez | 9e4bffd | 2009-09-10 16:11:21 -0700 | [diff] [blame] | 1547 | * Read and write, they both share the same lock. We do this to serialize |
| 1548 | * reads and writes on Atheros 802.11n PCI devices only. This is required |
| 1549 | * as the FIFO on these devices can only accept sanely 2 requests. After |
| 1550 | * that the device goes bananas. Serializing the reads/writes prevents this |
| 1551 | * from happening. |
| 1552 | */ |
| 1553 | |
| 1554 | static void ath9k_iowrite32(void *hw_priv, u32 val, u32 reg_offset) |
| 1555 | { |
| 1556 | struct ath_hw *ah = (struct ath_hw *) hw_priv; |
| 1557 | |
| 1558 | if (ah->config.serialize_regmode == SER_REG_MODE_ON) { |
| 1559 | unsigned long flags; |
| 1560 | spin_lock_irqsave(&ah->ah_sc->sc_serial_rw, flags); |
| 1561 | iowrite32(val, ah->ah_sc->mem + reg_offset); |
| 1562 | spin_unlock_irqrestore(&ah->ah_sc->sc_serial_rw, flags); |
| 1563 | } else |
| 1564 | iowrite32(val, ah->ah_sc->mem + reg_offset); |
| 1565 | } |
| 1566 | |
| 1567 | static unsigned int ath9k_ioread32(void *hw_priv, u32 reg_offset) |
| 1568 | { |
| 1569 | struct ath_hw *ah = (struct ath_hw *) hw_priv; |
| 1570 | u32 val; |
| 1571 | |
| 1572 | if (ah->config.serialize_regmode == SER_REG_MODE_ON) { |
| 1573 | unsigned long flags; |
| 1574 | spin_lock_irqsave(&ah->ah_sc->sc_serial_rw, flags); |
| 1575 | val = ioread32(ah->ah_sc->mem + reg_offset); |
| 1576 | spin_unlock_irqrestore(&ah->ah_sc->sc_serial_rw, flags); |
| 1577 | } else |
| 1578 | val = ioread32(ah->ah_sc->mem + reg_offset); |
| 1579 | return val; |
| 1580 | } |
| 1581 | |
Luis R. Rodriguez | 2ddb5c8 | 2009-09-14 02:09:38 -0700 | [diff] [blame^] | 1582 | static const struct ath_ops ath9k_common_ops = { |
Luis R. Rodriguez | 9e4bffd | 2009-09-10 16:11:21 -0700 | [diff] [blame] | 1583 | .read = ath9k_ioread32, |
| 1584 | .write = ath9k_iowrite32, |
| 1585 | }; |
| 1586 | |
| 1587 | /* |
Luis R. Rodriguez | 1e40bcf | 2009-08-03 12:24:47 -0700 | [diff] [blame] | 1588 | * Initialize and fill ath_softc, ath_sofct is the |
| 1589 | * "Software Carrier" struct. Historically it has existed |
| 1590 | * to allow the separation between hardware specific |
| 1591 | * variables (now in ath_hw) and driver specific variables. |
| 1592 | */ |
Luis R. Rodriguez | 5bb1279 | 2009-09-14 00:55:09 -0700 | [diff] [blame] | 1593 | static int ath_init_softc(u16 devid, struct ath_softc *sc, u16 subsysid, |
| 1594 | const struct ath_bus_ops *bus_ops) |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1595 | { |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1596 | struct ath_hw *ah = NULL; |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 1597 | struct ath_common *common; |
Luis R. Rodriguez | 4f3acf8 | 2009-08-03 12:24:36 -0700 | [diff] [blame] | 1598 | int r = 0, i; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1599 | int csz = 0; |
Luis R. Rodriguez | 75d7839 | 2009-09-09 04:00:10 -0700 | [diff] [blame] | 1600 | int qnum; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1601 | |
| 1602 | /* XXX: hardware will not be ready until ath_open() being called */ |
| 1603 | sc->sc_flags |= SC_OP_INVALID; |
Sujith | 88b126a | 2008-11-28 22:19:02 +0530 | [diff] [blame] | 1604 | |
Jouni Malinen | c52f33d | 2009-03-03 19:23:29 +0200 | [diff] [blame] | 1605 | spin_lock_init(&sc->wiphy_lock); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1606 | spin_lock_init(&sc->sc_resetlock); |
Luis R. Rodriguez | 6158425 | 2009-03-12 18:18:49 -0400 | [diff] [blame] | 1607 | spin_lock_init(&sc->sc_serial_rw); |
Senthil Balasubramanian | e5f0921 | 2009-06-24 18:56:41 +0530 | [diff] [blame] | 1608 | spin_lock_init(&sc->ani_lock); |
Gabor Juhos | 04717cc | 2009-07-14 20:17:13 -0400 | [diff] [blame] | 1609 | spin_lock_init(&sc->sc_pm_lock); |
Sujith | aa33de0 | 2008-12-18 11:40:16 +0530 | [diff] [blame] | 1610 | mutex_init(&sc->mutex); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1611 | tasklet_init(&sc->intr_tq, ath9k_tasklet, (unsigned long)sc); |
Sujith | 9fc9ab0 | 2009-03-03 10:16:51 +0530 | [diff] [blame] | 1612 | tasklet_init(&sc->bcon_tasklet, ath_beacon_tasklet, |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1613 | (unsigned long)sc); |
| 1614 | |
Luis R. Rodriguez | 4f3acf8 | 2009-08-03 12:24:36 -0700 | [diff] [blame] | 1615 | ah = kzalloc(sizeof(struct ath_hw), GFP_KERNEL); |
| 1616 | if (!ah) { |
Luis R. Rodriguez | 4f3acf8 | 2009-08-03 12:24:36 -0700 | [diff] [blame] | 1617 | r = -ENOMEM; |
| 1618 | goto bad_no_ah; |
| 1619 | } |
| 1620 | |
| 1621 | ah->ah_sc = sc; |
Luis R. Rodriguez | 8df5d1b | 2009-08-03 12:24:37 -0700 | [diff] [blame] | 1622 | ah->hw_version.devid = devid; |
Vasanthakumar Thiagarajan | aeac355 | 2009-09-09 15:25:49 +0530 | [diff] [blame] | 1623 | ah->hw_version.subsysid = subsysid; |
Luis R. Rodriguez | e1e2f93 | 2009-08-03 12:24:38 -0700 | [diff] [blame] | 1624 | sc->sc_ah = ah; |
Luis R. Rodriguez | 4f3acf8 | 2009-08-03 12:24:36 -0700 | [diff] [blame] | 1625 | |
Luis R. Rodriguez | 27c51f1 | 2009-09-10 11:08:14 -0700 | [diff] [blame] | 1626 | common = ath9k_hw_common(ah); |
Luis R. Rodriguez | 9e4bffd | 2009-09-10 16:11:21 -0700 | [diff] [blame] | 1627 | common->ops = &ath9k_common_ops; |
Luis R. Rodriguez | 5bb1279 | 2009-09-14 00:55:09 -0700 | [diff] [blame] | 1628 | common->bus_ops = bus_ops; |
Luis R. Rodriguez | 13b8155 | 2009-09-10 17:52:45 -0700 | [diff] [blame] | 1629 | common->ah = ah; |
Luis R. Rodriguez | b002a4a | 2009-09-13 00:03:27 -0700 | [diff] [blame] | 1630 | common->hw = sc->hw; |
Luis R. Rodriguez | 27c51f1 | 2009-09-10 11:08:14 -0700 | [diff] [blame] | 1631 | |
| 1632 | /* |
| 1633 | * Cache line size is used to size and align various |
| 1634 | * structures used to communicate with the hardware. |
| 1635 | */ |
Luis R. Rodriguez | 5bb1279 | 2009-09-14 00:55:09 -0700 | [diff] [blame] | 1636 | ath_read_cachesize(common, &csz); |
Luis R. Rodriguez | 27c51f1 | 2009-09-10 11:08:14 -0700 | [diff] [blame] | 1637 | /* XXX assert csz is non-zero */ |
| 1638 | common->cachelsz = csz << 2; /* convert to bytes */ |
| 1639 | |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 1640 | if (ath9k_init_debug(ah) < 0) |
| 1641 | dev_err(sc->dev, "Unable to create debugfs files\n"); |
| 1642 | |
Luis R. Rodriguez | f637cfd | 2009-08-03 12:24:46 -0700 | [diff] [blame] | 1643 | r = ath9k_hw_init(ah); |
Luis R. Rodriguez | 4f3acf8 | 2009-08-03 12:24:36 -0700 | [diff] [blame] | 1644 | if (r) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1645 | ath_print(common, ATH_DBG_FATAL, |
| 1646 | "Unable to initialize hardware; " |
| 1647 | "initialization status: %d\n", r); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1648 | goto bad; |
| 1649 | } |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1650 | |
| 1651 | /* Get the hardware key cache size. */ |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1652 | sc->keymax = ah->caps.keycache_size; |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 1653 | if (sc->keymax > ATH_KEYMAX) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1654 | ath_print(common, ATH_DBG_ANY, |
| 1655 | "Warning, using only %u entries in %u key cache\n", |
| 1656 | ATH_KEYMAX, sc->keymax); |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 1657 | sc->keymax = ATH_KEYMAX; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1658 | } |
| 1659 | |
| 1660 | /* |
| 1661 | * Reset the key cache since some parts do not |
| 1662 | * reset the contents on initial power up. |
| 1663 | */ |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 1664 | for (i = 0; i < sc->keymax; i++) |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1665 | ath9k_hw_keyreset(ah, (u16) i); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1666 | |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1667 | /* default to MONITOR mode */ |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1668 | sc->sc_ah->opmode = NL80211_IFTYPE_MONITOR; |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 1669 | |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1670 | /* Setup rate tables */ |
| 1671 | |
| 1672 | ath_rate_attach(sc); |
| 1673 | ath_setup_rates(sc, IEEE80211_BAND_2GHZ); |
| 1674 | ath_setup_rates(sc, IEEE80211_BAND_5GHZ); |
| 1675 | |
| 1676 | /* |
| 1677 | * Allocate hardware transmit queues: one queue for |
| 1678 | * beacon frames and one data queue for each QoS |
| 1679 | * priority. Note that the hal handles reseting |
| 1680 | * these queues at the needed time. |
| 1681 | */ |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 1682 | sc->beacon.beaconq = ath_beaconq_setup(ah); |
| 1683 | if (sc->beacon.beaconq == -1) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1684 | ath_print(common, ATH_DBG_FATAL, |
| 1685 | "Unable to setup a beacon xmit queue\n"); |
Luis R. Rodriguez | 4f3acf8 | 2009-08-03 12:24:36 -0700 | [diff] [blame] | 1686 | r = -EIO; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1687 | goto bad2; |
| 1688 | } |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 1689 | sc->beacon.cabq = ath_txq_setup(sc, ATH9K_TX_QUEUE_CAB, 0); |
| 1690 | if (sc->beacon.cabq == NULL) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1691 | ath_print(common, ATH_DBG_FATAL, |
| 1692 | "Unable to setup CAB xmit queue\n"); |
Luis R. Rodriguez | 4f3acf8 | 2009-08-03 12:24:36 -0700 | [diff] [blame] | 1693 | r = -EIO; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1694 | goto bad2; |
| 1695 | } |
| 1696 | |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 1697 | sc->config.cabqReadytime = ATH_CABQ_READY_TIME; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1698 | ath_cabq_update(sc); |
| 1699 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 1700 | for (i = 0; i < ARRAY_SIZE(sc->tx.hwq_map); i++) |
| 1701 | sc->tx.hwq_map[i] = -1; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1702 | |
| 1703 | /* Setup data queues */ |
| 1704 | /* NB: ensure BK queue is the lowest priority h/w queue */ |
| 1705 | if (!ath_tx_setup(sc, ATH9K_WME_AC_BK)) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1706 | ath_print(common, ATH_DBG_FATAL, |
| 1707 | "Unable to setup xmit queue for BK traffic\n"); |
Luis R. Rodriguez | 4f3acf8 | 2009-08-03 12:24:36 -0700 | [diff] [blame] | 1708 | r = -EIO; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1709 | goto bad2; |
| 1710 | } |
| 1711 | |
| 1712 | if (!ath_tx_setup(sc, ATH9K_WME_AC_BE)) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1713 | ath_print(common, ATH_DBG_FATAL, |
| 1714 | "Unable to setup xmit queue for BE traffic\n"); |
Luis R. Rodriguez | 4f3acf8 | 2009-08-03 12:24:36 -0700 | [diff] [blame] | 1715 | r = -EIO; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1716 | goto bad2; |
| 1717 | } |
| 1718 | if (!ath_tx_setup(sc, ATH9K_WME_AC_VI)) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1719 | ath_print(common, ATH_DBG_FATAL, |
| 1720 | "Unable to setup xmit queue for VI traffic\n"); |
Luis R. Rodriguez | 4f3acf8 | 2009-08-03 12:24:36 -0700 | [diff] [blame] | 1721 | r = -EIO; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1722 | goto bad2; |
| 1723 | } |
| 1724 | if (!ath_tx_setup(sc, ATH9K_WME_AC_VO)) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1725 | ath_print(common, ATH_DBG_FATAL, |
| 1726 | "Unable to setup xmit queue for VO traffic\n"); |
Luis R. Rodriguez | 4f3acf8 | 2009-08-03 12:24:36 -0700 | [diff] [blame] | 1727 | r = -EIO; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1728 | goto bad2; |
| 1729 | } |
| 1730 | |
| 1731 | /* Initializes the noise floor to a reasonable default value. |
| 1732 | * Later on this will be updated during ANI processing. */ |
| 1733 | |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 1734 | sc->ani.noise_floor = ATH_DEFAULT_NOISE_FLOOR; |
| 1735 | setup_timer(&sc->ani.timer, ath_ani_calibrate, (unsigned long)sc); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1736 | |
| 1737 | if (ath9k_hw_getcapability(ah, ATH9K_CAP_CIPHER, |
| 1738 | ATH9K_CIPHER_TKIP, NULL)) { |
| 1739 | /* |
| 1740 | * Whether we should enable h/w TKIP MIC. |
| 1741 | * XXX: if we don't support WME TKIP MIC, then we wouldn't |
| 1742 | * report WMM capable, so it's always safe to turn on |
| 1743 | * TKIP MIC in this case. |
| 1744 | */ |
| 1745 | ath9k_hw_setcapability(sc->sc_ah, ATH9K_CAP_TKIP_MIC, |
| 1746 | 0, 1, NULL); |
| 1747 | } |
| 1748 | |
| 1749 | /* |
| 1750 | * Check whether the separate key cache entries |
| 1751 | * are required to handle both tx+rx MIC keys. |
| 1752 | * With split mic keys the number of stations is limited |
| 1753 | * to 27 otherwise 59. |
| 1754 | */ |
| 1755 | if (ath9k_hw_getcapability(ah, ATH9K_CAP_CIPHER, |
| 1756 | ATH9K_CIPHER_TKIP, NULL) |
| 1757 | && ath9k_hw_getcapability(ah, ATH9K_CAP_CIPHER, |
| 1758 | ATH9K_CIPHER_MIC, NULL) |
| 1759 | && ath9k_hw_getcapability(ah, ATH9K_CAP_TKIP_SPLIT, |
| 1760 | 0, NULL)) |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 1761 | sc->splitmic = 1; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1762 | |
| 1763 | /* turn on mcast key search if possible */ |
| 1764 | if (!ath9k_hw_getcapability(ah, ATH9K_CAP_MCAST_KEYSRCH, 0, NULL)) |
| 1765 | (void)ath9k_hw_setcapability(ah, ATH9K_CAP_MCAST_KEYSRCH, 1, |
| 1766 | 1, NULL); |
| 1767 | |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 1768 | sc->config.txpowlimit = ATH_TXPOWER_MAX; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1769 | |
| 1770 | /* 11n Capabilities */ |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1771 | if (ah->caps.hw_caps & ATH9K_HW_CAP_HT) { |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1772 | sc->sc_flags |= SC_OP_TXAGGR; |
| 1773 | sc->sc_flags |= SC_OP_RXAGGR; |
| 1774 | } |
| 1775 | |
Luis R. Rodriguez | 43c2761 | 2009-09-13 21:07:07 -0700 | [diff] [blame] | 1776 | common->tx_chainmask = ah->caps.tx_chainmask; |
| 1777 | common->rx_chainmask = ah->caps.rx_chainmask; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1778 | |
| 1779 | ath9k_hw_setcapability(ah, ATH9K_CAP_DIVERSITY, 1, true, NULL); |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 1780 | sc->rx.defant = ath9k_hw_getdefantenna(ah); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1781 | |
Jouni Malinen | 8ca21f0 | 2009-03-03 19:23:27 +0200 | [diff] [blame] | 1782 | if (ah->caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK) |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 1783 | memcpy(common->bssidmask, ath_bcast_mac, ETH_ALEN); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1784 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 1785 | sc->beacon.slottime = ATH9K_SLOT_TIME_9; /* default to short slot time */ |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1786 | |
| 1787 | /* initialize beacon slots */ |
Jouni Malinen | c52f33d | 2009-03-03 19:23:29 +0200 | [diff] [blame] | 1788 | for (i = 0; i < ARRAY_SIZE(sc->beacon.bslot); i++) { |
Jouni Malinen | 2c3db3d | 2009-03-03 19:23:26 +0200 | [diff] [blame] | 1789 | sc->beacon.bslot[i] = NULL; |
Jouni Malinen | c52f33d | 2009-03-03 19:23:29 +0200 | [diff] [blame] | 1790 | sc->beacon.bslot_aphy[i] = NULL; |
| 1791 | } |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1792 | |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1793 | /* setup channels and rates */ |
| 1794 | |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 1795 | sc->sbands[IEEE80211_BAND_2GHZ].channels = ath9k_2ghz_chantable; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1796 | sc->sbands[IEEE80211_BAND_2GHZ].bitrates = |
| 1797 | sc->rates[IEEE80211_BAND_2GHZ]; |
| 1798 | sc->sbands[IEEE80211_BAND_2GHZ].band = IEEE80211_BAND_2GHZ; |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 1799 | sc->sbands[IEEE80211_BAND_2GHZ].n_channels = |
| 1800 | ARRAY_SIZE(ath9k_2ghz_chantable); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1801 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1802 | if (test_bit(ATH9K_MODE_11A, sc->sc_ah->caps.wireless_modes)) { |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 1803 | sc->sbands[IEEE80211_BAND_5GHZ].channels = ath9k_5ghz_chantable; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1804 | sc->sbands[IEEE80211_BAND_5GHZ].bitrates = |
| 1805 | sc->rates[IEEE80211_BAND_5GHZ]; |
| 1806 | sc->sbands[IEEE80211_BAND_5GHZ].band = IEEE80211_BAND_5GHZ; |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 1807 | sc->sbands[IEEE80211_BAND_5GHZ].n_channels = |
| 1808 | ARRAY_SIZE(ath9k_5ghz_chantable); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1809 | } |
| 1810 | |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 1811 | switch (ah->btcoex_hw.scheme) { |
Luis R. Rodriguez | 75d7839 | 2009-09-09 04:00:10 -0700 | [diff] [blame] | 1812 | case ATH_BTCOEX_CFG_NONE: |
| 1813 | break; |
| 1814 | case ATH_BTCOEX_CFG_2WIRE: |
| 1815 | ath9k_hw_btcoex_init_2wire(ah); |
| 1816 | break; |
| 1817 | case ATH_BTCOEX_CFG_3WIRE: |
| 1818 | ath9k_hw_btcoex_init_3wire(ah); |
| 1819 | r = ath_init_btcoex_timer(sc); |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 1820 | if (r) |
| 1821 | goto bad2; |
Luis R. Rodriguez | 75d7839 | 2009-09-09 04:00:10 -0700 | [diff] [blame] | 1822 | qnum = ath_tx_get_qnum(sc, ATH9K_TX_QUEUE_DATA, ATH9K_WME_AC_BE); |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 1823 | ath9k_hw_init_btcoex_hw(ah, qnum); |
Luis R. Rodriguez | e08a6ac | 2009-09-09 14:26:15 -0700 | [diff] [blame] | 1824 | sc->btcoex.bt_stomp_type = ATH_BTCOEX_STOMP_LOW; |
Luis R. Rodriguez | 75d7839 | 2009-09-09 04:00:10 -0700 | [diff] [blame] | 1825 | break; |
| 1826 | default: |
| 1827 | WARN_ON(1); |
| 1828 | break; |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 1829 | } |
Vasanthakumar Thiagarajan | c97c92d | 2009-01-02 15:35:46 +0530 | [diff] [blame] | 1830 | |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1831 | return 0; |
| 1832 | bad2: |
| 1833 | /* cleanup tx queues */ |
| 1834 | for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) |
| 1835 | if (ATH_TXQ_SETUP(sc, i)) |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 1836 | ath_tx_cleanupq(sc, &sc->tx.txq[i]); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1837 | bad: |
Luis R. Rodriguez | 95fafca | 2009-08-03 12:24:54 -0700 | [diff] [blame] | 1838 | ath9k_hw_detach(ah); |
Luis R. Rodriguez | 4f3acf8 | 2009-08-03 12:24:36 -0700 | [diff] [blame] | 1839 | bad_no_ah: |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 1840 | ath9k_exit_debug(sc->sc_ah); |
| 1841 | sc->sc_ah = NULL; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1842 | |
Luis R. Rodriguez | 4f3acf8 | 2009-08-03 12:24:36 -0700 | [diff] [blame] | 1843 | return r; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1844 | } |
| 1845 | |
Jouni Malinen | c52f33d | 2009-03-03 19:23:29 +0200 | [diff] [blame] | 1846 | void ath_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw) |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 1847 | { |
Sujith | 9c84b79 | 2008-10-29 10:17:13 +0530 | [diff] [blame] | 1848 | hw->flags = IEEE80211_HW_RX_INCLUDES_FCS | |
| 1849 | IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING | |
| 1850 | IEEE80211_HW_SIGNAL_DBM | |
Vivek Natarajan | 3cbb5dd | 2009-01-20 11:17:08 +0530 | [diff] [blame] | 1851 | IEEE80211_HW_AMPDU_AGGREGATION | |
| 1852 | IEEE80211_HW_SUPPORTS_PS | |
Sujith | eeee132 | 2009-03-10 10:39:53 +0530 | [diff] [blame] | 1853 | IEEE80211_HW_PS_NULLFUNC_STACK | |
| 1854 | IEEE80211_HW_SPECTRUM_MGMT; |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 1855 | |
Jouni Malinen | b3bd89c | 2009-02-24 13:42:01 +0200 | [diff] [blame] | 1856 | if (AR_SREV_9160_10_OR_LATER(sc->sc_ah) || modparam_nohwcrypt) |
Jouni Malinen | 0ced0e1 | 2009-01-08 13:32:13 +0200 | [diff] [blame] | 1857 | hw->flags |= IEEE80211_HW_MFP_CAPABLE; |
| 1858 | |
Sujith | 9c84b79 | 2008-10-29 10:17:13 +0530 | [diff] [blame] | 1859 | hw->wiphy->interface_modes = |
| 1860 | BIT(NL80211_IFTYPE_AP) | |
| 1861 | BIT(NL80211_IFTYPE_STATION) | |
Pat Erley | 9cb5412 | 2009-03-20 22:59:59 -0400 | [diff] [blame] | 1862 | BIT(NL80211_IFTYPE_ADHOC) | |
| 1863 | BIT(NL80211_IFTYPE_MESH_POINT); |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 1864 | |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 1865 | hw->queues = 4; |
Sujith | e63835b | 2008-11-18 09:07:53 +0530 | [diff] [blame] | 1866 | hw->max_rates = 4; |
Sujith | 171387e | 2009-02-17 15:36:25 +0530 | [diff] [blame] | 1867 | hw->channel_change_time = 5000; |
Jouni Malinen | 465ca84 | 2009-03-03 19:23:34 +0200 | [diff] [blame] | 1868 | hw->max_listen_interval = 10; |
Luis R. Rodriguez | dd19018 | 2009-07-14 20:13:56 -0400 | [diff] [blame] | 1869 | /* Hardware supports 10 but we use 4 */ |
| 1870 | hw->max_rate_tries = 4; |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1871 | hw->sta_data_size = sizeof(struct ath_node); |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 1872 | hw->vif_data_size = sizeof(struct ath_vif); |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 1873 | |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 1874 | hw->rate_control_algorithm = "ath9k_rate_control"; |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 1875 | |
Jouni Malinen | c52f33d | 2009-03-03 19:23:29 +0200 | [diff] [blame] | 1876 | hw->wiphy->bands[IEEE80211_BAND_2GHZ] = |
| 1877 | &sc->sbands[IEEE80211_BAND_2GHZ]; |
| 1878 | if (test_bit(ATH9K_MODE_11A, sc->sc_ah->caps.wireless_modes)) |
| 1879 | hw->wiphy->bands[IEEE80211_BAND_5GHZ] = |
| 1880 | &sc->sbands[IEEE80211_BAND_5GHZ]; |
| 1881 | } |
| 1882 | |
Luis R. Rodriguez | 1e40bcf | 2009-08-03 12:24:47 -0700 | [diff] [blame] | 1883 | /* Device driver core initialization */ |
Luis R. Rodriguez | 5bb1279 | 2009-09-14 00:55:09 -0700 | [diff] [blame] | 1884 | int ath_init_device(u16 devid, struct ath_softc *sc, u16 subsysid, |
| 1885 | const struct ath_bus_ops *bus_ops) |
Jouni Malinen | c52f33d | 2009-03-03 19:23:29 +0200 | [diff] [blame] | 1886 | { |
| 1887 | struct ieee80211_hw *hw = sc->hw; |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 1888 | struct ath_common *common; |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 1889 | struct ath_hw *ah; |
Jouni Malinen | c52f33d | 2009-03-03 19:23:29 +0200 | [diff] [blame] | 1890 | int error = 0, i; |
Bob Copeland | 3a702e4 | 2009-03-30 22:30:29 -0400 | [diff] [blame] | 1891 | struct ath_regulatory *reg; |
Jouni Malinen | c52f33d | 2009-03-03 19:23:29 +0200 | [diff] [blame] | 1892 | |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 1893 | dev_dbg(sc->dev, "Attach ATH hw\n"); |
Jouni Malinen | c52f33d | 2009-03-03 19:23:29 +0200 | [diff] [blame] | 1894 | |
Luis R. Rodriguez | 5bb1279 | 2009-09-14 00:55:09 -0700 | [diff] [blame] | 1895 | error = ath_init_softc(devid, sc, subsysid, bus_ops); |
Jouni Malinen | c52f33d | 2009-03-03 19:23:29 +0200 | [diff] [blame] | 1896 | if (error != 0) |
| 1897 | return error; |
| 1898 | |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 1899 | ah = sc->sc_ah; |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 1900 | common = ath9k_hw_common(ah); |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 1901 | |
Jouni Malinen | c52f33d | 2009-03-03 19:23:29 +0200 | [diff] [blame] | 1902 | /* get mac address from hardware and set in mac80211 */ |
| 1903 | |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 1904 | SET_IEEE80211_PERM_ADDR(hw, common->macaddr); |
Jouni Malinen | c52f33d | 2009-03-03 19:23:29 +0200 | [diff] [blame] | 1905 | |
| 1906 | ath_set_hw_capab(sc, hw); |
| 1907 | |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 1908 | error = ath_regd_init(&common->regulatory, sc->hw->wiphy, |
Luis R. Rodriguez | c26c2e5 | 2009-05-19 18:27:11 -0400 | [diff] [blame] | 1909 | ath9k_reg_notifier); |
| 1910 | if (error) |
| 1911 | return error; |
| 1912 | |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 1913 | reg = &common->regulatory; |
Luis R. Rodriguez | c26c2e5 | 2009-05-19 18:27:11 -0400 | [diff] [blame] | 1914 | |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 1915 | if (ah->caps.hw_caps & ATH9K_HW_CAP_HT) { |
Sujith | eb2599c | 2009-01-23 11:20:44 +0530 | [diff] [blame] | 1916 | setup_ht_cap(sc, &sc->sbands[IEEE80211_BAND_2GHZ].ht_cap); |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 1917 | if (test_bit(ATH9K_MODE_11A, ah->caps.wireless_modes)) |
Sujith | eb2599c | 2009-01-23 11:20:44 +0530 | [diff] [blame] | 1918 | setup_ht_cap(sc, &sc->sbands[IEEE80211_BAND_5GHZ].ht_cap); |
Sujith | 9c84b79 | 2008-10-29 10:17:13 +0530 | [diff] [blame] | 1919 | } |
| 1920 | |
Senthil Balasubramanian | db93e7b | 2008-11-13 18:01:08 +0530 | [diff] [blame] | 1921 | /* initialize tx/rx engine */ |
| 1922 | error = ath_tx_init(sc, ATH_TXBUF); |
| 1923 | if (error != 0) |
Vasanthakumar Thiagarajan | 40b130a | 2009-02-16 13:55:07 +0530 | [diff] [blame] | 1924 | goto error_attach; |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 1925 | |
Senthil Balasubramanian | db93e7b | 2008-11-13 18:01:08 +0530 | [diff] [blame] | 1926 | error = ath_rx_init(sc, ATH_RXBUF); |
| 1927 | if (error != 0) |
Vasanthakumar Thiagarajan | 40b130a | 2009-02-16 13:55:07 +0530 | [diff] [blame] | 1928 | goto error_attach; |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 1929 | |
Jouni Malinen | 0e2dedf | 2009-03-03 19:23:32 +0200 | [diff] [blame] | 1930 | INIT_WORK(&sc->chan_work, ath9k_wiphy_chan_work); |
Jouni Malinen | f98c3bd | 2009-03-03 19:23:39 +0200 | [diff] [blame] | 1931 | INIT_DELAYED_WORK(&sc->wiphy_work, ath9k_wiphy_work); |
| 1932 | sc->wiphy_scheduler_int = msecs_to_jiffies(500); |
Jouni Malinen | 0e2dedf | 2009-03-03 19:23:32 +0200 | [diff] [blame] | 1933 | |
Senthil Balasubramanian | db93e7b | 2008-11-13 18:01:08 +0530 | [diff] [blame] | 1934 | error = ieee80211_register_hw(hw); |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 1935 | |
Bob Copeland | 3a702e4 | 2009-03-30 22:30:29 -0400 | [diff] [blame] | 1936 | if (!ath_is_world_regd(reg)) { |
Bob Copeland | c02cf37 | 2009-03-30 22:30:28 -0400 | [diff] [blame] | 1937 | error = regulatory_hint(hw->wiphy, reg->alpha2); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 1938 | if (error) |
| 1939 | goto error_attach; |
| 1940 | } |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 1941 | |
Senthil Balasubramanian | db93e7b | 2008-11-13 18:01:08 +0530 | [diff] [blame] | 1942 | /* Initialize LED control */ |
| 1943 | ath_init_leds(sc); |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 1944 | |
Johannes Berg | 3b319aa | 2009-06-13 14:50:26 +0530 | [diff] [blame] | 1945 | ath_start_rfkill_poll(sc); |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 1946 | |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 1947 | return 0; |
Vasanthakumar Thiagarajan | 40b130a | 2009-02-16 13:55:07 +0530 | [diff] [blame] | 1948 | |
| 1949 | error_attach: |
| 1950 | /* cleanup tx queues */ |
| 1951 | for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) |
| 1952 | if (ATH_TXQ_SETUP(sc, i)) |
| 1953 | ath_tx_cleanupq(sc, &sc->tx.txq[i]); |
| 1954 | |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 1955 | ath9k_hw_detach(ah); |
| 1956 | ath9k_exit_debug(ah); |
Luis R. Rodriguez | 3ce1b1a | 2009-08-03 12:24:53 -0700 | [diff] [blame] | 1957 | sc->sc_ah = NULL; |
Vasanthakumar Thiagarajan | 40b130a | 2009-02-16 13:55:07 +0530 | [diff] [blame] | 1958 | |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 1959 | return error; |
| 1960 | } |
| 1961 | |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1962 | int ath_reset(struct ath_softc *sc, bool retry_tx) |
| 1963 | { |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1964 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1965 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | 030bb49 | 2008-12-23 15:58:37 -0800 | [diff] [blame] | 1966 | struct ieee80211_hw *hw = sc->hw; |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 1967 | int r; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1968 | |
| 1969 | ath9k_hw_set_interrupts(ah, 0); |
Sujith | 043a040 | 2009-01-16 21:38:47 +0530 | [diff] [blame] | 1970 | ath_drain_all_txq(sc, retry_tx); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1971 | ath_stoprecv(sc); |
| 1972 | ath_flushrecv(sc); |
| 1973 | |
| 1974 | spin_lock_bh(&sc->sc_resetlock); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1975 | r = ath9k_hw_reset(ah, sc->sc_ah->curchan, false); |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 1976 | if (r) |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1977 | ath_print(common, ATH_DBG_FATAL, |
| 1978 | "Unable to reset hardware; reset status %d\n", r); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1979 | spin_unlock_bh(&sc->sc_resetlock); |
| 1980 | |
| 1981 | if (ath_startrecv(sc) != 0) |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1982 | ath_print(common, ATH_DBG_FATAL, |
| 1983 | "Unable to start recv logic\n"); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1984 | |
| 1985 | /* |
| 1986 | * We may be doing a reset in response to a request |
| 1987 | * that changes the channel so update any state that |
| 1988 | * might change as a result. |
| 1989 | */ |
Luis R. Rodriguez | ce111ba | 2008-12-23 15:58:39 -0800 | [diff] [blame] | 1990 | ath_cache_conf_rate(sc, &hw->conf); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1991 | |
| 1992 | ath_update_txpow(sc); |
| 1993 | |
| 1994 | if (sc->sc_flags & SC_OP_BEACONS) |
Jouni Malinen | 2c3db3d | 2009-03-03 19:23:26 +0200 | [diff] [blame] | 1995 | ath_beacon_config(sc, NULL); /* restart beacons */ |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1996 | |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 1997 | ath9k_hw_set_interrupts(ah, sc->imask); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1998 | |
| 1999 | if (retry_tx) { |
| 2000 | int i; |
| 2001 | for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) { |
| 2002 | if (ATH_TXQ_SETUP(sc, i)) { |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 2003 | spin_lock_bh(&sc->tx.txq[i].axq_lock); |
| 2004 | ath_txq_schedule(sc, &sc->tx.txq[i]); |
| 2005 | spin_unlock_bh(&sc->tx.txq[i].axq_lock); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 2006 | } |
| 2007 | } |
| 2008 | } |
| 2009 | |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 2010 | return r; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 2011 | } |
| 2012 | |
| 2013 | /* |
| 2014 | * This function will allocate both the DMA descriptor structure, and the |
| 2015 | * buffers it contains. These are used to contain the descriptors used |
| 2016 | * by the system. |
| 2017 | */ |
| 2018 | int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd, |
| 2019 | struct list_head *head, const char *name, |
| 2020 | int nbuf, int ndesc) |
| 2021 | { |
| 2022 | #define DS2PHYS(_dd, _ds) \ |
| 2023 | ((_dd)->dd_desc_paddr + ((caddr_t)(_ds) - (caddr_t)(_dd)->dd_desc)) |
| 2024 | #define ATH_DESC_4KB_BOUND_CHECK(_daddr) ((((_daddr) & 0xFFF) > 0xF7F) ? 1 : 0) |
| 2025 | #define ATH_DESC_4KB_BOUND_NUM_SKIPPED(_len) ((_len) / 4096) |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2026 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 2027 | struct ath_desc *ds; |
| 2028 | struct ath_buf *bf; |
| 2029 | int i, bsize, error; |
| 2030 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2031 | ath_print(common, ATH_DBG_CONFIG, "%s DMA: %u buffers %u desc/buf\n", |
| 2032 | name, nbuf, ndesc); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 2033 | |
Senthil Balasubramanian | b03a9db | 2009-03-06 11:24:09 +0530 | [diff] [blame] | 2034 | INIT_LIST_HEAD(head); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 2035 | /* ath_desc must be a multiple of DWORDs */ |
| 2036 | if ((sizeof(struct ath_desc) % 4) != 0) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2037 | ath_print(common, ATH_DBG_FATAL, |
| 2038 | "ath_desc not DWORD aligned\n"); |
Luis R. Rodriguez | 9680e8a | 2009-09-13 23:28:00 -0700 | [diff] [blame] | 2039 | BUG_ON((sizeof(struct ath_desc) % 4) != 0); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 2040 | error = -ENOMEM; |
| 2041 | goto fail; |
| 2042 | } |
| 2043 | |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 2044 | dd->dd_desc_len = sizeof(struct ath_desc) * nbuf * ndesc; |
| 2045 | |
| 2046 | /* |
| 2047 | * Need additional DMA memory because we can't use |
| 2048 | * descriptors that cross the 4K page boundary. Assume |
| 2049 | * one skipped descriptor per 4K page. |
| 2050 | */ |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2051 | if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_4KB_SPLITTRANS)) { |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 2052 | u32 ndesc_skipped = |
| 2053 | ATH_DESC_4KB_BOUND_NUM_SKIPPED(dd->dd_desc_len); |
| 2054 | u32 dma_len; |
| 2055 | |
| 2056 | while (ndesc_skipped) { |
| 2057 | dma_len = ndesc_skipped * sizeof(struct ath_desc); |
| 2058 | dd->dd_desc_len += dma_len; |
| 2059 | |
| 2060 | ndesc_skipped = ATH_DESC_4KB_BOUND_NUM_SKIPPED(dma_len); |
| 2061 | }; |
| 2062 | } |
| 2063 | |
| 2064 | /* allocate descriptors */ |
Gabor Juhos | 7da3c55 | 2009-01-14 20:17:03 +0100 | [diff] [blame] | 2065 | dd->dd_desc = dma_alloc_coherent(sc->dev, dd->dd_desc_len, |
Senthil Balasubramanian | f0e6ce1 | 2009-03-06 11:24:08 +0530 | [diff] [blame] | 2066 | &dd->dd_desc_paddr, GFP_KERNEL); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 2067 | if (dd->dd_desc == NULL) { |
| 2068 | error = -ENOMEM; |
| 2069 | goto fail; |
| 2070 | } |
| 2071 | ds = dd->dd_desc; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2072 | ath_print(common, ATH_DBG_CONFIG, "%s DMA map: %p (%u) -> %llx (%u)\n", |
| 2073 | name, ds, (u32) dd->dd_desc_len, |
| 2074 | ito64(dd->dd_desc_paddr), /*XXX*/(u32) dd->dd_desc_len); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 2075 | |
| 2076 | /* allocate buffers */ |
| 2077 | bsize = sizeof(struct ath_buf) * nbuf; |
Senthil Balasubramanian | f0e6ce1 | 2009-03-06 11:24:08 +0530 | [diff] [blame] | 2078 | bf = kzalloc(bsize, GFP_KERNEL); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 2079 | if (bf == NULL) { |
| 2080 | error = -ENOMEM; |
| 2081 | goto fail2; |
| 2082 | } |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 2083 | dd->dd_bufptr = bf; |
| 2084 | |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 2085 | for (i = 0; i < nbuf; i++, bf++, ds += ndesc) { |
| 2086 | bf->bf_desc = ds; |
| 2087 | bf->bf_daddr = DS2PHYS(dd, ds); |
| 2088 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2089 | if (!(sc->sc_ah->caps.hw_caps & |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 2090 | ATH9K_HW_CAP_4KB_SPLITTRANS)) { |
| 2091 | /* |
| 2092 | * Skip descriptor addresses which can cause 4KB |
| 2093 | * boundary crossing (addr + length) with a 32 dword |
| 2094 | * descriptor fetch. |
| 2095 | */ |
| 2096 | while (ATH_DESC_4KB_BOUND_CHECK(bf->bf_daddr)) { |
Luis R. Rodriguez | 9680e8a | 2009-09-13 23:28:00 -0700 | [diff] [blame] | 2097 | BUG_ON((caddr_t) bf->bf_desc >= |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 2098 | ((caddr_t) dd->dd_desc + |
| 2099 | dd->dd_desc_len)); |
| 2100 | |
| 2101 | ds += ndesc; |
| 2102 | bf->bf_desc = ds; |
| 2103 | bf->bf_daddr = DS2PHYS(dd, ds); |
| 2104 | } |
| 2105 | } |
| 2106 | list_add_tail(&bf->list, head); |
| 2107 | } |
| 2108 | return 0; |
| 2109 | fail2: |
Gabor Juhos | 7da3c55 | 2009-01-14 20:17:03 +0100 | [diff] [blame] | 2110 | dma_free_coherent(sc->dev, dd->dd_desc_len, dd->dd_desc, |
| 2111 | dd->dd_desc_paddr); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 2112 | fail: |
| 2113 | memset(dd, 0, sizeof(*dd)); |
| 2114 | return error; |
| 2115 | #undef ATH_DESC_4KB_BOUND_CHECK |
| 2116 | #undef ATH_DESC_4KB_BOUND_NUM_SKIPPED |
| 2117 | #undef DS2PHYS |
| 2118 | } |
| 2119 | |
| 2120 | void ath_descdma_cleanup(struct ath_softc *sc, |
| 2121 | struct ath_descdma *dd, |
| 2122 | struct list_head *head) |
| 2123 | { |
Gabor Juhos | 7da3c55 | 2009-01-14 20:17:03 +0100 | [diff] [blame] | 2124 | dma_free_coherent(sc->dev, dd->dd_desc_len, dd->dd_desc, |
| 2125 | dd->dd_desc_paddr); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 2126 | |
| 2127 | INIT_LIST_HEAD(head); |
| 2128 | kfree(dd->dd_bufptr); |
| 2129 | memset(dd, 0, sizeof(*dd)); |
| 2130 | } |
| 2131 | |
| 2132 | int ath_get_hal_qnum(u16 queue, struct ath_softc *sc) |
| 2133 | { |
| 2134 | int qnum; |
| 2135 | |
| 2136 | switch (queue) { |
| 2137 | case 0: |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 2138 | qnum = sc->tx.hwq_map[ATH9K_WME_AC_VO]; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 2139 | break; |
| 2140 | case 1: |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 2141 | qnum = sc->tx.hwq_map[ATH9K_WME_AC_VI]; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 2142 | break; |
| 2143 | case 2: |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 2144 | qnum = sc->tx.hwq_map[ATH9K_WME_AC_BE]; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 2145 | break; |
| 2146 | case 3: |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 2147 | qnum = sc->tx.hwq_map[ATH9K_WME_AC_BK]; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 2148 | break; |
| 2149 | default: |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 2150 | qnum = sc->tx.hwq_map[ATH9K_WME_AC_BE]; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 2151 | break; |
| 2152 | } |
| 2153 | |
| 2154 | return qnum; |
| 2155 | } |
| 2156 | |
| 2157 | int ath_get_mac80211_qnum(u32 queue, struct ath_softc *sc) |
| 2158 | { |
| 2159 | int qnum; |
| 2160 | |
| 2161 | switch (queue) { |
| 2162 | case ATH9K_WME_AC_VO: |
| 2163 | qnum = 0; |
| 2164 | break; |
| 2165 | case ATH9K_WME_AC_VI: |
| 2166 | qnum = 1; |
| 2167 | break; |
| 2168 | case ATH9K_WME_AC_BE: |
| 2169 | qnum = 2; |
| 2170 | break; |
| 2171 | case ATH9K_WME_AC_BK: |
| 2172 | qnum = 3; |
| 2173 | break; |
| 2174 | default: |
| 2175 | qnum = -1; |
| 2176 | break; |
| 2177 | } |
| 2178 | |
| 2179 | return qnum; |
| 2180 | } |
| 2181 | |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 2182 | /* XXX: Remove me once we don't depend on ath9k_channel for all |
| 2183 | * this redundant data */ |
Jouni Malinen | 0e2dedf | 2009-03-03 19:23:32 +0200 | [diff] [blame] | 2184 | void ath9k_update_ichannel(struct ath_softc *sc, struct ieee80211_hw *hw, |
| 2185 | struct ath9k_channel *ichan) |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 2186 | { |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 2187 | struct ieee80211_channel *chan = hw->conf.channel; |
| 2188 | struct ieee80211_conf *conf = &hw->conf; |
| 2189 | |
| 2190 | ichan->channel = chan->center_freq; |
| 2191 | ichan->chan = chan; |
| 2192 | |
| 2193 | if (chan->band == IEEE80211_BAND_2GHZ) { |
| 2194 | ichan->chanmode = CHANNEL_G; |
Sujith | 8813262 | 2009-09-03 12:08:53 +0530 | [diff] [blame] | 2195 | ichan->channelFlags = CHANNEL_2GHZ | CHANNEL_OFDM | CHANNEL_G; |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 2196 | } else { |
| 2197 | ichan->chanmode = CHANNEL_A; |
| 2198 | ichan->channelFlags = CHANNEL_5GHZ | CHANNEL_OFDM; |
| 2199 | } |
| 2200 | |
Luis R. Rodriguez | 25c56ee | 2009-09-13 23:04:44 -0700 | [diff] [blame] | 2201 | if (conf_is_ht(conf)) |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 2202 | ichan->chanmode = ath_get_extchanmode(sc, chan, |
| 2203 | conf->channel_type); |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 2204 | } |
| 2205 | |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 2206 | /**********************/ |
| 2207 | /* mac80211 callbacks */ |
| 2208 | /**********************/ |
| 2209 | |
Luis R. Rodriguez | 75d7839 | 2009-09-09 04:00:10 -0700 | [diff] [blame] | 2210 | /* |
| 2211 | * (Re)start btcoex timers |
| 2212 | */ |
| 2213 | static void ath9k_btcoex_timer_resume(struct ath_softc *sc) |
| 2214 | { |
| 2215 | struct ath_btcoex *btcoex = &sc->btcoex; |
| 2216 | struct ath_hw *ah = sc->sc_ah; |
| 2217 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2218 | ath_print(ath9k_hw_common(ah), ATH_DBG_BTCOEX, |
| 2219 | "Starting btcoex timers"); |
Luis R. Rodriguez | 75d7839 | 2009-09-09 04:00:10 -0700 | [diff] [blame] | 2220 | |
| 2221 | /* make sure duty cycle timer is also stopped when resuming */ |
| 2222 | if (btcoex->hw_timer_enabled) |
Luis R. Rodriguez | cd9bf68 | 2009-09-13 02:08:34 -0700 | [diff] [blame] | 2223 | ath9k_gen_timer_stop(sc->sc_ah, btcoex->no_stomp_timer); |
Luis R. Rodriguez | 75d7839 | 2009-09-09 04:00:10 -0700 | [diff] [blame] | 2224 | |
| 2225 | btcoex->bt_priority_cnt = 0; |
| 2226 | btcoex->bt_priority_time = jiffies; |
| 2227 | sc->sc_flags &= ~SC_OP_BT_PRIORITY_DETECTED; |
| 2228 | |
| 2229 | mod_timer(&btcoex->period_timer, jiffies); |
| 2230 | } |
| 2231 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2232 | static int ath9k_start(struct ieee80211_hw *hw) |
| 2233 | { |
Jouni Malinen | bce048d | 2009-03-03 19:23:28 +0200 | [diff] [blame] | 2234 | struct ath_wiphy *aphy = hw->priv; |
| 2235 | struct ath_softc *sc = aphy->sc; |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 2236 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2237 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2238 | struct ieee80211_channel *curchan = hw->conf.channel; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 2239 | struct ath9k_channel *init_channel; |
Vasanthakumar Thiagarajan | 82880a7 | 2009-06-13 14:50:24 +0530 | [diff] [blame] | 2240 | int r; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2241 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2242 | ath_print(common, ATH_DBG_CONFIG, |
| 2243 | "Starting driver with initial channel: %d MHz\n", |
| 2244 | curchan->center_freq); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2245 | |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 2246 | mutex_lock(&sc->mutex); |
| 2247 | |
Jouni Malinen | 9580a22 | 2009-03-03 19:23:33 +0200 | [diff] [blame] | 2248 | if (ath9k_wiphy_started(sc)) { |
| 2249 | if (sc->chan_idx == curchan->hw_value) { |
| 2250 | /* |
| 2251 | * Already on the operational channel, the new wiphy |
| 2252 | * can be marked active. |
| 2253 | */ |
| 2254 | aphy->state = ATH_WIPHY_ACTIVE; |
| 2255 | ieee80211_wake_queues(hw); |
| 2256 | } else { |
| 2257 | /* |
| 2258 | * Another wiphy is on another channel, start the new |
| 2259 | * wiphy in paused state. |
| 2260 | */ |
| 2261 | aphy->state = ATH_WIPHY_PAUSED; |
| 2262 | ieee80211_stop_queues(hw); |
| 2263 | } |
| 2264 | mutex_unlock(&sc->mutex); |
| 2265 | return 0; |
| 2266 | } |
| 2267 | aphy->state = ATH_WIPHY_ACTIVE; |
| 2268 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2269 | /* setup initial channel */ |
| 2270 | |
Vasanthakumar Thiagarajan | 82880a7 | 2009-06-13 14:50:24 +0530 | [diff] [blame] | 2271 | sc->chan_idx = curchan->hw_value; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2272 | |
Vasanthakumar Thiagarajan | 82880a7 | 2009-06-13 14:50:24 +0530 | [diff] [blame] | 2273 | init_channel = ath_get_curchannel(sc, hw); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2274 | |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 2275 | /* Reset SERDES registers */ |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 2276 | ath9k_hw_configpcipowersave(ah, 0, 0); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 2277 | |
| 2278 | /* |
| 2279 | * The basic interface to setting the hardware in a good |
| 2280 | * state is ``reset''. On return the hardware is known to |
| 2281 | * be powered up and with interrupts disabled. This must |
| 2282 | * be followed by initialization of the appropriate bits |
| 2283 | * and then setup of the interrupt mask. |
| 2284 | */ |
| 2285 | spin_lock_bh(&sc->sc_resetlock); |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 2286 | r = ath9k_hw_reset(ah, init_channel, false); |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 2287 | if (r) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2288 | ath_print(common, ATH_DBG_FATAL, |
| 2289 | "Unable to reset hardware; reset status %d " |
| 2290 | "(freq %u MHz)\n", r, |
| 2291 | curchan->center_freq); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 2292 | spin_unlock_bh(&sc->sc_resetlock); |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 2293 | goto mutex_unlock; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2294 | } |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 2295 | spin_unlock_bh(&sc->sc_resetlock); |
| 2296 | |
| 2297 | /* |
| 2298 | * This is needed only to setup initial state |
| 2299 | * but it's best done after a reset. |
| 2300 | */ |
| 2301 | ath_update_txpow(sc); |
| 2302 | |
| 2303 | /* |
| 2304 | * Setup the hardware after reset: |
| 2305 | * The receive engine is set going. |
| 2306 | * Frame transmit is handled entirely |
| 2307 | * in the frame output path; there's nothing to do |
| 2308 | * here except setup the interrupt mask. |
| 2309 | */ |
| 2310 | if (ath_startrecv(sc) != 0) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2311 | ath_print(common, ATH_DBG_FATAL, |
| 2312 | "Unable to start recv logic\n"); |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 2313 | r = -EIO; |
| 2314 | goto mutex_unlock; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 2315 | } |
| 2316 | |
| 2317 | /* Setup our intr mask. */ |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 2318 | sc->imask = ATH9K_INT_RX | ATH9K_INT_TX |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 2319 | | ATH9K_INT_RXEOL | ATH9K_INT_RXORN |
| 2320 | | ATH9K_INT_FATAL | ATH9K_INT_GLOBAL; |
| 2321 | |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 2322 | if (ah->caps.hw_caps & ATH9K_HW_CAP_GTT) |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 2323 | sc->imask |= ATH9K_INT_GTT; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 2324 | |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 2325 | if (ah->caps.hw_caps & ATH9K_HW_CAP_HT) |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 2326 | sc->imask |= ATH9K_INT_CST; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 2327 | |
Luis R. Rodriguez | ce111ba | 2008-12-23 15:58:39 -0800 | [diff] [blame] | 2328 | ath_cache_conf_rate(sc, &hw->conf); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 2329 | |
| 2330 | sc->sc_flags &= ~SC_OP_INVALID; |
| 2331 | |
| 2332 | /* Disable BMISS interrupt when we're not associated */ |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 2333 | sc->imask &= ~(ATH9K_INT_SWBA | ATH9K_INT_BMISS); |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 2334 | ath9k_hw_set_interrupts(ah, sc->imask); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 2335 | |
Jouni Malinen | bce048d | 2009-03-03 19:23:28 +0200 | [diff] [blame] | 2336 | ieee80211_wake_queues(hw); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2337 | |
Luis R. Rodriguez | 42935ec | 2009-07-29 20:08:07 -0400 | [diff] [blame] | 2338 | ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0); |
Senthil Balasubramanian | 164ace3 | 2009-07-14 20:17:09 -0400 | [diff] [blame] | 2339 | |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 2340 | if ((ah->btcoex_hw.scheme != ATH_BTCOEX_CFG_NONE) && |
| 2341 | !ah->btcoex_hw.enabled) { |
Luis R. Rodriguez | 5e19729 | 2009-09-09 15:15:55 -0700 | [diff] [blame] | 2342 | ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT, |
| 2343 | AR_STOMP_LOW_WLAN_WGHT); |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 2344 | ath9k_hw_btcoex_enable(ah); |
Vasanthakumar Thiagarajan | f985ad1 | 2009-08-26 21:08:43 +0530 | [diff] [blame] | 2345 | |
Luis R. Rodriguez | 5bb1279 | 2009-09-14 00:55:09 -0700 | [diff] [blame] | 2346 | if (common->bus_ops->bt_coex_prep) |
| 2347 | common->bus_ops->bt_coex_prep(common); |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 2348 | if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE) |
Luis R. Rodriguez | 75d7839 | 2009-09-09 04:00:10 -0700 | [diff] [blame] | 2349 | ath9k_btcoex_timer_resume(sc); |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 2350 | } |
| 2351 | |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 2352 | mutex_unlock: |
| 2353 | mutex_unlock(&sc->mutex); |
| 2354 | |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 2355 | return r; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2356 | } |
| 2357 | |
| 2358 | static int ath9k_tx(struct ieee80211_hw *hw, |
| 2359 | struct sk_buff *skb) |
| 2360 | { |
Jouni Malinen | 147583c | 2008-08-11 14:01:50 +0300 | [diff] [blame] | 2361 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
Jouni Malinen | bce048d | 2009-03-03 19:23:28 +0200 | [diff] [blame] | 2362 | struct ath_wiphy *aphy = hw->priv; |
| 2363 | struct ath_softc *sc = aphy->sc; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2364 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 2365 | struct ath_tx_control txctl; |
| 2366 | int hdrlen, padsize; |
| 2367 | |
Jouni Malinen | 8089cc4 | 2009-03-03 19:23:38 +0200 | [diff] [blame] | 2368 | if (aphy->state != ATH_WIPHY_ACTIVE && aphy->state != ATH_WIPHY_SCAN) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2369 | ath_print(common, ATH_DBG_XMIT, |
| 2370 | "ath9k: %s: TX in unexpected wiphy state " |
| 2371 | "%d\n", wiphy_name(hw->wiphy), aphy->state); |
Jouni Malinen | ee166a0 | 2009-03-03 19:23:36 +0200 | [diff] [blame] | 2372 | goto exit; |
| 2373 | } |
| 2374 | |
Gabor Juhos | 9614832 | 2009-07-24 17:27:21 +0200 | [diff] [blame] | 2375 | if (sc->ps_enabled) { |
Jouni Malinen | dc8c458 | 2009-05-19 17:01:42 +0300 | [diff] [blame] | 2376 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; |
| 2377 | /* |
| 2378 | * mac80211 does not set PM field for normal data frames, so we |
| 2379 | * need to update that based on the current PS mode. |
| 2380 | */ |
| 2381 | if (ieee80211_is_data(hdr->frame_control) && |
| 2382 | !ieee80211_is_nullfunc(hdr->frame_control) && |
| 2383 | !ieee80211_has_pm(hdr->frame_control)) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2384 | ath_print(common, ATH_DBG_PS, "Add PM=1 for a TX frame " |
| 2385 | "while in PS mode\n"); |
Jouni Malinen | dc8c458 | 2009-05-19 17:01:42 +0300 | [diff] [blame] | 2386 | hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM); |
| 2387 | } |
| 2388 | } |
| 2389 | |
Jouni Malinen | 9a23f9c | 2009-05-19 17:01:38 +0300 | [diff] [blame] | 2390 | if (unlikely(sc->sc_ah->power_mode != ATH9K_PM_AWAKE)) { |
| 2391 | /* |
| 2392 | * We are using PS-Poll and mac80211 can request TX while in |
| 2393 | * power save mode. Need to wake up hardware for the TX to be |
| 2394 | * completed and if needed, also for RX of buffered frames. |
| 2395 | */ |
| 2396 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; |
| 2397 | ath9k_ps_wakeup(sc); |
| 2398 | ath9k_hw_setrxabort(sc->sc_ah, 0); |
| 2399 | if (ieee80211_is_pspoll(hdr->frame_control)) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2400 | ath_print(common, ATH_DBG_PS, |
| 2401 | "Sending PS-Poll to pick a buffered frame\n"); |
Jouni Malinen | 9a23f9c | 2009-05-19 17:01:38 +0300 | [diff] [blame] | 2402 | sc->sc_flags |= SC_OP_WAIT_FOR_PSPOLL_DATA; |
| 2403 | } else { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2404 | ath_print(common, ATH_DBG_PS, |
| 2405 | "Wake up to complete TX\n"); |
Jouni Malinen | 9a23f9c | 2009-05-19 17:01:38 +0300 | [diff] [blame] | 2406 | sc->sc_flags |= SC_OP_WAIT_FOR_TX_ACK; |
| 2407 | } |
| 2408 | /* |
| 2409 | * The actual restore operation will happen only after |
| 2410 | * the sc_flags bit is cleared. We are just dropping |
| 2411 | * the ps_usecount here. |
| 2412 | */ |
| 2413 | ath9k_ps_restore(sc); |
| 2414 | } |
| 2415 | |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 2416 | memset(&txctl, 0, sizeof(struct ath_tx_control)); |
Jouni Malinen | 147583c | 2008-08-11 14:01:50 +0300 | [diff] [blame] | 2417 | |
| 2418 | /* |
| 2419 | * As a temporary workaround, assign seq# here; this will likely need |
| 2420 | * to be cleaned up to work better with Beacon transmission and virtual |
| 2421 | * BSSes. |
| 2422 | */ |
| 2423 | if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) { |
| 2424 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; |
| 2425 | if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT) |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 2426 | sc->tx.seq_no += 0x10; |
Jouni Malinen | 147583c | 2008-08-11 14:01:50 +0300 | [diff] [blame] | 2427 | hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG); |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 2428 | hdr->seq_ctrl |= cpu_to_le16(sc->tx.seq_no); |
Jouni Malinen | 147583c | 2008-08-11 14:01:50 +0300 | [diff] [blame] | 2429 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2430 | |
| 2431 | /* Add the padding after the header if this is not already done */ |
| 2432 | hdrlen = ieee80211_get_hdrlen_from_skb(skb); |
| 2433 | if (hdrlen & 3) { |
| 2434 | padsize = hdrlen % 4; |
| 2435 | if (skb_headroom(skb) < padsize) |
| 2436 | return -1; |
| 2437 | skb_push(skb, padsize); |
| 2438 | memmove(skb->data, skb->data + padsize, hdrlen); |
| 2439 | } |
| 2440 | |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 2441 | /* Check if a tx queue is available */ |
| 2442 | |
| 2443 | txctl.txq = ath_test_get_txq(sc, skb); |
| 2444 | if (!txctl.txq) |
| 2445 | goto exit; |
| 2446 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2447 | ath_print(common, ATH_DBG_XMIT, "transmitting packet, skb: %p\n", skb); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2448 | |
Jouni Malinen | c52f33d | 2009-03-03 19:23:29 +0200 | [diff] [blame] | 2449 | if (ath_tx_start(hw, skb, &txctl) != 0) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2450 | ath_print(common, ATH_DBG_XMIT, "TX failed\n"); |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 2451 | goto exit; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2452 | } |
| 2453 | |
| 2454 | return 0; |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 2455 | exit: |
| 2456 | dev_kfree_skb_any(skb); |
| 2457 | return 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2458 | } |
| 2459 | |
Luis R. Rodriguez | 75d7839 | 2009-09-09 04:00:10 -0700 | [diff] [blame] | 2460 | /* |
| 2461 | * Pause btcoex timer and bt duty cycle timer |
| 2462 | */ |
| 2463 | static void ath9k_btcoex_timer_pause(struct ath_softc *sc) |
| 2464 | { |
| 2465 | struct ath_btcoex *btcoex = &sc->btcoex; |
| 2466 | struct ath_hw *ah = sc->sc_ah; |
| 2467 | |
| 2468 | del_timer_sync(&btcoex->period_timer); |
| 2469 | |
| 2470 | if (btcoex->hw_timer_enabled) |
Luis R. Rodriguez | cd9bf68 | 2009-09-13 02:08:34 -0700 | [diff] [blame] | 2471 | ath9k_gen_timer_stop(ah, btcoex->no_stomp_timer); |
Luis R. Rodriguez | 75d7839 | 2009-09-09 04:00:10 -0700 | [diff] [blame] | 2472 | |
| 2473 | btcoex->hw_timer_enabled = false; |
| 2474 | } |
| 2475 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2476 | static void ath9k_stop(struct ieee80211_hw *hw) |
| 2477 | { |
Jouni Malinen | bce048d | 2009-03-03 19:23:28 +0200 | [diff] [blame] | 2478 | struct ath_wiphy *aphy = hw->priv; |
| 2479 | struct ath_softc *sc = aphy->sc; |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 2480 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2481 | struct ath_common *common = ath9k_hw_common(ah); |
Sujith | 9c84b79 | 2008-10-29 10:17:13 +0530 | [diff] [blame] | 2482 | |
Sujith | 4c48381 | 2009-08-18 10:51:52 +0530 | [diff] [blame] | 2483 | mutex_lock(&sc->mutex); |
| 2484 | |
Jouni Malinen | 9580a22 | 2009-03-03 19:23:33 +0200 | [diff] [blame] | 2485 | aphy->state = ATH_WIPHY_INACTIVE; |
| 2486 | |
Luis R. Rodriguez | c94dbff | 2009-07-27 11:53:04 -0700 | [diff] [blame] | 2487 | cancel_delayed_work_sync(&sc->ath_led_blink_work); |
| 2488 | cancel_delayed_work_sync(&sc->tx_complete_work); |
| 2489 | |
| 2490 | if (!sc->num_sec_wiphy) { |
| 2491 | cancel_delayed_work_sync(&sc->wiphy_work); |
| 2492 | cancel_work_sync(&sc->chan_work); |
| 2493 | } |
| 2494 | |
Sujith | 9c84b79 | 2008-10-29 10:17:13 +0530 | [diff] [blame] | 2495 | if (sc->sc_flags & SC_OP_INVALID) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2496 | ath_print(common, ATH_DBG_ANY, "Device not present\n"); |
Sujith | 4c48381 | 2009-08-18 10:51:52 +0530 | [diff] [blame] | 2497 | mutex_unlock(&sc->mutex); |
Sujith | 9c84b79 | 2008-10-29 10:17:13 +0530 | [diff] [blame] | 2498 | return; |
| 2499 | } |
| 2500 | |
Jouni Malinen | 9580a22 | 2009-03-03 19:23:33 +0200 | [diff] [blame] | 2501 | if (ath9k_wiphy_started(sc)) { |
| 2502 | mutex_unlock(&sc->mutex); |
| 2503 | return; /* another wiphy still in use */ |
| 2504 | } |
| 2505 | |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 2506 | if (ah->btcoex_hw.enabled) { |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 2507 | ath9k_hw_btcoex_disable(ah); |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 2508 | if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE) |
Luis R. Rodriguez | 75d7839 | 2009-09-09 04:00:10 -0700 | [diff] [blame] | 2509 | ath9k_btcoex_timer_pause(sc); |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 2510 | } |
| 2511 | |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 2512 | /* make sure h/w will not generate any interrupt |
| 2513 | * before setting the invalid flag. */ |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 2514 | ath9k_hw_set_interrupts(ah, 0); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 2515 | |
| 2516 | if (!(sc->sc_flags & SC_OP_INVALID)) { |
Sujith | 043a040 | 2009-01-16 21:38:47 +0530 | [diff] [blame] | 2517 | ath_drain_all_txq(sc, false); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 2518 | ath_stoprecv(sc); |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 2519 | ath9k_hw_phy_disable(ah); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 2520 | } else |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 2521 | sc->rx.rxlink = NULL; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 2522 | |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 2523 | /* disable HAL and put h/w to sleep */ |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 2524 | ath9k_hw_disable(ah); |
| 2525 | ath9k_hw_configpcipowersave(ah, 1, 1); |
Luis R. Rodriguez | 9ecdef4 | 2009-09-09 21:10:09 -0700 | [diff] [blame] | 2526 | ath9k_setpower(sc, ATH9K_PM_FULL_SLEEP); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 2527 | |
| 2528 | sc->sc_flags |= SC_OP_INVALID; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2529 | |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 2530 | mutex_unlock(&sc->mutex); |
| 2531 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2532 | ath_print(common, ATH_DBG_CONFIG, "Driver halt\n"); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2533 | } |
| 2534 | |
| 2535 | static int ath9k_add_interface(struct ieee80211_hw *hw, |
| 2536 | struct ieee80211_if_init_conf *conf) |
| 2537 | { |
Jouni Malinen | bce048d | 2009-03-03 19:23:28 +0200 | [diff] [blame] | 2538 | struct ath_wiphy *aphy = hw->priv; |
| 2539 | struct ath_softc *sc = aphy->sc; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2540 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 2541 | struct ath_vif *avp = (void *)conf->vif->drv_priv; |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 2542 | enum nl80211_iftype ic_opmode = NL80211_IFTYPE_UNSPECIFIED; |
Jouni Malinen | 2c3db3d | 2009-03-03 19:23:26 +0200 | [diff] [blame] | 2543 | int ret = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2544 | |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 2545 | mutex_lock(&sc->mutex); |
| 2546 | |
Jouni Malinen | 8ca21f0 | 2009-03-03 19:23:27 +0200 | [diff] [blame] | 2547 | if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK) && |
| 2548 | sc->nvifs > 0) { |
| 2549 | ret = -ENOBUFS; |
| 2550 | goto out; |
| 2551 | } |
| 2552 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2553 | switch (conf->type) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2554 | case NL80211_IFTYPE_STATION: |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 2555 | ic_opmode = NL80211_IFTYPE_STATION; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2556 | break; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2557 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2558 | case NL80211_IFTYPE_AP: |
Pat Erley | 9cb5412 | 2009-03-20 22:59:59 -0400 | [diff] [blame] | 2559 | case NL80211_IFTYPE_MESH_POINT: |
Jouni Malinen | 2c3db3d | 2009-03-03 19:23:26 +0200 | [diff] [blame] | 2560 | if (sc->nbcnvifs >= ATH_BCBUF) { |
| 2561 | ret = -ENOBUFS; |
| 2562 | goto out; |
| 2563 | } |
Pat Erley | 9cb5412 | 2009-03-20 22:59:59 -0400 | [diff] [blame] | 2564 | ic_opmode = conf->type; |
Jouni Malinen | 2ad67de | 2008-08-11 14:01:47 +0300 | [diff] [blame] | 2565 | break; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2566 | default: |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2567 | ath_print(common, ATH_DBG_FATAL, |
Sujith | 04bd463 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 2568 | "Interface type %d not yet supported\n", conf->type); |
Jouni Malinen | 2c3db3d | 2009-03-03 19:23:26 +0200 | [diff] [blame] | 2569 | ret = -EOPNOTSUPP; |
| 2570 | goto out; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2571 | } |
| 2572 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2573 | ath_print(common, ATH_DBG_CONFIG, |
| 2574 | "Attach a VIF of type: %d\n", ic_opmode); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2575 | |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 2576 | /* Set the VIF opmode */ |
Sujith | 5640b08 | 2008-10-29 10:16:06 +0530 | [diff] [blame] | 2577 | avp->av_opmode = ic_opmode; |
| 2578 | avp->av_bslot = -1; |
| 2579 | |
Jouni Malinen | 2c3db3d | 2009-03-03 19:23:26 +0200 | [diff] [blame] | 2580 | sc->nvifs++; |
Jouni Malinen | 8ca21f0 | 2009-03-03 19:23:27 +0200 | [diff] [blame] | 2581 | |
| 2582 | if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK) |
| 2583 | ath9k_set_bssid_mask(hw); |
| 2584 | |
Jouni Malinen | 2c3db3d | 2009-03-03 19:23:26 +0200 | [diff] [blame] | 2585 | if (sc->nvifs > 1) |
| 2586 | goto out; /* skip global settings for secondary vif */ |
| 2587 | |
Sujith | b238e90 | 2009-03-03 10:16:56 +0530 | [diff] [blame] | 2588 | if (ic_opmode == NL80211_IFTYPE_AP) { |
Sujith | 5640b08 | 2008-10-29 10:16:06 +0530 | [diff] [blame] | 2589 | ath9k_hw_set_tsfadjust(sc->sc_ah, 1); |
Sujith | b238e90 | 2009-03-03 10:16:56 +0530 | [diff] [blame] | 2590 | sc->sc_flags |= SC_OP_TSF_RESET; |
| 2591 | } |
Sujith | 5640b08 | 2008-10-29 10:16:06 +0530 | [diff] [blame] | 2592 | |
Sujith | 5640b08 | 2008-10-29 10:16:06 +0530 | [diff] [blame] | 2593 | /* Set the device opmode */ |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2594 | sc->sc_ah->opmode = ic_opmode; |
Sujith | 5640b08 | 2008-10-29 10:16:06 +0530 | [diff] [blame] | 2595 | |
Vivek Natarajan | 4e30ffa | 2009-01-28 20:53:27 +0530 | [diff] [blame] | 2596 | /* |
| 2597 | * Enable MIB interrupts when there are hardware phy counters. |
| 2598 | * Note we only do this (at the moment) for station mode. |
| 2599 | */ |
Sujith | 4af9cf4 | 2009-02-12 10:06:47 +0530 | [diff] [blame] | 2600 | if ((conf->type == NL80211_IFTYPE_STATION) || |
Pat Erley | 9cb5412 | 2009-03-20 22:59:59 -0400 | [diff] [blame] | 2601 | (conf->type == NL80211_IFTYPE_ADHOC) || |
| 2602 | (conf->type == NL80211_IFTYPE_MESH_POINT)) { |
Sujith | 1aa8e84 | 2009-08-13 09:34:25 +0530 | [diff] [blame] | 2603 | sc->imask |= ATH9K_INT_MIB; |
Sujith | 4af9cf4 | 2009-02-12 10:06:47 +0530 | [diff] [blame] | 2604 | sc->imask |= ATH9K_INT_TSFOOR; |
| 2605 | } |
| 2606 | |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 2607 | ath9k_hw_set_interrupts(sc->sc_ah, sc->imask); |
Vivek Natarajan | 4e30ffa | 2009-01-28 20:53:27 +0530 | [diff] [blame] | 2608 | |
Senthil Balasubramanian | f38faa3 | 2009-06-24 18:56:40 +0530 | [diff] [blame] | 2609 | if (conf->type == NL80211_IFTYPE_AP || |
| 2610 | conf->type == NL80211_IFTYPE_ADHOC || |
| 2611 | conf->type == NL80211_IFTYPE_MONITOR) |
Sujith | 415f738 | 2009-04-13 21:56:46 +0530 | [diff] [blame] | 2612 | ath_start_ani(sc); |
Luis R. Rodriguez | 6f25542 | 2008-10-03 15:45:27 -0700 | [diff] [blame] | 2613 | |
Jouni Malinen | 2c3db3d | 2009-03-03 19:23:26 +0200 | [diff] [blame] | 2614 | out: |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 2615 | mutex_unlock(&sc->mutex); |
Jouni Malinen | 2c3db3d | 2009-03-03 19:23:26 +0200 | [diff] [blame] | 2616 | return ret; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2617 | } |
| 2618 | |
| 2619 | static void ath9k_remove_interface(struct ieee80211_hw *hw, |
| 2620 | struct ieee80211_if_init_conf *conf) |
| 2621 | { |
Jouni Malinen | bce048d | 2009-03-03 19:23:28 +0200 | [diff] [blame] | 2622 | struct ath_wiphy *aphy = hw->priv; |
| 2623 | struct ath_softc *sc = aphy->sc; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2624 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 2625 | struct ath_vif *avp = (void *)conf->vif->drv_priv; |
Jouni Malinen | 2c3db3d | 2009-03-03 19:23:26 +0200 | [diff] [blame] | 2626 | int i; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2627 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2628 | ath_print(common, ATH_DBG_CONFIG, "Detach Interface\n"); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2629 | |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 2630 | mutex_lock(&sc->mutex); |
| 2631 | |
Luis R. Rodriguez | 6f25542 | 2008-10-03 15:45:27 -0700 | [diff] [blame] | 2632 | /* Stop ANI */ |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 2633 | del_timer_sync(&sc->ani.timer); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2634 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2635 | /* Reclaim beacon resources */ |
Pat Erley | 9cb5412 | 2009-03-20 22:59:59 -0400 | [diff] [blame] | 2636 | if ((sc->sc_ah->opmode == NL80211_IFTYPE_AP) || |
| 2637 | (sc->sc_ah->opmode == NL80211_IFTYPE_ADHOC) || |
| 2638 | (sc->sc_ah->opmode == NL80211_IFTYPE_MESH_POINT)) { |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 2639 | ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2640 | ath_beacon_return(sc, avp); |
| 2641 | } |
| 2642 | |
Sujith | 672840a | 2008-08-11 14:05:08 +0530 | [diff] [blame] | 2643 | sc->sc_flags &= ~SC_OP_BEACONS; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2644 | |
Jouni Malinen | 2c3db3d | 2009-03-03 19:23:26 +0200 | [diff] [blame] | 2645 | for (i = 0; i < ARRAY_SIZE(sc->beacon.bslot); i++) { |
| 2646 | if (sc->beacon.bslot[i] == conf->vif) { |
| 2647 | printk(KERN_DEBUG "%s: vif had allocated beacon " |
| 2648 | "slot\n", __func__); |
| 2649 | sc->beacon.bslot[i] = NULL; |
Jouni Malinen | c52f33d | 2009-03-03 19:23:29 +0200 | [diff] [blame] | 2650 | sc->beacon.bslot_aphy[i] = NULL; |
Jouni Malinen | 2c3db3d | 2009-03-03 19:23:26 +0200 | [diff] [blame] | 2651 | } |
| 2652 | } |
| 2653 | |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 2654 | sc->nvifs--; |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 2655 | |
| 2656 | mutex_unlock(&sc->mutex); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2657 | } |
| 2658 | |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 2659 | static int ath9k_config(struct ieee80211_hw *hw, u32 changed) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2660 | { |
Jouni Malinen | bce048d | 2009-03-03 19:23:28 +0200 | [diff] [blame] | 2661 | struct ath_wiphy *aphy = hw->priv; |
| 2662 | struct ath_softc *sc = aphy->sc; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2663 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 2664 | struct ieee80211_conf *conf = &hw->conf; |
Vivek Natarajan | 8782b41 | 2009-03-30 14:17:00 +0530 | [diff] [blame] | 2665 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | 6483917 | 2009-07-14 20:22:53 -0400 | [diff] [blame] | 2666 | bool all_wiphys_idle = false, disable_radio = false; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2667 | |
Sujith | aa33de0 | 2008-12-18 11:40:16 +0530 | [diff] [blame] | 2668 | mutex_lock(&sc->mutex); |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 2669 | |
Luis R. Rodriguez | 6483917 | 2009-07-14 20:22:53 -0400 | [diff] [blame] | 2670 | /* Leave this as the first check */ |
| 2671 | if (changed & IEEE80211_CONF_CHANGE_IDLE) { |
| 2672 | |
| 2673 | spin_lock_bh(&sc->wiphy_lock); |
| 2674 | all_wiphys_idle = ath9k_all_wiphys_idle(sc); |
| 2675 | spin_unlock_bh(&sc->wiphy_lock); |
| 2676 | |
| 2677 | if (conf->flags & IEEE80211_CONF_IDLE){ |
| 2678 | if (all_wiphys_idle) |
| 2679 | disable_radio = true; |
| 2680 | } |
| 2681 | else if (all_wiphys_idle) { |
| 2682 | ath_radio_enable(sc); |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2683 | ath_print(common, ATH_DBG_CONFIG, |
| 2684 | "not-idle: enabling radio\n"); |
Luis R. Rodriguez | 6483917 | 2009-07-14 20:22:53 -0400 | [diff] [blame] | 2685 | } |
| 2686 | } |
| 2687 | |
Vivek Natarajan | 3cbb5dd | 2009-01-20 11:17:08 +0530 | [diff] [blame] | 2688 | if (changed & IEEE80211_CONF_CHANGE_PS) { |
| 2689 | if (conf->flags & IEEE80211_CONF_PS) { |
Vivek Natarajan | 8782b41 | 2009-03-30 14:17:00 +0530 | [diff] [blame] | 2690 | if (!(ah->caps.hw_caps & |
| 2691 | ATH9K_HW_CAP_AUTOSLEEP)) { |
| 2692 | if ((sc->imask & ATH9K_INT_TIM_TIMER) == 0) { |
| 2693 | sc->imask |= ATH9K_INT_TIM_TIMER; |
| 2694 | ath9k_hw_set_interrupts(sc->sc_ah, |
| 2695 | sc->imask); |
| 2696 | } |
| 2697 | ath9k_hw_setrxabort(sc->sc_ah, 1); |
Vivek Natarajan | 3cbb5dd | 2009-01-20 11:17:08 +0530 | [diff] [blame] | 2698 | } |
Gabor Juhos | 9614832 | 2009-07-24 17:27:21 +0200 | [diff] [blame] | 2699 | sc->ps_enabled = true; |
Vivek Natarajan | 3cbb5dd | 2009-01-20 11:17:08 +0530 | [diff] [blame] | 2700 | } else { |
Gabor Juhos | 9614832 | 2009-07-24 17:27:21 +0200 | [diff] [blame] | 2701 | sc->ps_enabled = false; |
Luis R. Rodriguez | 9ecdef4 | 2009-09-09 21:10:09 -0700 | [diff] [blame] | 2702 | ath9k_setpower(sc, ATH9K_PM_AWAKE); |
Vivek Natarajan | 8782b41 | 2009-03-30 14:17:00 +0530 | [diff] [blame] | 2703 | if (!(ah->caps.hw_caps & |
| 2704 | ATH9K_HW_CAP_AUTOSLEEP)) { |
| 2705 | ath9k_hw_setrxabort(sc->sc_ah, 0); |
Jouni Malinen | 9a23f9c | 2009-05-19 17:01:38 +0300 | [diff] [blame] | 2706 | sc->sc_flags &= ~(SC_OP_WAIT_FOR_BEACON | |
| 2707 | SC_OP_WAIT_FOR_CAB | |
| 2708 | SC_OP_WAIT_FOR_PSPOLL_DATA | |
| 2709 | SC_OP_WAIT_FOR_TX_ACK); |
Vivek Natarajan | 8782b41 | 2009-03-30 14:17:00 +0530 | [diff] [blame] | 2710 | if (sc->imask & ATH9K_INT_TIM_TIMER) { |
| 2711 | sc->imask &= ~ATH9K_INT_TIM_TIMER; |
| 2712 | ath9k_hw_set_interrupts(sc->sc_ah, |
| 2713 | sc->imask); |
| 2714 | } |
Vivek Natarajan | 3cbb5dd | 2009-01-20 11:17:08 +0530 | [diff] [blame] | 2715 | } |
| 2716 | } |
| 2717 | } |
| 2718 | |
Johannes Berg | 4797938 | 2009-01-07 10:13:27 +0100 | [diff] [blame] | 2719 | if (changed & IEEE80211_CONF_CHANGE_CHANNEL) { |
Sujith | 99405f9 | 2008-11-24 12:08:35 +0530 | [diff] [blame] | 2720 | struct ieee80211_channel *curchan = hw->conf.channel; |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 2721 | int pos = curchan->hw_value; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2722 | |
Jouni Malinen | 0e2dedf | 2009-03-03 19:23:32 +0200 | [diff] [blame] | 2723 | aphy->chan_idx = pos; |
| 2724 | aphy->chan_is_ht = conf_is_ht(conf); |
| 2725 | |
Jouni Malinen | 8089cc4 | 2009-03-03 19:23:38 +0200 | [diff] [blame] | 2726 | if (aphy->state == ATH_WIPHY_SCAN || |
| 2727 | aphy->state == ATH_WIPHY_ACTIVE) |
| 2728 | ath9k_wiphy_pause_all_forced(sc, aphy); |
| 2729 | else { |
| 2730 | /* |
| 2731 | * Do not change operational channel based on a paused |
| 2732 | * wiphy changes. |
| 2733 | */ |
| 2734 | goto skip_chan_change; |
| 2735 | } |
Jouni Malinen | 0e2dedf | 2009-03-03 19:23:32 +0200 | [diff] [blame] | 2736 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2737 | ath_print(common, ATH_DBG_CONFIG, "Set channel: %d MHz\n", |
| 2738 | curchan->center_freq); |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 2739 | |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 2740 | /* XXX: remove me eventualy */ |
Jouni Malinen | 0e2dedf | 2009-03-03 19:23:32 +0200 | [diff] [blame] | 2741 | ath9k_update_ichannel(sc, hw, &sc->sc_ah->channels[pos]); |
Sujith | e11602b | 2008-11-27 09:46:27 +0530 | [diff] [blame] | 2742 | |
Luis R. Rodriguez | ecf7044 | 2008-12-23 15:58:43 -0800 | [diff] [blame] | 2743 | ath_update_chainmask(sc, conf_is_ht(conf)); |
Sujith | 86060f0 | 2009-01-07 14:25:29 +0530 | [diff] [blame] | 2744 | |
Jouni Malinen | 0e2dedf | 2009-03-03 19:23:32 +0200 | [diff] [blame] | 2745 | if (ath_set_channel(sc, hw, &sc->sc_ah->channels[pos]) < 0) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2746 | ath_print(common, ATH_DBG_FATAL, |
| 2747 | "Unable to set channel\n"); |
Sujith | aa33de0 | 2008-12-18 11:40:16 +0530 | [diff] [blame] | 2748 | mutex_unlock(&sc->mutex); |
Sujith | e11602b | 2008-11-27 09:46:27 +0530 | [diff] [blame] | 2749 | return -EINVAL; |
| 2750 | } |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 2751 | } |
Sujith | 86b89ee | 2008-08-07 10:54:57 +0530 | [diff] [blame] | 2752 | |
Jouni Malinen | 8089cc4 | 2009-03-03 19:23:38 +0200 | [diff] [blame] | 2753 | skip_chan_change: |
Luis R. Rodriguez | 5c020dc | 2008-10-22 13:28:45 -0700 | [diff] [blame] | 2754 | if (changed & IEEE80211_CONF_CHANGE_POWER) |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 2755 | sc->config.txpowlimit = 2 * conf->power_level; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2756 | |
Luis R. Rodriguez | 6483917 | 2009-07-14 20:22:53 -0400 | [diff] [blame] | 2757 | if (disable_radio) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2758 | ath_print(common, ATH_DBG_CONFIG, "idle: disabling radio\n"); |
Luis R. Rodriguez | 6483917 | 2009-07-14 20:22:53 -0400 | [diff] [blame] | 2759 | ath_radio_disable(sc); |
| 2760 | } |
| 2761 | |
Sujith | aa33de0 | 2008-12-18 11:40:16 +0530 | [diff] [blame] | 2762 | mutex_unlock(&sc->mutex); |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 2763 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2764 | return 0; |
| 2765 | } |
| 2766 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2767 | #define SUPPORTED_FILTERS \ |
| 2768 | (FIF_PROMISC_IN_BSS | \ |
| 2769 | FIF_ALLMULTI | \ |
| 2770 | FIF_CONTROL | \ |
Luis R. Rodriguez | af6a3fc | 2009-08-08 21:55:16 -0400 | [diff] [blame] | 2771 | FIF_PSPOLL | \ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2772 | FIF_OTHER_BSS | \ |
| 2773 | FIF_BCN_PRBRESP_PROMISC | \ |
| 2774 | FIF_FCSFAIL) |
| 2775 | |
Sujith | 7dcfdcd | 2008-08-11 14:03:13 +0530 | [diff] [blame] | 2776 | /* FIXME: sc->sc_full_reset ? */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2777 | static void ath9k_configure_filter(struct ieee80211_hw *hw, |
| 2778 | unsigned int changed_flags, |
| 2779 | unsigned int *total_flags, |
Johannes Berg | 3ac64be | 2009-08-17 16:16:53 +0200 | [diff] [blame] | 2780 | u64 multicast) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2781 | { |
Jouni Malinen | bce048d | 2009-03-03 19:23:28 +0200 | [diff] [blame] | 2782 | struct ath_wiphy *aphy = hw->priv; |
| 2783 | struct ath_softc *sc = aphy->sc; |
Sujith | 7dcfdcd | 2008-08-11 14:03:13 +0530 | [diff] [blame] | 2784 | u32 rfilt; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2785 | |
| 2786 | changed_flags &= SUPPORTED_FILTERS; |
| 2787 | *total_flags &= SUPPORTED_FILTERS; |
| 2788 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 2789 | sc->rx.rxfilter = *total_flags; |
Jouni Malinen | aa68aea | 2009-05-19 17:01:41 +0300 | [diff] [blame] | 2790 | ath9k_ps_wakeup(sc); |
Sujith | 7dcfdcd | 2008-08-11 14:03:13 +0530 | [diff] [blame] | 2791 | rfilt = ath_calcrxfilter(sc); |
| 2792 | ath9k_hw_setrxfilter(sc->sc_ah, rfilt); |
Jouni Malinen | aa68aea | 2009-05-19 17:01:41 +0300 | [diff] [blame] | 2793 | ath9k_ps_restore(sc); |
Sujith | 7dcfdcd | 2008-08-11 14:03:13 +0530 | [diff] [blame] | 2794 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2795 | ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_CONFIG, |
| 2796 | "Set HW RX filter: 0x%x\n", rfilt); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2797 | } |
| 2798 | |
| 2799 | static void ath9k_sta_notify(struct ieee80211_hw *hw, |
| 2800 | struct ieee80211_vif *vif, |
| 2801 | enum sta_notify_cmd cmd, |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 2802 | struct ieee80211_sta *sta) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2803 | { |
Jouni Malinen | bce048d | 2009-03-03 19:23:28 +0200 | [diff] [blame] | 2804 | struct ath_wiphy *aphy = hw->priv; |
| 2805 | struct ath_softc *sc = aphy->sc; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2806 | |
| 2807 | switch (cmd) { |
| 2808 | case STA_NOTIFY_ADD: |
Sujith | 5640b08 | 2008-10-29 10:16:06 +0530 | [diff] [blame] | 2809 | ath_node_attach(sc, sta); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2810 | break; |
| 2811 | case STA_NOTIFY_REMOVE: |
Sujith | b5aa9bf | 2008-10-29 10:13:31 +0530 | [diff] [blame] | 2812 | ath_node_detach(sc, sta); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2813 | break; |
| 2814 | default: |
| 2815 | break; |
| 2816 | } |
| 2817 | } |
| 2818 | |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 2819 | static int ath9k_conf_tx(struct ieee80211_hw *hw, u16 queue, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2820 | const struct ieee80211_tx_queue_params *params) |
| 2821 | { |
Jouni Malinen | bce048d | 2009-03-03 19:23:28 +0200 | [diff] [blame] | 2822 | struct ath_wiphy *aphy = hw->priv; |
| 2823 | struct ath_softc *sc = aphy->sc; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2824 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Sujith | ea9880f | 2008-08-07 10:53:10 +0530 | [diff] [blame] | 2825 | struct ath9k_tx_queue_info qi; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2826 | int ret = 0, qnum; |
| 2827 | |
| 2828 | if (queue >= WME_NUM_AC) |
| 2829 | return 0; |
| 2830 | |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 2831 | mutex_lock(&sc->mutex); |
| 2832 | |
Sujith | 1ffb061 | 2009-03-30 15:28:46 +0530 | [diff] [blame] | 2833 | memset(&qi, 0, sizeof(struct ath9k_tx_queue_info)); |
| 2834 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2835 | qi.tqi_aifs = params->aifs; |
| 2836 | qi.tqi_cwmin = params->cw_min; |
| 2837 | qi.tqi_cwmax = params->cw_max; |
| 2838 | qi.tqi_burstTime = params->txop; |
| 2839 | qnum = ath_get_hal_qnum(queue, sc); |
| 2840 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2841 | ath_print(common, ATH_DBG_CONFIG, |
| 2842 | "Configure tx [queue/halq] [%d/%d], " |
| 2843 | "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n", |
| 2844 | queue, qnum, params->aifs, params->cw_min, |
| 2845 | params->cw_max, params->txop); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2846 | |
| 2847 | ret = ath_txq_update(sc, qnum, &qi); |
| 2848 | if (ret) |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2849 | ath_print(common, ATH_DBG_FATAL, "TXQ Update failed\n"); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2850 | |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 2851 | mutex_unlock(&sc->mutex); |
| 2852 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2853 | return ret; |
| 2854 | } |
| 2855 | |
| 2856 | static int ath9k_set_key(struct ieee80211_hw *hw, |
| 2857 | enum set_key_cmd cmd, |
Johannes Berg | dc822b5 | 2008-12-29 12:55:09 +0100 | [diff] [blame] | 2858 | struct ieee80211_vif *vif, |
| 2859 | struct ieee80211_sta *sta, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2860 | struct ieee80211_key_conf *key) |
| 2861 | { |
Jouni Malinen | bce048d | 2009-03-03 19:23:28 +0200 | [diff] [blame] | 2862 | struct ath_wiphy *aphy = hw->priv; |
| 2863 | struct ath_softc *sc = aphy->sc; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2864 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2865 | int ret = 0; |
| 2866 | |
Jouni Malinen | b3bd89c | 2009-02-24 13:42:01 +0200 | [diff] [blame] | 2867 | if (modparam_nohwcrypt) |
| 2868 | return -ENOSPC; |
| 2869 | |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 2870 | mutex_lock(&sc->mutex); |
Vivek Natarajan | 3cbb5dd | 2009-01-20 11:17:08 +0530 | [diff] [blame] | 2871 | ath9k_ps_wakeup(sc); |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2872 | ath_print(common, ATH_DBG_CONFIG, "Set HW Key\n"); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2873 | |
| 2874 | switch (cmd) { |
| 2875 | case SET_KEY: |
Jouni Malinen | 3f53dd6 | 2009-02-26 11:18:46 +0200 | [diff] [blame] | 2876 | ret = ath_key_config(sc, vif, sta, key); |
Jouni Malinen | 6ace289 | 2008-12-17 13:32:17 +0200 | [diff] [blame] | 2877 | if (ret >= 0) { |
| 2878 | key->hw_key_idx = ret; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2879 | /* push IV and Michael MIC generation to stack */ |
| 2880 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
Senthil Balasubramanian | 1b96175 | 2008-09-01 19:45:21 +0530 | [diff] [blame] | 2881 | if (key->alg == ALG_TKIP) |
| 2882 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; |
Jouni Malinen | 0ced0e1 | 2009-01-08 13:32:13 +0200 | [diff] [blame] | 2883 | if (sc->sc_ah->sw_mgmt_crypto && key->alg == ALG_CCMP) |
| 2884 | key->flags |= IEEE80211_KEY_FLAG_SW_MGMT; |
Jouni Malinen | 6ace289 | 2008-12-17 13:32:17 +0200 | [diff] [blame] | 2885 | ret = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2886 | } |
| 2887 | break; |
| 2888 | case DISABLE_KEY: |
| 2889 | ath_key_delete(sc, key); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2890 | break; |
| 2891 | default: |
| 2892 | ret = -EINVAL; |
| 2893 | } |
| 2894 | |
Vivek Natarajan | 3cbb5dd | 2009-01-20 11:17:08 +0530 | [diff] [blame] | 2895 | ath9k_ps_restore(sc); |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 2896 | mutex_unlock(&sc->mutex); |
| 2897 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2898 | return ret; |
| 2899 | } |
| 2900 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2901 | static void ath9k_bss_info_changed(struct ieee80211_hw *hw, |
| 2902 | struct ieee80211_vif *vif, |
| 2903 | struct ieee80211_bss_conf *bss_conf, |
| 2904 | u32 changed) |
| 2905 | { |
Jouni Malinen | bce048d | 2009-03-03 19:23:28 +0200 | [diff] [blame] | 2906 | struct ath_wiphy *aphy = hw->priv; |
| 2907 | struct ath_softc *sc = aphy->sc; |
Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 2908 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 2909 | struct ath_common *common = ath9k_hw_common(ah); |
Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 2910 | struct ath_vif *avp = (void *)vif->drv_priv; |
| 2911 | u32 rfilt = 0; |
| 2912 | int error, i; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2913 | |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 2914 | mutex_lock(&sc->mutex); |
| 2915 | |
Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 2916 | /* |
| 2917 | * TODO: Need to decide which hw opmode to use for |
| 2918 | * multi-interface cases |
| 2919 | * XXX: This belongs into add_interface! |
| 2920 | */ |
| 2921 | if (vif->type == NL80211_IFTYPE_AP && |
| 2922 | ah->opmode != NL80211_IFTYPE_AP) { |
| 2923 | ah->opmode = NL80211_IFTYPE_STATION; |
| 2924 | ath9k_hw_setopmode(ah); |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 2925 | memcpy(common->curbssid, common->macaddr, ETH_ALEN); |
| 2926 | common->curaid = 0; |
Luis R. Rodriguez | f2b2143 | 2009-09-10 08:50:20 -0700 | [diff] [blame] | 2927 | ath9k_hw_write_associd(ah); |
Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 2928 | /* Request full reset to get hw opmode changed properly */ |
| 2929 | sc->sc_flags |= SC_OP_FULL_RESET; |
| 2930 | } |
| 2931 | |
| 2932 | if ((changed & BSS_CHANGED_BSSID) && |
| 2933 | !is_zero_ether_addr(bss_conf->bssid)) { |
| 2934 | switch (vif->type) { |
| 2935 | case NL80211_IFTYPE_STATION: |
| 2936 | case NL80211_IFTYPE_ADHOC: |
| 2937 | case NL80211_IFTYPE_MESH_POINT: |
| 2938 | /* Set BSSID */ |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 2939 | memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN); |
Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 2940 | memcpy(avp->bssid, bss_conf->bssid, ETH_ALEN); |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 2941 | common->curaid = 0; |
Luis R. Rodriguez | f2b2143 | 2009-09-10 08:50:20 -0700 | [diff] [blame] | 2942 | ath9k_hw_write_associd(ah); |
Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 2943 | |
| 2944 | /* Set aggregation protection mode parameters */ |
| 2945 | sc->config.ath_aggr_prot = 0; |
| 2946 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2947 | ath_print(common, ATH_DBG_CONFIG, |
| 2948 | "RX filter 0x%x bssid %pM aid 0x%x\n", |
| 2949 | rfilt, common->curbssid, common->curaid); |
Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 2950 | |
| 2951 | /* need to reconfigure the beacon */ |
| 2952 | sc->sc_flags &= ~SC_OP_BEACONS ; |
| 2953 | |
| 2954 | break; |
| 2955 | default: |
| 2956 | break; |
| 2957 | } |
| 2958 | } |
| 2959 | |
| 2960 | if ((vif->type == NL80211_IFTYPE_ADHOC) || |
| 2961 | (vif->type == NL80211_IFTYPE_AP) || |
| 2962 | (vif->type == NL80211_IFTYPE_MESH_POINT)) { |
| 2963 | if ((changed & BSS_CHANGED_BEACON) || |
| 2964 | (changed & BSS_CHANGED_BEACON_ENABLED && |
| 2965 | bss_conf->enable_beacon)) { |
| 2966 | /* |
| 2967 | * Allocate and setup the beacon frame. |
| 2968 | * |
| 2969 | * Stop any previous beacon DMA. This may be |
| 2970 | * necessary, for example, when an ibss merge |
| 2971 | * causes reconfiguration; we may be called |
| 2972 | * with beacon transmission active. |
| 2973 | */ |
| 2974 | ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq); |
| 2975 | |
| 2976 | error = ath_beacon_alloc(aphy, vif); |
| 2977 | if (!error) |
| 2978 | ath_beacon_config(sc, vif); |
| 2979 | } |
| 2980 | } |
| 2981 | |
| 2982 | /* Check for WLAN_CAPABILITY_PRIVACY ? */ |
| 2983 | if ((avp->av_opmode != NL80211_IFTYPE_STATION)) { |
| 2984 | for (i = 0; i < IEEE80211_WEP_NKID; i++) |
| 2985 | if (ath9k_hw_keyisvalid(sc->sc_ah, (u16)i)) |
| 2986 | ath9k_hw_keysetmac(sc->sc_ah, |
| 2987 | (u16)i, |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 2988 | common->curbssid); |
Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 2989 | } |
| 2990 | |
| 2991 | /* Only legacy IBSS for now */ |
| 2992 | if (vif->type == NL80211_IFTYPE_ADHOC) |
| 2993 | ath_update_chainmask(sc, 0); |
| 2994 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2995 | if (changed & BSS_CHANGED_ERP_PREAMBLE) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2996 | ath_print(common, ATH_DBG_CONFIG, "BSS Changed PREAMBLE %d\n", |
| 2997 | bss_conf->use_short_preamble); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2998 | if (bss_conf->use_short_preamble) |
Sujith | 672840a | 2008-08-11 14:05:08 +0530 | [diff] [blame] | 2999 | sc->sc_flags |= SC_OP_PREAMBLE_SHORT; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3000 | else |
Sujith | 672840a | 2008-08-11 14:05:08 +0530 | [diff] [blame] | 3001 | sc->sc_flags &= ~SC_OP_PREAMBLE_SHORT; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3002 | } |
| 3003 | |
| 3004 | if (changed & BSS_CHANGED_ERP_CTS_PROT) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 3005 | ath_print(common, ATH_DBG_CONFIG, "BSS Changed CTS PROT %d\n", |
| 3006 | bss_conf->use_cts_prot); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3007 | if (bss_conf->use_cts_prot && |
| 3008 | hw->conf.channel->band != IEEE80211_BAND_5GHZ) |
Sujith | 672840a | 2008-08-11 14:05:08 +0530 | [diff] [blame] | 3009 | sc->sc_flags |= SC_OP_PROTECT_ENABLE; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3010 | else |
Sujith | 672840a | 2008-08-11 14:05:08 +0530 | [diff] [blame] | 3011 | sc->sc_flags &= ~SC_OP_PROTECT_ENABLE; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3012 | } |
| 3013 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3014 | if (changed & BSS_CHANGED_ASSOC) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 3015 | ath_print(common, ATH_DBG_CONFIG, "BSS Changed ASSOC %d\n", |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3016 | bss_conf->assoc); |
Sujith | 5640b08 | 2008-10-29 10:16:06 +0530 | [diff] [blame] | 3017 | ath9k_bss_assoc_info(sc, vif, bss_conf); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3018 | } |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 3019 | |
Johannes Berg | 57c4d7b | 2009-04-23 16:10:04 +0200 | [diff] [blame] | 3020 | /* |
| 3021 | * The HW TSF has to be reset when the beacon interval changes. |
| 3022 | * We set the flag here, and ath_beacon_config_ap() would take this |
| 3023 | * into account when it gets called through the subsequent |
| 3024 | * config_interface() call - with IFCC_BEACON in the changed field. |
| 3025 | */ |
| 3026 | |
| 3027 | if (changed & BSS_CHANGED_BEACON_INT) { |
| 3028 | sc->sc_flags |= SC_OP_TSF_RESET; |
| 3029 | sc->beacon_interval = bss_conf->beacon_int; |
| 3030 | } |
| 3031 | |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 3032 | mutex_unlock(&sc->mutex); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3033 | } |
| 3034 | |
| 3035 | static u64 ath9k_get_tsf(struct ieee80211_hw *hw) |
| 3036 | { |
| 3037 | u64 tsf; |
Jouni Malinen | bce048d | 2009-03-03 19:23:28 +0200 | [diff] [blame] | 3038 | struct ath_wiphy *aphy = hw->priv; |
| 3039 | struct ath_softc *sc = aphy->sc; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3040 | |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 3041 | mutex_lock(&sc->mutex); |
| 3042 | tsf = ath9k_hw_gettsf64(sc->sc_ah); |
| 3043 | mutex_unlock(&sc->mutex); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3044 | |
| 3045 | return tsf; |
| 3046 | } |
| 3047 | |
Alina Friedrichsen | 3b5d665 | 2009-01-24 07:09:59 +0100 | [diff] [blame] | 3048 | static void ath9k_set_tsf(struct ieee80211_hw *hw, u64 tsf) |
| 3049 | { |
Jouni Malinen | bce048d | 2009-03-03 19:23:28 +0200 | [diff] [blame] | 3050 | struct ath_wiphy *aphy = hw->priv; |
| 3051 | struct ath_softc *sc = aphy->sc; |
Alina Friedrichsen | 3b5d665 | 2009-01-24 07:09:59 +0100 | [diff] [blame] | 3052 | |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 3053 | mutex_lock(&sc->mutex); |
| 3054 | ath9k_hw_settsf64(sc->sc_ah, tsf); |
| 3055 | mutex_unlock(&sc->mutex); |
Alina Friedrichsen | 3b5d665 | 2009-01-24 07:09:59 +0100 | [diff] [blame] | 3056 | } |
| 3057 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3058 | static void ath9k_reset_tsf(struct ieee80211_hw *hw) |
| 3059 | { |
Jouni Malinen | bce048d | 2009-03-03 19:23:28 +0200 | [diff] [blame] | 3060 | struct ath_wiphy *aphy = hw->priv; |
| 3061 | struct ath_softc *sc = aphy->sc; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3062 | |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 3063 | mutex_lock(&sc->mutex); |
Luis R. Rodriguez | 21526d5 | 2009-09-09 20:05:39 -0700 | [diff] [blame] | 3064 | |
| 3065 | ath9k_ps_wakeup(sc); |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 3066 | ath9k_hw_reset_tsf(sc->sc_ah); |
Luis R. Rodriguez | 21526d5 | 2009-09-09 20:05:39 -0700 | [diff] [blame] | 3067 | ath9k_ps_restore(sc); |
| 3068 | |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 3069 | mutex_unlock(&sc->mutex); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3070 | } |
| 3071 | |
| 3072 | static int ath9k_ampdu_action(struct ieee80211_hw *hw, |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 3073 | enum ieee80211_ampdu_mlme_action action, |
| 3074 | struct ieee80211_sta *sta, |
| 3075 | u16 tid, u16 *ssn) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3076 | { |
Jouni Malinen | bce048d | 2009-03-03 19:23:28 +0200 | [diff] [blame] | 3077 | struct ath_wiphy *aphy = hw->priv; |
| 3078 | struct ath_softc *sc = aphy->sc; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3079 | int ret = 0; |
| 3080 | |
| 3081 | switch (action) { |
| 3082 | case IEEE80211_AMPDU_RX_START: |
Sujith | dca3edb | 2008-10-29 10:19:01 +0530 | [diff] [blame] | 3083 | if (!(sc->sc_flags & SC_OP_RXAGGR)) |
| 3084 | ret = -ENOTSUPP; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3085 | break; |
| 3086 | case IEEE80211_AMPDU_RX_STOP: |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3087 | break; |
| 3088 | case IEEE80211_AMPDU_TX_START: |
Sujith | f83da96 | 2009-07-23 15:32:37 +0530 | [diff] [blame] | 3089 | ath_tx_aggr_start(sc, sta, tid, ssn); |
| 3090 | ieee80211_start_tx_ba_cb_irqsafe(hw, sta->addr, tid); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3091 | break; |
| 3092 | case IEEE80211_AMPDU_TX_STOP: |
Sujith | f83da96 | 2009-07-23 15:32:37 +0530 | [diff] [blame] | 3093 | ath_tx_aggr_stop(sc, sta, tid); |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 3094 | ieee80211_stop_tx_ba_cb_irqsafe(hw, sta->addr, tid); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3095 | break; |
Johannes Berg | b172023 | 2009-03-23 17:28:39 +0100 | [diff] [blame] | 3096 | case IEEE80211_AMPDU_TX_OPERATIONAL: |
Sujith | 8469cde | 2008-10-29 10:19:28 +0530 | [diff] [blame] | 3097 | ath_tx_aggr_resume(sc, sta, tid); |
| 3098 | break; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3099 | default: |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 3100 | ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_FATAL, |
| 3101 | "Unknown AMPDU action\n"); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3102 | } |
| 3103 | |
| 3104 | return ret; |
| 3105 | } |
| 3106 | |
Sujith | 0c98de6 | 2009-03-03 10:16:45 +0530 | [diff] [blame] | 3107 | static void ath9k_sw_scan_start(struct ieee80211_hw *hw) |
| 3108 | { |
Jouni Malinen | bce048d | 2009-03-03 19:23:28 +0200 | [diff] [blame] | 3109 | struct ath_wiphy *aphy = hw->priv; |
| 3110 | struct ath_softc *sc = aphy->sc; |
Sujith | 0c98de6 | 2009-03-03 10:16:45 +0530 | [diff] [blame] | 3111 | |
Sujith | 3d83261 | 2009-08-21 12:00:28 +0530 | [diff] [blame] | 3112 | mutex_lock(&sc->mutex); |
Jouni Malinen | 8089cc4 | 2009-03-03 19:23:38 +0200 | [diff] [blame] | 3113 | if (ath9k_wiphy_scanning(sc)) { |
| 3114 | printk(KERN_DEBUG "ath9k: Two wiphys trying to scan at the " |
| 3115 | "same time\n"); |
| 3116 | /* |
| 3117 | * Do not allow the concurrent scanning state for now. This |
| 3118 | * could be improved with scanning control moved into ath9k. |
| 3119 | */ |
Sujith | 3d83261 | 2009-08-21 12:00:28 +0530 | [diff] [blame] | 3120 | mutex_unlock(&sc->mutex); |
Jouni Malinen | 8089cc4 | 2009-03-03 19:23:38 +0200 | [diff] [blame] | 3121 | return; |
| 3122 | } |
| 3123 | |
| 3124 | aphy->state = ATH_WIPHY_SCAN; |
| 3125 | ath9k_wiphy_pause_all_forced(sc, aphy); |
| 3126 | |
Senthil Balasubramanian | e5f0921 | 2009-06-24 18:56:41 +0530 | [diff] [blame] | 3127 | spin_lock_bh(&sc->ani_lock); |
Sujith | 0c98de6 | 2009-03-03 10:16:45 +0530 | [diff] [blame] | 3128 | sc->sc_flags |= SC_OP_SCANNING; |
Senthil Balasubramanian | e5f0921 | 2009-06-24 18:56:41 +0530 | [diff] [blame] | 3129 | spin_unlock_bh(&sc->ani_lock); |
Sujith | 3d83261 | 2009-08-21 12:00:28 +0530 | [diff] [blame] | 3130 | mutex_unlock(&sc->mutex); |
Sujith | 0c98de6 | 2009-03-03 10:16:45 +0530 | [diff] [blame] | 3131 | } |
| 3132 | |
| 3133 | static void ath9k_sw_scan_complete(struct ieee80211_hw *hw) |
| 3134 | { |
Jouni Malinen | bce048d | 2009-03-03 19:23:28 +0200 | [diff] [blame] | 3135 | struct ath_wiphy *aphy = hw->priv; |
| 3136 | struct ath_softc *sc = aphy->sc; |
Sujith | 0c98de6 | 2009-03-03 10:16:45 +0530 | [diff] [blame] | 3137 | |
Sujith | 3d83261 | 2009-08-21 12:00:28 +0530 | [diff] [blame] | 3138 | mutex_lock(&sc->mutex); |
Senthil Balasubramanian | e5f0921 | 2009-06-24 18:56:41 +0530 | [diff] [blame] | 3139 | spin_lock_bh(&sc->ani_lock); |
Jouni Malinen | 8089cc4 | 2009-03-03 19:23:38 +0200 | [diff] [blame] | 3140 | aphy->state = ATH_WIPHY_ACTIVE; |
Sujith | 0c98de6 | 2009-03-03 10:16:45 +0530 | [diff] [blame] | 3141 | sc->sc_flags &= ~SC_OP_SCANNING; |
Sujith | 9c07a77 | 2009-04-13 21:56:36 +0530 | [diff] [blame] | 3142 | sc->sc_flags |= SC_OP_FULL_RESET; |
Senthil Balasubramanian | e5f0921 | 2009-06-24 18:56:41 +0530 | [diff] [blame] | 3143 | spin_unlock_bh(&sc->ani_lock); |
Vivek Natarajan | d0bec34 | 2009-09-02 15:50:55 +0530 | [diff] [blame] | 3144 | ath_beacon_config(sc, NULL); |
Sujith | 3d83261 | 2009-08-21 12:00:28 +0530 | [diff] [blame] | 3145 | mutex_unlock(&sc->mutex); |
Sujith | 0c98de6 | 2009-03-03 10:16:45 +0530 | [diff] [blame] | 3146 | } |
| 3147 | |
Gabor Juhos | 6baff7f | 2009-01-14 20:17:06 +0100 | [diff] [blame] | 3148 | struct ieee80211_ops ath9k_ops = { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3149 | .tx = ath9k_tx, |
| 3150 | .start = ath9k_start, |
| 3151 | .stop = ath9k_stop, |
| 3152 | .add_interface = ath9k_add_interface, |
| 3153 | .remove_interface = ath9k_remove_interface, |
| 3154 | .config = ath9k_config, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3155 | .configure_filter = ath9k_configure_filter, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3156 | .sta_notify = ath9k_sta_notify, |
| 3157 | .conf_tx = ath9k_conf_tx, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3158 | .bss_info_changed = ath9k_bss_info_changed, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3159 | .set_key = ath9k_set_key, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3160 | .get_tsf = ath9k_get_tsf, |
Alina Friedrichsen | 3b5d665 | 2009-01-24 07:09:59 +0100 | [diff] [blame] | 3161 | .set_tsf = ath9k_set_tsf, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3162 | .reset_tsf = ath9k_reset_tsf, |
Johannes Berg | 4233df6 | 2008-10-13 13:35:05 +0200 | [diff] [blame] | 3163 | .ampdu_action = ath9k_ampdu_action, |
Sujith | 0c98de6 | 2009-03-03 10:16:45 +0530 | [diff] [blame] | 3164 | .sw_scan_start = ath9k_sw_scan_start, |
| 3165 | .sw_scan_complete = ath9k_sw_scan_complete, |
Johannes Berg | 3b319aa | 2009-06-13 14:50:26 +0530 | [diff] [blame] | 3166 | .rfkill_poll = ath9k_rfkill_poll_state, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3167 | }; |
| 3168 | |
Benoit PAPILLAULT | 392dff8 | 2008-11-06 22:26:49 +0100 | [diff] [blame] | 3169 | static struct { |
| 3170 | u32 version; |
| 3171 | const char * name; |
| 3172 | } ath_mac_bb_names[] = { |
| 3173 | { AR_SREV_VERSION_5416_PCI, "5416" }, |
| 3174 | { AR_SREV_VERSION_5416_PCIE, "5418" }, |
| 3175 | { AR_SREV_VERSION_9100, "9100" }, |
| 3176 | { AR_SREV_VERSION_9160, "9160" }, |
| 3177 | { AR_SREV_VERSION_9280, "9280" }, |
Vivek Natarajan | ac88b6e | 2009-07-23 10:59:57 +0530 | [diff] [blame] | 3178 | { AR_SREV_VERSION_9285, "9285" }, |
| 3179 | { AR_SREV_VERSION_9287, "9287" } |
Benoit PAPILLAULT | 392dff8 | 2008-11-06 22:26:49 +0100 | [diff] [blame] | 3180 | }; |
| 3181 | |
| 3182 | static struct { |
| 3183 | u16 version; |
| 3184 | const char * name; |
| 3185 | } ath_rf_names[] = { |
| 3186 | { 0, "5133" }, |
| 3187 | { AR_RAD5133_SREV_MAJOR, "5133" }, |
| 3188 | { AR_RAD5122_SREV_MAJOR, "5122" }, |
| 3189 | { AR_RAD2133_SREV_MAJOR, "2133" }, |
| 3190 | { AR_RAD2122_SREV_MAJOR, "2122" } |
| 3191 | }; |
| 3192 | |
| 3193 | /* |
| 3194 | * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown. |
| 3195 | */ |
Gabor Juhos | 6baff7f | 2009-01-14 20:17:06 +0100 | [diff] [blame] | 3196 | const char * |
Benoit PAPILLAULT | 392dff8 | 2008-11-06 22:26:49 +0100 | [diff] [blame] | 3197 | ath_mac_bb_name(u32 mac_bb_version) |
| 3198 | { |
| 3199 | int i; |
| 3200 | |
| 3201 | for (i=0; i<ARRAY_SIZE(ath_mac_bb_names); i++) { |
| 3202 | if (ath_mac_bb_names[i].version == mac_bb_version) { |
| 3203 | return ath_mac_bb_names[i].name; |
| 3204 | } |
| 3205 | } |
| 3206 | |
| 3207 | return "????"; |
| 3208 | } |
| 3209 | |
| 3210 | /* |
| 3211 | * Return the RF name. "????" is returned if the RF is unknown. |
| 3212 | */ |
Gabor Juhos | 6baff7f | 2009-01-14 20:17:06 +0100 | [diff] [blame] | 3213 | const char * |
Benoit PAPILLAULT | 392dff8 | 2008-11-06 22:26:49 +0100 | [diff] [blame] | 3214 | ath_rf_name(u16 rf_version) |
| 3215 | { |
| 3216 | int i; |
| 3217 | |
| 3218 | for (i=0; i<ARRAY_SIZE(ath_rf_names); i++) { |
| 3219 | if (ath_rf_names[i].version == rf_version) { |
| 3220 | return ath_rf_names[i].name; |
| 3221 | } |
| 3222 | } |
| 3223 | |
| 3224 | return "????"; |
| 3225 | } |
| 3226 | |
Gabor Juhos | 6baff7f | 2009-01-14 20:17:06 +0100 | [diff] [blame] | 3227 | static int __init ath9k_init(void) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3228 | { |
Vasanthakumar Thiagarajan | ca8a856 | 2008-12-16 12:37:38 +0530 | [diff] [blame] | 3229 | int error; |
| 3230 | |
Vasanthakumar Thiagarajan | ca8a856 | 2008-12-16 12:37:38 +0530 | [diff] [blame] | 3231 | /* Register rate control algorithm */ |
| 3232 | error = ath_rate_control_register(); |
| 3233 | if (error != 0) { |
| 3234 | printk(KERN_ERR |
Luis R. Rodriguez | b51bb3c | 2009-01-26 07:30:03 -0800 | [diff] [blame] | 3235 | "ath9k: Unable to register rate control " |
| 3236 | "algorithm: %d\n", |
Vasanthakumar Thiagarajan | ca8a856 | 2008-12-16 12:37:38 +0530 | [diff] [blame] | 3237 | error); |
Gabor Juhos | 6baff7f | 2009-01-14 20:17:06 +0100 | [diff] [blame] | 3238 | goto err_out; |
Vasanthakumar Thiagarajan | ca8a856 | 2008-12-16 12:37:38 +0530 | [diff] [blame] | 3239 | } |
| 3240 | |
Gabor Juhos | 19d8bc2 | 2009-03-05 16:55:18 +0100 | [diff] [blame] | 3241 | error = ath9k_debug_create_root(); |
| 3242 | if (error) { |
| 3243 | printk(KERN_ERR |
| 3244 | "ath9k: Unable to create debugfs root: %d\n", |
| 3245 | error); |
| 3246 | goto err_rate_unregister; |
| 3247 | } |
| 3248 | |
Gabor Juhos | 6baff7f | 2009-01-14 20:17:06 +0100 | [diff] [blame] | 3249 | error = ath_pci_init(); |
| 3250 | if (error < 0) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3251 | printk(KERN_ERR |
Luis R. Rodriguez | b51bb3c | 2009-01-26 07:30:03 -0800 | [diff] [blame] | 3252 | "ath9k: No PCI devices found, driver not installed.\n"); |
Gabor Juhos | 6baff7f | 2009-01-14 20:17:06 +0100 | [diff] [blame] | 3253 | error = -ENODEV; |
Gabor Juhos | 19d8bc2 | 2009-03-05 16:55:18 +0100 | [diff] [blame] | 3254 | goto err_remove_root; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3255 | } |
| 3256 | |
Gabor Juhos | 09329d3 | 2009-01-14 20:17:07 +0100 | [diff] [blame] | 3257 | error = ath_ahb_init(); |
| 3258 | if (error < 0) { |
| 3259 | error = -ENODEV; |
| 3260 | goto err_pci_exit; |
| 3261 | } |
| 3262 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3263 | return 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3264 | |
Gabor Juhos | 09329d3 | 2009-01-14 20:17:07 +0100 | [diff] [blame] | 3265 | err_pci_exit: |
| 3266 | ath_pci_exit(); |
| 3267 | |
Gabor Juhos | 19d8bc2 | 2009-03-05 16:55:18 +0100 | [diff] [blame] | 3268 | err_remove_root: |
| 3269 | ath9k_debug_remove_root(); |
Gabor Juhos | 6baff7f | 2009-01-14 20:17:06 +0100 | [diff] [blame] | 3270 | err_rate_unregister: |
Vasanthakumar Thiagarajan | ca8a856 | 2008-12-16 12:37:38 +0530 | [diff] [blame] | 3271 | ath_rate_control_unregister(); |
Gabor Juhos | 6baff7f | 2009-01-14 20:17:06 +0100 | [diff] [blame] | 3272 | err_out: |
| 3273 | return error; |
| 3274 | } |
| 3275 | module_init(ath9k_init); |
| 3276 | |
| 3277 | static void __exit ath9k_exit(void) |
| 3278 | { |
Gabor Juhos | 09329d3 | 2009-01-14 20:17:07 +0100 | [diff] [blame] | 3279 | ath_ahb_exit(); |
Gabor Juhos | 6baff7f | 2009-01-14 20:17:06 +0100 | [diff] [blame] | 3280 | ath_pci_exit(); |
Gabor Juhos | 19d8bc2 | 2009-03-05 16:55:18 +0100 | [diff] [blame] | 3281 | ath9k_debug_remove_root(); |
Gabor Juhos | 6baff7f | 2009-01-14 20:17:06 +0100 | [diff] [blame] | 3282 | ath_rate_control_unregister(); |
Sujith | 04bd463 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 3283 | printk(KERN_INFO "%s: Driver unloaded\n", dev_info); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3284 | } |
Gabor Juhos | 6baff7f | 2009-01-14 20:17:06 +0100 | [diff] [blame] | 3285 | module_exit(ath9k_exit); |