blob: 916b3409a0e8dca6fb4bc7beff7bd05a3b90eb5c [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;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700486 bool stopped;
487
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);
491 stopped = ath9k_hw_stopdmarecv(ah);
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 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700506 return stopped;
507}
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);
Jouni Malinenccdfeab2009-05-20 21:59:08 +0300575 }
576
Jouni Malinencc659652009-05-14 21:28:48 +0300577 if (ath_beacon_dtim_pending_cab(skb)) {
578 /*
579 * Remain awake waiting for buffered broadcast/multicast
Gabor Juhos58f5fff2009-06-17 20:53:20 +0200580 * frames. If the last broadcast/multicast frame is not
581 * received properly, the next beacon frame will work as
582 * a backup trigger for returning into NETWORK SLEEP state,
583 * so we are waiting for it as well.
Jouni Malinencc659652009-05-14 21:28:48 +0300584 */
Joe Perches226afe62010-12-02 19:12:37 -0800585 ath_dbg(common, ATH_DBG_PS,
586 "Received DTIM beacon indicating buffered broadcast/multicast frame(s)\n");
Sujith1b04b932010-01-08 10:36:05 +0530587 sc->ps_flags |= PS_WAIT_FOR_CAB | PS_WAIT_FOR_BEACON;
Jouni Malinencc659652009-05-14 21:28:48 +0300588 return;
589 }
590
Sujith1b04b932010-01-08 10:36:05 +0530591 if (sc->ps_flags & PS_WAIT_FOR_CAB) {
Jouni Malinencc659652009-05-14 21:28:48 +0300592 /*
593 * This can happen if a broadcast frame is dropped or the AP
594 * fails to send a frame indicating that all CAB frames have
595 * been delivered.
596 */
Sujith1b04b932010-01-08 10:36:05 +0530597 sc->ps_flags &= ~PS_WAIT_FOR_CAB;
Joe Perches226afe62010-12-02 19:12:37 -0800598 ath_dbg(common, ATH_DBG_PS,
599 "PS wait for CAB frames timed out\n");
Jouni Malinencc659652009-05-14 21:28:48 +0300600 }
Jouni Malinencc659652009-05-14 21:28:48 +0300601}
602
603static void ath_rx_ps(struct ath_softc *sc, struct sk_buff *skb)
604{
605 struct ieee80211_hdr *hdr;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700606 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Jouni Malinencc659652009-05-14 21:28:48 +0300607
608 hdr = (struct ieee80211_hdr *)skb->data;
609
610 /* Process Beacon and CAB receive in PS state */
Vasanthakumar Thiagarajanededf1f2010-05-22 23:58:13 -0700611 if (((sc->ps_flags & PS_WAIT_FOR_BEACON) || ath9k_check_auto_sleep(sc))
612 && ieee80211_is_beacon(hdr->frame_control))
Jouni Malinencc659652009-05-14 21:28:48 +0300613 ath_rx_ps_beacon(sc, skb);
Sujith1b04b932010-01-08 10:36:05 +0530614 else if ((sc->ps_flags & PS_WAIT_FOR_CAB) &&
Jouni Malinencc659652009-05-14 21:28:48 +0300615 (ieee80211_is_data(hdr->frame_control) ||
616 ieee80211_is_action(hdr->frame_control)) &&
617 is_multicast_ether_addr(hdr->addr1) &&
618 !ieee80211_has_moredata(hdr->frame_control)) {
Jouni Malinencc659652009-05-14 21:28:48 +0300619 /*
620 * No more broadcast/multicast frames to be received at this
621 * point.
622 */
Senthil Balasubramanian3fac6df2010-09-16 15:12:35 -0400623 sc->ps_flags &= ~(PS_WAIT_FOR_CAB | PS_WAIT_FOR_BEACON);
Joe Perches226afe62010-12-02 19:12:37 -0800624 ath_dbg(common, ATH_DBG_PS,
625 "All PS CAB frames received, back to sleep\n");
Sujith1b04b932010-01-08 10:36:05 +0530626 } else if ((sc->ps_flags & PS_WAIT_FOR_PSPOLL_DATA) &&
Jouni Malinen9a23f9c2009-05-19 17:01:38 +0300627 !is_multicast_ether_addr(hdr->addr1) &&
628 !ieee80211_has_morefrags(hdr->frame_control)) {
Sujith1b04b932010-01-08 10:36:05 +0530629 sc->ps_flags &= ~PS_WAIT_FOR_PSPOLL_DATA;
Joe Perches226afe62010-12-02 19:12:37 -0800630 ath_dbg(common, ATH_DBG_PS,
631 "Going back to sleep after having received PS-Poll data (0x%lx)\n",
Sujith1b04b932010-01-08 10:36:05 +0530632 sc->ps_flags & (PS_WAIT_FOR_BEACON |
633 PS_WAIT_FOR_CAB |
634 PS_WAIT_FOR_PSPOLL_DATA |
635 PS_WAIT_FOR_TX_ACK));
Jouni Malinencc659652009-05-14 21:28:48 +0300636 }
637}
638
Felix Fietkaub5c804752010-04-15 17:38:48 -0400639static bool ath_edma_get_buffers(struct ath_softc *sc,
640 enum ath9k_rx_qtype qtype)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700641{
Felix Fietkaub5c804752010-04-15 17:38:48 -0400642 struct ath_rx_edma *rx_edma = &sc->rx.rx_edma[qtype];
643 struct ath_hw *ah = sc->sc_ah;
644 struct ath_common *common = ath9k_hw_common(ah);
645 struct sk_buff *skb;
Sujithbe0418a2008-11-18 09:05:55 +0530646 struct ath_buf *bf;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400647 int ret;
648
649 skb = skb_peek(&rx_edma->rx_fifo);
650 if (!skb)
651 return false;
652
653 bf = SKB_CB_ATHBUF(skb);
654 BUG_ON(!bf);
655
Ming Leice9426d2010-05-15 18:25:40 +0800656 dma_sync_single_for_cpu(sc->dev, bf->bf_buf_addr,
Felix Fietkaub5c804752010-04-15 17:38:48 -0400657 common->rx_bufsize, DMA_FROM_DEVICE);
658
659 ret = ath9k_hw_process_rxdesc_edma(ah, NULL, skb->data);
Ming Leice9426d2010-05-15 18:25:40 +0800660 if (ret == -EINPROGRESS) {
661 /*let device gain the buffer again*/
662 dma_sync_single_for_device(sc->dev, bf->bf_buf_addr,
663 common->rx_bufsize, DMA_FROM_DEVICE);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400664 return false;
Ming Leice9426d2010-05-15 18:25:40 +0800665 }
Felix Fietkaub5c804752010-04-15 17:38:48 -0400666
667 __skb_unlink(skb, &rx_edma->rx_fifo);
668 if (ret == -EINVAL) {
669 /* corrupt descriptor, skip this one and the following one */
670 list_add_tail(&bf->list, &sc->rx.rxbuf);
671 ath_rx_edma_buf_link(sc, qtype);
672 skb = skb_peek(&rx_edma->rx_fifo);
673 if (!skb)
674 return true;
675
676 bf = SKB_CB_ATHBUF(skb);
677 BUG_ON(!bf);
678
679 __skb_unlink(skb, &rx_edma->rx_fifo);
680 list_add_tail(&bf->list, &sc->rx.rxbuf);
681 ath_rx_edma_buf_link(sc, qtype);
Vasanthakumar Thiagarajan083e3e82010-05-10 19:41:34 -0700682 return true;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400683 }
684 skb_queue_tail(&rx_edma->rx_buffers, skb);
685
686 return true;
687}
688
689static struct ath_buf *ath_edma_get_next_rx_buf(struct ath_softc *sc,
690 struct ath_rx_status *rs,
691 enum ath9k_rx_qtype qtype)
692{
693 struct ath_rx_edma *rx_edma = &sc->rx.rx_edma[qtype];
694 struct sk_buff *skb;
695 struct ath_buf *bf;
696
697 while (ath_edma_get_buffers(sc, qtype));
698 skb = __skb_dequeue(&rx_edma->rx_buffers);
699 if (!skb)
700 return NULL;
701
702 bf = SKB_CB_ATHBUF(skb);
703 ath9k_hw_process_rxdesc_edma(sc->sc_ah, rs, skb->data);
704 return bf;
705}
706
707static struct ath_buf *ath_get_next_rx_buf(struct ath_softc *sc,
708 struct ath_rx_status *rs)
709{
710 struct ath_hw *ah = sc->sc_ah;
711 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700712 struct ath_desc *ds;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400713 struct ath_buf *bf;
714 int ret;
715
716 if (list_empty(&sc->rx.rxbuf)) {
717 sc->rx.rxlink = NULL;
718 return NULL;
719 }
720
721 bf = list_first_entry(&sc->rx.rxbuf, struct ath_buf, list);
722 ds = bf->bf_desc;
723
724 /*
725 * Must provide the virtual address of the current
726 * descriptor, the physical address, and the virtual
727 * address of the next descriptor in the h/w chain.
728 * This allows the HAL to look ahead to see if the
729 * hardware is done with a descriptor by checking the
730 * done bit in the following descriptor and the address
731 * of the current descriptor the DMA engine is working
732 * on. All this is necessary because of our use of
733 * a self-linked list to avoid rx overruns.
734 */
735 ret = ath9k_hw_rxprocdesc(ah, ds, rs, 0);
736 if (ret == -EINPROGRESS) {
737 struct ath_rx_status trs;
738 struct ath_buf *tbf;
739 struct ath_desc *tds;
740
741 memset(&trs, 0, sizeof(trs));
742 if (list_is_last(&bf->list, &sc->rx.rxbuf)) {
743 sc->rx.rxlink = NULL;
744 return NULL;
745 }
746
747 tbf = list_entry(bf->list.next, struct ath_buf, list);
748
749 /*
750 * On some hardware the descriptor status words could
751 * get corrupted, including the done bit. Because of
752 * this, check if the next descriptor's done bit is
753 * set or not.
754 *
755 * If the next descriptor's done bit is set, the current
756 * descriptor has been corrupted. Force s/w to discard
757 * this descriptor and continue...
758 */
759
760 tds = tbf->bf_desc;
761 ret = ath9k_hw_rxprocdesc(ah, tds, &trs, 0);
762 if (ret == -EINPROGRESS)
763 return NULL;
764 }
765
766 if (!bf->bf_mpdu)
767 return bf;
768
769 /*
770 * Synchronize the DMA transfer with CPU before
771 * 1. accessing the frame
772 * 2. requeueing the same buffer to h/w
773 */
Ming Leice9426d2010-05-15 18:25:40 +0800774 dma_sync_single_for_cpu(sc->dev, bf->bf_buf_addr,
Felix Fietkaub5c804752010-04-15 17:38:48 -0400775 common->rx_bufsize,
776 DMA_FROM_DEVICE);
777
778 return bf;
779}
780
Sujithd4357002010-05-20 15:34:38 +0530781/* Assumes you've already done the endian to CPU conversion */
782static bool ath9k_rx_accept(struct ath_common *common,
Vasanthakumar Thiagarajan9f167f62010-05-20 14:34:46 -0700783 struct ieee80211_hdr *hdr,
Sujithd4357002010-05-20 15:34:38 +0530784 struct ieee80211_rx_status *rxs,
785 struct ath_rx_status *rx_stats,
786 bool *decrypt_error)
787{
Senthil Balasubramanian38852b22010-12-06 19:09:27 +0530788#define is_mc_or_valid_tkip_keyix ((is_mc || \
789 (rx_stats->rs_keyix != ATH9K_RXKEYIX_INVALID && \
790 test_bit(rx_stats->rs_keyix, common->tkip_keymap))))
791
Sujithd4357002010-05-20 15:34:38 +0530792 struct ath_hw *ah = common->ah;
Sujithd4357002010-05-20 15:34:38 +0530793 __le16 fc;
Vasanthakumar Thiagarajanb7b1b512010-05-20 14:34:48 -0700794 u8 rx_status_len = ah->caps.rx_status_len;
Sujithd4357002010-05-20 15:34:38 +0530795
Sujithd4357002010-05-20 15:34:38 +0530796 fc = hdr->frame_control;
797
798 if (!rx_stats->rs_datalen)
799 return false;
800 /*
801 * rs_status follows rs_datalen so if rs_datalen is too large
802 * we can take a hint that hardware corrupted it, so ignore
803 * those frames.
804 */
Vasanthakumar Thiagarajanb7b1b512010-05-20 14:34:48 -0700805 if (rx_stats->rs_datalen > (common->rx_bufsize - rx_status_len))
Sujithd4357002010-05-20 15:34:38 +0530806 return false;
807
Felix Fietkau0d955212011-01-26 18:23:27 +0100808 /* Only use error bits from the last fragment */
Sujithd4357002010-05-20 15:34:38 +0530809 if (rx_stats->rs_more)
Felix Fietkau0d955212011-01-26 18:23:27 +0100810 return true;
Sujithd4357002010-05-20 15:34:38 +0530811
812 /*
813 * The rx_stats->rs_status will not be set until the end of the
814 * chained descriptors so it can be ignored if rs_more is set. The
815 * rs_more will be false at the last element of the chained
816 * descriptors.
817 */
818 if (rx_stats->rs_status != 0) {
819 if (rx_stats->rs_status & ATH9K_RXERR_CRC)
820 rxs->flag |= RX_FLAG_FAILED_FCS_CRC;
821 if (rx_stats->rs_status & ATH9K_RXERR_PHY)
822 return false;
823
824 if (rx_stats->rs_status & ATH9K_RXERR_DECRYPT) {
825 *decrypt_error = true;
826 } else if (rx_stats->rs_status & ATH9K_RXERR_MIC) {
Senthil Balasubramanian38852b22010-12-06 19:09:27 +0530827 bool is_mc;
Felix Fietkau56363dd2010-08-28 18:21:21 +0200828 /*
829 * The MIC error bit is only valid if the frame
830 * is not a control frame or fragment, and it was
831 * decrypted using a valid TKIP key.
832 */
Senthil Balasubramanian38852b22010-12-06 19:09:27 +0530833 is_mc = !!is_multicast_ether_addr(hdr->addr1);
834
Felix Fietkau56363dd2010-08-28 18:21:21 +0200835 if (!ieee80211_is_ctl(fc) &&
836 !ieee80211_has_morefrags(fc) &&
837 !(le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG) &&
Senthil Balasubramanian38852b22010-12-06 19:09:27 +0530838 is_mc_or_valid_tkip_keyix)
Sujithd4357002010-05-20 15:34:38 +0530839 rxs->flag |= RX_FLAG_MMIC_ERROR;
Felix Fietkau56363dd2010-08-28 18:21:21 +0200840 else
841 rx_stats->rs_status &= ~ATH9K_RXERR_MIC;
Sujithd4357002010-05-20 15:34:38 +0530842 }
843 /*
844 * Reject error frames with the exception of
845 * decryption and MIC failures. For monitor mode,
846 * we also ignore the CRC error.
847 */
Rajkumar Manoharan5f841b42010-10-27 18:31:15 +0530848 if (ah->is_monitoring) {
Sujithd4357002010-05-20 15:34:38 +0530849 if (rx_stats->rs_status &
850 ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC |
851 ATH9K_RXERR_CRC))
852 return false;
853 } else {
854 if (rx_stats->rs_status &
855 ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC)) {
856 return false;
857 }
858 }
859 }
860 return true;
861}
862
863static int ath9k_process_rate(struct ath_common *common,
864 struct ieee80211_hw *hw,
865 struct ath_rx_status *rx_stats,
Vasanthakumar Thiagarajan9f167f62010-05-20 14:34:46 -0700866 struct ieee80211_rx_status *rxs)
Sujithd4357002010-05-20 15:34:38 +0530867{
868 struct ieee80211_supported_band *sband;
869 enum ieee80211_band band;
870 unsigned int i = 0;
871
872 band = hw->conf.channel->band;
873 sband = hw->wiphy->bands[band];
874
875 if (rx_stats->rs_rate & 0x80) {
876 /* HT rate */
877 rxs->flag |= RX_FLAG_HT;
878 if (rx_stats->rs_flags & ATH9K_RX_2040)
879 rxs->flag |= RX_FLAG_40MHZ;
880 if (rx_stats->rs_flags & ATH9K_RX_GI)
881 rxs->flag |= RX_FLAG_SHORT_GI;
882 rxs->rate_idx = rx_stats->rs_rate & 0x7f;
883 return 0;
884 }
885
886 for (i = 0; i < sband->n_bitrates; i++) {
887 if (sband->bitrates[i].hw_value == rx_stats->rs_rate) {
888 rxs->rate_idx = i;
889 return 0;
890 }
891 if (sband->bitrates[i].hw_value_short == rx_stats->rs_rate) {
892 rxs->flag |= RX_FLAG_SHORTPRE;
893 rxs->rate_idx = i;
894 return 0;
895 }
896 }
897
898 /*
899 * No valid hardware bitrate found -- we should not get here
900 * because hardware has already validated this frame as OK.
901 */
Joe Perches226afe62010-12-02 19:12:37 -0800902 ath_dbg(common, ATH_DBG_XMIT,
903 "unsupported hw bitrate detected 0x%02x using 1 Mbit\n",
904 rx_stats->rs_rate);
Sujithd4357002010-05-20 15:34:38 +0530905
906 return -EINVAL;
907}
908
909static void ath9k_process_rssi(struct ath_common *common,
910 struct ieee80211_hw *hw,
Vasanthakumar Thiagarajan9f167f62010-05-20 14:34:46 -0700911 struct ieee80211_hdr *hdr,
Sujithd4357002010-05-20 15:34:38 +0530912 struct ath_rx_status *rx_stats)
913{
Felix Fietkau9ac58612011-01-24 19:23:18 +0100914 struct ath_softc *sc = hw->priv;
Sujithd4357002010-05-20 15:34:38 +0530915 struct ath_hw *ah = common->ah;
Felix Fietkau9fa23e12010-10-15 20:03:31 +0200916 int last_rssi;
Sujithd4357002010-05-20 15:34:38 +0530917 __le16 fc;
918
Felix Fietkau9fa23e12010-10-15 20:03:31 +0200919 if (ah->opmode != NL80211_IFTYPE_STATION)
920 return;
921
Sujithd4357002010-05-20 15:34:38 +0530922 fc = hdr->frame_control;
Felix Fietkau9fa23e12010-10-15 20:03:31 +0200923 if (!ieee80211_is_beacon(fc) ||
Ben Greear48014162011-01-15 19:13:48 +0000924 compare_ether_addr(hdr->addr3, common->curbssid)) {
925 /* TODO: This doesn't work well if you have stations
926 * associated to two different APs because curbssid
927 * is just the last AP that any of the stations associated
928 * with.
929 */
Felix Fietkau9fa23e12010-10-15 20:03:31 +0200930 return;
Ben Greear48014162011-01-15 19:13:48 +0000931 }
Sujithd4357002010-05-20 15:34:38 +0530932
Felix Fietkau9fa23e12010-10-15 20:03:31 +0200933 if (rx_stats->rs_rssi != ATH9K_RSSI_BAD && !rx_stats->rs_moreaggr)
Felix Fietkau9ac58612011-01-24 19:23:18 +0100934 ATH_RSSI_LPF(sc->last_rssi, rx_stats->rs_rssi);
Ben Greear686b9cb2010-09-23 09:44:36 -0700935
Felix Fietkau9ac58612011-01-24 19:23:18 +0100936 last_rssi = sc->last_rssi;
Sujithd4357002010-05-20 15:34:38 +0530937 if (likely(last_rssi != ATH_RSSI_DUMMY_MARKER))
938 rx_stats->rs_rssi = ATH_EP_RND(last_rssi,
939 ATH_RSSI_EP_MULTIPLIER);
940 if (rx_stats->rs_rssi < 0)
941 rx_stats->rs_rssi = 0;
942
943 /* Update Beacon RSSI, this is used by ANI. */
Felix Fietkau9fa23e12010-10-15 20:03:31 +0200944 ah->stats.avgbrssi = rx_stats->rs_rssi;
Sujithd4357002010-05-20 15:34:38 +0530945}
946
947/*
948 * For Decrypt or Demic errors, we only mark packet status here and always push
949 * up the frame up to let mac80211 handle the actual error case, be it no
950 * decryption key or real decryption error. This let us keep statistics there.
951 */
952static int ath9k_rx_skb_preprocess(struct ath_common *common,
953 struct ieee80211_hw *hw,
Vasanthakumar Thiagarajan9f167f62010-05-20 14:34:46 -0700954 struct ieee80211_hdr *hdr,
Sujithd4357002010-05-20 15:34:38 +0530955 struct ath_rx_status *rx_stats,
956 struct ieee80211_rx_status *rx_status,
957 bool *decrypt_error)
958{
Sujithd4357002010-05-20 15:34:38 +0530959 memset(rx_status, 0, sizeof(struct ieee80211_rx_status));
960
961 /*
962 * everything but the rate is checked here, the rate check is done
963 * separately to avoid doing two lookups for a rate for each frame.
964 */
Vasanthakumar Thiagarajan9f167f62010-05-20 14:34:46 -0700965 if (!ath9k_rx_accept(common, hdr, rx_status, rx_stats, decrypt_error))
Sujithd4357002010-05-20 15:34:38 +0530966 return -EINVAL;
967
Felix Fietkau0d955212011-01-26 18:23:27 +0100968 /* Only use status info from the last fragment */
969 if (rx_stats->rs_more)
970 return 0;
971
Vasanthakumar Thiagarajan9f167f62010-05-20 14:34:46 -0700972 ath9k_process_rssi(common, hw, hdr, rx_stats);
Sujithd4357002010-05-20 15:34:38 +0530973
Vasanthakumar Thiagarajan9f167f62010-05-20 14:34:46 -0700974 if (ath9k_process_rate(common, hw, rx_stats, rx_status))
Sujithd4357002010-05-20 15:34:38 +0530975 return -EINVAL;
976
Sujithd4357002010-05-20 15:34:38 +0530977 rx_status->band = hw->conf.channel->band;
978 rx_status->freq = hw->conf.channel->center_freq;
979 rx_status->signal = ATH_DEFAULT_NOISE_FLOOR + rx_stats->rs_rssi;
980 rx_status->antenna = rx_stats->rs_antenna;
Johannes Berg6ebacbb2011-02-23 15:06:08 +0100981 rx_status->flag |= RX_FLAG_MACTIME_MPDU;
Sujithd4357002010-05-20 15:34:38 +0530982
983 return 0;
984}
985
986static void ath9k_rx_skb_postprocess(struct ath_common *common,
987 struct sk_buff *skb,
988 struct ath_rx_status *rx_stats,
989 struct ieee80211_rx_status *rxs,
990 bool decrypt_error)
991{
992 struct ath_hw *ah = common->ah;
993 struct ieee80211_hdr *hdr;
994 int hdrlen, padpos, padsize;
995 u8 keyix;
996 __le16 fc;
997
998 /* see if any padding is done by the hw and remove it */
999 hdr = (struct ieee80211_hdr *) skb->data;
1000 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
1001 fc = hdr->frame_control;
1002 padpos = ath9k_cmn_padpos(hdr->frame_control);
1003
1004 /* The MAC header is padded to have 32-bit boundary if the
1005 * packet payload is non-zero. The general calculation for
1006 * padsize would take into account odd header lengths:
1007 * padsize = (4 - padpos % 4) % 4; However, since only
1008 * even-length headers are used, padding can only be 0 or 2
1009 * bytes and we can optimize this a bit. In addition, we must
1010 * not try to remove padding from short control frames that do
1011 * not have payload. */
1012 padsize = padpos & 3;
1013 if (padsize && skb->len>=padpos+padsize+FCS_LEN) {
1014 memmove(skb->data + padsize, skb->data, padpos);
1015 skb_pull(skb, padsize);
1016 }
1017
1018 keyix = rx_stats->rs_keyix;
1019
1020 if (!(keyix == ATH9K_RXKEYIX_INVALID) && !decrypt_error &&
1021 ieee80211_has_protected(fc)) {
1022 rxs->flag |= RX_FLAG_DECRYPTED;
1023 } else if (ieee80211_has_protected(fc)
1024 && !decrypt_error && skb->len >= hdrlen + 4) {
1025 keyix = skb->data[hdrlen + 3] >> 6;
1026
1027 if (test_bit(keyix, common->keymap))
1028 rxs->flag |= RX_FLAG_DECRYPTED;
1029 }
1030 if (ah->sw_mgmt_crypto &&
1031 (rxs->flag & RX_FLAG_DECRYPTED) &&
1032 ieee80211_is_mgmt(fc))
1033 /* Use software decrypt for management frames. */
1034 rxs->flag &= ~RX_FLAG_DECRYPTED;
1035}
Felix Fietkaub5c804752010-04-15 17:38:48 -04001036
Vasanthakumar Thiagarajan102885a2010-09-02 01:34:43 -07001037static void ath_lnaconf_alt_good_scan(struct ath_ant_comb *antcomb,
1038 struct ath_hw_antcomb_conf ant_conf,
1039 int main_rssi_avg)
1040{
1041 antcomb->quick_scan_cnt = 0;
1042
1043 if (ant_conf.main_lna_conf == ATH_ANT_DIV_COMB_LNA2)
1044 antcomb->rssi_lna2 = main_rssi_avg;
1045 else if (ant_conf.main_lna_conf == ATH_ANT_DIV_COMB_LNA1)
1046 antcomb->rssi_lna1 = main_rssi_avg;
1047
1048 switch ((ant_conf.main_lna_conf << 4) | ant_conf.alt_lna_conf) {
1049 case (0x10): /* LNA2 A-B */
1050 antcomb->main_conf = ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1051 antcomb->first_quick_scan_conf =
1052 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1053 antcomb->second_quick_scan_conf = ATH_ANT_DIV_COMB_LNA1;
1054 break;
1055 case (0x20): /* LNA1 A-B */
1056 antcomb->main_conf = ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1057 antcomb->first_quick_scan_conf =
1058 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1059 antcomb->second_quick_scan_conf = ATH_ANT_DIV_COMB_LNA2;
1060 break;
1061 case (0x21): /* LNA1 LNA2 */
1062 antcomb->main_conf = ATH_ANT_DIV_COMB_LNA2;
1063 antcomb->first_quick_scan_conf =
1064 ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1065 antcomb->second_quick_scan_conf =
1066 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1067 break;
1068 case (0x12): /* LNA2 LNA1 */
1069 antcomb->main_conf = ATH_ANT_DIV_COMB_LNA1;
1070 antcomb->first_quick_scan_conf =
1071 ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1072 antcomb->second_quick_scan_conf =
1073 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1074 break;
1075 case (0x13): /* LNA2 A+B */
1076 antcomb->main_conf = ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1077 antcomb->first_quick_scan_conf =
1078 ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1079 antcomb->second_quick_scan_conf = ATH_ANT_DIV_COMB_LNA1;
1080 break;
1081 case (0x23): /* LNA1 A+B */
1082 antcomb->main_conf = ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1083 antcomb->first_quick_scan_conf =
1084 ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1085 antcomb->second_quick_scan_conf = ATH_ANT_DIV_COMB_LNA2;
1086 break;
1087 default:
1088 break;
1089 }
1090}
1091
1092static void ath_select_ant_div_from_quick_scan(struct ath_ant_comb *antcomb,
1093 struct ath_hw_antcomb_conf *div_ant_conf,
1094 int main_rssi_avg, int alt_rssi_avg,
1095 int alt_ratio)
1096{
1097 /* alt_good */
1098 switch (antcomb->quick_scan_cnt) {
1099 case 0:
1100 /* set alt to main, and alt to first conf */
1101 div_ant_conf->main_lna_conf = antcomb->main_conf;
1102 div_ant_conf->alt_lna_conf = antcomb->first_quick_scan_conf;
1103 break;
1104 case 1:
1105 /* set alt to main, and alt to first conf */
1106 div_ant_conf->main_lna_conf = antcomb->main_conf;
1107 div_ant_conf->alt_lna_conf = antcomb->second_quick_scan_conf;
1108 antcomb->rssi_first = main_rssi_avg;
1109 antcomb->rssi_second = alt_rssi_avg;
1110
1111 if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA1) {
1112 /* main is LNA1 */
1113 if (ath_is_alt_ant_ratio_better(alt_ratio,
1114 ATH_ANT_DIV_COMB_LNA1_DELTA_HI,
1115 ATH_ANT_DIV_COMB_LNA1_DELTA_LOW,
1116 main_rssi_avg, alt_rssi_avg,
1117 antcomb->total_pkt_count))
1118 antcomb->first_ratio = true;
1119 else
1120 antcomb->first_ratio = false;
1121 } else if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA2) {
1122 if (ath_is_alt_ant_ratio_better(alt_ratio,
1123 ATH_ANT_DIV_COMB_LNA1_DELTA_MID,
1124 ATH_ANT_DIV_COMB_LNA1_DELTA_LOW,
1125 main_rssi_avg, alt_rssi_avg,
1126 antcomb->total_pkt_count))
1127 antcomb->first_ratio = true;
1128 else
1129 antcomb->first_ratio = false;
1130 } else {
1131 if ((((alt_ratio >= ATH_ANT_DIV_COMB_ALT_ANT_RATIO2) &&
1132 (alt_rssi_avg > main_rssi_avg +
1133 ATH_ANT_DIV_COMB_LNA1_DELTA_HI)) ||
1134 (alt_rssi_avg > main_rssi_avg)) &&
1135 (antcomb->total_pkt_count > 50))
1136 antcomb->first_ratio = true;
1137 else
1138 antcomb->first_ratio = false;
1139 }
1140 break;
1141 case 2:
1142 antcomb->alt_good = false;
1143 antcomb->scan_not_start = false;
1144 antcomb->scan = false;
1145 antcomb->rssi_first = main_rssi_avg;
1146 antcomb->rssi_third = alt_rssi_avg;
1147
1148 if (antcomb->second_quick_scan_conf == ATH_ANT_DIV_COMB_LNA1)
1149 antcomb->rssi_lna1 = alt_rssi_avg;
1150 else if (antcomb->second_quick_scan_conf ==
1151 ATH_ANT_DIV_COMB_LNA2)
1152 antcomb->rssi_lna2 = alt_rssi_avg;
1153 else if (antcomb->second_quick_scan_conf ==
1154 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2) {
1155 if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA2)
1156 antcomb->rssi_lna2 = main_rssi_avg;
1157 else if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA1)
1158 antcomb->rssi_lna1 = main_rssi_avg;
1159 }
1160
1161 if (antcomb->rssi_lna2 > antcomb->rssi_lna1 +
1162 ATH_ANT_DIV_COMB_LNA1_LNA2_SWITCH_DELTA)
1163 div_ant_conf->main_lna_conf = ATH_ANT_DIV_COMB_LNA2;
1164 else
1165 div_ant_conf->main_lna_conf = ATH_ANT_DIV_COMB_LNA1;
1166
1167 if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA1) {
1168 if (ath_is_alt_ant_ratio_better(alt_ratio,
1169 ATH_ANT_DIV_COMB_LNA1_DELTA_HI,
1170 ATH_ANT_DIV_COMB_LNA1_DELTA_LOW,
1171 main_rssi_avg, alt_rssi_avg,
1172 antcomb->total_pkt_count))
1173 antcomb->second_ratio = true;
1174 else
1175 antcomb->second_ratio = false;
1176 } else if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA2) {
1177 if (ath_is_alt_ant_ratio_better(alt_ratio,
1178 ATH_ANT_DIV_COMB_LNA1_DELTA_MID,
1179 ATH_ANT_DIV_COMB_LNA1_DELTA_LOW,
1180 main_rssi_avg, alt_rssi_avg,
1181 antcomb->total_pkt_count))
1182 antcomb->second_ratio = true;
1183 else
1184 antcomb->second_ratio = false;
1185 } else {
1186 if ((((alt_ratio >= ATH_ANT_DIV_COMB_ALT_ANT_RATIO2) &&
1187 (alt_rssi_avg > main_rssi_avg +
1188 ATH_ANT_DIV_COMB_LNA1_DELTA_HI)) ||
1189 (alt_rssi_avg > main_rssi_avg)) &&
1190 (antcomb->total_pkt_count > 50))
1191 antcomb->second_ratio = true;
1192 else
1193 antcomb->second_ratio = false;
1194 }
1195
1196 /* set alt to the conf with maximun ratio */
1197 if (antcomb->first_ratio && antcomb->second_ratio) {
1198 if (antcomb->rssi_second > antcomb->rssi_third) {
1199 /* first alt*/
1200 if ((antcomb->first_quick_scan_conf ==
1201 ATH_ANT_DIV_COMB_LNA1) ||
1202 (antcomb->first_quick_scan_conf ==
1203 ATH_ANT_DIV_COMB_LNA2))
1204 /* Set alt LNA1 or LNA2*/
1205 if (div_ant_conf->main_lna_conf ==
1206 ATH_ANT_DIV_COMB_LNA2)
1207 div_ant_conf->alt_lna_conf =
1208 ATH_ANT_DIV_COMB_LNA1;
1209 else
1210 div_ant_conf->alt_lna_conf =
1211 ATH_ANT_DIV_COMB_LNA2;
1212 else
1213 /* Set alt to A+B or A-B */
1214 div_ant_conf->alt_lna_conf =
1215 antcomb->first_quick_scan_conf;
1216 } else if ((antcomb->second_quick_scan_conf ==
1217 ATH_ANT_DIV_COMB_LNA1) ||
1218 (antcomb->second_quick_scan_conf ==
1219 ATH_ANT_DIV_COMB_LNA2)) {
1220 /* Set alt LNA1 or LNA2 */
1221 if (div_ant_conf->main_lna_conf ==
1222 ATH_ANT_DIV_COMB_LNA2)
1223 div_ant_conf->alt_lna_conf =
1224 ATH_ANT_DIV_COMB_LNA1;
1225 else
1226 div_ant_conf->alt_lna_conf =
1227 ATH_ANT_DIV_COMB_LNA2;
1228 } else {
1229 /* Set alt to A+B or A-B */
1230 div_ant_conf->alt_lna_conf =
1231 antcomb->second_quick_scan_conf;
1232 }
1233 } else if (antcomb->first_ratio) {
1234 /* first alt */
1235 if ((antcomb->first_quick_scan_conf ==
1236 ATH_ANT_DIV_COMB_LNA1) ||
1237 (antcomb->first_quick_scan_conf ==
1238 ATH_ANT_DIV_COMB_LNA2))
1239 /* Set alt LNA1 or LNA2 */
1240 if (div_ant_conf->main_lna_conf ==
1241 ATH_ANT_DIV_COMB_LNA2)
1242 div_ant_conf->alt_lna_conf =
1243 ATH_ANT_DIV_COMB_LNA1;
1244 else
1245 div_ant_conf->alt_lna_conf =
1246 ATH_ANT_DIV_COMB_LNA2;
1247 else
1248 /* Set alt to A+B or A-B */
1249 div_ant_conf->alt_lna_conf =
1250 antcomb->first_quick_scan_conf;
1251 } else if (antcomb->second_ratio) {
1252 /* second alt */
1253 if ((antcomb->second_quick_scan_conf ==
1254 ATH_ANT_DIV_COMB_LNA1) ||
1255 (antcomb->second_quick_scan_conf ==
1256 ATH_ANT_DIV_COMB_LNA2))
1257 /* Set alt LNA1 or LNA2 */
1258 if (div_ant_conf->main_lna_conf ==
1259 ATH_ANT_DIV_COMB_LNA2)
1260 div_ant_conf->alt_lna_conf =
1261 ATH_ANT_DIV_COMB_LNA1;
1262 else
1263 div_ant_conf->alt_lna_conf =
1264 ATH_ANT_DIV_COMB_LNA2;
1265 else
1266 /* Set alt to A+B or A-B */
1267 div_ant_conf->alt_lna_conf =
1268 antcomb->second_quick_scan_conf;
1269 } else {
1270 /* main is largest */
1271 if ((antcomb->main_conf == ATH_ANT_DIV_COMB_LNA1) ||
1272 (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA2))
1273 /* Set alt LNA1 or LNA2 */
1274 if (div_ant_conf->main_lna_conf ==
1275 ATH_ANT_DIV_COMB_LNA2)
1276 div_ant_conf->alt_lna_conf =
1277 ATH_ANT_DIV_COMB_LNA1;
1278 else
1279 div_ant_conf->alt_lna_conf =
1280 ATH_ANT_DIV_COMB_LNA2;
1281 else
1282 /* Set alt to A+B or A-B */
1283 div_ant_conf->alt_lna_conf = antcomb->main_conf;
1284 }
1285 break;
1286 default:
1287 break;
1288 }
1289}
1290
John W. Linville9bad82b2010-09-15 15:26:13 -04001291static void ath_ant_div_conf_fast_divbias(struct ath_hw_antcomb_conf *ant_conf)
Vasanthakumar Thiagarajan102885a2010-09-02 01:34:43 -07001292{
1293 /* Adjust the fast_div_bias based on main and alt lna conf */
1294 switch ((ant_conf->main_lna_conf << 4) | ant_conf->alt_lna_conf) {
1295 case (0x01): /* A-B LNA2 */
1296 ant_conf->fast_div_bias = 0x3b;
1297 break;
1298 case (0x02): /* A-B LNA1 */
1299 ant_conf->fast_div_bias = 0x3d;
1300 break;
1301 case (0x03): /* A-B A+B */
1302 ant_conf->fast_div_bias = 0x1;
1303 break;
1304 case (0x10): /* LNA2 A-B */
1305 ant_conf->fast_div_bias = 0x7;
1306 break;
1307 case (0x12): /* LNA2 LNA1 */
1308 ant_conf->fast_div_bias = 0x2;
1309 break;
1310 case (0x13): /* LNA2 A+B */
1311 ant_conf->fast_div_bias = 0x7;
1312 break;
1313 case (0x20): /* LNA1 A-B */
1314 ant_conf->fast_div_bias = 0x6;
1315 break;
1316 case (0x21): /* LNA1 LNA2 */
1317 ant_conf->fast_div_bias = 0x0;
1318 break;
1319 case (0x23): /* LNA1 A+B */
1320 ant_conf->fast_div_bias = 0x6;
1321 break;
1322 case (0x30): /* A+B A-B */
1323 ant_conf->fast_div_bias = 0x1;
1324 break;
1325 case (0x31): /* A+B LNA2 */
1326 ant_conf->fast_div_bias = 0x3b;
1327 break;
1328 case (0x32): /* A+B LNA1 */
1329 ant_conf->fast_div_bias = 0x3d;
1330 break;
1331 default:
1332 break;
1333 }
1334}
1335
1336/* Antenna diversity and combining */
1337static void ath_ant_comb_scan(struct ath_softc *sc, struct ath_rx_status *rs)
1338{
1339 struct ath_hw_antcomb_conf div_ant_conf;
1340 struct ath_ant_comb *antcomb = &sc->ant_comb;
1341 int alt_ratio = 0, alt_rssi_avg = 0, main_rssi_avg = 0, curr_alt_set;
Sujith Manoharan0ff2b5c2011-04-20 11:00:34 +05301342 int curr_main_set;
Vasanthakumar Thiagarajan102885a2010-09-02 01:34:43 -07001343 int main_rssi = rs->rs_rssi_ctl0;
1344 int alt_rssi = rs->rs_rssi_ctl1;
1345 int rx_ant_conf, main_ant_conf;
1346 bool short_scan = false;
1347
1348 rx_ant_conf = (rs->rs_rssi_ctl2 >> ATH_ANT_RX_CURRENT_SHIFT) &
1349 ATH_ANT_RX_MASK;
1350 main_ant_conf = (rs->rs_rssi_ctl2 >> ATH_ANT_RX_MAIN_SHIFT) &
1351 ATH_ANT_RX_MASK;
1352
1353 /* Record packet only when alt_rssi is positive */
1354 if (alt_rssi > 0) {
1355 antcomb->total_pkt_count++;
1356 antcomb->main_total_rssi += main_rssi;
1357 antcomb->alt_total_rssi += alt_rssi;
1358 if (main_ant_conf == rx_ant_conf)
1359 antcomb->main_recv_cnt++;
1360 else
1361 antcomb->alt_recv_cnt++;
1362 }
1363
1364 /* Short scan check */
1365 if (antcomb->scan && antcomb->alt_good) {
1366 if (time_after(jiffies, antcomb->scan_start_time +
1367 msecs_to_jiffies(ATH_ANT_DIV_COMB_SHORT_SCAN_INTR)))
1368 short_scan = true;
1369 else
1370 if (antcomb->total_pkt_count ==
1371 ATH_ANT_DIV_COMB_SHORT_SCAN_PKTCOUNT) {
1372 alt_ratio = ((antcomb->alt_recv_cnt * 100) /
1373 antcomb->total_pkt_count);
1374 if (alt_ratio < ATH_ANT_DIV_COMB_ALT_ANT_RATIO)
1375 short_scan = true;
1376 }
1377 }
1378
1379 if (((antcomb->total_pkt_count < ATH_ANT_DIV_COMB_MAX_PKTCOUNT) ||
1380 rs->rs_moreaggr) && !short_scan)
1381 return;
1382
1383 if (antcomb->total_pkt_count) {
1384 alt_ratio = ((antcomb->alt_recv_cnt * 100) /
1385 antcomb->total_pkt_count);
1386 main_rssi_avg = (antcomb->main_total_rssi /
1387 antcomb->total_pkt_count);
1388 alt_rssi_avg = (antcomb->alt_total_rssi /
1389 antcomb->total_pkt_count);
1390 }
1391
1392
1393 ath9k_hw_antdiv_comb_conf_get(sc->sc_ah, &div_ant_conf);
1394 curr_alt_set = div_ant_conf.alt_lna_conf;
1395 curr_main_set = div_ant_conf.main_lna_conf;
Vasanthakumar Thiagarajan102885a2010-09-02 01:34:43 -07001396
1397 antcomb->count++;
1398
1399 if (antcomb->count == ATH_ANT_DIV_COMB_MAX_COUNT) {
1400 if (alt_ratio > ATH_ANT_DIV_COMB_ALT_ANT_RATIO) {
1401 ath_lnaconf_alt_good_scan(antcomb, div_ant_conf,
1402 main_rssi_avg);
1403 antcomb->alt_good = true;
1404 } else {
1405 antcomb->alt_good = false;
1406 }
1407
1408 antcomb->count = 0;
1409 antcomb->scan = true;
1410 antcomb->scan_not_start = true;
1411 }
1412
1413 if (!antcomb->scan) {
1414 if (alt_ratio > ATH_ANT_DIV_COMB_ALT_ANT_RATIO) {
1415 if (curr_alt_set == ATH_ANT_DIV_COMB_LNA2) {
1416 /* Switch main and alt LNA */
1417 div_ant_conf.main_lna_conf =
1418 ATH_ANT_DIV_COMB_LNA2;
1419 div_ant_conf.alt_lna_conf =
1420 ATH_ANT_DIV_COMB_LNA1;
1421 } else if (curr_alt_set == ATH_ANT_DIV_COMB_LNA1) {
1422 div_ant_conf.main_lna_conf =
1423 ATH_ANT_DIV_COMB_LNA1;
1424 div_ant_conf.alt_lna_conf =
1425 ATH_ANT_DIV_COMB_LNA2;
1426 }
1427
1428 goto div_comb_done;
1429 } else if ((curr_alt_set != ATH_ANT_DIV_COMB_LNA1) &&
1430 (curr_alt_set != ATH_ANT_DIV_COMB_LNA2)) {
1431 /* Set alt to another LNA */
1432 if (curr_main_set == ATH_ANT_DIV_COMB_LNA2)
1433 div_ant_conf.alt_lna_conf =
1434 ATH_ANT_DIV_COMB_LNA1;
1435 else if (curr_main_set == ATH_ANT_DIV_COMB_LNA1)
1436 div_ant_conf.alt_lna_conf =
1437 ATH_ANT_DIV_COMB_LNA2;
1438
1439 goto div_comb_done;
1440 }
1441
1442 if ((alt_rssi_avg < (main_rssi_avg +
1443 ATH_ANT_DIV_COMB_LNA1_LNA2_DELTA)))
1444 goto div_comb_done;
1445 }
1446
1447 if (!antcomb->scan_not_start) {
1448 switch (curr_alt_set) {
1449 case ATH_ANT_DIV_COMB_LNA2:
1450 antcomb->rssi_lna2 = alt_rssi_avg;
1451 antcomb->rssi_lna1 = main_rssi_avg;
1452 antcomb->scan = true;
1453 /* set to A+B */
1454 div_ant_conf.main_lna_conf =
1455 ATH_ANT_DIV_COMB_LNA1;
1456 div_ant_conf.alt_lna_conf =
1457 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1458 break;
1459 case ATH_ANT_DIV_COMB_LNA1:
1460 antcomb->rssi_lna1 = alt_rssi_avg;
1461 antcomb->rssi_lna2 = main_rssi_avg;
1462 antcomb->scan = true;
1463 /* set to A+B */
1464 div_ant_conf.main_lna_conf = ATH_ANT_DIV_COMB_LNA2;
1465 div_ant_conf.alt_lna_conf =
1466 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1467 break;
1468 case ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2:
1469 antcomb->rssi_add = alt_rssi_avg;
1470 antcomb->scan = true;
1471 /* set to A-B */
1472 div_ant_conf.alt_lna_conf =
1473 ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1474 break;
1475 case ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2:
1476 antcomb->rssi_sub = alt_rssi_avg;
1477 antcomb->scan = false;
1478 if (antcomb->rssi_lna2 >
1479 (antcomb->rssi_lna1 +
1480 ATH_ANT_DIV_COMB_LNA1_LNA2_SWITCH_DELTA)) {
1481 /* use LNA2 as main LNA */
1482 if ((antcomb->rssi_add > antcomb->rssi_lna1) &&
1483 (antcomb->rssi_add > antcomb->rssi_sub)) {
1484 /* set to A+B */
1485 div_ant_conf.main_lna_conf =
1486 ATH_ANT_DIV_COMB_LNA2;
1487 div_ant_conf.alt_lna_conf =
1488 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1489 } else if (antcomb->rssi_sub >
1490 antcomb->rssi_lna1) {
1491 /* set to A-B */
1492 div_ant_conf.main_lna_conf =
1493 ATH_ANT_DIV_COMB_LNA2;
1494 div_ant_conf.alt_lna_conf =
1495 ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1496 } else {
1497 /* set to LNA1 */
1498 div_ant_conf.main_lna_conf =
1499 ATH_ANT_DIV_COMB_LNA2;
1500 div_ant_conf.alt_lna_conf =
1501 ATH_ANT_DIV_COMB_LNA1;
1502 }
1503 } else {
1504 /* use LNA1 as main LNA */
1505 if ((antcomb->rssi_add > antcomb->rssi_lna2) &&
1506 (antcomb->rssi_add > antcomb->rssi_sub)) {
1507 /* set to A+B */
1508 div_ant_conf.main_lna_conf =
1509 ATH_ANT_DIV_COMB_LNA1;
1510 div_ant_conf.alt_lna_conf =
1511 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1512 } else if (antcomb->rssi_sub >
1513 antcomb->rssi_lna1) {
1514 /* set to A-B */
1515 div_ant_conf.main_lna_conf =
1516 ATH_ANT_DIV_COMB_LNA1;
1517 div_ant_conf.alt_lna_conf =
1518 ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1519 } else {
1520 /* set to LNA2 */
1521 div_ant_conf.main_lna_conf =
1522 ATH_ANT_DIV_COMB_LNA1;
1523 div_ant_conf.alt_lna_conf =
1524 ATH_ANT_DIV_COMB_LNA2;
1525 }
1526 }
1527 break;
1528 default:
1529 break;
1530 }
1531 } else {
1532 if (!antcomb->alt_good) {
1533 antcomb->scan_not_start = false;
1534 /* Set alt to another LNA */
1535 if (curr_main_set == ATH_ANT_DIV_COMB_LNA2) {
1536 div_ant_conf.main_lna_conf =
1537 ATH_ANT_DIV_COMB_LNA2;
1538 div_ant_conf.alt_lna_conf =
1539 ATH_ANT_DIV_COMB_LNA1;
1540 } else if (curr_main_set == ATH_ANT_DIV_COMB_LNA1) {
1541 div_ant_conf.main_lna_conf =
1542 ATH_ANT_DIV_COMB_LNA1;
1543 div_ant_conf.alt_lna_conf =
1544 ATH_ANT_DIV_COMB_LNA2;
1545 }
1546 goto div_comb_done;
1547 }
1548 }
1549
1550 ath_select_ant_div_from_quick_scan(antcomb, &div_ant_conf,
1551 main_rssi_avg, alt_rssi_avg,
1552 alt_ratio);
1553
1554 antcomb->quick_scan_cnt++;
1555
1556div_comb_done:
1557 ath_ant_div_conf_fast_divbias(&div_ant_conf);
1558
1559 ath9k_hw_antdiv_comb_conf_set(sc->sc_ah, &div_ant_conf);
1560
1561 antcomb->scan_start_time = jiffies;
1562 antcomb->total_pkt_count = 0;
1563 antcomb->main_total_rssi = 0;
1564 antcomb->alt_total_rssi = 0;
1565 antcomb->main_recv_cnt = 0;
1566 antcomb->alt_recv_cnt = 0;
1567}
1568
Felix Fietkaub5c804752010-04-15 17:38:48 -04001569int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp)
1570{
1571 struct ath_buf *bf;
Felix Fietkau0d955212011-01-26 18:23:27 +01001572 struct sk_buff *skb = NULL, *requeue_skb, *hdr_skb;
Luis R. Rodriguez5ca42622009-11-04 08:20:42 -08001573 struct ieee80211_rx_status *rxs;
Sujithcbe61d82009-02-09 13:27:12 +05301574 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez27c51f12009-09-10 11:08:14 -07001575 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezb4afffc2009-11-02 11:36:08 -08001576 /*
Mohammed Shafi Shajakhancae6b742010-12-07 21:23:16 +05301577 * The hw can technically differ from common->hw when using ath9k
Luis R. Rodriguezb4afffc2009-11-02 11:36:08 -08001578 * virtual wiphy so to account for that we iterate over the active
1579 * wiphys and find the appropriate wiphy and therefore hw.
1580 */
Felix Fietkau7545daf2011-01-24 19:23:16 +01001581 struct ieee80211_hw *hw = sc->hw;
Sujithbe0418a2008-11-18 09:05:55 +05301582 struct ieee80211_hdr *hdr;
Luis R. Rodriguezc9b14172009-11-04 16:47:22 -08001583 int retval;
Sujithbe0418a2008-11-18 09:05:55 +05301584 bool decrypt_error = false;
Felix Fietkau29bffa92010-03-29 20:14:23 -07001585 struct ath_rx_status rs;
Felix Fietkaub5c804752010-04-15 17:38:48 -04001586 enum ath9k_rx_qtype qtype;
1587 bool edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA);
1588 int dma_type;
Vasanthakumar Thiagarajan5c6dd922010-05-20 14:34:47 -07001589 u8 rx_status_len = ah->caps.rx_status_len;
Felix Fietkaua6d20552010-06-12 00:33:54 -04001590 u64 tsf = 0;
1591 u32 tsf_lower = 0;
Luis R. Rodriguez8ab2cd02010-09-16 15:12:26 -04001592 unsigned long flags;
Sujithbe0418a2008-11-18 09:05:55 +05301593
Felix Fietkaub5c804752010-04-15 17:38:48 -04001594 if (edma)
Felix Fietkaub5c804752010-04-15 17:38:48 -04001595 dma_type = DMA_BIDIRECTIONAL;
Ming Lei56824222010-05-14 21:15:38 +08001596 else
1597 dma_type = DMA_FROM_DEVICE;
Felix Fietkaub5c804752010-04-15 17:38:48 -04001598
1599 qtype = hp ? ATH9K_RX_QUEUE_HP : ATH9K_RX_QUEUE_LP;
Sujithb77f4832008-12-07 21:44:03 +05301600 spin_lock_bh(&sc->rx.rxbuflock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001601
Felix Fietkaua6d20552010-06-12 00:33:54 -04001602 tsf = ath9k_hw_gettsf64(ah);
1603 tsf_lower = tsf & 0xffffffff;
1604
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001605 do {
1606 /* If handling rx interrupt and flush is in progress => exit */
Sujith98deeea2008-08-11 14:05:46 +05301607 if ((sc->sc_flags & SC_OP_RXFLUSH) && (flush == 0))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001608 break;
1609
Felix Fietkau29bffa92010-03-29 20:14:23 -07001610 memset(&rs, 0, sizeof(rs));
Felix Fietkaub5c804752010-04-15 17:38:48 -04001611 if (edma)
1612 bf = ath_edma_get_next_rx_buf(sc, &rs, qtype);
1613 else
1614 bf = ath_get_next_rx_buf(sc, &rs);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001615
Felix Fietkaub5c804752010-04-15 17:38:48 -04001616 if (!bf)
1617 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001618
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001619 skb = bf->bf_mpdu;
Sujithbe0418a2008-11-18 09:05:55 +05301620 if (!skb)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001621 continue;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001622
Felix Fietkau0d955212011-01-26 18:23:27 +01001623 /*
1624 * Take frame header from the first fragment and RX status from
1625 * the last one.
1626 */
1627 if (sc->rx.frag)
1628 hdr_skb = sc->rx.frag;
1629 else
1630 hdr_skb = skb;
1631
1632 hdr = (struct ieee80211_hdr *) (hdr_skb->data + rx_status_len);
1633 rxs = IEEE80211_SKB_RXCB(hdr_skb);
Luis R. Rodriguez5ca42622009-11-04 08:20:42 -08001634
Felix Fietkau29bffa92010-03-29 20:14:23 -07001635 ath_debug_stat_rx(sc, &rs);
Sujith1395d3f2010-01-08 10:36:11 +05301636
Vasanthakumar Thiagarajan9bf9fca2008-12-15 20:40:46 +05301637 /*
Sujithbe0418a2008-11-18 09:05:55 +05301638 * If we're asked to flush receive queue, directly
1639 * chain it back at the queue without processing it.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001640 */
Sujithbe0418a2008-11-18 09:05:55 +05301641 if (flush)
Felix Fietkau0d955212011-01-26 18:23:27 +01001642 goto requeue_drop_frag;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001643
Jan Friedrichc8f3b722010-08-02 23:55:50 +02001644 retval = ath9k_rx_skb_preprocess(common, hw, hdr, &rs,
1645 rxs, &decrypt_error);
1646 if (retval)
Felix Fietkau0d955212011-01-26 18:23:27 +01001647 goto requeue_drop_frag;
Jan Friedrichc8f3b722010-08-02 23:55:50 +02001648
Felix Fietkaua6d20552010-06-12 00:33:54 -04001649 rxs->mactime = (tsf & ~0xffffffffULL) | rs.rs_tstamp;
1650 if (rs.rs_tstamp > tsf_lower &&
1651 unlikely(rs.rs_tstamp - tsf_lower > 0x10000000))
1652 rxs->mactime -= 0x100000000ULL;
1653
1654 if (rs.rs_tstamp < tsf_lower &&
1655 unlikely(tsf_lower - rs.rs_tstamp > 0x10000000))
1656 rxs->mactime += 0x100000000ULL;
1657
Luis R. Rodriguezcb71d9b2008-11-21 17:41:33 -08001658 /* Ensure we always have an skb to requeue once we are done
1659 * processing the current buffer's skb */
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -08001660 requeue_skb = ath_rxbuf_alloc(common, common->rx_bufsize, GFP_ATOMIC);
Luis R. Rodriguezcb71d9b2008-11-21 17:41:33 -08001661
1662 /* If there is no memory we ignore the current RX'd frame,
1663 * tell hardware it can give us a new frame using the old
Sujithb77f4832008-12-07 21:44:03 +05301664 * skb and put it at the tail of the sc->rx.rxbuf list for
Luis R. Rodriguezcb71d9b2008-11-21 17:41:33 -08001665 * processing. */
1666 if (!requeue_skb)
Felix Fietkau0d955212011-01-26 18:23:27 +01001667 goto requeue_drop_frag;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001668
Vasanthakumar Thiagarajan9bf9fca2008-12-15 20:40:46 +05301669 /* Unmap the frame */
Gabor Juhos7da3c552009-01-14 20:17:03 +01001670 dma_unmap_single(sc->dev, bf->bf_buf_addr,
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -08001671 common->rx_bufsize,
Felix Fietkaub5c804752010-04-15 17:38:48 -04001672 dma_type);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001673
Felix Fietkaub5c804752010-04-15 17:38:48 -04001674 skb_put(skb, rs.rs_datalen + ah->caps.rx_status_len);
1675 if (ah->caps.rx_status_len)
1676 skb_pull(skb, ah->caps.rx_status_len);
Sujithbe0418a2008-11-18 09:05:55 +05301677
Felix Fietkau0d955212011-01-26 18:23:27 +01001678 if (!rs.rs_more)
1679 ath9k_rx_skb_postprocess(common, hdr_skb, &rs,
1680 rxs, decrypt_error);
Sujithbe0418a2008-11-18 09:05:55 +05301681
Luis R. Rodriguezcb71d9b2008-11-21 17:41:33 -08001682 /* We will now give hardware our shiny new allocated skb */
1683 bf->bf_mpdu = requeue_skb;
Gabor Juhos7da3c552009-01-14 20:17:03 +01001684 bf->bf_buf_addr = dma_map_single(sc->dev, requeue_skb->data,
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -08001685 common->rx_bufsize,
Felix Fietkaub5c804752010-04-15 17:38:48 -04001686 dma_type);
Gabor Juhos7da3c552009-01-14 20:17:03 +01001687 if (unlikely(dma_mapping_error(sc->dev,
Luis R. Rodriguezf8316df2008-12-03 03:35:29 -08001688 bf->bf_buf_addr))) {
1689 dev_kfree_skb_any(requeue_skb);
1690 bf->bf_mpdu = NULL;
Ben Greear6cf9e992010-10-14 12:45:30 -07001691 bf->bf_buf_addr = 0;
Joe Perches38002762010-12-02 19:12:36 -08001692 ath_err(common, "dma_mapping_error() on RX\n");
Felix Fietkau7545daf2011-01-24 19:23:16 +01001693 ieee80211_rx(hw, skb);
Luis R. Rodriguezf8316df2008-12-03 03:35:29 -08001694 break;
1695 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001696
Felix Fietkau0d955212011-01-26 18:23:27 +01001697 if (rs.rs_more) {
1698 /*
1699 * rs_more indicates chained descriptors which can be
1700 * used to link buffers together for a sort of
1701 * scatter-gather operation.
1702 */
1703 if (sc->rx.frag) {
1704 /* too many fragments - cannot handle frame */
1705 dev_kfree_skb_any(sc->rx.frag);
1706 dev_kfree_skb_any(skb);
1707 skb = NULL;
1708 }
1709 sc->rx.frag = skb;
1710 goto requeue;
1711 }
1712
1713 if (sc->rx.frag) {
1714 int space = skb->len - skb_tailroom(hdr_skb);
1715
1716 sc->rx.frag = NULL;
1717
1718 if (pskb_expand_head(hdr_skb, 0, space, GFP_ATOMIC) < 0) {
1719 dev_kfree_skb(skb);
1720 goto requeue_drop_frag;
1721 }
1722
1723 skb_copy_from_linear_data(skb, skb_put(hdr_skb, skb->len),
1724 skb->len);
1725 dev_kfree_skb_any(skb);
1726 skb = hdr_skb;
1727 }
1728
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001729 /*
1730 * change the default rx antenna if rx diversity chooses the
1731 * other antenna 3 times in a row.
1732 */
Felix Fietkau29bffa92010-03-29 20:14:23 -07001733 if (sc->rx.defant != rs.rs_antenna) {
Sujithb77f4832008-12-07 21:44:03 +05301734 if (++sc->rx.rxotherant >= 3)
Felix Fietkau29bffa92010-03-29 20:14:23 -07001735 ath_setdefantenna(sc, rs.rs_antenna);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001736 } else {
Sujithb77f4832008-12-07 21:44:03 +05301737 sc->rx.rxotherant = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001738 }
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301739
Luis R. Rodriguez8ab2cd02010-09-16 15:12:26 -04001740 spin_lock_irqsave(&sc->sc_pm_lock, flags);
Mohammed Shafi Shajakhanaaef24b2010-12-07 20:40:58 +05301741
1742 if ((sc->ps_flags & (PS_WAIT_FOR_BEACON |
Vasanthakumar Thiagarajanededf1f2010-05-22 23:58:13 -07001743 PS_WAIT_FOR_CAB |
Mohammed Shafi Shajakhanaaef24b2010-12-07 20:40:58 +05301744 PS_WAIT_FOR_PSPOLL_DATA)) ||
Mohammed Shafi Shajakhancedc7e32011-04-22 13:12:23 +05301745 ath9k_check_auto_sleep(sc))
Jouni Malinencc659652009-05-14 21:28:48 +03001746 ath_rx_ps(sc, skb);
Luis R. Rodriguez8ab2cd02010-09-16 15:12:26 -04001747 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
Jouni Malinencc659652009-05-14 21:28:48 +03001748
Vasanthakumar Thiagarajan102885a2010-09-02 01:34:43 -07001749 if (ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)
1750 ath_ant_comb_scan(sc, &rs);
1751
Felix Fietkau7545daf2011-01-24 19:23:16 +01001752 ieee80211_rx(hw, skb);
Jouni Malinencc659652009-05-14 21:28:48 +03001753
Felix Fietkau0d955212011-01-26 18:23:27 +01001754requeue_drop_frag:
1755 if (sc->rx.frag) {
1756 dev_kfree_skb_any(sc->rx.frag);
1757 sc->rx.frag = NULL;
1758 }
Luis R. Rodriguezcb71d9b2008-11-21 17:41:33 -08001759requeue:
Felix Fietkaub5c804752010-04-15 17:38:48 -04001760 if (edma) {
1761 list_add_tail(&bf->list, &sc->rx.rxbuf);
1762 ath_rx_edma_buf_link(sc, qtype);
1763 } else {
1764 list_move_tail(&bf->list, &sc->rx.rxbuf);
1765 ath_rx_buf_link(sc, bf);
Felix Fietkau95294972011-04-07 19:30:32 +02001766 ath9k_hw_rxena(ah);
Felix Fietkaub5c804752010-04-15 17:38:48 -04001767 }
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}