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.
26 #include <linux/log2.h>
28 #define HTT_RX_RING_SIZE 1024
29 #define HTT_RX_RING_FILL_LEVEL 1000
31 /* when under memory pressure rx ring refill may fail and needs a retry */
32 #define HTT_RX_RING_REFILL_RETRY_MS 50
34 static int ath10k_htt_rx_get_csum_state(struct sk_buff
*skb
);
35 static void ath10k_htt_txrx_compl_task(unsigned long ptr
);
37 static void ath10k_htt_rx_ring_free(struct ath10k_htt
*htt
)
40 struct ath10k_skb_cb
*cb
;
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
),
49 dev_kfree_skb_any(skb
);
52 htt
->rx_ring
.fill_cnt
= 0;
55 static int __ath10k_htt_rx_ring_fill_n(struct ath10k_htt
*htt
, int num
)
57 struct htt_rx_desc
*rx_desc
;
62 idx
= __le32_to_cpu(*htt
->rx_ring
.alloc_idx
.vaddr
);
64 skb
= dev_alloc_skb(HTT_RX_BUF_SIZE
+ HTT_RX_DESC_ALIGN
);
70 if (!IS_ALIGNED((unsigned long)skb
->data
, HTT_RX_DESC_ALIGN
))
72 PTR_ALIGN(skb
->data
, HTT_RX_DESC_ALIGN
) -
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);
79 paddr
= dma_map_single(htt
->ar
->dev
, skb
->data
,
80 skb
->len
+ skb_tailroom(skb
),
83 if (unlikely(dma_mapping_error(htt
->ar
->dev
, paddr
))) {
84 dev_kfree_skb_any(skb
);
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
++;
96 idx
&= htt
->rx_ring
.size_mask
;
100 *htt
->rx_ring
.alloc_idx
.vaddr
= __cpu_to_le32(idx
);
104 static int ath10k_htt_rx_ring_fill_n(struct ath10k_htt
*htt
, int num
)
106 lockdep_assert_held(&htt
->rx_ring
.lock
);
107 return __ath10k_htt_rx_ring_fill_n(htt
, num
);
110 static void ath10k_htt_rx_msdu_buff_replenish(struct ath10k_htt
*htt
)
112 int ret
, num_deficit
, num_to_fill
;
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.
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.
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
) {
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.
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
);
146 spin_unlock_bh(&htt
->rx_ring
.lock
);
149 static void ath10k_htt_rx_ring_refill_retry(unsigned long arg
)
151 struct ath10k_htt
*htt
= (struct ath10k_htt
*)arg
;
153 ath10k_htt_rx_msdu_buff_replenish(htt
);
156 static void ath10k_htt_rx_ring_clean_up(struct ath10k_htt
*htt
)
161 for (i
= 0; i
< htt
->rx_ring
.size
; i
++) {
162 skb
= htt
->rx_ring
.netbufs_ring
[i
];
166 dma_unmap_single(htt
->ar
->dev
, ATH10K_SKB_CB(skb
)->paddr
,
167 skb
->len
+ skb_tailroom(skb
),
169 dev_kfree_skb_any(skb
);
170 htt
->rx_ring
.netbufs_ring
[i
] = NULL
;
174 void ath10k_htt_rx_free(struct ath10k_htt
*htt
)
176 del_timer_sync(&htt
->rx_ring
.refill_retry_timer
);
177 tasklet_kill(&htt
->rx_replenish_task
);
178 tasklet_kill(&htt
->txrx_compl_task
);
180 skb_queue_purge(&htt
->tx_compl_q
);
181 skb_queue_purge(&htt
->rx_compl_q
);
183 ath10k_htt_rx_ring_clean_up(htt
);
185 dma_free_coherent(htt
->ar
->dev
,
187 sizeof(htt
->rx_ring
.paddrs_ring
)),
188 htt
->rx_ring
.paddrs_ring
,
189 htt
->rx_ring
.base_paddr
);
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
);
196 kfree(htt
->rx_ring
.netbufs_ring
);
199 static inline struct sk_buff
*ath10k_htt_rx_netbuf_pop(struct ath10k_htt
*htt
)
201 struct ath10k
*ar
= htt
->ar
;
203 struct sk_buff
*msdu
;
205 lockdep_assert_held(&htt
->rx_ring
.lock
);
207 if (htt
->rx_ring
.fill_cnt
== 0) {
208 ath10k_warn(ar
, "tried to pop sk_buff from an empty rx ring\n");
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
;
217 idx
&= htt
->rx_ring
.size_mask
;
218 htt
->rx_ring
.sw_rd_idx
.msdu_payld
= idx
;
219 htt
->rx_ring
.fill_cnt
--;
221 dma_unmap_single(htt
->ar
->dev
,
222 ATH10K_SKB_CB(msdu
)->paddr
,
223 msdu
->len
+ skb_tailroom(msdu
),
225 ath10k_dbg_dump(ar
, ATH10K_DBG_HTT_DUMP
, NULL
, "htt rx netbuf pop: ",
226 msdu
->data
, msdu
->len
+ skb_tailroom(msdu
));
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
)
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
;
241 lockdep_assert_held(&htt
->rx_ring
.lock
);
244 int last_msdu
, msdu_len_invalid
, msdu_chained
;
246 msdu
= ath10k_htt_rx_netbuf_pop(htt
);
248 __skb_queue_purge(amsdu
);
252 __skb_queue_tail(amsdu
, msdu
);
254 rx_desc
= (struct htt_rx_desc
*)msdu
->data
;
256 /* FIXME: we must report msdu payload since this is what caller
258 skb_put(msdu
, offsetof(struct htt_rx_desc
, msdu_payload
));
259 skb_pull(msdu
, offsetof(struct htt_rx_desc
, msdu_payload
));
262 * Sanity check - confirm the HW is finished filling in the
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.
269 if (!(__le32_to_cpu(rx_desc
->attention
.flags
)
270 & RX_ATTENTION_FLAGS_MSDU_DONE
)) {
271 __skb_queue_purge(amsdu
);
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.)
289 if (*fw_desc_len
> 0) {
290 rx_desc
->fw_desc
.info0
= **fw_desc
;
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).
298 /* or more, if there's extension data */
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.
310 * FIX THIS - the FW descriptors are actually for
311 * MSDUs in the end of this A-MSDU instead of the
314 rx_desc
->fw_desc
.info0
= 0;
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
;
324 if (msdu_len_invalid
)
328 skb_put(msdu
, min(msdu_len
, HTT_RX_MSDU_SIZE
));
329 msdu_len
-= msdu
->len
;
331 /* Note: Chained buffers do not contain rx descriptor */
332 while (msdu_chained
--) {
333 msdu
= ath10k_htt_rx_netbuf_pop(htt
);
335 __skb_queue_purge(amsdu
);
339 __skb_queue_tail(amsdu
, msdu
);
341 skb_put(msdu
, min(msdu_len
, HTT_RX_BUF_SIZE
));
342 msdu_len
-= msdu
->len
;
346 last_msdu
= __le32_to_cpu(rx_desc
->msdu_end
.info0
) &
347 RX_MSDU_END_INFO0_LAST_MSDU
;
349 trace_ath10k_htt_rx_desc(ar
, &rx_desc
->attention
,
350 sizeof(*rx_desc
) - sizeof(u32
));
356 if (skb_queue_empty(amsdu
))
360 * Don't refill the ring yet.
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.
372 return msdu_chaining
;
375 static void ath10k_htt_rx_replenish_task(unsigned long ptr
)
377 struct ath10k_htt
*htt
= (struct ath10k_htt
*)ptr
;
379 ath10k_htt_rx_msdu_buff_replenish(htt
);
382 int ath10k_htt_rx_alloc(struct ath10k_htt
*htt
)
384 struct ath10k
*ar
= htt
->ar
;
388 struct timer_list
*timer
= &htt
->rx_ring
.refill_retry_timer
;
390 htt
->rx_confused
= false;
392 /* XXX: The fill level could be changed during runtime in response to
393 * the host processing latency. Is this really worth it?
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
;
399 if (!is_power_of_2(htt
->rx_ring
.size
)) {
400 ath10k_warn(ar
, "htt rx ring size is not power of 2\n");
404 htt
->rx_ring
.netbufs_ring
=
405 kzalloc(htt
->rx_ring
.size
* sizeof(struct sk_buff
*),
407 if (!htt
->rx_ring
.netbufs_ring
)
410 size
= htt
->rx_ring
.size
* sizeof(htt
->rx_ring
.paddrs_ring
);
412 vaddr
= dma_alloc_coherent(htt
->ar
->dev
, size
, &paddr
, GFP_DMA
);
416 htt
->rx_ring
.paddrs_ring
= vaddr
;
417 htt
->rx_ring
.base_paddr
= paddr
;
419 vaddr
= dma_alloc_coherent(htt
->ar
->dev
,
420 sizeof(*htt
->rx_ring
.alloc_idx
.vaddr
),
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;
430 /* Initialize the Rx refill retry timer */
431 setup_timer(timer
, ath10k_htt_rx_ring_refill_retry
, (unsigned long)htt
);
433 spin_lock_init(&htt
->rx_ring
.lock
);
435 htt
->rx_ring
.fill_cnt
= 0;
436 if (__ath10k_htt_rx_ring_fill_n(htt
, htt
->rx_ring
.fill_level
))
439 tasklet_init(&htt
->rx_replenish_task
, ath10k_htt_rx_replenish_task
,
442 skb_queue_head_init(&htt
->tx_compl_q
);
443 skb_queue_head_init(&htt
->rx_compl_q
);
445 tasklet_init(&htt
->txrx_compl_task
, ath10k_htt_txrx_compl_task
,
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
);
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
);
459 dma_free_coherent(htt
->ar
->dev
,
461 sizeof(htt
->rx_ring
.paddrs_ring
)),
462 htt
->rx_ring
.paddrs_ring
,
463 htt
->rx_ring
.base_paddr
);
465 kfree(htt
->rx_ring
.netbufs_ring
);
470 static int ath10k_htt_rx_crypto_param_len(struct ath10k
*ar
,
471 enum htt_rx_mpdu_encrypt_type type
)
474 case HTT_RX_MPDU_ENCRYPT_NONE
:
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
:
489 ath10k_warn(ar
, "unsupported encryption type %d\n", type
);
493 #define MICHAEL_MIC_LEN 8
495 static int ath10k_htt_rx_crypto_tail_len(struct ath10k
*ar
,
496 enum htt_rx_mpdu_encrypt_type type
)
499 case HTT_RX_MPDU_ENCRYPT_NONE
:
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
:
514 ath10k_warn(ar
, "unsupported encryption type %d\n", type
);
526 struct amsdu_subframe_hdr
{
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 */
551 static void ath10k_htt_rx_h_rates(struct ath10k
*ar
,
552 struct ieee80211_rx_status
*status
,
553 struct htt_rx_desc
*rxd
)
555 enum ieee80211_band band
;
556 u8 cck
, rate
, rate_idx
, bw
, sgi
, mcs
, nss
;
558 u32 info1
, info2
, info3
;
560 /* Band value can't be set as undefined but freq can be 0 - use that to
561 * determine whether band is provided.
563 * FIXME: Perhaps this can go away if CCK rate reporting is a little
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
);
574 preamble
= MS(info1
, RX_PPDU_START_INFO1_PREAMBLE_TYPE
);
578 cck
= info1
& RX_PPDU_START_INFO1_L_SIG_RATE_SELECT
;
579 rate
= MS(info1
, RX_PPDU_START_INFO1_L_SIG_RATE
);
582 if (rate
< 0x08 || rate
> 0x0F)
586 case IEEE80211_BAND_2GHZ
:
589 rate_idx
= rx_legacy_rate_idx
[rate
];
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 */
602 status
->rate_idx
= rate_idx
;
605 case HTT_RX_HT_WITH_TXBF
:
606 /* HT-SIG - Table 20-11 in info2 and info3 */
609 bw
= (info2
>> 7) & 1;
610 sgi
= (info3
>> 7) & 1;
612 status
->rate_idx
= mcs
;
613 status
->flag
|= RX_FLAG_HT
;
615 status
->flag
|= RX_FLAG_SHORT_GI
;
617 status
->flag
|= RX_FLAG_40MHZ
;
620 case HTT_RX_VHT_WITH_TXBF
:
621 /* VHT-SIG-A1 in info2, VHT-SIG-A2 in info3
623 mcs
= (info3
>> 4) & 0x0F;
624 nss
= ((info2
>> 10) & 0x07) + 1;
628 status
->rate_idx
= mcs
;
629 status
->vht_nss
= nss
;
632 status
->flag
|= RX_FLAG_SHORT_GI
;
640 status
->flag
|= RX_FLAG_40MHZ
;
644 status
->vht_flag
|= RX_VHT_FLAG_80MHZ
;
647 status
->flag
|= RX_FLAG_VHT
;
654 static bool ath10k_htt_rx_h_channel(struct ath10k
*ar
,
655 struct ieee80211_rx_status
*status
)
657 struct ieee80211_channel
*ch
;
659 spin_lock_bh(&ar
->data_lock
);
660 ch
= ar
->scan_channel
;
663 spin_unlock_bh(&ar
->data_lock
);
668 status
->band
= ch
->band
;
669 status
->freq
= ch
->center_freq
;
674 static void ath10k_htt_rx_h_signal(struct ath10k
*ar
,
675 struct ieee80211_rx_status
*status
,
676 struct htt_rx_desc
*rxd
)
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
;
684 static void ath10k_htt_rx_h_mactime(struct ath10k
*ar
,
685 struct ieee80211_rx_status
*status
,
686 struct htt_rx_desc
*rxd
)
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?
692 * FIXME: Can we get/compute 64bit TSF?
694 status
->mactime
= __le32_to_cpu(rxd
->ppdu_end
.tsf_timestamp
);
695 status
->flag
|= RX_FLAG_MACTIME_END
;
698 static void ath10k_htt_rx_h_ppdu(struct ath10k
*ar
,
699 struct sk_buff_head
*amsdu
,
700 struct ieee80211_rx_status
*status
)
702 struct sk_buff
*first
;
703 struct htt_rx_desc
*rxd
;
707 if (skb_queue_empty(amsdu
))
710 first
= skb_peek(amsdu
);
711 rxd
= (void *)first
->data
- sizeof(*rxd
);
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
));
719 /* New PPDU starts so clear out the old per-PPDU status. */
721 status
->rate_idx
= 0;
723 status
->vht_flag
&= ~RX_VHT_FLAG_80MHZ
;
724 status
->flag
&= ~(RX_FLAG_HT
|
728 RX_FLAG_MACTIME_END
);
729 status
->flag
|= RX_FLAG_NO_SIGNAL_VAL
;
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
);
737 ath10k_htt_rx_h_mactime(ar
, status
, rxd
);
740 static const char * const tid_to_ac
[] = {
751 static char *ath10k_get_tid(struct ieee80211_hdr
*hdr
, char *out
, size_t size
)
756 if (!ieee80211_is_data_qos(hdr
->frame_control
))
759 qc
= ieee80211_get_qos_ctl(hdr
);
760 tid
= *qc
& IEEE80211_QOS_CTL_TID_MASK
;
762 snprintf(out
, size
, "tid %d (%s)", tid
, tid_to_ac
[tid
]);
764 snprintf(out
, size
, "tid %d", tid
);
769 static void ath10k_process_rx(struct ath10k
*ar
,
770 struct ieee80211_rx_status
*rx_status
,
773 struct ieee80211_rx_status
*status
;
774 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
777 status
= IEEE80211_SKB_RXCB(skb
);
778 *status
= *rx_status
;
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",
784 ieee80211_get_SA(hdr
),
785 ath10k_get_tid(hdr
, tid
, sizeof(tid
)),
786 is_multicast_ether_addr(ieee80211_get_DA(hdr
)) ?
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 " : "",
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
);
807 ieee80211_rx(ar
->hw
, skb
);
810 static int ath10k_htt_rx_nwifi_hdrlen(struct ieee80211_hdr
*hdr
)
812 /* nwifi header is padded to 4 bytes. this fixes 4addr rx */
813 return round_up(ieee80211_hdrlen(hdr
->frame_control
), 4);
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
,
822 struct ieee80211_hdr
*hdr
;
823 struct htt_rx_desc
*rxd
;
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
));
835 /* Delivered decapped frame:
837 * [crypto param] <-- can be trimmed if !fcs_err &&
838 * !decrypt_err && !peer_idx_invalid
839 * [amsdu header] <-- only if A-MSDU
842 * [FCS] <-- at end, needs to be trimmed
845 /* This probably shouldn't happen but warn just in case */
846 if (unlikely(WARN_ON_ONCE(!is_first
)))
849 /* This probably shouldn't happen but warn just in case */
850 if (unlikely(WARN_ON_ONCE(!(is_first
&& is_last
))))
853 skb_trim(msdu
, msdu
->len
- FCS_LEN
);
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).
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.
866 /* The payload is decrypted so strip crypto params. Start from tail
867 * since hdr is used to compute some stuff.
870 hdr
= (void *)msdu
->data
;
873 skb_trim(msdu
, msdu
->len
- ath10k_htt_rx_crypto_tail_len(ar
, enctype
));
876 if (!ieee80211_has_morefrags(hdr
->frame_control
) &&
877 enctype
== HTT_RX_MPDU_ENCRYPT_TKIP_WPA
)
878 skb_trim(msdu
, msdu
->len
- 8);
881 hdr_len
= ieee80211_hdrlen(hdr
->frame_control
);
882 crypto_len
= ath10k_htt_rx_crypto_param_len(ar
, enctype
);
884 memmove((void *)msdu
->data
+ crypto_len
,
885 (void *)msdu
->data
, hdr_len
);
886 skb_pull(msdu
, crypto_len
);
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])
894 struct ieee80211_hdr
*hdr
;
899 /* Delivered decapped frame:
900 * [nwifi 802.11 header] <-- replaced with 802.11 hdr
903 * Note: The nwifi header doesn't have QoS Control and is
904 * (always?) a 3addr frame.
906 * Note2: There's no A-MSDU subframe header. Even if it's part
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
);
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
);
922 /* original 802.11 header has a different DA and in
923 * case of 4addr it may also have different SA
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
);
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
)
934 struct ieee80211_hdr
*hdr
;
935 struct htt_rx_desc
*rxd
;
936 size_t hdr_len
, crypto_len
;
938 bool is_first
, is_last
, is_amsdu
;
940 rxd
= (void *)msdu
->data
- sizeof(*rxd
);
941 hdr
= (void *)rxd
->rx_hdr_status
;
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
);
952 hdr_len
= ieee80211_hdrlen(hdr
->frame_control
);
953 crypto_len
= ath10k_htt_rx_crypto_param_len(ar
, enctype
);
955 rfc1042
+= round_up(hdr_len
, 4) +
956 round_up(crypto_len
, 4);
960 rfc1042
+= sizeof(struct amsdu_subframe_hdr
);
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
)
971 struct ieee80211_hdr
*hdr
;
978 /* Delivered decapped frame:
979 * [eth header] <-- replaced with 802.11 hdr & rfc1042/llc
983 rfc1042
= ath10k_htt_rx_h_find_rfc1042(ar
, msdu
, enctype
);
984 if (WARN_ON_ONCE(!rfc1042
))
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
));
993 /* push rfc1042/llc/snap */
994 memcpy(skb_push(msdu
, sizeof(struct rfc1042_hdr
)), rfc1042
,
995 sizeof(struct rfc1042_hdr
));
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
);
1002 /* original 802.11 header has a different DA and in
1003 * case of 4addr it may also have different SA
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
);
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])
1015 struct ieee80211_hdr
*hdr
;
1018 /* Delivered decapped frame:
1019 * [amsdu header] <-- replaced with 802.11 hdr
1024 skb_pull(msdu
, sizeof(struct amsdu_subframe_hdr
));
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
);
1031 static void ath10k_htt_rx_h_undecap(struct ath10k
*ar
,
1032 struct sk_buff
*msdu
,
1033 struct ieee80211_rx_status
*status
,
1035 enum htt_rx_mpdu_encrypt_type enctype
,
1038 struct htt_rx_desc
*rxd
;
1039 enum rx_msdu_decap_format decap
;
1040 struct ieee80211_hdr
*hdr
;
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
1048 * Other (2nd, 3rd, ..) msdu's decapped header:
1049 * [amsdu header] <-- only if A-MSDU
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
);
1059 case RX_MSDU_DECAP_RAW
:
1060 ath10k_htt_rx_h_undecap_raw(ar
, msdu
, status
, enctype
,
1063 case RX_MSDU_DECAP_NATIVE_WIFI
:
1064 ath10k_htt_rx_h_undecap_nwifi(ar
, msdu
, status
, first_hdr
);
1066 case RX_MSDU_DECAP_ETHERNET2_DIX
:
1067 ath10k_htt_rx_h_undecap_eth(ar
, msdu
, status
, first_hdr
, enctype
);
1069 case RX_MSDU_DECAP_8023_SNAP_LLC
:
1070 ath10k_htt_rx_h_undecap_snap(ar
, msdu
, status
, first_hdr
);
1075 static int ath10k_htt_rx_get_csum_state(struct sk_buff
*skb
)
1077 struct htt_rx_desc
*rxd
;
1079 bool is_ip4
, is_ip6
;
1080 bool is_tcp
, is_udp
;
1081 bool ip_csum_ok
, tcpudp_csum_ok
;
1083 rxd
= (void *)skb
->data
- sizeof(*rxd
);
1084 flags
= __le32_to_cpu(rxd
->attention
.flags
);
1085 info
= __le32_to_cpu(rxd
->msdu_start
.info1
);
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
);
1094 if (!is_ip4
&& !is_ip6
)
1095 return CHECKSUM_NONE
;
1096 if (!is_tcp
&& !is_udp
)
1097 return CHECKSUM_NONE
;
1099 return CHECKSUM_NONE
;
1100 if (!tcpudp_csum_ok
)
1101 return CHECKSUM_NONE
;
1103 return CHECKSUM_UNNECESSARY
;
1106 static void ath10k_htt_rx_h_csum_offload(struct sk_buff
*msdu
)
1108 msdu
->ip_summed
= ath10k_htt_rx_get_csum_state(msdu
);
1111 static void ath10k_htt_rx_h_mpdu(struct ath10k
*ar
,
1112 struct sk_buff_head
*amsdu
,
1113 struct ieee80211_rx_status
*status
)
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
;
1125 bool has_crypto_err
;
1127 bool has_peer_idx_invalid
;
1131 if (skb_queue_empty(amsdu
))
1134 first
= skb_peek(amsdu
);
1135 rxd
= (void *)first
->data
- sizeof(*rxd
);
1137 enctype
= MS(__le32_to_cpu(rxd
->mpdu_start
.info0
),
1138 RX_MPDU_START_INFO0_ENCRYPT_TYPE
);
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.
1143 hdr
= (void *)rxd
->rx_hdr_status
;
1144 hdr_len
= ieee80211_hdrlen(hdr
->frame_control
);
1145 memcpy(first_hdr
, hdr
, hdr_len
);
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.
1150 hdr
= (void *)first_hdr
;
1151 qos
= ieee80211_get_qos_ctl(hdr
);
1152 qos
[0] &= ~IEEE80211_QOS_CTL_A_MSDU_PRESENT
;
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
);
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
);
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.
1168 is_decrypted
= (enctype
!= HTT_RX_MPDU_ENCRYPT_NONE
&&
1171 !has_peer_idx_invalid
);
1173 /* Clear per-MPDU flags while leaving per-PPDU flags intact. */
1174 status
->flag
&= ~(RX_FLAG_FAILED_FCS_CRC
|
1175 RX_FLAG_MMIC_ERROR
|
1177 RX_FLAG_IV_STRIPPED
|
1178 RX_FLAG_MMIC_STRIPPED
);
1181 status
->flag
|= RX_FLAG_FAILED_FCS_CRC
;
1184 status
->flag
|= RX_FLAG_MMIC_ERROR
;
1187 status
->flag
|= RX_FLAG_DECRYPTED
|
1188 RX_FLAG_IV_STRIPPED
|
1189 RX_FLAG_MMIC_STRIPPED
;
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
,
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.
1203 hdr
= (void *)msdu
->data
;
1204 hdr
->frame_control
&= ~__cpu_to_le16(IEEE80211_FCTL_PROTECTED
);
1208 static void ath10k_htt_rx_h_deliver(struct ath10k
*ar
,
1209 struct sk_buff_head
*amsdu
,
1210 struct ieee80211_rx_status
*status
)
1212 struct sk_buff
*msdu
;
1214 while ((msdu
= __skb_dequeue(amsdu
))) {
1215 /* Setup per-MSDU flags */
1216 if (skb_queue_empty(amsdu
))
1217 status
->flag
&= ~RX_FLAG_AMSDU_MORE
;
1219 status
->flag
|= RX_FLAG_AMSDU_MORE
;
1221 ath10k_process_rx(ar
, status
, msdu
);
1225 static int ath10k_unchain_msdu(struct sk_buff_head
*amsdu
)
1227 struct sk_buff
*skb
, *first
;
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
1238 first
= __skb_dequeue(amsdu
);
1240 /* Allocate total length all at once. */
1241 skb_queue_walk(amsdu
, skb
)
1242 total_len
+= skb
->len
;
1244 space
= total_len
- skb_tailroom(first
);
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.
1251 __skb_queue_head(amsdu
, first
);
1255 /* Walk list again, copying contents into
1258 while ((skb
= __skb_dequeue(amsdu
))) {
1259 skb_copy_from_linear_data(skb
, skb_put(first
, skb
->len
),
1261 dev_kfree_skb_any(skb
);
1264 __skb_queue_head(amsdu
, first
);
1268 static void ath10k_htt_rx_h_unchain(struct ath10k
*ar
,
1269 struct sk_buff_head
*amsdu
,
1272 struct sk_buff
*first
;
1273 struct htt_rx_desc
*rxd
;
1274 enum rx_msdu_decap_format decap
;
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
);
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.
1289 if (decap
!= RX_MSDU_DECAP_RAW
||
1290 skb_queue_len(amsdu
) != 1 + rxd
->frag_info
.ring2_more_count
) {
1291 __skb_queue_purge(amsdu
);
1295 ath10k_unchain_msdu(amsdu
);
1298 static bool ath10k_htt_rx_amsdu_allowed(struct ath10k
*ar
,
1299 struct sk_buff_head
*amsdu
,
1300 struct ieee80211_rx_status
*rx_status
)
1302 struct sk_buff
*msdu
;
1303 struct htt_rx_desc
*rxd
;
1307 msdu
= skb_peek(amsdu
);
1308 rxd
= (void *)msdu
->data
- sizeof(*rxd
);
1310 /* FIXME: It might be a good idea to do some fuzzy-testing to drop
1311 * invalid/dangerous frames.
1314 if (!rx_status
->freq
) {
1315 ath10k_warn(ar
, "no channel configured; ignoring frame(s)!\n");
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
));
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.
1328 * However some firmware revisions don't report corrupted frames via
1329 * WMI so don't drop them.
1331 if (is_mgmt
&& !has_fcs_err
) {
1332 ath10k_dbg(ar
, ATH10K_DBG_HTT
, "htt rx mgmt ctrl\n");
1336 if (test_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
)) {
1337 ath10k_dbg(ar
, ATH10K_DBG_HTT
, "htt rx cac running\n");
1344 static void ath10k_htt_rx_h_filter(struct ath10k
*ar
,
1345 struct sk_buff_head
*amsdu
,
1346 struct ieee80211_rx_status
*rx_status
)
1348 if (skb_queue_empty(amsdu
))
1351 if (ath10k_htt_rx_amsdu_allowed(ar
, amsdu
, rx_status
))
1354 __skb_queue_purge(amsdu
);
1357 static void ath10k_htt_rx_handler(struct ath10k_htt
*htt
,
1358 struct htt_rx_indication
*rx
)
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
;
1367 int i
, ret
, mpdu_count
= 0;
1369 lockdep_assert_held(&htt
->rx_ring
.lock
);
1371 if (htt
->rx_confused
)
1374 fw_desc_len
= __le16_to_cpu(rx
->prefix
.fw_rx_desc_bytes
);
1375 fw_desc
= (u8
*)&rx
->fw_desc
;
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
);
1381 ath10k_dbg_dump(ar
, ATH10K_DBG_HTT_DUMP
, NULL
, "htt rx ind: ",
1383 (sizeof(struct htt_rx_indication_mpdu_range
) *
1386 for (i
= 0; i
< num_mpdu_ranges
; i
++)
1387 mpdu_count
+= mpdu_ranges
[i
].mpdu_count
;
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
);
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.
1399 htt
->rx_confused
= true;
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
);
1410 tasklet_schedule(&htt
->rx_replenish_task
);
1413 static void ath10k_htt_rx_frag_handler(struct ath10k_htt
*htt
,
1414 struct htt_rx_fragment_indication
*frag
)
1416 struct ath10k
*ar
= htt
->ar
;
1417 struct ieee80211_rx_status
*rx_status
= &htt
->rx_status
;
1418 struct sk_buff_head amsdu
;
1423 fw_desc_len
= __le16_to_cpu(frag
->fw_rx_desc_bytes
);
1424 fw_desc
= (u8
*)frag
->fw_msdu_rx_desc
;
1426 __skb_queue_head_init(&amsdu
);
1428 spin_lock_bh(&htt
->rx_ring
.lock
);
1429 ret
= ath10k_htt_rx_amsdu_pop(htt
, &fw_desc
, &fw_desc_len
,
1431 spin_unlock_bh(&htt
->rx_ring
.lock
);
1433 tasklet_schedule(&htt
->rx_replenish_task
);
1435 ath10k_dbg(ar
, ATH10K_DBG_HTT_DUMP
, "htt rx frag ahead\n");
1438 ath10k_warn(ar
, "failed to pop amsdu from httr rx ring for fragmented rx %d\n",
1440 __skb_queue_purge(&amsdu
);
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
);
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
);
1455 if (fw_desc_len
> 0) {
1456 ath10k_dbg(ar
, ATH10K_DBG_HTT
,
1457 "expecting more fragmented rx in one indication %d\n",
1462 static void ath10k_htt_rx_frm_tx_compl(struct ath10k
*ar
,
1463 struct sk_buff
*skb
)
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
);
1472 lockdep_assert_held(&htt
->tx_lock
);
1475 case HTT_DATA_TX_STATUS_NO_ACK
:
1476 tx_done
.no_ack
= true;
1478 case HTT_DATA_TX_STATUS_OK
:
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;
1486 ath10k_warn(ar
, "unhandled tx completion status %d\n", status
);
1487 tx_done
.discard
= true;
1491 ath10k_dbg(ar
, ATH10K_DBG_HTT
, "htt tx completion num_msdus %d\n",
1492 resp
->data_tx_completion
.num_msdus
);
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
);
1501 static void ath10k_htt_rx_addba(struct ath10k
*ar
, struct htt_resp
*resp
)
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
;
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
);
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
);
1516 spin_lock_bh(&ar
->data_lock
);
1517 peer
= ath10k_peer_find_by_id(ar
, peer_id
);
1519 ath10k_warn(ar
, "received addba event for invalid peer_id: %hu\n",
1521 spin_unlock_bh(&ar
->data_lock
);
1525 arvif
= ath10k_get_arvif(ar
, peer
->vdev_id
);
1527 ath10k_warn(ar
, "received addba event for invalid vdev_id: %u\n",
1529 spin_unlock_bh(&ar
->data_lock
);
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
);
1537 ieee80211_start_rx_ba_session_offl(arvif
->vif
, peer
->addr
, tid
);
1538 spin_unlock_bh(&ar
->data_lock
);
1541 static void ath10k_htt_rx_delba(struct ath10k
*ar
, struct htt_resp
*resp
)
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
;
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
);
1552 ath10k_dbg(ar
, ATH10K_DBG_HTT
,
1553 "htt rx delba tid %hu peer_id %hu\n",
1556 spin_lock_bh(&ar
->data_lock
);
1557 peer
= ath10k_peer_find_by_id(ar
, peer_id
);
1559 ath10k_warn(ar
, "received addba event for invalid peer_id: %hu\n",
1561 spin_unlock_bh(&ar
->data_lock
);
1565 arvif
= ath10k_get_arvif(ar
, peer
->vdev_id
);
1567 ath10k_warn(ar
, "received addba event for invalid vdev_id: %u\n",
1569 spin_unlock_bh(&ar
->data_lock
);
1573 ath10k_dbg(ar
, ATH10K_DBG_HTT
,
1574 "htt rx stop rx ba session sta %pM tid %hu\n",
1577 ieee80211_stop_rx_ba_session_offl(arvif
->vif
, peer
->addr
, tid
);
1578 spin_unlock_bh(&ar
->data_lock
);
1581 void ath10k_htt_t2h_msg_handler(struct ath10k
*ar
, struct sk_buff
*skb
)
1583 struct ath10k_htt
*htt
= &ar
->htt
;
1584 struct htt_resp
*resp
= (struct htt_resp
*)skb
->data
;
1586 /* confirm alignment */
1587 if (!IS_ALIGNED((unsigned long)skb
->data
, 4))
1588 ath10k_warn(ar
, "unaligned htt message, expect trouble\n");
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
);
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
);
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
),
1610 memcpy(ev
.addr
, resp
->peer_map
.addr
, sizeof(ev
.addr
));
1611 ath10k_peer_map_event(htt
, &ev
);
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
),
1618 ath10k_peer_unmap_event(htt
, &ev
);
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
);
1626 __le32_to_cpu(resp
->mgmt_tx_completion
.desc_id
);
1629 case HTT_MGMT_TX_STATUS_OK
:
1631 case HTT_MGMT_TX_STATUS_RETRY
:
1632 tx_done
.no_ack
= true;
1634 case HTT_MGMT_TX_STATUS_DROP
:
1635 tx_done
.discard
= true;
1639 spin_lock_bh(&htt
->tx_lock
);
1640 ath10k_txrx_tx_unref(htt
, &tx_done
);
1641 spin_unlock_bh(&htt
->tx_lock
);
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
);
1650 case HTT_T2H_MSG_TYPE_SEC_IND
: {
1651 struct ath10k
*ar
= htt
->ar
;
1652 struct htt_security_indication
*ev
= &resp
->security_indication
;
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
);
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
);
1668 case HTT_T2H_MSG_TYPE_TEST
:
1671 case HTT_T2H_MSG_TYPE_STATS_CONF
:
1672 trace_ath10k_htt_stats(ar
, skb
->data
, skb
->len
);
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.
1680 ath10k_warn(ar
, "received an unexpected htt tx inspect event\n");
1682 case HTT_T2H_MSG_TYPE_RX_ADDBA
:
1683 ath10k_htt_rx_addba(ar
, resp
);
1685 case HTT_T2H_MSG_TYPE_RX_DELBA
:
1686 ath10k_htt_rx_delba(ar
, resp
);
1688 case HTT_T2H_MSG_TYPE_PKTLOG
: {
1689 struct ath10k_pktlog_hdr
*hdr
=
1690 (struct ath10k_pktlog_hdr
*)resp
->pktlog_msg
.payload
;
1692 trace_ath10k_htt_pktlog(ar
, resp
->pktlog_msg
.payload
,
1694 __le16_to_cpu(hdr
->size
));
1697 case HTT_T2H_MSG_TYPE_RX_FLUSH
: {
1698 /* Ignore this event because mac80211 takes care of Rx
1699 * aggregation reordering.
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
);
1711 /* Free the indication buffer */
1712 dev_kfree_skb_any(skb
);
1715 static void ath10k_htt_txrx_compl_task(unsigned long ptr
)
1717 struct ath10k_htt
*htt
= (struct ath10k_htt
*)ptr
;
1718 struct htt_resp
*resp
;
1719 struct sk_buff
*skb
;
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
);
1726 spin_unlock_bh(&htt
->tx_lock
);
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
);
1734 spin_unlock_bh(&htt
->rx_ring
.lock
);