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" |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 24 | |
| 25 | #include <linux/log2.h> |
| 26 | |
| 27 | /* slightly larger than one large A-MPDU */ |
| 28 | #define HTT_RX_RING_SIZE_MIN 128 |
| 29 | |
| 30 | /* roughly 20 ms @ 1 Gbps of 1500B MSDUs */ |
| 31 | #define HTT_RX_RING_SIZE_MAX 2048 |
| 32 | |
| 33 | #define HTT_RX_AVG_FRM_BYTES 1000 |
| 34 | |
| 35 | /* ms, very conservative */ |
| 36 | #define HTT_RX_HOST_LATENCY_MAX_MS 20 |
| 37 | |
| 38 | /* ms, conservative */ |
| 39 | #define HTT_RX_HOST_LATENCY_WORST_LIKELY_MS 10 |
| 40 | |
| 41 | /* when under memory pressure rx ring refill may fail and needs a retry */ |
| 42 | #define HTT_RX_RING_REFILL_RETRY_MS 50 |
| 43 | |
Michal Kazior | f6dc209 | 2013-09-26 10:12:22 +0300 | [diff] [blame] | 44 | |
| 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 | |
| 135 | idx = __le32_to_cpu(*(htt->rx_ring.alloc_idx.vaddr)); |
| 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: |
| 173 | *(htt->rx_ring.alloc_idx.vaddr) = __cpu_to_le32(idx); |
| 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; |
| 225 | ath10k_htt_rx_msdu_buff_replenish(htt); |
| 226 | } |
| 227 | |
| 228 | static unsigned ath10k_htt_rx_ring_elems(struct ath10k_htt *htt) |
| 229 | { |
| 230 | return (__le32_to_cpu(*htt->rx_ring.alloc_idx.vaddr) - |
| 231 | htt->rx_ring.sw_rd_idx.msdu_payld) & htt->rx_ring.size_mask; |
| 232 | } |
| 233 | |
| 234 | void ath10k_htt_rx_detach(struct ath10k_htt *htt) |
| 235 | { |
| 236 | int sw_rd_idx = htt->rx_ring.sw_rd_idx.msdu_payld; |
| 237 | |
| 238 | del_timer_sync(&htt->rx_ring.refill_retry_timer); |
Michal Kazior | 6e712d4 | 2013-09-24 10:18:36 +0200 | [diff] [blame] | 239 | tasklet_kill(&htt->rx_replenish_task); |
Michal Kazior | 6c5151a | 2014-02-27 18:50:04 +0200 | [diff] [blame^] | 240 | tasklet_kill(&htt->txrx_compl_task); |
| 241 | |
| 242 | skb_queue_purge(&htt->tx_compl_q); |
| 243 | skb_queue_purge(&htt->rx_compl_q); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 244 | |
| 245 | while (sw_rd_idx != __le32_to_cpu(*(htt->rx_ring.alloc_idx.vaddr))) { |
| 246 | struct sk_buff *skb = |
| 247 | htt->rx_ring.netbufs_ring[sw_rd_idx]; |
| 248 | struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb); |
| 249 | |
| 250 | dma_unmap_single(htt->ar->dev, cb->paddr, |
| 251 | skb->len + skb_tailroom(skb), |
| 252 | DMA_FROM_DEVICE); |
| 253 | dev_kfree_skb_any(htt->rx_ring.netbufs_ring[sw_rd_idx]); |
| 254 | sw_rd_idx++; |
| 255 | sw_rd_idx &= htt->rx_ring.size_mask; |
| 256 | } |
| 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 | { |
| 274 | int idx; |
| 275 | struct sk_buff *msdu; |
| 276 | |
| 277 | spin_lock_bh(&htt->rx_ring.lock); |
| 278 | |
| 279 | if (ath10k_htt_rx_ring_elems(htt) == 0) |
| 280 | ath10k_warn("htt rx ring is empty!\n"); |
| 281 | |
| 282 | idx = htt->rx_ring.sw_rd_idx.msdu_payld; |
| 283 | msdu = htt->rx_ring.netbufs_ring[idx]; |
| 284 | |
| 285 | idx++; |
| 286 | idx &= htt->rx_ring.size_mask; |
| 287 | htt->rx_ring.sw_rd_idx.msdu_payld = idx; |
| 288 | htt->rx_ring.fill_cnt--; |
| 289 | |
| 290 | spin_unlock_bh(&htt->rx_ring.lock); |
| 291 | return msdu; |
| 292 | } |
| 293 | |
| 294 | static void ath10k_htt_rx_free_msdu_chain(struct sk_buff *skb) |
| 295 | { |
| 296 | struct sk_buff *next; |
| 297 | |
| 298 | while (skb) { |
| 299 | next = skb->next; |
| 300 | dev_kfree_skb_any(skb); |
| 301 | skb = next; |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | static int ath10k_htt_rx_amsdu_pop(struct ath10k_htt *htt, |
| 306 | u8 **fw_desc, int *fw_desc_len, |
| 307 | struct sk_buff **head_msdu, |
| 308 | struct sk_buff **tail_msdu) |
| 309 | { |
| 310 | int msdu_len, msdu_chaining = 0; |
| 311 | struct sk_buff *msdu; |
| 312 | struct htt_rx_desc *rx_desc; |
| 313 | |
| 314 | if (ath10k_htt_rx_ring_elems(htt) == 0) |
| 315 | ath10k_warn("htt rx ring is empty!\n"); |
| 316 | |
| 317 | if (htt->rx_confused) { |
| 318 | ath10k_warn("htt is confused. refusing rx\n"); |
| 319 | return 0; |
| 320 | } |
| 321 | |
| 322 | msdu = *head_msdu = ath10k_htt_rx_netbuf_pop(htt); |
| 323 | while (msdu) { |
| 324 | int last_msdu, msdu_len_invalid, msdu_chained; |
| 325 | |
| 326 | dma_unmap_single(htt->ar->dev, |
| 327 | ATH10K_SKB_CB(msdu)->paddr, |
| 328 | msdu->len + skb_tailroom(msdu), |
| 329 | DMA_FROM_DEVICE); |
| 330 | |
Ben Greear | 75fb2f9 | 2014-02-05 13:58:34 -0800 | [diff] [blame] | 331 | ath10k_dbg_dump(ATH10K_DBG_HTT_DUMP, NULL, "htt rx pop: ", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 332 | msdu->data, msdu->len + skb_tailroom(msdu)); |
| 333 | |
| 334 | rx_desc = (struct htt_rx_desc *)msdu->data; |
| 335 | |
| 336 | /* FIXME: we must report msdu payload since this is what caller |
| 337 | * expects now */ |
| 338 | skb_put(msdu, offsetof(struct htt_rx_desc, msdu_payload)); |
| 339 | skb_pull(msdu, offsetof(struct htt_rx_desc, msdu_payload)); |
| 340 | |
| 341 | /* |
| 342 | * Sanity check - confirm the HW is finished filling in the |
| 343 | * rx data. |
| 344 | * If the HW and SW are working correctly, then it's guaranteed |
| 345 | * that the HW's MAC DMA is done before this point in the SW. |
| 346 | * To prevent the case that we handle a stale Rx descriptor, |
| 347 | * just assert for now until we have a way to recover. |
| 348 | */ |
| 349 | if (!(__le32_to_cpu(rx_desc->attention.flags) |
| 350 | & RX_ATTENTION_FLAGS_MSDU_DONE)) { |
| 351 | ath10k_htt_rx_free_msdu_chain(*head_msdu); |
| 352 | *head_msdu = NULL; |
| 353 | msdu = NULL; |
| 354 | ath10k_err("htt rx stopped. cannot recover\n"); |
| 355 | htt->rx_confused = true; |
| 356 | break; |
| 357 | } |
| 358 | |
| 359 | /* |
| 360 | * Copy the FW rx descriptor for this MSDU from the rx |
| 361 | * indication message into the MSDU's netbuf. HL uses the |
| 362 | * same rx indication message definition as LL, and simply |
| 363 | * appends new info (fields from the HW rx desc, and the |
| 364 | * MSDU payload itself). So, the offset into the rx |
| 365 | * indication message only has to account for the standard |
| 366 | * offset of the per-MSDU FW rx desc info within the |
| 367 | * message, and how many bytes of the per-MSDU FW rx desc |
| 368 | * info have already been consumed. (And the endianness of |
| 369 | * the host, since for a big-endian host, the rx ind |
| 370 | * message contents, including the per-MSDU rx desc bytes, |
| 371 | * were byteswapped during upload.) |
| 372 | */ |
| 373 | if (*fw_desc_len > 0) { |
| 374 | rx_desc->fw_desc.info0 = **fw_desc; |
| 375 | /* |
| 376 | * The target is expected to only provide the basic |
| 377 | * per-MSDU rx descriptors. Just to be sure, verify |
| 378 | * that the target has not attached extension data |
| 379 | * (e.g. LRO flow ID). |
| 380 | */ |
| 381 | |
| 382 | /* or more, if there's extension data */ |
| 383 | (*fw_desc)++; |
| 384 | (*fw_desc_len)--; |
| 385 | } else { |
| 386 | /* |
| 387 | * When an oversized AMSDU happened, FW will lost |
| 388 | * some of MSDU status - in this case, the FW |
| 389 | * descriptors provided will be less than the |
| 390 | * actual MSDUs inside this MPDU. Mark the FW |
| 391 | * descriptors so that it will still deliver to |
| 392 | * upper stack, if no CRC error for this MPDU. |
| 393 | * |
| 394 | * FIX THIS - the FW descriptors are actually for |
| 395 | * MSDUs in the end of this A-MSDU instead of the |
| 396 | * beginning. |
| 397 | */ |
| 398 | rx_desc->fw_desc.info0 = 0; |
| 399 | } |
| 400 | |
| 401 | msdu_len_invalid = !!(__le32_to_cpu(rx_desc->attention.flags) |
| 402 | & (RX_ATTENTION_FLAGS_MPDU_LENGTH_ERR | |
| 403 | RX_ATTENTION_FLAGS_MSDU_LENGTH_ERR)); |
| 404 | msdu_len = MS(__le32_to_cpu(rx_desc->msdu_start.info0), |
| 405 | RX_MSDU_START_INFO0_MSDU_LENGTH); |
| 406 | msdu_chained = rx_desc->frag_info.ring2_more_count; |
| 407 | |
| 408 | if (msdu_len_invalid) |
| 409 | msdu_len = 0; |
| 410 | |
| 411 | skb_trim(msdu, 0); |
| 412 | skb_put(msdu, min(msdu_len, HTT_RX_MSDU_SIZE)); |
| 413 | msdu_len -= msdu->len; |
| 414 | |
| 415 | /* FIXME: Do chained buffers include htt_rx_desc or not? */ |
| 416 | while (msdu_chained--) { |
| 417 | struct sk_buff *next = ath10k_htt_rx_netbuf_pop(htt); |
| 418 | |
| 419 | dma_unmap_single(htt->ar->dev, |
| 420 | ATH10K_SKB_CB(next)->paddr, |
| 421 | next->len + skb_tailroom(next), |
| 422 | DMA_FROM_DEVICE); |
| 423 | |
Ben Greear | 75fb2f9 | 2014-02-05 13:58:34 -0800 | [diff] [blame] | 424 | ath10k_dbg_dump(ATH10K_DBG_HTT_DUMP, NULL, |
| 425 | "htt rx chained: ", next->data, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 426 | next->len + skb_tailroom(next)); |
| 427 | |
| 428 | skb_trim(next, 0); |
| 429 | skb_put(next, min(msdu_len, HTT_RX_BUF_SIZE)); |
| 430 | msdu_len -= next->len; |
| 431 | |
| 432 | msdu->next = next; |
| 433 | msdu = next; |
| 434 | msdu_chaining = 1; |
| 435 | } |
| 436 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 437 | last_msdu = __le32_to_cpu(rx_desc->msdu_end.info0) & |
| 438 | RX_MSDU_END_INFO0_LAST_MSDU; |
| 439 | |
| 440 | if (last_msdu) { |
| 441 | msdu->next = NULL; |
| 442 | break; |
| 443 | } else { |
| 444 | struct sk_buff *next = ath10k_htt_rx_netbuf_pop(htt); |
| 445 | msdu->next = next; |
| 446 | msdu = next; |
| 447 | } |
| 448 | } |
| 449 | *tail_msdu = msdu; |
| 450 | |
| 451 | /* |
| 452 | * Don't refill the ring yet. |
| 453 | * |
| 454 | * First, the elements popped here are still in use - it is not |
| 455 | * safe to overwrite them until the matching call to |
| 456 | * mpdu_desc_list_next. Second, for efficiency it is preferable to |
| 457 | * refill the rx ring with 1 PPDU's worth of rx buffers (something |
| 458 | * like 32 x 3 buffers), rather than one MPDU's worth of rx buffers |
| 459 | * (something like 3 buffers). Consequently, we'll rely on the txrx |
| 460 | * SW to tell us when it is done pulling all the PPDU's rx buffers |
| 461 | * out of the rx ring, and then refill it just once. |
| 462 | */ |
| 463 | |
| 464 | return msdu_chaining; |
| 465 | } |
| 466 | |
Michal Kazior | 6e712d4 | 2013-09-24 10:18:36 +0200 | [diff] [blame] | 467 | static void ath10k_htt_rx_replenish_task(unsigned long ptr) |
| 468 | { |
| 469 | struct ath10k_htt *htt = (struct ath10k_htt *)ptr; |
| 470 | ath10k_htt_rx_msdu_buff_replenish(htt); |
| 471 | } |
| 472 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 473 | int ath10k_htt_rx_attach(struct ath10k_htt *htt) |
| 474 | { |
| 475 | dma_addr_t paddr; |
| 476 | void *vaddr; |
| 477 | struct timer_list *timer = &htt->rx_ring.refill_retry_timer; |
| 478 | |
| 479 | htt->rx_ring.size = ath10k_htt_rx_ring_size(htt); |
| 480 | if (!is_power_of_2(htt->rx_ring.size)) { |
| 481 | ath10k_warn("htt rx ring size is not power of 2\n"); |
| 482 | return -EINVAL; |
| 483 | } |
| 484 | |
| 485 | htt->rx_ring.size_mask = htt->rx_ring.size - 1; |
| 486 | |
| 487 | /* |
| 488 | * Set the initial value for the level to which the rx ring |
| 489 | * should be filled, based on the max throughput and the |
| 490 | * worst likely latency for the host to fill the rx ring |
| 491 | * with new buffers. In theory, this fill level can be |
| 492 | * dynamically adjusted from the initial value set here, to |
| 493 | * reflect the actual host latency rather than a |
| 494 | * conservative assumption about the host latency. |
| 495 | */ |
| 496 | htt->rx_ring.fill_level = ath10k_htt_rx_ring_fill_level(htt); |
| 497 | |
| 498 | htt->rx_ring.netbufs_ring = |
| 499 | kmalloc(htt->rx_ring.size * sizeof(struct sk_buff *), |
| 500 | GFP_KERNEL); |
| 501 | if (!htt->rx_ring.netbufs_ring) |
| 502 | goto err_netbuf; |
| 503 | |
| 504 | vaddr = dma_alloc_coherent(htt->ar->dev, |
| 505 | (htt->rx_ring.size * sizeof(htt->rx_ring.paddrs_ring)), |
| 506 | &paddr, GFP_DMA); |
| 507 | if (!vaddr) |
| 508 | goto err_dma_ring; |
| 509 | |
| 510 | htt->rx_ring.paddrs_ring = vaddr; |
| 511 | htt->rx_ring.base_paddr = paddr; |
| 512 | |
| 513 | vaddr = dma_alloc_coherent(htt->ar->dev, |
| 514 | sizeof(*htt->rx_ring.alloc_idx.vaddr), |
| 515 | &paddr, GFP_DMA); |
| 516 | if (!vaddr) |
| 517 | goto err_dma_idx; |
| 518 | |
| 519 | htt->rx_ring.alloc_idx.vaddr = vaddr; |
| 520 | htt->rx_ring.alloc_idx.paddr = paddr; |
| 521 | htt->rx_ring.sw_rd_idx.msdu_payld = 0; |
| 522 | *htt->rx_ring.alloc_idx.vaddr = 0; |
| 523 | |
| 524 | /* Initialize the Rx refill retry timer */ |
| 525 | setup_timer(timer, ath10k_htt_rx_ring_refill_retry, (unsigned long)htt); |
| 526 | |
| 527 | spin_lock_init(&htt->rx_ring.lock); |
| 528 | |
| 529 | htt->rx_ring.fill_cnt = 0; |
| 530 | if (__ath10k_htt_rx_ring_fill_n(htt, htt->rx_ring.fill_level)) |
| 531 | goto err_fill_ring; |
| 532 | |
Michal Kazior | 6e712d4 | 2013-09-24 10:18:36 +0200 | [diff] [blame] | 533 | tasklet_init(&htt->rx_replenish_task, ath10k_htt_rx_replenish_task, |
| 534 | (unsigned long)htt); |
| 535 | |
Michal Kazior | 6c5151a | 2014-02-27 18:50:04 +0200 | [diff] [blame^] | 536 | skb_queue_head_init(&htt->tx_compl_q); |
| 537 | skb_queue_head_init(&htt->rx_compl_q); |
| 538 | |
| 539 | tasklet_init(&htt->txrx_compl_task, ath10k_htt_txrx_compl_task, |
| 540 | (unsigned long)htt); |
| 541 | |
Kalle Valo | aad0b65 | 2013-09-08 17:56:02 +0300 | [diff] [blame] | 542 | ath10k_dbg(ATH10K_DBG_BOOT, "htt rx ring size %d fill_level %d\n", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 543 | htt->rx_ring.size, htt->rx_ring.fill_level); |
| 544 | return 0; |
| 545 | |
| 546 | err_fill_ring: |
| 547 | ath10k_htt_rx_ring_free(htt); |
| 548 | dma_free_coherent(htt->ar->dev, |
| 549 | sizeof(*htt->rx_ring.alloc_idx.vaddr), |
| 550 | htt->rx_ring.alloc_idx.vaddr, |
| 551 | htt->rx_ring.alloc_idx.paddr); |
| 552 | err_dma_idx: |
| 553 | dma_free_coherent(htt->ar->dev, |
| 554 | (htt->rx_ring.size * |
| 555 | sizeof(htt->rx_ring.paddrs_ring)), |
| 556 | htt->rx_ring.paddrs_ring, |
| 557 | htt->rx_ring.base_paddr); |
| 558 | err_dma_ring: |
| 559 | kfree(htt->rx_ring.netbufs_ring); |
| 560 | err_netbuf: |
| 561 | return -ENOMEM; |
| 562 | } |
| 563 | |
| 564 | static int ath10k_htt_rx_crypto_param_len(enum htt_rx_mpdu_encrypt_type type) |
| 565 | { |
| 566 | switch (type) { |
| 567 | case HTT_RX_MPDU_ENCRYPT_WEP40: |
| 568 | case HTT_RX_MPDU_ENCRYPT_WEP104: |
| 569 | return 4; |
| 570 | case HTT_RX_MPDU_ENCRYPT_TKIP_WITHOUT_MIC: |
| 571 | case HTT_RX_MPDU_ENCRYPT_WEP128: /* not tested */ |
| 572 | case HTT_RX_MPDU_ENCRYPT_TKIP_WPA: |
| 573 | case HTT_RX_MPDU_ENCRYPT_WAPI: /* not tested */ |
| 574 | case HTT_RX_MPDU_ENCRYPT_AES_CCM_WPA2: |
| 575 | return 8; |
| 576 | case HTT_RX_MPDU_ENCRYPT_NONE: |
| 577 | return 0; |
| 578 | } |
| 579 | |
| 580 | ath10k_warn("unknown encryption type %d\n", type); |
| 581 | return 0; |
| 582 | } |
| 583 | |
| 584 | static int ath10k_htt_rx_crypto_tail_len(enum htt_rx_mpdu_encrypt_type type) |
| 585 | { |
| 586 | switch (type) { |
| 587 | case HTT_RX_MPDU_ENCRYPT_NONE: |
| 588 | case HTT_RX_MPDU_ENCRYPT_WEP40: |
| 589 | case HTT_RX_MPDU_ENCRYPT_WEP104: |
| 590 | case HTT_RX_MPDU_ENCRYPT_WEP128: |
| 591 | case HTT_RX_MPDU_ENCRYPT_WAPI: |
| 592 | return 0; |
| 593 | case HTT_RX_MPDU_ENCRYPT_TKIP_WITHOUT_MIC: |
| 594 | case HTT_RX_MPDU_ENCRYPT_TKIP_WPA: |
| 595 | return 4; |
| 596 | case HTT_RX_MPDU_ENCRYPT_AES_CCM_WPA2: |
| 597 | return 8; |
| 598 | } |
| 599 | |
| 600 | ath10k_warn("unknown encryption type %d\n", type); |
| 601 | return 0; |
| 602 | } |
| 603 | |
| 604 | /* Applies for first msdu in chain, before altering it. */ |
| 605 | static struct ieee80211_hdr *ath10k_htt_rx_skb_get_hdr(struct sk_buff *skb) |
| 606 | { |
| 607 | struct htt_rx_desc *rxd; |
| 608 | enum rx_msdu_decap_format fmt; |
| 609 | |
| 610 | rxd = (void *)skb->data - sizeof(*rxd); |
| 611 | fmt = MS(__le32_to_cpu(rxd->msdu_start.info1), |
| 612 | RX_MSDU_START_INFO1_DECAP_FORMAT); |
| 613 | |
| 614 | if (fmt == RX_MSDU_DECAP_RAW) |
| 615 | return (void *)skb->data; |
| 616 | else |
| 617 | return (void *)skb->data - RX_HTT_HDR_STATUS_LEN; |
| 618 | } |
| 619 | |
| 620 | /* This function only applies for first msdu in an msdu chain */ |
| 621 | static bool ath10k_htt_rx_hdr_is_amsdu(struct ieee80211_hdr *hdr) |
| 622 | { |
| 623 | if (ieee80211_is_data_qos(hdr->frame_control)) { |
| 624 | u8 *qc = ieee80211_get_qos_ctl(hdr); |
| 625 | if (qc[0] & 0x80) |
| 626 | return true; |
| 627 | } |
| 628 | return false; |
| 629 | } |
| 630 | |
Michal Kazior | f6dc209 | 2013-09-26 10:12:22 +0300 | [diff] [blame] | 631 | struct rfc1042_hdr { |
| 632 | u8 llc_dsap; |
| 633 | u8 llc_ssap; |
| 634 | u8 llc_ctrl; |
| 635 | u8 snap_oui[3]; |
| 636 | __be16 snap_type; |
| 637 | } __packed; |
| 638 | |
| 639 | struct amsdu_subframe_hdr { |
| 640 | u8 dst[ETH_ALEN]; |
| 641 | u8 src[ETH_ALEN]; |
| 642 | __be16 len; |
| 643 | } __packed; |
| 644 | |
Michal Kazior | d960c36 | 2014-02-25 09:29:57 +0200 | [diff] [blame] | 645 | static int ath10k_htt_rx_nwifi_hdrlen(struct ieee80211_hdr *hdr) |
| 646 | { |
| 647 | /* nwifi header is padded to 4 bytes. this fixes 4addr rx */ |
| 648 | return round_up(ieee80211_hdrlen(hdr->frame_control), 4); |
| 649 | } |
| 650 | |
Michal Kazior | f6dc209 | 2013-09-26 10:12:22 +0300 | [diff] [blame] | 651 | static void ath10k_htt_rx_amsdu(struct ath10k_htt *htt, |
| 652 | struct htt_rx_info *info) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 653 | { |
| 654 | struct htt_rx_desc *rxd; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 655 | struct sk_buff *first; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 656 | struct sk_buff *skb = info->skb; |
| 657 | enum rx_msdu_decap_format fmt; |
| 658 | enum htt_rx_mpdu_encrypt_type enctype; |
Michal Kazior | f6dc209 | 2013-09-26 10:12:22 +0300 | [diff] [blame] | 659 | struct ieee80211_hdr *hdr; |
Michal Kazior | 784f69d | 2013-09-26 10:12:23 +0300 | [diff] [blame] | 660 | u8 hdr_buf[64], addr[ETH_ALEN], *qos; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 661 | unsigned int hdr_len; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 662 | |
| 663 | rxd = (void *)skb->data - sizeof(*rxd); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 664 | enctype = MS(__le32_to_cpu(rxd->mpdu_start.info0), |
| 665 | RX_MPDU_START_INFO0_ENCRYPT_TYPE); |
| 666 | |
Michal Kazior | f6dc209 | 2013-09-26 10:12:22 +0300 | [diff] [blame] | 667 | hdr = (struct ieee80211_hdr *)rxd->rx_hdr_status; |
| 668 | hdr_len = ieee80211_hdrlen(hdr->frame_control); |
| 669 | memcpy(hdr_buf, hdr, hdr_len); |
| 670 | hdr = (struct ieee80211_hdr *)hdr_buf; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 671 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 672 | first = skb; |
| 673 | while (skb) { |
| 674 | void *decap_hdr; |
Michal Kazior | f6dc209 | 2013-09-26 10:12:22 +0300 | [diff] [blame] | 675 | int len; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 676 | |
| 677 | rxd = (void *)skb->data - sizeof(*rxd); |
| 678 | fmt = MS(__le32_to_cpu(rxd->msdu_start.info1), |
Michal Kazior | f6dc209 | 2013-09-26 10:12:22 +0300 | [diff] [blame] | 679 | RX_MSDU_START_INFO1_DECAP_FORMAT); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 680 | decap_hdr = (void *)rxd->rx_hdr_status; |
| 681 | |
Michal Kazior | f6dc209 | 2013-09-26 10:12:22 +0300 | [diff] [blame] | 682 | skb->ip_summed = ath10k_htt_rx_get_csum_state(skb); |
| 683 | |
| 684 | /* First frame in an A-MSDU chain has more decapped data. */ |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 685 | if (skb == first) { |
Michal Kazior | f6dc209 | 2013-09-26 10:12:22 +0300 | [diff] [blame] | 686 | len = round_up(ieee80211_hdrlen(hdr->frame_control), 4); |
| 687 | len += round_up(ath10k_htt_rx_crypto_param_len(enctype), |
| 688 | 4); |
| 689 | decap_hdr += len; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 690 | } |
| 691 | |
Michal Kazior | f6dc209 | 2013-09-26 10:12:22 +0300 | [diff] [blame] | 692 | switch (fmt) { |
| 693 | case RX_MSDU_DECAP_RAW: |
Michal Kazior | e3fbf8d | 2013-09-26 10:12:23 +0300 | [diff] [blame] | 694 | /* remove trailing FCS */ |
Michal Kazior | f6dc209 | 2013-09-26 10:12:22 +0300 | [diff] [blame] | 695 | skb_trim(skb, skb->len - FCS_LEN); |
| 696 | break; |
| 697 | case RX_MSDU_DECAP_NATIVE_WIFI: |
Michal Kazior | 784f69d | 2013-09-26 10:12:23 +0300 | [diff] [blame] | 698 | /* pull decapped header and copy DA */ |
| 699 | hdr = (struct ieee80211_hdr *)skb->data; |
Michal Kazior | d960c36 | 2014-02-25 09:29:57 +0200 | [diff] [blame] | 700 | hdr_len = ath10k_htt_rx_nwifi_hdrlen(hdr); |
Michal Kazior | 784f69d | 2013-09-26 10:12:23 +0300 | [diff] [blame] | 701 | memcpy(addr, ieee80211_get_DA(hdr), ETH_ALEN); |
| 702 | skb_pull(skb, hdr_len); |
| 703 | |
| 704 | /* push original 802.11 header */ |
| 705 | hdr = (struct ieee80211_hdr *)hdr_buf; |
| 706 | hdr_len = ieee80211_hdrlen(hdr->frame_control); |
| 707 | memcpy(skb_push(skb, hdr_len), hdr, hdr_len); |
| 708 | |
| 709 | /* original A-MSDU header has the bit set but we're |
| 710 | * not including A-MSDU subframe header */ |
| 711 | hdr = (struct ieee80211_hdr *)skb->data; |
| 712 | qos = ieee80211_get_qos_ctl(hdr); |
| 713 | qos[0] &= ~IEEE80211_QOS_CTL_A_MSDU_PRESENT; |
| 714 | |
| 715 | /* original 802.11 header has a different DA */ |
| 716 | memcpy(ieee80211_get_DA(hdr), addr, ETH_ALEN); |
Michal Kazior | f6dc209 | 2013-09-26 10:12:22 +0300 | [diff] [blame] | 717 | break; |
| 718 | case RX_MSDU_DECAP_ETHERNET2_DIX: |
Michal Kazior | e3fbf8d | 2013-09-26 10:12:23 +0300 | [diff] [blame] | 719 | /* strip ethernet header and insert decapped 802.11 |
| 720 | * header, amsdu subframe header and rfc1042 header */ |
| 721 | |
Michal Kazior | f6dc209 | 2013-09-26 10:12:22 +0300 | [diff] [blame] | 722 | len = 0; |
| 723 | len += sizeof(struct rfc1042_hdr); |
| 724 | len += sizeof(struct amsdu_subframe_hdr); |
Michal Kazior | dfa95b5 | 2013-08-13 07:59:37 +0200 | [diff] [blame] | 725 | |
Michal Kazior | f6dc209 | 2013-09-26 10:12:22 +0300 | [diff] [blame] | 726 | skb_pull(skb, sizeof(struct ethhdr)); |
| 727 | memcpy(skb_push(skb, len), decap_hdr, len); |
| 728 | memcpy(skb_push(skb, hdr_len), hdr, hdr_len); |
| 729 | break; |
| 730 | case RX_MSDU_DECAP_8023_SNAP_LLC: |
Michal Kazior | e3fbf8d | 2013-09-26 10:12:23 +0300 | [diff] [blame] | 731 | /* insert decapped 802.11 header making a singly |
| 732 | * A-MSDU */ |
Michal Kazior | f6dc209 | 2013-09-26 10:12:22 +0300 | [diff] [blame] | 733 | memcpy(skb_push(skb, hdr_len), hdr, hdr_len); |
| 734 | break; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 735 | } |
| 736 | |
Michal Kazior | f6dc209 | 2013-09-26 10:12:22 +0300 | [diff] [blame] | 737 | info->skb = skb; |
| 738 | info->encrypt_type = enctype; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 739 | skb = skb->next; |
Michal Kazior | f6dc209 | 2013-09-26 10:12:22 +0300 | [diff] [blame] | 740 | info->skb->next = NULL; |
| 741 | |
Kalle Valo | 652de35 | 2013-11-13 15:23:30 +0200 | [diff] [blame] | 742 | if (skb) |
| 743 | info->amsdu_more = true; |
| 744 | |
Michal Kazior | f6dc209 | 2013-09-26 10:12:22 +0300 | [diff] [blame] | 745 | ath10k_process_rx(htt->ar, info); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 746 | } |
| 747 | |
Michal Kazior | f6dc209 | 2013-09-26 10:12:22 +0300 | [diff] [blame] | 748 | /* FIXME: It might be nice to re-assemble the A-MSDU when there's a |
| 749 | * monitor interface active for sniffing purposes. */ |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 750 | } |
| 751 | |
Michal Kazior | f6dc209 | 2013-09-26 10:12:22 +0300 | [diff] [blame] | 752 | static void ath10k_htt_rx_msdu(struct ath10k_htt *htt, struct htt_rx_info *info) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 753 | { |
| 754 | struct sk_buff *skb = info->skb; |
| 755 | struct htt_rx_desc *rxd; |
| 756 | struct ieee80211_hdr *hdr; |
| 757 | enum rx_msdu_decap_format fmt; |
| 758 | enum htt_rx_mpdu_encrypt_type enctype; |
Michal Kazior | e3fbf8d | 2013-09-26 10:12:23 +0300 | [diff] [blame] | 759 | int hdr_len; |
| 760 | void *rfc1042; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 761 | |
| 762 | /* This shouldn't happen. If it does than it may be a FW bug. */ |
| 763 | if (skb->next) { |
Ben Greear | 75fb2f9 | 2014-02-05 13:58:34 -0800 | [diff] [blame] | 764 | ath10k_warn("htt rx received chained non A-MSDU frame\n"); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 765 | ath10k_htt_rx_free_msdu_chain(skb->next); |
| 766 | skb->next = NULL; |
| 767 | } |
| 768 | |
| 769 | rxd = (void *)skb->data - sizeof(*rxd); |
| 770 | fmt = MS(__le32_to_cpu(rxd->msdu_start.info1), |
| 771 | RX_MSDU_START_INFO1_DECAP_FORMAT); |
| 772 | enctype = MS(__le32_to_cpu(rxd->mpdu_start.info0), |
| 773 | RX_MPDU_START_INFO0_ENCRYPT_TYPE); |
Michal Kazior | e3fbf8d | 2013-09-26 10:12:23 +0300 | [diff] [blame] | 774 | hdr = (struct ieee80211_hdr *)rxd->rx_hdr_status; |
| 775 | hdr_len = ieee80211_hdrlen(hdr->frame_control); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 776 | |
Michal Kazior | f6dc209 | 2013-09-26 10:12:22 +0300 | [diff] [blame] | 777 | skb->ip_summed = ath10k_htt_rx_get_csum_state(skb); |
| 778 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 779 | switch (fmt) { |
| 780 | case RX_MSDU_DECAP_RAW: |
| 781 | /* remove trailing FCS */ |
Michal Kazior | e3fbf8d | 2013-09-26 10:12:23 +0300 | [diff] [blame] | 782 | skb_trim(skb, skb->len - FCS_LEN); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 783 | break; |
| 784 | case RX_MSDU_DECAP_NATIVE_WIFI: |
Michal Kazior | 784f69d | 2013-09-26 10:12:23 +0300 | [diff] [blame] | 785 | /* Pull decapped header */ |
| 786 | hdr = (struct ieee80211_hdr *)skb->data; |
Michal Kazior | d960c36 | 2014-02-25 09:29:57 +0200 | [diff] [blame] | 787 | hdr_len = ath10k_htt_rx_nwifi_hdrlen(hdr); |
Michal Kazior | 784f69d | 2013-09-26 10:12:23 +0300 | [diff] [blame] | 788 | skb_pull(skb, hdr_len); |
| 789 | |
| 790 | /* Push original header */ |
| 791 | hdr = (struct ieee80211_hdr *)rxd->rx_hdr_status; |
| 792 | hdr_len = ieee80211_hdrlen(hdr->frame_control); |
| 793 | memcpy(skb_push(skb, hdr_len), hdr, hdr_len); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 794 | break; |
| 795 | case RX_MSDU_DECAP_ETHERNET2_DIX: |
Michal Kazior | e3fbf8d | 2013-09-26 10:12:23 +0300 | [diff] [blame] | 796 | /* strip ethernet header and insert decapped 802.11 header and |
| 797 | * rfc1042 header */ |
| 798 | |
| 799 | rfc1042 = hdr; |
| 800 | rfc1042 += roundup(hdr_len, 4); |
| 801 | rfc1042 += roundup(ath10k_htt_rx_crypto_param_len(enctype), 4); |
| 802 | |
| 803 | skb_pull(skb, sizeof(struct ethhdr)); |
| 804 | memcpy(skb_push(skb, sizeof(struct rfc1042_hdr)), |
| 805 | rfc1042, sizeof(struct rfc1042_hdr)); |
| 806 | memcpy(skb_push(skb, hdr_len), hdr, hdr_len); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 807 | break; |
| 808 | case RX_MSDU_DECAP_8023_SNAP_LLC: |
Michal Kazior | e3fbf8d | 2013-09-26 10:12:23 +0300 | [diff] [blame] | 809 | /* remove A-MSDU subframe header and insert |
| 810 | * decapped 802.11 header. rfc1042 header is already there */ |
| 811 | |
| 812 | skb_pull(skb, sizeof(struct amsdu_subframe_hdr)); |
| 813 | memcpy(skb_push(skb, hdr_len), hdr, hdr_len); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 814 | break; |
| 815 | } |
| 816 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 817 | info->skb = skb; |
| 818 | info->encrypt_type = enctype; |
Michal Kazior | f6dc209 | 2013-09-26 10:12:22 +0300 | [diff] [blame] | 819 | |
| 820 | ath10k_process_rx(htt->ar, info); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 821 | } |
| 822 | |
| 823 | static bool ath10k_htt_rx_has_decrypt_err(struct sk_buff *skb) |
| 824 | { |
| 825 | struct htt_rx_desc *rxd; |
| 826 | u32 flags; |
| 827 | |
| 828 | rxd = (void *)skb->data - sizeof(*rxd); |
| 829 | flags = __le32_to_cpu(rxd->attention.flags); |
| 830 | |
| 831 | if (flags & RX_ATTENTION_FLAGS_DECRYPT_ERR) |
| 832 | return true; |
| 833 | |
| 834 | return false; |
| 835 | } |
| 836 | |
| 837 | static bool ath10k_htt_rx_has_fcs_err(struct sk_buff *skb) |
| 838 | { |
| 839 | struct htt_rx_desc *rxd; |
| 840 | u32 flags; |
| 841 | |
| 842 | rxd = (void *)skb->data - sizeof(*rxd); |
| 843 | flags = __le32_to_cpu(rxd->attention.flags); |
| 844 | |
| 845 | if (flags & RX_ATTENTION_FLAGS_FCS_ERR) |
| 846 | return true; |
| 847 | |
| 848 | return false; |
| 849 | } |
| 850 | |
Janusz Dziedzic | 2256940 | 2013-12-13 13:44:16 +0100 | [diff] [blame] | 851 | static bool ath10k_htt_rx_has_mic_err(struct sk_buff *skb) |
| 852 | { |
| 853 | struct htt_rx_desc *rxd; |
| 854 | u32 flags; |
| 855 | |
| 856 | rxd = (void *)skb->data - sizeof(*rxd); |
| 857 | flags = __le32_to_cpu(rxd->attention.flags); |
| 858 | |
| 859 | if (flags & RX_ATTENTION_FLAGS_TKIP_MIC_ERR) |
| 860 | return true; |
| 861 | |
| 862 | return false; |
| 863 | } |
| 864 | |
Janusz Dziedzic | a80ddb0 | 2014-02-25 07:56:39 +0100 | [diff] [blame] | 865 | static bool ath10k_htt_rx_is_mgmt(struct sk_buff *skb) |
| 866 | { |
| 867 | struct htt_rx_desc *rxd; |
| 868 | u32 flags; |
| 869 | |
| 870 | rxd = (void *)skb->data - sizeof(*rxd); |
| 871 | flags = __le32_to_cpu(rxd->attention.flags); |
| 872 | |
| 873 | if (flags & RX_ATTENTION_FLAGS_MGMT_TYPE) |
| 874 | return true; |
| 875 | |
| 876 | return false; |
| 877 | } |
| 878 | |
Michal Kazior | 605f81a | 2013-07-31 10:47:56 +0200 | [diff] [blame] | 879 | static int ath10k_htt_rx_get_csum_state(struct sk_buff *skb) |
| 880 | { |
| 881 | struct htt_rx_desc *rxd; |
| 882 | u32 flags, info; |
| 883 | bool is_ip4, is_ip6; |
| 884 | bool is_tcp, is_udp; |
| 885 | bool ip_csum_ok, tcpudp_csum_ok; |
| 886 | |
| 887 | rxd = (void *)skb->data - sizeof(*rxd); |
| 888 | flags = __le32_to_cpu(rxd->attention.flags); |
| 889 | info = __le32_to_cpu(rxd->msdu_start.info1); |
| 890 | |
| 891 | is_ip4 = !!(info & RX_MSDU_START_INFO1_IPV4_PROTO); |
| 892 | is_ip6 = !!(info & RX_MSDU_START_INFO1_IPV6_PROTO); |
| 893 | is_tcp = !!(info & RX_MSDU_START_INFO1_TCP_PROTO); |
| 894 | is_udp = !!(info & RX_MSDU_START_INFO1_UDP_PROTO); |
| 895 | ip_csum_ok = !(flags & RX_ATTENTION_FLAGS_IP_CHKSUM_FAIL); |
| 896 | tcpudp_csum_ok = !(flags & RX_ATTENTION_FLAGS_TCP_UDP_CHKSUM_FAIL); |
| 897 | |
| 898 | if (!is_ip4 && !is_ip6) |
| 899 | return CHECKSUM_NONE; |
| 900 | if (!is_tcp && !is_udp) |
| 901 | return CHECKSUM_NONE; |
| 902 | if (!ip_csum_ok) |
| 903 | return CHECKSUM_NONE; |
| 904 | if (!tcpudp_csum_ok) |
| 905 | return CHECKSUM_NONE; |
| 906 | |
| 907 | return CHECKSUM_UNNECESSARY; |
| 908 | } |
| 909 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 910 | static void ath10k_htt_rx_handler(struct ath10k_htt *htt, |
| 911 | struct htt_rx_indication *rx) |
| 912 | { |
| 913 | struct htt_rx_info info; |
| 914 | struct htt_rx_indication_mpdu_range *mpdu_ranges; |
| 915 | struct ieee80211_hdr *hdr; |
| 916 | int num_mpdu_ranges; |
| 917 | int fw_desc_len; |
| 918 | u8 *fw_desc; |
| 919 | int i, j; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 920 | |
| 921 | memset(&info, 0, sizeof(info)); |
| 922 | |
| 923 | fw_desc_len = __le16_to_cpu(rx->prefix.fw_rx_desc_bytes); |
| 924 | fw_desc = (u8 *)&rx->fw_desc; |
| 925 | |
| 926 | num_mpdu_ranges = MS(__le32_to_cpu(rx->hdr.info1), |
| 927 | HTT_RX_INDICATION_INFO1_NUM_MPDU_RANGES); |
| 928 | mpdu_ranges = htt_rx_ind_get_mpdu_ranges(rx); |
| 929 | |
| 930 | ath10k_dbg_dump(ATH10K_DBG_HTT_DUMP, NULL, "htt rx ind: ", |
| 931 | rx, sizeof(*rx) + |
| 932 | (sizeof(struct htt_rx_indication_mpdu_range) * |
| 933 | num_mpdu_ranges)); |
| 934 | |
| 935 | for (i = 0; i < num_mpdu_ranges; i++) { |
| 936 | info.status = mpdu_ranges[i].mpdu_range_status; |
| 937 | |
| 938 | for (j = 0; j < mpdu_ranges[i].mpdu_count; j++) { |
| 939 | struct sk_buff *msdu_head, *msdu_tail; |
| 940 | enum htt_rx_mpdu_status status; |
| 941 | int msdu_chaining; |
| 942 | |
| 943 | msdu_head = NULL; |
| 944 | msdu_tail = NULL; |
| 945 | msdu_chaining = ath10k_htt_rx_amsdu_pop(htt, |
| 946 | &fw_desc, |
| 947 | &fw_desc_len, |
| 948 | &msdu_head, |
| 949 | &msdu_tail); |
| 950 | |
| 951 | if (!msdu_head) { |
| 952 | ath10k_warn("htt rx no data!\n"); |
| 953 | continue; |
| 954 | } |
| 955 | |
| 956 | if (msdu_head->len == 0) { |
| 957 | ath10k_dbg(ATH10K_DBG_HTT, |
| 958 | "htt rx dropping due to zero-len\n"); |
| 959 | ath10k_htt_rx_free_msdu_chain(msdu_head); |
| 960 | continue; |
| 961 | } |
| 962 | |
| 963 | if (ath10k_htt_rx_has_decrypt_err(msdu_head)) { |
Ben Greear | c6b56b0 | 2014-02-05 13:58:33 -0800 | [diff] [blame] | 964 | ath10k_dbg(ATH10K_DBG_HTT, |
| 965 | "htt rx dropping due to decrypt-err\n"); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 966 | ath10k_htt_rx_free_msdu_chain(msdu_head); |
| 967 | continue; |
| 968 | } |
| 969 | |
| 970 | status = info.status; |
| 971 | |
| 972 | /* Skip mgmt frames while we handle this in WMI */ |
Janusz Dziedzic | a80ddb0 | 2014-02-25 07:56:39 +0100 | [diff] [blame] | 973 | if (status == HTT_RX_IND_MPDU_STATUS_MGMT_CTRL || |
| 974 | ath10k_htt_rx_is_mgmt(msdu_head)) { |
Ben Greear | 75fb2f9 | 2014-02-05 13:58:34 -0800 | [diff] [blame] | 975 | ath10k_dbg(ATH10K_DBG_HTT, "htt rx mgmt ctrl\n"); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 976 | ath10k_htt_rx_free_msdu_chain(msdu_head); |
| 977 | continue; |
| 978 | } |
| 979 | |
| 980 | if (status != HTT_RX_IND_MPDU_STATUS_OK && |
| 981 | status != HTT_RX_IND_MPDU_STATUS_TKIP_MIC_ERR && |
Janusz Dziedzic | 716ae53 | 2014-02-13 17:50:00 +0200 | [diff] [blame] | 982 | status != HTT_RX_IND_MPDU_STATUS_ERR_INV_PEER && |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 983 | !htt->ar->monitor_enabled) { |
| 984 | ath10k_dbg(ATH10K_DBG_HTT, |
| 985 | "htt rx ignoring frame w/ status %d\n", |
| 986 | status); |
| 987 | ath10k_htt_rx_free_msdu_chain(msdu_head); |
| 988 | continue; |
| 989 | } |
| 990 | |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 991 | if (test_bit(ATH10K_CAC_RUNNING, &htt->ar->dev_flags)) { |
Ben Greear | 75fb2f9 | 2014-02-05 13:58:34 -0800 | [diff] [blame] | 992 | ath10k_dbg(ATH10K_DBG_HTT, |
| 993 | "htt rx CAC running\n"); |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 994 | ath10k_htt_rx_free_msdu_chain(msdu_head); |
| 995 | continue; |
| 996 | } |
| 997 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 998 | /* FIXME: we do not support chaining yet. |
| 999 | * this needs investigation */ |
| 1000 | if (msdu_chaining) { |
Ben Greear | 75fb2f9 | 2014-02-05 13:58:34 -0800 | [diff] [blame] | 1001 | ath10k_warn("htt rx msdu_chaining is true\n"); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1002 | ath10k_htt_rx_free_msdu_chain(msdu_head); |
| 1003 | continue; |
| 1004 | } |
| 1005 | |
| 1006 | info.skb = msdu_head; |
| 1007 | info.fcs_err = ath10k_htt_rx_has_fcs_err(msdu_head); |
Janusz Dziedzic | 2256940 | 2013-12-13 13:44:16 +0100 | [diff] [blame] | 1008 | info.mic_err = ath10k_htt_rx_has_mic_err(msdu_head); |
Ben Greear | c6b56b0 | 2014-02-05 13:58:33 -0800 | [diff] [blame] | 1009 | |
| 1010 | if (info.fcs_err) |
| 1011 | ath10k_dbg(ATH10K_DBG_HTT, |
| 1012 | "htt rx has FCS err\n"); |
| 1013 | |
| 1014 | if (info.mic_err) |
| 1015 | ath10k_dbg(ATH10K_DBG_HTT, |
| 1016 | "htt rx has MIC err\n"); |
| 1017 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1018 | info.signal = ATH10K_DEFAULT_NOISE_FLOOR; |
| 1019 | info.signal += rx->ppdu.combined_rssi; |
| 1020 | |
| 1021 | info.rate.info0 = rx->ppdu.info0; |
| 1022 | info.rate.info1 = __le32_to_cpu(rx->ppdu.info1); |
| 1023 | info.rate.info2 = __le32_to_cpu(rx->ppdu.info2); |
Chun-Yeow Yeoh | e72698f | 2014-02-26 18:42:05 +0200 | [diff] [blame] | 1024 | info.tsf = __le32_to_cpu(rx->ppdu.tsf); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1025 | |
| 1026 | hdr = ath10k_htt_rx_skb_get_hdr(msdu_head); |
| 1027 | |
| 1028 | if (ath10k_htt_rx_hdr_is_amsdu(hdr)) |
Michal Kazior | f6dc209 | 2013-09-26 10:12:22 +0300 | [diff] [blame] | 1029 | ath10k_htt_rx_amsdu(htt, &info); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1030 | else |
Michal Kazior | f6dc209 | 2013-09-26 10:12:22 +0300 | [diff] [blame] | 1031 | ath10k_htt_rx_msdu(htt, &info); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1032 | } |
| 1033 | } |
| 1034 | |
Michal Kazior | 6e712d4 | 2013-09-24 10:18:36 +0200 | [diff] [blame] | 1035 | tasklet_schedule(&htt->rx_replenish_task); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1036 | } |
| 1037 | |
| 1038 | static void ath10k_htt_rx_frag_handler(struct ath10k_htt *htt, |
| 1039 | struct htt_rx_fragment_indication *frag) |
| 1040 | { |
| 1041 | struct sk_buff *msdu_head, *msdu_tail; |
| 1042 | struct htt_rx_desc *rxd; |
| 1043 | enum rx_msdu_decap_format fmt; |
| 1044 | struct htt_rx_info info = {}; |
| 1045 | struct ieee80211_hdr *hdr; |
| 1046 | int msdu_chaining; |
| 1047 | bool tkip_mic_err; |
| 1048 | bool decrypt_err; |
| 1049 | u8 *fw_desc; |
| 1050 | int fw_desc_len, hdrlen, paramlen; |
| 1051 | int trim; |
| 1052 | |
| 1053 | fw_desc_len = __le16_to_cpu(frag->fw_rx_desc_bytes); |
| 1054 | fw_desc = (u8 *)frag->fw_msdu_rx_desc; |
| 1055 | |
| 1056 | msdu_head = NULL; |
| 1057 | msdu_tail = NULL; |
| 1058 | msdu_chaining = ath10k_htt_rx_amsdu_pop(htt, &fw_desc, &fw_desc_len, |
| 1059 | &msdu_head, &msdu_tail); |
| 1060 | |
| 1061 | ath10k_dbg(ATH10K_DBG_HTT_DUMP, "htt rx frag ahead\n"); |
| 1062 | |
| 1063 | if (!msdu_head) { |
| 1064 | ath10k_warn("htt rx frag no data\n"); |
| 1065 | return; |
| 1066 | } |
| 1067 | |
| 1068 | if (msdu_chaining || msdu_head != msdu_tail) { |
| 1069 | ath10k_warn("aggregation with fragmentation?!\n"); |
| 1070 | ath10k_htt_rx_free_msdu_chain(msdu_head); |
| 1071 | return; |
| 1072 | } |
| 1073 | |
| 1074 | /* FIXME: implement signal strength */ |
| 1075 | |
| 1076 | hdr = (struct ieee80211_hdr *)msdu_head->data; |
| 1077 | rxd = (void *)msdu_head->data - sizeof(*rxd); |
| 1078 | tkip_mic_err = !!(__le32_to_cpu(rxd->attention.flags) & |
| 1079 | RX_ATTENTION_FLAGS_TKIP_MIC_ERR); |
| 1080 | decrypt_err = !!(__le32_to_cpu(rxd->attention.flags) & |
| 1081 | RX_ATTENTION_FLAGS_DECRYPT_ERR); |
| 1082 | fmt = MS(__le32_to_cpu(rxd->msdu_start.info1), |
| 1083 | RX_MSDU_START_INFO1_DECAP_FORMAT); |
| 1084 | |
| 1085 | if (fmt != RX_MSDU_DECAP_RAW) { |
| 1086 | ath10k_warn("we dont support non-raw fragmented rx yet\n"); |
| 1087 | dev_kfree_skb_any(msdu_head); |
| 1088 | goto end; |
| 1089 | } |
| 1090 | |
| 1091 | info.skb = msdu_head; |
| 1092 | info.status = HTT_RX_IND_MPDU_STATUS_OK; |
| 1093 | info.encrypt_type = MS(__le32_to_cpu(rxd->mpdu_start.info0), |
| 1094 | RX_MPDU_START_INFO0_ENCRYPT_TYPE); |
Michal Kazior | 605f81a | 2013-07-31 10:47:56 +0200 | [diff] [blame] | 1095 | info.skb->ip_summed = ath10k_htt_rx_get_csum_state(info.skb); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1096 | |
| 1097 | if (tkip_mic_err) { |
| 1098 | ath10k_warn("tkip mic error\n"); |
| 1099 | info.status = HTT_RX_IND_MPDU_STATUS_TKIP_MIC_ERR; |
| 1100 | } |
| 1101 | |
| 1102 | if (decrypt_err) { |
| 1103 | ath10k_warn("decryption err in fragmented rx\n"); |
| 1104 | dev_kfree_skb_any(info.skb); |
| 1105 | goto end; |
| 1106 | } |
| 1107 | |
| 1108 | if (info.encrypt_type != HTT_RX_MPDU_ENCRYPT_NONE) { |
| 1109 | hdrlen = ieee80211_hdrlen(hdr->frame_control); |
| 1110 | paramlen = ath10k_htt_rx_crypto_param_len(info.encrypt_type); |
| 1111 | |
| 1112 | /* It is more efficient to move the header than the payload */ |
| 1113 | memmove((void *)info.skb->data + paramlen, |
| 1114 | (void *)info.skb->data, |
| 1115 | hdrlen); |
| 1116 | skb_pull(info.skb, paramlen); |
| 1117 | hdr = (struct ieee80211_hdr *)info.skb->data; |
| 1118 | } |
| 1119 | |
| 1120 | /* remove trailing FCS */ |
| 1121 | trim = 4; |
| 1122 | |
| 1123 | /* remove crypto trailer */ |
| 1124 | trim += ath10k_htt_rx_crypto_tail_len(info.encrypt_type); |
| 1125 | |
| 1126 | /* last fragment of TKIP frags has MIC */ |
| 1127 | if (!ieee80211_has_morefrags(hdr->frame_control) && |
| 1128 | info.encrypt_type == HTT_RX_MPDU_ENCRYPT_TKIP_WPA) |
| 1129 | trim += 8; |
| 1130 | |
| 1131 | if (trim > info.skb->len) { |
| 1132 | ath10k_warn("htt rx fragment: trailer longer than the frame itself? drop\n"); |
| 1133 | dev_kfree_skb_any(info.skb); |
| 1134 | goto end; |
| 1135 | } |
| 1136 | |
| 1137 | skb_trim(info.skb, info.skb->len - trim); |
| 1138 | |
Ben Greear | 75fb2f9 | 2014-02-05 13:58:34 -0800 | [diff] [blame] | 1139 | ath10k_dbg_dump(ATH10K_DBG_HTT_DUMP, NULL, "htt rx frag mpdu: ", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1140 | info.skb->data, info.skb->len); |
| 1141 | ath10k_process_rx(htt->ar, &info); |
| 1142 | |
| 1143 | end: |
| 1144 | if (fw_desc_len > 0) { |
| 1145 | ath10k_dbg(ATH10K_DBG_HTT, |
| 1146 | "expecting more fragmented rx in one indication %d\n", |
| 1147 | fw_desc_len); |
| 1148 | } |
| 1149 | } |
| 1150 | |
Michal Kazior | 6c5151a | 2014-02-27 18:50:04 +0200 | [diff] [blame^] | 1151 | static void ath10k_htt_rx_frm_tx_compl(struct ath10k *ar, |
| 1152 | struct sk_buff *skb) |
| 1153 | { |
| 1154 | struct ath10k_htt *htt = &ar->htt; |
| 1155 | struct htt_resp *resp = (struct htt_resp *)skb->data; |
| 1156 | struct htt_tx_done tx_done = {}; |
| 1157 | int status = MS(resp->data_tx_completion.flags, HTT_DATA_TX_STATUS); |
| 1158 | __le16 msdu_id; |
| 1159 | int i; |
| 1160 | |
| 1161 | switch (status) { |
| 1162 | case HTT_DATA_TX_STATUS_NO_ACK: |
| 1163 | tx_done.no_ack = true; |
| 1164 | break; |
| 1165 | case HTT_DATA_TX_STATUS_OK: |
| 1166 | break; |
| 1167 | case HTT_DATA_TX_STATUS_DISCARD: |
| 1168 | case HTT_DATA_TX_STATUS_POSTPONE: |
| 1169 | case HTT_DATA_TX_STATUS_DOWNLOAD_FAIL: |
| 1170 | tx_done.discard = true; |
| 1171 | break; |
| 1172 | default: |
| 1173 | ath10k_warn("unhandled tx completion status %d\n", status); |
| 1174 | tx_done.discard = true; |
| 1175 | break; |
| 1176 | } |
| 1177 | |
| 1178 | ath10k_dbg(ATH10K_DBG_HTT, "htt tx completion num_msdus %d\n", |
| 1179 | resp->data_tx_completion.num_msdus); |
| 1180 | |
| 1181 | for (i = 0; i < resp->data_tx_completion.num_msdus; i++) { |
| 1182 | msdu_id = resp->data_tx_completion.msdus[i]; |
| 1183 | tx_done.msdu_id = __le16_to_cpu(msdu_id); |
| 1184 | ath10k_txrx_tx_unref(htt, &tx_done); |
| 1185 | } |
| 1186 | } |
| 1187 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1188 | void ath10k_htt_t2h_msg_handler(struct ath10k *ar, struct sk_buff *skb) |
| 1189 | { |
Michal Kazior | edb8236 | 2013-07-05 16:15:14 +0300 | [diff] [blame] | 1190 | struct ath10k_htt *htt = &ar->htt; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1191 | struct htt_resp *resp = (struct htt_resp *)skb->data; |
| 1192 | |
| 1193 | /* confirm alignment */ |
| 1194 | if (!IS_ALIGNED((unsigned long)skb->data, 4)) |
| 1195 | ath10k_warn("unaligned htt message, expect trouble\n"); |
| 1196 | |
Ben Greear | 75fb2f9 | 2014-02-05 13:58:34 -0800 | [diff] [blame] | 1197 | ath10k_dbg(ATH10K_DBG_HTT, "htt rx, msg_type: 0x%0X\n", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1198 | resp->hdr.msg_type); |
| 1199 | switch (resp->hdr.msg_type) { |
| 1200 | case HTT_T2H_MSG_TYPE_VERSION_CONF: { |
| 1201 | htt->target_version_major = resp->ver_resp.major; |
| 1202 | htt->target_version_minor = resp->ver_resp.minor; |
| 1203 | complete(&htt->target_version_received); |
| 1204 | break; |
| 1205 | } |
Michal Kazior | 6c5151a | 2014-02-27 18:50:04 +0200 | [diff] [blame^] | 1206 | case HTT_T2H_MSG_TYPE_RX_IND: |
| 1207 | skb_queue_tail(&htt->rx_compl_q, skb); |
| 1208 | tasklet_schedule(&htt->txrx_compl_task); |
| 1209 | return; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1210 | case HTT_T2H_MSG_TYPE_PEER_MAP: { |
| 1211 | struct htt_peer_map_event ev = { |
| 1212 | .vdev_id = resp->peer_map.vdev_id, |
| 1213 | .peer_id = __le16_to_cpu(resp->peer_map.peer_id), |
| 1214 | }; |
| 1215 | memcpy(ev.addr, resp->peer_map.addr, sizeof(ev.addr)); |
| 1216 | ath10k_peer_map_event(htt, &ev); |
| 1217 | break; |
| 1218 | } |
| 1219 | case HTT_T2H_MSG_TYPE_PEER_UNMAP: { |
| 1220 | struct htt_peer_unmap_event ev = { |
| 1221 | .peer_id = __le16_to_cpu(resp->peer_unmap.peer_id), |
| 1222 | }; |
| 1223 | ath10k_peer_unmap_event(htt, &ev); |
| 1224 | break; |
| 1225 | } |
| 1226 | case HTT_T2H_MSG_TYPE_MGMT_TX_COMPLETION: { |
| 1227 | struct htt_tx_done tx_done = {}; |
| 1228 | int status = __le32_to_cpu(resp->mgmt_tx_completion.status); |
| 1229 | |
| 1230 | tx_done.msdu_id = |
| 1231 | __le32_to_cpu(resp->mgmt_tx_completion.desc_id); |
| 1232 | |
| 1233 | switch (status) { |
| 1234 | case HTT_MGMT_TX_STATUS_OK: |
| 1235 | break; |
| 1236 | case HTT_MGMT_TX_STATUS_RETRY: |
| 1237 | tx_done.no_ack = true; |
| 1238 | break; |
| 1239 | case HTT_MGMT_TX_STATUS_DROP: |
| 1240 | tx_done.discard = true; |
| 1241 | break; |
| 1242 | } |
| 1243 | |
Michal Kazior | 6c5151a | 2014-02-27 18:50:04 +0200 | [diff] [blame^] | 1244 | spin_lock_bh(&htt->tx_lock); |
Michal Kazior | 0a89f8a | 2013-09-18 14:43:20 +0200 | [diff] [blame] | 1245 | ath10k_txrx_tx_unref(htt, &tx_done); |
Michal Kazior | 6c5151a | 2014-02-27 18:50:04 +0200 | [diff] [blame^] | 1246 | spin_unlock_bh(&htt->tx_lock); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1247 | break; |
| 1248 | } |
Michal Kazior | 6c5151a | 2014-02-27 18:50:04 +0200 | [diff] [blame^] | 1249 | case HTT_T2H_MSG_TYPE_TX_COMPL_IND: |
| 1250 | spin_lock_bh(&htt->tx_lock); |
| 1251 | __skb_queue_tail(&htt->tx_compl_q, skb); |
| 1252 | spin_unlock_bh(&htt->tx_lock); |
| 1253 | tasklet_schedule(&htt->txrx_compl_task); |
| 1254 | return; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1255 | case HTT_T2H_MSG_TYPE_SEC_IND: { |
| 1256 | struct ath10k *ar = htt->ar; |
| 1257 | struct htt_security_indication *ev = &resp->security_indication; |
| 1258 | |
| 1259 | ath10k_dbg(ATH10K_DBG_HTT, |
| 1260 | "sec ind peer_id %d unicast %d type %d\n", |
| 1261 | __le16_to_cpu(ev->peer_id), |
| 1262 | !!(ev->flags & HTT_SECURITY_IS_UNICAST), |
| 1263 | MS(ev->flags, HTT_SECURITY_TYPE)); |
| 1264 | complete(&ar->install_key_done); |
| 1265 | break; |
| 1266 | } |
| 1267 | case HTT_T2H_MSG_TYPE_RX_FRAG_IND: { |
| 1268 | ath10k_dbg_dump(ATH10K_DBG_HTT_DUMP, NULL, "htt event: ", |
| 1269 | skb->data, skb->len); |
| 1270 | ath10k_htt_rx_frag_handler(htt, &resp->rx_frag_ind); |
| 1271 | break; |
| 1272 | } |
| 1273 | case HTT_T2H_MSG_TYPE_TEST: |
| 1274 | /* FIX THIS */ |
| 1275 | break; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1276 | case HTT_T2H_MSG_TYPE_STATS_CONF: |
Kalle Valo | a9bf050 | 2013-09-03 11:43:55 +0300 | [diff] [blame] | 1277 | trace_ath10k_htt_stats(skb->data, skb->len); |
| 1278 | break; |
| 1279 | case HTT_T2H_MSG_TYPE_TX_INSPECT_IND: |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1280 | case HTT_T2H_MSG_TYPE_RX_ADDBA: |
| 1281 | case HTT_T2H_MSG_TYPE_RX_DELBA: |
| 1282 | case HTT_T2H_MSG_TYPE_RX_FLUSH: |
| 1283 | default: |
| 1284 | ath10k_dbg(ATH10K_DBG_HTT, "htt event (%d) not handled\n", |
| 1285 | resp->hdr.msg_type); |
| 1286 | ath10k_dbg_dump(ATH10K_DBG_HTT_DUMP, NULL, "htt event: ", |
| 1287 | skb->data, skb->len); |
| 1288 | break; |
| 1289 | }; |
| 1290 | |
| 1291 | /* Free the indication buffer */ |
| 1292 | dev_kfree_skb_any(skb); |
| 1293 | } |
Michal Kazior | 6c5151a | 2014-02-27 18:50:04 +0200 | [diff] [blame^] | 1294 | |
| 1295 | static void ath10k_htt_txrx_compl_task(unsigned long ptr) |
| 1296 | { |
| 1297 | struct ath10k_htt *htt = (struct ath10k_htt *)ptr; |
| 1298 | struct htt_resp *resp; |
| 1299 | struct sk_buff *skb; |
| 1300 | |
| 1301 | while ((skb = skb_dequeue(&htt->tx_compl_q))) { |
| 1302 | ath10k_htt_rx_frm_tx_compl(htt->ar, skb); |
| 1303 | dev_kfree_skb_any(skb); |
| 1304 | } |
| 1305 | |
| 1306 | while ((skb = skb_dequeue(&htt->rx_compl_q))) { |
| 1307 | resp = (struct htt_resp *)skb->data; |
| 1308 | ath10k_htt_rx_handler(htt, &resp->rx_ind); |
| 1309 | dev_kfree_skb_any(skb); |
| 1310 | } |
| 1311 | } |