ath9k: Remove is_bslot_active
[linux-2.6/libata-dev.git] / drivers / net / wireless / ath / ath9k / beacon.c
blob2962b3e928d8208ea23f898ec950fc8ce455b54f
1 /*
2 * Copyright (c) 2008-2011 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 #include <linux/dma-mapping.h>
18 #include "ath9k.h"
20 #define FUDGE 2
22 static void ath9k_reset_beacon_status(struct ath_softc *sc)
24 sc->beacon.tx_processed = false;
25 sc->beacon.tx_last = false;
29 * This function will modify certain transmit queue properties depending on
30 * the operating mode of the station (AP or AdHoc). Parameters are AIFS
31 * settings and channel width min/max
33 int ath_beaconq_config(struct ath_softc *sc)
35 struct ath_hw *ah = sc->sc_ah;
36 struct ath_common *common = ath9k_hw_common(ah);
37 struct ath9k_tx_queue_info qi, qi_be;
38 struct ath_txq *txq;
40 ath9k_hw_get_txq_props(ah, sc->beacon.beaconq, &qi);
41 if (sc->sc_ah->opmode == NL80211_IFTYPE_AP) {
42 /* Always burst out beacon and CAB traffic. */
43 qi.tqi_aifs = 1;
44 qi.tqi_cwmin = 0;
45 qi.tqi_cwmax = 0;
46 } else {
47 /* Adhoc mode; important thing is to use 2x cwmin. */
48 txq = sc->tx.txq_map[WME_AC_BE];
49 ath9k_hw_get_txq_props(ah, txq->axq_qnum, &qi_be);
50 qi.tqi_aifs = qi_be.tqi_aifs;
51 if (ah->slottime == ATH9K_SLOT_TIME_20)
52 qi.tqi_cwmin = 2*qi_be.tqi_cwmin;
53 else
54 qi.tqi_cwmin = 4*qi_be.tqi_cwmin;
55 qi.tqi_cwmax = qi_be.tqi_cwmax;
58 if (!ath9k_hw_set_txq_props(ah, sc->beacon.beaconq, &qi)) {
59 ath_err(common,
60 "Unable to update h/w beacon queue parameters\n");
61 return 0;
62 } else {
63 ath9k_hw_resettxqueue(ah, sc->beacon.beaconq);
64 return 1;
69 * Associates the beacon frame buffer with a transmit descriptor. Will set
70 * up rate codes, and channel flags. Beacons are always sent out at the
71 * lowest rate, and are not retried.
73 static void ath_beacon_setup(struct ath_softc *sc, struct ieee80211_vif *vif,
74 struct ath_buf *bf, int rateidx)
76 struct sk_buff *skb = bf->bf_mpdu;
77 struct ath_hw *ah = sc->sc_ah;
78 struct ath_common *common = ath9k_hw_common(ah);
79 struct ath_tx_info info;
80 struct ieee80211_supported_band *sband;
81 u8 chainmask = ah->txchainmask;
82 u8 rate = 0;
84 ath9k_reset_beacon_status(sc);
86 sband = &sc->sbands[common->hw->conf.channel->band];
87 rate = sband->bitrates[rateidx].hw_value;
88 if (vif->bss_conf.use_short_preamble)
89 rate |= sband->bitrates[rateidx].hw_value_short;
91 memset(&info, 0, sizeof(info));
92 info.pkt_len = skb->len + FCS_LEN;
93 info.type = ATH9K_PKT_TYPE_BEACON;
94 info.txpower = MAX_RATE_POWER;
95 info.keyix = ATH9K_TXKEYIX_INVALID;
96 info.keytype = ATH9K_KEY_TYPE_CLEAR;
97 info.flags = ATH9K_TXDESC_NOACK | ATH9K_TXDESC_CLRDMASK;
99 info.buf_addr[0] = bf->bf_buf_addr;
100 info.buf_len[0] = roundup(skb->len, 4);
102 info.is_first = true;
103 info.is_last = true;
105 info.qcu = sc->beacon.beaconq;
107 info.rates[0].Tries = 1;
108 info.rates[0].Rate = rate;
109 info.rates[0].ChSel = ath_txchainmask_reduction(sc, chainmask, rate);
111 ath9k_hw_set_txdesc(ah, bf->bf_desc, &info);
114 static void ath_tx_cabq(struct ieee80211_hw *hw, struct sk_buff *skb)
116 struct ath_softc *sc = hw->priv;
117 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
118 struct ath_tx_control txctl;
120 memset(&txctl, 0, sizeof(struct ath_tx_control));
121 txctl.txq = sc->beacon.cabq;
123 ath_dbg(common, XMIT, "transmitting CABQ packet, skb: %p\n", skb);
125 if (ath_tx_start(hw, skb, &txctl) != 0) {
126 ath_dbg(common, XMIT, "CABQ TX failed\n");
127 dev_kfree_skb_any(skb);
131 static struct ath_buf *ath_beacon_generate(struct ieee80211_hw *hw,
132 struct ieee80211_vif *vif)
134 struct ath_softc *sc = hw->priv;
135 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
136 struct ath_buf *bf;
137 struct ath_vif *avp = (void *)vif->drv_priv;
138 struct sk_buff *skb;
139 struct ath_txq *cabq = sc->beacon.cabq;
140 struct ieee80211_tx_info *info;
141 int cabq_depth;
143 if (avp->av_bcbuf == NULL)
144 return NULL;
146 ath9k_reset_beacon_status(sc);
148 /* Release the old beacon first */
150 bf = avp->av_bcbuf;
151 skb = bf->bf_mpdu;
152 if (skb) {
153 dma_unmap_single(sc->dev, bf->bf_buf_addr,
154 skb->len, DMA_TO_DEVICE);
155 dev_kfree_skb_any(skb);
156 bf->bf_buf_addr = 0;
159 /* Get a new beacon from mac80211 */
161 skb = ieee80211_beacon_get(hw, vif);
162 bf->bf_mpdu = skb;
163 if (skb == NULL)
164 return NULL;
165 ((struct ieee80211_mgmt *)skb->data)->u.beacon.timestamp =
166 avp->tsf_adjust;
168 info = IEEE80211_SKB_CB(skb);
169 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
171 * TODO: make sure the seq# gets assigned properly (vs. other
172 * TX frames)
174 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
175 sc->tx.seq_no += 0x10;
176 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
177 hdr->seq_ctrl |= cpu_to_le16(sc->tx.seq_no);
180 bf->bf_buf_addr = dma_map_single(sc->dev, skb->data,
181 skb->len, DMA_TO_DEVICE);
182 if (unlikely(dma_mapping_error(sc->dev, bf->bf_buf_addr))) {
183 dev_kfree_skb_any(skb);
184 bf->bf_mpdu = NULL;
185 bf->bf_buf_addr = 0;
186 ath_err(common, "dma_mapping_error on beaconing\n");
187 return NULL;
190 skb = ieee80211_get_buffered_bc(hw, vif);
193 * if the CABQ traffic from previous DTIM is pending and the current
194 * beacon is also a DTIM.
195 * 1) if there is only one vif let the cab traffic continue.
196 * 2) if there are more than one vif and we are using staggered
197 * beacons, then drain the cabq by dropping all the frames in
198 * the cabq so that the current vifs cab traffic can be scheduled.
200 spin_lock_bh(&cabq->axq_lock);
201 cabq_depth = cabq->axq_depth;
202 spin_unlock_bh(&cabq->axq_lock);
204 if (skb && cabq_depth) {
205 if (sc->nvifs > 1) {
206 ath_dbg(common, BEACON,
207 "Flushing previous cabq traffic\n");
208 ath_draintxq(sc, cabq, false);
212 ath_beacon_setup(sc, vif, bf, info->control.rates[0].idx);
214 while (skb) {
215 ath_tx_cabq(hw, skb);
216 skb = ieee80211_get_buffered_bc(hw, vif);
219 return bf;
222 void ath9k_beacon_assign_slot(struct ath_softc *sc, struct ieee80211_vif *vif)
224 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
225 struct ath_vif *avp = (void *)vif->drv_priv;
226 int slot;
228 avp->av_bcbuf = list_first_entry(&sc->beacon.bbuf, struct ath_buf, list);
229 list_del(&avp->av_bcbuf->list);
231 for (slot = 0; slot < ATH_BCBUF; slot++) {
232 if (sc->beacon.bslot[slot] == NULL) {
233 avp->av_bslot = slot;
234 break;
238 sc->beacon.bslot[avp->av_bslot] = vif;
239 sc->nbcnvifs++;
241 ath_dbg(common, CONFIG, "Added interface at beacon slot: %d\n",
242 avp->av_bslot);
245 void ath9k_beacon_remove_slot(struct ath_softc *sc, struct ieee80211_vif *vif)
247 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
248 struct ath_vif *avp = (void *)vif->drv_priv;
249 struct ath_buf *bf = avp->av_bcbuf;
251 ath_dbg(common, CONFIG, "Removing interface at beacon slot: %d\n",
252 avp->av_bslot);
254 tasklet_disable(&sc->bcon_tasklet);
256 if (bf && bf->bf_mpdu) {
257 struct sk_buff *skb = bf->bf_mpdu;
258 dma_unmap_single(sc->dev, bf->bf_buf_addr,
259 skb->len, DMA_TO_DEVICE);
260 dev_kfree_skb_any(skb);
261 bf->bf_mpdu = NULL;
262 bf->bf_buf_addr = 0;
265 avp->av_bcbuf = NULL;
266 sc->beacon.bslot[avp->av_bslot] = NULL;
267 sc->nbcnvifs--;
268 list_add_tail(&bf->list, &sc->beacon.bbuf);
270 tasklet_enable(&sc->bcon_tasklet);
273 void ath_beacon_tasklet(unsigned long data)
275 struct ath_softc *sc = (struct ath_softc *)data;
276 struct ath_beacon_config *cur_conf = &sc->cur_beacon_conf;
277 struct ath_hw *ah = sc->sc_ah;
278 struct ath_common *common = ath9k_hw_common(ah);
279 struct ath_buf *bf = NULL;
280 struct ieee80211_vif *vif;
281 bool edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA);
282 int slot;
283 u32 bfaddr, bc = 0;
285 if (work_pending(&sc->hw_reset_work)) {
286 ath_dbg(common, RESET,
287 "reset work is pending, skip beaconing now\n");
288 return;
291 * Check if the previous beacon has gone out. If
292 * not don't try to post another, skip this period
293 * and wait for the next. Missed beacons indicate
294 * a problem and should not occur. If we miss too
295 * many consecutive beacons reset the device.
297 if (ath9k_hw_numtxpending(ah, sc->beacon.beaconq) != 0) {
298 sc->beacon.bmisscnt++;
300 if (!ath9k_hw_check_alive(ah))
301 ieee80211_queue_work(sc->hw, &sc->hw_check_work);
303 if (sc->beacon.bmisscnt < BSTUCK_THRESH * sc->nbcnvifs) {
304 ath_dbg(common, BSTUCK,
305 "missed %u consecutive beacons\n",
306 sc->beacon.bmisscnt);
307 ath9k_hw_stop_dma_queue(ah, sc->beacon.beaconq);
308 if (sc->beacon.bmisscnt > 3)
309 ath9k_hw_bstuck_nfcal(ah);
310 } else if (sc->beacon.bmisscnt >= BSTUCK_THRESH) {
311 ath_dbg(common, BSTUCK, "beacon is officially stuck\n");
312 sc->beacon.bmisscnt = 0;
313 ieee80211_queue_work(sc->hw, &sc->hw_reset_work);
316 return;
320 * Generate beacon frames. we are sending frames
321 * staggered so calculate the slot for this frame based
322 * on the tsf to safeguard against missing an swba.
326 if (ah->opmode == NL80211_IFTYPE_AP) {
327 u16 intval;
328 u32 tsftu;
329 u64 tsf;
331 intval = cur_conf->beacon_interval ? : ATH_DEFAULT_BINTVAL;
332 tsf = ath9k_hw_gettsf64(ah);
333 tsf += TU_TO_USEC(ah->config.sw_beacon_response_time);
334 tsftu = TSF_TO_TU((tsf * ATH_BCBUF) >>32, tsf * ATH_BCBUF);
335 slot = (tsftu % (intval * ATH_BCBUF)) / intval;
336 vif = sc->beacon.bslot[slot];
338 ath_dbg(common, BEACON,
339 "slot %d [tsf %llu tsftu %u intval %u] vif %p\n",
340 slot, tsf, tsftu / ATH_BCBUF, intval, vif);
341 } else {
342 slot = 0;
343 vif = sc->beacon.bslot[slot];
347 bfaddr = 0;
348 if (vif) {
349 bf = ath_beacon_generate(sc->hw, vif);
350 if (bf != NULL) {
351 bfaddr = bf->bf_daddr;
352 bc = 1;
355 if (sc->beacon.bmisscnt != 0) {
356 ath_dbg(common, BSTUCK,
357 "resume beacon xmit after %u misses\n",
358 sc->beacon.bmisscnt);
359 sc->beacon.bmisscnt = 0;
364 * Handle slot time change when a non-ERP station joins/leaves
365 * an 11g network. The 802.11 layer notifies us via callback,
366 * we mark updateslot, then wait one beacon before effecting
367 * the change. This gives associated stations at least one
368 * beacon interval to note the state change.
370 * NB: The slot time change state machine is clocked according
371 * to whether we are bursting or staggering beacons. We
372 * recognize the request to update and record the current
373 * slot then don't transition until that slot is reached
374 * again. If we miss a beacon for that slot then we'll be
375 * slow to transition but we'll be sure at least one beacon
376 * interval has passed. When bursting slot is always left
377 * set to ATH_BCBUF so this check is a noop.
379 if (sc->beacon.updateslot == UPDATE) {
380 sc->beacon.updateslot = COMMIT; /* commit next beacon */
381 sc->beacon.slotupdate = slot;
382 } else if (sc->beacon.updateslot == COMMIT && sc->beacon.slotupdate == slot) {
383 ah->slottime = sc->beacon.slottime;
384 ath9k_hw_init_global_settings(ah);
385 sc->beacon.updateslot = OK;
387 if (bfaddr != 0) {
388 /* NB: cabq traffic should already be queued and primed */
389 ath9k_hw_puttxbuf(ah, sc->beacon.beaconq, bfaddr);
391 if (!edma)
392 ath9k_hw_txstart(ah, sc->beacon.beaconq);
394 sc->beacon.ast_be_xmit += bc; /* XXX per-vif? */
398 static void ath9k_beacon_init(struct ath_softc *sc, u32 nexttbtt, u32 intval)
400 struct ath_hw *ah = sc->sc_ah;
402 ath9k_hw_disable_interrupts(ah);
403 ath9k_hw_reset_tsf(ah);
404 ath9k_hw_beaconinit(ah, nexttbtt, intval);
405 sc->beacon.bmisscnt = 0;
406 ath9k_hw_set_interrupts(ah);
407 ath9k_hw_enable_interrupts(ah);
411 * For multi-bss ap support beacons are either staggered evenly over N slots or
412 * burst together. For the former arrange for the SWBA to be delivered for each
413 * slot. Slots that are not occupied will generate nothing.
415 static void ath9k_beacon_config_ap(struct ath_softc *sc,
416 struct ath_beacon_config *conf)
418 struct ath_hw *ah = sc->sc_ah;
419 struct ath_common *common = ath9k_hw_common(ah);
420 u32 nexttbtt, intval;
422 /* NB: the beacon interval is kept internally in TU's */
423 intval = TU_TO_USEC(conf->beacon_interval);
424 intval /= ATH_BCBUF;
425 nexttbtt = intval;
427 if (conf->enable_beacon)
428 ah->imask |= ATH9K_INT_SWBA;
429 else
430 ah->imask &= ~ATH9K_INT_SWBA;
432 ath_dbg(common, BEACON, "AP nexttbtt: %u intval: %u conf_intval: %u\n",
433 nexttbtt, intval, conf->beacon_interval);
435 ath_beaconq_config(sc);
436 ath9k_beacon_init(sc, nexttbtt, intval);
440 * This sets up the beacon timers according to the timestamp of the last
441 * received beacon and the current TSF, configures PCF and DTIM
442 * handling, programs the sleep registers so the hardware will wakeup in
443 * time to receive beacons, and configures the beacon miss handling so
444 * we'll receive a BMISS interrupt when we stop seeing beacons from the AP
445 * we've associated with.
447 static void ath9k_beacon_config_sta(struct ath_softc *sc,
448 struct ath_beacon_config *conf)
450 struct ath_hw *ah = sc->sc_ah;
451 struct ath_common *common = ath9k_hw_common(ah);
452 struct ath9k_beacon_state bs;
453 int dtimperiod, dtimcount, sleepduration;
454 int cfpperiod, cfpcount;
455 u32 nexttbtt = 0, intval, tsftu;
456 u64 tsf;
457 int num_beacons, offset, dtim_dec_count, cfp_dec_count;
459 /* No need to configure beacon if we are not associated */
460 if (!test_bit(SC_OP_PRIM_STA_VIF, &sc->sc_flags)) {
461 ath_dbg(common, BEACON,
462 "STA is not yet associated..skipping beacon config\n");
463 return;
466 memset(&bs, 0, sizeof(bs));
467 intval = conf->beacon_interval;
470 * Setup dtim and cfp parameters according to
471 * last beacon we received (which may be none).
473 dtimperiod = conf->dtim_period;
474 dtimcount = conf->dtim_count;
475 if (dtimcount >= dtimperiod) /* NB: sanity check */
476 dtimcount = 0;
477 cfpperiod = 1; /* NB: no PCF support yet */
478 cfpcount = 0;
480 sleepduration = conf->listen_interval * intval;
483 * Pull nexttbtt forward to reflect the current
484 * TSF and calculate dtim+cfp state for the result.
486 tsf = ath9k_hw_gettsf64(ah);
487 tsftu = TSF_TO_TU(tsf>>32, tsf) + FUDGE;
489 num_beacons = tsftu / intval + 1;
490 offset = tsftu % intval;
491 nexttbtt = tsftu - offset;
492 if (offset)
493 nexttbtt += intval;
495 /* DTIM Beacon every dtimperiod Beacon */
496 dtim_dec_count = num_beacons % dtimperiod;
497 /* CFP every cfpperiod DTIM Beacon */
498 cfp_dec_count = (num_beacons / dtimperiod) % cfpperiod;
499 if (dtim_dec_count)
500 cfp_dec_count++;
502 dtimcount -= dtim_dec_count;
503 if (dtimcount < 0)
504 dtimcount += dtimperiod;
506 cfpcount -= cfp_dec_count;
507 if (cfpcount < 0)
508 cfpcount += cfpperiod;
510 bs.bs_intval = intval;
511 bs.bs_nexttbtt = nexttbtt;
512 bs.bs_dtimperiod = dtimperiod*intval;
513 bs.bs_nextdtim = bs.bs_nexttbtt + dtimcount*intval;
514 bs.bs_cfpperiod = cfpperiod*bs.bs_dtimperiod;
515 bs.bs_cfpnext = bs.bs_nextdtim + cfpcount*bs.bs_dtimperiod;
516 bs.bs_cfpmaxduration = 0;
519 * Calculate the number of consecutive beacons to miss* before taking
520 * a BMISS interrupt. The configuration is specified in TU so we only
521 * need calculate based on the beacon interval. Note that we clamp the
522 * result to at most 15 beacons.
524 if (sleepduration > intval) {
525 bs.bs_bmissthreshold = conf->listen_interval *
526 ATH_DEFAULT_BMISS_LIMIT / 2;
527 } else {
528 bs.bs_bmissthreshold = DIV_ROUND_UP(conf->bmiss_timeout, intval);
529 if (bs.bs_bmissthreshold > 15)
530 bs.bs_bmissthreshold = 15;
531 else if (bs.bs_bmissthreshold <= 0)
532 bs.bs_bmissthreshold = 1;
536 * Calculate sleep duration. The configuration is given in ms.
537 * We ensure a multiple of the beacon period is used. Also, if the sleep
538 * duration is greater than the DTIM period then it makes senses
539 * to make it a multiple of that.
541 * XXX fixed at 100ms
544 bs.bs_sleepduration = roundup(IEEE80211_MS_TO_TU(100), sleepduration);
545 if (bs.bs_sleepduration > bs.bs_dtimperiod)
546 bs.bs_sleepduration = bs.bs_dtimperiod;
548 /* TSF out of range threshold fixed at 1 second */
549 bs.bs_tsfoor_threshold = ATH9K_TSFOOR_THRESHOLD;
551 ath_dbg(common, BEACON, "tsf: %llu tsftu: %u\n", tsf, tsftu);
552 ath_dbg(common, BEACON,
553 "bmiss: %u sleep: %u cfp-period: %u maxdur: %u next: %u\n",
554 bs.bs_bmissthreshold, bs.bs_sleepduration,
555 bs.bs_cfpperiod, bs.bs_cfpmaxduration, bs.bs_cfpnext);
557 /* Set the computed STA beacon timers */
559 ath9k_hw_disable_interrupts(ah);
560 ath9k_hw_set_sta_beacon_timers(ah, &bs);
561 ah->imask |= ATH9K_INT_BMISS;
563 ath9k_hw_set_interrupts(ah);
564 ath9k_hw_enable_interrupts(ah);
567 static void ath9k_beacon_config_adhoc(struct ath_softc *sc,
568 struct ath_beacon_config *conf)
570 struct ath_hw *ah = sc->sc_ah;
571 struct ath_common *common = ath9k_hw_common(ah);
572 u32 intval, nexttbtt;
574 ath9k_reset_beacon_status(sc);
576 intval = TU_TO_USEC(conf->beacon_interval);
577 nexttbtt = intval;
579 if (conf->enable_beacon)
580 ah->imask |= ATH9K_INT_SWBA;
581 else
582 ah->imask &= ~ATH9K_INT_SWBA;
584 ath_dbg(common, BEACON, "IBSS nexttbtt: %u intval: %u conf_intval: %u\n",
585 nexttbtt, intval, conf->beacon_interval);
587 ath_beaconq_config(sc);
588 ath9k_beacon_init(sc, nexttbtt, intval);
591 bool ath9k_allow_beacon_config(struct ath_softc *sc, struct ieee80211_vif *vif)
593 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
594 struct ath_vif *avp = (void *)vif->drv_priv;
596 if (sc->sc_ah->opmode == NL80211_IFTYPE_AP) {
597 if ((vif->type != NL80211_IFTYPE_AP) ||
598 (sc->nbcnvifs > 1)) {
599 ath_dbg(common, CONFIG,
600 "An AP interface is already present !\n");
601 return false;
605 if (sc->sc_ah->opmode == NL80211_IFTYPE_STATION) {
606 if ((vif->type == NL80211_IFTYPE_STATION) &&
607 test_bit(SC_OP_BEACONS, &sc->sc_flags) &&
608 !avp->primary_sta_vif) {
609 ath_dbg(common, CONFIG,
610 "Beacon already configured for a station interface\n");
611 return false;
615 return true;
618 static void ath9k_cache_beacon_config(struct ath_softc *sc,
619 struct ieee80211_bss_conf *bss_conf)
621 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
622 struct ath_beacon_config *cur_conf = &sc->cur_beacon_conf;
624 ath_dbg(common, BEACON,
625 "Caching beacon data for BSS: %pM\n", bss_conf->bssid);
627 cur_conf->beacon_interval = bss_conf->beacon_int;
628 cur_conf->dtim_period = bss_conf->dtim_period;
629 cur_conf->listen_interval = 1;
630 cur_conf->dtim_count = 1;
631 cur_conf->bmiss_timeout =
632 ATH_DEFAULT_BMISS_LIMIT * cur_conf->beacon_interval;
635 * It looks like mac80211 may end up using beacon interval of zero in
636 * some cases (at least for mesh point). Avoid getting into an
637 * infinite loop by using a bit safer value instead. To be safe,
638 * do sanity check on beacon interval for all operating modes.
640 if (cur_conf->beacon_interval == 0)
641 cur_conf->beacon_interval = 100;
644 * We don't parse dtim period from mac80211 during the driver
645 * initialization as it breaks association with hidden-ssid
646 * AP and it causes latency in roaming
648 if (cur_conf->dtim_period == 0)
649 cur_conf->dtim_period = 1;
653 void ath9k_beacon_config(struct ath_softc *sc, struct ieee80211_vif *vif,
654 u32 changed)
656 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
657 struct ath_beacon_config *cur_conf = &sc->cur_beacon_conf;
659 if (sc->sc_ah->opmode == NL80211_IFTYPE_STATION) {
660 ath9k_cache_beacon_config(sc, bss_conf);
661 ath9k_set_beacon(sc);
662 set_bit(SC_OP_BEACONS, &sc->sc_flags);
663 } else {
665 * Take care of multiple interfaces when
666 * enabling/disabling SWBA.
668 if (changed & BSS_CHANGED_BEACON_ENABLED) {
669 if (!bss_conf->enable_beacon &&
670 (sc->nbcnvifs <= 1)) {
671 cur_conf->enable_beacon = false;
672 } else if (bss_conf->enable_beacon) {
673 cur_conf->enable_beacon = true;
674 ath9k_cache_beacon_config(sc, bss_conf);
678 if (cur_conf->beacon_interval) {
679 ath9k_set_beacon(sc);
681 if (cur_conf->enable_beacon)
682 set_bit(SC_OP_BEACONS, &sc->sc_flags);
683 else
684 clear_bit(SC_OP_BEACONS, &sc->sc_flags);
689 void ath9k_set_beacon(struct ath_softc *sc)
691 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
692 struct ath_beacon_config *cur_conf = &sc->cur_beacon_conf;
694 switch (sc->sc_ah->opmode) {
695 case NL80211_IFTYPE_AP:
696 ath9k_beacon_config_ap(sc, cur_conf);
697 break;
698 case NL80211_IFTYPE_ADHOC:
699 case NL80211_IFTYPE_MESH_POINT:
700 ath9k_beacon_config_adhoc(sc, cur_conf);
701 break;
702 case NL80211_IFTYPE_STATION:
703 ath9k_beacon_config_sta(sc, cur_conf);
704 break;
705 default:
706 ath_dbg(common, CONFIG, "Unsupported beaconing mode\n");
707 return;