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