2 * Copyright (c) 2008 Atheros Communications 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.
20 * This function will modify certain transmit queue properties depending on
21 * the operating mode of the station (AP or AdHoc). Parameters are AIFS
22 * settings and channel width min/max
24 static int ath_beaconq_config(struct ath_softc
*sc
)
26 struct ath_hw
*ah
= sc
->sc_ah
;
27 struct ath9k_tx_queue_info qi
;
29 ath9k_hw_get_txq_props(ah
, sc
->beacon
.beaconq
, &qi
);
30 if (sc
->sc_ah
->opmode
== NL80211_IFTYPE_AP
) {
31 /* Always burst out beacon and CAB traffic. */
36 /* Adhoc mode; important thing is to use 2x cwmin. */
37 qi
.tqi_aifs
= sc
->beacon
.beacon_qi
.tqi_aifs
;
38 qi
.tqi_cwmin
= 2*sc
->beacon
.beacon_qi
.tqi_cwmin
;
39 qi
.tqi_cwmax
= sc
->beacon
.beacon_qi
.tqi_cwmax
;
42 if (!ath9k_hw_set_txq_props(ah
, sc
->beacon
.beaconq
, &qi
)) {
43 DPRINTF(sc
, ATH_DBG_FATAL
,
44 "unable to update h/w beacon queue parameters\n");
47 ath9k_hw_resettxqueue(ah
, sc
->beacon
.beaconq
);
53 * Associates the beacon frame buffer with a transmit descriptor. Will set
54 * up all required antenna switch parameters, rate codes, and channel flags.
55 * Beacons are always sent out at the lowest rate, and are not retried.
57 static void ath_beacon_setup(struct ath_softc
*sc
, struct ath_vif
*avp
,
60 struct sk_buff
*skb
= (struct sk_buff
*)bf
->bf_mpdu
;
61 struct ath_hw
*ah
= sc
->sc_ah
;
63 struct ath9k_11n_rate_series series
[4];
64 struct ath_rate_table
*rt
;
65 int flags
, antenna
, ctsrate
= 0, ctsduration
= 0;
69 flags
= ATH9K_TXDESC_NOACK
;
71 if (sc
->sc_ah
->opmode
== NL80211_IFTYPE_ADHOC
&&
72 (ah
->caps
.hw_caps
& ATH9K_HW_CAP_VEOL
)) {
73 ds
->ds_link
= bf
->bf_daddr
; /* self-linked */
74 flags
|= ATH9K_TXDESC_VEOL
;
75 /* Let hardware handle antenna switching. */
80 * Switch antenna every beacon.
81 * Should only switch every beacon period, not for every SWBA
82 * XXX assumes two antennae
84 antenna
= ((sc
->beacon
.ast_be_xmit
/ sc
->nbcnvifs
) & 1 ? 2 : 1);
87 ds
->ds_data
= bf
->bf_buf_addr
;
89 rt
= sc
->cur_rate_table
;
90 rate
= rt
->info
[0].ratecode
;
91 if (sc
->sc_flags
& SC_OP_PREAMBLE_SHORT
)
92 rate
|= rt
->info
[0].short_preamble
;
94 ath9k_hw_set11n_txdesc(ah
, ds
, skb
->len
+ FCS_LEN
,
95 ATH9K_PKT_TYPE_BEACON
,
97 ATH9K_TXKEYIX_INVALID
,
101 /* NB: beacon's BufLen must be a multiple of 4 bytes */
102 ath9k_hw_filltxdesc(ah
, ds
, roundup(skb
->len
, 4),
105 memset(series
, 0, sizeof(struct ath9k_11n_rate_series
) * 4);
107 series
[0].Rate
= rate
;
108 series
[0].ChSel
= sc
->tx_chainmask
;
109 series
[0].RateFlags
= (ctsrate
) ? ATH9K_RATESERIES_RTS_CTS
: 0;
110 ath9k_hw_set11n_ratescenario(ah
, ds
, ds
, 0, ctsrate
, ctsduration
,
114 static struct ath_buf
*ath_beacon_generate(struct ath_softc
*sc
, int if_id
)
119 struct ath_txq
*cabq
;
120 struct ieee80211_vif
*vif
;
121 struct ieee80211_tx_info
*info
;
124 vif
= sc
->vifs
[if_id
];
125 avp
= (void *)vif
->drv_priv
;
126 cabq
= sc
->beacon
.cabq
;
128 if (avp
->av_bcbuf
== NULL
) {
129 DPRINTF(sc
, ATH_DBG_BEACON
, "avp=%p av_bcbuf=%p\n",
134 /* Release the old beacon first */
137 skb
= (struct sk_buff
*)bf
->bf_mpdu
;
139 dma_unmap_single(sc
->dev
, bf
->bf_dmacontext
,
140 skb
->len
, DMA_TO_DEVICE
);
141 dev_kfree_skb_any(skb
);
144 /* Get a new beacon from mac80211 */
146 skb
= ieee80211_beacon_get(sc
->hw
, vif
);
151 info
= IEEE80211_SKB_CB(skb
);
152 if (info
->flags
& IEEE80211_TX_CTL_ASSIGN_SEQ
) {
154 * TODO: make sure the seq# gets assigned properly (vs. other
157 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
158 sc
->tx
.seq_no
+= 0x10;
159 hdr
->seq_ctrl
&= cpu_to_le16(IEEE80211_SCTL_FRAG
);
160 hdr
->seq_ctrl
|= cpu_to_le16(sc
->tx
.seq_no
);
163 bf
->bf_buf_addr
= bf
->bf_dmacontext
=
164 dma_map_single(sc
->dev
, skb
->data
,
165 skb
->len
, DMA_TO_DEVICE
);
166 if (unlikely(dma_mapping_error(sc
->dev
, bf
->bf_buf_addr
))) {
167 dev_kfree_skb_any(skb
);
169 DPRINTF(sc
, ATH_DBG_FATAL
, "dma_mapping_error on beaconing\n");
173 skb
= ieee80211_get_buffered_bc(sc
->hw
, vif
);
176 * if the CABQ traffic from previous DTIM is pending and the current
177 * beacon is also a DTIM.
178 * 1) if there is only one vif let the cab traffic continue.
179 * 2) if there are more than one vif and we are using staggered
180 * beacons, then drain the cabq by dropping all the frames in
181 * the cabq so that the current vifs cab traffic can be scheduled.
183 spin_lock_bh(&cabq
->axq_lock
);
184 cabq_depth
= cabq
->axq_depth
;
185 spin_unlock_bh(&cabq
->axq_lock
);
187 if (skb
&& cabq_depth
) {
189 DPRINTF(sc
, ATH_DBG_BEACON
,
190 "Flushing previous cabq traffic\n");
191 ath_draintxq(sc
, cabq
, false);
195 ath_beacon_setup(sc
, avp
, bf
);
198 ath_tx_cabq(sc
, skb
);
199 skb
= ieee80211_get_buffered_bc(sc
->hw
, vif
);
206 * Startup beacon transmission for adhoc mode when they are sent entirely
207 * by the hardware using the self-linked descriptor + veol trick.
209 static void ath_beacon_start_adhoc(struct ath_softc
*sc
, int if_id
)
211 struct ieee80211_vif
*vif
;
212 struct ath_hw
*ah
= sc
->sc_ah
;
217 vif
= sc
->vifs
[if_id
];
218 avp
= (void *)vif
->drv_priv
;
220 if (avp
->av_bcbuf
== NULL
)
224 skb
= (struct sk_buff
*) bf
->bf_mpdu
;
226 ath_beacon_setup(sc
, avp
, bf
);
228 /* NB: caller is known to have already stopped tx dma */
229 ath9k_hw_puttxbuf(ah
, sc
->beacon
.beaconq
, bf
->bf_daddr
);
230 ath9k_hw_txstart(ah
, sc
->beacon
.beaconq
);
231 DPRINTF(sc
, ATH_DBG_BEACON
, "TXDP%u = %llx (%p)\n",
232 sc
->beacon
.beaconq
, ito64(bf
->bf_daddr
), bf
->bf_desc
);
235 int ath_beaconq_setup(struct ath_hw
*ah
)
237 struct ath9k_tx_queue_info qi
;
239 memset(&qi
, 0, sizeof(qi
));
243 /* NB: don't enable any interrupts */
244 return ath9k_hw_setuptxqueue(ah
, ATH9K_TX_QUEUE_BEACON
, &qi
);
247 int ath_beacon_alloc(struct ath_softc
*sc
, int if_id
)
249 struct ieee80211_vif
*vif
;
251 struct ieee80211_hdr
*hdr
;
256 vif
= sc
->vifs
[if_id
];
257 avp
= (void *)vif
->drv_priv
;
259 /* Allocate a beacon descriptor if we haven't done so. */
260 if (!avp
->av_bcbuf
) {
261 /* Allocate beacon state for hostap/ibss. We know
262 * a buffer is available. */
263 avp
->av_bcbuf
= list_first_entry(&sc
->beacon
.bbuf
,
264 struct ath_buf
, list
);
265 list_del(&avp
->av_bcbuf
->list
);
267 if (sc
->sc_ah
->opmode
== NL80211_IFTYPE_AP
||
268 !(sc
->sc_ah
->caps
.hw_caps
& ATH9K_HW_CAP_VEOL
)) {
271 * Assign the vif to a beacon xmit slot. As
272 * above, this cannot fail to find one.
275 for (slot
= 0; slot
< ATH_BCBUF
; slot
++)
276 if (sc
->beacon
.bslot
[slot
] == ATH_IF_ID_ANY
) {
278 * XXX hack, space out slots to better
281 if (slot
+1 < ATH_BCBUF
&&
282 sc
->beacon
.bslot
[slot
+1] ==
284 avp
->av_bslot
= slot
+1;
287 avp
->av_bslot
= slot
;
288 /* NB: keep looking for a double slot */
290 BUG_ON(sc
->beacon
.bslot
[avp
->av_bslot
] != ATH_IF_ID_ANY
);
291 sc
->beacon
.bslot
[avp
->av_bslot
] = if_id
;
296 /* release the previous beacon frame, if it already exists. */
298 if (bf
->bf_mpdu
!= NULL
) {
299 skb
= (struct sk_buff
*)bf
->bf_mpdu
;
300 dma_unmap_single(sc
->dev
, bf
->bf_dmacontext
,
301 skb
->len
, DMA_TO_DEVICE
);
302 dev_kfree_skb_any(skb
);
306 /* NB: the beacon data buffer must be 32-bit aligned. */
307 skb
= ieee80211_beacon_get(sc
->hw
, vif
);
309 DPRINTF(sc
, ATH_DBG_BEACON
, "cannot get skb\n");
313 tstamp
= ((struct ieee80211_mgmt
*)skb
->data
)->u
.beacon
.timestamp
;
314 sc
->beacon
.bc_tstamp
= le64_to_cpu(tstamp
);
317 * Calculate a TSF adjustment factor required for
318 * staggered beacons. Note that we assume the format
319 * of the beacon frame leaves the tstamp field immediately
320 * following the header.
322 if (avp
->av_bslot
> 0) {
327 intval
= sc
->hw
->conf
.beacon_int
?
328 sc
->hw
->conf
.beacon_int
: ATH_DEFAULT_BINTVAL
;
331 * The beacon interval is in TU's; the TSF in usecs.
332 * We figure out how many TU's to add to align the
333 * timestamp then convert to TSF units and handle
334 * byte swapping before writing it in the frame.
335 * The hardware will then add this each time a beacon
336 * frame is sent. Note that we align vif's 1..N
337 * and leave vif 0 untouched. This means vap 0
338 * has a timestamp in one beacon interval while the
339 * others get a timestamp aligned to the next interval.
341 tsfadjust
= (intval
* (ATH_BCBUF
- avp
->av_bslot
)) / ATH_BCBUF
;
342 val
= cpu_to_le64(tsfadjust
<< 10); /* TU->TSF */
344 DPRINTF(sc
, ATH_DBG_BEACON
,
345 "stagger beacons, bslot %d intval %u tsfadjust %llu\n",
346 avp
->av_bslot
, intval
, (unsigned long long)tsfadjust
);
348 hdr
= (struct ieee80211_hdr
*)skb
->data
;
349 memcpy(&hdr
[1], &val
, sizeof(val
));
353 bf
->bf_buf_addr
= bf
->bf_dmacontext
=
354 dma_map_single(sc
->dev
, skb
->data
,
355 skb
->len
, DMA_TO_DEVICE
);
356 if (unlikely(dma_mapping_error(sc
->dev
, bf
->bf_buf_addr
))) {
357 dev_kfree_skb_any(skb
);
359 DPRINTF(sc
, ATH_DBG_FATAL
,
360 "dma_mapping_error on beacon alloc\n");
367 void ath_beacon_return(struct ath_softc
*sc
, struct ath_vif
*avp
)
369 if (avp
->av_bcbuf
!= NULL
) {
372 if (avp
->av_bslot
!= -1) {
373 sc
->beacon
.bslot
[avp
->av_bslot
] = ATH_IF_ID_ANY
;
378 if (bf
->bf_mpdu
!= NULL
) {
379 struct sk_buff
*skb
= (struct sk_buff
*)bf
->bf_mpdu
;
380 dma_unmap_single(sc
->dev
, bf
->bf_dmacontext
,
381 skb
->len
, DMA_TO_DEVICE
);
382 dev_kfree_skb_any(skb
);
385 list_add_tail(&bf
->list
, &sc
->beacon
.bbuf
);
387 avp
->av_bcbuf
= NULL
;
391 void ath_beacon_tasklet(unsigned long data
)
393 struct ath_softc
*sc
= (struct ath_softc
*)data
;
394 struct ath_hw
*ah
= sc
->sc_ah
;
395 struct ath_buf
*bf
= NULL
;
397 u32 bfaddr
, bc
= 0, tsftu
;
402 * Check if the previous beacon has gone out. If
403 * not don't try to post another, skip this period
404 * and wait for the next. Missed beacons indicate
405 * a problem and should not occur. If we miss too
406 * many consecutive beacons reset the device.
408 if (ath9k_hw_numtxpending(ah
, sc
->beacon
.beaconq
) != 0) {
409 sc
->beacon
.bmisscnt
++;
411 if (sc
->beacon
.bmisscnt
< BSTUCK_THRESH
) {
412 DPRINTF(sc
, ATH_DBG_BEACON
,
413 "missed %u consecutive beacons\n",
414 sc
->beacon
.bmisscnt
);
415 } else if (sc
->beacon
.bmisscnt
>= BSTUCK_THRESH
) {
416 DPRINTF(sc
, ATH_DBG_BEACON
,
417 "beacon is officially stuck\n");
418 ath_reset(sc
, false);
424 if (sc
->beacon
.bmisscnt
!= 0) {
425 DPRINTF(sc
, ATH_DBG_BEACON
,
426 "resume beacon xmit after %u misses\n",
427 sc
->beacon
.bmisscnt
);
428 sc
->beacon
.bmisscnt
= 0;
432 * Generate beacon frames. we are sending frames
433 * staggered so calculate the slot for this frame based
434 * on the tsf to safeguard against missing an swba.
437 intval
= sc
->hw
->conf
.beacon_int
?
438 sc
->hw
->conf
.beacon_int
: ATH_DEFAULT_BINTVAL
;
440 tsf
= ath9k_hw_gettsf64(ah
);
441 tsftu
= TSF_TO_TU(tsf
>>32, tsf
);
442 slot
= ((tsftu
% intval
) * ATH_BCBUF
) / intval
;
443 if_id
= sc
->beacon
.bslot
[(slot
+ 1) % ATH_BCBUF
];
445 DPRINTF(sc
, ATH_DBG_BEACON
,
446 "slot %d [tsf %llu tsftu %u intval %u] if_id %d\n",
447 slot
, tsf
, tsftu
, intval
, if_id
);
450 if (if_id
!= ATH_IF_ID_ANY
) {
451 bf
= ath_beacon_generate(sc
, if_id
);
453 bfaddr
= bf
->bf_daddr
;
459 * Handle slot time change when a non-ERP station joins/leaves
460 * an 11g network. The 802.11 layer notifies us via callback,
461 * we mark updateslot, then wait one beacon before effecting
462 * the change. This gives associated stations at least one
463 * beacon interval to note the state change.
465 * NB: The slot time change state machine is clocked according
466 * to whether we are bursting or staggering beacons. We
467 * recognize the request to update and record the current
468 * slot then don't transition until that slot is reached
469 * again. If we miss a beacon for that slot then we'll be
470 * slow to transition but we'll be sure at least one beacon
471 * interval has passed. When bursting slot is always left
472 * set to ATH_BCBUF so this check is a noop.
474 if (sc
->beacon
.updateslot
== UPDATE
) {
475 sc
->beacon
.updateslot
= COMMIT
; /* commit next beacon */
476 sc
->beacon
.slotupdate
= slot
;
477 } else if (sc
->beacon
.updateslot
== COMMIT
&& sc
->beacon
.slotupdate
== slot
) {
478 ath9k_hw_setslottime(sc
->sc_ah
, sc
->beacon
.slottime
);
479 sc
->beacon
.updateslot
= OK
;
483 * Stop any current dma and put the new frame(s) on the queue.
484 * This should never fail since we check above that no frames
485 * are still pending on the queue.
487 if (!ath9k_hw_stoptxdma(ah
, sc
->beacon
.beaconq
)) {
488 DPRINTF(sc
, ATH_DBG_FATAL
,
489 "beacon queue %u did not stop?\n", sc
->beacon
.beaconq
);
492 /* NB: cabq traffic should already be queued and primed */
493 ath9k_hw_puttxbuf(ah
, sc
->beacon
.beaconq
, bfaddr
);
494 ath9k_hw_txstart(ah
, sc
->beacon
.beaconq
);
496 sc
->beacon
.ast_be_xmit
+= bc
; /* XXX per-vif? */
501 * Configure the beacon and sleep timers.
503 * When operating as an AP this resets the TSF and sets
504 * up the hardware to notify us when we need to issue beacons.
506 * When operating in station mode this sets up the beacon
507 * timers according to the timestamp of the last received
508 * beacon and the current TSF, configures PCF and DTIM
509 * handling, programs the sleep registers so the hardware
510 * will wakeup in time to receive beacons, and configures
511 * the beacon miss handling so we'll receive a BMISS
512 * interrupt when we stop seeing beacons from the AP
513 * we've associated with.
515 void ath_beacon_config(struct ath_softc
*sc
, int if_id
)
517 struct ieee80211_vif
*vif
;
518 struct ath_hw
*ah
= sc
->sc_ah
;
519 struct ath_beacon_config conf
;
521 enum nl80211_iftype opmode
;
522 u32 nexttbtt
, intval
;
524 if (if_id
!= ATH_IF_ID_ANY
) {
525 vif
= sc
->vifs
[if_id
];
526 avp
= (void *)vif
->drv_priv
;
527 opmode
= avp
->av_opmode
;
529 opmode
= sc
->sc_ah
->opmode
;
532 memset(&conf
, 0, sizeof(struct ath_beacon_config
));
534 conf
.beacon_interval
= sc
->hw
->conf
.beacon_int
?
535 sc
->hw
->conf
.beacon_int
: ATH_DEFAULT_BINTVAL
;
536 conf
.listen_interval
= 1;
537 conf
.dtim_period
= conf
.beacon_interval
;
539 conf
.bmiss_timeout
= ATH_DEFAULT_BMISS_LIMIT
* conf
.beacon_interval
;
541 /* extract tstamp from last beacon and convert to TU */
542 nexttbtt
= TSF_TO_TU(sc
->beacon
.bc_tstamp
>> 32, sc
->beacon
.bc_tstamp
);
544 /* XXX conditionalize multi-bss support? */
545 if (sc
->sc_ah
->opmode
== NL80211_IFTYPE_AP
) {
547 * For multi-bss ap support beacons are either staggered
548 * evenly over N slots or burst together. For the former
549 * arrange for the SWBA to be delivered for each slot.
550 * Slots that are not occupied will generate nothing.
552 /* NB: the beacon interval is kept internally in TU's */
553 intval
= conf
.beacon_interval
& ATH9K_BEACON_PERIOD
;
554 intval
/= ATH_BCBUF
; /* for staggered beacons */
556 intval
= conf
.beacon_interval
& ATH9K_BEACON_PERIOD
;
559 if (nexttbtt
== 0) /* e.g. for ap mode */
561 else if (intval
) /* NB: can be 0 for monitor mode */
562 nexttbtt
= roundup(nexttbtt
, intval
);
564 DPRINTF(sc
, ATH_DBG_BEACON
, "nexttbtt %u intval %u (%u)\n",
565 nexttbtt
, intval
, conf
.beacon_interval
);
567 /* Check for NL80211_IFTYPE_AP and sc_nostabeacons for WDS client */
568 if (sc
->sc_ah
->opmode
== NL80211_IFTYPE_STATION
) {
569 struct ath9k_beacon_state bs
;
572 int dtimperiod
, dtimcount
, sleepduration
;
573 int cfpperiod
, cfpcount
;
576 * Setup dtim and cfp parameters according to
577 * last beacon we received (which may be none).
579 dtimperiod
= conf
.dtim_period
;
580 if (dtimperiod
<= 0) /* NB: 0 if not known */
582 dtimcount
= conf
.dtim_count
;
583 if (dtimcount
>= dtimperiod
) /* NB: sanity check */
585 cfpperiod
= 1; /* NB: no PCF support yet */
588 sleepduration
= conf
.listen_interval
* intval
;
589 if (sleepduration
<= 0)
590 sleepduration
= intval
;
594 * Pull nexttbtt forward to reflect the current
595 * TSF and calculate dtim+cfp state for the result.
597 tsf
= ath9k_hw_gettsf64(ah
);
598 tsftu
= TSF_TO_TU(tsf
>>32, tsf
) + FUDGE
;
601 if (--dtimcount
< 0) {
602 dtimcount
= dtimperiod
- 1;
604 cfpcount
= cfpperiod
- 1;
606 } while (nexttbtt
< tsftu
);
608 memset(&bs
, 0, sizeof(bs
));
609 bs
.bs_intval
= intval
;
610 bs
.bs_nexttbtt
= nexttbtt
;
611 bs
.bs_dtimperiod
= dtimperiod
*intval
;
612 bs
.bs_nextdtim
= bs
.bs_nexttbtt
+ dtimcount
*intval
;
613 bs
.bs_cfpperiod
= cfpperiod
*bs
.bs_dtimperiod
;
614 bs
.bs_cfpnext
= bs
.bs_nextdtim
+ cfpcount
*bs
.bs_dtimperiod
;
615 bs
.bs_cfpmaxduration
= 0;
618 * Calculate the number of consecutive beacons to miss
619 * before taking a BMISS interrupt. The configuration
620 * is specified in TU so we only need calculate based
621 * on the beacon interval. Note that we clamp the
622 * result to at most 15 beacons.
624 if (sleepduration
> intval
) {
625 bs
.bs_bmissthreshold
= conf
.listen_interval
*
626 ATH_DEFAULT_BMISS_LIMIT
/ 2;
628 bs
.bs_bmissthreshold
=
629 DIV_ROUND_UP(conf
.bmiss_timeout
, intval
);
630 if (bs
.bs_bmissthreshold
> 15)
631 bs
.bs_bmissthreshold
= 15;
632 else if (bs
.bs_bmissthreshold
<= 0)
633 bs
.bs_bmissthreshold
= 1;
637 * Calculate sleep duration. The configuration is
638 * given in ms. We insure a multiple of the beacon
639 * period is used. Also, if the sleep duration is
640 * greater than the DTIM period then it makes senses
641 * to make it a multiple of that.
646 bs
.bs_sleepduration
= roundup(IEEE80211_MS_TO_TU(100),
648 if (bs
.bs_sleepduration
> bs
.bs_dtimperiod
)
649 bs
.bs_sleepduration
= bs
.bs_dtimperiod
;
651 /* TSF out of range threshold fixed at 1 second */
652 bs
.bs_tsfoor_threshold
= ATH9K_TSFOOR_THRESHOLD
;
654 DPRINTF(sc
, ATH_DBG_BEACON
,
655 "tsf: %llu tsftu: %u\n", tsf
, tsftu
);
656 DPRINTF(sc
, ATH_DBG_BEACON
,
657 "bmiss: %u sleep: %u cfp-period: %u maxdur: %u next: %u\n",
658 bs
.bs_bmissthreshold
, bs
.bs_sleepduration
,
659 bs
.bs_cfpperiod
, bs
.bs_cfpmaxduration
, bs
.bs_cfpnext
);
661 ath9k_hw_set_interrupts(ah
, 0);
662 ath9k_hw_set_sta_beacon_timers(ah
, &bs
);
663 sc
->imask
|= ATH9K_INT_BMISS
;
664 ath9k_hw_set_interrupts(ah
, sc
->imask
);
669 ath9k_hw_set_interrupts(ah
, 0);
670 if (sc
->sc_ah
->opmode
== NL80211_IFTYPE_ADHOC
) {
671 /* Pull nexttbtt forward to reflect the current TSF */
673 if (!(intval
& ATH9K_BEACON_RESET_TSF
)) {
674 tsf
= ath9k_hw_gettsf64(ah
);
675 tsftu
= TSF_TO_TU((u32
)(tsf
>>32),
679 } while (nexttbtt
< tsftu
);
682 DPRINTF(sc
, ATH_DBG_BEACON
,
683 "IBSS nexttbtt %u intval %u (%u)\n",
684 nexttbtt
, intval
& ~ATH9K_BEACON_RESET_TSF
,
685 conf
.beacon_interval
);
688 * In IBSS mode enable the beacon timers but only
689 * enable SWBA interrupts if we need to manually
690 * prepare beacon frames. Otherwise we use a
691 * self-linked tx descriptor and let the hardware
694 intval
|= ATH9K_BEACON_ENA
;
695 if (!(ah
->caps
.hw_caps
& ATH9K_HW_CAP_VEOL
))
696 sc
->imask
|= ATH9K_INT_SWBA
;
697 ath_beaconq_config(sc
);
698 } else if (sc
->sc_ah
->opmode
== NL80211_IFTYPE_AP
) {
699 if (nexttbtt
== intval
)
700 intval
|= ATH9K_BEACON_RESET_TSF
;
702 * In AP mode we enable the beacon timers and
703 * SWBA interrupts to prepare beacon frames.
705 intval
|= ATH9K_BEACON_ENA
;
706 sc
->imask
|= ATH9K_INT_SWBA
;
707 ath_beaconq_config(sc
);
710 ath9k_hw_beaconinit(ah
, nexttbtt
, intval
);
711 sc
->beacon
.bmisscnt
= 0;
712 ath9k_hw_set_interrupts(ah
, sc
->imask
);
715 * When using a self-linked beacon descriptor in
716 * ibss mode load it once here.
718 if (sc
->sc_ah
->opmode
== NL80211_IFTYPE_ADHOC
&&
719 (ah
->caps
.hw_caps
& ATH9K_HW_CAP_VEOL
))
720 ath_beacon_start_adhoc(sc
, 0);
724 void ath_beacon_sync(struct ath_softc
*sc
, int if_id
)
727 * Resync beacon timers using the tsf of the
728 * beacon frame we just received.
730 ath_beacon_config(sc
, if_id
);
731 sc
->sc_flags
|= SC_OP_BEACONS
;