blob: f988a8db7bfdba511ddb05c5fd6e89cedfde80f6 [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
Michal Kazior4de02802014-10-23 17:04:23 +0300294 dma_unmap_single(htt->ar->dev,
295 ATH10K_SKB_CB(msdu)->paddr,
296 msdu->len + skb_tailroom(msdu),
297 DMA_FROM_DEVICE);
298 ath10k_dbg_dump(ar, ATH10K_DBG_HTT_DUMP, NULL, "htt rx netbuf pop: ",
299 msdu->data, msdu->len + skb_tailroom(msdu));
Michal Kazior4de02802014-10-23 17:04:23 +0300300
Kalle Valo5e3dd152013-06-12 20:52:10 +0300301 return msdu;
302}
303
Janusz Dziedzicd84dd602014-03-24 21:23:20 +0100304/* return: < 0 fatal error, 0 - non chained msdu, 1 chained msdu */
Kalle Valo5e3dd152013-06-12 20:52:10 +0300305static int ath10k_htt_rx_amsdu_pop(struct ath10k_htt *htt,
306 u8 **fw_desc, int *fw_desc_len,
Michal Kazior9aa505d2014-11-18 09:24:47 +0200307 struct sk_buff_head *amsdu,
Janusz Dziedzic0ccb7a32014-07-25 11:28:50 +0300308 u32 *attention)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300309{
Michal Kazior7aa7a722014-08-25 12:09:38 +0200310 struct ath10k *ar = htt->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300311 int msdu_len, msdu_chaining = 0;
Michal Kazior9aa505d2014-11-18 09:24:47 +0200312 struct sk_buff *msdu;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300313 struct htt_rx_desc *rx_desc;
314
Michal Kazior45967082014-02-27 18:50:05 +0200315 lockdep_assert_held(&htt->rx_ring.lock);
316
Kalle Valo5e3dd152013-06-12 20:52:10 +0300317 if (htt->rx_confused) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200318 ath10k_warn(ar, "htt is confused. refusing rx\n");
Janusz Dziedzicd84dd602014-03-24 21:23:20 +0100319 return -1;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300320 }
321
Michal Kazior9aa505d2014-11-18 09:24:47 +0200322 for (;;) {
Kalle Valo5e3dd152013-06-12 20:52:10 +0300323 int last_msdu, msdu_len_invalid, msdu_chained;
324
Michal Kazior9aa505d2014-11-18 09:24:47 +0200325 msdu = ath10k_htt_rx_netbuf_pop(htt);
326 if (!msdu) {
327 ath10k_err(ar, "failed to pop msdu\n");
328 __skb_queue_purge(amsdu);
329 htt->rx_confused = true;
330 break;
331 }
332
333 __skb_queue_tail(amsdu, msdu);
334
Kalle Valo5e3dd152013-06-12 20:52:10 +0300335 rx_desc = (struct htt_rx_desc *)msdu->data;
336
337 /* FIXME: we must report msdu payload since this is what caller
338 * expects now */
339 skb_put(msdu, offsetof(struct htt_rx_desc, msdu_payload));
340 skb_pull(msdu, offsetof(struct htt_rx_desc, msdu_payload));
341
342 /*
343 * Sanity check - confirm the HW is finished filling in the
344 * rx data.
345 * If the HW and SW are working correctly, then it's guaranteed
346 * that the HW's MAC DMA is done before this point in the SW.
347 * To prevent the case that we handle a stale Rx descriptor,
348 * just assert for now until we have a way to recover.
349 */
350 if (!(__le32_to_cpu(rx_desc->attention.flags)
351 & RX_ATTENTION_FLAGS_MSDU_DONE)) {
Michal Kazior9aa505d2014-11-18 09:24:47 +0200352 ath10k_err(ar, "popped an incomplete msdu\n");
353 __skb_queue_purge(amsdu);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300354 htt->rx_confused = true;
355 break;
356 }
357
Janusz Dziedzic0ccb7a32014-07-25 11:28:50 +0300358 *attention |= __le32_to_cpu(rx_desc->attention.flags) &
359 (RX_ATTENTION_FLAGS_TKIP_MIC_ERR |
360 RX_ATTENTION_FLAGS_DECRYPT_ERR |
361 RX_ATTENTION_FLAGS_FCS_ERR |
362 RX_ATTENTION_FLAGS_MGMT_TYPE);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300363 /*
364 * Copy the FW rx descriptor for this MSDU from the rx
365 * indication message into the MSDU's netbuf. HL uses the
366 * same rx indication message definition as LL, and simply
367 * appends new info (fields from the HW rx desc, and the
368 * MSDU payload itself). So, the offset into the rx
369 * indication message only has to account for the standard
370 * offset of the per-MSDU FW rx desc info within the
371 * message, and how many bytes of the per-MSDU FW rx desc
372 * info have already been consumed. (And the endianness of
373 * the host, since for a big-endian host, the rx ind
374 * message contents, including the per-MSDU rx desc bytes,
375 * were byteswapped during upload.)
376 */
377 if (*fw_desc_len > 0) {
378 rx_desc->fw_desc.info0 = **fw_desc;
379 /*
380 * The target is expected to only provide the basic
381 * per-MSDU rx descriptors. Just to be sure, verify
382 * that the target has not attached extension data
383 * (e.g. LRO flow ID).
384 */
385
386 /* or more, if there's extension data */
387 (*fw_desc)++;
388 (*fw_desc_len)--;
389 } else {
390 /*
391 * When an oversized AMSDU happened, FW will lost
392 * some of MSDU status - in this case, the FW
393 * descriptors provided will be less than the
394 * actual MSDUs inside this MPDU. Mark the FW
395 * descriptors so that it will still deliver to
396 * upper stack, if no CRC error for this MPDU.
397 *
398 * FIX THIS - the FW descriptors are actually for
399 * MSDUs in the end of this A-MSDU instead of the
400 * beginning.
401 */
402 rx_desc->fw_desc.info0 = 0;
403 }
404
405 msdu_len_invalid = !!(__le32_to_cpu(rx_desc->attention.flags)
406 & (RX_ATTENTION_FLAGS_MPDU_LENGTH_ERR |
407 RX_ATTENTION_FLAGS_MSDU_LENGTH_ERR));
408 msdu_len = MS(__le32_to_cpu(rx_desc->msdu_start.info0),
409 RX_MSDU_START_INFO0_MSDU_LENGTH);
410 msdu_chained = rx_desc->frag_info.ring2_more_count;
411
412 if (msdu_len_invalid)
413 msdu_len = 0;
414
415 skb_trim(msdu, 0);
416 skb_put(msdu, min(msdu_len, HTT_RX_MSDU_SIZE));
417 msdu_len -= msdu->len;
418
Michal Kazior9aa505d2014-11-18 09:24:47 +0200419 /* Note: Chained buffers do not contain rx descriptor */
Kalle Valo5e3dd152013-06-12 20:52:10 +0300420 while (msdu_chained--) {
Michal Kazior9aa505d2014-11-18 09:24:47 +0200421 msdu = ath10k_htt_rx_netbuf_pop(htt);
422 if (!msdu) {
Michal Kaziorb30595a2014-10-23 17:04:24 +0300423 ath10k_warn(ar, "failed to pop chained msdu\n");
Michal Kazior9aa505d2014-11-18 09:24:47 +0200424 __skb_queue_purge(amsdu);
Michal Kaziorb30595a2014-10-23 17:04:24 +0300425 htt->rx_confused = true;
426 break;
427 }
428
Michal Kazior9aa505d2014-11-18 09:24:47 +0200429 __skb_queue_tail(amsdu, msdu);
430 skb_trim(msdu, 0);
431 skb_put(msdu, min(msdu_len, HTT_RX_BUF_SIZE));
432 msdu_len -= msdu->len;
Michal Kaziorede9c8e2014-05-14 16:23:31 +0300433 msdu_chaining = 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300434 }
435
Kalle Valo5e3dd152013-06-12 20:52:10 +0300436 last_msdu = __le32_to_cpu(rx_desc->msdu_end.info0) &
437 RX_MSDU_END_INFO0_LAST_MSDU;
438
Michal Kaziorb04e2042014-10-23 17:04:27 +0300439 trace_ath10k_htt_rx_desc(ar, &rx_desc->attention,
Rajkumar Manoharana0883cf2014-10-03 08:02:47 +0300440 sizeof(*rx_desc) - sizeof(u32));
Michal Kazior9aa505d2014-11-18 09:24:47 +0200441
442 if (last_msdu)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300443 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300444 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300445
Michal Kazior9aa505d2014-11-18 09:24:47 +0200446 if (skb_queue_empty(amsdu))
Janusz Dziedzicd84dd602014-03-24 21:23:20 +0100447 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;
Kalle Valoaf762c02014-09-14 12:50:17 +0300468
Michal Kazior6e712d42013-09-24 10:18:36 +0200469 ath10k_htt_rx_msdu_buff_replenish(htt);
470}
471
Michal Kazior95bf21f2014-05-16 17:15:39 +0300472int ath10k_htt_rx_alloc(struct ath10k_htt *htt)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300473{
Michal Kazior7aa7a722014-08-25 12:09:38 +0200474 struct ath10k *ar = htt->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300475 dma_addr_t paddr;
476 void *vaddr;
Kalle Valobd8bdbb2014-09-14 12:50:00 +0300477 size_t size;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300478 struct timer_list *timer = &htt->rx_ring.refill_retry_timer;
479
Michal Kazior51fc7d72014-10-23 17:04:24 +0300480 htt->rx_confused = false;
481
Kalle Valo5e3dd152013-06-12 20:52:10 +0300482 htt->rx_ring.size = ath10k_htt_rx_ring_size(htt);
483 if (!is_power_of_2(htt->rx_ring.size)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200484 ath10k_warn(ar, "htt rx ring size is not power of 2\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +0300485 return -EINVAL;
486 }
487
488 htt->rx_ring.size_mask = htt->rx_ring.size - 1;
489
490 /*
491 * Set the initial value for the level to which the rx ring
492 * should be filled, based on the max throughput and the
493 * worst likely latency for the host to fill the rx ring
494 * with new buffers. In theory, this fill level can be
495 * dynamically adjusted from the initial value set here, to
496 * reflect the actual host latency rather than a
497 * conservative assumption about the host latency.
498 */
499 htt->rx_ring.fill_level = ath10k_htt_rx_ring_fill_level(htt);
500
501 htt->rx_ring.netbufs_ring =
Michal Kazior3e841fd2014-05-14 16:23:31 +0300502 kzalloc(htt->rx_ring.size * sizeof(struct sk_buff *),
Kalle Valo5e3dd152013-06-12 20:52:10 +0300503 GFP_KERNEL);
504 if (!htt->rx_ring.netbufs_ring)
505 goto err_netbuf;
506
Kalle Valobd8bdbb2014-09-14 12:50:00 +0300507 size = htt->rx_ring.size * sizeof(htt->rx_ring.paddrs_ring);
508
509 vaddr = dma_alloc_coherent(htt->ar->dev, size, &paddr, GFP_DMA);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300510 if (!vaddr)
511 goto err_dma_ring;
512
513 htt->rx_ring.paddrs_ring = vaddr;
514 htt->rx_ring.base_paddr = paddr;
515
516 vaddr = dma_alloc_coherent(htt->ar->dev,
517 sizeof(*htt->rx_ring.alloc_idx.vaddr),
518 &paddr, GFP_DMA);
519 if (!vaddr)
520 goto err_dma_idx;
521
522 htt->rx_ring.alloc_idx.vaddr = vaddr;
523 htt->rx_ring.alloc_idx.paddr = paddr;
524 htt->rx_ring.sw_rd_idx.msdu_payld = 0;
525 *htt->rx_ring.alloc_idx.vaddr = 0;
526
527 /* Initialize the Rx refill retry timer */
528 setup_timer(timer, ath10k_htt_rx_ring_refill_retry, (unsigned long)htt);
529
530 spin_lock_init(&htt->rx_ring.lock);
531
532 htt->rx_ring.fill_cnt = 0;
533 if (__ath10k_htt_rx_ring_fill_n(htt, htt->rx_ring.fill_level))
534 goto err_fill_ring;
535
Michal Kazior6e712d42013-09-24 10:18:36 +0200536 tasklet_init(&htt->rx_replenish_task, ath10k_htt_rx_replenish_task,
537 (unsigned long)htt);
538
Michal Kazior6c5151a2014-02-27 18:50:04 +0200539 skb_queue_head_init(&htt->tx_compl_q);
540 skb_queue_head_init(&htt->rx_compl_q);
541
542 tasklet_init(&htt->txrx_compl_task, ath10k_htt_txrx_compl_task,
543 (unsigned long)htt);
544
Michal Kazior7aa7a722014-08-25 12:09:38 +0200545 ath10k_dbg(ar, ATH10K_DBG_BOOT, "htt rx ring size %d fill_level %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300546 htt->rx_ring.size, htt->rx_ring.fill_level);
547 return 0;
548
549err_fill_ring:
550 ath10k_htt_rx_ring_free(htt);
551 dma_free_coherent(htt->ar->dev,
552 sizeof(*htt->rx_ring.alloc_idx.vaddr),
553 htt->rx_ring.alloc_idx.vaddr,
554 htt->rx_ring.alloc_idx.paddr);
555err_dma_idx:
556 dma_free_coherent(htt->ar->dev,
557 (htt->rx_ring.size *
558 sizeof(htt->rx_ring.paddrs_ring)),
559 htt->rx_ring.paddrs_ring,
560 htt->rx_ring.base_paddr);
561err_dma_ring:
562 kfree(htt->rx_ring.netbufs_ring);
563err_netbuf:
564 return -ENOMEM;
565}
566
Michal Kazior7aa7a722014-08-25 12:09:38 +0200567static int ath10k_htt_rx_crypto_param_len(struct ath10k *ar,
568 enum htt_rx_mpdu_encrypt_type type)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300569{
570 switch (type) {
Kalle Valo5e3dd152013-06-12 20:52:10 +0300571 case HTT_RX_MPDU_ENCRYPT_NONE:
572 return 0;
Michal Kazior890d3b22014-10-23 17:04:22 +0300573 case HTT_RX_MPDU_ENCRYPT_WEP40:
574 case HTT_RX_MPDU_ENCRYPT_WEP104:
575 return IEEE80211_WEP_IV_LEN;
576 case HTT_RX_MPDU_ENCRYPT_TKIP_WITHOUT_MIC:
577 case HTT_RX_MPDU_ENCRYPT_TKIP_WPA:
578 return IEEE80211_TKIP_IV_LEN;
579 case HTT_RX_MPDU_ENCRYPT_AES_CCM_WPA2:
580 return IEEE80211_CCMP_HDR_LEN;
581 case HTT_RX_MPDU_ENCRYPT_WEP128:
582 case HTT_RX_MPDU_ENCRYPT_WAPI:
583 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300584 }
585
Michal Kazior890d3b22014-10-23 17:04:22 +0300586 ath10k_warn(ar, "unsupported encryption type %d\n", type);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300587 return 0;
588}
589
Michal Kazior890d3b22014-10-23 17:04:22 +0300590#define MICHAEL_MIC_LEN 8
591
Michal Kazior7aa7a722014-08-25 12:09:38 +0200592static int ath10k_htt_rx_crypto_tail_len(struct ath10k *ar,
593 enum htt_rx_mpdu_encrypt_type type)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300594{
595 switch (type) {
596 case HTT_RX_MPDU_ENCRYPT_NONE:
Michal Kazior890d3b22014-10-23 17:04:22 +0300597 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300598 case HTT_RX_MPDU_ENCRYPT_WEP40:
599 case HTT_RX_MPDU_ENCRYPT_WEP104:
Michal Kazior890d3b22014-10-23 17:04:22 +0300600 return IEEE80211_WEP_ICV_LEN;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300601 case HTT_RX_MPDU_ENCRYPT_TKIP_WITHOUT_MIC:
602 case HTT_RX_MPDU_ENCRYPT_TKIP_WPA:
Michal Kazior890d3b22014-10-23 17:04:22 +0300603 return IEEE80211_TKIP_ICV_LEN;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300604 case HTT_RX_MPDU_ENCRYPT_AES_CCM_WPA2:
Michal Kazior890d3b22014-10-23 17:04:22 +0300605 return IEEE80211_CCMP_MIC_LEN;
606 case HTT_RX_MPDU_ENCRYPT_WEP128:
607 case HTT_RX_MPDU_ENCRYPT_WAPI:
608 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300609 }
610
Michal Kazior890d3b22014-10-23 17:04:22 +0300611 ath10k_warn(ar, "unsupported encryption type %d\n", type);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300612 return 0;
613}
614
615/* Applies for first msdu in chain, before altering it. */
616static struct ieee80211_hdr *ath10k_htt_rx_skb_get_hdr(struct sk_buff *skb)
617{
618 struct htt_rx_desc *rxd;
619 enum rx_msdu_decap_format fmt;
620
621 rxd = (void *)skb->data - sizeof(*rxd);
622 fmt = MS(__le32_to_cpu(rxd->msdu_start.info1),
Kalle Valo5b07e072014-09-14 12:50:06 +0300623 RX_MSDU_START_INFO1_DECAP_FORMAT);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300624
625 if (fmt == RX_MSDU_DECAP_RAW)
626 return (void *)skb->data;
Kalle Valod8bb26b2014-09-14 12:50:33 +0300627
628 return (void *)skb->data - RX_HTT_HDR_STATUS_LEN;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300629}
630
631/* This function only applies for first msdu in an msdu chain */
632static bool ath10k_htt_rx_hdr_is_amsdu(struct ieee80211_hdr *hdr)
633{
Kalle Valoaf762c02014-09-14 12:50:17 +0300634 u8 *qc;
635
Kalle Valo5e3dd152013-06-12 20:52:10 +0300636 if (ieee80211_is_data_qos(hdr->frame_control)) {
Kalle Valoaf762c02014-09-14 12:50:17 +0300637 qc = ieee80211_get_qos_ctl(hdr);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300638 if (qc[0] & 0x80)
639 return true;
640 }
641 return false;
642}
643
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300644struct rfc1042_hdr {
645 u8 llc_dsap;
646 u8 llc_ssap;
647 u8 llc_ctrl;
648 u8 snap_oui[3];
649 __be16 snap_type;
650} __packed;
651
652struct amsdu_subframe_hdr {
653 u8 dst[ETH_ALEN];
654 u8 src[ETH_ALEN];
655 __be16 len;
656} __packed;
657
Janusz Dziedzic73539b42014-03-24 21:23:15 +0100658static const u8 rx_legacy_rate_idx[] = {
659 3, /* 0x00 - 11Mbps */
660 2, /* 0x01 - 5.5Mbps */
661 1, /* 0x02 - 2Mbps */
662 0, /* 0x03 - 1Mbps */
663 3, /* 0x04 - 11Mbps */
664 2, /* 0x05 - 5.5Mbps */
665 1, /* 0x06 - 2Mbps */
666 0, /* 0x07 - 1Mbps */
667 10, /* 0x08 - 48Mbps */
668 8, /* 0x09 - 24Mbps */
669 6, /* 0x0A - 12Mbps */
670 4, /* 0x0B - 6Mbps */
671 11, /* 0x0C - 54Mbps */
672 9, /* 0x0D - 36Mbps */
673 7, /* 0x0E - 18Mbps */
674 5, /* 0x0F - 9Mbps */
675};
676
Janusz Dziedzic87326c92014-03-24 21:23:19 +0100677static void ath10k_htt_rx_h_rates(struct ath10k *ar,
Janusz Dziedziccfadd9b2014-03-24 21:23:16 +0100678 enum ieee80211_band band,
Janusz Dziedzic87326c92014-03-24 21:23:19 +0100679 u8 info0, u32 info1, u32 info2,
Janusz Dziedziccfadd9b2014-03-24 21:23:16 +0100680 struct ieee80211_rx_status *status)
Janusz Dziedzic73539b42014-03-24 21:23:15 +0100681{
682 u8 cck, rate, rate_idx, bw, sgi, mcs, nss;
Janusz Dziedzic73539b42014-03-24 21:23:15 +0100683 u8 preamble = 0;
684
685 /* Check if valid fields */
686 if (!(info0 & HTT_RX_INDICATION_INFO0_START_VALID))
687 return;
688
689 preamble = MS(info1, HTT_RX_INDICATION_INFO1_PREAMBLE_TYPE);
690
691 switch (preamble) {
692 case HTT_RX_LEGACY:
693 cck = info0 & HTT_RX_INDICATION_INFO0_LEGACY_RATE_CCK;
694 rate = MS(info0, HTT_RX_INDICATION_INFO0_LEGACY_RATE);
695 rate_idx = 0;
696
697 if (rate < 0x08 || rate > 0x0F)
698 break;
699
700 switch (band) {
701 case IEEE80211_BAND_2GHZ:
702 if (cck)
703 rate &= ~BIT(3);
704 rate_idx = rx_legacy_rate_idx[rate];
705 break;
706 case IEEE80211_BAND_5GHZ:
707 rate_idx = rx_legacy_rate_idx[rate];
708 /* We are using same rate table registering
709 HW - ath10k_rates[]. In case of 5GHz skip
710 CCK rates, so -4 here */
711 rate_idx -= 4;
712 break;
713 default:
714 break;
715 }
716
717 status->rate_idx = rate_idx;
718 break;
719 case HTT_RX_HT:
720 case HTT_RX_HT_WITH_TXBF:
721 /* HT-SIG - Table 20-11 in info1 and info2 */
722 mcs = info1 & 0x1F;
723 nss = mcs >> 3;
724 bw = (info1 >> 7) & 1;
725 sgi = (info2 >> 7) & 1;
726
727 status->rate_idx = mcs;
728 status->flag |= RX_FLAG_HT;
729 if (sgi)
730 status->flag |= RX_FLAG_SHORT_GI;
731 if (bw)
732 status->flag |= RX_FLAG_40MHZ;
733 break;
734 case HTT_RX_VHT:
735 case HTT_RX_VHT_WITH_TXBF:
736 /* VHT-SIG-A1 in info 1, VHT-SIG-A2 in info2
737 TODO check this */
738 mcs = (info2 >> 4) & 0x0F;
739 nss = ((info1 >> 10) & 0x07) + 1;
740 bw = info1 & 3;
741 sgi = info2 & 1;
742
743 status->rate_idx = mcs;
744 status->vht_nss = nss;
745
746 if (sgi)
747 status->flag |= RX_FLAG_SHORT_GI;
748
749 switch (bw) {
750 /* 20MHZ */
751 case 0:
752 break;
753 /* 40MHZ */
754 case 1:
755 status->flag |= RX_FLAG_40MHZ;
756 break;
757 /* 80MHZ */
758 case 2:
759 status->vht_flag |= RX_VHT_FLAG_80MHZ;
760 }
761
762 status->flag |= RX_FLAG_VHT;
763 break;
764 default:
765 break;
766 }
767}
768
Janusz Dziedzic87326c92014-03-24 21:23:19 +0100769static void ath10k_htt_rx_h_protected(struct ath10k_htt *htt,
Janusz Dziedzic85f6d7c2014-03-24 21:23:22 +0100770 struct ieee80211_rx_status *rx_status,
771 struct sk_buff *skb,
Michal Kaziorc071dcb2014-05-23 11:33:18 +0300772 enum htt_rx_mpdu_encrypt_type enctype,
773 enum rx_msdu_decap_format fmt,
774 bool dot11frag)
Janusz Dziedzic87326c92014-03-24 21:23:19 +0100775{
Janusz Dziedzic85f6d7c2014-03-24 21:23:22 +0100776 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Janusz Dziedzic87326c92014-03-24 21:23:19 +0100777
Michal Kaziorc071dcb2014-05-23 11:33:18 +0300778 rx_status->flag &= ~(RX_FLAG_DECRYPTED |
779 RX_FLAG_IV_STRIPPED |
780 RX_FLAG_MMIC_STRIPPED);
Janusz Dziedzic87326c92014-03-24 21:23:19 +0100781
Michal Kaziorc071dcb2014-05-23 11:33:18 +0300782 if (enctype == HTT_RX_MPDU_ENCRYPT_NONE)
Janusz Dziedzic87326c92014-03-24 21:23:19 +0100783 return;
Michal Kaziorc071dcb2014-05-23 11:33:18 +0300784
785 /*
786 * There's no explicit rx descriptor flag to indicate whether a given
787 * frame has been decrypted or not. We're forced to use the decap
788 * format as an implicit indication. However fragmentation rx is always
789 * raw and it probably never reports undecrypted raws.
790 *
791 * This makes sure sniffed frames are reported as-is without stripping
792 * the protected flag.
793 */
794 if (fmt == RX_MSDU_DECAP_RAW && !dot11frag)
795 return;
Janusz Dziedzic87326c92014-03-24 21:23:19 +0100796
Janusz Dziedzic85f6d7c2014-03-24 21:23:22 +0100797 rx_status->flag |= RX_FLAG_DECRYPTED |
798 RX_FLAG_IV_STRIPPED |
799 RX_FLAG_MMIC_STRIPPED;
Janusz Dziedzic87326c92014-03-24 21:23:19 +0100800 hdr->frame_control = __cpu_to_le16(__le16_to_cpu(hdr->frame_control) &
801 ~IEEE80211_FCTL_PROTECTED);
802}
803
Janusz Dziedzic36653f02014-03-24 21:23:18 +0100804static bool ath10k_htt_rx_h_channel(struct ath10k *ar,
805 struct ieee80211_rx_status *status)
806{
807 struct ieee80211_channel *ch;
808
809 spin_lock_bh(&ar->data_lock);
810 ch = ar->scan_channel;
811 if (!ch)
812 ch = ar->rx_channel;
813 spin_unlock_bh(&ar->data_lock);
814
815 if (!ch)
816 return false;
817
818 status->band = ch->band;
819 status->freq = ch->center_freq;
820
821 return true;
822}
823
Janusz Dziedzic76f53292014-07-28 23:59:43 +0300824static const char * const tid_to_ac[] = {
825 "BE",
826 "BK",
827 "BK",
828 "BE",
829 "VI",
830 "VI",
831 "VO",
832 "VO",
833};
834
835static char *ath10k_get_tid(struct ieee80211_hdr *hdr, char *out, size_t size)
836{
837 u8 *qc;
838 int tid;
839
840 if (!ieee80211_is_data_qos(hdr->frame_control))
841 return "";
842
843 qc = ieee80211_get_qos_ctl(hdr);
844 tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
845 if (tid < 8)
846 snprintf(out, size, "tid %d (%s)", tid, tid_to_ac[tid]);
847 else
848 snprintf(out, size, "tid %d", tid);
849
850 return out;
851}
852
Janusz Dziedzic85f6d7c2014-03-24 21:23:22 +0100853static void ath10k_process_rx(struct ath10k *ar,
854 struct ieee80211_rx_status *rx_status,
855 struct sk_buff *skb)
Janusz Dziedzic73539b42014-03-24 21:23:15 +0100856{
857 struct ieee80211_rx_status *status;
Janusz Dziedzic76f53292014-07-28 23:59:43 +0300858 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
859 char tid[32];
Janusz Dziedzic73539b42014-03-24 21:23:15 +0100860
Janusz Dziedzic85f6d7c2014-03-24 21:23:22 +0100861 status = IEEE80211_SKB_RXCB(skb);
862 *status = *rx_status;
Janusz Dziedzic73539b42014-03-24 21:23:15 +0100863
Michal Kazior7aa7a722014-08-25 12:09:38 +0200864 ath10k_dbg(ar, ATH10K_DBG_DATA,
Janusz Dziedzic76f53292014-07-28 23:59:43 +0300865 "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 +0100866 skb,
867 skb->len,
Janusz Dziedzic76f53292014-07-28 23:59:43 +0300868 ieee80211_get_SA(hdr),
869 ath10k_get_tid(hdr, tid, sizeof(tid)),
870 is_multicast_ether_addr(ieee80211_get_DA(hdr)) ?
871 "mcast" : "ucast",
872 (__le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_SEQ) >> 4,
Janusz Dziedzic73539b42014-03-24 21:23:15 +0100873 status->flag == 0 ? "legacy" : "",
874 status->flag & RX_FLAG_HT ? "ht" : "",
875 status->flag & RX_FLAG_VHT ? "vht" : "",
876 status->flag & RX_FLAG_40MHZ ? "40" : "",
877 status->vht_flag & RX_VHT_FLAG_80MHZ ? "80" : "",
878 status->flag & RX_FLAG_SHORT_GI ? "sgi " : "",
879 status->rate_idx,
880 status->vht_nss,
881 status->freq,
Janusz Dziedzic87326c92014-03-24 21:23:19 +0100882 status->band, status->flag,
Janusz Dziedzic78433f92014-03-24 21:23:21 +0100883 !!(status->flag & RX_FLAG_FAILED_FCS_CRC),
Janusz Dziedzic76f53292014-07-28 23:59:43 +0300884 !!(status->flag & RX_FLAG_MMIC_ERROR),
885 !!(status->flag & RX_FLAG_AMSDU_MORE));
Michal Kazior7aa7a722014-08-25 12:09:38 +0200886 ath10k_dbg_dump(ar, ATH10K_DBG_HTT_DUMP, NULL, "rx skb: ",
Janusz Dziedzic85f6d7c2014-03-24 21:23:22 +0100887 skb->data, skb->len);
Rajkumar Manoharan5ce8e7f2014-11-05 19:14:31 +0530888 trace_ath10k_rx_hdr(ar, skb->data, skb->len);
889 trace_ath10k_rx_payload(ar, skb->data, skb->len);
Janusz Dziedzic73539b42014-03-24 21:23:15 +0100890
Janusz Dziedzic85f6d7c2014-03-24 21:23:22 +0100891 ieee80211_rx(ar->hw, skb);
Janusz Dziedzic73539b42014-03-24 21:23:15 +0100892}
893
Michal Kaziord960c362014-02-25 09:29:57 +0200894static int ath10k_htt_rx_nwifi_hdrlen(struct ieee80211_hdr *hdr)
895{
896 /* nwifi header is padded to 4 bytes. this fixes 4addr rx */
897 return round_up(ieee80211_hdrlen(hdr->frame_control), 4);
898}
899
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300900static void ath10k_htt_rx_amsdu(struct ath10k_htt *htt,
Janusz Dziedzic85f6d7c2014-03-24 21:23:22 +0100901 struct ieee80211_rx_status *rx_status,
Michal Kazior9aa505d2014-11-18 09:24:47 +0200902 struct sk_buff_head *amsdu)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300903{
Michal Kazior7aa7a722014-08-25 12:09:38 +0200904 struct ath10k *ar = htt->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300905 struct htt_rx_desc *rxd;
Michal Kazior9aa505d2014-11-18 09:24:47 +0200906 struct sk_buff *skb;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300907 struct sk_buff *first;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300908 enum rx_msdu_decap_format fmt;
909 enum htt_rx_mpdu_encrypt_type enctype;
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300910 struct ieee80211_hdr *hdr;
Michal Kazior72bdeb82014-07-28 23:59:42 +0300911 u8 hdr_buf[64], da[ETH_ALEN], sa[ETH_ALEN], *qos;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300912 unsigned int hdr_len;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300913
Michal Kazior9aa505d2014-11-18 09:24:47 +0200914 first = skb_peek(amsdu);
915
916 rxd = (void *)first->data - sizeof(*rxd);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300917 enctype = MS(__le32_to_cpu(rxd->mpdu_start.info0),
Kalle Valo5b07e072014-09-14 12:50:06 +0300918 RX_MPDU_START_INFO0_ENCRYPT_TYPE);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300919
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300920 hdr = (struct ieee80211_hdr *)rxd->rx_hdr_status;
921 hdr_len = ieee80211_hdrlen(hdr->frame_control);
922 memcpy(hdr_buf, hdr, hdr_len);
923 hdr = (struct ieee80211_hdr *)hdr_buf;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300924
Michal Kazior9aa505d2014-11-18 09:24:47 +0200925 while ((skb = __skb_dequeue(amsdu))) {
Kalle Valo5e3dd152013-06-12 20:52:10 +0300926 void *decap_hdr;
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300927 int len;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300928
929 rxd = (void *)skb->data - sizeof(*rxd);
930 fmt = MS(__le32_to_cpu(rxd->msdu_start.info1),
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300931 RX_MSDU_START_INFO1_DECAP_FORMAT);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300932 decap_hdr = (void *)rxd->rx_hdr_status;
933
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300934 skb->ip_summed = ath10k_htt_rx_get_csum_state(skb);
935
936 /* First frame in an A-MSDU chain has more decapped data. */
Kalle Valo5e3dd152013-06-12 20:52:10 +0300937 if (skb == first) {
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300938 len = round_up(ieee80211_hdrlen(hdr->frame_control), 4);
Michal Kazior7aa7a722014-08-25 12:09:38 +0200939 len += round_up(ath10k_htt_rx_crypto_param_len(ar,
940 enctype), 4);
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300941 decap_hdr += len;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300942 }
943
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300944 switch (fmt) {
945 case RX_MSDU_DECAP_RAW:
Michal Kaziore3fbf8d2013-09-26 10:12:23 +0300946 /* remove trailing FCS */
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300947 skb_trim(skb, skb->len - FCS_LEN);
948 break;
949 case RX_MSDU_DECAP_NATIVE_WIFI:
Michal Kazior72bdeb82014-07-28 23:59:42 +0300950 /* pull decapped header and copy SA & DA */
Michal Kazior784f69d2013-09-26 10:12:23 +0300951 hdr = (struct ieee80211_hdr *)skb->data;
Michal Kaziord960c362014-02-25 09:29:57 +0200952 hdr_len = ath10k_htt_rx_nwifi_hdrlen(hdr);
Kalle Valob25f32c2014-09-14 12:50:49 +0300953 ether_addr_copy(da, ieee80211_get_DA(hdr));
954 ether_addr_copy(sa, ieee80211_get_SA(hdr));
Michal Kazior784f69d2013-09-26 10:12:23 +0300955 skb_pull(skb, hdr_len);
956
957 /* push original 802.11 header */
958 hdr = (struct ieee80211_hdr *)hdr_buf;
959 hdr_len = ieee80211_hdrlen(hdr->frame_control);
960 memcpy(skb_push(skb, hdr_len), hdr, hdr_len);
961
962 /* original A-MSDU header has the bit set but we're
963 * not including A-MSDU subframe header */
964 hdr = (struct ieee80211_hdr *)skb->data;
965 qos = ieee80211_get_qos_ctl(hdr);
966 qos[0] &= ~IEEE80211_QOS_CTL_A_MSDU_PRESENT;
967
Michal Kazior72bdeb82014-07-28 23:59:42 +0300968 /* original 802.11 header has a different DA and in
969 * case of 4addr it may also have different SA
970 */
Kalle Valob25f32c2014-09-14 12:50:49 +0300971 ether_addr_copy(ieee80211_get_DA(hdr), da);
972 ether_addr_copy(ieee80211_get_SA(hdr), sa);
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300973 break;
974 case RX_MSDU_DECAP_ETHERNET2_DIX:
Michal Kaziore3fbf8d2013-09-26 10:12:23 +0300975 /* strip ethernet header and insert decapped 802.11
976 * header, amsdu subframe header and rfc1042 header */
977
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300978 len = 0;
979 len += sizeof(struct rfc1042_hdr);
980 len += sizeof(struct amsdu_subframe_hdr);
Michal Kaziordfa95b52013-08-13 07:59:37 +0200981
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300982 skb_pull(skb, sizeof(struct ethhdr));
983 memcpy(skb_push(skb, len), decap_hdr, len);
984 memcpy(skb_push(skb, hdr_len), hdr, hdr_len);
985 break;
986 case RX_MSDU_DECAP_8023_SNAP_LLC:
Michal Kaziore3fbf8d2013-09-26 10:12:23 +0300987 /* insert decapped 802.11 header making a singly
988 * A-MSDU */
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300989 memcpy(skb_push(skb, hdr_len), hdr, hdr_len);
990 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300991 }
992
Michal Kazior9aa505d2014-11-18 09:24:47 +0200993 ath10k_htt_rx_h_protected(htt, rx_status, skb, enctype, fmt,
Michal Kaziorc071dcb2014-05-23 11:33:18 +0300994 false);
Michal Kaziorf6dc2092013-09-26 10:12:22 +0300995
Michal Kazior9aa505d2014-11-18 09:24:47 +0200996 if (skb_queue_empty(amsdu))
Janusz Dziedzic85f6d7c2014-03-24 21:23:22 +0100997 rx_status->flag &= ~RX_FLAG_AMSDU_MORE;
Michal Kazior9aa505d2014-11-18 09:24:47 +0200998 else
999 rx_status->flag |= RX_FLAG_AMSDU_MORE;
Kalle Valo652de352013-11-13 15:23:30 +02001000
Michal Kazior9aa505d2014-11-18 09:24:47 +02001001 ath10k_process_rx(htt->ar, rx_status, skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001002 }
1003
Michal Kaziorf6dc2092013-09-26 10:12:22 +03001004 /* FIXME: It might be nice to re-assemble the A-MSDU when there's a
1005 * monitor interface active for sniffing purposes. */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001006}
1007
Janusz Dziedzic85f6d7c2014-03-24 21:23:22 +01001008static void ath10k_htt_rx_msdu(struct ath10k_htt *htt,
1009 struct ieee80211_rx_status *rx_status,
1010 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001011{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001012 struct ath10k *ar = htt->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001013 struct htt_rx_desc *rxd;
1014 struct ieee80211_hdr *hdr;
1015 enum rx_msdu_decap_format fmt;
1016 enum htt_rx_mpdu_encrypt_type enctype;
Michal Kaziore3fbf8d2013-09-26 10:12:23 +03001017 int hdr_len;
1018 void *rfc1042;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001019
Kalle Valo5e3dd152013-06-12 20:52:10 +03001020 rxd = (void *)skb->data - sizeof(*rxd);
1021 fmt = MS(__le32_to_cpu(rxd->msdu_start.info1),
Kalle Valo5b07e072014-09-14 12:50:06 +03001022 RX_MSDU_START_INFO1_DECAP_FORMAT);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001023 enctype = MS(__le32_to_cpu(rxd->mpdu_start.info0),
Kalle Valo5b07e072014-09-14 12:50:06 +03001024 RX_MPDU_START_INFO0_ENCRYPT_TYPE);
Michal Kaziore3fbf8d2013-09-26 10:12:23 +03001025 hdr = (struct ieee80211_hdr *)rxd->rx_hdr_status;
1026 hdr_len = ieee80211_hdrlen(hdr->frame_control);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001027
Michal Kaziorf6dc2092013-09-26 10:12:22 +03001028 skb->ip_summed = ath10k_htt_rx_get_csum_state(skb);
1029
Kalle Valo5e3dd152013-06-12 20:52:10 +03001030 switch (fmt) {
1031 case RX_MSDU_DECAP_RAW:
1032 /* remove trailing FCS */
Michal Kaziore3fbf8d2013-09-26 10:12:23 +03001033 skb_trim(skb, skb->len - FCS_LEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001034 break;
1035 case RX_MSDU_DECAP_NATIVE_WIFI:
Michal Kazior784f69d2013-09-26 10:12:23 +03001036 /* Pull decapped header */
1037 hdr = (struct ieee80211_hdr *)skb->data;
Michal Kaziord960c362014-02-25 09:29:57 +02001038 hdr_len = ath10k_htt_rx_nwifi_hdrlen(hdr);
Michal Kazior784f69d2013-09-26 10:12:23 +03001039 skb_pull(skb, hdr_len);
1040
1041 /* Push original header */
1042 hdr = (struct ieee80211_hdr *)rxd->rx_hdr_status;
1043 hdr_len = ieee80211_hdrlen(hdr->frame_control);
1044 memcpy(skb_push(skb, hdr_len), hdr, hdr_len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001045 break;
1046 case RX_MSDU_DECAP_ETHERNET2_DIX:
Michal Kaziore3fbf8d2013-09-26 10:12:23 +03001047 /* strip ethernet header and insert decapped 802.11 header and
1048 * rfc1042 header */
1049
1050 rfc1042 = hdr;
1051 rfc1042 += roundup(hdr_len, 4);
Michal Kazior7aa7a722014-08-25 12:09:38 +02001052 rfc1042 += roundup(ath10k_htt_rx_crypto_param_len(ar,
1053 enctype), 4);
Michal Kaziore3fbf8d2013-09-26 10:12:23 +03001054
1055 skb_pull(skb, sizeof(struct ethhdr));
1056 memcpy(skb_push(skb, sizeof(struct rfc1042_hdr)),
1057 rfc1042, sizeof(struct rfc1042_hdr));
1058 memcpy(skb_push(skb, hdr_len), hdr, hdr_len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001059 break;
1060 case RX_MSDU_DECAP_8023_SNAP_LLC:
Michal Kaziore3fbf8d2013-09-26 10:12:23 +03001061 /* remove A-MSDU subframe header and insert
1062 * decapped 802.11 header. rfc1042 header is already there */
1063
1064 skb_pull(skb, sizeof(struct amsdu_subframe_hdr));
1065 memcpy(skb_push(skb, hdr_len), hdr, hdr_len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001066 break;
1067 }
1068
Michal Kaziorc071dcb2014-05-23 11:33:18 +03001069 ath10k_htt_rx_h_protected(htt, rx_status, skb, enctype, fmt, false);
Michal Kaziorf6dc2092013-09-26 10:12:22 +03001070
Janusz Dziedzic85f6d7c2014-03-24 21:23:22 +01001071 ath10k_process_rx(htt->ar, rx_status, skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001072}
1073
Michal Kazior605f81a2013-07-31 10:47:56 +02001074static int ath10k_htt_rx_get_csum_state(struct sk_buff *skb)
1075{
1076 struct htt_rx_desc *rxd;
1077 u32 flags, info;
1078 bool is_ip4, is_ip6;
1079 bool is_tcp, is_udp;
1080 bool ip_csum_ok, tcpudp_csum_ok;
1081
1082 rxd = (void *)skb->data - sizeof(*rxd);
1083 flags = __le32_to_cpu(rxd->attention.flags);
1084 info = __le32_to_cpu(rxd->msdu_start.info1);
1085
1086 is_ip4 = !!(info & RX_MSDU_START_INFO1_IPV4_PROTO);
1087 is_ip6 = !!(info & RX_MSDU_START_INFO1_IPV6_PROTO);
1088 is_tcp = !!(info & RX_MSDU_START_INFO1_TCP_PROTO);
1089 is_udp = !!(info & RX_MSDU_START_INFO1_UDP_PROTO);
1090 ip_csum_ok = !(flags & RX_ATTENTION_FLAGS_IP_CHKSUM_FAIL);
1091 tcpudp_csum_ok = !(flags & RX_ATTENTION_FLAGS_TCP_UDP_CHKSUM_FAIL);
1092
1093 if (!is_ip4 && !is_ip6)
1094 return CHECKSUM_NONE;
1095 if (!is_tcp && !is_udp)
1096 return CHECKSUM_NONE;
1097 if (!ip_csum_ok)
1098 return CHECKSUM_NONE;
1099 if (!tcpudp_csum_ok)
1100 return CHECKSUM_NONE;
1101
1102 return CHECKSUM_UNNECESSARY;
1103}
1104
Michal Kazior9aa505d2014-11-18 09:24:47 +02001105static int ath10k_unchain_msdu(struct sk_buff_head *amsdu)
Ben Greearbfa35362014-03-03 14:07:09 -08001106{
Michal Kazior9aa505d2014-11-18 09:24:47 +02001107 struct sk_buff *skb, *first;
Ben Greearbfa35362014-03-03 14:07:09 -08001108 int space;
1109 int total_len = 0;
1110
1111 /* TODO: Might could optimize this by using
1112 * skb_try_coalesce or similar method to
1113 * decrease copying, or maybe get mac80211 to
1114 * provide a way to just receive a list of
1115 * skb?
1116 */
1117
Michal Kazior9aa505d2014-11-18 09:24:47 +02001118 first = __skb_dequeue(amsdu);
Ben Greearbfa35362014-03-03 14:07:09 -08001119
1120 /* Allocate total length all at once. */
Michal Kazior9aa505d2014-11-18 09:24:47 +02001121 skb_queue_walk(amsdu, skb)
1122 total_len += skb->len;
Ben Greearbfa35362014-03-03 14:07:09 -08001123
Michal Kazior9aa505d2014-11-18 09:24:47 +02001124 space = total_len - skb_tailroom(first);
Ben Greearbfa35362014-03-03 14:07:09 -08001125 if ((space > 0) &&
Michal Kazior9aa505d2014-11-18 09:24:47 +02001126 (pskb_expand_head(first, 0, space, GFP_ATOMIC) < 0)) {
Ben Greearbfa35362014-03-03 14:07:09 -08001127 /* TODO: bump some rx-oom error stat */
1128 /* put it back together so we can free the
1129 * whole list at once.
1130 */
Michal Kazior9aa505d2014-11-18 09:24:47 +02001131 __skb_queue_head(amsdu, first);
Ben Greearbfa35362014-03-03 14:07:09 -08001132 return -1;
1133 }
1134
1135 /* Walk list again, copying contents into
1136 * msdu_head
1137 */
Michal Kazior9aa505d2014-11-18 09:24:47 +02001138 while ((skb = __skb_dequeue(amsdu))) {
1139 skb_copy_from_linear_data(skb, skb_put(first, skb->len),
1140 skb->len);
1141 dev_kfree_skb_any(skb);
Ben Greearbfa35362014-03-03 14:07:09 -08001142 }
1143
Michal Kazior9aa505d2014-11-18 09:24:47 +02001144 __skb_queue_head(amsdu, first);
Ben Greearbfa35362014-03-03 14:07:09 -08001145 return 0;
1146}
1147
Janusz Dziedzic2acc4eb2014-03-19 07:09:40 +01001148static bool ath10k_htt_rx_amsdu_allowed(struct ath10k_htt *htt,
1149 struct sk_buff *head,
Janusz Dziedzic78433f92014-03-24 21:23:21 +01001150 bool channel_set,
1151 u32 attention)
Janusz Dziedzic2acc4eb2014-03-19 07:09:40 +01001152{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001153 struct ath10k *ar = htt->ar;
1154
Janusz Dziedzic2acc4eb2014-03-19 07:09:40 +01001155 if (head->len == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001156 ath10k_dbg(ar, ATH10K_DBG_HTT,
Janusz Dziedzic2acc4eb2014-03-19 07:09:40 +01001157 "htt rx dropping due to zero-len\n");
1158 return false;
1159 }
1160
Janusz Dziedzic78433f92014-03-24 21:23:21 +01001161 if (attention & RX_ATTENTION_FLAGS_DECRYPT_ERR) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001162 ath10k_dbg(ar, ATH10K_DBG_HTT,
Janusz Dziedzic2acc4eb2014-03-19 07:09:40 +01001163 "htt rx dropping due to decrypt-err\n");
1164 return false;
1165 }
1166
Janusz Dziedzic36653f02014-03-24 21:23:18 +01001167 if (!channel_set) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001168 ath10k_warn(ar, "no channel configured; ignoring frame!\n");
Janusz Dziedzic36653f02014-03-24 21:23:18 +01001169 return false;
1170 }
1171
Janusz Dziedzic2acc4eb2014-03-19 07:09:40 +01001172 /* Skip mgmt frames while we handle this in WMI */
Michal Kaziorf6b946e2014-10-23 17:04:22 +03001173 if (attention & RX_ATTENTION_FLAGS_MGMT_TYPE) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001174 ath10k_dbg(ar, ATH10K_DBG_HTT, "htt rx mgmt ctrl\n");
Janusz Dziedzic2acc4eb2014-03-19 07:09:40 +01001175 return false;
1176 }
1177
Janusz Dziedzic2acc4eb2014-03-19 07:09:40 +01001178 if (test_bit(ATH10K_CAC_RUNNING, &htt->ar->dev_flags)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001179 ath10k_dbg(ar, ATH10K_DBG_HTT,
Janusz Dziedzic2acc4eb2014-03-19 07:09:40 +01001180 "htt rx CAC running\n");
1181 return false;
1182 }
1183
1184 return true;
1185}
1186
Kalle Valo5e3dd152013-06-12 20:52:10 +03001187static void ath10k_htt_rx_handler(struct ath10k_htt *htt,
1188 struct htt_rx_indication *rx)
1189{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001190 struct ath10k *ar = htt->ar;
Janusz Dziedzic6df92a32014-03-24 21:24:57 +01001191 struct ieee80211_rx_status *rx_status = &htt->rx_status;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001192 struct htt_rx_indication_mpdu_range *mpdu_ranges;
Michal Kazior9aa505d2014-11-18 09:24:47 +02001193 struct sk_buff_head amsdu;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001194 struct ieee80211_hdr *hdr;
1195 int num_mpdu_ranges;
Janusz Dziedzic78433f92014-03-24 21:23:21 +01001196 u32 attention;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001197 int fw_desc_len;
1198 u8 *fw_desc;
Janusz Dziedzic78433f92014-03-24 21:23:21 +01001199 bool channel_set;
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 fw_desc_len = __le16_to_cpu(rx->prefix.fw_rx_desc_bytes);
1206 fw_desc = (u8 *)&rx->fw_desc;
1207
1208 num_mpdu_ranges = MS(__le32_to_cpu(rx->hdr.info1),
1209 HTT_RX_INDICATION_INFO1_NUM_MPDU_RANGES);
1210 mpdu_ranges = htt_rx_ind_get_mpdu_ranges(rx);
1211
Janusz Dziedzice8dc1a92014-03-19 07:09:41 +01001212 /* Fill this once, while this is per-ppdu */
Janusz Dziedzic22891882014-03-24 21:24:58 +01001213 if (rx->ppdu.info0 & HTT_RX_INDICATION_INFO0_START_VALID) {
1214 memset(rx_status, 0, sizeof(*rx_status));
1215 rx_status->signal = ATH10K_DEFAULT_NOISE_FLOOR +
1216 rx->ppdu.combined_rssi;
1217 }
Janusz Dziedzic87326c92014-03-24 21:23:19 +01001218
1219 if (rx->ppdu.info0 & HTT_RX_INDICATION_INFO0_END_VALID) {
1220 /* TSF available only in 32-bit */
Janusz Dziedzic6df92a32014-03-24 21:24:57 +01001221 rx_status->mactime = __le32_to_cpu(rx->ppdu.tsf) & 0xffffffff;
1222 rx_status->flag |= RX_FLAG_MACTIME_END;
Janusz Dziedzic87326c92014-03-24 21:23:19 +01001223 }
Janusz Dziedzice8dc1a92014-03-19 07:09:41 +01001224
Janusz Dziedzic6df92a32014-03-24 21:24:57 +01001225 channel_set = ath10k_htt_rx_h_channel(htt->ar, rx_status);
Janusz Dziedzic36653f02014-03-24 21:23:18 +01001226
Janusz Dziedzic87326c92014-03-24 21:23:19 +01001227 if (channel_set) {
Janusz Dziedzic6df92a32014-03-24 21:24:57 +01001228 ath10k_htt_rx_h_rates(htt->ar, rx_status->band,
Janusz Dziedzic87326c92014-03-24 21:23:19 +01001229 rx->ppdu.info0,
1230 __le32_to_cpu(rx->ppdu.info1),
1231 __le32_to_cpu(rx->ppdu.info2),
Janusz Dziedzic6df92a32014-03-24 21:24:57 +01001232 rx_status);
Janusz Dziedzic87326c92014-03-24 21:23:19 +01001233 }
Janusz Dziedzice8dc1a92014-03-19 07:09:41 +01001234
Michal Kazior7aa7a722014-08-25 12:09:38 +02001235 ath10k_dbg_dump(ar, ATH10K_DBG_HTT_DUMP, NULL, "htt rx ind: ",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001236 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++) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001241 for (j = 0; j < mpdu_ranges[i].mpdu_count; j++) {
Janusz Dziedzic0ccb7a32014-07-25 11:28:50 +03001242 attention = 0;
Michal Kazior9aa505d2014-11-18 09:24:47 +02001243 __skb_queue_head_init(&amsdu);
1244 ret = ath10k_htt_rx_amsdu_pop(htt, &fw_desc,
1245 &fw_desc_len, &amsdu,
Janusz Dziedzic0ccb7a32014-07-25 11:28:50 +03001246 &attention);
Janusz Dziedzicd84dd602014-03-24 21:23:20 +01001247
1248 if (ret < 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001249 ath10k_warn(ar, "failed to pop amsdu from htt rx ring %d\n",
Janusz Dziedzicd84dd602014-03-24 21:23:20 +01001250 ret);
Michal Kazior9aa505d2014-11-18 09:24:47 +02001251 __skb_queue_purge(&amsdu);
Janusz Dziedzicd84dd602014-03-24 21:23:20 +01001252 continue;
1253 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001254
Michal Kazior9aa505d2014-11-18 09:24:47 +02001255 if (!ath10k_htt_rx_amsdu_allowed(htt, skb_peek(&amsdu),
Janusz Dziedzic78433f92014-03-24 21:23:21 +01001256 channel_set,
1257 attention)) {
Michal Kazior9aa505d2014-11-18 09:24:47 +02001258 __skb_queue_purge(&amsdu);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001259 continue;
1260 }
1261
Michal Kazior9aa505d2014-11-18 09:24:47 +02001262 if (ret > 0 && ath10k_unchain_msdu(&amsdu) < 0) {
1263 __skb_queue_purge(&amsdu);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001264 continue;
1265 }
1266
Janusz Dziedzic78433f92014-03-24 21:23:21 +01001267 if (attention & RX_ATTENTION_FLAGS_FCS_ERR)
Janusz Dziedzic6df92a32014-03-24 21:24:57 +01001268 rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
Janusz Dziedzic87326c92014-03-24 21:23:19 +01001269 else
Janusz Dziedzic6df92a32014-03-24 21:24:57 +01001270 rx_status->flag &= ~RX_FLAG_FAILED_FCS_CRC;
Janusz Dziedzic87326c92014-03-24 21:23:19 +01001271
Janusz Dziedzic78433f92014-03-24 21:23:21 +01001272 if (attention & RX_ATTENTION_FLAGS_TKIP_MIC_ERR)
Janusz Dziedzic6df92a32014-03-24 21:24:57 +01001273 rx_status->flag |= RX_FLAG_MMIC_ERROR;
Janusz Dziedzic87326c92014-03-24 21:23:19 +01001274 else
Janusz Dziedzic6df92a32014-03-24 21:24:57 +01001275 rx_status->flag &= ~RX_FLAG_MMIC_ERROR;
Janusz Dziedzic87326c92014-03-24 21:23:19 +01001276
Michal Kazior9aa505d2014-11-18 09:24:47 +02001277 hdr = ath10k_htt_rx_skb_get_hdr(skb_peek(&amsdu));
Kalle Valo5e3dd152013-06-12 20:52:10 +03001278
1279 if (ath10k_htt_rx_hdr_is_amsdu(hdr))
Michal Kazior9aa505d2014-11-18 09:24:47 +02001280 ath10k_htt_rx_amsdu(htt, rx_status, &amsdu);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001281 else
Michal Kazior9aa505d2014-11-18 09:24:47 +02001282 ath10k_htt_rx_msdu(htt, rx_status,
1283 __skb_dequeue(&amsdu));
Kalle Valo5e3dd152013-06-12 20:52:10 +03001284 }
1285 }
1286
Michal Kazior6e712d42013-09-24 10:18:36 +02001287 tasklet_schedule(&htt->rx_replenish_task);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001288}
1289
1290static void ath10k_htt_rx_frag_handler(struct ath10k_htt *htt,
Kalle Valo5b07e072014-09-14 12:50:06 +03001291 struct htt_rx_fragment_indication *frag)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001292{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001293 struct ath10k *ar = htt->ar;
Michal Kazior9aa505d2014-11-18 09:24:47 +02001294 struct sk_buff *msdu;
Janusz Dziedzic87326c92014-03-24 21:23:19 +01001295 enum htt_rx_mpdu_encrypt_type enctype;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001296 struct htt_rx_desc *rxd;
1297 enum rx_msdu_decap_format fmt;
Janusz Dziedzic6df92a32014-03-24 21:24:57 +01001298 struct ieee80211_rx_status *rx_status = &htt->rx_status;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001299 struct ieee80211_hdr *hdr;
Michal Kazior9aa505d2014-11-18 09:24:47 +02001300 struct sk_buff_head amsdu;
Janusz Dziedzicd84dd602014-03-24 21:23:20 +01001301 int ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001302 bool tkip_mic_err;
1303 bool decrypt_err;
1304 u8 *fw_desc;
1305 int fw_desc_len, hdrlen, paramlen;
1306 int trim;
Janusz Dziedzic0ccb7a32014-07-25 11:28:50 +03001307 u32 attention = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001308
1309 fw_desc_len = __le16_to_cpu(frag->fw_rx_desc_bytes);
1310 fw_desc = (u8 *)frag->fw_msdu_rx_desc;
1311
Michal Kazior9aa505d2014-11-18 09:24:47 +02001312 __skb_queue_head_init(&amsdu);
Michal Kazior45967082014-02-27 18:50:05 +02001313
1314 spin_lock_bh(&htt->rx_ring.lock);
Janusz Dziedzicd84dd602014-03-24 21:23:20 +01001315 ret = ath10k_htt_rx_amsdu_pop(htt, &fw_desc, &fw_desc_len,
Michal Kazior9aa505d2014-11-18 09:24:47 +02001316 &amsdu, &attention);
Michal Kazior45967082014-02-27 18:50:05 +02001317 spin_unlock_bh(&htt->rx_ring.lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001318
Michal Kazior686687c2014-10-23 17:04:24 +03001319 tasklet_schedule(&htt->rx_replenish_task);
1320
Michal Kazior7aa7a722014-08-25 12:09:38 +02001321 ath10k_dbg(ar, ATH10K_DBG_HTT_DUMP, "htt rx frag ahead\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03001322
Janusz Dziedzicd84dd602014-03-24 21:23:20 +01001323 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001324 ath10k_warn(ar, "failed to pop amsdu from httr rx ring for fragmented rx %d\n",
Janusz Dziedzicd84dd602014-03-24 21:23:20 +01001325 ret);
Michal Kazior9aa505d2014-11-18 09:24:47 +02001326 __skb_queue_purge(&amsdu);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001327 return;
1328 }
1329
Michal Kazior9aa505d2014-11-18 09:24:47 +02001330 if (skb_queue_len(&amsdu) != 1) {
1331 ath10k_warn(ar, "failed to pop frag amsdu: too many msdus\n");
1332 __skb_queue_purge(&amsdu);
1333 return;
1334 }
1335
1336 msdu = __skb_dequeue(&amsdu);
1337
Kalle Valo5e3dd152013-06-12 20:52:10 +03001338 /* FIXME: implement signal strength */
Ben Greear4b81d172014-05-26 12:46:04 +03001339 rx_status->flag |= RX_FLAG_NO_SIGNAL_VAL;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001340
Michal Kazior9aa505d2014-11-18 09:24:47 +02001341 hdr = (struct ieee80211_hdr *)msdu->data;
1342 rxd = (void *)msdu->data - sizeof(*rxd);
Janusz Dziedzic0ccb7a32014-07-25 11:28:50 +03001343 tkip_mic_err = !!(attention & RX_ATTENTION_FLAGS_TKIP_MIC_ERR);
1344 decrypt_err = !!(attention & RX_ATTENTION_FLAGS_DECRYPT_ERR);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001345 fmt = MS(__le32_to_cpu(rxd->msdu_start.info1),
Kalle Valo5b07e072014-09-14 12:50:06 +03001346 RX_MSDU_START_INFO1_DECAP_FORMAT);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001347
1348 if (fmt != RX_MSDU_DECAP_RAW) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001349 ath10k_warn(ar, "we dont support non-raw fragmented rx yet\n");
Michal Kazior9aa505d2014-11-18 09:24:47 +02001350 dev_kfree_skb_any(msdu);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001351 goto end;
1352 }
1353
Janusz Dziedzic87326c92014-03-24 21:23:19 +01001354 enctype = MS(__le32_to_cpu(rxd->mpdu_start.info0),
1355 RX_MPDU_START_INFO0_ENCRYPT_TYPE);
Michal Kazior9aa505d2014-11-18 09:24:47 +02001356 ath10k_htt_rx_h_protected(htt, rx_status, msdu, enctype, fmt,
Michal Kaziorc071dcb2014-05-23 11:33:18 +03001357 true);
Michal Kazior9aa505d2014-11-18 09:24:47 +02001358 msdu->ip_summed = ath10k_htt_rx_get_csum_state(msdu);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001359
Janusz Dziedzic87326c92014-03-24 21:23:19 +01001360 if (tkip_mic_err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001361 ath10k_warn(ar, "tkip mic error\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03001362
1363 if (decrypt_err) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001364 ath10k_warn(ar, "decryption err in fragmented rx\n");
Michal Kazior9aa505d2014-11-18 09:24:47 +02001365 dev_kfree_skb_any(msdu);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001366 goto end;
1367 }
1368
Janusz Dziedzic87326c92014-03-24 21:23:19 +01001369 if (enctype != HTT_RX_MPDU_ENCRYPT_NONE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001370 hdrlen = ieee80211_hdrlen(hdr->frame_control);
Michal Kazior7aa7a722014-08-25 12:09:38 +02001371 paramlen = ath10k_htt_rx_crypto_param_len(ar, enctype);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001372
1373 /* It is more efficient to move the header than the payload */
Michal Kazior9aa505d2014-11-18 09:24:47 +02001374 memmove((void *)msdu->data + paramlen,
1375 (void *)msdu->data,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001376 hdrlen);
Michal Kazior9aa505d2014-11-18 09:24:47 +02001377 skb_pull(msdu, paramlen);
1378 hdr = (struct ieee80211_hdr *)msdu->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001379 }
1380
1381 /* remove trailing FCS */
1382 trim = 4;
1383
1384 /* remove crypto trailer */
Michal Kazior7aa7a722014-08-25 12:09:38 +02001385 trim += ath10k_htt_rx_crypto_tail_len(ar, enctype);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001386
1387 /* last fragment of TKIP frags has MIC */
1388 if (!ieee80211_has_morefrags(hdr->frame_control) &&
Janusz Dziedzic87326c92014-03-24 21:23:19 +01001389 enctype == HTT_RX_MPDU_ENCRYPT_TKIP_WPA)
Michal Kazior890d3b22014-10-23 17:04:22 +03001390 trim += MICHAEL_MIC_LEN;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001391
Michal Kazior9aa505d2014-11-18 09:24:47 +02001392 if (trim > msdu->len) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001393 ath10k_warn(ar, "htt rx fragment: trailer longer than the frame itself? drop\n");
Michal Kazior9aa505d2014-11-18 09:24:47 +02001394 dev_kfree_skb_any(msdu);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001395 goto end;
1396 }
1397
Michal Kazior9aa505d2014-11-18 09:24:47 +02001398 skb_trim(msdu, msdu->len - trim);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001399
Michal Kazior7aa7a722014-08-25 12:09:38 +02001400 ath10k_dbg_dump(ar, ATH10K_DBG_HTT_DUMP, NULL, "htt rx frag mpdu: ",
Michal Kazior9aa505d2014-11-18 09:24:47 +02001401 msdu->data, msdu->len);
1402 ath10k_process_rx(htt->ar, rx_status, msdu);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001403
1404end:
1405 if (fw_desc_len > 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001406 ath10k_dbg(ar, ATH10K_DBG_HTT,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001407 "expecting more fragmented rx in one indication %d\n",
1408 fw_desc_len);
1409 }
1410}
1411
Michal Kazior6c5151a2014-02-27 18:50:04 +02001412static void ath10k_htt_rx_frm_tx_compl(struct ath10k *ar,
1413 struct sk_buff *skb)
1414{
1415 struct ath10k_htt *htt = &ar->htt;
1416 struct htt_resp *resp = (struct htt_resp *)skb->data;
1417 struct htt_tx_done tx_done = {};
1418 int status = MS(resp->data_tx_completion.flags, HTT_DATA_TX_STATUS);
1419 __le16 msdu_id;
1420 int i;
1421
Michal Kazior45967082014-02-27 18:50:05 +02001422 lockdep_assert_held(&htt->tx_lock);
1423
Michal Kazior6c5151a2014-02-27 18:50:04 +02001424 switch (status) {
1425 case HTT_DATA_TX_STATUS_NO_ACK:
1426 tx_done.no_ack = true;
1427 break;
1428 case HTT_DATA_TX_STATUS_OK:
1429 break;
1430 case HTT_DATA_TX_STATUS_DISCARD:
1431 case HTT_DATA_TX_STATUS_POSTPONE:
1432 case HTT_DATA_TX_STATUS_DOWNLOAD_FAIL:
1433 tx_done.discard = true;
1434 break;
1435 default:
Michal Kazior7aa7a722014-08-25 12:09:38 +02001436 ath10k_warn(ar, "unhandled tx completion status %d\n", status);
Michal Kazior6c5151a2014-02-27 18:50:04 +02001437 tx_done.discard = true;
1438 break;
1439 }
1440
Michal Kazior7aa7a722014-08-25 12:09:38 +02001441 ath10k_dbg(ar, ATH10K_DBG_HTT, "htt tx completion num_msdus %d\n",
Michal Kazior6c5151a2014-02-27 18:50:04 +02001442 resp->data_tx_completion.num_msdus);
1443
1444 for (i = 0; i < resp->data_tx_completion.num_msdus; i++) {
1445 msdu_id = resp->data_tx_completion.msdus[i];
1446 tx_done.msdu_id = __le16_to_cpu(msdu_id);
1447 ath10k_txrx_tx_unref(htt, &tx_done);
1448 }
1449}
1450
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02001451static void ath10k_htt_rx_addba(struct ath10k *ar, struct htt_resp *resp)
1452{
1453 struct htt_rx_addba *ev = &resp->rx_addba;
1454 struct ath10k_peer *peer;
1455 struct ath10k_vif *arvif;
1456 u16 info0, tid, peer_id;
1457
1458 info0 = __le16_to_cpu(ev->info0);
1459 tid = MS(info0, HTT_RX_BA_INFO0_TID);
1460 peer_id = MS(info0, HTT_RX_BA_INFO0_PEER_ID);
1461
Michal Kazior7aa7a722014-08-25 12:09:38 +02001462 ath10k_dbg(ar, ATH10K_DBG_HTT,
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02001463 "htt rx addba tid %hu peer_id %hu size %hhu\n",
1464 tid, peer_id, ev->window_size);
1465
1466 spin_lock_bh(&ar->data_lock);
1467 peer = ath10k_peer_find_by_id(ar, peer_id);
1468 if (!peer) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001469 ath10k_warn(ar, "received addba event for invalid peer_id: %hu\n",
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02001470 peer_id);
1471 spin_unlock_bh(&ar->data_lock);
1472 return;
1473 }
1474
1475 arvif = ath10k_get_arvif(ar, peer->vdev_id);
1476 if (!arvif) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001477 ath10k_warn(ar, "received addba event for invalid vdev_id: %u\n",
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02001478 peer->vdev_id);
1479 spin_unlock_bh(&ar->data_lock);
1480 return;
1481 }
1482
Michal Kazior7aa7a722014-08-25 12:09:38 +02001483 ath10k_dbg(ar, ATH10K_DBG_HTT,
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02001484 "htt rx start rx ba session sta %pM tid %hu size %hhu\n",
1485 peer->addr, tid, ev->window_size);
1486
1487 ieee80211_start_rx_ba_session_offl(arvif->vif, peer->addr, tid);
1488 spin_unlock_bh(&ar->data_lock);
1489}
1490
1491static void ath10k_htt_rx_delba(struct ath10k *ar, struct htt_resp *resp)
1492{
1493 struct htt_rx_delba *ev = &resp->rx_delba;
1494 struct ath10k_peer *peer;
1495 struct ath10k_vif *arvif;
1496 u16 info0, tid, peer_id;
1497
1498 info0 = __le16_to_cpu(ev->info0);
1499 tid = MS(info0, HTT_RX_BA_INFO0_TID);
1500 peer_id = MS(info0, HTT_RX_BA_INFO0_PEER_ID);
1501
Michal Kazior7aa7a722014-08-25 12:09:38 +02001502 ath10k_dbg(ar, ATH10K_DBG_HTT,
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02001503 "htt rx delba tid %hu peer_id %hu\n",
1504 tid, peer_id);
1505
1506 spin_lock_bh(&ar->data_lock);
1507 peer = ath10k_peer_find_by_id(ar, peer_id);
1508 if (!peer) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001509 ath10k_warn(ar, "received addba event for invalid peer_id: %hu\n",
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02001510 peer_id);
1511 spin_unlock_bh(&ar->data_lock);
1512 return;
1513 }
1514
1515 arvif = ath10k_get_arvif(ar, peer->vdev_id);
1516 if (!arvif) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001517 ath10k_warn(ar, "received addba event for invalid vdev_id: %u\n",
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02001518 peer->vdev_id);
1519 spin_unlock_bh(&ar->data_lock);
1520 return;
1521 }
1522
Michal Kazior7aa7a722014-08-25 12:09:38 +02001523 ath10k_dbg(ar, ATH10K_DBG_HTT,
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02001524 "htt rx stop rx ba session sta %pM tid %hu\n",
1525 peer->addr, tid);
1526
1527 ieee80211_stop_rx_ba_session_offl(arvif->vif, peer->addr, tid);
1528 spin_unlock_bh(&ar->data_lock);
1529}
1530
Kalle Valo5e3dd152013-06-12 20:52:10 +03001531void ath10k_htt_t2h_msg_handler(struct ath10k *ar, struct sk_buff *skb)
1532{
Michal Kazioredb82362013-07-05 16:15:14 +03001533 struct ath10k_htt *htt = &ar->htt;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001534 struct htt_resp *resp = (struct htt_resp *)skb->data;
1535
1536 /* confirm alignment */
1537 if (!IS_ALIGNED((unsigned long)skb->data, 4))
Michal Kazior7aa7a722014-08-25 12:09:38 +02001538 ath10k_warn(ar, "unaligned htt message, expect trouble\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03001539
Michal Kazior7aa7a722014-08-25 12:09:38 +02001540 ath10k_dbg(ar, ATH10K_DBG_HTT, "htt rx, msg_type: 0x%0X\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001541 resp->hdr.msg_type);
1542 switch (resp->hdr.msg_type) {
1543 case HTT_T2H_MSG_TYPE_VERSION_CONF: {
1544 htt->target_version_major = resp->ver_resp.major;
1545 htt->target_version_minor = resp->ver_resp.minor;
1546 complete(&htt->target_version_received);
1547 break;
1548 }
Michal Kazior6c5151a2014-02-27 18:50:04 +02001549 case HTT_T2H_MSG_TYPE_RX_IND:
Michal Kazior45967082014-02-27 18:50:05 +02001550 spin_lock_bh(&htt->rx_ring.lock);
1551 __skb_queue_tail(&htt->rx_compl_q, skb);
1552 spin_unlock_bh(&htt->rx_ring.lock);
Michal Kazior6c5151a2014-02-27 18:50:04 +02001553 tasklet_schedule(&htt->txrx_compl_task);
1554 return;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001555 case HTT_T2H_MSG_TYPE_PEER_MAP: {
1556 struct htt_peer_map_event ev = {
1557 .vdev_id = resp->peer_map.vdev_id,
1558 .peer_id = __le16_to_cpu(resp->peer_map.peer_id),
1559 };
1560 memcpy(ev.addr, resp->peer_map.addr, sizeof(ev.addr));
1561 ath10k_peer_map_event(htt, &ev);
1562 break;
1563 }
1564 case HTT_T2H_MSG_TYPE_PEER_UNMAP: {
1565 struct htt_peer_unmap_event ev = {
1566 .peer_id = __le16_to_cpu(resp->peer_unmap.peer_id),
1567 };
1568 ath10k_peer_unmap_event(htt, &ev);
1569 break;
1570 }
1571 case HTT_T2H_MSG_TYPE_MGMT_TX_COMPLETION: {
1572 struct htt_tx_done tx_done = {};
1573 int status = __le32_to_cpu(resp->mgmt_tx_completion.status);
1574
1575 tx_done.msdu_id =
1576 __le32_to_cpu(resp->mgmt_tx_completion.desc_id);
1577
1578 switch (status) {
1579 case HTT_MGMT_TX_STATUS_OK:
1580 break;
1581 case HTT_MGMT_TX_STATUS_RETRY:
1582 tx_done.no_ack = true;
1583 break;
1584 case HTT_MGMT_TX_STATUS_DROP:
1585 tx_done.discard = true;
1586 break;
1587 }
1588
Michal Kazior6c5151a2014-02-27 18:50:04 +02001589 spin_lock_bh(&htt->tx_lock);
Michal Kazior0a89f8a2013-09-18 14:43:20 +02001590 ath10k_txrx_tx_unref(htt, &tx_done);
Michal Kazior6c5151a2014-02-27 18:50:04 +02001591 spin_unlock_bh(&htt->tx_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001592 break;
1593 }
Michal Kazior6c5151a2014-02-27 18:50:04 +02001594 case HTT_T2H_MSG_TYPE_TX_COMPL_IND:
1595 spin_lock_bh(&htt->tx_lock);
1596 __skb_queue_tail(&htt->tx_compl_q, skb);
1597 spin_unlock_bh(&htt->tx_lock);
1598 tasklet_schedule(&htt->txrx_compl_task);
1599 return;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001600 case HTT_T2H_MSG_TYPE_SEC_IND: {
1601 struct ath10k *ar = htt->ar;
1602 struct htt_security_indication *ev = &resp->security_indication;
1603
Michal Kazior7aa7a722014-08-25 12:09:38 +02001604 ath10k_dbg(ar, ATH10K_DBG_HTT,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001605 "sec ind peer_id %d unicast %d type %d\n",
1606 __le16_to_cpu(ev->peer_id),
1607 !!(ev->flags & HTT_SECURITY_IS_UNICAST),
1608 MS(ev->flags, HTT_SECURITY_TYPE));
1609 complete(&ar->install_key_done);
1610 break;
1611 }
1612 case HTT_T2H_MSG_TYPE_RX_FRAG_IND: {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001613 ath10k_dbg_dump(ar, ATH10K_DBG_HTT_DUMP, NULL, "htt event: ",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001614 skb->data, skb->len);
1615 ath10k_htt_rx_frag_handler(htt, &resp->rx_frag_ind);
1616 break;
1617 }
1618 case HTT_T2H_MSG_TYPE_TEST:
1619 /* FIX THIS */
1620 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001621 case HTT_T2H_MSG_TYPE_STATS_CONF:
Michal Kaziord35a6c12014-09-02 11:00:21 +03001622 trace_ath10k_htt_stats(ar, skb->data, skb->len);
Kalle Valoa9bf0502013-09-03 11:43:55 +03001623 break;
1624 case HTT_T2H_MSG_TYPE_TX_INSPECT_IND:
Michal Kazior708b9bd2014-07-21 20:52:59 +03001625 /* Firmware can return tx frames if it's unable to fully
1626 * process them and suspects host may be able to fix it. ath10k
1627 * sends all tx frames as already inspected so this shouldn't
1628 * happen unless fw has a bug.
1629 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02001630 ath10k_warn(ar, "received an unexpected htt tx inspect event\n");
Michal Kazior708b9bd2014-07-21 20:52:59 +03001631 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001632 case HTT_T2H_MSG_TYPE_RX_ADDBA:
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02001633 ath10k_htt_rx_addba(ar, resp);
1634 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001635 case HTT_T2H_MSG_TYPE_RX_DELBA:
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02001636 ath10k_htt_rx_delba(ar, resp);
1637 break;
Rajkumar Manoharanbfdd7932014-10-03 08:02:40 +03001638 case HTT_T2H_MSG_TYPE_PKTLOG: {
1639 struct ath10k_pktlog_hdr *hdr =
1640 (struct ath10k_pktlog_hdr *)resp->pktlog_msg.payload;
1641
1642 trace_ath10k_htt_pktlog(ar, resp->pktlog_msg.payload,
1643 sizeof(*hdr) +
1644 __le16_to_cpu(hdr->size));
1645 break;
1646 }
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02001647 case HTT_T2H_MSG_TYPE_RX_FLUSH: {
1648 /* Ignore this event because mac80211 takes care of Rx
1649 * aggregation reordering.
1650 */
1651 break;
1652 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001653 default:
Michal Kazior2358a542014-10-02 13:32:55 +02001654 ath10k_warn(ar, "htt event (%d) not handled\n",
1655 resp->hdr.msg_type);
Michal Kazior7aa7a722014-08-25 12:09:38 +02001656 ath10k_dbg_dump(ar, ATH10K_DBG_HTT_DUMP, NULL, "htt event: ",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001657 skb->data, skb->len);
1658 break;
1659 };
1660
1661 /* Free the indication buffer */
1662 dev_kfree_skb_any(skb);
1663}
Michal Kazior6c5151a2014-02-27 18:50:04 +02001664
1665static void ath10k_htt_txrx_compl_task(unsigned long ptr)
1666{
1667 struct ath10k_htt *htt = (struct ath10k_htt *)ptr;
1668 struct htt_resp *resp;
1669 struct sk_buff *skb;
1670
Michal Kazior45967082014-02-27 18:50:05 +02001671 spin_lock_bh(&htt->tx_lock);
1672 while ((skb = __skb_dequeue(&htt->tx_compl_q))) {
Michal Kazior6c5151a2014-02-27 18:50:04 +02001673 ath10k_htt_rx_frm_tx_compl(htt->ar, skb);
1674 dev_kfree_skb_any(skb);
1675 }
Michal Kazior45967082014-02-27 18:50:05 +02001676 spin_unlock_bh(&htt->tx_lock);
Michal Kazior6c5151a2014-02-27 18:50:04 +02001677
Michal Kazior45967082014-02-27 18:50:05 +02001678 spin_lock_bh(&htt->rx_ring.lock);
1679 while ((skb = __skb_dequeue(&htt->rx_compl_q))) {
Michal Kazior6c5151a2014-02-27 18:50:04 +02001680 resp = (struct htt_resp *)skb->data;
1681 ath10k_htt_rx_handler(htt, &resp->rx_ind);
1682 dev_kfree_skb_any(skb);
1683 }
Michal Kazior45967082014-02-27 18:50:05 +02001684 spin_unlock_bh(&htt->rx_ring.lock);
Michal Kazior6c5151a2014-02-27 18:50:04 +02001685}