]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/net/wireless/ath/ath9k/recv.c
ath9k: fix rx flush handling
[karo-tx-linux.git] / drivers / net / wireless / ath / ath9k / recv.c
1 /*
2  * Copyright (c) 2008-2011 Atheros Communications Inc.
3  *
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
17 #include <linux/dma-mapping.h>
18 #include "ath9k.h"
19 #include "ar9003_mac.h"
20
21 #define SKB_CB_ATHBUF(__skb)    (*((struct ath_buf **)__skb->cb))
22
23 static 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
29 /*
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.
36  */
37 static void ath_rx_buf_link(struct ath_softc *sc, struct ath_buf *bf)
38 {
39         struct ath_hw *ah = sc->sc_ah;
40         struct ath_common *common = ath9k_hw_common(ah);
41         struct ath_desc *ds;
42         struct sk_buff *skb;
43
44         ATH_RXBUF_RESET(bf);
45
46         ds = bf->bf_desc;
47         ds->ds_link = 0; /* link to null */
48         ds->ds_data = bf->bf_buf_addr;
49
50         /* virtual addr of the beginning of the buffer. */
51         skb = bf->bf_mpdu;
52         BUG_ON(skb == NULL);
53         ds->ds_vdata = skb->data;
54
55         /*
56          * setup rx descriptors. The rx_bufsize here tells the hardware
57          * how much data it can DMA to us and that we are prepared
58          * to process
59          */
60         ath9k_hw_setuprxdesc(ah, ds,
61                              common->rx_bufsize,
62                              0);
63
64         if (sc->rx.rxlink == NULL)
65                 ath9k_hw_putrxbuf(ah, bf->bf_daddr);
66         else
67                 *sc->rx.rxlink = bf->bf_daddr;
68
69         sc->rx.rxlink = &ds->ds_link;
70 }
71
72 static void ath_setdefantenna(struct ath_softc *sc, u32 antenna)
73 {
74         /* XXX block beacon interrupts */
75         ath9k_hw_setantenna(sc->sc_ah, antenna);
76         sc->rx.defant = antenna;
77         sc->rx.rxotherant = 0;
78 }
79
80 static void ath_opmode_init(struct ath_softc *sc)
81 {
82         struct ath_hw *ah = sc->sc_ah;
83         struct ath_common *common = ath9k_hw_common(ah);
84
85         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 */
92         ath_hw_setbssidmask(common);
93
94         /* configure operational mode */
95         ath9k_hw_setopmode(ah);
96
97         /* calculate and install multicast filter */
98         mfilt[0] = mfilt[1] = ~0;
99         ath9k_hw_setmcastfilter(ah, mfilt[0], mfilt[1]);
100 }
101
102 static 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
131 static void ath_rx_addbuffer_edma(struct ath_softc *sc,
132                                   enum ath9k_rx_qtype qtype, int size)
133 {
134         struct ath_common *common = ath9k_hw_common(sc->sc_ah);
135         struct ath_buf *bf, *tbf;
136
137         if (list_empty(&sc->rx.rxbuf)) {
138                 ath_dbg(common, QUEUE, "No free rx buf available\n");
139                 return;
140         }
141
142         list_for_each_entry_safe(bf, tbf, &sc->rx.rxbuf, list)
143                 if (!ath_rx_edma_buf_link(sc, qtype))
144                         break;
145
146 }
147
148 static 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
164 static void ath_rx_edma_cleanup(struct ath_softc *sc)
165 {
166         struct ath_hw *ah = sc->sc_ah;
167         struct ath_common *common = ath9k_hw_common(ah);
168         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) {
174                 if (bf->bf_mpdu) {
175                         dma_unmap_single(sc->dev, bf->bf_buf_addr,
176                                         common->rx_bufsize,
177                                         DMA_BIDIRECTIONAL);
178                         dev_kfree_skb_any(bf->bf_mpdu);
179                         bf->bf_buf_addr = 0;
180                         bf->bf_mpdu = NULL;
181                 }
182         }
183
184         INIT_LIST_HEAD(&sc->rx.rxbuf);
185
186         kfree(sc->rx.rx_bufptr);
187         sc->rx.rx_bufptr = NULL;
188 }
189
190 static void ath_rx_edma_init_queue(struct ath_rx_edma *rx_edma, int size)
191 {
192         skb_queue_head_init(&rx_edma->rx_fifo);
193         rx_edma->rx_fifo_hwsize = size;
194 }
195
196 static 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
205         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;
238                                 bf->bf_buf_addr = 0;
239                                 ath_err(common,
240                                         "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
250 rx_init_fail:
251         ath_rx_edma_cleanup(sc);
252         return error;
253 }
254
255 static 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
267         ath_opmode_init(sc);
268
269         ath9k_hw_startpcureceive(sc->sc_ah, !!(sc->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL));
270
271         spin_unlock_bh(&sc->rx.rxbuflock);
272 }
273
274 static void ath_edma_stop_recv(struct ath_softc *sc)
275 {
276         ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_HP);
277         ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_LP);
278 }
279
280 int ath_rx_init(struct ath_softc *sc, int nbufs)
281 {
282         struct ath_common *common = ath9k_hw_common(sc->sc_ah);
283         struct sk_buff *skb;
284         struct ath_buf *bf;
285         int error = 0;
286
287         spin_lock_init(&sc->sc_pcu_lock);
288         spin_lock_init(&sc->rx.rxbuflock);
289
290         common->rx_bufsize = IEEE80211_MAX_MPDU_LEN / 2 +
291                              sc->sc_ah->caps.rx_status_len;
292
293         if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
294                 return ath_rx_edma_init(sc, nbufs);
295         } else {
296                 ath_dbg(common, CONFIG, "cachelsz %u rxbufsize %u\n",
297                         common->cachelsz, common->rx_bufsize);
298
299                 /* Initialize rx descriptors */
300
301                 error = ath_descdma_setup(sc, &sc->rx.rxdma, &sc->rx.rxbuf,
302                                 "rx", nbufs, 1, 0);
303                 if (error != 0) {
304                         ath_err(common,
305                                 "failed to allocate rx descriptors: %d\n",
306                                 error);
307                         goto err;
308                 }
309
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;
326                                 bf->bf_buf_addr = 0;
327                                 ath_err(common,
328                                         "dma_mapping_error() on RX init\n");
329                                 error = -ENOMEM;
330                                 goto err;
331                         }
332                 }
333                 sc->rx.rxlink = NULL;
334         }
335
336 err:
337         if (error)
338                 ath_rx_cleanup(sc);
339
340         return error;
341 }
342
343 void ath_rx_cleanup(struct ath_softc *sc)
344 {
345         struct ath_hw *ah = sc->sc_ah;
346         struct ath_common *common = ath9k_hw_common(ah);
347         struct sk_buff *skb;
348         struct ath_buf *bf;
349
350         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);
361                                 bf->bf_buf_addr = 0;
362                                 bf->bf_mpdu = NULL;
363                         }
364                 }
365
366                 if (sc->rx.rxdma.dd_desc_len != 0)
367                         ath_descdma_cleanup(sc, &sc->rx.rxdma, &sc->rx.rxbuf);
368         }
369 }
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
390 u32 ath_calcrxfilter(struct ath_softc *sc)
391 {
392         u32 rfilt;
393
394         rfilt = ATH9K_RX_FILTER_UCAST | ATH9K_RX_FILTER_BCAST
395                 | ATH9K_RX_FILTER_MCAST;
396
397         if (sc->rx.rxfilter & FIF_PROBE_REQ)
398                 rfilt |= ATH9K_RX_FILTER_PROBEREQ;
399
400         /*
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          */
405         if (sc->sc_ah->is_monitoring)
406                 rfilt |= ATH9K_RX_FILTER_PROM;
407
408         if (sc->rx.rxfilter & FIF_CONTROL)
409                 rfilt |= ATH9K_RX_FILTER_CONTROL;
410
411         if ((sc->sc_ah->opmode == NL80211_IFTYPE_STATION) &&
412             (sc->nvifs <= 1) &&
413             !(sc->rx.rxfilter & FIF_BCN_PRBRESP_PROMISC))
414                 rfilt |= ATH9K_RX_FILTER_MYBEACON;
415         else
416                 rfilt |= ATH9K_RX_FILTER_BEACON;
417
418         if ((sc->sc_ah->opmode == NL80211_IFTYPE_AP) ||
419             (sc->rx.rxfilter & FIF_PSPOLL))
420                 rfilt |= ATH9K_RX_FILTER_PSPOLL;
421
422         if (conf_is_ht(&sc->hw->conf))
423                 rfilt |= ATH9K_RX_FILTER_COMP_BAR;
424
425         if (sc->nvifs > 1 || (sc->rx.rxfilter & FIF_OTHER_BSS)) {
426                 /* This is needed for older chips */
427                 if (sc->sc_ah->hw_version.macVersion <= AR_SREV_VERSION_9160)
428                         rfilt |= ATH9K_RX_FILTER_PROM;
429                 rfilt |= ATH9K_RX_FILTER_MCAST_BCAST_ALL;
430         }
431
432         if (AR_SREV_9550(sc->sc_ah))
433                 rfilt |= ATH9K_RX_FILTER_4ADDRESS;
434
435         return rfilt;
436
437 }
438
439 int ath_startrecv(struct ath_softc *sc)
440 {
441         struct ath_hw *ah = sc->sc_ah;
442         struct ath_buf *bf, *tbf;
443
444         if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
445                 ath_edma_start_recv(sc);
446                 return 0;
447         }
448
449         spin_lock_bh(&sc->rx.rxbuflock);
450         if (list_empty(&sc->rx.rxbuf))
451                 goto start_recv;
452
453         sc->rx.rxlink = NULL;
454         list_for_each_entry_safe(bf, tbf, &sc->rx.rxbuf, list) {
455                 ath_rx_buf_link(sc, bf);
456         }
457
458         /* We could have deleted elements so the list may be empty now */
459         if (list_empty(&sc->rx.rxbuf))
460                 goto start_recv;
461
462         bf = list_first_entry(&sc->rx.rxbuf, struct ath_buf, list);
463         ath9k_hw_putrxbuf(ah, bf->bf_daddr);
464         ath9k_hw_rxena(ah);
465
466 start_recv:
467         ath_opmode_init(sc);
468         ath9k_hw_startpcureceive(ah, !!(sc->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL));
469
470         spin_unlock_bh(&sc->rx.rxbuflock);
471
472         return 0;
473 }
474
475 static 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
482 bool ath_stoprecv(struct ath_softc *sc)
483 {
484         struct ath_hw *ah = sc->sc_ah;
485         bool stopped, reset = false;
486
487         spin_lock_bh(&sc->rx.rxbuflock);
488         ath9k_hw_abortpcurecv(ah);
489         ath9k_hw_setrxfilter(ah, 0);
490         stopped = ath9k_hw_stopdmarecv(ah, &reset);
491
492         ath_flushrecv(sc);
493
494         if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
495                 ath_edma_stop_recv(sc);
496         else
497                 sc->rx.rxlink = NULL;
498         spin_unlock_bh(&sc->rx.rxbuflock);
499
500         if (!(ah->ah_flags & AH_UNPLUGGED) &&
501             unlikely(!stopped)) {
502                 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         }
507         return stopped && !reset;
508 }
509
510 static 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
542 static void ath_rx_ps_beacon(struct ath_softc *sc, struct sk_buff *skb)
543 {
544         struct ath_common *common = ath9k_hw_common(sc->sc_ah);
545
546         if (skb->len < 24 + 8 + 2 + 2)
547                 return;
548
549         sc->ps_flags &= ~PS_WAIT_FOR_BEACON;
550
551         if (sc->ps_flags & PS_BEACON_SYNC) {
552                 sc->ps_flags &= ~PS_BEACON_SYNC;
553                 ath_dbg(common, PS,
554                         "Reconfigure Beacon timers based on timestamp from the AP\n");
555                 ath9k_set_beacon(sc);
556         }
557
558         if (ath_beacon_dtim_pending_cab(skb)) {
559                 /*
560                  * Remain awake waiting for buffered broadcast/multicast
561                  * 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.
565                  */
566                 ath_dbg(common, PS,
567                         "Received DTIM beacon indicating buffered broadcast/multicast frame(s)\n");
568                 sc->ps_flags |= PS_WAIT_FOR_CAB | PS_WAIT_FOR_BEACON;
569                 return;
570         }
571
572         if (sc->ps_flags & PS_WAIT_FOR_CAB) {
573                 /*
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                  */
578                 sc->ps_flags &= ~PS_WAIT_FOR_CAB;
579                 ath_dbg(common, PS, "PS wait for CAB frames timed out\n");
580         }
581 }
582
583 static void ath_rx_ps(struct ath_softc *sc, struct sk_buff *skb, bool mybeacon)
584 {
585         struct ieee80211_hdr *hdr;
586         struct ath_common *common = ath9k_hw_common(sc->sc_ah);
587
588         hdr = (struct ieee80211_hdr *)skb->data;
589
590         /* Process Beacon and CAB receive in PS state */
591         if (((sc->ps_flags & PS_WAIT_FOR_BEACON) || ath9k_check_auto_sleep(sc))
592             && mybeacon) {
593                 ath_rx_ps_beacon(sc, skb);
594         } 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)) {
599                 /*
600                  * No more broadcast/multicast frames to be received at this
601                  * point.
602                  */
603                 sc->ps_flags &= ~(PS_WAIT_FOR_CAB | PS_WAIT_FOR_BEACON);
604                 ath_dbg(common, PS,
605                         "All PS CAB frames received, back to sleep\n");
606         } else if ((sc->ps_flags & PS_WAIT_FOR_PSPOLL_DATA) &&
607                    !is_multicast_ether_addr(hdr->addr1) &&
608                    !ieee80211_has_morefrags(hdr->frame_control)) {
609                 sc->ps_flags &= ~PS_WAIT_FOR_PSPOLL_DATA;
610                 ath_dbg(common, PS,
611                         "Going back to sleep after having received PS-Poll data (0x%lx)\n",
612                         sc->ps_flags & (PS_WAIT_FOR_BEACON |
613                                         PS_WAIT_FOR_CAB |
614                                         PS_WAIT_FOR_PSPOLL_DATA |
615                                         PS_WAIT_FOR_TX_ACK));
616         }
617 }
618
619 static bool ath_edma_get_buffers(struct ath_softc *sc,
620                                  enum ath9k_rx_qtype qtype,
621                                  struct ath_rx_status *rs,
622                                  struct ath_buf **dest)
623 {
624         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;
628         struct ath_buf *bf;
629         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
638         dma_sync_single_for_cpu(sc->dev, bf->bf_buf_addr,
639                                 common->rx_bufsize, DMA_FROM_DEVICE);
640
641         ret = ath9k_hw_process_rxdesc_edma(ah, rs, skb->data);
642         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);
646                 return false;
647         }
648
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);
654
655                 skb = skb_peek(&rx_edma->rx_fifo);
656                 if (skb) {
657                         bf = SKB_CB_ATHBUF(skb);
658                         BUG_ON(!bf);
659
660                         __skb_unlink(skb, &rx_edma->rx_fifo);
661                         list_add_tail(&bf->list, &sc->rx.rxbuf);
662                         ath_rx_edma_buf_link(sc, qtype);
663                 }
664
665                 bf = NULL;
666         }
667
668         *dest = bf;
669         return true;
670 }
671
672 static 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 {
676         struct ath_buf *bf = NULL;
677
678         while (ath_edma_get_buffers(sc, qtype, rs, &bf)) {
679                 if (!bf)
680                         continue;
681
682                 return bf;
683         }
684         return NULL;
685 }
686
687 static 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);
692         struct ath_desc *ds;
693         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          */
715         ret = ath9k_hw_rxprocdesc(ah, ds, rs);
716         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;
741                 ret = ath9k_hw_rxprocdesc(ah, tds, &trs);
742                 if (ret == -EINPROGRESS)
743                         return NULL;
744         }
745
746         list_del(&bf->list);
747         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          */
755         dma_sync_single_for_cpu(sc->dev, bf->bf_buf_addr,
756                         common->rx_bufsize,
757                         DMA_FROM_DEVICE);
758
759         return bf;
760 }
761
762 /* Assumes you've already done the endian to CPU conversion */
763 static bool ath9k_rx_accept(struct ath_common *common,
764                             struct ieee80211_hdr *hdr,
765                             struct ieee80211_rx_status *rxs,
766                             struct ath_rx_status *rx_stats,
767                             bool *decrypt_error)
768 {
769         struct ath_softc *sc = (struct ath_softc *) common->priv;
770         bool is_mc, is_valid_tkip, strip_mic, mic_error;
771         struct ath_hw *ah = common->ah;
772         __le16 fc;
773         u8 rx_status_len = ah->caps.rx_status_len;
774
775         fc = hdr->frame_control;
776
777         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);
780         strip_mic = is_valid_tkip && ieee80211_is_data(fc) &&
781                 ieee80211_has_protected(fc) &&
782                 !(rx_stats->rs_status &
783                 (ATH9K_RXERR_DECRYPT | ATH9K_RXERR_CRC | ATH9K_RXERR_MIC |
784                  ATH9K_RXERR_KEYMISS));
785
786         /*
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          */
791         if (rx_stats->rs_keyix == ATH9K_RXKEYIX_INVALID ||
792             !test_bit(rx_stats->rs_keyix, common->ccmp_keymap))
793                 rx_stats->rs_status &= ~ATH9K_RXERR_KEYMISS;
794
795         if (!rx_stats->rs_datalen) {
796                 RX_STAT_INC(rx_len_err);
797                 return false;
798         }
799
800         /*
801          * rs_status follows rs_datalen so if rs_datalen is too large
802          * we can take a hint that hardware corrupted it, so ignore
803          * those frames.
804          */
805         if (rx_stats->rs_datalen > (common->rx_bufsize - rx_status_len)) {
806                 RX_STAT_INC(rx_len_err);
807                 return false;
808         }
809
810         /* Only use error bits from the last fragment */
811         if (rx_stats->rs_more)
812                 return true;
813
814         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
819         /*
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) {
826                 u8 status_mask;
827
828                 if (rx_stats->rs_status & ATH9K_RXERR_CRC) {
829                         rxs->flag |= RX_FLAG_FAILED_FCS_CRC;
830                         mic_error = false;
831                 }
832                 if (rx_stats->rs_status & ATH9K_RXERR_PHY)
833                         return false;
834
835                 if ((rx_stats->rs_status & ATH9K_RXERR_DECRYPT) ||
836                     (!is_mc && (rx_stats->rs_status & ATH9K_RXERR_KEYMISS))) {
837                         *decrypt_error = true;
838                         mic_error = false;
839                 }
840
841                 /*
842                  * Reject error frames with the exception of
843                  * decryption and MIC failures. For monitor mode,
844                  * we also ignore the CRC error.
845                  */
846                 status_mask = ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC |
847                               ATH9K_RXERR_KEYMISS;
848
849                 if (ah->is_monitoring && (sc->rx.rxfilter & FIF_FCSFAIL))
850                         status_mask |= ATH9K_RXERR_CRC;
851
852                 if (rx_stats->rs_status & ~status_mask)
853                         return false;
854         }
855
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
867         return true;
868 }
869
870 static int ath9k_process_rate(struct ath_common *common,
871                               struct ieee80211_hw *hw,
872                               struct ath_rx_status *rx_stats,
873                               struct ieee80211_rx_status *rxs)
874 {
875         struct ieee80211_supported_band *sband;
876         enum ieee80211_band band;
877         unsigned int i = 0;
878         struct ath_softc __maybe_unused *sc = common->priv;
879
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          */
910         ath_dbg(common, ANY,
911                 "unsupported hw bitrate detected 0x%02x using 1 Mbit\n",
912                 rx_stats->rs_rate);
913         RX_STAT_INC(rx_rate_err);
914         return -EINVAL;
915 }
916
917 static void ath9k_process_rssi(struct ath_common *common,
918                                struct ieee80211_hw *hw,
919                                struct ieee80211_hdr *hdr,
920                                struct ath_rx_status *rx_stats)
921 {
922         struct ath_softc *sc = hw->priv;
923         struct ath_hw *ah = common->ah;
924         int last_rssi;
925         int rssi = rx_stats->rs_rssi;
926
927         if (!rx_stats->is_mybeacon ||
928             ((ah->opmode != NL80211_IFTYPE_STATION) &&
929              (ah->opmode != NL80211_IFTYPE_ADHOC)))
930                 return;
931
932         if (rx_stats->rs_rssi != ATH9K_RSSI_BAD && !rx_stats->rs_moreaggr)
933                 ATH_RSSI_LPF(sc->last_rssi, rx_stats->rs_rssi);
934
935         last_rssi = sc->last_rssi;
936         if (likely(last_rssi != ATH_RSSI_DUMMY_MARKER))
937                 rssi = ATH_EP_RND(last_rssi, ATH_RSSI_EP_MULTIPLIER);
938         if (rssi < 0)
939                 rssi = 0;
940
941         /* Update Beacon RSSI, this is used by ANI. */
942         ah->stats.avgbrssi = rssi;
943 }
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  */
950 static int ath9k_rx_skb_preprocess(struct ath_common *common,
951                                    struct ieee80211_hw *hw,
952                                    struct ieee80211_hdr *hdr,
953                                    struct ath_rx_status *rx_stats,
954                                    struct ieee80211_rx_status *rx_status,
955                                    bool *decrypt_error)
956 {
957         struct ath_hw *ah = common->ah;
958
959         /*
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          */
963         if (!ath9k_rx_accept(common, hdr, rx_status, rx_stats, decrypt_error))
964                 return -EINVAL;
965
966         /* Only use status info from the last fragment */
967         if (rx_stats->rs_more)
968                 return 0;
969
970         ath9k_process_rssi(common, hw, hdr, rx_stats);
971
972         if (ath9k_process_rate(common, hw, rx_stats, rx_status))
973                 return -EINVAL;
974
975         rx_status->band = hw->conf.channel->band;
976         rx_status->freq = hw->conf.channel->center_freq;
977         rx_status->signal = ah->noise + rx_stats->rs_rssi;
978         rx_status->antenna = rx_stats->rs_antenna;
979         rx_status->flag |= RX_FLAG_MACTIME_MPDU;
980         if (rx_stats->rs_moreaggr)
981                 rx_status->flag |= RX_FLAG_NO_SIGNAL_VAL;
982
983         return 0;
984 }
985
986 static 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 }
1036
1037 int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp)
1038 {
1039         struct ath_buf *bf;
1040         struct sk_buff *skb = NULL, *requeue_skb, *hdr_skb;
1041         struct ieee80211_rx_status *rxs;
1042         struct ath_hw *ah = sc->sc_ah;
1043         struct ath_common *common = ath9k_hw_common(ah);
1044         struct ieee80211_hw *hw = sc->hw;
1045         struct ieee80211_hdr *hdr;
1046         int retval;
1047         struct ath_rx_status rs;
1048         enum ath9k_rx_qtype qtype;
1049         bool edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA);
1050         int dma_type;
1051         u8 rx_status_len = ah->caps.rx_status_len;
1052         u64 tsf = 0;
1053         u32 tsf_lower = 0;
1054         unsigned long flags;
1055
1056         if (edma)
1057                 dma_type = DMA_BIDIRECTIONAL;
1058         else
1059                 dma_type = DMA_FROM_DEVICE;
1060
1061         qtype = hp ? ATH9K_RX_QUEUE_HP : ATH9K_RX_QUEUE_LP;
1062         spin_lock_bh(&sc->rx.rxbuflock);
1063
1064         tsf = ath9k_hw_gettsf64(ah);
1065         tsf_lower = tsf & 0xffffffff;
1066
1067         do {
1068                 bool decrypt_error = false;
1069
1070                 memset(&rs, 0, sizeof(rs));
1071                 if (edma)
1072                         bf = ath_edma_get_next_rx_buf(sc, &rs, qtype);
1073                 else
1074                         bf = ath_get_next_rx_buf(sc, &rs);
1075
1076                 if (!bf)
1077                         break;
1078
1079                 skb = bf->bf_mpdu;
1080                 if (!skb)
1081                         continue;
1082
1083                 /*
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);
1094                 if (ieee80211_is_beacon(hdr->frame_control)) {
1095                         RX_STAT_INC(rx_beacons);
1096                         if (!is_zero_ether_addr(common->curbssid) &&
1097                             ether_addr_equal(hdr->addr3, common->curbssid))
1098                                 rs.is_mybeacon = true;
1099                         else
1100                                 rs.is_mybeacon = false;
1101                 }
1102                 else
1103                         rs.is_mybeacon = false;
1104
1105                 sc->rx.num_pkts++;
1106                 ath_debug_stat_rx(sc, &rs);
1107
1108                 memset(rxs, 0, sizeof(struct ieee80211_rx_status));
1109
1110                 rxs->mactime = (tsf & ~0xffffffffULL) | rs.rs_tstamp;
1111                 if (rs.rs_tstamp > tsf_lower &&
1112                     unlikely(rs.rs_tstamp - tsf_lower > 0x10000000))
1113                         rxs->mactime -= 0x100000000ULL;
1114
1115                 if (rs.rs_tstamp < tsf_lower &&
1116                     unlikely(tsf_lower - rs.rs_tstamp > 0x10000000))
1117                         rxs->mactime += 0x100000000ULL;
1118
1119                 retval = ath9k_rx_skb_preprocess(common, hw, hdr, &rs,
1120                                                  rxs, &decrypt_error);
1121                 if (retval)
1122                         goto requeue_drop_frag;
1123
1124                 if (rs.is_mybeacon) {
1125                         sc->hw_busy_count = 0;
1126                         ath_start_rx_poll(sc, 3);
1127                 }
1128                 /* Ensure we always have an skb to requeue once we are done
1129                  * processing the current buffer's skb */
1130                 requeue_skb = ath_rxbuf_alloc(common, common->rx_bufsize, GFP_ATOMIC);
1131
1132                 /* If there is no memory we ignore the current RX'd frame,
1133                  * tell hardware it can give us a new frame using the old
1134                  * skb and put it at the tail of the sc->rx.rxbuf list for
1135                  * processing. */
1136                 if (!requeue_skb) {
1137                         RX_STAT_INC(rx_oom_err);
1138                         goto requeue_drop_frag;
1139                 }
1140
1141                 /* Unmap the frame */
1142                 dma_unmap_single(sc->dev, bf->bf_buf_addr,
1143                                  common->rx_bufsize,
1144                                  dma_type);
1145
1146                 skb_put(skb, rs.rs_datalen + ah->caps.rx_status_len);
1147                 if (ah->caps.rx_status_len)
1148                         skb_pull(skb, ah->caps.rx_status_len);
1149
1150                 if (!rs.rs_more)
1151                         ath9k_rx_skb_postprocess(common, hdr_skb, &rs,
1152                                                  rxs, decrypt_error);
1153
1154                 /* We will now give hardware our shiny new allocated skb */
1155                 bf->bf_mpdu = requeue_skb;
1156                 bf->bf_buf_addr = dma_map_single(sc->dev, requeue_skb->data,
1157                                                  common->rx_bufsize,
1158                                                  dma_type);
1159                 if (unlikely(dma_mapping_error(sc->dev,
1160                           bf->bf_buf_addr))) {
1161                         dev_kfree_skb_any(requeue_skb);
1162                         bf->bf_mpdu = NULL;
1163                         bf->bf_buf_addr = 0;
1164                         ath_err(common, "dma_mapping_error() on RX\n");
1165                         ieee80211_rx(hw, skb);
1166                         break;
1167                 }
1168
1169                 if (rs.rs_more) {
1170                         RX_STAT_INC(rx_frags);
1171                         /*
1172                          * rs_more indicates chained descriptors which can be
1173                          * used to link buffers together for a sort of
1174                          * scatter-gather operation.
1175                          */
1176                         if (sc->rx.frag) {
1177                                 /* too many fragments - cannot handle frame */
1178                                 dev_kfree_skb_any(sc->rx.frag);
1179                                 dev_kfree_skb_any(skb);
1180                                 RX_STAT_INC(rx_too_many_frags_err);
1181                                 skb = NULL;
1182                         }
1183                         sc->rx.frag = skb;
1184                         goto requeue;
1185                 }
1186
1187                 if (sc->rx.frag) {
1188                         int space = skb->len - skb_tailroom(hdr_skb);
1189
1190                         if (pskb_expand_head(hdr_skb, 0, space, GFP_ATOMIC) < 0) {
1191                                 dev_kfree_skb(skb);
1192                                 RX_STAT_INC(rx_oom_err);
1193                                 goto requeue_drop_frag;
1194                         }
1195
1196                         sc->rx.frag = NULL;
1197
1198                         skb_copy_from_linear_data(skb, skb_put(hdr_skb, skb->len),
1199                                                   skb->len);
1200                         dev_kfree_skb_any(skb);
1201                         skb = hdr_skb;
1202                 }
1203
1204
1205                 if (ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB) {
1206
1207                         /*
1208                          * change the default rx antenna if rx diversity
1209                          * chooses the other antenna 3 times in a row.
1210                          */
1211                         if (sc->rx.defant != rs.rs_antenna) {
1212                                 if (++sc->rx.rxotherant >= 3)
1213                                         ath_setdefantenna(sc, rs.rs_antenna);
1214                         } else {
1215                                 sc->rx.rxotherant = 0;
1216                         }
1217
1218                 }
1219
1220                 if (rxs->flag & RX_FLAG_MMIC_STRIPPED)
1221                         skb_trim(skb, skb->len - 8);
1222
1223                 spin_lock_irqsave(&sc->sc_pm_lock, flags);
1224                 if ((sc->ps_flags & (PS_WAIT_FOR_BEACON |
1225                                      PS_WAIT_FOR_CAB |
1226                                      PS_WAIT_FOR_PSPOLL_DATA)) ||
1227                     ath9k_check_auto_sleep(sc))
1228                         ath_rx_ps(sc, skb, rs.is_mybeacon);
1229                 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
1230
1231                 if ((ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB) && sc->ant_rx == 3)
1232                         ath_ant_comb_scan(sc, &rs);
1233
1234                 ieee80211_rx(hw, skb);
1235
1236 requeue_drop_frag:
1237                 if (sc->rx.frag) {
1238                         dev_kfree_skb_any(sc->rx.frag);
1239                         sc->rx.frag = NULL;
1240                 }
1241 requeue:
1242                 list_add_tail(&bf->list, &sc->rx.rxbuf);
1243                 if (flush)
1244                         continue;
1245
1246                 if (edma) {
1247                         ath_rx_edma_buf_link(sc, qtype);
1248                 } else {
1249                         ath_rx_buf_link(sc, bf);
1250                         ath9k_hw_rxena(ah);
1251                 }
1252         } while (1);
1253
1254         spin_unlock_bh(&sc->rx.rxbuflock);
1255
1256         if (!(ah->imask & ATH9K_INT_RXEOL)) {
1257                 ah->imask |= (ATH9K_INT_RXEOL | ATH9K_INT_RXORN);
1258                 ath9k_hw_set_interrupts(ah);
1259         }
1260
1261         return 0;
1262 }