blob: 66c5fe81a03543b30c67534832b76d40e30ac254 [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 Fietkau1a04d592013-10-11 23:30:52 +020021#define SKB_CB_ATHBUF(__skb) (*((struct ath_rxbuf **)__skb->cb))
Felix Fietkaub5c804752010-04-15 17:38:48 -040022
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 */
Felix Fietkau7dd74f52014-05-23 19:21:34 +020037static void ath_rx_buf_link(struct ath_softc *sc, struct ath_rxbuf *bf,
38 bool flush)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070039{
Sujithcbe61d82009-02-09 13:27:12 +053040 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -080041 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070042 struct ath_desc *ds;
43 struct sk_buff *skb;
44
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070045 ds = bf->bf_desc;
Sujithbe0418a2008-11-18 09:05:55 +053046 ds->ds_link = 0; /* link to null */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070047 ds->ds_data = bf->bf_buf_addr;
48
Sujithbe0418a2008-11-18 09:05:55 +053049 /* virtual addr of the beginning of the buffer. */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070050 skb = bf->bf_mpdu;
Luis R. Rodriguez9680e8a2009-09-13 23:28:00 -070051 BUG_ON(skb == NULL);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070052 ds->ds_vdata = skb->data;
53
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -080054 /*
55 * setup rx descriptors. The rx_bufsize here tells the hardware
Luis R. Rodriguezb4b6cda2008-11-20 17:15:13 -080056 * how much data it can DMA to us and that we are prepared
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -080057 * to process
58 */
Sujithb77f4832008-12-07 21:44:03 +053059 ath9k_hw_setuprxdesc(ah, ds,
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -080060 common->rx_bufsize,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070061 0);
62
Felix Fietkau7dd74f52014-05-23 19:21:34 +020063 if (sc->rx.rxlink)
Sujithb77f4832008-12-07 21:44:03 +053064 *sc->rx.rxlink = bf->bf_daddr;
Felix Fietkau7dd74f52014-05-23 19:21:34 +020065 else if (!flush)
66 ath9k_hw_putrxbuf(ah, bf->bf_daddr);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070067
Sujithb77f4832008-12-07 21:44:03 +053068 sc->rx.rxlink = &ds->ds_link;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070069}
70
Felix Fietkau7dd74f52014-05-23 19:21:34 +020071static void ath_rx_buf_relink(struct ath_softc *sc, struct ath_rxbuf *bf,
72 bool flush)
Felix Fietkaue96542e2013-08-10 15:59:15 +020073{
74 if (sc->rx.buf_hold)
Felix Fietkau7dd74f52014-05-23 19:21:34 +020075 ath_rx_buf_link(sc, sc->rx.buf_hold, flush);
Felix Fietkaue96542e2013-08-10 15:59:15 +020076
77 sc->rx.buf_hold = bf;
78}
79
Sujithff37e332008-11-24 12:07:55 +053080static void ath_setdefantenna(struct ath_softc *sc, u32 antenna)
81{
82 /* XXX block beacon interrupts */
83 ath9k_hw_setantenna(sc->sc_ah, antenna);
Sujithb77f4832008-12-07 21:44:03 +053084 sc->rx.defant = antenna;
85 sc->rx.rxotherant = 0;
Sujithff37e332008-11-24 12:07:55 +053086}
87
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070088static void ath_opmode_init(struct ath_softc *sc)
89{
Sujithcbe61d82009-02-09 13:27:12 +053090 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez15107182009-09-10 09:22:37 -070091 struct ath_common *common = ath9k_hw_common(ah);
92
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070093 u32 rfilt, mfilt[2];
94
95 /* configure rx filter */
96 rfilt = ath_calcrxfilter(sc);
97 ath9k_hw_setrxfilter(ah, rfilt);
98
99 /* configure bssid mask */
Felix Fietkau364734f2010-09-14 20:22:44 +0200100 ath_hw_setbssidmask(common);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700101
102 /* configure operational mode */
103 ath9k_hw_setopmode(ah);
104
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700105 /* calculate and install multicast filter */
106 mfilt[0] = mfilt[1] = ~0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700107 ath9k_hw_setmcastfilter(ah, mfilt[0], mfilt[1]);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700108}
109
Felix Fietkaub5c804752010-04-15 17:38:48 -0400110static bool ath_rx_edma_buf_link(struct ath_softc *sc,
111 enum ath9k_rx_qtype qtype)
112{
113 struct ath_hw *ah = sc->sc_ah;
114 struct ath_rx_edma *rx_edma;
115 struct sk_buff *skb;
Felix Fietkau1a04d592013-10-11 23:30:52 +0200116 struct ath_rxbuf *bf;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400117
118 rx_edma = &sc->rx.rx_edma[qtype];
119 if (skb_queue_len(&rx_edma->rx_fifo) >= rx_edma->rx_fifo_hwsize)
120 return false;
121
Felix Fietkau1a04d592013-10-11 23:30:52 +0200122 bf = list_first_entry(&sc->rx.rxbuf, struct ath_rxbuf, list);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400123 list_del_init(&bf->list);
124
125 skb = bf->bf_mpdu;
126
Felix Fietkaub5c804752010-04-15 17:38:48 -0400127 memset(skb->data, 0, ah->caps.rx_status_len);
128 dma_sync_single_for_device(sc->dev, bf->bf_buf_addr,
129 ah->caps.rx_status_len, DMA_TO_DEVICE);
130
131 SKB_CB_ATHBUF(skb) = bf;
132 ath9k_hw_addrxbuf_edma(ah, bf->bf_buf_addr, qtype);
Sujith Manoharan07236bf2013-04-23 12:22:18 +0530133 __skb_queue_tail(&rx_edma->rx_fifo, skb);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400134
135 return true;
136}
137
138static void ath_rx_addbuffer_edma(struct ath_softc *sc,
Sujith Manoharan7a8972032013-04-23 12:22:16 +0530139 enum ath9k_rx_qtype qtype)
Felix Fietkaub5c804752010-04-15 17:38:48 -0400140{
Felix Fietkaub5c804752010-04-15 17:38:48 -0400141 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Felix Fietkau1a04d592013-10-11 23:30:52 +0200142 struct ath_rxbuf *bf, *tbf;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400143
Felix Fietkaub5c804752010-04-15 17:38:48 -0400144 if (list_empty(&sc->rx.rxbuf)) {
Joe Perchesd2182b62011-12-15 14:55:53 -0800145 ath_dbg(common, QUEUE, "No free rx buf available\n");
Felix Fietkaub5c804752010-04-15 17:38:48 -0400146 return;
147 }
148
Mohammed Shafi Shajakhan6a01f0c2012-02-28 20:54:44 +0530149 list_for_each_entry_safe(bf, tbf, &sc->rx.rxbuf, list)
Felix Fietkaub5c804752010-04-15 17:38:48 -0400150 if (!ath_rx_edma_buf_link(sc, qtype))
151 break;
152
Felix Fietkaub5c804752010-04-15 17:38:48 -0400153}
154
155static void ath_rx_remove_buffer(struct ath_softc *sc,
156 enum ath9k_rx_qtype qtype)
157{
Felix Fietkau1a04d592013-10-11 23:30:52 +0200158 struct ath_rxbuf *bf;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400159 struct ath_rx_edma *rx_edma;
160 struct sk_buff *skb;
161
162 rx_edma = &sc->rx.rx_edma[qtype];
163
Sujith Manoharan07236bf2013-04-23 12:22:18 +0530164 while ((skb = __skb_dequeue(&rx_edma->rx_fifo)) != NULL) {
Felix Fietkaub5c804752010-04-15 17:38:48 -0400165 bf = SKB_CB_ATHBUF(skb);
166 BUG_ON(!bf);
167 list_add_tail(&bf->list, &sc->rx.rxbuf);
168 }
169}
170
171static void ath_rx_edma_cleanup(struct ath_softc *sc)
172{
Mohammed Shafi Shajakhanba542382011-09-23 14:33:14 +0530173 struct ath_hw *ah = sc->sc_ah;
174 struct ath_common *common = ath9k_hw_common(ah);
Felix Fietkau1a04d592013-10-11 23:30:52 +0200175 struct ath_rxbuf *bf;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400176
177 ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_LP);
178 ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_HP);
179
180 list_for_each_entry(bf, &sc->rx.rxbuf, list) {
Mohammed Shafi Shajakhanba542382011-09-23 14:33:14 +0530181 if (bf->bf_mpdu) {
182 dma_unmap_single(sc->dev, bf->bf_buf_addr,
183 common->rx_bufsize,
184 DMA_BIDIRECTIONAL);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400185 dev_kfree_skb_any(bf->bf_mpdu);
Mohammed Shafi Shajakhanba542382011-09-23 14:33:14 +0530186 bf->bf_buf_addr = 0;
187 bf->bf_mpdu = NULL;
188 }
Felix Fietkaub5c804752010-04-15 17:38:48 -0400189 }
Felix Fietkaub5c804752010-04-15 17:38:48 -0400190}
191
192static void ath_rx_edma_init_queue(struct ath_rx_edma *rx_edma, int size)
193{
Sujith Manoharan5d07cca2013-08-14 21:15:57 +0530194 __skb_queue_head_init(&rx_edma->rx_fifo);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400195 rx_edma->rx_fifo_hwsize = size;
196}
197
198static int ath_rx_edma_init(struct ath_softc *sc, int nbufs)
199{
200 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
201 struct ath_hw *ah = sc->sc_ah;
202 struct sk_buff *skb;
Felix Fietkau1a04d592013-10-11 23:30:52 +0200203 struct ath_rxbuf *bf;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400204 int error = 0, i;
205 u32 size;
206
Felix Fietkaub5c804752010-04-15 17:38:48 -0400207 ath9k_hw_set_rx_bufsize(ah, common->rx_bufsize -
208 ah->caps.rx_status_len);
209
210 ath_rx_edma_init_queue(&sc->rx.rx_edma[ATH9K_RX_QUEUE_LP],
211 ah->caps.rx_lp_qdepth);
212 ath_rx_edma_init_queue(&sc->rx.rx_edma[ATH9K_RX_QUEUE_HP],
213 ah->caps.rx_hp_qdepth);
214
Felix Fietkau1a04d592013-10-11 23:30:52 +0200215 size = sizeof(struct ath_rxbuf) * nbufs;
Felix Fietkaub81950b12012-12-12 13:14:22 +0100216 bf = devm_kzalloc(sc->dev, size, GFP_KERNEL);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400217 if (!bf)
218 return -ENOMEM;
219
220 INIT_LIST_HEAD(&sc->rx.rxbuf);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400221
222 for (i = 0; i < nbufs; i++, bf++) {
223 skb = ath_rxbuf_alloc(common, common->rx_bufsize, GFP_KERNEL);
224 if (!skb) {
225 error = -ENOMEM;
226 goto rx_init_fail;
227 }
228
229 memset(skb->data, 0, common->rx_bufsize);
230 bf->bf_mpdu = skb;
231
232 bf->bf_buf_addr = dma_map_single(sc->dev, skb->data,
233 common->rx_bufsize,
234 DMA_BIDIRECTIONAL);
235 if (unlikely(dma_mapping_error(sc->dev,
236 bf->bf_buf_addr))) {
237 dev_kfree_skb_any(skb);
238 bf->bf_mpdu = NULL;
Ben Greear6cf9e992010-10-14 12:45:30 -0700239 bf->bf_buf_addr = 0;
Joe Perches38002762010-12-02 19:12:36 -0800240 ath_err(common,
Felix Fietkaub5c804752010-04-15 17:38:48 -0400241 "dma_mapping_error() on RX init\n");
242 error = -ENOMEM;
243 goto rx_init_fail;
244 }
245
246 list_add_tail(&bf->list, &sc->rx.rxbuf);
247 }
248
249 return 0;
250
251rx_init_fail:
252 ath_rx_edma_cleanup(sc);
253 return error;
254}
255
256static void ath_edma_start_recv(struct ath_softc *sc)
257{
Felix Fietkaub5c804752010-04-15 17:38:48 -0400258 ath9k_hw_rxena(sc->sc_ah);
Sujith Manoharan7a8972032013-04-23 12:22:16 +0530259 ath_rx_addbuffer_edma(sc, ATH9K_RX_QUEUE_HP);
260 ath_rx_addbuffer_edma(sc, ATH9K_RX_QUEUE_LP);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400261 ath_opmode_init(sc);
Felix Fietkaufbbcd142014-06-11 16:17:49 +0530262 ath9k_hw_startpcureceive(sc->sc_ah, sc->cur_chan->offchannel);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400263}
264
265static void ath_edma_stop_recv(struct ath_softc *sc)
266{
Felix Fietkaub5c804752010-04-15 17:38:48 -0400267 ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_HP);
268 ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_LP);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400269}
270
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700271int ath_rx_init(struct ath_softc *sc, int nbufs)
272{
Luis R. Rodriguez27c51f12009-09-10 11:08:14 -0700273 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700274 struct sk_buff *skb;
Felix Fietkau1a04d592013-10-11 23:30:52 +0200275 struct ath_rxbuf *bf;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700276 int error = 0;
277
Luis R. Rodriguez4bdd1e92010-10-26 15:27:24 -0700278 spin_lock_init(&sc->sc_pcu_lock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700279
Felix Fietkau0d955212011-01-26 18:23:27 +0100280 common->rx_bufsize = IEEE80211_MAX_MPDU_LEN / 2 +
281 sc->sc_ah->caps.rx_status_len;
282
Sujith Manoharane87f3d52013-04-23 12:22:17 +0530283 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
Felix Fietkaub5c804752010-04-15 17:38:48 -0400284 return ath_rx_edma_init(sc, nbufs);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700285
Sujith Manoharane87f3d52013-04-23 12:22:17 +0530286 ath_dbg(common, CONFIG, "cachelsz %u rxbufsize %u\n",
287 common->cachelsz, common->rx_bufsize);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700288
Sujith Manoharane87f3d52013-04-23 12:22:17 +0530289 /* Initialize rx descriptors */
290
291 error = ath_descdma_setup(sc, &sc->rx.rxdma, &sc->rx.rxbuf,
292 "rx", nbufs, 1, 0);
293 if (error != 0) {
294 ath_err(common,
295 "failed to allocate rx descriptors: %d\n",
296 error);
297 goto err;
298 }
299
300 list_for_each_entry(bf, &sc->rx.rxbuf, list) {
301 skb = ath_rxbuf_alloc(common, common->rx_bufsize,
302 GFP_KERNEL);
303 if (skb == NULL) {
304 error = -ENOMEM;
Sujith797fe5cb2009-03-30 15:28:45 +0530305 goto err;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700306 }
Felix Fietkaub5c804752010-04-15 17:38:48 -0400307
Sujith Manoharane87f3d52013-04-23 12:22:17 +0530308 bf->bf_mpdu = skb;
309 bf->bf_buf_addr = dma_map_single(sc->dev, skb->data,
310 common->rx_bufsize,
311 DMA_FROM_DEVICE);
312 if (unlikely(dma_mapping_error(sc->dev,
313 bf->bf_buf_addr))) {
314 dev_kfree_skb_any(skb);
315 bf->bf_mpdu = NULL;
316 bf->bf_buf_addr = 0;
317 ath_err(common,
318 "dma_mapping_error() on RX init\n");
319 error = -ENOMEM;
320 goto err;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400321 }
Sujith797fe5cb2009-03-30 15:28:45 +0530322 }
Sujith Manoharane87f3d52013-04-23 12:22:17 +0530323 sc->rx.rxlink = NULL;
Sujith797fe5cb2009-03-30 15:28:45 +0530324err:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700325 if (error)
326 ath_rx_cleanup(sc);
327
328 return error;
329}
330
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700331void ath_rx_cleanup(struct ath_softc *sc)
332{
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -0800333 struct ath_hw *ah = sc->sc_ah;
334 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700335 struct sk_buff *skb;
Felix Fietkau1a04d592013-10-11 23:30:52 +0200336 struct ath_rxbuf *bf;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700337
Felix Fietkaub5c804752010-04-15 17:38:48 -0400338 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
339 ath_rx_edma_cleanup(sc);
340 return;
Sujith Manoharane87f3d52013-04-23 12:22:17 +0530341 }
342
343 list_for_each_entry(bf, &sc->rx.rxbuf, list) {
344 skb = bf->bf_mpdu;
345 if (skb) {
346 dma_unmap_single(sc->dev, bf->bf_buf_addr,
347 common->rx_bufsize,
348 DMA_FROM_DEVICE);
349 dev_kfree_skb(skb);
350 bf->bf_buf_addr = 0;
351 bf->bf_mpdu = NULL;
Luis R. Rodriguez051b9192009-03-23 18:25:01 -0400352 }
Felix Fietkaub5c804752010-04-15 17:38:48 -0400353 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700354}
355
356/*
357 * Calculate the receive filter according to the
358 * operating mode and state:
359 *
360 * o always accept unicast, broadcast, and multicast traffic
361 * o maintain current state of phy error reception (the hal
362 * may enable phy error frames for noise immunity work)
363 * o probe request frames are accepted only when operating in
364 * hostap, adhoc, or monitor modes
365 * o enable promiscuous mode according to the interface state
366 * o accept beacons:
367 * - when operating in adhoc mode so the 802.11 layer creates
368 * node table entries for peers,
369 * - when operating in station mode for collecting rssi data when
370 * the station is otherwise quiet, or
371 * - when operating as a repeater so we see repeater-sta beacons
372 * - when scanning
373 */
374
375u32 ath_calcrxfilter(struct ath_softc *sc)
376{
Felix Fietkau78b21942014-06-11 16:17:55 +0530377 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700378 u32 rfilt;
379
Luis R. Rodriguez89f927a2013-10-14 17:42:11 -0700380 if (config_enabled(CONFIG_ATH9K_TX99))
381 return 0;
382
Felix Fietkauac066972011-10-08 15:49:57 +0200383 rfilt = ATH9K_RX_FILTER_UCAST | ATH9K_RX_FILTER_BCAST
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700384 | ATH9K_RX_FILTER_MCAST;
385
Zefir Kurtisi73e49372013-04-03 18:31:31 +0200386 /* if operating on a DFS channel, enable radar pulse detection */
387 if (sc->hw->conf.radar_enabled)
388 rfilt |= ATH9K_RX_FILTER_PHYRADAR | ATH9K_RX_FILTER_PHYERR;
389
Sujith Manoharanfce34432014-09-05 08:03:18 +0530390 spin_lock_bh(&sc->chan_lock);
391
392 if (sc->cur_chan->rxfilter & FIF_PROBE_REQ)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700393 rfilt |= ATH9K_RX_FILTER_PROBEREQ;
394
Jouni Malinen217ba9d2009-03-10 10:55:50 +0200395 /*
396 * Set promiscuous mode when FIF_PROMISC_IN_BSS is enabled for station
397 * mode interface or when in monitor mode. AP mode does not need this
398 * since it receives all in-BSS frames anyway.
399 */
Felix Fietkau2e286942011-03-09 01:48:12 +0100400 if (sc->sc_ah->is_monitoring)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700401 rfilt |= ATH9K_RX_FILTER_PROM;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700402
Sujith Manoharanfce34432014-09-05 08:03:18 +0530403 if (sc->cur_chan->rxfilter & FIF_CONTROL)
Sujithd42c6b72009-02-04 08:10:22 +0530404 rfilt |= ATH9K_RX_FILTER_CONTROL;
405
Vasanthakumar Thiagarajandbaaa142009-02-19 15:41:52 +0530406 if ((sc->sc_ah->opmode == NL80211_IFTYPE_STATION) &&
Sujith Manoharanca529c92014-09-05 08:03:19 +0530407 (sc->cur_chan->nvifs <= 1) &&
Sujith Manoharanfce34432014-09-05 08:03:18 +0530408 !(sc->cur_chan->rxfilter & FIF_BCN_PRBRESP_PROMISC))
Vasanthakumar Thiagarajandbaaa142009-02-19 15:41:52 +0530409 rfilt |= ATH9K_RX_FILTER_MYBEACON;
410 else
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700411 rfilt |= ATH9K_RX_FILTER_BEACON;
412
Felix Fietkau264bbec2011-04-07 19:24:23 +0200413 if ((sc->sc_ah->opmode == NL80211_IFTYPE_AP) ||
Sujith Manoharanfce34432014-09-05 08:03:18 +0530414 (sc->cur_chan->rxfilter & FIF_PSPOLL))
Vasanthakumar Thiagarajandbaaa142009-02-19 15:41:52 +0530415 rfilt |= ATH9K_RX_FILTER_PSPOLL;
Sujithbe0418a2008-11-18 09:05:55 +0530416
Sujith Manoharan3d1132d2014-09-05 08:03:17 +0530417 if (sc->cur_chandef.width != NL80211_CHAN_WIDTH_20_NOHT)
Sujith7ea310b2009-09-03 12:08:43 +0530418 rfilt |= ATH9K_RX_FILTER_COMP_BAR;
419
Sujith Manoharanca529c92014-09-05 08:03:19 +0530420 if (sc->cur_chan->nvifs > 1 || (sc->cur_chan->rxfilter & FIF_OTHER_BSS)) {
Thomas Wagnera5494592012-09-25 21:32:55 +0530421 /* This is needed for older chips */
422 if (sc->sc_ah->hw_version.macVersion <= AR_SREV_VERSION_9160)
Javier Cardona5eb6ba82009-08-20 19:12:07 -0700423 rfilt |= ATH9K_RX_FILTER_PROM;
Jouni Malinenb93bce22009-03-03 19:23:30 +0200424 rfilt |= ATH9K_RX_FILTER_MCAST_BCAST_ALL;
425 }
426
Sujith Manoharan2c323052013-12-31 08:12:02 +0530427 if (AR_SREV_9550(sc->sc_ah) || AR_SREV_9531(sc->sc_ah))
Gabor Juhosb3d7aa42012-07-03 19:13:33 +0200428 rfilt |= ATH9K_RX_FILTER_4ADDRESS;
429
Sujith Manoharan499afac2014-08-22 20:39:31 +0530430 if (ath9k_is_chanctx_enabled() &&
Felix Fietkau78b21942014-06-11 16:17:55 +0530431 test_bit(ATH_OP_SCANNING, &common->op_flags))
432 rfilt |= ATH9K_RX_FILTER_BEACON;
433
Sujith Manoharanfce34432014-09-05 08:03:18 +0530434 spin_unlock_bh(&sc->chan_lock);
435
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700436 return rfilt;
Sujith7dcfdcd2008-08-11 14:03:13 +0530437
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700438}
439
Sujith Manoharan19ec4772014-09-05 08:03:16 +0530440void ath_startrecv(struct ath_softc *sc)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700441{
Sujithcbe61d82009-02-09 13:27:12 +0530442 struct ath_hw *ah = sc->sc_ah;
Felix Fietkau1a04d592013-10-11 23:30:52 +0200443 struct ath_rxbuf *bf, *tbf;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700444
Felix Fietkaub5c804752010-04-15 17:38:48 -0400445 if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
446 ath_edma_start_recv(sc);
Sujith Manoharan19ec4772014-09-05 08:03:16 +0530447 return;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400448 }
449
Sujithb77f4832008-12-07 21:44:03 +0530450 if (list_empty(&sc->rx.rxbuf))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700451 goto start_recv;
452
Felix Fietkaue96542e2013-08-10 15:59:15 +0200453 sc->rx.buf_hold = NULL;
Sujithb77f4832008-12-07 21:44:03 +0530454 sc->rx.rxlink = NULL;
455 list_for_each_entry_safe(bf, tbf, &sc->rx.rxbuf, list) {
Felix Fietkau7dd74f52014-05-23 19:21:34 +0200456 ath_rx_buf_link(sc, bf, false);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700457 }
458
459 /* We could have deleted elements so the list may be empty now */
Sujithb77f4832008-12-07 21:44:03 +0530460 if (list_empty(&sc->rx.rxbuf))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700461 goto start_recv;
462
Felix Fietkau1a04d592013-10-11 23:30:52 +0200463 bf = list_first_entry(&sc->rx.rxbuf, struct ath_rxbuf, list);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700464 ath9k_hw_putrxbuf(ah, bf->bf_daddr);
Sujithbe0418a2008-11-18 09:05:55 +0530465 ath9k_hw_rxena(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700466
467start_recv:
Sujithbe0418a2008-11-18 09:05:55 +0530468 ath_opmode_init(sc);
Felix Fietkaufbbcd142014-06-11 16:17:49 +0530469 ath9k_hw_startpcureceive(ah, sc->cur_chan->offchannel);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700470}
471
Felix Fietkau4b883f02013-01-09 16:16:56 +0100472static void ath_flushrecv(struct ath_softc *sc)
473{
474 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
475 ath_rx_tasklet(sc, 1, true);
476 ath_rx_tasklet(sc, 1, false);
477}
478
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700479bool ath_stoprecv(struct ath_softc *sc)
480{
Sujithcbe61d82009-02-09 13:27:12 +0530481 struct ath_hw *ah = sc->sc_ah;
Felix Fietkau5882da022011-04-08 20:13:18 +0200482 bool stopped, reset = false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700483
Felix Fietkaud47844a2010-11-20 03:08:47 +0100484 ath9k_hw_abortpcurecv(ah);
Sujithbe0418a2008-11-18 09:05:55 +0530485 ath9k_hw_setrxfilter(ah, 0);
Felix Fietkau5882da022011-04-08 20:13:18 +0200486 stopped = ath9k_hw_stopdmarecv(ah, &reset);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400487
Felix Fietkau4b883f02013-01-09 16:16:56 +0100488 ath_flushrecv(sc);
489
Felix Fietkaub5c804752010-04-15 17:38:48 -0400490 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
491 ath_edma_stop_recv(sc);
492 else
493 sc->rx.rxlink = NULL;
Sujithbe0418a2008-11-18 09:05:55 +0530494
Rajkumar Manoharand5847472010-12-20 14:39:51 +0530495 if (!(ah->ah_flags & AH_UNPLUGGED) &&
496 unlikely(!stopped)) {
Ben Greeard7fd1b502010-12-06 13:13:07 -0800497 ath_err(ath9k_hw_common(sc->sc_ah),
498 "Could not stop RX, we could be "
499 "confusing the DMA engine when we start RX up\n");
500 ATH_DBG_WARN_ON_ONCE(!stopped);
501 }
Felix Fietkau2232d312011-04-15 00:41:43 +0200502 return stopped && !reset;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700503}
504
Jouni Malinencc659652009-05-14 21:28:48 +0300505static bool ath_beacon_dtim_pending_cab(struct sk_buff *skb)
506{
507 /* Check whether the Beacon frame has DTIM indicating buffered bc/mc */
508 struct ieee80211_mgmt *mgmt;
509 u8 *pos, *end, id, elen;
510 struct ieee80211_tim_ie *tim;
511
512 mgmt = (struct ieee80211_mgmt *)skb->data;
513 pos = mgmt->u.beacon.variable;
514 end = skb->data + skb->len;
515
516 while (pos + 2 < end) {
517 id = *pos++;
518 elen = *pos++;
519 if (pos + elen > end)
520 break;
521
522 if (id == WLAN_EID_TIM) {
523 if (elen < sizeof(*tim))
524 break;
525 tim = (struct ieee80211_tim_ie *) pos;
526 if (tim->dtim_count != 0)
527 break;
528 return tim->bitmap_ctrl & 0x01;
529 }
530
531 pos += elen;
532 }
533
534 return false;
535}
536
Jouni Malinencc659652009-05-14 21:28:48 +0300537static void ath_rx_ps_beacon(struct ath_softc *sc, struct sk_buff *skb)
538{
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700539 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujith Manoharan48bf43f2014-09-12 12:10:48 +0530540 bool skip_beacon = false;
Jouni Malinencc659652009-05-14 21:28:48 +0300541
542 if (skb->len < 24 + 8 + 2 + 2)
543 return;
544
Sujith1b04b932010-01-08 10:36:05 +0530545 sc->ps_flags &= ~PS_WAIT_FOR_BEACON;
Gabor Juhos293dc5d2009-06-19 12:17:48 +0200546
Sujith1b04b932010-01-08 10:36:05 +0530547 if (sc->ps_flags & PS_BEACON_SYNC) {
548 sc->ps_flags &= ~PS_BEACON_SYNC;
Joe Perchesd2182b62011-12-15 14:55:53 -0800549 ath_dbg(common, PS,
Sujith Manoharan1a6404a2013-02-04 15:38:24 +0530550 "Reconfigure beacon timers based on synchronized timestamp\n");
Sujith Manoharan48bf43f2014-09-12 12:10:48 +0530551
552 if (ath9k_is_chanctx_enabled()) {
553 if (sc->cur_chan == &sc->offchannel.chan)
554 skip_beacon = true;
555 }
556
557 if (!skip_beacon &&
558 !(WARN_ON_ONCE(sc->cur_chan->beacon.beacon_interval == 0)))
Ben Greear76c93982014-04-30 12:02:05 -0700559 ath9k_set_beacon(sc);
Sujith Manoharanc7dd40c2014-08-22 20:39:30 +0530560
561 ath9k_p2p_beacon_sync(sc);
Jouni Malinenccdfeab2009-05-20 21:59:08 +0300562 }
563
Jouni Malinencc659652009-05-14 21:28:48 +0300564 if (ath_beacon_dtim_pending_cab(skb)) {
565 /*
566 * Remain awake waiting for buffered broadcast/multicast
Gabor Juhos58f5fff2009-06-17 20:53:20 +0200567 * frames. If the last broadcast/multicast frame is not
568 * received properly, the next beacon frame will work as
569 * a backup trigger for returning into NETWORK SLEEP state,
570 * so we are waiting for it as well.
Jouni Malinencc659652009-05-14 21:28:48 +0300571 */
Joe Perchesd2182b62011-12-15 14:55:53 -0800572 ath_dbg(common, PS,
Joe Perches226afe62010-12-02 19:12:37 -0800573 "Received DTIM beacon indicating buffered broadcast/multicast frame(s)\n");
Sujith1b04b932010-01-08 10:36:05 +0530574 sc->ps_flags |= PS_WAIT_FOR_CAB | PS_WAIT_FOR_BEACON;
Jouni Malinencc659652009-05-14 21:28:48 +0300575 return;
576 }
577
Sujith1b04b932010-01-08 10:36:05 +0530578 if (sc->ps_flags & PS_WAIT_FOR_CAB) {
Jouni Malinencc659652009-05-14 21:28:48 +0300579 /*
580 * This can happen if a broadcast frame is dropped or the AP
581 * fails to send a frame indicating that all CAB frames have
582 * been delivered.
583 */
Sujith1b04b932010-01-08 10:36:05 +0530584 sc->ps_flags &= ~PS_WAIT_FOR_CAB;
Joe Perchesd2182b62011-12-15 14:55:53 -0800585 ath_dbg(common, PS, "PS wait for CAB frames timed out\n");
Jouni Malinencc659652009-05-14 21:28:48 +0300586 }
Jouni Malinencc659652009-05-14 21:28:48 +0300587}
588
Rajkumar Manoharanf73c6042011-09-26 22:16:56 +0530589static void ath_rx_ps(struct ath_softc *sc, struct sk_buff *skb, bool mybeacon)
Jouni Malinencc659652009-05-14 21:28:48 +0300590{
591 struct ieee80211_hdr *hdr;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700592 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Jouni Malinencc659652009-05-14 21:28:48 +0300593
594 hdr = (struct ieee80211_hdr *)skb->data;
595
596 /* Process Beacon and CAB receive in PS state */
Vasanthakumar Thiagarajanededf1f2010-05-22 23:58:13 -0700597 if (((sc->ps_flags & PS_WAIT_FOR_BEACON) || ath9k_check_auto_sleep(sc))
Sujith Manoharan07c15a32012-06-04 20:24:07 +0530598 && mybeacon) {
Jouni Malinencc659652009-05-14 21:28:48 +0300599 ath_rx_ps_beacon(sc, skb);
Sujith Manoharan07c15a32012-06-04 20:24:07 +0530600 } else if ((sc->ps_flags & PS_WAIT_FOR_CAB) &&
601 (ieee80211_is_data(hdr->frame_control) ||
602 ieee80211_is_action(hdr->frame_control)) &&
603 is_multicast_ether_addr(hdr->addr1) &&
604 !ieee80211_has_moredata(hdr->frame_control)) {
Jouni Malinencc659652009-05-14 21:28:48 +0300605 /*
606 * No more broadcast/multicast frames to be received at this
607 * point.
608 */
Senthil Balasubramanian3fac6df2010-09-16 15:12:35 -0400609 sc->ps_flags &= ~(PS_WAIT_FOR_CAB | PS_WAIT_FOR_BEACON);
Joe Perchesd2182b62011-12-15 14:55:53 -0800610 ath_dbg(common, PS,
Joe Perches226afe62010-12-02 19:12:37 -0800611 "All PS CAB frames received, back to sleep\n");
Sujith1b04b932010-01-08 10:36:05 +0530612 } else if ((sc->ps_flags & PS_WAIT_FOR_PSPOLL_DATA) &&
Jouni Malinen9a23f9c2009-05-19 17:01:38 +0300613 !is_multicast_ether_addr(hdr->addr1) &&
614 !ieee80211_has_morefrags(hdr->frame_control)) {
Sujith1b04b932010-01-08 10:36:05 +0530615 sc->ps_flags &= ~PS_WAIT_FOR_PSPOLL_DATA;
Joe Perchesd2182b62011-12-15 14:55:53 -0800616 ath_dbg(common, PS,
Joe Perches226afe62010-12-02 19:12:37 -0800617 "Going back to sleep after having received PS-Poll data (0x%lx)\n",
Sujith1b04b932010-01-08 10:36:05 +0530618 sc->ps_flags & (PS_WAIT_FOR_BEACON |
619 PS_WAIT_FOR_CAB |
620 PS_WAIT_FOR_PSPOLL_DATA |
621 PS_WAIT_FOR_TX_ACK));
Jouni Malinencc659652009-05-14 21:28:48 +0300622 }
623}
624
Felix Fietkaub5c804752010-04-15 17:38:48 -0400625static bool ath_edma_get_buffers(struct ath_softc *sc,
Felix Fietkau3a2923e2012-03-03 15:17:05 +0100626 enum ath9k_rx_qtype qtype,
627 struct ath_rx_status *rs,
Felix Fietkau1a04d592013-10-11 23:30:52 +0200628 struct ath_rxbuf **dest)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700629{
Felix Fietkaub5c804752010-04-15 17:38:48 -0400630 struct ath_rx_edma *rx_edma = &sc->rx.rx_edma[qtype];
631 struct ath_hw *ah = sc->sc_ah;
632 struct ath_common *common = ath9k_hw_common(ah);
633 struct sk_buff *skb;
Felix Fietkau1a04d592013-10-11 23:30:52 +0200634 struct ath_rxbuf *bf;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400635 int ret;
636
637 skb = skb_peek(&rx_edma->rx_fifo);
638 if (!skb)
639 return false;
640
641 bf = SKB_CB_ATHBUF(skb);
642 BUG_ON(!bf);
643
Ming Leice9426d2010-05-15 18:25:40 +0800644 dma_sync_single_for_cpu(sc->dev, bf->bf_buf_addr,
Felix Fietkaub5c804752010-04-15 17:38:48 -0400645 common->rx_bufsize, DMA_FROM_DEVICE);
646
Felix Fietkau3a2923e2012-03-03 15:17:05 +0100647 ret = ath9k_hw_process_rxdesc_edma(ah, rs, skb->data);
Ming Leice9426d2010-05-15 18:25:40 +0800648 if (ret == -EINPROGRESS) {
649 /*let device gain the buffer again*/
650 dma_sync_single_for_device(sc->dev, bf->bf_buf_addr,
651 common->rx_bufsize, DMA_FROM_DEVICE);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400652 return false;
Ming Leice9426d2010-05-15 18:25:40 +0800653 }
Felix Fietkaub5c804752010-04-15 17:38:48 -0400654
655 __skb_unlink(skb, &rx_edma->rx_fifo);
656 if (ret == -EINVAL) {
657 /* corrupt descriptor, skip this one and the following one */
658 list_add_tail(&bf->list, &sc->rx.rxbuf);
659 ath_rx_edma_buf_link(sc, qtype);
Felix Fietkau3a2923e2012-03-03 15:17:05 +0100660
Felix Fietkaub5c804752010-04-15 17:38:48 -0400661 skb = skb_peek(&rx_edma->rx_fifo);
Felix Fietkau3a2923e2012-03-03 15:17:05 +0100662 if (skb) {
663 bf = SKB_CB_ATHBUF(skb);
664 BUG_ON(!bf);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400665
Felix Fietkau3a2923e2012-03-03 15:17:05 +0100666 __skb_unlink(skb, &rx_edma->rx_fifo);
667 list_add_tail(&bf->list, &sc->rx.rxbuf);
668 ath_rx_edma_buf_link(sc, qtype);
Felix Fietkau3a2923e2012-03-03 15:17:05 +0100669 }
Tom Hughes6bb51c72012-06-27 18:21:15 +0100670
671 bf = NULL;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400672 }
Felix Fietkaub5c804752010-04-15 17:38:48 -0400673
Felix Fietkau3a2923e2012-03-03 15:17:05 +0100674 *dest = bf;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400675 return true;
676}
677
Felix Fietkau1a04d592013-10-11 23:30:52 +0200678static struct ath_rxbuf *ath_edma_get_next_rx_buf(struct ath_softc *sc,
Felix Fietkaub5c804752010-04-15 17:38:48 -0400679 struct ath_rx_status *rs,
680 enum ath9k_rx_qtype qtype)
681{
Felix Fietkau1a04d592013-10-11 23:30:52 +0200682 struct ath_rxbuf *bf = NULL;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400683
Felix Fietkau3a2923e2012-03-03 15:17:05 +0100684 while (ath_edma_get_buffers(sc, qtype, rs, &bf)) {
685 if (!bf)
686 continue;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400687
Felix Fietkau3a2923e2012-03-03 15:17:05 +0100688 return bf;
689 }
690 return NULL;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400691}
692
Felix Fietkau1a04d592013-10-11 23:30:52 +0200693static struct ath_rxbuf *ath_get_next_rx_buf(struct ath_softc *sc,
Felix Fietkaub5c804752010-04-15 17:38:48 -0400694 struct ath_rx_status *rs)
695{
696 struct ath_hw *ah = sc->sc_ah;
697 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700698 struct ath_desc *ds;
Felix Fietkau1a04d592013-10-11 23:30:52 +0200699 struct ath_rxbuf *bf;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400700 int ret;
701
702 if (list_empty(&sc->rx.rxbuf)) {
703 sc->rx.rxlink = NULL;
704 return NULL;
705 }
706
Felix Fietkau1a04d592013-10-11 23:30:52 +0200707 bf = list_first_entry(&sc->rx.rxbuf, struct ath_rxbuf, list);
Felix Fietkaue96542e2013-08-10 15:59:15 +0200708 if (bf == sc->rx.buf_hold)
709 return NULL;
710
Felix Fietkaub5c804752010-04-15 17:38:48 -0400711 ds = bf->bf_desc;
712
713 /*
714 * Must provide the virtual address of the current
715 * descriptor, the physical address, and the virtual
716 * address of the next descriptor in the h/w chain.
717 * This allows the HAL to look ahead to see if the
718 * hardware is done with a descriptor by checking the
719 * done bit in the following descriptor and the address
720 * of the current descriptor the DMA engine is working
721 * on. All this is necessary because of our use of
722 * a self-linked list to avoid rx overruns.
723 */
Rajkumar Manoharan3de21112011-08-13 10:28:11 +0530724 ret = ath9k_hw_rxprocdesc(ah, ds, rs);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400725 if (ret == -EINPROGRESS) {
726 struct ath_rx_status trs;
Felix Fietkau1a04d592013-10-11 23:30:52 +0200727 struct ath_rxbuf *tbf;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400728 struct ath_desc *tds;
729
730 memset(&trs, 0, sizeof(trs));
731 if (list_is_last(&bf->list, &sc->rx.rxbuf)) {
732 sc->rx.rxlink = NULL;
733 return NULL;
734 }
735
Felix Fietkau1a04d592013-10-11 23:30:52 +0200736 tbf = list_entry(bf->list.next, struct ath_rxbuf, list);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400737
738 /*
739 * On some hardware the descriptor status words could
740 * get corrupted, including the done bit. Because of
741 * this, check if the next descriptor's done bit is
742 * set or not.
743 *
744 * If the next descriptor's done bit is set, the current
745 * descriptor has been corrupted. Force s/w to discard
746 * this descriptor and continue...
747 */
748
749 tds = tbf->bf_desc;
Rajkumar Manoharan3de21112011-08-13 10:28:11 +0530750 ret = ath9k_hw_rxprocdesc(ah, tds, &trs);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400751 if (ret == -EINPROGRESS)
752 return NULL;
Felix Fietkau723e7112013-04-08 00:04:11 +0200753
754 /*
Felix Fietkaub7b146c2014-02-24 22:26:06 +0100755 * Re-check previous descriptor, in case it has been filled
756 * in the mean time.
Felix Fietkau723e7112013-04-08 00:04:11 +0200757 */
Felix Fietkaub7b146c2014-02-24 22:26:06 +0100758 ret = ath9k_hw_rxprocdesc(ah, ds, rs);
759 if (ret == -EINPROGRESS) {
760 /*
761 * mark descriptor as zero-length and set the 'more'
762 * flag to ensure that both buffers get discarded
763 */
764 rs->rs_datalen = 0;
765 rs->rs_more = true;
766 }
Felix Fietkaub5c804752010-04-15 17:38:48 -0400767 }
768
Felix Fietkaua3dc48e2013-01-09 16:16:52 +0100769 list_del(&bf->list);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400770 if (!bf->bf_mpdu)
771 return bf;
772
773 /*
774 * Synchronize the DMA transfer with CPU before
775 * 1. accessing the frame
776 * 2. requeueing the same buffer to h/w
777 */
Ming Leice9426d2010-05-15 18:25:40 +0800778 dma_sync_single_for_cpu(sc->dev, bf->bf_buf_addr,
Felix Fietkaub5c804752010-04-15 17:38:48 -0400779 common->rx_bufsize,
780 DMA_FROM_DEVICE);
781
782 return bf;
783}
784
Sujith Manoharane0dd1a92013-08-14 09:11:13 +0530785static void ath9k_process_tsf(struct ath_rx_status *rs,
786 struct ieee80211_rx_status *rxs,
787 u64 tsf)
788{
789 u32 tsf_lower = tsf & 0xffffffff;
790
791 rxs->mactime = (tsf & ~0xffffffffULL) | rs->rs_tstamp;
792 if (rs->rs_tstamp > tsf_lower &&
793 unlikely(rs->rs_tstamp - tsf_lower > 0x10000000))
794 rxs->mactime -= 0x100000000ULL;
795
796 if (rs->rs_tstamp < tsf_lower &&
797 unlikely(tsf_lower - rs->rs_tstamp > 0x10000000))
798 rxs->mactime += 0x100000000ULL;
799}
800
Sujithd4357002010-05-20 15:34:38 +0530801/*
802 * For Decrypt or Demic errors, we only mark packet status here and always push
803 * up the frame up to let mac80211 handle the actual error case, be it no
804 * decryption key or real decryption error. This let us keep statistics there.
805 */
Felix Fietkau723e7112013-04-08 00:04:11 +0200806static int ath9k_rx_skb_preprocess(struct ath_softc *sc,
Sujith Manoharan6f384822013-08-14 09:11:18 +0530807 struct sk_buff *skb,
Sujithd4357002010-05-20 15:34:38 +0530808 struct ath_rx_status *rx_stats,
809 struct ieee80211_rx_status *rx_status,
Sujith Manoharane0dd1a92013-08-14 09:11:13 +0530810 bool *decrypt_error, u64 tsf)
Sujithd4357002010-05-20 15:34:38 +0530811{
Felix Fietkau723e7112013-04-08 00:04:11 +0200812 struct ieee80211_hw *hw = sc->hw;
813 struct ath_hw *ah = sc->sc_ah;
814 struct ath_common *common = ath9k_hw_common(ah);
Sujith Manoharan6f384822013-08-14 09:11:18 +0530815 struct ieee80211_hdr *hdr;
Felix Fietkau723e7112013-04-08 00:04:11 +0200816 bool discard_current = sc->rx.discard_next;
817
Sujith Manoharan5871d2d2013-08-14 09:11:11 +0530818 /*
819 * Discard corrupt descriptors which are marked in
820 * ath_get_next_rx_buf().
821 */
Felix Fietkau723e7112013-04-08 00:04:11 +0200822 if (discard_current)
Felix Fietkaub7b146c2014-02-24 22:26:06 +0100823 goto corrupt;
824
825 sc->rx.discard_next = false;
Felix Fietkauf749b942011-07-28 14:08:57 +0200826
Sujithd4357002010-05-20 15:34:38 +0530827 /*
Sujith Manoharan5871d2d2013-08-14 09:11:11 +0530828 * Discard zero-length packets.
829 */
830 if (!rx_stats->rs_datalen) {
831 RX_STAT_INC(rx_len_err);
Felix Fietkaub7b146c2014-02-24 22:26:06 +0100832 goto corrupt;
Sujith Manoharan5871d2d2013-08-14 09:11:11 +0530833 }
834
Felix Fietkaub7b146c2014-02-24 22:26:06 +0100835 /*
836 * rs_status follows rs_datalen so if rs_datalen is too large
837 * we can take a hint that hardware corrupted it, so ignore
838 * those frames.
839 */
Sujith Manoharan5871d2d2013-08-14 09:11:11 +0530840 if (rx_stats->rs_datalen > (common->rx_bufsize - ah->caps.rx_status_len)) {
841 RX_STAT_INC(rx_len_err);
Felix Fietkaub7b146c2014-02-24 22:26:06 +0100842 goto corrupt;
Sujith Manoharan5871d2d2013-08-14 09:11:11 +0530843 }
844
Sujith Manoharan4a470642013-08-14 09:11:12 +0530845 /* Only use status info from the last fragment */
846 if (rx_stats->rs_more)
847 return 0;
848
Sujith Manoharanb0925592013-08-14 09:11:20 +0530849 /*
850 * Return immediately if the RX descriptor has been marked
851 * as corrupt based on the various error bits.
852 *
853 * This is different from the other corrupt descriptor
854 * condition handled above.
855 */
Felix Fietkaub7b146c2014-02-24 22:26:06 +0100856 if (rx_stats->rs_status & ATH9K_RXERR_CORRUPT_DESC)
857 goto corrupt;
Sujith Manoharanb0925592013-08-14 09:11:20 +0530858
Sujith Manoharan6f384822013-08-14 09:11:18 +0530859 hdr = (struct ieee80211_hdr *) (skb->data + ah->caps.rx_status_len);
860
Sujith Manoharane0dd1a92013-08-14 09:11:13 +0530861 ath9k_process_tsf(rx_stats, rx_status, tsf);
Sujith Manoharan5e85a322013-08-14 09:11:16 +0530862 ath_debug_stat_rx(sc, rx_stats);
Sujith Manoharane0dd1a92013-08-14 09:11:13 +0530863
Sujith Manoharan5871d2d2013-08-14 09:11:11 +0530864 /*
Sujith Manoharan6b87d712013-08-14 09:11:15 +0530865 * Process PHY errors and return so that the packet
866 * can be dropped.
867 */
868 if (rx_stats->rs_status & ATH9K_RXERR_PHY) {
869 ath9k_dfs_process_phyerr(sc, hdr, rx_stats, rx_status->mactime);
870 if (ath_process_fft(sc, hdr, rx_stats, rx_status->mactime))
871 RX_STAT_INC(rx_spectral);
872
Felix Fietkaub7b146c2014-02-24 22:26:06 +0100873 return -EINVAL;
Sujith Manoharan6b87d712013-08-14 09:11:15 +0530874 }
875
876 /*
Sujithd4357002010-05-20 15:34:38 +0530877 * everything but the rate is checked here, the rate check is done
878 * separately to avoid doing two lookups for a rate for each frame.
879 */
Sujith Manoharanfce34432014-09-05 08:03:18 +0530880 spin_lock_bh(&sc->chan_lock);
881 if (!ath9k_cmn_rx_accept(common, hdr, rx_status, rx_stats, decrypt_error,
882 sc->cur_chan->rxfilter)) {
883 spin_unlock_bh(&sc->chan_lock);
Felix Fietkaub7b146c2014-02-24 22:26:06 +0100884 return -EINVAL;
Sujith Manoharanfce34432014-09-05 08:03:18 +0530885 }
886 spin_unlock_bh(&sc->chan_lock);
Sujithd4357002010-05-20 15:34:38 +0530887
Oleksij Rempel1cc47a52014-01-15 17:07:15 +0100888 if (ath_is_mybeacon(common, hdr)) {
889 RX_STAT_INC(rx_beacons);
890 rx_stats->is_mybeacon = true;
891 }
Sujith Manoharan6f384822013-08-14 09:11:18 +0530892
Sujith Manoharanff9a93f2014-01-09 08:51:14 +0530893 /*
894 * This shouldn't happen, but have a safety check anyway.
895 */
Felix Fietkaub7b146c2014-02-24 22:26:06 +0100896 if (WARN_ON(!ah->curchan))
897 return -EINVAL;
Sujith Manoharanff9a93f2014-01-09 08:51:14 +0530898
Oleksij Rempel12746032014-02-04 10:27:40 +0100899 if (ath9k_cmn_process_rate(common, hw, rx_stats, rx_status)) {
900 /*
901 * No valid hardware bitrate found -- we should not get here
902 * because hardware has already validated this frame as OK.
903 */
904 ath_dbg(common, ANY, "unsupported hw bitrate detected 0x%02x using 1 Mbit\n",
905 rx_stats->rs_rate);
906 RX_STAT_INC(rx_rate_err);
Felix Fietkaub7b146c2014-02-24 22:26:06 +0100907 return -EINVAL;
Sujith Manoharan7c5c73c2013-08-14 09:11:21 +0530908 }
Sujithd4357002010-05-20 15:34:38 +0530909
Sujith Manoharan27babf92014-08-23 13:29:16 +0530910 if (ath9k_is_chanctx_enabled()) {
Sujith Manoharan70b06da2014-08-23 13:29:18 +0530911 if (rx_stats->is_mybeacon)
Sujith Manoharana2b28602014-09-15 11:25:50 +0530912 ath_chanctx_beacon_recv_ev(sc,
Sujith Manoharan70b06da2014-08-23 13:29:18 +0530913 ATH_CHANCTX_EVENT_BEACON_RECEIVED);
Felix Fietkau58b57372014-06-11 16:18:08 +0530914 }
915
Oleksij Rempel32efb0c2014-02-04 10:27:39 +0100916 ath9k_cmn_process_rssi(common, hw, rx_stats, rx_status);
Sujith Manoharan74a97752013-06-03 09:19:23 +0530917
Sujith Manoharanff9a93f2014-01-09 08:51:14 +0530918 rx_status->band = ah->curchan->chan->band;
919 rx_status->freq = ah->curchan->chan->center_freq;
Sujithd4357002010-05-20 15:34:38 +0530920 rx_status->antenna = rx_stats->rs_antenna;
Thomas Pedersen96d21372012-12-10 14:48:01 -0800921 rx_status->flag |= RX_FLAG_MACTIME_END;
Sujithd4357002010-05-20 15:34:38 +0530922
Sujith Manoharana5525d92013-08-14 09:11:17 +0530923#ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
924 if (ieee80211_is_data_present(hdr->frame_control) &&
925 !ieee80211_is_qos_nullfunc(hdr->frame_control))
926 sc->rx.num_pkts++;
927#endif
928
Felix Fietkaub7b146c2014-02-24 22:26:06 +0100929 return 0;
930
931corrupt:
932 sc->rx.discard_next = rx_stats->rs_more;
933 return -EINVAL;
Sujithd4357002010-05-20 15:34:38 +0530934}
935
Sujith Manoharanc3124df2013-08-14 21:15:56 +0530936/*
937 * Run the LNA combining algorithm only in these cases:
938 *
939 * Standalone WLAN cards with both LNA/Antenna diversity
940 * enabled in the EEPROM.
941 *
942 * WLAN+BT cards which are in the supported card list
943 * in ath_pci_id_table and the user has loaded the
944 * driver with "bt_ant_diversity" set to true.
945 */
946static void ath9k_antenna_check(struct ath_softc *sc,
947 struct ath_rx_status *rs)
948{
949 struct ath_hw *ah = sc->sc_ah;
950 struct ath9k_hw_capabilities *pCap = &ah->caps;
951 struct ath_common *common = ath9k_hw_common(ah);
952
953 if (!(ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB))
954 return;
955
956 /*
Sujith Manoharanc3124df2013-08-14 21:15:56 +0530957 * Change the default rx antenna if rx diversity
958 * chooses the other antenna 3 times in a row.
959 */
960 if (sc->rx.defant != rs->rs_antenna) {
961 if (++sc->rx.rxotherant >= 3)
962 ath_setdefantenna(sc, rs->rs_antenna);
963 } else {
964 sc->rx.rxotherant = 0;
965 }
966
967 if (pCap->hw_caps & ATH9K_HW_CAP_BT_ANT_DIV) {
968 if (common->bt_ant_diversity)
969 ath_ant_comb_scan(sc, rs);
970 } else {
971 ath_ant_comb_scan(sc, rs);
972 }
973}
974
Christian Lamparter21fbbca2013-01-30 23:37:41 +0100975static void ath9k_apply_ampdu_details(struct ath_softc *sc,
976 struct ath_rx_status *rs, struct ieee80211_rx_status *rxs)
977{
978 if (rs->rs_isaggr) {
979 rxs->flag |= RX_FLAG_AMPDU_DETAILS | RX_FLAG_AMPDU_LAST_KNOWN;
980
981 rxs->ampdu_reference = sc->rx.ampdu_ref;
982
983 if (!rs->rs_moreaggr) {
984 rxs->flag |= RX_FLAG_AMPDU_IS_LAST;
985 sc->rx.ampdu_ref++;
986 }
987
988 if (rs->rs_flags & ATH9K_RX_DELIM_CRC_PRE)
989 rxs->flag |= RX_FLAG_AMPDU_DELIM_CRC_ERROR;
990 }
991}
992
Felix Fietkaub5c804752010-04-15 17:38:48 -0400993int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp)
994{
Felix Fietkau1a04d592013-10-11 23:30:52 +0200995 struct ath_rxbuf *bf;
Felix Fietkau0d955212011-01-26 18:23:27 +0100996 struct sk_buff *skb = NULL, *requeue_skb, *hdr_skb;
Luis R. Rodriguez5ca42622009-11-04 08:20:42 -0800997 struct ieee80211_rx_status *rxs;
Sujithcbe61d82009-02-09 13:27:12 +0530998 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez27c51f12009-09-10 11:08:14 -0700999 struct ath_common *common = ath9k_hw_common(ah);
Felix Fietkau7545daf2011-01-24 19:23:16 +01001000 struct ieee80211_hw *hw = sc->hw;
Luis R. Rodriguezc9b14172009-11-04 16:47:22 -08001001 int retval;
Felix Fietkau29bffa92010-03-29 20:14:23 -07001002 struct ath_rx_status rs;
Felix Fietkaub5c804752010-04-15 17:38:48 -04001003 enum ath9k_rx_qtype qtype;
1004 bool edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA);
1005 int dma_type;
Felix Fietkaua6d20552010-06-12 00:33:54 -04001006 u64 tsf = 0;
Luis R. Rodriguez8ab2cd02010-09-16 15:12:26 -04001007 unsigned long flags;
Felix Fietkau2e1cd492013-04-08 00:04:10 +02001008 dma_addr_t new_buf_addr;
Tim Harveyc82552c2014-04-21 16:14:57 -07001009 unsigned int budget = 512;
Lorenzo Bianconi982e0392014-09-16 02:13:12 +02001010 struct ieee80211_hdr *hdr;
Sujithbe0418a2008-11-18 09:05:55 +05301011
Felix Fietkaub5c804752010-04-15 17:38:48 -04001012 if (edma)
Felix Fietkaub5c804752010-04-15 17:38:48 -04001013 dma_type = DMA_BIDIRECTIONAL;
Ming Lei56824222010-05-14 21:15:38 +08001014 else
1015 dma_type = DMA_FROM_DEVICE;
Felix Fietkaub5c804752010-04-15 17:38:48 -04001016
1017 qtype = hp ? ATH9K_RX_QUEUE_HP : ATH9K_RX_QUEUE_LP;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001018
Felix Fietkaua6d20552010-06-12 00:33:54 -04001019 tsf = ath9k_hw_gettsf64(ah);
Felix Fietkaua6d20552010-06-12 00:33:54 -04001020
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001021 do {
Lorenzo Bianconie1352fd2012-08-10 11:00:24 +02001022 bool decrypt_error = false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001023
Felix Fietkau29bffa92010-03-29 20:14:23 -07001024 memset(&rs, 0, sizeof(rs));
Felix Fietkaub5c804752010-04-15 17:38:48 -04001025 if (edma)
1026 bf = ath_edma_get_next_rx_buf(sc, &rs, qtype);
1027 else
1028 bf = ath_get_next_rx_buf(sc, &rs);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001029
Felix Fietkaub5c804752010-04-15 17:38:48 -04001030 if (!bf)
1031 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001032
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001033 skb = bf->bf_mpdu;
Sujithbe0418a2008-11-18 09:05:55 +05301034 if (!skb)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001035 continue;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001036
Felix Fietkau0d955212011-01-26 18:23:27 +01001037 /*
1038 * Take frame header from the first fragment and RX status from
1039 * the last one.
1040 */
1041 if (sc->rx.frag)
1042 hdr_skb = sc->rx.frag;
1043 else
1044 hdr_skb = skb;
1045
Sujith Manoharanf6307dd2013-08-14 09:11:09 +05301046 rxs = IEEE80211_SKB_RXCB(hdr_skb);
Ashok Nagarajanffb1c562012-03-09 18:57:39 -08001047 memset(rxs, 0, sizeof(struct ieee80211_rx_status));
1048
Sujith Manoharan6f384822013-08-14 09:11:18 +05301049 retval = ath9k_rx_skb_preprocess(sc, hdr_skb, &rs, rxs,
Sujith Manoharane0dd1a92013-08-14 09:11:13 +05301050 &decrypt_error, tsf);
Zefir Kurtisi83c76572011-11-16 11:09:44 +01001051 if (retval)
1052 goto requeue_drop_frag;
1053
Luis R. Rodriguezcb71d9b2008-11-21 17:41:33 -08001054 /* Ensure we always have an skb to requeue once we are done
1055 * processing the current buffer's skb */
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -08001056 requeue_skb = ath_rxbuf_alloc(common, common->rx_bufsize, GFP_ATOMIC);
Luis R. Rodriguezcb71d9b2008-11-21 17:41:33 -08001057
1058 /* If there is no memory we ignore the current RX'd frame,
1059 * tell hardware it can give us a new frame using the old
Sujithb77f4832008-12-07 21:44:03 +05301060 * skb and put it at the tail of the sc->rx.rxbuf list for
Luis R. Rodriguezcb71d9b2008-11-21 17:41:33 -08001061 * processing. */
Ben Greear15072182012-04-03 09:18:59 -07001062 if (!requeue_skb) {
1063 RX_STAT_INC(rx_oom_err);
Felix Fietkau0d955212011-01-26 18:23:27 +01001064 goto requeue_drop_frag;
Ben Greear15072182012-04-03 09:18:59 -07001065 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001066
Felix Fietkau2e1cd492013-04-08 00:04:10 +02001067 /* We will now give hardware our shiny new allocated skb */
1068 new_buf_addr = dma_map_single(sc->dev, requeue_skb->data,
1069 common->rx_bufsize, dma_type);
1070 if (unlikely(dma_mapping_error(sc->dev, new_buf_addr))) {
1071 dev_kfree_skb_any(requeue_skb);
1072 goto requeue_drop_frag;
1073 }
1074
Vasanthakumar Thiagarajan9bf9fca2008-12-15 20:40:46 +05301075 /* Unmap the frame */
Gabor Juhos7da3c552009-01-14 20:17:03 +01001076 dma_unmap_single(sc->dev, bf->bf_buf_addr,
Felix Fietkau2e1cd492013-04-08 00:04:10 +02001077 common->rx_bufsize, dma_type);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001078
Sujith Manoharan176f0e82013-04-23 12:22:19 +05301079 bf->bf_mpdu = requeue_skb;
1080 bf->bf_buf_addr = new_buf_addr;
1081
Felix Fietkaub5c804752010-04-15 17:38:48 -04001082 skb_put(skb, rs.rs_datalen + ah->caps.rx_status_len);
1083 if (ah->caps.rx_status_len)
1084 skb_pull(skb, ah->caps.rx_status_len);
Sujithbe0418a2008-11-18 09:05:55 +05301085
Felix Fietkau0d955212011-01-26 18:23:27 +01001086 if (!rs.rs_more)
Oleksij Rempel5a078fc2014-02-04 10:27:47 +01001087 ath9k_cmn_rx_skb_postprocess(common, hdr_skb, &rs,
1088 rxs, decrypt_error);
Sujithbe0418a2008-11-18 09:05:55 +05301089
Felix Fietkau0d955212011-01-26 18:23:27 +01001090 if (rs.rs_more) {
Ben Greear15072182012-04-03 09:18:59 -07001091 RX_STAT_INC(rx_frags);
Felix Fietkau0d955212011-01-26 18:23:27 +01001092 /*
1093 * rs_more indicates chained descriptors which can be
1094 * used to link buffers together for a sort of
1095 * scatter-gather operation.
1096 */
1097 if (sc->rx.frag) {
1098 /* too many fragments - cannot handle frame */
1099 dev_kfree_skb_any(sc->rx.frag);
1100 dev_kfree_skb_any(skb);
Ben Greear15072182012-04-03 09:18:59 -07001101 RX_STAT_INC(rx_too_many_frags_err);
Felix Fietkau0d955212011-01-26 18:23:27 +01001102 skb = NULL;
1103 }
1104 sc->rx.frag = skb;
1105 goto requeue;
1106 }
1107
1108 if (sc->rx.frag) {
1109 int space = skb->len - skb_tailroom(hdr_skb);
1110
Felix Fietkau0d955212011-01-26 18:23:27 +01001111 if (pskb_expand_head(hdr_skb, 0, space, GFP_ATOMIC) < 0) {
1112 dev_kfree_skb(skb);
Ben Greear15072182012-04-03 09:18:59 -07001113 RX_STAT_INC(rx_oom_err);
Felix Fietkau0d955212011-01-26 18:23:27 +01001114 goto requeue_drop_frag;
1115 }
1116
Eric Dumazetb5447ff2012-03-15 13:43:29 -07001117 sc->rx.frag = NULL;
1118
Felix Fietkau0d955212011-01-26 18:23:27 +01001119 skb_copy_from_linear_data(skb, skb_put(hdr_skb, skb->len),
1120 skb->len);
1121 dev_kfree_skb_any(skb);
1122 skb = hdr_skb;
1123 }
1124
Felix Fietkau66760ea2011-07-13 23:35:05 +08001125 if (rxs->flag & RX_FLAG_MMIC_STRIPPED)
1126 skb_trim(skb, skb->len - 8);
1127
Luis R. Rodriguez8ab2cd02010-09-16 15:12:26 -04001128 spin_lock_irqsave(&sc->sc_pm_lock, flags);
Mohammed Shafi Shajakhanaaef24b2010-12-07 20:40:58 +05301129 if ((sc->ps_flags & (PS_WAIT_FOR_BEACON |
Rajkumar Manoharanf73c6042011-09-26 22:16:56 +05301130 PS_WAIT_FOR_CAB |
1131 PS_WAIT_FOR_PSPOLL_DATA)) ||
1132 ath9k_check_auto_sleep(sc))
1133 ath_rx_ps(sc, skb, rs.is_mybeacon);
Luis R. Rodriguez8ab2cd02010-09-16 15:12:26 -04001134 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
Jouni Malinencc659652009-05-14 21:28:48 +03001135
Sujith Manoharanc3124df2013-08-14 21:15:56 +05301136 ath9k_antenna_check(sc, &rs);
Christian Lamparter21fbbca2013-01-30 23:37:41 +01001137 ath9k_apply_ampdu_details(sc, &rs, rxs);
Sujith Manoharan350e2dc2014-01-13 07:29:30 +05301138 ath_debug_rate_stats(sc, &rs, skb);
Christian Lamparter21fbbca2013-01-30 23:37:41 +01001139
Lorenzo Bianconi982e0392014-09-16 02:13:12 +02001140 hdr = (struct ieee80211_hdr *)skb->data;
1141 if (ieee80211_is_ack(hdr->frame_control))
1142 ath_dynack_sample_ack_ts(sc->sc_ah, skb, rs.rs_tstamp);
1143
Felix Fietkau7545daf2011-01-24 19:23:16 +01001144 ieee80211_rx(hw, skb);
Jouni Malinencc659652009-05-14 21:28:48 +03001145
Felix Fietkau0d955212011-01-26 18:23:27 +01001146requeue_drop_frag:
1147 if (sc->rx.frag) {
1148 dev_kfree_skb_any(sc->rx.frag);
1149 sc->rx.frag = NULL;
1150 }
Luis R. Rodriguezcb71d9b2008-11-21 17:41:33 -08001151requeue:
Felix Fietkaua3dc48e2013-01-09 16:16:52 +01001152 list_add_tail(&bf->list, &sc->rx.rxbuf);
Felix Fietkaua3dc48e2013-01-09 16:16:52 +01001153
Felix Fietkau7dd74f52014-05-23 19:21:34 +02001154 if (!edma) {
1155 ath_rx_buf_relink(sc, bf, flush);
Tim Harvey3a758132014-04-21 16:14:56 -07001156 if (!flush)
1157 ath9k_hw_rxena(ah);
Felix Fietkau7dd74f52014-05-23 19:21:34 +02001158 } else if (!flush) {
1159 ath_rx_edma_buf_link(sc, qtype);
Felix Fietkaub5c804752010-04-15 17:38:48 -04001160 }
Tim Harveyc82552c2014-04-21 16:14:57 -07001161
1162 if (!budget--)
1163 break;
Sujithbe0418a2008-11-18 09:05:55 +05301164 } while (1);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001165
Rajkumar Manoharan29ab0b32011-08-13 10:28:10 +05301166 if (!(ah->imask & ATH9K_INT_RXEOL)) {
1167 ah->imask |= (ATH9K_INT_RXEOL | ATH9K_INT_RXORN);
Felix Fietkau72d874c2011-10-08 20:06:19 +02001168 ath9k_hw_set_interrupts(ah);
Rajkumar Manoharan29ab0b32011-08-13 10:28:10 +05301169 }
1170
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001171 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001172}