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