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