blob: 68c95d42e3d54d4b9448a038cf6de6d1f284a6b8 [file] [log] [blame]
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001/*
Sujith Manoharan5b681382011-05-17 13:36:18 +05302 * Copyright (c) 2008-2011 Atheros Communications Inc.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003 *
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
Alexey Dobriyanb7f080c2011-06-16 11:01:34 +000017#include <linux/dma-mapping.h>
Sujith394cf0a2009-02-09 13:26:54 +053018#include "ath9k.h"
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070019
Sujith5379c8a2009-03-03 10:16:54 +053020#define FUDGE 2
21
Felix Fietkauba4903f2011-05-17 21:09:54 +020022static void ath9k_reset_beacon_status(struct ath_softc *sc)
23{
24 sc->beacon.tx_processed = false;
25 sc->beacon.tx_last = false;
26}
27
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070028/*
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070029 * 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
32*/
Sujith Manoharan7e52c8a2012-07-17 17:16:09 +053033static void ath9k_beaconq_config(struct ath_softc *sc)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070034{
Sujithcbe61d82009-02-09 13:27:12 +053035 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070036 struct ath_common *common = ath9k_hw_common(ah);
Vivek Natarajan94db2932009-11-25 12:01:54 +053037 struct ath9k_tx_queue_info qi, qi_be;
Felix Fietkau066dae92010-11-07 14:59:39 +010038 struct ath_txq *txq;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070039
Sujithb77f4832008-12-07 21:44:03 +053040 ath9k_hw_get_txq_props(ah, sc->beacon.beaconq, &qi);
Sujith Manoharan7e52c8a2012-07-17 17:16:09 +053041
Thomas Pedersen2664d662013-05-08 10:16:48 -070042 if (sc->sc_ah->opmode == NL80211_IFTYPE_AP ||
43 sc->sc_ah->opmode == NL80211_IFTYPE_MESH_POINT) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070044 /* Always burst out beacon and CAB traffic. */
45 qi.tqi_aifs = 1;
46 qi.tqi_cwmin = 0;
47 qi.tqi_cwmax = 0;
48 } else {
49 /* Adhoc mode; important thing is to use 2x cwmin. */
Sujith Manoharanbea843c2012-11-21 18:13:10 +053050 txq = sc->tx.txq_map[IEEE80211_AC_BE];
Felix Fietkau066dae92010-11-07 14:59:39 +010051 ath9k_hw_get_txq_props(ah, txq->axq_qnum, &qi_be);
Vivek Natarajan94db2932009-11-25 12:01:54 +053052 qi.tqi_aifs = qi_be.tqi_aifs;
Vivek Natarajand202caf2012-05-29 15:59:55 +053053 if (ah->slottime == ATH9K_SLOT_TIME_20)
54 qi.tqi_cwmin = 2*qi_be.tqi_cwmin;
55 else
56 qi.tqi_cwmin = 4*qi_be.tqi_cwmin;
Vivek Natarajan94db2932009-11-25 12:01:54 +053057 qi.tqi_cwmax = qi_be.tqi_cwmax;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070058 }
59
Sujithb77f4832008-12-07 21:44:03 +053060 if (!ath9k_hw_set_txq_props(ah, sc->beacon.beaconq, &qi)) {
Sujith Manoharan7e52c8a2012-07-17 17:16:09 +053061 ath_err(common, "Unable to update h/w beacon queue parameters\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070062 } else {
Sujith9fc9ab02009-03-03 10:16:51 +053063 ath9k_hw_resettxqueue(ah, sc->beacon.beaconq);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070064 }
65}
66
67/*
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070068 * Associates the beacon frame buffer with a transmit descriptor. Will set
Felix Fietkaudd347f22011-03-22 21:54:17 +010069 * up rate codes, and channel flags. Beacons are always sent out at the
70 * lowest rate, and are not retried.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070071*/
Sujith Manoharanfb6e2522012-07-17 17:16:22 +053072static void ath9k_beacon_setup(struct ath_softc *sc, struct ieee80211_vif *vif,
Jouni Malinen64b84012010-02-16 17:56:18 +020073 struct ath_buf *bf, int rateidx)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070074{
Sujitha22be222009-03-30 15:28:36 +053075 struct sk_buff *skb = bf->bf_mpdu;
Sujithcbe61d82009-02-09 13:27:12 +053076 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez43c27612009-09-13 21:07:07 -070077 struct ath_common *common = ath9k_hw_common(ah);
Felix Fietkau493cf042011-09-14 21:24:22 +020078 struct ath_tx_info info;
Felix Fietkau545750d2009-11-23 22:21:01 +010079 struct ieee80211_supported_band *sband;
Felix Fietkau493cf042011-09-14 21:24:22 +020080 u8 chainmask = ah->txchainmask;
Felix Fietkau545750d2009-11-23 22:21:01 +010081 u8 rate = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070082
Felix Fietkaubff11762014-06-11 16:17:52 +053083 sband = &common->sbands[sc->cur_chandef.chan->band];
Jouni Malinen64b84012010-02-16 17:56:18 +020084 rate = sband->bitrates[rateidx].hw_value;
Sujith Manoharand47a61a2012-03-14 14:41:05 +053085 if (vif->bss_conf.use_short_preamble)
Jouni Malinen64b84012010-02-16 17:56:18 +020086 rate |= sband->bitrates[rateidx].hw_value_short;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070087
Felix Fietkau493cf042011-09-14 21:24:22 +020088 memset(&info, 0, sizeof(info));
89 info.pkt_len = skb->len + FCS_LEN;
90 info.type = ATH9K_PKT_TYPE_BEACON;
91 info.txpower = MAX_RATE_POWER;
92 info.keyix = ATH9K_TXKEYIX_INVALID;
93 info.keytype = ATH9K_KEY_TYPE_CLEAR;
Rajkumar Manoharancd484ae2012-04-13 16:44:22 +053094 info.flags = ATH9K_TXDESC_NOACK | ATH9K_TXDESC_CLRDMASK;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070095
Felix Fietkau493cf042011-09-14 21:24:22 +020096 info.buf_addr[0] = bf->bf_buf_addr;
97 info.buf_len[0] = roundup(skb->len, 4);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070098
Felix Fietkau493cf042011-09-14 21:24:22 +020099 info.is_first = true;
100 info.is_last = true;
101
102 info.qcu = sc->beacon.beaconq;
103
104 info.rates[0].Tries = 1;
105 info.rates[0].Rate = rate;
106 info.rates[0].ChSel = ath_txchainmask_reduction(sc, chainmask, rate);
107
108 ath9k_hw_set_txdesc(ah, bf->bf_desc, &info);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700109}
110
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530111static void ath9k_beacon_add_noa(struct ath_softc *sc, struct ath_vif *avp,
112 struct sk_buff *skb)
113{
114 static const u8 noa_ie_hdr[] = {
115 WLAN_EID_VENDOR_SPECIFIC, /* type */
116 0, /* length */
117 0x50, 0x6f, 0x9a, /* WFA OUI */
118 0x09, /* P2P subtype */
119 0x0c, /* Notice of Absence */
120 0x00, /* LSB of little-endian len */
121 0x00, /* MSB of little-endian len */
122 };
123
124 struct ieee80211_p2p_noa_attr *noa;
Felix Fietkau74148632014-06-11 16:18:11 +0530125 int noa_len, noa_desc, i = 0;
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530126 u8 *hdr;
127
Felix Fietkau74148632014-06-11 16:18:11 +0530128 if (!avp->offchannel_duration && !avp->periodic_noa_duration)
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530129 return;
130
Felix Fietkau74148632014-06-11 16:18:11 +0530131 noa_desc = !!avp->offchannel_duration + !!avp->periodic_noa_duration;
132 noa_len = 2 + sizeof(struct ieee80211_p2p_noa_desc) * noa_desc;
133
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530134 hdr = skb_put(skb, sizeof(noa_ie_hdr));
135 memcpy(hdr, noa_ie_hdr, sizeof(noa_ie_hdr));
136 hdr[1] = sizeof(noa_ie_hdr) + noa_len - 2;
137 hdr[7] = noa_len;
138
139 noa = (void *) skb_put(skb, noa_len);
140 memset(noa, 0, noa_len);
141
142 noa->index = avp->noa_index;
Felix Fietkau74148632014-06-11 16:18:11 +0530143 if (avp->periodic_noa_duration) {
144 u32 interval = TU_TO_USEC(sc->cur_chan->beacon.beacon_interval);
145
146 noa->desc[i].count = 255;
147 noa->desc[i].start_time = cpu_to_le32(avp->periodic_noa_start);
148 noa->desc[i].duration = cpu_to_le32(avp->periodic_noa_duration);
149 noa->desc[i].interval = cpu_to_le32(interval);
150 i++;
151 }
152
153 if (avp->offchannel_duration) {
154 noa->desc[i].count = 1;
155 noa->desc[i].start_time = cpu_to_le32(avp->offchannel_start);
156 noa->desc[i].duration = cpu_to_le32(avp->offchannel_duration);
157 }
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530158}
159
Sujith Manoharanfb6e2522012-07-17 17:16:22 +0530160static struct ath_buf *ath9k_beacon_generate(struct ieee80211_hw *hw,
161 struct ieee80211_vif *vif)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700162{
Felix Fietkau9ac586152011-01-24 19:23:18 +0100163 struct ath_softc *sc = hw->priv;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700164 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700165 struct ath_buf *bf;
Sujith Manoharanaa45fe92012-07-17 17:16:03 +0530166 struct ath_vif *avp = (void *)vif->drv_priv;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700167 struct sk_buff *skb;
Sujith Manoharanaa45fe92012-07-17 17:16:03 +0530168 struct ath_txq *cabq = sc->beacon.cabq;
Jouni Malinen147583c2008-08-11 14:01:50 +0300169 struct ieee80211_tx_info *info;
Sujith Manoharanfb6e2522012-07-17 17:16:22 +0530170 struct ieee80211_mgmt *mgmt_hdr;
Sujith980b24d2008-09-17 10:15:09 +0530171 int cabq_depth;
172
Sujith Manoharanaa45fe92012-07-17 17:16:03 +0530173 if (avp->av_bcbuf == NULL)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700174 return NULL;
Sujith980b24d2008-09-17 10:15:09 +0530175
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700176 bf = avp->av_bcbuf;
Sujitha22be222009-03-30 15:28:36 +0530177 skb = bf->bf_mpdu;
Jouni Malinena8fff502008-08-11 14:01:48 +0300178 if (skb) {
Ben Greearc1739eb32010-10-14 12:45:29 -0700179 dma_unmap_single(sc->dev, bf->bf_buf_addr,
Sujith9fc9ab02009-03-03 10:16:51 +0530180 skb->len, DMA_TO_DEVICE);
Jouni Malinen3fbb9d92008-12-05 20:42:45 +0200181 dev_kfree_skb_any(skb);
Ben Greear6cf9e992010-10-14 12:45:30 -0700182 bf->bf_buf_addr = 0;
Felix Fietkau1adb2e22013-01-09 16:16:53 +0100183 bf->bf_mpdu = NULL;
Jouni Malinena8fff502008-08-11 14:01:48 +0300184 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700185
Jouni Malinenc52f33d2009-03-03 19:23:29 +0200186 skb = ieee80211_beacon_get(hw, vif);
Jouni Malinena8fff502008-08-11 14:01:48 +0300187 if (skb == NULL)
188 return NULL;
Sujith Manoharanfb6e2522012-07-17 17:16:22 +0530189
190 bf->bf_mpdu = skb;
191
192 mgmt_hdr = (struct ieee80211_mgmt *)skb->data;
193 mgmt_hdr->u.beacon.timestamp = avp->tsf_adjust;
Sujith980b24d2008-09-17 10:15:09 +0530194
Jouni Malinen147583c2008-08-11 14:01:50 +0300195 info = IEEE80211_SKB_CB(skb);
196 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
197 /*
198 * TODO: make sure the seq# gets assigned properly (vs. other
199 * TX frames)
200 */
Sujith980b24d2008-09-17 10:15:09 +0530201 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Sujithb77f4832008-12-07 21:44:03 +0530202 sc->tx.seq_no += 0x10;
Jouni Malinen147583c2008-08-11 14:01:50 +0300203 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
Sujithb77f4832008-12-07 21:44:03 +0530204 hdr->seq_ctrl |= cpu_to_le16(sc->tx.seq_no);
Jouni Malinen147583c2008-08-11 14:01:50 +0300205 }
Sujith980b24d2008-09-17 10:15:09 +0530206
Felix Fietkau3ae07d32014-06-11 16:18:06 +0530207 if (vif->p2p)
208 ath9k_beacon_add_noa(sc, avp, skb);
209
Ben Greearc1739eb32010-10-14 12:45:29 -0700210 bf->bf_buf_addr = dma_map_single(sc->dev, skb->data,
211 skb->len, DMA_TO_DEVICE);
Gabor Juhos7da3c552009-01-14 20:17:03 +0100212 if (unlikely(dma_mapping_error(sc->dev, bf->bf_buf_addr))) {
Luis R. Rodriguezf8316df2008-12-03 03:35:29 -0800213 dev_kfree_skb_any(skb);
214 bf->bf_mpdu = NULL;
Ben Greear6cf9e992010-10-14 12:45:30 -0700215 bf->bf_buf_addr = 0;
Joe Perches38002762010-12-02 19:12:36 -0800216 ath_err(common, "dma_mapping_error on beaconing\n");
Luis R. Rodriguezf8316df2008-12-03 03:35:29 -0800217 return NULL;
218 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700219
Jouni Malinenc52f33d2009-03-03 19:23:29 +0200220 skb = ieee80211_get_buffered_bc(hw, vif);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700221
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700222 /*
223 * if the CABQ traffic from previous DTIM is pending and the current
224 * beacon is also a DTIM.
Sujith17d79042009-02-09 13:27:03 +0530225 * 1) if there is only one vif let the cab traffic continue.
226 * 2) if there are more than one vif and we are using staggered
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700227 * beacons, then drain the cabq by dropping all the frames in
Sujith17d79042009-02-09 13:27:03 +0530228 * the cabq so that the current vifs cab traffic can be scheduled.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700229 */
230 spin_lock_bh(&cabq->axq_lock);
231 cabq_depth = cabq->axq_depth;
232 spin_unlock_bh(&cabq->axq_lock);
233
Jouni Malinene022edb2008-08-22 17:31:33 +0300234 if (skb && cabq_depth) {
Sujith17d79042009-02-09 13:27:03 +0530235 if (sc->nvifs > 1) {
Joe Perchesd2182b62011-12-15 14:55:53 -0800236 ath_dbg(common, BEACON,
Joe Perches226afe62010-12-02 19:12:37 -0800237 "Flushing previous cabq traffic\n");
Felix Fietkau13815592013-01-20 18:51:53 +0100238 ath_draintxq(sc, cabq);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700239 }
240 }
241
Sujith Manoharanfb6e2522012-07-17 17:16:22 +0530242 ath9k_beacon_setup(sc, vif, bf, info->control.rates[0].idx);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700243
Felix Fietkau59505c02013-06-07 18:12:02 +0200244 if (skb)
245 ath_tx_cabq(hw, vif, skb);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700246
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700247 return bf;
248}
249
Sujith Manoharan130ef6e2012-07-17 17:15:30 +0530250void ath9k_beacon_assign_slot(struct ath_softc *sc, struct ieee80211_vif *vif)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700251{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700252 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujith Manoharan130ef6e2012-07-17 17:15:30 +0530253 struct ath_vif *avp = (void *)vif->drv_priv;
254 int slot;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700255
Sujith Manoharan130ef6e2012-07-17 17:15:30 +0530256 avp->av_bcbuf = list_first_entry(&sc->beacon.bbuf, struct ath_buf, list);
257 list_del(&avp->av_bcbuf->list);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700258
Sujith Manoharan130ef6e2012-07-17 17:15:30 +0530259 for (slot = 0; slot < ATH_BCBUF; slot++) {
260 if (sc->beacon.bslot[slot] == NULL) {
261 avp->av_bslot = slot;
Sujith Manoharan130ef6e2012-07-17 17:15:30 +0530262 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700263 }
264 }
265
Sujith Manoharan130ef6e2012-07-17 17:15:30 +0530266 sc->beacon.bslot[avp->av_bslot] = vif;
267 sc->nbcnvifs++;
268
269 ath_dbg(common, CONFIG, "Added interface at beacon slot: %d\n",
270 avp->av_bslot);
271}
272
273void ath9k_beacon_remove_slot(struct ath_softc *sc, struct ieee80211_vif *vif)
274{
275 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
276 struct ath_vif *avp = (void *)vif->drv_priv;
277 struct ath_buf *bf = avp->av_bcbuf;
278
279 ath_dbg(common, CONFIG, "Removing interface at beacon slot: %d\n",
280 avp->av_bslot);
281
282 tasklet_disable(&sc->bcon_tasklet);
283
284 if (bf && bf->bf_mpdu) {
285 struct sk_buff *skb = bf->bf_mpdu;
Ben Greearc1739eb32010-10-14 12:45:29 -0700286 dma_unmap_single(sc->dev, bf->bf_buf_addr,
Sujith9fc9ab02009-03-03 10:16:51 +0530287 skb->len, DMA_TO_DEVICE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700288 dev_kfree_skb_any(skb);
289 bf->bf_mpdu = NULL;
Ben Greear6cf9e992010-10-14 12:45:30 -0700290 bf->bf_buf_addr = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700291 }
292
Sujith Manoharan130ef6e2012-07-17 17:15:30 +0530293 avp->av_bcbuf = NULL;
Sujith Manoharan130ef6e2012-07-17 17:15:30 +0530294 sc->beacon.bslot[avp->av_bslot] = NULL;
295 sc->nbcnvifs--;
296 list_add_tail(&bf->list, &sc->beacon.bbuf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700297
Sujith Manoharan130ef6e2012-07-17 17:15:30 +0530298 tasklet_enable(&sc->bcon_tasklet);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700299}
300
Sujith Manoharanfb6e2522012-07-17 17:16:22 +0530301static int ath9k_beacon_choose_slot(struct ath_softc *sc)
302{
303 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Rajkumar Manoharanca900ac2014-06-11 16:18:02 +0530304 struct ath_beacon_config *cur_conf = &sc->cur_chan->beacon;
Sujith Manoharanfb6e2522012-07-17 17:16:22 +0530305 u16 intval;
306 u32 tsftu;
307 u64 tsf;
308 int slot;
309
Thomas Pedersen2664d662013-05-08 10:16:48 -0700310 if (sc->sc_ah->opmode != NL80211_IFTYPE_AP &&
311 sc->sc_ah->opmode != NL80211_IFTYPE_MESH_POINT) {
Sujith Manoharanfb6e2522012-07-17 17:16:22 +0530312 ath_dbg(common, BEACON, "slot 0, tsf: %llu\n",
313 ath9k_hw_gettsf64(sc->sc_ah));
314 return 0;
315 }
316
317 intval = cur_conf->beacon_interval ? : ATH_DEFAULT_BINTVAL;
318 tsf = ath9k_hw_gettsf64(sc->sc_ah);
319 tsf += TU_TO_USEC(sc->sc_ah->config.sw_beacon_response_time);
320 tsftu = TSF_TO_TU((tsf * ATH_BCBUF) >>32, tsf * ATH_BCBUF);
321 slot = (tsftu % (intval * ATH_BCBUF)) / intval;
322
323 ath_dbg(common, BEACON, "slot: %d tsf: %llu tsftu: %u\n",
324 slot, tsf, tsftu / ATH_BCBUF);
325
326 return slot;
327}
328
Felix Fietkauc32e4e52013-12-19 18:01:49 +0100329static void ath9k_set_tsfadjust(struct ath_softc *sc, struct ieee80211_vif *vif)
Sujith Manoharan2f8e82e2012-07-17 17:16:16 +0530330{
331 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujith Manoharan2f8e82e2012-07-17 17:16:16 +0530332 struct ath_vif *avp = (void *)vif->drv_priv;
Rajkumar Manoharan9a9c4fb2014-06-11 16:18:03 +0530333 struct ath_beacon_config *cur_conf = &avp->chanctx->beacon;
Felix Fietkau63ded3f2013-12-19 18:01:50 +0100334 u32 tsfadjust;
Sujith Manoharan2f8e82e2012-07-17 17:16:16 +0530335
336 if (avp->av_bslot == 0)
337 return;
338
Felix Fietkau63ded3f2013-12-19 18:01:50 +0100339 tsfadjust = cur_conf->beacon_interval * avp->av_bslot;
340 tsfadjust = TU_TO_USEC(tsfadjust) / ATH_BCBUF;
341 avp->tsf_adjust = cpu_to_le64(tsfadjust);
Sujith Manoharan2f8e82e2012-07-17 17:16:16 +0530342
343 ath_dbg(common, CONFIG, "tsfadjust is: %llu for bslot: %d\n",
344 (unsigned long long)tsfadjust, avp->av_bslot);
345}
346
Michal Kazior4effc6f2014-01-20 15:27:12 +0100347bool ath9k_csa_is_finished(struct ath_softc *sc, struct ieee80211_vif *vif)
Simon Wunderlichd074e8d2013-08-14 08:01:38 +0200348{
Simon Wunderlichd074e8d2013-08-14 08:01:38 +0200349 if (!vif || !vif->csa_active)
350 return false;
351
352 if (!ieee80211_csa_is_complete(vif))
353 return false;
354
355 ieee80211_csa_finish(vif);
Simon Wunderlichd074e8d2013-08-14 08:01:38 +0200356 return true;
357}
358
Michal Kazior4effc6f2014-01-20 15:27:12 +0100359static void ath9k_csa_update_vif(void *data, u8 *mac, struct ieee80211_vif *vif)
360{
361 struct ath_softc *sc = data;
362 ath9k_csa_is_finished(sc, vif);
363}
364
365void ath9k_csa_update(struct ath_softc *sc)
366{
Felix Fietkau5869e792014-04-08 23:44:26 +0200367 ieee80211_iterate_active_interfaces_atomic(sc->hw,
368 IEEE80211_IFACE_ITER_NORMAL,
369 ath9k_csa_update_vif, sc);
Michal Kazior4effc6f2014-01-20 15:27:12 +0100370}
371
Sujith Manoharanfb6e2522012-07-17 17:16:22 +0530372void ath9k_beacon_tasklet(unsigned long data)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700373{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700374 struct ath_softc *sc = (struct ath_softc *)data;
Sujithcbe61d82009-02-09 13:27:12 +0530375 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700376 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700377 struct ath_buf *bf = NULL;
Jouni Malinen2c3db3d2009-03-03 19:23:26 +0200378 struct ieee80211_vif *vif;
Mohammed Shafi Shajakhan98f0a5e2011-12-28 19:09:54 +0530379 bool edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA);
Jouni Malinen2c3db3d2009-03-03 19:23:26 +0200380 int slot;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700381
Oleksij Rempeleefa01d2014-02-27 11:40:46 +0100382 if (test_bit(ATH_OP_HW_RESET, &common->op_flags)) {
Rajkumar Manoharan4e7fb712012-04-13 16:44:21 +0530383 ath_dbg(common, RESET,
384 "reset work is pending, skip beaconing now\n");
385 return;
386 }
Rajkumar Manoharan124b9792012-07-17 17:16:42 +0530387
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700388 /*
389 * Check if the previous beacon has gone out. If
390 * not don't try to post another, skip this period
391 * and wait for the next. Missed beacons indicate
392 * a problem and should not occur. If we miss too
393 * many consecutive beacons reset the device.
394 */
Sujithb77f4832008-12-07 21:44:03 +0530395 if (ath9k_hw_numtxpending(ah, sc->beacon.beaconq) != 0) {
396 sc->beacon.bmisscnt++;
Sujith9546aae2009-03-03 10:16:53 +0530397
Sujith Manoharan1e516ca2013-09-11 21:30:27 +0530398 ath9k_hw_check_nav(ah);
399
Sujith Manoharan415ec612013-12-24 10:44:25 +0530400 /*
401 * If the previous beacon has not been transmitted
402 * and a MAC/BB hang has been identified, return
403 * here because a chip reset would have been
404 * initiated.
405 */
406 if (!ath_hw_check(sc))
407 return;
Felix Fietkaub381fa32012-04-12 22:35:58 +0200408
Felix Fietkauc944daf42011-03-22 21:54:19 +0100409 if (sc->beacon.bmisscnt < BSTUCK_THRESH * sc->nbcnvifs) {
Joe Perchesd2182b62011-12-15 14:55:53 -0800410 ath_dbg(common, BSTUCK,
Joe Perches226afe62010-12-02 19:12:37 -0800411 "missed %u consecutive beacons\n",
412 sc->beacon.bmisscnt);
Felix Fietkauefff3952011-03-11 21:38:20 +0100413 ath9k_hw_stop_dma_queue(ah, sc->beacon.beaconq);
Felix Fietkau87c510fe2011-03-22 21:54:18 +0100414 if (sc->beacon.bmisscnt > 3)
415 ath9k_hw_bstuck_nfcal(ah);
Sujithb77f4832008-12-07 21:44:03 +0530416 } else if (sc->beacon.bmisscnt >= BSTUCK_THRESH) {
Joe Perchesd2182b62011-12-15 14:55:53 -0800417 ath_dbg(common, BSTUCK, "beacon is officially stuck\n");
Rajkumar Manoharan4e7fb712012-04-13 16:44:21 +0530418 sc->beacon.bmisscnt = 0;
Rajkumar Manoharan124b9792012-07-17 17:16:42 +0530419 ath9k_queue_reset(sc, RESET_TYPE_BEACON_STUCK);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700420 }
Sujith9546aae2009-03-03 10:16:53 +0530421
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700422 return;
423 }
Sujith980b24d2008-09-17 10:15:09 +0530424
Sujith Manoharanfb6e2522012-07-17 17:16:22 +0530425 slot = ath9k_beacon_choose_slot(sc);
426 vif = sc->beacon.bslot[slot];
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700427
Michal Kazior4effc6f2014-01-20 15:27:12 +0100428 /* EDMA devices check that in the tx completion function. */
Felix Fietkau748299f2014-06-11 16:18:04 +0530429 if (!edma) {
Sujith Manoharan27babf92014-08-23 13:29:16 +0530430 if (ath9k_is_chanctx_enabled()) {
431 if (sc->sched.beacon_pending)
432 ath_chanctx_event(sc, NULL,
433 ATH_CHANCTX_EVENT_BEACON_SENT);
434 }
Felix Fietkau748299f2014-06-11 16:18:04 +0530435
436 if (ath9k_csa_is_finished(sc, vif))
437 return;
438 }
Michal Kazior4effc6f2014-01-20 15:27:12 +0100439
Sujith Manoharanfb6e2522012-07-17 17:16:22 +0530440 if (!vif || !vif->bss_conf.enable_beacon)
441 return;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700442
Sujith Manoharan27babf92014-08-23 13:29:16 +0530443 if (ath9k_is_chanctx_enabled()) {
444 ath_chanctx_event(sc, vif, ATH_CHANCTX_EVENT_BEACON_PREPARE);
445 }
446
Sujith Manoharanfb6e2522012-07-17 17:16:22 +0530447 bf = ath9k_beacon_generate(sc->hw, vif);
Sujith980b24d2008-09-17 10:15:09 +0530448
Sujith Manoharanfb6e2522012-07-17 17:16:22 +0530449 if (sc->beacon.bmisscnt != 0) {
450 ath_dbg(common, BSTUCK, "resume beacon xmit after %u misses\n",
451 sc->beacon.bmisscnt);
452 sc->beacon.bmisscnt = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700453 }
Sujith9546aae2009-03-03 10:16:53 +0530454
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700455 /*
456 * Handle slot time change when a non-ERP station joins/leaves
457 * an 11g network. The 802.11 layer notifies us via callback,
458 * we mark updateslot, then wait one beacon before effecting
459 * the change. This gives associated stations at least one
460 * beacon interval to note the state change.
461 *
462 * NB: The slot time change state machine is clocked according
463 * to whether we are bursting or staggering beacons. We
464 * recognize the request to update and record the current
465 * slot then don't transition until that slot is reached
466 * again. If we miss a beacon for that slot then we'll be
467 * slow to transition but we'll be sure at least one beacon
468 * interval has passed. When bursting slot is always left
469 * set to ATH_BCBUF so this check is a noop.
470 */
Sujithb77f4832008-12-07 21:44:03 +0530471 if (sc->beacon.updateslot == UPDATE) {
Sujith Manoharanfb6e2522012-07-17 17:16:22 +0530472 sc->beacon.updateslot = COMMIT;
Sujithb77f4832008-12-07 21:44:03 +0530473 sc->beacon.slotupdate = slot;
Sujith Manoharanfb6e2522012-07-17 17:16:22 +0530474 } else if (sc->beacon.updateslot == COMMIT &&
475 sc->beacon.slotupdate == slot) {
Felix Fietkau0005baf2010-01-15 02:33:40 +0100476 ah->slottime = sc->beacon.slottime;
477 ath9k_hw_init_global_settings(ah);
Sujithb77f4832008-12-07 21:44:03 +0530478 sc->beacon.updateslot = OK;
Sujithff37e332008-11-24 12:07:55 +0530479 }
Sujith Manoharanfb6e2522012-07-17 17:16:22 +0530480
481 if (bf) {
482 ath9k_reset_beacon_status(sc);
483
484 ath_dbg(common, BEACON,
485 "Transmitting beacon for slot: %d\n", slot);
486
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700487 /* NB: cabq traffic should already be queued and primed */
Sujith Manoharanfb6e2522012-07-17 17:16:22 +0530488 ath9k_hw_puttxbuf(ah, sc->beacon.beaconq, bf->bf_daddr);
Mohammed Shafi Shajakhan98f0a5e2011-12-28 19:09:54 +0530489
490 if (!edma)
491 ath9k_hw_txstart(ah, sc->beacon.beaconq);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700492 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700493}
494
Sujith Manoharan1a6404a2013-02-04 15:38:24 +0530495/*
496 * Both nexttbtt and intval have to be in usecs.
497 */
498static void ath9k_beacon_init(struct ath_softc *sc, u32 nexttbtt,
499 u32 intval, bool reset_tsf)
Luis R. Rodriguez21526d52009-09-09 20:05:39 -0700500{
Sujith Manoharanef4ad632012-07-17 17:15:56 +0530501 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez21526d52009-09-09 20:05:39 -0700502
Sujith Manoharanef4ad632012-07-17 17:15:56 +0530503 ath9k_hw_disable_interrupts(ah);
Sujith Manoharan1a6404a2013-02-04 15:38:24 +0530504 if (reset_tsf)
505 ath9k_hw_reset_tsf(ah);
Sujith Manoharan7e52c8a2012-07-17 17:16:09 +0530506 ath9k_beaconq_config(sc);
Sujith Manoharanef4ad632012-07-17 17:15:56 +0530507 ath9k_hw_beaconinit(ah, nexttbtt, intval);
508 sc->beacon.bmisscnt = 0;
509 ath9k_hw_set_interrupts(ah);
510 ath9k_hw_enable_interrupts(ah);
Luis R. Rodriguez21526d52009-09-09 20:05:39 -0700511}
512
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700513/*
Sujith5379c8a2009-03-03 10:16:54 +0530514 * For multi-bss ap support beacons are either staggered evenly over N slots or
515 * burst together. For the former arrange for the SWBA to be delivered for each
516 * slot. Slots that are not occupied will generate nothing.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700517 */
Sujith Manoharanef4ad632012-07-17 17:15:56 +0530518static void ath9k_beacon_config_ap(struct ath_softc *sc,
519 struct ath_beacon_config *conf)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700520{
Pavel Roskin30691682010-03-31 18:05:31 -0400521 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700522
Oleksij Rempelfa7b52f2014-03-01 21:16:03 +0100523 ath9k_cmn_beacon_config_ap(ah, conf, ATH_BCBUF);
524 ath9k_beacon_init(sc, conf->nexttbtt, conf->intval, false);
Sujith5379c8a2009-03-03 10:16:54 +0530525}
526
Oleksij Rempelcbbdf2a2014-03-01 21:15:56 +0100527static void ath9k_beacon_config_sta(struct ath_hw *ah,
Sujith Manoharanef4ad632012-07-17 17:15:56 +0530528 struct ath_beacon_config *conf)
Sujith5379c8a2009-03-03 10:16:54 +0530529{
530 struct ath9k_beacon_state bs;
Sujith5379c8a2009-03-03 10:16:54 +0530531
Oleksij Rempelcbbdf2a2014-03-01 21:15:56 +0100532 if (ath9k_cmn_beacon_config_sta(ah, conf, &bs) == -EPERM)
Senthil Balasubramanian1a200342010-02-03 22:50:18 +0530533 return;
Sujith5379c8a2009-03-03 10:16:54 +0530534
Felix Fietkau4df30712010-11-08 20:54:47 +0100535 ath9k_hw_disable_interrupts(ah);
Pavel Roskin30691682010-03-31 18:05:31 -0400536 ath9k_hw_set_sta_beacon_timers(ah, &bs);
537 ah->imask |= ATH9K_INT_BMISS;
Rajkumar Manoharandeb75182011-05-06 18:27:46 +0530538
Felix Fietkau72d874c2011-10-08 20:06:19 +0200539 ath9k_hw_set_interrupts(ah);
Rajkumar Manoharane8fe7332011-08-05 18:59:41 +0530540 ath9k_hw_enable_interrupts(ah);
Sujith5379c8a2009-03-03 10:16:54 +0530541}
542
Sujith Manoharanef4ad632012-07-17 17:15:56 +0530543static void ath9k_beacon_config_adhoc(struct ath_softc *sc,
544 struct ath_beacon_config *conf)
Sujith5379c8a2009-03-03 10:16:54 +0530545{
Pavel Roskin30691682010-03-31 18:05:31 -0400546 struct ath_hw *ah = sc->sc_ah;
547 struct ath_common *common = ath9k_hw_common(ah);
Sujith5379c8a2009-03-03 10:16:54 +0530548
Felix Fietkauba4903f2011-05-17 21:09:54 +0200549 ath9k_reset_beacon_status(sc);
550
Oleksij Rempel4c9a1f32014-03-01 21:15:58 +0100551 ath9k_cmn_beacon_config_adhoc(ah, conf);
Sujith Manoharan1a6404a2013-02-04 15:38:24 +0530552
Oleksij Rempel4c9a1f32014-03-01 21:15:58 +0100553 ath9k_beacon_init(sc, conf->nexttbtt, conf->intval, conf->ibss_creator);
Sujith Manoharan1a6404a2013-02-04 15:38:24 +0530554
555 /*
556 * Set the global 'beacon has been configured' flag for the
557 * joiner case in IBSS mode.
558 */
559 if (!conf->ibss_creator && conf->enable_beacon)
Oleksij Rempeleefa01d2014-02-27 11:40:46 +0100560 set_bit(ATH_OP_BEACONS, &common->op_flags);
Sujith5379c8a2009-03-03 10:16:54 +0530561}
562
Felix Fietkauc32e4e52013-12-19 18:01:49 +0100563static bool ath9k_allow_beacon_config(struct ath_softc *sc,
564 struct ieee80211_vif *vif)
Sujith5379c8a2009-03-03 10:16:54 +0530565{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700566 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Rajkumar Manoharan99e4d432011-04-04 22:56:19 +0530567
Sujith Manoharanef4ad632012-07-17 17:15:56 +0530568 if (sc->sc_ah->opmode == NL80211_IFTYPE_AP) {
569 if ((vif->type != NL80211_IFTYPE_AP) ||
570 (sc->nbcnvifs > 1)) {
571 ath_dbg(common, CONFIG,
572 "An AP interface is already present !\n");
573 return false;
574 }
Rajkumar Manoharan99e4d432011-04-04 22:56:19 +0530575 }
Sujith Manoharanef4ad632012-07-17 17:15:56 +0530576
577 if (sc->sc_ah->opmode == NL80211_IFTYPE_STATION) {
578 if ((vif->type == NL80211_IFTYPE_STATION) &&
Oleksij Rempeleefa01d2014-02-27 11:40:46 +0100579 test_bit(ATH_OP_BEACONS, &common->op_flags) &&
Rajkumar Manoharan9a9c4fb2014-06-11 16:18:03 +0530580 vif != sc->cur_chan->primary_sta) {
Sujith Manoharanef4ad632012-07-17 17:15:56 +0530581 ath_dbg(common, CONFIG,
582 "Beacon already configured for a station interface\n");
583 return false;
584 }
Rajkumar Manoharan99e4d432011-04-04 22:56:19 +0530585 }
Sujith Manoharanef4ad632012-07-17 17:15:56 +0530586
Rajkumar Manoharan99e4d432011-04-04 22:56:19 +0530587 return true;
588}
589
Sujith Manoharanef4ad632012-07-17 17:15:56 +0530590static void ath9k_cache_beacon_config(struct ath_softc *sc,
Rajkumar Manoharan9a9c4fb2014-06-11 16:18:03 +0530591 struct ath_chanctx *ctx,
Sujith Manoharanef4ad632012-07-17 17:15:56 +0530592 struct ieee80211_bss_conf *bss_conf)
Rajkumar Manoharan99e4d432011-04-04 22:56:19 +0530593{
Sujith Manoharanef4ad632012-07-17 17:15:56 +0530594 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Rajkumar Manoharan9a9c4fb2014-06-11 16:18:03 +0530595 struct ath_beacon_config *cur_conf = &ctx->beacon;
Rajkumar Manoharan99e4d432011-04-04 22:56:19 +0530596
Sujith Manoharanef4ad632012-07-17 17:15:56 +0530597 ath_dbg(common, BEACON,
598 "Caching beacon data for BSS: %pM\n", bss_conf->bssid);
Sujith5379c8a2009-03-03 10:16:54 +0530599
Rajkumar Manoharan99e4d432011-04-04 22:56:19 +0530600 cur_conf->beacon_interval = bss_conf->beacon_int;
601 cur_conf->dtim_period = bss_conf->dtim_period;
Ben Greear48014162011-01-15 19:13:48 +0000602 cur_conf->dtim_count = 1;
Sujith Manoharan1a6404a2013-02-04 15:38:24 +0530603 cur_conf->ibss_creator = bss_conf->ibss_creator;
Vasanthakumar Thiagarajan6b96f932009-05-15 18:59:22 +0530604
Vasanthakumar Thiagarajanc4f9f162009-06-12 10:55:55 +0530605 /*
606 * It looks like mac80211 may end up using beacon interval of zero in
607 * some cases (at least for mesh point). Avoid getting into an
608 * infinite loop by using a bit safer value instead. To be safe,
609 * do sanity check on beacon interval for all operating modes.
610 */
611 if (cur_conf->beacon_interval == 0)
612 cur_conf->beacon_interval = 100;
Vasanthakumar Thiagarajan6b96f932009-05-15 18:59:22 +0530613
Ben Greear76c93982014-04-30 12:02:05 -0700614 cur_conf->bmiss_timeout =
615 ATH_DEFAULT_BMISS_LIMIT * cur_conf->beacon_interval;
616
Mohammed Shafi Shajakhanee832d3e2010-12-28 13:06:26 +0530617 /*
Mohammed Shafi Shajakhan3a2329f2011-02-07 21:08:28 +0530618 * We don't parse dtim period from mac80211 during the driver
619 * initialization as it breaks association with hidden-ssid
620 * AP and it causes latency in roaming
Mohammed Shafi Shajakhanee832d3e2010-12-28 13:06:26 +0530621 */
622 if (cur_conf->dtim_period == 0)
623 cur_conf->dtim_period = 1;
624
Rajkumar Manoharan99e4d432011-04-04 22:56:19 +0530625}
626
Sujith Manoharanef4ad632012-07-17 17:15:56 +0530627void ath9k_beacon_config(struct ath_softc *sc, struct ieee80211_vif *vif,
628 u32 changed)
Rajkumar Manoharan8e22ad32011-04-17 21:38:10 +0530629{
Sujith Manoharanef4ad632012-07-17 17:15:56 +0530630 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
Oleksij Rempeleefa01d2014-02-27 11:40:46 +0100631 struct ath_hw *ah = sc->sc_ah;
632 struct ath_common *common = ath9k_hw_common(ah);
Rajkumar Manoharan9a9c4fb2014-06-11 16:18:03 +0530633 struct ath_vif *avp = (void *)vif->drv_priv;
634 struct ath_chanctx *ctx = avp->chanctx;
635 struct ath_beacon_config *cur_conf;
Sujith Manoharan1a6404a2013-02-04 15:38:24 +0530636 unsigned long flags;
637 bool skip_beacon = false;
Rajkumar Manoharan8e22ad32011-04-17 21:38:10 +0530638
Rajkumar Manoharan9a9c4fb2014-06-11 16:18:03 +0530639 if (!ctx)
640 return;
641
642 cur_conf = &avp->chanctx->beacon;
Felix Fietkauc32e4e52013-12-19 18:01:49 +0100643 if (vif->type == NL80211_IFTYPE_AP)
644 ath9k_set_tsfadjust(sc, vif);
645
646 if (!ath9k_allow_beacon_config(sc, vif))
647 return;
648
Rajkumar Manoharan9a9c4fb2014-06-11 16:18:03 +0530649 if (vif->type == NL80211_IFTYPE_STATION) {
650 ath9k_cache_beacon_config(sc, ctx, bss_conf);
651 if (ctx != sc->cur_chan)
652 return;
653
Sujith Manoharanef4ad632012-07-17 17:15:56 +0530654 ath9k_set_beacon(sc);
Oleksij Rempeleefa01d2014-02-27 11:40:46 +0100655 set_bit(ATH_OP_BEACONS, &common->op_flags);
Sujith Manoharan1a6404a2013-02-04 15:38:24 +0530656 return;
Sujith Manoharan1a6404a2013-02-04 15:38:24 +0530657 }
658
659 /*
660 * Take care of multiple interfaces when
661 * enabling/disabling SWBA.
662 */
663 if (changed & BSS_CHANGED_BEACON_ENABLED) {
664 if (!bss_conf->enable_beacon &&
665 (sc->nbcnvifs <= 1)) {
666 cur_conf->enable_beacon = false;
667 } else if (bss_conf->enable_beacon) {
668 cur_conf->enable_beacon = true;
Rajkumar Manoharan9a9c4fb2014-06-11 16:18:03 +0530669 ath9k_cache_beacon_config(sc, ctx, bss_conf);
Sujith Manoharan1a6404a2013-02-04 15:38:24 +0530670 }
671 }
672
Rajkumar Manoharan9a9c4fb2014-06-11 16:18:03 +0530673 if (ctx != sc->cur_chan)
674 return;
675
Sujith Manoharan1a6404a2013-02-04 15:38:24 +0530676 /*
677 * Configure the HW beacon registers only when we have a valid
678 * beacon interval.
679 */
680 if (cur_conf->beacon_interval) {
Sujith Manoharanef4ad632012-07-17 17:15:56 +0530681 /*
Sujith Manoharan1a6404a2013-02-04 15:38:24 +0530682 * If we are joining an existing IBSS network, start beaconing
683 * only after a TSF-sync has taken place. Ensure that this
684 * happens by setting the appropriate flags.
Sujith Manoharanef4ad632012-07-17 17:15:56 +0530685 */
Sujith Manoharan1a6404a2013-02-04 15:38:24 +0530686 if ((changed & BSS_CHANGED_IBSS) && !bss_conf->ibss_creator &&
687 bss_conf->enable_beacon) {
688 spin_lock_irqsave(&sc->sc_pm_lock, flags);
689 sc->ps_flags |= PS_BEACON_SYNC | PS_WAIT_FOR_BEACON;
690 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
691 skip_beacon = true;
692 } else {
Sujith Manoharanef4ad632012-07-17 17:15:56 +0530693 ath9k_set_beacon(sc);
Sujith Manoharanef4ad632012-07-17 17:15:56 +0530694 }
Sujith Manoharan1a6404a2013-02-04 15:38:24 +0530695
696 /*
Oleksij Rempeleefa01d2014-02-27 11:40:46 +0100697 * Do not set the ATH_OP_BEACONS flag for IBSS joiner mode
Sujith Manoharan1a6404a2013-02-04 15:38:24 +0530698 * here, it is done in ath9k_beacon_config_adhoc().
699 */
700 if (cur_conf->enable_beacon && !skip_beacon)
Oleksij Rempeleefa01d2014-02-27 11:40:46 +0100701 set_bit(ATH_OP_BEACONS, &common->op_flags);
Sujith Manoharan1a6404a2013-02-04 15:38:24 +0530702 else
Oleksij Rempeleefa01d2014-02-27 11:40:46 +0100703 clear_bit(ATH_OP_BEACONS, &common->op_flags);
Rajkumar Manoharan8e22ad32011-04-17 21:38:10 +0530704 }
Rajkumar Manoharan8e22ad32011-04-17 21:38:10 +0530705}
706
Sujith Manoharanef4ad632012-07-17 17:15:56 +0530707void ath9k_set_beacon(struct ath_softc *sc)
Rajkumar Manoharan99e4d432011-04-04 22:56:19 +0530708{
709 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Rajkumar Manoharanca900ac2014-06-11 16:18:02 +0530710 struct ath_beacon_config *cur_conf = &sc->cur_chan->beacon;
Rajkumar Manoharan99e4d432011-04-04 22:56:19 +0530711
Felix Fietkau26cd3222011-04-02 03:39:48 +0200712 switch (sc->sc_ah->opmode) {
Vasanthakumar Thiagarajan6b96f932009-05-15 18:59:22 +0530713 case NL80211_IFTYPE_AP:
Thomas Pedersen2664d662013-05-08 10:16:48 -0700714 case NL80211_IFTYPE_MESH_POINT:
Sujith Manoharanef4ad632012-07-17 17:15:56 +0530715 ath9k_beacon_config_ap(sc, cur_conf);
Vasanthakumar Thiagarajan6b96f932009-05-15 18:59:22 +0530716 break;
717 case NL80211_IFTYPE_ADHOC:
Sujith Manoharanef4ad632012-07-17 17:15:56 +0530718 ath9k_beacon_config_adhoc(sc, cur_conf);
Vasanthakumar Thiagarajan6b96f932009-05-15 18:59:22 +0530719 break;
720 case NL80211_IFTYPE_STATION:
Oleksij Rempelcbbdf2a2014-03-01 21:15:56 +0100721 ath9k_beacon_config_sta(sc->sc_ah, cur_conf);
Vasanthakumar Thiagarajan6b96f932009-05-15 18:59:22 +0530722 break;
723 default:
Joe Perchesd2182b62011-12-15 14:55:53 -0800724 ath_dbg(common, CONFIG, "Unsupported beaconing mode\n");
Vasanthakumar Thiagarajan6b96f932009-05-15 18:59:22 +0530725 return;
726 }
Rajkumar Manoharan014cf3b2011-02-09 17:46:39 +0530727}