recv.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753
  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. /*
  17. * Implementation of receive path.
  18. */
  19. #include "core.h"
  20. /*
  21. * Setup and link descriptors.
  22. *
  23. * 11N: we can no longer afford to self link the last descriptor.
  24. * MAC acknowledges BA status as long as it copies frames to host
  25. * buffer (or rx fifo). This can incorrectly acknowledge packets
  26. * to a sender if last desc is self-linked.
  27. *
  28. * NOTE: Caller should hold the rxbuf lock.
  29. */
  30. static void ath_rx_buf_link(struct ath_softc *sc, struct ath_buf *bf)
  31. {
  32. struct ath_hal *ah = sc->sc_ah;
  33. struct ath_desc *ds;
  34. struct sk_buff *skb;
  35. ATH_RXBUF_RESET(bf);
  36. ds = bf->bf_desc;
  37. ds->ds_link = 0; /* link to null */
  38. ds->ds_data = bf->bf_buf_addr;
  39. /* XXX For RADAR?
  40. * virtual addr of the beginning of the buffer. */
  41. skb = bf->bf_mpdu;
  42. ASSERT(skb != NULL);
  43. ds->ds_vdata = skb->data;
  44. /* setup rx descriptors */
  45. ath9k_hw_setuprxdesc(ah,
  46. ds,
  47. skb_tailroom(skb), /* buffer size */
  48. 0);
  49. if (sc->sc_rxlink == NULL)
  50. ath9k_hw_putrxbuf(ah, bf->bf_daddr);
  51. else
  52. *sc->sc_rxlink = bf->bf_daddr;
  53. sc->sc_rxlink = &ds->ds_link;
  54. ath9k_hw_rxena(ah);
  55. }
  56. static struct sk_buff *ath_rxbuf_alloc(struct ath_softc *sc,
  57. u32 len)
  58. {
  59. struct sk_buff *skb;
  60. u32 off;
  61. /*
  62. * Cache-line-align. This is important (for the
  63. * 5210 at least) as not doing so causes bogus data
  64. * in rx'd frames.
  65. */
  66. skb = dev_alloc_skb(len + sc->sc_cachelsz - 1);
  67. if (skb != NULL) {
  68. off = ((unsigned long) skb->data) % sc->sc_cachelsz;
  69. if (off != 0)
  70. skb_reserve(skb, sc->sc_cachelsz - off);
  71. } else {
  72. DPRINTF(sc, ATH_DBG_FATAL,
  73. "%s: skbuff alloc of size %u failed\n",
  74. __func__, len);
  75. return NULL;
  76. }
  77. return skb;
  78. }
  79. static void ath_rx_requeue(struct ath_softc *sc, struct sk_buff *skb)
  80. {
  81. struct ath_buf *bf = ATH_RX_CONTEXT(skb)->ctx_rxbuf;
  82. ASSERT(bf != NULL);
  83. spin_lock_bh(&sc->sc_rxbuflock);
  84. if (bf->bf_status & ATH_BUFSTATUS_STALE) {
  85. /*
  86. * This buffer is still held for hw acess.
  87. * Mark it as free to be re-queued it later.
  88. */
  89. bf->bf_status |= ATH_BUFSTATUS_FREE;
  90. } else {
  91. /* XXX: we probably never enter here, remove after
  92. * verification */
  93. list_add_tail(&bf->list, &sc->sc_rxbuf);
  94. ath_rx_buf_link(sc, bf);
  95. }
  96. spin_unlock_bh(&sc->sc_rxbuflock);
  97. }
  98. /*
  99. * The skb indicated to upper stack won't be returned to us.
  100. * So we have to allocate a new one and queue it by ourselves.
  101. */
  102. static int ath_rx_indicate(struct ath_softc *sc,
  103. struct sk_buff *skb,
  104. struct ath_recv_status *status,
  105. u16 keyix)
  106. {
  107. struct ath_buf *bf = ATH_RX_CONTEXT(skb)->ctx_rxbuf;
  108. struct sk_buff *nskb;
  109. int type;
  110. /* indicate frame to the stack, which will free the old skb. */
  111. type = _ath_rx_indicate(sc, skb, status, keyix);
  112. /* allocate a new skb and queue it to for H/W processing */
  113. nskb = ath_rxbuf_alloc(sc, sc->sc_rxbufsize);
  114. if (nskb != NULL) {
  115. bf->bf_mpdu = nskb;
  116. bf->bf_buf_addr = pci_map_single(sc->pdev, nskb->data,
  117. skb_end_pointer(nskb) - nskb->head,
  118. PCI_DMA_FROMDEVICE);
  119. bf->bf_dmacontext = bf->bf_buf_addr;
  120. ATH_RX_CONTEXT(nskb)->ctx_rxbuf = bf;
  121. /* queue the new wbuf to H/W */
  122. ath_rx_requeue(sc, nskb);
  123. }
  124. return type;
  125. }
  126. static void ath_opmode_init(struct ath_softc *sc)
  127. {
  128. struct ath_hal *ah = sc->sc_ah;
  129. u32 rfilt, mfilt[2];
  130. /* configure rx filter */
  131. rfilt = ath_calcrxfilter(sc);
  132. ath9k_hw_setrxfilter(ah, rfilt);
  133. /* configure bssid mask */
  134. if (ah->ah_caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK)
  135. ath9k_hw_setbssidmask(ah, sc->sc_bssidmask);
  136. /* configure operational mode */
  137. ath9k_hw_setopmode(ah);
  138. /* Handle any link-level address change. */
  139. ath9k_hw_setmac(ah, sc->sc_myaddr);
  140. /* calculate and install multicast filter */
  141. mfilt[0] = mfilt[1] = ~0;
  142. ath9k_hw_setmcastfilter(ah, mfilt[0], mfilt[1]);
  143. DPRINTF(sc, ATH_DBG_CONFIG ,
  144. "%s: RX filter 0x%x, MC filter %08x:%08x\n",
  145. __func__, rfilt, mfilt[0], mfilt[1]);
  146. }
  147. int ath_rx_init(struct ath_softc *sc, int nbufs)
  148. {
  149. struct sk_buff *skb;
  150. struct ath_buf *bf;
  151. int error = 0;
  152. do {
  153. spin_lock_init(&sc->sc_rxflushlock);
  154. sc->sc_flags &= ~SC_OP_RXFLUSH;
  155. spin_lock_init(&sc->sc_rxbuflock);
  156. /*
  157. * Cisco's VPN software requires that drivers be able to
  158. * receive encapsulated frames that are larger than the MTU.
  159. * Since we can't be sure how large a frame we'll get, setup
  160. * to handle the larges on possible.
  161. */
  162. sc->sc_rxbufsize = roundup(IEEE80211_MAX_MPDU_LEN,
  163. min(sc->sc_cachelsz,
  164. (u16)64));
  165. DPRINTF(sc, ATH_DBG_CONFIG, "%s: cachelsz %u rxbufsize %u\n",
  166. __func__, sc->sc_cachelsz, sc->sc_rxbufsize);
  167. /* Initialize rx descriptors */
  168. error = ath_descdma_setup(sc, &sc->sc_rxdma, &sc->sc_rxbuf,
  169. "rx", nbufs, 1);
  170. if (error != 0) {
  171. DPRINTF(sc, ATH_DBG_FATAL,
  172. "%s: failed to allocate rx descriptors: %d\n",
  173. __func__, error);
  174. break;
  175. }
  176. /* Pre-allocate a wbuf for each rx buffer */
  177. list_for_each_entry(bf, &sc->sc_rxbuf, list) {
  178. skb = ath_rxbuf_alloc(sc, sc->sc_rxbufsize);
  179. if (skb == NULL) {
  180. error = -ENOMEM;
  181. break;
  182. }
  183. bf->bf_mpdu = skb;
  184. bf->bf_buf_addr = pci_map_single(sc->pdev, skb->data,
  185. skb_end_pointer(skb) - skb->head,
  186. PCI_DMA_FROMDEVICE);
  187. bf->bf_dmacontext = bf->bf_buf_addr;
  188. ATH_RX_CONTEXT(skb)->ctx_rxbuf = bf;
  189. }
  190. sc->sc_rxlink = NULL;
  191. } while (0);
  192. if (error)
  193. ath_rx_cleanup(sc);
  194. return error;
  195. }
  196. /* Reclaim all rx queue resources */
  197. void ath_rx_cleanup(struct ath_softc *sc)
  198. {
  199. struct sk_buff *skb;
  200. struct ath_buf *bf;
  201. list_for_each_entry(bf, &sc->sc_rxbuf, list) {
  202. skb = bf->bf_mpdu;
  203. if (skb)
  204. dev_kfree_skb(skb);
  205. }
  206. /* cleanup rx descriptors */
  207. if (sc->sc_rxdma.dd_desc_len != 0)
  208. ath_descdma_cleanup(sc, &sc->sc_rxdma, &sc->sc_rxbuf);
  209. }
  210. /*
  211. * Calculate the receive filter according to the
  212. * operating mode and state:
  213. *
  214. * o always accept unicast, broadcast, and multicast traffic
  215. * o maintain current state of phy error reception (the hal
  216. * may enable phy error frames for noise immunity work)
  217. * o probe request frames are accepted only when operating in
  218. * hostap, adhoc, or monitor modes
  219. * o enable promiscuous mode according to the interface state
  220. * o accept beacons:
  221. * - when operating in adhoc mode so the 802.11 layer creates
  222. * node table entries for peers,
  223. * - when operating in station mode for collecting rssi data when
  224. * the station is otherwise quiet, or
  225. * - when operating as a repeater so we see repeater-sta beacons
  226. * - when scanning
  227. */
  228. u32 ath_calcrxfilter(struct ath_softc *sc)
  229. {
  230. #define RX_FILTER_PRESERVE (ATH9K_RX_FILTER_PHYERR | ATH9K_RX_FILTER_PHYRADAR)
  231. u32 rfilt;
  232. rfilt = (ath9k_hw_getrxfilter(sc->sc_ah) & RX_FILTER_PRESERVE)
  233. | ATH9K_RX_FILTER_UCAST | ATH9K_RX_FILTER_BCAST
  234. | ATH9K_RX_FILTER_MCAST;
  235. /* If not a STA, enable processing of Probe Requests */
  236. if (sc->sc_ah->ah_opmode != ATH9K_M_STA)
  237. rfilt |= ATH9K_RX_FILTER_PROBEREQ;
  238. /* Can't set HOSTAP into promiscous mode */
  239. if (((sc->sc_ah->ah_opmode != ATH9K_M_HOSTAP) &&
  240. (sc->rx_filter & FIF_PROMISC_IN_BSS)) ||
  241. (sc->sc_ah->ah_opmode == ATH9K_M_MONITOR)) {
  242. rfilt |= ATH9K_RX_FILTER_PROM;
  243. /* ??? To prevent from sending ACK */
  244. rfilt &= ~ATH9K_RX_FILTER_UCAST;
  245. }
  246. if (sc->sc_ah->ah_opmode == ATH9K_M_STA ||
  247. sc->sc_ah->ah_opmode == ATH9K_M_IBSS)
  248. rfilt |= ATH9K_RX_FILTER_BEACON;
  249. /* If in HOSTAP mode, want to enable reception of PSPOLL frames
  250. & beacon frames */
  251. if (sc->sc_ah->ah_opmode == ATH9K_M_HOSTAP)
  252. rfilt |= (ATH9K_RX_FILTER_BEACON | ATH9K_RX_FILTER_PSPOLL);
  253. return rfilt;
  254. #undef RX_FILTER_PRESERVE
  255. }
  256. /* Enable the receive h/w following a reset. */
  257. int ath_startrecv(struct ath_softc *sc)
  258. {
  259. struct ath_hal *ah = sc->sc_ah;
  260. struct ath_buf *bf, *tbf;
  261. spin_lock_bh(&sc->sc_rxbuflock);
  262. if (list_empty(&sc->sc_rxbuf))
  263. goto start_recv;
  264. sc->sc_rxlink = NULL;
  265. list_for_each_entry_safe(bf, tbf, &sc->sc_rxbuf, list) {
  266. if (bf->bf_status & ATH_BUFSTATUS_STALE) {
  267. /* restarting h/w, no need for holding descriptors */
  268. bf->bf_status &= ~ATH_BUFSTATUS_STALE;
  269. /*
  270. * Upper layer may not be done with the frame yet so
  271. * we can't just re-queue it to hardware. Remove it
  272. * from h/w queue. It'll be re-queued when upper layer
  273. * returns the frame and ath_rx_requeue_mpdu is called.
  274. */
  275. if (!(bf->bf_status & ATH_BUFSTATUS_FREE)) {
  276. list_del(&bf->list);
  277. continue;
  278. }
  279. }
  280. /* chain descriptors */
  281. ath_rx_buf_link(sc, bf);
  282. }
  283. /* We could have deleted elements so the list may be empty now */
  284. if (list_empty(&sc->sc_rxbuf))
  285. goto start_recv;
  286. bf = list_first_entry(&sc->sc_rxbuf, struct ath_buf, list);
  287. ath9k_hw_putrxbuf(ah, bf->bf_daddr);
  288. ath9k_hw_rxena(ah); /* enable recv descriptors */
  289. start_recv:
  290. spin_unlock_bh(&sc->sc_rxbuflock);
  291. ath_opmode_init(sc); /* set filters, etc. */
  292. ath9k_hw_startpcureceive(ah); /* re-enable PCU/DMA engine */
  293. return 0;
  294. }
  295. /* Disable the receive h/w in preparation for a reset. */
  296. bool ath_stoprecv(struct ath_softc *sc)
  297. {
  298. struct ath_hal *ah = sc->sc_ah;
  299. u64 tsf;
  300. bool stopped;
  301. ath9k_hw_stoppcurecv(ah); /* disable PCU */
  302. ath9k_hw_setrxfilter(ah, 0); /* clear recv filter */
  303. stopped = ath9k_hw_stopdmarecv(ah); /* disable DMA engine */
  304. mdelay(3); /* 3ms is long enough for 1 frame */
  305. tsf = ath9k_hw_gettsf64(ah);
  306. sc->sc_rxlink = NULL; /* just in case */
  307. return stopped;
  308. }
  309. /* Flush receive queue */
  310. void ath_flushrecv(struct ath_softc *sc)
  311. {
  312. /*
  313. * ath_rx_tasklet may be used to handle rx interrupt and flush receive
  314. * queue at the same time. Use a lock to serialize the access of rx
  315. * queue.
  316. * ath_rx_tasklet cannot hold the spinlock while indicating packets.
  317. * Instead, do not claim the spinlock but check for a flush in
  318. * progress (see references to sc_rxflush)
  319. */
  320. spin_lock_bh(&sc->sc_rxflushlock);
  321. sc->sc_flags |= SC_OP_RXFLUSH;
  322. ath_rx_tasklet(sc, 1);
  323. sc->sc_flags &= ~SC_OP_RXFLUSH;
  324. spin_unlock_bh(&sc->sc_rxflushlock);
  325. }
  326. /* Process receive queue, as well as LED, etc. */
  327. int ath_rx_tasklet(struct ath_softc *sc, int flush)
  328. {
  329. #define PA2DESC(_sc, _pa) \
  330. ((struct ath_desc *)((caddr_t)(_sc)->sc_rxdma.dd_desc + \
  331. ((_pa) - (_sc)->sc_rxdma.dd_desc_paddr)))
  332. struct ath_buf *bf, *bf_held = NULL;
  333. struct ath_desc *ds;
  334. struct ieee80211_hdr *hdr;
  335. struct sk_buff *skb = NULL;
  336. struct ath_recv_status rx_status;
  337. struct ath_hal *ah = sc->sc_ah;
  338. int type, rx_processed = 0;
  339. u32 phyerr;
  340. u8 chainreset = 0;
  341. int retval;
  342. __le16 fc;
  343. do {
  344. /* If handling rx interrupt and flush is in progress => exit */
  345. if ((sc->sc_flags & SC_OP_RXFLUSH) && (flush == 0))
  346. break;
  347. spin_lock_bh(&sc->sc_rxbuflock);
  348. if (list_empty(&sc->sc_rxbuf)) {
  349. sc->sc_rxlink = NULL;
  350. spin_unlock_bh(&sc->sc_rxbuflock);
  351. break;
  352. }
  353. bf = list_first_entry(&sc->sc_rxbuf, struct ath_buf, list);
  354. /*
  355. * There is a race condition that BH gets scheduled after sw
  356. * writes RxE and before hw re-load the last descriptor to get
  357. * the newly chained one. Software must keep the last DONE
  358. * descriptor as a holding descriptor - software does so by
  359. * marking it with the STALE flag.
  360. */
  361. if (bf->bf_status & ATH_BUFSTATUS_STALE) {
  362. bf_held = bf;
  363. if (list_is_last(&bf_held->list, &sc->sc_rxbuf)) {
  364. /*
  365. * The holding descriptor is the last
  366. * descriptor in queue. It's safe to
  367. * remove the last holding descriptor
  368. * in BH context.
  369. */
  370. list_del(&bf_held->list);
  371. bf_held->bf_status &= ~ATH_BUFSTATUS_STALE;
  372. sc->sc_rxlink = NULL;
  373. if (bf_held->bf_status & ATH_BUFSTATUS_FREE) {
  374. list_add_tail(&bf_held->list,
  375. &sc->sc_rxbuf);
  376. ath_rx_buf_link(sc, bf_held);
  377. }
  378. spin_unlock_bh(&sc->sc_rxbuflock);
  379. break;
  380. }
  381. bf = list_entry(bf->list.next, struct ath_buf, list);
  382. }
  383. ds = bf->bf_desc;
  384. ++rx_processed;
  385. /*
  386. * Must provide the virtual address of the current
  387. * descriptor, the physical address, and the virtual
  388. * address of the next descriptor in the h/w chain.
  389. * This allows the HAL to look ahead to see if the
  390. * hardware is done with a descriptor by checking the
  391. * done bit in the following descriptor and the address
  392. * of the current descriptor the DMA engine is working
  393. * on. All this is necessary because of our use of
  394. * a self-linked list to avoid rx overruns.
  395. */
  396. retval = ath9k_hw_rxprocdesc(ah,
  397. ds,
  398. bf->bf_daddr,
  399. PA2DESC(sc, ds->ds_link),
  400. 0);
  401. if (retval == -EINPROGRESS) {
  402. struct ath_buf *tbf;
  403. struct ath_desc *tds;
  404. if (list_is_last(&bf->list, &sc->sc_rxbuf)) {
  405. spin_unlock_bh(&sc->sc_rxbuflock);
  406. break;
  407. }
  408. tbf = list_entry(bf->list.next, struct ath_buf, list);
  409. /*
  410. * On some hardware the descriptor status words could
  411. * get corrupted, including the done bit. Because of
  412. * this, check if the next descriptor's done bit is
  413. * set or not.
  414. *
  415. * If the next descriptor's done bit is set, the current
  416. * descriptor has been corrupted. Force s/w to discard
  417. * this descriptor and continue...
  418. */
  419. tds = tbf->bf_desc;
  420. retval = ath9k_hw_rxprocdesc(ah,
  421. tds, tbf->bf_daddr,
  422. PA2DESC(sc, tds->ds_link), 0);
  423. if (retval == -EINPROGRESS) {
  424. spin_unlock_bh(&sc->sc_rxbuflock);
  425. break;
  426. }
  427. }
  428. /* XXX: we do not support frames spanning
  429. * multiple descriptors */
  430. bf->bf_status |= ATH_BUFSTATUS_DONE;
  431. skb = bf->bf_mpdu;
  432. if (skb == NULL) { /* XXX ??? can this happen */
  433. spin_unlock_bh(&sc->sc_rxbuflock);
  434. continue;
  435. }
  436. /*
  437. * Now we know it's a completed frame, we can indicate the
  438. * frame. Remove the previous holding descriptor and leave
  439. * this one in the queue as the new holding descriptor.
  440. */
  441. if (bf_held) {
  442. list_del(&bf_held->list);
  443. bf_held->bf_status &= ~ATH_BUFSTATUS_STALE;
  444. if (bf_held->bf_status & ATH_BUFSTATUS_FREE) {
  445. list_add_tail(&bf_held->list, &sc->sc_rxbuf);
  446. /* try to requeue this descriptor */
  447. ath_rx_buf_link(sc, bf_held);
  448. }
  449. }
  450. bf->bf_status |= ATH_BUFSTATUS_STALE;
  451. bf_held = bf;
  452. /*
  453. * Release the lock here in case ieee80211_input() return
  454. * the frame immediately by calling ath_rx_mpdu_requeue().
  455. */
  456. spin_unlock_bh(&sc->sc_rxbuflock);
  457. if (flush) {
  458. /*
  459. * If we're asked to flush receive queue, directly
  460. * chain it back at the queue without processing it.
  461. */
  462. goto rx_next;
  463. }
  464. hdr = (struct ieee80211_hdr *)skb->data;
  465. fc = hdr->frame_control;
  466. memset(&rx_status, 0, sizeof(struct ath_recv_status));
  467. if (ds->ds_rxstat.rs_more) {
  468. /*
  469. * Frame spans multiple descriptors; this
  470. * cannot happen yet as we don't support
  471. * jumbograms. If not in monitor mode,
  472. * discard the frame.
  473. */
  474. #ifndef ERROR_FRAMES
  475. /*
  476. * Enable this if you want to see
  477. * error frames in Monitor mode.
  478. */
  479. if (sc->sc_ah->ah_opmode != ATH9K_M_MONITOR)
  480. goto rx_next;
  481. #endif
  482. /* fall thru for monitor mode handling... */
  483. } else if (ds->ds_rxstat.rs_status != 0) {
  484. if (ds->ds_rxstat.rs_status & ATH9K_RXERR_CRC)
  485. rx_status.flags |= ATH_RX_FCS_ERROR;
  486. if (ds->ds_rxstat.rs_status & ATH9K_RXERR_PHY) {
  487. phyerr = ds->ds_rxstat.rs_phyerr & 0x1f;
  488. goto rx_next;
  489. }
  490. if (ds->ds_rxstat.rs_status & ATH9K_RXERR_DECRYPT) {
  491. /*
  492. * Decrypt error. We only mark packet status
  493. * here and always push up the frame up to let
  494. * mac80211 handle the actual error case, be
  495. * it no decryption key or real decryption
  496. * error. This let us keep statistics there.
  497. */
  498. rx_status.flags |= ATH_RX_DECRYPT_ERROR;
  499. } else if (ds->ds_rxstat.rs_status & ATH9K_RXERR_MIC) {
  500. /*
  501. * Demic error. We only mark frame status here
  502. * and always push up the frame up to let
  503. * mac80211 handle the actual error case. This
  504. * let us keep statistics there. Hardware may
  505. * post a false-positive MIC error.
  506. */
  507. if (ieee80211_is_ctl(fc))
  508. /*
  509. * Sometimes, we get invalid
  510. * MIC failures on valid control frames.
  511. * Remove these mic errors.
  512. */
  513. ds->ds_rxstat.rs_status &=
  514. ~ATH9K_RXERR_MIC;
  515. else
  516. rx_status.flags |= ATH_RX_MIC_ERROR;
  517. }
  518. /*
  519. * Reject error frames with the exception of
  520. * decryption and MIC failures. For monitor mode,
  521. * we also ignore the CRC error.
  522. */
  523. if (sc->sc_ah->ah_opmode == ATH9K_M_MONITOR) {
  524. if (ds->ds_rxstat.rs_status &
  525. ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC |
  526. ATH9K_RXERR_CRC))
  527. goto rx_next;
  528. } else {
  529. if (ds->ds_rxstat.rs_status &
  530. ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC)) {
  531. goto rx_next;
  532. }
  533. }
  534. }
  535. /*
  536. * The status portion of the descriptor could get corrupted.
  537. */
  538. if (sc->sc_rxbufsize < ds->ds_rxstat.rs_datalen)
  539. goto rx_next;
  540. /*
  541. * Sync and unmap the frame. At this point we're
  542. * committed to passing the sk_buff somewhere so
  543. * clear buf_skb; this means a new sk_buff must be
  544. * allocated when the rx descriptor is setup again
  545. * to receive another frame.
  546. */
  547. skb_put(skb, ds->ds_rxstat.rs_datalen);
  548. skb->protocol = cpu_to_be16(ETH_P_CONTROL);
  549. rx_status.tsf = ath_extend_tsf(sc, ds->ds_rxstat.rs_tstamp);
  550. rx_status.rateieee =
  551. sc->sc_hwmap[ds->ds_rxstat.rs_rate].ieeerate;
  552. rx_status.rateKbps =
  553. sc->sc_hwmap[ds->ds_rxstat.rs_rate].rateKbps;
  554. rx_status.ratecode = ds->ds_rxstat.rs_rate;
  555. /* HT rate */
  556. if (rx_status.ratecode & 0x80) {
  557. /* TODO - add table to avoid division */
  558. if (ds->ds_rxstat.rs_flags & ATH9K_RX_2040) {
  559. rx_status.flags |= ATH_RX_40MHZ;
  560. rx_status.rateKbps =
  561. (rx_status.rateKbps * 27) / 13;
  562. }
  563. if (ds->ds_rxstat.rs_flags & ATH9K_RX_GI)
  564. rx_status.rateKbps =
  565. (rx_status.rateKbps * 10) / 9;
  566. else
  567. rx_status.flags |= ATH_RX_SHORT_GI;
  568. }
  569. /* sc_noise_floor is only available when the station
  570. attaches to an AP, so we use a default value
  571. if we are not yet attached. */
  572. rx_status.abs_rssi =
  573. ds->ds_rxstat.rs_rssi + sc->sc_ani.sc_noise_floor;
  574. pci_dma_sync_single_for_cpu(sc->pdev,
  575. bf->bf_buf_addr,
  576. skb_tailroom(skb),
  577. PCI_DMA_FROMDEVICE);
  578. pci_unmap_single(sc->pdev,
  579. bf->bf_buf_addr,
  580. sc->sc_rxbufsize,
  581. PCI_DMA_FROMDEVICE);
  582. /* XXX: Ah! make me more readable, use a helper */
  583. if (ah->ah_caps.hw_caps & ATH9K_HW_CAP_HT) {
  584. if (ds->ds_rxstat.rs_moreaggr == 0) {
  585. rx_status.rssictl[0] =
  586. ds->ds_rxstat.rs_rssi_ctl0;
  587. rx_status.rssictl[1] =
  588. ds->ds_rxstat.rs_rssi_ctl1;
  589. rx_status.rssictl[2] =
  590. ds->ds_rxstat.rs_rssi_ctl2;
  591. rx_status.rssi = ds->ds_rxstat.rs_rssi;
  592. if (ds->ds_rxstat.rs_flags & ATH9K_RX_2040) {
  593. rx_status.rssiextn[0] =
  594. ds->ds_rxstat.rs_rssi_ext0;
  595. rx_status.rssiextn[1] =
  596. ds->ds_rxstat.rs_rssi_ext1;
  597. rx_status.rssiextn[2] =
  598. ds->ds_rxstat.rs_rssi_ext2;
  599. rx_status.flags |=
  600. ATH_RX_RSSI_EXTN_VALID;
  601. }
  602. rx_status.flags |= ATH_RX_RSSI_VALID |
  603. ATH_RX_CHAIN_RSSI_VALID;
  604. }
  605. } else {
  606. /*
  607. * Need to insert the "combined" rssi into the
  608. * status structure for upper layer processing
  609. */
  610. rx_status.rssi = ds->ds_rxstat.rs_rssi;
  611. rx_status.flags |= ATH_RX_RSSI_VALID;
  612. }
  613. /* Pass frames up to the stack. */
  614. type = ath_rx_indicate(sc, skb,
  615. &rx_status, ds->ds_rxstat.rs_keyix);
  616. /*
  617. * change the default rx antenna if rx diversity chooses the
  618. * other antenna 3 times in a row.
  619. */
  620. if (sc->sc_defant != ds->ds_rxstat.rs_antenna) {
  621. if (++sc->sc_rxotherant >= 3)
  622. ath_setdefantenna(sc,
  623. ds->ds_rxstat.rs_antenna);
  624. } else {
  625. sc->sc_rxotherant = 0;
  626. }
  627. #ifdef CONFIG_SLOW_ANT_DIV
  628. if ((rx_status.flags & ATH_RX_RSSI_VALID) &&
  629. ieee80211_is_beacon(fc)) {
  630. ath_slow_ant_div(&sc->sc_antdiv, hdr, &ds->ds_rxstat);
  631. }
  632. #endif
  633. /*
  634. * For frames successfully indicated, the buffer will be
  635. * returned to us by upper layers by calling
  636. * ath_rx_mpdu_requeue, either synchronusly or asynchronously.
  637. * So we don't want to do it here in this loop.
  638. */
  639. continue;
  640. rx_next:
  641. bf->bf_status |= ATH_BUFSTATUS_FREE;
  642. } while (TRUE);
  643. if (chainreset) {
  644. DPRINTF(sc, ATH_DBG_CONFIG,
  645. "%s: Reset rx chain mask. "
  646. "Do internal reset\n", __func__);
  647. ASSERT(flush == 0);
  648. ath_reset(sc, false);
  649. }
  650. return 0;
  651. #undef PA2DESC
  652. }