blob: 67f58d4bb10ef74664119e02325569883a9a3085 [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);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700289
Felix Fietkau0d955212011-01-26 18:23:27 +0100290 common->rx_bufsize = IEEE80211_MAX_MPDU_LEN / 2 +
291 sc->sc_ah->caps.rx_status_len;
292
Felix Fietkaub5c804752010-04-15 17:38:48 -0400293 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
294 return ath_rx_edma_init(sc, nbufs);
295 } else {
Joe Perchesd2182b62011-12-15 14:55:53 -0800296 ath_dbg(common, CONFIG, "cachelsz %u rxbufsize %u\n",
Joe Perches226afe62010-12-02 19:12:37 -0800297 common->cachelsz, common->rx_bufsize);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700298
Felix Fietkaub5c804752010-04-15 17:38:48 -0400299 /* Initialize rx descriptors */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700300
Felix Fietkaub5c804752010-04-15 17:38:48 -0400301 error = ath_descdma_setup(sc, &sc->rx.rxdma, &sc->rx.rxbuf,
Vasanthakumar Thiagarajan4adfcde2010-04-15 17:39:33 -0400302 "rx", nbufs, 1, 0);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400303 if (error != 0) {
Joe Perches38002762010-12-02 19:12:36 -0800304 ath_err(common,
305 "failed to allocate rx descriptors: %d\n",
306 error);
Sujith797fe5cb2009-03-30 15:28:45 +0530307 goto err;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700308 }
Felix Fietkaub5c804752010-04-15 17:38:48 -0400309
310 list_for_each_entry(bf, &sc->rx.rxbuf, list) {
311 skb = ath_rxbuf_alloc(common, common->rx_bufsize,
312 GFP_KERNEL);
313 if (skb == NULL) {
314 error = -ENOMEM;
315 goto err;
316 }
317
318 bf->bf_mpdu = skb;
319 bf->bf_buf_addr = dma_map_single(sc->dev, skb->data,
320 common->rx_bufsize,
321 DMA_FROM_DEVICE);
322 if (unlikely(dma_mapping_error(sc->dev,
323 bf->bf_buf_addr))) {
324 dev_kfree_skb_any(skb);
325 bf->bf_mpdu = NULL;
Ben Greear6cf9e992010-10-14 12:45:30 -0700326 bf->bf_buf_addr = 0;
Joe Perches38002762010-12-02 19:12:36 -0800327 ath_err(common,
328 "dma_mapping_error() on RX init\n");
Felix Fietkaub5c804752010-04-15 17:38:48 -0400329 error = -ENOMEM;
330 goto err;
331 }
Felix Fietkaub5c804752010-04-15 17:38:48 -0400332 }
333 sc->rx.rxlink = NULL;
Sujith797fe5cb2009-03-30 15:28:45 +0530334 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700335
Sujith797fe5cb2009-03-30 15:28:45 +0530336err:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700337 if (error)
338 ath_rx_cleanup(sc);
339
340 return error;
341}
342
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700343void ath_rx_cleanup(struct ath_softc *sc)
344{
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -0800345 struct ath_hw *ah = sc->sc_ah;
346 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700347 struct sk_buff *skb;
348 struct ath_buf *bf;
349
Felix Fietkaub5c804752010-04-15 17:38:48 -0400350 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
351 ath_rx_edma_cleanup(sc);
352 return;
353 } else {
354 list_for_each_entry(bf, &sc->rx.rxbuf, list) {
355 skb = bf->bf_mpdu;
356 if (skb) {
357 dma_unmap_single(sc->dev, bf->bf_buf_addr,
358 common->rx_bufsize,
359 DMA_FROM_DEVICE);
360 dev_kfree_skb(skb);
Ben Greear6cf9e992010-10-14 12:45:30 -0700361 bf->bf_buf_addr = 0;
362 bf->bf_mpdu = NULL;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400363 }
Luis R. Rodriguez051b9192009-03-23 18:25:01 -0400364 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700365
Felix Fietkaub5c804752010-04-15 17:38:48 -0400366 if (sc->rx.rxdma.dd_desc_len != 0)
367 ath_descdma_cleanup(sc, &sc->rx.rxdma, &sc->rx.rxbuf);
368 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700369}
370
371/*
372 * Calculate the receive filter according to the
373 * operating mode and state:
374 *
375 * o always accept unicast, broadcast, and multicast traffic
376 * o maintain current state of phy error reception (the hal
377 * may enable phy error frames for noise immunity work)
378 * o probe request frames are accepted only when operating in
379 * hostap, adhoc, or monitor modes
380 * o enable promiscuous mode according to the interface state
381 * o accept beacons:
382 * - when operating in adhoc mode so the 802.11 layer creates
383 * node table entries for peers,
384 * - when operating in station mode for collecting rssi data when
385 * the station is otherwise quiet, or
386 * - when operating as a repeater so we see repeater-sta beacons
387 * - when scanning
388 */
389
390u32 ath_calcrxfilter(struct ath_softc *sc)
391{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700392 u32 rfilt;
393
Felix Fietkauac066972011-10-08 15:49:57 +0200394 rfilt = ATH9K_RX_FILTER_UCAST | ATH9K_RX_FILTER_BCAST
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700395 | ATH9K_RX_FILTER_MCAST;
396
Jouni Malinen9c1d8e42010-10-13 17:29:31 +0300397 if (sc->rx.rxfilter & FIF_PROBE_REQ)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700398 rfilt |= ATH9K_RX_FILTER_PROBEREQ;
399
Jouni Malinen217ba9d2009-03-10 10:55:50 +0200400 /*
401 * Set promiscuous mode when FIF_PROMISC_IN_BSS is enabled for station
402 * mode interface or when in monitor mode. AP mode does not need this
403 * since it receives all in-BSS frames anyway.
404 */
Felix Fietkau2e286942011-03-09 01:48:12 +0100405 if (sc->sc_ah->is_monitoring)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700406 rfilt |= ATH9K_RX_FILTER_PROM;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700407
Sujithd42c6b72009-02-04 08:10:22 +0530408 if (sc->rx.rxfilter & FIF_CONTROL)
409 rfilt |= ATH9K_RX_FILTER_CONTROL;
410
Vasanthakumar Thiagarajandbaaa142009-02-19 15:41:52 +0530411 if ((sc->sc_ah->opmode == NL80211_IFTYPE_STATION) &&
Ben Greearcfda6692010-09-14 12:00:22 -0700412 (sc->nvifs <= 1) &&
Vasanthakumar Thiagarajandbaaa142009-02-19 15:41:52 +0530413 !(sc->rx.rxfilter & FIF_BCN_PRBRESP_PROMISC))
414 rfilt |= ATH9K_RX_FILTER_MYBEACON;
415 else
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700416 rfilt |= ATH9K_RX_FILTER_BEACON;
417
Felix Fietkau264bbec2011-04-07 19:24:23 +0200418 if ((sc->sc_ah->opmode == NL80211_IFTYPE_AP) ||
Senthil Balasubramanian66afad02009-09-18 15:06:07 +0530419 (sc->rx.rxfilter & FIF_PSPOLL))
Vasanthakumar Thiagarajandbaaa142009-02-19 15:41:52 +0530420 rfilt |= ATH9K_RX_FILTER_PSPOLL;
Sujithbe0418a2008-11-18 09:05:55 +0530421
Sujith7ea310b2009-09-03 12:08:43 +0530422 if (conf_is_ht(&sc->hw->conf))
423 rfilt |= ATH9K_RX_FILTER_COMP_BAR;
424
Felix Fietkau7545daf2011-01-24 19:23:16 +0100425 if (sc->nvifs > 1 || (sc->rx.rxfilter & FIF_OTHER_BSS)) {
Thomas Wagnera5494592012-09-25 21:32:55 +0530426 /* This is needed for older chips */
427 if (sc->sc_ah->hw_version.macVersion <= AR_SREV_VERSION_9160)
Javier Cardona5eb6ba82009-08-20 19:12:07 -0700428 rfilt |= ATH9K_RX_FILTER_PROM;
Jouni Malinenb93bce22009-03-03 19:23:30 +0200429 rfilt |= ATH9K_RX_FILTER_MCAST_BCAST_ALL;
430 }
431
Gabor Juhosb3d7aa42012-07-03 19:13:33 +0200432 if (AR_SREV_9550(sc->sc_ah))
433 rfilt |= ATH9K_RX_FILTER_4ADDRESS;
434
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700435 return rfilt;
Sujith7dcfdcd2008-08-11 14:03:13 +0530436
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700437}
438
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700439int ath_startrecv(struct ath_softc *sc)
440{
Sujithcbe61d82009-02-09 13:27:12 +0530441 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700442 struct ath_buf *bf, *tbf;
443
Felix Fietkaub5c804752010-04-15 17:38:48 -0400444 if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
445 ath_edma_start_recv(sc);
446 return 0;
447 }
448
Sujithb77f4832008-12-07 21:44:03 +0530449 spin_lock_bh(&sc->rx.rxbuflock);
450 if (list_empty(&sc->rx.rxbuf))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700451 goto start_recv;
452
Sujithb77f4832008-12-07 21:44:03 +0530453 sc->rx.rxlink = NULL;
454 list_for_each_entry_safe(bf, tbf, &sc->rx.rxbuf, list) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700455 ath_rx_buf_link(sc, bf);
456 }
457
458 /* We could have deleted elements so the list may be empty now */
Sujithb77f4832008-12-07 21:44:03 +0530459 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 bf = list_first_entry(&sc->rx.rxbuf, struct ath_buf, list);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700463 ath9k_hw_putrxbuf(ah, bf->bf_daddr);
Sujithbe0418a2008-11-18 09:05:55 +0530464 ath9k_hw_rxena(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700465
466start_recv:
Sujithbe0418a2008-11-18 09:05:55 +0530467 ath_opmode_init(sc);
Sujith Manoharan4cb54fa2012-06-04 16:27:52 +0530468 ath9k_hw_startpcureceive(ah, !!(sc->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL));
Sujithbe0418a2008-11-18 09:05:55 +0530469
Luis R. Rodriguez7583c5502010-10-20 16:07:04 -0700470 spin_unlock_bh(&sc->rx.rxbuflock);
471
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700472 return 0;
473}
474
Felix Fietkau4b883f02013-01-09 16:16:56 +0100475static void ath_flushrecv(struct ath_softc *sc)
476{
477 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
478 ath_rx_tasklet(sc, 1, true);
479 ath_rx_tasklet(sc, 1, false);
480}
481
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700482bool ath_stoprecv(struct ath_softc *sc)
483{
Sujithcbe61d82009-02-09 13:27:12 +0530484 struct ath_hw *ah = sc->sc_ah;
Felix Fietkau5882da022011-04-08 20:13:18 +0200485 bool stopped, reset = false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700486
Luis R. Rodriguez1e450282010-10-20 16:07:03 -0700487 spin_lock_bh(&sc->rx.rxbuflock);
Felix Fietkaud47844a2010-11-20 03:08:47 +0100488 ath9k_hw_abortpcurecv(ah);
Sujithbe0418a2008-11-18 09:05:55 +0530489 ath9k_hw_setrxfilter(ah, 0);
Felix Fietkau5882da022011-04-08 20:13:18 +0200490 stopped = ath9k_hw_stopdmarecv(ah, &reset);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400491
Felix Fietkau4b883f02013-01-09 16:16:56 +0100492 ath_flushrecv(sc);
493
Felix Fietkaub5c804752010-04-15 17:38:48 -0400494 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 }
Felix Fietkau2232d312011-04-15 00:41:43 +0200507 return stopped && !reset;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700508}
509
Jouni Malinencc659652009-05-14 21:28:48 +0300510static bool ath_beacon_dtim_pending_cab(struct sk_buff *skb)
511{
512 /* Check whether the Beacon frame has DTIM indicating buffered bc/mc */
513 struct ieee80211_mgmt *mgmt;
514 u8 *pos, *end, id, elen;
515 struct ieee80211_tim_ie *tim;
516
517 mgmt = (struct ieee80211_mgmt *)skb->data;
518 pos = mgmt->u.beacon.variable;
519 end = skb->data + skb->len;
520
521 while (pos + 2 < end) {
522 id = *pos++;
523 elen = *pos++;
524 if (pos + elen > end)
525 break;
526
527 if (id == WLAN_EID_TIM) {
528 if (elen < sizeof(*tim))
529 break;
530 tim = (struct ieee80211_tim_ie *) pos;
531 if (tim->dtim_count != 0)
532 break;
533 return tim->bitmap_ctrl & 0x01;
534 }
535
536 pos += elen;
537 }
538
539 return false;
540}
541
Jouni Malinencc659652009-05-14 21:28:48 +0300542static void ath_rx_ps_beacon(struct ath_softc *sc, struct sk_buff *skb)
543{
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700544 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Jouni Malinencc659652009-05-14 21:28:48 +0300545
546 if (skb->len < 24 + 8 + 2 + 2)
547 return;
548
Sujith1b04b932010-01-08 10:36:05 +0530549 sc->ps_flags &= ~PS_WAIT_FOR_BEACON;
Gabor Juhos293dc5d2009-06-19 12:17:48 +0200550
Sujith1b04b932010-01-08 10:36:05 +0530551 if (sc->ps_flags & PS_BEACON_SYNC) {
552 sc->ps_flags &= ~PS_BEACON_SYNC;
Joe Perchesd2182b62011-12-15 14:55:53 -0800553 ath_dbg(common, PS,
Joe Perches226afe62010-12-02 19:12:37 -0800554 "Reconfigure Beacon timers based on timestamp from the AP\n");
Sujith Manoharanef4ad632012-07-17 17:15:56 +0530555 ath9k_set_beacon(sc);
Jouni Malinenccdfeab2009-05-20 21:59:08 +0300556 }
557
Jouni Malinencc659652009-05-14 21:28:48 +0300558 if (ath_beacon_dtim_pending_cab(skb)) {
559 /*
560 * Remain awake waiting for buffered broadcast/multicast
Gabor Juhos58f5fff2009-06-17 20:53:20 +0200561 * frames. If the last broadcast/multicast frame is not
562 * received properly, the next beacon frame will work as
563 * a backup trigger for returning into NETWORK SLEEP state,
564 * so we are waiting for it as well.
Jouni Malinencc659652009-05-14 21:28:48 +0300565 */
Joe Perchesd2182b62011-12-15 14:55:53 -0800566 ath_dbg(common, PS,
Joe Perches226afe62010-12-02 19:12:37 -0800567 "Received DTIM beacon indicating buffered broadcast/multicast frame(s)\n");
Sujith1b04b932010-01-08 10:36:05 +0530568 sc->ps_flags |= PS_WAIT_FOR_CAB | PS_WAIT_FOR_BEACON;
Jouni Malinencc659652009-05-14 21:28:48 +0300569 return;
570 }
571
Sujith1b04b932010-01-08 10:36:05 +0530572 if (sc->ps_flags & PS_WAIT_FOR_CAB) {
Jouni Malinencc659652009-05-14 21:28:48 +0300573 /*
574 * This can happen if a broadcast frame is dropped or the AP
575 * fails to send a frame indicating that all CAB frames have
576 * been delivered.
577 */
Sujith1b04b932010-01-08 10:36:05 +0530578 sc->ps_flags &= ~PS_WAIT_FOR_CAB;
Joe Perchesd2182b62011-12-15 14:55:53 -0800579 ath_dbg(common, PS, "PS wait for CAB frames timed out\n");
Jouni Malinencc659652009-05-14 21:28:48 +0300580 }
Jouni Malinencc659652009-05-14 21:28:48 +0300581}
582
Rajkumar Manoharanf73c6042011-09-26 22:16:56 +0530583static void ath_rx_ps(struct ath_softc *sc, struct sk_buff *skb, bool mybeacon)
Jouni Malinencc659652009-05-14 21:28:48 +0300584{
585 struct ieee80211_hdr *hdr;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700586 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Jouni Malinencc659652009-05-14 21:28:48 +0300587
588 hdr = (struct ieee80211_hdr *)skb->data;
589
590 /* Process Beacon and CAB receive in PS state */
Vasanthakumar Thiagarajanededf1f2010-05-22 23:58:13 -0700591 if (((sc->ps_flags & PS_WAIT_FOR_BEACON) || ath9k_check_auto_sleep(sc))
Sujith Manoharan07c15a32012-06-04 20:24:07 +0530592 && mybeacon) {
Jouni Malinencc659652009-05-14 21:28:48 +0300593 ath_rx_ps_beacon(sc, skb);
Sujith Manoharan07c15a32012-06-04 20:24:07 +0530594 } else if ((sc->ps_flags & PS_WAIT_FOR_CAB) &&
595 (ieee80211_is_data(hdr->frame_control) ||
596 ieee80211_is_action(hdr->frame_control)) &&
597 is_multicast_ether_addr(hdr->addr1) &&
598 !ieee80211_has_moredata(hdr->frame_control)) {
Jouni Malinencc659652009-05-14 21:28:48 +0300599 /*
600 * No more broadcast/multicast frames to be received at this
601 * point.
602 */
Senthil Balasubramanian3fac6df2010-09-16 15:12:35 -0400603 sc->ps_flags &= ~(PS_WAIT_FOR_CAB | PS_WAIT_FOR_BEACON);
Joe Perchesd2182b62011-12-15 14:55:53 -0800604 ath_dbg(common, PS,
Joe Perches226afe62010-12-02 19:12:37 -0800605 "All PS CAB frames received, back to sleep\n");
Sujith1b04b932010-01-08 10:36:05 +0530606 } else if ((sc->ps_flags & PS_WAIT_FOR_PSPOLL_DATA) &&
Jouni Malinen9a23f9c2009-05-19 17:01:38 +0300607 !is_multicast_ether_addr(hdr->addr1) &&
608 !ieee80211_has_morefrags(hdr->frame_control)) {
Sujith1b04b932010-01-08 10:36:05 +0530609 sc->ps_flags &= ~PS_WAIT_FOR_PSPOLL_DATA;
Joe Perchesd2182b62011-12-15 14:55:53 -0800610 ath_dbg(common, PS,
Joe Perches226afe62010-12-02 19:12:37 -0800611 "Going back to sleep after having received PS-Poll data (0x%lx)\n",
Sujith1b04b932010-01-08 10:36:05 +0530612 sc->ps_flags & (PS_WAIT_FOR_BEACON |
613 PS_WAIT_FOR_CAB |
614 PS_WAIT_FOR_PSPOLL_DATA |
615 PS_WAIT_FOR_TX_ACK));
Jouni Malinencc659652009-05-14 21:28:48 +0300616 }
617}
618
Felix Fietkaub5c804752010-04-15 17:38:48 -0400619static bool ath_edma_get_buffers(struct ath_softc *sc,
Felix Fietkau3a2923e2012-03-03 15:17:05 +0100620 enum ath9k_rx_qtype qtype,
621 struct ath_rx_status *rs,
622 struct ath_buf **dest)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700623{
Felix Fietkaub5c804752010-04-15 17:38:48 -0400624 struct ath_rx_edma *rx_edma = &sc->rx.rx_edma[qtype];
625 struct ath_hw *ah = sc->sc_ah;
626 struct ath_common *common = ath9k_hw_common(ah);
627 struct sk_buff *skb;
Sujithbe0418a2008-11-18 09:05:55 +0530628 struct ath_buf *bf;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400629 int ret;
630
631 skb = skb_peek(&rx_edma->rx_fifo);
632 if (!skb)
633 return false;
634
635 bf = SKB_CB_ATHBUF(skb);
636 BUG_ON(!bf);
637
Ming Leice9426d2010-05-15 18:25:40 +0800638 dma_sync_single_for_cpu(sc->dev, bf->bf_buf_addr,
Felix Fietkaub5c804752010-04-15 17:38:48 -0400639 common->rx_bufsize, DMA_FROM_DEVICE);
640
Felix Fietkau3a2923e2012-03-03 15:17:05 +0100641 ret = ath9k_hw_process_rxdesc_edma(ah, rs, skb->data);
Ming Leice9426d2010-05-15 18:25:40 +0800642 if (ret == -EINPROGRESS) {
643 /*let device gain the buffer again*/
644 dma_sync_single_for_device(sc->dev, bf->bf_buf_addr,
645 common->rx_bufsize, DMA_FROM_DEVICE);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400646 return false;
Ming Leice9426d2010-05-15 18:25:40 +0800647 }
Felix Fietkaub5c804752010-04-15 17:38:48 -0400648
649 __skb_unlink(skb, &rx_edma->rx_fifo);
650 if (ret == -EINVAL) {
651 /* corrupt descriptor, skip this one and the following one */
652 list_add_tail(&bf->list, &sc->rx.rxbuf);
653 ath_rx_edma_buf_link(sc, qtype);
Felix Fietkau3a2923e2012-03-03 15:17:05 +0100654
Felix Fietkaub5c804752010-04-15 17:38:48 -0400655 skb = skb_peek(&rx_edma->rx_fifo);
Felix Fietkau3a2923e2012-03-03 15:17:05 +0100656 if (skb) {
657 bf = SKB_CB_ATHBUF(skb);
658 BUG_ON(!bf);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400659
Felix Fietkau3a2923e2012-03-03 15:17:05 +0100660 __skb_unlink(skb, &rx_edma->rx_fifo);
661 list_add_tail(&bf->list, &sc->rx.rxbuf);
662 ath_rx_edma_buf_link(sc, qtype);
Felix Fietkau3a2923e2012-03-03 15:17:05 +0100663 }
Tom Hughes6bb51c72012-06-27 18:21:15 +0100664
665 bf = NULL;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400666 }
Felix Fietkaub5c804752010-04-15 17:38:48 -0400667
Felix Fietkau3a2923e2012-03-03 15:17:05 +0100668 *dest = bf;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400669 return true;
670}
671
672static struct ath_buf *ath_edma_get_next_rx_buf(struct ath_softc *sc,
673 struct ath_rx_status *rs,
674 enum ath9k_rx_qtype qtype)
675{
Felix Fietkau3a2923e2012-03-03 15:17:05 +0100676 struct ath_buf *bf = NULL;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400677
Felix Fietkau3a2923e2012-03-03 15:17:05 +0100678 while (ath_edma_get_buffers(sc, qtype, rs, &bf)) {
679 if (!bf)
680 continue;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400681
Felix Fietkau3a2923e2012-03-03 15:17:05 +0100682 return bf;
683 }
684 return NULL;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400685}
686
687static struct ath_buf *ath_get_next_rx_buf(struct ath_softc *sc,
688 struct ath_rx_status *rs)
689{
690 struct ath_hw *ah = sc->sc_ah;
691 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700692 struct ath_desc *ds;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400693 struct ath_buf *bf;
694 int ret;
695
696 if (list_empty(&sc->rx.rxbuf)) {
697 sc->rx.rxlink = NULL;
698 return NULL;
699 }
700
701 bf = list_first_entry(&sc->rx.rxbuf, struct ath_buf, list);
702 ds = bf->bf_desc;
703
704 /*
705 * Must provide the virtual address of the current
706 * descriptor, the physical address, and the virtual
707 * address of the next descriptor in the h/w chain.
708 * This allows the HAL to look ahead to see if the
709 * hardware is done with a descriptor by checking the
710 * done bit in the following descriptor and the address
711 * of the current descriptor the DMA engine is working
712 * on. All this is necessary because of our use of
713 * a self-linked list to avoid rx overruns.
714 */
Rajkumar Manoharan3de21112011-08-13 10:28:11 +0530715 ret = ath9k_hw_rxprocdesc(ah, ds, rs);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400716 if (ret == -EINPROGRESS) {
717 struct ath_rx_status trs;
718 struct ath_buf *tbf;
719 struct ath_desc *tds;
720
721 memset(&trs, 0, sizeof(trs));
722 if (list_is_last(&bf->list, &sc->rx.rxbuf)) {
723 sc->rx.rxlink = NULL;
724 return NULL;
725 }
726
727 tbf = list_entry(bf->list.next, struct ath_buf, list);
728
729 /*
730 * On some hardware the descriptor status words could
731 * get corrupted, including the done bit. Because of
732 * this, check if the next descriptor's done bit is
733 * set or not.
734 *
735 * If the next descriptor's done bit is set, the current
736 * descriptor has been corrupted. Force s/w to discard
737 * this descriptor and continue...
738 */
739
740 tds = tbf->bf_desc;
Rajkumar Manoharan3de21112011-08-13 10:28:11 +0530741 ret = ath9k_hw_rxprocdesc(ah, tds, &trs);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400742 if (ret == -EINPROGRESS)
743 return NULL;
744 }
745
Felix Fietkaua3dc48e2013-01-09 16:16:52 +0100746 list_del(&bf->list);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400747 if (!bf->bf_mpdu)
748 return bf;
749
750 /*
751 * Synchronize the DMA transfer with CPU before
752 * 1. accessing the frame
753 * 2. requeueing the same buffer to h/w
754 */
Ming Leice9426d2010-05-15 18:25:40 +0800755 dma_sync_single_for_cpu(sc->dev, bf->bf_buf_addr,
Felix Fietkaub5c804752010-04-15 17:38:48 -0400756 common->rx_bufsize,
757 DMA_FROM_DEVICE);
758
759 return bf;
760}
761
Sujithd4357002010-05-20 15:34:38 +0530762/* Assumes you've already done the endian to CPU conversion */
763static bool ath9k_rx_accept(struct ath_common *common,
Vasanthakumar Thiagarajan9f167f62010-05-20 14:34:46 -0700764 struct ieee80211_hdr *hdr,
Sujithd4357002010-05-20 15:34:38 +0530765 struct ieee80211_rx_status *rxs,
766 struct ath_rx_status *rx_stats,
767 bool *decrypt_error)
768{
Felix Fietkauec205992011-10-08 22:02:59 +0200769 struct ath_softc *sc = (struct ath_softc *) common->priv;
Felix Fietkau66760ea2011-07-13 23:35:05 +0800770 bool is_mc, is_valid_tkip, strip_mic, mic_error;
Sujithd4357002010-05-20 15:34:38 +0530771 struct ath_hw *ah = common->ah;
Sujithd4357002010-05-20 15:34:38 +0530772 __le16 fc;
Vasanthakumar Thiagarajanb7b1b512010-05-20 14:34:48 -0700773 u8 rx_status_len = ah->caps.rx_status_len;
Sujithd4357002010-05-20 15:34:38 +0530774
Sujithd4357002010-05-20 15:34:38 +0530775 fc = hdr->frame_control;
776
Felix Fietkau66760ea2011-07-13 23:35:05 +0800777 is_mc = !!is_multicast_ether_addr(hdr->addr1);
778 is_valid_tkip = rx_stats->rs_keyix != ATH9K_RXKEYIX_INVALID &&
779 test_bit(rx_stats->rs_keyix, common->tkip_keymap);
Bill Jordan152e5852011-08-19 11:10:22 -0400780 strip_mic = is_valid_tkip && ieee80211_is_data(fc) &&
Michael Liang2a5783b2012-04-20 17:11:57 +0800781 ieee80211_has_protected(fc) &&
Bill Jordan152e5852011-08-19 11:10:22 -0400782 !(rx_stats->rs_status &
Felix Fietkau846d9362011-10-08 22:02:58 +0200783 (ATH9K_RXERR_DECRYPT | ATH9K_RXERR_CRC | ATH9K_RXERR_MIC |
784 ATH9K_RXERR_KEYMISS));
Felix Fietkau66760ea2011-07-13 23:35:05 +0800785
Felix Fietkauf88373f2012-02-05 21:15:17 +0100786 /*
787 * Key miss events are only relevant for pairwise keys where the
788 * descriptor does contain a valid key index. This has been observed
789 * mostly with CCMP encryption.
790 */
Felix Fietkaubed3d9c2012-06-23 19:23:31 +0200791 if (rx_stats->rs_keyix == ATH9K_RXKEYIX_INVALID ||
792 !test_bit(rx_stats->rs_keyix, common->ccmp_keymap))
Felix Fietkauf88373f2012-02-05 21:15:17 +0100793 rx_stats->rs_status &= ~ATH9K_RXERR_KEYMISS;
794
Ben Greear15072182012-04-03 09:18:59 -0700795 if (!rx_stats->rs_datalen) {
796 RX_STAT_INC(rx_len_err);
Sujithd4357002010-05-20 15:34:38 +0530797 return false;
Ben Greear15072182012-04-03 09:18:59 -0700798 }
799
Sujithd4357002010-05-20 15:34:38 +0530800 /*
801 * rs_status follows rs_datalen so if rs_datalen is too large
802 * we can take a hint that hardware corrupted it, so ignore
803 * those frames.
804 */
Ben Greear15072182012-04-03 09:18:59 -0700805 if (rx_stats->rs_datalen > (common->rx_bufsize - rx_status_len)) {
806 RX_STAT_INC(rx_len_err);
Sujithd4357002010-05-20 15:34:38 +0530807 return false;
Ben Greear15072182012-04-03 09:18:59 -0700808 }
Sujithd4357002010-05-20 15:34:38 +0530809
Felix Fietkau0d955212011-01-26 18:23:27 +0100810 /* Only use error bits from the last fragment */
Sujithd4357002010-05-20 15:34:38 +0530811 if (rx_stats->rs_more)
Felix Fietkau0d955212011-01-26 18:23:27 +0100812 return true;
Sujithd4357002010-05-20 15:34:38 +0530813
Felix Fietkau66760ea2011-07-13 23:35:05 +0800814 mic_error = is_valid_tkip && !ieee80211_is_ctl(fc) &&
815 !ieee80211_has_morefrags(fc) &&
816 !(le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG) &&
817 (rx_stats->rs_status & ATH9K_RXERR_MIC);
818
Sujithd4357002010-05-20 15:34:38 +0530819 /*
820 * The rx_stats->rs_status will not be set until the end of the
821 * chained descriptors so it can be ignored if rs_more is set. The
822 * rs_more will be false at the last element of the chained
823 * descriptors.
824 */
825 if (rx_stats->rs_status != 0) {
Felix Fietkau846d9362011-10-08 22:02:58 +0200826 u8 status_mask;
827
Felix Fietkau66760ea2011-07-13 23:35:05 +0800828 if (rx_stats->rs_status & ATH9K_RXERR_CRC) {
Sujithd4357002010-05-20 15:34:38 +0530829 rxs->flag |= RX_FLAG_FAILED_FCS_CRC;
Felix Fietkau66760ea2011-07-13 23:35:05 +0800830 mic_error = false;
831 }
Sujithd4357002010-05-20 15:34:38 +0530832 if (rx_stats->rs_status & ATH9K_RXERR_PHY)
833 return false;
834
Felix Fietkau846d9362011-10-08 22:02:58 +0200835 if ((rx_stats->rs_status & ATH9K_RXERR_DECRYPT) ||
836 (!is_mc && (rx_stats->rs_status & ATH9K_RXERR_KEYMISS))) {
Sujithd4357002010-05-20 15:34:38 +0530837 *decrypt_error = true;
Felix Fietkau66760ea2011-07-13 23:35:05 +0800838 mic_error = false;
Sujithd4357002010-05-20 15:34:38 +0530839 }
Felix Fietkau66760ea2011-07-13 23:35:05 +0800840
Sujithd4357002010-05-20 15:34:38 +0530841 /*
842 * Reject error frames with the exception of
843 * decryption and MIC failures. For monitor mode,
844 * we also ignore the CRC error.
845 */
Felix Fietkau846d9362011-10-08 22:02:58 +0200846 status_mask = ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC |
847 ATH9K_RXERR_KEYMISS;
848
Felix Fietkauec205992011-10-08 22:02:59 +0200849 if (ah->is_monitoring && (sc->rx.rxfilter & FIF_FCSFAIL))
Felix Fietkau846d9362011-10-08 22:02:58 +0200850 status_mask |= ATH9K_RXERR_CRC;
851
852 if (rx_stats->rs_status & ~status_mask)
853 return false;
Sujithd4357002010-05-20 15:34:38 +0530854 }
Felix Fietkau66760ea2011-07-13 23:35:05 +0800855
856 /*
857 * For unicast frames the MIC error bit can have false positives,
858 * so all MIC error reports need to be validated in software.
859 * False negatives are not common, so skip software verification
860 * if the hardware considers the MIC valid.
861 */
862 if (strip_mic)
863 rxs->flag |= RX_FLAG_MMIC_STRIPPED;
864 else if (is_mc && mic_error)
865 rxs->flag |= RX_FLAG_MMIC_ERROR;
866
Sujithd4357002010-05-20 15:34:38 +0530867 return true;
868}
869
870static int ath9k_process_rate(struct ath_common *common,
871 struct ieee80211_hw *hw,
872 struct ath_rx_status *rx_stats,
Vasanthakumar Thiagarajan9f167f62010-05-20 14:34:46 -0700873 struct ieee80211_rx_status *rxs)
Sujithd4357002010-05-20 15:34:38 +0530874{
875 struct ieee80211_supported_band *sband;
876 enum ieee80211_band band;
877 unsigned int i = 0;
Ben Greear990e08a2012-04-17 15:19:03 -0700878 struct ath_softc __maybe_unused *sc = common->priv;
Sujithd4357002010-05-20 15:34:38 +0530879
880 band = hw->conf.channel->band;
881 sband = hw->wiphy->bands[band];
882
883 if (rx_stats->rs_rate & 0x80) {
884 /* HT rate */
885 rxs->flag |= RX_FLAG_HT;
886 if (rx_stats->rs_flags & ATH9K_RX_2040)
887 rxs->flag |= RX_FLAG_40MHZ;
888 if (rx_stats->rs_flags & ATH9K_RX_GI)
889 rxs->flag |= RX_FLAG_SHORT_GI;
890 rxs->rate_idx = rx_stats->rs_rate & 0x7f;
891 return 0;
892 }
893
894 for (i = 0; i < sband->n_bitrates; i++) {
895 if (sband->bitrates[i].hw_value == rx_stats->rs_rate) {
896 rxs->rate_idx = i;
897 return 0;
898 }
899 if (sband->bitrates[i].hw_value_short == rx_stats->rs_rate) {
900 rxs->flag |= RX_FLAG_SHORTPRE;
901 rxs->rate_idx = i;
902 return 0;
903 }
904 }
905
906 /*
907 * No valid hardware bitrate found -- we should not get here
908 * because hardware has already validated this frame as OK.
909 */
Joe Perchesd2182b62011-12-15 14:55:53 -0800910 ath_dbg(common, ANY,
Joe Perches226afe62010-12-02 19:12:37 -0800911 "unsupported hw bitrate detected 0x%02x using 1 Mbit\n",
912 rx_stats->rs_rate);
Ben Greear15072182012-04-03 09:18:59 -0700913 RX_STAT_INC(rx_rate_err);
Sujithd4357002010-05-20 15:34:38 +0530914 return -EINVAL;
915}
916
917static void ath9k_process_rssi(struct ath_common *common,
918 struct ieee80211_hw *hw,
Vasanthakumar Thiagarajan9f167f62010-05-20 14:34:46 -0700919 struct ieee80211_hdr *hdr,
Sujithd4357002010-05-20 15:34:38 +0530920 struct ath_rx_status *rx_stats)
921{
Felix Fietkau9ac586152011-01-24 19:23:18 +0100922 struct ath_softc *sc = hw->priv;
Sujithd4357002010-05-20 15:34:38 +0530923 struct ath_hw *ah = common->ah;
Felix Fietkau9fa23e12010-10-15 20:03:31 +0200924 int last_rssi;
Felix Fietkau2ef16752012-03-03 15:17:06 +0100925 int rssi = rx_stats->rs_rssi;
Sujithd4357002010-05-20 15:34:38 +0530926
Rajkumar Manoharancf3af742011-08-27 16:17:47 +0530927 if (!rx_stats->is_mybeacon ||
928 ((ah->opmode != NL80211_IFTYPE_STATION) &&
929 (ah->opmode != NL80211_IFTYPE_ADHOC)))
Felix Fietkau9fa23e12010-10-15 20:03:31 +0200930 return;
931
Felix Fietkau9fa23e12010-10-15 20:03:31 +0200932 if (rx_stats->rs_rssi != ATH9K_RSSI_BAD && !rx_stats->rs_moreaggr)
Felix Fietkau9ac586152011-01-24 19:23:18 +0100933 ATH_RSSI_LPF(sc->last_rssi, rx_stats->rs_rssi);
Ben Greear686b9cb2010-09-23 09:44:36 -0700934
Felix Fietkau9ac586152011-01-24 19:23:18 +0100935 last_rssi = sc->last_rssi;
Sujithd4357002010-05-20 15:34:38 +0530936 if (likely(last_rssi != ATH_RSSI_DUMMY_MARKER))
Felix Fietkau2ef16752012-03-03 15:17:06 +0100937 rssi = ATH_EP_RND(last_rssi, ATH_RSSI_EP_MULTIPLIER);
938 if (rssi < 0)
939 rssi = 0;
Sujithd4357002010-05-20 15:34:38 +0530940
941 /* Update Beacon RSSI, this is used by ANI. */
Felix Fietkau2ef16752012-03-03 15:17:06 +0100942 ah->stats.avgbrssi = rssi;
Sujithd4357002010-05-20 15:34:38 +0530943}
944
945/*
946 * For Decrypt or Demic errors, we only mark packet status here and always push
947 * up the frame up to let mac80211 handle the actual error case, be it no
948 * decryption key or real decryption error. This let us keep statistics there.
949 */
950static int ath9k_rx_skb_preprocess(struct ath_common *common,
951 struct ieee80211_hw *hw,
Vasanthakumar Thiagarajan9f167f62010-05-20 14:34:46 -0700952 struct ieee80211_hdr *hdr,
Sujithd4357002010-05-20 15:34:38 +0530953 struct ath_rx_status *rx_stats,
954 struct ieee80211_rx_status *rx_status,
955 bool *decrypt_error)
956{
Felix Fietkauf749b942011-07-28 14:08:57 +0200957 struct ath_hw *ah = common->ah;
958
Sujithd4357002010-05-20 15:34:38 +0530959 /*
960 * everything but the rate is checked here, the rate check is done
961 * separately to avoid doing two lookups for a rate for each frame.
962 */
Vasanthakumar Thiagarajan9f167f62010-05-20 14:34:46 -0700963 if (!ath9k_rx_accept(common, hdr, rx_status, rx_stats, decrypt_error))
Sujithd4357002010-05-20 15:34:38 +0530964 return -EINVAL;
965
Felix Fietkau0d955212011-01-26 18:23:27 +0100966 /* Only use status info from the last fragment */
967 if (rx_stats->rs_more)
968 return 0;
969
Vasanthakumar Thiagarajan9f167f62010-05-20 14:34:46 -0700970 ath9k_process_rssi(common, hw, hdr, rx_stats);
Sujithd4357002010-05-20 15:34:38 +0530971
Vasanthakumar Thiagarajan9f167f62010-05-20 14:34:46 -0700972 if (ath9k_process_rate(common, hw, rx_stats, rx_status))
Sujithd4357002010-05-20 15:34:38 +0530973 return -EINVAL;
974
Sujithd4357002010-05-20 15:34:38 +0530975 rx_status->band = hw->conf.channel->band;
976 rx_status->freq = hw->conf.channel->center_freq;
Felix Fietkauf749b942011-07-28 14:08:57 +0200977 rx_status->signal = ah->noise + rx_stats->rs_rssi;
Sujithd4357002010-05-20 15:34:38 +0530978 rx_status->antenna = rx_stats->rs_antenna;
Thomas Pedersen96d21372012-12-10 14:48:01 -0800979 rx_status->flag |= RX_FLAG_MACTIME_END;
Felix Fietkau2ef16752012-03-03 15:17:06 +0100980 if (rx_stats->rs_moreaggr)
981 rx_status->flag |= RX_FLAG_NO_SIGNAL_VAL;
Sujithd4357002010-05-20 15:34:38 +0530982
983 return 0;
984}
985
986static void ath9k_rx_skb_postprocess(struct ath_common *common,
987 struct sk_buff *skb,
988 struct ath_rx_status *rx_stats,
989 struct ieee80211_rx_status *rxs,
990 bool decrypt_error)
991{
992 struct ath_hw *ah = common->ah;
993 struct ieee80211_hdr *hdr;
994 int hdrlen, padpos, padsize;
995 u8 keyix;
996 __le16 fc;
997
998 /* see if any padding is done by the hw and remove it */
999 hdr = (struct ieee80211_hdr *) skb->data;
1000 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
1001 fc = hdr->frame_control;
1002 padpos = ath9k_cmn_padpos(hdr->frame_control);
1003
1004 /* The MAC header is padded to have 32-bit boundary if the
1005 * packet payload is non-zero. The general calculation for
1006 * padsize would take into account odd header lengths:
1007 * padsize = (4 - padpos % 4) % 4; However, since only
1008 * even-length headers are used, padding can only be 0 or 2
1009 * bytes and we can optimize this a bit. In addition, we must
1010 * not try to remove padding from short control frames that do
1011 * not have payload. */
1012 padsize = padpos & 3;
1013 if (padsize && skb->len>=padpos+padsize+FCS_LEN) {
1014 memmove(skb->data + padsize, skb->data, padpos);
1015 skb_pull(skb, padsize);
1016 }
1017
1018 keyix = rx_stats->rs_keyix;
1019
1020 if (!(keyix == ATH9K_RXKEYIX_INVALID) && !decrypt_error &&
1021 ieee80211_has_protected(fc)) {
1022 rxs->flag |= RX_FLAG_DECRYPTED;
1023 } else if (ieee80211_has_protected(fc)
1024 && !decrypt_error && skb->len >= hdrlen + 4) {
1025 keyix = skb->data[hdrlen + 3] >> 6;
1026
1027 if (test_bit(keyix, common->keymap))
1028 rxs->flag |= RX_FLAG_DECRYPTED;
1029 }
1030 if (ah->sw_mgmt_crypto &&
1031 (rxs->flag & RX_FLAG_DECRYPTED) &&
1032 ieee80211_is_mgmt(fc))
1033 /* Use software decrypt for management frames. */
1034 rxs->flag &= ~RX_FLAG_DECRYPTED;
1035}
Felix Fietkaub5c804752010-04-15 17:38:48 -04001036
1037int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp)
1038{
1039 struct ath_buf *bf;
Felix Fietkau0d955212011-01-26 18:23:27 +01001040 struct sk_buff *skb = NULL, *requeue_skb, *hdr_skb;
Luis R. Rodriguez5ca42622009-11-04 08:20:42 -08001041 struct ieee80211_rx_status *rxs;
Sujithcbe61d82009-02-09 13:27:12 +05301042 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez27c51f12009-09-10 11:08:14 -07001043 struct ath_common *common = ath9k_hw_common(ah);
Felix Fietkau7545daf2011-01-24 19:23:16 +01001044 struct ieee80211_hw *hw = sc->hw;
Sujithbe0418a2008-11-18 09:05:55 +05301045 struct ieee80211_hdr *hdr;
Luis R. Rodriguezc9b14172009-11-04 16:47:22 -08001046 int retval;
Felix Fietkau29bffa92010-03-29 20:14:23 -07001047 struct ath_rx_status rs;
Felix Fietkaub5c804752010-04-15 17:38:48 -04001048 enum ath9k_rx_qtype qtype;
1049 bool edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA);
1050 int dma_type;
Vasanthakumar Thiagarajan5c6dd922010-05-20 14:34:47 -07001051 u8 rx_status_len = ah->caps.rx_status_len;
Felix Fietkaua6d20552010-06-12 00:33:54 -04001052 u64 tsf = 0;
1053 u32 tsf_lower = 0;
Luis R. Rodriguez8ab2cd02010-09-16 15:12:26 -04001054 unsigned long flags;
Sujithbe0418a2008-11-18 09:05:55 +05301055
Felix Fietkaub5c804752010-04-15 17:38:48 -04001056 if (edma)
Felix Fietkaub5c804752010-04-15 17:38:48 -04001057 dma_type = DMA_BIDIRECTIONAL;
Ming Lei56824222010-05-14 21:15:38 +08001058 else
1059 dma_type = DMA_FROM_DEVICE;
Felix Fietkaub5c804752010-04-15 17:38:48 -04001060
1061 qtype = hp ? ATH9K_RX_QUEUE_HP : ATH9K_RX_QUEUE_LP;
Sujithb77f4832008-12-07 21:44:03 +05301062 spin_lock_bh(&sc->rx.rxbuflock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001063
Felix Fietkaua6d20552010-06-12 00:33:54 -04001064 tsf = ath9k_hw_gettsf64(ah);
1065 tsf_lower = tsf & 0xffffffff;
1066
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001067 do {
Lorenzo Bianconie1352fd2012-08-10 11:00:24 +02001068 bool decrypt_error = false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001069
Felix Fietkau29bffa92010-03-29 20:14:23 -07001070 memset(&rs, 0, sizeof(rs));
Felix Fietkaub5c804752010-04-15 17:38:48 -04001071 if (edma)
1072 bf = ath_edma_get_next_rx_buf(sc, &rs, qtype);
1073 else
1074 bf = ath_get_next_rx_buf(sc, &rs);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001075
Felix Fietkaub5c804752010-04-15 17:38:48 -04001076 if (!bf)
1077 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001078
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001079 skb = bf->bf_mpdu;
Sujithbe0418a2008-11-18 09:05:55 +05301080 if (!skb)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001081 continue;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001082
Felix Fietkau0d955212011-01-26 18:23:27 +01001083 /*
1084 * Take frame header from the first fragment and RX status from
1085 * the last one.
1086 */
1087 if (sc->rx.frag)
1088 hdr_skb = sc->rx.frag;
1089 else
1090 hdr_skb = skb;
1091
1092 hdr = (struct ieee80211_hdr *) (hdr_skb->data + rx_status_len);
1093 rxs = IEEE80211_SKB_RXCB(hdr_skb);
Ben Greear15072182012-04-03 09:18:59 -07001094 if (ieee80211_is_beacon(hdr->frame_control)) {
1095 RX_STAT_INC(rx_beacons);
1096 if (!is_zero_ether_addr(common->curbssid) &&
Joe Perches2e42e472012-05-09 17:17:46 +00001097 ether_addr_equal(hdr->addr3, common->curbssid))
Ben Greear15072182012-04-03 09:18:59 -07001098 rs.is_mybeacon = true;
1099 else
1100 rs.is_mybeacon = false;
1101 }
Rajkumar Manoharancf3af742011-08-27 16:17:47 +05301102 else
1103 rs.is_mybeacon = false;
Luis R. Rodriguez5ca42622009-11-04 08:20:42 -08001104
Mohammed Shafi Shajakhanbe41b052012-10-08 21:30:51 +05301105 if (ieee80211_is_data_present(hdr->frame_control) &&
1106 !ieee80211_is_qos_nullfunc(hdr->frame_control))
1107 sc->rx.num_pkts++;
1108
Felix Fietkau29bffa92010-03-29 20:14:23 -07001109 ath_debug_stat_rx(sc, &rs);
Sujith1395d3f2010-01-08 10:36:11 +05301110
Ashok Nagarajanffb1c562012-03-09 18:57:39 -08001111 memset(rxs, 0, sizeof(struct ieee80211_rx_status));
1112
Felix Fietkaua6d20552010-06-12 00:33:54 -04001113 rxs->mactime = (tsf & ~0xffffffffULL) | rs.rs_tstamp;
1114 if (rs.rs_tstamp > tsf_lower &&
1115 unlikely(rs.rs_tstamp - tsf_lower > 0x10000000))
1116 rxs->mactime -= 0x100000000ULL;
1117
1118 if (rs.rs_tstamp < tsf_lower &&
1119 unlikely(tsf_lower - rs.rs_tstamp > 0x10000000))
1120 rxs->mactime += 0x100000000ULL;
1121
Zefir Kurtisi83c76572011-11-16 11:09:44 +01001122 retval = ath9k_rx_skb_preprocess(common, hw, hdr, &rs,
1123 rxs, &decrypt_error);
1124 if (retval)
1125 goto requeue_drop_frag;
1126
Rajkumar Manoharan01e18912012-03-15 05:34:27 +05301127 if (rs.is_mybeacon) {
1128 sc->hw_busy_count = 0;
1129 ath_start_rx_poll(sc, 3);
1130 }
Luis R. Rodriguezcb71d9b2008-11-21 17:41:33 -08001131 /* Ensure we always have an skb to requeue once we are done
1132 * processing the current buffer's skb */
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -08001133 requeue_skb = ath_rxbuf_alloc(common, common->rx_bufsize, GFP_ATOMIC);
Luis R. Rodriguezcb71d9b2008-11-21 17:41:33 -08001134
1135 /* If there is no memory we ignore the current RX'd frame,
1136 * tell hardware it can give us a new frame using the old
Sujithb77f4832008-12-07 21:44:03 +05301137 * skb and put it at the tail of the sc->rx.rxbuf list for
Luis R. Rodriguezcb71d9b2008-11-21 17:41:33 -08001138 * processing. */
Ben Greear15072182012-04-03 09:18:59 -07001139 if (!requeue_skb) {
1140 RX_STAT_INC(rx_oom_err);
Felix Fietkau0d955212011-01-26 18:23:27 +01001141 goto requeue_drop_frag;
Ben Greear15072182012-04-03 09:18:59 -07001142 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001143
Vasanthakumar Thiagarajan9bf9fca2008-12-15 20:40:46 +05301144 /* Unmap the frame */
Gabor Juhos7da3c552009-01-14 20:17:03 +01001145 dma_unmap_single(sc->dev, bf->bf_buf_addr,
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -08001146 common->rx_bufsize,
Felix Fietkaub5c804752010-04-15 17:38:48 -04001147 dma_type);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001148
Felix Fietkaub5c804752010-04-15 17:38:48 -04001149 skb_put(skb, rs.rs_datalen + ah->caps.rx_status_len);
1150 if (ah->caps.rx_status_len)
1151 skb_pull(skb, ah->caps.rx_status_len);
Sujithbe0418a2008-11-18 09:05:55 +05301152
Felix Fietkau0d955212011-01-26 18:23:27 +01001153 if (!rs.rs_more)
1154 ath9k_rx_skb_postprocess(common, hdr_skb, &rs,
1155 rxs, decrypt_error);
Sujithbe0418a2008-11-18 09:05:55 +05301156
Luis R. Rodriguezcb71d9b2008-11-21 17:41:33 -08001157 /* We will now give hardware our shiny new allocated skb */
1158 bf->bf_mpdu = requeue_skb;
Gabor Juhos7da3c552009-01-14 20:17:03 +01001159 bf->bf_buf_addr = dma_map_single(sc->dev, requeue_skb->data,
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -08001160 common->rx_bufsize,
Felix Fietkaub5c804752010-04-15 17:38:48 -04001161 dma_type);
Gabor Juhos7da3c552009-01-14 20:17:03 +01001162 if (unlikely(dma_mapping_error(sc->dev,
Luis R. Rodriguezf8316df2008-12-03 03:35:29 -08001163 bf->bf_buf_addr))) {
1164 dev_kfree_skb_any(requeue_skb);
1165 bf->bf_mpdu = NULL;
Ben Greear6cf9e992010-10-14 12:45:30 -07001166 bf->bf_buf_addr = 0;
Joe Perches38002762010-12-02 19:12:36 -08001167 ath_err(common, "dma_mapping_error() on RX\n");
Felix Fietkau7545daf2011-01-24 19:23:16 +01001168 ieee80211_rx(hw, skb);
Luis R. Rodriguezf8316df2008-12-03 03:35:29 -08001169 break;
1170 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001171
Felix Fietkau0d955212011-01-26 18:23:27 +01001172 if (rs.rs_more) {
Ben Greear15072182012-04-03 09:18:59 -07001173 RX_STAT_INC(rx_frags);
Felix Fietkau0d955212011-01-26 18:23:27 +01001174 /*
1175 * rs_more indicates chained descriptors which can be
1176 * used to link buffers together for a sort of
1177 * scatter-gather operation.
1178 */
1179 if (sc->rx.frag) {
1180 /* too many fragments - cannot handle frame */
1181 dev_kfree_skb_any(sc->rx.frag);
1182 dev_kfree_skb_any(skb);
Ben Greear15072182012-04-03 09:18:59 -07001183 RX_STAT_INC(rx_too_many_frags_err);
Felix Fietkau0d955212011-01-26 18:23:27 +01001184 skb = NULL;
1185 }
1186 sc->rx.frag = skb;
1187 goto requeue;
1188 }
1189
1190 if (sc->rx.frag) {
1191 int space = skb->len - skb_tailroom(hdr_skb);
1192
Felix Fietkau0d955212011-01-26 18:23:27 +01001193 if (pskb_expand_head(hdr_skb, 0, space, GFP_ATOMIC) < 0) {
1194 dev_kfree_skb(skb);
Ben Greear15072182012-04-03 09:18:59 -07001195 RX_STAT_INC(rx_oom_err);
Felix Fietkau0d955212011-01-26 18:23:27 +01001196 goto requeue_drop_frag;
1197 }
1198
Eric Dumazetb5447ff2012-03-15 13:43:29 -07001199 sc->rx.frag = NULL;
1200
Felix Fietkau0d955212011-01-26 18:23:27 +01001201 skb_copy_from_linear_data(skb, skb_put(hdr_skb, skb->len),
1202 skb->len);
1203 dev_kfree_skb_any(skb);
1204 skb = hdr_skb;
1205 }
1206
Mohammed Shafi Shajakhaneb840a82011-11-29 20:30:35 +05301207
1208 if (ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB) {
1209
1210 /*
1211 * change the default rx antenna if rx diversity
1212 * chooses the other antenna 3 times in a row.
1213 */
1214 if (sc->rx.defant != rs.rs_antenna) {
1215 if (++sc->rx.rxotherant >= 3)
1216 ath_setdefantenna(sc, rs.rs_antenna);
1217 } else {
1218 sc->rx.rxotherant = 0;
1219 }
1220
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001221 }
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301222
Felix Fietkau66760ea2011-07-13 23:35:05 +08001223 if (rxs->flag & RX_FLAG_MMIC_STRIPPED)
1224 skb_trim(skb, skb->len - 8);
1225
Luis R. Rodriguez8ab2cd02010-09-16 15:12:26 -04001226 spin_lock_irqsave(&sc->sc_pm_lock, flags);
Mohammed Shafi Shajakhanaaef24b2010-12-07 20:40:58 +05301227 if ((sc->ps_flags & (PS_WAIT_FOR_BEACON |
Rajkumar Manoharanf73c6042011-09-26 22:16:56 +05301228 PS_WAIT_FOR_CAB |
1229 PS_WAIT_FOR_PSPOLL_DATA)) ||
1230 ath9k_check_auto_sleep(sc))
1231 ath_rx_ps(sc, skb, rs.is_mybeacon);
Luis R. Rodriguez8ab2cd02010-09-16 15:12:26 -04001232 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
Jouni Malinencc659652009-05-14 21:28:48 +03001233
Felix Fietkau43c35282011-09-03 01:40:27 +02001234 if ((ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB) && sc->ant_rx == 3)
Vasanthakumar Thiagarajan102885a2010-09-02 01:34:43 -07001235 ath_ant_comb_scan(sc, &rs);
1236
Felix Fietkau7545daf2011-01-24 19:23:16 +01001237 ieee80211_rx(hw, skb);
Jouni Malinencc659652009-05-14 21:28:48 +03001238
Felix Fietkau0d955212011-01-26 18:23:27 +01001239requeue_drop_frag:
1240 if (sc->rx.frag) {
1241 dev_kfree_skb_any(sc->rx.frag);
1242 sc->rx.frag = NULL;
1243 }
Luis R. Rodriguezcb71d9b2008-11-21 17:41:33 -08001244requeue:
Felix Fietkaua3dc48e2013-01-09 16:16:52 +01001245 list_add_tail(&bf->list, &sc->rx.rxbuf);
1246 if (flush)
1247 continue;
1248
Felix Fietkaub5c804752010-04-15 17:38:48 -04001249 if (edma) {
Felix Fietkaub5c804752010-04-15 17:38:48 -04001250 ath_rx_edma_buf_link(sc, qtype);
1251 } else {
Felix Fietkaub5c804752010-04-15 17:38:48 -04001252 ath_rx_buf_link(sc, bf);
Felix Fietkaua3dc48e2013-01-09 16:16:52 +01001253 ath9k_hw_rxena(ah);
Felix Fietkaub5c804752010-04-15 17:38:48 -04001254 }
Sujithbe0418a2008-11-18 09:05:55 +05301255 } while (1);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001256
Sujithb77f4832008-12-07 21:44:03 +05301257 spin_unlock_bh(&sc->rx.rxbuflock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001258
Rajkumar Manoharan29ab0b32011-08-13 10:28:10 +05301259 if (!(ah->imask & ATH9K_INT_RXEOL)) {
1260 ah->imask |= (ATH9K_INT_RXEOL | ATH9K_INT_RXORN);
Felix Fietkau72d874c2011-10-08 20:06:19 +02001261 ath9k_hw_set_interrupts(ah);
Rajkumar Manoharan29ab0b32011-08-13 10:28:10 +05301262 }
1263
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001264 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001265}