recv.c 32 KB

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