Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 1 | /* |
Jeff Johnson | 0571813 | 2016-12-17 10:18:17 -0800 | [diff] [blame] | 2 | * Copyright (c) 2016-2017 The Linux Foundation. All rights reserved. |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 3 | * |
| 4 | * Permission to use, copy, modify, and/or distribute this software for |
| 5 | * any purpose with or without fee is hereby granted, provided that the |
| 6 | * above copyright notice and this permission notice appear in all |
| 7 | * copies. |
| 8 | * |
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL |
| 10 | * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED |
| 11 | * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE |
| 12 | * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL |
| 13 | * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
| 14 | * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 15 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 16 | * PERFORMANCE OF THIS SOFTWARE. |
| 17 | */ |
| 18 | |
| 19 | #include "hif.h" |
| 20 | #include "hif_io32.h" |
| 21 | #include "reg_struct.h" |
| 22 | #include "ce_api.h" |
| 23 | #include "ce_main.h" |
| 24 | #include "ce_internal.h" |
| 25 | #include "ce_reg.h" |
| 26 | #include "qdf_lock.h" |
| 27 | #include "regtable.h" |
| 28 | #include "hif_main.h" |
| 29 | #include "hif_debug.h" |
| 30 | #include "hal_api.h" |
Houston Hoffman | 1501077 | 2016-09-16 14:01:13 -0700 | [diff] [blame] | 31 | #include "pld_common.h" |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 32 | |
| 33 | /* |
| 34 | * Support for Copy Engine hardware, which is mainly used for |
| 35 | * communication between Host and Target over a PCIe interconnect. |
| 36 | */ |
| 37 | |
| 38 | /* |
| 39 | * A single CopyEngine (CE) comprises two "rings": |
| 40 | * a source ring |
| 41 | * a destination ring |
| 42 | * |
| 43 | * Each ring consists of a number of descriptors which specify |
| 44 | * an address, length, and meta-data. |
| 45 | * |
| 46 | * Typically, one side of the PCIe interconnect (Host or Target) |
| 47 | * controls one ring and the other side controls the other ring. |
| 48 | * The source side chooses when to initiate a transfer and it |
| 49 | * chooses what to send (buffer address, length). The destination |
| 50 | * side keeps a supply of "anonymous receive buffers" available and |
| 51 | * it handles incoming data as it arrives (when the destination |
| 52 | * receives an interrupt). |
| 53 | * |
| 54 | * The sender may send a simple buffer (address/length) or it may |
| 55 | * send a small list of buffers. When a small list is sent, hardware |
| 56 | * "gathers" these and they end up in a single destination buffer |
| 57 | * with a single interrupt. |
| 58 | * |
| 59 | * There are several "contexts" managed by this layer -- more, it |
| 60 | * may seem -- than should be needed. These are provided mainly for |
| 61 | * maximum flexibility and especially to facilitate a simpler HIF |
| 62 | * implementation. There are per-CopyEngine recv, send, and watermark |
| 63 | * contexts. These are supplied by the caller when a recv, send, |
| 64 | * or watermark handler is established and they are echoed back to |
| 65 | * the caller when the respective callbacks are invoked. There is |
| 66 | * also a per-transfer context supplied by the caller when a buffer |
| 67 | * (or sendlist) is sent and when a buffer is enqueued for recv. |
| 68 | * These per-transfer contexts are echoed back to the caller when |
| 69 | * the buffer is sent/received. |
| 70 | * Target TX harsh result toeplitz_hash_result |
| 71 | */ |
| 72 | |
| 73 | #define CE_ADDR_COPY(desc, dma_addr) do {\ |
| 74 | (desc)->buffer_addr_lo = (uint32_t)((dma_addr) &\ |
| 75 | 0xFFFFFFFF);\ |
| 76 | (desc)->buffer_addr_hi =\ |
| 77 | (uint32_t)(((dma_addr) >> 32) & 0xFF);\ |
| 78 | } while (0) |
| 79 | |
Jeff Johnson | 0571813 | 2016-12-17 10:18:17 -0800 | [diff] [blame] | 80 | static int |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 81 | ce_send_nolock_srng(struct CE_handle *copyeng, |
| 82 | void *per_transfer_context, |
| 83 | qdf_dma_addr_t buffer, |
| 84 | uint32_t nbytes, |
| 85 | uint32_t transfer_id, |
| 86 | uint32_t flags, |
| 87 | uint32_t user_flags) |
| 88 | { |
| 89 | int status; |
| 90 | struct CE_state *CE_state = (struct CE_state *)copyeng; |
| 91 | struct CE_ring_state *src_ring = CE_state->src_ring; |
| 92 | unsigned int nentries_mask = src_ring->nentries_mask; |
| 93 | unsigned int write_index = src_ring->write_index; |
| 94 | uint64_t dma_addr = buffer; |
| 95 | struct hif_softc *scn = CE_state->scn; |
| 96 | |
| 97 | if (Q_TARGET_ACCESS_BEGIN(scn) < 0) |
| 98 | return QDF_STATUS_E_FAILURE; |
| 99 | if (unlikely(hal_srng_src_num_avail(scn->hal_soc, src_ring->srng_ctx, |
| 100 | false) <= 0)) { |
| 101 | OL_ATH_CE_PKT_ERROR_COUNT_INCR(scn, CE_RING_DELTA_FAIL); |
| 102 | Q_TARGET_ACCESS_END(scn); |
| 103 | return QDF_STATUS_E_FAILURE; |
| 104 | } |
| 105 | { |
| 106 | enum hif_ce_event_type event_type = HIF_TX_GATHER_DESC_POST; |
| 107 | struct ce_srng_src_desc *src_desc; |
| 108 | |
| 109 | if (hal_srng_access_start(scn->hal_soc, src_ring->srng_ctx)) { |
| 110 | Q_TARGET_ACCESS_END(scn); |
| 111 | return QDF_STATUS_E_FAILURE; |
| 112 | } |
| 113 | |
| 114 | src_desc = hal_srng_src_get_next_reaped(scn->hal_soc, |
| 115 | src_ring->srng_ctx); |
| 116 | |
| 117 | /* Update low 32 bits source descriptor address */ |
| 118 | src_desc->buffer_addr_lo = |
| 119 | (uint32_t)(dma_addr & 0xFFFFFFFF); |
| 120 | src_desc->buffer_addr_hi = |
| 121 | (uint32_t)((dma_addr >> 32) & 0xFF); |
| 122 | |
| 123 | src_desc->meta_data = transfer_id; |
| 124 | |
| 125 | /* |
| 126 | * Set the swap bit if: |
| 127 | * typical sends on this CE are swapped (host is big-endian) |
| 128 | * and this send doesn't disable the swapping |
| 129 | * (data is not bytestream) |
| 130 | */ |
| 131 | src_desc->byte_swap = |
| 132 | (((CE_state->attr_flags & CE_ATTR_BYTE_SWAP_DATA) |
| 133 | != 0) & ((flags & CE_SEND_FLAG_SWAP_DISABLE) == 0)); |
| 134 | src_desc->gather = ((flags & CE_SEND_FLAG_GATHER) != 0); |
| 135 | src_desc->nbytes = nbytes; |
| 136 | |
| 137 | src_ring->per_transfer_context[write_index] = |
| 138 | per_transfer_context; |
| 139 | write_index = CE_RING_IDX_INCR(nentries_mask, write_index); |
| 140 | |
| 141 | hal_srng_access_end(scn->hal_soc, src_ring->srng_ctx); |
| 142 | |
| 143 | /* src_ring->write index hasn't been updated event though |
| 144 | * the register has allready been written to. |
| 145 | */ |
| 146 | hif_record_ce_desc_event(scn, CE_state->id, event_type, |
| 147 | (union ce_desc *) src_desc, per_transfer_context, |
| 148 | src_ring->write_index); |
| 149 | |
| 150 | src_ring->write_index = write_index; |
| 151 | status = QDF_STATUS_SUCCESS; |
| 152 | } |
| 153 | Q_TARGET_ACCESS_END(scn); |
| 154 | return status; |
| 155 | } |
| 156 | |
Jeff Johnson | 0571813 | 2016-12-17 10:18:17 -0800 | [diff] [blame] | 157 | static int |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 158 | ce_sendlist_send_srng(struct CE_handle *copyeng, |
| 159 | void *per_transfer_context, |
| 160 | struct ce_sendlist *sendlist, unsigned int transfer_id) |
| 161 | { |
| 162 | int status = -ENOMEM; |
| 163 | struct ce_sendlist_s *sl = (struct ce_sendlist_s *)sendlist; |
| 164 | struct CE_state *CE_state = (struct CE_state *)copyeng; |
| 165 | struct CE_ring_state *src_ring = CE_state->src_ring; |
| 166 | unsigned int num_items = sl->num_items; |
| 167 | unsigned int sw_index; |
| 168 | unsigned int write_index; |
| 169 | struct hif_softc *scn = CE_state->scn; |
| 170 | |
| 171 | QDF_ASSERT((num_items > 0) && (num_items < src_ring->nentries)); |
| 172 | |
| 173 | qdf_spin_lock_bh(&CE_state->ce_index_lock); |
| 174 | sw_index = src_ring->sw_index; |
| 175 | write_index = src_ring->write_index; |
| 176 | |
| 177 | if (hal_srng_src_num_avail(scn->hal_soc, src_ring->srng_ctx, false) >= |
| 178 | num_items) { |
| 179 | struct ce_sendlist_item *item; |
| 180 | int i; |
| 181 | |
| 182 | /* handle all but the last item uniformly */ |
| 183 | for (i = 0; i < num_items - 1; i++) { |
| 184 | item = &sl->item[i]; |
| 185 | /* TBDXXX: Support extensible sendlist_types? */ |
| 186 | QDF_ASSERT(item->send_type == CE_SIMPLE_BUFFER_TYPE); |
| 187 | status = ce_send_nolock_srng(copyeng, |
| 188 | CE_SENDLIST_ITEM_CTXT, |
| 189 | (qdf_dma_addr_t) item->data, |
| 190 | item->u.nbytes, transfer_id, |
| 191 | item->flags | CE_SEND_FLAG_GATHER, |
| 192 | item->user_flags); |
| 193 | QDF_ASSERT(status == QDF_STATUS_SUCCESS); |
| 194 | } |
| 195 | /* provide valid context pointer for final item */ |
| 196 | item = &sl->item[i]; |
| 197 | /* TBDXXX: Support extensible sendlist_types? */ |
| 198 | QDF_ASSERT(item->send_type == CE_SIMPLE_BUFFER_TYPE); |
| 199 | status = ce_send_nolock_srng(copyeng, per_transfer_context, |
| 200 | (qdf_dma_addr_t) item->data, |
| 201 | item->u.nbytes, |
| 202 | transfer_id, item->flags, |
| 203 | item->user_flags); |
| 204 | QDF_ASSERT(status == QDF_STATUS_SUCCESS); |
| 205 | QDF_NBUF_UPDATE_TX_PKT_COUNT((qdf_nbuf_t)per_transfer_context, |
| 206 | QDF_NBUF_TX_PKT_CE); |
| 207 | DPTRACE(qdf_dp_trace((qdf_nbuf_t)per_transfer_context, |
| 208 | QDF_DP_TRACE_CE_PACKET_PTR_RECORD, |
| 209 | (uint8_t *)(((qdf_nbuf_t)per_transfer_context)->data), |
Houston Hoffman | 9a1b391 | 2016-10-17 18:56:32 -0700 | [diff] [blame] | 210 | sizeof(((qdf_nbuf_t)per_transfer_context)->data), QDF_TX)); |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 211 | } else { |
| 212 | /* |
| 213 | * Probably not worth the additional complexity to support |
| 214 | * partial sends with continuation or notification. We expect |
| 215 | * to use large rings and small sendlists. If we can't handle |
| 216 | * the entire request at once, punt it back to the caller. |
| 217 | */ |
| 218 | } |
| 219 | qdf_spin_unlock_bh(&CE_state->ce_index_lock); |
| 220 | |
| 221 | return status; |
| 222 | } |
| 223 | |
| 224 | #define SLOTS_PER_DATAPATH_TX 2 |
| 225 | |
| 226 | #ifndef AH_NEED_TX_DATA_SWAP |
| 227 | #define AH_NEED_TX_DATA_SWAP 0 |
| 228 | #endif |
| 229 | /** |
| 230 | * ce_recv_buf_enqueue_srng() - enqueue a recv buffer into a copy engine |
| 231 | * @coyeng: copy engine handle |
| 232 | * @per_recv_context: virtual address of the nbuf |
| 233 | * @buffer: physical address of the nbuf |
| 234 | * |
| 235 | * Return: 0 if the buffer is enqueued |
| 236 | */ |
Jeff Johnson | 0571813 | 2016-12-17 10:18:17 -0800 | [diff] [blame] | 237 | static int |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 238 | ce_recv_buf_enqueue_srng(struct CE_handle *copyeng, |
| 239 | void *per_recv_context, qdf_dma_addr_t buffer) |
| 240 | { |
| 241 | int status; |
| 242 | struct CE_state *CE_state = (struct CE_state *)copyeng; |
| 243 | struct CE_ring_state *dest_ring = CE_state->dest_ring; |
| 244 | unsigned int nentries_mask = dest_ring->nentries_mask; |
| 245 | unsigned int write_index; |
| 246 | unsigned int sw_index; |
| 247 | uint64_t dma_addr = buffer; |
| 248 | struct hif_softc *scn = CE_state->scn; |
| 249 | |
| 250 | qdf_spin_lock_bh(&CE_state->ce_index_lock); |
| 251 | write_index = dest_ring->write_index; |
| 252 | sw_index = dest_ring->sw_index; |
| 253 | |
| 254 | if (Q_TARGET_ACCESS_BEGIN(scn) < 0) { |
| 255 | qdf_spin_unlock_bh(&CE_state->ce_index_lock); |
| 256 | return -EIO; |
| 257 | } |
| 258 | |
| 259 | if (hal_srng_access_start(scn->hal_soc, dest_ring->srng_ctx)) { |
| 260 | qdf_spin_unlock_bh(&CE_state->ce_index_lock); |
| 261 | return QDF_STATUS_E_FAILURE; |
| 262 | } |
| 263 | |
| 264 | if ((hal_srng_src_num_avail(scn->hal_soc, |
| 265 | dest_ring->srng_ctx, false) > 0)) { |
| 266 | struct ce_srng_dest_desc *dest_desc = |
| 267 | hal_srng_src_get_next(scn->hal_soc, |
| 268 | dest_ring->srng_ctx); |
| 269 | |
| 270 | if (dest_desc == NULL) { |
| 271 | status = QDF_STATUS_E_FAILURE; |
| 272 | } else { |
| 273 | |
| 274 | CE_ADDR_COPY(dest_desc, dma_addr); |
| 275 | |
| 276 | dest_ring->per_transfer_context[write_index] = |
| 277 | per_recv_context; |
| 278 | |
| 279 | /* Update Destination Ring Write Index */ |
| 280 | write_index = CE_RING_IDX_INCR(nentries_mask, |
| 281 | write_index); |
| 282 | status = QDF_STATUS_SUCCESS; |
| 283 | } |
| 284 | } else |
| 285 | status = QDF_STATUS_E_FAILURE; |
| 286 | |
| 287 | dest_ring->write_index = write_index; |
| 288 | hal_srng_access_end(scn->hal_soc, dest_ring->srng_ctx); |
| 289 | Q_TARGET_ACCESS_END(scn); |
| 290 | qdf_spin_unlock_bh(&CE_state->ce_index_lock); |
| 291 | return status; |
| 292 | } |
| 293 | |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 294 | /* |
| 295 | * Guts of ce_recv_entries_done. |
| 296 | * The caller takes responsibility for any necessary locking. |
| 297 | */ |
Jeff Johnson | 0571813 | 2016-12-17 10:18:17 -0800 | [diff] [blame] | 298 | static unsigned int |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 299 | ce_recv_entries_done_nolock_srng(struct hif_softc *scn, |
| 300 | struct CE_state *CE_state) |
| 301 | { |
| 302 | struct CE_ring_state *status_ring = CE_state->status_ring; |
| 303 | |
| 304 | return hal_srng_dst_num_valid(scn->hal_soc, |
| 305 | status_ring->srng_ctx, false); |
| 306 | } |
| 307 | |
| 308 | /* |
| 309 | * Guts of ce_send_entries_done. |
| 310 | * The caller takes responsibility for any necessary locking. |
| 311 | */ |
Jeff Johnson | 0571813 | 2016-12-17 10:18:17 -0800 | [diff] [blame] | 312 | static unsigned int |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 313 | ce_send_entries_done_nolock_srng(struct hif_softc *scn, |
| 314 | struct CE_state *CE_state) |
| 315 | { |
| 316 | |
| 317 | struct CE_ring_state *src_ring = CE_state->src_ring; |
| 318 | int count = 0; |
| 319 | |
| 320 | if (hal_srng_access_start(scn->hal_soc, src_ring->srng_ctx)) |
| 321 | return 0; |
| 322 | |
| 323 | count = hal_srng_src_done_val(scn->hal_soc, src_ring->srng_ctx); |
| 324 | |
| 325 | hal_srng_access_end(scn->hal_soc, src_ring->srng_ctx); |
| 326 | |
| 327 | return count; |
| 328 | } |
| 329 | |
| 330 | /* Debug support */ |
| 331 | void *ce_debug_cmplrn_context_srng; /* completed recv next context */ |
| 332 | void *ce_debug_cmplsn_context_srng; /* completed send next context */ |
| 333 | |
| 334 | /* |
| 335 | * Guts of ce_completed_recv_next. |
| 336 | * The caller takes responsibility for any necessary locking. |
| 337 | */ |
Jeff Johnson | 0571813 | 2016-12-17 10:18:17 -0800 | [diff] [blame] | 338 | static int |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 339 | ce_completed_recv_next_nolock_srng(struct CE_state *CE_state, |
| 340 | void **per_CE_contextp, |
| 341 | void **per_transfer_contextp, |
| 342 | qdf_dma_addr_t *bufferp, |
| 343 | unsigned int *nbytesp, |
| 344 | unsigned int *transfer_idp, |
| 345 | unsigned int *flagsp) |
| 346 | { |
| 347 | int status; |
| 348 | struct CE_ring_state *dest_ring = CE_state->dest_ring; |
| 349 | struct CE_ring_state *status_ring = CE_state->status_ring; |
| 350 | unsigned int nentries_mask = dest_ring->nentries_mask; |
| 351 | unsigned int sw_index = dest_ring->sw_index; |
| 352 | struct hif_softc *scn = CE_state->scn; |
| 353 | struct ce_srng_dest_status_desc *dest_status; |
| 354 | int nbytes; |
| 355 | struct ce_srng_dest_status_desc dest_status_info; |
| 356 | |
| 357 | if (hal_srng_access_start(scn->hal_soc, status_ring->srng_ctx)) { |
| 358 | status = QDF_STATUS_E_FAILURE; |
| 359 | goto done; |
| 360 | } |
| 361 | |
| 362 | dest_status = hal_srng_dst_get_next(scn->hal_soc, |
| 363 | status_ring->srng_ctx); |
| 364 | |
| 365 | if (dest_status == NULL) { |
| 366 | status = QDF_STATUS_E_FAILURE; |
| 367 | goto done; |
| 368 | } |
| 369 | /* |
| 370 | * By copying the dest_desc_info element to local memory, we could |
| 371 | * avoid extra memory read from non-cachable memory. |
| 372 | */ |
| 373 | dest_status_info = *dest_status; |
| 374 | nbytes = dest_status_info.nbytes; |
| 375 | if (nbytes == 0) { |
| 376 | /* |
| 377 | * This closes a relatively unusual race where the Host |
| 378 | * sees the updated DRRI before the update to the |
| 379 | * corresponding descriptor has completed. We treat this |
| 380 | * as a descriptor that is not yet done. |
| 381 | */ |
| 382 | status = QDF_STATUS_E_FAILURE; |
| 383 | goto done; |
| 384 | } |
| 385 | |
| 386 | dest_status->nbytes = 0; |
| 387 | |
| 388 | *nbytesp = nbytes; |
| 389 | *transfer_idp = dest_status_info.meta_data; |
| 390 | *flagsp = (dest_status_info.byte_swap) ? CE_RECV_FLAG_SWAPPED : 0; |
| 391 | |
| 392 | if (per_CE_contextp) |
| 393 | *per_CE_contextp = CE_state->recv_context; |
| 394 | |
| 395 | /* NOTE: sw_index is more like a read_index in this context. It has a |
| 396 | * one-to-one mapping with status ring. |
| 397 | * Get the per trasnfer context from dest_ring. |
| 398 | */ |
| 399 | ce_debug_cmplrn_context_srng = |
| 400 | dest_ring->per_transfer_context[sw_index]; |
| 401 | |
| 402 | if (per_transfer_contextp) |
| 403 | *per_transfer_contextp = ce_debug_cmplrn_context_srng; |
| 404 | |
| 405 | dest_ring->per_transfer_context[sw_index] = 0; /* sanity */ |
| 406 | |
| 407 | /* Update sw_index */ |
| 408 | sw_index = CE_RING_IDX_INCR(nentries_mask, sw_index); |
| 409 | dest_ring->sw_index = sw_index; |
| 410 | status = QDF_STATUS_SUCCESS; |
| 411 | |
| 412 | done: |
| 413 | hal_srng_access_end(scn->hal_soc, status_ring->srng_ctx); |
| 414 | |
| 415 | return status; |
| 416 | } |
| 417 | |
Jeff Johnson | 0571813 | 2016-12-17 10:18:17 -0800 | [diff] [blame] | 418 | static QDF_STATUS |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 419 | ce_revoke_recv_next_srng(struct CE_handle *copyeng, |
| 420 | void **per_CE_contextp, |
| 421 | void **per_transfer_contextp, qdf_dma_addr_t *bufferp) |
| 422 | { |
| 423 | QDF_STATUS status = QDF_STATUS_E_FAILURE; |
| 424 | |
| 425 | return status; |
| 426 | } |
| 427 | |
| 428 | /* |
| 429 | * Guts of ce_completed_send_next. |
| 430 | * The caller takes responsibility for any necessary locking. |
| 431 | */ |
Jeff Johnson | 0571813 | 2016-12-17 10:18:17 -0800 | [diff] [blame] | 432 | static int |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 433 | ce_completed_send_next_nolock_srng(struct CE_state *CE_state, |
| 434 | void **per_CE_contextp, |
| 435 | void **per_transfer_contextp, |
| 436 | qdf_dma_addr_t *bufferp, |
| 437 | unsigned int *nbytesp, |
| 438 | unsigned int *transfer_idp, |
| 439 | unsigned int *sw_idx, |
| 440 | unsigned int *hw_idx, |
| 441 | uint32_t *toeplitz_hash_result) |
| 442 | { |
| 443 | int status = QDF_STATUS_E_FAILURE; |
| 444 | struct CE_ring_state *src_ring = CE_state->src_ring; |
| 445 | unsigned int nentries_mask = src_ring->nentries_mask; |
| 446 | unsigned int sw_index = src_ring->sw_index; |
| 447 | struct hif_softc *scn = CE_state->scn; |
| 448 | struct ce_srng_src_desc *src_desc; |
| 449 | |
| 450 | if (hal_srng_access_start(scn->hal_soc, src_ring->srng_ctx)) { |
| 451 | status = QDF_STATUS_E_FAILURE; |
| 452 | return status; |
| 453 | } |
| 454 | |
| 455 | src_desc = hal_srng_src_reap_next(scn->hal_soc, src_ring->srng_ctx); |
| 456 | if (src_desc) { |
| 457 | |
| 458 | /* Return data from completed source descriptor */ |
| 459 | *bufferp = (qdf_dma_addr_t) |
| 460 | (((uint64_t)(src_desc)->buffer_addr_lo + |
| 461 | ((uint64_t)((src_desc)->buffer_addr_hi & |
| 462 | 0xFF) << 32))); |
| 463 | *nbytesp = src_desc->nbytes; |
| 464 | *transfer_idp = src_desc->meta_data; |
| 465 | *toeplitz_hash_result = 0; /*src_desc->toeplitz_hash_result;*/ |
| 466 | |
| 467 | if (per_CE_contextp) |
| 468 | *per_CE_contextp = CE_state->send_context; |
| 469 | |
| 470 | /* sw_index is used more like read index */ |
| 471 | ce_debug_cmplsn_context_srng = |
| 472 | src_ring->per_transfer_context[sw_index]; |
| 473 | if (per_transfer_contextp) |
| 474 | *per_transfer_contextp = ce_debug_cmplsn_context_srng; |
| 475 | |
| 476 | src_ring->per_transfer_context[sw_index] = 0; /* sanity */ |
| 477 | |
| 478 | /* Update sw_index */ |
| 479 | sw_index = CE_RING_IDX_INCR(nentries_mask, sw_index); |
| 480 | src_ring->sw_index = sw_index; |
| 481 | status = QDF_STATUS_SUCCESS; |
| 482 | } |
Pamidipati, Vijay | dfe618e | 2016-10-09 09:17:24 +0530 | [diff] [blame] | 483 | hal_srng_access_end_reap(scn->hal_soc, src_ring->srng_ctx); |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 484 | |
| 485 | return status; |
| 486 | } |
| 487 | |
| 488 | /* NB: Modelled after ce_completed_send_next */ |
Jeff Johnson | 0571813 | 2016-12-17 10:18:17 -0800 | [diff] [blame] | 489 | static QDF_STATUS |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 490 | ce_cancel_send_next_srng(struct CE_handle *copyeng, |
| 491 | void **per_CE_contextp, |
| 492 | void **per_transfer_contextp, |
| 493 | qdf_dma_addr_t *bufferp, |
| 494 | unsigned int *nbytesp, |
| 495 | unsigned int *transfer_idp, |
| 496 | uint32_t *toeplitz_hash_result) |
| 497 | { |
Kiran Venkatappa | 55d3a20 | 2016-12-20 11:29:34 +0530 | [diff] [blame] | 498 | return QDF_STATUS_E_INVAL; |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | /* Shift bits to convert IS_*_RING_*_WATERMARK_MASK to CE_WM_FLAG_*_* */ |
| 502 | #define CE_WM_SHFT 1 |
| 503 | |
| 504 | /* |
| 505 | * Number of times to check for any pending tx/rx completion on |
| 506 | * a copy engine, this count should be big enough. Once we hit |
| 507 | * this threashold we'll not check for any Tx/Rx comlpetion in same |
| 508 | * interrupt handling. Note that this threashold is only used for |
| 509 | * Rx interrupt processing, this can be used tor Tx as well if we |
| 510 | * suspect any infinite loop in checking for pending Tx completion. |
| 511 | */ |
| 512 | #define CE_TXRX_COMP_CHECK_THRESHOLD 20 |
| 513 | |
| 514 | /* |
| 515 | * Adjust interrupts for the copy complete handler. |
| 516 | * If it's needed for either send or recv, then unmask |
| 517 | * this interrupt; otherwise, mask it. |
| 518 | * |
| 519 | * Called with target_lock held. |
| 520 | */ |
| 521 | static void |
| 522 | ce_per_engine_handler_adjust_srng(struct CE_state *CE_state, |
| 523 | int disable_copy_compl_intr) |
| 524 | { |
| 525 | } |
| 526 | |
Jeff Johnson | 0571813 | 2016-12-17 10:18:17 -0800 | [diff] [blame] | 527 | static bool ce_check_int_watermark_srng(struct CE_state *CE_state, |
| 528 | unsigned int *flags) |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 529 | { |
| 530 | /*TODO*/ |
| 531 | return false; |
| 532 | } |
| 533 | |
Jeff Johnson | 0571813 | 2016-12-17 10:18:17 -0800 | [diff] [blame] | 534 | static uint32_t ce_get_desc_size_srng(uint8_t ring_type) |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 535 | { |
| 536 | switch (ring_type) { |
| 537 | case CE_RING_SRC: |
| 538 | return sizeof(struct ce_srng_src_desc); |
| 539 | case CE_RING_DEST: |
| 540 | return sizeof(struct ce_srng_dest_desc); |
| 541 | case CE_RING_STATUS: |
| 542 | return sizeof(struct ce_srng_dest_status_desc); |
| 543 | default: |
| 544 | return 0; |
| 545 | } |
| 546 | return 0; |
| 547 | } |
| 548 | |
Houston Hoffman | 1501077 | 2016-09-16 14:01:13 -0700 | [diff] [blame] | 549 | static void ce_srng_msi_ring_params_setup(struct hif_softc *scn, uint32_t ce_id, |
| 550 | struct hal_srng_params *ring_params) |
| 551 | { |
| 552 | uint32_t addr_low; |
| 553 | uint32_t addr_high; |
| 554 | uint32_t msi_data_start; |
| 555 | uint32_t msi_data_count; |
| 556 | uint32_t msi_irq_start; |
| 557 | int ret; |
| 558 | |
| 559 | ret = pld_get_user_msi_assignment(scn->qdf_dev->dev, "CE", |
| 560 | &msi_data_count, &msi_data_start, |
| 561 | &msi_irq_start); |
| 562 | |
| 563 | /* msi config not found */ |
| 564 | if (ret) |
| 565 | return; |
| 566 | |
| 567 | HIF_INFO("%s: ce_id %d, msi_start: %d, msi_count %d", __func__, ce_id, |
| 568 | msi_data_start, msi_data_count); |
| 569 | |
| 570 | pld_get_msi_address(scn->qdf_dev->dev, &addr_low, &addr_high); |
| 571 | |
| 572 | ring_params->msi_addr = addr_low; |
| 573 | ring_params->msi_addr |= (qdf_dma_addr_t)(((uint64_t)addr_high) << 32); |
| 574 | ring_params->msi_data = (ce_id % msi_data_count) + msi_data_start; |
| 575 | ring_params->flags |= HAL_SRNG_MSI_INTR; |
| 576 | |
| 577 | HIF_INFO("%s: ce_id %d, msi_addr %p, msi_data %d", __func__, ce_id, |
| 578 | (void *)ring_params->msi_addr, ring_params->msi_data); |
| 579 | } |
| 580 | |
Jeff Johnson | 0571813 | 2016-12-17 10:18:17 -0800 | [diff] [blame] | 581 | static void ce_srng_src_ring_setup(struct hif_softc *scn, uint32_t ce_id, |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 582 | struct CE_ring_state *src_ring) |
| 583 | { |
| 584 | struct hal_srng_params ring_params = {0}; |
| 585 | |
Houston Hoffman | 1501077 | 2016-09-16 14:01:13 -0700 | [diff] [blame] | 586 | HIF_INFO("%s: ce_id %d", __func__, ce_id); |
| 587 | |
| 588 | ce_srng_msi_ring_params_setup(scn, ce_id, &ring_params); |
| 589 | |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 590 | ring_params.ring_base_paddr = src_ring->base_addr_CE_space; |
| 591 | ring_params.ring_base_vaddr = src_ring->base_addr_owner_space; |
| 592 | ring_params.num_entries = src_ring->nentries; |
Houston Hoffman | 202425d | 2016-10-17 19:42:48 -0700 | [diff] [blame] | 593 | /* |
| 594 | * The minimum increment for the timer is 8us |
| 595 | * A default value of 0 disables the timer |
| 596 | * A valid default value caused continuous interrupts to |
| 597 | * fire with MSI enabled. Need to revisit usage of the timer |
| 598 | */ |
| 599 | ring_params.intr_timer_thres_us = 0; |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 600 | ring_params.intr_batch_cntr_thres_entries = 1; |
| 601 | |
| 602 | /* TODO |
| 603 | * ring_params.msi_addr = XXX; |
| 604 | * ring_params.msi_data = XXX; |
| 605 | * ring_params.flags = XXX; |
| 606 | */ |
| 607 | |
| 608 | src_ring->srng_ctx = hal_srng_setup(scn->hal_soc, CE_SRC, ce_id, 0, |
| 609 | &ring_params); |
| 610 | } |
| 611 | |
Jeff Johnson | 0571813 | 2016-12-17 10:18:17 -0800 | [diff] [blame] | 612 | static void ce_srng_dest_ring_setup(struct hif_softc *scn, uint32_t ce_id, |
Houston Hoffman | 7410912 | 2016-10-21 14:58:34 -0700 | [diff] [blame] | 613 | struct CE_ring_state *dest_ring, |
| 614 | struct CE_attr *attr) |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 615 | { |
| 616 | struct hal_srng_params ring_params = {0}; |
| 617 | |
Houston Hoffman | 1501077 | 2016-09-16 14:01:13 -0700 | [diff] [blame] | 618 | HIF_INFO("%s: ce_id %d", __func__, ce_id); |
| 619 | |
| 620 | ce_srng_msi_ring_params_setup(scn, ce_id, &ring_params); |
| 621 | |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 622 | ring_params.ring_base_paddr = dest_ring->base_addr_CE_space; |
| 623 | ring_params.ring_base_vaddr = dest_ring->base_addr_owner_space; |
| 624 | ring_params.num_entries = dest_ring->nentries; |
Houston Hoffman | 202425d | 2016-10-17 19:42:48 -0700 | [diff] [blame] | 625 | ring_params.intr_timer_thres_us = 0; |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 626 | ring_params.intr_batch_cntr_thres_entries = 1; |
Houston Hoffman | 7410912 | 2016-10-21 14:58:34 -0700 | [diff] [blame] | 627 | ring_params.max_buffer_length = attr->src_sz_max; |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 628 | |
| 629 | /* TODO |
| 630 | * ring_params.msi_addr = XXX; |
| 631 | * ring_params.msi_data = XXX; |
| 632 | * ring_params.flags = XXX; |
| 633 | */ |
| 634 | |
| 635 | /*Dest ring is also source ring*/ |
| 636 | dest_ring->srng_ctx = hal_srng_setup(scn->hal_soc, CE_DST, ce_id, 0, |
| 637 | &ring_params); |
| 638 | } |
| 639 | |
Jeff Johnson | 0571813 | 2016-12-17 10:18:17 -0800 | [diff] [blame] | 640 | static void ce_srng_status_ring_setup(struct hif_softc *scn, uint32_t ce_id, |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 641 | struct CE_ring_state *status_ring) |
| 642 | { |
| 643 | struct hal_srng_params ring_params = {0}; |
| 644 | |
Houston Hoffman | 1501077 | 2016-09-16 14:01:13 -0700 | [diff] [blame] | 645 | HIF_INFO("%s: ce_id %d", __func__, ce_id); |
| 646 | |
| 647 | ce_srng_msi_ring_params_setup(scn, ce_id, &ring_params); |
| 648 | |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 649 | ring_params.ring_base_paddr = status_ring->base_addr_CE_space; |
| 650 | ring_params.ring_base_vaddr = status_ring->base_addr_owner_space; |
| 651 | ring_params.num_entries = status_ring->nentries; |
Houston Hoffman | 202425d | 2016-10-17 19:42:48 -0700 | [diff] [blame] | 652 | ring_params.intr_timer_thres_us = 0; |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 653 | ring_params.intr_batch_cntr_thres_entries = 1; |
| 654 | |
| 655 | /* TODO |
| 656 | * ring_params.msi_addr = XXX; |
| 657 | * ring_params.msi_data = XXX; |
| 658 | * ring_params.flags = XXX; |
| 659 | */ |
| 660 | |
| 661 | status_ring->srng_ctx = hal_srng_setup(scn->hal_soc, CE_DST_STATUS, |
| 662 | ce_id, 0, &ring_params); |
| 663 | } |
| 664 | |
Jeff Johnson | 0571813 | 2016-12-17 10:18:17 -0800 | [diff] [blame] | 665 | static void ce_ring_setup_srng(struct hif_softc *scn, uint8_t ring_type, |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 666 | uint32_t ce_id, struct CE_ring_state *ring, |
| 667 | struct CE_attr *attr) |
| 668 | { |
| 669 | switch (ring_type) { |
| 670 | case CE_RING_SRC: |
| 671 | ce_srng_src_ring_setup(scn, ce_id, ring); |
| 672 | break; |
| 673 | case CE_RING_DEST: |
Houston Hoffman | 7410912 | 2016-10-21 14:58:34 -0700 | [diff] [blame] | 674 | ce_srng_dest_ring_setup(scn, ce_id, ring, attr); |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 675 | break; |
| 676 | case CE_RING_STATUS: |
| 677 | ce_srng_status_ring_setup(scn, ce_id, ring); |
| 678 | break; |
| 679 | default: |
| 680 | qdf_assert(0); |
| 681 | break; |
| 682 | } |
| 683 | } |
Jeff Johnson | 0571813 | 2016-12-17 10:18:17 -0800 | [diff] [blame] | 684 | |
Houston Hoffman | 10fedfc | 2017-01-23 15:23:09 -0800 | [diff] [blame^] | 685 | static void ce_construct_shadow_config_srng(struct hif_softc *scn) |
| 686 | { |
| 687 | struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn); |
| 688 | int ce_id; |
| 689 | |
| 690 | for (ce_id = 0; ce_id < scn->ce_count; ce_id++) { |
| 691 | if (hif_state->host_ce_config[ce_id].src_nentries) |
| 692 | hal_set_one_shadow_config(scn->hal_soc, |
| 693 | CE_SRC, ce_id); |
| 694 | |
| 695 | if (hif_state->host_ce_config[ce_id].dest_nentries) { |
| 696 | hal_set_one_shadow_config(scn->hal_soc, |
| 697 | CE_DST, ce_id); |
| 698 | |
| 699 | hal_set_one_shadow_config(scn->hal_soc, |
| 700 | CE_DST_STATUS, ce_id); |
| 701 | } |
| 702 | } |
| 703 | } |
| 704 | |
| 705 | static void ce_prepare_shadow_register_v2_cfg_srng(struct hif_softc *scn, |
| 706 | struct pld_shadow_reg_v2_cfg **shadow_config, |
| 707 | int *num_shadow_registers_configured) |
| 708 | { |
| 709 | if (scn->hal_soc == NULL) { |
| 710 | HIF_ERROR("%s: hal not initialized: not initializing shadow config", |
| 711 | __func__); |
| 712 | return; |
| 713 | } |
| 714 | |
| 715 | hal_get_shadow_config(scn->hal_soc, shadow_config, |
| 716 | num_shadow_registers_configured); |
| 717 | |
| 718 | if (*num_shadow_registers_configured != 0) { |
| 719 | HIF_ERROR("%s: hal shadow register configuration allready constructed", |
| 720 | __func__); |
| 721 | |
| 722 | /* return with original configuration*/ |
| 723 | return; |
| 724 | } |
| 725 | |
| 726 | hal_construct_shadow_config(scn->hal_soc); |
| 727 | ce_construct_shadow_config_srng(scn); |
| 728 | |
| 729 | /* get updated configuration */ |
| 730 | hal_get_shadow_config(scn->hal_soc, shadow_config, |
| 731 | num_shadow_registers_configured); |
| 732 | } |
| 733 | |
Jeff Johnson | 0571813 | 2016-12-17 10:18:17 -0800 | [diff] [blame] | 734 | static struct ce_ops ce_service_srng = { |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 735 | .ce_get_desc_size = ce_get_desc_size_srng, |
| 736 | .ce_ring_setup = ce_ring_setup_srng, |
| 737 | .ce_sendlist_send = ce_sendlist_send_srng, |
| 738 | .ce_completed_recv_next_nolock = ce_completed_recv_next_nolock_srng, |
| 739 | .ce_revoke_recv_next = ce_revoke_recv_next_srng, |
| 740 | .ce_cancel_send_next = ce_cancel_send_next_srng, |
| 741 | .ce_recv_buf_enqueue = ce_recv_buf_enqueue_srng, |
| 742 | .ce_per_engine_handler_adjust = ce_per_engine_handler_adjust_srng, |
| 743 | .ce_send_nolock = ce_send_nolock_srng, |
| 744 | .watermark_int = ce_check_int_watermark_srng, |
| 745 | .ce_completed_send_next_nolock = ce_completed_send_next_nolock_srng, |
| 746 | .ce_recv_entries_done_nolock = ce_recv_entries_done_nolock_srng, |
| 747 | .ce_send_entries_done_nolock = ce_send_entries_done_nolock_srng, |
Houston Hoffman | 10fedfc | 2017-01-23 15:23:09 -0800 | [diff] [blame^] | 748 | .ce_prepare_shadow_register_v2_cfg = |
| 749 | ce_prepare_shadow_register_v2_cfg_srng, |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 750 | }; |
| 751 | |
| 752 | struct ce_ops *ce_services_srng() |
| 753 | { |
| 754 | return &ce_service_srng; |
| 755 | } |