recv.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184
  1. /*
  2. * Copyright (c) 2008-2011 Atheros Communications Inc.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include <linux/dma-mapping.h>
  17. #include "ath9k.h"
  18. #include "ar9003_mac.h"
  19. #define SKB_CB_ATHBUF(__skb) (*((struct ath_rxbuf **)__skb->cb))
  20. static inline bool ath9k_check_auto_sleep(struct ath_softc *sc)
  21. {
  22. return sc->ps_enabled &&
  23. (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP);
  24. }
  25. /*
  26. * Setup and link descriptors.
  27. *
  28. * 11N: we can no longer afford to self link the last descriptor.
  29. * MAC acknowledges BA status as long as it copies frames to host
  30. * buffer (or rx fifo). This can incorrectly acknowledge packets
  31. * to a sender if last desc is self-linked.
  32. */
  33. static void ath_rx_buf_link(struct ath_softc *sc, struct ath_rxbuf *bf,
  34. bool flush)
  35. {
  36. struct ath_hw *ah = sc->sc_ah;
  37. struct ath_common *common = ath9k_hw_common(ah);
  38. struct ath_desc *ds;
  39. struct sk_buff *skb;
  40. ds = bf->bf_desc;
  41. ds->ds_link = 0; /* link to null */
  42. ds->ds_data = bf->bf_buf_addr;
  43. /* virtual addr of the beginning of the buffer. */
  44. skb = bf->bf_mpdu;
  45. BUG_ON(skb == NULL);
  46. ds->ds_vdata = skb->data;
  47. /*
  48. * setup rx descriptors. The rx_bufsize here tells the hardware
  49. * how much data it can DMA to us and that we are prepared
  50. * to process
  51. */
  52. ath9k_hw_setuprxdesc(ah, ds,
  53. common->rx_bufsize,
  54. 0);
  55. if (sc->rx.rxlink)
  56. *sc->rx.rxlink = bf->bf_daddr;
  57. else if (!flush)
  58. ath9k_hw_putrxbuf(ah, bf->bf_daddr);
  59. sc->rx.rxlink = &ds->ds_link;
  60. }
  61. static void ath_rx_buf_relink(struct ath_softc *sc, struct ath_rxbuf *bf,
  62. bool flush)
  63. {
  64. if (sc->rx.buf_hold)
  65. ath_rx_buf_link(sc, sc->rx.buf_hold, flush);
  66. sc->rx.buf_hold = bf;
  67. }
  68. static void ath_setdefantenna(struct ath_softc *sc, u32 antenna)
  69. {
  70. /* XXX block beacon interrupts */
  71. ath9k_hw_setantenna(sc->sc_ah, antenna);
  72. sc->rx.defant = antenna;
  73. sc->rx.rxotherant = 0;
  74. }
  75. static void ath_opmode_init(struct ath_softc *sc)
  76. {
  77. struct ath_hw *ah = sc->sc_ah;
  78. struct ath_common *common = ath9k_hw_common(ah);
  79. u32 rfilt, mfilt[2];
  80. /* configure rx filter */
  81. rfilt = ath_calcrxfilter(sc);
  82. ath9k_hw_setrxfilter(ah, rfilt);
  83. /* configure bssid mask */
  84. ath_hw_setbssidmask(common);
  85. /* configure operational mode */
  86. ath9k_hw_setopmode(ah);
  87. /* calculate and install multicast filter */
  88. mfilt[0] = mfilt[1] = ~0;
  89. ath9k_hw_setmcastfilter(ah, mfilt[0], mfilt[1]);
  90. }
  91. static bool ath_rx_edma_buf_link(struct ath_softc *sc,
  92. enum ath9k_rx_qtype qtype)
  93. {
  94. struct ath_hw *ah = sc->sc_ah;
  95. struct ath_rx_edma *rx_edma;
  96. struct sk_buff *skb;
  97. struct ath_rxbuf *bf;
  98. rx_edma = &sc->rx.rx_edma[qtype];
  99. if (skb_queue_len(&rx_edma->rx_fifo) >= rx_edma->rx_fifo_hwsize)
  100. return false;
  101. bf = list_first_entry(&sc->rx.rxbuf, struct ath_rxbuf, list);
  102. list_del_init(&bf->list);
  103. skb = bf->bf_mpdu;
  104. memset(skb->data, 0, ah->caps.rx_status_len);
  105. dma_sync_single_for_device(sc->dev, bf->bf_buf_addr,
  106. ah->caps.rx_status_len, DMA_TO_DEVICE);
  107. SKB_CB_ATHBUF(skb) = bf;
  108. ath9k_hw_addrxbuf_edma(ah, bf->bf_buf_addr, qtype);
  109. __skb_queue_tail(&rx_edma->rx_fifo, skb);
  110. return true;
  111. }
  112. static void ath_rx_addbuffer_edma(struct ath_softc *sc,
  113. enum ath9k_rx_qtype qtype)
  114. {
  115. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  116. struct ath_rxbuf *bf, *tbf;
  117. if (list_empty(&sc->rx.rxbuf)) {
  118. ath_dbg(common, QUEUE, "No free rx buf available\n");
  119. return;
  120. }
  121. list_for_each_entry_safe(bf, tbf, &sc->rx.rxbuf, list)
  122. if (!ath_rx_edma_buf_link(sc, qtype))
  123. break;
  124. }
  125. static void ath_rx_remove_buffer(struct ath_softc *sc,
  126. enum ath9k_rx_qtype qtype)
  127. {
  128. struct ath_rxbuf *bf;
  129. struct ath_rx_edma *rx_edma;
  130. struct sk_buff *skb;
  131. rx_edma = &sc->rx.rx_edma[qtype];
  132. while ((skb = __skb_dequeue(&rx_edma->rx_fifo)) != NULL) {
  133. bf = SKB_CB_ATHBUF(skb);
  134. BUG_ON(!bf);
  135. list_add_tail(&bf->list, &sc->rx.rxbuf);
  136. }
  137. }
  138. static void ath_rx_edma_cleanup(struct ath_softc *sc)
  139. {
  140. struct ath_hw *ah = sc->sc_ah;
  141. struct ath_common *common = ath9k_hw_common(ah);
  142. struct ath_rxbuf *bf;
  143. ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_LP);
  144. ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_HP);
  145. list_for_each_entry(bf, &sc->rx.rxbuf, list) {
  146. if (bf->bf_mpdu) {
  147. dma_unmap_single(sc->dev, bf->bf_buf_addr,
  148. common->rx_bufsize,
  149. DMA_BIDIRECTIONAL);
  150. dev_kfree_skb_any(bf->bf_mpdu);
  151. bf->bf_buf_addr = 0;
  152. bf->bf_mpdu = NULL;
  153. }
  154. }
  155. }
  156. static void ath_rx_edma_init_queue(struct ath_rx_edma *rx_edma, int size)
  157. {
  158. __skb_queue_head_init(&rx_edma->rx_fifo);
  159. rx_edma->rx_fifo_hwsize = size;
  160. }
  161. static int ath_rx_edma_init(struct ath_softc *sc, int nbufs)
  162. {
  163. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  164. struct ath_hw *ah = sc->sc_ah;
  165. struct sk_buff *skb;
  166. struct ath_rxbuf *bf;
  167. int error = 0, i;
  168. u32 size;
  169. ath9k_hw_set_rx_bufsize(ah, common->rx_bufsize -
  170. ah->caps.rx_status_len);
  171. ath_rx_edma_init_queue(&sc->rx.rx_edma[ATH9K_RX_QUEUE_LP],
  172. ah->caps.rx_lp_qdepth);
  173. ath_rx_edma_init_queue(&sc->rx.rx_edma[ATH9K_RX_QUEUE_HP],
  174. ah->caps.rx_hp_qdepth);
  175. size = sizeof(struct ath_rxbuf) * nbufs;
  176. bf = devm_kzalloc(sc->dev, size, GFP_KERNEL);
  177. if (!bf)
  178. return -ENOMEM;
  179. INIT_LIST_HEAD(&sc->rx.rxbuf);
  180. for (i = 0; i < nbufs; i++, bf++) {
  181. skb = ath_rxbuf_alloc(common, common->rx_bufsize, GFP_KERNEL);
  182. if (!skb) {
  183. error = -ENOMEM;
  184. goto rx_init_fail;
  185. }
  186. memset(skb->data, 0, common->rx_bufsize);
  187. bf->bf_mpdu = skb;
  188. bf->bf_buf_addr = dma_map_single(sc->dev, skb->data,
  189. common->rx_bufsize,
  190. DMA_BIDIRECTIONAL);
  191. if (unlikely(dma_mapping_error(sc->dev,
  192. bf->bf_buf_addr))) {
  193. dev_kfree_skb_any(skb);
  194. bf->bf_mpdu = NULL;
  195. bf->bf_buf_addr = 0;
  196. ath_err(common,
  197. "dma_mapping_error() on RX init\n");
  198. error = -ENOMEM;
  199. goto rx_init_fail;
  200. }
  201. list_add_tail(&bf->list, &sc->rx.rxbuf);
  202. }
  203. return 0;
  204. rx_init_fail:
  205. ath_rx_edma_cleanup(sc);
  206. return error;
  207. }
  208. static void ath_edma_start_recv(struct ath_softc *sc)
  209. {
  210. ath9k_hw_rxena(sc->sc_ah);
  211. ath_rx_addbuffer_edma(sc, ATH9K_RX_QUEUE_HP);
  212. ath_rx_addbuffer_edma(sc, ATH9K_RX_QUEUE_LP);
  213. ath_opmode_init(sc);
  214. ath9k_hw_startpcureceive(sc->sc_ah, sc->cur_chan->offchannel);
  215. }
  216. static void ath_edma_stop_recv(struct ath_softc *sc)
  217. {
  218. ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_HP);
  219. ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_LP);
  220. }
  221. int ath_rx_init(struct ath_softc *sc, int nbufs)
  222. {
  223. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  224. struct sk_buff *skb;
  225. struct ath_rxbuf *bf;
  226. int error = 0;
  227. spin_lock_init(&sc->sc_pcu_lock);
  228. common->rx_bufsize = IEEE80211_MAX_MPDU_LEN / 2 +
  229. sc->sc_ah->caps.rx_status_len;
  230. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
  231. return ath_rx_edma_init(sc, nbufs);
  232. ath_dbg(common, CONFIG, "cachelsz %u rxbufsize %u\n",
  233. common->cachelsz, common->rx_bufsize);
  234. /* Initialize rx descriptors */
  235. error = ath_descdma_setup(sc, &sc->rx.rxdma, &sc->rx.rxbuf,
  236. "rx", nbufs, 1, 0);
  237. if (error != 0) {
  238. ath_err(common,
  239. "failed to allocate rx descriptors: %d\n",
  240. error);
  241. goto err;
  242. }
  243. list_for_each_entry(bf, &sc->rx.rxbuf, list) {
  244. skb = ath_rxbuf_alloc(common, common->rx_bufsize,
  245. GFP_KERNEL);
  246. if (skb == NULL) {
  247. error = -ENOMEM;
  248. goto err;
  249. }
  250. bf->bf_mpdu = skb;
  251. bf->bf_buf_addr = dma_map_single(sc->dev, skb->data,
  252. common->rx_bufsize,
  253. DMA_FROM_DEVICE);
  254. if (unlikely(dma_mapping_error(sc->dev,
  255. bf->bf_buf_addr))) {
  256. dev_kfree_skb_any(skb);
  257. bf->bf_mpdu = NULL;
  258. bf->bf_buf_addr = 0;
  259. ath_err(common,
  260. "dma_mapping_error() on RX init\n");
  261. error = -ENOMEM;
  262. goto err;
  263. }
  264. }
  265. sc->rx.rxlink = NULL;
  266. err:
  267. if (error)
  268. ath_rx_cleanup(sc);
  269. return error;
  270. }
  271. void ath_rx_cleanup(struct ath_softc *sc)
  272. {
  273. struct ath_hw *ah = sc->sc_ah;
  274. struct ath_common *common = ath9k_hw_common(ah);
  275. struct sk_buff *skb;
  276. struct ath_rxbuf *bf;
  277. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
  278. ath_rx_edma_cleanup(sc);
  279. return;
  280. }
  281. list_for_each_entry(bf, &sc->rx.rxbuf, list) {
  282. skb = bf->bf_mpdu;
  283. if (skb) {
  284. dma_unmap_single(sc->dev, bf->bf_buf_addr,
  285. common->rx_bufsize,
  286. DMA_FROM_DEVICE);
  287. dev_kfree_skb(skb);
  288. bf->bf_buf_addr = 0;
  289. bf->bf_mpdu = NULL;
  290. }
  291. }
  292. }
  293. /*
  294. * Calculate the receive filter according to the
  295. * operating mode and state:
  296. *
  297. * o always accept unicast, broadcast, and multicast traffic
  298. * o maintain current state of phy error reception (the hal
  299. * may enable phy error frames for noise immunity work)
  300. * o probe request frames are accepted only when operating in
  301. * hostap, adhoc, or monitor modes
  302. * o enable promiscuous mode according to the interface state
  303. * o accept beacons:
  304. * - when operating in adhoc mode so the 802.11 layer creates
  305. * node table entries for peers,
  306. * - when operating in station mode for collecting rssi data when
  307. * the station is otherwise quiet, or
  308. * - when operating as a repeater so we see repeater-sta beacons
  309. * - when scanning
  310. */
  311. u32 ath_calcrxfilter(struct ath_softc *sc)
  312. {
  313. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  314. u32 rfilt;
  315. if (IS_ENABLED(CONFIG_ATH9K_TX99))
  316. return 0;
  317. rfilt = ATH9K_RX_FILTER_UCAST | ATH9K_RX_FILTER_BCAST
  318. | ATH9K_RX_FILTER_MCAST;
  319. /* if operating on a DFS channel, enable radar pulse detection */
  320. if (sc->hw->conf.radar_enabled)
  321. rfilt |= ATH9K_RX_FILTER_PHYRADAR | ATH9K_RX_FILTER_PHYERR;
  322. spin_lock_bh(&sc->chan_lock);
  323. if (sc->cur_chan->rxfilter & FIF_PROBE_REQ)
  324. rfilt |= ATH9K_RX_FILTER_PROBEREQ;
  325. if (sc->sc_ah->is_monitoring)
  326. rfilt |= ATH9K_RX_FILTER_PROM;
  327. if ((sc->cur_chan->rxfilter & FIF_CONTROL) ||
  328. sc->sc_ah->dynack.enabled)
  329. rfilt |= ATH9K_RX_FILTER_CONTROL;
  330. if ((sc->sc_ah->opmode == NL80211_IFTYPE_STATION) &&
  331. (sc->cur_chan->nvifs <= 1) &&
  332. !(sc->cur_chan->rxfilter & FIF_BCN_PRBRESP_PROMISC))
  333. rfilt |= ATH9K_RX_FILTER_MYBEACON;
  334. else if (sc->sc_ah->opmode != NL80211_IFTYPE_OCB)
  335. rfilt |= ATH9K_RX_FILTER_BEACON;
  336. if ((sc->sc_ah->opmode == NL80211_IFTYPE_AP) ||
  337. (sc->cur_chan->rxfilter & FIF_PSPOLL))
  338. rfilt |= ATH9K_RX_FILTER_PSPOLL;
  339. if (sc->cur_chandef.width != NL80211_CHAN_WIDTH_20_NOHT)
  340. rfilt |= ATH9K_RX_FILTER_COMP_BAR;
  341. if (sc->cur_chan->nvifs > 1 || (sc->cur_chan->rxfilter & FIF_OTHER_BSS)) {
  342. /* This is needed for older chips */
  343. if (sc->sc_ah->hw_version.macVersion <= AR_SREV_VERSION_9160)
  344. rfilt |= ATH9K_RX_FILTER_PROM;
  345. rfilt |= ATH9K_RX_FILTER_MCAST_BCAST_ALL;
  346. }
  347. if (AR_SREV_9550(sc->sc_ah) || AR_SREV_9531(sc->sc_ah) ||
  348. AR_SREV_9561(sc->sc_ah))
  349. rfilt |= ATH9K_RX_FILTER_4ADDRESS;
  350. if (AR_SREV_9462(sc->sc_ah) || AR_SREV_9565(sc->sc_ah))
  351. rfilt |= ATH9K_RX_FILTER_CONTROL_WRAPPER;
  352. if (ath9k_is_chanctx_enabled() &&
  353. test_bit(ATH_OP_SCANNING, &common->op_flags))
  354. rfilt |= ATH9K_RX_FILTER_BEACON;
  355. spin_unlock_bh(&sc->chan_lock);
  356. return rfilt;
  357. }
  358. void ath_startrecv(struct ath_softc *sc)
  359. {
  360. struct ath_hw *ah = sc->sc_ah;
  361. struct ath_rxbuf *bf, *tbf;
  362. if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
  363. ath_edma_start_recv(sc);
  364. return;
  365. }
  366. if (list_empty(&sc->rx.rxbuf))
  367. goto start_recv;
  368. sc->rx.buf_hold = NULL;
  369. sc->rx.rxlink = NULL;
  370. list_for_each_entry_safe(bf, tbf, &sc->rx.rxbuf, list) {
  371. ath_rx_buf_link(sc, bf, false);
  372. }
  373. /* We could have deleted elements so the list may be empty now */
  374. if (list_empty(&sc->rx.rxbuf))
  375. goto start_recv;
  376. bf = list_first_entry(&sc->rx.rxbuf, struct ath_rxbuf, list);
  377. ath9k_hw_putrxbuf(ah, bf->bf_daddr);
  378. ath9k_hw_rxena(ah);
  379. start_recv:
  380. ath_opmode_init(sc);
  381. ath9k_hw_startpcureceive(ah, sc->cur_chan->offchannel);
  382. }
  383. static void ath_flushrecv(struct ath_softc *sc)
  384. {
  385. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
  386. ath_rx_tasklet(sc, 1, true);
  387. ath_rx_tasklet(sc, 1, false);
  388. }
  389. bool ath_stoprecv(struct ath_softc *sc)
  390. {
  391. struct ath_hw *ah = sc->sc_ah;
  392. bool stopped, reset = false;
  393. ath9k_hw_abortpcurecv(ah);
  394. ath9k_hw_setrxfilter(ah, 0);
  395. stopped = ath9k_hw_stopdmarecv(ah, &reset);
  396. ath_flushrecv(sc);
  397. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
  398. ath_edma_stop_recv(sc);
  399. else
  400. sc->rx.rxlink = NULL;
  401. if (!(ah->ah_flags & AH_UNPLUGGED) &&
  402. unlikely(!stopped)) {
  403. ath_dbg(ath9k_hw_common(sc->sc_ah), RESET,
  404. "Failed to stop Rx DMA\n");
  405. RESET_STAT_INC(sc, RESET_RX_DMA_ERROR);
  406. }
  407. return stopped && !reset;
  408. }
  409. static bool ath_beacon_dtim_pending_cab(struct sk_buff *skb)
  410. {
  411. /* Check whether the Beacon frame has DTIM indicating buffered bc/mc */
  412. struct ieee80211_mgmt *mgmt;
  413. u8 *pos, *end, id, elen;
  414. struct ieee80211_tim_ie *tim;
  415. mgmt = (struct ieee80211_mgmt *)skb->data;
  416. pos = mgmt->u.beacon.variable;
  417. end = skb->data + skb->len;
  418. while (pos + 2 < end) {
  419. id = *pos++;
  420. elen = *pos++;
  421. if (pos + elen > end)
  422. break;
  423. if (id == WLAN_EID_TIM) {
  424. if (elen < sizeof(*tim))
  425. break;
  426. tim = (struct ieee80211_tim_ie *) pos;
  427. if (tim->dtim_count != 0)
  428. break;
  429. return tim->bitmap_ctrl & 0x01;
  430. }
  431. pos += elen;
  432. }
  433. return false;
  434. }
  435. static void ath_rx_ps_beacon(struct ath_softc *sc, struct sk_buff *skb)
  436. {
  437. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  438. bool skip_beacon = false;
  439. if (skb->len < 24 + 8 + 2 + 2)
  440. return;
  441. sc->ps_flags &= ~PS_WAIT_FOR_BEACON;
  442. if (sc->ps_flags & PS_BEACON_SYNC) {
  443. sc->ps_flags &= ~PS_BEACON_SYNC;
  444. ath_dbg(common, PS,
  445. "Reconfigure beacon timers based on synchronized timestamp\n");
  446. #ifdef CONFIG_ATH9K_CHANNEL_CONTEXT
  447. if (ath9k_is_chanctx_enabled()) {
  448. if (sc->cur_chan == &sc->offchannel.chan)
  449. skip_beacon = true;
  450. }
  451. #endif
  452. if (!skip_beacon &&
  453. !(WARN_ON_ONCE(sc->cur_chan->beacon.beacon_interval == 0)))
  454. ath9k_set_beacon(sc);
  455. ath9k_p2p_beacon_sync(sc);
  456. }
  457. if (ath_beacon_dtim_pending_cab(skb)) {
  458. /*
  459. * Remain awake waiting for buffered broadcast/multicast
  460. * frames. If the last broadcast/multicast frame is not
  461. * received properly, the next beacon frame will work as
  462. * a backup trigger for returning into NETWORK SLEEP state,
  463. * so we are waiting for it as well.
  464. */
  465. ath_dbg(common, PS,
  466. "Received DTIM beacon indicating buffered broadcast/multicast frame(s)\n");
  467. sc->ps_flags |= PS_WAIT_FOR_CAB | PS_WAIT_FOR_BEACON;
  468. return;
  469. }
  470. if (sc->ps_flags & PS_WAIT_FOR_CAB) {
  471. /*
  472. * This can happen if a broadcast frame is dropped or the AP
  473. * fails to send a frame indicating that all CAB frames have
  474. * been delivered.
  475. */
  476. sc->ps_flags &= ~PS_WAIT_FOR_CAB;
  477. ath_dbg(common, PS, "PS wait for CAB frames timed out\n");
  478. }
  479. }
  480. static void ath_rx_ps(struct ath_softc *sc, struct sk_buff *skb, bool mybeacon)
  481. {
  482. struct ieee80211_hdr *hdr;
  483. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  484. hdr = (struct ieee80211_hdr *)skb->data;
  485. /* Process Beacon and CAB receive in PS state */
  486. if (((sc->ps_flags & PS_WAIT_FOR_BEACON) || ath9k_check_auto_sleep(sc))
  487. && mybeacon) {
  488. ath_rx_ps_beacon(sc, skb);
  489. } else if ((sc->ps_flags & PS_WAIT_FOR_CAB) &&
  490. (ieee80211_is_data(hdr->frame_control) ||
  491. ieee80211_is_action(hdr->frame_control)) &&
  492. is_multicast_ether_addr(hdr->addr1) &&
  493. !ieee80211_has_moredata(hdr->frame_control)) {
  494. /*
  495. * No more broadcast/multicast frames to be received at this
  496. * point.
  497. */
  498. sc->ps_flags &= ~(PS_WAIT_FOR_CAB | PS_WAIT_FOR_BEACON);
  499. ath_dbg(common, PS,
  500. "All PS CAB frames received, back to sleep\n");
  501. } else if ((sc->ps_flags & PS_WAIT_FOR_PSPOLL_DATA) &&
  502. !is_multicast_ether_addr(hdr->addr1) &&
  503. !ieee80211_has_morefrags(hdr->frame_control)) {
  504. sc->ps_flags &= ~PS_WAIT_FOR_PSPOLL_DATA;
  505. ath_dbg(common, PS,
  506. "Going back to sleep after having received PS-Poll data (0x%lx)\n",
  507. sc->ps_flags & (PS_WAIT_FOR_BEACON |
  508. PS_WAIT_FOR_CAB |
  509. PS_WAIT_FOR_PSPOLL_DATA |
  510. PS_WAIT_FOR_TX_ACK));
  511. }
  512. }
  513. static bool ath_edma_get_buffers(struct ath_softc *sc,
  514. enum ath9k_rx_qtype qtype,
  515. struct ath_rx_status *rs,
  516. struct ath_rxbuf **dest)
  517. {
  518. struct ath_rx_edma *rx_edma = &sc->rx.rx_edma[qtype];
  519. struct ath_hw *ah = sc->sc_ah;
  520. struct ath_common *common = ath9k_hw_common(ah);
  521. struct sk_buff *skb;
  522. struct ath_rxbuf *bf;
  523. int ret;
  524. skb = skb_peek(&rx_edma->rx_fifo);
  525. if (!skb)
  526. return false;
  527. bf = SKB_CB_ATHBUF(skb);
  528. BUG_ON(!bf);
  529. dma_sync_single_for_cpu(sc->dev, bf->bf_buf_addr,
  530. common->rx_bufsize, DMA_FROM_DEVICE);
  531. ret = ath9k_hw_process_rxdesc_edma(ah, rs, skb->data);
  532. if (ret == -EINPROGRESS) {
  533. /*let device gain the buffer again*/
  534. dma_sync_single_for_device(sc->dev, bf->bf_buf_addr,
  535. common->rx_bufsize, DMA_FROM_DEVICE);
  536. return false;
  537. }
  538. __skb_unlink(skb, &rx_edma->rx_fifo);
  539. if (ret == -EINVAL) {
  540. /* corrupt descriptor, skip this one and the following one */
  541. list_add_tail(&bf->list, &sc->rx.rxbuf);
  542. ath_rx_edma_buf_link(sc, qtype);
  543. skb = skb_peek(&rx_edma->rx_fifo);
  544. if (skb) {
  545. bf = SKB_CB_ATHBUF(skb);
  546. BUG_ON(!bf);
  547. __skb_unlink(skb, &rx_edma->rx_fifo);
  548. list_add_tail(&bf->list, &sc->rx.rxbuf);
  549. ath_rx_edma_buf_link(sc, qtype);
  550. }
  551. bf = NULL;
  552. }
  553. *dest = bf;
  554. return true;
  555. }
  556. static struct ath_rxbuf *ath_edma_get_next_rx_buf(struct ath_softc *sc,
  557. struct ath_rx_status *rs,
  558. enum ath9k_rx_qtype qtype)
  559. {
  560. struct ath_rxbuf *bf = NULL;
  561. while (ath_edma_get_buffers(sc, qtype, rs, &bf)) {
  562. if (!bf)
  563. continue;
  564. return bf;
  565. }
  566. return NULL;
  567. }
  568. static struct ath_rxbuf *ath_get_next_rx_buf(struct ath_softc *sc,
  569. struct ath_rx_status *rs)
  570. {
  571. struct ath_hw *ah = sc->sc_ah;
  572. struct ath_common *common = ath9k_hw_common(ah);
  573. struct ath_desc *ds;
  574. struct ath_rxbuf *bf;
  575. int ret;
  576. if (list_empty(&sc->rx.rxbuf)) {
  577. sc->rx.rxlink = NULL;
  578. return NULL;
  579. }
  580. bf = list_first_entry(&sc->rx.rxbuf, struct ath_rxbuf, list);
  581. if (bf == sc->rx.buf_hold)
  582. return NULL;
  583. ds = bf->bf_desc;
  584. /*
  585. * Must provide the virtual address of the current
  586. * descriptor, the physical address, and the virtual
  587. * address of the next descriptor in the h/w chain.
  588. * This allows the HAL to look ahead to see if the
  589. * hardware is done with a descriptor by checking the
  590. * done bit in the following descriptor and the address
  591. * of the current descriptor the DMA engine is working
  592. * on. All this is necessary because of our use of
  593. * a self-linked list to avoid rx overruns.
  594. */
  595. ret = ath9k_hw_rxprocdesc(ah, ds, rs);
  596. if (ret == -EINPROGRESS) {
  597. struct ath_rx_status trs;
  598. struct ath_rxbuf *tbf;
  599. struct ath_desc *tds;
  600. memset(&trs, 0, sizeof(trs));
  601. if (list_is_last(&bf->list, &sc->rx.rxbuf)) {
  602. sc->rx.rxlink = NULL;
  603. return NULL;
  604. }
  605. tbf = list_entry(bf->list.next, struct ath_rxbuf, list);
  606. /*
  607. * On some hardware the descriptor status words could
  608. * get corrupted, including the done bit. Because of
  609. * this, check if the next descriptor's done bit is
  610. * set or not.
  611. *
  612. * If the next descriptor's done bit is set, the current
  613. * descriptor has been corrupted. Force s/w to discard
  614. * this descriptor and continue...
  615. */
  616. tds = tbf->bf_desc;
  617. ret = ath9k_hw_rxprocdesc(ah, tds, &trs);
  618. if (ret == -EINPROGRESS)
  619. return NULL;
  620. /*
  621. * Re-check previous descriptor, in case it has been filled
  622. * in the mean time.
  623. */
  624. ret = ath9k_hw_rxprocdesc(ah, ds, rs);
  625. if (ret == -EINPROGRESS) {
  626. /*
  627. * mark descriptor as zero-length and set the 'more'
  628. * flag to ensure that both buffers get discarded
  629. */
  630. rs->rs_datalen = 0;
  631. rs->rs_more = true;
  632. }
  633. }
  634. list_del(&bf->list);
  635. if (!bf->bf_mpdu)
  636. return bf;
  637. /*
  638. * Synchronize the DMA transfer with CPU before
  639. * 1. accessing the frame
  640. * 2. requeueing the same buffer to h/w
  641. */
  642. dma_sync_single_for_cpu(sc->dev, bf->bf_buf_addr,
  643. common->rx_bufsize,
  644. DMA_FROM_DEVICE);
  645. return bf;
  646. }
  647. static void ath9k_process_tsf(struct ath_rx_status *rs,
  648. struct ieee80211_rx_status *rxs,
  649. u64 tsf)
  650. {
  651. u32 tsf_lower = tsf & 0xffffffff;
  652. rxs->mactime = (tsf & ~0xffffffffULL) | rs->rs_tstamp;
  653. if (rs->rs_tstamp > tsf_lower &&
  654. unlikely(rs->rs_tstamp - tsf_lower > 0x10000000))
  655. rxs->mactime -= 0x100000000ULL;
  656. if (rs->rs_tstamp < tsf_lower &&
  657. unlikely(tsf_lower - rs->rs_tstamp > 0x10000000))
  658. rxs->mactime += 0x100000000ULL;
  659. }
  660. /*
  661. * For Decrypt or Demic errors, we only mark packet status here and always push
  662. * up the frame up to let mac80211 handle the actual error case, be it no
  663. * decryption key or real decryption error. This let us keep statistics there.
  664. */
  665. static int ath9k_rx_skb_preprocess(struct ath_softc *sc,
  666. struct sk_buff *skb,
  667. struct ath_rx_status *rx_stats,
  668. struct ieee80211_rx_status *rx_status,
  669. bool *decrypt_error, u64 tsf)
  670. {
  671. struct ieee80211_hw *hw = sc->hw;
  672. struct ath_hw *ah = sc->sc_ah;
  673. struct ath_common *common = ath9k_hw_common(ah);
  674. struct ieee80211_hdr *hdr;
  675. bool discard_current = sc->rx.discard_next;
  676. /*
  677. * Discard corrupt descriptors which are marked in
  678. * ath_get_next_rx_buf().
  679. */
  680. if (discard_current)
  681. goto corrupt;
  682. sc->rx.discard_next = false;
  683. /*
  684. * Discard zero-length packets.
  685. */
  686. if (!rx_stats->rs_datalen) {
  687. RX_STAT_INC(rx_len_err);
  688. goto corrupt;
  689. }
  690. /*
  691. * rs_status follows rs_datalen so if rs_datalen is too large
  692. * we can take a hint that hardware corrupted it, so ignore
  693. * those frames.
  694. */
  695. if (rx_stats->rs_datalen > (common->rx_bufsize - ah->caps.rx_status_len)) {
  696. RX_STAT_INC(rx_len_err);
  697. goto corrupt;
  698. }
  699. /* Only use status info from the last fragment */
  700. if (rx_stats->rs_more)
  701. return 0;
  702. /*
  703. * Return immediately if the RX descriptor has been marked
  704. * as corrupt based on the various error bits.
  705. *
  706. * This is different from the other corrupt descriptor
  707. * condition handled above.
  708. */
  709. if (rx_stats->rs_status & ATH9K_RXERR_CORRUPT_DESC)
  710. goto corrupt;
  711. hdr = (struct ieee80211_hdr *) (skb->data + ah->caps.rx_status_len);
  712. ath9k_process_tsf(rx_stats, rx_status, tsf);
  713. ath_debug_stat_rx(sc, rx_stats);
  714. /*
  715. * Process PHY errors and return so that the packet
  716. * can be dropped.
  717. */
  718. if (rx_stats->rs_status & ATH9K_RXERR_PHY) {
  719. /*
  720. * DFS and spectral are mutually exclusive
  721. *
  722. * Since some chips use PHYERR_RADAR as indication for both, we
  723. * need to double check which feature is enabled to prevent
  724. * feeding spectral or dfs-detector with wrong frames.
  725. */
  726. if (hw->conf.radar_enabled) {
  727. ath9k_dfs_process_phyerr(sc, hdr, rx_stats,
  728. rx_status->mactime);
  729. } else if (sc->spec_priv.spectral_mode != SPECTRAL_DISABLED &&
  730. ath_cmn_process_fft(&sc->spec_priv, hdr, rx_stats,
  731. rx_status->mactime)) {
  732. RX_STAT_INC(rx_spectral);
  733. }
  734. return -EINVAL;
  735. }
  736. /*
  737. * everything but the rate is checked here, the rate check is done
  738. * separately to avoid doing two lookups for a rate for each frame.
  739. */
  740. spin_lock_bh(&sc->chan_lock);
  741. if (!ath9k_cmn_rx_accept(common, hdr, rx_status, rx_stats, decrypt_error,
  742. sc->cur_chan->rxfilter)) {
  743. spin_unlock_bh(&sc->chan_lock);
  744. return -EINVAL;
  745. }
  746. spin_unlock_bh(&sc->chan_lock);
  747. if (ath_is_mybeacon(common, hdr)) {
  748. RX_STAT_INC(rx_beacons);
  749. rx_stats->is_mybeacon = true;
  750. }
  751. /*
  752. * This shouldn't happen, but have a safety check anyway.
  753. */
  754. if (WARN_ON(!ah->curchan))
  755. return -EINVAL;
  756. if (ath9k_cmn_process_rate(common, hw, rx_stats, rx_status)) {
  757. /*
  758. * No valid hardware bitrate found -- we should not get here
  759. * because hardware has already validated this frame as OK.
  760. */
  761. ath_dbg(common, ANY, "unsupported hw bitrate detected 0x%02x using 1 Mbit\n",
  762. rx_stats->rs_rate);
  763. RX_STAT_INC(rx_rate_err);
  764. return -EINVAL;
  765. }
  766. if (ath9k_is_chanctx_enabled()) {
  767. if (rx_stats->is_mybeacon)
  768. ath_chanctx_beacon_recv_ev(sc,
  769. ATH_CHANCTX_EVENT_BEACON_RECEIVED);
  770. }
  771. ath9k_cmn_process_rssi(common, hw, rx_stats, rx_status);
  772. rx_status->band = ah->curchan->chan->band;
  773. rx_status->freq = ah->curchan->chan->center_freq;
  774. rx_status->antenna = rx_stats->rs_antenna;
  775. rx_status->flag |= RX_FLAG_MACTIME_END;
  776. #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
  777. if (ieee80211_is_data_present(hdr->frame_control) &&
  778. !ieee80211_is_qos_nullfunc(hdr->frame_control))
  779. sc->rx.num_pkts++;
  780. #endif
  781. return 0;
  782. corrupt:
  783. sc->rx.discard_next = rx_stats->rs_more;
  784. return -EINVAL;
  785. }
  786. /*
  787. * Run the LNA combining algorithm only in these cases:
  788. *
  789. * Standalone WLAN cards with both LNA/Antenna diversity
  790. * enabled in the EEPROM.
  791. *
  792. * WLAN+BT cards which are in the supported card list
  793. * in ath_pci_id_table and the user has loaded the
  794. * driver with "bt_ant_diversity" set to true.
  795. */
  796. static void ath9k_antenna_check(struct ath_softc *sc,
  797. struct ath_rx_status *rs)
  798. {
  799. struct ath_hw *ah = sc->sc_ah;
  800. struct ath9k_hw_capabilities *pCap = &ah->caps;
  801. struct ath_common *common = ath9k_hw_common(ah);
  802. if (!(ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB))
  803. return;
  804. /*
  805. * Change the default rx antenna if rx diversity
  806. * chooses the other antenna 3 times in a row.
  807. */
  808. if (sc->rx.defant != rs->rs_antenna) {
  809. if (++sc->rx.rxotherant >= 3)
  810. ath_setdefantenna(sc, rs->rs_antenna);
  811. } else {
  812. sc->rx.rxotherant = 0;
  813. }
  814. if (pCap->hw_caps & ATH9K_HW_CAP_BT_ANT_DIV) {
  815. if (common->bt_ant_diversity)
  816. ath_ant_comb_scan(sc, rs);
  817. } else {
  818. ath_ant_comb_scan(sc, rs);
  819. }
  820. }
  821. static void ath9k_apply_ampdu_details(struct ath_softc *sc,
  822. struct ath_rx_status *rs, struct ieee80211_rx_status *rxs)
  823. {
  824. if (rs->rs_isaggr) {
  825. rxs->flag |= RX_FLAG_AMPDU_DETAILS | RX_FLAG_AMPDU_LAST_KNOWN;
  826. rxs->ampdu_reference = sc->rx.ampdu_ref;
  827. if (!rs->rs_moreaggr) {
  828. rxs->flag |= RX_FLAG_AMPDU_IS_LAST;
  829. sc->rx.ampdu_ref++;
  830. }
  831. if (rs->rs_flags & ATH9K_RX_DELIM_CRC_PRE)
  832. rxs->flag |= RX_FLAG_AMPDU_DELIM_CRC_ERROR;
  833. }
  834. }
  835. int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp)
  836. {
  837. struct ath_rxbuf *bf;
  838. struct sk_buff *skb = NULL, *requeue_skb, *hdr_skb;
  839. struct ieee80211_rx_status *rxs;
  840. struct ath_hw *ah = sc->sc_ah;
  841. struct ath_common *common = ath9k_hw_common(ah);
  842. struct ieee80211_hw *hw = sc->hw;
  843. int retval;
  844. struct ath_rx_status rs;
  845. enum ath9k_rx_qtype qtype;
  846. bool edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA);
  847. int dma_type;
  848. u64 tsf = 0;
  849. unsigned long flags;
  850. dma_addr_t new_buf_addr;
  851. unsigned int budget = 512;
  852. struct ieee80211_hdr *hdr;
  853. if (edma)
  854. dma_type = DMA_BIDIRECTIONAL;
  855. else
  856. dma_type = DMA_FROM_DEVICE;
  857. qtype = hp ? ATH9K_RX_QUEUE_HP : ATH9K_RX_QUEUE_LP;
  858. tsf = ath9k_hw_gettsf64(ah);
  859. do {
  860. bool decrypt_error = false;
  861. memset(&rs, 0, sizeof(rs));
  862. if (edma)
  863. bf = ath_edma_get_next_rx_buf(sc, &rs, qtype);
  864. else
  865. bf = ath_get_next_rx_buf(sc, &rs);
  866. if (!bf)
  867. break;
  868. skb = bf->bf_mpdu;
  869. if (!skb)
  870. continue;
  871. /*
  872. * Take frame header from the first fragment and RX status from
  873. * the last one.
  874. */
  875. if (sc->rx.frag)
  876. hdr_skb = sc->rx.frag;
  877. else
  878. hdr_skb = skb;
  879. rxs = IEEE80211_SKB_RXCB(hdr_skb);
  880. memset(rxs, 0, sizeof(struct ieee80211_rx_status));
  881. retval = ath9k_rx_skb_preprocess(sc, hdr_skb, &rs, rxs,
  882. &decrypt_error, tsf);
  883. if (retval)
  884. goto requeue_drop_frag;
  885. /* Ensure we always have an skb to requeue once we are done
  886. * processing the current buffer's skb */
  887. requeue_skb = ath_rxbuf_alloc(common, common->rx_bufsize, GFP_ATOMIC);
  888. /* If there is no memory we ignore the current RX'd frame,
  889. * tell hardware it can give us a new frame using the old
  890. * skb and put it at the tail of the sc->rx.rxbuf list for
  891. * processing. */
  892. if (!requeue_skb) {
  893. RX_STAT_INC(rx_oom_err);
  894. goto requeue_drop_frag;
  895. }
  896. /* We will now give hardware our shiny new allocated skb */
  897. new_buf_addr = dma_map_single(sc->dev, requeue_skb->data,
  898. common->rx_bufsize, dma_type);
  899. if (unlikely(dma_mapping_error(sc->dev, new_buf_addr))) {
  900. dev_kfree_skb_any(requeue_skb);
  901. goto requeue_drop_frag;
  902. }
  903. /* Unmap the frame */
  904. dma_unmap_single(sc->dev, bf->bf_buf_addr,
  905. common->rx_bufsize, dma_type);
  906. bf->bf_mpdu = requeue_skb;
  907. bf->bf_buf_addr = new_buf_addr;
  908. skb_put(skb, rs.rs_datalen + ah->caps.rx_status_len);
  909. if (ah->caps.rx_status_len)
  910. skb_pull(skb, ah->caps.rx_status_len);
  911. if (!rs.rs_more)
  912. ath9k_cmn_rx_skb_postprocess(common, hdr_skb, &rs,
  913. rxs, decrypt_error);
  914. if (rs.rs_more) {
  915. RX_STAT_INC(rx_frags);
  916. /*
  917. * rs_more indicates chained descriptors which can be
  918. * used to link buffers together for a sort of
  919. * scatter-gather operation.
  920. */
  921. if (sc->rx.frag) {
  922. /* too many fragments - cannot handle frame */
  923. dev_kfree_skb_any(sc->rx.frag);
  924. dev_kfree_skb_any(skb);
  925. RX_STAT_INC(rx_too_many_frags_err);
  926. skb = NULL;
  927. }
  928. sc->rx.frag = skb;
  929. goto requeue;
  930. }
  931. if (sc->rx.frag) {
  932. int space = skb->len - skb_tailroom(hdr_skb);
  933. if (pskb_expand_head(hdr_skb, 0, space, GFP_ATOMIC) < 0) {
  934. dev_kfree_skb(skb);
  935. RX_STAT_INC(rx_oom_err);
  936. goto requeue_drop_frag;
  937. }
  938. sc->rx.frag = NULL;
  939. skb_copy_from_linear_data(skb, skb_put(hdr_skb, skb->len),
  940. skb->len);
  941. dev_kfree_skb_any(skb);
  942. skb = hdr_skb;
  943. }
  944. if (rxs->flag & RX_FLAG_MMIC_STRIPPED)
  945. skb_trim(skb, skb->len - 8);
  946. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  947. if ((sc->ps_flags & (PS_WAIT_FOR_BEACON |
  948. PS_WAIT_FOR_CAB |
  949. PS_WAIT_FOR_PSPOLL_DATA)) ||
  950. ath9k_check_auto_sleep(sc))
  951. ath_rx_ps(sc, skb, rs.is_mybeacon);
  952. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  953. ath9k_antenna_check(sc, &rs);
  954. ath9k_apply_ampdu_details(sc, &rs, rxs);
  955. ath_debug_rate_stats(sc, &rs, skb);
  956. hdr = (struct ieee80211_hdr *)skb->data;
  957. if (ieee80211_is_ack(hdr->frame_control))
  958. ath_dynack_sample_ack_ts(sc->sc_ah, skb, rs.rs_tstamp);
  959. ieee80211_rx(hw, skb);
  960. requeue_drop_frag:
  961. if (sc->rx.frag) {
  962. dev_kfree_skb_any(sc->rx.frag);
  963. sc->rx.frag = NULL;
  964. }
  965. requeue:
  966. list_add_tail(&bf->list, &sc->rx.rxbuf);
  967. if (!edma) {
  968. ath_rx_buf_relink(sc, bf, flush);
  969. if (!flush)
  970. ath9k_hw_rxena(ah);
  971. } else if (!flush) {
  972. ath_rx_edma_buf_link(sc, qtype);
  973. }
  974. if (!budget--)
  975. break;
  976. } while (1);
  977. if (!(ah->imask & ATH9K_INT_RXEOL)) {
  978. ah->imask |= (ATH9K_INT_RXEOL | ATH9K_INT_RXORN);
  979. ath9k_hw_set_interrupts(ah);
  980. }
  981. return 0;
  982. }