blob: 64abc2ab604142e5e73775605de2c333cf577b1b [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);
Michal Kazior6c5151a2014-02-27 18:50:04 +020046static void ath10k_htt_txrx_compl_task(unsigned long ptr);
Michal Kaziorf6dc2092013-09-26 10:12:22 +030047
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{
Michal Kazior6e712d42013-09-24 10:18:36 +0200185 int ret, num_deficit, num_to_fill;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300186
Michal Kazior6e712d42013-09-24 10:18:36 +0200187 /* Refilling the whole RX ring buffer proves to be a bad idea. The
188 * reason is RX may take up significant amount of CPU cycles and starve
189 * other tasks, e.g. TX on an ethernet device while acting as a bridge
190 * with ath10k wlan interface. This ended up with very poor performance
191 * once CPU the host system was overwhelmed with RX on ath10k.
192 *
193 * By limiting the number of refills the replenishing occurs
194 * progressively. This in turns makes use of the fact tasklets are
195 * processed in FIFO order. This means actual RX processing can starve
196 * out refilling. If there's not enough buffers on RX ring FW will not
197 * report RX until it is refilled with enough buffers. This
198 * automatically balances load wrt to CPU power.
199 *
200 * This probably comes at a cost of lower maximum throughput but
201 * improves the avarage and stability. */
Kalle Valo5e3dd152013-06-12 20:52:10 +0300202 spin_lock_bh(&htt->rx_ring.lock);
Michal Kazior6e712d42013-09-24 10:18:36 +0200203 num_deficit = htt->rx_ring.fill_level - htt->rx_ring.fill_cnt;
204 num_to_fill = min(ATH10K_HTT_MAX_NUM_REFILL, num_deficit);
205 num_deficit -= num_to_fill;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300206 ret = ath10k_htt_rx_ring_fill_n(htt, num_to_fill);
207 if (ret == -ENOMEM) {
208 /*
209 * Failed to fill it to the desired level -
210 * we'll start a timer and try again next time.
211 * As long as enough buffers are left in the ring for
212 * another A-MPDU rx, no special recovery is needed.
213 */
214 mod_timer(&htt->rx_ring.refill_retry_timer, jiffies +
215 msecs_to_jiffies(HTT_RX_RING_REFILL_RETRY_MS));
Michal Kazior6e712d42013-09-24 10:18:36 +0200216 } else if (num_deficit > 0) {
217 tasklet_schedule(&htt->rx_replenish_task);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300218 }
219 spin_unlock_bh(&htt->rx_ring.lock);
220}
221
222static void ath10k_htt_rx_ring_refill_retry(unsigned long arg)
223{
224 struct ath10k_htt *htt = (struct ath10k_htt *)arg;
225 ath10k_htt_rx_msdu_buff_replenish(htt);
226}
227
Kalle Valo5e3dd152013-06-12 20:52:10 +0300228void ath10k_htt_rx_detach(struct ath10k_htt *htt)
229{
230 int sw_rd_idx = htt->rx_ring.sw_rd_idx.msdu_payld;
231
232 del_timer_sync(&htt->rx_ring.refill_retry_timer);
Michal Kazior6e712d42013-09-24 10:18:36 +0200233 tasklet_kill(&htt->rx_replenish_task);
Michal Kazior6c5151a2014-02-27 18:50:04 +0200234 tasklet_kill(&htt->txrx_compl_task);
235
236 skb_queue_purge(&htt->tx_compl_q);
237 skb_queue_purge(&htt->rx_compl_q);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300238
239 while (sw_rd_idx != __le32_to_cpu(*(htt->rx_ring.alloc_idx.vaddr))) {
240 struct sk_buff *skb =
241 htt->rx_ring.netbufs_ring[sw_rd_idx];
242 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
243
244 dma_unmap_single(htt->ar->dev, cb->paddr,
245 skb->len + skb_tailroom(skb),
246 DMA_FROM_DEVICE);
247 dev_kfree_skb_any(htt->rx_ring.netbufs_ring[sw_rd_idx]);
248 sw_rd_idx++;
249 sw_rd_idx &= htt->rx_ring.size_mask;
250 }
251
252 dma_free_coherent(htt->ar->dev,
253 (htt->rx_ring.size *
254 sizeof(htt->rx_ring.paddrs_ring)),
255 htt->rx_ring.paddrs_ring,
256 htt->rx_ring.base_paddr);
257
258 dma_free_coherent(htt->ar->dev,
259 sizeof(*htt->rx_ring.alloc_idx.vaddr),
260 htt->rx_ring.alloc_idx.vaddr,
261 htt->rx_ring.alloc_idx.paddr);
262
263 kfree(htt->rx_ring.netbufs_ring);
264}
265
266static inline struct sk_buff *ath10k_htt_rx_netbuf_pop(struct ath10k_htt *htt)
267{
268 int idx;
269 struct sk_buff *msdu;
270
Michal Kazior45967082014-02-27 18:50:05 +0200271 lockdep_assert_held(&htt->rx_ring.lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300272
Michal Kazior8d60ee82014-02-27 18:50:05 +0200273 if (htt->rx_ring.fill_cnt == 0) {
274 ath10k_warn("tried to pop sk_buff from an empty rx ring\n");
275 return NULL;
276 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300277
278 idx = htt->rx_ring.sw_rd_idx.msdu_payld;
279 msdu = htt->rx_ring.netbufs_ring[idx];
280
281 idx++;
282 idx &= htt->rx_ring.size_mask;
283 htt->rx_ring.sw_rd_idx.msdu_payld = idx;
284 htt->rx_ring.fill_cnt--;
285
Kalle Valo5e3dd152013-06-12 20:52:10 +0300286 return msdu;
287}
288
289static void ath10k_htt_rx_free_msdu_chain(struct sk_buff *skb)
290{
291 struct sk_buff *next;
292
293 while (skb) {
294 next = skb->next;
295 dev_kfree_skb_any(skb);
296 skb = next;
297 }
298}
299
Janusz Dziedzicd84dd602014-03-24 21:23:20 +0100300/* return: < 0 fatal error, 0 - non chained msdu, 1 chained msdu */
Kalle Valo5e3dd152013-06-12 20:52:10 +0300301static int ath10k_htt_rx_amsdu_pop(struct ath10k_htt *htt,
302 u8 **fw_desc, int *fw_desc_len,
303 struct sk_buff **head_msdu,
304 struct sk_buff **tail_msdu)
305{
306 int msdu_len, msdu_chaining = 0;
307 struct sk_buff *msdu;
308 struct htt_rx_desc *rx_desc;
309
Michal Kazior45967082014-02-27 18:50:05 +0200310 lockdep_assert_held(&htt->rx_ring.lock);
311
Kalle Valo5e3dd152013-06-12 20:52:10 +0300312 if (htt->rx_confused) {
313 ath10k_warn("htt is confused. refusing rx\n");
Janusz Dziedzicd84dd602014-03-24 21:23:20 +0100314 return -1;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300315 }
316
317 msdu = *head_msdu = ath10k_htt_rx_netbuf_pop(htt);
318 while (msdu) {
319 int last_msdu, msdu_len_invalid, msdu_chained;
320
321 dma_unmap_single(htt->ar->dev,
322 ATH10K_SKB_CB(msdu)->paddr,
323 msdu->len + skb_tailroom(msdu),
324 DMA_FROM_DEVICE);
325
Ben Greear75fb2f92014-02-05 13:58:34 -0800326 ath10k_dbg_dump(ATH10K_DBG_HTT_DUMP, NULL, "htt rx pop: ",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300327 msdu->data, msdu->len + skb_tailroom(msdu));
328
329 rx_desc = (struct htt_rx_desc *)msdu->data;
330
331 /* FIXME: we must report msdu payload since this is what caller
332 * expects now */
333 skb_put(msdu, offsetof(struct htt_rx_desc, msdu_payload));
334 skb_pull(msdu, offsetof(struct htt_rx_desc, msdu_payload));
335
336 /*
337 * Sanity check - confirm the HW is finished filling in the
338 * rx data.
339 * If the HW and SW are working correctly, then it's guaranteed
340 * that the HW's MAC DMA is done before this point in the SW.
341 * To prevent the case that we handle a stale Rx descriptor,
342 * just assert for now until we have a way to recover.
343 */
344 if (!(__le32_to_cpu(rx_desc->attention.flags)
345 & RX_ATTENTION_FLAGS_MSDU_DONE)) {
346 ath10k_htt_rx_free_msdu_chain(*head_msdu);
347 *head_msdu = NULL;
348 msdu = NULL;
349 ath10k_err("htt rx stopped. cannot recover\n");
350 htt->rx_confused = true;
351 break;
352 }
353
354 /*
355 * Copy the FW rx descriptor for this MSDU from the rx
356 * indication message into the MSDU's netbuf. HL uses the
357 * same rx indication message definition as LL, and simply
358 * appends new info (fields from the HW rx desc, and the
359 * MSDU payload itself). So, the offset into the rx
360 * indication message only has to account for the standard
361 * offset of the per-MSDU FW rx desc info within the
362 * message, and how many bytes of the per-MSDU FW rx desc
363 * info have already been consumed. (And the endianness of
364 * the host, since for a big-endian host, the rx ind
365 * message contents, including the per-MSDU rx desc bytes,
366 * were byteswapped during upload.)
367 */
368 if (*fw_desc_len > 0) {
369 rx_desc->fw_desc.info0 = **fw_desc;
370 /*
371 * The target is expected to only provide the basic
372 * per-MSDU rx descriptors. Just to be sure, verify
373 * that the target has not attached extension data
374 * (e.g. LRO flow ID).
375 */
376
377 /* or more, if there's extension data */
378 (*fw_desc)++;
379 (*fw_desc_len)--;
380 } else {
381 /*
382 * When an oversized AMSDU happened, FW will lost
383 * some of MSDU status - in this case, the FW
384 * descriptors provided will be less than the
385 * actual MSDUs inside this MPDU. Mark the FW
386 * descriptors so that it will still deliver to
387 * upper stack, if no CRC error for this MPDU.
388 *
389 * FIX THIS - the FW descriptors are actually for
390 * MSDUs in the end of this A-MSDU instead of the
391 * beginning.
392 */
393 rx_desc->fw_desc.info0 = 0;
394 }
395
396 msdu_len_invalid = !!(__le32_to_cpu(rx_desc->attention.flags)
397 & (RX_ATTENTION_FLAGS_MPDU_LENGTH_ERR |
398 RX_ATTENTION_FLAGS_MSDU_LENGTH_ERR));
399 msdu_len = MS(__le32_to_cpu(rx_desc->msdu_start.info0),
400 RX_MSDU_START_INFO0_MSDU_LENGTH);
401 msdu_chained = rx_desc->frag_info.ring2_more_count;
Ben Greearbfa35362014-03-03 14:07:09 -0800402 msdu_chaining = msdu_chained;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300403
404 if (msdu_len_invalid)
405 msdu_len = 0;
406
407 skb_trim(msdu, 0);
408 skb_put(msdu, min(msdu_len, HTT_RX_MSDU_SIZE));
409 msdu_len -= msdu->len;
410
411 /* FIXME: Do chained buffers include htt_rx_desc or not? */
412 while (msdu_chained--) {
413 struct sk_buff *next = ath10k_htt_rx_netbuf_pop(htt);
414
415 dma_unmap_single(htt->ar->dev,
416 ATH10K_SKB_CB(next)->paddr,
417 next->len + skb_tailroom(next),
418 DMA_FROM_DEVICE);
419
Ben Greear75fb2f92014-02-05 13:58:34 -0800420 ath10k_dbg_dump(ATH10K_DBG_HTT_DUMP, NULL,
421 "htt rx chained: ", next->data,
Kalle Valo5e3dd152013-06-12 20:52:10 +0300422 next->len + skb_tailroom(next));
423
424 skb_trim(next, 0);
425 skb_put(next, min(msdu_len, HTT_RX_BUF_SIZE));
426 msdu_len -= next->len;
427
428 msdu->next = next;
429 msdu = next;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300430 }
431
Kalle Valo5e3dd152013-06-12 20:52:10 +0300432 last_msdu = __le32_to_cpu(rx_desc->msdu_end.info0) &
433 RX_MSDU_END_INFO0_LAST_MSDU;
434
435 if (last_msdu) {
436 msdu->next = NULL;
437 break;
438 } else {
439 struct sk_buff *next = ath10k_htt_rx_netbuf_pop(htt);
440 msdu->next = next;
441 msdu = next;
442 }
443 }
444 *tail_msdu = msdu;
445
Janusz Dziedzicd84dd602014-03-24 21:23:20 +0100446 if (*head_msdu == NULL)
447 msdu_chaining = -1;
448
Kalle Valo5e3dd152013-06-12 20:52:10 +0300449 /*
450 * Don't refill the ring yet.
451 *
452 * First, the elements popped here are still in use - it is not
453 * safe to overwrite them until the matching call to
454 * mpdu_desc_list_next. Second, for efficiency it is preferable to
455 * refill the rx ring with 1 PPDU's worth of rx buffers (something
456 * like 32 x 3 buffers), rather than one MPDU's worth of rx buffers
457 * (something like 3 buffers). Consequently, we'll rely on the txrx
458 * SW to tell us when it is done pulling all the PPDU's rx buffers
459 * out of the rx ring, and then refill it just once.
460 */
461
462 return msdu_chaining;
463}
464
Michal Kazior6e712d42013-09-24 10:18:36 +0200465static void ath10k_htt_rx_replenish_task(unsigned long ptr)
466{
467 struct ath10k_htt *htt = (struct ath10k_htt *)ptr;
468 ath10k_htt_rx_msdu_buff_replenish(htt);
469}
470
Kalle Valo5e3dd152013-06-12 20:52:10 +0300471int ath10k_htt_rx_attach(struct ath10k_htt *htt)
472{
473 dma_addr_t paddr;
474 void *vaddr;
475 struct timer_list *timer = &htt->rx_ring.refill_retry_timer;
476
477 htt->rx_ring.size = ath10k_htt_rx_ring_size(htt);
478 if (!is_power_of_2(htt->rx_ring.size)) {
479 ath10k_warn("htt rx ring size is not power of 2\n");
480 return -EINVAL;
481 }
482
483 htt->rx_ring.size_mask = htt->rx_ring.size - 1;
484
485 /*
486 * Set the initial value for the level to which the rx ring
487 * should be filled, based on the max throughput and the
488 * worst likely latency for the host to fill the rx ring
489 * with new buffers. In theory, this fill level can be
490 * dynamically adjusted from the initial value set here, to
491 * reflect the actual host latency rather than a
492 * conservative assumption about the host latency.
493 */
494 htt->rx_ring.fill_level = ath10k_htt_rx_ring_fill_level(htt);
495
496 htt->rx_ring.netbufs_ring =
497 kmalloc(htt->rx_ring.size * sizeof(struct sk_buff *),
498 GFP_KERNEL);
499 if (!htt->rx_ring.netbufs_ring)
500 goto err_netbuf;
501
502 vaddr = dma_alloc_coherent(htt->ar->dev,
503 (htt->rx_ring.size * sizeof(htt->rx_ring.paddrs_ring)),
504 &paddr, GFP_DMA);
505 if (!vaddr)
506 goto err_dma_ring;
507
508 htt->rx_ring.paddrs_ring = vaddr;
509 htt->rx_ring.base_paddr = paddr;
510
511 vaddr = dma_alloc_coherent(htt->ar->dev,
512 sizeof(*htt->rx_ring.alloc_idx.vaddr),
513 &paddr, GFP_DMA);
514 if (!vaddr)
515 goto err_dma_idx;
516
517 htt->rx_ring.alloc_idx.vaddr = vaddr;
518 htt->rx_ring.alloc_idx.paddr = paddr;
519 htt->rx_ring.sw_rd_idx.msdu_payld = 0;
520 *htt->rx_ring.alloc_idx.vaddr = 0;
521
522 /* Initialize the Rx refill retry timer */
523 setup_timer(timer, ath10k_htt_rx_ring_refill_retry, (unsigned long)htt);
524
525 spin_lock_init(&htt->rx_ring.lock);
526
527 htt->rx_ring.fill_cnt = 0;
528 if (__ath10k_htt_rx_ring_fill_n(htt, htt->rx_ring.fill_level))
529 goto err_fill_ring;
530
Michal Kazior6e712d42013-09-24 10:18:36 +0200531 tasklet_init(&htt->rx_replenish_task, ath10k_htt_rx_replenish_task,
532 (unsigned long)htt);
533
Michal Kazior6c5151a2014-02-27 18:50:04 +0200534 skb_queue_head_init(&htt->tx_compl_q);
535 skb_queue_head_init(&htt->rx_compl_q);
536
537 tasklet_init(&htt->txrx_compl_task, ath10k_htt_txrx_compl_task,
538 (unsigned long)htt);
539
Kalle Valoaad0b652013-09-08 17:56:02 +0300540 ath10k_dbg(ATH10K_DBG_BOOT, "htt rx ring size %d fill_level %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300541 htt->rx_ring.size, htt->rx_ring.fill_level);
542 return 0;
543
544err_fill_ring:
545 ath10k_htt_rx_ring_free(htt);
546 dma_free_coherent(htt->ar->dev,
547 sizeof(*htt->rx_ring.alloc_idx.vaddr),
548 htt->rx_ring.alloc_idx.vaddr,
549 htt->rx_ring.alloc_idx.paddr);
550err_dma_idx:
551 dma_free_coherent(htt->ar->dev,
552 (htt->rx_ring.size *
553 sizeof(htt->rx_ring.paddrs_ring)),
554 htt->rx_ring.paddrs_ring,
555 htt->rx_ring.base_paddr);
556err_dma_ring:
557 kfree(htt->rx_ring.netbufs_ring);
558err_netbuf:
559 return -ENOMEM;
560}
561
562static int ath10k_htt_rx_crypto_param_len(enum htt_rx_mpdu_encrypt_type type)
563{
564 switch (type) {
565 case HTT_RX_MPDU_ENCRYPT_WEP40:
566 case HTT_RX_MPDU_ENCRYPT_WEP104:
567 return 4;
568 case HTT_RX_MPDU_ENCRYPT_TKIP_WITHOUT_MIC:
569 case HTT_RX_MPDU_ENCRYPT_WEP128: /* not tested */
570 case HTT_RX_MPDU_ENCRYPT_TKIP_WPA:
571 case HTT_RX_MPDU_ENCRYPT_WAPI: /* not tested */
572 case HTT_RX_MPDU_ENCRYPT_AES_CCM_WPA2:
573 return 8;
574 case HTT_RX_MPDU_ENCRYPT_NONE:
575 return 0;
576 }
577
578 ath10k_warn("unknown encryption type %d\n", type);
579 return 0;
580}
581
582static int ath10k_htt_rx_crypto_tail_len(enum htt_rx_mpdu_encrypt_type type)
583{
584 switch (type) {
585 case HTT_RX_MPDU_ENCRYPT_NONE:
586 case HTT_RX_MPDU_ENCRYPT_WEP40:
587 case HTT_RX_MPDU_ENCRYPT_WEP104:
588 case HTT_RX_MPDU_ENCRYPT_WEP128:
589 case HTT_RX_MPDU_ENCRYPT_WAPI:
590 return 0;
591 case HTT_RX_MPDU_ENCRYPT_TKIP_WITHOUT_MIC:
592 case HTT_RX_MPDU_ENCRYPT_TKIP_WPA:
593 return 4;
594 case HTT_RX_MPDU_ENCRYPT_AES_CCM_WPA2:
595 return 8;
596 }
597
598 ath10k_warn("unknown encryption type %d\n", type);
599 return 0;
600}
601
602/* Applies for first msdu in chain, before altering it. */
603static struct ieee80211_hdr *ath10k_htt_rx_skb_get_hdr(struct sk_buff *skb)
604{
605 struct htt_rx_desc *rxd;
606 enum rx_msdu_decap_format fmt;
607
608 rxd = (void *)skb->data - sizeof(*rxd);
609 fmt = MS(__le32_to_cpu(rxd->msdu_start.info1),
610 RX_MSDU_START_INFO1_DECAP_FORMAT);
611
612 if (fmt == RX_MSDU_DECAP_RAW)
613 return (void *)skb->data;
614 else
615 return (void *)skb->data - RX_HTT_HDR_STATUS_LEN;
616}
617
618/* This function only applies for first msdu in an msdu chain */
619static bool ath10k_htt_rx_hdr_is_amsdu(struct ieee80211_hdr *hdr)
620{
621 if (ieee80211_is_data_qos(hdr->frame_control)) {
622 u8 *qc = ieee80211_get_qos_ctl(hdr);
623 if (qc[0] & 0x80)
624 return true;
625 }
626 return false;
627}
628
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300629struct rfc1042_hdr {
630 u8 llc_dsap;
631 u8 llc_ssap;
632 u8 llc_ctrl;
633 u8 snap_oui[3];
634 __be16 snap_type;
635} __packed;
636
637struct amsdu_subframe_hdr {
638 u8 dst[ETH_ALEN];
639 u8 src[ETH_ALEN];
640 __be16 len;
641} __packed;
642
Janusz Dziedzic73539b42014-03-24 21:23:15 +0100643static const u8 rx_legacy_rate_idx[] = {
644 3, /* 0x00 - 11Mbps */
645 2, /* 0x01 - 5.5Mbps */
646 1, /* 0x02 - 2Mbps */
647 0, /* 0x03 - 1Mbps */
648 3, /* 0x04 - 11Mbps */
649 2, /* 0x05 - 5.5Mbps */
650 1, /* 0x06 - 2Mbps */
651 0, /* 0x07 - 1Mbps */
652 10, /* 0x08 - 48Mbps */
653 8, /* 0x09 - 24Mbps */
654 6, /* 0x0A - 12Mbps */
655 4, /* 0x0B - 6Mbps */
656 11, /* 0x0C - 54Mbps */
657 9, /* 0x0D - 36Mbps */
658 7, /* 0x0E - 18Mbps */
659 5, /* 0x0F - 9Mbps */
660};
661
Janusz Dziedzic87326c92014-03-24 21:23:19 +0100662static void ath10k_htt_rx_h_rates(struct ath10k *ar,
Janusz Dziedziccfadd9b2014-03-24 21:23:16 +0100663 enum ieee80211_band band,
Janusz Dziedzic87326c92014-03-24 21:23:19 +0100664 u8 info0, u32 info1, u32 info2,
Janusz Dziedziccfadd9b2014-03-24 21:23:16 +0100665 struct ieee80211_rx_status *status)
Janusz Dziedzic73539b42014-03-24 21:23:15 +0100666{
667 u8 cck, rate, rate_idx, bw, sgi, mcs, nss;
Janusz Dziedzic73539b42014-03-24 21:23:15 +0100668 u8 preamble = 0;
669
670 /* Check if valid fields */
671 if (!(info0 & HTT_RX_INDICATION_INFO0_START_VALID))
672 return;
673
674 preamble = MS(info1, HTT_RX_INDICATION_INFO1_PREAMBLE_TYPE);
675
676 switch (preamble) {
677 case HTT_RX_LEGACY:
678 cck = info0 & HTT_RX_INDICATION_INFO0_LEGACY_RATE_CCK;
679 rate = MS(info0, HTT_RX_INDICATION_INFO0_LEGACY_RATE);
680 rate_idx = 0;
681
682 if (rate < 0x08 || rate > 0x0F)
683 break;
684
685 switch (band) {
686 case IEEE80211_BAND_2GHZ:
687 if (cck)
688 rate &= ~BIT(3);
689 rate_idx = rx_legacy_rate_idx[rate];
690 break;
691 case IEEE80211_BAND_5GHZ:
692 rate_idx = rx_legacy_rate_idx[rate];
693 /* We are using same rate table registering
694 HW - ath10k_rates[]. In case of 5GHz skip
695 CCK rates, so -4 here */
696 rate_idx -= 4;
697 break;
698 default:
699 break;
700 }
701
702 status->rate_idx = rate_idx;
703 break;
704 case HTT_RX_HT:
705 case HTT_RX_HT_WITH_TXBF:
706 /* HT-SIG - Table 20-11 in info1 and info2 */
707 mcs = info1 & 0x1F;
708 nss = mcs >> 3;
709 bw = (info1 >> 7) & 1;
710 sgi = (info2 >> 7) & 1;
711
712 status->rate_idx = mcs;
713 status->flag |= RX_FLAG_HT;
714 if (sgi)
715 status->flag |= RX_FLAG_SHORT_GI;
716 if (bw)
717 status->flag |= RX_FLAG_40MHZ;
718 break;
719 case HTT_RX_VHT:
720 case HTT_RX_VHT_WITH_TXBF:
721 /* VHT-SIG-A1 in info 1, VHT-SIG-A2 in info2
722 TODO check this */
723 mcs = (info2 >> 4) & 0x0F;
724 nss = ((info1 >> 10) & 0x07) + 1;
725 bw = info1 & 3;
726 sgi = info2 & 1;
727
728 status->rate_idx = mcs;
729 status->vht_nss = nss;
730
731 if (sgi)
732 status->flag |= RX_FLAG_SHORT_GI;
733
734 switch (bw) {
735 /* 20MHZ */
736 case 0:
737 break;
738 /* 40MHZ */
739 case 1:
740 status->flag |= RX_FLAG_40MHZ;
741 break;
742 /* 80MHZ */
743 case 2:
744 status->vht_flag |= RX_VHT_FLAG_80MHZ;
745 }
746
747 status->flag |= RX_FLAG_VHT;
748 break;
749 default:
750 break;
751 }
752}
753
Janusz Dziedzic87326c92014-03-24 21:23:19 +0100754static void ath10k_htt_rx_h_protected(struct ath10k_htt *htt,
755 struct htt_rx_info *info,
756 enum htt_rx_mpdu_encrypt_type enctype)
757{
758 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)info->skb->data;
759
760
761 if (enctype == HTT_RX_MPDU_ENCRYPT_NONE) {
762 info->rx_status.flag &= ~(RX_FLAG_DECRYPTED |
763 RX_FLAG_IV_STRIPPED |
764 RX_FLAG_MMIC_STRIPPED);
765 return;
766 }
767
768 info->rx_status.flag |= RX_FLAG_DECRYPTED |
769 RX_FLAG_IV_STRIPPED |
770 RX_FLAG_MMIC_STRIPPED;
771 hdr->frame_control = __cpu_to_le16(__le16_to_cpu(hdr->frame_control) &
772 ~IEEE80211_FCTL_PROTECTED);
773}
774
Janusz Dziedzic36653f02014-03-24 21:23:18 +0100775static bool ath10k_htt_rx_h_channel(struct ath10k *ar,
776 struct ieee80211_rx_status *status)
777{
778 struct ieee80211_channel *ch;
779
780 spin_lock_bh(&ar->data_lock);
781 ch = ar->scan_channel;
782 if (!ch)
783 ch = ar->rx_channel;
784 spin_unlock_bh(&ar->data_lock);
785
786 if (!ch)
787 return false;
788
789 status->band = ch->band;
790 status->freq = ch->center_freq;
791
792 return true;
793}
794
Janusz Dziedzic73539b42014-03-24 21:23:15 +0100795static void ath10k_process_rx(struct ath10k *ar, struct htt_rx_info *info)
796{
797 struct ieee80211_rx_status *status;
Janusz Dziedzic73539b42014-03-24 21:23:15 +0100798
799 status = IEEE80211_SKB_RXCB(info->skb);
Janusz Dziedzic8f739db2014-03-24 21:23:17 +0100800 memcpy(status, &info->rx_status, sizeof(*status));
Janusz Dziedzic73539b42014-03-24 21:23:15 +0100801
Janusz Dziedzic73539b42014-03-24 21:23:15 +0100802 ath10k_dbg(ATH10K_DBG_DATA,
803 "rx skb %p len %u %s%s%s%s%s %srate_idx %u vht_nss %u freq %u band %u flag 0x%x fcs-err %i\n",
804 info->skb,
805 info->skb->len,
806 status->flag == 0 ? "legacy" : "",
807 status->flag & RX_FLAG_HT ? "ht" : "",
808 status->flag & RX_FLAG_VHT ? "vht" : "",
809 status->flag & RX_FLAG_40MHZ ? "40" : "",
810 status->vht_flag & RX_VHT_FLAG_80MHZ ? "80" : "",
811 status->flag & RX_FLAG_SHORT_GI ? "sgi " : "",
812 status->rate_idx,
813 status->vht_nss,
814 status->freq,
Janusz Dziedzic87326c92014-03-24 21:23:19 +0100815 status->band, status->flag,
816 !!(status->flag & RX_FLAG_FAILED_FCS_CRC));
Janusz Dziedzic73539b42014-03-24 21:23:15 +0100817 ath10k_dbg_dump(ATH10K_DBG_HTT_DUMP, NULL, "rx skb: ",
818 info->skb->data, info->skb->len);
819
820 ieee80211_rx(ar->hw, info->skb);
821}
822
Michal Kaziord960c362014-02-25 09:29:57 +0200823static int ath10k_htt_rx_nwifi_hdrlen(struct ieee80211_hdr *hdr)
824{
825 /* nwifi header is padded to 4 bytes. this fixes 4addr rx */
826 return round_up(ieee80211_hdrlen(hdr->frame_control), 4);
827}
828
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300829static void ath10k_htt_rx_amsdu(struct ath10k_htt *htt,
830 struct htt_rx_info *info)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300831{
832 struct htt_rx_desc *rxd;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300833 struct sk_buff *first;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300834 struct sk_buff *skb = info->skb;
835 enum rx_msdu_decap_format fmt;
836 enum htt_rx_mpdu_encrypt_type enctype;
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300837 struct ieee80211_hdr *hdr;
Michal Kazior784f69d2013-09-26 10:12:23 +0300838 u8 hdr_buf[64], addr[ETH_ALEN], *qos;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300839 unsigned int hdr_len;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300840
841 rxd = (void *)skb->data - sizeof(*rxd);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300842 enctype = MS(__le32_to_cpu(rxd->mpdu_start.info0),
843 RX_MPDU_START_INFO0_ENCRYPT_TYPE);
844
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300845 hdr = (struct ieee80211_hdr *)rxd->rx_hdr_status;
846 hdr_len = ieee80211_hdrlen(hdr->frame_control);
847 memcpy(hdr_buf, hdr, hdr_len);
848 hdr = (struct ieee80211_hdr *)hdr_buf;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300849
Kalle Valo5e3dd152013-06-12 20:52:10 +0300850 first = skb;
851 while (skb) {
852 void *decap_hdr;
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300853 int len;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300854
855 rxd = (void *)skb->data - sizeof(*rxd);
856 fmt = MS(__le32_to_cpu(rxd->msdu_start.info1),
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300857 RX_MSDU_START_INFO1_DECAP_FORMAT);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300858 decap_hdr = (void *)rxd->rx_hdr_status;
859
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300860 skb->ip_summed = ath10k_htt_rx_get_csum_state(skb);
861
862 /* First frame in an A-MSDU chain has more decapped data. */
Kalle Valo5e3dd152013-06-12 20:52:10 +0300863 if (skb == first) {
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300864 len = round_up(ieee80211_hdrlen(hdr->frame_control), 4);
865 len += round_up(ath10k_htt_rx_crypto_param_len(enctype),
866 4);
867 decap_hdr += len;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300868 }
869
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300870 switch (fmt) {
871 case RX_MSDU_DECAP_RAW:
Michal Kaziore3fbf8d2013-09-26 10:12:23 +0300872 /* remove trailing FCS */
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300873 skb_trim(skb, skb->len - FCS_LEN);
874 break;
875 case RX_MSDU_DECAP_NATIVE_WIFI:
Michal Kazior784f69d2013-09-26 10:12:23 +0300876 /* pull decapped header and copy DA */
877 hdr = (struct ieee80211_hdr *)skb->data;
Michal Kaziord960c362014-02-25 09:29:57 +0200878 hdr_len = ath10k_htt_rx_nwifi_hdrlen(hdr);
Michal Kazior784f69d2013-09-26 10:12:23 +0300879 memcpy(addr, ieee80211_get_DA(hdr), ETH_ALEN);
880 skb_pull(skb, hdr_len);
881
882 /* push original 802.11 header */
883 hdr = (struct ieee80211_hdr *)hdr_buf;
884 hdr_len = ieee80211_hdrlen(hdr->frame_control);
885 memcpy(skb_push(skb, hdr_len), hdr, hdr_len);
886
887 /* original A-MSDU header has the bit set but we're
888 * not including A-MSDU subframe header */
889 hdr = (struct ieee80211_hdr *)skb->data;
890 qos = ieee80211_get_qos_ctl(hdr);
891 qos[0] &= ~IEEE80211_QOS_CTL_A_MSDU_PRESENT;
892
893 /* original 802.11 header has a different DA */
894 memcpy(ieee80211_get_DA(hdr), addr, ETH_ALEN);
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300895 break;
896 case RX_MSDU_DECAP_ETHERNET2_DIX:
Michal Kaziore3fbf8d2013-09-26 10:12:23 +0300897 /* strip ethernet header and insert decapped 802.11
898 * header, amsdu subframe header and rfc1042 header */
899
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300900 len = 0;
901 len += sizeof(struct rfc1042_hdr);
902 len += sizeof(struct amsdu_subframe_hdr);
Michal Kaziordfa95b52013-08-13 07:59:37 +0200903
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300904 skb_pull(skb, sizeof(struct ethhdr));
905 memcpy(skb_push(skb, len), decap_hdr, len);
906 memcpy(skb_push(skb, hdr_len), hdr, hdr_len);
907 break;
908 case RX_MSDU_DECAP_8023_SNAP_LLC:
Michal Kaziore3fbf8d2013-09-26 10:12:23 +0300909 /* insert decapped 802.11 header making a singly
910 * A-MSDU */
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300911 memcpy(skb_push(skb, hdr_len), hdr, hdr_len);
912 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300913 }
914
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300915 info->skb = skb;
Janusz Dziedzic87326c92014-03-24 21:23:19 +0100916 ath10k_htt_rx_h_protected(htt, info, enctype);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300917 skb = skb->next;
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300918 info->skb->next = NULL;
919
Kalle Valo652de352013-11-13 15:23:30 +0200920 if (skb)
Janusz Dziedzic87326c92014-03-24 21:23:19 +0100921 info->rx_status.flag |= RX_FLAG_AMSDU_MORE;
922 else
923 info->rx_status.flag &= ~RX_FLAG_AMSDU_MORE;
Kalle Valo652de352013-11-13 15:23:30 +0200924
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300925 ath10k_process_rx(htt->ar, info);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300926 }
927
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300928 /* FIXME: It might be nice to re-assemble the A-MSDU when there's a
929 * monitor interface active for sniffing purposes. */
Kalle Valo5e3dd152013-06-12 20:52:10 +0300930}
931
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300932static void ath10k_htt_rx_msdu(struct ath10k_htt *htt, struct htt_rx_info *info)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300933{
934 struct sk_buff *skb = info->skb;
935 struct htt_rx_desc *rxd;
936 struct ieee80211_hdr *hdr;
937 enum rx_msdu_decap_format fmt;
938 enum htt_rx_mpdu_encrypt_type enctype;
Michal Kaziore3fbf8d2013-09-26 10:12:23 +0300939 int hdr_len;
940 void *rfc1042;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300941
942 /* This shouldn't happen. If it does than it may be a FW bug. */
943 if (skb->next) {
Ben Greear75fb2f92014-02-05 13:58:34 -0800944 ath10k_warn("htt rx received chained non A-MSDU frame\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +0300945 ath10k_htt_rx_free_msdu_chain(skb->next);
946 skb->next = NULL;
947 }
948
949 rxd = (void *)skb->data - sizeof(*rxd);
950 fmt = MS(__le32_to_cpu(rxd->msdu_start.info1),
951 RX_MSDU_START_INFO1_DECAP_FORMAT);
952 enctype = MS(__le32_to_cpu(rxd->mpdu_start.info0),
953 RX_MPDU_START_INFO0_ENCRYPT_TYPE);
Michal Kaziore3fbf8d2013-09-26 10:12:23 +0300954 hdr = (struct ieee80211_hdr *)rxd->rx_hdr_status;
955 hdr_len = ieee80211_hdrlen(hdr->frame_control);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300956
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300957 skb->ip_summed = ath10k_htt_rx_get_csum_state(skb);
958
Kalle Valo5e3dd152013-06-12 20:52:10 +0300959 switch (fmt) {
960 case RX_MSDU_DECAP_RAW:
961 /* remove trailing FCS */
Michal Kaziore3fbf8d2013-09-26 10:12:23 +0300962 skb_trim(skb, skb->len - FCS_LEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300963 break;
964 case RX_MSDU_DECAP_NATIVE_WIFI:
Michal Kazior784f69d2013-09-26 10:12:23 +0300965 /* Pull decapped header */
966 hdr = (struct ieee80211_hdr *)skb->data;
Michal Kaziord960c362014-02-25 09:29:57 +0200967 hdr_len = ath10k_htt_rx_nwifi_hdrlen(hdr);
Michal Kazior784f69d2013-09-26 10:12:23 +0300968 skb_pull(skb, hdr_len);
969
970 /* Push original header */
971 hdr = (struct ieee80211_hdr *)rxd->rx_hdr_status;
972 hdr_len = ieee80211_hdrlen(hdr->frame_control);
973 memcpy(skb_push(skb, hdr_len), hdr, hdr_len);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300974 break;
975 case RX_MSDU_DECAP_ETHERNET2_DIX:
Michal Kaziore3fbf8d2013-09-26 10:12:23 +0300976 /* strip ethernet header and insert decapped 802.11 header and
977 * rfc1042 header */
978
979 rfc1042 = hdr;
980 rfc1042 += roundup(hdr_len, 4);
981 rfc1042 += roundup(ath10k_htt_rx_crypto_param_len(enctype), 4);
982
983 skb_pull(skb, sizeof(struct ethhdr));
984 memcpy(skb_push(skb, sizeof(struct rfc1042_hdr)),
985 rfc1042, sizeof(struct rfc1042_hdr));
986 memcpy(skb_push(skb, hdr_len), hdr, hdr_len);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300987 break;
988 case RX_MSDU_DECAP_8023_SNAP_LLC:
Michal Kaziore3fbf8d2013-09-26 10:12:23 +0300989 /* remove A-MSDU subframe header and insert
990 * decapped 802.11 header. rfc1042 header is already there */
991
992 skb_pull(skb, sizeof(struct amsdu_subframe_hdr));
993 memcpy(skb_push(skb, hdr_len), hdr, hdr_len);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300994 break;
995 }
996
Kalle Valo5e3dd152013-06-12 20:52:10 +0300997 info->skb = skb;
Janusz Dziedzic87326c92014-03-24 21:23:19 +0100998 ath10k_htt_rx_h_protected(htt, info, enctype);
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300999
1000 ath10k_process_rx(htt->ar, info);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001001}
1002
1003static bool ath10k_htt_rx_has_decrypt_err(struct sk_buff *skb)
1004{
1005 struct htt_rx_desc *rxd;
1006 u32 flags;
1007
1008 rxd = (void *)skb->data - sizeof(*rxd);
1009 flags = __le32_to_cpu(rxd->attention.flags);
1010
1011 if (flags & RX_ATTENTION_FLAGS_DECRYPT_ERR)
1012 return true;
1013
1014 return false;
1015}
1016
1017static bool ath10k_htt_rx_has_fcs_err(struct sk_buff *skb)
1018{
1019 struct htt_rx_desc *rxd;
1020 u32 flags;
1021
1022 rxd = (void *)skb->data - sizeof(*rxd);
1023 flags = __le32_to_cpu(rxd->attention.flags);
1024
1025 if (flags & RX_ATTENTION_FLAGS_FCS_ERR)
1026 return true;
1027
1028 return false;
1029}
1030
Janusz Dziedzic22569402013-12-13 13:44:16 +01001031static bool ath10k_htt_rx_has_mic_err(struct sk_buff *skb)
1032{
1033 struct htt_rx_desc *rxd;
1034 u32 flags;
1035
1036 rxd = (void *)skb->data - sizeof(*rxd);
1037 flags = __le32_to_cpu(rxd->attention.flags);
1038
1039 if (flags & RX_ATTENTION_FLAGS_TKIP_MIC_ERR)
1040 return true;
1041
1042 return false;
1043}
1044
Janusz Dziedzica80ddb02014-02-25 07:56:39 +01001045static bool ath10k_htt_rx_is_mgmt(struct sk_buff *skb)
1046{
1047 struct htt_rx_desc *rxd;
1048 u32 flags;
1049
1050 rxd = (void *)skb->data - sizeof(*rxd);
1051 flags = __le32_to_cpu(rxd->attention.flags);
1052
1053 if (flags & RX_ATTENTION_FLAGS_MGMT_TYPE)
1054 return true;
1055
1056 return false;
1057}
1058
Michal Kazior605f81a2013-07-31 10:47:56 +02001059static int ath10k_htt_rx_get_csum_state(struct sk_buff *skb)
1060{
1061 struct htt_rx_desc *rxd;
1062 u32 flags, info;
1063 bool is_ip4, is_ip6;
1064 bool is_tcp, is_udp;
1065 bool ip_csum_ok, tcpudp_csum_ok;
1066
1067 rxd = (void *)skb->data - sizeof(*rxd);
1068 flags = __le32_to_cpu(rxd->attention.flags);
1069 info = __le32_to_cpu(rxd->msdu_start.info1);
1070
1071 is_ip4 = !!(info & RX_MSDU_START_INFO1_IPV4_PROTO);
1072 is_ip6 = !!(info & RX_MSDU_START_INFO1_IPV6_PROTO);
1073 is_tcp = !!(info & RX_MSDU_START_INFO1_TCP_PROTO);
1074 is_udp = !!(info & RX_MSDU_START_INFO1_UDP_PROTO);
1075 ip_csum_ok = !(flags & RX_ATTENTION_FLAGS_IP_CHKSUM_FAIL);
1076 tcpudp_csum_ok = !(flags & RX_ATTENTION_FLAGS_TCP_UDP_CHKSUM_FAIL);
1077
1078 if (!is_ip4 && !is_ip6)
1079 return CHECKSUM_NONE;
1080 if (!is_tcp && !is_udp)
1081 return CHECKSUM_NONE;
1082 if (!ip_csum_ok)
1083 return CHECKSUM_NONE;
1084 if (!tcpudp_csum_ok)
1085 return CHECKSUM_NONE;
1086
1087 return CHECKSUM_UNNECESSARY;
1088}
1089
Ben Greearbfa35362014-03-03 14:07:09 -08001090static int ath10k_unchain_msdu(struct sk_buff *msdu_head)
1091{
1092 struct sk_buff *next = msdu_head->next;
1093 struct sk_buff *to_free = next;
1094 int space;
1095 int total_len = 0;
1096
1097 /* TODO: Might could optimize this by using
1098 * skb_try_coalesce or similar method to
1099 * decrease copying, or maybe get mac80211 to
1100 * provide a way to just receive a list of
1101 * skb?
1102 */
1103
1104 msdu_head->next = NULL;
1105
1106 /* Allocate total length all at once. */
1107 while (next) {
1108 total_len += next->len;
1109 next = next->next;
1110 }
1111
1112 space = total_len - skb_tailroom(msdu_head);
1113 if ((space > 0) &&
1114 (pskb_expand_head(msdu_head, 0, space, GFP_ATOMIC) < 0)) {
1115 /* TODO: bump some rx-oom error stat */
1116 /* put it back together so we can free the
1117 * whole list at once.
1118 */
1119 msdu_head->next = to_free;
1120 return -1;
1121 }
1122
1123 /* Walk list again, copying contents into
1124 * msdu_head
1125 */
1126 next = to_free;
1127 while (next) {
1128 skb_copy_from_linear_data(next, skb_put(msdu_head, next->len),
1129 next->len);
1130 next = next->next;
1131 }
1132
1133 /* If here, we have consolidated skb. Free the
1134 * fragments and pass the main skb on up the
1135 * stack.
1136 */
1137 ath10k_htt_rx_free_msdu_chain(to_free);
1138 return 0;
1139}
1140
Janusz Dziedzic2acc4eb2014-03-19 07:09:40 +01001141static bool ath10k_htt_rx_amsdu_allowed(struct ath10k_htt *htt,
1142 struct sk_buff *head,
Janusz Dziedzic87326c92014-03-24 21:23:19 +01001143 enum htt_rx_mpdu_status status,
Janusz Dziedzic36653f02014-03-24 21:23:18 +01001144 bool channel_set)
Janusz Dziedzic2acc4eb2014-03-19 07:09:40 +01001145{
Janusz Dziedzic2acc4eb2014-03-19 07:09:40 +01001146 if (head->len == 0) {
1147 ath10k_dbg(ATH10K_DBG_HTT,
1148 "htt rx dropping due to zero-len\n");
1149 return false;
1150 }
1151
1152 if (ath10k_htt_rx_has_decrypt_err(head)) {
1153 ath10k_dbg(ATH10K_DBG_HTT,
1154 "htt rx dropping due to decrypt-err\n");
1155 return false;
1156 }
1157
Janusz Dziedzic36653f02014-03-24 21:23:18 +01001158 if (!channel_set) {
1159 ath10k_warn("no channel configured; ignoring frame!\n");
1160 return false;
1161 }
1162
Janusz Dziedzic2acc4eb2014-03-19 07:09:40 +01001163 /* Skip mgmt frames while we handle this in WMI */
1164 if (status == HTT_RX_IND_MPDU_STATUS_MGMT_CTRL ||
1165 ath10k_htt_rx_is_mgmt(head)) {
1166 ath10k_dbg(ATH10K_DBG_HTT, "htt rx mgmt ctrl\n");
1167 return false;
1168 }
1169
1170 if (status != HTT_RX_IND_MPDU_STATUS_OK &&
1171 status != HTT_RX_IND_MPDU_STATUS_TKIP_MIC_ERR &&
1172 status != HTT_RX_IND_MPDU_STATUS_ERR_INV_PEER &&
1173 !htt->ar->monitor_enabled) {
1174 ath10k_dbg(ATH10K_DBG_HTT,
1175 "htt rx ignoring frame w/ status %d\n",
1176 status);
1177 return false;
1178 }
1179
1180 if (test_bit(ATH10K_CAC_RUNNING, &htt->ar->dev_flags)) {
1181 ath10k_dbg(ATH10K_DBG_HTT,
1182 "htt rx CAC running\n");
1183 return false;
1184 }
1185
1186 return true;
1187}
1188
Kalle Valo5e3dd152013-06-12 20:52:10 +03001189static void ath10k_htt_rx_handler(struct ath10k_htt *htt,
1190 struct htt_rx_indication *rx)
1191{
1192 struct htt_rx_info info;
1193 struct htt_rx_indication_mpdu_range *mpdu_ranges;
Janusz Dziedzic87326c92014-03-24 21:23:19 +01001194 enum htt_rx_mpdu_status status;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001195 struct ieee80211_hdr *hdr;
1196 int num_mpdu_ranges;
1197 int fw_desc_len;
1198 u8 *fw_desc;
Janusz Dziedzic87326c92014-03-24 21:23:19 +01001199 bool channel_set, fcs_err, mic_err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001200 int i, j;
Janusz Dziedzicd84dd602014-03-24 21:23:20 +01001201 int ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001202
Michal Kazior45967082014-02-27 18:50:05 +02001203 lockdep_assert_held(&htt->rx_ring.lock);
1204
Kalle Valo5e3dd152013-06-12 20:52:10 +03001205 memset(&info, 0, sizeof(info));
1206
1207 fw_desc_len = __le16_to_cpu(rx->prefix.fw_rx_desc_bytes);
1208 fw_desc = (u8 *)&rx->fw_desc;
1209
1210 num_mpdu_ranges = MS(__le32_to_cpu(rx->hdr.info1),
1211 HTT_RX_INDICATION_INFO1_NUM_MPDU_RANGES);
1212 mpdu_ranges = htt_rx_ind_get_mpdu_ranges(rx);
1213
Janusz Dziedzice8dc1a92014-03-19 07:09:41 +01001214 /* Fill this once, while this is per-ppdu */
Janusz Dziedzic87326c92014-03-24 21:23:19 +01001215 info.rx_status.signal = ATH10K_DEFAULT_NOISE_FLOOR;
1216 info.rx_status.signal += rx->ppdu.combined_rssi;
1217
1218 if (rx->ppdu.info0 & HTT_RX_INDICATION_INFO0_END_VALID) {
1219 /* TSF available only in 32-bit */
1220 info.rx_status.mactime =
1221 __le32_to_cpu(rx->ppdu.tsf) & 0xffffffff;
1222 info.rx_status.flag |= RX_FLAG_MACTIME_END;
1223 }
Janusz Dziedzice8dc1a92014-03-19 07:09:41 +01001224
Janusz Dziedzic36653f02014-03-24 21:23:18 +01001225 channel_set = ath10k_htt_rx_h_channel(htt->ar, &info.rx_status);
1226
Janusz Dziedzic87326c92014-03-24 21:23:19 +01001227 if (channel_set) {
1228 ath10k_htt_rx_h_rates(htt->ar, info.rx_status.band,
1229 rx->ppdu.info0,
1230 __le32_to_cpu(rx->ppdu.info1),
1231 __le32_to_cpu(rx->ppdu.info2),
1232 &info.rx_status);
1233 }
Janusz Dziedzice8dc1a92014-03-19 07:09:41 +01001234
Kalle Valo5e3dd152013-06-12 20:52:10 +03001235 ath10k_dbg_dump(ATH10K_DBG_HTT_DUMP, NULL, "htt rx ind: ",
1236 rx, sizeof(*rx) +
1237 (sizeof(struct htt_rx_indication_mpdu_range) *
1238 num_mpdu_ranges));
1239
1240 for (i = 0; i < num_mpdu_ranges; i++) {
Janusz Dziedzic87326c92014-03-24 21:23:19 +01001241 status = mpdu_ranges[i].mpdu_range_status;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001242
1243 for (j = 0; j < mpdu_ranges[i].mpdu_count; j++) {
1244 struct sk_buff *msdu_head, *msdu_tail;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001245
1246 msdu_head = NULL;
1247 msdu_tail = NULL;
Janusz Dziedzicd84dd602014-03-24 21:23:20 +01001248 ret = ath10k_htt_rx_amsdu_pop(htt,
1249 &fw_desc,
1250 &fw_desc_len,
1251 &msdu_head,
1252 &msdu_tail);
1253
1254 if (ret < 0) {
1255 ath10k_warn("failed to pop amsdu from htt rx ring %d\n",
1256 ret);
1257 ath10k_htt_rx_free_msdu_chain(msdu_head);
1258 continue;
1259 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001260
Janusz Dziedzic2acc4eb2014-03-19 07:09:40 +01001261 if (!ath10k_htt_rx_amsdu_allowed(htt, msdu_head,
Janusz Dziedzic87326c92014-03-24 21:23:19 +01001262 status,
Janusz Dziedzic36653f02014-03-24 21:23:18 +01001263 channel_set)) {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001264 ath10k_htt_rx_free_msdu_chain(msdu_head);
1265 continue;
1266 }
1267
Janusz Dziedzicd84dd602014-03-24 21:23:20 +01001268 if (ret > 0 &&
1269 ath10k_unchain_msdu(msdu_head) < 0) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001270 ath10k_htt_rx_free_msdu_chain(msdu_head);
1271 continue;
1272 }
1273
1274 info.skb = msdu_head;
Ben Greearc6b56b02014-02-05 13:58:33 -08001275
Janusz Dziedzic87326c92014-03-24 21:23:19 +01001276 fcs_err = ath10k_htt_rx_has_fcs_err(msdu_head);
1277 if (fcs_err)
1278 info.rx_status.flag |= RX_FLAG_FAILED_FCS_CRC;
1279 else
1280 info.rx_status.flag &= ~RX_FLAG_FAILED_FCS_CRC;
1281
1282 mic_err = ath10k_htt_rx_has_mic_err(msdu_head);
1283 if (mic_err)
1284 info.rx_status.flag |= RX_FLAG_MMIC_ERROR;
1285 else
1286 info.rx_status.flag &= ~RX_FLAG_MMIC_ERROR;
1287
1288 if (fcs_err)
Ben Greearc6b56b02014-02-05 13:58:33 -08001289 ath10k_dbg(ATH10K_DBG_HTT,
1290 "htt rx has FCS err\n");
1291
Janusz Dziedzic87326c92014-03-24 21:23:19 +01001292 if (mic_err)
Ben Greearc6b56b02014-02-05 13:58:33 -08001293 ath10k_dbg(ATH10K_DBG_HTT,
1294 "htt rx has MIC err\n");
1295
Kalle Valo5e3dd152013-06-12 20:52:10 +03001296 hdr = ath10k_htt_rx_skb_get_hdr(msdu_head);
1297
1298 if (ath10k_htt_rx_hdr_is_amsdu(hdr))
Michal Kaziorf6dc2092013-09-26 10:12:22 +03001299 ath10k_htt_rx_amsdu(htt, &info);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001300 else
Michal Kaziorf6dc2092013-09-26 10:12:22 +03001301 ath10k_htt_rx_msdu(htt, &info);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001302 }
1303 }
1304
Michal Kazior6e712d42013-09-24 10:18:36 +02001305 tasklet_schedule(&htt->rx_replenish_task);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001306}
1307
1308static void ath10k_htt_rx_frag_handler(struct ath10k_htt *htt,
1309 struct htt_rx_fragment_indication *frag)
1310{
1311 struct sk_buff *msdu_head, *msdu_tail;
Janusz Dziedzic87326c92014-03-24 21:23:19 +01001312 enum htt_rx_mpdu_encrypt_type enctype;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001313 struct htt_rx_desc *rxd;
1314 enum rx_msdu_decap_format fmt;
1315 struct htt_rx_info info = {};
1316 struct ieee80211_hdr *hdr;
Janusz Dziedzicd84dd602014-03-24 21:23:20 +01001317 int ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001318 bool tkip_mic_err;
1319 bool decrypt_err;
1320 u8 *fw_desc;
1321 int fw_desc_len, hdrlen, paramlen;
1322 int trim;
1323
1324 fw_desc_len = __le16_to_cpu(frag->fw_rx_desc_bytes);
1325 fw_desc = (u8 *)frag->fw_msdu_rx_desc;
1326
1327 msdu_head = NULL;
1328 msdu_tail = NULL;
Michal Kazior45967082014-02-27 18:50:05 +02001329
1330 spin_lock_bh(&htt->rx_ring.lock);
Janusz Dziedzicd84dd602014-03-24 21:23:20 +01001331 ret = ath10k_htt_rx_amsdu_pop(htt, &fw_desc, &fw_desc_len,
1332 &msdu_head, &msdu_tail);
Michal Kazior45967082014-02-27 18:50:05 +02001333 spin_unlock_bh(&htt->rx_ring.lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001334
1335 ath10k_dbg(ATH10K_DBG_HTT_DUMP, "htt rx frag ahead\n");
1336
Janusz Dziedzicd84dd602014-03-24 21:23:20 +01001337 if (ret) {
1338 ath10k_warn("failed to pop amsdu from httr rx ring for fragmented rx %d\n",
1339 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001340 ath10k_htt_rx_free_msdu_chain(msdu_head);
1341 return;
1342 }
1343
1344 /* FIXME: implement signal strength */
1345
1346 hdr = (struct ieee80211_hdr *)msdu_head->data;
1347 rxd = (void *)msdu_head->data - sizeof(*rxd);
1348 tkip_mic_err = !!(__le32_to_cpu(rxd->attention.flags) &
1349 RX_ATTENTION_FLAGS_TKIP_MIC_ERR);
1350 decrypt_err = !!(__le32_to_cpu(rxd->attention.flags) &
1351 RX_ATTENTION_FLAGS_DECRYPT_ERR);
1352 fmt = MS(__le32_to_cpu(rxd->msdu_start.info1),
1353 RX_MSDU_START_INFO1_DECAP_FORMAT);
1354
1355 if (fmt != RX_MSDU_DECAP_RAW) {
1356 ath10k_warn("we dont support non-raw fragmented rx yet\n");
1357 dev_kfree_skb_any(msdu_head);
1358 goto end;
1359 }
1360
1361 info.skb = msdu_head;
Janusz Dziedzic87326c92014-03-24 21:23:19 +01001362 enctype = MS(__le32_to_cpu(rxd->mpdu_start.info0),
1363 RX_MPDU_START_INFO0_ENCRYPT_TYPE);
1364 ath10k_htt_rx_h_protected(htt, &info, enctype);
Michal Kazior605f81a2013-07-31 10:47:56 +02001365 info.skb->ip_summed = ath10k_htt_rx_get_csum_state(info.skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001366
Janusz Dziedzic87326c92014-03-24 21:23:19 +01001367 if (tkip_mic_err)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001368 ath10k_warn("tkip mic error\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03001369
1370 if (decrypt_err) {
1371 ath10k_warn("decryption err in fragmented rx\n");
1372 dev_kfree_skb_any(info.skb);
1373 goto end;
1374 }
1375
Janusz Dziedzic87326c92014-03-24 21:23:19 +01001376 if (enctype != HTT_RX_MPDU_ENCRYPT_NONE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001377 hdrlen = ieee80211_hdrlen(hdr->frame_control);
Janusz Dziedzic87326c92014-03-24 21:23:19 +01001378 paramlen = ath10k_htt_rx_crypto_param_len(enctype);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001379
1380 /* It is more efficient to move the header than the payload */
1381 memmove((void *)info.skb->data + paramlen,
1382 (void *)info.skb->data,
1383 hdrlen);
1384 skb_pull(info.skb, paramlen);
1385 hdr = (struct ieee80211_hdr *)info.skb->data;
1386 }
1387
1388 /* remove trailing FCS */
1389 trim = 4;
1390
1391 /* remove crypto trailer */
Janusz Dziedzic87326c92014-03-24 21:23:19 +01001392 trim += ath10k_htt_rx_crypto_tail_len(enctype);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001393
1394 /* last fragment of TKIP frags has MIC */
1395 if (!ieee80211_has_morefrags(hdr->frame_control) &&
Janusz Dziedzic87326c92014-03-24 21:23:19 +01001396 enctype == HTT_RX_MPDU_ENCRYPT_TKIP_WPA)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001397 trim += 8;
1398
1399 if (trim > info.skb->len) {
1400 ath10k_warn("htt rx fragment: trailer longer than the frame itself? drop\n");
1401 dev_kfree_skb_any(info.skb);
1402 goto end;
1403 }
1404
1405 skb_trim(info.skb, info.skb->len - trim);
1406
Ben Greear75fb2f92014-02-05 13:58:34 -08001407 ath10k_dbg_dump(ATH10K_DBG_HTT_DUMP, NULL, "htt rx frag mpdu: ",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001408 info.skb->data, info.skb->len);
1409 ath10k_process_rx(htt->ar, &info);
1410
1411end:
1412 if (fw_desc_len > 0) {
1413 ath10k_dbg(ATH10K_DBG_HTT,
1414 "expecting more fragmented rx in one indication %d\n",
1415 fw_desc_len);
1416 }
1417}
1418
Michal Kazior6c5151a2014-02-27 18:50:04 +02001419static void ath10k_htt_rx_frm_tx_compl(struct ath10k *ar,
1420 struct sk_buff *skb)
1421{
1422 struct ath10k_htt *htt = &ar->htt;
1423 struct htt_resp *resp = (struct htt_resp *)skb->data;
1424 struct htt_tx_done tx_done = {};
1425 int status = MS(resp->data_tx_completion.flags, HTT_DATA_TX_STATUS);
1426 __le16 msdu_id;
1427 int i;
1428
Michal Kazior45967082014-02-27 18:50:05 +02001429 lockdep_assert_held(&htt->tx_lock);
1430
Michal Kazior6c5151a2014-02-27 18:50:04 +02001431 switch (status) {
1432 case HTT_DATA_TX_STATUS_NO_ACK:
1433 tx_done.no_ack = true;
1434 break;
1435 case HTT_DATA_TX_STATUS_OK:
1436 break;
1437 case HTT_DATA_TX_STATUS_DISCARD:
1438 case HTT_DATA_TX_STATUS_POSTPONE:
1439 case HTT_DATA_TX_STATUS_DOWNLOAD_FAIL:
1440 tx_done.discard = true;
1441 break;
1442 default:
1443 ath10k_warn("unhandled tx completion status %d\n", status);
1444 tx_done.discard = true;
1445 break;
1446 }
1447
1448 ath10k_dbg(ATH10K_DBG_HTT, "htt tx completion num_msdus %d\n",
1449 resp->data_tx_completion.num_msdus);
1450
1451 for (i = 0; i < resp->data_tx_completion.num_msdus; i++) {
1452 msdu_id = resp->data_tx_completion.msdus[i];
1453 tx_done.msdu_id = __le16_to_cpu(msdu_id);
1454 ath10k_txrx_tx_unref(htt, &tx_done);
1455 }
1456}
1457
Kalle Valo5e3dd152013-06-12 20:52:10 +03001458void ath10k_htt_t2h_msg_handler(struct ath10k *ar, struct sk_buff *skb)
1459{
Michal Kazioredb82362013-07-05 16:15:14 +03001460 struct ath10k_htt *htt = &ar->htt;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001461 struct htt_resp *resp = (struct htt_resp *)skb->data;
1462
1463 /* confirm alignment */
1464 if (!IS_ALIGNED((unsigned long)skb->data, 4))
1465 ath10k_warn("unaligned htt message, expect trouble\n");
1466
Ben Greear75fb2f92014-02-05 13:58:34 -08001467 ath10k_dbg(ATH10K_DBG_HTT, "htt rx, msg_type: 0x%0X\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001468 resp->hdr.msg_type);
1469 switch (resp->hdr.msg_type) {
1470 case HTT_T2H_MSG_TYPE_VERSION_CONF: {
1471 htt->target_version_major = resp->ver_resp.major;
1472 htt->target_version_minor = resp->ver_resp.minor;
1473 complete(&htt->target_version_received);
1474 break;
1475 }
Michal Kazior6c5151a2014-02-27 18:50:04 +02001476 case HTT_T2H_MSG_TYPE_RX_IND:
Michal Kazior45967082014-02-27 18:50:05 +02001477 spin_lock_bh(&htt->rx_ring.lock);
1478 __skb_queue_tail(&htt->rx_compl_q, skb);
1479 spin_unlock_bh(&htt->rx_ring.lock);
Michal Kazior6c5151a2014-02-27 18:50:04 +02001480 tasklet_schedule(&htt->txrx_compl_task);
1481 return;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001482 case HTT_T2H_MSG_TYPE_PEER_MAP: {
1483 struct htt_peer_map_event ev = {
1484 .vdev_id = resp->peer_map.vdev_id,
1485 .peer_id = __le16_to_cpu(resp->peer_map.peer_id),
1486 };
1487 memcpy(ev.addr, resp->peer_map.addr, sizeof(ev.addr));
1488 ath10k_peer_map_event(htt, &ev);
1489 break;
1490 }
1491 case HTT_T2H_MSG_TYPE_PEER_UNMAP: {
1492 struct htt_peer_unmap_event ev = {
1493 .peer_id = __le16_to_cpu(resp->peer_unmap.peer_id),
1494 };
1495 ath10k_peer_unmap_event(htt, &ev);
1496 break;
1497 }
1498 case HTT_T2H_MSG_TYPE_MGMT_TX_COMPLETION: {
1499 struct htt_tx_done tx_done = {};
1500 int status = __le32_to_cpu(resp->mgmt_tx_completion.status);
1501
1502 tx_done.msdu_id =
1503 __le32_to_cpu(resp->mgmt_tx_completion.desc_id);
1504
1505 switch (status) {
1506 case HTT_MGMT_TX_STATUS_OK:
1507 break;
1508 case HTT_MGMT_TX_STATUS_RETRY:
1509 tx_done.no_ack = true;
1510 break;
1511 case HTT_MGMT_TX_STATUS_DROP:
1512 tx_done.discard = true;
1513 break;
1514 }
1515
Michal Kazior6c5151a2014-02-27 18:50:04 +02001516 spin_lock_bh(&htt->tx_lock);
Michal Kazior0a89f8a2013-09-18 14:43:20 +02001517 ath10k_txrx_tx_unref(htt, &tx_done);
Michal Kazior6c5151a2014-02-27 18:50:04 +02001518 spin_unlock_bh(&htt->tx_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001519 break;
1520 }
Michal Kazior6c5151a2014-02-27 18:50:04 +02001521 case HTT_T2H_MSG_TYPE_TX_COMPL_IND:
1522 spin_lock_bh(&htt->tx_lock);
1523 __skb_queue_tail(&htt->tx_compl_q, skb);
1524 spin_unlock_bh(&htt->tx_lock);
1525 tasklet_schedule(&htt->txrx_compl_task);
1526 return;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001527 case HTT_T2H_MSG_TYPE_SEC_IND: {
1528 struct ath10k *ar = htt->ar;
1529 struct htt_security_indication *ev = &resp->security_indication;
1530
1531 ath10k_dbg(ATH10K_DBG_HTT,
1532 "sec ind peer_id %d unicast %d type %d\n",
1533 __le16_to_cpu(ev->peer_id),
1534 !!(ev->flags & HTT_SECURITY_IS_UNICAST),
1535 MS(ev->flags, HTT_SECURITY_TYPE));
1536 complete(&ar->install_key_done);
1537 break;
1538 }
1539 case HTT_T2H_MSG_TYPE_RX_FRAG_IND: {
1540 ath10k_dbg_dump(ATH10K_DBG_HTT_DUMP, NULL, "htt event: ",
1541 skb->data, skb->len);
1542 ath10k_htt_rx_frag_handler(htt, &resp->rx_frag_ind);
1543 break;
1544 }
1545 case HTT_T2H_MSG_TYPE_TEST:
1546 /* FIX THIS */
1547 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001548 case HTT_T2H_MSG_TYPE_STATS_CONF:
Kalle Valoa9bf0502013-09-03 11:43:55 +03001549 trace_ath10k_htt_stats(skb->data, skb->len);
1550 break;
1551 case HTT_T2H_MSG_TYPE_TX_INSPECT_IND:
Kalle Valo5e3dd152013-06-12 20:52:10 +03001552 case HTT_T2H_MSG_TYPE_RX_ADDBA:
1553 case HTT_T2H_MSG_TYPE_RX_DELBA:
1554 case HTT_T2H_MSG_TYPE_RX_FLUSH:
1555 default:
1556 ath10k_dbg(ATH10K_DBG_HTT, "htt event (%d) not handled\n",
1557 resp->hdr.msg_type);
1558 ath10k_dbg_dump(ATH10K_DBG_HTT_DUMP, NULL, "htt event: ",
1559 skb->data, skb->len);
1560 break;
1561 };
1562
1563 /* Free the indication buffer */
1564 dev_kfree_skb_any(skb);
1565}
Michal Kazior6c5151a2014-02-27 18:50:04 +02001566
1567static void ath10k_htt_txrx_compl_task(unsigned long ptr)
1568{
1569 struct ath10k_htt *htt = (struct ath10k_htt *)ptr;
1570 struct htt_resp *resp;
1571 struct sk_buff *skb;
1572
Michal Kazior45967082014-02-27 18:50:05 +02001573 spin_lock_bh(&htt->tx_lock);
1574 while ((skb = __skb_dequeue(&htt->tx_compl_q))) {
Michal Kazior6c5151a2014-02-27 18:50:04 +02001575 ath10k_htt_rx_frm_tx_compl(htt->ar, skb);
1576 dev_kfree_skb_any(skb);
1577 }
Michal Kazior45967082014-02-27 18:50:05 +02001578 spin_unlock_bh(&htt->tx_lock);
Michal Kazior6c5151a2014-02-27 18:50:04 +02001579
Michal Kazior45967082014-02-27 18:50:05 +02001580 spin_lock_bh(&htt->rx_ring.lock);
1581 while ((skb = __skb_dequeue(&htt->rx_compl_q))) {
Michal Kazior6c5151a2014-02-27 18:50:04 +02001582 resp = (struct htt_resp *)skb->data;
1583 ath10k_htt_rx_handler(htt, &resp->rx_ind);
1584 dev_kfree_skb_any(skb);
1585 }
Michal Kazior45967082014-02-27 18:50:05 +02001586 spin_unlock_bh(&htt->rx_ring.lock);
Michal Kazior6c5151a2014-02-27 18:50:04 +02001587}