2 * Copyright (c) 2005-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
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.
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.
25 #include <linux/log2.h>
27 /* slightly larger than one large A-MPDU */
28 #define HTT_RX_RING_SIZE_MIN 128
30 /* roughly 20 ms @ 1 Gbps of 1500B MSDUs */
31 #define HTT_RX_RING_SIZE_MAX 2048
33 #define HTT_RX_AVG_FRM_BYTES 1000
35 /* ms, very conservative */
36 #define HTT_RX_HOST_LATENCY_MAX_MS 20
38 /* ms, conservative */
39 #define HTT_RX_HOST_LATENCY_WORST_LIKELY_MS 10
41 /* when under memory pressure rx ring refill may fail and needs a retry */
42 #define HTT_RX_RING_REFILL_RETRY_MS 50
45 static int ath10k_htt_rx_get_csum_state(struct sk_buff
*skb
);
46 static void ath10k_htt_txrx_compl_task(unsigned long ptr
);
48 static int ath10k_htt_rx_ring_size(struct ath10k_htt
*htt
)
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.
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
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.
72 /* 1e6 bps/mbps / 1e3 ms per sec = 1000 */
74 htt
->max_throughput_mbps
+
76 (8 * HTT_RX_AVG_FRM_BYTES
) * HTT_RX_HOST_LATENCY_MAX_MS
;
78 if (size
< HTT_RX_RING_SIZE_MIN
)
79 size
= HTT_RX_RING_SIZE_MIN
;
81 if (size
> HTT_RX_RING_SIZE_MAX
)
82 size
= HTT_RX_RING_SIZE_MAX
;
84 size
= roundup_pow_of_two(size
);
89 static int ath10k_htt_rx_ring_fill_level(struct ath10k_htt
*htt
)
93 /* 1e6 bps/mbps / 1e3 ms per sec = 1000 */
95 htt
->max_throughput_mbps
*
97 (8 * HTT_RX_AVG_FRM_BYTES
) * HTT_RX_HOST_LATENCY_WORST_LIKELY_MS
;
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.
104 if (size
>= htt
->rx_ring
.size
)
105 size
= htt
->rx_ring
.size
- 1;
110 static void ath10k_htt_rx_ring_free(struct ath10k_htt
*htt
)
113 struct ath10k_skb_cb
*cb
;
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
),
122 dev_kfree_skb_any(skb
);
125 htt
->rx_ring
.fill_cnt
= 0;
128 static int __ath10k_htt_rx_ring_fill_n(struct ath10k_htt
*htt
, int num
)
130 struct htt_rx_desc
*rx_desc
;
135 idx
= __le32_to_cpu(*(htt
->rx_ring
.alloc_idx
.vaddr
));
137 skb
= dev_alloc_skb(HTT_RX_BUF_SIZE
+ HTT_RX_DESC_ALIGN
);
143 if (!IS_ALIGNED((unsigned long)skb
->data
, HTT_RX_DESC_ALIGN
))
145 PTR_ALIGN(skb
->data
, HTT_RX_DESC_ALIGN
) -
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);
152 paddr
= dma_map_single(htt
->ar
->dev
, skb
->data
,
153 skb
->len
+ skb_tailroom(skb
),
156 if (unlikely(dma_mapping_error(htt
->ar
->dev
, paddr
))) {
157 dev_kfree_skb_any(skb
);
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
++;
169 idx
&= htt
->rx_ring
.size_mask
;
173 *(htt
->rx_ring
.alloc_idx
.vaddr
) = __cpu_to_le32(idx
);
177 static int ath10k_htt_rx_ring_fill_n(struct ath10k_htt
*htt
, int num
)
179 lockdep_assert_held(&htt
->rx_ring
.lock
);
180 return __ath10k_htt_rx_ring_fill_n(htt
, num
);
183 static void ath10k_htt_rx_msdu_buff_replenish(struct ath10k_htt
*htt
)
185 int ret
, num_deficit
, num_to_fill
;
187 /* 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.
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.
200 * This probably comes at a cost of lower maximum throughput but
201 * improves the avarage and stability. */
202 spin_lock_bh(&htt
->rx_ring
.lock
);
203 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
;
206 ret
= ath10k_htt_rx_ring_fill_n(htt
, num_to_fill
);
207 if (ret
== -ENOMEM
) {
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.
214 mod_timer(&htt
->rx_ring
.refill_retry_timer
, jiffies
+
215 msecs_to_jiffies(HTT_RX_RING_REFILL_RETRY_MS
));
216 } else if (num_deficit
> 0) {
217 tasklet_schedule(&htt
->rx_replenish_task
);
219 spin_unlock_bh(&htt
->rx_ring
.lock
);
222 static void ath10k_htt_rx_ring_refill_retry(unsigned long arg
)
224 struct ath10k_htt
*htt
= (struct ath10k_htt
*)arg
;
225 ath10k_htt_rx_msdu_buff_replenish(htt
);
228 static void ath10k_htt_rx_ring_clean_up(struct ath10k_htt
*htt
)
233 for (i
= 0; i
< htt
->rx_ring
.size
; i
++) {
234 skb
= htt
->rx_ring
.netbufs_ring
[i
];
238 dma_unmap_single(htt
->ar
->dev
, ATH10K_SKB_CB(skb
)->paddr
,
239 skb
->len
+ skb_tailroom(skb
),
241 dev_kfree_skb_any(skb
);
242 htt
->rx_ring
.netbufs_ring
[i
] = NULL
;
246 void ath10k_htt_rx_free(struct ath10k_htt
*htt
)
248 del_timer_sync(&htt
->rx_ring
.refill_retry_timer
);
249 tasklet_kill(&htt
->rx_replenish_task
);
250 tasklet_kill(&htt
->txrx_compl_task
);
252 skb_queue_purge(&htt
->tx_compl_q
);
253 skb_queue_purge(&htt
->rx_compl_q
);
255 ath10k_htt_rx_ring_clean_up(htt
);
257 dma_free_coherent(htt
->ar
->dev
,
259 sizeof(htt
->rx_ring
.paddrs_ring
)),
260 htt
->rx_ring
.paddrs_ring
,
261 htt
->rx_ring
.base_paddr
);
263 dma_free_coherent(htt
->ar
->dev
,
264 sizeof(*htt
->rx_ring
.alloc_idx
.vaddr
),
265 htt
->rx_ring
.alloc_idx
.vaddr
,
266 htt
->rx_ring
.alloc_idx
.paddr
);
268 kfree(htt
->rx_ring
.netbufs_ring
);
271 static inline struct sk_buff
*ath10k_htt_rx_netbuf_pop(struct ath10k_htt
*htt
)
274 struct sk_buff
*msdu
;
276 lockdep_assert_held(&htt
->rx_ring
.lock
);
278 if (htt
->rx_ring
.fill_cnt
== 0) {
279 ath10k_warn("tried to pop sk_buff from an empty rx ring\n");
283 idx
= htt
->rx_ring
.sw_rd_idx
.msdu_payld
;
284 msdu
= htt
->rx_ring
.netbufs_ring
[idx
];
285 htt
->rx_ring
.netbufs_ring
[idx
] = NULL
;
288 idx
&= htt
->rx_ring
.size_mask
;
289 htt
->rx_ring
.sw_rd_idx
.msdu_payld
= idx
;
290 htt
->rx_ring
.fill_cnt
--;
295 static void ath10k_htt_rx_free_msdu_chain(struct sk_buff
*skb
)
297 struct sk_buff
*next
;
301 dev_kfree_skb_any(skb
);
306 /* return: < 0 fatal error, 0 - non chained msdu, 1 chained msdu */
307 static int ath10k_htt_rx_amsdu_pop(struct ath10k_htt
*htt
,
308 u8
**fw_desc
, int *fw_desc_len
,
309 struct sk_buff
**head_msdu
,
310 struct sk_buff
**tail_msdu
)
312 int msdu_len
, msdu_chaining
= 0;
313 struct sk_buff
*msdu
;
314 struct htt_rx_desc
*rx_desc
;
315 bool corrupted
= false;
317 lockdep_assert_held(&htt
->rx_ring
.lock
);
319 if (htt
->rx_confused
) {
320 ath10k_warn("htt is confused. refusing rx\n");
324 msdu
= *head_msdu
= ath10k_htt_rx_netbuf_pop(htt
);
326 int last_msdu
, msdu_len_invalid
, msdu_chained
;
328 dma_unmap_single(htt
->ar
->dev
,
329 ATH10K_SKB_CB(msdu
)->paddr
,
330 msdu
->len
+ skb_tailroom(msdu
),
333 ath10k_dbg_dump(ATH10K_DBG_HTT_DUMP
, NULL
, "htt rx pop: ",
334 msdu
->data
, msdu
->len
+ skb_tailroom(msdu
));
336 rx_desc
= (struct htt_rx_desc
*)msdu
->data
;
338 /* FIXME: we must report msdu payload since this is what caller
340 skb_put(msdu
, offsetof(struct htt_rx_desc
, msdu_payload
));
341 skb_pull(msdu
, offsetof(struct htt_rx_desc
, msdu_payload
));
344 * Sanity check - confirm the HW is finished filling in the
346 * If the HW and SW are working correctly, then it's guaranteed
347 * that the HW's MAC DMA is done before this point in the SW.
348 * To prevent the case that we handle a stale Rx descriptor,
349 * just assert for now until we have a way to recover.
351 if (!(__le32_to_cpu(rx_desc
->attention
.flags
)
352 & RX_ATTENTION_FLAGS_MSDU_DONE
)) {
353 ath10k_htt_rx_free_msdu_chain(*head_msdu
);
356 ath10k_err("htt rx stopped. cannot recover\n");
357 htt
->rx_confused
= true;
362 * Copy the FW rx descriptor for this MSDU from the rx
363 * indication message into the MSDU's netbuf. HL uses the
364 * same rx indication message definition as LL, and simply
365 * appends new info (fields from the HW rx desc, and the
366 * MSDU payload itself). So, the offset into the rx
367 * indication message only has to account for the standard
368 * offset of the per-MSDU FW rx desc info within the
369 * message, and how many bytes of the per-MSDU FW rx desc
370 * info have already been consumed. (And the endianness of
371 * the host, since for a big-endian host, the rx ind
372 * message contents, including the per-MSDU rx desc bytes,
373 * were byteswapped during upload.)
375 if (*fw_desc_len
> 0) {
376 rx_desc
->fw_desc
.info0
= **fw_desc
;
378 * The target is expected to only provide the basic
379 * per-MSDU rx descriptors. Just to be sure, verify
380 * that the target has not attached extension data
381 * (e.g. LRO flow ID).
384 /* or more, if there's extension data */
389 * When an oversized AMSDU happened, FW will lost
390 * some of MSDU status - in this case, the FW
391 * descriptors provided will be less than the
392 * actual MSDUs inside this MPDU. Mark the FW
393 * descriptors so that it will still deliver to
394 * upper stack, if no CRC error for this MPDU.
396 * FIX THIS - the FW descriptors are actually for
397 * MSDUs in the end of this A-MSDU instead of the
400 rx_desc
->fw_desc
.info0
= 0;
403 msdu_len_invalid
= !!(__le32_to_cpu(rx_desc
->attention
.flags
)
404 & (RX_ATTENTION_FLAGS_MPDU_LENGTH_ERR
|
405 RX_ATTENTION_FLAGS_MSDU_LENGTH_ERR
));
406 msdu_len
= MS(__le32_to_cpu(rx_desc
->msdu_start
.info0
),
407 RX_MSDU_START_INFO0_MSDU_LENGTH
);
408 msdu_chained
= rx_desc
->frag_info
.ring2_more_count
;
410 if (msdu_len_invalid
)
414 skb_put(msdu
, min(msdu_len
, HTT_RX_MSDU_SIZE
));
415 msdu_len
-= msdu
->len
;
417 /* FIXME: Do chained buffers include htt_rx_desc or not? */
418 while (msdu_chained
--) {
419 struct sk_buff
*next
= ath10k_htt_rx_netbuf_pop(htt
);
421 dma_unmap_single(htt
->ar
->dev
,
422 ATH10K_SKB_CB(next
)->paddr
,
423 next
->len
+ skb_tailroom(next
),
426 ath10k_dbg_dump(ATH10K_DBG_HTT_DUMP
, NULL
,
427 "htt rx chained: ", next
->data
,
428 next
->len
+ skb_tailroom(next
));
431 skb_put(next
, min(msdu_len
, HTT_RX_BUF_SIZE
));
432 msdu_len
-= next
->len
;
439 last_msdu
= __le32_to_cpu(rx_desc
->msdu_end
.info0
) &
440 RX_MSDU_END_INFO0_LAST_MSDU
;
442 if (msdu_chaining
&& !last_msdu
)
449 struct sk_buff
*next
= ath10k_htt_rx_netbuf_pop(htt
);
456 if (*head_msdu
== NULL
)
460 * Apparently FW sometimes reports weird chained MSDU sequences with
461 * more than one rx descriptor. This seems like a bug but needs more
462 * analyzing. For the time being fix it by dropping such sequences to
463 * avoid blowing up the host system.
466 ath10k_warn("failed to pop chained msdus, dropping\n");
467 ath10k_htt_rx_free_msdu_chain(*head_msdu
);
470 msdu_chaining
= -EINVAL
;
474 * Don't refill the ring yet.
476 * First, the elements popped here are still in use - it is not
477 * safe to overwrite them until the matching call to
478 * mpdu_desc_list_next. Second, for efficiency it is preferable to
479 * refill the rx ring with 1 PPDU's worth of rx buffers (something
480 * like 32 x 3 buffers), rather than one MPDU's worth of rx buffers
481 * (something like 3 buffers). Consequently, we'll rely on the txrx
482 * SW to tell us when it is done pulling all the PPDU's rx buffers
483 * out of the rx ring, and then refill it just once.
486 return msdu_chaining
;
489 static void ath10k_htt_rx_replenish_task(unsigned long ptr
)
491 struct ath10k_htt
*htt
= (struct ath10k_htt
*)ptr
;
492 ath10k_htt_rx_msdu_buff_replenish(htt
);
495 int ath10k_htt_rx_alloc(struct ath10k_htt
*htt
)
499 struct timer_list
*timer
= &htt
->rx_ring
.refill_retry_timer
;
501 htt
->rx_ring
.size
= ath10k_htt_rx_ring_size(htt
);
502 if (!is_power_of_2(htt
->rx_ring
.size
)) {
503 ath10k_warn("htt rx ring size is not power of 2\n");
507 htt
->rx_ring
.size_mask
= htt
->rx_ring
.size
- 1;
510 * Set the initial value for the level to which the rx ring
511 * should be filled, based on the max throughput and the
512 * worst likely latency for the host to fill the rx ring
513 * with new buffers. In theory, this fill level can be
514 * dynamically adjusted from the initial value set here, to
515 * reflect the actual host latency rather than a
516 * conservative assumption about the host latency.
518 htt
->rx_ring
.fill_level
= ath10k_htt_rx_ring_fill_level(htt
);
520 htt
->rx_ring
.netbufs_ring
=
521 kzalloc(htt
->rx_ring
.size
* sizeof(struct sk_buff
*),
523 if (!htt
->rx_ring
.netbufs_ring
)
526 vaddr
= dma_alloc_coherent(htt
->ar
->dev
,
527 (htt
->rx_ring
.size
* sizeof(htt
->rx_ring
.paddrs_ring
)),
532 htt
->rx_ring
.paddrs_ring
= vaddr
;
533 htt
->rx_ring
.base_paddr
= paddr
;
535 vaddr
= dma_alloc_coherent(htt
->ar
->dev
,
536 sizeof(*htt
->rx_ring
.alloc_idx
.vaddr
),
541 htt
->rx_ring
.alloc_idx
.vaddr
= vaddr
;
542 htt
->rx_ring
.alloc_idx
.paddr
= paddr
;
543 htt
->rx_ring
.sw_rd_idx
.msdu_payld
= 0;
544 *htt
->rx_ring
.alloc_idx
.vaddr
= 0;
546 /* Initialize the Rx refill retry timer */
547 setup_timer(timer
, ath10k_htt_rx_ring_refill_retry
, (unsigned long)htt
);
549 spin_lock_init(&htt
->rx_ring
.lock
);
551 htt
->rx_ring
.fill_cnt
= 0;
552 if (__ath10k_htt_rx_ring_fill_n(htt
, htt
->rx_ring
.fill_level
))
555 tasklet_init(&htt
->rx_replenish_task
, ath10k_htt_rx_replenish_task
,
558 skb_queue_head_init(&htt
->tx_compl_q
);
559 skb_queue_head_init(&htt
->rx_compl_q
);
561 tasklet_init(&htt
->txrx_compl_task
, ath10k_htt_txrx_compl_task
,
564 ath10k_dbg(ATH10K_DBG_BOOT
, "htt rx ring size %d fill_level %d\n",
565 htt
->rx_ring
.size
, htt
->rx_ring
.fill_level
);
569 ath10k_htt_rx_ring_free(htt
);
570 dma_free_coherent(htt
->ar
->dev
,
571 sizeof(*htt
->rx_ring
.alloc_idx
.vaddr
),
572 htt
->rx_ring
.alloc_idx
.vaddr
,
573 htt
->rx_ring
.alloc_idx
.paddr
);
575 dma_free_coherent(htt
->ar
->dev
,
577 sizeof(htt
->rx_ring
.paddrs_ring
)),
578 htt
->rx_ring
.paddrs_ring
,
579 htt
->rx_ring
.base_paddr
);
581 kfree(htt
->rx_ring
.netbufs_ring
);
586 static int ath10k_htt_rx_crypto_param_len(enum htt_rx_mpdu_encrypt_type type
)
589 case HTT_RX_MPDU_ENCRYPT_WEP40
:
590 case HTT_RX_MPDU_ENCRYPT_WEP104
:
592 case HTT_RX_MPDU_ENCRYPT_TKIP_WITHOUT_MIC
:
593 case HTT_RX_MPDU_ENCRYPT_WEP128
: /* not tested */
594 case HTT_RX_MPDU_ENCRYPT_TKIP_WPA
:
595 case HTT_RX_MPDU_ENCRYPT_WAPI
: /* not tested */
596 case HTT_RX_MPDU_ENCRYPT_AES_CCM_WPA2
:
598 case HTT_RX_MPDU_ENCRYPT_NONE
:
602 ath10k_warn("unknown encryption type %d\n", type
);
606 static int ath10k_htt_rx_crypto_tail_len(enum htt_rx_mpdu_encrypt_type type
)
609 case HTT_RX_MPDU_ENCRYPT_NONE
:
610 case HTT_RX_MPDU_ENCRYPT_WEP40
:
611 case HTT_RX_MPDU_ENCRYPT_WEP104
:
612 case HTT_RX_MPDU_ENCRYPT_WEP128
:
613 case HTT_RX_MPDU_ENCRYPT_WAPI
:
615 case HTT_RX_MPDU_ENCRYPT_TKIP_WITHOUT_MIC
:
616 case HTT_RX_MPDU_ENCRYPT_TKIP_WPA
:
618 case HTT_RX_MPDU_ENCRYPT_AES_CCM_WPA2
:
622 ath10k_warn("unknown encryption type %d\n", type
);
626 /* Applies for first msdu in chain, before altering it. */
627 static struct ieee80211_hdr
*ath10k_htt_rx_skb_get_hdr(struct sk_buff
*skb
)
629 struct htt_rx_desc
*rxd
;
630 enum rx_msdu_decap_format fmt
;
632 rxd
= (void *)skb
->data
- sizeof(*rxd
);
633 fmt
= MS(__le32_to_cpu(rxd
->msdu_start
.info1
),
634 RX_MSDU_START_INFO1_DECAP_FORMAT
);
636 if (fmt
== RX_MSDU_DECAP_RAW
)
637 return (void *)skb
->data
;
639 return (void *)skb
->data
- RX_HTT_HDR_STATUS_LEN
;
642 /* This function only applies for first msdu in an msdu chain */
643 static bool ath10k_htt_rx_hdr_is_amsdu(struct ieee80211_hdr
*hdr
)
645 if (ieee80211_is_data_qos(hdr
->frame_control
)) {
646 u8
*qc
= ieee80211_get_qos_ctl(hdr
);
661 struct amsdu_subframe_hdr
{
667 static const u8 rx_legacy_rate_idx
[] = {
668 3, /* 0x00 - 11Mbps */
669 2, /* 0x01 - 5.5Mbps */
670 1, /* 0x02 - 2Mbps */
671 0, /* 0x03 - 1Mbps */
672 3, /* 0x04 - 11Mbps */
673 2, /* 0x05 - 5.5Mbps */
674 1, /* 0x06 - 2Mbps */
675 0, /* 0x07 - 1Mbps */
676 10, /* 0x08 - 48Mbps */
677 8, /* 0x09 - 24Mbps */
678 6, /* 0x0A - 12Mbps */
679 4, /* 0x0B - 6Mbps */
680 11, /* 0x0C - 54Mbps */
681 9, /* 0x0D - 36Mbps */
682 7, /* 0x0E - 18Mbps */
683 5, /* 0x0F - 9Mbps */
686 static void ath10k_htt_rx_h_rates(struct ath10k
*ar
,
687 enum ieee80211_band band
,
688 u8 info0
, u32 info1
, u32 info2
,
689 struct ieee80211_rx_status
*status
)
691 u8 cck
, rate
, rate_idx
, bw
, sgi
, mcs
, nss
;
694 /* Check if valid fields */
695 if (!(info0
& HTT_RX_INDICATION_INFO0_START_VALID
))
698 preamble
= MS(info1
, HTT_RX_INDICATION_INFO1_PREAMBLE_TYPE
);
702 cck
= info0
& HTT_RX_INDICATION_INFO0_LEGACY_RATE_CCK
;
703 rate
= MS(info0
, HTT_RX_INDICATION_INFO0_LEGACY_RATE
);
706 if (rate
< 0x08 || rate
> 0x0F)
710 case IEEE80211_BAND_2GHZ
:
713 rate_idx
= rx_legacy_rate_idx
[rate
];
715 case IEEE80211_BAND_5GHZ
:
716 rate_idx
= rx_legacy_rate_idx
[rate
];
717 /* We are using same rate table registering
718 HW - ath10k_rates[]. In case of 5GHz skip
719 CCK rates, so -4 here */
726 status
->rate_idx
= rate_idx
;
729 case HTT_RX_HT_WITH_TXBF
:
730 /* HT-SIG - Table 20-11 in info1 and info2 */
733 bw
= (info1
>> 7) & 1;
734 sgi
= (info2
>> 7) & 1;
736 status
->rate_idx
= mcs
;
737 status
->flag
|= RX_FLAG_HT
;
739 status
->flag
|= RX_FLAG_SHORT_GI
;
741 status
->flag
|= RX_FLAG_40MHZ
;
744 case HTT_RX_VHT_WITH_TXBF
:
745 /* VHT-SIG-A1 in info 1, VHT-SIG-A2 in info2
747 mcs
= (info2
>> 4) & 0x0F;
748 nss
= ((info1
>> 10) & 0x07) + 1;
752 status
->rate_idx
= mcs
;
753 status
->vht_nss
= nss
;
756 status
->flag
|= RX_FLAG_SHORT_GI
;
764 status
->flag
|= RX_FLAG_40MHZ
;
768 status
->vht_flag
|= RX_VHT_FLAG_80MHZ
;
771 status
->flag
|= RX_FLAG_VHT
;
778 static void ath10k_htt_rx_h_protected(struct ath10k_htt
*htt
,
779 struct ieee80211_rx_status
*rx_status
,
781 enum htt_rx_mpdu_encrypt_type enctype
,
782 enum rx_msdu_decap_format fmt
,
785 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
787 rx_status
->flag
&= ~(RX_FLAG_DECRYPTED
|
788 RX_FLAG_IV_STRIPPED
|
789 RX_FLAG_MMIC_STRIPPED
);
791 if (enctype
== HTT_RX_MPDU_ENCRYPT_NONE
)
795 * There's no explicit rx descriptor flag to indicate whether a given
796 * frame has been decrypted or not. We're forced to use the decap
797 * format as an implicit indication. However fragmentation rx is always
798 * raw and it probably never reports undecrypted raws.
800 * This makes sure sniffed frames are reported as-is without stripping
801 * the protected flag.
803 if (fmt
== RX_MSDU_DECAP_RAW
&& !dot11frag
)
806 rx_status
->flag
|= RX_FLAG_DECRYPTED
|
807 RX_FLAG_IV_STRIPPED
|
808 RX_FLAG_MMIC_STRIPPED
;
809 hdr
->frame_control
= __cpu_to_le16(__le16_to_cpu(hdr
->frame_control
) &
810 ~IEEE80211_FCTL_PROTECTED
);
813 static bool ath10k_htt_rx_h_channel(struct ath10k
*ar
,
814 struct ieee80211_rx_status
*status
)
816 struct ieee80211_channel
*ch
;
818 spin_lock_bh(&ar
->data_lock
);
819 ch
= ar
->scan_channel
;
822 spin_unlock_bh(&ar
->data_lock
);
827 status
->band
= ch
->band
;
828 status
->freq
= ch
->center_freq
;
833 static void ath10k_process_rx(struct ath10k
*ar
,
834 struct ieee80211_rx_status
*rx_status
,
837 struct ieee80211_rx_status
*status
;
839 status
= IEEE80211_SKB_RXCB(skb
);
840 *status
= *rx_status
;
842 ath10k_dbg(ATH10K_DBG_DATA
,
843 "rx skb %p len %u %s%s%s%s%s %srate_idx %u vht_nss %u freq %u band %u flag 0x%x fcs-err %imic-err %i\n",
846 status
->flag
== 0 ? "legacy" : "",
847 status
->flag
& RX_FLAG_HT
? "ht" : "",
848 status
->flag
& RX_FLAG_VHT
? "vht" : "",
849 status
->flag
& RX_FLAG_40MHZ
? "40" : "",
850 status
->vht_flag
& RX_VHT_FLAG_80MHZ
? "80" : "",
851 status
->flag
& RX_FLAG_SHORT_GI
? "sgi " : "",
855 status
->band
, status
->flag
,
856 !!(status
->flag
& RX_FLAG_FAILED_FCS_CRC
),
857 !!(status
->flag
& RX_FLAG_MMIC_ERROR
));
858 ath10k_dbg_dump(ATH10K_DBG_HTT_DUMP
, NULL
, "rx skb: ",
859 skb
->data
, skb
->len
);
861 ieee80211_rx(ar
->hw
, skb
);
864 static int ath10k_htt_rx_nwifi_hdrlen(struct ieee80211_hdr
*hdr
)
866 /* nwifi header is padded to 4 bytes. this fixes 4addr rx */
867 return round_up(ieee80211_hdrlen(hdr
->frame_control
), 4);
870 static void ath10k_htt_rx_amsdu(struct ath10k_htt
*htt
,
871 struct ieee80211_rx_status
*rx_status
,
872 struct sk_buff
*skb_in
)
874 struct htt_rx_desc
*rxd
;
875 struct sk_buff
*skb
= skb_in
;
876 struct sk_buff
*first
;
877 enum rx_msdu_decap_format fmt
;
878 enum htt_rx_mpdu_encrypt_type enctype
;
879 struct ieee80211_hdr
*hdr
;
880 u8 hdr_buf
[64], addr
[ETH_ALEN
], *qos
;
881 unsigned int hdr_len
;
883 rxd
= (void *)skb
->data
- sizeof(*rxd
);
884 enctype
= MS(__le32_to_cpu(rxd
->mpdu_start
.info0
),
885 RX_MPDU_START_INFO0_ENCRYPT_TYPE
);
887 hdr
= (struct ieee80211_hdr
*)rxd
->rx_hdr_status
;
888 hdr_len
= ieee80211_hdrlen(hdr
->frame_control
);
889 memcpy(hdr_buf
, hdr
, hdr_len
);
890 hdr
= (struct ieee80211_hdr
*)hdr_buf
;
897 rxd
= (void *)skb
->data
- sizeof(*rxd
);
898 fmt
= MS(__le32_to_cpu(rxd
->msdu_start
.info1
),
899 RX_MSDU_START_INFO1_DECAP_FORMAT
);
900 decap_hdr
= (void *)rxd
->rx_hdr_status
;
902 skb
->ip_summed
= ath10k_htt_rx_get_csum_state(skb
);
904 /* First frame in an A-MSDU chain has more decapped data. */
906 len
= round_up(ieee80211_hdrlen(hdr
->frame_control
), 4);
907 len
+= round_up(ath10k_htt_rx_crypto_param_len(enctype
),
913 case RX_MSDU_DECAP_RAW
:
914 /* remove trailing FCS */
915 skb_trim(skb
, skb
->len
- FCS_LEN
);
917 case RX_MSDU_DECAP_NATIVE_WIFI
:
918 /* pull decapped header and copy DA */
919 hdr
= (struct ieee80211_hdr
*)skb
->data
;
920 hdr_len
= ath10k_htt_rx_nwifi_hdrlen(hdr
);
921 memcpy(addr
, ieee80211_get_DA(hdr
), ETH_ALEN
);
922 skb_pull(skb
, hdr_len
);
924 /* push original 802.11 header */
925 hdr
= (struct ieee80211_hdr
*)hdr_buf
;
926 hdr_len
= ieee80211_hdrlen(hdr
->frame_control
);
927 memcpy(skb_push(skb
, hdr_len
), hdr
, hdr_len
);
929 /* original A-MSDU header has the bit set but we're
930 * not including A-MSDU subframe header */
931 hdr
= (struct ieee80211_hdr
*)skb
->data
;
932 qos
= ieee80211_get_qos_ctl(hdr
);
933 qos
[0] &= ~IEEE80211_QOS_CTL_A_MSDU_PRESENT
;
935 /* original 802.11 header has a different DA */
936 memcpy(ieee80211_get_DA(hdr
), addr
, ETH_ALEN
);
938 case RX_MSDU_DECAP_ETHERNET2_DIX
:
939 /* strip ethernet header and insert decapped 802.11
940 * header, amsdu subframe header and rfc1042 header */
943 len
+= sizeof(struct rfc1042_hdr
);
944 len
+= sizeof(struct amsdu_subframe_hdr
);
946 skb_pull(skb
, sizeof(struct ethhdr
));
947 memcpy(skb_push(skb
, len
), decap_hdr
, len
);
948 memcpy(skb_push(skb
, hdr_len
), hdr
, hdr_len
);
950 case RX_MSDU_DECAP_8023_SNAP_LLC
:
951 /* insert decapped 802.11 header making a singly
953 memcpy(skb_push(skb
, hdr_len
), hdr
, hdr_len
);
958 ath10k_htt_rx_h_protected(htt
, rx_status
, skb_in
, enctype
, fmt
,
964 rx_status
->flag
|= RX_FLAG_AMSDU_MORE
;
966 rx_status
->flag
&= ~RX_FLAG_AMSDU_MORE
;
968 ath10k_process_rx(htt
->ar
, rx_status
, skb_in
);
971 /* FIXME: It might be nice to re-assemble the A-MSDU when there's a
972 * monitor interface active for sniffing purposes. */
975 static void ath10k_htt_rx_msdu(struct ath10k_htt
*htt
,
976 struct ieee80211_rx_status
*rx_status
,
979 struct htt_rx_desc
*rxd
;
980 struct ieee80211_hdr
*hdr
;
981 enum rx_msdu_decap_format fmt
;
982 enum htt_rx_mpdu_encrypt_type enctype
;
986 /* This shouldn't happen. If it does than it may be a FW bug. */
988 ath10k_warn("htt rx received chained non A-MSDU frame\n");
989 ath10k_htt_rx_free_msdu_chain(skb
->next
);
993 rxd
= (void *)skb
->data
- sizeof(*rxd
);
994 fmt
= MS(__le32_to_cpu(rxd
->msdu_start
.info1
),
995 RX_MSDU_START_INFO1_DECAP_FORMAT
);
996 enctype
= MS(__le32_to_cpu(rxd
->mpdu_start
.info0
),
997 RX_MPDU_START_INFO0_ENCRYPT_TYPE
);
998 hdr
= (struct ieee80211_hdr
*)rxd
->rx_hdr_status
;
999 hdr_len
= ieee80211_hdrlen(hdr
->frame_control
);
1001 skb
->ip_summed
= ath10k_htt_rx_get_csum_state(skb
);
1004 case RX_MSDU_DECAP_RAW
:
1005 /* remove trailing FCS */
1006 skb_trim(skb
, skb
->len
- FCS_LEN
);
1008 case RX_MSDU_DECAP_NATIVE_WIFI
:
1009 /* Pull decapped header */
1010 hdr
= (struct ieee80211_hdr
*)skb
->data
;
1011 hdr_len
= ath10k_htt_rx_nwifi_hdrlen(hdr
);
1012 skb_pull(skb
, hdr_len
);
1014 /* Push original header */
1015 hdr
= (struct ieee80211_hdr
*)rxd
->rx_hdr_status
;
1016 hdr_len
= ieee80211_hdrlen(hdr
->frame_control
);
1017 memcpy(skb_push(skb
, hdr_len
), hdr
, hdr_len
);
1019 case RX_MSDU_DECAP_ETHERNET2_DIX
:
1020 /* strip ethernet header and insert decapped 802.11 header and
1024 rfc1042
+= roundup(hdr_len
, 4);
1025 rfc1042
+= roundup(ath10k_htt_rx_crypto_param_len(enctype
), 4);
1027 skb_pull(skb
, sizeof(struct ethhdr
));
1028 memcpy(skb_push(skb
, sizeof(struct rfc1042_hdr
)),
1029 rfc1042
, sizeof(struct rfc1042_hdr
));
1030 memcpy(skb_push(skb
, hdr_len
), hdr
, hdr_len
);
1032 case RX_MSDU_DECAP_8023_SNAP_LLC
:
1033 /* remove A-MSDU subframe header and insert
1034 * decapped 802.11 header. rfc1042 header is already there */
1036 skb_pull(skb
, sizeof(struct amsdu_subframe_hdr
));
1037 memcpy(skb_push(skb
, hdr_len
), hdr
, hdr_len
);
1041 ath10k_htt_rx_h_protected(htt
, rx_status
, skb
, enctype
, fmt
, false);
1043 ath10k_process_rx(htt
->ar
, rx_status
, skb
);
1046 static int ath10k_htt_rx_get_csum_state(struct sk_buff
*skb
)
1048 struct htt_rx_desc
*rxd
;
1050 bool is_ip4
, is_ip6
;
1051 bool is_tcp
, is_udp
;
1052 bool ip_csum_ok
, tcpudp_csum_ok
;
1054 rxd
= (void *)skb
->data
- sizeof(*rxd
);
1055 flags
= __le32_to_cpu(rxd
->attention
.flags
);
1056 info
= __le32_to_cpu(rxd
->msdu_start
.info1
);
1058 is_ip4
= !!(info
& RX_MSDU_START_INFO1_IPV4_PROTO
);
1059 is_ip6
= !!(info
& RX_MSDU_START_INFO1_IPV6_PROTO
);
1060 is_tcp
= !!(info
& RX_MSDU_START_INFO1_TCP_PROTO
);
1061 is_udp
= !!(info
& RX_MSDU_START_INFO1_UDP_PROTO
);
1062 ip_csum_ok
= !(flags
& RX_ATTENTION_FLAGS_IP_CHKSUM_FAIL
);
1063 tcpudp_csum_ok
= !(flags
& RX_ATTENTION_FLAGS_TCP_UDP_CHKSUM_FAIL
);
1065 if (!is_ip4
&& !is_ip6
)
1066 return CHECKSUM_NONE
;
1067 if (!is_tcp
&& !is_udp
)
1068 return CHECKSUM_NONE
;
1070 return CHECKSUM_NONE
;
1071 if (!tcpudp_csum_ok
)
1072 return CHECKSUM_NONE
;
1074 return CHECKSUM_UNNECESSARY
;
1077 static int ath10k_unchain_msdu(struct sk_buff
*msdu_head
)
1079 struct sk_buff
*next
= msdu_head
->next
;
1080 struct sk_buff
*to_free
= next
;
1084 /* TODO: Might could optimize this by using
1085 * skb_try_coalesce or similar method to
1086 * decrease copying, or maybe get mac80211 to
1087 * provide a way to just receive a list of
1091 msdu_head
->next
= NULL
;
1093 /* Allocate total length all at once. */
1095 total_len
+= next
->len
;
1099 space
= total_len
- skb_tailroom(msdu_head
);
1101 (pskb_expand_head(msdu_head
, 0, space
, GFP_ATOMIC
) < 0)) {
1102 /* TODO: bump some rx-oom error stat */
1103 /* put it back together so we can free the
1104 * whole list at once.
1106 msdu_head
->next
= to_free
;
1110 /* Walk list again, copying contents into
1115 skb_copy_from_linear_data(next
, skb_put(msdu_head
, next
->len
),
1120 /* If here, we have consolidated skb. Free the
1121 * fragments and pass the main skb on up the
1124 ath10k_htt_rx_free_msdu_chain(to_free
);
1128 static bool ath10k_htt_rx_amsdu_allowed(struct ath10k_htt
*htt
,
1129 struct sk_buff
*head
,
1130 enum htt_rx_mpdu_status status
,
1134 if (head
->len
== 0) {
1135 ath10k_dbg(ATH10K_DBG_HTT
,
1136 "htt rx dropping due to zero-len\n");
1140 if (attention
& RX_ATTENTION_FLAGS_DECRYPT_ERR
) {
1141 ath10k_dbg(ATH10K_DBG_HTT
,
1142 "htt rx dropping due to decrypt-err\n");
1147 ath10k_warn("no channel configured; ignoring frame!\n");
1151 /* Skip mgmt frames while we handle this in WMI */
1152 if (status
== HTT_RX_IND_MPDU_STATUS_MGMT_CTRL
||
1153 attention
& RX_ATTENTION_FLAGS_MGMT_TYPE
) {
1154 ath10k_dbg(ATH10K_DBG_HTT
, "htt rx mgmt ctrl\n");
1158 if (status
!= HTT_RX_IND_MPDU_STATUS_OK
&&
1159 status
!= HTT_RX_IND_MPDU_STATUS_TKIP_MIC_ERR
&&
1160 status
!= HTT_RX_IND_MPDU_STATUS_ERR_INV_PEER
&&
1161 !htt
->ar
->monitor_started
) {
1162 ath10k_dbg(ATH10K_DBG_HTT
,
1163 "htt rx ignoring frame w/ status %d\n",
1168 if (test_bit(ATH10K_CAC_RUNNING
, &htt
->ar
->dev_flags
)) {
1169 ath10k_dbg(ATH10K_DBG_HTT
,
1170 "htt rx CAC running\n");
1177 static void ath10k_htt_rx_handler(struct ath10k_htt
*htt
,
1178 struct htt_rx_indication
*rx
)
1180 struct ieee80211_rx_status
*rx_status
= &htt
->rx_status
;
1181 struct htt_rx_indication_mpdu_range
*mpdu_ranges
;
1182 struct htt_rx_desc
*rxd
;
1183 enum htt_rx_mpdu_status status
;
1184 struct ieee80211_hdr
*hdr
;
1185 int num_mpdu_ranges
;
1193 lockdep_assert_held(&htt
->rx_ring
.lock
);
1195 fw_desc_len
= __le16_to_cpu(rx
->prefix
.fw_rx_desc_bytes
);
1196 fw_desc
= (u8
*)&rx
->fw_desc
;
1198 num_mpdu_ranges
= MS(__le32_to_cpu(rx
->hdr
.info1
),
1199 HTT_RX_INDICATION_INFO1_NUM_MPDU_RANGES
);
1200 mpdu_ranges
= htt_rx_ind_get_mpdu_ranges(rx
);
1202 /* Fill this once, while this is per-ppdu */
1203 if (rx
->ppdu
.info0
& HTT_RX_INDICATION_INFO0_START_VALID
) {
1204 memset(rx_status
, 0, sizeof(*rx_status
));
1205 rx_status
->signal
= ATH10K_DEFAULT_NOISE_FLOOR
+
1206 rx
->ppdu
.combined_rssi
;
1209 if (rx
->ppdu
.info0
& HTT_RX_INDICATION_INFO0_END_VALID
) {
1210 /* TSF available only in 32-bit */
1211 rx_status
->mactime
= __le32_to_cpu(rx
->ppdu
.tsf
) & 0xffffffff;
1212 rx_status
->flag
|= RX_FLAG_MACTIME_END
;
1215 channel_set
= ath10k_htt_rx_h_channel(htt
->ar
, rx_status
);
1218 ath10k_htt_rx_h_rates(htt
->ar
, rx_status
->band
,
1220 __le32_to_cpu(rx
->ppdu
.info1
),
1221 __le32_to_cpu(rx
->ppdu
.info2
),
1225 ath10k_dbg_dump(ATH10K_DBG_HTT_DUMP
, NULL
, "htt rx ind: ",
1227 (sizeof(struct htt_rx_indication_mpdu_range
) *
1230 for (i
= 0; i
< num_mpdu_ranges
; i
++) {
1231 status
= mpdu_ranges
[i
].mpdu_range_status
;
1233 for (j
= 0; j
< mpdu_ranges
[i
].mpdu_count
; j
++) {
1234 struct sk_buff
*msdu_head
, *msdu_tail
;
1238 ret
= ath10k_htt_rx_amsdu_pop(htt
,
1245 ath10k_warn("failed to pop amsdu from htt rx ring %d\n",
1247 ath10k_htt_rx_free_msdu_chain(msdu_head
);
1251 rxd
= container_of((void *)msdu_head
->data
,
1254 attention
= __le32_to_cpu(rxd
->attention
.flags
);
1256 if (!ath10k_htt_rx_amsdu_allowed(htt
, msdu_head
,
1260 ath10k_htt_rx_free_msdu_chain(msdu_head
);
1265 ath10k_unchain_msdu(msdu_head
) < 0) {
1266 ath10k_htt_rx_free_msdu_chain(msdu_head
);
1270 if (attention
& RX_ATTENTION_FLAGS_FCS_ERR
)
1271 rx_status
->flag
|= RX_FLAG_FAILED_FCS_CRC
;
1273 rx_status
->flag
&= ~RX_FLAG_FAILED_FCS_CRC
;
1275 if (attention
& RX_ATTENTION_FLAGS_TKIP_MIC_ERR
)
1276 rx_status
->flag
|= RX_FLAG_MMIC_ERROR
;
1278 rx_status
->flag
&= ~RX_FLAG_MMIC_ERROR
;
1280 hdr
= ath10k_htt_rx_skb_get_hdr(msdu_head
);
1282 if (ath10k_htt_rx_hdr_is_amsdu(hdr
))
1283 ath10k_htt_rx_amsdu(htt
, rx_status
, msdu_head
);
1285 ath10k_htt_rx_msdu(htt
, rx_status
, msdu_head
);
1289 tasklet_schedule(&htt
->rx_replenish_task
);
1292 static void ath10k_htt_rx_frag_handler(struct ath10k_htt
*htt
,
1293 struct htt_rx_fragment_indication
*frag
)
1295 struct sk_buff
*msdu_head
, *msdu_tail
;
1296 enum htt_rx_mpdu_encrypt_type enctype
;
1297 struct htt_rx_desc
*rxd
;
1298 enum rx_msdu_decap_format fmt
;
1299 struct ieee80211_rx_status
*rx_status
= &htt
->rx_status
;
1300 struct ieee80211_hdr
*hdr
;
1305 int fw_desc_len
, hdrlen
, paramlen
;
1308 fw_desc_len
= __le16_to_cpu(frag
->fw_rx_desc_bytes
);
1309 fw_desc
= (u8
*)frag
->fw_msdu_rx_desc
;
1314 spin_lock_bh(&htt
->rx_ring
.lock
);
1315 ret
= ath10k_htt_rx_amsdu_pop(htt
, &fw_desc
, &fw_desc_len
,
1316 &msdu_head
, &msdu_tail
);
1317 spin_unlock_bh(&htt
->rx_ring
.lock
);
1319 ath10k_dbg(ATH10K_DBG_HTT_DUMP
, "htt rx frag ahead\n");
1322 ath10k_warn("failed to pop amsdu from httr rx ring for fragmented rx %d\n",
1324 ath10k_htt_rx_free_msdu_chain(msdu_head
);
1328 /* FIXME: implement signal strength */
1329 rx_status
->flag
|= RX_FLAG_NO_SIGNAL_VAL
;
1331 hdr
= (struct ieee80211_hdr
*)msdu_head
->data
;
1332 rxd
= (void *)msdu_head
->data
- sizeof(*rxd
);
1333 tkip_mic_err
= !!(__le32_to_cpu(rxd
->attention
.flags
) &
1334 RX_ATTENTION_FLAGS_TKIP_MIC_ERR
);
1335 decrypt_err
= !!(__le32_to_cpu(rxd
->attention
.flags
) &
1336 RX_ATTENTION_FLAGS_DECRYPT_ERR
);
1337 fmt
= MS(__le32_to_cpu(rxd
->msdu_start
.info1
),
1338 RX_MSDU_START_INFO1_DECAP_FORMAT
);
1340 if (fmt
!= RX_MSDU_DECAP_RAW
) {
1341 ath10k_warn("we dont support non-raw fragmented rx yet\n");
1342 dev_kfree_skb_any(msdu_head
);
1346 enctype
= MS(__le32_to_cpu(rxd
->mpdu_start
.info0
),
1347 RX_MPDU_START_INFO0_ENCRYPT_TYPE
);
1348 ath10k_htt_rx_h_protected(htt
, rx_status
, msdu_head
, enctype
, fmt
,
1350 msdu_head
->ip_summed
= ath10k_htt_rx_get_csum_state(msdu_head
);
1353 ath10k_warn("tkip mic error\n");
1356 ath10k_warn("decryption err in fragmented rx\n");
1357 dev_kfree_skb_any(msdu_head
);
1361 if (enctype
!= HTT_RX_MPDU_ENCRYPT_NONE
) {
1362 hdrlen
= ieee80211_hdrlen(hdr
->frame_control
);
1363 paramlen
= ath10k_htt_rx_crypto_param_len(enctype
);
1365 /* It is more efficient to move the header than the payload */
1366 memmove((void *)msdu_head
->data
+ paramlen
,
1367 (void *)msdu_head
->data
,
1369 skb_pull(msdu_head
, paramlen
);
1370 hdr
= (struct ieee80211_hdr
*)msdu_head
->data
;
1373 /* remove trailing FCS */
1376 /* remove crypto trailer */
1377 trim
+= ath10k_htt_rx_crypto_tail_len(enctype
);
1379 /* last fragment of TKIP frags has MIC */
1380 if (!ieee80211_has_morefrags(hdr
->frame_control
) &&
1381 enctype
== HTT_RX_MPDU_ENCRYPT_TKIP_WPA
)
1384 if (trim
> msdu_head
->len
) {
1385 ath10k_warn("htt rx fragment: trailer longer than the frame itself? drop\n");
1386 dev_kfree_skb_any(msdu_head
);
1390 skb_trim(msdu_head
, msdu_head
->len
- trim
);
1392 ath10k_dbg_dump(ATH10K_DBG_HTT_DUMP
, NULL
, "htt rx frag mpdu: ",
1393 msdu_head
->data
, msdu_head
->len
);
1394 ath10k_process_rx(htt
->ar
, rx_status
, msdu_head
);
1397 if (fw_desc_len
> 0) {
1398 ath10k_dbg(ATH10K_DBG_HTT
,
1399 "expecting more fragmented rx in one indication %d\n",
1404 static void ath10k_htt_rx_frm_tx_compl(struct ath10k
*ar
,
1405 struct sk_buff
*skb
)
1407 struct ath10k_htt
*htt
= &ar
->htt
;
1408 struct htt_resp
*resp
= (struct htt_resp
*)skb
->data
;
1409 struct htt_tx_done tx_done
= {};
1410 int status
= MS(resp
->data_tx_completion
.flags
, HTT_DATA_TX_STATUS
);
1414 lockdep_assert_held(&htt
->tx_lock
);
1417 case HTT_DATA_TX_STATUS_NO_ACK
:
1418 tx_done
.no_ack
= true;
1420 case HTT_DATA_TX_STATUS_OK
:
1422 case HTT_DATA_TX_STATUS_DISCARD
:
1423 case HTT_DATA_TX_STATUS_POSTPONE
:
1424 case HTT_DATA_TX_STATUS_DOWNLOAD_FAIL
:
1425 tx_done
.discard
= true;
1428 ath10k_warn("unhandled tx completion status %d\n", status
);
1429 tx_done
.discard
= true;
1433 ath10k_dbg(ATH10K_DBG_HTT
, "htt tx completion num_msdus %d\n",
1434 resp
->data_tx_completion
.num_msdus
);
1436 for (i
= 0; i
< resp
->data_tx_completion
.num_msdus
; i
++) {
1437 msdu_id
= resp
->data_tx_completion
.msdus
[i
];
1438 tx_done
.msdu_id
= __le16_to_cpu(msdu_id
);
1439 ath10k_txrx_tx_unref(htt
, &tx_done
);
1443 void ath10k_htt_t2h_msg_handler(struct ath10k
*ar
, struct sk_buff
*skb
)
1445 struct ath10k_htt
*htt
= &ar
->htt
;
1446 struct htt_resp
*resp
= (struct htt_resp
*)skb
->data
;
1448 /* confirm alignment */
1449 if (!IS_ALIGNED((unsigned long)skb
->data
, 4))
1450 ath10k_warn("unaligned htt message, expect trouble\n");
1452 ath10k_dbg(ATH10K_DBG_HTT
, "htt rx, msg_type: 0x%0X\n",
1453 resp
->hdr
.msg_type
);
1454 switch (resp
->hdr
.msg_type
) {
1455 case HTT_T2H_MSG_TYPE_VERSION_CONF
: {
1456 htt
->target_version_major
= resp
->ver_resp
.major
;
1457 htt
->target_version_minor
= resp
->ver_resp
.minor
;
1458 complete(&htt
->target_version_received
);
1461 case HTT_T2H_MSG_TYPE_RX_IND
:
1462 spin_lock_bh(&htt
->rx_ring
.lock
);
1463 __skb_queue_tail(&htt
->rx_compl_q
, skb
);
1464 spin_unlock_bh(&htt
->rx_ring
.lock
);
1465 tasklet_schedule(&htt
->txrx_compl_task
);
1467 case HTT_T2H_MSG_TYPE_PEER_MAP
: {
1468 struct htt_peer_map_event ev
= {
1469 .vdev_id
= resp
->peer_map
.vdev_id
,
1470 .peer_id
= __le16_to_cpu(resp
->peer_map
.peer_id
),
1472 memcpy(ev
.addr
, resp
->peer_map
.addr
, sizeof(ev
.addr
));
1473 ath10k_peer_map_event(htt
, &ev
);
1476 case HTT_T2H_MSG_TYPE_PEER_UNMAP
: {
1477 struct htt_peer_unmap_event ev
= {
1478 .peer_id
= __le16_to_cpu(resp
->peer_unmap
.peer_id
),
1480 ath10k_peer_unmap_event(htt
, &ev
);
1483 case HTT_T2H_MSG_TYPE_MGMT_TX_COMPLETION
: {
1484 struct htt_tx_done tx_done
= {};
1485 int status
= __le32_to_cpu(resp
->mgmt_tx_completion
.status
);
1488 __le32_to_cpu(resp
->mgmt_tx_completion
.desc_id
);
1491 case HTT_MGMT_TX_STATUS_OK
:
1493 case HTT_MGMT_TX_STATUS_RETRY
:
1494 tx_done
.no_ack
= true;
1496 case HTT_MGMT_TX_STATUS_DROP
:
1497 tx_done
.discard
= true;
1501 spin_lock_bh(&htt
->tx_lock
);
1502 ath10k_txrx_tx_unref(htt
, &tx_done
);
1503 spin_unlock_bh(&htt
->tx_lock
);
1506 case HTT_T2H_MSG_TYPE_TX_COMPL_IND
:
1507 spin_lock_bh(&htt
->tx_lock
);
1508 __skb_queue_tail(&htt
->tx_compl_q
, skb
);
1509 spin_unlock_bh(&htt
->tx_lock
);
1510 tasklet_schedule(&htt
->txrx_compl_task
);
1512 case HTT_T2H_MSG_TYPE_SEC_IND
: {
1513 struct ath10k
*ar
= htt
->ar
;
1514 struct htt_security_indication
*ev
= &resp
->security_indication
;
1516 ath10k_dbg(ATH10K_DBG_HTT
,
1517 "sec ind peer_id %d unicast %d type %d\n",
1518 __le16_to_cpu(ev
->peer_id
),
1519 !!(ev
->flags
& HTT_SECURITY_IS_UNICAST
),
1520 MS(ev
->flags
, HTT_SECURITY_TYPE
));
1521 complete(&ar
->install_key_done
);
1524 case HTT_T2H_MSG_TYPE_RX_FRAG_IND
: {
1525 ath10k_dbg_dump(ATH10K_DBG_HTT_DUMP
, NULL
, "htt event: ",
1526 skb
->data
, skb
->len
);
1527 ath10k_htt_rx_frag_handler(htt
, &resp
->rx_frag_ind
);
1530 case HTT_T2H_MSG_TYPE_TEST
:
1533 case HTT_T2H_MSG_TYPE_STATS_CONF
:
1534 trace_ath10k_htt_stats(skb
->data
, skb
->len
);
1536 case HTT_T2H_MSG_TYPE_TX_INSPECT_IND
:
1537 case HTT_T2H_MSG_TYPE_RX_ADDBA
:
1538 case HTT_T2H_MSG_TYPE_RX_DELBA
:
1539 case HTT_T2H_MSG_TYPE_RX_FLUSH
:
1541 ath10k_dbg(ATH10K_DBG_HTT
, "htt event (%d) not handled\n",
1542 resp
->hdr
.msg_type
);
1543 ath10k_dbg_dump(ATH10K_DBG_HTT_DUMP
, NULL
, "htt event: ",
1544 skb
->data
, skb
->len
);
1548 /* Free the indication buffer */
1549 dev_kfree_skb_any(skb
);
1552 static void ath10k_htt_txrx_compl_task(unsigned long ptr
)
1554 struct ath10k_htt
*htt
= (struct ath10k_htt
*)ptr
;
1555 struct htt_resp
*resp
;
1556 struct sk_buff
*skb
;
1558 spin_lock_bh(&htt
->tx_lock
);
1559 while ((skb
= __skb_dequeue(&htt
->tx_compl_q
))) {
1560 ath10k_htt_rx_frm_tx_compl(htt
->ar
, skb
);
1561 dev_kfree_skb_any(skb
);
1563 spin_unlock_bh(&htt
->tx_lock
);
1565 spin_lock_bh(&htt
->rx_ring
.lock
);
1566 while ((skb
= __skb_dequeue(&htt
->rx_compl_q
))) {
1567 resp
= (struct htt_resp
*)skb
->data
;
1568 ath10k_htt_rx_handler(htt
, &resp
->rx_ind
);
1569 dev_kfree_skb_any(skb
);
1571 spin_unlock_bh(&htt
->rx_ring
.lock
);