recv.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240
  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 ||
  342. (sc->cur_chan->rxfilter & (FIF_OTHER_BSS | FIF_MCAST_ACTION))) {
  343. /* This is needed for older chips */
  344. if (sc->sc_ah->hw_version.macVersion <= AR_SREV_VERSION_9160)
  345. rfilt |= ATH9K_RX_FILTER_PROM;
  346. rfilt |= ATH9K_RX_FILTER_MCAST_BCAST_ALL;
  347. }
  348. if (AR_SREV_9550(sc->sc_ah) || AR_SREV_9531(sc->sc_ah) ||
  349. AR_SREV_9561(sc->sc_ah))
  350. rfilt |= ATH9K_RX_FILTER_4ADDRESS;
  351. if (AR_SREV_9462(sc->sc_ah) || AR_SREV_9565(sc->sc_ah))
  352. rfilt |= ATH9K_RX_FILTER_CONTROL_WRAPPER;
  353. if (ath9k_is_chanctx_enabled() &&
  354. test_bit(ATH_OP_SCANNING, &common->op_flags))
  355. rfilt |= ATH9K_RX_FILTER_BEACON;
  356. spin_unlock_bh(&sc->chan_lock);
  357. return rfilt;
  358. }
  359. void ath_startrecv(struct ath_softc *sc)
  360. {
  361. struct ath_hw *ah = sc->sc_ah;
  362. struct ath_rxbuf *bf, *tbf;
  363. if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
  364. ath_edma_start_recv(sc);
  365. return;
  366. }
  367. if (list_empty(&sc->rx.rxbuf))
  368. goto start_recv;
  369. sc->rx.buf_hold = NULL;
  370. sc->rx.rxlink = NULL;
  371. list_for_each_entry_safe(bf, tbf, &sc->rx.rxbuf, list) {
  372. ath_rx_buf_link(sc, bf, false);
  373. }
  374. /* We could have deleted elements so the list may be empty now */
  375. if (list_empty(&sc->rx.rxbuf))
  376. goto start_recv;
  377. bf = list_first_entry(&sc->rx.rxbuf, struct ath_rxbuf, list);
  378. ath9k_hw_putrxbuf(ah, bf->bf_daddr);
  379. ath9k_hw_rxena(ah);
  380. start_recv:
  381. ath_opmode_init(sc);
  382. ath9k_hw_startpcureceive(ah, sc->cur_chan->offchannel);
  383. }
  384. static void ath_flushrecv(struct ath_softc *sc)
  385. {
  386. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
  387. ath_rx_tasklet(sc, 1, true);
  388. ath_rx_tasklet(sc, 1, false);
  389. }
  390. bool ath_stoprecv(struct ath_softc *sc)
  391. {
  392. struct ath_hw *ah = sc->sc_ah;
  393. bool stopped, reset = false;
  394. ath9k_hw_abortpcurecv(ah);
  395. ath9k_hw_setrxfilter(ah, 0);
  396. stopped = ath9k_hw_stopdmarecv(ah, &reset);
  397. ath_flushrecv(sc);
  398. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
  399. ath_edma_stop_recv(sc);
  400. else
  401. sc->rx.rxlink = NULL;
  402. if (!(ah->ah_flags & AH_UNPLUGGED) &&
  403. unlikely(!stopped)) {
  404. ath_dbg(ath9k_hw_common(sc->sc_ah), RESET,
  405. "Failed to stop Rx DMA\n");
  406. RESET_STAT_INC(sc, RESET_RX_DMA_ERROR);
  407. }
  408. return stopped && !reset;
  409. }
  410. static bool ath_beacon_dtim_pending_cab(struct sk_buff *skb)
  411. {
  412. /* Check whether the Beacon frame has DTIM indicating buffered bc/mc */
  413. struct ieee80211_mgmt *mgmt;
  414. u8 *pos, *end, id, elen;
  415. struct ieee80211_tim_ie *tim;
  416. mgmt = (struct ieee80211_mgmt *)skb->data;
  417. pos = mgmt->u.beacon.variable;
  418. end = skb->data + skb->len;
  419. while (pos + 2 < end) {
  420. id = *pos++;
  421. elen = *pos++;
  422. if (pos + elen > end)
  423. break;
  424. if (id == WLAN_EID_TIM) {
  425. if (elen < sizeof(*tim))
  426. break;
  427. tim = (struct ieee80211_tim_ie *) pos;
  428. if (tim->dtim_count != 0)
  429. break;
  430. return tim->bitmap_ctrl & 0x01;
  431. }
  432. pos += elen;
  433. }
  434. return false;
  435. }
  436. static void ath_rx_ps_beacon(struct ath_softc *sc, struct sk_buff *skb)
  437. {
  438. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  439. bool skip_beacon = false;
  440. if (skb->len < 24 + 8 + 2 + 2)
  441. return;
  442. sc->ps_flags &= ~PS_WAIT_FOR_BEACON;
  443. if (sc->ps_flags & PS_BEACON_SYNC) {
  444. sc->ps_flags &= ~PS_BEACON_SYNC;
  445. ath_dbg(common, PS,
  446. "Reconfigure beacon timers based on synchronized timestamp\n");
  447. #ifdef CONFIG_ATH9K_CHANNEL_CONTEXT
  448. if (ath9k_is_chanctx_enabled()) {
  449. if (sc->cur_chan == &sc->offchannel.chan)
  450. skip_beacon = true;
  451. }
  452. #endif
  453. if (!skip_beacon &&
  454. !(WARN_ON_ONCE(sc->cur_chan->beacon.beacon_interval == 0)))
  455. ath9k_set_beacon(sc);
  456. ath9k_p2p_beacon_sync(sc);
  457. }
  458. if (ath_beacon_dtim_pending_cab(skb)) {
  459. /*
  460. * Remain awake waiting for buffered broadcast/multicast
  461. * frames. If the last broadcast/multicast frame is not
  462. * received properly, the next beacon frame will work as
  463. * a backup trigger for returning into NETWORK SLEEP state,
  464. * so we are waiting for it as well.
  465. */
  466. ath_dbg(common, PS,
  467. "Received DTIM beacon indicating buffered broadcast/multicast frame(s)\n");
  468. sc->ps_flags |= PS_WAIT_FOR_CAB | PS_WAIT_FOR_BEACON;
  469. return;
  470. }
  471. if (sc->ps_flags & PS_WAIT_FOR_CAB) {
  472. /*
  473. * This can happen if a broadcast frame is dropped or the AP
  474. * fails to send a frame indicating that all CAB frames have
  475. * been delivered.
  476. */
  477. sc->ps_flags &= ~PS_WAIT_FOR_CAB;
  478. ath_dbg(common, PS, "PS wait for CAB frames timed out\n");
  479. }
  480. }
  481. static void ath_rx_ps(struct ath_softc *sc, struct sk_buff *skb, bool mybeacon)
  482. {
  483. struct ieee80211_hdr *hdr;
  484. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  485. hdr = (struct ieee80211_hdr *)skb->data;
  486. /* Process Beacon and CAB receive in PS state */
  487. if (((sc->ps_flags & PS_WAIT_FOR_BEACON) || ath9k_check_auto_sleep(sc))
  488. && mybeacon) {
  489. ath_rx_ps_beacon(sc, skb);
  490. } else if ((sc->ps_flags & PS_WAIT_FOR_CAB) &&
  491. (ieee80211_is_data(hdr->frame_control) ||
  492. ieee80211_is_action(hdr->frame_control)) &&
  493. is_multicast_ether_addr(hdr->addr1) &&
  494. !ieee80211_has_moredata(hdr->frame_control)) {
  495. /*
  496. * No more broadcast/multicast frames to be received at this
  497. * point.
  498. */
  499. sc->ps_flags &= ~(PS_WAIT_FOR_CAB | PS_WAIT_FOR_BEACON);
  500. ath_dbg(common, PS,
  501. "All PS CAB frames received, back to sleep\n");
  502. } else if ((sc->ps_flags & PS_WAIT_FOR_PSPOLL_DATA) &&
  503. !is_multicast_ether_addr(hdr->addr1) &&
  504. !ieee80211_has_morefrags(hdr->frame_control)) {
  505. sc->ps_flags &= ~PS_WAIT_FOR_PSPOLL_DATA;
  506. ath_dbg(common, PS,
  507. "Going back to sleep after having received PS-Poll data (0x%lx)\n",
  508. sc->ps_flags & (PS_WAIT_FOR_BEACON |
  509. PS_WAIT_FOR_CAB |
  510. PS_WAIT_FOR_PSPOLL_DATA |
  511. PS_WAIT_FOR_TX_ACK));
  512. }
  513. }
  514. static bool ath_edma_get_buffers(struct ath_softc *sc,
  515. enum ath9k_rx_qtype qtype,
  516. struct ath_rx_status *rs,
  517. struct ath_rxbuf **dest)
  518. {
  519. struct ath_rx_edma *rx_edma = &sc->rx.rx_edma[qtype];
  520. struct ath_hw *ah = sc->sc_ah;
  521. struct ath_common *common = ath9k_hw_common(ah);
  522. struct sk_buff *skb;
  523. struct ath_rxbuf *bf;
  524. int ret;
  525. skb = skb_peek(&rx_edma->rx_fifo);
  526. if (!skb)
  527. return false;
  528. bf = SKB_CB_ATHBUF(skb);
  529. BUG_ON(!bf);
  530. dma_sync_single_for_cpu(sc->dev, bf->bf_buf_addr,
  531. common->rx_bufsize, DMA_FROM_DEVICE);
  532. ret = ath9k_hw_process_rxdesc_edma(ah, rs, skb->data);
  533. if (ret == -EINPROGRESS) {
  534. /*let device gain the buffer again*/
  535. dma_sync_single_for_device(sc->dev, bf->bf_buf_addr,
  536. common->rx_bufsize, DMA_FROM_DEVICE);
  537. return false;
  538. }
  539. __skb_unlink(skb, &rx_edma->rx_fifo);
  540. if (ret == -EINVAL) {
  541. /* corrupt descriptor, skip this one and the following one */
  542. list_add_tail(&bf->list, &sc->rx.rxbuf);
  543. ath_rx_edma_buf_link(sc, qtype);
  544. skb = skb_peek(&rx_edma->rx_fifo);
  545. if (skb) {
  546. bf = SKB_CB_ATHBUF(skb);
  547. BUG_ON(!bf);
  548. __skb_unlink(skb, &rx_edma->rx_fifo);
  549. list_add_tail(&bf->list, &sc->rx.rxbuf);
  550. ath_rx_edma_buf_link(sc, qtype);
  551. }
  552. bf = NULL;
  553. }
  554. *dest = bf;
  555. return true;
  556. }
  557. static struct ath_rxbuf *ath_edma_get_next_rx_buf(struct ath_softc *sc,
  558. struct ath_rx_status *rs,
  559. enum ath9k_rx_qtype qtype)
  560. {
  561. struct ath_rxbuf *bf = NULL;
  562. while (ath_edma_get_buffers(sc, qtype, rs, &bf)) {
  563. if (!bf)
  564. continue;
  565. return bf;
  566. }
  567. return NULL;
  568. }
  569. static struct ath_rxbuf *ath_get_next_rx_buf(struct ath_softc *sc,
  570. struct ath_rx_status *rs)
  571. {
  572. struct ath_hw *ah = sc->sc_ah;
  573. struct ath_common *common = ath9k_hw_common(ah);
  574. struct ath_desc *ds;
  575. struct ath_rxbuf *bf;
  576. int ret;
  577. if (list_empty(&sc->rx.rxbuf)) {
  578. sc->rx.rxlink = NULL;
  579. return NULL;
  580. }
  581. bf = list_first_entry(&sc->rx.rxbuf, struct ath_rxbuf, list);
  582. if (bf == sc->rx.buf_hold)
  583. return NULL;
  584. ds = bf->bf_desc;
  585. /*
  586. * Must provide the virtual address of the current
  587. * descriptor, the physical address, and the virtual
  588. * address of the next descriptor in the h/w chain.
  589. * This allows the HAL to look ahead to see if the
  590. * hardware is done with a descriptor by checking the
  591. * done bit in the following descriptor and the address
  592. * of the current descriptor the DMA engine is working
  593. * on. All this is necessary because of our use of
  594. * a self-linked list to avoid rx overruns.
  595. */
  596. ret = ath9k_hw_rxprocdesc(ah, ds, rs);
  597. if (ret == -EINPROGRESS) {
  598. struct ath_rx_status trs;
  599. struct ath_rxbuf *tbf;
  600. struct ath_desc *tds;
  601. memset(&trs, 0, sizeof(trs));
  602. if (list_is_last(&bf->list, &sc->rx.rxbuf)) {
  603. sc->rx.rxlink = NULL;
  604. return NULL;
  605. }
  606. tbf = list_entry(bf->list.next, struct ath_rxbuf, list);
  607. /*
  608. * On some hardware the descriptor status words could
  609. * get corrupted, including the done bit. Because of
  610. * this, check if the next descriptor's done bit is
  611. * set or not.
  612. *
  613. * If the next descriptor's done bit is set, the current
  614. * descriptor has been corrupted. Force s/w to discard
  615. * this descriptor and continue...
  616. */
  617. tds = tbf->bf_desc;
  618. ret = ath9k_hw_rxprocdesc(ah, tds, &trs);
  619. if (ret == -EINPROGRESS)
  620. return NULL;
  621. /*
  622. * Re-check previous descriptor, in case it has been filled
  623. * in the mean time.
  624. */
  625. ret = ath9k_hw_rxprocdesc(ah, ds, rs);
  626. if (ret == -EINPROGRESS) {
  627. /*
  628. * mark descriptor as zero-length and set the 'more'
  629. * flag to ensure that both buffers get discarded
  630. */
  631. rs->rs_datalen = 0;
  632. rs->rs_more = true;
  633. }
  634. }
  635. list_del(&bf->list);
  636. if (!bf->bf_mpdu)
  637. return bf;
  638. /*
  639. * Synchronize the DMA transfer with CPU before
  640. * 1. accessing the frame
  641. * 2. requeueing the same buffer to h/w
  642. */
  643. dma_sync_single_for_cpu(sc->dev, bf->bf_buf_addr,
  644. common->rx_bufsize,
  645. DMA_FROM_DEVICE);
  646. return bf;
  647. }
  648. static void ath9k_process_tsf(struct ath_rx_status *rs,
  649. struct ieee80211_rx_status *rxs,
  650. u64 tsf)
  651. {
  652. u32 tsf_lower = tsf & 0xffffffff;
  653. rxs->mactime = (tsf & ~0xffffffffULL) | rs->rs_tstamp;
  654. if (rs->rs_tstamp > tsf_lower &&
  655. unlikely(rs->rs_tstamp - tsf_lower > 0x10000000))
  656. rxs->mactime -= 0x100000000ULL;
  657. if (rs->rs_tstamp < tsf_lower &&
  658. unlikely(tsf_lower - rs->rs_tstamp > 0x10000000))
  659. rxs->mactime += 0x100000000ULL;
  660. }
  661. /*
  662. * For Decrypt or Demic errors, we only mark packet status here and always push
  663. * up the frame up to let mac80211 handle the actual error case, be it no
  664. * decryption key or real decryption error. This let us keep statistics there.
  665. */
  666. static int ath9k_rx_skb_preprocess(struct ath_softc *sc,
  667. struct sk_buff *skb,
  668. struct ath_rx_status *rx_stats,
  669. struct ieee80211_rx_status *rx_status,
  670. bool *decrypt_error, u64 tsf)
  671. {
  672. struct ieee80211_hw *hw = sc->hw;
  673. struct ath_hw *ah = sc->sc_ah;
  674. struct ath_common *common = ath9k_hw_common(ah);
  675. struct ieee80211_hdr *hdr;
  676. bool discard_current = sc->rx.discard_next;
  677. bool is_phyerr;
  678. /*
  679. * Discard corrupt descriptors which are marked in
  680. * ath_get_next_rx_buf().
  681. */
  682. if (discard_current)
  683. goto corrupt;
  684. sc->rx.discard_next = false;
  685. /*
  686. * Discard zero-length packets and packets smaller than an ACK
  687. * which are not PHY_ERROR (short radar pulses have a length of 3)
  688. */
  689. is_phyerr = rx_stats->rs_status & ATH9K_RXERR_PHY;
  690. if (!rx_stats->rs_datalen ||
  691. (rx_stats->rs_datalen < 10 && !is_phyerr)) {
  692. RX_STAT_INC(sc, rx_len_err);
  693. goto corrupt;
  694. }
  695. /*
  696. * rs_status follows rs_datalen so if rs_datalen is too large
  697. * we can take a hint that hardware corrupted it, so ignore
  698. * those frames.
  699. */
  700. if (rx_stats->rs_datalen > (common->rx_bufsize - ah->caps.rx_status_len)) {
  701. RX_STAT_INC(sc, rx_len_err);
  702. goto corrupt;
  703. }
  704. /* Only use status info from the last fragment */
  705. if (rx_stats->rs_more)
  706. return 0;
  707. /*
  708. * Return immediately if the RX descriptor has been marked
  709. * as corrupt based on the various error bits.
  710. *
  711. * This is different from the other corrupt descriptor
  712. * condition handled above.
  713. */
  714. if (rx_stats->rs_status & ATH9K_RXERR_CORRUPT_DESC)
  715. goto corrupt;
  716. hdr = (struct ieee80211_hdr *) (skb->data + ah->caps.rx_status_len);
  717. ath9k_process_tsf(rx_stats, rx_status, tsf);
  718. ath_debug_stat_rx(sc, rx_stats);
  719. /*
  720. * Process PHY errors and return so that the packet
  721. * can be dropped.
  722. */
  723. if (rx_stats->rs_status & ATH9K_RXERR_PHY) {
  724. /*
  725. * DFS and spectral are mutually exclusive
  726. *
  727. * Since some chips use PHYERR_RADAR as indication for both, we
  728. * need to double check which feature is enabled to prevent
  729. * feeding spectral or dfs-detector with wrong frames.
  730. */
  731. if (hw->conf.radar_enabled) {
  732. ath9k_dfs_process_phyerr(sc, hdr, rx_stats,
  733. rx_status->mactime);
  734. } else if (sc->spec_priv.spectral_mode != SPECTRAL_DISABLED &&
  735. ath_cmn_process_fft(&sc->spec_priv, hdr, rx_stats,
  736. rx_status->mactime)) {
  737. RX_STAT_INC(sc, rx_spectral);
  738. }
  739. return -EINVAL;
  740. }
  741. /*
  742. * everything but the rate is checked here, the rate check is done
  743. * separately to avoid doing two lookups for a rate for each frame.
  744. */
  745. spin_lock_bh(&sc->chan_lock);
  746. if (!ath9k_cmn_rx_accept(common, hdr, rx_status, rx_stats, decrypt_error,
  747. sc->cur_chan->rxfilter)) {
  748. spin_unlock_bh(&sc->chan_lock);
  749. return -EINVAL;
  750. }
  751. spin_unlock_bh(&sc->chan_lock);
  752. if (ath_is_mybeacon(common, hdr)) {
  753. RX_STAT_INC(sc, rx_beacons);
  754. rx_stats->is_mybeacon = true;
  755. }
  756. /*
  757. * This shouldn't happen, but have a safety check anyway.
  758. */
  759. if (WARN_ON(!ah->curchan))
  760. return -EINVAL;
  761. if (ath9k_cmn_process_rate(common, hw, rx_stats, rx_status)) {
  762. /*
  763. * No valid hardware bitrate found -- we should not get here
  764. * because hardware has already validated this frame as OK.
  765. */
  766. ath_dbg(common, ANY, "unsupported hw bitrate detected 0x%02x using 1 Mbit\n",
  767. rx_stats->rs_rate);
  768. RX_STAT_INC(sc, rx_rate_err);
  769. return -EINVAL;
  770. }
  771. if (ath9k_is_chanctx_enabled()) {
  772. if (rx_stats->is_mybeacon)
  773. ath_chanctx_beacon_recv_ev(sc,
  774. ATH_CHANCTX_EVENT_BEACON_RECEIVED);
  775. }
  776. ath9k_cmn_process_rssi(common, hw, rx_stats, rx_status);
  777. rx_status->band = ah->curchan->chan->band;
  778. rx_status->freq = ah->curchan->chan->center_freq;
  779. rx_status->antenna = rx_stats->rs_antenna;
  780. rx_status->flag |= RX_FLAG_MACTIME_END;
  781. #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
  782. if (ieee80211_is_data_present(hdr->frame_control) &&
  783. !ieee80211_is_qos_nullfunc(hdr->frame_control))
  784. sc->rx.num_pkts++;
  785. #endif
  786. return 0;
  787. corrupt:
  788. sc->rx.discard_next = rx_stats->rs_more;
  789. return -EINVAL;
  790. }
  791. /*
  792. * Run the LNA combining algorithm only in these cases:
  793. *
  794. * Standalone WLAN cards with both LNA/Antenna diversity
  795. * enabled in the EEPROM.
  796. *
  797. * WLAN+BT cards which are in the supported card list
  798. * in ath_pci_id_table and the user has loaded the
  799. * driver with "bt_ant_diversity" set to true.
  800. */
  801. static void ath9k_antenna_check(struct ath_softc *sc,
  802. struct ath_rx_status *rs)
  803. {
  804. struct ath_hw *ah = sc->sc_ah;
  805. struct ath9k_hw_capabilities *pCap = &ah->caps;
  806. struct ath_common *common = ath9k_hw_common(ah);
  807. if (!(ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB))
  808. return;
  809. /*
  810. * Change the default rx antenna if rx diversity
  811. * chooses the other antenna 3 times in a row.
  812. */
  813. if (sc->rx.defant != rs->rs_antenna) {
  814. if (++sc->rx.rxotherant >= 3)
  815. ath_setdefantenna(sc, rs->rs_antenna);
  816. } else {
  817. sc->rx.rxotherant = 0;
  818. }
  819. if (pCap->hw_caps & ATH9K_HW_CAP_BT_ANT_DIV) {
  820. if (common->bt_ant_diversity)
  821. ath_ant_comb_scan(sc, rs);
  822. } else {
  823. ath_ant_comb_scan(sc, rs);
  824. }
  825. }
  826. static void ath9k_apply_ampdu_details(struct ath_softc *sc,
  827. struct ath_rx_status *rs, struct ieee80211_rx_status *rxs)
  828. {
  829. if (rs->rs_isaggr) {
  830. rxs->flag |= RX_FLAG_AMPDU_DETAILS | RX_FLAG_AMPDU_LAST_KNOWN;
  831. rxs->ampdu_reference = sc->rx.ampdu_ref;
  832. if (!rs->rs_moreaggr) {
  833. rxs->flag |= RX_FLAG_AMPDU_IS_LAST;
  834. sc->rx.ampdu_ref++;
  835. }
  836. if (rs->rs_flags & ATH9K_RX_DELIM_CRC_PRE)
  837. rxs->flag |= RX_FLAG_AMPDU_DELIM_CRC_ERROR;
  838. }
  839. }
  840. static void ath_rx_count_airtime(struct ath_softc *sc,
  841. struct ath_rx_status *rs,
  842. struct sk_buff *skb)
  843. {
  844. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  845. struct ath_hw *ah = sc->sc_ah;
  846. struct ath_common *common = ath9k_hw_common(ah);
  847. struct ieee80211_sta *sta;
  848. struct ieee80211_rx_status *rxs;
  849. const struct ieee80211_rate *rate;
  850. bool is_sgi, is_40, is_sp;
  851. int phy;
  852. u16 len = rs->rs_datalen;
  853. u32 airtime = 0;
  854. u8 tidno;
  855. if (!ieee80211_is_data(hdr->frame_control))
  856. return;
  857. rcu_read_lock();
  858. sta = ieee80211_find_sta_by_ifaddr(sc->hw, hdr->addr2, NULL);
  859. if (!sta)
  860. goto exit;
  861. tidno = skb->priority & IEEE80211_QOS_CTL_TID_MASK;
  862. rxs = IEEE80211_SKB_RXCB(skb);
  863. is_sgi = !!(rxs->enc_flags & RX_ENC_FLAG_SHORT_GI);
  864. is_40 = !!(rxs->bw == RATE_INFO_BW_40);
  865. is_sp = !!(rxs->enc_flags & RX_ENC_FLAG_SHORTPRE);
  866. if (!!(rxs->encoding == RX_ENC_HT)) {
  867. /* MCS rates */
  868. airtime += ath_pkt_duration(sc, rxs->rate_idx, len,
  869. is_40, is_sgi, is_sp);
  870. } else {
  871. phy = IS_CCK_RATE(rs->rs_rate) ? WLAN_RC_PHY_CCK : WLAN_RC_PHY_OFDM;
  872. rate = &common->sbands[rxs->band].bitrates[rxs->rate_idx];
  873. airtime += ath9k_hw_computetxtime(ah, phy, rate->bitrate * 100,
  874. len, rxs->rate_idx, is_sp);
  875. }
  876. ieee80211_sta_register_airtime(sta, tidno, 0, airtime);
  877. exit:
  878. rcu_read_unlock();
  879. }
  880. int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp)
  881. {
  882. struct ath_rxbuf *bf;
  883. struct sk_buff *skb = NULL, *requeue_skb, *hdr_skb;
  884. struct ieee80211_rx_status *rxs;
  885. struct ath_hw *ah = sc->sc_ah;
  886. struct ath_common *common = ath9k_hw_common(ah);
  887. struct ieee80211_hw *hw = sc->hw;
  888. int retval;
  889. struct ath_rx_status rs;
  890. enum ath9k_rx_qtype qtype;
  891. bool edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA);
  892. int dma_type;
  893. u64 tsf = 0;
  894. unsigned long flags;
  895. dma_addr_t new_buf_addr;
  896. unsigned int budget = 512;
  897. struct ieee80211_hdr *hdr;
  898. if (edma)
  899. dma_type = DMA_BIDIRECTIONAL;
  900. else
  901. dma_type = DMA_FROM_DEVICE;
  902. qtype = hp ? ATH9K_RX_QUEUE_HP : ATH9K_RX_QUEUE_LP;
  903. tsf = ath9k_hw_gettsf64(ah);
  904. do {
  905. bool decrypt_error = false;
  906. memset(&rs, 0, sizeof(rs));
  907. if (edma)
  908. bf = ath_edma_get_next_rx_buf(sc, &rs, qtype);
  909. else
  910. bf = ath_get_next_rx_buf(sc, &rs);
  911. if (!bf)
  912. break;
  913. skb = bf->bf_mpdu;
  914. if (!skb)
  915. continue;
  916. /*
  917. * Take frame header from the first fragment and RX status from
  918. * the last one.
  919. */
  920. if (sc->rx.frag)
  921. hdr_skb = sc->rx.frag;
  922. else
  923. hdr_skb = skb;
  924. rxs = IEEE80211_SKB_RXCB(hdr_skb);
  925. memset(rxs, 0, sizeof(struct ieee80211_rx_status));
  926. retval = ath9k_rx_skb_preprocess(sc, hdr_skb, &rs, rxs,
  927. &decrypt_error, tsf);
  928. if (retval)
  929. goto requeue_drop_frag;
  930. /* Ensure we always have an skb to requeue once we are done
  931. * processing the current buffer's skb */
  932. requeue_skb = ath_rxbuf_alloc(common, common->rx_bufsize, GFP_ATOMIC);
  933. /* If there is no memory we ignore the current RX'd frame,
  934. * tell hardware it can give us a new frame using the old
  935. * skb and put it at the tail of the sc->rx.rxbuf list for
  936. * processing. */
  937. if (!requeue_skb) {
  938. RX_STAT_INC(sc, rx_oom_err);
  939. goto requeue_drop_frag;
  940. }
  941. /* We will now give hardware our shiny new allocated skb */
  942. new_buf_addr = dma_map_single(sc->dev, requeue_skb->data,
  943. common->rx_bufsize, dma_type);
  944. if (unlikely(dma_mapping_error(sc->dev, new_buf_addr))) {
  945. dev_kfree_skb_any(requeue_skb);
  946. goto requeue_drop_frag;
  947. }
  948. /* Unmap the frame */
  949. dma_unmap_single(sc->dev, bf->bf_buf_addr,
  950. common->rx_bufsize, dma_type);
  951. bf->bf_mpdu = requeue_skb;
  952. bf->bf_buf_addr = new_buf_addr;
  953. skb_put(skb, rs.rs_datalen + ah->caps.rx_status_len);
  954. if (ah->caps.rx_status_len)
  955. skb_pull(skb, ah->caps.rx_status_len);
  956. if (!rs.rs_more)
  957. ath9k_cmn_rx_skb_postprocess(common, hdr_skb, &rs,
  958. rxs, decrypt_error);
  959. if (rs.rs_more) {
  960. RX_STAT_INC(sc, rx_frags);
  961. /*
  962. * rs_more indicates chained descriptors which can be
  963. * used to link buffers together for a sort of
  964. * scatter-gather operation.
  965. */
  966. if (sc->rx.frag) {
  967. /* too many fragments - cannot handle frame */
  968. dev_kfree_skb_any(sc->rx.frag);
  969. dev_kfree_skb_any(skb);
  970. RX_STAT_INC(sc, rx_too_many_frags_err);
  971. skb = NULL;
  972. }
  973. sc->rx.frag = skb;
  974. goto requeue;
  975. }
  976. if (sc->rx.frag) {
  977. int space = skb->len - skb_tailroom(hdr_skb);
  978. if (pskb_expand_head(hdr_skb, 0, space, GFP_ATOMIC) < 0) {
  979. dev_kfree_skb(skb);
  980. RX_STAT_INC(sc, rx_oom_err);
  981. goto requeue_drop_frag;
  982. }
  983. sc->rx.frag = NULL;
  984. skb_copy_from_linear_data(skb, skb_put(hdr_skb, skb->len),
  985. skb->len);
  986. dev_kfree_skb_any(skb);
  987. skb = hdr_skb;
  988. }
  989. if (rxs->flag & RX_FLAG_MMIC_STRIPPED)
  990. skb_trim(skb, skb->len - 8);
  991. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  992. if ((sc->ps_flags & (PS_WAIT_FOR_BEACON |
  993. PS_WAIT_FOR_CAB |
  994. PS_WAIT_FOR_PSPOLL_DATA)) ||
  995. ath9k_check_auto_sleep(sc))
  996. ath_rx_ps(sc, skb, rs.is_mybeacon);
  997. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  998. ath9k_antenna_check(sc, &rs);
  999. ath9k_apply_ampdu_details(sc, &rs, rxs);
  1000. ath_debug_rate_stats(sc, &rs, skb);
  1001. ath_rx_count_airtime(sc, &rs, skb);
  1002. hdr = (struct ieee80211_hdr *)skb->data;
  1003. if (ieee80211_is_ack(hdr->frame_control))
  1004. ath_dynack_sample_ack_ts(sc->sc_ah, skb, rs.rs_tstamp);
  1005. ieee80211_rx(hw, skb);
  1006. requeue_drop_frag:
  1007. if (sc->rx.frag) {
  1008. dev_kfree_skb_any(sc->rx.frag);
  1009. sc->rx.frag = NULL;
  1010. }
  1011. requeue:
  1012. list_add_tail(&bf->list, &sc->rx.rxbuf);
  1013. if (!edma) {
  1014. ath_rx_buf_relink(sc, bf, flush);
  1015. if (!flush)
  1016. ath9k_hw_rxena(ah);
  1017. } else if (!flush) {
  1018. ath_rx_edma_buf_link(sc, qtype);
  1019. }
  1020. if (!budget--)
  1021. break;
  1022. } while (1);
  1023. if (!(ah->imask & ATH9K_INT_RXEOL)) {
  1024. ah->imask |= (ATH9K_INT_RXEOL | ATH9K_INT_RXORN);
  1025. ath9k_hw_set_interrupts(ah);
  1026. }
  1027. return 0;
  1028. }