Felix Fietkau | fbbcd14 | 2014-06-11 16:17:49 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014 Qualcomm Atheros, Inc. |
| 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 | |
| 17 | #include "ath9k.h" |
| 18 | |
| 19 | /* Set/change channels. If the channel is really being changed, it's done |
| 20 | * by reseting the chip. To accomplish this we must first cleanup any pending |
| 21 | * DMA, then restart stuff. |
| 22 | */ |
| 23 | static int ath_set_channel(struct ath_softc *sc) |
| 24 | { |
| 25 | struct ath_hw *ah = sc->sc_ah; |
| 26 | struct ath_common *common = ath9k_hw_common(ah); |
| 27 | struct ieee80211_hw *hw = sc->hw; |
| 28 | struct ath9k_channel *hchan; |
| 29 | struct cfg80211_chan_def *chandef = &sc->cur_chan->chandef; |
| 30 | struct ieee80211_channel *chan = chandef->chan; |
| 31 | int pos = chan->hw_value; |
| 32 | int old_pos = -1; |
| 33 | int r; |
| 34 | |
| 35 | if (test_bit(ATH_OP_INVALID, &common->op_flags)) |
| 36 | return -EIO; |
| 37 | |
| 38 | if (ah->curchan) |
| 39 | old_pos = ah->curchan - &ah->channels[0]; |
| 40 | |
| 41 | ath_dbg(common, CONFIG, "Set channel: %d MHz width: %d\n", |
| 42 | chan->center_freq, chandef->width); |
| 43 | |
| 44 | /* update survey stats for the old channel before switching */ |
| 45 | spin_lock_bh(&common->cc_lock); |
| 46 | ath_update_survey_stats(sc); |
| 47 | spin_unlock_bh(&common->cc_lock); |
| 48 | |
| 49 | ath9k_cmn_get_channel(hw, ah, chandef); |
| 50 | |
| 51 | /* If the operating channel changes, change the survey in-use flags |
| 52 | * along with it. |
| 53 | * Reset the survey data for the new channel, unless we're switching |
| 54 | * back to the operating channel from an off-channel operation. |
| 55 | */ |
| 56 | if (!sc->cur_chan->offchannel && sc->cur_survey != &sc->survey[pos]) { |
| 57 | if (sc->cur_survey) |
| 58 | sc->cur_survey->filled &= ~SURVEY_INFO_IN_USE; |
| 59 | |
| 60 | sc->cur_survey = &sc->survey[pos]; |
| 61 | |
| 62 | memset(sc->cur_survey, 0, sizeof(struct survey_info)); |
| 63 | sc->cur_survey->filled |= SURVEY_INFO_IN_USE; |
| 64 | } else if (!(sc->survey[pos].filled & SURVEY_INFO_IN_USE)) { |
| 65 | memset(&sc->survey[pos], 0, sizeof(struct survey_info)); |
| 66 | } |
| 67 | |
| 68 | hchan = &sc->sc_ah->channels[pos]; |
Sujith Manoharan | 5555c95 | 2014-10-17 07:40:11 +0530 | [diff] [blame] | 69 | r = ath_reset(sc, hchan); |
Felix Fietkau | fbbcd14 | 2014-06-11 16:17:49 +0530 | [diff] [blame] | 70 | if (r) |
| 71 | return r; |
| 72 | |
| 73 | /* The most recent snapshot of channel->noisefloor for the old |
| 74 | * channel is only available after the hardware reset. Copy it to |
| 75 | * the survey stats now. |
| 76 | */ |
| 77 | if (old_pos >= 0) |
| 78 | ath_update_survey_nf(sc, old_pos); |
| 79 | |
| 80 | /* Enable radar pulse detection if on a DFS channel. Spectral |
| 81 | * scanning and radar detection can not be used concurrently. |
| 82 | */ |
| 83 | if (hw->conf.radar_enabled) { |
| 84 | u32 rxfilter; |
| 85 | |
Felix Fietkau | fbbcd14 | 2014-06-11 16:17:49 +0530 | [diff] [blame] | 86 | rxfilter = ath9k_hw_getrxfilter(ah); |
| 87 | rxfilter |= ATH9K_RX_FILTER_PHYRADAR | |
| 88 | ATH9K_RX_FILTER_PHYERR; |
| 89 | ath9k_hw_setrxfilter(ah, rxfilter); |
| 90 | ath_dbg(common, DFS, "DFS enabled at freq %d\n", |
| 91 | chan->center_freq); |
| 92 | } else { |
| 93 | /* perform spectral scan if requested. */ |
| 94 | if (test_bit(ATH_OP_SCANNING, &common->op_flags) && |
| 95 | sc->spectral_mode == SPECTRAL_CHANSCAN) |
| 96 | ath9k_spectral_scan_trigger(hw); |
| 97 | } |
| 98 | |
| 99 | return 0; |
| 100 | } |
| 101 | |
| 102 | void ath_chanctx_init(struct ath_softc *sc) |
| 103 | { |
| 104 | struct ath_chanctx *ctx; |
| 105 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 106 | struct ieee80211_supported_band *sband; |
| 107 | struct ieee80211_channel *chan; |
Felix Fietkau | 0453531 | 2014-06-11 16:17:51 +0530 | [diff] [blame] | 108 | int i, j; |
Felix Fietkau | fbbcd14 | 2014-06-11 16:17:49 +0530 | [diff] [blame] | 109 | |
| 110 | sband = &common->sbands[IEEE80211_BAND_2GHZ]; |
| 111 | if (!sband->n_channels) |
| 112 | sband = &common->sbands[IEEE80211_BAND_5GHZ]; |
| 113 | |
| 114 | chan = &sband->channels[0]; |
| 115 | for (i = 0; i < ATH9K_NUM_CHANCTX; i++) { |
| 116 | ctx = &sc->chanctx[i]; |
| 117 | cfg80211_chandef_create(&ctx->chandef, chan, NL80211_CHAN_HT20); |
| 118 | INIT_LIST_HEAD(&ctx->vifs); |
Felix Fietkau | bc7e1be | 2014-06-11 16:17:50 +0530 | [diff] [blame] | 119 | ctx->txpower = ATH_TXPOWER_MAX; |
Sujith Manoharan | 2fae0d9 | 2014-10-17 07:40:15 +0530 | [diff] [blame] | 120 | ctx->flush_timeout = HZ / 5; /* 200ms */ |
Felix Fietkau | 0453531 | 2014-06-11 16:17:51 +0530 | [diff] [blame] | 121 | for (j = 0; j < ARRAY_SIZE(ctx->acq); j++) |
| 122 | INIT_LIST_HEAD(&ctx->acq[j]); |
Felix Fietkau | fbbcd14 | 2014-06-11 16:17:49 +0530 | [diff] [blame] | 123 | } |
Felix Fietkau | fbbcd14 | 2014-06-11 16:17:49 +0530 | [diff] [blame] | 124 | } |
| 125 | |
Felix Fietkau | bff1176 | 2014-06-11 16:17:52 +0530 | [diff] [blame] | 126 | void ath_chanctx_set_channel(struct ath_softc *sc, struct ath_chanctx *ctx, |
| 127 | struct cfg80211_chan_def *chandef) |
| 128 | { |
Sujith Manoharan | 4c7e9ae | 2014-08-24 21:16:13 +0530 | [diff] [blame] | 129 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Felix Fietkau | bff1176 | 2014-06-11 16:17:52 +0530 | [diff] [blame] | 130 | bool cur_chan; |
| 131 | |
| 132 | spin_lock_bh(&sc->chan_lock); |
| 133 | if (chandef) |
| 134 | memcpy(&ctx->chandef, chandef, sizeof(*chandef)); |
| 135 | cur_chan = sc->cur_chan == ctx; |
| 136 | spin_unlock_bh(&sc->chan_lock); |
| 137 | |
Sujith Manoharan | 4c7e9ae | 2014-08-24 21:16:13 +0530 | [diff] [blame] | 138 | if (!cur_chan) { |
| 139 | ath_dbg(common, CHAN_CTX, |
| 140 | "Current context differs from the new context\n"); |
Felix Fietkau | bff1176 | 2014-06-11 16:17:52 +0530 | [diff] [blame] | 141 | return; |
Sujith Manoharan | 4c7e9ae | 2014-08-24 21:16:13 +0530 | [diff] [blame] | 142 | } |
Felix Fietkau | bff1176 | 2014-06-11 16:17:52 +0530 | [diff] [blame] | 143 | |
| 144 | ath_set_channel(sc); |
Felix Fietkau | fbbcd14 | 2014-06-11 16:17:49 +0530 | [diff] [blame] | 145 | } |
Felix Fietkau | 78b2194 | 2014-06-11 16:17:55 +0530 | [diff] [blame] | 146 | |
Sujith Manoharan | 27babf9 | 2014-08-23 13:29:16 +0530 | [diff] [blame] | 147 | #ifdef CONFIG_ATH9K_CHANNEL_CONTEXT |
| 148 | |
Sujith Manoharan | 26103b8 | 2014-10-17 07:40:21 +0530 | [diff] [blame] | 149 | /*************/ |
| 150 | /* Utilities */ |
| 151 | /*************/ |
| 152 | |
| 153 | struct ath_chanctx* ath_is_go_chanctx_present(struct ath_softc *sc) |
| 154 | { |
| 155 | struct ath_chanctx *ctx; |
| 156 | struct ath_vif *avp; |
| 157 | struct ieee80211_vif *vif; |
| 158 | |
| 159 | spin_lock_bh(&sc->chan_lock); |
| 160 | |
| 161 | ath_for_each_chanctx(sc, ctx) { |
| 162 | if (!ctx->active) |
| 163 | continue; |
| 164 | |
| 165 | list_for_each_entry(avp, &ctx->vifs, list) { |
| 166 | vif = avp->vif; |
| 167 | |
| 168 | if (ieee80211_vif_type_p2p(vif) == NL80211_IFTYPE_P2P_GO) { |
| 169 | spin_unlock_bh(&sc->chan_lock); |
| 170 | return ctx; |
| 171 | } |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | spin_unlock_bh(&sc->chan_lock); |
| 176 | return NULL; |
| 177 | } |
| 178 | |
Sujith Manoharan | 0e08b5f | 2014-08-23 13:29:19 +0530 | [diff] [blame] | 179 | /**********************************************************/ |
| 180 | /* Functions to handle the channel context state machine. */ |
| 181 | /**********************************************************/ |
| 182 | |
Sujith Manoharan | 27babf9 | 2014-08-23 13:29:16 +0530 | [diff] [blame] | 183 | static const char *offchannel_state_string(enum ath_offchannel_state state) |
| 184 | { |
Sujith Manoharan | 27babf9 | 2014-08-23 13:29:16 +0530 | [diff] [blame] | 185 | switch (state) { |
| 186 | case_rtn_string(ATH_OFFCHANNEL_IDLE); |
| 187 | case_rtn_string(ATH_OFFCHANNEL_PROBE_SEND); |
| 188 | case_rtn_string(ATH_OFFCHANNEL_PROBE_WAIT); |
| 189 | case_rtn_string(ATH_OFFCHANNEL_SUSPEND); |
| 190 | case_rtn_string(ATH_OFFCHANNEL_ROC_START); |
| 191 | case_rtn_string(ATH_OFFCHANNEL_ROC_WAIT); |
| 192 | case_rtn_string(ATH_OFFCHANNEL_ROC_DONE); |
| 193 | default: |
| 194 | return "unknown"; |
| 195 | } |
| 196 | } |
| 197 | |
Sujith Manoharan | 5a8cbec | 2014-08-24 21:16:11 +0530 | [diff] [blame] | 198 | static const char *chanctx_event_string(enum ath_chanctx_event ev) |
| 199 | { |
| 200 | switch (ev) { |
| 201 | case_rtn_string(ATH_CHANCTX_EVENT_BEACON_PREPARE); |
| 202 | case_rtn_string(ATH_CHANCTX_EVENT_BEACON_SENT); |
| 203 | case_rtn_string(ATH_CHANCTX_EVENT_TSF_TIMER); |
| 204 | case_rtn_string(ATH_CHANCTX_EVENT_BEACON_RECEIVED); |
Sujith Manoharan | b8f9279 | 2014-10-17 07:40:09 +0530 | [diff] [blame] | 205 | case_rtn_string(ATH_CHANCTX_EVENT_AUTHORIZED); |
Sujith Manoharan | 5a8cbec | 2014-08-24 21:16:11 +0530 | [diff] [blame] | 206 | case_rtn_string(ATH_CHANCTX_EVENT_SWITCH); |
| 207 | case_rtn_string(ATH_CHANCTX_EVENT_ASSIGN); |
| 208 | case_rtn_string(ATH_CHANCTX_EVENT_UNASSIGN); |
| 209 | case_rtn_string(ATH_CHANCTX_EVENT_CHANGE); |
| 210 | case_rtn_string(ATH_CHANCTX_EVENT_ENABLE_MULTICHANNEL); |
| 211 | default: |
| 212 | return "unknown"; |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | static const char *chanctx_state_string(enum ath_chanctx_state state) |
| 217 | { |
| 218 | switch (state) { |
| 219 | case_rtn_string(ATH_CHANCTX_STATE_IDLE); |
| 220 | case_rtn_string(ATH_CHANCTX_STATE_WAIT_FOR_BEACON); |
| 221 | case_rtn_string(ATH_CHANCTX_STATE_WAIT_FOR_TIMER); |
| 222 | case_rtn_string(ATH_CHANCTX_STATE_SWITCH); |
| 223 | case_rtn_string(ATH_CHANCTX_STATE_FORCE_ACTIVE); |
| 224 | default: |
| 225 | return "unknown"; |
| 226 | } |
| 227 | } |
| 228 | |
Sujith Manoharan | a09798f | 2014-08-23 13:29:21 +0530 | [diff] [blame] | 229 | void ath_chanctx_check_active(struct ath_softc *sc, struct ath_chanctx *ctx) |
| 230 | { |
| 231 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Sujith Manoharan | 67259d5 | 2014-10-17 07:40:16 +0530 | [diff] [blame] | 232 | struct ath_chanctx *ictx; |
Sujith Manoharan | a09798f | 2014-08-23 13:29:21 +0530 | [diff] [blame] | 233 | struct ath_vif *avp; |
| 234 | bool active = false; |
| 235 | u8 n_active = 0; |
| 236 | |
| 237 | if (!ctx) |
| 238 | return; |
| 239 | |
Sujith Manoharan | 290c8a7 | 2014-10-17 07:40:17 +0530 | [diff] [blame] | 240 | if (ctx == &sc->offchannel.chan) { |
| 241 | spin_lock_bh(&sc->chan_lock); |
| 242 | |
| 243 | if (likely(sc->sched.channel_switch_time)) |
| 244 | ctx->flush_timeout = |
| 245 | usecs_to_jiffies(sc->sched.channel_switch_time); |
| 246 | else |
| 247 | ctx->flush_timeout = |
| 248 | msecs_to_jiffies(10); |
| 249 | |
| 250 | spin_unlock_bh(&sc->chan_lock); |
| 251 | |
| 252 | /* |
| 253 | * There is no need to iterate over the |
| 254 | * active/assigned channel contexts if |
| 255 | * the current context is offchannel. |
| 256 | */ |
| 257 | return; |
| 258 | } |
| 259 | |
Sujith Manoharan | 67259d5 | 2014-10-17 07:40:16 +0530 | [diff] [blame] | 260 | ictx = ctx; |
| 261 | |
Sujith Manoharan | a09798f | 2014-08-23 13:29:21 +0530 | [diff] [blame] | 262 | list_for_each_entry(avp, &ctx->vifs, list) { |
| 263 | struct ieee80211_vif *vif = avp->vif; |
| 264 | |
| 265 | switch (vif->type) { |
| 266 | case NL80211_IFTYPE_P2P_CLIENT: |
| 267 | case NL80211_IFTYPE_STATION: |
Sujith Manoharan | cb35582 | 2014-09-17 14:45:56 +0530 | [diff] [blame] | 268 | if (avp->assoc) |
Sujith Manoharan | a09798f | 2014-08-23 13:29:21 +0530 | [diff] [blame] | 269 | active = true; |
| 270 | break; |
| 271 | default: |
| 272 | active = true; |
| 273 | break; |
| 274 | } |
| 275 | } |
| 276 | ctx->active = active; |
| 277 | |
| 278 | ath_for_each_chanctx(sc, ctx) { |
| 279 | if (!ctx->assigned || list_empty(&ctx->vifs)) |
| 280 | continue; |
| 281 | n_active++; |
| 282 | } |
| 283 | |
Sujith Manoharan | 67259d5 | 2014-10-17 07:40:16 +0530 | [diff] [blame] | 284 | spin_lock_bh(&sc->chan_lock); |
| 285 | |
Sujith Manoharan | a09798f | 2014-08-23 13:29:21 +0530 | [diff] [blame] | 286 | if (n_active <= 1) { |
Sujith Manoharan | 67259d5 | 2014-10-17 07:40:16 +0530 | [diff] [blame] | 287 | ictx->flush_timeout = HZ / 5; |
Sujith Manoharan | a09798f | 2014-08-23 13:29:21 +0530 | [diff] [blame] | 288 | clear_bit(ATH_OP_MULTI_CHANNEL, &common->op_flags); |
Sujith Manoharan | 67259d5 | 2014-10-17 07:40:16 +0530 | [diff] [blame] | 289 | spin_unlock_bh(&sc->chan_lock); |
Sujith Manoharan | a09798f | 2014-08-23 13:29:21 +0530 | [diff] [blame] | 290 | return; |
| 291 | } |
Sujith Manoharan | 67259d5 | 2014-10-17 07:40:16 +0530 | [diff] [blame] | 292 | |
| 293 | ictx->flush_timeout = usecs_to_jiffies(sc->sched.channel_switch_time); |
| 294 | |
| 295 | if (test_and_set_bit(ATH_OP_MULTI_CHANNEL, &common->op_flags)) { |
| 296 | spin_unlock_bh(&sc->chan_lock); |
Sujith Manoharan | a09798f | 2014-08-23 13:29:21 +0530 | [diff] [blame] | 297 | return; |
Sujith Manoharan | 67259d5 | 2014-10-17 07:40:16 +0530 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | spin_unlock_bh(&sc->chan_lock); |
Sujith Manoharan | a09798f | 2014-08-23 13:29:21 +0530 | [diff] [blame] | 301 | |
| 302 | if (ath9k_is_chanctx_enabled()) { |
| 303 | ath_chanctx_event(sc, NULL, |
| 304 | ATH_CHANCTX_EVENT_ENABLE_MULTICHANNEL); |
| 305 | } |
| 306 | } |
| 307 | |
Felix Fietkau | 58b5737 | 2014-06-11 16:18:08 +0530 | [diff] [blame] | 308 | static struct ath_chanctx * |
| 309 | ath_chanctx_get_next(struct ath_softc *sc, struct ath_chanctx *ctx) |
| 310 | { |
| 311 | int idx = ctx - &sc->chanctx[0]; |
| 312 | |
| 313 | return &sc->chanctx[!idx]; |
| 314 | } |
| 315 | |
| 316 | static void ath_chanctx_adjust_tbtt_delta(struct ath_softc *sc) |
| 317 | { |
| 318 | struct ath_chanctx *prev, *cur; |
| 319 | struct timespec ts; |
| 320 | u32 cur_tsf, prev_tsf, beacon_int; |
| 321 | s32 offset; |
| 322 | |
| 323 | beacon_int = TU_TO_USEC(sc->cur_chan->beacon.beacon_interval); |
| 324 | |
| 325 | cur = sc->cur_chan; |
| 326 | prev = ath_chanctx_get_next(sc, cur); |
| 327 | |
Sujith Manoharan | 7f30eac | 2014-09-15 11:25:51 +0530 | [diff] [blame] | 328 | if (!prev->switch_after_beacon) |
| 329 | return; |
| 330 | |
Felix Fietkau | 58b5737 | 2014-06-11 16:18:08 +0530 | [diff] [blame] | 331 | getrawmonotonic(&ts); |
| 332 | cur_tsf = (u32) cur->tsf_val + |
| 333 | ath9k_hw_get_tsf_offset(&cur->tsf_ts, &ts); |
| 334 | |
| 335 | prev_tsf = prev->last_beacon - (u32) prev->tsf_val + cur_tsf; |
| 336 | prev_tsf -= ath9k_hw_get_tsf_offset(&prev->tsf_ts, &ts); |
| 337 | |
| 338 | /* Adjust the TSF time of the AP chanctx to keep its beacons |
| 339 | * at half beacon interval offset relative to the STA chanctx. |
| 340 | */ |
| 341 | offset = cur_tsf - prev_tsf; |
| 342 | |
| 343 | /* Ignore stale data or spurious timestamps */ |
| 344 | if (offset < 0 || offset > 3 * beacon_int) |
| 345 | return; |
| 346 | |
| 347 | offset = beacon_int / 2 - (offset % beacon_int); |
| 348 | prev->tsf_val += offset; |
| 349 | } |
| 350 | |
Felix Fietkau | 42eda11 | 2014-06-11 16:18:14 +0530 | [diff] [blame] | 351 | /* Configure the TSF based hardware timer for a channel switch. |
| 352 | * Also set up backup software timer, in case the gen timer fails. |
| 353 | * This could be caused by a hardware reset. |
| 354 | */ |
| 355 | static void ath_chanctx_setup_timer(struct ath_softc *sc, u32 tsf_time) |
| 356 | { |
Sujith Manoharan | 878066e | 2014-08-27 12:07:24 +0530 | [diff] [blame] | 357 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Felix Fietkau | 42eda11 | 2014-06-11 16:18:14 +0530 | [diff] [blame] | 358 | struct ath_hw *ah = sc->sc_ah; |
| 359 | |
| 360 | ath9k_hw_gen_timer_start(ah, sc->p2p_ps_timer, tsf_time, 1000000); |
| 361 | tsf_time -= ath9k_hw_gettsf32(ah); |
| 362 | tsf_time = msecs_to_jiffies(tsf_time / 1000) + 1; |
Sujith Manoharan | 1a7c5b7 | 2014-08-27 12:07:25 +0530 | [diff] [blame] | 363 | mod_timer(&sc->sched.timer, jiffies + tsf_time); |
Sujith Manoharan | 878066e | 2014-08-27 12:07:24 +0530 | [diff] [blame] | 364 | |
| 365 | ath_dbg(common, CHAN_CTX, |
| 366 | "Setup chanctx timer with timeout: %d ms\n", jiffies_to_msecs(tsf_time)); |
Felix Fietkau | 42eda11 | 2014-06-11 16:18:14 +0530 | [diff] [blame] | 367 | } |
| 368 | |
Felix Fietkau | 748299f | 2014-06-11 16:18:04 +0530 | [diff] [blame] | 369 | void ath_chanctx_event(struct ath_softc *sc, struct ieee80211_vif *vif, |
| 370 | enum ath_chanctx_event ev) |
| 371 | { |
| 372 | struct ath_hw *ah = sc->sc_ah; |
Felix Fietkau | 58b5737 | 2014-06-11 16:18:08 +0530 | [diff] [blame] | 373 | struct ath_common *common = ath9k_hw_common(ah); |
Felix Fietkau | 7414863 | 2014-06-11 16:18:11 +0530 | [diff] [blame] | 374 | struct ath_beacon_config *cur_conf; |
Felix Fietkau | 3ae07d3 | 2014-06-11 16:18:06 +0530 | [diff] [blame] | 375 | struct ath_vif *avp = NULL; |
Felix Fietkau | 73fa2f2 | 2014-06-11 16:18:10 +0530 | [diff] [blame] | 376 | struct ath_chanctx *ctx; |
Felix Fietkau | 748299f | 2014-06-11 16:18:04 +0530 | [diff] [blame] | 377 | u32 tsf_time; |
Felix Fietkau | ec70abe | 2014-06-11 16:18:12 +0530 | [diff] [blame] | 378 | u32 beacon_int; |
Felix Fietkau | 3ae07d3 | 2014-06-11 16:18:06 +0530 | [diff] [blame] | 379 | |
| 380 | if (vif) |
| 381 | avp = (struct ath_vif *) vif->drv_priv; |
Felix Fietkau | 748299f | 2014-06-11 16:18:04 +0530 | [diff] [blame] | 382 | |
| 383 | spin_lock_bh(&sc->chan_lock); |
| 384 | |
Sujith Manoharan | 878066e | 2014-08-27 12:07:24 +0530 | [diff] [blame] | 385 | ath_dbg(common, CHAN_CTX, "cur_chan: %d MHz, event: %s, state: %s\n", |
| 386 | sc->cur_chan->chandef.center_freq1, |
| 387 | chanctx_event_string(ev), |
| 388 | chanctx_state_string(sc->sched.state)); |
| 389 | |
Felix Fietkau | 748299f | 2014-06-11 16:18:04 +0530 | [diff] [blame] | 390 | switch (ev) { |
| 391 | case ATH_CHANCTX_EVENT_BEACON_PREPARE: |
Felix Fietkau | 3ae07d3 | 2014-06-11 16:18:06 +0530 | [diff] [blame] | 392 | if (avp->offchannel_duration) |
| 393 | avp->offchannel_duration = 0; |
| 394 | |
Sujith Manoharan | 878066e | 2014-08-27 12:07:24 +0530 | [diff] [blame] | 395 | if (avp->chanctx != sc->cur_chan) { |
| 396 | ath_dbg(common, CHAN_CTX, |
| 397 | "Contexts differ, not preparing beacon\n"); |
Felix Fietkau | 73fa2f2 | 2014-06-11 16:18:10 +0530 | [diff] [blame] | 398 | break; |
Sujith Manoharan | 878066e | 2014-08-27 12:07:24 +0530 | [diff] [blame] | 399 | } |
Felix Fietkau | 73fa2f2 | 2014-06-11 16:18:10 +0530 | [diff] [blame] | 400 | |
Sujith Manoharan | 367b341 | 2014-09-05 09:50:57 +0530 | [diff] [blame] | 401 | if (sc->sched.offchannel_pending && !sc->sched.wait_switch) { |
Felix Fietkau | 73fa2f2 | 2014-06-11 16:18:10 +0530 | [diff] [blame] | 402 | sc->sched.offchannel_pending = false; |
| 403 | sc->next_chan = &sc->offchannel.chan; |
| 404 | sc->sched.state = ATH_CHANCTX_STATE_WAIT_FOR_BEACON; |
Sujith Manoharan | 878066e | 2014-08-27 12:07:24 +0530 | [diff] [blame] | 405 | ath_dbg(common, CHAN_CTX, |
| 406 | "Setting offchannel_pending to false\n"); |
Felix Fietkau | 73fa2f2 | 2014-06-11 16:18:10 +0530 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | ctx = ath_chanctx_get_next(sc, sc->cur_chan); |
| 410 | if (ctx->active && sc->sched.state == ATH_CHANCTX_STATE_IDLE) { |
| 411 | sc->next_chan = ctx; |
| 412 | sc->sched.state = ATH_CHANCTX_STATE_WAIT_FOR_BEACON; |
Sujith Manoharan | 878066e | 2014-08-27 12:07:24 +0530 | [diff] [blame] | 413 | ath_dbg(common, CHAN_CTX, |
| 414 | "Set next context, move chanctx state to WAIT_FOR_BEACON\n"); |
Felix Fietkau | 73fa2f2 | 2014-06-11 16:18:10 +0530 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | /* if the timer missed its window, use the next interval */ |
Sujith Manoharan | 878066e | 2014-08-27 12:07:24 +0530 | [diff] [blame] | 418 | if (sc->sched.state == ATH_CHANCTX_STATE_WAIT_FOR_TIMER) { |
Felix Fietkau | 73fa2f2 | 2014-06-11 16:18:10 +0530 | [diff] [blame] | 419 | sc->sched.state = ATH_CHANCTX_STATE_WAIT_FOR_BEACON; |
Sujith Manoharan | 878066e | 2014-08-27 12:07:24 +0530 | [diff] [blame] | 420 | ath_dbg(common, CHAN_CTX, |
| 421 | "Move chanctx state from WAIT_FOR_TIMER to WAIT_FOR_BEACON\n"); |
| 422 | } |
Felix Fietkau | 73fa2f2 | 2014-06-11 16:18:10 +0530 | [diff] [blame] | 423 | |
Sujith Manoharan | c6500ea | 2014-10-17 07:40:22 +0530 | [diff] [blame^] | 424 | if (sc->sched.mgd_prepare_tx) |
| 425 | sc->sched.state = ATH_CHANCTX_STATE_WAIT_FOR_BEACON; |
| 426 | |
Sujith Manoharan | 8890d05 | 2014-10-17 07:40:14 +0530 | [diff] [blame] | 427 | /* |
| 428 | * When a context becomes inactive, for example, |
| 429 | * disassociation of a station context, the NoA |
| 430 | * attribute needs to be removed from subsequent |
| 431 | * beacons. |
| 432 | */ |
| 433 | if (!ctx->active && avp->noa_duration && |
| 434 | sc->sched.state != ATH_CHANCTX_STATE_WAIT_FOR_BEACON) { |
| 435 | avp->noa_duration = 0; |
| 436 | avp->periodic_noa = false; |
| 437 | |
| 438 | ath_dbg(common, CHAN_CTX, |
| 439 | "Clearing NoA schedule\n"); |
| 440 | } |
| 441 | |
Felix Fietkau | 748299f | 2014-06-11 16:18:04 +0530 | [diff] [blame] | 442 | if (sc->sched.state != ATH_CHANCTX_STATE_WAIT_FOR_BEACON) |
| 443 | break; |
| 444 | |
Sujith Manoharan | 878066e | 2014-08-27 12:07:24 +0530 | [diff] [blame] | 445 | ath_dbg(common, CHAN_CTX, "Preparing beacon for vif: %pM\n", vif->addr); |
| 446 | |
Felix Fietkau | 748299f | 2014-06-11 16:18:04 +0530 | [diff] [blame] | 447 | sc->sched.beacon_pending = true; |
| 448 | sc->sched.next_tbtt = REG_READ(ah, AR_NEXT_TBTT_TIMER); |
Felix Fietkau | 3ae07d3 | 2014-06-11 16:18:06 +0530 | [diff] [blame] | 449 | |
Felix Fietkau | 7414863 | 2014-06-11 16:18:11 +0530 | [diff] [blame] | 450 | cur_conf = &sc->cur_chan->beacon; |
Felix Fietkau | ec70abe | 2014-06-11 16:18:12 +0530 | [diff] [blame] | 451 | beacon_int = TU_TO_USEC(cur_conf->beacon_interval); |
| 452 | |
Felix Fietkau | 3ae07d3 | 2014-06-11 16:18:06 +0530 | [diff] [blame] | 453 | /* defer channel switch by a quarter beacon interval */ |
Felix Fietkau | ec70abe | 2014-06-11 16:18:12 +0530 | [diff] [blame] | 454 | tsf_time = sc->sched.next_tbtt + beacon_int / 4; |
Felix Fietkau | 3ae07d3 | 2014-06-11 16:18:06 +0530 | [diff] [blame] | 455 | sc->sched.switch_start_time = tsf_time; |
Felix Fietkau | 58b5737 | 2014-06-11 16:18:08 +0530 | [diff] [blame] | 456 | sc->cur_chan->last_beacon = sc->sched.next_tbtt; |
Felix Fietkau | 3ae07d3 | 2014-06-11 16:18:06 +0530 | [diff] [blame] | 457 | |
Sujith Manoharan | d0975ed | 2014-09-10 19:15:57 +0530 | [diff] [blame] | 458 | /* |
| 459 | * If an offchannel switch is scheduled to happen after |
| 460 | * a beacon transmission, update the NoA with one-shot |
| 461 | * values and increment the index. |
| 462 | */ |
| 463 | if (sc->next_chan == &sc->offchannel.chan) { |
| 464 | avp->noa_index++; |
Felix Fietkau | 3ae07d3 | 2014-06-11 16:18:06 +0530 | [diff] [blame] | 465 | avp->offchannel_start = tsf_time; |
Sujith Manoharan | d0975ed | 2014-09-10 19:15:57 +0530 | [diff] [blame] | 466 | avp->offchannel_duration = sc->sched.offchannel_duration; |
| 467 | |
| 468 | ath_dbg(common, CHAN_CTX, |
| 469 | "offchannel noa_duration: %d, noa_start: %d, noa_index: %d\n", |
| 470 | avp->offchannel_duration, |
| 471 | avp->offchannel_start, |
| 472 | avp->noa_index); |
| 473 | |
| 474 | /* |
| 475 | * When multiple contexts are active, the NoA |
| 476 | * has to be recalculated and advertised after |
| 477 | * an offchannel operation. |
| 478 | */ |
| 479 | if (ctx->active && avp->noa_duration) |
| 480 | avp->noa_duration = 0; |
| 481 | |
| 482 | break; |
Felix Fietkau | 3ae07d3 | 2014-06-11 16:18:06 +0530 | [diff] [blame] | 483 | } |
| 484 | |
Sujith Manoharan | 167bf96d | 2014-09-10 19:16:00 +0530 | [diff] [blame] | 485 | /* |
| 486 | * Clear the extend_absence flag if it had been |
| 487 | * set during the previous beacon transmission, |
| 488 | * since we need to revert to the normal NoA |
| 489 | * schedule. |
| 490 | */ |
| 491 | if (ctx->active && sc->sched.extend_absence) { |
| 492 | avp->noa_duration = 0; |
| 493 | sc->sched.extend_absence = false; |
| 494 | } |
| 495 | |
| 496 | /* If at least two consecutive beacons were missed on the STA |
| 497 | * chanctx, stay on the STA channel for one extra beacon period, |
| 498 | * to resync the timer properly. |
| 499 | */ |
| 500 | if (ctx->active && sc->sched.beacon_miss >= 2) { |
| 501 | avp->noa_duration = 0; |
| 502 | sc->sched.extend_absence = true; |
| 503 | } |
Sujith Manoharan | a2b2860 | 2014-09-15 11:25:50 +0530 | [diff] [blame] | 504 | |
Sujith Manoharan | d0975ed | 2014-09-10 19:15:57 +0530 | [diff] [blame] | 505 | /* Prevent wrap-around issues */ |
| 506 | if (avp->noa_duration && tsf_time - avp->noa_start > BIT(30)) |
| 507 | avp->noa_duration = 0; |
Sujith Manoharan | 878066e | 2014-08-27 12:07:24 +0530 | [diff] [blame] | 508 | |
Sujith Manoharan | d0975ed | 2014-09-10 19:15:57 +0530 | [diff] [blame] | 509 | /* |
| 510 | * If multiple contexts are active, start periodic |
| 511 | * NoA and increment the index for the first |
| 512 | * announcement. |
| 513 | */ |
| 514 | if (ctx->active && |
| 515 | (!avp->noa_duration || sc->sched.force_noa_update)) { |
| 516 | avp->noa_index++; |
| 517 | avp->noa_start = tsf_time; |
Sujith Manoharan | d0975ed | 2014-09-10 19:15:57 +0530 | [diff] [blame] | 518 | |
Sujith Manoharan | 167bf96d | 2014-09-10 19:16:00 +0530 | [diff] [blame] | 519 | if (sc->sched.extend_absence) |
| 520 | avp->noa_duration = (3 * beacon_int / 2) + |
| 521 | sc->sched.channel_switch_time; |
| 522 | else |
| 523 | avp->noa_duration = |
| 524 | TU_TO_USEC(cur_conf->beacon_interval) / 2 + |
| 525 | sc->sched.channel_switch_time; |
| 526 | |
| 527 | if (test_bit(ATH_OP_SCANNING, &common->op_flags) || |
| 528 | sc->sched.extend_absence) |
Sujith Manoharan | d0975ed | 2014-09-10 19:15:57 +0530 | [diff] [blame] | 529 | avp->periodic_noa = false; |
| 530 | else |
| 531 | avp->periodic_noa = true; |
| 532 | |
| 533 | ath_dbg(common, CHAN_CTX, |
| 534 | "noa_duration: %d, noa_start: %d, noa_index: %d, periodic: %d\n", |
| 535 | avp->noa_duration, |
| 536 | avp->noa_start, |
| 537 | avp->noa_index, |
| 538 | avp->periodic_noa); |
| 539 | } |
| 540 | |
| 541 | if (ctx->active && sc->sched.force_noa_update) |
| 542 | sc->sched.force_noa_update = false; |
Sujith Manoharan | 878066e | 2014-08-27 12:07:24 +0530 | [diff] [blame] | 543 | |
Felix Fietkau | 748299f | 2014-06-11 16:18:04 +0530 | [diff] [blame] | 544 | break; |
| 545 | case ATH_CHANCTX_EVENT_BEACON_SENT: |
Sujith Manoharan | 878066e | 2014-08-27 12:07:24 +0530 | [diff] [blame] | 546 | if (!sc->sched.beacon_pending) { |
| 547 | ath_dbg(common, CHAN_CTX, |
| 548 | "No pending beacon\n"); |
Felix Fietkau | 748299f | 2014-06-11 16:18:04 +0530 | [diff] [blame] | 549 | break; |
Sujith Manoharan | 878066e | 2014-08-27 12:07:24 +0530 | [diff] [blame] | 550 | } |
Felix Fietkau | 748299f | 2014-06-11 16:18:04 +0530 | [diff] [blame] | 551 | |
| 552 | sc->sched.beacon_pending = false; |
Sujith Manoharan | c6500ea | 2014-10-17 07:40:22 +0530 | [diff] [blame^] | 553 | |
| 554 | if (sc->sched.mgd_prepare_tx) { |
| 555 | sc->sched.mgd_prepare_tx = false; |
| 556 | complete(&sc->go_beacon); |
| 557 | ath_dbg(common, CHAN_CTX, |
| 558 | "Beacon sent, complete go_beacon\n"); |
| 559 | break; |
| 560 | } |
| 561 | |
Felix Fietkau | 748299f | 2014-06-11 16:18:04 +0530 | [diff] [blame] | 562 | if (sc->sched.state != ATH_CHANCTX_STATE_WAIT_FOR_BEACON) |
| 563 | break; |
| 564 | |
Sujith Manoharan | 878066e | 2014-08-27 12:07:24 +0530 | [diff] [blame] | 565 | ath_dbg(common, CHAN_CTX, |
| 566 | "Move chanctx state to WAIT_FOR_TIMER\n"); |
| 567 | |
Felix Fietkau | 748299f | 2014-06-11 16:18:04 +0530 | [diff] [blame] | 568 | sc->sched.state = ATH_CHANCTX_STATE_WAIT_FOR_TIMER; |
Felix Fietkau | 42eda11 | 2014-06-11 16:18:14 +0530 | [diff] [blame] | 569 | ath_chanctx_setup_timer(sc, sc->sched.switch_start_time); |
Felix Fietkau | 748299f | 2014-06-11 16:18:04 +0530 | [diff] [blame] | 570 | break; |
| 571 | case ATH_CHANCTX_EVENT_TSF_TIMER: |
| 572 | if (sc->sched.state != ATH_CHANCTX_STATE_WAIT_FOR_TIMER) |
| 573 | break; |
| 574 | |
Felix Fietkau | ec70abe | 2014-06-11 16:18:12 +0530 | [diff] [blame] | 575 | if (!sc->cur_chan->switch_after_beacon && |
| 576 | sc->sched.beacon_pending) |
| 577 | sc->sched.beacon_miss++; |
| 578 | |
Sujith Manoharan | 878066e | 2014-08-27 12:07:24 +0530 | [diff] [blame] | 579 | ath_dbg(common, CHAN_CTX, |
| 580 | "Move chanctx state to SWITCH\n"); |
| 581 | |
Felix Fietkau | 748299f | 2014-06-11 16:18:04 +0530 | [diff] [blame] | 582 | sc->sched.state = ATH_CHANCTX_STATE_SWITCH; |
| 583 | ieee80211_queue_work(sc->hw, &sc->chanctx_work); |
| 584 | break; |
Felix Fietkau | 58b5737 | 2014-06-11 16:18:08 +0530 | [diff] [blame] | 585 | case ATH_CHANCTX_EVENT_BEACON_RECEIVED: |
Felix Fietkau | 73fa2f2 | 2014-06-11 16:18:10 +0530 | [diff] [blame] | 586 | if (!test_bit(ATH_OP_MULTI_CHANNEL, &common->op_flags) || |
| 587 | sc->cur_chan == &sc->offchannel.chan) |
Felix Fietkau | 58b5737 | 2014-06-11 16:18:08 +0530 | [diff] [blame] | 588 | break; |
| 589 | |
Felix Fietkau | ec70abe | 2014-06-11 16:18:12 +0530 | [diff] [blame] | 590 | sc->sched.beacon_pending = false; |
| 591 | sc->sched.beacon_miss = 0; |
Felix Fietkau | a899b67 | 2014-06-11 16:18:13 +0530 | [diff] [blame] | 592 | |
Sujith Manoharan | be247c1 | 2014-10-17 07:40:10 +0530 | [diff] [blame] | 593 | if (sc->sched.state == ATH_CHANCTX_STATE_FORCE_ACTIVE || |
| 594 | !sc->cur_chan->tsf_val) |
| 595 | break; |
| 596 | |
| 597 | ath_chanctx_adjust_tbtt_delta(sc); |
| 598 | |
Felix Fietkau | a899b67 | 2014-06-11 16:18:13 +0530 | [diff] [blame] | 599 | /* TSF time might have been updated by the incoming beacon, |
| 600 | * need update the channel switch timer to reflect the change. |
| 601 | */ |
| 602 | tsf_time = sc->sched.switch_start_time; |
| 603 | tsf_time -= (u32) sc->cur_chan->tsf_val + |
| 604 | ath9k_hw_get_tsf_offset(&sc->cur_chan->tsf_ts, NULL); |
| 605 | tsf_time += ath9k_hw_gettsf32(ah); |
| 606 | |
Felix Fietkau | 42eda11 | 2014-06-11 16:18:14 +0530 | [diff] [blame] | 607 | |
| 608 | ath_chanctx_setup_timer(sc, tsf_time); |
Felix Fietkau | 58b5737 | 2014-06-11 16:18:08 +0530 | [diff] [blame] | 609 | break; |
Sujith Manoharan | b8f9279 | 2014-10-17 07:40:09 +0530 | [diff] [blame] | 610 | case ATH_CHANCTX_EVENT_AUTHORIZED: |
Felix Fietkau | 73fa2f2 | 2014-06-11 16:18:10 +0530 | [diff] [blame] | 611 | if (sc->sched.state != ATH_CHANCTX_STATE_FORCE_ACTIVE || |
| 612 | avp->chanctx != sc->cur_chan) |
| 613 | break; |
| 614 | |
Sujith Manoharan | 878066e | 2014-08-27 12:07:24 +0530 | [diff] [blame] | 615 | ath_dbg(common, CHAN_CTX, |
| 616 | "Move chanctx state from FORCE_ACTIVE to IDLE\n"); |
| 617 | |
Felix Fietkau | 73fa2f2 | 2014-06-11 16:18:10 +0530 | [diff] [blame] | 618 | sc->sched.state = ATH_CHANCTX_STATE_IDLE; |
| 619 | /* fall through */ |
| 620 | case ATH_CHANCTX_EVENT_SWITCH: |
| 621 | if (!test_bit(ATH_OP_MULTI_CHANNEL, &common->op_flags) || |
| 622 | sc->sched.state == ATH_CHANCTX_STATE_FORCE_ACTIVE || |
| 623 | sc->cur_chan->switch_after_beacon || |
| 624 | sc->cur_chan == &sc->offchannel.chan) |
| 625 | break; |
| 626 | |
| 627 | /* If this is a station chanctx, stay active for a half |
| 628 | * beacon period (minus channel switch time) |
| 629 | */ |
| 630 | sc->next_chan = ath_chanctx_get_next(sc, sc->cur_chan); |
Felix Fietkau | 7414863 | 2014-06-11 16:18:11 +0530 | [diff] [blame] | 631 | cur_conf = &sc->cur_chan->beacon; |
Felix Fietkau | 73fa2f2 | 2014-06-11 16:18:10 +0530 | [diff] [blame] | 632 | |
Sujith Manoharan | 878066e | 2014-08-27 12:07:24 +0530 | [diff] [blame] | 633 | ath_dbg(common, CHAN_CTX, |
| 634 | "Move chanctx state to WAIT_FOR_TIMER (event SWITCH)\n"); |
| 635 | |
Felix Fietkau | 73fa2f2 | 2014-06-11 16:18:10 +0530 | [diff] [blame] | 636 | sc->sched.state = ATH_CHANCTX_STATE_WAIT_FOR_TIMER; |
Sujith Manoharan | 367b341 | 2014-09-05 09:50:57 +0530 | [diff] [blame] | 637 | sc->sched.wait_switch = false; |
Felix Fietkau | ec70abe | 2014-06-11 16:18:12 +0530 | [diff] [blame] | 638 | |
| 639 | tsf_time = TU_TO_USEC(cur_conf->beacon_interval) / 2; |
Sujith Manoharan | 167bf96d | 2014-09-10 19:16:00 +0530 | [diff] [blame] | 640 | |
| 641 | if (sc->sched.extend_absence) { |
Felix Fietkau | ec70abe | 2014-06-11 16:18:12 +0530 | [diff] [blame] | 642 | sc->sched.beacon_miss = 0; |
| 643 | tsf_time *= 3; |
| 644 | } |
| 645 | |
Felix Fietkau | 73fa2f2 | 2014-06-11 16:18:10 +0530 | [diff] [blame] | 646 | tsf_time -= sc->sched.channel_switch_time; |
Felix Fietkau | ec70abe | 2014-06-11 16:18:12 +0530 | [diff] [blame] | 647 | tsf_time += ath9k_hw_gettsf32(sc->sc_ah); |
Felix Fietkau | 73fa2f2 | 2014-06-11 16:18:10 +0530 | [diff] [blame] | 648 | sc->sched.switch_start_time = tsf_time; |
| 649 | |
Felix Fietkau | 42eda11 | 2014-06-11 16:18:14 +0530 | [diff] [blame] | 650 | ath_chanctx_setup_timer(sc, tsf_time); |
Felix Fietkau | ec70abe | 2014-06-11 16:18:12 +0530 | [diff] [blame] | 651 | sc->sched.beacon_pending = true; |
Felix Fietkau | 73fa2f2 | 2014-06-11 16:18:10 +0530 | [diff] [blame] | 652 | break; |
| 653 | case ATH_CHANCTX_EVENT_ENABLE_MULTICHANNEL: |
| 654 | if (sc->cur_chan == &sc->offchannel.chan || |
| 655 | sc->cur_chan->switch_after_beacon) |
| 656 | break; |
| 657 | |
| 658 | sc->next_chan = ath_chanctx_get_next(sc, sc->cur_chan); |
| 659 | ieee80211_queue_work(sc->hw, &sc->chanctx_work); |
| 660 | break; |
| 661 | case ATH_CHANCTX_EVENT_UNASSIGN: |
| 662 | if (sc->cur_chan->assigned) { |
| 663 | if (sc->next_chan && !sc->next_chan->assigned && |
| 664 | sc->next_chan != &sc->offchannel.chan) |
| 665 | sc->sched.state = ATH_CHANCTX_STATE_IDLE; |
| 666 | break; |
| 667 | } |
| 668 | |
| 669 | ctx = ath_chanctx_get_next(sc, sc->cur_chan); |
| 670 | sc->sched.state = ATH_CHANCTX_STATE_IDLE; |
| 671 | if (!ctx->assigned) |
| 672 | break; |
| 673 | |
| 674 | sc->next_chan = ctx; |
| 675 | ieee80211_queue_work(sc->hw, &sc->chanctx_work); |
| 676 | break; |
Sujith Manoharan | 02da18b | 2014-08-24 21:16:10 +0530 | [diff] [blame] | 677 | case ATH_CHANCTX_EVENT_ASSIGN: |
Sujith Manoharan | 4c7e9ae | 2014-08-24 21:16:13 +0530 | [diff] [blame] | 678 | /* |
| 679 | * When adding a new channel context, check if a scan |
| 680 | * is in progress and abort it since the addition of |
| 681 | * a new channel context is usually followed by VIF |
| 682 | * assignment, in which case we have to start multi-channel |
| 683 | * operation. |
| 684 | */ |
| 685 | if (test_bit(ATH_OP_SCANNING, &common->op_flags)) { |
| 686 | ath_dbg(common, CHAN_CTX, |
| 687 | "Aborting HW scan to add new context\n"); |
| 688 | |
| 689 | spin_unlock_bh(&sc->chan_lock); |
| 690 | del_timer_sync(&sc->offchannel.timer); |
| 691 | ath_scan_complete(sc, true); |
| 692 | spin_lock_bh(&sc->chan_lock); |
| 693 | } |
Sujith Manoharan | 02da18b | 2014-08-24 21:16:10 +0530 | [diff] [blame] | 694 | break; |
| 695 | case ATH_CHANCTX_EVENT_CHANGE: |
| 696 | break; |
Felix Fietkau | 748299f | 2014-06-11 16:18:04 +0530 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | spin_unlock_bh(&sc->chan_lock); |
| 700 | } |
Sujith Manoharan | dfcbb3e | 2014-08-22 20:39:26 +0530 | [diff] [blame] | 701 | |
Sujith Manoharan | 70b06da | 2014-08-23 13:29:18 +0530 | [diff] [blame] | 702 | void ath_chanctx_beacon_sent_ev(struct ath_softc *sc, |
| 703 | enum ath_chanctx_event ev) |
| 704 | { |
| 705 | if (sc->sched.beacon_pending) |
| 706 | ath_chanctx_event(sc, NULL, ev); |
| 707 | } |
| 708 | |
Sujith Manoharan | a2b2860 | 2014-09-15 11:25:50 +0530 | [diff] [blame] | 709 | void ath_chanctx_beacon_recv_ev(struct ath_softc *sc, |
Sujith Manoharan | 70b06da | 2014-08-23 13:29:18 +0530 | [diff] [blame] | 710 | enum ath_chanctx_event ev) |
| 711 | { |
Sujith Manoharan | 70b06da | 2014-08-23 13:29:18 +0530 | [diff] [blame] | 712 | ath_chanctx_event(sc, NULL, ev); |
| 713 | } |
| 714 | |
Sujith Manoharan | dfcbb3e | 2014-08-22 20:39:26 +0530 | [diff] [blame] | 715 | static int ath_scan_channel_duration(struct ath_softc *sc, |
| 716 | struct ieee80211_channel *chan) |
| 717 | { |
| 718 | struct cfg80211_scan_request *req = sc->offchannel.scan_req; |
| 719 | |
| 720 | if (!req->n_ssids || (chan->flags & IEEE80211_CHAN_NO_IR)) |
| 721 | return (HZ / 9); /* ~110 ms */ |
| 722 | |
| 723 | return (HZ / 16); /* ~60 ms */ |
| 724 | } |
| 725 | |
Sujith Manoharan | 922c943 | 2014-08-23 13:29:15 +0530 | [diff] [blame] | 726 | static void ath_chanctx_switch(struct ath_softc *sc, struct ath_chanctx *ctx, |
| 727 | struct cfg80211_chan_def *chandef) |
| 728 | { |
| 729 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 730 | |
| 731 | spin_lock_bh(&sc->chan_lock); |
| 732 | |
| 733 | if (test_bit(ATH_OP_MULTI_CHANNEL, &common->op_flags) && |
| 734 | (sc->cur_chan != ctx) && (ctx == &sc->offchannel.chan)) { |
Sujith Manoharan | da0162f | 2014-09-05 09:50:56 +0530 | [diff] [blame] | 735 | if (chandef) |
| 736 | ctx->chandef = *chandef; |
Sujith Manoharan | cbc775d | 2014-09-10 19:15:56 +0530 | [diff] [blame] | 737 | |
| 738 | sc->sched.offchannel_pending = true; |
| 739 | sc->sched.wait_switch = true; |
| 740 | sc->sched.offchannel_duration = |
| 741 | jiffies_to_usecs(sc->offchannel.duration) + |
| 742 | sc->sched.channel_switch_time; |
| 743 | |
Sujith Manoharan | 922c943 | 2014-08-23 13:29:15 +0530 | [diff] [blame] | 744 | spin_unlock_bh(&sc->chan_lock); |
Sujith Manoharan | da0162f | 2014-09-05 09:50:56 +0530 | [diff] [blame] | 745 | ath_dbg(common, CHAN_CTX, |
| 746 | "Set offchannel_pending to true\n"); |
Sujith Manoharan | 922c943 | 2014-08-23 13:29:15 +0530 | [diff] [blame] | 747 | return; |
| 748 | } |
| 749 | |
| 750 | sc->next_chan = ctx; |
| 751 | if (chandef) { |
| 752 | ctx->chandef = *chandef; |
| 753 | ath_dbg(common, CHAN_CTX, |
| 754 | "Assigned next_chan to %d MHz\n", chandef->center_freq1); |
| 755 | } |
| 756 | |
| 757 | if (sc->next_chan == &sc->offchannel.chan) { |
| 758 | sc->sched.offchannel_duration = |
Sujith Manoharan | bb628eb | 2014-09-05 08:03:13 +0530 | [diff] [blame] | 759 | jiffies_to_usecs(sc->offchannel.duration) + |
Sujith Manoharan | 922c943 | 2014-08-23 13:29:15 +0530 | [diff] [blame] | 760 | sc->sched.channel_switch_time; |
| 761 | |
| 762 | if (chandef) { |
| 763 | ath_dbg(common, CHAN_CTX, |
| 764 | "Offchannel duration for chan %d MHz : %u\n", |
| 765 | chandef->center_freq1, |
| 766 | sc->sched.offchannel_duration); |
| 767 | } |
| 768 | } |
| 769 | spin_unlock_bh(&sc->chan_lock); |
| 770 | ieee80211_queue_work(sc->hw, &sc->chanctx_work); |
| 771 | } |
| 772 | |
Sujith Manoharan | 344ae6a | 2014-08-23 13:29:13 +0530 | [diff] [blame] | 773 | static void ath_chanctx_offchan_switch(struct ath_softc *sc, |
| 774 | struct ieee80211_channel *chan) |
| 775 | { |
| 776 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 777 | struct cfg80211_chan_def chandef; |
| 778 | |
| 779 | cfg80211_chandef_create(&chandef, chan, NL80211_CHAN_NO_HT); |
| 780 | ath_dbg(common, CHAN_CTX, |
| 781 | "Channel definition created: %d MHz\n", chandef.center_freq1); |
| 782 | |
| 783 | ath_chanctx_switch(sc, &sc->offchannel.chan, &chandef); |
| 784 | } |
| 785 | |
Sujith Manoharan | 98f411b | 2014-08-23 13:29:14 +0530 | [diff] [blame] | 786 | static struct ath_chanctx *ath_chanctx_get_oper_chan(struct ath_softc *sc, |
| 787 | bool active) |
| 788 | { |
| 789 | struct ath_chanctx *ctx; |
| 790 | |
| 791 | ath_for_each_chanctx(sc, ctx) { |
| 792 | if (!ctx->assigned || list_empty(&ctx->vifs)) |
| 793 | continue; |
| 794 | if (active && !ctx->active) |
| 795 | continue; |
| 796 | |
| 797 | if (ctx->switch_after_beacon) |
| 798 | return ctx; |
| 799 | } |
| 800 | |
| 801 | return &sc->chanctx[0]; |
| 802 | } |
| 803 | |
Sujith Manoharan | dfcbb3e | 2014-08-22 20:39:26 +0530 | [diff] [blame] | 804 | static void |
| 805 | ath_scan_next_channel(struct ath_softc *sc) |
| 806 | { |
Sujith Manoharan | bc81d43 | 2014-08-22 20:39:27 +0530 | [diff] [blame] | 807 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Sujith Manoharan | dfcbb3e | 2014-08-22 20:39:26 +0530 | [diff] [blame] | 808 | struct cfg80211_scan_request *req = sc->offchannel.scan_req; |
| 809 | struct ieee80211_channel *chan; |
| 810 | |
| 811 | if (sc->offchannel.scan_idx >= req->n_channels) { |
Sujith Manoharan | bc81d43 | 2014-08-22 20:39:27 +0530 | [diff] [blame] | 812 | ath_dbg(common, CHAN_CTX, |
Sujith Manoharan | 878066e | 2014-08-27 12:07:24 +0530 | [diff] [blame] | 813 | "Moving offchannel state to ATH_OFFCHANNEL_IDLE, " |
| 814 | "scan_idx: %d, n_channels: %d\n", |
Sujith Manoharan | bc81d43 | 2014-08-22 20:39:27 +0530 | [diff] [blame] | 815 | sc->offchannel.scan_idx, |
| 816 | req->n_channels); |
| 817 | |
Sujith Manoharan | dfcbb3e | 2014-08-22 20:39:26 +0530 | [diff] [blame] | 818 | sc->offchannel.state = ATH_OFFCHANNEL_IDLE; |
| 819 | ath_chanctx_switch(sc, ath_chanctx_get_oper_chan(sc, false), |
| 820 | NULL); |
| 821 | return; |
| 822 | } |
| 823 | |
Sujith Manoharan | bc81d43 | 2014-08-22 20:39:27 +0530 | [diff] [blame] | 824 | ath_dbg(common, CHAN_CTX, |
Sujith Manoharan | 878066e | 2014-08-27 12:07:24 +0530 | [diff] [blame] | 825 | "Moving offchannel state to ATH_OFFCHANNEL_PROBE_SEND, scan_idx: %d\n", |
Sujith Manoharan | bc81d43 | 2014-08-22 20:39:27 +0530 | [diff] [blame] | 826 | sc->offchannel.scan_idx); |
| 827 | |
Sujith Manoharan | dfcbb3e | 2014-08-22 20:39:26 +0530 | [diff] [blame] | 828 | chan = req->channels[sc->offchannel.scan_idx++]; |
| 829 | sc->offchannel.duration = ath_scan_channel_duration(sc, chan); |
| 830 | sc->offchannel.state = ATH_OFFCHANNEL_PROBE_SEND; |
Sujith Manoharan | bc81d43 | 2014-08-22 20:39:27 +0530 | [diff] [blame] | 831 | |
Sujith Manoharan | dfcbb3e | 2014-08-22 20:39:26 +0530 | [diff] [blame] | 832 | ath_chanctx_offchan_switch(sc, chan); |
| 833 | } |
| 834 | |
| 835 | void ath_offchannel_next(struct ath_softc *sc) |
| 836 | { |
| 837 | struct ieee80211_vif *vif; |
| 838 | |
| 839 | if (sc->offchannel.scan_req) { |
| 840 | vif = sc->offchannel.scan_vif; |
| 841 | sc->offchannel.chan.txpower = vif->bss_conf.txpower; |
| 842 | ath_scan_next_channel(sc); |
| 843 | } else if (sc->offchannel.roc_vif) { |
| 844 | vif = sc->offchannel.roc_vif; |
| 845 | sc->offchannel.chan.txpower = vif->bss_conf.txpower; |
Sujith Manoharan | bb628eb | 2014-09-05 08:03:13 +0530 | [diff] [blame] | 846 | sc->offchannel.duration = |
| 847 | msecs_to_jiffies(sc->offchannel.roc_duration); |
Sujith Manoharan | dfcbb3e | 2014-08-22 20:39:26 +0530 | [diff] [blame] | 848 | sc->offchannel.state = ATH_OFFCHANNEL_ROC_START; |
| 849 | ath_chanctx_offchan_switch(sc, sc->offchannel.roc_chan); |
| 850 | } else { |
| 851 | ath_chanctx_switch(sc, ath_chanctx_get_oper_chan(sc, false), |
| 852 | NULL); |
| 853 | sc->offchannel.state = ATH_OFFCHANNEL_IDLE; |
| 854 | if (sc->ps_idle) |
| 855 | ath_cancel_work(sc); |
| 856 | } |
| 857 | } |
| 858 | |
| 859 | void ath_roc_complete(struct ath_softc *sc, bool abort) |
| 860 | { |
Sujith Manoharan | 4b60af4 | 2014-10-02 06:33:12 +0530 | [diff] [blame] | 861 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 862 | |
| 863 | if (abort) |
| 864 | ath_dbg(common, CHAN_CTX, "RoC aborted\n"); |
| 865 | else |
| 866 | ath_dbg(common, CHAN_CTX, "RoC expired\n"); |
| 867 | |
Sujith Manoharan | dfcbb3e | 2014-08-22 20:39:26 +0530 | [diff] [blame] | 868 | sc->offchannel.roc_vif = NULL; |
| 869 | sc->offchannel.roc_chan = NULL; |
| 870 | if (!abort) |
| 871 | ieee80211_remain_on_channel_expired(sc->hw); |
| 872 | ath_offchannel_next(sc); |
| 873 | ath9k_ps_restore(sc); |
| 874 | } |
| 875 | |
| 876 | void ath_scan_complete(struct ath_softc *sc, bool abort) |
| 877 | { |
| 878 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 879 | |
Sujith Manoharan | bc81d43 | 2014-08-22 20:39:27 +0530 | [diff] [blame] | 880 | if (abort) |
| 881 | ath_dbg(common, CHAN_CTX, "HW scan aborted\n"); |
| 882 | else |
| 883 | ath_dbg(common, CHAN_CTX, "HW scan complete\n"); |
| 884 | |
Sujith Manoharan | dfcbb3e | 2014-08-22 20:39:26 +0530 | [diff] [blame] | 885 | sc->offchannel.scan_req = NULL; |
| 886 | sc->offchannel.scan_vif = NULL; |
| 887 | sc->offchannel.state = ATH_OFFCHANNEL_IDLE; |
| 888 | ieee80211_scan_completed(sc->hw, abort); |
| 889 | clear_bit(ATH_OP_SCANNING, &common->op_flags); |
Sujith Manoharan | d0975ed | 2014-09-10 19:15:57 +0530 | [diff] [blame] | 890 | spin_lock_bh(&sc->chan_lock); |
| 891 | if (test_bit(ATH_OP_MULTI_CHANNEL, &common->op_flags)) |
| 892 | sc->sched.force_noa_update = true; |
| 893 | spin_unlock_bh(&sc->chan_lock); |
Sujith Manoharan | dfcbb3e | 2014-08-22 20:39:26 +0530 | [diff] [blame] | 894 | ath_offchannel_next(sc); |
| 895 | ath9k_ps_restore(sc); |
| 896 | } |
| 897 | |
| 898 | static void ath_scan_send_probe(struct ath_softc *sc, |
| 899 | struct cfg80211_ssid *ssid) |
| 900 | { |
| 901 | struct cfg80211_scan_request *req = sc->offchannel.scan_req; |
| 902 | struct ieee80211_vif *vif = sc->offchannel.scan_vif; |
| 903 | struct ath_tx_control txctl = {}; |
| 904 | struct sk_buff *skb; |
| 905 | struct ieee80211_tx_info *info; |
| 906 | int band = sc->offchannel.chan.chandef.chan->band; |
| 907 | |
| 908 | skb = ieee80211_probereq_get(sc->hw, vif, |
| 909 | ssid->ssid, ssid->ssid_len, req->ie_len); |
| 910 | if (!skb) |
| 911 | return; |
| 912 | |
| 913 | info = IEEE80211_SKB_CB(skb); |
| 914 | if (req->no_cck) |
| 915 | info->flags |= IEEE80211_TX_CTL_NO_CCK_RATE; |
| 916 | |
| 917 | if (req->ie_len) |
| 918 | memcpy(skb_put(skb, req->ie_len), req->ie, req->ie_len); |
| 919 | |
| 920 | skb_set_queue_mapping(skb, IEEE80211_AC_VO); |
| 921 | |
| 922 | if (!ieee80211_tx_prepare_skb(sc->hw, vif, skb, band, NULL)) |
| 923 | goto error; |
| 924 | |
| 925 | txctl.txq = sc->tx.txq_map[IEEE80211_AC_VO]; |
| 926 | txctl.force_channel = true; |
| 927 | if (ath_tx_start(sc->hw, skb, &txctl)) |
| 928 | goto error; |
| 929 | |
| 930 | return; |
| 931 | |
| 932 | error: |
| 933 | ieee80211_free_txskb(sc->hw, skb); |
| 934 | } |
| 935 | |
| 936 | static void ath_scan_channel_start(struct ath_softc *sc) |
| 937 | { |
Sujith Manoharan | bc81d43 | 2014-08-22 20:39:27 +0530 | [diff] [blame] | 938 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Sujith Manoharan | dfcbb3e | 2014-08-22 20:39:26 +0530 | [diff] [blame] | 939 | struct cfg80211_scan_request *req = sc->offchannel.scan_req; |
| 940 | int i; |
| 941 | |
| 942 | if (!(sc->cur_chan->chandef.chan->flags & IEEE80211_CHAN_NO_IR) && |
| 943 | req->n_ssids) { |
| 944 | for (i = 0; i < req->n_ssids; i++) |
| 945 | ath_scan_send_probe(sc, &req->ssids[i]); |
| 946 | |
| 947 | } |
| 948 | |
Sujith Manoharan | bc81d43 | 2014-08-22 20:39:27 +0530 | [diff] [blame] | 949 | ath_dbg(common, CHAN_CTX, |
Sujith Manoharan | 878066e | 2014-08-27 12:07:24 +0530 | [diff] [blame] | 950 | "Moving offchannel state to ATH_OFFCHANNEL_PROBE_WAIT\n"); |
Sujith Manoharan | bc81d43 | 2014-08-22 20:39:27 +0530 | [diff] [blame] | 951 | |
Sujith Manoharan | dfcbb3e | 2014-08-22 20:39:26 +0530 | [diff] [blame] | 952 | sc->offchannel.state = ATH_OFFCHANNEL_PROBE_WAIT; |
| 953 | mod_timer(&sc->offchannel.timer, jiffies + sc->offchannel.duration); |
| 954 | } |
| 955 | |
Sujith Manoharan | 705d0bf | 2014-08-23 13:29:06 +0530 | [diff] [blame] | 956 | static void ath_chanctx_timer(unsigned long data) |
| 957 | { |
| 958 | struct ath_softc *sc = (struct ath_softc *) data; |
Sujith Manoharan | 878066e | 2014-08-27 12:07:24 +0530 | [diff] [blame] | 959 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 960 | |
| 961 | ath_dbg(common, CHAN_CTX, |
| 962 | "Channel context timer invoked\n"); |
Sujith Manoharan | 705d0bf | 2014-08-23 13:29:06 +0530 | [diff] [blame] | 963 | |
| 964 | ath_chanctx_event(sc, NULL, ATH_CHANCTX_EVENT_TSF_TIMER); |
| 965 | } |
| 966 | |
| 967 | static void ath_offchannel_timer(unsigned long data) |
Sujith Manoharan | dfcbb3e | 2014-08-22 20:39:26 +0530 | [diff] [blame] | 968 | { |
| 969 | struct ath_softc *sc = (struct ath_softc *)data; |
| 970 | struct ath_chanctx *ctx; |
Sujith Manoharan | bc81d43 | 2014-08-22 20:39:27 +0530 | [diff] [blame] | 971 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 972 | |
Sujith Manoharan | 878066e | 2014-08-27 12:07:24 +0530 | [diff] [blame] | 973 | ath_dbg(common, CHAN_CTX, "%s: offchannel state: %s\n", |
Sujith Manoharan | bc81d43 | 2014-08-22 20:39:27 +0530 | [diff] [blame] | 974 | __func__, offchannel_state_string(sc->offchannel.state)); |
Sujith Manoharan | dfcbb3e | 2014-08-22 20:39:26 +0530 | [diff] [blame] | 975 | |
| 976 | switch (sc->offchannel.state) { |
| 977 | case ATH_OFFCHANNEL_PROBE_WAIT: |
| 978 | if (!sc->offchannel.scan_req) |
| 979 | return; |
| 980 | |
| 981 | /* get first active channel context */ |
| 982 | ctx = ath_chanctx_get_oper_chan(sc, true); |
| 983 | if (ctx->active) { |
Sujith Manoharan | 878066e | 2014-08-27 12:07:24 +0530 | [diff] [blame] | 984 | ath_dbg(common, CHAN_CTX, |
| 985 | "Switch to oper/active context, " |
| 986 | "move offchannel state to ATH_OFFCHANNEL_SUSPEND\n"); |
| 987 | |
Sujith Manoharan | dfcbb3e | 2014-08-22 20:39:26 +0530 | [diff] [blame] | 988 | sc->offchannel.state = ATH_OFFCHANNEL_SUSPEND; |
| 989 | ath_chanctx_switch(sc, ctx, NULL); |
| 990 | mod_timer(&sc->offchannel.timer, jiffies + HZ / 10); |
| 991 | break; |
| 992 | } |
| 993 | /* fall through */ |
| 994 | case ATH_OFFCHANNEL_SUSPEND: |
| 995 | if (!sc->offchannel.scan_req) |
| 996 | return; |
| 997 | |
| 998 | ath_scan_next_channel(sc); |
| 999 | break; |
| 1000 | case ATH_OFFCHANNEL_ROC_START: |
| 1001 | case ATH_OFFCHANNEL_ROC_WAIT: |
| 1002 | ctx = ath_chanctx_get_oper_chan(sc, false); |
| 1003 | sc->offchannel.state = ATH_OFFCHANNEL_ROC_DONE; |
| 1004 | ath_chanctx_switch(sc, ctx, NULL); |
| 1005 | break; |
| 1006 | default: |
| 1007 | break; |
| 1008 | } |
| 1009 | } |
Sujith Manoharan | 2471adf | 2014-08-22 20:39:29 +0530 | [diff] [blame] | 1010 | |
Sujith Manoharan | 6d7cbd7 | 2014-08-23 13:29:10 +0530 | [diff] [blame] | 1011 | static bool |
| 1012 | ath_chanctx_send_vif_ps_frame(struct ath_softc *sc, struct ath_vif *avp, |
| 1013 | bool powersave) |
| 1014 | { |
| 1015 | struct ieee80211_vif *vif = avp->vif; |
| 1016 | struct ieee80211_sta *sta = NULL; |
| 1017 | struct ieee80211_hdr_3addr *nullfunc; |
| 1018 | struct ath_tx_control txctl; |
| 1019 | struct sk_buff *skb; |
| 1020 | int band = sc->cur_chan->chandef.chan->band; |
| 1021 | |
| 1022 | switch (vif->type) { |
| 1023 | case NL80211_IFTYPE_STATION: |
Sujith Manoharan | cb35582 | 2014-09-17 14:45:56 +0530 | [diff] [blame] | 1024 | if (!avp->assoc) |
Sujith Manoharan | 6d7cbd7 | 2014-08-23 13:29:10 +0530 | [diff] [blame] | 1025 | return false; |
| 1026 | |
| 1027 | skb = ieee80211_nullfunc_get(sc->hw, vif); |
| 1028 | if (!skb) |
| 1029 | return false; |
| 1030 | |
| 1031 | nullfunc = (struct ieee80211_hdr_3addr *) skb->data; |
| 1032 | if (powersave) |
| 1033 | nullfunc->frame_control |= |
| 1034 | cpu_to_le16(IEEE80211_FCTL_PM); |
| 1035 | |
| 1036 | skb_set_queue_mapping(skb, IEEE80211_AC_VO); |
| 1037 | if (!ieee80211_tx_prepare_skb(sc->hw, vif, skb, band, &sta)) { |
| 1038 | dev_kfree_skb_any(skb); |
| 1039 | return false; |
| 1040 | } |
| 1041 | break; |
| 1042 | default: |
| 1043 | return false; |
| 1044 | } |
| 1045 | |
| 1046 | memset(&txctl, 0, sizeof(txctl)); |
| 1047 | txctl.txq = sc->tx.txq_map[IEEE80211_AC_VO]; |
| 1048 | txctl.sta = sta; |
| 1049 | txctl.force_channel = true; |
| 1050 | if (ath_tx_start(sc->hw, skb, &txctl)) { |
| 1051 | ieee80211_free_txskb(sc->hw, skb); |
| 1052 | return false; |
| 1053 | } |
| 1054 | |
| 1055 | return true; |
| 1056 | } |
| 1057 | |
| 1058 | static bool |
| 1059 | ath_chanctx_send_ps_frame(struct ath_softc *sc, bool powersave) |
| 1060 | { |
| 1061 | struct ath_vif *avp; |
| 1062 | bool sent = false; |
| 1063 | |
| 1064 | rcu_read_lock(); |
| 1065 | list_for_each_entry(avp, &sc->cur_chan->vifs, list) { |
| 1066 | if (ath_chanctx_send_vif_ps_frame(sc, avp, powersave)) |
| 1067 | sent = true; |
| 1068 | } |
| 1069 | rcu_read_unlock(); |
| 1070 | |
| 1071 | return sent; |
| 1072 | } |
| 1073 | |
| 1074 | static bool ath_chanctx_defer_switch(struct ath_softc *sc) |
| 1075 | { |
Sujith Manoharan | 878066e | 2014-08-27 12:07:24 +0530 | [diff] [blame] | 1076 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 1077 | |
Sujith Manoharan | 6d7cbd7 | 2014-08-23 13:29:10 +0530 | [diff] [blame] | 1078 | if (sc->cur_chan == &sc->offchannel.chan) |
| 1079 | return false; |
| 1080 | |
| 1081 | switch (sc->sched.state) { |
| 1082 | case ATH_CHANCTX_STATE_SWITCH: |
| 1083 | return false; |
| 1084 | case ATH_CHANCTX_STATE_IDLE: |
| 1085 | if (!sc->cur_chan->switch_after_beacon) |
| 1086 | return false; |
| 1087 | |
Sujith Manoharan | 878066e | 2014-08-27 12:07:24 +0530 | [diff] [blame] | 1088 | ath_dbg(common, CHAN_CTX, |
| 1089 | "Defer switch, set chanctx state to WAIT_FOR_BEACON\n"); |
| 1090 | |
Sujith Manoharan | 6d7cbd7 | 2014-08-23 13:29:10 +0530 | [diff] [blame] | 1091 | sc->sched.state = ATH_CHANCTX_STATE_WAIT_FOR_BEACON; |
| 1092 | break; |
| 1093 | default: |
| 1094 | break; |
| 1095 | } |
| 1096 | |
| 1097 | return true; |
| 1098 | } |
| 1099 | |
Sujith Manoharan | 55254ee | 2014-08-23 13:29:11 +0530 | [diff] [blame] | 1100 | static void ath_offchannel_channel_change(struct ath_softc *sc) |
| 1101 | { |
| 1102 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 1103 | |
Sujith Manoharan | 878066e | 2014-08-27 12:07:24 +0530 | [diff] [blame] | 1104 | ath_dbg(common, CHAN_CTX, "%s: offchannel state: %s\n", |
Sujith Manoharan | 55254ee | 2014-08-23 13:29:11 +0530 | [diff] [blame] | 1105 | __func__, offchannel_state_string(sc->offchannel.state)); |
| 1106 | |
| 1107 | switch (sc->offchannel.state) { |
| 1108 | case ATH_OFFCHANNEL_PROBE_SEND: |
| 1109 | if (!sc->offchannel.scan_req) |
| 1110 | return; |
| 1111 | |
| 1112 | if (sc->cur_chan->chandef.chan != |
| 1113 | sc->offchannel.chan.chandef.chan) |
| 1114 | return; |
| 1115 | |
| 1116 | ath_scan_channel_start(sc); |
| 1117 | break; |
| 1118 | case ATH_OFFCHANNEL_IDLE: |
| 1119 | if (!sc->offchannel.scan_req) |
| 1120 | return; |
| 1121 | |
| 1122 | ath_scan_complete(sc, false); |
| 1123 | break; |
| 1124 | case ATH_OFFCHANNEL_ROC_START: |
| 1125 | if (sc->cur_chan != &sc->offchannel.chan) |
| 1126 | break; |
| 1127 | |
| 1128 | sc->offchannel.state = ATH_OFFCHANNEL_ROC_WAIT; |
Sujith Manoharan | bb628eb | 2014-09-05 08:03:13 +0530 | [diff] [blame] | 1129 | mod_timer(&sc->offchannel.timer, |
| 1130 | jiffies + sc->offchannel.duration); |
Sujith Manoharan | 55254ee | 2014-08-23 13:29:11 +0530 | [diff] [blame] | 1131 | ieee80211_ready_on_channel(sc->hw); |
| 1132 | break; |
| 1133 | case ATH_OFFCHANNEL_ROC_DONE: |
| 1134 | ath_roc_complete(sc, false); |
| 1135 | break; |
| 1136 | default: |
| 1137 | break; |
| 1138 | } |
| 1139 | } |
| 1140 | |
Sujith Manoharan | 6d7cbd7 | 2014-08-23 13:29:10 +0530 | [diff] [blame] | 1141 | void ath_chanctx_set_next(struct ath_softc *sc, bool force) |
| 1142 | { |
Sujith Manoharan | 878066e | 2014-08-27 12:07:24 +0530 | [diff] [blame] | 1143 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Sujith Manoharan | e2cba8d | 2014-10-02 06:33:20 +0530 | [diff] [blame] | 1144 | struct ath_chanctx *old_ctx; |
Sujith Manoharan | 6d7cbd7 | 2014-08-23 13:29:10 +0530 | [diff] [blame] | 1145 | struct timespec ts; |
| 1146 | bool measure_time = false; |
| 1147 | bool send_ps = false; |
Sujith Manoharan | e2cba8d | 2014-10-02 06:33:20 +0530 | [diff] [blame] | 1148 | bool queues_stopped = false; |
Sujith Manoharan | 6d7cbd7 | 2014-08-23 13:29:10 +0530 | [diff] [blame] | 1149 | |
| 1150 | spin_lock_bh(&sc->chan_lock); |
| 1151 | if (!sc->next_chan) { |
| 1152 | spin_unlock_bh(&sc->chan_lock); |
| 1153 | return; |
| 1154 | } |
| 1155 | |
| 1156 | if (!force && ath_chanctx_defer_switch(sc)) { |
| 1157 | spin_unlock_bh(&sc->chan_lock); |
| 1158 | return; |
| 1159 | } |
| 1160 | |
Sujith Manoharan | 878066e | 2014-08-27 12:07:24 +0530 | [diff] [blame] | 1161 | ath_dbg(common, CHAN_CTX, |
| 1162 | "%s: current: %d MHz, next: %d MHz\n", |
| 1163 | __func__, |
| 1164 | sc->cur_chan->chandef.center_freq1, |
| 1165 | sc->next_chan->chandef.center_freq1); |
| 1166 | |
Sujith Manoharan | 6d7cbd7 | 2014-08-23 13:29:10 +0530 | [diff] [blame] | 1167 | if (sc->cur_chan != sc->next_chan) { |
Sujith Manoharan | 878066e | 2014-08-27 12:07:24 +0530 | [diff] [blame] | 1168 | ath_dbg(common, CHAN_CTX, |
| 1169 | "Stopping current chanctx: %d\n", |
| 1170 | sc->cur_chan->chandef.center_freq1); |
Sujith Manoharan | 6d7cbd7 | 2014-08-23 13:29:10 +0530 | [diff] [blame] | 1171 | sc->cur_chan->stopped = true; |
| 1172 | spin_unlock_bh(&sc->chan_lock); |
| 1173 | |
| 1174 | if (sc->next_chan == &sc->offchannel.chan) { |
| 1175 | getrawmonotonic(&ts); |
| 1176 | measure_time = true; |
| 1177 | } |
Sujith Manoharan | e2cba8d | 2014-10-02 06:33:20 +0530 | [diff] [blame] | 1178 | |
| 1179 | ath9k_chanctx_stop_queues(sc, sc->cur_chan); |
| 1180 | queues_stopped = true; |
| 1181 | |
Sujith Manoharan | e2d389b | 2014-10-17 07:40:18 +0530 | [diff] [blame] | 1182 | __ath9k_flush(sc->hw, ~0, true, false); |
Sujith Manoharan | 6d7cbd7 | 2014-08-23 13:29:10 +0530 | [diff] [blame] | 1183 | |
| 1184 | if (ath_chanctx_send_ps_frame(sc, true)) |
Sujith Manoharan | e2d389b | 2014-10-17 07:40:18 +0530 | [diff] [blame] | 1185 | __ath9k_flush(sc->hw, BIT(IEEE80211_AC_VO), |
| 1186 | false, false); |
Sujith Manoharan | 6d7cbd7 | 2014-08-23 13:29:10 +0530 | [diff] [blame] | 1187 | |
| 1188 | send_ps = true; |
| 1189 | spin_lock_bh(&sc->chan_lock); |
| 1190 | |
| 1191 | if (sc->cur_chan != &sc->offchannel.chan) { |
| 1192 | getrawmonotonic(&sc->cur_chan->tsf_ts); |
| 1193 | sc->cur_chan->tsf_val = ath9k_hw_gettsf64(sc->sc_ah); |
| 1194 | } |
| 1195 | } |
Sujith Manoharan | e2cba8d | 2014-10-02 06:33:20 +0530 | [diff] [blame] | 1196 | old_ctx = sc->cur_chan; |
Sujith Manoharan | 6d7cbd7 | 2014-08-23 13:29:10 +0530 | [diff] [blame] | 1197 | sc->cur_chan = sc->next_chan; |
| 1198 | sc->cur_chan->stopped = false; |
| 1199 | sc->next_chan = NULL; |
Sujith Manoharan | 124130d | 2014-09-10 19:15:58 +0530 | [diff] [blame] | 1200 | |
| 1201 | if (!sc->sched.offchannel_pending) |
| 1202 | sc->sched.offchannel_duration = 0; |
| 1203 | |
Sujith Manoharan | 6d7cbd7 | 2014-08-23 13:29:10 +0530 | [diff] [blame] | 1204 | if (sc->sched.state != ATH_CHANCTX_STATE_FORCE_ACTIVE) |
| 1205 | sc->sched.state = ATH_CHANCTX_STATE_IDLE; |
| 1206 | |
| 1207 | spin_unlock_bh(&sc->chan_lock); |
| 1208 | |
| 1209 | if (sc->sc_ah->chip_fullsleep || |
| 1210 | memcmp(&sc->cur_chandef, &sc->cur_chan->chandef, |
| 1211 | sizeof(sc->cur_chandef))) { |
Sujith Manoharan | 878066e | 2014-08-27 12:07:24 +0530 | [diff] [blame] | 1212 | ath_dbg(common, CHAN_CTX, |
| 1213 | "%s: Set channel %d MHz\n", |
| 1214 | __func__, sc->cur_chan->chandef.center_freq1); |
Sujith Manoharan | 6d7cbd7 | 2014-08-23 13:29:10 +0530 | [diff] [blame] | 1215 | ath_set_channel(sc); |
| 1216 | if (measure_time) |
| 1217 | sc->sched.channel_switch_time = |
| 1218 | ath9k_hw_get_tsf_offset(&ts, NULL); |
Sujith Manoharan | e2cba8d | 2014-10-02 06:33:20 +0530 | [diff] [blame] | 1219 | /* |
| 1220 | * A reset will ensure that all queues are woken up, |
| 1221 | * so there is no need to awaken them again. |
| 1222 | */ |
| 1223 | goto out; |
Sujith Manoharan | 6d7cbd7 | 2014-08-23 13:29:10 +0530 | [diff] [blame] | 1224 | } |
Sujith Manoharan | e2cba8d | 2014-10-02 06:33:20 +0530 | [diff] [blame] | 1225 | |
| 1226 | if (queues_stopped) |
| 1227 | ath9k_chanctx_wake_queues(sc, old_ctx); |
| 1228 | out: |
Sujith Manoharan | 6d7cbd7 | 2014-08-23 13:29:10 +0530 | [diff] [blame] | 1229 | if (send_ps) |
| 1230 | ath_chanctx_send_ps_frame(sc, false); |
| 1231 | |
| 1232 | ath_offchannel_channel_change(sc); |
| 1233 | ath_chanctx_event(sc, NULL, ATH_CHANCTX_EVENT_SWITCH); |
| 1234 | } |
| 1235 | |
Sujith Manoharan | 0e62f8b | 2014-08-23 13:29:08 +0530 | [diff] [blame] | 1236 | static void ath_chanctx_work(struct work_struct *work) |
| 1237 | { |
| 1238 | struct ath_softc *sc = container_of(work, struct ath_softc, |
| 1239 | chanctx_work); |
| 1240 | mutex_lock(&sc->mutex); |
| 1241 | ath_chanctx_set_next(sc, false); |
| 1242 | mutex_unlock(&sc->mutex); |
| 1243 | } |
| 1244 | |
Sujith Manoharan | e90e302 | 2014-08-23 13:29:20 +0530 | [diff] [blame] | 1245 | void ath9k_offchannel_init(struct ath_softc *sc) |
| 1246 | { |
| 1247 | struct ath_chanctx *ctx; |
| 1248 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 1249 | struct ieee80211_supported_band *sband; |
| 1250 | struct ieee80211_channel *chan; |
| 1251 | int i; |
| 1252 | |
| 1253 | sband = &common->sbands[IEEE80211_BAND_2GHZ]; |
| 1254 | if (!sband->n_channels) |
| 1255 | sband = &common->sbands[IEEE80211_BAND_5GHZ]; |
| 1256 | |
| 1257 | chan = &sband->channels[0]; |
| 1258 | |
| 1259 | ctx = &sc->offchannel.chan; |
| 1260 | INIT_LIST_HEAD(&ctx->vifs); |
| 1261 | ctx->txpower = ATH_TXPOWER_MAX; |
| 1262 | cfg80211_chandef_create(&ctx->chandef, chan, NL80211_CHAN_HT20); |
| 1263 | |
| 1264 | for (i = 0; i < ARRAY_SIZE(ctx->acq); i++) |
| 1265 | INIT_LIST_HEAD(&ctx->acq[i]); |
| 1266 | |
| 1267 | sc->offchannel.chan.offchannel = true; |
| 1268 | } |
| 1269 | |
Sujith Manoharan | 705d0bf | 2014-08-23 13:29:06 +0530 | [diff] [blame] | 1270 | void ath9k_init_channel_context(struct ath_softc *sc) |
| 1271 | { |
| 1272 | INIT_WORK(&sc->chanctx_work, ath_chanctx_work); |
| 1273 | |
| 1274 | setup_timer(&sc->offchannel.timer, ath_offchannel_timer, |
| 1275 | (unsigned long)sc); |
| 1276 | setup_timer(&sc->sched.timer, ath_chanctx_timer, |
| 1277 | (unsigned long)sc); |
Sujith Manoharan | c6500ea | 2014-10-17 07:40:22 +0530 | [diff] [blame^] | 1278 | |
| 1279 | init_completion(&sc->go_beacon); |
Sujith Manoharan | 705d0bf | 2014-08-23 13:29:06 +0530 | [diff] [blame] | 1280 | } |
Sujith Manoharan | c7dd40c | 2014-08-22 20:39:30 +0530 | [diff] [blame] | 1281 | |
Sujith Manoharan | ea22df2 | 2014-08-23 13:29:07 +0530 | [diff] [blame] | 1282 | void ath9k_deinit_channel_context(struct ath_softc *sc) |
| 1283 | { |
| 1284 | cancel_work_sync(&sc->chanctx_work); |
| 1285 | } |
| 1286 | |
Sujith Manoharan | 499afac | 2014-08-22 20:39:31 +0530 | [diff] [blame] | 1287 | bool ath9k_is_chanctx_enabled(void) |
| 1288 | { |
| 1289 | return (ath9k_use_chanctx == 1); |
| 1290 | } |
| 1291 | |
Sujith Manoharan | 0e08b5f | 2014-08-23 13:29:19 +0530 | [diff] [blame] | 1292 | /********************/ |
| 1293 | /* Queue management */ |
| 1294 | /********************/ |
| 1295 | |
Sujith Manoharan | a064eaa | 2014-10-02 06:33:18 +0530 | [diff] [blame] | 1296 | void ath9k_chanctx_stop_queues(struct ath_softc *sc, struct ath_chanctx *ctx) |
| 1297 | { |
| 1298 | struct ath_hw *ah = sc->sc_ah; |
| 1299 | int i; |
| 1300 | |
| 1301 | if (ctx == &sc->offchannel.chan) { |
| 1302 | ieee80211_stop_queue(sc->hw, |
| 1303 | sc->hw->offchannel_tx_hw_queue); |
| 1304 | } else { |
| 1305 | for (i = 0; i < IEEE80211_NUM_ACS; i++) |
| 1306 | ieee80211_stop_queue(sc->hw, |
| 1307 | ctx->hw_queue_base + i); |
| 1308 | } |
| 1309 | |
| 1310 | if (ah->opmode == NL80211_IFTYPE_AP) |
| 1311 | ieee80211_stop_queue(sc->hw, sc->hw->queues - 2); |
| 1312 | } |
| 1313 | |
| 1314 | |
Sujith Manoharan | b390315 | 2014-10-02 06:33:17 +0530 | [diff] [blame] | 1315 | void ath9k_chanctx_wake_queues(struct ath_softc *sc, struct ath_chanctx *ctx) |
Sujith Manoharan | 0e08b5f | 2014-08-23 13:29:19 +0530 | [diff] [blame] | 1316 | { |
| 1317 | struct ath_hw *ah = sc->sc_ah; |
| 1318 | int i; |
| 1319 | |
Sujith Manoharan | b390315 | 2014-10-02 06:33:17 +0530 | [diff] [blame] | 1320 | if (ctx == &sc->offchannel.chan) { |
Sujith Manoharan | 0e08b5f | 2014-08-23 13:29:19 +0530 | [diff] [blame] | 1321 | ieee80211_wake_queue(sc->hw, |
| 1322 | sc->hw->offchannel_tx_hw_queue); |
| 1323 | } else { |
| 1324 | for (i = 0; i < IEEE80211_NUM_ACS; i++) |
| 1325 | ieee80211_wake_queue(sc->hw, |
Sujith Manoharan | b390315 | 2014-10-02 06:33:17 +0530 | [diff] [blame] | 1326 | ctx->hw_queue_base + i); |
Sujith Manoharan | 0e08b5f | 2014-08-23 13:29:19 +0530 | [diff] [blame] | 1327 | } |
| 1328 | |
| 1329 | if (ah->opmode == NL80211_IFTYPE_AP) |
| 1330 | ieee80211_wake_queue(sc->hw, sc->hw->queues - 2); |
| 1331 | } |
| 1332 | |
Sujith Manoharan | c7dd40c | 2014-08-22 20:39:30 +0530 | [diff] [blame] | 1333 | /*****************/ |
| 1334 | /* P2P Powersave */ |
| 1335 | /*****************/ |
| 1336 | |
| 1337 | static void ath9k_update_p2p_ps_timer(struct ath_softc *sc, struct ath_vif *avp) |
Sujith Manoharan | 2471adf | 2014-08-22 20:39:29 +0530 | [diff] [blame] | 1338 | { |
| 1339 | struct ath_hw *ah = sc->sc_ah; |
| 1340 | s32 tsf, target_tsf; |
| 1341 | |
| 1342 | if (!avp || !avp->noa.has_next_tsf) |
| 1343 | return; |
| 1344 | |
| 1345 | ath9k_hw_gen_timer_stop(ah, sc->p2p_ps_timer); |
| 1346 | |
| 1347 | tsf = ath9k_hw_gettsf32(sc->sc_ah); |
| 1348 | |
| 1349 | target_tsf = avp->noa.next_tsf; |
| 1350 | if (!avp->noa.absent) |
| 1351 | target_tsf -= ATH_P2P_PS_STOP_TIME; |
| 1352 | |
| 1353 | if (target_tsf - tsf < ATH_P2P_PS_STOP_TIME) |
| 1354 | target_tsf = tsf + ATH_P2P_PS_STOP_TIME; |
| 1355 | |
| 1356 | ath9k_hw_gen_timer_start(ah, sc->p2p_ps_timer, (u32) target_tsf, 1000000); |
| 1357 | } |
| 1358 | |
Sujith Manoharan | c7dd40c | 2014-08-22 20:39:30 +0530 | [diff] [blame] | 1359 | static void ath9k_update_p2p_ps(struct ath_softc *sc, struct ieee80211_vif *vif) |
| 1360 | { |
| 1361 | struct ath_vif *avp = (void *)vif->drv_priv; |
| 1362 | u32 tsf; |
| 1363 | |
| 1364 | if (!sc->p2p_ps_timer) |
| 1365 | return; |
| 1366 | |
| 1367 | if (vif->type != NL80211_IFTYPE_STATION || !vif->p2p) |
| 1368 | return; |
| 1369 | |
| 1370 | sc->p2p_ps_vif = avp; |
| 1371 | tsf = ath9k_hw_gettsf32(sc->sc_ah); |
| 1372 | ieee80211_parse_p2p_noa(&vif->bss_conf.p2p_noa_attr, &avp->noa, tsf); |
| 1373 | ath9k_update_p2p_ps_timer(sc, avp); |
| 1374 | } |
| 1375 | |
Sujith Manoharan | fdcf1bd | 2014-09-05 08:03:14 +0530 | [diff] [blame] | 1376 | static u8 ath9k_get_ctwin(struct ath_softc *sc, struct ath_vif *avp) |
| 1377 | { |
| 1378 | struct ath_beacon_config *cur_conf = &sc->cur_chan->beacon; |
| 1379 | u8 switch_time, ctwin; |
| 1380 | |
| 1381 | /* |
| 1382 | * Channel switch in multi-channel mode is deferred |
| 1383 | * by a quarter beacon interval when handling |
| 1384 | * ATH_CHANCTX_EVENT_BEACON_PREPARE, so the P2P-GO |
| 1385 | * interface is guaranteed to be discoverable |
| 1386 | * for that duration after a TBTT. |
| 1387 | */ |
| 1388 | switch_time = cur_conf->beacon_interval / 4; |
| 1389 | |
| 1390 | ctwin = avp->vif->bss_conf.p2p_noa_attr.oppps_ctwindow; |
| 1391 | if (ctwin && (ctwin < switch_time)) |
| 1392 | return ctwin; |
| 1393 | |
| 1394 | if (switch_time < P2P_DEFAULT_CTWIN) |
| 1395 | return 0; |
| 1396 | |
| 1397 | return P2P_DEFAULT_CTWIN; |
| 1398 | } |
| 1399 | |
Sujith Manoharan | 11e39a4 | 2014-08-23 19:12:15 +0530 | [diff] [blame] | 1400 | void ath9k_beacon_add_noa(struct ath_softc *sc, struct ath_vif *avp, |
| 1401 | struct sk_buff *skb) |
| 1402 | { |
| 1403 | static const u8 noa_ie_hdr[] = { |
| 1404 | WLAN_EID_VENDOR_SPECIFIC, /* type */ |
| 1405 | 0, /* length */ |
| 1406 | 0x50, 0x6f, 0x9a, /* WFA OUI */ |
| 1407 | 0x09, /* P2P subtype */ |
| 1408 | 0x0c, /* Notice of Absence */ |
| 1409 | 0x00, /* LSB of little-endian len */ |
| 1410 | 0x00, /* MSB of little-endian len */ |
| 1411 | }; |
| 1412 | |
| 1413 | struct ieee80211_p2p_noa_attr *noa; |
| 1414 | int noa_len, noa_desc, i = 0; |
| 1415 | u8 *hdr; |
| 1416 | |
Sujith Manoharan | d0975ed | 2014-09-10 19:15:57 +0530 | [diff] [blame] | 1417 | if (!avp->offchannel_duration && !avp->noa_duration) |
Sujith Manoharan | 11e39a4 | 2014-08-23 19:12:15 +0530 | [diff] [blame] | 1418 | return; |
| 1419 | |
Sujith Manoharan | d0975ed | 2014-09-10 19:15:57 +0530 | [diff] [blame] | 1420 | noa_desc = !!avp->offchannel_duration + !!avp->noa_duration; |
Sujith Manoharan | 11e39a4 | 2014-08-23 19:12:15 +0530 | [diff] [blame] | 1421 | noa_len = 2 + sizeof(struct ieee80211_p2p_noa_desc) * noa_desc; |
| 1422 | |
| 1423 | hdr = skb_put(skb, sizeof(noa_ie_hdr)); |
| 1424 | memcpy(hdr, noa_ie_hdr, sizeof(noa_ie_hdr)); |
| 1425 | hdr[1] = sizeof(noa_ie_hdr) + noa_len - 2; |
| 1426 | hdr[7] = noa_len; |
| 1427 | |
| 1428 | noa = (void *) skb_put(skb, noa_len); |
| 1429 | memset(noa, 0, noa_len); |
| 1430 | |
| 1431 | noa->index = avp->noa_index; |
Sujith Manoharan | fdcf1bd | 2014-09-05 08:03:14 +0530 | [diff] [blame] | 1432 | noa->oppps_ctwindow = ath9k_get_ctwin(sc, avp); |
| 1433 | |
Sujith Manoharan | d0975ed | 2014-09-10 19:15:57 +0530 | [diff] [blame] | 1434 | if (avp->noa_duration) { |
| 1435 | if (avp->periodic_noa) { |
| 1436 | u32 interval = TU_TO_USEC(sc->cur_chan->beacon.beacon_interval); |
| 1437 | noa->desc[i].count = 255; |
| 1438 | noa->desc[i].interval = cpu_to_le32(interval); |
| 1439 | } else { |
| 1440 | noa->desc[i].count = 1; |
| 1441 | } |
Sujith Manoharan | 11e39a4 | 2014-08-23 19:12:15 +0530 | [diff] [blame] | 1442 | |
Sujith Manoharan | d0975ed | 2014-09-10 19:15:57 +0530 | [diff] [blame] | 1443 | noa->desc[i].start_time = cpu_to_le32(avp->noa_start); |
| 1444 | noa->desc[i].duration = cpu_to_le32(avp->noa_duration); |
Sujith Manoharan | 11e39a4 | 2014-08-23 19:12:15 +0530 | [diff] [blame] | 1445 | i++; |
| 1446 | } |
| 1447 | |
| 1448 | if (avp->offchannel_duration) { |
| 1449 | noa->desc[i].count = 1; |
| 1450 | noa->desc[i].start_time = cpu_to_le32(avp->offchannel_start); |
| 1451 | noa->desc[i].duration = cpu_to_le32(avp->offchannel_duration); |
| 1452 | } |
| 1453 | } |
| 1454 | |
Sujith Manoharan | 2471adf | 2014-08-22 20:39:29 +0530 | [diff] [blame] | 1455 | void ath9k_p2p_ps_timer(void *priv) |
| 1456 | { |
| 1457 | struct ath_softc *sc = priv; |
| 1458 | struct ath_vif *avp = sc->p2p_ps_vif; |
| 1459 | struct ieee80211_vif *vif; |
| 1460 | struct ieee80211_sta *sta; |
| 1461 | struct ath_node *an; |
| 1462 | u32 tsf; |
| 1463 | |
| 1464 | del_timer_sync(&sc->sched.timer); |
| 1465 | ath9k_hw_gen_timer_stop(sc->sc_ah, sc->p2p_ps_timer); |
| 1466 | ath_chanctx_event(sc, NULL, ATH_CHANCTX_EVENT_TSF_TIMER); |
| 1467 | |
| 1468 | if (!avp || avp->chanctx != sc->cur_chan) |
| 1469 | return; |
| 1470 | |
| 1471 | tsf = ath9k_hw_gettsf32(sc->sc_ah); |
| 1472 | if (!avp->noa.absent) |
| 1473 | tsf += ATH_P2P_PS_STOP_TIME; |
| 1474 | |
| 1475 | if (!avp->noa.has_next_tsf || |
| 1476 | avp->noa.next_tsf - tsf > BIT(31)) |
| 1477 | ieee80211_update_p2p_noa(&avp->noa, tsf); |
| 1478 | |
| 1479 | ath9k_update_p2p_ps_timer(sc, avp); |
| 1480 | |
| 1481 | rcu_read_lock(); |
| 1482 | |
| 1483 | vif = avp->vif; |
Sujith Manoharan | cb35582 | 2014-09-17 14:45:56 +0530 | [diff] [blame] | 1484 | sta = ieee80211_find_sta(vif, avp->bssid); |
Sujith Manoharan | 2471adf | 2014-08-22 20:39:29 +0530 | [diff] [blame] | 1485 | if (!sta) |
| 1486 | goto out; |
| 1487 | |
| 1488 | an = (void *) sta->drv_priv; |
| 1489 | if (an->sleeping == !!avp->noa.absent) |
| 1490 | goto out; |
| 1491 | |
| 1492 | an->sleeping = avp->noa.absent; |
| 1493 | if (an->sleeping) |
| 1494 | ath_tx_aggr_sleep(sta, sc, an); |
| 1495 | else |
| 1496 | ath_tx_aggr_wakeup(sc, an); |
| 1497 | |
| 1498 | out: |
| 1499 | rcu_read_unlock(); |
| 1500 | } |
| 1501 | |
Sujith Manoharan | c7dd40c | 2014-08-22 20:39:30 +0530 | [diff] [blame] | 1502 | void ath9k_p2p_bss_info_changed(struct ath_softc *sc, |
| 1503 | struct ieee80211_vif *vif) |
| 1504 | { |
| 1505 | unsigned long flags; |
| 1506 | |
| 1507 | spin_lock_bh(&sc->sc_pcu_lock); |
| 1508 | spin_lock_irqsave(&sc->sc_pm_lock, flags); |
| 1509 | if (!(sc->ps_flags & PS_BEACON_SYNC)) |
| 1510 | ath9k_update_p2p_ps(sc, vif); |
| 1511 | spin_unlock_irqrestore(&sc->sc_pm_lock, flags); |
| 1512 | spin_unlock_bh(&sc->sc_pcu_lock); |
| 1513 | } |
| 1514 | |
| 1515 | void ath9k_p2p_beacon_sync(struct ath_softc *sc) |
| 1516 | { |
| 1517 | if (sc->p2p_ps_vif) |
| 1518 | ath9k_update_p2p_ps(sc, sc->p2p_ps_vif->vif); |
| 1519 | } |
| 1520 | |
| 1521 | void ath9k_p2p_remove_vif(struct ath_softc *sc, |
| 1522 | struct ieee80211_vif *vif) |
Sujith Manoharan | 2471adf | 2014-08-22 20:39:29 +0530 | [diff] [blame] | 1523 | { |
| 1524 | struct ath_vif *avp = (void *)vif->drv_priv; |
Sujith Manoharan | 2471adf | 2014-08-22 20:39:29 +0530 | [diff] [blame] | 1525 | |
Sujith Manoharan | c7dd40c | 2014-08-22 20:39:30 +0530 | [diff] [blame] | 1526 | spin_lock_bh(&sc->sc_pcu_lock); |
| 1527 | if (avp == sc->p2p_ps_vif) { |
| 1528 | sc->p2p_ps_vif = NULL; |
| 1529 | ath9k_update_p2p_ps_timer(sc, NULL); |
| 1530 | } |
| 1531 | spin_unlock_bh(&sc->sc_pcu_lock); |
Sujith Manoharan | 2471adf | 2014-08-22 20:39:29 +0530 | [diff] [blame] | 1532 | } |
Sujith Manoharan | c7dd40c | 2014-08-22 20:39:30 +0530 | [diff] [blame] | 1533 | |
| 1534 | int ath9k_init_p2p(struct ath_softc *sc) |
| 1535 | { |
| 1536 | sc->p2p_ps_timer = ath_gen_timer_alloc(sc->sc_ah, ath9k_p2p_ps_timer, |
| 1537 | NULL, sc, AR_FIRST_NDP_TIMER); |
| 1538 | if (!sc->p2p_ps_timer) |
| 1539 | return -ENOMEM; |
| 1540 | |
| 1541 | return 0; |
| 1542 | } |
| 1543 | |
| 1544 | void ath9k_deinit_p2p(struct ath_softc *sc) |
| 1545 | { |
| 1546 | if (sc->p2p_ps_timer) |
| 1547 | ath_gen_timer_free(sc->sc_ah, sc->p2p_ps_timer); |
| 1548 | } |
| 1549 | |
| 1550 | #endif /* CONFIG_ATH9K_CHANNEL_CONTEXT */ |