Merge remote-tracking branch 'regmap/topic/flat' into regmap-next
[cascardo/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         ath9k_hw_rxena(sc->sc_ah);
258
259         ath_rx_addbuffer_edma(sc, ATH9K_RX_QUEUE_HP,
260                               sc->rx.rx_edma[ATH9K_RX_QUEUE_HP].rx_fifo_hwsize);
261
262         ath_rx_addbuffer_edma(sc, ATH9K_RX_QUEUE_LP,
263                               sc->rx.rx_edma[ATH9K_RX_QUEUE_LP].rx_fifo_hwsize);
264
265         ath_opmode_init(sc);
266
267         ath9k_hw_startpcureceive(sc->sc_ah, !!(sc->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL));
268 }
269
270 static void ath_edma_stop_recv(struct ath_softc *sc)
271 {
272         ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_HP);
273         ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_LP);
274 }
275
276 int ath_rx_init(struct ath_softc *sc, int nbufs)
277 {
278         struct ath_common *common = ath9k_hw_common(sc->sc_ah);
279         struct sk_buff *skb;
280         struct ath_buf *bf;
281         int error = 0;
282
283         spin_lock_init(&sc->sc_pcu_lock);
284
285         common->rx_bufsize = IEEE80211_MAX_MPDU_LEN / 2 +
286                              sc->sc_ah->caps.rx_status_len;
287
288         if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
289                 return ath_rx_edma_init(sc, nbufs);
290         } else {
291                 ath_dbg(common, CONFIG, "cachelsz %u rxbufsize %u\n",
292                         common->cachelsz, common->rx_bufsize);
293
294                 /* Initialize rx descriptors */
295
296                 error = ath_descdma_setup(sc, &sc->rx.rxdma, &sc->rx.rxbuf,
297                                 "rx", nbufs, 1, 0);
298                 if (error != 0) {
299                         ath_err(common,
300                                 "failed to allocate rx descriptors: %d\n",
301                                 error);
302                         goto err;
303                 }
304
305                 list_for_each_entry(bf, &sc->rx.rxbuf, list) {
306                         skb = ath_rxbuf_alloc(common, common->rx_bufsize,
307                                               GFP_KERNEL);
308                         if (skb == NULL) {
309                                 error = -ENOMEM;
310                                 goto err;
311                         }
312
313                         bf->bf_mpdu = skb;
314                         bf->bf_buf_addr = dma_map_single(sc->dev, skb->data,
315                                         common->rx_bufsize,
316                                         DMA_FROM_DEVICE);
317                         if (unlikely(dma_mapping_error(sc->dev,
318                                                         bf->bf_buf_addr))) {
319                                 dev_kfree_skb_any(skb);
320                                 bf->bf_mpdu = NULL;
321                                 bf->bf_buf_addr = 0;
322                                 ath_err(common,
323                                         "dma_mapping_error() on RX init\n");
324                                 error = -ENOMEM;
325                                 goto err;
326                         }
327                 }
328                 sc->rx.rxlink = NULL;
329         }
330
331 err:
332         if (error)
333                 ath_rx_cleanup(sc);
334
335         return error;
336 }
337
338 void ath_rx_cleanup(struct ath_softc *sc)
339 {
340         struct ath_hw *ah = sc->sc_ah;
341         struct ath_common *common = ath9k_hw_common(ah);
342         struct sk_buff *skb;
343         struct ath_buf *bf;
344
345         if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
346                 ath_rx_edma_cleanup(sc);
347                 return;
348         } else {
349                 list_for_each_entry(bf, &sc->rx.rxbuf, list) {
350                         skb = bf->bf_mpdu;
351                         if (skb) {
352                                 dma_unmap_single(sc->dev, bf->bf_buf_addr,
353                                                 common->rx_bufsize,
354                                                 DMA_FROM_DEVICE);
355                                 dev_kfree_skb(skb);
356                                 bf->bf_buf_addr = 0;
357                                 bf->bf_mpdu = NULL;
358                         }
359                 }
360
361                 if (sc->rx.rxdma.dd_desc_len != 0)
362                         ath_descdma_cleanup(sc, &sc->rx.rxdma, &sc->rx.rxbuf);
363         }
364 }
365
366 /*
367  * Calculate the receive filter according to the
368  * operating mode and state:
369  *
370  * o always accept unicast, broadcast, and multicast traffic
371  * o maintain current state of phy error reception (the hal
372  *   may enable phy error frames for noise immunity work)
373  * o probe request frames are accepted only when operating in
374  *   hostap, adhoc, or monitor modes
375  * o enable promiscuous mode according to the interface state
376  * o accept beacons:
377  *   - when operating in adhoc mode so the 802.11 layer creates
378  *     node table entries for peers,
379  *   - when operating in station mode for collecting rssi data when
380  *     the station is otherwise quiet, or
381  *   - when operating as a repeater so we see repeater-sta beacons
382  *   - when scanning
383  */
384
385 u32 ath_calcrxfilter(struct ath_softc *sc)
386 {
387         u32 rfilt;
388
389         rfilt = ATH9K_RX_FILTER_UCAST | ATH9K_RX_FILTER_BCAST
390                 | ATH9K_RX_FILTER_MCAST;
391
392         if (sc->rx.rxfilter & FIF_PROBE_REQ)
393                 rfilt |= ATH9K_RX_FILTER_PROBEREQ;
394
395         /*
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          */
400         if (sc->sc_ah->is_monitoring)
401                 rfilt |= ATH9K_RX_FILTER_PROM;
402
403         if (sc->rx.rxfilter & FIF_CONTROL)
404                 rfilt |= ATH9K_RX_FILTER_CONTROL;
405
406         if ((sc->sc_ah->opmode == NL80211_IFTYPE_STATION) &&
407             (sc->nvifs <= 1) &&
408             !(sc->rx.rxfilter & FIF_BCN_PRBRESP_PROMISC))
409                 rfilt |= ATH9K_RX_FILTER_MYBEACON;
410         else
411                 rfilt |= ATH9K_RX_FILTER_BEACON;
412
413         if ((sc->sc_ah->opmode == NL80211_IFTYPE_AP) ||
414             (sc->rx.rxfilter & FIF_PSPOLL))
415                 rfilt |= ATH9K_RX_FILTER_PSPOLL;
416
417         if (conf_is_ht(&sc->hw->conf))
418                 rfilt |= ATH9K_RX_FILTER_COMP_BAR;
419
420         if (sc->nvifs > 1 || (sc->rx.rxfilter & FIF_OTHER_BSS)) {
421                 /* This is needed for older chips */
422                 if (sc->sc_ah->hw_version.macVersion <= AR_SREV_VERSION_9160)
423                         rfilt |= ATH9K_RX_FILTER_PROM;
424                 rfilt |= ATH9K_RX_FILTER_MCAST_BCAST_ALL;
425         }
426
427         if (AR_SREV_9550(sc->sc_ah))
428                 rfilt |= ATH9K_RX_FILTER_4ADDRESS;
429
430         return rfilt;
431
432 }
433
434 int ath_startrecv(struct ath_softc *sc)
435 {
436         struct ath_hw *ah = sc->sc_ah;
437         struct ath_buf *bf, *tbf;
438
439         if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
440                 ath_edma_start_recv(sc);
441                 return 0;
442         }
443
444         if (list_empty(&sc->rx.rxbuf))
445                 goto start_recv;
446
447         sc->rx.rxlink = NULL;
448         list_for_each_entry_safe(bf, tbf, &sc->rx.rxbuf, list) {
449                 ath_rx_buf_link(sc, bf);
450         }
451
452         /* We could have deleted elements so the list may be empty now */
453         if (list_empty(&sc->rx.rxbuf))
454                 goto start_recv;
455
456         bf = list_first_entry(&sc->rx.rxbuf, struct ath_buf, list);
457         ath9k_hw_putrxbuf(ah, bf->bf_daddr);
458         ath9k_hw_rxena(ah);
459
460 start_recv:
461         ath_opmode_init(sc);
462         ath9k_hw_startpcureceive(ah, !!(sc->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL));
463
464         return 0;
465 }
466
467 static void ath_flushrecv(struct ath_softc *sc)
468 {
469         if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
470                 ath_rx_tasklet(sc, 1, true);
471         ath_rx_tasklet(sc, 1, false);
472 }
473
474 bool ath_stoprecv(struct ath_softc *sc)
475 {
476         struct ath_hw *ah = sc->sc_ah;
477         bool stopped, reset = false;
478
479         ath9k_hw_abortpcurecv(ah);
480         ath9k_hw_setrxfilter(ah, 0);
481         stopped = ath9k_hw_stopdmarecv(ah, &reset);
482
483         ath_flushrecv(sc);
484
485         if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
486                 ath_edma_stop_recv(sc);
487         else
488                 sc->rx.rxlink = NULL;
489
490         if (!(ah->ah_flags & AH_UNPLUGGED) &&
491             unlikely(!stopped)) {
492                 ath_err(ath9k_hw_common(sc->sc_ah),
493                         "Could not stop RX, we could be "
494                         "confusing the DMA engine when we start RX up\n");
495                 ATH_DBG_WARN_ON_ONCE(!stopped);
496         }
497         return stopped && !reset;
498 }
499
500 static bool ath_beacon_dtim_pending_cab(struct sk_buff *skb)
501 {
502         /* Check whether the Beacon frame has DTIM indicating buffered bc/mc */
503         struct ieee80211_mgmt *mgmt;
504         u8 *pos, *end, id, elen;
505         struct ieee80211_tim_ie *tim;
506
507         mgmt = (struct ieee80211_mgmt *)skb->data;
508         pos = mgmt->u.beacon.variable;
509         end = skb->data + skb->len;
510
511         while (pos + 2 < end) {
512                 id = *pos++;
513                 elen = *pos++;
514                 if (pos + elen > end)
515                         break;
516
517                 if (id == WLAN_EID_TIM) {
518                         if (elen < sizeof(*tim))
519                                 break;
520                         tim = (struct ieee80211_tim_ie *) pos;
521                         if (tim->dtim_count != 0)
522                                 break;
523                         return tim->bitmap_ctrl & 0x01;
524                 }
525
526                 pos += elen;
527         }
528
529         return false;
530 }
531
532 static void ath_rx_ps_beacon(struct ath_softc *sc, struct sk_buff *skb)
533 {
534         struct ath_common *common = ath9k_hw_common(sc->sc_ah);
535
536         if (skb->len < 24 + 8 + 2 + 2)
537                 return;
538
539         sc->ps_flags &= ~PS_WAIT_FOR_BEACON;
540
541         if (sc->ps_flags & PS_BEACON_SYNC) {
542                 sc->ps_flags &= ~PS_BEACON_SYNC;
543                 ath_dbg(common, PS,
544                         "Reconfigure Beacon timers based on timestamp from the AP\n");
545                 ath9k_set_beacon(sc);
546         }
547
548         if (ath_beacon_dtim_pending_cab(skb)) {
549                 /*
550                  * Remain awake waiting for buffered broadcast/multicast
551                  * frames. If the last broadcast/multicast frame is not
552                  * received properly, the next beacon frame will work as
553                  * a backup trigger for returning into NETWORK SLEEP state,
554                  * so we are waiting for it as well.
555                  */
556                 ath_dbg(common, PS,
557                         "Received DTIM beacon indicating buffered broadcast/multicast frame(s)\n");
558                 sc->ps_flags |= PS_WAIT_FOR_CAB | PS_WAIT_FOR_BEACON;
559                 return;
560         }
561
562         if (sc->ps_flags & PS_WAIT_FOR_CAB) {
563                 /*
564                  * This can happen if a broadcast frame is dropped or the AP
565                  * fails to send a frame indicating that all CAB frames have
566                  * been delivered.
567                  */
568                 sc->ps_flags &= ~PS_WAIT_FOR_CAB;
569                 ath_dbg(common, PS, "PS wait for CAB frames timed out\n");
570         }
571 }
572
573 static void ath_rx_ps(struct ath_softc *sc, struct sk_buff *skb, bool mybeacon)
574 {
575         struct ieee80211_hdr *hdr;
576         struct ath_common *common = ath9k_hw_common(sc->sc_ah);
577
578         hdr = (struct ieee80211_hdr *)skb->data;
579
580         /* Process Beacon and CAB receive in PS state */
581         if (((sc->ps_flags & PS_WAIT_FOR_BEACON) || ath9k_check_auto_sleep(sc))
582             && mybeacon) {
583                 ath_rx_ps_beacon(sc, skb);
584         } else if ((sc->ps_flags & PS_WAIT_FOR_CAB) &&
585                    (ieee80211_is_data(hdr->frame_control) ||
586                     ieee80211_is_action(hdr->frame_control)) &&
587                    is_multicast_ether_addr(hdr->addr1) &&
588                    !ieee80211_has_moredata(hdr->frame_control)) {
589                 /*
590                  * No more broadcast/multicast frames to be received at this
591                  * point.
592                  */
593                 sc->ps_flags &= ~(PS_WAIT_FOR_CAB | PS_WAIT_FOR_BEACON);
594                 ath_dbg(common, PS,
595                         "All PS CAB frames received, back to sleep\n");
596         } else if ((sc->ps_flags & PS_WAIT_FOR_PSPOLL_DATA) &&
597                    !is_multicast_ether_addr(hdr->addr1) &&
598                    !ieee80211_has_morefrags(hdr->frame_control)) {
599                 sc->ps_flags &= ~PS_WAIT_FOR_PSPOLL_DATA;
600                 ath_dbg(common, PS,
601                         "Going back to sleep after having received PS-Poll data (0x%lx)\n",
602                         sc->ps_flags & (PS_WAIT_FOR_BEACON |
603                                         PS_WAIT_FOR_CAB |
604                                         PS_WAIT_FOR_PSPOLL_DATA |
605                                         PS_WAIT_FOR_TX_ACK));
606         }
607 }
608
609 static bool ath_edma_get_buffers(struct ath_softc *sc,
610                                  enum ath9k_rx_qtype qtype,
611                                  struct ath_rx_status *rs,
612                                  struct ath_buf **dest)
613 {
614         struct ath_rx_edma *rx_edma = &sc->rx.rx_edma[qtype];
615         struct ath_hw *ah = sc->sc_ah;
616         struct ath_common *common = ath9k_hw_common(ah);
617         struct sk_buff *skb;
618         struct ath_buf *bf;
619         int ret;
620
621         skb = skb_peek(&rx_edma->rx_fifo);
622         if (!skb)
623                 return false;
624
625         bf = SKB_CB_ATHBUF(skb);
626         BUG_ON(!bf);
627
628         dma_sync_single_for_cpu(sc->dev, bf->bf_buf_addr,
629                                 common->rx_bufsize, DMA_FROM_DEVICE);
630
631         ret = ath9k_hw_process_rxdesc_edma(ah, rs, skb->data);
632         if (ret == -EINPROGRESS) {
633                 /*let device gain the buffer again*/
634                 dma_sync_single_for_device(sc->dev, bf->bf_buf_addr,
635                                 common->rx_bufsize, DMA_FROM_DEVICE);
636                 return false;
637         }
638
639         __skb_unlink(skb, &rx_edma->rx_fifo);
640         if (ret == -EINVAL) {
641                 /* corrupt descriptor, skip this one and the following one */
642                 list_add_tail(&bf->list, &sc->rx.rxbuf);
643                 ath_rx_edma_buf_link(sc, qtype);
644
645                 skb = skb_peek(&rx_edma->rx_fifo);
646                 if (skb) {
647                         bf = SKB_CB_ATHBUF(skb);
648                         BUG_ON(!bf);
649
650                         __skb_unlink(skb, &rx_edma->rx_fifo);
651                         list_add_tail(&bf->list, &sc->rx.rxbuf);
652                         ath_rx_edma_buf_link(sc, qtype);
653                 }
654
655                 bf = NULL;
656         }
657
658         *dest = bf;
659         return true;
660 }
661
662 static struct ath_buf *ath_edma_get_next_rx_buf(struct ath_softc *sc,
663                                                 struct ath_rx_status *rs,
664                                                 enum ath9k_rx_qtype qtype)
665 {
666         struct ath_buf *bf = NULL;
667
668         while (ath_edma_get_buffers(sc, qtype, rs, &bf)) {
669                 if (!bf)
670                         continue;
671
672                 return bf;
673         }
674         return NULL;
675 }
676
677 static struct ath_buf *ath_get_next_rx_buf(struct ath_softc *sc,
678                                            struct ath_rx_status *rs)
679 {
680         struct ath_hw *ah = sc->sc_ah;
681         struct ath_common *common = ath9k_hw_common(ah);
682         struct ath_desc *ds;
683         struct ath_buf *bf;
684         int ret;
685
686         if (list_empty(&sc->rx.rxbuf)) {
687                 sc->rx.rxlink = NULL;
688                 return NULL;
689         }
690
691         bf = list_first_entry(&sc->rx.rxbuf, struct ath_buf, list);
692         ds = bf->bf_desc;
693
694         /*
695          * Must provide the virtual address of the current
696          * descriptor, the physical address, and the virtual
697          * address of the next descriptor in the h/w chain.
698          * This allows the HAL to look ahead to see if the
699          * hardware is done with a descriptor by checking the
700          * done bit in the following descriptor and the address
701          * of the current descriptor the DMA engine is working
702          * on.  All this is necessary because of our use of
703          * a self-linked list to avoid rx overruns.
704          */
705         ret = ath9k_hw_rxprocdesc(ah, ds, rs);
706         if (ret == -EINPROGRESS) {
707                 struct ath_rx_status trs;
708                 struct ath_buf *tbf;
709                 struct ath_desc *tds;
710
711                 memset(&trs, 0, sizeof(trs));
712                 if (list_is_last(&bf->list, &sc->rx.rxbuf)) {
713                         sc->rx.rxlink = NULL;
714                         return NULL;
715                 }
716
717                 tbf = list_entry(bf->list.next, struct ath_buf, list);
718
719                 /*
720                  * On some hardware the descriptor status words could
721                  * get corrupted, including the done bit. Because of
722                  * this, check if the next descriptor's done bit is
723                  * set or not.
724                  *
725                  * If the next descriptor's done bit is set, the current
726                  * descriptor has been corrupted. Force s/w to discard
727                  * this descriptor and continue...
728                  */
729
730                 tds = tbf->bf_desc;
731                 ret = ath9k_hw_rxprocdesc(ah, tds, &trs);
732                 if (ret == -EINPROGRESS)
733                         return NULL;
734         }
735
736         list_del(&bf->list);
737         if (!bf->bf_mpdu)
738                 return bf;
739
740         /*
741          * Synchronize the DMA transfer with CPU before
742          * 1. accessing the frame
743          * 2. requeueing the same buffer to h/w
744          */
745         dma_sync_single_for_cpu(sc->dev, bf->bf_buf_addr,
746                         common->rx_bufsize,
747                         DMA_FROM_DEVICE);
748
749         return bf;
750 }
751
752 /* Assumes you've already done the endian to CPU conversion */
753 static bool ath9k_rx_accept(struct ath_common *common,
754                             struct ieee80211_hdr *hdr,
755                             struct ieee80211_rx_status *rxs,
756                             struct ath_rx_status *rx_stats,
757                             bool *decrypt_error)
758 {
759         struct ath_softc *sc = (struct ath_softc *) common->priv;
760         bool is_mc, is_valid_tkip, strip_mic, mic_error;
761         struct ath_hw *ah = common->ah;
762         __le16 fc;
763         u8 rx_status_len = ah->caps.rx_status_len;
764
765         fc = hdr->frame_control;
766
767         is_mc = !!is_multicast_ether_addr(hdr->addr1);
768         is_valid_tkip = rx_stats->rs_keyix != ATH9K_RXKEYIX_INVALID &&
769                 test_bit(rx_stats->rs_keyix, common->tkip_keymap);
770         strip_mic = is_valid_tkip && ieee80211_is_data(fc) &&
771                 ieee80211_has_protected(fc) &&
772                 !(rx_stats->rs_status &
773                 (ATH9K_RXERR_DECRYPT | ATH9K_RXERR_CRC | ATH9K_RXERR_MIC |
774                  ATH9K_RXERR_KEYMISS));
775
776         /*
777          * Key miss events are only relevant for pairwise keys where the
778          * descriptor does contain a valid key index. This has been observed
779          * mostly with CCMP encryption.
780          */
781         if (rx_stats->rs_keyix == ATH9K_RXKEYIX_INVALID ||
782             !test_bit(rx_stats->rs_keyix, common->ccmp_keymap))
783                 rx_stats->rs_status &= ~ATH9K_RXERR_KEYMISS;
784
785         if (!rx_stats->rs_datalen) {
786                 RX_STAT_INC(rx_len_err);
787                 return false;
788         }
789
790         /*
791          * rs_status follows rs_datalen so if rs_datalen is too large
792          * we can take a hint that hardware corrupted it, so ignore
793          * those frames.
794          */
795         if (rx_stats->rs_datalen > (common->rx_bufsize - rx_status_len)) {
796                 RX_STAT_INC(rx_len_err);
797                 return false;
798         }
799
800         /* Only use error bits from the last fragment */
801         if (rx_stats->rs_more)
802                 return true;
803
804         mic_error = is_valid_tkip && !ieee80211_is_ctl(fc) &&
805                 !ieee80211_has_morefrags(fc) &&
806                 !(le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG) &&
807                 (rx_stats->rs_status & ATH9K_RXERR_MIC);
808
809         /*
810          * The rx_stats->rs_status will not be set until the end of the
811          * chained descriptors so it can be ignored if rs_more is set. The
812          * rs_more will be false at the last element of the chained
813          * descriptors.
814          */
815         if (rx_stats->rs_status != 0) {
816                 u8 status_mask;
817
818                 if (rx_stats->rs_status & ATH9K_RXERR_CRC) {
819                         rxs->flag |= RX_FLAG_FAILED_FCS_CRC;
820                         mic_error = false;
821                 }
822                 if (rx_stats->rs_status & ATH9K_RXERR_PHY)
823                         return false;
824
825                 if ((rx_stats->rs_status & ATH9K_RXERR_DECRYPT) ||
826                     (!is_mc && (rx_stats->rs_status & ATH9K_RXERR_KEYMISS))) {
827                         *decrypt_error = true;
828                         mic_error = false;
829                 }
830
831                 /*
832                  * Reject error frames with the exception of
833                  * decryption and MIC failures. For monitor mode,
834                  * we also ignore the CRC error.
835                  */
836                 status_mask = ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC |
837                               ATH9K_RXERR_KEYMISS;
838
839                 if (ah->is_monitoring && (sc->rx.rxfilter & FIF_FCSFAIL))
840                         status_mask |= ATH9K_RXERR_CRC;
841
842                 if (rx_stats->rs_status & ~status_mask)
843                         return false;
844         }
845
846         /*
847          * For unicast frames the MIC error bit can have false positives,
848          * so all MIC error reports need to be validated in software.
849          * False negatives are not common, so skip software verification
850          * if the hardware considers the MIC valid.
851          */
852         if (strip_mic)
853                 rxs->flag |= RX_FLAG_MMIC_STRIPPED;
854         else if (is_mc && mic_error)
855                 rxs->flag |= RX_FLAG_MMIC_ERROR;
856
857         return true;
858 }
859
860 static int ath9k_process_rate(struct ath_common *common,
861                               struct ieee80211_hw *hw,
862                               struct ath_rx_status *rx_stats,
863                               struct ieee80211_rx_status *rxs)
864 {
865         struct ieee80211_supported_band *sband;
866         enum ieee80211_band band;
867         unsigned int i = 0;
868         struct ath_softc __maybe_unused *sc = common->priv;
869
870         band = hw->conf.channel->band;
871         sband = hw->wiphy->bands[band];
872
873         if (rx_stats->rs_rate & 0x80) {
874                 /* HT rate */
875                 rxs->flag |= RX_FLAG_HT;
876                 if (rx_stats->rs_flags & ATH9K_RX_2040)
877                         rxs->flag |= RX_FLAG_40MHZ;
878                 if (rx_stats->rs_flags & ATH9K_RX_GI)
879                         rxs->flag |= RX_FLAG_SHORT_GI;
880                 rxs->rate_idx = rx_stats->rs_rate & 0x7f;
881                 return 0;
882         }
883
884         for (i = 0; i < sband->n_bitrates; i++) {
885                 if (sband->bitrates[i].hw_value == rx_stats->rs_rate) {
886                         rxs->rate_idx = i;
887                         return 0;
888                 }
889                 if (sband->bitrates[i].hw_value_short == rx_stats->rs_rate) {
890                         rxs->flag |= RX_FLAG_SHORTPRE;
891                         rxs->rate_idx = i;
892                         return 0;
893                 }
894         }
895
896         /*
897          * No valid hardware bitrate found -- we should not get here
898          * because hardware has already validated this frame as OK.
899          */
900         ath_dbg(common, ANY,
901                 "unsupported hw bitrate detected 0x%02x using 1 Mbit\n",
902                 rx_stats->rs_rate);
903         RX_STAT_INC(rx_rate_err);
904         return -EINVAL;
905 }
906
907 static void ath9k_process_rssi(struct ath_common *common,
908                                struct ieee80211_hw *hw,
909                                struct ieee80211_hdr *hdr,
910                                struct ath_rx_status *rx_stats)
911 {
912         struct ath_softc *sc = hw->priv;
913         struct ath_hw *ah = common->ah;
914         int last_rssi;
915         int rssi = rx_stats->rs_rssi;
916
917         if (!rx_stats->is_mybeacon ||
918             ((ah->opmode != NL80211_IFTYPE_STATION) &&
919              (ah->opmode != NL80211_IFTYPE_ADHOC)))
920                 return;
921
922         if (rx_stats->rs_rssi != ATH9K_RSSI_BAD && !rx_stats->rs_moreaggr)
923                 ATH_RSSI_LPF(sc->last_rssi, rx_stats->rs_rssi);
924
925         last_rssi = sc->last_rssi;
926         if (likely(last_rssi != ATH_RSSI_DUMMY_MARKER))
927                 rssi = ATH_EP_RND(last_rssi, ATH_RSSI_EP_MULTIPLIER);
928         if (rssi < 0)
929                 rssi = 0;
930
931         /* Update Beacon RSSI, this is used by ANI. */
932         ah->stats.avgbrssi = rssi;
933 }
934
935 /*
936  * For Decrypt or Demic errors, we only mark packet status here and always push
937  * up the frame up to let mac80211 handle the actual error case, be it no
938  * decryption key or real decryption error. This let us keep statistics there.
939  */
940 static int ath9k_rx_skb_preprocess(struct ath_common *common,
941                                    struct ieee80211_hw *hw,
942                                    struct ieee80211_hdr *hdr,
943                                    struct ath_rx_status *rx_stats,
944                                    struct ieee80211_rx_status *rx_status,
945                                    bool *decrypt_error)
946 {
947         struct ath_hw *ah = common->ah;
948
949         /*
950          * everything but the rate is checked here, the rate check is done
951          * separately to avoid doing two lookups for a rate for each frame.
952          */
953         if (!ath9k_rx_accept(common, hdr, rx_status, rx_stats, decrypt_error))
954                 return -EINVAL;
955
956         /* Only use status info from the last fragment */
957         if (rx_stats->rs_more)
958                 return 0;
959
960         ath9k_process_rssi(common, hw, hdr, rx_stats);
961
962         if (ath9k_process_rate(common, hw, rx_stats, rx_status))
963                 return -EINVAL;
964
965         rx_status->band = hw->conf.channel->band;
966         rx_status->freq = hw->conf.channel->center_freq;
967         rx_status->signal = ah->noise + rx_stats->rs_rssi;
968         rx_status->antenna = rx_stats->rs_antenna;
969         rx_status->flag |= RX_FLAG_MACTIME_END;
970         if (rx_stats->rs_moreaggr)
971                 rx_status->flag |= RX_FLAG_NO_SIGNAL_VAL;
972
973         return 0;
974 }
975
976 static void ath9k_rx_skb_postprocess(struct ath_common *common,
977                                      struct sk_buff *skb,
978                                      struct ath_rx_status *rx_stats,
979                                      struct ieee80211_rx_status *rxs,
980                                      bool decrypt_error)
981 {
982         struct ath_hw *ah = common->ah;
983         struct ieee80211_hdr *hdr;
984         int hdrlen, padpos, padsize;
985         u8 keyix;
986         __le16 fc;
987
988         /* see if any padding is done by the hw and remove it */
989         hdr = (struct ieee80211_hdr *) skb->data;
990         hdrlen = ieee80211_get_hdrlen_from_skb(skb);
991         fc = hdr->frame_control;
992         padpos = ath9k_cmn_padpos(hdr->frame_control);
993
994         /* The MAC header is padded to have 32-bit boundary if the
995          * packet payload is non-zero. The general calculation for
996          * padsize would take into account odd header lengths:
997          * padsize = (4 - padpos % 4) % 4; However, since only
998          * even-length headers are used, padding can only be 0 or 2
999          * bytes and we can optimize this a bit. In addition, we must
1000          * not try to remove padding from short control frames that do
1001          * not have payload. */
1002         padsize = padpos & 3;
1003         if (padsize && skb->len>=padpos+padsize+FCS_LEN) {
1004                 memmove(skb->data + padsize, skb->data, padpos);
1005                 skb_pull(skb, padsize);
1006         }
1007
1008         keyix = rx_stats->rs_keyix;
1009
1010         if (!(keyix == ATH9K_RXKEYIX_INVALID) && !decrypt_error &&
1011             ieee80211_has_protected(fc)) {
1012                 rxs->flag |= RX_FLAG_DECRYPTED;
1013         } else if (ieee80211_has_protected(fc)
1014                    && !decrypt_error && skb->len >= hdrlen + 4) {
1015                 keyix = skb->data[hdrlen + 3] >> 6;
1016
1017                 if (test_bit(keyix, common->keymap))
1018                         rxs->flag |= RX_FLAG_DECRYPTED;
1019         }
1020         if (ah->sw_mgmt_crypto &&
1021             (rxs->flag & RX_FLAG_DECRYPTED) &&
1022             ieee80211_is_mgmt(fc))
1023                 /* Use software decrypt for management frames. */
1024                 rxs->flag &= ~RX_FLAG_DECRYPTED;
1025 }
1026
1027 int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp)
1028 {
1029         struct ath_buf *bf;
1030         struct sk_buff *skb = NULL, *requeue_skb, *hdr_skb;
1031         struct ieee80211_rx_status *rxs;
1032         struct ath_hw *ah = sc->sc_ah;
1033         struct ath_common *common = ath9k_hw_common(ah);
1034         struct ieee80211_hw *hw = sc->hw;
1035         struct ieee80211_hdr *hdr;
1036         int retval;
1037         struct ath_rx_status rs;
1038         enum ath9k_rx_qtype qtype;
1039         bool edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA);
1040         int dma_type;
1041         u8 rx_status_len = ah->caps.rx_status_len;
1042         u64 tsf = 0;
1043         u32 tsf_lower = 0;
1044         unsigned long flags;
1045
1046         if (edma)
1047                 dma_type = DMA_BIDIRECTIONAL;
1048         else
1049                 dma_type = DMA_FROM_DEVICE;
1050
1051         qtype = hp ? ATH9K_RX_QUEUE_HP : ATH9K_RX_QUEUE_LP;
1052
1053         tsf = ath9k_hw_gettsf64(ah);
1054         tsf_lower = tsf & 0xffffffff;
1055
1056         do {
1057                 bool decrypt_error = false;
1058
1059                 memset(&rs, 0, sizeof(rs));
1060                 if (edma)
1061                         bf = ath_edma_get_next_rx_buf(sc, &rs, qtype);
1062                 else
1063                         bf = ath_get_next_rx_buf(sc, &rs);
1064
1065                 if (!bf)
1066                         break;
1067
1068                 skb = bf->bf_mpdu;
1069                 if (!skb)
1070                         continue;
1071
1072                 /*
1073                  * Take frame header from the first fragment and RX status from
1074                  * the last one.
1075                  */
1076                 if (sc->rx.frag)
1077                         hdr_skb = sc->rx.frag;
1078                 else
1079                         hdr_skb = skb;
1080
1081                 hdr = (struct ieee80211_hdr *) (hdr_skb->data + rx_status_len);
1082                 rxs = IEEE80211_SKB_RXCB(hdr_skb);
1083                 if (ieee80211_is_beacon(hdr->frame_control)) {
1084                         RX_STAT_INC(rx_beacons);
1085                         if (!is_zero_ether_addr(common->curbssid) &&
1086                             ether_addr_equal(hdr->addr3, common->curbssid))
1087                                 rs.is_mybeacon = true;
1088                         else
1089                                 rs.is_mybeacon = false;
1090                 }
1091                 else
1092                         rs.is_mybeacon = false;
1093
1094                 if (ieee80211_is_data_present(hdr->frame_control) &&
1095                     !ieee80211_is_qos_nullfunc(hdr->frame_control))
1096                         sc->rx.num_pkts++;
1097
1098                 ath_debug_stat_rx(sc, &rs);
1099
1100                 memset(rxs, 0, sizeof(struct ieee80211_rx_status));
1101
1102                 rxs->mactime = (tsf & ~0xffffffffULL) | rs.rs_tstamp;
1103                 if (rs.rs_tstamp > tsf_lower &&
1104                     unlikely(rs.rs_tstamp - tsf_lower > 0x10000000))
1105                         rxs->mactime -= 0x100000000ULL;
1106
1107                 if (rs.rs_tstamp < tsf_lower &&
1108                     unlikely(tsf_lower - rs.rs_tstamp > 0x10000000))
1109                         rxs->mactime += 0x100000000ULL;
1110
1111                 retval = ath9k_rx_skb_preprocess(common, hw, hdr, &rs,
1112                                                  rxs, &decrypt_error);
1113                 if (retval)
1114                         goto requeue_drop_frag;
1115
1116                 if (rs.is_mybeacon) {
1117                         sc->hw_busy_count = 0;
1118                         ath_start_rx_poll(sc, 3);
1119                 }
1120                 /* Ensure we always have an skb to requeue once we are done
1121                  * processing the current buffer's skb */
1122                 requeue_skb = ath_rxbuf_alloc(common, common->rx_bufsize, GFP_ATOMIC);
1123
1124                 /* If there is no memory we ignore the current RX'd frame,
1125                  * tell hardware it can give us a new frame using the old
1126                  * skb and put it at the tail of the sc->rx.rxbuf list for
1127                  * processing. */
1128                 if (!requeue_skb) {
1129                         RX_STAT_INC(rx_oom_err);
1130                         goto requeue_drop_frag;
1131                 }
1132
1133                 /* Unmap the frame */
1134                 dma_unmap_single(sc->dev, bf->bf_buf_addr,
1135                                  common->rx_bufsize,
1136                                  dma_type);
1137
1138                 skb_put(skb, rs.rs_datalen + ah->caps.rx_status_len);
1139                 if (ah->caps.rx_status_len)
1140                         skb_pull(skb, ah->caps.rx_status_len);
1141
1142                 if (!rs.rs_more)
1143                         ath9k_rx_skb_postprocess(common, hdr_skb, &rs,
1144                                                  rxs, decrypt_error);
1145
1146                 /* We will now give hardware our shiny new allocated skb */
1147                 bf->bf_mpdu = requeue_skb;
1148                 bf->bf_buf_addr = dma_map_single(sc->dev, requeue_skb->data,
1149                                                  common->rx_bufsize,
1150                                                  dma_type);
1151                 if (unlikely(dma_mapping_error(sc->dev,
1152                           bf->bf_buf_addr))) {
1153                         dev_kfree_skb_any(requeue_skb);
1154                         bf->bf_mpdu = NULL;
1155                         bf->bf_buf_addr = 0;
1156                         ath_err(common, "dma_mapping_error() on RX\n");
1157                         ieee80211_rx(hw, skb);
1158                         break;
1159                 }
1160
1161                 if (rs.rs_more) {
1162                         RX_STAT_INC(rx_frags);
1163                         /*
1164                          * rs_more indicates chained descriptors which can be
1165                          * used to link buffers together for a sort of
1166                          * scatter-gather operation.
1167                          */
1168                         if (sc->rx.frag) {
1169                                 /* too many fragments - cannot handle frame */
1170                                 dev_kfree_skb_any(sc->rx.frag);
1171                                 dev_kfree_skb_any(skb);
1172                                 RX_STAT_INC(rx_too_many_frags_err);
1173                                 skb = NULL;
1174                         }
1175                         sc->rx.frag = skb;
1176                         goto requeue;
1177                 }
1178
1179                 if (sc->rx.frag) {
1180                         int space = skb->len - skb_tailroom(hdr_skb);
1181
1182                         if (pskb_expand_head(hdr_skb, 0, space, GFP_ATOMIC) < 0) {
1183                                 dev_kfree_skb(skb);
1184                                 RX_STAT_INC(rx_oom_err);
1185                                 goto requeue_drop_frag;
1186                         }
1187
1188                         sc->rx.frag = NULL;
1189
1190                         skb_copy_from_linear_data(skb, skb_put(hdr_skb, skb->len),
1191                                                   skb->len);
1192                         dev_kfree_skb_any(skb);
1193                         skb = hdr_skb;
1194                 }
1195
1196
1197                 if (ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB) {
1198
1199                         /*
1200                          * change the default rx antenna if rx diversity
1201                          * chooses the other antenna 3 times in a row.
1202                          */
1203                         if (sc->rx.defant != rs.rs_antenna) {
1204                                 if (++sc->rx.rxotherant >= 3)
1205                                         ath_setdefantenna(sc, rs.rs_antenna);
1206                         } else {
1207                                 sc->rx.rxotherant = 0;
1208                         }
1209
1210                 }
1211
1212                 if (rxs->flag & RX_FLAG_MMIC_STRIPPED)
1213                         skb_trim(skb, skb->len - 8);
1214
1215                 spin_lock_irqsave(&sc->sc_pm_lock, flags);
1216                 if ((sc->ps_flags & (PS_WAIT_FOR_BEACON |
1217                                      PS_WAIT_FOR_CAB |
1218                                      PS_WAIT_FOR_PSPOLL_DATA)) ||
1219                     ath9k_check_auto_sleep(sc))
1220                         ath_rx_ps(sc, skb, rs.is_mybeacon);
1221                 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
1222
1223                 if ((ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB) && sc->ant_rx == 3)
1224                         ath_ant_comb_scan(sc, &rs);
1225
1226                 ieee80211_rx(hw, skb);
1227
1228 requeue_drop_frag:
1229                 if (sc->rx.frag) {
1230                         dev_kfree_skb_any(sc->rx.frag);
1231                         sc->rx.frag = NULL;
1232                 }
1233 requeue:
1234                 list_add_tail(&bf->list, &sc->rx.rxbuf);
1235                 if (flush)
1236                         continue;
1237
1238                 if (edma) {
1239                         ath_rx_edma_buf_link(sc, qtype);
1240                 } else {
1241                         ath_rx_buf_link(sc, bf);
1242                         ath9k_hw_rxena(ah);
1243                 }
1244         } while (1);
1245
1246         if (!(ah->imask & ATH9K_INT_RXEOL)) {
1247                 ah->imask |= (ATH9K_INT_RXEOL | ATH9K_INT_RXORN);
1248                 ath9k_hw_set_interrupts(ah);
1249         }
1250
1251         return 0;
1252 }