ath10k: simplify rx ring size/fill calculation
[cascardo/linux.git] / drivers / net / wireless / ath / ath10k / htt_rx.c
1 /*
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
18 #include "core.h"
19 #include "htc.h"
20 #include "htt.h"
21 #include "txrx.h"
22 #include "debug.h"
23 #include "trace.h"
24 #include "mac.h"
25
26 #include <linux/log2.h>
27
28 #define HTT_RX_RING_SIZE 1024
29 #define HTT_RX_RING_FILL_LEVEL 1000
30
31 /* when under memory pressure rx ring refill may fail and needs a retry */
32 #define HTT_RX_RING_REFILL_RETRY_MS 50
33
34 static int ath10k_htt_rx_get_csum_state(struct sk_buff *skb);
35 static void ath10k_htt_txrx_compl_task(unsigned long ptr);
36
37 static void ath10k_htt_rx_ring_free(struct ath10k_htt *htt)
38 {
39         struct sk_buff *skb;
40         struct ath10k_skb_cb *cb;
41         int i;
42
43         for (i = 0; i < htt->rx_ring.fill_cnt; i++) {
44                 skb = htt->rx_ring.netbufs_ring[i];
45                 cb = ATH10K_SKB_CB(skb);
46                 dma_unmap_single(htt->ar->dev, cb->paddr,
47                                  skb->len + skb_tailroom(skb),
48                                  DMA_FROM_DEVICE);
49                 dev_kfree_skb_any(skb);
50         }
51
52         htt->rx_ring.fill_cnt = 0;
53 }
54
55 static int __ath10k_htt_rx_ring_fill_n(struct ath10k_htt *htt, int num)
56 {
57         struct htt_rx_desc *rx_desc;
58         struct sk_buff *skb;
59         dma_addr_t paddr;
60         int ret = 0, idx;
61
62         idx = __le32_to_cpu(*htt->rx_ring.alloc_idx.vaddr);
63         while (num > 0) {
64                 skb = dev_alloc_skb(HTT_RX_BUF_SIZE + HTT_RX_DESC_ALIGN);
65                 if (!skb) {
66                         ret = -ENOMEM;
67                         goto fail;
68                 }
69
70                 if (!IS_ALIGNED((unsigned long)skb->data, HTT_RX_DESC_ALIGN))
71                         skb_pull(skb,
72                                  PTR_ALIGN(skb->data, HTT_RX_DESC_ALIGN) -
73                                  skb->data);
74
75                 /* Clear rx_desc attention word before posting to Rx ring */
76                 rx_desc = (struct htt_rx_desc *)skb->data;
77                 rx_desc->attention.flags = __cpu_to_le32(0);
78
79                 paddr = dma_map_single(htt->ar->dev, skb->data,
80                                        skb->len + skb_tailroom(skb),
81                                        DMA_FROM_DEVICE);
82
83                 if (unlikely(dma_mapping_error(htt->ar->dev, paddr))) {
84                         dev_kfree_skb_any(skb);
85                         ret = -ENOMEM;
86                         goto fail;
87                 }
88
89                 ATH10K_SKB_CB(skb)->paddr = paddr;
90                 htt->rx_ring.netbufs_ring[idx] = skb;
91                 htt->rx_ring.paddrs_ring[idx] = __cpu_to_le32(paddr);
92                 htt->rx_ring.fill_cnt++;
93
94                 num--;
95                 idx++;
96                 idx &= htt->rx_ring.size_mask;
97         }
98
99 fail:
100         *htt->rx_ring.alloc_idx.vaddr = __cpu_to_le32(idx);
101         return ret;
102 }
103
104 static int ath10k_htt_rx_ring_fill_n(struct ath10k_htt *htt, int num)
105 {
106         lockdep_assert_held(&htt->rx_ring.lock);
107         return __ath10k_htt_rx_ring_fill_n(htt, num);
108 }
109
110 static void ath10k_htt_rx_msdu_buff_replenish(struct ath10k_htt *htt)
111 {
112         int ret, num_deficit, num_to_fill;
113
114         /* Refilling the whole RX ring buffer proves to be a bad idea. The
115          * reason is RX may take up significant amount of CPU cycles and starve
116          * other tasks, e.g. TX on an ethernet device while acting as a bridge
117          * with ath10k wlan interface. This ended up with very poor performance
118          * once CPU the host system was overwhelmed with RX on ath10k.
119          *
120          * By limiting the number of refills the replenishing occurs
121          * progressively. This in turns makes use of the fact tasklets are
122          * processed in FIFO order. This means actual RX processing can starve
123          * out refilling. If there's not enough buffers on RX ring FW will not
124          * report RX until it is refilled with enough buffers. This
125          * automatically balances load wrt to CPU power.
126          *
127          * This probably comes at a cost of lower maximum throughput but
128          * improves the avarage and stability. */
129         spin_lock_bh(&htt->rx_ring.lock);
130         num_deficit = htt->rx_ring.fill_level - htt->rx_ring.fill_cnt;
131         num_to_fill = min(ATH10K_HTT_MAX_NUM_REFILL, num_deficit);
132         num_deficit -= num_to_fill;
133         ret = ath10k_htt_rx_ring_fill_n(htt, num_to_fill);
134         if (ret == -ENOMEM) {
135                 /*
136                  * Failed to fill it to the desired level -
137                  * we'll start a timer and try again next time.
138                  * As long as enough buffers are left in the ring for
139                  * another A-MPDU rx, no special recovery is needed.
140                  */
141                 mod_timer(&htt->rx_ring.refill_retry_timer, jiffies +
142                           msecs_to_jiffies(HTT_RX_RING_REFILL_RETRY_MS));
143         } else if (num_deficit > 0) {
144                 tasklet_schedule(&htt->rx_replenish_task);
145         }
146         spin_unlock_bh(&htt->rx_ring.lock);
147 }
148
149 static void ath10k_htt_rx_ring_refill_retry(unsigned long arg)
150 {
151         struct ath10k_htt *htt = (struct ath10k_htt *)arg;
152
153         ath10k_htt_rx_msdu_buff_replenish(htt);
154 }
155
156 static void ath10k_htt_rx_ring_clean_up(struct ath10k_htt *htt)
157 {
158         struct sk_buff *skb;
159         int i;
160
161         for (i = 0; i < htt->rx_ring.size; i++) {
162                 skb = htt->rx_ring.netbufs_ring[i];
163                 if (!skb)
164                         continue;
165
166                 dma_unmap_single(htt->ar->dev, ATH10K_SKB_CB(skb)->paddr,
167                                  skb->len + skb_tailroom(skb),
168                                  DMA_FROM_DEVICE);
169                 dev_kfree_skb_any(skb);
170                 htt->rx_ring.netbufs_ring[i] = NULL;
171         }
172 }
173
174 void ath10k_htt_rx_free(struct ath10k_htt *htt)
175 {
176         del_timer_sync(&htt->rx_ring.refill_retry_timer);
177         tasklet_kill(&htt->rx_replenish_task);
178         tasklet_kill(&htt->txrx_compl_task);
179
180         skb_queue_purge(&htt->tx_compl_q);
181         skb_queue_purge(&htt->rx_compl_q);
182
183         ath10k_htt_rx_ring_clean_up(htt);
184
185         dma_free_coherent(htt->ar->dev,
186                           (htt->rx_ring.size *
187                            sizeof(htt->rx_ring.paddrs_ring)),
188                           htt->rx_ring.paddrs_ring,
189                           htt->rx_ring.base_paddr);
190
191         dma_free_coherent(htt->ar->dev,
192                           sizeof(*htt->rx_ring.alloc_idx.vaddr),
193                           htt->rx_ring.alloc_idx.vaddr,
194                           htt->rx_ring.alloc_idx.paddr);
195
196         kfree(htt->rx_ring.netbufs_ring);
197 }
198
199 static inline struct sk_buff *ath10k_htt_rx_netbuf_pop(struct ath10k_htt *htt)
200 {
201         struct ath10k *ar = htt->ar;
202         int idx;
203         struct sk_buff *msdu;
204
205         lockdep_assert_held(&htt->rx_ring.lock);
206
207         if (htt->rx_ring.fill_cnt == 0) {
208                 ath10k_warn(ar, "tried to pop sk_buff from an empty rx ring\n");
209                 return NULL;
210         }
211
212         idx = htt->rx_ring.sw_rd_idx.msdu_payld;
213         msdu = htt->rx_ring.netbufs_ring[idx];
214         htt->rx_ring.netbufs_ring[idx] = NULL;
215
216         idx++;
217         idx &= htt->rx_ring.size_mask;
218         htt->rx_ring.sw_rd_idx.msdu_payld = idx;
219         htt->rx_ring.fill_cnt--;
220
221         dma_unmap_single(htt->ar->dev,
222                          ATH10K_SKB_CB(msdu)->paddr,
223                          msdu->len + skb_tailroom(msdu),
224                          DMA_FROM_DEVICE);
225         ath10k_dbg_dump(ar, ATH10K_DBG_HTT_DUMP, NULL, "htt rx netbuf pop: ",
226                         msdu->data, msdu->len + skb_tailroom(msdu));
227
228         return msdu;
229 }
230
231 /* return: < 0 fatal error, 0 - non chained msdu, 1 chained msdu */
232 static int ath10k_htt_rx_amsdu_pop(struct ath10k_htt *htt,
233                                    u8 **fw_desc, int *fw_desc_len,
234                                    struct sk_buff_head *amsdu)
235 {
236         struct ath10k *ar = htt->ar;
237         int msdu_len, msdu_chaining = 0;
238         struct sk_buff *msdu;
239         struct htt_rx_desc *rx_desc;
240
241         lockdep_assert_held(&htt->rx_ring.lock);
242
243         for (;;) {
244                 int last_msdu, msdu_len_invalid, msdu_chained;
245
246                 msdu = ath10k_htt_rx_netbuf_pop(htt);
247                 if (!msdu) {
248                         __skb_queue_purge(amsdu);
249                         return -ENOENT;
250                 }
251
252                 __skb_queue_tail(amsdu, msdu);
253
254                 rx_desc = (struct htt_rx_desc *)msdu->data;
255
256                 /* FIXME: we must report msdu payload since this is what caller
257                  *        expects now */
258                 skb_put(msdu, offsetof(struct htt_rx_desc, msdu_payload));
259                 skb_pull(msdu, offsetof(struct htt_rx_desc, msdu_payload));
260
261                 /*
262                  * Sanity check - confirm the HW is finished filling in the
263                  * rx data.
264                  * If the HW and SW are working correctly, then it's guaranteed
265                  * that the HW's MAC DMA is done before this point in the SW.
266                  * To prevent the case that we handle a stale Rx descriptor,
267                  * just assert for now until we have a way to recover.
268                  */
269                 if (!(__le32_to_cpu(rx_desc->attention.flags)
270                                 & RX_ATTENTION_FLAGS_MSDU_DONE)) {
271                         __skb_queue_purge(amsdu);
272                         return -EIO;
273                 }
274
275                 /*
276                  * Copy the FW rx descriptor for this MSDU from the rx
277                  * indication message into the MSDU's netbuf. HL uses the
278                  * same rx indication message definition as LL, and simply
279                  * appends new info (fields from the HW rx desc, and the
280                  * MSDU payload itself). So, the offset into the rx
281                  * indication message only has to account for the standard
282                  * offset of the per-MSDU FW rx desc info within the
283                  * message, and how many bytes of the per-MSDU FW rx desc
284                  * info have already been consumed. (And the endianness of
285                  * the host, since for a big-endian host, the rx ind
286                  * message contents, including the per-MSDU rx desc bytes,
287                  * were byteswapped during upload.)
288                  */
289                 if (*fw_desc_len > 0) {
290                         rx_desc->fw_desc.info0 = **fw_desc;
291                         /*
292                          * The target is expected to only provide the basic
293                          * per-MSDU rx descriptors. Just to be sure, verify
294                          * that the target has not attached extension data
295                          * (e.g. LRO flow ID).
296                          */
297
298                         /* or more, if there's extension data */
299                         (*fw_desc)++;
300                         (*fw_desc_len)--;
301                 } else {
302                         /*
303                          * When an oversized AMSDU happened, FW will lost
304                          * some of MSDU status - in this case, the FW
305                          * descriptors provided will be less than the
306                          * actual MSDUs inside this MPDU. Mark the FW
307                          * descriptors so that it will still deliver to
308                          * upper stack, if no CRC error for this MPDU.
309                          *
310                          * FIX THIS - the FW descriptors are actually for
311                          * MSDUs in the end of this A-MSDU instead of the
312                          * beginning.
313                          */
314                         rx_desc->fw_desc.info0 = 0;
315                 }
316
317                 msdu_len_invalid = !!(__le32_to_cpu(rx_desc->attention.flags)
318                                         & (RX_ATTENTION_FLAGS_MPDU_LENGTH_ERR |
319                                            RX_ATTENTION_FLAGS_MSDU_LENGTH_ERR));
320                 msdu_len = MS(__le32_to_cpu(rx_desc->msdu_start.info0),
321                               RX_MSDU_START_INFO0_MSDU_LENGTH);
322                 msdu_chained = rx_desc->frag_info.ring2_more_count;
323
324                 if (msdu_len_invalid)
325                         msdu_len = 0;
326
327                 skb_trim(msdu, 0);
328                 skb_put(msdu, min(msdu_len, HTT_RX_MSDU_SIZE));
329                 msdu_len -= msdu->len;
330
331                 /* Note: Chained buffers do not contain rx descriptor */
332                 while (msdu_chained--) {
333                         msdu = ath10k_htt_rx_netbuf_pop(htt);
334                         if (!msdu) {
335                                 __skb_queue_purge(amsdu);
336                                 return -ENOENT;
337                         }
338
339                         __skb_queue_tail(amsdu, msdu);
340                         skb_trim(msdu, 0);
341                         skb_put(msdu, min(msdu_len, HTT_RX_BUF_SIZE));
342                         msdu_len -= msdu->len;
343                         msdu_chaining = 1;
344                 }
345
346                 last_msdu = __le32_to_cpu(rx_desc->msdu_end.info0) &
347                                 RX_MSDU_END_INFO0_LAST_MSDU;
348
349                 trace_ath10k_htt_rx_desc(ar, &rx_desc->attention,
350                                          sizeof(*rx_desc) - sizeof(u32));
351
352                 if (last_msdu)
353                         break;
354         }
355
356         if (skb_queue_empty(amsdu))
357                 msdu_chaining = -1;
358
359         /*
360          * Don't refill the ring yet.
361          *
362          * First, the elements popped here are still in use - it is not
363          * safe to overwrite them until the matching call to
364          * mpdu_desc_list_next. Second, for efficiency it is preferable to
365          * refill the rx ring with 1 PPDU's worth of rx buffers (something
366          * like 32 x 3 buffers), rather than one MPDU's worth of rx buffers
367          * (something like 3 buffers). Consequently, we'll rely on the txrx
368          * SW to tell us when it is done pulling all the PPDU's rx buffers
369          * out of the rx ring, and then refill it just once.
370          */
371
372         return msdu_chaining;
373 }
374
375 static void ath10k_htt_rx_replenish_task(unsigned long ptr)
376 {
377         struct ath10k_htt *htt = (struct ath10k_htt *)ptr;
378
379         ath10k_htt_rx_msdu_buff_replenish(htt);
380 }
381
382 int ath10k_htt_rx_alloc(struct ath10k_htt *htt)
383 {
384         struct ath10k *ar = htt->ar;
385         dma_addr_t paddr;
386         void *vaddr;
387         size_t size;
388         struct timer_list *timer = &htt->rx_ring.refill_retry_timer;
389
390         htt->rx_confused = false;
391
392         /* XXX: The fill level could be changed during runtime in response to
393          * the host processing latency. Is this really worth it?
394          */
395         htt->rx_ring.size = HTT_RX_RING_SIZE;
396         htt->rx_ring.size_mask = htt->rx_ring.size - 1;
397         htt->rx_ring.fill_level = HTT_RX_RING_FILL_LEVEL;
398
399         if (!is_power_of_2(htt->rx_ring.size)) {
400                 ath10k_warn(ar, "htt rx ring size is not power of 2\n");
401                 return -EINVAL;
402         }
403
404         htt->rx_ring.netbufs_ring =
405                 kzalloc(htt->rx_ring.size * sizeof(struct sk_buff *),
406                         GFP_KERNEL);
407         if (!htt->rx_ring.netbufs_ring)
408                 goto err_netbuf;
409
410         size = htt->rx_ring.size * sizeof(htt->rx_ring.paddrs_ring);
411
412         vaddr = dma_alloc_coherent(htt->ar->dev, size, &paddr, GFP_DMA);
413         if (!vaddr)
414                 goto err_dma_ring;
415
416         htt->rx_ring.paddrs_ring = vaddr;
417         htt->rx_ring.base_paddr = paddr;
418
419         vaddr = dma_alloc_coherent(htt->ar->dev,
420                                    sizeof(*htt->rx_ring.alloc_idx.vaddr),
421                                    &paddr, GFP_DMA);
422         if (!vaddr)
423                 goto err_dma_idx;
424
425         htt->rx_ring.alloc_idx.vaddr = vaddr;
426         htt->rx_ring.alloc_idx.paddr = paddr;
427         htt->rx_ring.sw_rd_idx.msdu_payld = 0;
428         *htt->rx_ring.alloc_idx.vaddr = 0;
429
430         /* Initialize the Rx refill retry timer */
431         setup_timer(timer, ath10k_htt_rx_ring_refill_retry, (unsigned long)htt);
432
433         spin_lock_init(&htt->rx_ring.lock);
434
435         htt->rx_ring.fill_cnt = 0;
436         if (__ath10k_htt_rx_ring_fill_n(htt, htt->rx_ring.fill_level))
437                 goto err_fill_ring;
438
439         tasklet_init(&htt->rx_replenish_task, ath10k_htt_rx_replenish_task,
440                      (unsigned long)htt);
441
442         skb_queue_head_init(&htt->tx_compl_q);
443         skb_queue_head_init(&htt->rx_compl_q);
444
445         tasklet_init(&htt->txrx_compl_task, ath10k_htt_txrx_compl_task,
446                      (unsigned long)htt);
447
448         ath10k_dbg(ar, ATH10K_DBG_BOOT, "htt rx ring size %d fill_level %d\n",
449                    htt->rx_ring.size, htt->rx_ring.fill_level);
450         return 0;
451
452 err_fill_ring:
453         ath10k_htt_rx_ring_free(htt);
454         dma_free_coherent(htt->ar->dev,
455                           sizeof(*htt->rx_ring.alloc_idx.vaddr),
456                           htt->rx_ring.alloc_idx.vaddr,
457                           htt->rx_ring.alloc_idx.paddr);
458 err_dma_idx:
459         dma_free_coherent(htt->ar->dev,
460                           (htt->rx_ring.size *
461                            sizeof(htt->rx_ring.paddrs_ring)),
462                           htt->rx_ring.paddrs_ring,
463                           htt->rx_ring.base_paddr);
464 err_dma_ring:
465         kfree(htt->rx_ring.netbufs_ring);
466 err_netbuf:
467         return -ENOMEM;
468 }
469
470 static int ath10k_htt_rx_crypto_param_len(struct ath10k *ar,
471                                           enum htt_rx_mpdu_encrypt_type type)
472 {
473         switch (type) {
474         case HTT_RX_MPDU_ENCRYPT_NONE:
475                 return 0;
476         case HTT_RX_MPDU_ENCRYPT_WEP40:
477         case HTT_RX_MPDU_ENCRYPT_WEP104:
478                 return IEEE80211_WEP_IV_LEN;
479         case HTT_RX_MPDU_ENCRYPT_TKIP_WITHOUT_MIC:
480         case HTT_RX_MPDU_ENCRYPT_TKIP_WPA:
481                 return IEEE80211_TKIP_IV_LEN;
482         case HTT_RX_MPDU_ENCRYPT_AES_CCM_WPA2:
483                 return IEEE80211_CCMP_HDR_LEN;
484         case HTT_RX_MPDU_ENCRYPT_WEP128:
485         case HTT_RX_MPDU_ENCRYPT_WAPI:
486                 break;
487         }
488
489         ath10k_warn(ar, "unsupported encryption type %d\n", type);
490         return 0;
491 }
492
493 #define MICHAEL_MIC_LEN 8
494
495 static int ath10k_htt_rx_crypto_tail_len(struct ath10k *ar,
496                                          enum htt_rx_mpdu_encrypt_type type)
497 {
498         switch (type) {
499         case HTT_RX_MPDU_ENCRYPT_NONE:
500                 return 0;
501         case HTT_RX_MPDU_ENCRYPT_WEP40:
502         case HTT_RX_MPDU_ENCRYPT_WEP104:
503                 return IEEE80211_WEP_ICV_LEN;
504         case HTT_RX_MPDU_ENCRYPT_TKIP_WITHOUT_MIC:
505         case HTT_RX_MPDU_ENCRYPT_TKIP_WPA:
506                 return IEEE80211_TKIP_ICV_LEN;
507         case HTT_RX_MPDU_ENCRYPT_AES_CCM_WPA2:
508                 return IEEE80211_CCMP_MIC_LEN;
509         case HTT_RX_MPDU_ENCRYPT_WEP128:
510         case HTT_RX_MPDU_ENCRYPT_WAPI:
511                 break;
512         }
513
514         ath10k_warn(ar, "unsupported encryption type %d\n", type);
515         return 0;
516 }
517
518 struct rfc1042_hdr {
519         u8 llc_dsap;
520         u8 llc_ssap;
521         u8 llc_ctrl;
522         u8 snap_oui[3];
523         __be16 snap_type;
524 } __packed;
525
526 struct amsdu_subframe_hdr {
527         u8 dst[ETH_ALEN];
528         u8 src[ETH_ALEN];
529         __be16 len;
530 } __packed;
531
532 static const u8 rx_legacy_rate_idx[] = {
533         3,      /* 0x00  - 11Mbps  */
534         2,      /* 0x01  - 5.5Mbps */
535         1,      /* 0x02  - 2Mbps   */
536         0,      /* 0x03  - 1Mbps   */
537         3,      /* 0x04  - 11Mbps  */
538         2,      /* 0x05  - 5.5Mbps */
539         1,      /* 0x06  - 2Mbps   */
540         0,      /* 0x07  - 1Mbps   */
541         10,     /* 0x08  - 48Mbps  */
542         8,      /* 0x09  - 24Mbps  */
543         6,      /* 0x0A  - 12Mbps  */
544         4,      /* 0x0B  - 6Mbps   */
545         11,     /* 0x0C  - 54Mbps  */
546         9,      /* 0x0D  - 36Mbps  */
547         7,      /* 0x0E  - 18Mbps  */
548         5,      /* 0x0F  - 9Mbps   */
549 };
550
551 static void ath10k_htt_rx_h_rates(struct ath10k *ar,
552                                   struct ieee80211_rx_status *status,
553                                   struct htt_rx_desc *rxd)
554 {
555         enum ieee80211_band band;
556         u8 cck, rate, rate_idx, bw, sgi, mcs, nss;
557         u8 preamble = 0;
558         u32 info1, info2, info3;
559
560         /* Band value can't be set as undefined but freq can be 0 - use that to
561          * determine whether band is provided.
562          *
563          * FIXME: Perhaps this can go away if CCK rate reporting is a little
564          * reworked?
565          */
566         if (!status->freq)
567                 return;
568
569         band = status->band;
570         info1 = __le32_to_cpu(rxd->ppdu_start.info1);
571         info2 = __le32_to_cpu(rxd->ppdu_start.info2);
572         info3 = __le32_to_cpu(rxd->ppdu_start.info3);
573
574         preamble = MS(info1, RX_PPDU_START_INFO1_PREAMBLE_TYPE);
575
576         switch (preamble) {
577         case HTT_RX_LEGACY:
578                 cck = info1 & RX_PPDU_START_INFO1_L_SIG_RATE_SELECT;
579                 rate = MS(info1, RX_PPDU_START_INFO1_L_SIG_RATE);
580                 rate_idx = 0;
581
582                 if (rate < 0x08 || rate > 0x0F)
583                         break;
584
585                 switch (band) {
586                 case IEEE80211_BAND_2GHZ:
587                         if (cck)
588                                 rate &= ~BIT(3);
589                         rate_idx = rx_legacy_rate_idx[rate];
590                         break;
591                 case IEEE80211_BAND_5GHZ:
592                         rate_idx = rx_legacy_rate_idx[rate];
593                         /* We are using same rate table registering
594                            HW - ath10k_rates[]. In case of 5GHz skip
595                            CCK rates, so -4 here */
596                         rate_idx -= 4;
597                         break;
598                 default:
599                         break;
600                 }
601
602                 status->rate_idx = rate_idx;
603                 break;
604         case HTT_RX_HT:
605         case HTT_RX_HT_WITH_TXBF:
606                 /* HT-SIG - Table 20-11 in info2 and info3 */
607                 mcs = info2 & 0x1F;
608                 nss = mcs >> 3;
609                 bw = (info2 >> 7) & 1;
610                 sgi = (info3 >> 7) & 1;
611
612                 status->rate_idx = mcs;
613                 status->flag |= RX_FLAG_HT;
614                 if (sgi)
615                         status->flag |= RX_FLAG_SHORT_GI;
616                 if (bw)
617                         status->flag |= RX_FLAG_40MHZ;
618                 break;
619         case HTT_RX_VHT:
620         case HTT_RX_VHT_WITH_TXBF:
621                 /* VHT-SIG-A1 in info2, VHT-SIG-A2 in info3
622                    TODO check this */
623                 mcs = (info3 >> 4) & 0x0F;
624                 nss = ((info2 >> 10) & 0x07) + 1;
625                 bw = info2 & 3;
626                 sgi = info3 & 1;
627
628                 status->rate_idx = mcs;
629                 status->vht_nss = nss;
630
631                 if (sgi)
632                         status->flag |= RX_FLAG_SHORT_GI;
633
634                 switch (bw) {
635                 /* 20MHZ */
636                 case 0:
637                         break;
638                 /* 40MHZ */
639                 case 1:
640                         status->flag |= RX_FLAG_40MHZ;
641                         break;
642                 /* 80MHZ */
643                 case 2:
644                         status->vht_flag |= RX_VHT_FLAG_80MHZ;
645                 }
646
647                 status->flag |= RX_FLAG_VHT;
648                 break;
649         default:
650                 break;
651         }
652 }
653
654 static bool ath10k_htt_rx_h_channel(struct ath10k *ar,
655                                     struct ieee80211_rx_status *status)
656 {
657         struct ieee80211_channel *ch;
658
659         spin_lock_bh(&ar->data_lock);
660         ch = ar->scan_channel;
661         if (!ch)
662                 ch = ar->rx_channel;
663         spin_unlock_bh(&ar->data_lock);
664
665         if (!ch)
666                 return false;
667
668         status->band = ch->band;
669         status->freq = ch->center_freq;
670
671         return true;
672 }
673
674 static void ath10k_htt_rx_h_signal(struct ath10k *ar,
675                                    struct ieee80211_rx_status *status,
676                                    struct htt_rx_desc *rxd)
677 {
678         /* FIXME: Get real NF */
679         status->signal = ATH10K_DEFAULT_NOISE_FLOOR +
680                          rxd->ppdu_start.rssi_comb;
681         status->flag &= ~RX_FLAG_NO_SIGNAL_VAL;
682 }
683
684 static void ath10k_htt_rx_h_mactime(struct ath10k *ar,
685                                     struct ieee80211_rx_status *status,
686                                     struct htt_rx_desc *rxd)
687 {
688         /* FIXME: TSF is known only at the end of PPDU, in the last MPDU. This
689          * means all prior MSDUs in a PPDU are reported to mac80211 without the
690          * TSF. Is it worth holding frames until end of PPDU is known?
691          *
692          * FIXME: Can we get/compute 64bit TSF?
693          */
694         status->mactime = __le32_to_cpu(rxd->ppdu_end.tsf_timestamp);
695         status->flag |= RX_FLAG_MACTIME_END;
696 }
697
698 static void ath10k_htt_rx_h_ppdu(struct ath10k *ar,
699                                  struct sk_buff_head *amsdu,
700                                  struct ieee80211_rx_status *status)
701 {
702         struct sk_buff *first;
703         struct htt_rx_desc *rxd;
704         bool is_first_ppdu;
705         bool is_last_ppdu;
706
707         if (skb_queue_empty(amsdu))
708                 return;
709
710         first = skb_peek(amsdu);
711         rxd = (void *)first->data - sizeof(*rxd);
712
713         is_first_ppdu = !!(rxd->attention.flags &
714                            __cpu_to_le32(RX_ATTENTION_FLAGS_FIRST_MPDU));
715         is_last_ppdu = !!(rxd->attention.flags &
716                           __cpu_to_le32(RX_ATTENTION_FLAGS_LAST_MPDU));
717
718         if (is_first_ppdu) {
719                 /* New PPDU starts so clear out the old per-PPDU status. */
720                 status->freq = 0;
721                 status->rate_idx = 0;
722                 status->vht_nss = 0;
723                 status->vht_flag &= ~RX_VHT_FLAG_80MHZ;
724                 status->flag &= ~(RX_FLAG_HT |
725                                   RX_FLAG_VHT |
726                                   RX_FLAG_SHORT_GI |
727                                   RX_FLAG_40MHZ |
728                                   RX_FLAG_MACTIME_END);
729                 status->flag |= RX_FLAG_NO_SIGNAL_VAL;
730
731                 ath10k_htt_rx_h_signal(ar, status, rxd);
732                 ath10k_htt_rx_h_channel(ar, status);
733                 ath10k_htt_rx_h_rates(ar, status, rxd);
734         }
735
736         if (is_last_ppdu)
737                 ath10k_htt_rx_h_mactime(ar, status, rxd);
738 }
739
740 static const char * const tid_to_ac[] = {
741         "BE",
742         "BK",
743         "BK",
744         "BE",
745         "VI",
746         "VI",
747         "VO",
748         "VO",
749 };
750
751 static char *ath10k_get_tid(struct ieee80211_hdr *hdr, char *out, size_t size)
752 {
753         u8 *qc;
754         int tid;
755
756         if (!ieee80211_is_data_qos(hdr->frame_control))
757                 return "";
758
759         qc = ieee80211_get_qos_ctl(hdr);
760         tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
761         if (tid < 8)
762                 snprintf(out, size, "tid %d (%s)", tid, tid_to_ac[tid]);
763         else
764                 snprintf(out, size, "tid %d", tid);
765
766         return out;
767 }
768
769 static void ath10k_process_rx(struct ath10k *ar,
770                               struct ieee80211_rx_status *rx_status,
771                               struct sk_buff *skb)
772 {
773         struct ieee80211_rx_status *status;
774         struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
775         char tid[32];
776
777         status = IEEE80211_SKB_RXCB(skb);
778         *status = *rx_status;
779
780         ath10k_dbg(ar, ATH10K_DBG_DATA,
781                    "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",
782                    skb,
783                    skb->len,
784                    ieee80211_get_SA(hdr),
785                    ath10k_get_tid(hdr, tid, sizeof(tid)),
786                    is_multicast_ether_addr(ieee80211_get_DA(hdr)) ?
787                                                         "mcast" : "ucast",
788                    (__le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_SEQ) >> 4,
789                    status->flag == 0 ? "legacy" : "",
790                    status->flag & RX_FLAG_HT ? "ht" : "",
791                    status->flag & RX_FLAG_VHT ? "vht" : "",
792                    status->flag & RX_FLAG_40MHZ ? "40" : "",
793                    status->vht_flag & RX_VHT_FLAG_80MHZ ? "80" : "",
794                    status->flag & RX_FLAG_SHORT_GI ? "sgi " : "",
795                    status->rate_idx,
796                    status->vht_nss,
797                    status->freq,
798                    status->band, status->flag,
799                    !!(status->flag & RX_FLAG_FAILED_FCS_CRC),
800                    !!(status->flag & RX_FLAG_MMIC_ERROR),
801                    !!(status->flag & RX_FLAG_AMSDU_MORE));
802         ath10k_dbg_dump(ar, ATH10K_DBG_HTT_DUMP, NULL, "rx skb: ",
803                         skb->data, skb->len);
804         trace_ath10k_rx_hdr(ar, skb->data, skb->len);
805         trace_ath10k_rx_payload(ar, skb->data, skb->len);
806
807         ieee80211_rx(ar->hw, skb);
808 }
809
810 static int ath10k_htt_rx_nwifi_hdrlen(struct ieee80211_hdr *hdr)
811 {
812         /* nwifi header is padded to 4 bytes. this fixes 4addr rx */
813         return round_up(ieee80211_hdrlen(hdr->frame_control), 4);
814 }
815
816 static void ath10k_htt_rx_h_undecap_raw(struct ath10k *ar,
817                                         struct sk_buff *msdu,
818                                         struct ieee80211_rx_status *status,
819                                         enum htt_rx_mpdu_encrypt_type enctype,
820                                         bool is_decrypted)
821 {
822         struct ieee80211_hdr *hdr;
823         struct htt_rx_desc *rxd;
824         size_t hdr_len;
825         size_t crypto_len;
826         bool is_first;
827         bool is_last;
828
829         rxd = (void *)msdu->data - sizeof(*rxd);
830         is_first = !!(rxd->msdu_end.info0 &
831                       __cpu_to_le32(RX_MSDU_END_INFO0_FIRST_MSDU));
832         is_last = !!(rxd->msdu_end.info0 &
833                      __cpu_to_le32(RX_MSDU_END_INFO0_LAST_MSDU));
834
835         /* Delivered decapped frame:
836          * [802.11 header]
837          * [crypto param] <-- can be trimmed if !fcs_err &&
838          *                    !decrypt_err && !peer_idx_invalid
839          * [amsdu header] <-- only if A-MSDU
840          * [rfc1042/llc]
841          * [payload]
842          * [FCS] <-- at end, needs to be trimmed
843          */
844
845         /* This probably shouldn't happen but warn just in case */
846         if (unlikely(WARN_ON_ONCE(!is_first)))
847                 return;
848
849         /* This probably shouldn't happen but warn just in case */
850         if (unlikely(WARN_ON_ONCE(!(is_first && is_last))))
851                 return;
852
853         skb_trim(msdu, msdu->len - FCS_LEN);
854
855         /* In most cases this will be true for sniffed frames. It makes sense
856          * to deliver them as-is without stripping the crypto param. This would
857          * also make sense for software based decryption (which is not
858          * implemented in ath10k).
859          *
860          * If there's no error then the frame is decrypted. At least that is
861          * the case for frames that come in via fragmented rx indication.
862          */
863         if (!is_decrypted)
864                 return;
865
866         /* The payload is decrypted so strip crypto params. Start from tail
867          * since hdr is used to compute some stuff.
868          */
869
870         hdr = (void *)msdu->data;
871
872         /* Tail */
873         skb_trim(msdu, msdu->len - ath10k_htt_rx_crypto_tail_len(ar, enctype));
874
875         /* MMIC */
876         if (!ieee80211_has_morefrags(hdr->frame_control) &&
877             enctype == HTT_RX_MPDU_ENCRYPT_TKIP_WPA)
878                 skb_trim(msdu, msdu->len - 8);
879
880         /* Head */
881         hdr_len = ieee80211_hdrlen(hdr->frame_control);
882         crypto_len = ath10k_htt_rx_crypto_param_len(ar, enctype);
883
884         memmove((void *)msdu->data + crypto_len,
885                 (void *)msdu->data, hdr_len);
886         skb_pull(msdu, crypto_len);
887 }
888
889 static void ath10k_htt_rx_h_undecap_nwifi(struct ath10k *ar,
890                                           struct sk_buff *msdu,
891                                           struct ieee80211_rx_status *status,
892                                           const u8 first_hdr[64])
893 {
894         struct ieee80211_hdr *hdr;
895         size_t hdr_len;
896         u8 da[ETH_ALEN];
897         u8 sa[ETH_ALEN];
898
899         /* Delivered decapped frame:
900          * [nwifi 802.11 header] <-- replaced with 802.11 hdr
901          * [rfc1042/llc]
902          *
903          * Note: The nwifi header doesn't have QoS Control and is
904          * (always?) a 3addr frame.
905          *
906          * Note2: There's no A-MSDU subframe header. Even if it's part
907          * of an A-MSDU.
908          */
909
910         /* pull decapped header and copy SA & DA */
911         hdr = (struct ieee80211_hdr *)msdu->data;
912         hdr_len = ath10k_htt_rx_nwifi_hdrlen(hdr);
913         ether_addr_copy(da, ieee80211_get_DA(hdr));
914         ether_addr_copy(sa, ieee80211_get_SA(hdr));
915         skb_pull(msdu, hdr_len);
916
917         /* push original 802.11 header */
918         hdr = (struct ieee80211_hdr *)first_hdr;
919         hdr_len = ieee80211_hdrlen(hdr->frame_control);
920         memcpy(skb_push(msdu, hdr_len), hdr, hdr_len);
921
922         /* original 802.11 header has a different DA and in
923          * case of 4addr it may also have different SA
924          */
925         hdr = (struct ieee80211_hdr *)msdu->data;
926         ether_addr_copy(ieee80211_get_DA(hdr), da);
927         ether_addr_copy(ieee80211_get_SA(hdr), sa);
928 }
929
930 static void *ath10k_htt_rx_h_find_rfc1042(struct ath10k *ar,
931                                           struct sk_buff *msdu,
932                                           enum htt_rx_mpdu_encrypt_type enctype)
933 {
934         struct ieee80211_hdr *hdr;
935         struct htt_rx_desc *rxd;
936         size_t hdr_len, crypto_len;
937         void *rfc1042;
938         bool is_first, is_last, is_amsdu;
939
940         rxd = (void *)msdu->data - sizeof(*rxd);
941         hdr = (void *)rxd->rx_hdr_status;
942
943         is_first = !!(rxd->msdu_end.info0 &
944                       __cpu_to_le32(RX_MSDU_END_INFO0_FIRST_MSDU));
945         is_last = !!(rxd->msdu_end.info0 &
946                      __cpu_to_le32(RX_MSDU_END_INFO0_LAST_MSDU));
947         is_amsdu = !(is_first && is_last);
948
949         rfc1042 = hdr;
950
951         if (is_first) {
952                 hdr_len = ieee80211_hdrlen(hdr->frame_control);
953                 crypto_len = ath10k_htt_rx_crypto_param_len(ar, enctype);
954
955                 rfc1042 += round_up(hdr_len, 4) +
956                            round_up(crypto_len, 4);
957         }
958
959         if (is_amsdu)
960                 rfc1042 += sizeof(struct amsdu_subframe_hdr);
961
962         return rfc1042;
963 }
964
965 static void ath10k_htt_rx_h_undecap_eth(struct ath10k *ar,
966                                         struct sk_buff *msdu,
967                                         struct ieee80211_rx_status *status,
968                                         const u8 first_hdr[64],
969                                         enum htt_rx_mpdu_encrypt_type enctype)
970 {
971         struct ieee80211_hdr *hdr;
972         struct ethhdr *eth;
973         size_t hdr_len;
974         void *rfc1042;
975         u8 da[ETH_ALEN];
976         u8 sa[ETH_ALEN];
977
978         /* Delivered decapped frame:
979          * [eth header] <-- replaced with 802.11 hdr & rfc1042/llc
980          * [payload]
981          */
982
983         rfc1042 = ath10k_htt_rx_h_find_rfc1042(ar, msdu, enctype);
984         if (WARN_ON_ONCE(!rfc1042))
985                 return;
986
987         /* pull decapped header and copy SA & DA */
988         eth = (struct ethhdr *)msdu->data;
989         ether_addr_copy(da, eth->h_dest);
990         ether_addr_copy(sa, eth->h_source);
991         skb_pull(msdu, sizeof(struct ethhdr));
992
993         /* push rfc1042/llc/snap */
994         memcpy(skb_push(msdu, sizeof(struct rfc1042_hdr)), rfc1042,
995                sizeof(struct rfc1042_hdr));
996
997         /* push original 802.11 header */
998         hdr = (struct ieee80211_hdr *)first_hdr;
999         hdr_len = ieee80211_hdrlen(hdr->frame_control);
1000         memcpy(skb_push(msdu, hdr_len), hdr, hdr_len);
1001
1002         /* original 802.11 header has a different DA and in
1003          * case of 4addr it may also have different SA
1004          */
1005         hdr = (struct ieee80211_hdr *)msdu->data;
1006         ether_addr_copy(ieee80211_get_DA(hdr), da);
1007         ether_addr_copy(ieee80211_get_SA(hdr), sa);
1008 }
1009
1010 static void ath10k_htt_rx_h_undecap_snap(struct ath10k *ar,
1011                                          struct sk_buff *msdu,
1012                                          struct ieee80211_rx_status *status,
1013                                          const u8 first_hdr[64])
1014 {
1015         struct ieee80211_hdr *hdr;
1016         size_t hdr_len;
1017
1018         /* Delivered decapped frame:
1019          * [amsdu header] <-- replaced with 802.11 hdr
1020          * [rfc1042/llc]
1021          * [payload]
1022          */
1023
1024         skb_pull(msdu, sizeof(struct amsdu_subframe_hdr));
1025
1026         hdr = (struct ieee80211_hdr *)first_hdr;
1027         hdr_len = ieee80211_hdrlen(hdr->frame_control);
1028         memcpy(skb_push(msdu, hdr_len), hdr, hdr_len);
1029 }
1030
1031 static void ath10k_htt_rx_h_undecap(struct ath10k *ar,
1032                                     struct sk_buff *msdu,
1033                                     struct ieee80211_rx_status *status,
1034                                     u8 first_hdr[64],
1035                                     enum htt_rx_mpdu_encrypt_type enctype,
1036                                     bool is_decrypted)
1037 {
1038         struct htt_rx_desc *rxd;
1039         enum rx_msdu_decap_format decap;
1040         struct ieee80211_hdr *hdr;
1041
1042         /* First msdu's decapped header:
1043          * [802.11 header] <-- padded to 4 bytes long
1044          * [crypto param] <-- padded to 4 bytes long
1045          * [amsdu header] <-- only if A-MSDU
1046          * [rfc1042/llc]
1047          *
1048          * Other (2nd, 3rd, ..) msdu's decapped header:
1049          * [amsdu header] <-- only if A-MSDU
1050          * [rfc1042/llc]
1051          */
1052
1053         rxd = (void *)msdu->data - sizeof(*rxd);
1054         hdr = (void *)rxd->rx_hdr_status;
1055         decap = MS(__le32_to_cpu(rxd->msdu_start.info1),
1056                    RX_MSDU_START_INFO1_DECAP_FORMAT);
1057
1058         switch (decap) {
1059         case RX_MSDU_DECAP_RAW:
1060                 ath10k_htt_rx_h_undecap_raw(ar, msdu, status, enctype,
1061                                             is_decrypted);
1062                 break;
1063         case RX_MSDU_DECAP_NATIVE_WIFI:
1064                 ath10k_htt_rx_h_undecap_nwifi(ar, msdu, status, first_hdr);
1065                 break;
1066         case RX_MSDU_DECAP_ETHERNET2_DIX:
1067                 ath10k_htt_rx_h_undecap_eth(ar, msdu, status, first_hdr, enctype);
1068                 break;
1069         case RX_MSDU_DECAP_8023_SNAP_LLC:
1070                 ath10k_htt_rx_h_undecap_snap(ar, msdu, status, first_hdr);
1071                 break;
1072         }
1073 }
1074
1075 static int ath10k_htt_rx_get_csum_state(struct sk_buff *skb)
1076 {
1077         struct htt_rx_desc *rxd;
1078         u32 flags, info;
1079         bool is_ip4, is_ip6;
1080         bool is_tcp, is_udp;
1081         bool ip_csum_ok, tcpudp_csum_ok;
1082
1083         rxd = (void *)skb->data - sizeof(*rxd);
1084         flags = __le32_to_cpu(rxd->attention.flags);
1085         info = __le32_to_cpu(rxd->msdu_start.info1);
1086
1087         is_ip4 = !!(info & RX_MSDU_START_INFO1_IPV4_PROTO);
1088         is_ip6 = !!(info & RX_MSDU_START_INFO1_IPV6_PROTO);
1089         is_tcp = !!(info & RX_MSDU_START_INFO1_TCP_PROTO);
1090         is_udp = !!(info & RX_MSDU_START_INFO1_UDP_PROTO);
1091         ip_csum_ok = !(flags & RX_ATTENTION_FLAGS_IP_CHKSUM_FAIL);
1092         tcpudp_csum_ok = !(flags & RX_ATTENTION_FLAGS_TCP_UDP_CHKSUM_FAIL);
1093
1094         if (!is_ip4 && !is_ip6)
1095                 return CHECKSUM_NONE;
1096         if (!is_tcp && !is_udp)
1097                 return CHECKSUM_NONE;
1098         if (!ip_csum_ok)
1099                 return CHECKSUM_NONE;
1100         if (!tcpudp_csum_ok)
1101                 return CHECKSUM_NONE;
1102
1103         return CHECKSUM_UNNECESSARY;
1104 }
1105
1106 static void ath10k_htt_rx_h_csum_offload(struct sk_buff *msdu)
1107 {
1108         msdu->ip_summed = ath10k_htt_rx_get_csum_state(msdu);
1109 }
1110
1111 static void ath10k_htt_rx_h_mpdu(struct ath10k *ar,
1112                                  struct sk_buff_head *amsdu,
1113                                  struct ieee80211_rx_status *status)
1114 {
1115         struct sk_buff *first;
1116         struct sk_buff *last;
1117         struct sk_buff *msdu;
1118         struct htt_rx_desc *rxd;
1119         struct ieee80211_hdr *hdr;
1120         enum htt_rx_mpdu_encrypt_type enctype;
1121         u8 first_hdr[64];
1122         u8 *qos;
1123         size_t hdr_len;
1124         bool has_fcs_err;
1125         bool has_crypto_err;
1126         bool has_tkip_err;
1127         bool has_peer_idx_invalid;
1128         bool is_decrypted;
1129         u32 attention;
1130
1131         if (skb_queue_empty(amsdu))
1132                 return;
1133
1134         first = skb_peek(amsdu);
1135         rxd = (void *)first->data - sizeof(*rxd);
1136
1137         enctype = MS(__le32_to_cpu(rxd->mpdu_start.info0),
1138                      RX_MPDU_START_INFO0_ENCRYPT_TYPE);
1139
1140         /* First MSDU's Rx descriptor in an A-MSDU contains full 802.11
1141          * decapped header. It'll be used for undecapping of each MSDU.
1142          */
1143         hdr = (void *)rxd->rx_hdr_status;
1144         hdr_len = ieee80211_hdrlen(hdr->frame_control);
1145         memcpy(first_hdr, hdr, hdr_len);
1146
1147         /* Each A-MSDU subframe will use the original header as the base and be
1148          * reported as a separate MSDU so strip the A-MSDU bit from QoS Ctl.
1149          */
1150         hdr = (void *)first_hdr;
1151         qos = ieee80211_get_qos_ctl(hdr);
1152         qos[0] &= ~IEEE80211_QOS_CTL_A_MSDU_PRESENT;
1153
1154         /* Some attention flags are valid only in the last MSDU. */
1155         last = skb_peek_tail(amsdu);
1156         rxd = (void *)last->data - sizeof(*rxd);
1157         attention = __le32_to_cpu(rxd->attention.flags);
1158
1159         has_fcs_err = !!(attention & RX_ATTENTION_FLAGS_FCS_ERR);
1160         has_crypto_err = !!(attention & RX_ATTENTION_FLAGS_DECRYPT_ERR);
1161         has_tkip_err = !!(attention & RX_ATTENTION_FLAGS_TKIP_MIC_ERR);
1162         has_peer_idx_invalid = !!(attention & RX_ATTENTION_FLAGS_PEER_IDX_INVALID);
1163
1164         /* Note: If hardware captures an encrypted frame that it can't decrypt,
1165          * e.g. due to fcs error, missing peer or invalid key data it will
1166          * report the frame as raw.
1167          */
1168         is_decrypted = (enctype != HTT_RX_MPDU_ENCRYPT_NONE &&
1169                         !has_fcs_err &&
1170                         !has_crypto_err &&
1171                         !has_peer_idx_invalid);
1172
1173         /* Clear per-MPDU flags while leaving per-PPDU flags intact. */
1174         status->flag &= ~(RX_FLAG_FAILED_FCS_CRC |
1175                           RX_FLAG_MMIC_ERROR |
1176                           RX_FLAG_DECRYPTED |
1177                           RX_FLAG_IV_STRIPPED |
1178                           RX_FLAG_MMIC_STRIPPED);
1179
1180         if (has_fcs_err)
1181                 status->flag |= RX_FLAG_FAILED_FCS_CRC;
1182
1183         if (has_tkip_err)
1184                 status->flag |= RX_FLAG_MMIC_ERROR;
1185
1186         if (is_decrypted)
1187                 status->flag |= RX_FLAG_DECRYPTED |
1188                                 RX_FLAG_IV_STRIPPED |
1189                                 RX_FLAG_MMIC_STRIPPED;
1190
1191         skb_queue_walk(amsdu, msdu) {
1192                 ath10k_htt_rx_h_csum_offload(msdu);
1193                 ath10k_htt_rx_h_undecap(ar, msdu, status, first_hdr, enctype,
1194                                         is_decrypted);
1195
1196                 /* Undecapping involves copying the original 802.11 header back
1197                  * to sk_buff. If frame is protected and hardware has decrypted
1198                  * it then remove the protected bit.
1199                  */
1200                 if (!is_decrypted)
1201                         continue;
1202
1203                 hdr = (void *)msdu->data;
1204                 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_FCTL_PROTECTED);
1205         }
1206 }
1207
1208 static void ath10k_htt_rx_h_deliver(struct ath10k *ar,
1209                                     struct sk_buff_head *amsdu,
1210                                     struct ieee80211_rx_status *status)
1211 {
1212         struct sk_buff *msdu;
1213
1214         while ((msdu = __skb_dequeue(amsdu))) {
1215                 /* Setup per-MSDU flags */
1216                 if (skb_queue_empty(amsdu))
1217                         status->flag &= ~RX_FLAG_AMSDU_MORE;
1218                 else
1219                         status->flag |= RX_FLAG_AMSDU_MORE;
1220
1221                 ath10k_process_rx(ar, status, msdu);
1222         }
1223 }
1224
1225 static int ath10k_unchain_msdu(struct sk_buff_head *amsdu)
1226 {
1227         struct sk_buff *skb, *first;
1228         int space;
1229         int total_len = 0;
1230
1231         /* TODO:  Might could optimize this by using
1232          * skb_try_coalesce or similar method to
1233          * decrease copying, or maybe get mac80211 to
1234          * provide a way to just receive a list of
1235          * skb?
1236          */
1237
1238         first = __skb_dequeue(amsdu);
1239
1240         /* Allocate total length all at once. */
1241         skb_queue_walk(amsdu, skb)
1242                 total_len += skb->len;
1243
1244         space = total_len - skb_tailroom(first);
1245         if ((space > 0) &&
1246             (pskb_expand_head(first, 0, space, GFP_ATOMIC) < 0)) {
1247                 /* TODO:  bump some rx-oom error stat */
1248                 /* put it back together so we can free the
1249                  * whole list at once.
1250                  */
1251                 __skb_queue_head(amsdu, first);
1252                 return -1;
1253         }
1254
1255         /* Walk list again, copying contents into
1256          * msdu_head
1257          */
1258         while ((skb = __skb_dequeue(amsdu))) {
1259                 skb_copy_from_linear_data(skb, skb_put(first, skb->len),
1260                                           skb->len);
1261                 dev_kfree_skb_any(skb);
1262         }
1263
1264         __skb_queue_head(amsdu, first);
1265         return 0;
1266 }
1267
1268 static void ath10k_htt_rx_h_unchain(struct ath10k *ar,
1269                                     struct sk_buff_head *amsdu,
1270                                     bool chained)
1271 {
1272         struct sk_buff *first;
1273         struct htt_rx_desc *rxd;
1274         enum rx_msdu_decap_format decap;
1275
1276         first = skb_peek(amsdu);
1277         rxd = (void *)first->data - sizeof(*rxd);
1278         decap = MS(__le32_to_cpu(rxd->msdu_start.info1),
1279                    RX_MSDU_START_INFO1_DECAP_FORMAT);
1280
1281         if (!chained)
1282                 return;
1283
1284         /* FIXME: Current unchaining logic can only handle simple case of raw
1285          * msdu chaining. If decapping is other than raw the chaining may be
1286          * more complex and this isn't handled by the current code. Don't even
1287          * try re-constructing such frames - it'll be pretty much garbage.
1288          */
1289         if (decap != RX_MSDU_DECAP_RAW ||
1290             skb_queue_len(amsdu) != 1 + rxd->frag_info.ring2_more_count) {
1291                 __skb_queue_purge(amsdu);
1292                 return;
1293         }
1294
1295         ath10k_unchain_msdu(amsdu);
1296 }
1297
1298 static bool ath10k_htt_rx_amsdu_allowed(struct ath10k *ar,
1299                                         struct sk_buff_head *amsdu,
1300                                         struct ieee80211_rx_status *rx_status)
1301 {
1302         struct sk_buff *msdu;
1303         struct htt_rx_desc *rxd;
1304         bool is_mgmt;
1305         bool has_fcs_err;
1306
1307         msdu = skb_peek(amsdu);
1308         rxd = (void *)msdu->data - sizeof(*rxd);
1309
1310         /* FIXME: It might be a good idea to do some fuzzy-testing to drop
1311          * invalid/dangerous frames.
1312          */
1313
1314         if (!rx_status->freq) {
1315                 ath10k_warn(ar, "no channel configured; ignoring frame(s)!\n");
1316                 return false;
1317         }
1318
1319         is_mgmt = !!(rxd->attention.flags &
1320                      __cpu_to_le32(RX_ATTENTION_FLAGS_MGMT_TYPE));
1321         has_fcs_err = !!(rxd->attention.flags &
1322                          __cpu_to_le32(RX_ATTENTION_FLAGS_FCS_ERR));
1323
1324         /* Management frames are handled via WMI events. The pros of such
1325          * approach is that channel is explicitly provided in WMI events
1326          * whereas HTT doesn't provide channel information for Rxed frames.
1327          *
1328          * However some firmware revisions don't report corrupted frames via
1329          * WMI so don't drop them.
1330          */
1331         if (is_mgmt && !has_fcs_err) {
1332                 ath10k_dbg(ar, ATH10K_DBG_HTT, "htt rx mgmt ctrl\n");
1333                 return false;
1334         }
1335
1336         if (test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags)) {
1337                 ath10k_dbg(ar, ATH10K_DBG_HTT, "htt rx cac running\n");
1338                 return false;
1339         }
1340
1341         return true;
1342 }
1343
1344 static void ath10k_htt_rx_h_filter(struct ath10k *ar,
1345                                    struct sk_buff_head *amsdu,
1346                                    struct ieee80211_rx_status *rx_status)
1347 {
1348         if (skb_queue_empty(amsdu))
1349                 return;
1350
1351         if (ath10k_htt_rx_amsdu_allowed(ar, amsdu, rx_status))
1352                 return;
1353
1354         __skb_queue_purge(amsdu);
1355 }
1356
1357 static void ath10k_htt_rx_handler(struct ath10k_htt *htt,
1358                                   struct htt_rx_indication *rx)
1359 {
1360         struct ath10k *ar = htt->ar;
1361         struct ieee80211_rx_status *rx_status = &htt->rx_status;
1362         struct htt_rx_indication_mpdu_range *mpdu_ranges;
1363         struct sk_buff_head amsdu;
1364         int num_mpdu_ranges;
1365         int fw_desc_len;
1366         u8 *fw_desc;
1367         int i, ret, mpdu_count = 0;
1368
1369         lockdep_assert_held(&htt->rx_ring.lock);
1370
1371         if (htt->rx_confused)
1372                 return;
1373
1374         fw_desc_len = __le16_to_cpu(rx->prefix.fw_rx_desc_bytes);
1375         fw_desc = (u8 *)&rx->fw_desc;
1376
1377         num_mpdu_ranges = MS(__le32_to_cpu(rx->hdr.info1),
1378                              HTT_RX_INDICATION_INFO1_NUM_MPDU_RANGES);
1379         mpdu_ranges = htt_rx_ind_get_mpdu_ranges(rx);
1380
1381         ath10k_dbg_dump(ar, ATH10K_DBG_HTT_DUMP, NULL, "htt rx ind: ",
1382                         rx, sizeof(*rx) +
1383                         (sizeof(struct htt_rx_indication_mpdu_range) *
1384                                 num_mpdu_ranges));
1385
1386         for (i = 0; i < num_mpdu_ranges; i++)
1387                 mpdu_count += mpdu_ranges[i].mpdu_count;
1388
1389         while (mpdu_count--) {
1390                 __skb_queue_head_init(&amsdu);
1391                 ret = ath10k_htt_rx_amsdu_pop(htt, &fw_desc,
1392                                               &fw_desc_len, &amsdu);
1393                 if (ret < 0) {
1394                         ath10k_warn(ar, "rx ring became corrupted: %d\n", ret);
1395                         __skb_queue_purge(&amsdu);
1396                         /* FIXME: It's probably a good idea to reboot the
1397                          * device instead of leaving it inoperable.
1398                          */
1399                         htt->rx_confused = true;
1400                         break;
1401                 }
1402
1403                 ath10k_htt_rx_h_ppdu(ar, &amsdu, rx_status);
1404                 ath10k_htt_rx_h_unchain(ar, &amsdu, ret > 0);
1405                 ath10k_htt_rx_h_filter(ar, &amsdu, rx_status);
1406                 ath10k_htt_rx_h_mpdu(ar, &amsdu, rx_status);
1407                 ath10k_htt_rx_h_deliver(ar, &amsdu, rx_status);
1408         }
1409
1410         tasklet_schedule(&htt->rx_replenish_task);
1411 }
1412
1413 static void ath10k_htt_rx_frag_handler(struct ath10k_htt *htt,
1414                                        struct htt_rx_fragment_indication *frag)
1415 {
1416         struct ath10k *ar = htt->ar;
1417         struct ieee80211_rx_status *rx_status = &htt->rx_status;
1418         struct sk_buff_head amsdu;
1419         int ret;
1420         u8 *fw_desc;
1421         int fw_desc_len;
1422
1423         fw_desc_len = __le16_to_cpu(frag->fw_rx_desc_bytes);
1424         fw_desc = (u8 *)frag->fw_msdu_rx_desc;
1425
1426         __skb_queue_head_init(&amsdu);
1427
1428         spin_lock_bh(&htt->rx_ring.lock);
1429         ret = ath10k_htt_rx_amsdu_pop(htt, &fw_desc, &fw_desc_len,
1430                                       &amsdu);
1431         spin_unlock_bh(&htt->rx_ring.lock);
1432
1433         tasklet_schedule(&htt->rx_replenish_task);
1434
1435         ath10k_dbg(ar, ATH10K_DBG_HTT_DUMP, "htt rx frag ahead\n");
1436
1437         if (ret) {
1438                 ath10k_warn(ar, "failed to pop amsdu from httr rx ring for fragmented rx %d\n",
1439                             ret);
1440                 __skb_queue_purge(&amsdu);
1441                 return;
1442         }
1443
1444         if (skb_queue_len(&amsdu) != 1) {
1445                 ath10k_warn(ar, "failed to pop frag amsdu: too many msdus\n");
1446                 __skb_queue_purge(&amsdu);
1447                 return;
1448         }
1449
1450         ath10k_htt_rx_h_ppdu(ar, &amsdu, rx_status);
1451         ath10k_htt_rx_h_filter(ar, &amsdu, rx_status);
1452         ath10k_htt_rx_h_mpdu(ar, &amsdu, rx_status);
1453         ath10k_htt_rx_h_deliver(ar, &amsdu, rx_status);
1454
1455         if (fw_desc_len > 0) {
1456                 ath10k_dbg(ar, ATH10K_DBG_HTT,
1457                            "expecting more fragmented rx in one indication %d\n",
1458                            fw_desc_len);
1459         }
1460 }
1461
1462 static void ath10k_htt_rx_frm_tx_compl(struct ath10k *ar,
1463                                        struct sk_buff *skb)
1464 {
1465         struct ath10k_htt *htt = &ar->htt;
1466         struct htt_resp *resp = (struct htt_resp *)skb->data;
1467         struct htt_tx_done tx_done = {};
1468         int status = MS(resp->data_tx_completion.flags, HTT_DATA_TX_STATUS);
1469         __le16 msdu_id;
1470         int i;
1471
1472         lockdep_assert_held(&htt->tx_lock);
1473
1474         switch (status) {
1475         case HTT_DATA_TX_STATUS_NO_ACK:
1476                 tx_done.no_ack = true;
1477                 break;
1478         case HTT_DATA_TX_STATUS_OK:
1479                 break;
1480         case HTT_DATA_TX_STATUS_DISCARD:
1481         case HTT_DATA_TX_STATUS_POSTPONE:
1482         case HTT_DATA_TX_STATUS_DOWNLOAD_FAIL:
1483                 tx_done.discard = true;
1484                 break;
1485         default:
1486                 ath10k_warn(ar, "unhandled tx completion status %d\n", status);
1487                 tx_done.discard = true;
1488                 break;
1489         }
1490
1491         ath10k_dbg(ar, ATH10K_DBG_HTT, "htt tx completion num_msdus %d\n",
1492                    resp->data_tx_completion.num_msdus);
1493
1494         for (i = 0; i < resp->data_tx_completion.num_msdus; i++) {
1495                 msdu_id = resp->data_tx_completion.msdus[i];
1496                 tx_done.msdu_id = __le16_to_cpu(msdu_id);
1497                 ath10k_txrx_tx_unref(htt, &tx_done);
1498         }
1499 }
1500
1501 static void ath10k_htt_rx_addba(struct ath10k *ar, struct htt_resp *resp)
1502 {
1503         struct htt_rx_addba *ev = &resp->rx_addba;
1504         struct ath10k_peer *peer;
1505         struct ath10k_vif *arvif;
1506         u16 info0, tid, peer_id;
1507
1508         info0 = __le16_to_cpu(ev->info0);
1509         tid = MS(info0, HTT_RX_BA_INFO0_TID);
1510         peer_id = MS(info0, HTT_RX_BA_INFO0_PEER_ID);
1511
1512         ath10k_dbg(ar, ATH10K_DBG_HTT,
1513                    "htt rx addba tid %hu peer_id %hu size %hhu\n",
1514                    tid, peer_id, ev->window_size);
1515
1516         spin_lock_bh(&ar->data_lock);
1517         peer = ath10k_peer_find_by_id(ar, peer_id);
1518         if (!peer) {
1519                 ath10k_warn(ar, "received addba event for invalid peer_id: %hu\n",
1520                             peer_id);
1521                 spin_unlock_bh(&ar->data_lock);
1522                 return;
1523         }
1524
1525         arvif = ath10k_get_arvif(ar, peer->vdev_id);
1526         if (!arvif) {
1527                 ath10k_warn(ar, "received addba event for invalid vdev_id: %u\n",
1528                             peer->vdev_id);
1529                 spin_unlock_bh(&ar->data_lock);
1530                 return;
1531         }
1532
1533         ath10k_dbg(ar, ATH10K_DBG_HTT,
1534                    "htt rx start rx ba session sta %pM tid %hu size %hhu\n",
1535                    peer->addr, tid, ev->window_size);
1536
1537         ieee80211_start_rx_ba_session_offl(arvif->vif, peer->addr, tid);
1538         spin_unlock_bh(&ar->data_lock);
1539 }
1540
1541 static void ath10k_htt_rx_delba(struct ath10k *ar, struct htt_resp *resp)
1542 {
1543         struct htt_rx_delba *ev = &resp->rx_delba;
1544         struct ath10k_peer *peer;
1545         struct ath10k_vif *arvif;
1546         u16 info0, tid, peer_id;
1547
1548         info0 = __le16_to_cpu(ev->info0);
1549         tid = MS(info0, HTT_RX_BA_INFO0_TID);
1550         peer_id = MS(info0, HTT_RX_BA_INFO0_PEER_ID);
1551
1552         ath10k_dbg(ar, ATH10K_DBG_HTT,
1553                    "htt rx delba tid %hu peer_id %hu\n",
1554                    tid, peer_id);
1555
1556         spin_lock_bh(&ar->data_lock);
1557         peer = ath10k_peer_find_by_id(ar, peer_id);
1558         if (!peer) {
1559                 ath10k_warn(ar, "received addba event for invalid peer_id: %hu\n",
1560                             peer_id);
1561                 spin_unlock_bh(&ar->data_lock);
1562                 return;
1563         }
1564
1565         arvif = ath10k_get_arvif(ar, peer->vdev_id);
1566         if (!arvif) {
1567                 ath10k_warn(ar, "received addba event for invalid vdev_id: %u\n",
1568                             peer->vdev_id);
1569                 spin_unlock_bh(&ar->data_lock);
1570                 return;
1571         }
1572
1573         ath10k_dbg(ar, ATH10K_DBG_HTT,
1574                    "htt rx stop rx ba session sta %pM tid %hu\n",
1575                    peer->addr, tid);
1576
1577         ieee80211_stop_rx_ba_session_offl(arvif->vif, peer->addr, tid);
1578         spin_unlock_bh(&ar->data_lock);
1579 }
1580
1581 void ath10k_htt_t2h_msg_handler(struct ath10k *ar, struct sk_buff *skb)
1582 {
1583         struct ath10k_htt *htt = &ar->htt;
1584         struct htt_resp *resp = (struct htt_resp *)skb->data;
1585
1586         /* confirm alignment */
1587         if (!IS_ALIGNED((unsigned long)skb->data, 4))
1588                 ath10k_warn(ar, "unaligned htt message, expect trouble\n");
1589
1590         ath10k_dbg(ar, ATH10K_DBG_HTT, "htt rx, msg_type: 0x%0X\n",
1591                    resp->hdr.msg_type);
1592         switch (resp->hdr.msg_type) {
1593         case HTT_T2H_MSG_TYPE_VERSION_CONF: {
1594                 htt->target_version_major = resp->ver_resp.major;
1595                 htt->target_version_minor = resp->ver_resp.minor;
1596                 complete(&htt->target_version_received);
1597                 break;
1598         }
1599         case HTT_T2H_MSG_TYPE_RX_IND:
1600                 spin_lock_bh(&htt->rx_ring.lock);
1601                 __skb_queue_tail(&htt->rx_compl_q, skb);
1602                 spin_unlock_bh(&htt->rx_ring.lock);
1603                 tasklet_schedule(&htt->txrx_compl_task);
1604                 return;
1605         case HTT_T2H_MSG_TYPE_PEER_MAP: {
1606                 struct htt_peer_map_event ev = {
1607                         .vdev_id = resp->peer_map.vdev_id,
1608                         .peer_id = __le16_to_cpu(resp->peer_map.peer_id),
1609                 };
1610                 memcpy(ev.addr, resp->peer_map.addr, sizeof(ev.addr));
1611                 ath10k_peer_map_event(htt, &ev);
1612                 break;
1613         }
1614         case HTT_T2H_MSG_TYPE_PEER_UNMAP: {
1615                 struct htt_peer_unmap_event ev = {
1616                         .peer_id = __le16_to_cpu(resp->peer_unmap.peer_id),
1617                 };
1618                 ath10k_peer_unmap_event(htt, &ev);
1619                 break;
1620         }
1621         case HTT_T2H_MSG_TYPE_MGMT_TX_COMPLETION: {
1622                 struct htt_tx_done tx_done = {};
1623                 int status = __le32_to_cpu(resp->mgmt_tx_completion.status);
1624
1625                 tx_done.msdu_id =
1626                         __le32_to_cpu(resp->mgmt_tx_completion.desc_id);
1627
1628                 switch (status) {
1629                 case HTT_MGMT_TX_STATUS_OK:
1630                         break;
1631                 case HTT_MGMT_TX_STATUS_RETRY:
1632                         tx_done.no_ack = true;
1633                         break;
1634                 case HTT_MGMT_TX_STATUS_DROP:
1635                         tx_done.discard = true;
1636                         break;
1637                 }
1638
1639                 spin_lock_bh(&htt->tx_lock);
1640                 ath10k_txrx_tx_unref(htt, &tx_done);
1641                 spin_unlock_bh(&htt->tx_lock);
1642                 break;
1643         }
1644         case HTT_T2H_MSG_TYPE_TX_COMPL_IND:
1645                 spin_lock_bh(&htt->tx_lock);
1646                 __skb_queue_tail(&htt->tx_compl_q, skb);
1647                 spin_unlock_bh(&htt->tx_lock);
1648                 tasklet_schedule(&htt->txrx_compl_task);
1649                 return;
1650         case HTT_T2H_MSG_TYPE_SEC_IND: {
1651                 struct ath10k *ar = htt->ar;
1652                 struct htt_security_indication *ev = &resp->security_indication;
1653
1654                 ath10k_dbg(ar, ATH10K_DBG_HTT,
1655                            "sec ind peer_id %d unicast %d type %d\n",
1656                           __le16_to_cpu(ev->peer_id),
1657                           !!(ev->flags & HTT_SECURITY_IS_UNICAST),
1658                           MS(ev->flags, HTT_SECURITY_TYPE));
1659                 complete(&ar->install_key_done);
1660                 break;
1661         }
1662         case HTT_T2H_MSG_TYPE_RX_FRAG_IND: {
1663                 ath10k_dbg_dump(ar, ATH10K_DBG_HTT_DUMP, NULL, "htt event: ",
1664                                 skb->data, skb->len);
1665                 ath10k_htt_rx_frag_handler(htt, &resp->rx_frag_ind);
1666                 break;
1667         }
1668         case HTT_T2H_MSG_TYPE_TEST:
1669                 /* FIX THIS */
1670                 break;
1671         case HTT_T2H_MSG_TYPE_STATS_CONF:
1672                 trace_ath10k_htt_stats(ar, skb->data, skb->len);
1673                 break;
1674         case HTT_T2H_MSG_TYPE_TX_INSPECT_IND:
1675                 /* Firmware can return tx frames if it's unable to fully
1676                  * process them and suspects host may be able to fix it. ath10k
1677                  * sends all tx frames as already inspected so this shouldn't
1678                  * happen unless fw has a bug.
1679                  */
1680                 ath10k_warn(ar, "received an unexpected htt tx inspect event\n");
1681                 break;
1682         case HTT_T2H_MSG_TYPE_RX_ADDBA:
1683                 ath10k_htt_rx_addba(ar, resp);
1684                 break;
1685         case HTT_T2H_MSG_TYPE_RX_DELBA:
1686                 ath10k_htt_rx_delba(ar, resp);
1687                 break;
1688         case HTT_T2H_MSG_TYPE_PKTLOG: {
1689                 struct ath10k_pktlog_hdr *hdr =
1690                         (struct ath10k_pktlog_hdr *)resp->pktlog_msg.payload;
1691
1692                 trace_ath10k_htt_pktlog(ar, resp->pktlog_msg.payload,
1693                                         sizeof(*hdr) +
1694                                         __le16_to_cpu(hdr->size));
1695                 break;
1696         }
1697         case HTT_T2H_MSG_TYPE_RX_FLUSH: {
1698                 /* Ignore this event because mac80211 takes care of Rx
1699                  * aggregation reordering.
1700                  */
1701                 break;
1702         }
1703         default:
1704                 ath10k_warn(ar, "htt event (%d) not handled\n",
1705                             resp->hdr.msg_type);
1706                 ath10k_dbg_dump(ar, ATH10K_DBG_HTT_DUMP, NULL, "htt event: ",
1707                                 skb->data, skb->len);
1708                 break;
1709         };
1710
1711         /* Free the indication buffer */
1712         dev_kfree_skb_any(skb);
1713 }
1714
1715 static void ath10k_htt_txrx_compl_task(unsigned long ptr)
1716 {
1717         struct ath10k_htt *htt = (struct ath10k_htt *)ptr;
1718         struct htt_resp *resp;
1719         struct sk_buff *skb;
1720
1721         spin_lock_bh(&htt->tx_lock);
1722         while ((skb = __skb_dequeue(&htt->tx_compl_q))) {
1723                 ath10k_htt_rx_frm_tx_compl(htt->ar, skb);
1724                 dev_kfree_skb_any(skb);
1725         }
1726         spin_unlock_bh(&htt->tx_lock);
1727
1728         spin_lock_bh(&htt->rx_ring.lock);
1729         while ((skb = __skb_dequeue(&htt->rx_compl_q))) {
1730                 resp = (struct htt_resp *)skb->data;
1731                 ath10k_htt_rx_handler(htt, &resp->rx_ind);
1732                 dev_kfree_skb_any(skb);
1733         }
1734         spin_unlock_bh(&htt->rx_ring.lock);
1735 }