recv.c 32 KB

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