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.
17 /* Implementation of beacon processing. */
19 #include <asm/unaligned.h>
23 * Configure parameters for the beacon queue
25 * This function will modify certain transmit queue properties depending on
26 * the operating mode of the station (AP or AdHoc). Parameters are AIFS
27 * settings and channel width min/max
30 static int ath_beaconq_config(struct ath_softc
*sc
)
32 struct ath_hal
*ah
= sc
->sc_ah
;
33 struct ath9k_tx_queue_info qi
;
35 ath9k_hw_get_txq_props(ah
, sc
->sc_bhalq
, &qi
);
36 if (sc
->sc_ah
->ah_opmode
== ATH9K_M_HOSTAP
) {
37 /* Always burst out beacon and CAB traffic. */
42 /* Adhoc mode; important thing is to use 2x cwmin. */
43 qi
.tqi_aifs
= sc
->sc_beacon_qi
.tqi_aifs
;
44 qi
.tqi_cwmin
= 2*sc
->sc_beacon_qi
.tqi_cwmin
;
45 qi
.tqi_cwmax
= sc
->sc_beacon_qi
.tqi_cwmax
;
48 if (!ath9k_hw_set_txq_props(ah
, sc
->sc_bhalq
, &qi
)) {
49 DPRINTF(sc
, ATH_DBG_FATAL
,
50 "%s: unable to update h/w beacon queue parameters\n",
54 ath9k_hw_resettxqueue(ah
, sc
->sc_bhalq
); /* push to h/w */
60 * Setup the beacon frame for transmit.
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.
67 static void ath_beacon_setup(struct ath_softc
*sc
,
68 struct ath_vap
*avp
, struct ath_buf
*bf
)
70 struct sk_buff
*skb
= (struct sk_buff
*)bf
->bf_mpdu
;
71 struct ath_hal
*ah
= sc
->sc_ah
;
74 const struct ath9k_rate_table
*rt
;
78 struct ath9k_11n_rate_series series
[4];
80 DPRINTF(sc
, ATH_DBG_BEACON
, "%s: m %p len %u\n",
81 __func__
, skb
, skb
->len
);
83 /* setup descriptors */
86 flags
= ATH9K_TXDESC_NOACK
;
88 if (sc
->sc_ah
->ah_opmode
== ATH9K_M_IBSS
&&
89 (ah
->ah_caps
.hw_caps
& ATH9K_HW_CAP_VEOL
)) {
90 ds
->ds_link
= bf
->bf_daddr
; /* self-linked */
91 flags
|= ATH9K_TXDESC_VEOL
;
92 /* Let hardware handle antenna switching. */
97 * Switch antenna every beacon.
98 * Should only switch every beacon period, not for every
100 * XXX assumes two antenna
102 antenna
= ((sc
->ast_be_xmit
/ sc
->sc_nbcnvaps
) & 1 ? 2 : 1);
105 ds
->ds_data
= bf
->bf_buf_addr
;
108 * Calculate rate code.
109 * XXX everything at min xmit rate
112 rt
= sc
->sc_currates
;
113 rate
= rt
->info
[rix
].rateCode
;
114 if (sc
->sc_flags
& SC_OP_PREAMBLE_SHORT
)
115 rate
|= rt
->info
[rix
].shortPreamble
;
117 ath9k_hw_set11n_txdesc(ah
, ds
118 , skb
->len
+ FCS_LEN
/* frame length */
119 , ATH9K_PKT_TYPE_BEACON
/* Atheros packet type */
120 , avp
->av_btxctl
.txpower
/* txpower XXX */
121 , ATH9K_TXKEYIX_INVALID
/* no encryption */
122 , ATH9K_KEY_TYPE_CLEAR
/* no encryption */
123 , flags
/* no ack, veol for beacons */
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 memzero(series
, 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 /* Move everything from the vap's mcast queue to the hardware cab queue.
144 * Caller must hold mcasq lock and cabq lock
147 static void empty_mcastq_into_cabq(struct ath_hal
*ah
,
148 struct ath_txq
*mcastq
, struct ath_txq
*cabq
)
150 struct ath_buf
*bfmcast
;
152 BUG_ON(list_empty(&mcastq
->axq_q
));
154 bfmcast
= list_first_entry(&mcastq
->axq_q
, struct ath_buf
, list
);
156 /* link the descriptors */
158 ath9k_hw_puttxbuf(ah
, cabq
->axq_qnum
, bfmcast
->bf_daddr
);
160 *cabq
->axq_link
= bfmcast
->bf_daddr
;
162 /* append the private vap mcast list to the cabq */
164 cabq
->axq_depth
+= mcastq
->axq_depth
;
165 cabq
->axq_totalqueued
+= mcastq
->axq_totalqueued
;
166 cabq
->axq_linkbuf
= mcastq
->axq_linkbuf
;
167 cabq
->axq_link
= mcastq
->axq_link
;
168 list_splice_tail_init(&mcastq
->axq_q
, &cabq
->axq_q
);
169 mcastq
->axq_depth
= 0;
170 mcastq
->axq_totalqueued
= 0;
171 mcastq
->axq_linkbuf
= NULL
;
172 mcastq
->axq_link
= NULL
;
175 /* This is only run at DTIM. We move everything from the vap's mcast queue
176 * to the hardware cab queue. Caller must hold the mcastq lock. */
177 static void trigger_mcastq(struct ath_hal
*ah
,
178 struct ath_txq
*mcastq
, struct ath_txq
*cabq
)
180 spin_lock_bh(&cabq
->axq_lock
);
182 if (!list_empty(&mcastq
->axq_q
))
183 empty_mcastq_into_cabq(ah
, mcastq
, cabq
);
185 /* cabq is gated by beacon so it is safe to start here */
186 if (!list_empty(&cabq
->axq_q
))
187 ath9k_hw_txstart(ah
, cabq
->axq_qnum
);
189 spin_unlock_bh(&cabq
->axq_lock
);
193 * Generate beacon frame and queue cab data for a vap.
195 * Updates the contents of the beacon frame. It is assumed that the buffer for
196 * the beacon frame has been allocated in the ATH object, and simply needs to
197 * be filled for this cycle. Also, any CAB (crap after beacon?) traffic will
198 * be added to the beacon frame at this point.
200 static struct ath_buf
*ath_beacon_generate(struct ath_softc
*sc
, int if_id
)
202 struct ath_hal
*ah
= sc
->sc_ah
;
208 int is_beacon_dtim
= 0;
210 struct ath_txq
*cabq
;
211 struct ath_txq
*mcastq
;
212 avp
= sc
->sc_vaps
[if_id
];
214 mcastq
= &avp
->av_mcastq
;
219 if (avp
->av_bcbuf
== NULL
) {
220 DPRINTF(sc
, ATH_DBG_BEACON
, "%s: avp=%p av_bcbuf=%p\n",
221 __func__
, avp
, avp
->av_bcbuf
);
225 skb
= (struct sk_buff
*) bf
->bf_mpdu
;
228 * Update dynamic beacon contents. If this returns
229 * non-zero then we need to remap the memory because
230 * the beacon frame changed size (probably because
231 * of the TIM bitmap).
235 /* XXX: spin_lock_bh should not be used here, but sparse bitches
236 * otherwise. We should fix sparse :) */
237 spin_lock_bh(&mcastq
->axq_lock
);
238 mcastq_depth
= avp
->av_mcastq
.axq_depth
;
240 if (ath_update_beacon(sc
, if_id
, &avp
->av_boff
, skb
, mcastq_depth
) ==
242 ath_skb_unmap_single(sc
, skb
, PCI_DMA_TODEVICE
,
243 get_dma_mem_context(bf
, bf_dmacontext
));
244 bf
->bf_buf_addr
= ath_skb_map_single(sc
, skb
, PCI_DMA_TODEVICE
,
245 get_dma_mem_context(bf
, bf_dmacontext
));
247 pci_dma_sync_single_for_cpu(sc
->pdev
,
254 * if the CABQ traffic from previous DTIM is pending and the current
255 * beacon is also a DTIM.
256 * 1) if there is only one vap let the cab traffic continue.
257 * 2) if there are more than one vap and we are using staggered
258 * beacons, then drain the cabq by dropping all the frames in
259 * the cabq so that the current vaps cab traffic can be scheduled.
261 spin_lock_bh(&cabq
->axq_lock
);
262 cabq_depth
= cabq
->axq_depth
;
263 spin_unlock_bh(&cabq
->axq_lock
);
265 is_beacon_dtim
= avp
->av_boff
.bo_tim
[4] & 1;
267 if (mcastq_depth
&& is_beacon_dtim
&& cabq_depth
) {
269 * Unlock the cabq lock as ath_tx_draintxq acquires
270 * the lock again which is a common function and that
271 * acquires txq lock inside.
273 if (sc
->sc_nvaps
> 1) {
274 ath_tx_draintxq(sc
, cabq
, false);
275 DPRINTF(sc
, ATH_DBG_BEACON
,
276 "%s: flush previous cabq traffic\n", __func__
);
280 /* Construct tx descriptor. */
281 ath_beacon_setup(sc
, avp
, bf
);
284 * Enable the CAB queue before the beacon queue to
285 * insure cab frames are triggered by this beacon.
288 trigger_mcastq(ah
, mcastq
, cabq
);
290 spin_unlock_bh(&mcastq
->axq_lock
);
295 * Startup beacon transmission for adhoc mode when they are sent entirely
296 * by the hardware using the self-linked descriptor + veol trick.
299 static void ath_beacon_start_adhoc(struct ath_softc
*sc
, int if_id
)
301 struct ath_hal
*ah
= sc
->sc_ah
;
306 avp
= sc
->sc_vaps
[if_id
];
309 if (avp
->av_bcbuf
== NULL
) {
310 DPRINTF(sc
, ATH_DBG_BEACON
, "%s: avp=%p av_bcbuf=%p\n",
311 __func__
, avp
, avp
!= NULL
? avp
->av_bcbuf
: NULL
);
315 skb
= (struct sk_buff
*) bf
->bf_mpdu
;
317 /* Construct tx descriptor. */
318 ath_beacon_setup(sc
, avp
, bf
);
320 /* NB: caller is known to have already stopped tx dma */
321 ath9k_hw_puttxbuf(ah
, sc
->sc_bhalq
, bf
->bf_daddr
);
322 ath9k_hw_txstart(ah
, sc
->sc_bhalq
);
323 DPRINTF(sc
, ATH_DBG_BEACON
, "%s: TXDP%u = %llx (%p)\n", __func__
,
324 sc
->sc_bhalq
, ito64(bf
->bf_daddr
), bf
->bf_desc
);
328 * Setup a h/w transmit queue for beacons.
330 * This function allocates an information structure (struct ath9k_txq_info)
331 * on the stack, sets some specific parameters (zero out channel width
332 * min/max, and enable aifs). The info structure does not need to be
336 int ath_beaconq_setup(struct ath_hal
*ah
)
338 struct ath9k_tx_queue_info qi
;
340 memzero(&qi
, sizeof(qi
));
344 /* NB: don't enable any interrupts */
345 return ath9k_hw_setuptxqueue(ah
, ATH9K_TX_QUEUE_BEACON
, &qi
);
350 * Allocate and setup an initial beacon frame.
352 * Allocate a beacon state variable for a specific VAP instance created on
353 * the ATH interface. This routine also calculates the beacon "slot" for
354 * staggared beacons in the mBSSID case.
357 int ath_beacon_alloc(struct ath_softc
*sc
, int if_id
)
360 struct ieee80211_hdr
*wh
;
364 avp
= sc
->sc_vaps
[if_id
];
367 /* Allocate a beacon descriptor if we haven't done so. */
368 if (!avp
->av_bcbuf
) {
370 * Allocate beacon state for hostap/ibss. We know
371 * a buffer is available.
374 avp
->av_bcbuf
= list_first_entry(&sc
->sc_bbuf
,
375 struct ath_buf
, list
);
376 list_del(&avp
->av_bcbuf
->list
);
378 if (sc
->sc_ah
->ah_opmode
== ATH9K_M_HOSTAP
||
379 !(sc
->sc_ah
->ah_caps
.hw_caps
& ATH9K_HW_CAP_VEOL
)) {
382 * Assign the vap to a beacon xmit slot. As
383 * above, this cannot fail to find one.
386 for (slot
= 0; slot
< ATH_BCBUF
; slot
++)
387 if (sc
->sc_bslot
[slot
] == ATH_IF_ID_ANY
) {
389 * XXX hack, space out slots to better
392 if (slot
+1 < ATH_BCBUF
&&
393 sc
->sc_bslot
[slot
+1] ==
395 avp
->av_bslot
= slot
+1;
398 avp
->av_bslot
= slot
;
399 /* NB: keep looking for a double slot */
401 BUG_ON(sc
->sc_bslot
[avp
->av_bslot
] != ATH_IF_ID_ANY
);
402 sc
->sc_bslot
[avp
->av_bslot
] = if_id
;
407 /* release the previous beacon frame , if it already exists. */
409 if (bf
->bf_mpdu
!= NULL
) {
410 skb
= (struct sk_buff
*)bf
->bf_mpdu
;
411 ath_skb_unmap_single(sc
, skb
, PCI_DMA_TODEVICE
,
412 get_dma_mem_context(bf
, bf_dmacontext
));
413 dev_kfree_skb_any(skb
);
418 * NB: the beacon data buffer must be 32-bit aligned;
419 * we assume the wbuf routines will return us something
420 * with this alignment (perhaps should assert).
421 * FIXME: Fill avp->av_boff.bo_tim,avp->av_btxctl.txpower and
422 * avp->av_btxctl.shortPreamble
424 skb
= ieee80211_beacon_get(sc
->hw
, avp
->av_if_data
);
426 DPRINTF(sc
, ATH_DBG_BEACON
, "%s: cannot get skb\n",
432 * Calculate a TSF adjustment factor required for
433 * staggered beacons. Note that we assume the format
434 * of the beacon frame leaves the tstamp field immediately
435 * following the header.
437 if (avp
->av_bslot
> 0) {
442 /* FIXME: Use default value for now: Sujith */
444 intval
= ATH_DEFAULT_BINTVAL
;
447 * The beacon interval is in TU's; the TSF in usecs.
448 * We figure out how many TU's to add to align the
449 * timestamp then convert to TSF units and handle
450 * byte swapping before writing it in the frame.
451 * The hardware will then add this each time a beacon
452 * frame is sent. Note that we align vap's 1..N
453 * and leave vap 0 untouched. This means vap 0
454 * has a timestamp in one beacon interval while the
455 * others get a timestamp aligned to the next interval.
457 tsfadjust
= (intval
* (ATH_BCBUF
- avp
->av_bslot
)) / ATH_BCBUF
;
458 val
= cpu_to_le64(tsfadjust
<< 10); /* TU->TSF */
460 DPRINTF(sc
, ATH_DBG_BEACON
,
461 "%s: %s beacons, bslot %d intval %u tsfadjust %llu\n",
463 avp
->av_bslot
, intval
, (unsigned long long)tsfadjust
);
465 wh
= (struct ieee80211_hdr
*)skb
->data
;
466 memcpy(&wh
[1], &val
, sizeof(val
));
469 bf
->bf_buf_addr
= ath_skb_map_single(sc
, skb
, PCI_DMA_TODEVICE
,
470 get_dma_mem_context(bf
, bf_dmacontext
));
477 * Reclaim beacon resources and return buffer to the pool.
479 * Checks the VAP to put the beacon frame buffer back to the ATH object
480 * queue, and de-allocates any wbuf frames that were sent as CAB traffic.
483 void ath_beacon_return(struct ath_softc
*sc
, struct ath_vap
*avp
)
485 if (avp
->av_bcbuf
!= NULL
) {
488 if (avp
->av_bslot
!= -1) {
489 sc
->sc_bslot
[avp
->av_bslot
] = ATH_IF_ID_ANY
;
494 if (bf
->bf_mpdu
!= NULL
) {
495 struct sk_buff
*skb
= (struct sk_buff
*)bf
->bf_mpdu
;
496 ath_skb_unmap_single(sc
, skb
, PCI_DMA_TODEVICE
,
497 get_dma_mem_context(bf
, bf_dmacontext
));
498 dev_kfree_skb_any(skb
);
501 list_add_tail(&bf
->list
, &sc
->sc_bbuf
);
503 avp
->av_bcbuf
= NULL
;
508 * Reclaim beacon resources and return buffer to the pool.
510 * This function will free any wbuf frames that are still attached to the
511 * beacon buffers in the ATH object. Note that this does not de-allocate
512 * any wbuf objects that are in the transmit queue and have not yet returned
516 void ath_beacon_free(struct ath_softc
*sc
)
520 list_for_each_entry(bf
, &sc
->sc_bbuf
, list
) {
521 if (bf
->bf_mpdu
!= NULL
) {
522 struct sk_buff
*skb
= (struct sk_buff
*) bf
->bf_mpdu
;
523 ath_skb_unmap_single(sc
, skb
, PCI_DMA_TODEVICE
,
524 get_dma_mem_context(bf
, bf_dmacontext
));
525 dev_kfree_skb_any(skb
);
532 * Tasklet for Sending Beacons
534 * Transmit one or more beacon frames at SWBA. Dynamic updates to the frame
535 * contents are done as needed and the slot time is also adjusted based on
538 * This tasklet is not scheduled, it's called in ISR context.
541 void ath9k_beacon_tasklet(unsigned long data
)
543 #define TSF_TO_TU(_h,_l) \
544 ((((u32)(_h)) << 22) | (((u32)(_l)) >> 10))
546 struct ath_softc
*sc
= (struct ath_softc
*)data
;
547 struct ath_hal
*ah
= sc
->sc_ah
;
548 struct ath_buf
*bf
= NULL
;
551 u32 rx_clear
= 0, rx_frame
= 0, tx_frame
= 0;
553 u32 bc
= 0; /* beacon count */
558 if (sc
->sc_flags
& SC_OP_NO_RESET
) {
559 show_cycles
= ath9k_hw_GetMibCycleCountsPct(ah
,
566 * Check if the previous beacon has gone out. If
567 * not don't try to post another, skip this period
568 * and wait for the next. Missed beacons indicate
569 * a problem and should not occur. If we miss too
570 * many consecutive beacons reset the device.
572 if (ath9k_hw_numtxpending(ah
, sc
->sc_bhalq
) != 0) {
574 /* XXX: doth needs the chanchange IE countdown decremented.
575 * We should consider adding a mac80211 call to indicate
576 * a beacon miss so appropriate action could be taken
579 if (sc
->sc_bmisscount
< BSTUCK_THRESH
) {
580 if (sc
->sc_flags
& SC_OP_NO_RESET
) {
581 DPRINTF(sc
, ATH_DBG_BEACON
,
582 "%s: missed %u consecutive beacons\n",
583 __func__
, sc
->sc_bmisscount
);
586 * Display cycle counter stats
587 * from HW to aide in debug of
592 "%s: busy times: rx_clear=%d, "
593 "rx_frame=%d, tx_frame=%d\n",
594 __func__
, rx_clear
, rx_frame
,
599 "%s: unable to obtain "
600 "busy times\n", __func__
);
603 DPRINTF(sc
, ATH_DBG_BEACON
,
604 "%s: missed %u consecutive beacons\n",
605 __func__
, sc
->sc_bmisscount
);
607 } else if (sc
->sc_bmisscount
>= BSTUCK_THRESH
) {
608 if (sc
->sc_flags
& SC_OP_NO_RESET
) {
609 if (sc
->sc_bmisscount
== BSTUCK_THRESH
) {
612 "%s: beacon is officially "
613 "stuck\n", __func__
);
614 ath9k_hw_dmaRegDump(ah
);
617 DPRINTF(sc
, ATH_DBG_BEACON
,
618 "%s: beacon is officially stuck\n",
620 ath_bstuck_process(sc
);
626 if (sc
->sc_bmisscount
!= 0) {
627 if (sc
->sc_flags
& SC_OP_NO_RESET
) {
630 "%s: resume beacon xmit after %u misses\n",
631 __func__
, sc
->sc_bmisscount
);
633 DPRINTF(sc
, ATH_DBG_BEACON
,
634 "%s: resume beacon xmit after %u misses\n",
635 __func__
, sc
->sc_bmisscount
);
637 sc
->sc_bmisscount
= 0;
641 * Generate beacon frames. we are sending frames
642 * staggered so calculate the slot for this frame based
643 * on the tsf to safeguard against missing an swba.
646 /* FIXME: Use default value for now - Sujith */
647 intval
= ATH_DEFAULT_BINTVAL
;
649 tsf
= ath9k_hw_gettsf64(ah
);
650 tsftu
= TSF_TO_TU(tsf
>>32, tsf
);
651 slot
= ((tsftu
% intval
) * ATH_BCBUF
) / intval
;
652 if_id
= sc
->sc_bslot
[(slot
+ 1) % ATH_BCBUF
];
653 DPRINTF(sc
, ATH_DBG_BEACON
,
654 "%s: slot %d [tsf %llu tsftu %u intval %u] if_id %d\n",
655 __func__
, slot
, (unsigned long long) tsf
, tsftu
,
658 if (if_id
!= ATH_IF_ID_ANY
) {
659 bf
= ath_beacon_generate(sc
, if_id
);
661 bfaddr
= bf
->bf_daddr
;
666 * Handle slot time change when a non-ERP station joins/leaves
667 * an 11g network. The 802.11 layer notifies us via callback,
668 * we mark updateslot, then wait one beacon before effecting
669 * the change. This gives associated stations at least one
670 * beacon interval to note the state change.
672 * NB: The slot time change state machine is clocked according
673 * to whether we are bursting or staggering beacons. We
674 * recognize the request to update and record the current
675 * slot then don't transition until that slot is reached
676 * again. If we miss a beacon for that slot then we'll be
677 * slow to transition but we'll be sure at least one beacon
678 * interval has passed. When bursting slot is always left
679 * set to ATH_BCBUF so this check is a noop.
682 if (sc
->sc_updateslot
== UPDATE
) {
683 sc
->sc_updateslot
= COMMIT
; /* commit next beacon */
684 sc
->sc_slotupdate
= slot
;
685 } else if (sc
->sc_updateslot
== COMMIT
&& sc
->sc_slotupdate
== slot
)
686 ath_setslottime(sc
); /* commit change to hardware */
690 * Stop any current dma and put the new frame(s) on the queue.
691 * This should never fail since we check above that no frames
692 * are still pending on the queue.
694 if (!ath9k_hw_stoptxdma(ah
, sc
->sc_bhalq
)) {
695 DPRINTF(sc
, ATH_DBG_FATAL
,
696 "%s: beacon queue %u did not stop?\n",
697 __func__
, sc
->sc_bhalq
);
698 /* NB: the HAL still stops DMA, so proceed */
701 /* NB: cabq traffic should already be queued and primed */
702 ath9k_hw_puttxbuf(ah
, sc
->sc_bhalq
, bfaddr
);
703 ath9k_hw_txstart(ah
, sc
->sc_bhalq
);
705 sc
->ast_be_xmit
+= bc
; /* XXX per-vap? */
711 * Tasklet for Beacon Stuck processing
713 * Processing for Beacon Stuck.
714 * Basically calls the ath_internal_reset function to reset the chip.
717 void ath_bstuck_process(struct ath_softc
*sc
)
719 DPRINTF(sc
, ATH_DBG_BEACON
,
720 "%s: stuck beacon; resetting (bmiss count %u)\n",
721 __func__
, sc
->sc_bmisscount
);
722 ath_reset(sc
, false);
726 * Configure the beacon and sleep timers.
728 * When operating as an AP this resets the TSF and sets
729 * up the hardware to notify us when we need to issue beacons.
731 * When operating in station mode this sets up the beacon
732 * timers according to the timestamp of the last received
733 * beacon and the current TSF, configures PCF and DTIM
734 * handling, programs the sleep registers so the hardware
735 * will wakeup in time to receive beacons, and configures
736 * the beacon miss handling so we'll receive a BMISS
737 * interrupt when we stop seeing beacons from the AP
738 * we've associated with.
741 void ath_beacon_config(struct ath_softc
*sc
, int if_id
)
743 #define TSF_TO_TU(_h,_l) \
744 ((((u32)(_h)) << 22) | (((u32)(_l)) >> 10))
745 struct ath_hal
*ah
= sc
->sc_ah
;
746 u32 nexttbtt
, intval
;
747 struct ath_beacon_config conf
;
748 enum ath9k_opmode av_opmode
;
750 if (if_id
!= ATH_IF_ID_ANY
)
751 av_opmode
= sc
->sc_vaps
[if_id
]->av_opmode
;
753 av_opmode
= sc
->sc_ah
->ah_opmode
;
755 memzero(&conf
, sizeof(struct ath_beacon_config
));
757 /* FIXME: Use default values for now - Sujith */
758 /* Query beacon configuration first */
760 * Protocol stack doesn't support dynamic beacon configuration,
761 * use default configurations.
763 conf
.beacon_interval
= ATH_DEFAULT_BINTVAL
;
764 conf
.listen_interval
= 1;
765 conf
.dtim_period
= conf
.beacon_interval
;
767 conf
.bmiss_timeout
= ATH_DEFAULT_BMISS_LIMIT
* conf
.beacon_interval
;
769 /* extract tstamp from last beacon and convert to TU */
770 nexttbtt
= TSF_TO_TU(get_unaligned_le32(conf
.u
.last_tstamp
+ 4),
771 get_unaligned_le32(conf
.u
.last_tstamp
));
772 /* XXX conditionalize multi-bss support? */
773 if (sc
->sc_ah
->ah_opmode
== ATH9K_M_HOSTAP
) {
775 * For multi-bss ap support beacons are either staggered
776 * evenly over N slots or burst together. For the former
777 * arrange for the SWBA to be delivered for each slot.
778 * Slots that are not occupied will generate nothing.
780 /* NB: the beacon interval is kept internally in TU's */
781 intval
= conf
.beacon_interval
& ATH9K_BEACON_PERIOD
;
782 intval
/= ATH_BCBUF
; /* for staggered beacons */
784 intval
= conf
.beacon_interval
& ATH9K_BEACON_PERIOD
;
787 if (nexttbtt
== 0) /* e.g. for ap mode */
789 else if (intval
) /* NB: can be 0 for monitor mode */
790 nexttbtt
= roundup(nexttbtt
, intval
);
791 DPRINTF(sc
, ATH_DBG_BEACON
, "%s: nexttbtt %u intval %u (%u)\n",
792 __func__
, nexttbtt
, intval
, conf
.beacon_interval
);
793 /* Check for ATH9K_M_HOSTAP and sc_nostabeacons for WDS client */
794 if (sc
->sc_ah
->ah_opmode
== ATH9K_M_STA
) {
795 struct ath9k_beacon_state bs
;
798 int dtimperiod
, dtimcount
, sleepduration
;
799 int cfpperiod
, cfpcount
;
802 * Setup dtim and cfp parameters according to
803 * last beacon we received (which may be none).
805 dtimperiod
= conf
.dtim_period
;
806 if (dtimperiod
<= 0) /* NB: 0 if not known */
808 dtimcount
= conf
.dtim_count
;
809 if (dtimcount
>= dtimperiod
) /* NB: sanity check */
810 dtimcount
= 0; /* XXX? */
811 cfpperiod
= 1; /* NB: no PCF support yet */
814 sleepduration
= conf
.listen_interval
* intval
;
815 if (sleepduration
<= 0)
816 sleepduration
= intval
;
820 * Pull nexttbtt forward to reflect the current
821 * TSF and calculate dtim+cfp state for the result.
823 tsf
= ath9k_hw_gettsf64(ah
);
824 tsftu
= TSF_TO_TU(tsf
>>32, tsf
) + FUDGE
;
827 if (--dtimcount
< 0) {
828 dtimcount
= dtimperiod
- 1;
830 cfpcount
= cfpperiod
- 1;
832 } while (nexttbtt
< tsftu
);
834 memzero(&bs
, sizeof(bs
));
835 bs
.bs_intval
= intval
;
836 bs
.bs_nexttbtt
= nexttbtt
;
837 bs
.bs_dtimperiod
= dtimperiod
*intval
;
838 bs
.bs_nextdtim
= bs
.bs_nexttbtt
+ dtimcount
*intval
;
839 bs
.bs_cfpperiod
= cfpperiod
*bs
.bs_dtimperiod
;
840 bs
.bs_cfpnext
= bs
.bs_nextdtim
+ cfpcount
*bs
.bs_dtimperiod
;
841 bs
.bs_cfpmaxduration
= 0;
843 * Calculate the number of consecutive beacons to miss
844 * before taking a BMISS interrupt. The configuration
845 * is specified in TU so we only need calculate based
846 * on the beacon interval. Note that we clamp the
847 * result to at most 15 beacons.
849 if (sleepduration
> intval
) {
850 bs
.bs_bmissthreshold
=
851 conf
.listen_interval
*
852 ATH_DEFAULT_BMISS_LIMIT
/ 2;
854 bs
.bs_bmissthreshold
=
855 DIV_ROUND_UP(conf
.bmiss_timeout
, intval
);
856 if (bs
.bs_bmissthreshold
> 15)
857 bs
.bs_bmissthreshold
= 15;
858 else if (bs
.bs_bmissthreshold
<= 0)
859 bs
.bs_bmissthreshold
= 1;
863 * Calculate sleep duration. The configuration is
864 * given in ms. We insure a multiple of the beacon
865 * period is used. Also, if the sleep duration is
866 * greater than the DTIM period then it makes senses
867 * to make it a multiple of that.
872 bs
.bs_sleepduration
=
873 roundup(IEEE80211_MS_TO_TU(100), sleepduration
);
874 if (bs
.bs_sleepduration
> bs
.bs_dtimperiod
)
875 bs
.bs_sleepduration
= bs
.bs_dtimperiod
;
877 DPRINTF(sc
, ATH_DBG_BEACON
,
891 , (unsigned long long)tsf
, tsftu
896 , bs
.bs_bmissthreshold
897 , bs
.bs_sleepduration
899 , bs
.bs_cfpmaxduration
904 ath9k_hw_set_interrupts(ah
, 0);
905 ath9k_hw_set_sta_beacon_timers(ah
, &bs
);
906 sc
->sc_imask
|= ATH9K_INT_BMISS
;
907 ath9k_hw_set_interrupts(ah
, sc
->sc_imask
);
911 ath9k_hw_set_interrupts(ah
, 0);
912 if (nexttbtt
== intval
)
913 intval
|= ATH9K_BEACON_RESET_TSF
;
914 if (sc
->sc_ah
->ah_opmode
== ATH9K_M_IBSS
) {
916 * Pull nexttbtt forward to reflect the current
920 if (!(intval
& ATH9K_BEACON_RESET_TSF
)) {
921 tsf
= ath9k_hw_gettsf64(ah
);
922 tsftu
= TSF_TO_TU((u32
)(tsf
>>32),
926 } while (nexttbtt
< tsftu
);
929 DPRINTF(sc
, ATH_DBG_BEACON
,
930 "%s: IBSS nexttbtt %u intval %u (%u)\n",
932 intval
& ~ATH9K_BEACON_RESET_TSF
,
933 conf
.beacon_interval
);
936 * In IBSS mode enable the beacon timers but only
937 * enable SWBA interrupts if we need to manually
938 * prepare beacon frames. Otherwise we use a
939 * self-linked tx descriptor and let the hardware
942 intval
|= ATH9K_BEACON_ENA
;
943 if (!(ah
->ah_caps
.hw_caps
& ATH9K_HW_CAP_VEOL
))
944 sc
->sc_imask
|= ATH9K_INT_SWBA
;
945 ath_beaconq_config(sc
);
946 } else if (sc
->sc_ah
->ah_opmode
== ATH9K_M_HOSTAP
) {
948 * In AP mode we enable the beacon timers and
949 * SWBA interrupts to prepare beacon frames.
951 intval
|= ATH9K_BEACON_ENA
;
952 sc
->sc_imask
|= ATH9K_INT_SWBA
; /* beacon prepare */
953 ath_beaconq_config(sc
);
955 ath9k_hw_beaconinit(ah
, nexttbtt
, intval
);
956 sc
->sc_bmisscount
= 0;
957 ath9k_hw_set_interrupts(ah
, sc
->sc_imask
);
959 * When using a self-linked beacon descriptor in
960 * ibss mode load it once here.
962 if (sc
->sc_ah
->ah_opmode
== ATH9K_M_IBSS
&&
963 (ah
->ah_caps
.hw_caps
& ATH9K_HW_CAP_VEOL
))
964 ath_beacon_start_adhoc(sc
, 0);
969 /* Function to collect beacon rssi data and resync beacon if necessary */
971 void ath_beacon_sync(struct ath_softc
*sc
, int if_id
)
974 * Resync beacon timers using the tsf of the
975 * beacon frame we just received.
977 ath_beacon_config(sc
, if_id
);
978 sc
->sc_flags
|= SC_OP_BEACONS
;