recv.c 17 KB

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