recv.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  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. if (unlikely(pci_dma_mapping_error(sc->pdev,
  263. bf->bf_buf_addr))) {
  264. dev_kfree_skb_any(skb);
  265. bf->bf_mpdu = NULL;
  266. DPRINTF(sc, ATH_DBG_CONFIG,
  267. "pci_dma_mapping_error() on RX init\n");
  268. error = -ENOMEM;
  269. break;
  270. }
  271. bf->bf_dmacontext = bf->bf_buf_addr;
  272. }
  273. sc->sc_rxlink = NULL;
  274. } while (0);
  275. if (error)
  276. ath_rx_cleanup(sc);
  277. return error;
  278. }
  279. void ath_rx_cleanup(struct ath_softc *sc)
  280. {
  281. struct sk_buff *skb;
  282. struct ath_buf *bf;
  283. list_for_each_entry(bf, &sc->sc_rxbuf, list) {
  284. skb = bf->bf_mpdu;
  285. if (skb)
  286. dev_kfree_skb(skb);
  287. }
  288. if (sc->sc_rxdma.dd_desc_len != 0)
  289. ath_descdma_cleanup(sc, &sc->sc_rxdma, &sc->sc_rxbuf);
  290. }
  291. /*
  292. * Calculate the receive filter according to the
  293. * operating mode and state:
  294. *
  295. * o always accept unicast, broadcast, and multicast traffic
  296. * o maintain current state of phy error reception (the hal
  297. * may enable phy error frames for noise immunity work)
  298. * o probe request frames are accepted only when operating in
  299. * hostap, adhoc, or monitor modes
  300. * o enable promiscuous mode according to the interface state
  301. * o accept beacons:
  302. * - when operating in adhoc mode so the 802.11 layer creates
  303. * node table entries for peers,
  304. * - when operating in station mode for collecting rssi data when
  305. * the station is otherwise quiet, or
  306. * - when operating as a repeater so we see repeater-sta beacons
  307. * - when scanning
  308. */
  309. u32 ath_calcrxfilter(struct ath_softc *sc)
  310. {
  311. #define RX_FILTER_PRESERVE (ATH9K_RX_FILTER_PHYERR | ATH9K_RX_FILTER_PHYRADAR)
  312. u32 rfilt;
  313. rfilt = (ath9k_hw_getrxfilter(sc->sc_ah) & RX_FILTER_PRESERVE)
  314. | ATH9K_RX_FILTER_UCAST | ATH9K_RX_FILTER_BCAST
  315. | ATH9K_RX_FILTER_MCAST;
  316. /* If not a STA, enable processing of Probe Requests */
  317. if (sc->sc_ah->ah_opmode != NL80211_IFTYPE_STATION)
  318. rfilt |= ATH9K_RX_FILTER_PROBEREQ;
  319. /* Can't set HOSTAP into promiscous mode */
  320. if (((sc->sc_ah->ah_opmode != NL80211_IFTYPE_AP) &&
  321. (sc->rx_filter & FIF_PROMISC_IN_BSS)) ||
  322. (sc->sc_ah->ah_opmode == NL80211_IFTYPE_MONITOR)) {
  323. rfilt |= ATH9K_RX_FILTER_PROM;
  324. /* ??? To prevent from sending ACK */
  325. rfilt &= ~ATH9K_RX_FILTER_UCAST;
  326. }
  327. if (sc->sc_ah->ah_opmode == NL80211_IFTYPE_STATION ||
  328. sc->sc_ah->ah_opmode == NL80211_IFTYPE_ADHOC)
  329. rfilt |= ATH9K_RX_FILTER_BEACON;
  330. /* If in HOSTAP mode, want to enable reception of PSPOLL frames
  331. & beacon frames */
  332. if (sc->sc_ah->ah_opmode == NL80211_IFTYPE_AP)
  333. rfilt |= (ATH9K_RX_FILTER_BEACON | ATH9K_RX_FILTER_PSPOLL);
  334. return rfilt;
  335. #undef RX_FILTER_PRESERVE
  336. }
  337. int ath_startrecv(struct ath_softc *sc)
  338. {
  339. struct ath_hal *ah = sc->sc_ah;
  340. struct ath_buf *bf, *tbf;
  341. spin_lock_bh(&sc->sc_rxbuflock);
  342. if (list_empty(&sc->sc_rxbuf))
  343. goto start_recv;
  344. sc->sc_rxlink = NULL;
  345. list_for_each_entry_safe(bf, tbf, &sc->sc_rxbuf, list) {
  346. ath_rx_buf_link(sc, bf);
  347. }
  348. /* We could have deleted elements so the list may be empty now */
  349. if (list_empty(&sc->sc_rxbuf))
  350. goto start_recv;
  351. bf = list_first_entry(&sc->sc_rxbuf, struct ath_buf, list);
  352. ath9k_hw_putrxbuf(ah, bf->bf_daddr);
  353. ath9k_hw_rxena(ah);
  354. start_recv:
  355. spin_unlock_bh(&sc->sc_rxbuflock);
  356. ath_opmode_init(sc);
  357. ath9k_hw_startpcureceive(ah);
  358. return 0;
  359. }
  360. bool ath_stoprecv(struct ath_softc *sc)
  361. {
  362. struct ath_hal *ah = sc->sc_ah;
  363. bool stopped;
  364. ath9k_hw_stoppcurecv(ah);
  365. ath9k_hw_setrxfilter(ah, 0);
  366. stopped = ath9k_hw_stopdmarecv(ah);
  367. mdelay(3); /* 3ms is long enough for 1 frame */
  368. sc->sc_rxlink = NULL;
  369. return stopped;
  370. }
  371. void ath_flushrecv(struct ath_softc *sc)
  372. {
  373. spin_lock_bh(&sc->sc_rxflushlock);
  374. sc->sc_flags |= SC_OP_RXFLUSH;
  375. ath_rx_tasklet(sc, 1);
  376. sc->sc_flags &= ~SC_OP_RXFLUSH;
  377. spin_unlock_bh(&sc->sc_rxflushlock);
  378. }
  379. int ath_rx_tasklet(struct ath_softc *sc, int flush)
  380. {
  381. #define PA2DESC(_sc, _pa) \
  382. ((struct ath_desc *)((caddr_t)(_sc)->sc_rxdma.dd_desc + \
  383. ((_pa) - (_sc)->sc_rxdma.dd_desc_paddr)))
  384. struct ath_buf *bf;
  385. struct ath_desc *ds;
  386. struct sk_buff *skb = NULL, *requeue_skb;
  387. struct ieee80211_rx_status rx_status;
  388. struct ath_hal *ah = sc->sc_ah;
  389. struct ieee80211_hdr *hdr;
  390. int hdrlen, padsize, retval;
  391. bool decrypt_error = false;
  392. u8 keyix;
  393. spin_lock_bh(&sc->sc_rxbuflock);
  394. do {
  395. /* If handling rx interrupt and flush is in progress => exit */
  396. if ((sc->sc_flags & SC_OP_RXFLUSH) && (flush == 0))
  397. break;
  398. if (list_empty(&sc->sc_rxbuf)) {
  399. sc->sc_rxlink = NULL;
  400. break;
  401. }
  402. bf = list_first_entry(&sc->sc_rxbuf, struct ath_buf, list);
  403. ds = bf->bf_desc;
  404. /*
  405. * Must provide the virtual address of the current
  406. * descriptor, the physical address, and the virtual
  407. * address of the next descriptor in the h/w chain.
  408. * This allows the HAL to look ahead to see if the
  409. * hardware is done with a descriptor by checking the
  410. * done bit in the following descriptor and the address
  411. * of the current descriptor the DMA engine is working
  412. * on. All this is necessary because of our use of
  413. * a self-linked list to avoid rx overruns.
  414. */
  415. retval = ath9k_hw_rxprocdesc(ah, ds,
  416. bf->bf_daddr,
  417. PA2DESC(sc, ds->ds_link),
  418. 0);
  419. if (retval == -EINPROGRESS) {
  420. struct ath_buf *tbf;
  421. struct ath_desc *tds;
  422. if (list_is_last(&bf->list, &sc->sc_rxbuf)) {
  423. sc->sc_rxlink = NULL;
  424. break;
  425. }
  426. tbf = list_entry(bf->list.next, struct ath_buf, list);
  427. /*
  428. * On some hardware the descriptor status words could
  429. * get corrupted, including the done bit. Because of
  430. * this, check if the next descriptor's done bit is
  431. * set or not.
  432. *
  433. * If the next descriptor's done bit is set, the current
  434. * descriptor has been corrupted. Force s/w to discard
  435. * this descriptor and continue...
  436. */
  437. tds = tbf->bf_desc;
  438. retval = ath9k_hw_rxprocdesc(ah, tds, tbf->bf_daddr,
  439. PA2DESC(sc, tds->ds_link), 0);
  440. if (retval == -EINPROGRESS) {
  441. break;
  442. }
  443. }
  444. skb = bf->bf_mpdu;
  445. if (!skb)
  446. continue;
  447. /*
  448. * If we're asked to flush receive queue, directly
  449. * chain it back at the queue without processing it.
  450. */
  451. if (flush)
  452. goto requeue;
  453. if (!ds->ds_rxstat.rs_datalen)
  454. goto requeue;
  455. /* The status portion of the descriptor could get corrupted. */
  456. if (sc->sc_rxbufsize < ds->ds_rxstat.rs_datalen)
  457. goto requeue;
  458. if (!ath_rx_prepare(skb, ds, &rx_status, &decrypt_error, sc))
  459. goto requeue;
  460. /* Ensure we always have an skb to requeue once we are done
  461. * processing the current buffer's skb */
  462. requeue_skb = ath_rxbuf_alloc(sc, sc->sc_rxbufsize);
  463. /* If there is no memory we ignore the current RX'd frame,
  464. * tell hardware it can give us a new frame using the old
  465. * skb and put it at the tail of the sc->sc_rxbuf list for
  466. * processing. */
  467. if (!requeue_skb)
  468. goto requeue;
  469. pci_dma_sync_single_for_cpu(sc->pdev,
  470. bf->bf_buf_addr,
  471. sc->sc_rxbufsize,
  472. PCI_DMA_FROMDEVICE);
  473. pci_unmap_single(sc->pdev, bf->bf_buf_addr,
  474. sc->sc_rxbufsize,
  475. PCI_DMA_FROMDEVICE);
  476. skb_put(skb, ds->ds_rxstat.rs_datalen);
  477. skb->protocol = cpu_to_be16(ETH_P_CONTROL);
  478. /* see if any padding is done by the hw and remove it */
  479. hdr = (struct ieee80211_hdr *)skb->data;
  480. hdrlen = ieee80211_get_hdrlen_from_skb(skb);
  481. if (hdrlen & 3) {
  482. padsize = hdrlen % 4;
  483. memmove(skb->data + padsize, skb->data, hdrlen);
  484. skb_pull(skb, padsize);
  485. }
  486. keyix = ds->ds_rxstat.rs_keyix;
  487. if (!(keyix == ATH9K_RXKEYIX_INVALID) && !decrypt_error) {
  488. rx_status.flag |= RX_FLAG_DECRYPTED;
  489. } else if ((le16_to_cpu(hdr->frame_control) & IEEE80211_FCTL_PROTECTED)
  490. && !decrypt_error && skb->len >= hdrlen + 4) {
  491. keyix = skb->data[hdrlen + 3] >> 6;
  492. if (test_bit(keyix, sc->sc_keymap))
  493. rx_status.flag |= RX_FLAG_DECRYPTED;
  494. }
  495. /* Send the frame to mac80211 */
  496. __ieee80211_rx(sc->hw, skb, &rx_status);
  497. /* We will now give hardware our shiny new allocated skb */
  498. bf->bf_mpdu = requeue_skb;
  499. bf->bf_buf_addr = pci_map_single(sc->pdev, requeue_skb->data,
  500. sc->sc_rxbufsize,
  501. PCI_DMA_FROMDEVICE);
  502. if (unlikely(pci_dma_mapping_error(sc->pdev,
  503. bf->bf_buf_addr))) {
  504. dev_kfree_skb_any(requeue_skb);
  505. bf->bf_mpdu = NULL;
  506. DPRINTF(sc, ATH_DBG_CONFIG,
  507. "pci_dma_mapping_error() on RX\n");
  508. break;
  509. }
  510. bf->bf_dmacontext = bf->bf_buf_addr;
  511. /*
  512. * change the default rx antenna if rx diversity chooses the
  513. * other antenna 3 times in a row.
  514. */
  515. if (sc->sc_defant != ds->ds_rxstat.rs_antenna) {
  516. if (++sc->sc_rxotherant >= 3)
  517. ath_setdefantenna(sc, ds->ds_rxstat.rs_antenna);
  518. } else {
  519. sc->sc_rxotherant = 0;
  520. }
  521. requeue:
  522. list_move_tail(&bf->list, &sc->sc_rxbuf);
  523. ath_rx_buf_link(sc, bf);
  524. } while (1);
  525. spin_unlock_bh(&sc->sc_rxbuflock);
  526. return 0;
  527. #undef PA2DESC
  528. }