blob: 61ed7a72c989342172213c800486a981aadd4460 [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
Sujith Manoharanbc81d432014-08-22 20:39:27 +053019static const char *offchannel_state_string(enum ath_offchannel_state state)
20{
21#define case_rtn_string(val) case val: return #val
22
23 switch (state) {
24 case_rtn_string(ATH_OFFCHANNEL_IDLE);
25 case_rtn_string(ATH_OFFCHANNEL_PROBE_SEND);
26 case_rtn_string(ATH_OFFCHANNEL_PROBE_WAIT);
27 case_rtn_string(ATH_OFFCHANNEL_SUSPEND);
28 case_rtn_string(ATH_OFFCHANNEL_ROC_START);
29 case_rtn_string(ATH_OFFCHANNEL_ROC_WAIT);
30 case_rtn_string(ATH_OFFCHANNEL_ROC_DONE);
31 default:
32 return "unknown";
33 }
34}
35
Felix Fietkaufbbcd142014-06-11 16:17:49 +053036/* Set/change channels. If the channel is really being changed, it's done
37 * by reseting the chip. To accomplish this we must first cleanup any pending
38 * DMA, then restart stuff.
39 */
40static int ath_set_channel(struct ath_softc *sc)
41{
42 struct ath_hw *ah = sc->sc_ah;
43 struct ath_common *common = ath9k_hw_common(ah);
44 struct ieee80211_hw *hw = sc->hw;
45 struct ath9k_channel *hchan;
46 struct cfg80211_chan_def *chandef = &sc->cur_chan->chandef;
47 struct ieee80211_channel *chan = chandef->chan;
48 int pos = chan->hw_value;
49 int old_pos = -1;
50 int r;
51
52 if (test_bit(ATH_OP_INVALID, &common->op_flags))
53 return -EIO;
54
55 if (ah->curchan)
56 old_pos = ah->curchan - &ah->channels[0];
57
58 ath_dbg(common, CONFIG, "Set channel: %d MHz width: %d\n",
59 chan->center_freq, chandef->width);
60
61 /* update survey stats for the old channel before switching */
62 spin_lock_bh(&common->cc_lock);
63 ath_update_survey_stats(sc);
64 spin_unlock_bh(&common->cc_lock);
65
66 ath9k_cmn_get_channel(hw, ah, chandef);
67
68 /* If the operating channel changes, change the survey in-use flags
69 * along with it.
70 * Reset the survey data for the new channel, unless we're switching
71 * back to the operating channel from an off-channel operation.
72 */
73 if (!sc->cur_chan->offchannel && sc->cur_survey != &sc->survey[pos]) {
74 if (sc->cur_survey)
75 sc->cur_survey->filled &= ~SURVEY_INFO_IN_USE;
76
77 sc->cur_survey = &sc->survey[pos];
78
79 memset(sc->cur_survey, 0, sizeof(struct survey_info));
80 sc->cur_survey->filled |= SURVEY_INFO_IN_USE;
81 } else if (!(sc->survey[pos].filled & SURVEY_INFO_IN_USE)) {
82 memset(&sc->survey[pos], 0, sizeof(struct survey_info));
83 }
84
85 hchan = &sc->sc_ah->channels[pos];
86 r = ath_reset_internal(sc, hchan);
87 if (r)
88 return r;
89
90 /* The most recent snapshot of channel->noisefloor for the old
91 * channel is only available after the hardware reset. Copy it to
92 * the survey stats now.
93 */
94 if (old_pos >= 0)
95 ath_update_survey_nf(sc, old_pos);
96
97 /* Enable radar pulse detection if on a DFS channel. Spectral
98 * scanning and radar detection can not be used concurrently.
99 */
100 if (hw->conf.radar_enabled) {
101 u32 rxfilter;
102
103 /* set HW specific DFS configuration */
104 ath9k_hw_set_radar_params(ah);
105 rxfilter = ath9k_hw_getrxfilter(ah);
106 rxfilter |= ATH9K_RX_FILTER_PHYRADAR |
107 ATH9K_RX_FILTER_PHYERR;
108 ath9k_hw_setrxfilter(ah, rxfilter);
109 ath_dbg(common, DFS, "DFS enabled at freq %d\n",
110 chan->center_freq);
111 } else {
112 /* perform spectral scan if requested. */
113 if (test_bit(ATH_OP_SCANNING, &common->op_flags) &&
114 sc->spectral_mode == SPECTRAL_CHANSCAN)
115 ath9k_spectral_scan_trigger(hw);
116 }
117
118 return 0;
119}
120
Felix Fietkauc083ce92014-06-11 16:17:54 +0530121void ath_chanctx_check_active(struct ath_softc *sc, struct ath_chanctx *ctx)
122{
Felix Fietkau26f16c22014-06-11 16:18:00 +0530123 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Felix Fietkauc083ce92014-06-11 16:17:54 +0530124 struct ath_vif *avp;
125 bool active = false;
Felix Fietkau26f16c22014-06-11 16:18:00 +0530126 u8 n_active = 0;
Felix Fietkauc083ce92014-06-11 16:17:54 +0530127
128 if (!ctx)
129 return;
130
131 list_for_each_entry(avp, &ctx->vifs, list) {
132 struct ieee80211_vif *vif = avp->vif;
133
134 switch (vif->type) {
135 case NL80211_IFTYPE_P2P_CLIENT:
136 case NL80211_IFTYPE_STATION:
137 if (vif->bss_conf.assoc)
138 active = true;
139 break;
140 default:
141 active = true;
142 break;
143 }
144 }
145 ctx->active = active;
Felix Fietkau26f16c22014-06-11 16:18:00 +0530146
147 ath_for_each_chanctx(sc, ctx) {
148 if (!ctx->assigned || list_empty(&ctx->vifs))
149 continue;
150 n_active++;
151 }
152
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530153 if (n_active <= 1) {
Felix Fietkau26f16c22014-06-11 16:18:00 +0530154 clear_bit(ATH_OP_MULTI_CHANNEL, &common->op_flags);
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530155 return;
156 }
157 if (test_and_set_bit(ATH_OP_MULTI_CHANNEL, &common->op_flags))
158 return;
159 ath_chanctx_event(sc, NULL, ATH_CHANCTX_EVENT_ENABLE_MULTICHANNEL);
Felix Fietkauc083ce92014-06-11 16:17:54 +0530160}
161
Felix Fietkaufbbcd142014-06-11 16:17:49 +0530162void ath_chanctx_init(struct ath_softc *sc)
163{
164 struct ath_chanctx *ctx;
165 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
166 struct ieee80211_supported_band *sband;
167 struct ieee80211_channel *chan;
Felix Fietkau04535312014-06-11 16:17:51 +0530168 int i, j;
Felix Fietkaufbbcd142014-06-11 16:17:49 +0530169
170 sband = &common->sbands[IEEE80211_BAND_2GHZ];
171 if (!sband->n_channels)
172 sband = &common->sbands[IEEE80211_BAND_5GHZ];
173
174 chan = &sband->channels[0];
175 for (i = 0; i < ATH9K_NUM_CHANCTX; i++) {
176 ctx = &sc->chanctx[i];
177 cfg80211_chandef_create(&ctx->chandef, chan, NL80211_CHAN_HT20);
178 INIT_LIST_HEAD(&ctx->vifs);
Felix Fietkaubc7e1be2014-06-11 16:17:50 +0530179 ctx->txpower = ATH_TXPOWER_MAX;
Felix Fietkau04535312014-06-11 16:17:51 +0530180 for (j = 0; j < ARRAY_SIZE(ctx->acq); j++)
181 INIT_LIST_HEAD(&ctx->acq[j]);
Felix Fietkaufbbcd142014-06-11 16:17:49 +0530182 }
Felix Fietkau78b21942014-06-11 16:17:55 +0530183 ctx = &sc->offchannel.chan;
184 cfg80211_chandef_create(&ctx->chandef, chan, NL80211_CHAN_HT20);
185 INIT_LIST_HEAD(&ctx->vifs);
186 ctx->txpower = ATH_TXPOWER_MAX;
187 for (j = 0; j < ARRAY_SIZE(ctx->acq); j++)
188 INIT_LIST_HEAD(&ctx->acq[j]);
189 sc->offchannel.chan.offchannel = true;
190
Felix Fietkaufbbcd142014-06-11 16:17:49 +0530191}
192
Felix Fietkaubff11762014-06-11 16:17:52 +0530193void ath_chanctx_switch(struct ath_softc *sc, struct ath_chanctx *ctx,
194 struct cfg80211_chan_def *chandef)
Felix Fietkaufbbcd142014-06-11 16:17:49 +0530195{
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530196 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Felix Fietkaufbbcd142014-06-11 16:17:49 +0530197
Felix Fietkaubff11762014-06-11 16:17:52 +0530198 spin_lock_bh(&sc->chan_lock);
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530199
200 if (test_bit(ATH_OP_MULTI_CHANNEL, &common->op_flags) &&
201 (sc->cur_chan != ctx) && (ctx == &sc->offchannel.chan)) {
202 sc->sched.offchannel_pending = true;
203 spin_unlock_bh(&sc->chan_lock);
204 return;
205 }
206
Felix Fietkaubff11762014-06-11 16:17:52 +0530207 sc->next_chan = ctx;
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530208 if (chandef) {
Felix Fietkaubff11762014-06-11 16:17:52 +0530209 ctx->chandef = *chandef;
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530210 ath_dbg(common, CHAN_CTX,
211 "Assigned next_chan to %d MHz\n", chandef->center_freq1);
212 }
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530213
214 if (sc->next_chan == &sc->offchannel.chan) {
215 sc->sched.offchannel_duration =
216 TU_TO_USEC(sc->offchannel.duration) +
217 sc->sched.channel_switch_time;
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530218
219 if (chandef) {
220 ath_dbg(common, CHAN_CTX,
221 "Offchannel duration for chan %d MHz : %u\n",
222 chandef->center_freq1,
223 sc->sched.offchannel_duration);
224 }
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530225 }
Felix Fietkaubff11762014-06-11 16:17:52 +0530226 spin_unlock_bh(&sc->chan_lock);
227 ieee80211_queue_work(sc->hw, &sc->chanctx_work);
228}
229
230void ath_chanctx_set_channel(struct ath_softc *sc, struct ath_chanctx *ctx,
231 struct cfg80211_chan_def *chandef)
232{
233 bool cur_chan;
234
235 spin_lock_bh(&sc->chan_lock);
236 if (chandef)
237 memcpy(&ctx->chandef, chandef, sizeof(*chandef));
238 cur_chan = sc->cur_chan == ctx;
239 spin_unlock_bh(&sc->chan_lock);
240
241 if (!cur_chan)
242 return;
243
244 ath_set_channel(sc);
Felix Fietkaufbbcd142014-06-11 16:17:49 +0530245}
Felix Fietkau78b21942014-06-11 16:17:55 +0530246
Rajkumar Manoharanc4dc0d02014-06-11 16:17:58 +0530247struct ath_chanctx *ath_chanctx_get_oper_chan(struct ath_softc *sc, bool active)
Felix Fietkau78b21942014-06-11 16:17:55 +0530248{
Rajkumar Manoharanc4dc0d02014-06-11 16:17:58 +0530249 struct ath_chanctx *ctx;
Felix Fietkau78b21942014-06-11 16:17:55 +0530250
Rajkumar Manoharanc4dc0d02014-06-11 16:17:58 +0530251 ath_for_each_chanctx(sc, ctx) {
252 if (!ctx->assigned || list_empty(&ctx->vifs))
253 continue;
254 if (active && !ctx->active)
255 continue;
256
Felix Fietkau8eab25102014-06-11 16:18:07 +0530257 if (ctx->switch_after_beacon)
258 return ctx;
Felix Fietkau78b21942014-06-11 16:17:55 +0530259 }
260
261 return &sc->chanctx[0];
262}
263
264void ath_chanctx_offchan_switch(struct ath_softc *sc,
265 struct ieee80211_channel *chan)
266{
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530267 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Felix Fietkau78b21942014-06-11 16:17:55 +0530268 struct cfg80211_chan_def chandef;
269
270 cfg80211_chandef_create(&chandef, chan, NL80211_CHAN_NO_HT);
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530271 ath_dbg(common, CHAN_CTX,
272 "Channel definition created: %d MHz\n", chandef.center_freq1);
Felix Fietkau78b21942014-06-11 16:17:55 +0530273
274 ath_chanctx_switch(sc, &sc->offchannel.chan, &chandef);
275}
Felix Fietkau748299f2014-06-11 16:18:04 +0530276
Felix Fietkau58b57372014-06-11 16:18:08 +0530277static struct ath_chanctx *
278ath_chanctx_get_next(struct ath_softc *sc, struct ath_chanctx *ctx)
279{
280 int idx = ctx - &sc->chanctx[0];
281
282 return &sc->chanctx[!idx];
283}
284
285static void ath_chanctx_adjust_tbtt_delta(struct ath_softc *sc)
286{
287 struct ath_chanctx *prev, *cur;
288 struct timespec ts;
289 u32 cur_tsf, prev_tsf, beacon_int;
290 s32 offset;
291
292 beacon_int = TU_TO_USEC(sc->cur_chan->beacon.beacon_interval);
293
294 cur = sc->cur_chan;
295 prev = ath_chanctx_get_next(sc, cur);
296
297 getrawmonotonic(&ts);
298 cur_tsf = (u32) cur->tsf_val +
299 ath9k_hw_get_tsf_offset(&cur->tsf_ts, &ts);
300
301 prev_tsf = prev->last_beacon - (u32) prev->tsf_val + cur_tsf;
302 prev_tsf -= ath9k_hw_get_tsf_offset(&prev->tsf_ts, &ts);
303
304 /* Adjust the TSF time of the AP chanctx to keep its beacons
305 * at half beacon interval offset relative to the STA chanctx.
306 */
307 offset = cur_tsf - prev_tsf;
308
309 /* Ignore stale data or spurious timestamps */
310 if (offset < 0 || offset > 3 * beacon_int)
311 return;
312
313 offset = beacon_int / 2 - (offset % beacon_int);
314 prev->tsf_val += offset;
315}
316
Felix Fietkau42eda112014-06-11 16:18:14 +0530317/* Configure the TSF based hardware timer for a channel switch.
318 * Also set up backup software timer, in case the gen timer fails.
319 * This could be caused by a hardware reset.
320 */
321static void ath_chanctx_setup_timer(struct ath_softc *sc, u32 tsf_time)
322{
323 struct ath_hw *ah = sc->sc_ah;
324
Sujith Manoharanc7dd40c2014-08-22 20:39:30 +0530325#ifdef CONFIG_ATH9K_CHANNEL_CONTEXT
Felix Fietkau42eda112014-06-11 16:18:14 +0530326 ath9k_hw_gen_timer_start(ah, sc->p2p_ps_timer, tsf_time, 1000000);
Sujith Manoharanc7dd40c2014-08-22 20:39:30 +0530327#endif
Felix Fietkau42eda112014-06-11 16:18:14 +0530328 tsf_time -= ath9k_hw_gettsf32(ah);
329 tsf_time = msecs_to_jiffies(tsf_time / 1000) + 1;
330 mod_timer(&sc->sched.timer, tsf_time);
331}
332
Felix Fietkau748299f2014-06-11 16:18:04 +0530333void ath_chanctx_event(struct ath_softc *sc, struct ieee80211_vif *vif,
334 enum ath_chanctx_event ev)
335{
336 struct ath_hw *ah = sc->sc_ah;
Felix Fietkau58b57372014-06-11 16:18:08 +0530337 struct ath_common *common = ath9k_hw_common(ah);
Felix Fietkau74148632014-06-11 16:18:11 +0530338 struct ath_beacon_config *cur_conf;
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530339 struct ath_vif *avp = NULL;
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530340 struct ath_chanctx *ctx;
Felix Fietkau748299f2014-06-11 16:18:04 +0530341 u32 tsf_time;
Felix Fietkauec70abe2014-06-11 16:18:12 +0530342 u32 beacon_int;
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530343 bool noa_changed = false;
344
345 if (vif)
346 avp = (struct ath_vif *) vif->drv_priv;
Felix Fietkau748299f2014-06-11 16:18:04 +0530347
348 spin_lock_bh(&sc->chan_lock);
349
350 switch (ev) {
351 case ATH_CHANCTX_EVENT_BEACON_PREPARE:
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530352 if (avp->offchannel_duration)
353 avp->offchannel_duration = 0;
354
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530355 if (avp->chanctx != sc->cur_chan)
356 break;
357
358 if (sc->sched.offchannel_pending) {
359 sc->sched.offchannel_pending = false;
360 sc->next_chan = &sc->offchannel.chan;
361 sc->sched.state = ATH_CHANCTX_STATE_WAIT_FOR_BEACON;
362 }
363
364 ctx = ath_chanctx_get_next(sc, sc->cur_chan);
365 if (ctx->active && sc->sched.state == ATH_CHANCTX_STATE_IDLE) {
366 sc->next_chan = ctx;
367 sc->sched.state = ATH_CHANCTX_STATE_WAIT_FOR_BEACON;
368 }
369
370 /* if the timer missed its window, use the next interval */
371 if (sc->sched.state == ATH_CHANCTX_STATE_WAIT_FOR_TIMER)
372 sc->sched.state = ATH_CHANCTX_STATE_WAIT_FOR_BEACON;
373
Felix Fietkau748299f2014-06-11 16:18:04 +0530374 if (sc->sched.state != ATH_CHANCTX_STATE_WAIT_FOR_BEACON)
375 break;
376
377 sc->sched.beacon_pending = true;
378 sc->sched.next_tbtt = REG_READ(ah, AR_NEXT_TBTT_TIMER);
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530379
Felix Fietkau74148632014-06-11 16:18:11 +0530380 cur_conf = &sc->cur_chan->beacon;
Felix Fietkauec70abe2014-06-11 16:18:12 +0530381 beacon_int = TU_TO_USEC(cur_conf->beacon_interval);
382
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530383 /* defer channel switch by a quarter beacon interval */
Felix Fietkauec70abe2014-06-11 16:18:12 +0530384 tsf_time = sc->sched.next_tbtt + beacon_int / 4;
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530385 sc->sched.switch_start_time = tsf_time;
Felix Fietkau58b57372014-06-11 16:18:08 +0530386 sc->cur_chan->last_beacon = sc->sched.next_tbtt;
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530387
Felix Fietkau74148632014-06-11 16:18:11 +0530388 /* Prevent wrap-around issues */
389 if (avp->periodic_noa_duration &&
390 tsf_time - avp->periodic_noa_start > BIT(30))
391 avp->periodic_noa_duration = 0;
392
393 if (ctx->active && !avp->periodic_noa_duration) {
394 avp->periodic_noa_start = tsf_time;
395 avp->periodic_noa_duration =
396 TU_TO_USEC(cur_conf->beacon_interval) / 2 -
397 sc->sched.channel_switch_time;
398 noa_changed = true;
399 } else if (!ctx->active && avp->periodic_noa_duration) {
400 avp->periodic_noa_duration = 0;
401 noa_changed = true;
402 }
403
Felix Fietkauec70abe2014-06-11 16:18:12 +0530404 /* If at least two consecutive beacons were missed on the STA
405 * chanctx, stay on the STA channel for one extra beacon period,
406 * to resync the timer properly.
407 */
408 if (ctx->active && sc->sched.beacon_miss >= 2)
409 sc->sched.offchannel_duration = 3 * beacon_int / 2;
410
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530411 if (sc->sched.offchannel_duration) {
412 noa_changed = true;
413 avp->offchannel_start = tsf_time;
414 avp->offchannel_duration =
415 sc->sched.offchannel_duration;
416 }
417
418 if (noa_changed)
419 avp->noa_index++;
Felix Fietkau748299f2014-06-11 16:18:04 +0530420 break;
421 case ATH_CHANCTX_EVENT_BEACON_SENT:
422 if (!sc->sched.beacon_pending)
423 break;
424
425 sc->sched.beacon_pending = false;
426 if (sc->sched.state != ATH_CHANCTX_STATE_WAIT_FOR_BEACON)
427 break;
428
Felix Fietkau748299f2014-06-11 16:18:04 +0530429 sc->sched.state = ATH_CHANCTX_STATE_WAIT_FOR_TIMER;
Felix Fietkau42eda112014-06-11 16:18:14 +0530430 ath_chanctx_setup_timer(sc, sc->sched.switch_start_time);
Felix Fietkau748299f2014-06-11 16:18:04 +0530431 break;
432 case ATH_CHANCTX_EVENT_TSF_TIMER:
433 if (sc->sched.state != ATH_CHANCTX_STATE_WAIT_FOR_TIMER)
434 break;
435
Felix Fietkauec70abe2014-06-11 16:18:12 +0530436 if (!sc->cur_chan->switch_after_beacon &&
437 sc->sched.beacon_pending)
438 sc->sched.beacon_miss++;
439
Felix Fietkau748299f2014-06-11 16:18:04 +0530440 sc->sched.state = ATH_CHANCTX_STATE_SWITCH;
441 ieee80211_queue_work(sc->hw, &sc->chanctx_work);
442 break;
Felix Fietkau58b57372014-06-11 16:18:08 +0530443 case ATH_CHANCTX_EVENT_BEACON_RECEIVED:
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530444 if (!test_bit(ATH_OP_MULTI_CHANNEL, &common->op_flags) ||
445 sc->cur_chan == &sc->offchannel.chan)
Felix Fietkau58b57372014-06-11 16:18:08 +0530446 break;
447
448 ath_chanctx_adjust_tbtt_delta(sc);
Felix Fietkauec70abe2014-06-11 16:18:12 +0530449 sc->sched.beacon_pending = false;
450 sc->sched.beacon_miss = 0;
Felix Fietkaua899b672014-06-11 16:18:13 +0530451
452 /* TSF time might have been updated by the incoming beacon,
453 * need update the channel switch timer to reflect the change.
454 */
455 tsf_time = sc->sched.switch_start_time;
456 tsf_time -= (u32) sc->cur_chan->tsf_val +
457 ath9k_hw_get_tsf_offset(&sc->cur_chan->tsf_ts, NULL);
458 tsf_time += ath9k_hw_gettsf32(ah);
459
Felix Fietkau42eda112014-06-11 16:18:14 +0530460
461 ath_chanctx_setup_timer(sc, tsf_time);
Felix Fietkau58b57372014-06-11 16:18:08 +0530462 break;
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530463 case ATH_CHANCTX_EVENT_ASSOC:
464 if (sc->sched.state != ATH_CHANCTX_STATE_FORCE_ACTIVE ||
465 avp->chanctx != sc->cur_chan)
466 break;
467
468 sc->sched.state = ATH_CHANCTX_STATE_IDLE;
469 /* fall through */
470 case ATH_CHANCTX_EVENT_SWITCH:
471 if (!test_bit(ATH_OP_MULTI_CHANNEL, &common->op_flags) ||
472 sc->sched.state == ATH_CHANCTX_STATE_FORCE_ACTIVE ||
473 sc->cur_chan->switch_after_beacon ||
474 sc->cur_chan == &sc->offchannel.chan)
475 break;
476
477 /* If this is a station chanctx, stay active for a half
478 * beacon period (minus channel switch time)
479 */
480 sc->next_chan = ath_chanctx_get_next(sc, sc->cur_chan);
Felix Fietkau74148632014-06-11 16:18:11 +0530481 cur_conf = &sc->cur_chan->beacon;
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530482
483 sc->sched.state = ATH_CHANCTX_STATE_WAIT_FOR_TIMER;
Felix Fietkauec70abe2014-06-11 16:18:12 +0530484
485 tsf_time = TU_TO_USEC(cur_conf->beacon_interval) / 2;
486 if (sc->sched.beacon_miss >= 2) {
487 sc->sched.beacon_miss = 0;
488 tsf_time *= 3;
489 }
490
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530491 tsf_time -= sc->sched.channel_switch_time;
Felix Fietkauec70abe2014-06-11 16:18:12 +0530492 tsf_time += ath9k_hw_gettsf32(sc->sc_ah);
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530493 sc->sched.switch_start_time = tsf_time;
494
Felix Fietkau42eda112014-06-11 16:18:14 +0530495 ath_chanctx_setup_timer(sc, tsf_time);
Felix Fietkauec70abe2014-06-11 16:18:12 +0530496 sc->sched.beacon_pending = true;
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530497 break;
498 case ATH_CHANCTX_EVENT_ENABLE_MULTICHANNEL:
499 if (sc->cur_chan == &sc->offchannel.chan ||
500 sc->cur_chan->switch_after_beacon)
501 break;
502
503 sc->next_chan = ath_chanctx_get_next(sc, sc->cur_chan);
504 ieee80211_queue_work(sc->hw, &sc->chanctx_work);
505 break;
506 case ATH_CHANCTX_EVENT_UNASSIGN:
507 if (sc->cur_chan->assigned) {
508 if (sc->next_chan && !sc->next_chan->assigned &&
509 sc->next_chan != &sc->offchannel.chan)
510 sc->sched.state = ATH_CHANCTX_STATE_IDLE;
511 break;
512 }
513
514 ctx = ath_chanctx_get_next(sc, sc->cur_chan);
515 sc->sched.state = ATH_CHANCTX_STATE_IDLE;
516 if (!ctx->assigned)
517 break;
518
519 sc->next_chan = ctx;
520 ieee80211_queue_work(sc->hw, &sc->chanctx_work);
521 break;
Felix Fietkau748299f2014-06-11 16:18:04 +0530522 }
523
524 spin_unlock_bh(&sc->chan_lock);
525}
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530526
527static int ath_scan_channel_duration(struct ath_softc *sc,
528 struct ieee80211_channel *chan)
529{
530 struct cfg80211_scan_request *req = sc->offchannel.scan_req;
531
532 if (!req->n_ssids || (chan->flags & IEEE80211_CHAN_NO_IR))
533 return (HZ / 9); /* ~110 ms */
534
535 return (HZ / 16); /* ~60 ms */
536}
537
538static void
539ath_scan_next_channel(struct ath_softc *sc)
540{
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530541 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530542 struct cfg80211_scan_request *req = sc->offchannel.scan_req;
543 struct ieee80211_channel *chan;
544
545 if (sc->offchannel.scan_idx >= req->n_channels) {
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530546 ath_dbg(common, CHAN_CTX,
547 "Moving to ATH_OFFCHANNEL_IDLE state, scan_idx: %d, n_channels: %d\n",
548 sc->offchannel.scan_idx,
549 req->n_channels);
550
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530551 sc->offchannel.state = ATH_OFFCHANNEL_IDLE;
552 ath_chanctx_switch(sc, ath_chanctx_get_oper_chan(sc, false),
553 NULL);
554 return;
555 }
556
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530557 ath_dbg(common, CHAN_CTX,
558 "Moving to ATH_OFFCHANNEL_PROBE_SEND state, scan_idx: %d\n",
559 sc->offchannel.scan_idx);
560
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530561 chan = req->channels[sc->offchannel.scan_idx++];
562 sc->offchannel.duration = ath_scan_channel_duration(sc, chan);
563 sc->offchannel.state = ATH_OFFCHANNEL_PROBE_SEND;
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530564
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530565 ath_chanctx_offchan_switch(sc, chan);
566}
567
568void ath_offchannel_next(struct ath_softc *sc)
569{
570 struct ieee80211_vif *vif;
571
572 if (sc->offchannel.scan_req) {
573 vif = sc->offchannel.scan_vif;
574 sc->offchannel.chan.txpower = vif->bss_conf.txpower;
575 ath_scan_next_channel(sc);
576 } else if (sc->offchannel.roc_vif) {
577 vif = sc->offchannel.roc_vif;
578 sc->offchannel.chan.txpower = vif->bss_conf.txpower;
579 sc->offchannel.duration = sc->offchannel.roc_duration;
580 sc->offchannel.state = ATH_OFFCHANNEL_ROC_START;
581 ath_chanctx_offchan_switch(sc, sc->offchannel.roc_chan);
582 } else {
583 ath_chanctx_switch(sc, ath_chanctx_get_oper_chan(sc, false),
584 NULL);
585 sc->offchannel.state = ATH_OFFCHANNEL_IDLE;
586 if (sc->ps_idle)
587 ath_cancel_work(sc);
588 }
589}
590
591void ath_roc_complete(struct ath_softc *sc, bool abort)
592{
593 sc->offchannel.roc_vif = NULL;
594 sc->offchannel.roc_chan = NULL;
595 if (!abort)
596 ieee80211_remain_on_channel_expired(sc->hw);
597 ath_offchannel_next(sc);
598 ath9k_ps_restore(sc);
599}
600
601void ath_scan_complete(struct ath_softc *sc, bool abort)
602{
603 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
604
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530605 if (abort)
606 ath_dbg(common, CHAN_CTX, "HW scan aborted\n");
607 else
608 ath_dbg(common, CHAN_CTX, "HW scan complete\n");
609
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530610 sc->offchannel.scan_req = NULL;
611 sc->offchannel.scan_vif = NULL;
612 sc->offchannel.state = ATH_OFFCHANNEL_IDLE;
613 ieee80211_scan_completed(sc->hw, abort);
614 clear_bit(ATH_OP_SCANNING, &common->op_flags);
615 ath_offchannel_next(sc);
616 ath9k_ps_restore(sc);
617}
618
619static void ath_scan_send_probe(struct ath_softc *sc,
620 struct cfg80211_ssid *ssid)
621{
622 struct cfg80211_scan_request *req = sc->offchannel.scan_req;
623 struct ieee80211_vif *vif = sc->offchannel.scan_vif;
624 struct ath_tx_control txctl = {};
625 struct sk_buff *skb;
626 struct ieee80211_tx_info *info;
627 int band = sc->offchannel.chan.chandef.chan->band;
628
629 skb = ieee80211_probereq_get(sc->hw, vif,
630 ssid->ssid, ssid->ssid_len, req->ie_len);
631 if (!skb)
632 return;
633
634 info = IEEE80211_SKB_CB(skb);
635 if (req->no_cck)
636 info->flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
637
638 if (req->ie_len)
639 memcpy(skb_put(skb, req->ie_len), req->ie, req->ie_len);
640
641 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
642
643 if (!ieee80211_tx_prepare_skb(sc->hw, vif, skb, band, NULL))
644 goto error;
645
646 txctl.txq = sc->tx.txq_map[IEEE80211_AC_VO];
647 txctl.force_channel = true;
648 if (ath_tx_start(sc->hw, skb, &txctl))
649 goto error;
650
651 return;
652
653error:
654 ieee80211_free_txskb(sc->hw, skb);
655}
656
657static void ath_scan_channel_start(struct ath_softc *sc)
658{
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530659 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530660 struct cfg80211_scan_request *req = sc->offchannel.scan_req;
661 int i;
662
663 if (!(sc->cur_chan->chandef.chan->flags & IEEE80211_CHAN_NO_IR) &&
664 req->n_ssids) {
665 for (i = 0; i < req->n_ssids; i++)
666 ath_scan_send_probe(sc, &req->ssids[i]);
667
668 }
669
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530670 ath_dbg(common, CHAN_CTX,
671 "Moving to ATH_OFFCHANNEL_PROBE_WAIT state\n");
672
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530673 sc->offchannel.state = ATH_OFFCHANNEL_PROBE_WAIT;
674 mod_timer(&sc->offchannel.timer, jiffies + sc->offchannel.duration);
675}
676
677void ath_offchannel_channel_change(struct ath_softc *sc)
678{
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530679 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
680
681 ath_dbg(common, CHAN_CTX, "%s: state: %s\n",
682 __func__, offchannel_state_string(sc->offchannel.state));
683
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530684 switch (sc->offchannel.state) {
685 case ATH_OFFCHANNEL_PROBE_SEND:
686 if (!sc->offchannel.scan_req)
687 return;
688
689 if (sc->cur_chan->chandef.chan !=
690 sc->offchannel.chan.chandef.chan)
691 return;
692
693 ath_scan_channel_start(sc);
694 break;
695 case ATH_OFFCHANNEL_IDLE:
696 if (!sc->offchannel.scan_req)
697 return;
698
699 ath_scan_complete(sc, false);
700 break;
701 case ATH_OFFCHANNEL_ROC_START:
702 if (sc->cur_chan != &sc->offchannel.chan)
703 break;
704
705 sc->offchannel.state = ATH_OFFCHANNEL_ROC_WAIT;
706 mod_timer(&sc->offchannel.timer, jiffies +
707 msecs_to_jiffies(sc->offchannel.duration));
708 ieee80211_ready_on_channel(sc->hw);
709 break;
710 case ATH_OFFCHANNEL_ROC_DONE:
711 ath_roc_complete(sc, false);
712 break;
713 default:
714 break;
715 }
716}
717
Sujith Manoharan705d0bf2014-08-23 13:29:06 +0530718#ifdef CONFIG_ATH9K_CHANNEL_CONTEXT
719
720static void ath_chanctx_timer(unsigned long data)
721{
722 struct ath_softc *sc = (struct ath_softc *) data;
723
724 ath_chanctx_event(sc, NULL, ATH_CHANCTX_EVENT_TSF_TIMER);
725}
726
727static void ath_offchannel_timer(unsigned long data)
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530728{
729 struct ath_softc *sc = (struct ath_softc *)data;
730 struct ath_chanctx *ctx;
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530731 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
732
733 ath_dbg(common, CHAN_CTX, "%s: state: %s\n",
734 __func__, offchannel_state_string(sc->offchannel.state));
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530735
736 switch (sc->offchannel.state) {
737 case ATH_OFFCHANNEL_PROBE_WAIT:
738 if (!sc->offchannel.scan_req)
739 return;
740
741 /* get first active channel context */
742 ctx = ath_chanctx_get_oper_chan(sc, true);
743 if (ctx->active) {
744 sc->offchannel.state = ATH_OFFCHANNEL_SUSPEND;
745 ath_chanctx_switch(sc, ctx, NULL);
746 mod_timer(&sc->offchannel.timer, jiffies + HZ / 10);
747 break;
748 }
749 /* fall through */
750 case ATH_OFFCHANNEL_SUSPEND:
751 if (!sc->offchannel.scan_req)
752 return;
753
754 ath_scan_next_channel(sc);
755 break;
756 case ATH_OFFCHANNEL_ROC_START:
757 case ATH_OFFCHANNEL_ROC_WAIT:
758 ctx = ath_chanctx_get_oper_chan(sc, false);
759 sc->offchannel.state = ATH_OFFCHANNEL_ROC_DONE;
760 ath_chanctx_switch(sc, ctx, NULL);
761 break;
762 default:
763 break;
764 }
765}
Sujith Manoharan2471adf2014-08-22 20:39:29 +0530766
Sujith Manoharan6d7cbd72014-08-23 13:29:10 +0530767static bool
768ath_chanctx_send_vif_ps_frame(struct ath_softc *sc, struct ath_vif *avp,
769 bool powersave)
770{
771 struct ieee80211_vif *vif = avp->vif;
772 struct ieee80211_sta *sta = NULL;
773 struct ieee80211_hdr_3addr *nullfunc;
774 struct ath_tx_control txctl;
775 struct sk_buff *skb;
776 int band = sc->cur_chan->chandef.chan->band;
777
778 switch (vif->type) {
779 case NL80211_IFTYPE_STATION:
780 if (!vif->bss_conf.assoc)
781 return false;
782
783 skb = ieee80211_nullfunc_get(sc->hw, vif);
784 if (!skb)
785 return false;
786
787 nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
788 if (powersave)
789 nullfunc->frame_control |=
790 cpu_to_le16(IEEE80211_FCTL_PM);
791
792 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
793 if (!ieee80211_tx_prepare_skb(sc->hw, vif, skb, band, &sta)) {
794 dev_kfree_skb_any(skb);
795 return false;
796 }
797 break;
798 default:
799 return false;
800 }
801
802 memset(&txctl, 0, sizeof(txctl));
803 txctl.txq = sc->tx.txq_map[IEEE80211_AC_VO];
804 txctl.sta = sta;
805 txctl.force_channel = true;
806 if (ath_tx_start(sc->hw, skb, &txctl)) {
807 ieee80211_free_txskb(sc->hw, skb);
808 return false;
809 }
810
811 return true;
812}
813
814static bool
815ath_chanctx_send_ps_frame(struct ath_softc *sc, bool powersave)
816{
817 struct ath_vif *avp;
818 bool sent = false;
819
820 rcu_read_lock();
821 list_for_each_entry(avp, &sc->cur_chan->vifs, list) {
822 if (ath_chanctx_send_vif_ps_frame(sc, avp, powersave))
823 sent = true;
824 }
825 rcu_read_unlock();
826
827 return sent;
828}
829
830static bool ath_chanctx_defer_switch(struct ath_softc *sc)
831{
832 if (sc->cur_chan == &sc->offchannel.chan)
833 return false;
834
835 switch (sc->sched.state) {
836 case ATH_CHANCTX_STATE_SWITCH:
837 return false;
838 case ATH_CHANCTX_STATE_IDLE:
839 if (!sc->cur_chan->switch_after_beacon)
840 return false;
841
842 sc->sched.state = ATH_CHANCTX_STATE_WAIT_FOR_BEACON;
843 break;
844 default:
845 break;
846 }
847
848 return true;
849}
850
851void ath_chanctx_set_next(struct ath_softc *sc, bool force)
852{
853 struct timespec ts;
854 bool measure_time = false;
855 bool send_ps = false;
856
857 spin_lock_bh(&sc->chan_lock);
858 if (!sc->next_chan) {
859 spin_unlock_bh(&sc->chan_lock);
860 return;
861 }
862
863 if (!force && ath_chanctx_defer_switch(sc)) {
864 spin_unlock_bh(&sc->chan_lock);
865 return;
866 }
867
868 if (sc->cur_chan != sc->next_chan) {
869 sc->cur_chan->stopped = true;
870 spin_unlock_bh(&sc->chan_lock);
871
872 if (sc->next_chan == &sc->offchannel.chan) {
873 getrawmonotonic(&ts);
874 measure_time = true;
875 }
876 __ath9k_flush(sc->hw, ~0, true);
877
878 if (ath_chanctx_send_ps_frame(sc, true))
879 __ath9k_flush(sc->hw, BIT(IEEE80211_AC_VO), false);
880
881 send_ps = true;
882 spin_lock_bh(&sc->chan_lock);
883
884 if (sc->cur_chan != &sc->offchannel.chan) {
885 getrawmonotonic(&sc->cur_chan->tsf_ts);
886 sc->cur_chan->tsf_val = ath9k_hw_gettsf64(sc->sc_ah);
887 }
888 }
889 sc->cur_chan = sc->next_chan;
890 sc->cur_chan->stopped = false;
891 sc->next_chan = NULL;
892 sc->sched.offchannel_duration = 0;
893 if (sc->sched.state != ATH_CHANCTX_STATE_FORCE_ACTIVE)
894 sc->sched.state = ATH_CHANCTX_STATE_IDLE;
895
896 spin_unlock_bh(&sc->chan_lock);
897
898 if (sc->sc_ah->chip_fullsleep ||
899 memcmp(&sc->cur_chandef, &sc->cur_chan->chandef,
900 sizeof(sc->cur_chandef))) {
901 ath_set_channel(sc);
902 if (measure_time)
903 sc->sched.channel_switch_time =
904 ath9k_hw_get_tsf_offset(&ts, NULL);
905 }
906 if (send_ps)
907 ath_chanctx_send_ps_frame(sc, false);
908
909 ath_offchannel_channel_change(sc);
910 ath_chanctx_event(sc, NULL, ATH_CHANCTX_EVENT_SWITCH);
911}
912
Sujith Manoharan0e62f8b2014-08-23 13:29:08 +0530913static void ath_chanctx_work(struct work_struct *work)
914{
915 struct ath_softc *sc = container_of(work, struct ath_softc,
916 chanctx_work);
917 mutex_lock(&sc->mutex);
918 ath_chanctx_set_next(sc, false);
919 mutex_unlock(&sc->mutex);
920}
921
Sujith Manoharan705d0bf2014-08-23 13:29:06 +0530922void ath9k_init_channel_context(struct ath_softc *sc)
923{
924 INIT_WORK(&sc->chanctx_work, ath_chanctx_work);
925
926 setup_timer(&sc->offchannel.timer, ath_offchannel_timer,
927 (unsigned long)sc);
928 setup_timer(&sc->sched.timer, ath_chanctx_timer,
929 (unsigned long)sc);
930}
Sujith Manoharanc7dd40c2014-08-22 20:39:30 +0530931
Sujith Manoharanea22df22014-08-23 13:29:07 +0530932void ath9k_deinit_channel_context(struct ath_softc *sc)
933{
934 cancel_work_sync(&sc->chanctx_work);
935}
936
Sujith Manoharan499afac2014-08-22 20:39:31 +0530937bool ath9k_is_chanctx_enabled(void)
938{
939 return (ath9k_use_chanctx == 1);
940}
941
Sujith Manoharanc7dd40c2014-08-22 20:39:30 +0530942/*****************/
943/* P2P Powersave */
944/*****************/
945
946static void ath9k_update_p2p_ps_timer(struct ath_softc *sc, struct ath_vif *avp)
Sujith Manoharan2471adf2014-08-22 20:39:29 +0530947{
948 struct ath_hw *ah = sc->sc_ah;
949 s32 tsf, target_tsf;
950
951 if (!avp || !avp->noa.has_next_tsf)
952 return;
953
954 ath9k_hw_gen_timer_stop(ah, sc->p2p_ps_timer);
955
956 tsf = ath9k_hw_gettsf32(sc->sc_ah);
957
958 target_tsf = avp->noa.next_tsf;
959 if (!avp->noa.absent)
960 target_tsf -= ATH_P2P_PS_STOP_TIME;
961
962 if (target_tsf - tsf < ATH_P2P_PS_STOP_TIME)
963 target_tsf = tsf + ATH_P2P_PS_STOP_TIME;
964
965 ath9k_hw_gen_timer_start(ah, sc->p2p_ps_timer, (u32) target_tsf, 1000000);
966}
967
Sujith Manoharanc7dd40c2014-08-22 20:39:30 +0530968static void ath9k_update_p2p_ps(struct ath_softc *sc, struct ieee80211_vif *vif)
969{
970 struct ath_vif *avp = (void *)vif->drv_priv;
971 u32 tsf;
972
973 if (!sc->p2p_ps_timer)
974 return;
975
976 if (vif->type != NL80211_IFTYPE_STATION || !vif->p2p)
977 return;
978
979 sc->p2p_ps_vif = avp;
980 tsf = ath9k_hw_gettsf32(sc->sc_ah);
981 ieee80211_parse_p2p_noa(&vif->bss_conf.p2p_noa_attr, &avp->noa, tsf);
982 ath9k_update_p2p_ps_timer(sc, avp);
983}
984
Sujith Manoharan2471adf2014-08-22 20:39:29 +0530985void ath9k_p2p_ps_timer(void *priv)
986{
987 struct ath_softc *sc = priv;
988 struct ath_vif *avp = sc->p2p_ps_vif;
989 struct ieee80211_vif *vif;
990 struct ieee80211_sta *sta;
991 struct ath_node *an;
992 u32 tsf;
993
994 del_timer_sync(&sc->sched.timer);
995 ath9k_hw_gen_timer_stop(sc->sc_ah, sc->p2p_ps_timer);
996 ath_chanctx_event(sc, NULL, ATH_CHANCTX_EVENT_TSF_TIMER);
997
998 if (!avp || avp->chanctx != sc->cur_chan)
999 return;
1000
1001 tsf = ath9k_hw_gettsf32(sc->sc_ah);
1002 if (!avp->noa.absent)
1003 tsf += ATH_P2P_PS_STOP_TIME;
1004
1005 if (!avp->noa.has_next_tsf ||
1006 avp->noa.next_tsf - tsf > BIT(31))
1007 ieee80211_update_p2p_noa(&avp->noa, tsf);
1008
1009 ath9k_update_p2p_ps_timer(sc, avp);
1010
1011 rcu_read_lock();
1012
1013 vif = avp->vif;
1014 sta = ieee80211_find_sta(vif, vif->bss_conf.bssid);
1015 if (!sta)
1016 goto out;
1017
1018 an = (void *) sta->drv_priv;
1019 if (an->sleeping == !!avp->noa.absent)
1020 goto out;
1021
1022 an->sleeping = avp->noa.absent;
1023 if (an->sleeping)
1024 ath_tx_aggr_sleep(sta, sc, an);
1025 else
1026 ath_tx_aggr_wakeup(sc, an);
1027
1028out:
1029 rcu_read_unlock();
1030}
1031
Sujith Manoharanc7dd40c2014-08-22 20:39:30 +05301032void ath9k_p2p_bss_info_changed(struct ath_softc *sc,
1033 struct ieee80211_vif *vif)
1034{
1035 unsigned long flags;
1036
1037 spin_lock_bh(&sc->sc_pcu_lock);
1038 spin_lock_irqsave(&sc->sc_pm_lock, flags);
1039 if (!(sc->ps_flags & PS_BEACON_SYNC))
1040 ath9k_update_p2p_ps(sc, vif);
1041 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
1042 spin_unlock_bh(&sc->sc_pcu_lock);
1043}
1044
1045void ath9k_p2p_beacon_sync(struct ath_softc *sc)
1046{
1047 if (sc->p2p_ps_vif)
1048 ath9k_update_p2p_ps(sc, sc->p2p_ps_vif->vif);
1049}
1050
1051void ath9k_p2p_remove_vif(struct ath_softc *sc,
1052 struct ieee80211_vif *vif)
Sujith Manoharan2471adf2014-08-22 20:39:29 +05301053{
1054 struct ath_vif *avp = (void *)vif->drv_priv;
Sujith Manoharan2471adf2014-08-22 20:39:29 +05301055
Sujith Manoharanc7dd40c2014-08-22 20:39:30 +05301056 spin_lock_bh(&sc->sc_pcu_lock);
1057 if (avp == sc->p2p_ps_vif) {
1058 sc->p2p_ps_vif = NULL;
1059 ath9k_update_p2p_ps_timer(sc, NULL);
1060 }
1061 spin_unlock_bh(&sc->sc_pcu_lock);
Sujith Manoharan2471adf2014-08-22 20:39:29 +05301062}
Sujith Manoharanc7dd40c2014-08-22 20:39:30 +05301063
1064int ath9k_init_p2p(struct ath_softc *sc)
1065{
1066 sc->p2p_ps_timer = ath_gen_timer_alloc(sc->sc_ah, ath9k_p2p_ps_timer,
1067 NULL, sc, AR_FIRST_NDP_TIMER);
1068 if (!sc->p2p_ps_timer)
1069 return -ENOMEM;
1070
1071 return 0;
1072}
1073
1074void ath9k_deinit_p2p(struct ath_softc *sc)
1075{
1076 if (sc->p2p_ps_timer)
1077 ath_gen_timer_free(sc->sc_ah, sc->p2p_ps_timer);
1078}
1079
1080#endif /* CONFIG_ATH9K_CHANNEL_CONTEXT */