]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/net/wireless/ath9k/recv.c
ath9k: convert to struct device
[net-next-2.6.git] / drivers / net / wireless / ath9k / recv.c
CommitLineData
f078f209
LR
1/*
2 * Copyright (c) 2008 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
f078f209
LR
17#include "core.h"
18
19/*
20 * Setup and link descriptors.
21 *
22 * 11N: we can no longer afford to self link the last descriptor.
23 * MAC acknowledges BA status as long as it copies frames to host
24 * buffer (or rx fifo). This can incorrectly acknowledge packets
25 * to a sender if last desc is self-linked.
f078f209 26 */
f078f209
LR
27static void ath_rx_buf_link(struct ath_softc *sc, struct ath_buf *bf)
28{
29 struct ath_hal *ah = sc->sc_ah;
30 struct ath_desc *ds;
31 struct sk_buff *skb;
32
33 ATH_RXBUF_RESET(bf);
34
35 ds = bf->bf_desc;
be0418ad 36 ds->ds_link = 0; /* link to null */
f078f209
LR
37 ds->ds_data = bf->bf_buf_addr;
38
be0418ad 39 /* virtual addr of the beginning of the buffer. */
f078f209
LR
40 skb = bf->bf_mpdu;
41 ASSERT(skb != NULL);
42 ds->ds_vdata = skb->data;
43
b77f483f 44 /* setup rx descriptors. The rx.bufsize here tells the harware
b4b6cda2
LR
45 * how much data it can DMA to us and that we are prepared
46 * to process */
b77f483f
S
47 ath9k_hw_setuprxdesc(ah, ds,
48 sc->rx.bufsize,
f078f209
LR
49 0);
50
b77f483f 51 if (sc->rx.rxlink == NULL)
f078f209
LR
52 ath9k_hw_putrxbuf(ah, bf->bf_daddr);
53 else
b77f483f 54 *sc->rx.rxlink = bf->bf_daddr;
f078f209 55
b77f483f 56 sc->rx.rxlink = &ds->ds_link;
f078f209
LR
57 ath9k_hw_rxena(ah);
58}
59
ff37e337
S
60static void ath_setdefantenna(struct ath_softc *sc, u32 antenna)
61{
62 /* XXX block beacon interrupts */
63 ath9k_hw_setantenna(sc->sc_ah, antenna);
b77f483f
S
64 sc->rx.defant = antenna;
65 sc->rx.rxotherant = 0;
ff37e337
S
66}
67
68/*
69 * Extend 15-bit time stamp from rx descriptor to
70 * a full 64-bit TSF using the current h/w TSF.
71*/
72static u64 ath_extend_tsf(struct ath_softc *sc, u32 rstamp)
73{
74 u64 tsf;
75
76 tsf = ath9k_hw_gettsf64(sc->sc_ah);
77 if ((tsf & 0x7fff) < rstamp)
78 tsf -= 0x8000;
79 return (tsf & ~0x7fff) | rstamp;
80}
81
be0418ad 82static struct sk_buff *ath_rxbuf_alloc(struct ath_softc *sc, u32 len)
f078f209
LR
83{
84 struct sk_buff *skb;
85 u32 off;
86
87 /*
88 * Cache-line-align. This is important (for the
89 * 5210 at least) as not doing so causes bogus data
90 * in rx'd frames.
91 */
92
b4b6cda2
LR
93 /* Note: the kernel can allocate a value greater than
94 * what we ask it to give us. We really only need 4 KB as that
95 * is this hardware supports and in fact we need at least 3849
96 * as that is the MAX AMSDU size this hardware supports.
97 * Unfortunately this means we may get 8 KB here from the
98 * kernel... and that is actually what is observed on some
99 * systems :( */
f078f209
LR
100 skb = dev_alloc_skb(len + sc->sc_cachelsz - 1);
101 if (skb != NULL) {
102 off = ((unsigned long) skb->data) % sc->sc_cachelsz;
103 if (off != 0)
104 skb_reserve(skb, sc->sc_cachelsz - off);
105 } else {
106 DPRINTF(sc, ATH_DBG_FATAL,
04bd4638 107 "skbuff alloc of size %u failed\n", len);
f078f209
LR
108 return NULL;
109 }
110
111 return skb;
112}
113
f078f209 114/*
be0418ad
S
115 * For Decrypt or Demic errors, we only mark packet status here and always push
116 * up the frame up to let mac80211 handle the actual error case, be it no
117 * decryption key or real decryption error. This let us keep statistics there.
f078f209 118 */
be0418ad
S
119static int ath_rx_prepare(struct sk_buff *skb, struct ath_desc *ds,
120 struct ieee80211_rx_status *rx_status, bool *decrypt_error,
121 struct ath_softc *sc)
f078f209 122{
be0418ad 123 struct ieee80211_hdr *hdr;
be0418ad
S
124 u8 ratecode;
125 __le16 fc;
126
127 hdr = (struct ieee80211_hdr *)skb->data;
128 fc = hdr->frame_control;
129 memset(rx_status, 0, sizeof(struct ieee80211_rx_status));
130
131 if (ds->ds_rxstat.rs_more) {
132 /*
133 * Frame spans multiple descriptors; this cannot happen yet
134 * as we don't support jumbograms. If not in monitor mode,
135 * discard the frame. Enable this if you want to see
136 * error frames in Monitor mode.
137 */
d97809db 138 if (sc->sc_ah->ah_opmode != NL80211_IFTYPE_MONITOR)
be0418ad
S
139 goto rx_next;
140 } else if (ds->ds_rxstat.rs_status != 0) {
141 if (ds->ds_rxstat.rs_status & ATH9K_RXERR_CRC)
142 rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
143 if (ds->ds_rxstat.rs_status & ATH9K_RXERR_PHY)
144 goto rx_next;
f078f209 145
be0418ad
S
146 if (ds->ds_rxstat.rs_status & ATH9K_RXERR_DECRYPT) {
147 *decrypt_error = true;
148 } else if (ds->ds_rxstat.rs_status & ATH9K_RXERR_MIC) {
149 if (ieee80211_is_ctl(fc))
150 /*
151 * Sometimes, we get invalid
152 * MIC failures on valid control frames.
153 * Remove these mic errors.
154 */
155 ds->ds_rxstat.rs_status &= ~ATH9K_RXERR_MIC;
156 else
157 rx_status->flag |= RX_FLAG_MMIC_ERROR;
158 }
159 /*
160 * Reject error frames with the exception of
161 * decryption and MIC failures. For monitor mode,
162 * we also ignore the CRC error.
163 */
d97809db 164 if (sc->sc_ah->ah_opmode == NL80211_IFTYPE_MONITOR) {
be0418ad
S
165 if (ds->ds_rxstat.rs_status &
166 ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC |
167 ATH9K_RXERR_CRC))
168 goto rx_next;
169 } else {
170 if (ds->ds_rxstat.rs_status &
171 ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC)) {
172 goto rx_next;
173 }
174 }
f078f209
LR
175 }
176
be0418ad 177 ratecode = ds->ds_rxstat.rs_rate;
be0418ad 178
be0418ad 179 if (ratecode & 0x80) {
baad1d92
JM
180 /* HT rate */
181 rx_status->flag |= RX_FLAG_HT;
be0418ad 182 if (ds->ds_rxstat.rs_flags & ATH9K_RX_2040)
baad1d92 183 rx_status->flag |= RX_FLAG_40MHZ;
be0418ad 184 if (ds->ds_rxstat.rs_flags & ATH9K_RX_GI)
baad1d92
JM
185 rx_status->flag |= RX_FLAG_SHORT_GI;
186 rx_status->rate_idx = ratecode & 0x7f;
187 } else {
188 int i = 0, cur_band, n_rates;
189 struct ieee80211_hw *hw = sc->hw;
190
191 cur_band = hw->conf.channel->band;
192 n_rates = sc->sbands[cur_band].n_bitrates;
193
194 for (i = 0; i < n_rates; i++) {
195 if (sc->sbands[cur_band].bitrates[i].hw_value ==
196 ratecode) {
197 rx_status->rate_idx = i;
198 break;
199 }
200
201 if (sc->sbands[cur_band].bitrates[i].hw_value_short ==
202 ratecode) {
203 rx_status->rate_idx = i;
204 rx_status->flag |= RX_FLAG_SHORTPRE;
205 break;
206 }
207 }
be0418ad
S
208 }
209
210 rx_status->mactime = ath_extend_tsf(sc, ds->ds_rxstat.rs_tstamp);
211 rx_status->band = sc->hw->conf.channel->band;
212 rx_status->freq = sc->hw->conf.channel->center_freq;
213 rx_status->noise = sc->sc_ani.sc_noise_floor;
214 rx_status->signal = rx_status->noise + ds->ds_rxstat.rs_rssi;
be0418ad
S
215 rx_status->antenna = ds->ds_rxstat.rs_antenna;
216
217 /* at 45 you will be able to use MCS 15 reliably. A more elaborate
218 * scheme can be used here but it requires tables of SNR/throughput for
219 * each possible mode used. */
220 rx_status->qual = ds->ds_rxstat.rs_rssi * 100 / 45;
221
222 /* rssi can be more than 45 though, anything above that
223 * should be considered at 100% */
224 if (rx_status->qual > 100)
225 rx_status->qual = 100;
226
227 rx_status->flag |= RX_FLAG_TSFT;
228
229 return 1;
230rx_next:
231 return 0;
f078f209
LR
232}
233
234static void ath_opmode_init(struct ath_softc *sc)
235{
236 struct ath_hal *ah = sc->sc_ah;
237 u32 rfilt, mfilt[2];
238
239 /* configure rx filter */
240 rfilt = ath_calcrxfilter(sc);
241 ath9k_hw_setrxfilter(ah, rfilt);
242
243 /* configure bssid mask */
60b67f51 244 if (ah->ah_caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK)
f078f209
LR
245 ath9k_hw_setbssidmask(ah, sc->sc_bssidmask);
246
247 /* configure operational mode */
248 ath9k_hw_setopmode(ah);
249
250 /* Handle any link-level address change. */
251 ath9k_hw_setmac(ah, sc->sc_myaddr);
252
253 /* calculate and install multicast filter */
254 mfilt[0] = mfilt[1] = ~0;
f078f209 255 ath9k_hw_setmcastfilter(ah, mfilt[0], mfilt[1]);
f078f209
LR
256}
257
258int ath_rx_init(struct ath_softc *sc, int nbufs)
259{
260 struct sk_buff *skb;
261 struct ath_buf *bf;
262 int error = 0;
263
264 do {
b77f483f 265 spin_lock_init(&sc->rx.rxflushlock);
98deeea0 266 sc->sc_flags &= ~SC_OP_RXFLUSH;
b77f483f 267 spin_lock_init(&sc->rx.rxbuflock);
f078f209 268
b77f483f 269 sc->rx.bufsize = roundup(IEEE80211_MAX_MPDU_LEN,
f078f209
LR
270 min(sc->sc_cachelsz,
271 (u16)64));
272
04bd4638 273 DPRINTF(sc, ATH_DBG_CONFIG, "cachelsz %u rxbufsize %u\n",
b77f483f 274 sc->sc_cachelsz, sc->rx.bufsize);
f078f209
LR
275
276 /* Initialize rx descriptors */
277
b77f483f 278 error = ath_descdma_setup(sc, &sc->rx.rxdma, &sc->rx.rxbuf,
f078f209
LR
279 "rx", nbufs, 1);
280 if (error != 0) {
281 DPRINTF(sc, ATH_DBG_FATAL,
04bd4638 282 "failed to allocate rx descriptors: %d\n", error);
f078f209
LR
283 break;
284 }
285
b77f483f
S
286 list_for_each_entry(bf, &sc->rx.rxbuf, list) {
287 skb = ath_rxbuf_alloc(sc, sc->rx.bufsize);
f078f209
LR
288 if (skb == NULL) {
289 error = -ENOMEM;
290 break;
291 }
292
293 bf->bf_mpdu = skb;
f5870acb
GJ
294 bf->bf_buf_addr = pci_map_single(to_pci_dev(sc->dev),
295 skb->data,
b77f483f
S
296 sc->rx.bufsize,
297 PCI_DMA_FROMDEVICE);
f5870acb 298 if (unlikely(pci_dma_mapping_error(to_pci_dev(sc->dev),
f8316df1
LR
299 bf->bf_buf_addr))) {
300 dev_kfree_skb_any(skb);
301 bf->bf_mpdu = NULL;
302 DPRINTF(sc, ATH_DBG_CONFIG,
303 "pci_dma_mapping_error() on RX init\n");
304 error = -ENOMEM;
305 break;
306 }
927e70e9 307 bf->bf_dmacontext = bf->bf_buf_addr;
f078f209 308 }
b77f483f 309 sc->rx.rxlink = NULL;
f078f209
LR
310
311 } while (0);
312
313 if (error)
314 ath_rx_cleanup(sc);
315
316 return error;
317}
318
f078f209
LR
319void ath_rx_cleanup(struct ath_softc *sc)
320{
321 struct sk_buff *skb;
322 struct ath_buf *bf;
323
b77f483f 324 list_for_each_entry(bf, &sc->rx.rxbuf, list) {
f078f209
LR
325 skb = bf->bf_mpdu;
326 if (skb)
327 dev_kfree_skb(skb);
328 }
329
b77f483f
S
330 if (sc->rx.rxdma.dd_desc_len != 0)
331 ath_descdma_cleanup(sc, &sc->rx.rxdma, &sc->rx.rxbuf);
f078f209
LR
332}
333
334/*
335 * Calculate the receive filter according to the
336 * operating mode and state:
337 *
338 * o always accept unicast, broadcast, and multicast traffic
339 * o maintain current state of phy error reception (the hal
340 * may enable phy error frames for noise immunity work)
341 * o probe request frames are accepted only when operating in
342 * hostap, adhoc, or monitor modes
343 * o enable promiscuous mode according to the interface state
344 * o accept beacons:
345 * - when operating in adhoc mode so the 802.11 layer creates
346 * node table entries for peers,
347 * - when operating in station mode for collecting rssi data when
348 * the station is otherwise quiet, or
349 * - when operating as a repeater so we see repeater-sta beacons
350 * - when scanning
351 */
352
353u32 ath_calcrxfilter(struct ath_softc *sc)
354{
355#define RX_FILTER_PRESERVE (ATH9K_RX_FILTER_PHYERR | ATH9K_RX_FILTER_PHYRADAR)
7dcfdcd9 356
f078f209
LR
357 u32 rfilt;
358
359 rfilt = (ath9k_hw_getrxfilter(sc->sc_ah) & RX_FILTER_PRESERVE)
360 | ATH9K_RX_FILTER_UCAST | ATH9K_RX_FILTER_BCAST
361 | ATH9K_RX_FILTER_MCAST;
362
363 /* If not a STA, enable processing of Probe Requests */
d97809db 364 if (sc->sc_ah->ah_opmode != NL80211_IFTYPE_STATION)
f078f209
LR
365 rfilt |= ATH9K_RX_FILTER_PROBEREQ;
366
367 /* Can't set HOSTAP into promiscous mode */
d97809db 368 if (((sc->sc_ah->ah_opmode != NL80211_IFTYPE_AP) &&
b77f483f 369 (sc->rx.rxfilter & FIF_PROMISC_IN_BSS)) ||
d97809db 370 (sc->sc_ah->ah_opmode == NL80211_IFTYPE_MONITOR)) {
f078f209
LR
371 rfilt |= ATH9K_RX_FILTER_PROM;
372 /* ??? To prevent from sending ACK */
373 rfilt &= ~ATH9K_RX_FILTER_UCAST;
374 }
375
d97809db
CM
376 if (sc->sc_ah->ah_opmode == NL80211_IFTYPE_STATION ||
377 sc->sc_ah->ah_opmode == NL80211_IFTYPE_ADHOC)
f078f209
LR
378 rfilt |= ATH9K_RX_FILTER_BEACON;
379
380 /* If in HOSTAP mode, want to enable reception of PSPOLL frames
381 & beacon frames */
d97809db 382 if (sc->sc_ah->ah_opmode == NL80211_IFTYPE_AP)
f078f209 383 rfilt |= (ATH9K_RX_FILTER_BEACON | ATH9K_RX_FILTER_PSPOLL);
be0418ad 384
f078f209 385 return rfilt;
7dcfdcd9 386
f078f209
LR
387#undef RX_FILTER_PRESERVE
388}
389
f078f209
LR
390int ath_startrecv(struct ath_softc *sc)
391{
392 struct ath_hal *ah = sc->sc_ah;
393 struct ath_buf *bf, *tbf;
394
b77f483f
S
395 spin_lock_bh(&sc->rx.rxbuflock);
396 if (list_empty(&sc->rx.rxbuf))
f078f209
LR
397 goto start_recv;
398
b77f483f
S
399 sc->rx.rxlink = NULL;
400 list_for_each_entry_safe(bf, tbf, &sc->rx.rxbuf, list) {
f078f209
LR
401 ath_rx_buf_link(sc, bf);
402 }
403
404 /* We could have deleted elements so the list may be empty now */
b77f483f 405 if (list_empty(&sc->rx.rxbuf))
f078f209
LR
406 goto start_recv;
407
b77f483f 408 bf = list_first_entry(&sc->rx.rxbuf, struct ath_buf, list);
f078f209 409 ath9k_hw_putrxbuf(ah, bf->bf_daddr);
be0418ad 410 ath9k_hw_rxena(ah);
f078f209
LR
411
412start_recv:
b77f483f 413 spin_unlock_bh(&sc->rx.rxbuflock);
be0418ad
S
414 ath_opmode_init(sc);
415 ath9k_hw_startpcureceive(ah);
416
f078f209
LR
417 return 0;
418}
419
f078f209
LR
420bool ath_stoprecv(struct ath_softc *sc)
421{
422 struct ath_hal *ah = sc->sc_ah;
f078f209
LR
423 bool stopped;
424
be0418ad
S
425 ath9k_hw_stoppcurecv(ah);
426 ath9k_hw_setrxfilter(ah, 0);
427 stopped = ath9k_hw_stopdmarecv(ah);
428 mdelay(3); /* 3ms is long enough for 1 frame */
b77f483f 429 sc->rx.rxlink = NULL;
be0418ad 430
f078f209
LR
431 return stopped;
432}
433
f078f209
LR
434void ath_flushrecv(struct ath_softc *sc)
435{
b77f483f 436 spin_lock_bh(&sc->rx.rxflushlock);
98deeea0 437 sc->sc_flags |= SC_OP_RXFLUSH;
f078f209 438 ath_rx_tasklet(sc, 1);
98deeea0 439 sc->sc_flags &= ~SC_OP_RXFLUSH;
b77f483f 440 spin_unlock_bh(&sc->rx.rxflushlock);
f078f209
LR
441}
442
f078f209
LR
443int ath_rx_tasklet(struct ath_softc *sc, int flush)
444{
445#define PA2DESC(_sc, _pa) \
b77f483f
S
446 ((struct ath_desc *)((caddr_t)(_sc)->rx.rxdma.dd_desc + \
447 ((_pa) - (_sc)->rx.rxdma.dd_desc_paddr)))
f078f209 448
be0418ad 449 struct ath_buf *bf;
f078f209 450 struct ath_desc *ds;
cb71d9ba 451 struct sk_buff *skb = NULL, *requeue_skb;
be0418ad 452 struct ieee80211_rx_status rx_status;
f078f209 453 struct ath_hal *ah = sc->sc_ah;
be0418ad
S
454 struct ieee80211_hdr *hdr;
455 int hdrlen, padsize, retval;
456 bool decrypt_error = false;
457 u8 keyix;
458
b77f483f 459 spin_lock_bh(&sc->rx.rxbuflock);
f078f209
LR
460
461 do {
462 /* If handling rx interrupt and flush is in progress => exit */
98deeea0 463 if ((sc->sc_flags & SC_OP_RXFLUSH) && (flush == 0))
f078f209
LR
464 break;
465
b77f483f
S
466 if (list_empty(&sc->rx.rxbuf)) {
467 sc->rx.rxlink = NULL;
f078f209
LR
468 break;
469 }
470
b77f483f 471 bf = list_first_entry(&sc->rx.rxbuf, struct ath_buf, list);
f078f209 472 ds = bf->bf_desc;
f078f209
LR
473
474 /*
475 * Must provide the virtual address of the current
476 * descriptor, the physical address, and the virtual
477 * address of the next descriptor in the h/w chain.
478 * This allows the HAL to look ahead to see if the
479 * hardware is done with a descriptor by checking the
480 * done bit in the following descriptor and the address
481 * of the current descriptor the DMA engine is working
482 * on. All this is necessary because of our use of
483 * a self-linked list to avoid rx overruns.
484 */
be0418ad 485 retval = ath9k_hw_rxprocdesc(ah, ds,
f078f209
LR
486 bf->bf_daddr,
487 PA2DESC(sc, ds->ds_link),
488 0);
489 if (retval == -EINPROGRESS) {
490 struct ath_buf *tbf;
491 struct ath_desc *tds;
492
b77f483f
S
493 if (list_is_last(&bf->list, &sc->rx.rxbuf)) {
494 sc->rx.rxlink = NULL;
f078f209
LR
495 break;
496 }
497
498 tbf = list_entry(bf->list.next, struct ath_buf, list);
499
500 /*
501 * On some hardware the descriptor status words could
502 * get corrupted, including the done bit. Because of
503 * this, check if the next descriptor's done bit is
504 * set or not.
505 *
506 * If the next descriptor's done bit is set, the current
507 * descriptor has been corrupted. Force s/w to discard
508 * this descriptor and continue...
509 */
510
511 tds = tbf->bf_desc;
be0418ad
S
512 retval = ath9k_hw_rxprocdesc(ah, tds, tbf->bf_daddr,
513 PA2DESC(sc, tds->ds_link), 0);
f078f209 514 if (retval == -EINPROGRESS) {
f078f209
LR
515 break;
516 }
517 }
518
f078f209 519 skb = bf->bf_mpdu;
be0418ad 520 if (!skb)
f078f209 521 continue;
f078f209 522
9bf9fca8
VT
523 /*
524 * Synchronize the DMA transfer with CPU before
525 * 1. accessing the frame
526 * 2. requeueing the same buffer to h/w
527 */
f5870acb
GJ
528 pci_dma_sync_single_for_cpu(to_pci_dev(sc->dev),
529 bf->bf_buf_addr,
9bf9fca8
VT
530 sc->rx.bufsize,
531 PCI_DMA_FROMDEVICE);
532
f078f209 533 /*
be0418ad
S
534 * If we're asked to flush receive queue, directly
535 * chain it back at the queue without processing it.
f078f209 536 */
be0418ad 537 if (flush)
cb71d9ba 538 goto requeue;
f078f209 539
be0418ad 540 if (!ds->ds_rxstat.rs_datalen)
cb71d9ba 541 goto requeue;
f078f209 542
be0418ad 543 /* The status portion of the descriptor could get corrupted. */
b77f483f 544 if (sc->rx.bufsize < ds->ds_rxstat.rs_datalen)
cb71d9ba 545 goto requeue;
f078f209 546
be0418ad 547 if (!ath_rx_prepare(skb, ds, &rx_status, &decrypt_error, sc))
cb71d9ba
LR
548 goto requeue;
549
550 /* Ensure we always have an skb to requeue once we are done
551 * processing the current buffer's skb */
b77f483f 552 requeue_skb = ath_rxbuf_alloc(sc, sc->rx.bufsize);
cb71d9ba
LR
553
554 /* If there is no memory we ignore the current RX'd frame,
555 * tell hardware it can give us a new frame using the old
b77f483f 556 * skb and put it at the tail of the sc->rx.rxbuf list for
cb71d9ba
LR
557 * processing. */
558 if (!requeue_skb)
559 goto requeue;
f078f209 560
9bf9fca8 561 /* Unmap the frame */
f5870acb 562 pci_unmap_single(to_pci_dev(sc->dev), bf->bf_buf_addr,
b77f483f 563 sc->rx.bufsize,
f078f209
LR
564 PCI_DMA_FROMDEVICE);
565
be0418ad
S
566 skb_put(skb, ds->ds_rxstat.rs_datalen);
567 skb->protocol = cpu_to_be16(ETH_P_CONTROL);
568
569 /* see if any padding is done by the hw and remove it */
570 hdr = (struct ieee80211_hdr *)skb->data;
571 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
572
9c5f89b3
JM
573 /* The MAC header is padded to have 32-bit boundary if the
574 * packet payload is non-zero. The general calculation for
575 * padsize would take into account odd header lengths:
576 * padsize = (4 - hdrlen % 4) % 4; However, since only
577 * even-length headers are used, padding can only be 0 or 2
578 * bytes and we can optimize this a bit. In addition, we must
579 * not try to remove padding from short control frames that do
580 * not have payload. */
581 padsize = hdrlen & 3;
582 if (padsize && hdrlen >= 24) {
be0418ad
S
583 memmove(skb->data + padsize, skb->data, hdrlen);
584 skb_pull(skb, padsize);
f078f209
LR
585 }
586
be0418ad 587 keyix = ds->ds_rxstat.rs_keyix;
f078f209 588
be0418ad
S
589 if (!(keyix == ATH9K_RXKEYIX_INVALID) && !decrypt_error) {
590 rx_status.flag |= RX_FLAG_DECRYPTED;
591 } else if ((le16_to_cpu(hdr->frame_control) & IEEE80211_FCTL_PROTECTED)
592 && !decrypt_error && skb->len >= hdrlen + 4) {
593 keyix = skb->data[hdrlen + 3] >> 6;
594
595 if (test_bit(keyix, sc->sc_keymap))
596 rx_status.flag |= RX_FLAG_DECRYPTED;
597 }
0ced0e17
JM
598 if (ah->sw_mgmt_crypto &&
599 (rx_status.flag & RX_FLAG_DECRYPTED) &&
600 ieee80211_is_mgmt(hdr->frame_control)) {
601 /* Use software decrypt for management frames. */
602 rx_status.flag &= ~RX_FLAG_DECRYPTED;
603 }
be0418ad
S
604
605 /* Send the frame to mac80211 */
606 __ieee80211_rx(sc->hw, skb, &rx_status);
cb71d9ba
LR
607
608 /* We will now give hardware our shiny new allocated skb */
609 bf->bf_mpdu = requeue_skb;
f5870acb
GJ
610 bf->bf_buf_addr = pci_map_single(to_pci_dev(sc->dev),
611 requeue_skb->data,
b77f483f 612 sc->rx.bufsize,
cb71d9ba 613 PCI_DMA_FROMDEVICE);
f5870acb 614 if (unlikely(pci_dma_mapping_error(to_pci_dev(sc->dev),
f8316df1
LR
615 bf->bf_buf_addr))) {
616 dev_kfree_skb_any(requeue_skb);
617 bf->bf_mpdu = NULL;
618 DPRINTF(sc, ATH_DBG_CONFIG,
619 "pci_dma_mapping_error() on RX\n");
620 break;
621 }
cb71d9ba 622 bf->bf_dmacontext = bf->bf_buf_addr;
f078f209
LR
623
624 /*
625 * change the default rx antenna if rx diversity chooses the
626 * other antenna 3 times in a row.
627 */
b77f483f
S
628 if (sc->rx.defant != ds->ds_rxstat.rs_antenna) {
629 if (++sc->rx.rxotherant >= 3)
be0418ad 630 ath_setdefantenna(sc, ds->ds_rxstat.rs_antenna);
f078f209 631 } else {
b77f483f 632 sc->rx.rxotherant = 0;
f078f209 633 }
cb71d9ba 634requeue:
b77f483f 635 list_move_tail(&bf->list, &sc->rx.rxbuf);
cb71d9ba 636 ath_rx_buf_link(sc, bf);
be0418ad
S
637 } while (1);
638
b77f483f 639 spin_unlock_bh(&sc->rx.rxbuflock);
f078f209
LR
640
641 return 0;
642#undef PA2DESC
643}