recv.c 18 KB

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