blob: 39df24c964c378c193ad5b3ec7dfa914f548e5f4 [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;
Sujith Manoharan27babf92014-08-23 13:29:16 +0530142
143 if (ath9k_is_chanctx_enabled()) {
144 ath_chanctx_event(sc, NULL,
145 ATH_CHANCTX_EVENT_ENABLE_MULTICHANNEL);
146 }
Felix Fietkauc083ce92014-06-11 16:17:54 +0530147}
148
Felix Fietkaufbbcd142014-06-11 16:17:49 +0530149void ath_chanctx_init(struct ath_softc *sc)
150{
151 struct ath_chanctx *ctx;
152 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
153 struct ieee80211_supported_band *sband;
154 struct ieee80211_channel *chan;
Felix Fietkau04535312014-06-11 16:17:51 +0530155 int i, j;
Felix Fietkaufbbcd142014-06-11 16:17:49 +0530156
157 sband = &common->sbands[IEEE80211_BAND_2GHZ];
158 if (!sband->n_channels)
159 sband = &common->sbands[IEEE80211_BAND_5GHZ];
160
161 chan = &sband->channels[0];
162 for (i = 0; i < ATH9K_NUM_CHANCTX; i++) {
163 ctx = &sc->chanctx[i];
164 cfg80211_chandef_create(&ctx->chandef, chan, NL80211_CHAN_HT20);
165 INIT_LIST_HEAD(&ctx->vifs);
Felix Fietkaubc7e1be2014-06-11 16:17:50 +0530166 ctx->txpower = ATH_TXPOWER_MAX;
Felix Fietkau04535312014-06-11 16:17:51 +0530167 for (j = 0; j < ARRAY_SIZE(ctx->acq); j++)
168 INIT_LIST_HEAD(&ctx->acq[j]);
Felix Fietkaufbbcd142014-06-11 16:17:49 +0530169 }
Felix Fietkau78b21942014-06-11 16:17:55 +0530170 ctx = &sc->offchannel.chan;
171 cfg80211_chandef_create(&ctx->chandef, chan, NL80211_CHAN_HT20);
172 INIT_LIST_HEAD(&ctx->vifs);
173 ctx->txpower = ATH_TXPOWER_MAX;
174 for (j = 0; j < ARRAY_SIZE(ctx->acq); j++)
175 INIT_LIST_HEAD(&ctx->acq[j]);
176 sc->offchannel.chan.offchannel = true;
177
Felix Fietkaufbbcd142014-06-11 16:17:49 +0530178}
179
Felix Fietkaubff11762014-06-11 16:17:52 +0530180void ath_chanctx_set_channel(struct ath_softc *sc, struct ath_chanctx *ctx,
181 struct cfg80211_chan_def *chandef)
182{
183 bool cur_chan;
184
185 spin_lock_bh(&sc->chan_lock);
186 if (chandef)
187 memcpy(&ctx->chandef, chandef, sizeof(*chandef));
188 cur_chan = sc->cur_chan == ctx;
189 spin_unlock_bh(&sc->chan_lock);
190
191 if (!cur_chan)
192 return;
193
194 ath_set_channel(sc);
Felix Fietkaufbbcd142014-06-11 16:17:49 +0530195}
Felix Fietkau78b21942014-06-11 16:17:55 +0530196
Sujith Manoharan27babf92014-08-23 13:29:16 +0530197#ifdef CONFIG_ATH9K_CHANNEL_CONTEXT
198
199static const char *offchannel_state_string(enum ath_offchannel_state state)
200{
201#define case_rtn_string(val) case val: return #val
202
203 switch (state) {
204 case_rtn_string(ATH_OFFCHANNEL_IDLE);
205 case_rtn_string(ATH_OFFCHANNEL_PROBE_SEND);
206 case_rtn_string(ATH_OFFCHANNEL_PROBE_WAIT);
207 case_rtn_string(ATH_OFFCHANNEL_SUSPEND);
208 case_rtn_string(ATH_OFFCHANNEL_ROC_START);
209 case_rtn_string(ATH_OFFCHANNEL_ROC_WAIT);
210 case_rtn_string(ATH_OFFCHANNEL_ROC_DONE);
211 default:
212 return "unknown";
213 }
214}
215
Felix Fietkau58b57372014-06-11 16:18:08 +0530216static struct ath_chanctx *
217ath_chanctx_get_next(struct ath_softc *sc, struct ath_chanctx *ctx)
218{
219 int idx = ctx - &sc->chanctx[0];
220
221 return &sc->chanctx[!idx];
222}
223
224static void ath_chanctx_adjust_tbtt_delta(struct ath_softc *sc)
225{
226 struct ath_chanctx *prev, *cur;
227 struct timespec ts;
228 u32 cur_tsf, prev_tsf, beacon_int;
229 s32 offset;
230
231 beacon_int = TU_TO_USEC(sc->cur_chan->beacon.beacon_interval);
232
233 cur = sc->cur_chan;
234 prev = ath_chanctx_get_next(sc, cur);
235
236 getrawmonotonic(&ts);
237 cur_tsf = (u32) cur->tsf_val +
238 ath9k_hw_get_tsf_offset(&cur->tsf_ts, &ts);
239
240 prev_tsf = prev->last_beacon - (u32) prev->tsf_val + cur_tsf;
241 prev_tsf -= ath9k_hw_get_tsf_offset(&prev->tsf_ts, &ts);
242
243 /* Adjust the TSF time of the AP chanctx to keep its beacons
244 * at half beacon interval offset relative to the STA chanctx.
245 */
246 offset = cur_tsf - prev_tsf;
247
248 /* Ignore stale data or spurious timestamps */
249 if (offset < 0 || offset > 3 * beacon_int)
250 return;
251
252 offset = beacon_int / 2 - (offset % beacon_int);
253 prev->tsf_val += offset;
254}
255
Felix Fietkau42eda112014-06-11 16:18:14 +0530256/* Configure the TSF based hardware timer for a channel switch.
257 * Also set up backup software timer, in case the gen timer fails.
258 * This could be caused by a hardware reset.
259 */
260static void ath_chanctx_setup_timer(struct ath_softc *sc, u32 tsf_time)
261{
262 struct ath_hw *ah = sc->sc_ah;
263
Sujith Manoharanc7dd40c2014-08-22 20:39:30 +0530264#ifdef CONFIG_ATH9K_CHANNEL_CONTEXT
Felix Fietkau42eda112014-06-11 16:18:14 +0530265 ath9k_hw_gen_timer_start(ah, sc->p2p_ps_timer, tsf_time, 1000000);
Sujith Manoharanc7dd40c2014-08-22 20:39:30 +0530266#endif
Felix Fietkau42eda112014-06-11 16:18:14 +0530267 tsf_time -= ath9k_hw_gettsf32(ah);
268 tsf_time = msecs_to_jiffies(tsf_time / 1000) + 1;
269 mod_timer(&sc->sched.timer, tsf_time);
270}
271
Felix Fietkau748299f2014-06-11 16:18:04 +0530272void ath_chanctx_event(struct ath_softc *sc, struct ieee80211_vif *vif,
273 enum ath_chanctx_event ev)
274{
275 struct ath_hw *ah = sc->sc_ah;
Felix Fietkau58b57372014-06-11 16:18:08 +0530276 struct ath_common *common = ath9k_hw_common(ah);
Felix Fietkau74148632014-06-11 16:18:11 +0530277 struct ath_beacon_config *cur_conf;
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530278 struct ath_vif *avp = NULL;
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530279 struct ath_chanctx *ctx;
Felix Fietkau748299f2014-06-11 16:18:04 +0530280 u32 tsf_time;
Felix Fietkauec70abe2014-06-11 16:18:12 +0530281 u32 beacon_int;
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530282 bool noa_changed = false;
283
284 if (vif)
285 avp = (struct ath_vif *) vif->drv_priv;
Felix Fietkau748299f2014-06-11 16:18:04 +0530286
287 spin_lock_bh(&sc->chan_lock);
288
289 switch (ev) {
290 case ATH_CHANCTX_EVENT_BEACON_PREPARE:
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530291 if (avp->offchannel_duration)
292 avp->offchannel_duration = 0;
293
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530294 if (avp->chanctx != sc->cur_chan)
295 break;
296
297 if (sc->sched.offchannel_pending) {
298 sc->sched.offchannel_pending = false;
299 sc->next_chan = &sc->offchannel.chan;
300 sc->sched.state = ATH_CHANCTX_STATE_WAIT_FOR_BEACON;
301 }
302
303 ctx = ath_chanctx_get_next(sc, sc->cur_chan);
304 if (ctx->active && sc->sched.state == ATH_CHANCTX_STATE_IDLE) {
305 sc->next_chan = ctx;
306 sc->sched.state = ATH_CHANCTX_STATE_WAIT_FOR_BEACON;
307 }
308
309 /* if the timer missed its window, use the next interval */
310 if (sc->sched.state == ATH_CHANCTX_STATE_WAIT_FOR_TIMER)
311 sc->sched.state = ATH_CHANCTX_STATE_WAIT_FOR_BEACON;
312
Felix Fietkau748299f2014-06-11 16:18:04 +0530313 if (sc->sched.state != ATH_CHANCTX_STATE_WAIT_FOR_BEACON)
314 break;
315
316 sc->sched.beacon_pending = true;
317 sc->sched.next_tbtt = REG_READ(ah, AR_NEXT_TBTT_TIMER);
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530318
Felix Fietkau74148632014-06-11 16:18:11 +0530319 cur_conf = &sc->cur_chan->beacon;
Felix Fietkauec70abe2014-06-11 16:18:12 +0530320 beacon_int = TU_TO_USEC(cur_conf->beacon_interval);
321
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530322 /* defer channel switch by a quarter beacon interval */
Felix Fietkauec70abe2014-06-11 16:18:12 +0530323 tsf_time = sc->sched.next_tbtt + beacon_int / 4;
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530324 sc->sched.switch_start_time = tsf_time;
Felix Fietkau58b57372014-06-11 16:18:08 +0530325 sc->cur_chan->last_beacon = sc->sched.next_tbtt;
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530326
Felix Fietkau74148632014-06-11 16:18:11 +0530327 /* Prevent wrap-around issues */
328 if (avp->periodic_noa_duration &&
329 tsf_time - avp->periodic_noa_start > BIT(30))
330 avp->periodic_noa_duration = 0;
331
332 if (ctx->active && !avp->periodic_noa_duration) {
333 avp->periodic_noa_start = tsf_time;
334 avp->periodic_noa_duration =
335 TU_TO_USEC(cur_conf->beacon_interval) / 2 -
336 sc->sched.channel_switch_time;
337 noa_changed = true;
338 } else if (!ctx->active && avp->periodic_noa_duration) {
339 avp->periodic_noa_duration = 0;
340 noa_changed = true;
341 }
342
Felix Fietkauec70abe2014-06-11 16:18:12 +0530343 /* If at least two consecutive beacons were missed on the STA
344 * chanctx, stay on the STA channel for one extra beacon period,
345 * to resync the timer properly.
346 */
347 if (ctx->active && sc->sched.beacon_miss >= 2)
348 sc->sched.offchannel_duration = 3 * beacon_int / 2;
349
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530350 if (sc->sched.offchannel_duration) {
351 noa_changed = true;
352 avp->offchannel_start = tsf_time;
353 avp->offchannel_duration =
354 sc->sched.offchannel_duration;
355 }
356
357 if (noa_changed)
358 avp->noa_index++;
Felix Fietkau748299f2014-06-11 16:18:04 +0530359 break;
360 case ATH_CHANCTX_EVENT_BEACON_SENT:
361 if (!sc->sched.beacon_pending)
362 break;
363
364 sc->sched.beacon_pending = false;
365 if (sc->sched.state != ATH_CHANCTX_STATE_WAIT_FOR_BEACON)
366 break;
367
Felix Fietkau748299f2014-06-11 16:18:04 +0530368 sc->sched.state = ATH_CHANCTX_STATE_WAIT_FOR_TIMER;
Felix Fietkau42eda112014-06-11 16:18:14 +0530369 ath_chanctx_setup_timer(sc, sc->sched.switch_start_time);
Felix Fietkau748299f2014-06-11 16:18:04 +0530370 break;
371 case ATH_CHANCTX_EVENT_TSF_TIMER:
372 if (sc->sched.state != ATH_CHANCTX_STATE_WAIT_FOR_TIMER)
373 break;
374
Felix Fietkauec70abe2014-06-11 16:18:12 +0530375 if (!sc->cur_chan->switch_after_beacon &&
376 sc->sched.beacon_pending)
377 sc->sched.beacon_miss++;
378
Felix Fietkau748299f2014-06-11 16:18:04 +0530379 sc->sched.state = ATH_CHANCTX_STATE_SWITCH;
380 ieee80211_queue_work(sc->hw, &sc->chanctx_work);
381 break;
Felix Fietkau58b57372014-06-11 16:18:08 +0530382 case ATH_CHANCTX_EVENT_BEACON_RECEIVED:
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530383 if (!test_bit(ATH_OP_MULTI_CHANNEL, &common->op_flags) ||
384 sc->cur_chan == &sc->offchannel.chan)
Felix Fietkau58b57372014-06-11 16:18:08 +0530385 break;
386
387 ath_chanctx_adjust_tbtt_delta(sc);
Felix Fietkauec70abe2014-06-11 16:18:12 +0530388 sc->sched.beacon_pending = false;
389 sc->sched.beacon_miss = 0;
Felix Fietkaua899b672014-06-11 16:18:13 +0530390
391 /* TSF time might have been updated by the incoming beacon,
392 * need update the channel switch timer to reflect the change.
393 */
394 tsf_time = sc->sched.switch_start_time;
395 tsf_time -= (u32) sc->cur_chan->tsf_val +
396 ath9k_hw_get_tsf_offset(&sc->cur_chan->tsf_ts, NULL);
397 tsf_time += ath9k_hw_gettsf32(ah);
398
Felix Fietkau42eda112014-06-11 16:18:14 +0530399
400 ath_chanctx_setup_timer(sc, tsf_time);
Felix Fietkau58b57372014-06-11 16:18:08 +0530401 break;
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530402 case ATH_CHANCTX_EVENT_ASSOC:
403 if (sc->sched.state != ATH_CHANCTX_STATE_FORCE_ACTIVE ||
404 avp->chanctx != sc->cur_chan)
405 break;
406
407 sc->sched.state = ATH_CHANCTX_STATE_IDLE;
408 /* fall through */
409 case ATH_CHANCTX_EVENT_SWITCH:
410 if (!test_bit(ATH_OP_MULTI_CHANNEL, &common->op_flags) ||
411 sc->sched.state == ATH_CHANCTX_STATE_FORCE_ACTIVE ||
412 sc->cur_chan->switch_after_beacon ||
413 sc->cur_chan == &sc->offchannel.chan)
414 break;
415
416 /* If this is a station chanctx, stay active for a half
417 * beacon period (minus channel switch time)
418 */
419 sc->next_chan = ath_chanctx_get_next(sc, sc->cur_chan);
Felix Fietkau74148632014-06-11 16:18:11 +0530420 cur_conf = &sc->cur_chan->beacon;
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530421
422 sc->sched.state = ATH_CHANCTX_STATE_WAIT_FOR_TIMER;
Felix Fietkauec70abe2014-06-11 16:18:12 +0530423
424 tsf_time = TU_TO_USEC(cur_conf->beacon_interval) / 2;
425 if (sc->sched.beacon_miss >= 2) {
426 sc->sched.beacon_miss = 0;
427 tsf_time *= 3;
428 }
429
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530430 tsf_time -= sc->sched.channel_switch_time;
Felix Fietkauec70abe2014-06-11 16:18:12 +0530431 tsf_time += ath9k_hw_gettsf32(sc->sc_ah);
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530432 sc->sched.switch_start_time = tsf_time;
433
Felix Fietkau42eda112014-06-11 16:18:14 +0530434 ath_chanctx_setup_timer(sc, tsf_time);
Felix Fietkauec70abe2014-06-11 16:18:12 +0530435 sc->sched.beacon_pending = true;
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530436 break;
437 case ATH_CHANCTX_EVENT_ENABLE_MULTICHANNEL:
438 if (sc->cur_chan == &sc->offchannel.chan ||
439 sc->cur_chan->switch_after_beacon)
440 break;
441
442 sc->next_chan = ath_chanctx_get_next(sc, sc->cur_chan);
443 ieee80211_queue_work(sc->hw, &sc->chanctx_work);
444 break;
445 case ATH_CHANCTX_EVENT_UNASSIGN:
446 if (sc->cur_chan->assigned) {
447 if (sc->next_chan && !sc->next_chan->assigned &&
448 sc->next_chan != &sc->offchannel.chan)
449 sc->sched.state = ATH_CHANCTX_STATE_IDLE;
450 break;
451 }
452
453 ctx = ath_chanctx_get_next(sc, sc->cur_chan);
454 sc->sched.state = ATH_CHANCTX_STATE_IDLE;
455 if (!ctx->assigned)
456 break;
457
458 sc->next_chan = ctx;
459 ieee80211_queue_work(sc->hw, &sc->chanctx_work);
460 break;
Felix Fietkau748299f2014-06-11 16:18:04 +0530461 }
462
463 spin_unlock_bh(&sc->chan_lock);
464}
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530465
Sujith Manoharan70b06da2014-08-23 13:29:18 +0530466void ath_chanctx_beacon_sent_ev(struct ath_softc *sc,
467 enum ath_chanctx_event ev)
468{
469 if (sc->sched.beacon_pending)
470 ath_chanctx_event(sc, NULL, ev);
471}
472
473void ath_chanctx_beacon_recv_ev(struct ath_softc *sc, u32 ts,
474 enum ath_chanctx_event ev)
475{
476 sc->sched.next_tbtt = ts;
477 ath_chanctx_event(sc, NULL, ev);
478}
479
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530480static int ath_scan_channel_duration(struct ath_softc *sc,
481 struct ieee80211_channel *chan)
482{
483 struct cfg80211_scan_request *req = sc->offchannel.scan_req;
484
485 if (!req->n_ssids || (chan->flags & IEEE80211_CHAN_NO_IR))
486 return (HZ / 9); /* ~110 ms */
487
488 return (HZ / 16); /* ~60 ms */
489}
490
Sujith Manoharan922c9432014-08-23 13:29:15 +0530491static void ath_chanctx_switch(struct ath_softc *sc, struct ath_chanctx *ctx,
492 struct cfg80211_chan_def *chandef)
493{
494 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
495
496 spin_lock_bh(&sc->chan_lock);
497
498 if (test_bit(ATH_OP_MULTI_CHANNEL, &common->op_flags) &&
499 (sc->cur_chan != ctx) && (ctx == &sc->offchannel.chan)) {
500 sc->sched.offchannel_pending = true;
501 spin_unlock_bh(&sc->chan_lock);
502 return;
503 }
504
505 sc->next_chan = ctx;
506 if (chandef) {
507 ctx->chandef = *chandef;
508 ath_dbg(common, CHAN_CTX,
509 "Assigned next_chan to %d MHz\n", chandef->center_freq1);
510 }
511
512 if (sc->next_chan == &sc->offchannel.chan) {
513 sc->sched.offchannel_duration =
514 TU_TO_USEC(sc->offchannel.duration) +
515 sc->sched.channel_switch_time;
516
517 if (chandef) {
518 ath_dbg(common, CHAN_CTX,
519 "Offchannel duration for chan %d MHz : %u\n",
520 chandef->center_freq1,
521 sc->sched.offchannel_duration);
522 }
523 }
524 spin_unlock_bh(&sc->chan_lock);
525 ieee80211_queue_work(sc->hw, &sc->chanctx_work);
526}
527
Sujith Manoharan344ae6a2014-08-23 13:29:13 +0530528static void ath_chanctx_offchan_switch(struct ath_softc *sc,
529 struct ieee80211_channel *chan)
530{
531 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
532 struct cfg80211_chan_def chandef;
533
534 cfg80211_chandef_create(&chandef, chan, NL80211_CHAN_NO_HT);
535 ath_dbg(common, CHAN_CTX,
536 "Channel definition created: %d MHz\n", chandef.center_freq1);
537
538 ath_chanctx_switch(sc, &sc->offchannel.chan, &chandef);
539}
540
Sujith Manoharan98f411b2014-08-23 13:29:14 +0530541static struct ath_chanctx *ath_chanctx_get_oper_chan(struct ath_softc *sc,
542 bool active)
543{
544 struct ath_chanctx *ctx;
545
546 ath_for_each_chanctx(sc, ctx) {
547 if (!ctx->assigned || list_empty(&ctx->vifs))
548 continue;
549 if (active && !ctx->active)
550 continue;
551
552 if (ctx->switch_after_beacon)
553 return ctx;
554 }
555
556 return &sc->chanctx[0];
557}
558
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530559static void
560ath_scan_next_channel(struct ath_softc *sc)
561{
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530562 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530563 struct cfg80211_scan_request *req = sc->offchannel.scan_req;
564 struct ieee80211_channel *chan;
565
566 if (sc->offchannel.scan_idx >= req->n_channels) {
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530567 ath_dbg(common, CHAN_CTX,
568 "Moving to ATH_OFFCHANNEL_IDLE state, scan_idx: %d, n_channels: %d\n",
569 sc->offchannel.scan_idx,
570 req->n_channels);
571
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530572 sc->offchannel.state = ATH_OFFCHANNEL_IDLE;
573 ath_chanctx_switch(sc, ath_chanctx_get_oper_chan(sc, false),
574 NULL);
575 return;
576 }
577
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530578 ath_dbg(common, CHAN_CTX,
579 "Moving to ATH_OFFCHANNEL_PROBE_SEND state, scan_idx: %d\n",
580 sc->offchannel.scan_idx);
581
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530582 chan = req->channels[sc->offchannel.scan_idx++];
583 sc->offchannel.duration = ath_scan_channel_duration(sc, chan);
584 sc->offchannel.state = ATH_OFFCHANNEL_PROBE_SEND;
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530585
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530586 ath_chanctx_offchan_switch(sc, chan);
587}
588
589void ath_offchannel_next(struct ath_softc *sc)
590{
591 struct ieee80211_vif *vif;
592
593 if (sc->offchannel.scan_req) {
594 vif = sc->offchannel.scan_vif;
595 sc->offchannel.chan.txpower = vif->bss_conf.txpower;
596 ath_scan_next_channel(sc);
597 } else if (sc->offchannel.roc_vif) {
598 vif = sc->offchannel.roc_vif;
599 sc->offchannel.chan.txpower = vif->bss_conf.txpower;
600 sc->offchannel.duration = sc->offchannel.roc_duration;
601 sc->offchannel.state = ATH_OFFCHANNEL_ROC_START;
602 ath_chanctx_offchan_switch(sc, sc->offchannel.roc_chan);
603 } else {
604 ath_chanctx_switch(sc, ath_chanctx_get_oper_chan(sc, false),
605 NULL);
606 sc->offchannel.state = ATH_OFFCHANNEL_IDLE;
607 if (sc->ps_idle)
608 ath_cancel_work(sc);
609 }
610}
611
612void ath_roc_complete(struct ath_softc *sc, bool abort)
613{
614 sc->offchannel.roc_vif = NULL;
615 sc->offchannel.roc_chan = NULL;
616 if (!abort)
617 ieee80211_remain_on_channel_expired(sc->hw);
618 ath_offchannel_next(sc);
619 ath9k_ps_restore(sc);
620}
621
622void ath_scan_complete(struct ath_softc *sc, bool abort)
623{
624 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
625
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530626 if (abort)
627 ath_dbg(common, CHAN_CTX, "HW scan aborted\n");
628 else
629 ath_dbg(common, CHAN_CTX, "HW scan complete\n");
630
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530631 sc->offchannel.scan_req = NULL;
632 sc->offchannel.scan_vif = NULL;
633 sc->offchannel.state = ATH_OFFCHANNEL_IDLE;
634 ieee80211_scan_completed(sc->hw, abort);
635 clear_bit(ATH_OP_SCANNING, &common->op_flags);
636 ath_offchannel_next(sc);
637 ath9k_ps_restore(sc);
638}
639
640static void ath_scan_send_probe(struct ath_softc *sc,
641 struct cfg80211_ssid *ssid)
642{
643 struct cfg80211_scan_request *req = sc->offchannel.scan_req;
644 struct ieee80211_vif *vif = sc->offchannel.scan_vif;
645 struct ath_tx_control txctl = {};
646 struct sk_buff *skb;
647 struct ieee80211_tx_info *info;
648 int band = sc->offchannel.chan.chandef.chan->band;
649
650 skb = ieee80211_probereq_get(sc->hw, vif,
651 ssid->ssid, ssid->ssid_len, req->ie_len);
652 if (!skb)
653 return;
654
655 info = IEEE80211_SKB_CB(skb);
656 if (req->no_cck)
657 info->flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
658
659 if (req->ie_len)
660 memcpy(skb_put(skb, req->ie_len), req->ie, req->ie_len);
661
662 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
663
664 if (!ieee80211_tx_prepare_skb(sc->hw, vif, skb, band, NULL))
665 goto error;
666
667 txctl.txq = sc->tx.txq_map[IEEE80211_AC_VO];
668 txctl.force_channel = true;
669 if (ath_tx_start(sc->hw, skb, &txctl))
670 goto error;
671
672 return;
673
674error:
675 ieee80211_free_txskb(sc->hw, skb);
676}
677
678static void ath_scan_channel_start(struct ath_softc *sc)
679{
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530680 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530681 struct cfg80211_scan_request *req = sc->offchannel.scan_req;
682 int i;
683
684 if (!(sc->cur_chan->chandef.chan->flags & IEEE80211_CHAN_NO_IR) &&
685 req->n_ssids) {
686 for (i = 0; i < req->n_ssids; i++)
687 ath_scan_send_probe(sc, &req->ssids[i]);
688
689 }
690
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530691 ath_dbg(common, CHAN_CTX,
692 "Moving to ATH_OFFCHANNEL_PROBE_WAIT state\n");
693
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530694 sc->offchannel.state = ATH_OFFCHANNEL_PROBE_WAIT;
695 mod_timer(&sc->offchannel.timer, jiffies + sc->offchannel.duration);
696}
697
Sujith Manoharan705d0bf2014-08-23 13:29:06 +0530698static void ath_chanctx_timer(unsigned long data)
699{
700 struct ath_softc *sc = (struct ath_softc *) data;
701
702 ath_chanctx_event(sc, NULL, ATH_CHANCTX_EVENT_TSF_TIMER);
703}
704
705static void ath_offchannel_timer(unsigned long data)
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530706{
707 struct ath_softc *sc = (struct ath_softc *)data;
708 struct ath_chanctx *ctx;
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530709 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
710
711 ath_dbg(common, CHAN_CTX, "%s: state: %s\n",
712 __func__, offchannel_state_string(sc->offchannel.state));
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530713
714 switch (sc->offchannel.state) {
715 case ATH_OFFCHANNEL_PROBE_WAIT:
716 if (!sc->offchannel.scan_req)
717 return;
718
719 /* get first active channel context */
720 ctx = ath_chanctx_get_oper_chan(sc, true);
721 if (ctx->active) {
722 sc->offchannel.state = ATH_OFFCHANNEL_SUSPEND;
723 ath_chanctx_switch(sc, ctx, NULL);
724 mod_timer(&sc->offchannel.timer, jiffies + HZ / 10);
725 break;
726 }
727 /* fall through */
728 case ATH_OFFCHANNEL_SUSPEND:
729 if (!sc->offchannel.scan_req)
730 return;
731
732 ath_scan_next_channel(sc);
733 break;
734 case ATH_OFFCHANNEL_ROC_START:
735 case ATH_OFFCHANNEL_ROC_WAIT:
736 ctx = ath_chanctx_get_oper_chan(sc, false);
737 sc->offchannel.state = ATH_OFFCHANNEL_ROC_DONE;
738 ath_chanctx_switch(sc, ctx, NULL);
739 break;
740 default:
741 break;
742 }
743}
Sujith Manoharan2471adf2014-08-22 20:39:29 +0530744
Sujith Manoharan6d7cbd72014-08-23 13:29:10 +0530745static bool
746ath_chanctx_send_vif_ps_frame(struct ath_softc *sc, struct ath_vif *avp,
747 bool powersave)
748{
749 struct ieee80211_vif *vif = avp->vif;
750 struct ieee80211_sta *sta = NULL;
751 struct ieee80211_hdr_3addr *nullfunc;
752 struct ath_tx_control txctl;
753 struct sk_buff *skb;
754 int band = sc->cur_chan->chandef.chan->band;
755
756 switch (vif->type) {
757 case NL80211_IFTYPE_STATION:
758 if (!vif->bss_conf.assoc)
759 return false;
760
761 skb = ieee80211_nullfunc_get(sc->hw, vif);
762 if (!skb)
763 return false;
764
765 nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
766 if (powersave)
767 nullfunc->frame_control |=
768 cpu_to_le16(IEEE80211_FCTL_PM);
769
770 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
771 if (!ieee80211_tx_prepare_skb(sc->hw, vif, skb, band, &sta)) {
772 dev_kfree_skb_any(skb);
773 return false;
774 }
775 break;
776 default:
777 return false;
778 }
779
780 memset(&txctl, 0, sizeof(txctl));
781 txctl.txq = sc->tx.txq_map[IEEE80211_AC_VO];
782 txctl.sta = sta;
783 txctl.force_channel = true;
784 if (ath_tx_start(sc->hw, skb, &txctl)) {
785 ieee80211_free_txskb(sc->hw, skb);
786 return false;
787 }
788
789 return true;
790}
791
792static bool
793ath_chanctx_send_ps_frame(struct ath_softc *sc, bool powersave)
794{
795 struct ath_vif *avp;
796 bool sent = false;
797
798 rcu_read_lock();
799 list_for_each_entry(avp, &sc->cur_chan->vifs, list) {
800 if (ath_chanctx_send_vif_ps_frame(sc, avp, powersave))
801 sent = true;
802 }
803 rcu_read_unlock();
804
805 return sent;
806}
807
808static bool ath_chanctx_defer_switch(struct ath_softc *sc)
809{
810 if (sc->cur_chan == &sc->offchannel.chan)
811 return false;
812
813 switch (sc->sched.state) {
814 case ATH_CHANCTX_STATE_SWITCH:
815 return false;
816 case ATH_CHANCTX_STATE_IDLE:
817 if (!sc->cur_chan->switch_after_beacon)
818 return false;
819
820 sc->sched.state = ATH_CHANCTX_STATE_WAIT_FOR_BEACON;
821 break;
822 default:
823 break;
824 }
825
826 return true;
827}
828
Sujith Manoharan55254ee2014-08-23 13:29:11 +0530829static void ath_offchannel_channel_change(struct ath_softc *sc)
830{
831 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
832
833 ath_dbg(common, CHAN_CTX, "%s: state: %s\n",
834 __func__, offchannel_state_string(sc->offchannel.state));
835
836 switch (sc->offchannel.state) {
837 case ATH_OFFCHANNEL_PROBE_SEND:
838 if (!sc->offchannel.scan_req)
839 return;
840
841 if (sc->cur_chan->chandef.chan !=
842 sc->offchannel.chan.chandef.chan)
843 return;
844
845 ath_scan_channel_start(sc);
846 break;
847 case ATH_OFFCHANNEL_IDLE:
848 if (!sc->offchannel.scan_req)
849 return;
850
851 ath_scan_complete(sc, false);
852 break;
853 case ATH_OFFCHANNEL_ROC_START:
854 if (sc->cur_chan != &sc->offchannel.chan)
855 break;
856
857 sc->offchannel.state = ATH_OFFCHANNEL_ROC_WAIT;
858 mod_timer(&sc->offchannel.timer, jiffies +
859 msecs_to_jiffies(sc->offchannel.duration));
860 ieee80211_ready_on_channel(sc->hw);
861 break;
862 case ATH_OFFCHANNEL_ROC_DONE:
863 ath_roc_complete(sc, false);
864 break;
865 default:
866 break;
867 }
868}
869
Sujith Manoharan6d7cbd72014-08-23 13:29:10 +0530870void ath_chanctx_set_next(struct ath_softc *sc, bool force)
871{
872 struct timespec ts;
873 bool measure_time = false;
874 bool send_ps = false;
875
876 spin_lock_bh(&sc->chan_lock);
877 if (!sc->next_chan) {
878 spin_unlock_bh(&sc->chan_lock);
879 return;
880 }
881
882 if (!force && ath_chanctx_defer_switch(sc)) {
883 spin_unlock_bh(&sc->chan_lock);
884 return;
885 }
886
887 if (sc->cur_chan != sc->next_chan) {
888 sc->cur_chan->stopped = true;
889 spin_unlock_bh(&sc->chan_lock);
890
891 if (sc->next_chan == &sc->offchannel.chan) {
892 getrawmonotonic(&ts);
893 measure_time = true;
894 }
895 __ath9k_flush(sc->hw, ~0, true);
896
897 if (ath_chanctx_send_ps_frame(sc, true))
898 __ath9k_flush(sc->hw, BIT(IEEE80211_AC_VO), false);
899
900 send_ps = true;
901 spin_lock_bh(&sc->chan_lock);
902
903 if (sc->cur_chan != &sc->offchannel.chan) {
904 getrawmonotonic(&sc->cur_chan->tsf_ts);
905 sc->cur_chan->tsf_val = ath9k_hw_gettsf64(sc->sc_ah);
906 }
907 }
908 sc->cur_chan = sc->next_chan;
909 sc->cur_chan->stopped = false;
910 sc->next_chan = NULL;
911 sc->sched.offchannel_duration = 0;
912 if (sc->sched.state != ATH_CHANCTX_STATE_FORCE_ACTIVE)
913 sc->sched.state = ATH_CHANCTX_STATE_IDLE;
914
915 spin_unlock_bh(&sc->chan_lock);
916
917 if (sc->sc_ah->chip_fullsleep ||
918 memcmp(&sc->cur_chandef, &sc->cur_chan->chandef,
919 sizeof(sc->cur_chandef))) {
920 ath_set_channel(sc);
921 if (measure_time)
922 sc->sched.channel_switch_time =
923 ath9k_hw_get_tsf_offset(&ts, NULL);
924 }
925 if (send_ps)
926 ath_chanctx_send_ps_frame(sc, false);
927
928 ath_offchannel_channel_change(sc);
929 ath_chanctx_event(sc, NULL, ATH_CHANCTX_EVENT_SWITCH);
930}
931
Sujith Manoharan0e62f8b2014-08-23 13:29:08 +0530932static void ath_chanctx_work(struct work_struct *work)
933{
934 struct ath_softc *sc = container_of(work, struct ath_softc,
935 chanctx_work);
936 mutex_lock(&sc->mutex);
937 ath_chanctx_set_next(sc, false);
938 mutex_unlock(&sc->mutex);
939}
940
Sujith Manoharan705d0bf2014-08-23 13:29:06 +0530941void ath9k_init_channel_context(struct ath_softc *sc)
942{
943 INIT_WORK(&sc->chanctx_work, ath_chanctx_work);
944
945 setup_timer(&sc->offchannel.timer, ath_offchannel_timer,
946 (unsigned long)sc);
947 setup_timer(&sc->sched.timer, ath_chanctx_timer,
948 (unsigned long)sc);
949}
Sujith Manoharanc7dd40c2014-08-22 20:39:30 +0530950
Sujith Manoharanea22df22014-08-23 13:29:07 +0530951void ath9k_deinit_channel_context(struct ath_softc *sc)
952{
953 cancel_work_sync(&sc->chanctx_work);
954}
955
Sujith Manoharan499afac2014-08-22 20:39:31 +0530956bool ath9k_is_chanctx_enabled(void)
957{
958 return (ath9k_use_chanctx == 1);
959}
960
Sujith Manoharanc7dd40c2014-08-22 20:39:30 +0530961/*****************/
962/* P2P Powersave */
963/*****************/
964
965static void ath9k_update_p2p_ps_timer(struct ath_softc *sc, struct ath_vif *avp)
Sujith Manoharan2471adf2014-08-22 20:39:29 +0530966{
967 struct ath_hw *ah = sc->sc_ah;
968 s32 tsf, target_tsf;
969
970 if (!avp || !avp->noa.has_next_tsf)
971 return;
972
973 ath9k_hw_gen_timer_stop(ah, sc->p2p_ps_timer);
974
975 tsf = ath9k_hw_gettsf32(sc->sc_ah);
976
977 target_tsf = avp->noa.next_tsf;
978 if (!avp->noa.absent)
979 target_tsf -= ATH_P2P_PS_STOP_TIME;
980
981 if (target_tsf - tsf < ATH_P2P_PS_STOP_TIME)
982 target_tsf = tsf + ATH_P2P_PS_STOP_TIME;
983
984 ath9k_hw_gen_timer_start(ah, sc->p2p_ps_timer, (u32) target_tsf, 1000000);
985}
986
Sujith Manoharanc7dd40c2014-08-22 20:39:30 +0530987static void ath9k_update_p2p_ps(struct ath_softc *sc, struct ieee80211_vif *vif)
988{
989 struct ath_vif *avp = (void *)vif->drv_priv;
990 u32 tsf;
991
992 if (!sc->p2p_ps_timer)
993 return;
994
995 if (vif->type != NL80211_IFTYPE_STATION || !vif->p2p)
996 return;
997
998 sc->p2p_ps_vif = avp;
999 tsf = ath9k_hw_gettsf32(sc->sc_ah);
1000 ieee80211_parse_p2p_noa(&vif->bss_conf.p2p_noa_attr, &avp->noa, tsf);
1001 ath9k_update_p2p_ps_timer(sc, avp);
1002}
1003
Sujith Manoharan2471adf2014-08-22 20:39:29 +05301004void ath9k_p2p_ps_timer(void *priv)
1005{
1006 struct ath_softc *sc = priv;
1007 struct ath_vif *avp = sc->p2p_ps_vif;
1008 struct ieee80211_vif *vif;
1009 struct ieee80211_sta *sta;
1010 struct ath_node *an;
1011 u32 tsf;
1012
1013 del_timer_sync(&sc->sched.timer);
1014 ath9k_hw_gen_timer_stop(sc->sc_ah, sc->p2p_ps_timer);
1015 ath_chanctx_event(sc, NULL, ATH_CHANCTX_EVENT_TSF_TIMER);
1016
1017 if (!avp || avp->chanctx != sc->cur_chan)
1018 return;
1019
1020 tsf = ath9k_hw_gettsf32(sc->sc_ah);
1021 if (!avp->noa.absent)
1022 tsf += ATH_P2P_PS_STOP_TIME;
1023
1024 if (!avp->noa.has_next_tsf ||
1025 avp->noa.next_tsf - tsf > BIT(31))
1026 ieee80211_update_p2p_noa(&avp->noa, tsf);
1027
1028 ath9k_update_p2p_ps_timer(sc, avp);
1029
1030 rcu_read_lock();
1031
1032 vif = avp->vif;
1033 sta = ieee80211_find_sta(vif, vif->bss_conf.bssid);
1034 if (!sta)
1035 goto out;
1036
1037 an = (void *) sta->drv_priv;
1038 if (an->sleeping == !!avp->noa.absent)
1039 goto out;
1040
1041 an->sleeping = avp->noa.absent;
1042 if (an->sleeping)
1043 ath_tx_aggr_sleep(sta, sc, an);
1044 else
1045 ath_tx_aggr_wakeup(sc, an);
1046
1047out:
1048 rcu_read_unlock();
1049}
1050
Sujith Manoharanc7dd40c2014-08-22 20:39:30 +05301051void ath9k_p2p_bss_info_changed(struct ath_softc *sc,
1052 struct ieee80211_vif *vif)
1053{
1054 unsigned long flags;
1055
1056 spin_lock_bh(&sc->sc_pcu_lock);
1057 spin_lock_irqsave(&sc->sc_pm_lock, flags);
1058 if (!(sc->ps_flags & PS_BEACON_SYNC))
1059 ath9k_update_p2p_ps(sc, vif);
1060 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
1061 spin_unlock_bh(&sc->sc_pcu_lock);
1062}
1063
1064void ath9k_p2p_beacon_sync(struct ath_softc *sc)
1065{
1066 if (sc->p2p_ps_vif)
1067 ath9k_update_p2p_ps(sc, sc->p2p_ps_vif->vif);
1068}
1069
1070void ath9k_p2p_remove_vif(struct ath_softc *sc,
1071 struct ieee80211_vif *vif)
Sujith Manoharan2471adf2014-08-22 20:39:29 +05301072{
1073 struct ath_vif *avp = (void *)vif->drv_priv;
Sujith Manoharan2471adf2014-08-22 20:39:29 +05301074
Sujith Manoharanc7dd40c2014-08-22 20:39:30 +05301075 spin_lock_bh(&sc->sc_pcu_lock);
1076 if (avp == sc->p2p_ps_vif) {
1077 sc->p2p_ps_vif = NULL;
1078 ath9k_update_p2p_ps_timer(sc, NULL);
1079 }
1080 spin_unlock_bh(&sc->sc_pcu_lock);
Sujith Manoharan2471adf2014-08-22 20:39:29 +05301081}
Sujith Manoharanc7dd40c2014-08-22 20:39:30 +05301082
1083int ath9k_init_p2p(struct ath_softc *sc)
1084{
1085 sc->p2p_ps_timer = ath_gen_timer_alloc(sc->sc_ah, ath9k_p2p_ps_timer,
1086 NULL, sc, AR_FIRST_NDP_TIMER);
1087 if (!sc->p2p_ps_timer)
1088 return -ENOMEM;
1089
1090 return 0;
1091}
1092
1093void ath9k_deinit_p2p(struct ath_softc *sc)
1094{
1095 if (sc->p2p_ps_timer)
1096 ath_gen_timer_free(sc->sc_ah, sc->p2p_ps_timer);
1097}
1098
1099#endif /* CONFIG_ATH9K_CHANNEL_CONTEXT */