blob: 77bf0055e9530f35adb4390c9a3a7b1d49c40d44 [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 +0530121static bool
122ath_chanctx_send_vif_ps_frame(struct ath_softc *sc, struct ath_vif *avp,
123 bool powersave)
124{
125 struct ieee80211_vif *vif = avp->vif;
126 struct ieee80211_sta *sta = NULL;
127 struct ieee80211_hdr_3addr *nullfunc;
128 struct ath_tx_control txctl;
129 struct sk_buff *skb;
130 int band = sc->cur_chan->chandef.chan->band;
131
132 switch (vif->type) {
133 case NL80211_IFTYPE_STATION:
134 if (!vif->bss_conf.assoc)
135 return false;
136
137 skb = ieee80211_nullfunc_get(sc->hw, vif);
138 if (!skb)
139 return false;
140
141 nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
142 if (powersave)
143 nullfunc->frame_control |=
144 cpu_to_le16(IEEE80211_FCTL_PM);
145
146 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
147 if (!ieee80211_tx_prepare_skb(sc->hw, vif, skb, band, &sta)) {
148 dev_kfree_skb_any(skb);
149 return false;
150 }
151 break;
152 default:
153 return false;
154 }
155
156 memset(&txctl, 0, sizeof(txctl));
157 txctl.txq = sc->tx.txq_map[IEEE80211_AC_VO];
158 txctl.sta = sta;
159 txctl.force_channel = true;
160 if (ath_tx_start(sc->hw, skb, &txctl)) {
161 ieee80211_free_txskb(sc->hw, skb);
162 return false;
163 }
164
165 return true;
166}
167
168void ath_chanctx_check_active(struct ath_softc *sc, struct ath_chanctx *ctx)
169{
Felix Fietkau26f16c22014-06-11 16:18:00 +0530170 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Felix Fietkauc083ce92014-06-11 16:17:54 +0530171 struct ath_vif *avp;
172 bool active = false;
Felix Fietkau26f16c22014-06-11 16:18:00 +0530173 u8 n_active = 0;
Felix Fietkauc083ce92014-06-11 16:17:54 +0530174
175 if (!ctx)
176 return;
177
178 list_for_each_entry(avp, &ctx->vifs, list) {
179 struct ieee80211_vif *vif = avp->vif;
180
181 switch (vif->type) {
182 case NL80211_IFTYPE_P2P_CLIENT:
183 case NL80211_IFTYPE_STATION:
184 if (vif->bss_conf.assoc)
185 active = true;
186 break;
187 default:
188 active = true;
189 break;
190 }
191 }
192 ctx->active = active;
Felix Fietkau26f16c22014-06-11 16:18:00 +0530193
194 ath_for_each_chanctx(sc, ctx) {
195 if (!ctx->assigned || list_empty(&ctx->vifs))
196 continue;
197 n_active++;
198 }
199
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530200 if (n_active <= 1) {
Felix Fietkau26f16c22014-06-11 16:18:00 +0530201 clear_bit(ATH_OP_MULTI_CHANNEL, &common->op_flags);
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530202 return;
203 }
204 if (test_and_set_bit(ATH_OP_MULTI_CHANNEL, &common->op_flags))
205 return;
206 ath_chanctx_event(sc, NULL, ATH_CHANCTX_EVENT_ENABLE_MULTICHANNEL);
Felix Fietkauc083ce92014-06-11 16:17:54 +0530207}
208
209static bool
210ath_chanctx_send_ps_frame(struct ath_softc *sc, bool powersave)
211{
212 struct ath_vif *avp;
213 bool sent = false;
214
215 rcu_read_lock();
216 list_for_each_entry(avp, &sc->cur_chan->vifs, list) {
217 if (ath_chanctx_send_vif_ps_frame(sc, avp, powersave))
218 sent = true;
219 }
220 rcu_read_unlock();
221
222 return sent;
223}
224
Felix Fietkau748299f2014-06-11 16:18:04 +0530225static bool ath_chanctx_defer_switch(struct ath_softc *sc)
226{
227 if (sc->cur_chan == &sc->offchannel.chan)
228 return false;
229
230 switch (sc->sched.state) {
231 case ATH_CHANCTX_STATE_SWITCH:
232 return false;
233 case ATH_CHANCTX_STATE_IDLE:
234 if (!sc->cur_chan->switch_after_beacon)
235 return false;
236
237 sc->sched.state = ATH_CHANCTX_STATE_WAIT_FOR_BEACON;
238 break;
239 default:
240 break;
241 }
242
243 return true;
244}
245
Felix Fietkau6036c282014-06-11 16:18:09 +0530246static void ath_chanctx_set_next(struct ath_softc *sc, bool force)
Felix Fietkaubff11762014-06-11 16:17:52 +0530247{
Felix Fietkau748299f2014-06-11 16:18:04 +0530248 struct timespec ts;
249 bool measure_time = false;
Felix Fietkauc083ce92014-06-11 16:17:54 +0530250 bool send_ps = false;
Felix Fietkaubff11762014-06-11 16:17:52 +0530251
Felix Fietkaubff11762014-06-11 16:17:52 +0530252 spin_lock_bh(&sc->chan_lock);
253 if (!sc->next_chan) {
254 spin_unlock_bh(&sc->chan_lock);
Felix Fietkaubff11762014-06-11 16:17:52 +0530255 return;
256 }
257
Felix Fietkau6036c282014-06-11 16:18:09 +0530258 if (!force && ath_chanctx_defer_switch(sc)) {
Felix Fietkau748299f2014-06-11 16:18:04 +0530259 spin_unlock_bh(&sc->chan_lock);
Felix Fietkau748299f2014-06-11 16:18:04 +0530260 return;
261 }
262
Felix Fietkaubff11762014-06-11 16:17:52 +0530263 if (sc->cur_chan != sc->next_chan) {
264 sc->cur_chan->stopped = true;
265 spin_unlock_bh(&sc->chan_lock);
266
Felix Fietkau748299f2014-06-11 16:18:04 +0530267 if (sc->next_chan == &sc->offchannel.chan) {
268 getrawmonotonic(&ts);
269 measure_time = true;
270 }
Felix Fietkaubff11762014-06-11 16:17:52 +0530271 __ath9k_flush(sc->hw, ~0, true);
272
Felix Fietkauc083ce92014-06-11 16:17:54 +0530273 if (ath_chanctx_send_ps_frame(sc, true))
274 __ath9k_flush(sc->hw, BIT(IEEE80211_AC_VO), false);
275
276 send_ps = true;
Felix Fietkaubff11762014-06-11 16:17:52 +0530277 spin_lock_bh(&sc->chan_lock);
Felix Fietkau8d7e09d2014-06-11 16:18:01 +0530278
279 if (sc->cur_chan != &sc->offchannel.chan) {
280 getrawmonotonic(&sc->cur_chan->tsf_ts);
281 sc->cur_chan->tsf_val = ath9k_hw_gettsf64(sc->sc_ah);
282 }
Felix Fietkaubff11762014-06-11 16:17:52 +0530283 }
284 sc->cur_chan = sc->next_chan;
285 sc->cur_chan->stopped = false;
286 sc->next_chan = NULL;
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530287 sc->sched.offchannel_duration = 0;
Felix Fietkau6036c282014-06-11 16:18:09 +0530288 if (sc->sched.state != ATH_CHANCTX_STATE_FORCE_ACTIVE)
289 sc->sched.state = ATH_CHANCTX_STATE_IDLE;
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530290
Felix Fietkaubff11762014-06-11 16:17:52 +0530291 spin_unlock_bh(&sc->chan_lock);
292
293 if (sc->sc_ah->chip_fullsleep ||
294 memcmp(&sc->cur_chandef, &sc->cur_chan->chandef,
Felix Fietkau748299f2014-06-11 16:18:04 +0530295 sizeof(sc->cur_chandef))) {
Felix Fietkaubff11762014-06-11 16:17:52 +0530296 ath_set_channel(sc);
Felix Fietkau748299f2014-06-11 16:18:04 +0530297 if (measure_time)
298 sc->sched.channel_switch_time =
299 ath9k_hw_get_tsf_offset(&ts, NULL);
300 }
Felix Fietkauc083ce92014-06-11 16:17:54 +0530301 if (send_ps)
302 ath_chanctx_send_ps_frame(sc, false);
303
Felix Fietkau78b21942014-06-11 16:17:55 +0530304 ath_offchannel_channel_change(sc);
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530305 ath_chanctx_event(sc, NULL, ATH_CHANCTX_EVENT_SWITCH);
Felix Fietkau6036c282014-06-11 16:18:09 +0530306}
307
308void ath_chanctx_work(struct work_struct *work)
309{
310 struct ath_softc *sc = container_of(work, struct ath_softc,
311 chanctx_work);
312 mutex_lock(&sc->mutex);
313 ath_chanctx_set_next(sc, false);
Felix Fietkaubff11762014-06-11 16:17:52 +0530314 mutex_unlock(&sc->mutex);
315}
316
Felix Fietkaufbbcd142014-06-11 16:17:49 +0530317void ath_chanctx_init(struct ath_softc *sc)
318{
319 struct ath_chanctx *ctx;
320 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
321 struct ieee80211_supported_band *sband;
322 struct ieee80211_channel *chan;
Felix Fietkau04535312014-06-11 16:17:51 +0530323 int i, j;
Felix Fietkaufbbcd142014-06-11 16:17:49 +0530324
325 sband = &common->sbands[IEEE80211_BAND_2GHZ];
326 if (!sband->n_channels)
327 sband = &common->sbands[IEEE80211_BAND_5GHZ];
328
329 chan = &sband->channels[0];
330 for (i = 0; i < ATH9K_NUM_CHANCTX; i++) {
331 ctx = &sc->chanctx[i];
332 cfg80211_chandef_create(&ctx->chandef, chan, NL80211_CHAN_HT20);
333 INIT_LIST_HEAD(&ctx->vifs);
Felix Fietkaubc7e1be2014-06-11 16:17:50 +0530334 ctx->txpower = ATH_TXPOWER_MAX;
Felix Fietkau04535312014-06-11 16:17:51 +0530335 for (j = 0; j < ARRAY_SIZE(ctx->acq); j++)
336 INIT_LIST_HEAD(&ctx->acq[j]);
Felix Fietkaufbbcd142014-06-11 16:17:49 +0530337 }
Felix Fietkau78b21942014-06-11 16:17:55 +0530338 ctx = &sc->offchannel.chan;
339 cfg80211_chandef_create(&ctx->chandef, chan, NL80211_CHAN_HT20);
340 INIT_LIST_HEAD(&ctx->vifs);
341 ctx->txpower = ATH_TXPOWER_MAX;
342 for (j = 0; j < ARRAY_SIZE(ctx->acq); j++)
343 INIT_LIST_HEAD(&ctx->acq[j]);
344 sc->offchannel.chan.offchannel = true;
345
Felix Fietkaufbbcd142014-06-11 16:17:49 +0530346}
347
Felix Fietkau6036c282014-06-11 16:18:09 +0530348void ath9k_chanctx_force_active(struct ieee80211_hw *hw,
349 struct ieee80211_vif *vif)
350{
351 struct ath_softc *sc = hw->priv;
352 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
353 struct ath_vif *avp = (struct ath_vif *) vif->drv_priv;
354 bool changed = false;
355
356 if (!test_bit(ATH_OP_MULTI_CHANNEL, &common->op_flags))
357 return;
358
359 if (!avp->chanctx)
360 return;
361
362 mutex_lock(&sc->mutex);
363
364 spin_lock_bh(&sc->chan_lock);
365 if (sc->next_chan || (sc->cur_chan != avp->chanctx)) {
366 sc->next_chan = avp->chanctx;
367 changed = true;
368 }
369 sc->sched.state = ATH_CHANCTX_STATE_FORCE_ACTIVE;
370 spin_unlock_bh(&sc->chan_lock);
371
372 if (changed)
373 ath_chanctx_set_next(sc, true);
374
375 mutex_unlock(&sc->mutex);
376}
377
Felix Fietkaubff11762014-06-11 16:17:52 +0530378void ath_chanctx_switch(struct ath_softc *sc, struct ath_chanctx *ctx,
379 struct cfg80211_chan_def *chandef)
Felix Fietkaufbbcd142014-06-11 16:17:49 +0530380{
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530381 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Felix Fietkaufbbcd142014-06-11 16:17:49 +0530382
Felix Fietkaubff11762014-06-11 16:17:52 +0530383 spin_lock_bh(&sc->chan_lock);
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530384
385 if (test_bit(ATH_OP_MULTI_CHANNEL, &common->op_flags) &&
386 (sc->cur_chan != ctx) && (ctx == &sc->offchannel.chan)) {
387 sc->sched.offchannel_pending = true;
388 spin_unlock_bh(&sc->chan_lock);
389 return;
390 }
391
Felix Fietkaubff11762014-06-11 16:17:52 +0530392 sc->next_chan = ctx;
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530393 if (chandef) {
Felix Fietkaubff11762014-06-11 16:17:52 +0530394 ctx->chandef = *chandef;
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530395 ath_dbg(common, CHAN_CTX,
396 "Assigned next_chan to %d MHz\n", chandef->center_freq1);
397 }
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530398
399 if (sc->next_chan == &sc->offchannel.chan) {
400 sc->sched.offchannel_duration =
401 TU_TO_USEC(sc->offchannel.duration) +
402 sc->sched.channel_switch_time;
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530403
404 if (chandef) {
405 ath_dbg(common, CHAN_CTX,
406 "Offchannel duration for chan %d MHz : %u\n",
407 chandef->center_freq1,
408 sc->sched.offchannel_duration);
409 }
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530410 }
Felix Fietkaubff11762014-06-11 16:17:52 +0530411 spin_unlock_bh(&sc->chan_lock);
412 ieee80211_queue_work(sc->hw, &sc->chanctx_work);
413}
414
415void ath_chanctx_set_channel(struct ath_softc *sc, struct ath_chanctx *ctx,
416 struct cfg80211_chan_def *chandef)
417{
418 bool cur_chan;
419
420 spin_lock_bh(&sc->chan_lock);
421 if (chandef)
422 memcpy(&ctx->chandef, chandef, sizeof(*chandef));
423 cur_chan = sc->cur_chan == ctx;
424 spin_unlock_bh(&sc->chan_lock);
425
426 if (!cur_chan)
427 return;
428
429 ath_set_channel(sc);
Felix Fietkaufbbcd142014-06-11 16:17:49 +0530430}
Felix Fietkau78b21942014-06-11 16:17:55 +0530431
Rajkumar Manoharanc4dc0d02014-06-11 16:17:58 +0530432struct ath_chanctx *ath_chanctx_get_oper_chan(struct ath_softc *sc, bool active)
Felix Fietkau78b21942014-06-11 16:17:55 +0530433{
Rajkumar Manoharanc4dc0d02014-06-11 16:17:58 +0530434 struct ath_chanctx *ctx;
Felix Fietkau78b21942014-06-11 16:17:55 +0530435
Rajkumar Manoharanc4dc0d02014-06-11 16:17:58 +0530436 ath_for_each_chanctx(sc, ctx) {
437 if (!ctx->assigned || list_empty(&ctx->vifs))
438 continue;
439 if (active && !ctx->active)
440 continue;
441
Felix Fietkau8eab25102014-06-11 16:18:07 +0530442 if (ctx->switch_after_beacon)
443 return ctx;
Felix Fietkau78b21942014-06-11 16:17:55 +0530444 }
445
446 return &sc->chanctx[0];
447}
448
449void ath_chanctx_offchan_switch(struct ath_softc *sc,
450 struct ieee80211_channel *chan)
451{
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530452 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Felix Fietkau78b21942014-06-11 16:17:55 +0530453 struct cfg80211_chan_def chandef;
454
455 cfg80211_chandef_create(&chandef, chan, NL80211_CHAN_NO_HT);
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530456 ath_dbg(common, CHAN_CTX,
457 "Channel definition created: %d MHz\n", chandef.center_freq1);
Felix Fietkau78b21942014-06-11 16:17:55 +0530458
459 ath_chanctx_switch(sc, &sc->offchannel.chan, &chandef);
460}
Felix Fietkau748299f2014-06-11 16:18:04 +0530461
Felix Fietkau58b57372014-06-11 16:18:08 +0530462static struct ath_chanctx *
463ath_chanctx_get_next(struct ath_softc *sc, struct ath_chanctx *ctx)
464{
465 int idx = ctx - &sc->chanctx[0];
466
467 return &sc->chanctx[!idx];
468}
469
470static void ath_chanctx_adjust_tbtt_delta(struct ath_softc *sc)
471{
472 struct ath_chanctx *prev, *cur;
473 struct timespec ts;
474 u32 cur_tsf, prev_tsf, beacon_int;
475 s32 offset;
476
477 beacon_int = TU_TO_USEC(sc->cur_chan->beacon.beacon_interval);
478
479 cur = sc->cur_chan;
480 prev = ath_chanctx_get_next(sc, cur);
481
482 getrawmonotonic(&ts);
483 cur_tsf = (u32) cur->tsf_val +
484 ath9k_hw_get_tsf_offset(&cur->tsf_ts, &ts);
485
486 prev_tsf = prev->last_beacon - (u32) prev->tsf_val + cur_tsf;
487 prev_tsf -= ath9k_hw_get_tsf_offset(&prev->tsf_ts, &ts);
488
489 /* Adjust the TSF time of the AP chanctx to keep its beacons
490 * at half beacon interval offset relative to the STA chanctx.
491 */
492 offset = cur_tsf - prev_tsf;
493
494 /* Ignore stale data or spurious timestamps */
495 if (offset < 0 || offset > 3 * beacon_int)
496 return;
497
498 offset = beacon_int / 2 - (offset % beacon_int);
499 prev->tsf_val += offset;
500}
501
Felix Fietkau42eda112014-06-11 16:18:14 +0530502void ath_chanctx_timer(unsigned long data)
503{
504 struct ath_softc *sc = (struct ath_softc *) data;
505
506 ath_chanctx_event(sc, NULL, ATH_CHANCTX_EVENT_TSF_TIMER);
507}
508
509/* Configure the TSF based hardware timer for a channel switch.
510 * Also set up backup software timer, in case the gen timer fails.
511 * This could be caused by a hardware reset.
512 */
513static void ath_chanctx_setup_timer(struct ath_softc *sc, u32 tsf_time)
514{
515 struct ath_hw *ah = sc->sc_ah;
516
517 ath9k_hw_gen_timer_start(ah, sc->p2p_ps_timer, tsf_time, 1000000);
518 tsf_time -= ath9k_hw_gettsf32(ah);
519 tsf_time = msecs_to_jiffies(tsf_time / 1000) + 1;
520 mod_timer(&sc->sched.timer, tsf_time);
521}
522
Felix Fietkau748299f2014-06-11 16:18:04 +0530523void ath_chanctx_event(struct ath_softc *sc, struct ieee80211_vif *vif,
524 enum ath_chanctx_event ev)
525{
526 struct ath_hw *ah = sc->sc_ah;
Felix Fietkau58b57372014-06-11 16:18:08 +0530527 struct ath_common *common = ath9k_hw_common(ah);
Felix Fietkau74148632014-06-11 16:18:11 +0530528 struct ath_beacon_config *cur_conf;
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530529 struct ath_vif *avp = NULL;
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530530 struct ath_chanctx *ctx;
Felix Fietkau748299f2014-06-11 16:18:04 +0530531 u32 tsf_time;
Felix Fietkauec70abe2014-06-11 16:18:12 +0530532 u32 beacon_int;
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530533 bool noa_changed = false;
534
535 if (vif)
536 avp = (struct ath_vif *) vif->drv_priv;
Felix Fietkau748299f2014-06-11 16:18:04 +0530537
538 spin_lock_bh(&sc->chan_lock);
539
540 switch (ev) {
541 case ATH_CHANCTX_EVENT_BEACON_PREPARE:
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530542 if (avp->offchannel_duration)
543 avp->offchannel_duration = 0;
544
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530545 if (avp->chanctx != sc->cur_chan)
546 break;
547
548 if (sc->sched.offchannel_pending) {
549 sc->sched.offchannel_pending = false;
550 sc->next_chan = &sc->offchannel.chan;
551 sc->sched.state = ATH_CHANCTX_STATE_WAIT_FOR_BEACON;
552 }
553
554 ctx = ath_chanctx_get_next(sc, sc->cur_chan);
555 if (ctx->active && sc->sched.state == ATH_CHANCTX_STATE_IDLE) {
556 sc->next_chan = ctx;
557 sc->sched.state = ATH_CHANCTX_STATE_WAIT_FOR_BEACON;
558 }
559
560 /* if the timer missed its window, use the next interval */
561 if (sc->sched.state == ATH_CHANCTX_STATE_WAIT_FOR_TIMER)
562 sc->sched.state = ATH_CHANCTX_STATE_WAIT_FOR_BEACON;
563
Felix Fietkau748299f2014-06-11 16:18:04 +0530564 if (sc->sched.state != ATH_CHANCTX_STATE_WAIT_FOR_BEACON)
565 break;
566
567 sc->sched.beacon_pending = true;
568 sc->sched.next_tbtt = REG_READ(ah, AR_NEXT_TBTT_TIMER);
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530569
Felix Fietkau74148632014-06-11 16:18:11 +0530570 cur_conf = &sc->cur_chan->beacon;
Felix Fietkauec70abe2014-06-11 16:18:12 +0530571 beacon_int = TU_TO_USEC(cur_conf->beacon_interval);
572
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530573 /* defer channel switch by a quarter beacon interval */
Felix Fietkauec70abe2014-06-11 16:18:12 +0530574 tsf_time = sc->sched.next_tbtt + beacon_int / 4;
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530575 sc->sched.switch_start_time = tsf_time;
Felix Fietkau58b57372014-06-11 16:18:08 +0530576 sc->cur_chan->last_beacon = sc->sched.next_tbtt;
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530577
Felix Fietkau74148632014-06-11 16:18:11 +0530578 /* Prevent wrap-around issues */
579 if (avp->periodic_noa_duration &&
580 tsf_time - avp->periodic_noa_start > BIT(30))
581 avp->periodic_noa_duration = 0;
582
583 if (ctx->active && !avp->periodic_noa_duration) {
584 avp->periodic_noa_start = tsf_time;
585 avp->periodic_noa_duration =
586 TU_TO_USEC(cur_conf->beacon_interval) / 2 -
587 sc->sched.channel_switch_time;
588 noa_changed = true;
589 } else if (!ctx->active && avp->periodic_noa_duration) {
590 avp->periodic_noa_duration = 0;
591 noa_changed = true;
592 }
593
Felix Fietkauec70abe2014-06-11 16:18:12 +0530594 /* If at least two consecutive beacons were missed on the STA
595 * chanctx, stay on the STA channel for one extra beacon period,
596 * to resync the timer properly.
597 */
598 if (ctx->active && sc->sched.beacon_miss >= 2)
599 sc->sched.offchannel_duration = 3 * beacon_int / 2;
600
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530601 if (sc->sched.offchannel_duration) {
602 noa_changed = true;
603 avp->offchannel_start = tsf_time;
604 avp->offchannel_duration =
605 sc->sched.offchannel_duration;
606 }
607
608 if (noa_changed)
609 avp->noa_index++;
Felix Fietkau748299f2014-06-11 16:18:04 +0530610 break;
611 case ATH_CHANCTX_EVENT_BEACON_SENT:
612 if (!sc->sched.beacon_pending)
613 break;
614
615 sc->sched.beacon_pending = false;
616 if (sc->sched.state != ATH_CHANCTX_STATE_WAIT_FOR_BEACON)
617 break;
618
Felix Fietkau748299f2014-06-11 16:18:04 +0530619 sc->sched.state = ATH_CHANCTX_STATE_WAIT_FOR_TIMER;
Felix Fietkau42eda112014-06-11 16:18:14 +0530620 ath_chanctx_setup_timer(sc, sc->sched.switch_start_time);
Felix Fietkau748299f2014-06-11 16:18:04 +0530621 break;
622 case ATH_CHANCTX_EVENT_TSF_TIMER:
623 if (sc->sched.state != ATH_CHANCTX_STATE_WAIT_FOR_TIMER)
624 break;
625
Felix Fietkauec70abe2014-06-11 16:18:12 +0530626 if (!sc->cur_chan->switch_after_beacon &&
627 sc->sched.beacon_pending)
628 sc->sched.beacon_miss++;
629
Felix Fietkau748299f2014-06-11 16:18:04 +0530630 sc->sched.state = ATH_CHANCTX_STATE_SWITCH;
631 ieee80211_queue_work(sc->hw, &sc->chanctx_work);
632 break;
Felix Fietkau58b57372014-06-11 16:18:08 +0530633 case ATH_CHANCTX_EVENT_BEACON_RECEIVED:
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530634 if (!test_bit(ATH_OP_MULTI_CHANNEL, &common->op_flags) ||
635 sc->cur_chan == &sc->offchannel.chan)
Felix Fietkau58b57372014-06-11 16:18:08 +0530636 break;
637
638 ath_chanctx_adjust_tbtt_delta(sc);
Felix Fietkauec70abe2014-06-11 16:18:12 +0530639 sc->sched.beacon_pending = false;
640 sc->sched.beacon_miss = 0;
Felix Fietkaua899b672014-06-11 16:18:13 +0530641
642 /* TSF time might have been updated by the incoming beacon,
643 * need update the channel switch timer to reflect the change.
644 */
645 tsf_time = sc->sched.switch_start_time;
646 tsf_time -= (u32) sc->cur_chan->tsf_val +
647 ath9k_hw_get_tsf_offset(&sc->cur_chan->tsf_ts, NULL);
648 tsf_time += ath9k_hw_gettsf32(ah);
649
Felix Fietkau42eda112014-06-11 16:18:14 +0530650
651 ath_chanctx_setup_timer(sc, tsf_time);
Felix Fietkau58b57372014-06-11 16:18:08 +0530652 break;
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530653 case ATH_CHANCTX_EVENT_ASSOC:
654 if (sc->sched.state != ATH_CHANCTX_STATE_FORCE_ACTIVE ||
655 avp->chanctx != sc->cur_chan)
656 break;
657
658 sc->sched.state = ATH_CHANCTX_STATE_IDLE;
659 /* fall through */
660 case ATH_CHANCTX_EVENT_SWITCH:
661 if (!test_bit(ATH_OP_MULTI_CHANNEL, &common->op_flags) ||
662 sc->sched.state == ATH_CHANCTX_STATE_FORCE_ACTIVE ||
663 sc->cur_chan->switch_after_beacon ||
664 sc->cur_chan == &sc->offchannel.chan)
665 break;
666
667 /* If this is a station chanctx, stay active for a half
668 * beacon period (minus channel switch time)
669 */
670 sc->next_chan = ath_chanctx_get_next(sc, sc->cur_chan);
Felix Fietkau74148632014-06-11 16:18:11 +0530671 cur_conf = &sc->cur_chan->beacon;
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530672
673 sc->sched.state = ATH_CHANCTX_STATE_WAIT_FOR_TIMER;
Felix Fietkauec70abe2014-06-11 16:18:12 +0530674
675 tsf_time = TU_TO_USEC(cur_conf->beacon_interval) / 2;
676 if (sc->sched.beacon_miss >= 2) {
677 sc->sched.beacon_miss = 0;
678 tsf_time *= 3;
679 }
680
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530681 tsf_time -= sc->sched.channel_switch_time;
Felix Fietkauec70abe2014-06-11 16:18:12 +0530682 tsf_time += ath9k_hw_gettsf32(sc->sc_ah);
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530683 sc->sched.switch_start_time = tsf_time;
684
Felix Fietkau42eda112014-06-11 16:18:14 +0530685 ath_chanctx_setup_timer(sc, tsf_time);
Felix Fietkauec70abe2014-06-11 16:18:12 +0530686 sc->sched.beacon_pending = true;
Felix Fietkau73fa2f22014-06-11 16:18:10 +0530687 break;
688 case ATH_CHANCTX_EVENT_ENABLE_MULTICHANNEL:
689 if (sc->cur_chan == &sc->offchannel.chan ||
690 sc->cur_chan->switch_after_beacon)
691 break;
692
693 sc->next_chan = ath_chanctx_get_next(sc, sc->cur_chan);
694 ieee80211_queue_work(sc->hw, &sc->chanctx_work);
695 break;
696 case ATH_CHANCTX_EVENT_UNASSIGN:
697 if (sc->cur_chan->assigned) {
698 if (sc->next_chan && !sc->next_chan->assigned &&
699 sc->next_chan != &sc->offchannel.chan)
700 sc->sched.state = ATH_CHANCTX_STATE_IDLE;
701 break;
702 }
703
704 ctx = ath_chanctx_get_next(sc, sc->cur_chan);
705 sc->sched.state = ATH_CHANCTX_STATE_IDLE;
706 if (!ctx->assigned)
707 break;
708
709 sc->next_chan = ctx;
710 ieee80211_queue_work(sc->hw, &sc->chanctx_work);
711 break;
Felix Fietkau748299f2014-06-11 16:18:04 +0530712 }
713
714 spin_unlock_bh(&sc->chan_lock);
715}
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530716
717static int ath_scan_channel_duration(struct ath_softc *sc,
718 struct ieee80211_channel *chan)
719{
720 struct cfg80211_scan_request *req = sc->offchannel.scan_req;
721
722 if (!req->n_ssids || (chan->flags & IEEE80211_CHAN_NO_IR))
723 return (HZ / 9); /* ~110 ms */
724
725 return (HZ / 16); /* ~60 ms */
726}
727
728static void
729ath_scan_next_channel(struct ath_softc *sc)
730{
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530731 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530732 struct cfg80211_scan_request *req = sc->offchannel.scan_req;
733 struct ieee80211_channel *chan;
734
735 if (sc->offchannel.scan_idx >= req->n_channels) {
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530736 ath_dbg(common, CHAN_CTX,
737 "Moving to ATH_OFFCHANNEL_IDLE state, scan_idx: %d, n_channels: %d\n",
738 sc->offchannel.scan_idx,
739 req->n_channels);
740
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530741 sc->offchannel.state = ATH_OFFCHANNEL_IDLE;
742 ath_chanctx_switch(sc, ath_chanctx_get_oper_chan(sc, false),
743 NULL);
744 return;
745 }
746
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530747 ath_dbg(common, CHAN_CTX,
748 "Moving to ATH_OFFCHANNEL_PROBE_SEND state, scan_idx: %d\n",
749 sc->offchannel.scan_idx);
750
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530751 chan = req->channels[sc->offchannel.scan_idx++];
752 sc->offchannel.duration = ath_scan_channel_duration(sc, chan);
753 sc->offchannel.state = ATH_OFFCHANNEL_PROBE_SEND;
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530754
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530755 ath_chanctx_offchan_switch(sc, chan);
756}
757
758void ath_offchannel_next(struct ath_softc *sc)
759{
760 struct ieee80211_vif *vif;
761
762 if (sc->offchannel.scan_req) {
763 vif = sc->offchannel.scan_vif;
764 sc->offchannel.chan.txpower = vif->bss_conf.txpower;
765 ath_scan_next_channel(sc);
766 } else if (sc->offchannel.roc_vif) {
767 vif = sc->offchannel.roc_vif;
768 sc->offchannel.chan.txpower = vif->bss_conf.txpower;
769 sc->offchannel.duration = sc->offchannel.roc_duration;
770 sc->offchannel.state = ATH_OFFCHANNEL_ROC_START;
771 ath_chanctx_offchan_switch(sc, sc->offchannel.roc_chan);
772 } else {
773 ath_chanctx_switch(sc, ath_chanctx_get_oper_chan(sc, false),
774 NULL);
775 sc->offchannel.state = ATH_OFFCHANNEL_IDLE;
776 if (sc->ps_idle)
777 ath_cancel_work(sc);
778 }
779}
780
781void ath_roc_complete(struct ath_softc *sc, bool abort)
782{
783 sc->offchannel.roc_vif = NULL;
784 sc->offchannel.roc_chan = NULL;
785 if (!abort)
786 ieee80211_remain_on_channel_expired(sc->hw);
787 ath_offchannel_next(sc);
788 ath9k_ps_restore(sc);
789}
790
791void ath_scan_complete(struct ath_softc *sc, bool abort)
792{
793 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
794
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530795 if (abort)
796 ath_dbg(common, CHAN_CTX, "HW scan aborted\n");
797 else
798 ath_dbg(common, CHAN_CTX, "HW scan complete\n");
799
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530800 sc->offchannel.scan_req = NULL;
801 sc->offchannel.scan_vif = NULL;
802 sc->offchannel.state = ATH_OFFCHANNEL_IDLE;
803 ieee80211_scan_completed(sc->hw, abort);
804 clear_bit(ATH_OP_SCANNING, &common->op_flags);
805 ath_offchannel_next(sc);
806 ath9k_ps_restore(sc);
807}
808
809static void ath_scan_send_probe(struct ath_softc *sc,
810 struct cfg80211_ssid *ssid)
811{
812 struct cfg80211_scan_request *req = sc->offchannel.scan_req;
813 struct ieee80211_vif *vif = sc->offchannel.scan_vif;
814 struct ath_tx_control txctl = {};
815 struct sk_buff *skb;
816 struct ieee80211_tx_info *info;
817 int band = sc->offchannel.chan.chandef.chan->band;
818
819 skb = ieee80211_probereq_get(sc->hw, vif,
820 ssid->ssid, ssid->ssid_len, req->ie_len);
821 if (!skb)
822 return;
823
824 info = IEEE80211_SKB_CB(skb);
825 if (req->no_cck)
826 info->flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
827
828 if (req->ie_len)
829 memcpy(skb_put(skb, req->ie_len), req->ie, req->ie_len);
830
831 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
832
833 if (!ieee80211_tx_prepare_skb(sc->hw, vif, skb, band, NULL))
834 goto error;
835
836 txctl.txq = sc->tx.txq_map[IEEE80211_AC_VO];
837 txctl.force_channel = true;
838 if (ath_tx_start(sc->hw, skb, &txctl))
839 goto error;
840
841 return;
842
843error:
844 ieee80211_free_txskb(sc->hw, skb);
845}
846
847static void ath_scan_channel_start(struct ath_softc *sc)
848{
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530849 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530850 struct cfg80211_scan_request *req = sc->offchannel.scan_req;
851 int i;
852
853 if (!(sc->cur_chan->chandef.chan->flags & IEEE80211_CHAN_NO_IR) &&
854 req->n_ssids) {
855 for (i = 0; i < req->n_ssids; i++)
856 ath_scan_send_probe(sc, &req->ssids[i]);
857
858 }
859
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530860 ath_dbg(common, CHAN_CTX,
861 "Moving to ATH_OFFCHANNEL_PROBE_WAIT state\n");
862
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530863 sc->offchannel.state = ATH_OFFCHANNEL_PROBE_WAIT;
864 mod_timer(&sc->offchannel.timer, jiffies + sc->offchannel.duration);
865}
866
867void ath_offchannel_channel_change(struct ath_softc *sc)
868{
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530869 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
870
871 ath_dbg(common, CHAN_CTX, "%s: state: %s\n",
872 __func__, offchannel_state_string(sc->offchannel.state));
873
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530874 switch (sc->offchannel.state) {
875 case ATH_OFFCHANNEL_PROBE_SEND:
876 if (!sc->offchannel.scan_req)
877 return;
878
879 if (sc->cur_chan->chandef.chan !=
880 sc->offchannel.chan.chandef.chan)
881 return;
882
883 ath_scan_channel_start(sc);
884 break;
885 case ATH_OFFCHANNEL_IDLE:
886 if (!sc->offchannel.scan_req)
887 return;
888
889 ath_scan_complete(sc, false);
890 break;
891 case ATH_OFFCHANNEL_ROC_START:
892 if (sc->cur_chan != &sc->offchannel.chan)
893 break;
894
895 sc->offchannel.state = ATH_OFFCHANNEL_ROC_WAIT;
896 mod_timer(&sc->offchannel.timer, jiffies +
897 msecs_to_jiffies(sc->offchannel.duration));
898 ieee80211_ready_on_channel(sc->hw);
899 break;
900 case ATH_OFFCHANNEL_ROC_DONE:
901 ath_roc_complete(sc, false);
902 break;
903 default:
904 break;
905 }
906}
907
908void ath_offchannel_timer(unsigned long data)
909{
910 struct ath_softc *sc = (struct ath_softc *)data;
911 struct ath_chanctx *ctx;
Sujith Manoharanbc81d432014-08-22 20:39:27 +0530912 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
913
914 ath_dbg(common, CHAN_CTX, "%s: state: %s\n",
915 __func__, offchannel_state_string(sc->offchannel.state));
Sujith Manoharandfcbb3e2014-08-22 20:39:26 +0530916
917 switch (sc->offchannel.state) {
918 case ATH_OFFCHANNEL_PROBE_WAIT:
919 if (!sc->offchannel.scan_req)
920 return;
921
922 /* get first active channel context */
923 ctx = ath_chanctx_get_oper_chan(sc, true);
924 if (ctx->active) {
925 sc->offchannel.state = ATH_OFFCHANNEL_SUSPEND;
926 ath_chanctx_switch(sc, ctx, NULL);
927 mod_timer(&sc->offchannel.timer, jiffies + HZ / 10);
928 break;
929 }
930 /* fall through */
931 case ATH_OFFCHANNEL_SUSPEND:
932 if (!sc->offchannel.scan_req)
933 return;
934
935 ath_scan_next_channel(sc);
936 break;
937 case ATH_OFFCHANNEL_ROC_START:
938 case ATH_OFFCHANNEL_ROC_WAIT:
939 ctx = ath_chanctx_get_oper_chan(sc, false);
940 sc->offchannel.state = ATH_OFFCHANNEL_ROC_DONE;
941 ath_chanctx_switch(sc, ctx, NULL);
942 break;
943 default:
944 break;
945 }
946}
Sujith Manoharan2471adf2014-08-22 20:39:29 +0530947
948void ath9k_update_p2p_ps_timer(struct ath_softc *sc, struct ath_vif *avp)
949{
950 struct ath_hw *ah = sc->sc_ah;
951 s32 tsf, target_tsf;
952
953 if (!avp || !avp->noa.has_next_tsf)
954 return;
955
956 ath9k_hw_gen_timer_stop(ah, sc->p2p_ps_timer);
957
958 tsf = ath9k_hw_gettsf32(sc->sc_ah);
959
960 target_tsf = avp->noa.next_tsf;
961 if (!avp->noa.absent)
962 target_tsf -= ATH_P2P_PS_STOP_TIME;
963
964 if (target_tsf - tsf < ATH_P2P_PS_STOP_TIME)
965 target_tsf = tsf + ATH_P2P_PS_STOP_TIME;
966
967 ath9k_hw_gen_timer_start(ah, sc->p2p_ps_timer, (u32) target_tsf, 1000000);
968}
969
970void ath9k_p2p_ps_timer(void *priv)
971{
972 struct ath_softc *sc = priv;
973 struct ath_vif *avp = sc->p2p_ps_vif;
974 struct ieee80211_vif *vif;
975 struct ieee80211_sta *sta;
976 struct ath_node *an;
977 u32 tsf;
978
979 del_timer_sync(&sc->sched.timer);
980 ath9k_hw_gen_timer_stop(sc->sc_ah, sc->p2p_ps_timer);
981 ath_chanctx_event(sc, NULL, ATH_CHANCTX_EVENT_TSF_TIMER);
982
983 if (!avp || avp->chanctx != sc->cur_chan)
984 return;
985
986 tsf = ath9k_hw_gettsf32(sc->sc_ah);
987 if (!avp->noa.absent)
988 tsf += ATH_P2P_PS_STOP_TIME;
989
990 if (!avp->noa.has_next_tsf ||
991 avp->noa.next_tsf - tsf > BIT(31))
992 ieee80211_update_p2p_noa(&avp->noa, tsf);
993
994 ath9k_update_p2p_ps_timer(sc, avp);
995
996 rcu_read_lock();
997
998 vif = avp->vif;
999 sta = ieee80211_find_sta(vif, vif->bss_conf.bssid);
1000 if (!sta)
1001 goto out;
1002
1003 an = (void *) sta->drv_priv;
1004 if (an->sleeping == !!avp->noa.absent)
1005 goto out;
1006
1007 an->sleeping = avp->noa.absent;
1008 if (an->sleeping)
1009 ath_tx_aggr_sleep(sta, sc, an);
1010 else
1011 ath_tx_aggr_wakeup(sc, an);
1012
1013out:
1014 rcu_read_unlock();
1015}
1016
1017void ath9k_update_p2p_ps(struct ath_softc *sc, struct ieee80211_vif *vif)
1018{
1019 struct ath_vif *avp = (void *)vif->drv_priv;
1020 u32 tsf;
1021
1022 if (!sc->p2p_ps_timer)
1023 return;
1024
1025 if (vif->type != NL80211_IFTYPE_STATION || !vif->p2p)
1026 return;
1027
1028 sc->p2p_ps_vif = avp;
1029 tsf = ath9k_hw_gettsf32(sc->sc_ah);
1030 ieee80211_parse_p2p_noa(&vif->bss_conf.p2p_noa_attr, &avp->noa, tsf);
1031 ath9k_update_p2p_ps_timer(sc, avp);
1032}