recv.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270
  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. /* The following may also be needed for other 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. return rfilt;
  354. }
  355. int ath_startrecv(struct ath_softc *sc)
  356. {
  357. struct ath_hw *ah = sc->sc_ah;
  358. struct ath_buf *bf, *tbf;
  359. if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
  360. ath_edma_start_recv(sc);
  361. return 0;
  362. }
  363. spin_lock_bh(&sc->rx.rxbuflock);
  364. if (list_empty(&sc->rx.rxbuf))
  365. goto start_recv;
  366. sc->rx.rxlink = NULL;
  367. list_for_each_entry_safe(bf, tbf, &sc->rx.rxbuf, list) {
  368. ath_rx_buf_link(sc, bf);
  369. }
  370. /* We could have deleted elements so the list may be empty now */
  371. if (list_empty(&sc->rx.rxbuf))
  372. goto start_recv;
  373. bf = list_first_entry(&sc->rx.rxbuf, struct ath_buf, list);
  374. ath9k_hw_putrxbuf(ah, bf->bf_daddr);
  375. ath9k_hw_rxena(ah);
  376. start_recv:
  377. ath_opmode_init(sc);
  378. ath9k_hw_startpcureceive(ah, !!(sc->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL));
  379. spin_unlock_bh(&sc->rx.rxbuflock);
  380. return 0;
  381. }
  382. bool ath_stoprecv(struct ath_softc *sc)
  383. {
  384. struct ath_hw *ah = sc->sc_ah;
  385. bool stopped, reset = false;
  386. spin_lock_bh(&sc->rx.rxbuflock);
  387. ath9k_hw_abortpcurecv(ah);
  388. ath9k_hw_setrxfilter(ah, 0);
  389. stopped = ath9k_hw_stopdmarecv(ah, &reset);
  390. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
  391. ath_edma_stop_recv(sc);
  392. else
  393. sc->rx.rxlink = NULL;
  394. spin_unlock_bh(&sc->rx.rxbuflock);
  395. if (!(ah->ah_flags & AH_UNPLUGGED) &&
  396. unlikely(!stopped)) {
  397. ath_err(ath9k_hw_common(sc->sc_ah),
  398. "Could not stop RX, we could be "
  399. "confusing the DMA engine when we start RX up\n");
  400. ATH_DBG_WARN_ON_ONCE(!stopped);
  401. }
  402. return stopped && !reset;
  403. }
  404. void ath_flushrecv(struct ath_softc *sc)
  405. {
  406. set_bit(SC_OP_RXFLUSH, &sc->sc_flags);
  407. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
  408. ath_rx_tasklet(sc, 1, true);
  409. ath_rx_tasklet(sc, 1, false);
  410. clear_bit(SC_OP_RXFLUSH, &sc->sc_flags);
  411. }
  412. static bool ath_beacon_dtim_pending_cab(struct sk_buff *skb)
  413. {
  414. /* Check whether the Beacon frame has DTIM indicating buffered bc/mc */
  415. struct ieee80211_mgmt *mgmt;
  416. u8 *pos, *end, id, elen;
  417. struct ieee80211_tim_ie *tim;
  418. mgmt = (struct ieee80211_mgmt *)skb->data;
  419. pos = mgmt->u.beacon.variable;
  420. end = skb->data + skb->len;
  421. while (pos + 2 < end) {
  422. id = *pos++;
  423. elen = *pos++;
  424. if (pos + elen > end)
  425. break;
  426. if (id == WLAN_EID_TIM) {
  427. if (elen < sizeof(*tim))
  428. break;
  429. tim = (struct ieee80211_tim_ie *) pos;
  430. if (tim->dtim_count != 0)
  431. break;
  432. return tim->bitmap_ctrl & 0x01;
  433. }
  434. pos += elen;
  435. }
  436. return false;
  437. }
  438. static void ath_rx_ps_beacon(struct ath_softc *sc, struct sk_buff *skb)
  439. {
  440. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  441. if (skb->len < 24 + 8 + 2 + 2)
  442. return;
  443. sc->ps_flags &= ~PS_WAIT_FOR_BEACON;
  444. if (sc->ps_flags & PS_BEACON_SYNC) {
  445. sc->ps_flags &= ~PS_BEACON_SYNC;
  446. ath_dbg(common, PS,
  447. "Reconfigure Beacon timers based on timestamp from the AP\n");
  448. ath_set_beacon(sc);
  449. }
  450. if (ath_beacon_dtim_pending_cab(skb)) {
  451. /*
  452. * Remain awake waiting for buffered broadcast/multicast
  453. * frames. If the last broadcast/multicast frame is not
  454. * received properly, the next beacon frame will work as
  455. * a backup trigger for returning into NETWORK SLEEP state,
  456. * so we are waiting for it as well.
  457. */
  458. ath_dbg(common, PS,
  459. "Received DTIM beacon indicating buffered broadcast/multicast frame(s)\n");
  460. sc->ps_flags |= PS_WAIT_FOR_CAB | PS_WAIT_FOR_BEACON;
  461. return;
  462. }
  463. if (sc->ps_flags & PS_WAIT_FOR_CAB) {
  464. /*
  465. * This can happen if a broadcast frame is dropped or the AP
  466. * fails to send a frame indicating that all CAB frames have
  467. * been delivered.
  468. */
  469. sc->ps_flags &= ~PS_WAIT_FOR_CAB;
  470. ath_dbg(common, PS, "PS wait for CAB frames timed out\n");
  471. }
  472. }
  473. static void ath_rx_ps(struct ath_softc *sc, struct sk_buff *skb, bool mybeacon)
  474. {
  475. struct ieee80211_hdr *hdr;
  476. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  477. hdr = (struct ieee80211_hdr *)skb->data;
  478. /* Process Beacon and CAB receive in PS state */
  479. if (((sc->ps_flags & PS_WAIT_FOR_BEACON) || ath9k_check_auto_sleep(sc))
  480. && mybeacon)
  481. ath_rx_ps_beacon(sc, skb);
  482. else if ((sc->ps_flags & PS_WAIT_FOR_CAB) &&
  483. (ieee80211_is_data(hdr->frame_control) ||
  484. ieee80211_is_action(hdr->frame_control)) &&
  485. is_multicast_ether_addr(hdr->addr1) &&
  486. !ieee80211_has_moredata(hdr->frame_control)) {
  487. /*
  488. * No more broadcast/multicast frames to be received at this
  489. * point.
  490. */
  491. sc->ps_flags &= ~(PS_WAIT_FOR_CAB | PS_WAIT_FOR_BEACON);
  492. ath_dbg(common, PS,
  493. "All PS CAB frames received, back to sleep\n");
  494. } else if ((sc->ps_flags & PS_WAIT_FOR_PSPOLL_DATA) &&
  495. !is_multicast_ether_addr(hdr->addr1) &&
  496. !ieee80211_has_morefrags(hdr->frame_control)) {
  497. sc->ps_flags &= ~PS_WAIT_FOR_PSPOLL_DATA;
  498. ath_dbg(common, PS,
  499. "Going back to sleep after having received PS-Poll data (0x%lx)\n",
  500. sc->ps_flags & (PS_WAIT_FOR_BEACON |
  501. PS_WAIT_FOR_CAB |
  502. PS_WAIT_FOR_PSPOLL_DATA |
  503. PS_WAIT_FOR_TX_ACK));
  504. }
  505. }
  506. static bool ath_edma_get_buffers(struct ath_softc *sc,
  507. enum ath9k_rx_qtype qtype,
  508. struct ath_rx_status *rs,
  509. struct ath_buf **dest)
  510. {
  511. struct ath_rx_edma *rx_edma = &sc->rx.rx_edma[qtype];
  512. struct ath_hw *ah = sc->sc_ah;
  513. struct ath_common *common = ath9k_hw_common(ah);
  514. struct sk_buff *skb;
  515. struct ath_buf *bf;
  516. int ret;
  517. skb = skb_peek(&rx_edma->rx_fifo);
  518. if (!skb)
  519. return false;
  520. bf = SKB_CB_ATHBUF(skb);
  521. BUG_ON(!bf);
  522. dma_sync_single_for_cpu(sc->dev, bf->bf_buf_addr,
  523. common->rx_bufsize, DMA_FROM_DEVICE);
  524. ret = ath9k_hw_process_rxdesc_edma(ah, rs, skb->data);
  525. if (ret == -EINPROGRESS) {
  526. /*let device gain the buffer again*/
  527. dma_sync_single_for_device(sc->dev, bf->bf_buf_addr,
  528. common->rx_bufsize, DMA_FROM_DEVICE);
  529. return false;
  530. }
  531. __skb_unlink(skb, &rx_edma->rx_fifo);
  532. if (ret == -EINVAL) {
  533. /* corrupt descriptor, skip this one and the following one */
  534. list_add_tail(&bf->list, &sc->rx.rxbuf);
  535. ath_rx_edma_buf_link(sc, qtype);
  536. skb = skb_peek(&rx_edma->rx_fifo);
  537. if (skb) {
  538. bf = SKB_CB_ATHBUF(skb);
  539. BUG_ON(!bf);
  540. __skb_unlink(skb, &rx_edma->rx_fifo);
  541. list_add_tail(&bf->list, &sc->rx.rxbuf);
  542. ath_rx_edma_buf_link(sc, qtype);
  543. } else {
  544. bf = NULL;
  545. }
  546. }
  547. *dest = bf;
  548. return true;
  549. }
  550. static struct ath_buf *ath_edma_get_next_rx_buf(struct ath_softc *sc,
  551. struct ath_rx_status *rs,
  552. enum ath9k_rx_qtype qtype)
  553. {
  554. struct ath_buf *bf = NULL;
  555. while (ath_edma_get_buffers(sc, qtype, rs, &bf)) {
  556. if (!bf)
  557. continue;
  558. return bf;
  559. }
  560. return NULL;
  561. }
  562. static struct ath_buf *ath_get_next_rx_buf(struct ath_softc *sc,
  563. struct ath_rx_status *rs)
  564. {
  565. struct ath_hw *ah = sc->sc_ah;
  566. struct ath_common *common = ath9k_hw_common(ah);
  567. struct ath_desc *ds;
  568. struct ath_buf *bf;
  569. int ret;
  570. if (list_empty(&sc->rx.rxbuf)) {
  571. sc->rx.rxlink = NULL;
  572. return NULL;
  573. }
  574. bf = list_first_entry(&sc->rx.rxbuf, struct ath_buf, list);
  575. ds = bf->bf_desc;
  576. /*
  577. * Must provide the virtual address of the current
  578. * descriptor, the physical address, and the virtual
  579. * address of the next descriptor in the h/w chain.
  580. * This allows the HAL to look ahead to see if the
  581. * hardware is done with a descriptor by checking the
  582. * done bit in the following descriptor and the address
  583. * of the current descriptor the DMA engine is working
  584. * on. All this is necessary because of our use of
  585. * a self-linked list to avoid rx overruns.
  586. */
  587. ret = ath9k_hw_rxprocdesc(ah, ds, rs);
  588. if (ret == -EINPROGRESS) {
  589. struct ath_rx_status trs;
  590. struct ath_buf *tbf;
  591. struct ath_desc *tds;
  592. memset(&trs, 0, sizeof(trs));
  593. if (list_is_last(&bf->list, &sc->rx.rxbuf)) {
  594. sc->rx.rxlink = NULL;
  595. return NULL;
  596. }
  597. tbf = list_entry(bf->list.next, struct ath_buf, list);
  598. /*
  599. * On some hardware the descriptor status words could
  600. * get corrupted, including the done bit. Because of
  601. * this, check if the next descriptor's done bit is
  602. * set or not.
  603. *
  604. * If the next descriptor's done bit is set, the current
  605. * descriptor has been corrupted. Force s/w to discard
  606. * this descriptor and continue...
  607. */
  608. tds = tbf->bf_desc;
  609. ret = ath9k_hw_rxprocdesc(ah, tds, &trs);
  610. if (ret == -EINPROGRESS)
  611. return NULL;
  612. }
  613. if (!bf->bf_mpdu)
  614. return bf;
  615. /*
  616. * Synchronize the DMA transfer with CPU before
  617. * 1. accessing the frame
  618. * 2. requeueing the same buffer to h/w
  619. */
  620. dma_sync_single_for_cpu(sc->dev, bf->bf_buf_addr,
  621. common->rx_bufsize,
  622. DMA_FROM_DEVICE);
  623. return bf;
  624. }
  625. /* Assumes you've already done the endian to CPU conversion */
  626. static bool ath9k_rx_accept(struct ath_common *common,
  627. struct ieee80211_hdr *hdr,
  628. struct ieee80211_rx_status *rxs,
  629. struct ath_rx_status *rx_stats,
  630. bool *decrypt_error)
  631. {
  632. struct ath_softc *sc = (struct ath_softc *) common->priv;
  633. bool is_mc, is_valid_tkip, strip_mic, mic_error;
  634. struct ath_hw *ah = common->ah;
  635. __le16 fc;
  636. u8 rx_status_len = ah->caps.rx_status_len;
  637. fc = hdr->frame_control;
  638. is_mc = !!is_multicast_ether_addr(hdr->addr1);
  639. is_valid_tkip = rx_stats->rs_keyix != ATH9K_RXKEYIX_INVALID &&
  640. test_bit(rx_stats->rs_keyix, common->tkip_keymap);
  641. strip_mic = is_valid_tkip && ieee80211_is_data(fc) &&
  642. ieee80211_has_protected(fc) &&
  643. !(rx_stats->rs_status &
  644. (ATH9K_RXERR_DECRYPT | ATH9K_RXERR_CRC | ATH9K_RXERR_MIC |
  645. ATH9K_RXERR_KEYMISS));
  646. /*
  647. * Key miss events are only relevant for pairwise keys where the
  648. * descriptor does contain a valid key index. This has been observed
  649. * mostly with CCMP encryption.
  650. */
  651. if (rx_stats->rs_keyix == ATH9K_RXKEYIX_INVALID)
  652. rx_stats->rs_status &= ~ATH9K_RXERR_KEYMISS;
  653. if (!rx_stats->rs_datalen) {
  654. RX_STAT_INC(rx_len_err);
  655. return false;
  656. }
  657. /*
  658. * rs_status follows rs_datalen so if rs_datalen is too large
  659. * we can take a hint that hardware corrupted it, so ignore
  660. * those frames.
  661. */
  662. if (rx_stats->rs_datalen > (common->rx_bufsize - rx_status_len)) {
  663. RX_STAT_INC(rx_len_err);
  664. return false;
  665. }
  666. /* Only use error bits from the last fragment */
  667. if (rx_stats->rs_more)
  668. return true;
  669. mic_error = is_valid_tkip && !ieee80211_is_ctl(fc) &&
  670. !ieee80211_has_morefrags(fc) &&
  671. !(le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG) &&
  672. (rx_stats->rs_status & ATH9K_RXERR_MIC);
  673. /*
  674. * The rx_stats->rs_status will not be set until the end of the
  675. * chained descriptors so it can be ignored if rs_more is set. The
  676. * rs_more will be false at the last element of the chained
  677. * descriptors.
  678. */
  679. if (rx_stats->rs_status != 0) {
  680. u8 status_mask;
  681. if (rx_stats->rs_status & ATH9K_RXERR_CRC) {
  682. rxs->flag |= RX_FLAG_FAILED_FCS_CRC;
  683. mic_error = false;
  684. }
  685. if (rx_stats->rs_status & ATH9K_RXERR_PHY)
  686. return false;
  687. if ((rx_stats->rs_status & ATH9K_RXERR_DECRYPT) ||
  688. (!is_mc && (rx_stats->rs_status & ATH9K_RXERR_KEYMISS))) {
  689. *decrypt_error = true;
  690. mic_error = false;
  691. }
  692. /*
  693. * Reject error frames with the exception of
  694. * decryption and MIC failures. For monitor mode,
  695. * we also ignore the CRC error.
  696. */
  697. status_mask = ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC |
  698. ATH9K_RXERR_KEYMISS;
  699. if (ah->is_monitoring && (sc->rx.rxfilter & FIF_FCSFAIL))
  700. status_mask |= ATH9K_RXERR_CRC;
  701. if (rx_stats->rs_status & ~status_mask)
  702. return false;
  703. }
  704. /*
  705. * For unicast frames the MIC error bit can have false positives,
  706. * so all MIC error reports need to be validated in software.
  707. * False negatives are not common, so skip software verification
  708. * if the hardware considers the MIC valid.
  709. */
  710. if (strip_mic)
  711. rxs->flag |= RX_FLAG_MMIC_STRIPPED;
  712. else if (is_mc && mic_error)
  713. rxs->flag |= RX_FLAG_MMIC_ERROR;
  714. return true;
  715. }
  716. static int ath9k_process_rate(struct ath_common *common,
  717. struct ieee80211_hw *hw,
  718. struct ath_rx_status *rx_stats,
  719. struct ieee80211_rx_status *rxs)
  720. {
  721. struct ieee80211_supported_band *sband;
  722. enum ieee80211_band band;
  723. unsigned int i = 0;
  724. struct ath_softc __maybe_unused *sc = common->priv;
  725. band = hw->conf.channel->band;
  726. sband = hw->wiphy->bands[band];
  727. if (rx_stats->rs_rate & 0x80) {
  728. /* HT rate */
  729. rxs->flag |= RX_FLAG_HT;
  730. if (rx_stats->rs_flags & ATH9K_RX_2040)
  731. rxs->flag |= RX_FLAG_40MHZ;
  732. if (rx_stats->rs_flags & ATH9K_RX_GI)
  733. rxs->flag |= RX_FLAG_SHORT_GI;
  734. rxs->rate_idx = rx_stats->rs_rate & 0x7f;
  735. return 0;
  736. }
  737. for (i = 0; i < sband->n_bitrates; i++) {
  738. if (sband->bitrates[i].hw_value == rx_stats->rs_rate) {
  739. rxs->rate_idx = i;
  740. return 0;
  741. }
  742. if (sband->bitrates[i].hw_value_short == rx_stats->rs_rate) {
  743. rxs->flag |= RX_FLAG_SHORTPRE;
  744. rxs->rate_idx = i;
  745. return 0;
  746. }
  747. }
  748. /*
  749. * No valid hardware bitrate found -- we should not get here
  750. * because hardware has already validated this frame as OK.
  751. */
  752. ath_dbg(common, ANY,
  753. "unsupported hw bitrate detected 0x%02x using 1 Mbit\n",
  754. rx_stats->rs_rate);
  755. RX_STAT_INC(rx_rate_err);
  756. return -EINVAL;
  757. }
  758. static void ath9k_process_rssi(struct ath_common *common,
  759. struct ieee80211_hw *hw,
  760. struct ieee80211_hdr *hdr,
  761. struct ath_rx_status *rx_stats)
  762. {
  763. struct ath_softc *sc = hw->priv;
  764. struct ath_hw *ah = common->ah;
  765. int last_rssi;
  766. int rssi = rx_stats->rs_rssi;
  767. if (!rx_stats->is_mybeacon ||
  768. ((ah->opmode != NL80211_IFTYPE_STATION) &&
  769. (ah->opmode != NL80211_IFTYPE_ADHOC)))
  770. return;
  771. if (rx_stats->rs_rssi != ATH9K_RSSI_BAD && !rx_stats->rs_moreaggr)
  772. ATH_RSSI_LPF(sc->last_rssi, rx_stats->rs_rssi);
  773. last_rssi = sc->last_rssi;
  774. if (likely(last_rssi != ATH_RSSI_DUMMY_MARKER))
  775. rssi = ATH_EP_RND(last_rssi, ATH_RSSI_EP_MULTIPLIER);
  776. if (rssi < 0)
  777. rssi = 0;
  778. /* Update Beacon RSSI, this is used by ANI. */
  779. ah->stats.avgbrssi = rssi;
  780. }
  781. /*
  782. * For Decrypt or Demic errors, we only mark packet status here and always push
  783. * up the frame up to let mac80211 handle the actual error case, be it no
  784. * decryption key or real decryption error. This let us keep statistics there.
  785. */
  786. static int ath9k_rx_skb_preprocess(struct ath_common *common,
  787. struct ieee80211_hw *hw,
  788. struct ieee80211_hdr *hdr,
  789. struct ath_rx_status *rx_stats,
  790. struct ieee80211_rx_status *rx_status,
  791. bool *decrypt_error)
  792. {
  793. struct ath_hw *ah = common->ah;
  794. /*
  795. * everything but the rate is checked here, the rate check is done
  796. * separately to avoid doing two lookups for a rate for each frame.
  797. */
  798. if (!ath9k_rx_accept(common, hdr, rx_status, rx_stats, decrypt_error))
  799. return -EINVAL;
  800. /* Only use status info from the last fragment */
  801. if (rx_stats->rs_more)
  802. return 0;
  803. ath9k_process_rssi(common, hw, hdr, rx_stats);
  804. if (ath9k_process_rate(common, hw, rx_stats, rx_status))
  805. return -EINVAL;
  806. rx_status->band = hw->conf.channel->band;
  807. rx_status->freq = hw->conf.channel->center_freq;
  808. rx_status->signal = ah->noise + rx_stats->rs_rssi;
  809. rx_status->antenna = rx_stats->rs_antenna;
  810. rx_status->flag |= RX_FLAG_MACTIME_MPDU;
  811. if (rx_stats->rs_moreaggr)
  812. rx_status->flag |= RX_FLAG_NO_SIGNAL_VAL;
  813. return 0;
  814. }
  815. static void ath9k_rx_skb_postprocess(struct ath_common *common,
  816. struct sk_buff *skb,
  817. struct ath_rx_status *rx_stats,
  818. struct ieee80211_rx_status *rxs,
  819. bool decrypt_error)
  820. {
  821. struct ath_hw *ah = common->ah;
  822. struct ieee80211_hdr *hdr;
  823. int hdrlen, padpos, padsize;
  824. u8 keyix;
  825. __le16 fc;
  826. /* see if any padding is done by the hw and remove it */
  827. hdr = (struct ieee80211_hdr *) skb->data;
  828. hdrlen = ieee80211_get_hdrlen_from_skb(skb);
  829. fc = hdr->frame_control;
  830. padpos = ath9k_cmn_padpos(hdr->frame_control);
  831. /* The MAC header is padded to have 32-bit boundary if the
  832. * packet payload is non-zero. The general calculation for
  833. * padsize would take into account odd header lengths:
  834. * padsize = (4 - padpos % 4) % 4; However, since only
  835. * even-length headers are used, padding can only be 0 or 2
  836. * bytes and we can optimize this a bit. In addition, we must
  837. * not try to remove padding from short control frames that do
  838. * not have payload. */
  839. padsize = padpos & 3;
  840. if (padsize && skb->len>=padpos+padsize+FCS_LEN) {
  841. memmove(skb->data + padsize, skb->data, padpos);
  842. skb_pull(skb, padsize);
  843. }
  844. keyix = rx_stats->rs_keyix;
  845. if (!(keyix == ATH9K_RXKEYIX_INVALID) && !decrypt_error &&
  846. ieee80211_has_protected(fc)) {
  847. rxs->flag |= RX_FLAG_DECRYPTED;
  848. } else if (ieee80211_has_protected(fc)
  849. && !decrypt_error && skb->len >= hdrlen + 4) {
  850. keyix = skb->data[hdrlen + 3] >> 6;
  851. if (test_bit(keyix, common->keymap))
  852. rxs->flag |= RX_FLAG_DECRYPTED;
  853. }
  854. if (ah->sw_mgmt_crypto &&
  855. (rxs->flag & RX_FLAG_DECRYPTED) &&
  856. ieee80211_is_mgmt(fc))
  857. /* Use software decrypt for management frames. */
  858. rxs->flag &= ~RX_FLAG_DECRYPTED;
  859. }
  860. int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp)
  861. {
  862. struct ath_buf *bf;
  863. struct sk_buff *skb = NULL, *requeue_skb, *hdr_skb;
  864. struct ieee80211_rx_status *rxs;
  865. struct ath_hw *ah = sc->sc_ah;
  866. struct ath_common *common = ath9k_hw_common(ah);
  867. struct ieee80211_hw *hw = sc->hw;
  868. struct ieee80211_hdr *hdr;
  869. int retval;
  870. bool decrypt_error = false;
  871. struct ath_rx_status rs;
  872. enum ath9k_rx_qtype qtype;
  873. bool edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA);
  874. int dma_type;
  875. u8 rx_status_len = ah->caps.rx_status_len;
  876. u64 tsf = 0;
  877. u32 tsf_lower = 0;
  878. unsigned long flags;
  879. if (edma)
  880. dma_type = DMA_BIDIRECTIONAL;
  881. else
  882. dma_type = DMA_FROM_DEVICE;
  883. qtype = hp ? ATH9K_RX_QUEUE_HP : ATH9K_RX_QUEUE_LP;
  884. spin_lock_bh(&sc->rx.rxbuflock);
  885. tsf = ath9k_hw_gettsf64(ah);
  886. tsf_lower = tsf & 0xffffffff;
  887. do {
  888. /* If handling rx interrupt and flush is in progress => exit */
  889. if (test_bit(SC_OP_RXFLUSH, &sc->sc_flags) && (flush == 0))
  890. break;
  891. memset(&rs, 0, sizeof(rs));
  892. if (edma)
  893. bf = ath_edma_get_next_rx_buf(sc, &rs, qtype);
  894. else
  895. bf = ath_get_next_rx_buf(sc, &rs);
  896. if (!bf)
  897. break;
  898. skb = bf->bf_mpdu;
  899. if (!skb)
  900. continue;
  901. /*
  902. * Take frame header from the first fragment and RX status from
  903. * the last one.
  904. */
  905. if (sc->rx.frag)
  906. hdr_skb = sc->rx.frag;
  907. else
  908. hdr_skb = skb;
  909. hdr = (struct ieee80211_hdr *) (hdr_skb->data + rx_status_len);
  910. rxs = IEEE80211_SKB_RXCB(hdr_skb);
  911. if (ieee80211_is_beacon(hdr->frame_control)) {
  912. RX_STAT_INC(rx_beacons);
  913. if (!is_zero_ether_addr(common->curbssid) &&
  914. ether_addr_equal(hdr->addr3, common->curbssid))
  915. rs.is_mybeacon = true;
  916. else
  917. rs.is_mybeacon = false;
  918. }
  919. else
  920. rs.is_mybeacon = false;
  921. sc->rx.num_pkts++;
  922. ath_debug_stat_rx(sc, &rs);
  923. /*
  924. * If we're asked to flush receive queue, directly
  925. * chain it back at the queue without processing it.
  926. */
  927. if (test_bit(SC_OP_RXFLUSH, &sc->sc_flags)) {
  928. RX_STAT_INC(rx_drop_rxflush);
  929. goto requeue_drop_frag;
  930. }
  931. memset(rxs, 0, sizeof(struct ieee80211_rx_status));
  932. rxs->mactime = (tsf & ~0xffffffffULL) | rs.rs_tstamp;
  933. if (rs.rs_tstamp > tsf_lower &&
  934. unlikely(rs.rs_tstamp - tsf_lower > 0x10000000))
  935. rxs->mactime -= 0x100000000ULL;
  936. if (rs.rs_tstamp < tsf_lower &&
  937. unlikely(tsf_lower - rs.rs_tstamp > 0x10000000))
  938. rxs->mactime += 0x100000000ULL;
  939. retval = ath9k_rx_skb_preprocess(common, hw, hdr, &rs,
  940. rxs, &decrypt_error);
  941. if (retval)
  942. goto requeue_drop_frag;
  943. if (rs.is_mybeacon) {
  944. sc->hw_busy_count = 0;
  945. ath_start_rx_poll(sc, 3);
  946. }
  947. /* Ensure we always have an skb to requeue once we are done
  948. * processing the current buffer's skb */
  949. requeue_skb = ath_rxbuf_alloc(common, common->rx_bufsize, GFP_ATOMIC);
  950. /* If there is no memory we ignore the current RX'd frame,
  951. * tell hardware it can give us a new frame using the old
  952. * skb and put it at the tail of the sc->rx.rxbuf list for
  953. * processing. */
  954. if (!requeue_skb) {
  955. RX_STAT_INC(rx_oom_err);
  956. goto requeue_drop_frag;
  957. }
  958. /* Unmap the frame */
  959. dma_unmap_single(sc->dev, bf->bf_buf_addr,
  960. common->rx_bufsize,
  961. dma_type);
  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_rx_skb_postprocess(common, hdr_skb, &rs,
  967. rxs, decrypt_error);
  968. /* We will now give hardware our shiny new allocated skb */
  969. bf->bf_mpdu = requeue_skb;
  970. bf->bf_buf_addr = dma_map_single(sc->dev, requeue_skb->data,
  971. common->rx_bufsize,
  972. dma_type);
  973. if (unlikely(dma_mapping_error(sc->dev,
  974. bf->bf_buf_addr))) {
  975. dev_kfree_skb_any(requeue_skb);
  976. bf->bf_mpdu = NULL;
  977. bf->bf_buf_addr = 0;
  978. ath_err(common, "dma_mapping_error() on RX\n");
  979. ieee80211_rx(hw, skb);
  980. break;
  981. }
  982. if (rs.rs_more) {
  983. RX_STAT_INC(rx_frags);
  984. /*
  985. * rs_more indicates chained descriptors which can be
  986. * used to link buffers together for a sort of
  987. * scatter-gather operation.
  988. */
  989. if (sc->rx.frag) {
  990. /* too many fragments - cannot handle frame */
  991. dev_kfree_skb_any(sc->rx.frag);
  992. dev_kfree_skb_any(skb);
  993. RX_STAT_INC(rx_too_many_frags_err);
  994. skb = NULL;
  995. }
  996. sc->rx.frag = skb;
  997. goto requeue;
  998. }
  999. if (sc->rx.frag) {
  1000. int space = skb->len - skb_tailroom(hdr_skb);
  1001. if (pskb_expand_head(hdr_skb, 0, space, GFP_ATOMIC) < 0) {
  1002. dev_kfree_skb(skb);
  1003. RX_STAT_INC(rx_oom_err);
  1004. goto requeue_drop_frag;
  1005. }
  1006. sc->rx.frag = NULL;
  1007. skb_copy_from_linear_data(skb, skb_put(hdr_skb, skb->len),
  1008. skb->len);
  1009. dev_kfree_skb_any(skb);
  1010. skb = hdr_skb;
  1011. }
  1012. if (ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB) {
  1013. /*
  1014. * change the default rx antenna if rx diversity
  1015. * chooses the other antenna 3 times in a row.
  1016. */
  1017. if (sc->rx.defant != rs.rs_antenna) {
  1018. if (++sc->rx.rxotherant >= 3)
  1019. ath_setdefantenna(sc, rs.rs_antenna);
  1020. } else {
  1021. sc->rx.rxotherant = 0;
  1022. }
  1023. }
  1024. if (rxs->flag & RX_FLAG_MMIC_STRIPPED)
  1025. skb_trim(skb, skb->len - 8);
  1026. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  1027. if ((sc->ps_flags & (PS_WAIT_FOR_BEACON |
  1028. PS_WAIT_FOR_CAB |
  1029. PS_WAIT_FOR_PSPOLL_DATA)) ||
  1030. ath9k_check_auto_sleep(sc))
  1031. ath_rx_ps(sc, skb, rs.is_mybeacon);
  1032. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  1033. if ((ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB) && sc->ant_rx == 3)
  1034. ath_ant_comb_scan(sc, &rs);
  1035. ieee80211_rx(hw, skb);
  1036. requeue_drop_frag:
  1037. if (sc->rx.frag) {
  1038. dev_kfree_skb_any(sc->rx.frag);
  1039. sc->rx.frag = NULL;
  1040. }
  1041. requeue:
  1042. if (edma) {
  1043. list_add_tail(&bf->list, &sc->rx.rxbuf);
  1044. ath_rx_edma_buf_link(sc, qtype);
  1045. } else {
  1046. list_move_tail(&bf->list, &sc->rx.rxbuf);
  1047. ath_rx_buf_link(sc, bf);
  1048. if (!flush)
  1049. ath9k_hw_rxena(ah);
  1050. }
  1051. } while (1);
  1052. spin_unlock_bh(&sc->rx.rxbuflock);
  1053. if (!(ah->imask & ATH9K_INT_RXEOL)) {
  1054. ah->imask |= (ATH9K_INT_RXEOL | ATH9K_INT_RXORN);
  1055. ath9k_hw_set_interrupts(ah);
  1056. }
  1057. return 0;
  1058. }