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