recv.c 17 KB

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