blob: 2813a83e5e5e967949d10637726ad6f2daf5803a [file] [log] [blame]
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05301/*
Jeff Johnson05718132016-12-17 10:18:17 -08002 * Copyright (c) 2016-2017 The Linux Foundation. All rights reserved.
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05303 *
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 Hoffman15010772016-09-16 14:01:13 -070031#include "pld_common.h"
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +053032
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 Johnson05718132016-12-17 10:18:17 -080080static int
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +053081ce_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 Johnson05718132016-12-17 10:18:17 -0800157static int
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530158ce_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 Hoffman9a1b3912016-10-17 18:56:32 -0700210 sizeof(((qdf_nbuf_t)per_transfer_context)->data), QDF_TX));
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530211 } 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 Johnson05718132016-12-17 10:18:17 -0800237static int
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530238ce_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 Venkatappaf41ef2e2016-09-05 10:59:58 +0530294/*
295 * Guts of ce_recv_entries_done.
296 * The caller takes responsibility for any necessary locking.
297 */
Jeff Johnson05718132016-12-17 10:18:17 -0800298static unsigned int
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530299ce_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 Johnson05718132016-12-17 10:18:17 -0800312static unsigned int
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530313ce_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 Venkatappaf41ef2e2016-09-05 10:59:58 +0530330/*
331 * Guts of ce_completed_recv_next.
332 * The caller takes responsibility for any necessary locking.
333 */
Jeff Johnson05718132016-12-17 10:18:17 -0800334static int
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530335ce_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 Venkatappaf41ef2e2016-09-05 10:59:58 +0530395 if (per_transfer_contextp)
Houston Hoffman3274fbc2017-01-26 22:32:26 -0800396 *per_transfer_contextp =
397 dest_ring->per_transfer_context[sw_index];
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530398
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
406done:
407 hal_srng_access_end(scn->hal_soc, status_ring->srng_ctx);
408
409 return status;
410}
411
Jeff Johnson05718132016-12-17 10:18:17 -0800412static QDF_STATUS
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530413ce_revoke_recv_next_srng(struct CE_handle *copyeng,
414 void **per_CE_contextp,
415 void **per_transfer_contextp, qdf_dma_addr_t *bufferp)
416{
417 QDF_STATUS status = QDF_STATUS_E_FAILURE;
418
419 return status;
420}
421
422/*
423 * Guts of ce_completed_send_next.
424 * The caller takes responsibility for any necessary locking.
425 */
Jeff Johnson05718132016-12-17 10:18:17 -0800426static int
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530427ce_completed_send_next_nolock_srng(struct CE_state *CE_state,
428 void **per_CE_contextp,
429 void **per_transfer_contextp,
430 qdf_dma_addr_t *bufferp,
431 unsigned int *nbytesp,
432 unsigned int *transfer_idp,
433 unsigned int *sw_idx,
434 unsigned int *hw_idx,
435 uint32_t *toeplitz_hash_result)
436{
437 int status = QDF_STATUS_E_FAILURE;
438 struct CE_ring_state *src_ring = CE_state->src_ring;
439 unsigned int nentries_mask = src_ring->nentries_mask;
440 unsigned int sw_index = src_ring->sw_index;
441 struct hif_softc *scn = CE_state->scn;
442 struct ce_srng_src_desc *src_desc;
443
444 if (hal_srng_access_start(scn->hal_soc, src_ring->srng_ctx)) {
445 status = QDF_STATUS_E_FAILURE;
446 return status;
447 }
448
449 src_desc = hal_srng_src_reap_next(scn->hal_soc, src_ring->srng_ctx);
450 if (src_desc) {
451
452 /* Return data from completed source descriptor */
453 *bufferp = (qdf_dma_addr_t)
454 (((uint64_t)(src_desc)->buffer_addr_lo +
455 ((uint64_t)((src_desc)->buffer_addr_hi &
456 0xFF) << 32)));
457 *nbytesp = src_desc->nbytes;
458 *transfer_idp = src_desc->meta_data;
459 *toeplitz_hash_result = 0; /*src_desc->toeplitz_hash_result;*/
460
461 if (per_CE_contextp)
462 *per_CE_contextp = CE_state->send_context;
463
464 /* sw_index is used more like read index */
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530465 if (per_transfer_contextp)
Houston Hoffman3274fbc2017-01-26 22:32:26 -0800466 *per_transfer_contextp =
467 src_ring->per_transfer_context[sw_index];
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530468
469 src_ring->per_transfer_context[sw_index] = 0; /* sanity */
470
471 /* Update sw_index */
472 sw_index = CE_RING_IDX_INCR(nentries_mask, sw_index);
473 src_ring->sw_index = sw_index;
474 status = QDF_STATUS_SUCCESS;
475 }
Pamidipati, Vijaydfe618e2016-10-09 09:17:24 +0530476 hal_srng_access_end_reap(scn->hal_soc, src_ring->srng_ctx);
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530477
478 return status;
479}
480
481/* NB: Modelled after ce_completed_send_next */
Jeff Johnson05718132016-12-17 10:18:17 -0800482static QDF_STATUS
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530483ce_cancel_send_next_srng(struct CE_handle *copyeng,
484 void **per_CE_contextp,
485 void **per_transfer_contextp,
486 qdf_dma_addr_t *bufferp,
487 unsigned int *nbytesp,
488 unsigned int *transfer_idp,
489 uint32_t *toeplitz_hash_result)
490{
Kiran Venkatappa55d3a202016-12-20 11:29:34 +0530491 return QDF_STATUS_E_INVAL;
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530492}
493
494/* Shift bits to convert IS_*_RING_*_WATERMARK_MASK to CE_WM_FLAG_*_* */
495#define CE_WM_SHFT 1
496
497/*
498 * Number of times to check for any pending tx/rx completion on
499 * a copy engine, this count should be big enough. Once we hit
500 * this threashold we'll not check for any Tx/Rx comlpetion in same
501 * interrupt handling. Note that this threashold is only used for
502 * Rx interrupt processing, this can be used tor Tx as well if we
503 * suspect any infinite loop in checking for pending Tx completion.
504 */
505#define CE_TXRX_COMP_CHECK_THRESHOLD 20
506
507/*
508 * Adjust interrupts for the copy complete handler.
509 * If it's needed for either send or recv, then unmask
510 * this interrupt; otherwise, mask it.
511 *
512 * Called with target_lock held.
513 */
514static void
515ce_per_engine_handler_adjust_srng(struct CE_state *CE_state,
516 int disable_copy_compl_intr)
517{
518}
519
Jeff Johnson05718132016-12-17 10:18:17 -0800520static bool ce_check_int_watermark_srng(struct CE_state *CE_state,
521 unsigned int *flags)
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530522{
523 /*TODO*/
524 return false;
525}
526
Jeff Johnson05718132016-12-17 10:18:17 -0800527static uint32_t ce_get_desc_size_srng(uint8_t ring_type)
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530528{
529 switch (ring_type) {
530 case CE_RING_SRC:
531 return sizeof(struct ce_srng_src_desc);
532 case CE_RING_DEST:
533 return sizeof(struct ce_srng_dest_desc);
534 case CE_RING_STATUS:
535 return sizeof(struct ce_srng_dest_status_desc);
536 default:
537 return 0;
538 }
539 return 0;
540}
541
Houston Hoffman15010772016-09-16 14:01:13 -0700542static void ce_srng_msi_ring_params_setup(struct hif_softc *scn, uint32_t ce_id,
543 struct hal_srng_params *ring_params)
544{
545 uint32_t addr_low;
546 uint32_t addr_high;
547 uint32_t msi_data_start;
548 uint32_t msi_data_count;
549 uint32_t msi_irq_start;
550 int ret;
551
552 ret = pld_get_user_msi_assignment(scn->qdf_dev->dev, "CE",
553 &msi_data_count, &msi_data_start,
554 &msi_irq_start);
555
556 /* msi config not found */
557 if (ret)
558 return;
559
560 HIF_INFO("%s: ce_id %d, msi_start: %d, msi_count %d", __func__, ce_id,
561 msi_data_start, msi_data_count);
562
563 pld_get_msi_address(scn->qdf_dev->dev, &addr_low, &addr_high);
564
565 ring_params->msi_addr = addr_low;
566 ring_params->msi_addr |= (qdf_dma_addr_t)(((uint64_t)addr_high) << 32);
567 ring_params->msi_data = (ce_id % msi_data_count) + msi_data_start;
568 ring_params->flags |= HAL_SRNG_MSI_INTR;
569
570 HIF_INFO("%s: ce_id %d, msi_addr %p, msi_data %d", __func__, ce_id,
571 (void *)ring_params->msi_addr, ring_params->msi_data);
572}
573
Jeff Johnson05718132016-12-17 10:18:17 -0800574static void ce_srng_src_ring_setup(struct hif_softc *scn, uint32_t ce_id,
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530575 struct CE_ring_state *src_ring)
576{
577 struct hal_srng_params ring_params = {0};
578
Houston Hoffman15010772016-09-16 14:01:13 -0700579 HIF_INFO("%s: ce_id %d", __func__, ce_id);
580
581 ce_srng_msi_ring_params_setup(scn, ce_id, &ring_params);
582
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530583 ring_params.ring_base_paddr = src_ring->base_addr_CE_space;
584 ring_params.ring_base_vaddr = src_ring->base_addr_owner_space;
585 ring_params.num_entries = src_ring->nentries;
Houston Hoffman202425d2016-10-17 19:42:48 -0700586 /*
587 * The minimum increment for the timer is 8us
588 * A default value of 0 disables the timer
589 * A valid default value caused continuous interrupts to
590 * fire with MSI enabled. Need to revisit usage of the timer
591 */
592 ring_params.intr_timer_thres_us = 0;
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530593 ring_params.intr_batch_cntr_thres_entries = 1;
594
595 /* TODO
596 * ring_params.msi_addr = XXX;
597 * ring_params.msi_data = XXX;
598 * ring_params.flags = XXX;
599 */
600
601 src_ring->srng_ctx = hal_srng_setup(scn->hal_soc, CE_SRC, ce_id, 0,
602 &ring_params);
603}
604
Jeff Johnson05718132016-12-17 10:18:17 -0800605static void ce_srng_dest_ring_setup(struct hif_softc *scn, uint32_t ce_id,
Houston Hoffman74109122016-10-21 14:58:34 -0700606 struct CE_ring_state *dest_ring,
607 struct CE_attr *attr)
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530608{
609 struct hal_srng_params ring_params = {0};
610
Houston Hoffman15010772016-09-16 14:01:13 -0700611 HIF_INFO("%s: ce_id %d", __func__, ce_id);
612
613 ce_srng_msi_ring_params_setup(scn, ce_id, &ring_params);
614
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530615 ring_params.ring_base_paddr = dest_ring->base_addr_CE_space;
616 ring_params.ring_base_vaddr = dest_ring->base_addr_owner_space;
617 ring_params.num_entries = dest_ring->nentries;
Houston Hoffman202425d2016-10-17 19:42:48 -0700618 ring_params.intr_timer_thres_us = 0;
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530619 ring_params.intr_batch_cntr_thres_entries = 1;
Houston Hoffman74109122016-10-21 14:58:34 -0700620 ring_params.max_buffer_length = attr->src_sz_max;
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530621
622 /* TODO
623 * ring_params.msi_addr = XXX;
624 * ring_params.msi_data = XXX;
625 * ring_params.flags = XXX;
626 */
627
628 /*Dest ring is also source ring*/
629 dest_ring->srng_ctx = hal_srng_setup(scn->hal_soc, CE_DST, ce_id, 0,
630 &ring_params);
631}
632
Jeff Johnson05718132016-12-17 10:18:17 -0800633static void ce_srng_status_ring_setup(struct hif_softc *scn, uint32_t ce_id,
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530634 struct CE_ring_state *status_ring)
635{
636 struct hal_srng_params ring_params = {0};
637
Houston Hoffman15010772016-09-16 14:01:13 -0700638 HIF_INFO("%s: ce_id %d", __func__, ce_id);
639
640 ce_srng_msi_ring_params_setup(scn, ce_id, &ring_params);
641
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530642 ring_params.ring_base_paddr = status_ring->base_addr_CE_space;
643 ring_params.ring_base_vaddr = status_ring->base_addr_owner_space;
644 ring_params.num_entries = status_ring->nentries;
Houston Hoffman202425d2016-10-17 19:42:48 -0700645 ring_params.intr_timer_thres_us = 0;
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530646 ring_params.intr_batch_cntr_thres_entries = 1;
647
648 /* TODO
649 * ring_params.msi_addr = XXX;
650 * ring_params.msi_data = XXX;
651 * ring_params.flags = XXX;
652 */
653
654 status_ring->srng_ctx = hal_srng_setup(scn->hal_soc, CE_DST_STATUS,
655 ce_id, 0, &ring_params);
656}
657
Jeff Johnson05718132016-12-17 10:18:17 -0800658static void ce_ring_setup_srng(struct hif_softc *scn, uint8_t ring_type,
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530659 uint32_t ce_id, struct CE_ring_state *ring,
660 struct CE_attr *attr)
661{
662 switch (ring_type) {
663 case CE_RING_SRC:
664 ce_srng_src_ring_setup(scn, ce_id, ring);
665 break;
666 case CE_RING_DEST:
Houston Hoffman74109122016-10-21 14:58:34 -0700667 ce_srng_dest_ring_setup(scn, ce_id, ring, attr);
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530668 break;
669 case CE_RING_STATUS:
670 ce_srng_status_ring_setup(scn, ce_id, ring);
671 break;
672 default:
673 qdf_assert(0);
674 break;
675 }
676}
Jeff Johnson05718132016-12-17 10:18:17 -0800677
Houston Hoffman10fedfc2017-01-23 15:23:09 -0800678static void ce_construct_shadow_config_srng(struct hif_softc *scn)
679{
680 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
681 int ce_id;
682
683 for (ce_id = 0; ce_id < scn->ce_count; ce_id++) {
684 if (hif_state->host_ce_config[ce_id].src_nentries)
685 hal_set_one_shadow_config(scn->hal_soc,
686 CE_SRC, ce_id);
687
688 if (hif_state->host_ce_config[ce_id].dest_nentries) {
689 hal_set_one_shadow_config(scn->hal_soc,
690 CE_DST, ce_id);
691
692 hal_set_one_shadow_config(scn->hal_soc,
693 CE_DST_STATUS, ce_id);
694 }
695 }
696}
697
698static void ce_prepare_shadow_register_v2_cfg_srng(struct hif_softc *scn,
699 struct pld_shadow_reg_v2_cfg **shadow_config,
700 int *num_shadow_registers_configured)
701{
702 if (scn->hal_soc == NULL) {
703 HIF_ERROR("%s: hal not initialized: not initializing shadow config",
704 __func__);
705 return;
706 }
707
708 hal_get_shadow_config(scn->hal_soc, shadow_config,
709 num_shadow_registers_configured);
710
711 if (*num_shadow_registers_configured != 0) {
712 HIF_ERROR("%s: hal shadow register configuration allready constructed",
713 __func__);
714
715 /* return with original configuration*/
716 return;
717 }
718
719 hal_construct_shadow_config(scn->hal_soc);
720 ce_construct_shadow_config_srng(scn);
721
722 /* get updated configuration */
723 hal_get_shadow_config(scn->hal_soc, shadow_config,
724 num_shadow_registers_configured);
725}
726
Jeff Johnson05718132016-12-17 10:18:17 -0800727static struct ce_ops ce_service_srng = {
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530728 .ce_get_desc_size = ce_get_desc_size_srng,
729 .ce_ring_setup = ce_ring_setup_srng,
730 .ce_sendlist_send = ce_sendlist_send_srng,
731 .ce_completed_recv_next_nolock = ce_completed_recv_next_nolock_srng,
732 .ce_revoke_recv_next = ce_revoke_recv_next_srng,
733 .ce_cancel_send_next = ce_cancel_send_next_srng,
734 .ce_recv_buf_enqueue = ce_recv_buf_enqueue_srng,
735 .ce_per_engine_handler_adjust = ce_per_engine_handler_adjust_srng,
736 .ce_send_nolock = ce_send_nolock_srng,
737 .watermark_int = ce_check_int_watermark_srng,
738 .ce_completed_send_next_nolock = ce_completed_send_next_nolock_srng,
739 .ce_recv_entries_done_nolock = ce_recv_entries_done_nolock_srng,
740 .ce_send_entries_done_nolock = ce_send_entries_done_nolock_srng,
Houston Hoffman10fedfc2017-01-23 15:23:09 -0800741 .ce_prepare_shadow_register_v2_cfg =
742 ce_prepare_shadow_register_v2_cfg_srng,
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530743};
744
745struct ce_ops *ce_services_srng()
746{
747 return &ce_service_srng;
748}