htt_rx.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181
  1. /*
  2. * Copyright (c) 2005-2011 Atheros Communications Inc.
  3. * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #include "core.h"
  18. #include "htc.h"
  19. #include "htt.h"
  20. #include "txrx.h"
  21. #include "debug.h"
  22. #include "trace.h"
  23. #include <linux/log2.h>
  24. /* slightly larger than one large A-MPDU */
  25. #define HTT_RX_RING_SIZE_MIN 128
  26. /* roughly 20 ms @ 1 Gbps of 1500B MSDUs */
  27. #define HTT_RX_RING_SIZE_MAX 2048
  28. #define HTT_RX_AVG_FRM_BYTES 1000
  29. /* ms, very conservative */
  30. #define HTT_RX_HOST_LATENCY_MAX_MS 20
  31. /* ms, conservative */
  32. #define HTT_RX_HOST_LATENCY_WORST_LIKELY_MS 10
  33. /* when under memory pressure rx ring refill may fail and needs a retry */
  34. #define HTT_RX_RING_REFILL_RETRY_MS 50
  35. static int ath10k_htt_rx_get_csum_state(struct sk_buff *skb);
  36. static int ath10k_htt_rx_ring_size(struct ath10k_htt *htt)
  37. {
  38. int size;
  39. /*
  40. * It is expected that the host CPU will typically be able to
  41. * service the rx indication from one A-MPDU before the rx
  42. * indication from the subsequent A-MPDU happens, roughly 1-2 ms
  43. * later. However, the rx ring should be sized very conservatively,
  44. * to accomodate the worst reasonable delay before the host CPU
  45. * services a rx indication interrupt.
  46. *
  47. * The rx ring need not be kept full of empty buffers. In theory,
  48. * the htt host SW can dynamically track the low-water mark in the
  49. * rx ring, and dynamically adjust the level to which the rx ring
  50. * is filled with empty buffers, to dynamically meet the desired
  51. * low-water mark.
  52. *
  53. * In contrast, it's difficult to resize the rx ring itself, once
  54. * it's in use. Thus, the ring itself should be sized very
  55. * conservatively, while the degree to which the ring is filled
  56. * with empty buffers should be sized moderately conservatively.
  57. */
  58. /* 1e6 bps/mbps / 1e3 ms per sec = 1000 */
  59. size =
  60. htt->max_throughput_mbps +
  61. 1000 /
  62. (8 * HTT_RX_AVG_FRM_BYTES) * HTT_RX_HOST_LATENCY_MAX_MS;
  63. if (size < HTT_RX_RING_SIZE_MIN)
  64. size = HTT_RX_RING_SIZE_MIN;
  65. if (size > HTT_RX_RING_SIZE_MAX)
  66. size = HTT_RX_RING_SIZE_MAX;
  67. size = roundup_pow_of_two(size);
  68. return size;
  69. }
  70. static int ath10k_htt_rx_ring_fill_level(struct ath10k_htt *htt)
  71. {
  72. int size;
  73. /* 1e6 bps/mbps / 1e3 ms per sec = 1000 */
  74. size =
  75. htt->max_throughput_mbps *
  76. 1000 /
  77. (8 * HTT_RX_AVG_FRM_BYTES) * HTT_RX_HOST_LATENCY_WORST_LIKELY_MS;
  78. /*
  79. * Make sure the fill level is at least 1 less than the ring size.
  80. * Leaving 1 element empty allows the SW to easily distinguish
  81. * between a full ring vs. an empty ring.
  82. */
  83. if (size >= htt->rx_ring.size)
  84. size = htt->rx_ring.size - 1;
  85. return size;
  86. }
  87. static void ath10k_htt_rx_ring_free(struct ath10k_htt *htt)
  88. {
  89. struct sk_buff *skb;
  90. struct ath10k_skb_cb *cb;
  91. int i;
  92. for (i = 0; i < htt->rx_ring.fill_cnt; i++) {
  93. skb = htt->rx_ring.netbufs_ring[i];
  94. cb = ATH10K_SKB_CB(skb);
  95. dma_unmap_single(htt->ar->dev, cb->paddr,
  96. skb->len + skb_tailroom(skb),
  97. DMA_FROM_DEVICE);
  98. dev_kfree_skb_any(skb);
  99. }
  100. htt->rx_ring.fill_cnt = 0;
  101. }
  102. static int __ath10k_htt_rx_ring_fill_n(struct ath10k_htt *htt, int num)
  103. {
  104. struct htt_rx_desc *rx_desc;
  105. struct sk_buff *skb;
  106. dma_addr_t paddr;
  107. int ret = 0, idx;
  108. idx = __le32_to_cpu(*(htt->rx_ring.alloc_idx.vaddr));
  109. while (num > 0) {
  110. skb = dev_alloc_skb(HTT_RX_BUF_SIZE + HTT_RX_DESC_ALIGN);
  111. if (!skb) {
  112. ret = -ENOMEM;
  113. goto fail;
  114. }
  115. if (!IS_ALIGNED((unsigned long)skb->data, HTT_RX_DESC_ALIGN))
  116. skb_pull(skb,
  117. PTR_ALIGN(skb->data, HTT_RX_DESC_ALIGN) -
  118. skb->data);
  119. /* Clear rx_desc attention word before posting to Rx ring */
  120. rx_desc = (struct htt_rx_desc *)skb->data;
  121. rx_desc->attention.flags = __cpu_to_le32(0);
  122. paddr = dma_map_single(htt->ar->dev, skb->data,
  123. skb->len + skb_tailroom(skb),
  124. DMA_FROM_DEVICE);
  125. if (unlikely(dma_mapping_error(htt->ar->dev, paddr))) {
  126. dev_kfree_skb_any(skb);
  127. ret = -ENOMEM;
  128. goto fail;
  129. }
  130. ATH10K_SKB_CB(skb)->paddr = paddr;
  131. htt->rx_ring.netbufs_ring[idx] = skb;
  132. htt->rx_ring.paddrs_ring[idx] = __cpu_to_le32(paddr);
  133. htt->rx_ring.fill_cnt++;
  134. num--;
  135. idx++;
  136. idx &= htt->rx_ring.size_mask;
  137. }
  138. fail:
  139. *(htt->rx_ring.alloc_idx.vaddr) = __cpu_to_le32(idx);
  140. return ret;
  141. }
  142. static int ath10k_htt_rx_ring_fill_n(struct ath10k_htt *htt, int num)
  143. {
  144. lockdep_assert_held(&htt->rx_ring.lock);
  145. return __ath10k_htt_rx_ring_fill_n(htt, num);
  146. }
  147. static void ath10k_htt_rx_msdu_buff_replenish(struct ath10k_htt *htt)
  148. {
  149. int ret, num_to_fill;
  150. spin_lock_bh(&htt->rx_ring.lock);
  151. num_to_fill = htt->rx_ring.fill_level - htt->rx_ring.fill_cnt;
  152. ret = ath10k_htt_rx_ring_fill_n(htt, num_to_fill);
  153. if (ret == -ENOMEM) {
  154. /*
  155. * Failed to fill it to the desired level -
  156. * we'll start a timer and try again next time.
  157. * As long as enough buffers are left in the ring for
  158. * another A-MPDU rx, no special recovery is needed.
  159. */
  160. mod_timer(&htt->rx_ring.refill_retry_timer, jiffies +
  161. msecs_to_jiffies(HTT_RX_RING_REFILL_RETRY_MS));
  162. }
  163. spin_unlock_bh(&htt->rx_ring.lock);
  164. }
  165. static void ath10k_htt_rx_ring_refill_retry(unsigned long arg)
  166. {
  167. struct ath10k_htt *htt = (struct ath10k_htt *)arg;
  168. ath10k_htt_rx_msdu_buff_replenish(htt);
  169. }
  170. static unsigned ath10k_htt_rx_ring_elems(struct ath10k_htt *htt)
  171. {
  172. return (__le32_to_cpu(*htt->rx_ring.alloc_idx.vaddr) -
  173. htt->rx_ring.sw_rd_idx.msdu_payld) & htt->rx_ring.size_mask;
  174. }
  175. void ath10k_htt_rx_detach(struct ath10k_htt *htt)
  176. {
  177. int sw_rd_idx = htt->rx_ring.sw_rd_idx.msdu_payld;
  178. del_timer_sync(&htt->rx_ring.refill_retry_timer);
  179. while (sw_rd_idx != __le32_to_cpu(*(htt->rx_ring.alloc_idx.vaddr))) {
  180. struct sk_buff *skb =
  181. htt->rx_ring.netbufs_ring[sw_rd_idx];
  182. struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
  183. dma_unmap_single(htt->ar->dev, cb->paddr,
  184. skb->len + skb_tailroom(skb),
  185. DMA_FROM_DEVICE);
  186. dev_kfree_skb_any(htt->rx_ring.netbufs_ring[sw_rd_idx]);
  187. sw_rd_idx++;
  188. sw_rd_idx &= htt->rx_ring.size_mask;
  189. }
  190. dma_free_coherent(htt->ar->dev,
  191. (htt->rx_ring.size *
  192. sizeof(htt->rx_ring.paddrs_ring)),
  193. htt->rx_ring.paddrs_ring,
  194. htt->rx_ring.base_paddr);
  195. dma_free_coherent(htt->ar->dev,
  196. sizeof(*htt->rx_ring.alloc_idx.vaddr),
  197. htt->rx_ring.alloc_idx.vaddr,
  198. htt->rx_ring.alloc_idx.paddr);
  199. kfree(htt->rx_ring.netbufs_ring);
  200. }
  201. static inline struct sk_buff *ath10k_htt_rx_netbuf_pop(struct ath10k_htt *htt)
  202. {
  203. int idx;
  204. struct sk_buff *msdu;
  205. spin_lock_bh(&htt->rx_ring.lock);
  206. if (ath10k_htt_rx_ring_elems(htt) == 0)
  207. ath10k_warn("htt rx ring is empty!\n");
  208. idx = htt->rx_ring.sw_rd_idx.msdu_payld;
  209. msdu = htt->rx_ring.netbufs_ring[idx];
  210. idx++;
  211. idx &= htt->rx_ring.size_mask;
  212. htt->rx_ring.sw_rd_idx.msdu_payld = idx;
  213. htt->rx_ring.fill_cnt--;
  214. spin_unlock_bh(&htt->rx_ring.lock);
  215. return msdu;
  216. }
  217. static void ath10k_htt_rx_free_msdu_chain(struct sk_buff *skb)
  218. {
  219. struct sk_buff *next;
  220. while (skb) {
  221. next = skb->next;
  222. dev_kfree_skb_any(skb);
  223. skb = next;
  224. }
  225. }
  226. static int ath10k_htt_rx_amsdu_pop(struct ath10k_htt *htt,
  227. u8 **fw_desc, int *fw_desc_len,
  228. struct sk_buff **head_msdu,
  229. struct sk_buff **tail_msdu)
  230. {
  231. int msdu_len, msdu_chaining = 0;
  232. struct sk_buff *msdu;
  233. struct htt_rx_desc *rx_desc;
  234. if (ath10k_htt_rx_ring_elems(htt) == 0)
  235. ath10k_warn("htt rx ring is empty!\n");
  236. if (htt->rx_confused) {
  237. ath10k_warn("htt is confused. refusing rx\n");
  238. return 0;
  239. }
  240. msdu = *head_msdu = ath10k_htt_rx_netbuf_pop(htt);
  241. while (msdu) {
  242. int last_msdu, msdu_len_invalid, msdu_chained;
  243. dma_unmap_single(htt->ar->dev,
  244. ATH10K_SKB_CB(msdu)->paddr,
  245. msdu->len + skb_tailroom(msdu),
  246. DMA_FROM_DEVICE);
  247. ath10k_dbg_dump(ATH10K_DBG_HTT_DUMP, NULL, "htt rx: ",
  248. msdu->data, msdu->len + skb_tailroom(msdu));
  249. rx_desc = (struct htt_rx_desc *)msdu->data;
  250. /* FIXME: we must report msdu payload since this is what caller
  251. * expects now */
  252. skb_put(msdu, offsetof(struct htt_rx_desc, msdu_payload));
  253. skb_pull(msdu, offsetof(struct htt_rx_desc, msdu_payload));
  254. /*
  255. * Sanity check - confirm the HW is finished filling in the
  256. * rx data.
  257. * If the HW and SW are working correctly, then it's guaranteed
  258. * that the HW's MAC DMA is done before this point in the SW.
  259. * To prevent the case that we handle a stale Rx descriptor,
  260. * just assert for now until we have a way to recover.
  261. */
  262. if (!(__le32_to_cpu(rx_desc->attention.flags)
  263. & RX_ATTENTION_FLAGS_MSDU_DONE)) {
  264. ath10k_htt_rx_free_msdu_chain(*head_msdu);
  265. *head_msdu = NULL;
  266. msdu = NULL;
  267. ath10k_err("htt rx stopped. cannot recover\n");
  268. htt->rx_confused = true;
  269. break;
  270. }
  271. /*
  272. * Copy the FW rx descriptor for this MSDU from the rx
  273. * indication message into the MSDU's netbuf. HL uses the
  274. * same rx indication message definition as LL, and simply
  275. * appends new info (fields from the HW rx desc, and the
  276. * MSDU payload itself). So, the offset into the rx
  277. * indication message only has to account for the standard
  278. * offset of the per-MSDU FW rx desc info within the
  279. * message, and how many bytes of the per-MSDU FW rx desc
  280. * info have already been consumed. (And the endianness of
  281. * the host, since for a big-endian host, the rx ind
  282. * message contents, including the per-MSDU rx desc bytes,
  283. * were byteswapped during upload.)
  284. */
  285. if (*fw_desc_len > 0) {
  286. rx_desc->fw_desc.info0 = **fw_desc;
  287. /*
  288. * The target is expected to only provide the basic
  289. * per-MSDU rx descriptors. Just to be sure, verify
  290. * that the target has not attached extension data
  291. * (e.g. LRO flow ID).
  292. */
  293. /* or more, if there's extension data */
  294. (*fw_desc)++;
  295. (*fw_desc_len)--;
  296. } else {
  297. /*
  298. * When an oversized AMSDU happened, FW will lost
  299. * some of MSDU status - in this case, the FW
  300. * descriptors provided will be less than the
  301. * actual MSDUs inside this MPDU. Mark the FW
  302. * descriptors so that it will still deliver to
  303. * upper stack, if no CRC error for this MPDU.
  304. *
  305. * FIX THIS - the FW descriptors are actually for
  306. * MSDUs in the end of this A-MSDU instead of the
  307. * beginning.
  308. */
  309. rx_desc->fw_desc.info0 = 0;
  310. }
  311. msdu_len_invalid = !!(__le32_to_cpu(rx_desc->attention.flags)
  312. & (RX_ATTENTION_FLAGS_MPDU_LENGTH_ERR |
  313. RX_ATTENTION_FLAGS_MSDU_LENGTH_ERR));
  314. msdu_len = MS(__le32_to_cpu(rx_desc->msdu_start.info0),
  315. RX_MSDU_START_INFO0_MSDU_LENGTH);
  316. msdu_chained = rx_desc->frag_info.ring2_more_count;
  317. if (msdu_len_invalid)
  318. msdu_len = 0;
  319. skb_trim(msdu, 0);
  320. skb_put(msdu, min(msdu_len, HTT_RX_MSDU_SIZE));
  321. msdu_len -= msdu->len;
  322. /* FIXME: Do chained buffers include htt_rx_desc or not? */
  323. while (msdu_chained--) {
  324. struct sk_buff *next = ath10k_htt_rx_netbuf_pop(htt);
  325. dma_unmap_single(htt->ar->dev,
  326. ATH10K_SKB_CB(next)->paddr,
  327. next->len + skb_tailroom(next),
  328. DMA_FROM_DEVICE);
  329. ath10k_dbg_dump(ATH10K_DBG_HTT_DUMP, NULL, "htt rx: ",
  330. next->data,
  331. next->len + skb_tailroom(next));
  332. skb_trim(next, 0);
  333. skb_put(next, min(msdu_len, HTT_RX_BUF_SIZE));
  334. msdu_len -= next->len;
  335. msdu->next = next;
  336. msdu = next;
  337. msdu_chaining = 1;
  338. }
  339. if (msdu_len > 0) {
  340. /* This may suggest FW bug? */
  341. ath10k_warn("htt rx msdu len not consumed (%d)\n",
  342. msdu_len);
  343. }
  344. last_msdu = __le32_to_cpu(rx_desc->msdu_end.info0) &
  345. RX_MSDU_END_INFO0_LAST_MSDU;
  346. if (last_msdu) {
  347. msdu->next = NULL;
  348. break;
  349. } else {
  350. struct sk_buff *next = ath10k_htt_rx_netbuf_pop(htt);
  351. msdu->next = next;
  352. msdu = next;
  353. }
  354. }
  355. *tail_msdu = msdu;
  356. /*
  357. * Don't refill the ring yet.
  358. *
  359. * First, the elements popped here are still in use - it is not
  360. * safe to overwrite them until the matching call to
  361. * mpdu_desc_list_next. Second, for efficiency it is preferable to
  362. * refill the rx ring with 1 PPDU's worth of rx buffers (something
  363. * like 32 x 3 buffers), rather than one MPDU's worth of rx buffers
  364. * (something like 3 buffers). Consequently, we'll rely on the txrx
  365. * SW to tell us when it is done pulling all the PPDU's rx buffers
  366. * out of the rx ring, and then refill it just once.
  367. */
  368. return msdu_chaining;
  369. }
  370. int ath10k_htt_rx_attach(struct ath10k_htt *htt)
  371. {
  372. dma_addr_t paddr;
  373. void *vaddr;
  374. struct timer_list *timer = &htt->rx_ring.refill_retry_timer;
  375. htt->rx_ring.size = ath10k_htt_rx_ring_size(htt);
  376. if (!is_power_of_2(htt->rx_ring.size)) {
  377. ath10k_warn("htt rx ring size is not power of 2\n");
  378. return -EINVAL;
  379. }
  380. htt->rx_ring.size_mask = htt->rx_ring.size - 1;
  381. /*
  382. * Set the initial value for the level to which the rx ring
  383. * should be filled, based on the max throughput and the
  384. * worst likely latency for the host to fill the rx ring
  385. * with new buffers. In theory, this fill level can be
  386. * dynamically adjusted from the initial value set here, to
  387. * reflect the actual host latency rather than a
  388. * conservative assumption about the host latency.
  389. */
  390. htt->rx_ring.fill_level = ath10k_htt_rx_ring_fill_level(htt);
  391. htt->rx_ring.netbufs_ring =
  392. kmalloc(htt->rx_ring.size * sizeof(struct sk_buff *),
  393. GFP_KERNEL);
  394. if (!htt->rx_ring.netbufs_ring)
  395. goto err_netbuf;
  396. vaddr = dma_alloc_coherent(htt->ar->dev,
  397. (htt->rx_ring.size * sizeof(htt->rx_ring.paddrs_ring)),
  398. &paddr, GFP_DMA);
  399. if (!vaddr)
  400. goto err_dma_ring;
  401. htt->rx_ring.paddrs_ring = vaddr;
  402. htt->rx_ring.base_paddr = paddr;
  403. vaddr = dma_alloc_coherent(htt->ar->dev,
  404. sizeof(*htt->rx_ring.alloc_idx.vaddr),
  405. &paddr, GFP_DMA);
  406. if (!vaddr)
  407. goto err_dma_idx;
  408. htt->rx_ring.alloc_idx.vaddr = vaddr;
  409. htt->rx_ring.alloc_idx.paddr = paddr;
  410. htt->rx_ring.sw_rd_idx.msdu_payld = 0;
  411. *htt->rx_ring.alloc_idx.vaddr = 0;
  412. /* Initialize the Rx refill retry timer */
  413. setup_timer(timer, ath10k_htt_rx_ring_refill_retry, (unsigned long)htt);
  414. spin_lock_init(&htt->rx_ring.lock);
  415. htt->rx_ring.fill_cnt = 0;
  416. if (__ath10k_htt_rx_ring_fill_n(htt, htt->rx_ring.fill_level))
  417. goto err_fill_ring;
  418. ath10k_dbg(ATH10K_DBG_BOOT, "htt rx ring size %d fill_level %d\n",
  419. htt->rx_ring.size, htt->rx_ring.fill_level);
  420. return 0;
  421. err_fill_ring:
  422. ath10k_htt_rx_ring_free(htt);
  423. dma_free_coherent(htt->ar->dev,
  424. sizeof(*htt->rx_ring.alloc_idx.vaddr),
  425. htt->rx_ring.alloc_idx.vaddr,
  426. htt->rx_ring.alloc_idx.paddr);
  427. err_dma_idx:
  428. dma_free_coherent(htt->ar->dev,
  429. (htt->rx_ring.size *
  430. sizeof(htt->rx_ring.paddrs_ring)),
  431. htt->rx_ring.paddrs_ring,
  432. htt->rx_ring.base_paddr);
  433. err_dma_ring:
  434. kfree(htt->rx_ring.netbufs_ring);
  435. err_netbuf:
  436. return -ENOMEM;
  437. }
  438. static int ath10k_htt_rx_crypto_param_len(enum htt_rx_mpdu_encrypt_type type)
  439. {
  440. switch (type) {
  441. case HTT_RX_MPDU_ENCRYPT_WEP40:
  442. case HTT_RX_MPDU_ENCRYPT_WEP104:
  443. return 4;
  444. case HTT_RX_MPDU_ENCRYPT_TKIP_WITHOUT_MIC:
  445. case HTT_RX_MPDU_ENCRYPT_WEP128: /* not tested */
  446. case HTT_RX_MPDU_ENCRYPT_TKIP_WPA:
  447. case HTT_RX_MPDU_ENCRYPT_WAPI: /* not tested */
  448. case HTT_RX_MPDU_ENCRYPT_AES_CCM_WPA2:
  449. return 8;
  450. case HTT_RX_MPDU_ENCRYPT_NONE:
  451. return 0;
  452. }
  453. ath10k_warn("unknown encryption type %d\n", type);
  454. return 0;
  455. }
  456. static int ath10k_htt_rx_crypto_tail_len(enum htt_rx_mpdu_encrypt_type type)
  457. {
  458. switch (type) {
  459. case HTT_RX_MPDU_ENCRYPT_NONE:
  460. case HTT_RX_MPDU_ENCRYPT_WEP40:
  461. case HTT_RX_MPDU_ENCRYPT_WEP104:
  462. case HTT_RX_MPDU_ENCRYPT_WEP128:
  463. case HTT_RX_MPDU_ENCRYPT_WAPI:
  464. return 0;
  465. case HTT_RX_MPDU_ENCRYPT_TKIP_WITHOUT_MIC:
  466. case HTT_RX_MPDU_ENCRYPT_TKIP_WPA:
  467. return 4;
  468. case HTT_RX_MPDU_ENCRYPT_AES_CCM_WPA2:
  469. return 8;
  470. }
  471. ath10k_warn("unknown encryption type %d\n", type);
  472. return 0;
  473. }
  474. /* Applies for first msdu in chain, before altering it. */
  475. static struct ieee80211_hdr *ath10k_htt_rx_skb_get_hdr(struct sk_buff *skb)
  476. {
  477. struct htt_rx_desc *rxd;
  478. enum rx_msdu_decap_format fmt;
  479. rxd = (void *)skb->data - sizeof(*rxd);
  480. fmt = MS(__le32_to_cpu(rxd->msdu_start.info1),
  481. RX_MSDU_START_INFO1_DECAP_FORMAT);
  482. if (fmt == RX_MSDU_DECAP_RAW)
  483. return (void *)skb->data;
  484. else
  485. return (void *)skb->data - RX_HTT_HDR_STATUS_LEN;
  486. }
  487. /* This function only applies for first msdu in an msdu chain */
  488. static bool ath10k_htt_rx_hdr_is_amsdu(struct ieee80211_hdr *hdr)
  489. {
  490. if (ieee80211_is_data_qos(hdr->frame_control)) {
  491. u8 *qc = ieee80211_get_qos_ctl(hdr);
  492. if (qc[0] & 0x80)
  493. return true;
  494. }
  495. return false;
  496. }
  497. struct rfc1042_hdr {
  498. u8 llc_dsap;
  499. u8 llc_ssap;
  500. u8 llc_ctrl;
  501. u8 snap_oui[3];
  502. __be16 snap_type;
  503. } __packed;
  504. struct amsdu_subframe_hdr {
  505. u8 dst[ETH_ALEN];
  506. u8 src[ETH_ALEN];
  507. __be16 len;
  508. } __packed;
  509. static void ath10k_htt_rx_amsdu(struct ath10k_htt *htt,
  510. struct htt_rx_info *info)
  511. {
  512. struct htt_rx_desc *rxd;
  513. struct sk_buff *first;
  514. struct sk_buff *skb = info->skb;
  515. enum rx_msdu_decap_format fmt;
  516. enum htt_rx_mpdu_encrypt_type enctype;
  517. struct ieee80211_hdr *hdr;
  518. u8 hdr_buf[64];
  519. unsigned int hdr_len;
  520. rxd = (void *)skb->data - sizeof(*rxd);
  521. enctype = MS(__le32_to_cpu(rxd->mpdu_start.info0),
  522. RX_MPDU_START_INFO0_ENCRYPT_TYPE);
  523. hdr = (struct ieee80211_hdr *)rxd->rx_hdr_status;
  524. hdr_len = ieee80211_hdrlen(hdr->frame_control);
  525. memcpy(hdr_buf, hdr, hdr_len);
  526. hdr = (struct ieee80211_hdr *)hdr_buf;
  527. /* FIXME: Hopefully this is a temporary measure.
  528. *
  529. * Reporting individual A-MSDU subframes means each reported frame
  530. * shares the same sequence number.
  531. *
  532. * mac80211 drops frames it recognizes as duplicates, i.e.
  533. * retransmission flag is set and sequence number matches sequence
  534. * number from a previous frame (as per IEEE 802.11-2012: 9.3.2.10
  535. * "Duplicate detection and recovery")
  536. *
  537. * To avoid frames being dropped clear retransmission flag for all
  538. * received A-MSDUs.
  539. *
  540. * Worst case: actual duplicate frames will be reported but this should
  541. * still be handled gracefully by other OSI/ISO layers. */
  542. hdr->frame_control &= cpu_to_le16(~IEEE80211_FCTL_RETRY);
  543. first = skb;
  544. while (skb) {
  545. void *decap_hdr;
  546. int len;
  547. rxd = (void *)skb->data - sizeof(*rxd);
  548. fmt = MS(__le32_to_cpu(rxd->msdu_start.info1),
  549. RX_MSDU_START_INFO1_DECAP_FORMAT);
  550. decap_hdr = (void *)rxd->rx_hdr_status;
  551. skb->ip_summed = ath10k_htt_rx_get_csum_state(skb);
  552. /* First frame in an A-MSDU chain has more decapped data. */
  553. if (skb == first) {
  554. len = round_up(ieee80211_hdrlen(hdr->frame_control), 4);
  555. len += round_up(ath10k_htt_rx_crypto_param_len(enctype),
  556. 4);
  557. decap_hdr += len;
  558. }
  559. switch (fmt) {
  560. case RX_MSDU_DECAP_RAW:
  561. /* remove trailing FCS */
  562. skb_trim(skb, skb->len - FCS_LEN);
  563. break;
  564. case RX_MSDU_DECAP_NATIVE_WIFI:
  565. /* nothing to do */
  566. break;
  567. case RX_MSDU_DECAP_ETHERNET2_DIX:
  568. /* strip ethernet header and insert decapped 802.11
  569. * header, amsdu subframe header and rfc1042 header */
  570. len = 0;
  571. len += sizeof(struct rfc1042_hdr);
  572. len += sizeof(struct amsdu_subframe_hdr);
  573. skb_pull(skb, sizeof(struct ethhdr));
  574. memcpy(skb_push(skb, len), decap_hdr, len);
  575. memcpy(skb_push(skb, hdr_len), hdr, hdr_len);
  576. break;
  577. case RX_MSDU_DECAP_8023_SNAP_LLC:
  578. /* insert decapped 802.11 header making a singly
  579. * A-MSDU */
  580. memcpy(skb_push(skb, hdr_len), hdr, hdr_len);
  581. break;
  582. }
  583. info->skb = skb;
  584. info->encrypt_type = enctype;
  585. skb = skb->next;
  586. info->skb->next = NULL;
  587. ath10k_process_rx(htt->ar, info);
  588. }
  589. /* FIXME: It might be nice to re-assemble the A-MSDU when there's a
  590. * monitor interface active for sniffing purposes. */
  591. }
  592. static void ath10k_htt_rx_msdu(struct ath10k_htt *htt, struct htt_rx_info *info)
  593. {
  594. struct sk_buff *skb = info->skb;
  595. struct htt_rx_desc *rxd;
  596. struct ieee80211_hdr *hdr;
  597. enum rx_msdu_decap_format fmt;
  598. enum htt_rx_mpdu_encrypt_type enctype;
  599. int hdr_len;
  600. void *rfc1042;
  601. /* This shouldn't happen. If it does than it may be a FW bug. */
  602. if (skb->next) {
  603. ath10k_warn("received chained non A-MSDU frame\n");
  604. ath10k_htt_rx_free_msdu_chain(skb->next);
  605. skb->next = NULL;
  606. }
  607. rxd = (void *)skb->data - sizeof(*rxd);
  608. fmt = MS(__le32_to_cpu(rxd->msdu_start.info1),
  609. RX_MSDU_START_INFO1_DECAP_FORMAT);
  610. enctype = MS(__le32_to_cpu(rxd->mpdu_start.info0),
  611. RX_MPDU_START_INFO0_ENCRYPT_TYPE);
  612. hdr = (struct ieee80211_hdr *)rxd->rx_hdr_status;
  613. hdr_len = ieee80211_hdrlen(hdr->frame_control);
  614. skb->ip_summed = ath10k_htt_rx_get_csum_state(skb);
  615. switch (fmt) {
  616. case RX_MSDU_DECAP_RAW:
  617. /* remove trailing FCS */
  618. skb_trim(skb, skb->len - FCS_LEN);
  619. break;
  620. case RX_MSDU_DECAP_NATIVE_WIFI:
  621. /* nothing to do here */
  622. break;
  623. case RX_MSDU_DECAP_ETHERNET2_DIX:
  624. /* strip ethernet header and insert decapped 802.11 header and
  625. * rfc1042 header */
  626. rfc1042 = hdr;
  627. rfc1042 += roundup(hdr_len, 4);
  628. rfc1042 += roundup(ath10k_htt_rx_crypto_param_len(enctype), 4);
  629. skb_pull(skb, sizeof(struct ethhdr));
  630. memcpy(skb_push(skb, sizeof(struct rfc1042_hdr)),
  631. rfc1042, sizeof(struct rfc1042_hdr));
  632. memcpy(skb_push(skb, hdr_len), hdr, hdr_len);
  633. break;
  634. case RX_MSDU_DECAP_8023_SNAP_LLC:
  635. /* remove A-MSDU subframe header and insert
  636. * decapped 802.11 header. rfc1042 header is already there */
  637. skb_pull(skb, sizeof(struct amsdu_subframe_hdr));
  638. memcpy(skb_push(skb, hdr_len), hdr, hdr_len);
  639. break;
  640. }
  641. info->skb = skb;
  642. info->encrypt_type = enctype;
  643. ath10k_process_rx(htt->ar, info);
  644. }
  645. static bool ath10k_htt_rx_has_decrypt_err(struct sk_buff *skb)
  646. {
  647. struct htt_rx_desc *rxd;
  648. u32 flags;
  649. rxd = (void *)skb->data - sizeof(*rxd);
  650. flags = __le32_to_cpu(rxd->attention.flags);
  651. if (flags & RX_ATTENTION_FLAGS_DECRYPT_ERR)
  652. return true;
  653. return false;
  654. }
  655. static bool ath10k_htt_rx_has_fcs_err(struct sk_buff *skb)
  656. {
  657. struct htt_rx_desc *rxd;
  658. u32 flags;
  659. rxd = (void *)skb->data - sizeof(*rxd);
  660. flags = __le32_to_cpu(rxd->attention.flags);
  661. if (flags & RX_ATTENTION_FLAGS_FCS_ERR)
  662. return true;
  663. return false;
  664. }
  665. static int ath10k_htt_rx_get_csum_state(struct sk_buff *skb)
  666. {
  667. struct htt_rx_desc *rxd;
  668. u32 flags, info;
  669. bool is_ip4, is_ip6;
  670. bool is_tcp, is_udp;
  671. bool ip_csum_ok, tcpudp_csum_ok;
  672. rxd = (void *)skb->data - sizeof(*rxd);
  673. flags = __le32_to_cpu(rxd->attention.flags);
  674. info = __le32_to_cpu(rxd->msdu_start.info1);
  675. is_ip4 = !!(info & RX_MSDU_START_INFO1_IPV4_PROTO);
  676. is_ip6 = !!(info & RX_MSDU_START_INFO1_IPV6_PROTO);
  677. is_tcp = !!(info & RX_MSDU_START_INFO1_TCP_PROTO);
  678. is_udp = !!(info & RX_MSDU_START_INFO1_UDP_PROTO);
  679. ip_csum_ok = !(flags & RX_ATTENTION_FLAGS_IP_CHKSUM_FAIL);
  680. tcpudp_csum_ok = !(flags & RX_ATTENTION_FLAGS_TCP_UDP_CHKSUM_FAIL);
  681. if (!is_ip4 && !is_ip6)
  682. return CHECKSUM_NONE;
  683. if (!is_tcp && !is_udp)
  684. return CHECKSUM_NONE;
  685. if (!ip_csum_ok)
  686. return CHECKSUM_NONE;
  687. if (!tcpudp_csum_ok)
  688. return CHECKSUM_NONE;
  689. return CHECKSUM_UNNECESSARY;
  690. }
  691. static void ath10k_htt_rx_handler(struct ath10k_htt *htt,
  692. struct htt_rx_indication *rx)
  693. {
  694. struct htt_rx_info info;
  695. struct htt_rx_indication_mpdu_range *mpdu_ranges;
  696. struct ieee80211_hdr *hdr;
  697. int num_mpdu_ranges;
  698. int fw_desc_len;
  699. u8 *fw_desc;
  700. int i, j;
  701. memset(&info, 0, sizeof(info));
  702. fw_desc_len = __le16_to_cpu(rx->prefix.fw_rx_desc_bytes);
  703. fw_desc = (u8 *)&rx->fw_desc;
  704. num_mpdu_ranges = MS(__le32_to_cpu(rx->hdr.info1),
  705. HTT_RX_INDICATION_INFO1_NUM_MPDU_RANGES);
  706. mpdu_ranges = htt_rx_ind_get_mpdu_ranges(rx);
  707. ath10k_dbg_dump(ATH10K_DBG_HTT_DUMP, NULL, "htt rx ind: ",
  708. rx, sizeof(*rx) +
  709. (sizeof(struct htt_rx_indication_mpdu_range) *
  710. num_mpdu_ranges));
  711. for (i = 0; i < num_mpdu_ranges; i++) {
  712. info.status = mpdu_ranges[i].mpdu_range_status;
  713. for (j = 0; j < mpdu_ranges[i].mpdu_count; j++) {
  714. struct sk_buff *msdu_head, *msdu_tail;
  715. enum htt_rx_mpdu_status status;
  716. int msdu_chaining;
  717. msdu_head = NULL;
  718. msdu_tail = NULL;
  719. msdu_chaining = ath10k_htt_rx_amsdu_pop(htt,
  720. &fw_desc,
  721. &fw_desc_len,
  722. &msdu_head,
  723. &msdu_tail);
  724. if (!msdu_head) {
  725. ath10k_warn("htt rx no data!\n");
  726. continue;
  727. }
  728. if (msdu_head->len == 0) {
  729. ath10k_dbg(ATH10K_DBG_HTT,
  730. "htt rx dropping due to zero-len\n");
  731. ath10k_htt_rx_free_msdu_chain(msdu_head);
  732. continue;
  733. }
  734. if (ath10k_htt_rx_has_decrypt_err(msdu_head)) {
  735. ath10k_htt_rx_free_msdu_chain(msdu_head);
  736. continue;
  737. }
  738. status = info.status;
  739. /* Skip mgmt frames while we handle this in WMI */
  740. if (status == HTT_RX_IND_MPDU_STATUS_MGMT_CTRL) {
  741. ath10k_htt_rx_free_msdu_chain(msdu_head);
  742. continue;
  743. }
  744. if (status != HTT_RX_IND_MPDU_STATUS_OK &&
  745. status != HTT_RX_IND_MPDU_STATUS_TKIP_MIC_ERR &&
  746. !htt->ar->monitor_enabled) {
  747. ath10k_dbg(ATH10K_DBG_HTT,
  748. "htt rx ignoring frame w/ status %d\n",
  749. status);
  750. ath10k_htt_rx_free_msdu_chain(msdu_head);
  751. continue;
  752. }
  753. /* FIXME: we do not support chaining yet.
  754. * this needs investigation */
  755. if (msdu_chaining) {
  756. ath10k_warn("msdu_chaining is true\n");
  757. ath10k_htt_rx_free_msdu_chain(msdu_head);
  758. continue;
  759. }
  760. info.skb = msdu_head;
  761. info.fcs_err = ath10k_htt_rx_has_fcs_err(msdu_head);
  762. info.signal = ATH10K_DEFAULT_NOISE_FLOOR;
  763. info.signal += rx->ppdu.combined_rssi;
  764. info.rate.info0 = rx->ppdu.info0;
  765. info.rate.info1 = __le32_to_cpu(rx->ppdu.info1);
  766. info.rate.info2 = __le32_to_cpu(rx->ppdu.info2);
  767. hdr = ath10k_htt_rx_skb_get_hdr(msdu_head);
  768. if (ath10k_htt_rx_hdr_is_amsdu(hdr))
  769. ath10k_htt_rx_amsdu(htt, &info);
  770. else
  771. ath10k_htt_rx_msdu(htt, &info);
  772. }
  773. }
  774. ath10k_htt_rx_msdu_buff_replenish(htt);
  775. }
  776. static void ath10k_htt_rx_frag_handler(struct ath10k_htt *htt,
  777. struct htt_rx_fragment_indication *frag)
  778. {
  779. struct sk_buff *msdu_head, *msdu_tail;
  780. struct htt_rx_desc *rxd;
  781. enum rx_msdu_decap_format fmt;
  782. struct htt_rx_info info = {};
  783. struct ieee80211_hdr *hdr;
  784. int msdu_chaining;
  785. bool tkip_mic_err;
  786. bool decrypt_err;
  787. u8 *fw_desc;
  788. int fw_desc_len, hdrlen, paramlen;
  789. int trim;
  790. fw_desc_len = __le16_to_cpu(frag->fw_rx_desc_bytes);
  791. fw_desc = (u8 *)frag->fw_msdu_rx_desc;
  792. msdu_head = NULL;
  793. msdu_tail = NULL;
  794. msdu_chaining = ath10k_htt_rx_amsdu_pop(htt, &fw_desc, &fw_desc_len,
  795. &msdu_head, &msdu_tail);
  796. ath10k_dbg(ATH10K_DBG_HTT_DUMP, "htt rx frag ahead\n");
  797. if (!msdu_head) {
  798. ath10k_warn("htt rx frag no data\n");
  799. return;
  800. }
  801. if (msdu_chaining || msdu_head != msdu_tail) {
  802. ath10k_warn("aggregation with fragmentation?!\n");
  803. ath10k_htt_rx_free_msdu_chain(msdu_head);
  804. return;
  805. }
  806. /* FIXME: implement signal strength */
  807. hdr = (struct ieee80211_hdr *)msdu_head->data;
  808. rxd = (void *)msdu_head->data - sizeof(*rxd);
  809. tkip_mic_err = !!(__le32_to_cpu(rxd->attention.flags) &
  810. RX_ATTENTION_FLAGS_TKIP_MIC_ERR);
  811. decrypt_err = !!(__le32_to_cpu(rxd->attention.flags) &
  812. RX_ATTENTION_FLAGS_DECRYPT_ERR);
  813. fmt = MS(__le32_to_cpu(rxd->msdu_start.info1),
  814. RX_MSDU_START_INFO1_DECAP_FORMAT);
  815. if (fmt != RX_MSDU_DECAP_RAW) {
  816. ath10k_warn("we dont support non-raw fragmented rx yet\n");
  817. dev_kfree_skb_any(msdu_head);
  818. goto end;
  819. }
  820. info.skb = msdu_head;
  821. info.status = HTT_RX_IND_MPDU_STATUS_OK;
  822. info.encrypt_type = MS(__le32_to_cpu(rxd->mpdu_start.info0),
  823. RX_MPDU_START_INFO0_ENCRYPT_TYPE);
  824. info.skb->ip_summed = ath10k_htt_rx_get_csum_state(info.skb);
  825. if (tkip_mic_err) {
  826. ath10k_warn("tkip mic error\n");
  827. info.status = HTT_RX_IND_MPDU_STATUS_TKIP_MIC_ERR;
  828. }
  829. if (decrypt_err) {
  830. ath10k_warn("decryption err in fragmented rx\n");
  831. dev_kfree_skb_any(info.skb);
  832. goto end;
  833. }
  834. if (info.encrypt_type != HTT_RX_MPDU_ENCRYPT_NONE) {
  835. hdrlen = ieee80211_hdrlen(hdr->frame_control);
  836. paramlen = ath10k_htt_rx_crypto_param_len(info.encrypt_type);
  837. /* It is more efficient to move the header than the payload */
  838. memmove((void *)info.skb->data + paramlen,
  839. (void *)info.skb->data,
  840. hdrlen);
  841. skb_pull(info.skb, paramlen);
  842. hdr = (struct ieee80211_hdr *)info.skb->data;
  843. }
  844. /* remove trailing FCS */
  845. trim = 4;
  846. /* remove crypto trailer */
  847. trim += ath10k_htt_rx_crypto_tail_len(info.encrypt_type);
  848. /* last fragment of TKIP frags has MIC */
  849. if (!ieee80211_has_morefrags(hdr->frame_control) &&
  850. info.encrypt_type == HTT_RX_MPDU_ENCRYPT_TKIP_WPA)
  851. trim += 8;
  852. if (trim > info.skb->len) {
  853. ath10k_warn("htt rx fragment: trailer longer than the frame itself? drop\n");
  854. dev_kfree_skb_any(info.skb);
  855. goto end;
  856. }
  857. skb_trim(info.skb, info.skb->len - trim);
  858. ath10k_dbg_dump(ATH10K_DBG_HTT_DUMP, NULL, "htt frag mpdu: ",
  859. info.skb->data, info.skb->len);
  860. ath10k_process_rx(htt->ar, &info);
  861. end:
  862. if (fw_desc_len > 0) {
  863. ath10k_dbg(ATH10K_DBG_HTT,
  864. "expecting more fragmented rx in one indication %d\n",
  865. fw_desc_len);
  866. }
  867. }
  868. void ath10k_htt_t2h_msg_handler(struct ath10k *ar, struct sk_buff *skb)
  869. {
  870. struct ath10k_htt *htt = &ar->htt;
  871. struct htt_resp *resp = (struct htt_resp *)skb->data;
  872. /* confirm alignment */
  873. if (!IS_ALIGNED((unsigned long)skb->data, 4))
  874. ath10k_warn("unaligned htt message, expect trouble\n");
  875. ath10k_dbg(ATH10K_DBG_HTT, "HTT RX, msg_type: 0x%0X\n",
  876. resp->hdr.msg_type);
  877. switch (resp->hdr.msg_type) {
  878. case HTT_T2H_MSG_TYPE_VERSION_CONF: {
  879. htt->target_version_major = resp->ver_resp.major;
  880. htt->target_version_minor = resp->ver_resp.minor;
  881. complete(&htt->target_version_received);
  882. break;
  883. }
  884. case HTT_T2H_MSG_TYPE_RX_IND: {
  885. ath10k_htt_rx_handler(htt, &resp->rx_ind);
  886. break;
  887. }
  888. case HTT_T2H_MSG_TYPE_PEER_MAP: {
  889. struct htt_peer_map_event ev = {
  890. .vdev_id = resp->peer_map.vdev_id,
  891. .peer_id = __le16_to_cpu(resp->peer_map.peer_id),
  892. };
  893. memcpy(ev.addr, resp->peer_map.addr, sizeof(ev.addr));
  894. ath10k_peer_map_event(htt, &ev);
  895. break;
  896. }
  897. case HTT_T2H_MSG_TYPE_PEER_UNMAP: {
  898. struct htt_peer_unmap_event ev = {
  899. .peer_id = __le16_to_cpu(resp->peer_unmap.peer_id),
  900. };
  901. ath10k_peer_unmap_event(htt, &ev);
  902. break;
  903. }
  904. case HTT_T2H_MSG_TYPE_MGMT_TX_COMPLETION: {
  905. struct htt_tx_done tx_done = {};
  906. int status = __le32_to_cpu(resp->mgmt_tx_completion.status);
  907. tx_done.msdu_id =
  908. __le32_to_cpu(resp->mgmt_tx_completion.desc_id);
  909. switch (status) {
  910. case HTT_MGMT_TX_STATUS_OK:
  911. break;
  912. case HTT_MGMT_TX_STATUS_RETRY:
  913. tx_done.no_ack = true;
  914. break;
  915. case HTT_MGMT_TX_STATUS_DROP:
  916. tx_done.discard = true;
  917. break;
  918. }
  919. ath10k_txrx_tx_unref(htt, &tx_done);
  920. break;
  921. }
  922. case HTT_T2H_MSG_TYPE_TX_COMPL_IND: {
  923. struct htt_tx_done tx_done = {};
  924. int status = MS(resp->data_tx_completion.flags,
  925. HTT_DATA_TX_STATUS);
  926. __le16 msdu_id;
  927. int i;
  928. switch (status) {
  929. case HTT_DATA_TX_STATUS_NO_ACK:
  930. tx_done.no_ack = true;
  931. break;
  932. case HTT_DATA_TX_STATUS_OK:
  933. break;
  934. case HTT_DATA_TX_STATUS_DISCARD:
  935. case HTT_DATA_TX_STATUS_POSTPONE:
  936. case HTT_DATA_TX_STATUS_DOWNLOAD_FAIL:
  937. tx_done.discard = true;
  938. break;
  939. default:
  940. ath10k_warn("unhandled tx completion status %d\n",
  941. status);
  942. tx_done.discard = true;
  943. break;
  944. }
  945. ath10k_dbg(ATH10K_DBG_HTT, "htt tx completion num_msdus %d\n",
  946. resp->data_tx_completion.num_msdus);
  947. for (i = 0; i < resp->data_tx_completion.num_msdus; i++) {
  948. msdu_id = resp->data_tx_completion.msdus[i];
  949. tx_done.msdu_id = __le16_to_cpu(msdu_id);
  950. ath10k_txrx_tx_unref(htt, &tx_done);
  951. }
  952. break;
  953. }
  954. case HTT_T2H_MSG_TYPE_SEC_IND: {
  955. struct ath10k *ar = htt->ar;
  956. struct htt_security_indication *ev = &resp->security_indication;
  957. ath10k_dbg(ATH10K_DBG_HTT,
  958. "sec ind peer_id %d unicast %d type %d\n",
  959. __le16_to_cpu(ev->peer_id),
  960. !!(ev->flags & HTT_SECURITY_IS_UNICAST),
  961. MS(ev->flags, HTT_SECURITY_TYPE));
  962. complete(&ar->install_key_done);
  963. break;
  964. }
  965. case HTT_T2H_MSG_TYPE_RX_FRAG_IND: {
  966. ath10k_dbg_dump(ATH10K_DBG_HTT_DUMP, NULL, "htt event: ",
  967. skb->data, skb->len);
  968. ath10k_htt_rx_frag_handler(htt, &resp->rx_frag_ind);
  969. break;
  970. }
  971. case HTT_T2H_MSG_TYPE_TEST:
  972. /* FIX THIS */
  973. break;
  974. case HTT_T2H_MSG_TYPE_STATS_CONF:
  975. trace_ath10k_htt_stats(skb->data, skb->len);
  976. break;
  977. case HTT_T2H_MSG_TYPE_TX_INSPECT_IND:
  978. case HTT_T2H_MSG_TYPE_RX_ADDBA:
  979. case HTT_T2H_MSG_TYPE_RX_DELBA:
  980. case HTT_T2H_MSG_TYPE_RX_FLUSH:
  981. default:
  982. ath10k_dbg(ATH10K_DBG_HTT, "htt event (%d) not handled\n",
  983. resp->hdr.msg_type);
  984. ath10k_dbg_dump(ATH10K_DBG_HTT_DUMP, NULL, "htt event: ",
  985. skb->data, skb->len);
  986. break;
  987. };
  988. /* Free the indication buffer */
  989. dev_kfree_skb_any(skb);
  990. }