blob: a485c040bf80de06174fbc003efe061f80226f86 [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
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070037/*
38 * Setup and link descriptors.
39 *
40 * 11N: we can no longer afford to self link the last descriptor.
41 * MAC acknowledges BA status as long as it copies frames to host
42 * buffer (or rx fifo). This can incorrectly acknowledge packets
43 * to a sender if last desc is self-linked.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070044 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070045static void ath_rx_buf_link(struct ath_softc *sc, struct ath_buf *bf)
46{
Sujithcbe61d82009-02-09 13:27:12 +053047 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -080048 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070049 struct ath_desc *ds;
50 struct sk_buff *skb;
51
52 ATH_RXBUF_RESET(bf);
53
54 ds = bf->bf_desc;
Sujithbe0418a2008-11-18 09:05:55 +053055 ds->ds_link = 0; /* link to null */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070056 ds->ds_data = bf->bf_buf_addr;
57
Sujithbe0418a2008-11-18 09:05:55 +053058 /* virtual addr of the beginning of the buffer. */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070059 skb = bf->bf_mpdu;
Luis R. Rodriguez9680e8a2009-09-13 23:28:00 -070060 BUG_ON(skb == NULL);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070061 ds->ds_vdata = skb->data;
62
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -080063 /*
64 * setup rx descriptors. The rx_bufsize here tells the hardware
Luis R. Rodriguezb4b6cda2008-11-20 17:15:13 -080065 * how much data it can DMA to us and that we are prepared
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -080066 * to process
67 */
Sujithb77f4832008-12-07 21:44:03 +053068 ath9k_hw_setuprxdesc(ah, ds,
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -080069 common->rx_bufsize,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070070 0);
71
Sujithb77f4832008-12-07 21:44:03 +053072 if (sc->rx.rxlink == NULL)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070073 ath9k_hw_putrxbuf(ah, bf->bf_daddr);
74 else
Sujithb77f4832008-12-07 21:44:03 +053075 *sc->rx.rxlink = bf->bf_daddr;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070076
Sujithb77f4832008-12-07 21:44:03 +053077 sc->rx.rxlink = &ds->ds_link;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070078}
79
Sujithff37e332008-11-24 12:07:55 +053080static void ath_setdefantenna(struct ath_softc *sc, u32 antenna)
81{
82 /* XXX block beacon interrupts */
83 ath9k_hw_setantenna(sc->sc_ah, antenna);
Sujithb77f4832008-12-07 21:44:03 +053084 sc->rx.defant = antenna;
85 sc->rx.rxotherant = 0;
Sujithff37e332008-11-24 12:07:55 +053086}
87
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070088static void ath_opmode_init(struct ath_softc *sc)
89{
Sujithcbe61d82009-02-09 13:27:12 +053090 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez15107182009-09-10 09:22:37 -070091 struct ath_common *common = ath9k_hw_common(ah);
92
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070093 u32 rfilt, mfilt[2];
94
95 /* configure rx filter */
96 rfilt = ath_calcrxfilter(sc);
97 ath9k_hw_setrxfilter(ah, rfilt);
98
99 /* configure bssid mask */
Felix Fietkau364734f2010-09-14 20:22:44 +0200100 ath_hw_setbssidmask(common);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700101
102 /* configure operational mode */
103 ath9k_hw_setopmode(ah);
104
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700105 /* calculate and install multicast filter */
106 mfilt[0] = mfilt[1] = ~0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700107 ath9k_hw_setmcastfilter(ah, mfilt[0], mfilt[1]);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700108}
109
Felix Fietkaub5c804752010-04-15 17:38:48 -0400110static bool ath_rx_edma_buf_link(struct ath_softc *sc,
111 enum ath9k_rx_qtype qtype)
112{
113 struct ath_hw *ah = sc->sc_ah;
114 struct ath_rx_edma *rx_edma;
115 struct sk_buff *skb;
116 struct ath_buf *bf;
117
118 rx_edma = &sc->rx.rx_edma[qtype];
119 if (skb_queue_len(&rx_edma->rx_fifo) >= rx_edma->rx_fifo_hwsize)
120 return false;
121
122 bf = list_first_entry(&sc->rx.rxbuf, struct ath_buf, list);
123 list_del_init(&bf->list);
124
125 skb = bf->bf_mpdu;
126
127 ATH_RXBUF_RESET(bf);
128 memset(skb->data, 0, ah->caps.rx_status_len);
129 dma_sync_single_for_device(sc->dev, bf->bf_buf_addr,
130 ah->caps.rx_status_len, DMA_TO_DEVICE);
131
132 SKB_CB_ATHBUF(skb) = bf;
133 ath9k_hw_addrxbuf_edma(ah, bf->bf_buf_addr, qtype);
134 skb_queue_tail(&rx_edma->rx_fifo, skb);
135
136 return true;
137}
138
139static void ath_rx_addbuffer_edma(struct ath_softc *sc,
140 enum ath9k_rx_qtype qtype, int size)
141{
Felix Fietkaub5c804752010-04-15 17:38:48 -0400142 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
143 u32 nbuf = 0;
144
Felix Fietkaub5c804752010-04-15 17:38:48 -0400145 if (list_empty(&sc->rx.rxbuf)) {
Joe Perches226afe62010-12-02 19:12:37 -0800146 ath_dbg(common, ATH_DBG_QUEUE, "No free rx buf available\n");
Felix Fietkaub5c804752010-04-15 17:38:48 -0400147 return;
148 }
149
150 while (!list_empty(&sc->rx.rxbuf)) {
151 nbuf++;
152
153 if (!ath_rx_edma_buf_link(sc, qtype))
154 break;
155
156 if (nbuf >= size)
157 break;
158 }
159}
160
161static void ath_rx_remove_buffer(struct ath_softc *sc,
162 enum ath9k_rx_qtype qtype)
163{
164 struct ath_buf *bf;
165 struct ath_rx_edma *rx_edma;
166 struct sk_buff *skb;
167
168 rx_edma = &sc->rx.rx_edma[qtype];
169
170 while ((skb = skb_dequeue(&rx_edma->rx_fifo)) != NULL) {
171 bf = SKB_CB_ATHBUF(skb);
172 BUG_ON(!bf);
173 list_add_tail(&bf->list, &sc->rx.rxbuf);
174 }
175}
176
177static void ath_rx_edma_cleanup(struct ath_softc *sc)
178{
179 struct ath_buf *bf;
180
181 ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_LP);
182 ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_HP);
183
184 list_for_each_entry(bf, &sc->rx.rxbuf, list) {
185 if (bf->bf_mpdu)
186 dev_kfree_skb_any(bf->bf_mpdu);
187 }
188
189 INIT_LIST_HEAD(&sc->rx.rxbuf);
190
191 kfree(sc->rx.rx_bufptr);
192 sc->rx.rx_bufptr = NULL;
193}
194
195static void ath_rx_edma_init_queue(struct ath_rx_edma *rx_edma, int size)
196{
197 skb_queue_head_init(&rx_edma->rx_fifo);
198 skb_queue_head_init(&rx_edma->rx_buffers);
199 rx_edma->rx_fifo_hwsize = size;
200}
201
202static int ath_rx_edma_init(struct ath_softc *sc, int nbufs)
203{
204 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
205 struct ath_hw *ah = sc->sc_ah;
206 struct sk_buff *skb;
207 struct ath_buf *bf;
208 int error = 0, i;
209 u32 size;
210
Felix Fietkaub5c804752010-04-15 17:38:48 -0400211 ath9k_hw_set_rx_bufsize(ah, common->rx_bufsize -
212 ah->caps.rx_status_len);
213
214 ath_rx_edma_init_queue(&sc->rx.rx_edma[ATH9K_RX_QUEUE_LP],
215 ah->caps.rx_lp_qdepth);
216 ath_rx_edma_init_queue(&sc->rx.rx_edma[ATH9K_RX_QUEUE_HP],
217 ah->caps.rx_hp_qdepth);
218
219 size = sizeof(struct ath_buf) * nbufs;
220 bf = kzalloc(size, GFP_KERNEL);
221 if (!bf)
222 return -ENOMEM;
223
224 INIT_LIST_HEAD(&sc->rx.rxbuf);
225 sc->rx.rx_bufptr = bf;
226
227 for (i = 0; i < nbufs; i++, bf++) {
228 skb = ath_rxbuf_alloc(common, common->rx_bufsize, GFP_KERNEL);
229 if (!skb) {
230 error = -ENOMEM;
231 goto rx_init_fail;
232 }
233
234 memset(skb->data, 0, common->rx_bufsize);
235 bf->bf_mpdu = skb;
236
237 bf->bf_buf_addr = dma_map_single(sc->dev, skb->data,
238 common->rx_bufsize,
239 DMA_BIDIRECTIONAL);
240 if (unlikely(dma_mapping_error(sc->dev,
241 bf->bf_buf_addr))) {
242 dev_kfree_skb_any(skb);
243 bf->bf_mpdu = NULL;
Ben Greear6cf9e992010-10-14 12:45:30 -0700244 bf->bf_buf_addr = 0;
Joe Perches38002762010-12-02 19:12:36 -0800245 ath_err(common,
Felix Fietkaub5c804752010-04-15 17:38:48 -0400246 "dma_mapping_error() on RX init\n");
247 error = -ENOMEM;
248 goto rx_init_fail;
249 }
250
251 list_add_tail(&bf->list, &sc->rx.rxbuf);
252 }
253
254 return 0;
255
256rx_init_fail:
257 ath_rx_edma_cleanup(sc);
258 return error;
259}
260
261static void ath_edma_start_recv(struct ath_softc *sc)
262{
263 spin_lock_bh(&sc->rx.rxbuflock);
264
265 ath9k_hw_rxena(sc->sc_ah);
266
267 ath_rx_addbuffer_edma(sc, ATH9K_RX_QUEUE_HP,
268 sc->rx.rx_edma[ATH9K_RX_QUEUE_HP].rx_fifo_hwsize);
269
270 ath_rx_addbuffer_edma(sc, ATH9K_RX_QUEUE_LP,
271 sc->rx.rx_edma[ATH9K_RX_QUEUE_LP].rx_fifo_hwsize);
272
Felix Fietkaub5c804752010-04-15 17:38:48 -0400273 ath_opmode_init(sc);
274
Luis R. Rodriguez48a6a462010-09-16 15:12:28 -0400275 ath9k_hw_startpcureceive(sc->sc_ah, (sc->sc_flags & SC_OP_OFFCHANNEL));
Luis R. Rodriguez7583c5502010-10-20 16:07:04 -0700276
277 spin_unlock_bh(&sc->rx.rxbuflock);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400278}
279
280static void ath_edma_stop_recv(struct ath_softc *sc)
281{
Felix Fietkaub5c804752010-04-15 17:38:48 -0400282 ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_HP);
283 ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_LP);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400284}
285
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700286int ath_rx_init(struct ath_softc *sc, int nbufs)
287{
Luis R. Rodriguez27c51f12009-09-10 11:08:14 -0700288 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700289 struct sk_buff *skb;
290 struct ath_buf *bf;
291 int error = 0;
292
Luis R. Rodriguez4bdd1e92010-10-26 15:27:24 -0700293 spin_lock_init(&sc->sc_pcu_lock);
Sujith797fe5cb2009-03-30 15:28:45 +0530294 sc->sc_flags &= ~SC_OP_RXFLUSH;
295 spin_lock_init(&sc->rx.rxbuflock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700296
Felix Fietkau0d955212011-01-26 18:23:27 +0100297 common->rx_bufsize = IEEE80211_MAX_MPDU_LEN / 2 +
298 sc->sc_ah->caps.rx_status_len;
299
Felix Fietkaub5c804752010-04-15 17:38:48 -0400300 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
301 return ath_rx_edma_init(sc, nbufs);
302 } else {
Joe Perches226afe62010-12-02 19:12:37 -0800303 ath_dbg(common, ATH_DBG_CONFIG, "cachelsz %u rxbufsize %u\n",
304 common->cachelsz, common->rx_bufsize);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700305
Felix Fietkaub5c804752010-04-15 17:38:48 -0400306 /* Initialize rx descriptors */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700307
Felix Fietkaub5c804752010-04-15 17:38:48 -0400308 error = ath_descdma_setup(sc, &sc->rx.rxdma, &sc->rx.rxbuf,
Vasanthakumar Thiagarajan4adfcde2010-04-15 17:39:33 -0400309 "rx", nbufs, 1, 0);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400310 if (error != 0) {
Joe Perches38002762010-12-02 19:12:36 -0800311 ath_err(common,
312 "failed to allocate rx descriptors: %d\n",
313 error);
Sujith797fe5cb2009-03-30 15:28:45 +0530314 goto err;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700315 }
Felix Fietkaub5c804752010-04-15 17:38:48 -0400316
317 list_for_each_entry(bf, &sc->rx.rxbuf, list) {
318 skb = ath_rxbuf_alloc(common, common->rx_bufsize,
319 GFP_KERNEL);
320 if (skb == NULL) {
321 error = -ENOMEM;
322 goto err;
323 }
324
325 bf->bf_mpdu = skb;
326 bf->bf_buf_addr = dma_map_single(sc->dev, skb->data,
327 common->rx_bufsize,
328 DMA_FROM_DEVICE);
329 if (unlikely(dma_mapping_error(sc->dev,
330 bf->bf_buf_addr))) {
331 dev_kfree_skb_any(skb);
332 bf->bf_mpdu = NULL;
Ben Greear6cf9e992010-10-14 12:45:30 -0700333 bf->bf_buf_addr = 0;
Joe Perches38002762010-12-02 19:12:36 -0800334 ath_err(common,
335 "dma_mapping_error() on RX init\n");
Felix Fietkaub5c804752010-04-15 17:38:48 -0400336 error = -ENOMEM;
337 goto err;
338 }
Felix Fietkaub5c804752010-04-15 17:38:48 -0400339 }
340 sc->rx.rxlink = NULL;
Sujith797fe5cb2009-03-30 15:28:45 +0530341 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700342
Sujith797fe5cb2009-03-30 15:28:45 +0530343err:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700344 if (error)
345 ath_rx_cleanup(sc);
346
347 return error;
348}
349
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700350void ath_rx_cleanup(struct ath_softc *sc)
351{
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -0800352 struct ath_hw *ah = sc->sc_ah;
353 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700354 struct sk_buff *skb;
355 struct ath_buf *bf;
356
Felix Fietkaub5c804752010-04-15 17:38:48 -0400357 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
358 ath_rx_edma_cleanup(sc);
359 return;
360 } else {
361 list_for_each_entry(bf, &sc->rx.rxbuf, list) {
362 skb = bf->bf_mpdu;
363 if (skb) {
364 dma_unmap_single(sc->dev, bf->bf_buf_addr,
365 common->rx_bufsize,
366 DMA_FROM_DEVICE);
367 dev_kfree_skb(skb);
Ben Greear6cf9e992010-10-14 12:45:30 -0700368 bf->bf_buf_addr = 0;
369 bf->bf_mpdu = NULL;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400370 }
Luis R. Rodriguez051b9192009-03-23 18:25:01 -0400371 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700372
Felix Fietkaub5c804752010-04-15 17:38:48 -0400373 if (sc->rx.rxdma.dd_desc_len != 0)
374 ath_descdma_cleanup(sc, &sc->rx.rxdma, &sc->rx.rxbuf);
375 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700376}
377
378/*
379 * Calculate the receive filter according to the
380 * operating mode and state:
381 *
382 * o always accept unicast, broadcast, and multicast traffic
383 * o maintain current state of phy error reception (the hal
384 * may enable phy error frames for noise immunity work)
385 * o probe request frames are accepted only when operating in
386 * hostap, adhoc, or monitor modes
387 * o enable promiscuous mode according to the interface state
388 * o accept beacons:
389 * - when operating in adhoc mode so the 802.11 layer creates
390 * node table entries for peers,
391 * - when operating in station mode for collecting rssi data when
392 * the station is otherwise quiet, or
393 * - when operating as a repeater so we see repeater-sta beacons
394 * - when scanning
395 */
396
397u32 ath_calcrxfilter(struct ath_softc *sc)
398{
399#define RX_FILTER_PRESERVE (ATH9K_RX_FILTER_PHYERR | ATH9K_RX_FILTER_PHYRADAR)
Sujith7dcfdcd2008-08-11 14:03:13 +0530400
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700401 u32 rfilt;
402
403 rfilt = (ath9k_hw_getrxfilter(sc->sc_ah) & RX_FILTER_PRESERVE)
404 | ATH9K_RX_FILTER_UCAST | ATH9K_RX_FILTER_BCAST
405 | ATH9K_RX_FILTER_MCAST;
406
Jouni Malinen9c1d8e42010-10-13 17:29:31 +0300407 if (sc->rx.rxfilter & FIF_PROBE_REQ)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700408 rfilt |= ATH9K_RX_FILTER_PROBEREQ;
409
Jouni Malinen217ba9d2009-03-10 10:55:50 +0200410 /*
411 * Set promiscuous mode when FIF_PROMISC_IN_BSS is enabled for station
412 * mode interface or when in monitor mode. AP mode does not need this
413 * since it receives all in-BSS frames anyway.
414 */
Felix Fietkau2e286942011-03-09 01:48:12 +0100415 if (sc->sc_ah->is_monitoring)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700416 rfilt |= ATH9K_RX_FILTER_PROM;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700417
Sujithd42c6b72009-02-04 08:10:22 +0530418 if (sc->rx.rxfilter & FIF_CONTROL)
419 rfilt |= ATH9K_RX_FILTER_CONTROL;
420
Vasanthakumar Thiagarajandbaaa142009-02-19 15:41:52 +0530421 if ((sc->sc_ah->opmode == NL80211_IFTYPE_STATION) &&
Ben Greearcfda6692010-09-14 12:00:22 -0700422 (sc->nvifs <= 1) &&
Vasanthakumar Thiagarajandbaaa142009-02-19 15:41:52 +0530423 !(sc->rx.rxfilter & FIF_BCN_PRBRESP_PROMISC))
424 rfilt |= ATH9K_RX_FILTER_MYBEACON;
425 else
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700426 rfilt |= ATH9K_RX_FILTER_BEACON;
427
Felix Fietkau264bbec2011-04-07 19:24:23 +0200428 if ((sc->sc_ah->opmode == NL80211_IFTYPE_AP) ||
Senthil Balasubramanian66afad02009-09-18 15:06:07 +0530429 (sc->rx.rxfilter & FIF_PSPOLL))
Vasanthakumar Thiagarajandbaaa142009-02-19 15:41:52 +0530430 rfilt |= ATH9K_RX_FILTER_PSPOLL;
Sujithbe0418a2008-11-18 09:05:55 +0530431
Sujith7ea310b2009-09-03 12:08:43 +0530432 if (conf_is_ht(&sc->hw->conf))
433 rfilt |= ATH9K_RX_FILTER_COMP_BAR;
434
Felix Fietkau7545daf2011-01-24 19:23:16 +0100435 if (sc->nvifs > 1 || (sc->rx.rxfilter & FIF_OTHER_BSS)) {
Javier Cardona5eb6ba82009-08-20 19:12:07 -0700436 /* The following may also be needed for other older chips */
437 if (sc->sc_ah->hw_version.macVersion == AR_SREV_VERSION_9160)
438 rfilt |= ATH9K_RX_FILTER_PROM;
Jouni Malinenb93bce22009-03-03 19:23:30 +0200439 rfilt |= ATH9K_RX_FILTER_MCAST_BCAST_ALL;
440 }
441
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700442 return rfilt;
Sujith7dcfdcd2008-08-11 14:03:13 +0530443
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700444#undef RX_FILTER_PRESERVE
445}
446
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700447int ath_startrecv(struct ath_softc *sc)
448{
Sujithcbe61d82009-02-09 13:27:12 +0530449 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700450 struct ath_buf *bf, *tbf;
451
Felix Fietkaub5c804752010-04-15 17:38:48 -0400452 if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
453 ath_edma_start_recv(sc);
454 return 0;
455 }
456
Sujithb77f4832008-12-07 21:44:03 +0530457 spin_lock_bh(&sc->rx.rxbuflock);
458 if (list_empty(&sc->rx.rxbuf))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700459 goto start_recv;
460
Sujithb77f4832008-12-07 21:44:03 +0530461 sc->rx.rxlink = NULL;
462 list_for_each_entry_safe(bf, tbf, &sc->rx.rxbuf, list) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700463 ath_rx_buf_link(sc, bf);
464 }
465
466 /* We could have deleted elements so the list may be empty now */
Sujithb77f4832008-12-07 21:44:03 +0530467 if (list_empty(&sc->rx.rxbuf))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700468 goto start_recv;
469
Sujithb77f4832008-12-07 21:44:03 +0530470 bf = list_first_entry(&sc->rx.rxbuf, struct ath_buf, list);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700471 ath9k_hw_putrxbuf(ah, bf->bf_daddr);
Sujithbe0418a2008-11-18 09:05:55 +0530472 ath9k_hw_rxena(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700473
474start_recv:
Sujithbe0418a2008-11-18 09:05:55 +0530475 ath_opmode_init(sc);
Luis R. Rodriguez48a6a462010-09-16 15:12:28 -0400476 ath9k_hw_startpcureceive(ah, (sc->sc_flags & SC_OP_OFFCHANNEL));
Sujithbe0418a2008-11-18 09:05:55 +0530477
Luis R. Rodriguez7583c5502010-10-20 16:07:04 -0700478 spin_unlock_bh(&sc->rx.rxbuflock);
479
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700480 return 0;
481}
482
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700483bool ath_stoprecv(struct ath_softc *sc)
484{
Sujithcbe61d82009-02-09 13:27:12 +0530485 struct ath_hw *ah = sc->sc_ah;
Felix Fietkau5882da022011-04-08 20:13:18 +0200486 bool stopped, reset = false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700487
Luis R. Rodriguez1e450282010-10-20 16:07:03 -0700488 spin_lock_bh(&sc->rx.rxbuflock);
Felix Fietkaud47844a2010-11-20 03:08:47 +0100489 ath9k_hw_abortpcurecv(ah);
Sujithbe0418a2008-11-18 09:05:55 +0530490 ath9k_hw_setrxfilter(ah, 0);
Felix Fietkau5882da022011-04-08 20:13:18 +0200491 stopped = ath9k_hw_stopdmarecv(ah, &reset);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400492
493 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
494 ath_edma_stop_recv(sc);
495 else
496 sc->rx.rxlink = NULL;
Luis R. Rodriguez1e450282010-10-20 16:07:03 -0700497 spin_unlock_bh(&sc->rx.rxbuflock);
Sujithbe0418a2008-11-18 09:05:55 +0530498
Rajkumar Manoharand5847472010-12-20 14:39:51 +0530499 if (!(ah->ah_flags & AH_UNPLUGGED) &&
500 unlikely(!stopped)) {
Ben Greeard7fd1b502010-12-06 13:13:07 -0800501 ath_err(ath9k_hw_common(sc->sc_ah),
502 "Could not stop RX, we could be "
503 "confusing the DMA engine when we start RX up\n");
504 ATH_DBG_WARN_ON_ONCE(!stopped);
505 }
Felix Fietkau2232d312011-04-15 00:41:43 +0200506 return stopped && !reset;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700507}
508
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700509void ath_flushrecv(struct ath_softc *sc)
510{
Sujith98deeea2008-08-11 14:05:46 +0530511 sc->sc_flags |= SC_OP_RXFLUSH;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400512 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
513 ath_rx_tasklet(sc, 1, true);
514 ath_rx_tasklet(sc, 1, false);
Sujith98deeea2008-08-11 14:05:46 +0530515 sc->sc_flags &= ~SC_OP_RXFLUSH;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700516}
517
Jouni Malinencc659652009-05-14 21:28:48 +0300518static bool ath_beacon_dtim_pending_cab(struct sk_buff *skb)
519{
520 /* Check whether the Beacon frame has DTIM indicating buffered bc/mc */
521 struct ieee80211_mgmt *mgmt;
522 u8 *pos, *end, id, elen;
523 struct ieee80211_tim_ie *tim;
524
525 mgmt = (struct ieee80211_mgmt *)skb->data;
526 pos = mgmt->u.beacon.variable;
527 end = skb->data + skb->len;
528
529 while (pos + 2 < end) {
530 id = *pos++;
531 elen = *pos++;
532 if (pos + elen > end)
533 break;
534
535 if (id == WLAN_EID_TIM) {
536 if (elen < sizeof(*tim))
537 break;
538 tim = (struct ieee80211_tim_ie *) pos;
539 if (tim->dtim_count != 0)
540 break;
541 return tim->bitmap_ctrl & 0x01;
542 }
543
544 pos += elen;
545 }
546
547 return false;
548}
549
Jouni Malinencc659652009-05-14 21:28:48 +0300550static void ath_rx_ps_beacon(struct ath_softc *sc, struct sk_buff *skb)
551{
552 struct ieee80211_mgmt *mgmt;
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700553 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Jouni Malinencc659652009-05-14 21:28:48 +0300554
555 if (skb->len < 24 + 8 + 2 + 2)
556 return;
557
558 mgmt = (struct ieee80211_mgmt *)skb->data;
Ben Greear48014162011-01-15 19:13:48 +0000559 if (memcmp(common->curbssid, mgmt->bssid, ETH_ALEN) != 0) {
560 /* TODO: This doesn't work well if you have stations
561 * associated to two different APs because curbssid
562 * is just the last AP that any of the stations associated
563 * with.
564 */
Jouni Malinencc659652009-05-14 21:28:48 +0300565 return; /* not from our current AP */
Ben Greear48014162011-01-15 19:13:48 +0000566 }
Jouni Malinencc659652009-05-14 21:28:48 +0300567
Sujith1b04b932010-01-08 10:36:05 +0530568 sc->ps_flags &= ~PS_WAIT_FOR_BEACON;
Gabor Juhos293dc5d2009-06-19 12:17:48 +0200569
Sujith1b04b932010-01-08 10:36:05 +0530570 if (sc->ps_flags & PS_BEACON_SYNC) {
571 sc->ps_flags &= ~PS_BEACON_SYNC;
Joe Perches226afe62010-12-02 19:12:37 -0800572 ath_dbg(common, ATH_DBG_PS,
573 "Reconfigure Beacon timers based on timestamp from the AP\n");
Rajkumar Manoharan99e4d432011-04-04 22:56:19 +0530574 ath_set_beacon(sc);
Rajkumar Manoharandeb75182011-05-06 18:27:46 +0530575 sc->ps_flags &= ~PS_TSFOOR_SYNC;
Jouni Malinenccdfeab2009-05-20 21:59:08 +0300576 }
577
Jouni Malinencc659652009-05-14 21:28:48 +0300578 if (ath_beacon_dtim_pending_cab(skb)) {
579 /*
580 * Remain awake waiting for buffered broadcast/multicast
Gabor Juhos58f5fff2009-06-17 20:53:20 +0200581 * frames. If the last broadcast/multicast frame is not
582 * received properly, the next beacon frame will work as
583 * a backup trigger for returning into NETWORK SLEEP state,
584 * so we are waiting for it as well.
Jouni Malinencc659652009-05-14 21:28:48 +0300585 */
Joe Perches226afe62010-12-02 19:12:37 -0800586 ath_dbg(common, ATH_DBG_PS,
587 "Received DTIM beacon indicating buffered broadcast/multicast frame(s)\n");
Sujith1b04b932010-01-08 10:36:05 +0530588 sc->ps_flags |= PS_WAIT_FOR_CAB | PS_WAIT_FOR_BEACON;
Jouni Malinencc659652009-05-14 21:28:48 +0300589 return;
590 }
591
Sujith1b04b932010-01-08 10:36:05 +0530592 if (sc->ps_flags & PS_WAIT_FOR_CAB) {
Jouni Malinencc659652009-05-14 21:28:48 +0300593 /*
594 * This can happen if a broadcast frame is dropped or the AP
595 * fails to send a frame indicating that all CAB frames have
596 * been delivered.
597 */
Sujith1b04b932010-01-08 10:36:05 +0530598 sc->ps_flags &= ~PS_WAIT_FOR_CAB;
Joe Perches226afe62010-12-02 19:12:37 -0800599 ath_dbg(common, ATH_DBG_PS,
600 "PS wait for CAB frames timed out\n");
Jouni Malinencc659652009-05-14 21:28:48 +0300601 }
Jouni Malinencc659652009-05-14 21:28:48 +0300602}
603
604static void ath_rx_ps(struct ath_softc *sc, struct sk_buff *skb)
605{
606 struct ieee80211_hdr *hdr;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700607 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Jouni Malinencc659652009-05-14 21:28:48 +0300608
609 hdr = (struct ieee80211_hdr *)skb->data;
610
611 /* Process Beacon and CAB receive in PS state */
Vasanthakumar Thiagarajanededf1f2010-05-22 23:58:13 -0700612 if (((sc->ps_flags & PS_WAIT_FOR_BEACON) || ath9k_check_auto_sleep(sc))
613 && ieee80211_is_beacon(hdr->frame_control))
Jouni Malinencc659652009-05-14 21:28:48 +0300614 ath_rx_ps_beacon(sc, skb);
Sujith1b04b932010-01-08 10:36:05 +0530615 else if ((sc->ps_flags & PS_WAIT_FOR_CAB) &&
Jouni Malinencc659652009-05-14 21:28:48 +0300616 (ieee80211_is_data(hdr->frame_control) ||
617 ieee80211_is_action(hdr->frame_control)) &&
618 is_multicast_ether_addr(hdr->addr1) &&
619 !ieee80211_has_moredata(hdr->frame_control)) {
Jouni Malinencc659652009-05-14 21:28:48 +0300620 /*
621 * No more broadcast/multicast frames to be received at this
622 * point.
623 */
Senthil Balasubramanian3fac6df2010-09-16 15:12:35 -0400624 sc->ps_flags &= ~(PS_WAIT_FOR_CAB | PS_WAIT_FOR_BEACON);
Joe Perches226afe62010-12-02 19:12:37 -0800625 ath_dbg(common, ATH_DBG_PS,
626 "All PS CAB frames received, back to sleep\n");
Sujith1b04b932010-01-08 10:36:05 +0530627 } else if ((sc->ps_flags & PS_WAIT_FOR_PSPOLL_DATA) &&
Jouni Malinen9a23f9c2009-05-19 17:01:38 +0300628 !is_multicast_ether_addr(hdr->addr1) &&
629 !ieee80211_has_morefrags(hdr->frame_control)) {
Sujith1b04b932010-01-08 10:36:05 +0530630 sc->ps_flags &= ~PS_WAIT_FOR_PSPOLL_DATA;
Joe Perches226afe62010-12-02 19:12:37 -0800631 ath_dbg(common, ATH_DBG_PS,
632 "Going back to sleep after having received PS-Poll data (0x%lx)\n",
Sujith1b04b932010-01-08 10:36:05 +0530633 sc->ps_flags & (PS_WAIT_FOR_BEACON |
634 PS_WAIT_FOR_CAB |
635 PS_WAIT_FOR_PSPOLL_DATA |
636 PS_WAIT_FOR_TX_ACK));
Jouni Malinencc659652009-05-14 21:28:48 +0300637 }
638}
639
Felix Fietkaub5c804752010-04-15 17:38:48 -0400640static bool ath_edma_get_buffers(struct ath_softc *sc,
641 enum ath9k_rx_qtype qtype)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700642{
Felix Fietkaub5c804752010-04-15 17:38:48 -0400643 struct ath_rx_edma *rx_edma = &sc->rx.rx_edma[qtype];
644 struct ath_hw *ah = sc->sc_ah;
645 struct ath_common *common = ath9k_hw_common(ah);
646 struct sk_buff *skb;
Sujithbe0418a2008-11-18 09:05:55 +0530647 struct ath_buf *bf;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400648 int ret;
649
650 skb = skb_peek(&rx_edma->rx_fifo);
651 if (!skb)
652 return false;
653
654 bf = SKB_CB_ATHBUF(skb);
655 BUG_ON(!bf);
656
Ming Leice9426d2010-05-15 18:25:40 +0800657 dma_sync_single_for_cpu(sc->dev, bf->bf_buf_addr,
Felix Fietkaub5c804752010-04-15 17:38:48 -0400658 common->rx_bufsize, DMA_FROM_DEVICE);
659
660 ret = ath9k_hw_process_rxdesc_edma(ah, NULL, skb->data);
Ming Leice9426d2010-05-15 18:25:40 +0800661 if (ret == -EINPROGRESS) {
662 /*let device gain the buffer again*/
663 dma_sync_single_for_device(sc->dev, bf->bf_buf_addr,
664 common->rx_bufsize, DMA_FROM_DEVICE);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400665 return false;
Ming Leice9426d2010-05-15 18:25:40 +0800666 }
Felix Fietkaub5c804752010-04-15 17:38:48 -0400667
668 __skb_unlink(skb, &rx_edma->rx_fifo);
669 if (ret == -EINVAL) {
670 /* corrupt descriptor, skip this one and the following one */
671 list_add_tail(&bf->list, &sc->rx.rxbuf);
672 ath_rx_edma_buf_link(sc, qtype);
673 skb = skb_peek(&rx_edma->rx_fifo);
674 if (!skb)
675 return true;
676
677 bf = SKB_CB_ATHBUF(skb);
678 BUG_ON(!bf);
679
680 __skb_unlink(skb, &rx_edma->rx_fifo);
681 list_add_tail(&bf->list, &sc->rx.rxbuf);
682 ath_rx_edma_buf_link(sc, qtype);
Vasanthakumar Thiagarajan083e3e82010-05-10 19:41:34 -0700683 return true;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400684 }
685 skb_queue_tail(&rx_edma->rx_buffers, skb);
686
687 return true;
688}
689
690static struct ath_buf *ath_edma_get_next_rx_buf(struct ath_softc *sc,
691 struct ath_rx_status *rs,
692 enum ath9k_rx_qtype qtype)
693{
694 struct ath_rx_edma *rx_edma = &sc->rx.rx_edma[qtype];
695 struct sk_buff *skb;
696 struct ath_buf *bf;
697
698 while (ath_edma_get_buffers(sc, qtype));
699 skb = __skb_dequeue(&rx_edma->rx_buffers);
700 if (!skb)
701 return NULL;
702
703 bf = SKB_CB_ATHBUF(skb);
704 ath9k_hw_process_rxdesc_edma(sc->sc_ah, rs, skb->data);
705 return bf;
706}
707
708static struct ath_buf *ath_get_next_rx_buf(struct ath_softc *sc,
709 struct ath_rx_status *rs)
710{
711 struct ath_hw *ah = sc->sc_ah;
712 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700713 struct ath_desc *ds;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400714 struct ath_buf *bf;
715 int ret;
716
717 if (list_empty(&sc->rx.rxbuf)) {
718 sc->rx.rxlink = NULL;
719 return NULL;
720 }
721
722 bf = list_first_entry(&sc->rx.rxbuf, struct ath_buf, list);
723 ds = bf->bf_desc;
724
725 /*
726 * Must provide the virtual address of the current
727 * descriptor, the physical address, and the virtual
728 * address of the next descriptor in the h/w chain.
729 * This allows the HAL to look ahead to see if the
730 * hardware is done with a descriptor by checking the
731 * done bit in the following descriptor and the address
732 * of the current descriptor the DMA engine is working
733 * on. All this is necessary because of our use of
734 * a self-linked list to avoid rx overruns.
735 */
736 ret = ath9k_hw_rxprocdesc(ah, ds, rs, 0);
737 if (ret == -EINPROGRESS) {
738 struct ath_rx_status trs;
739 struct ath_buf *tbf;
740 struct ath_desc *tds;
741
742 memset(&trs, 0, sizeof(trs));
743 if (list_is_last(&bf->list, &sc->rx.rxbuf)) {
744 sc->rx.rxlink = NULL;
745 return NULL;
746 }
747
748 tbf = list_entry(bf->list.next, struct ath_buf, list);
749
750 /*
751 * On some hardware the descriptor status words could
752 * get corrupted, including the done bit. Because of
753 * this, check if the next descriptor's done bit is
754 * set or not.
755 *
756 * If the next descriptor's done bit is set, the current
757 * descriptor has been corrupted. Force s/w to discard
758 * this descriptor and continue...
759 */
760
761 tds = tbf->bf_desc;
762 ret = ath9k_hw_rxprocdesc(ah, tds, &trs, 0);
763 if (ret == -EINPROGRESS)
764 return NULL;
765 }
766
767 if (!bf->bf_mpdu)
768 return bf;
769
770 /*
771 * Synchronize the DMA transfer with CPU before
772 * 1. accessing the frame
773 * 2. requeueing the same buffer to h/w
774 */
Ming Leice9426d2010-05-15 18:25:40 +0800775 dma_sync_single_for_cpu(sc->dev, bf->bf_buf_addr,
Felix Fietkaub5c804752010-04-15 17:38:48 -0400776 common->rx_bufsize,
777 DMA_FROM_DEVICE);
778
779 return bf;
780}
781
Sujithd4357002010-05-20 15:34:38 +0530782/* Assumes you've already done the endian to CPU conversion */
783static bool ath9k_rx_accept(struct ath_common *common,
Vasanthakumar Thiagarajan9f167f62010-05-20 14:34:46 -0700784 struct ieee80211_hdr *hdr,
Sujithd4357002010-05-20 15:34:38 +0530785 struct ieee80211_rx_status *rxs,
786 struct ath_rx_status *rx_stats,
787 bool *decrypt_error)
788{
Senthil Balasubramanian38852b22010-12-06 19:09:27 +0530789#define is_mc_or_valid_tkip_keyix ((is_mc || \
790 (rx_stats->rs_keyix != ATH9K_RXKEYIX_INVALID && \
791 test_bit(rx_stats->rs_keyix, common->tkip_keymap))))
792
Sujithd4357002010-05-20 15:34:38 +0530793 struct ath_hw *ah = common->ah;
Sujithd4357002010-05-20 15:34:38 +0530794 __le16 fc;
Vasanthakumar Thiagarajanb7b1b512010-05-20 14:34:48 -0700795 u8 rx_status_len = ah->caps.rx_status_len;
Sujithd4357002010-05-20 15:34:38 +0530796
Sujithd4357002010-05-20 15:34:38 +0530797 fc = hdr->frame_control;
798
799 if (!rx_stats->rs_datalen)
800 return false;
801 /*
802 * rs_status follows rs_datalen so if rs_datalen is too large
803 * we can take a hint that hardware corrupted it, so ignore
804 * those frames.
805 */
Vasanthakumar Thiagarajanb7b1b512010-05-20 14:34:48 -0700806 if (rx_stats->rs_datalen > (common->rx_bufsize - rx_status_len))
Sujithd4357002010-05-20 15:34:38 +0530807 return false;
808
Felix Fietkau0d955212011-01-26 18:23:27 +0100809 /* Only use error bits from the last fragment */
Sujithd4357002010-05-20 15:34:38 +0530810 if (rx_stats->rs_more)
Felix Fietkau0d955212011-01-26 18:23:27 +0100811 return true;
Sujithd4357002010-05-20 15:34:38 +0530812
813 /*
814 * The rx_stats->rs_status will not be set until the end of the
815 * chained descriptors so it can be ignored if rs_more is set. The
816 * rs_more will be false at the last element of the chained
817 * descriptors.
818 */
819 if (rx_stats->rs_status != 0) {
820 if (rx_stats->rs_status & ATH9K_RXERR_CRC)
821 rxs->flag |= RX_FLAG_FAILED_FCS_CRC;
822 if (rx_stats->rs_status & ATH9K_RXERR_PHY)
823 return false;
824
825 if (rx_stats->rs_status & ATH9K_RXERR_DECRYPT) {
826 *decrypt_error = true;
827 } else if (rx_stats->rs_status & ATH9K_RXERR_MIC) {
Senthil Balasubramanian38852b22010-12-06 19:09:27 +0530828 bool is_mc;
Felix Fietkau56363dd2010-08-28 18:21:21 +0200829 /*
830 * The MIC error bit is only valid if the frame
831 * is not a control frame or fragment, and it was
832 * decrypted using a valid TKIP key.
833 */
Senthil Balasubramanian38852b22010-12-06 19:09:27 +0530834 is_mc = !!is_multicast_ether_addr(hdr->addr1);
835
Felix Fietkau56363dd2010-08-28 18:21:21 +0200836 if (!ieee80211_is_ctl(fc) &&
837 !ieee80211_has_morefrags(fc) &&
838 !(le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG) &&
Senthil Balasubramanian38852b22010-12-06 19:09:27 +0530839 is_mc_or_valid_tkip_keyix)
Sujithd4357002010-05-20 15:34:38 +0530840 rxs->flag |= RX_FLAG_MMIC_ERROR;
Felix Fietkau56363dd2010-08-28 18:21:21 +0200841 else
842 rx_stats->rs_status &= ~ATH9K_RXERR_MIC;
Sujithd4357002010-05-20 15:34:38 +0530843 }
844 /*
845 * Reject error frames with the exception of
846 * decryption and MIC failures. For monitor mode,
847 * we also ignore the CRC error.
848 */
Rajkumar Manoharan5f841b42010-10-27 18:31:15 +0530849 if (ah->is_monitoring) {
Sujithd4357002010-05-20 15:34:38 +0530850 if (rx_stats->rs_status &
851 ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC |
852 ATH9K_RXERR_CRC))
853 return false;
854 } else {
855 if (rx_stats->rs_status &
856 ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC)) {
857 return false;
858 }
859 }
860 }
861 return true;
862}
863
864static int ath9k_process_rate(struct ath_common *common,
865 struct ieee80211_hw *hw,
866 struct ath_rx_status *rx_stats,
Vasanthakumar Thiagarajan9f167f62010-05-20 14:34:46 -0700867 struct ieee80211_rx_status *rxs)
Sujithd4357002010-05-20 15:34:38 +0530868{
869 struct ieee80211_supported_band *sband;
870 enum ieee80211_band band;
871 unsigned int i = 0;
872
873 band = hw->conf.channel->band;
874 sband = hw->wiphy->bands[band];
875
876 if (rx_stats->rs_rate & 0x80) {
877 /* HT rate */
878 rxs->flag |= RX_FLAG_HT;
879 if (rx_stats->rs_flags & ATH9K_RX_2040)
880 rxs->flag |= RX_FLAG_40MHZ;
881 if (rx_stats->rs_flags & ATH9K_RX_GI)
882 rxs->flag |= RX_FLAG_SHORT_GI;
883 rxs->rate_idx = rx_stats->rs_rate & 0x7f;
884 return 0;
885 }
886
887 for (i = 0; i < sband->n_bitrates; i++) {
888 if (sband->bitrates[i].hw_value == rx_stats->rs_rate) {
889 rxs->rate_idx = i;
890 return 0;
891 }
892 if (sband->bitrates[i].hw_value_short == rx_stats->rs_rate) {
893 rxs->flag |= RX_FLAG_SHORTPRE;
894 rxs->rate_idx = i;
895 return 0;
896 }
897 }
898
899 /*
900 * No valid hardware bitrate found -- we should not get here
901 * because hardware has already validated this frame as OK.
902 */
Joe Perches226afe62010-12-02 19:12:37 -0800903 ath_dbg(common, ATH_DBG_XMIT,
904 "unsupported hw bitrate detected 0x%02x using 1 Mbit\n",
905 rx_stats->rs_rate);
Sujithd4357002010-05-20 15:34:38 +0530906
907 return -EINVAL;
908}
909
910static void ath9k_process_rssi(struct ath_common *common,
911 struct ieee80211_hw *hw,
Vasanthakumar Thiagarajan9f167f62010-05-20 14:34:46 -0700912 struct ieee80211_hdr *hdr,
Sujithd4357002010-05-20 15:34:38 +0530913 struct ath_rx_status *rx_stats)
914{
Felix Fietkau9ac586152011-01-24 19:23:18 +0100915 struct ath_softc *sc = hw->priv;
Sujithd4357002010-05-20 15:34:38 +0530916 struct ath_hw *ah = common->ah;
Felix Fietkau9fa23e12010-10-15 20:03:31 +0200917 int last_rssi;
Sujithd4357002010-05-20 15:34:38 +0530918 __le16 fc;
919
Felix Fietkau9fa23e12010-10-15 20:03:31 +0200920 if (ah->opmode != NL80211_IFTYPE_STATION)
921 return;
922
Sujithd4357002010-05-20 15:34:38 +0530923 fc = hdr->frame_control;
Felix Fietkau9fa23e12010-10-15 20:03:31 +0200924 if (!ieee80211_is_beacon(fc) ||
Ben Greear48014162011-01-15 19:13:48 +0000925 compare_ether_addr(hdr->addr3, common->curbssid)) {
926 /* TODO: This doesn't work well if you have stations
927 * associated to two different APs because curbssid
928 * is just the last AP that any of the stations associated
929 * with.
930 */
Felix Fietkau9fa23e12010-10-15 20:03:31 +0200931 return;
Ben Greear48014162011-01-15 19:13:48 +0000932 }
Sujithd4357002010-05-20 15:34:38 +0530933
Felix Fietkau9fa23e12010-10-15 20:03:31 +0200934 if (rx_stats->rs_rssi != ATH9K_RSSI_BAD && !rx_stats->rs_moreaggr)
Felix Fietkau9ac586152011-01-24 19:23:18 +0100935 ATH_RSSI_LPF(sc->last_rssi, rx_stats->rs_rssi);
Ben Greear686b9cb2010-09-23 09:44:36 -0700936
Felix Fietkau9ac586152011-01-24 19:23:18 +0100937 last_rssi = sc->last_rssi;
Sujithd4357002010-05-20 15:34:38 +0530938 if (likely(last_rssi != ATH_RSSI_DUMMY_MARKER))
939 rx_stats->rs_rssi = ATH_EP_RND(last_rssi,
940 ATH_RSSI_EP_MULTIPLIER);
941 if (rx_stats->rs_rssi < 0)
942 rx_stats->rs_rssi = 0;
943
944 /* Update Beacon RSSI, this is used by ANI. */
Felix Fietkau9fa23e12010-10-15 20:03:31 +0200945 ah->stats.avgbrssi = rx_stats->rs_rssi;
Sujithd4357002010-05-20 15:34:38 +0530946}
947
948/*
949 * For Decrypt or Demic errors, we only mark packet status here and always push
950 * up the frame up to let mac80211 handle the actual error case, be it no
951 * decryption key or real decryption error. This let us keep statistics there.
952 */
953static int ath9k_rx_skb_preprocess(struct ath_common *common,
954 struct ieee80211_hw *hw,
Vasanthakumar Thiagarajan9f167f62010-05-20 14:34:46 -0700955 struct ieee80211_hdr *hdr,
Sujithd4357002010-05-20 15:34:38 +0530956 struct ath_rx_status *rx_stats,
957 struct ieee80211_rx_status *rx_status,
958 bool *decrypt_error)
959{
Sujithd4357002010-05-20 15:34:38 +0530960 memset(rx_status, 0, sizeof(struct ieee80211_rx_status));
961
962 /*
963 * everything but the rate is checked here, the rate check is done
964 * separately to avoid doing two lookups for a rate for each frame.
965 */
Vasanthakumar Thiagarajan9f167f62010-05-20 14:34:46 -0700966 if (!ath9k_rx_accept(common, hdr, rx_status, rx_stats, decrypt_error))
Sujithd4357002010-05-20 15:34:38 +0530967 return -EINVAL;
968
Felix Fietkau0d955212011-01-26 18:23:27 +0100969 /* Only use status info from the last fragment */
970 if (rx_stats->rs_more)
971 return 0;
972
Vasanthakumar Thiagarajan9f167f62010-05-20 14:34:46 -0700973 ath9k_process_rssi(common, hw, hdr, rx_stats);
Sujithd4357002010-05-20 15:34:38 +0530974
Vasanthakumar Thiagarajan9f167f62010-05-20 14:34:46 -0700975 if (ath9k_process_rate(common, hw, rx_stats, rx_status))
Sujithd4357002010-05-20 15:34:38 +0530976 return -EINVAL;
977
Sujithd4357002010-05-20 15:34:38 +0530978 rx_status->band = hw->conf.channel->band;
979 rx_status->freq = hw->conf.channel->center_freq;
980 rx_status->signal = ATH_DEFAULT_NOISE_FLOOR + rx_stats->rs_rssi;
981 rx_status->antenna = rx_stats->rs_antenna;
Johannes Berg6ebacbb2011-02-23 15:06:08 +0100982 rx_status->flag |= RX_FLAG_MACTIME_MPDU;
Sujithd4357002010-05-20 15:34:38 +0530983
984 return 0;
985}
986
987static void ath9k_rx_skb_postprocess(struct ath_common *common,
988 struct sk_buff *skb,
989 struct ath_rx_status *rx_stats,
990 struct ieee80211_rx_status *rxs,
991 bool decrypt_error)
992{
993 struct ath_hw *ah = common->ah;
994 struct ieee80211_hdr *hdr;
995 int hdrlen, padpos, padsize;
996 u8 keyix;
997 __le16 fc;
998
999 /* see if any padding is done by the hw and remove it */
1000 hdr = (struct ieee80211_hdr *) skb->data;
1001 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
1002 fc = hdr->frame_control;
1003 padpos = ath9k_cmn_padpos(hdr->frame_control);
1004
1005 /* The MAC header is padded to have 32-bit boundary if the
1006 * packet payload is non-zero. The general calculation for
1007 * padsize would take into account odd header lengths:
1008 * padsize = (4 - padpos % 4) % 4; However, since only
1009 * even-length headers are used, padding can only be 0 or 2
1010 * bytes and we can optimize this a bit. In addition, we must
1011 * not try to remove padding from short control frames that do
1012 * not have payload. */
1013 padsize = padpos & 3;
1014 if (padsize && skb->len>=padpos+padsize+FCS_LEN) {
1015 memmove(skb->data + padsize, skb->data, padpos);
1016 skb_pull(skb, padsize);
1017 }
1018
1019 keyix = rx_stats->rs_keyix;
1020
1021 if (!(keyix == ATH9K_RXKEYIX_INVALID) && !decrypt_error &&
1022 ieee80211_has_protected(fc)) {
1023 rxs->flag |= RX_FLAG_DECRYPTED;
1024 } else if (ieee80211_has_protected(fc)
1025 && !decrypt_error && skb->len >= hdrlen + 4) {
1026 keyix = skb->data[hdrlen + 3] >> 6;
1027
1028 if (test_bit(keyix, common->keymap))
1029 rxs->flag |= RX_FLAG_DECRYPTED;
1030 }
1031 if (ah->sw_mgmt_crypto &&
1032 (rxs->flag & RX_FLAG_DECRYPTED) &&
1033 ieee80211_is_mgmt(fc))
1034 /* Use software decrypt for management frames. */
1035 rxs->flag &= ~RX_FLAG_DECRYPTED;
1036}
Felix Fietkaub5c804752010-04-15 17:38:48 -04001037
Vasanthakumar Thiagarajan102885a2010-09-02 01:34:43 -07001038static void ath_lnaconf_alt_good_scan(struct ath_ant_comb *antcomb,
1039 struct ath_hw_antcomb_conf ant_conf,
1040 int main_rssi_avg)
1041{
1042 antcomb->quick_scan_cnt = 0;
1043
1044 if (ant_conf.main_lna_conf == ATH_ANT_DIV_COMB_LNA2)
1045 antcomb->rssi_lna2 = main_rssi_avg;
1046 else if (ant_conf.main_lna_conf == ATH_ANT_DIV_COMB_LNA1)
1047 antcomb->rssi_lna1 = main_rssi_avg;
1048
1049 switch ((ant_conf.main_lna_conf << 4) | ant_conf.alt_lna_conf) {
1050 case (0x10): /* LNA2 A-B */
1051 antcomb->main_conf = ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1052 antcomb->first_quick_scan_conf =
1053 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1054 antcomb->second_quick_scan_conf = ATH_ANT_DIV_COMB_LNA1;
1055 break;
1056 case (0x20): /* LNA1 A-B */
1057 antcomb->main_conf = ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1058 antcomb->first_quick_scan_conf =
1059 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1060 antcomb->second_quick_scan_conf = ATH_ANT_DIV_COMB_LNA2;
1061 break;
1062 case (0x21): /* LNA1 LNA2 */
1063 antcomb->main_conf = ATH_ANT_DIV_COMB_LNA2;
1064 antcomb->first_quick_scan_conf =
1065 ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1066 antcomb->second_quick_scan_conf =
1067 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1068 break;
1069 case (0x12): /* LNA2 LNA1 */
1070 antcomb->main_conf = ATH_ANT_DIV_COMB_LNA1;
1071 antcomb->first_quick_scan_conf =
1072 ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1073 antcomb->second_quick_scan_conf =
1074 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1075 break;
1076 case (0x13): /* LNA2 A+B */
1077 antcomb->main_conf = ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1078 antcomb->first_quick_scan_conf =
1079 ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1080 antcomb->second_quick_scan_conf = ATH_ANT_DIV_COMB_LNA1;
1081 break;
1082 case (0x23): /* LNA1 A+B */
1083 antcomb->main_conf = ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1084 antcomb->first_quick_scan_conf =
1085 ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1086 antcomb->second_quick_scan_conf = ATH_ANT_DIV_COMB_LNA2;
1087 break;
1088 default:
1089 break;
1090 }
1091}
1092
1093static void ath_select_ant_div_from_quick_scan(struct ath_ant_comb *antcomb,
1094 struct ath_hw_antcomb_conf *div_ant_conf,
1095 int main_rssi_avg, int alt_rssi_avg,
1096 int alt_ratio)
1097{
1098 /* alt_good */
1099 switch (antcomb->quick_scan_cnt) {
1100 case 0:
1101 /* set alt to main, and alt to first conf */
1102 div_ant_conf->main_lna_conf = antcomb->main_conf;
1103 div_ant_conf->alt_lna_conf = antcomb->first_quick_scan_conf;
1104 break;
1105 case 1:
1106 /* set alt to main, and alt to first conf */
1107 div_ant_conf->main_lna_conf = antcomb->main_conf;
1108 div_ant_conf->alt_lna_conf = antcomb->second_quick_scan_conf;
1109 antcomb->rssi_first = main_rssi_avg;
1110 antcomb->rssi_second = alt_rssi_avg;
1111
1112 if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA1) {
1113 /* main is LNA1 */
1114 if (ath_is_alt_ant_ratio_better(alt_ratio,
1115 ATH_ANT_DIV_COMB_LNA1_DELTA_HI,
1116 ATH_ANT_DIV_COMB_LNA1_DELTA_LOW,
1117 main_rssi_avg, alt_rssi_avg,
1118 antcomb->total_pkt_count))
1119 antcomb->first_ratio = true;
1120 else
1121 antcomb->first_ratio = false;
1122 } else if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA2) {
1123 if (ath_is_alt_ant_ratio_better(alt_ratio,
1124 ATH_ANT_DIV_COMB_LNA1_DELTA_MID,
1125 ATH_ANT_DIV_COMB_LNA1_DELTA_LOW,
1126 main_rssi_avg, alt_rssi_avg,
1127 antcomb->total_pkt_count))
1128 antcomb->first_ratio = true;
1129 else
1130 antcomb->first_ratio = false;
1131 } else {
1132 if ((((alt_ratio >= ATH_ANT_DIV_COMB_ALT_ANT_RATIO2) &&
1133 (alt_rssi_avg > main_rssi_avg +
1134 ATH_ANT_DIV_COMB_LNA1_DELTA_HI)) ||
1135 (alt_rssi_avg > main_rssi_avg)) &&
1136 (antcomb->total_pkt_count > 50))
1137 antcomb->first_ratio = true;
1138 else
1139 antcomb->first_ratio = false;
1140 }
1141 break;
1142 case 2:
1143 antcomb->alt_good = false;
1144 antcomb->scan_not_start = false;
1145 antcomb->scan = false;
1146 antcomb->rssi_first = main_rssi_avg;
1147 antcomb->rssi_third = alt_rssi_avg;
1148
1149 if (antcomb->second_quick_scan_conf == ATH_ANT_DIV_COMB_LNA1)
1150 antcomb->rssi_lna1 = alt_rssi_avg;
1151 else if (antcomb->second_quick_scan_conf ==
1152 ATH_ANT_DIV_COMB_LNA2)
1153 antcomb->rssi_lna2 = alt_rssi_avg;
1154 else if (antcomb->second_quick_scan_conf ==
1155 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2) {
1156 if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA2)
1157 antcomb->rssi_lna2 = main_rssi_avg;
1158 else if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA1)
1159 antcomb->rssi_lna1 = main_rssi_avg;
1160 }
1161
1162 if (antcomb->rssi_lna2 > antcomb->rssi_lna1 +
1163 ATH_ANT_DIV_COMB_LNA1_LNA2_SWITCH_DELTA)
1164 div_ant_conf->main_lna_conf = ATH_ANT_DIV_COMB_LNA2;
1165 else
1166 div_ant_conf->main_lna_conf = ATH_ANT_DIV_COMB_LNA1;
1167
1168 if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA1) {
1169 if (ath_is_alt_ant_ratio_better(alt_ratio,
1170 ATH_ANT_DIV_COMB_LNA1_DELTA_HI,
1171 ATH_ANT_DIV_COMB_LNA1_DELTA_LOW,
1172 main_rssi_avg, alt_rssi_avg,
1173 antcomb->total_pkt_count))
1174 antcomb->second_ratio = true;
1175 else
1176 antcomb->second_ratio = false;
1177 } else if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA2) {
1178 if (ath_is_alt_ant_ratio_better(alt_ratio,
1179 ATH_ANT_DIV_COMB_LNA1_DELTA_MID,
1180 ATH_ANT_DIV_COMB_LNA1_DELTA_LOW,
1181 main_rssi_avg, alt_rssi_avg,
1182 antcomb->total_pkt_count))
1183 antcomb->second_ratio = true;
1184 else
1185 antcomb->second_ratio = false;
1186 } else {
1187 if ((((alt_ratio >= ATH_ANT_DIV_COMB_ALT_ANT_RATIO2) &&
1188 (alt_rssi_avg > main_rssi_avg +
1189 ATH_ANT_DIV_COMB_LNA1_DELTA_HI)) ||
1190 (alt_rssi_avg > main_rssi_avg)) &&
1191 (antcomb->total_pkt_count > 50))
1192 antcomb->second_ratio = true;
1193 else
1194 antcomb->second_ratio = false;
1195 }
1196
1197 /* set alt to the conf with maximun ratio */
1198 if (antcomb->first_ratio && antcomb->second_ratio) {
1199 if (antcomb->rssi_second > antcomb->rssi_third) {
1200 /* first alt*/
1201 if ((antcomb->first_quick_scan_conf ==
1202 ATH_ANT_DIV_COMB_LNA1) ||
1203 (antcomb->first_quick_scan_conf ==
1204 ATH_ANT_DIV_COMB_LNA2))
1205 /* Set alt LNA1 or LNA2*/
1206 if (div_ant_conf->main_lna_conf ==
1207 ATH_ANT_DIV_COMB_LNA2)
1208 div_ant_conf->alt_lna_conf =
1209 ATH_ANT_DIV_COMB_LNA1;
1210 else
1211 div_ant_conf->alt_lna_conf =
1212 ATH_ANT_DIV_COMB_LNA2;
1213 else
1214 /* Set alt to A+B or A-B */
1215 div_ant_conf->alt_lna_conf =
1216 antcomb->first_quick_scan_conf;
1217 } else if ((antcomb->second_quick_scan_conf ==
1218 ATH_ANT_DIV_COMB_LNA1) ||
1219 (antcomb->second_quick_scan_conf ==
1220 ATH_ANT_DIV_COMB_LNA2)) {
1221 /* Set alt LNA1 or LNA2 */
1222 if (div_ant_conf->main_lna_conf ==
1223 ATH_ANT_DIV_COMB_LNA2)
1224 div_ant_conf->alt_lna_conf =
1225 ATH_ANT_DIV_COMB_LNA1;
1226 else
1227 div_ant_conf->alt_lna_conf =
1228 ATH_ANT_DIV_COMB_LNA2;
1229 } else {
1230 /* Set alt to A+B or A-B */
1231 div_ant_conf->alt_lna_conf =
1232 antcomb->second_quick_scan_conf;
1233 }
1234 } else if (antcomb->first_ratio) {
1235 /* first alt */
1236 if ((antcomb->first_quick_scan_conf ==
1237 ATH_ANT_DIV_COMB_LNA1) ||
1238 (antcomb->first_quick_scan_conf ==
1239 ATH_ANT_DIV_COMB_LNA2))
1240 /* Set alt LNA1 or LNA2 */
1241 if (div_ant_conf->main_lna_conf ==
1242 ATH_ANT_DIV_COMB_LNA2)
1243 div_ant_conf->alt_lna_conf =
1244 ATH_ANT_DIV_COMB_LNA1;
1245 else
1246 div_ant_conf->alt_lna_conf =
1247 ATH_ANT_DIV_COMB_LNA2;
1248 else
1249 /* Set alt to A+B or A-B */
1250 div_ant_conf->alt_lna_conf =
1251 antcomb->first_quick_scan_conf;
1252 } else if (antcomb->second_ratio) {
1253 /* second alt */
1254 if ((antcomb->second_quick_scan_conf ==
1255 ATH_ANT_DIV_COMB_LNA1) ||
1256 (antcomb->second_quick_scan_conf ==
1257 ATH_ANT_DIV_COMB_LNA2))
1258 /* Set alt LNA1 or LNA2 */
1259 if (div_ant_conf->main_lna_conf ==
1260 ATH_ANT_DIV_COMB_LNA2)
1261 div_ant_conf->alt_lna_conf =
1262 ATH_ANT_DIV_COMB_LNA1;
1263 else
1264 div_ant_conf->alt_lna_conf =
1265 ATH_ANT_DIV_COMB_LNA2;
1266 else
1267 /* Set alt to A+B or A-B */
1268 div_ant_conf->alt_lna_conf =
1269 antcomb->second_quick_scan_conf;
1270 } else {
1271 /* main is largest */
1272 if ((antcomb->main_conf == ATH_ANT_DIV_COMB_LNA1) ||
1273 (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA2))
1274 /* Set alt LNA1 or LNA2 */
1275 if (div_ant_conf->main_lna_conf ==
1276 ATH_ANT_DIV_COMB_LNA2)
1277 div_ant_conf->alt_lna_conf =
1278 ATH_ANT_DIV_COMB_LNA1;
1279 else
1280 div_ant_conf->alt_lna_conf =
1281 ATH_ANT_DIV_COMB_LNA2;
1282 else
1283 /* Set alt to A+B or A-B */
1284 div_ant_conf->alt_lna_conf = antcomb->main_conf;
1285 }
1286 break;
1287 default:
1288 break;
1289 }
1290}
1291
John W. Linville9bad82b2010-09-15 15:26:13 -04001292static void ath_ant_div_conf_fast_divbias(struct ath_hw_antcomb_conf *ant_conf)
Vasanthakumar Thiagarajan102885a2010-09-02 01:34:43 -07001293{
1294 /* Adjust the fast_div_bias based on main and alt lna conf */
1295 switch ((ant_conf->main_lna_conf << 4) | ant_conf->alt_lna_conf) {
1296 case (0x01): /* A-B LNA2 */
1297 ant_conf->fast_div_bias = 0x3b;
1298 break;
1299 case (0x02): /* A-B LNA1 */
1300 ant_conf->fast_div_bias = 0x3d;
1301 break;
1302 case (0x03): /* A-B A+B */
1303 ant_conf->fast_div_bias = 0x1;
1304 break;
1305 case (0x10): /* LNA2 A-B */
1306 ant_conf->fast_div_bias = 0x7;
1307 break;
1308 case (0x12): /* LNA2 LNA1 */
1309 ant_conf->fast_div_bias = 0x2;
1310 break;
1311 case (0x13): /* LNA2 A+B */
1312 ant_conf->fast_div_bias = 0x7;
1313 break;
1314 case (0x20): /* LNA1 A-B */
1315 ant_conf->fast_div_bias = 0x6;
1316 break;
1317 case (0x21): /* LNA1 LNA2 */
1318 ant_conf->fast_div_bias = 0x0;
1319 break;
1320 case (0x23): /* LNA1 A+B */
1321 ant_conf->fast_div_bias = 0x6;
1322 break;
1323 case (0x30): /* A+B A-B */
1324 ant_conf->fast_div_bias = 0x1;
1325 break;
1326 case (0x31): /* A+B LNA2 */
1327 ant_conf->fast_div_bias = 0x3b;
1328 break;
1329 case (0x32): /* A+B LNA1 */
1330 ant_conf->fast_div_bias = 0x3d;
1331 break;
1332 default:
1333 break;
1334 }
1335}
1336
1337/* Antenna diversity and combining */
1338static void ath_ant_comb_scan(struct ath_softc *sc, struct ath_rx_status *rs)
1339{
1340 struct ath_hw_antcomb_conf div_ant_conf;
1341 struct ath_ant_comb *antcomb = &sc->ant_comb;
1342 int alt_ratio = 0, alt_rssi_avg = 0, main_rssi_avg = 0, curr_alt_set;
Sujith Manoharan0ff2b5c2011-04-20 11:00:34 +05301343 int curr_main_set;
Vasanthakumar Thiagarajan102885a2010-09-02 01:34:43 -07001344 int main_rssi = rs->rs_rssi_ctl0;
1345 int alt_rssi = rs->rs_rssi_ctl1;
1346 int rx_ant_conf, main_ant_conf;
1347 bool short_scan = false;
1348
1349 rx_ant_conf = (rs->rs_rssi_ctl2 >> ATH_ANT_RX_CURRENT_SHIFT) &
1350 ATH_ANT_RX_MASK;
1351 main_ant_conf = (rs->rs_rssi_ctl2 >> ATH_ANT_RX_MAIN_SHIFT) &
1352 ATH_ANT_RX_MASK;
1353
1354 /* Record packet only when alt_rssi is positive */
1355 if (alt_rssi > 0) {
1356 antcomb->total_pkt_count++;
1357 antcomb->main_total_rssi += main_rssi;
1358 antcomb->alt_total_rssi += alt_rssi;
1359 if (main_ant_conf == rx_ant_conf)
1360 antcomb->main_recv_cnt++;
1361 else
1362 antcomb->alt_recv_cnt++;
1363 }
1364
1365 /* Short scan check */
1366 if (antcomb->scan && antcomb->alt_good) {
1367 if (time_after(jiffies, antcomb->scan_start_time +
1368 msecs_to_jiffies(ATH_ANT_DIV_COMB_SHORT_SCAN_INTR)))
1369 short_scan = true;
1370 else
1371 if (antcomb->total_pkt_count ==
1372 ATH_ANT_DIV_COMB_SHORT_SCAN_PKTCOUNT) {
1373 alt_ratio = ((antcomb->alt_recv_cnt * 100) /
1374 antcomb->total_pkt_count);
1375 if (alt_ratio < ATH_ANT_DIV_COMB_ALT_ANT_RATIO)
1376 short_scan = true;
1377 }
1378 }
1379
1380 if (((antcomb->total_pkt_count < ATH_ANT_DIV_COMB_MAX_PKTCOUNT) ||
1381 rs->rs_moreaggr) && !short_scan)
1382 return;
1383
1384 if (antcomb->total_pkt_count) {
1385 alt_ratio = ((antcomb->alt_recv_cnt * 100) /
1386 antcomb->total_pkt_count);
1387 main_rssi_avg = (antcomb->main_total_rssi /
1388 antcomb->total_pkt_count);
1389 alt_rssi_avg = (antcomb->alt_total_rssi /
1390 antcomb->total_pkt_count);
1391 }
1392
1393
1394 ath9k_hw_antdiv_comb_conf_get(sc->sc_ah, &div_ant_conf);
1395 curr_alt_set = div_ant_conf.alt_lna_conf;
1396 curr_main_set = div_ant_conf.main_lna_conf;
Vasanthakumar Thiagarajan102885a2010-09-02 01:34:43 -07001397
1398 antcomb->count++;
1399
1400 if (antcomb->count == ATH_ANT_DIV_COMB_MAX_COUNT) {
1401 if (alt_ratio > ATH_ANT_DIV_COMB_ALT_ANT_RATIO) {
1402 ath_lnaconf_alt_good_scan(antcomb, div_ant_conf,
1403 main_rssi_avg);
1404 antcomb->alt_good = true;
1405 } else {
1406 antcomb->alt_good = false;
1407 }
1408
1409 antcomb->count = 0;
1410 antcomb->scan = true;
1411 antcomb->scan_not_start = true;
1412 }
1413
1414 if (!antcomb->scan) {
1415 if (alt_ratio > ATH_ANT_DIV_COMB_ALT_ANT_RATIO) {
1416 if (curr_alt_set == ATH_ANT_DIV_COMB_LNA2) {
1417 /* Switch main and alt LNA */
1418 div_ant_conf.main_lna_conf =
1419 ATH_ANT_DIV_COMB_LNA2;
1420 div_ant_conf.alt_lna_conf =
1421 ATH_ANT_DIV_COMB_LNA1;
1422 } else if (curr_alt_set == ATH_ANT_DIV_COMB_LNA1) {
1423 div_ant_conf.main_lna_conf =
1424 ATH_ANT_DIV_COMB_LNA1;
1425 div_ant_conf.alt_lna_conf =
1426 ATH_ANT_DIV_COMB_LNA2;
1427 }
1428
1429 goto div_comb_done;
1430 } else if ((curr_alt_set != ATH_ANT_DIV_COMB_LNA1) &&
1431 (curr_alt_set != ATH_ANT_DIV_COMB_LNA2)) {
1432 /* Set alt to another LNA */
1433 if (curr_main_set == ATH_ANT_DIV_COMB_LNA2)
1434 div_ant_conf.alt_lna_conf =
1435 ATH_ANT_DIV_COMB_LNA1;
1436 else if (curr_main_set == ATH_ANT_DIV_COMB_LNA1)
1437 div_ant_conf.alt_lna_conf =
1438 ATH_ANT_DIV_COMB_LNA2;
1439
1440 goto div_comb_done;
1441 }
1442
1443 if ((alt_rssi_avg < (main_rssi_avg +
1444 ATH_ANT_DIV_COMB_LNA1_LNA2_DELTA)))
1445 goto div_comb_done;
1446 }
1447
1448 if (!antcomb->scan_not_start) {
1449 switch (curr_alt_set) {
1450 case ATH_ANT_DIV_COMB_LNA2:
1451 antcomb->rssi_lna2 = alt_rssi_avg;
1452 antcomb->rssi_lna1 = main_rssi_avg;
1453 antcomb->scan = true;
1454 /* set to A+B */
1455 div_ant_conf.main_lna_conf =
1456 ATH_ANT_DIV_COMB_LNA1;
1457 div_ant_conf.alt_lna_conf =
1458 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1459 break;
1460 case ATH_ANT_DIV_COMB_LNA1:
1461 antcomb->rssi_lna1 = alt_rssi_avg;
1462 antcomb->rssi_lna2 = main_rssi_avg;
1463 antcomb->scan = true;
1464 /* set to A+B */
1465 div_ant_conf.main_lna_conf = ATH_ANT_DIV_COMB_LNA2;
1466 div_ant_conf.alt_lna_conf =
1467 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1468 break;
1469 case ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2:
1470 antcomb->rssi_add = alt_rssi_avg;
1471 antcomb->scan = true;
1472 /* set to A-B */
1473 div_ant_conf.alt_lna_conf =
1474 ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1475 break;
1476 case ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2:
1477 antcomb->rssi_sub = alt_rssi_avg;
1478 antcomb->scan = false;
1479 if (antcomb->rssi_lna2 >
1480 (antcomb->rssi_lna1 +
1481 ATH_ANT_DIV_COMB_LNA1_LNA2_SWITCH_DELTA)) {
1482 /* use LNA2 as main LNA */
1483 if ((antcomb->rssi_add > antcomb->rssi_lna1) &&
1484 (antcomb->rssi_add > antcomb->rssi_sub)) {
1485 /* set to A+B */
1486 div_ant_conf.main_lna_conf =
1487 ATH_ANT_DIV_COMB_LNA2;
1488 div_ant_conf.alt_lna_conf =
1489 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1490 } else if (antcomb->rssi_sub >
1491 antcomb->rssi_lna1) {
1492 /* set to A-B */
1493 div_ant_conf.main_lna_conf =
1494 ATH_ANT_DIV_COMB_LNA2;
1495 div_ant_conf.alt_lna_conf =
1496 ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1497 } else {
1498 /* set to LNA1 */
1499 div_ant_conf.main_lna_conf =
1500 ATH_ANT_DIV_COMB_LNA2;
1501 div_ant_conf.alt_lna_conf =
1502 ATH_ANT_DIV_COMB_LNA1;
1503 }
1504 } else {
1505 /* use LNA1 as main LNA */
1506 if ((antcomb->rssi_add > antcomb->rssi_lna2) &&
1507 (antcomb->rssi_add > antcomb->rssi_sub)) {
1508 /* set to A+B */
1509 div_ant_conf.main_lna_conf =
1510 ATH_ANT_DIV_COMB_LNA1;
1511 div_ant_conf.alt_lna_conf =
1512 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1513 } else if (antcomb->rssi_sub >
1514 antcomb->rssi_lna1) {
1515 /* set to A-B */
1516 div_ant_conf.main_lna_conf =
1517 ATH_ANT_DIV_COMB_LNA1;
1518 div_ant_conf.alt_lna_conf =
1519 ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1520 } else {
1521 /* set to LNA2 */
1522 div_ant_conf.main_lna_conf =
1523 ATH_ANT_DIV_COMB_LNA1;
1524 div_ant_conf.alt_lna_conf =
1525 ATH_ANT_DIV_COMB_LNA2;
1526 }
1527 }
1528 break;
1529 default:
1530 break;
1531 }
1532 } else {
1533 if (!antcomb->alt_good) {
1534 antcomb->scan_not_start = false;
1535 /* Set alt to another LNA */
1536 if (curr_main_set == ATH_ANT_DIV_COMB_LNA2) {
1537 div_ant_conf.main_lna_conf =
1538 ATH_ANT_DIV_COMB_LNA2;
1539 div_ant_conf.alt_lna_conf =
1540 ATH_ANT_DIV_COMB_LNA1;
1541 } else if (curr_main_set == ATH_ANT_DIV_COMB_LNA1) {
1542 div_ant_conf.main_lna_conf =
1543 ATH_ANT_DIV_COMB_LNA1;
1544 div_ant_conf.alt_lna_conf =
1545 ATH_ANT_DIV_COMB_LNA2;
1546 }
1547 goto div_comb_done;
1548 }
1549 }
1550
1551 ath_select_ant_div_from_quick_scan(antcomb, &div_ant_conf,
1552 main_rssi_avg, alt_rssi_avg,
1553 alt_ratio);
1554
1555 antcomb->quick_scan_cnt++;
1556
1557div_comb_done:
1558 ath_ant_div_conf_fast_divbias(&div_ant_conf);
1559
1560 ath9k_hw_antdiv_comb_conf_set(sc->sc_ah, &div_ant_conf);
1561
1562 antcomb->scan_start_time = jiffies;
1563 antcomb->total_pkt_count = 0;
1564 antcomb->main_total_rssi = 0;
1565 antcomb->alt_total_rssi = 0;
1566 antcomb->main_recv_cnt = 0;
1567 antcomb->alt_recv_cnt = 0;
1568}
1569
Felix Fietkaub5c804752010-04-15 17:38:48 -04001570int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp)
1571{
1572 struct ath_buf *bf;
Felix Fietkau0d955212011-01-26 18:23:27 +01001573 struct sk_buff *skb = NULL, *requeue_skb, *hdr_skb;
Luis R. Rodriguez5ca42622009-11-04 08:20:42 -08001574 struct ieee80211_rx_status *rxs;
Sujithcbe61d82009-02-09 13:27:12 +05301575 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez27c51f12009-09-10 11:08:14 -07001576 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezb4afffc2009-11-02 11:36:08 -08001577 /*
Mohammed Shafi Shajakhancae6b742010-12-07 21:23:16 +05301578 * The hw can technically differ from common->hw when using ath9k
Luis R. Rodriguezb4afffc2009-11-02 11:36:08 -08001579 * virtual wiphy so to account for that we iterate over the active
1580 * wiphys and find the appropriate wiphy and therefore hw.
1581 */
Felix Fietkau7545daf2011-01-24 19:23:16 +01001582 struct ieee80211_hw *hw = sc->hw;
Sujithbe0418a2008-11-18 09:05:55 +05301583 struct ieee80211_hdr *hdr;
Luis R. Rodriguezc9b14172009-11-04 16:47:22 -08001584 int retval;
Sujithbe0418a2008-11-18 09:05:55 +05301585 bool decrypt_error = false;
Felix Fietkau29bffa92010-03-29 20:14:23 -07001586 struct ath_rx_status rs;
Felix Fietkaub5c804752010-04-15 17:38:48 -04001587 enum ath9k_rx_qtype qtype;
1588 bool edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA);
1589 int dma_type;
Vasanthakumar Thiagarajan5c6dd922010-05-20 14:34:47 -07001590 u8 rx_status_len = ah->caps.rx_status_len;
Felix Fietkaua6d20552010-06-12 00:33:54 -04001591 u64 tsf = 0;
1592 u32 tsf_lower = 0;
Luis R. Rodriguez8ab2cd02010-09-16 15:12:26 -04001593 unsigned long flags;
Sujithbe0418a2008-11-18 09:05:55 +05301594
Felix Fietkaub5c804752010-04-15 17:38:48 -04001595 if (edma)
Felix Fietkaub5c804752010-04-15 17:38:48 -04001596 dma_type = DMA_BIDIRECTIONAL;
Ming Lei56824222010-05-14 21:15:38 +08001597 else
1598 dma_type = DMA_FROM_DEVICE;
Felix Fietkaub5c804752010-04-15 17:38:48 -04001599
1600 qtype = hp ? ATH9K_RX_QUEUE_HP : ATH9K_RX_QUEUE_LP;
Sujithb77f4832008-12-07 21:44:03 +05301601 spin_lock_bh(&sc->rx.rxbuflock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001602
Felix Fietkaua6d20552010-06-12 00:33:54 -04001603 tsf = ath9k_hw_gettsf64(ah);
1604 tsf_lower = tsf & 0xffffffff;
1605
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001606 do {
1607 /* If handling rx interrupt and flush is in progress => exit */
Sujith98deeea2008-08-11 14:05:46 +05301608 if ((sc->sc_flags & SC_OP_RXFLUSH) && (flush == 0))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001609 break;
1610
Felix Fietkau29bffa92010-03-29 20:14:23 -07001611 memset(&rs, 0, sizeof(rs));
Felix Fietkaub5c804752010-04-15 17:38:48 -04001612 if (edma)
1613 bf = ath_edma_get_next_rx_buf(sc, &rs, qtype);
1614 else
1615 bf = ath_get_next_rx_buf(sc, &rs);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001616
Felix Fietkaub5c804752010-04-15 17:38:48 -04001617 if (!bf)
1618 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001619
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001620 skb = bf->bf_mpdu;
Sujithbe0418a2008-11-18 09:05:55 +05301621 if (!skb)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001622 continue;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001623
Felix Fietkau0d955212011-01-26 18:23:27 +01001624 /*
1625 * Take frame header from the first fragment and RX status from
1626 * the last one.
1627 */
1628 if (sc->rx.frag)
1629 hdr_skb = sc->rx.frag;
1630 else
1631 hdr_skb = skb;
1632
1633 hdr = (struct ieee80211_hdr *) (hdr_skb->data + rx_status_len);
1634 rxs = IEEE80211_SKB_RXCB(hdr_skb);
Luis R. Rodriguez5ca42622009-11-04 08:20:42 -08001635
Felix Fietkau29bffa92010-03-29 20:14:23 -07001636 ath_debug_stat_rx(sc, &rs);
Sujith1395d3f2010-01-08 10:36:11 +05301637
Vasanthakumar Thiagarajan9bf9fca2008-12-15 20:40:46 +05301638 /*
Sujithbe0418a2008-11-18 09:05:55 +05301639 * If we're asked to flush receive queue, directly
1640 * chain it back at the queue without processing it.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001641 */
Sujithbe0418a2008-11-18 09:05:55 +05301642 if (flush)
Felix Fietkau0d955212011-01-26 18:23:27 +01001643 goto requeue_drop_frag;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001644
Jan Friedrichc8f3b722010-08-02 23:55:50 +02001645 retval = ath9k_rx_skb_preprocess(common, hw, hdr, &rs,
1646 rxs, &decrypt_error);
1647 if (retval)
Felix Fietkau0d955212011-01-26 18:23:27 +01001648 goto requeue_drop_frag;
Jan Friedrichc8f3b722010-08-02 23:55:50 +02001649
Felix Fietkaua6d20552010-06-12 00:33:54 -04001650 rxs->mactime = (tsf & ~0xffffffffULL) | rs.rs_tstamp;
1651 if (rs.rs_tstamp > tsf_lower &&
1652 unlikely(rs.rs_tstamp - tsf_lower > 0x10000000))
1653 rxs->mactime -= 0x100000000ULL;
1654
1655 if (rs.rs_tstamp < tsf_lower &&
1656 unlikely(tsf_lower - rs.rs_tstamp > 0x10000000))
1657 rxs->mactime += 0x100000000ULL;
1658
Luis R. Rodriguezcb71d9b2008-11-21 17:41:33 -08001659 /* Ensure we always have an skb to requeue once we are done
1660 * processing the current buffer's skb */
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -08001661 requeue_skb = ath_rxbuf_alloc(common, common->rx_bufsize, GFP_ATOMIC);
Luis R. Rodriguezcb71d9b2008-11-21 17:41:33 -08001662
1663 /* If there is no memory we ignore the current RX'd frame,
1664 * tell hardware it can give us a new frame using the old
Sujithb77f4832008-12-07 21:44:03 +05301665 * skb and put it at the tail of the sc->rx.rxbuf list for
Luis R. Rodriguezcb71d9b2008-11-21 17:41:33 -08001666 * processing. */
1667 if (!requeue_skb)
Felix Fietkau0d955212011-01-26 18:23:27 +01001668 goto requeue_drop_frag;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001669
Vasanthakumar Thiagarajan9bf9fca2008-12-15 20:40:46 +05301670 /* Unmap the frame */
Gabor Juhos7da3c552009-01-14 20:17:03 +01001671 dma_unmap_single(sc->dev, bf->bf_buf_addr,
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -08001672 common->rx_bufsize,
Felix Fietkaub5c804752010-04-15 17:38:48 -04001673 dma_type);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001674
Felix Fietkaub5c804752010-04-15 17:38:48 -04001675 skb_put(skb, rs.rs_datalen + ah->caps.rx_status_len);
1676 if (ah->caps.rx_status_len)
1677 skb_pull(skb, ah->caps.rx_status_len);
Sujithbe0418a2008-11-18 09:05:55 +05301678
Felix Fietkau0d955212011-01-26 18:23:27 +01001679 if (!rs.rs_more)
1680 ath9k_rx_skb_postprocess(common, hdr_skb, &rs,
1681 rxs, decrypt_error);
Sujithbe0418a2008-11-18 09:05:55 +05301682
Luis R. Rodriguezcb71d9b2008-11-21 17:41:33 -08001683 /* We will now give hardware our shiny new allocated skb */
1684 bf->bf_mpdu = requeue_skb;
Gabor Juhos7da3c552009-01-14 20:17:03 +01001685 bf->bf_buf_addr = dma_map_single(sc->dev, requeue_skb->data,
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -08001686 common->rx_bufsize,
Felix Fietkaub5c804752010-04-15 17:38:48 -04001687 dma_type);
Gabor Juhos7da3c552009-01-14 20:17:03 +01001688 if (unlikely(dma_mapping_error(sc->dev,
Luis R. Rodriguezf8316df2008-12-03 03:35:29 -08001689 bf->bf_buf_addr))) {
1690 dev_kfree_skb_any(requeue_skb);
1691 bf->bf_mpdu = NULL;
Ben Greear6cf9e992010-10-14 12:45:30 -07001692 bf->bf_buf_addr = 0;
Joe Perches38002762010-12-02 19:12:36 -08001693 ath_err(common, "dma_mapping_error() on RX\n");
Felix Fietkau7545daf2011-01-24 19:23:16 +01001694 ieee80211_rx(hw, skb);
Luis R. Rodriguezf8316df2008-12-03 03:35:29 -08001695 break;
1696 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001697
Felix Fietkau0d955212011-01-26 18:23:27 +01001698 if (rs.rs_more) {
1699 /*
1700 * rs_more indicates chained descriptors which can be
1701 * used to link buffers together for a sort of
1702 * scatter-gather operation.
1703 */
1704 if (sc->rx.frag) {
1705 /* too many fragments - cannot handle frame */
1706 dev_kfree_skb_any(sc->rx.frag);
1707 dev_kfree_skb_any(skb);
1708 skb = NULL;
1709 }
1710 sc->rx.frag = skb;
1711 goto requeue;
1712 }
1713
1714 if (sc->rx.frag) {
1715 int space = skb->len - skb_tailroom(hdr_skb);
1716
1717 sc->rx.frag = NULL;
1718
1719 if (pskb_expand_head(hdr_skb, 0, space, GFP_ATOMIC) < 0) {
1720 dev_kfree_skb(skb);
1721 goto requeue_drop_frag;
1722 }
1723
1724 skb_copy_from_linear_data(skb, skb_put(hdr_skb, skb->len),
1725 skb->len);
1726 dev_kfree_skb_any(skb);
1727 skb = hdr_skb;
1728 }
1729
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001730 /*
1731 * change the default rx antenna if rx diversity chooses the
1732 * other antenna 3 times in a row.
1733 */
Felix Fietkau29bffa92010-03-29 20:14:23 -07001734 if (sc->rx.defant != rs.rs_antenna) {
Sujithb77f4832008-12-07 21:44:03 +05301735 if (++sc->rx.rxotherant >= 3)
Felix Fietkau29bffa92010-03-29 20:14:23 -07001736 ath_setdefantenna(sc, rs.rs_antenna);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001737 } else {
Sujithb77f4832008-12-07 21:44:03 +05301738 sc->rx.rxotherant = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001739 }
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301740
Luis R. Rodriguez8ab2cd02010-09-16 15:12:26 -04001741 spin_lock_irqsave(&sc->sc_pm_lock, flags);
Mohammed Shafi Shajakhanaaef24b2010-12-07 20:40:58 +05301742
1743 if ((sc->ps_flags & (PS_WAIT_FOR_BEACON |
Vasanthakumar Thiagarajanededf1f2010-05-22 23:58:13 -07001744 PS_WAIT_FOR_CAB |
Mohammed Shafi Shajakhanaaef24b2010-12-07 20:40:58 +05301745 PS_WAIT_FOR_PSPOLL_DATA)) ||
Mohammed Shafi Shajakhancedc7e32011-04-22 13:12:23 +05301746 ath9k_check_auto_sleep(sc))
Jouni Malinencc659652009-05-14 21:28:48 +03001747 ath_rx_ps(sc, skb);
Luis R. Rodriguez8ab2cd02010-09-16 15:12:26 -04001748 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
Jouni Malinencc659652009-05-14 21:28:48 +03001749
Vasanthakumar Thiagarajan102885a2010-09-02 01:34:43 -07001750 if (ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)
1751 ath_ant_comb_scan(sc, &rs);
1752
Felix Fietkau7545daf2011-01-24 19:23:16 +01001753 ieee80211_rx(hw, skb);
Jouni Malinencc659652009-05-14 21:28:48 +03001754
Felix Fietkau0d955212011-01-26 18:23:27 +01001755requeue_drop_frag:
1756 if (sc->rx.frag) {
1757 dev_kfree_skb_any(sc->rx.frag);
1758 sc->rx.frag = NULL;
1759 }
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);
Felix Fietkau95294972011-04-07 19:30:32 +02001767 ath9k_hw_rxena(ah);
Felix Fietkaub5c804752010-04-15 17:38:48 -04001768 }
Sujithbe0418a2008-11-18 09:05:55 +05301769 } while (1);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001770
Sujithb77f4832008-12-07 21:44:03 +05301771 spin_unlock_bh(&sc->rx.rxbuflock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001772
1773 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001774}