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