Merge branch 'bkl/ioctl' of git://git.kernel.org/pub/scm/linux/kernel/git/frederic...
[sfrench/cifs-2.6.git] / drivers / net / wireless / ath / ath9k / recv.c
1 /*
2  * Copyright (c) 2008-2009 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 "ath9k.h"
18 #include "ar9003_mac.h"
19
20 #define SKB_CB_ATHBUF(__skb)    (*((struct ath_buf **)__skb->cb))
21
22 static inline bool ath9k_check_auto_sleep(struct ath_softc *sc)
23 {
24         return sc->ps_enabled &&
25                (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP);
26 }
27
28 static struct ieee80211_hw * ath_get_virt_hw(struct ath_softc *sc,
29                                              struct ieee80211_hdr *hdr)
30 {
31         struct ieee80211_hw *hw = sc->pri_wiphy->hw;
32         int i;
33
34         spin_lock_bh(&sc->wiphy_lock);
35         for (i = 0; i < sc->num_sec_wiphy; i++) {
36                 struct ath_wiphy *aphy = sc->sec_wiphy[i];
37                 if (aphy == NULL)
38                         continue;
39                 if (compare_ether_addr(hdr->addr1, aphy->hw->wiphy->perm_addr)
40                     == 0) {
41                         hw = aphy->hw;
42                         break;
43                 }
44         }
45         spin_unlock_bh(&sc->wiphy_lock);
46         return hw;
47 }
48
49 /*
50  * Setup and link descriptors.
51  *
52  * 11N: we can no longer afford to self link the last descriptor.
53  * MAC acknowledges BA status as long as it copies frames to host
54  * buffer (or rx fifo). This can incorrectly acknowledge packets
55  * to a sender if last desc is self-linked.
56  */
57 static void ath_rx_buf_link(struct ath_softc *sc, struct ath_buf *bf)
58 {
59         struct ath_hw *ah = sc->sc_ah;
60         struct ath_common *common = ath9k_hw_common(ah);
61         struct ath_desc *ds;
62         struct sk_buff *skb;
63
64         ATH_RXBUF_RESET(bf);
65
66         ds = bf->bf_desc;
67         ds->ds_link = 0; /* link to null */
68         ds->ds_data = bf->bf_buf_addr;
69
70         /* virtual addr of the beginning of the buffer. */
71         skb = bf->bf_mpdu;
72         BUG_ON(skb == NULL);
73         ds->ds_vdata = skb->data;
74
75         /*
76          * setup rx descriptors. The rx_bufsize here tells the hardware
77          * how much data it can DMA to us and that we are prepared
78          * to process
79          */
80         ath9k_hw_setuprxdesc(ah, ds,
81                              common->rx_bufsize,
82                              0);
83
84         if (sc->rx.rxlink == NULL)
85                 ath9k_hw_putrxbuf(ah, bf->bf_daddr);
86         else
87                 *sc->rx.rxlink = bf->bf_daddr;
88
89         sc->rx.rxlink = &ds->ds_link;
90         ath9k_hw_rxena(ah);
91 }
92
93 static void ath_setdefantenna(struct ath_softc *sc, u32 antenna)
94 {
95         /* XXX block beacon interrupts */
96         ath9k_hw_setantenna(sc->sc_ah, antenna);
97         sc->rx.defant = antenna;
98         sc->rx.rxotherant = 0;
99 }
100
101 static void ath_opmode_init(struct ath_softc *sc)
102 {
103         struct ath_hw *ah = sc->sc_ah;
104         struct ath_common *common = ath9k_hw_common(ah);
105
106         u32 rfilt, mfilt[2];
107
108         /* configure rx filter */
109         rfilt = ath_calcrxfilter(sc);
110         ath9k_hw_setrxfilter(ah, rfilt);
111
112         /* configure bssid mask */
113         if (ah->caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK)
114                 ath_hw_setbssidmask(common);
115
116         /* configure operational mode */
117         ath9k_hw_setopmode(ah);
118
119         /* calculate and install multicast filter */
120         mfilt[0] = mfilt[1] = ~0;
121         ath9k_hw_setmcastfilter(ah, mfilt[0], mfilt[1]);
122 }
123
124 static bool ath_rx_edma_buf_link(struct ath_softc *sc,
125                                  enum ath9k_rx_qtype qtype)
126 {
127         struct ath_hw *ah = sc->sc_ah;
128         struct ath_rx_edma *rx_edma;
129         struct sk_buff *skb;
130         struct ath_buf *bf;
131
132         rx_edma = &sc->rx.rx_edma[qtype];
133         if (skb_queue_len(&rx_edma->rx_fifo) >= rx_edma->rx_fifo_hwsize)
134                 return false;
135
136         bf = list_first_entry(&sc->rx.rxbuf, struct ath_buf, list);
137         list_del_init(&bf->list);
138
139         skb = bf->bf_mpdu;
140
141         ATH_RXBUF_RESET(bf);
142         memset(skb->data, 0, ah->caps.rx_status_len);
143         dma_sync_single_for_device(sc->dev, bf->bf_buf_addr,
144                                 ah->caps.rx_status_len, DMA_TO_DEVICE);
145
146         SKB_CB_ATHBUF(skb) = bf;
147         ath9k_hw_addrxbuf_edma(ah, bf->bf_buf_addr, qtype);
148         skb_queue_tail(&rx_edma->rx_fifo, skb);
149
150         return true;
151 }
152
153 static void ath_rx_addbuffer_edma(struct ath_softc *sc,
154                                   enum ath9k_rx_qtype qtype, int size)
155 {
156         struct ath_common *common = ath9k_hw_common(sc->sc_ah);
157         u32 nbuf = 0;
158
159         if (list_empty(&sc->rx.rxbuf)) {
160                 ath_print(common, ATH_DBG_QUEUE, "No free rx buf available\n");
161                 return;
162         }
163
164         while (!list_empty(&sc->rx.rxbuf)) {
165                 nbuf++;
166
167                 if (!ath_rx_edma_buf_link(sc, qtype))
168                         break;
169
170                 if (nbuf >= size)
171                         break;
172         }
173 }
174
175 static void ath_rx_remove_buffer(struct ath_softc *sc,
176                                  enum ath9k_rx_qtype qtype)
177 {
178         struct ath_buf *bf;
179         struct ath_rx_edma *rx_edma;
180         struct sk_buff *skb;
181
182         rx_edma = &sc->rx.rx_edma[qtype];
183
184         while ((skb = skb_dequeue(&rx_edma->rx_fifo)) != NULL) {
185                 bf = SKB_CB_ATHBUF(skb);
186                 BUG_ON(!bf);
187                 list_add_tail(&bf->list, &sc->rx.rxbuf);
188         }
189 }
190
191 static void ath_rx_edma_cleanup(struct ath_softc *sc)
192 {
193         struct ath_buf *bf;
194
195         ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_LP);
196         ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_HP);
197
198         list_for_each_entry(bf, &sc->rx.rxbuf, list) {
199                 if (bf->bf_mpdu)
200                         dev_kfree_skb_any(bf->bf_mpdu);
201         }
202
203         INIT_LIST_HEAD(&sc->rx.rxbuf);
204
205         kfree(sc->rx.rx_bufptr);
206         sc->rx.rx_bufptr = NULL;
207 }
208
209 static void ath_rx_edma_init_queue(struct ath_rx_edma *rx_edma, int size)
210 {
211         skb_queue_head_init(&rx_edma->rx_fifo);
212         skb_queue_head_init(&rx_edma->rx_buffers);
213         rx_edma->rx_fifo_hwsize = size;
214 }
215
216 static int ath_rx_edma_init(struct ath_softc *sc, int nbufs)
217 {
218         struct ath_common *common = ath9k_hw_common(sc->sc_ah);
219         struct ath_hw *ah = sc->sc_ah;
220         struct sk_buff *skb;
221         struct ath_buf *bf;
222         int error = 0, i;
223         u32 size;
224
225
226         common->rx_bufsize = roundup(IEEE80211_MAX_MPDU_LEN +
227                                      ah->caps.rx_status_len,
228                                      min(common->cachelsz, (u16)64));
229
230         ath9k_hw_set_rx_bufsize(ah, common->rx_bufsize -
231                                     ah->caps.rx_status_len);
232
233         ath_rx_edma_init_queue(&sc->rx.rx_edma[ATH9K_RX_QUEUE_LP],
234                                ah->caps.rx_lp_qdepth);
235         ath_rx_edma_init_queue(&sc->rx.rx_edma[ATH9K_RX_QUEUE_HP],
236                                ah->caps.rx_hp_qdepth);
237
238         size = sizeof(struct ath_buf) * nbufs;
239         bf = kzalloc(size, GFP_KERNEL);
240         if (!bf)
241                 return -ENOMEM;
242
243         INIT_LIST_HEAD(&sc->rx.rxbuf);
244         sc->rx.rx_bufptr = bf;
245
246         for (i = 0; i < nbufs; i++, bf++) {
247                 skb = ath_rxbuf_alloc(common, common->rx_bufsize, GFP_KERNEL);
248                 if (!skb) {
249                         error = -ENOMEM;
250                         goto rx_init_fail;
251                 }
252
253                 memset(skb->data, 0, common->rx_bufsize);
254                 bf->bf_mpdu = skb;
255
256                 bf->bf_buf_addr = dma_map_single(sc->dev, skb->data,
257                                                  common->rx_bufsize,
258                                                  DMA_BIDIRECTIONAL);
259                 if (unlikely(dma_mapping_error(sc->dev,
260                                                 bf->bf_buf_addr))) {
261                                 dev_kfree_skb_any(skb);
262                                 bf->bf_mpdu = NULL;
263                                 ath_print(common, ATH_DBG_FATAL,
264                                         "dma_mapping_error() on RX init\n");
265                                 error = -ENOMEM;
266                                 goto rx_init_fail;
267                 }
268
269                 list_add_tail(&bf->list, &sc->rx.rxbuf);
270         }
271
272         return 0;
273
274 rx_init_fail:
275         ath_rx_edma_cleanup(sc);
276         return error;
277 }
278
279 static void ath_edma_start_recv(struct ath_softc *sc)
280 {
281         spin_lock_bh(&sc->rx.rxbuflock);
282
283         ath9k_hw_rxena(sc->sc_ah);
284
285         ath_rx_addbuffer_edma(sc, ATH9K_RX_QUEUE_HP,
286                               sc->rx.rx_edma[ATH9K_RX_QUEUE_HP].rx_fifo_hwsize);
287
288         ath_rx_addbuffer_edma(sc, ATH9K_RX_QUEUE_LP,
289                               sc->rx.rx_edma[ATH9K_RX_QUEUE_LP].rx_fifo_hwsize);
290
291         spin_unlock_bh(&sc->rx.rxbuflock);
292
293         ath_opmode_init(sc);
294
295         ath9k_hw_startpcureceive(sc->sc_ah, (sc->sc_flags & SC_OP_SCANNING));
296 }
297
298 static void ath_edma_stop_recv(struct ath_softc *sc)
299 {
300         spin_lock_bh(&sc->rx.rxbuflock);
301         ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_HP);
302         ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_LP);
303         spin_unlock_bh(&sc->rx.rxbuflock);
304 }
305
306 int ath_rx_init(struct ath_softc *sc, int nbufs)
307 {
308         struct ath_common *common = ath9k_hw_common(sc->sc_ah);
309         struct sk_buff *skb;
310         struct ath_buf *bf;
311         int error = 0;
312
313         spin_lock_init(&sc->rx.rxflushlock);
314         sc->sc_flags &= ~SC_OP_RXFLUSH;
315         spin_lock_init(&sc->rx.rxbuflock);
316
317         if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
318                 return ath_rx_edma_init(sc, nbufs);
319         } else {
320                 common->rx_bufsize = roundup(IEEE80211_MAX_MPDU_LEN,
321                                 min(common->cachelsz, (u16)64));
322
323                 ath_print(common, ATH_DBG_CONFIG, "cachelsz %u rxbufsize %u\n",
324                                 common->cachelsz, common->rx_bufsize);
325
326                 /* Initialize rx descriptors */
327
328                 error = ath_descdma_setup(sc, &sc->rx.rxdma, &sc->rx.rxbuf,
329                                 "rx", nbufs, 1, 0);
330                 if (error != 0) {
331                         ath_print(common, ATH_DBG_FATAL,
332                                   "failed to allocate rx descriptors: %d\n",
333                                   error);
334                         goto err;
335                 }
336
337                 list_for_each_entry(bf, &sc->rx.rxbuf, list) {
338                         skb = ath_rxbuf_alloc(common, common->rx_bufsize,
339                                               GFP_KERNEL);
340                         if (skb == NULL) {
341                                 error = -ENOMEM;
342                                 goto err;
343                         }
344
345                         bf->bf_mpdu = skb;
346                         bf->bf_buf_addr = dma_map_single(sc->dev, skb->data,
347                                         common->rx_bufsize,
348                                         DMA_FROM_DEVICE);
349                         if (unlikely(dma_mapping_error(sc->dev,
350                                                         bf->bf_buf_addr))) {
351                                 dev_kfree_skb_any(skb);
352                                 bf->bf_mpdu = NULL;
353                                 ath_print(common, ATH_DBG_FATAL,
354                                           "dma_mapping_error() on RX init\n");
355                                 error = -ENOMEM;
356                                 goto err;
357                         }
358                         bf->bf_dmacontext = bf->bf_buf_addr;
359                 }
360                 sc->rx.rxlink = NULL;
361         }
362
363 err:
364         if (error)
365                 ath_rx_cleanup(sc);
366
367         return error;
368 }
369
370 void ath_rx_cleanup(struct ath_softc *sc)
371 {
372         struct ath_hw *ah = sc->sc_ah;
373         struct ath_common *common = ath9k_hw_common(ah);
374         struct sk_buff *skb;
375         struct ath_buf *bf;
376
377         if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
378                 ath_rx_edma_cleanup(sc);
379                 return;
380         } else {
381                 list_for_each_entry(bf, &sc->rx.rxbuf, list) {
382                         skb = bf->bf_mpdu;
383                         if (skb) {
384                                 dma_unmap_single(sc->dev, bf->bf_buf_addr,
385                                                 common->rx_bufsize,
386                                                 DMA_FROM_DEVICE);
387                                 dev_kfree_skb(skb);
388                         }
389                 }
390
391                 if (sc->rx.rxdma.dd_desc_len != 0)
392                         ath_descdma_cleanup(sc, &sc->rx.rxdma, &sc->rx.rxbuf);
393         }
394 }
395
396 /*
397  * Calculate the receive filter according to the
398  * operating mode and state:
399  *
400  * o always accept unicast, broadcast, and multicast traffic
401  * o maintain current state of phy error reception (the hal
402  *   may enable phy error frames for noise immunity work)
403  * o probe request frames are accepted only when operating in
404  *   hostap, adhoc, or monitor modes
405  * o enable promiscuous mode according to the interface state
406  * o accept beacons:
407  *   - when operating in adhoc mode so the 802.11 layer creates
408  *     node table entries for peers,
409  *   - when operating in station mode for collecting rssi data when
410  *     the station is otherwise quiet, or
411  *   - when operating as a repeater so we see repeater-sta beacons
412  *   - when scanning
413  */
414
415 u32 ath_calcrxfilter(struct ath_softc *sc)
416 {
417 #define RX_FILTER_PRESERVE (ATH9K_RX_FILTER_PHYERR | ATH9K_RX_FILTER_PHYRADAR)
418
419         u32 rfilt;
420
421         rfilt = (ath9k_hw_getrxfilter(sc->sc_ah) & RX_FILTER_PRESERVE)
422                 | ATH9K_RX_FILTER_UCAST | ATH9K_RX_FILTER_BCAST
423                 | ATH9K_RX_FILTER_MCAST;
424
425         /* If not a STA, enable processing of Probe Requests */
426         if (sc->sc_ah->opmode != NL80211_IFTYPE_STATION)
427                 rfilt |= ATH9K_RX_FILTER_PROBEREQ;
428
429         /*
430          * Set promiscuous mode when FIF_PROMISC_IN_BSS is enabled for station
431          * mode interface or when in monitor mode. AP mode does not need this
432          * since it receives all in-BSS frames anyway.
433          */
434         if (((sc->sc_ah->opmode != NL80211_IFTYPE_AP) &&
435              (sc->rx.rxfilter & FIF_PROMISC_IN_BSS)) ||
436             (sc->sc_ah->opmode == NL80211_IFTYPE_MONITOR))
437                 rfilt |= ATH9K_RX_FILTER_PROM;
438
439         if (sc->rx.rxfilter & FIF_CONTROL)
440                 rfilt |= ATH9K_RX_FILTER_CONTROL;
441
442         if ((sc->sc_ah->opmode == NL80211_IFTYPE_STATION) &&
443             !(sc->rx.rxfilter & FIF_BCN_PRBRESP_PROMISC))
444                 rfilt |= ATH9K_RX_FILTER_MYBEACON;
445         else
446                 rfilt |= ATH9K_RX_FILTER_BEACON;
447
448         if ((AR_SREV_9280_10_OR_LATER(sc->sc_ah) ||
449             AR_SREV_9285_10_OR_LATER(sc->sc_ah)) &&
450             (sc->sc_ah->opmode == NL80211_IFTYPE_AP) &&
451             (sc->rx.rxfilter & FIF_PSPOLL))
452                 rfilt |= ATH9K_RX_FILTER_PSPOLL;
453
454         if (conf_is_ht(&sc->hw->conf))
455                 rfilt |= ATH9K_RX_FILTER_COMP_BAR;
456
457         if (sc->sec_wiphy || (sc->rx.rxfilter & FIF_OTHER_BSS)) {
458                 /* TODO: only needed if more than one BSSID is in use in
459                  * station/adhoc mode */
460                 /* The following may also be needed for other older chips */
461                 if (sc->sc_ah->hw_version.macVersion == AR_SREV_VERSION_9160)
462                         rfilt |= ATH9K_RX_FILTER_PROM;
463                 rfilt |= ATH9K_RX_FILTER_MCAST_BCAST_ALL;
464         }
465
466         return rfilt;
467
468 #undef RX_FILTER_PRESERVE
469 }
470
471 int ath_startrecv(struct ath_softc *sc)
472 {
473         struct ath_hw *ah = sc->sc_ah;
474         struct ath_buf *bf, *tbf;
475
476         if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
477                 ath_edma_start_recv(sc);
478                 return 0;
479         }
480
481         spin_lock_bh(&sc->rx.rxbuflock);
482         if (list_empty(&sc->rx.rxbuf))
483                 goto start_recv;
484
485         sc->rx.rxlink = NULL;
486         list_for_each_entry_safe(bf, tbf, &sc->rx.rxbuf, list) {
487                 ath_rx_buf_link(sc, bf);
488         }
489
490         /* We could have deleted elements so the list may be empty now */
491         if (list_empty(&sc->rx.rxbuf))
492                 goto start_recv;
493
494         bf = list_first_entry(&sc->rx.rxbuf, struct ath_buf, list);
495         ath9k_hw_putrxbuf(ah, bf->bf_daddr);
496         ath9k_hw_rxena(ah);
497
498 start_recv:
499         spin_unlock_bh(&sc->rx.rxbuflock);
500         ath_opmode_init(sc);
501         ath9k_hw_startpcureceive(ah, (sc->sc_flags & SC_OP_SCANNING));
502
503         return 0;
504 }
505
506 bool ath_stoprecv(struct ath_softc *sc)
507 {
508         struct ath_hw *ah = sc->sc_ah;
509         bool stopped;
510
511         ath9k_hw_stoppcurecv(ah);
512         ath9k_hw_setrxfilter(ah, 0);
513         stopped = ath9k_hw_stopdmarecv(ah);
514
515         if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
516                 ath_edma_stop_recv(sc);
517         else
518                 sc->rx.rxlink = NULL;
519
520         return stopped;
521 }
522
523 void ath_flushrecv(struct ath_softc *sc)
524 {
525         spin_lock_bh(&sc->rx.rxflushlock);
526         sc->sc_flags |= SC_OP_RXFLUSH;
527         if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
528                 ath_rx_tasklet(sc, 1, true);
529         ath_rx_tasklet(sc, 1, false);
530         sc->sc_flags &= ~SC_OP_RXFLUSH;
531         spin_unlock_bh(&sc->rx.rxflushlock);
532 }
533
534 static bool ath_beacon_dtim_pending_cab(struct sk_buff *skb)
535 {
536         /* Check whether the Beacon frame has DTIM indicating buffered bc/mc */
537         struct ieee80211_mgmt *mgmt;
538         u8 *pos, *end, id, elen;
539         struct ieee80211_tim_ie *tim;
540
541         mgmt = (struct ieee80211_mgmt *)skb->data;
542         pos = mgmt->u.beacon.variable;
543         end = skb->data + skb->len;
544
545         while (pos + 2 < end) {
546                 id = *pos++;
547                 elen = *pos++;
548                 if (pos + elen > end)
549                         break;
550
551                 if (id == WLAN_EID_TIM) {
552                         if (elen < sizeof(*tim))
553                                 break;
554                         tim = (struct ieee80211_tim_ie *) pos;
555                         if (tim->dtim_count != 0)
556                                 break;
557                         return tim->bitmap_ctrl & 0x01;
558                 }
559
560                 pos += elen;
561         }
562
563         return false;
564 }
565
566 static void ath_rx_ps_beacon(struct ath_softc *sc, struct sk_buff *skb)
567 {
568         struct ieee80211_mgmt *mgmt;
569         struct ath_common *common = ath9k_hw_common(sc->sc_ah);
570
571         if (skb->len < 24 + 8 + 2 + 2)
572                 return;
573
574         mgmt = (struct ieee80211_mgmt *)skb->data;
575         if (memcmp(common->curbssid, mgmt->bssid, ETH_ALEN) != 0)
576                 return; /* not from our current AP */
577
578         sc->ps_flags &= ~PS_WAIT_FOR_BEACON;
579
580         if (sc->ps_flags & PS_BEACON_SYNC) {
581                 sc->ps_flags &= ~PS_BEACON_SYNC;
582                 ath_print(common, ATH_DBG_PS,
583                           "Reconfigure Beacon timers based on "
584                           "timestamp from the AP\n");
585                 ath_beacon_config(sc, NULL);
586         }
587
588         if (ath_beacon_dtim_pending_cab(skb)) {
589                 /*
590                  * Remain awake waiting for buffered broadcast/multicast
591                  * frames. If the last broadcast/multicast frame is not
592                  * received properly, the next beacon frame will work as
593                  * a backup trigger for returning into NETWORK SLEEP state,
594                  * so we are waiting for it as well.
595                  */
596                 ath_print(common, ATH_DBG_PS, "Received DTIM beacon indicating "
597                           "buffered broadcast/multicast frame(s)\n");
598                 sc->ps_flags |= PS_WAIT_FOR_CAB | PS_WAIT_FOR_BEACON;
599                 return;
600         }
601
602         if (sc->ps_flags & PS_WAIT_FOR_CAB) {
603                 /*
604                  * This can happen if a broadcast frame is dropped or the AP
605                  * fails to send a frame indicating that all CAB frames have
606                  * been delivered.
607                  */
608                 sc->ps_flags &= ~PS_WAIT_FOR_CAB;
609                 ath_print(common, ATH_DBG_PS,
610                           "PS wait for CAB frames timed out\n");
611         }
612 }
613
614 static void ath_rx_ps(struct ath_softc *sc, struct sk_buff *skb)
615 {
616         struct ieee80211_hdr *hdr;
617         struct ath_common *common = ath9k_hw_common(sc->sc_ah);
618
619         hdr = (struct ieee80211_hdr *)skb->data;
620
621         /* Process Beacon and CAB receive in PS state */
622         if (((sc->ps_flags & PS_WAIT_FOR_BEACON) || ath9k_check_auto_sleep(sc))
623             && ieee80211_is_beacon(hdr->frame_control))
624                 ath_rx_ps_beacon(sc, skb);
625         else if ((sc->ps_flags & PS_WAIT_FOR_CAB) &&
626                  (ieee80211_is_data(hdr->frame_control) ||
627                   ieee80211_is_action(hdr->frame_control)) &&
628                  is_multicast_ether_addr(hdr->addr1) &&
629                  !ieee80211_has_moredata(hdr->frame_control)) {
630                 /*
631                  * No more broadcast/multicast frames to be received at this
632                  * point.
633                  */
634                 sc->ps_flags &= ~PS_WAIT_FOR_CAB;
635                 ath_print(common, ATH_DBG_PS,
636                           "All PS CAB frames received, back to sleep\n");
637         } else if ((sc->ps_flags & PS_WAIT_FOR_PSPOLL_DATA) &&
638                    !is_multicast_ether_addr(hdr->addr1) &&
639                    !ieee80211_has_morefrags(hdr->frame_control)) {
640                 sc->ps_flags &= ~PS_WAIT_FOR_PSPOLL_DATA;
641                 ath_print(common, ATH_DBG_PS,
642                           "Going back to sleep after having received "
643                           "PS-Poll data (0x%lx)\n",
644                         sc->ps_flags & (PS_WAIT_FOR_BEACON |
645                                         PS_WAIT_FOR_CAB |
646                                         PS_WAIT_FOR_PSPOLL_DATA |
647                                         PS_WAIT_FOR_TX_ACK));
648         }
649 }
650
651 static void ath_rx_send_to_mac80211(struct ieee80211_hw *hw,
652                                     struct ath_softc *sc, struct sk_buff *skb,
653                                     struct ieee80211_rx_status *rxs)
654 {
655         struct ieee80211_hdr *hdr;
656
657         hdr = (struct ieee80211_hdr *)skb->data;
658
659         /* Send the frame to mac80211 */
660         if (is_multicast_ether_addr(hdr->addr1)) {
661                 int i;
662                 /*
663                  * Deliver broadcast/multicast frames to all suitable
664                  * virtual wiphys.
665                  */
666                 /* TODO: filter based on channel configuration */
667                 for (i = 0; i < sc->num_sec_wiphy; i++) {
668                         struct ath_wiphy *aphy = sc->sec_wiphy[i];
669                         struct sk_buff *nskb;
670                         if (aphy == NULL)
671                                 continue;
672                         nskb = skb_copy(skb, GFP_ATOMIC);
673                         if (!nskb)
674                                 continue;
675                         ieee80211_rx(aphy->hw, nskb);
676                 }
677                 ieee80211_rx(sc->hw, skb);
678         } else
679                 /* Deliver unicast frames based on receiver address */
680                 ieee80211_rx(hw, skb);
681 }
682
683 static bool ath_edma_get_buffers(struct ath_softc *sc,
684                                  enum ath9k_rx_qtype qtype)
685 {
686         struct ath_rx_edma *rx_edma = &sc->rx.rx_edma[qtype];
687         struct ath_hw *ah = sc->sc_ah;
688         struct ath_common *common = ath9k_hw_common(ah);
689         struct sk_buff *skb;
690         struct ath_buf *bf;
691         int ret;
692
693         skb = skb_peek(&rx_edma->rx_fifo);
694         if (!skb)
695                 return false;
696
697         bf = SKB_CB_ATHBUF(skb);
698         BUG_ON(!bf);
699
700         dma_sync_single_for_cpu(sc->dev, bf->bf_buf_addr,
701                                 common->rx_bufsize, DMA_FROM_DEVICE);
702
703         ret = ath9k_hw_process_rxdesc_edma(ah, NULL, skb->data);
704         if (ret == -EINPROGRESS) {
705                 /*let device gain the buffer again*/
706                 dma_sync_single_for_device(sc->dev, bf->bf_buf_addr,
707                                 common->rx_bufsize, DMA_FROM_DEVICE);
708                 return false;
709         }
710
711         __skb_unlink(skb, &rx_edma->rx_fifo);
712         if (ret == -EINVAL) {
713                 /* corrupt descriptor, skip this one and the following one */
714                 list_add_tail(&bf->list, &sc->rx.rxbuf);
715                 ath_rx_edma_buf_link(sc, qtype);
716                 skb = skb_peek(&rx_edma->rx_fifo);
717                 if (!skb)
718                         return true;
719
720                 bf = SKB_CB_ATHBUF(skb);
721                 BUG_ON(!bf);
722
723                 __skb_unlink(skb, &rx_edma->rx_fifo);
724                 list_add_tail(&bf->list, &sc->rx.rxbuf);
725                 ath_rx_edma_buf_link(sc, qtype);
726                 return true;
727         }
728         skb_queue_tail(&rx_edma->rx_buffers, skb);
729
730         return true;
731 }
732
733 static struct ath_buf *ath_edma_get_next_rx_buf(struct ath_softc *sc,
734                                                 struct ath_rx_status *rs,
735                                                 enum ath9k_rx_qtype qtype)
736 {
737         struct ath_rx_edma *rx_edma = &sc->rx.rx_edma[qtype];
738         struct sk_buff *skb;
739         struct ath_buf *bf;
740
741         while (ath_edma_get_buffers(sc, qtype));
742         skb = __skb_dequeue(&rx_edma->rx_buffers);
743         if (!skb)
744                 return NULL;
745
746         bf = SKB_CB_ATHBUF(skb);
747         ath9k_hw_process_rxdesc_edma(sc->sc_ah, rs, skb->data);
748         return bf;
749 }
750
751 static struct ath_buf *ath_get_next_rx_buf(struct ath_softc *sc,
752                                            struct ath_rx_status *rs)
753 {
754         struct ath_hw *ah = sc->sc_ah;
755         struct ath_common *common = ath9k_hw_common(ah);
756         struct ath_desc *ds;
757         struct ath_buf *bf;
758         int ret;
759
760         if (list_empty(&sc->rx.rxbuf)) {
761                 sc->rx.rxlink = NULL;
762                 return NULL;
763         }
764
765         bf = list_first_entry(&sc->rx.rxbuf, struct ath_buf, list);
766         ds = bf->bf_desc;
767
768         /*
769          * Must provide the virtual address of the current
770          * descriptor, the physical address, and the virtual
771          * address of the next descriptor in the h/w chain.
772          * This allows the HAL to look ahead to see if the
773          * hardware is done with a descriptor by checking the
774          * done bit in the following descriptor and the address
775          * of the current descriptor the DMA engine is working
776          * on.  All this is necessary because of our use of
777          * a self-linked list to avoid rx overruns.
778          */
779         ret = ath9k_hw_rxprocdesc(ah, ds, rs, 0);
780         if (ret == -EINPROGRESS) {
781                 struct ath_rx_status trs;
782                 struct ath_buf *tbf;
783                 struct ath_desc *tds;
784
785                 memset(&trs, 0, sizeof(trs));
786                 if (list_is_last(&bf->list, &sc->rx.rxbuf)) {
787                         sc->rx.rxlink = NULL;
788                         return NULL;
789                 }
790
791                 tbf = list_entry(bf->list.next, struct ath_buf, list);
792
793                 /*
794                  * On some hardware the descriptor status words could
795                  * get corrupted, including the done bit. Because of
796                  * this, check if the next descriptor's done bit is
797                  * set or not.
798                  *
799                  * If the next descriptor's done bit is set, the current
800                  * descriptor has been corrupted. Force s/w to discard
801                  * this descriptor and continue...
802                  */
803
804                 tds = tbf->bf_desc;
805                 ret = ath9k_hw_rxprocdesc(ah, tds, &trs, 0);
806                 if (ret == -EINPROGRESS)
807                         return NULL;
808         }
809
810         if (!bf->bf_mpdu)
811                 return bf;
812
813         /*
814          * Synchronize the DMA transfer with CPU before
815          * 1. accessing the frame
816          * 2. requeueing the same buffer to h/w
817          */
818         dma_sync_single_for_cpu(sc->dev, bf->bf_buf_addr,
819                         common->rx_bufsize,
820                         DMA_FROM_DEVICE);
821
822         return bf;
823 }
824
825 /* Assumes you've already done the endian to CPU conversion */
826 static bool ath9k_rx_accept(struct ath_common *common,
827                             struct ieee80211_hdr *hdr,
828                             struct ieee80211_rx_status *rxs,
829                             struct ath_rx_status *rx_stats,
830                             bool *decrypt_error)
831 {
832         struct ath_hw *ah = common->ah;
833         __le16 fc;
834         u8 rx_status_len = ah->caps.rx_status_len;
835
836         fc = hdr->frame_control;
837
838         if (!rx_stats->rs_datalen)
839                 return false;
840         /*
841          * rs_status follows rs_datalen so if rs_datalen is too large
842          * we can take a hint that hardware corrupted it, so ignore
843          * those frames.
844          */
845         if (rx_stats->rs_datalen > (common->rx_bufsize - rx_status_len))
846                 return false;
847
848         /*
849          * rs_more indicates chained descriptors which can be used
850          * to link buffers together for a sort of scatter-gather
851          * operation.
852          * reject the frame, we don't support scatter-gather yet and
853          * the frame is probably corrupt anyway
854          */
855         if (rx_stats->rs_more)
856                 return false;
857
858         /*
859          * The rx_stats->rs_status will not be set until the end of the
860          * chained descriptors so it can be ignored if rs_more is set. The
861          * rs_more will be false at the last element of the chained
862          * descriptors.
863          */
864         if (rx_stats->rs_status != 0) {
865                 if (rx_stats->rs_status & ATH9K_RXERR_CRC)
866                         rxs->flag |= RX_FLAG_FAILED_FCS_CRC;
867                 if (rx_stats->rs_status & ATH9K_RXERR_PHY)
868                         return false;
869
870                 if (rx_stats->rs_status & ATH9K_RXERR_DECRYPT) {
871                         *decrypt_error = true;
872                 } else if (rx_stats->rs_status & ATH9K_RXERR_MIC) {
873                         if (ieee80211_is_ctl(fc))
874                                 /*
875                                  * Sometimes, we get invalid
876                                  * MIC failures on valid control frames.
877                                  * Remove these mic errors.
878                                  */
879                                 rx_stats->rs_status &= ~ATH9K_RXERR_MIC;
880                         else
881                                 rxs->flag |= RX_FLAG_MMIC_ERROR;
882                 }
883                 /*
884                  * Reject error frames with the exception of
885                  * decryption and MIC failures. For monitor mode,
886                  * we also ignore the CRC error.
887                  */
888                 if (ah->opmode == NL80211_IFTYPE_MONITOR) {
889                         if (rx_stats->rs_status &
890                             ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC |
891                               ATH9K_RXERR_CRC))
892                                 return false;
893                 } else {
894                         if (rx_stats->rs_status &
895                             ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC)) {
896                                 return false;
897                         }
898                 }
899         }
900         return true;
901 }
902
903 static int ath9k_process_rate(struct ath_common *common,
904                               struct ieee80211_hw *hw,
905                               struct ath_rx_status *rx_stats,
906                               struct ieee80211_rx_status *rxs)
907 {
908         struct ieee80211_supported_band *sband;
909         enum ieee80211_band band;
910         unsigned int i = 0;
911
912         band = hw->conf.channel->band;
913         sband = hw->wiphy->bands[band];
914
915         if (rx_stats->rs_rate & 0x80) {
916                 /* HT rate */
917                 rxs->flag |= RX_FLAG_HT;
918                 if (rx_stats->rs_flags & ATH9K_RX_2040)
919                         rxs->flag |= RX_FLAG_40MHZ;
920                 if (rx_stats->rs_flags & ATH9K_RX_GI)
921                         rxs->flag |= RX_FLAG_SHORT_GI;
922                 rxs->rate_idx = rx_stats->rs_rate & 0x7f;
923                 return 0;
924         }
925
926         for (i = 0; i < sband->n_bitrates; i++) {
927                 if (sband->bitrates[i].hw_value == rx_stats->rs_rate) {
928                         rxs->rate_idx = i;
929                         return 0;
930                 }
931                 if (sband->bitrates[i].hw_value_short == rx_stats->rs_rate) {
932                         rxs->flag |= RX_FLAG_SHORTPRE;
933                         rxs->rate_idx = i;
934                         return 0;
935                 }
936         }
937
938         /*
939          * No valid hardware bitrate found -- we should not get here
940          * because hardware has already validated this frame as OK.
941          */
942         ath_print(common, ATH_DBG_XMIT, "unsupported hw bitrate detected "
943                   "0x%02x using 1 Mbit\n", rx_stats->rs_rate);
944
945         return -EINVAL;
946 }
947
948 static void ath9k_process_rssi(struct ath_common *common,
949                                struct ieee80211_hw *hw,
950                                struct ieee80211_hdr *hdr,
951                                struct ath_rx_status *rx_stats)
952 {
953         struct ath_hw *ah = common->ah;
954         struct ieee80211_sta *sta;
955         struct ath_node *an;
956         int last_rssi = ATH_RSSI_DUMMY_MARKER;
957         __le16 fc;
958
959         fc = hdr->frame_control;
960
961         rcu_read_lock();
962         /*
963          * XXX: use ieee80211_find_sta! This requires quite a bit of work
964          * under the current ath9k virtual wiphy implementation as we have
965          * no way of tying a vif to wiphy. Typically vifs are attached to
966          * at least one sdata of a wiphy on mac80211 but with ath9k virtual
967          * wiphy you'd have to iterate over every wiphy and each sdata.
968          */
969         sta = ieee80211_find_sta_by_hw(hw, hdr->addr2);
970         if (sta) {
971                 an = (struct ath_node *) sta->drv_priv;
972                 if (rx_stats->rs_rssi != ATH9K_RSSI_BAD &&
973                    !rx_stats->rs_moreaggr)
974                         ATH_RSSI_LPF(an->last_rssi, rx_stats->rs_rssi);
975                 last_rssi = an->last_rssi;
976         }
977         rcu_read_unlock();
978
979         if (likely(last_rssi != ATH_RSSI_DUMMY_MARKER))
980                 rx_stats->rs_rssi = ATH_EP_RND(last_rssi,
981                                               ATH_RSSI_EP_MULTIPLIER);
982         if (rx_stats->rs_rssi < 0)
983                 rx_stats->rs_rssi = 0;
984
985         /* Update Beacon RSSI, this is used by ANI. */
986         if (ieee80211_is_beacon(fc))
987                 ah->stats.avgbrssi = rx_stats->rs_rssi;
988 }
989
990 /*
991  * For Decrypt or Demic errors, we only mark packet status here and always push
992  * up the frame up to let mac80211 handle the actual error case, be it no
993  * decryption key or real decryption error. This let us keep statistics there.
994  */
995 static int ath9k_rx_skb_preprocess(struct ath_common *common,
996                                    struct ieee80211_hw *hw,
997                                    struct ieee80211_hdr *hdr,
998                                    struct ath_rx_status *rx_stats,
999                                    struct ieee80211_rx_status *rx_status,
1000                                    bool *decrypt_error)
1001 {
1002         memset(rx_status, 0, sizeof(struct ieee80211_rx_status));
1003
1004         /*
1005          * everything but the rate is checked here, the rate check is done
1006          * separately to avoid doing two lookups for a rate for each frame.
1007          */
1008         if (!ath9k_rx_accept(common, hdr, rx_status, rx_stats, decrypt_error))
1009                 return -EINVAL;
1010
1011         ath9k_process_rssi(common, hw, hdr, rx_stats);
1012
1013         if (ath9k_process_rate(common, hw, rx_stats, rx_status))
1014                 return -EINVAL;
1015
1016         rx_status->band = hw->conf.channel->band;
1017         rx_status->freq = hw->conf.channel->center_freq;
1018         rx_status->signal = ATH_DEFAULT_NOISE_FLOOR + rx_stats->rs_rssi;
1019         rx_status->antenna = rx_stats->rs_antenna;
1020         rx_status->flag |= RX_FLAG_TSFT;
1021
1022         return 0;
1023 }
1024
1025 static void ath9k_rx_skb_postprocess(struct ath_common *common,
1026                                      struct sk_buff *skb,
1027                                      struct ath_rx_status *rx_stats,
1028                                      struct ieee80211_rx_status *rxs,
1029                                      bool decrypt_error)
1030 {
1031         struct ath_hw *ah = common->ah;
1032         struct ieee80211_hdr *hdr;
1033         int hdrlen, padpos, padsize;
1034         u8 keyix;
1035         __le16 fc;
1036
1037         /* see if any padding is done by the hw and remove it */
1038         hdr = (struct ieee80211_hdr *) skb->data;
1039         hdrlen = ieee80211_get_hdrlen_from_skb(skb);
1040         fc = hdr->frame_control;
1041         padpos = ath9k_cmn_padpos(hdr->frame_control);
1042
1043         /* The MAC header is padded to have 32-bit boundary if the
1044          * packet payload is non-zero. The general calculation for
1045          * padsize would take into account odd header lengths:
1046          * padsize = (4 - padpos % 4) % 4; However, since only
1047          * even-length headers are used, padding can only be 0 or 2
1048          * bytes and we can optimize this a bit. In addition, we must
1049          * not try to remove padding from short control frames that do
1050          * not have payload. */
1051         padsize = padpos & 3;
1052         if (padsize && skb->len>=padpos+padsize+FCS_LEN) {
1053                 memmove(skb->data + padsize, skb->data, padpos);
1054                 skb_pull(skb, padsize);
1055         }
1056
1057         keyix = rx_stats->rs_keyix;
1058
1059         if (!(keyix == ATH9K_RXKEYIX_INVALID) && !decrypt_error &&
1060             ieee80211_has_protected(fc)) {
1061                 rxs->flag |= RX_FLAG_DECRYPTED;
1062         } else if (ieee80211_has_protected(fc)
1063                    && !decrypt_error && skb->len >= hdrlen + 4) {
1064                 keyix = skb->data[hdrlen + 3] >> 6;
1065
1066                 if (test_bit(keyix, common->keymap))
1067                         rxs->flag |= RX_FLAG_DECRYPTED;
1068         }
1069         if (ah->sw_mgmt_crypto &&
1070             (rxs->flag & RX_FLAG_DECRYPTED) &&
1071             ieee80211_is_mgmt(fc))
1072                 /* Use software decrypt for management frames. */
1073                 rxs->flag &= ~RX_FLAG_DECRYPTED;
1074 }
1075
1076 int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp)
1077 {
1078         struct ath_buf *bf;
1079         struct sk_buff *skb = NULL, *requeue_skb;
1080         struct ieee80211_rx_status *rxs;
1081         struct ath_hw *ah = sc->sc_ah;
1082         struct ath_common *common = ath9k_hw_common(ah);
1083         /*
1084          * The hw can techncically differ from common->hw when using ath9k
1085          * virtual wiphy so to account for that we iterate over the active
1086          * wiphys and find the appropriate wiphy and therefore hw.
1087          */
1088         struct ieee80211_hw *hw = NULL;
1089         struct ieee80211_hdr *hdr;
1090         int retval;
1091         bool decrypt_error = false;
1092         struct ath_rx_status rs;
1093         enum ath9k_rx_qtype qtype;
1094         bool edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA);
1095         int dma_type;
1096         u8 rx_status_len = ah->caps.rx_status_len;
1097         u64 tsf = 0;
1098         u32 tsf_lower = 0;
1099
1100         if (edma)
1101                 dma_type = DMA_BIDIRECTIONAL;
1102         else
1103                 dma_type = DMA_FROM_DEVICE;
1104
1105         qtype = hp ? ATH9K_RX_QUEUE_HP : ATH9K_RX_QUEUE_LP;
1106         spin_lock_bh(&sc->rx.rxbuflock);
1107
1108         tsf = ath9k_hw_gettsf64(ah);
1109         tsf_lower = tsf & 0xffffffff;
1110
1111         do {
1112                 /* If handling rx interrupt and flush is in progress => exit */
1113                 if ((sc->sc_flags & SC_OP_RXFLUSH) && (flush == 0))
1114                         break;
1115
1116                 memset(&rs, 0, sizeof(rs));
1117                 if (edma)
1118                         bf = ath_edma_get_next_rx_buf(sc, &rs, qtype);
1119                 else
1120                         bf = ath_get_next_rx_buf(sc, &rs);
1121
1122                 if (!bf)
1123                         break;
1124
1125                 skb = bf->bf_mpdu;
1126                 if (!skb)
1127                         continue;
1128
1129                 hdr = (struct ieee80211_hdr *) (skb->data + rx_status_len);
1130                 rxs =  IEEE80211_SKB_RXCB(skb);
1131
1132                 hw = ath_get_virt_hw(sc, hdr);
1133
1134                 ath_debug_stat_rx(sc, &rs);
1135
1136                 /*
1137                  * If we're asked to flush receive queue, directly
1138                  * chain it back at the queue without processing it.
1139                  */
1140                 if (flush)
1141                         goto requeue;
1142
1143                 retval = ath9k_rx_skb_preprocess(common, hw, hdr, &rs,
1144                                                  rxs, &decrypt_error);
1145                 if (retval)
1146                         goto requeue;
1147
1148                 rxs->mactime = (tsf & ~0xffffffffULL) | rs.rs_tstamp;
1149                 if (rs.rs_tstamp > tsf_lower &&
1150                     unlikely(rs.rs_tstamp - tsf_lower > 0x10000000))
1151                         rxs->mactime -= 0x100000000ULL;
1152
1153                 if (rs.rs_tstamp < tsf_lower &&
1154                     unlikely(tsf_lower - rs.rs_tstamp > 0x10000000))
1155                         rxs->mactime += 0x100000000ULL;
1156
1157                 /* Ensure we always have an skb to requeue once we are done
1158                  * processing the current buffer's skb */
1159                 requeue_skb = ath_rxbuf_alloc(common, common->rx_bufsize, GFP_ATOMIC);
1160
1161                 /* If there is no memory we ignore the current RX'd frame,
1162                  * tell hardware it can give us a new frame using the old
1163                  * skb and put it at the tail of the sc->rx.rxbuf list for
1164                  * processing. */
1165                 if (!requeue_skb)
1166                         goto requeue;
1167
1168                 /* Unmap the frame */
1169                 dma_unmap_single(sc->dev, bf->bf_buf_addr,
1170                                  common->rx_bufsize,
1171                                  dma_type);
1172
1173                 skb_put(skb, rs.rs_datalen + ah->caps.rx_status_len);
1174                 if (ah->caps.rx_status_len)
1175                         skb_pull(skb, ah->caps.rx_status_len);
1176
1177                 ath9k_rx_skb_postprocess(common, skb, &rs,
1178                                          rxs, decrypt_error);
1179
1180                 /* We will now give hardware our shiny new allocated skb */
1181                 bf->bf_mpdu = requeue_skb;
1182                 bf->bf_buf_addr = dma_map_single(sc->dev, requeue_skb->data,
1183                                                  common->rx_bufsize,
1184                                                  dma_type);
1185                 if (unlikely(dma_mapping_error(sc->dev,
1186                           bf->bf_buf_addr))) {
1187                         dev_kfree_skb_any(requeue_skb);
1188                         bf->bf_mpdu = NULL;
1189                         ath_print(common, ATH_DBG_FATAL,
1190                                   "dma_mapping_error() on RX\n");
1191                         ath_rx_send_to_mac80211(hw, sc, skb, rxs);
1192                         break;
1193                 }
1194                 bf->bf_dmacontext = bf->bf_buf_addr;
1195
1196                 /*
1197                  * change the default rx antenna if rx diversity chooses the
1198                  * other antenna 3 times in a row.
1199                  */
1200                 if (sc->rx.defant != rs.rs_antenna) {
1201                         if (++sc->rx.rxotherant >= 3)
1202                                 ath_setdefantenna(sc, rs.rs_antenna);
1203                 } else {
1204                         sc->rx.rxotherant = 0;
1205                 }
1206
1207                 if (unlikely(ath9k_check_auto_sleep(sc) ||
1208                              (sc->ps_flags & (PS_WAIT_FOR_BEACON |
1209                                               PS_WAIT_FOR_CAB |
1210                                               PS_WAIT_FOR_PSPOLL_DATA))))
1211                         ath_rx_ps(sc, skb);
1212
1213                 ath_rx_send_to_mac80211(hw, sc, skb, rxs);
1214
1215 requeue:
1216                 if (edma) {
1217                         list_add_tail(&bf->list, &sc->rx.rxbuf);
1218                         ath_rx_edma_buf_link(sc, qtype);
1219                 } else {
1220                         list_move_tail(&bf->list, &sc->rx.rxbuf);
1221                         ath_rx_buf_link(sc, bf);
1222                 }
1223         } while (1);
1224
1225         spin_unlock_bh(&sc->rx.rxbuflock);
1226
1227         return 0;
1228 }