2 * Copyright (c) 2014 Qualcomm Atheros, Inc.
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.
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.
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.
23 static int ath_set_channel(struct ath_softc
*sc
)
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
;
35 if (test_bit(ATH_OP_INVALID
, &common
->op_flags
))
39 old_pos
= ah
->curchan
- &ah
->channels
[0];
41 ath_dbg(common
, CONFIG
, "Set channel: %d MHz width: %d\n",
42 chan
->center_freq
, chandef
->width
);
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
);
49 ath9k_cmn_get_channel(hw
, ah
, chandef
);
51 /* If the operating channel changes, change the survey in-use flags
53 * Reset the survey data for the new channel, unless we're switching
54 * back to the operating channel from an off-channel operation.
56 if (!sc
->cur_chan
->offchannel
&& sc
->cur_survey
!= &sc
->survey
[pos
]) {
58 sc
->cur_survey
->filled
&= ~SURVEY_INFO_IN_USE
;
60 sc
->cur_survey
= &sc
->survey
[pos
];
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
));
68 hchan
= &sc
->sc_ah
->channels
[pos
];
69 r
= ath_reset(sc
, hchan
);
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.
78 ath_update_survey_nf(sc
, old_pos
);
80 /* Enable radar pulse detection if on a DFS channel. Spectral
81 * scanning and radar detection can not be used concurrently.
83 if (hw
->conf
.radar_enabled
) {
86 rxfilter
= ath9k_hw_getrxfilter(ah
);
87 rxfilter
|= ATH9K_RX_FILTER_PHYRADAR
|
88 ATH9K_RX_FILTER_PHYERR
;
89 ath9k_hw_setrxfilter(ah
, rxfilter
);
90 ath_dbg(common
, DFS
, "DFS enabled at freq %d\n",
93 /* perform spectral scan if requested. */
94 if (test_bit(ATH_OP_SCANNING
, &common
->op_flags
) &&
95 sc
->spectral_mode
== SPECTRAL_CHANSCAN
)
96 ath9k_spectral_scan_trigger(hw
);
102 void ath_chanctx_init(struct ath_softc
*sc
)
104 struct ath_chanctx
*ctx
;
105 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
106 struct ieee80211_supported_band
*sband
;
107 struct ieee80211_channel
*chan
;
110 sband
= &common
->sbands
[IEEE80211_BAND_2GHZ
];
111 if (!sband
->n_channels
)
112 sband
= &common
->sbands
[IEEE80211_BAND_5GHZ
];
114 chan
= &sband
->channels
[0];
115 for (i
= 0; i
< ATH9K_NUM_CHANCTX
; i
++) {
116 ctx
= &sc
->chanctx
[i
];
117 cfg80211_chandef_create(&ctx
->chandef
, chan
, NL80211_CHAN_HT20
);
118 INIT_LIST_HEAD(&ctx
->vifs
);
119 ctx
->txpower
= ATH_TXPOWER_MAX
;
120 ctx
->flush_timeout
= HZ
/ 5; /* 200ms */
121 for (j
= 0; j
< ARRAY_SIZE(ctx
->acq
); j
++)
122 INIT_LIST_HEAD(&ctx
->acq
[j
]);
126 void ath_chanctx_set_channel(struct ath_softc
*sc
, struct ath_chanctx
*ctx
,
127 struct cfg80211_chan_def
*chandef
)
129 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
132 spin_lock_bh(&sc
->chan_lock
);
134 memcpy(&ctx
->chandef
, chandef
, sizeof(*chandef
));
135 cur_chan
= sc
->cur_chan
== ctx
;
136 spin_unlock_bh(&sc
->chan_lock
);
139 ath_dbg(common
, CHAN_CTX
,
140 "Current context differs from the new context\n");
147 #ifdef CONFIG_ATH9K_CHANNEL_CONTEXT
153 struct ath_chanctx
* ath_is_go_chanctx_present(struct ath_softc
*sc
)
155 struct ath_chanctx
*ctx
;
157 struct ieee80211_vif
*vif
;
159 spin_lock_bh(&sc
->chan_lock
);
161 ath_for_each_chanctx(sc
, ctx
) {
165 list_for_each_entry(avp
, &ctx
->vifs
, list
) {
168 if (ieee80211_vif_type_p2p(vif
) == NL80211_IFTYPE_P2P_GO
) {
169 spin_unlock_bh(&sc
->chan_lock
);
175 spin_unlock_bh(&sc
->chan_lock
);
179 /**********************************************************/
180 /* Functions to handle the channel context state machine. */
181 /**********************************************************/
183 static const char *offchannel_state_string(enum ath_offchannel_state state
)
186 case_rtn_string(ATH_OFFCHANNEL_IDLE
);
187 case_rtn_string(ATH_OFFCHANNEL_PROBE_SEND
);
188 case_rtn_string(ATH_OFFCHANNEL_PROBE_WAIT
);
189 case_rtn_string(ATH_OFFCHANNEL_SUSPEND
);
190 case_rtn_string(ATH_OFFCHANNEL_ROC_START
);
191 case_rtn_string(ATH_OFFCHANNEL_ROC_WAIT
);
192 case_rtn_string(ATH_OFFCHANNEL_ROC_DONE
);
198 static const char *chanctx_event_string(enum ath_chanctx_event ev
)
201 case_rtn_string(ATH_CHANCTX_EVENT_BEACON_PREPARE
);
202 case_rtn_string(ATH_CHANCTX_EVENT_BEACON_SENT
);
203 case_rtn_string(ATH_CHANCTX_EVENT_TSF_TIMER
);
204 case_rtn_string(ATH_CHANCTX_EVENT_BEACON_RECEIVED
);
205 case_rtn_string(ATH_CHANCTX_EVENT_AUTHORIZED
);
206 case_rtn_string(ATH_CHANCTX_EVENT_SWITCH
);
207 case_rtn_string(ATH_CHANCTX_EVENT_ASSIGN
);
208 case_rtn_string(ATH_CHANCTX_EVENT_UNASSIGN
);
209 case_rtn_string(ATH_CHANCTX_EVENT_CHANGE
);
210 case_rtn_string(ATH_CHANCTX_EVENT_ENABLE_MULTICHANNEL
);
216 static const char *chanctx_state_string(enum ath_chanctx_state state
)
219 case_rtn_string(ATH_CHANCTX_STATE_IDLE
);
220 case_rtn_string(ATH_CHANCTX_STATE_WAIT_FOR_BEACON
);
221 case_rtn_string(ATH_CHANCTX_STATE_WAIT_FOR_TIMER
);
222 case_rtn_string(ATH_CHANCTX_STATE_SWITCH
);
223 case_rtn_string(ATH_CHANCTX_STATE_FORCE_ACTIVE
);
229 void ath_chanctx_check_active(struct ath_softc
*sc
, struct ath_chanctx
*ctx
)
231 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
232 struct ath_chanctx
*ictx
;
240 if (ctx
== &sc
->offchannel
.chan
) {
241 spin_lock_bh(&sc
->chan_lock
);
243 if (likely(sc
->sched
.channel_switch_time
))
245 usecs_to_jiffies(sc
->sched
.channel_switch_time
);
248 msecs_to_jiffies(10);
250 spin_unlock_bh(&sc
->chan_lock
);
253 * There is no need to iterate over the
254 * active/assigned channel contexts if
255 * the current context is offchannel.
262 list_for_each_entry(avp
, &ctx
->vifs
, list
) {
263 struct ieee80211_vif
*vif
= avp
->vif
;
266 case NL80211_IFTYPE_P2P_CLIENT
:
267 case NL80211_IFTYPE_STATION
:
276 ctx
->active
= active
;
278 ath_for_each_chanctx(sc
, ctx
) {
279 if (!ctx
->assigned
|| list_empty(&ctx
->vifs
))
284 spin_lock_bh(&sc
->chan_lock
);
287 ictx
->flush_timeout
= HZ
/ 5;
288 clear_bit(ATH_OP_MULTI_CHANNEL
, &common
->op_flags
);
289 spin_unlock_bh(&sc
->chan_lock
);
293 ictx
->flush_timeout
= usecs_to_jiffies(sc
->sched
.channel_switch_time
);
295 if (test_and_set_bit(ATH_OP_MULTI_CHANNEL
, &common
->op_flags
)) {
296 spin_unlock_bh(&sc
->chan_lock
);
300 spin_unlock_bh(&sc
->chan_lock
);
302 if (ath9k_is_chanctx_enabled()) {
303 ath_chanctx_event(sc
, NULL
,
304 ATH_CHANCTX_EVENT_ENABLE_MULTICHANNEL
);
308 static struct ath_chanctx
*
309 ath_chanctx_get_next(struct ath_softc
*sc
, struct ath_chanctx
*ctx
)
311 int idx
= ctx
- &sc
->chanctx
[0];
313 return &sc
->chanctx
[!idx
];
316 static void ath_chanctx_adjust_tbtt_delta(struct ath_softc
*sc
)
318 struct ath_chanctx
*prev
, *cur
;
320 u32 cur_tsf
, prev_tsf
, beacon_int
;
323 beacon_int
= TU_TO_USEC(sc
->cur_chan
->beacon
.beacon_interval
);
326 prev
= ath_chanctx_get_next(sc
, cur
);
328 if (!prev
->switch_after_beacon
)
331 getrawmonotonic(&ts
);
332 cur_tsf
= (u32
) cur
->tsf_val
+
333 ath9k_hw_get_tsf_offset(&cur
->tsf_ts
, &ts
);
335 prev_tsf
= prev
->last_beacon
- (u32
) prev
->tsf_val
+ cur_tsf
;
336 prev_tsf
-= ath9k_hw_get_tsf_offset(&prev
->tsf_ts
, &ts
);
338 /* Adjust the TSF time of the AP chanctx to keep its beacons
339 * at half beacon interval offset relative to the STA chanctx.
341 offset
= cur_tsf
- prev_tsf
;
343 /* Ignore stale data or spurious timestamps */
344 if (offset
< 0 || offset
> 3 * beacon_int
)
347 offset
= beacon_int
/ 2 - (offset
% beacon_int
);
348 prev
->tsf_val
+= offset
;
351 /* Configure the TSF based hardware timer for a channel switch.
352 * Also set up backup software timer, in case the gen timer fails.
353 * This could be caused by a hardware reset.
355 static void ath_chanctx_setup_timer(struct ath_softc
*sc
, u32 tsf_time
)
357 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
358 struct ath_hw
*ah
= sc
->sc_ah
;
360 ath9k_hw_gen_timer_start(ah
, sc
->p2p_ps_timer
, tsf_time
, 1000000);
361 tsf_time
-= ath9k_hw_gettsf32(ah
);
362 tsf_time
= msecs_to_jiffies(tsf_time
/ 1000) + 1;
363 mod_timer(&sc
->sched
.timer
, jiffies
+ tsf_time
);
365 ath_dbg(common
, CHAN_CTX
,
366 "Setup chanctx timer with timeout: %d ms\n", jiffies_to_msecs(tsf_time
));
369 static void ath_chanctx_handle_bmiss(struct ath_softc
*sc
,
370 struct ath_chanctx
*ctx
,
374 * Clear the extend_absence flag if it had been
375 * set during the previous beacon transmission,
376 * since we need to revert to the normal NoA
379 if (ctx
->active
&& sc
->sched
.extend_absence
) {
380 avp
->noa_duration
= 0;
381 sc
->sched
.extend_absence
= false;
384 /* If at least two consecutive beacons were missed on the STA
385 * chanctx, stay on the STA channel for one extra beacon period,
386 * to resync the timer properly.
388 if (ctx
->active
&& sc
->sched
.beacon_miss
>= 2) {
389 avp
->noa_duration
= 0;
390 sc
->sched
.extend_absence
= true;
394 static void ath_chanctx_offchannel_noa(struct ath_softc
*sc
,
395 struct ath_chanctx
*ctx
,
399 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
402 avp
->offchannel_start
= tsf_time
;
403 avp
->offchannel_duration
= sc
->sched
.offchannel_duration
;
405 ath_dbg(common
, CHAN_CTX
,
406 "offchannel noa_duration: %d, noa_start: %d, noa_index: %d\n",
407 avp
->offchannel_duration
,
408 avp
->offchannel_start
,
412 * When multiple contexts are active, the NoA
413 * has to be recalculated and advertised after
414 * an offchannel operation.
416 if (ctx
->active
&& avp
->noa_duration
)
417 avp
->noa_duration
= 0;
420 static void ath_chanctx_set_periodic_noa(struct ath_softc
*sc
,
422 struct ath_beacon_config
*cur_conf
,
426 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
429 avp
->noa_start
= tsf_time
;
431 if (sc
->sched
.extend_absence
)
432 avp
->noa_duration
= (3 * beacon_int
/ 2) +
433 sc
->sched
.channel_switch_time
;
436 TU_TO_USEC(cur_conf
->beacon_interval
) / 2 +
437 sc
->sched
.channel_switch_time
;
439 if (test_bit(ATH_OP_SCANNING
, &common
->op_flags
) ||
440 sc
->sched
.extend_absence
)
441 avp
->periodic_noa
= false;
443 avp
->periodic_noa
= true;
445 ath_dbg(common
, CHAN_CTX
,
446 "noa_duration: %d, noa_start: %d, noa_index: %d, periodic: %d\n",
453 void ath_chanctx_event(struct ath_softc
*sc
, struct ieee80211_vif
*vif
,
454 enum ath_chanctx_event ev
)
456 struct ath_hw
*ah
= sc
->sc_ah
;
457 struct ath_common
*common
= ath9k_hw_common(ah
);
458 struct ath_beacon_config
*cur_conf
;
459 struct ath_vif
*avp
= NULL
;
460 struct ath_chanctx
*ctx
;
465 avp
= (struct ath_vif
*) vif
->drv_priv
;
467 spin_lock_bh(&sc
->chan_lock
);
469 ath_dbg(common
, CHAN_CTX
, "cur_chan: %d MHz, event: %s, state: %s\n",
470 sc
->cur_chan
->chandef
.center_freq1
,
471 chanctx_event_string(ev
),
472 chanctx_state_string(sc
->sched
.state
));
475 case ATH_CHANCTX_EVENT_BEACON_PREPARE
:
476 if (avp
->offchannel_duration
)
477 avp
->offchannel_duration
= 0;
479 if (avp
->chanctx
!= sc
->cur_chan
) {
480 ath_dbg(common
, CHAN_CTX
,
481 "Contexts differ, not preparing beacon\n");
485 if (sc
->sched
.offchannel_pending
&& !sc
->sched
.wait_switch
) {
486 sc
->sched
.offchannel_pending
= false;
487 sc
->next_chan
= &sc
->offchannel
.chan
;
488 sc
->sched
.state
= ATH_CHANCTX_STATE_WAIT_FOR_BEACON
;
489 ath_dbg(common
, CHAN_CTX
,
490 "Setting offchannel_pending to false\n");
493 ctx
= ath_chanctx_get_next(sc
, sc
->cur_chan
);
494 if (ctx
->active
&& sc
->sched
.state
== ATH_CHANCTX_STATE_IDLE
) {
496 sc
->sched
.state
= ATH_CHANCTX_STATE_WAIT_FOR_BEACON
;
497 ath_dbg(common
, CHAN_CTX
,
498 "Set next context, move chanctx state to WAIT_FOR_BEACON\n");
501 /* if the timer missed its window, use the next interval */
502 if (sc
->sched
.state
== ATH_CHANCTX_STATE_WAIT_FOR_TIMER
) {
503 sc
->sched
.state
= ATH_CHANCTX_STATE_WAIT_FOR_BEACON
;
504 ath_dbg(common
, CHAN_CTX
,
505 "Move chanctx state from WAIT_FOR_TIMER to WAIT_FOR_BEACON\n");
508 if (sc
->sched
.mgd_prepare_tx
)
509 sc
->sched
.state
= ATH_CHANCTX_STATE_WAIT_FOR_BEACON
;
512 * When a context becomes inactive, for example,
513 * disassociation of a station context, the NoA
514 * attribute needs to be removed from subsequent
517 if (!ctx
->active
&& avp
->noa_duration
&&
518 sc
->sched
.state
!= ATH_CHANCTX_STATE_WAIT_FOR_BEACON
) {
519 avp
->noa_duration
= 0;
520 avp
->periodic_noa
= false;
522 ath_dbg(common
, CHAN_CTX
,
523 "Clearing NoA schedule\n");
526 if (sc
->sched
.state
!= ATH_CHANCTX_STATE_WAIT_FOR_BEACON
)
529 ath_dbg(common
, CHAN_CTX
, "Preparing beacon for vif: %pM\n", vif
->addr
);
531 sc
->sched
.beacon_pending
= true;
532 sc
->sched
.next_tbtt
= REG_READ(ah
, AR_NEXT_TBTT_TIMER
);
534 cur_conf
= &sc
->cur_chan
->beacon
;
535 beacon_int
= TU_TO_USEC(cur_conf
->beacon_interval
);
537 /* defer channel switch by a quarter beacon interval */
538 tsf_time
= sc
->sched
.next_tbtt
+ beacon_int
/ 4;
539 sc
->sched
.switch_start_time
= tsf_time
;
540 sc
->cur_chan
->last_beacon
= sc
->sched
.next_tbtt
;
543 * If an offchannel switch is scheduled to happen after
544 * a beacon transmission, update the NoA with one-shot
545 * values and increment the index.
547 if (sc
->next_chan
== &sc
->offchannel
.chan
) {
548 ath_chanctx_offchannel_noa(sc
, ctx
, avp
, tsf_time
);
552 ath_chanctx_handle_bmiss(sc
, ctx
, avp
);
554 /* Prevent wrap-around issues */
555 if (avp
->noa_duration
&& tsf_time
- avp
->noa_start
> BIT(30))
556 avp
->noa_duration
= 0;
559 * If multiple contexts are active, start periodic
560 * NoA and increment the index for the first
564 (!avp
->noa_duration
|| sc
->sched
.force_noa_update
))
565 ath_chanctx_set_periodic_noa(sc
, avp
, cur_conf
,
566 tsf_time
, beacon_int
);
568 if (ctx
->active
&& sc
->sched
.force_noa_update
)
569 sc
->sched
.force_noa_update
= false;
572 case ATH_CHANCTX_EVENT_BEACON_SENT
:
573 if (!sc
->sched
.beacon_pending
) {
574 ath_dbg(common
, CHAN_CTX
,
575 "No pending beacon\n");
579 sc
->sched
.beacon_pending
= false;
581 if (sc
->sched
.mgd_prepare_tx
) {
582 sc
->sched
.mgd_prepare_tx
= false;
583 complete(&sc
->go_beacon
);
584 ath_dbg(common
, CHAN_CTX
,
585 "Beacon sent, complete go_beacon\n");
589 if (sc
->sched
.state
!= ATH_CHANCTX_STATE_WAIT_FOR_BEACON
)
592 ath_dbg(common
, CHAN_CTX
,
593 "Move chanctx state to WAIT_FOR_TIMER\n");
595 sc
->sched
.state
= ATH_CHANCTX_STATE_WAIT_FOR_TIMER
;
596 ath_chanctx_setup_timer(sc
, sc
->sched
.switch_start_time
);
598 case ATH_CHANCTX_EVENT_TSF_TIMER
:
599 if (sc
->sched
.state
!= ATH_CHANCTX_STATE_WAIT_FOR_TIMER
)
602 if (!sc
->cur_chan
->switch_after_beacon
&&
603 sc
->sched
.beacon_pending
)
604 sc
->sched
.beacon_miss
++;
606 ath_dbg(common
, CHAN_CTX
,
607 "Move chanctx state to SWITCH\n");
609 sc
->sched
.state
= ATH_CHANCTX_STATE_SWITCH
;
610 ieee80211_queue_work(sc
->hw
, &sc
->chanctx_work
);
612 case ATH_CHANCTX_EVENT_BEACON_RECEIVED
:
613 if (!test_bit(ATH_OP_MULTI_CHANNEL
, &common
->op_flags
) ||
614 sc
->cur_chan
== &sc
->offchannel
.chan
)
617 sc
->sched
.beacon_pending
= false;
618 sc
->sched
.beacon_miss
= 0;
620 if (sc
->sched
.state
== ATH_CHANCTX_STATE_FORCE_ACTIVE
||
621 !sc
->cur_chan
->tsf_val
)
624 ath_chanctx_adjust_tbtt_delta(sc
);
626 /* TSF time might have been updated by the incoming beacon,
627 * need update the channel switch timer to reflect the change.
629 tsf_time
= sc
->sched
.switch_start_time
;
630 tsf_time
-= (u32
) sc
->cur_chan
->tsf_val
+
631 ath9k_hw_get_tsf_offset(&sc
->cur_chan
->tsf_ts
, NULL
);
632 tsf_time
+= ath9k_hw_gettsf32(ah
);
635 ath_chanctx_setup_timer(sc
, tsf_time
);
637 case ATH_CHANCTX_EVENT_AUTHORIZED
:
638 if (sc
->sched
.state
!= ATH_CHANCTX_STATE_FORCE_ACTIVE
||
639 avp
->chanctx
!= sc
->cur_chan
)
642 ath_dbg(common
, CHAN_CTX
,
643 "Move chanctx state from FORCE_ACTIVE to IDLE\n");
645 sc
->sched
.state
= ATH_CHANCTX_STATE_IDLE
;
647 case ATH_CHANCTX_EVENT_SWITCH
:
648 if (!test_bit(ATH_OP_MULTI_CHANNEL
, &common
->op_flags
) ||
649 sc
->sched
.state
== ATH_CHANCTX_STATE_FORCE_ACTIVE
||
650 sc
->cur_chan
->switch_after_beacon
||
651 sc
->cur_chan
== &sc
->offchannel
.chan
)
654 /* If this is a station chanctx, stay active for a half
655 * beacon period (minus channel switch time)
657 sc
->next_chan
= ath_chanctx_get_next(sc
, sc
->cur_chan
);
658 cur_conf
= &sc
->cur_chan
->beacon
;
660 ath_dbg(common
, CHAN_CTX
,
661 "Move chanctx state to WAIT_FOR_TIMER (event SWITCH)\n");
663 sc
->sched
.state
= ATH_CHANCTX_STATE_WAIT_FOR_TIMER
;
664 sc
->sched
.wait_switch
= false;
666 tsf_time
= TU_TO_USEC(cur_conf
->beacon_interval
) / 2;
668 if (sc
->sched
.extend_absence
) {
669 sc
->sched
.beacon_miss
= 0;
673 tsf_time
-= sc
->sched
.channel_switch_time
;
674 tsf_time
+= ath9k_hw_gettsf32(sc
->sc_ah
);
675 sc
->sched
.switch_start_time
= tsf_time
;
677 ath_chanctx_setup_timer(sc
, tsf_time
);
678 sc
->sched
.beacon_pending
= true;
680 case ATH_CHANCTX_EVENT_ENABLE_MULTICHANNEL
:
681 if (sc
->cur_chan
== &sc
->offchannel
.chan
||
682 sc
->cur_chan
->switch_after_beacon
)
685 sc
->next_chan
= ath_chanctx_get_next(sc
, sc
->cur_chan
);
686 ieee80211_queue_work(sc
->hw
, &sc
->chanctx_work
);
688 case ATH_CHANCTX_EVENT_UNASSIGN
:
689 if (sc
->cur_chan
->assigned
) {
690 if (sc
->next_chan
&& !sc
->next_chan
->assigned
&&
691 sc
->next_chan
!= &sc
->offchannel
.chan
)
692 sc
->sched
.state
= ATH_CHANCTX_STATE_IDLE
;
696 ctx
= ath_chanctx_get_next(sc
, sc
->cur_chan
);
697 sc
->sched
.state
= ATH_CHANCTX_STATE_IDLE
;
702 ieee80211_queue_work(sc
->hw
, &sc
->chanctx_work
);
704 case ATH_CHANCTX_EVENT_ASSIGN
:
706 * When adding a new channel context, check if a scan
707 * is in progress and abort it since the addition of
708 * a new channel context is usually followed by VIF
709 * assignment, in which case we have to start multi-channel
712 if (test_bit(ATH_OP_SCANNING
, &common
->op_flags
)) {
713 ath_dbg(common
, CHAN_CTX
,
714 "Aborting HW scan to add new context\n");
716 spin_unlock_bh(&sc
->chan_lock
);
717 del_timer_sync(&sc
->offchannel
.timer
);
718 ath_scan_complete(sc
, true);
719 spin_lock_bh(&sc
->chan_lock
);
722 case ATH_CHANCTX_EVENT_CHANGE
:
726 spin_unlock_bh(&sc
->chan_lock
);
729 void ath_chanctx_beacon_sent_ev(struct ath_softc
*sc
,
730 enum ath_chanctx_event ev
)
732 if (sc
->sched
.beacon_pending
)
733 ath_chanctx_event(sc
, NULL
, ev
);
736 void ath_chanctx_beacon_recv_ev(struct ath_softc
*sc
,
737 enum ath_chanctx_event ev
)
739 ath_chanctx_event(sc
, NULL
, ev
);
742 static int ath_scan_channel_duration(struct ath_softc
*sc
,
743 struct ieee80211_channel
*chan
)
745 struct cfg80211_scan_request
*req
= sc
->offchannel
.scan_req
;
747 if (!req
->n_ssids
|| (chan
->flags
& IEEE80211_CHAN_NO_IR
))
748 return (HZ
/ 9); /* ~110 ms */
750 return (HZ
/ 16); /* ~60 ms */
753 static void ath_chanctx_switch(struct ath_softc
*sc
, struct ath_chanctx
*ctx
,
754 struct cfg80211_chan_def
*chandef
)
756 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
758 spin_lock_bh(&sc
->chan_lock
);
760 if (test_bit(ATH_OP_MULTI_CHANNEL
, &common
->op_flags
) &&
761 (sc
->cur_chan
!= ctx
) && (ctx
== &sc
->offchannel
.chan
)) {
763 ctx
->chandef
= *chandef
;
765 sc
->sched
.offchannel_pending
= true;
766 sc
->sched
.wait_switch
= true;
767 sc
->sched
.offchannel_duration
=
768 jiffies_to_usecs(sc
->offchannel
.duration
) +
769 sc
->sched
.channel_switch_time
;
771 spin_unlock_bh(&sc
->chan_lock
);
772 ath_dbg(common
, CHAN_CTX
,
773 "Set offchannel_pending to true\n");
779 ctx
->chandef
= *chandef
;
780 ath_dbg(common
, CHAN_CTX
,
781 "Assigned next_chan to %d MHz\n", chandef
->center_freq1
);
784 if (sc
->next_chan
== &sc
->offchannel
.chan
) {
785 sc
->sched
.offchannel_duration
=
786 jiffies_to_usecs(sc
->offchannel
.duration
) +
787 sc
->sched
.channel_switch_time
;
790 ath_dbg(common
, CHAN_CTX
,
791 "Offchannel duration for chan %d MHz : %u\n",
792 chandef
->center_freq1
,
793 sc
->sched
.offchannel_duration
);
796 spin_unlock_bh(&sc
->chan_lock
);
797 ieee80211_queue_work(sc
->hw
, &sc
->chanctx_work
);
800 static void ath_chanctx_offchan_switch(struct ath_softc
*sc
,
801 struct ieee80211_channel
*chan
)
803 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
804 struct cfg80211_chan_def chandef
;
806 cfg80211_chandef_create(&chandef
, chan
, NL80211_CHAN_NO_HT
);
807 ath_dbg(common
, CHAN_CTX
,
808 "Channel definition created: %d MHz\n", chandef
.center_freq1
);
810 ath_chanctx_switch(sc
, &sc
->offchannel
.chan
, &chandef
);
813 static struct ath_chanctx
*ath_chanctx_get_oper_chan(struct ath_softc
*sc
,
816 struct ath_chanctx
*ctx
;
818 ath_for_each_chanctx(sc
, ctx
) {
819 if (!ctx
->assigned
|| list_empty(&ctx
->vifs
))
821 if (active
&& !ctx
->active
)
824 if (ctx
->switch_after_beacon
)
828 return &sc
->chanctx
[0];
832 ath_scan_next_channel(struct ath_softc
*sc
)
834 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
835 struct cfg80211_scan_request
*req
= sc
->offchannel
.scan_req
;
836 struct ieee80211_channel
*chan
;
838 if (sc
->offchannel
.scan_idx
>= req
->n_channels
) {
839 ath_dbg(common
, CHAN_CTX
,
840 "Moving offchannel state to ATH_OFFCHANNEL_IDLE, "
841 "scan_idx: %d, n_channels: %d\n",
842 sc
->offchannel
.scan_idx
,
845 sc
->offchannel
.state
= ATH_OFFCHANNEL_IDLE
;
846 ath_chanctx_switch(sc
, ath_chanctx_get_oper_chan(sc
, false),
851 ath_dbg(common
, CHAN_CTX
,
852 "Moving offchannel state to ATH_OFFCHANNEL_PROBE_SEND, scan_idx: %d\n",
853 sc
->offchannel
.scan_idx
);
855 chan
= req
->channels
[sc
->offchannel
.scan_idx
++];
856 sc
->offchannel
.duration
= ath_scan_channel_duration(sc
, chan
);
857 sc
->offchannel
.state
= ATH_OFFCHANNEL_PROBE_SEND
;
859 ath_chanctx_offchan_switch(sc
, chan
);
862 void ath_offchannel_next(struct ath_softc
*sc
)
864 struct ieee80211_vif
*vif
;
866 if (sc
->offchannel
.scan_req
) {
867 vif
= sc
->offchannel
.scan_vif
;
868 sc
->offchannel
.chan
.txpower
= vif
->bss_conf
.txpower
;
869 ath_scan_next_channel(sc
);
870 } else if (sc
->offchannel
.roc_vif
) {
871 vif
= sc
->offchannel
.roc_vif
;
872 sc
->offchannel
.chan
.txpower
= vif
->bss_conf
.txpower
;
873 sc
->offchannel
.duration
=
874 msecs_to_jiffies(sc
->offchannel
.roc_duration
);
875 sc
->offchannel
.state
= ATH_OFFCHANNEL_ROC_START
;
876 ath_chanctx_offchan_switch(sc
, sc
->offchannel
.roc_chan
);
878 ath_chanctx_switch(sc
, ath_chanctx_get_oper_chan(sc
, false),
880 sc
->offchannel
.state
= ATH_OFFCHANNEL_IDLE
;
886 void ath_roc_complete(struct ath_softc
*sc
, bool abort
)
888 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
891 ath_dbg(common
, CHAN_CTX
, "RoC aborted\n");
893 ath_dbg(common
, CHAN_CTX
, "RoC expired\n");
895 sc
->offchannel
.roc_vif
= NULL
;
896 sc
->offchannel
.roc_chan
= NULL
;
898 ieee80211_remain_on_channel_expired(sc
->hw
);
899 ath_offchannel_next(sc
);
900 ath9k_ps_restore(sc
);
903 void ath_scan_complete(struct ath_softc
*sc
, bool abort
)
905 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
908 ath_dbg(common
, CHAN_CTX
, "HW scan aborted\n");
910 ath_dbg(common
, CHAN_CTX
, "HW scan complete\n");
912 sc
->offchannel
.scan_req
= NULL
;
913 sc
->offchannel
.scan_vif
= NULL
;
914 sc
->offchannel
.state
= ATH_OFFCHANNEL_IDLE
;
915 ieee80211_scan_completed(sc
->hw
, abort
);
916 clear_bit(ATH_OP_SCANNING
, &common
->op_flags
);
917 spin_lock_bh(&sc
->chan_lock
);
918 if (test_bit(ATH_OP_MULTI_CHANNEL
, &common
->op_flags
))
919 sc
->sched
.force_noa_update
= true;
920 spin_unlock_bh(&sc
->chan_lock
);
921 ath_offchannel_next(sc
);
922 ath9k_ps_restore(sc
);
925 static void ath_scan_send_probe(struct ath_softc
*sc
,
926 struct cfg80211_ssid
*ssid
)
928 struct cfg80211_scan_request
*req
= sc
->offchannel
.scan_req
;
929 struct ieee80211_vif
*vif
= sc
->offchannel
.scan_vif
;
930 struct ath_tx_control txctl
= {};
932 struct ieee80211_tx_info
*info
;
933 int band
= sc
->offchannel
.chan
.chandef
.chan
->band
;
935 skb
= ieee80211_probereq_get(sc
->hw
, vif
,
936 ssid
->ssid
, ssid
->ssid_len
, req
->ie_len
);
940 info
= IEEE80211_SKB_CB(skb
);
942 info
->flags
|= IEEE80211_TX_CTL_NO_CCK_RATE
;
945 memcpy(skb_put(skb
, req
->ie_len
), req
->ie
, req
->ie_len
);
947 skb_set_queue_mapping(skb
, IEEE80211_AC_VO
);
949 if (!ieee80211_tx_prepare_skb(sc
->hw
, vif
, skb
, band
, NULL
))
952 txctl
.txq
= sc
->tx
.txq_map
[IEEE80211_AC_VO
];
953 txctl
.force_channel
= true;
954 if (ath_tx_start(sc
->hw
, skb
, &txctl
))
960 ieee80211_free_txskb(sc
->hw
, skb
);
963 static void ath_scan_channel_start(struct ath_softc
*sc
)
965 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
966 struct cfg80211_scan_request
*req
= sc
->offchannel
.scan_req
;
969 if (!(sc
->cur_chan
->chandef
.chan
->flags
& IEEE80211_CHAN_NO_IR
) &&
971 for (i
= 0; i
< req
->n_ssids
; i
++)
972 ath_scan_send_probe(sc
, &req
->ssids
[i
]);
976 ath_dbg(common
, CHAN_CTX
,
977 "Moving offchannel state to ATH_OFFCHANNEL_PROBE_WAIT\n");
979 sc
->offchannel
.state
= ATH_OFFCHANNEL_PROBE_WAIT
;
980 mod_timer(&sc
->offchannel
.timer
, jiffies
+ sc
->offchannel
.duration
);
983 static void ath_chanctx_timer(unsigned long data
)
985 struct ath_softc
*sc
= (struct ath_softc
*) data
;
986 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
988 ath_dbg(common
, CHAN_CTX
,
989 "Channel context timer invoked\n");
991 ath_chanctx_event(sc
, NULL
, ATH_CHANCTX_EVENT_TSF_TIMER
);
994 static void ath_offchannel_timer(unsigned long data
)
996 struct ath_softc
*sc
= (struct ath_softc
*)data
;
997 struct ath_chanctx
*ctx
;
998 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
1000 ath_dbg(common
, CHAN_CTX
, "%s: offchannel state: %s\n",
1001 __func__
, offchannel_state_string(sc
->offchannel
.state
));
1003 switch (sc
->offchannel
.state
) {
1004 case ATH_OFFCHANNEL_PROBE_WAIT
:
1005 if (!sc
->offchannel
.scan_req
)
1008 /* get first active channel context */
1009 ctx
= ath_chanctx_get_oper_chan(sc
, true);
1011 ath_dbg(common
, CHAN_CTX
,
1012 "Switch to oper/active context, "
1013 "move offchannel state to ATH_OFFCHANNEL_SUSPEND\n");
1015 sc
->offchannel
.state
= ATH_OFFCHANNEL_SUSPEND
;
1016 ath_chanctx_switch(sc
, ctx
, NULL
);
1017 mod_timer(&sc
->offchannel
.timer
, jiffies
+ HZ
/ 10);
1021 case ATH_OFFCHANNEL_SUSPEND
:
1022 if (!sc
->offchannel
.scan_req
)
1025 ath_scan_next_channel(sc
);
1027 case ATH_OFFCHANNEL_ROC_START
:
1028 case ATH_OFFCHANNEL_ROC_WAIT
:
1029 ctx
= ath_chanctx_get_oper_chan(sc
, false);
1030 sc
->offchannel
.state
= ATH_OFFCHANNEL_ROC_DONE
;
1031 ath_chanctx_switch(sc
, ctx
, NULL
);
1039 ath_chanctx_send_vif_ps_frame(struct ath_softc
*sc
, struct ath_vif
*avp
,
1042 struct ieee80211_vif
*vif
= avp
->vif
;
1043 struct ieee80211_sta
*sta
= NULL
;
1044 struct ieee80211_hdr_3addr
*nullfunc
;
1045 struct ath_tx_control txctl
;
1046 struct sk_buff
*skb
;
1047 int band
= sc
->cur_chan
->chandef
.chan
->band
;
1049 switch (vif
->type
) {
1050 case NL80211_IFTYPE_STATION
:
1054 skb
= ieee80211_nullfunc_get(sc
->hw
, vif
);
1058 nullfunc
= (struct ieee80211_hdr_3addr
*) skb
->data
;
1060 nullfunc
->frame_control
|=
1061 cpu_to_le16(IEEE80211_FCTL_PM
);
1063 skb_set_queue_mapping(skb
, IEEE80211_AC_VO
);
1064 if (!ieee80211_tx_prepare_skb(sc
->hw
, vif
, skb
, band
, &sta
)) {
1065 dev_kfree_skb_any(skb
);
1073 memset(&txctl
, 0, sizeof(txctl
));
1074 txctl
.txq
= sc
->tx
.txq_map
[IEEE80211_AC_VO
];
1076 txctl
.force_channel
= true;
1077 if (ath_tx_start(sc
->hw
, skb
, &txctl
)) {
1078 ieee80211_free_txskb(sc
->hw
, skb
);
1086 ath_chanctx_send_ps_frame(struct ath_softc
*sc
, bool powersave
)
1088 struct ath_vif
*avp
;
1092 list_for_each_entry(avp
, &sc
->cur_chan
->vifs
, list
) {
1093 if (ath_chanctx_send_vif_ps_frame(sc
, avp
, powersave
))
1101 static bool ath_chanctx_defer_switch(struct ath_softc
*sc
)
1103 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
1105 if (sc
->cur_chan
== &sc
->offchannel
.chan
)
1108 switch (sc
->sched
.state
) {
1109 case ATH_CHANCTX_STATE_SWITCH
:
1111 case ATH_CHANCTX_STATE_IDLE
:
1112 if (!sc
->cur_chan
->switch_after_beacon
)
1115 ath_dbg(common
, CHAN_CTX
,
1116 "Defer switch, set chanctx state to WAIT_FOR_BEACON\n");
1118 sc
->sched
.state
= ATH_CHANCTX_STATE_WAIT_FOR_BEACON
;
1127 static void ath_offchannel_channel_change(struct ath_softc
*sc
)
1129 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
1131 ath_dbg(common
, CHAN_CTX
, "%s: offchannel state: %s\n",
1132 __func__
, offchannel_state_string(sc
->offchannel
.state
));
1134 switch (sc
->offchannel
.state
) {
1135 case ATH_OFFCHANNEL_PROBE_SEND
:
1136 if (!sc
->offchannel
.scan_req
)
1139 if (sc
->cur_chan
->chandef
.chan
!=
1140 sc
->offchannel
.chan
.chandef
.chan
)
1143 ath_scan_channel_start(sc
);
1145 case ATH_OFFCHANNEL_IDLE
:
1146 if (!sc
->offchannel
.scan_req
)
1149 ath_scan_complete(sc
, false);
1151 case ATH_OFFCHANNEL_ROC_START
:
1152 if (sc
->cur_chan
!= &sc
->offchannel
.chan
)
1155 sc
->offchannel
.state
= ATH_OFFCHANNEL_ROC_WAIT
;
1156 mod_timer(&sc
->offchannel
.timer
,
1157 jiffies
+ sc
->offchannel
.duration
);
1158 ieee80211_ready_on_channel(sc
->hw
);
1160 case ATH_OFFCHANNEL_ROC_DONE
:
1161 ath_roc_complete(sc
, false);
1168 void ath_chanctx_set_next(struct ath_softc
*sc
, bool force
)
1170 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
1171 struct ath_chanctx
*old_ctx
;
1173 bool measure_time
= false;
1174 bool send_ps
= false;
1175 bool queues_stopped
= false;
1177 spin_lock_bh(&sc
->chan_lock
);
1178 if (!sc
->next_chan
) {
1179 spin_unlock_bh(&sc
->chan_lock
);
1183 if (!force
&& ath_chanctx_defer_switch(sc
)) {
1184 spin_unlock_bh(&sc
->chan_lock
);
1188 ath_dbg(common
, CHAN_CTX
,
1189 "%s: current: %d MHz, next: %d MHz\n",
1191 sc
->cur_chan
->chandef
.center_freq1
,
1192 sc
->next_chan
->chandef
.center_freq1
);
1194 if (sc
->cur_chan
!= sc
->next_chan
) {
1195 ath_dbg(common
, CHAN_CTX
,
1196 "Stopping current chanctx: %d\n",
1197 sc
->cur_chan
->chandef
.center_freq1
);
1198 sc
->cur_chan
->stopped
= true;
1199 spin_unlock_bh(&sc
->chan_lock
);
1201 if (sc
->next_chan
== &sc
->offchannel
.chan
) {
1202 getrawmonotonic(&ts
);
1203 measure_time
= true;
1206 ath9k_chanctx_stop_queues(sc
, sc
->cur_chan
);
1207 queues_stopped
= true;
1209 __ath9k_flush(sc
->hw
, ~0, true, false);
1211 if (ath_chanctx_send_ps_frame(sc
, true))
1212 __ath9k_flush(sc
->hw
, BIT(IEEE80211_AC_VO
),
1216 spin_lock_bh(&sc
->chan_lock
);
1218 if (sc
->cur_chan
!= &sc
->offchannel
.chan
) {
1219 getrawmonotonic(&sc
->cur_chan
->tsf_ts
);
1220 sc
->cur_chan
->tsf_val
= ath9k_hw_gettsf64(sc
->sc_ah
);
1223 old_ctx
= sc
->cur_chan
;
1224 sc
->cur_chan
= sc
->next_chan
;
1225 sc
->cur_chan
->stopped
= false;
1226 sc
->next_chan
= NULL
;
1228 if (!sc
->sched
.offchannel_pending
)
1229 sc
->sched
.offchannel_duration
= 0;
1231 if (sc
->sched
.state
!= ATH_CHANCTX_STATE_FORCE_ACTIVE
)
1232 sc
->sched
.state
= ATH_CHANCTX_STATE_IDLE
;
1234 spin_unlock_bh(&sc
->chan_lock
);
1236 if (sc
->sc_ah
->chip_fullsleep
||
1237 memcmp(&sc
->cur_chandef
, &sc
->cur_chan
->chandef
,
1238 sizeof(sc
->cur_chandef
))) {
1239 ath_dbg(common
, CHAN_CTX
,
1240 "%s: Set channel %d MHz\n",
1241 __func__
, sc
->cur_chan
->chandef
.center_freq1
);
1242 ath_set_channel(sc
);
1244 sc
->sched
.channel_switch_time
=
1245 ath9k_hw_get_tsf_offset(&ts
, NULL
);
1247 * A reset will ensure that all queues are woken up,
1248 * so there is no need to awaken them again.
1254 ath9k_chanctx_wake_queues(sc
, old_ctx
);
1257 ath_chanctx_send_ps_frame(sc
, false);
1259 ath_offchannel_channel_change(sc
);
1260 ath_chanctx_event(sc
, NULL
, ATH_CHANCTX_EVENT_SWITCH
);
1263 static void ath_chanctx_work(struct work_struct
*work
)
1265 struct ath_softc
*sc
= container_of(work
, struct ath_softc
,
1267 mutex_lock(&sc
->mutex
);
1268 ath_chanctx_set_next(sc
, false);
1269 mutex_unlock(&sc
->mutex
);
1272 void ath9k_offchannel_init(struct ath_softc
*sc
)
1274 struct ath_chanctx
*ctx
;
1275 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
1276 struct ieee80211_supported_band
*sband
;
1277 struct ieee80211_channel
*chan
;
1280 sband
= &common
->sbands
[IEEE80211_BAND_2GHZ
];
1281 if (!sband
->n_channels
)
1282 sband
= &common
->sbands
[IEEE80211_BAND_5GHZ
];
1284 chan
= &sband
->channels
[0];
1286 ctx
= &sc
->offchannel
.chan
;
1287 INIT_LIST_HEAD(&ctx
->vifs
);
1288 ctx
->txpower
= ATH_TXPOWER_MAX
;
1289 cfg80211_chandef_create(&ctx
->chandef
, chan
, NL80211_CHAN_HT20
);
1291 for (i
= 0; i
< ARRAY_SIZE(ctx
->acq
); i
++)
1292 INIT_LIST_HEAD(&ctx
->acq
[i
]);
1294 sc
->offchannel
.chan
.offchannel
= true;
1297 void ath9k_init_channel_context(struct ath_softc
*sc
)
1299 INIT_WORK(&sc
->chanctx_work
, ath_chanctx_work
);
1301 setup_timer(&sc
->offchannel
.timer
, ath_offchannel_timer
,
1303 setup_timer(&sc
->sched
.timer
, ath_chanctx_timer
,
1306 init_completion(&sc
->go_beacon
);
1309 void ath9k_deinit_channel_context(struct ath_softc
*sc
)
1311 cancel_work_sync(&sc
->chanctx_work
);
1314 bool ath9k_is_chanctx_enabled(void)
1316 return (ath9k_use_chanctx
== 1);
1319 /********************/
1320 /* Queue management */
1321 /********************/
1323 void ath9k_chanctx_stop_queues(struct ath_softc
*sc
, struct ath_chanctx
*ctx
)
1325 struct ath_hw
*ah
= sc
->sc_ah
;
1328 if (ctx
== &sc
->offchannel
.chan
) {
1329 ieee80211_stop_queue(sc
->hw
,
1330 sc
->hw
->offchannel_tx_hw_queue
);
1332 for (i
= 0; i
< IEEE80211_NUM_ACS
; i
++)
1333 ieee80211_stop_queue(sc
->hw
,
1334 ctx
->hw_queue_base
+ i
);
1337 if (ah
->opmode
== NL80211_IFTYPE_AP
)
1338 ieee80211_stop_queue(sc
->hw
, sc
->hw
->queues
- 2);
1342 void ath9k_chanctx_wake_queues(struct ath_softc
*sc
, struct ath_chanctx
*ctx
)
1344 struct ath_hw
*ah
= sc
->sc_ah
;
1347 if (ctx
== &sc
->offchannel
.chan
) {
1348 ieee80211_wake_queue(sc
->hw
,
1349 sc
->hw
->offchannel_tx_hw_queue
);
1351 for (i
= 0; i
< IEEE80211_NUM_ACS
; i
++)
1352 ieee80211_wake_queue(sc
->hw
,
1353 ctx
->hw_queue_base
+ i
);
1356 if (ah
->opmode
== NL80211_IFTYPE_AP
)
1357 ieee80211_wake_queue(sc
->hw
, sc
->hw
->queues
- 2);
1364 static void ath9k_update_p2p_ps_timer(struct ath_softc
*sc
, struct ath_vif
*avp
)
1366 struct ath_hw
*ah
= sc
->sc_ah
;
1367 s32 tsf
, target_tsf
;
1369 if (!avp
|| !avp
->noa
.has_next_tsf
)
1372 ath9k_hw_gen_timer_stop(ah
, sc
->p2p_ps_timer
);
1374 tsf
= ath9k_hw_gettsf32(sc
->sc_ah
);
1376 target_tsf
= avp
->noa
.next_tsf
;
1377 if (!avp
->noa
.absent
)
1378 target_tsf
-= ATH_P2P_PS_STOP_TIME
;
1380 if (target_tsf
- tsf
< ATH_P2P_PS_STOP_TIME
)
1381 target_tsf
= tsf
+ ATH_P2P_PS_STOP_TIME
;
1383 ath9k_hw_gen_timer_start(ah
, sc
->p2p_ps_timer
, (u32
) target_tsf
, 1000000);
1386 static void ath9k_update_p2p_ps(struct ath_softc
*sc
, struct ieee80211_vif
*vif
)
1388 struct ath_vif
*avp
= (void *)vif
->drv_priv
;
1391 if (!sc
->p2p_ps_timer
)
1394 if (vif
->type
!= NL80211_IFTYPE_STATION
|| !vif
->p2p
)
1397 sc
->p2p_ps_vif
= avp
;
1398 tsf
= ath9k_hw_gettsf32(sc
->sc_ah
);
1399 ieee80211_parse_p2p_noa(&vif
->bss_conf
.p2p_noa_attr
, &avp
->noa
, tsf
);
1400 ath9k_update_p2p_ps_timer(sc
, avp
);
1403 static u8
ath9k_get_ctwin(struct ath_softc
*sc
, struct ath_vif
*avp
)
1405 struct ath_beacon_config
*cur_conf
= &sc
->cur_chan
->beacon
;
1406 u8 switch_time
, ctwin
;
1409 * Channel switch in multi-channel mode is deferred
1410 * by a quarter beacon interval when handling
1411 * ATH_CHANCTX_EVENT_BEACON_PREPARE, so the P2P-GO
1412 * interface is guaranteed to be discoverable
1413 * for that duration after a TBTT.
1415 switch_time
= cur_conf
->beacon_interval
/ 4;
1417 ctwin
= avp
->vif
->bss_conf
.p2p_noa_attr
.oppps_ctwindow
;
1418 if (ctwin
&& (ctwin
< switch_time
))
1421 if (switch_time
< P2P_DEFAULT_CTWIN
)
1424 return P2P_DEFAULT_CTWIN
;
1427 void ath9k_beacon_add_noa(struct ath_softc
*sc
, struct ath_vif
*avp
,
1428 struct sk_buff
*skb
)
1430 static const u8 noa_ie_hdr
[] = {
1431 WLAN_EID_VENDOR_SPECIFIC
, /* type */
1433 0x50, 0x6f, 0x9a, /* WFA OUI */
1434 0x09, /* P2P subtype */
1435 0x0c, /* Notice of Absence */
1436 0x00, /* LSB of little-endian len */
1437 0x00, /* MSB of little-endian len */
1440 struct ieee80211_p2p_noa_attr
*noa
;
1441 int noa_len
, noa_desc
, i
= 0;
1444 if (!avp
->offchannel_duration
&& !avp
->noa_duration
)
1447 noa_desc
= !!avp
->offchannel_duration
+ !!avp
->noa_duration
;
1448 noa_len
= 2 + sizeof(struct ieee80211_p2p_noa_desc
) * noa_desc
;
1450 hdr
= skb_put(skb
, sizeof(noa_ie_hdr
));
1451 memcpy(hdr
, noa_ie_hdr
, sizeof(noa_ie_hdr
));
1452 hdr
[1] = sizeof(noa_ie_hdr
) + noa_len
- 2;
1455 noa
= (void *) skb_put(skb
, noa_len
);
1456 memset(noa
, 0, noa_len
);
1458 noa
->index
= avp
->noa_index
;
1459 noa
->oppps_ctwindow
= ath9k_get_ctwin(sc
, avp
);
1461 if (avp
->noa_duration
) {
1462 if (avp
->periodic_noa
) {
1463 u32 interval
= TU_TO_USEC(sc
->cur_chan
->beacon
.beacon_interval
);
1464 noa
->desc
[i
].count
= 255;
1465 noa
->desc
[i
].interval
= cpu_to_le32(interval
);
1467 noa
->desc
[i
].count
= 1;
1470 noa
->desc
[i
].start_time
= cpu_to_le32(avp
->noa_start
);
1471 noa
->desc
[i
].duration
= cpu_to_le32(avp
->noa_duration
);
1475 if (avp
->offchannel_duration
) {
1476 noa
->desc
[i
].count
= 1;
1477 noa
->desc
[i
].start_time
= cpu_to_le32(avp
->offchannel_start
);
1478 noa
->desc
[i
].duration
= cpu_to_le32(avp
->offchannel_duration
);
1482 void ath9k_p2p_ps_timer(void *priv
)
1484 struct ath_softc
*sc
= priv
;
1485 struct ath_vif
*avp
= sc
->p2p_ps_vif
;
1486 struct ieee80211_vif
*vif
;
1487 struct ieee80211_sta
*sta
;
1488 struct ath_node
*an
;
1491 del_timer_sync(&sc
->sched
.timer
);
1492 ath9k_hw_gen_timer_stop(sc
->sc_ah
, sc
->p2p_ps_timer
);
1493 ath_chanctx_event(sc
, NULL
, ATH_CHANCTX_EVENT_TSF_TIMER
);
1495 if (!avp
|| avp
->chanctx
!= sc
->cur_chan
)
1498 tsf
= ath9k_hw_gettsf32(sc
->sc_ah
);
1499 if (!avp
->noa
.absent
)
1500 tsf
+= ATH_P2P_PS_STOP_TIME
;
1502 if (!avp
->noa
.has_next_tsf
||
1503 avp
->noa
.next_tsf
- tsf
> BIT(31))
1504 ieee80211_update_p2p_noa(&avp
->noa
, tsf
);
1506 ath9k_update_p2p_ps_timer(sc
, avp
);
1511 sta
= ieee80211_find_sta(vif
, avp
->bssid
);
1515 an
= (void *) sta
->drv_priv
;
1516 if (an
->sleeping
== !!avp
->noa
.absent
)
1519 an
->sleeping
= avp
->noa
.absent
;
1521 ath_tx_aggr_sleep(sta
, sc
, an
);
1523 ath_tx_aggr_wakeup(sc
, an
);
1529 void ath9k_p2p_bss_info_changed(struct ath_softc
*sc
,
1530 struct ieee80211_vif
*vif
)
1532 unsigned long flags
;
1534 spin_lock_bh(&sc
->sc_pcu_lock
);
1535 spin_lock_irqsave(&sc
->sc_pm_lock
, flags
);
1536 if (!(sc
->ps_flags
& PS_BEACON_SYNC
))
1537 ath9k_update_p2p_ps(sc
, vif
);
1538 spin_unlock_irqrestore(&sc
->sc_pm_lock
, flags
);
1539 spin_unlock_bh(&sc
->sc_pcu_lock
);
1542 void ath9k_p2p_beacon_sync(struct ath_softc
*sc
)
1545 ath9k_update_p2p_ps(sc
, sc
->p2p_ps_vif
->vif
);
1548 void ath9k_p2p_remove_vif(struct ath_softc
*sc
,
1549 struct ieee80211_vif
*vif
)
1551 struct ath_vif
*avp
= (void *)vif
->drv_priv
;
1553 spin_lock_bh(&sc
->sc_pcu_lock
);
1554 if (avp
== sc
->p2p_ps_vif
) {
1555 sc
->p2p_ps_vif
= NULL
;
1556 ath9k_update_p2p_ps_timer(sc
, NULL
);
1558 spin_unlock_bh(&sc
->sc_pcu_lock
);
1561 int ath9k_init_p2p(struct ath_softc
*sc
)
1563 sc
->p2p_ps_timer
= ath_gen_timer_alloc(sc
->sc_ah
, ath9k_p2p_ps_timer
,
1564 NULL
, sc
, AR_FIRST_NDP_TIMER
);
1565 if (!sc
->p2p_ps_timer
)
1571 void ath9k_deinit_p2p(struct ath_softc
*sc
)
1573 if (sc
->p2p_ps_timer
)
1574 ath_gen_timer_free(sc
->sc_ah
, sc
->p2p_ps_timer
);
1577 #endif /* CONFIG_ATH9K_CHANNEL_CONTEXT */