blob: a078451b4620a4201bb2e4e66b52578641f74bd4 [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"
Michal Kazioraa5b4fb2014-07-23 12:20:33 +020024#include "mac.h"
Kalle Valo5e3dd152013-06-12 20:52:10 +030025
26#include <linux/log2.h>
27
28/* slightly larger than one large A-MPDU */
29#define HTT_RX_RING_SIZE_MIN 128
30
31/* roughly 20 ms @ 1 Gbps of 1500B MSDUs */
32#define HTT_RX_RING_SIZE_MAX 2048
33
34#define HTT_RX_AVG_FRM_BYTES 1000
35
36/* ms, very conservative */
37#define HTT_RX_HOST_LATENCY_MAX_MS 20
38
39/* ms, conservative */
40#define HTT_RX_HOST_LATENCY_WORST_LIKELY_MS 10
41
42/* when under memory pressure rx ring refill may fail and needs a retry */
43#define HTT_RX_RING_REFILL_RETRY_MS 50
44
Michal Kaziorf6dc2092013-09-26 10:12:22 +030045static 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
Kalle Valo8cc7f262014-09-14 12:50:39 +0300135 idx = __le32_to_cpu(*htt->rx_ring.alloc_idx.vaddr);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300136 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:
Kalle Valo8cc7f262014-09-14 12:50:39 +0300173 *htt->rx_ring.alloc_idx.vaddr = __cpu_to_le32(idx);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300174 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;
Kalle Valoaf762c02014-09-14 12:50:17 +0300225
Kalle Valo5e3dd152013-06-12 20:52:10 +0300226 ath10k_htt_rx_msdu_buff_replenish(htt);
227}
228
Michal Kazior3e841fd2014-05-14 16:23:31 +0300229static void ath10k_htt_rx_ring_clean_up(struct ath10k_htt *htt)
230{
231 struct sk_buff *skb;
232 int i;
233
234 for (i = 0; i < htt->rx_ring.size; i++) {
235 skb = htt->rx_ring.netbufs_ring[i];
236 if (!skb)
237 continue;
238
239 dma_unmap_single(htt->ar->dev, ATH10K_SKB_CB(skb)->paddr,
240 skb->len + skb_tailroom(skb),
241 DMA_FROM_DEVICE);
242 dev_kfree_skb_any(skb);
243 htt->rx_ring.netbufs_ring[i] = NULL;
244 }
245}
246
Michal Kazior95bf21f2014-05-16 17:15:39 +0300247void ath10k_htt_rx_free(struct ath10k_htt *htt)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300248{
Kalle Valo5e3dd152013-06-12 20:52:10 +0300249 del_timer_sync(&htt->rx_ring.refill_retry_timer);
Michal Kazior6e712d42013-09-24 10:18:36 +0200250 tasklet_kill(&htt->rx_replenish_task);
Michal Kazior6c5151a2014-02-27 18:50:04 +0200251 tasklet_kill(&htt->txrx_compl_task);
252
253 skb_queue_purge(&htt->tx_compl_q);
254 skb_queue_purge(&htt->rx_compl_q);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300255
Michal Kazior3e841fd2014-05-14 16:23:31 +0300256 ath10k_htt_rx_ring_clean_up(htt);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300257
258 dma_free_coherent(htt->ar->dev,
259 (htt->rx_ring.size *
260 sizeof(htt->rx_ring.paddrs_ring)),
261 htt->rx_ring.paddrs_ring,
262 htt->rx_ring.base_paddr);
263
264 dma_free_coherent(htt->ar->dev,
265 sizeof(*htt->rx_ring.alloc_idx.vaddr),
266 htt->rx_ring.alloc_idx.vaddr,
267 htt->rx_ring.alloc_idx.paddr);
268
269 kfree(htt->rx_ring.netbufs_ring);
270}
271
272static inline struct sk_buff *ath10k_htt_rx_netbuf_pop(struct ath10k_htt *htt)
273{
Michal Kazior7aa7a722014-08-25 12:09:38 +0200274 struct ath10k *ar = htt->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300275 int idx;
276 struct sk_buff *msdu;
277
Michal Kazior45967082014-02-27 18:50:05 +0200278 lockdep_assert_held(&htt->rx_ring.lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300279
Michal Kazior8d60ee82014-02-27 18:50:05 +0200280 if (htt->rx_ring.fill_cnt == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200281 ath10k_warn(ar, "tried to pop sk_buff from an empty rx ring\n");
Michal Kazior8d60ee82014-02-27 18:50:05 +0200282 return NULL;
283 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300284
285 idx = htt->rx_ring.sw_rd_idx.msdu_payld;
286 msdu = htt->rx_ring.netbufs_ring[idx];
Michal Kazior3e841fd2014-05-14 16:23:31 +0300287 htt->rx_ring.netbufs_ring[idx] = NULL;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300288
289 idx++;
290 idx &= htt->rx_ring.size_mask;
291 htt->rx_ring.sw_rd_idx.msdu_payld = idx;
292 htt->rx_ring.fill_cnt--;
293
Kalle Valo5e3dd152013-06-12 20:52:10 +0300294 return msdu;
295}
296
297static void ath10k_htt_rx_free_msdu_chain(struct sk_buff *skb)
298{
299 struct sk_buff *next;
300
301 while (skb) {
302 next = skb->next;
303 dev_kfree_skb_any(skb);
304 skb = next;
305 }
306}
307
Janusz Dziedzicd84dd602014-03-24 21:23:20 +0100308/* return: < 0 fatal error, 0 - non chained msdu, 1 chained msdu */
Kalle Valo5e3dd152013-06-12 20:52:10 +0300309static int ath10k_htt_rx_amsdu_pop(struct ath10k_htt *htt,
310 u8 **fw_desc, int *fw_desc_len,
311 struct sk_buff **head_msdu,
Janusz Dziedzic0ccb7a32014-07-25 11:28:50 +0300312 struct sk_buff **tail_msdu,
313 u32 *attention)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300314{
Michal Kazior7aa7a722014-08-25 12:09:38 +0200315 struct ath10k *ar = htt->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300316 int msdu_len, msdu_chaining = 0;
Kalle Valoaf762c02014-09-14 12:50:17 +0300317 struct sk_buff *msdu, *next;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300318 struct htt_rx_desc *rx_desc;
319
Michal Kazior45967082014-02-27 18:50:05 +0200320 lockdep_assert_held(&htt->rx_ring.lock);
321
Kalle Valo5e3dd152013-06-12 20:52:10 +0300322 if (htt->rx_confused) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200323 ath10k_warn(ar, "htt is confused. refusing rx\n");
Janusz Dziedzicd84dd602014-03-24 21:23:20 +0100324 return -1;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300325 }
326
327 msdu = *head_msdu = ath10k_htt_rx_netbuf_pop(htt);
328 while (msdu) {
329 int last_msdu, msdu_len_invalid, msdu_chained;
330
331 dma_unmap_single(htt->ar->dev,
332 ATH10K_SKB_CB(msdu)->paddr,
333 msdu->len + skb_tailroom(msdu),
334 DMA_FROM_DEVICE);
335
Michal Kazior7aa7a722014-08-25 12:09:38 +0200336 ath10k_dbg_dump(ar, ATH10K_DBG_HTT_DUMP, NULL, "htt rx pop: ",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300337 msdu->data, msdu->len + skb_tailroom(msdu));
338
339 rx_desc = (struct htt_rx_desc *)msdu->data;
340
341 /* FIXME: we must report msdu payload since this is what caller
342 * expects now */
343 skb_put(msdu, offsetof(struct htt_rx_desc, msdu_payload));
344 skb_pull(msdu, offsetof(struct htt_rx_desc, msdu_payload));
345
346 /*
347 * Sanity check - confirm the HW is finished filling in the
348 * rx data.
349 * If the HW and SW are working correctly, then it's guaranteed
350 * that the HW's MAC DMA is done before this point in the SW.
351 * To prevent the case that we handle a stale Rx descriptor,
352 * just assert for now until we have a way to recover.
353 */
354 if (!(__le32_to_cpu(rx_desc->attention.flags)
355 & RX_ATTENTION_FLAGS_MSDU_DONE)) {
356 ath10k_htt_rx_free_msdu_chain(*head_msdu);
357 *head_msdu = NULL;
358 msdu = NULL;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200359 ath10k_err(ar, "htt rx stopped. cannot recover\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +0300360 htt->rx_confused = true;
361 break;
362 }
363
Janusz Dziedzic0ccb7a32014-07-25 11:28:50 +0300364 *attention |= __le32_to_cpu(rx_desc->attention.flags) &
365 (RX_ATTENTION_FLAGS_TKIP_MIC_ERR |
366 RX_ATTENTION_FLAGS_DECRYPT_ERR |
367 RX_ATTENTION_FLAGS_FCS_ERR |
368 RX_ATTENTION_FLAGS_MGMT_TYPE);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300369 /*
370 * Copy the FW rx descriptor for this MSDU from the rx
371 * indication message into the MSDU's netbuf. HL uses the
372 * same rx indication message definition as LL, and simply
373 * appends new info (fields from the HW rx desc, and the
374 * MSDU payload itself). So, the offset into the rx
375 * indication message only has to account for the standard
376 * offset of the per-MSDU FW rx desc info within the
377 * message, and how many bytes of the per-MSDU FW rx desc
378 * info have already been consumed. (And the endianness of
379 * the host, since for a big-endian host, the rx ind
380 * message contents, including the per-MSDU rx desc bytes,
381 * were byteswapped during upload.)
382 */
383 if (*fw_desc_len > 0) {
384 rx_desc->fw_desc.info0 = **fw_desc;
385 /*
386 * The target is expected to only provide the basic
387 * per-MSDU rx descriptors. Just to be sure, verify
388 * that the target has not attached extension data
389 * (e.g. LRO flow ID).
390 */
391
392 /* or more, if there's extension data */
393 (*fw_desc)++;
394 (*fw_desc_len)--;
395 } else {
396 /*
397 * When an oversized AMSDU happened, FW will lost
398 * some of MSDU status - in this case, the FW
399 * descriptors provided will be less than the
400 * actual MSDUs inside this MPDU. Mark the FW
401 * descriptors so that it will still deliver to
402 * upper stack, if no CRC error for this MPDU.
403 *
404 * FIX THIS - the FW descriptors are actually for
405 * MSDUs in the end of this A-MSDU instead of the
406 * beginning.
407 */
408 rx_desc->fw_desc.info0 = 0;
409 }
410
411 msdu_len_invalid = !!(__le32_to_cpu(rx_desc->attention.flags)
412 & (RX_ATTENTION_FLAGS_MPDU_LENGTH_ERR |
413 RX_ATTENTION_FLAGS_MSDU_LENGTH_ERR));
414 msdu_len = MS(__le32_to_cpu(rx_desc->msdu_start.info0),
415 RX_MSDU_START_INFO0_MSDU_LENGTH);
416 msdu_chained = rx_desc->frag_info.ring2_more_count;
417
418 if (msdu_len_invalid)
419 msdu_len = 0;
420
421 skb_trim(msdu, 0);
422 skb_put(msdu, min(msdu_len, HTT_RX_MSDU_SIZE));
423 msdu_len -= msdu->len;
424
425 /* FIXME: Do chained buffers include htt_rx_desc or not? */
426 while (msdu_chained--) {
427 struct sk_buff *next = ath10k_htt_rx_netbuf_pop(htt);
428
429 dma_unmap_single(htt->ar->dev,
430 ATH10K_SKB_CB(next)->paddr,
431 next->len + skb_tailroom(next),
432 DMA_FROM_DEVICE);
433
Michal Kazior7aa7a722014-08-25 12:09:38 +0200434 ath10k_dbg_dump(ar, ATH10K_DBG_HTT_DUMP, NULL,
Ben Greear75fb2f92014-02-05 13:58:34 -0800435 "htt rx chained: ", next->data,
Kalle Valo5e3dd152013-06-12 20:52:10 +0300436 next->len + skb_tailroom(next));
437
438 skb_trim(next, 0);
439 skb_put(next, min(msdu_len, HTT_RX_BUF_SIZE));
440 msdu_len -= next->len;
441
442 msdu->next = next;
443 msdu = next;
Michal Kaziorede9c8e2014-05-14 16:23:31 +0300444 msdu_chaining = 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300445 }
446
Kalle Valo5e3dd152013-06-12 20:52:10 +0300447 last_msdu = __le32_to_cpu(rx_desc->msdu_end.info0) &
448 RX_MSDU_END_INFO0_LAST_MSDU;
449
450 if (last_msdu) {
451 msdu->next = NULL;
452 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300453 }
Kalle Valod8bb26b2014-09-14 12:50:33 +0300454
455 next = ath10k_htt_rx_netbuf_pop(htt);
456 msdu->next = next;
457 msdu = next;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300458 }
459 *tail_msdu = msdu;
460
Janusz Dziedzicd84dd602014-03-24 21:23:20 +0100461 if (*head_msdu == NULL)
462 msdu_chaining = -1;
463
Kalle Valo5e3dd152013-06-12 20:52:10 +0300464 /*
465 * Don't refill the ring yet.
466 *
467 * First, the elements popped here are still in use - it is not
468 * safe to overwrite them until the matching call to
469 * mpdu_desc_list_next. Second, for efficiency it is preferable to
470 * refill the rx ring with 1 PPDU's worth of rx buffers (something
471 * like 32 x 3 buffers), rather than one MPDU's worth of rx buffers
472 * (something like 3 buffers). Consequently, we'll rely on the txrx
473 * SW to tell us when it is done pulling all the PPDU's rx buffers
474 * out of the rx ring, and then refill it just once.
475 */
476
477 return msdu_chaining;
478}
479
Michal Kazior6e712d42013-09-24 10:18:36 +0200480static void ath10k_htt_rx_replenish_task(unsigned long ptr)
481{
482 struct ath10k_htt *htt = (struct ath10k_htt *)ptr;
Kalle Valoaf762c02014-09-14 12:50:17 +0300483
Michal Kazior6e712d42013-09-24 10:18:36 +0200484 ath10k_htt_rx_msdu_buff_replenish(htt);
485}
486
Michal Kazior95bf21f2014-05-16 17:15:39 +0300487int ath10k_htt_rx_alloc(struct ath10k_htt *htt)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300488{
Michal Kazior7aa7a722014-08-25 12:09:38 +0200489 struct ath10k *ar = htt->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300490 dma_addr_t paddr;
491 void *vaddr;
Kalle Valobd8bdbb2014-09-14 12:50:00 +0300492 size_t size;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300493 struct timer_list *timer = &htt->rx_ring.refill_retry_timer;
494
495 htt->rx_ring.size = ath10k_htt_rx_ring_size(htt);
496 if (!is_power_of_2(htt->rx_ring.size)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200497 ath10k_warn(ar, "htt rx ring size is not power of 2\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +0300498 return -EINVAL;
499 }
500
501 htt->rx_ring.size_mask = htt->rx_ring.size - 1;
502
503 /*
504 * Set the initial value for the level to which the rx ring
505 * should be filled, based on the max throughput and the
506 * worst likely latency for the host to fill the rx ring
507 * with new buffers. In theory, this fill level can be
508 * dynamically adjusted from the initial value set here, to
509 * reflect the actual host latency rather than a
510 * conservative assumption about the host latency.
511 */
512 htt->rx_ring.fill_level = ath10k_htt_rx_ring_fill_level(htt);
513
514 htt->rx_ring.netbufs_ring =
Michal Kazior3e841fd2014-05-14 16:23:31 +0300515 kzalloc(htt->rx_ring.size * sizeof(struct sk_buff *),
Kalle Valo5e3dd152013-06-12 20:52:10 +0300516 GFP_KERNEL);
517 if (!htt->rx_ring.netbufs_ring)
518 goto err_netbuf;
519
Kalle Valobd8bdbb2014-09-14 12:50:00 +0300520 size = htt->rx_ring.size * sizeof(htt->rx_ring.paddrs_ring);
521
522 vaddr = dma_alloc_coherent(htt->ar->dev, size, &paddr, GFP_DMA);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300523 if (!vaddr)
524 goto err_dma_ring;
525
526 htt->rx_ring.paddrs_ring = vaddr;
527 htt->rx_ring.base_paddr = paddr;
528
529 vaddr = dma_alloc_coherent(htt->ar->dev,
530 sizeof(*htt->rx_ring.alloc_idx.vaddr),
531 &paddr, GFP_DMA);
532 if (!vaddr)
533 goto err_dma_idx;
534
535 htt->rx_ring.alloc_idx.vaddr = vaddr;
536 htt->rx_ring.alloc_idx.paddr = paddr;
537 htt->rx_ring.sw_rd_idx.msdu_payld = 0;
538 *htt->rx_ring.alloc_idx.vaddr = 0;
539
540 /* Initialize the Rx refill retry timer */
541 setup_timer(timer, ath10k_htt_rx_ring_refill_retry, (unsigned long)htt);
542
543 spin_lock_init(&htt->rx_ring.lock);
544
545 htt->rx_ring.fill_cnt = 0;
546 if (__ath10k_htt_rx_ring_fill_n(htt, htt->rx_ring.fill_level))
547 goto err_fill_ring;
548
Michal Kazior6e712d42013-09-24 10:18:36 +0200549 tasklet_init(&htt->rx_replenish_task, ath10k_htt_rx_replenish_task,
550 (unsigned long)htt);
551
Michal Kazior6c5151a2014-02-27 18:50:04 +0200552 skb_queue_head_init(&htt->tx_compl_q);
553 skb_queue_head_init(&htt->rx_compl_q);
554
555 tasklet_init(&htt->txrx_compl_task, ath10k_htt_txrx_compl_task,
556 (unsigned long)htt);
557
Michal Kazior7aa7a722014-08-25 12:09:38 +0200558 ath10k_dbg(ar, ATH10K_DBG_BOOT, "htt rx ring size %d fill_level %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300559 htt->rx_ring.size, htt->rx_ring.fill_level);
560 return 0;
561
562err_fill_ring:
563 ath10k_htt_rx_ring_free(htt);
564 dma_free_coherent(htt->ar->dev,
565 sizeof(*htt->rx_ring.alloc_idx.vaddr),
566 htt->rx_ring.alloc_idx.vaddr,
567 htt->rx_ring.alloc_idx.paddr);
568err_dma_idx:
569 dma_free_coherent(htt->ar->dev,
570 (htt->rx_ring.size *
571 sizeof(htt->rx_ring.paddrs_ring)),
572 htt->rx_ring.paddrs_ring,
573 htt->rx_ring.base_paddr);
574err_dma_ring:
575 kfree(htt->rx_ring.netbufs_ring);
576err_netbuf:
577 return -ENOMEM;
578}
579
Michal Kazior7aa7a722014-08-25 12:09:38 +0200580static int ath10k_htt_rx_crypto_param_len(struct ath10k *ar,
581 enum htt_rx_mpdu_encrypt_type type)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300582{
583 switch (type) {
584 case HTT_RX_MPDU_ENCRYPT_WEP40:
585 case HTT_RX_MPDU_ENCRYPT_WEP104:
586 return 4;
587 case HTT_RX_MPDU_ENCRYPT_TKIP_WITHOUT_MIC:
588 case HTT_RX_MPDU_ENCRYPT_WEP128: /* not tested */
589 case HTT_RX_MPDU_ENCRYPT_TKIP_WPA:
590 case HTT_RX_MPDU_ENCRYPT_WAPI: /* not tested */
591 case HTT_RX_MPDU_ENCRYPT_AES_CCM_WPA2:
592 return 8;
593 case HTT_RX_MPDU_ENCRYPT_NONE:
594 return 0;
595 }
596
Michal Kazior7aa7a722014-08-25 12:09:38 +0200597 ath10k_warn(ar, "unknown encryption type %d\n", type);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300598 return 0;
599}
600
Michal Kazior7aa7a722014-08-25 12:09:38 +0200601static int ath10k_htt_rx_crypto_tail_len(struct ath10k *ar,
602 enum htt_rx_mpdu_encrypt_type type)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300603{
604 switch (type) {
605 case HTT_RX_MPDU_ENCRYPT_NONE:
606 case HTT_RX_MPDU_ENCRYPT_WEP40:
607 case HTT_RX_MPDU_ENCRYPT_WEP104:
608 case HTT_RX_MPDU_ENCRYPT_WEP128:
609 case HTT_RX_MPDU_ENCRYPT_WAPI:
610 return 0;
611 case HTT_RX_MPDU_ENCRYPT_TKIP_WITHOUT_MIC:
612 case HTT_RX_MPDU_ENCRYPT_TKIP_WPA:
613 return 4;
614 case HTT_RX_MPDU_ENCRYPT_AES_CCM_WPA2:
615 return 8;
616 }
617
Michal Kazior7aa7a722014-08-25 12:09:38 +0200618 ath10k_warn(ar, "unknown encryption type %d\n", type);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300619 return 0;
620}
621
622/* Applies for first msdu in chain, before altering it. */
623static struct ieee80211_hdr *ath10k_htt_rx_skb_get_hdr(struct sk_buff *skb)
624{
625 struct htt_rx_desc *rxd;
626 enum rx_msdu_decap_format fmt;
627
628 rxd = (void *)skb->data - sizeof(*rxd);
629 fmt = MS(__le32_to_cpu(rxd->msdu_start.info1),
Kalle Valo5b07e072014-09-14 12:50:06 +0300630 RX_MSDU_START_INFO1_DECAP_FORMAT);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300631
632 if (fmt == RX_MSDU_DECAP_RAW)
633 return (void *)skb->data;
Kalle Valod8bb26b2014-09-14 12:50:33 +0300634
635 return (void *)skb->data - RX_HTT_HDR_STATUS_LEN;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300636}
637
638/* This function only applies for first msdu in an msdu chain */
639static bool ath10k_htt_rx_hdr_is_amsdu(struct ieee80211_hdr *hdr)
640{
Kalle Valoaf762c02014-09-14 12:50:17 +0300641 u8 *qc;
642
Kalle Valo5e3dd152013-06-12 20:52:10 +0300643 if (ieee80211_is_data_qos(hdr->frame_control)) {
Kalle Valoaf762c02014-09-14 12:50:17 +0300644 qc = ieee80211_get_qos_ctl(hdr);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300645 if (qc[0] & 0x80)
646 return true;
647 }
648 return false;
649}
650
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300651struct rfc1042_hdr {
652 u8 llc_dsap;
653 u8 llc_ssap;
654 u8 llc_ctrl;
655 u8 snap_oui[3];
656 __be16 snap_type;
657} __packed;
658
659struct amsdu_subframe_hdr {
660 u8 dst[ETH_ALEN];
661 u8 src[ETH_ALEN];
662 __be16 len;
663} __packed;
664
Janusz Dziedzic73539b42014-03-24 21:23:15 +0100665static const u8 rx_legacy_rate_idx[] = {
666 3, /* 0x00 - 11Mbps */
667 2, /* 0x01 - 5.5Mbps */
668 1, /* 0x02 - 2Mbps */
669 0, /* 0x03 - 1Mbps */
670 3, /* 0x04 - 11Mbps */
671 2, /* 0x05 - 5.5Mbps */
672 1, /* 0x06 - 2Mbps */
673 0, /* 0x07 - 1Mbps */
674 10, /* 0x08 - 48Mbps */
675 8, /* 0x09 - 24Mbps */
676 6, /* 0x0A - 12Mbps */
677 4, /* 0x0B - 6Mbps */
678 11, /* 0x0C - 54Mbps */
679 9, /* 0x0D - 36Mbps */
680 7, /* 0x0E - 18Mbps */
681 5, /* 0x0F - 9Mbps */
682};
683
Janusz Dziedzic87326c92014-03-24 21:23:19 +0100684static void ath10k_htt_rx_h_rates(struct ath10k *ar,
Janusz Dziedziccfadd9b2014-03-24 21:23:16 +0100685 enum ieee80211_band band,
Janusz Dziedzic87326c92014-03-24 21:23:19 +0100686 u8 info0, u32 info1, u32 info2,
Janusz Dziedziccfadd9b2014-03-24 21:23:16 +0100687 struct ieee80211_rx_status *status)
Janusz Dziedzic73539b42014-03-24 21:23:15 +0100688{
689 u8 cck, rate, rate_idx, bw, sgi, mcs, nss;
Janusz Dziedzic73539b42014-03-24 21:23:15 +0100690 u8 preamble = 0;
691
692 /* Check if valid fields */
693 if (!(info0 & HTT_RX_INDICATION_INFO0_START_VALID))
694 return;
695
696 preamble = MS(info1, HTT_RX_INDICATION_INFO1_PREAMBLE_TYPE);
697
698 switch (preamble) {
699 case HTT_RX_LEGACY:
700 cck = info0 & HTT_RX_INDICATION_INFO0_LEGACY_RATE_CCK;
701 rate = MS(info0, HTT_RX_INDICATION_INFO0_LEGACY_RATE);
702 rate_idx = 0;
703
704 if (rate < 0x08 || rate > 0x0F)
705 break;
706
707 switch (band) {
708 case IEEE80211_BAND_2GHZ:
709 if (cck)
710 rate &= ~BIT(3);
711 rate_idx = rx_legacy_rate_idx[rate];
712 break;
713 case IEEE80211_BAND_5GHZ:
714 rate_idx = rx_legacy_rate_idx[rate];
715 /* We are using same rate table registering
716 HW - ath10k_rates[]. In case of 5GHz skip
717 CCK rates, so -4 here */
718 rate_idx -= 4;
719 break;
720 default:
721 break;
722 }
723
724 status->rate_idx = rate_idx;
725 break;
726 case HTT_RX_HT:
727 case HTT_RX_HT_WITH_TXBF:
728 /* HT-SIG - Table 20-11 in info1 and info2 */
729 mcs = info1 & 0x1F;
730 nss = mcs >> 3;
731 bw = (info1 >> 7) & 1;
732 sgi = (info2 >> 7) & 1;
733
734 status->rate_idx = mcs;
735 status->flag |= RX_FLAG_HT;
736 if (sgi)
737 status->flag |= RX_FLAG_SHORT_GI;
738 if (bw)
739 status->flag |= RX_FLAG_40MHZ;
740 break;
741 case HTT_RX_VHT:
742 case HTT_RX_VHT_WITH_TXBF:
743 /* VHT-SIG-A1 in info 1, VHT-SIG-A2 in info2
744 TODO check this */
745 mcs = (info2 >> 4) & 0x0F;
746 nss = ((info1 >> 10) & 0x07) + 1;
747 bw = info1 & 3;
748 sgi = info2 & 1;
749
750 status->rate_idx = mcs;
751 status->vht_nss = nss;
752
753 if (sgi)
754 status->flag |= RX_FLAG_SHORT_GI;
755
756 switch (bw) {
757 /* 20MHZ */
758 case 0:
759 break;
760 /* 40MHZ */
761 case 1:
762 status->flag |= RX_FLAG_40MHZ;
763 break;
764 /* 80MHZ */
765 case 2:
766 status->vht_flag |= RX_VHT_FLAG_80MHZ;
767 }
768
769 status->flag |= RX_FLAG_VHT;
770 break;
771 default:
772 break;
773 }
774}
775
Janusz Dziedzic87326c92014-03-24 21:23:19 +0100776static void ath10k_htt_rx_h_protected(struct ath10k_htt *htt,
Janusz Dziedzic85f6d7c2014-03-24 21:23:22 +0100777 struct ieee80211_rx_status *rx_status,
778 struct sk_buff *skb,
Michal Kaziorc071dcb2014-05-23 11:33:18 +0300779 enum htt_rx_mpdu_encrypt_type enctype,
780 enum rx_msdu_decap_format fmt,
781 bool dot11frag)
Janusz Dziedzic87326c92014-03-24 21:23:19 +0100782{
Janusz Dziedzic85f6d7c2014-03-24 21:23:22 +0100783 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Janusz Dziedzic87326c92014-03-24 21:23:19 +0100784
Michal Kaziorc071dcb2014-05-23 11:33:18 +0300785 rx_status->flag &= ~(RX_FLAG_DECRYPTED |
786 RX_FLAG_IV_STRIPPED |
787 RX_FLAG_MMIC_STRIPPED);
Janusz Dziedzic87326c92014-03-24 21:23:19 +0100788
Michal Kaziorc071dcb2014-05-23 11:33:18 +0300789 if (enctype == HTT_RX_MPDU_ENCRYPT_NONE)
Janusz Dziedzic87326c92014-03-24 21:23:19 +0100790 return;
Michal Kaziorc071dcb2014-05-23 11:33:18 +0300791
792 /*
793 * There's no explicit rx descriptor flag to indicate whether a given
794 * frame has been decrypted or not. We're forced to use the decap
795 * format as an implicit indication. However fragmentation rx is always
796 * raw and it probably never reports undecrypted raws.
797 *
798 * This makes sure sniffed frames are reported as-is without stripping
799 * the protected flag.
800 */
801 if (fmt == RX_MSDU_DECAP_RAW && !dot11frag)
802 return;
Janusz Dziedzic87326c92014-03-24 21:23:19 +0100803
Janusz Dziedzic85f6d7c2014-03-24 21:23:22 +0100804 rx_status->flag |= RX_FLAG_DECRYPTED |
805 RX_FLAG_IV_STRIPPED |
806 RX_FLAG_MMIC_STRIPPED;
Janusz Dziedzic87326c92014-03-24 21:23:19 +0100807 hdr->frame_control = __cpu_to_le16(__le16_to_cpu(hdr->frame_control) &
808 ~IEEE80211_FCTL_PROTECTED);
809}
810
Janusz Dziedzic36653f02014-03-24 21:23:18 +0100811static bool ath10k_htt_rx_h_channel(struct ath10k *ar,
812 struct ieee80211_rx_status *status)
813{
814 struct ieee80211_channel *ch;
815
816 spin_lock_bh(&ar->data_lock);
817 ch = ar->scan_channel;
818 if (!ch)
819 ch = ar->rx_channel;
820 spin_unlock_bh(&ar->data_lock);
821
822 if (!ch)
823 return false;
824
825 status->band = ch->band;
826 status->freq = ch->center_freq;
827
828 return true;
829}
830
Janusz Dziedzic76f53292014-07-28 23:59:43 +0300831static const char * const tid_to_ac[] = {
832 "BE",
833 "BK",
834 "BK",
835 "BE",
836 "VI",
837 "VI",
838 "VO",
839 "VO",
840};
841
842static char *ath10k_get_tid(struct ieee80211_hdr *hdr, char *out, size_t size)
843{
844 u8 *qc;
845 int tid;
846
847 if (!ieee80211_is_data_qos(hdr->frame_control))
848 return "";
849
850 qc = ieee80211_get_qos_ctl(hdr);
851 tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
852 if (tid < 8)
853 snprintf(out, size, "tid %d (%s)", tid, tid_to_ac[tid]);
854 else
855 snprintf(out, size, "tid %d", tid);
856
857 return out;
858}
859
Janusz Dziedzic85f6d7c2014-03-24 21:23:22 +0100860static void ath10k_process_rx(struct ath10k *ar,
861 struct ieee80211_rx_status *rx_status,
862 struct sk_buff *skb)
Janusz Dziedzic73539b42014-03-24 21:23:15 +0100863{
864 struct ieee80211_rx_status *status;
Janusz Dziedzic76f53292014-07-28 23:59:43 +0300865 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
866 char tid[32];
Janusz Dziedzic73539b42014-03-24 21:23:15 +0100867
Janusz Dziedzic85f6d7c2014-03-24 21:23:22 +0100868 status = IEEE80211_SKB_RXCB(skb);
869 *status = *rx_status;
Janusz Dziedzic73539b42014-03-24 21:23:15 +0100870
Michal Kazior7aa7a722014-08-25 12:09:38 +0200871 ath10k_dbg(ar, ATH10K_DBG_DATA,
Janusz Dziedzic76f53292014-07-28 23:59:43 +0300872 "rx skb %p len %u peer %pM %s %s sn %u %s%s%s%s%s %srate_idx %u vht_nss %u freq %u band %u flag 0x%x fcs-err %i mic-err %i amsdu-more %i\n",
Janusz Dziedzic85f6d7c2014-03-24 21:23:22 +0100873 skb,
874 skb->len,
Janusz Dziedzic76f53292014-07-28 23:59:43 +0300875 ieee80211_get_SA(hdr),
876 ath10k_get_tid(hdr, tid, sizeof(tid)),
877 is_multicast_ether_addr(ieee80211_get_DA(hdr)) ?
878 "mcast" : "ucast",
879 (__le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_SEQ) >> 4,
Janusz Dziedzic73539b42014-03-24 21:23:15 +0100880 status->flag == 0 ? "legacy" : "",
881 status->flag & RX_FLAG_HT ? "ht" : "",
882 status->flag & RX_FLAG_VHT ? "vht" : "",
883 status->flag & RX_FLAG_40MHZ ? "40" : "",
884 status->vht_flag & RX_VHT_FLAG_80MHZ ? "80" : "",
885 status->flag & RX_FLAG_SHORT_GI ? "sgi " : "",
886 status->rate_idx,
887 status->vht_nss,
888 status->freq,
Janusz Dziedzic87326c92014-03-24 21:23:19 +0100889 status->band, status->flag,
Janusz Dziedzic78433f92014-03-24 21:23:21 +0100890 !!(status->flag & RX_FLAG_FAILED_FCS_CRC),
Janusz Dziedzic76f53292014-07-28 23:59:43 +0300891 !!(status->flag & RX_FLAG_MMIC_ERROR),
892 !!(status->flag & RX_FLAG_AMSDU_MORE));
Michal Kazior7aa7a722014-08-25 12:09:38 +0200893 ath10k_dbg_dump(ar, ATH10K_DBG_HTT_DUMP, NULL, "rx skb: ",
Janusz Dziedzic85f6d7c2014-03-24 21:23:22 +0100894 skb->data, skb->len);
Janusz Dziedzic73539b42014-03-24 21:23:15 +0100895
Janusz Dziedzic85f6d7c2014-03-24 21:23:22 +0100896 ieee80211_rx(ar->hw, skb);
Janusz Dziedzic73539b42014-03-24 21:23:15 +0100897}
898
Michal Kaziord960c362014-02-25 09:29:57 +0200899static int ath10k_htt_rx_nwifi_hdrlen(struct ieee80211_hdr *hdr)
900{
901 /* nwifi header is padded to 4 bytes. this fixes 4addr rx */
902 return round_up(ieee80211_hdrlen(hdr->frame_control), 4);
903}
904
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300905static void ath10k_htt_rx_amsdu(struct ath10k_htt *htt,
Janusz Dziedzic85f6d7c2014-03-24 21:23:22 +0100906 struct ieee80211_rx_status *rx_status,
907 struct sk_buff *skb_in)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300908{
Michal Kazior7aa7a722014-08-25 12:09:38 +0200909 struct ath10k *ar = htt->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300910 struct htt_rx_desc *rxd;
Janusz Dziedzic85f6d7c2014-03-24 21:23:22 +0100911 struct sk_buff *skb = skb_in;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300912 struct sk_buff *first;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300913 enum rx_msdu_decap_format fmt;
914 enum htt_rx_mpdu_encrypt_type enctype;
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300915 struct ieee80211_hdr *hdr;
Michal Kazior72bdeb82014-07-28 23:59:42 +0300916 u8 hdr_buf[64], da[ETH_ALEN], sa[ETH_ALEN], *qos;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300917 unsigned int hdr_len;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300918
919 rxd = (void *)skb->data - sizeof(*rxd);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300920 enctype = MS(__le32_to_cpu(rxd->mpdu_start.info0),
Kalle Valo5b07e072014-09-14 12:50:06 +0300921 RX_MPDU_START_INFO0_ENCRYPT_TYPE);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300922
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300923 hdr = (struct ieee80211_hdr *)rxd->rx_hdr_status;
924 hdr_len = ieee80211_hdrlen(hdr->frame_control);
925 memcpy(hdr_buf, hdr, hdr_len);
926 hdr = (struct ieee80211_hdr *)hdr_buf;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300927
Kalle Valo5e3dd152013-06-12 20:52:10 +0300928 first = skb;
929 while (skb) {
930 void *decap_hdr;
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300931 int len;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300932
933 rxd = (void *)skb->data - sizeof(*rxd);
934 fmt = MS(__le32_to_cpu(rxd->msdu_start.info1),
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300935 RX_MSDU_START_INFO1_DECAP_FORMAT);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300936 decap_hdr = (void *)rxd->rx_hdr_status;
937
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300938 skb->ip_summed = ath10k_htt_rx_get_csum_state(skb);
939
940 /* First frame in an A-MSDU chain has more decapped data. */
Kalle Valo5e3dd152013-06-12 20:52:10 +0300941 if (skb == first) {
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300942 len = round_up(ieee80211_hdrlen(hdr->frame_control), 4);
Michal Kazior7aa7a722014-08-25 12:09:38 +0200943 len += round_up(ath10k_htt_rx_crypto_param_len(ar,
944 enctype), 4);
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300945 decap_hdr += len;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300946 }
947
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300948 switch (fmt) {
949 case RX_MSDU_DECAP_RAW:
Michal Kaziore3fbf8d2013-09-26 10:12:23 +0300950 /* remove trailing FCS */
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300951 skb_trim(skb, skb->len - FCS_LEN);
952 break;
953 case RX_MSDU_DECAP_NATIVE_WIFI:
Michal Kazior72bdeb82014-07-28 23:59:42 +0300954 /* pull decapped header and copy SA & DA */
Michal Kazior784f69d2013-09-26 10:12:23 +0300955 hdr = (struct ieee80211_hdr *)skb->data;
Michal Kaziord960c362014-02-25 09:29:57 +0200956 hdr_len = ath10k_htt_rx_nwifi_hdrlen(hdr);
Kalle Valob25f32c2014-09-14 12:50:49 +0300957 ether_addr_copy(da, ieee80211_get_DA(hdr));
958 ether_addr_copy(sa, ieee80211_get_SA(hdr));
Michal Kazior784f69d2013-09-26 10:12:23 +0300959 skb_pull(skb, hdr_len);
960
961 /* push original 802.11 header */
962 hdr = (struct ieee80211_hdr *)hdr_buf;
963 hdr_len = ieee80211_hdrlen(hdr->frame_control);
964 memcpy(skb_push(skb, hdr_len), hdr, hdr_len);
965
966 /* original A-MSDU header has the bit set but we're
967 * not including A-MSDU subframe header */
968 hdr = (struct ieee80211_hdr *)skb->data;
969 qos = ieee80211_get_qos_ctl(hdr);
970 qos[0] &= ~IEEE80211_QOS_CTL_A_MSDU_PRESENT;
971
Michal Kazior72bdeb82014-07-28 23:59:42 +0300972 /* original 802.11 header has a different DA and in
973 * case of 4addr it may also have different SA
974 */
Kalle Valob25f32c2014-09-14 12:50:49 +0300975 ether_addr_copy(ieee80211_get_DA(hdr), da);
976 ether_addr_copy(ieee80211_get_SA(hdr), sa);
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300977 break;
978 case RX_MSDU_DECAP_ETHERNET2_DIX:
Michal Kaziore3fbf8d2013-09-26 10:12:23 +0300979 /* strip ethernet header and insert decapped 802.11
980 * header, amsdu subframe header and rfc1042 header */
981
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300982 len = 0;
983 len += sizeof(struct rfc1042_hdr);
984 len += sizeof(struct amsdu_subframe_hdr);
Michal Kaziordfa95b52013-08-13 07:59:37 +0200985
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300986 skb_pull(skb, sizeof(struct ethhdr));
987 memcpy(skb_push(skb, len), decap_hdr, len);
988 memcpy(skb_push(skb, hdr_len), hdr, hdr_len);
989 break;
990 case RX_MSDU_DECAP_8023_SNAP_LLC:
Michal Kaziore3fbf8d2013-09-26 10:12:23 +0300991 /* insert decapped 802.11 header making a singly
992 * A-MSDU */
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300993 memcpy(skb_push(skb, hdr_len), hdr, hdr_len);
994 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300995 }
996
Janusz Dziedzic85f6d7c2014-03-24 21:23:22 +0100997 skb_in = skb;
Michal Kaziorc071dcb2014-05-23 11:33:18 +0300998 ath10k_htt_rx_h_protected(htt, rx_status, skb_in, enctype, fmt,
999 false);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001000 skb = skb->next;
Janusz Dziedzic85f6d7c2014-03-24 21:23:22 +01001001 skb_in->next = NULL;
Michal Kaziorf6dc2092013-09-26 10:12:22 +03001002
Kalle Valo652de352013-11-13 15:23:30 +02001003 if (skb)
Janusz Dziedzic85f6d7c2014-03-24 21:23:22 +01001004 rx_status->flag |= RX_FLAG_AMSDU_MORE;
Janusz Dziedzic87326c92014-03-24 21:23:19 +01001005 else
Janusz Dziedzic85f6d7c2014-03-24 21:23:22 +01001006 rx_status->flag &= ~RX_FLAG_AMSDU_MORE;
Kalle Valo652de352013-11-13 15:23:30 +02001007
Janusz Dziedzic85f6d7c2014-03-24 21:23:22 +01001008 ath10k_process_rx(htt->ar, rx_status, skb_in);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001009 }
1010
Michal Kaziorf6dc2092013-09-26 10:12:22 +03001011 /* FIXME: It might be nice to re-assemble the A-MSDU when there's a
1012 * monitor interface active for sniffing purposes. */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001013}
1014
Janusz Dziedzic85f6d7c2014-03-24 21:23:22 +01001015static void ath10k_htt_rx_msdu(struct ath10k_htt *htt,
1016 struct ieee80211_rx_status *rx_status,
1017 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001018{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001019 struct ath10k *ar = htt->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001020 struct htt_rx_desc *rxd;
1021 struct ieee80211_hdr *hdr;
1022 enum rx_msdu_decap_format fmt;
1023 enum htt_rx_mpdu_encrypt_type enctype;
Michal Kaziore3fbf8d2013-09-26 10:12:23 +03001024 int hdr_len;
1025 void *rfc1042;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001026
1027 /* This shouldn't happen. If it does than it may be a FW bug. */
1028 if (skb->next) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001029 ath10k_warn(ar, "htt rx received chained non A-MSDU frame\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03001030 ath10k_htt_rx_free_msdu_chain(skb->next);
1031 skb->next = NULL;
1032 }
1033
1034 rxd = (void *)skb->data - sizeof(*rxd);
1035 fmt = MS(__le32_to_cpu(rxd->msdu_start.info1),
Kalle Valo5b07e072014-09-14 12:50:06 +03001036 RX_MSDU_START_INFO1_DECAP_FORMAT);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001037 enctype = MS(__le32_to_cpu(rxd->mpdu_start.info0),
Kalle Valo5b07e072014-09-14 12:50:06 +03001038 RX_MPDU_START_INFO0_ENCRYPT_TYPE);
Michal Kaziore3fbf8d2013-09-26 10:12:23 +03001039 hdr = (struct ieee80211_hdr *)rxd->rx_hdr_status;
1040 hdr_len = ieee80211_hdrlen(hdr->frame_control);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001041
Michal Kaziorf6dc2092013-09-26 10:12:22 +03001042 skb->ip_summed = ath10k_htt_rx_get_csum_state(skb);
1043
Kalle Valo5e3dd152013-06-12 20:52:10 +03001044 switch (fmt) {
1045 case RX_MSDU_DECAP_RAW:
1046 /* remove trailing FCS */
Michal Kaziore3fbf8d2013-09-26 10:12:23 +03001047 skb_trim(skb, skb->len - FCS_LEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001048 break;
1049 case RX_MSDU_DECAP_NATIVE_WIFI:
Michal Kazior784f69d2013-09-26 10:12:23 +03001050 /* Pull decapped header */
1051 hdr = (struct ieee80211_hdr *)skb->data;
Michal Kaziord960c362014-02-25 09:29:57 +02001052 hdr_len = ath10k_htt_rx_nwifi_hdrlen(hdr);
Michal Kazior784f69d2013-09-26 10:12:23 +03001053 skb_pull(skb, hdr_len);
1054
1055 /* Push original header */
1056 hdr = (struct ieee80211_hdr *)rxd->rx_hdr_status;
1057 hdr_len = ieee80211_hdrlen(hdr->frame_control);
1058 memcpy(skb_push(skb, hdr_len), hdr, hdr_len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001059 break;
1060 case RX_MSDU_DECAP_ETHERNET2_DIX:
Michal Kaziore3fbf8d2013-09-26 10:12:23 +03001061 /* strip ethernet header and insert decapped 802.11 header and
1062 * rfc1042 header */
1063
1064 rfc1042 = hdr;
1065 rfc1042 += roundup(hdr_len, 4);
Michal Kazior7aa7a722014-08-25 12:09:38 +02001066 rfc1042 += roundup(ath10k_htt_rx_crypto_param_len(ar,
1067 enctype), 4);
Michal Kaziore3fbf8d2013-09-26 10:12:23 +03001068
1069 skb_pull(skb, sizeof(struct ethhdr));
1070 memcpy(skb_push(skb, sizeof(struct rfc1042_hdr)),
1071 rfc1042, sizeof(struct rfc1042_hdr));
1072 memcpy(skb_push(skb, hdr_len), hdr, hdr_len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001073 break;
1074 case RX_MSDU_DECAP_8023_SNAP_LLC:
Michal Kaziore3fbf8d2013-09-26 10:12:23 +03001075 /* remove A-MSDU subframe header and insert
1076 * decapped 802.11 header. rfc1042 header is already there */
1077
1078 skb_pull(skb, sizeof(struct amsdu_subframe_hdr));
1079 memcpy(skb_push(skb, hdr_len), hdr, hdr_len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001080 break;
1081 }
1082
Michal Kaziorc071dcb2014-05-23 11:33:18 +03001083 ath10k_htt_rx_h_protected(htt, rx_status, skb, enctype, fmt, false);
Michal Kaziorf6dc2092013-09-26 10:12:22 +03001084
Janusz Dziedzic85f6d7c2014-03-24 21:23:22 +01001085 ath10k_process_rx(htt->ar, rx_status, skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001086}
1087
Michal Kazior605f81a2013-07-31 10:47:56 +02001088static int ath10k_htt_rx_get_csum_state(struct sk_buff *skb)
1089{
1090 struct htt_rx_desc *rxd;
1091 u32 flags, info;
1092 bool is_ip4, is_ip6;
1093 bool is_tcp, is_udp;
1094 bool ip_csum_ok, tcpudp_csum_ok;
1095
1096 rxd = (void *)skb->data - sizeof(*rxd);
1097 flags = __le32_to_cpu(rxd->attention.flags);
1098 info = __le32_to_cpu(rxd->msdu_start.info1);
1099
1100 is_ip4 = !!(info & RX_MSDU_START_INFO1_IPV4_PROTO);
1101 is_ip6 = !!(info & RX_MSDU_START_INFO1_IPV6_PROTO);
1102 is_tcp = !!(info & RX_MSDU_START_INFO1_TCP_PROTO);
1103 is_udp = !!(info & RX_MSDU_START_INFO1_UDP_PROTO);
1104 ip_csum_ok = !(flags & RX_ATTENTION_FLAGS_IP_CHKSUM_FAIL);
1105 tcpudp_csum_ok = !(flags & RX_ATTENTION_FLAGS_TCP_UDP_CHKSUM_FAIL);
1106
1107 if (!is_ip4 && !is_ip6)
1108 return CHECKSUM_NONE;
1109 if (!is_tcp && !is_udp)
1110 return CHECKSUM_NONE;
1111 if (!ip_csum_ok)
1112 return CHECKSUM_NONE;
1113 if (!tcpudp_csum_ok)
1114 return CHECKSUM_NONE;
1115
1116 return CHECKSUM_UNNECESSARY;
1117}
1118
Ben Greearbfa35362014-03-03 14:07:09 -08001119static int ath10k_unchain_msdu(struct sk_buff *msdu_head)
1120{
1121 struct sk_buff *next = msdu_head->next;
1122 struct sk_buff *to_free = next;
1123 int space;
1124 int total_len = 0;
1125
1126 /* TODO: Might could optimize this by using
1127 * skb_try_coalesce or similar method to
1128 * decrease copying, or maybe get mac80211 to
1129 * provide a way to just receive a list of
1130 * skb?
1131 */
1132
1133 msdu_head->next = NULL;
1134
1135 /* Allocate total length all at once. */
1136 while (next) {
1137 total_len += next->len;
1138 next = next->next;
1139 }
1140
1141 space = total_len - skb_tailroom(msdu_head);
1142 if ((space > 0) &&
1143 (pskb_expand_head(msdu_head, 0, space, GFP_ATOMIC) < 0)) {
1144 /* TODO: bump some rx-oom error stat */
1145 /* put it back together so we can free the
1146 * whole list at once.
1147 */
1148 msdu_head->next = to_free;
1149 return -1;
1150 }
1151
1152 /* Walk list again, copying contents into
1153 * msdu_head
1154 */
1155 next = to_free;
1156 while (next) {
1157 skb_copy_from_linear_data(next, skb_put(msdu_head, next->len),
1158 next->len);
1159 next = next->next;
1160 }
1161
1162 /* If here, we have consolidated skb. Free the
1163 * fragments and pass the main skb on up the
1164 * stack.
1165 */
1166 ath10k_htt_rx_free_msdu_chain(to_free);
1167 return 0;
1168}
1169
Janusz Dziedzic2acc4eb2014-03-19 07:09:40 +01001170static bool ath10k_htt_rx_amsdu_allowed(struct ath10k_htt *htt,
1171 struct sk_buff *head,
Janusz Dziedzic87326c92014-03-24 21:23:19 +01001172 enum htt_rx_mpdu_status status,
Janusz Dziedzic78433f92014-03-24 21:23:21 +01001173 bool channel_set,
1174 u32 attention)
Janusz Dziedzic2acc4eb2014-03-19 07:09:40 +01001175{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001176 struct ath10k *ar = htt->ar;
1177
Janusz Dziedzic2acc4eb2014-03-19 07:09:40 +01001178 if (head->len == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001179 ath10k_dbg(ar, ATH10K_DBG_HTT,
Janusz Dziedzic2acc4eb2014-03-19 07:09:40 +01001180 "htt rx dropping due to zero-len\n");
1181 return false;
1182 }
1183
Janusz Dziedzic78433f92014-03-24 21:23:21 +01001184 if (attention & RX_ATTENTION_FLAGS_DECRYPT_ERR) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001185 ath10k_dbg(ar, ATH10K_DBG_HTT,
Janusz Dziedzic2acc4eb2014-03-19 07:09:40 +01001186 "htt rx dropping due to decrypt-err\n");
1187 return false;
1188 }
1189
Janusz Dziedzic36653f02014-03-24 21:23:18 +01001190 if (!channel_set) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001191 ath10k_warn(ar, "no channel configured; ignoring frame!\n");
Janusz Dziedzic36653f02014-03-24 21:23:18 +01001192 return false;
1193 }
1194
Janusz Dziedzic2acc4eb2014-03-19 07:09:40 +01001195 /* Skip mgmt frames while we handle this in WMI */
1196 if (status == HTT_RX_IND_MPDU_STATUS_MGMT_CTRL ||
Janusz Dziedzic78433f92014-03-24 21:23:21 +01001197 attention & RX_ATTENTION_FLAGS_MGMT_TYPE) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001198 ath10k_dbg(ar, ATH10K_DBG_HTT, "htt rx mgmt ctrl\n");
Janusz Dziedzic2acc4eb2014-03-19 07:09:40 +01001199 return false;
1200 }
1201
1202 if (status != HTT_RX_IND_MPDU_STATUS_OK &&
1203 status != HTT_RX_IND_MPDU_STATUS_TKIP_MIC_ERR &&
1204 status != HTT_RX_IND_MPDU_STATUS_ERR_INV_PEER &&
Michal Kazior1bbc0972014-04-08 09:45:47 +03001205 !htt->ar->monitor_started) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001206 ath10k_dbg(ar, ATH10K_DBG_HTT,
Janusz Dziedzic2acc4eb2014-03-19 07:09:40 +01001207 "htt rx ignoring frame w/ status %d\n",
1208 status);
1209 return false;
1210 }
1211
1212 if (test_bit(ATH10K_CAC_RUNNING, &htt->ar->dev_flags)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001213 ath10k_dbg(ar, ATH10K_DBG_HTT,
Janusz Dziedzic2acc4eb2014-03-19 07:09:40 +01001214 "htt rx CAC running\n");
1215 return false;
1216 }
1217
1218 return true;
1219}
1220
Kalle Valo5e3dd152013-06-12 20:52:10 +03001221static void ath10k_htt_rx_handler(struct ath10k_htt *htt,
1222 struct htt_rx_indication *rx)
1223{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001224 struct ath10k *ar = htt->ar;
Janusz Dziedzic6df92a32014-03-24 21:24:57 +01001225 struct ieee80211_rx_status *rx_status = &htt->rx_status;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001226 struct htt_rx_indication_mpdu_range *mpdu_ranges;
Janusz Dziedzic78433f92014-03-24 21:23:21 +01001227 struct htt_rx_desc *rxd;
Janusz Dziedzic87326c92014-03-24 21:23:19 +01001228 enum htt_rx_mpdu_status status;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001229 struct ieee80211_hdr *hdr;
1230 int num_mpdu_ranges;
Janusz Dziedzic78433f92014-03-24 21:23:21 +01001231 u32 attention;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001232 int fw_desc_len;
1233 u8 *fw_desc;
Janusz Dziedzic78433f92014-03-24 21:23:21 +01001234 bool channel_set;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001235 int i, j;
Janusz Dziedzicd84dd602014-03-24 21:23:20 +01001236 int ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001237
Michal Kazior45967082014-02-27 18:50:05 +02001238 lockdep_assert_held(&htt->rx_ring.lock);
1239
Kalle Valo5e3dd152013-06-12 20:52:10 +03001240 fw_desc_len = __le16_to_cpu(rx->prefix.fw_rx_desc_bytes);
1241 fw_desc = (u8 *)&rx->fw_desc;
1242
1243 num_mpdu_ranges = MS(__le32_to_cpu(rx->hdr.info1),
1244 HTT_RX_INDICATION_INFO1_NUM_MPDU_RANGES);
1245 mpdu_ranges = htt_rx_ind_get_mpdu_ranges(rx);
1246
Janusz Dziedzice8dc1a92014-03-19 07:09:41 +01001247 /* Fill this once, while this is per-ppdu */
Janusz Dziedzic22891882014-03-24 21:24:58 +01001248 if (rx->ppdu.info0 & HTT_RX_INDICATION_INFO0_START_VALID) {
1249 memset(rx_status, 0, sizeof(*rx_status));
1250 rx_status->signal = ATH10K_DEFAULT_NOISE_FLOOR +
1251 rx->ppdu.combined_rssi;
1252 }
Janusz Dziedzic87326c92014-03-24 21:23:19 +01001253
1254 if (rx->ppdu.info0 & HTT_RX_INDICATION_INFO0_END_VALID) {
1255 /* TSF available only in 32-bit */
Janusz Dziedzic6df92a32014-03-24 21:24:57 +01001256 rx_status->mactime = __le32_to_cpu(rx->ppdu.tsf) & 0xffffffff;
1257 rx_status->flag |= RX_FLAG_MACTIME_END;
Janusz Dziedzic87326c92014-03-24 21:23:19 +01001258 }
Janusz Dziedzice8dc1a92014-03-19 07:09:41 +01001259
Janusz Dziedzic6df92a32014-03-24 21:24:57 +01001260 channel_set = ath10k_htt_rx_h_channel(htt->ar, rx_status);
Janusz Dziedzic36653f02014-03-24 21:23:18 +01001261
Janusz Dziedzic87326c92014-03-24 21:23:19 +01001262 if (channel_set) {
Janusz Dziedzic6df92a32014-03-24 21:24:57 +01001263 ath10k_htt_rx_h_rates(htt->ar, rx_status->band,
Janusz Dziedzic87326c92014-03-24 21:23:19 +01001264 rx->ppdu.info0,
1265 __le32_to_cpu(rx->ppdu.info1),
1266 __le32_to_cpu(rx->ppdu.info2),
Janusz Dziedzic6df92a32014-03-24 21:24:57 +01001267 rx_status);
Janusz Dziedzic87326c92014-03-24 21:23:19 +01001268 }
Janusz Dziedzice8dc1a92014-03-19 07:09:41 +01001269
Michal Kazior7aa7a722014-08-25 12:09:38 +02001270 ath10k_dbg_dump(ar, ATH10K_DBG_HTT_DUMP, NULL, "htt rx ind: ",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001271 rx, sizeof(*rx) +
1272 (sizeof(struct htt_rx_indication_mpdu_range) *
1273 num_mpdu_ranges));
1274
1275 for (i = 0; i < num_mpdu_ranges; i++) {
Janusz Dziedzic87326c92014-03-24 21:23:19 +01001276 status = mpdu_ranges[i].mpdu_range_status;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001277
1278 for (j = 0; j < mpdu_ranges[i].mpdu_count; j++) {
1279 struct sk_buff *msdu_head, *msdu_tail;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001280
Janusz Dziedzic0ccb7a32014-07-25 11:28:50 +03001281 attention = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001282 msdu_head = NULL;
1283 msdu_tail = NULL;
Janusz Dziedzicd84dd602014-03-24 21:23:20 +01001284 ret = ath10k_htt_rx_amsdu_pop(htt,
1285 &fw_desc,
1286 &fw_desc_len,
1287 &msdu_head,
Janusz Dziedzic0ccb7a32014-07-25 11:28:50 +03001288 &msdu_tail,
1289 &attention);
Janusz Dziedzicd84dd602014-03-24 21:23:20 +01001290
1291 if (ret < 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001292 ath10k_warn(ar, "failed to pop amsdu from htt rx ring %d\n",
Janusz Dziedzicd84dd602014-03-24 21:23:20 +01001293 ret);
1294 ath10k_htt_rx_free_msdu_chain(msdu_head);
1295 continue;
1296 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001297
Janusz Dziedzic78433f92014-03-24 21:23:21 +01001298 rxd = container_of((void *)msdu_head->data,
1299 struct htt_rx_desc,
1300 msdu_payload);
Janusz Dziedzic78433f92014-03-24 21:23:21 +01001301
Janusz Dziedzic2acc4eb2014-03-19 07:09:40 +01001302 if (!ath10k_htt_rx_amsdu_allowed(htt, msdu_head,
Janusz Dziedzic87326c92014-03-24 21:23:19 +01001303 status,
Janusz Dziedzic78433f92014-03-24 21:23:21 +01001304 channel_set,
1305 attention)) {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001306 ath10k_htt_rx_free_msdu_chain(msdu_head);
1307 continue;
1308 }
1309
Janusz Dziedzicd84dd602014-03-24 21:23:20 +01001310 if (ret > 0 &&
1311 ath10k_unchain_msdu(msdu_head) < 0) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001312 ath10k_htt_rx_free_msdu_chain(msdu_head);
1313 continue;
1314 }
1315
Janusz Dziedzic78433f92014-03-24 21:23:21 +01001316 if (attention & RX_ATTENTION_FLAGS_FCS_ERR)
Janusz Dziedzic6df92a32014-03-24 21:24:57 +01001317 rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
Janusz Dziedzic87326c92014-03-24 21:23:19 +01001318 else
Janusz Dziedzic6df92a32014-03-24 21:24:57 +01001319 rx_status->flag &= ~RX_FLAG_FAILED_FCS_CRC;
Janusz Dziedzic87326c92014-03-24 21:23:19 +01001320
Janusz Dziedzic78433f92014-03-24 21:23:21 +01001321 if (attention & RX_ATTENTION_FLAGS_TKIP_MIC_ERR)
Janusz Dziedzic6df92a32014-03-24 21:24:57 +01001322 rx_status->flag |= RX_FLAG_MMIC_ERROR;
Janusz Dziedzic87326c92014-03-24 21:23:19 +01001323 else
Janusz Dziedzic6df92a32014-03-24 21:24:57 +01001324 rx_status->flag &= ~RX_FLAG_MMIC_ERROR;
Janusz Dziedzic87326c92014-03-24 21:23:19 +01001325
Kalle Valo5e3dd152013-06-12 20:52:10 +03001326 hdr = ath10k_htt_rx_skb_get_hdr(msdu_head);
1327
1328 if (ath10k_htt_rx_hdr_is_amsdu(hdr))
Janusz Dziedzic6df92a32014-03-24 21:24:57 +01001329 ath10k_htt_rx_amsdu(htt, rx_status, msdu_head);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001330 else
Janusz Dziedzic6df92a32014-03-24 21:24:57 +01001331 ath10k_htt_rx_msdu(htt, rx_status, msdu_head);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001332 }
1333 }
1334
Michal Kazior6e712d42013-09-24 10:18:36 +02001335 tasklet_schedule(&htt->rx_replenish_task);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001336}
1337
1338static void ath10k_htt_rx_frag_handler(struct ath10k_htt *htt,
Kalle Valo5b07e072014-09-14 12:50:06 +03001339 struct htt_rx_fragment_indication *frag)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001340{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001341 struct ath10k *ar = htt->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001342 struct sk_buff *msdu_head, *msdu_tail;
Janusz Dziedzic87326c92014-03-24 21:23:19 +01001343 enum htt_rx_mpdu_encrypt_type enctype;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001344 struct htt_rx_desc *rxd;
1345 enum rx_msdu_decap_format fmt;
Janusz Dziedzic6df92a32014-03-24 21:24:57 +01001346 struct ieee80211_rx_status *rx_status = &htt->rx_status;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001347 struct ieee80211_hdr *hdr;
Janusz Dziedzicd84dd602014-03-24 21:23:20 +01001348 int ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001349 bool tkip_mic_err;
1350 bool decrypt_err;
1351 u8 *fw_desc;
1352 int fw_desc_len, hdrlen, paramlen;
1353 int trim;
Janusz Dziedzic0ccb7a32014-07-25 11:28:50 +03001354 u32 attention = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001355
1356 fw_desc_len = __le16_to_cpu(frag->fw_rx_desc_bytes);
1357 fw_desc = (u8 *)frag->fw_msdu_rx_desc;
1358
1359 msdu_head = NULL;
1360 msdu_tail = NULL;
Michal Kazior45967082014-02-27 18:50:05 +02001361
1362 spin_lock_bh(&htt->rx_ring.lock);
Janusz Dziedzicd84dd602014-03-24 21:23:20 +01001363 ret = ath10k_htt_rx_amsdu_pop(htt, &fw_desc, &fw_desc_len,
Janusz Dziedzic0ccb7a32014-07-25 11:28:50 +03001364 &msdu_head, &msdu_tail,
1365 &attention);
Michal Kazior45967082014-02-27 18:50:05 +02001366 spin_unlock_bh(&htt->rx_ring.lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001367
Michal Kazior7aa7a722014-08-25 12:09:38 +02001368 ath10k_dbg(ar, ATH10K_DBG_HTT_DUMP, "htt rx frag ahead\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03001369
Janusz Dziedzicd84dd602014-03-24 21:23:20 +01001370 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001371 ath10k_warn(ar, "failed to pop amsdu from httr rx ring for fragmented rx %d\n",
Janusz Dziedzicd84dd602014-03-24 21:23:20 +01001372 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001373 ath10k_htt_rx_free_msdu_chain(msdu_head);
1374 return;
1375 }
1376
1377 /* FIXME: implement signal strength */
Ben Greear4b81d172014-05-26 12:46:04 +03001378 rx_status->flag |= RX_FLAG_NO_SIGNAL_VAL;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001379
1380 hdr = (struct ieee80211_hdr *)msdu_head->data;
1381 rxd = (void *)msdu_head->data - sizeof(*rxd);
Janusz Dziedzic0ccb7a32014-07-25 11:28:50 +03001382 tkip_mic_err = !!(attention & RX_ATTENTION_FLAGS_TKIP_MIC_ERR);
1383 decrypt_err = !!(attention & RX_ATTENTION_FLAGS_DECRYPT_ERR);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001384 fmt = MS(__le32_to_cpu(rxd->msdu_start.info1),
Kalle Valo5b07e072014-09-14 12:50:06 +03001385 RX_MSDU_START_INFO1_DECAP_FORMAT);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001386
1387 if (fmt != RX_MSDU_DECAP_RAW) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001388 ath10k_warn(ar, "we dont support non-raw fragmented rx yet\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03001389 dev_kfree_skb_any(msdu_head);
1390 goto end;
1391 }
1392
Janusz Dziedzic87326c92014-03-24 21:23:19 +01001393 enctype = MS(__le32_to_cpu(rxd->mpdu_start.info0),
1394 RX_MPDU_START_INFO0_ENCRYPT_TYPE);
Michal Kaziorc071dcb2014-05-23 11:33:18 +03001395 ath10k_htt_rx_h_protected(htt, rx_status, msdu_head, enctype, fmt,
1396 true);
Janusz Dziedzic85f6d7c2014-03-24 21:23:22 +01001397 msdu_head->ip_summed = ath10k_htt_rx_get_csum_state(msdu_head);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001398
Janusz Dziedzic87326c92014-03-24 21:23:19 +01001399 if (tkip_mic_err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001400 ath10k_warn(ar, "tkip mic error\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03001401
1402 if (decrypt_err) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001403 ath10k_warn(ar, "decryption err in fragmented rx\n");
Janusz Dziedzic85f6d7c2014-03-24 21:23:22 +01001404 dev_kfree_skb_any(msdu_head);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001405 goto end;
1406 }
1407
Janusz Dziedzic87326c92014-03-24 21:23:19 +01001408 if (enctype != HTT_RX_MPDU_ENCRYPT_NONE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001409 hdrlen = ieee80211_hdrlen(hdr->frame_control);
Michal Kazior7aa7a722014-08-25 12:09:38 +02001410 paramlen = ath10k_htt_rx_crypto_param_len(ar, enctype);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001411
1412 /* It is more efficient to move the header than the payload */
Janusz Dziedzic85f6d7c2014-03-24 21:23:22 +01001413 memmove((void *)msdu_head->data + paramlen,
1414 (void *)msdu_head->data,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001415 hdrlen);
Janusz Dziedzic85f6d7c2014-03-24 21:23:22 +01001416 skb_pull(msdu_head, paramlen);
1417 hdr = (struct ieee80211_hdr *)msdu_head->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001418 }
1419
1420 /* remove trailing FCS */
1421 trim = 4;
1422
1423 /* remove crypto trailer */
Michal Kazior7aa7a722014-08-25 12:09:38 +02001424 trim += ath10k_htt_rx_crypto_tail_len(ar, enctype);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001425
1426 /* last fragment of TKIP frags has MIC */
1427 if (!ieee80211_has_morefrags(hdr->frame_control) &&
Janusz Dziedzic87326c92014-03-24 21:23:19 +01001428 enctype == HTT_RX_MPDU_ENCRYPT_TKIP_WPA)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001429 trim += 8;
1430
Janusz Dziedzic85f6d7c2014-03-24 21:23:22 +01001431 if (trim > msdu_head->len) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001432 ath10k_warn(ar, "htt rx fragment: trailer longer than the frame itself? drop\n");
Janusz Dziedzic85f6d7c2014-03-24 21:23:22 +01001433 dev_kfree_skb_any(msdu_head);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001434 goto end;
1435 }
1436
Janusz Dziedzic85f6d7c2014-03-24 21:23:22 +01001437 skb_trim(msdu_head, msdu_head->len - trim);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001438
Michal Kazior7aa7a722014-08-25 12:09:38 +02001439 ath10k_dbg_dump(ar, ATH10K_DBG_HTT_DUMP, NULL, "htt rx frag mpdu: ",
Janusz Dziedzic85f6d7c2014-03-24 21:23:22 +01001440 msdu_head->data, msdu_head->len);
Janusz Dziedzic6df92a32014-03-24 21:24:57 +01001441 ath10k_process_rx(htt->ar, rx_status, msdu_head);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001442
1443end:
1444 if (fw_desc_len > 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001445 ath10k_dbg(ar, ATH10K_DBG_HTT,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001446 "expecting more fragmented rx in one indication %d\n",
1447 fw_desc_len);
1448 }
1449}
1450
Michal Kazior6c5151a2014-02-27 18:50:04 +02001451static void ath10k_htt_rx_frm_tx_compl(struct ath10k *ar,
1452 struct sk_buff *skb)
1453{
1454 struct ath10k_htt *htt = &ar->htt;
1455 struct htt_resp *resp = (struct htt_resp *)skb->data;
1456 struct htt_tx_done tx_done = {};
1457 int status = MS(resp->data_tx_completion.flags, HTT_DATA_TX_STATUS);
1458 __le16 msdu_id;
1459 int i;
1460
Michal Kazior45967082014-02-27 18:50:05 +02001461 lockdep_assert_held(&htt->tx_lock);
1462
Michal Kazior6c5151a2014-02-27 18:50:04 +02001463 switch (status) {
1464 case HTT_DATA_TX_STATUS_NO_ACK:
1465 tx_done.no_ack = true;
1466 break;
1467 case HTT_DATA_TX_STATUS_OK:
1468 break;
1469 case HTT_DATA_TX_STATUS_DISCARD:
1470 case HTT_DATA_TX_STATUS_POSTPONE:
1471 case HTT_DATA_TX_STATUS_DOWNLOAD_FAIL:
1472 tx_done.discard = true;
1473 break;
1474 default:
Michal Kazior7aa7a722014-08-25 12:09:38 +02001475 ath10k_warn(ar, "unhandled tx completion status %d\n", status);
Michal Kazior6c5151a2014-02-27 18:50:04 +02001476 tx_done.discard = true;
1477 break;
1478 }
1479
Michal Kazior7aa7a722014-08-25 12:09:38 +02001480 ath10k_dbg(ar, ATH10K_DBG_HTT, "htt tx completion num_msdus %d\n",
Michal Kazior6c5151a2014-02-27 18:50:04 +02001481 resp->data_tx_completion.num_msdus);
1482
1483 for (i = 0; i < resp->data_tx_completion.num_msdus; i++) {
1484 msdu_id = resp->data_tx_completion.msdus[i];
1485 tx_done.msdu_id = __le16_to_cpu(msdu_id);
1486 ath10k_txrx_tx_unref(htt, &tx_done);
1487 }
1488}
1489
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02001490static void ath10k_htt_rx_addba(struct ath10k *ar, struct htt_resp *resp)
1491{
1492 struct htt_rx_addba *ev = &resp->rx_addba;
1493 struct ath10k_peer *peer;
1494 struct ath10k_vif *arvif;
1495 u16 info0, tid, peer_id;
1496
1497 info0 = __le16_to_cpu(ev->info0);
1498 tid = MS(info0, HTT_RX_BA_INFO0_TID);
1499 peer_id = MS(info0, HTT_RX_BA_INFO0_PEER_ID);
1500
Michal Kazior7aa7a722014-08-25 12:09:38 +02001501 ath10k_dbg(ar, ATH10K_DBG_HTT,
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02001502 "htt rx addba tid %hu peer_id %hu size %hhu\n",
1503 tid, peer_id, ev->window_size);
1504
1505 spin_lock_bh(&ar->data_lock);
1506 peer = ath10k_peer_find_by_id(ar, peer_id);
1507 if (!peer) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001508 ath10k_warn(ar, "received addba event for invalid peer_id: %hu\n",
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02001509 peer_id);
1510 spin_unlock_bh(&ar->data_lock);
1511 return;
1512 }
1513
1514 arvif = ath10k_get_arvif(ar, peer->vdev_id);
1515 if (!arvif) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001516 ath10k_warn(ar, "received addba event for invalid vdev_id: %u\n",
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02001517 peer->vdev_id);
1518 spin_unlock_bh(&ar->data_lock);
1519 return;
1520 }
1521
Michal Kazior7aa7a722014-08-25 12:09:38 +02001522 ath10k_dbg(ar, ATH10K_DBG_HTT,
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02001523 "htt rx start rx ba session sta %pM tid %hu size %hhu\n",
1524 peer->addr, tid, ev->window_size);
1525
1526 ieee80211_start_rx_ba_session_offl(arvif->vif, peer->addr, tid);
1527 spin_unlock_bh(&ar->data_lock);
1528}
1529
1530static void ath10k_htt_rx_delba(struct ath10k *ar, struct htt_resp *resp)
1531{
1532 struct htt_rx_delba *ev = &resp->rx_delba;
1533 struct ath10k_peer *peer;
1534 struct ath10k_vif *arvif;
1535 u16 info0, tid, peer_id;
1536
1537 info0 = __le16_to_cpu(ev->info0);
1538 tid = MS(info0, HTT_RX_BA_INFO0_TID);
1539 peer_id = MS(info0, HTT_RX_BA_INFO0_PEER_ID);
1540
Michal Kazior7aa7a722014-08-25 12:09:38 +02001541 ath10k_dbg(ar, ATH10K_DBG_HTT,
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02001542 "htt rx delba tid %hu peer_id %hu\n",
1543 tid, peer_id);
1544
1545 spin_lock_bh(&ar->data_lock);
1546 peer = ath10k_peer_find_by_id(ar, peer_id);
1547 if (!peer) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001548 ath10k_warn(ar, "received addba event for invalid peer_id: %hu\n",
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02001549 peer_id);
1550 spin_unlock_bh(&ar->data_lock);
1551 return;
1552 }
1553
1554 arvif = ath10k_get_arvif(ar, peer->vdev_id);
1555 if (!arvif) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001556 ath10k_warn(ar, "received addba event for invalid vdev_id: %u\n",
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02001557 peer->vdev_id);
1558 spin_unlock_bh(&ar->data_lock);
1559 return;
1560 }
1561
Michal Kazior7aa7a722014-08-25 12:09:38 +02001562 ath10k_dbg(ar, ATH10K_DBG_HTT,
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02001563 "htt rx stop rx ba session sta %pM tid %hu\n",
1564 peer->addr, tid);
1565
1566 ieee80211_stop_rx_ba_session_offl(arvif->vif, peer->addr, tid);
1567 spin_unlock_bh(&ar->data_lock);
1568}
1569
Kalle Valo5e3dd152013-06-12 20:52:10 +03001570void ath10k_htt_t2h_msg_handler(struct ath10k *ar, struct sk_buff *skb)
1571{
Michal Kazioredb82362013-07-05 16:15:14 +03001572 struct ath10k_htt *htt = &ar->htt;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001573 struct htt_resp *resp = (struct htt_resp *)skb->data;
1574
1575 /* confirm alignment */
1576 if (!IS_ALIGNED((unsigned long)skb->data, 4))
Michal Kazior7aa7a722014-08-25 12:09:38 +02001577 ath10k_warn(ar, "unaligned htt message, expect trouble\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03001578
Michal Kazior7aa7a722014-08-25 12:09:38 +02001579 ath10k_dbg(ar, ATH10K_DBG_HTT, "htt rx, msg_type: 0x%0X\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001580 resp->hdr.msg_type);
1581 switch (resp->hdr.msg_type) {
1582 case HTT_T2H_MSG_TYPE_VERSION_CONF: {
1583 htt->target_version_major = resp->ver_resp.major;
1584 htt->target_version_minor = resp->ver_resp.minor;
1585 complete(&htt->target_version_received);
1586 break;
1587 }
Michal Kazior6c5151a2014-02-27 18:50:04 +02001588 case HTT_T2H_MSG_TYPE_RX_IND:
Michal Kazior45967082014-02-27 18:50:05 +02001589 spin_lock_bh(&htt->rx_ring.lock);
1590 __skb_queue_tail(&htt->rx_compl_q, skb);
1591 spin_unlock_bh(&htt->rx_ring.lock);
Michal Kazior6c5151a2014-02-27 18:50:04 +02001592 tasklet_schedule(&htt->txrx_compl_task);
1593 return;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001594 case HTT_T2H_MSG_TYPE_PEER_MAP: {
1595 struct htt_peer_map_event ev = {
1596 .vdev_id = resp->peer_map.vdev_id,
1597 .peer_id = __le16_to_cpu(resp->peer_map.peer_id),
1598 };
1599 memcpy(ev.addr, resp->peer_map.addr, sizeof(ev.addr));
1600 ath10k_peer_map_event(htt, &ev);
1601 break;
1602 }
1603 case HTT_T2H_MSG_TYPE_PEER_UNMAP: {
1604 struct htt_peer_unmap_event ev = {
1605 .peer_id = __le16_to_cpu(resp->peer_unmap.peer_id),
1606 };
1607 ath10k_peer_unmap_event(htt, &ev);
1608 break;
1609 }
1610 case HTT_T2H_MSG_TYPE_MGMT_TX_COMPLETION: {
1611 struct htt_tx_done tx_done = {};
1612 int status = __le32_to_cpu(resp->mgmt_tx_completion.status);
1613
1614 tx_done.msdu_id =
1615 __le32_to_cpu(resp->mgmt_tx_completion.desc_id);
1616
1617 switch (status) {
1618 case HTT_MGMT_TX_STATUS_OK:
1619 break;
1620 case HTT_MGMT_TX_STATUS_RETRY:
1621 tx_done.no_ack = true;
1622 break;
1623 case HTT_MGMT_TX_STATUS_DROP:
1624 tx_done.discard = true;
1625 break;
1626 }
1627
Michal Kazior6c5151a2014-02-27 18:50:04 +02001628 spin_lock_bh(&htt->tx_lock);
Michal Kazior0a89f8a2013-09-18 14:43:20 +02001629 ath10k_txrx_tx_unref(htt, &tx_done);
Michal Kazior6c5151a2014-02-27 18:50:04 +02001630 spin_unlock_bh(&htt->tx_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001631 break;
1632 }
Michal Kazior6c5151a2014-02-27 18:50:04 +02001633 case HTT_T2H_MSG_TYPE_TX_COMPL_IND:
1634 spin_lock_bh(&htt->tx_lock);
1635 __skb_queue_tail(&htt->tx_compl_q, skb);
1636 spin_unlock_bh(&htt->tx_lock);
1637 tasklet_schedule(&htt->txrx_compl_task);
1638 return;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001639 case HTT_T2H_MSG_TYPE_SEC_IND: {
1640 struct ath10k *ar = htt->ar;
1641 struct htt_security_indication *ev = &resp->security_indication;
1642
Michal Kazior7aa7a722014-08-25 12:09:38 +02001643 ath10k_dbg(ar, ATH10K_DBG_HTT,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001644 "sec ind peer_id %d unicast %d type %d\n",
1645 __le16_to_cpu(ev->peer_id),
1646 !!(ev->flags & HTT_SECURITY_IS_UNICAST),
1647 MS(ev->flags, HTT_SECURITY_TYPE));
1648 complete(&ar->install_key_done);
1649 break;
1650 }
1651 case HTT_T2H_MSG_TYPE_RX_FRAG_IND: {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001652 ath10k_dbg_dump(ar, ATH10K_DBG_HTT_DUMP, NULL, "htt event: ",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001653 skb->data, skb->len);
1654 ath10k_htt_rx_frag_handler(htt, &resp->rx_frag_ind);
1655 break;
1656 }
1657 case HTT_T2H_MSG_TYPE_TEST:
1658 /* FIX THIS */
1659 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001660 case HTT_T2H_MSG_TYPE_STATS_CONF:
Michal Kaziord35a6c12014-09-02 11:00:21 +03001661 trace_ath10k_htt_stats(ar, skb->data, skb->len);
Kalle Valoa9bf0502013-09-03 11:43:55 +03001662 break;
1663 case HTT_T2H_MSG_TYPE_TX_INSPECT_IND:
Michal Kazior708b9bd2014-07-21 20:52:59 +03001664 /* Firmware can return tx frames if it's unable to fully
1665 * process them and suspects host may be able to fix it. ath10k
1666 * sends all tx frames as already inspected so this shouldn't
1667 * happen unless fw has a bug.
1668 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02001669 ath10k_warn(ar, "received an unexpected htt tx inspect event\n");
Michal Kazior708b9bd2014-07-21 20:52:59 +03001670 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001671 case HTT_T2H_MSG_TYPE_RX_ADDBA:
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02001672 ath10k_htt_rx_addba(ar, resp);
1673 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001674 case HTT_T2H_MSG_TYPE_RX_DELBA:
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02001675 ath10k_htt_rx_delba(ar, resp);
1676 break;
Rajkumar Manoharanbfdd7932014-10-03 08:02:40 +03001677 case HTT_T2H_MSG_TYPE_PKTLOG: {
1678 struct ath10k_pktlog_hdr *hdr =
1679 (struct ath10k_pktlog_hdr *)resp->pktlog_msg.payload;
1680
1681 trace_ath10k_htt_pktlog(ar, resp->pktlog_msg.payload,
1682 sizeof(*hdr) +
1683 __le16_to_cpu(hdr->size));
1684 break;
1685 }
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02001686 case HTT_T2H_MSG_TYPE_RX_FLUSH: {
1687 /* Ignore this event because mac80211 takes care of Rx
1688 * aggregation reordering.
1689 */
1690 break;
1691 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001692 default:
Michal Kazior7aa7a722014-08-25 12:09:38 +02001693 ath10k_dbg(ar, ATH10K_DBG_HTT, "htt event (%d) not handled\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001694 resp->hdr.msg_type);
Michal Kazior7aa7a722014-08-25 12:09:38 +02001695 ath10k_dbg_dump(ar, ATH10K_DBG_HTT_DUMP, NULL, "htt event: ",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001696 skb->data, skb->len);
1697 break;
1698 };
1699
1700 /* Free the indication buffer */
1701 dev_kfree_skb_any(skb);
1702}
Michal Kazior6c5151a2014-02-27 18:50:04 +02001703
1704static void ath10k_htt_txrx_compl_task(unsigned long ptr)
1705{
1706 struct ath10k_htt *htt = (struct ath10k_htt *)ptr;
1707 struct htt_resp *resp;
1708 struct sk_buff *skb;
1709
Michal Kazior45967082014-02-27 18:50:05 +02001710 spin_lock_bh(&htt->tx_lock);
1711 while ((skb = __skb_dequeue(&htt->tx_compl_q))) {
Michal Kazior6c5151a2014-02-27 18:50:04 +02001712 ath10k_htt_rx_frm_tx_compl(htt->ar, skb);
1713 dev_kfree_skb_any(skb);
1714 }
Michal Kazior45967082014-02-27 18:50:05 +02001715 spin_unlock_bh(&htt->tx_lock);
Michal Kazior6c5151a2014-02-27 18:50:04 +02001716
Michal Kazior45967082014-02-27 18:50:05 +02001717 spin_lock_bh(&htt->rx_ring.lock);
1718 while ((skb = __skb_dequeue(&htt->rx_compl_q))) {
Michal Kazior6c5151a2014-02-27 18:50:04 +02001719 resp = (struct htt_resp *)skb->data;
1720 ath10k_htt_rx_handler(htt, &resp->rx_ind);
1721 dev_kfree_skb_any(skb);
1722 }
Michal Kazior45967082014-02-27 18:50:05 +02001723 spin_unlock_bh(&htt->rx_ring.lock);
Michal Kazior6c5151a2014-02-27 18:50:04 +02001724}