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 | |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 21 | static void ath_update_txpow(struct ath_softc *sc) |
| 22 | { |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 23 | struct ath_hw *ah = sc->sc_ah; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 24 | |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 25 | if (sc->curtxpow != sc->config.txpowlimit) { |
| 26 | ath9k_hw_set_txpowerlimit(ah, sc->config.txpowlimit); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 27 | /* read back in case value is clamped */ |
Felix Fietkau | 9cc3271 | 2010-06-12 17:22:29 +0200 | [diff] [blame] | 28 | sc->curtxpow = ath9k_hw_regulatory(ah)->power_limit; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 29 | } |
| 30 | } |
| 31 | |
| 32 | static u8 parse_mpdudensity(u8 mpdudensity) |
| 33 | { |
| 34 | /* |
| 35 | * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing": |
| 36 | * 0 for no restriction |
| 37 | * 1 for 1/4 us |
| 38 | * 2 for 1/2 us |
| 39 | * 3 for 1 us |
| 40 | * 4 for 2 us |
| 41 | * 5 for 4 us |
| 42 | * 6 for 8 us |
| 43 | * 7 for 16 us |
| 44 | */ |
| 45 | switch (mpdudensity) { |
| 46 | case 0: |
| 47 | return 0; |
| 48 | case 1: |
| 49 | case 2: |
| 50 | case 3: |
| 51 | /* Our lower layer calculations limit our precision to |
| 52 | 1 microsecond */ |
| 53 | return 1; |
| 54 | case 4: |
| 55 | return 2; |
| 56 | case 5: |
| 57 | return 4; |
| 58 | case 6: |
| 59 | return 8; |
| 60 | case 7: |
| 61 | return 16; |
| 62 | default: |
| 63 | return 0; |
| 64 | } |
| 65 | } |
| 66 | |
Vasanthakumar Thiagarajan | 82880a7 | 2009-06-13 14:50:24 +0530 | [diff] [blame] | 67 | static struct ath9k_channel *ath_get_curchannel(struct ath_softc *sc, |
| 68 | struct ieee80211_hw *hw) |
| 69 | { |
| 70 | struct ieee80211_channel *curchan = hw->conf.channel; |
| 71 | struct ath9k_channel *channel; |
| 72 | u8 chan_idx; |
| 73 | |
| 74 | chan_idx = curchan->hw_value; |
| 75 | channel = &sc->sc_ah->channels[chan_idx]; |
| 76 | ath9k_update_ichannel(sc, hw, channel); |
| 77 | return channel; |
| 78 | } |
| 79 | |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 80 | 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] | 81 | { |
| 82 | unsigned long flags; |
| 83 | bool ret; |
| 84 | |
Luis R. Rodriguez | 9ecdef4 | 2009-09-09 21:10:09 -0700 | [diff] [blame] | 85 | spin_lock_irqsave(&sc->sc_pm_lock, flags); |
| 86 | ret = ath9k_hw_setpower(sc->sc_ah, mode); |
| 87 | spin_unlock_irqrestore(&sc->sc_pm_lock, flags); |
Luis R. Rodriguez | 8c77a56 | 2009-09-09 21:02:34 -0700 | [diff] [blame] | 88 | |
| 89 | return ret; |
| 90 | } |
| 91 | |
Luis R. Rodriguez | a91d75ae | 2009-09-09 20:29:18 -0700 | [diff] [blame] | 92 | void ath9k_ps_wakeup(struct ath_softc *sc) |
| 93 | { |
Felix Fietkau | 898c914 | 2010-10-12 14:02:53 +0200 | [diff] [blame] | 94 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Luis R. Rodriguez | a91d75ae | 2009-09-09 20:29:18 -0700 | [diff] [blame] | 95 | unsigned long flags; |
| 96 | |
| 97 | spin_lock_irqsave(&sc->sc_pm_lock, flags); |
| 98 | if (++sc->ps_usecount != 1) |
| 99 | goto unlock; |
| 100 | |
Luis R. Rodriguez | 9ecdef4 | 2009-09-09 21:10:09 -0700 | [diff] [blame] | 101 | ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_AWAKE); |
Luis R. Rodriguez | a91d75ae | 2009-09-09 20:29:18 -0700 | [diff] [blame] | 102 | |
Felix Fietkau | 898c914 | 2010-10-12 14:02:53 +0200 | [diff] [blame] | 103 | /* |
| 104 | * While the hardware is asleep, the cycle counters contain no |
| 105 | * useful data. Better clear them now so that they don't mess up |
| 106 | * survey data results. |
| 107 | */ |
| 108 | spin_lock(&common->cc_lock); |
| 109 | ath_hw_cycle_counters_update(common); |
| 110 | memset(&common->cc_survey, 0, sizeof(common->cc_survey)); |
| 111 | spin_unlock(&common->cc_lock); |
| 112 | |
Luis R. Rodriguez | a91d75ae | 2009-09-09 20:29:18 -0700 | [diff] [blame] | 113 | unlock: |
| 114 | spin_unlock_irqrestore(&sc->sc_pm_lock, flags); |
| 115 | } |
| 116 | |
| 117 | void ath9k_ps_restore(struct ath_softc *sc) |
| 118 | { |
Felix Fietkau | 898c914 | 2010-10-12 14:02:53 +0200 | [diff] [blame] | 119 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Luis R. Rodriguez | a91d75ae | 2009-09-09 20:29:18 -0700 | [diff] [blame] | 120 | unsigned long flags; |
| 121 | |
| 122 | spin_lock_irqsave(&sc->sc_pm_lock, flags); |
| 123 | if (--sc->ps_usecount != 0) |
| 124 | goto unlock; |
| 125 | |
Felix Fietkau | 898c914 | 2010-10-12 14:02:53 +0200 | [diff] [blame] | 126 | spin_lock(&common->cc_lock); |
| 127 | ath_hw_cycle_counters_update(common); |
| 128 | spin_unlock(&common->cc_lock); |
| 129 | |
Vivek Natarajan | 1dbfd9d | 2010-01-29 16:56:51 +0530 | [diff] [blame] | 130 | if (sc->ps_idle) |
| 131 | ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_FULL_SLEEP); |
| 132 | else if (sc->ps_enabled && |
| 133 | !(sc->ps_flags & (PS_WAIT_FOR_BEACON | |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 134 | PS_WAIT_FOR_CAB | |
| 135 | PS_WAIT_FOR_PSPOLL_DATA | |
| 136 | PS_WAIT_FOR_TX_ACK))) |
Luis R. Rodriguez | 9ecdef4 | 2009-09-09 21:10:09 -0700 | [diff] [blame] | 137 | ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_NETWORK_SLEEP); |
Luis R. Rodriguez | a91d75ae | 2009-09-09 20:29:18 -0700 | [diff] [blame] | 138 | |
| 139 | unlock: |
| 140 | spin_unlock_irqrestore(&sc->sc_pm_lock, flags); |
| 141 | } |
| 142 | |
Felix Fietkau | 5ee0865 | 2010-07-31 00:11:59 +0200 | [diff] [blame] | 143 | static void ath_start_ani(struct ath_common *common) |
| 144 | { |
| 145 | struct ath_hw *ah = common->ah; |
| 146 | unsigned long timestamp = jiffies_to_msecs(jiffies); |
| 147 | struct ath_softc *sc = (struct ath_softc *) common->priv; |
| 148 | |
| 149 | if (!(sc->sc_flags & SC_OP_ANI_RUN)) |
| 150 | return; |
| 151 | |
| 152 | if (sc->sc_flags & SC_OP_OFFCHANNEL) |
| 153 | return; |
| 154 | |
| 155 | common->ani.longcal_timer = timestamp; |
| 156 | common->ani.shortcal_timer = timestamp; |
| 157 | common->ani.checkani_timer = timestamp; |
| 158 | |
| 159 | mod_timer(&common->ani.timer, |
| 160 | jiffies + |
| 161 | msecs_to_jiffies((u32)ah->config.ani_poll_interval)); |
| 162 | } |
| 163 | |
Felix Fietkau | 3430098 | 2010-10-10 18:21:52 +0200 | [diff] [blame] | 164 | static void ath_update_survey_nf(struct ath_softc *sc, int channel) |
| 165 | { |
| 166 | struct ath_hw *ah = sc->sc_ah; |
| 167 | struct ath9k_channel *chan = &ah->channels[channel]; |
| 168 | struct survey_info *survey = &sc->survey[channel]; |
| 169 | |
| 170 | if (chan->noisefloor) { |
| 171 | survey->filled |= SURVEY_INFO_NOISE_DBM; |
| 172 | survey->noise = chan->noisefloor; |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | static void ath_update_survey_stats(struct ath_softc *sc) |
| 177 | { |
| 178 | struct ath_hw *ah = sc->sc_ah; |
| 179 | struct ath_common *common = ath9k_hw_common(ah); |
| 180 | int pos = ah->curchan - &ah->channels[0]; |
| 181 | struct survey_info *survey = &sc->survey[pos]; |
| 182 | struct ath_cycle_counters *cc = &common->cc_survey; |
| 183 | unsigned int div = common->clockrate * 1000; |
| 184 | |
Felix Fietkau | 0845735 | 2010-10-20 15:59:28 +0200 | [diff] [blame] | 185 | if (!ah->curchan) |
| 186 | return; |
| 187 | |
Felix Fietkau | 898c914 | 2010-10-12 14:02:53 +0200 | [diff] [blame] | 188 | if (ah->power_mode == ATH9K_PM_AWAKE) |
| 189 | ath_hw_cycle_counters_update(common); |
Felix Fietkau | 3430098 | 2010-10-10 18:21:52 +0200 | [diff] [blame] | 190 | |
| 191 | if (cc->cycles > 0) { |
| 192 | survey->filled |= SURVEY_INFO_CHANNEL_TIME | |
| 193 | SURVEY_INFO_CHANNEL_TIME_BUSY | |
| 194 | SURVEY_INFO_CHANNEL_TIME_RX | |
| 195 | SURVEY_INFO_CHANNEL_TIME_TX; |
| 196 | survey->channel_time += cc->cycles / div; |
| 197 | survey->channel_time_busy += cc->rx_busy / div; |
| 198 | survey->channel_time_rx += cc->rx_frame / div; |
| 199 | survey->channel_time_tx += cc->tx_frame / div; |
| 200 | } |
| 201 | memset(cc, 0, sizeof(*cc)); |
| 202 | |
| 203 | ath_update_survey_nf(sc, pos); |
| 204 | } |
| 205 | |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 206 | /* |
| 207 | * Set/change channels. If the channel is really being changed, it's done |
| 208 | * by reseting the chip. To accomplish this we must first cleanup any pending |
| 209 | * DMA, then restart stuff. |
| 210 | */ |
Jouni Malinen | 0e2dedf | 2009-03-03 19:23:32 +0200 | [diff] [blame] | 211 | int ath_set_channel(struct ath_softc *sc, struct ieee80211_hw *hw, |
| 212 | struct ath9k_channel *hchan) |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 213 | { |
Felix Fietkau | 20bd2a0 | 2010-07-31 00:12:00 +0200 | [diff] [blame] | 214 | struct ath_wiphy *aphy = hw->priv; |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 215 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 216 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | 25c56ee | 2009-09-13 23:04:44 -0700 | [diff] [blame] | 217 | struct ieee80211_conf *conf = &common->hw->conf; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 218 | bool fastcc = true, stopped; |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 219 | struct ieee80211_channel *channel = hw->conf.channel; |
Felix Fietkau | 20bd2a0 | 2010-07-31 00:12:00 +0200 | [diff] [blame] | 220 | struct ath9k_hw_cal_data *caldata = NULL; |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 221 | int r; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 222 | |
| 223 | if (sc->sc_flags & SC_OP_INVALID) |
| 224 | return -EIO; |
| 225 | |
Felix Fietkau | 5ee0865 | 2010-07-31 00:11:59 +0200 | [diff] [blame] | 226 | del_timer_sync(&common->ani.timer); |
| 227 | cancel_work_sync(&sc->paprd_work); |
| 228 | cancel_work_sync(&sc->hw_check_work); |
| 229 | cancel_delayed_work_sync(&sc->tx_complete_work); |
| 230 | |
Vivek Natarajan | 3cbb5dd | 2009-01-20 11:17:08 +0530 | [diff] [blame] | 231 | ath9k_ps_wakeup(sc); |
| 232 | |
Luis R. Rodriguez | c0d7c7a | 2008-12-23 15:58:50 -0800 | [diff] [blame] | 233 | /* |
| 234 | * This is only performed if the channel settings have |
| 235 | * actually changed. |
| 236 | * |
| 237 | * To switch channels clear any pending DMA operations; |
| 238 | * wait long enough for the RX fifo to drain, reset the |
| 239 | * hardware at the new frequency, and then re-enable |
| 240 | * the relevant bits of the h/w. |
| 241 | */ |
Felix Fietkau | 4df3071 | 2010-11-08 20:54:47 +0100 | [diff] [blame] | 242 | ath9k_hw_disable_interrupts(ah); |
Sujith | 043a040 | 2009-01-16 21:38:47 +0530 | [diff] [blame] | 243 | ath_drain_all_txq(sc, false); |
Luis R. Rodriguez | 5e848f7 | 2010-10-20 16:07:06 -0700 | [diff] [blame] | 244 | |
| 245 | spin_lock_bh(&sc->rx.pcu_lock); |
| 246 | |
Luis R. Rodriguez | c0d7c7a | 2008-12-23 15:58:50 -0800 | [diff] [blame] | 247 | stopped = ath_stoprecv(sc); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 248 | |
Luis R. Rodriguez | c0d7c7a | 2008-12-23 15:58:50 -0800 | [diff] [blame] | 249 | /* XXX: do not flush receive queue here. We don't want |
| 250 | * to flush data frames already in queue because of |
| 251 | * changing channel. */ |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 252 | |
Felix Fietkau | 5ee0865 | 2010-07-31 00:11:59 +0200 | [diff] [blame] | 253 | if (!stopped || !(sc->sc_flags & SC_OP_OFFCHANNEL)) |
Luis R. Rodriguez | c0d7c7a | 2008-12-23 15:58:50 -0800 | [diff] [blame] | 254 | fastcc = false; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 255 | |
Felix Fietkau | 20bd2a0 | 2010-07-31 00:12:00 +0200 | [diff] [blame] | 256 | if (!(sc->sc_flags & SC_OP_OFFCHANNEL)) |
| 257 | caldata = &aphy->caldata; |
| 258 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 259 | ath_print(common, ATH_DBG_CONFIG, |
Luis R. Rodriguez | 1e51b2f | 2010-07-29 22:56:22 -0400 | [diff] [blame] | 260 | "(%u MHz) -> (%u MHz), conf_is_ht40: %d fastcc: %d\n", |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 261 | sc->sc_ah->curchan->channel, |
Luis R. Rodriguez | 1e51b2f | 2010-07-29 22:56:22 -0400 | [diff] [blame] | 262 | channel->center_freq, conf_is_ht40(conf), |
| 263 | fastcc); |
Sujith | 99405f9 | 2008-11-24 12:08:35 +0530 | [diff] [blame] | 264 | |
Luis R. Rodriguez | c0d7c7a | 2008-12-23 15:58:50 -0800 | [diff] [blame] | 265 | spin_lock_bh(&sc->sc_resetlock); |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 266 | |
Felix Fietkau | 20bd2a0 | 2010-07-31 00:12:00 +0200 | [diff] [blame] | 267 | r = ath9k_hw_reset(ah, hchan, caldata, fastcc); |
Luis R. Rodriguez | c0d7c7a | 2008-12-23 15:58:50 -0800 | [diff] [blame] | 268 | if (r) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 269 | ath_print(common, ATH_DBG_FATAL, |
Pavel Roskin | f643e51 | 2010-01-29 17:22:12 -0500 | [diff] [blame] | 270 | "Unable to reset channel (%u MHz), " |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 271 | "reset status %d\n", |
| 272 | channel->center_freq, r); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 273 | spin_unlock_bh(&sc->sc_resetlock); |
Luis R. Rodriguez | 5e848f7 | 2010-10-20 16:07:06 -0700 | [diff] [blame] | 274 | spin_unlock_bh(&sc->rx.pcu_lock); |
Gabor Juhos | 3989279 | 2009-06-15 17:49:09 +0200 | [diff] [blame] | 275 | goto ps_restore; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 276 | } |
Luis R. Rodriguez | c0d7c7a | 2008-12-23 15:58:50 -0800 | [diff] [blame] | 277 | spin_unlock_bh(&sc->sc_resetlock); |
| 278 | |
Luis R. Rodriguez | c0d7c7a | 2008-12-23 15:58:50 -0800 | [diff] [blame] | 279 | if (ath_startrecv(sc) != 0) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 280 | ath_print(common, ATH_DBG_FATAL, |
| 281 | "Unable to restart recv logic\n"); |
Gabor Juhos | 3989279 | 2009-06-15 17:49:09 +0200 | [diff] [blame] | 282 | r = -EIO; |
Luis R. Rodriguez | 5e848f7 | 2010-10-20 16:07:06 -0700 | [diff] [blame] | 283 | spin_unlock_bh(&sc->rx.pcu_lock); |
Gabor Juhos | 3989279 | 2009-06-15 17:49:09 +0200 | [diff] [blame] | 284 | goto ps_restore; |
Luis R. Rodriguez | c0d7c7a | 2008-12-23 15:58:50 -0800 | [diff] [blame] | 285 | } |
| 286 | |
Luis R. Rodriguez | 5e848f7 | 2010-10-20 16:07:06 -0700 | [diff] [blame] | 287 | spin_unlock_bh(&sc->rx.pcu_lock); |
| 288 | |
Luis R. Rodriguez | c0d7c7a | 2008-12-23 15:58:50 -0800 | [diff] [blame] | 289 | ath_update_txpow(sc); |
Pavel Roskin | 3069168 | 2010-03-31 18:05:31 -0400 | [diff] [blame] | 290 | ath9k_hw_set_interrupts(ah, ah->imask); |
Gabor Juhos | 3989279 | 2009-06-15 17:49:09 +0200 | [diff] [blame] | 291 | |
Luis R. Rodriguez | 48a6a46 | 2010-09-16 15:12:28 -0400 | [diff] [blame] | 292 | if (!(sc->sc_flags & (SC_OP_OFFCHANNEL))) { |
Luis R. Rodriguez | 52b8ac9 | 2010-09-16 15:12:27 -0400 | [diff] [blame] | 293 | ath_beacon_config(sc, NULL); |
Luis R. Rodriguez | 48a6a46 | 2010-09-16 15:12:28 -0400 | [diff] [blame] | 294 | ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0); |
| 295 | ath_start_ani(common); |
| 296 | } |
Luis R. Rodriguez | 52b8ac9 | 2010-09-16 15:12:27 -0400 | [diff] [blame] | 297 | |
Gabor Juhos | 3989279 | 2009-06-15 17:49:09 +0200 | [diff] [blame] | 298 | ps_restore: |
Vivek Natarajan | 3cbb5dd | 2009-01-20 11:17:08 +0530 | [diff] [blame] | 299 | ath9k_ps_restore(sc); |
Gabor Juhos | 3989279 | 2009-06-15 17:49:09 +0200 | [diff] [blame] | 300 | return r; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 301 | } |
| 302 | |
Felix Fietkau | 9f42c2b | 2010-06-12 00:34:01 -0400 | [diff] [blame] | 303 | static void ath_paprd_activate(struct ath_softc *sc) |
| 304 | { |
| 305 | struct ath_hw *ah = sc->sc_ah; |
Felix Fietkau | 20bd2a0 | 2010-07-31 00:12:00 +0200 | [diff] [blame] | 306 | struct ath9k_hw_cal_data *caldata = ah->caldata; |
Vasanthakumar Thiagarajan | 9094537 | 2010-09-20 22:54:46 -0700 | [diff] [blame] | 307 | struct ath_common *common = ath9k_hw_common(ah); |
Felix Fietkau | 9f42c2b | 2010-06-12 00:34:01 -0400 | [diff] [blame] | 308 | int chain; |
| 309 | |
Felix Fietkau | 20bd2a0 | 2010-07-31 00:12:00 +0200 | [diff] [blame] | 310 | if (!caldata || !caldata->paprd_done) |
Felix Fietkau | 9f42c2b | 2010-06-12 00:34:01 -0400 | [diff] [blame] | 311 | return; |
| 312 | |
| 313 | ath9k_ps_wakeup(sc); |
Felix Fietkau | ddfef792 | 2010-07-30 21:02:11 +0200 | [diff] [blame] | 314 | ar9003_paprd_enable(ah, false); |
Felix Fietkau | 9f42c2b | 2010-06-12 00:34:01 -0400 | [diff] [blame] | 315 | for (chain = 0; chain < AR9300_MAX_CHAINS; chain++) { |
Vasanthakumar Thiagarajan | 9094537 | 2010-09-20 22:54:46 -0700 | [diff] [blame] | 316 | if (!(common->tx_chainmask & BIT(chain))) |
Felix Fietkau | 9f42c2b | 2010-06-12 00:34:01 -0400 | [diff] [blame] | 317 | continue; |
| 318 | |
Felix Fietkau | 20bd2a0 | 2010-07-31 00:12:00 +0200 | [diff] [blame] | 319 | ar9003_paprd_populate_single_table(ah, caldata, chain); |
Felix Fietkau | 9f42c2b | 2010-06-12 00:34:01 -0400 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | ar9003_paprd_enable(ah, true); |
| 323 | ath9k_ps_restore(sc); |
| 324 | } |
| 325 | |
| 326 | void ath_paprd_calibrate(struct work_struct *work) |
| 327 | { |
| 328 | struct ath_softc *sc = container_of(work, struct ath_softc, paprd_work); |
| 329 | struct ieee80211_hw *hw = sc->hw; |
| 330 | struct ath_hw *ah = sc->sc_ah; |
| 331 | struct ieee80211_hdr *hdr; |
| 332 | struct sk_buff *skb = NULL; |
| 333 | struct ieee80211_tx_info *tx_info; |
| 334 | int band = hw->conf.channel->band; |
| 335 | struct ieee80211_supported_band *sband = &sc->sbands[band]; |
| 336 | struct ath_tx_control txctl; |
Felix Fietkau | 20bd2a0 | 2010-07-31 00:12:00 +0200 | [diff] [blame] | 337 | struct ath9k_hw_cal_data *caldata = ah->caldata; |
Vasanthakumar Thiagarajan | 9094537 | 2010-09-20 22:54:46 -0700 | [diff] [blame] | 338 | struct ath_common *common = ath9k_hw_common(ah); |
Felix Fietkau | 9f42c2b | 2010-06-12 00:34:01 -0400 | [diff] [blame] | 339 | int qnum, ftype; |
| 340 | int chain_ok = 0; |
| 341 | int chain; |
| 342 | int len = 1800; |
| 343 | int time_left; |
| 344 | int i; |
| 345 | |
Felix Fietkau | 20bd2a0 | 2010-07-31 00:12:00 +0200 | [diff] [blame] | 346 | if (!caldata) |
| 347 | return; |
| 348 | |
Felix Fietkau | 9f42c2b | 2010-06-12 00:34:01 -0400 | [diff] [blame] | 349 | skb = alloc_skb(len, GFP_KERNEL); |
| 350 | if (!skb) |
| 351 | return; |
| 352 | |
| 353 | tx_info = IEEE80211_SKB_CB(skb); |
| 354 | |
| 355 | skb_put(skb, len); |
| 356 | memset(skb->data, 0, len); |
| 357 | hdr = (struct ieee80211_hdr *)skb->data; |
| 358 | ftype = IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC; |
| 359 | hdr->frame_control = cpu_to_le16(ftype); |
John W. Linville | a3d3da1 | 2010-07-20 13:15:31 -0400 | [diff] [blame] | 360 | hdr->duration_id = cpu_to_le16(10); |
Felix Fietkau | 9f42c2b | 2010-06-12 00:34:01 -0400 | [diff] [blame] | 361 | memcpy(hdr->addr1, hw->wiphy->perm_addr, ETH_ALEN); |
| 362 | memcpy(hdr->addr2, hw->wiphy->perm_addr, ETH_ALEN); |
| 363 | memcpy(hdr->addr3, hw->wiphy->perm_addr, ETH_ALEN); |
| 364 | |
| 365 | memset(&txctl, 0, sizeof(txctl)); |
| 366 | qnum = sc->tx.hwq_map[WME_AC_BE]; |
| 367 | txctl.txq = &sc->tx.txq[qnum]; |
| 368 | |
Vasanthakumar Thiagarajan | 47399f1 | 2010-06-24 04:09:27 -0700 | [diff] [blame] | 369 | ath9k_ps_wakeup(sc); |
Felix Fietkau | 9f42c2b | 2010-06-12 00:34:01 -0400 | [diff] [blame] | 370 | ar9003_paprd_init_table(ah); |
| 371 | for (chain = 0; chain < AR9300_MAX_CHAINS; chain++) { |
Vasanthakumar Thiagarajan | 9094537 | 2010-09-20 22:54:46 -0700 | [diff] [blame] | 372 | if (!(common->tx_chainmask & BIT(chain))) |
Felix Fietkau | 9f42c2b | 2010-06-12 00:34:01 -0400 | [diff] [blame] | 373 | continue; |
| 374 | |
| 375 | chain_ok = 0; |
| 376 | memset(tx_info, 0, sizeof(*tx_info)); |
| 377 | tx_info->band = band; |
| 378 | |
| 379 | for (i = 0; i < 4; i++) { |
| 380 | tx_info->control.rates[i].idx = sband->n_bitrates - 1; |
| 381 | tx_info->control.rates[i].count = 6; |
| 382 | } |
| 383 | |
| 384 | init_completion(&sc->paprd_complete); |
| 385 | ar9003_paprd_setup_gain_table(ah, chain); |
| 386 | txctl.paprd = BIT(chain); |
| 387 | if (ath_tx_start(hw, skb, &txctl) != 0) |
| 388 | break; |
| 389 | |
| 390 | time_left = wait_for_completion_timeout(&sc->paprd_complete, |
Vasanthakumar Thiagarajan | ca369eb | 2010-06-24 02:42:44 -0700 | [diff] [blame] | 391 | msecs_to_jiffies(ATH_PAPRD_TIMEOUT)); |
Felix Fietkau | 9f42c2b | 2010-06-12 00:34:01 -0400 | [diff] [blame] | 392 | if (!time_left) { |
| 393 | ath_print(ath9k_hw_common(ah), ATH_DBG_CALIBRATE, |
| 394 | "Timeout waiting for paprd training on " |
| 395 | "TX chain %d\n", |
| 396 | chain); |
Vasanthakumar Thiagarajan | ca369eb | 2010-06-24 02:42:44 -0700 | [diff] [blame] | 397 | goto fail_paprd; |
Felix Fietkau | 9f42c2b | 2010-06-12 00:34:01 -0400 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | if (!ar9003_paprd_is_done(ah)) |
| 401 | break; |
| 402 | |
Felix Fietkau | 20bd2a0 | 2010-07-31 00:12:00 +0200 | [diff] [blame] | 403 | if (ar9003_paprd_create_curve(ah, caldata, chain) != 0) |
Felix Fietkau | 9f42c2b | 2010-06-12 00:34:01 -0400 | [diff] [blame] | 404 | break; |
| 405 | |
| 406 | chain_ok = 1; |
| 407 | } |
| 408 | kfree_skb(skb); |
| 409 | |
| 410 | if (chain_ok) { |
Felix Fietkau | 20bd2a0 | 2010-07-31 00:12:00 +0200 | [diff] [blame] | 411 | caldata->paprd_done = true; |
Felix Fietkau | 9f42c2b | 2010-06-12 00:34:01 -0400 | [diff] [blame] | 412 | ath_paprd_activate(sc); |
| 413 | } |
| 414 | |
Vasanthakumar Thiagarajan | ca369eb | 2010-06-24 02:42:44 -0700 | [diff] [blame] | 415 | fail_paprd: |
Felix Fietkau | 9f42c2b | 2010-06-12 00:34:01 -0400 | [diff] [blame] | 416 | ath9k_ps_restore(sc); |
| 417 | } |
| 418 | |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 419 | /* |
| 420 | * This routine performs the periodic noise floor calibration function |
| 421 | * that is used to adjust and optimize the chip performance. This |
| 422 | * takes environmental changes (location, temperature) into account. |
| 423 | * When the task is complete, it reschedules itself depending on the |
| 424 | * appropriate interval that was calculated. |
| 425 | */ |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 426 | void ath_ani_calibrate(unsigned long data) |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 427 | { |
Sujith | 20977d3 | 2009-02-20 15:13:28 +0530 | [diff] [blame] | 428 | struct ath_softc *sc = (struct ath_softc *)data; |
| 429 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 430 | struct ath_common *common = ath9k_hw_common(ah); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 431 | bool longcal = false; |
| 432 | bool shortcal = false; |
| 433 | bool aniflag = false; |
| 434 | unsigned int timestamp = jiffies_to_msecs(jiffies); |
Felix Fietkau | 6044474 | 2010-08-02 15:53:15 +0200 | [diff] [blame] | 435 | u32 cal_interval, short_cal_interval, long_cal_interval; |
Felix Fietkau | b5bfc56 | 2010-10-08 22:13:53 +0200 | [diff] [blame] | 436 | unsigned long flags; |
Felix Fietkau | 6044474 | 2010-08-02 15:53:15 +0200 | [diff] [blame] | 437 | |
| 438 | if (ah->caldata && ah->caldata->nfcal_interference) |
| 439 | long_cal_interval = ATH_LONG_CALINTERVAL_INT; |
| 440 | else |
| 441 | long_cal_interval = ATH_LONG_CALINTERVAL; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 442 | |
Sujith | 20977d3 | 2009-02-20 15:13:28 +0530 | [diff] [blame] | 443 | short_cal_interval = (ah->opmode == NL80211_IFTYPE_AP) ? |
| 444 | ATH_AP_SHORT_CALINTERVAL : ATH_STA_SHORT_CALINTERVAL; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 445 | |
Jouni Malinen | 1ffc1c6 | 2009-05-19 17:01:39 +0300 | [diff] [blame] | 446 | /* Only calibrate if awake */ |
| 447 | if (sc->sc_ah->power_mode != ATH9K_PM_AWAKE) |
| 448 | goto set_timer; |
| 449 | |
| 450 | ath9k_ps_wakeup(sc); |
| 451 | |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 452 | /* Long calibration runs independently of short calibration. */ |
Felix Fietkau | 6044474 | 2010-08-02 15:53:15 +0200 | [diff] [blame] | 453 | if ((timestamp - common->ani.longcal_timer) >= long_cal_interval) { |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 454 | longcal = true; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 455 | ath_print(common, ATH_DBG_ANI, "longcal @%lu\n", jiffies); |
Luis R. Rodriguez | 3d536ac | 2009-11-03 17:07:04 -0800 | [diff] [blame] | 456 | common->ani.longcal_timer = timestamp; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 457 | } |
| 458 | |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 459 | /* Short calibration applies only while caldone is false */ |
Luis R. Rodriguez | 3d536ac | 2009-11-03 17:07:04 -0800 | [diff] [blame] | 460 | if (!common->ani.caldone) { |
| 461 | if ((timestamp - common->ani.shortcal_timer) >= short_cal_interval) { |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 462 | shortcal = true; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 463 | ath_print(common, ATH_DBG_ANI, |
| 464 | "shortcal @%lu\n", jiffies); |
Luis R. Rodriguez | 3d536ac | 2009-11-03 17:07:04 -0800 | [diff] [blame] | 465 | common->ani.shortcal_timer = timestamp; |
| 466 | common->ani.resetcal_timer = timestamp; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 467 | } |
| 468 | } else { |
Luis R. Rodriguez | 3d536ac | 2009-11-03 17:07:04 -0800 | [diff] [blame] | 469 | if ((timestamp - common->ani.resetcal_timer) >= |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 470 | ATH_RESTART_CALINTERVAL) { |
Luis R. Rodriguez | 3d536ac | 2009-11-03 17:07:04 -0800 | [diff] [blame] | 471 | common->ani.caldone = ath9k_hw_reset_calvalid(ah); |
| 472 | if (common->ani.caldone) |
| 473 | common->ani.resetcal_timer = timestamp; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 474 | } |
| 475 | } |
| 476 | |
| 477 | /* Verify whether we must check ANI */ |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 478 | if ((timestamp - common->ani.checkani_timer) >= |
| 479 | ah->config.ani_poll_interval) { |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 480 | aniflag = true; |
Luis R. Rodriguez | 3d536ac | 2009-11-03 17:07:04 -0800 | [diff] [blame] | 481 | common->ani.checkani_timer = timestamp; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | /* Skip all processing if there's nothing to do. */ |
| 485 | if (longcal || shortcal || aniflag) { |
| 486 | /* Call ANI routine if necessary */ |
Felix Fietkau | b5bfc56 | 2010-10-08 22:13:53 +0200 | [diff] [blame] | 487 | if (aniflag) { |
| 488 | spin_lock_irqsave(&common->cc_lock, flags); |
Vasanthakumar Thiagarajan | 22e66a4 | 2009-08-19 16:23:40 +0530 | [diff] [blame] | 489 | ath9k_hw_ani_monitor(ah, ah->curchan); |
Felix Fietkau | 3430098 | 2010-10-10 18:21:52 +0200 | [diff] [blame] | 490 | ath_update_survey_stats(sc); |
Felix Fietkau | b5bfc56 | 2010-10-08 22:13:53 +0200 | [diff] [blame] | 491 | spin_unlock_irqrestore(&common->cc_lock, flags); |
| 492 | } |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 493 | |
| 494 | /* Perform calibration if necessary */ |
| 495 | if (longcal || shortcal) { |
Luis R. Rodriguez | 3d536ac | 2009-11-03 17:07:04 -0800 | [diff] [blame] | 496 | common->ani.caldone = |
Luis R. Rodriguez | 43c2761 | 2009-09-13 21:07:07 -0700 | [diff] [blame] | 497 | ath9k_hw_calibrate(ah, |
| 498 | ah->curchan, |
| 499 | common->rx_chainmask, |
| 500 | longcal); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 501 | } |
| 502 | } |
| 503 | |
Jouni Malinen | 1ffc1c6 | 2009-05-19 17:01:39 +0300 | [diff] [blame] | 504 | ath9k_ps_restore(sc); |
| 505 | |
Sujith | 20977d3 | 2009-02-20 15:13:28 +0530 | [diff] [blame] | 506 | set_timer: |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 507 | /* |
| 508 | * Set timer interval based on previous results. |
| 509 | * The interval must be the shortest necessary to satisfy ANI, |
| 510 | * short calibration and long calibration. |
| 511 | */ |
Sujith | aac9207 | 2008-12-02 18:37:54 +0530 | [diff] [blame] | 512 | cal_interval = ATH_LONG_CALINTERVAL; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 513 | if (sc->sc_ah->config.enable_ani) |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 514 | cal_interval = min(cal_interval, |
| 515 | (u32)ah->config.ani_poll_interval); |
Luis R. Rodriguez | 3d536ac | 2009-11-03 17:07:04 -0800 | [diff] [blame] | 516 | if (!common->ani.caldone) |
Sujith | 20977d3 | 2009-02-20 15:13:28 +0530 | [diff] [blame] | 517 | cal_interval = min(cal_interval, (u32)short_cal_interval); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 518 | |
Luis R. Rodriguez | 3d536ac | 2009-11-03 17:07:04 -0800 | [diff] [blame] | 519 | mod_timer(&common->ani.timer, jiffies + msecs_to_jiffies(cal_interval)); |
Felix Fietkau | 20bd2a0 | 2010-07-31 00:12:00 +0200 | [diff] [blame] | 520 | if ((sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_PAPRD) && ah->caldata) { |
| 521 | if (!ah->caldata->paprd_done) |
Felix Fietkau | 9f42c2b | 2010-06-12 00:34:01 -0400 | [diff] [blame] | 522 | ieee80211_queue_work(sc->hw, &sc->paprd_work); |
| 523 | else |
| 524 | ath_paprd_activate(sc); |
| 525 | } |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | /* |
| 529 | * Update tx/rx chainmask. For legacy association, |
| 530 | * hard code chainmask to 1x1, for 11n association, use |
Vasanthakumar Thiagarajan | c97c92d | 2009-01-02 15:35:46 +0530 | [diff] [blame] | 531 | * the chainmask configuration, for bt coexistence, use |
| 532 | * the chainmask configuration even in legacy mode. |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 533 | */ |
Jouni Malinen | 0e2dedf | 2009-03-03 19:23:32 +0200 | [diff] [blame] | 534 | void ath_update_chainmask(struct ath_softc *sc, int is_ht) |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 535 | { |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 536 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | 43c2761 | 2009-09-13 21:07:07 -0700 | [diff] [blame] | 537 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 538 | |
Felix Fietkau | 5ee0865 | 2010-07-31 00:11:59 +0200 | [diff] [blame] | 539 | if ((sc->sc_flags & SC_OP_OFFCHANNEL) || is_ht || |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 540 | (ah->btcoex_hw.scheme != ATH_BTCOEX_CFG_NONE)) { |
Luis R. Rodriguez | 43c2761 | 2009-09-13 21:07:07 -0700 | [diff] [blame] | 541 | common->tx_chainmask = ah->caps.tx_chainmask; |
| 542 | common->rx_chainmask = ah->caps.rx_chainmask; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 543 | } else { |
Luis R. Rodriguez | 43c2761 | 2009-09-13 21:07:07 -0700 | [diff] [blame] | 544 | common->tx_chainmask = 1; |
| 545 | common->rx_chainmask = 1; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 546 | } |
| 547 | |
Luis R. Rodriguez | 43c2761 | 2009-09-13 21:07:07 -0700 | [diff] [blame] | 548 | ath_print(common, ATH_DBG_CONFIG, |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 549 | "tx chmask: %d, rx chmask: %d\n", |
Luis R. Rodriguez | 43c2761 | 2009-09-13 21:07:07 -0700 | [diff] [blame] | 550 | common->tx_chainmask, |
| 551 | common->rx_chainmask); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | static void ath_node_attach(struct ath_softc *sc, struct ieee80211_sta *sta) |
| 555 | { |
| 556 | struct ath_node *an; |
| 557 | |
| 558 | an = (struct ath_node *)sta->drv_priv; |
| 559 | |
Sujith | 87792ef | 2009-03-30 15:28:48 +0530 | [diff] [blame] | 560 | if (sc->sc_flags & SC_OP_TXAGGR) { |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 561 | ath_tx_node_init(sc, an); |
Sujith | 9e98ac6 | 2009-07-23 15:32:34 +0530 | [diff] [blame] | 562 | an->maxampdu = 1 << (IEEE80211_HT_MAX_AMPDU_FACTOR + |
Sujith | 87792ef | 2009-03-30 15:28:48 +0530 | [diff] [blame] | 563 | sta->ht_cap.ampdu_factor); |
| 564 | an->mpdudensity = parse_mpdudensity(sta->ht_cap.ampdu_density); |
| 565 | } |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | static void ath_node_detach(struct ath_softc *sc, struct ieee80211_sta *sta) |
| 569 | { |
| 570 | struct ath_node *an = (struct ath_node *)sta->drv_priv; |
| 571 | |
| 572 | if (sc->sc_flags & SC_OP_TXAGGR) |
| 573 | ath_tx_node_cleanup(sc, an); |
| 574 | } |
| 575 | |
Felix Fietkau | 347809f | 2010-07-02 00:09:52 +0200 | [diff] [blame] | 576 | void ath_hw_check(struct work_struct *work) |
| 577 | { |
| 578 | struct ath_softc *sc = container_of(work, struct ath_softc, hw_check_work); |
| 579 | int i; |
| 580 | |
| 581 | ath9k_ps_wakeup(sc); |
| 582 | |
| 583 | for (i = 0; i < 3; i++) { |
| 584 | if (ath9k_hw_check_alive(sc->sc_ah)) |
| 585 | goto out; |
| 586 | |
| 587 | msleep(1); |
| 588 | } |
Felix Fietkau | fac6b6a | 2010-10-23 17:45:38 +0200 | [diff] [blame] | 589 | ath_reset(sc, true); |
Felix Fietkau | 347809f | 2010-07-02 00:09:52 +0200 | [diff] [blame] | 590 | |
| 591 | out: |
| 592 | ath9k_ps_restore(sc); |
| 593 | } |
| 594 | |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 595 | void ath9k_tasklet(unsigned long data) |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 596 | { |
| 597 | struct ath_softc *sc = (struct ath_softc *)data; |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 598 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 599 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 600 | |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 601 | u32 status = sc->intrstatus; |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 602 | u32 rxmask; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 603 | |
Vasanthakumar Thiagarajan | 153e080 | 2009-05-15 02:47:16 -0400 | [diff] [blame] | 604 | ath9k_ps_wakeup(sc); |
| 605 | |
Felix Fietkau | 347809f | 2010-07-02 00:09:52 +0200 | [diff] [blame] | 606 | if (status & ATH9K_INT_FATAL) { |
Felix Fietkau | fac6b6a | 2010-10-23 17:45:38 +0200 | [diff] [blame] | 607 | ath_reset(sc, true); |
Vasanthakumar Thiagarajan | 153e080 | 2009-05-15 02:47:16 -0400 | [diff] [blame] | 608 | ath9k_ps_restore(sc); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 609 | return; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 610 | } |
| 611 | |
Felix Fietkau | 347809f | 2010-07-02 00:09:52 +0200 | [diff] [blame] | 612 | if (!ath9k_hw_check_alive(ah)) |
| 613 | ieee80211_queue_work(sc->hw, &sc->hw_check_work); |
| 614 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 615 | if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) |
| 616 | rxmask = (ATH9K_INT_RXHP | ATH9K_INT_RXLP | ATH9K_INT_RXEOL | |
| 617 | ATH9K_INT_RXORN); |
| 618 | else |
| 619 | rxmask = (ATH9K_INT_RX | ATH9K_INT_RXEOL | ATH9K_INT_RXORN); |
| 620 | |
| 621 | if (status & rxmask) { |
Luis R. Rodriguez | b79b33c | 2010-10-20 16:07:05 -0700 | [diff] [blame] | 622 | spin_lock_bh(&sc->rx.pcu_lock); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 623 | |
| 624 | /* Check for high priority Rx first */ |
| 625 | if ((ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) && |
| 626 | (status & ATH9K_INT_RXHP)) |
| 627 | ath_rx_tasklet(sc, 0, true); |
| 628 | |
| 629 | ath_rx_tasklet(sc, 0, false); |
Luis R. Rodriguez | b79b33c | 2010-10-20 16:07:05 -0700 | [diff] [blame] | 630 | spin_unlock_bh(&sc->rx.pcu_lock); |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 631 | } |
| 632 | |
Vasanthakumar Thiagarajan | e500324 | 2010-04-15 17:39:36 -0400 | [diff] [blame] | 633 | if (status & ATH9K_INT_TX) { |
| 634 | if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) |
| 635 | ath_tx_edma_tasklet(sc); |
| 636 | else |
| 637 | ath_tx_tasklet(sc); |
| 638 | } |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 639 | |
Gabor Juhos | 9614832 | 2009-07-24 17:27:21 +0200 | [diff] [blame] | 640 | if ((status & ATH9K_INT_TSFOOR) && sc->ps_enabled) { |
Jouni Malinen | 54ce846 | 2009-05-19 17:01:40 +0300 | [diff] [blame] | 641 | /* |
| 642 | * TSF sync does not look correct; remain awake to sync with |
| 643 | * the next Beacon. |
| 644 | */ |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 645 | ath_print(common, ATH_DBG_PS, |
| 646 | "TSFOOR - Sync with next Beacon\n"); |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 647 | sc->ps_flags |= PS_WAIT_FOR_BEACON | PS_BEACON_SYNC; |
Jouni Malinen | 54ce846 | 2009-05-19 17:01:40 +0300 | [diff] [blame] | 648 | } |
| 649 | |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 650 | if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE) |
Vasanthakumar Thiagarajan | ebb8e1d | 2009-09-01 17:46:32 +0530 | [diff] [blame] | 651 | if (status & ATH9K_INT_GENTIMER) |
| 652 | ath_gen_timer_isr(sc->sc_ah); |
| 653 | |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 654 | /* re-enable hardware interrupt */ |
Felix Fietkau | 4df3071 | 2010-11-08 20:54:47 +0100 | [diff] [blame] | 655 | ath9k_hw_enable_interrupts(ah); |
Vasanthakumar Thiagarajan | 153e080 | 2009-05-15 02:47:16 -0400 | [diff] [blame] | 656 | ath9k_ps_restore(sc); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 657 | } |
| 658 | |
Gabor Juhos | 6baff7f | 2009-01-14 20:17:06 +0100 | [diff] [blame] | 659 | irqreturn_t ath_isr(int irq, void *dev) |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 660 | { |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 661 | #define SCHED_INTR ( \ |
| 662 | ATH9K_INT_FATAL | \ |
| 663 | ATH9K_INT_RXORN | \ |
| 664 | ATH9K_INT_RXEOL | \ |
| 665 | ATH9K_INT_RX | \ |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 666 | ATH9K_INT_RXLP | \ |
| 667 | ATH9K_INT_RXHP | \ |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 668 | ATH9K_INT_TX | \ |
| 669 | ATH9K_INT_BMISS | \ |
| 670 | ATH9K_INT_CST | \ |
Vasanthakumar Thiagarajan | ebb8e1d | 2009-09-01 17:46:32 +0530 | [diff] [blame] | 671 | ATH9K_INT_TSFOOR | \ |
| 672 | ATH9K_INT_GENTIMER) |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 673 | |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 674 | struct ath_softc *sc = dev; |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 675 | struct ath_hw *ah = sc->sc_ah; |
Felix Fietkau | b5bfc56 | 2010-10-08 22:13:53 +0200 | [diff] [blame] | 676 | struct ath_common *common = ath9k_hw_common(ah); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 677 | enum ath9k_int status; |
| 678 | bool sched = false; |
| 679 | |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 680 | /* |
| 681 | * The hardware is not ready/present, don't |
| 682 | * touch anything. Note this can happen early |
| 683 | * on if the IRQ is shared. |
| 684 | */ |
| 685 | if (sc->sc_flags & SC_OP_INVALID) |
| 686 | return IRQ_NONE; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 687 | |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 688 | |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 689 | /* shared irq, not for us */ |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 690 | |
Vasanthakumar Thiagarajan | 153e080 | 2009-05-15 02:47:16 -0400 | [diff] [blame] | 691 | if (!ath9k_hw_intrpend(ah)) |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 692 | return IRQ_NONE; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 693 | |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 694 | /* |
| 695 | * Figure out the reason(s) for the interrupt. Note |
| 696 | * that the hal returns a pseudo-ISR that may include |
| 697 | * bits we haven't explicitly enabled so we mask the |
| 698 | * value to insure we only process bits we requested. |
| 699 | */ |
| 700 | ath9k_hw_getisr(ah, &status); /* NB: clears ISR too */ |
Pavel Roskin | 3069168 | 2010-03-31 18:05:31 -0400 | [diff] [blame] | 701 | status &= ah->imask; /* discard unasked-for bits */ |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 702 | |
| 703 | /* |
| 704 | * If there are no status bits set, then this interrupt was not |
| 705 | * for me (should have been caught above). |
| 706 | */ |
Vasanthakumar Thiagarajan | 153e080 | 2009-05-15 02:47:16 -0400 | [diff] [blame] | 707 | if (!status) |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 708 | return IRQ_NONE; |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 709 | |
| 710 | /* Cache the status */ |
| 711 | sc->intrstatus = status; |
| 712 | |
| 713 | if (status & SCHED_INTR) |
| 714 | sched = true; |
| 715 | |
| 716 | /* |
| 717 | * If a FATAL or RXORN interrupt is received, we have to reset the |
| 718 | * chip immediately. |
| 719 | */ |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 720 | if ((status & ATH9K_INT_FATAL) || ((status & ATH9K_INT_RXORN) && |
| 721 | !(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA))) |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 722 | goto chip_reset; |
| 723 | |
Luis R. Rodriguez | 08578b8 | 2010-05-13 13:33:44 -0400 | [diff] [blame] | 724 | if ((ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) && |
| 725 | (status & ATH9K_INT_BB_WATCHDOG)) { |
Felix Fietkau | b5bfc56 | 2010-10-08 22:13:53 +0200 | [diff] [blame] | 726 | |
| 727 | spin_lock(&common->cc_lock); |
| 728 | ath_hw_cycle_counters_update(common); |
Luis R. Rodriguez | 08578b8 | 2010-05-13 13:33:44 -0400 | [diff] [blame] | 729 | ar9003_hw_bb_watchdog_dbg_info(ah); |
Felix Fietkau | b5bfc56 | 2010-10-08 22:13:53 +0200 | [diff] [blame] | 730 | spin_unlock(&common->cc_lock); |
| 731 | |
Luis R. Rodriguez | 08578b8 | 2010-05-13 13:33:44 -0400 | [diff] [blame] | 732 | goto chip_reset; |
| 733 | } |
| 734 | |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 735 | if (status & ATH9K_INT_SWBA) |
| 736 | tasklet_schedule(&sc->bcon_tasklet); |
| 737 | |
| 738 | if (status & ATH9K_INT_TXURN) |
| 739 | ath9k_hw_updatetxtriglevel(ah, true); |
| 740 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 741 | if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) { |
| 742 | if (status & ATH9K_INT_RXEOL) { |
| 743 | ah->imask &= ~(ATH9K_INT_RXEOL | ATH9K_INT_RXORN); |
| 744 | ath9k_hw_set_interrupts(ah, ah->imask); |
| 745 | } |
| 746 | } |
| 747 | |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 748 | if (status & ATH9K_INT_MIB) { |
| 749 | /* |
| 750 | * Disable interrupts until we service the MIB |
| 751 | * interrupt; otherwise it will continue to |
| 752 | * fire. |
| 753 | */ |
Felix Fietkau | 4df3071 | 2010-11-08 20:54:47 +0100 | [diff] [blame] | 754 | ath9k_hw_disable_interrupts(ah); |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 755 | /* |
| 756 | * Let the hal handle the event. We assume |
| 757 | * it will clear whatever condition caused |
| 758 | * the interrupt. |
| 759 | */ |
Felix Fietkau | 88eac2d | 2010-10-12 16:08:03 +0200 | [diff] [blame] | 760 | spin_lock(&common->cc_lock); |
Felix Fietkau | bfc472b | 2010-10-04 20:09:48 +0200 | [diff] [blame] | 761 | ath9k_hw_proc_mib_event(ah); |
Felix Fietkau | 88eac2d | 2010-10-12 16:08:03 +0200 | [diff] [blame] | 762 | spin_unlock(&common->cc_lock); |
Felix Fietkau | 4df3071 | 2010-11-08 20:54:47 +0100 | [diff] [blame] | 763 | ath9k_hw_enable_interrupts(ah); |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 764 | } |
| 765 | |
Vasanthakumar Thiagarajan | 153e080 | 2009-05-15 02:47:16 -0400 | [diff] [blame] | 766 | if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) |
| 767 | if (status & ATH9K_INT_TIM_TIMER) { |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 768 | /* Clear RxAbort bit so that we can |
| 769 | * receive frames */ |
Luis R. Rodriguez | 9ecdef4 | 2009-09-09 21:10:09 -0700 | [diff] [blame] | 770 | ath9k_setpower(sc, ATH9K_PM_AWAKE); |
Vasanthakumar Thiagarajan | 153e080 | 2009-05-15 02:47:16 -0400 | [diff] [blame] | 771 | ath9k_hw_setrxabort(sc->sc_ah, 0); |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 772 | sc->ps_flags |= PS_WAIT_FOR_BEACON; |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 773 | } |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 774 | |
| 775 | chip_reset: |
| 776 | |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 777 | ath_debug_stat_interrupt(sc, status); |
| 778 | |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 779 | if (sched) { |
Felix Fietkau | 4df3071 | 2010-11-08 20:54:47 +0100 | [diff] [blame] | 780 | /* turn off every interrupt */ |
| 781 | ath9k_hw_disable_interrupts(ah); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 782 | tasklet_schedule(&sc->intr_tq); |
| 783 | } |
| 784 | |
| 785 | return IRQ_HANDLED; |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 786 | |
| 787 | #undef SCHED_INTR |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 788 | } |
| 789 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 790 | static u32 ath_get_extchanmode(struct ath_softc *sc, |
Sujith | 99405f9 | 2008-11-24 12:08:35 +0530 | [diff] [blame] | 791 | struct ieee80211_channel *chan, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 792 | enum nl80211_channel_type channel_type) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 793 | { |
| 794 | u32 chanmode = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 795 | |
| 796 | switch (chan->band) { |
| 797 | case IEEE80211_BAND_2GHZ: |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 798 | switch(channel_type) { |
| 799 | case NL80211_CHAN_NO_HT: |
| 800 | case NL80211_CHAN_HT20: |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 801 | chanmode = CHANNEL_G_HT20; |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 802 | break; |
| 803 | case NL80211_CHAN_HT40PLUS: |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 804 | chanmode = CHANNEL_G_HT40PLUS; |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 805 | break; |
| 806 | case NL80211_CHAN_HT40MINUS: |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 807 | chanmode = CHANNEL_G_HT40MINUS; |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 808 | break; |
| 809 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 810 | break; |
| 811 | case IEEE80211_BAND_5GHZ: |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 812 | switch(channel_type) { |
| 813 | case NL80211_CHAN_NO_HT: |
| 814 | case NL80211_CHAN_HT20: |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 815 | chanmode = CHANNEL_A_HT20; |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 816 | break; |
| 817 | case NL80211_CHAN_HT40PLUS: |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 818 | chanmode = CHANNEL_A_HT40PLUS; |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 819 | break; |
| 820 | case NL80211_CHAN_HT40MINUS: |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 821 | chanmode = CHANNEL_A_HT40MINUS; |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 822 | break; |
| 823 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 824 | break; |
| 825 | default: |
| 826 | break; |
| 827 | } |
| 828 | |
| 829 | return chanmode; |
| 830 | } |
| 831 | |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 832 | static void ath9k_bss_assoc_info(struct ath_softc *sc, |
Felix Fietkau | 9fa23e1 | 2010-10-15 20:03:31 +0200 | [diff] [blame] | 833 | struct ieee80211_hw *hw, |
Sujith | 5640b08 | 2008-10-29 10:16:06 +0530 | [diff] [blame] | 834 | struct ieee80211_vif *vif, |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 835 | struct ieee80211_bss_conf *bss_conf) |
| 836 | { |
Felix Fietkau | 9fa23e1 | 2010-10-15 20:03:31 +0200 | [diff] [blame] | 837 | struct ath_wiphy *aphy = hw->priv; |
Luis R. Rodriguez | f2b2143 | 2009-09-10 08:50:20 -0700 | [diff] [blame] | 838 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 839 | struct ath_common *common = ath9k_hw_common(ah); |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 840 | |
| 841 | if (bss_conf->assoc) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 842 | ath_print(common, ATH_DBG_CONFIG, |
| 843 | "Bss Info ASSOC %d, bssid: %pM\n", |
| 844 | bss_conf->aid, common->curbssid); |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 845 | |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 846 | /* New association, store aid */ |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 847 | common->curaid = bss_conf->aid; |
Luis R. Rodriguez | f2b2143 | 2009-09-10 08:50:20 -0700 | [diff] [blame] | 848 | ath9k_hw_write_associd(ah); |
Jouni Malinen | ccdfeab | 2009-05-20 21:59:08 +0300 | [diff] [blame] | 849 | |
Senthil Balasubramanian | 2664f20 | 2009-06-24 18:56:39 +0530 | [diff] [blame] | 850 | /* |
| 851 | * Request a re-configuration of Beacon related timers |
| 852 | * on the receipt of the first Beacon frame (i.e., |
| 853 | * after time sync with the AP). |
| 854 | */ |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 855 | sc->ps_flags |= PS_BEACON_SYNC; |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 856 | |
| 857 | /* Configure the beacon */ |
Jouni Malinen | 2c3db3d | 2009-03-03 19:23:26 +0200 | [diff] [blame] | 858 | ath_beacon_config(sc, vif); |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 859 | |
| 860 | /* Reset rssi stats */ |
Felix Fietkau | 9fa23e1 | 2010-10-15 20:03:31 +0200 | [diff] [blame] | 861 | aphy->last_rssi = ATH_RSSI_DUMMY_MARKER; |
Vasanthakumar Thiagarajan | 22e66a4 | 2009-08-19 16:23:40 +0530 | [diff] [blame] | 862 | sc->sc_ah->stats.avgbrssi = ATH_RSSI_DUMMY_MARKER; |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 863 | |
Vasanthakumar Thiagarajan | 6c3118e | 2010-06-23 06:49:21 -0700 | [diff] [blame] | 864 | sc->sc_flags |= SC_OP_ANI_RUN; |
Luis R. Rodriguez | 3d536ac | 2009-11-03 17:07:04 -0800 | [diff] [blame] | 865 | ath_start_ani(common); |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 866 | } else { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 867 | ath_print(common, ATH_DBG_CONFIG, "Bss Info DISASSOC\n"); |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 868 | common->curaid = 0; |
Senthil Balasubramanian | f38faa3 | 2009-06-24 18:56:40 +0530 | [diff] [blame] | 869 | /* Stop ANI */ |
Vasanthakumar Thiagarajan | 6c3118e | 2010-06-23 06:49:21 -0700 | [diff] [blame] | 870 | sc->sc_flags &= ~SC_OP_ANI_RUN; |
Luis R. Rodriguez | 3d536ac | 2009-11-03 17:07:04 -0800 | [diff] [blame] | 871 | del_timer_sync(&common->ani.timer); |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 872 | } |
| 873 | } |
| 874 | |
Luis R. Rodriguez | 68a8911 | 2009-11-02 14:35:42 -0800 | [diff] [blame] | 875 | void ath_radio_enable(struct ath_softc *sc, struct ieee80211_hw *hw) |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 876 | { |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 877 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 878 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | 68a8911 | 2009-11-02 14:35:42 -0800 | [diff] [blame] | 879 | struct ieee80211_channel *channel = hw->conf.channel; |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 880 | int r; |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 881 | |
Vivek Natarajan | 3cbb5dd | 2009-01-20 11:17:08 +0530 | [diff] [blame] | 882 | ath9k_ps_wakeup(sc); |
Vivek Natarajan | 93b1b37 | 2009-09-17 09:24:58 +0530 | [diff] [blame] | 883 | ath9k_hw_configpcipowersave(ah, 0, 0); |
Sujith | d2f5b3a | 2009-04-13 21:56:25 +0530 | [diff] [blame] | 884 | |
Vasanthakumar Thiagarajan | 159cd46 | 2009-06-13 14:50:25 +0530 | [diff] [blame] | 885 | if (!ah->curchan) |
| 886 | ah->curchan = ath_get_curchannel(sc, sc->hw); |
| 887 | |
Luis R. Rodriguez | 5e848f7 | 2010-10-20 16:07:06 -0700 | [diff] [blame] | 888 | spin_lock_bh(&sc->rx.pcu_lock); |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 889 | spin_lock_bh(&sc->sc_resetlock); |
Felix Fietkau | 20bd2a0 | 2010-07-31 00:12:00 +0200 | [diff] [blame] | 890 | r = ath9k_hw_reset(ah, ah->curchan, ah->caldata, false); |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 891 | if (r) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 892 | ath_print(common, ATH_DBG_FATAL, |
Pavel Roskin | f643e51 | 2010-01-29 17:22:12 -0500 | [diff] [blame] | 893 | "Unable to reset channel (%u MHz), " |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 894 | "reset status %d\n", |
| 895 | channel->center_freq, r); |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 896 | } |
| 897 | spin_unlock_bh(&sc->sc_resetlock); |
| 898 | |
| 899 | ath_update_txpow(sc); |
| 900 | if (ath_startrecv(sc) != 0) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 901 | ath_print(common, ATH_DBG_FATAL, |
| 902 | "Unable to restart recv logic\n"); |
Luis R. Rodriguez | 5e848f7 | 2010-10-20 16:07:06 -0700 | [diff] [blame] | 903 | spin_unlock_bh(&sc->rx.pcu_lock); |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 904 | return; |
| 905 | } |
Luis R. Rodriguez | 5e848f7 | 2010-10-20 16:07:06 -0700 | [diff] [blame] | 906 | spin_unlock_bh(&sc->rx.pcu_lock); |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 907 | |
| 908 | if (sc->sc_flags & SC_OP_BEACONS) |
Jouni Malinen | 2c3db3d | 2009-03-03 19:23:26 +0200 | [diff] [blame] | 909 | ath_beacon_config(sc, NULL); /* restart beacons */ |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 910 | |
| 911 | /* Re-Enable interrupts */ |
Pavel Roskin | 3069168 | 2010-03-31 18:05:31 -0400 | [diff] [blame] | 912 | ath9k_hw_set_interrupts(ah, ah->imask); |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 913 | |
| 914 | /* Enable LED */ |
Vivek Natarajan | 08fc5c1 | 2009-08-14 11:30:52 +0530 | [diff] [blame] | 915 | ath9k_hw_cfg_output(ah, ah->led_pin, |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 916 | AR_GPIO_OUTPUT_MUX_AS_OUTPUT); |
Vivek Natarajan | 08fc5c1 | 2009-08-14 11:30:52 +0530 | [diff] [blame] | 917 | ath9k_hw_set_gpio(ah, ah->led_pin, 0); |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 918 | |
Luis R. Rodriguez | 68a8911 | 2009-11-02 14:35:42 -0800 | [diff] [blame] | 919 | ieee80211_wake_queues(hw); |
Vivek Natarajan | 3cbb5dd | 2009-01-20 11:17:08 +0530 | [diff] [blame] | 920 | ath9k_ps_restore(sc); |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 921 | } |
| 922 | |
Luis R. Rodriguez | 68a8911 | 2009-11-02 14:35:42 -0800 | [diff] [blame] | 923 | void ath_radio_disable(struct ath_softc *sc, struct ieee80211_hw *hw) |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 924 | { |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 925 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | 68a8911 | 2009-11-02 14:35:42 -0800 | [diff] [blame] | 926 | struct ieee80211_channel *channel = hw->conf.channel; |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 927 | int r; |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 928 | |
Vivek Natarajan | 3cbb5dd | 2009-01-20 11:17:08 +0530 | [diff] [blame] | 929 | ath9k_ps_wakeup(sc); |
Luis R. Rodriguez | 68a8911 | 2009-11-02 14:35:42 -0800 | [diff] [blame] | 930 | ieee80211_stop_queues(hw); |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 931 | |
Vivek Natarajan | 982723d | 2010-06-23 12:08:29 +0530 | [diff] [blame] | 932 | /* |
| 933 | * Keep the LED on when the radio is disabled |
| 934 | * during idle unassociated state. |
| 935 | */ |
| 936 | if (!sc->ps_idle) { |
| 937 | ath9k_hw_set_gpio(ah, ah->led_pin, 1); |
| 938 | ath9k_hw_cfg_gpio_input(ah, ah->led_pin); |
| 939 | } |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 940 | |
| 941 | /* Disable interrupts */ |
Felix Fietkau | 4df3071 | 2010-11-08 20:54:47 +0100 | [diff] [blame] | 942 | ath9k_hw_disable_interrupts(ah); |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 943 | |
Sujith | 043a040 | 2009-01-16 21:38:47 +0530 | [diff] [blame] | 944 | ath_drain_all_txq(sc, false); /* clear pending tx frames */ |
Luis R. Rodriguez | 5e848f7 | 2010-10-20 16:07:06 -0700 | [diff] [blame] | 945 | |
| 946 | spin_lock_bh(&sc->rx.pcu_lock); |
| 947 | |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 948 | ath_stoprecv(sc); /* turn off frame recv */ |
| 949 | ath_flushrecv(sc); /* flush recv queue */ |
| 950 | |
Vasanthakumar Thiagarajan | 159cd46 | 2009-06-13 14:50:25 +0530 | [diff] [blame] | 951 | if (!ah->curchan) |
Luis R. Rodriguez | 68a8911 | 2009-11-02 14:35:42 -0800 | [diff] [blame] | 952 | ah->curchan = ath_get_curchannel(sc, hw); |
Vasanthakumar Thiagarajan | 159cd46 | 2009-06-13 14:50:25 +0530 | [diff] [blame] | 953 | |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 954 | spin_lock_bh(&sc->sc_resetlock); |
Felix Fietkau | 20bd2a0 | 2010-07-31 00:12:00 +0200 | [diff] [blame] | 955 | r = ath9k_hw_reset(ah, ah->curchan, ah->caldata, false); |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 956 | if (r) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 957 | ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_FATAL, |
Pavel Roskin | f643e51 | 2010-01-29 17:22:12 -0500 | [diff] [blame] | 958 | "Unable to reset channel (%u MHz), " |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 959 | "reset status %d\n", |
| 960 | channel->center_freq, r); |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 961 | } |
| 962 | spin_unlock_bh(&sc->sc_resetlock); |
| 963 | |
| 964 | ath9k_hw_phy_disable(ah); |
Luis R. Rodriguez | 5e848f7 | 2010-10-20 16:07:06 -0700 | [diff] [blame] | 965 | |
| 966 | spin_unlock_bh(&sc->rx.pcu_lock); |
| 967 | |
Vivek Natarajan | 93b1b37 | 2009-09-17 09:24:58 +0530 | [diff] [blame] | 968 | ath9k_hw_configpcipowersave(ah, 1, 1); |
Vivek Natarajan | 3cbb5dd | 2009-01-20 11:17:08 +0530 | [diff] [blame] | 969 | ath9k_ps_restore(sc); |
Luis R. Rodriguez | 9ecdef4 | 2009-09-09 21:10:09 -0700 | [diff] [blame] | 970 | ath9k_setpower(sc, ATH9K_PM_FULL_SLEEP); |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 971 | } |
| 972 | |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 973 | int ath_reset(struct ath_softc *sc, bool retry_tx) |
| 974 | { |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 975 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 976 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | 030bb49 | 2008-12-23 15:58:37 -0800 | [diff] [blame] | 977 | struct ieee80211_hw *hw = sc->hw; |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 978 | int r; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 979 | |
Sujith | 2ab81d4 | 2009-12-14 16:34:56 +0530 | [diff] [blame] | 980 | /* Stop ANI */ |
| 981 | del_timer_sync(&common->ani.timer); |
| 982 | |
Sujith | cc9c378 | 2010-01-08 10:36:09 +0530 | [diff] [blame] | 983 | ieee80211_stop_queues(hw); |
| 984 | |
Felix Fietkau | 4df3071 | 2010-11-08 20:54:47 +0100 | [diff] [blame] | 985 | ath9k_hw_disable_interrupts(ah); |
Sujith | 043a040 | 2009-01-16 21:38:47 +0530 | [diff] [blame] | 986 | ath_drain_all_txq(sc, retry_tx); |
Luis R. Rodriguez | 5e848f7 | 2010-10-20 16:07:06 -0700 | [diff] [blame] | 987 | |
| 988 | spin_lock_bh(&sc->rx.pcu_lock); |
| 989 | |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 990 | ath_stoprecv(sc); |
| 991 | ath_flushrecv(sc); |
| 992 | |
| 993 | spin_lock_bh(&sc->sc_resetlock); |
Felix Fietkau | 20bd2a0 | 2010-07-31 00:12:00 +0200 | [diff] [blame] | 994 | r = ath9k_hw_reset(ah, sc->sc_ah->curchan, ah->caldata, false); |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 995 | if (r) |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 996 | ath_print(common, ATH_DBG_FATAL, |
| 997 | "Unable to reset hardware; reset status %d\n", r); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 998 | spin_unlock_bh(&sc->sc_resetlock); |
| 999 | |
| 1000 | if (ath_startrecv(sc) != 0) |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1001 | ath_print(common, ATH_DBG_FATAL, |
| 1002 | "Unable to start recv logic\n"); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1003 | |
Luis R. Rodriguez | 5e848f7 | 2010-10-20 16:07:06 -0700 | [diff] [blame] | 1004 | spin_unlock_bh(&sc->rx.pcu_lock); |
| 1005 | |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1006 | /* |
| 1007 | * We may be doing a reset in response to a request |
| 1008 | * that changes the channel so update any state that |
| 1009 | * might change as a result. |
| 1010 | */ |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1011 | ath_update_txpow(sc); |
| 1012 | |
Luis R. Rodriguez | 52b8ac9 | 2010-09-16 15:12:27 -0400 | [diff] [blame] | 1013 | if ((sc->sc_flags & SC_OP_BEACONS) || !(sc->sc_flags & (SC_OP_OFFCHANNEL))) |
Jouni Malinen | 2c3db3d | 2009-03-03 19:23:26 +0200 | [diff] [blame] | 1014 | ath_beacon_config(sc, NULL); /* restart beacons */ |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1015 | |
Pavel Roskin | 3069168 | 2010-03-31 18:05:31 -0400 | [diff] [blame] | 1016 | ath9k_hw_set_interrupts(ah, ah->imask); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1017 | |
| 1018 | if (retry_tx) { |
| 1019 | int i; |
| 1020 | for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) { |
| 1021 | if (ATH_TXQ_SETUP(sc, i)) { |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 1022 | spin_lock_bh(&sc->tx.txq[i].axq_lock); |
| 1023 | ath_txq_schedule(sc, &sc->tx.txq[i]); |
| 1024 | spin_unlock_bh(&sc->tx.txq[i].axq_lock); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1025 | } |
| 1026 | } |
| 1027 | } |
| 1028 | |
Sujith | cc9c378 | 2010-01-08 10:36:09 +0530 | [diff] [blame] | 1029 | ieee80211_wake_queues(hw); |
| 1030 | |
Sujith | 2ab81d4 | 2009-12-14 16:34:56 +0530 | [diff] [blame] | 1031 | /* Start ANI */ |
| 1032 | ath_start_ani(common); |
| 1033 | |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 1034 | return r; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1035 | } |
| 1036 | |
Felix Fietkau | ebe297c | 2010-06-12 00:33:53 -0400 | [diff] [blame] | 1037 | static int ath_get_hal_qnum(u16 queue, struct ath_softc *sc) |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1038 | { |
| 1039 | int qnum; |
| 1040 | |
| 1041 | switch (queue) { |
| 1042 | case 0: |
Felix Fietkau | 1d2231e | 2010-06-12 00:33:51 -0400 | [diff] [blame] | 1043 | qnum = sc->tx.hwq_map[WME_AC_VO]; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1044 | break; |
| 1045 | case 1: |
Felix Fietkau | 1d2231e | 2010-06-12 00:33:51 -0400 | [diff] [blame] | 1046 | qnum = sc->tx.hwq_map[WME_AC_VI]; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1047 | break; |
| 1048 | case 2: |
Felix Fietkau | 1d2231e | 2010-06-12 00:33:51 -0400 | [diff] [blame] | 1049 | qnum = sc->tx.hwq_map[WME_AC_BE]; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1050 | break; |
| 1051 | case 3: |
Felix Fietkau | 1d2231e | 2010-06-12 00:33:51 -0400 | [diff] [blame] | 1052 | qnum = sc->tx.hwq_map[WME_AC_BK]; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1053 | break; |
| 1054 | default: |
Felix Fietkau | 1d2231e | 2010-06-12 00:33:51 -0400 | [diff] [blame] | 1055 | qnum = sc->tx.hwq_map[WME_AC_BE]; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1056 | break; |
| 1057 | } |
| 1058 | |
| 1059 | return qnum; |
| 1060 | } |
| 1061 | |
| 1062 | int ath_get_mac80211_qnum(u32 queue, struct ath_softc *sc) |
| 1063 | { |
| 1064 | int qnum; |
| 1065 | |
| 1066 | switch (queue) { |
Felix Fietkau | 1d2231e | 2010-06-12 00:33:51 -0400 | [diff] [blame] | 1067 | case WME_AC_VO: |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1068 | qnum = 0; |
| 1069 | break; |
Felix Fietkau | 1d2231e | 2010-06-12 00:33:51 -0400 | [diff] [blame] | 1070 | case WME_AC_VI: |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1071 | qnum = 1; |
| 1072 | break; |
Felix Fietkau | 1d2231e | 2010-06-12 00:33:51 -0400 | [diff] [blame] | 1073 | case WME_AC_BE: |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1074 | qnum = 2; |
| 1075 | break; |
Felix Fietkau | 1d2231e | 2010-06-12 00:33:51 -0400 | [diff] [blame] | 1076 | case WME_AC_BK: |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1077 | qnum = 3; |
| 1078 | break; |
| 1079 | default: |
| 1080 | qnum = -1; |
| 1081 | break; |
| 1082 | } |
| 1083 | |
| 1084 | return qnum; |
| 1085 | } |
| 1086 | |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 1087 | /* XXX: Remove me once we don't depend on ath9k_channel for all |
| 1088 | * this redundant data */ |
Jouni Malinen | 0e2dedf | 2009-03-03 19:23:32 +0200 | [diff] [blame] | 1089 | void ath9k_update_ichannel(struct ath_softc *sc, struct ieee80211_hw *hw, |
| 1090 | struct ath9k_channel *ichan) |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 1091 | { |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 1092 | struct ieee80211_channel *chan = hw->conf.channel; |
| 1093 | struct ieee80211_conf *conf = &hw->conf; |
| 1094 | |
| 1095 | ichan->channel = chan->center_freq; |
| 1096 | ichan->chan = chan; |
| 1097 | |
| 1098 | if (chan->band == IEEE80211_BAND_2GHZ) { |
| 1099 | ichan->chanmode = CHANNEL_G; |
Sujith | 8813262 | 2009-09-03 12:08:53 +0530 | [diff] [blame] | 1100 | ichan->channelFlags = CHANNEL_2GHZ | CHANNEL_OFDM | CHANNEL_G; |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 1101 | } else { |
| 1102 | ichan->chanmode = CHANNEL_A; |
| 1103 | ichan->channelFlags = CHANNEL_5GHZ | CHANNEL_OFDM; |
| 1104 | } |
| 1105 | |
Luis R. Rodriguez | 25c56ee | 2009-09-13 23:04:44 -0700 | [diff] [blame] | 1106 | if (conf_is_ht(conf)) |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 1107 | ichan->chanmode = ath_get_extchanmode(sc, chan, |
| 1108 | conf->channel_type); |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 1109 | } |
| 1110 | |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1111 | /**********************/ |
| 1112 | /* mac80211 callbacks */ |
| 1113 | /**********************/ |
| 1114 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1115 | static int ath9k_start(struct ieee80211_hw *hw) |
| 1116 | { |
Jouni Malinen | bce048d | 2009-03-03 19:23:28 +0200 | [diff] [blame] | 1117 | struct ath_wiphy *aphy = hw->priv; |
| 1118 | struct ath_softc *sc = aphy->sc; |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 1119 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1120 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1121 | struct ieee80211_channel *curchan = hw->conf.channel; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1122 | struct ath9k_channel *init_channel; |
Vasanthakumar Thiagarajan | 82880a7 | 2009-06-13 14:50:24 +0530 | [diff] [blame] | 1123 | int r; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1124 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1125 | ath_print(common, ATH_DBG_CONFIG, |
| 1126 | "Starting driver with initial channel: %d MHz\n", |
| 1127 | curchan->center_freq); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1128 | |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 1129 | mutex_lock(&sc->mutex); |
| 1130 | |
Jouni Malinen | 9580a22 | 2009-03-03 19:23:33 +0200 | [diff] [blame] | 1131 | if (ath9k_wiphy_started(sc)) { |
| 1132 | if (sc->chan_idx == curchan->hw_value) { |
| 1133 | /* |
| 1134 | * Already on the operational channel, the new wiphy |
| 1135 | * can be marked active. |
| 1136 | */ |
| 1137 | aphy->state = ATH_WIPHY_ACTIVE; |
| 1138 | ieee80211_wake_queues(hw); |
| 1139 | } else { |
| 1140 | /* |
| 1141 | * Another wiphy is on another channel, start the new |
| 1142 | * wiphy in paused state. |
| 1143 | */ |
| 1144 | aphy->state = ATH_WIPHY_PAUSED; |
| 1145 | ieee80211_stop_queues(hw); |
| 1146 | } |
| 1147 | mutex_unlock(&sc->mutex); |
| 1148 | return 0; |
| 1149 | } |
| 1150 | aphy->state = ATH_WIPHY_ACTIVE; |
| 1151 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1152 | /* setup initial channel */ |
| 1153 | |
Vasanthakumar Thiagarajan | 82880a7 | 2009-06-13 14:50:24 +0530 | [diff] [blame] | 1154 | sc->chan_idx = curchan->hw_value; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1155 | |
Vasanthakumar Thiagarajan | 82880a7 | 2009-06-13 14:50:24 +0530 | [diff] [blame] | 1156 | init_channel = ath_get_curchannel(sc, hw); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1157 | |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1158 | /* Reset SERDES registers */ |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 1159 | ath9k_hw_configpcipowersave(ah, 0, 0); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1160 | |
| 1161 | /* |
| 1162 | * The basic interface to setting the hardware in a good |
| 1163 | * state is ``reset''. On return the hardware is known to |
| 1164 | * be powered up and with interrupts disabled. This must |
| 1165 | * be followed by initialization of the appropriate bits |
| 1166 | * and then setup of the interrupt mask. |
| 1167 | */ |
Luis R. Rodriguez | 5e848f7 | 2010-10-20 16:07:06 -0700 | [diff] [blame] | 1168 | spin_lock_bh(&sc->rx.pcu_lock); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1169 | spin_lock_bh(&sc->sc_resetlock); |
Felix Fietkau | 20bd2a0 | 2010-07-31 00:12:00 +0200 | [diff] [blame] | 1170 | r = ath9k_hw_reset(ah, init_channel, ah->caldata, false); |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 1171 | if (r) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1172 | ath_print(common, ATH_DBG_FATAL, |
| 1173 | "Unable to reset hardware; reset status %d " |
| 1174 | "(freq %u MHz)\n", r, |
| 1175 | curchan->center_freq); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1176 | spin_unlock_bh(&sc->sc_resetlock); |
Luis R. Rodriguez | 5e848f7 | 2010-10-20 16:07:06 -0700 | [diff] [blame] | 1177 | spin_unlock_bh(&sc->rx.pcu_lock); |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 1178 | goto mutex_unlock; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1179 | } |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1180 | spin_unlock_bh(&sc->sc_resetlock); |
| 1181 | |
| 1182 | /* |
| 1183 | * This is needed only to setup initial state |
| 1184 | * but it's best done after a reset. |
| 1185 | */ |
| 1186 | ath_update_txpow(sc); |
| 1187 | |
| 1188 | /* |
| 1189 | * Setup the hardware after reset: |
| 1190 | * The receive engine is set going. |
| 1191 | * Frame transmit is handled entirely |
| 1192 | * in the frame output path; there's nothing to do |
| 1193 | * here except setup the interrupt mask. |
| 1194 | */ |
| 1195 | if (ath_startrecv(sc) != 0) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1196 | ath_print(common, ATH_DBG_FATAL, |
| 1197 | "Unable to start recv logic\n"); |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 1198 | r = -EIO; |
Luis R. Rodriguez | 5e848f7 | 2010-10-20 16:07:06 -0700 | [diff] [blame] | 1199 | spin_unlock_bh(&sc->rx.pcu_lock); |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 1200 | goto mutex_unlock; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1201 | } |
Luis R. Rodriguez | 5e848f7 | 2010-10-20 16:07:06 -0700 | [diff] [blame] | 1202 | spin_unlock_bh(&sc->rx.pcu_lock); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1203 | |
| 1204 | /* Setup our intr mask. */ |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 1205 | ah->imask = ATH9K_INT_TX | ATH9K_INT_RXEOL | |
| 1206 | ATH9K_INT_RXORN | ATH9K_INT_FATAL | |
| 1207 | ATH9K_INT_GLOBAL; |
| 1208 | |
| 1209 | if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) |
Luis R. Rodriguez | 08578b8 | 2010-05-13 13:33:44 -0400 | [diff] [blame] | 1210 | ah->imask |= ATH9K_INT_RXHP | |
| 1211 | ATH9K_INT_RXLP | |
| 1212 | ATH9K_INT_BB_WATCHDOG; |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 1213 | else |
| 1214 | ah->imask |= ATH9K_INT_RX; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1215 | |
Felix Fietkau | 364734f | 2010-09-14 20:22:44 +0200 | [diff] [blame] | 1216 | ah->imask |= ATH9K_INT_GTT; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1217 | |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 1218 | if (ah->caps.hw_caps & ATH9K_HW_CAP_HT) |
Pavel Roskin | 3069168 | 2010-03-31 18:05:31 -0400 | [diff] [blame] | 1219 | ah->imask |= ATH9K_INT_CST; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1220 | |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1221 | sc->sc_flags &= ~SC_OP_INVALID; |
| 1222 | |
| 1223 | /* Disable BMISS interrupt when we're not associated */ |
Pavel Roskin | 3069168 | 2010-03-31 18:05:31 -0400 | [diff] [blame] | 1224 | ah->imask &= ~(ATH9K_INT_SWBA | ATH9K_INT_BMISS); |
| 1225 | ath9k_hw_set_interrupts(ah, ah->imask); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1226 | |
Jouni Malinen | bce048d | 2009-03-03 19:23:28 +0200 | [diff] [blame] | 1227 | ieee80211_wake_queues(hw); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1228 | |
Luis R. Rodriguez | 42935ec | 2009-07-29 20:08:07 -0400 | [diff] [blame] | 1229 | ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0); |
Senthil Balasubramanian | 164ace3 | 2009-07-14 20:17:09 -0400 | [diff] [blame] | 1230 | |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 1231 | if ((ah->btcoex_hw.scheme != ATH_BTCOEX_CFG_NONE) && |
| 1232 | !ah->btcoex_hw.enabled) { |
Luis R. Rodriguez | 5e19729 | 2009-09-09 15:15:55 -0700 | [diff] [blame] | 1233 | ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT, |
| 1234 | AR_STOMP_LOW_WLAN_WGHT); |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 1235 | ath9k_hw_btcoex_enable(ah); |
Vasanthakumar Thiagarajan | f985ad1 | 2009-08-26 21:08:43 +0530 | [diff] [blame] | 1236 | |
Luis R. Rodriguez | 5bb1279 | 2009-09-14 00:55:09 -0700 | [diff] [blame] | 1237 | if (common->bus_ops->bt_coex_prep) |
| 1238 | common->bus_ops->bt_coex_prep(common); |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 1239 | if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE) |
Luis R. Rodriguez | 75d7839 | 2009-09-09 04:00:10 -0700 | [diff] [blame] | 1240 | ath9k_btcoex_timer_resume(sc); |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 1241 | } |
| 1242 | |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 1243 | mutex_unlock: |
| 1244 | mutex_unlock(&sc->mutex); |
| 1245 | |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 1246 | return r; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1247 | } |
| 1248 | |
| 1249 | static int ath9k_tx(struct ieee80211_hw *hw, |
| 1250 | struct sk_buff *skb) |
| 1251 | { |
Jouni Malinen | 147583c | 2008-08-11 14:01:50 +0300 | [diff] [blame] | 1252 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
Jouni Malinen | bce048d | 2009-03-03 19:23:28 +0200 | [diff] [blame] | 1253 | struct ath_wiphy *aphy = hw->priv; |
| 1254 | struct ath_softc *sc = aphy->sc; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1255 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1256 | struct ath_tx_control txctl; |
Benoit Papillault | 1bc1488 | 2009-11-24 15:49:18 +0100 | [diff] [blame] | 1257 | int padpos, padsize; |
| 1258 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; |
Felix Fietkau | 84642d6 | 2010-06-01 21:33:13 +0200 | [diff] [blame] | 1259 | int qnum; |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1260 | |
Jouni Malinen | 8089cc4 | 2009-03-03 19:23:38 +0200 | [diff] [blame] | 1261 | if (aphy->state != ATH_WIPHY_ACTIVE && aphy->state != ATH_WIPHY_SCAN) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1262 | ath_print(common, ATH_DBG_XMIT, |
| 1263 | "ath9k: %s: TX in unexpected wiphy state " |
| 1264 | "%d\n", wiphy_name(hw->wiphy), aphy->state); |
Jouni Malinen | ee166a0 | 2009-03-03 19:23:36 +0200 | [diff] [blame] | 1265 | goto exit; |
| 1266 | } |
| 1267 | |
Gabor Juhos | 9614832 | 2009-07-24 17:27:21 +0200 | [diff] [blame] | 1268 | if (sc->ps_enabled) { |
Jouni Malinen | dc8c458 | 2009-05-19 17:01:42 +0300 | [diff] [blame] | 1269 | /* |
| 1270 | * mac80211 does not set PM field for normal data frames, so we |
| 1271 | * need to update that based on the current PS mode. |
| 1272 | */ |
| 1273 | if (ieee80211_is_data(hdr->frame_control) && |
| 1274 | !ieee80211_is_nullfunc(hdr->frame_control) && |
| 1275 | !ieee80211_has_pm(hdr->frame_control)) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1276 | ath_print(common, ATH_DBG_PS, "Add PM=1 for a TX frame " |
| 1277 | "while in PS mode\n"); |
Jouni Malinen | dc8c458 | 2009-05-19 17:01:42 +0300 | [diff] [blame] | 1278 | hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM); |
| 1279 | } |
| 1280 | } |
| 1281 | |
Jouni Malinen | 9a23f9c | 2009-05-19 17:01:38 +0300 | [diff] [blame] | 1282 | if (unlikely(sc->sc_ah->power_mode != ATH9K_PM_AWAKE)) { |
| 1283 | /* |
| 1284 | * We are using PS-Poll and mac80211 can request TX while in |
| 1285 | * power save mode. Need to wake up hardware for the TX to be |
| 1286 | * completed and if needed, also for RX of buffered frames. |
| 1287 | */ |
Jouni Malinen | 9a23f9c | 2009-05-19 17:01:38 +0300 | [diff] [blame] | 1288 | ath9k_ps_wakeup(sc); |
Vasanthakumar Thiagarajan | fdf7662 | 2010-05-17 18:57:55 -0700 | [diff] [blame] | 1289 | if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) |
| 1290 | ath9k_hw_setrxabort(sc->sc_ah, 0); |
Jouni Malinen | 9a23f9c | 2009-05-19 17:01:38 +0300 | [diff] [blame] | 1291 | if (ieee80211_is_pspoll(hdr->frame_control)) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1292 | ath_print(common, ATH_DBG_PS, |
| 1293 | "Sending PS-Poll to pick a buffered frame\n"); |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 1294 | sc->ps_flags |= PS_WAIT_FOR_PSPOLL_DATA; |
Jouni Malinen | 9a23f9c | 2009-05-19 17:01:38 +0300 | [diff] [blame] | 1295 | } else { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1296 | ath_print(common, ATH_DBG_PS, |
| 1297 | "Wake up to complete TX\n"); |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 1298 | sc->ps_flags |= PS_WAIT_FOR_TX_ACK; |
Jouni Malinen | 9a23f9c | 2009-05-19 17:01:38 +0300 | [diff] [blame] | 1299 | } |
| 1300 | /* |
| 1301 | * The actual restore operation will happen only after |
| 1302 | * the sc_flags bit is cleared. We are just dropping |
| 1303 | * the ps_usecount here. |
| 1304 | */ |
| 1305 | ath9k_ps_restore(sc); |
| 1306 | } |
| 1307 | |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1308 | memset(&txctl, 0, sizeof(struct ath_tx_control)); |
Jouni Malinen | 147583c | 2008-08-11 14:01:50 +0300 | [diff] [blame] | 1309 | |
| 1310 | /* |
| 1311 | * As a temporary workaround, assign seq# here; this will likely need |
| 1312 | * to be cleaned up to work better with Beacon transmission and virtual |
| 1313 | * BSSes. |
| 1314 | */ |
| 1315 | if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) { |
Jouni Malinen | 147583c | 2008-08-11 14:01:50 +0300 | [diff] [blame] | 1316 | if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT) |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 1317 | sc->tx.seq_no += 0x10; |
Jouni Malinen | 147583c | 2008-08-11 14:01:50 +0300 | [diff] [blame] | 1318 | hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG); |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 1319 | hdr->seq_ctrl |= cpu_to_le16(sc->tx.seq_no); |
Jouni Malinen | 147583c | 2008-08-11 14:01:50 +0300 | [diff] [blame] | 1320 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1321 | |
| 1322 | /* Add the padding after the header if this is not already done */ |
Benoit Papillault | 1bc1488 | 2009-11-24 15:49:18 +0100 | [diff] [blame] | 1323 | padpos = ath9k_cmn_padpos(hdr->frame_control); |
| 1324 | padsize = padpos & 3; |
| 1325 | if (padsize && skb->len>padpos) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1326 | if (skb_headroom(skb) < padsize) |
| 1327 | return -1; |
| 1328 | skb_push(skb, padsize); |
Benoit Papillault | 1bc1488 | 2009-11-24 15:49:18 +0100 | [diff] [blame] | 1329 | memmove(skb->data, skb->data + padsize, padpos); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1330 | } |
| 1331 | |
Felix Fietkau | 84642d6 | 2010-06-01 21:33:13 +0200 | [diff] [blame] | 1332 | qnum = ath_get_hal_qnum(skb_get_queue_mapping(skb), sc); |
| 1333 | txctl.txq = &sc->tx.txq[qnum]; |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1334 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1335 | 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] | 1336 | |
Jouni Malinen | c52f33d | 2009-03-03 19:23:29 +0200 | [diff] [blame] | 1337 | if (ath_tx_start(hw, skb, &txctl) != 0) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1338 | ath_print(common, ATH_DBG_XMIT, "TX failed\n"); |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1339 | goto exit; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1340 | } |
| 1341 | |
| 1342 | return 0; |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1343 | exit: |
| 1344 | dev_kfree_skb_any(skb); |
| 1345 | return 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1346 | } |
| 1347 | |
| 1348 | static void ath9k_stop(struct ieee80211_hw *hw) |
| 1349 | { |
Jouni Malinen | bce048d | 2009-03-03 19:23:28 +0200 | [diff] [blame] | 1350 | struct ath_wiphy *aphy = hw->priv; |
| 1351 | struct ath_softc *sc = aphy->sc; |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 1352 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1353 | struct ath_common *common = ath9k_hw_common(ah); |
Rajkumar Manoharan | 447a42c | 2010-07-08 12:12:29 +0530 | [diff] [blame] | 1354 | int i; |
Sujith | 9c84b79 | 2008-10-29 10:17:13 +0530 | [diff] [blame] | 1355 | |
Sujith | 4c48381 | 2009-08-18 10:51:52 +0530 | [diff] [blame] | 1356 | mutex_lock(&sc->mutex); |
| 1357 | |
Jouni Malinen | 9580a22 | 2009-03-03 19:23:33 +0200 | [diff] [blame] | 1358 | aphy->state = ATH_WIPHY_INACTIVE; |
| 1359 | |
Vivek Natarajan | 9a75c2f | 2010-06-22 11:52:37 +0530 | [diff] [blame] | 1360 | if (led_blink) |
| 1361 | cancel_delayed_work_sync(&sc->ath_led_blink_work); |
| 1362 | |
Luis R. Rodriguez | c94dbff | 2009-07-27 11:53:04 -0700 | [diff] [blame] | 1363 | cancel_delayed_work_sync(&sc->tx_complete_work); |
Felix Fietkau | 9f42c2b | 2010-06-12 00:34:01 -0400 | [diff] [blame] | 1364 | cancel_work_sync(&sc->paprd_work); |
Felix Fietkau | 347809f | 2010-07-02 00:09:52 +0200 | [diff] [blame] | 1365 | cancel_work_sync(&sc->hw_check_work); |
Luis R. Rodriguez | c94dbff | 2009-07-27 11:53:04 -0700 | [diff] [blame] | 1366 | |
Rajkumar Manoharan | 447a42c | 2010-07-08 12:12:29 +0530 | [diff] [blame] | 1367 | for (i = 0; i < sc->num_sec_wiphy; i++) { |
| 1368 | if (sc->sec_wiphy[i]) |
| 1369 | break; |
| 1370 | } |
| 1371 | |
| 1372 | if (i == sc->num_sec_wiphy) { |
Luis R. Rodriguez | c94dbff | 2009-07-27 11:53:04 -0700 | [diff] [blame] | 1373 | cancel_delayed_work_sync(&sc->wiphy_work); |
| 1374 | cancel_work_sync(&sc->chan_work); |
| 1375 | } |
| 1376 | |
Sujith | 9c84b79 | 2008-10-29 10:17:13 +0530 | [diff] [blame] | 1377 | if (sc->sc_flags & SC_OP_INVALID) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1378 | ath_print(common, ATH_DBG_ANY, "Device not present\n"); |
Sujith | 4c48381 | 2009-08-18 10:51:52 +0530 | [diff] [blame] | 1379 | mutex_unlock(&sc->mutex); |
Sujith | 9c84b79 | 2008-10-29 10:17:13 +0530 | [diff] [blame] | 1380 | return; |
| 1381 | } |
| 1382 | |
Jouni Malinen | 9580a22 | 2009-03-03 19:23:33 +0200 | [diff] [blame] | 1383 | if (ath9k_wiphy_started(sc)) { |
| 1384 | mutex_unlock(&sc->mutex); |
| 1385 | return; /* another wiphy still in use */ |
| 1386 | } |
| 1387 | |
Sujith | 3867cf6 | 2009-12-23 20:03:27 -0500 | [diff] [blame] | 1388 | /* Ensure HW is awake when we try to shut it down. */ |
| 1389 | ath9k_ps_wakeup(sc); |
| 1390 | |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 1391 | if (ah->btcoex_hw.enabled) { |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 1392 | ath9k_hw_btcoex_disable(ah); |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 1393 | if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE) |
Luis R. Rodriguez | 75d7839 | 2009-09-09 04:00:10 -0700 | [diff] [blame] | 1394 | ath9k_btcoex_timer_pause(sc); |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 1395 | } |
| 1396 | |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1397 | /* make sure h/w will not generate any interrupt |
| 1398 | * before setting the invalid flag. */ |
Felix Fietkau | 4df3071 | 2010-11-08 20:54:47 +0100 | [diff] [blame] | 1399 | ath9k_hw_disable_interrupts(ah); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1400 | |
Luis R. Rodriguez | 5e848f7 | 2010-10-20 16:07:06 -0700 | [diff] [blame] | 1401 | spin_lock_bh(&sc->rx.pcu_lock); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1402 | if (!(sc->sc_flags & SC_OP_INVALID)) { |
Sujith | 043a040 | 2009-01-16 21:38:47 +0530 | [diff] [blame] | 1403 | ath_drain_all_txq(sc, false); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1404 | ath_stoprecv(sc); |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 1405 | ath9k_hw_phy_disable(ah); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1406 | } else |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 1407 | sc->rx.rxlink = NULL; |
Luis R. Rodriguez | 5e848f7 | 2010-10-20 16:07:06 -0700 | [diff] [blame] | 1408 | spin_unlock_bh(&sc->rx.pcu_lock); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1409 | |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1410 | /* disable HAL and put h/w to sleep */ |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 1411 | ath9k_hw_disable(ah); |
| 1412 | ath9k_hw_configpcipowersave(ah, 1, 1); |
Sujith | 3867cf6 | 2009-12-23 20:03:27 -0500 | [diff] [blame] | 1413 | ath9k_ps_restore(sc); |
| 1414 | |
| 1415 | /* Finally, put the chip in FULL SLEEP mode */ |
Luis R. Rodriguez | 9ecdef4 | 2009-09-09 21:10:09 -0700 | [diff] [blame] | 1416 | ath9k_setpower(sc, ATH9K_PM_FULL_SLEEP); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 1417 | |
| 1418 | sc->sc_flags |= SC_OP_INVALID; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1419 | |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 1420 | mutex_unlock(&sc->mutex); |
| 1421 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1422 | ath_print(common, ATH_DBG_CONFIG, "Driver halt\n"); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1423 | } |
| 1424 | |
| 1425 | static int ath9k_add_interface(struct ieee80211_hw *hw, |
Johannes Berg | 1ed32e4 | 2009-12-23 13:15:45 +0100 | [diff] [blame] | 1426 | struct ieee80211_vif *vif) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1427 | { |
Jouni Malinen | bce048d | 2009-03-03 19:23:28 +0200 | [diff] [blame] | 1428 | struct ath_wiphy *aphy = hw->priv; |
| 1429 | struct ath_softc *sc = aphy->sc; |
Pavel Roskin | 3069168 | 2010-03-31 18:05:31 -0400 | [diff] [blame] | 1430 | struct ath_hw *ah = sc->sc_ah; |
| 1431 | struct ath_common *common = ath9k_hw_common(ah); |
Johannes Berg | 1ed32e4 | 2009-12-23 13:15:45 +0100 | [diff] [blame] | 1432 | struct ath_vif *avp = (void *)vif->drv_priv; |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 1433 | enum nl80211_iftype ic_opmode = NL80211_IFTYPE_UNSPECIFIED; |
Jouni Malinen | 2c3db3d | 2009-03-03 19:23:26 +0200 | [diff] [blame] | 1434 | int ret = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1435 | |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 1436 | mutex_lock(&sc->mutex); |
| 1437 | |
Johannes Berg | 1ed32e4 | 2009-12-23 13:15:45 +0100 | [diff] [blame] | 1438 | switch (vif->type) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1439 | case NL80211_IFTYPE_STATION: |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 1440 | ic_opmode = NL80211_IFTYPE_STATION; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1441 | break; |
Bill Jordan | e51f3ef | 2010-10-01 11:20:39 -0400 | [diff] [blame] | 1442 | case NL80211_IFTYPE_WDS: |
| 1443 | ic_opmode = NL80211_IFTYPE_WDS; |
| 1444 | break; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1445 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1446 | case NL80211_IFTYPE_AP: |
Pat Erley | 9cb5412 | 2009-03-20 22:59:59 -0400 | [diff] [blame] | 1447 | case NL80211_IFTYPE_MESH_POINT: |
Jouni Malinen | 2c3db3d | 2009-03-03 19:23:26 +0200 | [diff] [blame] | 1448 | if (sc->nbcnvifs >= ATH_BCBUF) { |
| 1449 | ret = -ENOBUFS; |
| 1450 | goto out; |
| 1451 | } |
Johannes Berg | 1ed32e4 | 2009-12-23 13:15:45 +0100 | [diff] [blame] | 1452 | ic_opmode = vif->type; |
Jouni Malinen | 2ad67de | 2008-08-11 14:01:47 +0300 | [diff] [blame] | 1453 | break; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1454 | default: |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1455 | ath_print(common, ATH_DBG_FATAL, |
Johannes Berg | 1ed32e4 | 2009-12-23 13:15:45 +0100 | [diff] [blame] | 1456 | "Interface type %d not yet supported\n", vif->type); |
Jouni Malinen | 2c3db3d | 2009-03-03 19:23:26 +0200 | [diff] [blame] | 1457 | ret = -EOPNOTSUPP; |
| 1458 | goto out; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1459 | } |
| 1460 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1461 | ath_print(common, ATH_DBG_CONFIG, |
| 1462 | "Attach a VIF of type: %d\n", ic_opmode); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1463 | |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 1464 | /* Set the VIF opmode */ |
Sujith | 5640b08 | 2008-10-29 10:16:06 +0530 | [diff] [blame] | 1465 | avp->av_opmode = ic_opmode; |
| 1466 | avp->av_bslot = -1; |
| 1467 | |
Jouni Malinen | 2c3db3d | 2009-03-03 19:23:26 +0200 | [diff] [blame] | 1468 | sc->nvifs++; |
Jouni Malinen | 8ca21f0 | 2009-03-03 19:23:27 +0200 | [diff] [blame] | 1469 | |
Felix Fietkau | 364734f | 2010-09-14 20:22:44 +0200 | [diff] [blame] | 1470 | ath9k_set_bssid_mask(hw, vif); |
Jouni Malinen | 8ca21f0 | 2009-03-03 19:23:27 +0200 | [diff] [blame] | 1471 | |
Jouni Malinen | 2c3db3d | 2009-03-03 19:23:26 +0200 | [diff] [blame] | 1472 | if (sc->nvifs > 1) |
| 1473 | goto out; /* skip global settings for secondary vif */ |
| 1474 | |
Sujith | b238e90 | 2009-03-03 10:16:56 +0530 | [diff] [blame] | 1475 | if (ic_opmode == NL80211_IFTYPE_AP) { |
Pavel Roskin | 3069168 | 2010-03-31 18:05:31 -0400 | [diff] [blame] | 1476 | ath9k_hw_set_tsfadjust(ah, 1); |
Sujith | b238e90 | 2009-03-03 10:16:56 +0530 | [diff] [blame] | 1477 | sc->sc_flags |= SC_OP_TSF_RESET; |
| 1478 | } |
Sujith | 5640b08 | 2008-10-29 10:16:06 +0530 | [diff] [blame] | 1479 | |
Sujith | 5640b08 | 2008-10-29 10:16:06 +0530 | [diff] [blame] | 1480 | /* Set the device opmode */ |
Pavel Roskin | 3069168 | 2010-03-31 18:05:31 -0400 | [diff] [blame] | 1481 | ah->opmode = ic_opmode; |
Sujith | 5640b08 | 2008-10-29 10:16:06 +0530 | [diff] [blame] | 1482 | |
Vivek Natarajan | 4e30ffa | 2009-01-28 20:53:27 +0530 | [diff] [blame] | 1483 | /* |
| 1484 | * Enable MIB interrupts when there are hardware phy counters. |
| 1485 | * Note we only do this (at the moment) for station mode. |
| 1486 | */ |
Johannes Berg | 1ed32e4 | 2009-12-23 13:15:45 +0100 | [diff] [blame] | 1487 | if ((vif->type == NL80211_IFTYPE_STATION) || |
| 1488 | (vif->type == NL80211_IFTYPE_ADHOC) || |
| 1489 | (vif->type == NL80211_IFTYPE_MESH_POINT)) { |
Luis R. Rodriguez | 3448f91 | 2010-04-15 17:38:23 -0400 | [diff] [blame] | 1490 | if (ah->config.enable_ani) |
| 1491 | ah->imask |= ATH9K_INT_MIB; |
Pavel Roskin | 3069168 | 2010-03-31 18:05:31 -0400 | [diff] [blame] | 1492 | ah->imask |= ATH9K_INT_TSFOOR; |
Sujith | 4af9cf4 | 2009-02-12 10:06:47 +0530 | [diff] [blame] | 1493 | } |
| 1494 | |
Pavel Roskin | 3069168 | 2010-03-31 18:05:31 -0400 | [diff] [blame] | 1495 | ath9k_hw_set_interrupts(ah, ah->imask); |
Vivek Natarajan | 4e30ffa | 2009-01-28 20:53:27 +0530 | [diff] [blame] | 1496 | |
Johannes Berg | 1ed32e4 | 2009-12-23 13:15:45 +0100 | [diff] [blame] | 1497 | if (vif->type == NL80211_IFTYPE_AP || |
| 1498 | vif->type == NL80211_IFTYPE_ADHOC || |
Vasanthakumar Thiagarajan | 6c3118e | 2010-06-23 06:49:21 -0700 | [diff] [blame] | 1499 | vif->type == NL80211_IFTYPE_MONITOR) { |
| 1500 | sc->sc_flags |= SC_OP_ANI_RUN; |
Luis R. Rodriguez | 3d536ac | 2009-11-03 17:07:04 -0800 | [diff] [blame] | 1501 | ath_start_ani(common); |
Vasanthakumar Thiagarajan | 6c3118e | 2010-06-23 06:49:21 -0700 | [diff] [blame] | 1502 | } |
Luis R. Rodriguez | 6f25542 | 2008-10-03 15:45:27 -0700 | [diff] [blame] | 1503 | |
Jouni Malinen | 2c3db3d | 2009-03-03 19:23:26 +0200 | [diff] [blame] | 1504 | out: |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 1505 | mutex_unlock(&sc->mutex); |
Jouni Malinen | 2c3db3d | 2009-03-03 19:23:26 +0200 | [diff] [blame] | 1506 | return ret; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1507 | } |
| 1508 | |
| 1509 | static void ath9k_remove_interface(struct ieee80211_hw *hw, |
Johannes Berg | 1ed32e4 | 2009-12-23 13:15:45 +0100 | [diff] [blame] | 1510 | struct ieee80211_vif *vif) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1511 | { |
Jouni Malinen | bce048d | 2009-03-03 19:23:28 +0200 | [diff] [blame] | 1512 | struct ath_wiphy *aphy = hw->priv; |
| 1513 | struct ath_softc *sc = aphy->sc; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1514 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Johannes Berg | 1ed32e4 | 2009-12-23 13:15:45 +0100 | [diff] [blame] | 1515 | struct ath_vif *avp = (void *)vif->drv_priv; |
Jouni Malinen | 2c3db3d | 2009-03-03 19:23:26 +0200 | [diff] [blame] | 1516 | int i; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1517 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1518 | ath_print(common, ATH_DBG_CONFIG, "Detach Interface\n"); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1519 | |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 1520 | mutex_lock(&sc->mutex); |
| 1521 | |
Luis R. Rodriguez | 6f25542 | 2008-10-03 15:45:27 -0700 | [diff] [blame] | 1522 | /* Stop ANI */ |
Vasanthakumar Thiagarajan | 6c3118e | 2010-06-23 06:49:21 -0700 | [diff] [blame] | 1523 | sc->sc_flags &= ~SC_OP_ANI_RUN; |
Luis R. Rodriguez | 3d536ac | 2009-11-03 17:07:04 -0800 | [diff] [blame] | 1524 | del_timer_sync(&common->ani.timer); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1525 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1526 | /* Reclaim beacon resources */ |
Pat Erley | 9cb5412 | 2009-03-20 22:59:59 -0400 | [diff] [blame] | 1527 | if ((sc->sc_ah->opmode == NL80211_IFTYPE_AP) || |
| 1528 | (sc->sc_ah->opmode == NL80211_IFTYPE_ADHOC) || |
| 1529 | (sc->sc_ah->opmode == NL80211_IFTYPE_MESH_POINT)) { |
Luis R. Rodriguez | 5f70a88 | 2009-12-23 20:03:28 -0500 | [diff] [blame] | 1530 | ath9k_ps_wakeup(sc); |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 1531 | ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq); |
Luis R. Rodriguez | 5f70a88 | 2009-12-23 20:03:28 -0500 | [diff] [blame] | 1532 | ath9k_ps_restore(sc); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1533 | } |
| 1534 | |
Felix Fietkau | 7440177 | 2010-01-19 20:51:32 +0100 | [diff] [blame] | 1535 | ath_beacon_return(sc, avp); |
Sujith | 672840a | 2008-08-11 14:05:08 +0530 | [diff] [blame] | 1536 | sc->sc_flags &= ~SC_OP_BEACONS; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1537 | |
Jouni Malinen | 2c3db3d | 2009-03-03 19:23:26 +0200 | [diff] [blame] | 1538 | for (i = 0; i < ARRAY_SIZE(sc->beacon.bslot); i++) { |
Johannes Berg | 1ed32e4 | 2009-12-23 13:15:45 +0100 | [diff] [blame] | 1539 | if (sc->beacon.bslot[i] == vif) { |
Jouni Malinen | 2c3db3d | 2009-03-03 19:23:26 +0200 | [diff] [blame] | 1540 | printk(KERN_DEBUG "%s: vif had allocated beacon " |
| 1541 | "slot\n", __func__); |
| 1542 | sc->beacon.bslot[i] = NULL; |
Jouni Malinen | c52f33d | 2009-03-03 19:23:29 +0200 | [diff] [blame] | 1543 | sc->beacon.bslot_aphy[i] = NULL; |
Jouni Malinen | 2c3db3d | 2009-03-03 19:23:26 +0200 | [diff] [blame] | 1544 | } |
| 1545 | } |
| 1546 | |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 1547 | sc->nvifs--; |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 1548 | |
| 1549 | mutex_unlock(&sc->mutex); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1550 | } |
| 1551 | |
Senthil Balasubramanian | fbab739 | 2010-10-05 20:36:40 +0530 | [diff] [blame] | 1552 | static void ath9k_enable_ps(struct ath_softc *sc) |
Senthil Balasubramanian | 3f7c5c1 | 2010-02-03 22:51:13 +0530 | [diff] [blame] | 1553 | { |
Pavel Roskin | 3069168 | 2010-03-31 18:05:31 -0400 | [diff] [blame] | 1554 | struct ath_hw *ah = sc->sc_ah; |
| 1555 | |
Senthil Balasubramanian | 3f7c5c1 | 2010-02-03 22:51:13 +0530 | [diff] [blame] | 1556 | sc->ps_enabled = true; |
Pavel Roskin | 3069168 | 2010-03-31 18:05:31 -0400 | [diff] [blame] | 1557 | if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) { |
| 1558 | if ((ah->imask & ATH9K_INT_TIM_TIMER) == 0) { |
| 1559 | ah->imask |= ATH9K_INT_TIM_TIMER; |
| 1560 | ath9k_hw_set_interrupts(ah, ah->imask); |
Senthil Balasubramanian | 3f7c5c1 | 2010-02-03 22:51:13 +0530 | [diff] [blame] | 1561 | } |
Vasanthakumar Thiagarajan | fdf7662 | 2010-05-17 18:57:55 -0700 | [diff] [blame] | 1562 | ath9k_hw_setrxabort(ah, 1); |
Senthil Balasubramanian | 3f7c5c1 | 2010-02-03 22:51:13 +0530 | [diff] [blame] | 1563 | } |
Senthil Balasubramanian | 3f7c5c1 | 2010-02-03 22:51:13 +0530 | [diff] [blame] | 1564 | } |
| 1565 | |
Senthil Balasubramanian | 845d708 | 2010-10-05 20:36:41 +0530 | [diff] [blame] | 1566 | static void ath9k_disable_ps(struct ath_softc *sc) |
| 1567 | { |
| 1568 | struct ath_hw *ah = sc->sc_ah; |
| 1569 | |
| 1570 | sc->ps_enabled = false; |
| 1571 | ath9k_hw_setpower(ah, ATH9K_PM_AWAKE); |
| 1572 | if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) { |
| 1573 | ath9k_hw_setrxabort(ah, 0); |
| 1574 | sc->ps_flags &= ~(PS_WAIT_FOR_BEACON | |
| 1575 | PS_WAIT_FOR_CAB | |
| 1576 | PS_WAIT_FOR_PSPOLL_DATA | |
| 1577 | PS_WAIT_FOR_TX_ACK); |
| 1578 | if (ah->imask & ATH9K_INT_TIM_TIMER) { |
| 1579 | ah->imask &= ~ATH9K_INT_TIM_TIMER; |
| 1580 | ath9k_hw_set_interrupts(ah, ah->imask); |
| 1581 | } |
| 1582 | } |
| 1583 | |
| 1584 | } |
| 1585 | |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 1586 | static int ath9k_config(struct ieee80211_hw *hw, u32 changed) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1587 | { |
Jouni Malinen | bce048d | 2009-03-03 19:23:28 +0200 | [diff] [blame] | 1588 | struct ath_wiphy *aphy = hw->priv; |
| 1589 | struct ath_softc *sc = aphy->sc; |
Felix Fietkau | 3430098 | 2010-10-10 18:21:52 +0200 | [diff] [blame] | 1590 | struct ath_hw *ah = sc->sc_ah; |
| 1591 | struct ath_common *common = ath9k_hw_common(ah); |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 1592 | struct ieee80211_conf *conf = &hw->conf; |
Luis R. Rodriguez | 194b7c1 | 2009-10-29 10:41:15 -0700 | [diff] [blame] | 1593 | bool disable_radio; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1594 | |
Sujith | aa33de0 | 2008-12-18 11:40:16 +0530 | [diff] [blame] | 1595 | mutex_lock(&sc->mutex); |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 1596 | |
Luis R. Rodriguez | 194b7c1 | 2009-10-29 10:41:15 -0700 | [diff] [blame] | 1597 | /* |
| 1598 | * Leave this as the first check because we need to turn on the |
| 1599 | * radio if it was disabled before prior to processing the rest |
| 1600 | * of the changes. Likewise we must only disable the radio towards |
| 1601 | * the end. |
| 1602 | */ |
Luis R. Rodriguez | 6483917 | 2009-07-14 20:22:53 -0400 | [diff] [blame] | 1603 | if (changed & IEEE80211_CONF_CHANGE_IDLE) { |
Luis R. Rodriguez | 194b7c1 | 2009-10-29 10:41:15 -0700 | [diff] [blame] | 1604 | bool enable_radio; |
| 1605 | bool all_wiphys_idle; |
| 1606 | bool idle = !!(conf->flags & IEEE80211_CONF_IDLE); |
Luis R. Rodriguez | 6483917 | 2009-07-14 20:22:53 -0400 | [diff] [blame] | 1607 | |
| 1608 | spin_lock_bh(&sc->wiphy_lock); |
| 1609 | all_wiphys_idle = ath9k_all_wiphys_idle(sc); |
Luis R. Rodriguez | 194b7c1 | 2009-10-29 10:41:15 -0700 | [diff] [blame] | 1610 | ath9k_set_wiphy_idle(aphy, idle); |
| 1611 | |
Felix Fietkau | 1144601 | 2010-04-06 12:05:01 -0700 | [diff] [blame] | 1612 | enable_radio = (!idle && all_wiphys_idle); |
Luis R. Rodriguez | 194b7c1 | 2009-10-29 10:41:15 -0700 | [diff] [blame] | 1613 | |
| 1614 | /* |
| 1615 | * After we unlock here its possible another wiphy |
| 1616 | * can be re-renabled so to account for that we will |
| 1617 | * only disable the radio toward the end of this routine |
| 1618 | * if by then all wiphys are still idle. |
| 1619 | */ |
Luis R. Rodriguez | 6483917 | 2009-07-14 20:22:53 -0400 | [diff] [blame] | 1620 | spin_unlock_bh(&sc->wiphy_lock); |
| 1621 | |
Luis R. Rodriguez | 194b7c1 | 2009-10-29 10:41:15 -0700 | [diff] [blame] | 1622 | if (enable_radio) { |
Vivek Natarajan | 1dbfd9d | 2010-01-29 16:56:51 +0530 | [diff] [blame] | 1623 | sc->ps_idle = false; |
Luis R. Rodriguez | 68a8911 | 2009-11-02 14:35:42 -0800 | [diff] [blame] | 1624 | ath_radio_enable(sc, hw); |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1625 | ath_print(common, ATH_DBG_CONFIG, |
| 1626 | "not-idle: enabling radio\n"); |
Luis R. Rodriguez | 6483917 | 2009-07-14 20:22:53 -0400 | [diff] [blame] | 1627 | } |
| 1628 | } |
| 1629 | |
Luis R. Rodriguez | e7824a5 | 2009-11-24 02:53:25 -0500 | [diff] [blame] | 1630 | /* |
| 1631 | * We just prepare to enable PS. We have to wait until our AP has |
| 1632 | * ACK'd our null data frame to disable RX otherwise we'll ignore |
| 1633 | * those ACKs and end up retransmitting the same null data frames. |
| 1634 | * IEEE80211_CONF_CHANGE_PS is only passed by mac80211 for STA mode. |
| 1635 | */ |
Vivek Natarajan | 3cbb5dd | 2009-01-20 11:17:08 +0530 | [diff] [blame] | 1636 | if (changed & IEEE80211_CONF_CHANGE_PS) { |
Luis R. Rodriguez | 8ab2cd0 | 2010-09-16 15:12:26 -0400 | [diff] [blame] | 1637 | unsigned long flags; |
| 1638 | spin_lock_irqsave(&sc->sc_pm_lock, flags); |
Senthil Balasubramanian | fbab739 | 2010-10-05 20:36:40 +0530 | [diff] [blame] | 1639 | if (conf->flags & IEEE80211_CONF_PS) |
| 1640 | ath9k_enable_ps(sc); |
Senthil Balasubramanian | 845d708 | 2010-10-05 20:36:41 +0530 | [diff] [blame] | 1641 | else |
| 1642 | ath9k_disable_ps(sc); |
Luis R. Rodriguez | 8ab2cd0 | 2010-09-16 15:12:26 -0400 | [diff] [blame] | 1643 | spin_unlock_irqrestore(&sc->sc_pm_lock, flags); |
Vivek Natarajan | 3cbb5dd | 2009-01-20 11:17:08 +0530 | [diff] [blame] | 1644 | } |
| 1645 | |
Sujith | 199afd9 | 2010-01-08 10:36:13 +0530 | [diff] [blame] | 1646 | if (changed & IEEE80211_CONF_CHANGE_MONITOR) { |
| 1647 | if (conf->flags & IEEE80211_CONF_MONITOR) { |
| 1648 | ath_print(common, ATH_DBG_CONFIG, |
| 1649 | "HW opmode set to Monitor mode\n"); |
| 1650 | sc->sc_ah->opmode = NL80211_IFTYPE_MONITOR; |
| 1651 | } |
| 1652 | } |
| 1653 | |
Johannes Berg | 4797938 | 2009-01-07 10:13:27 +0100 | [diff] [blame] | 1654 | if (changed & IEEE80211_CONF_CHANGE_CHANNEL) { |
Sujith | 99405f9 | 2008-11-24 12:08:35 +0530 | [diff] [blame] | 1655 | struct ieee80211_channel *curchan = hw->conf.channel; |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 1656 | int pos = curchan->hw_value; |
Felix Fietkau | 3430098 | 2010-10-10 18:21:52 +0200 | [diff] [blame] | 1657 | int old_pos = -1; |
| 1658 | unsigned long flags; |
| 1659 | |
| 1660 | if (ah->curchan) |
| 1661 | old_pos = ah->curchan - &ah->channels[0]; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1662 | |
Jouni Malinen | 0e2dedf | 2009-03-03 19:23:32 +0200 | [diff] [blame] | 1663 | aphy->chan_idx = pos; |
| 1664 | aphy->chan_is_ht = conf_is_ht(conf); |
Felix Fietkau | 5ee0865 | 2010-07-31 00:11:59 +0200 | [diff] [blame] | 1665 | if (hw->conf.flags & IEEE80211_CONF_OFFCHANNEL) |
| 1666 | sc->sc_flags |= SC_OP_OFFCHANNEL; |
| 1667 | else |
| 1668 | sc->sc_flags &= ~SC_OP_OFFCHANNEL; |
Jouni Malinen | 0e2dedf | 2009-03-03 19:23:32 +0200 | [diff] [blame] | 1669 | |
Jouni Malinen | 8089cc4 | 2009-03-03 19:23:38 +0200 | [diff] [blame] | 1670 | if (aphy->state == ATH_WIPHY_SCAN || |
| 1671 | aphy->state == ATH_WIPHY_ACTIVE) |
| 1672 | ath9k_wiphy_pause_all_forced(sc, aphy); |
| 1673 | else { |
| 1674 | /* |
| 1675 | * Do not change operational channel based on a paused |
| 1676 | * wiphy changes. |
| 1677 | */ |
| 1678 | goto skip_chan_change; |
| 1679 | } |
Jouni Malinen | 0e2dedf | 2009-03-03 19:23:32 +0200 | [diff] [blame] | 1680 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1681 | ath_print(common, ATH_DBG_CONFIG, "Set channel: %d MHz\n", |
| 1682 | curchan->center_freq); |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 1683 | |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 1684 | /* XXX: remove me eventualy */ |
Jouni Malinen | 0e2dedf | 2009-03-03 19:23:32 +0200 | [diff] [blame] | 1685 | ath9k_update_ichannel(sc, hw, &sc->sc_ah->channels[pos]); |
Sujith | e11602b | 2008-11-27 09:46:27 +0530 | [diff] [blame] | 1686 | |
Luis R. Rodriguez | ecf7044 | 2008-12-23 15:58:43 -0800 | [diff] [blame] | 1687 | ath_update_chainmask(sc, conf_is_ht(conf)); |
Sujith | 86060f0 | 2009-01-07 14:25:29 +0530 | [diff] [blame] | 1688 | |
Felix Fietkau | 3430098 | 2010-10-10 18:21:52 +0200 | [diff] [blame] | 1689 | /* update survey stats for the old channel before switching */ |
| 1690 | spin_lock_irqsave(&common->cc_lock, flags); |
| 1691 | ath_update_survey_stats(sc); |
| 1692 | spin_unlock_irqrestore(&common->cc_lock, flags); |
| 1693 | |
| 1694 | /* |
| 1695 | * If the operating channel changes, change the survey in-use flags |
| 1696 | * along with it. |
| 1697 | * Reset the survey data for the new channel, unless we're switching |
| 1698 | * back to the operating channel from an off-channel operation. |
| 1699 | */ |
| 1700 | if (!(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL) && |
| 1701 | sc->cur_survey != &sc->survey[pos]) { |
| 1702 | |
| 1703 | if (sc->cur_survey) |
| 1704 | sc->cur_survey->filled &= ~SURVEY_INFO_IN_USE; |
| 1705 | |
| 1706 | sc->cur_survey = &sc->survey[pos]; |
| 1707 | |
| 1708 | memset(sc->cur_survey, 0, sizeof(struct survey_info)); |
| 1709 | sc->cur_survey->filled |= SURVEY_INFO_IN_USE; |
| 1710 | } else if (!(sc->survey[pos].filled & SURVEY_INFO_IN_USE)) { |
| 1711 | memset(&sc->survey[pos], 0, sizeof(struct survey_info)); |
| 1712 | } |
| 1713 | |
Jouni Malinen | 0e2dedf | 2009-03-03 19:23:32 +0200 | [diff] [blame] | 1714 | 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] | 1715 | ath_print(common, ATH_DBG_FATAL, |
| 1716 | "Unable to set channel\n"); |
Sujith | aa33de0 | 2008-12-18 11:40:16 +0530 | [diff] [blame] | 1717 | mutex_unlock(&sc->mutex); |
Sujith | e11602b | 2008-11-27 09:46:27 +0530 | [diff] [blame] | 1718 | return -EINVAL; |
| 1719 | } |
Felix Fietkau | 3430098 | 2010-10-10 18:21:52 +0200 | [diff] [blame] | 1720 | |
| 1721 | /* |
| 1722 | * The most recent snapshot of channel->noisefloor for the old |
| 1723 | * channel is only available after the hardware reset. Copy it to |
| 1724 | * the survey stats now. |
| 1725 | */ |
| 1726 | if (old_pos >= 0) |
| 1727 | ath_update_survey_nf(sc, old_pos); |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 1728 | } |
Sujith | 86b89ee | 2008-08-07 10:54:57 +0530 | [diff] [blame] | 1729 | |
Jouni Malinen | 8089cc4 | 2009-03-03 19:23:38 +0200 | [diff] [blame] | 1730 | skip_chan_change: |
Luis R. Rodriguez | c9f6a65 | 2010-01-19 14:04:19 -0500 | [diff] [blame] | 1731 | if (changed & IEEE80211_CONF_CHANGE_POWER) { |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 1732 | sc->config.txpowlimit = 2 * conf->power_level; |
Luis R. Rodriguez | c9f6a65 | 2010-01-19 14:04:19 -0500 | [diff] [blame] | 1733 | ath_update_txpow(sc); |
| 1734 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1735 | |
Luis R. Rodriguez | 194b7c1 | 2009-10-29 10:41:15 -0700 | [diff] [blame] | 1736 | spin_lock_bh(&sc->wiphy_lock); |
| 1737 | disable_radio = ath9k_all_wiphys_idle(sc); |
| 1738 | spin_unlock_bh(&sc->wiphy_lock); |
| 1739 | |
Luis R. Rodriguez | 6483917 | 2009-07-14 20:22:53 -0400 | [diff] [blame] | 1740 | if (disable_radio) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1741 | ath_print(common, ATH_DBG_CONFIG, "idle: disabling radio\n"); |
Vivek Natarajan | 1dbfd9d | 2010-01-29 16:56:51 +0530 | [diff] [blame] | 1742 | sc->ps_idle = true; |
Luis R. Rodriguez | 68a8911 | 2009-11-02 14:35:42 -0800 | [diff] [blame] | 1743 | ath_radio_disable(sc, hw); |
Luis R. Rodriguez | 6483917 | 2009-07-14 20:22:53 -0400 | [diff] [blame] | 1744 | } |
| 1745 | |
Sujith | aa33de0 | 2008-12-18 11:40:16 +0530 | [diff] [blame] | 1746 | mutex_unlock(&sc->mutex); |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 1747 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1748 | return 0; |
| 1749 | } |
| 1750 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1751 | #define SUPPORTED_FILTERS \ |
| 1752 | (FIF_PROMISC_IN_BSS | \ |
| 1753 | FIF_ALLMULTI | \ |
| 1754 | FIF_CONTROL | \ |
Luis R. Rodriguez | af6a3fc | 2009-08-08 21:55:16 -0400 | [diff] [blame] | 1755 | FIF_PSPOLL | \ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1756 | FIF_OTHER_BSS | \ |
| 1757 | FIF_BCN_PRBRESP_PROMISC | \ |
Jouni Malinen | 9c1d8e4 | 2010-10-13 17:29:31 +0300 | [diff] [blame] | 1758 | FIF_PROBE_REQ | \ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1759 | FIF_FCSFAIL) |
| 1760 | |
Sujith | 7dcfdcd | 2008-08-11 14:03:13 +0530 | [diff] [blame] | 1761 | /* FIXME: sc->sc_full_reset ? */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1762 | static void ath9k_configure_filter(struct ieee80211_hw *hw, |
| 1763 | unsigned int changed_flags, |
| 1764 | unsigned int *total_flags, |
Johannes Berg | 3ac64be | 2009-08-17 16:16:53 +0200 | [diff] [blame] | 1765 | u64 multicast) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1766 | { |
Jouni Malinen | bce048d | 2009-03-03 19:23:28 +0200 | [diff] [blame] | 1767 | struct ath_wiphy *aphy = hw->priv; |
| 1768 | struct ath_softc *sc = aphy->sc; |
Sujith | 7dcfdcd | 2008-08-11 14:03:13 +0530 | [diff] [blame] | 1769 | u32 rfilt; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1770 | |
| 1771 | changed_flags &= SUPPORTED_FILTERS; |
| 1772 | *total_flags &= SUPPORTED_FILTERS; |
| 1773 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 1774 | sc->rx.rxfilter = *total_flags; |
Jouni Malinen | aa68aea | 2009-05-19 17:01:41 +0300 | [diff] [blame] | 1775 | ath9k_ps_wakeup(sc); |
Sujith | 7dcfdcd | 2008-08-11 14:03:13 +0530 | [diff] [blame] | 1776 | rfilt = ath_calcrxfilter(sc); |
| 1777 | ath9k_hw_setrxfilter(sc->sc_ah, rfilt); |
Jouni Malinen | aa68aea | 2009-05-19 17:01:41 +0300 | [diff] [blame] | 1778 | ath9k_ps_restore(sc); |
Sujith | 7dcfdcd | 2008-08-11 14:03:13 +0530 | [diff] [blame] | 1779 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1780 | ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_CONFIG, |
| 1781 | "Set HW RX filter: 0x%x\n", rfilt); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1782 | } |
| 1783 | |
Johannes Berg | 4ca7786 | 2010-02-19 19:06:56 +0100 | [diff] [blame] | 1784 | static int ath9k_sta_add(struct ieee80211_hw *hw, |
| 1785 | struct ieee80211_vif *vif, |
| 1786 | struct ieee80211_sta *sta) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1787 | { |
Jouni Malinen | bce048d | 2009-03-03 19:23:28 +0200 | [diff] [blame] | 1788 | struct ath_wiphy *aphy = hw->priv; |
| 1789 | struct ath_softc *sc = aphy->sc; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1790 | |
Johannes Berg | 4ca7786 | 2010-02-19 19:06:56 +0100 | [diff] [blame] | 1791 | ath_node_attach(sc, sta); |
| 1792 | |
| 1793 | return 0; |
| 1794 | } |
| 1795 | |
| 1796 | static int ath9k_sta_remove(struct ieee80211_hw *hw, |
| 1797 | struct ieee80211_vif *vif, |
| 1798 | struct ieee80211_sta *sta) |
| 1799 | { |
| 1800 | struct ath_wiphy *aphy = hw->priv; |
| 1801 | struct ath_softc *sc = aphy->sc; |
| 1802 | |
| 1803 | ath_node_detach(sc, sta); |
| 1804 | |
| 1805 | return 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1806 | } |
| 1807 | |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 1808 | static int ath9k_conf_tx(struct ieee80211_hw *hw, u16 queue, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1809 | const struct ieee80211_tx_queue_params *params) |
| 1810 | { |
Jouni Malinen | bce048d | 2009-03-03 19:23:28 +0200 | [diff] [blame] | 1811 | struct ath_wiphy *aphy = hw->priv; |
| 1812 | struct ath_softc *sc = aphy->sc; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1813 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Sujith | ea9880f | 2008-08-07 10:53:10 +0530 | [diff] [blame] | 1814 | struct ath9k_tx_queue_info qi; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1815 | int ret = 0, qnum; |
| 1816 | |
| 1817 | if (queue >= WME_NUM_AC) |
| 1818 | return 0; |
| 1819 | |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 1820 | mutex_lock(&sc->mutex); |
| 1821 | |
Sujith | 1ffb061 | 2009-03-30 15:28:46 +0530 | [diff] [blame] | 1822 | memset(&qi, 0, sizeof(struct ath9k_tx_queue_info)); |
| 1823 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1824 | qi.tqi_aifs = params->aifs; |
| 1825 | qi.tqi_cwmin = params->cw_min; |
| 1826 | qi.tqi_cwmax = params->cw_max; |
| 1827 | qi.tqi_burstTime = params->txop; |
| 1828 | qnum = ath_get_hal_qnum(queue, sc); |
| 1829 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1830 | ath_print(common, ATH_DBG_CONFIG, |
| 1831 | "Configure tx [queue/halq] [%d/%d], " |
| 1832 | "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n", |
| 1833 | queue, qnum, params->aifs, params->cw_min, |
| 1834 | params->cw_max, params->txop); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1835 | |
| 1836 | ret = ath_txq_update(sc, qnum, &qi); |
| 1837 | if (ret) |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1838 | ath_print(common, ATH_DBG_FATAL, "TXQ Update failed\n"); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1839 | |
Vivek Natarajan | 94db293 | 2009-11-25 12:01:54 +0530 | [diff] [blame] | 1840 | if (sc->sc_ah->opmode == NL80211_IFTYPE_ADHOC) |
Felix Fietkau | 1d2231e | 2010-06-12 00:33:51 -0400 | [diff] [blame] | 1841 | if ((qnum == sc->tx.hwq_map[WME_AC_BE]) && !ret) |
Vivek Natarajan | 94db293 | 2009-11-25 12:01:54 +0530 | [diff] [blame] | 1842 | ath_beaconq_config(sc); |
| 1843 | |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 1844 | mutex_unlock(&sc->mutex); |
| 1845 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1846 | return ret; |
| 1847 | } |
| 1848 | |
| 1849 | static int ath9k_set_key(struct ieee80211_hw *hw, |
| 1850 | enum set_key_cmd cmd, |
Johannes Berg | dc822b5 | 2008-12-29 12:55:09 +0100 | [diff] [blame] | 1851 | struct ieee80211_vif *vif, |
| 1852 | struct ieee80211_sta *sta, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1853 | struct ieee80211_key_conf *key) |
| 1854 | { |
Jouni Malinen | bce048d | 2009-03-03 19:23:28 +0200 | [diff] [blame] | 1855 | struct ath_wiphy *aphy = hw->priv; |
| 1856 | struct ath_softc *sc = aphy->sc; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1857 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1858 | int ret = 0; |
| 1859 | |
Jouni Malinen | b3bd89c | 2009-02-24 13:42:01 +0200 | [diff] [blame] | 1860 | if (modparam_nohwcrypt) |
| 1861 | return -ENOSPC; |
| 1862 | |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 1863 | mutex_lock(&sc->mutex); |
Vivek Natarajan | 3cbb5dd | 2009-01-20 11:17:08 +0530 | [diff] [blame] | 1864 | ath9k_ps_wakeup(sc); |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1865 | ath_print(common, ATH_DBG_CONFIG, "Set HW Key\n"); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1866 | |
| 1867 | switch (cmd) { |
| 1868 | case SET_KEY: |
Bruno Randolf | 040e539 | 2010-09-08 16:05:04 +0900 | [diff] [blame] | 1869 | ret = ath_key_config(common, vif, sta, key); |
Jouni Malinen | 6ace289 | 2008-12-17 13:32:17 +0200 | [diff] [blame] | 1870 | if (ret >= 0) { |
| 1871 | key->hw_key_idx = ret; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1872 | /* push IV and Michael MIC generation to stack */ |
| 1873 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 1874 | if (key->cipher == WLAN_CIPHER_SUITE_TKIP) |
Senthil Balasubramanian | 1b96175 | 2008-09-01 19:45:21 +0530 | [diff] [blame] | 1875 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 1876 | if (sc->sc_ah->sw_mgmt_crypto && |
| 1877 | key->cipher == WLAN_CIPHER_SUITE_CCMP) |
Jouni Malinen | 0ced0e1 | 2009-01-08 13:32:13 +0200 | [diff] [blame] | 1878 | key->flags |= IEEE80211_KEY_FLAG_SW_MGMT; |
Jouni Malinen | 6ace289 | 2008-12-17 13:32:17 +0200 | [diff] [blame] | 1879 | ret = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1880 | } |
| 1881 | break; |
| 1882 | case DISABLE_KEY: |
Bruno Randolf | 040e539 | 2010-09-08 16:05:04 +0900 | [diff] [blame] | 1883 | ath_key_delete(common, key); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1884 | break; |
| 1885 | default: |
| 1886 | ret = -EINVAL; |
| 1887 | } |
| 1888 | |
Vivek Natarajan | 3cbb5dd | 2009-01-20 11:17:08 +0530 | [diff] [blame] | 1889 | ath9k_ps_restore(sc); |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 1890 | mutex_unlock(&sc->mutex); |
| 1891 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1892 | return ret; |
| 1893 | } |
| 1894 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1895 | static void ath9k_bss_info_changed(struct ieee80211_hw *hw, |
| 1896 | struct ieee80211_vif *vif, |
| 1897 | struct ieee80211_bss_conf *bss_conf, |
| 1898 | u32 changed) |
| 1899 | { |
Jouni Malinen | bce048d | 2009-03-03 19:23:28 +0200 | [diff] [blame] | 1900 | struct ath_wiphy *aphy = hw->priv; |
| 1901 | struct ath_softc *sc = aphy->sc; |
Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 1902 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 1903 | struct ath_common *common = ath9k_hw_common(ah); |
Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 1904 | struct ath_vif *avp = (void *)vif->drv_priv; |
Felix Fietkau | 0005baf | 2010-01-15 02:33:40 +0100 | [diff] [blame] | 1905 | int slottime; |
Sujith | c6089cc | 2009-11-16 11:40:48 +0530 | [diff] [blame] | 1906 | int error; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1907 | |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 1908 | mutex_lock(&sc->mutex); |
| 1909 | |
Sujith | c6089cc | 2009-11-16 11:40:48 +0530 | [diff] [blame] | 1910 | if (changed & BSS_CHANGED_BSSID) { |
| 1911 | /* Set BSSID */ |
| 1912 | memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN); |
| 1913 | memcpy(avp->bssid, bss_conf->bssid, ETH_ALEN); |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 1914 | common->curaid = 0; |
Luis R. Rodriguez | f2b2143 | 2009-09-10 08:50:20 -0700 | [diff] [blame] | 1915 | ath9k_hw_write_associd(ah); |
Sujith | c6089cc | 2009-11-16 11:40:48 +0530 | [diff] [blame] | 1916 | |
| 1917 | /* Set aggregation protection mode parameters */ |
| 1918 | sc->config.ath_aggr_prot = 0; |
| 1919 | |
| 1920 | /* Only legacy IBSS for now */ |
| 1921 | if (vif->type == NL80211_IFTYPE_ADHOC) |
| 1922 | ath_update_chainmask(sc, 0); |
| 1923 | |
| 1924 | ath_print(common, ATH_DBG_CONFIG, |
| 1925 | "BSSID: %pM aid: 0x%x\n", |
| 1926 | common->curbssid, common->curaid); |
| 1927 | |
| 1928 | /* need to reconfigure the beacon */ |
| 1929 | sc->sc_flags &= ~SC_OP_BEACONS ; |
Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 1930 | } |
| 1931 | |
Sujith | c6089cc | 2009-11-16 11:40:48 +0530 | [diff] [blame] | 1932 | /* Enable transmission of beacons (AP, IBSS, MESH) */ |
| 1933 | if ((changed & BSS_CHANGED_BEACON) || |
| 1934 | ((changed & BSS_CHANGED_BEACON_ENABLED) && bss_conf->enable_beacon)) { |
| 1935 | ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq); |
| 1936 | error = ath_beacon_alloc(aphy, vif); |
| 1937 | if (!error) |
| 1938 | ath_beacon_config(sc, vif); |
Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 1939 | } |
| 1940 | |
Felix Fietkau | 0005baf | 2010-01-15 02:33:40 +0100 | [diff] [blame] | 1941 | if (changed & BSS_CHANGED_ERP_SLOT) { |
| 1942 | if (bss_conf->use_short_slot) |
| 1943 | slottime = 9; |
| 1944 | else |
| 1945 | slottime = 20; |
| 1946 | if (vif->type == NL80211_IFTYPE_AP) { |
| 1947 | /* |
| 1948 | * Defer update, so that connected stations can adjust |
| 1949 | * their settings at the same time. |
| 1950 | * See beacon.c for more details |
| 1951 | */ |
| 1952 | sc->beacon.slottime = slottime; |
| 1953 | sc->beacon.updateslot = UPDATE; |
| 1954 | } else { |
| 1955 | ah->slottime = slottime; |
| 1956 | ath9k_hw_init_global_settings(ah); |
| 1957 | } |
| 1958 | } |
| 1959 | |
Sujith | c6089cc | 2009-11-16 11:40:48 +0530 | [diff] [blame] | 1960 | /* Disable transmission of beacons */ |
| 1961 | if ((changed & BSS_CHANGED_BEACON_ENABLED) && !bss_conf->enable_beacon) |
| 1962 | ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq); |
| 1963 | |
| 1964 | if (changed & BSS_CHANGED_BEACON_INT) { |
| 1965 | sc->beacon_interval = bss_conf->beacon_int; |
| 1966 | /* |
| 1967 | * In case of AP mode, the HW TSF has to be reset |
| 1968 | * when the beacon interval changes. |
| 1969 | */ |
| 1970 | if (vif->type == NL80211_IFTYPE_AP) { |
| 1971 | sc->sc_flags |= SC_OP_TSF_RESET; |
Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 1972 | ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq); |
Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 1973 | error = ath_beacon_alloc(aphy, vif); |
| 1974 | if (!error) |
| 1975 | ath_beacon_config(sc, vif); |
Sujith | c6089cc | 2009-11-16 11:40:48 +0530 | [diff] [blame] | 1976 | } else { |
| 1977 | ath_beacon_config(sc, vif); |
Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 1978 | } |
| 1979 | } |
| 1980 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1981 | if (changed & BSS_CHANGED_ERP_PREAMBLE) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1982 | ath_print(common, ATH_DBG_CONFIG, "BSS Changed PREAMBLE %d\n", |
| 1983 | bss_conf->use_short_preamble); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1984 | if (bss_conf->use_short_preamble) |
Sujith | 672840a | 2008-08-11 14:05:08 +0530 | [diff] [blame] | 1985 | sc->sc_flags |= SC_OP_PREAMBLE_SHORT; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1986 | else |
Sujith | 672840a | 2008-08-11 14:05:08 +0530 | [diff] [blame] | 1987 | sc->sc_flags &= ~SC_OP_PREAMBLE_SHORT; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1988 | } |
| 1989 | |
| 1990 | if (changed & BSS_CHANGED_ERP_CTS_PROT) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1991 | ath_print(common, ATH_DBG_CONFIG, "BSS Changed CTS PROT %d\n", |
| 1992 | bss_conf->use_cts_prot); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1993 | if (bss_conf->use_cts_prot && |
| 1994 | hw->conf.channel->band != IEEE80211_BAND_5GHZ) |
Sujith | 672840a | 2008-08-11 14:05:08 +0530 | [diff] [blame] | 1995 | sc->sc_flags |= SC_OP_PROTECT_ENABLE; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1996 | else |
Sujith | 672840a | 2008-08-11 14:05:08 +0530 | [diff] [blame] | 1997 | sc->sc_flags &= ~SC_OP_PROTECT_ENABLE; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1998 | } |
| 1999 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2000 | if (changed & BSS_CHANGED_ASSOC) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2001 | ath_print(common, ATH_DBG_CONFIG, "BSS Changed ASSOC %d\n", |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2002 | bss_conf->assoc); |
Felix Fietkau | 9fa23e1 | 2010-10-15 20:03:31 +0200 | [diff] [blame] | 2003 | ath9k_bss_assoc_info(sc, hw, vif, bss_conf); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2004 | } |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 2005 | |
| 2006 | mutex_unlock(&sc->mutex); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2007 | } |
| 2008 | |
| 2009 | static u64 ath9k_get_tsf(struct ieee80211_hw *hw) |
| 2010 | { |
| 2011 | u64 tsf; |
Jouni Malinen | bce048d | 2009-03-03 19:23:28 +0200 | [diff] [blame] | 2012 | struct ath_wiphy *aphy = hw->priv; |
| 2013 | struct ath_softc *sc = aphy->sc; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2014 | |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 2015 | mutex_lock(&sc->mutex); |
| 2016 | tsf = ath9k_hw_gettsf64(sc->sc_ah); |
| 2017 | mutex_unlock(&sc->mutex); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2018 | |
| 2019 | return tsf; |
| 2020 | } |
| 2021 | |
Alina Friedrichsen | 3b5d665 | 2009-01-24 07:09:59 +0100 | [diff] [blame] | 2022 | static void ath9k_set_tsf(struct ieee80211_hw *hw, u64 tsf) |
| 2023 | { |
Jouni Malinen | bce048d | 2009-03-03 19:23:28 +0200 | [diff] [blame] | 2024 | struct ath_wiphy *aphy = hw->priv; |
| 2025 | struct ath_softc *sc = aphy->sc; |
Alina Friedrichsen | 3b5d665 | 2009-01-24 07:09:59 +0100 | [diff] [blame] | 2026 | |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 2027 | mutex_lock(&sc->mutex); |
| 2028 | ath9k_hw_settsf64(sc->sc_ah, tsf); |
| 2029 | mutex_unlock(&sc->mutex); |
Alina Friedrichsen | 3b5d665 | 2009-01-24 07:09:59 +0100 | [diff] [blame] | 2030 | } |
| 2031 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2032 | static void ath9k_reset_tsf(struct ieee80211_hw *hw) |
| 2033 | { |
Jouni Malinen | bce048d | 2009-03-03 19:23:28 +0200 | [diff] [blame] | 2034 | struct ath_wiphy *aphy = hw->priv; |
| 2035 | struct ath_softc *sc = aphy->sc; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2036 | |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 2037 | mutex_lock(&sc->mutex); |
Luis R. Rodriguez | 21526d5 | 2009-09-09 20:05:39 -0700 | [diff] [blame] | 2038 | |
| 2039 | ath9k_ps_wakeup(sc); |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 2040 | ath9k_hw_reset_tsf(sc->sc_ah); |
Luis R. Rodriguez | 21526d5 | 2009-09-09 20:05:39 -0700 | [diff] [blame] | 2041 | ath9k_ps_restore(sc); |
| 2042 | |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 2043 | mutex_unlock(&sc->mutex); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2044 | } |
| 2045 | |
| 2046 | static int ath9k_ampdu_action(struct ieee80211_hw *hw, |
Johannes Berg | c951ad3 | 2009-11-16 12:00:38 +0100 | [diff] [blame] | 2047 | struct ieee80211_vif *vif, |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 2048 | enum ieee80211_ampdu_mlme_action action, |
| 2049 | struct ieee80211_sta *sta, |
| 2050 | u16 tid, u16 *ssn) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2051 | { |
Jouni Malinen | bce048d | 2009-03-03 19:23:28 +0200 | [diff] [blame] | 2052 | struct ath_wiphy *aphy = hw->priv; |
| 2053 | struct ath_softc *sc = aphy->sc; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2054 | int ret = 0; |
| 2055 | |
Johannes Berg | 85ad181 | 2010-06-10 10:21:49 +0200 | [diff] [blame] | 2056 | local_bh_disable(); |
| 2057 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2058 | switch (action) { |
| 2059 | case IEEE80211_AMPDU_RX_START: |
Sujith | dca3edb | 2008-10-29 10:19:01 +0530 | [diff] [blame] | 2060 | if (!(sc->sc_flags & SC_OP_RXAGGR)) |
| 2061 | ret = -ENOTSUPP; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2062 | break; |
| 2063 | case IEEE80211_AMPDU_RX_STOP: |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2064 | break; |
| 2065 | case IEEE80211_AMPDU_TX_START: |
Luis R. Rodriguez | 8b685ba | 2009-12-23 20:03:29 -0500 | [diff] [blame] | 2066 | ath9k_ps_wakeup(sc); |
Felix Fietkau | 231c3a1 | 2010-09-20 19:35:28 +0200 | [diff] [blame] | 2067 | ret = ath_tx_aggr_start(sc, sta, tid, ssn); |
| 2068 | if (!ret) |
| 2069 | ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
Luis R. Rodriguez | 8b685ba | 2009-12-23 20:03:29 -0500 | [diff] [blame] | 2070 | ath9k_ps_restore(sc); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2071 | break; |
| 2072 | case IEEE80211_AMPDU_TX_STOP: |
Luis R. Rodriguez | 8b685ba | 2009-12-23 20:03:29 -0500 | [diff] [blame] | 2073 | ath9k_ps_wakeup(sc); |
Sujith | f83da96 | 2009-07-23 15:32:37 +0530 | [diff] [blame] | 2074 | ath_tx_aggr_stop(sc, sta, tid); |
Johannes Berg | c951ad3 | 2009-11-16 12:00:38 +0100 | [diff] [blame] | 2075 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
Luis R. Rodriguez | 8b685ba | 2009-12-23 20:03:29 -0500 | [diff] [blame] | 2076 | ath9k_ps_restore(sc); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2077 | break; |
Johannes Berg | b172023 | 2009-03-23 17:28:39 +0100 | [diff] [blame] | 2078 | case IEEE80211_AMPDU_TX_OPERATIONAL: |
Luis R. Rodriguez | 8b685ba | 2009-12-23 20:03:29 -0500 | [diff] [blame] | 2079 | ath9k_ps_wakeup(sc); |
Sujith | 8469cde | 2008-10-29 10:19:28 +0530 | [diff] [blame] | 2080 | ath_tx_aggr_resume(sc, sta, tid); |
Luis R. Rodriguez | 8b685ba | 2009-12-23 20:03:29 -0500 | [diff] [blame] | 2081 | ath9k_ps_restore(sc); |
Sujith | 8469cde | 2008-10-29 10:19:28 +0530 | [diff] [blame] | 2082 | break; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2083 | default: |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2084 | ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_FATAL, |
| 2085 | "Unknown AMPDU action\n"); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2086 | } |
| 2087 | |
Johannes Berg | 85ad181 | 2010-06-10 10:21:49 +0200 | [diff] [blame] | 2088 | local_bh_enable(); |
| 2089 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2090 | return ret; |
| 2091 | } |
| 2092 | |
Benoit Papillault | 62dad5b | 2010-04-28 00:08:24 +0200 | [diff] [blame] | 2093 | static int ath9k_get_survey(struct ieee80211_hw *hw, int idx, |
| 2094 | struct survey_info *survey) |
| 2095 | { |
| 2096 | struct ath_wiphy *aphy = hw->priv; |
| 2097 | struct ath_softc *sc = aphy->sc; |
Felix Fietkau | 3430098 | 2010-10-10 18:21:52 +0200 | [diff] [blame] | 2098 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Felix Fietkau | 39162db | 2010-09-29 19:12:06 +0200 | [diff] [blame] | 2099 | struct ieee80211_supported_band *sband; |
Felix Fietkau | 3430098 | 2010-10-10 18:21:52 +0200 | [diff] [blame] | 2100 | struct ieee80211_channel *chan; |
| 2101 | unsigned long flags; |
| 2102 | int pos; |
| 2103 | |
| 2104 | spin_lock_irqsave(&common->cc_lock, flags); |
| 2105 | if (idx == 0) |
| 2106 | ath_update_survey_stats(sc); |
Benoit Papillault | 62dad5b | 2010-04-28 00:08:24 +0200 | [diff] [blame] | 2107 | |
Felix Fietkau | 39162db | 2010-09-29 19:12:06 +0200 | [diff] [blame] | 2108 | sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ]; |
| 2109 | if (sband && idx >= sband->n_channels) { |
| 2110 | idx -= sband->n_channels; |
| 2111 | sband = NULL; |
| 2112 | } |
Benoit Papillault | 62dad5b | 2010-04-28 00:08:24 +0200 | [diff] [blame] | 2113 | |
Felix Fietkau | 39162db | 2010-09-29 19:12:06 +0200 | [diff] [blame] | 2114 | if (!sband) |
| 2115 | sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ]; |
| 2116 | |
Felix Fietkau | 3430098 | 2010-10-10 18:21:52 +0200 | [diff] [blame] | 2117 | if (!sband || idx >= sband->n_channels) { |
| 2118 | spin_unlock_irqrestore(&common->cc_lock, flags); |
| 2119 | return -ENOENT; |
Felix Fietkau | 4f1a5a4 | 2010-09-29 17:15:28 +0200 | [diff] [blame] | 2120 | } |
Benoit Papillault | 62dad5b | 2010-04-28 00:08:24 +0200 | [diff] [blame] | 2121 | |
Felix Fietkau | 3430098 | 2010-10-10 18:21:52 +0200 | [diff] [blame] | 2122 | chan = &sband->channels[idx]; |
| 2123 | pos = chan->hw_value; |
| 2124 | memcpy(survey, &sc->survey[pos], sizeof(*survey)); |
| 2125 | survey->channel = chan; |
| 2126 | spin_unlock_irqrestore(&common->cc_lock, flags); |
| 2127 | |
Benoit Papillault | 62dad5b | 2010-04-28 00:08:24 +0200 | [diff] [blame] | 2128 | return 0; |
| 2129 | } |
| 2130 | |
Sujith | 0c98de6 | 2009-03-03 10:16:45 +0530 | [diff] [blame] | 2131 | static void ath9k_sw_scan_start(struct ieee80211_hw *hw) |
| 2132 | { |
Jouni Malinen | bce048d | 2009-03-03 19:23:28 +0200 | [diff] [blame] | 2133 | struct ath_wiphy *aphy = hw->priv; |
| 2134 | struct ath_softc *sc = aphy->sc; |
Sujith | 0c98de6 | 2009-03-03 10:16:45 +0530 | [diff] [blame] | 2135 | |
Sujith | 3d83261 | 2009-08-21 12:00:28 +0530 | [diff] [blame] | 2136 | mutex_lock(&sc->mutex); |
Jouni Malinen | 8089cc4 | 2009-03-03 19:23:38 +0200 | [diff] [blame] | 2137 | if (ath9k_wiphy_scanning(sc)) { |
Jouni Malinen | 8089cc4 | 2009-03-03 19:23:38 +0200 | [diff] [blame] | 2138 | /* |
Luis R. Rodriguez | 3088833 | 2010-07-27 16:33:06 -0400 | [diff] [blame] | 2139 | * There is a race here in mac80211 but fixing it requires |
| 2140 | * we revisit how we handle the scan complete callback. |
| 2141 | * After mac80211 fixes we will not have configured hardware |
| 2142 | * to the home channel nor would we have configured the RX |
| 2143 | * filter yet. |
Jouni Malinen | 8089cc4 | 2009-03-03 19:23:38 +0200 | [diff] [blame] | 2144 | */ |
Sujith | 3d83261 | 2009-08-21 12:00:28 +0530 | [diff] [blame] | 2145 | mutex_unlock(&sc->mutex); |
Jouni Malinen | 8089cc4 | 2009-03-03 19:23:38 +0200 | [diff] [blame] | 2146 | return; |
| 2147 | } |
| 2148 | |
| 2149 | aphy->state = ATH_WIPHY_SCAN; |
| 2150 | ath9k_wiphy_pause_all_forced(sc, aphy); |
Sujith | 3d83261 | 2009-08-21 12:00:28 +0530 | [diff] [blame] | 2151 | mutex_unlock(&sc->mutex); |
Sujith | 0c98de6 | 2009-03-03 10:16:45 +0530 | [diff] [blame] | 2152 | } |
| 2153 | |
Luis R. Rodriguez | 3088833 | 2010-07-27 16:33:06 -0400 | [diff] [blame] | 2154 | /* |
| 2155 | * XXX: this requires a revisit after the driver |
| 2156 | * scan_complete gets moved to another place/removed in mac80211. |
| 2157 | */ |
Sujith | 0c98de6 | 2009-03-03 10:16:45 +0530 | [diff] [blame] | 2158 | static void ath9k_sw_scan_complete(struct ieee80211_hw *hw) |
| 2159 | { |
Jouni Malinen | bce048d | 2009-03-03 19:23:28 +0200 | [diff] [blame] | 2160 | struct ath_wiphy *aphy = hw->priv; |
| 2161 | struct ath_softc *sc = aphy->sc; |
Sujith | 0c98de6 | 2009-03-03 10:16:45 +0530 | [diff] [blame] | 2162 | |
Sujith | 3d83261 | 2009-08-21 12:00:28 +0530 | [diff] [blame] | 2163 | mutex_lock(&sc->mutex); |
Jouni Malinen | 8089cc4 | 2009-03-03 19:23:38 +0200 | [diff] [blame] | 2164 | aphy->state = ATH_WIPHY_ACTIVE; |
Sujith | 3d83261 | 2009-08-21 12:00:28 +0530 | [diff] [blame] | 2165 | mutex_unlock(&sc->mutex); |
Sujith | 0c98de6 | 2009-03-03 10:16:45 +0530 | [diff] [blame] | 2166 | } |
| 2167 | |
Felix Fietkau | e239d85 | 2010-01-15 02:34:58 +0100 | [diff] [blame] | 2168 | static void ath9k_set_coverage_class(struct ieee80211_hw *hw, u8 coverage_class) |
| 2169 | { |
| 2170 | struct ath_wiphy *aphy = hw->priv; |
| 2171 | struct ath_softc *sc = aphy->sc; |
| 2172 | struct ath_hw *ah = sc->sc_ah; |
| 2173 | |
| 2174 | mutex_lock(&sc->mutex); |
| 2175 | ah->coverage_class = coverage_class; |
| 2176 | ath9k_hw_init_global_settings(ah); |
| 2177 | mutex_unlock(&sc->mutex); |
| 2178 | } |
| 2179 | |
Gabor Juhos | 6baff7f | 2009-01-14 20:17:06 +0100 | [diff] [blame] | 2180 | struct ieee80211_ops ath9k_ops = { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2181 | .tx = ath9k_tx, |
| 2182 | .start = ath9k_start, |
| 2183 | .stop = ath9k_stop, |
| 2184 | .add_interface = ath9k_add_interface, |
| 2185 | .remove_interface = ath9k_remove_interface, |
| 2186 | .config = ath9k_config, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2187 | .configure_filter = ath9k_configure_filter, |
Johannes Berg | 4ca7786 | 2010-02-19 19:06:56 +0100 | [diff] [blame] | 2188 | .sta_add = ath9k_sta_add, |
| 2189 | .sta_remove = ath9k_sta_remove, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2190 | .conf_tx = ath9k_conf_tx, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2191 | .bss_info_changed = ath9k_bss_info_changed, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2192 | .set_key = ath9k_set_key, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2193 | .get_tsf = ath9k_get_tsf, |
Alina Friedrichsen | 3b5d665 | 2009-01-24 07:09:59 +0100 | [diff] [blame] | 2194 | .set_tsf = ath9k_set_tsf, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2195 | .reset_tsf = ath9k_reset_tsf, |
Johannes Berg | 4233df6 | 2008-10-13 13:35:05 +0200 | [diff] [blame] | 2196 | .ampdu_action = ath9k_ampdu_action, |
Benoit Papillault | 62dad5b | 2010-04-28 00:08:24 +0200 | [diff] [blame] | 2197 | .get_survey = ath9k_get_survey, |
Sujith | 0c98de6 | 2009-03-03 10:16:45 +0530 | [diff] [blame] | 2198 | .sw_scan_start = ath9k_sw_scan_start, |
| 2199 | .sw_scan_complete = ath9k_sw_scan_complete, |
Johannes Berg | 3b319aa | 2009-06-13 14:50:26 +0530 | [diff] [blame] | 2200 | .rfkill_poll = ath9k_rfkill_poll_state, |
Felix Fietkau | e239d85 | 2010-01-15 02:34:58 +0100 | [diff] [blame] | 2201 | .set_coverage_class = ath9k_set_coverage_class, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2202 | }; |