blob: 349904c761e4cb4ac251fd21d771e90fb74300b4 [file] [log] [blame]
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001/*
2 * Copyright (c) 2008 Atheros Communications Inc.
3 *
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.
7 *
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.
15 */
16
Sujith394cf0a2009-02-09 13:26:54 +053017#include "ath9k.h"
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070018
19/*
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070020 * 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
23*/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070024static int ath_beaconq_config(struct ath_softc *sc)
25{
Sujithcbe61d82009-02-09 13:27:12 +053026 struct ath_hw *ah = sc->sc_ah;
Sujithea9880f2008-08-07 10:53:10 +053027 struct ath9k_tx_queue_info qi;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070028
Sujithb77f4832008-12-07 21:44:03 +053029 ath9k_hw_get_txq_props(ah, sc->beacon.beaconq, &qi);
Sujith2660b812009-02-09 13:27:26 +053030 if (sc->sc_ah->opmode == NL80211_IFTYPE_AP) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070031 /* Always burst out beacon and CAB traffic. */
32 qi.tqi_aifs = 1;
33 qi.tqi_cwmin = 0;
34 qi.tqi_cwmax = 0;
35 } else {
36 /* Adhoc mode; important thing is to use 2x cwmin. */
Sujithb77f4832008-12-07 21:44:03 +053037 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;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070040 }
41
Sujithb77f4832008-12-07 21:44:03 +053042 if (!ath9k_hw_set_txq_props(ah, sc->beacon.beaconq, &qi)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070043 DPRINTF(sc, ATH_DBG_FATAL,
Sujith04bd4632008-11-28 22:18:05 +053044 "unable to update h/w beacon queue parameters\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070045 return 0;
46 } else {
Sujith9fc9ab02009-03-03 10:16:51 +053047 ath9k_hw_resettxqueue(ah, sc->beacon.beaconq);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070048 return 1;
49 }
50}
51
52/*
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070053 * 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.
56*/
Sujith9fc9ab02009-03-03 10:16:51 +053057static void ath_beacon_setup(struct ath_softc *sc, struct ath_vif *avp,
58 struct ath_buf *bf)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070059{
60 struct sk_buff *skb = (struct sk_buff *)bf->bf_mpdu;
Sujithcbe61d82009-02-09 13:27:12 +053061 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070062 struct ath_desc *ds;
Sujith980b24d2008-09-17 10:15:09 +053063 struct ath9k_11n_rate_series series[4];
Sujithe63835b2008-11-18 09:07:53 +053064 struct ath_rate_table *rt;
Sujith9fc9ab02009-03-03 10:16:51 +053065 int flags, antenna, ctsrate = 0, ctsduration = 0;
66 u8 rate;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070067
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070068 ds = bf->bf_desc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070069 flags = ATH9K_TXDESC_NOACK;
70
Sujith2660b812009-02-09 13:27:26 +053071 if (sc->sc_ah->opmode == NL80211_IFTYPE_ADHOC &&
72 (ah->caps.hw_caps & ATH9K_HW_CAP_VEOL)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070073 ds->ds_link = bf->bf_daddr; /* self-linked */
74 flags |= ATH9K_TXDESC_VEOL;
75 /* Let hardware handle antenna switching. */
76 antenna = 0;
77 } else {
78 ds->ds_link = 0;
79 /*
80 * Switch antenna every beacon.
Sujith9fc9ab02009-03-03 10:16:51 +053081 * Should only switch every beacon period, not for every SWBA
82 * XXX assumes two antennae
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070083 */
Sujith17d79042009-02-09 13:27:03 +053084 antenna = ((sc->beacon.ast_be_xmit / sc->nbcnvifs) & 1 ? 2 : 1);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070085 }
86
87 ds->ds_data = bf->bf_buf_addr;
88
Sujith3706de62008-12-07 21:42:10 +053089 rt = sc->cur_rate_table;
Sujith9fc9ab02009-03-03 10:16:51 +053090 rate = rt->info[0].ratecode;
Sujith672840a2008-08-11 14:05:08 +053091 if (sc->sc_flags & SC_OP_PREAMBLE_SHORT)
Sujith9fc9ab02009-03-03 10:16:51 +053092 rate |= rt->info[0].short_preamble;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070093
Sujith9fc9ab02009-03-03 10:16:51 +053094 ath9k_hw_set11n_txdesc(ah, ds, skb->len + FCS_LEN,
95 ATH9K_PKT_TYPE_BEACON,
96 MAX_RATE_POWER,
97 ATH9K_TXKEYIX_INVALID,
98 ATH9K_KEY_TYPE_CLEAR,
99 flags);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700100
101 /* NB: beacon's BufLen must be a multiple of 4 bytes */
Sujith9fc9ab02009-03-03 10:16:51 +0530102 ath9k_hw_filltxdesc(ah, ds, roundup(skb->len, 4),
103 true, true, ds);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700104
Luis R. Rodriguez0345f372008-10-03 15:45:25 -0700105 memset(series, 0, sizeof(struct ath9k_11n_rate_series) * 4);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700106 series[0].Tries = 1;
107 series[0].Rate = rate;
Sujith17d79042009-02-09 13:27:03 +0530108 series[0].ChSel = sc->tx_chainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700109 series[0].RateFlags = (ctsrate) ? ATH9K_RATESERIES_RTS_CTS : 0;
Sujith9fc9ab02009-03-03 10:16:51 +0530110 ath9k_hw_set11n_ratescenario(ah, ds, ds, 0, ctsrate, ctsduration,
111 series, 4, 0);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700112}
113
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700114static struct ath_buf *ath_beacon_generate(struct ath_softc *sc, int if_id)
115{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700116 struct ath_buf *bf;
Sujith17d79042009-02-09 13:27:03 +0530117 struct ath_vif *avp;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700118 struct sk_buff *skb;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700119 struct ath_txq *cabq;
Sujith5640b082008-10-29 10:16:06 +0530120 struct ieee80211_vif *vif;
Jouni Malinen147583c2008-08-11 14:01:50 +0300121 struct ieee80211_tx_info *info;
Sujith980b24d2008-09-17 10:15:09 +0530122 int cabq_depth;
123
Sujith17d79042009-02-09 13:27:03 +0530124 vif = sc->vifs[if_id];
Sujith5640b082008-10-29 10:16:06 +0530125 avp = (void *)vif->drv_priv;
Sujithb77f4832008-12-07 21:44:03 +0530126 cabq = sc->beacon.cabq;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700127
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700128 if (avp->av_bcbuf == NULL) {
Sujith04bd4632008-11-28 22:18:05 +0530129 DPRINTF(sc, ATH_DBG_BEACON, "avp=%p av_bcbuf=%p\n",
130 avp, avp->av_bcbuf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700131 return NULL;
132 }
Sujith980b24d2008-09-17 10:15:09 +0530133
Sujith9fc9ab02009-03-03 10:16:51 +0530134 /* Release the old beacon first */
135
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700136 bf = avp->av_bcbuf;
Sujith980b24d2008-09-17 10:15:09 +0530137 skb = (struct sk_buff *)bf->bf_mpdu;
Jouni Malinena8fff502008-08-11 14:01:48 +0300138 if (skb) {
Gabor Juhos7da3c552009-01-14 20:17:03 +0100139 dma_unmap_single(sc->dev, bf->bf_dmacontext,
Sujith9fc9ab02009-03-03 10:16:51 +0530140 skb->len, DMA_TO_DEVICE);
Jouni Malinen3fbb9d92008-12-05 20:42:45 +0200141 dev_kfree_skb_any(skb);
Jouni Malinena8fff502008-08-11 14:01:48 +0300142 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700143
Sujith9fc9ab02009-03-03 10:16:51 +0530144 /* Get a new beacon from mac80211 */
145
Sujith5640b082008-10-29 10:16:06 +0530146 skb = ieee80211_beacon_get(sc->hw, vif);
Jouni Malinena8fff502008-08-11 14:01:48 +0300147 bf->bf_mpdu = skb;
148 if (skb == NULL)
149 return NULL;
Sujith980b24d2008-09-17 10:15:09 +0530150
Jouni Malinen147583c2008-08-11 14:01:50 +0300151 info = IEEE80211_SKB_CB(skb);
152 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
153 /*
154 * TODO: make sure the seq# gets assigned properly (vs. other
155 * TX frames)
156 */
Sujith980b24d2008-09-17 10:15:09 +0530157 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Sujithb77f4832008-12-07 21:44:03 +0530158 sc->tx.seq_no += 0x10;
Jouni Malinen147583c2008-08-11 14:01:50 +0300159 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
Sujithb77f4832008-12-07 21:44:03 +0530160 hdr->seq_ctrl |= cpu_to_le16(sc->tx.seq_no);
Jouni Malinen147583c2008-08-11 14:01:50 +0300161 }
Sujith980b24d2008-09-17 10:15:09 +0530162
Jouni Malinena8fff502008-08-11 14:01:48 +0300163 bf->bf_buf_addr = bf->bf_dmacontext =
Gabor Juhos7da3c552009-01-14 20:17:03 +0100164 dma_map_single(sc->dev, skb->data,
Sujith9fc9ab02009-03-03 10:16:51 +0530165 skb->len, DMA_TO_DEVICE);
Gabor Juhos7da3c552009-01-14 20:17:03 +0100166 if (unlikely(dma_mapping_error(sc->dev, bf->bf_buf_addr))) {
Luis R. Rodriguezf8316df2008-12-03 03:35:29 -0800167 dev_kfree_skb_any(skb);
168 bf->bf_mpdu = NULL;
Sujith9fc9ab02009-03-03 10:16:51 +0530169 DPRINTF(sc, ATH_DBG_FATAL, "dma_mapping_error on beaconing\n");
Luis R. Rodriguezf8316df2008-12-03 03:35:29 -0800170 return NULL;
171 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700172
Sujith5640b082008-10-29 10:16:06 +0530173 skb = ieee80211_get_buffered_bc(sc->hw, vif);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700174
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700175 /*
176 * if the CABQ traffic from previous DTIM is pending and the current
177 * beacon is also a DTIM.
Sujith17d79042009-02-09 13:27:03 +0530178 * 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
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700180 * beacons, then drain the cabq by dropping all the frames in
Sujith17d79042009-02-09 13:27:03 +0530181 * the cabq so that the current vifs cab traffic can be scheduled.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700182 */
183 spin_lock_bh(&cabq->axq_lock);
184 cabq_depth = cabq->axq_depth;
185 spin_unlock_bh(&cabq->axq_lock);
186
Jouni Malinene022edb2008-08-22 17:31:33 +0300187 if (skb && cabq_depth) {
Sujith17d79042009-02-09 13:27:03 +0530188 if (sc->nvifs > 1) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700189 DPRINTF(sc, ATH_DBG_BEACON,
Sujith9fc9ab02009-03-03 10:16:51 +0530190 "Flushing previous cabq traffic\n");
191 ath_draintxq(sc, cabq, false);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700192 }
193 }
194
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700195 ath_beacon_setup(sc, avp, bf);
196
Jouni Malinene022edb2008-08-22 17:31:33 +0300197 while (skb) {
198 ath_tx_cabq(sc, skb);
Sujith5640b082008-10-29 10:16:06 +0530199 skb = ieee80211_get_buffered_bc(sc->hw, vif);
Jouni Malinene022edb2008-08-22 17:31:33 +0300200 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700201
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700202 return bf;
203}
204
205/*
206 * Startup beacon transmission for adhoc mode when they are sent entirely
207 * by the hardware using the self-linked descriptor + veol trick.
208*/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700209static void ath_beacon_start_adhoc(struct ath_softc *sc, int if_id)
210{
Sujith5640b082008-10-29 10:16:06 +0530211 struct ieee80211_vif *vif;
Sujithcbe61d82009-02-09 13:27:12 +0530212 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700213 struct ath_buf *bf;
Sujith17d79042009-02-09 13:27:03 +0530214 struct ath_vif *avp;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700215 struct sk_buff *skb;
216
Sujith17d79042009-02-09 13:27:03 +0530217 vif = sc->vifs[if_id];
Sujith5640b082008-10-29 10:16:06 +0530218 avp = (void *)vif->drv_priv;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700219
Sujith9fc9ab02009-03-03 10:16:51 +0530220 if (avp->av_bcbuf == NULL)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700221 return;
Sujith9fc9ab02009-03-03 10:16:51 +0530222
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700223 bf = avp->av_bcbuf;
224 skb = (struct sk_buff *) bf->bf_mpdu;
225
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700226 ath_beacon_setup(sc, avp, bf);
227
228 /* NB: caller is known to have already stopped tx dma */
Sujithb77f4832008-12-07 21:44:03 +0530229 ath9k_hw_puttxbuf(ah, sc->beacon.beaconq, bf->bf_daddr);
230 ath9k_hw_txstart(ah, sc->beacon.beaconq);
Sujith04bd4632008-11-28 22:18:05 +0530231 DPRINTF(sc, ATH_DBG_BEACON, "TXDP%u = %llx (%p)\n",
Sujithb77f4832008-12-07 21:44:03 +0530232 sc->beacon.beaconq, ito64(bf->bf_daddr), bf->bf_desc);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700233}
234
Sujithcbe61d82009-02-09 13:27:12 +0530235int ath_beaconq_setup(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700236{
Sujithea9880f2008-08-07 10:53:10 +0530237 struct ath9k_tx_queue_info qi;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700238
Luis R. Rodriguez0345f372008-10-03 15:45:25 -0700239 memset(&qi, 0, sizeof(qi));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700240 qi.tqi_aifs = 1;
241 qi.tqi_cwmin = 0;
242 qi.tqi_cwmax = 0;
243 /* NB: don't enable any interrupts */
244 return ath9k_hw_setuptxqueue(ah, ATH9K_TX_QUEUE_BEACON, &qi);
245}
246
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700247int ath_beacon_alloc(struct ath_softc *sc, int if_id)
248{
Sujith5640b082008-10-29 10:16:06 +0530249 struct ieee80211_vif *vif;
Sujith17d79042009-02-09 13:27:03 +0530250 struct ath_vif *avp;
Sujith980b24d2008-09-17 10:15:09 +0530251 struct ieee80211_hdr *hdr;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700252 struct ath_buf *bf;
253 struct sk_buff *skb;
Sujith459f5f92008-09-17 10:15:36 +0530254 __le64 tstamp;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700255
Sujith17d79042009-02-09 13:27:03 +0530256 vif = sc->vifs[if_id];
Sujith5640b082008-10-29 10:16:06 +0530257 avp = (void *)vif->drv_priv;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700258
259 /* Allocate a beacon descriptor if we haven't done so. */
260 if (!avp->av_bcbuf) {
Sujith980b24d2008-09-17 10:15:09 +0530261 /* Allocate beacon state for hostap/ibss. We know
262 * a buffer is available. */
Sujithb77f4832008-12-07 21:44:03 +0530263 avp->av_bcbuf = list_first_entry(&sc->beacon.bbuf,
Sujith980b24d2008-09-17 10:15:09 +0530264 struct ath_buf, list);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700265 list_del(&avp->av_bcbuf->list);
266
Sujith2660b812009-02-09 13:27:26 +0530267 if (sc->sc_ah->opmode == NL80211_IFTYPE_AP ||
268 !(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_VEOL)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700269 int slot;
270 /*
Sujith17d79042009-02-09 13:27:03 +0530271 * Assign the vif to a beacon xmit slot. As
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700272 * above, this cannot fail to find one.
273 */
274 avp->av_bslot = 0;
275 for (slot = 0; slot < ATH_BCBUF; slot++)
Sujithb77f4832008-12-07 21:44:03 +0530276 if (sc->beacon.bslot[slot] == ATH_IF_ID_ANY) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700277 /*
278 * XXX hack, space out slots to better
279 * deal with misses
280 */
281 if (slot+1 < ATH_BCBUF &&
Sujithb77f4832008-12-07 21:44:03 +0530282 sc->beacon.bslot[slot+1] ==
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700283 ATH_IF_ID_ANY) {
284 avp->av_bslot = slot+1;
285 break;
286 }
287 avp->av_bslot = slot;
288 /* NB: keep looking for a double slot */
289 }
Sujithb77f4832008-12-07 21:44:03 +0530290 BUG_ON(sc->beacon.bslot[avp->av_bslot] != ATH_IF_ID_ANY);
291 sc->beacon.bslot[avp->av_bslot] = if_id;
Sujith17d79042009-02-09 13:27:03 +0530292 sc->nbcnvifs++;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700293 }
294 }
295
Sujith9fc9ab02009-03-03 10:16:51 +0530296 /* release the previous beacon frame, if it already exists. */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700297 bf = avp->av_bcbuf;
298 if (bf->bf_mpdu != NULL) {
299 skb = (struct sk_buff *)bf->bf_mpdu;
Gabor Juhos7da3c552009-01-14 20:17:03 +0100300 dma_unmap_single(sc->dev, bf->bf_dmacontext,
Sujith9fc9ab02009-03-03 10:16:51 +0530301 skb->len, DMA_TO_DEVICE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700302 dev_kfree_skb_any(skb);
303 bf->bf_mpdu = NULL;
304 }
305
Sujith9fc9ab02009-03-03 10:16:51 +0530306 /* NB: the beacon data buffer must be 32-bit aligned. */
Sujith5640b082008-10-29 10:16:06 +0530307 skb = ieee80211_beacon_get(sc->hw, vif);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700308 if (skb == NULL) {
Sujith04bd4632008-11-28 22:18:05 +0530309 DPRINTF(sc, ATH_DBG_BEACON, "cannot get skb\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700310 return -ENOMEM;
311 }
312
Sujith459f5f92008-09-17 10:15:36 +0530313 tstamp = ((struct ieee80211_mgmt *)skb->data)->u.beacon.timestamp;
Sujithb77f4832008-12-07 21:44:03 +0530314 sc->beacon.bc_tstamp = le64_to_cpu(tstamp);
Sujith459f5f92008-09-17 10:15:36 +0530315
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700316 /*
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.
321 */
322 if (avp->av_bslot > 0) {
323 u64 tsfadjust;
324 __le64 val;
325 int intval;
326
Jouni Malinena8fff502008-08-11 14:01:48 +0300327 intval = sc->hw->conf.beacon_int ?
328 sc->hw->conf.beacon_int : ATH_DEFAULT_BINTVAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700329
330 /*
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
Sujith17d79042009-02-09 13:27:03 +0530336 * frame is sent. Note that we align vif's 1..N
337 * and leave vif 0 untouched. This means vap 0
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700338 * has a timestamp in one beacon interval while the
339 * others get a timestamp aligned to the next interval.
340 */
341 tsfadjust = (intval * (ATH_BCBUF - avp->av_bslot)) / ATH_BCBUF;
342 val = cpu_to_le64(tsfadjust << 10); /* TU->TSF */
343
344 DPRINTF(sc, ATH_DBG_BEACON,
Sujith04bd4632008-11-28 22:18:05 +0530345 "stagger beacons, bslot %d intval %u tsfadjust %llu\n",
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700346 avp->av_bslot, intval, (unsigned long long)tsfadjust);
347
Sujith980b24d2008-09-17 10:15:09 +0530348 hdr = (struct ieee80211_hdr *)skb->data;
349 memcpy(&hdr[1], &val, sizeof(val));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700350 }
351
Luis R. Rodriguezf8316df2008-12-03 03:35:29 -0800352 bf->bf_mpdu = skb;
Jouni Malinena8fff502008-08-11 14:01:48 +0300353 bf->bf_buf_addr = bf->bf_dmacontext =
Gabor Juhos7da3c552009-01-14 20:17:03 +0100354 dma_map_single(sc->dev, skb->data,
Sujith9fc9ab02009-03-03 10:16:51 +0530355 skb->len, DMA_TO_DEVICE);
Gabor Juhos7da3c552009-01-14 20:17:03 +0100356 if (unlikely(dma_mapping_error(sc->dev, bf->bf_buf_addr))) {
Luis R. Rodriguezf8316df2008-12-03 03:35:29 -0800357 dev_kfree_skb_any(skb);
358 bf->bf_mpdu = NULL;
Sujith9fc9ab02009-03-03 10:16:51 +0530359 DPRINTF(sc, ATH_DBG_FATAL,
360 "dma_mapping_error on beacon alloc\n");
Luis R. Rodriguezf8316df2008-12-03 03:35:29 -0800361 return -ENOMEM;
362 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700363
364 return 0;
365}
366
Sujith17d79042009-02-09 13:27:03 +0530367void ath_beacon_return(struct ath_softc *sc, struct ath_vif *avp)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700368{
369 if (avp->av_bcbuf != NULL) {
370 struct ath_buf *bf;
371
372 if (avp->av_bslot != -1) {
Sujithb77f4832008-12-07 21:44:03 +0530373 sc->beacon.bslot[avp->av_bslot] = ATH_IF_ID_ANY;
Sujith17d79042009-02-09 13:27:03 +0530374 sc->nbcnvifs--;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700375 }
376
377 bf = avp->av_bcbuf;
378 if (bf->bf_mpdu != NULL) {
379 struct sk_buff *skb = (struct sk_buff *)bf->bf_mpdu;
Gabor Juhos7da3c552009-01-14 20:17:03 +0100380 dma_unmap_single(sc->dev, bf->bf_dmacontext,
Sujith9fc9ab02009-03-03 10:16:51 +0530381 skb->len, DMA_TO_DEVICE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700382 dev_kfree_skb_any(skb);
383 bf->bf_mpdu = NULL;
384 }
Sujithb77f4832008-12-07 21:44:03 +0530385 list_add_tail(&bf->list, &sc->beacon.bbuf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700386
387 avp->av_bcbuf = NULL;
388 }
389}
390
Sujith9fc9ab02009-03-03 10:16:51 +0530391void ath_beacon_tasklet(unsigned long data)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700392{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700393 struct ath_softc *sc = (struct ath_softc *)data;
Sujithcbe61d82009-02-09 13:27:12 +0530394 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700395 struct ath_buf *bf = NULL;
396 int slot, if_id;
Sujith9546aae2009-03-03 10:16:53 +0530397 u32 bfaddr, bc = 0, tsftu;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700398 u64 tsf;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700399 u16 intval;
400
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700401 /*
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.
407 */
Sujithb77f4832008-12-07 21:44:03 +0530408 if (ath9k_hw_numtxpending(ah, sc->beacon.beaconq) != 0) {
409 sc->beacon.bmisscnt++;
Sujith9546aae2009-03-03 10:16:53 +0530410
Sujithb77f4832008-12-07 21:44:03 +0530411 if (sc->beacon.bmisscnt < BSTUCK_THRESH) {
Sujith9546aae2009-03-03 10:16:53 +0530412 DPRINTF(sc, ATH_DBG_BEACON,
413 "missed %u consecutive beacons\n",
414 sc->beacon.bmisscnt);
Sujithb77f4832008-12-07 21:44:03 +0530415 } else if (sc->beacon.bmisscnt >= BSTUCK_THRESH) {
Sujith9546aae2009-03-03 10:16:53 +0530416 DPRINTF(sc, ATH_DBG_BEACON,
417 "beacon is officially stuck\n");
418 ath_reset(sc, false);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700419 }
Sujith9546aae2009-03-03 10:16:53 +0530420
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700421 return;
422 }
Sujith980b24d2008-09-17 10:15:09 +0530423
Sujithb77f4832008-12-07 21:44:03 +0530424 if (sc->beacon.bmisscnt != 0) {
Sujith9546aae2009-03-03 10:16:53 +0530425 DPRINTF(sc, ATH_DBG_BEACON,
426 "resume beacon xmit after %u misses\n",
427 sc->beacon.bmisscnt);
Sujithb77f4832008-12-07 21:44:03 +0530428 sc->beacon.bmisscnt = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700429 }
430
431 /*
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.
435 */
436
Jouni Malinena8fff502008-08-11 14:01:48 +0300437 intval = sc->hw->conf.beacon_int ?
438 sc->hw->conf.beacon_int : ATH_DEFAULT_BINTVAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700439
440 tsf = ath9k_hw_gettsf64(ah);
441 tsftu = TSF_TO_TU(tsf>>32, tsf);
442 slot = ((tsftu % intval) * ATH_BCBUF) / intval;
Sujithb77f4832008-12-07 21:44:03 +0530443 if_id = sc->beacon.bslot[(slot + 1) % ATH_BCBUF];
Sujith980b24d2008-09-17 10:15:09 +0530444
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700445 DPRINTF(sc, ATH_DBG_BEACON,
Sujith04bd4632008-11-28 22:18:05 +0530446 "slot %d [tsf %llu tsftu %u intval %u] if_id %d\n",
Sujith9546aae2009-03-03 10:16:53 +0530447 slot, tsf, tsftu, intval, if_id);
Sujith980b24d2008-09-17 10:15:09 +0530448
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700449 bfaddr = 0;
450 if (if_id != ATH_IF_ID_ANY) {
451 bf = ath_beacon_generate(sc, if_id);
452 if (bf != NULL) {
453 bfaddr = bf->bf_daddr;
454 bc = 1;
455 }
456 }
Sujith9546aae2009-03-03 10:16:53 +0530457
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700458 /*
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.
464 *
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.
473 */
Sujithb77f4832008-12-07 21:44:03 +0530474 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;
Sujithff37e332008-11-24 12:07:55 +0530480 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700481 if (bfaddr != 0) {
482 /*
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.
486 */
Sujithb77f4832008-12-07 21:44:03 +0530487 if (!ath9k_hw_stoptxdma(ah, sc->beacon.beaconq)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700488 DPRINTF(sc, ATH_DBG_FATAL,
Sujithb77f4832008-12-07 21:44:03 +0530489 "beacon queue %u did not stop?\n", sc->beacon.beaconq);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700490 }
491
492 /* NB: cabq traffic should already be queued and primed */
Sujithb77f4832008-12-07 21:44:03 +0530493 ath9k_hw_puttxbuf(ah, sc->beacon.beaconq, bfaddr);
494 ath9k_hw_txstart(ah, sc->beacon.beaconq);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700495
Sujith17d79042009-02-09 13:27:03 +0530496 sc->beacon.ast_be_xmit += bc; /* XXX per-vif? */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700497 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700498}
499
500/*
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700501 * Configure the beacon and sleep timers.
502 *
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.
505 *
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.
514 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700515void ath_beacon_config(struct ath_softc *sc, int if_id)
516{
Sujith5640b082008-10-29 10:16:06 +0530517 struct ieee80211_vif *vif;
Sujithcbe61d82009-02-09 13:27:12 +0530518 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700519 struct ath_beacon_config conf;
Sujith17d79042009-02-09 13:27:03 +0530520 struct ath_vif *avp;
Colin McCabed97809d2008-12-01 13:38:55 -0800521 enum nl80211_iftype opmode;
Sujith980b24d2008-09-17 10:15:09 +0530522 u32 nexttbtt, intval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700523
Sujith5640b082008-10-29 10:16:06 +0530524 if (if_id != ATH_IF_ID_ANY) {
Sujith17d79042009-02-09 13:27:03 +0530525 vif = sc->vifs[if_id];
Sujith5640b082008-10-29 10:16:06 +0530526 avp = (void *)vif->drv_priv;
Colin McCabed97809d2008-12-01 13:38:55 -0800527 opmode = avp->av_opmode;
Sujith5640b082008-10-29 10:16:06 +0530528 } else {
Sujith2660b812009-02-09 13:27:26 +0530529 opmode = sc->sc_ah->opmode;
Sujith5640b082008-10-29 10:16:06 +0530530 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700531
Luis R. Rodriguez0345f372008-10-03 15:45:25 -0700532 memset(&conf, 0, sizeof(struct ath_beacon_config));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700533
Jouni Malinena8fff502008-08-11 14:01:48 +0300534 conf.beacon_interval = sc->hw->conf.beacon_int ?
535 sc->hw->conf.beacon_int : ATH_DEFAULT_BINTVAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700536 conf.listen_interval = 1;
537 conf.dtim_period = conf.beacon_interval;
538 conf.dtim_count = 1;
539 conf.bmiss_timeout = ATH_DEFAULT_BMISS_LIMIT * conf.beacon_interval;
540
541 /* extract tstamp from last beacon and convert to TU */
Sujithb77f4832008-12-07 21:44:03 +0530542 nexttbtt = TSF_TO_TU(sc->beacon.bc_tstamp >> 32, sc->beacon.bc_tstamp);
Sujith459f5f92008-09-17 10:15:36 +0530543
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700544 /* XXX conditionalize multi-bss support? */
Sujith2660b812009-02-09 13:27:26 +0530545 if (sc->sc_ah->opmode == NL80211_IFTYPE_AP) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700546 /*
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.
551 */
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 */
555 } else {
556 intval = conf.beacon_interval & ATH9K_BEACON_PERIOD;
557 }
558
Sujith980b24d2008-09-17 10:15:09 +0530559 if (nexttbtt == 0) /* e.g. for ap mode */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700560 nexttbtt = intval;
Sujith980b24d2008-09-17 10:15:09 +0530561 else if (intval) /* NB: can be 0 for monitor mode */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700562 nexttbtt = roundup(nexttbtt, intval);
Sujith980b24d2008-09-17 10:15:09 +0530563
Sujith04bd4632008-11-28 22:18:05 +0530564 DPRINTF(sc, ATH_DBG_BEACON, "nexttbtt %u intval %u (%u)\n",
565 nexttbtt, intval, conf.beacon_interval);
Sujith980b24d2008-09-17 10:15:09 +0530566
Colin McCabed97809d2008-12-01 13:38:55 -0800567 /* Check for NL80211_IFTYPE_AP and sc_nostabeacons for WDS client */
Sujith2660b812009-02-09 13:27:26 +0530568 if (sc->sc_ah->opmode == NL80211_IFTYPE_STATION) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700569 struct ath9k_beacon_state bs;
570 u64 tsf;
571 u32 tsftu;
572 int dtimperiod, dtimcount, sleepduration;
573 int cfpperiod, cfpcount;
574
575 /*
576 * Setup dtim and cfp parameters according to
577 * last beacon we received (which may be none).
578 */
579 dtimperiod = conf.dtim_period;
Sujith980b24d2008-09-17 10:15:09 +0530580 if (dtimperiod <= 0) /* NB: 0 if not known */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700581 dtimperiod = 1;
582 dtimcount = conf.dtim_count;
Sujith980b24d2008-09-17 10:15:09 +0530583 if (dtimcount >= dtimperiod) /* NB: sanity check */
584 dtimcount = 0;
585 cfpperiod = 1; /* NB: no PCF support yet */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700586 cfpcount = 0;
587
588 sleepduration = conf.listen_interval * intval;
589 if (sleepduration <= 0)
590 sleepduration = intval;
591
Sujith980b24d2008-09-17 10:15:09 +0530592#define FUDGE 2
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700593 /*
594 * Pull nexttbtt forward to reflect the current
595 * TSF and calculate dtim+cfp state for the result.
596 */
597 tsf = ath9k_hw_gettsf64(ah);
598 tsftu = TSF_TO_TU(tsf>>32, tsf) + FUDGE;
599 do {
600 nexttbtt += intval;
601 if (--dtimcount < 0) {
602 dtimcount = dtimperiod - 1;
603 if (--cfpcount < 0)
604 cfpcount = cfpperiod - 1;
605 }
606 } while (nexttbtt < tsftu);
607#undef FUDGE
Luis R. Rodriguez0345f372008-10-03 15:45:25 -0700608 memset(&bs, 0, sizeof(bs));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700609 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;
Sujith980b24d2008-09-17 10:15:09 +0530616
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700617 /*
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.
623 */
624 if (sleepduration > intval) {
Sujith980b24d2008-09-17 10:15:09 +0530625 bs.bs_bmissthreshold = conf.listen_interval *
626 ATH_DEFAULT_BMISS_LIMIT / 2;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700627 } else {
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;
634 }
635
636 /*
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.
642 *
643 * XXX fixed at 100ms
644 */
645
Sujith980b24d2008-09-17 10:15:09 +0530646 bs.bs_sleepduration = roundup(IEEE80211_MS_TO_TU(100),
647 sleepduration);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700648 if (bs.bs_sleepduration > bs.bs_dtimperiod)
649 bs.bs_sleepduration = bs.bs_dtimperiod;
650
Sujith4af9cf42009-02-12 10:06:47 +0530651 /* TSF out of range threshold fixed at 1 second */
652 bs.bs_tsfoor_threshold = ATH9K_TSFOOR_THRESHOLD;
653
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700654 DPRINTF(sc, ATH_DBG_BEACON,
Sujith9fc9ab02009-03-03 10:16:51 +0530655 "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);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700660
661 ath9k_hw_set_interrupts(ah, 0);
662 ath9k_hw_set_sta_beacon_timers(ah, &bs);
Sujith17d79042009-02-09 13:27:03 +0530663 sc->imask |= ATH9K_INT_BMISS;
664 ath9k_hw_set_interrupts(ah, sc->imask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700665 } else {
666 u64 tsf;
667 u32 tsftu;
Sujith9fc9ab02009-03-03 10:16:51 +0530668
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700669 ath9k_hw_set_interrupts(ah, 0);
Sujith2660b812009-02-09 13:27:26 +0530670 if (sc->sc_ah->opmode == NL80211_IFTYPE_ADHOC) {
Sujith9fc9ab02009-03-03 10:16:51 +0530671 /* Pull nexttbtt forward to reflect the current TSF */
Sujith980b24d2008-09-17 10:15:09 +0530672#define FUDGE 2
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700673 if (!(intval & ATH9K_BEACON_RESET_TSF)) {
674 tsf = ath9k_hw_gettsf64(ah);
675 tsftu = TSF_TO_TU((u32)(tsf>>32),
Sujith9fc9ab02009-03-03 10:16:51 +0530676 (u32)tsf) + FUDGE;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700677 do {
678 nexttbtt += intval;
679 } while (nexttbtt < tsftu);
680 }
681#undef FUDGE
682 DPRINTF(sc, ATH_DBG_BEACON,
Sujith04bd4632008-11-28 22:18:05 +0530683 "IBSS nexttbtt %u intval %u (%u)\n",
Sujith9fc9ab02009-03-03 10:16:51 +0530684 nexttbtt, intval & ~ATH9K_BEACON_RESET_TSF,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700685 conf.beacon_interval);
686
687 /*
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
692 * deal with things.
693 */
694 intval |= ATH9K_BEACON_ENA;
Sujith2660b812009-02-09 13:27:26 +0530695 if (!(ah->caps.hw_caps & ATH9K_HW_CAP_VEOL))
Sujith17d79042009-02-09 13:27:03 +0530696 sc->imask |= ATH9K_INT_SWBA;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700697 ath_beaconq_config(sc);
Sujith2660b812009-02-09 13:27:26 +0530698 } else if (sc->sc_ah->opmode == NL80211_IFTYPE_AP) {
Alina Friedrichsenf452a632009-02-19 23:46:31 +0100699 if (nexttbtt == intval)
700 intval |= ATH9K_BEACON_RESET_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700701 /*
702 * In AP mode we enable the beacon timers and
703 * SWBA interrupts to prepare beacon frames.
704 */
705 intval |= ATH9K_BEACON_ENA;
Sujith9fc9ab02009-03-03 10:16:51 +0530706 sc->imask |= ATH9K_INT_SWBA;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700707 ath_beaconq_config(sc);
708 }
Sujith9fc9ab02009-03-03 10:16:51 +0530709
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700710 ath9k_hw_beaconinit(ah, nexttbtt, intval);
Sujithb77f4832008-12-07 21:44:03 +0530711 sc->beacon.bmisscnt = 0;
Sujith17d79042009-02-09 13:27:03 +0530712 ath9k_hw_set_interrupts(ah, sc->imask);
Sujith9fc9ab02009-03-03 10:16:51 +0530713
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700714 /*
715 * When using a self-linked beacon descriptor in
716 * ibss mode load it once here.
717 */
Sujith2660b812009-02-09 13:27:26 +0530718 if (sc->sc_ah->opmode == NL80211_IFTYPE_ADHOC &&
719 (ah->caps.hw_caps & ATH9K_HW_CAP_VEOL))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700720 ath_beacon_start_adhoc(sc, 0);
721 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700722}
723
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700724void ath_beacon_sync(struct ath_softc *sc, int if_id)
725{
726 /*
727 * Resync beacon timers using the tsf of the
728 * beacon frame we just received.
729 */
730 ath_beacon_config(sc, if_id);
Sujith672840a2008-08-11 14:05:08 +0530731 sc->sc_flags |= SC_OP_BEACONS;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700732}