blob: c3129db7828f4173f0e1d51120fc3cd953a9937f [file] [log] [blame]
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001/*
Sujithcee075a2009-03-13 09:07:23 +05302 * Copyright (c) 2008-2009 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
Sujith394cf0a2009-02-09 13:26:54 +053017#include "ath9k.h"
Luis R. Rodriguezb622a722010-04-15 17:39:28 -040018#include "ar9003_mac.h"
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070019
Felix Fietkaub5c804752010-04-15 17:38:48 -040020#define SKB_CB_ATHBUF(__skb) (*((struct ath_buf **)__skb->cb))
21
Vasanthakumar Thiagarajan102885a2010-09-02 01:34:43 -070022static inline bool ath_is_alt_ant_ratio_better(int alt_ratio, int maxdelta,
23 int mindelta, int main_rssi_avg,
24 int alt_rssi_avg, int pkt_count)
25{
26 return (((alt_ratio >= ATH_ANT_DIV_COMB_ALT_ANT_RATIO2) &&
27 (alt_rssi_avg > main_rssi_avg + maxdelta)) ||
28 (alt_rssi_avg > main_rssi_avg + mindelta)) && (pkt_count > 50);
29}
30
Vasanthakumar Thiagarajanededf1f2010-05-22 23:58:13 -070031static inline bool ath9k_check_auto_sleep(struct ath_softc *sc)
32{
33 return sc->ps_enabled &&
34 (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP);
35}
36
Jouni Malinenbce048d2009-03-03 19:23:28 +020037static struct ieee80211_hw * ath_get_virt_hw(struct ath_softc *sc,
38 struct ieee80211_hdr *hdr)
39{
Jouni Malinenc52f33d2009-03-03 19:23:29 +020040 struct ieee80211_hw *hw = sc->pri_wiphy->hw;
41 int i;
42
43 spin_lock_bh(&sc->wiphy_lock);
44 for (i = 0; i < sc->num_sec_wiphy; i++) {
45 struct ath_wiphy *aphy = sc->sec_wiphy[i];
46 if (aphy == NULL)
47 continue;
48 if (compare_ether_addr(hdr->addr1, aphy->hw->wiphy->perm_addr)
49 == 0) {
50 hw = aphy->hw;
51 break;
52 }
53 }
54 spin_unlock_bh(&sc->wiphy_lock);
55 return hw;
Jouni Malinenbce048d2009-03-03 19:23:28 +020056}
57
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070058/*
59 * Setup and link descriptors.
60 *
61 * 11N: we can no longer afford to self link the last descriptor.
62 * MAC acknowledges BA status as long as it copies frames to host
63 * buffer (or rx fifo). This can incorrectly acknowledge packets
64 * to a sender if last desc is self-linked.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070065 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070066static void ath_rx_buf_link(struct ath_softc *sc, struct ath_buf *bf)
67{
Sujithcbe61d82009-02-09 13:27:12 +053068 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -080069 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070070 struct ath_desc *ds;
71 struct sk_buff *skb;
72
73 ATH_RXBUF_RESET(bf);
74
75 ds = bf->bf_desc;
Sujithbe0418a2008-11-18 09:05:55 +053076 ds->ds_link = 0; /* link to null */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070077 ds->ds_data = bf->bf_buf_addr;
78
Sujithbe0418a2008-11-18 09:05:55 +053079 /* virtual addr of the beginning of the buffer. */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070080 skb = bf->bf_mpdu;
Luis R. Rodriguez9680e8a2009-09-13 23:28:00 -070081 BUG_ON(skb == NULL);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070082 ds->ds_vdata = skb->data;
83
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -080084 /*
85 * setup rx descriptors. The rx_bufsize here tells the hardware
Luis R. Rodriguezb4b6cda2008-11-20 17:15:13 -080086 * how much data it can DMA to us and that we are prepared
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -080087 * to process
88 */
Sujithb77f4832008-12-07 21:44:03 +053089 ath9k_hw_setuprxdesc(ah, ds,
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -080090 common->rx_bufsize,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070091 0);
92
Sujithb77f4832008-12-07 21:44:03 +053093 if (sc->rx.rxlink == NULL)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070094 ath9k_hw_putrxbuf(ah, bf->bf_daddr);
95 else
Sujithb77f4832008-12-07 21:44:03 +053096 *sc->rx.rxlink = bf->bf_daddr;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070097
Sujithb77f4832008-12-07 21:44:03 +053098 sc->rx.rxlink = &ds->ds_link;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070099 ath9k_hw_rxena(ah);
100}
101
Sujithff37e332008-11-24 12:07:55 +0530102static void ath_setdefantenna(struct ath_softc *sc, u32 antenna)
103{
104 /* XXX block beacon interrupts */
105 ath9k_hw_setantenna(sc->sc_ah, antenna);
Sujithb77f4832008-12-07 21:44:03 +0530106 sc->rx.defant = antenna;
107 sc->rx.rxotherant = 0;
Sujithff37e332008-11-24 12:07:55 +0530108}
109
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700110static void ath_opmode_init(struct ath_softc *sc)
111{
Sujithcbe61d82009-02-09 13:27:12 +0530112 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700113 struct ath_common *common = ath9k_hw_common(ah);
114
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700115 u32 rfilt, mfilt[2];
116
117 /* configure rx filter */
118 rfilt = ath_calcrxfilter(sc);
119 ath9k_hw_setrxfilter(ah, rfilt);
120
121 /* configure bssid mask */
Felix Fietkau364734f2010-09-14 20:22:44 +0200122 ath_hw_setbssidmask(common);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700123
124 /* configure operational mode */
125 ath9k_hw_setopmode(ah);
126
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700127 /* calculate and install multicast filter */
128 mfilt[0] = mfilt[1] = ~0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700129 ath9k_hw_setmcastfilter(ah, mfilt[0], mfilt[1]);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700130}
131
Felix Fietkaub5c804752010-04-15 17:38:48 -0400132static bool ath_rx_edma_buf_link(struct ath_softc *sc,
133 enum ath9k_rx_qtype qtype)
134{
135 struct ath_hw *ah = sc->sc_ah;
136 struct ath_rx_edma *rx_edma;
137 struct sk_buff *skb;
138 struct ath_buf *bf;
139
140 rx_edma = &sc->rx.rx_edma[qtype];
141 if (skb_queue_len(&rx_edma->rx_fifo) >= rx_edma->rx_fifo_hwsize)
142 return false;
143
144 bf = list_first_entry(&sc->rx.rxbuf, struct ath_buf, list);
145 list_del_init(&bf->list);
146
147 skb = bf->bf_mpdu;
148
149 ATH_RXBUF_RESET(bf);
150 memset(skb->data, 0, ah->caps.rx_status_len);
151 dma_sync_single_for_device(sc->dev, bf->bf_buf_addr,
152 ah->caps.rx_status_len, DMA_TO_DEVICE);
153
154 SKB_CB_ATHBUF(skb) = bf;
155 ath9k_hw_addrxbuf_edma(ah, bf->bf_buf_addr, qtype);
156 skb_queue_tail(&rx_edma->rx_fifo, skb);
157
158 return true;
159}
160
161static void ath_rx_addbuffer_edma(struct ath_softc *sc,
162 enum ath9k_rx_qtype qtype, int size)
163{
Felix Fietkaub5c804752010-04-15 17:38:48 -0400164 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
165 u32 nbuf = 0;
166
Felix Fietkaub5c804752010-04-15 17:38:48 -0400167 if (list_empty(&sc->rx.rxbuf)) {
Joe Perches226afe62010-12-02 19:12:37 -0800168 ath_dbg(common, ATH_DBG_QUEUE, "No free rx buf available\n");
Felix Fietkaub5c804752010-04-15 17:38:48 -0400169 return;
170 }
171
172 while (!list_empty(&sc->rx.rxbuf)) {
173 nbuf++;
174
175 if (!ath_rx_edma_buf_link(sc, qtype))
176 break;
177
178 if (nbuf >= size)
179 break;
180 }
181}
182
183static void ath_rx_remove_buffer(struct ath_softc *sc,
184 enum ath9k_rx_qtype qtype)
185{
186 struct ath_buf *bf;
187 struct ath_rx_edma *rx_edma;
188 struct sk_buff *skb;
189
190 rx_edma = &sc->rx.rx_edma[qtype];
191
192 while ((skb = skb_dequeue(&rx_edma->rx_fifo)) != NULL) {
193 bf = SKB_CB_ATHBUF(skb);
194 BUG_ON(!bf);
195 list_add_tail(&bf->list, &sc->rx.rxbuf);
196 }
197}
198
199static void ath_rx_edma_cleanup(struct ath_softc *sc)
200{
201 struct ath_buf *bf;
202
203 ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_LP);
204 ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_HP);
205
206 list_for_each_entry(bf, &sc->rx.rxbuf, list) {
207 if (bf->bf_mpdu)
208 dev_kfree_skb_any(bf->bf_mpdu);
209 }
210
211 INIT_LIST_HEAD(&sc->rx.rxbuf);
212
213 kfree(sc->rx.rx_bufptr);
214 sc->rx.rx_bufptr = NULL;
215}
216
217static void ath_rx_edma_init_queue(struct ath_rx_edma *rx_edma, int size)
218{
219 skb_queue_head_init(&rx_edma->rx_fifo);
220 skb_queue_head_init(&rx_edma->rx_buffers);
221 rx_edma->rx_fifo_hwsize = size;
222}
223
224static int ath_rx_edma_init(struct ath_softc *sc, int nbufs)
225{
226 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
227 struct ath_hw *ah = sc->sc_ah;
228 struct sk_buff *skb;
229 struct ath_buf *bf;
230 int error = 0, i;
231 u32 size;
232
233
234 common->rx_bufsize = roundup(IEEE80211_MAX_MPDU_LEN +
235 ah->caps.rx_status_len,
236 min(common->cachelsz, (u16)64));
237
238 ath9k_hw_set_rx_bufsize(ah, common->rx_bufsize -
239 ah->caps.rx_status_len);
240
241 ath_rx_edma_init_queue(&sc->rx.rx_edma[ATH9K_RX_QUEUE_LP],
242 ah->caps.rx_lp_qdepth);
243 ath_rx_edma_init_queue(&sc->rx.rx_edma[ATH9K_RX_QUEUE_HP],
244 ah->caps.rx_hp_qdepth);
245
246 size = sizeof(struct ath_buf) * nbufs;
247 bf = kzalloc(size, GFP_KERNEL);
248 if (!bf)
249 return -ENOMEM;
250
251 INIT_LIST_HEAD(&sc->rx.rxbuf);
252 sc->rx.rx_bufptr = bf;
253
254 for (i = 0; i < nbufs; i++, bf++) {
255 skb = ath_rxbuf_alloc(common, common->rx_bufsize, GFP_KERNEL);
256 if (!skb) {
257 error = -ENOMEM;
258 goto rx_init_fail;
259 }
260
261 memset(skb->data, 0, common->rx_bufsize);
262 bf->bf_mpdu = skb;
263
264 bf->bf_buf_addr = dma_map_single(sc->dev, skb->data,
265 common->rx_bufsize,
266 DMA_BIDIRECTIONAL);
267 if (unlikely(dma_mapping_error(sc->dev,
268 bf->bf_buf_addr))) {
269 dev_kfree_skb_any(skb);
270 bf->bf_mpdu = NULL;
Ben Greear6cf9e992010-10-14 12:45:30 -0700271 bf->bf_buf_addr = 0;
Joe Perches38002762010-12-02 19:12:36 -0800272 ath_err(common,
Felix Fietkaub5c804752010-04-15 17:38:48 -0400273 "dma_mapping_error() on RX init\n");
274 error = -ENOMEM;
275 goto rx_init_fail;
276 }
277
278 list_add_tail(&bf->list, &sc->rx.rxbuf);
279 }
280
281 return 0;
282
283rx_init_fail:
284 ath_rx_edma_cleanup(sc);
285 return error;
286}
287
288static void ath_edma_start_recv(struct ath_softc *sc)
289{
290 spin_lock_bh(&sc->rx.rxbuflock);
291
292 ath9k_hw_rxena(sc->sc_ah);
293
294 ath_rx_addbuffer_edma(sc, ATH9K_RX_QUEUE_HP,
295 sc->rx.rx_edma[ATH9K_RX_QUEUE_HP].rx_fifo_hwsize);
296
297 ath_rx_addbuffer_edma(sc, ATH9K_RX_QUEUE_LP,
298 sc->rx.rx_edma[ATH9K_RX_QUEUE_LP].rx_fifo_hwsize);
299
Felix Fietkaub5c804752010-04-15 17:38:48 -0400300 ath_opmode_init(sc);
301
Luis R. Rodriguez48a6a462010-09-16 15:12:28 -0400302 ath9k_hw_startpcureceive(sc->sc_ah, (sc->sc_flags & SC_OP_OFFCHANNEL));
Luis R. Rodriguez7583c552010-10-20 16:07:04 -0700303
304 spin_unlock_bh(&sc->rx.rxbuflock);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400305}
306
307static void ath_edma_stop_recv(struct ath_softc *sc)
308{
Felix Fietkaub5c804752010-04-15 17:38:48 -0400309 ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_HP);
310 ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_LP);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400311}
312
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700313int ath_rx_init(struct ath_softc *sc, int nbufs)
314{
Luis R. Rodriguez27c51f12009-09-10 11:08:14 -0700315 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700316 struct sk_buff *skb;
317 struct ath_buf *bf;
318 int error = 0;
319
Luis R. Rodriguez4bdd1e92010-10-26 15:27:24 -0700320 spin_lock_init(&sc->sc_pcu_lock);
Sujith797fe5c2009-03-30 15:28:45 +0530321 sc->sc_flags &= ~SC_OP_RXFLUSH;
322 spin_lock_init(&sc->rx.rxbuflock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700323
Felix Fietkaub5c804752010-04-15 17:38:48 -0400324 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
325 return ath_rx_edma_init(sc, nbufs);
326 } else {
327 common->rx_bufsize = roundup(IEEE80211_MAX_MPDU_LEN,
328 min(common->cachelsz, (u16)64));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700329
Joe Perches226afe62010-12-02 19:12:37 -0800330 ath_dbg(common, ATH_DBG_CONFIG, "cachelsz %u rxbufsize %u\n",
331 common->cachelsz, common->rx_bufsize);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700332
Felix Fietkaub5c804752010-04-15 17:38:48 -0400333 /* Initialize rx descriptors */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700334
Felix Fietkaub5c804752010-04-15 17:38:48 -0400335 error = ath_descdma_setup(sc, &sc->rx.rxdma, &sc->rx.rxbuf,
Vasanthakumar Thiagarajan4adfcde2010-04-15 17:39:33 -0400336 "rx", nbufs, 1, 0);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400337 if (error != 0) {
Joe Perches38002762010-12-02 19:12:36 -0800338 ath_err(common,
339 "failed to allocate rx descriptors: %d\n",
340 error);
Sujith797fe5c2009-03-30 15:28:45 +0530341 goto err;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700342 }
Felix Fietkaub5c804752010-04-15 17:38:48 -0400343
344 list_for_each_entry(bf, &sc->rx.rxbuf, list) {
345 skb = ath_rxbuf_alloc(common, common->rx_bufsize,
346 GFP_KERNEL);
347 if (skb == NULL) {
348 error = -ENOMEM;
349 goto err;
350 }
351
352 bf->bf_mpdu = skb;
353 bf->bf_buf_addr = dma_map_single(sc->dev, skb->data,
354 common->rx_bufsize,
355 DMA_FROM_DEVICE);
356 if (unlikely(dma_mapping_error(sc->dev,
357 bf->bf_buf_addr))) {
358 dev_kfree_skb_any(skb);
359 bf->bf_mpdu = NULL;
Ben Greear6cf9e992010-10-14 12:45:30 -0700360 bf->bf_buf_addr = 0;
Joe Perches38002762010-12-02 19:12:36 -0800361 ath_err(common,
362 "dma_mapping_error() on RX init\n");
Felix Fietkaub5c804752010-04-15 17:38:48 -0400363 error = -ENOMEM;
364 goto err;
365 }
Felix Fietkaub5c804752010-04-15 17:38:48 -0400366 }
367 sc->rx.rxlink = NULL;
Sujith797fe5c2009-03-30 15:28:45 +0530368 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700369
Sujith797fe5c2009-03-30 15:28:45 +0530370err:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700371 if (error)
372 ath_rx_cleanup(sc);
373
374 return error;
375}
376
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700377void ath_rx_cleanup(struct ath_softc *sc)
378{
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -0800379 struct ath_hw *ah = sc->sc_ah;
380 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700381 struct sk_buff *skb;
382 struct ath_buf *bf;
383
Felix Fietkaub5c804752010-04-15 17:38:48 -0400384 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
385 ath_rx_edma_cleanup(sc);
386 return;
387 } else {
388 list_for_each_entry(bf, &sc->rx.rxbuf, list) {
389 skb = bf->bf_mpdu;
390 if (skb) {
391 dma_unmap_single(sc->dev, bf->bf_buf_addr,
392 common->rx_bufsize,
393 DMA_FROM_DEVICE);
394 dev_kfree_skb(skb);
Ben Greear6cf9e992010-10-14 12:45:30 -0700395 bf->bf_buf_addr = 0;
396 bf->bf_mpdu = NULL;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400397 }
Luis R. Rodriguez051b9192009-03-23 18:25:01 -0400398 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700399
Felix Fietkaub5c804752010-04-15 17:38:48 -0400400 if (sc->rx.rxdma.dd_desc_len != 0)
401 ath_descdma_cleanup(sc, &sc->rx.rxdma, &sc->rx.rxbuf);
402 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700403}
404
405/*
406 * Calculate the receive filter according to the
407 * operating mode and state:
408 *
409 * o always accept unicast, broadcast, and multicast traffic
410 * o maintain current state of phy error reception (the hal
411 * may enable phy error frames for noise immunity work)
412 * o probe request frames are accepted only when operating in
413 * hostap, adhoc, or monitor modes
414 * o enable promiscuous mode according to the interface state
415 * o accept beacons:
416 * - when operating in adhoc mode so the 802.11 layer creates
417 * node table entries for peers,
418 * - when operating in station mode for collecting rssi data when
419 * the station is otherwise quiet, or
420 * - when operating as a repeater so we see repeater-sta beacons
421 * - when scanning
422 */
423
424u32 ath_calcrxfilter(struct ath_softc *sc)
425{
426#define RX_FILTER_PRESERVE (ATH9K_RX_FILTER_PHYERR | ATH9K_RX_FILTER_PHYRADAR)
Sujith7dcfdcd2008-08-11 14:03:13 +0530427
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700428 u32 rfilt;
429
430 rfilt = (ath9k_hw_getrxfilter(sc->sc_ah) & RX_FILTER_PRESERVE)
431 | ATH9K_RX_FILTER_UCAST | ATH9K_RX_FILTER_BCAST
432 | ATH9K_RX_FILTER_MCAST;
433
Jouni Malinen9c1d8e42010-10-13 17:29:31 +0300434 if (sc->rx.rxfilter & FIF_PROBE_REQ)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700435 rfilt |= ATH9K_RX_FILTER_PROBEREQ;
436
Jouni Malinen217ba9d2009-03-10 10:55:50 +0200437 /*
438 * Set promiscuous mode when FIF_PROMISC_IN_BSS is enabled for station
439 * mode interface or when in monitor mode. AP mode does not need this
440 * since it receives all in-BSS frames anyway.
441 */
Sujith2660b812009-02-09 13:27:26 +0530442 if (((sc->sc_ah->opmode != NL80211_IFTYPE_AP) &&
Sujithb77f4832008-12-07 21:44:03 +0530443 (sc->rx.rxfilter & FIF_PROMISC_IN_BSS)) ||
Rajkumar Manoharan5f841b42010-10-27 18:31:15 +0530444 (sc->sc_ah->is_monitoring))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700445 rfilt |= ATH9K_RX_FILTER_PROM;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700446
Sujithd42c6b72009-02-04 08:10:22 +0530447 if (sc->rx.rxfilter & FIF_CONTROL)
448 rfilt |= ATH9K_RX_FILTER_CONTROL;
449
Vasanthakumar Thiagarajandbaaa142009-02-19 15:41:52 +0530450 if ((sc->sc_ah->opmode == NL80211_IFTYPE_STATION) &&
Ben Greearcfda6692010-09-14 12:00:22 -0700451 (sc->nvifs <= 1) &&
Vasanthakumar Thiagarajandbaaa142009-02-19 15:41:52 +0530452 !(sc->rx.rxfilter & FIF_BCN_PRBRESP_PROMISC))
453 rfilt |= ATH9K_RX_FILTER_MYBEACON;
454 else
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700455 rfilt |= ATH9K_RX_FILTER_BEACON;
456
Felix Fietkau7a370812010-09-22 12:34:52 +0200457 if ((AR_SREV_9280_20_OR_LATER(sc->sc_ah) ||
Felix Fietkaue17f83e2010-09-22 12:34:53 +0200458 AR_SREV_9285_12_OR_LATER(sc->sc_ah)) &&
Senthil Balasubramanian66afad02009-09-18 15:06:07 +0530459 (sc->sc_ah->opmode == NL80211_IFTYPE_AP) &&
460 (sc->rx.rxfilter & FIF_PSPOLL))
Vasanthakumar Thiagarajandbaaa142009-02-19 15:41:52 +0530461 rfilt |= ATH9K_RX_FILTER_PSPOLL;
Sujithbe0418a2008-11-18 09:05:55 +0530462
Sujith7ea310b2009-09-03 12:08:43 +0530463 if (conf_is_ht(&sc->hw->conf))
464 rfilt |= ATH9K_RX_FILTER_COMP_BAR;
465
Ben Greearcfda6692010-09-14 12:00:22 -0700466 if (sc->sec_wiphy || (sc->nvifs > 1) ||
467 (sc->rx.rxfilter & FIF_OTHER_BSS)) {
Javier Cardona5eb6ba82009-08-20 19:12:07 -0700468 /* The following may also be needed for other older chips */
469 if (sc->sc_ah->hw_version.macVersion == AR_SREV_VERSION_9160)
470 rfilt |= ATH9K_RX_FILTER_PROM;
Jouni Malinenb93bce22009-03-03 19:23:30 +0200471 rfilt |= ATH9K_RX_FILTER_MCAST_BCAST_ALL;
472 }
473
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700474 return rfilt;
Sujith7dcfdcd2008-08-11 14:03:13 +0530475
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700476#undef RX_FILTER_PRESERVE
477}
478
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700479int ath_startrecv(struct ath_softc *sc)
480{
Sujithcbe61d82009-02-09 13:27:12 +0530481 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700482 struct ath_buf *bf, *tbf;
483
Felix Fietkaub5c804752010-04-15 17:38:48 -0400484 if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
485 ath_edma_start_recv(sc);
486 return 0;
487 }
488
Sujithb77f4832008-12-07 21:44:03 +0530489 spin_lock_bh(&sc->rx.rxbuflock);
490 if (list_empty(&sc->rx.rxbuf))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700491 goto start_recv;
492
Sujithb77f4832008-12-07 21:44:03 +0530493 sc->rx.rxlink = NULL;
494 list_for_each_entry_safe(bf, tbf, &sc->rx.rxbuf, list) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700495 ath_rx_buf_link(sc, bf);
496 }
497
498 /* We could have deleted elements so the list may be empty now */
Sujithb77f4832008-12-07 21:44:03 +0530499 if (list_empty(&sc->rx.rxbuf))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700500 goto start_recv;
501
Sujithb77f4832008-12-07 21:44:03 +0530502 bf = list_first_entry(&sc->rx.rxbuf, struct ath_buf, list);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700503 ath9k_hw_putrxbuf(ah, bf->bf_daddr);
Sujithbe0418a2008-11-18 09:05:55 +0530504 ath9k_hw_rxena(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700505
506start_recv:
Sujithbe0418a2008-11-18 09:05:55 +0530507 ath_opmode_init(sc);
Luis R. Rodriguez48a6a462010-09-16 15:12:28 -0400508 ath9k_hw_startpcureceive(ah, (sc->sc_flags & SC_OP_OFFCHANNEL));
Sujithbe0418a2008-11-18 09:05:55 +0530509
Luis R. Rodriguez7583c552010-10-20 16:07:04 -0700510 spin_unlock_bh(&sc->rx.rxbuflock);
511
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700512 return 0;
513}
514
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700515bool ath_stoprecv(struct ath_softc *sc)
516{
Sujithcbe61d82009-02-09 13:27:12 +0530517 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700518 bool stopped;
519
Luis R. Rodriguez1e450282010-10-20 16:07:03 -0700520 spin_lock_bh(&sc->rx.rxbuflock);
Felix Fietkaud47844a2010-11-20 03:08:47 +0100521 ath9k_hw_abortpcurecv(ah);
Sujithbe0418a2008-11-18 09:05:55 +0530522 ath9k_hw_setrxfilter(ah, 0);
523 stopped = ath9k_hw_stopdmarecv(ah);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400524
525 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
526 ath_edma_stop_recv(sc);
527 else
528 sc->rx.rxlink = NULL;
Luis R. Rodriguez1e450282010-10-20 16:07:03 -0700529 spin_unlock_bh(&sc->rx.rxbuflock);
Sujithbe0418a2008-11-18 09:05:55 +0530530
Ben Greeard7fd1b502010-12-06 13:13:07 -0800531 if (unlikely(!stopped)) {
532 ath_err(ath9k_hw_common(sc->sc_ah),
533 "Could not stop RX, we could be "
534 "confusing the DMA engine when we start RX up\n");
535 ATH_DBG_WARN_ON_ONCE(!stopped);
536 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700537 return stopped;
538}
539
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700540void ath_flushrecv(struct ath_softc *sc)
541{
Sujith98deeea2008-08-11 14:05:46 +0530542 sc->sc_flags |= SC_OP_RXFLUSH;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400543 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
544 ath_rx_tasklet(sc, 1, true);
545 ath_rx_tasklet(sc, 1, false);
Sujith98deeea2008-08-11 14:05:46 +0530546 sc->sc_flags &= ~SC_OP_RXFLUSH;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700547}
548
Jouni Malinencc659652009-05-14 21:28:48 +0300549static bool ath_beacon_dtim_pending_cab(struct sk_buff *skb)
550{
551 /* Check whether the Beacon frame has DTIM indicating buffered bc/mc */
552 struct ieee80211_mgmt *mgmt;
553 u8 *pos, *end, id, elen;
554 struct ieee80211_tim_ie *tim;
555
556 mgmt = (struct ieee80211_mgmt *)skb->data;
557 pos = mgmt->u.beacon.variable;
558 end = skb->data + skb->len;
559
560 while (pos + 2 < end) {
561 id = *pos++;
562 elen = *pos++;
563 if (pos + elen > end)
564 break;
565
566 if (id == WLAN_EID_TIM) {
567 if (elen < sizeof(*tim))
568 break;
569 tim = (struct ieee80211_tim_ie *) pos;
570 if (tim->dtim_count != 0)
571 break;
572 return tim->bitmap_ctrl & 0x01;
573 }
574
575 pos += elen;
576 }
577
578 return false;
579}
580
Jouni Malinencc659652009-05-14 21:28:48 +0300581static void ath_rx_ps_beacon(struct ath_softc *sc, struct sk_buff *skb)
582{
583 struct ieee80211_mgmt *mgmt;
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700584 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Jouni Malinencc659652009-05-14 21:28:48 +0300585
586 if (skb->len < 24 + 8 + 2 + 2)
587 return;
588
589 mgmt = (struct ieee80211_mgmt *)skb->data;
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700590 if (memcmp(common->curbssid, mgmt->bssid, ETH_ALEN) != 0)
Jouni Malinencc659652009-05-14 21:28:48 +0300591 return; /* not from our current AP */
592
Sujith1b04b932010-01-08 10:36:05 +0530593 sc->ps_flags &= ~PS_WAIT_FOR_BEACON;
Gabor Juhos293dc5d2009-06-19 12:17:48 +0200594
Sujith1b04b932010-01-08 10:36:05 +0530595 if (sc->ps_flags & PS_BEACON_SYNC) {
596 sc->ps_flags &= ~PS_BEACON_SYNC;
Joe Perches226afe62010-12-02 19:12:37 -0800597 ath_dbg(common, ATH_DBG_PS,
598 "Reconfigure Beacon timers based on timestamp from the AP\n");
Jouni Malinenccdfeab2009-05-20 21:59:08 +0300599 ath_beacon_config(sc, NULL);
600 }
601
Jouni Malinencc659652009-05-14 21:28:48 +0300602 if (ath_beacon_dtim_pending_cab(skb)) {
603 /*
604 * Remain awake waiting for buffered broadcast/multicast
Gabor Juhos58f5fff2009-06-17 20:53:20 +0200605 * frames. If the last broadcast/multicast frame is not
606 * received properly, the next beacon frame will work as
607 * a backup trigger for returning into NETWORK SLEEP state,
608 * so we are waiting for it as well.
Jouni Malinencc659652009-05-14 21:28:48 +0300609 */
Joe Perches226afe62010-12-02 19:12:37 -0800610 ath_dbg(common, ATH_DBG_PS,
611 "Received DTIM beacon indicating buffered broadcast/multicast frame(s)\n");
Sujith1b04b932010-01-08 10:36:05 +0530612 sc->ps_flags |= PS_WAIT_FOR_CAB | PS_WAIT_FOR_BEACON;
Jouni Malinencc659652009-05-14 21:28:48 +0300613 return;
614 }
615
Sujith1b04b932010-01-08 10:36:05 +0530616 if (sc->ps_flags & PS_WAIT_FOR_CAB) {
Jouni Malinencc659652009-05-14 21:28:48 +0300617 /*
618 * This can happen if a broadcast frame is dropped or the AP
619 * fails to send a frame indicating that all CAB frames have
620 * been delivered.
621 */
Sujith1b04b932010-01-08 10:36:05 +0530622 sc->ps_flags &= ~PS_WAIT_FOR_CAB;
Joe Perches226afe62010-12-02 19:12:37 -0800623 ath_dbg(common, ATH_DBG_PS,
624 "PS wait for CAB frames timed out\n");
Jouni Malinencc659652009-05-14 21:28:48 +0300625 }
Jouni Malinencc659652009-05-14 21:28:48 +0300626}
627
628static void ath_rx_ps(struct ath_softc *sc, struct sk_buff *skb)
629{
630 struct ieee80211_hdr *hdr;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700631 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Jouni Malinencc659652009-05-14 21:28:48 +0300632
633 hdr = (struct ieee80211_hdr *)skb->data;
634
635 /* Process Beacon and CAB receive in PS state */
Vasanthakumar Thiagarajanededf1f2010-05-22 23:58:13 -0700636 if (((sc->ps_flags & PS_WAIT_FOR_BEACON) || ath9k_check_auto_sleep(sc))
637 && ieee80211_is_beacon(hdr->frame_control))
Jouni Malinencc659652009-05-14 21:28:48 +0300638 ath_rx_ps_beacon(sc, skb);
Sujith1b04b932010-01-08 10:36:05 +0530639 else if ((sc->ps_flags & PS_WAIT_FOR_CAB) &&
Jouni Malinencc659652009-05-14 21:28:48 +0300640 (ieee80211_is_data(hdr->frame_control) ||
641 ieee80211_is_action(hdr->frame_control)) &&
642 is_multicast_ether_addr(hdr->addr1) &&
643 !ieee80211_has_moredata(hdr->frame_control)) {
Jouni Malinencc659652009-05-14 21:28:48 +0300644 /*
645 * No more broadcast/multicast frames to be received at this
646 * point.
647 */
Senthil Balasubramanian3fac6df2010-09-16 15:12:35 -0400648 sc->ps_flags &= ~(PS_WAIT_FOR_CAB | PS_WAIT_FOR_BEACON);
Joe Perches226afe62010-12-02 19:12:37 -0800649 ath_dbg(common, ATH_DBG_PS,
650 "All PS CAB frames received, back to sleep\n");
Sujith1b04b932010-01-08 10:36:05 +0530651 } else if ((sc->ps_flags & PS_WAIT_FOR_PSPOLL_DATA) &&
Jouni Malinen9a23f9c2009-05-19 17:01:38 +0300652 !is_multicast_ether_addr(hdr->addr1) &&
653 !ieee80211_has_morefrags(hdr->frame_control)) {
Sujith1b04b932010-01-08 10:36:05 +0530654 sc->ps_flags &= ~PS_WAIT_FOR_PSPOLL_DATA;
Joe Perches226afe62010-12-02 19:12:37 -0800655 ath_dbg(common, ATH_DBG_PS,
656 "Going back to sleep after having received PS-Poll data (0x%lx)\n",
Sujith1b04b932010-01-08 10:36:05 +0530657 sc->ps_flags & (PS_WAIT_FOR_BEACON |
658 PS_WAIT_FOR_CAB |
659 PS_WAIT_FOR_PSPOLL_DATA |
660 PS_WAIT_FOR_TX_ACK));
Jouni Malinencc659652009-05-14 21:28:48 +0300661 }
662}
663
Luis R. Rodriguezb4afffc2009-11-02 11:36:08 -0800664static void ath_rx_send_to_mac80211(struct ieee80211_hw *hw,
Mohammed Shafi Shajakhancae6b742010-12-07 21:23:16 +0530665 struct ath_softc *sc, struct sk_buff *skb)
Jouni Malinen9d64a3c2009-05-14 21:28:47 +0300666{
667 struct ieee80211_hdr *hdr;
668
669 hdr = (struct ieee80211_hdr *)skb->data;
670
671 /* Send the frame to mac80211 */
672 if (is_multicast_ether_addr(hdr->addr1)) {
673 int i;
674 /*
675 * Deliver broadcast/multicast frames to all suitable
676 * virtual wiphys.
677 */
678 /* TODO: filter based on channel configuration */
679 for (i = 0; i < sc->num_sec_wiphy; i++) {
680 struct ath_wiphy *aphy = sc->sec_wiphy[i];
681 struct sk_buff *nskb;
682 if (aphy == NULL)
683 continue;
684 nskb = skb_copy(skb, GFP_ATOMIC);
Luis R. Rodriguez5ca42622009-11-04 08:20:42 -0800685 if (!nskb)
686 continue;
687 ieee80211_rx(aphy->hw, nskb);
Jouni Malinen9d64a3c2009-05-14 21:28:47 +0300688 }
Johannes Bergf1d58c22009-06-17 13:13:00 +0200689 ieee80211_rx(sc->hw, skb);
Luis R. Rodriguez5ca42622009-11-04 08:20:42 -0800690 } else
Jouni Malinen9d64a3c2009-05-14 21:28:47 +0300691 /* Deliver unicast frames based on receiver address */
Luis R. Rodriguezb4afffc2009-11-02 11:36:08 -0800692 ieee80211_rx(hw, skb);
Jouni Malinen9d64a3c2009-05-14 21:28:47 +0300693}
694
Felix Fietkaub5c804752010-04-15 17:38:48 -0400695static bool ath_edma_get_buffers(struct ath_softc *sc,
696 enum ath9k_rx_qtype qtype)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700697{
Felix Fietkaub5c804752010-04-15 17:38:48 -0400698 struct ath_rx_edma *rx_edma = &sc->rx.rx_edma[qtype];
699 struct ath_hw *ah = sc->sc_ah;
700 struct ath_common *common = ath9k_hw_common(ah);
701 struct sk_buff *skb;
Sujithbe0418a2008-11-18 09:05:55 +0530702 struct ath_buf *bf;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400703 int ret;
704
705 skb = skb_peek(&rx_edma->rx_fifo);
706 if (!skb)
707 return false;
708
709 bf = SKB_CB_ATHBUF(skb);
710 BUG_ON(!bf);
711
Ming Leice9426d2010-05-15 18:25:40 +0800712 dma_sync_single_for_cpu(sc->dev, bf->bf_buf_addr,
Felix Fietkaub5c804752010-04-15 17:38:48 -0400713 common->rx_bufsize, DMA_FROM_DEVICE);
714
715 ret = ath9k_hw_process_rxdesc_edma(ah, NULL, skb->data);
Ming Leice9426d2010-05-15 18:25:40 +0800716 if (ret == -EINPROGRESS) {
717 /*let device gain the buffer again*/
718 dma_sync_single_for_device(sc->dev, bf->bf_buf_addr,
719 common->rx_bufsize, DMA_FROM_DEVICE);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400720 return false;
Ming Leice9426d2010-05-15 18:25:40 +0800721 }
Felix Fietkaub5c804752010-04-15 17:38:48 -0400722
723 __skb_unlink(skb, &rx_edma->rx_fifo);
724 if (ret == -EINVAL) {
725 /* corrupt descriptor, skip this one and the following one */
726 list_add_tail(&bf->list, &sc->rx.rxbuf);
727 ath_rx_edma_buf_link(sc, qtype);
728 skb = skb_peek(&rx_edma->rx_fifo);
729 if (!skb)
730 return true;
731
732 bf = SKB_CB_ATHBUF(skb);
733 BUG_ON(!bf);
734
735 __skb_unlink(skb, &rx_edma->rx_fifo);
736 list_add_tail(&bf->list, &sc->rx.rxbuf);
737 ath_rx_edma_buf_link(sc, qtype);
Vasanthakumar Thiagarajan083e3e82010-05-10 19:41:34 -0700738 return true;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400739 }
740 skb_queue_tail(&rx_edma->rx_buffers, skb);
741
742 return true;
743}
744
745static struct ath_buf *ath_edma_get_next_rx_buf(struct ath_softc *sc,
746 struct ath_rx_status *rs,
747 enum ath9k_rx_qtype qtype)
748{
749 struct ath_rx_edma *rx_edma = &sc->rx.rx_edma[qtype];
750 struct sk_buff *skb;
751 struct ath_buf *bf;
752
753 while (ath_edma_get_buffers(sc, qtype));
754 skb = __skb_dequeue(&rx_edma->rx_buffers);
755 if (!skb)
756 return NULL;
757
758 bf = SKB_CB_ATHBUF(skb);
759 ath9k_hw_process_rxdesc_edma(sc->sc_ah, rs, skb->data);
760 return bf;
761}
762
763static struct ath_buf *ath_get_next_rx_buf(struct ath_softc *sc,
764 struct ath_rx_status *rs)
765{
766 struct ath_hw *ah = sc->sc_ah;
767 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700768 struct ath_desc *ds;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400769 struct ath_buf *bf;
770 int ret;
771
772 if (list_empty(&sc->rx.rxbuf)) {
773 sc->rx.rxlink = NULL;
774 return NULL;
775 }
776
777 bf = list_first_entry(&sc->rx.rxbuf, struct ath_buf, list);
778 ds = bf->bf_desc;
779
780 /*
781 * Must provide the virtual address of the current
782 * descriptor, the physical address, and the virtual
783 * address of the next descriptor in the h/w chain.
784 * This allows the HAL to look ahead to see if the
785 * hardware is done with a descriptor by checking the
786 * done bit in the following descriptor and the address
787 * of the current descriptor the DMA engine is working
788 * on. All this is necessary because of our use of
789 * a self-linked list to avoid rx overruns.
790 */
791 ret = ath9k_hw_rxprocdesc(ah, ds, rs, 0);
792 if (ret == -EINPROGRESS) {
793 struct ath_rx_status trs;
794 struct ath_buf *tbf;
795 struct ath_desc *tds;
796
797 memset(&trs, 0, sizeof(trs));
798 if (list_is_last(&bf->list, &sc->rx.rxbuf)) {
799 sc->rx.rxlink = NULL;
800 return NULL;
801 }
802
803 tbf = list_entry(bf->list.next, struct ath_buf, list);
804
805 /*
806 * On some hardware the descriptor status words could
807 * get corrupted, including the done bit. Because of
808 * this, check if the next descriptor's done bit is
809 * set or not.
810 *
811 * If the next descriptor's done bit is set, the current
812 * descriptor has been corrupted. Force s/w to discard
813 * this descriptor and continue...
814 */
815
816 tds = tbf->bf_desc;
817 ret = ath9k_hw_rxprocdesc(ah, tds, &trs, 0);
818 if (ret == -EINPROGRESS)
819 return NULL;
820 }
821
822 if (!bf->bf_mpdu)
823 return bf;
824
825 /*
826 * Synchronize the DMA transfer with CPU before
827 * 1. accessing the frame
828 * 2. requeueing the same buffer to h/w
829 */
Ming Leice9426d2010-05-15 18:25:40 +0800830 dma_sync_single_for_cpu(sc->dev, bf->bf_buf_addr,
Felix Fietkaub5c804752010-04-15 17:38:48 -0400831 common->rx_bufsize,
832 DMA_FROM_DEVICE);
833
834 return bf;
835}
836
Sujithd4357002010-05-20 15:34:38 +0530837/* Assumes you've already done the endian to CPU conversion */
838static bool ath9k_rx_accept(struct ath_common *common,
Vasanthakumar Thiagarajan9f167f62010-05-20 14:34:46 -0700839 struct ieee80211_hdr *hdr,
Sujithd4357002010-05-20 15:34:38 +0530840 struct ieee80211_rx_status *rxs,
841 struct ath_rx_status *rx_stats,
842 bool *decrypt_error)
843{
844 struct ath_hw *ah = common->ah;
Sujithd4357002010-05-20 15:34:38 +0530845 __le16 fc;
Vasanthakumar Thiagarajanb7b1b512010-05-20 14:34:48 -0700846 u8 rx_status_len = ah->caps.rx_status_len;
Sujithd4357002010-05-20 15:34:38 +0530847
Sujithd4357002010-05-20 15:34:38 +0530848 fc = hdr->frame_control;
849
850 if (!rx_stats->rs_datalen)
851 return false;
852 /*
853 * rs_status follows rs_datalen so if rs_datalen is too large
854 * we can take a hint that hardware corrupted it, so ignore
855 * those frames.
856 */
Vasanthakumar Thiagarajanb7b1b512010-05-20 14:34:48 -0700857 if (rx_stats->rs_datalen > (common->rx_bufsize - rx_status_len))
Sujithd4357002010-05-20 15:34:38 +0530858 return false;
859
860 /*
861 * rs_more indicates chained descriptors which can be used
862 * to link buffers together for a sort of scatter-gather
863 * operation.
864 * reject the frame, we don't support scatter-gather yet and
865 * the frame is probably corrupt anyway
866 */
867 if (rx_stats->rs_more)
868 return false;
869
870 /*
871 * The rx_stats->rs_status will not be set until the end of the
872 * chained descriptors so it can be ignored if rs_more is set. The
873 * rs_more will be false at the last element of the chained
874 * descriptors.
875 */
876 if (rx_stats->rs_status != 0) {
877 if (rx_stats->rs_status & ATH9K_RXERR_CRC)
878 rxs->flag |= RX_FLAG_FAILED_FCS_CRC;
879 if (rx_stats->rs_status & ATH9K_RXERR_PHY)
880 return false;
881
882 if (rx_stats->rs_status & ATH9K_RXERR_DECRYPT) {
883 *decrypt_error = true;
884 } else if (rx_stats->rs_status & ATH9K_RXERR_MIC) {
Felix Fietkau56363dd2010-08-28 18:21:21 +0200885 /*
886 * The MIC error bit is only valid if the frame
887 * is not a control frame or fragment, and it was
888 * decrypted using a valid TKIP key.
889 */
890 if (!ieee80211_is_ctl(fc) &&
891 !ieee80211_has_morefrags(fc) &&
892 !(le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG) &&
893 test_bit(rx_stats->rs_keyix, common->tkip_keymap))
Sujithd4357002010-05-20 15:34:38 +0530894 rxs->flag |= RX_FLAG_MMIC_ERROR;
Felix Fietkau56363dd2010-08-28 18:21:21 +0200895 else
896 rx_stats->rs_status &= ~ATH9K_RXERR_MIC;
Sujithd4357002010-05-20 15:34:38 +0530897 }
898 /*
899 * Reject error frames with the exception of
900 * decryption and MIC failures. For monitor mode,
901 * we also ignore the CRC error.
902 */
Rajkumar Manoharan5f841b42010-10-27 18:31:15 +0530903 if (ah->is_monitoring) {
Sujithd4357002010-05-20 15:34:38 +0530904 if (rx_stats->rs_status &
905 ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC |
906 ATH9K_RXERR_CRC))
907 return false;
908 } else {
909 if (rx_stats->rs_status &
910 ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC)) {
911 return false;
912 }
913 }
914 }
915 return true;
916}
917
918static int ath9k_process_rate(struct ath_common *common,
919 struct ieee80211_hw *hw,
920 struct ath_rx_status *rx_stats,
Vasanthakumar Thiagarajan9f167f62010-05-20 14:34:46 -0700921 struct ieee80211_rx_status *rxs)
Sujithd4357002010-05-20 15:34:38 +0530922{
923 struct ieee80211_supported_band *sband;
924 enum ieee80211_band band;
925 unsigned int i = 0;
926
927 band = hw->conf.channel->band;
928 sband = hw->wiphy->bands[band];
929
930 if (rx_stats->rs_rate & 0x80) {
931 /* HT rate */
932 rxs->flag |= RX_FLAG_HT;
933 if (rx_stats->rs_flags & ATH9K_RX_2040)
934 rxs->flag |= RX_FLAG_40MHZ;
935 if (rx_stats->rs_flags & ATH9K_RX_GI)
936 rxs->flag |= RX_FLAG_SHORT_GI;
937 rxs->rate_idx = rx_stats->rs_rate & 0x7f;
938 return 0;
939 }
940
941 for (i = 0; i < sband->n_bitrates; i++) {
942 if (sband->bitrates[i].hw_value == rx_stats->rs_rate) {
943 rxs->rate_idx = i;
944 return 0;
945 }
946 if (sband->bitrates[i].hw_value_short == rx_stats->rs_rate) {
947 rxs->flag |= RX_FLAG_SHORTPRE;
948 rxs->rate_idx = i;
949 return 0;
950 }
951 }
952
953 /*
954 * No valid hardware bitrate found -- we should not get here
955 * because hardware has already validated this frame as OK.
956 */
Joe Perches226afe62010-12-02 19:12:37 -0800957 ath_dbg(common, ATH_DBG_XMIT,
958 "unsupported hw bitrate detected 0x%02x using 1 Mbit\n",
959 rx_stats->rs_rate);
Sujithd4357002010-05-20 15:34:38 +0530960
961 return -EINVAL;
962}
963
964static void ath9k_process_rssi(struct ath_common *common,
965 struct ieee80211_hw *hw,
Vasanthakumar Thiagarajan9f167f62010-05-20 14:34:46 -0700966 struct ieee80211_hdr *hdr,
Sujithd4357002010-05-20 15:34:38 +0530967 struct ath_rx_status *rx_stats)
968{
Felix Fietkau9fa23e12010-10-15 20:03:31 +0200969 struct ath_wiphy *aphy = hw->priv;
Sujithd4357002010-05-20 15:34:38 +0530970 struct ath_hw *ah = common->ah;
Felix Fietkau9fa23e12010-10-15 20:03:31 +0200971 int last_rssi;
Sujithd4357002010-05-20 15:34:38 +0530972 __le16 fc;
973
Felix Fietkau9fa23e12010-10-15 20:03:31 +0200974 if (ah->opmode != NL80211_IFTYPE_STATION)
975 return;
976
Sujithd4357002010-05-20 15:34:38 +0530977 fc = hdr->frame_control;
Felix Fietkau9fa23e12010-10-15 20:03:31 +0200978 if (!ieee80211_is_beacon(fc) ||
979 compare_ether_addr(hdr->addr3, common->curbssid))
980 return;
Sujithd4357002010-05-20 15:34:38 +0530981
Felix Fietkau9fa23e12010-10-15 20:03:31 +0200982 if (rx_stats->rs_rssi != ATH9K_RSSI_BAD && !rx_stats->rs_moreaggr)
983 ATH_RSSI_LPF(aphy->last_rssi, rx_stats->rs_rssi);
Ben Greear686b9cb2010-09-23 09:44:36 -0700984
Felix Fietkau9fa23e12010-10-15 20:03:31 +0200985 last_rssi = aphy->last_rssi;
Sujithd4357002010-05-20 15:34:38 +0530986 if (likely(last_rssi != ATH_RSSI_DUMMY_MARKER))
987 rx_stats->rs_rssi = ATH_EP_RND(last_rssi,
988 ATH_RSSI_EP_MULTIPLIER);
989 if (rx_stats->rs_rssi < 0)
990 rx_stats->rs_rssi = 0;
991
992 /* Update Beacon RSSI, this is used by ANI. */
Felix Fietkau9fa23e12010-10-15 20:03:31 +0200993 ah->stats.avgbrssi = rx_stats->rs_rssi;
Sujithd4357002010-05-20 15:34:38 +0530994}
995
996/*
997 * For Decrypt or Demic errors, we only mark packet status here and always push
998 * up the frame up to let mac80211 handle the actual error case, be it no
999 * decryption key or real decryption error. This let us keep statistics there.
1000 */
1001static int ath9k_rx_skb_preprocess(struct ath_common *common,
1002 struct ieee80211_hw *hw,
Vasanthakumar Thiagarajan9f167f62010-05-20 14:34:46 -07001003 struct ieee80211_hdr *hdr,
Sujithd4357002010-05-20 15:34:38 +05301004 struct ath_rx_status *rx_stats,
1005 struct ieee80211_rx_status *rx_status,
1006 bool *decrypt_error)
1007{
Sujithd4357002010-05-20 15:34:38 +05301008 memset(rx_status, 0, sizeof(struct ieee80211_rx_status));
1009
1010 /*
1011 * everything but the rate is checked here, the rate check is done
1012 * separately to avoid doing two lookups for a rate for each frame.
1013 */
Vasanthakumar Thiagarajan9f167f62010-05-20 14:34:46 -07001014 if (!ath9k_rx_accept(common, hdr, rx_status, rx_stats, decrypt_error))
Sujithd4357002010-05-20 15:34:38 +05301015 return -EINVAL;
1016
Vasanthakumar Thiagarajan9f167f62010-05-20 14:34:46 -07001017 ath9k_process_rssi(common, hw, hdr, rx_stats);
Sujithd4357002010-05-20 15:34:38 +05301018
Vasanthakumar Thiagarajan9f167f62010-05-20 14:34:46 -07001019 if (ath9k_process_rate(common, hw, rx_stats, rx_status))
Sujithd4357002010-05-20 15:34:38 +05301020 return -EINVAL;
1021
Sujithd4357002010-05-20 15:34:38 +05301022 rx_status->band = hw->conf.channel->band;
1023 rx_status->freq = hw->conf.channel->center_freq;
1024 rx_status->signal = ATH_DEFAULT_NOISE_FLOOR + rx_stats->rs_rssi;
1025 rx_status->antenna = rx_stats->rs_antenna;
1026 rx_status->flag |= RX_FLAG_TSFT;
1027
1028 return 0;
1029}
1030
1031static void ath9k_rx_skb_postprocess(struct ath_common *common,
1032 struct sk_buff *skb,
1033 struct ath_rx_status *rx_stats,
1034 struct ieee80211_rx_status *rxs,
1035 bool decrypt_error)
1036{
1037 struct ath_hw *ah = common->ah;
1038 struct ieee80211_hdr *hdr;
1039 int hdrlen, padpos, padsize;
1040 u8 keyix;
1041 __le16 fc;
1042
1043 /* see if any padding is done by the hw and remove it */
1044 hdr = (struct ieee80211_hdr *) skb->data;
1045 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
1046 fc = hdr->frame_control;
1047 padpos = ath9k_cmn_padpos(hdr->frame_control);
1048
1049 /* The MAC header is padded to have 32-bit boundary if the
1050 * packet payload is non-zero. The general calculation for
1051 * padsize would take into account odd header lengths:
1052 * padsize = (4 - padpos % 4) % 4; However, since only
1053 * even-length headers are used, padding can only be 0 or 2
1054 * bytes and we can optimize this a bit. In addition, we must
1055 * not try to remove padding from short control frames that do
1056 * not have payload. */
1057 padsize = padpos & 3;
1058 if (padsize && skb->len>=padpos+padsize+FCS_LEN) {
1059 memmove(skb->data + padsize, skb->data, padpos);
1060 skb_pull(skb, padsize);
1061 }
1062
1063 keyix = rx_stats->rs_keyix;
1064
1065 if (!(keyix == ATH9K_RXKEYIX_INVALID) && !decrypt_error &&
1066 ieee80211_has_protected(fc)) {
1067 rxs->flag |= RX_FLAG_DECRYPTED;
1068 } else if (ieee80211_has_protected(fc)
1069 && !decrypt_error && skb->len >= hdrlen + 4) {
1070 keyix = skb->data[hdrlen + 3] >> 6;
1071
1072 if (test_bit(keyix, common->keymap))
1073 rxs->flag |= RX_FLAG_DECRYPTED;
1074 }
1075 if (ah->sw_mgmt_crypto &&
1076 (rxs->flag & RX_FLAG_DECRYPTED) &&
1077 ieee80211_is_mgmt(fc))
1078 /* Use software decrypt for management frames. */
1079 rxs->flag &= ~RX_FLAG_DECRYPTED;
1080}
Felix Fietkaub5c804752010-04-15 17:38:48 -04001081
Vasanthakumar Thiagarajan102885a2010-09-02 01:34:43 -07001082static void ath_lnaconf_alt_good_scan(struct ath_ant_comb *antcomb,
1083 struct ath_hw_antcomb_conf ant_conf,
1084 int main_rssi_avg)
1085{
1086 antcomb->quick_scan_cnt = 0;
1087
1088 if (ant_conf.main_lna_conf == ATH_ANT_DIV_COMB_LNA2)
1089 antcomb->rssi_lna2 = main_rssi_avg;
1090 else if (ant_conf.main_lna_conf == ATH_ANT_DIV_COMB_LNA1)
1091 antcomb->rssi_lna1 = main_rssi_avg;
1092
1093 switch ((ant_conf.main_lna_conf << 4) | ant_conf.alt_lna_conf) {
1094 case (0x10): /* LNA2 A-B */
1095 antcomb->main_conf = ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1096 antcomb->first_quick_scan_conf =
1097 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1098 antcomb->second_quick_scan_conf = ATH_ANT_DIV_COMB_LNA1;
1099 break;
1100 case (0x20): /* LNA1 A-B */
1101 antcomb->main_conf = ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1102 antcomb->first_quick_scan_conf =
1103 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1104 antcomb->second_quick_scan_conf = ATH_ANT_DIV_COMB_LNA2;
1105 break;
1106 case (0x21): /* LNA1 LNA2 */
1107 antcomb->main_conf = ATH_ANT_DIV_COMB_LNA2;
1108 antcomb->first_quick_scan_conf =
1109 ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1110 antcomb->second_quick_scan_conf =
1111 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1112 break;
1113 case (0x12): /* LNA2 LNA1 */
1114 antcomb->main_conf = ATH_ANT_DIV_COMB_LNA1;
1115 antcomb->first_quick_scan_conf =
1116 ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1117 antcomb->second_quick_scan_conf =
1118 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1119 break;
1120 case (0x13): /* LNA2 A+B */
1121 antcomb->main_conf = ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1122 antcomb->first_quick_scan_conf =
1123 ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1124 antcomb->second_quick_scan_conf = ATH_ANT_DIV_COMB_LNA1;
1125 break;
1126 case (0x23): /* LNA1 A+B */
1127 antcomb->main_conf = ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1128 antcomb->first_quick_scan_conf =
1129 ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1130 antcomb->second_quick_scan_conf = ATH_ANT_DIV_COMB_LNA2;
1131 break;
1132 default:
1133 break;
1134 }
1135}
1136
1137static void ath_select_ant_div_from_quick_scan(struct ath_ant_comb *antcomb,
1138 struct ath_hw_antcomb_conf *div_ant_conf,
1139 int main_rssi_avg, int alt_rssi_avg,
1140 int alt_ratio)
1141{
1142 /* alt_good */
1143 switch (antcomb->quick_scan_cnt) {
1144 case 0:
1145 /* set alt to main, and alt to first conf */
1146 div_ant_conf->main_lna_conf = antcomb->main_conf;
1147 div_ant_conf->alt_lna_conf = antcomb->first_quick_scan_conf;
1148 break;
1149 case 1:
1150 /* set alt to main, and alt to first conf */
1151 div_ant_conf->main_lna_conf = antcomb->main_conf;
1152 div_ant_conf->alt_lna_conf = antcomb->second_quick_scan_conf;
1153 antcomb->rssi_first = main_rssi_avg;
1154 antcomb->rssi_second = alt_rssi_avg;
1155
1156 if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA1) {
1157 /* main is LNA1 */
1158 if (ath_is_alt_ant_ratio_better(alt_ratio,
1159 ATH_ANT_DIV_COMB_LNA1_DELTA_HI,
1160 ATH_ANT_DIV_COMB_LNA1_DELTA_LOW,
1161 main_rssi_avg, alt_rssi_avg,
1162 antcomb->total_pkt_count))
1163 antcomb->first_ratio = true;
1164 else
1165 antcomb->first_ratio = false;
1166 } else if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA2) {
1167 if (ath_is_alt_ant_ratio_better(alt_ratio,
1168 ATH_ANT_DIV_COMB_LNA1_DELTA_MID,
1169 ATH_ANT_DIV_COMB_LNA1_DELTA_LOW,
1170 main_rssi_avg, alt_rssi_avg,
1171 antcomb->total_pkt_count))
1172 antcomb->first_ratio = true;
1173 else
1174 antcomb->first_ratio = false;
1175 } else {
1176 if ((((alt_ratio >= ATH_ANT_DIV_COMB_ALT_ANT_RATIO2) &&
1177 (alt_rssi_avg > main_rssi_avg +
1178 ATH_ANT_DIV_COMB_LNA1_DELTA_HI)) ||
1179 (alt_rssi_avg > main_rssi_avg)) &&
1180 (antcomb->total_pkt_count > 50))
1181 antcomb->first_ratio = true;
1182 else
1183 antcomb->first_ratio = false;
1184 }
1185 break;
1186 case 2:
1187 antcomb->alt_good = false;
1188 antcomb->scan_not_start = false;
1189 antcomb->scan = false;
1190 antcomb->rssi_first = main_rssi_avg;
1191 antcomb->rssi_third = alt_rssi_avg;
1192
1193 if (antcomb->second_quick_scan_conf == ATH_ANT_DIV_COMB_LNA1)
1194 antcomb->rssi_lna1 = alt_rssi_avg;
1195 else if (antcomb->second_quick_scan_conf ==
1196 ATH_ANT_DIV_COMB_LNA2)
1197 antcomb->rssi_lna2 = alt_rssi_avg;
1198 else if (antcomb->second_quick_scan_conf ==
1199 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2) {
1200 if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA2)
1201 antcomb->rssi_lna2 = main_rssi_avg;
1202 else if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA1)
1203 antcomb->rssi_lna1 = main_rssi_avg;
1204 }
1205
1206 if (antcomb->rssi_lna2 > antcomb->rssi_lna1 +
1207 ATH_ANT_DIV_COMB_LNA1_LNA2_SWITCH_DELTA)
1208 div_ant_conf->main_lna_conf = ATH_ANT_DIV_COMB_LNA2;
1209 else
1210 div_ant_conf->main_lna_conf = ATH_ANT_DIV_COMB_LNA1;
1211
1212 if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA1) {
1213 if (ath_is_alt_ant_ratio_better(alt_ratio,
1214 ATH_ANT_DIV_COMB_LNA1_DELTA_HI,
1215 ATH_ANT_DIV_COMB_LNA1_DELTA_LOW,
1216 main_rssi_avg, alt_rssi_avg,
1217 antcomb->total_pkt_count))
1218 antcomb->second_ratio = true;
1219 else
1220 antcomb->second_ratio = false;
1221 } else if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA2) {
1222 if (ath_is_alt_ant_ratio_better(alt_ratio,
1223 ATH_ANT_DIV_COMB_LNA1_DELTA_MID,
1224 ATH_ANT_DIV_COMB_LNA1_DELTA_LOW,
1225 main_rssi_avg, alt_rssi_avg,
1226 antcomb->total_pkt_count))
1227 antcomb->second_ratio = true;
1228 else
1229 antcomb->second_ratio = false;
1230 } else {
1231 if ((((alt_ratio >= ATH_ANT_DIV_COMB_ALT_ANT_RATIO2) &&
1232 (alt_rssi_avg > main_rssi_avg +
1233 ATH_ANT_DIV_COMB_LNA1_DELTA_HI)) ||
1234 (alt_rssi_avg > main_rssi_avg)) &&
1235 (antcomb->total_pkt_count > 50))
1236 antcomb->second_ratio = true;
1237 else
1238 antcomb->second_ratio = false;
1239 }
1240
1241 /* set alt to the conf with maximun ratio */
1242 if (antcomb->first_ratio && antcomb->second_ratio) {
1243 if (antcomb->rssi_second > antcomb->rssi_third) {
1244 /* first alt*/
1245 if ((antcomb->first_quick_scan_conf ==
1246 ATH_ANT_DIV_COMB_LNA1) ||
1247 (antcomb->first_quick_scan_conf ==
1248 ATH_ANT_DIV_COMB_LNA2))
1249 /* Set alt LNA1 or LNA2*/
1250 if (div_ant_conf->main_lna_conf ==
1251 ATH_ANT_DIV_COMB_LNA2)
1252 div_ant_conf->alt_lna_conf =
1253 ATH_ANT_DIV_COMB_LNA1;
1254 else
1255 div_ant_conf->alt_lna_conf =
1256 ATH_ANT_DIV_COMB_LNA2;
1257 else
1258 /* Set alt to A+B or A-B */
1259 div_ant_conf->alt_lna_conf =
1260 antcomb->first_quick_scan_conf;
1261 } else if ((antcomb->second_quick_scan_conf ==
1262 ATH_ANT_DIV_COMB_LNA1) ||
1263 (antcomb->second_quick_scan_conf ==
1264 ATH_ANT_DIV_COMB_LNA2)) {
1265 /* Set alt LNA1 or LNA2 */
1266 if (div_ant_conf->main_lna_conf ==
1267 ATH_ANT_DIV_COMB_LNA2)
1268 div_ant_conf->alt_lna_conf =
1269 ATH_ANT_DIV_COMB_LNA1;
1270 else
1271 div_ant_conf->alt_lna_conf =
1272 ATH_ANT_DIV_COMB_LNA2;
1273 } else {
1274 /* Set alt to A+B or A-B */
1275 div_ant_conf->alt_lna_conf =
1276 antcomb->second_quick_scan_conf;
1277 }
1278 } else if (antcomb->first_ratio) {
1279 /* first alt */
1280 if ((antcomb->first_quick_scan_conf ==
1281 ATH_ANT_DIV_COMB_LNA1) ||
1282 (antcomb->first_quick_scan_conf ==
1283 ATH_ANT_DIV_COMB_LNA2))
1284 /* Set alt LNA1 or LNA2 */
1285 if (div_ant_conf->main_lna_conf ==
1286 ATH_ANT_DIV_COMB_LNA2)
1287 div_ant_conf->alt_lna_conf =
1288 ATH_ANT_DIV_COMB_LNA1;
1289 else
1290 div_ant_conf->alt_lna_conf =
1291 ATH_ANT_DIV_COMB_LNA2;
1292 else
1293 /* Set alt to A+B or A-B */
1294 div_ant_conf->alt_lna_conf =
1295 antcomb->first_quick_scan_conf;
1296 } else if (antcomb->second_ratio) {
1297 /* second alt */
1298 if ((antcomb->second_quick_scan_conf ==
1299 ATH_ANT_DIV_COMB_LNA1) ||
1300 (antcomb->second_quick_scan_conf ==
1301 ATH_ANT_DIV_COMB_LNA2))
1302 /* Set alt LNA1 or LNA2 */
1303 if (div_ant_conf->main_lna_conf ==
1304 ATH_ANT_DIV_COMB_LNA2)
1305 div_ant_conf->alt_lna_conf =
1306 ATH_ANT_DIV_COMB_LNA1;
1307 else
1308 div_ant_conf->alt_lna_conf =
1309 ATH_ANT_DIV_COMB_LNA2;
1310 else
1311 /* Set alt to A+B or A-B */
1312 div_ant_conf->alt_lna_conf =
1313 antcomb->second_quick_scan_conf;
1314 } else {
1315 /* main is largest */
1316 if ((antcomb->main_conf == ATH_ANT_DIV_COMB_LNA1) ||
1317 (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA2))
1318 /* Set alt LNA1 or LNA2 */
1319 if (div_ant_conf->main_lna_conf ==
1320 ATH_ANT_DIV_COMB_LNA2)
1321 div_ant_conf->alt_lna_conf =
1322 ATH_ANT_DIV_COMB_LNA1;
1323 else
1324 div_ant_conf->alt_lna_conf =
1325 ATH_ANT_DIV_COMB_LNA2;
1326 else
1327 /* Set alt to A+B or A-B */
1328 div_ant_conf->alt_lna_conf = antcomb->main_conf;
1329 }
1330 break;
1331 default:
1332 break;
1333 }
1334}
1335
John W. Linville9bad82b2010-09-15 15:26:13 -04001336static void ath_ant_div_conf_fast_divbias(struct ath_hw_antcomb_conf *ant_conf)
Vasanthakumar Thiagarajan102885a2010-09-02 01:34:43 -07001337{
1338 /* Adjust the fast_div_bias based on main and alt lna conf */
1339 switch ((ant_conf->main_lna_conf << 4) | ant_conf->alt_lna_conf) {
1340 case (0x01): /* A-B LNA2 */
1341 ant_conf->fast_div_bias = 0x3b;
1342 break;
1343 case (0x02): /* A-B LNA1 */
1344 ant_conf->fast_div_bias = 0x3d;
1345 break;
1346 case (0x03): /* A-B A+B */
1347 ant_conf->fast_div_bias = 0x1;
1348 break;
1349 case (0x10): /* LNA2 A-B */
1350 ant_conf->fast_div_bias = 0x7;
1351 break;
1352 case (0x12): /* LNA2 LNA1 */
1353 ant_conf->fast_div_bias = 0x2;
1354 break;
1355 case (0x13): /* LNA2 A+B */
1356 ant_conf->fast_div_bias = 0x7;
1357 break;
1358 case (0x20): /* LNA1 A-B */
1359 ant_conf->fast_div_bias = 0x6;
1360 break;
1361 case (0x21): /* LNA1 LNA2 */
1362 ant_conf->fast_div_bias = 0x0;
1363 break;
1364 case (0x23): /* LNA1 A+B */
1365 ant_conf->fast_div_bias = 0x6;
1366 break;
1367 case (0x30): /* A+B A-B */
1368 ant_conf->fast_div_bias = 0x1;
1369 break;
1370 case (0x31): /* A+B LNA2 */
1371 ant_conf->fast_div_bias = 0x3b;
1372 break;
1373 case (0x32): /* A+B LNA1 */
1374 ant_conf->fast_div_bias = 0x3d;
1375 break;
1376 default:
1377 break;
1378 }
1379}
1380
1381/* Antenna diversity and combining */
1382static void ath_ant_comb_scan(struct ath_softc *sc, struct ath_rx_status *rs)
1383{
1384 struct ath_hw_antcomb_conf div_ant_conf;
1385 struct ath_ant_comb *antcomb = &sc->ant_comb;
1386 int alt_ratio = 0, alt_rssi_avg = 0, main_rssi_avg = 0, curr_alt_set;
1387 int curr_main_set, curr_bias;
1388 int main_rssi = rs->rs_rssi_ctl0;
1389 int alt_rssi = rs->rs_rssi_ctl1;
1390 int rx_ant_conf, main_ant_conf;
1391 bool short_scan = false;
1392
1393 rx_ant_conf = (rs->rs_rssi_ctl2 >> ATH_ANT_RX_CURRENT_SHIFT) &
1394 ATH_ANT_RX_MASK;
1395 main_ant_conf = (rs->rs_rssi_ctl2 >> ATH_ANT_RX_MAIN_SHIFT) &
1396 ATH_ANT_RX_MASK;
1397
1398 /* Record packet only when alt_rssi is positive */
1399 if (alt_rssi > 0) {
1400 antcomb->total_pkt_count++;
1401 antcomb->main_total_rssi += main_rssi;
1402 antcomb->alt_total_rssi += alt_rssi;
1403 if (main_ant_conf == rx_ant_conf)
1404 antcomb->main_recv_cnt++;
1405 else
1406 antcomb->alt_recv_cnt++;
1407 }
1408
1409 /* Short scan check */
1410 if (antcomb->scan && antcomb->alt_good) {
1411 if (time_after(jiffies, antcomb->scan_start_time +
1412 msecs_to_jiffies(ATH_ANT_DIV_COMB_SHORT_SCAN_INTR)))
1413 short_scan = true;
1414 else
1415 if (antcomb->total_pkt_count ==
1416 ATH_ANT_DIV_COMB_SHORT_SCAN_PKTCOUNT) {
1417 alt_ratio = ((antcomb->alt_recv_cnt * 100) /
1418 antcomb->total_pkt_count);
1419 if (alt_ratio < ATH_ANT_DIV_COMB_ALT_ANT_RATIO)
1420 short_scan = true;
1421 }
1422 }
1423
1424 if (((antcomb->total_pkt_count < ATH_ANT_DIV_COMB_MAX_PKTCOUNT) ||
1425 rs->rs_moreaggr) && !short_scan)
1426 return;
1427
1428 if (antcomb->total_pkt_count) {
1429 alt_ratio = ((antcomb->alt_recv_cnt * 100) /
1430 antcomb->total_pkt_count);
1431 main_rssi_avg = (antcomb->main_total_rssi /
1432 antcomb->total_pkt_count);
1433 alt_rssi_avg = (antcomb->alt_total_rssi /
1434 antcomb->total_pkt_count);
1435 }
1436
1437
1438 ath9k_hw_antdiv_comb_conf_get(sc->sc_ah, &div_ant_conf);
1439 curr_alt_set = div_ant_conf.alt_lna_conf;
1440 curr_main_set = div_ant_conf.main_lna_conf;
1441 curr_bias = div_ant_conf.fast_div_bias;
1442
1443 antcomb->count++;
1444
1445 if (antcomb->count == ATH_ANT_DIV_COMB_MAX_COUNT) {
1446 if (alt_ratio > ATH_ANT_DIV_COMB_ALT_ANT_RATIO) {
1447 ath_lnaconf_alt_good_scan(antcomb, div_ant_conf,
1448 main_rssi_avg);
1449 antcomb->alt_good = true;
1450 } else {
1451 antcomb->alt_good = false;
1452 }
1453
1454 antcomb->count = 0;
1455 antcomb->scan = true;
1456 antcomb->scan_not_start = true;
1457 }
1458
1459 if (!antcomb->scan) {
1460 if (alt_ratio > ATH_ANT_DIV_COMB_ALT_ANT_RATIO) {
1461 if (curr_alt_set == ATH_ANT_DIV_COMB_LNA2) {
1462 /* Switch main and alt LNA */
1463 div_ant_conf.main_lna_conf =
1464 ATH_ANT_DIV_COMB_LNA2;
1465 div_ant_conf.alt_lna_conf =
1466 ATH_ANT_DIV_COMB_LNA1;
1467 } else if (curr_alt_set == ATH_ANT_DIV_COMB_LNA1) {
1468 div_ant_conf.main_lna_conf =
1469 ATH_ANT_DIV_COMB_LNA1;
1470 div_ant_conf.alt_lna_conf =
1471 ATH_ANT_DIV_COMB_LNA2;
1472 }
1473
1474 goto div_comb_done;
1475 } else if ((curr_alt_set != ATH_ANT_DIV_COMB_LNA1) &&
1476 (curr_alt_set != ATH_ANT_DIV_COMB_LNA2)) {
1477 /* Set alt to another LNA */
1478 if (curr_main_set == ATH_ANT_DIV_COMB_LNA2)
1479 div_ant_conf.alt_lna_conf =
1480 ATH_ANT_DIV_COMB_LNA1;
1481 else if (curr_main_set == ATH_ANT_DIV_COMB_LNA1)
1482 div_ant_conf.alt_lna_conf =
1483 ATH_ANT_DIV_COMB_LNA2;
1484
1485 goto div_comb_done;
1486 }
1487
1488 if ((alt_rssi_avg < (main_rssi_avg +
1489 ATH_ANT_DIV_COMB_LNA1_LNA2_DELTA)))
1490 goto div_comb_done;
1491 }
1492
1493 if (!antcomb->scan_not_start) {
1494 switch (curr_alt_set) {
1495 case ATH_ANT_DIV_COMB_LNA2:
1496 antcomb->rssi_lna2 = alt_rssi_avg;
1497 antcomb->rssi_lna1 = main_rssi_avg;
1498 antcomb->scan = true;
1499 /* set to A+B */
1500 div_ant_conf.main_lna_conf =
1501 ATH_ANT_DIV_COMB_LNA1;
1502 div_ant_conf.alt_lna_conf =
1503 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1504 break;
1505 case ATH_ANT_DIV_COMB_LNA1:
1506 antcomb->rssi_lna1 = alt_rssi_avg;
1507 antcomb->rssi_lna2 = main_rssi_avg;
1508 antcomb->scan = true;
1509 /* set to A+B */
1510 div_ant_conf.main_lna_conf = ATH_ANT_DIV_COMB_LNA2;
1511 div_ant_conf.alt_lna_conf =
1512 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1513 break;
1514 case ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2:
1515 antcomb->rssi_add = alt_rssi_avg;
1516 antcomb->scan = true;
1517 /* set to A-B */
1518 div_ant_conf.alt_lna_conf =
1519 ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1520 break;
1521 case ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2:
1522 antcomb->rssi_sub = alt_rssi_avg;
1523 antcomb->scan = false;
1524 if (antcomb->rssi_lna2 >
1525 (antcomb->rssi_lna1 +
1526 ATH_ANT_DIV_COMB_LNA1_LNA2_SWITCH_DELTA)) {
1527 /* use LNA2 as main LNA */
1528 if ((antcomb->rssi_add > antcomb->rssi_lna1) &&
1529 (antcomb->rssi_add > antcomb->rssi_sub)) {
1530 /* set to A+B */
1531 div_ant_conf.main_lna_conf =
1532 ATH_ANT_DIV_COMB_LNA2;
1533 div_ant_conf.alt_lna_conf =
1534 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1535 } else if (antcomb->rssi_sub >
1536 antcomb->rssi_lna1) {
1537 /* set to A-B */
1538 div_ant_conf.main_lna_conf =
1539 ATH_ANT_DIV_COMB_LNA2;
1540 div_ant_conf.alt_lna_conf =
1541 ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1542 } else {
1543 /* set to LNA1 */
1544 div_ant_conf.main_lna_conf =
1545 ATH_ANT_DIV_COMB_LNA2;
1546 div_ant_conf.alt_lna_conf =
1547 ATH_ANT_DIV_COMB_LNA1;
1548 }
1549 } else {
1550 /* use LNA1 as main LNA */
1551 if ((antcomb->rssi_add > antcomb->rssi_lna2) &&
1552 (antcomb->rssi_add > antcomb->rssi_sub)) {
1553 /* set to A+B */
1554 div_ant_conf.main_lna_conf =
1555 ATH_ANT_DIV_COMB_LNA1;
1556 div_ant_conf.alt_lna_conf =
1557 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1558 } else if (antcomb->rssi_sub >
1559 antcomb->rssi_lna1) {
1560 /* set to A-B */
1561 div_ant_conf.main_lna_conf =
1562 ATH_ANT_DIV_COMB_LNA1;
1563 div_ant_conf.alt_lna_conf =
1564 ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1565 } else {
1566 /* set to LNA2 */
1567 div_ant_conf.main_lna_conf =
1568 ATH_ANT_DIV_COMB_LNA1;
1569 div_ant_conf.alt_lna_conf =
1570 ATH_ANT_DIV_COMB_LNA2;
1571 }
1572 }
1573 break;
1574 default:
1575 break;
1576 }
1577 } else {
1578 if (!antcomb->alt_good) {
1579 antcomb->scan_not_start = false;
1580 /* Set alt to another LNA */
1581 if (curr_main_set == ATH_ANT_DIV_COMB_LNA2) {
1582 div_ant_conf.main_lna_conf =
1583 ATH_ANT_DIV_COMB_LNA2;
1584 div_ant_conf.alt_lna_conf =
1585 ATH_ANT_DIV_COMB_LNA1;
1586 } else if (curr_main_set == ATH_ANT_DIV_COMB_LNA1) {
1587 div_ant_conf.main_lna_conf =
1588 ATH_ANT_DIV_COMB_LNA1;
1589 div_ant_conf.alt_lna_conf =
1590 ATH_ANT_DIV_COMB_LNA2;
1591 }
1592 goto div_comb_done;
1593 }
1594 }
1595
1596 ath_select_ant_div_from_quick_scan(antcomb, &div_ant_conf,
1597 main_rssi_avg, alt_rssi_avg,
1598 alt_ratio);
1599
1600 antcomb->quick_scan_cnt++;
1601
1602div_comb_done:
1603 ath_ant_div_conf_fast_divbias(&div_ant_conf);
1604
1605 ath9k_hw_antdiv_comb_conf_set(sc->sc_ah, &div_ant_conf);
1606
1607 antcomb->scan_start_time = jiffies;
1608 antcomb->total_pkt_count = 0;
1609 antcomb->main_total_rssi = 0;
1610 antcomb->alt_total_rssi = 0;
1611 antcomb->main_recv_cnt = 0;
1612 antcomb->alt_recv_cnt = 0;
1613}
1614
Felix Fietkaub5c804752010-04-15 17:38:48 -04001615int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp)
1616{
1617 struct ath_buf *bf;
Luis R. Rodriguezcb71d9b2008-11-21 17:41:33 -08001618 struct sk_buff *skb = NULL, *requeue_skb;
Luis R. Rodriguez5ca42622009-11-04 08:20:42 -08001619 struct ieee80211_rx_status *rxs;
Sujithcbe61d82009-02-09 13:27:12 +05301620 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez27c51f12009-09-10 11:08:14 -07001621 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezb4afffc2009-11-02 11:36:08 -08001622 /*
Mohammed Shafi Shajakhancae6b742010-12-07 21:23:16 +05301623 * The hw can technically differ from common->hw when using ath9k
Luis R. Rodriguezb4afffc2009-11-02 11:36:08 -08001624 * virtual wiphy so to account for that we iterate over the active
1625 * wiphys and find the appropriate wiphy and therefore hw.
1626 */
1627 struct ieee80211_hw *hw = NULL;
Sujithbe0418a2008-11-18 09:05:55 +05301628 struct ieee80211_hdr *hdr;
Luis R. Rodriguezc9b14172009-11-04 16:47:22 -08001629 int retval;
Sujithbe0418a2008-11-18 09:05:55 +05301630 bool decrypt_error = false;
Felix Fietkau29bffa92010-03-29 20:14:23 -07001631 struct ath_rx_status rs;
Felix Fietkaub5c804752010-04-15 17:38:48 -04001632 enum ath9k_rx_qtype qtype;
1633 bool edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA);
1634 int dma_type;
Vasanthakumar Thiagarajan5c6dd922010-05-20 14:34:47 -07001635 u8 rx_status_len = ah->caps.rx_status_len;
Felix Fietkaua6d20552010-06-12 00:33:54 -04001636 u64 tsf = 0;
1637 u32 tsf_lower = 0;
Luis R. Rodriguez8ab2cd02010-09-16 15:12:26 -04001638 unsigned long flags;
Sujithbe0418a2008-11-18 09:05:55 +05301639
Felix Fietkaub5c804752010-04-15 17:38:48 -04001640 if (edma)
Felix Fietkaub5c804752010-04-15 17:38:48 -04001641 dma_type = DMA_BIDIRECTIONAL;
Ming Lei56824222010-05-14 21:15:38 +08001642 else
1643 dma_type = DMA_FROM_DEVICE;
Felix Fietkaub5c804752010-04-15 17:38:48 -04001644
1645 qtype = hp ? ATH9K_RX_QUEUE_HP : ATH9K_RX_QUEUE_LP;
Sujithb77f4832008-12-07 21:44:03 +05301646 spin_lock_bh(&sc->rx.rxbuflock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001647
Felix Fietkaua6d20552010-06-12 00:33:54 -04001648 tsf = ath9k_hw_gettsf64(ah);
1649 tsf_lower = tsf & 0xffffffff;
1650
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001651 do {
1652 /* If handling rx interrupt and flush is in progress => exit */
Sujith98deeea2008-08-11 14:05:46 +05301653 if ((sc->sc_flags & SC_OP_RXFLUSH) && (flush == 0))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001654 break;
1655
Felix Fietkau29bffa92010-03-29 20:14:23 -07001656 memset(&rs, 0, sizeof(rs));
Felix Fietkaub5c804752010-04-15 17:38:48 -04001657 if (edma)
1658 bf = ath_edma_get_next_rx_buf(sc, &rs, qtype);
1659 else
1660 bf = ath_get_next_rx_buf(sc, &rs);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001661
Felix Fietkaub5c804752010-04-15 17:38:48 -04001662 if (!bf)
1663 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001664
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001665 skb = bf->bf_mpdu;
Sujithbe0418a2008-11-18 09:05:55 +05301666 if (!skb)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001667 continue;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001668
Vasanthakumar Thiagarajan5c6dd922010-05-20 14:34:47 -07001669 hdr = (struct ieee80211_hdr *) (skb->data + rx_status_len);
Luis R. Rodriguez5ca42622009-11-04 08:20:42 -08001670 rxs = IEEE80211_SKB_RXCB(skb);
1671
Luis R. Rodriguezb4afffc2009-11-02 11:36:08 -08001672 hw = ath_get_virt_hw(sc, hdr);
1673
Felix Fietkau29bffa92010-03-29 20:14:23 -07001674 ath_debug_stat_rx(sc, &rs);
Sujith1395d3f2010-01-08 10:36:11 +05301675
Vasanthakumar Thiagarajan9bf9fca2008-12-15 20:40:46 +05301676 /*
Sujithbe0418a2008-11-18 09:05:55 +05301677 * If we're asked to flush receive queue, directly
1678 * chain it back at the queue without processing it.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001679 */
Sujithbe0418a2008-11-18 09:05:55 +05301680 if (flush)
Luis R. Rodriguezcb71d9b2008-11-21 17:41:33 -08001681 goto requeue;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001682
Jan Friedrichc8f3b722010-08-02 23:55:50 +02001683 retval = ath9k_rx_skb_preprocess(common, hw, hdr, &rs,
1684 rxs, &decrypt_error);
1685 if (retval)
1686 goto requeue;
1687
Felix Fietkaua6d20552010-06-12 00:33:54 -04001688 rxs->mactime = (tsf & ~0xffffffffULL) | rs.rs_tstamp;
1689 if (rs.rs_tstamp > tsf_lower &&
1690 unlikely(rs.rs_tstamp - tsf_lower > 0x10000000))
1691 rxs->mactime -= 0x100000000ULL;
1692
1693 if (rs.rs_tstamp < tsf_lower &&
1694 unlikely(tsf_lower - rs.rs_tstamp > 0x10000000))
1695 rxs->mactime += 0x100000000ULL;
1696
Luis R. Rodriguezcb71d9b2008-11-21 17:41:33 -08001697 /* Ensure we always have an skb to requeue once we are done
1698 * processing the current buffer's skb */
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -08001699 requeue_skb = ath_rxbuf_alloc(common, common->rx_bufsize, GFP_ATOMIC);
Luis R. Rodriguezcb71d9b2008-11-21 17:41:33 -08001700
1701 /* If there is no memory we ignore the current RX'd frame,
1702 * tell hardware it can give us a new frame using the old
Sujithb77f4832008-12-07 21:44:03 +05301703 * skb and put it at the tail of the sc->rx.rxbuf list for
Luis R. Rodriguezcb71d9b2008-11-21 17:41:33 -08001704 * processing. */
1705 if (!requeue_skb)
1706 goto requeue;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001707
Vasanthakumar Thiagarajan9bf9fca2008-12-15 20:40:46 +05301708 /* Unmap the frame */
Gabor Juhos7da3c552009-01-14 20:17:03 +01001709 dma_unmap_single(sc->dev, bf->bf_buf_addr,
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -08001710 common->rx_bufsize,
Felix Fietkaub5c804752010-04-15 17:38:48 -04001711 dma_type);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001712
Felix Fietkaub5c804752010-04-15 17:38:48 -04001713 skb_put(skb, rs.rs_datalen + ah->caps.rx_status_len);
1714 if (ah->caps.rx_status_len)
1715 skb_pull(skb, ah->caps.rx_status_len);
Sujithbe0418a2008-11-18 09:05:55 +05301716
Sujithd4357002010-05-20 15:34:38 +05301717 ath9k_rx_skb_postprocess(common, skb, &rs,
1718 rxs, decrypt_error);
Sujithbe0418a2008-11-18 09:05:55 +05301719
Luis R. Rodriguezcb71d9b2008-11-21 17:41:33 -08001720 /* We will now give hardware our shiny new allocated skb */
1721 bf->bf_mpdu = requeue_skb;
Gabor Juhos7da3c552009-01-14 20:17:03 +01001722 bf->bf_buf_addr = dma_map_single(sc->dev, requeue_skb->data,
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -08001723 common->rx_bufsize,
Felix Fietkaub5c804752010-04-15 17:38:48 -04001724 dma_type);
Gabor Juhos7da3c552009-01-14 20:17:03 +01001725 if (unlikely(dma_mapping_error(sc->dev,
Luis R. Rodriguezf8316df2008-12-03 03:35:29 -08001726 bf->bf_buf_addr))) {
1727 dev_kfree_skb_any(requeue_skb);
1728 bf->bf_mpdu = NULL;
Ben Greear6cf9e992010-10-14 12:45:30 -07001729 bf->bf_buf_addr = 0;
Joe Perches38002762010-12-02 19:12:36 -08001730 ath_err(common, "dma_mapping_error() on RX\n");
Mohammed Shafi Shajakhancae6b742010-12-07 21:23:16 +05301731 ath_rx_send_to_mac80211(hw, sc, skb);
Luis R. Rodriguezf8316df2008-12-03 03:35:29 -08001732 break;
1733 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001734
1735 /*
1736 * change the default rx antenna if rx diversity chooses the
1737 * other antenna 3 times in a row.
1738 */
Felix Fietkau29bffa92010-03-29 20:14:23 -07001739 if (sc->rx.defant != rs.rs_antenna) {
Sujithb77f4832008-12-07 21:44:03 +05301740 if (++sc->rx.rxotherant >= 3)
Felix Fietkau29bffa92010-03-29 20:14:23 -07001741 ath_setdefantenna(sc, rs.rs_antenna);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001742 } else {
Sujithb77f4832008-12-07 21:44:03 +05301743 sc->rx.rxotherant = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001744 }
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301745
Luis R. Rodriguez8ab2cd02010-09-16 15:12:26 -04001746 spin_lock_irqsave(&sc->sc_pm_lock, flags);
Mohammed Shafi Shajakhanaaef24b2010-12-07 20:40:58 +05301747
1748 if ((sc->ps_flags & (PS_WAIT_FOR_BEACON |
Vasanthakumar Thiagarajanededf1f2010-05-22 23:58:13 -07001749 PS_WAIT_FOR_CAB |
Mohammed Shafi Shajakhanaaef24b2010-12-07 20:40:58 +05301750 PS_WAIT_FOR_PSPOLL_DATA)) ||
1751 unlikely(ath9k_check_auto_sleep(sc)))
Jouni Malinencc659652009-05-14 21:28:48 +03001752 ath_rx_ps(sc, skb);
Luis R. Rodriguez8ab2cd02010-09-16 15:12:26 -04001753 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
Jouni Malinencc659652009-05-14 21:28:48 +03001754
Vasanthakumar Thiagarajan102885a2010-09-02 01:34:43 -07001755 if (ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)
1756 ath_ant_comb_scan(sc, &rs);
1757
Mohammed Shafi Shajakhancae6b742010-12-07 21:23:16 +05301758 ath_rx_send_to_mac80211(hw, sc, skb);
Jouni Malinencc659652009-05-14 21:28:48 +03001759
Luis R. Rodriguezcb71d9b2008-11-21 17:41:33 -08001760requeue:
Felix Fietkaub5c804752010-04-15 17:38:48 -04001761 if (edma) {
1762 list_add_tail(&bf->list, &sc->rx.rxbuf);
1763 ath_rx_edma_buf_link(sc, qtype);
1764 } else {
1765 list_move_tail(&bf->list, &sc->rx.rxbuf);
1766 ath_rx_buf_link(sc, bf);
1767 }
Sujithbe0418a2008-11-18 09:05:55 +05301768 } while (1);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001769
Sujithb77f4832008-12-07 21:44:03 +05301770 spin_unlock_bh(&sc->rx.rxbuflock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001771
1772 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001773}