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_hal *ah = sc->sc_ah;
27 struct ath9k_tx_queue_info qi;
29 ath9k_hw_get_txq_props(ah, sc->sc_bhalq, &qi);
30 if (sc->sc_ah->ah_opmode == ATH9K_M_HOSTAP) {
31 /* Always burst out beacon and CAB traffic. */
36 /* Adhoc mode; important thing is to use 2x cwmin. */
37 qi.tqi_aifs = sc->sc_beacon_qi.tqi_aifs;
38 qi.tqi_cwmin = 2*sc->sc_beacon_qi.tqi_cwmin;
39 qi.tqi_cwmax = sc->sc_beacon_qi.tqi_cwmax;
42 if (!ath9k_hw_set_txq_props(ah, sc->sc_bhalq, &qi)) {
43 DPRINTF(sc, ATH_DBG_FATAL,
44 "%s: unable to update h/w beacon queue parameters\n",
48 ath9k_hw_resettxqueue(ah, sc->sc_bhalq); /* push to h/w */
53 static void ath_bstuck_process(struct ath_softc *sc)
55 DPRINTF(sc, ATH_DBG_BEACON,
56 "%s: stuck beacon; resetting (bmiss count %u)\n",
57 __func__, sc->sc_bmisscount);
62 * Associates the beacon frame buffer with a transmit descriptor. Will set
63 * up all required antenna switch parameters, rate codes, and channel flags.
64 * Beacons are always sent out at the lowest rate, and are not retried.
66 static void ath_beacon_setup(struct ath_softc *sc,
67 struct ath_vap *avp, struct ath_buf *bf)
69 struct sk_buff *skb = (struct sk_buff *)bf->bf_mpdu;
70 struct ath_hal *ah = sc->sc_ah;
72 struct ath9k_11n_rate_series series[4];
73 struct ath_rate_table *rt;
79 DPRINTF(sc, ATH_DBG_BEACON, "%s: m %p len %u\n",
80 __func__, skb, skb->len);
82 /* setup descriptors */
85 flags = ATH9K_TXDESC_NOACK;
87 if (sc->sc_ah->ah_opmode == ATH9K_M_IBSS &&
88 (ah->ah_caps.hw_caps & ATH9K_HW_CAP_VEOL)) {
89 ds->ds_link = bf->bf_daddr; /* self-linked */
90 flags |= ATH9K_TXDESC_VEOL;
91 /* Let hardware handle antenna switching. */
96 * Switch antenna every beacon.
97 * Should only switch every beacon period, not for every
99 * XXX assumes two antenna
101 antenna = ((sc->ast_be_xmit / sc->sc_nbcnvaps) & 1 ? 2 : 1);
104 ds->ds_data = bf->bf_buf_addr;
107 * Calculate rate code.
108 * XXX everything at min xmit rate
111 rt = sc->hw_rate_table[sc->sc_curmode];
112 rate = rt->info[rix].ratecode;
113 if (sc->sc_flags & SC_OP_PREAMBLE_SHORT)
114 rate |= rt->info[rix].short_preamble;
116 ath9k_hw_set11n_txdesc(ah, ds,
117 skb->len + FCS_LEN, /* frame length */
118 ATH9K_PKT_TYPE_BEACON, /* Atheros packet type */
119 MAX_RATE_POWER, /* FIXME */
120 ATH9K_TXKEYIX_INVALID, /* no encryption */
121 ATH9K_KEY_TYPE_CLEAR, /* no encryption */
126 /* NB: beacon's BufLen must be a multiple of 4 bytes */
127 ath9k_hw_filltxdesc(ah, ds,
128 roundup(skb->len, 4), /* buffer length */
129 true, /* first segment */
130 true, /* last segment */
131 ds /* first descriptor */
134 memset(series, 0, sizeof(struct ath9k_11n_rate_series) * 4);
136 series[0].Rate = rate;
137 series[0].ChSel = sc->sc_tx_chainmask;
138 series[0].RateFlags = (ctsrate) ? ATH9K_RATESERIES_RTS_CTS : 0;
139 ath9k_hw_set11n_ratescenario(ah, ds, ds, 0,
140 ctsrate, ctsduration, series, 4, 0);
143 /* Generate beacon frame and queue cab data for a vap */
144 static struct ath_buf *ath_beacon_generate(struct ath_softc *sc, int if_id)
149 struct ath_txq *cabq;
150 struct ieee80211_vif *vif;
151 struct ieee80211_tx_info *info;
154 vif = sc->sc_vaps[if_id];
157 avp = (void *)vif->drv_priv;
160 if (avp->av_bcbuf == NULL) {
161 DPRINTF(sc, ATH_DBG_BEACON, "%s: avp=%p av_bcbuf=%p\n",
162 __func__, avp, avp->av_bcbuf);
167 skb = (struct sk_buff *)bf->bf_mpdu;
169 pci_unmap_single(sc->pdev, bf->bf_dmacontext,
170 skb_end_pointer(skb) - skb->head,
174 skb = ieee80211_beacon_get(sc->hw, vif);
179 info = IEEE80211_SKB_CB(skb);
180 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
182 * TODO: make sure the seq# gets assigned properly (vs. other
185 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
187 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
188 hdr->seq_ctrl |= cpu_to_le16(sc->seq_no);
191 bf->bf_buf_addr = bf->bf_dmacontext =
192 pci_map_single(sc->pdev, skb->data,
193 skb_end_pointer(skb) - skb->head,
196 skb = ieee80211_get_buffered_bc(sc->hw, vif);
199 * if the CABQ traffic from previous DTIM is pending and the current
200 * beacon is also a DTIM.
201 * 1) if there is only one vap let the cab traffic continue.
202 * 2) if there are more than one vap and we are using staggered
203 * beacons, then drain the cabq by dropping all the frames in
204 * the cabq so that the current vaps cab traffic can be scheduled.
206 spin_lock_bh(&cabq->axq_lock);
207 cabq_depth = cabq->axq_depth;
208 spin_unlock_bh(&cabq->axq_lock);
210 if (skb && cabq_depth) {
212 * Unlock the cabq lock as ath_tx_draintxq acquires
213 * the lock again which is a common function and that
214 * acquires txq lock inside.
216 if (sc->sc_nvaps > 1) {
217 ath_tx_draintxq(sc, cabq, false);
218 DPRINTF(sc, ATH_DBG_BEACON,
219 "%s: flush previous cabq traffic\n", __func__);
223 /* Construct tx descriptor. */
224 ath_beacon_setup(sc, avp, bf);
227 * Enable the CAB queue before the beacon queue to
228 * insure cab frames are triggered by this beacon.
231 ath_tx_cabq(sc, skb);
232 skb = ieee80211_get_buffered_bc(sc->hw, vif);
239 * Startup beacon transmission for adhoc mode when they are sent entirely
240 * by the hardware using the self-linked descriptor + veol trick.
242 static void ath_beacon_start_adhoc(struct ath_softc *sc, int if_id)
244 struct ieee80211_vif *vif;
245 struct ath_hal *ah = sc->sc_ah;
250 vif = sc->sc_vaps[if_id];
253 avp = (void *)vif->drv_priv;
255 if (avp->av_bcbuf == NULL) {
256 DPRINTF(sc, ATH_DBG_BEACON, "%s: avp=%p av_bcbuf=%p\n",
257 __func__, avp, avp != NULL ? avp->av_bcbuf : NULL);
261 skb = (struct sk_buff *) bf->bf_mpdu;
263 /* Construct tx descriptor. */
264 ath_beacon_setup(sc, avp, bf);
266 /* NB: caller is known to have already stopped tx dma */
267 ath9k_hw_puttxbuf(ah, sc->sc_bhalq, bf->bf_daddr);
268 ath9k_hw_txstart(ah, sc->sc_bhalq);
269 DPRINTF(sc, ATH_DBG_BEACON, "%s: TXDP%u = %llx (%p)\n", __func__,
270 sc->sc_bhalq, ito64(bf->bf_daddr), bf->bf_desc);
273 int ath_beaconq_setup(struct ath_hal *ah)
275 struct ath9k_tx_queue_info qi;
277 memset(&qi, 0, sizeof(qi));
281 /* NB: don't enable any interrupts */
282 return ath9k_hw_setuptxqueue(ah, ATH9K_TX_QUEUE_BEACON, &qi);
285 int ath_beacon_alloc(struct ath_softc *sc, int if_id)
287 struct ieee80211_vif *vif;
289 struct ieee80211_hdr *hdr;
294 vif = sc->sc_vaps[if_id];
297 avp = (void *)vif->drv_priv;
299 /* Allocate a beacon descriptor if we haven't done so. */
300 if (!avp->av_bcbuf) {
301 /* Allocate beacon state for hostap/ibss. We know
302 * a buffer is available. */
303 avp->av_bcbuf = list_first_entry(&sc->sc_bbuf,
304 struct ath_buf, list);
305 list_del(&avp->av_bcbuf->list);
307 if (sc->sc_ah->ah_opmode == ATH9K_M_HOSTAP ||
308 !(sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_VEOL)) {
311 * Assign the vap to a beacon xmit slot. As
312 * above, this cannot fail to find one.
315 for (slot = 0; slot < ATH_BCBUF; slot++)
316 if (sc->sc_bslot[slot] == ATH_IF_ID_ANY) {
318 * XXX hack, space out slots to better
321 if (slot+1 < ATH_BCBUF &&
322 sc->sc_bslot[slot+1] ==
324 avp->av_bslot = slot+1;
327 avp->av_bslot = slot;
328 /* NB: keep looking for a double slot */
330 BUG_ON(sc->sc_bslot[avp->av_bslot] != ATH_IF_ID_ANY);
331 sc->sc_bslot[avp->av_bslot] = if_id;
336 /* release the previous beacon frame , if it already exists. */
338 if (bf->bf_mpdu != NULL) {
339 skb = (struct sk_buff *)bf->bf_mpdu;
340 pci_unmap_single(sc->pdev, bf->bf_dmacontext,
341 skb_end_pointer(skb) - skb->head,
343 dev_kfree_skb_any(skb);
348 * NB: the beacon data buffer must be 32-bit aligned.
349 * FIXME: Fill avp->av_btxctl.txpower and
350 * avp->av_btxctl.shortPreamble
352 skb = ieee80211_beacon_get(sc->hw, vif);
354 DPRINTF(sc, ATH_DBG_BEACON, "%s: cannot get skb\n",
359 tstamp = ((struct ieee80211_mgmt *)skb->data)->u.beacon.timestamp;
360 sc->bc_tstamp = le64_to_cpu(tstamp);
363 * Calculate a TSF adjustment factor required for
364 * staggered beacons. Note that we assume the format
365 * of the beacon frame leaves the tstamp field immediately
366 * following the header.
368 if (avp->av_bslot > 0) {
373 intval = sc->hw->conf.beacon_int ?
374 sc->hw->conf.beacon_int : ATH_DEFAULT_BINTVAL;
377 * The beacon interval is in TU's; the TSF in usecs.
378 * We figure out how many TU's to add to align the
379 * timestamp then convert to TSF units and handle
380 * byte swapping before writing it in the frame.
381 * The hardware will then add this each time a beacon
382 * frame is sent. Note that we align vap's 1..N
383 * and leave vap 0 untouched. This means vap 0
384 * has a timestamp in one beacon interval while the
385 * others get a timestamp aligned to the next interval.
387 tsfadjust = (intval * (ATH_BCBUF - avp->av_bslot)) / ATH_BCBUF;
388 val = cpu_to_le64(tsfadjust << 10); /* TU->TSF */
390 DPRINTF(sc, ATH_DBG_BEACON,
391 "%s: %s beacons, bslot %d intval %u tsfadjust %llu\n",
393 avp->av_bslot, intval, (unsigned long long)tsfadjust);
395 hdr = (struct ieee80211_hdr *)skb->data;
396 memcpy(&hdr[1], &val, sizeof(val));
399 bf->bf_buf_addr = bf->bf_dmacontext =
400 pci_map_single(sc->pdev, skb->data,
401 skb_end_pointer(skb) - skb->head,
408 void ath_beacon_return(struct ath_softc *sc, struct ath_vap *avp)
410 if (avp->av_bcbuf != NULL) {
413 if (avp->av_bslot != -1) {
414 sc->sc_bslot[avp->av_bslot] = ATH_IF_ID_ANY;
419 if (bf->bf_mpdu != NULL) {
420 struct sk_buff *skb = (struct sk_buff *)bf->bf_mpdu;
421 pci_unmap_single(sc->pdev, bf->bf_dmacontext,
422 skb_end_pointer(skb) - skb->head,
424 dev_kfree_skb_any(skb);
427 list_add_tail(&bf->list, &sc->sc_bbuf);
429 avp->av_bcbuf = NULL;
433 void ath9k_beacon_tasklet(unsigned long data)
435 struct ath_softc *sc = (struct ath_softc *)data;
436 struct ath_hal *ah = sc->sc_ah;
437 struct ath_buf *bf = NULL;
440 u32 rx_clear = 0, rx_frame = 0, tx_frame = 0;
442 u32 bc = 0; /* beacon count */
447 if (sc->sc_flags & SC_OP_NO_RESET) {
448 show_cycles = ath9k_hw_GetMibCycleCountsPct(ah,
449 &rx_clear, &rx_frame, &tx_frame);
453 * Check if the previous beacon has gone out. If
454 * not don't try to post another, skip this period
455 * and wait for the next. Missed beacons indicate
456 * a problem and should not occur. If we miss too
457 * many consecutive beacons reset the device.
459 * FIXME: Clean up this mess !!
461 if (ath9k_hw_numtxpending(ah, sc->sc_bhalq) != 0) {
463 /* XXX: doth needs the chanchange IE countdown decremented.
464 * We should consider adding a mac80211 call to indicate
465 * a beacon miss so appropriate action could be taken
468 if (sc->sc_bmisscount < BSTUCK_THRESH) {
469 if (sc->sc_flags & SC_OP_NO_RESET) {
470 DPRINTF(sc, ATH_DBG_BEACON,
471 "%s: missed %u consecutive beacons\n",
472 __func__, sc->sc_bmisscount);
475 * Display cycle counter stats from HW
476 * to aide in debug of stickiness.
478 DPRINTF(sc, ATH_DBG_BEACON,
479 "%s: busy times: rx_clear=%d, "
480 "rx_frame=%d, tx_frame=%d\n",
481 __func__, rx_clear, rx_frame,
484 DPRINTF(sc, ATH_DBG_BEACON,
485 "%s: unable to obtain "
486 "busy times\n", __func__);
489 DPRINTF(sc, ATH_DBG_BEACON,
490 "%s: missed %u consecutive beacons\n",
491 __func__, sc->sc_bmisscount);
493 } else if (sc->sc_bmisscount >= BSTUCK_THRESH) {
494 if (sc->sc_flags & SC_OP_NO_RESET) {
495 if (sc->sc_bmisscount == BSTUCK_THRESH) {
496 DPRINTF(sc, ATH_DBG_BEACON,
497 "%s: beacon is officially "
498 "stuck\n", __func__);
499 ath9k_hw_dmaRegDump(ah);
502 DPRINTF(sc, ATH_DBG_BEACON,
503 "%s: beacon is officially stuck\n",
505 ath_bstuck_process(sc);
511 if (sc->sc_bmisscount != 0) {
512 if (sc->sc_flags & SC_OP_NO_RESET) {
513 DPRINTF(sc, ATH_DBG_BEACON,
514 "%s: resume beacon xmit after %u misses\n",
515 __func__, sc->sc_bmisscount);
517 DPRINTF(sc, ATH_DBG_BEACON,
518 "%s: resume beacon xmit after %u misses\n",
519 __func__, sc->sc_bmisscount);
521 sc->sc_bmisscount = 0;
525 * Generate beacon frames. we are sending frames
526 * staggered so calculate the slot for this frame based
527 * on the tsf to safeguard against missing an swba.
530 intval = sc->hw->conf.beacon_int ?
531 sc->hw->conf.beacon_int : ATH_DEFAULT_BINTVAL;
533 tsf = ath9k_hw_gettsf64(ah);
534 tsftu = TSF_TO_TU(tsf>>32, tsf);
535 slot = ((tsftu % intval) * ATH_BCBUF) / intval;
536 if_id = sc->sc_bslot[(slot + 1) % ATH_BCBUF];
538 DPRINTF(sc, ATH_DBG_BEACON,
539 "%s: slot %d [tsf %llu tsftu %u intval %u] if_id %d\n",
540 __func__, slot, (unsigned long long)tsf, tsftu,
544 if (if_id != ATH_IF_ID_ANY) {
545 bf = ath_beacon_generate(sc, if_id);
547 bfaddr = bf->bf_daddr;
552 * Handle slot time change when a non-ERP station joins/leaves
553 * an 11g network. The 802.11 layer notifies us via callback,
554 * we mark updateslot, then wait one beacon before effecting
555 * the change. This gives associated stations at least one
556 * beacon interval to note the state change.
558 * NB: The slot time change state machine is clocked according
559 * to whether we are bursting or staggering beacons. We
560 * recognize the request to update and record the current
561 * slot then don't transition until that slot is reached
562 * again. If we miss a beacon for that slot then we'll be
563 * slow to transition but we'll be sure at least one beacon
564 * interval has passed. When bursting slot is always left
565 * set to ATH_BCBUF so this check is a noop.
568 if (sc->sc_updateslot == UPDATE) {
569 sc->sc_updateslot = COMMIT; /* commit next beacon */
570 sc->sc_slotupdate = slot;
571 } else if (sc->sc_updateslot == COMMIT && sc->sc_slotupdate == slot) {
572 ath9k_hw_setslottime(sc->sc_ah, sc->sc_slottime);
573 sc->sc_updateslot = OK;
577 * Stop any current dma and put the new frame(s) on the queue.
578 * This should never fail since we check above that no frames
579 * are still pending on the queue.
581 if (!ath9k_hw_stoptxdma(ah, sc->sc_bhalq)) {
582 DPRINTF(sc, ATH_DBG_FATAL,
583 "%s: beacon queue %u did not stop?\n",
584 __func__, sc->sc_bhalq);
585 /* NB: the HAL still stops DMA, so proceed */
588 /* NB: cabq traffic should already be queued and primed */
589 ath9k_hw_puttxbuf(ah, sc->sc_bhalq, bfaddr);
590 ath9k_hw_txstart(ah, sc->sc_bhalq);
592 sc->ast_be_xmit += bc; /* XXX per-vap? */
597 * Configure the beacon and sleep timers.
599 * When operating as an AP this resets the TSF and sets
600 * up the hardware to notify us when we need to issue beacons.
602 * When operating in station mode this sets up the beacon
603 * timers according to the timestamp of the last received
604 * beacon and the current TSF, configures PCF and DTIM
605 * handling, programs the sleep registers so the hardware
606 * will wakeup in time to receive beacons, and configures
607 * the beacon miss handling so we'll receive a BMISS
608 * interrupt when we stop seeing beacons from the AP
609 * we've associated with.
611 void ath_beacon_config(struct ath_softc *sc, int if_id)
613 struct ieee80211_vif *vif;
614 struct ath_hal *ah = sc->sc_ah;
615 struct ath_beacon_config conf;
617 enum ath9k_opmode av_opmode;
618 u32 nexttbtt, intval;
620 if (if_id != ATH_IF_ID_ANY) {
621 vif = sc->sc_vaps[if_id];
623 avp = (void *)vif->drv_priv;
624 av_opmode = avp->av_opmode;
626 av_opmode = sc->sc_ah->ah_opmode;
629 memset(&conf, 0, sizeof(struct ath_beacon_config));
631 conf.beacon_interval = sc->hw->conf.beacon_int ?
632 sc->hw->conf.beacon_int : ATH_DEFAULT_BINTVAL;
633 conf.listen_interval = 1;
634 conf.dtim_period = conf.beacon_interval;
636 conf.bmiss_timeout = ATH_DEFAULT_BMISS_LIMIT * conf.beacon_interval;
638 /* extract tstamp from last beacon and convert to TU */
639 nexttbtt = TSF_TO_TU(sc->bc_tstamp >> 32, sc->bc_tstamp);
641 /* XXX conditionalize multi-bss support? */
642 if (sc->sc_ah->ah_opmode == ATH9K_M_HOSTAP) {
644 * For multi-bss ap support beacons are either staggered
645 * evenly over N slots or burst together. For the former
646 * arrange for the SWBA to be delivered for each slot.
647 * Slots that are not occupied will generate nothing.
649 /* NB: the beacon interval is kept internally in TU's */
650 intval = conf.beacon_interval & ATH9K_BEACON_PERIOD;
651 intval /= ATH_BCBUF; /* for staggered beacons */
653 intval = conf.beacon_interval & ATH9K_BEACON_PERIOD;
656 if (nexttbtt == 0) /* e.g. for ap mode */
658 else if (intval) /* NB: can be 0 for monitor mode */
659 nexttbtt = roundup(nexttbtt, intval);
661 DPRINTF(sc, ATH_DBG_BEACON, "%s: nexttbtt %u intval %u (%u)\n",
662 __func__, nexttbtt, intval, conf.beacon_interval);
664 /* Check for ATH9K_M_HOSTAP and sc_nostabeacons for WDS client */
665 if (sc->sc_ah->ah_opmode == ATH9K_M_STA) {
666 struct ath9k_beacon_state bs;
669 int dtimperiod, dtimcount, sleepduration;
670 int cfpperiod, cfpcount;
673 * Setup dtim and cfp parameters according to
674 * last beacon we received (which may be none).
676 dtimperiod = conf.dtim_period;
677 if (dtimperiod <= 0) /* NB: 0 if not known */
679 dtimcount = conf.dtim_count;
680 if (dtimcount >= dtimperiod) /* NB: sanity check */
682 cfpperiod = 1; /* NB: no PCF support yet */
685 sleepduration = conf.listen_interval * intval;
686 if (sleepduration <= 0)
687 sleepduration = intval;
691 * Pull nexttbtt forward to reflect the current
692 * TSF and calculate dtim+cfp state for the result.
694 tsf = ath9k_hw_gettsf64(ah);
695 tsftu = TSF_TO_TU(tsf>>32, tsf) + FUDGE;
698 if (--dtimcount < 0) {
699 dtimcount = dtimperiod - 1;
701 cfpcount = cfpperiod - 1;
703 } while (nexttbtt < tsftu);
705 memset(&bs, 0, sizeof(bs));
706 bs.bs_intval = intval;
707 bs.bs_nexttbtt = nexttbtt;
708 bs.bs_dtimperiod = dtimperiod*intval;
709 bs.bs_nextdtim = bs.bs_nexttbtt + dtimcount*intval;
710 bs.bs_cfpperiod = cfpperiod*bs.bs_dtimperiod;
711 bs.bs_cfpnext = bs.bs_nextdtim + cfpcount*bs.bs_dtimperiod;
712 bs.bs_cfpmaxduration = 0;
715 * Calculate the number of consecutive beacons to miss
716 * before taking a BMISS interrupt. The configuration
717 * is specified in TU so we only need calculate based
718 * on the beacon interval. Note that we clamp the
719 * result to at most 15 beacons.
721 if (sleepduration > intval) {
722 bs.bs_bmissthreshold = conf.listen_interval *
723 ATH_DEFAULT_BMISS_LIMIT / 2;
725 bs.bs_bmissthreshold =
726 DIV_ROUND_UP(conf.bmiss_timeout, intval);
727 if (bs.bs_bmissthreshold > 15)
728 bs.bs_bmissthreshold = 15;
729 else if (bs.bs_bmissthreshold <= 0)
730 bs.bs_bmissthreshold = 1;
734 * Calculate sleep duration. The configuration is
735 * given in ms. We insure a multiple of the beacon
736 * period is used. Also, if the sleep duration is
737 * greater than the DTIM period then it makes senses
738 * to make it a multiple of that.
743 bs.bs_sleepduration = roundup(IEEE80211_MS_TO_TU(100),
745 if (bs.bs_sleepduration > bs.bs_dtimperiod)
746 bs.bs_sleepduration = bs.bs_dtimperiod;
748 DPRINTF(sc, ATH_DBG_BEACON,
762 (unsigned long long)tsf, tsftu,
767 bs.bs_bmissthreshold,
770 bs.bs_cfpmaxduration,
775 ath9k_hw_set_interrupts(ah, 0);
776 ath9k_hw_set_sta_beacon_timers(ah, &bs);
777 sc->sc_imask |= ATH9K_INT_BMISS;
778 ath9k_hw_set_interrupts(ah, sc->sc_imask);
782 ath9k_hw_set_interrupts(ah, 0);
783 if (nexttbtt == intval)
784 intval |= ATH9K_BEACON_RESET_TSF;
785 if (sc->sc_ah->ah_opmode == ATH9K_M_IBSS) {
787 * Pull nexttbtt forward to reflect the current
791 if (!(intval & ATH9K_BEACON_RESET_TSF)) {
792 tsf = ath9k_hw_gettsf64(ah);
793 tsftu = TSF_TO_TU((u32)(tsf>>32),
797 } while (nexttbtt < tsftu);
800 DPRINTF(sc, ATH_DBG_BEACON,
801 "%s: IBSS nexttbtt %u intval %u (%u)\n",
803 intval & ~ATH9K_BEACON_RESET_TSF,
804 conf.beacon_interval);
807 * In IBSS mode enable the beacon timers but only
808 * enable SWBA interrupts if we need to manually
809 * prepare beacon frames. Otherwise we use a
810 * self-linked tx descriptor and let the hardware
813 intval |= ATH9K_BEACON_ENA;
814 if (!(ah->ah_caps.hw_caps & ATH9K_HW_CAP_VEOL))
815 sc->sc_imask |= ATH9K_INT_SWBA;
816 ath_beaconq_config(sc);
817 } else if (sc->sc_ah->ah_opmode == ATH9K_M_HOSTAP) {
819 * In AP mode we enable the beacon timers and
820 * SWBA interrupts to prepare beacon frames.
822 intval |= ATH9K_BEACON_ENA;
823 sc->sc_imask |= ATH9K_INT_SWBA; /* beacon prepare */
824 ath_beaconq_config(sc);
826 ath9k_hw_beaconinit(ah, nexttbtt, intval);
827 sc->sc_bmisscount = 0;
828 ath9k_hw_set_interrupts(ah, sc->sc_imask);
830 * When using a self-linked beacon descriptor in
831 * ibss mode load it once here.
833 if (sc->sc_ah->ah_opmode == ATH9K_M_IBSS &&
834 (ah->ah_caps.hw_caps & ATH9K_HW_CAP_VEOL))
835 ath_beacon_start_adhoc(sc, 0);
839 void ath_beacon_sync(struct ath_softc *sc, int if_id)
842 * Resync beacon timers using the tsf of the
843 * beacon frame we just received.
845 ath_beacon_config(sc, if_id);
846 sc->sc_flags |= SC_OP_BEACONS;