blob: 5045b107b6d8b1b36dbfb286c974094b44139ed7 [file] [log] [blame]
Felix Fietkaufbbcd142014-06-11 16:17:49 +05301/*
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 */
23static 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 Manoharan5555c952014-10-17 07:40:11 +053069 r = ath_reset(sc, hchan);
Felix Fietkaufbbcd142014-06-11 16:17:49 +053070 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 Fietkaufbbcd142014-06-11 16:17:49 +053086 rxfilter = ath9k_hw_getrxfilter(ah);
87 rxfilter |= ATH9K_RX_FILTER_PHYRADAR |
88 ATH9K_RX_FILTER_PHYERR;
89 ath9k_hw_setrxfilter(ah, rxfilter);
90 ath_dbg(common, DFS, "DFS enabled at freq %d\n",
91 chan->center_freq);
92 } else {
93 /* perform spectral scan if requested. */
94 if (test_bit(ATH_OP_SCANNING, &common->op_flags) &&
95 sc->spectral_mode == SPECTRAL_CHANSCAN)
96 ath9k_spectral_scan_trigger(hw);
97 }
98
99 return 0;
100}
101
102void 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 Fietkau04535312014-06-11 16:17:51 +0530108 int i, j;
Felix Fietkaufbbcd142014-06-11 16:17:49 +0530109
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 Fietkaubc7e1be2014-06-11 16:17:50 +0530119 ctx->txpower = ATH_TXPOWER_MAX;
Sujith Manoharan2fae0d92014-10-17 07:40:15 +0530120 ctx->flush_timeout = HZ / 5; /* 200ms */
Felix Fietkau04535312014-06-11 16:17:51 +0530121 for (j = 0; j < ARRAY_SIZE(ctx->acq); j++)
122 INIT_LIST_HEAD(&ctx->acq[j]);
Felix Fietkaufbbcd142014-06-11 16:17:49 +0530123 }
Felix Fietkaufbbcd142014-06-11 16:17:49 +0530124}
125
Felix Fietkaubff11762014-06-11 16:17:52 +0530126void ath_chanctx_set_channel(struct ath_softc *sc, struct ath_chanctx *ctx,
127 struct cfg80211_chan_def *chandef)
128{
Sujith Manoharan4c7e9ae2014-08-24 21:16:13 +0530129 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Felix Fietkaubff11762014-06-11 16:17:52 +0530130 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 Manoharan4c7e9ae2014-08-24 21:16:13 +0530138 if (!cur_chan) {
139 ath_dbg(common, CHAN_CTX,
140 "Current context differs from the new context\n");
Felix Fietkaubff11762014-06-11 16:17:52 +0530141 return;
Sujith Manoharan4c7e9ae2014-08-24 21:16:13 +0530142 }
Felix Fietkaubff11762014-06-11 16:17:52 +0530143
144 ath_set_channel(sc);
Felix Fietkaufbbcd142014-06-11 16:17:49 +0530145}
Felix Fietkau78b21942014-06-11 16:17:55 +0530146
Sujith Manoharan27babf92014-08-23 13:29:16 +0530147#ifdef CONFIG_ATH9K_CHANNEL_CONTEXT
148
Sujith Manoharan0e08b5f2014-08-23 13:29:19 +0530149/**********************************************************/
150/* Functions to handle the channel context state machine. */
151/**********************************************************/
152
Sujith Manoharan27babf92014-08-23 13:29:16 +0530153static const char *offchannel_state_string(enum ath_offchannel_state state)
154{
Sujith Manoharan27babf92014-08-23 13:29:16 +0530155 switch (state) {
156 case_rtn_string(ATH_OFFCHANNEL_IDLE);
157 case_rtn_string(ATH_OFFCHANNEL_PROBE_SEND);
158 case_rtn_string(ATH_OFFCHANNEL_PROBE_WAIT);
159 case_rtn_string(ATH_OFFCHANNEL_SUSPEND);
160 case_rtn_string(ATH_OFFCHANNEL_ROC_START);
161 case_rtn_string(ATH_OFFCHANNEL_ROC_WAIT);
162 case_rtn_string(ATH_OFFCHANNEL_ROC_DONE);
163 default:
164 return "unknown";
165 }
166}
167
Sujith Manoharan5a8cbec2014-08-24 21:16:11 +0530168static const char *chanctx_event_string(enum ath_chanctx_event ev)
169{
170 switch (ev) {
171 case_rtn_string(ATH_CHANCTX_EVENT_BEACON_PREPARE);
172 case_rtn_string(ATH_CHANCTX_EVENT_BEACON_SENT);
173 case_rtn_string(ATH_CHANCTX_EVENT_TSF_TIMER);
174 case_rtn_string(ATH_CHANCTX_EVENT_BEACON_RECEIVED);
Sujith Manoharanb8f92792014-10-17 07:40:09 +0530175 case_rtn_string(ATH_CHANCTX_EVENT_AUTHORIZED);
Sujith Manoharan5a8cbec2014-08-24 21:16:11 +0530176 case_rtn_string(ATH_CHANCTX_EVENT_SWITCH);
177 case_rtn_string(ATH_CHANCTX_EVENT_ASSIGN);
178 case_rtn_string(ATH_CHANCTX_EVENT_UNASSIGN);
179 case_rtn_string(ATH_CHANCTX_EVENT_CHANGE);
180 case_rtn_string(ATH_CHANCTX_EVENT_ENABLE_MULTICHANNEL);
181 default:
182 return "unknown";
183 }
184}
185
186static const char *chanctx_state_string(enum ath_chanctx_state state)
187{
188 switch (state) {
189 case_rtn_string(ATH_CHANCTX_STATE_IDLE);
190 case_rtn_string(ATH_CHANCTX_STATE_WAIT_FOR_BEACON);
191 case_rtn_string(ATH_CHANCTX_STATE_WAIT_FOR_TIMER);
192 case_rtn_string(ATH_CHANCTX_STATE_SWITCH);
193 case_rtn_string(ATH_CHANCTX_STATE_FORCE_ACTIVE);
194 default:
195 return "unknown";
196 }
197}
198
Sujith Manoharana09798f2014-08-23 13:29:21 +0530199void ath_chanctx_check_active(struct ath_softc *sc, struct ath_chanctx *ctx)
200{
201 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
202 struct ath_vif *avp;
203 bool active = false;
204 u8 n_active = 0;
205
206 if (!ctx)
207 return;
208
209 list_for_each_entry(avp, &ctx->vifs, list) {
210 struct ieee80211_vif *vif = avp->vif;
211
212 switch (vif->type) {
213 case NL80211_IFTYPE_P2P_CLIENT:
214 case NL80211_IFTYPE_STATION:
Sujith Manoharancb355822014-09-17 14:45:56 +0530215 if (avp->assoc)
Sujith Manoharana09798f2014-08-23 13:29:21 +0530216 active = true;
217 break;
218 default:
219 active = true;
220 break;
221 }
222 }
223 ctx->active = active;
224
225 ath_for_each_chanctx(sc, ctx) {
226 if (!ctx->assigned || list_empty(&ctx->vifs))
227 continue;
228 n_active++;
229 }
230
231 if (n_active <= 1) {
232 clear_bit(ATH_OP_MULTI_CHANNEL, &common->op_flags);
233 return;
234 }
235 if (test_and_set_bit(ATH_OP_MULTI_CHANNEL, &common->op_flags))
236 return;
237
238 if (ath9k_is_chanctx_enabled()) {
239 ath_chanctx_event(sc, NULL,
240 ATH_CHANCTX_EVENT_ENABLE_MULTICHANNEL);
241 }
242}
243
Felix Fietkau58b57372014-06-11 16:18:08 +0530244static struct ath_chanctx *
245ath_chanctx_get_next(struct ath_softc *sc, struct ath_chanctx *ctx)
246{
247 int idx = ctx - &sc->chanctx[0];
248
249 return &sc->chanctx[!idx];
250}
251
252static void ath_chanctx_adjust_tbtt_delta(struct ath_softc *sc)
253{
254 struct ath_chanctx *prev, *cur;
255 struct timespec ts;
256 u32 cur_tsf, prev_tsf, beacon_int;
257 s32 offset;
258
259 beacon_int = TU_TO_USEC(sc->cur_chan->beacon.beacon_interval);
260
261 cur = sc->cur_chan;
262 prev = ath_chanctx_get_next(sc, cur);
263
Sujith Manoharan7f30eac2014-09-15 11:25:51 +0530264 if (!prev->switch_after_beacon)
265 return;
266
Felix Fietkau58b57372014-06-11 16:18:08 +0530267 getrawmonotonic(&ts);
268 cur_tsf = (u32) cur->tsf_val +
269 ath9k_hw_get_tsf_offset(&cur->tsf_ts, &ts);
270
271 prev_tsf = prev->last_beacon - (u32) prev->tsf_val + cur_tsf;
272 prev_tsf -= ath9k_hw_get_tsf_offset(&prev->tsf_ts, &ts);
273
274 /* Adjust the TSF time of the AP chanctx to keep its beacons
275 * at half beacon interval offset relative to the STA chanctx.
276 */
277 offset = cur_tsf - prev_tsf;
278
279 /* Ignore stale data or spurious timestamps */
280 if (offset < 0 || offset > 3 * beacon_int)
281 return;
282
283 offset = beacon_int / 2 - (offset % beacon_int);
284 prev->tsf_val += offset;
285}
286
Felix Fietkau42eda112014-06-11 16:18:14 +0530287/* Configure the TSF based hardware timer for a channel switch.
288 * Also set up backup software timer, in case the gen timer fails.
289 * This could be caused by a hardware reset.
290 */
291static void ath_chanctx_setup_timer(struct ath_softc *sc, u32 tsf_time)
292{
Sujith Manoharan878066e2014-08-27 12:07:24 +0530293 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Felix Fietkau42eda112014-06-11 16:18:14 +0530294 struct ath_hw *ah = sc->sc_ah;
295
296 ath9k_hw_gen_timer_start(ah, sc->p2p_ps_timer, tsf_time, 1000000);
297 tsf_time -= ath9k_hw_gettsf32(ah);
298 tsf_time = msecs_to_jiffies(tsf_time / 1000) + 1;
Sujith Manoharan1a7c5b72014-08-27 12:07:25 +0530299 mod_timer(&sc->sched.timer, jiffies + tsf_time);
Sujith Manoharan878066e2014-08-27 12:07:24 +0530300
301 ath_dbg(common, CHAN_CTX,
302 "Setup chanctx timer with timeout: %d ms\n", jiffies_to_msecs(tsf_time));
Felix Fietkau42eda112014-06-11 16:18:14 +0530303}
304
Felix Fietkau748299f2014-06-11 16:18:04 +0530305void ath_chanctx_event(struct ath_softc *sc, struct ieee80211_vif *vif,
306 enum ath_chanctx_event ev)
307{
308 struct ath_hw *ah = sc->sc_ah;
Felix Fietkau58b57372014-06-11 16:18:08 +0530309 struct ath_common *common = ath9k_hw_common(ah);
Felix Fietkau74148632014-06-11 16:18:11 +0530310 struct ath_beacon_config *cur_conf;
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530311 struct ath_vif *avp = NULL;
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530312 struct ath_chanctx *ctx;
Felix Fietkau748299f2014-06-11 16:18:04 +0530313 u32 tsf_time;
Felix Fietkauec70abe2014-06-11 16:18:12 +0530314 u32 beacon_int;
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530315
316 if (vif)
317 avp = (struct ath_vif *) vif->drv_priv;
Felix Fietkau748299f2014-06-11 16:18:04 +0530318
319 spin_lock_bh(&sc->chan_lock);
320
Sujith Manoharan878066e2014-08-27 12:07:24 +0530321 ath_dbg(common, CHAN_CTX, "cur_chan: %d MHz, event: %s, state: %s\n",
322 sc->cur_chan->chandef.center_freq1,
323 chanctx_event_string(ev),
324 chanctx_state_string(sc->sched.state));
325
Felix Fietkau748299f2014-06-11 16:18:04 +0530326 switch (ev) {
327 case ATH_CHANCTX_EVENT_BEACON_PREPARE:
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530328 if (avp->offchannel_duration)
329 avp->offchannel_duration = 0;
330
Sujith Manoharan878066e2014-08-27 12:07:24 +0530331 if (avp->chanctx != sc->cur_chan) {
332 ath_dbg(common, CHAN_CTX,
333 "Contexts differ, not preparing beacon\n");
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530334 break;
Sujith Manoharan878066e2014-08-27 12:07:24 +0530335 }
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530336
Sujith Manoharan367b3412014-09-05 09:50:57 +0530337 if (sc->sched.offchannel_pending && !sc->sched.wait_switch) {
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530338 sc->sched.offchannel_pending = false;
339 sc->next_chan = &sc->offchannel.chan;
340 sc->sched.state = ATH_CHANCTX_STATE_WAIT_FOR_BEACON;
Sujith Manoharan878066e2014-08-27 12:07:24 +0530341 ath_dbg(common, CHAN_CTX,
342 "Setting offchannel_pending to false\n");
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530343 }
344
345 ctx = ath_chanctx_get_next(sc, sc->cur_chan);
346 if (ctx->active && sc->sched.state == ATH_CHANCTX_STATE_IDLE) {
347 sc->next_chan = ctx;
348 sc->sched.state = ATH_CHANCTX_STATE_WAIT_FOR_BEACON;
Sujith Manoharan878066e2014-08-27 12:07:24 +0530349 ath_dbg(common, CHAN_CTX,
350 "Set next context, move chanctx state to WAIT_FOR_BEACON\n");
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530351 }
352
353 /* if the timer missed its window, use the next interval */
Sujith Manoharan878066e2014-08-27 12:07:24 +0530354 if (sc->sched.state == ATH_CHANCTX_STATE_WAIT_FOR_TIMER) {
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530355 sc->sched.state = ATH_CHANCTX_STATE_WAIT_FOR_BEACON;
Sujith Manoharan878066e2014-08-27 12:07:24 +0530356 ath_dbg(common, CHAN_CTX,
357 "Move chanctx state from WAIT_FOR_TIMER to WAIT_FOR_BEACON\n");
358 }
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530359
Sujith Manoharan8890d052014-10-17 07:40:14 +0530360 /*
361 * When a context becomes inactive, for example,
362 * disassociation of a station context, the NoA
363 * attribute needs to be removed from subsequent
364 * beacons.
365 */
366 if (!ctx->active && avp->noa_duration &&
367 sc->sched.state != ATH_CHANCTX_STATE_WAIT_FOR_BEACON) {
368 avp->noa_duration = 0;
369 avp->periodic_noa = false;
370
371 ath_dbg(common, CHAN_CTX,
372 "Clearing NoA schedule\n");
373 }
374
Felix Fietkau748299f2014-06-11 16:18:04 +0530375 if (sc->sched.state != ATH_CHANCTX_STATE_WAIT_FOR_BEACON)
376 break;
377
Sujith Manoharan878066e2014-08-27 12:07:24 +0530378 ath_dbg(common, CHAN_CTX, "Preparing beacon for vif: %pM\n", vif->addr);
379
Felix Fietkau748299f2014-06-11 16:18:04 +0530380 sc->sched.beacon_pending = true;
381 sc->sched.next_tbtt = REG_READ(ah, AR_NEXT_TBTT_TIMER);
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530382
Felix Fietkau74148632014-06-11 16:18:11 +0530383 cur_conf = &sc->cur_chan->beacon;
Felix Fietkauec70abe2014-06-11 16:18:12 +0530384 beacon_int = TU_TO_USEC(cur_conf->beacon_interval);
385
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530386 /* defer channel switch by a quarter beacon interval */
Felix Fietkauec70abe2014-06-11 16:18:12 +0530387 tsf_time = sc->sched.next_tbtt + beacon_int / 4;
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530388 sc->sched.switch_start_time = tsf_time;
Felix Fietkau58b57372014-06-11 16:18:08 +0530389 sc->cur_chan->last_beacon = sc->sched.next_tbtt;
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530390
Sujith Manoharand0975ed2014-09-10 19:15:57 +0530391 /*
392 * If an offchannel switch is scheduled to happen after
393 * a beacon transmission, update the NoA with one-shot
394 * values and increment the index.
395 */
396 if (sc->next_chan == &sc->offchannel.chan) {
397 avp->noa_index++;
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530398 avp->offchannel_start = tsf_time;
Sujith Manoharand0975ed2014-09-10 19:15:57 +0530399 avp->offchannel_duration = sc->sched.offchannel_duration;
400
401 ath_dbg(common, CHAN_CTX,
402 "offchannel noa_duration: %d, noa_start: %d, noa_index: %d\n",
403 avp->offchannel_duration,
404 avp->offchannel_start,
405 avp->noa_index);
406
407 /*
408 * When multiple contexts are active, the NoA
409 * has to be recalculated and advertised after
410 * an offchannel operation.
411 */
412 if (ctx->active && avp->noa_duration)
413 avp->noa_duration = 0;
414
415 break;
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530416 }
417
Sujith Manoharan167bf96d2014-09-10 19:16:00 +0530418 /*
419 * Clear the extend_absence flag if it had been
420 * set during the previous beacon transmission,
421 * since we need to revert to the normal NoA
422 * schedule.
423 */
424 if (ctx->active && sc->sched.extend_absence) {
425 avp->noa_duration = 0;
426 sc->sched.extend_absence = false;
427 }
428
429 /* If at least two consecutive beacons were missed on the STA
430 * chanctx, stay on the STA channel for one extra beacon period,
431 * to resync the timer properly.
432 */
433 if (ctx->active && sc->sched.beacon_miss >= 2) {
434 avp->noa_duration = 0;
435 sc->sched.extend_absence = true;
436 }
Sujith Manoharana2b28602014-09-15 11:25:50 +0530437
Sujith Manoharand0975ed2014-09-10 19:15:57 +0530438 /* Prevent wrap-around issues */
439 if (avp->noa_duration && tsf_time - avp->noa_start > BIT(30))
440 avp->noa_duration = 0;
Sujith Manoharan878066e2014-08-27 12:07:24 +0530441
Sujith Manoharand0975ed2014-09-10 19:15:57 +0530442 /*
443 * If multiple contexts are active, start periodic
444 * NoA and increment the index for the first
445 * announcement.
446 */
447 if (ctx->active &&
448 (!avp->noa_duration || sc->sched.force_noa_update)) {
449 avp->noa_index++;
450 avp->noa_start = tsf_time;
Sujith Manoharand0975ed2014-09-10 19:15:57 +0530451
Sujith Manoharan167bf96d2014-09-10 19:16:00 +0530452 if (sc->sched.extend_absence)
453 avp->noa_duration = (3 * beacon_int / 2) +
454 sc->sched.channel_switch_time;
455 else
456 avp->noa_duration =
457 TU_TO_USEC(cur_conf->beacon_interval) / 2 +
458 sc->sched.channel_switch_time;
459
460 if (test_bit(ATH_OP_SCANNING, &common->op_flags) ||
461 sc->sched.extend_absence)
Sujith Manoharand0975ed2014-09-10 19:15:57 +0530462 avp->periodic_noa = false;
463 else
464 avp->periodic_noa = true;
465
466 ath_dbg(common, CHAN_CTX,
467 "noa_duration: %d, noa_start: %d, noa_index: %d, periodic: %d\n",
468 avp->noa_duration,
469 avp->noa_start,
470 avp->noa_index,
471 avp->periodic_noa);
472 }
473
474 if (ctx->active && sc->sched.force_noa_update)
475 sc->sched.force_noa_update = false;
Sujith Manoharan878066e2014-08-27 12:07:24 +0530476
Felix Fietkau748299f2014-06-11 16:18:04 +0530477 break;
478 case ATH_CHANCTX_EVENT_BEACON_SENT:
Sujith Manoharan878066e2014-08-27 12:07:24 +0530479 if (!sc->sched.beacon_pending) {
480 ath_dbg(common, CHAN_CTX,
481 "No pending beacon\n");
Felix Fietkau748299f2014-06-11 16:18:04 +0530482 break;
Sujith Manoharan878066e2014-08-27 12:07:24 +0530483 }
Felix Fietkau748299f2014-06-11 16:18:04 +0530484
485 sc->sched.beacon_pending = false;
486 if (sc->sched.state != ATH_CHANCTX_STATE_WAIT_FOR_BEACON)
487 break;
488
Sujith Manoharan878066e2014-08-27 12:07:24 +0530489 ath_dbg(common, CHAN_CTX,
490 "Move chanctx state to WAIT_FOR_TIMER\n");
491
Felix Fietkau748299f2014-06-11 16:18:04 +0530492 sc->sched.state = ATH_CHANCTX_STATE_WAIT_FOR_TIMER;
Felix Fietkau42eda112014-06-11 16:18:14 +0530493 ath_chanctx_setup_timer(sc, sc->sched.switch_start_time);
Felix Fietkau748299f2014-06-11 16:18:04 +0530494 break;
495 case ATH_CHANCTX_EVENT_TSF_TIMER:
496 if (sc->sched.state != ATH_CHANCTX_STATE_WAIT_FOR_TIMER)
497 break;
498
Felix Fietkauec70abe2014-06-11 16:18:12 +0530499 if (!sc->cur_chan->switch_after_beacon &&
500 sc->sched.beacon_pending)
501 sc->sched.beacon_miss++;
502
Sujith Manoharan878066e2014-08-27 12:07:24 +0530503 ath_dbg(common, CHAN_CTX,
504 "Move chanctx state to SWITCH\n");
505
Felix Fietkau748299f2014-06-11 16:18:04 +0530506 sc->sched.state = ATH_CHANCTX_STATE_SWITCH;
507 ieee80211_queue_work(sc->hw, &sc->chanctx_work);
508 break;
Felix Fietkau58b57372014-06-11 16:18:08 +0530509 case ATH_CHANCTX_EVENT_BEACON_RECEIVED:
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530510 if (!test_bit(ATH_OP_MULTI_CHANNEL, &common->op_flags) ||
511 sc->cur_chan == &sc->offchannel.chan)
Felix Fietkau58b57372014-06-11 16:18:08 +0530512 break;
513
Felix Fietkauec70abe2014-06-11 16:18:12 +0530514 sc->sched.beacon_pending = false;
515 sc->sched.beacon_miss = 0;
Felix Fietkaua899b672014-06-11 16:18:13 +0530516
Sujith Manoharanbe247c12014-10-17 07:40:10 +0530517 if (sc->sched.state == ATH_CHANCTX_STATE_FORCE_ACTIVE ||
518 !sc->cur_chan->tsf_val)
519 break;
520
521 ath_chanctx_adjust_tbtt_delta(sc);
522
Felix Fietkaua899b672014-06-11 16:18:13 +0530523 /* TSF time might have been updated by the incoming beacon,
524 * need update the channel switch timer to reflect the change.
525 */
526 tsf_time = sc->sched.switch_start_time;
527 tsf_time -= (u32) sc->cur_chan->tsf_val +
528 ath9k_hw_get_tsf_offset(&sc->cur_chan->tsf_ts, NULL);
529 tsf_time += ath9k_hw_gettsf32(ah);
530
Felix Fietkau42eda112014-06-11 16:18:14 +0530531
532 ath_chanctx_setup_timer(sc, tsf_time);
Felix Fietkau58b57372014-06-11 16:18:08 +0530533 break;
Sujith Manoharanb8f92792014-10-17 07:40:09 +0530534 case ATH_CHANCTX_EVENT_AUTHORIZED:
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530535 if (sc->sched.state != ATH_CHANCTX_STATE_FORCE_ACTIVE ||
536 avp->chanctx != sc->cur_chan)
537 break;
538
Sujith Manoharan878066e2014-08-27 12:07:24 +0530539 ath_dbg(common, CHAN_CTX,
540 "Move chanctx state from FORCE_ACTIVE to IDLE\n");
541
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530542 sc->sched.state = ATH_CHANCTX_STATE_IDLE;
543 /* fall through */
544 case ATH_CHANCTX_EVENT_SWITCH:
545 if (!test_bit(ATH_OP_MULTI_CHANNEL, &common->op_flags) ||
546 sc->sched.state == ATH_CHANCTX_STATE_FORCE_ACTIVE ||
547 sc->cur_chan->switch_after_beacon ||
548 sc->cur_chan == &sc->offchannel.chan)
549 break;
550
551 /* If this is a station chanctx, stay active for a half
552 * beacon period (minus channel switch time)
553 */
554 sc->next_chan = ath_chanctx_get_next(sc, sc->cur_chan);
Felix Fietkau74148632014-06-11 16:18:11 +0530555 cur_conf = &sc->cur_chan->beacon;
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530556
Sujith Manoharan878066e2014-08-27 12:07:24 +0530557 ath_dbg(common, CHAN_CTX,
558 "Move chanctx state to WAIT_FOR_TIMER (event SWITCH)\n");
559
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530560 sc->sched.state = ATH_CHANCTX_STATE_WAIT_FOR_TIMER;
Sujith Manoharan367b3412014-09-05 09:50:57 +0530561 sc->sched.wait_switch = false;
Felix Fietkauec70abe2014-06-11 16:18:12 +0530562
563 tsf_time = TU_TO_USEC(cur_conf->beacon_interval) / 2;
Sujith Manoharan167bf96d2014-09-10 19:16:00 +0530564
565 if (sc->sched.extend_absence) {
Felix Fietkauec70abe2014-06-11 16:18:12 +0530566 sc->sched.beacon_miss = 0;
567 tsf_time *= 3;
568 }
569
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530570 tsf_time -= sc->sched.channel_switch_time;
Felix Fietkauec70abe2014-06-11 16:18:12 +0530571 tsf_time += ath9k_hw_gettsf32(sc->sc_ah);
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530572 sc->sched.switch_start_time = tsf_time;
573
Felix Fietkau42eda112014-06-11 16:18:14 +0530574 ath_chanctx_setup_timer(sc, tsf_time);
Felix Fietkauec70abe2014-06-11 16:18:12 +0530575 sc->sched.beacon_pending = true;
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530576 break;
577 case ATH_CHANCTX_EVENT_ENABLE_MULTICHANNEL:
578 if (sc->cur_chan == &sc->offchannel.chan ||
579 sc->cur_chan->switch_after_beacon)
580 break;
581
582 sc->next_chan = ath_chanctx_get_next(sc, sc->cur_chan);
583 ieee80211_queue_work(sc->hw, &sc->chanctx_work);
584 break;
585 case ATH_CHANCTX_EVENT_UNASSIGN:
586 if (sc->cur_chan->assigned) {
587 if (sc->next_chan && !sc->next_chan->assigned &&
588 sc->next_chan != &sc->offchannel.chan)
589 sc->sched.state = ATH_CHANCTX_STATE_IDLE;
590 break;
591 }
592
593 ctx = ath_chanctx_get_next(sc, sc->cur_chan);
594 sc->sched.state = ATH_CHANCTX_STATE_IDLE;
595 if (!ctx->assigned)
596 break;
597
598 sc->next_chan = ctx;
599 ieee80211_queue_work(sc->hw, &sc->chanctx_work);
600 break;
Sujith Manoharan02da18b2014-08-24 21:16:10 +0530601 case ATH_CHANCTX_EVENT_ASSIGN:
Sujith Manoharan4c7e9ae2014-08-24 21:16:13 +0530602 /*
603 * When adding a new channel context, check if a scan
604 * is in progress and abort it since the addition of
605 * a new channel context is usually followed by VIF
606 * assignment, in which case we have to start multi-channel
607 * operation.
608 */
609 if (test_bit(ATH_OP_SCANNING, &common->op_flags)) {
610 ath_dbg(common, CHAN_CTX,
611 "Aborting HW scan to add new context\n");
612
613 spin_unlock_bh(&sc->chan_lock);
614 del_timer_sync(&sc->offchannel.timer);
615 ath_scan_complete(sc, true);
616 spin_lock_bh(&sc->chan_lock);
617 }
Sujith Manoharan02da18b2014-08-24 21:16:10 +0530618 break;
619 case ATH_CHANCTX_EVENT_CHANGE:
620 break;
Felix Fietkau748299f2014-06-11 16:18:04 +0530621 }
622
623 spin_unlock_bh(&sc->chan_lock);
624}
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530625
Sujith Manoharan70b06da2014-08-23 13:29:18 +0530626void ath_chanctx_beacon_sent_ev(struct ath_softc *sc,
627 enum ath_chanctx_event ev)
628{
629 if (sc->sched.beacon_pending)
630 ath_chanctx_event(sc, NULL, ev);
631}
632
Sujith Manoharana2b28602014-09-15 11:25:50 +0530633void ath_chanctx_beacon_recv_ev(struct ath_softc *sc,
Sujith Manoharan70b06da2014-08-23 13:29:18 +0530634 enum ath_chanctx_event ev)
635{
Sujith Manoharan70b06da2014-08-23 13:29:18 +0530636 ath_chanctx_event(sc, NULL, ev);
637}
638
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530639static int ath_scan_channel_duration(struct ath_softc *sc,
640 struct ieee80211_channel *chan)
641{
642 struct cfg80211_scan_request *req = sc->offchannel.scan_req;
643
644 if (!req->n_ssids || (chan->flags & IEEE80211_CHAN_NO_IR))
645 return (HZ / 9); /* ~110 ms */
646
647 return (HZ / 16); /* ~60 ms */
648}
649
Sujith Manoharan922c9432014-08-23 13:29:15 +0530650static void ath_chanctx_switch(struct ath_softc *sc, struct ath_chanctx *ctx,
651 struct cfg80211_chan_def *chandef)
652{
653 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
654
655 spin_lock_bh(&sc->chan_lock);
656
657 if (test_bit(ATH_OP_MULTI_CHANNEL, &common->op_flags) &&
658 (sc->cur_chan != ctx) && (ctx == &sc->offchannel.chan)) {
Sujith Manoharanda0162f2014-09-05 09:50:56 +0530659 if (chandef)
660 ctx->chandef = *chandef;
Sujith Manoharancbc775d2014-09-10 19:15:56 +0530661
662 sc->sched.offchannel_pending = true;
663 sc->sched.wait_switch = true;
664 sc->sched.offchannel_duration =
665 jiffies_to_usecs(sc->offchannel.duration) +
666 sc->sched.channel_switch_time;
667
Sujith Manoharan922c9432014-08-23 13:29:15 +0530668 spin_unlock_bh(&sc->chan_lock);
Sujith Manoharanda0162f2014-09-05 09:50:56 +0530669 ath_dbg(common, CHAN_CTX,
670 "Set offchannel_pending to true\n");
Sujith Manoharan922c9432014-08-23 13:29:15 +0530671 return;
672 }
673
674 sc->next_chan = ctx;
675 if (chandef) {
676 ctx->chandef = *chandef;
677 ath_dbg(common, CHAN_CTX,
678 "Assigned next_chan to %d MHz\n", chandef->center_freq1);
679 }
680
681 if (sc->next_chan == &sc->offchannel.chan) {
682 sc->sched.offchannel_duration =
Sujith Manoharanbb628eb2014-09-05 08:03:13 +0530683 jiffies_to_usecs(sc->offchannel.duration) +
Sujith Manoharan922c9432014-08-23 13:29:15 +0530684 sc->sched.channel_switch_time;
685
686 if (chandef) {
687 ath_dbg(common, CHAN_CTX,
688 "Offchannel duration for chan %d MHz : %u\n",
689 chandef->center_freq1,
690 sc->sched.offchannel_duration);
691 }
692 }
693 spin_unlock_bh(&sc->chan_lock);
694 ieee80211_queue_work(sc->hw, &sc->chanctx_work);
695}
696
Sujith Manoharan344ae6a2014-08-23 13:29:13 +0530697static void ath_chanctx_offchan_switch(struct ath_softc *sc,
698 struct ieee80211_channel *chan)
699{
700 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
701 struct cfg80211_chan_def chandef;
702
703 cfg80211_chandef_create(&chandef, chan, NL80211_CHAN_NO_HT);
704 ath_dbg(common, CHAN_CTX,
705 "Channel definition created: %d MHz\n", chandef.center_freq1);
706
707 ath_chanctx_switch(sc, &sc->offchannel.chan, &chandef);
708}
709
Sujith Manoharan98f411b2014-08-23 13:29:14 +0530710static struct ath_chanctx *ath_chanctx_get_oper_chan(struct ath_softc *sc,
711 bool active)
712{
713 struct ath_chanctx *ctx;
714
715 ath_for_each_chanctx(sc, ctx) {
716 if (!ctx->assigned || list_empty(&ctx->vifs))
717 continue;
718 if (active && !ctx->active)
719 continue;
720
721 if (ctx->switch_after_beacon)
722 return ctx;
723 }
724
725 return &sc->chanctx[0];
726}
727
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530728static void
729ath_scan_next_channel(struct ath_softc *sc)
730{
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530731 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530732 struct cfg80211_scan_request *req = sc->offchannel.scan_req;
733 struct ieee80211_channel *chan;
734
735 if (sc->offchannel.scan_idx >= req->n_channels) {
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530736 ath_dbg(common, CHAN_CTX,
Sujith Manoharan878066e2014-08-27 12:07:24 +0530737 "Moving offchannel state to ATH_OFFCHANNEL_IDLE, "
738 "scan_idx: %d, n_channels: %d\n",
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530739 sc->offchannel.scan_idx,
740 req->n_channels);
741
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530742 sc->offchannel.state = ATH_OFFCHANNEL_IDLE;
743 ath_chanctx_switch(sc, ath_chanctx_get_oper_chan(sc, false),
744 NULL);
745 return;
746 }
747
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530748 ath_dbg(common, CHAN_CTX,
Sujith Manoharan878066e2014-08-27 12:07:24 +0530749 "Moving offchannel state to ATH_OFFCHANNEL_PROBE_SEND, scan_idx: %d\n",
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530750 sc->offchannel.scan_idx);
751
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530752 chan = req->channels[sc->offchannel.scan_idx++];
753 sc->offchannel.duration = ath_scan_channel_duration(sc, chan);
754 sc->offchannel.state = ATH_OFFCHANNEL_PROBE_SEND;
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530755
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530756 ath_chanctx_offchan_switch(sc, chan);
757}
758
759void ath_offchannel_next(struct ath_softc *sc)
760{
761 struct ieee80211_vif *vif;
762
763 if (sc->offchannel.scan_req) {
764 vif = sc->offchannel.scan_vif;
765 sc->offchannel.chan.txpower = vif->bss_conf.txpower;
766 ath_scan_next_channel(sc);
767 } else if (sc->offchannel.roc_vif) {
768 vif = sc->offchannel.roc_vif;
769 sc->offchannel.chan.txpower = vif->bss_conf.txpower;
Sujith Manoharanbb628eb2014-09-05 08:03:13 +0530770 sc->offchannel.duration =
771 msecs_to_jiffies(sc->offchannel.roc_duration);
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530772 sc->offchannel.state = ATH_OFFCHANNEL_ROC_START;
773 ath_chanctx_offchan_switch(sc, sc->offchannel.roc_chan);
774 } else {
775 ath_chanctx_switch(sc, ath_chanctx_get_oper_chan(sc, false),
776 NULL);
777 sc->offchannel.state = ATH_OFFCHANNEL_IDLE;
778 if (sc->ps_idle)
779 ath_cancel_work(sc);
780 }
781}
782
783void ath_roc_complete(struct ath_softc *sc, bool abort)
784{
Sujith Manoharan4b60af42014-10-02 06:33:12 +0530785 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
786
787 if (abort)
788 ath_dbg(common, CHAN_CTX, "RoC aborted\n");
789 else
790 ath_dbg(common, CHAN_CTX, "RoC expired\n");
791
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530792 sc->offchannel.roc_vif = NULL;
793 sc->offchannel.roc_chan = NULL;
794 if (!abort)
795 ieee80211_remain_on_channel_expired(sc->hw);
796 ath_offchannel_next(sc);
797 ath9k_ps_restore(sc);
798}
799
800void ath_scan_complete(struct ath_softc *sc, bool abort)
801{
802 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
803
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530804 if (abort)
805 ath_dbg(common, CHAN_CTX, "HW scan aborted\n");
806 else
807 ath_dbg(common, CHAN_CTX, "HW scan complete\n");
808
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530809 sc->offchannel.scan_req = NULL;
810 sc->offchannel.scan_vif = NULL;
811 sc->offchannel.state = ATH_OFFCHANNEL_IDLE;
812 ieee80211_scan_completed(sc->hw, abort);
813 clear_bit(ATH_OP_SCANNING, &common->op_flags);
Sujith Manoharand0975ed2014-09-10 19:15:57 +0530814 spin_lock_bh(&sc->chan_lock);
815 if (test_bit(ATH_OP_MULTI_CHANNEL, &common->op_flags))
816 sc->sched.force_noa_update = true;
817 spin_unlock_bh(&sc->chan_lock);
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530818 ath_offchannel_next(sc);
819 ath9k_ps_restore(sc);
820}
821
822static void ath_scan_send_probe(struct ath_softc *sc,
823 struct cfg80211_ssid *ssid)
824{
825 struct cfg80211_scan_request *req = sc->offchannel.scan_req;
826 struct ieee80211_vif *vif = sc->offchannel.scan_vif;
827 struct ath_tx_control txctl = {};
828 struct sk_buff *skb;
829 struct ieee80211_tx_info *info;
830 int band = sc->offchannel.chan.chandef.chan->band;
831
832 skb = ieee80211_probereq_get(sc->hw, vif,
833 ssid->ssid, ssid->ssid_len, req->ie_len);
834 if (!skb)
835 return;
836
837 info = IEEE80211_SKB_CB(skb);
838 if (req->no_cck)
839 info->flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
840
841 if (req->ie_len)
842 memcpy(skb_put(skb, req->ie_len), req->ie, req->ie_len);
843
844 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
845
846 if (!ieee80211_tx_prepare_skb(sc->hw, vif, skb, band, NULL))
847 goto error;
848
849 txctl.txq = sc->tx.txq_map[IEEE80211_AC_VO];
850 txctl.force_channel = true;
851 if (ath_tx_start(sc->hw, skb, &txctl))
852 goto error;
853
854 return;
855
856error:
857 ieee80211_free_txskb(sc->hw, skb);
858}
859
860static void ath_scan_channel_start(struct ath_softc *sc)
861{
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530862 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530863 struct cfg80211_scan_request *req = sc->offchannel.scan_req;
864 int i;
865
866 if (!(sc->cur_chan->chandef.chan->flags & IEEE80211_CHAN_NO_IR) &&
867 req->n_ssids) {
868 for (i = 0; i < req->n_ssids; i++)
869 ath_scan_send_probe(sc, &req->ssids[i]);
870
871 }
872
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530873 ath_dbg(common, CHAN_CTX,
Sujith Manoharan878066e2014-08-27 12:07:24 +0530874 "Moving offchannel state to ATH_OFFCHANNEL_PROBE_WAIT\n");
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530875
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530876 sc->offchannel.state = ATH_OFFCHANNEL_PROBE_WAIT;
877 mod_timer(&sc->offchannel.timer, jiffies + sc->offchannel.duration);
878}
879
Sujith Manoharan705d0bf2014-08-23 13:29:06 +0530880static void ath_chanctx_timer(unsigned long data)
881{
882 struct ath_softc *sc = (struct ath_softc *) data;
Sujith Manoharan878066e2014-08-27 12:07:24 +0530883 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
884
885 ath_dbg(common, CHAN_CTX,
886 "Channel context timer invoked\n");
Sujith Manoharan705d0bf2014-08-23 13:29:06 +0530887
888 ath_chanctx_event(sc, NULL, ATH_CHANCTX_EVENT_TSF_TIMER);
889}
890
891static void ath_offchannel_timer(unsigned long data)
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530892{
893 struct ath_softc *sc = (struct ath_softc *)data;
894 struct ath_chanctx *ctx;
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530895 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
896
Sujith Manoharan878066e2014-08-27 12:07:24 +0530897 ath_dbg(common, CHAN_CTX, "%s: offchannel state: %s\n",
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530898 __func__, offchannel_state_string(sc->offchannel.state));
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530899
900 switch (sc->offchannel.state) {
901 case ATH_OFFCHANNEL_PROBE_WAIT:
902 if (!sc->offchannel.scan_req)
903 return;
904
905 /* get first active channel context */
906 ctx = ath_chanctx_get_oper_chan(sc, true);
907 if (ctx->active) {
Sujith Manoharan878066e2014-08-27 12:07:24 +0530908 ath_dbg(common, CHAN_CTX,
909 "Switch to oper/active context, "
910 "move offchannel state to ATH_OFFCHANNEL_SUSPEND\n");
911
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530912 sc->offchannel.state = ATH_OFFCHANNEL_SUSPEND;
913 ath_chanctx_switch(sc, ctx, NULL);
914 mod_timer(&sc->offchannel.timer, jiffies + HZ / 10);
915 break;
916 }
917 /* fall through */
918 case ATH_OFFCHANNEL_SUSPEND:
919 if (!sc->offchannel.scan_req)
920 return;
921
922 ath_scan_next_channel(sc);
923 break;
924 case ATH_OFFCHANNEL_ROC_START:
925 case ATH_OFFCHANNEL_ROC_WAIT:
926 ctx = ath_chanctx_get_oper_chan(sc, false);
927 sc->offchannel.state = ATH_OFFCHANNEL_ROC_DONE;
928 ath_chanctx_switch(sc, ctx, NULL);
929 break;
930 default:
931 break;
932 }
933}
Sujith Manoharan2471adf2014-08-22 20:39:29 +0530934
Sujith Manoharan6d7cbd72014-08-23 13:29:10 +0530935static bool
936ath_chanctx_send_vif_ps_frame(struct ath_softc *sc, struct ath_vif *avp,
937 bool powersave)
938{
939 struct ieee80211_vif *vif = avp->vif;
940 struct ieee80211_sta *sta = NULL;
941 struct ieee80211_hdr_3addr *nullfunc;
942 struct ath_tx_control txctl;
943 struct sk_buff *skb;
944 int band = sc->cur_chan->chandef.chan->band;
945
946 switch (vif->type) {
947 case NL80211_IFTYPE_STATION:
Sujith Manoharancb355822014-09-17 14:45:56 +0530948 if (!avp->assoc)
Sujith Manoharan6d7cbd72014-08-23 13:29:10 +0530949 return false;
950
951 skb = ieee80211_nullfunc_get(sc->hw, vif);
952 if (!skb)
953 return false;
954
955 nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
956 if (powersave)
957 nullfunc->frame_control |=
958 cpu_to_le16(IEEE80211_FCTL_PM);
959
960 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
961 if (!ieee80211_tx_prepare_skb(sc->hw, vif, skb, band, &sta)) {
962 dev_kfree_skb_any(skb);
963 return false;
964 }
965 break;
966 default:
967 return false;
968 }
969
970 memset(&txctl, 0, sizeof(txctl));
971 txctl.txq = sc->tx.txq_map[IEEE80211_AC_VO];
972 txctl.sta = sta;
973 txctl.force_channel = true;
974 if (ath_tx_start(sc->hw, skb, &txctl)) {
975 ieee80211_free_txskb(sc->hw, skb);
976 return false;
977 }
978
979 return true;
980}
981
982static bool
983ath_chanctx_send_ps_frame(struct ath_softc *sc, bool powersave)
984{
985 struct ath_vif *avp;
986 bool sent = false;
987
988 rcu_read_lock();
989 list_for_each_entry(avp, &sc->cur_chan->vifs, list) {
990 if (ath_chanctx_send_vif_ps_frame(sc, avp, powersave))
991 sent = true;
992 }
993 rcu_read_unlock();
994
995 return sent;
996}
997
998static bool ath_chanctx_defer_switch(struct ath_softc *sc)
999{
Sujith Manoharan878066e2014-08-27 12:07:24 +05301000 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1001
Sujith Manoharan6d7cbd72014-08-23 13:29:10 +05301002 if (sc->cur_chan == &sc->offchannel.chan)
1003 return false;
1004
1005 switch (sc->sched.state) {
1006 case ATH_CHANCTX_STATE_SWITCH:
1007 return false;
1008 case ATH_CHANCTX_STATE_IDLE:
1009 if (!sc->cur_chan->switch_after_beacon)
1010 return false;
1011
Sujith Manoharan878066e2014-08-27 12:07:24 +05301012 ath_dbg(common, CHAN_CTX,
1013 "Defer switch, set chanctx state to WAIT_FOR_BEACON\n");
1014
Sujith Manoharan6d7cbd72014-08-23 13:29:10 +05301015 sc->sched.state = ATH_CHANCTX_STATE_WAIT_FOR_BEACON;
1016 break;
1017 default:
1018 break;
1019 }
1020
1021 return true;
1022}
1023
Sujith Manoharan55254ee2014-08-23 13:29:11 +05301024static void ath_offchannel_channel_change(struct ath_softc *sc)
1025{
1026 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1027
Sujith Manoharan878066e2014-08-27 12:07:24 +05301028 ath_dbg(common, CHAN_CTX, "%s: offchannel state: %s\n",
Sujith Manoharan55254ee2014-08-23 13:29:11 +05301029 __func__, offchannel_state_string(sc->offchannel.state));
1030
1031 switch (sc->offchannel.state) {
1032 case ATH_OFFCHANNEL_PROBE_SEND:
1033 if (!sc->offchannel.scan_req)
1034 return;
1035
1036 if (sc->cur_chan->chandef.chan !=
1037 sc->offchannel.chan.chandef.chan)
1038 return;
1039
1040 ath_scan_channel_start(sc);
1041 break;
1042 case ATH_OFFCHANNEL_IDLE:
1043 if (!sc->offchannel.scan_req)
1044 return;
1045
1046 ath_scan_complete(sc, false);
1047 break;
1048 case ATH_OFFCHANNEL_ROC_START:
1049 if (sc->cur_chan != &sc->offchannel.chan)
1050 break;
1051
1052 sc->offchannel.state = ATH_OFFCHANNEL_ROC_WAIT;
Sujith Manoharanbb628eb2014-09-05 08:03:13 +05301053 mod_timer(&sc->offchannel.timer,
1054 jiffies + sc->offchannel.duration);
Sujith Manoharan55254ee2014-08-23 13:29:11 +05301055 ieee80211_ready_on_channel(sc->hw);
1056 break;
1057 case ATH_OFFCHANNEL_ROC_DONE:
1058 ath_roc_complete(sc, false);
1059 break;
1060 default:
1061 break;
1062 }
1063}
1064
Sujith Manoharan6d7cbd72014-08-23 13:29:10 +05301065void ath_chanctx_set_next(struct ath_softc *sc, bool force)
1066{
Sujith Manoharan878066e2014-08-27 12:07:24 +05301067 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujith Manoharane2cba8d2014-10-02 06:33:20 +05301068 struct ath_chanctx *old_ctx;
Sujith Manoharan6d7cbd72014-08-23 13:29:10 +05301069 struct timespec ts;
1070 bool measure_time = false;
1071 bool send_ps = false;
Sujith Manoharane2cba8d2014-10-02 06:33:20 +05301072 bool queues_stopped = false;
Sujith Manoharan6d7cbd72014-08-23 13:29:10 +05301073
1074 spin_lock_bh(&sc->chan_lock);
1075 if (!sc->next_chan) {
1076 spin_unlock_bh(&sc->chan_lock);
1077 return;
1078 }
1079
1080 if (!force && ath_chanctx_defer_switch(sc)) {
1081 spin_unlock_bh(&sc->chan_lock);
1082 return;
1083 }
1084
Sujith Manoharan878066e2014-08-27 12:07:24 +05301085 ath_dbg(common, CHAN_CTX,
1086 "%s: current: %d MHz, next: %d MHz\n",
1087 __func__,
1088 sc->cur_chan->chandef.center_freq1,
1089 sc->next_chan->chandef.center_freq1);
1090
Sujith Manoharan6d7cbd72014-08-23 13:29:10 +05301091 if (sc->cur_chan != sc->next_chan) {
Sujith Manoharan878066e2014-08-27 12:07:24 +05301092 ath_dbg(common, CHAN_CTX,
1093 "Stopping current chanctx: %d\n",
1094 sc->cur_chan->chandef.center_freq1);
Sujith Manoharan6d7cbd72014-08-23 13:29:10 +05301095 sc->cur_chan->stopped = true;
1096 spin_unlock_bh(&sc->chan_lock);
1097
1098 if (sc->next_chan == &sc->offchannel.chan) {
1099 getrawmonotonic(&ts);
1100 measure_time = true;
1101 }
Sujith Manoharane2cba8d2014-10-02 06:33:20 +05301102
1103 ath9k_chanctx_stop_queues(sc, sc->cur_chan);
1104 queues_stopped = true;
1105
Sujith Manoharan6d7cbd72014-08-23 13:29:10 +05301106 __ath9k_flush(sc->hw, ~0, true);
1107
1108 if (ath_chanctx_send_ps_frame(sc, true))
1109 __ath9k_flush(sc->hw, BIT(IEEE80211_AC_VO), false);
1110
1111 send_ps = true;
1112 spin_lock_bh(&sc->chan_lock);
1113
1114 if (sc->cur_chan != &sc->offchannel.chan) {
1115 getrawmonotonic(&sc->cur_chan->tsf_ts);
1116 sc->cur_chan->tsf_val = ath9k_hw_gettsf64(sc->sc_ah);
1117 }
1118 }
Sujith Manoharane2cba8d2014-10-02 06:33:20 +05301119 old_ctx = sc->cur_chan;
Sujith Manoharan6d7cbd72014-08-23 13:29:10 +05301120 sc->cur_chan = sc->next_chan;
1121 sc->cur_chan->stopped = false;
1122 sc->next_chan = NULL;
Sujith Manoharan124130d2014-09-10 19:15:58 +05301123
1124 if (!sc->sched.offchannel_pending)
1125 sc->sched.offchannel_duration = 0;
1126
Sujith Manoharan6d7cbd72014-08-23 13:29:10 +05301127 if (sc->sched.state != ATH_CHANCTX_STATE_FORCE_ACTIVE)
1128 sc->sched.state = ATH_CHANCTX_STATE_IDLE;
1129
1130 spin_unlock_bh(&sc->chan_lock);
1131
1132 if (sc->sc_ah->chip_fullsleep ||
1133 memcmp(&sc->cur_chandef, &sc->cur_chan->chandef,
1134 sizeof(sc->cur_chandef))) {
Sujith Manoharan878066e2014-08-27 12:07:24 +05301135 ath_dbg(common, CHAN_CTX,
1136 "%s: Set channel %d MHz\n",
1137 __func__, sc->cur_chan->chandef.center_freq1);
Sujith Manoharan6d7cbd72014-08-23 13:29:10 +05301138 ath_set_channel(sc);
1139 if (measure_time)
1140 sc->sched.channel_switch_time =
1141 ath9k_hw_get_tsf_offset(&ts, NULL);
Sujith Manoharane2cba8d2014-10-02 06:33:20 +05301142 /*
1143 * A reset will ensure that all queues are woken up,
1144 * so there is no need to awaken them again.
1145 */
1146 goto out;
Sujith Manoharan6d7cbd72014-08-23 13:29:10 +05301147 }
Sujith Manoharane2cba8d2014-10-02 06:33:20 +05301148
1149 if (queues_stopped)
1150 ath9k_chanctx_wake_queues(sc, old_ctx);
1151out:
Sujith Manoharan6d7cbd72014-08-23 13:29:10 +05301152 if (send_ps)
1153 ath_chanctx_send_ps_frame(sc, false);
1154
1155 ath_offchannel_channel_change(sc);
1156 ath_chanctx_event(sc, NULL, ATH_CHANCTX_EVENT_SWITCH);
1157}
1158
Sujith Manoharan0e62f8b2014-08-23 13:29:08 +05301159static void ath_chanctx_work(struct work_struct *work)
1160{
1161 struct ath_softc *sc = container_of(work, struct ath_softc,
1162 chanctx_work);
1163 mutex_lock(&sc->mutex);
1164 ath_chanctx_set_next(sc, false);
1165 mutex_unlock(&sc->mutex);
1166}
1167
Sujith Manoharane90e3022014-08-23 13:29:20 +05301168void ath9k_offchannel_init(struct ath_softc *sc)
1169{
1170 struct ath_chanctx *ctx;
1171 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1172 struct ieee80211_supported_band *sband;
1173 struct ieee80211_channel *chan;
1174 int i;
1175
1176 sband = &common->sbands[IEEE80211_BAND_2GHZ];
1177 if (!sband->n_channels)
1178 sband = &common->sbands[IEEE80211_BAND_5GHZ];
1179
1180 chan = &sband->channels[0];
1181
1182 ctx = &sc->offchannel.chan;
1183 INIT_LIST_HEAD(&ctx->vifs);
1184 ctx->txpower = ATH_TXPOWER_MAX;
1185 cfg80211_chandef_create(&ctx->chandef, chan, NL80211_CHAN_HT20);
1186
1187 for (i = 0; i < ARRAY_SIZE(ctx->acq); i++)
1188 INIT_LIST_HEAD(&ctx->acq[i]);
1189
1190 sc->offchannel.chan.offchannel = true;
1191}
1192
Sujith Manoharan705d0bf2014-08-23 13:29:06 +05301193void ath9k_init_channel_context(struct ath_softc *sc)
1194{
1195 INIT_WORK(&sc->chanctx_work, ath_chanctx_work);
1196
1197 setup_timer(&sc->offchannel.timer, ath_offchannel_timer,
1198 (unsigned long)sc);
1199 setup_timer(&sc->sched.timer, ath_chanctx_timer,
1200 (unsigned long)sc);
1201}
Sujith Manoharanc7dd40c2014-08-22 20:39:30 +05301202
Sujith Manoharanea22df22014-08-23 13:29:07 +05301203void ath9k_deinit_channel_context(struct ath_softc *sc)
1204{
1205 cancel_work_sync(&sc->chanctx_work);
1206}
1207
Sujith Manoharan499afac2014-08-22 20:39:31 +05301208bool ath9k_is_chanctx_enabled(void)
1209{
1210 return (ath9k_use_chanctx == 1);
1211}
1212
Sujith Manoharan0e08b5f2014-08-23 13:29:19 +05301213/********************/
1214/* Queue management */
1215/********************/
1216
Sujith Manoharana064eaa2014-10-02 06:33:18 +05301217void ath9k_chanctx_stop_queues(struct ath_softc *sc, struct ath_chanctx *ctx)
1218{
1219 struct ath_hw *ah = sc->sc_ah;
1220 int i;
1221
1222 if (ctx == &sc->offchannel.chan) {
1223 ieee80211_stop_queue(sc->hw,
1224 sc->hw->offchannel_tx_hw_queue);
1225 } else {
1226 for (i = 0; i < IEEE80211_NUM_ACS; i++)
1227 ieee80211_stop_queue(sc->hw,
1228 ctx->hw_queue_base + i);
1229 }
1230
1231 if (ah->opmode == NL80211_IFTYPE_AP)
1232 ieee80211_stop_queue(sc->hw, sc->hw->queues - 2);
1233}
1234
1235
Sujith Manoharanb3903152014-10-02 06:33:17 +05301236void ath9k_chanctx_wake_queues(struct ath_softc *sc, struct ath_chanctx *ctx)
Sujith Manoharan0e08b5f2014-08-23 13:29:19 +05301237{
1238 struct ath_hw *ah = sc->sc_ah;
1239 int i;
1240
Sujith Manoharanb3903152014-10-02 06:33:17 +05301241 if (ctx == &sc->offchannel.chan) {
Sujith Manoharan0e08b5f2014-08-23 13:29:19 +05301242 ieee80211_wake_queue(sc->hw,
1243 sc->hw->offchannel_tx_hw_queue);
1244 } else {
1245 for (i = 0; i < IEEE80211_NUM_ACS; i++)
1246 ieee80211_wake_queue(sc->hw,
Sujith Manoharanb3903152014-10-02 06:33:17 +05301247 ctx->hw_queue_base + i);
Sujith Manoharan0e08b5f2014-08-23 13:29:19 +05301248 }
1249
1250 if (ah->opmode == NL80211_IFTYPE_AP)
1251 ieee80211_wake_queue(sc->hw, sc->hw->queues - 2);
1252}
1253
Sujith Manoharanc7dd40c2014-08-22 20:39:30 +05301254/*****************/
1255/* P2P Powersave */
1256/*****************/
1257
1258static void ath9k_update_p2p_ps_timer(struct ath_softc *sc, struct ath_vif *avp)
Sujith Manoharan2471adf2014-08-22 20:39:29 +05301259{
1260 struct ath_hw *ah = sc->sc_ah;
1261 s32 tsf, target_tsf;
1262
1263 if (!avp || !avp->noa.has_next_tsf)
1264 return;
1265
1266 ath9k_hw_gen_timer_stop(ah, sc->p2p_ps_timer);
1267
1268 tsf = ath9k_hw_gettsf32(sc->sc_ah);
1269
1270 target_tsf = avp->noa.next_tsf;
1271 if (!avp->noa.absent)
1272 target_tsf -= ATH_P2P_PS_STOP_TIME;
1273
1274 if (target_tsf - tsf < ATH_P2P_PS_STOP_TIME)
1275 target_tsf = tsf + ATH_P2P_PS_STOP_TIME;
1276
1277 ath9k_hw_gen_timer_start(ah, sc->p2p_ps_timer, (u32) target_tsf, 1000000);
1278}
1279
Sujith Manoharanc7dd40c2014-08-22 20:39:30 +05301280static void ath9k_update_p2p_ps(struct ath_softc *sc, struct ieee80211_vif *vif)
1281{
1282 struct ath_vif *avp = (void *)vif->drv_priv;
1283 u32 tsf;
1284
1285 if (!sc->p2p_ps_timer)
1286 return;
1287
1288 if (vif->type != NL80211_IFTYPE_STATION || !vif->p2p)
1289 return;
1290
1291 sc->p2p_ps_vif = avp;
1292 tsf = ath9k_hw_gettsf32(sc->sc_ah);
1293 ieee80211_parse_p2p_noa(&vif->bss_conf.p2p_noa_attr, &avp->noa, tsf);
1294 ath9k_update_p2p_ps_timer(sc, avp);
1295}
1296
Sujith Manoharanfdcf1bd2014-09-05 08:03:14 +05301297static u8 ath9k_get_ctwin(struct ath_softc *sc, struct ath_vif *avp)
1298{
1299 struct ath_beacon_config *cur_conf = &sc->cur_chan->beacon;
1300 u8 switch_time, ctwin;
1301
1302 /*
1303 * Channel switch in multi-channel mode is deferred
1304 * by a quarter beacon interval when handling
1305 * ATH_CHANCTX_EVENT_BEACON_PREPARE, so the P2P-GO
1306 * interface is guaranteed to be discoverable
1307 * for that duration after a TBTT.
1308 */
1309 switch_time = cur_conf->beacon_interval / 4;
1310
1311 ctwin = avp->vif->bss_conf.p2p_noa_attr.oppps_ctwindow;
1312 if (ctwin && (ctwin < switch_time))
1313 return ctwin;
1314
1315 if (switch_time < P2P_DEFAULT_CTWIN)
1316 return 0;
1317
1318 return P2P_DEFAULT_CTWIN;
1319}
1320
Sujith Manoharan11e39a42014-08-23 19:12:15 +05301321void ath9k_beacon_add_noa(struct ath_softc *sc, struct ath_vif *avp,
1322 struct sk_buff *skb)
1323{
1324 static const u8 noa_ie_hdr[] = {
1325 WLAN_EID_VENDOR_SPECIFIC, /* type */
1326 0, /* length */
1327 0x50, 0x6f, 0x9a, /* WFA OUI */
1328 0x09, /* P2P subtype */
1329 0x0c, /* Notice of Absence */
1330 0x00, /* LSB of little-endian len */
1331 0x00, /* MSB of little-endian len */
1332 };
1333
1334 struct ieee80211_p2p_noa_attr *noa;
1335 int noa_len, noa_desc, i = 0;
1336 u8 *hdr;
1337
Sujith Manoharand0975ed2014-09-10 19:15:57 +05301338 if (!avp->offchannel_duration && !avp->noa_duration)
Sujith Manoharan11e39a42014-08-23 19:12:15 +05301339 return;
1340
Sujith Manoharand0975ed2014-09-10 19:15:57 +05301341 noa_desc = !!avp->offchannel_duration + !!avp->noa_duration;
Sujith Manoharan11e39a42014-08-23 19:12:15 +05301342 noa_len = 2 + sizeof(struct ieee80211_p2p_noa_desc) * noa_desc;
1343
1344 hdr = skb_put(skb, sizeof(noa_ie_hdr));
1345 memcpy(hdr, noa_ie_hdr, sizeof(noa_ie_hdr));
1346 hdr[1] = sizeof(noa_ie_hdr) + noa_len - 2;
1347 hdr[7] = noa_len;
1348
1349 noa = (void *) skb_put(skb, noa_len);
1350 memset(noa, 0, noa_len);
1351
1352 noa->index = avp->noa_index;
Sujith Manoharanfdcf1bd2014-09-05 08:03:14 +05301353 noa->oppps_ctwindow = ath9k_get_ctwin(sc, avp);
1354
Sujith Manoharand0975ed2014-09-10 19:15:57 +05301355 if (avp->noa_duration) {
1356 if (avp->periodic_noa) {
1357 u32 interval = TU_TO_USEC(sc->cur_chan->beacon.beacon_interval);
1358 noa->desc[i].count = 255;
1359 noa->desc[i].interval = cpu_to_le32(interval);
1360 } else {
1361 noa->desc[i].count = 1;
1362 }
Sujith Manoharan11e39a42014-08-23 19:12:15 +05301363
Sujith Manoharand0975ed2014-09-10 19:15:57 +05301364 noa->desc[i].start_time = cpu_to_le32(avp->noa_start);
1365 noa->desc[i].duration = cpu_to_le32(avp->noa_duration);
Sujith Manoharan11e39a42014-08-23 19:12:15 +05301366 i++;
1367 }
1368
1369 if (avp->offchannel_duration) {
1370 noa->desc[i].count = 1;
1371 noa->desc[i].start_time = cpu_to_le32(avp->offchannel_start);
1372 noa->desc[i].duration = cpu_to_le32(avp->offchannel_duration);
1373 }
1374}
1375
Sujith Manoharan2471adf2014-08-22 20:39:29 +05301376void ath9k_p2p_ps_timer(void *priv)
1377{
1378 struct ath_softc *sc = priv;
1379 struct ath_vif *avp = sc->p2p_ps_vif;
1380 struct ieee80211_vif *vif;
1381 struct ieee80211_sta *sta;
1382 struct ath_node *an;
1383 u32 tsf;
1384
1385 del_timer_sync(&sc->sched.timer);
1386 ath9k_hw_gen_timer_stop(sc->sc_ah, sc->p2p_ps_timer);
1387 ath_chanctx_event(sc, NULL, ATH_CHANCTX_EVENT_TSF_TIMER);
1388
1389 if (!avp || avp->chanctx != sc->cur_chan)
1390 return;
1391
1392 tsf = ath9k_hw_gettsf32(sc->sc_ah);
1393 if (!avp->noa.absent)
1394 tsf += ATH_P2P_PS_STOP_TIME;
1395
1396 if (!avp->noa.has_next_tsf ||
1397 avp->noa.next_tsf - tsf > BIT(31))
1398 ieee80211_update_p2p_noa(&avp->noa, tsf);
1399
1400 ath9k_update_p2p_ps_timer(sc, avp);
1401
1402 rcu_read_lock();
1403
1404 vif = avp->vif;
Sujith Manoharancb355822014-09-17 14:45:56 +05301405 sta = ieee80211_find_sta(vif, avp->bssid);
Sujith Manoharan2471adf2014-08-22 20:39:29 +05301406 if (!sta)
1407 goto out;
1408
1409 an = (void *) sta->drv_priv;
1410 if (an->sleeping == !!avp->noa.absent)
1411 goto out;
1412
1413 an->sleeping = avp->noa.absent;
1414 if (an->sleeping)
1415 ath_tx_aggr_sleep(sta, sc, an);
1416 else
1417 ath_tx_aggr_wakeup(sc, an);
1418
1419out:
1420 rcu_read_unlock();
1421}
1422
Sujith Manoharanc7dd40c2014-08-22 20:39:30 +05301423void ath9k_p2p_bss_info_changed(struct ath_softc *sc,
1424 struct ieee80211_vif *vif)
1425{
1426 unsigned long flags;
1427
1428 spin_lock_bh(&sc->sc_pcu_lock);
1429 spin_lock_irqsave(&sc->sc_pm_lock, flags);
1430 if (!(sc->ps_flags & PS_BEACON_SYNC))
1431 ath9k_update_p2p_ps(sc, vif);
1432 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
1433 spin_unlock_bh(&sc->sc_pcu_lock);
1434}
1435
1436void ath9k_p2p_beacon_sync(struct ath_softc *sc)
1437{
1438 if (sc->p2p_ps_vif)
1439 ath9k_update_p2p_ps(sc, sc->p2p_ps_vif->vif);
1440}
1441
1442void ath9k_p2p_remove_vif(struct ath_softc *sc,
1443 struct ieee80211_vif *vif)
Sujith Manoharan2471adf2014-08-22 20:39:29 +05301444{
1445 struct ath_vif *avp = (void *)vif->drv_priv;
Sujith Manoharan2471adf2014-08-22 20:39:29 +05301446
Sujith Manoharanc7dd40c2014-08-22 20:39:30 +05301447 spin_lock_bh(&sc->sc_pcu_lock);
1448 if (avp == sc->p2p_ps_vif) {
1449 sc->p2p_ps_vif = NULL;
1450 ath9k_update_p2p_ps_timer(sc, NULL);
1451 }
1452 spin_unlock_bh(&sc->sc_pcu_lock);
Sujith Manoharan2471adf2014-08-22 20:39:29 +05301453}
Sujith Manoharanc7dd40c2014-08-22 20:39:30 +05301454
1455int ath9k_init_p2p(struct ath_softc *sc)
1456{
1457 sc->p2p_ps_timer = ath_gen_timer_alloc(sc->sc_ah, ath9k_p2p_ps_timer,
1458 NULL, sc, AR_FIRST_NDP_TIMER);
1459 if (!sc->p2p_ps_timer)
1460 return -ENOMEM;
1461
1462 return 0;
1463}
1464
1465void ath9k_deinit_p2p(struct ath_softc *sc)
1466{
1467 if (sc->p2p_ps_timer)
1468 ath_gen_timer_free(sc->sc_ah, sc->p2p_ps_timer);
1469}
1470
1471#endif /* CONFIG_ATH9K_CHANNEL_CONTEXT */