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