recv.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249
  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_rxbuf **)__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_rxbuf *bf,
  34. bool flush)
  35. {
  36. struct ath_hw *ah = sc->sc_ah;
  37. struct ath_common *common = ath9k_hw_common(ah);
  38. struct ath_desc *ds;
  39. struct sk_buff *skb;
  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)
  56. *sc->rx.rxlink = bf->bf_daddr;
  57. else if (!flush)
  58. ath9k_hw_putrxbuf(ah, bf->bf_daddr);
  59. sc->rx.rxlink = &ds->ds_link;
  60. }
  61. static void ath_rx_buf_relink(struct ath_softc *sc, struct ath_rxbuf *bf,
  62. bool flush)
  63. {
  64. if (sc->rx.buf_hold)
  65. ath_rx_buf_link(sc, sc->rx.buf_hold, flush);
  66. sc->rx.buf_hold = bf;
  67. }
  68. static void ath_setdefantenna(struct ath_softc *sc, u32 antenna)
  69. {
  70. /* XXX block beacon interrupts */
  71. ath9k_hw_setantenna(sc->sc_ah, antenna);
  72. sc->rx.defant = antenna;
  73. sc->rx.rxotherant = 0;
  74. }
  75. static void ath_opmode_init(struct ath_softc *sc)
  76. {
  77. struct ath_hw *ah = sc->sc_ah;
  78. struct ath_common *common = ath9k_hw_common(ah);
  79. u32 rfilt, mfilt[2];
  80. /* configure rx filter */
  81. rfilt = ath_calcrxfilter(sc);
  82. ath9k_hw_setrxfilter(ah, rfilt);
  83. /* configure bssid mask */
  84. ath_hw_setbssidmask(common);
  85. /* configure operational mode */
  86. ath9k_hw_setopmode(ah);
  87. /* calculate and install multicast filter */
  88. mfilt[0] = mfilt[1] = ~0;
  89. ath9k_hw_setmcastfilter(ah, mfilt[0], mfilt[1]);
  90. }
  91. static bool ath_rx_edma_buf_link(struct ath_softc *sc,
  92. enum ath9k_rx_qtype qtype)
  93. {
  94. struct ath_hw *ah = sc->sc_ah;
  95. struct ath_rx_edma *rx_edma;
  96. struct sk_buff *skb;
  97. struct ath_rxbuf *bf;
  98. rx_edma = &sc->rx.rx_edma[qtype];
  99. if (skb_queue_len(&rx_edma->rx_fifo) >= rx_edma->rx_fifo_hwsize)
  100. return false;
  101. bf = list_first_entry(&sc->rx.rxbuf, struct ath_rxbuf, list);
  102. list_del_init(&bf->list);
  103. skb = bf->bf_mpdu;
  104. memset(skb->data, 0, ah->caps.rx_status_len);
  105. dma_sync_single_for_device(sc->dev, bf->bf_buf_addr,
  106. ah->caps.rx_status_len, DMA_TO_DEVICE);
  107. SKB_CB_ATHBUF(skb) = bf;
  108. ath9k_hw_addrxbuf_edma(ah, bf->bf_buf_addr, qtype);
  109. __skb_queue_tail(&rx_edma->rx_fifo, skb);
  110. return true;
  111. }
  112. static void ath_rx_addbuffer_edma(struct ath_softc *sc,
  113. enum ath9k_rx_qtype qtype)
  114. {
  115. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  116. struct ath_rxbuf *bf, *tbf;
  117. if (list_empty(&sc->rx.rxbuf)) {
  118. ath_dbg(common, QUEUE, "No free rx buf available\n");
  119. return;
  120. }
  121. list_for_each_entry_safe(bf, tbf, &sc->rx.rxbuf, list)
  122. if (!ath_rx_edma_buf_link(sc, qtype))
  123. break;
  124. }
  125. static void ath_rx_remove_buffer(struct ath_softc *sc,
  126. enum ath9k_rx_qtype qtype)
  127. {
  128. struct ath_rxbuf *bf;
  129. struct ath_rx_edma *rx_edma;
  130. struct sk_buff *skb;
  131. rx_edma = &sc->rx.rx_edma[qtype];
  132. while ((skb = __skb_dequeue(&rx_edma->rx_fifo)) != NULL) {
  133. bf = SKB_CB_ATHBUF(skb);
  134. BUG_ON(!bf);
  135. list_add_tail(&bf->list, &sc->rx.rxbuf);
  136. }
  137. }
  138. static void ath_rx_edma_cleanup(struct ath_softc *sc)
  139. {
  140. struct ath_hw *ah = sc->sc_ah;
  141. struct ath_common *common = ath9k_hw_common(ah);
  142. struct ath_rxbuf *bf;
  143. ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_LP);
  144. ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_HP);
  145. list_for_each_entry(bf, &sc->rx.rxbuf, list) {
  146. if (bf->bf_mpdu) {
  147. dma_unmap_single(sc->dev, bf->bf_buf_addr,
  148. common->rx_bufsize,
  149. DMA_BIDIRECTIONAL);
  150. dev_kfree_skb_any(bf->bf_mpdu);
  151. bf->bf_buf_addr = 0;
  152. bf->bf_mpdu = NULL;
  153. }
  154. }
  155. }
  156. static void ath_rx_edma_init_queue(struct ath_rx_edma *rx_edma, int size)
  157. {
  158. __skb_queue_head_init(&rx_edma->rx_fifo);
  159. rx_edma->rx_fifo_hwsize = size;
  160. }
  161. static int ath_rx_edma_init(struct ath_softc *sc, int nbufs)
  162. {
  163. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  164. struct ath_hw *ah = sc->sc_ah;
  165. struct sk_buff *skb;
  166. struct ath_rxbuf *bf;
  167. int error = 0, i;
  168. u32 size;
  169. ath9k_hw_set_rx_bufsize(ah, common->rx_bufsize -
  170. ah->caps.rx_status_len);
  171. ath_rx_edma_init_queue(&sc->rx.rx_edma[ATH9K_RX_QUEUE_LP],
  172. ah->caps.rx_lp_qdepth);
  173. ath_rx_edma_init_queue(&sc->rx.rx_edma[ATH9K_RX_QUEUE_HP],
  174. ah->caps.rx_hp_qdepth);
  175. size = sizeof(struct ath_rxbuf) * nbufs;
  176. bf = devm_kzalloc(sc->dev, size, GFP_KERNEL);
  177. if (!bf)
  178. return -ENOMEM;
  179. INIT_LIST_HEAD(&sc->rx.rxbuf);
  180. for (i = 0; i < nbufs; i++, bf++) {
  181. skb = ath_rxbuf_alloc(common, common->rx_bufsize, GFP_KERNEL);
  182. if (!skb) {
  183. error = -ENOMEM;
  184. goto rx_init_fail;
  185. }
  186. memset(skb->data, 0, common->rx_bufsize);
  187. bf->bf_mpdu = skb;
  188. bf->bf_buf_addr = dma_map_single(sc->dev, skb->data,
  189. common->rx_bufsize,
  190. DMA_BIDIRECTIONAL);
  191. if (unlikely(dma_mapping_error(sc->dev,
  192. bf->bf_buf_addr))) {
  193. dev_kfree_skb_any(skb);
  194. bf->bf_mpdu = NULL;
  195. bf->bf_buf_addr = 0;
  196. ath_err(common,
  197. "dma_mapping_error() on RX init\n");
  198. error = -ENOMEM;
  199. goto rx_init_fail;
  200. }
  201. list_add_tail(&bf->list, &sc->rx.rxbuf);
  202. }
  203. return 0;
  204. rx_init_fail:
  205. ath_rx_edma_cleanup(sc);
  206. return error;
  207. }
  208. static void ath_edma_start_recv(struct ath_softc *sc)
  209. {
  210. ath9k_hw_rxena(sc->sc_ah);
  211. ath_rx_addbuffer_edma(sc, ATH9K_RX_QUEUE_HP);
  212. ath_rx_addbuffer_edma(sc, ATH9K_RX_QUEUE_LP);
  213. ath_opmode_init(sc);
  214. ath9k_hw_startpcureceive(sc->sc_ah, sc->cur_chan->offchannel);
  215. }
  216. static void ath_edma_stop_recv(struct ath_softc *sc)
  217. {
  218. ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_HP);
  219. ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_LP);
  220. }
  221. int ath_rx_init(struct ath_softc *sc, int nbufs)
  222. {
  223. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  224. struct sk_buff *skb;
  225. struct ath_rxbuf *bf;
  226. int error = 0;
  227. spin_lock_init(&sc->sc_pcu_lock);
  228. common->rx_bufsize = IEEE80211_MAX_MPDU_LEN / 2 +
  229. sc->sc_ah->caps.rx_status_len;
  230. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
  231. return ath_rx_edma_init(sc, nbufs);
  232. ath_dbg(common, CONFIG, "cachelsz %u rxbufsize %u\n",
  233. common->cachelsz, common->rx_bufsize);
  234. /* Initialize rx descriptors */
  235. error = ath_descdma_setup(sc, &sc->rx.rxdma, &sc->rx.rxbuf,
  236. "rx", nbufs, 1, 0);
  237. if (error != 0) {
  238. ath_err(common,
  239. "failed to allocate rx descriptors: %d\n",
  240. error);
  241. goto err;
  242. }
  243. list_for_each_entry(bf, &sc->rx.rxbuf, list) {
  244. skb = ath_rxbuf_alloc(common, common->rx_bufsize,
  245. GFP_KERNEL);
  246. if (skb == NULL) {
  247. error = -ENOMEM;
  248. goto err;
  249. }
  250. bf->bf_mpdu = skb;
  251. bf->bf_buf_addr = dma_map_single(sc->dev, skb->data,
  252. common->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. bf->bf_buf_addr = 0;
  259. ath_err(common,
  260. "dma_mapping_error() on RX init\n");
  261. error = -ENOMEM;
  262. goto err;
  263. }
  264. }
  265. sc->rx.rxlink = NULL;
  266. err:
  267. if (error)
  268. ath_rx_cleanup(sc);
  269. return error;
  270. }
  271. void ath_rx_cleanup(struct ath_softc *sc)
  272. {
  273. struct ath_hw *ah = sc->sc_ah;
  274. struct ath_common *common = ath9k_hw_common(ah);
  275. struct sk_buff *skb;
  276. struct ath_rxbuf *bf;
  277. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
  278. ath_rx_edma_cleanup(sc);
  279. return;
  280. }
  281. list_for_each_entry(bf, &sc->rx.rxbuf, list) {
  282. skb = bf->bf_mpdu;
  283. if (skb) {
  284. dma_unmap_single(sc->dev, bf->bf_buf_addr,
  285. common->rx_bufsize,
  286. DMA_FROM_DEVICE);
  287. dev_kfree_skb(skb);
  288. bf->bf_buf_addr = 0;
  289. bf->bf_mpdu = NULL;
  290. }
  291. }
  292. }
  293. /*
  294. * Calculate the receive filter according to the
  295. * operating mode and state:
  296. *
  297. * o always accept unicast, broadcast, and multicast traffic
  298. * o maintain current state of phy error reception (the hal
  299. * may enable phy error frames for noise immunity work)
  300. * o probe request frames are accepted only when operating in
  301. * hostap, adhoc, or monitor modes
  302. * o enable promiscuous mode according to the interface state
  303. * o accept beacons:
  304. * - when operating in adhoc mode so the 802.11 layer creates
  305. * node table entries for peers,
  306. * - when operating in station mode for collecting rssi data when
  307. * the station is otherwise quiet, or
  308. * - when operating as a repeater so we see repeater-sta beacons
  309. * - when scanning
  310. */
  311. u32 ath_calcrxfilter(struct ath_softc *sc)
  312. {
  313. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  314. u32 rfilt;
  315. if (IS_ENABLED(CONFIG_ATH9K_TX99))
  316. return 0;
  317. rfilt = ATH9K_RX_FILTER_UCAST | ATH9K_RX_FILTER_BCAST
  318. | ATH9K_RX_FILTER_MCAST;
  319. /* if operating on a DFS channel, enable radar pulse detection */
  320. if (sc->hw->conf.radar_enabled)
  321. rfilt |= ATH9K_RX_FILTER_PHYRADAR | ATH9K_RX_FILTER_PHYERR;
  322. spin_lock_bh(&sc->chan_lock);
  323. if (sc->cur_chan->rxfilter & FIF_PROBE_REQ)
  324. rfilt |= ATH9K_RX_FILTER_PROBEREQ;
  325. if (sc->sc_ah->is_monitoring)
  326. rfilt |= ATH9K_RX_FILTER_PROM;
  327. if ((sc->cur_chan->rxfilter & FIF_CONTROL) ||
  328. sc->sc_ah->dynack.enabled)
  329. rfilt |= ATH9K_RX_FILTER_CONTROL;
  330. if ((sc->sc_ah->opmode == NL80211_IFTYPE_STATION) &&
  331. (sc->cur_chan->nvifs <= 1) &&
  332. !(sc->cur_chan->rxfilter & FIF_BCN_PRBRESP_PROMISC))
  333. rfilt |= ATH9K_RX_FILTER_MYBEACON;
  334. else if (sc->sc_ah->opmode != NL80211_IFTYPE_OCB)
  335. rfilt |= ATH9K_RX_FILTER_BEACON;
  336. if ((sc->sc_ah->opmode == NL80211_IFTYPE_AP) ||
  337. (sc->cur_chan->rxfilter & FIF_PSPOLL))
  338. rfilt |= ATH9K_RX_FILTER_PSPOLL;
  339. if (sc->cur_chandef.width != NL80211_CHAN_WIDTH_20_NOHT)
  340. rfilt |= ATH9K_RX_FILTER_COMP_BAR;
  341. if (sc->cur_chan->nvifs > 1 || (sc->cur_chan->rxfilter & FIF_OTHER_BSS)) {
  342. /* This is needed for older chips */
  343. if (sc->sc_ah->hw_version.macVersion <= AR_SREV_VERSION_9160)
  344. rfilt |= ATH9K_RX_FILTER_PROM;
  345. rfilt |= ATH9K_RX_FILTER_MCAST_BCAST_ALL;
  346. }
  347. if (AR_SREV_9550(sc->sc_ah) || AR_SREV_9531(sc->sc_ah) ||
  348. AR_SREV_9561(sc->sc_ah))
  349. rfilt |= ATH9K_RX_FILTER_4ADDRESS;
  350. if (AR_SREV_9462(sc->sc_ah) || AR_SREV_9565(sc->sc_ah))
  351. rfilt |= ATH9K_RX_FILTER_CONTROL_WRAPPER;
  352. if (ath9k_is_chanctx_enabled() &&
  353. test_bit(ATH_OP_SCANNING, &common->op_flags))
  354. rfilt |= ATH9K_RX_FILTER_BEACON;
  355. spin_unlock_bh(&sc->chan_lock);
  356. return rfilt;
  357. }
  358. void ath_startrecv(struct ath_softc *sc)
  359. {
  360. struct ath_hw *ah = sc->sc_ah;
  361. struct ath_rxbuf *bf, *tbf;
  362. if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
  363. ath_edma_start_recv(sc);
  364. return;
  365. }
  366. if (list_empty(&sc->rx.rxbuf))
  367. goto start_recv;
  368. sc->rx.buf_hold = NULL;
  369. sc->rx.rxlink = NULL;
  370. list_for_each_entry_safe(bf, tbf, &sc->rx.rxbuf, list) {
  371. ath_rx_buf_link(sc, bf, false);
  372. }
  373. /* We could have deleted elements so the list may be empty now */
  374. if (list_empty(&sc->rx.rxbuf))
  375. goto start_recv;
  376. bf = list_first_entry(&sc->rx.rxbuf, struct ath_rxbuf, list);
  377. ath9k_hw_putrxbuf(ah, bf->bf_daddr);
  378. ath9k_hw_rxena(ah);
  379. start_recv:
  380. ath_opmode_init(sc);
  381. ath9k_hw_startpcureceive(ah, sc->cur_chan->offchannel);
  382. }
  383. static void ath_flushrecv(struct ath_softc *sc)
  384. {
  385. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
  386. ath_rx_tasklet(sc, 1, true);
  387. ath_rx_tasklet(sc, 1, false);
  388. }
  389. bool ath_stoprecv(struct ath_softc *sc)
  390. {
  391. struct ath_hw *ah = sc->sc_ah;
  392. bool stopped, reset = false;
  393. ath9k_hw_abortpcurecv(ah);
  394. ath9k_hw_setrxfilter(ah, 0);
  395. stopped = ath9k_hw_stopdmarecv(ah, &reset);
  396. ath_flushrecv(sc);
  397. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
  398. ath_edma_stop_recv(sc);
  399. else
  400. sc->rx.rxlink = NULL;
  401. if (!(ah->ah_flags & AH_UNPLUGGED) &&
  402. unlikely(!stopped)) {
  403. ath_dbg(ath9k_hw_common(sc->sc_ah), RESET,
  404. "Failed to stop Rx DMA\n");
  405. RESET_STAT_INC(sc, RESET_RX_DMA_ERROR);
  406. }
  407. return stopped && !reset;
  408. }
  409. static bool ath_beacon_dtim_pending_cab(struct sk_buff *skb)
  410. {
  411. /* Check whether the Beacon frame has DTIM indicating buffered bc/mc */
  412. struct ieee80211_mgmt *mgmt;
  413. u8 *pos, *end, id, elen;
  414. struct ieee80211_tim_ie *tim;
  415. mgmt = (struct ieee80211_mgmt *)skb->data;
  416. pos = mgmt->u.beacon.variable;
  417. end = skb->data + skb->len;
  418. while (pos + 2 < end) {
  419. id = *pos++;
  420. elen = *pos++;
  421. if (pos + elen > end)
  422. break;
  423. if (id == WLAN_EID_TIM) {
  424. if (elen < sizeof(*tim))
  425. break;
  426. tim = (struct ieee80211_tim_ie *) pos;
  427. if (tim->dtim_count != 0)
  428. break;
  429. return tim->bitmap_ctrl & 0x01;
  430. }
  431. pos += elen;
  432. }
  433. return false;
  434. }
  435. static void ath_rx_ps_beacon(struct ath_softc *sc, struct sk_buff *skb)
  436. {
  437. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  438. bool skip_beacon = false;
  439. if (skb->len < 24 + 8 + 2 + 2)
  440. return;
  441. sc->ps_flags &= ~PS_WAIT_FOR_BEACON;
  442. if (sc->ps_flags & PS_BEACON_SYNC) {
  443. sc->ps_flags &= ~PS_BEACON_SYNC;
  444. ath_dbg(common, PS,
  445. "Reconfigure beacon timers based on synchronized timestamp\n");
  446. #ifdef CONFIG_ATH9K_CHANNEL_CONTEXT
  447. if (ath9k_is_chanctx_enabled()) {
  448. if (sc->cur_chan == &sc->offchannel.chan)
  449. skip_beacon = true;
  450. }
  451. #endif
  452. if (!skip_beacon &&
  453. !(WARN_ON_ONCE(sc->cur_chan->beacon.beacon_interval == 0)))
  454. ath9k_set_beacon(sc);
  455. ath9k_p2p_beacon_sync(sc);
  456. }
  457. if (ath_beacon_dtim_pending_cab(skb)) {
  458. /*
  459. * Remain awake waiting for buffered broadcast/multicast
  460. * frames. If the last broadcast/multicast frame is not
  461. * received properly, the next beacon frame will work as
  462. * a backup trigger for returning into NETWORK SLEEP state,
  463. * so we are waiting for it as well.
  464. */
  465. ath_dbg(common, PS,
  466. "Received DTIM beacon indicating buffered broadcast/multicast frame(s)\n");
  467. sc->ps_flags |= PS_WAIT_FOR_CAB | PS_WAIT_FOR_BEACON;
  468. return;
  469. }
  470. if (sc->ps_flags & PS_WAIT_FOR_CAB) {
  471. /*
  472. * This can happen if a broadcast frame is dropped or the AP
  473. * fails to send a frame indicating that all CAB frames have
  474. * been delivered.
  475. */
  476. sc->ps_flags &= ~PS_WAIT_FOR_CAB;
  477. ath_dbg(common, PS, "PS wait for CAB frames timed out\n");
  478. }
  479. }
  480. static void ath_rx_ps(struct ath_softc *sc, struct sk_buff *skb, bool mybeacon)
  481. {
  482. struct ieee80211_hdr *hdr;
  483. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  484. hdr = (struct ieee80211_hdr *)skb->data;
  485. /* Process Beacon and CAB receive in PS state */
  486. if (((sc->ps_flags & PS_WAIT_FOR_BEACON) || ath9k_check_auto_sleep(sc))
  487. && mybeacon) {
  488. ath_rx_ps_beacon(sc, skb);
  489. } else if ((sc->ps_flags & PS_WAIT_FOR_CAB) &&
  490. (ieee80211_is_data(hdr->frame_control) ||
  491. ieee80211_is_action(hdr->frame_control)) &&
  492. is_multicast_ether_addr(hdr->addr1) &&
  493. !ieee80211_has_moredata(hdr->frame_control)) {
  494. /*
  495. * No more broadcast/multicast frames to be received at this
  496. * point.
  497. */
  498. sc->ps_flags &= ~(PS_WAIT_FOR_CAB | PS_WAIT_FOR_BEACON);
  499. ath_dbg(common, PS,
  500. "All PS CAB frames received, back to sleep\n");
  501. } else if ((sc->ps_flags & PS_WAIT_FOR_PSPOLL_DATA) &&
  502. !is_multicast_ether_addr(hdr->addr1) &&
  503. !ieee80211_has_morefrags(hdr->frame_control)) {
  504. sc->ps_flags &= ~PS_WAIT_FOR_PSPOLL_DATA;
  505. ath_dbg(common, PS,
  506. "Going back to sleep after having received PS-Poll data (0x%lx)\n",
  507. sc->ps_flags & (PS_WAIT_FOR_BEACON |
  508. PS_WAIT_FOR_CAB |
  509. PS_WAIT_FOR_PSPOLL_DATA |
  510. PS_WAIT_FOR_TX_ACK));
  511. }
  512. }
  513. static bool ath_edma_get_buffers(struct ath_softc *sc,
  514. enum ath9k_rx_qtype qtype,
  515. struct ath_rx_status *rs,
  516. struct ath_rxbuf **dest)
  517. {
  518. struct ath_rx_edma *rx_edma = &sc->rx.rx_edma[qtype];
  519. struct ath_hw *ah = sc->sc_ah;
  520. struct ath_common *common = ath9k_hw_common(ah);
  521. struct sk_buff *skb;
  522. struct ath_rxbuf *bf;
  523. int ret;
  524. skb = skb_peek(&rx_edma->rx_fifo);
  525. if (!skb)
  526. return false;
  527. bf = SKB_CB_ATHBUF(skb);
  528. BUG_ON(!bf);
  529. dma_sync_single_for_cpu(sc->dev, bf->bf_buf_addr,
  530. common->rx_bufsize, DMA_FROM_DEVICE);
  531. ret = ath9k_hw_process_rxdesc_edma(ah, rs, skb->data);
  532. if (ret == -EINPROGRESS) {
  533. /*let device gain the buffer again*/
  534. dma_sync_single_for_device(sc->dev, bf->bf_buf_addr,
  535. common->rx_bufsize, DMA_FROM_DEVICE);
  536. return false;
  537. }
  538. __skb_unlink(skb, &rx_edma->rx_fifo);
  539. if (ret == -EINVAL) {
  540. /* corrupt descriptor, skip this one and the following one */
  541. list_add_tail(&bf->list, &sc->rx.rxbuf);
  542. ath_rx_edma_buf_link(sc, qtype);
  543. skb = skb_peek(&rx_edma->rx_fifo);
  544. if (skb) {
  545. bf = SKB_CB_ATHBUF(skb);
  546. BUG_ON(!bf);
  547. __skb_unlink(skb, &rx_edma->rx_fifo);
  548. list_add_tail(&bf->list, &sc->rx.rxbuf);
  549. ath_rx_edma_buf_link(sc, qtype);
  550. }
  551. bf = NULL;
  552. }
  553. *dest = bf;
  554. return true;
  555. }
  556. static struct ath_rxbuf *ath_edma_get_next_rx_buf(struct ath_softc *sc,
  557. struct ath_rx_status *rs,
  558. enum ath9k_rx_qtype qtype)
  559. {
  560. struct ath_rxbuf *bf = NULL;
  561. while (ath_edma_get_buffers(sc, qtype, rs, &bf)) {
  562. if (!bf)
  563. continue;
  564. return bf;
  565. }
  566. return NULL;
  567. }
  568. static struct ath_rxbuf *ath_get_next_rx_buf(struct ath_softc *sc,
  569. struct ath_rx_status *rs)
  570. {
  571. struct ath_hw *ah = sc->sc_ah;
  572. struct ath_common *common = ath9k_hw_common(ah);
  573. struct ath_desc *ds;
  574. struct ath_rxbuf *bf;
  575. int ret;
  576. if (list_empty(&sc->rx.rxbuf)) {
  577. sc->rx.rxlink = NULL;
  578. return NULL;
  579. }
  580. bf = list_first_entry(&sc->rx.rxbuf, struct ath_rxbuf, list);
  581. if (bf == sc->rx.buf_hold)
  582. return NULL;
  583. ds = bf->bf_desc;
  584. /*
  585. * Must provide the virtual address of the current
  586. * descriptor, the physical address, and the virtual
  587. * address of the next descriptor in the h/w chain.
  588. * This allows the HAL to look ahead to see if the
  589. * hardware is done with a descriptor by checking the
  590. * done bit in the following descriptor and the address
  591. * of the current descriptor the DMA engine is working
  592. * on. All this is necessary because of our use of
  593. * a self-linked list to avoid rx overruns.
  594. */
  595. ret = ath9k_hw_rxprocdesc(ah, ds, rs);
  596. if (ret == -EINPROGRESS) {
  597. struct ath_rx_status trs;
  598. struct ath_rxbuf *tbf;
  599. struct ath_desc *tds;
  600. memset(&trs, 0, sizeof(trs));
  601. if (list_is_last(&bf->list, &sc->rx.rxbuf)) {
  602. sc->rx.rxlink = NULL;
  603. return NULL;
  604. }
  605. tbf = list_entry(bf->list.next, struct ath_rxbuf, list);
  606. /*
  607. * On some hardware the descriptor status words could
  608. * get corrupted, including the done bit. Because of
  609. * this, check if the next descriptor's done bit is
  610. * set or not.
  611. *
  612. * If the next descriptor's done bit is set, the current
  613. * descriptor has been corrupted. Force s/w to discard
  614. * this descriptor and continue...
  615. */
  616. tds = tbf->bf_desc;
  617. ret = ath9k_hw_rxprocdesc(ah, tds, &trs);
  618. if (ret == -EINPROGRESS)
  619. return NULL;
  620. /*
  621. * Re-check previous descriptor, in case it has been filled
  622. * in the mean time.
  623. */
  624. ret = ath9k_hw_rxprocdesc(ah, ds, rs);
  625. if (ret == -EINPROGRESS) {
  626. /*
  627. * mark descriptor as zero-length and set the 'more'
  628. * flag to ensure that both buffers get discarded
  629. */
  630. rs->rs_datalen = 0;
  631. rs->rs_more = true;
  632. }
  633. }
  634. list_del(&bf->list);
  635. if (!bf->bf_mpdu)
  636. return bf;
  637. /*
  638. * Synchronize the DMA transfer with CPU before
  639. * 1. accessing the frame
  640. * 2. requeueing the same buffer to h/w
  641. */
  642. dma_sync_single_for_cpu(sc->dev, bf->bf_buf_addr,
  643. common->rx_bufsize,
  644. DMA_FROM_DEVICE);
  645. return bf;
  646. }
  647. static void ath9k_process_tsf(struct ath_rx_status *rs,
  648. struct ieee80211_rx_status *rxs,
  649. u64 tsf)
  650. {
  651. u32 tsf_lower = tsf & 0xffffffff;
  652. rxs->mactime = (tsf & ~0xffffffffULL) | rs->rs_tstamp;
  653. if (rs->rs_tstamp > tsf_lower &&
  654. unlikely(rs->rs_tstamp - tsf_lower > 0x10000000))
  655. rxs->mactime -= 0x100000000ULL;
  656. if (rs->rs_tstamp < tsf_lower &&
  657. unlikely(tsf_lower - rs->rs_tstamp > 0x10000000))
  658. rxs->mactime += 0x100000000ULL;
  659. }
  660. /*
  661. * For Decrypt or Demic errors, we only mark packet status here and always push
  662. * up the frame up to let mac80211 handle the actual error case, be it no
  663. * decryption key or real decryption error. This let us keep statistics there.
  664. */
  665. static int ath9k_rx_skb_preprocess(struct ath_softc *sc,
  666. struct sk_buff *skb,
  667. struct ath_rx_status *rx_stats,
  668. struct ieee80211_rx_status *rx_status,
  669. bool *decrypt_error, u64 tsf)
  670. {
  671. struct ieee80211_hw *hw = sc->hw;
  672. struct ath_hw *ah = sc->sc_ah;
  673. struct ath_common *common = ath9k_hw_common(ah);
  674. struct ieee80211_hdr *hdr;
  675. bool discard_current = sc->rx.discard_next;
  676. /*
  677. * Discard corrupt descriptors which are marked in
  678. * ath_get_next_rx_buf().
  679. */
  680. if (discard_current)
  681. goto corrupt;
  682. sc->rx.discard_next = false;
  683. /*
  684. * Discard zero-length packets.
  685. */
  686. if (!rx_stats->rs_datalen) {
  687. RX_STAT_INC(rx_len_err);
  688. goto corrupt;
  689. }
  690. /*
  691. * rs_status follows rs_datalen so if rs_datalen is too large
  692. * we can take a hint that hardware corrupted it, so ignore
  693. * those frames.
  694. */
  695. if (rx_stats->rs_datalen > (common->rx_bufsize - ah->caps.rx_status_len)) {
  696. RX_STAT_INC(rx_len_err);
  697. goto corrupt;
  698. }
  699. /* Only use status info from the last fragment */
  700. if (rx_stats->rs_more)
  701. return 0;
  702. /*
  703. * Return immediately if the RX descriptor has been marked
  704. * as corrupt based on the various error bits.
  705. *
  706. * This is different from the other corrupt descriptor
  707. * condition handled above.
  708. */
  709. if (rx_stats->rs_status & ATH9K_RXERR_CORRUPT_DESC)
  710. goto corrupt;
  711. hdr = (struct ieee80211_hdr *) (skb->data + ah->caps.rx_status_len);
  712. ath9k_process_tsf(rx_stats, rx_status, tsf);
  713. ath_debug_stat_rx(sc, rx_stats);
  714. /*
  715. * Process PHY errors and return so that the packet
  716. * can be dropped.
  717. */
  718. if (rx_stats->rs_status & ATH9K_RXERR_PHY) {
  719. /*
  720. * DFS and spectral are mutually exclusive
  721. *
  722. * Since some chips use PHYERR_RADAR as indication for both, we
  723. * need to double check which feature is enabled to prevent
  724. * feeding spectral or dfs-detector with wrong frames.
  725. */
  726. if (hw->conf.radar_enabled) {
  727. ath9k_dfs_process_phyerr(sc, hdr, rx_stats,
  728. rx_status->mactime);
  729. } else if (sc->spec_priv.spectral_mode != SPECTRAL_DISABLED &&
  730. ath_cmn_process_fft(&sc->spec_priv, hdr, rx_stats,
  731. rx_status->mactime)) {
  732. RX_STAT_INC(rx_spectral);
  733. }
  734. return -EINVAL;
  735. }
  736. /*
  737. * everything but the rate is checked here, the rate check is done
  738. * separately to avoid doing two lookups for a rate for each frame.
  739. */
  740. spin_lock_bh(&sc->chan_lock);
  741. if (!ath9k_cmn_rx_accept(common, hdr, rx_status, rx_stats, decrypt_error,
  742. sc->cur_chan->rxfilter)) {
  743. spin_unlock_bh(&sc->chan_lock);
  744. return -EINVAL;
  745. }
  746. spin_unlock_bh(&sc->chan_lock);
  747. if (ath_is_mybeacon(common, hdr)) {
  748. RX_STAT_INC(rx_beacons);
  749. rx_stats->is_mybeacon = true;
  750. }
  751. /*
  752. * This shouldn't happen, but have a safety check anyway.
  753. */
  754. if (WARN_ON(!ah->curchan))
  755. return -EINVAL;
  756. if (ath9k_cmn_process_rate(common, hw, rx_stats, rx_status)) {
  757. /*
  758. * No valid hardware bitrate found -- we should not get here
  759. * because hardware has already validated this frame as OK.
  760. */
  761. ath_dbg(common, ANY, "unsupported hw bitrate detected 0x%02x using 1 Mbit\n",
  762. rx_stats->rs_rate);
  763. RX_STAT_INC(rx_rate_err);
  764. return -EINVAL;
  765. }
  766. if (ath9k_is_chanctx_enabled()) {
  767. if (rx_stats->is_mybeacon)
  768. ath_chanctx_beacon_recv_ev(sc,
  769. ATH_CHANCTX_EVENT_BEACON_RECEIVED);
  770. }
  771. ath9k_cmn_process_rssi(common, hw, rx_stats, rx_status);
  772. rx_status->band = ah->curchan->chan->band;
  773. rx_status->freq = ah->curchan->chan->center_freq;
  774. rx_status->antenna = rx_stats->rs_antenna;
  775. rx_status->flag |= RX_FLAG_MACTIME_END;
  776. #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
  777. if (ieee80211_is_data_present(hdr->frame_control) &&
  778. !ieee80211_is_qos_nullfunc(hdr->frame_control))
  779. sc->rx.num_pkts++;
  780. #endif
  781. return 0;
  782. corrupt:
  783. sc->rx.discard_next = rx_stats->rs_more;
  784. return -EINVAL;
  785. }
  786. /*
  787. * Run the LNA combining algorithm only in these cases:
  788. *
  789. * Standalone WLAN cards with both LNA/Antenna diversity
  790. * enabled in the EEPROM.
  791. *
  792. * WLAN+BT cards which are in the supported card list
  793. * in ath_pci_id_table and the user has loaded the
  794. * driver with "bt_ant_diversity" set to true.
  795. */
  796. static void ath9k_antenna_check(struct ath_softc *sc,
  797. struct ath_rx_status *rs)
  798. {
  799. struct ath_hw *ah = sc->sc_ah;
  800. struct ath9k_hw_capabilities *pCap = &ah->caps;
  801. struct ath_common *common = ath9k_hw_common(ah);
  802. if (!(ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB))
  803. return;
  804. /*
  805. * Change the default rx antenna if rx diversity
  806. * chooses the other antenna 3 times in a row.
  807. */
  808. if (sc->rx.defant != rs->rs_antenna) {
  809. if (++sc->rx.rxotherant >= 3)
  810. ath_setdefantenna(sc, rs->rs_antenna);
  811. } else {
  812. sc->rx.rxotherant = 0;
  813. }
  814. if (pCap->hw_caps & ATH9K_HW_CAP_BT_ANT_DIV) {
  815. if (common->bt_ant_diversity)
  816. ath_ant_comb_scan(sc, rs);
  817. } else {
  818. ath_ant_comb_scan(sc, rs);
  819. }
  820. }
  821. static void ath9k_apply_ampdu_details(struct ath_softc *sc,
  822. struct ath_rx_status *rs, struct ieee80211_rx_status *rxs)
  823. {
  824. if (rs->rs_isaggr) {
  825. rxs->flag |= RX_FLAG_AMPDU_DETAILS | RX_FLAG_AMPDU_LAST_KNOWN;
  826. rxs->ampdu_reference = sc->rx.ampdu_ref;
  827. if (!rs->rs_moreaggr) {
  828. rxs->flag |= RX_FLAG_AMPDU_IS_LAST;
  829. sc->rx.ampdu_ref++;
  830. }
  831. if (rs->rs_flags & ATH9K_RX_DELIM_CRC_PRE)
  832. rxs->flag |= RX_FLAG_AMPDU_DELIM_CRC_ERROR;
  833. }
  834. }
  835. static void ath_rx_count_airtime(struct ath_softc *sc,
  836. struct ath_rx_status *rs,
  837. struct sk_buff *skb)
  838. {
  839. struct ath_node *an;
  840. struct ath_acq *acq;
  841. struct ath_vif *avp;
  842. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  843. struct ath_hw *ah = sc->sc_ah;
  844. struct ath_common *common = ath9k_hw_common(ah);
  845. struct ieee80211_sta *sta;
  846. struct ieee80211_rx_status *rxs;
  847. const struct ieee80211_rate *rate;
  848. bool is_sgi, is_40, is_sp;
  849. int phy;
  850. u16 len = rs->rs_datalen;
  851. u32 airtime = 0;
  852. u8 tidno, acno;
  853. if (!ieee80211_is_data(hdr->frame_control))
  854. return;
  855. rcu_read_lock();
  856. sta = ieee80211_find_sta_by_ifaddr(sc->hw, hdr->addr2, NULL);
  857. if (!sta)
  858. goto exit;
  859. an = (struct ath_node *) sta->drv_priv;
  860. avp = (struct ath_vif *) an->vif->drv_priv;
  861. tidno = skb->priority & IEEE80211_QOS_CTL_TID_MASK;
  862. acno = TID_TO_WME_AC(tidno);
  863. acq = &avp->chanctx->acq[acno];
  864. rxs = IEEE80211_SKB_RXCB(skb);
  865. is_sgi = !!(rxs->enc_flags & RX_ENC_FLAG_SHORT_GI);
  866. is_40 = !!(rxs->bw == RATE_INFO_BW_40);
  867. is_sp = !!(rxs->enc_flags & RX_ENC_FLAG_SHORTPRE);
  868. if (!!(rxs->encoding == RX_ENC_HT)) {
  869. /* MCS rates */
  870. airtime += ath_pkt_duration(sc, rxs->rate_idx, len,
  871. is_40, is_sgi, is_sp);
  872. } else {
  873. phy = IS_CCK_RATE(rs->rs_rate) ? WLAN_RC_PHY_CCK : WLAN_RC_PHY_OFDM;
  874. rate = &common->sbands[rxs->band].bitrates[rxs->rate_idx];
  875. airtime += ath9k_hw_computetxtime(ah, phy, rate->bitrate * 100,
  876. len, rxs->rate_idx, is_sp);
  877. }
  878. if (!!(sc->airtime_flags & AIRTIME_USE_RX)) {
  879. spin_lock_bh(&acq->lock);
  880. an->airtime_deficit[acno] -= airtime;
  881. if (an->airtime_deficit[acno] <= 0)
  882. __ath_tx_queue_tid(sc, ATH_AN_2_TID(an, tidno));
  883. spin_unlock_bh(&acq->lock);
  884. }
  885. ath_debug_airtime(sc, an, airtime, 0);
  886. exit:
  887. rcu_read_unlock();
  888. }
  889. int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp)
  890. {
  891. struct ath_rxbuf *bf;
  892. struct sk_buff *skb = NULL, *requeue_skb, *hdr_skb;
  893. struct ieee80211_rx_status *rxs;
  894. struct ath_hw *ah = sc->sc_ah;
  895. struct ath_common *common = ath9k_hw_common(ah);
  896. struct ieee80211_hw *hw = sc->hw;
  897. int retval;
  898. struct ath_rx_status rs;
  899. enum ath9k_rx_qtype qtype;
  900. bool edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA);
  901. int dma_type;
  902. u64 tsf = 0;
  903. unsigned long flags;
  904. dma_addr_t new_buf_addr;
  905. unsigned int budget = 512;
  906. struct ieee80211_hdr *hdr;
  907. if (edma)
  908. dma_type = DMA_BIDIRECTIONAL;
  909. else
  910. dma_type = DMA_FROM_DEVICE;
  911. qtype = hp ? ATH9K_RX_QUEUE_HP : ATH9K_RX_QUEUE_LP;
  912. tsf = ath9k_hw_gettsf64(ah);
  913. do {
  914. bool decrypt_error = false;
  915. memset(&rs, 0, sizeof(rs));
  916. if (edma)
  917. bf = ath_edma_get_next_rx_buf(sc, &rs, qtype);
  918. else
  919. bf = ath_get_next_rx_buf(sc, &rs);
  920. if (!bf)
  921. break;
  922. skb = bf->bf_mpdu;
  923. if (!skb)
  924. continue;
  925. /*
  926. * Take frame header from the first fragment and RX status from
  927. * the last one.
  928. */
  929. if (sc->rx.frag)
  930. hdr_skb = sc->rx.frag;
  931. else
  932. hdr_skb = skb;
  933. rxs = IEEE80211_SKB_RXCB(hdr_skb);
  934. memset(rxs, 0, sizeof(struct ieee80211_rx_status));
  935. retval = ath9k_rx_skb_preprocess(sc, hdr_skb, &rs, rxs,
  936. &decrypt_error, tsf);
  937. if (retval)
  938. goto requeue_drop_frag;
  939. /* Ensure we always have an skb to requeue once we are done
  940. * processing the current buffer's skb */
  941. requeue_skb = ath_rxbuf_alloc(common, common->rx_bufsize, GFP_ATOMIC);
  942. /* If there is no memory we ignore the current RX'd frame,
  943. * tell hardware it can give us a new frame using the old
  944. * skb and put it at the tail of the sc->rx.rxbuf list for
  945. * processing. */
  946. if (!requeue_skb) {
  947. RX_STAT_INC(rx_oom_err);
  948. goto requeue_drop_frag;
  949. }
  950. /* We will now give hardware our shiny new allocated skb */
  951. new_buf_addr = dma_map_single(sc->dev, requeue_skb->data,
  952. common->rx_bufsize, dma_type);
  953. if (unlikely(dma_mapping_error(sc->dev, new_buf_addr))) {
  954. dev_kfree_skb_any(requeue_skb);
  955. goto requeue_drop_frag;
  956. }
  957. /* Unmap the frame */
  958. dma_unmap_single(sc->dev, bf->bf_buf_addr,
  959. common->rx_bufsize, dma_type);
  960. bf->bf_mpdu = requeue_skb;
  961. bf->bf_buf_addr = new_buf_addr;
  962. skb_put(skb, rs.rs_datalen + ah->caps.rx_status_len);
  963. if (ah->caps.rx_status_len)
  964. skb_pull(skb, ah->caps.rx_status_len);
  965. if (!rs.rs_more)
  966. ath9k_cmn_rx_skb_postprocess(common, hdr_skb, &rs,
  967. rxs, decrypt_error);
  968. if (rs.rs_more) {
  969. RX_STAT_INC(rx_frags);
  970. /*
  971. * rs_more indicates chained descriptors which can be
  972. * used to link buffers together for a sort of
  973. * scatter-gather operation.
  974. */
  975. if (sc->rx.frag) {
  976. /* too many fragments - cannot handle frame */
  977. dev_kfree_skb_any(sc->rx.frag);
  978. dev_kfree_skb_any(skb);
  979. RX_STAT_INC(rx_too_many_frags_err);
  980. skb = NULL;
  981. }
  982. sc->rx.frag = skb;
  983. goto requeue;
  984. }
  985. if (sc->rx.frag) {
  986. int space = skb->len - skb_tailroom(hdr_skb);
  987. if (pskb_expand_head(hdr_skb, 0, space, GFP_ATOMIC) < 0) {
  988. dev_kfree_skb(skb);
  989. RX_STAT_INC(rx_oom_err);
  990. goto requeue_drop_frag;
  991. }
  992. sc->rx.frag = NULL;
  993. skb_copy_from_linear_data(skb, skb_put(hdr_skb, skb->len),
  994. skb->len);
  995. dev_kfree_skb_any(skb);
  996. skb = hdr_skb;
  997. }
  998. if (rxs->flag & RX_FLAG_MMIC_STRIPPED)
  999. skb_trim(skb, skb->len - 8);
  1000. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  1001. if ((sc->ps_flags & (PS_WAIT_FOR_BEACON |
  1002. PS_WAIT_FOR_CAB |
  1003. PS_WAIT_FOR_PSPOLL_DATA)) ||
  1004. ath9k_check_auto_sleep(sc))
  1005. ath_rx_ps(sc, skb, rs.is_mybeacon);
  1006. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  1007. ath9k_antenna_check(sc, &rs);
  1008. ath9k_apply_ampdu_details(sc, &rs, rxs);
  1009. ath_debug_rate_stats(sc, &rs, skb);
  1010. ath_rx_count_airtime(sc, &rs, skb);
  1011. hdr = (struct ieee80211_hdr *)skb->data;
  1012. if (ieee80211_is_ack(hdr->frame_control))
  1013. ath_dynack_sample_ack_ts(sc->sc_ah, skb, rs.rs_tstamp);
  1014. ieee80211_rx(hw, skb);
  1015. requeue_drop_frag:
  1016. if (sc->rx.frag) {
  1017. dev_kfree_skb_any(sc->rx.frag);
  1018. sc->rx.frag = NULL;
  1019. }
  1020. requeue:
  1021. list_add_tail(&bf->list, &sc->rx.rxbuf);
  1022. if (!edma) {
  1023. ath_rx_buf_relink(sc, bf, flush);
  1024. if (!flush)
  1025. ath9k_hw_rxena(ah);
  1026. } else if (!flush) {
  1027. ath_rx_edma_buf_link(sc, qtype);
  1028. }
  1029. if (!budget--)
  1030. break;
  1031. } while (1);
  1032. if (!(ah->imask & ATH9K_INT_RXEOL)) {
  1033. ah->imask |= (ATH9K_INT_RXEOL | ATH9K_INT_RXORN);
  1034. ath9k_hw_set_interrupts(ah);
  1035. }
  1036. return 0;
  1037. }