recv.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  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 = dma_map_single(sc->dev, skb->data,
  252. sc->rx.bufsize,
  253. DMA_FROM_DEVICE);
  254. if (unlikely(dma_mapping_error(sc->dev,
  255. bf->bf_buf_addr))) {
  256. dev_kfree_skb_any(skb);
  257. bf->bf_mpdu = NULL;
  258. DPRINTF(sc, ATH_DBG_CONFIG,
  259. "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->rx.rxfilter & FIF_CONTROL)
  320. rfilt |= ATH9K_RX_FILTER_CONTROL;
  321. if (sc->sc_ah->ah_opmode == NL80211_IFTYPE_STATION ||
  322. sc->sc_ah->ah_opmode == NL80211_IFTYPE_ADHOC)
  323. rfilt |= ATH9K_RX_FILTER_BEACON;
  324. /* If in HOSTAP mode, want to enable reception of PSPOLL frames
  325. & beacon frames */
  326. if (sc->sc_ah->ah_opmode == NL80211_IFTYPE_AP)
  327. rfilt |= (ATH9K_RX_FILTER_BEACON | ATH9K_RX_FILTER_PSPOLL);
  328. return rfilt;
  329. #undef RX_FILTER_PRESERVE
  330. }
  331. int ath_startrecv(struct ath_softc *sc)
  332. {
  333. struct ath_hal *ah = sc->sc_ah;
  334. struct ath_buf *bf, *tbf;
  335. spin_lock_bh(&sc->rx.rxbuflock);
  336. if (list_empty(&sc->rx.rxbuf))
  337. goto start_recv;
  338. sc->rx.rxlink = NULL;
  339. list_for_each_entry_safe(bf, tbf, &sc->rx.rxbuf, list) {
  340. ath_rx_buf_link(sc, bf);
  341. }
  342. /* We could have deleted elements so the list may be empty now */
  343. if (list_empty(&sc->rx.rxbuf))
  344. goto start_recv;
  345. bf = list_first_entry(&sc->rx.rxbuf, struct ath_buf, list);
  346. ath9k_hw_putrxbuf(ah, bf->bf_daddr);
  347. ath9k_hw_rxena(ah);
  348. start_recv:
  349. spin_unlock_bh(&sc->rx.rxbuflock);
  350. ath_opmode_init(sc);
  351. ath9k_hw_startpcureceive(ah);
  352. return 0;
  353. }
  354. bool ath_stoprecv(struct ath_softc *sc)
  355. {
  356. struct ath_hal *ah = sc->sc_ah;
  357. bool stopped;
  358. ath9k_hw_stoppcurecv(ah);
  359. ath9k_hw_setrxfilter(ah, 0);
  360. stopped = ath9k_hw_stopdmarecv(ah);
  361. mdelay(3); /* 3ms is long enough for 1 frame */
  362. sc->rx.rxlink = NULL;
  363. return stopped;
  364. }
  365. void ath_flushrecv(struct ath_softc *sc)
  366. {
  367. spin_lock_bh(&sc->rx.rxflushlock);
  368. sc->sc_flags |= SC_OP_RXFLUSH;
  369. ath_rx_tasklet(sc, 1);
  370. sc->sc_flags &= ~SC_OP_RXFLUSH;
  371. spin_unlock_bh(&sc->rx.rxflushlock);
  372. }
  373. int ath_rx_tasklet(struct ath_softc *sc, int flush)
  374. {
  375. #define PA2DESC(_sc, _pa) \
  376. ((struct ath_desc *)((caddr_t)(_sc)->rx.rxdma.dd_desc + \
  377. ((_pa) - (_sc)->rx.rxdma.dd_desc_paddr)))
  378. struct ath_buf *bf;
  379. struct ath_desc *ds;
  380. struct sk_buff *skb = NULL, *requeue_skb;
  381. struct ieee80211_rx_status rx_status;
  382. struct ath_hal *ah = sc->sc_ah;
  383. struct ieee80211_hdr *hdr;
  384. int hdrlen, padsize, retval;
  385. bool decrypt_error = false;
  386. u8 keyix;
  387. spin_lock_bh(&sc->rx.rxbuflock);
  388. do {
  389. /* If handling rx interrupt and flush is in progress => exit */
  390. if ((sc->sc_flags & SC_OP_RXFLUSH) && (flush == 0))
  391. break;
  392. if (list_empty(&sc->rx.rxbuf)) {
  393. sc->rx.rxlink = NULL;
  394. break;
  395. }
  396. bf = list_first_entry(&sc->rx.rxbuf, struct ath_buf, list);
  397. ds = bf->bf_desc;
  398. /*
  399. * Must provide the virtual address of the current
  400. * descriptor, the physical address, and the virtual
  401. * address of the next descriptor in the h/w chain.
  402. * This allows the HAL to look ahead to see if the
  403. * hardware is done with a descriptor by checking the
  404. * done bit in the following descriptor and the address
  405. * of the current descriptor the DMA engine is working
  406. * on. All this is necessary because of our use of
  407. * a self-linked list to avoid rx overruns.
  408. */
  409. retval = ath9k_hw_rxprocdesc(ah, ds,
  410. bf->bf_daddr,
  411. PA2DESC(sc, ds->ds_link),
  412. 0);
  413. if (retval == -EINPROGRESS) {
  414. struct ath_buf *tbf;
  415. struct ath_desc *tds;
  416. if (list_is_last(&bf->list, &sc->rx.rxbuf)) {
  417. sc->rx.rxlink = NULL;
  418. break;
  419. }
  420. tbf = list_entry(bf->list.next, struct ath_buf, list);
  421. /*
  422. * On some hardware the descriptor status words could
  423. * get corrupted, including the done bit. Because of
  424. * this, check if the next descriptor's done bit is
  425. * set or not.
  426. *
  427. * If the next descriptor's done bit is set, the current
  428. * descriptor has been corrupted. Force s/w to discard
  429. * this descriptor and continue...
  430. */
  431. tds = tbf->bf_desc;
  432. retval = ath9k_hw_rxprocdesc(ah, tds, tbf->bf_daddr,
  433. PA2DESC(sc, tds->ds_link), 0);
  434. if (retval == -EINPROGRESS) {
  435. break;
  436. }
  437. }
  438. skb = bf->bf_mpdu;
  439. if (!skb)
  440. continue;
  441. /*
  442. * Synchronize the DMA transfer with CPU before
  443. * 1. accessing the frame
  444. * 2. requeueing the same buffer to h/w
  445. */
  446. dma_sync_single_for_cpu(sc->dev, bf->bf_buf_addr,
  447. sc->rx.bufsize,
  448. DMA_FROM_DEVICE);
  449. /*
  450. * If we're asked to flush receive queue, directly
  451. * chain it back at the queue without processing it.
  452. */
  453. if (flush)
  454. goto requeue;
  455. if (!ds->ds_rxstat.rs_datalen)
  456. goto requeue;
  457. /* The status portion of the descriptor could get corrupted. */
  458. if (sc->rx.bufsize < ds->ds_rxstat.rs_datalen)
  459. goto requeue;
  460. if (!ath_rx_prepare(skb, ds, &rx_status, &decrypt_error, sc))
  461. goto requeue;
  462. /* Ensure we always have an skb to requeue once we are done
  463. * processing the current buffer's skb */
  464. requeue_skb = ath_rxbuf_alloc(sc, sc->rx.bufsize);
  465. /* If there is no memory we ignore the current RX'd frame,
  466. * tell hardware it can give us a new frame using the old
  467. * skb and put it at the tail of the sc->rx.rxbuf list for
  468. * processing. */
  469. if (!requeue_skb)
  470. goto requeue;
  471. /* Unmap the frame */
  472. dma_unmap_single(sc->dev, bf->bf_buf_addr,
  473. sc->rx.bufsize,
  474. DMA_FROM_DEVICE);
  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. if (ah->sw_mgmt_crypto &&
  503. (rx_status.flag & RX_FLAG_DECRYPTED) &&
  504. ieee80211_is_mgmt(hdr->frame_control)) {
  505. /* Use software decrypt for management frames. */
  506. rx_status.flag &= ~RX_FLAG_DECRYPTED;
  507. }
  508. /* Send the frame to mac80211 */
  509. __ieee80211_rx(sc->hw, skb, &rx_status);
  510. /* We will now give hardware our shiny new allocated skb */
  511. bf->bf_mpdu = requeue_skb;
  512. bf->bf_buf_addr = dma_map_single(sc->dev, requeue_skb->data,
  513. sc->rx.bufsize,
  514. DMA_FROM_DEVICE);
  515. if (unlikely(dma_mapping_error(sc->dev,
  516. bf->bf_buf_addr))) {
  517. dev_kfree_skb_any(requeue_skb);
  518. bf->bf_mpdu = NULL;
  519. DPRINTF(sc, ATH_DBG_CONFIG,
  520. "dma_mapping_error() on RX\n");
  521. break;
  522. }
  523. bf->bf_dmacontext = bf->bf_buf_addr;
  524. /*
  525. * change the default rx antenna if rx diversity chooses the
  526. * other antenna 3 times in a row.
  527. */
  528. if (sc->rx.defant != ds->ds_rxstat.rs_antenna) {
  529. if (++sc->rx.rxotherant >= 3)
  530. ath_setdefantenna(sc, ds->ds_rxstat.rs_antenna);
  531. } else {
  532. sc->rx.rxotherant = 0;
  533. }
  534. if (ieee80211_is_beacon(hdr->frame_control) &&
  535. (sc->sc_flags & SC_OP_WAIT_FOR_BEACON)) {
  536. sc->sc_flags &= ~SC_OP_WAIT_FOR_BEACON;
  537. ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_NETWORK_SLEEP);
  538. }
  539. requeue:
  540. list_move_tail(&bf->list, &sc->rx.rxbuf);
  541. ath_rx_buf_link(sc, bf);
  542. } while (1);
  543. spin_unlock_bh(&sc->rx.rxbuflock);
  544. return 0;
  545. #undef PA2DESC
  546. }