recv.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220
  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. struct ath_hw *ah = common->ah;
  845. memset(rx_status, 0, sizeof(struct ieee80211_rx_status));
  846. /*
  847. * everything but the rate is checked here, the rate check is done
  848. * separately to avoid doing two lookups for a rate for each frame.
  849. */
  850. if (!ath9k_rx_accept(common, hdr, rx_status, rx_stats, decrypt_error))
  851. return -EINVAL;
  852. ath9k_process_rssi(common, hw, hdr, rx_stats);
  853. if (ath9k_process_rate(common, hw, rx_stats, rx_status))
  854. return -EINVAL;
  855. rx_status->mactime = ath9k_hw_extend_tsf(ah, rx_stats->rs_tstamp);
  856. rx_status->band = hw->conf.channel->band;
  857. rx_status->freq = hw->conf.channel->center_freq;
  858. rx_status->signal = ATH_DEFAULT_NOISE_FLOOR + rx_stats->rs_rssi;
  859. rx_status->antenna = rx_stats->rs_antenna;
  860. rx_status->flag |= RX_FLAG_TSFT;
  861. return 0;
  862. }
  863. static void ath9k_rx_skb_postprocess(struct ath_common *common,
  864. struct sk_buff *skb,
  865. struct ath_rx_status *rx_stats,
  866. struct ieee80211_rx_status *rxs,
  867. bool decrypt_error)
  868. {
  869. struct ath_hw *ah = common->ah;
  870. struct ieee80211_hdr *hdr;
  871. int hdrlen, padpos, padsize;
  872. u8 keyix;
  873. __le16 fc;
  874. /* see if any padding is done by the hw and remove it */
  875. hdr = (struct ieee80211_hdr *) skb->data;
  876. hdrlen = ieee80211_get_hdrlen_from_skb(skb);
  877. fc = hdr->frame_control;
  878. padpos = ath9k_cmn_padpos(hdr->frame_control);
  879. /* The MAC header is padded to have 32-bit boundary if the
  880. * packet payload is non-zero. The general calculation for
  881. * padsize would take into account odd header lengths:
  882. * padsize = (4 - padpos % 4) % 4; However, since only
  883. * even-length headers are used, padding can only be 0 or 2
  884. * bytes and we can optimize this a bit. In addition, we must
  885. * not try to remove padding from short control frames that do
  886. * not have payload. */
  887. padsize = padpos & 3;
  888. if (padsize && skb->len>=padpos+padsize+FCS_LEN) {
  889. memmove(skb->data + padsize, skb->data, padpos);
  890. skb_pull(skb, padsize);
  891. }
  892. keyix = rx_stats->rs_keyix;
  893. if (!(keyix == ATH9K_RXKEYIX_INVALID) && !decrypt_error &&
  894. ieee80211_has_protected(fc)) {
  895. rxs->flag |= RX_FLAG_DECRYPTED;
  896. } else if (ieee80211_has_protected(fc)
  897. && !decrypt_error && skb->len >= hdrlen + 4) {
  898. keyix = skb->data[hdrlen + 3] >> 6;
  899. if (test_bit(keyix, common->keymap))
  900. rxs->flag |= RX_FLAG_DECRYPTED;
  901. }
  902. if (ah->sw_mgmt_crypto &&
  903. (rxs->flag & RX_FLAG_DECRYPTED) &&
  904. ieee80211_is_mgmt(fc))
  905. /* Use software decrypt for management frames. */
  906. rxs->flag &= ~RX_FLAG_DECRYPTED;
  907. }
  908. int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp)
  909. {
  910. struct ath_buf *bf;
  911. struct sk_buff *skb = NULL, *requeue_skb;
  912. struct ieee80211_rx_status *rxs;
  913. struct ath_hw *ah = sc->sc_ah;
  914. struct ath_common *common = ath9k_hw_common(ah);
  915. /*
  916. * The hw can techncically differ from common->hw when using ath9k
  917. * virtual wiphy so to account for that we iterate over the active
  918. * wiphys and find the appropriate wiphy and therefore hw.
  919. */
  920. struct ieee80211_hw *hw = NULL;
  921. struct ieee80211_hdr *hdr;
  922. int retval;
  923. bool decrypt_error = false;
  924. struct ath_rx_status rs;
  925. enum ath9k_rx_qtype qtype;
  926. bool edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA);
  927. int dma_type;
  928. u8 rx_status_len = ah->caps.rx_status_len;
  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. 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. retval = ath9k_rx_skb_preprocess(common, hw, hdr, &rs,
  960. rxs, &decrypt_error);
  961. if (retval)
  962. goto requeue;
  963. /* Ensure we always have an skb to requeue once we are done
  964. * processing the current buffer's skb */
  965. requeue_skb = ath_rxbuf_alloc(common, common->rx_bufsize, GFP_ATOMIC);
  966. /* If there is no memory we ignore the current RX'd frame,
  967. * tell hardware it can give us a new frame using the old
  968. * skb and put it at the tail of the sc->rx.rxbuf list for
  969. * processing. */
  970. if (!requeue_skb)
  971. goto requeue;
  972. /* Unmap the frame */
  973. dma_unmap_single(sc->dev, bf->bf_buf_addr,
  974. common->rx_bufsize,
  975. dma_type);
  976. skb_put(skb, rs.rs_datalen + ah->caps.rx_status_len);
  977. if (ah->caps.rx_status_len)
  978. skb_pull(skb, ah->caps.rx_status_len);
  979. ath9k_rx_skb_postprocess(common, skb, &rs,
  980. rxs, decrypt_error);
  981. /* We will now give hardware our shiny new allocated skb */
  982. bf->bf_mpdu = requeue_skb;
  983. bf->bf_buf_addr = dma_map_single(sc->dev, requeue_skb->data,
  984. common->rx_bufsize,
  985. dma_type);
  986. if (unlikely(dma_mapping_error(sc->dev,
  987. bf->bf_buf_addr))) {
  988. dev_kfree_skb_any(requeue_skb);
  989. bf->bf_mpdu = NULL;
  990. ath_print(common, ATH_DBG_FATAL,
  991. "dma_mapping_error() on RX\n");
  992. ath_rx_send_to_mac80211(hw, sc, skb, rxs);
  993. break;
  994. }
  995. bf->bf_dmacontext = bf->bf_buf_addr;
  996. /*
  997. * change the default rx antenna if rx diversity chooses the
  998. * other antenna 3 times in a row.
  999. */
  1000. if (sc->rx.defant != rs.rs_antenna) {
  1001. if (++sc->rx.rxotherant >= 3)
  1002. ath_setdefantenna(sc, rs.rs_antenna);
  1003. } else {
  1004. sc->rx.rxotherant = 0;
  1005. }
  1006. if (unlikely(ath9k_check_auto_sleep(sc) ||
  1007. (sc->ps_flags & (PS_WAIT_FOR_BEACON |
  1008. PS_WAIT_FOR_CAB |
  1009. PS_WAIT_FOR_PSPOLL_DATA))))
  1010. ath_rx_ps(sc, skb);
  1011. ath_rx_send_to_mac80211(hw, sc, skb, rxs);
  1012. requeue:
  1013. if (edma) {
  1014. list_add_tail(&bf->list, &sc->rx.rxbuf);
  1015. ath_rx_edma_buf_link(sc, qtype);
  1016. } else {
  1017. list_move_tail(&bf->list, &sc->rx.rxbuf);
  1018. ath_rx_buf_link(sc, bf);
  1019. }
  1020. } while (1);
  1021. spin_unlock_bh(&sc->rx.rxbuflock);
  1022. return 0;
  1023. }