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 HTT_RX_RING_SIZE_MAX
29 #define HTT_RX_RING_FILL_LEVEL (((HTT_RX_RING_SIZE) / 2) - 1)
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 struct sk_buff *
38 ath10k_htt_rx_find_skb_paddr(struct ath10k *ar, u32 paddr)
40 struct ath10k_skb_rxcb *rxcb;
42 hash_for_each_possible(ar->htt.rx_ring.skb_table, rxcb, hlist, paddr)
43 if (rxcb->paddr == paddr)
44 return ATH10K_RXCB_SKB(rxcb);
50 static void ath10k_htt_rx_ring_free(struct ath10k_htt *htt)
53 struct ath10k_skb_rxcb *rxcb;
57 if (htt->rx_ring.in_ord_rx) {
58 hash_for_each_safe(htt->rx_ring.skb_table, i, n, rxcb, hlist) {
59 skb = ATH10K_RXCB_SKB(rxcb);
60 dma_unmap_single(htt->ar->dev, rxcb->paddr,
61 skb->len + skb_tailroom(skb),
63 hash_del(&rxcb->hlist);
64 dev_kfree_skb_any(skb);
67 for (i = 0; i < htt->rx_ring.size; i++) {
68 skb = htt->rx_ring.netbufs_ring[i];
72 rxcb = ATH10K_SKB_RXCB(skb);
73 dma_unmap_single(htt->ar->dev, rxcb->paddr,
74 skb->len + skb_tailroom(skb),
76 dev_kfree_skb_any(skb);
80 htt->rx_ring.fill_cnt = 0;
81 hash_init(htt->rx_ring.skb_table);
82 memset(htt->rx_ring.netbufs_ring, 0,
83 htt->rx_ring.size * sizeof(htt->rx_ring.netbufs_ring[0]));
86 static int __ath10k_htt_rx_ring_fill_n(struct ath10k_htt *htt, int num)
88 struct htt_rx_desc *rx_desc;
89 struct ath10k_skb_rxcb *rxcb;
94 /* The Full Rx Reorder firmware has no way of telling the host
95 * implicitly when it copied HTT Rx Ring buffers to MAC Rx Ring.
96 * To keep things simple make sure ring is always half empty. This
97 * guarantees there'll be no replenishment overruns possible.
99 BUILD_BUG_ON(HTT_RX_RING_FILL_LEVEL >= HTT_RX_RING_SIZE / 2);
101 idx = __le32_to_cpu(*htt->rx_ring.alloc_idx.vaddr);
103 skb = dev_alloc_skb(HTT_RX_BUF_SIZE + HTT_RX_DESC_ALIGN);
109 if (!IS_ALIGNED((unsigned long)skb->data, HTT_RX_DESC_ALIGN))
111 PTR_ALIGN(skb->data, HTT_RX_DESC_ALIGN) -
114 /* Clear rx_desc attention word before posting to Rx ring */
115 rx_desc = (struct htt_rx_desc *)skb->data;
116 rx_desc->attention.flags = __cpu_to_le32(0);
118 paddr = dma_map_single(htt->ar->dev, skb->data,
119 skb->len + skb_tailroom(skb),
122 if (unlikely(dma_mapping_error(htt->ar->dev, paddr))) {
123 dev_kfree_skb_any(skb);
128 rxcb = ATH10K_SKB_RXCB(skb);
130 htt->rx_ring.netbufs_ring[idx] = skb;
131 htt->rx_ring.paddrs_ring[idx] = __cpu_to_le32(paddr);
132 htt->rx_ring.fill_cnt++;
134 if (htt->rx_ring.in_ord_rx) {
135 hash_add(htt->rx_ring.skb_table,
136 &ATH10K_SKB_RXCB(skb)->hlist,
142 idx &= htt->rx_ring.size_mask;
147 * Make sure the rx buffer is updated before available buffer
148 * index to avoid any potential rx ring corruption.
151 *htt->rx_ring.alloc_idx.vaddr = __cpu_to_le32(idx);
155 static int ath10k_htt_rx_ring_fill_n(struct ath10k_htt *htt, int num)
157 lockdep_assert_held(&htt->rx_ring.lock);
158 return __ath10k_htt_rx_ring_fill_n(htt, num);
161 static void ath10k_htt_rx_msdu_buff_replenish(struct ath10k_htt *htt)
163 int ret, num_deficit, num_to_fill;
165 /* Refilling the whole RX ring buffer proves to be a bad idea. The
166 * reason is RX may take up significant amount of CPU cycles and starve
167 * other tasks, e.g. TX on an ethernet device while acting as a bridge
168 * with ath10k wlan interface. This ended up with very poor performance
169 * once CPU the host system was overwhelmed with RX on ath10k.
171 * By limiting the number of refills the replenishing occurs
172 * progressively. This in turns makes use of the fact tasklets are
173 * processed in FIFO order. This means actual RX processing can starve
174 * out refilling. If there's not enough buffers on RX ring FW will not
175 * report RX until it is refilled with enough buffers. This
176 * automatically balances load wrt to CPU power.
178 * This probably comes at a cost of lower maximum throughput but
179 * improves the average and stability. */
180 spin_lock_bh(&htt->rx_ring.lock);
181 num_deficit = htt->rx_ring.fill_level - htt->rx_ring.fill_cnt;
182 num_to_fill = min(ATH10K_HTT_MAX_NUM_REFILL, num_deficit);
183 num_deficit -= num_to_fill;
184 ret = ath10k_htt_rx_ring_fill_n(htt, num_to_fill);
185 if (ret == -ENOMEM) {
187 * Failed to fill it to the desired level -
188 * we'll start a timer and try again next time.
189 * As long as enough buffers are left in the ring for
190 * another A-MPDU rx, no special recovery is needed.
192 mod_timer(&htt->rx_ring.refill_retry_timer, jiffies +
193 msecs_to_jiffies(HTT_RX_RING_REFILL_RETRY_MS));
194 } else if (num_deficit > 0) {
195 tasklet_schedule(&htt->rx_replenish_task);
197 spin_unlock_bh(&htt->rx_ring.lock);
200 static void ath10k_htt_rx_ring_refill_retry(unsigned long arg)
202 struct ath10k_htt *htt = (struct ath10k_htt *)arg;
204 ath10k_htt_rx_msdu_buff_replenish(htt);
207 int ath10k_htt_rx_ring_refill(struct ath10k *ar)
209 struct ath10k_htt *htt = &ar->htt;
212 spin_lock_bh(&htt->rx_ring.lock);
213 ret = ath10k_htt_rx_ring_fill_n(htt, (htt->rx_ring.fill_level -
214 htt->rx_ring.fill_cnt));
215 spin_unlock_bh(&htt->rx_ring.lock);
218 ath10k_htt_rx_ring_free(htt);
223 void ath10k_htt_rx_free(struct ath10k_htt *htt)
225 del_timer_sync(&htt->rx_ring.refill_retry_timer);
226 tasklet_kill(&htt->rx_replenish_task);
227 tasklet_kill(&htt->txrx_compl_task);
229 skb_queue_purge(&htt->rx_compl_q);
230 skb_queue_purge(&htt->rx_in_ord_compl_q);
231 skb_queue_purge(&htt->tx_fetch_ind_q);
233 ath10k_htt_rx_ring_free(htt);
235 dma_free_coherent(htt->ar->dev,
237 sizeof(htt->rx_ring.paddrs_ring)),
238 htt->rx_ring.paddrs_ring,
239 htt->rx_ring.base_paddr);
241 dma_free_coherent(htt->ar->dev,
242 sizeof(*htt->rx_ring.alloc_idx.vaddr),
243 htt->rx_ring.alloc_idx.vaddr,
244 htt->rx_ring.alloc_idx.paddr);
246 kfree(htt->rx_ring.netbufs_ring);
249 static inline struct sk_buff *ath10k_htt_rx_netbuf_pop(struct ath10k_htt *htt)
251 struct ath10k *ar = htt->ar;
253 struct sk_buff *msdu;
255 lockdep_assert_held(&htt->rx_ring.lock);
257 if (htt->rx_ring.fill_cnt == 0) {
258 ath10k_warn(ar, "tried to pop sk_buff from an empty rx ring\n");
262 idx = htt->rx_ring.sw_rd_idx.msdu_payld;
263 msdu = htt->rx_ring.netbufs_ring[idx];
264 htt->rx_ring.netbufs_ring[idx] = NULL;
265 htt->rx_ring.paddrs_ring[idx] = 0;
268 idx &= htt->rx_ring.size_mask;
269 htt->rx_ring.sw_rd_idx.msdu_payld = idx;
270 htt->rx_ring.fill_cnt--;
272 dma_unmap_single(htt->ar->dev,
273 ATH10K_SKB_RXCB(msdu)->paddr,
274 msdu->len + skb_tailroom(msdu),
276 ath10k_dbg_dump(ar, ATH10K_DBG_HTT_DUMP, NULL, "htt rx netbuf pop: ",
277 msdu->data, msdu->len + skb_tailroom(msdu));
282 /* return: < 0 fatal error, 0 - non chained msdu, 1 chained msdu */
283 static int ath10k_htt_rx_amsdu_pop(struct ath10k_htt *htt,
284 struct sk_buff_head *amsdu)
286 struct ath10k *ar = htt->ar;
287 int msdu_len, msdu_chaining = 0;
288 struct sk_buff *msdu;
289 struct htt_rx_desc *rx_desc;
291 lockdep_assert_held(&htt->rx_ring.lock);
294 int last_msdu, msdu_len_invalid, msdu_chained;
296 msdu = ath10k_htt_rx_netbuf_pop(htt);
298 __skb_queue_purge(amsdu);
302 __skb_queue_tail(amsdu, msdu);
304 rx_desc = (struct htt_rx_desc *)msdu->data;
306 /* FIXME: we must report msdu payload since this is what caller
308 skb_put(msdu, offsetof(struct htt_rx_desc, msdu_payload));
309 skb_pull(msdu, offsetof(struct htt_rx_desc, msdu_payload));
312 * Sanity check - confirm the HW is finished filling in the
314 * If the HW and SW are working correctly, then it's guaranteed
315 * that the HW's MAC DMA is done before this point in the SW.
316 * To prevent the case that we handle a stale Rx descriptor,
317 * just assert for now until we have a way to recover.
319 if (!(__le32_to_cpu(rx_desc->attention.flags)
320 & RX_ATTENTION_FLAGS_MSDU_DONE)) {
321 __skb_queue_purge(amsdu);
325 msdu_len_invalid = !!(__le32_to_cpu(rx_desc->attention.flags)
326 & (RX_ATTENTION_FLAGS_MPDU_LENGTH_ERR |
327 RX_ATTENTION_FLAGS_MSDU_LENGTH_ERR));
328 msdu_len = MS(__le32_to_cpu(rx_desc->msdu_start.common.info0),
329 RX_MSDU_START_INFO0_MSDU_LENGTH);
330 msdu_chained = rx_desc->frag_info.ring2_more_count;
332 if (msdu_len_invalid)
336 skb_put(msdu, min(msdu_len, HTT_RX_MSDU_SIZE));
337 msdu_len -= msdu->len;
339 /* Note: Chained buffers do not contain rx descriptor */
340 while (msdu_chained--) {
341 msdu = ath10k_htt_rx_netbuf_pop(htt);
343 __skb_queue_purge(amsdu);
347 __skb_queue_tail(amsdu, msdu);
349 skb_put(msdu, min(msdu_len, HTT_RX_BUF_SIZE));
350 msdu_len -= msdu->len;
354 last_msdu = __le32_to_cpu(rx_desc->msdu_end.common.info0) &
355 RX_MSDU_END_INFO0_LAST_MSDU;
357 trace_ath10k_htt_rx_desc(ar, &rx_desc->attention,
358 sizeof(*rx_desc) - sizeof(u32));
364 if (skb_queue_empty(amsdu))
368 * Don't refill the ring yet.
370 * First, the elements popped here are still in use - it is not
371 * safe to overwrite them until the matching call to
372 * mpdu_desc_list_next. Second, for efficiency it is preferable to
373 * refill the rx ring with 1 PPDU's worth of rx buffers (something
374 * like 32 x 3 buffers), rather than one MPDU's worth of rx buffers
375 * (something like 3 buffers). Consequently, we'll rely on the txrx
376 * SW to tell us when it is done pulling all the PPDU's rx buffers
377 * out of the rx ring, and then refill it just once.
380 return msdu_chaining;
383 static void ath10k_htt_rx_replenish_task(unsigned long ptr)
385 struct ath10k_htt *htt = (struct ath10k_htt *)ptr;
387 ath10k_htt_rx_msdu_buff_replenish(htt);
390 static struct sk_buff *ath10k_htt_rx_pop_paddr(struct ath10k_htt *htt,
393 struct ath10k *ar = htt->ar;
394 struct ath10k_skb_rxcb *rxcb;
395 struct sk_buff *msdu;
397 lockdep_assert_held(&htt->rx_ring.lock);
399 msdu = ath10k_htt_rx_find_skb_paddr(ar, paddr);
403 rxcb = ATH10K_SKB_RXCB(msdu);
404 hash_del(&rxcb->hlist);
405 htt->rx_ring.fill_cnt--;
407 dma_unmap_single(htt->ar->dev, rxcb->paddr,
408 msdu->len + skb_tailroom(msdu),
410 ath10k_dbg_dump(ar, ATH10K_DBG_HTT_DUMP, NULL, "htt rx netbuf pop: ",
411 msdu->data, msdu->len + skb_tailroom(msdu));
416 static int ath10k_htt_rx_pop_paddr_list(struct ath10k_htt *htt,
417 struct htt_rx_in_ord_ind *ev,
418 struct sk_buff_head *list)
420 struct ath10k *ar = htt->ar;
421 struct htt_rx_in_ord_msdu_desc *msdu_desc = ev->msdu_descs;
422 struct htt_rx_desc *rxd;
423 struct sk_buff *msdu;
428 lockdep_assert_held(&htt->rx_ring.lock);
430 msdu_count = __le16_to_cpu(ev->msdu_count);
431 is_offload = !!(ev->info & HTT_RX_IN_ORD_IND_INFO_OFFLOAD_MASK);
433 while (msdu_count--) {
434 paddr = __le32_to_cpu(msdu_desc->msdu_paddr);
436 msdu = ath10k_htt_rx_pop_paddr(htt, paddr);
438 __skb_queue_purge(list);
442 __skb_queue_tail(list, msdu);
445 rxd = (void *)msdu->data;
447 trace_ath10k_htt_rx_desc(ar, rxd, sizeof(*rxd));
449 skb_put(msdu, sizeof(*rxd));
450 skb_pull(msdu, sizeof(*rxd));
451 skb_put(msdu, __le16_to_cpu(msdu_desc->msdu_len));
453 if (!(__le32_to_cpu(rxd->attention.flags) &
454 RX_ATTENTION_FLAGS_MSDU_DONE)) {
455 ath10k_warn(htt->ar, "tried to pop an incomplete frame, oops!\n");
466 int ath10k_htt_rx_alloc(struct ath10k_htt *htt)
468 struct ath10k *ar = htt->ar;
472 struct timer_list *timer = &htt->rx_ring.refill_retry_timer;
474 htt->rx_confused = false;
476 /* XXX: The fill level could be changed during runtime in response to
477 * the host processing latency. Is this really worth it?
479 htt->rx_ring.size = HTT_RX_RING_SIZE;
480 htt->rx_ring.size_mask = htt->rx_ring.size - 1;
481 htt->rx_ring.fill_level = HTT_RX_RING_FILL_LEVEL;
483 if (!is_power_of_2(htt->rx_ring.size)) {
484 ath10k_warn(ar, "htt rx ring size is not power of 2\n");
488 htt->rx_ring.netbufs_ring =
489 kzalloc(htt->rx_ring.size * sizeof(struct sk_buff *),
491 if (!htt->rx_ring.netbufs_ring)
494 size = htt->rx_ring.size * sizeof(htt->rx_ring.paddrs_ring);
496 vaddr = dma_alloc_coherent(htt->ar->dev, size, &paddr, GFP_KERNEL);
500 htt->rx_ring.paddrs_ring = vaddr;
501 htt->rx_ring.base_paddr = paddr;
503 vaddr = dma_alloc_coherent(htt->ar->dev,
504 sizeof(*htt->rx_ring.alloc_idx.vaddr),
509 htt->rx_ring.alloc_idx.vaddr = vaddr;
510 htt->rx_ring.alloc_idx.paddr = paddr;
511 htt->rx_ring.sw_rd_idx.msdu_payld = htt->rx_ring.size_mask;
512 *htt->rx_ring.alloc_idx.vaddr = 0;
514 /* Initialize the Rx refill retry timer */
515 setup_timer(timer, ath10k_htt_rx_ring_refill_retry, (unsigned long)htt);
517 spin_lock_init(&htt->rx_ring.lock);
519 htt->rx_ring.fill_cnt = 0;
520 htt->rx_ring.sw_rd_idx.msdu_payld = 0;
521 hash_init(htt->rx_ring.skb_table);
523 tasklet_init(&htt->rx_replenish_task, ath10k_htt_rx_replenish_task,
526 skb_queue_head_init(&htt->rx_compl_q);
527 skb_queue_head_init(&htt->rx_in_ord_compl_q);
528 skb_queue_head_init(&htt->tx_fetch_ind_q);
530 tasklet_init(&htt->txrx_compl_task, ath10k_htt_txrx_compl_task,
533 ath10k_dbg(ar, ATH10K_DBG_BOOT, "htt rx ring size %d fill_level %d\n",
534 htt->rx_ring.size, htt->rx_ring.fill_level);
538 dma_free_coherent(htt->ar->dev,
540 sizeof(htt->rx_ring.paddrs_ring)),
541 htt->rx_ring.paddrs_ring,
542 htt->rx_ring.base_paddr);
544 kfree(htt->rx_ring.netbufs_ring);
549 static int ath10k_htt_rx_crypto_param_len(struct ath10k *ar,
550 enum htt_rx_mpdu_encrypt_type type)
553 case HTT_RX_MPDU_ENCRYPT_NONE:
555 case HTT_RX_MPDU_ENCRYPT_WEP40:
556 case HTT_RX_MPDU_ENCRYPT_WEP104:
557 return IEEE80211_WEP_IV_LEN;
558 case HTT_RX_MPDU_ENCRYPT_TKIP_WITHOUT_MIC:
559 case HTT_RX_MPDU_ENCRYPT_TKIP_WPA:
560 return IEEE80211_TKIP_IV_LEN;
561 case HTT_RX_MPDU_ENCRYPT_AES_CCM_WPA2:
562 return IEEE80211_CCMP_HDR_LEN;
563 case HTT_RX_MPDU_ENCRYPT_WEP128:
564 case HTT_RX_MPDU_ENCRYPT_WAPI:
568 ath10k_warn(ar, "unsupported encryption type %d\n", type);
572 #define MICHAEL_MIC_LEN 8
574 static int ath10k_htt_rx_crypto_tail_len(struct ath10k *ar,
575 enum htt_rx_mpdu_encrypt_type type)
578 case HTT_RX_MPDU_ENCRYPT_NONE:
580 case HTT_RX_MPDU_ENCRYPT_WEP40:
581 case HTT_RX_MPDU_ENCRYPT_WEP104:
582 return IEEE80211_WEP_ICV_LEN;
583 case HTT_RX_MPDU_ENCRYPT_TKIP_WITHOUT_MIC:
584 case HTT_RX_MPDU_ENCRYPT_TKIP_WPA:
585 return IEEE80211_TKIP_ICV_LEN;
586 case HTT_RX_MPDU_ENCRYPT_AES_CCM_WPA2:
587 return IEEE80211_CCMP_MIC_LEN;
588 case HTT_RX_MPDU_ENCRYPT_WEP128:
589 case HTT_RX_MPDU_ENCRYPT_WAPI:
593 ath10k_warn(ar, "unsupported encryption type %d\n", type);
597 struct amsdu_subframe_hdr {
603 #define GROUP_ID_IS_SU_MIMO(x) ((x) == 0 || (x) == 63)
605 static void ath10k_htt_rx_h_rates(struct ath10k *ar,
606 struct ieee80211_rx_status *status,
607 struct htt_rx_desc *rxd)
609 struct ieee80211_supported_band *sband;
610 u8 cck, rate, bw, sgi, mcs, nss;
613 u32 info1, info2, info3;
615 info1 = __le32_to_cpu(rxd->ppdu_start.info1);
616 info2 = __le32_to_cpu(rxd->ppdu_start.info2);
617 info3 = __le32_to_cpu(rxd->ppdu_start.info3);
619 preamble = MS(info1, RX_PPDU_START_INFO1_PREAMBLE_TYPE);
623 /* To get legacy rate index band is required. Since band can't
624 * be undefined check if freq is non-zero.
629 cck = info1 & RX_PPDU_START_INFO1_L_SIG_RATE_SELECT;
630 rate = MS(info1, RX_PPDU_START_INFO1_L_SIG_RATE);
631 rate &= ~RX_PPDU_START_RATE_FLAG;
633 sband = &ar->mac.sbands[status->band];
634 status->rate_idx = ath10k_mac_hw_rate_to_idx(sband, rate, cck);
637 case HTT_RX_HT_WITH_TXBF:
638 /* HT-SIG - Table 20-11 in info2 and info3 */
641 bw = (info2 >> 7) & 1;
642 sgi = (info3 >> 7) & 1;
644 status->rate_idx = mcs;
645 status->flag |= RX_FLAG_HT;
647 status->flag |= RX_FLAG_SHORT_GI;
649 status->flag |= RX_FLAG_40MHZ;
652 case HTT_RX_VHT_WITH_TXBF:
653 /* VHT-SIG-A1 in info2, VHT-SIG-A2 in info3
657 group_id = (info2 >> 4) & 0x3F;
659 if (GROUP_ID_IS_SU_MIMO(group_id)) {
660 mcs = (info3 >> 4) & 0x0F;
661 nss = ((info2 >> 10) & 0x07) + 1;
663 /* Hardware doesn't decode VHT-SIG-B into Rx descriptor
664 * so it's impossible to decode MCS. Also since
665 * firmware consumes Group Id Management frames host
666 * has no knowledge regarding group/user position
667 * mapping so it's impossible to pick the correct Nsts
670 * Bandwidth and SGI are valid so report the rateinfo
671 * on best-effort basis.
678 ath10k_warn(ar, "invalid MCS received %u\n", mcs);
679 ath10k_warn(ar, "rxd %08x mpdu start %08x %08x msdu start %08x %08x ppdu start %08x %08x %08x %08x %08x\n",
680 __le32_to_cpu(rxd->attention.flags),
681 __le32_to_cpu(rxd->mpdu_start.info0),
682 __le32_to_cpu(rxd->mpdu_start.info1),
683 __le32_to_cpu(rxd->msdu_start.common.info0),
684 __le32_to_cpu(rxd->msdu_start.common.info1),
685 rxd->ppdu_start.info0,
686 __le32_to_cpu(rxd->ppdu_start.info1),
687 __le32_to_cpu(rxd->ppdu_start.info2),
688 __le32_to_cpu(rxd->ppdu_start.info3),
689 __le32_to_cpu(rxd->ppdu_start.info4));
691 ath10k_warn(ar, "msdu end %08x mpdu end %08x\n",
692 __le32_to_cpu(rxd->msdu_end.common.info0),
693 __le32_to_cpu(rxd->mpdu_end.info0));
695 ath10k_dbg_dump(ar, ATH10K_DBG_HTT_DUMP, NULL,
696 "rx desc msdu payload: ",
697 rxd->msdu_payload, 50);
700 status->rate_idx = mcs;
701 status->vht_nss = nss;
704 status->flag |= RX_FLAG_SHORT_GI;
712 status->flag |= RX_FLAG_40MHZ;
716 status->vht_flag |= RX_VHT_FLAG_80MHZ;
719 status->flag |= RX_FLAG_VHT;
726 static struct ieee80211_channel *
727 ath10k_htt_rx_h_peer_channel(struct ath10k *ar, struct htt_rx_desc *rxd)
729 struct ath10k_peer *peer;
730 struct ath10k_vif *arvif;
731 struct cfg80211_chan_def def;
734 lockdep_assert_held(&ar->data_lock);
739 if (rxd->attention.flags &
740 __cpu_to_le32(RX_ATTENTION_FLAGS_PEER_IDX_INVALID))
743 if (!(rxd->msdu_end.common.info0 &
744 __cpu_to_le32(RX_MSDU_END_INFO0_FIRST_MSDU)))
747 peer_id = MS(__le32_to_cpu(rxd->mpdu_start.info0),
748 RX_MPDU_START_INFO0_PEER_IDX);
750 peer = ath10k_peer_find_by_id(ar, peer_id);
754 arvif = ath10k_get_arvif(ar, peer->vdev_id);
755 if (WARN_ON_ONCE(!arvif))
758 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
764 static struct ieee80211_channel *
765 ath10k_htt_rx_h_vdev_channel(struct ath10k *ar, u32 vdev_id)
767 struct ath10k_vif *arvif;
768 struct cfg80211_chan_def def;
770 lockdep_assert_held(&ar->data_lock);
772 list_for_each_entry(arvif, &ar->arvifs, list) {
773 if (arvif->vdev_id == vdev_id &&
774 ath10k_mac_vif_chan(arvif->vif, &def) == 0)
782 ath10k_htt_rx_h_any_chan_iter(struct ieee80211_hw *hw,
783 struct ieee80211_chanctx_conf *conf,
786 struct cfg80211_chan_def *def = data;
791 static struct ieee80211_channel *
792 ath10k_htt_rx_h_any_channel(struct ath10k *ar)
794 struct cfg80211_chan_def def = {};
796 ieee80211_iter_chan_contexts_atomic(ar->hw,
797 ath10k_htt_rx_h_any_chan_iter,
803 static bool ath10k_htt_rx_h_channel(struct ath10k *ar,
804 struct ieee80211_rx_status *status,
805 struct htt_rx_desc *rxd,
808 struct ieee80211_channel *ch;
810 spin_lock_bh(&ar->data_lock);
811 ch = ar->scan_channel;
815 ch = ath10k_htt_rx_h_peer_channel(ar, rxd);
817 ch = ath10k_htt_rx_h_vdev_channel(ar, vdev_id);
819 ch = ath10k_htt_rx_h_any_channel(ar);
821 ch = ar->tgt_oper_chan;
822 spin_unlock_bh(&ar->data_lock);
827 status->band = ch->band;
828 status->freq = ch->center_freq;
833 static void ath10k_htt_rx_h_signal(struct ath10k *ar,
834 struct ieee80211_rx_status *status,
835 struct htt_rx_desc *rxd)
837 /* FIXME: Get real NF */
838 status->signal = ATH10K_DEFAULT_NOISE_FLOOR +
839 rxd->ppdu_start.rssi_comb;
840 status->flag &= ~RX_FLAG_NO_SIGNAL_VAL;
843 static void ath10k_htt_rx_h_mactime(struct ath10k *ar,
844 struct ieee80211_rx_status *status,
845 struct htt_rx_desc *rxd)
847 /* FIXME: TSF is known only at the end of PPDU, in the last MPDU. This
848 * means all prior MSDUs in a PPDU are reported to mac80211 without the
849 * TSF. Is it worth holding frames until end of PPDU is known?
851 * FIXME: Can we get/compute 64bit TSF?
853 status->mactime = __le32_to_cpu(rxd->ppdu_end.common.tsf_timestamp);
854 status->flag |= RX_FLAG_MACTIME_END;
857 static void ath10k_htt_rx_h_ppdu(struct ath10k *ar,
858 struct sk_buff_head *amsdu,
859 struct ieee80211_rx_status *status,
862 struct sk_buff *first;
863 struct htt_rx_desc *rxd;
867 if (skb_queue_empty(amsdu))
870 first = skb_peek(amsdu);
871 rxd = (void *)first->data - sizeof(*rxd);
873 is_first_ppdu = !!(rxd->attention.flags &
874 __cpu_to_le32(RX_ATTENTION_FLAGS_FIRST_MPDU));
875 is_last_ppdu = !!(rxd->attention.flags &
876 __cpu_to_le32(RX_ATTENTION_FLAGS_LAST_MPDU));
879 /* New PPDU starts so clear out the old per-PPDU status. */
881 status->rate_idx = 0;
883 status->vht_flag &= ~RX_VHT_FLAG_80MHZ;
884 status->flag &= ~(RX_FLAG_HT |
888 RX_FLAG_MACTIME_END);
889 status->flag |= RX_FLAG_NO_SIGNAL_VAL;
891 ath10k_htt_rx_h_signal(ar, status, rxd);
892 ath10k_htt_rx_h_channel(ar, status, rxd, vdev_id);
893 ath10k_htt_rx_h_rates(ar, status, rxd);
897 ath10k_htt_rx_h_mactime(ar, status, rxd);
900 static const char * const tid_to_ac[] = {
911 static char *ath10k_get_tid(struct ieee80211_hdr *hdr, char *out, size_t size)
916 if (!ieee80211_is_data_qos(hdr->frame_control))
919 qc = ieee80211_get_qos_ctl(hdr);
920 tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
922 snprintf(out, size, "tid %d (%s)", tid, tid_to_ac[tid]);
924 snprintf(out, size, "tid %d", tid);
929 static void ath10k_process_rx(struct ath10k *ar,
930 struct ieee80211_rx_status *rx_status,
933 struct ieee80211_rx_status *status;
934 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
937 status = IEEE80211_SKB_RXCB(skb);
938 *status = *rx_status;
940 ath10k_dbg(ar, ATH10K_DBG_DATA,
941 "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",
944 ieee80211_get_SA(hdr),
945 ath10k_get_tid(hdr, tid, sizeof(tid)),
946 is_multicast_ether_addr(ieee80211_get_DA(hdr)) ?
948 (__le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_SEQ) >> 4,
949 status->flag == 0 ? "legacy" : "",
950 status->flag & RX_FLAG_HT ? "ht" : "",
951 status->flag & RX_FLAG_VHT ? "vht" : "",
952 status->flag & RX_FLAG_40MHZ ? "40" : "",
953 status->vht_flag & RX_VHT_FLAG_80MHZ ? "80" : "",
954 status->flag & RX_FLAG_SHORT_GI ? "sgi " : "",
958 status->band, status->flag,
959 !!(status->flag & RX_FLAG_FAILED_FCS_CRC),
960 !!(status->flag & RX_FLAG_MMIC_ERROR),
961 !!(status->flag & RX_FLAG_AMSDU_MORE));
962 ath10k_dbg_dump(ar, ATH10K_DBG_HTT_DUMP, NULL, "rx skb: ",
963 skb->data, skb->len);
964 trace_ath10k_rx_hdr(ar, skb->data, skb->len);
965 trace_ath10k_rx_payload(ar, skb->data, skb->len);
967 ieee80211_rx(ar->hw, skb);
970 static int ath10k_htt_rx_nwifi_hdrlen(struct ath10k *ar,
971 struct ieee80211_hdr *hdr)
973 int len = ieee80211_hdrlen(hdr->frame_control);
975 if (!test_bit(ATH10K_FW_FEATURE_NO_NWIFI_DECAP_4ADDR_PADDING,
977 len = round_up(len, 4);
982 static void ath10k_htt_rx_h_undecap_raw(struct ath10k *ar,
983 struct sk_buff *msdu,
984 struct ieee80211_rx_status *status,
985 enum htt_rx_mpdu_encrypt_type enctype,
988 struct ieee80211_hdr *hdr;
989 struct htt_rx_desc *rxd;
995 rxd = (void *)msdu->data - sizeof(*rxd);
996 is_first = !!(rxd->msdu_end.common.info0 &
997 __cpu_to_le32(RX_MSDU_END_INFO0_FIRST_MSDU));
998 is_last = !!(rxd->msdu_end.common.info0 &
999 __cpu_to_le32(RX_MSDU_END_INFO0_LAST_MSDU));
1001 /* Delivered decapped frame:
1003 * [crypto param] <-- can be trimmed if !fcs_err &&
1004 * !decrypt_err && !peer_idx_invalid
1005 * [amsdu header] <-- only if A-MSDU
1008 * [FCS] <-- at end, needs to be trimmed
1011 /* This probably shouldn't happen but warn just in case */
1012 if (unlikely(WARN_ON_ONCE(!is_first)))
1015 /* This probably shouldn't happen but warn just in case */
1016 if (unlikely(WARN_ON_ONCE(!(is_first && is_last))))
1019 skb_trim(msdu, msdu->len - FCS_LEN);
1021 /* In most cases this will be true for sniffed frames. It makes sense
1022 * to deliver them as-is without stripping the crypto param. This is
1023 * necessary for software based decryption.
1025 * If there's no error then the frame is decrypted. At least that is
1026 * the case for frames that come in via fragmented rx indication.
1031 /* The payload is decrypted so strip crypto params. Start from tail
1032 * since hdr is used to compute some stuff.
1035 hdr = (void *)msdu->data;
1038 if (status->flag & RX_FLAG_IV_STRIPPED)
1039 skb_trim(msdu, msdu->len -
1040 ath10k_htt_rx_crypto_tail_len(ar, enctype));
1043 if ((status->flag & RX_FLAG_MMIC_STRIPPED) &&
1044 !ieee80211_has_morefrags(hdr->frame_control) &&
1045 enctype == HTT_RX_MPDU_ENCRYPT_TKIP_WPA)
1046 skb_trim(msdu, msdu->len - 8);
1049 if (status->flag & RX_FLAG_IV_STRIPPED) {
1050 hdr_len = ieee80211_hdrlen(hdr->frame_control);
1051 crypto_len = ath10k_htt_rx_crypto_param_len(ar, enctype);
1053 memmove((void *)msdu->data + crypto_len,
1054 (void *)msdu->data, hdr_len);
1055 skb_pull(msdu, crypto_len);
1059 static void ath10k_htt_rx_h_undecap_nwifi(struct ath10k *ar,
1060 struct sk_buff *msdu,
1061 struct ieee80211_rx_status *status,
1062 const u8 first_hdr[64])
1064 struct ieee80211_hdr *hdr;
1069 /* Delivered decapped frame:
1070 * [nwifi 802.11 header] <-- replaced with 802.11 hdr
1073 * Note: The nwifi header doesn't have QoS Control and is
1074 * (always?) a 3addr frame.
1076 * Note2: There's no A-MSDU subframe header. Even if it's part
1080 /* pull decapped header and copy SA & DA */
1081 if ((ar->hw_params.hw_4addr_pad == ATH10K_HW_4ADDR_PAD_BEFORE) &&
1082 ieee80211_has_a4(((struct ieee80211_hdr *)first_hdr)->frame_control)) {
1083 /* The QCA99X0 4 address mode pad 2 bytes at the
1086 hdr = (struct ieee80211_hdr *)(msdu->data + 2);
1087 /* The skb length need be extended 2 as the 2 bytes at the tail
1088 * be excluded due to the padding
1092 hdr = (struct ieee80211_hdr *)(msdu->data);
1095 hdr_len = ath10k_htt_rx_nwifi_hdrlen(ar, hdr);
1096 ether_addr_copy(da, ieee80211_get_DA(hdr));
1097 ether_addr_copy(sa, ieee80211_get_SA(hdr));
1098 skb_pull(msdu, hdr_len);
1100 /* push original 802.11 header */
1101 hdr = (struct ieee80211_hdr *)first_hdr;
1102 hdr_len = ieee80211_hdrlen(hdr->frame_control);
1103 memcpy(skb_push(msdu, hdr_len), hdr, hdr_len);
1105 /* original 802.11 header has a different DA and in
1106 * case of 4addr it may also have different SA
1108 hdr = (struct ieee80211_hdr *)msdu->data;
1109 ether_addr_copy(ieee80211_get_DA(hdr), da);
1110 ether_addr_copy(ieee80211_get_SA(hdr), sa);
1113 static void *ath10k_htt_rx_h_find_rfc1042(struct ath10k *ar,
1114 struct sk_buff *msdu,
1115 enum htt_rx_mpdu_encrypt_type enctype)
1117 struct ieee80211_hdr *hdr;
1118 struct htt_rx_desc *rxd;
1119 size_t hdr_len, crypto_len;
1121 bool is_first, is_last, is_amsdu;
1123 rxd = (void *)msdu->data - sizeof(*rxd);
1124 hdr = (void *)rxd->rx_hdr_status;
1126 is_first = !!(rxd->msdu_end.common.info0 &
1127 __cpu_to_le32(RX_MSDU_END_INFO0_FIRST_MSDU));
1128 is_last = !!(rxd->msdu_end.common.info0 &
1129 __cpu_to_le32(RX_MSDU_END_INFO0_LAST_MSDU));
1130 is_amsdu = !(is_first && is_last);
1135 hdr_len = ieee80211_hdrlen(hdr->frame_control);
1136 crypto_len = ath10k_htt_rx_crypto_param_len(ar, enctype);
1138 rfc1042 += round_up(hdr_len, 4) +
1139 round_up(crypto_len, 4);
1143 rfc1042 += sizeof(struct amsdu_subframe_hdr);
1148 static void ath10k_htt_rx_h_undecap_eth(struct ath10k *ar,
1149 struct sk_buff *msdu,
1150 struct ieee80211_rx_status *status,
1151 const u8 first_hdr[64],
1152 enum htt_rx_mpdu_encrypt_type enctype)
1154 struct ieee80211_hdr *hdr;
1161 /* Delivered decapped frame:
1162 * [eth header] <-- replaced with 802.11 hdr & rfc1042/llc
1166 rfc1042 = ath10k_htt_rx_h_find_rfc1042(ar, msdu, enctype);
1167 if (WARN_ON_ONCE(!rfc1042))
1170 /* pull decapped header and copy SA & DA */
1171 eth = (struct ethhdr *)msdu->data;
1172 ether_addr_copy(da, eth->h_dest);
1173 ether_addr_copy(sa, eth->h_source);
1174 skb_pull(msdu, sizeof(struct ethhdr));
1176 /* push rfc1042/llc/snap */
1177 memcpy(skb_push(msdu, sizeof(struct rfc1042_hdr)), rfc1042,
1178 sizeof(struct rfc1042_hdr));
1180 /* push original 802.11 header */
1181 hdr = (struct ieee80211_hdr *)first_hdr;
1182 hdr_len = ieee80211_hdrlen(hdr->frame_control);
1183 memcpy(skb_push(msdu, hdr_len), hdr, hdr_len);
1185 /* original 802.11 header has a different DA and in
1186 * case of 4addr it may also have different SA
1188 hdr = (struct ieee80211_hdr *)msdu->data;
1189 ether_addr_copy(ieee80211_get_DA(hdr), da);
1190 ether_addr_copy(ieee80211_get_SA(hdr), sa);
1193 static void ath10k_htt_rx_h_undecap_snap(struct ath10k *ar,
1194 struct sk_buff *msdu,
1195 struct ieee80211_rx_status *status,
1196 const u8 first_hdr[64])
1198 struct ieee80211_hdr *hdr;
1201 /* Delivered decapped frame:
1202 * [amsdu header] <-- replaced with 802.11 hdr
1207 skb_pull(msdu, sizeof(struct amsdu_subframe_hdr));
1209 hdr = (struct ieee80211_hdr *)first_hdr;
1210 hdr_len = ieee80211_hdrlen(hdr->frame_control);
1211 memcpy(skb_push(msdu, hdr_len), hdr, hdr_len);
1214 static void ath10k_htt_rx_h_undecap(struct ath10k *ar,
1215 struct sk_buff *msdu,
1216 struct ieee80211_rx_status *status,
1218 enum htt_rx_mpdu_encrypt_type enctype,
1221 struct htt_rx_desc *rxd;
1222 enum rx_msdu_decap_format decap;
1224 /* First msdu's decapped header:
1225 * [802.11 header] <-- padded to 4 bytes long
1226 * [crypto param] <-- padded to 4 bytes long
1227 * [amsdu header] <-- only if A-MSDU
1230 * Other (2nd, 3rd, ..) msdu's decapped header:
1231 * [amsdu header] <-- only if A-MSDU
1235 rxd = (void *)msdu->data - sizeof(*rxd);
1236 decap = MS(__le32_to_cpu(rxd->msdu_start.common.info1),
1237 RX_MSDU_START_INFO1_DECAP_FORMAT);
1240 case RX_MSDU_DECAP_RAW:
1241 ath10k_htt_rx_h_undecap_raw(ar, msdu, status, enctype,
1244 case RX_MSDU_DECAP_NATIVE_WIFI:
1245 ath10k_htt_rx_h_undecap_nwifi(ar, msdu, status, first_hdr);
1247 case RX_MSDU_DECAP_ETHERNET2_DIX:
1248 ath10k_htt_rx_h_undecap_eth(ar, msdu, status, first_hdr, enctype);
1250 case RX_MSDU_DECAP_8023_SNAP_LLC:
1251 ath10k_htt_rx_h_undecap_snap(ar, msdu, status, first_hdr);
1256 static int ath10k_htt_rx_get_csum_state(struct sk_buff *skb)
1258 struct htt_rx_desc *rxd;
1260 bool is_ip4, is_ip6;
1261 bool is_tcp, is_udp;
1262 bool ip_csum_ok, tcpudp_csum_ok;
1264 rxd = (void *)skb->data - sizeof(*rxd);
1265 flags = __le32_to_cpu(rxd->attention.flags);
1266 info = __le32_to_cpu(rxd->msdu_start.common.info1);
1268 is_ip4 = !!(info & RX_MSDU_START_INFO1_IPV4_PROTO);
1269 is_ip6 = !!(info & RX_MSDU_START_INFO1_IPV6_PROTO);
1270 is_tcp = !!(info & RX_MSDU_START_INFO1_TCP_PROTO);
1271 is_udp = !!(info & RX_MSDU_START_INFO1_UDP_PROTO);
1272 ip_csum_ok = !(flags & RX_ATTENTION_FLAGS_IP_CHKSUM_FAIL);
1273 tcpudp_csum_ok = !(flags & RX_ATTENTION_FLAGS_TCP_UDP_CHKSUM_FAIL);
1275 if (!is_ip4 && !is_ip6)
1276 return CHECKSUM_NONE;
1277 if (!is_tcp && !is_udp)
1278 return CHECKSUM_NONE;
1280 return CHECKSUM_NONE;
1281 if (!tcpudp_csum_ok)
1282 return CHECKSUM_NONE;
1284 return CHECKSUM_UNNECESSARY;
1287 static void ath10k_htt_rx_h_csum_offload(struct sk_buff *msdu)
1289 msdu->ip_summed = ath10k_htt_rx_get_csum_state(msdu);
1292 static void ath10k_htt_rx_h_mpdu(struct ath10k *ar,
1293 struct sk_buff_head *amsdu,
1294 struct ieee80211_rx_status *status)
1296 struct sk_buff *first;
1297 struct sk_buff *last;
1298 struct sk_buff *msdu;
1299 struct htt_rx_desc *rxd;
1300 struct ieee80211_hdr *hdr;
1301 enum htt_rx_mpdu_encrypt_type enctype;
1306 bool has_crypto_err;
1308 bool has_peer_idx_invalid;
1313 if (skb_queue_empty(amsdu))
1316 first = skb_peek(amsdu);
1317 rxd = (void *)first->data - sizeof(*rxd);
1319 is_mgmt = !!(rxd->attention.flags &
1320 __cpu_to_le32(RX_ATTENTION_FLAGS_MGMT_TYPE));
1322 enctype = MS(__le32_to_cpu(rxd->mpdu_start.info0),
1323 RX_MPDU_START_INFO0_ENCRYPT_TYPE);
1325 /* First MSDU's Rx descriptor in an A-MSDU contains full 802.11
1326 * decapped header. It'll be used for undecapping of each MSDU.
1328 hdr = (void *)rxd->rx_hdr_status;
1329 hdr_len = ieee80211_hdrlen(hdr->frame_control);
1330 memcpy(first_hdr, hdr, hdr_len);
1332 /* Each A-MSDU subframe will use the original header as the base and be
1333 * reported as a separate MSDU so strip the A-MSDU bit from QoS Ctl.
1335 hdr = (void *)first_hdr;
1336 qos = ieee80211_get_qos_ctl(hdr);
1337 qos[0] &= ~IEEE80211_QOS_CTL_A_MSDU_PRESENT;
1339 /* Some attention flags are valid only in the last MSDU. */
1340 last = skb_peek_tail(amsdu);
1341 rxd = (void *)last->data - sizeof(*rxd);
1342 attention = __le32_to_cpu(rxd->attention.flags);
1344 has_fcs_err = !!(attention & RX_ATTENTION_FLAGS_FCS_ERR);
1345 has_crypto_err = !!(attention & RX_ATTENTION_FLAGS_DECRYPT_ERR);
1346 has_tkip_err = !!(attention & RX_ATTENTION_FLAGS_TKIP_MIC_ERR);
1347 has_peer_idx_invalid = !!(attention & RX_ATTENTION_FLAGS_PEER_IDX_INVALID);
1349 /* Note: If hardware captures an encrypted frame that it can't decrypt,
1350 * e.g. due to fcs error, missing peer or invalid key data it will
1351 * report the frame as raw.
1353 is_decrypted = (enctype != HTT_RX_MPDU_ENCRYPT_NONE &&
1356 !has_peer_idx_invalid);
1358 /* Clear per-MPDU flags while leaving per-PPDU flags intact. */
1359 status->flag &= ~(RX_FLAG_FAILED_FCS_CRC |
1360 RX_FLAG_MMIC_ERROR |
1362 RX_FLAG_IV_STRIPPED |
1363 RX_FLAG_ONLY_MONITOR |
1364 RX_FLAG_MMIC_STRIPPED);
1367 status->flag |= RX_FLAG_FAILED_FCS_CRC;
1370 status->flag |= RX_FLAG_MMIC_ERROR;
1372 /* Firmware reports all necessary management frames via WMI already.
1373 * They are not reported to monitor interfaces at all so pass the ones
1374 * coming via HTT to monitor interfaces instead. This simplifies
1378 status->flag |= RX_FLAG_ONLY_MONITOR;
1381 status->flag |= RX_FLAG_DECRYPTED;
1383 if (likely(!is_mgmt))
1384 status->flag |= RX_FLAG_IV_STRIPPED |
1385 RX_FLAG_MMIC_STRIPPED;
1388 skb_queue_walk(amsdu, msdu) {
1389 ath10k_htt_rx_h_csum_offload(msdu);
1390 ath10k_htt_rx_h_undecap(ar, msdu, status, first_hdr, enctype,
1393 /* Undecapping involves copying the original 802.11 header back
1394 * to sk_buff. If frame is protected and hardware has decrypted
1395 * it then remove the protected bit.
1402 hdr = (void *)msdu->data;
1403 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_FCTL_PROTECTED);
1407 static void ath10k_htt_rx_h_deliver(struct ath10k *ar,
1408 struct sk_buff_head *amsdu,
1409 struct ieee80211_rx_status *status)
1411 struct sk_buff *msdu;
1413 while ((msdu = __skb_dequeue(amsdu))) {
1414 /* Setup per-MSDU flags */
1415 if (skb_queue_empty(amsdu))
1416 status->flag &= ~RX_FLAG_AMSDU_MORE;
1418 status->flag |= RX_FLAG_AMSDU_MORE;
1420 ath10k_process_rx(ar, status, msdu);
1424 static int ath10k_unchain_msdu(struct sk_buff_head *amsdu)
1426 struct sk_buff *skb, *first;
1430 /* TODO: Might could optimize this by using
1431 * skb_try_coalesce or similar method to
1432 * decrease copying, or maybe get mac80211 to
1433 * provide a way to just receive a list of
1437 first = __skb_dequeue(amsdu);
1439 /* Allocate total length all at once. */
1440 skb_queue_walk(amsdu, skb)
1441 total_len += skb->len;
1443 space = total_len - skb_tailroom(first);
1445 (pskb_expand_head(first, 0, space, GFP_ATOMIC) < 0)) {
1446 /* TODO: bump some rx-oom error stat */
1447 /* put it back together so we can free the
1448 * whole list at once.
1450 __skb_queue_head(amsdu, first);
1454 /* Walk list again, copying contents into
1457 while ((skb = __skb_dequeue(amsdu))) {
1458 skb_copy_from_linear_data(skb, skb_put(first, skb->len),
1460 dev_kfree_skb_any(skb);
1463 __skb_queue_head(amsdu, first);
1467 static void ath10k_htt_rx_h_unchain(struct ath10k *ar,
1468 struct sk_buff_head *amsdu,
1471 struct sk_buff *first;
1472 struct htt_rx_desc *rxd;
1473 enum rx_msdu_decap_format decap;
1475 first = skb_peek(amsdu);
1476 rxd = (void *)first->data - sizeof(*rxd);
1477 decap = MS(__le32_to_cpu(rxd->msdu_start.common.info1),
1478 RX_MSDU_START_INFO1_DECAP_FORMAT);
1483 /* FIXME: Current unchaining logic can only handle simple case of raw
1484 * msdu chaining. If decapping is other than raw the chaining may be
1485 * more complex and this isn't handled by the current code. Don't even
1486 * try re-constructing such frames - it'll be pretty much garbage.
1488 if (decap != RX_MSDU_DECAP_RAW ||
1489 skb_queue_len(amsdu) != 1 + rxd->frag_info.ring2_more_count) {
1490 __skb_queue_purge(amsdu);
1494 ath10k_unchain_msdu(amsdu);
1497 static bool ath10k_htt_rx_amsdu_allowed(struct ath10k *ar,
1498 struct sk_buff_head *amsdu,
1499 struct ieee80211_rx_status *rx_status)
1501 /* FIXME: It might be a good idea to do some fuzzy-testing to drop
1502 * invalid/dangerous frames.
1505 if (!rx_status->freq) {
1506 ath10k_warn(ar, "no channel configured; ignoring frame(s)!\n");
1510 if (test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags)) {
1511 ath10k_dbg(ar, ATH10K_DBG_HTT, "htt rx cac running\n");
1518 static void ath10k_htt_rx_h_filter(struct ath10k *ar,
1519 struct sk_buff_head *amsdu,
1520 struct ieee80211_rx_status *rx_status)
1522 if (skb_queue_empty(amsdu))
1525 if (ath10k_htt_rx_amsdu_allowed(ar, amsdu, rx_status))
1528 __skb_queue_purge(amsdu);
1531 static void ath10k_htt_rx_handler(struct ath10k_htt *htt,
1532 struct htt_rx_indication *rx)
1534 struct ath10k *ar = htt->ar;
1535 struct ieee80211_rx_status *rx_status = &htt->rx_status;
1536 struct htt_rx_indication_mpdu_range *mpdu_ranges;
1537 struct sk_buff_head amsdu;
1538 int num_mpdu_ranges;
1539 int i, ret, mpdu_count = 0;
1541 lockdep_assert_held(&htt->rx_ring.lock);
1543 if (htt->rx_confused)
1546 num_mpdu_ranges = MS(__le32_to_cpu(rx->hdr.info1),
1547 HTT_RX_INDICATION_INFO1_NUM_MPDU_RANGES);
1548 mpdu_ranges = htt_rx_ind_get_mpdu_ranges(rx);
1550 ath10k_dbg_dump(ar, ATH10K_DBG_HTT_DUMP, NULL, "htt rx ind: ",
1552 (sizeof(struct htt_rx_indication_mpdu_range) *
1555 for (i = 0; i < num_mpdu_ranges; i++)
1556 mpdu_count += mpdu_ranges[i].mpdu_count;
1558 while (mpdu_count--) {
1559 __skb_queue_head_init(&amsdu);
1560 ret = ath10k_htt_rx_amsdu_pop(htt, &amsdu);
1562 ath10k_warn(ar, "rx ring became corrupted: %d\n", ret);
1563 __skb_queue_purge(&amsdu);
1564 /* FIXME: It's probably a good idea to reboot the
1565 * device instead of leaving it inoperable.
1567 htt->rx_confused = true;
1571 ath10k_htt_rx_h_ppdu(ar, &amsdu, rx_status, 0xffff);
1572 ath10k_htt_rx_h_unchain(ar, &amsdu, ret > 0);
1573 ath10k_htt_rx_h_filter(ar, &amsdu, rx_status);
1574 ath10k_htt_rx_h_mpdu(ar, &amsdu, rx_status);
1575 ath10k_htt_rx_h_deliver(ar, &amsdu, rx_status);
1578 tasklet_schedule(&htt->rx_replenish_task);
1581 static void ath10k_htt_rx_frag_handler(struct ath10k_htt *htt,
1582 struct htt_rx_fragment_indication *frag)
1584 struct ath10k *ar = htt->ar;
1585 struct ieee80211_rx_status *rx_status = &htt->rx_status;
1586 struct sk_buff_head amsdu;
1589 __skb_queue_head_init(&amsdu);
1591 spin_lock_bh(&htt->rx_ring.lock);
1592 ret = ath10k_htt_rx_amsdu_pop(htt, &amsdu);
1593 spin_unlock_bh(&htt->rx_ring.lock);
1595 tasklet_schedule(&htt->rx_replenish_task);
1597 ath10k_dbg(ar, ATH10K_DBG_HTT_DUMP, "htt rx frag ahead\n");
1600 ath10k_warn(ar, "failed to pop amsdu from httr rx ring for fragmented rx %d\n",
1602 __skb_queue_purge(&amsdu);
1606 if (skb_queue_len(&amsdu) != 1) {
1607 ath10k_warn(ar, "failed to pop frag amsdu: too many msdus\n");
1608 __skb_queue_purge(&amsdu);
1612 ath10k_htt_rx_h_ppdu(ar, &amsdu, rx_status, 0xffff);
1613 ath10k_htt_rx_h_filter(ar, &amsdu, rx_status);
1614 ath10k_htt_rx_h_mpdu(ar, &amsdu, rx_status);
1615 ath10k_htt_rx_h_deliver(ar, &amsdu, rx_status);
1618 static void ath10k_htt_rx_tx_compl_ind(struct ath10k *ar,
1619 struct sk_buff *skb)
1621 struct ath10k_htt *htt = &ar->htt;
1622 struct htt_resp *resp = (struct htt_resp *)skb->data;
1623 struct htt_tx_done tx_done = {};
1624 int status = MS(resp->data_tx_completion.flags, HTT_DATA_TX_STATUS);
1629 case HTT_DATA_TX_STATUS_NO_ACK:
1630 tx_done.status = HTT_TX_COMPL_STATE_NOACK;
1632 case HTT_DATA_TX_STATUS_OK:
1633 tx_done.status = HTT_TX_COMPL_STATE_ACK;
1635 case HTT_DATA_TX_STATUS_DISCARD:
1636 case HTT_DATA_TX_STATUS_POSTPONE:
1637 case HTT_DATA_TX_STATUS_DOWNLOAD_FAIL:
1638 tx_done.status = HTT_TX_COMPL_STATE_DISCARD;
1641 ath10k_warn(ar, "unhandled tx completion status %d\n", status);
1642 tx_done.status = HTT_TX_COMPL_STATE_DISCARD;
1646 ath10k_dbg(ar, ATH10K_DBG_HTT, "htt tx completion num_msdus %d\n",
1647 resp->data_tx_completion.num_msdus);
1649 for (i = 0; i < resp->data_tx_completion.num_msdus; i++) {
1650 msdu_id = resp->data_tx_completion.msdus[i];
1651 tx_done.msdu_id = __le16_to_cpu(msdu_id);
1653 /* kfifo_put: In practice firmware shouldn't fire off per-CE
1654 * interrupt and main interrupt (MSI/-X range case) for the same
1655 * HTC service so it should be safe to use kfifo_put w/o lock.
1657 * From kfifo_put() documentation:
1658 * Note that with only one concurrent reader and one concurrent
1659 * writer, you don't need extra locking to use these macro.
1661 if (!kfifo_put(&htt->txdone_fifo, tx_done)) {
1662 ath10k_warn(ar, "txdone fifo overrun, msdu_id %d status %d\n",
1663 tx_done.msdu_id, tx_done.status);
1664 ath10k_txrx_tx_unref(htt, &tx_done);
1669 static void ath10k_htt_rx_addba(struct ath10k *ar, struct htt_resp *resp)
1671 struct htt_rx_addba *ev = &resp->rx_addba;
1672 struct ath10k_peer *peer;
1673 struct ath10k_vif *arvif;
1674 u16 info0, tid, peer_id;
1676 info0 = __le16_to_cpu(ev->info0);
1677 tid = MS(info0, HTT_RX_BA_INFO0_TID);
1678 peer_id = MS(info0, HTT_RX_BA_INFO0_PEER_ID);
1680 ath10k_dbg(ar, ATH10K_DBG_HTT,
1681 "htt rx addba tid %hu peer_id %hu size %hhu\n",
1682 tid, peer_id, ev->window_size);
1684 spin_lock_bh(&ar->data_lock);
1685 peer = ath10k_peer_find_by_id(ar, peer_id);
1687 ath10k_warn(ar, "received addba event for invalid peer_id: %hu\n",
1689 spin_unlock_bh(&ar->data_lock);
1693 arvif = ath10k_get_arvif(ar, peer->vdev_id);
1695 ath10k_warn(ar, "received addba event for invalid vdev_id: %u\n",
1697 spin_unlock_bh(&ar->data_lock);
1701 ath10k_dbg(ar, ATH10K_DBG_HTT,
1702 "htt rx start rx ba session sta %pM tid %hu size %hhu\n",
1703 peer->addr, tid, ev->window_size);
1705 ieee80211_start_rx_ba_session_offl(arvif->vif, peer->addr, tid);
1706 spin_unlock_bh(&ar->data_lock);
1709 static void ath10k_htt_rx_delba(struct ath10k *ar, struct htt_resp *resp)
1711 struct htt_rx_delba *ev = &resp->rx_delba;
1712 struct ath10k_peer *peer;
1713 struct ath10k_vif *arvif;
1714 u16 info0, tid, peer_id;
1716 info0 = __le16_to_cpu(ev->info0);
1717 tid = MS(info0, HTT_RX_BA_INFO0_TID);
1718 peer_id = MS(info0, HTT_RX_BA_INFO0_PEER_ID);
1720 ath10k_dbg(ar, ATH10K_DBG_HTT,
1721 "htt rx delba tid %hu peer_id %hu\n",
1724 spin_lock_bh(&ar->data_lock);
1725 peer = ath10k_peer_find_by_id(ar, peer_id);
1727 ath10k_warn(ar, "received addba event for invalid peer_id: %hu\n",
1729 spin_unlock_bh(&ar->data_lock);
1733 arvif = ath10k_get_arvif(ar, peer->vdev_id);
1735 ath10k_warn(ar, "received addba event for invalid vdev_id: %u\n",
1737 spin_unlock_bh(&ar->data_lock);
1741 ath10k_dbg(ar, ATH10K_DBG_HTT,
1742 "htt rx stop rx ba session sta %pM tid %hu\n",
1745 ieee80211_stop_rx_ba_session_offl(arvif->vif, peer->addr, tid);
1746 spin_unlock_bh(&ar->data_lock);
1749 static int ath10k_htt_rx_extract_amsdu(struct sk_buff_head *list,
1750 struct sk_buff_head *amsdu)
1752 struct sk_buff *msdu;
1753 struct htt_rx_desc *rxd;
1755 if (skb_queue_empty(list))
1758 if (WARN_ON(!skb_queue_empty(amsdu)))
1761 while ((msdu = __skb_dequeue(list))) {
1762 __skb_queue_tail(amsdu, msdu);
1764 rxd = (void *)msdu->data - sizeof(*rxd);
1765 if (rxd->msdu_end.common.info0 &
1766 __cpu_to_le32(RX_MSDU_END_INFO0_LAST_MSDU))
1770 msdu = skb_peek_tail(amsdu);
1771 rxd = (void *)msdu->data - sizeof(*rxd);
1772 if (!(rxd->msdu_end.common.info0 &
1773 __cpu_to_le32(RX_MSDU_END_INFO0_LAST_MSDU))) {
1774 skb_queue_splice_init(amsdu, list);
1781 static void ath10k_htt_rx_h_rx_offload_prot(struct ieee80211_rx_status *status,
1782 struct sk_buff *skb)
1784 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1786 if (!ieee80211_has_protected(hdr->frame_control))
1789 /* Offloaded frames are already decrypted but firmware insists they are
1790 * protected in the 802.11 header. Strip the flag. Otherwise mac80211
1791 * will drop the frame.
1794 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_FCTL_PROTECTED);
1795 status->flag |= RX_FLAG_DECRYPTED |
1796 RX_FLAG_IV_STRIPPED |
1797 RX_FLAG_MMIC_STRIPPED;
1800 static void ath10k_htt_rx_h_rx_offload(struct ath10k *ar,
1801 struct sk_buff_head *list)
1803 struct ath10k_htt *htt = &ar->htt;
1804 struct ieee80211_rx_status *status = &htt->rx_status;
1805 struct htt_rx_offload_msdu *rx;
1806 struct sk_buff *msdu;
1809 while ((msdu = __skb_dequeue(list))) {
1810 /* Offloaded frames don't have Rx descriptor. Instead they have
1811 * a short meta information header.
1814 rx = (void *)msdu->data;
1816 skb_put(msdu, sizeof(*rx));
1817 skb_pull(msdu, sizeof(*rx));
1819 if (skb_tailroom(msdu) < __le16_to_cpu(rx->msdu_len)) {
1820 ath10k_warn(ar, "dropping frame: offloaded rx msdu is too long!\n");
1821 dev_kfree_skb_any(msdu);
1825 skb_put(msdu, __le16_to_cpu(rx->msdu_len));
1827 /* Offloaded rx header length isn't multiple of 2 nor 4 so the
1828 * actual payload is unaligned. Align the frame. Otherwise
1829 * mac80211 complains. This shouldn't reduce performance much
1830 * because these offloaded frames are rare.
1832 offset = 4 - ((unsigned long)msdu->data & 3);
1833 skb_put(msdu, offset);
1834 memmove(msdu->data + offset, msdu->data, msdu->len);
1835 skb_pull(msdu, offset);
1837 /* FIXME: The frame is NWifi. Re-construct QoS Control
1838 * if possible later.
1841 memset(status, 0, sizeof(*status));
1842 status->flag |= RX_FLAG_NO_SIGNAL_VAL;
1844 ath10k_htt_rx_h_rx_offload_prot(status, msdu);
1845 ath10k_htt_rx_h_channel(ar, status, NULL, rx->vdev_id);
1846 ath10k_process_rx(ar, status, msdu);
1850 static void ath10k_htt_rx_in_ord_ind(struct ath10k *ar, struct sk_buff *skb)
1852 struct ath10k_htt *htt = &ar->htt;
1853 struct htt_resp *resp = (void *)skb->data;
1854 struct ieee80211_rx_status *status = &htt->rx_status;
1855 struct sk_buff_head list;
1856 struct sk_buff_head amsdu;
1865 lockdep_assert_held(&htt->rx_ring.lock);
1867 if (htt->rx_confused)
1870 skb_pull(skb, sizeof(resp->hdr));
1871 skb_pull(skb, sizeof(resp->rx_in_ord_ind));
1873 peer_id = __le16_to_cpu(resp->rx_in_ord_ind.peer_id);
1874 msdu_count = __le16_to_cpu(resp->rx_in_ord_ind.msdu_count);
1875 vdev_id = resp->rx_in_ord_ind.vdev_id;
1876 tid = SM(resp->rx_in_ord_ind.info, HTT_RX_IN_ORD_IND_INFO_TID);
1877 offload = !!(resp->rx_in_ord_ind.info &
1878 HTT_RX_IN_ORD_IND_INFO_OFFLOAD_MASK);
1879 frag = !!(resp->rx_in_ord_ind.info & HTT_RX_IN_ORD_IND_INFO_FRAG_MASK);
1881 ath10k_dbg(ar, ATH10K_DBG_HTT,
1882 "htt rx in ord vdev %i peer %i tid %i offload %i frag %i msdu count %i\n",
1883 vdev_id, peer_id, tid, offload, frag, msdu_count);
1885 if (skb->len < msdu_count * sizeof(*resp->rx_in_ord_ind.msdu_descs)) {
1886 ath10k_warn(ar, "dropping invalid in order rx indication\n");
1890 /* The event can deliver more than 1 A-MSDU. Each A-MSDU is later
1891 * extracted and processed.
1893 __skb_queue_head_init(&list);
1894 ret = ath10k_htt_rx_pop_paddr_list(htt, &resp->rx_in_ord_ind, &list);
1896 ath10k_warn(ar, "failed to pop paddr list: %d\n", ret);
1897 htt->rx_confused = true;
1901 /* Offloaded frames are very different and need to be handled
1905 ath10k_htt_rx_h_rx_offload(ar, &list);
1907 while (!skb_queue_empty(&list)) {
1908 __skb_queue_head_init(&amsdu);
1909 ret = ath10k_htt_rx_extract_amsdu(&list, &amsdu);
1912 /* Note: The in-order indication may report interleaved
1913 * frames from different PPDUs meaning reported rx rate
1914 * to mac80211 isn't accurate/reliable. It's still
1915 * better to report something than nothing though. This
1916 * should still give an idea about rx rate to the user.
1918 ath10k_htt_rx_h_ppdu(ar, &amsdu, status, vdev_id);
1919 ath10k_htt_rx_h_filter(ar, &amsdu, status);
1920 ath10k_htt_rx_h_mpdu(ar, &amsdu, status);
1921 ath10k_htt_rx_h_deliver(ar, &amsdu, status);
1926 /* Should not happen. */
1927 ath10k_warn(ar, "failed to extract amsdu: %d\n", ret);
1928 htt->rx_confused = true;
1929 __skb_queue_purge(&list);
1934 tasklet_schedule(&htt->rx_replenish_task);
1937 static void ath10k_htt_rx_tx_fetch_resp_id_confirm(struct ath10k *ar,
1938 const __le32 *resp_ids,
1944 ath10k_dbg(ar, ATH10K_DBG_HTT, "htt rx tx fetch confirm num_resp_ids %d\n",
1947 for (i = 0; i < num_resp_ids; i++) {
1948 resp_id = le32_to_cpu(resp_ids[i]);
1950 ath10k_dbg(ar, ATH10K_DBG_HTT, "htt rx tx fetch confirm resp_id %u\n",
1953 /* TODO: free resp_id */
1957 static void ath10k_htt_rx_tx_fetch_ind(struct ath10k *ar, struct sk_buff *skb)
1959 struct ieee80211_hw *hw = ar->hw;
1960 struct ieee80211_txq *txq;
1961 struct htt_resp *resp = (struct htt_resp *)skb->data;
1962 struct htt_tx_fetch_record *record;
1964 size_t max_num_bytes;
1965 size_t max_num_msdus;
1968 const __le32 *resp_ids;
1976 ath10k_dbg(ar, ATH10K_DBG_HTT, "htt rx tx fetch ind\n");
1978 len = sizeof(resp->hdr) + sizeof(resp->tx_fetch_ind);
1979 if (unlikely(skb->len < len)) {
1980 ath10k_warn(ar, "received corrupted tx_fetch_ind event: buffer too short\n");
1984 num_records = le16_to_cpu(resp->tx_fetch_ind.num_records);
1985 num_resp_ids = le16_to_cpu(resp->tx_fetch_ind.num_resp_ids);
1987 len += sizeof(resp->tx_fetch_ind.records[0]) * num_records;
1988 len += sizeof(resp->tx_fetch_ind.resp_ids[0]) * num_resp_ids;
1990 if (unlikely(skb->len < len)) {
1991 ath10k_warn(ar, "received corrupted tx_fetch_ind event: too many records/resp_ids\n");
1995 ath10k_dbg(ar, ATH10K_DBG_HTT, "htt rx tx fetch ind num records %hu num resps %hu seq %hu\n",
1996 num_records, num_resp_ids,
1997 le16_to_cpu(resp->tx_fetch_ind.fetch_seq_num));
1999 if (!ar->htt.tx_q_state.enabled) {
2000 ath10k_warn(ar, "received unexpected tx_fetch_ind event: not enabled\n");
2004 if (ar->htt.tx_q_state.mode == HTT_TX_MODE_SWITCH_PUSH) {
2005 ath10k_warn(ar, "received unexpected tx_fetch_ind event: in push mode\n");
2011 for (i = 0; i < num_records; i++) {
2012 record = &resp->tx_fetch_ind.records[i];
2013 peer_id = MS(le16_to_cpu(record->info),
2014 HTT_TX_FETCH_RECORD_INFO_PEER_ID);
2015 tid = MS(le16_to_cpu(record->info),
2016 HTT_TX_FETCH_RECORD_INFO_TID);
2017 max_num_msdus = le16_to_cpu(record->num_msdus);
2018 max_num_bytes = le32_to_cpu(record->num_bytes);
2020 ath10k_dbg(ar, ATH10K_DBG_HTT, "htt rx tx fetch record %i peer_id %hu tid %hhu msdus %zu bytes %zu\n",
2021 i, peer_id, tid, max_num_msdus, max_num_bytes);
2023 if (unlikely(peer_id >= ar->htt.tx_q_state.num_peers) ||
2024 unlikely(tid >= ar->htt.tx_q_state.num_tids)) {
2025 ath10k_warn(ar, "received out of range peer_id %hu tid %hhu\n",
2030 spin_lock_bh(&ar->data_lock);
2031 txq = ath10k_mac_txq_lookup(ar, peer_id, tid);
2032 spin_unlock_bh(&ar->data_lock);
2034 /* It is okay to release the lock and use txq because RCU read
2038 if (unlikely(!txq)) {
2039 ath10k_warn(ar, "failed to lookup txq for peer_id %hu tid %hhu\n",
2047 while (num_msdus < max_num_msdus &&
2048 num_bytes < max_num_bytes) {
2049 ret = ath10k_mac_tx_push_txq(hw, txq);
2057 record->num_msdus = cpu_to_le16(num_msdus);
2058 record->num_bytes = cpu_to_le32(num_bytes);
2060 ath10k_htt_tx_txq_recalc(hw, txq);
2065 resp_ids = ath10k_htt_get_tx_fetch_ind_resp_ids(&resp->tx_fetch_ind);
2066 ath10k_htt_rx_tx_fetch_resp_id_confirm(ar, resp_ids, num_resp_ids);
2068 ret = ath10k_htt_tx_fetch_resp(ar,
2069 resp->tx_fetch_ind.token,
2070 resp->tx_fetch_ind.fetch_seq_num,
2071 resp->tx_fetch_ind.records,
2073 if (unlikely(ret)) {
2074 ath10k_warn(ar, "failed to submit tx fetch resp for token 0x%08x: %d\n",
2075 le32_to_cpu(resp->tx_fetch_ind.token), ret);
2076 /* FIXME: request fw restart */
2079 ath10k_htt_tx_txq_sync(ar);
2082 static void ath10k_htt_rx_tx_fetch_confirm(struct ath10k *ar,
2083 struct sk_buff *skb)
2085 const struct htt_resp *resp = (void *)skb->data;
2089 ath10k_dbg(ar, ATH10K_DBG_HTT, "htt rx tx fetch confirm\n");
2091 len = sizeof(resp->hdr) + sizeof(resp->tx_fetch_confirm);
2092 if (unlikely(skb->len < len)) {
2093 ath10k_warn(ar, "received corrupted tx_fetch_confirm event: buffer too short\n");
2097 num_resp_ids = le16_to_cpu(resp->tx_fetch_confirm.num_resp_ids);
2098 len += sizeof(resp->tx_fetch_confirm.resp_ids[0]) * num_resp_ids;
2100 if (unlikely(skb->len < len)) {
2101 ath10k_warn(ar, "received corrupted tx_fetch_confirm event: resp_ids buffer overflow\n");
2105 ath10k_htt_rx_tx_fetch_resp_id_confirm(ar,
2106 resp->tx_fetch_confirm.resp_ids,
2110 static void ath10k_htt_rx_tx_mode_switch_ind(struct ath10k *ar,
2111 struct sk_buff *skb)
2113 const struct htt_resp *resp = (void *)skb->data;
2114 const struct htt_tx_mode_switch_record *record;
2115 struct ieee80211_txq *txq;
2116 struct ath10k_txq *artxq;
2119 enum htt_tx_mode_switch_mode mode;
2128 ath10k_dbg(ar, ATH10K_DBG_HTT, "htt rx tx mode switch ind\n");
2130 len = sizeof(resp->hdr) + sizeof(resp->tx_mode_switch_ind);
2131 if (unlikely(skb->len < len)) {
2132 ath10k_warn(ar, "received corrupted tx_mode_switch_ind event: buffer too short\n");
2136 info0 = le16_to_cpu(resp->tx_mode_switch_ind.info0);
2137 info1 = le16_to_cpu(resp->tx_mode_switch_ind.info1);
2139 enable = !!(info0 & HTT_TX_MODE_SWITCH_IND_INFO0_ENABLE);
2140 num_records = MS(info0, HTT_TX_MODE_SWITCH_IND_INFO1_THRESHOLD);
2141 mode = MS(info1, HTT_TX_MODE_SWITCH_IND_INFO1_MODE);
2142 threshold = MS(info1, HTT_TX_MODE_SWITCH_IND_INFO1_THRESHOLD);
2144 ath10k_dbg(ar, ATH10K_DBG_HTT,
2145 "htt rx tx mode switch ind info0 0x%04hx info1 0x%04hx enable %d num records %zd mode %d threshold %hu\n",
2146 info0, info1, enable, num_records, mode, threshold);
2148 len += sizeof(resp->tx_mode_switch_ind.records[0]) * num_records;
2150 if (unlikely(skb->len < len)) {
2151 ath10k_warn(ar, "received corrupted tx_mode_switch_mode_ind event: too many records\n");
2156 case HTT_TX_MODE_SWITCH_PUSH:
2157 case HTT_TX_MODE_SWITCH_PUSH_PULL:
2160 ath10k_warn(ar, "received invalid tx_mode_switch_mode_ind mode %d, ignoring\n",
2168 ar->htt.tx_q_state.enabled = enable;
2169 ar->htt.tx_q_state.mode = mode;
2170 ar->htt.tx_q_state.num_push_allowed = threshold;
2174 for (i = 0; i < num_records; i++) {
2175 record = &resp->tx_mode_switch_ind.records[i];
2176 info0 = le16_to_cpu(record->info0);
2177 peer_id = MS(info0, HTT_TX_MODE_SWITCH_RECORD_INFO0_PEER_ID);
2178 tid = MS(info0, HTT_TX_MODE_SWITCH_RECORD_INFO0_TID);
2180 if (unlikely(peer_id >= ar->htt.tx_q_state.num_peers) ||
2181 unlikely(tid >= ar->htt.tx_q_state.num_tids)) {
2182 ath10k_warn(ar, "received out of range peer_id %hu tid %hhu\n",
2187 spin_lock_bh(&ar->data_lock);
2188 txq = ath10k_mac_txq_lookup(ar, peer_id, tid);
2189 spin_unlock_bh(&ar->data_lock);
2191 /* It is okay to release the lock and use txq because RCU read
2195 if (unlikely(!txq)) {
2196 ath10k_warn(ar, "failed to lookup txq for peer_id %hu tid %hhu\n",
2201 spin_lock_bh(&ar->htt.tx_lock);
2202 artxq = (void *)txq->drv_priv;
2203 artxq->num_push_allowed = le16_to_cpu(record->num_max_msdus);
2204 spin_unlock_bh(&ar->htt.tx_lock);
2209 ath10k_mac_tx_push_pending(ar);
2212 static inline enum ieee80211_band phy_mode_to_band(u32 phy_mode)
2214 enum ieee80211_band band;
2218 case MODE_11NA_HT20:
2219 case MODE_11NA_HT40:
2220 case MODE_11AC_VHT20:
2221 case MODE_11AC_VHT40:
2222 case MODE_11AC_VHT80:
2223 band = IEEE80211_BAND_5GHZ;
2228 case MODE_11NG_HT20:
2229 case MODE_11NG_HT40:
2230 case MODE_11AC_VHT20_2G:
2231 case MODE_11AC_VHT40_2G:
2232 case MODE_11AC_VHT80_2G:
2234 band = IEEE80211_BAND_2GHZ;
2240 void ath10k_htt_t2h_msg_handler(struct ath10k *ar, struct sk_buff *skb)
2242 struct ath10k_htt *htt = &ar->htt;
2243 struct htt_resp *resp = (struct htt_resp *)skb->data;
2244 enum htt_t2h_msg_type type;
2246 /* confirm alignment */
2247 if (!IS_ALIGNED((unsigned long)skb->data, 4))
2248 ath10k_warn(ar, "unaligned htt message, expect trouble\n");
2250 ath10k_dbg(ar, ATH10K_DBG_HTT, "htt rx, msg_type: 0x%0X\n",
2251 resp->hdr.msg_type);
2253 if (resp->hdr.msg_type >= ar->htt.t2h_msg_types_max) {
2254 ath10k_dbg(ar, ATH10K_DBG_HTT, "htt rx, unsupported msg_type: 0x%0X\n max: 0x%0X",
2255 resp->hdr.msg_type, ar->htt.t2h_msg_types_max);
2256 dev_kfree_skb_any(skb);
2259 type = ar->htt.t2h_msg_types[resp->hdr.msg_type];
2262 case HTT_T2H_MSG_TYPE_VERSION_CONF: {
2263 htt->target_version_major = resp->ver_resp.major;
2264 htt->target_version_minor = resp->ver_resp.minor;
2265 complete(&htt->target_version_received);
2268 case HTT_T2H_MSG_TYPE_RX_IND:
2269 skb_queue_tail(&htt->rx_compl_q, skb);
2270 tasklet_schedule(&htt->txrx_compl_task);
2272 case HTT_T2H_MSG_TYPE_PEER_MAP: {
2273 struct htt_peer_map_event ev = {
2274 .vdev_id = resp->peer_map.vdev_id,
2275 .peer_id = __le16_to_cpu(resp->peer_map.peer_id),
2277 memcpy(ev.addr, resp->peer_map.addr, sizeof(ev.addr));
2278 ath10k_peer_map_event(htt, &ev);
2281 case HTT_T2H_MSG_TYPE_PEER_UNMAP: {
2282 struct htt_peer_unmap_event ev = {
2283 .peer_id = __le16_to_cpu(resp->peer_unmap.peer_id),
2285 ath10k_peer_unmap_event(htt, &ev);
2288 case HTT_T2H_MSG_TYPE_MGMT_TX_COMPLETION: {
2289 struct htt_tx_done tx_done = {};
2290 int status = __le32_to_cpu(resp->mgmt_tx_completion.status);
2292 tx_done.msdu_id = __le32_to_cpu(resp->mgmt_tx_completion.desc_id);
2295 case HTT_MGMT_TX_STATUS_OK:
2296 tx_done.status = HTT_TX_COMPL_STATE_ACK;
2298 case HTT_MGMT_TX_STATUS_RETRY:
2299 tx_done.status = HTT_TX_COMPL_STATE_NOACK;
2301 case HTT_MGMT_TX_STATUS_DROP:
2302 tx_done.status = HTT_TX_COMPL_STATE_DISCARD;
2306 status = ath10k_txrx_tx_unref(htt, &tx_done);
2308 spin_lock_bh(&htt->tx_lock);
2309 ath10k_htt_tx_mgmt_dec_pending(htt);
2310 spin_unlock_bh(&htt->tx_lock);
2312 ath10k_mac_tx_push_pending(ar);
2315 case HTT_T2H_MSG_TYPE_TX_COMPL_IND:
2316 ath10k_htt_rx_tx_compl_ind(htt->ar, skb);
2317 tasklet_schedule(&htt->txrx_compl_task);
2319 case HTT_T2H_MSG_TYPE_SEC_IND: {
2320 struct ath10k *ar = htt->ar;
2321 struct htt_security_indication *ev = &resp->security_indication;
2323 ath10k_dbg(ar, ATH10K_DBG_HTT,
2324 "sec ind peer_id %d unicast %d type %d\n",
2325 __le16_to_cpu(ev->peer_id),
2326 !!(ev->flags & HTT_SECURITY_IS_UNICAST),
2327 MS(ev->flags, HTT_SECURITY_TYPE));
2328 complete(&ar->install_key_done);
2331 case HTT_T2H_MSG_TYPE_RX_FRAG_IND: {
2332 ath10k_dbg_dump(ar, ATH10K_DBG_HTT_DUMP, NULL, "htt event: ",
2333 skb->data, skb->len);
2334 ath10k_htt_rx_frag_handler(htt, &resp->rx_frag_ind);
2337 case HTT_T2H_MSG_TYPE_TEST:
2339 case HTT_T2H_MSG_TYPE_STATS_CONF:
2340 trace_ath10k_htt_stats(ar, skb->data, skb->len);
2342 case HTT_T2H_MSG_TYPE_TX_INSPECT_IND:
2343 /* Firmware can return tx frames if it's unable to fully
2344 * process them and suspects host may be able to fix it. ath10k
2345 * sends all tx frames as already inspected so this shouldn't
2346 * happen unless fw has a bug.
2348 ath10k_warn(ar, "received an unexpected htt tx inspect event\n");
2350 case HTT_T2H_MSG_TYPE_RX_ADDBA:
2351 ath10k_htt_rx_addba(ar, resp);
2353 case HTT_T2H_MSG_TYPE_RX_DELBA:
2354 ath10k_htt_rx_delba(ar, resp);
2356 case HTT_T2H_MSG_TYPE_PKTLOG: {
2357 struct ath10k_pktlog_hdr *hdr =
2358 (struct ath10k_pktlog_hdr *)resp->pktlog_msg.payload;
2360 trace_ath10k_htt_pktlog(ar, resp->pktlog_msg.payload,
2362 __le16_to_cpu(hdr->size));
2365 case HTT_T2H_MSG_TYPE_RX_FLUSH: {
2366 /* Ignore this event because mac80211 takes care of Rx
2367 * aggregation reordering.
2371 case HTT_T2H_MSG_TYPE_RX_IN_ORD_PADDR_IND: {
2372 skb_queue_tail(&htt->rx_in_ord_compl_q, skb);
2373 tasklet_schedule(&htt->txrx_compl_task);
2376 case HTT_T2H_MSG_TYPE_TX_CREDIT_UPDATE_IND:
2378 case HTT_T2H_MSG_TYPE_CHAN_CHANGE: {
2379 u32 phymode = __le32_to_cpu(resp->chan_change.phymode);
2380 u32 freq = __le32_to_cpu(resp->chan_change.freq);
2383 __ieee80211_get_channel(ar->hw->wiphy, freq);
2384 ath10k_dbg(ar, ATH10K_DBG_HTT,
2385 "htt chan change freq %u phymode %s\n",
2386 freq, ath10k_wmi_phymode_str(phymode));
2389 case HTT_T2H_MSG_TYPE_AGGR_CONF:
2391 case HTT_T2H_MSG_TYPE_TX_FETCH_IND: {
2392 struct sk_buff *tx_fetch_ind = skb_copy(skb, GFP_ATOMIC);
2394 if (!tx_fetch_ind) {
2395 ath10k_warn(ar, "failed to copy htt tx fetch ind\n");
2398 skb_queue_tail(&htt->tx_fetch_ind_q, tx_fetch_ind);
2399 tasklet_schedule(&htt->txrx_compl_task);
2402 case HTT_T2H_MSG_TYPE_TX_FETCH_CONFIRM:
2403 ath10k_htt_rx_tx_fetch_confirm(ar, skb);
2405 case HTT_T2H_MSG_TYPE_TX_MODE_SWITCH_IND:
2406 ath10k_htt_rx_tx_mode_switch_ind(ar, skb);
2408 case HTT_T2H_MSG_TYPE_EN_STATS:
2410 ath10k_warn(ar, "htt event (%d) not handled\n",
2411 resp->hdr.msg_type);
2412 ath10k_dbg_dump(ar, ATH10K_DBG_HTT_DUMP, NULL, "htt event: ",
2413 skb->data, skb->len);
2417 /* Free the indication buffer */
2418 dev_kfree_skb_any(skb);
2420 EXPORT_SYMBOL(ath10k_htt_t2h_msg_handler);
2422 void ath10k_htt_rx_pktlog_completion_handler(struct ath10k *ar,
2423 struct sk_buff *skb)
2425 trace_ath10k_htt_pktlog(ar, skb->data, skb->len);
2426 dev_kfree_skb_any(skb);
2428 EXPORT_SYMBOL(ath10k_htt_rx_pktlog_completion_handler);
2430 static void ath10k_htt_txrx_compl_task(unsigned long ptr)
2432 struct ath10k_htt *htt = (struct ath10k_htt *)ptr;
2433 struct ath10k *ar = htt->ar;
2434 struct htt_tx_done tx_done = {};
2435 struct sk_buff_head rx_q;
2436 struct sk_buff_head rx_ind_q;
2437 struct sk_buff_head tx_ind_q;
2438 struct htt_resp *resp;
2439 struct sk_buff *skb;
2440 unsigned long flags;
2442 __skb_queue_head_init(&rx_q);
2443 __skb_queue_head_init(&rx_ind_q);
2444 __skb_queue_head_init(&tx_ind_q);
2446 spin_lock_irqsave(&htt->rx_compl_q.lock, flags);
2447 skb_queue_splice_init(&htt->rx_compl_q, &rx_q);
2448 spin_unlock_irqrestore(&htt->rx_compl_q.lock, flags);
2450 spin_lock_irqsave(&htt->rx_in_ord_compl_q.lock, flags);
2451 skb_queue_splice_init(&htt->rx_in_ord_compl_q, &rx_ind_q);
2452 spin_unlock_irqrestore(&htt->rx_in_ord_compl_q.lock, flags);
2454 spin_lock_irqsave(&htt->tx_fetch_ind_q.lock, flags);
2455 skb_queue_splice_init(&htt->tx_fetch_ind_q, &tx_ind_q);
2456 spin_unlock_irqrestore(&htt->tx_fetch_ind_q.lock, flags);
2458 /* kfifo_get: called only within txrx_tasklet so it's neatly serialized.
2459 * From kfifo_get() documentation:
2460 * Note that with only one concurrent reader and one concurrent writer,
2461 * you don't need extra locking to use these macro.
2463 while (kfifo_get(&htt->txdone_fifo, &tx_done))
2464 ath10k_txrx_tx_unref(htt, &tx_done);
2466 while ((skb = __skb_dequeue(&tx_ind_q))) {
2467 ath10k_htt_rx_tx_fetch_ind(ar, skb);
2468 dev_kfree_skb_any(skb);
2471 ath10k_mac_tx_push_pending(ar);
2473 while ((skb = __skb_dequeue(&rx_q))) {
2474 resp = (struct htt_resp *)skb->data;
2475 spin_lock_bh(&htt->rx_ring.lock);
2476 ath10k_htt_rx_handler(htt, &resp->rx_ind);
2477 spin_unlock_bh(&htt->rx_ring.lock);
2478 dev_kfree_skb_any(skb);
2481 while ((skb = __skb_dequeue(&rx_ind_q))) {
2482 spin_lock_bh(&htt->rx_ring.lock);
2483 ath10k_htt_rx_in_ord_ind(ar, skb);
2484 spin_unlock_bh(&htt->rx_ring.lock);
2485 dev_kfree_skb_any(skb);