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 | |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 330 | /* |
| 331 | * Guts of ce_completed_recv_next. |
| 332 | * The caller takes responsibility for any necessary locking. |
| 333 | */ |
Jeff Johnson | 0571813 | 2016-12-17 10:18:17 -0800 | [diff] [blame] | 334 | static int |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 335 | ce_completed_recv_next_nolock_srng(struct CE_state *CE_state, |
| 336 | void **per_CE_contextp, |
| 337 | void **per_transfer_contextp, |
| 338 | qdf_dma_addr_t *bufferp, |
| 339 | unsigned int *nbytesp, |
| 340 | unsigned int *transfer_idp, |
| 341 | unsigned int *flagsp) |
| 342 | { |
| 343 | int status; |
| 344 | struct CE_ring_state *dest_ring = CE_state->dest_ring; |
| 345 | struct CE_ring_state *status_ring = CE_state->status_ring; |
| 346 | unsigned int nentries_mask = dest_ring->nentries_mask; |
| 347 | unsigned int sw_index = dest_ring->sw_index; |
| 348 | struct hif_softc *scn = CE_state->scn; |
| 349 | struct ce_srng_dest_status_desc *dest_status; |
| 350 | int nbytes; |
| 351 | struct ce_srng_dest_status_desc dest_status_info; |
| 352 | |
| 353 | if (hal_srng_access_start(scn->hal_soc, status_ring->srng_ctx)) { |
| 354 | status = QDF_STATUS_E_FAILURE; |
| 355 | goto done; |
| 356 | } |
| 357 | |
| 358 | dest_status = hal_srng_dst_get_next(scn->hal_soc, |
| 359 | status_ring->srng_ctx); |
| 360 | |
| 361 | if (dest_status == NULL) { |
| 362 | status = QDF_STATUS_E_FAILURE; |
| 363 | goto done; |
| 364 | } |
| 365 | /* |
| 366 | * By copying the dest_desc_info element to local memory, we could |
| 367 | * avoid extra memory read from non-cachable memory. |
| 368 | */ |
| 369 | dest_status_info = *dest_status; |
| 370 | nbytes = dest_status_info.nbytes; |
| 371 | if (nbytes == 0) { |
| 372 | /* |
| 373 | * This closes a relatively unusual race where the Host |
| 374 | * sees the updated DRRI before the update to the |
| 375 | * corresponding descriptor has completed. We treat this |
| 376 | * as a descriptor that is not yet done. |
| 377 | */ |
| 378 | status = QDF_STATUS_E_FAILURE; |
| 379 | goto done; |
| 380 | } |
| 381 | |
| 382 | dest_status->nbytes = 0; |
| 383 | |
| 384 | *nbytesp = nbytes; |
| 385 | *transfer_idp = dest_status_info.meta_data; |
| 386 | *flagsp = (dest_status_info.byte_swap) ? CE_RECV_FLAG_SWAPPED : 0; |
| 387 | |
| 388 | if (per_CE_contextp) |
| 389 | *per_CE_contextp = CE_state->recv_context; |
| 390 | |
| 391 | /* NOTE: sw_index is more like a read_index in this context. It has a |
| 392 | * one-to-one mapping with status ring. |
| 393 | * Get the per trasnfer context from dest_ring. |
| 394 | */ |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 395 | if (per_transfer_contextp) |
Houston Hoffman | 3274fbc | 2017-01-26 22:32:26 -0800 | [diff] [blame] | 396 | *per_transfer_contextp = |
| 397 | dest_ring->per_transfer_context[sw_index]; |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 398 | |
| 399 | dest_ring->per_transfer_context[sw_index] = 0; /* sanity */ |
| 400 | |
| 401 | /* Update sw_index */ |
| 402 | sw_index = CE_RING_IDX_INCR(nentries_mask, sw_index); |
| 403 | dest_ring->sw_index = sw_index; |
| 404 | status = QDF_STATUS_SUCCESS; |
| 405 | |
| 406 | done: |
| 407 | hal_srng_access_end(scn->hal_soc, status_ring->srng_ctx); |
| 408 | |
| 409 | return status; |
| 410 | } |
| 411 | |
Jeff Johnson | 0571813 | 2016-12-17 10:18:17 -0800 | [diff] [blame] | 412 | static QDF_STATUS |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 413 | ce_revoke_recv_next_srng(struct CE_handle *copyeng, |
| 414 | void **per_CE_contextp, |
| 415 | void **per_transfer_contextp, qdf_dma_addr_t *bufferp) |
| 416 | { |
Houston Hoffman | 72ddc02 | 2017-01-30 14:21:46 -0800 | [diff] [blame^] | 417 | struct CE_state *CE_state = (struct CE_state *)copyeng; |
| 418 | struct CE_ring_state *dest_ring = CE_state->dest_ring; |
| 419 | unsigned int sw_index; |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 420 | |
Houston Hoffman | 72ddc02 | 2017-01-30 14:21:46 -0800 | [diff] [blame^] | 421 | if (!dest_ring) |
| 422 | return QDF_STATUS_E_FAILURE; |
| 423 | |
| 424 | sw_index = dest_ring->sw_index; |
| 425 | |
| 426 | if (per_CE_contextp) |
| 427 | *per_CE_contextp = CE_state->recv_context; |
| 428 | |
| 429 | /* NOTE: sw_index is more like a read_index in this context. It has a |
| 430 | * one-to-one mapping with status ring. |
| 431 | * Get the per trasnfer context from dest_ring. |
| 432 | */ |
| 433 | if (per_transfer_contextp) |
| 434 | *per_transfer_contextp = |
| 435 | dest_ring->per_transfer_context[sw_index]; |
| 436 | |
| 437 | if (dest_ring->per_transfer_context[sw_index] == NULL) |
| 438 | return QDF_STATUS_E_FAILURE; |
| 439 | |
| 440 | /* provide end condition */ |
| 441 | dest_ring->per_transfer_context[sw_index] = NULL; |
| 442 | |
| 443 | /* Update sw_index */ |
| 444 | sw_index = CE_RING_IDX_INCR(dest_ring->nentries_mask, sw_index); |
| 445 | dest_ring->sw_index = sw_index; |
| 446 | return QDF_STATUS_SUCCESS; |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | /* |
| 450 | * Guts of ce_completed_send_next. |
| 451 | * The caller takes responsibility for any necessary locking. |
| 452 | */ |
Jeff Johnson | 0571813 | 2016-12-17 10:18:17 -0800 | [diff] [blame] | 453 | static int |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 454 | ce_completed_send_next_nolock_srng(struct CE_state *CE_state, |
| 455 | void **per_CE_contextp, |
| 456 | void **per_transfer_contextp, |
| 457 | qdf_dma_addr_t *bufferp, |
| 458 | unsigned int *nbytesp, |
| 459 | unsigned int *transfer_idp, |
| 460 | unsigned int *sw_idx, |
| 461 | unsigned int *hw_idx, |
| 462 | uint32_t *toeplitz_hash_result) |
| 463 | { |
| 464 | int status = QDF_STATUS_E_FAILURE; |
| 465 | struct CE_ring_state *src_ring = CE_state->src_ring; |
| 466 | unsigned int nentries_mask = src_ring->nentries_mask; |
| 467 | unsigned int sw_index = src_ring->sw_index; |
| 468 | struct hif_softc *scn = CE_state->scn; |
| 469 | struct ce_srng_src_desc *src_desc; |
| 470 | |
| 471 | if (hal_srng_access_start(scn->hal_soc, src_ring->srng_ctx)) { |
| 472 | status = QDF_STATUS_E_FAILURE; |
| 473 | return status; |
| 474 | } |
| 475 | |
| 476 | src_desc = hal_srng_src_reap_next(scn->hal_soc, src_ring->srng_ctx); |
| 477 | if (src_desc) { |
| 478 | |
| 479 | /* Return data from completed source descriptor */ |
| 480 | *bufferp = (qdf_dma_addr_t) |
| 481 | (((uint64_t)(src_desc)->buffer_addr_lo + |
| 482 | ((uint64_t)((src_desc)->buffer_addr_hi & |
| 483 | 0xFF) << 32))); |
| 484 | *nbytesp = src_desc->nbytes; |
| 485 | *transfer_idp = src_desc->meta_data; |
| 486 | *toeplitz_hash_result = 0; /*src_desc->toeplitz_hash_result;*/ |
| 487 | |
| 488 | if (per_CE_contextp) |
| 489 | *per_CE_contextp = CE_state->send_context; |
| 490 | |
| 491 | /* sw_index is used more like read index */ |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 492 | if (per_transfer_contextp) |
Houston Hoffman | 3274fbc | 2017-01-26 22:32:26 -0800 | [diff] [blame] | 493 | *per_transfer_contextp = |
| 494 | src_ring->per_transfer_context[sw_index]; |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 495 | |
| 496 | src_ring->per_transfer_context[sw_index] = 0; /* sanity */ |
| 497 | |
| 498 | /* Update sw_index */ |
| 499 | sw_index = CE_RING_IDX_INCR(nentries_mask, sw_index); |
| 500 | src_ring->sw_index = sw_index; |
| 501 | status = QDF_STATUS_SUCCESS; |
| 502 | } |
Pamidipati, Vijay | dfe618e | 2016-10-09 09:17:24 +0530 | [diff] [blame] | 503 | hal_srng_access_end_reap(scn->hal_soc, src_ring->srng_ctx); |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 504 | |
| 505 | return status; |
| 506 | } |
| 507 | |
| 508 | /* NB: Modelled after ce_completed_send_next */ |
Jeff Johnson | 0571813 | 2016-12-17 10:18:17 -0800 | [diff] [blame] | 509 | static QDF_STATUS |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 510 | ce_cancel_send_next_srng(struct CE_handle *copyeng, |
| 511 | void **per_CE_contextp, |
| 512 | void **per_transfer_contextp, |
| 513 | qdf_dma_addr_t *bufferp, |
| 514 | unsigned int *nbytesp, |
| 515 | unsigned int *transfer_idp, |
| 516 | uint32_t *toeplitz_hash_result) |
| 517 | { |
Kiran Venkatappa | 55d3a20 | 2016-12-20 11:29:34 +0530 | [diff] [blame] | 518 | return QDF_STATUS_E_INVAL; |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | /* Shift bits to convert IS_*_RING_*_WATERMARK_MASK to CE_WM_FLAG_*_* */ |
| 522 | #define CE_WM_SHFT 1 |
| 523 | |
| 524 | /* |
| 525 | * Number of times to check for any pending tx/rx completion on |
| 526 | * a copy engine, this count should be big enough. Once we hit |
| 527 | * this threashold we'll not check for any Tx/Rx comlpetion in same |
| 528 | * interrupt handling. Note that this threashold is only used for |
| 529 | * Rx interrupt processing, this can be used tor Tx as well if we |
| 530 | * suspect any infinite loop in checking for pending Tx completion. |
| 531 | */ |
| 532 | #define CE_TXRX_COMP_CHECK_THRESHOLD 20 |
| 533 | |
| 534 | /* |
| 535 | * Adjust interrupts for the copy complete handler. |
| 536 | * If it's needed for either send or recv, then unmask |
| 537 | * this interrupt; otherwise, mask it. |
| 538 | * |
| 539 | * Called with target_lock held. |
| 540 | */ |
| 541 | static void |
| 542 | ce_per_engine_handler_adjust_srng(struct CE_state *CE_state, |
| 543 | int disable_copy_compl_intr) |
| 544 | { |
| 545 | } |
| 546 | |
Jeff Johnson | 0571813 | 2016-12-17 10:18:17 -0800 | [diff] [blame] | 547 | static bool ce_check_int_watermark_srng(struct CE_state *CE_state, |
| 548 | unsigned int *flags) |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 549 | { |
| 550 | /*TODO*/ |
| 551 | return false; |
| 552 | } |
| 553 | |
Jeff Johnson | 0571813 | 2016-12-17 10:18:17 -0800 | [diff] [blame] | 554 | static uint32_t ce_get_desc_size_srng(uint8_t ring_type) |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 555 | { |
| 556 | switch (ring_type) { |
| 557 | case CE_RING_SRC: |
| 558 | return sizeof(struct ce_srng_src_desc); |
| 559 | case CE_RING_DEST: |
| 560 | return sizeof(struct ce_srng_dest_desc); |
| 561 | case CE_RING_STATUS: |
| 562 | return sizeof(struct ce_srng_dest_status_desc); |
| 563 | default: |
| 564 | return 0; |
| 565 | } |
| 566 | return 0; |
| 567 | } |
| 568 | |
Houston Hoffman | 1501077 | 2016-09-16 14:01:13 -0700 | [diff] [blame] | 569 | static void ce_srng_msi_ring_params_setup(struct hif_softc *scn, uint32_t ce_id, |
| 570 | struct hal_srng_params *ring_params) |
| 571 | { |
| 572 | uint32_t addr_low; |
| 573 | uint32_t addr_high; |
| 574 | uint32_t msi_data_start; |
| 575 | uint32_t msi_data_count; |
| 576 | uint32_t msi_irq_start; |
| 577 | int ret; |
| 578 | |
| 579 | ret = pld_get_user_msi_assignment(scn->qdf_dev->dev, "CE", |
| 580 | &msi_data_count, &msi_data_start, |
| 581 | &msi_irq_start); |
| 582 | |
| 583 | /* msi config not found */ |
| 584 | if (ret) |
| 585 | return; |
| 586 | |
| 587 | HIF_INFO("%s: ce_id %d, msi_start: %d, msi_count %d", __func__, ce_id, |
| 588 | msi_data_start, msi_data_count); |
| 589 | |
| 590 | pld_get_msi_address(scn->qdf_dev->dev, &addr_low, &addr_high); |
| 591 | |
| 592 | ring_params->msi_addr = addr_low; |
| 593 | ring_params->msi_addr |= (qdf_dma_addr_t)(((uint64_t)addr_high) << 32); |
| 594 | ring_params->msi_data = (ce_id % msi_data_count) + msi_data_start; |
| 595 | ring_params->flags |= HAL_SRNG_MSI_INTR; |
| 596 | |
| 597 | HIF_INFO("%s: ce_id %d, msi_addr %p, msi_data %d", __func__, ce_id, |
| 598 | (void *)ring_params->msi_addr, ring_params->msi_data); |
| 599 | } |
| 600 | |
Jeff Johnson | 0571813 | 2016-12-17 10:18:17 -0800 | [diff] [blame] | 601 | 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] | 602 | struct CE_ring_state *src_ring) |
| 603 | { |
| 604 | struct hal_srng_params ring_params = {0}; |
| 605 | |
Houston Hoffman | 1501077 | 2016-09-16 14:01:13 -0700 | [diff] [blame] | 606 | HIF_INFO("%s: ce_id %d", __func__, ce_id); |
| 607 | |
| 608 | ce_srng_msi_ring_params_setup(scn, ce_id, &ring_params); |
| 609 | |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 610 | ring_params.ring_base_paddr = src_ring->base_addr_CE_space; |
| 611 | ring_params.ring_base_vaddr = src_ring->base_addr_owner_space; |
| 612 | ring_params.num_entries = src_ring->nentries; |
Houston Hoffman | 202425d | 2016-10-17 19:42:48 -0700 | [diff] [blame] | 613 | /* |
| 614 | * The minimum increment for the timer is 8us |
| 615 | * A default value of 0 disables the timer |
| 616 | * A valid default value caused continuous interrupts to |
| 617 | * fire with MSI enabled. Need to revisit usage of the timer |
| 618 | */ |
| 619 | ring_params.intr_timer_thres_us = 0; |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 620 | ring_params.intr_batch_cntr_thres_entries = 1; |
| 621 | |
| 622 | /* TODO |
| 623 | * ring_params.msi_addr = XXX; |
| 624 | * ring_params.msi_data = XXX; |
| 625 | * ring_params.flags = XXX; |
| 626 | */ |
| 627 | |
| 628 | src_ring->srng_ctx = hal_srng_setup(scn->hal_soc, CE_SRC, ce_id, 0, |
| 629 | &ring_params); |
| 630 | } |
| 631 | |
Jeff Johnson | 0571813 | 2016-12-17 10:18:17 -0800 | [diff] [blame] | 632 | 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] | 633 | struct CE_ring_state *dest_ring, |
| 634 | struct CE_attr *attr) |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 635 | { |
| 636 | struct hal_srng_params ring_params = {0}; |
| 637 | |
Houston Hoffman | 1501077 | 2016-09-16 14:01:13 -0700 | [diff] [blame] | 638 | HIF_INFO("%s: ce_id %d", __func__, ce_id); |
| 639 | |
| 640 | ce_srng_msi_ring_params_setup(scn, ce_id, &ring_params); |
| 641 | |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 642 | ring_params.ring_base_paddr = dest_ring->base_addr_CE_space; |
| 643 | ring_params.ring_base_vaddr = dest_ring->base_addr_owner_space; |
| 644 | ring_params.num_entries = dest_ring->nentries; |
Houston Hoffman | 202425d | 2016-10-17 19:42:48 -0700 | [diff] [blame] | 645 | ring_params.intr_timer_thres_us = 0; |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 646 | ring_params.intr_batch_cntr_thres_entries = 1; |
Houston Hoffman | 7410912 | 2016-10-21 14:58:34 -0700 | [diff] [blame] | 647 | ring_params.max_buffer_length = attr->src_sz_max; |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 648 | |
| 649 | /* TODO |
| 650 | * ring_params.msi_addr = XXX; |
| 651 | * ring_params.msi_data = XXX; |
| 652 | * ring_params.flags = XXX; |
| 653 | */ |
| 654 | |
| 655 | /*Dest ring is also source ring*/ |
| 656 | dest_ring->srng_ctx = hal_srng_setup(scn->hal_soc, CE_DST, ce_id, 0, |
| 657 | &ring_params); |
| 658 | } |
| 659 | |
Jeff Johnson | 0571813 | 2016-12-17 10:18:17 -0800 | [diff] [blame] | 660 | 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] | 661 | struct CE_ring_state *status_ring) |
| 662 | { |
| 663 | struct hal_srng_params ring_params = {0}; |
| 664 | |
Houston Hoffman | 1501077 | 2016-09-16 14:01:13 -0700 | [diff] [blame] | 665 | HIF_INFO("%s: ce_id %d", __func__, ce_id); |
| 666 | |
| 667 | ce_srng_msi_ring_params_setup(scn, ce_id, &ring_params); |
| 668 | |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 669 | ring_params.ring_base_paddr = status_ring->base_addr_CE_space; |
| 670 | ring_params.ring_base_vaddr = status_ring->base_addr_owner_space; |
| 671 | ring_params.num_entries = status_ring->nentries; |
Houston Hoffman | 202425d | 2016-10-17 19:42:48 -0700 | [diff] [blame] | 672 | ring_params.intr_timer_thres_us = 0; |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 673 | ring_params.intr_batch_cntr_thres_entries = 1; |
| 674 | |
| 675 | /* TODO |
| 676 | * ring_params.msi_addr = XXX; |
| 677 | * ring_params.msi_data = XXX; |
| 678 | * ring_params.flags = XXX; |
| 679 | */ |
| 680 | |
| 681 | status_ring->srng_ctx = hal_srng_setup(scn->hal_soc, CE_DST_STATUS, |
| 682 | ce_id, 0, &ring_params); |
| 683 | } |
| 684 | |
Jeff Johnson | 0571813 | 2016-12-17 10:18:17 -0800 | [diff] [blame] | 685 | 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] | 686 | uint32_t ce_id, struct CE_ring_state *ring, |
| 687 | struct CE_attr *attr) |
| 688 | { |
| 689 | switch (ring_type) { |
| 690 | case CE_RING_SRC: |
| 691 | ce_srng_src_ring_setup(scn, ce_id, ring); |
| 692 | break; |
| 693 | case CE_RING_DEST: |
Houston Hoffman | 7410912 | 2016-10-21 14:58:34 -0700 | [diff] [blame] | 694 | ce_srng_dest_ring_setup(scn, ce_id, ring, attr); |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 695 | break; |
| 696 | case CE_RING_STATUS: |
| 697 | ce_srng_status_ring_setup(scn, ce_id, ring); |
| 698 | break; |
| 699 | default: |
| 700 | qdf_assert(0); |
| 701 | break; |
| 702 | } |
| 703 | } |
Jeff Johnson | 0571813 | 2016-12-17 10:18:17 -0800 | [diff] [blame] | 704 | |
Houston Hoffman | 10fedfc | 2017-01-23 15:23:09 -0800 | [diff] [blame] | 705 | static void ce_construct_shadow_config_srng(struct hif_softc *scn) |
| 706 | { |
| 707 | struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn); |
| 708 | int ce_id; |
| 709 | |
| 710 | for (ce_id = 0; ce_id < scn->ce_count; ce_id++) { |
| 711 | if (hif_state->host_ce_config[ce_id].src_nentries) |
| 712 | hal_set_one_shadow_config(scn->hal_soc, |
| 713 | CE_SRC, ce_id); |
| 714 | |
| 715 | if (hif_state->host_ce_config[ce_id].dest_nentries) { |
| 716 | hal_set_one_shadow_config(scn->hal_soc, |
| 717 | CE_DST, ce_id); |
| 718 | |
| 719 | hal_set_one_shadow_config(scn->hal_soc, |
| 720 | CE_DST_STATUS, ce_id); |
| 721 | } |
| 722 | } |
| 723 | } |
| 724 | |
| 725 | static void ce_prepare_shadow_register_v2_cfg_srng(struct hif_softc *scn, |
| 726 | struct pld_shadow_reg_v2_cfg **shadow_config, |
| 727 | int *num_shadow_registers_configured) |
| 728 | { |
| 729 | if (scn->hal_soc == NULL) { |
| 730 | HIF_ERROR("%s: hal not initialized: not initializing shadow config", |
| 731 | __func__); |
| 732 | return; |
| 733 | } |
| 734 | |
| 735 | hal_get_shadow_config(scn->hal_soc, shadow_config, |
| 736 | num_shadow_registers_configured); |
| 737 | |
| 738 | if (*num_shadow_registers_configured != 0) { |
| 739 | HIF_ERROR("%s: hal shadow register configuration allready constructed", |
| 740 | __func__); |
| 741 | |
| 742 | /* return with original configuration*/ |
| 743 | return; |
| 744 | } |
| 745 | |
| 746 | hal_construct_shadow_config(scn->hal_soc); |
| 747 | ce_construct_shadow_config_srng(scn); |
| 748 | |
| 749 | /* get updated configuration */ |
| 750 | hal_get_shadow_config(scn->hal_soc, shadow_config, |
| 751 | num_shadow_registers_configured); |
| 752 | } |
| 753 | |
Jeff Johnson | 0571813 | 2016-12-17 10:18:17 -0800 | [diff] [blame] | 754 | static struct ce_ops ce_service_srng = { |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 755 | .ce_get_desc_size = ce_get_desc_size_srng, |
| 756 | .ce_ring_setup = ce_ring_setup_srng, |
| 757 | .ce_sendlist_send = ce_sendlist_send_srng, |
| 758 | .ce_completed_recv_next_nolock = ce_completed_recv_next_nolock_srng, |
| 759 | .ce_revoke_recv_next = ce_revoke_recv_next_srng, |
| 760 | .ce_cancel_send_next = ce_cancel_send_next_srng, |
| 761 | .ce_recv_buf_enqueue = ce_recv_buf_enqueue_srng, |
| 762 | .ce_per_engine_handler_adjust = ce_per_engine_handler_adjust_srng, |
| 763 | .ce_send_nolock = ce_send_nolock_srng, |
| 764 | .watermark_int = ce_check_int_watermark_srng, |
| 765 | .ce_completed_send_next_nolock = ce_completed_send_next_nolock_srng, |
| 766 | .ce_recv_entries_done_nolock = ce_recv_entries_done_nolock_srng, |
| 767 | .ce_send_entries_done_nolock = ce_send_entries_done_nolock_srng, |
Houston Hoffman | 10fedfc | 2017-01-23 15:23:09 -0800 | [diff] [blame] | 768 | .ce_prepare_shadow_register_v2_cfg = |
| 769 | ce_prepare_shadow_register_v2_cfg_srng, |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 770 | }; |
| 771 | |
| 772 | struct ce_ops *ce_services_srng() |
| 773 | { |
| 774 | return &ce_service_srng; |
| 775 | } |