recv.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  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. #include "core.h"
  17. /*
  18. * Setup and link descriptors.
  19. *
  20. * 11N: we can no longer afford to self link the last descriptor.
  21. * MAC acknowledges BA status as long as it copies frames to host
  22. * buffer (or rx fifo). This can incorrectly acknowledge packets
  23. * to a sender if last desc is self-linked.
  24. */
  25. static void ath_rx_buf_link(struct ath_softc *sc, struct ath_buf *bf)
  26. {
  27. struct ath_hal *ah = sc->sc_ah;
  28. struct ath_desc *ds;
  29. struct sk_buff *skb;
  30. ATH_RXBUF_RESET(bf);
  31. ds = bf->bf_desc;
  32. ds->ds_link = 0; /* link to null */
  33. ds->ds_data = bf->bf_buf_addr;
  34. /* virtual addr of the beginning of the buffer. */
  35. skb = bf->bf_mpdu;
  36. ASSERT(skb != NULL);
  37. ds->ds_vdata = skb->data;
  38. /* setup rx descriptors */
  39. ath9k_hw_setuprxdesc(ah, ds,
  40. skb_tailroom(skb), /* buffer size */
  41. 0);
  42. if (sc->sc_rxlink == NULL)
  43. ath9k_hw_putrxbuf(ah, bf->bf_daddr);
  44. else
  45. *sc->sc_rxlink = bf->bf_daddr;
  46. sc->sc_rxlink = &ds->ds_link;
  47. ath9k_hw_rxena(ah);
  48. }
  49. static void ath_setdefantenna(struct ath_softc *sc, u32 antenna)
  50. {
  51. /* XXX block beacon interrupts */
  52. ath9k_hw_setantenna(sc->sc_ah, antenna);
  53. sc->sc_defant = antenna;
  54. sc->sc_rxotherant = 0;
  55. }
  56. /*
  57. * Extend 15-bit time stamp from rx descriptor to
  58. * a full 64-bit TSF using the current h/w TSF.
  59. */
  60. static u64 ath_extend_tsf(struct ath_softc *sc, u32 rstamp)
  61. {
  62. u64 tsf;
  63. tsf = ath9k_hw_gettsf64(sc->sc_ah);
  64. if ((tsf & 0x7fff) < rstamp)
  65. tsf -= 0x8000;
  66. return (tsf & ~0x7fff) | rstamp;
  67. }
  68. static struct sk_buff *ath_rxbuf_alloc(struct ath_softc *sc, u32 len)
  69. {
  70. struct sk_buff *skb;
  71. u32 off;
  72. /*
  73. * Cache-line-align. This is important (for the
  74. * 5210 at least) as not doing so causes bogus data
  75. * in rx'd frames.
  76. */
  77. skb = dev_alloc_skb(len + sc->sc_cachelsz - 1);
  78. if (skb != NULL) {
  79. off = ((unsigned long) skb->data) % sc->sc_cachelsz;
  80. if (off != 0)
  81. skb_reserve(skb, sc->sc_cachelsz - off);
  82. } else {
  83. DPRINTF(sc, ATH_DBG_FATAL,
  84. "%s: skbuff alloc of size %u failed\n",
  85. __func__, len);
  86. return NULL;
  87. }
  88. return skb;
  89. }
  90. static int ath_rate2idx(struct ath_softc *sc, int rate)
  91. {
  92. int i = 0, cur_band, n_rates;
  93. struct ieee80211_hw *hw = sc->hw;
  94. cur_band = hw->conf.channel->band;
  95. n_rates = sc->sbands[cur_band].n_bitrates;
  96. for (i = 0; i < n_rates; i++) {
  97. if (sc->sbands[cur_band].bitrates[i].bitrate == rate)
  98. break;
  99. }
  100. /*
  101. * NB:mac80211 validates rx rate index against the supported legacy rate
  102. * index only (should be done against ht rates also), return the highest
  103. * legacy rate index for rx rate which does not match any one of the
  104. * supported basic and extended rates to make mac80211 happy.
  105. * The following hack will be cleaned up once the issue with
  106. * the rx rate index validation in mac80211 is fixed.
  107. */
  108. if (i == n_rates)
  109. return n_rates - 1;
  110. return i;
  111. }
  112. /*
  113. * For Decrypt or Demic errors, we only mark packet status here and always push
  114. * up the frame up to let mac80211 handle the actual error case, be it no
  115. * decryption key or real decryption error. This let us keep statistics there.
  116. */
  117. static int ath_rx_prepare(struct sk_buff *skb, struct ath_desc *ds,
  118. struct ieee80211_rx_status *rx_status, bool *decrypt_error,
  119. struct ath_softc *sc)
  120. {
  121. struct ath_rate_table *rate_table = sc->hw_rate_table[sc->sc_curmode];
  122. struct ieee80211_hdr *hdr;
  123. int ratekbps, rix;
  124. u8 ratecode;
  125. __le16 fc;
  126. hdr = (struct ieee80211_hdr *)skb->data;
  127. fc = hdr->frame_control;
  128. memset(rx_status, 0, sizeof(struct ieee80211_rx_status));
  129. if (ds->ds_rxstat.rs_more) {
  130. /*
  131. * Frame spans multiple descriptors; this cannot happen yet
  132. * as we don't support jumbograms. If not in monitor mode,
  133. * discard the frame. Enable this if you want to see
  134. * error frames in Monitor mode.
  135. */
  136. if (sc->sc_ah->ah_opmode != ATH9K_M_MONITOR)
  137. goto rx_next;
  138. } else if (ds->ds_rxstat.rs_status != 0) {
  139. if (ds->ds_rxstat.rs_status & ATH9K_RXERR_CRC)
  140. rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
  141. if (ds->ds_rxstat.rs_status & ATH9K_RXERR_PHY)
  142. goto rx_next;
  143. if (ds->ds_rxstat.rs_status & ATH9K_RXERR_DECRYPT) {
  144. *decrypt_error = true;
  145. } else if (ds->ds_rxstat.rs_status & ATH9K_RXERR_MIC) {
  146. if (ieee80211_is_ctl(fc))
  147. /*
  148. * Sometimes, we get invalid
  149. * MIC failures on valid control frames.
  150. * Remove these mic errors.
  151. */
  152. ds->ds_rxstat.rs_status &= ~ATH9K_RXERR_MIC;
  153. else
  154. rx_status->flag |= RX_FLAG_MMIC_ERROR;
  155. }
  156. /*
  157. * Reject error frames with the exception of
  158. * decryption and MIC failures. For monitor mode,
  159. * we also ignore the CRC error.
  160. */
  161. if (sc->sc_ah->ah_opmode == ATH9K_M_MONITOR) {
  162. if (ds->ds_rxstat.rs_status &
  163. ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC |
  164. ATH9K_RXERR_CRC))
  165. goto rx_next;
  166. } else {
  167. if (ds->ds_rxstat.rs_status &
  168. ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC)) {
  169. goto rx_next;
  170. }
  171. }
  172. }
  173. ratecode = ds->ds_rxstat.rs_rate;
  174. rix = rate_table->rateCodeToIndex[ratecode];
  175. ratekbps = rate_table->info[rix].ratekbps;
  176. /* HT rate */
  177. if (ratecode & 0x80) {
  178. if (ds->ds_rxstat.rs_flags & ATH9K_RX_2040)
  179. ratekbps = (ratekbps * 27) / 13;
  180. if (ds->ds_rxstat.rs_flags & ATH9K_RX_GI)
  181. ratekbps = (ratekbps * 10) / 9;
  182. }
  183. rx_status->mactime = ath_extend_tsf(sc, ds->ds_rxstat.rs_tstamp);
  184. rx_status->band = sc->hw->conf.channel->band;
  185. rx_status->freq = sc->hw->conf.channel->center_freq;
  186. rx_status->noise = sc->sc_ani.sc_noise_floor;
  187. rx_status->signal = rx_status->noise + ds->ds_rxstat.rs_rssi;
  188. rx_status->rate_idx = ath_rate2idx(sc, (ratekbps / 100));
  189. rx_status->antenna = ds->ds_rxstat.rs_antenna;
  190. /* at 45 you will be able to use MCS 15 reliably. A more elaborate
  191. * scheme can be used here but it requires tables of SNR/throughput for
  192. * each possible mode used. */
  193. rx_status->qual = ds->ds_rxstat.rs_rssi * 100 / 45;
  194. /* rssi can be more than 45 though, anything above that
  195. * should be considered at 100% */
  196. if (rx_status->qual > 100)
  197. rx_status->qual = 100;
  198. rx_status->flag |= RX_FLAG_TSFT;
  199. return 1;
  200. rx_next:
  201. return 0;
  202. }
  203. static void ath_opmode_init(struct ath_softc *sc)
  204. {
  205. struct ath_hal *ah = sc->sc_ah;
  206. u32 rfilt, mfilt[2];
  207. /* configure rx filter */
  208. rfilt = ath_calcrxfilter(sc);
  209. ath9k_hw_setrxfilter(ah, rfilt);
  210. /* configure bssid mask */
  211. if (ah->ah_caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK)
  212. ath9k_hw_setbssidmask(ah, sc->sc_bssidmask);
  213. /* configure operational mode */
  214. ath9k_hw_setopmode(ah);
  215. /* Handle any link-level address change. */
  216. ath9k_hw_setmac(ah, sc->sc_myaddr);
  217. /* calculate and install multicast filter */
  218. mfilt[0] = mfilt[1] = ~0;
  219. ath9k_hw_setmcastfilter(ah, mfilt[0], mfilt[1]);
  220. DPRINTF(sc, ATH_DBG_CONFIG ,
  221. "%s: RX filter 0x%x, MC filter %08x:%08x\n",
  222. __func__, rfilt, mfilt[0], mfilt[1]);
  223. }
  224. int ath_rx_init(struct ath_softc *sc, int nbufs)
  225. {
  226. struct sk_buff *skb;
  227. struct ath_buf *bf;
  228. int error = 0;
  229. do {
  230. spin_lock_init(&sc->sc_rxflushlock);
  231. sc->sc_flags &= ~SC_OP_RXFLUSH;
  232. spin_lock_init(&sc->sc_rxbuflock);
  233. sc->sc_rxbufsize = roundup(IEEE80211_MAX_MPDU_LEN,
  234. min(sc->sc_cachelsz,
  235. (u16)64));
  236. DPRINTF(sc, ATH_DBG_CONFIG, "%s: cachelsz %u rxbufsize %u\n",
  237. __func__, sc->sc_cachelsz, sc->sc_rxbufsize);
  238. /* Initialize rx descriptors */
  239. error = ath_descdma_setup(sc, &sc->sc_rxdma, &sc->sc_rxbuf,
  240. "rx", nbufs, 1);
  241. if (error != 0) {
  242. DPRINTF(sc, ATH_DBG_FATAL,
  243. "%s: failed to allocate rx descriptors: %d\n",
  244. __func__, error);
  245. break;
  246. }
  247. list_for_each_entry(bf, &sc->sc_rxbuf, list) {
  248. skb = ath_rxbuf_alloc(sc, sc->sc_rxbufsize);
  249. if (skb == NULL) {
  250. error = -ENOMEM;
  251. break;
  252. }
  253. bf->bf_mpdu = skb;
  254. bf->bf_buf_addr = pci_map_single(sc->pdev, skb->data,
  255. skb_end_pointer(skb) - skb->head,
  256. PCI_DMA_FROMDEVICE);
  257. bf->bf_dmacontext = bf->bf_buf_addr;
  258. }
  259. sc->sc_rxlink = NULL;
  260. } while (0);
  261. if (error)
  262. ath_rx_cleanup(sc);
  263. return error;
  264. }
  265. void ath_rx_cleanup(struct ath_softc *sc)
  266. {
  267. struct sk_buff *skb;
  268. struct ath_buf *bf;
  269. list_for_each_entry(bf, &sc->sc_rxbuf, list) {
  270. skb = bf->bf_mpdu;
  271. if (skb)
  272. dev_kfree_skb(skb);
  273. }
  274. if (sc->sc_rxdma.dd_desc_len != 0)
  275. ath_descdma_cleanup(sc, &sc->sc_rxdma, &sc->sc_rxbuf);
  276. }
  277. /*
  278. * Calculate the receive filter according to the
  279. * operating mode and state:
  280. *
  281. * o always accept unicast, broadcast, and multicast traffic
  282. * o maintain current state of phy error reception (the hal
  283. * may enable phy error frames for noise immunity work)
  284. * o probe request frames are accepted only when operating in
  285. * hostap, adhoc, or monitor modes
  286. * o enable promiscuous mode according to the interface state
  287. * o accept beacons:
  288. * - when operating in adhoc mode so the 802.11 layer creates
  289. * node table entries for peers,
  290. * - when operating in station mode for collecting rssi data when
  291. * the station is otherwise quiet, or
  292. * - when operating as a repeater so we see repeater-sta beacons
  293. * - when scanning
  294. */
  295. u32 ath_calcrxfilter(struct ath_softc *sc)
  296. {
  297. #define RX_FILTER_PRESERVE (ATH9K_RX_FILTER_PHYERR | ATH9K_RX_FILTER_PHYRADAR)
  298. u32 rfilt;
  299. rfilt = (ath9k_hw_getrxfilter(sc->sc_ah) & RX_FILTER_PRESERVE)
  300. | ATH9K_RX_FILTER_UCAST | ATH9K_RX_FILTER_BCAST
  301. | ATH9K_RX_FILTER_MCAST;
  302. /* If not a STA, enable processing of Probe Requests */
  303. if (sc->sc_ah->ah_opmode != ATH9K_M_STA)
  304. rfilt |= ATH9K_RX_FILTER_PROBEREQ;
  305. /* Can't set HOSTAP into promiscous mode */
  306. if (((sc->sc_ah->ah_opmode != ATH9K_M_HOSTAP) &&
  307. (sc->rx_filter & FIF_PROMISC_IN_BSS)) ||
  308. (sc->sc_ah->ah_opmode == ATH9K_M_MONITOR)) {
  309. rfilt |= ATH9K_RX_FILTER_PROM;
  310. /* ??? To prevent from sending ACK */
  311. rfilt &= ~ATH9K_RX_FILTER_UCAST;
  312. }
  313. if (sc->sc_ah->ah_opmode == ATH9K_M_STA ||
  314. sc->sc_ah->ah_opmode == ATH9K_M_IBSS)
  315. rfilt |= ATH9K_RX_FILTER_BEACON;
  316. /* If in HOSTAP mode, want to enable reception of PSPOLL frames
  317. & beacon frames */
  318. if (sc->sc_ah->ah_opmode == ATH9K_M_HOSTAP)
  319. rfilt |= (ATH9K_RX_FILTER_BEACON | ATH9K_RX_FILTER_PSPOLL);
  320. return rfilt;
  321. #undef RX_FILTER_PRESERVE
  322. }
  323. int ath_startrecv(struct ath_softc *sc)
  324. {
  325. struct ath_hal *ah = sc->sc_ah;
  326. struct ath_buf *bf, *tbf;
  327. spin_lock_bh(&sc->sc_rxbuflock);
  328. if (list_empty(&sc->sc_rxbuf))
  329. goto start_recv;
  330. sc->sc_rxlink = NULL;
  331. list_for_each_entry_safe(bf, tbf, &sc->sc_rxbuf, list) {
  332. ath_rx_buf_link(sc, bf);
  333. }
  334. /* We could have deleted elements so the list may be empty now */
  335. if (list_empty(&sc->sc_rxbuf))
  336. goto start_recv;
  337. bf = list_first_entry(&sc->sc_rxbuf, struct ath_buf, list);
  338. ath9k_hw_putrxbuf(ah, bf->bf_daddr);
  339. ath9k_hw_rxena(ah);
  340. start_recv:
  341. spin_unlock_bh(&sc->sc_rxbuflock);
  342. ath_opmode_init(sc);
  343. ath9k_hw_startpcureceive(ah);
  344. return 0;
  345. }
  346. bool ath_stoprecv(struct ath_softc *sc)
  347. {
  348. struct ath_hal *ah = sc->sc_ah;
  349. bool stopped;
  350. ath9k_hw_stoppcurecv(ah);
  351. ath9k_hw_setrxfilter(ah, 0);
  352. stopped = ath9k_hw_stopdmarecv(ah);
  353. mdelay(3); /* 3ms is long enough for 1 frame */
  354. sc->sc_rxlink = NULL;
  355. return stopped;
  356. }
  357. void ath_flushrecv(struct ath_softc *sc)
  358. {
  359. spin_lock_bh(&sc->sc_rxflushlock);
  360. sc->sc_flags |= SC_OP_RXFLUSH;
  361. ath_rx_tasklet(sc, 1);
  362. sc->sc_flags &= ~SC_OP_RXFLUSH;
  363. spin_unlock_bh(&sc->sc_rxflushlock);
  364. }
  365. int ath_rx_tasklet(struct ath_softc *sc, int flush)
  366. {
  367. #define PA2DESC(_sc, _pa) \
  368. ((struct ath_desc *)((caddr_t)(_sc)->sc_rxdma.dd_desc + \
  369. ((_pa) - (_sc)->sc_rxdma.dd_desc_paddr)))
  370. struct ath_buf *bf;
  371. struct ath_desc *ds;
  372. struct sk_buff *skb = NULL, *requeue_skb;
  373. struct ieee80211_rx_status rx_status;
  374. struct ath_hal *ah = sc->sc_ah;
  375. struct ieee80211_hdr *hdr;
  376. int hdrlen, padsize, retval;
  377. bool decrypt_error = false;
  378. u8 keyix;
  379. spin_lock_bh(&sc->sc_rxbuflock);
  380. do {
  381. /* If handling rx interrupt and flush is in progress => exit */
  382. if ((sc->sc_flags & SC_OP_RXFLUSH) && (flush == 0))
  383. break;
  384. if (list_empty(&sc->sc_rxbuf)) {
  385. sc->sc_rxlink = NULL;
  386. break;
  387. }
  388. bf = list_first_entry(&sc->sc_rxbuf, struct ath_buf, list);
  389. ds = bf->bf_desc;
  390. /*
  391. * Must provide the virtual address of the current
  392. * descriptor, the physical address, and the virtual
  393. * address of the next descriptor in the h/w chain.
  394. * This allows the HAL to look ahead to see if the
  395. * hardware is done with a descriptor by checking the
  396. * done bit in the following descriptor and the address
  397. * of the current descriptor the DMA engine is working
  398. * on. All this is necessary because of our use of
  399. * a self-linked list to avoid rx overruns.
  400. */
  401. retval = ath9k_hw_rxprocdesc(ah, ds,
  402. bf->bf_daddr,
  403. PA2DESC(sc, ds->ds_link),
  404. 0);
  405. if (retval == -EINPROGRESS) {
  406. struct ath_buf *tbf;
  407. struct ath_desc *tds;
  408. if (list_is_last(&bf->list, &sc->sc_rxbuf)) {
  409. sc->sc_rxlink = NULL;
  410. break;
  411. }
  412. tbf = list_entry(bf->list.next, struct ath_buf, list);
  413. /*
  414. * On some hardware the descriptor status words could
  415. * get corrupted, including the done bit. Because of
  416. * this, check if the next descriptor's done bit is
  417. * set or not.
  418. *
  419. * If the next descriptor's done bit is set, the current
  420. * descriptor has been corrupted. Force s/w to discard
  421. * this descriptor and continue...
  422. */
  423. tds = tbf->bf_desc;
  424. retval = ath9k_hw_rxprocdesc(ah, tds, tbf->bf_daddr,
  425. PA2DESC(sc, tds->ds_link), 0);
  426. if (retval == -EINPROGRESS) {
  427. break;
  428. }
  429. }
  430. skb = bf->bf_mpdu;
  431. if (!skb)
  432. continue;
  433. /*
  434. * If we're asked to flush receive queue, directly
  435. * chain it back at the queue without processing it.
  436. */
  437. if (flush)
  438. goto requeue;
  439. if (!ds->ds_rxstat.rs_datalen)
  440. goto requeue;
  441. /* The status portion of the descriptor could get corrupted. */
  442. if (sc->sc_rxbufsize < ds->ds_rxstat.rs_datalen)
  443. goto requeue;
  444. if (!ath_rx_prepare(skb, ds, &rx_status, &decrypt_error, sc))
  445. goto requeue;
  446. /* Ensure we always have an skb to requeue once we are done
  447. * processing the current buffer's skb */
  448. requeue_skb = ath_rxbuf_alloc(sc, sc->sc_rxbufsize);
  449. /* If there is no memory we ignore the current RX'd frame,
  450. * tell hardware it can give us a new frame using the old
  451. * skb and put it at the tail of the sc->sc_rxbuf list for
  452. * processing. */
  453. if (!requeue_skb)
  454. goto requeue;
  455. /* Sync and unmap the frame */
  456. pci_dma_sync_single_for_cpu(sc->pdev, bf->bf_buf_addr,
  457. skb_tailroom(skb),
  458. PCI_DMA_FROMDEVICE);
  459. pci_unmap_single(sc->pdev, bf->bf_buf_addr,
  460. sc->sc_rxbufsize,
  461. PCI_DMA_FROMDEVICE);
  462. skb_put(skb, ds->ds_rxstat.rs_datalen);
  463. skb->protocol = cpu_to_be16(ETH_P_CONTROL);
  464. /* see if any padding is done by the hw and remove it */
  465. hdr = (struct ieee80211_hdr *)skb->data;
  466. hdrlen = ieee80211_get_hdrlen_from_skb(skb);
  467. if (hdrlen & 3) {
  468. padsize = hdrlen % 4;
  469. memmove(skb->data + padsize, skb->data, hdrlen);
  470. skb_pull(skb, padsize);
  471. }
  472. keyix = ds->ds_rxstat.rs_keyix;
  473. if (!(keyix == ATH9K_RXKEYIX_INVALID) && !decrypt_error) {
  474. rx_status.flag |= RX_FLAG_DECRYPTED;
  475. } else if ((le16_to_cpu(hdr->frame_control) & IEEE80211_FCTL_PROTECTED)
  476. && !decrypt_error && skb->len >= hdrlen + 4) {
  477. keyix = skb->data[hdrlen + 3] >> 6;
  478. if (test_bit(keyix, sc->sc_keymap))
  479. rx_status.flag |= RX_FLAG_DECRYPTED;
  480. }
  481. /* Send the frame to mac80211 */
  482. __ieee80211_rx(sc->hw, skb, &rx_status);
  483. /* We will now give hardware our shiny new allocated skb */
  484. bf->bf_mpdu = requeue_skb;
  485. bf->bf_buf_addr = pci_map_single(sc->pdev, requeue_skb->data,
  486. sc->sc_rxbufsize,
  487. PCI_DMA_FROMDEVICE);
  488. bf->bf_dmacontext = bf->bf_buf_addr;
  489. /*
  490. * change the default rx antenna if rx diversity chooses the
  491. * other antenna 3 times in a row.
  492. */
  493. if (sc->sc_defant != ds->ds_rxstat.rs_antenna) {
  494. if (++sc->sc_rxotherant >= 3)
  495. ath_setdefantenna(sc, ds->ds_rxstat.rs_antenna);
  496. } else {
  497. sc->sc_rxotherant = 0;
  498. }
  499. requeue:
  500. list_move_tail(&bf->list, &sc->sc_rxbuf);
  501. ath_rx_buf_link(sc, bf);
  502. } while (1);
  503. spin_unlock_bh(&sc->sc_rxbuflock);
  504. return 0;
  505. #undef PA2DESC
  506. }