recv.c 32 KB

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