blob: 1950da4c73fe3b024f8c4ef4d89b0587ad0472e5 [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];
69 r = ath_reset_internal(sc, hchan);
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
86 /* set HW specific DFS configuration */
87 ath9k_hw_set_radar_params(ah);
88 rxfilter = ath9k_hw_getrxfilter(ah);
89 rxfilter |= ATH9K_RX_FILTER_PHYRADAR |
90 ATH9K_RX_FILTER_PHYERR;
91 ath9k_hw_setrxfilter(ah, rxfilter);
92 ath_dbg(common, DFS, "DFS enabled at freq %d\n",
93 chan->center_freq);
94 } else {
95 /* perform spectral scan if requested. */
96 if (test_bit(ATH_OP_SCANNING, &common->op_flags) &&
97 sc->spectral_mode == SPECTRAL_CHANSCAN)
98 ath9k_spectral_scan_trigger(hw);
99 }
100
101 return 0;
102}
103
Felix Fietkauc083ce92014-06-11 16:17:54 +0530104void ath_chanctx_check_active(struct ath_softc *sc, struct ath_chanctx *ctx)
105{
Felix Fietkau26f16c22014-06-11 16:18:00 +0530106 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Felix Fietkauc083ce92014-06-11 16:17:54 +0530107 struct ath_vif *avp;
108 bool active = false;
Felix Fietkau26f16c22014-06-11 16:18:00 +0530109 u8 n_active = 0;
Felix Fietkauc083ce92014-06-11 16:17:54 +0530110
111 if (!ctx)
112 return;
113
114 list_for_each_entry(avp, &ctx->vifs, list) {
115 struct ieee80211_vif *vif = avp->vif;
116
117 switch (vif->type) {
118 case NL80211_IFTYPE_P2P_CLIENT:
119 case NL80211_IFTYPE_STATION:
120 if (vif->bss_conf.assoc)
121 active = true;
122 break;
123 default:
124 active = true;
125 break;
126 }
127 }
128 ctx->active = active;
Felix Fietkau26f16c22014-06-11 16:18:00 +0530129
130 ath_for_each_chanctx(sc, ctx) {
131 if (!ctx->assigned || list_empty(&ctx->vifs))
132 continue;
133 n_active++;
134 }
135
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530136 if (n_active <= 1) {
Felix Fietkau26f16c22014-06-11 16:18:00 +0530137 clear_bit(ATH_OP_MULTI_CHANNEL, &common->op_flags);
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530138 return;
139 }
140 if (test_and_set_bit(ATH_OP_MULTI_CHANNEL, &common->op_flags))
141 return;
142 ath_chanctx_event(sc, NULL, ATH_CHANCTX_EVENT_ENABLE_MULTICHANNEL);
Felix Fietkauc083ce92014-06-11 16:17:54 +0530143}
144
Felix Fietkaufbbcd142014-06-11 16:17:49 +0530145void ath_chanctx_init(struct ath_softc *sc)
146{
147 struct ath_chanctx *ctx;
148 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
149 struct ieee80211_supported_band *sband;
150 struct ieee80211_channel *chan;
Felix Fietkau04535312014-06-11 16:17:51 +0530151 int i, j;
Felix Fietkaufbbcd142014-06-11 16:17:49 +0530152
153 sband = &common->sbands[IEEE80211_BAND_2GHZ];
154 if (!sband->n_channels)
155 sband = &common->sbands[IEEE80211_BAND_5GHZ];
156
157 chan = &sband->channels[0];
158 for (i = 0; i < ATH9K_NUM_CHANCTX; i++) {
159 ctx = &sc->chanctx[i];
160 cfg80211_chandef_create(&ctx->chandef, chan, NL80211_CHAN_HT20);
161 INIT_LIST_HEAD(&ctx->vifs);
Felix Fietkaubc7e1be2014-06-11 16:17:50 +0530162 ctx->txpower = ATH_TXPOWER_MAX;
Felix Fietkau04535312014-06-11 16:17:51 +0530163 for (j = 0; j < ARRAY_SIZE(ctx->acq); j++)
164 INIT_LIST_HEAD(&ctx->acq[j]);
Felix Fietkaufbbcd142014-06-11 16:17:49 +0530165 }
Felix Fietkau78b21942014-06-11 16:17:55 +0530166 ctx = &sc->offchannel.chan;
167 cfg80211_chandef_create(&ctx->chandef, chan, NL80211_CHAN_HT20);
168 INIT_LIST_HEAD(&ctx->vifs);
169 ctx->txpower = ATH_TXPOWER_MAX;
170 for (j = 0; j < ARRAY_SIZE(ctx->acq); j++)
171 INIT_LIST_HEAD(&ctx->acq[j]);
172 sc->offchannel.chan.offchannel = true;
173
Felix Fietkaufbbcd142014-06-11 16:17:49 +0530174}
175
Felix Fietkaubff11762014-06-11 16:17:52 +0530176void ath_chanctx_switch(struct ath_softc *sc, struct ath_chanctx *ctx,
177 struct cfg80211_chan_def *chandef)
Felix Fietkaufbbcd142014-06-11 16:17:49 +0530178{
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530179 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Felix Fietkaufbbcd142014-06-11 16:17:49 +0530180
Felix Fietkaubff11762014-06-11 16:17:52 +0530181 spin_lock_bh(&sc->chan_lock);
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530182
183 if (test_bit(ATH_OP_MULTI_CHANNEL, &common->op_flags) &&
184 (sc->cur_chan != ctx) && (ctx == &sc->offchannel.chan)) {
185 sc->sched.offchannel_pending = true;
186 spin_unlock_bh(&sc->chan_lock);
187 return;
188 }
189
Felix Fietkaubff11762014-06-11 16:17:52 +0530190 sc->next_chan = ctx;
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530191 if (chandef) {
Felix Fietkaubff11762014-06-11 16:17:52 +0530192 ctx->chandef = *chandef;
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530193 ath_dbg(common, CHAN_CTX,
194 "Assigned next_chan to %d MHz\n", chandef->center_freq1);
195 }
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530196
197 if (sc->next_chan == &sc->offchannel.chan) {
198 sc->sched.offchannel_duration =
199 TU_TO_USEC(sc->offchannel.duration) +
200 sc->sched.channel_switch_time;
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530201
202 if (chandef) {
203 ath_dbg(common, CHAN_CTX,
204 "Offchannel duration for chan %d MHz : %u\n",
205 chandef->center_freq1,
206 sc->sched.offchannel_duration);
207 }
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530208 }
Felix Fietkaubff11762014-06-11 16:17:52 +0530209 spin_unlock_bh(&sc->chan_lock);
210 ieee80211_queue_work(sc->hw, &sc->chanctx_work);
211}
212
213void ath_chanctx_set_channel(struct ath_softc *sc, struct ath_chanctx *ctx,
214 struct cfg80211_chan_def *chandef)
215{
216 bool cur_chan;
217
218 spin_lock_bh(&sc->chan_lock);
219 if (chandef)
220 memcpy(&ctx->chandef, chandef, sizeof(*chandef));
221 cur_chan = sc->cur_chan == ctx;
222 spin_unlock_bh(&sc->chan_lock);
223
224 if (!cur_chan)
225 return;
226
227 ath_set_channel(sc);
Felix Fietkaufbbcd142014-06-11 16:17:49 +0530228}
Felix Fietkau78b21942014-06-11 16:17:55 +0530229
Felix Fietkau58b57372014-06-11 16:18:08 +0530230static struct ath_chanctx *
231ath_chanctx_get_next(struct ath_softc *sc, struct ath_chanctx *ctx)
232{
233 int idx = ctx - &sc->chanctx[0];
234
235 return &sc->chanctx[!idx];
236}
237
238static void ath_chanctx_adjust_tbtt_delta(struct ath_softc *sc)
239{
240 struct ath_chanctx *prev, *cur;
241 struct timespec ts;
242 u32 cur_tsf, prev_tsf, beacon_int;
243 s32 offset;
244
245 beacon_int = TU_TO_USEC(sc->cur_chan->beacon.beacon_interval);
246
247 cur = sc->cur_chan;
248 prev = ath_chanctx_get_next(sc, cur);
249
250 getrawmonotonic(&ts);
251 cur_tsf = (u32) cur->tsf_val +
252 ath9k_hw_get_tsf_offset(&cur->tsf_ts, &ts);
253
254 prev_tsf = prev->last_beacon - (u32) prev->tsf_val + cur_tsf;
255 prev_tsf -= ath9k_hw_get_tsf_offset(&prev->tsf_ts, &ts);
256
257 /* Adjust the TSF time of the AP chanctx to keep its beacons
258 * at half beacon interval offset relative to the STA chanctx.
259 */
260 offset = cur_tsf - prev_tsf;
261
262 /* Ignore stale data or spurious timestamps */
263 if (offset < 0 || offset > 3 * beacon_int)
264 return;
265
266 offset = beacon_int / 2 - (offset % beacon_int);
267 prev->tsf_val += offset;
268}
269
Felix Fietkau42eda112014-06-11 16:18:14 +0530270/* Configure the TSF based hardware timer for a channel switch.
271 * Also set up backup software timer, in case the gen timer fails.
272 * This could be caused by a hardware reset.
273 */
274static void ath_chanctx_setup_timer(struct ath_softc *sc, u32 tsf_time)
275{
276 struct ath_hw *ah = sc->sc_ah;
277
Sujith Manoharanc7dd40c2014-08-22 20:39:30 +0530278#ifdef CONFIG_ATH9K_CHANNEL_CONTEXT
Felix Fietkau42eda112014-06-11 16:18:14 +0530279 ath9k_hw_gen_timer_start(ah, sc->p2p_ps_timer, tsf_time, 1000000);
Sujith Manoharanc7dd40c2014-08-22 20:39:30 +0530280#endif
Felix Fietkau42eda112014-06-11 16:18:14 +0530281 tsf_time -= ath9k_hw_gettsf32(ah);
282 tsf_time = msecs_to_jiffies(tsf_time / 1000) + 1;
283 mod_timer(&sc->sched.timer, tsf_time);
284}
285
Felix Fietkau748299f2014-06-11 16:18:04 +0530286void ath_chanctx_event(struct ath_softc *sc, struct ieee80211_vif *vif,
287 enum ath_chanctx_event ev)
288{
289 struct ath_hw *ah = sc->sc_ah;
Felix Fietkau58b57372014-06-11 16:18:08 +0530290 struct ath_common *common = ath9k_hw_common(ah);
Felix Fietkau74148632014-06-11 16:18:11 +0530291 struct ath_beacon_config *cur_conf;
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530292 struct ath_vif *avp = NULL;
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530293 struct ath_chanctx *ctx;
Felix Fietkau748299f2014-06-11 16:18:04 +0530294 u32 tsf_time;
Felix Fietkauec70abe2014-06-11 16:18:12 +0530295 u32 beacon_int;
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530296 bool noa_changed = false;
297
298 if (vif)
299 avp = (struct ath_vif *) vif->drv_priv;
Felix Fietkau748299f2014-06-11 16:18:04 +0530300
301 spin_lock_bh(&sc->chan_lock);
302
303 switch (ev) {
304 case ATH_CHANCTX_EVENT_BEACON_PREPARE:
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530305 if (avp->offchannel_duration)
306 avp->offchannel_duration = 0;
307
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530308 if (avp->chanctx != sc->cur_chan)
309 break;
310
311 if (sc->sched.offchannel_pending) {
312 sc->sched.offchannel_pending = false;
313 sc->next_chan = &sc->offchannel.chan;
314 sc->sched.state = ATH_CHANCTX_STATE_WAIT_FOR_BEACON;
315 }
316
317 ctx = ath_chanctx_get_next(sc, sc->cur_chan);
318 if (ctx->active && sc->sched.state == ATH_CHANCTX_STATE_IDLE) {
319 sc->next_chan = ctx;
320 sc->sched.state = ATH_CHANCTX_STATE_WAIT_FOR_BEACON;
321 }
322
323 /* if the timer missed its window, use the next interval */
324 if (sc->sched.state == ATH_CHANCTX_STATE_WAIT_FOR_TIMER)
325 sc->sched.state = ATH_CHANCTX_STATE_WAIT_FOR_BEACON;
326
Felix Fietkau748299f2014-06-11 16:18:04 +0530327 if (sc->sched.state != ATH_CHANCTX_STATE_WAIT_FOR_BEACON)
328 break;
329
330 sc->sched.beacon_pending = true;
331 sc->sched.next_tbtt = REG_READ(ah, AR_NEXT_TBTT_TIMER);
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530332
Felix Fietkau74148632014-06-11 16:18:11 +0530333 cur_conf = &sc->cur_chan->beacon;
Felix Fietkauec70abe2014-06-11 16:18:12 +0530334 beacon_int = TU_TO_USEC(cur_conf->beacon_interval);
335
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530336 /* defer channel switch by a quarter beacon interval */
Felix Fietkauec70abe2014-06-11 16:18:12 +0530337 tsf_time = sc->sched.next_tbtt + beacon_int / 4;
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530338 sc->sched.switch_start_time = tsf_time;
Felix Fietkau58b57372014-06-11 16:18:08 +0530339 sc->cur_chan->last_beacon = sc->sched.next_tbtt;
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530340
Felix Fietkau74148632014-06-11 16:18:11 +0530341 /* Prevent wrap-around issues */
342 if (avp->periodic_noa_duration &&
343 tsf_time - avp->periodic_noa_start > BIT(30))
344 avp->periodic_noa_duration = 0;
345
346 if (ctx->active && !avp->periodic_noa_duration) {
347 avp->periodic_noa_start = tsf_time;
348 avp->periodic_noa_duration =
349 TU_TO_USEC(cur_conf->beacon_interval) / 2 -
350 sc->sched.channel_switch_time;
351 noa_changed = true;
352 } else if (!ctx->active && avp->periodic_noa_duration) {
353 avp->periodic_noa_duration = 0;
354 noa_changed = true;
355 }
356
Felix Fietkauec70abe2014-06-11 16:18:12 +0530357 /* If at least two consecutive beacons were missed on the STA
358 * chanctx, stay on the STA channel for one extra beacon period,
359 * to resync the timer properly.
360 */
361 if (ctx->active && sc->sched.beacon_miss >= 2)
362 sc->sched.offchannel_duration = 3 * beacon_int / 2;
363
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530364 if (sc->sched.offchannel_duration) {
365 noa_changed = true;
366 avp->offchannel_start = tsf_time;
367 avp->offchannel_duration =
368 sc->sched.offchannel_duration;
369 }
370
371 if (noa_changed)
372 avp->noa_index++;
Felix Fietkau748299f2014-06-11 16:18:04 +0530373 break;
374 case ATH_CHANCTX_EVENT_BEACON_SENT:
375 if (!sc->sched.beacon_pending)
376 break;
377
378 sc->sched.beacon_pending = false;
379 if (sc->sched.state != ATH_CHANCTX_STATE_WAIT_FOR_BEACON)
380 break;
381
Felix Fietkau748299f2014-06-11 16:18:04 +0530382 sc->sched.state = ATH_CHANCTX_STATE_WAIT_FOR_TIMER;
Felix Fietkau42eda112014-06-11 16:18:14 +0530383 ath_chanctx_setup_timer(sc, sc->sched.switch_start_time);
Felix Fietkau748299f2014-06-11 16:18:04 +0530384 break;
385 case ATH_CHANCTX_EVENT_TSF_TIMER:
386 if (sc->sched.state != ATH_CHANCTX_STATE_WAIT_FOR_TIMER)
387 break;
388
Felix Fietkauec70abe2014-06-11 16:18:12 +0530389 if (!sc->cur_chan->switch_after_beacon &&
390 sc->sched.beacon_pending)
391 sc->sched.beacon_miss++;
392
Felix Fietkau748299f2014-06-11 16:18:04 +0530393 sc->sched.state = ATH_CHANCTX_STATE_SWITCH;
394 ieee80211_queue_work(sc->hw, &sc->chanctx_work);
395 break;
Felix Fietkau58b57372014-06-11 16:18:08 +0530396 case ATH_CHANCTX_EVENT_BEACON_RECEIVED:
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530397 if (!test_bit(ATH_OP_MULTI_CHANNEL, &common->op_flags) ||
398 sc->cur_chan == &sc->offchannel.chan)
Felix Fietkau58b57372014-06-11 16:18:08 +0530399 break;
400
401 ath_chanctx_adjust_tbtt_delta(sc);
Felix Fietkauec70abe2014-06-11 16:18:12 +0530402 sc->sched.beacon_pending = false;
403 sc->sched.beacon_miss = 0;
Felix Fietkaua899b672014-06-11 16:18:13 +0530404
405 /* TSF time might have been updated by the incoming beacon,
406 * need update the channel switch timer to reflect the change.
407 */
408 tsf_time = sc->sched.switch_start_time;
409 tsf_time -= (u32) sc->cur_chan->tsf_val +
410 ath9k_hw_get_tsf_offset(&sc->cur_chan->tsf_ts, NULL);
411 tsf_time += ath9k_hw_gettsf32(ah);
412
Felix Fietkau42eda112014-06-11 16:18:14 +0530413
414 ath_chanctx_setup_timer(sc, tsf_time);
Felix Fietkau58b57372014-06-11 16:18:08 +0530415 break;
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530416 case ATH_CHANCTX_EVENT_ASSOC:
417 if (sc->sched.state != ATH_CHANCTX_STATE_FORCE_ACTIVE ||
418 avp->chanctx != sc->cur_chan)
419 break;
420
421 sc->sched.state = ATH_CHANCTX_STATE_IDLE;
422 /* fall through */
423 case ATH_CHANCTX_EVENT_SWITCH:
424 if (!test_bit(ATH_OP_MULTI_CHANNEL, &common->op_flags) ||
425 sc->sched.state == ATH_CHANCTX_STATE_FORCE_ACTIVE ||
426 sc->cur_chan->switch_after_beacon ||
427 sc->cur_chan == &sc->offchannel.chan)
428 break;
429
430 /* If this is a station chanctx, stay active for a half
431 * beacon period (minus channel switch time)
432 */
433 sc->next_chan = ath_chanctx_get_next(sc, sc->cur_chan);
Felix Fietkau74148632014-06-11 16:18:11 +0530434 cur_conf = &sc->cur_chan->beacon;
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530435
436 sc->sched.state = ATH_CHANCTX_STATE_WAIT_FOR_TIMER;
Felix Fietkauec70abe2014-06-11 16:18:12 +0530437
438 tsf_time = TU_TO_USEC(cur_conf->beacon_interval) / 2;
439 if (sc->sched.beacon_miss >= 2) {
440 sc->sched.beacon_miss = 0;
441 tsf_time *= 3;
442 }
443
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530444 tsf_time -= sc->sched.channel_switch_time;
Felix Fietkauec70abe2014-06-11 16:18:12 +0530445 tsf_time += ath9k_hw_gettsf32(sc->sc_ah);
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530446 sc->sched.switch_start_time = tsf_time;
447
Felix Fietkau42eda112014-06-11 16:18:14 +0530448 ath_chanctx_setup_timer(sc, tsf_time);
Felix Fietkauec70abe2014-06-11 16:18:12 +0530449 sc->sched.beacon_pending = true;
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530450 break;
451 case ATH_CHANCTX_EVENT_ENABLE_MULTICHANNEL:
452 if (sc->cur_chan == &sc->offchannel.chan ||
453 sc->cur_chan->switch_after_beacon)
454 break;
455
456 sc->next_chan = ath_chanctx_get_next(sc, sc->cur_chan);
457 ieee80211_queue_work(sc->hw, &sc->chanctx_work);
458 break;
459 case ATH_CHANCTX_EVENT_UNASSIGN:
460 if (sc->cur_chan->assigned) {
461 if (sc->next_chan && !sc->next_chan->assigned &&
462 sc->next_chan != &sc->offchannel.chan)
463 sc->sched.state = ATH_CHANCTX_STATE_IDLE;
464 break;
465 }
466
467 ctx = ath_chanctx_get_next(sc, sc->cur_chan);
468 sc->sched.state = ATH_CHANCTX_STATE_IDLE;
469 if (!ctx->assigned)
470 break;
471
472 sc->next_chan = ctx;
473 ieee80211_queue_work(sc->hw, &sc->chanctx_work);
474 break;
Felix Fietkau748299f2014-06-11 16:18:04 +0530475 }
476
477 spin_unlock_bh(&sc->chan_lock);
478}
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530479
Sujith Manoharan22dc0de2014-08-23 13:29:12 +0530480#ifdef CONFIG_ATH9K_CHANNEL_CONTEXT
481
482static const char *offchannel_state_string(enum ath_offchannel_state state)
483{
484#define case_rtn_string(val) case val: return #val
485
486 switch (state) {
487 case_rtn_string(ATH_OFFCHANNEL_IDLE);
488 case_rtn_string(ATH_OFFCHANNEL_PROBE_SEND);
489 case_rtn_string(ATH_OFFCHANNEL_PROBE_WAIT);
490 case_rtn_string(ATH_OFFCHANNEL_SUSPEND);
491 case_rtn_string(ATH_OFFCHANNEL_ROC_START);
492 case_rtn_string(ATH_OFFCHANNEL_ROC_WAIT);
493 case_rtn_string(ATH_OFFCHANNEL_ROC_DONE);
494 default:
495 return "unknown";
496 }
497}
498
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530499static int ath_scan_channel_duration(struct ath_softc *sc,
500 struct ieee80211_channel *chan)
501{
502 struct cfg80211_scan_request *req = sc->offchannel.scan_req;
503
504 if (!req->n_ssids || (chan->flags & IEEE80211_CHAN_NO_IR))
505 return (HZ / 9); /* ~110 ms */
506
507 return (HZ / 16); /* ~60 ms */
508}
509
Sujith Manoharan344ae6a2014-08-23 13:29:13 +0530510static void ath_chanctx_offchan_switch(struct ath_softc *sc,
511 struct ieee80211_channel *chan)
512{
513 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
514 struct cfg80211_chan_def chandef;
515
516 cfg80211_chandef_create(&chandef, chan, NL80211_CHAN_NO_HT);
517 ath_dbg(common, CHAN_CTX,
518 "Channel definition created: %d MHz\n", chandef.center_freq1);
519
520 ath_chanctx_switch(sc, &sc->offchannel.chan, &chandef);
521}
522
Sujith Manoharan98f411b2014-08-23 13:29:14 +0530523static struct ath_chanctx *ath_chanctx_get_oper_chan(struct ath_softc *sc,
524 bool active)
525{
526 struct ath_chanctx *ctx;
527
528 ath_for_each_chanctx(sc, ctx) {
529 if (!ctx->assigned || list_empty(&ctx->vifs))
530 continue;
531 if (active && !ctx->active)
532 continue;
533
534 if (ctx->switch_after_beacon)
535 return ctx;
536 }
537
538 return &sc->chanctx[0];
539}
540
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530541static void
542ath_scan_next_channel(struct ath_softc *sc)
543{
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530544 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530545 struct cfg80211_scan_request *req = sc->offchannel.scan_req;
546 struct ieee80211_channel *chan;
547
548 if (sc->offchannel.scan_idx >= req->n_channels) {
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530549 ath_dbg(common, CHAN_CTX,
550 "Moving to ATH_OFFCHANNEL_IDLE state, scan_idx: %d, n_channels: %d\n",
551 sc->offchannel.scan_idx,
552 req->n_channels);
553
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530554 sc->offchannel.state = ATH_OFFCHANNEL_IDLE;
555 ath_chanctx_switch(sc, ath_chanctx_get_oper_chan(sc, false),
556 NULL);
557 return;
558 }
559
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530560 ath_dbg(common, CHAN_CTX,
561 "Moving to ATH_OFFCHANNEL_PROBE_SEND state, scan_idx: %d\n",
562 sc->offchannel.scan_idx);
563
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530564 chan = req->channels[sc->offchannel.scan_idx++];
565 sc->offchannel.duration = ath_scan_channel_duration(sc, chan);
566 sc->offchannel.state = ATH_OFFCHANNEL_PROBE_SEND;
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530567
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530568 ath_chanctx_offchan_switch(sc, chan);
569}
570
571void ath_offchannel_next(struct ath_softc *sc)
572{
573 struct ieee80211_vif *vif;
574
575 if (sc->offchannel.scan_req) {
576 vif = sc->offchannel.scan_vif;
577 sc->offchannel.chan.txpower = vif->bss_conf.txpower;
578 ath_scan_next_channel(sc);
579 } else if (sc->offchannel.roc_vif) {
580 vif = sc->offchannel.roc_vif;
581 sc->offchannel.chan.txpower = vif->bss_conf.txpower;
582 sc->offchannel.duration = sc->offchannel.roc_duration;
583 sc->offchannel.state = ATH_OFFCHANNEL_ROC_START;
584 ath_chanctx_offchan_switch(sc, sc->offchannel.roc_chan);
585 } else {
586 ath_chanctx_switch(sc, ath_chanctx_get_oper_chan(sc, false),
587 NULL);
588 sc->offchannel.state = ATH_OFFCHANNEL_IDLE;
589 if (sc->ps_idle)
590 ath_cancel_work(sc);
591 }
592}
593
594void ath_roc_complete(struct ath_softc *sc, bool abort)
595{
596 sc->offchannel.roc_vif = NULL;
597 sc->offchannel.roc_chan = NULL;
598 if (!abort)
599 ieee80211_remain_on_channel_expired(sc->hw);
600 ath_offchannel_next(sc);
601 ath9k_ps_restore(sc);
602}
603
604void ath_scan_complete(struct ath_softc *sc, bool abort)
605{
606 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
607
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530608 if (abort)
609 ath_dbg(common, CHAN_CTX, "HW scan aborted\n");
610 else
611 ath_dbg(common, CHAN_CTX, "HW scan complete\n");
612
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530613 sc->offchannel.scan_req = NULL;
614 sc->offchannel.scan_vif = NULL;
615 sc->offchannel.state = ATH_OFFCHANNEL_IDLE;
616 ieee80211_scan_completed(sc->hw, abort);
617 clear_bit(ATH_OP_SCANNING, &common->op_flags);
618 ath_offchannel_next(sc);
619 ath9k_ps_restore(sc);
620}
621
622static void ath_scan_send_probe(struct ath_softc *sc,
623 struct cfg80211_ssid *ssid)
624{
625 struct cfg80211_scan_request *req = sc->offchannel.scan_req;
626 struct ieee80211_vif *vif = sc->offchannel.scan_vif;
627 struct ath_tx_control txctl = {};
628 struct sk_buff *skb;
629 struct ieee80211_tx_info *info;
630 int band = sc->offchannel.chan.chandef.chan->band;
631
632 skb = ieee80211_probereq_get(sc->hw, vif,
633 ssid->ssid, ssid->ssid_len, req->ie_len);
634 if (!skb)
635 return;
636
637 info = IEEE80211_SKB_CB(skb);
638 if (req->no_cck)
639 info->flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
640
641 if (req->ie_len)
642 memcpy(skb_put(skb, req->ie_len), req->ie, req->ie_len);
643
644 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
645
646 if (!ieee80211_tx_prepare_skb(sc->hw, vif, skb, band, NULL))
647 goto error;
648
649 txctl.txq = sc->tx.txq_map[IEEE80211_AC_VO];
650 txctl.force_channel = true;
651 if (ath_tx_start(sc->hw, skb, &txctl))
652 goto error;
653
654 return;
655
656error:
657 ieee80211_free_txskb(sc->hw, skb);
658}
659
660static void ath_scan_channel_start(struct ath_softc *sc)
661{
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530662 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530663 struct cfg80211_scan_request *req = sc->offchannel.scan_req;
664 int i;
665
666 if (!(sc->cur_chan->chandef.chan->flags & IEEE80211_CHAN_NO_IR) &&
667 req->n_ssids) {
668 for (i = 0; i < req->n_ssids; i++)
669 ath_scan_send_probe(sc, &req->ssids[i]);
670
671 }
672
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530673 ath_dbg(common, CHAN_CTX,
674 "Moving to ATH_OFFCHANNEL_PROBE_WAIT state\n");
675
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530676 sc->offchannel.state = ATH_OFFCHANNEL_PROBE_WAIT;
677 mod_timer(&sc->offchannel.timer, jiffies + sc->offchannel.duration);
678}
679
Sujith Manoharan705d0bf2014-08-23 13:29:06 +0530680static void ath_chanctx_timer(unsigned long data)
681{
682 struct ath_softc *sc = (struct ath_softc *) data;
683
684 ath_chanctx_event(sc, NULL, ATH_CHANCTX_EVENT_TSF_TIMER);
685}
686
687static void ath_offchannel_timer(unsigned long data)
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530688{
689 struct ath_softc *sc = (struct ath_softc *)data;
690 struct ath_chanctx *ctx;
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530691 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
692
693 ath_dbg(common, CHAN_CTX, "%s: state: %s\n",
694 __func__, offchannel_state_string(sc->offchannel.state));
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530695
696 switch (sc->offchannel.state) {
697 case ATH_OFFCHANNEL_PROBE_WAIT:
698 if (!sc->offchannel.scan_req)
699 return;
700
701 /* get first active channel context */
702 ctx = ath_chanctx_get_oper_chan(sc, true);
703 if (ctx->active) {
704 sc->offchannel.state = ATH_OFFCHANNEL_SUSPEND;
705 ath_chanctx_switch(sc, ctx, NULL);
706 mod_timer(&sc->offchannel.timer, jiffies + HZ / 10);
707 break;
708 }
709 /* fall through */
710 case ATH_OFFCHANNEL_SUSPEND:
711 if (!sc->offchannel.scan_req)
712 return;
713
714 ath_scan_next_channel(sc);
715 break;
716 case ATH_OFFCHANNEL_ROC_START:
717 case ATH_OFFCHANNEL_ROC_WAIT:
718 ctx = ath_chanctx_get_oper_chan(sc, false);
719 sc->offchannel.state = ATH_OFFCHANNEL_ROC_DONE;
720 ath_chanctx_switch(sc, ctx, NULL);
721 break;
722 default:
723 break;
724 }
725}
Sujith Manoharan2471adf2014-08-22 20:39:29 +0530726
Sujith Manoharan6d7cbd72014-08-23 13:29:10 +0530727static bool
728ath_chanctx_send_vif_ps_frame(struct ath_softc *sc, struct ath_vif *avp,
729 bool powersave)
730{
731 struct ieee80211_vif *vif = avp->vif;
732 struct ieee80211_sta *sta = NULL;
733 struct ieee80211_hdr_3addr *nullfunc;
734 struct ath_tx_control txctl;
735 struct sk_buff *skb;
736 int band = sc->cur_chan->chandef.chan->band;
737
738 switch (vif->type) {
739 case NL80211_IFTYPE_STATION:
740 if (!vif->bss_conf.assoc)
741 return false;
742
743 skb = ieee80211_nullfunc_get(sc->hw, vif);
744 if (!skb)
745 return false;
746
747 nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
748 if (powersave)
749 nullfunc->frame_control |=
750 cpu_to_le16(IEEE80211_FCTL_PM);
751
752 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
753 if (!ieee80211_tx_prepare_skb(sc->hw, vif, skb, band, &sta)) {
754 dev_kfree_skb_any(skb);
755 return false;
756 }
757 break;
758 default:
759 return false;
760 }
761
762 memset(&txctl, 0, sizeof(txctl));
763 txctl.txq = sc->tx.txq_map[IEEE80211_AC_VO];
764 txctl.sta = sta;
765 txctl.force_channel = true;
766 if (ath_tx_start(sc->hw, skb, &txctl)) {
767 ieee80211_free_txskb(sc->hw, skb);
768 return false;
769 }
770
771 return true;
772}
773
774static bool
775ath_chanctx_send_ps_frame(struct ath_softc *sc, bool powersave)
776{
777 struct ath_vif *avp;
778 bool sent = false;
779
780 rcu_read_lock();
781 list_for_each_entry(avp, &sc->cur_chan->vifs, list) {
782 if (ath_chanctx_send_vif_ps_frame(sc, avp, powersave))
783 sent = true;
784 }
785 rcu_read_unlock();
786
787 return sent;
788}
789
790static bool ath_chanctx_defer_switch(struct ath_softc *sc)
791{
792 if (sc->cur_chan == &sc->offchannel.chan)
793 return false;
794
795 switch (sc->sched.state) {
796 case ATH_CHANCTX_STATE_SWITCH:
797 return false;
798 case ATH_CHANCTX_STATE_IDLE:
799 if (!sc->cur_chan->switch_after_beacon)
800 return false;
801
802 sc->sched.state = ATH_CHANCTX_STATE_WAIT_FOR_BEACON;
803 break;
804 default:
805 break;
806 }
807
808 return true;
809}
810
Sujith Manoharan55254ee2014-08-23 13:29:11 +0530811static void ath_offchannel_channel_change(struct ath_softc *sc)
812{
813 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
814
815 ath_dbg(common, CHAN_CTX, "%s: state: %s\n",
816 __func__, offchannel_state_string(sc->offchannel.state));
817
818 switch (sc->offchannel.state) {
819 case ATH_OFFCHANNEL_PROBE_SEND:
820 if (!sc->offchannel.scan_req)
821 return;
822
823 if (sc->cur_chan->chandef.chan !=
824 sc->offchannel.chan.chandef.chan)
825 return;
826
827 ath_scan_channel_start(sc);
828 break;
829 case ATH_OFFCHANNEL_IDLE:
830 if (!sc->offchannel.scan_req)
831 return;
832
833 ath_scan_complete(sc, false);
834 break;
835 case ATH_OFFCHANNEL_ROC_START:
836 if (sc->cur_chan != &sc->offchannel.chan)
837 break;
838
839 sc->offchannel.state = ATH_OFFCHANNEL_ROC_WAIT;
840 mod_timer(&sc->offchannel.timer, jiffies +
841 msecs_to_jiffies(sc->offchannel.duration));
842 ieee80211_ready_on_channel(sc->hw);
843 break;
844 case ATH_OFFCHANNEL_ROC_DONE:
845 ath_roc_complete(sc, false);
846 break;
847 default:
848 break;
849 }
850}
851
Sujith Manoharan6d7cbd72014-08-23 13:29:10 +0530852void ath_chanctx_set_next(struct ath_softc *sc, bool force)
853{
854 struct timespec ts;
855 bool measure_time = false;
856 bool send_ps = false;
857
858 spin_lock_bh(&sc->chan_lock);
859 if (!sc->next_chan) {
860 spin_unlock_bh(&sc->chan_lock);
861 return;
862 }
863
864 if (!force && ath_chanctx_defer_switch(sc)) {
865 spin_unlock_bh(&sc->chan_lock);
866 return;
867 }
868
869 if (sc->cur_chan != sc->next_chan) {
870 sc->cur_chan->stopped = true;
871 spin_unlock_bh(&sc->chan_lock);
872
873 if (sc->next_chan == &sc->offchannel.chan) {
874 getrawmonotonic(&ts);
875 measure_time = true;
876 }
877 __ath9k_flush(sc->hw, ~0, true);
878
879 if (ath_chanctx_send_ps_frame(sc, true))
880 __ath9k_flush(sc->hw, BIT(IEEE80211_AC_VO), false);
881
882 send_ps = true;
883 spin_lock_bh(&sc->chan_lock);
884
885 if (sc->cur_chan != &sc->offchannel.chan) {
886 getrawmonotonic(&sc->cur_chan->tsf_ts);
887 sc->cur_chan->tsf_val = ath9k_hw_gettsf64(sc->sc_ah);
888 }
889 }
890 sc->cur_chan = sc->next_chan;
891 sc->cur_chan->stopped = false;
892 sc->next_chan = NULL;
893 sc->sched.offchannel_duration = 0;
894 if (sc->sched.state != ATH_CHANCTX_STATE_FORCE_ACTIVE)
895 sc->sched.state = ATH_CHANCTX_STATE_IDLE;
896
897 spin_unlock_bh(&sc->chan_lock);
898
899 if (sc->sc_ah->chip_fullsleep ||
900 memcmp(&sc->cur_chandef, &sc->cur_chan->chandef,
901 sizeof(sc->cur_chandef))) {
902 ath_set_channel(sc);
903 if (measure_time)
904 sc->sched.channel_switch_time =
905 ath9k_hw_get_tsf_offset(&ts, NULL);
906 }
907 if (send_ps)
908 ath_chanctx_send_ps_frame(sc, false);
909
910 ath_offchannel_channel_change(sc);
911 ath_chanctx_event(sc, NULL, ATH_CHANCTX_EVENT_SWITCH);
912}
913
Sujith Manoharan0e62f8b2014-08-23 13:29:08 +0530914static void ath_chanctx_work(struct work_struct *work)
915{
916 struct ath_softc *sc = container_of(work, struct ath_softc,
917 chanctx_work);
918 mutex_lock(&sc->mutex);
919 ath_chanctx_set_next(sc, false);
920 mutex_unlock(&sc->mutex);
921}
922
Sujith Manoharan705d0bf2014-08-23 13:29:06 +0530923void ath9k_init_channel_context(struct ath_softc *sc)
924{
925 INIT_WORK(&sc->chanctx_work, ath_chanctx_work);
926
927 setup_timer(&sc->offchannel.timer, ath_offchannel_timer,
928 (unsigned long)sc);
929 setup_timer(&sc->sched.timer, ath_chanctx_timer,
930 (unsigned long)sc);
931}
Sujith Manoharanc7dd40c2014-08-22 20:39:30 +0530932
Sujith Manoharanea22df22014-08-23 13:29:07 +0530933void ath9k_deinit_channel_context(struct ath_softc *sc)
934{
935 cancel_work_sync(&sc->chanctx_work);
936}
937
Sujith Manoharan499afac2014-08-22 20:39:31 +0530938bool ath9k_is_chanctx_enabled(void)
939{
940 return (ath9k_use_chanctx == 1);
941}
942
Sujith Manoharanc7dd40c2014-08-22 20:39:30 +0530943/*****************/
944/* P2P Powersave */
945/*****************/
946
947static void ath9k_update_p2p_ps_timer(struct ath_softc *sc, struct ath_vif *avp)
Sujith Manoharan2471adf2014-08-22 20:39:29 +0530948{
949 struct ath_hw *ah = sc->sc_ah;
950 s32 tsf, target_tsf;
951
952 if (!avp || !avp->noa.has_next_tsf)
953 return;
954
955 ath9k_hw_gen_timer_stop(ah, sc->p2p_ps_timer);
956
957 tsf = ath9k_hw_gettsf32(sc->sc_ah);
958
959 target_tsf = avp->noa.next_tsf;
960 if (!avp->noa.absent)
961 target_tsf -= ATH_P2P_PS_STOP_TIME;
962
963 if (target_tsf - tsf < ATH_P2P_PS_STOP_TIME)
964 target_tsf = tsf + ATH_P2P_PS_STOP_TIME;
965
966 ath9k_hw_gen_timer_start(ah, sc->p2p_ps_timer, (u32) target_tsf, 1000000);
967}
968
Sujith Manoharanc7dd40c2014-08-22 20:39:30 +0530969static void ath9k_update_p2p_ps(struct ath_softc *sc, struct ieee80211_vif *vif)
970{
971 struct ath_vif *avp = (void *)vif->drv_priv;
972 u32 tsf;
973
974 if (!sc->p2p_ps_timer)
975 return;
976
977 if (vif->type != NL80211_IFTYPE_STATION || !vif->p2p)
978 return;
979
980 sc->p2p_ps_vif = avp;
981 tsf = ath9k_hw_gettsf32(sc->sc_ah);
982 ieee80211_parse_p2p_noa(&vif->bss_conf.p2p_noa_attr, &avp->noa, tsf);
983 ath9k_update_p2p_ps_timer(sc, avp);
984}
985
Sujith Manoharan2471adf2014-08-22 20:39:29 +0530986void ath9k_p2p_ps_timer(void *priv)
987{
988 struct ath_softc *sc = priv;
989 struct ath_vif *avp = sc->p2p_ps_vif;
990 struct ieee80211_vif *vif;
991 struct ieee80211_sta *sta;
992 struct ath_node *an;
993 u32 tsf;
994
995 del_timer_sync(&sc->sched.timer);
996 ath9k_hw_gen_timer_stop(sc->sc_ah, sc->p2p_ps_timer);
997 ath_chanctx_event(sc, NULL, ATH_CHANCTX_EVENT_TSF_TIMER);
998
999 if (!avp || avp->chanctx != sc->cur_chan)
1000 return;
1001
1002 tsf = ath9k_hw_gettsf32(sc->sc_ah);
1003 if (!avp->noa.absent)
1004 tsf += ATH_P2P_PS_STOP_TIME;
1005
1006 if (!avp->noa.has_next_tsf ||
1007 avp->noa.next_tsf - tsf > BIT(31))
1008 ieee80211_update_p2p_noa(&avp->noa, tsf);
1009
1010 ath9k_update_p2p_ps_timer(sc, avp);
1011
1012 rcu_read_lock();
1013
1014 vif = avp->vif;
1015 sta = ieee80211_find_sta(vif, vif->bss_conf.bssid);
1016 if (!sta)
1017 goto out;
1018
1019 an = (void *) sta->drv_priv;
1020 if (an->sleeping == !!avp->noa.absent)
1021 goto out;
1022
1023 an->sleeping = avp->noa.absent;
1024 if (an->sleeping)
1025 ath_tx_aggr_sleep(sta, sc, an);
1026 else
1027 ath_tx_aggr_wakeup(sc, an);
1028
1029out:
1030 rcu_read_unlock();
1031}
1032
Sujith Manoharanc7dd40c2014-08-22 20:39:30 +05301033void ath9k_p2p_bss_info_changed(struct ath_softc *sc,
1034 struct ieee80211_vif *vif)
1035{
1036 unsigned long flags;
1037
1038 spin_lock_bh(&sc->sc_pcu_lock);
1039 spin_lock_irqsave(&sc->sc_pm_lock, flags);
1040 if (!(sc->ps_flags & PS_BEACON_SYNC))
1041 ath9k_update_p2p_ps(sc, vif);
1042 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
1043 spin_unlock_bh(&sc->sc_pcu_lock);
1044}
1045
1046void ath9k_p2p_beacon_sync(struct ath_softc *sc)
1047{
1048 if (sc->p2p_ps_vif)
1049 ath9k_update_p2p_ps(sc, sc->p2p_ps_vif->vif);
1050}
1051
1052void ath9k_p2p_remove_vif(struct ath_softc *sc,
1053 struct ieee80211_vif *vif)
Sujith Manoharan2471adf2014-08-22 20:39:29 +05301054{
1055 struct ath_vif *avp = (void *)vif->drv_priv;
Sujith Manoharan2471adf2014-08-22 20:39:29 +05301056
Sujith Manoharanc7dd40c2014-08-22 20:39:30 +05301057 spin_lock_bh(&sc->sc_pcu_lock);
1058 if (avp == sc->p2p_ps_vif) {
1059 sc->p2p_ps_vif = NULL;
1060 ath9k_update_p2p_ps_timer(sc, NULL);
1061 }
1062 spin_unlock_bh(&sc->sc_pcu_lock);
Sujith Manoharan2471adf2014-08-22 20:39:29 +05301063}
Sujith Manoharanc7dd40c2014-08-22 20:39:30 +05301064
1065int ath9k_init_p2p(struct ath_softc *sc)
1066{
1067 sc->p2p_ps_timer = ath_gen_timer_alloc(sc->sc_ah, ath9k_p2p_ps_timer,
1068 NULL, sc, AR_FIRST_NDP_TIMER);
1069 if (!sc->p2p_ps_timer)
1070 return -ENOMEM;
1071
1072 return 0;
1073}
1074
1075void ath9k_deinit_p2p(struct ath_softc *sc)
1076{
1077 if (sc->p2p_ps_timer)
1078 ath_gen_timer_free(sc->sc_ah, sc->p2p_ps_timer);
1079}
1080
1081#endif /* CONFIG_ATH9K_CHANNEL_CONTEXT */