recv.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300
  1. /*
  2. * Copyright (c) 2008 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. /*
  17. * Implementation of receive path.
  18. */
  19. #include "core.h"
  20. /*
  21. * Setup and link descriptors.
  22. *
  23. * 11N: we can no longer afford to self link the last descriptor.
  24. * MAC acknowledges BA status as long as it copies frames to host
  25. * buffer (or rx fifo). This can incorrectly acknowledge packets
  26. * to a sender if last desc is self-linked.
  27. *
  28. * NOTE: Caller should hold the rxbuf lock.
  29. */
  30. static void ath_rx_buf_link(struct ath_softc *sc, struct ath_buf *bf)
  31. {
  32. struct ath_hal *ah = sc->sc_ah;
  33. struct ath_desc *ds;
  34. struct sk_buff *skb;
  35. ATH_RXBUF_RESET(bf);
  36. ds = bf->bf_desc;
  37. ds->ds_link = 0; /* link to null */
  38. ds->ds_data = bf->bf_buf_addr;
  39. /* XXX For RADAR?
  40. * virtual addr of the beginning of the buffer. */
  41. skb = bf->bf_mpdu;
  42. ASSERT(skb != NULL);
  43. ds->ds_vdata = skb->data;
  44. /* setup rx descriptors. The sc_rxbufsize here tells the harware
  45. * how much data it can DMA to us and that we are prepared
  46. * to process */
  47. ath9k_hw_setuprxdesc(ah,
  48. ds,
  49. sc->sc_rxbufsize,
  50. 0);
  51. if (sc->sc_rxlink == NULL)
  52. ath9k_hw_putrxbuf(ah, bf->bf_daddr);
  53. else
  54. *sc->sc_rxlink = bf->bf_daddr;
  55. sc->sc_rxlink = &ds->ds_link;
  56. ath9k_hw_rxena(ah);
  57. }
  58. /* Process received BAR frame */
  59. static int ath_bar_rx(struct ath_softc *sc,
  60. struct ath_node *an,
  61. struct sk_buff *skb)
  62. {
  63. struct ieee80211_bar *bar;
  64. struct ath_arx_tid *rxtid;
  65. struct sk_buff *tskb;
  66. struct ath_recv_status *rx_status;
  67. int tidno, index, cindex;
  68. u16 seqno;
  69. /* look at BAR contents */
  70. bar = (struct ieee80211_bar *)skb->data;
  71. tidno = (le16_to_cpu(bar->control) & IEEE80211_BAR_CTL_TID_M)
  72. >> IEEE80211_BAR_CTL_TID_S;
  73. seqno = le16_to_cpu(bar->start_seq_num) >> IEEE80211_SEQ_SEQ_SHIFT;
  74. /* process BAR - indicate all pending RX frames till the BAR seqno */
  75. rxtid = &an->an_aggr.rx.tid[tidno];
  76. spin_lock_bh(&rxtid->tidlock);
  77. /* get relative index */
  78. index = ATH_BA_INDEX(rxtid->seq_next, seqno);
  79. /* drop BAR if old sequence (index is too large) */
  80. if ((index > rxtid->baw_size) &&
  81. (index > (IEEE80211_SEQ_MAX - (rxtid->baw_size << 2))))
  82. /* discard frame, ieee layer may not treat frame as a dup */
  83. goto unlock_and_free;
  84. /* complete receive processing for all pending frames upto BAR seqno */
  85. cindex = (rxtid->baw_head + index) & (ATH_TID_MAX_BUFS - 1);
  86. while ((rxtid->baw_head != rxtid->baw_tail) &&
  87. (rxtid->baw_head != cindex)) {
  88. tskb = rxtid->rxbuf[rxtid->baw_head].rx_wbuf;
  89. rx_status = &rxtid->rxbuf[rxtid->baw_head].rx_status;
  90. rxtid->rxbuf[rxtid->baw_head].rx_wbuf = NULL;
  91. if (tskb != NULL)
  92. ath_rx_subframe(an, tskb, rx_status);
  93. INCR(rxtid->baw_head, ATH_TID_MAX_BUFS);
  94. INCR(rxtid->seq_next, IEEE80211_SEQ_MAX);
  95. }
  96. /* ... and indicate rest of the frames in-order */
  97. while (rxtid->baw_head != rxtid->baw_tail &&
  98. rxtid->rxbuf[rxtid->baw_head].rx_wbuf != NULL) {
  99. tskb = rxtid->rxbuf[rxtid->baw_head].rx_wbuf;
  100. rx_status = &rxtid->rxbuf[rxtid->baw_head].rx_status;
  101. rxtid->rxbuf[rxtid->baw_head].rx_wbuf = NULL;
  102. ath_rx_subframe(an, tskb, rx_status);
  103. INCR(rxtid->baw_head, ATH_TID_MAX_BUFS);
  104. INCR(rxtid->seq_next, IEEE80211_SEQ_MAX);
  105. }
  106. unlock_and_free:
  107. spin_unlock_bh(&rxtid->tidlock);
  108. /* free bar itself */
  109. dev_kfree_skb(skb);
  110. return IEEE80211_FTYPE_CTL;
  111. }
  112. /* Function to handle a subframe of aggregation when HT is enabled */
  113. static int ath_ampdu_input(struct ath_softc *sc,
  114. struct ath_node *an,
  115. struct sk_buff *skb,
  116. struct ath_recv_status *rx_status)
  117. {
  118. struct ieee80211_hdr *hdr;
  119. struct ath_arx_tid *rxtid;
  120. struct ath_rxbuf *rxbuf;
  121. u8 type, subtype;
  122. u16 rxseq;
  123. int tid = 0, index, cindex, rxdiff;
  124. __le16 fc;
  125. u8 *qc;
  126. hdr = (struct ieee80211_hdr *)skb->data;
  127. fc = hdr->frame_control;
  128. /* collect stats of frames with non-zero version */
  129. if ((le16_to_cpu(hdr->frame_control) & IEEE80211_FCTL_VERS) != 0) {
  130. dev_kfree_skb(skb);
  131. return -1;
  132. }
  133. type = le16_to_cpu(hdr->frame_control) & IEEE80211_FCTL_FTYPE;
  134. subtype = le16_to_cpu(hdr->frame_control) & IEEE80211_FCTL_STYPE;
  135. if (ieee80211_is_back_req(fc))
  136. return ath_bar_rx(sc, an, skb);
  137. /* special aggregate processing only for qos unicast data frames */
  138. if (!ieee80211_is_data(fc) ||
  139. !ieee80211_is_data_qos(fc) ||
  140. is_multicast_ether_addr(hdr->addr1))
  141. return ath_rx_subframe(an, skb, rx_status);
  142. /* lookup rx tid state */
  143. if (ieee80211_is_data_qos(fc)) {
  144. qc = ieee80211_get_qos_ctl(hdr);
  145. tid = qc[0] & 0xf;
  146. }
  147. if (sc->sc_ah->ah_opmode == ATH9K_M_STA) {
  148. /* Drop the frame not belonging to me. */
  149. if (memcmp(hdr->addr1, sc->sc_myaddr, ETH_ALEN)) {
  150. dev_kfree_skb(skb);
  151. return -1;
  152. }
  153. }
  154. rxtid = &an->an_aggr.rx.tid[tid];
  155. spin_lock(&rxtid->tidlock);
  156. rxdiff = (rxtid->baw_tail - rxtid->baw_head) &
  157. (ATH_TID_MAX_BUFS - 1);
  158. /*
  159. * If the ADDBA exchange has not been completed by the source,
  160. * process via legacy path (i.e. no reordering buffer is needed)
  161. */
  162. if (!rxtid->addba_exchangecomplete) {
  163. spin_unlock(&rxtid->tidlock);
  164. return ath_rx_subframe(an, skb, rx_status);
  165. }
  166. /* extract sequence number from recvd frame */
  167. rxseq = le16_to_cpu(hdr->seq_ctrl) >> IEEE80211_SEQ_SEQ_SHIFT;
  168. if (rxtid->seq_reset) {
  169. rxtid->seq_reset = 0;
  170. rxtid->seq_next = rxseq;
  171. }
  172. index = ATH_BA_INDEX(rxtid->seq_next, rxseq);
  173. /* drop frame if old sequence (index is too large) */
  174. if (index > (IEEE80211_SEQ_MAX - (rxtid->baw_size << 2))) {
  175. /* discard frame, ieee layer may not treat frame as a dup */
  176. spin_unlock(&rxtid->tidlock);
  177. dev_kfree_skb(skb);
  178. return IEEE80211_FTYPE_DATA;
  179. }
  180. /* sequence number is beyond block-ack window */
  181. if (index >= rxtid->baw_size) {
  182. /* complete receive processing for all pending frames */
  183. while (index >= rxtid->baw_size) {
  184. rxbuf = rxtid->rxbuf + rxtid->baw_head;
  185. if (rxbuf->rx_wbuf != NULL) {
  186. ath_rx_subframe(an, rxbuf->rx_wbuf,
  187. &rxbuf->rx_status);
  188. rxbuf->rx_wbuf = NULL;
  189. }
  190. INCR(rxtid->baw_head, ATH_TID_MAX_BUFS);
  191. INCR(rxtid->seq_next, IEEE80211_SEQ_MAX);
  192. index--;
  193. }
  194. }
  195. /* add buffer to the recv ba window */
  196. cindex = (rxtid->baw_head + index) & (ATH_TID_MAX_BUFS - 1);
  197. rxbuf = rxtid->rxbuf + cindex;
  198. if (rxbuf->rx_wbuf != NULL) {
  199. spin_unlock(&rxtid->tidlock);
  200. /* duplicate frame */
  201. dev_kfree_skb(skb);
  202. return IEEE80211_FTYPE_DATA;
  203. }
  204. rxbuf->rx_wbuf = skb;
  205. rxbuf->rx_time = get_timestamp();
  206. rxbuf->rx_status = *rx_status;
  207. /* advance tail if sequence received is newer
  208. * than any received so far */
  209. if (index >= rxdiff) {
  210. rxtid->baw_tail = cindex;
  211. INCR(rxtid->baw_tail, ATH_TID_MAX_BUFS);
  212. }
  213. /* indicate all in-order received frames */
  214. while (rxtid->baw_head != rxtid->baw_tail) {
  215. rxbuf = rxtid->rxbuf + rxtid->baw_head;
  216. if (!rxbuf->rx_wbuf)
  217. break;
  218. ath_rx_subframe(an, rxbuf->rx_wbuf, &rxbuf->rx_status);
  219. rxbuf->rx_wbuf = NULL;
  220. INCR(rxtid->baw_head, ATH_TID_MAX_BUFS);
  221. INCR(rxtid->seq_next, IEEE80211_SEQ_MAX);
  222. }
  223. /*
  224. * start a timer to flush all received frames if there are pending
  225. * receive frames
  226. */
  227. if (rxtid->baw_head != rxtid->baw_tail)
  228. mod_timer(&rxtid->timer, ATH_RX_TIMEOUT);
  229. else
  230. del_timer_sync(&rxtid->timer);
  231. spin_unlock(&rxtid->tidlock);
  232. return IEEE80211_FTYPE_DATA;
  233. }
  234. /* Timer to flush all received sub-frames */
  235. static void ath_rx_timer(unsigned long data)
  236. {
  237. struct ath_arx_tid *rxtid = (struct ath_arx_tid *)data;
  238. struct ath_node *an = rxtid->an;
  239. struct ath_rxbuf *rxbuf;
  240. int nosched;
  241. spin_lock_bh(&rxtid->tidlock);
  242. while (rxtid->baw_head != rxtid->baw_tail) {
  243. rxbuf = rxtid->rxbuf + rxtid->baw_head;
  244. if (!rxbuf->rx_wbuf) {
  245. INCR(rxtid->baw_head, ATH_TID_MAX_BUFS);
  246. INCR(rxtid->seq_next, IEEE80211_SEQ_MAX);
  247. continue;
  248. }
  249. /*
  250. * Stop if the next one is a very recent frame.
  251. *
  252. * Call get_timestamp in every iteration to protect against the
  253. * case in which a new frame is received while we are executing
  254. * this function. Using a timestamp obtained before entering
  255. * the loop could lead to a very large time interval
  256. * (a negative value typecast to unsigned), breaking the
  257. * function's logic.
  258. */
  259. if ((get_timestamp() - rxbuf->rx_time) <
  260. (ATH_RX_TIMEOUT * HZ / 1000))
  261. break;
  262. ath_rx_subframe(an, rxbuf->rx_wbuf,
  263. &rxbuf->rx_status);
  264. rxbuf->rx_wbuf = NULL;
  265. INCR(rxtid->baw_head, ATH_TID_MAX_BUFS);
  266. INCR(rxtid->seq_next, IEEE80211_SEQ_MAX);
  267. }
  268. /*
  269. * start a timer to flush all received frames if there are pending
  270. * receive frames
  271. */
  272. if (rxtid->baw_head != rxtid->baw_tail)
  273. nosched = 0;
  274. else
  275. nosched = 1; /* no need to re-arm the timer again */
  276. spin_unlock_bh(&rxtid->tidlock);
  277. }
  278. /* Free all pending sub-frames in the re-ordering buffer */
  279. static void ath_rx_flush_tid(struct ath_softc *sc,
  280. struct ath_arx_tid *rxtid, int drop)
  281. {
  282. struct ath_rxbuf *rxbuf;
  283. unsigned long flag;
  284. spin_lock_irqsave(&rxtid->tidlock, flag);
  285. while (rxtid->baw_head != rxtid->baw_tail) {
  286. rxbuf = rxtid->rxbuf + rxtid->baw_head;
  287. if (!rxbuf->rx_wbuf) {
  288. INCR(rxtid->baw_head, ATH_TID_MAX_BUFS);
  289. INCR(rxtid->seq_next, IEEE80211_SEQ_MAX);
  290. continue;
  291. }
  292. if (drop)
  293. dev_kfree_skb(rxbuf->rx_wbuf);
  294. else
  295. ath_rx_subframe(rxtid->an,
  296. rxbuf->rx_wbuf,
  297. &rxbuf->rx_status);
  298. rxbuf->rx_wbuf = NULL;
  299. INCR(rxtid->baw_head, ATH_TID_MAX_BUFS);
  300. INCR(rxtid->seq_next, IEEE80211_SEQ_MAX);
  301. }
  302. spin_unlock_irqrestore(&rxtid->tidlock, flag);
  303. }
  304. static struct sk_buff *ath_rxbuf_alloc(struct ath_softc *sc,
  305. u32 len)
  306. {
  307. struct sk_buff *skb;
  308. u32 off;
  309. /*
  310. * Cache-line-align. This is important (for the
  311. * 5210 at least) as not doing so causes bogus data
  312. * in rx'd frames.
  313. */
  314. /* Note: the kernel can allocate a value greater than
  315. * what we ask it to give us. We really only need 4 KB as that
  316. * is this hardware supports and in fact we need at least 3849
  317. * as that is the MAX AMSDU size this hardware supports.
  318. * Unfortunately this means we may get 8 KB here from the
  319. * kernel... and that is actually what is observed on some
  320. * systems :( */
  321. skb = dev_alloc_skb(len + sc->sc_cachelsz - 1);
  322. if (skb != NULL) {
  323. off = ((unsigned long) skb->data) % sc->sc_cachelsz;
  324. if (off != 0)
  325. skb_reserve(skb, sc->sc_cachelsz - off);
  326. } else {
  327. DPRINTF(sc, ATH_DBG_FATAL,
  328. "%s: skbuff alloc of size %u failed\n",
  329. __func__, len);
  330. return NULL;
  331. }
  332. return skb;
  333. }
  334. static void ath_rx_requeue(struct ath_softc *sc, struct sk_buff *skb)
  335. {
  336. struct ath_buf *bf = ATH_RX_CONTEXT(skb)->ctx_rxbuf;
  337. ASSERT(bf != NULL);
  338. spin_lock_bh(&sc->sc_rxbuflock);
  339. if (bf->bf_status & ATH_BUFSTATUS_STALE) {
  340. /*
  341. * This buffer is still held for hw acess.
  342. * Mark it as free to be re-queued it later.
  343. */
  344. bf->bf_status |= ATH_BUFSTATUS_FREE;
  345. } else {
  346. /* XXX: we probably never enter here, remove after
  347. * verification */
  348. list_add_tail(&bf->list, &sc->sc_rxbuf);
  349. ath_rx_buf_link(sc, bf);
  350. }
  351. spin_unlock_bh(&sc->sc_rxbuflock);
  352. }
  353. /*
  354. * The skb indicated to upper stack won't be returned to us.
  355. * So we have to allocate a new one and queue it by ourselves.
  356. */
  357. static int ath_rx_indicate(struct ath_softc *sc,
  358. struct sk_buff *skb,
  359. struct ath_recv_status *status,
  360. u16 keyix)
  361. {
  362. struct ath_buf *bf = ATH_RX_CONTEXT(skb)->ctx_rxbuf;
  363. struct sk_buff *nskb;
  364. int type;
  365. /* indicate frame to the stack, which will free the old skb. */
  366. type = _ath_rx_indicate(sc, skb, status, keyix);
  367. /* allocate a new skb and queue it to for H/W processing */
  368. nskb = ath_rxbuf_alloc(sc, sc->sc_rxbufsize);
  369. if (nskb != NULL) {
  370. bf->bf_mpdu = nskb;
  371. bf->bf_buf_addr = pci_map_single(sc->pdev, nskb->data,
  372. sc->sc_rxbufsize,
  373. PCI_DMA_FROMDEVICE);
  374. bf->bf_dmacontext = bf->bf_buf_addr;
  375. ATH_RX_CONTEXT(nskb)->ctx_rxbuf = bf;
  376. /* queue the new wbuf to H/W */
  377. ath_rx_requeue(sc, nskb);
  378. }
  379. return type;
  380. }
  381. static void ath_opmode_init(struct ath_softc *sc)
  382. {
  383. struct ath_hal *ah = sc->sc_ah;
  384. u32 rfilt, mfilt[2];
  385. /* configure rx filter */
  386. rfilt = ath_calcrxfilter(sc);
  387. ath9k_hw_setrxfilter(ah, rfilt);
  388. /* configure bssid mask */
  389. if (ah->ah_caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK)
  390. ath9k_hw_setbssidmask(ah, sc->sc_bssidmask);
  391. /* configure operational mode */
  392. ath9k_hw_setopmode(ah);
  393. /* Handle any link-level address change. */
  394. ath9k_hw_setmac(ah, sc->sc_myaddr);
  395. /* calculate and install multicast filter */
  396. mfilt[0] = mfilt[1] = ~0;
  397. ath9k_hw_setmcastfilter(ah, mfilt[0], mfilt[1]);
  398. DPRINTF(sc, ATH_DBG_CONFIG ,
  399. "%s: RX filter 0x%x, MC filter %08x:%08x\n",
  400. __func__, rfilt, mfilt[0], mfilt[1]);
  401. }
  402. int ath_rx_init(struct ath_softc *sc, int nbufs)
  403. {
  404. struct sk_buff *skb;
  405. struct ath_buf *bf;
  406. int error = 0;
  407. do {
  408. spin_lock_init(&sc->sc_rxflushlock);
  409. sc->sc_flags &= ~SC_OP_RXFLUSH;
  410. spin_lock_init(&sc->sc_rxbuflock);
  411. /*
  412. * Cisco's VPN software requires that drivers be able to
  413. * receive encapsulated frames that are larger than the MTU.
  414. * Since we can't be sure how large a frame we'll get, setup
  415. * to handle the larges on possible.
  416. */
  417. sc->sc_rxbufsize = roundup(IEEE80211_MAX_MPDU_LEN,
  418. min(sc->sc_cachelsz,
  419. (u16)64));
  420. DPRINTF(sc, ATH_DBG_CONFIG, "%s: cachelsz %u rxbufsize %u\n",
  421. __func__, sc->sc_cachelsz, sc->sc_rxbufsize);
  422. /* Initialize rx descriptors */
  423. error = ath_descdma_setup(sc, &sc->sc_rxdma, &sc->sc_rxbuf,
  424. "rx", nbufs, 1);
  425. if (error != 0) {
  426. DPRINTF(sc, ATH_DBG_FATAL,
  427. "%s: failed to allocate rx descriptors: %d\n",
  428. __func__, error);
  429. break;
  430. }
  431. /* Pre-allocate a wbuf for each rx buffer */
  432. list_for_each_entry(bf, &sc->sc_rxbuf, list) {
  433. skb = ath_rxbuf_alloc(sc, sc->sc_rxbufsize);
  434. if (skb == NULL) {
  435. error = -ENOMEM;
  436. break;
  437. }
  438. bf->bf_mpdu = skb;
  439. bf->bf_buf_addr = pci_map_single(sc->pdev, skb->data,
  440. sc->sc_rxbufsize,
  441. PCI_DMA_FROMDEVICE);
  442. bf->bf_dmacontext = bf->bf_buf_addr;
  443. ATH_RX_CONTEXT(skb)->ctx_rxbuf = bf;
  444. }
  445. sc->sc_rxlink = NULL;
  446. } while (0);
  447. if (error)
  448. ath_rx_cleanup(sc);
  449. return error;
  450. }
  451. /* Reclaim all rx queue resources */
  452. void ath_rx_cleanup(struct ath_softc *sc)
  453. {
  454. struct sk_buff *skb;
  455. struct ath_buf *bf;
  456. list_for_each_entry(bf, &sc->sc_rxbuf, list) {
  457. skb = bf->bf_mpdu;
  458. if (skb)
  459. dev_kfree_skb(skb);
  460. }
  461. /* cleanup rx descriptors */
  462. if (sc->sc_rxdma.dd_desc_len != 0)
  463. ath_descdma_cleanup(sc, &sc->sc_rxdma, &sc->sc_rxbuf);
  464. }
  465. /*
  466. * Calculate the receive filter according to the
  467. * operating mode and state:
  468. *
  469. * o always accept unicast, broadcast, and multicast traffic
  470. * o maintain current state of phy error reception (the hal
  471. * may enable phy error frames for noise immunity work)
  472. * o probe request frames are accepted only when operating in
  473. * hostap, adhoc, or monitor modes
  474. * o enable promiscuous mode according to the interface state
  475. * o accept beacons:
  476. * - when operating in adhoc mode so the 802.11 layer creates
  477. * node table entries for peers,
  478. * - when operating in station mode for collecting rssi data when
  479. * the station is otherwise quiet, or
  480. * - when operating as a repeater so we see repeater-sta beacons
  481. * - when scanning
  482. */
  483. u32 ath_calcrxfilter(struct ath_softc *sc)
  484. {
  485. #define RX_FILTER_PRESERVE (ATH9K_RX_FILTER_PHYERR | ATH9K_RX_FILTER_PHYRADAR)
  486. u32 rfilt;
  487. rfilt = (ath9k_hw_getrxfilter(sc->sc_ah) & RX_FILTER_PRESERVE)
  488. | ATH9K_RX_FILTER_UCAST | ATH9K_RX_FILTER_BCAST
  489. | ATH9K_RX_FILTER_MCAST;
  490. /* If not a STA, enable processing of Probe Requests */
  491. if (sc->sc_ah->ah_opmode != ATH9K_M_STA)
  492. rfilt |= ATH9K_RX_FILTER_PROBEREQ;
  493. /* Can't set HOSTAP into promiscous mode */
  494. if (((sc->sc_ah->ah_opmode != ATH9K_M_HOSTAP) &&
  495. (sc->rx_filter & FIF_PROMISC_IN_BSS)) ||
  496. (sc->sc_ah->ah_opmode == ATH9K_M_MONITOR)) {
  497. rfilt |= ATH9K_RX_FILTER_PROM;
  498. /* ??? To prevent from sending ACK */
  499. rfilt &= ~ATH9K_RX_FILTER_UCAST;
  500. }
  501. if (((sc->sc_ah->ah_opmode == ATH9K_M_STA) &&
  502. (sc->rx_filter & FIF_BCN_PRBRESP_PROMISC)) ||
  503. (sc->sc_ah->ah_opmode == ATH9K_M_IBSS))
  504. rfilt |= ATH9K_RX_FILTER_BEACON;
  505. /* If in HOSTAP mode, want to enable reception of PSPOLL frames
  506. & beacon frames */
  507. if (sc->sc_ah->ah_opmode == ATH9K_M_HOSTAP)
  508. rfilt |= (ATH9K_RX_FILTER_BEACON | ATH9K_RX_FILTER_PSPOLL);
  509. return rfilt;
  510. #undef RX_FILTER_PRESERVE
  511. }
  512. /* Enable the receive h/w following a reset. */
  513. int ath_startrecv(struct ath_softc *sc)
  514. {
  515. struct ath_hal *ah = sc->sc_ah;
  516. struct ath_buf *bf, *tbf;
  517. spin_lock_bh(&sc->sc_rxbuflock);
  518. if (list_empty(&sc->sc_rxbuf))
  519. goto start_recv;
  520. sc->sc_rxlink = NULL;
  521. list_for_each_entry_safe(bf, tbf, &sc->sc_rxbuf, list) {
  522. if (bf->bf_status & ATH_BUFSTATUS_STALE) {
  523. /* restarting h/w, no need for holding descriptors */
  524. bf->bf_status &= ~ATH_BUFSTATUS_STALE;
  525. /*
  526. * Upper layer may not be done with the frame yet so
  527. * we can't just re-queue it to hardware. Remove it
  528. * from h/w queue. It'll be re-queued when upper layer
  529. * returns the frame and ath_rx_requeue_mpdu is called.
  530. */
  531. if (!(bf->bf_status & ATH_BUFSTATUS_FREE)) {
  532. list_del(&bf->list);
  533. continue;
  534. }
  535. }
  536. /* chain descriptors */
  537. ath_rx_buf_link(sc, bf);
  538. }
  539. /* We could have deleted elements so the list may be empty now */
  540. if (list_empty(&sc->sc_rxbuf))
  541. goto start_recv;
  542. bf = list_first_entry(&sc->sc_rxbuf, struct ath_buf, list);
  543. ath9k_hw_putrxbuf(ah, bf->bf_daddr);
  544. ath9k_hw_rxena(ah); /* enable recv descriptors */
  545. start_recv:
  546. spin_unlock_bh(&sc->sc_rxbuflock);
  547. ath_opmode_init(sc); /* set filters, etc. */
  548. ath9k_hw_startpcureceive(ah); /* re-enable PCU/DMA engine */
  549. return 0;
  550. }
  551. /* Disable the receive h/w in preparation for a reset. */
  552. bool ath_stoprecv(struct ath_softc *sc)
  553. {
  554. struct ath_hal *ah = sc->sc_ah;
  555. u64 tsf;
  556. bool stopped;
  557. ath9k_hw_stoppcurecv(ah); /* disable PCU */
  558. ath9k_hw_setrxfilter(ah, 0); /* clear recv filter */
  559. stopped = ath9k_hw_stopdmarecv(ah); /* disable DMA engine */
  560. mdelay(3); /* 3ms is long enough for 1 frame */
  561. tsf = ath9k_hw_gettsf64(ah);
  562. sc->sc_rxlink = NULL; /* just in case */
  563. return stopped;
  564. }
  565. /* Flush receive queue */
  566. void ath_flushrecv(struct ath_softc *sc)
  567. {
  568. /*
  569. * ath_rx_tasklet may be used to handle rx interrupt and flush receive
  570. * queue at the same time. Use a lock to serialize the access of rx
  571. * queue.
  572. * ath_rx_tasklet cannot hold the spinlock while indicating packets.
  573. * Instead, do not claim the spinlock but check for a flush in
  574. * progress (see references to sc_rxflush)
  575. */
  576. spin_lock_bh(&sc->sc_rxflushlock);
  577. sc->sc_flags |= SC_OP_RXFLUSH;
  578. ath_rx_tasklet(sc, 1);
  579. sc->sc_flags &= ~SC_OP_RXFLUSH;
  580. spin_unlock_bh(&sc->sc_rxflushlock);
  581. }
  582. /* Process an individual frame */
  583. int ath_rx_input(struct ath_softc *sc,
  584. struct ath_node *an,
  585. int is_ampdu,
  586. struct sk_buff *skb,
  587. struct ath_recv_status *rx_status,
  588. enum ATH_RX_TYPE *status)
  589. {
  590. if (is_ampdu && (sc->sc_flags & SC_OP_RXAGGR)) {
  591. *status = ATH_RX_CONSUMED;
  592. return ath_ampdu_input(sc, an, skb, rx_status);
  593. } else {
  594. *status = ATH_RX_NON_CONSUMED;
  595. return -1;
  596. }
  597. }
  598. /* Process receive queue, as well as LED, etc. */
  599. int ath_rx_tasklet(struct ath_softc *sc, int flush)
  600. {
  601. #define PA2DESC(_sc, _pa) \
  602. ((struct ath_desc *)((caddr_t)(_sc)->sc_rxdma.dd_desc + \
  603. ((_pa) - (_sc)->sc_rxdma.dd_desc_paddr)))
  604. struct ath_buf *bf, *bf_held = NULL;
  605. struct ath_desc *ds;
  606. struct ieee80211_hdr *hdr;
  607. struct sk_buff *skb = NULL;
  608. struct ath_recv_status rx_status;
  609. struct ath_hal *ah = sc->sc_ah;
  610. int type, rx_processed = 0;
  611. u32 phyerr;
  612. u8 chainreset = 0;
  613. int retval;
  614. __le16 fc;
  615. do {
  616. /* If handling rx interrupt and flush is in progress => exit */
  617. if ((sc->sc_flags & SC_OP_RXFLUSH) && (flush == 0))
  618. break;
  619. spin_lock_bh(&sc->sc_rxbuflock);
  620. if (list_empty(&sc->sc_rxbuf)) {
  621. sc->sc_rxlink = NULL;
  622. spin_unlock_bh(&sc->sc_rxbuflock);
  623. break;
  624. }
  625. bf = list_first_entry(&sc->sc_rxbuf, struct ath_buf, list);
  626. /*
  627. * There is a race condition that BH gets scheduled after sw
  628. * writes RxE and before hw re-load the last descriptor to get
  629. * the newly chained one. Software must keep the last DONE
  630. * descriptor as a holding descriptor - software does so by
  631. * marking it with the STALE flag.
  632. */
  633. if (bf->bf_status & ATH_BUFSTATUS_STALE) {
  634. bf_held = bf;
  635. if (list_is_last(&bf_held->list, &sc->sc_rxbuf)) {
  636. /*
  637. * The holding descriptor is the last
  638. * descriptor in queue. It's safe to
  639. * remove the last holding descriptor
  640. * in BH context.
  641. */
  642. list_del(&bf_held->list);
  643. bf_held->bf_status &= ~ATH_BUFSTATUS_STALE;
  644. sc->sc_rxlink = NULL;
  645. if (bf_held->bf_status & ATH_BUFSTATUS_FREE) {
  646. list_add_tail(&bf_held->list,
  647. &sc->sc_rxbuf);
  648. ath_rx_buf_link(sc, bf_held);
  649. }
  650. spin_unlock_bh(&sc->sc_rxbuflock);
  651. break;
  652. }
  653. bf = list_entry(bf->list.next, struct ath_buf, list);
  654. }
  655. ds = bf->bf_desc;
  656. ++rx_processed;
  657. /*
  658. * Must provide the virtual address of the current
  659. * descriptor, the physical address, and the virtual
  660. * address of the next descriptor in the h/w chain.
  661. * This allows the HAL to look ahead to see if the
  662. * hardware is done with a descriptor by checking the
  663. * done bit in the following descriptor and the address
  664. * of the current descriptor the DMA engine is working
  665. * on. All this is necessary because of our use of
  666. * a self-linked list to avoid rx overruns.
  667. */
  668. retval = ath9k_hw_rxprocdesc(ah,
  669. ds,
  670. bf->bf_daddr,
  671. PA2DESC(sc, ds->ds_link),
  672. 0);
  673. if (retval == -EINPROGRESS) {
  674. struct ath_buf *tbf;
  675. struct ath_desc *tds;
  676. if (list_is_last(&bf->list, &sc->sc_rxbuf)) {
  677. spin_unlock_bh(&sc->sc_rxbuflock);
  678. break;
  679. }
  680. tbf = list_entry(bf->list.next, struct ath_buf, list);
  681. /*
  682. * On some hardware the descriptor status words could
  683. * get corrupted, including the done bit. Because of
  684. * this, check if the next descriptor's done bit is
  685. * set or not.
  686. *
  687. * If the next descriptor's done bit is set, the current
  688. * descriptor has been corrupted. Force s/w to discard
  689. * this descriptor and continue...
  690. */
  691. tds = tbf->bf_desc;
  692. retval = ath9k_hw_rxprocdesc(ah,
  693. tds, tbf->bf_daddr,
  694. PA2DESC(sc, tds->ds_link), 0);
  695. if (retval == -EINPROGRESS) {
  696. spin_unlock_bh(&sc->sc_rxbuflock);
  697. break;
  698. }
  699. }
  700. /* XXX: we do not support frames spanning
  701. * multiple descriptors */
  702. bf->bf_status |= ATH_BUFSTATUS_DONE;
  703. skb = bf->bf_mpdu;
  704. if (skb == NULL) { /* XXX ??? can this happen */
  705. spin_unlock_bh(&sc->sc_rxbuflock);
  706. continue;
  707. }
  708. /*
  709. * Now we know it's a completed frame, we can indicate the
  710. * frame. Remove the previous holding descriptor and leave
  711. * this one in the queue as the new holding descriptor.
  712. */
  713. if (bf_held) {
  714. list_del(&bf_held->list);
  715. bf_held->bf_status &= ~ATH_BUFSTATUS_STALE;
  716. if (bf_held->bf_status & ATH_BUFSTATUS_FREE) {
  717. list_add_tail(&bf_held->list, &sc->sc_rxbuf);
  718. /* try to requeue this descriptor */
  719. ath_rx_buf_link(sc, bf_held);
  720. }
  721. }
  722. bf->bf_status |= ATH_BUFSTATUS_STALE;
  723. bf_held = bf;
  724. /*
  725. * Release the lock here in case ieee80211_input() return
  726. * the frame immediately by calling ath_rx_mpdu_requeue().
  727. */
  728. spin_unlock_bh(&sc->sc_rxbuflock);
  729. if (flush) {
  730. /*
  731. * If we're asked to flush receive queue, directly
  732. * chain it back at the queue without processing it.
  733. */
  734. goto rx_next;
  735. }
  736. hdr = (struct ieee80211_hdr *)skb->data;
  737. fc = hdr->frame_control;
  738. memset(&rx_status, 0, sizeof(struct ath_recv_status));
  739. if (ds->ds_rxstat.rs_more) {
  740. /*
  741. * Frame spans multiple descriptors; this
  742. * cannot happen yet as we don't support
  743. * jumbograms. If not in monitor mode,
  744. * discard the frame.
  745. */
  746. #ifndef ERROR_FRAMES
  747. /*
  748. * Enable this if you want to see
  749. * error frames in Monitor mode.
  750. */
  751. if (sc->sc_ah->ah_opmode != ATH9K_M_MONITOR)
  752. goto rx_next;
  753. #endif
  754. /* fall thru for monitor mode handling... */
  755. } else if (ds->ds_rxstat.rs_status != 0) {
  756. if (ds->ds_rxstat.rs_status & ATH9K_RXERR_CRC)
  757. rx_status.flags |= ATH_RX_FCS_ERROR;
  758. if (ds->ds_rxstat.rs_status & ATH9K_RXERR_PHY) {
  759. phyerr = ds->ds_rxstat.rs_phyerr & 0x1f;
  760. goto rx_next;
  761. }
  762. if (ds->ds_rxstat.rs_status & ATH9K_RXERR_DECRYPT) {
  763. /*
  764. * Decrypt error. We only mark packet status
  765. * here and always push up the frame up to let
  766. * mac80211 handle the actual error case, be
  767. * it no decryption key or real decryption
  768. * error. This let us keep statistics there.
  769. */
  770. rx_status.flags |= ATH_RX_DECRYPT_ERROR;
  771. } else if (ds->ds_rxstat.rs_status & ATH9K_RXERR_MIC) {
  772. /*
  773. * Demic error. We only mark frame status here
  774. * and always push up the frame up to let
  775. * mac80211 handle the actual error case. This
  776. * let us keep statistics there. Hardware may
  777. * post a false-positive MIC error.
  778. */
  779. if (ieee80211_is_ctl(fc))
  780. /*
  781. * Sometimes, we get invalid
  782. * MIC failures on valid control frames.
  783. * Remove these mic errors.
  784. */
  785. ds->ds_rxstat.rs_status &=
  786. ~ATH9K_RXERR_MIC;
  787. else
  788. rx_status.flags |= ATH_RX_MIC_ERROR;
  789. }
  790. /*
  791. * Reject error frames with the exception of
  792. * decryption and MIC failures. For monitor mode,
  793. * we also ignore the CRC error.
  794. */
  795. if (sc->sc_ah->ah_opmode == ATH9K_M_MONITOR) {
  796. if (ds->ds_rxstat.rs_status &
  797. ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC |
  798. ATH9K_RXERR_CRC))
  799. goto rx_next;
  800. } else {
  801. if (ds->ds_rxstat.rs_status &
  802. ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC)) {
  803. goto rx_next;
  804. }
  805. }
  806. }
  807. /*
  808. * The status portion of the descriptor could get corrupted.
  809. */
  810. if (sc->sc_rxbufsize < ds->ds_rxstat.rs_datalen)
  811. goto rx_next;
  812. /*
  813. * Sync and unmap the frame. At this point we're
  814. * committed to passing the sk_buff somewhere so
  815. * clear buf_skb; this means a new sk_buff must be
  816. * allocated when the rx descriptor is setup again
  817. * to receive another frame.
  818. */
  819. skb_put(skb, ds->ds_rxstat.rs_datalen);
  820. skb->protocol = cpu_to_be16(ETH_P_CONTROL);
  821. rx_status.tsf = ath_extend_tsf(sc, ds->ds_rxstat.rs_tstamp);
  822. rx_status.rateieee =
  823. sc->sc_hwmap[ds->ds_rxstat.rs_rate].ieeerate;
  824. rx_status.rateKbps =
  825. sc->sc_hwmap[ds->ds_rxstat.rs_rate].rateKbps;
  826. rx_status.ratecode = ds->ds_rxstat.rs_rate;
  827. /* HT rate */
  828. if (rx_status.ratecode & 0x80) {
  829. /* TODO - add table to avoid division */
  830. if (ds->ds_rxstat.rs_flags & ATH9K_RX_2040) {
  831. rx_status.flags |= ATH_RX_40MHZ;
  832. rx_status.rateKbps =
  833. (rx_status.rateKbps * 27) / 13;
  834. }
  835. if (ds->ds_rxstat.rs_flags & ATH9K_RX_GI)
  836. rx_status.rateKbps =
  837. (rx_status.rateKbps * 10) / 9;
  838. else
  839. rx_status.flags |= ATH_RX_SHORT_GI;
  840. }
  841. /* sc_noise_floor is only available when the station
  842. attaches to an AP, so we use a default value
  843. if we are not yet attached. */
  844. rx_status.abs_rssi =
  845. ds->ds_rxstat.rs_rssi + sc->sc_ani.sc_noise_floor;
  846. pci_dma_sync_single_for_cpu(sc->pdev,
  847. bf->bf_buf_addr,
  848. sc->sc_rxbufsize,
  849. PCI_DMA_FROMDEVICE);
  850. pci_unmap_single(sc->pdev,
  851. bf->bf_buf_addr,
  852. sc->sc_rxbufsize,
  853. PCI_DMA_FROMDEVICE);
  854. /* XXX: Ah! make me more readable, use a helper */
  855. if (ah->ah_caps.hw_caps & ATH9K_HW_CAP_HT) {
  856. if (ds->ds_rxstat.rs_moreaggr == 0) {
  857. rx_status.rssictl[0] =
  858. ds->ds_rxstat.rs_rssi_ctl0;
  859. rx_status.rssictl[1] =
  860. ds->ds_rxstat.rs_rssi_ctl1;
  861. rx_status.rssictl[2] =
  862. ds->ds_rxstat.rs_rssi_ctl2;
  863. rx_status.rssi = ds->ds_rxstat.rs_rssi;
  864. if (ds->ds_rxstat.rs_flags & ATH9K_RX_2040) {
  865. rx_status.rssiextn[0] =
  866. ds->ds_rxstat.rs_rssi_ext0;
  867. rx_status.rssiextn[1] =
  868. ds->ds_rxstat.rs_rssi_ext1;
  869. rx_status.rssiextn[2] =
  870. ds->ds_rxstat.rs_rssi_ext2;
  871. rx_status.flags |=
  872. ATH_RX_RSSI_EXTN_VALID;
  873. }
  874. rx_status.flags |= ATH_RX_RSSI_VALID |
  875. ATH_RX_CHAIN_RSSI_VALID;
  876. }
  877. } else {
  878. /*
  879. * Need to insert the "combined" rssi into the
  880. * status structure for upper layer processing
  881. */
  882. rx_status.rssi = ds->ds_rxstat.rs_rssi;
  883. rx_status.flags |= ATH_RX_RSSI_VALID;
  884. }
  885. /* Pass frames up to the stack. */
  886. type = ath_rx_indicate(sc, skb,
  887. &rx_status, ds->ds_rxstat.rs_keyix);
  888. /*
  889. * change the default rx antenna if rx diversity chooses the
  890. * other antenna 3 times in a row.
  891. */
  892. if (sc->sc_defant != ds->ds_rxstat.rs_antenna) {
  893. if (++sc->sc_rxotherant >= 3)
  894. ath_setdefantenna(sc,
  895. ds->ds_rxstat.rs_antenna);
  896. } else {
  897. sc->sc_rxotherant = 0;
  898. }
  899. #ifdef CONFIG_SLOW_ANT_DIV
  900. if ((rx_status.flags & ATH_RX_RSSI_VALID) &&
  901. ieee80211_is_beacon(fc)) {
  902. ath_slow_ant_div(&sc->sc_antdiv, hdr, &ds->ds_rxstat);
  903. }
  904. #endif
  905. /*
  906. * For frames successfully indicated, the buffer will be
  907. * returned to us by upper layers by calling
  908. * ath_rx_mpdu_requeue, either synchronusly or asynchronously.
  909. * So we don't want to do it here in this loop.
  910. */
  911. continue;
  912. rx_next:
  913. bf->bf_status |= ATH_BUFSTATUS_FREE;
  914. } while (TRUE);
  915. if (chainreset) {
  916. DPRINTF(sc, ATH_DBG_CONFIG,
  917. "%s: Reset rx chain mask. "
  918. "Do internal reset\n", __func__);
  919. ASSERT(flush == 0);
  920. ath_reset(sc, false);
  921. }
  922. return 0;
  923. #undef PA2DESC
  924. }
  925. /* Process ADDBA request in per-TID data structure */
  926. int ath_rx_aggr_start(struct ath_softc *sc,
  927. const u8 *addr,
  928. u16 tid,
  929. u16 *ssn)
  930. {
  931. struct ath_arx_tid *rxtid;
  932. struct ath_node *an;
  933. struct ieee80211_hw *hw = sc->hw;
  934. struct ieee80211_supported_band *sband;
  935. u16 buffersize = 0;
  936. spin_lock_bh(&sc->node_lock);
  937. an = ath_node_find(sc, (u8 *) addr);
  938. spin_unlock_bh(&sc->node_lock);
  939. if (!an) {
  940. DPRINTF(sc, ATH_DBG_AGGR,
  941. "%s: Node not found to initialize RX aggregation\n",
  942. __func__);
  943. return -1;
  944. }
  945. sband = hw->wiphy->bands[hw->conf.channel->band];
  946. buffersize = IEEE80211_MIN_AMPDU_BUF <<
  947. sband->ht_info.ampdu_factor; /* FIXME */
  948. rxtid = &an->an_aggr.rx.tid[tid];
  949. spin_lock_bh(&rxtid->tidlock);
  950. if (sc->sc_flags & SC_OP_RXAGGR) {
  951. /* Allow aggregation reception
  952. * Adjust rx BA window size. Peer might indicate a
  953. * zero buffer size for a _dont_care_ condition.
  954. */
  955. if (buffersize)
  956. rxtid->baw_size = min(buffersize, rxtid->baw_size);
  957. /* set rx sequence number */
  958. rxtid->seq_next = *ssn;
  959. /* Allocate the receive buffers for this TID */
  960. DPRINTF(sc, ATH_DBG_AGGR,
  961. "%s: Allcating rxbuffer for TID %d\n", __func__, tid);
  962. if (rxtid->rxbuf == NULL) {
  963. /*
  964. * If the rxbuff is not NULL at this point, we *probably*
  965. * already allocated the buffer on a previous ADDBA,
  966. * and this is a subsequent ADDBA that got through.
  967. * Don't allocate, but use the value in the pointer,
  968. * we zero it out when we de-allocate.
  969. */
  970. rxtid->rxbuf = kmalloc(ATH_TID_MAX_BUFS *
  971. sizeof(struct ath_rxbuf), GFP_ATOMIC);
  972. }
  973. if (rxtid->rxbuf == NULL) {
  974. DPRINTF(sc, ATH_DBG_AGGR,
  975. "%s: Unable to allocate RX buffer, "
  976. "refusing ADDBA\n", __func__);
  977. } else {
  978. /* Ensure the memory is zeroed out (all internal
  979. * pointers are null) */
  980. memset(rxtid->rxbuf, 0, ATH_TID_MAX_BUFS *
  981. sizeof(struct ath_rxbuf));
  982. DPRINTF(sc, ATH_DBG_AGGR,
  983. "%s: Allocated @%p\n", __func__, rxtid->rxbuf);
  984. /* Allow aggregation reception */
  985. rxtid->addba_exchangecomplete = 1;
  986. }
  987. }
  988. spin_unlock_bh(&rxtid->tidlock);
  989. return 0;
  990. }
  991. /* Process DELBA */
  992. int ath_rx_aggr_stop(struct ath_softc *sc,
  993. const u8 *addr,
  994. u16 tid)
  995. {
  996. struct ath_node *an;
  997. spin_lock_bh(&sc->node_lock);
  998. an = ath_node_find(sc, (u8 *) addr);
  999. spin_unlock_bh(&sc->node_lock);
  1000. if (!an) {
  1001. DPRINTF(sc, ATH_DBG_AGGR,
  1002. "%s: RX aggr stop for non-existent node\n", __func__);
  1003. return -1;
  1004. }
  1005. ath_rx_aggr_teardown(sc, an, tid);
  1006. return 0;
  1007. }
  1008. /* Rx aggregation tear down */
  1009. void ath_rx_aggr_teardown(struct ath_softc *sc,
  1010. struct ath_node *an, u8 tid)
  1011. {
  1012. struct ath_arx_tid *rxtid = &an->an_aggr.rx.tid[tid];
  1013. if (!rxtid->addba_exchangecomplete)
  1014. return;
  1015. del_timer_sync(&rxtid->timer);
  1016. ath_rx_flush_tid(sc, rxtid, 0);
  1017. rxtid->addba_exchangecomplete = 0;
  1018. /* De-allocate the receive buffer array allocated when addba started */
  1019. if (rxtid->rxbuf) {
  1020. DPRINTF(sc, ATH_DBG_AGGR,
  1021. "%s: Deallocating TID %d rxbuff @%p\n",
  1022. __func__, tid, rxtid->rxbuf);
  1023. kfree(rxtid->rxbuf);
  1024. /* Set pointer to null to avoid reuse*/
  1025. rxtid->rxbuf = NULL;
  1026. }
  1027. }
  1028. /* Initialize per-node receive state */
  1029. void ath_rx_node_init(struct ath_softc *sc, struct ath_node *an)
  1030. {
  1031. if (sc->sc_flags & SC_OP_RXAGGR) {
  1032. struct ath_arx_tid *rxtid;
  1033. int tidno;
  1034. /* Init per tid rx state */
  1035. for (tidno = 0, rxtid = &an->an_aggr.rx.tid[tidno];
  1036. tidno < WME_NUM_TID;
  1037. tidno++, rxtid++) {
  1038. rxtid->an = an;
  1039. rxtid->seq_reset = 1;
  1040. rxtid->seq_next = 0;
  1041. rxtid->baw_size = WME_MAX_BA;
  1042. rxtid->baw_head = rxtid->baw_tail = 0;
  1043. /*
  1044. * Ensure the buffer pointer is null at this point
  1045. * (needs to be allocated when addba is received)
  1046. */
  1047. rxtid->rxbuf = NULL;
  1048. setup_timer(&rxtid->timer, ath_rx_timer,
  1049. (unsigned long)rxtid);
  1050. spin_lock_init(&rxtid->tidlock);
  1051. /* ADDBA state */
  1052. rxtid->addba_exchangecomplete = 0;
  1053. }
  1054. }
  1055. }
  1056. void ath_rx_node_cleanup(struct ath_softc *sc, struct ath_node *an)
  1057. {
  1058. if (sc->sc_flags & SC_OP_RXAGGR) {
  1059. struct ath_arx_tid *rxtid;
  1060. int tidno, i;
  1061. /* Init per tid rx state */
  1062. for (tidno = 0, rxtid = &an->an_aggr.rx.tid[tidno];
  1063. tidno < WME_NUM_TID;
  1064. tidno++, rxtid++) {
  1065. if (!rxtid->addba_exchangecomplete)
  1066. continue;
  1067. /* must cancel timer first */
  1068. del_timer_sync(&rxtid->timer);
  1069. /* drop any pending sub-frames */
  1070. ath_rx_flush_tid(sc, rxtid, 1);
  1071. for (i = 0; i < ATH_TID_MAX_BUFS; i++)
  1072. ASSERT(rxtid->rxbuf[i].rx_wbuf == NULL);
  1073. rxtid->addba_exchangecomplete = 0;
  1074. }
  1075. }
  1076. }
  1077. /* Cleanup per-node receive state */
  1078. void ath_rx_node_free(struct ath_softc *sc, struct ath_node *an)
  1079. {
  1080. ath_rx_node_cleanup(sc, an);
  1081. }