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 for (j
= 0; j
< ARRAY_SIZE(ctx
->acq
); j
++)
121 INIT_LIST_HEAD(&ctx
->acq
[j
]);
125 void ath_chanctx_set_channel(struct ath_softc
*sc
, struct ath_chanctx
*ctx
,
126 struct cfg80211_chan_def
*chandef
)
128 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
131 spin_lock_bh(&sc
->chan_lock
);
133 memcpy(&ctx
->chandef
, chandef
, sizeof(*chandef
));
134 cur_chan
= sc
->cur_chan
== ctx
;
135 spin_unlock_bh(&sc
->chan_lock
);
138 ath_dbg(common
, CHAN_CTX
,
139 "Current context differs from the new context\n");
146 #ifdef CONFIG_ATH9K_CHANNEL_CONTEXT
148 /**********************************************************/
149 /* Functions to handle the channel context state machine. */
150 /**********************************************************/
152 static const char *offchannel_state_string(enum ath_offchannel_state state
)
155 case_rtn_string(ATH_OFFCHANNEL_IDLE
);
156 case_rtn_string(ATH_OFFCHANNEL_PROBE_SEND
);
157 case_rtn_string(ATH_OFFCHANNEL_PROBE_WAIT
);
158 case_rtn_string(ATH_OFFCHANNEL_SUSPEND
);
159 case_rtn_string(ATH_OFFCHANNEL_ROC_START
);
160 case_rtn_string(ATH_OFFCHANNEL_ROC_WAIT
);
161 case_rtn_string(ATH_OFFCHANNEL_ROC_DONE
);
167 static const char *chanctx_event_string(enum ath_chanctx_event ev
)
170 case_rtn_string(ATH_CHANCTX_EVENT_BEACON_PREPARE
);
171 case_rtn_string(ATH_CHANCTX_EVENT_BEACON_SENT
);
172 case_rtn_string(ATH_CHANCTX_EVENT_TSF_TIMER
);
173 case_rtn_string(ATH_CHANCTX_EVENT_BEACON_RECEIVED
);
174 case_rtn_string(ATH_CHANCTX_EVENT_AUTHORIZED
);
175 case_rtn_string(ATH_CHANCTX_EVENT_SWITCH
);
176 case_rtn_string(ATH_CHANCTX_EVENT_ASSIGN
);
177 case_rtn_string(ATH_CHANCTX_EVENT_UNASSIGN
);
178 case_rtn_string(ATH_CHANCTX_EVENT_CHANGE
);
179 case_rtn_string(ATH_CHANCTX_EVENT_ENABLE_MULTICHANNEL
);
185 static const char *chanctx_state_string(enum ath_chanctx_state state
)
188 case_rtn_string(ATH_CHANCTX_STATE_IDLE
);
189 case_rtn_string(ATH_CHANCTX_STATE_WAIT_FOR_BEACON
);
190 case_rtn_string(ATH_CHANCTX_STATE_WAIT_FOR_TIMER
);
191 case_rtn_string(ATH_CHANCTX_STATE_SWITCH
);
192 case_rtn_string(ATH_CHANCTX_STATE_FORCE_ACTIVE
);
198 void ath_chanctx_check_active(struct ath_softc
*sc
, struct ath_chanctx
*ctx
)
200 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
208 list_for_each_entry(avp
, &ctx
->vifs
, list
) {
209 struct ieee80211_vif
*vif
= avp
->vif
;
212 case NL80211_IFTYPE_P2P_CLIENT
:
213 case NL80211_IFTYPE_STATION
:
222 ctx
->active
= active
;
224 ath_for_each_chanctx(sc
, ctx
) {
225 if (!ctx
->assigned
|| list_empty(&ctx
->vifs
))
231 clear_bit(ATH_OP_MULTI_CHANNEL
, &common
->op_flags
);
234 if (test_and_set_bit(ATH_OP_MULTI_CHANNEL
, &common
->op_flags
))
237 if (ath9k_is_chanctx_enabled()) {
238 ath_chanctx_event(sc
, NULL
,
239 ATH_CHANCTX_EVENT_ENABLE_MULTICHANNEL
);
243 static struct ath_chanctx
*
244 ath_chanctx_get_next(struct ath_softc
*sc
, struct ath_chanctx
*ctx
)
246 int idx
= ctx
- &sc
->chanctx
[0];
248 return &sc
->chanctx
[!idx
];
251 static void ath_chanctx_adjust_tbtt_delta(struct ath_softc
*sc
)
253 struct ath_chanctx
*prev
, *cur
;
255 u32 cur_tsf
, prev_tsf
, beacon_int
;
258 beacon_int
= TU_TO_USEC(sc
->cur_chan
->beacon
.beacon_interval
);
261 prev
= ath_chanctx_get_next(sc
, cur
);
263 if (!prev
->switch_after_beacon
)
266 getrawmonotonic(&ts
);
267 cur_tsf
= (u32
) cur
->tsf_val
+
268 ath9k_hw_get_tsf_offset(&cur
->tsf_ts
, &ts
);
270 prev_tsf
= prev
->last_beacon
- (u32
) prev
->tsf_val
+ cur_tsf
;
271 prev_tsf
-= ath9k_hw_get_tsf_offset(&prev
->tsf_ts
, &ts
);
273 /* Adjust the TSF time of the AP chanctx to keep its beacons
274 * at half beacon interval offset relative to the STA chanctx.
276 offset
= cur_tsf
- prev_tsf
;
278 /* Ignore stale data or spurious timestamps */
279 if (offset
< 0 || offset
> 3 * beacon_int
)
282 offset
= beacon_int
/ 2 - (offset
% beacon_int
);
283 prev
->tsf_val
+= offset
;
286 /* Configure the TSF based hardware timer for a channel switch.
287 * Also set up backup software timer, in case the gen timer fails.
288 * This could be caused by a hardware reset.
290 static void ath_chanctx_setup_timer(struct ath_softc
*sc
, u32 tsf_time
)
292 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
293 struct ath_hw
*ah
= sc
->sc_ah
;
295 ath9k_hw_gen_timer_start(ah
, sc
->p2p_ps_timer
, tsf_time
, 1000000);
296 tsf_time
-= ath9k_hw_gettsf32(ah
);
297 tsf_time
= msecs_to_jiffies(tsf_time
/ 1000) + 1;
298 mod_timer(&sc
->sched
.timer
, jiffies
+ tsf_time
);
300 ath_dbg(common
, CHAN_CTX
,
301 "Setup chanctx timer with timeout: %d ms\n", jiffies_to_msecs(tsf_time
));
304 void ath_chanctx_event(struct ath_softc
*sc
, struct ieee80211_vif
*vif
,
305 enum ath_chanctx_event ev
)
307 struct ath_hw
*ah
= sc
->sc_ah
;
308 struct ath_common
*common
= ath9k_hw_common(ah
);
309 struct ath_beacon_config
*cur_conf
;
310 struct ath_vif
*avp
= NULL
;
311 struct ath_chanctx
*ctx
;
316 avp
= (struct ath_vif
*) vif
->drv_priv
;
318 spin_lock_bh(&sc
->chan_lock
);
320 ath_dbg(common
, CHAN_CTX
, "cur_chan: %d MHz, event: %s, state: %s\n",
321 sc
->cur_chan
->chandef
.center_freq1
,
322 chanctx_event_string(ev
),
323 chanctx_state_string(sc
->sched
.state
));
326 case ATH_CHANCTX_EVENT_BEACON_PREPARE
:
327 if (avp
->offchannel_duration
)
328 avp
->offchannel_duration
= 0;
330 if (avp
->chanctx
!= sc
->cur_chan
) {
331 ath_dbg(common
, CHAN_CTX
,
332 "Contexts differ, not preparing beacon\n");
336 if (sc
->sched
.offchannel_pending
&& !sc
->sched
.wait_switch
) {
337 sc
->sched
.offchannel_pending
= false;
338 sc
->next_chan
= &sc
->offchannel
.chan
;
339 sc
->sched
.state
= ATH_CHANCTX_STATE_WAIT_FOR_BEACON
;
340 ath_dbg(common
, CHAN_CTX
,
341 "Setting offchannel_pending to false\n");
344 ctx
= ath_chanctx_get_next(sc
, sc
->cur_chan
);
345 if (ctx
->active
&& sc
->sched
.state
== ATH_CHANCTX_STATE_IDLE
) {
347 sc
->sched
.state
= ATH_CHANCTX_STATE_WAIT_FOR_BEACON
;
348 ath_dbg(common
, CHAN_CTX
,
349 "Set next context, move chanctx state to WAIT_FOR_BEACON\n");
352 /* if the timer missed its window, use the next interval */
353 if (sc
->sched
.state
== ATH_CHANCTX_STATE_WAIT_FOR_TIMER
) {
354 sc
->sched
.state
= ATH_CHANCTX_STATE_WAIT_FOR_BEACON
;
355 ath_dbg(common
, CHAN_CTX
,
356 "Move chanctx state from WAIT_FOR_TIMER to WAIT_FOR_BEACON\n");
359 if (sc
->sched
.state
!= ATH_CHANCTX_STATE_WAIT_FOR_BEACON
)
362 ath_dbg(common
, CHAN_CTX
, "Preparing beacon for vif: %pM\n", vif
->addr
);
364 sc
->sched
.beacon_pending
= true;
365 sc
->sched
.next_tbtt
= REG_READ(ah
, AR_NEXT_TBTT_TIMER
);
367 cur_conf
= &sc
->cur_chan
->beacon
;
368 beacon_int
= TU_TO_USEC(cur_conf
->beacon_interval
);
370 /* defer channel switch by a quarter beacon interval */
371 tsf_time
= sc
->sched
.next_tbtt
+ beacon_int
/ 4;
372 sc
->sched
.switch_start_time
= tsf_time
;
373 sc
->cur_chan
->last_beacon
= sc
->sched
.next_tbtt
;
376 * If an offchannel switch is scheduled to happen after
377 * a beacon transmission, update the NoA with one-shot
378 * values and increment the index.
380 if (sc
->next_chan
== &sc
->offchannel
.chan
) {
382 avp
->offchannel_start
= tsf_time
;
383 avp
->offchannel_duration
= sc
->sched
.offchannel_duration
;
385 ath_dbg(common
, CHAN_CTX
,
386 "offchannel noa_duration: %d, noa_start: %d, noa_index: %d\n",
387 avp
->offchannel_duration
,
388 avp
->offchannel_start
,
392 * When multiple contexts are active, the NoA
393 * has to be recalculated and advertised after
394 * an offchannel operation.
396 if (ctx
->active
&& avp
->noa_duration
)
397 avp
->noa_duration
= 0;
403 * Clear the extend_absence flag if it had been
404 * set during the previous beacon transmission,
405 * since we need to revert to the normal NoA
408 if (ctx
->active
&& sc
->sched
.extend_absence
) {
409 avp
->noa_duration
= 0;
410 sc
->sched
.extend_absence
= false;
413 /* If at least two consecutive beacons were missed on the STA
414 * chanctx, stay on the STA channel for one extra beacon period,
415 * to resync the timer properly.
417 if (ctx
->active
&& sc
->sched
.beacon_miss
>= 2) {
418 avp
->noa_duration
= 0;
419 sc
->sched
.extend_absence
= true;
422 /* Prevent wrap-around issues */
423 if (avp
->noa_duration
&& tsf_time
- avp
->noa_start
> BIT(30))
424 avp
->noa_duration
= 0;
427 * If multiple contexts are active, start periodic
428 * NoA and increment the index for the first
432 (!avp
->noa_duration
|| sc
->sched
.force_noa_update
)) {
434 avp
->noa_start
= tsf_time
;
436 if (sc
->sched
.extend_absence
)
437 avp
->noa_duration
= (3 * beacon_int
/ 2) +
438 sc
->sched
.channel_switch_time
;
441 TU_TO_USEC(cur_conf
->beacon_interval
) / 2 +
442 sc
->sched
.channel_switch_time
;
444 if (test_bit(ATH_OP_SCANNING
, &common
->op_flags
) ||
445 sc
->sched
.extend_absence
)
446 avp
->periodic_noa
= false;
448 avp
->periodic_noa
= true;
450 ath_dbg(common
, CHAN_CTX
,
451 "noa_duration: %d, noa_start: %d, noa_index: %d, periodic: %d\n",
458 if (ctx
->active
&& sc
->sched
.force_noa_update
)
459 sc
->sched
.force_noa_update
= false;
462 case ATH_CHANCTX_EVENT_BEACON_SENT
:
463 if (!sc
->sched
.beacon_pending
) {
464 ath_dbg(common
, CHAN_CTX
,
465 "No pending beacon\n");
469 sc
->sched
.beacon_pending
= false;
470 if (sc
->sched
.state
!= ATH_CHANCTX_STATE_WAIT_FOR_BEACON
)
473 ath_dbg(common
, CHAN_CTX
,
474 "Move chanctx state to WAIT_FOR_TIMER\n");
476 sc
->sched
.state
= ATH_CHANCTX_STATE_WAIT_FOR_TIMER
;
477 ath_chanctx_setup_timer(sc
, sc
->sched
.switch_start_time
);
479 case ATH_CHANCTX_EVENT_TSF_TIMER
:
480 if (sc
->sched
.state
!= ATH_CHANCTX_STATE_WAIT_FOR_TIMER
)
483 if (!sc
->cur_chan
->switch_after_beacon
&&
484 sc
->sched
.beacon_pending
)
485 sc
->sched
.beacon_miss
++;
487 ath_dbg(common
, CHAN_CTX
,
488 "Move chanctx state to SWITCH\n");
490 sc
->sched
.state
= ATH_CHANCTX_STATE_SWITCH
;
491 ieee80211_queue_work(sc
->hw
, &sc
->chanctx_work
);
493 case ATH_CHANCTX_EVENT_BEACON_RECEIVED
:
494 if (!test_bit(ATH_OP_MULTI_CHANNEL
, &common
->op_flags
) ||
495 sc
->cur_chan
== &sc
->offchannel
.chan
)
498 sc
->sched
.beacon_pending
= false;
499 sc
->sched
.beacon_miss
= 0;
501 if (sc
->sched
.state
== ATH_CHANCTX_STATE_FORCE_ACTIVE
||
502 !sc
->cur_chan
->tsf_val
)
505 ath_chanctx_adjust_tbtt_delta(sc
);
507 /* TSF time might have been updated by the incoming beacon,
508 * need update the channel switch timer to reflect the change.
510 tsf_time
= sc
->sched
.switch_start_time
;
511 tsf_time
-= (u32
) sc
->cur_chan
->tsf_val
+
512 ath9k_hw_get_tsf_offset(&sc
->cur_chan
->tsf_ts
, NULL
);
513 tsf_time
+= ath9k_hw_gettsf32(ah
);
516 ath_chanctx_setup_timer(sc
, tsf_time
);
518 case ATH_CHANCTX_EVENT_AUTHORIZED
:
519 if (sc
->sched
.state
!= ATH_CHANCTX_STATE_FORCE_ACTIVE
||
520 avp
->chanctx
!= sc
->cur_chan
)
523 ath_dbg(common
, CHAN_CTX
,
524 "Move chanctx state from FORCE_ACTIVE to IDLE\n");
526 sc
->sched
.state
= ATH_CHANCTX_STATE_IDLE
;
528 case ATH_CHANCTX_EVENT_SWITCH
:
529 if (!test_bit(ATH_OP_MULTI_CHANNEL
, &common
->op_flags
) ||
530 sc
->sched
.state
== ATH_CHANCTX_STATE_FORCE_ACTIVE
||
531 sc
->cur_chan
->switch_after_beacon
||
532 sc
->cur_chan
== &sc
->offchannel
.chan
)
535 /* If this is a station chanctx, stay active for a half
536 * beacon period (minus channel switch time)
538 sc
->next_chan
= ath_chanctx_get_next(sc
, sc
->cur_chan
);
539 cur_conf
= &sc
->cur_chan
->beacon
;
541 ath_dbg(common
, CHAN_CTX
,
542 "Move chanctx state to WAIT_FOR_TIMER (event SWITCH)\n");
544 sc
->sched
.state
= ATH_CHANCTX_STATE_WAIT_FOR_TIMER
;
545 sc
->sched
.wait_switch
= false;
547 tsf_time
= TU_TO_USEC(cur_conf
->beacon_interval
) / 2;
549 if (sc
->sched
.extend_absence
) {
550 sc
->sched
.beacon_miss
= 0;
554 tsf_time
-= sc
->sched
.channel_switch_time
;
555 tsf_time
+= ath9k_hw_gettsf32(sc
->sc_ah
);
556 sc
->sched
.switch_start_time
= tsf_time
;
558 ath_chanctx_setup_timer(sc
, tsf_time
);
559 sc
->sched
.beacon_pending
= true;
561 case ATH_CHANCTX_EVENT_ENABLE_MULTICHANNEL
:
562 if (sc
->cur_chan
== &sc
->offchannel
.chan
||
563 sc
->cur_chan
->switch_after_beacon
)
566 sc
->next_chan
= ath_chanctx_get_next(sc
, sc
->cur_chan
);
567 ieee80211_queue_work(sc
->hw
, &sc
->chanctx_work
);
569 case ATH_CHANCTX_EVENT_UNASSIGN
:
570 if (sc
->cur_chan
->assigned
) {
571 if (sc
->next_chan
&& !sc
->next_chan
->assigned
&&
572 sc
->next_chan
!= &sc
->offchannel
.chan
)
573 sc
->sched
.state
= ATH_CHANCTX_STATE_IDLE
;
577 ctx
= ath_chanctx_get_next(sc
, sc
->cur_chan
);
578 sc
->sched
.state
= ATH_CHANCTX_STATE_IDLE
;
583 ieee80211_queue_work(sc
->hw
, &sc
->chanctx_work
);
585 case ATH_CHANCTX_EVENT_ASSIGN
:
587 * When adding a new channel context, check if a scan
588 * is in progress and abort it since the addition of
589 * a new channel context is usually followed by VIF
590 * assignment, in which case we have to start multi-channel
593 if (test_bit(ATH_OP_SCANNING
, &common
->op_flags
)) {
594 ath_dbg(common
, CHAN_CTX
,
595 "Aborting HW scan to add new context\n");
597 spin_unlock_bh(&sc
->chan_lock
);
598 del_timer_sync(&sc
->offchannel
.timer
);
599 ath_scan_complete(sc
, true);
600 spin_lock_bh(&sc
->chan_lock
);
603 case ATH_CHANCTX_EVENT_CHANGE
:
607 spin_unlock_bh(&sc
->chan_lock
);
610 void ath_chanctx_beacon_sent_ev(struct ath_softc
*sc
,
611 enum ath_chanctx_event ev
)
613 if (sc
->sched
.beacon_pending
)
614 ath_chanctx_event(sc
, NULL
, ev
);
617 void ath_chanctx_beacon_recv_ev(struct ath_softc
*sc
,
618 enum ath_chanctx_event ev
)
620 ath_chanctx_event(sc
, NULL
, ev
);
623 static int ath_scan_channel_duration(struct ath_softc
*sc
,
624 struct ieee80211_channel
*chan
)
626 struct cfg80211_scan_request
*req
= sc
->offchannel
.scan_req
;
628 if (!req
->n_ssids
|| (chan
->flags
& IEEE80211_CHAN_NO_IR
))
629 return (HZ
/ 9); /* ~110 ms */
631 return (HZ
/ 16); /* ~60 ms */
634 static void ath_chanctx_switch(struct ath_softc
*sc
, struct ath_chanctx
*ctx
,
635 struct cfg80211_chan_def
*chandef
)
637 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
639 spin_lock_bh(&sc
->chan_lock
);
641 if (test_bit(ATH_OP_MULTI_CHANNEL
, &common
->op_flags
) &&
642 (sc
->cur_chan
!= ctx
) && (ctx
== &sc
->offchannel
.chan
)) {
644 ctx
->chandef
= *chandef
;
646 sc
->sched
.offchannel_pending
= true;
647 sc
->sched
.wait_switch
= true;
648 sc
->sched
.offchannel_duration
=
649 jiffies_to_usecs(sc
->offchannel
.duration
) +
650 sc
->sched
.channel_switch_time
;
652 spin_unlock_bh(&sc
->chan_lock
);
653 ath_dbg(common
, CHAN_CTX
,
654 "Set offchannel_pending to true\n");
660 ctx
->chandef
= *chandef
;
661 ath_dbg(common
, CHAN_CTX
,
662 "Assigned next_chan to %d MHz\n", chandef
->center_freq1
);
665 if (sc
->next_chan
== &sc
->offchannel
.chan
) {
666 sc
->sched
.offchannel_duration
=
667 jiffies_to_usecs(sc
->offchannel
.duration
) +
668 sc
->sched
.channel_switch_time
;
671 ath_dbg(common
, CHAN_CTX
,
672 "Offchannel duration for chan %d MHz : %u\n",
673 chandef
->center_freq1
,
674 sc
->sched
.offchannel_duration
);
677 spin_unlock_bh(&sc
->chan_lock
);
678 ieee80211_queue_work(sc
->hw
, &sc
->chanctx_work
);
681 static void ath_chanctx_offchan_switch(struct ath_softc
*sc
,
682 struct ieee80211_channel
*chan
)
684 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
685 struct cfg80211_chan_def chandef
;
687 cfg80211_chandef_create(&chandef
, chan
, NL80211_CHAN_NO_HT
);
688 ath_dbg(common
, CHAN_CTX
,
689 "Channel definition created: %d MHz\n", chandef
.center_freq1
);
691 ath_chanctx_switch(sc
, &sc
->offchannel
.chan
, &chandef
);
694 static struct ath_chanctx
*ath_chanctx_get_oper_chan(struct ath_softc
*sc
,
697 struct ath_chanctx
*ctx
;
699 ath_for_each_chanctx(sc
, ctx
) {
700 if (!ctx
->assigned
|| list_empty(&ctx
->vifs
))
702 if (active
&& !ctx
->active
)
705 if (ctx
->switch_after_beacon
)
709 return &sc
->chanctx
[0];
713 ath_scan_next_channel(struct ath_softc
*sc
)
715 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
716 struct cfg80211_scan_request
*req
= sc
->offchannel
.scan_req
;
717 struct ieee80211_channel
*chan
;
719 if (sc
->offchannel
.scan_idx
>= req
->n_channels
) {
720 ath_dbg(common
, CHAN_CTX
,
721 "Moving offchannel state to ATH_OFFCHANNEL_IDLE, "
722 "scan_idx: %d, n_channels: %d\n",
723 sc
->offchannel
.scan_idx
,
726 sc
->offchannel
.state
= ATH_OFFCHANNEL_IDLE
;
727 ath_chanctx_switch(sc
, ath_chanctx_get_oper_chan(sc
, false),
732 ath_dbg(common
, CHAN_CTX
,
733 "Moving offchannel state to ATH_OFFCHANNEL_PROBE_SEND, scan_idx: %d\n",
734 sc
->offchannel
.scan_idx
);
736 chan
= req
->channels
[sc
->offchannel
.scan_idx
++];
737 sc
->offchannel
.duration
= ath_scan_channel_duration(sc
, chan
);
738 sc
->offchannel
.state
= ATH_OFFCHANNEL_PROBE_SEND
;
740 ath_chanctx_offchan_switch(sc
, chan
);
743 void ath_offchannel_next(struct ath_softc
*sc
)
745 struct ieee80211_vif
*vif
;
747 if (sc
->offchannel
.scan_req
) {
748 vif
= sc
->offchannel
.scan_vif
;
749 sc
->offchannel
.chan
.txpower
= vif
->bss_conf
.txpower
;
750 ath_scan_next_channel(sc
);
751 } else if (sc
->offchannel
.roc_vif
) {
752 vif
= sc
->offchannel
.roc_vif
;
753 sc
->offchannel
.chan
.txpower
= vif
->bss_conf
.txpower
;
754 sc
->offchannel
.duration
=
755 msecs_to_jiffies(sc
->offchannel
.roc_duration
);
756 sc
->offchannel
.state
= ATH_OFFCHANNEL_ROC_START
;
757 ath_chanctx_offchan_switch(sc
, sc
->offchannel
.roc_chan
);
759 ath_chanctx_switch(sc
, ath_chanctx_get_oper_chan(sc
, false),
761 sc
->offchannel
.state
= ATH_OFFCHANNEL_IDLE
;
767 void ath_roc_complete(struct ath_softc
*sc
, bool abort
)
769 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
772 ath_dbg(common
, CHAN_CTX
, "RoC aborted\n");
774 ath_dbg(common
, CHAN_CTX
, "RoC expired\n");
776 sc
->offchannel
.roc_vif
= NULL
;
777 sc
->offchannel
.roc_chan
= NULL
;
779 ieee80211_remain_on_channel_expired(sc
->hw
);
780 ath_offchannel_next(sc
);
781 ath9k_ps_restore(sc
);
784 void ath_scan_complete(struct ath_softc
*sc
, bool abort
)
786 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
789 ath_dbg(common
, CHAN_CTX
, "HW scan aborted\n");
791 ath_dbg(common
, CHAN_CTX
, "HW scan complete\n");
793 sc
->offchannel
.scan_req
= NULL
;
794 sc
->offchannel
.scan_vif
= NULL
;
795 sc
->offchannel
.state
= ATH_OFFCHANNEL_IDLE
;
796 ieee80211_scan_completed(sc
->hw
, abort
);
797 clear_bit(ATH_OP_SCANNING
, &common
->op_flags
);
798 spin_lock_bh(&sc
->chan_lock
);
799 if (test_bit(ATH_OP_MULTI_CHANNEL
, &common
->op_flags
))
800 sc
->sched
.force_noa_update
= true;
801 spin_unlock_bh(&sc
->chan_lock
);
802 ath_offchannel_next(sc
);
803 ath9k_ps_restore(sc
);
806 static void ath_scan_send_probe(struct ath_softc
*sc
,
807 struct cfg80211_ssid
*ssid
)
809 struct cfg80211_scan_request
*req
= sc
->offchannel
.scan_req
;
810 struct ieee80211_vif
*vif
= sc
->offchannel
.scan_vif
;
811 struct ath_tx_control txctl
= {};
813 struct ieee80211_tx_info
*info
;
814 int band
= sc
->offchannel
.chan
.chandef
.chan
->band
;
816 skb
= ieee80211_probereq_get(sc
->hw
, vif
,
817 ssid
->ssid
, ssid
->ssid_len
, req
->ie_len
);
821 info
= IEEE80211_SKB_CB(skb
);
823 info
->flags
|= IEEE80211_TX_CTL_NO_CCK_RATE
;
826 memcpy(skb_put(skb
, req
->ie_len
), req
->ie
, req
->ie_len
);
828 skb_set_queue_mapping(skb
, IEEE80211_AC_VO
);
830 if (!ieee80211_tx_prepare_skb(sc
->hw
, vif
, skb
, band
, NULL
))
833 txctl
.txq
= sc
->tx
.txq_map
[IEEE80211_AC_VO
];
834 txctl
.force_channel
= true;
835 if (ath_tx_start(sc
->hw
, skb
, &txctl
))
841 ieee80211_free_txskb(sc
->hw
, skb
);
844 static void ath_scan_channel_start(struct ath_softc
*sc
)
846 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
847 struct cfg80211_scan_request
*req
= sc
->offchannel
.scan_req
;
850 if (!(sc
->cur_chan
->chandef
.chan
->flags
& IEEE80211_CHAN_NO_IR
) &&
852 for (i
= 0; i
< req
->n_ssids
; i
++)
853 ath_scan_send_probe(sc
, &req
->ssids
[i
]);
857 ath_dbg(common
, CHAN_CTX
,
858 "Moving offchannel state to ATH_OFFCHANNEL_PROBE_WAIT\n");
860 sc
->offchannel
.state
= ATH_OFFCHANNEL_PROBE_WAIT
;
861 mod_timer(&sc
->offchannel
.timer
, jiffies
+ sc
->offchannel
.duration
);
864 static void ath_chanctx_timer(unsigned long data
)
866 struct ath_softc
*sc
= (struct ath_softc
*) data
;
867 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
869 ath_dbg(common
, CHAN_CTX
,
870 "Channel context timer invoked\n");
872 ath_chanctx_event(sc
, NULL
, ATH_CHANCTX_EVENT_TSF_TIMER
);
875 static void ath_offchannel_timer(unsigned long data
)
877 struct ath_softc
*sc
= (struct ath_softc
*)data
;
878 struct ath_chanctx
*ctx
;
879 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
881 ath_dbg(common
, CHAN_CTX
, "%s: offchannel state: %s\n",
882 __func__
, offchannel_state_string(sc
->offchannel
.state
));
884 switch (sc
->offchannel
.state
) {
885 case ATH_OFFCHANNEL_PROBE_WAIT
:
886 if (!sc
->offchannel
.scan_req
)
889 /* get first active channel context */
890 ctx
= ath_chanctx_get_oper_chan(sc
, true);
892 ath_dbg(common
, CHAN_CTX
,
893 "Switch to oper/active context, "
894 "move offchannel state to ATH_OFFCHANNEL_SUSPEND\n");
896 sc
->offchannel
.state
= ATH_OFFCHANNEL_SUSPEND
;
897 ath_chanctx_switch(sc
, ctx
, NULL
);
898 mod_timer(&sc
->offchannel
.timer
, jiffies
+ HZ
/ 10);
902 case ATH_OFFCHANNEL_SUSPEND
:
903 if (!sc
->offchannel
.scan_req
)
906 ath_scan_next_channel(sc
);
908 case ATH_OFFCHANNEL_ROC_START
:
909 case ATH_OFFCHANNEL_ROC_WAIT
:
910 ctx
= ath_chanctx_get_oper_chan(sc
, false);
911 sc
->offchannel
.state
= ATH_OFFCHANNEL_ROC_DONE
;
912 ath_chanctx_switch(sc
, ctx
, NULL
);
920 ath_chanctx_send_vif_ps_frame(struct ath_softc
*sc
, struct ath_vif
*avp
,
923 struct ieee80211_vif
*vif
= avp
->vif
;
924 struct ieee80211_sta
*sta
= NULL
;
925 struct ieee80211_hdr_3addr
*nullfunc
;
926 struct ath_tx_control txctl
;
928 int band
= sc
->cur_chan
->chandef
.chan
->band
;
931 case NL80211_IFTYPE_STATION
:
935 skb
= ieee80211_nullfunc_get(sc
->hw
, vif
);
939 nullfunc
= (struct ieee80211_hdr_3addr
*) skb
->data
;
941 nullfunc
->frame_control
|=
942 cpu_to_le16(IEEE80211_FCTL_PM
);
944 skb_set_queue_mapping(skb
, IEEE80211_AC_VO
);
945 if (!ieee80211_tx_prepare_skb(sc
->hw
, vif
, skb
, band
, &sta
)) {
946 dev_kfree_skb_any(skb
);
954 memset(&txctl
, 0, sizeof(txctl
));
955 txctl
.txq
= sc
->tx
.txq_map
[IEEE80211_AC_VO
];
957 txctl
.force_channel
= true;
958 if (ath_tx_start(sc
->hw
, skb
, &txctl
)) {
959 ieee80211_free_txskb(sc
->hw
, skb
);
967 ath_chanctx_send_ps_frame(struct ath_softc
*sc
, bool powersave
)
973 list_for_each_entry(avp
, &sc
->cur_chan
->vifs
, list
) {
974 if (ath_chanctx_send_vif_ps_frame(sc
, avp
, powersave
))
982 static bool ath_chanctx_defer_switch(struct ath_softc
*sc
)
984 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
986 if (sc
->cur_chan
== &sc
->offchannel
.chan
)
989 switch (sc
->sched
.state
) {
990 case ATH_CHANCTX_STATE_SWITCH
:
992 case ATH_CHANCTX_STATE_IDLE
:
993 if (!sc
->cur_chan
->switch_after_beacon
)
996 ath_dbg(common
, CHAN_CTX
,
997 "Defer switch, set chanctx state to WAIT_FOR_BEACON\n");
999 sc
->sched
.state
= ATH_CHANCTX_STATE_WAIT_FOR_BEACON
;
1008 static void ath_offchannel_channel_change(struct ath_softc
*sc
)
1010 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
1012 ath_dbg(common
, CHAN_CTX
, "%s: offchannel state: %s\n",
1013 __func__
, offchannel_state_string(sc
->offchannel
.state
));
1015 switch (sc
->offchannel
.state
) {
1016 case ATH_OFFCHANNEL_PROBE_SEND
:
1017 if (!sc
->offchannel
.scan_req
)
1020 if (sc
->cur_chan
->chandef
.chan
!=
1021 sc
->offchannel
.chan
.chandef
.chan
)
1024 ath_scan_channel_start(sc
);
1026 case ATH_OFFCHANNEL_IDLE
:
1027 if (!sc
->offchannel
.scan_req
)
1030 ath_scan_complete(sc
, false);
1032 case ATH_OFFCHANNEL_ROC_START
:
1033 if (sc
->cur_chan
!= &sc
->offchannel
.chan
)
1036 sc
->offchannel
.state
= ATH_OFFCHANNEL_ROC_WAIT
;
1037 mod_timer(&sc
->offchannel
.timer
,
1038 jiffies
+ sc
->offchannel
.duration
);
1039 ieee80211_ready_on_channel(sc
->hw
);
1041 case ATH_OFFCHANNEL_ROC_DONE
:
1042 ath_roc_complete(sc
, false);
1049 void ath_chanctx_set_next(struct ath_softc
*sc
, bool force
)
1051 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
1052 struct ath_chanctx
*old_ctx
;
1054 bool measure_time
= false;
1055 bool send_ps
= false;
1056 bool queues_stopped
= false;
1058 spin_lock_bh(&sc
->chan_lock
);
1059 if (!sc
->next_chan
) {
1060 spin_unlock_bh(&sc
->chan_lock
);
1064 if (!force
&& ath_chanctx_defer_switch(sc
)) {
1065 spin_unlock_bh(&sc
->chan_lock
);
1069 ath_dbg(common
, CHAN_CTX
,
1070 "%s: current: %d MHz, next: %d MHz\n",
1072 sc
->cur_chan
->chandef
.center_freq1
,
1073 sc
->next_chan
->chandef
.center_freq1
);
1075 if (sc
->cur_chan
!= sc
->next_chan
) {
1076 ath_dbg(common
, CHAN_CTX
,
1077 "Stopping current chanctx: %d\n",
1078 sc
->cur_chan
->chandef
.center_freq1
);
1079 sc
->cur_chan
->stopped
= true;
1080 spin_unlock_bh(&sc
->chan_lock
);
1082 if (sc
->next_chan
== &sc
->offchannel
.chan
) {
1083 getrawmonotonic(&ts
);
1084 measure_time
= true;
1087 ath9k_chanctx_stop_queues(sc
, sc
->cur_chan
);
1088 queues_stopped
= true;
1090 __ath9k_flush(sc
->hw
, ~0, true);
1092 if (ath_chanctx_send_ps_frame(sc
, true))
1093 __ath9k_flush(sc
->hw
, BIT(IEEE80211_AC_VO
), false);
1096 spin_lock_bh(&sc
->chan_lock
);
1098 if (sc
->cur_chan
!= &sc
->offchannel
.chan
) {
1099 getrawmonotonic(&sc
->cur_chan
->tsf_ts
);
1100 sc
->cur_chan
->tsf_val
= ath9k_hw_gettsf64(sc
->sc_ah
);
1103 old_ctx
= sc
->cur_chan
;
1104 sc
->cur_chan
= sc
->next_chan
;
1105 sc
->cur_chan
->stopped
= false;
1106 sc
->next_chan
= NULL
;
1108 if (!sc
->sched
.offchannel_pending
)
1109 sc
->sched
.offchannel_duration
= 0;
1111 if (sc
->sched
.state
!= ATH_CHANCTX_STATE_FORCE_ACTIVE
)
1112 sc
->sched
.state
= ATH_CHANCTX_STATE_IDLE
;
1114 spin_unlock_bh(&sc
->chan_lock
);
1116 if (sc
->sc_ah
->chip_fullsleep
||
1117 memcmp(&sc
->cur_chandef
, &sc
->cur_chan
->chandef
,
1118 sizeof(sc
->cur_chandef
))) {
1119 ath_dbg(common
, CHAN_CTX
,
1120 "%s: Set channel %d MHz\n",
1121 __func__
, sc
->cur_chan
->chandef
.center_freq1
);
1122 ath_set_channel(sc
);
1124 sc
->sched
.channel_switch_time
=
1125 ath9k_hw_get_tsf_offset(&ts
, NULL
);
1127 * A reset will ensure that all queues are woken up,
1128 * so there is no need to awaken them again.
1134 ath9k_chanctx_wake_queues(sc
, old_ctx
);
1137 ath_chanctx_send_ps_frame(sc
, false);
1139 ath_offchannel_channel_change(sc
);
1140 ath_chanctx_event(sc
, NULL
, ATH_CHANCTX_EVENT_SWITCH
);
1143 static void ath_chanctx_work(struct work_struct
*work
)
1145 struct ath_softc
*sc
= container_of(work
, struct ath_softc
,
1147 mutex_lock(&sc
->mutex
);
1148 ath_chanctx_set_next(sc
, false);
1149 mutex_unlock(&sc
->mutex
);
1152 void ath9k_offchannel_init(struct ath_softc
*sc
)
1154 struct ath_chanctx
*ctx
;
1155 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
1156 struct ieee80211_supported_band
*sband
;
1157 struct ieee80211_channel
*chan
;
1160 sband
= &common
->sbands
[IEEE80211_BAND_2GHZ
];
1161 if (!sband
->n_channels
)
1162 sband
= &common
->sbands
[IEEE80211_BAND_5GHZ
];
1164 chan
= &sband
->channels
[0];
1166 ctx
= &sc
->offchannel
.chan
;
1167 INIT_LIST_HEAD(&ctx
->vifs
);
1168 ctx
->txpower
= ATH_TXPOWER_MAX
;
1169 cfg80211_chandef_create(&ctx
->chandef
, chan
, NL80211_CHAN_HT20
);
1171 for (i
= 0; i
< ARRAY_SIZE(ctx
->acq
); i
++)
1172 INIT_LIST_HEAD(&ctx
->acq
[i
]);
1174 sc
->offchannel
.chan
.offchannel
= true;
1177 void ath9k_init_channel_context(struct ath_softc
*sc
)
1179 INIT_WORK(&sc
->chanctx_work
, ath_chanctx_work
);
1181 setup_timer(&sc
->offchannel
.timer
, ath_offchannel_timer
,
1183 setup_timer(&sc
->sched
.timer
, ath_chanctx_timer
,
1187 void ath9k_deinit_channel_context(struct ath_softc
*sc
)
1189 cancel_work_sync(&sc
->chanctx_work
);
1192 bool ath9k_is_chanctx_enabled(void)
1194 return (ath9k_use_chanctx
== 1);
1197 /********************/
1198 /* Queue management */
1199 /********************/
1201 void ath9k_chanctx_stop_queues(struct ath_softc
*sc
, struct ath_chanctx
*ctx
)
1203 struct ath_hw
*ah
= sc
->sc_ah
;
1206 if (ctx
== &sc
->offchannel
.chan
) {
1207 ieee80211_stop_queue(sc
->hw
,
1208 sc
->hw
->offchannel_tx_hw_queue
);
1210 for (i
= 0; i
< IEEE80211_NUM_ACS
; i
++)
1211 ieee80211_stop_queue(sc
->hw
,
1212 ctx
->hw_queue_base
+ i
);
1215 if (ah
->opmode
== NL80211_IFTYPE_AP
)
1216 ieee80211_stop_queue(sc
->hw
, sc
->hw
->queues
- 2);
1220 void ath9k_chanctx_wake_queues(struct ath_softc
*sc
, struct ath_chanctx
*ctx
)
1222 struct ath_hw
*ah
= sc
->sc_ah
;
1225 if (ctx
== &sc
->offchannel
.chan
) {
1226 ieee80211_wake_queue(sc
->hw
,
1227 sc
->hw
->offchannel_tx_hw_queue
);
1229 for (i
= 0; i
< IEEE80211_NUM_ACS
; i
++)
1230 ieee80211_wake_queue(sc
->hw
,
1231 ctx
->hw_queue_base
+ i
);
1234 if (ah
->opmode
== NL80211_IFTYPE_AP
)
1235 ieee80211_wake_queue(sc
->hw
, sc
->hw
->queues
- 2);
1242 static void ath9k_update_p2p_ps_timer(struct ath_softc
*sc
, struct ath_vif
*avp
)
1244 struct ath_hw
*ah
= sc
->sc_ah
;
1245 s32 tsf
, target_tsf
;
1247 if (!avp
|| !avp
->noa
.has_next_tsf
)
1250 ath9k_hw_gen_timer_stop(ah
, sc
->p2p_ps_timer
);
1252 tsf
= ath9k_hw_gettsf32(sc
->sc_ah
);
1254 target_tsf
= avp
->noa
.next_tsf
;
1255 if (!avp
->noa
.absent
)
1256 target_tsf
-= ATH_P2P_PS_STOP_TIME
;
1258 if (target_tsf
- tsf
< ATH_P2P_PS_STOP_TIME
)
1259 target_tsf
= tsf
+ ATH_P2P_PS_STOP_TIME
;
1261 ath9k_hw_gen_timer_start(ah
, sc
->p2p_ps_timer
, (u32
) target_tsf
, 1000000);
1264 static void ath9k_update_p2p_ps(struct ath_softc
*sc
, struct ieee80211_vif
*vif
)
1266 struct ath_vif
*avp
= (void *)vif
->drv_priv
;
1269 if (!sc
->p2p_ps_timer
)
1272 if (vif
->type
!= NL80211_IFTYPE_STATION
|| !vif
->p2p
)
1275 sc
->p2p_ps_vif
= avp
;
1276 tsf
= ath9k_hw_gettsf32(sc
->sc_ah
);
1277 ieee80211_parse_p2p_noa(&vif
->bss_conf
.p2p_noa_attr
, &avp
->noa
, tsf
);
1278 ath9k_update_p2p_ps_timer(sc
, avp
);
1281 static u8
ath9k_get_ctwin(struct ath_softc
*sc
, struct ath_vif
*avp
)
1283 struct ath_beacon_config
*cur_conf
= &sc
->cur_chan
->beacon
;
1284 u8 switch_time
, ctwin
;
1287 * Channel switch in multi-channel mode is deferred
1288 * by a quarter beacon interval when handling
1289 * ATH_CHANCTX_EVENT_BEACON_PREPARE, so the P2P-GO
1290 * interface is guaranteed to be discoverable
1291 * for that duration after a TBTT.
1293 switch_time
= cur_conf
->beacon_interval
/ 4;
1295 ctwin
= avp
->vif
->bss_conf
.p2p_noa_attr
.oppps_ctwindow
;
1296 if (ctwin
&& (ctwin
< switch_time
))
1299 if (switch_time
< P2P_DEFAULT_CTWIN
)
1302 return P2P_DEFAULT_CTWIN
;
1305 void ath9k_beacon_add_noa(struct ath_softc
*sc
, struct ath_vif
*avp
,
1306 struct sk_buff
*skb
)
1308 static const u8 noa_ie_hdr
[] = {
1309 WLAN_EID_VENDOR_SPECIFIC
, /* type */
1311 0x50, 0x6f, 0x9a, /* WFA OUI */
1312 0x09, /* P2P subtype */
1313 0x0c, /* Notice of Absence */
1314 0x00, /* LSB of little-endian len */
1315 0x00, /* MSB of little-endian len */
1318 struct ieee80211_p2p_noa_attr
*noa
;
1319 int noa_len
, noa_desc
, i
= 0;
1322 if (!avp
->offchannel_duration
&& !avp
->noa_duration
)
1325 noa_desc
= !!avp
->offchannel_duration
+ !!avp
->noa_duration
;
1326 noa_len
= 2 + sizeof(struct ieee80211_p2p_noa_desc
) * noa_desc
;
1328 hdr
= skb_put(skb
, sizeof(noa_ie_hdr
));
1329 memcpy(hdr
, noa_ie_hdr
, sizeof(noa_ie_hdr
));
1330 hdr
[1] = sizeof(noa_ie_hdr
) + noa_len
- 2;
1333 noa
= (void *) skb_put(skb
, noa_len
);
1334 memset(noa
, 0, noa_len
);
1336 noa
->index
= avp
->noa_index
;
1337 noa
->oppps_ctwindow
= ath9k_get_ctwin(sc
, avp
);
1339 if (avp
->noa_duration
) {
1340 if (avp
->periodic_noa
) {
1341 u32 interval
= TU_TO_USEC(sc
->cur_chan
->beacon
.beacon_interval
);
1342 noa
->desc
[i
].count
= 255;
1343 noa
->desc
[i
].interval
= cpu_to_le32(interval
);
1345 noa
->desc
[i
].count
= 1;
1348 noa
->desc
[i
].start_time
= cpu_to_le32(avp
->noa_start
);
1349 noa
->desc
[i
].duration
= cpu_to_le32(avp
->noa_duration
);
1353 if (avp
->offchannel_duration
) {
1354 noa
->desc
[i
].count
= 1;
1355 noa
->desc
[i
].start_time
= cpu_to_le32(avp
->offchannel_start
);
1356 noa
->desc
[i
].duration
= cpu_to_le32(avp
->offchannel_duration
);
1360 void ath9k_p2p_ps_timer(void *priv
)
1362 struct ath_softc
*sc
= priv
;
1363 struct ath_vif
*avp
= sc
->p2p_ps_vif
;
1364 struct ieee80211_vif
*vif
;
1365 struct ieee80211_sta
*sta
;
1366 struct ath_node
*an
;
1369 del_timer_sync(&sc
->sched
.timer
);
1370 ath9k_hw_gen_timer_stop(sc
->sc_ah
, sc
->p2p_ps_timer
);
1371 ath_chanctx_event(sc
, NULL
, ATH_CHANCTX_EVENT_TSF_TIMER
);
1373 if (!avp
|| avp
->chanctx
!= sc
->cur_chan
)
1376 tsf
= ath9k_hw_gettsf32(sc
->sc_ah
);
1377 if (!avp
->noa
.absent
)
1378 tsf
+= ATH_P2P_PS_STOP_TIME
;
1380 if (!avp
->noa
.has_next_tsf
||
1381 avp
->noa
.next_tsf
- tsf
> BIT(31))
1382 ieee80211_update_p2p_noa(&avp
->noa
, tsf
);
1384 ath9k_update_p2p_ps_timer(sc
, avp
);
1389 sta
= ieee80211_find_sta(vif
, avp
->bssid
);
1393 an
= (void *) sta
->drv_priv
;
1394 if (an
->sleeping
== !!avp
->noa
.absent
)
1397 an
->sleeping
= avp
->noa
.absent
;
1399 ath_tx_aggr_sleep(sta
, sc
, an
);
1401 ath_tx_aggr_wakeup(sc
, an
);
1407 void ath9k_p2p_bss_info_changed(struct ath_softc
*sc
,
1408 struct ieee80211_vif
*vif
)
1410 unsigned long flags
;
1412 spin_lock_bh(&sc
->sc_pcu_lock
);
1413 spin_lock_irqsave(&sc
->sc_pm_lock
, flags
);
1414 if (!(sc
->ps_flags
& PS_BEACON_SYNC
))
1415 ath9k_update_p2p_ps(sc
, vif
);
1416 spin_unlock_irqrestore(&sc
->sc_pm_lock
, flags
);
1417 spin_unlock_bh(&sc
->sc_pcu_lock
);
1420 void ath9k_p2p_beacon_sync(struct ath_softc
*sc
)
1423 ath9k_update_p2p_ps(sc
, sc
->p2p_ps_vif
->vif
);
1426 void ath9k_p2p_remove_vif(struct ath_softc
*sc
,
1427 struct ieee80211_vif
*vif
)
1429 struct ath_vif
*avp
= (void *)vif
->drv_priv
;
1431 spin_lock_bh(&sc
->sc_pcu_lock
);
1432 if (avp
== sc
->p2p_ps_vif
) {
1433 sc
->p2p_ps_vif
= NULL
;
1434 ath9k_update_p2p_ps_timer(sc
, NULL
);
1436 spin_unlock_bh(&sc
->sc_pcu_lock
);
1439 int ath9k_init_p2p(struct ath_softc
*sc
)
1441 sc
->p2p_ps_timer
= ath_gen_timer_alloc(sc
->sc_ah
, ath9k_p2p_ps_timer
,
1442 NULL
, sc
, AR_FIRST_NDP_TIMER
);
1443 if (!sc
->p2p_ps_timer
)
1449 void ath9k_deinit_p2p(struct ath_softc
*sc
)
1451 if (sc
->p2p_ps_timer
)
1452 ath_gen_timer_free(sc
->sc_ah
, sc
->p2p_ps_timer
);
1455 #endif /* CONFIG_ATH9K_CHANNEL_CONTEXT */