recv.c 33 KB

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