recv.c 34 KB

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