blob: ef198ae71eb73ffe0a2a6a8d941737e3967ea124 [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 ath9k_hw_rxena(ah);
79}
80
Sujithff37e332008-11-24 12:07:55 +053081static void ath_setdefantenna(struct ath_softc *sc, u32 antenna)
82{
83 /* XXX block beacon interrupts */
84 ath9k_hw_setantenna(sc->sc_ah, antenna);
Sujithb77f4832008-12-07 21:44:03 +053085 sc->rx.defant = antenna;
86 sc->rx.rxotherant = 0;
Sujithff37e332008-11-24 12:07:55 +053087}
88
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070089static void ath_opmode_init(struct ath_softc *sc)
90{
Sujithcbe61d82009-02-09 13:27:12 +053091 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez15107182009-09-10 09:22:37 -070092 struct ath_common *common = ath9k_hw_common(ah);
93
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070094 u32 rfilt, mfilt[2];
95
96 /* configure rx filter */
97 rfilt = ath_calcrxfilter(sc);
98 ath9k_hw_setrxfilter(ah, rfilt);
99
100 /* configure bssid mask */
Felix Fietkau364734f2010-09-14 20:22:44 +0200101 ath_hw_setbssidmask(common);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700102
103 /* configure operational mode */
104 ath9k_hw_setopmode(ah);
105
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700106 /* calculate and install multicast filter */
107 mfilt[0] = mfilt[1] = ~0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700108 ath9k_hw_setmcastfilter(ah, mfilt[0], mfilt[1]);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700109}
110
Felix Fietkaub5c804752010-04-15 17:38:48 -0400111static bool ath_rx_edma_buf_link(struct ath_softc *sc,
112 enum ath9k_rx_qtype qtype)
113{
114 struct ath_hw *ah = sc->sc_ah;
115 struct ath_rx_edma *rx_edma;
116 struct sk_buff *skb;
117 struct ath_buf *bf;
118
119 rx_edma = &sc->rx.rx_edma[qtype];
120 if (skb_queue_len(&rx_edma->rx_fifo) >= rx_edma->rx_fifo_hwsize)
121 return false;
122
123 bf = list_first_entry(&sc->rx.rxbuf, struct ath_buf, list);
124 list_del_init(&bf->list);
125
126 skb = bf->bf_mpdu;
127
128 ATH_RXBUF_RESET(bf);
129 memset(skb->data, 0, ah->caps.rx_status_len);
130 dma_sync_single_for_device(sc->dev, bf->bf_buf_addr,
131 ah->caps.rx_status_len, DMA_TO_DEVICE);
132
133 SKB_CB_ATHBUF(skb) = bf;
134 ath9k_hw_addrxbuf_edma(ah, bf->bf_buf_addr, qtype);
135 skb_queue_tail(&rx_edma->rx_fifo, skb);
136
137 return true;
138}
139
140static void ath_rx_addbuffer_edma(struct ath_softc *sc,
141 enum ath9k_rx_qtype qtype, int size)
142{
Felix Fietkaub5c804752010-04-15 17:38:48 -0400143 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
144 u32 nbuf = 0;
145
Felix Fietkaub5c804752010-04-15 17:38:48 -0400146 if (list_empty(&sc->rx.rxbuf)) {
Joe Perches226afe62010-12-02 19:12:37 -0800147 ath_dbg(common, ATH_DBG_QUEUE, "No free rx buf available\n");
Felix Fietkaub5c804752010-04-15 17:38:48 -0400148 return;
149 }
150
151 while (!list_empty(&sc->rx.rxbuf)) {
152 nbuf++;
153
154 if (!ath_rx_edma_buf_link(sc, qtype))
155 break;
156
157 if (nbuf >= size)
158 break;
159 }
160}
161
162static void ath_rx_remove_buffer(struct ath_softc *sc,
163 enum ath9k_rx_qtype qtype)
164{
165 struct ath_buf *bf;
166 struct ath_rx_edma *rx_edma;
167 struct sk_buff *skb;
168
169 rx_edma = &sc->rx.rx_edma[qtype];
170
171 while ((skb = skb_dequeue(&rx_edma->rx_fifo)) != NULL) {
172 bf = SKB_CB_ATHBUF(skb);
173 BUG_ON(!bf);
174 list_add_tail(&bf->list, &sc->rx.rxbuf);
175 }
176}
177
178static void ath_rx_edma_cleanup(struct ath_softc *sc)
179{
180 struct ath_buf *bf;
181
182 ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_LP);
183 ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_HP);
184
185 list_for_each_entry(bf, &sc->rx.rxbuf, list) {
186 if (bf->bf_mpdu)
187 dev_kfree_skb_any(bf->bf_mpdu);
188 }
189
190 INIT_LIST_HEAD(&sc->rx.rxbuf);
191
192 kfree(sc->rx.rx_bufptr);
193 sc->rx.rx_bufptr = NULL;
194}
195
196static void ath_rx_edma_init_queue(struct ath_rx_edma *rx_edma, int size)
197{
198 skb_queue_head_init(&rx_edma->rx_fifo);
199 skb_queue_head_init(&rx_edma->rx_buffers);
200 rx_edma->rx_fifo_hwsize = size;
201}
202
203static int ath_rx_edma_init(struct ath_softc *sc, int nbufs)
204{
205 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
206 struct ath_hw *ah = sc->sc_ah;
207 struct sk_buff *skb;
208 struct ath_buf *bf;
209 int error = 0, i;
210 u32 size;
211
Felix Fietkaub5c804752010-04-15 17:38:48 -0400212 ath9k_hw_set_rx_bufsize(ah, common->rx_bufsize -
213 ah->caps.rx_status_len);
214
215 ath_rx_edma_init_queue(&sc->rx.rx_edma[ATH9K_RX_QUEUE_LP],
216 ah->caps.rx_lp_qdepth);
217 ath_rx_edma_init_queue(&sc->rx.rx_edma[ATH9K_RX_QUEUE_HP],
218 ah->caps.rx_hp_qdepth);
219
220 size = sizeof(struct ath_buf) * nbufs;
221 bf = kzalloc(size, GFP_KERNEL);
222 if (!bf)
223 return -ENOMEM;
224
225 INIT_LIST_HEAD(&sc->rx.rxbuf);
226 sc->rx.rx_bufptr = bf;
227
228 for (i = 0; i < nbufs; i++, bf++) {
229 skb = ath_rxbuf_alloc(common, common->rx_bufsize, GFP_KERNEL);
230 if (!skb) {
231 error = -ENOMEM;
232 goto rx_init_fail;
233 }
234
235 memset(skb->data, 0, common->rx_bufsize);
236 bf->bf_mpdu = skb;
237
238 bf->bf_buf_addr = dma_map_single(sc->dev, skb->data,
239 common->rx_bufsize,
240 DMA_BIDIRECTIONAL);
241 if (unlikely(dma_mapping_error(sc->dev,
242 bf->bf_buf_addr))) {
243 dev_kfree_skb_any(skb);
244 bf->bf_mpdu = NULL;
Ben Greear6cf9e992010-10-14 12:45:30 -0700245 bf->bf_buf_addr = 0;
Joe Perches38002762010-12-02 19:12:36 -0800246 ath_err(common,
Felix Fietkaub5c804752010-04-15 17:38:48 -0400247 "dma_mapping_error() on RX init\n");
248 error = -ENOMEM;
249 goto rx_init_fail;
250 }
251
252 list_add_tail(&bf->list, &sc->rx.rxbuf);
253 }
254
255 return 0;
256
257rx_init_fail:
258 ath_rx_edma_cleanup(sc);
259 return error;
260}
261
262static void ath_edma_start_recv(struct ath_softc *sc)
263{
264 spin_lock_bh(&sc->rx.rxbuflock);
265
266 ath9k_hw_rxena(sc->sc_ah);
267
268 ath_rx_addbuffer_edma(sc, ATH9K_RX_QUEUE_HP,
269 sc->rx.rx_edma[ATH9K_RX_QUEUE_HP].rx_fifo_hwsize);
270
271 ath_rx_addbuffer_edma(sc, ATH9K_RX_QUEUE_LP,
272 sc->rx.rx_edma[ATH9K_RX_QUEUE_LP].rx_fifo_hwsize);
273
Felix Fietkaub5c804752010-04-15 17:38:48 -0400274 ath_opmode_init(sc);
275
Luis R. Rodriguez48a6a462010-09-16 15:12:28 -0400276 ath9k_hw_startpcureceive(sc->sc_ah, (sc->sc_flags & SC_OP_OFFCHANNEL));
Luis R. Rodriguez7583c5502010-10-20 16:07:04 -0700277
278 spin_unlock_bh(&sc->rx.rxbuflock);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400279}
280
281static void ath_edma_stop_recv(struct ath_softc *sc)
282{
Felix Fietkaub5c804752010-04-15 17:38:48 -0400283 ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_HP);
284 ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_LP);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400285}
286
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700287int ath_rx_init(struct ath_softc *sc, int nbufs)
288{
Luis R. Rodriguez27c51f12009-09-10 11:08:14 -0700289 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700290 struct sk_buff *skb;
291 struct ath_buf *bf;
292 int error = 0;
293
Luis R. Rodriguez4bdd1e92010-10-26 15:27:24 -0700294 spin_lock_init(&sc->sc_pcu_lock);
Sujith797fe5cb2009-03-30 15:28:45 +0530295 sc->sc_flags &= ~SC_OP_RXFLUSH;
296 spin_lock_init(&sc->rx.rxbuflock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700297
Felix Fietkau0d955212011-01-26 18:23:27 +0100298 common->rx_bufsize = IEEE80211_MAX_MPDU_LEN / 2 +
299 sc->sc_ah->caps.rx_status_len;
300
Felix Fietkaub5c804752010-04-15 17:38:48 -0400301 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
302 return ath_rx_edma_init(sc, nbufs);
303 } else {
Joe Perches226afe62010-12-02 19:12:37 -0800304 ath_dbg(common, ATH_DBG_CONFIG, "cachelsz %u rxbufsize %u\n",
305 common->cachelsz, common->rx_bufsize);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700306
Felix Fietkaub5c804752010-04-15 17:38:48 -0400307 /* Initialize rx descriptors */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700308
Felix Fietkaub5c804752010-04-15 17:38:48 -0400309 error = ath_descdma_setup(sc, &sc->rx.rxdma, &sc->rx.rxbuf,
Vasanthakumar Thiagarajan4adfcde2010-04-15 17:39:33 -0400310 "rx", nbufs, 1, 0);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400311 if (error != 0) {
Joe Perches38002762010-12-02 19:12:36 -0800312 ath_err(common,
313 "failed to allocate rx descriptors: %d\n",
314 error);
Sujith797fe5cb2009-03-30 15:28:45 +0530315 goto err;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700316 }
Felix Fietkaub5c804752010-04-15 17:38:48 -0400317
318 list_for_each_entry(bf, &sc->rx.rxbuf, list) {
319 skb = ath_rxbuf_alloc(common, common->rx_bufsize,
320 GFP_KERNEL);
321 if (skb == NULL) {
322 error = -ENOMEM;
323 goto err;
324 }
325
326 bf->bf_mpdu = skb;
327 bf->bf_buf_addr = dma_map_single(sc->dev, skb->data,
328 common->rx_bufsize,
329 DMA_FROM_DEVICE);
330 if (unlikely(dma_mapping_error(sc->dev,
331 bf->bf_buf_addr))) {
332 dev_kfree_skb_any(skb);
333 bf->bf_mpdu = NULL;
Ben Greear6cf9e992010-10-14 12:45:30 -0700334 bf->bf_buf_addr = 0;
Joe Perches38002762010-12-02 19:12:36 -0800335 ath_err(common,
336 "dma_mapping_error() on RX init\n");
Felix Fietkaub5c804752010-04-15 17:38:48 -0400337 error = -ENOMEM;
338 goto err;
339 }
Felix Fietkaub5c804752010-04-15 17:38:48 -0400340 }
341 sc->rx.rxlink = NULL;
Sujith797fe5cb2009-03-30 15:28:45 +0530342 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700343
Sujith797fe5cb2009-03-30 15:28:45 +0530344err:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700345 if (error)
346 ath_rx_cleanup(sc);
347
348 return error;
349}
350
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700351void ath_rx_cleanup(struct ath_softc *sc)
352{
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -0800353 struct ath_hw *ah = sc->sc_ah;
354 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700355 struct sk_buff *skb;
356 struct ath_buf *bf;
357
Felix Fietkaub5c804752010-04-15 17:38:48 -0400358 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
359 ath_rx_edma_cleanup(sc);
360 return;
361 } else {
362 list_for_each_entry(bf, &sc->rx.rxbuf, list) {
363 skb = bf->bf_mpdu;
364 if (skb) {
365 dma_unmap_single(sc->dev, bf->bf_buf_addr,
366 common->rx_bufsize,
367 DMA_FROM_DEVICE);
368 dev_kfree_skb(skb);
Ben Greear6cf9e992010-10-14 12:45:30 -0700369 bf->bf_buf_addr = 0;
370 bf->bf_mpdu = NULL;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400371 }
Luis R. Rodriguez051b9192009-03-23 18:25:01 -0400372 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700373
Felix Fietkaub5c804752010-04-15 17:38:48 -0400374 if (sc->rx.rxdma.dd_desc_len != 0)
375 ath_descdma_cleanup(sc, &sc->rx.rxdma, &sc->rx.rxbuf);
376 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700377}
378
379/*
380 * Calculate the receive filter according to the
381 * operating mode and state:
382 *
383 * o always accept unicast, broadcast, and multicast traffic
384 * o maintain current state of phy error reception (the hal
385 * may enable phy error frames for noise immunity work)
386 * o probe request frames are accepted only when operating in
387 * hostap, adhoc, or monitor modes
388 * o enable promiscuous mode according to the interface state
389 * o accept beacons:
390 * - when operating in adhoc mode so the 802.11 layer creates
391 * node table entries for peers,
392 * - when operating in station mode for collecting rssi data when
393 * the station is otherwise quiet, or
394 * - when operating as a repeater so we see repeater-sta beacons
395 * - when scanning
396 */
397
398u32 ath_calcrxfilter(struct ath_softc *sc)
399{
400#define RX_FILTER_PRESERVE (ATH9K_RX_FILTER_PHYERR | ATH9K_RX_FILTER_PHYRADAR)
Sujith7dcfdcd2008-08-11 14:03:13 +0530401
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700402 u32 rfilt;
403
404 rfilt = (ath9k_hw_getrxfilter(sc->sc_ah) & RX_FILTER_PRESERVE)
405 | ATH9K_RX_FILTER_UCAST | ATH9K_RX_FILTER_BCAST
406 | ATH9K_RX_FILTER_MCAST;
407
Jouni Malinen9c1d8e42010-10-13 17:29:31 +0300408 if (sc->rx.rxfilter & FIF_PROBE_REQ)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700409 rfilt |= ATH9K_RX_FILTER_PROBEREQ;
410
Jouni Malinen217ba9d2009-03-10 10:55:50 +0200411 /*
412 * Set promiscuous mode when FIF_PROMISC_IN_BSS is enabled for station
413 * mode interface or when in monitor mode. AP mode does not need this
414 * since it receives all in-BSS frames anyway.
415 */
Felix Fietkau2e286942011-03-09 01:48:12 +0100416 if (sc->sc_ah->is_monitoring)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700417 rfilt |= ATH9K_RX_FILTER_PROM;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700418
Sujithd42c6b72009-02-04 08:10:22 +0530419 if (sc->rx.rxfilter & FIF_CONTROL)
420 rfilt |= ATH9K_RX_FILTER_CONTROL;
421
Vasanthakumar Thiagarajandbaaa142009-02-19 15:41:52 +0530422 if ((sc->sc_ah->opmode == NL80211_IFTYPE_STATION) &&
Ben Greearcfda6692010-09-14 12:00:22 -0700423 (sc->nvifs <= 1) &&
Vasanthakumar Thiagarajandbaaa142009-02-19 15:41:52 +0530424 !(sc->rx.rxfilter & FIF_BCN_PRBRESP_PROMISC))
425 rfilt |= ATH9K_RX_FILTER_MYBEACON;
426 else
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700427 rfilt |= ATH9K_RX_FILTER_BEACON;
428
Felix Fietkau264bbec2011-04-07 19:24:23 +0200429 if ((sc->sc_ah->opmode == NL80211_IFTYPE_AP) ||
Senthil Balasubramanian66afad02009-09-18 15:06:07 +0530430 (sc->rx.rxfilter & FIF_PSPOLL))
Vasanthakumar Thiagarajandbaaa142009-02-19 15:41:52 +0530431 rfilt |= ATH9K_RX_FILTER_PSPOLL;
Sujithbe0418a2008-11-18 09:05:55 +0530432
Sujith7ea310b2009-09-03 12:08:43 +0530433 if (conf_is_ht(&sc->hw->conf))
434 rfilt |= ATH9K_RX_FILTER_COMP_BAR;
435
Felix Fietkau7545daf2011-01-24 19:23:16 +0100436 if (sc->nvifs > 1 || (sc->rx.rxfilter & FIF_OTHER_BSS)) {
Javier Cardona5eb6ba82009-08-20 19:12:07 -0700437 /* The following may also be needed for other older chips */
438 if (sc->sc_ah->hw_version.macVersion == AR_SREV_VERSION_9160)
439 rfilt |= ATH9K_RX_FILTER_PROM;
Jouni Malinenb93bce22009-03-03 19:23:30 +0200440 rfilt |= ATH9K_RX_FILTER_MCAST_BCAST_ALL;
441 }
442
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700443 return rfilt;
Sujith7dcfdcd2008-08-11 14:03:13 +0530444
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700445#undef RX_FILTER_PRESERVE
446}
447
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700448int ath_startrecv(struct ath_softc *sc)
449{
Sujithcbe61d82009-02-09 13:27:12 +0530450 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700451 struct ath_buf *bf, *tbf;
452
Felix Fietkaub5c804752010-04-15 17:38:48 -0400453 if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
454 ath_edma_start_recv(sc);
455 return 0;
456 }
457
Sujithb77f4832008-12-07 21:44:03 +0530458 spin_lock_bh(&sc->rx.rxbuflock);
459 if (list_empty(&sc->rx.rxbuf))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700460 goto start_recv;
461
Sujithb77f4832008-12-07 21:44:03 +0530462 sc->rx.rxlink = NULL;
463 list_for_each_entry_safe(bf, tbf, &sc->rx.rxbuf, list) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700464 ath_rx_buf_link(sc, bf);
465 }
466
467 /* We could have deleted elements so the list may be empty now */
Sujithb77f4832008-12-07 21:44:03 +0530468 if (list_empty(&sc->rx.rxbuf))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700469 goto start_recv;
470
Sujithb77f4832008-12-07 21:44:03 +0530471 bf = list_first_entry(&sc->rx.rxbuf, struct ath_buf, list);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700472 ath9k_hw_putrxbuf(ah, bf->bf_daddr);
Sujithbe0418a2008-11-18 09:05:55 +0530473 ath9k_hw_rxena(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700474
475start_recv:
Sujithbe0418a2008-11-18 09:05:55 +0530476 ath_opmode_init(sc);
Luis R. Rodriguez48a6a462010-09-16 15:12:28 -0400477 ath9k_hw_startpcureceive(ah, (sc->sc_flags & SC_OP_OFFCHANNEL));
Sujithbe0418a2008-11-18 09:05:55 +0530478
Luis R. Rodriguez7583c5502010-10-20 16:07:04 -0700479 spin_unlock_bh(&sc->rx.rxbuflock);
480
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700481 return 0;
482}
483
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700484bool ath_stoprecv(struct ath_softc *sc)
485{
Sujithcbe61d82009-02-09 13:27:12 +0530486 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700487 bool stopped;
488
Luis R. Rodriguez1e450282010-10-20 16:07:03 -0700489 spin_lock_bh(&sc->rx.rxbuflock);
Felix Fietkaud47844a2010-11-20 03:08:47 +0100490 ath9k_hw_abortpcurecv(ah);
Sujithbe0418a2008-11-18 09:05:55 +0530491 ath9k_hw_setrxfilter(ah, 0);
492 stopped = ath9k_hw_stopdmarecv(ah);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400493
494 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
495 ath_edma_stop_recv(sc);
496 else
497 sc->rx.rxlink = NULL;
Luis R. Rodriguez1e450282010-10-20 16:07:03 -0700498 spin_unlock_bh(&sc->rx.rxbuflock);
Sujithbe0418a2008-11-18 09:05:55 +0530499
Rajkumar Manoharand5847472010-12-20 14:39:51 +0530500 if (!(ah->ah_flags & AH_UNPLUGGED) &&
501 unlikely(!stopped)) {
Ben Greeard7fd1b502010-12-06 13:13:07 -0800502 ath_err(ath9k_hw_common(sc->sc_ah),
503 "Could not stop RX, we could be "
504 "confusing the DMA engine when we start RX up\n");
505 ATH_DBG_WARN_ON_ONCE(!stopped);
506 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700507 return stopped;
508}
509
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700510void ath_flushrecv(struct ath_softc *sc)
511{
Sujith98deeea2008-08-11 14:05:46 +0530512 sc->sc_flags |= SC_OP_RXFLUSH;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400513 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
514 ath_rx_tasklet(sc, 1, true);
515 ath_rx_tasklet(sc, 1, false);
Sujith98deeea2008-08-11 14:05:46 +0530516 sc->sc_flags &= ~SC_OP_RXFLUSH;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700517}
518
Jouni Malinencc659652009-05-14 21:28:48 +0300519static bool ath_beacon_dtim_pending_cab(struct sk_buff *skb)
520{
521 /* Check whether the Beacon frame has DTIM indicating buffered bc/mc */
522 struct ieee80211_mgmt *mgmt;
523 u8 *pos, *end, id, elen;
524 struct ieee80211_tim_ie *tim;
525
526 mgmt = (struct ieee80211_mgmt *)skb->data;
527 pos = mgmt->u.beacon.variable;
528 end = skb->data + skb->len;
529
530 while (pos + 2 < end) {
531 id = *pos++;
532 elen = *pos++;
533 if (pos + elen > end)
534 break;
535
536 if (id == WLAN_EID_TIM) {
537 if (elen < sizeof(*tim))
538 break;
539 tim = (struct ieee80211_tim_ie *) pos;
540 if (tim->dtim_count != 0)
541 break;
542 return tim->bitmap_ctrl & 0x01;
543 }
544
545 pos += elen;
546 }
547
548 return false;
549}
550
Jouni Malinencc659652009-05-14 21:28:48 +0300551static void ath_rx_ps_beacon(struct ath_softc *sc, struct sk_buff *skb)
552{
553 struct ieee80211_mgmt *mgmt;
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700554 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Jouni Malinencc659652009-05-14 21:28:48 +0300555
556 if (skb->len < 24 + 8 + 2 + 2)
557 return;
558
559 mgmt = (struct ieee80211_mgmt *)skb->data;
Ben Greear48014162011-01-15 19:13:48 +0000560 if (memcmp(common->curbssid, mgmt->bssid, ETH_ALEN) != 0) {
561 /* TODO: This doesn't work well if you have stations
562 * associated to two different APs because curbssid
563 * is just the last AP that any of the stations associated
564 * with.
565 */
Jouni Malinencc659652009-05-14 21:28:48 +0300566 return; /* not from our current AP */
Ben Greear48014162011-01-15 19:13:48 +0000567 }
Jouni Malinencc659652009-05-14 21:28:48 +0300568
Sujith1b04b932010-01-08 10:36:05 +0530569 sc->ps_flags &= ~PS_WAIT_FOR_BEACON;
Gabor Juhos293dc5d2009-06-19 12:17:48 +0200570
Sujith1b04b932010-01-08 10:36:05 +0530571 if (sc->ps_flags & PS_BEACON_SYNC) {
572 sc->ps_flags &= ~PS_BEACON_SYNC;
Joe Perches226afe62010-12-02 19:12:37 -0800573 ath_dbg(common, ATH_DBG_PS,
574 "Reconfigure Beacon timers based on timestamp from the AP\n");
Rajkumar Manoharan99e4d432011-04-04 22:56:19 +0530575 ath_set_beacon(sc);
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;
1343 int curr_main_set, curr_bias;
1344 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;
1397 curr_bias = div_ant_conf.fast_div_bias;
1398
1399 antcomb->count++;
1400
1401 if (antcomb->count == ATH_ANT_DIV_COMB_MAX_COUNT) {
1402 if (alt_ratio > ATH_ANT_DIV_COMB_ALT_ANT_RATIO) {
1403 ath_lnaconf_alt_good_scan(antcomb, div_ant_conf,
1404 main_rssi_avg);
1405 antcomb->alt_good = true;
1406 } else {
1407 antcomb->alt_good = false;
1408 }
1409
1410 antcomb->count = 0;
1411 antcomb->scan = true;
1412 antcomb->scan_not_start = true;
1413 }
1414
1415 if (!antcomb->scan) {
1416 if (alt_ratio > ATH_ANT_DIV_COMB_ALT_ANT_RATIO) {
1417 if (curr_alt_set == ATH_ANT_DIV_COMB_LNA2) {
1418 /* Switch main and alt LNA */
1419 div_ant_conf.main_lna_conf =
1420 ATH_ANT_DIV_COMB_LNA2;
1421 div_ant_conf.alt_lna_conf =
1422 ATH_ANT_DIV_COMB_LNA1;
1423 } else if (curr_alt_set == ATH_ANT_DIV_COMB_LNA1) {
1424 div_ant_conf.main_lna_conf =
1425 ATH_ANT_DIV_COMB_LNA1;
1426 div_ant_conf.alt_lna_conf =
1427 ATH_ANT_DIV_COMB_LNA2;
1428 }
1429
1430 goto div_comb_done;
1431 } else if ((curr_alt_set != ATH_ANT_DIV_COMB_LNA1) &&
1432 (curr_alt_set != ATH_ANT_DIV_COMB_LNA2)) {
1433 /* Set alt to another LNA */
1434 if (curr_main_set == ATH_ANT_DIV_COMB_LNA2)
1435 div_ant_conf.alt_lna_conf =
1436 ATH_ANT_DIV_COMB_LNA1;
1437 else if (curr_main_set == ATH_ANT_DIV_COMB_LNA1)
1438 div_ant_conf.alt_lna_conf =
1439 ATH_ANT_DIV_COMB_LNA2;
1440
1441 goto div_comb_done;
1442 }
1443
1444 if ((alt_rssi_avg < (main_rssi_avg +
1445 ATH_ANT_DIV_COMB_LNA1_LNA2_DELTA)))
1446 goto div_comb_done;
1447 }
1448
1449 if (!antcomb->scan_not_start) {
1450 switch (curr_alt_set) {
1451 case ATH_ANT_DIV_COMB_LNA2:
1452 antcomb->rssi_lna2 = alt_rssi_avg;
1453 antcomb->rssi_lna1 = main_rssi_avg;
1454 antcomb->scan = true;
1455 /* set to A+B */
1456 div_ant_conf.main_lna_conf =
1457 ATH_ANT_DIV_COMB_LNA1;
1458 div_ant_conf.alt_lna_conf =
1459 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1460 break;
1461 case ATH_ANT_DIV_COMB_LNA1:
1462 antcomb->rssi_lna1 = alt_rssi_avg;
1463 antcomb->rssi_lna2 = main_rssi_avg;
1464 antcomb->scan = true;
1465 /* set to A+B */
1466 div_ant_conf.main_lna_conf = ATH_ANT_DIV_COMB_LNA2;
1467 div_ant_conf.alt_lna_conf =
1468 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1469 break;
1470 case ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2:
1471 antcomb->rssi_add = alt_rssi_avg;
1472 antcomb->scan = true;
1473 /* set to A-B */
1474 div_ant_conf.alt_lna_conf =
1475 ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1476 break;
1477 case ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2:
1478 antcomb->rssi_sub = alt_rssi_avg;
1479 antcomb->scan = false;
1480 if (antcomb->rssi_lna2 >
1481 (antcomb->rssi_lna1 +
1482 ATH_ANT_DIV_COMB_LNA1_LNA2_SWITCH_DELTA)) {
1483 /* use LNA2 as main LNA */
1484 if ((antcomb->rssi_add > antcomb->rssi_lna1) &&
1485 (antcomb->rssi_add > antcomb->rssi_sub)) {
1486 /* set to A+B */
1487 div_ant_conf.main_lna_conf =
1488 ATH_ANT_DIV_COMB_LNA2;
1489 div_ant_conf.alt_lna_conf =
1490 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1491 } else if (antcomb->rssi_sub >
1492 antcomb->rssi_lna1) {
1493 /* set to A-B */
1494 div_ant_conf.main_lna_conf =
1495 ATH_ANT_DIV_COMB_LNA2;
1496 div_ant_conf.alt_lna_conf =
1497 ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1498 } else {
1499 /* set to LNA1 */
1500 div_ant_conf.main_lna_conf =
1501 ATH_ANT_DIV_COMB_LNA2;
1502 div_ant_conf.alt_lna_conf =
1503 ATH_ANT_DIV_COMB_LNA1;
1504 }
1505 } else {
1506 /* use LNA1 as main LNA */
1507 if ((antcomb->rssi_add > antcomb->rssi_lna2) &&
1508 (antcomb->rssi_add > antcomb->rssi_sub)) {
1509 /* set to A+B */
1510 div_ant_conf.main_lna_conf =
1511 ATH_ANT_DIV_COMB_LNA1;
1512 div_ant_conf.alt_lna_conf =
1513 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1514 } else if (antcomb->rssi_sub >
1515 antcomb->rssi_lna1) {
1516 /* set to A-B */
1517 div_ant_conf.main_lna_conf =
1518 ATH_ANT_DIV_COMB_LNA1;
1519 div_ant_conf.alt_lna_conf =
1520 ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1521 } else {
1522 /* set to LNA2 */
1523 div_ant_conf.main_lna_conf =
1524 ATH_ANT_DIV_COMB_LNA1;
1525 div_ant_conf.alt_lna_conf =
1526 ATH_ANT_DIV_COMB_LNA2;
1527 }
1528 }
1529 break;
1530 default:
1531 break;
1532 }
1533 } else {
1534 if (!antcomb->alt_good) {
1535 antcomb->scan_not_start = false;
1536 /* Set alt to another LNA */
1537 if (curr_main_set == ATH_ANT_DIV_COMB_LNA2) {
1538 div_ant_conf.main_lna_conf =
1539 ATH_ANT_DIV_COMB_LNA2;
1540 div_ant_conf.alt_lna_conf =
1541 ATH_ANT_DIV_COMB_LNA1;
1542 } else if (curr_main_set == ATH_ANT_DIV_COMB_LNA1) {
1543 div_ant_conf.main_lna_conf =
1544 ATH_ANT_DIV_COMB_LNA1;
1545 div_ant_conf.alt_lna_conf =
1546 ATH_ANT_DIV_COMB_LNA2;
1547 }
1548 goto div_comb_done;
1549 }
1550 }
1551
1552 ath_select_ant_div_from_quick_scan(antcomb, &div_ant_conf,
1553 main_rssi_avg, alt_rssi_avg,
1554 alt_ratio);
1555
1556 antcomb->quick_scan_cnt++;
1557
1558div_comb_done:
1559 ath_ant_div_conf_fast_divbias(&div_ant_conf);
1560
1561 ath9k_hw_antdiv_comb_conf_set(sc->sc_ah, &div_ant_conf);
1562
1563 antcomb->scan_start_time = jiffies;
1564 antcomb->total_pkt_count = 0;
1565 antcomb->main_total_rssi = 0;
1566 antcomb->alt_total_rssi = 0;
1567 antcomb->main_recv_cnt = 0;
1568 antcomb->alt_recv_cnt = 0;
1569}
1570
Felix Fietkaub5c804752010-04-15 17:38:48 -04001571int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp)
1572{
1573 struct ath_buf *bf;
Felix Fietkau0d955212011-01-26 18:23:27 +01001574 struct sk_buff *skb = NULL, *requeue_skb, *hdr_skb;
Luis R. Rodriguez5ca42622009-11-04 08:20:42 -08001575 struct ieee80211_rx_status *rxs;
Sujithcbe61d82009-02-09 13:27:12 +05301576 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez27c51f12009-09-10 11:08:14 -07001577 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezb4afffc2009-11-02 11:36:08 -08001578 /*
Mohammed Shafi Shajakhancae6b742010-12-07 21:23:16 +05301579 * The hw can technically differ from common->hw when using ath9k
Luis R. Rodriguezb4afffc2009-11-02 11:36:08 -08001580 * virtual wiphy so to account for that we iterate over the active
1581 * wiphys and find the appropriate wiphy and therefore hw.
1582 */
Felix Fietkau7545daf2011-01-24 19:23:16 +01001583 struct ieee80211_hw *hw = sc->hw;
Sujithbe0418a2008-11-18 09:05:55 +05301584 struct ieee80211_hdr *hdr;
Luis R. Rodriguezc9b14172009-11-04 16:47:22 -08001585 int retval;
Sujithbe0418a2008-11-18 09:05:55 +05301586 bool decrypt_error = false;
Felix Fietkau29bffa92010-03-29 20:14:23 -07001587 struct ath_rx_status rs;
Felix Fietkaub5c804752010-04-15 17:38:48 -04001588 enum ath9k_rx_qtype qtype;
1589 bool edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA);
1590 int dma_type;
Vasanthakumar Thiagarajan5c6dd922010-05-20 14:34:47 -07001591 u8 rx_status_len = ah->caps.rx_status_len;
Felix Fietkaua6d20552010-06-12 00:33:54 -04001592 u64 tsf = 0;
1593 u32 tsf_lower = 0;
Luis R. Rodriguez8ab2cd02010-09-16 15:12:26 -04001594 unsigned long flags;
Sujithbe0418a2008-11-18 09:05:55 +05301595
Felix Fietkaub5c804752010-04-15 17:38:48 -04001596 if (edma)
Felix Fietkaub5c804752010-04-15 17:38:48 -04001597 dma_type = DMA_BIDIRECTIONAL;
Ming Lei56824222010-05-14 21:15:38 +08001598 else
1599 dma_type = DMA_FROM_DEVICE;
Felix Fietkaub5c804752010-04-15 17:38:48 -04001600
1601 qtype = hp ? ATH9K_RX_QUEUE_HP : ATH9K_RX_QUEUE_LP;
Sujithb77f4832008-12-07 21:44:03 +05301602 spin_lock_bh(&sc->rx.rxbuflock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001603
Felix Fietkaua6d20552010-06-12 00:33:54 -04001604 tsf = ath9k_hw_gettsf64(ah);
1605 tsf_lower = tsf & 0xffffffff;
1606
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001607 do {
1608 /* If handling rx interrupt and flush is in progress => exit */
Sujith98deeea2008-08-11 14:05:46 +05301609 if ((sc->sc_flags & SC_OP_RXFLUSH) && (flush == 0))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001610 break;
1611
Felix Fietkau29bffa92010-03-29 20:14:23 -07001612 memset(&rs, 0, sizeof(rs));
Felix Fietkaub5c804752010-04-15 17:38:48 -04001613 if (edma)
1614 bf = ath_edma_get_next_rx_buf(sc, &rs, qtype);
1615 else
1616 bf = ath_get_next_rx_buf(sc, &rs);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001617
Felix Fietkaub5c804752010-04-15 17:38:48 -04001618 if (!bf)
1619 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001620
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001621 skb = bf->bf_mpdu;
Sujithbe0418a2008-11-18 09:05:55 +05301622 if (!skb)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001623 continue;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001624
Felix Fietkau0d955212011-01-26 18:23:27 +01001625 /*
1626 * Take frame header from the first fragment and RX status from
1627 * the last one.
1628 */
1629 if (sc->rx.frag)
1630 hdr_skb = sc->rx.frag;
1631 else
1632 hdr_skb = skb;
1633
1634 hdr = (struct ieee80211_hdr *) (hdr_skb->data + rx_status_len);
1635 rxs = IEEE80211_SKB_RXCB(hdr_skb);
Luis R. Rodriguez5ca42622009-11-04 08:20:42 -08001636
Felix Fietkau29bffa92010-03-29 20:14:23 -07001637 ath_debug_stat_rx(sc, &rs);
Sujith1395d3f2010-01-08 10:36:11 +05301638
Vasanthakumar Thiagarajan9bf9fca2008-12-15 20:40:46 +05301639 /*
Sujithbe0418a2008-11-18 09:05:55 +05301640 * If we're asked to flush receive queue, directly
1641 * chain it back at the queue without processing it.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001642 */
Sujithbe0418a2008-11-18 09:05:55 +05301643 if (flush)
Felix Fietkau0d955212011-01-26 18:23:27 +01001644 goto requeue_drop_frag;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001645
Jan Friedrichc8f3b722010-08-02 23:55:50 +02001646 retval = ath9k_rx_skb_preprocess(common, hw, hdr, &rs,
1647 rxs, &decrypt_error);
1648 if (retval)
Felix Fietkau0d955212011-01-26 18:23:27 +01001649 goto requeue_drop_frag;
Jan Friedrichc8f3b722010-08-02 23:55:50 +02001650
Felix Fietkaua6d20552010-06-12 00:33:54 -04001651 rxs->mactime = (tsf & ~0xffffffffULL) | rs.rs_tstamp;
1652 if (rs.rs_tstamp > tsf_lower &&
1653 unlikely(rs.rs_tstamp - tsf_lower > 0x10000000))
1654 rxs->mactime -= 0x100000000ULL;
1655
1656 if (rs.rs_tstamp < tsf_lower &&
1657 unlikely(tsf_lower - rs.rs_tstamp > 0x10000000))
1658 rxs->mactime += 0x100000000ULL;
1659
Luis R. Rodriguezcb71d9b2008-11-21 17:41:33 -08001660 /* Ensure we always have an skb to requeue once we are done
1661 * processing the current buffer's skb */
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -08001662 requeue_skb = ath_rxbuf_alloc(common, common->rx_bufsize, GFP_ATOMIC);
Luis R. Rodriguezcb71d9b2008-11-21 17:41:33 -08001663
1664 /* If there is no memory we ignore the current RX'd frame,
1665 * tell hardware it can give us a new frame using the old
Sujithb77f4832008-12-07 21:44:03 +05301666 * skb and put it at the tail of the sc->rx.rxbuf list for
Luis R. Rodriguezcb71d9b2008-11-21 17:41:33 -08001667 * processing. */
1668 if (!requeue_skb)
Felix Fietkau0d955212011-01-26 18:23:27 +01001669 goto requeue_drop_frag;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001670
Vasanthakumar Thiagarajan9bf9fca2008-12-15 20:40:46 +05301671 /* Unmap the frame */
Gabor Juhos7da3c552009-01-14 20:17:03 +01001672 dma_unmap_single(sc->dev, bf->bf_buf_addr,
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -08001673 common->rx_bufsize,
Felix Fietkaub5c804752010-04-15 17:38:48 -04001674 dma_type);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001675
Felix Fietkaub5c804752010-04-15 17:38:48 -04001676 skb_put(skb, rs.rs_datalen + ah->caps.rx_status_len);
1677 if (ah->caps.rx_status_len)
1678 skb_pull(skb, ah->caps.rx_status_len);
Sujithbe0418a2008-11-18 09:05:55 +05301679
Felix Fietkau0d955212011-01-26 18:23:27 +01001680 if (!rs.rs_more)
1681 ath9k_rx_skb_postprocess(common, hdr_skb, &rs,
1682 rxs, decrypt_error);
Sujithbe0418a2008-11-18 09:05:55 +05301683
Luis R. Rodriguezcb71d9b2008-11-21 17:41:33 -08001684 /* We will now give hardware our shiny new allocated skb */
1685 bf->bf_mpdu = requeue_skb;
Gabor Juhos7da3c552009-01-14 20:17:03 +01001686 bf->bf_buf_addr = dma_map_single(sc->dev, requeue_skb->data,
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -08001687 common->rx_bufsize,
Felix Fietkaub5c804752010-04-15 17:38:48 -04001688 dma_type);
Gabor Juhos7da3c552009-01-14 20:17:03 +01001689 if (unlikely(dma_mapping_error(sc->dev,
Luis R. Rodriguezf8316df2008-12-03 03:35:29 -08001690 bf->bf_buf_addr))) {
1691 dev_kfree_skb_any(requeue_skb);
1692 bf->bf_mpdu = NULL;
Ben Greear6cf9e992010-10-14 12:45:30 -07001693 bf->bf_buf_addr = 0;
Joe Perches38002762010-12-02 19:12:36 -08001694 ath_err(common, "dma_mapping_error() on RX\n");
Felix Fietkau7545daf2011-01-24 19:23:16 +01001695 ieee80211_rx(hw, skb);
Luis R. Rodriguezf8316df2008-12-03 03:35:29 -08001696 break;
1697 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001698
Felix Fietkau0d955212011-01-26 18:23:27 +01001699 if (rs.rs_more) {
1700 /*
1701 * rs_more indicates chained descriptors which can be
1702 * used to link buffers together for a sort of
1703 * scatter-gather operation.
1704 */
1705 if (sc->rx.frag) {
1706 /* too many fragments - cannot handle frame */
1707 dev_kfree_skb_any(sc->rx.frag);
1708 dev_kfree_skb_any(skb);
1709 skb = NULL;
1710 }
1711 sc->rx.frag = skb;
1712 goto requeue;
1713 }
1714
1715 if (sc->rx.frag) {
1716 int space = skb->len - skb_tailroom(hdr_skb);
1717
1718 sc->rx.frag = NULL;
1719
1720 if (pskb_expand_head(hdr_skb, 0, space, GFP_ATOMIC) < 0) {
1721 dev_kfree_skb(skb);
1722 goto requeue_drop_frag;
1723 }
1724
1725 skb_copy_from_linear_data(skb, skb_put(hdr_skb, skb->len),
1726 skb->len);
1727 dev_kfree_skb_any(skb);
1728 skb = hdr_skb;
1729 }
1730
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001731 /*
1732 * change the default rx antenna if rx diversity chooses the
1733 * other antenna 3 times in a row.
1734 */
Felix Fietkau29bffa92010-03-29 20:14:23 -07001735 if (sc->rx.defant != rs.rs_antenna) {
Sujithb77f4832008-12-07 21:44:03 +05301736 if (++sc->rx.rxotherant >= 3)
Felix Fietkau29bffa92010-03-29 20:14:23 -07001737 ath_setdefantenna(sc, rs.rs_antenna);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001738 } else {
Sujithb77f4832008-12-07 21:44:03 +05301739 sc->rx.rxotherant = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001740 }
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301741
Luis R. Rodriguez8ab2cd02010-09-16 15:12:26 -04001742 spin_lock_irqsave(&sc->sc_pm_lock, flags);
Mohammed Shafi Shajakhanaaef24b2010-12-07 20:40:58 +05301743
1744 if ((sc->ps_flags & (PS_WAIT_FOR_BEACON |
Vasanthakumar Thiagarajanededf1f2010-05-22 23:58:13 -07001745 PS_WAIT_FOR_CAB |
Mohammed Shafi Shajakhanaaef24b2010-12-07 20:40:58 +05301746 PS_WAIT_FOR_PSPOLL_DATA)) ||
1747 unlikely(ath9k_check_auto_sleep(sc)))
Jouni Malinencc659652009-05-14 21:28:48 +03001748 ath_rx_ps(sc, skb);
Luis R. Rodriguez8ab2cd02010-09-16 15:12:26 -04001749 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
Jouni Malinencc659652009-05-14 21:28:48 +03001750
Vasanthakumar Thiagarajan102885a2010-09-02 01:34:43 -07001751 if (ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)
1752 ath_ant_comb_scan(sc, &rs);
1753
Felix Fietkau7545daf2011-01-24 19:23:16 +01001754 ieee80211_rx(hw, skb);
Jouni Malinencc659652009-05-14 21:28:48 +03001755
Felix Fietkau0d955212011-01-26 18:23:27 +01001756requeue_drop_frag:
1757 if (sc->rx.frag) {
1758 dev_kfree_skb_any(sc->rx.frag);
1759 sc->rx.frag = NULL;
1760 }
Luis R. Rodriguezcb71d9b2008-11-21 17:41:33 -08001761requeue:
Felix Fietkaub5c804752010-04-15 17:38:48 -04001762 if (edma) {
1763 list_add_tail(&bf->list, &sc->rx.rxbuf);
1764 ath_rx_edma_buf_link(sc, qtype);
1765 } else {
1766 list_move_tail(&bf->list, &sc->rx.rxbuf);
1767 ath_rx_buf_link(sc, bf);
1768 }
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}