Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1 | /* |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 2 | * Copyright (c) 2013-2016 The Linux Foundation. All rights reserved. |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 3 | * |
| 4 | * Previously licensed under the ISC license by Qualcomm Atheros, Inc. |
| 5 | * |
| 6 | * |
| 7 | * Permission to use, copy, modify, and/or distribute this software for |
| 8 | * any purpose with or without fee is hereby granted, provided that the |
| 9 | * above copyright notice and this permission notice appear in all |
| 10 | * copies. |
| 11 | * |
| 12 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL |
| 13 | * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED |
| 14 | * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE |
| 15 | * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL |
| 16 | * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
| 17 | * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 18 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 19 | * PERFORMANCE OF THIS SOFTWARE. |
| 20 | */ |
| 21 | |
| 22 | /* |
| 23 | * This file was originally distributed by Qualcomm Atheros, Inc. |
| 24 | * under proprietary terms before Copyright ownership was assigned |
| 25 | * to the Linux Foundation. |
| 26 | */ |
| 27 | |
| 28 | #include <osdep.h> |
| 29 | #include "a_types.h" |
| 30 | #include <athdefs.h> |
| 31 | #include "osapi_linux.h" |
| 32 | #include "hif.h" |
| 33 | #include "hif_io32.h" |
| 34 | #include "ce_api.h" |
| 35 | #include "ce_main.h" |
| 36 | #include "ce_internal.h" |
| 37 | #include "ce_reg.h" |
| 38 | #include "cdf_lock.h" |
| 39 | #include "regtable.h" |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 40 | #include "epping_main.h" |
| 41 | #include "hif_main.h" |
| 42 | #include "hif_debug.h" |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 43 | |
| 44 | #ifdef IPA_OFFLOAD |
| 45 | #ifdef QCA_WIFI_3_0 |
| 46 | #define CE_IPA_RING_INIT(ce_desc) \ |
| 47 | do { \ |
| 48 | ce_desc->gather = 0; \ |
| 49 | ce_desc->enable_11h = 0; \ |
| 50 | ce_desc->meta_data_low = 0; \ |
| 51 | ce_desc->packet_result_offset = 64; \ |
| 52 | ce_desc->toeplitz_hash_enable = 0; \ |
| 53 | ce_desc->addr_y_search_disable = 0; \ |
| 54 | ce_desc->addr_x_search_disable = 0; \ |
| 55 | ce_desc->misc_int_disable = 0; \ |
| 56 | ce_desc->target_int_disable = 0; \ |
| 57 | ce_desc->host_int_disable = 0; \ |
| 58 | ce_desc->dest_byte_swap = 0; \ |
| 59 | ce_desc->byte_swap = 0; \ |
| 60 | ce_desc->type = 2; \ |
| 61 | ce_desc->tx_classify = 1; \ |
| 62 | ce_desc->buffer_addr_hi = 0; \ |
| 63 | ce_desc->meta_data = 0; \ |
| 64 | ce_desc->nbytes = 128; \ |
| 65 | } while (0) |
| 66 | #else |
| 67 | #define CE_IPA_RING_INIT(ce_desc) \ |
| 68 | do { \ |
| 69 | ce_desc->byte_swap = 0; \ |
| 70 | ce_desc->nbytes = 60; \ |
| 71 | ce_desc->gather = 0; \ |
| 72 | } while (0) |
| 73 | #endif /* QCA_WIFI_3_0 */ |
| 74 | #endif /* IPA_OFFLOAD */ |
| 75 | |
| 76 | static int war1_allow_sleep; |
| 77 | /* io32 write workaround */ |
| 78 | static int hif_ce_war1; |
| 79 | |
Houston Hoffman | 68e837e | 2015-12-04 12:57:24 -0800 | [diff] [blame] | 80 | #ifdef CONFIG_SLUB_DEBUG_ON |
| 81 | |
| 82 | /** |
| 83 | * struct hif_ce_event - structure for detailing a ce event |
| 84 | * @type: what the event was |
| 85 | * @time: when it happened |
| 86 | * @descriptor: descriptor enqueued or dequeued |
| 87 | * @memory: virtual address that was used |
| 88 | * @index: location of the descriptor in the ce ring; |
| 89 | */ |
| 90 | struct hif_ce_desc_event { |
| 91 | uint16_t index; |
| 92 | enum hif_ce_event_type type; |
| 93 | uint64_t time; |
| 94 | union ce_desc descriptor; |
| 95 | void *memory; |
| 96 | }; |
| 97 | |
| 98 | /* max history to record per copy engine */ |
| 99 | #define HIF_CE_HISTORY_MAX 512 |
| 100 | cdf_atomic_t hif_ce_desc_history_index[CE_COUNT_MAX]; |
| 101 | struct hif_ce_desc_event hif_ce_desc_history[CE_COUNT_MAX][HIF_CE_HISTORY_MAX]; |
| 102 | |
Houston Hoffman | 4275ba2 | 2015-12-06 21:02:11 -0800 | [diff] [blame] | 103 | |
Houston Hoffman | 68e837e | 2015-12-04 12:57:24 -0800 | [diff] [blame] | 104 | /** |
| 105 | * get_next_record_index() - get the next record index |
| 106 | * @table_index: atomic index variable to increment |
| 107 | * @array_size: array size of the circular buffer |
| 108 | * |
| 109 | * Increment the atomic index and reserve the value. |
| 110 | * Takes care of buffer wrap. |
| 111 | * Guaranteed to be thread safe as long as fewer than array_size contexts |
| 112 | * try to access the array. If there are more than array_size contexts |
| 113 | * trying to access the array, full locking of the recording process would |
| 114 | * be needed to have sane logging. |
| 115 | */ |
| 116 | static int get_next_record_index(cdf_atomic_t *table_index, int array_size) |
| 117 | { |
| 118 | int record_index = cdf_atomic_inc_return(table_index); |
| 119 | if (record_index == array_size) |
| 120 | cdf_atomic_sub(array_size, table_index); |
| 121 | |
| 122 | while (record_index >= array_size) |
| 123 | record_index -= array_size; |
| 124 | return record_index; |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * hif_record_ce_desc_event() - record ce descriptor events |
Komal Seelam | bd7c51d | 2016-02-24 10:27:30 +0530 | [diff] [blame^] | 129 | * @scn: hif_softc |
Houston Hoffman | 68e837e | 2015-12-04 12:57:24 -0800 | [diff] [blame] | 130 | * @ce_id: which ce is the event occuring on |
| 131 | * @type: what happened |
| 132 | * @descriptor: pointer to the descriptor posted/completed |
| 133 | * @memory: virtual address of buffer related to the descriptor |
| 134 | * @index: index that the descriptor was/will be at. |
| 135 | */ |
Komal Seelam | bd7c51d | 2016-02-24 10:27:30 +0530 | [diff] [blame^] | 136 | void hif_record_ce_desc_event(struct hif_softc *scn, int ce_id, |
| 137 | enum hif_ce_event_type type, |
| 138 | union ce_desc *descriptor, |
| 139 | void *memory, int index) |
Houston Hoffman | 68e837e | 2015-12-04 12:57:24 -0800 | [diff] [blame] | 140 | { |
Komal Seelam | bd7c51d | 2016-02-24 10:27:30 +0530 | [diff] [blame^] | 141 | struct hif_callbacks *cbk = hif_get_callbacks_handle(scn); |
Houston Hoffman | 68e837e | 2015-12-04 12:57:24 -0800 | [diff] [blame] | 142 | int record_index = get_next_record_index( |
| 143 | &hif_ce_desc_history_index[ce_id], HIF_CE_HISTORY_MAX); |
| 144 | |
| 145 | struct hif_ce_desc_event *event = |
| 146 | &hif_ce_desc_history[ce_id][record_index]; |
| 147 | event->type = type; |
Komal Seelam | bd7c51d | 2016-02-24 10:27:30 +0530 | [diff] [blame^] | 148 | |
| 149 | if (cbk && cbk->get_monotonic_boottime) |
| 150 | event->time = cbk->get_monotonic_boottime(); |
| 151 | else |
| 152 | event->time = ((uint64_t)cdf_system_ticks_to_msecs( |
| 153 | cdf_system_ticks()) * 1000); |
| 154 | |
Houston Hoffman | 4275ba2 | 2015-12-06 21:02:11 -0800 | [diff] [blame] | 155 | if (descriptor != NULL) |
| 156 | event->descriptor = *descriptor; |
| 157 | else |
| 158 | memset(&event->descriptor, 0, sizeof(union ce_desc)); |
Houston Hoffman | 68e837e | 2015-12-04 12:57:24 -0800 | [diff] [blame] | 159 | event->memory = memory; |
| 160 | event->index = index; |
| 161 | } |
| 162 | |
| 163 | /** |
| 164 | * ce_init_ce_desc_event_log() - initialize the ce event log |
| 165 | * @ce_id: copy engine id for which we are initializing the log |
| 166 | * @size: size of array to dedicate |
| 167 | * |
| 168 | * Currently the passed size is ignored in favor of a precompiled value. |
| 169 | */ |
| 170 | void ce_init_ce_desc_event_log(int ce_id, int size) |
| 171 | { |
| 172 | cdf_atomic_init(&hif_ce_desc_history_index[ce_id]); |
| 173 | } |
| 174 | #else |
Komal Seelam | bd7c51d | 2016-02-24 10:27:30 +0530 | [diff] [blame^] | 175 | void hif_record_ce_desc_event(struct hif_softc *scn, |
Houston Hoffman | 68e837e | 2015-12-04 12:57:24 -0800 | [diff] [blame] | 176 | int ce_id, enum hif_ce_event_type type, |
| 177 | union ce_desc *descriptor, void *memory, |
| 178 | int index) |
| 179 | { |
| 180 | } |
| 181 | |
Houston Hoffman | 5cc292b | 2015-12-22 11:33:14 -0800 | [diff] [blame] | 182 | inline void ce_init_ce_desc_event_log(int ce_id, int size) |
Houston Hoffman | 68e837e | 2015-12-04 12:57:24 -0800 | [diff] [blame] | 183 | { |
| 184 | } |
| 185 | #endif |
| 186 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 187 | /* |
| 188 | * Support for Copy Engine hardware, which is mainly used for |
| 189 | * communication between Host and Target over a PCIe interconnect. |
| 190 | */ |
| 191 | |
| 192 | /* |
| 193 | * A single CopyEngine (CE) comprises two "rings": |
| 194 | * a source ring |
| 195 | * a destination ring |
| 196 | * |
| 197 | * Each ring consists of a number of descriptors which specify |
| 198 | * an address, length, and meta-data. |
| 199 | * |
| 200 | * Typically, one side of the PCIe interconnect (Host or Target) |
| 201 | * controls one ring and the other side controls the other ring. |
| 202 | * The source side chooses when to initiate a transfer and it |
| 203 | * chooses what to send (buffer address, length). The destination |
| 204 | * side keeps a supply of "anonymous receive buffers" available and |
| 205 | * it handles incoming data as it arrives (when the destination |
| 206 | * recieves an interrupt). |
| 207 | * |
| 208 | * The sender may send a simple buffer (address/length) or it may |
| 209 | * send a small list of buffers. When a small list is sent, hardware |
| 210 | * "gathers" these and they end up in a single destination buffer |
| 211 | * with a single interrupt. |
| 212 | * |
| 213 | * There are several "contexts" managed by this layer -- more, it |
| 214 | * may seem -- than should be needed. These are provided mainly for |
| 215 | * maximum flexibility and especially to facilitate a simpler HIF |
| 216 | * implementation. There are per-CopyEngine recv, send, and watermark |
| 217 | * contexts. These are supplied by the caller when a recv, send, |
| 218 | * or watermark handler is established and they are echoed back to |
| 219 | * the caller when the respective callbacks are invoked. There is |
| 220 | * also a per-transfer context supplied by the caller when a buffer |
| 221 | * (or sendlist) is sent and when a buffer is enqueued for recv. |
| 222 | * These per-transfer contexts are echoed back to the caller when |
| 223 | * the buffer is sent/received. |
| 224 | * Target TX harsh result toeplitz_hash_result |
| 225 | */ |
| 226 | |
| 227 | /* |
| 228 | * Guts of ce_send, used by both ce_send and ce_sendlist_send. |
| 229 | * The caller takes responsibility for any needed locking. |
| 230 | */ |
| 231 | int |
| 232 | ce_completed_send_next_nolock(struct CE_state *CE_state, |
| 233 | void **per_CE_contextp, |
| 234 | void **per_transfer_contextp, |
| 235 | cdf_dma_addr_t *bufferp, |
| 236 | unsigned int *nbytesp, |
| 237 | unsigned int *transfer_idp, |
| 238 | unsigned int *sw_idx, unsigned int *hw_idx, |
| 239 | uint32_t *toeplitz_hash_result); |
| 240 | |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 241 | void war_ce_src_ring_write_idx_set(struct hif_softc *scn, |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 242 | u32 ctrl_addr, unsigned int write_index) |
| 243 | { |
| 244 | if (hif_ce_war1) { |
| 245 | void __iomem *indicator_addr; |
| 246 | |
| 247 | indicator_addr = scn->mem + ctrl_addr + DST_WATERMARK_ADDRESS; |
| 248 | |
| 249 | if (!war1_allow_sleep |
| 250 | && ctrl_addr == CE_BASE_ADDRESS(CDC_WAR_DATA_CE)) { |
| 251 | hif_write32_mb(indicator_addr, |
| 252 | (CDC_WAR_MAGIC_STR | write_index)); |
| 253 | } else { |
| 254 | unsigned long irq_flags; |
| 255 | local_irq_save(irq_flags); |
| 256 | hif_write32_mb(indicator_addr, 1); |
| 257 | |
| 258 | /* |
| 259 | * PCIE write waits for ACK in IPQ8K, there is no |
| 260 | * need to read back value. |
| 261 | */ |
| 262 | (void)hif_read32_mb(indicator_addr); |
| 263 | (void)hif_read32_mb(indicator_addr); /* conservative */ |
| 264 | |
| 265 | CE_SRC_RING_WRITE_IDX_SET(scn, |
| 266 | ctrl_addr, write_index); |
| 267 | |
| 268 | hif_write32_mb(indicator_addr, 0); |
| 269 | local_irq_restore(irq_flags); |
| 270 | } |
| 271 | } else |
| 272 | CE_SRC_RING_WRITE_IDX_SET(scn, ctrl_addr, write_index); |
| 273 | } |
| 274 | |
| 275 | int |
| 276 | ce_send_nolock(struct CE_handle *copyeng, |
| 277 | void *per_transfer_context, |
| 278 | cdf_dma_addr_t buffer, |
| 279 | uint32_t nbytes, |
| 280 | uint32_t transfer_id, |
| 281 | uint32_t flags, |
| 282 | uint32_t user_flags) |
| 283 | { |
| 284 | int status; |
| 285 | struct CE_state *CE_state = (struct CE_state *)copyeng; |
| 286 | struct CE_ring_state *src_ring = CE_state->src_ring; |
| 287 | uint32_t ctrl_addr = CE_state->ctrl_addr; |
| 288 | unsigned int nentries_mask = src_ring->nentries_mask; |
| 289 | unsigned int sw_index = src_ring->sw_index; |
| 290 | unsigned int write_index = src_ring->write_index; |
| 291 | uint64_t dma_addr = buffer; |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 292 | struct hif_softc *scn = CE_state->scn; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 293 | |
| 294 | A_TARGET_ACCESS_BEGIN_RET(scn); |
| 295 | if (unlikely(CE_RING_DELTA(nentries_mask, |
| 296 | write_index, sw_index - 1) <= 0)) { |
| 297 | OL_ATH_CE_PKT_ERROR_COUNT_INCR(scn, CE_RING_DELTA_FAIL); |
| 298 | status = CDF_STATUS_E_FAILURE; |
| 299 | A_TARGET_ACCESS_END_RET(scn); |
| 300 | return status; |
| 301 | } |
| 302 | { |
Houston Hoffman | 68e837e | 2015-12-04 12:57:24 -0800 | [diff] [blame] | 303 | enum hif_ce_event_type event_type = HIF_TX_GATHER_DESC_POST; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 304 | struct CE_src_desc *src_ring_base = |
| 305 | (struct CE_src_desc *)src_ring->base_addr_owner_space; |
| 306 | struct CE_src_desc *shadow_base = |
| 307 | (struct CE_src_desc *)src_ring->shadow_base; |
| 308 | struct CE_src_desc *src_desc = |
| 309 | CE_SRC_RING_TO_DESC(src_ring_base, write_index); |
| 310 | struct CE_src_desc *shadow_src_desc = |
| 311 | CE_SRC_RING_TO_DESC(shadow_base, write_index); |
| 312 | |
| 313 | /* Update low 32 bits source descriptor address */ |
| 314 | shadow_src_desc->buffer_addr = |
| 315 | (uint32_t)(dma_addr & 0xFFFFFFFF); |
| 316 | #ifdef QCA_WIFI_3_0 |
| 317 | shadow_src_desc->buffer_addr_hi = |
| 318 | (uint32_t)((dma_addr >> 32) & 0x1F); |
| 319 | user_flags |= shadow_src_desc->buffer_addr_hi; |
| 320 | memcpy(&(((uint32_t *)shadow_src_desc)[1]), &user_flags, |
| 321 | sizeof(uint32_t)); |
| 322 | #endif |
| 323 | shadow_src_desc->meta_data = transfer_id; |
| 324 | |
| 325 | /* |
| 326 | * Set the swap bit if: |
| 327 | * typical sends on this CE are swapped (host is big-endian) |
| 328 | * and this send doesn't disable the swapping |
| 329 | * (data is not bytestream) |
| 330 | */ |
| 331 | shadow_src_desc->byte_swap = |
| 332 | (((CE_state->attr_flags & CE_ATTR_BYTE_SWAP_DATA) |
| 333 | != 0) & ((flags & CE_SEND_FLAG_SWAP_DISABLE) == 0)); |
| 334 | shadow_src_desc->gather = ((flags & CE_SEND_FLAG_GATHER) != 0); |
| 335 | shadow_src_desc->nbytes = nbytes; |
| 336 | |
| 337 | *src_desc = *shadow_src_desc; |
| 338 | |
| 339 | src_ring->per_transfer_context[write_index] = |
| 340 | per_transfer_context; |
| 341 | |
| 342 | /* Update Source Ring Write Index */ |
| 343 | write_index = CE_RING_IDX_INCR(nentries_mask, write_index); |
| 344 | |
| 345 | /* WORKAROUND */ |
| 346 | if (!shadow_src_desc->gather) { |
Houston Hoffman | 68e837e | 2015-12-04 12:57:24 -0800 | [diff] [blame] | 347 | event_type = HIF_TX_DESC_POST; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 348 | war_ce_src_ring_write_idx_set(scn, ctrl_addr, |
| 349 | write_index); |
| 350 | } |
| 351 | |
Houston Hoffman | 68e837e | 2015-12-04 12:57:24 -0800 | [diff] [blame] | 352 | /* src_ring->write index hasn't been updated event though |
| 353 | * the register has allready been written to. |
| 354 | */ |
Komal Seelam | bd7c51d | 2016-02-24 10:27:30 +0530 | [diff] [blame^] | 355 | hif_record_ce_desc_event(scn, CE_state->id, event_type, |
Houston Hoffman | 68e837e | 2015-12-04 12:57:24 -0800 | [diff] [blame] | 356 | (union ce_desc *) shadow_src_desc, per_transfer_context, |
| 357 | src_ring->write_index); |
| 358 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 359 | src_ring->write_index = write_index; |
| 360 | status = CDF_STATUS_SUCCESS; |
| 361 | } |
| 362 | A_TARGET_ACCESS_END_RET(scn); |
| 363 | |
| 364 | return status; |
| 365 | } |
| 366 | |
| 367 | int |
| 368 | ce_send(struct CE_handle *copyeng, |
| 369 | void *per_transfer_context, |
| 370 | cdf_dma_addr_t buffer, |
| 371 | uint32_t nbytes, |
| 372 | uint32_t transfer_id, |
| 373 | uint32_t flags, |
| 374 | uint32_t user_flag) |
| 375 | { |
| 376 | struct CE_state *CE_state = (struct CE_state *)copyeng; |
| 377 | int status; |
| 378 | |
Houston Hoffman | 44b7e4a | 2015-09-03 17:01:22 -0700 | [diff] [blame] | 379 | cdf_spin_lock_bh(&CE_state->ce_index_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 380 | status = ce_send_nolock(copyeng, per_transfer_context, buffer, nbytes, |
| 381 | transfer_id, flags, user_flag); |
Houston Hoffman | 44b7e4a | 2015-09-03 17:01:22 -0700 | [diff] [blame] | 382 | cdf_spin_unlock_bh(&CE_state->ce_index_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 383 | |
| 384 | return status; |
| 385 | } |
| 386 | |
| 387 | unsigned int ce_sendlist_sizeof(void) |
| 388 | { |
| 389 | return sizeof(struct ce_sendlist); |
| 390 | } |
| 391 | |
| 392 | void ce_sendlist_init(struct ce_sendlist *sendlist) |
| 393 | { |
| 394 | struct ce_sendlist_s *sl = (struct ce_sendlist_s *)sendlist; |
| 395 | sl->num_items = 0; |
| 396 | } |
| 397 | |
| 398 | int |
| 399 | ce_sendlist_buf_add(struct ce_sendlist *sendlist, |
| 400 | cdf_dma_addr_t buffer, |
| 401 | uint32_t nbytes, |
| 402 | uint32_t flags, |
| 403 | uint32_t user_flags) |
| 404 | { |
| 405 | struct ce_sendlist_s *sl = (struct ce_sendlist_s *)sendlist; |
| 406 | unsigned int num_items = sl->num_items; |
| 407 | struct ce_sendlist_item *item; |
| 408 | |
| 409 | if (num_items >= CE_SENDLIST_ITEMS_MAX) { |
| 410 | CDF_ASSERT(num_items < CE_SENDLIST_ITEMS_MAX); |
| 411 | return CDF_STATUS_E_RESOURCES; |
| 412 | } |
| 413 | |
| 414 | item = &sl->item[num_items]; |
| 415 | item->send_type = CE_SIMPLE_BUFFER_TYPE; |
| 416 | item->data = buffer; |
| 417 | item->u.nbytes = nbytes; |
| 418 | item->flags = flags; |
| 419 | item->user_flags = user_flags; |
| 420 | sl->num_items = num_items + 1; |
| 421 | return CDF_STATUS_SUCCESS; |
| 422 | } |
| 423 | |
| 424 | int |
| 425 | ce_sendlist_send(struct CE_handle *copyeng, |
| 426 | void *per_transfer_context, |
| 427 | struct ce_sendlist *sendlist, unsigned int transfer_id) |
| 428 | { |
| 429 | int status = -ENOMEM; |
| 430 | struct ce_sendlist_s *sl = (struct ce_sendlist_s *)sendlist; |
| 431 | struct CE_state *CE_state = (struct CE_state *)copyeng; |
| 432 | struct CE_ring_state *src_ring = CE_state->src_ring; |
| 433 | unsigned int nentries_mask = src_ring->nentries_mask; |
| 434 | unsigned int num_items = sl->num_items; |
| 435 | unsigned int sw_index; |
| 436 | unsigned int write_index; |
| 437 | |
| 438 | CDF_ASSERT((num_items > 0) && (num_items < src_ring->nentries)); |
| 439 | |
Houston Hoffman | 44b7e4a | 2015-09-03 17:01:22 -0700 | [diff] [blame] | 440 | cdf_spin_lock_bh(&CE_state->ce_index_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 441 | sw_index = src_ring->sw_index; |
| 442 | write_index = src_ring->write_index; |
| 443 | |
| 444 | if (CE_RING_DELTA(nentries_mask, write_index, sw_index - 1) >= |
| 445 | num_items) { |
| 446 | struct ce_sendlist_item *item; |
| 447 | int i; |
| 448 | |
| 449 | /* handle all but the last item uniformly */ |
| 450 | for (i = 0; i < num_items - 1; i++) { |
| 451 | item = &sl->item[i]; |
| 452 | /* TBDXXX: Support extensible sendlist_types? */ |
| 453 | CDF_ASSERT(item->send_type == CE_SIMPLE_BUFFER_TYPE); |
| 454 | status = ce_send_nolock(copyeng, CE_SENDLIST_ITEM_CTXT, |
| 455 | (cdf_dma_addr_t) item->data, |
| 456 | item->u.nbytes, transfer_id, |
| 457 | item->flags | CE_SEND_FLAG_GATHER, |
| 458 | item->user_flags); |
| 459 | CDF_ASSERT(status == CDF_STATUS_SUCCESS); |
| 460 | } |
| 461 | /* provide valid context pointer for final item */ |
| 462 | item = &sl->item[i]; |
| 463 | /* TBDXXX: Support extensible sendlist_types? */ |
| 464 | CDF_ASSERT(item->send_type == CE_SIMPLE_BUFFER_TYPE); |
| 465 | status = ce_send_nolock(copyeng, per_transfer_context, |
| 466 | (cdf_dma_addr_t) item->data, |
| 467 | item->u.nbytes, |
| 468 | transfer_id, item->flags, |
| 469 | item->user_flags); |
| 470 | CDF_ASSERT(status == CDF_STATUS_SUCCESS); |
| 471 | NBUF_UPDATE_TX_PKT_COUNT((cdf_nbuf_t)per_transfer_context, |
| 472 | NBUF_TX_PKT_CE); |
| 473 | DPTRACE(cdf_dp_trace((cdf_nbuf_t)per_transfer_context, |
| 474 | CDF_DP_TRACE_CE_PACKET_PTR_RECORD, |
| 475 | (uint8_t *)(((cdf_nbuf_t)per_transfer_context)->data), |
| 476 | sizeof(((cdf_nbuf_t)per_transfer_context)->data))); |
| 477 | } else { |
| 478 | /* |
| 479 | * Probably not worth the additional complexity to support |
| 480 | * partial sends with continuation or notification. We expect |
| 481 | * to use large rings and small sendlists. If we can't handle |
| 482 | * the entire request at once, punt it back to the caller. |
| 483 | */ |
| 484 | } |
Houston Hoffman | 44b7e4a | 2015-09-03 17:01:22 -0700 | [diff] [blame] | 485 | cdf_spin_unlock_bh(&CE_state->ce_index_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 486 | |
| 487 | return status; |
| 488 | } |
| 489 | |
| 490 | #ifdef WLAN_FEATURE_FASTPATH |
| 491 | #ifdef QCA_WIFI_3_0 |
| 492 | static inline void |
| 493 | ce_buffer_addr_hi_set(struct CE_src_desc *shadow_src_desc, |
| 494 | uint64_t dma_addr, |
| 495 | uint32_t user_flags) |
| 496 | { |
| 497 | shadow_src_desc->buffer_addr_hi = |
| 498 | (uint32_t)((dma_addr >> 32) & 0x1F); |
| 499 | user_flags |= shadow_src_desc->buffer_addr_hi; |
| 500 | memcpy(&(((uint32_t *)shadow_src_desc)[1]), &user_flags, |
| 501 | sizeof(uint32_t)); |
| 502 | } |
| 503 | #else |
| 504 | static inline void |
| 505 | ce_buffer_addr_hi_set(struct CE_src_desc *shadow_src_desc, |
| 506 | uint64_t dma_addr, |
| 507 | uint32_t user_flags) |
| 508 | { |
| 509 | } |
| 510 | #endif |
| 511 | |
| 512 | /** |
| 513 | * ce_send_fast() CE layer Tx buffer posting function |
| 514 | * @copyeng: copy engine handle |
| 515 | * @msdus: iarray of msdu to be sent |
| 516 | * @num_msdus: number of msdus in an array |
| 517 | * @transfer_id: transfer_id |
| 518 | * |
| 519 | * Assumption : Called with an array of MSDU's |
| 520 | * Function: |
| 521 | * For each msdu in the array |
| 522 | * 1. Check no. of available entries |
| 523 | * 2. Create src ring entries (allocated in consistent memory |
| 524 | * 3. Write index to h/w |
| 525 | * |
| 526 | * Return: No. of packets that could be sent |
| 527 | */ |
| 528 | |
| 529 | int ce_send_fast(struct CE_handle *copyeng, cdf_nbuf_t *msdus, |
| 530 | unsigned int num_msdus, unsigned int transfer_id) |
| 531 | { |
| 532 | struct CE_state *ce_state = (struct CE_state *)copyeng; |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 533 | struct hif_softc *scn = ce_state->scn; |
Komal Seelam | 5584a7c | 2016-02-24 19:22:48 +0530 | [diff] [blame] | 534 | struct hif_opaque_softc *hif_hdl = GET_HIF_OPAQUE_HDL(scn); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 535 | struct CE_ring_state *src_ring = ce_state->src_ring; |
| 536 | u_int32_t ctrl_addr = ce_state->ctrl_addr; |
| 537 | unsigned int nentries_mask = src_ring->nentries_mask; |
| 538 | unsigned int write_index; |
| 539 | unsigned int sw_index; |
| 540 | unsigned int frag_len; |
| 541 | cdf_nbuf_t msdu; |
| 542 | int i; |
| 543 | uint64_t dma_addr; |
| 544 | uint32_t user_flags = 0; |
| 545 | |
Houston Hoffman | 44b7e4a | 2015-09-03 17:01:22 -0700 | [diff] [blame] | 546 | cdf_spin_lock_bh(&ce_state->ce_index_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 547 | sw_index = src_ring->sw_index; |
| 548 | write_index = src_ring->write_index; |
| 549 | |
| 550 | /* 2 msdus per packet */ |
| 551 | for (i = 0; i < num_msdus; i++) { |
| 552 | struct CE_src_desc *src_ring_base = |
| 553 | (struct CE_src_desc *)src_ring->base_addr_owner_space; |
| 554 | struct CE_src_desc *shadow_base = |
| 555 | (struct CE_src_desc *)src_ring->shadow_base; |
| 556 | struct CE_src_desc *src_desc = |
| 557 | CE_SRC_RING_TO_DESC(src_ring_base, write_index); |
| 558 | struct CE_src_desc *shadow_src_desc = |
| 559 | CE_SRC_RING_TO_DESC(shadow_base, write_index); |
| 560 | |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 561 | hif_pm_runtime_get_noresume(hif_hdl); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 562 | msdu = msdus[i]; |
| 563 | |
| 564 | /* |
| 565 | * First fill out the ring descriptor for the HTC HTT frame |
| 566 | * header. These are uncached writes. Should we use a local |
| 567 | * structure instead? |
| 568 | */ |
| 569 | /* HTT/HTC header can be passed as a argument */ |
| 570 | dma_addr = cdf_nbuf_get_frag_paddr_lo(msdu, 0); |
| 571 | shadow_src_desc->buffer_addr = (uint32_t)(dma_addr & |
| 572 | 0xFFFFFFFF); |
| 573 | user_flags = cdf_nbuf_data_attr_get(msdu) & DESC_DATA_FLAG_MASK; |
| 574 | ce_buffer_addr_hi_set(shadow_src_desc, dma_addr, user_flags); |
| 575 | |
| 576 | shadow_src_desc->meta_data = transfer_id; |
| 577 | shadow_src_desc->nbytes = cdf_nbuf_get_frag_len(msdu, 0); |
| 578 | |
| 579 | /* |
| 580 | * HTC HTT header is a word stream, so byte swap if CE byte |
| 581 | * swap enabled |
| 582 | */ |
| 583 | shadow_src_desc->byte_swap = ((ce_state->attr_flags & |
| 584 | CE_ATTR_BYTE_SWAP_DATA) != 0); |
| 585 | /* For the first one, it still does not need to write */ |
| 586 | shadow_src_desc->gather = 1; |
| 587 | *src_desc = *shadow_src_desc; |
| 588 | |
| 589 | /* By default we could initialize the transfer context to this |
| 590 | * value |
| 591 | */ |
| 592 | src_ring->per_transfer_context[write_index] = |
| 593 | CE_SENDLIST_ITEM_CTXT; |
| 594 | |
| 595 | write_index = CE_RING_IDX_INCR(nentries_mask, write_index); |
| 596 | |
| 597 | src_desc = CE_SRC_RING_TO_DESC(src_ring_base, write_index); |
| 598 | shadow_src_desc = CE_SRC_RING_TO_DESC(shadow_base, write_index); |
| 599 | /* |
| 600 | * Now fill out the ring descriptor for the actual data |
| 601 | * packet |
| 602 | */ |
| 603 | dma_addr = cdf_nbuf_get_frag_paddr_lo(msdu, 1); |
| 604 | shadow_src_desc->buffer_addr = (uint32_t)(dma_addr & |
| 605 | 0xFFFFFFFF); |
| 606 | /* |
| 607 | * Clear packet offset for all but the first CE desc. |
| 608 | */ |
| 609 | user_flags &= ~CDF_CE_TX_PKT_OFFSET_BIT_M; |
| 610 | ce_buffer_addr_hi_set(shadow_src_desc, dma_addr, user_flags); |
| 611 | shadow_src_desc->meta_data = transfer_id; |
| 612 | |
| 613 | /* get actual packet length */ |
| 614 | frag_len = cdf_nbuf_get_frag_len(msdu, 1); |
Houston Hoffman | a5e74c1 | 2015-09-02 18:06:28 -0700 | [diff] [blame] | 615 | |
| 616 | /* only read download_len once */ |
| 617 | shadow_src_desc->nbytes = ce_state->download_len; |
| 618 | if (shadow_src_desc->nbytes > frag_len) |
| 619 | shadow_src_desc->nbytes = frag_len; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 620 | |
| 621 | /* Data packet is a byte stream, so disable byte swap */ |
| 622 | shadow_src_desc->byte_swap = 0; |
| 623 | /* For the last one, gather is not set */ |
| 624 | shadow_src_desc->gather = 0; |
| 625 | *src_desc = *shadow_src_desc; |
| 626 | src_ring->per_transfer_context[write_index] = msdu; |
| 627 | write_index = CE_RING_IDX_INCR(nentries_mask, write_index); |
| 628 | } |
| 629 | |
| 630 | /* Write the final index to h/w one-shot */ |
| 631 | if (i) { |
| 632 | src_ring->write_index = write_index; |
Houston Hoffman | f460785 | 2015-12-17 17:14:40 -0800 | [diff] [blame] | 633 | |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 634 | if (hif_pm_runtime_get(hif_hdl) == 0) { |
Houston Hoffman | f460785 | 2015-12-17 17:14:40 -0800 | [diff] [blame] | 635 | /* Don't call WAR_XXX from here |
| 636 | * Just call XXX instead, that has the reqd. intel |
| 637 | */ |
| 638 | war_ce_src_ring_write_idx_set(scn, ctrl_addr, |
| 639 | write_index); |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 640 | hif_pm_runtime_put(hif_hdl); |
Houston Hoffman | f460785 | 2015-12-17 17:14:40 -0800 | [diff] [blame] | 641 | } |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 642 | } |
| 643 | |
Houston Hoffman | 44b7e4a | 2015-09-03 17:01:22 -0700 | [diff] [blame] | 644 | cdf_spin_unlock_bh(&ce_state->ce_index_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 645 | |
| 646 | /* |
| 647 | * If all packets in the array are transmitted, |
| 648 | * i = num_msdus |
| 649 | * Temporarily add an ASSERT |
| 650 | */ |
| 651 | ASSERT(i == num_msdus); |
| 652 | return i; |
| 653 | } |
| 654 | #endif /* WLAN_FEATURE_FASTPATH */ |
| 655 | |
| 656 | int |
| 657 | ce_recv_buf_enqueue(struct CE_handle *copyeng, |
| 658 | void *per_recv_context, cdf_dma_addr_t buffer) |
| 659 | { |
| 660 | int status; |
| 661 | struct CE_state *CE_state = (struct CE_state *)copyeng; |
| 662 | struct CE_ring_state *dest_ring = CE_state->dest_ring; |
| 663 | uint32_t ctrl_addr = CE_state->ctrl_addr; |
| 664 | unsigned int nentries_mask = dest_ring->nentries_mask; |
| 665 | unsigned int write_index; |
| 666 | unsigned int sw_index; |
| 667 | int val = 0; |
| 668 | uint64_t dma_addr = buffer; |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 669 | struct hif_softc *scn = CE_state->scn; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 670 | |
Houston Hoffman | 44b7e4a | 2015-09-03 17:01:22 -0700 | [diff] [blame] | 671 | cdf_spin_lock_bh(&CE_state->ce_index_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 672 | write_index = dest_ring->write_index; |
| 673 | sw_index = dest_ring->sw_index; |
| 674 | |
| 675 | A_TARGET_ACCESS_BEGIN_RET_EXT(scn, val); |
| 676 | if (val == -1) { |
Houston Hoffman | 44b7e4a | 2015-09-03 17:01:22 -0700 | [diff] [blame] | 677 | cdf_spin_unlock_bh(&CE_state->ce_index_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 678 | return val; |
| 679 | } |
| 680 | |
| 681 | if (CE_RING_DELTA(nentries_mask, write_index, sw_index - 1) > 0) { |
| 682 | struct CE_dest_desc *dest_ring_base = |
| 683 | (struct CE_dest_desc *)dest_ring-> |
| 684 | base_addr_owner_space; |
| 685 | struct CE_dest_desc *dest_desc = |
| 686 | CE_DEST_RING_TO_DESC(dest_ring_base, write_index); |
| 687 | |
| 688 | /* Update low 32 bit destination descriptor */ |
| 689 | dest_desc->buffer_addr = (uint32_t)(dma_addr & 0xFFFFFFFF); |
| 690 | #ifdef QCA_WIFI_3_0 |
| 691 | dest_desc->buffer_addr_hi = |
| 692 | (uint32_t)((dma_addr >> 32) & 0x1F); |
| 693 | #endif |
| 694 | dest_desc->nbytes = 0; |
| 695 | |
| 696 | dest_ring->per_transfer_context[write_index] = |
| 697 | per_recv_context; |
| 698 | |
Komal Seelam | bd7c51d | 2016-02-24 10:27:30 +0530 | [diff] [blame^] | 699 | hif_record_ce_desc_event(scn, CE_state->id, HIF_RX_DESC_POST, |
Houston Hoffman | 68e837e | 2015-12-04 12:57:24 -0800 | [diff] [blame] | 700 | (union ce_desc *) dest_desc, per_recv_context, |
| 701 | write_index); |
| 702 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 703 | /* Update Destination Ring Write Index */ |
| 704 | write_index = CE_RING_IDX_INCR(nentries_mask, write_index); |
| 705 | CE_DEST_RING_WRITE_IDX_SET(scn, ctrl_addr, write_index); |
| 706 | dest_ring->write_index = write_index; |
| 707 | status = CDF_STATUS_SUCCESS; |
| 708 | } else { |
| 709 | status = CDF_STATUS_E_FAILURE; |
| 710 | } |
| 711 | A_TARGET_ACCESS_END_RET_EXT(scn, val); |
| 712 | if (val == -1) { |
Houston Hoffman | 44b7e4a | 2015-09-03 17:01:22 -0700 | [diff] [blame] | 713 | cdf_spin_unlock_bh(&CE_state->ce_index_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 714 | return val; |
| 715 | } |
| 716 | |
Houston Hoffman | 44b7e4a | 2015-09-03 17:01:22 -0700 | [diff] [blame] | 717 | cdf_spin_unlock_bh(&CE_state->ce_index_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 718 | |
| 719 | return status; |
| 720 | } |
| 721 | |
| 722 | void |
| 723 | ce_send_watermarks_set(struct CE_handle *copyeng, |
| 724 | unsigned int low_alert_nentries, |
| 725 | unsigned int high_alert_nentries) |
| 726 | { |
| 727 | struct CE_state *CE_state = (struct CE_state *)copyeng; |
| 728 | uint32_t ctrl_addr = CE_state->ctrl_addr; |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 729 | struct hif_softc *scn = CE_state->scn; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 730 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 731 | CE_SRC_RING_LOWMARK_SET(scn, ctrl_addr, low_alert_nentries); |
| 732 | CE_SRC_RING_HIGHMARK_SET(scn, ctrl_addr, high_alert_nentries); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 733 | } |
| 734 | |
| 735 | void |
| 736 | ce_recv_watermarks_set(struct CE_handle *copyeng, |
| 737 | unsigned int low_alert_nentries, |
| 738 | unsigned int high_alert_nentries) |
| 739 | { |
| 740 | struct CE_state *CE_state = (struct CE_state *)copyeng; |
| 741 | uint32_t ctrl_addr = CE_state->ctrl_addr; |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 742 | struct hif_softc *scn = CE_state->scn; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 743 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 744 | CE_DEST_RING_LOWMARK_SET(scn, ctrl_addr, |
| 745 | low_alert_nentries); |
| 746 | CE_DEST_RING_HIGHMARK_SET(scn, ctrl_addr, |
| 747 | high_alert_nentries); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | unsigned int ce_send_entries_avail(struct CE_handle *copyeng) |
| 751 | { |
| 752 | struct CE_state *CE_state = (struct CE_state *)copyeng; |
| 753 | struct CE_ring_state *src_ring = CE_state->src_ring; |
| 754 | unsigned int nentries_mask = src_ring->nentries_mask; |
| 755 | unsigned int sw_index; |
| 756 | unsigned int write_index; |
| 757 | |
Houston Hoffman | 44b7e4a | 2015-09-03 17:01:22 -0700 | [diff] [blame] | 758 | cdf_spin_lock(&CE_state->ce_index_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 759 | sw_index = src_ring->sw_index; |
| 760 | write_index = src_ring->write_index; |
Houston Hoffman | 44b7e4a | 2015-09-03 17:01:22 -0700 | [diff] [blame] | 761 | cdf_spin_unlock(&CE_state->ce_index_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 762 | |
| 763 | return CE_RING_DELTA(nentries_mask, write_index, sw_index - 1); |
| 764 | } |
| 765 | |
| 766 | unsigned int ce_recv_entries_avail(struct CE_handle *copyeng) |
| 767 | { |
| 768 | struct CE_state *CE_state = (struct CE_state *)copyeng; |
| 769 | struct CE_ring_state *dest_ring = CE_state->dest_ring; |
| 770 | unsigned int nentries_mask = dest_ring->nentries_mask; |
| 771 | unsigned int sw_index; |
| 772 | unsigned int write_index; |
| 773 | |
Houston Hoffman | 44b7e4a | 2015-09-03 17:01:22 -0700 | [diff] [blame] | 774 | cdf_spin_lock(&CE_state->ce_index_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 775 | sw_index = dest_ring->sw_index; |
| 776 | write_index = dest_ring->write_index; |
Houston Hoffman | 44b7e4a | 2015-09-03 17:01:22 -0700 | [diff] [blame] | 777 | cdf_spin_unlock(&CE_state->ce_index_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 778 | |
| 779 | return CE_RING_DELTA(nentries_mask, write_index, sw_index - 1); |
| 780 | } |
| 781 | |
| 782 | /* |
| 783 | * Guts of ce_send_entries_done. |
| 784 | * The caller takes responsibility for any necessary locking. |
| 785 | */ |
| 786 | unsigned int |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 787 | ce_send_entries_done_nolock(struct hif_softc *scn, |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 788 | struct CE_state *CE_state) |
| 789 | { |
| 790 | struct CE_ring_state *src_ring = CE_state->src_ring; |
| 791 | uint32_t ctrl_addr = CE_state->ctrl_addr; |
| 792 | unsigned int nentries_mask = src_ring->nentries_mask; |
| 793 | unsigned int sw_index; |
| 794 | unsigned int read_index; |
| 795 | |
| 796 | sw_index = src_ring->sw_index; |
| 797 | read_index = CE_SRC_RING_READ_IDX_GET(scn, ctrl_addr); |
| 798 | |
| 799 | return CE_RING_DELTA(nentries_mask, sw_index, read_index); |
| 800 | } |
| 801 | |
| 802 | unsigned int ce_send_entries_done(struct CE_handle *copyeng) |
| 803 | { |
| 804 | struct CE_state *CE_state = (struct CE_state *)copyeng; |
| 805 | unsigned int nentries; |
| 806 | |
Houston Hoffman | 44b7e4a | 2015-09-03 17:01:22 -0700 | [diff] [blame] | 807 | cdf_spin_lock(&CE_state->ce_index_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 808 | nentries = ce_send_entries_done_nolock(CE_state->scn, CE_state); |
Houston Hoffman | 44b7e4a | 2015-09-03 17:01:22 -0700 | [diff] [blame] | 809 | cdf_spin_unlock(&CE_state->ce_index_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 810 | |
| 811 | return nentries; |
| 812 | } |
| 813 | |
| 814 | /* |
| 815 | * Guts of ce_recv_entries_done. |
| 816 | * The caller takes responsibility for any necessary locking. |
| 817 | */ |
| 818 | unsigned int |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 819 | ce_recv_entries_done_nolock(struct hif_softc *scn, |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 820 | struct CE_state *CE_state) |
| 821 | { |
| 822 | struct CE_ring_state *dest_ring = CE_state->dest_ring; |
| 823 | uint32_t ctrl_addr = CE_state->ctrl_addr; |
| 824 | unsigned int nentries_mask = dest_ring->nentries_mask; |
| 825 | unsigned int sw_index; |
| 826 | unsigned int read_index; |
| 827 | |
| 828 | sw_index = dest_ring->sw_index; |
| 829 | read_index = CE_DEST_RING_READ_IDX_GET(scn, ctrl_addr); |
| 830 | |
| 831 | return CE_RING_DELTA(nentries_mask, sw_index, read_index); |
| 832 | } |
| 833 | |
| 834 | unsigned int ce_recv_entries_done(struct CE_handle *copyeng) |
| 835 | { |
| 836 | struct CE_state *CE_state = (struct CE_state *)copyeng; |
| 837 | unsigned int nentries; |
| 838 | |
Houston Hoffman | 44b7e4a | 2015-09-03 17:01:22 -0700 | [diff] [blame] | 839 | cdf_spin_lock(&CE_state->ce_index_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 840 | nentries = ce_recv_entries_done_nolock(CE_state->scn, CE_state); |
Houston Hoffman | 44b7e4a | 2015-09-03 17:01:22 -0700 | [diff] [blame] | 841 | cdf_spin_unlock(&CE_state->ce_index_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 842 | |
| 843 | return nentries; |
| 844 | } |
| 845 | |
| 846 | /* Debug support */ |
| 847 | void *ce_debug_cmplrn_context; /* completed recv next context */ |
| 848 | void *ce_debug_cnclsn_context; /* cancel send next context */ |
| 849 | void *ce_debug_rvkrn_context; /* revoke receive next context */ |
| 850 | void *ce_debug_cmplsn_context; /* completed send next context */ |
| 851 | |
| 852 | /* |
| 853 | * Guts of ce_completed_recv_next. |
| 854 | * The caller takes responsibility for any necessary locking. |
| 855 | */ |
| 856 | int |
| 857 | ce_completed_recv_next_nolock(struct CE_state *CE_state, |
| 858 | void **per_CE_contextp, |
| 859 | void **per_transfer_contextp, |
| 860 | cdf_dma_addr_t *bufferp, |
| 861 | unsigned int *nbytesp, |
| 862 | unsigned int *transfer_idp, |
| 863 | unsigned int *flagsp) |
| 864 | { |
| 865 | int status; |
| 866 | struct CE_ring_state *dest_ring = CE_state->dest_ring; |
| 867 | unsigned int nentries_mask = dest_ring->nentries_mask; |
| 868 | unsigned int sw_index = dest_ring->sw_index; |
Komal Seelam | bd7c51d | 2016-02-24 10:27:30 +0530 | [diff] [blame^] | 869 | struct hif_softc *scn = CE_state->scn; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 870 | struct CE_dest_desc *dest_ring_base = |
| 871 | (struct CE_dest_desc *)dest_ring->base_addr_owner_space; |
| 872 | struct CE_dest_desc *dest_desc = |
| 873 | CE_DEST_RING_TO_DESC(dest_ring_base, sw_index); |
| 874 | int nbytes; |
| 875 | struct CE_dest_desc dest_desc_info; |
| 876 | /* |
| 877 | * By copying the dest_desc_info element to local memory, we could |
| 878 | * avoid extra memory read from non-cachable memory. |
| 879 | */ |
| 880 | dest_desc_info = *dest_desc; |
| 881 | nbytes = dest_desc_info.nbytes; |
| 882 | if (nbytes == 0) { |
| 883 | /* |
| 884 | * This closes a relatively unusual race where the Host |
| 885 | * sees the updated DRRI before the update to the |
| 886 | * corresponding descriptor has completed. We treat this |
| 887 | * as a descriptor that is not yet done. |
| 888 | */ |
| 889 | status = CDF_STATUS_E_FAILURE; |
| 890 | goto done; |
| 891 | } |
| 892 | |
Komal Seelam | bd7c51d | 2016-02-24 10:27:30 +0530 | [diff] [blame^] | 893 | hif_record_ce_desc_event(scn, CE_state->id, HIF_RX_DESC_COMPLETION, |
Houston Hoffman | 68e837e | 2015-12-04 12:57:24 -0800 | [diff] [blame] | 894 | (union ce_desc *) dest_desc, |
| 895 | dest_ring->per_transfer_context[sw_index], |
| 896 | sw_index); |
| 897 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 898 | dest_desc->nbytes = 0; |
| 899 | |
| 900 | /* Return data from completed destination descriptor */ |
| 901 | *bufferp = HIF_CE_DESC_ADDR_TO_DMA(&dest_desc_info); |
| 902 | *nbytesp = nbytes; |
| 903 | *transfer_idp = dest_desc_info.meta_data; |
| 904 | *flagsp = (dest_desc_info.byte_swap) ? CE_RECV_FLAG_SWAPPED : 0; |
| 905 | |
| 906 | if (per_CE_contextp) { |
| 907 | *per_CE_contextp = CE_state->recv_context; |
| 908 | } |
| 909 | |
| 910 | ce_debug_cmplrn_context = dest_ring->per_transfer_context[sw_index]; |
| 911 | if (per_transfer_contextp) { |
| 912 | *per_transfer_contextp = ce_debug_cmplrn_context; |
| 913 | } |
| 914 | dest_ring->per_transfer_context[sw_index] = 0; /* sanity */ |
| 915 | |
| 916 | /* Update sw_index */ |
| 917 | sw_index = CE_RING_IDX_INCR(nentries_mask, sw_index); |
| 918 | dest_ring->sw_index = sw_index; |
| 919 | status = CDF_STATUS_SUCCESS; |
| 920 | |
| 921 | done: |
| 922 | return status; |
| 923 | } |
| 924 | |
| 925 | int |
| 926 | ce_completed_recv_next(struct CE_handle *copyeng, |
| 927 | void **per_CE_contextp, |
| 928 | void **per_transfer_contextp, |
| 929 | cdf_dma_addr_t *bufferp, |
| 930 | unsigned int *nbytesp, |
| 931 | unsigned int *transfer_idp, unsigned int *flagsp) |
| 932 | { |
| 933 | struct CE_state *CE_state = (struct CE_state *)copyeng; |
| 934 | int status; |
| 935 | |
Houston Hoffman | 44b7e4a | 2015-09-03 17:01:22 -0700 | [diff] [blame] | 936 | cdf_spin_lock_bh(&CE_state->ce_index_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 937 | status = |
| 938 | ce_completed_recv_next_nolock(CE_state, per_CE_contextp, |
| 939 | per_transfer_contextp, bufferp, |
| 940 | nbytesp, transfer_idp, flagsp); |
Houston Hoffman | 44b7e4a | 2015-09-03 17:01:22 -0700 | [diff] [blame] | 941 | cdf_spin_unlock_bh(&CE_state->ce_index_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 942 | |
| 943 | return status; |
| 944 | } |
| 945 | |
| 946 | /* NB: Modeled after ce_completed_recv_next_nolock */ |
| 947 | CDF_STATUS |
| 948 | ce_revoke_recv_next(struct CE_handle *copyeng, |
| 949 | void **per_CE_contextp, |
| 950 | void **per_transfer_contextp, cdf_dma_addr_t *bufferp) |
| 951 | { |
| 952 | struct CE_state *CE_state; |
| 953 | struct CE_ring_state *dest_ring; |
| 954 | unsigned int nentries_mask; |
| 955 | unsigned int sw_index; |
| 956 | unsigned int write_index; |
| 957 | CDF_STATUS status; |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 958 | struct hif_softc *scn; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 959 | |
| 960 | CE_state = (struct CE_state *)copyeng; |
| 961 | dest_ring = CE_state->dest_ring; |
| 962 | if (!dest_ring) { |
| 963 | return CDF_STATUS_E_FAILURE; |
| 964 | } |
| 965 | |
| 966 | scn = CE_state->scn; |
Houston Hoffman | 44b7e4a | 2015-09-03 17:01:22 -0700 | [diff] [blame] | 967 | cdf_spin_lock(&CE_state->ce_index_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 968 | nentries_mask = dest_ring->nentries_mask; |
| 969 | sw_index = dest_ring->sw_index; |
| 970 | write_index = dest_ring->write_index; |
| 971 | if (write_index != sw_index) { |
| 972 | struct CE_dest_desc *dest_ring_base = |
| 973 | (struct CE_dest_desc *)dest_ring-> |
| 974 | base_addr_owner_space; |
| 975 | struct CE_dest_desc *dest_desc = |
| 976 | CE_DEST_RING_TO_DESC(dest_ring_base, sw_index); |
| 977 | |
| 978 | /* Return data from completed destination descriptor */ |
| 979 | *bufferp = HIF_CE_DESC_ADDR_TO_DMA(dest_desc); |
| 980 | |
| 981 | if (per_CE_contextp) { |
| 982 | *per_CE_contextp = CE_state->recv_context; |
| 983 | } |
| 984 | |
| 985 | ce_debug_rvkrn_context = |
| 986 | dest_ring->per_transfer_context[sw_index]; |
| 987 | if (per_transfer_contextp) { |
| 988 | *per_transfer_contextp = ce_debug_rvkrn_context; |
| 989 | } |
| 990 | dest_ring->per_transfer_context[sw_index] = 0; /* sanity */ |
| 991 | |
| 992 | /* Update sw_index */ |
| 993 | sw_index = CE_RING_IDX_INCR(nentries_mask, sw_index); |
| 994 | dest_ring->sw_index = sw_index; |
| 995 | status = CDF_STATUS_SUCCESS; |
| 996 | } else { |
| 997 | status = CDF_STATUS_E_FAILURE; |
| 998 | } |
Houston Hoffman | 44b7e4a | 2015-09-03 17:01:22 -0700 | [diff] [blame] | 999 | cdf_spin_unlock(&CE_state->ce_index_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1000 | |
| 1001 | return status; |
| 1002 | } |
| 1003 | |
| 1004 | /* |
| 1005 | * Guts of ce_completed_send_next. |
| 1006 | * The caller takes responsibility for any necessary locking. |
| 1007 | */ |
| 1008 | int |
| 1009 | ce_completed_send_next_nolock(struct CE_state *CE_state, |
| 1010 | void **per_CE_contextp, |
| 1011 | void **per_transfer_contextp, |
| 1012 | cdf_dma_addr_t *bufferp, |
| 1013 | unsigned int *nbytesp, |
| 1014 | unsigned int *transfer_idp, |
| 1015 | unsigned int *sw_idx, |
| 1016 | unsigned int *hw_idx, |
| 1017 | uint32_t *toeplitz_hash_result) |
| 1018 | { |
| 1019 | int status = CDF_STATUS_E_FAILURE; |
| 1020 | struct CE_ring_state *src_ring = CE_state->src_ring; |
| 1021 | uint32_t ctrl_addr = CE_state->ctrl_addr; |
| 1022 | unsigned int nentries_mask = src_ring->nentries_mask; |
| 1023 | unsigned int sw_index = src_ring->sw_index; |
| 1024 | unsigned int read_index; |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 1025 | struct hif_softc *scn = CE_state->scn; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1026 | |
| 1027 | if (src_ring->hw_index == sw_index) { |
| 1028 | /* |
| 1029 | * The SW completion index has caught up with the cached |
| 1030 | * version of the HW completion index. |
| 1031 | * Update the cached HW completion index to see whether |
| 1032 | * the SW has really caught up to the HW, or if the cached |
| 1033 | * value of the HW index has become stale. |
| 1034 | */ |
| 1035 | A_TARGET_ACCESS_BEGIN_RET(scn); |
| 1036 | src_ring->hw_index = |
Houston Hoffman | 3d0cda8 | 2015-12-03 13:25:05 -0800 | [diff] [blame] | 1037 | CE_SRC_RING_READ_IDX_GET_FROM_DDR(scn, ctrl_addr); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1038 | A_TARGET_ACCESS_END_RET(scn); |
| 1039 | } |
| 1040 | read_index = src_ring->hw_index; |
| 1041 | |
| 1042 | if (sw_idx) |
| 1043 | *sw_idx = sw_index; |
| 1044 | |
| 1045 | if (hw_idx) |
| 1046 | *hw_idx = read_index; |
| 1047 | |
| 1048 | if ((read_index != sw_index) && (read_index != 0xffffffff)) { |
| 1049 | struct CE_src_desc *shadow_base = |
| 1050 | (struct CE_src_desc *)src_ring->shadow_base; |
| 1051 | struct CE_src_desc *shadow_src_desc = |
| 1052 | CE_SRC_RING_TO_DESC(shadow_base, sw_index); |
| 1053 | #ifdef QCA_WIFI_3_0 |
| 1054 | struct CE_src_desc *src_ring_base = |
| 1055 | (struct CE_src_desc *)src_ring->base_addr_owner_space; |
| 1056 | struct CE_src_desc *src_desc = |
| 1057 | CE_SRC_RING_TO_DESC(src_ring_base, sw_index); |
| 1058 | #endif |
Komal Seelam | bd7c51d | 2016-02-24 10:27:30 +0530 | [diff] [blame^] | 1059 | hif_record_ce_desc_event(scn, CE_state->id, |
| 1060 | HIF_TX_DESC_COMPLETION, |
Houston Hoffman | 68e837e | 2015-12-04 12:57:24 -0800 | [diff] [blame] | 1061 | (union ce_desc *) shadow_src_desc, |
| 1062 | src_ring->per_transfer_context[sw_index], |
| 1063 | sw_index); |
| 1064 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1065 | /* Return data from completed source descriptor */ |
| 1066 | *bufferp = HIF_CE_DESC_ADDR_TO_DMA(shadow_src_desc); |
| 1067 | *nbytesp = shadow_src_desc->nbytes; |
| 1068 | *transfer_idp = shadow_src_desc->meta_data; |
| 1069 | #ifdef QCA_WIFI_3_0 |
| 1070 | *toeplitz_hash_result = src_desc->toeplitz_hash_result; |
| 1071 | #else |
| 1072 | *toeplitz_hash_result = 0; |
| 1073 | #endif |
| 1074 | if (per_CE_contextp) { |
| 1075 | *per_CE_contextp = CE_state->send_context; |
| 1076 | } |
| 1077 | |
| 1078 | ce_debug_cmplsn_context = |
| 1079 | src_ring->per_transfer_context[sw_index]; |
| 1080 | if (per_transfer_contextp) { |
| 1081 | *per_transfer_contextp = ce_debug_cmplsn_context; |
| 1082 | } |
| 1083 | src_ring->per_transfer_context[sw_index] = 0; /* sanity */ |
| 1084 | |
| 1085 | /* Update sw_index */ |
| 1086 | sw_index = CE_RING_IDX_INCR(nentries_mask, sw_index); |
| 1087 | src_ring->sw_index = sw_index; |
| 1088 | status = CDF_STATUS_SUCCESS; |
| 1089 | } |
| 1090 | |
| 1091 | return status; |
| 1092 | } |
| 1093 | |
| 1094 | /* NB: Modeled after ce_completed_send_next */ |
| 1095 | CDF_STATUS |
| 1096 | ce_cancel_send_next(struct CE_handle *copyeng, |
| 1097 | void **per_CE_contextp, |
| 1098 | void **per_transfer_contextp, |
| 1099 | cdf_dma_addr_t *bufferp, |
| 1100 | unsigned int *nbytesp, |
| 1101 | unsigned int *transfer_idp, |
| 1102 | uint32_t *toeplitz_hash_result) |
| 1103 | { |
| 1104 | struct CE_state *CE_state; |
| 1105 | struct CE_ring_state *src_ring; |
| 1106 | unsigned int nentries_mask; |
| 1107 | unsigned int sw_index; |
| 1108 | unsigned int write_index; |
| 1109 | CDF_STATUS status; |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 1110 | struct hif_softc *scn; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1111 | |
| 1112 | CE_state = (struct CE_state *)copyeng; |
| 1113 | src_ring = CE_state->src_ring; |
| 1114 | if (!src_ring) { |
| 1115 | return CDF_STATUS_E_FAILURE; |
| 1116 | } |
| 1117 | |
| 1118 | scn = CE_state->scn; |
Houston Hoffman | 44b7e4a | 2015-09-03 17:01:22 -0700 | [diff] [blame] | 1119 | cdf_spin_lock(&CE_state->ce_index_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1120 | nentries_mask = src_ring->nentries_mask; |
| 1121 | sw_index = src_ring->sw_index; |
| 1122 | write_index = src_ring->write_index; |
| 1123 | |
| 1124 | if (write_index != sw_index) { |
| 1125 | struct CE_src_desc *src_ring_base = |
| 1126 | (struct CE_src_desc *)src_ring->base_addr_owner_space; |
| 1127 | struct CE_src_desc *src_desc = |
| 1128 | CE_SRC_RING_TO_DESC(src_ring_base, sw_index); |
| 1129 | |
| 1130 | /* Return data from completed source descriptor */ |
| 1131 | *bufferp = HIF_CE_DESC_ADDR_TO_DMA(src_desc); |
| 1132 | *nbytesp = src_desc->nbytes; |
| 1133 | *transfer_idp = src_desc->meta_data; |
| 1134 | #ifdef QCA_WIFI_3_0 |
| 1135 | *toeplitz_hash_result = src_desc->toeplitz_hash_result; |
| 1136 | #else |
| 1137 | *toeplitz_hash_result = 0; |
| 1138 | #endif |
| 1139 | |
| 1140 | if (per_CE_contextp) { |
| 1141 | *per_CE_contextp = CE_state->send_context; |
| 1142 | } |
| 1143 | |
| 1144 | ce_debug_cnclsn_context = |
| 1145 | src_ring->per_transfer_context[sw_index]; |
| 1146 | if (per_transfer_contextp) { |
| 1147 | *per_transfer_contextp = ce_debug_cnclsn_context; |
| 1148 | } |
| 1149 | src_ring->per_transfer_context[sw_index] = 0; /* sanity */ |
| 1150 | |
| 1151 | /* Update sw_index */ |
| 1152 | sw_index = CE_RING_IDX_INCR(nentries_mask, sw_index); |
| 1153 | src_ring->sw_index = sw_index; |
| 1154 | status = CDF_STATUS_SUCCESS; |
| 1155 | } else { |
| 1156 | status = CDF_STATUS_E_FAILURE; |
| 1157 | } |
Houston Hoffman | 44b7e4a | 2015-09-03 17:01:22 -0700 | [diff] [blame] | 1158 | cdf_spin_unlock(&CE_state->ce_index_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1159 | |
| 1160 | return status; |
| 1161 | } |
| 1162 | |
| 1163 | /* Shift bits to convert IS_*_RING_*_WATERMARK_MASK to CE_WM_FLAG_*_* */ |
| 1164 | #define CE_WM_SHFT 1 |
| 1165 | |
| 1166 | int |
| 1167 | ce_completed_send_next(struct CE_handle *copyeng, |
| 1168 | void **per_CE_contextp, |
| 1169 | void **per_transfer_contextp, |
| 1170 | cdf_dma_addr_t *bufferp, |
| 1171 | unsigned int *nbytesp, |
| 1172 | unsigned int *transfer_idp, |
| 1173 | unsigned int *sw_idx, |
| 1174 | unsigned int *hw_idx, |
| 1175 | unsigned int *toeplitz_hash_result) |
| 1176 | { |
| 1177 | struct CE_state *CE_state = (struct CE_state *)copyeng; |
| 1178 | int status; |
| 1179 | |
Houston Hoffman | 44b7e4a | 2015-09-03 17:01:22 -0700 | [diff] [blame] | 1180 | cdf_spin_lock_bh(&CE_state->ce_index_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1181 | status = |
| 1182 | ce_completed_send_next_nolock(CE_state, per_CE_contextp, |
| 1183 | per_transfer_contextp, bufferp, |
| 1184 | nbytesp, transfer_idp, sw_idx, |
| 1185 | hw_idx, toeplitz_hash_result); |
Houston Hoffman | 44b7e4a | 2015-09-03 17:01:22 -0700 | [diff] [blame] | 1186 | cdf_spin_unlock_bh(&CE_state->ce_index_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1187 | |
| 1188 | return status; |
| 1189 | } |
| 1190 | |
| 1191 | #ifdef ATH_11AC_TXCOMPACT |
| 1192 | /* CE engine descriptor reap |
| 1193 | * Similar to ce_per_engine_service , Only difference is ce_per_engine_service |
| 1194 | * does recieve and reaping of completed descriptor , |
| 1195 | * This function only handles reaping of Tx complete descriptor. |
| 1196 | * The Function is called from threshold reap poll routine |
| 1197 | * hif_send_complete_check so should not countain recieve functionality |
| 1198 | * within it . |
| 1199 | */ |
| 1200 | |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 1201 | void ce_per_engine_servicereap(struct hif_softc *scn, unsigned int ce_id) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1202 | { |
| 1203 | void *CE_context; |
| 1204 | void *transfer_context; |
| 1205 | cdf_dma_addr_t buf; |
| 1206 | unsigned int nbytes; |
| 1207 | unsigned int id; |
| 1208 | unsigned int sw_idx, hw_idx; |
| 1209 | uint32_t toeplitz_hash_result; |
Houston Hoffman | a575ec2 | 2015-12-14 16:35:15 -0800 | [diff] [blame] | 1210 | struct CE_state *CE_state = scn->ce_id_to_state[ce_id]; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1211 | |
| 1212 | A_TARGET_ACCESS_BEGIN(scn); |
Komal Seelam | bd7c51d | 2016-02-24 10:27:30 +0530 | [diff] [blame^] | 1213 | hif_record_ce_desc_event(scn, ce_id, HIF_CE_REAP_ENTRY, |
Houston Hoffman | a575ec2 | 2015-12-14 16:35:15 -0800 | [diff] [blame] | 1214 | NULL, NULL, 0); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1215 | |
| 1216 | /* Since this function is called from both user context and |
| 1217 | * tasklet context the spinlock has to lock the bottom halves. |
| 1218 | * This fix assumes that ATH_11AC_TXCOMPACT flag is always |
| 1219 | * enabled in TX polling mode. If this is not the case, more |
| 1220 | * bottom halve spin lock changes are needed. Due to data path |
| 1221 | * performance concern, after internal discussion we've decided |
| 1222 | * to make minimum change, i.e., only address the issue occured |
| 1223 | * in this function. The possible negative effect of this minimum |
| 1224 | * change is that, in the future, if some other function will also |
| 1225 | * be opened to let the user context to use, those cases need to be |
| 1226 | * addressed by change spin_lock to spin_lock_bh also. |
| 1227 | */ |
| 1228 | |
Houston Hoffman | 44b7e4a | 2015-09-03 17:01:22 -0700 | [diff] [blame] | 1229 | cdf_spin_lock_bh(&CE_state->ce_index_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1230 | |
| 1231 | if (CE_state->send_cb) { |
| 1232 | { |
| 1233 | /* Pop completed send buffers and call the |
| 1234 | * registered send callback for each |
| 1235 | */ |
| 1236 | while (ce_completed_send_next_nolock |
| 1237 | (CE_state, &CE_context, |
| 1238 | &transfer_context, &buf, |
| 1239 | &nbytes, &id, &sw_idx, &hw_idx, |
| 1240 | &toeplitz_hash_result) == |
| 1241 | CDF_STATUS_SUCCESS) { |
Houston Hoffman | a575ec2 | 2015-12-14 16:35:15 -0800 | [diff] [blame] | 1242 | if (ce_id != CE_HTT_H2T_MSG) { |
Houston Hoffman | 44b7e4a | 2015-09-03 17:01:22 -0700 | [diff] [blame] | 1243 | cdf_spin_unlock_bh( |
| 1244 | &CE_state->ce_index_lock); |
| 1245 | CE_state->send_cb( |
| 1246 | (struct CE_handle *) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1247 | CE_state, CE_context, |
| 1248 | transfer_context, buf, |
| 1249 | nbytes, id, sw_idx, hw_idx, |
| 1250 | toeplitz_hash_result); |
Houston Hoffman | 44b7e4a | 2015-09-03 17:01:22 -0700 | [diff] [blame] | 1251 | cdf_spin_lock_bh( |
| 1252 | &CE_state->ce_index_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1253 | } else { |
| 1254 | struct HIF_CE_pipe_info *pipe_info = |
| 1255 | (struct HIF_CE_pipe_info *) |
| 1256 | CE_context; |
| 1257 | |
| 1258 | cdf_spin_lock_bh(&pipe_info-> |
| 1259 | completion_freeq_lock); |
| 1260 | pipe_info->num_sends_allowed++; |
| 1261 | cdf_spin_unlock_bh(&pipe_info-> |
| 1262 | completion_freeq_lock); |
| 1263 | } |
| 1264 | } |
| 1265 | } |
| 1266 | } |
| 1267 | |
Houston Hoffman | 44b7e4a | 2015-09-03 17:01:22 -0700 | [diff] [blame] | 1268 | cdf_spin_unlock_bh(&CE_state->ce_index_lock); |
Houston Hoffman | a575ec2 | 2015-12-14 16:35:15 -0800 | [diff] [blame] | 1269 | |
Komal Seelam | bd7c51d | 2016-02-24 10:27:30 +0530 | [diff] [blame^] | 1270 | hif_record_ce_desc_event(scn, ce_id, HIF_CE_REAP_EXIT, |
Houston Hoffman | a575ec2 | 2015-12-14 16:35:15 -0800 | [diff] [blame] | 1271 | NULL, NULL, 0); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1272 | A_TARGET_ACCESS_END(scn); |
| 1273 | } |
| 1274 | |
| 1275 | #endif /*ATH_11AC_TXCOMPACT */ |
| 1276 | |
| 1277 | /* |
| 1278 | * Number of times to check for any pending tx/rx completion on |
| 1279 | * a copy engine, this count should be big enough. Once we hit |
| 1280 | * this threashold we'll not check for any Tx/Rx comlpetion in same |
| 1281 | * interrupt handling. Note that this threashold is only used for |
| 1282 | * Rx interrupt processing, this can be used tor Tx as well if we |
| 1283 | * suspect any infinite loop in checking for pending Tx completion. |
| 1284 | */ |
| 1285 | #define CE_TXRX_COMP_CHECK_THRESHOLD 20 |
| 1286 | |
| 1287 | /* |
| 1288 | * Guts of interrupt handler for per-engine interrupts on a particular CE. |
| 1289 | * |
| 1290 | * Invokes registered callbacks for recv_complete, |
| 1291 | * send_complete, and watermarks. |
| 1292 | * |
| 1293 | * Returns: number of messages processed |
| 1294 | */ |
| 1295 | |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 1296 | int ce_per_engine_service(struct hif_softc *scn, unsigned int CE_id) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1297 | { |
| 1298 | struct CE_state *CE_state = scn->ce_id_to_state[CE_id]; |
| 1299 | uint32_t ctrl_addr = CE_state->ctrl_addr; |
| 1300 | void *CE_context; |
| 1301 | void *transfer_context; |
| 1302 | cdf_dma_addr_t buf; |
| 1303 | unsigned int nbytes; |
| 1304 | unsigned int id; |
| 1305 | unsigned int flags; |
| 1306 | uint32_t CE_int_status; |
| 1307 | unsigned int more_comp_cnt = 0; |
| 1308 | unsigned int more_snd_comp_cnt = 0; |
| 1309 | unsigned int sw_idx, hw_idx; |
| 1310 | uint32_t toeplitz_hash_result; |
Komal Seelam | bd7c51d | 2016-02-24 10:27:30 +0530 | [diff] [blame^] | 1311 | uint32_t mode = hif_get_conparam(scn); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1312 | |
| 1313 | if (Q_TARGET_ACCESS_BEGIN(scn) < 0) { |
| 1314 | HIF_ERROR("[premature rc=0]\n"); |
| 1315 | return 0; /* no work done */ |
| 1316 | } |
| 1317 | |
Houston Hoffman | 44b7e4a | 2015-09-03 17:01:22 -0700 | [diff] [blame] | 1318 | cdf_spin_lock(&CE_state->ce_index_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1319 | |
| 1320 | /* Clear force_break flag and re-initialize receive_count to 0 */ |
| 1321 | |
| 1322 | /* NAPI: scn variables- thread/multi-processing safety? */ |
Houston Hoffman | 5bf441a | 2015-09-02 11:52:10 -0700 | [diff] [blame] | 1323 | CE_state->receive_count = 0; |
Houston Hoffman | 18c7fc5 | 2015-09-02 11:44:42 -0700 | [diff] [blame] | 1324 | CE_state->force_break = 0; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1325 | more_completions: |
| 1326 | if (CE_state->recv_cb) { |
| 1327 | |
| 1328 | /* Pop completed recv buffers and call |
| 1329 | * the registered recv callback for each |
| 1330 | */ |
| 1331 | while (ce_completed_recv_next_nolock |
| 1332 | (CE_state, &CE_context, &transfer_context, |
| 1333 | &buf, &nbytes, &id, &flags) == |
| 1334 | CDF_STATUS_SUCCESS) { |
Houston Hoffman | 44b7e4a | 2015-09-03 17:01:22 -0700 | [diff] [blame] | 1335 | cdf_spin_unlock(&CE_state->ce_index_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1336 | CE_state->recv_cb((struct CE_handle *)CE_state, |
| 1337 | CE_context, transfer_context, buf, |
| 1338 | nbytes, id, flags); |
| 1339 | |
| 1340 | /* |
| 1341 | * EV #112693 - |
| 1342 | * [Peregrine][ES1][WB342][Win8x86][Performance] |
| 1343 | * BSoD_0x133 occurred in VHT80 UDP_DL |
| 1344 | * Break out DPC by force if number of loops in |
| 1345 | * hif_pci_ce_recv_data reaches MAX_NUM_OF_RECEIVES |
| 1346 | * to avoid spending too long time in |
| 1347 | * DPC for each interrupt handling. Schedule another |
| 1348 | * DPC to avoid data loss if we had taken |
| 1349 | * force-break action before apply to Windows OS |
| 1350 | * only currently, Linux/MAC os can expand to their |
| 1351 | * platform if necessary |
| 1352 | */ |
| 1353 | |
| 1354 | /* Break the receive processes by |
| 1355 | * force if force_break set up |
| 1356 | */ |
Houston Hoffman | 18c7fc5 | 2015-09-02 11:44:42 -0700 | [diff] [blame] | 1357 | if (cdf_unlikely(CE_state->force_break)) { |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1358 | cdf_atomic_set(&CE_state->rx_pending, 1); |
| 1359 | CE_ENGINE_INT_STATUS_CLEAR(scn, ctrl_addr, |
| 1360 | HOST_IS_COPY_COMPLETE_MASK); |
| 1361 | if (Q_TARGET_ACCESS_END(scn) < 0) |
| 1362 | HIF_ERROR("<--[premature rc=%d]\n", |
Houston Hoffman | 5bf441a | 2015-09-02 11:52:10 -0700 | [diff] [blame] | 1363 | CE_state->receive_count); |
| 1364 | return CE_state->receive_count; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1365 | } |
Houston Hoffman | 44b7e4a | 2015-09-03 17:01:22 -0700 | [diff] [blame] | 1366 | cdf_spin_lock(&CE_state->ce_index_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1367 | } |
| 1368 | } |
| 1369 | |
| 1370 | /* |
| 1371 | * Attention: We may experience potential infinite loop for below |
| 1372 | * While Loop during Sending Stress test. |
| 1373 | * Resolve the same way as Receive Case (Refer to EV #112693) |
| 1374 | */ |
| 1375 | |
| 1376 | if (CE_state->send_cb) { |
| 1377 | /* Pop completed send buffers and call |
| 1378 | * the registered send callback for each |
| 1379 | */ |
| 1380 | |
| 1381 | #ifdef ATH_11AC_TXCOMPACT |
| 1382 | while (ce_completed_send_next_nolock |
| 1383 | (CE_state, &CE_context, |
| 1384 | &transfer_context, &buf, &nbytes, |
| 1385 | &id, &sw_idx, &hw_idx, |
| 1386 | &toeplitz_hash_result) == CDF_STATUS_SUCCESS) { |
| 1387 | |
| 1388 | if (CE_id != CE_HTT_H2T_MSG || |
Komal Seelam | bd7c51d | 2016-02-24 10:27:30 +0530 | [diff] [blame^] | 1389 | WLAN_IS_EPPING_ENABLED(mode)) { |
Houston Hoffman | 44b7e4a | 2015-09-03 17:01:22 -0700 | [diff] [blame] | 1390 | cdf_spin_unlock(&CE_state->ce_index_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1391 | CE_state->send_cb((struct CE_handle *)CE_state, |
| 1392 | CE_context, transfer_context, |
| 1393 | buf, nbytes, id, sw_idx, |
| 1394 | hw_idx, toeplitz_hash_result); |
Houston Hoffman | 44b7e4a | 2015-09-03 17:01:22 -0700 | [diff] [blame] | 1395 | cdf_spin_lock(&CE_state->ce_index_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1396 | } else { |
| 1397 | struct HIF_CE_pipe_info *pipe_info = |
| 1398 | (struct HIF_CE_pipe_info *)CE_context; |
| 1399 | |
| 1400 | cdf_spin_lock(&pipe_info-> |
| 1401 | completion_freeq_lock); |
| 1402 | pipe_info->num_sends_allowed++; |
| 1403 | cdf_spin_unlock(&pipe_info-> |
| 1404 | completion_freeq_lock); |
| 1405 | } |
| 1406 | } |
| 1407 | #else /*ATH_11AC_TXCOMPACT */ |
| 1408 | while (ce_completed_send_next_nolock |
| 1409 | (CE_state, &CE_context, |
| 1410 | &transfer_context, &buf, &nbytes, |
| 1411 | &id, &sw_idx, &hw_idx, |
| 1412 | &toeplitz_hash_result) == CDF_STATUS_SUCCESS) { |
Houston Hoffman | 44b7e4a | 2015-09-03 17:01:22 -0700 | [diff] [blame] | 1413 | cdf_spin_unlock(&CE_state->ce_index_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1414 | CE_state->send_cb((struct CE_handle *)CE_state, |
| 1415 | CE_context, transfer_context, buf, |
| 1416 | nbytes, id, sw_idx, hw_idx, |
| 1417 | toeplitz_hash_result); |
Houston Hoffman | 44b7e4a | 2015-09-03 17:01:22 -0700 | [diff] [blame] | 1418 | cdf_spin_lock(&CE_state->ce_index_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1419 | } |
| 1420 | #endif /*ATH_11AC_TXCOMPACT */ |
| 1421 | } |
| 1422 | |
| 1423 | more_watermarks: |
| 1424 | if (CE_state->misc_cbs) { |
| 1425 | CE_int_status = CE_ENGINE_INT_STATUS_GET(scn, ctrl_addr); |
| 1426 | if (CE_int_status & CE_WATERMARK_MASK) { |
| 1427 | if (CE_state->watermark_cb) { |
Houston Hoffman | 44b7e4a | 2015-09-03 17:01:22 -0700 | [diff] [blame] | 1428 | cdf_spin_unlock(&CE_state->ce_index_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1429 | /* Convert HW IS bits to software flags */ |
| 1430 | flags = |
| 1431 | (CE_int_status & CE_WATERMARK_MASK) >> |
| 1432 | CE_WM_SHFT; |
| 1433 | |
| 1434 | CE_state-> |
| 1435 | watermark_cb((struct CE_handle *)CE_state, |
| 1436 | CE_state->wm_context, flags); |
Houston Hoffman | 44b7e4a | 2015-09-03 17:01:22 -0700 | [diff] [blame] | 1437 | cdf_spin_lock(&CE_state->ce_index_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1438 | } |
| 1439 | } |
| 1440 | } |
| 1441 | |
| 1442 | /* |
| 1443 | * Clear the misc interrupts (watermark) that were handled above, |
| 1444 | * and that will be checked again below. |
| 1445 | * Clear and check for copy-complete interrupts again, just in case |
| 1446 | * more copy completions happened while the misc interrupts were being |
| 1447 | * handled. |
| 1448 | */ |
| 1449 | CE_ENGINE_INT_STATUS_CLEAR(scn, ctrl_addr, |
| 1450 | CE_WATERMARK_MASK | |
| 1451 | HOST_IS_COPY_COMPLETE_MASK); |
| 1452 | |
| 1453 | /* |
| 1454 | * Now that per-engine interrupts are cleared, verify that |
| 1455 | * no recv interrupts arrive while processing send interrupts, |
| 1456 | * and no recv or send interrupts happened while processing |
| 1457 | * misc interrupts.Go back and check again.Keep checking until |
| 1458 | * we find no more events to process. |
| 1459 | */ |
| 1460 | if (CE_state->recv_cb && ce_recv_entries_done_nolock(scn, CE_state)) { |
Komal Seelam | bd7c51d | 2016-02-24 10:27:30 +0530 | [diff] [blame^] | 1461 | if (WLAN_IS_EPPING_ENABLED(mode) || |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1462 | more_comp_cnt++ < CE_TXRX_COMP_CHECK_THRESHOLD) { |
| 1463 | goto more_completions; |
| 1464 | } else { |
| 1465 | HIF_ERROR( |
| 1466 | "%s:Potential infinite loop detected during Rx processing nentries_mask:0x%x sw read_idx:0x%x hw read_idx:0x%x", |
| 1467 | __func__, CE_state->dest_ring->nentries_mask, |
| 1468 | CE_state->dest_ring->sw_index, |
| 1469 | CE_DEST_RING_READ_IDX_GET(scn, |
| 1470 | CE_state->ctrl_addr)); |
| 1471 | } |
| 1472 | } |
| 1473 | |
| 1474 | if (CE_state->send_cb && ce_send_entries_done_nolock(scn, CE_state)) { |
Komal Seelam | bd7c51d | 2016-02-24 10:27:30 +0530 | [diff] [blame^] | 1475 | if (WLAN_IS_EPPING_ENABLED(mode) || |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1476 | more_snd_comp_cnt++ < CE_TXRX_COMP_CHECK_THRESHOLD) { |
| 1477 | goto more_completions; |
| 1478 | } else { |
| 1479 | HIF_ERROR( |
| 1480 | "%s:Potential infinite loop detected during send completion nentries_mask:0x%x sw read_idx:0x%x hw read_idx:0x%x", |
| 1481 | __func__, CE_state->src_ring->nentries_mask, |
| 1482 | CE_state->src_ring->sw_index, |
| 1483 | CE_SRC_RING_READ_IDX_GET(scn, |
| 1484 | CE_state->ctrl_addr)); |
| 1485 | } |
| 1486 | } |
| 1487 | |
| 1488 | if (CE_state->misc_cbs) { |
| 1489 | CE_int_status = CE_ENGINE_INT_STATUS_GET(scn, ctrl_addr); |
| 1490 | if (CE_int_status & CE_WATERMARK_MASK) { |
| 1491 | if (CE_state->watermark_cb) { |
| 1492 | goto more_watermarks; |
| 1493 | } |
| 1494 | } |
| 1495 | } |
| 1496 | |
Houston Hoffman | 44b7e4a | 2015-09-03 17:01:22 -0700 | [diff] [blame] | 1497 | cdf_spin_unlock(&CE_state->ce_index_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1498 | cdf_atomic_set(&CE_state->rx_pending, 0); |
| 1499 | |
| 1500 | if (Q_TARGET_ACCESS_END(scn) < 0) |
Houston Hoffman | 5bf441a | 2015-09-02 11:52:10 -0700 | [diff] [blame] | 1501 | HIF_ERROR("<--[premature rc=%d]\n", CE_state->receive_count); |
| 1502 | return CE_state->receive_count; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1503 | } |
| 1504 | |
| 1505 | /* |
| 1506 | * Handler for per-engine interrupts on ALL active CEs. |
| 1507 | * This is used in cases where the system is sharing a |
| 1508 | * single interrput for all CEs |
| 1509 | */ |
| 1510 | |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 1511 | void ce_per_engine_service_any(int irq, struct hif_softc *scn) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1512 | { |
| 1513 | int CE_id; |
| 1514 | uint32_t intr_summary; |
| 1515 | |
| 1516 | A_TARGET_ACCESS_BEGIN(scn); |
| 1517 | if (!cdf_atomic_read(&scn->tasklet_from_intr)) { |
| 1518 | for (CE_id = 0; CE_id < scn->ce_count; CE_id++) { |
| 1519 | struct CE_state *CE_state = scn->ce_id_to_state[CE_id]; |
| 1520 | if (cdf_atomic_read(&CE_state->rx_pending)) { |
| 1521 | cdf_atomic_set(&CE_state->rx_pending, 0); |
| 1522 | ce_per_engine_service(scn, CE_id); |
| 1523 | } |
| 1524 | } |
| 1525 | |
| 1526 | A_TARGET_ACCESS_END(scn); |
| 1527 | return; |
| 1528 | } |
| 1529 | |
| 1530 | intr_summary = CE_INTERRUPT_SUMMARY(scn); |
| 1531 | |
| 1532 | for (CE_id = 0; intr_summary && (CE_id < scn->ce_count); CE_id++) { |
| 1533 | if (intr_summary & (1 << CE_id)) { |
| 1534 | intr_summary &= ~(1 << CE_id); |
| 1535 | } else { |
| 1536 | continue; /* no intr pending on this CE */ |
| 1537 | } |
| 1538 | |
| 1539 | ce_per_engine_service(scn, CE_id); |
| 1540 | } |
| 1541 | |
| 1542 | A_TARGET_ACCESS_END(scn); |
| 1543 | } |
| 1544 | |
| 1545 | /* |
| 1546 | * Adjust interrupts for the copy complete handler. |
| 1547 | * If it's needed for either send or recv, then unmask |
| 1548 | * this interrupt; otherwise, mask it. |
| 1549 | * |
| 1550 | * Called with target_lock held. |
| 1551 | */ |
| 1552 | static void |
| 1553 | ce_per_engine_handler_adjust(struct CE_state *CE_state, |
| 1554 | int disable_copy_compl_intr) |
| 1555 | { |
| 1556 | uint32_t ctrl_addr = CE_state->ctrl_addr; |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 1557 | struct hif_softc *scn = CE_state->scn; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1558 | |
| 1559 | CE_state->disable_copy_compl_intr = disable_copy_compl_intr; |
| 1560 | A_TARGET_ACCESS_BEGIN(scn); |
| 1561 | if ((!disable_copy_compl_intr) && |
| 1562 | (CE_state->send_cb || CE_state->recv_cb)) { |
| 1563 | CE_COPY_COMPLETE_INTR_ENABLE(scn, ctrl_addr); |
| 1564 | } else { |
| 1565 | CE_COPY_COMPLETE_INTR_DISABLE(scn, ctrl_addr); |
| 1566 | } |
| 1567 | |
| 1568 | if (CE_state->watermark_cb) { |
| 1569 | CE_WATERMARK_INTR_ENABLE(scn, ctrl_addr); |
| 1570 | } else { |
| 1571 | CE_WATERMARK_INTR_DISABLE(scn, ctrl_addr); |
| 1572 | } |
| 1573 | A_TARGET_ACCESS_END(scn); |
| 1574 | |
| 1575 | } |
| 1576 | |
| 1577 | /*Iterate the CE_state list and disable the compl interrupt |
| 1578 | * if it has been registered already. |
| 1579 | */ |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 1580 | void ce_disable_any_copy_compl_intr_nolock(struct hif_softc *scn) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1581 | { |
| 1582 | int CE_id; |
| 1583 | |
| 1584 | A_TARGET_ACCESS_BEGIN(scn); |
| 1585 | for (CE_id = 0; CE_id < scn->ce_count; CE_id++) { |
| 1586 | struct CE_state *CE_state = scn->ce_id_to_state[CE_id]; |
| 1587 | uint32_t ctrl_addr = CE_state->ctrl_addr; |
| 1588 | |
| 1589 | /* if the interrupt is currently enabled, disable it */ |
| 1590 | if (!CE_state->disable_copy_compl_intr |
| 1591 | && (CE_state->send_cb || CE_state->recv_cb)) { |
| 1592 | CE_COPY_COMPLETE_INTR_DISABLE(scn, ctrl_addr); |
| 1593 | } |
| 1594 | |
| 1595 | if (CE_state->watermark_cb) { |
| 1596 | CE_WATERMARK_INTR_DISABLE(scn, ctrl_addr); |
| 1597 | } |
| 1598 | } |
| 1599 | A_TARGET_ACCESS_END(scn); |
| 1600 | } |
| 1601 | |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 1602 | void ce_enable_any_copy_compl_intr_nolock(struct hif_softc *scn) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1603 | { |
| 1604 | int CE_id; |
| 1605 | |
| 1606 | A_TARGET_ACCESS_BEGIN(scn); |
| 1607 | for (CE_id = 0; CE_id < scn->ce_count; CE_id++) { |
| 1608 | struct CE_state *CE_state = scn->ce_id_to_state[CE_id]; |
| 1609 | uint32_t ctrl_addr = CE_state->ctrl_addr; |
| 1610 | |
| 1611 | /* |
| 1612 | * If the CE is supposed to have copy complete interrupts |
| 1613 | * enabled (i.e. there a callback registered, and the |
| 1614 | * "disable" flag is not set), then re-enable the interrupt. |
| 1615 | */ |
| 1616 | if (!CE_state->disable_copy_compl_intr |
| 1617 | && (CE_state->send_cb || CE_state->recv_cb)) { |
| 1618 | CE_COPY_COMPLETE_INTR_ENABLE(scn, ctrl_addr); |
| 1619 | } |
| 1620 | |
| 1621 | if (CE_state->watermark_cb) { |
| 1622 | CE_WATERMARK_INTR_ENABLE(scn, ctrl_addr); |
| 1623 | } |
| 1624 | } |
| 1625 | A_TARGET_ACCESS_END(scn); |
| 1626 | } |
| 1627 | |
Houston Hoffman | a837c9a | 2015-09-03 12:47:01 -0700 | [diff] [blame] | 1628 | /** |
| 1629 | * ce_send_cb_register(): register completion handler |
| 1630 | * @copyeng: CE_state representing the ce we are adding the behavior to |
| 1631 | * @fn_ptr: callback that the ce should use when processing tx completions |
| 1632 | * @disable_interrupts: if the interupts should be enabled or not. |
| 1633 | * |
| 1634 | * Caller should guarantee that no transactions are in progress before |
| 1635 | * switching the callback function. |
| 1636 | * |
| 1637 | * Registers the send context before the fn pointer so that if the cb is valid |
| 1638 | * the context should be valid. |
| 1639 | * |
| 1640 | * Beware that currently this function will enable completion interrupts. |
| 1641 | */ |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1642 | void |
| 1643 | ce_send_cb_register(struct CE_handle *copyeng, |
| 1644 | ce_send_cb fn_ptr, |
| 1645 | void *ce_send_context, int disable_interrupts) |
| 1646 | { |
| 1647 | struct CE_state *CE_state = (struct CE_state *)copyeng; |
| 1648 | |
Sanjay Devnani | 9ce1577 | 2015-11-12 14:08:57 -0800 | [diff] [blame] | 1649 | if (CE_state == NULL) { |
| 1650 | pr_err("%s: Error CE state = NULL\n", __func__); |
| 1651 | return; |
| 1652 | } |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1653 | CE_state->send_context = ce_send_context; |
Houston Hoffman | a837c9a | 2015-09-03 12:47:01 -0700 | [diff] [blame] | 1654 | CE_state->send_cb = fn_ptr; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1655 | ce_per_engine_handler_adjust(CE_state, disable_interrupts); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1656 | } |
| 1657 | |
Houston Hoffman | a837c9a | 2015-09-03 12:47:01 -0700 | [diff] [blame] | 1658 | /** |
| 1659 | * ce_recv_cb_register(): register completion handler |
| 1660 | * @copyeng: CE_state representing the ce we are adding the behavior to |
| 1661 | * @fn_ptr: callback that the ce should use when processing rx completions |
| 1662 | * @disable_interrupts: if the interupts should be enabled or not. |
| 1663 | * |
| 1664 | * Registers the send context before the fn pointer so that if the cb is valid |
| 1665 | * the context should be valid. |
| 1666 | * |
| 1667 | * Caller should guarantee that no transactions are in progress before |
| 1668 | * switching the callback function. |
| 1669 | */ |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1670 | void |
| 1671 | ce_recv_cb_register(struct CE_handle *copyeng, |
| 1672 | CE_recv_cb fn_ptr, |
| 1673 | void *CE_recv_context, int disable_interrupts) |
| 1674 | { |
| 1675 | struct CE_state *CE_state = (struct CE_state *)copyeng; |
| 1676 | |
Sanjay Devnani | 9ce1577 | 2015-11-12 14:08:57 -0800 | [diff] [blame] | 1677 | if (CE_state == NULL) { |
| 1678 | pr_err("%s: ERROR CE state = NULL\n", __func__); |
| 1679 | return; |
| 1680 | } |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1681 | CE_state->recv_context = CE_recv_context; |
Houston Hoffman | a837c9a | 2015-09-03 12:47:01 -0700 | [diff] [blame] | 1682 | CE_state->recv_cb = fn_ptr; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1683 | ce_per_engine_handler_adjust(CE_state, disable_interrupts); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1684 | } |
| 1685 | |
Houston Hoffman | a837c9a | 2015-09-03 12:47:01 -0700 | [diff] [blame] | 1686 | /** |
| 1687 | * ce_watermark_cb_register(): register completion handler |
| 1688 | * @copyeng: CE_state representing the ce we are adding the behavior to |
| 1689 | * @fn_ptr: callback that the ce should use when processing watermark events |
| 1690 | * |
| 1691 | * Caller should guarantee that no watermark events are being processed before |
| 1692 | * switching the callback function. |
| 1693 | */ |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1694 | void |
| 1695 | ce_watermark_cb_register(struct CE_handle *copyeng, |
| 1696 | CE_watermark_cb fn_ptr, void *CE_wm_context) |
| 1697 | { |
| 1698 | struct CE_state *CE_state = (struct CE_state *)copyeng; |
| 1699 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1700 | CE_state->watermark_cb = fn_ptr; |
| 1701 | CE_state->wm_context = CE_wm_context; |
| 1702 | ce_per_engine_handler_adjust(CE_state, 0); |
| 1703 | if (fn_ptr) { |
| 1704 | CE_state->misc_cbs = 1; |
| 1705 | } |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1706 | } |
| 1707 | |
| 1708 | #ifdef WLAN_FEATURE_FASTPATH |
| 1709 | /** |
| 1710 | * ce_pkt_dl_len_set() set the HTT packet download length |
| 1711 | * @hif_sc: HIF context |
| 1712 | * @pkt_download_len: download length |
| 1713 | * |
| 1714 | * Return: None |
| 1715 | */ |
| 1716 | void ce_pkt_dl_len_set(void *hif_sc, u_int32_t pkt_download_len) |
| 1717 | { |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 1718 | struct hif_softc *sc = (struct hif_softc *)(hif_sc); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1719 | struct CE_state *ce_state = sc->ce_id_to_state[CE_HTT_H2T_MSG]; |
| 1720 | |
| 1721 | cdf_assert_always(ce_state); |
| 1722 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1723 | ce_state->download_len = pkt_download_len; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1724 | |
| 1725 | cdf_print("%s CE %d Pkt download length %d\n", __func__, |
| 1726 | ce_state->id, ce_state->download_len); |
| 1727 | } |
| 1728 | #else |
| 1729 | void ce_pkt_dl_len_set(void *hif_sc, u_int32_t pkt_download_len) |
| 1730 | { |
| 1731 | } |
| 1732 | #endif /* WLAN_FEATURE_FASTPATH */ |
| 1733 | |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 1734 | bool ce_get_rx_pending(struct hif_softc *scn) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1735 | { |
| 1736 | int CE_id; |
| 1737 | |
| 1738 | for (CE_id = 0; CE_id < scn->ce_count; CE_id++) { |
| 1739 | struct CE_state *CE_state = scn->ce_id_to_state[CE_id]; |
| 1740 | if (cdf_atomic_read(&CE_state->rx_pending)) |
| 1741 | return true; |
| 1742 | } |
| 1743 | |
| 1744 | return false; |
| 1745 | } |
| 1746 | |
| 1747 | /** |
| 1748 | * ce_check_rx_pending() - ce_check_rx_pending |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 1749 | * @scn: hif_softc |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1750 | * @ce_id: ce_id |
| 1751 | * |
| 1752 | * Return: bool |
| 1753 | */ |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 1754 | bool ce_check_rx_pending(struct hif_softc *scn, int ce_id) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1755 | { |
| 1756 | struct CE_state *CE_state = scn->ce_id_to_state[ce_id]; |
| 1757 | if (cdf_atomic_read(&CE_state->rx_pending)) |
| 1758 | return true; |
| 1759 | else |
| 1760 | return false; |
| 1761 | } |
Houston Hoffman | 8ed92e5 | 2015-09-02 14:49:48 -0700 | [diff] [blame] | 1762 | |
| 1763 | /** |
| 1764 | * ce_enable_msi(): write the msi configuration to the target |
| 1765 | * @scn: hif context |
| 1766 | * @CE_id: which copy engine will be configured for msi interupts |
| 1767 | * @msi_addr_lo: Hardware will write to this address to generate an interrupt |
| 1768 | * @msi_addr_hi: Hardware will write to this address to generate an interrupt |
| 1769 | * @msi_data: Hardware will write this data to generate an interrupt |
| 1770 | * |
| 1771 | * should be done in the initialization sequence so no locking would be needed |
| 1772 | */ |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 1773 | void ce_enable_msi(struct hif_softc *scn, unsigned int CE_id, |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1774 | uint32_t msi_addr_lo, uint32_t msi_addr_hi, |
| 1775 | uint32_t msi_data) |
| 1776 | { |
| 1777 | #ifdef WLAN_ENABLE_QCA6180 |
| 1778 | struct CE_state *CE_state; |
| 1779 | A_target_id_t targid; |
| 1780 | u_int32_t ctrl_addr; |
| 1781 | uint32_t tmp; |
| 1782 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1783 | CE_state = scn->ce_id_to_state[CE_id]; |
| 1784 | if (!CE_state) { |
| 1785 | HIF_ERROR("%s: error - CE_state = NULL", __func__); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1786 | return; |
| 1787 | } |
| 1788 | targid = TARGID(sc); |
| 1789 | ctrl_addr = CE_state->ctrl_addr; |
| 1790 | CE_MSI_ADDR_LOW_SET(scn, ctrl_addr, msi_addr_lo); |
| 1791 | CE_MSI_ADDR_HIGH_SET(scn, ctrl_addr, msi_addr_hi); |
| 1792 | CE_MSI_DATA_SET(scn, ctrl_addr, msi_data); |
| 1793 | tmp = CE_CTRL_REGISTER1_GET(scn, ctrl_addr); |
| 1794 | tmp |= (1 << CE_MSI_ENABLE_BIT); |
| 1795 | CE_CTRL_REGISTER1_SET(scn, ctrl_addr, tmp); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1796 | #endif |
| 1797 | } |
| 1798 | |
| 1799 | #ifdef IPA_OFFLOAD |
Leo Chang | d85f78d | 2015-11-13 10:55:34 -0800 | [diff] [blame] | 1800 | /** |
| 1801 | * ce_ipa_get_resource() - get uc resource on copyengine |
| 1802 | * @ce: copyengine context |
| 1803 | * @ce_sr_base_paddr: copyengine source ring base physical address |
| 1804 | * @ce_sr_ring_size: copyengine source ring size |
| 1805 | * @ce_reg_paddr: copyengine register physical address |
| 1806 | * |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1807 | * Copy engine should release resource to micro controller |
| 1808 | * Micro controller needs |
Leo Chang | d85f78d | 2015-11-13 10:55:34 -0800 | [diff] [blame] | 1809 | * - Copy engine source descriptor base address |
| 1810 | * - Copy engine source descriptor size |
| 1811 | * - PCI BAR address to access copy engine regiser |
| 1812 | * |
| 1813 | * Return: None |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1814 | */ |
| 1815 | void ce_ipa_get_resource(struct CE_handle *ce, |
Leo Chang | d85f78d | 2015-11-13 10:55:34 -0800 | [diff] [blame] | 1816 | cdf_dma_addr_t *ce_sr_base_paddr, |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1817 | uint32_t *ce_sr_ring_size, |
| 1818 | cdf_dma_addr_t *ce_reg_paddr) |
| 1819 | { |
| 1820 | struct CE_state *CE_state = (struct CE_state *)ce; |
| 1821 | uint32_t ring_loop; |
| 1822 | struct CE_src_desc *ce_desc; |
| 1823 | cdf_dma_addr_t phy_mem_base; |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 1824 | struct hif_softc *scn = CE_state->scn; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1825 | |
| 1826 | if (CE_RUNNING != CE_state->state) { |
| 1827 | *ce_sr_base_paddr = 0; |
| 1828 | *ce_sr_ring_size = 0; |
| 1829 | return; |
| 1830 | } |
| 1831 | |
| 1832 | /* Update default value for descriptor */ |
| 1833 | for (ring_loop = 0; ring_loop < CE_state->src_ring->nentries; |
| 1834 | ring_loop++) { |
| 1835 | ce_desc = (struct CE_src_desc *) |
| 1836 | ((char *)CE_state->src_ring->base_addr_owner_space + |
| 1837 | ring_loop * (sizeof(struct CE_src_desc))); |
| 1838 | CE_IPA_RING_INIT(ce_desc); |
| 1839 | } |
| 1840 | |
| 1841 | /* Get BAR address */ |
| 1842 | hif_read_phy_mem_base(CE_state->scn, &phy_mem_base); |
| 1843 | |
Leo Chang | d85f78d | 2015-11-13 10:55:34 -0800 | [diff] [blame] | 1844 | *ce_sr_base_paddr = CE_state->src_ring->base_addr_CE_space; |
| 1845 | *ce_sr_ring_size = (uint32_t) (CE_state->src_ring->nentries * |
| 1846 | sizeof(struct CE_src_desc)); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1847 | *ce_reg_paddr = phy_mem_base + CE_BASE_ADDRESS(CE_state->id) + |
| 1848 | SR_WR_INDEX_ADDRESS; |
| 1849 | return; |
| 1850 | } |
| 1851 | #endif /* IPA_OFFLOAD */ |
| 1852 | |