blob: c4637f18734fc51f6e9938421c00e050680c0b84 [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;
Michal Kazior784f69d2013-09-26 10:12:23 +0300621 u8 hdr_buf[64], addr[ETH_ALEN], *qos;
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 Kazior784f69d2013-09-26 10:12:23 +0300676 /* pull decapped header and copy DA */
677 hdr = (struct ieee80211_hdr *)skb->data;
678 hdr_len = ieee80211_hdrlen(hdr->frame_control);
679 memcpy(addr, ieee80211_get_DA(hdr), ETH_ALEN);
680 skb_pull(skb, hdr_len);
681
682 /* push original 802.11 header */
683 hdr = (struct ieee80211_hdr *)hdr_buf;
684 hdr_len = ieee80211_hdrlen(hdr->frame_control);
685 memcpy(skb_push(skb, hdr_len), hdr, hdr_len);
686
687 /* original A-MSDU header has the bit set but we're
688 * not including A-MSDU subframe header */
689 hdr = (struct ieee80211_hdr *)skb->data;
690 qos = ieee80211_get_qos_ctl(hdr);
691 qos[0] &= ~IEEE80211_QOS_CTL_A_MSDU_PRESENT;
692
693 /* original 802.11 header has a different DA */
694 memcpy(ieee80211_get_DA(hdr), addr, ETH_ALEN);
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300695 break;
696 case RX_MSDU_DECAP_ETHERNET2_DIX:
Michal Kaziore3fbf8d2013-09-26 10:12:23 +0300697 /* strip ethernet header and insert decapped 802.11
698 * header, amsdu subframe header and rfc1042 header */
699
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300700 len = 0;
701 len += sizeof(struct rfc1042_hdr);
702 len += sizeof(struct amsdu_subframe_hdr);
Michal Kaziordfa95b52013-08-13 07:59:37 +0200703
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300704 skb_pull(skb, sizeof(struct ethhdr));
705 memcpy(skb_push(skb, len), decap_hdr, len);
706 memcpy(skb_push(skb, hdr_len), hdr, hdr_len);
707 break;
708 case RX_MSDU_DECAP_8023_SNAP_LLC:
Michal Kaziore3fbf8d2013-09-26 10:12:23 +0300709 /* insert decapped 802.11 header making a singly
710 * A-MSDU */
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300711 memcpy(skb_push(skb, hdr_len), hdr, hdr_len);
712 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300713 }
714
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300715 info->skb = skb;
716 info->encrypt_type = enctype;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300717 skb = skb->next;
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300718 info->skb->next = NULL;
719
720 ath10k_process_rx(htt->ar, info);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300721 }
722
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300723 /* FIXME: It might be nice to re-assemble the A-MSDU when there's a
724 * monitor interface active for sniffing purposes. */
Kalle Valo5e3dd152013-06-12 20:52:10 +0300725}
726
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300727static void ath10k_htt_rx_msdu(struct ath10k_htt *htt, struct htt_rx_info *info)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300728{
729 struct sk_buff *skb = info->skb;
730 struct htt_rx_desc *rxd;
731 struct ieee80211_hdr *hdr;
732 enum rx_msdu_decap_format fmt;
733 enum htt_rx_mpdu_encrypt_type enctype;
Michal Kaziore3fbf8d2013-09-26 10:12:23 +0300734 int hdr_len;
735 void *rfc1042;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300736
737 /* This shouldn't happen. If it does than it may be a FW bug. */
738 if (skb->next) {
739 ath10k_warn("received chained non A-MSDU frame\n");
740 ath10k_htt_rx_free_msdu_chain(skb->next);
741 skb->next = NULL;
742 }
743
744 rxd = (void *)skb->data - sizeof(*rxd);
745 fmt = MS(__le32_to_cpu(rxd->msdu_start.info1),
746 RX_MSDU_START_INFO1_DECAP_FORMAT);
747 enctype = MS(__le32_to_cpu(rxd->mpdu_start.info0),
748 RX_MPDU_START_INFO0_ENCRYPT_TYPE);
Michal Kaziore3fbf8d2013-09-26 10:12:23 +0300749 hdr = (struct ieee80211_hdr *)rxd->rx_hdr_status;
750 hdr_len = ieee80211_hdrlen(hdr->frame_control);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300751
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300752 skb->ip_summed = ath10k_htt_rx_get_csum_state(skb);
753
Kalle Valo5e3dd152013-06-12 20:52:10 +0300754 switch (fmt) {
755 case RX_MSDU_DECAP_RAW:
756 /* remove trailing FCS */
Michal Kaziore3fbf8d2013-09-26 10:12:23 +0300757 skb_trim(skb, skb->len - FCS_LEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300758 break;
759 case RX_MSDU_DECAP_NATIVE_WIFI:
Michal Kazior784f69d2013-09-26 10:12:23 +0300760 /* Pull decapped header */
761 hdr = (struct ieee80211_hdr *)skb->data;
762 hdr_len = ieee80211_hdrlen(hdr->frame_control);
763 skb_pull(skb, hdr_len);
764
765 /* Push original header */
766 hdr = (struct ieee80211_hdr *)rxd->rx_hdr_status;
767 hdr_len = ieee80211_hdrlen(hdr->frame_control);
768 memcpy(skb_push(skb, hdr_len), hdr, hdr_len);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300769 break;
770 case RX_MSDU_DECAP_ETHERNET2_DIX:
Michal Kaziore3fbf8d2013-09-26 10:12:23 +0300771 /* strip ethernet header and insert decapped 802.11 header and
772 * rfc1042 header */
773
774 rfc1042 = hdr;
775 rfc1042 += roundup(hdr_len, 4);
776 rfc1042 += roundup(ath10k_htt_rx_crypto_param_len(enctype), 4);
777
778 skb_pull(skb, sizeof(struct ethhdr));
779 memcpy(skb_push(skb, sizeof(struct rfc1042_hdr)),
780 rfc1042, sizeof(struct rfc1042_hdr));
781 memcpy(skb_push(skb, hdr_len), hdr, hdr_len);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300782 break;
783 case RX_MSDU_DECAP_8023_SNAP_LLC:
Michal Kaziore3fbf8d2013-09-26 10:12:23 +0300784 /* remove A-MSDU subframe header and insert
785 * decapped 802.11 header. rfc1042 header is already there */
786
787 skb_pull(skb, sizeof(struct amsdu_subframe_hdr));
788 memcpy(skb_push(skb, hdr_len), hdr, hdr_len);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300789 break;
790 }
791
Kalle Valo5e3dd152013-06-12 20:52:10 +0300792 info->skb = skb;
793 info->encrypt_type = enctype;
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300794
795 ath10k_process_rx(htt->ar, info);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300796}
797
798static bool ath10k_htt_rx_has_decrypt_err(struct sk_buff *skb)
799{
800 struct htt_rx_desc *rxd;
801 u32 flags;
802
803 rxd = (void *)skb->data - sizeof(*rxd);
804 flags = __le32_to_cpu(rxd->attention.flags);
805
806 if (flags & RX_ATTENTION_FLAGS_DECRYPT_ERR)
807 return true;
808
809 return false;
810}
811
812static bool ath10k_htt_rx_has_fcs_err(struct sk_buff *skb)
813{
814 struct htt_rx_desc *rxd;
815 u32 flags;
816
817 rxd = (void *)skb->data - sizeof(*rxd);
818 flags = __le32_to_cpu(rxd->attention.flags);
819
820 if (flags & RX_ATTENTION_FLAGS_FCS_ERR)
821 return true;
822
823 return false;
824}
825
Michal Kazior605f81a2013-07-31 10:47:56 +0200826static int ath10k_htt_rx_get_csum_state(struct sk_buff *skb)
827{
828 struct htt_rx_desc *rxd;
829 u32 flags, info;
830 bool is_ip4, is_ip6;
831 bool is_tcp, is_udp;
832 bool ip_csum_ok, tcpudp_csum_ok;
833
834 rxd = (void *)skb->data - sizeof(*rxd);
835 flags = __le32_to_cpu(rxd->attention.flags);
836 info = __le32_to_cpu(rxd->msdu_start.info1);
837
838 is_ip4 = !!(info & RX_MSDU_START_INFO1_IPV4_PROTO);
839 is_ip6 = !!(info & RX_MSDU_START_INFO1_IPV6_PROTO);
840 is_tcp = !!(info & RX_MSDU_START_INFO1_TCP_PROTO);
841 is_udp = !!(info & RX_MSDU_START_INFO1_UDP_PROTO);
842 ip_csum_ok = !(flags & RX_ATTENTION_FLAGS_IP_CHKSUM_FAIL);
843 tcpudp_csum_ok = !(flags & RX_ATTENTION_FLAGS_TCP_UDP_CHKSUM_FAIL);
844
845 if (!is_ip4 && !is_ip6)
846 return CHECKSUM_NONE;
847 if (!is_tcp && !is_udp)
848 return CHECKSUM_NONE;
849 if (!ip_csum_ok)
850 return CHECKSUM_NONE;
851 if (!tcpudp_csum_ok)
852 return CHECKSUM_NONE;
853
854 return CHECKSUM_UNNECESSARY;
855}
856
Kalle Valo5e3dd152013-06-12 20:52:10 +0300857static void ath10k_htt_rx_handler(struct ath10k_htt *htt,
858 struct htt_rx_indication *rx)
859{
860 struct htt_rx_info info;
861 struct htt_rx_indication_mpdu_range *mpdu_ranges;
862 struct ieee80211_hdr *hdr;
863 int num_mpdu_ranges;
864 int fw_desc_len;
865 u8 *fw_desc;
866 int i, j;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300867
868 memset(&info, 0, sizeof(info));
869
870 fw_desc_len = __le16_to_cpu(rx->prefix.fw_rx_desc_bytes);
871 fw_desc = (u8 *)&rx->fw_desc;
872
873 num_mpdu_ranges = MS(__le32_to_cpu(rx->hdr.info1),
874 HTT_RX_INDICATION_INFO1_NUM_MPDU_RANGES);
875 mpdu_ranges = htt_rx_ind_get_mpdu_ranges(rx);
876
877 ath10k_dbg_dump(ATH10K_DBG_HTT_DUMP, NULL, "htt rx ind: ",
878 rx, sizeof(*rx) +
879 (sizeof(struct htt_rx_indication_mpdu_range) *
880 num_mpdu_ranges));
881
882 for (i = 0; i < num_mpdu_ranges; i++) {
883 info.status = mpdu_ranges[i].mpdu_range_status;
884
885 for (j = 0; j < mpdu_ranges[i].mpdu_count; j++) {
886 struct sk_buff *msdu_head, *msdu_tail;
887 enum htt_rx_mpdu_status status;
888 int msdu_chaining;
889
890 msdu_head = NULL;
891 msdu_tail = NULL;
892 msdu_chaining = ath10k_htt_rx_amsdu_pop(htt,
893 &fw_desc,
894 &fw_desc_len,
895 &msdu_head,
896 &msdu_tail);
897
898 if (!msdu_head) {
899 ath10k_warn("htt rx no data!\n");
900 continue;
901 }
902
903 if (msdu_head->len == 0) {
904 ath10k_dbg(ATH10K_DBG_HTT,
905 "htt rx dropping due to zero-len\n");
906 ath10k_htt_rx_free_msdu_chain(msdu_head);
907 continue;
908 }
909
910 if (ath10k_htt_rx_has_decrypt_err(msdu_head)) {
911 ath10k_htt_rx_free_msdu_chain(msdu_head);
912 continue;
913 }
914
915 status = info.status;
916
917 /* Skip mgmt frames while we handle this in WMI */
918 if (status == HTT_RX_IND_MPDU_STATUS_MGMT_CTRL) {
919 ath10k_htt_rx_free_msdu_chain(msdu_head);
920 continue;
921 }
922
923 if (status != HTT_RX_IND_MPDU_STATUS_OK &&
924 status != HTT_RX_IND_MPDU_STATUS_TKIP_MIC_ERR &&
925 !htt->ar->monitor_enabled) {
926 ath10k_dbg(ATH10K_DBG_HTT,
927 "htt rx ignoring frame w/ status %d\n",
928 status);
929 ath10k_htt_rx_free_msdu_chain(msdu_head);
930 continue;
931 }
932
933 /* FIXME: we do not support chaining yet.
934 * this needs investigation */
935 if (msdu_chaining) {
936 ath10k_warn("msdu_chaining is true\n");
937 ath10k_htt_rx_free_msdu_chain(msdu_head);
938 continue;
939 }
940
941 info.skb = msdu_head;
942 info.fcs_err = ath10k_htt_rx_has_fcs_err(msdu_head);
943 info.signal = ATH10K_DEFAULT_NOISE_FLOOR;
944 info.signal += rx->ppdu.combined_rssi;
945
946 info.rate.info0 = rx->ppdu.info0;
947 info.rate.info1 = __le32_to_cpu(rx->ppdu.info1);
948 info.rate.info2 = __le32_to_cpu(rx->ppdu.info2);
949
950 hdr = ath10k_htt_rx_skb_get_hdr(msdu_head);
951
952 if (ath10k_htt_rx_hdr_is_amsdu(hdr))
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300953 ath10k_htt_rx_amsdu(htt, &info);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300954 else
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300955 ath10k_htt_rx_msdu(htt, &info);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300956 }
957 }
958
959 ath10k_htt_rx_msdu_buff_replenish(htt);
960}
961
962static void ath10k_htt_rx_frag_handler(struct ath10k_htt *htt,
963 struct htt_rx_fragment_indication *frag)
964{
965 struct sk_buff *msdu_head, *msdu_tail;
966 struct htt_rx_desc *rxd;
967 enum rx_msdu_decap_format fmt;
968 struct htt_rx_info info = {};
969 struct ieee80211_hdr *hdr;
970 int msdu_chaining;
971 bool tkip_mic_err;
972 bool decrypt_err;
973 u8 *fw_desc;
974 int fw_desc_len, hdrlen, paramlen;
975 int trim;
976
977 fw_desc_len = __le16_to_cpu(frag->fw_rx_desc_bytes);
978 fw_desc = (u8 *)frag->fw_msdu_rx_desc;
979
980 msdu_head = NULL;
981 msdu_tail = NULL;
982 msdu_chaining = ath10k_htt_rx_amsdu_pop(htt, &fw_desc, &fw_desc_len,
983 &msdu_head, &msdu_tail);
984
985 ath10k_dbg(ATH10K_DBG_HTT_DUMP, "htt rx frag ahead\n");
986
987 if (!msdu_head) {
988 ath10k_warn("htt rx frag no data\n");
989 return;
990 }
991
992 if (msdu_chaining || msdu_head != msdu_tail) {
993 ath10k_warn("aggregation with fragmentation?!\n");
994 ath10k_htt_rx_free_msdu_chain(msdu_head);
995 return;
996 }
997
998 /* FIXME: implement signal strength */
999
1000 hdr = (struct ieee80211_hdr *)msdu_head->data;
1001 rxd = (void *)msdu_head->data - sizeof(*rxd);
1002 tkip_mic_err = !!(__le32_to_cpu(rxd->attention.flags) &
1003 RX_ATTENTION_FLAGS_TKIP_MIC_ERR);
1004 decrypt_err = !!(__le32_to_cpu(rxd->attention.flags) &
1005 RX_ATTENTION_FLAGS_DECRYPT_ERR);
1006 fmt = MS(__le32_to_cpu(rxd->msdu_start.info1),
1007 RX_MSDU_START_INFO1_DECAP_FORMAT);
1008
1009 if (fmt != RX_MSDU_DECAP_RAW) {
1010 ath10k_warn("we dont support non-raw fragmented rx yet\n");
1011 dev_kfree_skb_any(msdu_head);
1012 goto end;
1013 }
1014
1015 info.skb = msdu_head;
1016 info.status = HTT_RX_IND_MPDU_STATUS_OK;
1017 info.encrypt_type = MS(__le32_to_cpu(rxd->mpdu_start.info0),
1018 RX_MPDU_START_INFO0_ENCRYPT_TYPE);
Michal Kazior605f81a2013-07-31 10:47:56 +02001019 info.skb->ip_summed = ath10k_htt_rx_get_csum_state(info.skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001020
1021 if (tkip_mic_err) {
1022 ath10k_warn("tkip mic error\n");
1023 info.status = HTT_RX_IND_MPDU_STATUS_TKIP_MIC_ERR;
1024 }
1025
1026 if (decrypt_err) {
1027 ath10k_warn("decryption err in fragmented rx\n");
1028 dev_kfree_skb_any(info.skb);
1029 goto end;
1030 }
1031
1032 if (info.encrypt_type != HTT_RX_MPDU_ENCRYPT_NONE) {
1033 hdrlen = ieee80211_hdrlen(hdr->frame_control);
1034 paramlen = ath10k_htt_rx_crypto_param_len(info.encrypt_type);
1035
1036 /* It is more efficient to move the header than the payload */
1037 memmove((void *)info.skb->data + paramlen,
1038 (void *)info.skb->data,
1039 hdrlen);
1040 skb_pull(info.skb, paramlen);
1041 hdr = (struct ieee80211_hdr *)info.skb->data;
1042 }
1043
1044 /* remove trailing FCS */
1045 trim = 4;
1046
1047 /* remove crypto trailer */
1048 trim += ath10k_htt_rx_crypto_tail_len(info.encrypt_type);
1049
1050 /* last fragment of TKIP frags has MIC */
1051 if (!ieee80211_has_morefrags(hdr->frame_control) &&
1052 info.encrypt_type == HTT_RX_MPDU_ENCRYPT_TKIP_WPA)
1053 trim += 8;
1054
1055 if (trim > info.skb->len) {
1056 ath10k_warn("htt rx fragment: trailer longer than the frame itself? drop\n");
1057 dev_kfree_skb_any(info.skb);
1058 goto end;
1059 }
1060
1061 skb_trim(info.skb, info.skb->len - trim);
1062
1063 ath10k_dbg_dump(ATH10K_DBG_HTT_DUMP, NULL, "htt frag mpdu: ",
1064 info.skb->data, info.skb->len);
1065 ath10k_process_rx(htt->ar, &info);
1066
1067end:
1068 if (fw_desc_len > 0) {
1069 ath10k_dbg(ATH10K_DBG_HTT,
1070 "expecting more fragmented rx in one indication %d\n",
1071 fw_desc_len);
1072 }
1073}
1074
1075void ath10k_htt_t2h_msg_handler(struct ath10k *ar, struct sk_buff *skb)
1076{
Michal Kazioredb82362013-07-05 16:15:14 +03001077 struct ath10k_htt *htt = &ar->htt;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001078 struct htt_resp *resp = (struct htt_resp *)skb->data;
1079
1080 /* confirm alignment */
1081 if (!IS_ALIGNED((unsigned long)skb->data, 4))
1082 ath10k_warn("unaligned htt message, expect trouble\n");
1083
1084 ath10k_dbg(ATH10K_DBG_HTT, "HTT RX, msg_type: 0x%0X\n",
1085 resp->hdr.msg_type);
1086 switch (resp->hdr.msg_type) {
1087 case HTT_T2H_MSG_TYPE_VERSION_CONF: {
1088 htt->target_version_major = resp->ver_resp.major;
1089 htt->target_version_minor = resp->ver_resp.minor;
1090 complete(&htt->target_version_received);
1091 break;
1092 }
1093 case HTT_T2H_MSG_TYPE_RX_IND: {
1094 ath10k_htt_rx_handler(htt, &resp->rx_ind);
1095 break;
1096 }
1097 case HTT_T2H_MSG_TYPE_PEER_MAP: {
1098 struct htt_peer_map_event ev = {
1099 .vdev_id = resp->peer_map.vdev_id,
1100 .peer_id = __le16_to_cpu(resp->peer_map.peer_id),
1101 };
1102 memcpy(ev.addr, resp->peer_map.addr, sizeof(ev.addr));
1103 ath10k_peer_map_event(htt, &ev);
1104 break;
1105 }
1106 case HTT_T2H_MSG_TYPE_PEER_UNMAP: {
1107 struct htt_peer_unmap_event ev = {
1108 .peer_id = __le16_to_cpu(resp->peer_unmap.peer_id),
1109 };
1110 ath10k_peer_unmap_event(htt, &ev);
1111 break;
1112 }
1113 case HTT_T2H_MSG_TYPE_MGMT_TX_COMPLETION: {
1114 struct htt_tx_done tx_done = {};
1115 int status = __le32_to_cpu(resp->mgmt_tx_completion.status);
1116
1117 tx_done.msdu_id =
1118 __le32_to_cpu(resp->mgmt_tx_completion.desc_id);
1119
1120 switch (status) {
1121 case HTT_MGMT_TX_STATUS_OK:
1122 break;
1123 case HTT_MGMT_TX_STATUS_RETRY:
1124 tx_done.no_ack = true;
1125 break;
1126 case HTT_MGMT_TX_STATUS_DROP:
1127 tx_done.discard = true;
1128 break;
1129 }
1130
Michal Kazior0a89f8a2013-09-18 14:43:20 +02001131 ath10k_txrx_tx_unref(htt, &tx_done);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001132 break;
1133 }
1134 case HTT_T2H_MSG_TYPE_TX_COMPL_IND: {
1135 struct htt_tx_done tx_done = {};
1136 int status = MS(resp->data_tx_completion.flags,
1137 HTT_DATA_TX_STATUS);
1138 __le16 msdu_id;
1139 int i;
1140
1141 switch (status) {
1142 case HTT_DATA_TX_STATUS_NO_ACK:
1143 tx_done.no_ack = true;
1144 break;
1145 case HTT_DATA_TX_STATUS_OK:
1146 break;
1147 case HTT_DATA_TX_STATUS_DISCARD:
1148 case HTT_DATA_TX_STATUS_POSTPONE:
1149 case HTT_DATA_TX_STATUS_DOWNLOAD_FAIL:
1150 tx_done.discard = true;
1151 break;
1152 default:
1153 ath10k_warn("unhandled tx completion status %d\n",
1154 status);
1155 tx_done.discard = true;
1156 break;
1157 }
1158
1159 ath10k_dbg(ATH10K_DBG_HTT, "htt tx completion num_msdus %d\n",
1160 resp->data_tx_completion.num_msdus);
1161
1162 for (i = 0; i < resp->data_tx_completion.num_msdus; i++) {
1163 msdu_id = resp->data_tx_completion.msdus[i];
1164 tx_done.msdu_id = __le16_to_cpu(msdu_id);
Michal Kazior0a89f8a2013-09-18 14:43:20 +02001165 ath10k_txrx_tx_unref(htt, &tx_done);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001166 }
1167 break;
1168 }
1169 case HTT_T2H_MSG_TYPE_SEC_IND: {
1170 struct ath10k *ar = htt->ar;
1171 struct htt_security_indication *ev = &resp->security_indication;
1172
1173 ath10k_dbg(ATH10K_DBG_HTT,
1174 "sec ind peer_id %d unicast %d type %d\n",
1175 __le16_to_cpu(ev->peer_id),
1176 !!(ev->flags & HTT_SECURITY_IS_UNICAST),
1177 MS(ev->flags, HTT_SECURITY_TYPE));
1178 complete(&ar->install_key_done);
1179 break;
1180 }
1181 case HTT_T2H_MSG_TYPE_RX_FRAG_IND: {
1182 ath10k_dbg_dump(ATH10K_DBG_HTT_DUMP, NULL, "htt event: ",
1183 skb->data, skb->len);
1184 ath10k_htt_rx_frag_handler(htt, &resp->rx_frag_ind);
1185 break;
1186 }
1187 case HTT_T2H_MSG_TYPE_TEST:
1188 /* FIX THIS */
1189 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001190 case HTT_T2H_MSG_TYPE_STATS_CONF:
Kalle Valoa9bf0502013-09-03 11:43:55 +03001191 trace_ath10k_htt_stats(skb->data, skb->len);
1192 break;
1193 case HTT_T2H_MSG_TYPE_TX_INSPECT_IND:
Kalle Valo5e3dd152013-06-12 20:52:10 +03001194 case HTT_T2H_MSG_TYPE_RX_ADDBA:
1195 case HTT_T2H_MSG_TYPE_RX_DELBA:
1196 case HTT_T2H_MSG_TYPE_RX_FLUSH:
1197 default:
1198 ath10k_dbg(ATH10K_DBG_HTT, "htt event (%d) not handled\n",
1199 resp->hdr.msg_type);
1200 ath10k_dbg_dump(ATH10K_DBG_HTT_DUMP, NULL, "htt event: ",
1201 skb->data, skb->len);
1202 break;
1203 };
1204
1205 /* Free the indication buffer */
1206 dev_kfree_skb_any(skb);
1207}