recv.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276
  1. /*
  2. * Copyright (c) 2008-2011 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 <linux/dma-mapping.h>
  17. #include "ath9k.h"
  18. #include "ar9003_mac.h"
  19. #define SKB_CB_ATHBUF(__skb) (*((struct ath_buf **)__skb->cb))
  20. static inline bool ath9k_check_auto_sleep(struct ath_softc *sc)
  21. {
  22. return sc->ps_enabled &&
  23. (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP);
  24. }
  25. /*
  26. * Setup and link descriptors.
  27. *
  28. * 11N: we can no longer afford to self link the last descriptor.
  29. * MAC acknowledges BA status as long as it copies frames to host
  30. * buffer (or rx fifo). This can incorrectly acknowledge packets
  31. * to a sender if last desc is self-linked.
  32. */
  33. static void ath_rx_buf_link(struct ath_softc *sc, struct ath_buf *bf)
  34. {
  35. struct ath_hw *ah = sc->sc_ah;
  36. struct ath_common *common = ath9k_hw_common(ah);
  37. struct ath_desc *ds;
  38. struct sk_buff *skb;
  39. ATH_RXBUF_RESET(bf);
  40. ds = bf->bf_desc;
  41. ds->ds_link = 0; /* link to null */
  42. ds->ds_data = bf->bf_buf_addr;
  43. /* virtual addr of the beginning of the buffer. */
  44. skb = bf->bf_mpdu;
  45. BUG_ON(skb == NULL);
  46. ds->ds_vdata = skb->data;
  47. /*
  48. * setup rx descriptors. The rx_bufsize here tells the hardware
  49. * how much data it can DMA to us and that we are prepared
  50. * to process
  51. */
  52. ath9k_hw_setuprxdesc(ah, ds,
  53. common->rx_bufsize,
  54. 0);
  55. if (sc->rx.rxlink == NULL)
  56. ath9k_hw_putrxbuf(ah, bf->bf_daddr);
  57. else
  58. *sc->rx.rxlink = bf->bf_daddr;
  59. sc->rx.rxlink = &ds->ds_link;
  60. }
  61. static void ath_setdefantenna(struct ath_softc *sc, u32 antenna)
  62. {
  63. /* XXX block beacon interrupts */
  64. ath9k_hw_setantenna(sc->sc_ah, antenna);
  65. sc->rx.defant = antenna;
  66. sc->rx.rxotherant = 0;
  67. }
  68. static void ath_opmode_init(struct ath_softc *sc)
  69. {
  70. struct ath_hw *ah = sc->sc_ah;
  71. struct ath_common *common = ath9k_hw_common(ah);
  72. u32 rfilt, mfilt[2];
  73. /* configure rx filter */
  74. rfilt = ath_calcrxfilter(sc);
  75. ath9k_hw_setrxfilter(ah, rfilt);
  76. /* configure bssid mask */
  77. ath_hw_setbssidmask(common);
  78. /* configure operational mode */
  79. ath9k_hw_setopmode(ah);
  80. /* calculate and install multicast filter */
  81. mfilt[0] = mfilt[1] = ~0;
  82. ath9k_hw_setmcastfilter(ah, mfilt[0], mfilt[1]);
  83. }
  84. static bool ath_rx_edma_buf_link(struct ath_softc *sc,
  85. enum ath9k_rx_qtype qtype)
  86. {
  87. struct ath_hw *ah = sc->sc_ah;
  88. struct ath_rx_edma *rx_edma;
  89. struct sk_buff *skb;
  90. struct ath_buf *bf;
  91. rx_edma = &sc->rx.rx_edma[qtype];
  92. if (skb_queue_len(&rx_edma->rx_fifo) >= rx_edma->rx_fifo_hwsize)
  93. return false;
  94. bf = list_first_entry(&sc->rx.rxbuf, struct ath_buf, list);
  95. list_del_init(&bf->list);
  96. skb = bf->bf_mpdu;
  97. ATH_RXBUF_RESET(bf);
  98. memset(skb->data, 0, ah->caps.rx_status_len);
  99. dma_sync_single_for_device(sc->dev, bf->bf_buf_addr,
  100. ah->caps.rx_status_len, DMA_TO_DEVICE);
  101. SKB_CB_ATHBUF(skb) = bf;
  102. ath9k_hw_addrxbuf_edma(ah, bf->bf_buf_addr, qtype);
  103. skb_queue_tail(&rx_edma->rx_fifo, skb);
  104. return true;
  105. }
  106. static void ath_rx_addbuffer_edma(struct ath_softc *sc,
  107. enum ath9k_rx_qtype qtype, int size)
  108. {
  109. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  110. struct ath_buf *bf, *tbf;
  111. if (list_empty(&sc->rx.rxbuf)) {
  112. ath_dbg(common, QUEUE, "No free rx buf available\n");
  113. return;
  114. }
  115. list_for_each_entry_safe(bf, tbf, &sc->rx.rxbuf, list)
  116. if (!ath_rx_edma_buf_link(sc, qtype))
  117. break;
  118. }
  119. static void ath_rx_remove_buffer(struct ath_softc *sc,
  120. enum ath9k_rx_qtype qtype)
  121. {
  122. struct ath_buf *bf;
  123. struct ath_rx_edma *rx_edma;
  124. struct sk_buff *skb;
  125. rx_edma = &sc->rx.rx_edma[qtype];
  126. while ((skb = skb_dequeue(&rx_edma->rx_fifo)) != NULL) {
  127. bf = SKB_CB_ATHBUF(skb);
  128. BUG_ON(!bf);
  129. list_add_tail(&bf->list, &sc->rx.rxbuf);
  130. }
  131. }
  132. static void ath_rx_edma_cleanup(struct ath_softc *sc)
  133. {
  134. struct ath_hw *ah = sc->sc_ah;
  135. struct ath_common *common = ath9k_hw_common(ah);
  136. struct ath_buf *bf;
  137. ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_LP);
  138. ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_HP);
  139. list_for_each_entry(bf, &sc->rx.rxbuf, list) {
  140. if (bf->bf_mpdu) {
  141. dma_unmap_single(sc->dev, bf->bf_buf_addr,
  142. common->rx_bufsize,
  143. DMA_BIDIRECTIONAL);
  144. dev_kfree_skb_any(bf->bf_mpdu);
  145. bf->bf_buf_addr = 0;
  146. bf->bf_mpdu = NULL;
  147. }
  148. }
  149. INIT_LIST_HEAD(&sc->rx.rxbuf);
  150. kfree(sc->rx.rx_bufptr);
  151. sc->rx.rx_bufptr = NULL;
  152. }
  153. static void ath_rx_edma_init_queue(struct ath_rx_edma *rx_edma, int size)
  154. {
  155. skb_queue_head_init(&rx_edma->rx_fifo);
  156. rx_edma->rx_fifo_hwsize = size;
  157. }
  158. static int ath_rx_edma_init(struct ath_softc *sc, int nbufs)
  159. {
  160. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  161. struct ath_hw *ah = sc->sc_ah;
  162. struct sk_buff *skb;
  163. struct ath_buf *bf;
  164. int error = 0, i;
  165. u32 size;
  166. ath9k_hw_set_rx_bufsize(ah, common->rx_bufsize -
  167. ah->caps.rx_status_len);
  168. ath_rx_edma_init_queue(&sc->rx.rx_edma[ATH9K_RX_QUEUE_LP],
  169. ah->caps.rx_lp_qdepth);
  170. ath_rx_edma_init_queue(&sc->rx.rx_edma[ATH9K_RX_QUEUE_HP],
  171. ah->caps.rx_hp_qdepth);
  172. size = sizeof(struct ath_buf) * nbufs;
  173. bf = kzalloc(size, GFP_KERNEL);
  174. if (!bf)
  175. return -ENOMEM;
  176. INIT_LIST_HEAD(&sc->rx.rxbuf);
  177. sc->rx.rx_bufptr = bf;
  178. for (i = 0; i < nbufs; i++, bf++) {
  179. skb = ath_rxbuf_alloc(common, common->rx_bufsize, GFP_KERNEL);
  180. if (!skb) {
  181. error = -ENOMEM;
  182. goto rx_init_fail;
  183. }
  184. memset(skb->data, 0, common->rx_bufsize);
  185. bf->bf_mpdu = skb;
  186. bf->bf_buf_addr = dma_map_single(sc->dev, skb->data,
  187. common->rx_bufsize,
  188. DMA_BIDIRECTIONAL);
  189. if (unlikely(dma_mapping_error(sc->dev,
  190. bf->bf_buf_addr))) {
  191. dev_kfree_skb_any(skb);
  192. bf->bf_mpdu = NULL;
  193. bf->bf_buf_addr = 0;
  194. ath_err(common,
  195. "dma_mapping_error() on RX init\n");
  196. error = -ENOMEM;
  197. goto rx_init_fail;
  198. }
  199. list_add_tail(&bf->list, &sc->rx.rxbuf);
  200. }
  201. return 0;
  202. rx_init_fail:
  203. ath_rx_edma_cleanup(sc);
  204. return error;
  205. }
  206. static void ath_edma_start_recv(struct ath_softc *sc)
  207. {
  208. spin_lock_bh(&sc->rx.rxbuflock);
  209. ath9k_hw_rxena(sc->sc_ah);
  210. ath_rx_addbuffer_edma(sc, ATH9K_RX_QUEUE_HP,
  211. sc->rx.rx_edma[ATH9K_RX_QUEUE_HP].rx_fifo_hwsize);
  212. ath_rx_addbuffer_edma(sc, ATH9K_RX_QUEUE_LP,
  213. sc->rx.rx_edma[ATH9K_RX_QUEUE_LP].rx_fifo_hwsize);
  214. ath_opmode_init(sc);
  215. ath9k_hw_startpcureceive(sc->sc_ah, !!(sc->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL));
  216. spin_unlock_bh(&sc->rx.rxbuflock);
  217. }
  218. static void ath_edma_stop_recv(struct ath_softc *sc)
  219. {
  220. ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_HP);
  221. ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_LP);
  222. }
  223. int ath_rx_init(struct ath_softc *sc, int nbufs)
  224. {
  225. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  226. struct sk_buff *skb;
  227. struct ath_buf *bf;
  228. int error = 0;
  229. spin_lock_init(&sc->sc_pcu_lock);
  230. spin_lock_init(&sc->rx.rxbuflock);
  231. clear_bit(SC_OP_RXFLUSH, &sc->sc_flags);
  232. common->rx_bufsize = IEEE80211_MAX_MPDU_LEN / 2 +
  233. sc->sc_ah->caps.rx_status_len;
  234. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
  235. return ath_rx_edma_init(sc, nbufs);
  236. } else {
  237. ath_dbg(common, CONFIG, "cachelsz %u rxbufsize %u\n",
  238. common->cachelsz, common->rx_bufsize);
  239. /* Initialize rx descriptors */
  240. error = ath_descdma_setup(sc, &sc->rx.rxdma, &sc->rx.rxbuf,
  241. "rx", nbufs, 1, 0);
  242. if (error != 0) {
  243. ath_err(common,
  244. "failed to allocate rx descriptors: %d\n",
  245. error);
  246. goto err;
  247. }
  248. list_for_each_entry(bf, &sc->rx.rxbuf, list) {
  249. skb = ath_rxbuf_alloc(common, common->rx_bufsize,
  250. GFP_KERNEL);
  251. if (skb == NULL) {
  252. error = -ENOMEM;
  253. goto err;
  254. }
  255. bf->bf_mpdu = skb;
  256. bf->bf_buf_addr = dma_map_single(sc->dev, skb->data,
  257. common->rx_bufsize,
  258. DMA_FROM_DEVICE);
  259. if (unlikely(dma_mapping_error(sc->dev,
  260. bf->bf_buf_addr))) {
  261. dev_kfree_skb_any(skb);
  262. bf->bf_mpdu = NULL;
  263. bf->bf_buf_addr = 0;
  264. ath_err(common,
  265. "dma_mapping_error() on RX init\n");
  266. error = -ENOMEM;
  267. goto err;
  268. }
  269. }
  270. sc->rx.rxlink = NULL;
  271. }
  272. err:
  273. if (error)
  274. ath_rx_cleanup(sc);
  275. return error;
  276. }
  277. void ath_rx_cleanup(struct ath_softc *sc)
  278. {
  279. struct ath_hw *ah = sc->sc_ah;
  280. struct ath_common *common = ath9k_hw_common(ah);
  281. struct sk_buff *skb;
  282. struct ath_buf *bf;
  283. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
  284. ath_rx_edma_cleanup(sc);
  285. return;
  286. } else {
  287. list_for_each_entry(bf, &sc->rx.rxbuf, list) {
  288. skb = bf->bf_mpdu;
  289. if (skb) {
  290. dma_unmap_single(sc->dev, bf->bf_buf_addr,
  291. common->rx_bufsize,
  292. DMA_FROM_DEVICE);
  293. dev_kfree_skb(skb);
  294. bf->bf_buf_addr = 0;
  295. bf->bf_mpdu = NULL;
  296. }
  297. }
  298. if (sc->rx.rxdma.dd_desc_len != 0)
  299. ath_descdma_cleanup(sc, &sc->rx.rxdma, &sc->rx.rxbuf);
  300. }
  301. }
  302. /*
  303. * Calculate the receive filter according to the
  304. * operating mode and state:
  305. *
  306. * o always accept unicast, broadcast, and multicast traffic
  307. * o maintain current state of phy error reception (the hal
  308. * may enable phy error frames for noise immunity work)
  309. * o probe request frames are accepted only when operating in
  310. * hostap, adhoc, or monitor modes
  311. * o enable promiscuous mode according to the interface state
  312. * o accept beacons:
  313. * - when operating in adhoc mode so the 802.11 layer creates
  314. * node table entries for peers,
  315. * - when operating in station mode for collecting rssi data when
  316. * the station is otherwise quiet, or
  317. * - when operating as a repeater so we see repeater-sta beacons
  318. * - when scanning
  319. */
  320. u32 ath_calcrxfilter(struct ath_softc *sc)
  321. {
  322. u32 rfilt;
  323. rfilt = ATH9K_RX_FILTER_UCAST | ATH9K_RX_FILTER_BCAST
  324. | ATH9K_RX_FILTER_MCAST;
  325. if (sc->rx.rxfilter & FIF_PROBE_REQ)
  326. rfilt |= ATH9K_RX_FILTER_PROBEREQ;
  327. /*
  328. * Set promiscuous mode when FIF_PROMISC_IN_BSS is enabled for station
  329. * mode interface or when in monitor mode. AP mode does not need this
  330. * since it receives all in-BSS frames anyway.
  331. */
  332. if (sc->sc_ah->is_monitoring)
  333. rfilt |= ATH9K_RX_FILTER_PROM;
  334. if (sc->rx.rxfilter & FIF_CONTROL)
  335. rfilt |= ATH9K_RX_FILTER_CONTROL;
  336. if ((sc->sc_ah->opmode == NL80211_IFTYPE_STATION) &&
  337. (sc->nvifs <= 1) &&
  338. !(sc->rx.rxfilter & FIF_BCN_PRBRESP_PROMISC))
  339. rfilt |= ATH9K_RX_FILTER_MYBEACON;
  340. else
  341. rfilt |= ATH9K_RX_FILTER_BEACON;
  342. if ((sc->sc_ah->opmode == NL80211_IFTYPE_AP) ||
  343. (sc->rx.rxfilter & FIF_PSPOLL))
  344. rfilt |= ATH9K_RX_FILTER_PSPOLL;
  345. if (conf_is_ht(&sc->hw->conf))
  346. rfilt |= ATH9K_RX_FILTER_COMP_BAR;
  347. if (sc->nvifs > 1 || (sc->rx.rxfilter & FIF_OTHER_BSS)) {
  348. /* This is needed for older chips */
  349. if (sc->sc_ah->hw_version.macVersion <= AR_SREV_VERSION_9160)
  350. rfilt |= ATH9K_RX_FILTER_PROM;
  351. rfilt |= ATH9K_RX_FILTER_MCAST_BCAST_ALL;
  352. }
  353. if (AR_SREV_9550(sc->sc_ah))
  354. rfilt |= ATH9K_RX_FILTER_4ADDRESS;
  355. return rfilt;
  356. }
  357. int ath_startrecv(struct ath_softc *sc)
  358. {
  359. struct ath_hw *ah = sc->sc_ah;
  360. struct ath_buf *bf, *tbf;
  361. if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
  362. ath_edma_start_recv(sc);
  363. return 0;
  364. }
  365. spin_lock_bh(&sc->rx.rxbuflock);
  366. if (list_empty(&sc->rx.rxbuf))
  367. goto start_recv;
  368. sc->rx.rxlink = NULL;
  369. list_for_each_entry_safe(bf, tbf, &sc->rx.rxbuf, list) {
  370. ath_rx_buf_link(sc, bf);
  371. }
  372. /* We could have deleted elements so the list may be empty now */
  373. if (list_empty(&sc->rx.rxbuf))
  374. goto start_recv;
  375. bf = list_first_entry(&sc->rx.rxbuf, struct ath_buf, list);
  376. ath9k_hw_putrxbuf(ah, bf->bf_daddr);
  377. ath9k_hw_rxena(ah);
  378. start_recv:
  379. ath_opmode_init(sc);
  380. ath9k_hw_startpcureceive(ah, !!(sc->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL));
  381. spin_unlock_bh(&sc->rx.rxbuflock);
  382. return 0;
  383. }
  384. bool ath_stoprecv(struct ath_softc *sc)
  385. {
  386. struct ath_hw *ah = sc->sc_ah;
  387. bool stopped, reset = false;
  388. spin_lock_bh(&sc->rx.rxbuflock);
  389. ath9k_hw_abortpcurecv(ah);
  390. ath9k_hw_setrxfilter(ah, 0);
  391. stopped = ath9k_hw_stopdmarecv(ah, &reset);
  392. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
  393. ath_edma_stop_recv(sc);
  394. else
  395. sc->rx.rxlink = NULL;
  396. spin_unlock_bh(&sc->rx.rxbuflock);
  397. if (!(ah->ah_flags & AH_UNPLUGGED) &&
  398. unlikely(!stopped)) {
  399. ath_err(ath9k_hw_common(sc->sc_ah),
  400. "Could not stop RX, we could be "
  401. "confusing the DMA engine when we start RX up\n");
  402. ATH_DBG_WARN_ON_ONCE(!stopped);
  403. }
  404. return stopped && !reset;
  405. }
  406. void ath_flushrecv(struct ath_softc *sc)
  407. {
  408. set_bit(SC_OP_RXFLUSH, &sc->sc_flags);
  409. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
  410. ath_rx_tasklet(sc, 1, true);
  411. ath_rx_tasklet(sc, 1, false);
  412. clear_bit(SC_OP_RXFLUSH, &sc->sc_flags);
  413. }
  414. static bool ath_beacon_dtim_pending_cab(struct sk_buff *skb)
  415. {
  416. /* Check whether the Beacon frame has DTIM indicating buffered bc/mc */
  417. struct ieee80211_mgmt *mgmt;
  418. u8 *pos, *end, id, elen;
  419. struct ieee80211_tim_ie *tim;
  420. mgmt = (struct ieee80211_mgmt *)skb->data;
  421. pos = mgmt->u.beacon.variable;
  422. end = skb->data + skb->len;
  423. while (pos + 2 < end) {
  424. id = *pos++;
  425. elen = *pos++;
  426. if (pos + elen > end)
  427. break;
  428. if (id == WLAN_EID_TIM) {
  429. if (elen < sizeof(*tim))
  430. break;
  431. tim = (struct ieee80211_tim_ie *) pos;
  432. if (tim->dtim_count != 0)
  433. break;
  434. return tim->bitmap_ctrl & 0x01;
  435. }
  436. pos += elen;
  437. }
  438. return false;
  439. }
  440. static void ath_rx_ps_beacon(struct ath_softc *sc, struct sk_buff *skb)
  441. {
  442. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  443. if (skb->len < 24 + 8 + 2 + 2)
  444. return;
  445. sc->ps_flags &= ~PS_WAIT_FOR_BEACON;
  446. if (sc->ps_flags & PS_BEACON_SYNC) {
  447. sc->ps_flags &= ~PS_BEACON_SYNC;
  448. ath_dbg(common, PS,
  449. "Reconfigure Beacon timers based on timestamp from the AP\n");
  450. ath9k_set_beacon(sc);
  451. }
  452. if (ath_beacon_dtim_pending_cab(skb)) {
  453. /*
  454. * Remain awake waiting for buffered broadcast/multicast
  455. * frames. If the last broadcast/multicast frame is not
  456. * received properly, the next beacon frame will work as
  457. * a backup trigger for returning into NETWORK SLEEP state,
  458. * so we are waiting for it as well.
  459. */
  460. ath_dbg(common, PS,
  461. "Received DTIM beacon indicating buffered broadcast/multicast frame(s)\n");
  462. sc->ps_flags |= PS_WAIT_FOR_CAB | PS_WAIT_FOR_BEACON;
  463. return;
  464. }
  465. if (sc->ps_flags & PS_WAIT_FOR_CAB) {
  466. /*
  467. * This can happen if a broadcast frame is dropped or the AP
  468. * fails to send a frame indicating that all CAB frames have
  469. * been delivered.
  470. */
  471. sc->ps_flags &= ~PS_WAIT_FOR_CAB;
  472. ath_dbg(common, PS, "PS wait for CAB frames timed out\n");
  473. }
  474. }
  475. static void ath_rx_ps(struct ath_softc *sc, struct sk_buff *skb, bool mybeacon)
  476. {
  477. struct ieee80211_hdr *hdr;
  478. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  479. hdr = (struct ieee80211_hdr *)skb->data;
  480. /* Process Beacon and CAB receive in PS state */
  481. if (((sc->ps_flags & PS_WAIT_FOR_BEACON) || ath9k_check_auto_sleep(sc))
  482. && mybeacon) {
  483. ath_rx_ps_beacon(sc, skb);
  484. } else if ((sc->ps_flags & PS_WAIT_FOR_CAB) &&
  485. (ieee80211_is_data(hdr->frame_control) ||
  486. ieee80211_is_action(hdr->frame_control)) &&
  487. is_multicast_ether_addr(hdr->addr1) &&
  488. !ieee80211_has_moredata(hdr->frame_control)) {
  489. /*
  490. * No more broadcast/multicast frames to be received at this
  491. * point.
  492. */
  493. sc->ps_flags &= ~(PS_WAIT_FOR_CAB | PS_WAIT_FOR_BEACON);
  494. ath_dbg(common, PS,
  495. "All PS CAB frames received, back to sleep\n");
  496. } else if ((sc->ps_flags & PS_WAIT_FOR_PSPOLL_DATA) &&
  497. !is_multicast_ether_addr(hdr->addr1) &&
  498. !ieee80211_has_morefrags(hdr->frame_control)) {
  499. sc->ps_flags &= ~PS_WAIT_FOR_PSPOLL_DATA;
  500. ath_dbg(common, PS,
  501. "Going back to sleep after having received PS-Poll data (0x%lx)\n",
  502. sc->ps_flags & (PS_WAIT_FOR_BEACON |
  503. PS_WAIT_FOR_CAB |
  504. PS_WAIT_FOR_PSPOLL_DATA |
  505. PS_WAIT_FOR_TX_ACK));
  506. }
  507. }
  508. static bool ath_edma_get_buffers(struct ath_softc *sc,
  509. enum ath9k_rx_qtype qtype,
  510. struct ath_rx_status *rs,
  511. struct ath_buf **dest)
  512. {
  513. struct ath_rx_edma *rx_edma = &sc->rx.rx_edma[qtype];
  514. struct ath_hw *ah = sc->sc_ah;
  515. struct ath_common *common = ath9k_hw_common(ah);
  516. struct sk_buff *skb;
  517. struct ath_buf *bf;
  518. int ret;
  519. skb = skb_peek(&rx_edma->rx_fifo);
  520. if (!skb)
  521. return false;
  522. bf = SKB_CB_ATHBUF(skb);
  523. BUG_ON(!bf);
  524. dma_sync_single_for_cpu(sc->dev, bf->bf_buf_addr,
  525. common->rx_bufsize, DMA_FROM_DEVICE);
  526. ret = ath9k_hw_process_rxdesc_edma(ah, rs, skb->data);
  527. if (ret == -EINPROGRESS) {
  528. /*let device gain the buffer again*/
  529. dma_sync_single_for_device(sc->dev, bf->bf_buf_addr,
  530. common->rx_bufsize, DMA_FROM_DEVICE);
  531. return false;
  532. }
  533. __skb_unlink(skb, &rx_edma->rx_fifo);
  534. if (ret == -EINVAL) {
  535. /* corrupt descriptor, skip this one and the following one */
  536. list_add_tail(&bf->list, &sc->rx.rxbuf);
  537. ath_rx_edma_buf_link(sc, qtype);
  538. skb = skb_peek(&rx_edma->rx_fifo);
  539. if (skb) {
  540. bf = SKB_CB_ATHBUF(skb);
  541. BUG_ON(!bf);
  542. __skb_unlink(skb, &rx_edma->rx_fifo);
  543. list_add_tail(&bf->list, &sc->rx.rxbuf);
  544. ath_rx_edma_buf_link(sc, qtype);
  545. }
  546. bf = NULL;
  547. }
  548. *dest = bf;
  549. return true;
  550. }
  551. static struct ath_buf *ath_edma_get_next_rx_buf(struct ath_softc *sc,
  552. struct ath_rx_status *rs,
  553. enum ath9k_rx_qtype qtype)
  554. {
  555. struct ath_buf *bf = NULL;
  556. while (ath_edma_get_buffers(sc, qtype, rs, &bf)) {
  557. if (!bf)
  558. continue;
  559. return bf;
  560. }
  561. return NULL;
  562. }
  563. static struct ath_buf *ath_get_next_rx_buf(struct ath_softc *sc,
  564. struct ath_rx_status *rs)
  565. {
  566. struct ath_hw *ah = sc->sc_ah;
  567. struct ath_common *common = ath9k_hw_common(ah);
  568. struct ath_desc *ds;
  569. struct ath_buf *bf;
  570. int ret;
  571. if (list_empty(&sc->rx.rxbuf)) {
  572. sc->rx.rxlink = NULL;
  573. return NULL;
  574. }
  575. bf = list_first_entry(&sc->rx.rxbuf, struct ath_buf, list);
  576. ds = bf->bf_desc;
  577. /*
  578. * Must provide the virtual address of the current
  579. * descriptor, the physical address, and the virtual
  580. * address of the next descriptor in the h/w chain.
  581. * This allows the HAL to look ahead to see if the
  582. * hardware is done with a descriptor by checking the
  583. * done bit in the following descriptor and the address
  584. * of the current descriptor the DMA engine is working
  585. * on. All this is necessary because of our use of
  586. * a self-linked list to avoid rx overruns.
  587. */
  588. ret = ath9k_hw_rxprocdesc(ah, ds, rs);
  589. if (ret == -EINPROGRESS) {
  590. struct ath_rx_status trs;
  591. struct ath_buf *tbf;
  592. struct ath_desc *tds;
  593. memset(&trs, 0, sizeof(trs));
  594. if (list_is_last(&bf->list, &sc->rx.rxbuf)) {
  595. sc->rx.rxlink = NULL;
  596. return NULL;
  597. }
  598. tbf = list_entry(bf->list.next, struct ath_buf, list);
  599. /*
  600. * On some hardware the descriptor status words could
  601. * get corrupted, including the done bit. Because of
  602. * this, check if the next descriptor's done bit is
  603. * set or not.
  604. *
  605. * If the next descriptor's done bit is set, the current
  606. * descriptor has been corrupted. Force s/w to discard
  607. * this descriptor and continue...
  608. */
  609. tds = tbf->bf_desc;
  610. ret = ath9k_hw_rxprocdesc(ah, tds, &trs);
  611. if (ret == -EINPROGRESS)
  612. return NULL;
  613. }
  614. if (!bf->bf_mpdu)
  615. return bf;
  616. /*
  617. * Synchronize the DMA transfer with CPU before
  618. * 1. accessing the frame
  619. * 2. requeueing the same buffer to h/w
  620. */
  621. dma_sync_single_for_cpu(sc->dev, bf->bf_buf_addr,
  622. common->rx_bufsize,
  623. DMA_FROM_DEVICE);
  624. return bf;
  625. }
  626. /* Assumes you've already done the endian to CPU conversion */
  627. static bool ath9k_rx_accept(struct ath_common *common,
  628. struct ieee80211_hdr *hdr,
  629. struct ieee80211_rx_status *rxs,
  630. struct ath_rx_status *rx_stats,
  631. bool *decrypt_error)
  632. {
  633. struct ath_softc *sc = (struct ath_softc *) common->priv;
  634. bool is_mc, is_valid_tkip, strip_mic, mic_error;
  635. struct ath_hw *ah = common->ah;
  636. __le16 fc;
  637. u8 rx_status_len = ah->caps.rx_status_len;
  638. fc = hdr->frame_control;
  639. is_mc = !!is_multicast_ether_addr(hdr->addr1);
  640. is_valid_tkip = rx_stats->rs_keyix != ATH9K_RXKEYIX_INVALID &&
  641. test_bit(rx_stats->rs_keyix, common->tkip_keymap);
  642. strip_mic = is_valid_tkip && ieee80211_is_data(fc) &&
  643. ieee80211_has_protected(fc) &&
  644. !(rx_stats->rs_status &
  645. (ATH9K_RXERR_DECRYPT | ATH9K_RXERR_CRC | ATH9K_RXERR_MIC |
  646. ATH9K_RXERR_KEYMISS));
  647. /*
  648. * Key miss events are only relevant for pairwise keys where the
  649. * descriptor does contain a valid key index. This has been observed
  650. * mostly with CCMP encryption.
  651. */
  652. if (rx_stats->rs_keyix == ATH9K_RXKEYIX_INVALID ||
  653. !test_bit(rx_stats->rs_keyix, common->ccmp_keymap))
  654. rx_stats->rs_status &= ~ATH9K_RXERR_KEYMISS;
  655. if (!rx_stats->rs_datalen) {
  656. RX_STAT_INC(rx_len_err);
  657. return false;
  658. }
  659. /*
  660. * rs_status follows rs_datalen so if rs_datalen is too large
  661. * we can take a hint that hardware corrupted it, so ignore
  662. * those frames.
  663. */
  664. if (rx_stats->rs_datalen > (common->rx_bufsize - rx_status_len)) {
  665. RX_STAT_INC(rx_len_err);
  666. return false;
  667. }
  668. /* Only use error bits from the last fragment */
  669. if (rx_stats->rs_more)
  670. return true;
  671. mic_error = is_valid_tkip && !ieee80211_is_ctl(fc) &&
  672. !ieee80211_has_morefrags(fc) &&
  673. !(le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG) &&
  674. (rx_stats->rs_status & ATH9K_RXERR_MIC);
  675. /*
  676. * The rx_stats->rs_status will not be set until the end of the
  677. * chained descriptors so it can be ignored if rs_more is set. The
  678. * rs_more will be false at the last element of the chained
  679. * descriptors.
  680. */
  681. if (rx_stats->rs_status != 0) {
  682. u8 status_mask;
  683. if (rx_stats->rs_status & ATH9K_RXERR_CRC) {
  684. rxs->flag |= RX_FLAG_FAILED_FCS_CRC;
  685. mic_error = false;
  686. }
  687. if (rx_stats->rs_status & ATH9K_RXERR_PHY)
  688. return false;
  689. if ((rx_stats->rs_status & ATH9K_RXERR_DECRYPT) ||
  690. (!is_mc && (rx_stats->rs_status & ATH9K_RXERR_KEYMISS))) {
  691. *decrypt_error = true;
  692. mic_error = false;
  693. }
  694. /*
  695. * Reject error frames with the exception of
  696. * decryption and MIC failures. For monitor mode,
  697. * we also ignore the CRC error.
  698. */
  699. status_mask = ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC |
  700. ATH9K_RXERR_KEYMISS;
  701. if (ah->is_monitoring && (sc->rx.rxfilter & FIF_FCSFAIL))
  702. status_mask |= ATH9K_RXERR_CRC;
  703. if (rx_stats->rs_status & ~status_mask)
  704. return false;
  705. }
  706. /*
  707. * For unicast frames the MIC error bit can have false positives,
  708. * so all MIC error reports need to be validated in software.
  709. * False negatives are not common, so skip software verification
  710. * if the hardware considers the MIC valid.
  711. */
  712. if (strip_mic)
  713. rxs->flag |= RX_FLAG_MMIC_STRIPPED;
  714. else if (is_mc && mic_error)
  715. rxs->flag |= RX_FLAG_MMIC_ERROR;
  716. return true;
  717. }
  718. static int ath9k_process_rate(struct ath_common *common,
  719. struct ieee80211_hw *hw,
  720. struct ath_rx_status *rx_stats,
  721. struct ieee80211_rx_status *rxs)
  722. {
  723. struct ieee80211_supported_band *sband;
  724. enum ieee80211_band band;
  725. unsigned int i = 0;
  726. struct ath_softc __maybe_unused *sc = common->priv;
  727. band = hw->conf.channel->band;
  728. sband = hw->wiphy->bands[band];
  729. if (rx_stats->rs_rate & 0x80) {
  730. /* HT rate */
  731. rxs->flag |= RX_FLAG_HT;
  732. if (rx_stats->rs_flags & ATH9K_RX_2040)
  733. rxs->flag |= RX_FLAG_40MHZ;
  734. if (rx_stats->rs_flags & ATH9K_RX_GI)
  735. rxs->flag |= RX_FLAG_SHORT_GI;
  736. rxs->rate_idx = rx_stats->rs_rate & 0x7f;
  737. return 0;
  738. }
  739. for (i = 0; i < sband->n_bitrates; i++) {
  740. if (sband->bitrates[i].hw_value == rx_stats->rs_rate) {
  741. rxs->rate_idx = i;
  742. return 0;
  743. }
  744. if (sband->bitrates[i].hw_value_short == rx_stats->rs_rate) {
  745. rxs->flag |= RX_FLAG_SHORTPRE;
  746. rxs->rate_idx = i;
  747. return 0;
  748. }
  749. }
  750. /*
  751. * No valid hardware bitrate found -- we should not get here
  752. * because hardware has already validated this frame as OK.
  753. */
  754. ath_dbg(common, ANY,
  755. "unsupported hw bitrate detected 0x%02x using 1 Mbit\n",
  756. rx_stats->rs_rate);
  757. RX_STAT_INC(rx_rate_err);
  758. return -EINVAL;
  759. }
  760. static void ath9k_process_rssi(struct ath_common *common,
  761. struct ieee80211_hw *hw,
  762. struct ieee80211_hdr *hdr,
  763. struct ath_rx_status *rx_stats)
  764. {
  765. struct ath_softc *sc = hw->priv;
  766. struct ath_hw *ah = common->ah;
  767. int last_rssi;
  768. int rssi = rx_stats->rs_rssi;
  769. if (!rx_stats->is_mybeacon ||
  770. ((ah->opmode != NL80211_IFTYPE_STATION) &&
  771. (ah->opmode != NL80211_IFTYPE_ADHOC)))
  772. return;
  773. if (rx_stats->rs_rssi != ATH9K_RSSI_BAD && !rx_stats->rs_moreaggr)
  774. ATH_RSSI_LPF(sc->last_rssi, rx_stats->rs_rssi);
  775. last_rssi = sc->last_rssi;
  776. if (likely(last_rssi != ATH_RSSI_DUMMY_MARKER))
  777. rssi = ATH_EP_RND(last_rssi, ATH_RSSI_EP_MULTIPLIER);
  778. if (rssi < 0)
  779. rssi = 0;
  780. /* Update Beacon RSSI, this is used by ANI. */
  781. ah->stats.avgbrssi = rssi;
  782. }
  783. /*
  784. * For Decrypt or Demic errors, we only mark packet status here and always push
  785. * up the frame up to let mac80211 handle the actual error case, be it no
  786. * decryption key or real decryption error. This let us keep statistics there.
  787. */
  788. static int ath9k_rx_skb_preprocess(struct ath_common *common,
  789. struct ieee80211_hw *hw,
  790. struct ieee80211_hdr *hdr,
  791. struct ath_rx_status *rx_stats,
  792. struct ieee80211_rx_status *rx_status,
  793. bool *decrypt_error)
  794. {
  795. struct ath_hw *ah = common->ah;
  796. /*
  797. * everything but the rate is checked here, the rate check is done
  798. * separately to avoid doing two lookups for a rate for each frame.
  799. */
  800. if (!ath9k_rx_accept(common, hdr, rx_status, rx_stats, decrypt_error))
  801. return -EINVAL;
  802. /* Only use status info from the last fragment */
  803. if (rx_stats->rs_more)
  804. return 0;
  805. ath9k_process_rssi(common, hw, hdr, rx_stats);
  806. if (ath9k_process_rate(common, hw, rx_stats, rx_status))
  807. return -EINVAL;
  808. rx_status->band = hw->conf.channel->band;
  809. rx_status->freq = hw->conf.channel->center_freq;
  810. rx_status->signal = ah->noise + rx_stats->rs_rssi;
  811. rx_status->antenna = rx_stats->rs_antenna;
  812. rx_status->flag |= RX_FLAG_MACTIME_END;
  813. if (rx_stats->rs_moreaggr)
  814. rx_status->flag |= RX_FLAG_NO_SIGNAL_VAL;
  815. return 0;
  816. }
  817. static void ath9k_rx_skb_postprocess(struct ath_common *common,
  818. struct sk_buff *skb,
  819. struct ath_rx_status *rx_stats,
  820. struct ieee80211_rx_status *rxs,
  821. bool decrypt_error)
  822. {
  823. struct ath_hw *ah = common->ah;
  824. struct ieee80211_hdr *hdr;
  825. int hdrlen, padpos, padsize;
  826. u8 keyix;
  827. __le16 fc;
  828. /* see if any padding is done by the hw and remove it */
  829. hdr = (struct ieee80211_hdr *) skb->data;
  830. hdrlen = ieee80211_get_hdrlen_from_skb(skb);
  831. fc = hdr->frame_control;
  832. padpos = ath9k_cmn_padpos(hdr->frame_control);
  833. /* The MAC header is padded to have 32-bit boundary if the
  834. * packet payload is non-zero. The general calculation for
  835. * padsize would take into account odd header lengths:
  836. * padsize = (4 - padpos % 4) % 4; However, since only
  837. * even-length headers are used, padding can only be 0 or 2
  838. * bytes and we can optimize this a bit. In addition, we must
  839. * not try to remove padding from short control frames that do
  840. * not have payload. */
  841. padsize = padpos & 3;
  842. if (padsize && skb->len>=padpos+padsize+FCS_LEN) {
  843. memmove(skb->data + padsize, skb->data, padpos);
  844. skb_pull(skb, padsize);
  845. }
  846. keyix = rx_stats->rs_keyix;
  847. if (!(keyix == ATH9K_RXKEYIX_INVALID) && !decrypt_error &&
  848. ieee80211_has_protected(fc)) {
  849. rxs->flag |= RX_FLAG_DECRYPTED;
  850. } else if (ieee80211_has_protected(fc)
  851. && !decrypt_error && skb->len >= hdrlen + 4) {
  852. keyix = skb->data[hdrlen + 3] >> 6;
  853. if (test_bit(keyix, common->keymap))
  854. rxs->flag |= RX_FLAG_DECRYPTED;
  855. }
  856. if (ah->sw_mgmt_crypto &&
  857. (rxs->flag & RX_FLAG_DECRYPTED) &&
  858. ieee80211_is_mgmt(fc))
  859. /* Use software decrypt for management frames. */
  860. rxs->flag &= ~RX_FLAG_DECRYPTED;
  861. }
  862. int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp)
  863. {
  864. struct ath_buf *bf;
  865. struct sk_buff *skb = NULL, *requeue_skb, *hdr_skb;
  866. struct ieee80211_rx_status *rxs;
  867. struct ath_hw *ah = sc->sc_ah;
  868. struct ath_common *common = ath9k_hw_common(ah);
  869. struct ieee80211_hw *hw = sc->hw;
  870. struct ieee80211_hdr *hdr;
  871. int retval;
  872. struct ath_rx_status rs;
  873. enum ath9k_rx_qtype qtype;
  874. bool edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA);
  875. int dma_type;
  876. u8 rx_status_len = ah->caps.rx_status_len;
  877. u64 tsf = 0;
  878. u32 tsf_lower = 0;
  879. unsigned long flags;
  880. if (edma)
  881. dma_type = DMA_BIDIRECTIONAL;
  882. else
  883. dma_type = DMA_FROM_DEVICE;
  884. qtype = hp ? ATH9K_RX_QUEUE_HP : ATH9K_RX_QUEUE_LP;
  885. spin_lock_bh(&sc->rx.rxbuflock);
  886. tsf = ath9k_hw_gettsf64(ah);
  887. tsf_lower = tsf & 0xffffffff;
  888. do {
  889. bool decrypt_error = false;
  890. /* If handling rx interrupt and flush is in progress => exit */
  891. if (test_bit(SC_OP_RXFLUSH, &sc->sc_flags) && (flush == 0))
  892. break;
  893. memset(&rs, 0, sizeof(rs));
  894. if (edma)
  895. bf = ath_edma_get_next_rx_buf(sc, &rs, qtype);
  896. else
  897. bf = ath_get_next_rx_buf(sc, &rs);
  898. if (!bf)
  899. break;
  900. skb = bf->bf_mpdu;
  901. if (!skb)
  902. continue;
  903. /*
  904. * Take frame header from the first fragment and RX status from
  905. * the last one.
  906. */
  907. if (sc->rx.frag)
  908. hdr_skb = sc->rx.frag;
  909. else
  910. hdr_skb = skb;
  911. hdr = (struct ieee80211_hdr *) (hdr_skb->data + rx_status_len);
  912. rxs = IEEE80211_SKB_RXCB(hdr_skb);
  913. if (ieee80211_is_beacon(hdr->frame_control)) {
  914. RX_STAT_INC(rx_beacons);
  915. if (!is_zero_ether_addr(common->curbssid) &&
  916. ether_addr_equal(hdr->addr3, common->curbssid))
  917. rs.is_mybeacon = true;
  918. else
  919. rs.is_mybeacon = false;
  920. }
  921. else
  922. rs.is_mybeacon = false;
  923. if (ieee80211_is_data_present(hdr->frame_control) &&
  924. !ieee80211_is_qos_nullfunc(hdr->frame_control))
  925. sc->rx.num_pkts++;
  926. ath_debug_stat_rx(sc, &rs);
  927. /*
  928. * If we're asked to flush receive queue, directly
  929. * chain it back at the queue without processing it.
  930. */
  931. if (test_bit(SC_OP_RXFLUSH, &sc->sc_flags)) {
  932. RX_STAT_INC(rx_drop_rxflush);
  933. goto requeue_drop_frag;
  934. }
  935. memset(rxs, 0, sizeof(struct ieee80211_rx_status));
  936. rxs->mactime = (tsf & ~0xffffffffULL) | rs.rs_tstamp;
  937. if (rs.rs_tstamp > tsf_lower &&
  938. unlikely(rs.rs_tstamp - tsf_lower > 0x10000000))
  939. rxs->mactime -= 0x100000000ULL;
  940. if (rs.rs_tstamp < tsf_lower &&
  941. unlikely(tsf_lower - rs.rs_tstamp > 0x10000000))
  942. rxs->mactime += 0x100000000ULL;
  943. retval = ath9k_rx_skb_preprocess(common, hw, hdr, &rs,
  944. rxs, &decrypt_error);
  945. if (retval)
  946. goto requeue_drop_frag;
  947. if (rs.is_mybeacon) {
  948. sc->hw_busy_count = 0;
  949. ath_start_rx_poll(sc, 3);
  950. }
  951. /* Ensure we always have an skb to requeue once we are done
  952. * processing the current buffer's skb */
  953. requeue_skb = ath_rxbuf_alloc(common, common->rx_bufsize, GFP_ATOMIC);
  954. /* If there is no memory we ignore the current RX'd frame,
  955. * tell hardware it can give us a new frame using the old
  956. * skb and put it at the tail of the sc->rx.rxbuf list for
  957. * processing. */
  958. if (!requeue_skb) {
  959. RX_STAT_INC(rx_oom_err);
  960. goto requeue_drop_frag;
  961. }
  962. /* Unmap the frame */
  963. dma_unmap_single(sc->dev, bf->bf_buf_addr,
  964. common->rx_bufsize,
  965. dma_type);
  966. skb_put(skb, rs.rs_datalen + ah->caps.rx_status_len);
  967. if (ah->caps.rx_status_len)
  968. skb_pull(skb, ah->caps.rx_status_len);
  969. if (!rs.rs_more)
  970. ath9k_rx_skb_postprocess(common, hdr_skb, &rs,
  971. rxs, decrypt_error);
  972. /* We will now give hardware our shiny new allocated skb */
  973. bf->bf_mpdu = requeue_skb;
  974. bf->bf_buf_addr = dma_map_single(sc->dev, requeue_skb->data,
  975. common->rx_bufsize,
  976. dma_type);
  977. if (unlikely(dma_mapping_error(sc->dev,
  978. bf->bf_buf_addr))) {
  979. dev_kfree_skb_any(requeue_skb);
  980. bf->bf_mpdu = NULL;
  981. bf->bf_buf_addr = 0;
  982. ath_err(common, "dma_mapping_error() on RX\n");
  983. ieee80211_rx(hw, skb);
  984. break;
  985. }
  986. if (rs.rs_more) {
  987. RX_STAT_INC(rx_frags);
  988. /*
  989. * rs_more indicates chained descriptors which can be
  990. * used to link buffers together for a sort of
  991. * scatter-gather operation.
  992. */
  993. if (sc->rx.frag) {
  994. /* too many fragments - cannot handle frame */
  995. dev_kfree_skb_any(sc->rx.frag);
  996. dev_kfree_skb_any(skb);
  997. RX_STAT_INC(rx_too_many_frags_err);
  998. skb = NULL;
  999. }
  1000. sc->rx.frag = skb;
  1001. goto requeue;
  1002. }
  1003. if (sc->rx.frag) {
  1004. int space = skb->len - skb_tailroom(hdr_skb);
  1005. if (pskb_expand_head(hdr_skb, 0, space, GFP_ATOMIC) < 0) {
  1006. dev_kfree_skb(skb);
  1007. RX_STAT_INC(rx_oom_err);
  1008. goto requeue_drop_frag;
  1009. }
  1010. sc->rx.frag = NULL;
  1011. skb_copy_from_linear_data(skb, skb_put(hdr_skb, skb->len),
  1012. skb->len);
  1013. dev_kfree_skb_any(skb);
  1014. skb = hdr_skb;
  1015. }
  1016. if (ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB) {
  1017. /*
  1018. * change the default rx antenna if rx diversity
  1019. * chooses the other antenna 3 times in a row.
  1020. */
  1021. if (sc->rx.defant != rs.rs_antenna) {
  1022. if (++sc->rx.rxotherant >= 3)
  1023. ath_setdefantenna(sc, rs.rs_antenna);
  1024. } else {
  1025. sc->rx.rxotherant = 0;
  1026. }
  1027. }
  1028. if (rxs->flag & RX_FLAG_MMIC_STRIPPED)
  1029. skb_trim(skb, skb->len - 8);
  1030. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  1031. if ((sc->ps_flags & (PS_WAIT_FOR_BEACON |
  1032. PS_WAIT_FOR_CAB |
  1033. PS_WAIT_FOR_PSPOLL_DATA)) ||
  1034. ath9k_check_auto_sleep(sc))
  1035. ath_rx_ps(sc, skb, rs.is_mybeacon);
  1036. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  1037. if ((ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB) && sc->ant_rx == 3)
  1038. ath_ant_comb_scan(sc, &rs);
  1039. ieee80211_rx(hw, skb);
  1040. requeue_drop_frag:
  1041. if (sc->rx.frag) {
  1042. dev_kfree_skb_any(sc->rx.frag);
  1043. sc->rx.frag = NULL;
  1044. }
  1045. requeue:
  1046. if (edma) {
  1047. list_add_tail(&bf->list, &sc->rx.rxbuf);
  1048. ath_rx_edma_buf_link(sc, qtype);
  1049. } else {
  1050. list_move_tail(&bf->list, &sc->rx.rxbuf);
  1051. ath_rx_buf_link(sc, bf);
  1052. if (!flush)
  1053. ath9k_hw_rxena(ah);
  1054. }
  1055. } while (1);
  1056. spin_unlock_bh(&sc->rx.rxbuflock);
  1057. if (!(ah->imask & ATH9K_INT_RXEOL)) {
  1058. ah->imask |= (ATH9K_INT_RXEOL | ATH9K_INT_RXORN);
  1059. ath9k_hw_set_interrupts(ah);
  1060. }
  1061. return 0;
  1062. }