blob: fbdcc80437fe561bcaf5253f4e427edba49d7182 [file] [log] [blame]
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001/*
Sujith Manoharan5b681382011-05-17 13:36:18 +05302 * Copyright (c) 2008-2011 Atheros Communications Inc.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
Alexey Dobriyanb7f080c2011-06-16 11:01:34 +000017#include <linux/dma-mapping.h>
Sujith394cf0a2009-02-09 13:26:54 +053018#include "ath9k.h"
Luis R. Rodriguezb622a722010-04-15 17:39:28 -040019#include "ar9003_mac.h"
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070020
Felix Fietkaub5c804752010-04-15 17:38:48 -040021#define SKB_CB_ATHBUF(__skb) (*((struct ath_buf **)__skb->cb))
22
Vasanthakumar Thiagarajanededf1f2010-05-22 23:58:13 -070023static inline bool ath9k_check_auto_sleep(struct ath_softc *sc)
24{
25 return sc->ps_enabled &&
26 (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP);
27}
28
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070029/*
30 * Setup and link descriptors.
31 *
32 * 11N: we can no longer afford to self link the last descriptor.
33 * MAC acknowledges BA status as long as it copies frames to host
34 * buffer (or rx fifo). This can incorrectly acknowledge packets
35 * to a sender if last desc is self-linked.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070036 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070037static void ath_rx_buf_link(struct ath_softc *sc, struct ath_buf *bf)
38{
Sujithcbe61d82009-02-09 13:27:12 +053039 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -080040 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070041 struct ath_desc *ds;
42 struct sk_buff *skb;
43
44 ATH_RXBUF_RESET(bf);
45
46 ds = bf->bf_desc;
Sujithbe0418a2008-11-18 09:05:55 +053047 ds->ds_link = 0; /* link to null */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070048 ds->ds_data = bf->bf_buf_addr;
49
Sujithbe0418a2008-11-18 09:05:55 +053050 /* virtual addr of the beginning of the buffer. */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070051 skb = bf->bf_mpdu;
Luis R. Rodriguez9680e8a2009-09-13 23:28:00 -070052 BUG_ON(skb == NULL);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070053 ds->ds_vdata = skb->data;
54
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -080055 /*
56 * setup rx descriptors. The rx_bufsize here tells the hardware
Luis R. Rodriguezb4b6cda2008-11-20 17:15:13 -080057 * how much data it can DMA to us and that we are prepared
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -080058 * to process
59 */
Sujithb77f4832008-12-07 21:44:03 +053060 ath9k_hw_setuprxdesc(ah, ds,
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -080061 common->rx_bufsize,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070062 0);
63
Sujithb77f4832008-12-07 21:44:03 +053064 if (sc->rx.rxlink == NULL)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070065 ath9k_hw_putrxbuf(ah, bf->bf_daddr);
66 else
Sujithb77f4832008-12-07 21:44:03 +053067 *sc->rx.rxlink = bf->bf_daddr;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070068
Sujithb77f4832008-12-07 21:44:03 +053069 sc->rx.rxlink = &ds->ds_link;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070070}
71
Sujithff37e332008-11-24 12:07:55 +053072static void ath_setdefantenna(struct ath_softc *sc, u32 antenna)
73{
74 /* XXX block beacon interrupts */
75 ath9k_hw_setantenna(sc->sc_ah, antenna);
Sujithb77f4832008-12-07 21:44:03 +053076 sc->rx.defant = antenna;
77 sc->rx.rxotherant = 0;
Sujithff37e332008-11-24 12:07:55 +053078}
79
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070080static void ath_opmode_init(struct ath_softc *sc)
81{
Sujithcbe61d82009-02-09 13:27:12 +053082 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez15107182009-09-10 09:22:37 -070083 struct ath_common *common = ath9k_hw_common(ah);
84
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070085 u32 rfilt, mfilt[2];
86
87 /* configure rx filter */
88 rfilt = ath_calcrxfilter(sc);
89 ath9k_hw_setrxfilter(ah, rfilt);
90
91 /* configure bssid mask */
Felix Fietkau364734f2010-09-14 20:22:44 +020092 ath_hw_setbssidmask(common);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070093
94 /* configure operational mode */
95 ath9k_hw_setopmode(ah);
96
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070097 /* calculate and install multicast filter */
98 mfilt[0] = mfilt[1] = ~0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070099 ath9k_hw_setmcastfilter(ah, mfilt[0], mfilt[1]);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700100}
101
Felix Fietkaub5c804752010-04-15 17:38:48 -0400102static bool ath_rx_edma_buf_link(struct ath_softc *sc,
103 enum ath9k_rx_qtype qtype)
104{
105 struct ath_hw *ah = sc->sc_ah;
106 struct ath_rx_edma *rx_edma;
107 struct sk_buff *skb;
108 struct ath_buf *bf;
109
110 rx_edma = &sc->rx.rx_edma[qtype];
111 if (skb_queue_len(&rx_edma->rx_fifo) >= rx_edma->rx_fifo_hwsize)
112 return false;
113
114 bf = list_first_entry(&sc->rx.rxbuf, struct ath_buf, list);
115 list_del_init(&bf->list);
116
117 skb = bf->bf_mpdu;
118
119 ATH_RXBUF_RESET(bf);
120 memset(skb->data, 0, ah->caps.rx_status_len);
121 dma_sync_single_for_device(sc->dev, bf->bf_buf_addr,
122 ah->caps.rx_status_len, DMA_TO_DEVICE);
123
124 SKB_CB_ATHBUF(skb) = bf;
125 ath9k_hw_addrxbuf_edma(ah, bf->bf_buf_addr, qtype);
126 skb_queue_tail(&rx_edma->rx_fifo, skb);
127
128 return true;
129}
130
131static void ath_rx_addbuffer_edma(struct ath_softc *sc,
132 enum ath9k_rx_qtype qtype, int size)
133{
Felix Fietkaub5c804752010-04-15 17:38:48 -0400134 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Mohammed Shafi Shajakhan6a01f0c2012-02-28 20:54:44 +0530135 struct ath_buf *bf, *tbf;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400136
Felix Fietkaub5c804752010-04-15 17:38:48 -0400137 if (list_empty(&sc->rx.rxbuf)) {
Joe Perchesd2182b62011-12-15 14:55:53 -0800138 ath_dbg(common, QUEUE, "No free rx buf available\n");
Felix Fietkaub5c804752010-04-15 17:38:48 -0400139 return;
140 }
141
Mohammed Shafi Shajakhan6a01f0c2012-02-28 20:54:44 +0530142 list_for_each_entry_safe(bf, tbf, &sc->rx.rxbuf, list)
Felix Fietkaub5c804752010-04-15 17:38:48 -0400143 if (!ath_rx_edma_buf_link(sc, qtype))
144 break;
145
Felix Fietkaub5c804752010-04-15 17:38:48 -0400146}
147
148static void ath_rx_remove_buffer(struct ath_softc *sc,
149 enum ath9k_rx_qtype qtype)
150{
151 struct ath_buf *bf;
152 struct ath_rx_edma *rx_edma;
153 struct sk_buff *skb;
154
155 rx_edma = &sc->rx.rx_edma[qtype];
156
157 while ((skb = skb_dequeue(&rx_edma->rx_fifo)) != NULL) {
158 bf = SKB_CB_ATHBUF(skb);
159 BUG_ON(!bf);
160 list_add_tail(&bf->list, &sc->rx.rxbuf);
161 }
162}
163
164static void ath_rx_edma_cleanup(struct ath_softc *sc)
165{
Mohammed Shafi Shajakhanba542382011-09-23 14:33:14 +0530166 struct ath_hw *ah = sc->sc_ah;
167 struct ath_common *common = ath9k_hw_common(ah);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400168 struct ath_buf *bf;
169
170 ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_LP);
171 ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_HP);
172
173 list_for_each_entry(bf, &sc->rx.rxbuf, list) {
Mohammed Shafi Shajakhanba542382011-09-23 14:33:14 +0530174 if (bf->bf_mpdu) {
175 dma_unmap_single(sc->dev, bf->bf_buf_addr,
176 common->rx_bufsize,
177 DMA_BIDIRECTIONAL);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400178 dev_kfree_skb_any(bf->bf_mpdu);
Mohammed Shafi Shajakhanba542382011-09-23 14:33:14 +0530179 bf->bf_buf_addr = 0;
180 bf->bf_mpdu = NULL;
181 }
Felix Fietkaub5c804752010-04-15 17:38:48 -0400182 }
183
184 INIT_LIST_HEAD(&sc->rx.rxbuf);
185
186 kfree(sc->rx.rx_bufptr);
187 sc->rx.rx_bufptr = NULL;
188}
189
190static void ath_rx_edma_init_queue(struct ath_rx_edma *rx_edma, int size)
191{
192 skb_queue_head_init(&rx_edma->rx_fifo);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400193 rx_edma->rx_fifo_hwsize = size;
194}
195
196static int ath_rx_edma_init(struct ath_softc *sc, int nbufs)
197{
198 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
199 struct ath_hw *ah = sc->sc_ah;
200 struct sk_buff *skb;
201 struct ath_buf *bf;
202 int error = 0, i;
203 u32 size;
204
Felix Fietkaub5c804752010-04-15 17:38:48 -0400205 ath9k_hw_set_rx_bufsize(ah, common->rx_bufsize -
206 ah->caps.rx_status_len);
207
208 ath_rx_edma_init_queue(&sc->rx.rx_edma[ATH9K_RX_QUEUE_LP],
209 ah->caps.rx_lp_qdepth);
210 ath_rx_edma_init_queue(&sc->rx.rx_edma[ATH9K_RX_QUEUE_HP],
211 ah->caps.rx_hp_qdepth);
212
213 size = sizeof(struct ath_buf) * nbufs;
214 bf = kzalloc(size, GFP_KERNEL);
215 if (!bf)
216 return -ENOMEM;
217
218 INIT_LIST_HEAD(&sc->rx.rxbuf);
219 sc->rx.rx_bufptr = bf;
220
221 for (i = 0; i < nbufs; i++, bf++) {
222 skb = ath_rxbuf_alloc(common, common->rx_bufsize, GFP_KERNEL);
223 if (!skb) {
224 error = -ENOMEM;
225 goto rx_init_fail;
226 }
227
228 memset(skb->data, 0, common->rx_bufsize);
229 bf->bf_mpdu = skb;
230
231 bf->bf_buf_addr = dma_map_single(sc->dev, skb->data,
232 common->rx_bufsize,
233 DMA_BIDIRECTIONAL);
234 if (unlikely(dma_mapping_error(sc->dev,
235 bf->bf_buf_addr))) {
236 dev_kfree_skb_any(skb);
237 bf->bf_mpdu = NULL;
Ben Greear6cf9e992010-10-14 12:45:30 -0700238 bf->bf_buf_addr = 0;
Joe Perches38002762010-12-02 19:12:36 -0800239 ath_err(common,
Felix Fietkaub5c804752010-04-15 17:38:48 -0400240 "dma_mapping_error() on RX init\n");
241 error = -ENOMEM;
242 goto rx_init_fail;
243 }
244
245 list_add_tail(&bf->list, &sc->rx.rxbuf);
246 }
247
248 return 0;
249
250rx_init_fail:
251 ath_rx_edma_cleanup(sc);
252 return error;
253}
254
255static void ath_edma_start_recv(struct ath_softc *sc)
256{
257 spin_lock_bh(&sc->rx.rxbuflock);
258
259 ath9k_hw_rxena(sc->sc_ah);
260
261 ath_rx_addbuffer_edma(sc, ATH9K_RX_QUEUE_HP,
262 sc->rx.rx_edma[ATH9K_RX_QUEUE_HP].rx_fifo_hwsize);
263
264 ath_rx_addbuffer_edma(sc, ATH9K_RX_QUEUE_LP,
265 sc->rx.rx_edma[ATH9K_RX_QUEUE_LP].rx_fifo_hwsize);
266
Felix Fietkaub5c804752010-04-15 17:38:48 -0400267 ath_opmode_init(sc);
268
Sujith Manoharan4cb54fa2012-06-04 16:27:52 +0530269 ath9k_hw_startpcureceive(sc->sc_ah, !!(sc->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL));
Luis R. Rodriguez7583c5502010-10-20 16:07:04 -0700270
271 spin_unlock_bh(&sc->rx.rxbuflock);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400272}
273
274static void ath_edma_stop_recv(struct ath_softc *sc)
275{
Felix Fietkaub5c804752010-04-15 17:38:48 -0400276 ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_HP);
277 ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_LP);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400278}
279
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700280int ath_rx_init(struct ath_softc *sc, int nbufs)
281{
Luis R. Rodriguez27c51f12009-09-10 11:08:14 -0700282 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700283 struct sk_buff *skb;
284 struct ath_buf *bf;
285 int error = 0;
286
Luis R. Rodriguez4bdd1e92010-10-26 15:27:24 -0700287 spin_lock_init(&sc->sc_pcu_lock);
Sujith797fe5cb2009-03-30 15:28:45 +0530288 spin_lock_init(&sc->rx.rxbuflock);
Sujith Manoharan781b14a2012-06-04 20:23:55 +0530289 clear_bit(SC_OP_RXFLUSH, &sc->sc_flags);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700290
Felix Fietkau0d955212011-01-26 18:23:27 +0100291 common->rx_bufsize = IEEE80211_MAX_MPDU_LEN / 2 +
292 sc->sc_ah->caps.rx_status_len;
293
Felix Fietkaub5c804752010-04-15 17:38:48 -0400294 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
295 return ath_rx_edma_init(sc, nbufs);
296 } else {
Joe Perchesd2182b62011-12-15 14:55:53 -0800297 ath_dbg(common, CONFIG, "cachelsz %u rxbufsize %u\n",
Joe Perches226afe62010-12-02 19:12:37 -0800298 common->cachelsz, common->rx_bufsize);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700299
Felix Fietkaub5c804752010-04-15 17:38:48 -0400300 /* Initialize rx descriptors */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700301
Felix Fietkaub5c804752010-04-15 17:38:48 -0400302 error = ath_descdma_setup(sc, &sc->rx.rxdma, &sc->rx.rxbuf,
Vasanthakumar Thiagarajan4adfcde2010-04-15 17:39:33 -0400303 "rx", nbufs, 1, 0);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400304 if (error != 0) {
Joe Perches38002762010-12-02 19:12:36 -0800305 ath_err(common,
306 "failed to allocate rx descriptors: %d\n",
307 error);
Sujith797fe5cb2009-03-30 15:28:45 +0530308 goto err;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700309 }
Felix Fietkaub5c804752010-04-15 17:38:48 -0400310
311 list_for_each_entry(bf, &sc->rx.rxbuf, list) {
312 skb = ath_rxbuf_alloc(common, common->rx_bufsize,
313 GFP_KERNEL);
314 if (skb == NULL) {
315 error = -ENOMEM;
316 goto err;
317 }
318
319 bf->bf_mpdu = skb;
320 bf->bf_buf_addr = dma_map_single(sc->dev, skb->data,
321 common->rx_bufsize,
322 DMA_FROM_DEVICE);
323 if (unlikely(dma_mapping_error(sc->dev,
324 bf->bf_buf_addr))) {
325 dev_kfree_skb_any(skb);
326 bf->bf_mpdu = NULL;
Ben Greear6cf9e992010-10-14 12:45:30 -0700327 bf->bf_buf_addr = 0;
Joe Perches38002762010-12-02 19:12:36 -0800328 ath_err(common,
329 "dma_mapping_error() on RX init\n");
Felix Fietkaub5c804752010-04-15 17:38:48 -0400330 error = -ENOMEM;
331 goto err;
332 }
Felix Fietkaub5c804752010-04-15 17:38:48 -0400333 }
334 sc->rx.rxlink = NULL;
Sujith797fe5cb2009-03-30 15:28:45 +0530335 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700336
Sujith797fe5cb2009-03-30 15:28:45 +0530337err:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700338 if (error)
339 ath_rx_cleanup(sc);
340
341 return error;
342}
343
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700344void ath_rx_cleanup(struct ath_softc *sc)
345{
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -0800346 struct ath_hw *ah = sc->sc_ah;
347 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700348 struct sk_buff *skb;
349 struct ath_buf *bf;
350
Felix Fietkaub5c804752010-04-15 17:38:48 -0400351 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
352 ath_rx_edma_cleanup(sc);
353 return;
354 } else {
355 list_for_each_entry(bf, &sc->rx.rxbuf, list) {
356 skb = bf->bf_mpdu;
357 if (skb) {
358 dma_unmap_single(sc->dev, bf->bf_buf_addr,
359 common->rx_bufsize,
360 DMA_FROM_DEVICE);
361 dev_kfree_skb(skb);
Ben Greear6cf9e992010-10-14 12:45:30 -0700362 bf->bf_buf_addr = 0;
363 bf->bf_mpdu = NULL;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400364 }
Luis R. Rodriguez051b9192009-03-23 18:25:01 -0400365 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700366
Felix Fietkaub5c804752010-04-15 17:38:48 -0400367 if (sc->rx.rxdma.dd_desc_len != 0)
368 ath_descdma_cleanup(sc, &sc->rx.rxdma, &sc->rx.rxbuf);
369 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700370}
371
372/*
373 * Calculate the receive filter according to the
374 * operating mode and state:
375 *
376 * o always accept unicast, broadcast, and multicast traffic
377 * o maintain current state of phy error reception (the hal
378 * may enable phy error frames for noise immunity work)
379 * o probe request frames are accepted only when operating in
380 * hostap, adhoc, or monitor modes
381 * o enable promiscuous mode according to the interface state
382 * o accept beacons:
383 * - when operating in adhoc mode so the 802.11 layer creates
384 * node table entries for peers,
385 * - when operating in station mode for collecting rssi data when
386 * the station is otherwise quiet, or
387 * - when operating as a repeater so we see repeater-sta beacons
388 * - when scanning
389 */
390
391u32 ath_calcrxfilter(struct ath_softc *sc)
392{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700393 u32 rfilt;
394
Felix Fietkauac066972011-10-08 15:49:57 +0200395 rfilt = ATH9K_RX_FILTER_UCAST | ATH9K_RX_FILTER_BCAST
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700396 | ATH9K_RX_FILTER_MCAST;
397
Jouni Malinen9c1d8e42010-10-13 17:29:31 +0300398 if (sc->rx.rxfilter & FIF_PROBE_REQ)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700399 rfilt |= ATH9K_RX_FILTER_PROBEREQ;
400
Jouni Malinen217ba9d2009-03-10 10:55:50 +0200401 /*
402 * Set promiscuous mode when FIF_PROMISC_IN_BSS is enabled for station
403 * mode interface or when in monitor mode. AP mode does not need this
404 * since it receives all in-BSS frames anyway.
405 */
Felix Fietkau2e286942011-03-09 01:48:12 +0100406 if (sc->sc_ah->is_monitoring)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700407 rfilt |= ATH9K_RX_FILTER_PROM;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700408
Sujithd42c6b72009-02-04 08:10:22 +0530409 if (sc->rx.rxfilter & FIF_CONTROL)
410 rfilt |= ATH9K_RX_FILTER_CONTROL;
411
Vasanthakumar Thiagarajandbaaa142009-02-19 15:41:52 +0530412 if ((sc->sc_ah->opmode == NL80211_IFTYPE_STATION) &&
Ben Greearcfda6692010-09-14 12:00:22 -0700413 (sc->nvifs <= 1) &&
Vasanthakumar Thiagarajandbaaa142009-02-19 15:41:52 +0530414 !(sc->rx.rxfilter & FIF_BCN_PRBRESP_PROMISC))
415 rfilt |= ATH9K_RX_FILTER_MYBEACON;
416 else
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700417 rfilt |= ATH9K_RX_FILTER_BEACON;
418
Felix Fietkau264bbec2011-04-07 19:24:23 +0200419 if ((sc->sc_ah->opmode == NL80211_IFTYPE_AP) ||
Senthil Balasubramanian66afad02009-09-18 15:06:07 +0530420 (sc->rx.rxfilter & FIF_PSPOLL))
Vasanthakumar Thiagarajandbaaa142009-02-19 15:41:52 +0530421 rfilt |= ATH9K_RX_FILTER_PSPOLL;
Sujithbe0418a2008-11-18 09:05:55 +0530422
Sujith7ea310b2009-09-03 12:08:43 +0530423 if (conf_is_ht(&sc->hw->conf))
424 rfilt |= ATH9K_RX_FILTER_COMP_BAR;
425
Felix Fietkau7545daf2011-01-24 19:23:16 +0100426 if (sc->nvifs > 1 || (sc->rx.rxfilter & FIF_OTHER_BSS)) {
Javier Cardona5eb6ba82009-08-20 19:12:07 -0700427 /* The following may also be needed for other older chips */
428 if (sc->sc_ah->hw_version.macVersion == AR_SREV_VERSION_9160)
429 rfilt |= ATH9K_RX_FILTER_PROM;
Jouni Malinenb93bce22009-03-03 19:23:30 +0200430 rfilt |= ATH9K_RX_FILTER_MCAST_BCAST_ALL;
431 }
432
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700433 return rfilt;
Sujith7dcfdcd2008-08-11 14:03:13 +0530434
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700435}
436
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700437int ath_startrecv(struct ath_softc *sc)
438{
Sujithcbe61d82009-02-09 13:27:12 +0530439 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700440 struct ath_buf *bf, *tbf;
441
Felix Fietkaub5c804752010-04-15 17:38:48 -0400442 if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
443 ath_edma_start_recv(sc);
444 return 0;
445 }
446
Sujithb77f4832008-12-07 21:44:03 +0530447 spin_lock_bh(&sc->rx.rxbuflock);
448 if (list_empty(&sc->rx.rxbuf))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700449 goto start_recv;
450
Sujithb77f4832008-12-07 21:44:03 +0530451 sc->rx.rxlink = NULL;
452 list_for_each_entry_safe(bf, tbf, &sc->rx.rxbuf, list) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700453 ath_rx_buf_link(sc, bf);
454 }
455
456 /* We could have deleted elements so the list may be empty now */
Sujithb77f4832008-12-07 21:44:03 +0530457 if (list_empty(&sc->rx.rxbuf))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700458 goto start_recv;
459
Sujithb77f4832008-12-07 21:44:03 +0530460 bf = list_first_entry(&sc->rx.rxbuf, struct ath_buf, list);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700461 ath9k_hw_putrxbuf(ah, bf->bf_daddr);
Sujithbe0418a2008-11-18 09:05:55 +0530462 ath9k_hw_rxena(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700463
464start_recv:
Sujithbe0418a2008-11-18 09:05:55 +0530465 ath_opmode_init(sc);
Sujith Manoharan4cb54fa2012-06-04 16:27:52 +0530466 ath9k_hw_startpcureceive(ah, !!(sc->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL));
Sujithbe0418a2008-11-18 09:05:55 +0530467
Luis R. Rodriguez7583c5502010-10-20 16:07:04 -0700468 spin_unlock_bh(&sc->rx.rxbuflock);
469
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700470 return 0;
471}
472
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700473bool ath_stoprecv(struct ath_softc *sc)
474{
Sujithcbe61d82009-02-09 13:27:12 +0530475 struct ath_hw *ah = sc->sc_ah;
Felix Fietkau5882da022011-04-08 20:13:18 +0200476 bool stopped, reset = false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700477
Luis R. Rodriguez1e450282010-10-20 16:07:03 -0700478 spin_lock_bh(&sc->rx.rxbuflock);
Felix Fietkaud47844a2010-11-20 03:08:47 +0100479 ath9k_hw_abortpcurecv(ah);
Sujithbe0418a2008-11-18 09:05:55 +0530480 ath9k_hw_setrxfilter(ah, 0);
Felix Fietkau5882da022011-04-08 20:13:18 +0200481 stopped = ath9k_hw_stopdmarecv(ah, &reset);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400482
483 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
484 ath_edma_stop_recv(sc);
485 else
486 sc->rx.rxlink = NULL;
Luis R. Rodriguez1e450282010-10-20 16:07:03 -0700487 spin_unlock_bh(&sc->rx.rxbuflock);
Sujithbe0418a2008-11-18 09:05:55 +0530488
Rajkumar Manoharand5847472010-12-20 14:39:51 +0530489 if (!(ah->ah_flags & AH_UNPLUGGED) &&
490 unlikely(!stopped)) {
Ben Greeard7fd1b502010-12-06 13:13:07 -0800491 ath_err(ath9k_hw_common(sc->sc_ah),
492 "Could not stop RX, we could be "
493 "confusing the DMA engine when we start RX up\n");
494 ATH_DBG_WARN_ON_ONCE(!stopped);
495 }
Felix Fietkau2232d312011-04-15 00:41:43 +0200496 return stopped && !reset;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700497}
498
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700499void ath_flushrecv(struct ath_softc *sc)
500{
Sujith Manoharan781b14a2012-06-04 20:23:55 +0530501 set_bit(SC_OP_RXFLUSH, &sc->sc_flags);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400502 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
503 ath_rx_tasklet(sc, 1, true);
504 ath_rx_tasklet(sc, 1, false);
Sujith Manoharan781b14a2012-06-04 20:23:55 +0530505 clear_bit(SC_OP_RXFLUSH, &sc->sc_flags);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700506}
507
Jouni Malinencc659652009-05-14 21:28:48 +0300508static bool ath_beacon_dtim_pending_cab(struct sk_buff *skb)
509{
510 /* Check whether the Beacon frame has DTIM indicating buffered bc/mc */
511 struct ieee80211_mgmt *mgmt;
512 u8 *pos, *end, id, elen;
513 struct ieee80211_tim_ie *tim;
514
515 mgmt = (struct ieee80211_mgmt *)skb->data;
516 pos = mgmt->u.beacon.variable;
517 end = skb->data + skb->len;
518
519 while (pos + 2 < end) {
520 id = *pos++;
521 elen = *pos++;
522 if (pos + elen > end)
523 break;
524
525 if (id == WLAN_EID_TIM) {
526 if (elen < sizeof(*tim))
527 break;
528 tim = (struct ieee80211_tim_ie *) pos;
529 if (tim->dtim_count != 0)
530 break;
531 return tim->bitmap_ctrl & 0x01;
532 }
533
534 pos += elen;
535 }
536
537 return false;
538}
539
Jouni Malinencc659652009-05-14 21:28:48 +0300540static void ath_rx_ps_beacon(struct ath_softc *sc, struct sk_buff *skb)
541{
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700542 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Jouni Malinencc659652009-05-14 21:28:48 +0300543
544 if (skb->len < 24 + 8 + 2 + 2)
545 return;
546
Sujith1b04b932010-01-08 10:36:05 +0530547 sc->ps_flags &= ~PS_WAIT_FOR_BEACON;
Gabor Juhos293dc5d2009-06-19 12:17:48 +0200548
Sujith1b04b932010-01-08 10:36:05 +0530549 if (sc->ps_flags & PS_BEACON_SYNC) {
550 sc->ps_flags &= ~PS_BEACON_SYNC;
Joe Perchesd2182b62011-12-15 14:55:53 -0800551 ath_dbg(common, PS,
Joe Perches226afe62010-12-02 19:12:37 -0800552 "Reconfigure Beacon timers based on timestamp from the AP\n");
Rajkumar Manoharan99e4d432011-04-04 22:56:19 +0530553 ath_set_beacon(sc);
Jouni Malinenccdfeab2009-05-20 21:59:08 +0300554 }
555
Jouni Malinencc659652009-05-14 21:28:48 +0300556 if (ath_beacon_dtim_pending_cab(skb)) {
557 /*
558 * Remain awake waiting for buffered broadcast/multicast
Gabor Juhos58f5fff2009-06-17 20:53:20 +0200559 * frames. If the last broadcast/multicast frame is not
560 * received properly, the next beacon frame will work as
561 * a backup trigger for returning into NETWORK SLEEP state,
562 * so we are waiting for it as well.
Jouni Malinencc659652009-05-14 21:28:48 +0300563 */
Joe Perchesd2182b62011-12-15 14:55:53 -0800564 ath_dbg(common, PS,
Joe Perches226afe62010-12-02 19:12:37 -0800565 "Received DTIM beacon indicating buffered broadcast/multicast frame(s)\n");
Sujith1b04b932010-01-08 10:36:05 +0530566 sc->ps_flags |= PS_WAIT_FOR_CAB | PS_WAIT_FOR_BEACON;
Jouni Malinencc659652009-05-14 21:28:48 +0300567 return;
568 }
569
Sujith1b04b932010-01-08 10:36:05 +0530570 if (sc->ps_flags & PS_WAIT_FOR_CAB) {
Jouni Malinencc659652009-05-14 21:28:48 +0300571 /*
572 * This can happen if a broadcast frame is dropped or the AP
573 * fails to send a frame indicating that all CAB frames have
574 * been delivered.
575 */
Sujith1b04b932010-01-08 10:36:05 +0530576 sc->ps_flags &= ~PS_WAIT_FOR_CAB;
Joe Perchesd2182b62011-12-15 14:55:53 -0800577 ath_dbg(common, PS, "PS wait for CAB frames timed out\n");
Jouni Malinencc659652009-05-14 21:28:48 +0300578 }
Jouni Malinencc659652009-05-14 21:28:48 +0300579}
580
Rajkumar Manoharanf73c6042011-09-26 22:16:56 +0530581static void ath_rx_ps(struct ath_softc *sc, struct sk_buff *skb, bool mybeacon)
Jouni Malinencc659652009-05-14 21:28:48 +0300582{
583 struct ieee80211_hdr *hdr;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700584 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Jouni Malinencc659652009-05-14 21:28:48 +0300585
586 hdr = (struct ieee80211_hdr *)skb->data;
587
588 /* Process Beacon and CAB receive in PS state */
Vasanthakumar Thiagarajanededf1f2010-05-22 23:58:13 -0700589 if (((sc->ps_flags & PS_WAIT_FOR_BEACON) || ath9k_check_auto_sleep(sc))
Sujith Manoharan07c15a32012-06-04 20:24:07 +0530590 && mybeacon) {
Jouni Malinencc659652009-05-14 21:28:48 +0300591 ath_rx_ps_beacon(sc, skb);
Sujith Manoharan07c15a32012-06-04 20:24:07 +0530592 } else if ((sc->ps_flags & PS_WAIT_FOR_CAB) &&
593 (ieee80211_is_data(hdr->frame_control) ||
594 ieee80211_is_action(hdr->frame_control)) &&
595 is_multicast_ether_addr(hdr->addr1) &&
596 !ieee80211_has_moredata(hdr->frame_control)) {
Jouni Malinencc659652009-05-14 21:28:48 +0300597 /*
598 * No more broadcast/multicast frames to be received at this
599 * point.
600 */
Senthil Balasubramanian3fac6df2010-09-16 15:12:35 -0400601 sc->ps_flags &= ~(PS_WAIT_FOR_CAB | PS_WAIT_FOR_BEACON);
Joe Perchesd2182b62011-12-15 14:55:53 -0800602 ath_dbg(common, PS,
Joe Perches226afe62010-12-02 19:12:37 -0800603 "All PS CAB frames received, back to sleep\n");
Sujith1b04b932010-01-08 10:36:05 +0530604 } else if ((sc->ps_flags & PS_WAIT_FOR_PSPOLL_DATA) &&
Jouni Malinen9a23f9c2009-05-19 17:01:38 +0300605 !is_multicast_ether_addr(hdr->addr1) &&
606 !ieee80211_has_morefrags(hdr->frame_control)) {
Sujith1b04b932010-01-08 10:36:05 +0530607 sc->ps_flags &= ~PS_WAIT_FOR_PSPOLL_DATA;
Joe Perchesd2182b62011-12-15 14:55:53 -0800608 ath_dbg(common, PS,
Joe Perches226afe62010-12-02 19:12:37 -0800609 "Going back to sleep after having received PS-Poll data (0x%lx)\n",
Sujith1b04b932010-01-08 10:36:05 +0530610 sc->ps_flags & (PS_WAIT_FOR_BEACON |
611 PS_WAIT_FOR_CAB |
612 PS_WAIT_FOR_PSPOLL_DATA |
613 PS_WAIT_FOR_TX_ACK));
Jouni Malinencc659652009-05-14 21:28:48 +0300614 }
615}
616
Felix Fietkaub5c804752010-04-15 17:38:48 -0400617static bool ath_edma_get_buffers(struct ath_softc *sc,
Felix Fietkau3a2923e2012-03-03 15:17:05 +0100618 enum ath9k_rx_qtype qtype,
619 struct ath_rx_status *rs,
620 struct ath_buf **dest)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700621{
Felix Fietkaub5c804752010-04-15 17:38:48 -0400622 struct ath_rx_edma *rx_edma = &sc->rx.rx_edma[qtype];
623 struct ath_hw *ah = sc->sc_ah;
624 struct ath_common *common = ath9k_hw_common(ah);
625 struct sk_buff *skb;
Sujithbe0418a2008-11-18 09:05:55 +0530626 struct ath_buf *bf;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400627 int ret;
628
629 skb = skb_peek(&rx_edma->rx_fifo);
630 if (!skb)
631 return false;
632
633 bf = SKB_CB_ATHBUF(skb);
634 BUG_ON(!bf);
635
Ming Leice9426d2010-05-15 18:25:40 +0800636 dma_sync_single_for_cpu(sc->dev, bf->bf_buf_addr,
Felix Fietkaub5c804752010-04-15 17:38:48 -0400637 common->rx_bufsize, DMA_FROM_DEVICE);
638
Felix Fietkau3a2923e2012-03-03 15:17:05 +0100639 ret = ath9k_hw_process_rxdesc_edma(ah, rs, skb->data);
Ming Leice9426d2010-05-15 18:25:40 +0800640 if (ret == -EINPROGRESS) {
641 /*let device gain the buffer again*/
642 dma_sync_single_for_device(sc->dev, bf->bf_buf_addr,
643 common->rx_bufsize, DMA_FROM_DEVICE);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400644 return false;
Ming Leice9426d2010-05-15 18:25:40 +0800645 }
Felix Fietkaub5c804752010-04-15 17:38:48 -0400646
647 __skb_unlink(skb, &rx_edma->rx_fifo);
648 if (ret == -EINVAL) {
649 /* corrupt descriptor, skip this one and the following one */
650 list_add_tail(&bf->list, &sc->rx.rxbuf);
651 ath_rx_edma_buf_link(sc, qtype);
Felix Fietkau3a2923e2012-03-03 15:17:05 +0100652
Felix Fietkaub5c804752010-04-15 17:38:48 -0400653 skb = skb_peek(&rx_edma->rx_fifo);
Felix Fietkau3a2923e2012-03-03 15:17:05 +0100654 if (skb) {
655 bf = SKB_CB_ATHBUF(skb);
656 BUG_ON(!bf);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400657
Felix Fietkau3a2923e2012-03-03 15:17:05 +0100658 __skb_unlink(skb, &rx_edma->rx_fifo);
659 list_add_tail(&bf->list, &sc->rx.rxbuf);
660 ath_rx_edma_buf_link(sc, qtype);
661 } else {
662 bf = NULL;
663 }
Felix Fietkaub5c804752010-04-15 17:38:48 -0400664 }
Felix Fietkaub5c804752010-04-15 17:38:48 -0400665
Felix Fietkau3a2923e2012-03-03 15:17:05 +0100666 *dest = bf;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400667 return true;
668}
669
670static struct ath_buf *ath_edma_get_next_rx_buf(struct ath_softc *sc,
671 struct ath_rx_status *rs,
672 enum ath9k_rx_qtype qtype)
673{
Felix Fietkau3a2923e2012-03-03 15:17:05 +0100674 struct ath_buf *bf = NULL;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400675
Felix Fietkau3a2923e2012-03-03 15:17:05 +0100676 while (ath_edma_get_buffers(sc, qtype, rs, &bf)) {
677 if (!bf)
678 continue;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400679
Felix Fietkau3a2923e2012-03-03 15:17:05 +0100680 return bf;
681 }
682 return NULL;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400683}
684
685static struct ath_buf *ath_get_next_rx_buf(struct ath_softc *sc,
686 struct ath_rx_status *rs)
687{
688 struct ath_hw *ah = sc->sc_ah;
689 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700690 struct ath_desc *ds;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400691 struct ath_buf *bf;
692 int ret;
693
694 if (list_empty(&sc->rx.rxbuf)) {
695 sc->rx.rxlink = NULL;
696 return NULL;
697 }
698
699 bf = list_first_entry(&sc->rx.rxbuf, struct ath_buf, list);
700 ds = bf->bf_desc;
701
702 /*
703 * Must provide the virtual address of the current
704 * descriptor, the physical address, and the virtual
705 * address of the next descriptor in the h/w chain.
706 * This allows the HAL to look ahead to see if the
707 * hardware is done with a descriptor by checking the
708 * done bit in the following descriptor and the address
709 * of the current descriptor the DMA engine is working
710 * on. All this is necessary because of our use of
711 * a self-linked list to avoid rx overruns.
712 */
Rajkumar Manoharan3de21112011-08-13 10:28:11 +0530713 ret = ath9k_hw_rxprocdesc(ah, ds, rs);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400714 if (ret == -EINPROGRESS) {
715 struct ath_rx_status trs;
716 struct ath_buf *tbf;
717 struct ath_desc *tds;
718
719 memset(&trs, 0, sizeof(trs));
720 if (list_is_last(&bf->list, &sc->rx.rxbuf)) {
721 sc->rx.rxlink = NULL;
722 return NULL;
723 }
724
725 tbf = list_entry(bf->list.next, struct ath_buf, list);
726
727 /*
728 * On some hardware the descriptor status words could
729 * get corrupted, including the done bit. Because of
730 * this, check if the next descriptor's done bit is
731 * set or not.
732 *
733 * If the next descriptor's done bit is set, the current
734 * descriptor has been corrupted. Force s/w to discard
735 * this descriptor and continue...
736 */
737
738 tds = tbf->bf_desc;
Rajkumar Manoharan3de21112011-08-13 10:28:11 +0530739 ret = ath9k_hw_rxprocdesc(ah, tds, &trs);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400740 if (ret == -EINPROGRESS)
741 return NULL;
742 }
743
744 if (!bf->bf_mpdu)
745 return bf;
746
747 /*
748 * Synchronize the DMA transfer with CPU before
749 * 1. accessing the frame
750 * 2. requeueing the same buffer to h/w
751 */
Ming Leice9426d2010-05-15 18:25:40 +0800752 dma_sync_single_for_cpu(sc->dev, bf->bf_buf_addr,
Felix Fietkaub5c804752010-04-15 17:38:48 -0400753 common->rx_bufsize,
754 DMA_FROM_DEVICE);
755
756 return bf;
757}
758
Sujithd4357002010-05-20 15:34:38 +0530759/* Assumes you've already done the endian to CPU conversion */
760static bool ath9k_rx_accept(struct ath_common *common,
Vasanthakumar Thiagarajan9f167f62010-05-20 14:34:46 -0700761 struct ieee80211_hdr *hdr,
Sujithd4357002010-05-20 15:34:38 +0530762 struct ieee80211_rx_status *rxs,
763 struct ath_rx_status *rx_stats,
764 bool *decrypt_error)
765{
Felix Fietkauec205992011-10-08 22:02:59 +0200766 struct ath_softc *sc = (struct ath_softc *) common->priv;
Felix Fietkau66760ea2011-07-13 23:35:05 +0800767 bool is_mc, is_valid_tkip, strip_mic, mic_error;
Sujithd4357002010-05-20 15:34:38 +0530768 struct ath_hw *ah = common->ah;
Sujithd4357002010-05-20 15:34:38 +0530769 __le16 fc;
Vasanthakumar Thiagarajanb7b1b512010-05-20 14:34:48 -0700770 u8 rx_status_len = ah->caps.rx_status_len;
Sujithd4357002010-05-20 15:34:38 +0530771
Sujithd4357002010-05-20 15:34:38 +0530772 fc = hdr->frame_control;
773
Felix Fietkau66760ea2011-07-13 23:35:05 +0800774 is_mc = !!is_multicast_ether_addr(hdr->addr1);
775 is_valid_tkip = rx_stats->rs_keyix != ATH9K_RXKEYIX_INVALID &&
776 test_bit(rx_stats->rs_keyix, common->tkip_keymap);
Bill Jordan152e5852011-08-19 11:10:22 -0400777 strip_mic = is_valid_tkip && ieee80211_is_data(fc) &&
Michael Liang2a5783b2012-04-20 17:11:57 +0800778 ieee80211_has_protected(fc) &&
Bill Jordan152e5852011-08-19 11:10:22 -0400779 !(rx_stats->rs_status &
Felix Fietkau846d9362011-10-08 22:02:58 +0200780 (ATH9K_RXERR_DECRYPT | ATH9K_RXERR_CRC | ATH9K_RXERR_MIC |
781 ATH9K_RXERR_KEYMISS));
Felix Fietkau66760ea2011-07-13 23:35:05 +0800782
Felix Fietkauf88373f2012-02-05 21:15:17 +0100783 /*
784 * Key miss events are only relevant for pairwise keys where the
785 * descriptor does contain a valid key index. This has been observed
786 * mostly with CCMP encryption.
787 */
788 if (rx_stats->rs_keyix == ATH9K_RXKEYIX_INVALID)
789 rx_stats->rs_status &= ~ATH9K_RXERR_KEYMISS;
790
Ben Greear15072182012-04-03 09:18:59 -0700791 if (!rx_stats->rs_datalen) {
792 RX_STAT_INC(rx_len_err);
Sujithd4357002010-05-20 15:34:38 +0530793 return false;
Ben Greear15072182012-04-03 09:18:59 -0700794 }
795
Sujithd4357002010-05-20 15:34:38 +0530796 /*
797 * rs_status follows rs_datalen so if rs_datalen is too large
798 * we can take a hint that hardware corrupted it, so ignore
799 * those frames.
800 */
Ben Greear15072182012-04-03 09:18:59 -0700801 if (rx_stats->rs_datalen > (common->rx_bufsize - rx_status_len)) {
802 RX_STAT_INC(rx_len_err);
Sujithd4357002010-05-20 15:34:38 +0530803 return false;
Ben Greear15072182012-04-03 09:18:59 -0700804 }
Sujithd4357002010-05-20 15:34:38 +0530805
Felix Fietkau0d955212011-01-26 18:23:27 +0100806 /* Only use error bits from the last fragment */
Sujithd4357002010-05-20 15:34:38 +0530807 if (rx_stats->rs_more)
Felix Fietkau0d955212011-01-26 18:23:27 +0100808 return true;
Sujithd4357002010-05-20 15:34:38 +0530809
Felix Fietkau66760ea2011-07-13 23:35:05 +0800810 mic_error = is_valid_tkip && !ieee80211_is_ctl(fc) &&
811 !ieee80211_has_morefrags(fc) &&
812 !(le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG) &&
813 (rx_stats->rs_status & ATH9K_RXERR_MIC);
814
Sujithd4357002010-05-20 15:34:38 +0530815 /*
816 * The rx_stats->rs_status will not be set until the end of the
817 * chained descriptors so it can be ignored if rs_more is set. The
818 * rs_more will be false at the last element of the chained
819 * descriptors.
820 */
821 if (rx_stats->rs_status != 0) {
Felix Fietkau846d9362011-10-08 22:02:58 +0200822 u8 status_mask;
823
Felix Fietkau66760ea2011-07-13 23:35:05 +0800824 if (rx_stats->rs_status & ATH9K_RXERR_CRC) {
Sujithd4357002010-05-20 15:34:38 +0530825 rxs->flag |= RX_FLAG_FAILED_FCS_CRC;
Felix Fietkau66760ea2011-07-13 23:35:05 +0800826 mic_error = false;
827 }
Sujithd4357002010-05-20 15:34:38 +0530828 if (rx_stats->rs_status & ATH9K_RXERR_PHY)
829 return false;
830
Felix Fietkau846d9362011-10-08 22:02:58 +0200831 if ((rx_stats->rs_status & ATH9K_RXERR_DECRYPT) ||
832 (!is_mc && (rx_stats->rs_status & ATH9K_RXERR_KEYMISS))) {
Sujithd4357002010-05-20 15:34:38 +0530833 *decrypt_error = true;
Felix Fietkau66760ea2011-07-13 23:35:05 +0800834 mic_error = false;
Sujithd4357002010-05-20 15:34:38 +0530835 }
Felix Fietkau66760ea2011-07-13 23:35:05 +0800836
Sujithd4357002010-05-20 15:34:38 +0530837 /*
838 * Reject error frames with the exception of
839 * decryption and MIC failures. For monitor mode,
840 * we also ignore the CRC error.
841 */
Felix Fietkau846d9362011-10-08 22:02:58 +0200842 status_mask = ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC |
843 ATH9K_RXERR_KEYMISS;
844
Felix Fietkauec205992011-10-08 22:02:59 +0200845 if (ah->is_monitoring && (sc->rx.rxfilter & FIF_FCSFAIL))
Felix Fietkau846d9362011-10-08 22:02:58 +0200846 status_mask |= ATH9K_RXERR_CRC;
847
848 if (rx_stats->rs_status & ~status_mask)
849 return false;
Sujithd4357002010-05-20 15:34:38 +0530850 }
Felix Fietkau66760ea2011-07-13 23:35:05 +0800851
852 /*
853 * For unicast frames the MIC error bit can have false positives,
854 * so all MIC error reports need to be validated in software.
855 * False negatives are not common, so skip software verification
856 * if the hardware considers the MIC valid.
857 */
858 if (strip_mic)
859 rxs->flag |= RX_FLAG_MMIC_STRIPPED;
860 else if (is_mc && mic_error)
861 rxs->flag |= RX_FLAG_MMIC_ERROR;
862
Sujithd4357002010-05-20 15:34:38 +0530863 return true;
864}
865
866static int ath9k_process_rate(struct ath_common *common,
867 struct ieee80211_hw *hw,
868 struct ath_rx_status *rx_stats,
Vasanthakumar Thiagarajan9f167f62010-05-20 14:34:46 -0700869 struct ieee80211_rx_status *rxs)
Sujithd4357002010-05-20 15:34:38 +0530870{
871 struct ieee80211_supported_band *sband;
872 enum ieee80211_band band;
873 unsigned int i = 0;
Ben Greear990e08a2012-04-17 15:19:03 -0700874 struct ath_softc __maybe_unused *sc = common->priv;
Sujithd4357002010-05-20 15:34:38 +0530875
876 band = hw->conf.channel->band;
877 sband = hw->wiphy->bands[band];
878
879 if (rx_stats->rs_rate & 0x80) {
880 /* HT rate */
881 rxs->flag |= RX_FLAG_HT;
882 if (rx_stats->rs_flags & ATH9K_RX_2040)
883 rxs->flag |= RX_FLAG_40MHZ;
884 if (rx_stats->rs_flags & ATH9K_RX_GI)
885 rxs->flag |= RX_FLAG_SHORT_GI;
886 rxs->rate_idx = rx_stats->rs_rate & 0x7f;
887 return 0;
888 }
889
890 for (i = 0; i < sband->n_bitrates; i++) {
891 if (sband->bitrates[i].hw_value == rx_stats->rs_rate) {
892 rxs->rate_idx = i;
893 return 0;
894 }
895 if (sband->bitrates[i].hw_value_short == rx_stats->rs_rate) {
896 rxs->flag |= RX_FLAG_SHORTPRE;
897 rxs->rate_idx = i;
898 return 0;
899 }
900 }
901
902 /*
903 * No valid hardware bitrate found -- we should not get here
904 * because hardware has already validated this frame as OK.
905 */
Joe Perchesd2182b62011-12-15 14:55:53 -0800906 ath_dbg(common, ANY,
Joe Perches226afe62010-12-02 19:12:37 -0800907 "unsupported hw bitrate detected 0x%02x using 1 Mbit\n",
908 rx_stats->rs_rate);
Ben Greear15072182012-04-03 09:18:59 -0700909 RX_STAT_INC(rx_rate_err);
Sujithd4357002010-05-20 15:34:38 +0530910 return -EINVAL;
911}
912
913static void ath9k_process_rssi(struct ath_common *common,
914 struct ieee80211_hw *hw,
Vasanthakumar Thiagarajan9f167f62010-05-20 14:34:46 -0700915 struct ieee80211_hdr *hdr,
Sujithd4357002010-05-20 15:34:38 +0530916 struct ath_rx_status *rx_stats)
917{
Felix Fietkau9ac586152011-01-24 19:23:18 +0100918 struct ath_softc *sc = hw->priv;
Sujithd4357002010-05-20 15:34:38 +0530919 struct ath_hw *ah = common->ah;
Felix Fietkau9fa23e12010-10-15 20:03:31 +0200920 int last_rssi;
Felix Fietkau2ef16752012-03-03 15:17:06 +0100921 int rssi = rx_stats->rs_rssi;
Sujithd4357002010-05-20 15:34:38 +0530922
Rajkumar Manoharancf3af742011-08-27 16:17:47 +0530923 if (!rx_stats->is_mybeacon ||
924 ((ah->opmode != NL80211_IFTYPE_STATION) &&
925 (ah->opmode != NL80211_IFTYPE_ADHOC)))
Felix Fietkau9fa23e12010-10-15 20:03:31 +0200926 return;
927
Felix Fietkau9fa23e12010-10-15 20:03:31 +0200928 if (rx_stats->rs_rssi != ATH9K_RSSI_BAD && !rx_stats->rs_moreaggr)
Felix Fietkau9ac586152011-01-24 19:23:18 +0100929 ATH_RSSI_LPF(sc->last_rssi, rx_stats->rs_rssi);
Ben Greear686b9cb2010-09-23 09:44:36 -0700930
Felix Fietkau9ac586152011-01-24 19:23:18 +0100931 last_rssi = sc->last_rssi;
Sujithd4357002010-05-20 15:34:38 +0530932 if (likely(last_rssi != ATH_RSSI_DUMMY_MARKER))
Felix Fietkau2ef16752012-03-03 15:17:06 +0100933 rssi = ATH_EP_RND(last_rssi, ATH_RSSI_EP_MULTIPLIER);
934 if (rssi < 0)
935 rssi = 0;
Sujithd4357002010-05-20 15:34:38 +0530936
937 /* Update Beacon RSSI, this is used by ANI. */
Felix Fietkau2ef16752012-03-03 15:17:06 +0100938 ah->stats.avgbrssi = rssi;
Sujithd4357002010-05-20 15:34:38 +0530939}
940
941/*
942 * For Decrypt or Demic errors, we only mark packet status here and always push
943 * up the frame up to let mac80211 handle the actual error case, be it no
944 * decryption key or real decryption error. This let us keep statistics there.
945 */
946static int ath9k_rx_skb_preprocess(struct ath_common *common,
947 struct ieee80211_hw *hw,
Vasanthakumar Thiagarajan9f167f62010-05-20 14:34:46 -0700948 struct ieee80211_hdr *hdr,
Sujithd4357002010-05-20 15:34:38 +0530949 struct ath_rx_status *rx_stats,
950 struct ieee80211_rx_status *rx_status,
951 bool *decrypt_error)
952{
Felix Fietkauf749b942011-07-28 14:08:57 +0200953 struct ath_hw *ah = common->ah;
954
Sujithd4357002010-05-20 15:34:38 +0530955 /*
956 * everything but the rate is checked here, the rate check is done
957 * separately to avoid doing two lookups for a rate for each frame.
958 */
Vasanthakumar Thiagarajan9f167f62010-05-20 14:34:46 -0700959 if (!ath9k_rx_accept(common, hdr, rx_status, rx_stats, decrypt_error))
Sujithd4357002010-05-20 15:34:38 +0530960 return -EINVAL;
961
Felix Fietkau0d955212011-01-26 18:23:27 +0100962 /* Only use status info from the last fragment */
963 if (rx_stats->rs_more)
964 return 0;
965
Vasanthakumar Thiagarajan9f167f62010-05-20 14:34:46 -0700966 ath9k_process_rssi(common, hw, hdr, rx_stats);
Sujithd4357002010-05-20 15:34:38 +0530967
Vasanthakumar Thiagarajan9f167f62010-05-20 14:34:46 -0700968 if (ath9k_process_rate(common, hw, rx_stats, rx_status))
Sujithd4357002010-05-20 15:34:38 +0530969 return -EINVAL;
970
Sujithd4357002010-05-20 15:34:38 +0530971 rx_status->band = hw->conf.channel->band;
972 rx_status->freq = hw->conf.channel->center_freq;
Felix Fietkauf749b942011-07-28 14:08:57 +0200973 rx_status->signal = ah->noise + rx_stats->rs_rssi;
Sujithd4357002010-05-20 15:34:38 +0530974 rx_status->antenna = rx_stats->rs_antenna;
Johannes Berg6ebacbb2011-02-23 15:06:08 +0100975 rx_status->flag |= RX_FLAG_MACTIME_MPDU;
Felix Fietkau2ef16752012-03-03 15:17:06 +0100976 if (rx_stats->rs_moreaggr)
977 rx_status->flag |= RX_FLAG_NO_SIGNAL_VAL;
Sujithd4357002010-05-20 15:34:38 +0530978
979 return 0;
980}
981
982static void ath9k_rx_skb_postprocess(struct ath_common *common,
983 struct sk_buff *skb,
984 struct ath_rx_status *rx_stats,
985 struct ieee80211_rx_status *rxs,
986 bool decrypt_error)
987{
988 struct ath_hw *ah = common->ah;
989 struct ieee80211_hdr *hdr;
990 int hdrlen, padpos, padsize;
991 u8 keyix;
992 __le16 fc;
993
994 /* see if any padding is done by the hw and remove it */
995 hdr = (struct ieee80211_hdr *) skb->data;
996 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
997 fc = hdr->frame_control;
998 padpos = ath9k_cmn_padpos(hdr->frame_control);
999
1000 /* The MAC header is padded to have 32-bit boundary if the
1001 * packet payload is non-zero. The general calculation for
1002 * padsize would take into account odd header lengths:
1003 * padsize = (4 - padpos % 4) % 4; However, since only
1004 * even-length headers are used, padding can only be 0 or 2
1005 * bytes and we can optimize this a bit. In addition, we must
1006 * not try to remove padding from short control frames that do
1007 * not have payload. */
1008 padsize = padpos & 3;
1009 if (padsize && skb->len>=padpos+padsize+FCS_LEN) {
1010 memmove(skb->data + padsize, skb->data, padpos);
1011 skb_pull(skb, padsize);
1012 }
1013
1014 keyix = rx_stats->rs_keyix;
1015
1016 if (!(keyix == ATH9K_RXKEYIX_INVALID) && !decrypt_error &&
1017 ieee80211_has_protected(fc)) {
1018 rxs->flag |= RX_FLAG_DECRYPTED;
1019 } else if (ieee80211_has_protected(fc)
1020 && !decrypt_error && skb->len >= hdrlen + 4) {
1021 keyix = skb->data[hdrlen + 3] >> 6;
1022
1023 if (test_bit(keyix, common->keymap))
1024 rxs->flag |= RX_FLAG_DECRYPTED;
1025 }
1026 if (ah->sw_mgmt_crypto &&
1027 (rxs->flag & RX_FLAG_DECRYPTED) &&
1028 ieee80211_is_mgmt(fc))
1029 /* Use software decrypt for management frames. */
1030 rxs->flag &= ~RX_FLAG_DECRYPTED;
1031}
Felix Fietkaub5c804752010-04-15 17:38:48 -04001032
1033int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp)
1034{
1035 struct ath_buf *bf;
Felix Fietkau0d955212011-01-26 18:23:27 +01001036 struct sk_buff *skb = NULL, *requeue_skb, *hdr_skb;
Luis R. Rodriguez5ca42622009-11-04 08:20:42 -08001037 struct ieee80211_rx_status *rxs;
Sujithcbe61d82009-02-09 13:27:12 +05301038 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez27c51f12009-09-10 11:08:14 -07001039 struct ath_common *common = ath9k_hw_common(ah);
Felix Fietkau7545daf2011-01-24 19:23:16 +01001040 struct ieee80211_hw *hw = sc->hw;
Sujithbe0418a2008-11-18 09:05:55 +05301041 struct ieee80211_hdr *hdr;
Luis R. Rodriguezc9b14172009-11-04 16:47:22 -08001042 int retval;
Sujithbe0418a2008-11-18 09:05:55 +05301043 bool decrypt_error = false;
Felix Fietkau29bffa92010-03-29 20:14:23 -07001044 struct ath_rx_status rs;
Felix Fietkaub5c804752010-04-15 17:38:48 -04001045 enum ath9k_rx_qtype qtype;
1046 bool edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA);
1047 int dma_type;
Vasanthakumar Thiagarajan5c6dd922010-05-20 14:34:47 -07001048 u8 rx_status_len = ah->caps.rx_status_len;
Felix Fietkaua6d20552010-06-12 00:33:54 -04001049 u64 tsf = 0;
1050 u32 tsf_lower = 0;
Luis R. Rodriguez8ab2cd02010-09-16 15:12:26 -04001051 unsigned long flags;
Sujithbe0418a2008-11-18 09:05:55 +05301052
Felix Fietkaub5c804752010-04-15 17:38:48 -04001053 if (edma)
Felix Fietkaub5c804752010-04-15 17:38:48 -04001054 dma_type = DMA_BIDIRECTIONAL;
Ming Lei56824222010-05-14 21:15:38 +08001055 else
1056 dma_type = DMA_FROM_DEVICE;
Felix Fietkaub5c804752010-04-15 17:38:48 -04001057
1058 qtype = hp ? ATH9K_RX_QUEUE_HP : ATH9K_RX_QUEUE_LP;
Sujithb77f4832008-12-07 21:44:03 +05301059 spin_lock_bh(&sc->rx.rxbuflock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001060
Felix Fietkaua6d20552010-06-12 00:33:54 -04001061 tsf = ath9k_hw_gettsf64(ah);
1062 tsf_lower = tsf & 0xffffffff;
1063
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001064 do {
1065 /* If handling rx interrupt and flush is in progress => exit */
Sujith Manoharan781b14a2012-06-04 20:23:55 +05301066 if (test_bit(SC_OP_RXFLUSH, &sc->sc_flags) && (flush == 0))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001067 break;
1068
Felix Fietkau29bffa92010-03-29 20:14:23 -07001069 memset(&rs, 0, sizeof(rs));
Felix Fietkaub5c804752010-04-15 17:38:48 -04001070 if (edma)
1071 bf = ath_edma_get_next_rx_buf(sc, &rs, qtype);
1072 else
1073 bf = ath_get_next_rx_buf(sc, &rs);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001074
Felix Fietkaub5c804752010-04-15 17:38:48 -04001075 if (!bf)
1076 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001077
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001078 skb = bf->bf_mpdu;
Sujithbe0418a2008-11-18 09:05:55 +05301079 if (!skb)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001080 continue;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001081
Felix Fietkau0d955212011-01-26 18:23:27 +01001082 /*
1083 * Take frame header from the first fragment and RX status from
1084 * the last one.
1085 */
1086 if (sc->rx.frag)
1087 hdr_skb = sc->rx.frag;
1088 else
1089 hdr_skb = skb;
1090
1091 hdr = (struct ieee80211_hdr *) (hdr_skb->data + rx_status_len);
1092 rxs = IEEE80211_SKB_RXCB(hdr_skb);
Ben Greear15072182012-04-03 09:18:59 -07001093 if (ieee80211_is_beacon(hdr->frame_control)) {
1094 RX_STAT_INC(rx_beacons);
1095 if (!is_zero_ether_addr(common->curbssid) &&
Joe Perches2e42e472012-05-09 17:17:46 +00001096 ether_addr_equal(hdr->addr3, common->curbssid))
Ben Greear15072182012-04-03 09:18:59 -07001097 rs.is_mybeacon = true;
1098 else
1099 rs.is_mybeacon = false;
1100 }
Rajkumar Manoharancf3af742011-08-27 16:17:47 +05301101 else
1102 rs.is_mybeacon = false;
Luis R. Rodriguez5ca42622009-11-04 08:20:42 -08001103
Rajkumar Manoharan6995fb82012-06-04 16:28:52 +05301104 sc->rx.num_pkts++;
Felix Fietkau29bffa92010-03-29 20:14:23 -07001105 ath_debug_stat_rx(sc, &rs);
Sujith1395d3f2010-01-08 10:36:11 +05301106
Vasanthakumar Thiagarajan9bf9fca2008-12-15 20:40:46 +05301107 /*
Sujithbe0418a2008-11-18 09:05:55 +05301108 * If we're asked to flush receive queue, directly
1109 * chain it back at the queue without processing it.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001110 */
Sujith Manoharan781b14a2012-06-04 20:23:55 +05301111 if (test_bit(SC_OP_RXFLUSH, &sc->sc_flags)) {
Ben Greear15072182012-04-03 09:18:59 -07001112 RX_STAT_INC(rx_drop_rxflush);
Felix Fietkau0d955212011-01-26 18:23:27 +01001113 goto requeue_drop_frag;
Ben Greear15072182012-04-03 09:18:59 -07001114 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001115
Ashok Nagarajanffb1c562012-03-09 18:57:39 -08001116 memset(rxs, 0, sizeof(struct ieee80211_rx_status));
1117
Felix Fietkaua6d20552010-06-12 00:33:54 -04001118 rxs->mactime = (tsf & ~0xffffffffULL) | rs.rs_tstamp;
1119 if (rs.rs_tstamp > tsf_lower &&
1120 unlikely(rs.rs_tstamp - tsf_lower > 0x10000000))
1121 rxs->mactime -= 0x100000000ULL;
1122
1123 if (rs.rs_tstamp < tsf_lower &&
1124 unlikely(tsf_lower - rs.rs_tstamp > 0x10000000))
1125 rxs->mactime += 0x100000000ULL;
1126
Zefir Kurtisi83c76572011-11-16 11:09:44 +01001127 retval = ath9k_rx_skb_preprocess(common, hw, hdr, &rs,
1128 rxs, &decrypt_error);
1129 if (retval)
1130 goto requeue_drop_frag;
1131
Rajkumar Manoharan01e18912012-03-15 05:34:27 +05301132 if (rs.is_mybeacon) {
1133 sc->hw_busy_count = 0;
1134 ath_start_rx_poll(sc, 3);
1135 }
Luis R. Rodriguezcb71d9b2008-11-21 17:41:33 -08001136 /* Ensure we always have an skb to requeue once we are done
1137 * processing the current buffer's skb */
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -08001138 requeue_skb = ath_rxbuf_alloc(common, common->rx_bufsize, GFP_ATOMIC);
Luis R. Rodriguezcb71d9b2008-11-21 17:41:33 -08001139
1140 /* If there is no memory we ignore the current RX'd frame,
1141 * tell hardware it can give us a new frame using the old
Sujithb77f4832008-12-07 21:44:03 +05301142 * skb and put it at the tail of the sc->rx.rxbuf list for
Luis R. Rodriguezcb71d9b2008-11-21 17:41:33 -08001143 * processing. */
Ben Greear15072182012-04-03 09:18:59 -07001144 if (!requeue_skb) {
1145 RX_STAT_INC(rx_oom_err);
Felix Fietkau0d955212011-01-26 18:23:27 +01001146 goto requeue_drop_frag;
Ben Greear15072182012-04-03 09:18:59 -07001147 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001148
Vasanthakumar Thiagarajan9bf9fca2008-12-15 20:40:46 +05301149 /* Unmap the frame */
Gabor Juhos7da3c552009-01-14 20:17:03 +01001150 dma_unmap_single(sc->dev, bf->bf_buf_addr,
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -08001151 common->rx_bufsize,
Felix Fietkaub5c804752010-04-15 17:38:48 -04001152 dma_type);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001153
Felix Fietkaub5c804752010-04-15 17:38:48 -04001154 skb_put(skb, rs.rs_datalen + ah->caps.rx_status_len);
1155 if (ah->caps.rx_status_len)
1156 skb_pull(skb, ah->caps.rx_status_len);
Sujithbe0418a2008-11-18 09:05:55 +05301157
Felix Fietkau0d955212011-01-26 18:23:27 +01001158 if (!rs.rs_more)
1159 ath9k_rx_skb_postprocess(common, hdr_skb, &rs,
1160 rxs, decrypt_error);
Sujithbe0418a2008-11-18 09:05:55 +05301161
Luis R. Rodriguezcb71d9b2008-11-21 17:41:33 -08001162 /* We will now give hardware our shiny new allocated skb */
1163 bf->bf_mpdu = requeue_skb;
Gabor Juhos7da3c552009-01-14 20:17:03 +01001164 bf->bf_buf_addr = dma_map_single(sc->dev, requeue_skb->data,
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -08001165 common->rx_bufsize,
Felix Fietkaub5c804752010-04-15 17:38:48 -04001166 dma_type);
Gabor Juhos7da3c552009-01-14 20:17:03 +01001167 if (unlikely(dma_mapping_error(sc->dev,
Luis R. Rodriguezf8316df2008-12-03 03:35:29 -08001168 bf->bf_buf_addr))) {
1169 dev_kfree_skb_any(requeue_skb);
1170 bf->bf_mpdu = NULL;
Ben Greear6cf9e992010-10-14 12:45:30 -07001171 bf->bf_buf_addr = 0;
Joe Perches38002762010-12-02 19:12:36 -08001172 ath_err(common, "dma_mapping_error() on RX\n");
Felix Fietkau7545daf2011-01-24 19:23:16 +01001173 ieee80211_rx(hw, skb);
Luis R. Rodriguezf8316df2008-12-03 03:35:29 -08001174 break;
1175 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001176
Felix Fietkau0d955212011-01-26 18:23:27 +01001177 if (rs.rs_more) {
Ben Greear15072182012-04-03 09:18:59 -07001178 RX_STAT_INC(rx_frags);
Felix Fietkau0d955212011-01-26 18:23:27 +01001179 /*
1180 * rs_more indicates chained descriptors which can be
1181 * used to link buffers together for a sort of
1182 * scatter-gather operation.
1183 */
1184 if (sc->rx.frag) {
1185 /* too many fragments - cannot handle frame */
1186 dev_kfree_skb_any(sc->rx.frag);
1187 dev_kfree_skb_any(skb);
Ben Greear15072182012-04-03 09:18:59 -07001188 RX_STAT_INC(rx_too_many_frags_err);
Felix Fietkau0d955212011-01-26 18:23:27 +01001189 skb = NULL;
1190 }
1191 sc->rx.frag = skb;
1192 goto requeue;
1193 }
1194
1195 if (sc->rx.frag) {
1196 int space = skb->len - skb_tailroom(hdr_skb);
1197
Felix Fietkau0d955212011-01-26 18:23:27 +01001198 if (pskb_expand_head(hdr_skb, 0, space, GFP_ATOMIC) < 0) {
1199 dev_kfree_skb(skb);
Ben Greear15072182012-04-03 09:18:59 -07001200 RX_STAT_INC(rx_oom_err);
Felix Fietkau0d955212011-01-26 18:23:27 +01001201 goto requeue_drop_frag;
1202 }
1203
Eric Dumazetb5447ff2012-03-15 13:43:29 -07001204 sc->rx.frag = NULL;
1205
Felix Fietkau0d955212011-01-26 18:23:27 +01001206 skb_copy_from_linear_data(skb, skb_put(hdr_skb, skb->len),
1207 skb->len);
1208 dev_kfree_skb_any(skb);
1209 skb = hdr_skb;
1210 }
1211
Mohammed Shafi Shajakhaneb840a82011-11-29 20:30:35 +05301212
1213 if (ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB) {
1214
1215 /*
1216 * change the default rx antenna if rx diversity
1217 * chooses the other antenna 3 times in a row.
1218 */
1219 if (sc->rx.defant != rs.rs_antenna) {
1220 if (++sc->rx.rxotherant >= 3)
1221 ath_setdefantenna(sc, rs.rs_antenna);
1222 } else {
1223 sc->rx.rxotherant = 0;
1224 }
1225
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001226 }
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301227
Felix Fietkau66760ea2011-07-13 23:35:05 +08001228 if (rxs->flag & RX_FLAG_MMIC_STRIPPED)
1229 skb_trim(skb, skb->len - 8);
1230
Luis R. Rodriguez8ab2cd02010-09-16 15:12:26 -04001231 spin_lock_irqsave(&sc->sc_pm_lock, flags);
Mohammed Shafi Shajakhanaaef24b2010-12-07 20:40:58 +05301232 if ((sc->ps_flags & (PS_WAIT_FOR_BEACON |
Rajkumar Manoharanf73c6042011-09-26 22:16:56 +05301233 PS_WAIT_FOR_CAB |
1234 PS_WAIT_FOR_PSPOLL_DATA)) ||
1235 ath9k_check_auto_sleep(sc))
1236 ath_rx_ps(sc, skb, rs.is_mybeacon);
Luis R. Rodriguez8ab2cd02010-09-16 15:12:26 -04001237 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
Jouni Malinencc659652009-05-14 21:28:48 +03001238
Felix Fietkau43c35282011-09-03 01:40:27 +02001239 if ((ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB) && sc->ant_rx == 3)
Vasanthakumar Thiagarajan102885a2010-09-02 01:34:43 -07001240 ath_ant_comb_scan(sc, &rs);
1241
Felix Fietkau7545daf2011-01-24 19:23:16 +01001242 ieee80211_rx(hw, skb);
Jouni Malinencc659652009-05-14 21:28:48 +03001243
Felix Fietkau0d955212011-01-26 18:23:27 +01001244requeue_drop_frag:
1245 if (sc->rx.frag) {
1246 dev_kfree_skb_any(sc->rx.frag);
1247 sc->rx.frag = NULL;
1248 }
Luis R. Rodriguezcb71d9b2008-11-21 17:41:33 -08001249requeue:
Felix Fietkaub5c804752010-04-15 17:38:48 -04001250 if (edma) {
1251 list_add_tail(&bf->list, &sc->rx.rxbuf);
1252 ath_rx_edma_buf_link(sc, qtype);
1253 } else {
1254 list_move_tail(&bf->list, &sc->rx.rxbuf);
1255 ath_rx_buf_link(sc, bf);
Felix Fietkau34832882011-09-14 21:23:03 +02001256 if (!flush)
1257 ath9k_hw_rxena(ah);
Felix Fietkaub5c804752010-04-15 17:38:48 -04001258 }
Sujithbe0418a2008-11-18 09:05:55 +05301259 } while (1);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001260
Sujithb77f4832008-12-07 21:44:03 +05301261 spin_unlock_bh(&sc->rx.rxbuflock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001262
Rajkumar Manoharan29ab0b32011-08-13 10:28:10 +05301263 if (!(ah->imask & ATH9K_INT_RXEOL)) {
1264 ah->imask |= (ATH9K_INT_RXEOL | ATH9K_INT_RXORN);
Felix Fietkau72d874c2011-10-08 20:06:19 +02001265 ath9k_hw_set_interrupts(ah);
Rajkumar Manoharan29ab0b32011-08-13 10:28:10 +05301266 }
1267
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001268 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001269}