recv.c 33 KB

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