Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2005-2011 Atheros Communications Inc. |
| 3 | * Copyright (c) 2011-2013 Qualcomm Atheros, Inc. |
| 4 | * |
| 5 | * Permission to use, copy, modify, and/or distribute this software for any |
| 6 | * purpose with or without fee is hereby granted, provided that the above |
| 7 | * copyright notice and this permission notice appear in all copies. |
| 8 | * |
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 16 | */ |
| 17 | |
Michal Kazior | edb8236 | 2013-07-05 16:15:14 +0300 | [diff] [blame] | 18 | #include "core.h" |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 19 | #include "htc.h" |
| 20 | #include "htt.h" |
| 21 | #include "txrx.h" |
| 22 | #include "debug.h" |
Kalle Valo | a9bf050 | 2013-09-03 11:43:55 +0300 | [diff] [blame] | 23 | #include "trace.h" |
Michal Kazior | aa5b4fb | 2014-07-23 12:20:33 +0200 | [diff] [blame] | 24 | #include "mac.h" |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 25 | |
| 26 | #include <linux/log2.h> |
| 27 | |
Michal Kazior | c545070 | 2015-01-24 12:14:48 +0200 | [diff] [blame] | 28 | #define HTT_RX_RING_SIZE HTT_RX_RING_SIZE_MAX |
| 29 | #define HTT_RX_RING_FILL_LEVEL (((HTT_RX_RING_SIZE) / 2) - 1) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 30 | |
| 31 | /* when under memory pressure rx ring refill may fail and needs a retry */ |
| 32 | #define HTT_RX_RING_REFILL_RETRY_MS 50 |
| 33 | |
Michal Kazior | f6dc209 | 2013-09-26 10:12:22 +0300 | [diff] [blame] | 34 | static int ath10k_htt_rx_get_csum_state(struct sk_buff *skb); |
Michal Kazior | 6c5151a | 2014-02-27 18:50:04 +0200 | [diff] [blame] | 35 | static void ath10k_htt_txrx_compl_task(unsigned long ptr); |
Michal Kazior | f6dc209 | 2013-09-26 10:12:22 +0300 | [diff] [blame] | 36 | |
Michal Kazior | c545070 | 2015-01-24 12:14:48 +0200 | [diff] [blame] | 37 | static struct sk_buff * |
| 38 | ath10k_htt_rx_find_skb_paddr(struct ath10k *ar, u32 paddr) |
| 39 | { |
| 40 | struct ath10k_skb_rxcb *rxcb; |
| 41 | |
| 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); |
| 45 | |
| 46 | WARN_ON_ONCE(1); |
| 47 | return NULL; |
| 48 | } |
| 49 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 50 | static void ath10k_htt_rx_ring_free(struct ath10k_htt *htt) |
| 51 | { |
| 52 | struct sk_buff *skb; |
Michal Kazior | c545070 | 2015-01-24 12:14:48 +0200 | [diff] [blame] | 53 | struct ath10k_skb_rxcb *rxcb; |
| 54 | struct hlist_node *n; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 55 | int i; |
| 56 | |
Michal Kazior | c545070 | 2015-01-24 12:14:48 +0200 | [diff] [blame] | 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), |
| 62 | DMA_FROM_DEVICE); |
| 63 | hash_del(&rxcb->hlist); |
| 64 | dev_kfree_skb_any(skb); |
| 65 | } |
| 66 | } else { |
| 67 | for (i = 0; i < htt->rx_ring.size; i++) { |
| 68 | skb = htt->rx_ring.netbufs_ring[i]; |
| 69 | if (!skb) |
| 70 | continue; |
| 71 | |
| 72 | rxcb = ATH10K_SKB_RXCB(skb); |
| 73 | dma_unmap_single(htt->ar->dev, rxcb->paddr, |
| 74 | skb->len + skb_tailroom(skb), |
| 75 | DMA_FROM_DEVICE); |
| 76 | dev_kfree_skb_any(skb); |
| 77 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | htt->rx_ring.fill_cnt = 0; |
Michal Kazior | c545070 | 2015-01-24 12:14:48 +0200 | [diff] [blame] | 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])); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | static int __ath10k_htt_rx_ring_fill_n(struct ath10k_htt *htt, int num) |
| 87 | { |
| 88 | struct htt_rx_desc *rx_desc; |
Michal Kazior | c545070 | 2015-01-24 12:14:48 +0200 | [diff] [blame] | 89 | struct ath10k_skb_rxcb *rxcb; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 90 | struct sk_buff *skb; |
| 91 | dma_addr_t paddr; |
| 92 | int ret = 0, idx; |
| 93 | |
Michal Kazior | c545070 | 2015-01-24 12:14:48 +0200 | [diff] [blame] | 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. |
| 98 | */ |
| 99 | BUILD_BUG_ON(HTT_RX_RING_FILL_LEVEL >= HTT_RX_RING_SIZE / 2); |
| 100 | |
Kalle Valo | 8cc7f26 | 2014-09-14 12:50:39 +0300 | [diff] [blame] | 101 | idx = __le32_to_cpu(*htt->rx_ring.alloc_idx.vaddr); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 102 | while (num > 0) { |
| 103 | skb = dev_alloc_skb(HTT_RX_BUF_SIZE + HTT_RX_DESC_ALIGN); |
| 104 | if (!skb) { |
| 105 | ret = -ENOMEM; |
| 106 | goto fail; |
| 107 | } |
| 108 | |
| 109 | if (!IS_ALIGNED((unsigned long)skb->data, HTT_RX_DESC_ALIGN)) |
| 110 | skb_pull(skb, |
| 111 | PTR_ALIGN(skb->data, HTT_RX_DESC_ALIGN) - |
| 112 | skb->data); |
| 113 | |
| 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); |
| 117 | |
| 118 | paddr = dma_map_single(htt->ar->dev, skb->data, |
| 119 | skb->len + skb_tailroom(skb), |
| 120 | DMA_FROM_DEVICE); |
| 121 | |
| 122 | if (unlikely(dma_mapping_error(htt->ar->dev, paddr))) { |
| 123 | dev_kfree_skb_any(skb); |
| 124 | ret = -ENOMEM; |
| 125 | goto fail; |
| 126 | } |
| 127 | |
Michal Kazior | c545070 | 2015-01-24 12:14:48 +0200 | [diff] [blame] | 128 | rxcb = ATH10K_SKB_RXCB(skb); |
| 129 | rxcb->paddr = paddr; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 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++; |
| 133 | |
Michal Kazior | c545070 | 2015-01-24 12:14:48 +0200 | [diff] [blame] | 134 | if (htt->rx_ring.in_ord_rx) { |
| 135 | hash_add(htt->rx_ring.skb_table, |
| 136 | &ATH10K_SKB_RXCB(skb)->hlist, |
| 137 | (u32)paddr); |
| 138 | } |
| 139 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 140 | num--; |
| 141 | idx++; |
| 142 | idx &= htt->rx_ring.size_mask; |
| 143 | } |
| 144 | |
| 145 | fail: |
Vasanthakumar Thiagarajan | 5de6dfc | 2015-01-09 22:49:46 +0530 | [diff] [blame] | 146 | /* |
| 147 | * Make sure the rx buffer is updated before available buffer |
| 148 | * index to avoid any potential rx ring corruption. |
| 149 | */ |
| 150 | mb(); |
Kalle Valo | 8cc7f26 | 2014-09-14 12:50:39 +0300 | [diff] [blame] | 151 | *htt->rx_ring.alloc_idx.vaddr = __cpu_to_le32(idx); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 152 | return ret; |
| 153 | } |
| 154 | |
| 155 | static int ath10k_htt_rx_ring_fill_n(struct ath10k_htt *htt, int num) |
| 156 | { |
| 157 | lockdep_assert_held(&htt->rx_ring.lock); |
| 158 | return __ath10k_htt_rx_ring_fill_n(htt, num); |
| 159 | } |
| 160 | |
| 161 | static void ath10k_htt_rx_msdu_buff_replenish(struct ath10k_htt *htt) |
| 162 | { |
Michal Kazior | 6e712d4 | 2013-09-24 10:18:36 +0200 | [diff] [blame] | 163 | int ret, num_deficit, num_to_fill; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 164 | |
Michal Kazior | 6e712d4 | 2013-09-24 10:18:36 +0200 | [diff] [blame] | 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. |
| 170 | * |
| 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. |
| 177 | * |
| 178 | * This probably comes at a cost of lower maximum throughput but |
Ben Greear | 3eafdfd | 2015-02-15 16:50:39 +0200 | [diff] [blame] | 179 | * improves the average and stability. */ |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 180 | spin_lock_bh(&htt->rx_ring.lock); |
Michal Kazior | 6e712d4 | 2013-09-24 10:18:36 +0200 | [diff] [blame] | 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; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 184 | ret = ath10k_htt_rx_ring_fill_n(htt, num_to_fill); |
| 185 | if (ret == -ENOMEM) { |
| 186 | /* |
| 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. |
| 191 | */ |
| 192 | mod_timer(&htt->rx_ring.refill_retry_timer, jiffies + |
| 193 | msecs_to_jiffies(HTT_RX_RING_REFILL_RETRY_MS)); |
Michal Kazior | 6e712d4 | 2013-09-24 10:18:36 +0200 | [diff] [blame] | 194 | } else if (num_deficit > 0) { |
| 195 | tasklet_schedule(&htt->rx_replenish_task); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 196 | } |
| 197 | spin_unlock_bh(&htt->rx_ring.lock); |
| 198 | } |
| 199 | |
| 200 | static void ath10k_htt_rx_ring_refill_retry(unsigned long arg) |
| 201 | { |
| 202 | struct ath10k_htt *htt = (struct ath10k_htt *)arg; |
Kalle Valo | af762c0 | 2014-09-14 12:50:17 +0300 | [diff] [blame] | 203 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 204 | ath10k_htt_rx_msdu_buff_replenish(htt); |
| 205 | } |
| 206 | |
Michal Kazior | c545070 | 2015-01-24 12:14:48 +0200 | [diff] [blame] | 207 | int ath10k_htt_rx_ring_refill(struct ath10k *ar) |
Michal Kazior | 3e841fd | 2014-05-14 16:23:31 +0300 | [diff] [blame] | 208 | { |
Michal Kazior | c545070 | 2015-01-24 12:14:48 +0200 | [diff] [blame] | 209 | struct ath10k_htt *htt = &ar->htt; |
| 210 | int ret; |
Michal Kazior | 3e841fd | 2014-05-14 16:23:31 +0300 | [diff] [blame] | 211 | |
Michal Kazior | c545070 | 2015-01-24 12:14:48 +0200 | [diff] [blame] | 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); |
Michal Kazior | 3e841fd | 2014-05-14 16:23:31 +0300 | [diff] [blame] | 216 | |
Michal Kazior | c545070 | 2015-01-24 12:14:48 +0200 | [diff] [blame] | 217 | if (ret) |
| 218 | ath10k_htt_rx_ring_free(htt); |
| 219 | |
| 220 | return ret; |
Michal Kazior | 3e841fd | 2014-05-14 16:23:31 +0300 | [diff] [blame] | 221 | } |
| 222 | |
Michal Kazior | 95bf21f | 2014-05-16 17:15:39 +0300 | [diff] [blame] | 223 | void ath10k_htt_rx_free(struct ath10k_htt *htt) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 224 | { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 225 | del_timer_sync(&htt->rx_ring.refill_retry_timer); |
Michal Kazior | 6e712d4 | 2013-09-24 10:18:36 +0200 | [diff] [blame] | 226 | tasklet_kill(&htt->rx_replenish_task); |
Michal Kazior | 6c5151a | 2014-02-27 18:50:04 +0200 | [diff] [blame] | 227 | tasklet_kill(&htt->txrx_compl_task); |
| 228 | |
Michal Kazior | 6c5151a | 2014-02-27 18:50:04 +0200 | [diff] [blame] | 229 | skb_queue_purge(&htt->rx_compl_q); |
Michal Kazior | c545070 | 2015-01-24 12:14:48 +0200 | [diff] [blame] | 230 | skb_queue_purge(&htt->rx_in_ord_compl_q); |
Michal Kazior | 426e10e | 2016-03-06 16:14:43 +0200 | [diff] [blame] | 231 | skb_queue_purge(&htt->tx_fetch_ind_q); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 232 | |
Michal Kazior | c545070 | 2015-01-24 12:14:48 +0200 | [diff] [blame] | 233 | ath10k_htt_rx_ring_free(htt); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 234 | |
| 235 | dma_free_coherent(htt->ar->dev, |
| 236 | (htt->rx_ring.size * |
| 237 | sizeof(htt->rx_ring.paddrs_ring)), |
| 238 | htt->rx_ring.paddrs_ring, |
| 239 | htt->rx_ring.base_paddr); |
| 240 | |
| 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); |
| 245 | |
| 246 | kfree(htt->rx_ring.netbufs_ring); |
| 247 | } |
| 248 | |
| 249 | static inline struct sk_buff *ath10k_htt_rx_netbuf_pop(struct ath10k_htt *htt) |
| 250 | { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 251 | struct ath10k *ar = htt->ar; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 252 | int idx; |
| 253 | struct sk_buff *msdu; |
| 254 | |
Michal Kazior | 4596708 | 2014-02-27 18:50:05 +0200 | [diff] [blame] | 255 | lockdep_assert_held(&htt->rx_ring.lock); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 256 | |
Michal Kazior | 8d60ee8 | 2014-02-27 18:50:05 +0200 | [diff] [blame] | 257 | if (htt->rx_ring.fill_cnt == 0) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 258 | ath10k_warn(ar, "tried to pop sk_buff from an empty rx ring\n"); |
Michal Kazior | 8d60ee8 | 2014-02-27 18:50:05 +0200 | [diff] [blame] | 259 | return NULL; |
| 260 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 261 | |
| 262 | idx = htt->rx_ring.sw_rd_idx.msdu_payld; |
| 263 | msdu = htt->rx_ring.netbufs_ring[idx]; |
Michal Kazior | 3e841fd | 2014-05-14 16:23:31 +0300 | [diff] [blame] | 264 | htt->rx_ring.netbufs_ring[idx] = NULL; |
Michal Kazior | c545070 | 2015-01-24 12:14:48 +0200 | [diff] [blame] | 265 | htt->rx_ring.paddrs_ring[idx] = 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 266 | |
| 267 | idx++; |
| 268 | idx &= htt->rx_ring.size_mask; |
| 269 | htt->rx_ring.sw_rd_idx.msdu_payld = idx; |
| 270 | htt->rx_ring.fill_cnt--; |
| 271 | |
Michal Kazior | 4de0280 | 2014-10-23 17:04:23 +0300 | [diff] [blame] | 272 | dma_unmap_single(htt->ar->dev, |
Michal Kazior | 8582bf3 | 2015-01-24 12:14:47 +0200 | [diff] [blame] | 273 | ATH10K_SKB_RXCB(msdu)->paddr, |
Michal Kazior | 4de0280 | 2014-10-23 17:04:23 +0300 | [diff] [blame] | 274 | msdu->len + skb_tailroom(msdu), |
| 275 | DMA_FROM_DEVICE); |
| 276 | ath10k_dbg_dump(ar, ATH10K_DBG_HTT_DUMP, NULL, "htt rx netbuf pop: ", |
| 277 | msdu->data, msdu->len + skb_tailroom(msdu)); |
Michal Kazior | 4de0280 | 2014-10-23 17:04:23 +0300 | [diff] [blame] | 278 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 279 | return msdu; |
| 280 | } |
| 281 | |
Janusz Dziedzic | d84dd60 | 2014-03-24 21:23:20 +0100 | [diff] [blame] | 282 | /* return: < 0 fatal error, 0 - non chained msdu, 1 chained msdu */ |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 283 | static int ath10k_htt_rx_amsdu_pop(struct ath10k_htt *htt, |
Michal Kazior | f0e2770 | 2014-11-18 09:24:49 +0200 | [diff] [blame] | 284 | struct sk_buff_head *amsdu) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 285 | { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 286 | struct ath10k *ar = htt->ar; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 287 | int msdu_len, msdu_chaining = 0; |
Michal Kazior | 9aa505d | 2014-11-18 09:24:47 +0200 | [diff] [blame] | 288 | struct sk_buff *msdu; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 289 | struct htt_rx_desc *rx_desc; |
| 290 | |
Michal Kazior | 4596708 | 2014-02-27 18:50:05 +0200 | [diff] [blame] | 291 | lockdep_assert_held(&htt->rx_ring.lock); |
| 292 | |
Michal Kazior | 9aa505d | 2014-11-18 09:24:47 +0200 | [diff] [blame] | 293 | for (;;) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 294 | int last_msdu, msdu_len_invalid, msdu_chained; |
| 295 | |
Michal Kazior | 9aa505d | 2014-11-18 09:24:47 +0200 | [diff] [blame] | 296 | msdu = ath10k_htt_rx_netbuf_pop(htt); |
| 297 | if (!msdu) { |
Michal Kazior | 9aa505d | 2014-11-18 09:24:47 +0200 | [diff] [blame] | 298 | __skb_queue_purge(amsdu); |
Michal Kazior | e0bd751 | 2014-11-18 09:24:48 +0200 | [diff] [blame] | 299 | return -ENOENT; |
Michal Kazior | 9aa505d | 2014-11-18 09:24:47 +0200 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | __skb_queue_tail(amsdu, msdu); |
| 303 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 304 | rx_desc = (struct htt_rx_desc *)msdu->data; |
| 305 | |
| 306 | /* FIXME: we must report msdu payload since this is what caller |
| 307 | * expects now */ |
| 308 | skb_put(msdu, offsetof(struct htt_rx_desc, msdu_payload)); |
| 309 | skb_pull(msdu, offsetof(struct htt_rx_desc, msdu_payload)); |
| 310 | |
| 311 | /* |
| 312 | * Sanity check - confirm the HW is finished filling in the |
| 313 | * rx data. |
| 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. |
| 318 | */ |
| 319 | if (!(__le32_to_cpu(rx_desc->attention.flags) |
| 320 | & RX_ATTENTION_FLAGS_MSDU_DONE)) { |
Michal Kazior | 9aa505d | 2014-11-18 09:24:47 +0200 | [diff] [blame] | 321 | __skb_queue_purge(amsdu); |
Michal Kazior | e0bd751 | 2014-11-18 09:24:48 +0200 | [diff] [blame] | 322 | return -EIO; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 323 | } |
| 324 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 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)); |
Peter Oh | 1f5dbfb | 2015-07-15 19:01:21 -0700 | [diff] [blame] | 328 | msdu_len = MS(__le32_to_cpu(rx_desc->msdu_start.common.info0), |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 329 | RX_MSDU_START_INFO0_MSDU_LENGTH); |
| 330 | msdu_chained = rx_desc->frag_info.ring2_more_count; |
| 331 | |
| 332 | if (msdu_len_invalid) |
| 333 | msdu_len = 0; |
| 334 | |
| 335 | skb_trim(msdu, 0); |
| 336 | skb_put(msdu, min(msdu_len, HTT_RX_MSDU_SIZE)); |
| 337 | msdu_len -= msdu->len; |
| 338 | |
Michal Kazior | 9aa505d | 2014-11-18 09:24:47 +0200 | [diff] [blame] | 339 | /* Note: Chained buffers do not contain rx descriptor */ |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 340 | while (msdu_chained--) { |
Michal Kazior | 9aa505d | 2014-11-18 09:24:47 +0200 | [diff] [blame] | 341 | msdu = ath10k_htt_rx_netbuf_pop(htt); |
| 342 | if (!msdu) { |
Michal Kazior | 9aa505d | 2014-11-18 09:24:47 +0200 | [diff] [blame] | 343 | __skb_queue_purge(amsdu); |
Michal Kazior | e0bd751 | 2014-11-18 09:24:48 +0200 | [diff] [blame] | 344 | return -ENOENT; |
Michal Kazior | b30595a | 2014-10-23 17:04:24 +0300 | [diff] [blame] | 345 | } |
| 346 | |
Michal Kazior | 9aa505d | 2014-11-18 09:24:47 +0200 | [diff] [blame] | 347 | __skb_queue_tail(amsdu, msdu); |
| 348 | skb_trim(msdu, 0); |
| 349 | skb_put(msdu, min(msdu_len, HTT_RX_BUF_SIZE)); |
| 350 | msdu_len -= msdu->len; |
Michal Kazior | ede9c8e | 2014-05-14 16:23:31 +0300 | [diff] [blame] | 351 | msdu_chaining = 1; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 352 | } |
| 353 | |
Peter Oh | 1f5dbfb | 2015-07-15 19:01:21 -0700 | [diff] [blame] | 354 | last_msdu = __le32_to_cpu(rx_desc->msdu_end.common.info0) & |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 355 | RX_MSDU_END_INFO0_LAST_MSDU; |
| 356 | |
Michal Kazior | b04e204 | 2014-10-23 17:04:27 +0300 | [diff] [blame] | 357 | trace_ath10k_htt_rx_desc(ar, &rx_desc->attention, |
Rajkumar Manoharan | a0883cf | 2014-10-03 08:02:47 +0300 | [diff] [blame] | 358 | sizeof(*rx_desc) - sizeof(u32)); |
Michal Kazior | 9aa505d | 2014-11-18 09:24:47 +0200 | [diff] [blame] | 359 | |
| 360 | if (last_msdu) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 361 | break; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 362 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 363 | |
Michal Kazior | 9aa505d | 2014-11-18 09:24:47 +0200 | [diff] [blame] | 364 | if (skb_queue_empty(amsdu)) |
Janusz Dziedzic | d84dd60 | 2014-03-24 21:23:20 +0100 | [diff] [blame] | 365 | msdu_chaining = -1; |
| 366 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 367 | /* |
| 368 | * Don't refill the ring yet. |
| 369 | * |
| 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. |
| 378 | */ |
| 379 | |
| 380 | return msdu_chaining; |
| 381 | } |
| 382 | |
Michal Kazior | 6e712d4 | 2013-09-24 10:18:36 +0200 | [diff] [blame] | 383 | static void ath10k_htt_rx_replenish_task(unsigned long ptr) |
| 384 | { |
| 385 | struct ath10k_htt *htt = (struct ath10k_htt *)ptr; |
Kalle Valo | af762c0 | 2014-09-14 12:50:17 +0300 | [diff] [blame] | 386 | |
Michal Kazior | 6e712d4 | 2013-09-24 10:18:36 +0200 | [diff] [blame] | 387 | ath10k_htt_rx_msdu_buff_replenish(htt); |
| 388 | } |
| 389 | |
Michal Kazior | c545070 | 2015-01-24 12:14:48 +0200 | [diff] [blame] | 390 | static struct sk_buff *ath10k_htt_rx_pop_paddr(struct ath10k_htt *htt, |
| 391 | u32 paddr) |
| 392 | { |
| 393 | struct ath10k *ar = htt->ar; |
| 394 | struct ath10k_skb_rxcb *rxcb; |
| 395 | struct sk_buff *msdu; |
| 396 | |
| 397 | lockdep_assert_held(&htt->rx_ring.lock); |
| 398 | |
| 399 | msdu = ath10k_htt_rx_find_skb_paddr(ar, paddr); |
| 400 | if (!msdu) |
| 401 | return NULL; |
| 402 | |
| 403 | rxcb = ATH10K_SKB_RXCB(msdu); |
| 404 | hash_del(&rxcb->hlist); |
| 405 | htt->rx_ring.fill_cnt--; |
| 406 | |
| 407 | dma_unmap_single(htt->ar->dev, rxcb->paddr, |
| 408 | msdu->len + skb_tailroom(msdu), |
| 409 | DMA_FROM_DEVICE); |
| 410 | ath10k_dbg_dump(ar, ATH10K_DBG_HTT_DUMP, NULL, "htt rx netbuf pop: ", |
| 411 | msdu->data, msdu->len + skb_tailroom(msdu)); |
| 412 | |
| 413 | return msdu; |
| 414 | } |
| 415 | |
| 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) |
| 419 | { |
| 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; |
| 424 | int msdu_count; |
| 425 | bool is_offload; |
| 426 | u32 paddr; |
| 427 | |
| 428 | lockdep_assert_held(&htt->rx_ring.lock); |
| 429 | |
| 430 | msdu_count = __le16_to_cpu(ev->msdu_count); |
| 431 | is_offload = !!(ev->info & HTT_RX_IN_ORD_IND_INFO_OFFLOAD_MASK); |
| 432 | |
| 433 | while (msdu_count--) { |
| 434 | paddr = __le32_to_cpu(msdu_desc->msdu_paddr); |
| 435 | |
| 436 | msdu = ath10k_htt_rx_pop_paddr(htt, paddr); |
| 437 | if (!msdu) { |
| 438 | __skb_queue_purge(list); |
| 439 | return -ENOENT; |
| 440 | } |
| 441 | |
| 442 | __skb_queue_tail(list, msdu); |
| 443 | |
| 444 | if (!is_offload) { |
| 445 | rxd = (void *)msdu->data; |
| 446 | |
| 447 | trace_ath10k_htt_rx_desc(ar, rxd, sizeof(*rxd)); |
| 448 | |
| 449 | skb_put(msdu, sizeof(*rxd)); |
| 450 | skb_pull(msdu, sizeof(*rxd)); |
| 451 | skb_put(msdu, __le16_to_cpu(msdu_desc->msdu_len)); |
| 452 | |
| 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"); |
| 456 | return -EIO; |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | msdu_desc++; |
| 461 | } |
| 462 | |
| 463 | return 0; |
| 464 | } |
| 465 | |
Michal Kazior | 95bf21f | 2014-05-16 17:15:39 +0300 | [diff] [blame] | 466 | int ath10k_htt_rx_alloc(struct ath10k_htt *htt) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 467 | { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 468 | struct ath10k *ar = htt->ar; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 469 | dma_addr_t paddr; |
| 470 | void *vaddr; |
Kalle Valo | bd8bdbb | 2014-09-14 12:50:00 +0300 | [diff] [blame] | 471 | size_t size; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 472 | struct timer_list *timer = &htt->rx_ring.refill_retry_timer; |
| 473 | |
Michal Kazior | 51fc7d7 | 2014-10-23 17:04:24 +0300 | [diff] [blame] | 474 | htt->rx_confused = false; |
| 475 | |
Michal Kazior | fe2407a | 2014-11-27 11:12:43 +0100 | [diff] [blame] | 476 | /* XXX: The fill level could be changed during runtime in response to |
| 477 | * the host processing latency. Is this really worth it? |
| 478 | */ |
| 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; |
| 482 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 483 | if (!is_power_of_2(htt->rx_ring.size)) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 484 | ath10k_warn(ar, "htt rx ring size is not power of 2\n"); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 485 | return -EINVAL; |
| 486 | } |
| 487 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 488 | htt->rx_ring.netbufs_ring = |
Michal Kazior | 3e841fd | 2014-05-14 16:23:31 +0300 | [diff] [blame] | 489 | kzalloc(htt->rx_ring.size * sizeof(struct sk_buff *), |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 490 | GFP_KERNEL); |
| 491 | if (!htt->rx_ring.netbufs_ring) |
| 492 | goto err_netbuf; |
| 493 | |
Kalle Valo | bd8bdbb | 2014-09-14 12:50:00 +0300 | [diff] [blame] | 494 | size = htt->rx_ring.size * sizeof(htt->rx_ring.paddrs_ring); |
| 495 | |
Felix Fietkau | d6cb23b5 | 2015-11-24 11:36:52 +0100 | [diff] [blame] | 496 | vaddr = dma_alloc_coherent(htt->ar->dev, size, &paddr, GFP_KERNEL); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 497 | if (!vaddr) |
| 498 | goto err_dma_ring; |
| 499 | |
| 500 | htt->rx_ring.paddrs_ring = vaddr; |
| 501 | htt->rx_ring.base_paddr = paddr; |
| 502 | |
| 503 | vaddr = dma_alloc_coherent(htt->ar->dev, |
| 504 | sizeof(*htt->rx_ring.alloc_idx.vaddr), |
Felix Fietkau | d6cb23b5 | 2015-11-24 11:36:52 +0100 | [diff] [blame] | 505 | &paddr, GFP_KERNEL); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 506 | if (!vaddr) |
| 507 | goto err_dma_idx; |
| 508 | |
| 509 | htt->rx_ring.alloc_idx.vaddr = vaddr; |
| 510 | htt->rx_ring.alloc_idx.paddr = paddr; |
Michal Kazior | c545070 | 2015-01-24 12:14:48 +0200 | [diff] [blame] | 511 | htt->rx_ring.sw_rd_idx.msdu_payld = htt->rx_ring.size_mask; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 512 | *htt->rx_ring.alloc_idx.vaddr = 0; |
| 513 | |
| 514 | /* Initialize the Rx refill retry timer */ |
| 515 | setup_timer(timer, ath10k_htt_rx_ring_refill_retry, (unsigned long)htt); |
| 516 | |
| 517 | spin_lock_init(&htt->rx_ring.lock); |
| 518 | |
| 519 | htt->rx_ring.fill_cnt = 0; |
Michal Kazior | c545070 | 2015-01-24 12:14:48 +0200 | [diff] [blame] | 520 | htt->rx_ring.sw_rd_idx.msdu_payld = 0; |
| 521 | hash_init(htt->rx_ring.skb_table); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 522 | |
Michal Kazior | 6e712d4 | 2013-09-24 10:18:36 +0200 | [diff] [blame] | 523 | tasklet_init(&htt->rx_replenish_task, ath10k_htt_rx_replenish_task, |
| 524 | (unsigned long)htt); |
| 525 | |
Michal Kazior | 6c5151a | 2014-02-27 18:50:04 +0200 | [diff] [blame] | 526 | skb_queue_head_init(&htt->rx_compl_q); |
Michal Kazior | c545070 | 2015-01-24 12:14:48 +0200 | [diff] [blame] | 527 | skb_queue_head_init(&htt->rx_in_ord_compl_q); |
Michal Kazior | 426e10e | 2016-03-06 16:14:43 +0200 | [diff] [blame] | 528 | skb_queue_head_init(&htt->tx_fetch_ind_q); |
Rajkumar Manoharan | 3128b3d | 2016-03-22 17:22:15 +0530 | [diff] [blame] | 529 | atomic_set(&htt->num_mpdus_ready, 0); |
Michal Kazior | 6c5151a | 2014-02-27 18:50:04 +0200 | [diff] [blame] | 530 | |
| 531 | tasklet_init(&htt->txrx_compl_task, ath10k_htt_txrx_compl_task, |
| 532 | (unsigned long)htt); |
| 533 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 534 | ath10k_dbg(ar, ATH10K_DBG_BOOT, "htt rx ring size %d fill_level %d\n", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 535 | htt->rx_ring.size, htt->rx_ring.fill_level); |
| 536 | return 0; |
| 537 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 538 | err_dma_idx: |
| 539 | dma_free_coherent(htt->ar->dev, |
| 540 | (htt->rx_ring.size * |
| 541 | sizeof(htt->rx_ring.paddrs_ring)), |
| 542 | htt->rx_ring.paddrs_ring, |
| 543 | htt->rx_ring.base_paddr); |
| 544 | err_dma_ring: |
| 545 | kfree(htt->rx_ring.netbufs_ring); |
| 546 | err_netbuf: |
| 547 | return -ENOMEM; |
| 548 | } |
| 549 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 550 | static int ath10k_htt_rx_crypto_param_len(struct ath10k *ar, |
| 551 | enum htt_rx_mpdu_encrypt_type type) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 552 | { |
| 553 | switch (type) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 554 | case HTT_RX_MPDU_ENCRYPT_NONE: |
| 555 | return 0; |
Michal Kazior | 890d3b2 | 2014-10-23 17:04:22 +0300 | [diff] [blame] | 556 | case HTT_RX_MPDU_ENCRYPT_WEP40: |
| 557 | case HTT_RX_MPDU_ENCRYPT_WEP104: |
| 558 | return IEEE80211_WEP_IV_LEN; |
| 559 | case HTT_RX_MPDU_ENCRYPT_TKIP_WITHOUT_MIC: |
| 560 | case HTT_RX_MPDU_ENCRYPT_TKIP_WPA: |
| 561 | return IEEE80211_TKIP_IV_LEN; |
| 562 | case HTT_RX_MPDU_ENCRYPT_AES_CCM_WPA2: |
| 563 | return IEEE80211_CCMP_HDR_LEN; |
| 564 | case HTT_RX_MPDU_ENCRYPT_WEP128: |
| 565 | case HTT_RX_MPDU_ENCRYPT_WAPI: |
| 566 | break; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 567 | } |
| 568 | |
Michal Kazior | 890d3b2 | 2014-10-23 17:04:22 +0300 | [diff] [blame] | 569 | ath10k_warn(ar, "unsupported encryption type %d\n", type); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 570 | return 0; |
| 571 | } |
| 572 | |
Michal Kazior | 890d3b2 | 2014-10-23 17:04:22 +0300 | [diff] [blame] | 573 | #define MICHAEL_MIC_LEN 8 |
| 574 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 575 | static int ath10k_htt_rx_crypto_tail_len(struct ath10k *ar, |
| 576 | enum htt_rx_mpdu_encrypt_type type) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 577 | { |
| 578 | switch (type) { |
| 579 | case HTT_RX_MPDU_ENCRYPT_NONE: |
Michal Kazior | 890d3b2 | 2014-10-23 17:04:22 +0300 | [diff] [blame] | 580 | return 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 581 | case HTT_RX_MPDU_ENCRYPT_WEP40: |
| 582 | case HTT_RX_MPDU_ENCRYPT_WEP104: |
Michal Kazior | 890d3b2 | 2014-10-23 17:04:22 +0300 | [diff] [blame] | 583 | return IEEE80211_WEP_ICV_LEN; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 584 | case HTT_RX_MPDU_ENCRYPT_TKIP_WITHOUT_MIC: |
| 585 | case HTT_RX_MPDU_ENCRYPT_TKIP_WPA: |
Michal Kazior | 890d3b2 | 2014-10-23 17:04:22 +0300 | [diff] [blame] | 586 | return IEEE80211_TKIP_ICV_LEN; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 587 | case HTT_RX_MPDU_ENCRYPT_AES_CCM_WPA2: |
Michal Kazior | 890d3b2 | 2014-10-23 17:04:22 +0300 | [diff] [blame] | 588 | return IEEE80211_CCMP_MIC_LEN; |
| 589 | case HTT_RX_MPDU_ENCRYPT_WEP128: |
| 590 | case HTT_RX_MPDU_ENCRYPT_WAPI: |
| 591 | break; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 592 | } |
| 593 | |
Michal Kazior | 890d3b2 | 2014-10-23 17:04:22 +0300 | [diff] [blame] | 594 | ath10k_warn(ar, "unsupported encryption type %d\n", type); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 595 | return 0; |
| 596 | } |
| 597 | |
Michal Kazior | f6dc209 | 2013-09-26 10:12:22 +0300 | [diff] [blame] | 598 | struct amsdu_subframe_hdr { |
| 599 | u8 dst[ETH_ALEN]; |
| 600 | u8 src[ETH_ALEN]; |
| 601 | __be16 len; |
| 602 | } __packed; |
| 603 | |
Michal Kazior | 6986fdd | 2015-08-27 14:47:33 +0200 | [diff] [blame] | 604 | #define GROUP_ID_IS_SU_MIMO(x) ((x) == 0 || (x) == 63) |
| 605 | |
Janusz Dziedzic | 87326c9 | 2014-03-24 21:23:19 +0100 | [diff] [blame] | 606 | static void ath10k_htt_rx_h_rates(struct ath10k *ar, |
Michal Kazior | b9fd8a8 | 2014-11-18 09:24:49 +0200 | [diff] [blame] | 607 | struct ieee80211_rx_status *status, |
| 608 | struct htt_rx_desc *rxd) |
Janusz Dziedzic | 73539b4 | 2014-03-24 21:23:15 +0100 | [diff] [blame] | 609 | { |
Michal Kazior | 5528e03 | 2015-03-30 09:51:56 +0300 | [diff] [blame] | 610 | struct ieee80211_supported_band *sband; |
| 611 | u8 cck, rate, bw, sgi, mcs, nss; |
Janusz Dziedzic | 73539b4 | 2014-03-24 21:23:15 +0100 | [diff] [blame] | 612 | u8 preamble = 0; |
Michal Kazior | 6986fdd | 2015-08-27 14:47:33 +0200 | [diff] [blame] | 613 | u8 group_id; |
Michal Kazior | b9fd8a8 | 2014-11-18 09:24:49 +0200 | [diff] [blame] | 614 | u32 info1, info2, info3; |
Janusz Dziedzic | 73539b4 | 2014-03-24 21:23:15 +0100 | [diff] [blame] | 615 | |
Michal Kazior | b9fd8a8 | 2014-11-18 09:24:49 +0200 | [diff] [blame] | 616 | info1 = __le32_to_cpu(rxd->ppdu_start.info1); |
| 617 | info2 = __le32_to_cpu(rxd->ppdu_start.info2); |
| 618 | info3 = __le32_to_cpu(rxd->ppdu_start.info3); |
| 619 | |
| 620 | preamble = MS(info1, RX_PPDU_START_INFO1_PREAMBLE_TYPE); |
Janusz Dziedzic | 73539b4 | 2014-03-24 21:23:15 +0100 | [diff] [blame] | 621 | |
| 622 | switch (preamble) { |
| 623 | case HTT_RX_LEGACY: |
Michal Kazior | 5528e03 | 2015-03-30 09:51:56 +0300 | [diff] [blame] | 624 | /* To get legacy rate index band is required. Since band can't |
| 625 | * be undefined check if freq is non-zero. |
| 626 | */ |
| 627 | if (!status->freq) |
| 628 | return; |
| 629 | |
Michal Kazior | b9fd8a8 | 2014-11-18 09:24:49 +0200 | [diff] [blame] | 630 | cck = info1 & RX_PPDU_START_INFO1_L_SIG_RATE_SELECT; |
| 631 | rate = MS(info1, RX_PPDU_START_INFO1_L_SIG_RATE); |
Michal Kazior | 5528e03 | 2015-03-30 09:51:56 +0300 | [diff] [blame] | 632 | rate &= ~RX_PPDU_START_RATE_FLAG; |
Janusz Dziedzic | 73539b4 | 2014-03-24 21:23:15 +0100 | [diff] [blame] | 633 | |
Michal Kazior | 5528e03 | 2015-03-30 09:51:56 +0300 | [diff] [blame] | 634 | sband = &ar->mac.sbands[status->band]; |
Yanbo Li | 4b7f353 | 2015-11-12 10:36:10 -0800 | [diff] [blame] | 635 | status->rate_idx = ath10k_mac_hw_rate_to_idx(sband, rate, cck); |
Janusz Dziedzic | 73539b4 | 2014-03-24 21:23:15 +0100 | [diff] [blame] | 636 | break; |
| 637 | case HTT_RX_HT: |
| 638 | case HTT_RX_HT_WITH_TXBF: |
Michal Kazior | b9fd8a8 | 2014-11-18 09:24:49 +0200 | [diff] [blame] | 639 | /* HT-SIG - Table 20-11 in info2 and info3 */ |
| 640 | mcs = info2 & 0x1F; |
Janusz Dziedzic | 73539b4 | 2014-03-24 21:23:15 +0100 | [diff] [blame] | 641 | nss = mcs >> 3; |
Michal Kazior | b9fd8a8 | 2014-11-18 09:24:49 +0200 | [diff] [blame] | 642 | bw = (info2 >> 7) & 1; |
| 643 | sgi = (info3 >> 7) & 1; |
Janusz Dziedzic | 73539b4 | 2014-03-24 21:23:15 +0100 | [diff] [blame] | 644 | |
| 645 | status->rate_idx = mcs; |
| 646 | status->flag |= RX_FLAG_HT; |
| 647 | if (sgi) |
| 648 | status->flag |= RX_FLAG_SHORT_GI; |
| 649 | if (bw) |
| 650 | status->flag |= RX_FLAG_40MHZ; |
| 651 | break; |
| 652 | case HTT_RX_VHT: |
| 653 | case HTT_RX_VHT_WITH_TXBF: |
Michal Kazior | b9fd8a8 | 2014-11-18 09:24:49 +0200 | [diff] [blame] | 654 | /* VHT-SIG-A1 in info2, VHT-SIG-A2 in info3 |
Janusz Dziedzic | 73539b4 | 2014-03-24 21:23:15 +0100 | [diff] [blame] | 655 | TODO check this */ |
Michal Kazior | b9fd8a8 | 2014-11-18 09:24:49 +0200 | [diff] [blame] | 656 | bw = info2 & 3; |
| 657 | sgi = info3 & 1; |
Michal Kazior | 6986fdd | 2015-08-27 14:47:33 +0200 | [diff] [blame] | 658 | group_id = (info2 >> 4) & 0x3F; |
| 659 | |
| 660 | if (GROUP_ID_IS_SU_MIMO(group_id)) { |
| 661 | mcs = (info3 >> 4) & 0x0F; |
| 662 | nss = ((info2 >> 10) & 0x07) + 1; |
| 663 | } else { |
| 664 | /* Hardware doesn't decode VHT-SIG-B into Rx descriptor |
| 665 | * so it's impossible to decode MCS. Also since |
| 666 | * firmware consumes Group Id Management frames host |
| 667 | * has no knowledge regarding group/user position |
| 668 | * mapping so it's impossible to pick the correct Nsts |
| 669 | * from VHT-SIG-A1. |
| 670 | * |
| 671 | * Bandwidth and SGI are valid so report the rateinfo |
| 672 | * on best-effort basis. |
| 673 | */ |
| 674 | mcs = 0; |
| 675 | nss = 1; |
| 676 | } |
Janusz Dziedzic | 73539b4 | 2014-03-24 21:23:15 +0100 | [diff] [blame] | 677 | |
Manikanta Pubbisetty | 6ccea10 | 2015-09-02 17:05:27 +0300 | [diff] [blame] | 678 | if (mcs > 0x09) { |
| 679 | ath10k_warn(ar, "invalid MCS received %u\n", mcs); |
| 680 | ath10k_warn(ar, "rxd %08x mpdu start %08x %08x msdu start %08x %08x ppdu start %08x %08x %08x %08x %08x\n", |
| 681 | __le32_to_cpu(rxd->attention.flags), |
| 682 | __le32_to_cpu(rxd->mpdu_start.info0), |
| 683 | __le32_to_cpu(rxd->mpdu_start.info1), |
| 684 | __le32_to_cpu(rxd->msdu_start.common.info0), |
| 685 | __le32_to_cpu(rxd->msdu_start.common.info1), |
| 686 | rxd->ppdu_start.info0, |
| 687 | __le32_to_cpu(rxd->ppdu_start.info1), |
| 688 | __le32_to_cpu(rxd->ppdu_start.info2), |
| 689 | __le32_to_cpu(rxd->ppdu_start.info3), |
| 690 | __le32_to_cpu(rxd->ppdu_start.info4)); |
| 691 | |
| 692 | ath10k_warn(ar, "msdu end %08x mpdu end %08x\n", |
| 693 | __le32_to_cpu(rxd->msdu_end.common.info0), |
| 694 | __le32_to_cpu(rxd->mpdu_end.info0)); |
| 695 | |
| 696 | ath10k_dbg_dump(ar, ATH10K_DBG_HTT_DUMP, NULL, |
| 697 | "rx desc msdu payload: ", |
| 698 | rxd->msdu_payload, 50); |
| 699 | } |
| 700 | |
Janusz Dziedzic | 73539b4 | 2014-03-24 21:23:15 +0100 | [diff] [blame] | 701 | status->rate_idx = mcs; |
| 702 | status->vht_nss = nss; |
| 703 | |
| 704 | if (sgi) |
| 705 | status->flag |= RX_FLAG_SHORT_GI; |
| 706 | |
| 707 | switch (bw) { |
| 708 | /* 20MHZ */ |
| 709 | case 0: |
| 710 | break; |
| 711 | /* 40MHZ */ |
| 712 | case 1: |
| 713 | status->flag |= RX_FLAG_40MHZ; |
| 714 | break; |
| 715 | /* 80MHZ */ |
| 716 | case 2: |
| 717 | status->vht_flag |= RX_VHT_FLAG_80MHZ; |
| 718 | } |
| 719 | |
| 720 | status->flag |= RX_FLAG_VHT; |
| 721 | break; |
| 722 | default: |
| 723 | break; |
| 724 | } |
| 725 | } |
| 726 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 727 | static struct ieee80211_channel * |
| 728 | ath10k_htt_rx_h_peer_channel(struct ath10k *ar, struct htt_rx_desc *rxd) |
| 729 | { |
| 730 | struct ath10k_peer *peer; |
| 731 | struct ath10k_vif *arvif; |
| 732 | struct cfg80211_chan_def def; |
| 733 | u16 peer_id; |
| 734 | |
| 735 | lockdep_assert_held(&ar->data_lock); |
| 736 | |
| 737 | if (!rxd) |
| 738 | return NULL; |
| 739 | |
| 740 | if (rxd->attention.flags & |
| 741 | __cpu_to_le32(RX_ATTENTION_FLAGS_PEER_IDX_INVALID)) |
| 742 | return NULL; |
| 743 | |
Peter Oh | 1f5dbfb | 2015-07-15 19:01:21 -0700 | [diff] [blame] | 744 | if (!(rxd->msdu_end.common.info0 & |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 745 | __cpu_to_le32(RX_MSDU_END_INFO0_FIRST_MSDU))) |
| 746 | return NULL; |
| 747 | |
| 748 | peer_id = MS(__le32_to_cpu(rxd->mpdu_start.info0), |
| 749 | RX_MPDU_START_INFO0_PEER_IDX); |
| 750 | |
| 751 | peer = ath10k_peer_find_by_id(ar, peer_id); |
| 752 | if (!peer) |
| 753 | return NULL; |
| 754 | |
| 755 | arvif = ath10k_get_arvif(ar, peer->vdev_id); |
| 756 | if (WARN_ON_ONCE(!arvif)) |
| 757 | return NULL; |
| 758 | |
| 759 | if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def))) |
| 760 | return NULL; |
| 761 | |
| 762 | return def.chan; |
| 763 | } |
| 764 | |
| 765 | static struct ieee80211_channel * |
| 766 | ath10k_htt_rx_h_vdev_channel(struct ath10k *ar, u32 vdev_id) |
| 767 | { |
| 768 | struct ath10k_vif *arvif; |
| 769 | struct cfg80211_chan_def def; |
| 770 | |
| 771 | lockdep_assert_held(&ar->data_lock); |
| 772 | |
| 773 | list_for_each_entry(arvif, &ar->arvifs, list) { |
| 774 | if (arvif->vdev_id == vdev_id && |
| 775 | ath10k_mac_vif_chan(arvif->vif, &def) == 0) |
| 776 | return def.chan; |
| 777 | } |
| 778 | |
| 779 | return NULL; |
| 780 | } |
| 781 | |
| 782 | static void |
| 783 | ath10k_htt_rx_h_any_chan_iter(struct ieee80211_hw *hw, |
| 784 | struct ieee80211_chanctx_conf *conf, |
| 785 | void *data) |
| 786 | { |
| 787 | struct cfg80211_chan_def *def = data; |
| 788 | |
| 789 | *def = conf->def; |
| 790 | } |
| 791 | |
| 792 | static struct ieee80211_channel * |
| 793 | ath10k_htt_rx_h_any_channel(struct ath10k *ar) |
| 794 | { |
| 795 | struct cfg80211_chan_def def = {}; |
| 796 | |
| 797 | ieee80211_iter_chan_contexts_atomic(ar->hw, |
| 798 | ath10k_htt_rx_h_any_chan_iter, |
| 799 | &def); |
| 800 | |
| 801 | return def.chan; |
| 802 | } |
| 803 | |
Janusz Dziedzic | 36653f0 | 2014-03-24 21:23:18 +0100 | [diff] [blame] | 804 | static bool ath10k_htt_rx_h_channel(struct ath10k *ar, |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 805 | struct ieee80211_rx_status *status, |
| 806 | struct htt_rx_desc *rxd, |
| 807 | u32 vdev_id) |
Janusz Dziedzic | 36653f0 | 2014-03-24 21:23:18 +0100 | [diff] [blame] | 808 | { |
| 809 | struct ieee80211_channel *ch; |
| 810 | |
| 811 | spin_lock_bh(&ar->data_lock); |
| 812 | ch = ar->scan_channel; |
| 813 | if (!ch) |
| 814 | ch = ar->rx_channel; |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 815 | if (!ch) |
| 816 | ch = ath10k_htt_rx_h_peer_channel(ar, rxd); |
| 817 | if (!ch) |
| 818 | ch = ath10k_htt_rx_h_vdev_channel(ar, vdev_id); |
| 819 | if (!ch) |
| 820 | ch = ath10k_htt_rx_h_any_channel(ar); |
Rajkumar Manoharan | 2ce9b25 | 2016-03-08 22:57:23 +0530 | [diff] [blame] | 821 | if (!ch) |
| 822 | ch = ar->tgt_oper_chan; |
Janusz Dziedzic | 36653f0 | 2014-03-24 21:23:18 +0100 | [diff] [blame] | 823 | spin_unlock_bh(&ar->data_lock); |
| 824 | |
| 825 | if (!ch) |
| 826 | return false; |
| 827 | |
| 828 | status->band = ch->band; |
| 829 | status->freq = ch->center_freq; |
| 830 | |
| 831 | return true; |
| 832 | } |
| 833 | |
Michal Kazior | b9fd8a8 | 2014-11-18 09:24:49 +0200 | [diff] [blame] | 834 | static void ath10k_htt_rx_h_signal(struct ath10k *ar, |
| 835 | struct ieee80211_rx_status *status, |
| 836 | struct htt_rx_desc *rxd) |
| 837 | { |
| 838 | /* FIXME: Get real NF */ |
| 839 | status->signal = ATH10K_DEFAULT_NOISE_FLOOR + |
| 840 | rxd->ppdu_start.rssi_comb; |
| 841 | status->flag &= ~RX_FLAG_NO_SIGNAL_VAL; |
| 842 | } |
| 843 | |
| 844 | static void ath10k_htt_rx_h_mactime(struct ath10k *ar, |
| 845 | struct ieee80211_rx_status *status, |
| 846 | struct htt_rx_desc *rxd) |
| 847 | { |
| 848 | /* FIXME: TSF is known only at the end of PPDU, in the last MPDU. This |
| 849 | * means all prior MSDUs in a PPDU are reported to mac80211 without the |
| 850 | * TSF. Is it worth holding frames until end of PPDU is known? |
| 851 | * |
| 852 | * FIXME: Can we get/compute 64bit TSF? |
| 853 | */ |
Michal Kazior | 3ec79e3 | 2015-01-24 12:14:48 +0200 | [diff] [blame] | 854 | status->mactime = __le32_to_cpu(rxd->ppdu_end.common.tsf_timestamp); |
Michal Kazior | b9fd8a8 | 2014-11-18 09:24:49 +0200 | [diff] [blame] | 855 | status->flag |= RX_FLAG_MACTIME_END; |
| 856 | } |
| 857 | |
| 858 | static void ath10k_htt_rx_h_ppdu(struct ath10k *ar, |
| 859 | struct sk_buff_head *amsdu, |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 860 | struct ieee80211_rx_status *status, |
| 861 | u32 vdev_id) |
Michal Kazior | b9fd8a8 | 2014-11-18 09:24:49 +0200 | [diff] [blame] | 862 | { |
| 863 | struct sk_buff *first; |
| 864 | struct htt_rx_desc *rxd; |
| 865 | bool is_first_ppdu; |
| 866 | bool is_last_ppdu; |
| 867 | |
| 868 | if (skb_queue_empty(amsdu)) |
| 869 | return; |
| 870 | |
| 871 | first = skb_peek(amsdu); |
| 872 | rxd = (void *)first->data - sizeof(*rxd); |
| 873 | |
| 874 | is_first_ppdu = !!(rxd->attention.flags & |
| 875 | __cpu_to_le32(RX_ATTENTION_FLAGS_FIRST_MPDU)); |
| 876 | is_last_ppdu = !!(rxd->attention.flags & |
| 877 | __cpu_to_le32(RX_ATTENTION_FLAGS_LAST_MPDU)); |
| 878 | |
| 879 | if (is_first_ppdu) { |
| 880 | /* New PPDU starts so clear out the old per-PPDU status. */ |
| 881 | status->freq = 0; |
| 882 | status->rate_idx = 0; |
| 883 | status->vht_nss = 0; |
| 884 | status->vht_flag &= ~RX_VHT_FLAG_80MHZ; |
| 885 | status->flag &= ~(RX_FLAG_HT | |
| 886 | RX_FLAG_VHT | |
| 887 | RX_FLAG_SHORT_GI | |
| 888 | RX_FLAG_40MHZ | |
| 889 | RX_FLAG_MACTIME_END); |
| 890 | status->flag |= RX_FLAG_NO_SIGNAL_VAL; |
| 891 | |
| 892 | ath10k_htt_rx_h_signal(ar, status, rxd); |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 893 | ath10k_htt_rx_h_channel(ar, status, rxd, vdev_id); |
Michal Kazior | b9fd8a8 | 2014-11-18 09:24:49 +0200 | [diff] [blame] | 894 | ath10k_htt_rx_h_rates(ar, status, rxd); |
| 895 | } |
| 896 | |
| 897 | if (is_last_ppdu) |
| 898 | ath10k_htt_rx_h_mactime(ar, status, rxd); |
| 899 | } |
| 900 | |
Janusz Dziedzic | 76f5329 | 2014-07-28 23:59:43 +0300 | [diff] [blame] | 901 | static const char * const tid_to_ac[] = { |
| 902 | "BE", |
| 903 | "BK", |
| 904 | "BK", |
| 905 | "BE", |
| 906 | "VI", |
| 907 | "VI", |
| 908 | "VO", |
| 909 | "VO", |
| 910 | }; |
| 911 | |
| 912 | static char *ath10k_get_tid(struct ieee80211_hdr *hdr, char *out, size_t size) |
| 913 | { |
| 914 | u8 *qc; |
| 915 | int tid; |
| 916 | |
| 917 | if (!ieee80211_is_data_qos(hdr->frame_control)) |
| 918 | return ""; |
| 919 | |
| 920 | qc = ieee80211_get_qos_ctl(hdr); |
| 921 | tid = *qc & IEEE80211_QOS_CTL_TID_MASK; |
| 922 | if (tid < 8) |
| 923 | snprintf(out, size, "tid %d (%s)", tid, tid_to_ac[tid]); |
| 924 | else |
| 925 | snprintf(out, size, "tid %d", tid); |
| 926 | |
| 927 | return out; |
| 928 | } |
| 929 | |
Janusz Dziedzic | 85f6d7c | 2014-03-24 21:23:22 +0100 | [diff] [blame] | 930 | static void ath10k_process_rx(struct ath10k *ar, |
| 931 | struct ieee80211_rx_status *rx_status, |
| 932 | struct sk_buff *skb) |
Janusz Dziedzic | 73539b4 | 2014-03-24 21:23:15 +0100 | [diff] [blame] | 933 | { |
| 934 | struct ieee80211_rx_status *status; |
Janusz Dziedzic | 76f5329 | 2014-07-28 23:59:43 +0300 | [diff] [blame] | 935 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
| 936 | char tid[32]; |
Janusz Dziedzic | 73539b4 | 2014-03-24 21:23:15 +0100 | [diff] [blame] | 937 | |
Janusz Dziedzic | 85f6d7c | 2014-03-24 21:23:22 +0100 | [diff] [blame] | 938 | status = IEEE80211_SKB_RXCB(skb); |
| 939 | *status = *rx_status; |
Janusz Dziedzic | 73539b4 | 2014-03-24 21:23:15 +0100 | [diff] [blame] | 940 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 941 | ath10k_dbg(ar, ATH10K_DBG_DATA, |
Janusz Dziedzic | 76f5329 | 2014-07-28 23:59:43 +0300 | [diff] [blame] | 942 | "rx skb %p len %u peer %pM %s %s sn %u %s%s%s%s%s %srate_idx %u vht_nss %u freq %u band %u flag 0x%x fcs-err %i mic-err %i amsdu-more %i\n", |
Janusz Dziedzic | 85f6d7c | 2014-03-24 21:23:22 +0100 | [diff] [blame] | 943 | skb, |
| 944 | skb->len, |
Janusz Dziedzic | 76f5329 | 2014-07-28 23:59:43 +0300 | [diff] [blame] | 945 | ieee80211_get_SA(hdr), |
| 946 | ath10k_get_tid(hdr, tid, sizeof(tid)), |
| 947 | is_multicast_ether_addr(ieee80211_get_DA(hdr)) ? |
| 948 | "mcast" : "ucast", |
| 949 | (__le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_SEQ) >> 4, |
Janusz Dziedzic | 73539b4 | 2014-03-24 21:23:15 +0100 | [diff] [blame] | 950 | status->flag == 0 ? "legacy" : "", |
| 951 | status->flag & RX_FLAG_HT ? "ht" : "", |
| 952 | status->flag & RX_FLAG_VHT ? "vht" : "", |
| 953 | status->flag & RX_FLAG_40MHZ ? "40" : "", |
| 954 | status->vht_flag & RX_VHT_FLAG_80MHZ ? "80" : "", |
| 955 | status->flag & RX_FLAG_SHORT_GI ? "sgi " : "", |
| 956 | status->rate_idx, |
| 957 | status->vht_nss, |
| 958 | status->freq, |
Janusz Dziedzic | 87326c9 | 2014-03-24 21:23:19 +0100 | [diff] [blame] | 959 | status->band, status->flag, |
Janusz Dziedzic | 78433f9 | 2014-03-24 21:23:21 +0100 | [diff] [blame] | 960 | !!(status->flag & RX_FLAG_FAILED_FCS_CRC), |
Janusz Dziedzic | 76f5329 | 2014-07-28 23:59:43 +0300 | [diff] [blame] | 961 | !!(status->flag & RX_FLAG_MMIC_ERROR), |
| 962 | !!(status->flag & RX_FLAG_AMSDU_MORE)); |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 963 | ath10k_dbg_dump(ar, ATH10K_DBG_HTT_DUMP, NULL, "rx skb: ", |
Janusz Dziedzic | 85f6d7c | 2014-03-24 21:23:22 +0100 | [diff] [blame] | 964 | skb->data, skb->len); |
Rajkumar Manoharan | 5ce8e7f | 2014-11-05 19:14:31 +0530 | [diff] [blame] | 965 | trace_ath10k_rx_hdr(ar, skb->data, skb->len); |
| 966 | trace_ath10k_rx_payload(ar, skb->data, skb->len); |
Janusz Dziedzic | 73539b4 | 2014-03-24 21:23:15 +0100 | [diff] [blame] | 967 | |
Janusz Dziedzic | 85f6d7c | 2014-03-24 21:23:22 +0100 | [diff] [blame] | 968 | ieee80211_rx(ar->hw, skb); |
Janusz Dziedzic | 73539b4 | 2014-03-24 21:23:15 +0100 | [diff] [blame] | 969 | } |
| 970 | |
Michal Kazior | 48f4ca3 | 2015-05-19 14:09:34 +0200 | [diff] [blame] | 971 | static int ath10k_htt_rx_nwifi_hdrlen(struct ath10k *ar, |
| 972 | struct ieee80211_hdr *hdr) |
Michal Kazior | d960c36 | 2014-02-25 09:29:57 +0200 | [diff] [blame] | 973 | { |
Michal Kazior | 48f4ca3 | 2015-05-19 14:09:34 +0200 | [diff] [blame] | 974 | int len = ieee80211_hdrlen(hdr->frame_control); |
| 975 | |
| 976 | if (!test_bit(ATH10K_FW_FEATURE_NO_NWIFI_DECAP_4ADDR_PADDING, |
| 977 | ar->fw_features)) |
| 978 | len = round_up(len, 4); |
| 979 | |
| 980 | return len; |
Michal Kazior | d960c36 | 2014-02-25 09:29:57 +0200 | [diff] [blame] | 981 | } |
| 982 | |
Michal Kazior | 581c25f | 2014-11-18 09:24:48 +0200 | [diff] [blame] | 983 | static void ath10k_htt_rx_h_undecap_raw(struct ath10k *ar, |
| 984 | struct sk_buff *msdu, |
| 985 | struct ieee80211_rx_status *status, |
| 986 | enum htt_rx_mpdu_encrypt_type enctype, |
| 987 | bool is_decrypted) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 988 | { |
Michal Kazior | f6dc209 | 2013-09-26 10:12:22 +0300 | [diff] [blame] | 989 | struct ieee80211_hdr *hdr; |
Michal Kazior | 581c25f | 2014-11-18 09:24:48 +0200 | [diff] [blame] | 990 | struct htt_rx_desc *rxd; |
| 991 | size_t hdr_len; |
| 992 | size_t crypto_len; |
| 993 | bool is_first; |
| 994 | bool is_last; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 995 | |
Michal Kazior | 581c25f | 2014-11-18 09:24:48 +0200 | [diff] [blame] | 996 | rxd = (void *)msdu->data - sizeof(*rxd); |
Peter Oh | 1f5dbfb | 2015-07-15 19:01:21 -0700 | [diff] [blame] | 997 | is_first = !!(rxd->msdu_end.common.info0 & |
Michal Kazior | 581c25f | 2014-11-18 09:24:48 +0200 | [diff] [blame] | 998 | __cpu_to_le32(RX_MSDU_END_INFO0_FIRST_MSDU)); |
Peter Oh | 1f5dbfb | 2015-07-15 19:01:21 -0700 | [diff] [blame] | 999 | is_last = !!(rxd->msdu_end.common.info0 & |
Michal Kazior | 581c25f | 2014-11-18 09:24:48 +0200 | [diff] [blame] | 1000 | __cpu_to_le32(RX_MSDU_END_INFO0_LAST_MSDU)); |
Michal Kazior | 9aa505d | 2014-11-18 09:24:47 +0200 | [diff] [blame] | 1001 | |
Michal Kazior | 581c25f | 2014-11-18 09:24:48 +0200 | [diff] [blame] | 1002 | /* Delivered decapped frame: |
| 1003 | * [802.11 header] |
| 1004 | * [crypto param] <-- can be trimmed if !fcs_err && |
| 1005 | * !decrypt_err && !peer_idx_invalid |
| 1006 | * [amsdu header] <-- only if A-MSDU |
| 1007 | * [rfc1042/llc] |
| 1008 | * [payload] |
| 1009 | * [FCS] <-- at end, needs to be trimmed |
| 1010 | */ |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1011 | |
Michal Kazior | 581c25f | 2014-11-18 09:24:48 +0200 | [diff] [blame] | 1012 | /* This probably shouldn't happen but warn just in case */ |
| 1013 | if (unlikely(WARN_ON_ONCE(!is_first))) |
| 1014 | return; |
| 1015 | |
| 1016 | /* This probably shouldn't happen but warn just in case */ |
| 1017 | if (unlikely(WARN_ON_ONCE(!(is_first && is_last)))) |
| 1018 | return; |
| 1019 | |
| 1020 | skb_trim(msdu, msdu->len - FCS_LEN); |
| 1021 | |
| 1022 | /* In most cases this will be true for sniffed frames. It makes sense |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 1023 | * to deliver them as-is without stripping the crypto param. This is |
| 1024 | * necessary for software based decryption. |
Michal Kazior | 581c25f | 2014-11-18 09:24:48 +0200 | [diff] [blame] | 1025 | * |
| 1026 | * If there's no error then the frame is decrypted. At least that is |
| 1027 | * the case for frames that come in via fragmented rx indication. |
| 1028 | */ |
| 1029 | if (!is_decrypted) |
| 1030 | return; |
| 1031 | |
| 1032 | /* The payload is decrypted so strip crypto params. Start from tail |
| 1033 | * since hdr is used to compute some stuff. |
| 1034 | */ |
| 1035 | |
| 1036 | hdr = (void *)msdu->data; |
| 1037 | |
| 1038 | /* Tail */ |
Grzegorz Bajorski | 60549ca | 2015-11-30 13:56:59 +0100 | [diff] [blame] | 1039 | if (status->flag & RX_FLAG_IV_STRIPPED) |
| 1040 | skb_trim(msdu, msdu->len - |
| 1041 | ath10k_htt_rx_crypto_tail_len(ar, enctype)); |
Michal Kazior | 581c25f | 2014-11-18 09:24:48 +0200 | [diff] [blame] | 1042 | |
| 1043 | /* MMIC */ |
Grzegorz Bajorski | 60549ca | 2015-11-30 13:56:59 +0100 | [diff] [blame] | 1044 | if ((status->flag & RX_FLAG_MMIC_STRIPPED) && |
| 1045 | !ieee80211_has_morefrags(hdr->frame_control) && |
Michal Kazior | 581c25f | 2014-11-18 09:24:48 +0200 | [diff] [blame] | 1046 | enctype == HTT_RX_MPDU_ENCRYPT_TKIP_WPA) |
| 1047 | skb_trim(msdu, msdu->len - 8); |
| 1048 | |
| 1049 | /* Head */ |
Grzegorz Bajorski | 60549ca | 2015-11-30 13:56:59 +0100 | [diff] [blame] | 1050 | if (status->flag & RX_FLAG_IV_STRIPPED) { |
| 1051 | hdr_len = ieee80211_hdrlen(hdr->frame_control); |
| 1052 | crypto_len = ath10k_htt_rx_crypto_param_len(ar, enctype); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1053 | |
Grzegorz Bajorski | 60549ca | 2015-11-30 13:56:59 +0100 | [diff] [blame] | 1054 | memmove((void *)msdu->data + crypto_len, |
| 1055 | (void *)msdu->data, hdr_len); |
| 1056 | skb_pull(msdu, crypto_len); |
| 1057 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1058 | } |
| 1059 | |
Michal Kazior | 581c25f | 2014-11-18 09:24:48 +0200 | [diff] [blame] | 1060 | static void ath10k_htt_rx_h_undecap_nwifi(struct ath10k *ar, |
| 1061 | struct sk_buff *msdu, |
| 1062 | struct ieee80211_rx_status *status, |
| 1063 | const u8 first_hdr[64]) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1064 | { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1065 | struct ieee80211_hdr *hdr; |
Michal Kazior | 581c25f | 2014-11-18 09:24:48 +0200 | [diff] [blame] | 1066 | size_t hdr_len; |
| 1067 | u8 da[ETH_ALEN]; |
| 1068 | u8 sa[ETH_ALEN]; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1069 | |
Michal Kazior | 581c25f | 2014-11-18 09:24:48 +0200 | [diff] [blame] | 1070 | /* Delivered decapped frame: |
| 1071 | * [nwifi 802.11 header] <-- replaced with 802.11 hdr |
| 1072 | * [rfc1042/llc] |
| 1073 | * |
| 1074 | * Note: The nwifi header doesn't have QoS Control and is |
| 1075 | * (always?) a 3addr frame. |
| 1076 | * |
| 1077 | * Note2: There's no A-MSDU subframe header. Even if it's part |
| 1078 | * of an A-MSDU. |
| 1079 | */ |
| 1080 | |
| 1081 | /* pull decapped header and copy SA & DA */ |
Yanbo Li | b8d55fc | 2015-11-16 22:22:02 +0200 | [diff] [blame] | 1082 | if ((ar->hw_params.hw_4addr_pad == ATH10K_HW_4ADDR_PAD_BEFORE) && |
| 1083 | ieee80211_has_a4(((struct ieee80211_hdr *)first_hdr)->frame_control)) { |
| 1084 | /* The QCA99X0 4 address mode pad 2 bytes at the |
| 1085 | * beginning of MSDU |
| 1086 | */ |
| 1087 | hdr = (struct ieee80211_hdr *)(msdu->data + 2); |
| 1088 | /* The skb length need be extended 2 as the 2 bytes at the tail |
| 1089 | * be excluded due to the padding |
| 1090 | */ |
| 1091 | skb_put(msdu, 2); |
| 1092 | } else { |
| 1093 | hdr = (struct ieee80211_hdr *)(msdu->data); |
| 1094 | } |
| 1095 | |
Michal Kazior | 48f4ca3 | 2015-05-19 14:09:34 +0200 | [diff] [blame] | 1096 | hdr_len = ath10k_htt_rx_nwifi_hdrlen(ar, hdr); |
Michal Kazior | 581c25f | 2014-11-18 09:24:48 +0200 | [diff] [blame] | 1097 | ether_addr_copy(da, ieee80211_get_DA(hdr)); |
| 1098 | ether_addr_copy(sa, ieee80211_get_SA(hdr)); |
| 1099 | skb_pull(msdu, hdr_len); |
| 1100 | |
| 1101 | /* push original 802.11 header */ |
| 1102 | hdr = (struct ieee80211_hdr *)first_hdr; |
Michal Kazior | e3fbf8d | 2013-09-26 10:12:23 +0300 | [diff] [blame] | 1103 | hdr_len = ieee80211_hdrlen(hdr->frame_control); |
Michal Kazior | 581c25f | 2014-11-18 09:24:48 +0200 | [diff] [blame] | 1104 | memcpy(skb_push(msdu, hdr_len), hdr, hdr_len); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1105 | |
Michal Kazior | 581c25f | 2014-11-18 09:24:48 +0200 | [diff] [blame] | 1106 | /* original 802.11 header has a different DA and in |
| 1107 | * case of 4addr it may also have different SA |
| 1108 | */ |
| 1109 | hdr = (struct ieee80211_hdr *)msdu->data; |
| 1110 | ether_addr_copy(ieee80211_get_DA(hdr), da); |
| 1111 | ether_addr_copy(ieee80211_get_SA(hdr), sa); |
| 1112 | } |
Michal Kazior | f6dc209 | 2013-09-26 10:12:22 +0300 | [diff] [blame] | 1113 | |
Michal Kazior | 581c25f | 2014-11-18 09:24:48 +0200 | [diff] [blame] | 1114 | static void *ath10k_htt_rx_h_find_rfc1042(struct ath10k *ar, |
| 1115 | struct sk_buff *msdu, |
| 1116 | enum htt_rx_mpdu_encrypt_type enctype) |
| 1117 | { |
| 1118 | struct ieee80211_hdr *hdr; |
| 1119 | struct htt_rx_desc *rxd; |
| 1120 | size_t hdr_len, crypto_len; |
| 1121 | void *rfc1042; |
| 1122 | bool is_first, is_last, is_amsdu; |
Michal Kazior | 784f69d | 2013-09-26 10:12:23 +0300 | [diff] [blame] | 1123 | |
Michal Kazior | 581c25f | 2014-11-18 09:24:48 +0200 | [diff] [blame] | 1124 | rxd = (void *)msdu->data - sizeof(*rxd); |
| 1125 | hdr = (void *)rxd->rx_hdr_status; |
| 1126 | |
Peter Oh | 1f5dbfb | 2015-07-15 19:01:21 -0700 | [diff] [blame] | 1127 | is_first = !!(rxd->msdu_end.common.info0 & |
Michal Kazior | 581c25f | 2014-11-18 09:24:48 +0200 | [diff] [blame] | 1128 | __cpu_to_le32(RX_MSDU_END_INFO0_FIRST_MSDU)); |
Peter Oh | 1f5dbfb | 2015-07-15 19:01:21 -0700 | [diff] [blame] | 1129 | is_last = !!(rxd->msdu_end.common.info0 & |
Michal Kazior | 581c25f | 2014-11-18 09:24:48 +0200 | [diff] [blame] | 1130 | __cpu_to_le32(RX_MSDU_END_INFO0_LAST_MSDU)); |
| 1131 | is_amsdu = !(is_first && is_last); |
| 1132 | |
| 1133 | rfc1042 = hdr; |
| 1134 | |
| 1135 | if (is_first) { |
Michal Kazior | 784f69d | 2013-09-26 10:12:23 +0300 | [diff] [blame] | 1136 | hdr_len = ieee80211_hdrlen(hdr->frame_control); |
Michal Kazior | 581c25f | 2014-11-18 09:24:48 +0200 | [diff] [blame] | 1137 | crypto_len = ath10k_htt_rx_crypto_param_len(ar, enctype); |
Michal Kazior | e3fbf8d | 2013-09-26 10:12:23 +0300 | [diff] [blame] | 1138 | |
Michal Kazior | 581c25f | 2014-11-18 09:24:48 +0200 | [diff] [blame] | 1139 | rfc1042 += round_up(hdr_len, 4) + |
| 1140 | round_up(crypto_len, 4); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1141 | } |
| 1142 | |
Michal Kazior | 581c25f | 2014-11-18 09:24:48 +0200 | [diff] [blame] | 1143 | if (is_amsdu) |
| 1144 | rfc1042 += sizeof(struct amsdu_subframe_hdr); |
Michal Kazior | f6dc209 | 2013-09-26 10:12:22 +0300 | [diff] [blame] | 1145 | |
Michal Kazior | 581c25f | 2014-11-18 09:24:48 +0200 | [diff] [blame] | 1146 | return rfc1042; |
| 1147 | } |
| 1148 | |
| 1149 | static void ath10k_htt_rx_h_undecap_eth(struct ath10k *ar, |
| 1150 | struct sk_buff *msdu, |
| 1151 | struct ieee80211_rx_status *status, |
| 1152 | const u8 first_hdr[64], |
| 1153 | enum htt_rx_mpdu_encrypt_type enctype) |
| 1154 | { |
| 1155 | struct ieee80211_hdr *hdr; |
| 1156 | struct ethhdr *eth; |
| 1157 | size_t hdr_len; |
| 1158 | void *rfc1042; |
| 1159 | u8 da[ETH_ALEN]; |
| 1160 | u8 sa[ETH_ALEN]; |
| 1161 | |
| 1162 | /* Delivered decapped frame: |
| 1163 | * [eth header] <-- replaced with 802.11 hdr & rfc1042/llc |
| 1164 | * [payload] |
| 1165 | */ |
| 1166 | |
| 1167 | rfc1042 = ath10k_htt_rx_h_find_rfc1042(ar, msdu, enctype); |
| 1168 | if (WARN_ON_ONCE(!rfc1042)) |
| 1169 | return; |
| 1170 | |
| 1171 | /* pull decapped header and copy SA & DA */ |
| 1172 | eth = (struct ethhdr *)msdu->data; |
| 1173 | ether_addr_copy(da, eth->h_dest); |
| 1174 | ether_addr_copy(sa, eth->h_source); |
| 1175 | skb_pull(msdu, sizeof(struct ethhdr)); |
| 1176 | |
| 1177 | /* push rfc1042/llc/snap */ |
| 1178 | memcpy(skb_push(msdu, sizeof(struct rfc1042_hdr)), rfc1042, |
| 1179 | sizeof(struct rfc1042_hdr)); |
| 1180 | |
| 1181 | /* push original 802.11 header */ |
| 1182 | hdr = (struct ieee80211_hdr *)first_hdr; |
| 1183 | hdr_len = ieee80211_hdrlen(hdr->frame_control); |
| 1184 | memcpy(skb_push(msdu, hdr_len), hdr, hdr_len); |
| 1185 | |
| 1186 | /* original 802.11 header has a different DA and in |
| 1187 | * case of 4addr it may also have different SA |
| 1188 | */ |
| 1189 | hdr = (struct ieee80211_hdr *)msdu->data; |
| 1190 | ether_addr_copy(ieee80211_get_DA(hdr), da); |
| 1191 | ether_addr_copy(ieee80211_get_SA(hdr), sa); |
| 1192 | } |
| 1193 | |
| 1194 | static void ath10k_htt_rx_h_undecap_snap(struct ath10k *ar, |
| 1195 | struct sk_buff *msdu, |
| 1196 | struct ieee80211_rx_status *status, |
| 1197 | const u8 first_hdr[64]) |
| 1198 | { |
| 1199 | struct ieee80211_hdr *hdr; |
| 1200 | size_t hdr_len; |
| 1201 | |
| 1202 | /* Delivered decapped frame: |
| 1203 | * [amsdu header] <-- replaced with 802.11 hdr |
| 1204 | * [rfc1042/llc] |
| 1205 | * [payload] |
| 1206 | */ |
| 1207 | |
| 1208 | skb_pull(msdu, sizeof(struct amsdu_subframe_hdr)); |
| 1209 | |
| 1210 | hdr = (struct ieee80211_hdr *)first_hdr; |
| 1211 | hdr_len = ieee80211_hdrlen(hdr->frame_control); |
| 1212 | memcpy(skb_push(msdu, hdr_len), hdr, hdr_len); |
| 1213 | } |
| 1214 | |
| 1215 | static void ath10k_htt_rx_h_undecap(struct ath10k *ar, |
| 1216 | struct sk_buff *msdu, |
| 1217 | struct ieee80211_rx_status *status, |
| 1218 | u8 first_hdr[64], |
| 1219 | enum htt_rx_mpdu_encrypt_type enctype, |
| 1220 | bool is_decrypted) |
| 1221 | { |
| 1222 | struct htt_rx_desc *rxd; |
| 1223 | enum rx_msdu_decap_format decap; |
Michal Kazior | 581c25f | 2014-11-18 09:24:48 +0200 | [diff] [blame] | 1224 | |
| 1225 | /* First msdu's decapped header: |
| 1226 | * [802.11 header] <-- padded to 4 bytes long |
| 1227 | * [crypto param] <-- padded to 4 bytes long |
| 1228 | * [amsdu header] <-- only if A-MSDU |
| 1229 | * [rfc1042/llc] |
| 1230 | * |
| 1231 | * Other (2nd, 3rd, ..) msdu's decapped header: |
| 1232 | * [amsdu header] <-- only if A-MSDU |
| 1233 | * [rfc1042/llc] |
| 1234 | */ |
| 1235 | |
| 1236 | rxd = (void *)msdu->data - sizeof(*rxd); |
Peter Oh | 1f5dbfb | 2015-07-15 19:01:21 -0700 | [diff] [blame] | 1237 | decap = MS(__le32_to_cpu(rxd->msdu_start.common.info1), |
Michal Kazior | 581c25f | 2014-11-18 09:24:48 +0200 | [diff] [blame] | 1238 | RX_MSDU_START_INFO1_DECAP_FORMAT); |
| 1239 | |
| 1240 | switch (decap) { |
| 1241 | case RX_MSDU_DECAP_RAW: |
| 1242 | ath10k_htt_rx_h_undecap_raw(ar, msdu, status, enctype, |
| 1243 | is_decrypted); |
| 1244 | break; |
| 1245 | case RX_MSDU_DECAP_NATIVE_WIFI: |
| 1246 | ath10k_htt_rx_h_undecap_nwifi(ar, msdu, status, first_hdr); |
| 1247 | break; |
| 1248 | case RX_MSDU_DECAP_ETHERNET2_DIX: |
| 1249 | ath10k_htt_rx_h_undecap_eth(ar, msdu, status, first_hdr, enctype); |
| 1250 | break; |
| 1251 | case RX_MSDU_DECAP_8023_SNAP_LLC: |
| 1252 | ath10k_htt_rx_h_undecap_snap(ar, msdu, status, first_hdr); |
| 1253 | break; |
| 1254 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1255 | } |
| 1256 | |
Michal Kazior | 605f81a | 2013-07-31 10:47:56 +0200 | [diff] [blame] | 1257 | static int ath10k_htt_rx_get_csum_state(struct sk_buff *skb) |
| 1258 | { |
| 1259 | struct htt_rx_desc *rxd; |
| 1260 | u32 flags, info; |
| 1261 | bool is_ip4, is_ip6; |
| 1262 | bool is_tcp, is_udp; |
| 1263 | bool ip_csum_ok, tcpudp_csum_ok; |
| 1264 | |
| 1265 | rxd = (void *)skb->data - sizeof(*rxd); |
| 1266 | flags = __le32_to_cpu(rxd->attention.flags); |
Peter Oh | 1f5dbfb | 2015-07-15 19:01:21 -0700 | [diff] [blame] | 1267 | info = __le32_to_cpu(rxd->msdu_start.common.info1); |
Michal Kazior | 605f81a | 2013-07-31 10:47:56 +0200 | [diff] [blame] | 1268 | |
| 1269 | is_ip4 = !!(info & RX_MSDU_START_INFO1_IPV4_PROTO); |
| 1270 | is_ip6 = !!(info & RX_MSDU_START_INFO1_IPV6_PROTO); |
| 1271 | is_tcp = !!(info & RX_MSDU_START_INFO1_TCP_PROTO); |
| 1272 | is_udp = !!(info & RX_MSDU_START_INFO1_UDP_PROTO); |
| 1273 | ip_csum_ok = !(flags & RX_ATTENTION_FLAGS_IP_CHKSUM_FAIL); |
| 1274 | tcpudp_csum_ok = !(flags & RX_ATTENTION_FLAGS_TCP_UDP_CHKSUM_FAIL); |
| 1275 | |
| 1276 | if (!is_ip4 && !is_ip6) |
| 1277 | return CHECKSUM_NONE; |
| 1278 | if (!is_tcp && !is_udp) |
| 1279 | return CHECKSUM_NONE; |
| 1280 | if (!ip_csum_ok) |
| 1281 | return CHECKSUM_NONE; |
| 1282 | if (!tcpudp_csum_ok) |
| 1283 | return CHECKSUM_NONE; |
| 1284 | |
| 1285 | return CHECKSUM_UNNECESSARY; |
| 1286 | } |
| 1287 | |
Michal Kazior | 581c25f | 2014-11-18 09:24:48 +0200 | [diff] [blame] | 1288 | static void ath10k_htt_rx_h_csum_offload(struct sk_buff *msdu) |
| 1289 | { |
| 1290 | msdu->ip_summed = ath10k_htt_rx_get_csum_state(msdu); |
| 1291 | } |
| 1292 | |
| 1293 | static void ath10k_htt_rx_h_mpdu(struct ath10k *ar, |
| 1294 | struct sk_buff_head *amsdu, |
| 1295 | struct ieee80211_rx_status *status) |
| 1296 | { |
| 1297 | struct sk_buff *first; |
| 1298 | struct sk_buff *last; |
| 1299 | struct sk_buff *msdu; |
| 1300 | struct htt_rx_desc *rxd; |
| 1301 | struct ieee80211_hdr *hdr; |
| 1302 | enum htt_rx_mpdu_encrypt_type enctype; |
| 1303 | u8 first_hdr[64]; |
| 1304 | u8 *qos; |
| 1305 | size_t hdr_len; |
| 1306 | bool has_fcs_err; |
| 1307 | bool has_crypto_err; |
| 1308 | bool has_tkip_err; |
| 1309 | bool has_peer_idx_invalid; |
| 1310 | bool is_decrypted; |
Grzegorz Bajorski | 60549ca | 2015-11-30 13:56:59 +0100 | [diff] [blame] | 1311 | bool is_mgmt; |
Michal Kazior | 581c25f | 2014-11-18 09:24:48 +0200 | [diff] [blame] | 1312 | u32 attention; |
| 1313 | |
| 1314 | if (skb_queue_empty(amsdu)) |
| 1315 | return; |
| 1316 | |
| 1317 | first = skb_peek(amsdu); |
| 1318 | rxd = (void *)first->data - sizeof(*rxd); |
| 1319 | |
Grzegorz Bajorski | 60549ca | 2015-11-30 13:56:59 +0100 | [diff] [blame] | 1320 | is_mgmt = !!(rxd->attention.flags & |
| 1321 | __cpu_to_le32(RX_ATTENTION_FLAGS_MGMT_TYPE)); |
| 1322 | |
Michal Kazior | 581c25f | 2014-11-18 09:24:48 +0200 | [diff] [blame] | 1323 | enctype = MS(__le32_to_cpu(rxd->mpdu_start.info0), |
| 1324 | RX_MPDU_START_INFO0_ENCRYPT_TYPE); |
| 1325 | |
| 1326 | /* First MSDU's Rx descriptor in an A-MSDU contains full 802.11 |
| 1327 | * decapped header. It'll be used for undecapping of each MSDU. |
| 1328 | */ |
| 1329 | hdr = (void *)rxd->rx_hdr_status; |
| 1330 | hdr_len = ieee80211_hdrlen(hdr->frame_control); |
| 1331 | memcpy(first_hdr, hdr, hdr_len); |
| 1332 | |
| 1333 | /* Each A-MSDU subframe will use the original header as the base and be |
| 1334 | * reported as a separate MSDU so strip the A-MSDU bit from QoS Ctl. |
| 1335 | */ |
| 1336 | hdr = (void *)first_hdr; |
| 1337 | qos = ieee80211_get_qos_ctl(hdr); |
| 1338 | qos[0] &= ~IEEE80211_QOS_CTL_A_MSDU_PRESENT; |
| 1339 | |
| 1340 | /* Some attention flags are valid only in the last MSDU. */ |
| 1341 | last = skb_peek_tail(amsdu); |
| 1342 | rxd = (void *)last->data - sizeof(*rxd); |
| 1343 | attention = __le32_to_cpu(rxd->attention.flags); |
| 1344 | |
| 1345 | has_fcs_err = !!(attention & RX_ATTENTION_FLAGS_FCS_ERR); |
| 1346 | has_crypto_err = !!(attention & RX_ATTENTION_FLAGS_DECRYPT_ERR); |
| 1347 | has_tkip_err = !!(attention & RX_ATTENTION_FLAGS_TKIP_MIC_ERR); |
| 1348 | has_peer_idx_invalid = !!(attention & RX_ATTENTION_FLAGS_PEER_IDX_INVALID); |
| 1349 | |
| 1350 | /* Note: If hardware captures an encrypted frame that it can't decrypt, |
| 1351 | * e.g. due to fcs error, missing peer or invalid key data it will |
| 1352 | * report the frame as raw. |
| 1353 | */ |
| 1354 | is_decrypted = (enctype != HTT_RX_MPDU_ENCRYPT_NONE && |
| 1355 | !has_fcs_err && |
| 1356 | !has_crypto_err && |
| 1357 | !has_peer_idx_invalid); |
| 1358 | |
| 1359 | /* Clear per-MPDU flags while leaving per-PPDU flags intact. */ |
| 1360 | status->flag &= ~(RX_FLAG_FAILED_FCS_CRC | |
| 1361 | RX_FLAG_MMIC_ERROR | |
| 1362 | RX_FLAG_DECRYPTED | |
| 1363 | RX_FLAG_IV_STRIPPED | |
Grzegorz Bajorski | 60549ca | 2015-11-30 13:56:59 +0100 | [diff] [blame] | 1364 | RX_FLAG_ONLY_MONITOR | |
Michal Kazior | 581c25f | 2014-11-18 09:24:48 +0200 | [diff] [blame] | 1365 | RX_FLAG_MMIC_STRIPPED); |
| 1366 | |
| 1367 | if (has_fcs_err) |
| 1368 | status->flag |= RX_FLAG_FAILED_FCS_CRC; |
| 1369 | |
| 1370 | if (has_tkip_err) |
| 1371 | status->flag |= RX_FLAG_MMIC_ERROR; |
| 1372 | |
Grzegorz Bajorski | 60549ca | 2015-11-30 13:56:59 +0100 | [diff] [blame] | 1373 | /* Firmware reports all necessary management frames via WMI already. |
| 1374 | * They are not reported to monitor interfaces at all so pass the ones |
| 1375 | * coming via HTT to monitor interfaces instead. This simplifies |
| 1376 | * matters a lot. |
| 1377 | */ |
| 1378 | if (is_mgmt) |
| 1379 | status->flag |= RX_FLAG_ONLY_MONITOR; |
| 1380 | |
| 1381 | if (is_decrypted) { |
| 1382 | status->flag |= RX_FLAG_DECRYPTED; |
| 1383 | |
| 1384 | if (likely(!is_mgmt)) |
| 1385 | status->flag |= RX_FLAG_IV_STRIPPED | |
| 1386 | RX_FLAG_MMIC_STRIPPED; |
| 1387 | } |
Michal Kazior | 581c25f | 2014-11-18 09:24:48 +0200 | [diff] [blame] | 1388 | |
| 1389 | skb_queue_walk(amsdu, msdu) { |
| 1390 | ath10k_htt_rx_h_csum_offload(msdu); |
| 1391 | ath10k_htt_rx_h_undecap(ar, msdu, status, first_hdr, enctype, |
| 1392 | is_decrypted); |
| 1393 | |
| 1394 | /* Undecapping involves copying the original 802.11 header back |
| 1395 | * to sk_buff. If frame is protected and hardware has decrypted |
| 1396 | * it then remove the protected bit. |
| 1397 | */ |
| 1398 | if (!is_decrypted) |
| 1399 | continue; |
Grzegorz Bajorski | 60549ca | 2015-11-30 13:56:59 +0100 | [diff] [blame] | 1400 | if (is_mgmt) |
| 1401 | continue; |
Michal Kazior | 581c25f | 2014-11-18 09:24:48 +0200 | [diff] [blame] | 1402 | |
| 1403 | hdr = (void *)msdu->data; |
| 1404 | hdr->frame_control &= ~__cpu_to_le16(IEEE80211_FCTL_PROTECTED); |
| 1405 | } |
| 1406 | } |
| 1407 | |
| 1408 | static void ath10k_htt_rx_h_deliver(struct ath10k *ar, |
| 1409 | struct sk_buff_head *amsdu, |
| 1410 | struct ieee80211_rx_status *status) |
| 1411 | { |
| 1412 | struct sk_buff *msdu; |
| 1413 | |
| 1414 | while ((msdu = __skb_dequeue(amsdu))) { |
| 1415 | /* Setup per-MSDU flags */ |
| 1416 | if (skb_queue_empty(amsdu)) |
| 1417 | status->flag &= ~RX_FLAG_AMSDU_MORE; |
| 1418 | else |
| 1419 | status->flag |= RX_FLAG_AMSDU_MORE; |
| 1420 | |
| 1421 | ath10k_process_rx(ar, status, msdu); |
| 1422 | } |
| 1423 | } |
| 1424 | |
Michal Kazior | 9aa505d | 2014-11-18 09:24:47 +0200 | [diff] [blame] | 1425 | static int ath10k_unchain_msdu(struct sk_buff_head *amsdu) |
Ben Greear | bfa3536 | 2014-03-03 14:07:09 -0800 | [diff] [blame] | 1426 | { |
Michal Kazior | 9aa505d | 2014-11-18 09:24:47 +0200 | [diff] [blame] | 1427 | struct sk_buff *skb, *first; |
Ben Greear | bfa3536 | 2014-03-03 14:07:09 -0800 | [diff] [blame] | 1428 | int space; |
| 1429 | int total_len = 0; |
| 1430 | |
| 1431 | /* TODO: Might could optimize this by using |
| 1432 | * skb_try_coalesce or similar method to |
| 1433 | * decrease copying, or maybe get mac80211 to |
| 1434 | * provide a way to just receive a list of |
| 1435 | * skb? |
| 1436 | */ |
| 1437 | |
Michal Kazior | 9aa505d | 2014-11-18 09:24:47 +0200 | [diff] [blame] | 1438 | first = __skb_dequeue(amsdu); |
Ben Greear | bfa3536 | 2014-03-03 14:07:09 -0800 | [diff] [blame] | 1439 | |
| 1440 | /* Allocate total length all at once. */ |
Michal Kazior | 9aa505d | 2014-11-18 09:24:47 +0200 | [diff] [blame] | 1441 | skb_queue_walk(amsdu, skb) |
| 1442 | total_len += skb->len; |
Ben Greear | bfa3536 | 2014-03-03 14:07:09 -0800 | [diff] [blame] | 1443 | |
Michal Kazior | 9aa505d | 2014-11-18 09:24:47 +0200 | [diff] [blame] | 1444 | space = total_len - skb_tailroom(first); |
Ben Greear | bfa3536 | 2014-03-03 14:07:09 -0800 | [diff] [blame] | 1445 | if ((space > 0) && |
Michal Kazior | 9aa505d | 2014-11-18 09:24:47 +0200 | [diff] [blame] | 1446 | (pskb_expand_head(first, 0, space, GFP_ATOMIC) < 0)) { |
Ben Greear | bfa3536 | 2014-03-03 14:07:09 -0800 | [diff] [blame] | 1447 | /* TODO: bump some rx-oom error stat */ |
| 1448 | /* put it back together so we can free the |
| 1449 | * whole list at once. |
| 1450 | */ |
Michal Kazior | 9aa505d | 2014-11-18 09:24:47 +0200 | [diff] [blame] | 1451 | __skb_queue_head(amsdu, first); |
Ben Greear | bfa3536 | 2014-03-03 14:07:09 -0800 | [diff] [blame] | 1452 | return -1; |
| 1453 | } |
| 1454 | |
| 1455 | /* Walk list again, copying contents into |
| 1456 | * msdu_head |
| 1457 | */ |
Michal Kazior | 9aa505d | 2014-11-18 09:24:47 +0200 | [diff] [blame] | 1458 | while ((skb = __skb_dequeue(amsdu))) { |
| 1459 | skb_copy_from_linear_data(skb, skb_put(first, skb->len), |
| 1460 | skb->len); |
| 1461 | dev_kfree_skb_any(skb); |
Ben Greear | bfa3536 | 2014-03-03 14:07:09 -0800 | [diff] [blame] | 1462 | } |
| 1463 | |
Michal Kazior | 9aa505d | 2014-11-18 09:24:47 +0200 | [diff] [blame] | 1464 | __skb_queue_head(amsdu, first); |
Ben Greear | bfa3536 | 2014-03-03 14:07:09 -0800 | [diff] [blame] | 1465 | return 0; |
| 1466 | } |
| 1467 | |
Michal Kazior | 581c25f | 2014-11-18 09:24:48 +0200 | [diff] [blame] | 1468 | static void ath10k_htt_rx_h_unchain(struct ath10k *ar, |
| 1469 | struct sk_buff_head *amsdu, |
| 1470 | bool chained) |
Janusz Dziedzic | 2acc4eb | 2014-03-19 07:09:40 +0100 | [diff] [blame] | 1471 | { |
Michal Kazior | 581c25f | 2014-11-18 09:24:48 +0200 | [diff] [blame] | 1472 | struct sk_buff *first; |
| 1473 | struct htt_rx_desc *rxd; |
| 1474 | enum rx_msdu_decap_format decap; |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1475 | |
Michal Kazior | 581c25f | 2014-11-18 09:24:48 +0200 | [diff] [blame] | 1476 | first = skb_peek(amsdu); |
| 1477 | rxd = (void *)first->data - sizeof(*rxd); |
Peter Oh | 1f5dbfb | 2015-07-15 19:01:21 -0700 | [diff] [blame] | 1478 | decap = MS(__le32_to_cpu(rxd->msdu_start.common.info1), |
Michal Kazior | 581c25f | 2014-11-18 09:24:48 +0200 | [diff] [blame] | 1479 | RX_MSDU_START_INFO1_DECAP_FORMAT); |
| 1480 | |
| 1481 | if (!chained) |
| 1482 | return; |
| 1483 | |
| 1484 | /* FIXME: Current unchaining logic can only handle simple case of raw |
| 1485 | * msdu chaining. If decapping is other than raw the chaining may be |
| 1486 | * more complex and this isn't handled by the current code. Don't even |
| 1487 | * try re-constructing such frames - it'll be pretty much garbage. |
| 1488 | */ |
| 1489 | if (decap != RX_MSDU_DECAP_RAW || |
| 1490 | skb_queue_len(amsdu) != 1 + rxd->frag_info.ring2_more_count) { |
| 1491 | __skb_queue_purge(amsdu); |
| 1492 | return; |
| 1493 | } |
| 1494 | |
| 1495 | ath10k_unchain_msdu(amsdu); |
| 1496 | } |
| 1497 | |
| 1498 | static bool ath10k_htt_rx_amsdu_allowed(struct ath10k *ar, |
| 1499 | struct sk_buff_head *amsdu, |
| 1500 | struct ieee80211_rx_status *rx_status) |
| 1501 | { |
Michal Kazior | 581c25f | 2014-11-18 09:24:48 +0200 | [diff] [blame] | 1502 | /* FIXME: It might be a good idea to do some fuzzy-testing to drop |
| 1503 | * invalid/dangerous frames. |
| 1504 | */ |
| 1505 | |
| 1506 | if (!rx_status->freq) { |
| 1507 | ath10k_warn(ar, "no channel configured; ignoring frame(s)!\n"); |
Janusz Dziedzic | 2acc4eb | 2014-03-19 07:09:40 +0100 | [diff] [blame] | 1508 | return false; |
| 1509 | } |
| 1510 | |
Michal Kazior | 581c25f | 2014-11-18 09:24:48 +0200 | [diff] [blame] | 1511 | if (test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags)) { |
| 1512 | ath10k_dbg(ar, ATH10K_DBG_HTT, "htt rx cac running\n"); |
Janusz Dziedzic | 2acc4eb | 2014-03-19 07:09:40 +0100 | [diff] [blame] | 1513 | return false; |
| 1514 | } |
| 1515 | |
| 1516 | return true; |
| 1517 | } |
| 1518 | |
Michal Kazior | 581c25f | 2014-11-18 09:24:48 +0200 | [diff] [blame] | 1519 | static void ath10k_htt_rx_h_filter(struct ath10k *ar, |
| 1520 | struct sk_buff_head *amsdu, |
| 1521 | struct ieee80211_rx_status *rx_status) |
| 1522 | { |
| 1523 | if (skb_queue_empty(amsdu)) |
| 1524 | return; |
| 1525 | |
| 1526 | if (ath10k_htt_rx_amsdu_allowed(ar, amsdu, rx_status)) |
| 1527 | return; |
| 1528 | |
| 1529 | __skb_queue_purge(amsdu); |
| 1530 | } |
| 1531 | |
Rajkumar Manoharan | 1823566 | 2016-03-22 17:22:14 +0530 | [diff] [blame] | 1532 | static int ath10k_htt_rx_handle_amsdu(struct ath10k_htt *htt) |
| 1533 | { |
| 1534 | struct ath10k *ar = htt->ar; |
| 1535 | static struct ieee80211_rx_status rx_status; |
| 1536 | struct sk_buff_head amsdu; |
| 1537 | int ret; |
| 1538 | |
| 1539 | __skb_queue_head_init(&amsdu); |
| 1540 | |
| 1541 | spin_lock_bh(&htt->rx_ring.lock); |
| 1542 | if (htt->rx_confused) { |
| 1543 | spin_unlock_bh(&htt->rx_ring.lock); |
| 1544 | return -EIO; |
| 1545 | } |
| 1546 | ret = ath10k_htt_rx_amsdu_pop(htt, &amsdu); |
| 1547 | spin_unlock_bh(&htt->rx_ring.lock); |
| 1548 | |
| 1549 | if (ret < 0) { |
| 1550 | ath10k_warn(ar, "rx ring became corrupted: %d\n", ret); |
| 1551 | __skb_queue_purge(&amsdu); |
| 1552 | /* FIXME: It's probably a good idea to reboot the |
| 1553 | * device instead of leaving it inoperable. |
| 1554 | */ |
| 1555 | htt->rx_confused = true; |
| 1556 | return ret; |
| 1557 | } |
| 1558 | |
| 1559 | ath10k_htt_rx_h_ppdu(ar, &amsdu, &rx_status, 0xffff); |
| 1560 | ath10k_htt_rx_h_unchain(ar, &amsdu, ret > 0); |
| 1561 | ath10k_htt_rx_h_filter(ar, &amsdu, &rx_status); |
| 1562 | ath10k_htt_rx_h_mpdu(ar, &amsdu, &rx_status); |
| 1563 | ath10k_htt_rx_h_deliver(ar, &amsdu, &rx_status); |
| 1564 | |
| 1565 | return 0; |
| 1566 | } |
| 1567 | |
Rajkumar Manoharan | 3128b3d | 2016-03-22 17:22:15 +0530 | [diff] [blame] | 1568 | static void ath10k_htt_rx_proc_rx_ind(struct ath10k_htt *htt, |
| 1569 | struct htt_rx_indication *rx) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1570 | { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1571 | struct ath10k *ar = htt->ar; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1572 | struct htt_rx_indication_mpdu_range *mpdu_ranges; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1573 | int num_mpdu_ranges; |
Rajkumar Manoharan | 1823566 | 2016-03-22 17:22:14 +0530 | [diff] [blame] | 1574 | int i, mpdu_count = 0; |
Michal Kazior | e0bd751 | 2014-11-18 09:24:48 +0200 | [diff] [blame] | 1575 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1576 | num_mpdu_ranges = MS(__le32_to_cpu(rx->hdr.info1), |
| 1577 | HTT_RX_INDICATION_INFO1_NUM_MPDU_RANGES); |
| 1578 | mpdu_ranges = htt_rx_ind_get_mpdu_ranges(rx); |
| 1579 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1580 | ath10k_dbg_dump(ar, ATH10K_DBG_HTT_DUMP, NULL, "htt rx ind: ", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1581 | rx, sizeof(*rx) + |
| 1582 | (sizeof(struct htt_rx_indication_mpdu_range) * |
| 1583 | num_mpdu_ranges)); |
| 1584 | |
Michal Kazior | d540690 | 2014-11-18 09:24:47 +0200 | [diff] [blame] | 1585 | for (i = 0; i < num_mpdu_ranges; i++) |
| 1586 | mpdu_count += mpdu_ranges[i].mpdu_count; |
Janusz Dziedzic | d84dd60 | 2014-03-24 21:23:20 +0100 | [diff] [blame] | 1587 | |
Rajkumar Manoharan | 3128b3d | 2016-03-22 17:22:15 +0530 | [diff] [blame] | 1588 | atomic_add(mpdu_count, &htt->num_mpdus_ready); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1589 | |
Rajkumar Manoharan | 3128b3d | 2016-03-22 17:22:15 +0530 | [diff] [blame] | 1590 | tasklet_schedule(&htt->txrx_compl_task); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1591 | } |
| 1592 | |
Rajkumar Manoharan | 1823566 | 2016-03-22 17:22:14 +0530 | [diff] [blame] | 1593 | static void ath10k_htt_rx_frag_handler(struct ath10k_htt *htt) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1594 | { |
Rajkumar Manoharan | 3128b3d | 2016-03-22 17:22:15 +0530 | [diff] [blame] | 1595 | atomic_inc(&htt->num_mpdus_ready); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1596 | |
Rajkumar Manoharan | 3128b3d | 2016-03-22 17:22:15 +0530 | [diff] [blame] | 1597 | tasklet_schedule(&htt->txrx_compl_task); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1598 | } |
| 1599 | |
Rajkumar Manoharan | 59465fe | 2016-03-22 17:22:11 +0530 | [diff] [blame] | 1600 | static void ath10k_htt_rx_tx_compl_ind(struct ath10k *ar, |
Michal Kazior | 6c5151a | 2014-02-27 18:50:04 +0200 | [diff] [blame] | 1601 | struct sk_buff *skb) |
| 1602 | { |
| 1603 | struct ath10k_htt *htt = &ar->htt; |
| 1604 | struct htt_resp *resp = (struct htt_resp *)skb->data; |
| 1605 | struct htt_tx_done tx_done = {}; |
| 1606 | int status = MS(resp->data_tx_completion.flags, HTT_DATA_TX_STATUS); |
| 1607 | __le16 msdu_id; |
| 1608 | int i; |
| 1609 | |
| 1610 | switch (status) { |
| 1611 | case HTT_DATA_TX_STATUS_NO_ACK: |
Rajkumar Manoharan | 59465fe | 2016-03-22 17:22:11 +0530 | [diff] [blame] | 1612 | tx_done.status = HTT_TX_COMPL_STATE_NOACK; |
Michal Kazior | 6c5151a | 2014-02-27 18:50:04 +0200 | [diff] [blame] | 1613 | break; |
| 1614 | case HTT_DATA_TX_STATUS_OK: |
Rajkumar Manoharan | 59465fe | 2016-03-22 17:22:11 +0530 | [diff] [blame] | 1615 | tx_done.status = HTT_TX_COMPL_STATE_ACK; |
Michal Kazior | 6c5151a | 2014-02-27 18:50:04 +0200 | [diff] [blame] | 1616 | break; |
| 1617 | case HTT_DATA_TX_STATUS_DISCARD: |
| 1618 | case HTT_DATA_TX_STATUS_POSTPONE: |
| 1619 | case HTT_DATA_TX_STATUS_DOWNLOAD_FAIL: |
Rajkumar Manoharan | 59465fe | 2016-03-22 17:22:11 +0530 | [diff] [blame] | 1620 | tx_done.status = HTT_TX_COMPL_STATE_DISCARD; |
Michal Kazior | 6c5151a | 2014-02-27 18:50:04 +0200 | [diff] [blame] | 1621 | break; |
| 1622 | default: |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1623 | ath10k_warn(ar, "unhandled tx completion status %d\n", status); |
Rajkumar Manoharan | 59465fe | 2016-03-22 17:22:11 +0530 | [diff] [blame] | 1624 | tx_done.status = HTT_TX_COMPL_STATE_DISCARD; |
Michal Kazior | 6c5151a | 2014-02-27 18:50:04 +0200 | [diff] [blame] | 1625 | break; |
| 1626 | } |
| 1627 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1628 | ath10k_dbg(ar, ATH10K_DBG_HTT, "htt tx completion num_msdus %d\n", |
Michal Kazior | 6c5151a | 2014-02-27 18:50:04 +0200 | [diff] [blame] | 1629 | resp->data_tx_completion.num_msdus); |
| 1630 | |
| 1631 | for (i = 0; i < resp->data_tx_completion.num_msdus; i++) { |
| 1632 | msdu_id = resp->data_tx_completion.msdus[i]; |
| 1633 | tx_done.msdu_id = __le16_to_cpu(msdu_id); |
Rajkumar Manoharan | 59465fe | 2016-03-22 17:22:11 +0530 | [diff] [blame] | 1634 | |
| 1635 | /* kfifo_put: In practice firmware shouldn't fire off per-CE |
| 1636 | * interrupt and main interrupt (MSI/-X range case) for the same |
| 1637 | * HTC service so it should be safe to use kfifo_put w/o lock. |
| 1638 | * |
| 1639 | * From kfifo_put() documentation: |
| 1640 | * Note that with only one concurrent reader and one concurrent |
| 1641 | * writer, you don't need extra locking to use these macro. |
| 1642 | */ |
| 1643 | if (!kfifo_put(&htt->txdone_fifo, tx_done)) { |
| 1644 | ath10k_warn(ar, "txdone fifo overrun, msdu_id %d status %d\n", |
| 1645 | tx_done.msdu_id, tx_done.status); |
| 1646 | ath10k_txrx_tx_unref(htt, &tx_done); |
| 1647 | } |
Michal Kazior | 6c5151a | 2014-02-27 18:50:04 +0200 | [diff] [blame] | 1648 | } |
| 1649 | } |
| 1650 | |
Michal Kazior | aa5b4fb | 2014-07-23 12:20:33 +0200 | [diff] [blame] | 1651 | static void ath10k_htt_rx_addba(struct ath10k *ar, struct htt_resp *resp) |
| 1652 | { |
| 1653 | struct htt_rx_addba *ev = &resp->rx_addba; |
| 1654 | struct ath10k_peer *peer; |
| 1655 | struct ath10k_vif *arvif; |
| 1656 | u16 info0, tid, peer_id; |
| 1657 | |
| 1658 | info0 = __le16_to_cpu(ev->info0); |
| 1659 | tid = MS(info0, HTT_RX_BA_INFO0_TID); |
| 1660 | peer_id = MS(info0, HTT_RX_BA_INFO0_PEER_ID); |
| 1661 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1662 | ath10k_dbg(ar, ATH10K_DBG_HTT, |
Michal Kazior | aa5b4fb | 2014-07-23 12:20:33 +0200 | [diff] [blame] | 1663 | "htt rx addba tid %hu peer_id %hu size %hhu\n", |
| 1664 | tid, peer_id, ev->window_size); |
| 1665 | |
| 1666 | spin_lock_bh(&ar->data_lock); |
| 1667 | peer = ath10k_peer_find_by_id(ar, peer_id); |
| 1668 | if (!peer) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1669 | ath10k_warn(ar, "received addba event for invalid peer_id: %hu\n", |
Michal Kazior | aa5b4fb | 2014-07-23 12:20:33 +0200 | [diff] [blame] | 1670 | peer_id); |
| 1671 | spin_unlock_bh(&ar->data_lock); |
| 1672 | return; |
| 1673 | } |
| 1674 | |
| 1675 | arvif = ath10k_get_arvif(ar, peer->vdev_id); |
| 1676 | if (!arvif) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1677 | ath10k_warn(ar, "received addba event for invalid vdev_id: %u\n", |
Michal Kazior | aa5b4fb | 2014-07-23 12:20:33 +0200 | [diff] [blame] | 1678 | peer->vdev_id); |
| 1679 | spin_unlock_bh(&ar->data_lock); |
| 1680 | return; |
| 1681 | } |
| 1682 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1683 | ath10k_dbg(ar, ATH10K_DBG_HTT, |
Michal Kazior | aa5b4fb | 2014-07-23 12:20:33 +0200 | [diff] [blame] | 1684 | "htt rx start rx ba session sta %pM tid %hu size %hhu\n", |
| 1685 | peer->addr, tid, ev->window_size); |
| 1686 | |
| 1687 | ieee80211_start_rx_ba_session_offl(arvif->vif, peer->addr, tid); |
| 1688 | spin_unlock_bh(&ar->data_lock); |
| 1689 | } |
| 1690 | |
| 1691 | static void ath10k_htt_rx_delba(struct ath10k *ar, struct htt_resp *resp) |
| 1692 | { |
| 1693 | struct htt_rx_delba *ev = &resp->rx_delba; |
| 1694 | struct ath10k_peer *peer; |
| 1695 | struct ath10k_vif *arvif; |
| 1696 | u16 info0, tid, peer_id; |
| 1697 | |
| 1698 | info0 = __le16_to_cpu(ev->info0); |
| 1699 | tid = MS(info0, HTT_RX_BA_INFO0_TID); |
| 1700 | peer_id = MS(info0, HTT_RX_BA_INFO0_PEER_ID); |
| 1701 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1702 | ath10k_dbg(ar, ATH10K_DBG_HTT, |
Michal Kazior | aa5b4fb | 2014-07-23 12:20:33 +0200 | [diff] [blame] | 1703 | "htt rx delba tid %hu peer_id %hu\n", |
| 1704 | tid, peer_id); |
| 1705 | |
| 1706 | spin_lock_bh(&ar->data_lock); |
| 1707 | peer = ath10k_peer_find_by_id(ar, peer_id); |
| 1708 | if (!peer) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1709 | ath10k_warn(ar, "received addba event for invalid peer_id: %hu\n", |
Michal Kazior | aa5b4fb | 2014-07-23 12:20:33 +0200 | [diff] [blame] | 1710 | peer_id); |
| 1711 | spin_unlock_bh(&ar->data_lock); |
| 1712 | return; |
| 1713 | } |
| 1714 | |
| 1715 | arvif = ath10k_get_arvif(ar, peer->vdev_id); |
| 1716 | if (!arvif) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1717 | ath10k_warn(ar, "received addba event for invalid vdev_id: %u\n", |
Michal Kazior | aa5b4fb | 2014-07-23 12:20:33 +0200 | [diff] [blame] | 1718 | peer->vdev_id); |
| 1719 | spin_unlock_bh(&ar->data_lock); |
| 1720 | return; |
| 1721 | } |
| 1722 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1723 | ath10k_dbg(ar, ATH10K_DBG_HTT, |
Michal Kazior | aa5b4fb | 2014-07-23 12:20:33 +0200 | [diff] [blame] | 1724 | "htt rx stop rx ba session sta %pM tid %hu\n", |
| 1725 | peer->addr, tid); |
| 1726 | |
| 1727 | ieee80211_stop_rx_ba_session_offl(arvif->vif, peer->addr, tid); |
| 1728 | spin_unlock_bh(&ar->data_lock); |
| 1729 | } |
| 1730 | |
Michal Kazior | c545070 | 2015-01-24 12:14:48 +0200 | [diff] [blame] | 1731 | static int ath10k_htt_rx_extract_amsdu(struct sk_buff_head *list, |
| 1732 | struct sk_buff_head *amsdu) |
| 1733 | { |
| 1734 | struct sk_buff *msdu; |
| 1735 | struct htt_rx_desc *rxd; |
| 1736 | |
| 1737 | if (skb_queue_empty(list)) |
| 1738 | return -ENOBUFS; |
| 1739 | |
| 1740 | if (WARN_ON(!skb_queue_empty(amsdu))) |
| 1741 | return -EINVAL; |
| 1742 | |
| 1743 | while ((msdu = __skb_dequeue(list))) { |
| 1744 | __skb_queue_tail(amsdu, msdu); |
| 1745 | |
| 1746 | rxd = (void *)msdu->data - sizeof(*rxd); |
Peter Oh | 1f5dbfb | 2015-07-15 19:01:21 -0700 | [diff] [blame] | 1747 | if (rxd->msdu_end.common.info0 & |
Michal Kazior | c545070 | 2015-01-24 12:14:48 +0200 | [diff] [blame] | 1748 | __cpu_to_le32(RX_MSDU_END_INFO0_LAST_MSDU)) |
| 1749 | break; |
| 1750 | } |
| 1751 | |
| 1752 | msdu = skb_peek_tail(amsdu); |
| 1753 | rxd = (void *)msdu->data - sizeof(*rxd); |
Peter Oh | 1f5dbfb | 2015-07-15 19:01:21 -0700 | [diff] [blame] | 1754 | if (!(rxd->msdu_end.common.info0 & |
Michal Kazior | c545070 | 2015-01-24 12:14:48 +0200 | [diff] [blame] | 1755 | __cpu_to_le32(RX_MSDU_END_INFO0_LAST_MSDU))) { |
| 1756 | skb_queue_splice_init(amsdu, list); |
| 1757 | return -EAGAIN; |
| 1758 | } |
| 1759 | |
| 1760 | return 0; |
| 1761 | } |
| 1762 | |
| 1763 | static void ath10k_htt_rx_h_rx_offload_prot(struct ieee80211_rx_status *status, |
| 1764 | struct sk_buff *skb) |
| 1765 | { |
| 1766 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
| 1767 | |
| 1768 | if (!ieee80211_has_protected(hdr->frame_control)) |
| 1769 | return; |
| 1770 | |
| 1771 | /* Offloaded frames are already decrypted but firmware insists they are |
| 1772 | * protected in the 802.11 header. Strip the flag. Otherwise mac80211 |
| 1773 | * will drop the frame. |
| 1774 | */ |
| 1775 | |
| 1776 | hdr->frame_control &= ~__cpu_to_le16(IEEE80211_FCTL_PROTECTED); |
| 1777 | status->flag |= RX_FLAG_DECRYPTED | |
| 1778 | RX_FLAG_IV_STRIPPED | |
| 1779 | RX_FLAG_MMIC_STRIPPED; |
| 1780 | } |
| 1781 | |
| 1782 | static void ath10k_htt_rx_h_rx_offload(struct ath10k *ar, |
| 1783 | struct sk_buff_head *list) |
| 1784 | { |
| 1785 | struct ath10k_htt *htt = &ar->htt; |
| 1786 | struct ieee80211_rx_status *status = &htt->rx_status; |
| 1787 | struct htt_rx_offload_msdu *rx; |
| 1788 | struct sk_buff *msdu; |
| 1789 | size_t offset; |
| 1790 | |
| 1791 | while ((msdu = __skb_dequeue(list))) { |
| 1792 | /* Offloaded frames don't have Rx descriptor. Instead they have |
| 1793 | * a short meta information header. |
| 1794 | */ |
| 1795 | |
| 1796 | rx = (void *)msdu->data; |
| 1797 | |
| 1798 | skb_put(msdu, sizeof(*rx)); |
| 1799 | skb_pull(msdu, sizeof(*rx)); |
| 1800 | |
| 1801 | if (skb_tailroom(msdu) < __le16_to_cpu(rx->msdu_len)) { |
| 1802 | ath10k_warn(ar, "dropping frame: offloaded rx msdu is too long!\n"); |
| 1803 | dev_kfree_skb_any(msdu); |
| 1804 | continue; |
| 1805 | } |
| 1806 | |
| 1807 | skb_put(msdu, __le16_to_cpu(rx->msdu_len)); |
| 1808 | |
| 1809 | /* Offloaded rx header length isn't multiple of 2 nor 4 so the |
| 1810 | * actual payload is unaligned. Align the frame. Otherwise |
| 1811 | * mac80211 complains. This shouldn't reduce performance much |
| 1812 | * because these offloaded frames are rare. |
| 1813 | */ |
| 1814 | offset = 4 - ((unsigned long)msdu->data & 3); |
| 1815 | skb_put(msdu, offset); |
| 1816 | memmove(msdu->data + offset, msdu->data, msdu->len); |
| 1817 | skb_pull(msdu, offset); |
| 1818 | |
| 1819 | /* FIXME: The frame is NWifi. Re-construct QoS Control |
| 1820 | * if possible later. |
| 1821 | */ |
| 1822 | |
| 1823 | memset(status, 0, sizeof(*status)); |
| 1824 | status->flag |= RX_FLAG_NO_SIGNAL_VAL; |
| 1825 | |
| 1826 | ath10k_htt_rx_h_rx_offload_prot(status, msdu); |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 1827 | ath10k_htt_rx_h_channel(ar, status, NULL, rx->vdev_id); |
Michal Kazior | c545070 | 2015-01-24 12:14:48 +0200 | [diff] [blame] | 1828 | ath10k_process_rx(ar, status, msdu); |
| 1829 | } |
| 1830 | } |
| 1831 | |
| 1832 | static void ath10k_htt_rx_in_ord_ind(struct ath10k *ar, struct sk_buff *skb) |
| 1833 | { |
| 1834 | struct ath10k_htt *htt = &ar->htt; |
| 1835 | struct htt_resp *resp = (void *)skb->data; |
| 1836 | struct ieee80211_rx_status *status = &htt->rx_status; |
| 1837 | struct sk_buff_head list; |
| 1838 | struct sk_buff_head amsdu; |
| 1839 | u16 peer_id; |
| 1840 | u16 msdu_count; |
| 1841 | u8 vdev_id; |
| 1842 | u8 tid; |
| 1843 | bool offload; |
| 1844 | bool frag; |
| 1845 | int ret; |
| 1846 | |
| 1847 | lockdep_assert_held(&htt->rx_ring.lock); |
| 1848 | |
| 1849 | if (htt->rx_confused) |
| 1850 | return; |
| 1851 | |
| 1852 | skb_pull(skb, sizeof(resp->hdr)); |
| 1853 | skb_pull(skb, sizeof(resp->rx_in_ord_ind)); |
| 1854 | |
| 1855 | peer_id = __le16_to_cpu(resp->rx_in_ord_ind.peer_id); |
| 1856 | msdu_count = __le16_to_cpu(resp->rx_in_ord_ind.msdu_count); |
| 1857 | vdev_id = resp->rx_in_ord_ind.vdev_id; |
| 1858 | tid = SM(resp->rx_in_ord_ind.info, HTT_RX_IN_ORD_IND_INFO_TID); |
| 1859 | offload = !!(resp->rx_in_ord_ind.info & |
| 1860 | HTT_RX_IN_ORD_IND_INFO_OFFLOAD_MASK); |
| 1861 | frag = !!(resp->rx_in_ord_ind.info & HTT_RX_IN_ORD_IND_INFO_FRAG_MASK); |
| 1862 | |
| 1863 | ath10k_dbg(ar, ATH10K_DBG_HTT, |
| 1864 | "htt rx in ord vdev %i peer %i tid %i offload %i frag %i msdu count %i\n", |
| 1865 | vdev_id, peer_id, tid, offload, frag, msdu_count); |
| 1866 | |
| 1867 | if (skb->len < msdu_count * sizeof(*resp->rx_in_ord_ind.msdu_descs)) { |
| 1868 | ath10k_warn(ar, "dropping invalid in order rx indication\n"); |
| 1869 | return; |
| 1870 | } |
| 1871 | |
| 1872 | /* The event can deliver more than 1 A-MSDU. Each A-MSDU is later |
| 1873 | * extracted and processed. |
| 1874 | */ |
| 1875 | __skb_queue_head_init(&list); |
| 1876 | ret = ath10k_htt_rx_pop_paddr_list(htt, &resp->rx_in_ord_ind, &list); |
| 1877 | if (ret < 0) { |
| 1878 | ath10k_warn(ar, "failed to pop paddr list: %d\n", ret); |
| 1879 | htt->rx_confused = true; |
| 1880 | return; |
| 1881 | } |
| 1882 | |
| 1883 | /* Offloaded frames are very different and need to be handled |
| 1884 | * separately. |
| 1885 | */ |
| 1886 | if (offload) |
| 1887 | ath10k_htt_rx_h_rx_offload(ar, &list); |
| 1888 | |
| 1889 | while (!skb_queue_empty(&list)) { |
| 1890 | __skb_queue_head_init(&amsdu); |
| 1891 | ret = ath10k_htt_rx_extract_amsdu(&list, &amsdu); |
| 1892 | switch (ret) { |
| 1893 | case 0: |
| 1894 | /* Note: The in-order indication may report interleaved |
| 1895 | * frames from different PPDUs meaning reported rx rate |
| 1896 | * to mac80211 isn't accurate/reliable. It's still |
| 1897 | * better to report something than nothing though. This |
| 1898 | * should still give an idea about rx rate to the user. |
| 1899 | */ |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 1900 | ath10k_htt_rx_h_ppdu(ar, &amsdu, status, vdev_id); |
Michal Kazior | c545070 | 2015-01-24 12:14:48 +0200 | [diff] [blame] | 1901 | ath10k_htt_rx_h_filter(ar, &amsdu, status); |
| 1902 | ath10k_htt_rx_h_mpdu(ar, &amsdu, status); |
| 1903 | ath10k_htt_rx_h_deliver(ar, &amsdu, status); |
| 1904 | break; |
| 1905 | case -EAGAIN: |
| 1906 | /* fall through */ |
| 1907 | default: |
| 1908 | /* Should not happen. */ |
| 1909 | ath10k_warn(ar, "failed to extract amsdu: %d\n", ret); |
| 1910 | htt->rx_confused = true; |
| 1911 | __skb_queue_purge(&list); |
| 1912 | return; |
| 1913 | } |
| 1914 | } |
| 1915 | |
| 1916 | tasklet_schedule(&htt->rx_replenish_task); |
| 1917 | } |
| 1918 | |
Michal Kazior | 839ae63 | 2016-03-06 16:14:32 +0200 | [diff] [blame] | 1919 | static void ath10k_htt_rx_tx_fetch_resp_id_confirm(struct ath10k *ar, |
| 1920 | const __le32 *resp_ids, |
| 1921 | int num_resp_ids) |
| 1922 | { |
| 1923 | int i; |
| 1924 | u32 resp_id; |
| 1925 | |
| 1926 | ath10k_dbg(ar, ATH10K_DBG_HTT, "htt rx tx fetch confirm num_resp_ids %d\n", |
| 1927 | num_resp_ids); |
| 1928 | |
| 1929 | for (i = 0; i < num_resp_ids; i++) { |
| 1930 | resp_id = le32_to_cpu(resp_ids[i]); |
| 1931 | |
| 1932 | ath10k_dbg(ar, ATH10K_DBG_HTT, "htt rx tx fetch confirm resp_id %u\n", |
| 1933 | resp_id); |
| 1934 | |
| 1935 | /* TODO: free resp_id */ |
| 1936 | } |
| 1937 | } |
| 1938 | |
| 1939 | static void ath10k_htt_rx_tx_fetch_ind(struct ath10k *ar, struct sk_buff *skb) |
| 1940 | { |
Michal Kazior | 426e10e | 2016-03-06 16:14:43 +0200 | [diff] [blame] | 1941 | struct ieee80211_hw *hw = ar->hw; |
| 1942 | struct ieee80211_txq *txq; |
Michal Kazior | 839ae63 | 2016-03-06 16:14:32 +0200 | [diff] [blame] | 1943 | struct htt_resp *resp = (struct htt_resp *)skb->data; |
| 1944 | struct htt_tx_fetch_record *record; |
| 1945 | size_t len; |
| 1946 | size_t max_num_bytes; |
| 1947 | size_t max_num_msdus; |
Michal Kazior | 426e10e | 2016-03-06 16:14:43 +0200 | [diff] [blame] | 1948 | size_t num_bytes; |
| 1949 | size_t num_msdus; |
Michal Kazior | 839ae63 | 2016-03-06 16:14:32 +0200 | [diff] [blame] | 1950 | const __le32 *resp_ids; |
| 1951 | u16 num_records; |
| 1952 | u16 num_resp_ids; |
| 1953 | u16 peer_id; |
| 1954 | u8 tid; |
Michal Kazior | 426e10e | 2016-03-06 16:14:43 +0200 | [diff] [blame] | 1955 | int ret; |
Michal Kazior | 839ae63 | 2016-03-06 16:14:32 +0200 | [diff] [blame] | 1956 | int i; |
| 1957 | |
| 1958 | ath10k_dbg(ar, ATH10K_DBG_HTT, "htt rx tx fetch ind\n"); |
| 1959 | |
| 1960 | len = sizeof(resp->hdr) + sizeof(resp->tx_fetch_ind); |
| 1961 | if (unlikely(skb->len < len)) { |
| 1962 | ath10k_warn(ar, "received corrupted tx_fetch_ind event: buffer too short\n"); |
| 1963 | return; |
| 1964 | } |
| 1965 | |
| 1966 | num_records = le16_to_cpu(resp->tx_fetch_ind.num_records); |
| 1967 | num_resp_ids = le16_to_cpu(resp->tx_fetch_ind.num_resp_ids); |
| 1968 | |
| 1969 | len += sizeof(resp->tx_fetch_ind.records[0]) * num_records; |
| 1970 | len += sizeof(resp->tx_fetch_ind.resp_ids[0]) * num_resp_ids; |
| 1971 | |
| 1972 | if (unlikely(skb->len < len)) { |
| 1973 | ath10k_warn(ar, "received corrupted tx_fetch_ind event: too many records/resp_ids\n"); |
| 1974 | return; |
| 1975 | } |
| 1976 | |
| 1977 | ath10k_dbg(ar, ATH10K_DBG_HTT, "htt rx tx fetch ind num records %hu num resps %hu seq %hu\n", |
| 1978 | num_records, num_resp_ids, |
| 1979 | le16_to_cpu(resp->tx_fetch_ind.fetch_seq_num)); |
| 1980 | |
Michal Kazior | 426e10e | 2016-03-06 16:14:43 +0200 | [diff] [blame] | 1981 | if (!ar->htt.tx_q_state.enabled) { |
| 1982 | ath10k_warn(ar, "received unexpected tx_fetch_ind event: not enabled\n"); |
| 1983 | return; |
| 1984 | } |
| 1985 | |
| 1986 | if (ar->htt.tx_q_state.mode == HTT_TX_MODE_SWITCH_PUSH) { |
| 1987 | ath10k_warn(ar, "received unexpected tx_fetch_ind event: in push mode\n"); |
| 1988 | return; |
| 1989 | } |
| 1990 | |
| 1991 | rcu_read_lock(); |
Michal Kazior | 839ae63 | 2016-03-06 16:14:32 +0200 | [diff] [blame] | 1992 | |
| 1993 | for (i = 0; i < num_records; i++) { |
| 1994 | record = &resp->tx_fetch_ind.records[i]; |
| 1995 | peer_id = MS(le16_to_cpu(record->info), |
| 1996 | HTT_TX_FETCH_RECORD_INFO_PEER_ID); |
| 1997 | tid = MS(le16_to_cpu(record->info), |
| 1998 | HTT_TX_FETCH_RECORD_INFO_TID); |
| 1999 | max_num_msdus = le16_to_cpu(record->num_msdus); |
| 2000 | max_num_bytes = le32_to_cpu(record->num_bytes); |
| 2001 | |
| 2002 | ath10k_dbg(ar, ATH10K_DBG_HTT, "htt rx tx fetch record %i peer_id %hu tid %hhu msdus %zu bytes %zu\n", |
| 2003 | i, peer_id, tid, max_num_msdus, max_num_bytes); |
| 2004 | |
| 2005 | if (unlikely(peer_id >= ar->htt.tx_q_state.num_peers) || |
| 2006 | unlikely(tid >= ar->htt.tx_q_state.num_tids)) { |
| 2007 | ath10k_warn(ar, "received out of range peer_id %hu tid %hhu\n", |
| 2008 | peer_id, tid); |
| 2009 | continue; |
| 2010 | } |
| 2011 | |
Michal Kazior | 426e10e | 2016-03-06 16:14:43 +0200 | [diff] [blame] | 2012 | spin_lock_bh(&ar->data_lock); |
| 2013 | txq = ath10k_mac_txq_lookup(ar, peer_id, tid); |
| 2014 | spin_unlock_bh(&ar->data_lock); |
| 2015 | |
| 2016 | /* It is okay to release the lock and use txq because RCU read |
| 2017 | * lock is held. |
| 2018 | */ |
| 2019 | |
| 2020 | if (unlikely(!txq)) { |
| 2021 | ath10k_warn(ar, "failed to lookup txq for peer_id %hu tid %hhu\n", |
| 2022 | peer_id, tid); |
| 2023 | continue; |
| 2024 | } |
| 2025 | |
| 2026 | num_msdus = 0; |
| 2027 | num_bytes = 0; |
| 2028 | |
| 2029 | while (num_msdus < max_num_msdus && |
| 2030 | num_bytes < max_num_bytes) { |
| 2031 | ret = ath10k_mac_tx_push_txq(hw, txq); |
| 2032 | if (ret < 0) |
| 2033 | break; |
| 2034 | |
| 2035 | num_msdus++; |
| 2036 | num_bytes += ret; |
| 2037 | } |
| 2038 | |
| 2039 | record->num_msdus = cpu_to_le16(num_msdus); |
| 2040 | record->num_bytes = cpu_to_le32(num_bytes); |
| 2041 | |
| 2042 | ath10k_htt_tx_txq_recalc(hw, txq); |
Michal Kazior | 839ae63 | 2016-03-06 16:14:32 +0200 | [diff] [blame] | 2043 | } |
| 2044 | |
Michal Kazior | 426e10e | 2016-03-06 16:14:43 +0200 | [diff] [blame] | 2045 | rcu_read_unlock(); |
| 2046 | |
Michal Kazior | 839ae63 | 2016-03-06 16:14:32 +0200 | [diff] [blame] | 2047 | resp_ids = ath10k_htt_get_tx_fetch_ind_resp_ids(&resp->tx_fetch_ind); |
| 2048 | ath10k_htt_rx_tx_fetch_resp_id_confirm(ar, resp_ids, num_resp_ids); |
| 2049 | |
Michal Kazior | 426e10e | 2016-03-06 16:14:43 +0200 | [diff] [blame] | 2050 | ret = ath10k_htt_tx_fetch_resp(ar, |
| 2051 | resp->tx_fetch_ind.token, |
| 2052 | resp->tx_fetch_ind.fetch_seq_num, |
| 2053 | resp->tx_fetch_ind.records, |
| 2054 | num_records); |
| 2055 | if (unlikely(ret)) { |
| 2056 | ath10k_warn(ar, "failed to submit tx fetch resp for token 0x%08x: %d\n", |
| 2057 | le32_to_cpu(resp->tx_fetch_ind.token), ret); |
| 2058 | /* FIXME: request fw restart */ |
| 2059 | } |
| 2060 | |
| 2061 | ath10k_htt_tx_txq_sync(ar); |
Michal Kazior | 839ae63 | 2016-03-06 16:14:32 +0200 | [diff] [blame] | 2062 | } |
| 2063 | |
| 2064 | static void ath10k_htt_rx_tx_fetch_confirm(struct ath10k *ar, |
| 2065 | struct sk_buff *skb) |
| 2066 | { |
| 2067 | const struct htt_resp *resp = (void *)skb->data; |
| 2068 | size_t len; |
| 2069 | int num_resp_ids; |
| 2070 | |
| 2071 | ath10k_dbg(ar, ATH10K_DBG_HTT, "htt rx tx fetch confirm\n"); |
| 2072 | |
| 2073 | len = sizeof(resp->hdr) + sizeof(resp->tx_fetch_confirm); |
| 2074 | if (unlikely(skb->len < len)) { |
| 2075 | ath10k_warn(ar, "received corrupted tx_fetch_confirm event: buffer too short\n"); |
| 2076 | return; |
| 2077 | } |
| 2078 | |
| 2079 | num_resp_ids = le16_to_cpu(resp->tx_fetch_confirm.num_resp_ids); |
| 2080 | len += sizeof(resp->tx_fetch_confirm.resp_ids[0]) * num_resp_ids; |
| 2081 | |
| 2082 | if (unlikely(skb->len < len)) { |
| 2083 | ath10k_warn(ar, "received corrupted tx_fetch_confirm event: resp_ids buffer overflow\n"); |
| 2084 | return; |
| 2085 | } |
| 2086 | |
| 2087 | ath10k_htt_rx_tx_fetch_resp_id_confirm(ar, |
| 2088 | resp->tx_fetch_confirm.resp_ids, |
| 2089 | num_resp_ids); |
| 2090 | } |
| 2091 | |
| 2092 | static void ath10k_htt_rx_tx_mode_switch_ind(struct ath10k *ar, |
| 2093 | struct sk_buff *skb) |
| 2094 | { |
| 2095 | const struct htt_resp *resp = (void *)skb->data; |
| 2096 | const struct htt_tx_mode_switch_record *record; |
Michal Kazior | 426e10e | 2016-03-06 16:14:43 +0200 | [diff] [blame] | 2097 | struct ieee80211_txq *txq; |
| 2098 | struct ath10k_txq *artxq; |
Michal Kazior | 839ae63 | 2016-03-06 16:14:32 +0200 | [diff] [blame] | 2099 | size_t len; |
| 2100 | size_t num_records; |
| 2101 | enum htt_tx_mode_switch_mode mode; |
| 2102 | bool enable; |
| 2103 | u16 info0; |
| 2104 | u16 info1; |
| 2105 | u16 threshold; |
| 2106 | u16 peer_id; |
| 2107 | u8 tid; |
| 2108 | int i; |
| 2109 | |
| 2110 | ath10k_dbg(ar, ATH10K_DBG_HTT, "htt rx tx mode switch ind\n"); |
| 2111 | |
| 2112 | len = sizeof(resp->hdr) + sizeof(resp->tx_mode_switch_ind); |
| 2113 | if (unlikely(skb->len < len)) { |
| 2114 | ath10k_warn(ar, "received corrupted tx_mode_switch_ind event: buffer too short\n"); |
| 2115 | return; |
| 2116 | } |
| 2117 | |
| 2118 | info0 = le16_to_cpu(resp->tx_mode_switch_ind.info0); |
| 2119 | info1 = le16_to_cpu(resp->tx_mode_switch_ind.info1); |
| 2120 | |
| 2121 | enable = !!(info0 & HTT_TX_MODE_SWITCH_IND_INFO0_ENABLE); |
| 2122 | num_records = MS(info0, HTT_TX_MODE_SWITCH_IND_INFO1_THRESHOLD); |
| 2123 | mode = MS(info1, HTT_TX_MODE_SWITCH_IND_INFO1_MODE); |
| 2124 | threshold = MS(info1, HTT_TX_MODE_SWITCH_IND_INFO1_THRESHOLD); |
| 2125 | |
| 2126 | ath10k_dbg(ar, ATH10K_DBG_HTT, |
| 2127 | "htt rx tx mode switch ind info0 0x%04hx info1 0x%04hx enable %d num records %zd mode %d threshold %hu\n", |
| 2128 | info0, info1, enable, num_records, mode, threshold); |
| 2129 | |
| 2130 | len += sizeof(resp->tx_mode_switch_ind.records[0]) * num_records; |
| 2131 | |
| 2132 | if (unlikely(skb->len < len)) { |
| 2133 | ath10k_warn(ar, "received corrupted tx_mode_switch_mode_ind event: too many records\n"); |
| 2134 | return; |
| 2135 | } |
| 2136 | |
| 2137 | switch (mode) { |
| 2138 | case HTT_TX_MODE_SWITCH_PUSH: |
| 2139 | case HTT_TX_MODE_SWITCH_PUSH_PULL: |
| 2140 | break; |
| 2141 | default: |
| 2142 | ath10k_warn(ar, "received invalid tx_mode_switch_mode_ind mode %d, ignoring\n", |
| 2143 | mode); |
| 2144 | return; |
| 2145 | } |
| 2146 | |
| 2147 | if (!enable) |
| 2148 | return; |
| 2149 | |
Michal Kazior | 426e10e | 2016-03-06 16:14:43 +0200 | [diff] [blame] | 2150 | ar->htt.tx_q_state.enabled = enable; |
| 2151 | ar->htt.tx_q_state.mode = mode; |
| 2152 | ar->htt.tx_q_state.num_push_allowed = threshold; |
| 2153 | |
| 2154 | rcu_read_lock(); |
Michal Kazior | 839ae63 | 2016-03-06 16:14:32 +0200 | [diff] [blame] | 2155 | |
| 2156 | for (i = 0; i < num_records; i++) { |
| 2157 | record = &resp->tx_mode_switch_ind.records[i]; |
| 2158 | info0 = le16_to_cpu(record->info0); |
| 2159 | peer_id = MS(info0, HTT_TX_MODE_SWITCH_RECORD_INFO0_PEER_ID); |
| 2160 | tid = MS(info0, HTT_TX_MODE_SWITCH_RECORD_INFO0_TID); |
| 2161 | |
| 2162 | if (unlikely(peer_id >= ar->htt.tx_q_state.num_peers) || |
| 2163 | unlikely(tid >= ar->htt.tx_q_state.num_tids)) { |
| 2164 | ath10k_warn(ar, "received out of range peer_id %hu tid %hhu\n", |
| 2165 | peer_id, tid); |
| 2166 | continue; |
| 2167 | } |
| 2168 | |
Michal Kazior | 426e10e | 2016-03-06 16:14:43 +0200 | [diff] [blame] | 2169 | spin_lock_bh(&ar->data_lock); |
| 2170 | txq = ath10k_mac_txq_lookup(ar, peer_id, tid); |
| 2171 | spin_unlock_bh(&ar->data_lock); |
| 2172 | |
| 2173 | /* It is okay to release the lock and use txq because RCU read |
| 2174 | * lock is held. |
| 2175 | */ |
| 2176 | |
| 2177 | if (unlikely(!txq)) { |
| 2178 | ath10k_warn(ar, "failed to lookup txq for peer_id %hu tid %hhu\n", |
| 2179 | peer_id, tid); |
| 2180 | continue; |
| 2181 | } |
| 2182 | |
| 2183 | spin_lock_bh(&ar->htt.tx_lock); |
| 2184 | artxq = (void *)txq->drv_priv; |
| 2185 | artxq->num_push_allowed = le16_to_cpu(record->num_max_msdus); |
| 2186 | spin_unlock_bh(&ar->htt.tx_lock); |
Michal Kazior | 839ae63 | 2016-03-06 16:14:32 +0200 | [diff] [blame] | 2187 | } |
| 2188 | |
Michal Kazior | 426e10e | 2016-03-06 16:14:43 +0200 | [diff] [blame] | 2189 | rcu_read_unlock(); |
| 2190 | |
| 2191 | ath10k_mac_tx_push_pending(ar); |
Michal Kazior | 839ae63 | 2016-03-06 16:14:32 +0200 | [diff] [blame] | 2192 | } |
| 2193 | |
Rajkumar Manoharan | 2ce9b25 | 2016-03-08 22:57:23 +0530 | [diff] [blame] | 2194 | static inline enum ieee80211_band phy_mode_to_band(u32 phy_mode) |
| 2195 | { |
| 2196 | enum ieee80211_band band; |
| 2197 | |
| 2198 | switch (phy_mode) { |
| 2199 | case MODE_11A: |
| 2200 | case MODE_11NA_HT20: |
| 2201 | case MODE_11NA_HT40: |
| 2202 | case MODE_11AC_VHT20: |
| 2203 | case MODE_11AC_VHT40: |
| 2204 | case MODE_11AC_VHT80: |
| 2205 | band = IEEE80211_BAND_5GHZ; |
| 2206 | break; |
| 2207 | case MODE_11G: |
| 2208 | case MODE_11B: |
| 2209 | case MODE_11GONLY: |
| 2210 | case MODE_11NG_HT20: |
| 2211 | case MODE_11NG_HT40: |
| 2212 | case MODE_11AC_VHT20_2G: |
| 2213 | case MODE_11AC_VHT40_2G: |
| 2214 | case MODE_11AC_VHT80_2G: |
| 2215 | default: |
| 2216 | band = IEEE80211_BAND_2GHZ; |
| 2217 | } |
| 2218 | |
| 2219 | return band; |
| 2220 | } |
| 2221 | |
Rajkumar Manoharan | e3a91f87 | 2016-03-22 17:22:16 +0530 | [diff] [blame] | 2222 | void ath10k_htt_htc_t2h_msg_handler(struct ath10k *ar, struct sk_buff *skb) |
| 2223 | { |
| 2224 | bool release; |
| 2225 | |
| 2226 | release = ath10k_htt_t2h_msg_handler(ar, skb); |
| 2227 | |
| 2228 | /* Free the indication buffer */ |
| 2229 | if (release) |
| 2230 | dev_kfree_skb_any(skb); |
| 2231 | } |
| 2232 | |
| 2233 | bool ath10k_htt_t2h_msg_handler(struct ath10k *ar, struct sk_buff *skb) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2234 | { |
Michal Kazior | edb8236 | 2013-07-05 16:15:14 +0300 | [diff] [blame] | 2235 | struct ath10k_htt *htt = &ar->htt; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2236 | struct htt_resp *resp = (struct htt_resp *)skb->data; |
Rajkumar Manoharan | 8348db2 | 2015-03-25 13:12:27 +0200 | [diff] [blame] | 2237 | enum htt_t2h_msg_type type; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2238 | |
| 2239 | /* confirm alignment */ |
| 2240 | if (!IS_ALIGNED((unsigned long)skb->data, 4)) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2241 | ath10k_warn(ar, "unaligned htt message, expect trouble\n"); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2242 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2243 | ath10k_dbg(ar, ATH10K_DBG_HTT, "htt rx, msg_type: 0x%0X\n", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2244 | resp->hdr.msg_type); |
Rajkumar Manoharan | 8348db2 | 2015-03-25 13:12:27 +0200 | [diff] [blame] | 2245 | |
| 2246 | if (resp->hdr.msg_type >= ar->htt.t2h_msg_types_max) { |
| 2247 | ath10k_dbg(ar, ATH10K_DBG_HTT, "htt rx, unsupported msg_type: 0x%0X\n max: 0x%0X", |
| 2248 | resp->hdr.msg_type, ar->htt.t2h_msg_types_max); |
Rajkumar Manoharan | e3a91f87 | 2016-03-22 17:22:16 +0530 | [diff] [blame] | 2249 | return true; |
Rajkumar Manoharan | 8348db2 | 2015-03-25 13:12:27 +0200 | [diff] [blame] | 2250 | } |
| 2251 | type = ar->htt.t2h_msg_types[resp->hdr.msg_type]; |
| 2252 | |
| 2253 | switch (type) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2254 | case HTT_T2H_MSG_TYPE_VERSION_CONF: { |
| 2255 | htt->target_version_major = resp->ver_resp.major; |
| 2256 | htt->target_version_minor = resp->ver_resp.minor; |
| 2257 | complete(&htt->target_version_received); |
| 2258 | break; |
| 2259 | } |
Michal Kazior | 6c5151a | 2014-02-27 18:50:04 +0200 | [diff] [blame] | 2260 | case HTT_T2H_MSG_TYPE_RX_IND: |
Rajkumar Manoharan | 3128b3d | 2016-03-22 17:22:15 +0530 | [diff] [blame] | 2261 | ath10k_htt_rx_proc_rx_ind(htt, &resp->rx_ind); |
| 2262 | break; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2263 | case HTT_T2H_MSG_TYPE_PEER_MAP: { |
| 2264 | struct htt_peer_map_event ev = { |
| 2265 | .vdev_id = resp->peer_map.vdev_id, |
| 2266 | .peer_id = __le16_to_cpu(resp->peer_map.peer_id), |
| 2267 | }; |
| 2268 | memcpy(ev.addr, resp->peer_map.addr, sizeof(ev.addr)); |
| 2269 | ath10k_peer_map_event(htt, &ev); |
| 2270 | break; |
| 2271 | } |
| 2272 | case HTT_T2H_MSG_TYPE_PEER_UNMAP: { |
| 2273 | struct htt_peer_unmap_event ev = { |
| 2274 | .peer_id = __le16_to_cpu(resp->peer_unmap.peer_id), |
| 2275 | }; |
| 2276 | ath10k_peer_unmap_event(htt, &ev); |
| 2277 | break; |
| 2278 | } |
| 2279 | case HTT_T2H_MSG_TYPE_MGMT_TX_COMPLETION: { |
| 2280 | struct htt_tx_done tx_done = {}; |
| 2281 | int status = __le32_to_cpu(resp->mgmt_tx_completion.status); |
| 2282 | |
Rajkumar Manoharan | 59465fe | 2016-03-22 17:22:11 +0530 | [diff] [blame] | 2283 | tx_done.msdu_id = __le32_to_cpu(resp->mgmt_tx_completion.desc_id); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2284 | |
| 2285 | switch (status) { |
| 2286 | case HTT_MGMT_TX_STATUS_OK: |
Rajkumar Manoharan | 59465fe | 2016-03-22 17:22:11 +0530 | [diff] [blame] | 2287 | tx_done.status = HTT_TX_COMPL_STATE_ACK; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2288 | break; |
| 2289 | case HTT_MGMT_TX_STATUS_RETRY: |
Rajkumar Manoharan | 59465fe | 2016-03-22 17:22:11 +0530 | [diff] [blame] | 2290 | tx_done.status = HTT_TX_COMPL_STATE_NOACK; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2291 | break; |
| 2292 | case HTT_MGMT_TX_STATUS_DROP: |
Rajkumar Manoharan | 59465fe | 2016-03-22 17:22:11 +0530 | [diff] [blame] | 2293 | tx_done.status = HTT_TX_COMPL_STATE_DISCARD; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2294 | break; |
| 2295 | } |
| 2296 | |
Rajkumar Manoharan | cac0855 | 2016-03-09 20:25:46 +0530 | [diff] [blame] | 2297 | status = ath10k_txrx_tx_unref(htt, &tx_done); |
| 2298 | if (!status) { |
| 2299 | spin_lock_bh(&htt->tx_lock); |
| 2300 | ath10k_htt_tx_mgmt_dec_pending(htt); |
| 2301 | spin_unlock_bh(&htt->tx_lock); |
| 2302 | } |
Michal Kazior | 2994687 | 2016-03-06 16:14:34 +0200 | [diff] [blame] | 2303 | ath10k_mac_tx_push_pending(ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2304 | break; |
| 2305 | } |
Michal Kazior | 6c5151a | 2014-02-27 18:50:04 +0200 | [diff] [blame] | 2306 | case HTT_T2H_MSG_TYPE_TX_COMPL_IND: |
Rajkumar Manoharan | 59465fe | 2016-03-22 17:22:11 +0530 | [diff] [blame] | 2307 | ath10k_htt_rx_tx_compl_ind(htt->ar, skb); |
Michal Kazior | 6c5151a | 2014-02-27 18:50:04 +0200 | [diff] [blame] | 2308 | tasklet_schedule(&htt->txrx_compl_task); |
Rajkumar Manoharan | 59465fe | 2016-03-22 17:22:11 +0530 | [diff] [blame] | 2309 | break; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2310 | case HTT_T2H_MSG_TYPE_SEC_IND: { |
| 2311 | struct ath10k *ar = htt->ar; |
| 2312 | struct htt_security_indication *ev = &resp->security_indication; |
| 2313 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2314 | ath10k_dbg(ar, ATH10K_DBG_HTT, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2315 | "sec ind peer_id %d unicast %d type %d\n", |
| 2316 | __le16_to_cpu(ev->peer_id), |
| 2317 | !!(ev->flags & HTT_SECURITY_IS_UNICAST), |
| 2318 | MS(ev->flags, HTT_SECURITY_TYPE)); |
| 2319 | complete(&ar->install_key_done); |
| 2320 | break; |
| 2321 | } |
| 2322 | case HTT_T2H_MSG_TYPE_RX_FRAG_IND: { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2323 | ath10k_dbg_dump(ar, ATH10K_DBG_HTT_DUMP, NULL, "htt event: ", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2324 | skb->data, skb->len); |
Rajkumar Manoharan | 1823566 | 2016-03-22 17:22:14 +0530 | [diff] [blame] | 2325 | ath10k_htt_rx_frag_handler(htt); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2326 | break; |
| 2327 | } |
| 2328 | case HTT_T2H_MSG_TYPE_TEST: |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2329 | break; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2330 | case HTT_T2H_MSG_TYPE_STATS_CONF: |
Michal Kazior | d35a6c1 | 2014-09-02 11:00:21 +0300 | [diff] [blame] | 2331 | trace_ath10k_htt_stats(ar, skb->data, skb->len); |
Kalle Valo | a9bf050 | 2013-09-03 11:43:55 +0300 | [diff] [blame] | 2332 | break; |
| 2333 | case HTT_T2H_MSG_TYPE_TX_INSPECT_IND: |
Michal Kazior | 708b9bd | 2014-07-21 20:52:59 +0300 | [diff] [blame] | 2334 | /* Firmware can return tx frames if it's unable to fully |
| 2335 | * process them and suspects host may be able to fix it. ath10k |
| 2336 | * sends all tx frames as already inspected so this shouldn't |
| 2337 | * happen unless fw has a bug. |
| 2338 | */ |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2339 | ath10k_warn(ar, "received an unexpected htt tx inspect event\n"); |
Michal Kazior | 708b9bd | 2014-07-21 20:52:59 +0300 | [diff] [blame] | 2340 | break; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2341 | case HTT_T2H_MSG_TYPE_RX_ADDBA: |
Michal Kazior | aa5b4fb | 2014-07-23 12:20:33 +0200 | [diff] [blame] | 2342 | ath10k_htt_rx_addba(ar, resp); |
| 2343 | break; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2344 | case HTT_T2H_MSG_TYPE_RX_DELBA: |
Michal Kazior | aa5b4fb | 2014-07-23 12:20:33 +0200 | [diff] [blame] | 2345 | ath10k_htt_rx_delba(ar, resp); |
| 2346 | break; |
Rajkumar Manoharan | bfdd793 | 2014-10-03 08:02:40 +0300 | [diff] [blame] | 2347 | case HTT_T2H_MSG_TYPE_PKTLOG: { |
| 2348 | struct ath10k_pktlog_hdr *hdr = |
| 2349 | (struct ath10k_pktlog_hdr *)resp->pktlog_msg.payload; |
| 2350 | |
| 2351 | trace_ath10k_htt_pktlog(ar, resp->pktlog_msg.payload, |
| 2352 | sizeof(*hdr) + |
| 2353 | __le16_to_cpu(hdr->size)); |
| 2354 | break; |
| 2355 | } |
Michal Kazior | aa5b4fb | 2014-07-23 12:20:33 +0200 | [diff] [blame] | 2356 | case HTT_T2H_MSG_TYPE_RX_FLUSH: { |
| 2357 | /* Ignore this event because mac80211 takes care of Rx |
| 2358 | * aggregation reordering. |
| 2359 | */ |
| 2360 | break; |
| 2361 | } |
Michal Kazior | c545070 | 2015-01-24 12:14:48 +0200 | [diff] [blame] | 2362 | case HTT_T2H_MSG_TYPE_RX_IN_ORD_PADDR_IND: { |
Rajkumar Manoharan | e7827e5 | 2016-02-12 11:40:58 +0530 | [diff] [blame] | 2363 | skb_queue_tail(&htt->rx_in_ord_compl_q, skb); |
Michal Kazior | c545070 | 2015-01-24 12:14:48 +0200 | [diff] [blame] | 2364 | tasklet_schedule(&htt->txrx_compl_task); |
Rajkumar Manoharan | e3a91f87 | 2016-03-22 17:22:16 +0530 | [diff] [blame] | 2365 | return false; |
Michal Kazior | c545070 | 2015-01-24 12:14:48 +0200 | [diff] [blame] | 2366 | } |
| 2367 | case HTT_T2H_MSG_TYPE_TX_CREDIT_UPDATE_IND: |
Rajkumar Manoharan | 8348db2 | 2015-03-25 13:12:27 +0200 | [diff] [blame] | 2368 | break; |
Rajkumar Manoharan | 2ce9b25 | 2016-03-08 22:57:23 +0530 | [diff] [blame] | 2369 | case HTT_T2H_MSG_TYPE_CHAN_CHANGE: { |
| 2370 | u32 phymode = __le32_to_cpu(resp->chan_change.phymode); |
| 2371 | u32 freq = __le32_to_cpu(resp->chan_change.freq); |
| 2372 | |
| 2373 | ar->tgt_oper_chan = |
| 2374 | __ieee80211_get_channel(ar->hw->wiphy, freq); |
| 2375 | ath10k_dbg(ar, ATH10K_DBG_HTT, |
| 2376 | "htt chan change freq %u phymode %s\n", |
| 2377 | freq, ath10k_wmi_phymode_str(phymode)); |
Michal Kazior | c545070 | 2015-01-24 12:14:48 +0200 | [diff] [blame] | 2378 | break; |
Rajkumar Manoharan | 2ce9b25 | 2016-03-08 22:57:23 +0530 | [diff] [blame] | 2379 | } |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 2380 | case HTT_T2H_MSG_TYPE_AGGR_CONF: |
| 2381 | break; |
Rajkumar Manoharan | b2fdbcc | 2016-03-22 17:22:12 +0530 | [diff] [blame] | 2382 | case HTT_T2H_MSG_TYPE_TX_FETCH_IND: { |
| 2383 | struct sk_buff *tx_fetch_ind = skb_copy(skb, GFP_ATOMIC); |
| 2384 | |
| 2385 | if (!tx_fetch_ind) { |
| 2386 | ath10k_warn(ar, "failed to copy htt tx fetch ind\n"); |
| 2387 | break; |
| 2388 | } |
| 2389 | skb_queue_tail(&htt->tx_fetch_ind_q, tx_fetch_ind); |
Michal Kazior | 426e10e | 2016-03-06 16:14:43 +0200 | [diff] [blame] | 2390 | tasklet_schedule(&htt->txrx_compl_task); |
Rajkumar Manoharan | b2fdbcc | 2016-03-22 17:22:12 +0530 | [diff] [blame] | 2391 | break; |
| 2392 | } |
Michal Kazior | df94e70 | 2016-01-21 14:13:23 +0100 | [diff] [blame] | 2393 | case HTT_T2H_MSG_TYPE_TX_FETCH_CONFIRM: |
Michal Kazior | 839ae63 | 2016-03-06 16:14:32 +0200 | [diff] [blame] | 2394 | ath10k_htt_rx_tx_fetch_confirm(ar, skb); |
| 2395 | break; |
Michal Kazior | df94e70 | 2016-01-21 14:13:23 +0100 | [diff] [blame] | 2396 | case HTT_T2H_MSG_TYPE_TX_MODE_SWITCH_IND: |
Michal Kazior | 839ae63 | 2016-03-06 16:14:32 +0200 | [diff] [blame] | 2397 | ath10k_htt_rx_tx_mode_switch_ind(ar, skb); |
Michal Kazior | 9b15873 | 2016-01-21 14:13:27 +0100 | [diff] [blame] | 2398 | break; |
| 2399 | case HTT_T2H_MSG_TYPE_EN_STATS: |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2400 | default: |
Michal Kazior | 2358a54 | 2014-10-02 13:32:55 +0200 | [diff] [blame] | 2401 | ath10k_warn(ar, "htt event (%d) not handled\n", |
| 2402 | resp->hdr.msg_type); |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2403 | ath10k_dbg_dump(ar, ATH10K_DBG_HTT_DUMP, NULL, "htt event: ", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2404 | skb->data, skb->len); |
| 2405 | break; |
| 2406 | }; |
Rajkumar Manoharan | e3a91f87 | 2016-03-22 17:22:16 +0530 | [diff] [blame] | 2407 | return true; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2408 | } |
Rajkumar Manoharan | 3f0f7ed | 2015-10-12 18:27:03 +0530 | [diff] [blame] | 2409 | EXPORT_SYMBOL(ath10k_htt_t2h_msg_handler); |
Michal Kazior | 6c5151a | 2014-02-27 18:50:04 +0200 | [diff] [blame] | 2410 | |
Vivek Natarajan | afb0bf7 | 2015-10-30 14:57:58 +0530 | [diff] [blame] | 2411 | void ath10k_htt_rx_pktlog_completion_handler(struct ath10k *ar, |
| 2412 | struct sk_buff *skb) |
| 2413 | { |
Ashok Raj Nagarajan | 53a5c9b | 2016-02-05 21:12:48 +0530 | [diff] [blame] | 2414 | trace_ath10k_htt_pktlog(ar, skb->data, skb->len); |
Vivek Natarajan | afb0bf7 | 2015-10-30 14:57:58 +0530 | [diff] [blame] | 2415 | dev_kfree_skb_any(skb); |
| 2416 | } |
| 2417 | EXPORT_SYMBOL(ath10k_htt_rx_pktlog_completion_handler); |
| 2418 | |
Michal Kazior | 6c5151a | 2014-02-27 18:50:04 +0200 | [diff] [blame] | 2419 | static void ath10k_htt_txrx_compl_task(unsigned long ptr) |
| 2420 | { |
| 2421 | struct ath10k_htt *htt = (struct ath10k_htt *)ptr; |
Michal Kazior | c545070 | 2015-01-24 12:14:48 +0200 | [diff] [blame] | 2422 | struct ath10k *ar = htt->ar; |
Rajkumar Manoharan | 59465fe | 2016-03-22 17:22:11 +0530 | [diff] [blame] | 2423 | struct htt_tx_done tx_done = {}; |
Rajkumar Manoharan | da6416c | 2016-02-12 11:40:59 +0530 | [diff] [blame] | 2424 | struct sk_buff_head rx_q; |
| 2425 | struct sk_buff_head rx_ind_q; |
Michal Kazior | 426e10e | 2016-03-06 16:14:43 +0200 | [diff] [blame] | 2426 | struct sk_buff_head tx_ind_q; |
Michal Kazior | 6c5151a | 2014-02-27 18:50:04 +0200 | [diff] [blame] | 2427 | struct sk_buff *skb; |
Michal Kazior | d742c96 | 2016-01-13 14:52:52 +0100 | [diff] [blame] | 2428 | unsigned long flags; |
Rajkumar Manoharan | 3128b3d | 2016-03-22 17:22:15 +0530 | [diff] [blame] | 2429 | int num_mpdus; |
Michal Kazior | 6c5151a | 2014-02-27 18:50:04 +0200 | [diff] [blame] | 2430 | |
Rajkumar Manoharan | da6416c | 2016-02-12 11:40:59 +0530 | [diff] [blame] | 2431 | __skb_queue_head_init(&rx_q); |
| 2432 | __skb_queue_head_init(&rx_ind_q); |
Michal Kazior | 426e10e | 2016-03-06 16:14:43 +0200 | [diff] [blame] | 2433 | __skb_queue_head_init(&tx_ind_q); |
Michal Kazior | d742c96 | 2016-01-13 14:52:52 +0100 | [diff] [blame] | 2434 | |
Rajkumar Manoharan | da6416c | 2016-02-12 11:40:59 +0530 | [diff] [blame] | 2435 | spin_lock_irqsave(&htt->rx_in_ord_compl_q.lock, flags); |
| 2436 | skb_queue_splice_init(&htt->rx_in_ord_compl_q, &rx_ind_q); |
| 2437 | spin_unlock_irqrestore(&htt->rx_in_ord_compl_q.lock, flags); |
| 2438 | |
Michal Kazior | 426e10e | 2016-03-06 16:14:43 +0200 | [diff] [blame] | 2439 | spin_lock_irqsave(&htt->tx_fetch_ind_q.lock, flags); |
| 2440 | skb_queue_splice_init(&htt->tx_fetch_ind_q, &tx_ind_q); |
| 2441 | spin_unlock_irqrestore(&htt->tx_fetch_ind_q.lock, flags); |
| 2442 | |
Rajkumar Manoharan | 59465fe | 2016-03-22 17:22:11 +0530 | [diff] [blame] | 2443 | /* kfifo_get: called only within txrx_tasklet so it's neatly serialized. |
| 2444 | * From kfifo_get() documentation: |
| 2445 | * Note that with only one concurrent reader and one concurrent writer, |
| 2446 | * you don't need extra locking to use these macro. |
| 2447 | */ |
| 2448 | while (kfifo_get(&htt->txdone_fifo, &tx_done)) |
| 2449 | ath10k_txrx_tx_unref(htt, &tx_done); |
Michal Kazior | 6c5151a | 2014-02-27 18:50:04 +0200 | [diff] [blame] | 2450 | |
Michal Kazior | 426e10e | 2016-03-06 16:14:43 +0200 | [diff] [blame] | 2451 | while ((skb = __skb_dequeue(&tx_ind_q))) { |
| 2452 | ath10k_htt_rx_tx_fetch_ind(ar, skb); |
| 2453 | dev_kfree_skb_any(skb); |
| 2454 | } |
| 2455 | |
Michal Kazior | 2994687 | 2016-03-06 16:14:34 +0200 | [diff] [blame] | 2456 | ath10k_mac_tx_push_pending(ar); |
| 2457 | |
Rajkumar Manoharan | 3128b3d | 2016-03-22 17:22:15 +0530 | [diff] [blame] | 2458 | num_mpdus = atomic_read(&htt->num_mpdus_ready); |
| 2459 | atomic_sub(num_mpdus, &htt->num_mpdus_ready); |
| 2460 | |
| 2461 | while (num_mpdus--) { |
| 2462 | if (ath10k_htt_rx_handle_amsdu(htt)) |
| 2463 | break; |
Michal Kazior | 6c5151a | 2014-02-27 18:50:04 +0200 | [diff] [blame] | 2464 | } |
Michal Kazior | c545070 | 2015-01-24 12:14:48 +0200 | [diff] [blame] | 2465 | |
Rajkumar Manoharan | da6416c | 2016-02-12 11:40:59 +0530 | [diff] [blame] | 2466 | while ((skb = __skb_dequeue(&rx_ind_q))) { |
Rajkumar Manoharan | e7827e5 | 2016-02-12 11:40:58 +0530 | [diff] [blame] | 2467 | spin_lock_bh(&htt->rx_ring.lock); |
Michal Kazior | c545070 | 2015-01-24 12:14:48 +0200 | [diff] [blame] | 2468 | ath10k_htt_rx_in_ord_ind(ar, skb); |
Rajkumar Manoharan | e7827e5 | 2016-02-12 11:40:58 +0530 | [diff] [blame] | 2469 | spin_unlock_bh(&htt->rx_ring.lock); |
Michal Kazior | c545070 | 2015-01-24 12:14:48 +0200 | [diff] [blame] | 2470 | dev_kfree_skb_any(skb); |
| 2471 | } |
Rajkumar Manoharan | 3128b3d | 2016-03-22 17:22:15 +0530 | [diff] [blame] | 2472 | |
| 2473 | tasklet_schedule(&htt->rx_replenish_task); |
Michal Kazior | 6c5151a | 2014-02-27 18:50:04 +0200 | [diff] [blame] | 2474 | } |