recv.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318
  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_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. spin_lock_bh(&rxtid->tidlock);
  282. while (rxtid->baw_head != rxtid->baw_tail) {
  283. rxbuf = rxtid->rxbuf + rxtid->baw_head;
  284. if (!rxbuf->rx_wbuf) {
  285. INCR(rxtid->baw_head, ATH_TID_MAX_BUFS);
  286. INCR(rxtid->seq_next, IEEE80211_SEQ_MAX);
  287. continue;
  288. }
  289. if (drop)
  290. dev_kfree_skb(rxbuf->rx_wbuf);
  291. else
  292. ath_rx_subframe(rxtid->an,
  293. rxbuf->rx_wbuf,
  294. &rxbuf->rx_status);
  295. rxbuf->rx_wbuf = NULL;
  296. INCR(rxtid->baw_head, ATH_TID_MAX_BUFS);
  297. INCR(rxtid->seq_next, IEEE80211_SEQ_MAX);
  298. }
  299. spin_unlock_bh(&rxtid->tidlock);
  300. }
  301. static struct sk_buff *ath_rxbuf_alloc(struct ath_softc *sc,
  302. u32 len)
  303. {
  304. struct sk_buff *skb;
  305. u32 off;
  306. /*
  307. * Cache-line-align. This is important (for the
  308. * 5210 at least) as not doing so causes bogus data
  309. * in rx'd frames.
  310. */
  311. skb = dev_alloc_skb(len + sc->sc_cachelsz - 1);
  312. if (skb != NULL) {
  313. off = ((unsigned long) skb->data) % sc->sc_cachelsz;
  314. if (off != 0)
  315. skb_reserve(skb, sc->sc_cachelsz - off);
  316. } else {
  317. DPRINTF(sc, ATH_DBG_FATAL,
  318. "%s: skbuff alloc of size %u failed\n",
  319. __func__, len);
  320. return NULL;
  321. }
  322. return skb;
  323. }
  324. static void ath_rx_requeue(struct ath_softc *sc, struct sk_buff *skb)
  325. {
  326. struct ath_buf *bf = ATH_RX_CONTEXT(skb)->ctx_rxbuf;
  327. ASSERT(bf != NULL);
  328. spin_lock_bh(&sc->sc_rxbuflock);
  329. if (bf->bf_status & ATH_BUFSTATUS_STALE) {
  330. /*
  331. * This buffer is still held for hw acess.
  332. * Mark it as free to be re-queued it later.
  333. */
  334. bf->bf_status |= ATH_BUFSTATUS_FREE;
  335. } else {
  336. /* XXX: we probably never enter here, remove after
  337. * verification */
  338. list_add_tail(&bf->list, &sc->sc_rxbuf);
  339. ath_rx_buf_link(sc, bf);
  340. }
  341. spin_unlock_bh(&sc->sc_rxbuflock);
  342. }
  343. /*
  344. * The skb indicated to upper stack won't be returned to us.
  345. * So we have to allocate a new one and queue it by ourselves.
  346. */
  347. static int ath_rx_indicate(struct ath_softc *sc,
  348. struct sk_buff *skb,
  349. struct ath_recv_status *status,
  350. u16 keyix)
  351. {
  352. struct ath_buf *bf = ATH_RX_CONTEXT(skb)->ctx_rxbuf;
  353. struct sk_buff *nskb;
  354. int type;
  355. /* indicate frame to the stack, which will free the old skb. */
  356. type = ath__rx_indicate(sc, skb, status, keyix);
  357. /* allocate a new skb and queue it to for H/W processing */
  358. nskb = ath_rxbuf_alloc(sc, sc->sc_rxbufsize);
  359. if (nskb != NULL) {
  360. bf->bf_mpdu = nskb;
  361. bf->bf_buf_addr = ath_skb_map_single(sc,
  362. nskb,
  363. PCI_DMA_FROMDEVICE,
  364. /* XXX: Remove get_dma_mem_context() */
  365. get_dma_mem_context(bf, bf_dmacontext));
  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_rxflush = 0;
  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 =
  431. ath_skb_map_single(sc, skb, PCI_DMA_FROMDEVICE,
  432. get_dma_mem_context(bf, bf_dmacontext));
  433. ATH_RX_CONTEXT(skb)->ctx_rxbuf = bf;
  434. }
  435. sc->sc_rxlink = NULL;
  436. } while (0);
  437. if (error)
  438. ath_rx_cleanup(sc);
  439. return error;
  440. }
  441. /* Reclaim all rx queue resources */
  442. void ath_rx_cleanup(struct ath_softc *sc)
  443. {
  444. struct sk_buff *skb;
  445. struct ath_buf *bf;
  446. list_for_each_entry(bf, &sc->sc_rxbuf, list) {
  447. skb = bf->bf_mpdu;
  448. if (skb)
  449. dev_kfree_skb(skb);
  450. }
  451. /* cleanup rx descriptors */
  452. if (sc->sc_rxdma.dd_desc_len != 0)
  453. ath_descdma_cleanup(sc, &sc->sc_rxdma, &sc->sc_rxbuf);
  454. }
  455. /*
  456. * Calculate the receive filter according to the
  457. * operating mode and state:
  458. *
  459. * o always accept unicast, broadcast, and multicast traffic
  460. * o maintain current state of phy error reception (the hal
  461. * may enable phy error frames for noise immunity work)
  462. * o probe request frames are accepted only when operating in
  463. * hostap, adhoc, or monitor modes
  464. * o enable promiscuous mode according to the interface state
  465. * o accept beacons:
  466. * - when operating in adhoc mode so the 802.11 layer creates
  467. * node table entries for peers,
  468. * - when operating in station mode for collecting rssi data when
  469. * the station is otherwise quiet, or
  470. * - when operating as a repeater so we see repeater-sta beacons
  471. * - when scanning
  472. */
  473. u32 ath_calcrxfilter(struct ath_softc *sc)
  474. {
  475. #define RX_FILTER_PRESERVE (ATH9K_RX_FILTER_PHYERR | ATH9K_RX_FILTER_PHYRADAR)
  476. u32 rfilt;
  477. rfilt = (ath9k_hw_getrxfilter(sc->sc_ah) & RX_FILTER_PRESERVE)
  478. | ATH9K_RX_FILTER_UCAST | ATH9K_RX_FILTER_BCAST
  479. | ATH9K_RX_FILTER_MCAST;
  480. /* If not a STA, enable processing of Probe Requests */
  481. if (sc->sc_opmode != ATH9K_M_STA)
  482. rfilt |= ATH9K_RX_FILTER_PROBEREQ;
  483. /* Can't set HOSTAP into promiscous mode */
  484. if (sc->sc_opmode == ATH9K_M_MONITOR) {
  485. rfilt |= ATH9K_RX_FILTER_PROM;
  486. /* ??? To prevent from sending ACK */
  487. rfilt &= ~ATH9K_RX_FILTER_UCAST;
  488. }
  489. if (sc->sc_opmode == ATH9K_M_STA || sc->sc_opmode == ATH9K_M_IBSS ||
  490. sc->sc_scanning)
  491. rfilt |= ATH9K_RX_FILTER_BEACON;
  492. /* If in HOSTAP mode, want to enable reception of PSPOLL frames
  493. & beacon frames */
  494. if (sc->sc_opmode == ATH9K_M_HOSTAP)
  495. rfilt |= (ATH9K_RX_FILTER_BEACON | ATH9K_RX_FILTER_PSPOLL);
  496. return rfilt;
  497. #undef RX_FILTER_PRESERVE
  498. }
  499. /* Enable the receive h/w following a reset. */
  500. int ath_startrecv(struct ath_softc *sc)
  501. {
  502. struct ath_hal *ah = sc->sc_ah;
  503. struct ath_buf *bf, *tbf;
  504. spin_lock_bh(&sc->sc_rxbuflock);
  505. if (list_empty(&sc->sc_rxbuf))
  506. goto start_recv;
  507. sc->sc_rxlink = NULL;
  508. list_for_each_entry_safe(bf, tbf, &sc->sc_rxbuf, list) {
  509. if (bf->bf_status & ATH_BUFSTATUS_STALE) {
  510. /* restarting h/w, no need for holding descriptors */
  511. bf->bf_status &= ~ATH_BUFSTATUS_STALE;
  512. /*
  513. * Upper layer may not be done with the frame yet so
  514. * we can't just re-queue it to hardware. Remove it
  515. * from h/w queue. It'll be re-queued when upper layer
  516. * returns the frame and ath_rx_requeue_mpdu is called.
  517. */
  518. if (!(bf->bf_status & ATH_BUFSTATUS_FREE)) {
  519. list_del(&bf->list);
  520. continue;
  521. }
  522. }
  523. /* chain descriptors */
  524. ath_rx_buf_link(sc, bf);
  525. }
  526. /* We could have deleted elements so the list may be empty now */
  527. if (list_empty(&sc->sc_rxbuf))
  528. goto start_recv;
  529. bf = list_first_entry(&sc->sc_rxbuf, struct ath_buf, list);
  530. ath9k_hw_putrxbuf(ah, bf->bf_daddr);
  531. ath9k_hw_rxena(ah); /* enable recv descriptors */
  532. start_recv:
  533. spin_unlock_bh(&sc->sc_rxbuflock);
  534. ath_opmode_init(sc); /* set filters, etc. */
  535. ath9k_hw_startpcureceive(ah); /* re-enable PCU/DMA engine */
  536. return 0;
  537. }
  538. /* Disable the receive h/w in preparation for a reset. */
  539. bool ath_stoprecv(struct ath_softc *sc)
  540. {
  541. struct ath_hal *ah = sc->sc_ah;
  542. u64 tsf;
  543. bool stopped;
  544. ath9k_hw_stoppcurecv(ah); /* disable PCU */
  545. ath9k_hw_setrxfilter(ah, 0); /* clear recv filter */
  546. stopped = ath9k_hw_stopdmarecv(ah); /* disable DMA engine */
  547. mdelay(3); /* 3ms is long enough for 1 frame */
  548. tsf = ath9k_hw_gettsf64(ah);
  549. sc->sc_rxlink = NULL; /* just in case */
  550. return stopped;
  551. }
  552. /* Flush receive queue */
  553. void ath_flushrecv(struct ath_softc *sc)
  554. {
  555. /*
  556. * ath_rx_tasklet may be used to handle rx interrupt and flush receive
  557. * queue at the same time. Use a lock to serialize the access of rx
  558. * queue.
  559. * ath_rx_tasklet cannot hold the spinlock while indicating packets.
  560. * Instead, do not claim the spinlock but check for a flush in
  561. * progress (see references to sc_rxflush)
  562. */
  563. spin_lock_bh(&sc->sc_rxflushlock);
  564. sc->sc_rxflush = 1;
  565. ath_rx_tasklet(sc, 1);
  566. sc->sc_rxflush = 0;
  567. spin_unlock_bh(&sc->sc_rxflushlock);
  568. }
  569. /* Process an individual frame */
  570. int ath_rx_input(struct ath_softc *sc,
  571. struct ath_node *an,
  572. int is_ampdu,
  573. struct sk_buff *skb,
  574. struct ath_recv_status *rx_status,
  575. enum ATH_RX_TYPE *status)
  576. {
  577. if (is_ampdu && sc->sc_rxaggr) {
  578. *status = ATH_RX_CONSUMED;
  579. return ath_ampdu_input(sc, an, skb, rx_status);
  580. } else {
  581. *status = ATH_RX_NON_CONSUMED;
  582. return -1;
  583. }
  584. }
  585. /* Process receive queue, as well as LED, etc. */
  586. int ath_rx_tasklet(struct ath_softc *sc, int flush)
  587. {
  588. #define PA2DESC(_sc, _pa) \
  589. ((struct ath_desc *)((caddr_t)(_sc)->sc_rxdma.dd_desc + \
  590. ((_pa) - (_sc)->sc_rxdma.dd_desc_paddr)))
  591. struct ath_buf *bf, *bf_held = NULL;
  592. struct ath_desc *ds;
  593. struct ieee80211_hdr *hdr;
  594. struct sk_buff *skb = NULL;
  595. struct ath_recv_status rx_status;
  596. struct ath_hal *ah = sc->sc_ah;
  597. int type, rx_processed = 0;
  598. u32 phyerr;
  599. u8 chainreset = 0;
  600. int retval;
  601. __le16 fc;
  602. do {
  603. /* If handling rx interrupt and flush is in progress => exit */
  604. if (sc->sc_rxflush && (flush == 0))
  605. break;
  606. spin_lock_bh(&sc->sc_rxbuflock);
  607. if (list_empty(&sc->sc_rxbuf)) {
  608. sc->sc_rxlink = NULL;
  609. spin_unlock_bh(&sc->sc_rxbuflock);
  610. break;
  611. }
  612. bf = list_first_entry(&sc->sc_rxbuf, struct ath_buf, list);
  613. /*
  614. * There is a race condition that BH gets scheduled after sw
  615. * writes RxE and before hw re-load the last descriptor to get
  616. * the newly chained one. Software must keep the last DONE
  617. * descriptor as a holding descriptor - software does so by
  618. * marking it with the STALE flag.
  619. */
  620. if (bf->bf_status & ATH_BUFSTATUS_STALE) {
  621. bf_held = bf;
  622. if (list_is_last(&bf_held->list, &sc->sc_rxbuf)) {
  623. /*
  624. * The holding descriptor is the last
  625. * descriptor in queue. It's safe to
  626. * remove the last holding descriptor
  627. * in BH context.
  628. */
  629. list_del(&bf_held->list);
  630. bf_held->bf_status &= ~ATH_BUFSTATUS_STALE;
  631. sc->sc_rxlink = NULL;
  632. if (bf_held->bf_status & ATH_BUFSTATUS_FREE) {
  633. list_add_tail(&bf_held->list,
  634. &sc->sc_rxbuf);
  635. ath_rx_buf_link(sc, bf_held);
  636. }
  637. spin_unlock_bh(&sc->sc_rxbuflock);
  638. break;
  639. }
  640. bf = list_entry(bf->list.next, struct ath_buf, list);
  641. }
  642. ds = bf->bf_desc;
  643. ++rx_processed;
  644. /*
  645. * Must provide the virtual address of the current
  646. * descriptor, the physical address, and the virtual
  647. * address of the next descriptor in the h/w chain.
  648. * This allows the HAL to look ahead to see if the
  649. * hardware is done with a descriptor by checking the
  650. * done bit in the following descriptor and the address
  651. * of the current descriptor the DMA engine is working
  652. * on. All this is necessary because of our use of
  653. * a self-linked list to avoid rx overruns.
  654. */
  655. retval = ath9k_hw_rxprocdesc(ah,
  656. ds,
  657. bf->bf_daddr,
  658. PA2DESC(sc, ds->ds_link),
  659. 0);
  660. if (retval == -EINPROGRESS) {
  661. struct ath_buf *tbf;
  662. struct ath_desc *tds;
  663. if (list_is_last(&bf->list, &sc->sc_rxbuf)) {
  664. spin_unlock_bh(&sc->sc_rxbuflock);
  665. break;
  666. }
  667. tbf = list_entry(bf->list.next, struct ath_buf, list);
  668. /*
  669. * On some hardware the descriptor status words could
  670. * get corrupted, including the done bit. Because of
  671. * this, check if the next descriptor's done bit is
  672. * set or not.
  673. *
  674. * If the next descriptor's done bit is set, the current
  675. * descriptor has been corrupted. Force s/w to discard
  676. * this descriptor and continue...
  677. */
  678. tds = tbf->bf_desc;
  679. retval = ath9k_hw_rxprocdesc(ah,
  680. tds, tbf->bf_daddr,
  681. PA2DESC(sc, tds->ds_link), 0);
  682. if (retval == -EINPROGRESS) {
  683. spin_unlock_bh(&sc->sc_rxbuflock);
  684. break;
  685. }
  686. }
  687. /* XXX: we do not support frames spanning
  688. * multiple descriptors */
  689. bf->bf_status |= ATH_BUFSTATUS_DONE;
  690. skb = bf->bf_mpdu;
  691. if (skb == NULL) { /* XXX ??? can this happen */
  692. spin_unlock_bh(&sc->sc_rxbuflock);
  693. continue;
  694. }
  695. /*
  696. * Now we know it's a completed frame, we can indicate the
  697. * frame. Remove the previous holding descriptor and leave
  698. * this one in the queue as the new holding descriptor.
  699. */
  700. if (bf_held) {
  701. list_del(&bf_held->list);
  702. bf_held->bf_status &= ~ATH_BUFSTATUS_STALE;
  703. if (bf_held->bf_status & ATH_BUFSTATUS_FREE) {
  704. list_add_tail(&bf_held->list, &sc->sc_rxbuf);
  705. /* try to requeue this descriptor */
  706. ath_rx_buf_link(sc, bf_held);
  707. }
  708. }
  709. bf->bf_status |= ATH_BUFSTATUS_STALE;
  710. bf_held = bf;
  711. /*
  712. * Release the lock here in case ieee80211_input() return
  713. * the frame immediately by calling ath_rx_mpdu_requeue().
  714. */
  715. spin_unlock_bh(&sc->sc_rxbuflock);
  716. if (flush) {
  717. /*
  718. * If we're asked to flush receive queue, directly
  719. * chain it back at the queue without processing it.
  720. */
  721. goto rx_next;
  722. }
  723. hdr = (struct ieee80211_hdr *)skb->data;
  724. fc = hdr->frame_control;
  725. memzero(&rx_status, sizeof(struct ath_recv_status));
  726. if (ds->ds_rxstat.rs_more) {
  727. /*
  728. * Frame spans multiple descriptors; this
  729. * cannot happen yet as we don't support
  730. * jumbograms. If not in monitor mode,
  731. * discard the frame.
  732. */
  733. #ifndef ERROR_FRAMES
  734. /*
  735. * Enable this if you want to see
  736. * error frames in Monitor mode.
  737. */
  738. if (sc->sc_opmode != ATH9K_M_MONITOR)
  739. goto rx_next;
  740. #endif
  741. /* fall thru for monitor mode handling... */
  742. } else if (ds->ds_rxstat.rs_status != 0) {
  743. if (ds->ds_rxstat.rs_status & ATH9K_RXERR_CRC)
  744. rx_status.flags |= ATH_RX_FCS_ERROR;
  745. if (ds->ds_rxstat.rs_status & ATH9K_RXERR_PHY) {
  746. phyerr = ds->ds_rxstat.rs_phyerr & 0x1f;
  747. goto rx_next;
  748. }
  749. if (ds->ds_rxstat.rs_status & ATH9K_RXERR_DECRYPT) {
  750. /*
  751. * Decrypt error. We only mark packet status
  752. * here and always push up the frame up to let
  753. * mac80211 handle the actual error case, be
  754. * it no decryption key or real decryption
  755. * error. This let us keep statistics there.
  756. */
  757. rx_status.flags |= ATH_RX_DECRYPT_ERROR;
  758. } else if (ds->ds_rxstat.rs_status & ATH9K_RXERR_MIC) {
  759. /*
  760. * Demic error. We only mark frame status here
  761. * and always push up the frame up to let
  762. * mac80211 handle the actual error case. This
  763. * let us keep statistics there. Hardware may
  764. * post a false-positive MIC error.
  765. */
  766. if (ieee80211_is_ctl(fc))
  767. /*
  768. * Sometimes, we get invalid
  769. * MIC failures on valid control frames.
  770. * Remove these mic errors.
  771. */
  772. ds->ds_rxstat.rs_status &=
  773. ~ATH9K_RXERR_MIC;
  774. else
  775. rx_status.flags |= ATH_RX_MIC_ERROR;
  776. }
  777. /*
  778. * Reject error frames with the exception of
  779. * decryption and MIC failures. For monitor mode,
  780. * we also ignore the CRC error.
  781. */
  782. if (sc->sc_opmode == ATH9K_M_MONITOR) {
  783. if (ds->ds_rxstat.rs_status &
  784. ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC |
  785. ATH9K_RXERR_CRC))
  786. goto rx_next;
  787. } else {
  788. if (ds->ds_rxstat.rs_status &
  789. ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC)) {
  790. goto rx_next;
  791. }
  792. }
  793. }
  794. /*
  795. * The status portion of the descriptor could get corrupted.
  796. */
  797. if (sc->sc_rxbufsize < ds->ds_rxstat.rs_datalen)
  798. goto rx_next;
  799. /*
  800. * Sync and unmap the frame. At this point we're
  801. * committed to passing the sk_buff somewhere so
  802. * clear buf_skb; this means a new sk_buff must be
  803. * allocated when the rx descriptor is setup again
  804. * to receive another frame.
  805. */
  806. skb_put(skb, ds->ds_rxstat.rs_datalen);
  807. skb->protocol = cpu_to_be16(ETH_P_CONTROL);
  808. rx_status.tsf = ath_extend_tsf(sc, ds->ds_rxstat.rs_tstamp);
  809. rx_status.rateieee =
  810. sc->sc_hwmap[ds->ds_rxstat.rs_rate].ieeerate;
  811. rx_status.rateKbps =
  812. sc->sc_hwmap[ds->ds_rxstat.rs_rate].rateKbps;
  813. rx_status.ratecode = ds->ds_rxstat.rs_rate;
  814. /* HT rate */
  815. if (rx_status.ratecode & 0x80) {
  816. /* TODO - add table to avoid division */
  817. if (ds->ds_rxstat.rs_flags & ATH9K_RX_2040) {
  818. rx_status.flags |= ATH_RX_40MHZ;
  819. rx_status.rateKbps =
  820. (rx_status.rateKbps * 27) / 13;
  821. }
  822. if (ds->ds_rxstat.rs_flags & ATH9K_RX_GI)
  823. rx_status.rateKbps =
  824. (rx_status.rateKbps * 10) / 9;
  825. else
  826. rx_status.flags |= ATH_RX_SHORT_GI;
  827. }
  828. /* sc->sc_noise_floor is only available when the station
  829. attaches to an AP, so we use a default value
  830. if we are not yet attached. */
  831. /* XXX we should use either sc->sc_noise_floor or
  832. * ath_hal_getChanNoise(ah, &sc->sc_curchan)
  833. * to calculate the noise floor.
  834. * However, the value returned by ath_hal_getChanNoise
  835. * seems to be incorrect (-31dBm on the last test),
  836. * so we will use a hard-coded value until we
  837. * figure out what is going on.
  838. */
  839. rx_status.abs_rssi =
  840. ds->ds_rxstat.rs_rssi + ATH_DEFAULT_NOISE_FLOOR;
  841. pci_dma_sync_single_for_cpu(sc->pdev,
  842. bf->bf_buf_addr,
  843. skb_tailroom(skb),
  844. PCI_DMA_FROMDEVICE);
  845. pci_unmap_single(sc->pdev,
  846. bf->bf_buf_addr,
  847. sc->sc_rxbufsize,
  848. PCI_DMA_FROMDEVICE);
  849. /* XXX: Ah! make me more readable, use a helper */
  850. if (ah->ah_caps.hw_caps & ATH9K_HW_CAP_HT) {
  851. if (ds->ds_rxstat.rs_moreaggr == 0) {
  852. rx_status.rssictl[0] =
  853. ds->ds_rxstat.rs_rssi_ctl0;
  854. rx_status.rssictl[1] =
  855. ds->ds_rxstat.rs_rssi_ctl1;
  856. rx_status.rssictl[2] =
  857. ds->ds_rxstat.rs_rssi_ctl2;
  858. rx_status.rssi = ds->ds_rxstat.rs_rssi;
  859. if (ds->ds_rxstat.rs_flags & ATH9K_RX_2040) {
  860. rx_status.rssiextn[0] =
  861. ds->ds_rxstat.rs_rssi_ext0;
  862. rx_status.rssiextn[1] =
  863. ds->ds_rxstat.rs_rssi_ext1;
  864. rx_status.rssiextn[2] =
  865. ds->ds_rxstat.rs_rssi_ext2;
  866. rx_status.flags |=
  867. ATH_RX_RSSI_EXTN_VALID;
  868. }
  869. rx_status.flags |= ATH_RX_RSSI_VALID |
  870. ATH_RX_CHAIN_RSSI_VALID;
  871. }
  872. } else {
  873. /*
  874. * Need to insert the "combined" rssi into the
  875. * status structure for upper layer processing
  876. */
  877. rx_status.rssi = ds->ds_rxstat.rs_rssi;
  878. rx_status.flags |= ATH_RX_RSSI_VALID;
  879. }
  880. /* Pass frames up to the stack. */
  881. type = ath_rx_indicate(sc, skb,
  882. &rx_status, ds->ds_rxstat.rs_keyix);
  883. /*
  884. * change the default rx antenna if rx diversity chooses the
  885. * other antenna 3 times in a row.
  886. */
  887. if (sc->sc_defant != ds->ds_rxstat.rs_antenna) {
  888. if (++sc->sc_rxotherant >= 3)
  889. ath_setdefantenna(sc,
  890. ds->ds_rxstat.rs_antenna);
  891. } else {
  892. sc->sc_rxotherant = 0;
  893. }
  894. #ifdef CONFIG_SLOW_ANT_DIV
  895. if ((rx_status.flags & ATH_RX_RSSI_VALID) &&
  896. ieee80211_is_beacon(fc)) {
  897. ath_slow_ant_div(&sc->sc_antdiv, hdr, &ds->ds_rxstat);
  898. }
  899. #endif
  900. /*
  901. * For frames successfully indicated, the buffer will be
  902. * returned to us by upper layers by calling
  903. * ath_rx_mpdu_requeue, either synchronusly or asynchronously.
  904. * So we don't want to do it here in this loop.
  905. */
  906. continue;
  907. rx_next:
  908. bf->bf_status |= ATH_BUFSTATUS_FREE;
  909. } while (TRUE);
  910. if (chainreset) {
  911. DPRINTF(sc, ATH_DBG_CONFIG,
  912. "%s: Reset rx chain mask. "
  913. "Do internal reset\n", __func__);
  914. ASSERT(flush == 0);
  915. ath_internal_reset(sc);
  916. }
  917. return 0;
  918. #undef PA2DESC
  919. }
  920. /* Process ADDBA request in per-TID data structure */
  921. int ath_rx_aggr_start(struct ath_softc *sc,
  922. const u8 *addr,
  923. u16 tid,
  924. u16 *ssn)
  925. {
  926. struct ath_arx_tid *rxtid;
  927. struct ath_node *an;
  928. struct ieee80211_hw *hw = sc->hw;
  929. struct ieee80211_supported_band *sband;
  930. u16 buffersize = 0;
  931. spin_lock_bh(&sc->node_lock);
  932. an = ath_node_find(sc, (u8 *) addr);
  933. spin_unlock_bh(&sc->node_lock);
  934. if (!an) {
  935. DPRINTF(sc, ATH_DBG_AGGR,
  936. "%s: Node not found to initialize RX aggregation\n",
  937. __func__);
  938. return -1;
  939. }
  940. sband = hw->wiphy->bands[hw->conf.channel->band];
  941. buffersize = IEEE80211_MIN_AMPDU_BUF <<
  942. sband->ht_info.ampdu_factor; /* FIXME */
  943. rxtid = &an->an_aggr.rx.tid[tid];
  944. spin_lock_bh(&rxtid->tidlock);
  945. if (sc->sc_rxaggr) {
  946. /* Allow aggregation reception
  947. * Adjust rx BA window size. Peer might indicate a
  948. * zero buffer size for a _dont_care_ condition.
  949. */
  950. if (buffersize)
  951. rxtid->baw_size = min(buffersize, rxtid->baw_size);
  952. /* set rx sequence number */
  953. rxtid->seq_next = *ssn;
  954. /* Allocate the receive buffers for this TID */
  955. DPRINTF(sc, ATH_DBG_AGGR,
  956. "%s: Allcating rxbuffer for TID %d\n", __func__, tid);
  957. if (rxtid->rxbuf == NULL) {
  958. /*
  959. * If the rxbuff is not NULL at this point, we *probably*
  960. * already allocated the buffer on a previous ADDBA,
  961. * and this is a subsequent ADDBA that got through.
  962. * Don't allocate, but use the value in the pointer,
  963. * we zero it out when we de-allocate.
  964. */
  965. rxtid->rxbuf = kmalloc(ATH_TID_MAX_BUFS *
  966. sizeof(struct ath_rxbuf), GFP_ATOMIC);
  967. }
  968. if (rxtid->rxbuf == NULL) {
  969. DPRINTF(sc, ATH_DBG_AGGR,
  970. "%s: Unable to allocate RX buffer, "
  971. "refusing ADDBA\n", __func__);
  972. } else {
  973. /* Ensure the memory is zeroed out (all internal
  974. * pointers are null) */
  975. memzero(rxtid->rxbuf, ATH_TID_MAX_BUFS *
  976. sizeof(struct ath_rxbuf));
  977. DPRINTF(sc, ATH_DBG_AGGR,
  978. "%s: Allocated @%p\n", __func__, rxtid->rxbuf);
  979. /* Allow aggregation reception */
  980. rxtid->addba_exchangecomplete = 1;
  981. }
  982. }
  983. spin_unlock_bh(&rxtid->tidlock);
  984. return 0;
  985. }
  986. /* Process DELBA */
  987. int ath_rx_aggr_stop(struct ath_softc *sc,
  988. const u8 *addr,
  989. u16 tid)
  990. {
  991. struct ath_node *an;
  992. spin_lock_bh(&sc->node_lock);
  993. an = ath_node_find(sc, (u8 *) addr);
  994. spin_unlock_bh(&sc->node_lock);
  995. if (!an) {
  996. DPRINTF(sc, ATH_DBG_AGGR,
  997. "%s: RX aggr stop for non-existent node\n", __func__);
  998. return -1;
  999. }
  1000. ath_rx_aggr_teardown(sc, an, tid);
  1001. return 0;
  1002. }
  1003. /* Rx aggregation tear down */
  1004. void ath_rx_aggr_teardown(struct ath_softc *sc,
  1005. struct ath_node *an, u8 tid)
  1006. {
  1007. struct ath_arx_tid *rxtid = &an->an_aggr.rx.tid[tid];
  1008. if (!rxtid->addba_exchangecomplete)
  1009. return;
  1010. del_timer_sync(&rxtid->timer);
  1011. ath_rx_flush_tid(sc, rxtid, 0);
  1012. rxtid->addba_exchangecomplete = 0;
  1013. /* De-allocate the receive buffer array allocated when addba started */
  1014. if (rxtid->rxbuf) {
  1015. DPRINTF(sc, ATH_DBG_AGGR,
  1016. "%s: Deallocating TID %d rxbuff @%p\n",
  1017. __func__, tid, rxtid->rxbuf);
  1018. kfree(rxtid->rxbuf);
  1019. /* Set pointer to null to avoid reuse*/
  1020. rxtid->rxbuf = NULL;
  1021. }
  1022. }
  1023. /* Initialize per-node receive state */
  1024. void ath_rx_node_init(struct ath_softc *sc, struct ath_node *an)
  1025. {
  1026. if (sc->sc_rxaggr) {
  1027. struct ath_arx_tid *rxtid;
  1028. int tidno;
  1029. /* Init per tid rx state */
  1030. for (tidno = 0, rxtid = &an->an_aggr.rx.tid[tidno];
  1031. tidno < WME_NUM_TID;
  1032. tidno++, rxtid++) {
  1033. rxtid->an = an;
  1034. rxtid->seq_reset = 1;
  1035. rxtid->seq_next = 0;
  1036. rxtid->baw_size = WME_MAX_BA;
  1037. rxtid->baw_head = rxtid->baw_tail = 0;
  1038. /*
  1039. * Ensure the buffer pointer is null at this point
  1040. * (needs to be allocated when addba is received)
  1041. */
  1042. rxtid->rxbuf = NULL;
  1043. setup_timer(&rxtid->timer, ath_rx_timer,
  1044. (unsigned long)rxtid);
  1045. spin_lock_init(&rxtid->tidlock);
  1046. /* ADDBA state */
  1047. rxtid->addba_exchangecomplete = 0;
  1048. }
  1049. }
  1050. }
  1051. void ath_rx_node_cleanup(struct ath_softc *sc, struct ath_node *an)
  1052. {
  1053. if (sc->sc_rxaggr) {
  1054. struct ath_arx_tid *rxtid;
  1055. int tidno, i;
  1056. /* Init per tid rx state */
  1057. for (tidno = 0, rxtid = &an->an_aggr.rx.tid[tidno];
  1058. tidno < WME_NUM_TID;
  1059. tidno++, rxtid++) {
  1060. if (!rxtid->addba_exchangecomplete)
  1061. continue;
  1062. /* must cancel timer first */
  1063. del_timer_sync(&rxtid->timer);
  1064. /* drop any pending sub-frames */
  1065. ath_rx_flush_tid(sc, rxtid, 1);
  1066. for (i = 0; i < ATH_TID_MAX_BUFS; i++)
  1067. ASSERT(rxtid->rxbuf[i].rx_wbuf == NULL);
  1068. rxtid->addba_exchangecomplete = 0;
  1069. }
  1070. }
  1071. }
  1072. /* Cleanup per-node receive state */
  1073. void ath_rx_node_free(struct ath_softc *sc, struct ath_node *an)
  1074. {
  1075. ath_rx_node_cleanup(sc, an);
  1076. }
  1077. dma_addr_t ath_skb_map_single(struct ath_softc *sc,
  1078. struct sk_buff *skb,
  1079. int direction,
  1080. dma_addr_t *pa)
  1081. {
  1082. /*
  1083. * NB: do NOT use skb->len, which is 0 on initialization.
  1084. * Use skb's entire data area instead.
  1085. */
  1086. *pa = pci_map_single(sc->pdev, skb->data,
  1087. skb_end_pointer(skb) - skb->head, direction);
  1088. return *pa;
  1089. }
  1090. void ath_skb_unmap_single(struct ath_softc *sc,
  1091. struct sk_buff *skb,
  1092. int direction,
  1093. dma_addr_t *pa)
  1094. {
  1095. /* Unmap skb's entire data area */
  1096. pci_unmap_single(sc->pdev, *pa,
  1097. skb_end_pointer(skb) - skb->head, direction);
  1098. }