blob: 8e31cd507babb0ee7f9aa708d93e64518bf86edd [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
551 msdu = msdus[i];
552
553 /*
554 * First fill out the ring descriptor for the HTC HTT frame
555 * header. These are uncached writes. Should we use a local
556 * structure instead?
557 */
558 /* HTT/HTC header can be passed as a argument */
559 dma_addr = cdf_nbuf_get_frag_paddr_lo(msdu, 0);
560 shadow_src_desc->buffer_addr = (uint32_t)(dma_addr &
561 0xFFFFFFFF);
562 user_flags = cdf_nbuf_data_attr_get(msdu) & DESC_DATA_FLAG_MASK;
563 ce_buffer_addr_hi_set(shadow_src_desc, dma_addr, user_flags);
564
565 shadow_src_desc->meta_data = transfer_id;
566 shadow_src_desc->nbytes = cdf_nbuf_get_frag_len(msdu, 0);
567
568 /*
569 * HTC HTT header is a word stream, so byte swap if CE byte
570 * swap enabled
571 */
572 shadow_src_desc->byte_swap = ((ce_state->attr_flags &
573 CE_ATTR_BYTE_SWAP_DATA) != 0);
574 /* For the first one, it still does not need to write */
575 shadow_src_desc->gather = 1;
576 *src_desc = *shadow_src_desc;
577
578 /* By default we could initialize the transfer context to this
579 * value
580 */
581 src_ring->per_transfer_context[write_index] =
582 CE_SENDLIST_ITEM_CTXT;
583
584 write_index = CE_RING_IDX_INCR(nentries_mask, write_index);
585
586 src_desc = CE_SRC_RING_TO_DESC(src_ring_base, write_index);
587 shadow_src_desc = CE_SRC_RING_TO_DESC(shadow_base, write_index);
588 /*
589 * Now fill out the ring descriptor for the actual data
590 * packet
591 */
592 dma_addr = cdf_nbuf_get_frag_paddr_lo(msdu, 1);
593 shadow_src_desc->buffer_addr = (uint32_t)(dma_addr &
594 0xFFFFFFFF);
595 /*
596 * Clear packet offset for all but the first CE desc.
597 */
598 user_flags &= ~CDF_CE_TX_PKT_OFFSET_BIT_M;
599 ce_buffer_addr_hi_set(shadow_src_desc, dma_addr, user_flags);
600 shadow_src_desc->meta_data = transfer_id;
601
602 /* get actual packet length */
603 frag_len = cdf_nbuf_get_frag_len(msdu, 1);
Houston Hoffmana5e74c12015-09-02 18:06:28 -0700604
605 /* only read download_len once */
606 shadow_src_desc->nbytes = ce_state->download_len;
607 if (shadow_src_desc->nbytes > frag_len)
608 shadow_src_desc->nbytes = frag_len;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800609
610 /* Data packet is a byte stream, so disable byte swap */
611 shadow_src_desc->byte_swap = 0;
612 /* For the last one, gather is not set */
613 shadow_src_desc->gather = 0;
614 *src_desc = *shadow_src_desc;
615 src_ring->per_transfer_context[write_index] = msdu;
616 write_index = CE_RING_IDX_INCR(nentries_mask, write_index);
617 }
618
619 /* Write the final index to h/w one-shot */
620 if (i) {
621 src_ring->write_index = write_index;
622 /* Don't call WAR_XXX from here
623 * Just call XXX instead, that has the reqd. intel
624 */
625 war_ce_src_ring_write_idx_set(scn, ctrl_addr, write_index);
626 }
627
Houston Hoffman44b7e4a2015-09-03 17:01:22 -0700628 cdf_spin_unlock_bh(&ce_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800629
630 /*
631 * If all packets in the array are transmitted,
632 * i = num_msdus
633 * Temporarily add an ASSERT
634 */
635 ASSERT(i == num_msdus);
636 return i;
637}
638#endif /* WLAN_FEATURE_FASTPATH */
639
640int
641ce_recv_buf_enqueue(struct CE_handle *copyeng,
642 void *per_recv_context, cdf_dma_addr_t buffer)
643{
644 int status;
645 struct CE_state *CE_state = (struct CE_state *)copyeng;
646 struct CE_ring_state *dest_ring = CE_state->dest_ring;
647 uint32_t ctrl_addr = CE_state->ctrl_addr;
648 unsigned int nentries_mask = dest_ring->nentries_mask;
649 unsigned int write_index;
650 unsigned int sw_index;
651 int val = 0;
652 uint64_t dma_addr = buffer;
653 struct ol_softc *scn = CE_state->scn;
654
Houston Hoffman44b7e4a2015-09-03 17:01:22 -0700655 cdf_spin_lock_bh(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800656 write_index = dest_ring->write_index;
657 sw_index = dest_ring->sw_index;
658
659 A_TARGET_ACCESS_BEGIN_RET_EXT(scn, val);
660 if (val == -1) {
Houston Hoffman44b7e4a2015-09-03 17:01:22 -0700661 cdf_spin_unlock_bh(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800662 return val;
663 }
664
665 if (CE_RING_DELTA(nentries_mask, write_index, sw_index - 1) > 0) {
666 struct CE_dest_desc *dest_ring_base =
667 (struct CE_dest_desc *)dest_ring->
668 base_addr_owner_space;
669 struct CE_dest_desc *dest_desc =
670 CE_DEST_RING_TO_DESC(dest_ring_base, write_index);
671
672 /* Update low 32 bit destination descriptor */
673 dest_desc->buffer_addr = (uint32_t)(dma_addr & 0xFFFFFFFF);
674#ifdef QCA_WIFI_3_0
675 dest_desc->buffer_addr_hi =
676 (uint32_t)((dma_addr >> 32) & 0x1F);
677#endif
678 dest_desc->nbytes = 0;
679
680 dest_ring->per_transfer_context[write_index] =
681 per_recv_context;
682
Houston Hoffman68e837e2015-12-04 12:57:24 -0800683 hif_record_ce_desc_event(CE_state->id, HIF_RX_DESC_POST,
684 (union ce_desc *) dest_desc, per_recv_context,
685 write_index);
686
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800687 /* Update Destination Ring Write Index */
688 write_index = CE_RING_IDX_INCR(nentries_mask, write_index);
689 CE_DEST_RING_WRITE_IDX_SET(scn, ctrl_addr, write_index);
690 dest_ring->write_index = write_index;
691 status = CDF_STATUS_SUCCESS;
692 } else {
693 status = CDF_STATUS_E_FAILURE;
694 }
695 A_TARGET_ACCESS_END_RET_EXT(scn, val);
696 if (val == -1) {
Houston Hoffman44b7e4a2015-09-03 17:01:22 -0700697 cdf_spin_unlock_bh(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800698 return val;
699 }
700
Houston Hoffman44b7e4a2015-09-03 17:01:22 -0700701 cdf_spin_unlock_bh(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800702
703 return status;
704}
705
706void
707ce_send_watermarks_set(struct CE_handle *copyeng,
708 unsigned int low_alert_nentries,
709 unsigned int high_alert_nentries)
710{
711 struct CE_state *CE_state = (struct CE_state *)copyeng;
712 uint32_t ctrl_addr = CE_state->ctrl_addr;
713 struct ol_softc *scn = CE_state->scn;
714
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800715 CE_SRC_RING_LOWMARK_SET(scn, ctrl_addr, low_alert_nentries);
716 CE_SRC_RING_HIGHMARK_SET(scn, ctrl_addr, high_alert_nentries);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800717}
718
719void
720ce_recv_watermarks_set(struct CE_handle *copyeng,
721 unsigned int low_alert_nentries,
722 unsigned int high_alert_nentries)
723{
724 struct CE_state *CE_state = (struct CE_state *)copyeng;
725 uint32_t ctrl_addr = CE_state->ctrl_addr;
726 struct ol_softc *scn = CE_state->scn;
727
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800728 CE_DEST_RING_LOWMARK_SET(scn, ctrl_addr,
729 low_alert_nentries);
730 CE_DEST_RING_HIGHMARK_SET(scn, ctrl_addr,
731 high_alert_nentries);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800732}
733
734unsigned int ce_send_entries_avail(struct CE_handle *copyeng)
735{
736 struct CE_state *CE_state = (struct CE_state *)copyeng;
737 struct CE_ring_state *src_ring = CE_state->src_ring;
738 unsigned int nentries_mask = src_ring->nentries_mask;
739 unsigned int sw_index;
740 unsigned int write_index;
741
Houston Hoffman44b7e4a2015-09-03 17:01:22 -0700742 cdf_spin_lock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800743 sw_index = src_ring->sw_index;
744 write_index = src_ring->write_index;
Houston Hoffman44b7e4a2015-09-03 17:01:22 -0700745 cdf_spin_unlock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800746
747 return CE_RING_DELTA(nentries_mask, write_index, sw_index - 1);
748}
749
750unsigned int ce_recv_entries_avail(struct CE_handle *copyeng)
751{
752 struct CE_state *CE_state = (struct CE_state *)copyeng;
753 struct CE_ring_state *dest_ring = CE_state->dest_ring;
754 unsigned int nentries_mask = dest_ring->nentries_mask;
755 unsigned int sw_index;
756 unsigned int write_index;
757
Houston Hoffman44b7e4a2015-09-03 17:01:22 -0700758 cdf_spin_lock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800759 sw_index = dest_ring->sw_index;
760 write_index = dest_ring->write_index;
Houston Hoffman44b7e4a2015-09-03 17:01:22 -0700761 cdf_spin_unlock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800762
763 return CE_RING_DELTA(nentries_mask, write_index, sw_index - 1);
764}
765
766/*
767 * Guts of ce_send_entries_done.
768 * The caller takes responsibility for any necessary locking.
769 */
770unsigned int
771ce_send_entries_done_nolock(struct ol_softc *scn,
772 struct CE_state *CE_state)
773{
774 struct CE_ring_state *src_ring = CE_state->src_ring;
775 uint32_t ctrl_addr = CE_state->ctrl_addr;
776 unsigned int nentries_mask = src_ring->nentries_mask;
777 unsigned int sw_index;
778 unsigned int read_index;
779
780 sw_index = src_ring->sw_index;
781 read_index = CE_SRC_RING_READ_IDX_GET(scn, ctrl_addr);
782
783 return CE_RING_DELTA(nentries_mask, sw_index, read_index);
784}
785
786unsigned int ce_send_entries_done(struct CE_handle *copyeng)
787{
788 struct CE_state *CE_state = (struct CE_state *)copyeng;
789 unsigned int nentries;
790
Houston Hoffman44b7e4a2015-09-03 17:01:22 -0700791 cdf_spin_lock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800792 nentries = ce_send_entries_done_nolock(CE_state->scn, CE_state);
Houston Hoffman44b7e4a2015-09-03 17:01:22 -0700793 cdf_spin_unlock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800794
795 return nentries;
796}
797
798/*
799 * Guts of ce_recv_entries_done.
800 * The caller takes responsibility for any necessary locking.
801 */
802unsigned int
803ce_recv_entries_done_nolock(struct ol_softc *scn,
804 struct CE_state *CE_state)
805{
806 struct CE_ring_state *dest_ring = CE_state->dest_ring;
807 uint32_t ctrl_addr = CE_state->ctrl_addr;
808 unsigned int nentries_mask = dest_ring->nentries_mask;
809 unsigned int sw_index;
810 unsigned int read_index;
811
812 sw_index = dest_ring->sw_index;
813 read_index = CE_DEST_RING_READ_IDX_GET(scn, ctrl_addr);
814
815 return CE_RING_DELTA(nentries_mask, sw_index, read_index);
816}
817
818unsigned int ce_recv_entries_done(struct CE_handle *copyeng)
819{
820 struct CE_state *CE_state = (struct CE_state *)copyeng;
821 unsigned int nentries;
822
Houston Hoffman44b7e4a2015-09-03 17:01:22 -0700823 cdf_spin_lock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800824 nentries = ce_recv_entries_done_nolock(CE_state->scn, CE_state);
Houston Hoffman44b7e4a2015-09-03 17:01:22 -0700825 cdf_spin_unlock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800826
827 return nentries;
828}
829
830/* Debug support */
831void *ce_debug_cmplrn_context; /* completed recv next context */
832void *ce_debug_cnclsn_context; /* cancel send next context */
833void *ce_debug_rvkrn_context; /* revoke receive next context */
834void *ce_debug_cmplsn_context; /* completed send next context */
835
836/*
837 * Guts of ce_completed_recv_next.
838 * The caller takes responsibility for any necessary locking.
839 */
840int
841ce_completed_recv_next_nolock(struct CE_state *CE_state,
842 void **per_CE_contextp,
843 void **per_transfer_contextp,
844 cdf_dma_addr_t *bufferp,
845 unsigned int *nbytesp,
846 unsigned int *transfer_idp,
847 unsigned int *flagsp)
848{
849 int status;
850 struct CE_ring_state *dest_ring = CE_state->dest_ring;
851 unsigned int nentries_mask = dest_ring->nentries_mask;
852 unsigned int sw_index = dest_ring->sw_index;
853
854 struct CE_dest_desc *dest_ring_base =
855 (struct CE_dest_desc *)dest_ring->base_addr_owner_space;
856 struct CE_dest_desc *dest_desc =
857 CE_DEST_RING_TO_DESC(dest_ring_base, sw_index);
858 int nbytes;
859 struct CE_dest_desc dest_desc_info;
860 /*
861 * By copying the dest_desc_info element to local memory, we could
862 * avoid extra memory read from non-cachable memory.
863 */
864 dest_desc_info = *dest_desc;
865 nbytes = dest_desc_info.nbytes;
866 if (nbytes == 0) {
867 /*
868 * This closes a relatively unusual race where the Host
869 * sees the updated DRRI before the update to the
870 * corresponding descriptor has completed. We treat this
871 * as a descriptor that is not yet done.
872 */
873 status = CDF_STATUS_E_FAILURE;
874 goto done;
875 }
876
Houston Hoffman68e837e2015-12-04 12:57:24 -0800877 hif_record_ce_desc_event(CE_state->id, HIF_RX_DESC_COMPLETION,
878 (union ce_desc *) dest_desc,
879 dest_ring->per_transfer_context[sw_index],
880 sw_index);
881
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800882 dest_desc->nbytes = 0;
883
884 /* Return data from completed destination descriptor */
885 *bufferp = HIF_CE_DESC_ADDR_TO_DMA(&dest_desc_info);
886 *nbytesp = nbytes;
887 *transfer_idp = dest_desc_info.meta_data;
888 *flagsp = (dest_desc_info.byte_swap) ? CE_RECV_FLAG_SWAPPED : 0;
889
890 if (per_CE_contextp) {
891 *per_CE_contextp = CE_state->recv_context;
892 }
893
894 ce_debug_cmplrn_context = dest_ring->per_transfer_context[sw_index];
895 if (per_transfer_contextp) {
896 *per_transfer_contextp = ce_debug_cmplrn_context;
897 }
898 dest_ring->per_transfer_context[sw_index] = 0; /* sanity */
899
900 /* Update sw_index */
901 sw_index = CE_RING_IDX_INCR(nentries_mask, sw_index);
902 dest_ring->sw_index = sw_index;
903 status = CDF_STATUS_SUCCESS;
904
905done:
906 return status;
907}
908
909int
910ce_completed_recv_next(struct CE_handle *copyeng,
911 void **per_CE_contextp,
912 void **per_transfer_contextp,
913 cdf_dma_addr_t *bufferp,
914 unsigned int *nbytesp,
915 unsigned int *transfer_idp, unsigned int *flagsp)
916{
917 struct CE_state *CE_state = (struct CE_state *)copyeng;
918 int status;
919
Houston Hoffman44b7e4a2015-09-03 17:01:22 -0700920 cdf_spin_lock_bh(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800921 status =
922 ce_completed_recv_next_nolock(CE_state, per_CE_contextp,
923 per_transfer_contextp, bufferp,
924 nbytesp, transfer_idp, flagsp);
Houston Hoffman44b7e4a2015-09-03 17:01:22 -0700925 cdf_spin_unlock_bh(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800926
927 return status;
928}
929
930/* NB: Modeled after ce_completed_recv_next_nolock */
931CDF_STATUS
932ce_revoke_recv_next(struct CE_handle *copyeng,
933 void **per_CE_contextp,
934 void **per_transfer_contextp, cdf_dma_addr_t *bufferp)
935{
936 struct CE_state *CE_state;
937 struct CE_ring_state *dest_ring;
938 unsigned int nentries_mask;
939 unsigned int sw_index;
940 unsigned int write_index;
941 CDF_STATUS status;
942 struct ol_softc *scn;
943
944 CE_state = (struct CE_state *)copyeng;
945 dest_ring = CE_state->dest_ring;
946 if (!dest_ring) {
947 return CDF_STATUS_E_FAILURE;
948 }
949
950 scn = CE_state->scn;
Houston Hoffman44b7e4a2015-09-03 17:01:22 -0700951 cdf_spin_lock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800952 nentries_mask = dest_ring->nentries_mask;
953 sw_index = dest_ring->sw_index;
954 write_index = dest_ring->write_index;
955 if (write_index != sw_index) {
956 struct CE_dest_desc *dest_ring_base =
957 (struct CE_dest_desc *)dest_ring->
958 base_addr_owner_space;
959 struct CE_dest_desc *dest_desc =
960 CE_DEST_RING_TO_DESC(dest_ring_base, sw_index);
961
962 /* Return data from completed destination descriptor */
963 *bufferp = HIF_CE_DESC_ADDR_TO_DMA(dest_desc);
964
965 if (per_CE_contextp) {
966 *per_CE_contextp = CE_state->recv_context;
967 }
968
969 ce_debug_rvkrn_context =
970 dest_ring->per_transfer_context[sw_index];
971 if (per_transfer_contextp) {
972 *per_transfer_contextp = ce_debug_rvkrn_context;
973 }
974 dest_ring->per_transfer_context[sw_index] = 0; /* sanity */
975
976 /* Update sw_index */
977 sw_index = CE_RING_IDX_INCR(nentries_mask, sw_index);
978 dest_ring->sw_index = sw_index;
979 status = CDF_STATUS_SUCCESS;
980 } else {
981 status = CDF_STATUS_E_FAILURE;
982 }
Houston Hoffman44b7e4a2015-09-03 17:01:22 -0700983 cdf_spin_unlock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800984
985 return status;
986}
987
988/*
989 * Guts of ce_completed_send_next.
990 * The caller takes responsibility for any necessary locking.
991 */
992int
993ce_completed_send_next_nolock(struct CE_state *CE_state,
994 void **per_CE_contextp,
995 void **per_transfer_contextp,
996 cdf_dma_addr_t *bufferp,
997 unsigned int *nbytesp,
998 unsigned int *transfer_idp,
999 unsigned int *sw_idx,
1000 unsigned int *hw_idx,
1001 uint32_t *toeplitz_hash_result)
1002{
1003 int status = CDF_STATUS_E_FAILURE;
1004 struct CE_ring_state *src_ring = CE_state->src_ring;
1005 uint32_t ctrl_addr = CE_state->ctrl_addr;
1006 unsigned int nentries_mask = src_ring->nentries_mask;
1007 unsigned int sw_index = src_ring->sw_index;
1008 unsigned int read_index;
1009 struct ol_softc *scn = CE_state->scn;
1010
1011 if (src_ring->hw_index == sw_index) {
1012 /*
1013 * The SW completion index has caught up with the cached
1014 * version of the HW completion index.
1015 * Update the cached HW completion index to see whether
1016 * the SW has really caught up to the HW, or if the cached
1017 * value of the HW index has become stale.
1018 */
1019 A_TARGET_ACCESS_BEGIN_RET(scn);
1020 src_ring->hw_index =
Houston Hoffman3d0cda82015-12-03 13:25:05 -08001021 CE_SRC_RING_READ_IDX_GET_FROM_DDR(scn, ctrl_addr);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001022 A_TARGET_ACCESS_END_RET(scn);
1023 }
1024 read_index = src_ring->hw_index;
1025
1026 if (sw_idx)
1027 *sw_idx = sw_index;
1028
1029 if (hw_idx)
1030 *hw_idx = read_index;
1031
1032 if ((read_index != sw_index) && (read_index != 0xffffffff)) {
1033 struct CE_src_desc *shadow_base =
1034 (struct CE_src_desc *)src_ring->shadow_base;
1035 struct CE_src_desc *shadow_src_desc =
1036 CE_SRC_RING_TO_DESC(shadow_base, sw_index);
1037#ifdef QCA_WIFI_3_0
1038 struct CE_src_desc *src_ring_base =
1039 (struct CE_src_desc *)src_ring->base_addr_owner_space;
1040 struct CE_src_desc *src_desc =
1041 CE_SRC_RING_TO_DESC(src_ring_base, sw_index);
1042#endif
Houston Hoffman68e837e2015-12-04 12:57:24 -08001043 hif_record_ce_desc_event(CE_state->id, HIF_TX_DESC_COMPLETION,
1044 (union ce_desc *) shadow_src_desc,
1045 src_ring->per_transfer_context[sw_index],
1046 sw_index);
1047
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001048 /* Return data from completed source descriptor */
1049 *bufferp = HIF_CE_DESC_ADDR_TO_DMA(shadow_src_desc);
1050 *nbytesp = shadow_src_desc->nbytes;
1051 *transfer_idp = shadow_src_desc->meta_data;
1052#ifdef QCA_WIFI_3_0
1053 *toeplitz_hash_result = src_desc->toeplitz_hash_result;
1054#else
1055 *toeplitz_hash_result = 0;
1056#endif
1057 if (per_CE_contextp) {
1058 *per_CE_contextp = CE_state->send_context;
1059 }
1060
1061 ce_debug_cmplsn_context =
1062 src_ring->per_transfer_context[sw_index];
1063 if (per_transfer_contextp) {
1064 *per_transfer_contextp = ce_debug_cmplsn_context;
1065 }
1066 src_ring->per_transfer_context[sw_index] = 0; /* sanity */
1067
1068 /* Update sw_index */
1069 sw_index = CE_RING_IDX_INCR(nentries_mask, sw_index);
1070 src_ring->sw_index = sw_index;
1071 status = CDF_STATUS_SUCCESS;
1072 }
1073
1074 return status;
1075}
1076
1077/* NB: Modeled after ce_completed_send_next */
1078CDF_STATUS
1079ce_cancel_send_next(struct CE_handle *copyeng,
1080 void **per_CE_contextp,
1081 void **per_transfer_contextp,
1082 cdf_dma_addr_t *bufferp,
1083 unsigned int *nbytesp,
1084 unsigned int *transfer_idp,
1085 uint32_t *toeplitz_hash_result)
1086{
1087 struct CE_state *CE_state;
1088 struct CE_ring_state *src_ring;
1089 unsigned int nentries_mask;
1090 unsigned int sw_index;
1091 unsigned int write_index;
1092 CDF_STATUS status;
1093 struct ol_softc *scn;
1094
1095 CE_state = (struct CE_state *)copyeng;
1096 src_ring = CE_state->src_ring;
1097 if (!src_ring) {
1098 return CDF_STATUS_E_FAILURE;
1099 }
1100
1101 scn = CE_state->scn;
Houston Hoffman44b7e4a2015-09-03 17:01:22 -07001102 cdf_spin_lock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001103 nentries_mask = src_ring->nentries_mask;
1104 sw_index = src_ring->sw_index;
1105 write_index = src_ring->write_index;
1106
1107 if (write_index != sw_index) {
1108 struct CE_src_desc *src_ring_base =
1109 (struct CE_src_desc *)src_ring->base_addr_owner_space;
1110 struct CE_src_desc *src_desc =
1111 CE_SRC_RING_TO_DESC(src_ring_base, sw_index);
1112
1113 /* Return data from completed source descriptor */
1114 *bufferp = HIF_CE_DESC_ADDR_TO_DMA(src_desc);
1115 *nbytesp = src_desc->nbytes;
1116 *transfer_idp = src_desc->meta_data;
1117#ifdef QCA_WIFI_3_0
1118 *toeplitz_hash_result = src_desc->toeplitz_hash_result;
1119#else
1120 *toeplitz_hash_result = 0;
1121#endif
1122
1123 if (per_CE_contextp) {
1124 *per_CE_contextp = CE_state->send_context;
1125 }
1126
1127 ce_debug_cnclsn_context =
1128 src_ring->per_transfer_context[sw_index];
1129 if (per_transfer_contextp) {
1130 *per_transfer_contextp = ce_debug_cnclsn_context;
1131 }
1132 src_ring->per_transfer_context[sw_index] = 0; /* sanity */
1133
1134 /* Update sw_index */
1135 sw_index = CE_RING_IDX_INCR(nentries_mask, sw_index);
1136 src_ring->sw_index = sw_index;
1137 status = CDF_STATUS_SUCCESS;
1138 } else {
1139 status = CDF_STATUS_E_FAILURE;
1140 }
Houston Hoffman44b7e4a2015-09-03 17:01:22 -07001141 cdf_spin_unlock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001142
1143 return status;
1144}
1145
1146/* Shift bits to convert IS_*_RING_*_WATERMARK_MASK to CE_WM_FLAG_*_* */
1147#define CE_WM_SHFT 1
1148
1149int
1150ce_completed_send_next(struct CE_handle *copyeng,
1151 void **per_CE_contextp,
1152 void **per_transfer_contextp,
1153 cdf_dma_addr_t *bufferp,
1154 unsigned int *nbytesp,
1155 unsigned int *transfer_idp,
1156 unsigned int *sw_idx,
1157 unsigned int *hw_idx,
1158 unsigned int *toeplitz_hash_result)
1159{
1160 struct CE_state *CE_state = (struct CE_state *)copyeng;
1161 int status;
1162
Houston Hoffman44b7e4a2015-09-03 17:01:22 -07001163 cdf_spin_lock_bh(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001164 status =
1165 ce_completed_send_next_nolock(CE_state, per_CE_contextp,
1166 per_transfer_contextp, bufferp,
1167 nbytesp, transfer_idp, sw_idx,
1168 hw_idx, toeplitz_hash_result);
Houston Hoffman44b7e4a2015-09-03 17:01:22 -07001169 cdf_spin_unlock_bh(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001170
1171 return status;
1172}
1173
1174#ifdef ATH_11AC_TXCOMPACT
1175/* CE engine descriptor reap
1176 * Similar to ce_per_engine_service , Only difference is ce_per_engine_service
1177 * does recieve and reaping of completed descriptor ,
1178 * This function only handles reaping of Tx complete descriptor.
1179 * The Function is called from threshold reap poll routine
1180 * hif_send_complete_check so should not countain recieve functionality
1181 * within it .
1182 */
1183
1184void ce_per_engine_servicereap(struct ol_softc *scn, unsigned int CE_id)
1185{
1186 void *CE_context;
1187 void *transfer_context;
1188 cdf_dma_addr_t buf;
1189 unsigned int nbytes;
1190 unsigned int id;
1191 unsigned int sw_idx, hw_idx;
1192 uint32_t toeplitz_hash_result;
1193 struct CE_state *CE_state = scn->ce_id_to_state[CE_id];
1194
1195 A_TARGET_ACCESS_BEGIN(scn);
1196
1197 /* Since this function is called from both user context and
1198 * tasklet context the spinlock has to lock the bottom halves.
1199 * This fix assumes that ATH_11AC_TXCOMPACT flag is always
1200 * enabled in TX polling mode. If this is not the case, more
1201 * bottom halve spin lock changes are needed. Due to data path
1202 * performance concern, after internal discussion we've decided
1203 * to make minimum change, i.e., only address the issue occured
1204 * in this function. The possible negative effect of this minimum
1205 * change is that, in the future, if some other function will also
1206 * be opened to let the user context to use, those cases need to be
1207 * addressed by change spin_lock to spin_lock_bh also.
1208 */
1209
Houston Hoffman44b7e4a2015-09-03 17:01:22 -07001210 cdf_spin_lock_bh(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001211
1212 if (CE_state->send_cb) {
1213 {
1214 /* Pop completed send buffers and call the
1215 * registered send callback for each
1216 */
1217 while (ce_completed_send_next_nolock
1218 (CE_state, &CE_context,
1219 &transfer_context, &buf,
1220 &nbytes, &id, &sw_idx, &hw_idx,
1221 &toeplitz_hash_result) ==
1222 CDF_STATUS_SUCCESS) {
1223 if (CE_id != CE_HTT_H2T_MSG) {
Houston Hoffman44b7e4a2015-09-03 17:01:22 -07001224 cdf_spin_unlock_bh(
1225 &CE_state->ce_index_lock);
1226 CE_state->send_cb(
1227 (struct CE_handle *)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001228 CE_state, CE_context,
1229 transfer_context, buf,
1230 nbytes, id, sw_idx, hw_idx,
1231 toeplitz_hash_result);
Houston Hoffman44b7e4a2015-09-03 17:01:22 -07001232 cdf_spin_lock_bh(
1233 &CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001234 } else {
1235 struct HIF_CE_pipe_info *pipe_info =
1236 (struct HIF_CE_pipe_info *)
1237 CE_context;
1238
1239 cdf_spin_lock_bh(&pipe_info->
1240 completion_freeq_lock);
1241 pipe_info->num_sends_allowed++;
1242 cdf_spin_unlock_bh(&pipe_info->
1243 completion_freeq_lock);
1244 }
1245 }
1246 }
1247 }
1248
Houston Hoffman44b7e4a2015-09-03 17:01:22 -07001249 cdf_spin_unlock_bh(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001250 A_TARGET_ACCESS_END(scn);
1251}
1252
1253#endif /*ATH_11AC_TXCOMPACT */
1254
1255/*
1256 * Number of times to check for any pending tx/rx completion on
1257 * a copy engine, this count should be big enough. Once we hit
1258 * this threashold we'll not check for any Tx/Rx comlpetion in same
1259 * interrupt handling. Note that this threashold is only used for
1260 * Rx interrupt processing, this can be used tor Tx as well if we
1261 * suspect any infinite loop in checking for pending Tx completion.
1262 */
1263#define CE_TXRX_COMP_CHECK_THRESHOLD 20
1264
1265/*
1266 * Guts of interrupt handler for per-engine interrupts on a particular CE.
1267 *
1268 * Invokes registered callbacks for recv_complete,
1269 * send_complete, and watermarks.
1270 *
1271 * Returns: number of messages processed
1272 */
1273
1274int ce_per_engine_service(struct ol_softc *scn, unsigned int CE_id)
1275{
1276 struct CE_state *CE_state = scn->ce_id_to_state[CE_id];
1277 uint32_t ctrl_addr = CE_state->ctrl_addr;
1278 void *CE_context;
1279 void *transfer_context;
1280 cdf_dma_addr_t buf;
1281 unsigned int nbytes;
1282 unsigned int id;
1283 unsigned int flags;
1284 uint32_t CE_int_status;
1285 unsigned int more_comp_cnt = 0;
1286 unsigned int more_snd_comp_cnt = 0;
1287 unsigned int sw_idx, hw_idx;
1288 uint32_t toeplitz_hash_result;
1289
1290 if (Q_TARGET_ACCESS_BEGIN(scn) < 0) {
1291 HIF_ERROR("[premature rc=0]\n");
1292 return 0; /* no work done */
1293 }
1294
Houston Hoffman44b7e4a2015-09-03 17:01:22 -07001295 cdf_spin_lock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001296
1297 /* Clear force_break flag and re-initialize receive_count to 0 */
1298
1299 /* NAPI: scn variables- thread/multi-processing safety? */
Houston Hoffman5bf441a2015-09-02 11:52:10 -07001300 CE_state->receive_count = 0;
Houston Hoffman18c7fc52015-09-02 11:44:42 -07001301 CE_state->force_break = 0;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001302more_completions:
1303 if (CE_state->recv_cb) {
1304
1305 /* Pop completed recv buffers and call
1306 * the registered recv callback for each
1307 */
1308 while (ce_completed_recv_next_nolock
1309 (CE_state, &CE_context, &transfer_context,
1310 &buf, &nbytes, &id, &flags) ==
1311 CDF_STATUS_SUCCESS) {
Houston Hoffman44b7e4a2015-09-03 17:01:22 -07001312 cdf_spin_unlock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001313 CE_state->recv_cb((struct CE_handle *)CE_state,
1314 CE_context, transfer_context, buf,
1315 nbytes, id, flags);
1316
1317 /*
1318 * EV #112693 -
1319 * [Peregrine][ES1][WB342][Win8x86][Performance]
1320 * BSoD_0x133 occurred in VHT80 UDP_DL
1321 * Break out DPC by force if number of loops in
1322 * hif_pci_ce_recv_data reaches MAX_NUM_OF_RECEIVES
1323 * to avoid spending too long time in
1324 * DPC for each interrupt handling. Schedule another
1325 * DPC to avoid data loss if we had taken
1326 * force-break action before apply to Windows OS
1327 * only currently, Linux/MAC os can expand to their
1328 * platform if necessary
1329 */
1330
1331 /* Break the receive processes by
1332 * force if force_break set up
1333 */
Houston Hoffman18c7fc52015-09-02 11:44:42 -07001334 if (cdf_unlikely(CE_state->force_break)) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001335 cdf_atomic_set(&CE_state->rx_pending, 1);
1336 CE_ENGINE_INT_STATUS_CLEAR(scn, ctrl_addr,
1337 HOST_IS_COPY_COMPLETE_MASK);
1338 if (Q_TARGET_ACCESS_END(scn) < 0)
1339 HIF_ERROR("<--[premature rc=%d]\n",
Houston Hoffman5bf441a2015-09-02 11:52:10 -07001340 CE_state->receive_count);
1341 return CE_state->receive_count;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001342 }
Houston Hoffman44b7e4a2015-09-03 17:01:22 -07001343 cdf_spin_lock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001344 }
1345 }
1346
1347 /*
1348 * Attention: We may experience potential infinite loop for below
1349 * While Loop during Sending Stress test.
1350 * Resolve the same way as Receive Case (Refer to EV #112693)
1351 */
1352
1353 if (CE_state->send_cb) {
1354 /* Pop completed send buffers and call
1355 * the registered send callback for each
1356 */
1357
1358#ifdef ATH_11AC_TXCOMPACT
1359 while (ce_completed_send_next_nolock
1360 (CE_state, &CE_context,
1361 &transfer_context, &buf, &nbytes,
1362 &id, &sw_idx, &hw_idx,
1363 &toeplitz_hash_result) == CDF_STATUS_SUCCESS) {
1364
1365 if (CE_id != CE_HTT_H2T_MSG ||
1366 WLAN_IS_EPPING_ENABLED(cds_get_conparam())) {
Houston Hoffman44b7e4a2015-09-03 17:01:22 -07001367 cdf_spin_unlock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001368 CE_state->send_cb((struct CE_handle *)CE_state,
1369 CE_context, transfer_context,
1370 buf, nbytes, id, sw_idx,
1371 hw_idx, toeplitz_hash_result);
Houston Hoffman44b7e4a2015-09-03 17:01:22 -07001372 cdf_spin_lock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001373 } else {
1374 struct HIF_CE_pipe_info *pipe_info =
1375 (struct HIF_CE_pipe_info *)CE_context;
1376
1377 cdf_spin_lock(&pipe_info->
1378 completion_freeq_lock);
1379 pipe_info->num_sends_allowed++;
1380 cdf_spin_unlock(&pipe_info->
1381 completion_freeq_lock);
1382 }
1383 }
1384#else /*ATH_11AC_TXCOMPACT */
1385 while (ce_completed_send_next_nolock
1386 (CE_state, &CE_context,
1387 &transfer_context, &buf, &nbytes,
1388 &id, &sw_idx, &hw_idx,
1389 &toeplitz_hash_result) == CDF_STATUS_SUCCESS) {
Houston Hoffman44b7e4a2015-09-03 17:01:22 -07001390 cdf_spin_unlock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001391 CE_state->send_cb((struct CE_handle *)CE_state,
1392 CE_context, transfer_context, buf,
1393 nbytes, id, sw_idx, hw_idx,
1394 toeplitz_hash_result);
Houston Hoffman44b7e4a2015-09-03 17:01:22 -07001395 cdf_spin_lock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001396 }
1397#endif /*ATH_11AC_TXCOMPACT */
1398 }
1399
1400more_watermarks:
1401 if (CE_state->misc_cbs) {
1402 CE_int_status = CE_ENGINE_INT_STATUS_GET(scn, ctrl_addr);
1403 if (CE_int_status & CE_WATERMARK_MASK) {
1404 if (CE_state->watermark_cb) {
Houston Hoffman44b7e4a2015-09-03 17:01:22 -07001405 cdf_spin_unlock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001406 /* Convert HW IS bits to software flags */
1407 flags =
1408 (CE_int_status & CE_WATERMARK_MASK) >>
1409 CE_WM_SHFT;
1410
1411 CE_state->
1412 watermark_cb((struct CE_handle *)CE_state,
1413 CE_state->wm_context, flags);
Houston Hoffman44b7e4a2015-09-03 17:01:22 -07001414 cdf_spin_lock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001415 }
1416 }
1417 }
1418
1419 /*
1420 * Clear the misc interrupts (watermark) that were handled above,
1421 * and that will be checked again below.
1422 * Clear and check for copy-complete interrupts again, just in case
1423 * more copy completions happened while the misc interrupts were being
1424 * handled.
1425 */
1426 CE_ENGINE_INT_STATUS_CLEAR(scn, ctrl_addr,
1427 CE_WATERMARK_MASK |
1428 HOST_IS_COPY_COMPLETE_MASK);
1429
1430 /*
1431 * Now that per-engine interrupts are cleared, verify that
1432 * no recv interrupts arrive while processing send interrupts,
1433 * and no recv or send interrupts happened while processing
1434 * misc interrupts.Go back and check again.Keep checking until
1435 * we find no more events to process.
1436 */
1437 if (CE_state->recv_cb && ce_recv_entries_done_nolock(scn, CE_state)) {
1438 if (WLAN_IS_EPPING_ENABLED(cds_get_conparam()) ||
1439 more_comp_cnt++ < CE_TXRX_COMP_CHECK_THRESHOLD) {
1440 goto more_completions;
1441 } else {
1442 HIF_ERROR(
1443 "%s:Potential infinite loop detected during Rx processing nentries_mask:0x%x sw read_idx:0x%x hw read_idx:0x%x",
1444 __func__, CE_state->dest_ring->nentries_mask,
1445 CE_state->dest_ring->sw_index,
1446 CE_DEST_RING_READ_IDX_GET(scn,
1447 CE_state->ctrl_addr));
1448 }
1449 }
1450
1451 if (CE_state->send_cb && ce_send_entries_done_nolock(scn, CE_state)) {
1452 if (WLAN_IS_EPPING_ENABLED(cds_get_conparam()) ||
1453 more_snd_comp_cnt++ < CE_TXRX_COMP_CHECK_THRESHOLD) {
1454 goto more_completions;
1455 } else {
1456 HIF_ERROR(
1457 "%s:Potential infinite loop detected during send completion nentries_mask:0x%x sw read_idx:0x%x hw read_idx:0x%x",
1458 __func__, CE_state->src_ring->nentries_mask,
1459 CE_state->src_ring->sw_index,
1460 CE_SRC_RING_READ_IDX_GET(scn,
1461 CE_state->ctrl_addr));
1462 }
1463 }
1464
1465 if (CE_state->misc_cbs) {
1466 CE_int_status = CE_ENGINE_INT_STATUS_GET(scn, ctrl_addr);
1467 if (CE_int_status & CE_WATERMARK_MASK) {
1468 if (CE_state->watermark_cb) {
1469 goto more_watermarks;
1470 }
1471 }
1472 }
1473
Houston Hoffman44b7e4a2015-09-03 17:01:22 -07001474 cdf_spin_unlock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001475 cdf_atomic_set(&CE_state->rx_pending, 0);
1476
1477 if (Q_TARGET_ACCESS_END(scn) < 0)
Houston Hoffman5bf441a2015-09-02 11:52:10 -07001478 HIF_ERROR("<--[premature rc=%d]\n", CE_state->receive_count);
1479 return CE_state->receive_count;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001480}
1481
1482/*
1483 * Handler for per-engine interrupts on ALL active CEs.
1484 * This is used in cases where the system is sharing a
1485 * single interrput for all CEs
1486 */
1487
1488void ce_per_engine_service_any(int irq, struct ol_softc *scn)
1489{
1490 int CE_id;
1491 uint32_t intr_summary;
1492
1493 A_TARGET_ACCESS_BEGIN(scn);
1494 if (!cdf_atomic_read(&scn->tasklet_from_intr)) {
1495 for (CE_id = 0; CE_id < scn->ce_count; CE_id++) {
1496 struct CE_state *CE_state = scn->ce_id_to_state[CE_id];
1497 if (cdf_atomic_read(&CE_state->rx_pending)) {
1498 cdf_atomic_set(&CE_state->rx_pending, 0);
1499 ce_per_engine_service(scn, CE_id);
1500 }
1501 }
1502
1503 A_TARGET_ACCESS_END(scn);
1504 return;
1505 }
1506
1507 intr_summary = CE_INTERRUPT_SUMMARY(scn);
1508
1509 for (CE_id = 0; intr_summary && (CE_id < scn->ce_count); CE_id++) {
1510 if (intr_summary & (1 << CE_id)) {
1511 intr_summary &= ~(1 << CE_id);
1512 } else {
1513 continue; /* no intr pending on this CE */
1514 }
1515
1516 ce_per_engine_service(scn, CE_id);
1517 }
1518
1519 A_TARGET_ACCESS_END(scn);
1520}
1521
1522/*
1523 * Adjust interrupts for the copy complete handler.
1524 * If it's needed for either send or recv, then unmask
1525 * this interrupt; otherwise, mask it.
1526 *
1527 * Called with target_lock held.
1528 */
1529static void
1530ce_per_engine_handler_adjust(struct CE_state *CE_state,
1531 int disable_copy_compl_intr)
1532{
1533 uint32_t ctrl_addr = CE_state->ctrl_addr;
1534 struct ol_softc *scn = CE_state->scn;
1535
1536 CE_state->disable_copy_compl_intr = disable_copy_compl_intr;
1537 A_TARGET_ACCESS_BEGIN(scn);
1538 if ((!disable_copy_compl_intr) &&
1539 (CE_state->send_cb || CE_state->recv_cb)) {
1540 CE_COPY_COMPLETE_INTR_ENABLE(scn, ctrl_addr);
1541 } else {
1542 CE_COPY_COMPLETE_INTR_DISABLE(scn, ctrl_addr);
1543 }
1544
1545 if (CE_state->watermark_cb) {
1546 CE_WATERMARK_INTR_ENABLE(scn, ctrl_addr);
1547 } else {
1548 CE_WATERMARK_INTR_DISABLE(scn, ctrl_addr);
1549 }
1550 A_TARGET_ACCESS_END(scn);
1551
1552}
1553
1554/*Iterate the CE_state list and disable the compl interrupt
1555 * if it has been registered already.
1556 */
1557void ce_disable_any_copy_compl_intr_nolock(struct ol_softc *scn)
1558{
1559 int CE_id;
1560
1561 A_TARGET_ACCESS_BEGIN(scn);
1562 for (CE_id = 0; CE_id < scn->ce_count; CE_id++) {
1563 struct CE_state *CE_state = scn->ce_id_to_state[CE_id];
1564 uint32_t ctrl_addr = CE_state->ctrl_addr;
1565
1566 /* if the interrupt is currently enabled, disable it */
1567 if (!CE_state->disable_copy_compl_intr
1568 && (CE_state->send_cb || CE_state->recv_cb)) {
1569 CE_COPY_COMPLETE_INTR_DISABLE(scn, ctrl_addr);
1570 }
1571
1572 if (CE_state->watermark_cb) {
1573 CE_WATERMARK_INTR_DISABLE(scn, ctrl_addr);
1574 }
1575 }
1576 A_TARGET_ACCESS_END(scn);
1577}
1578
1579void ce_enable_any_copy_compl_intr_nolock(struct ol_softc *scn)
1580{
1581 int CE_id;
1582
1583 A_TARGET_ACCESS_BEGIN(scn);
1584 for (CE_id = 0; CE_id < scn->ce_count; CE_id++) {
1585 struct CE_state *CE_state = scn->ce_id_to_state[CE_id];
1586 uint32_t ctrl_addr = CE_state->ctrl_addr;
1587
1588 /*
1589 * If the CE is supposed to have copy complete interrupts
1590 * enabled (i.e. there a callback registered, and the
1591 * "disable" flag is not set), then re-enable the interrupt.
1592 */
1593 if (!CE_state->disable_copy_compl_intr
1594 && (CE_state->send_cb || CE_state->recv_cb)) {
1595 CE_COPY_COMPLETE_INTR_ENABLE(scn, ctrl_addr);
1596 }
1597
1598 if (CE_state->watermark_cb) {
1599 CE_WATERMARK_INTR_ENABLE(scn, ctrl_addr);
1600 }
1601 }
1602 A_TARGET_ACCESS_END(scn);
1603}
1604
Houston Hoffmana837c9a2015-09-03 12:47:01 -07001605/**
1606 * ce_send_cb_register(): register completion handler
1607 * @copyeng: CE_state representing the ce we are adding the behavior to
1608 * @fn_ptr: callback that the ce should use when processing tx completions
1609 * @disable_interrupts: if the interupts should be enabled or not.
1610 *
1611 * Caller should guarantee that no transactions are in progress before
1612 * switching the callback function.
1613 *
1614 * Registers the send context before the fn pointer so that if the cb is valid
1615 * the context should be valid.
1616 *
1617 * Beware that currently this function will enable completion interrupts.
1618 */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001619void
1620ce_send_cb_register(struct CE_handle *copyeng,
1621 ce_send_cb fn_ptr,
1622 void *ce_send_context, int disable_interrupts)
1623{
1624 struct CE_state *CE_state = (struct CE_state *)copyeng;
1625
Sanjay Devnani9ce15772015-11-12 14:08:57 -08001626 if (CE_state == NULL) {
1627 pr_err("%s: Error CE state = NULL\n", __func__);
1628 return;
1629 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001630 CE_state->send_context = ce_send_context;
Houston Hoffmana837c9a2015-09-03 12:47:01 -07001631 CE_state->send_cb = fn_ptr;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001632 ce_per_engine_handler_adjust(CE_state, disable_interrupts);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001633}
1634
Houston Hoffmana837c9a2015-09-03 12:47:01 -07001635/**
1636 * ce_recv_cb_register(): register completion handler
1637 * @copyeng: CE_state representing the ce we are adding the behavior to
1638 * @fn_ptr: callback that the ce should use when processing rx completions
1639 * @disable_interrupts: if the interupts should be enabled or not.
1640 *
1641 * Registers the send context before the fn pointer so that if the cb is valid
1642 * the context should be valid.
1643 *
1644 * Caller should guarantee that no transactions are in progress before
1645 * switching the callback function.
1646 */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001647void
1648ce_recv_cb_register(struct CE_handle *copyeng,
1649 CE_recv_cb fn_ptr,
1650 void *CE_recv_context, int disable_interrupts)
1651{
1652 struct CE_state *CE_state = (struct CE_state *)copyeng;
1653
Sanjay Devnani9ce15772015-11-12 14:08:57 -08001654 if (CE_state == NULL) {
1655 pr_err("%s: ERROR CE state = NULL\n", __func__);
1656 return;
1657 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001658 CE_state->recv_context = CE_recv_context;
Houston Hoffmana837c9a2015-09-03 12:47:01 -07001659 CE_state->recv_cb = fn_ptr;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001660 ce_per_engine_handler_adjust(CE_state, disable_interrupts);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001661}
1662
Houston Hoffmana837c9a2015-09-03 12:47:01 -07001663/**
1664 * ce_watermark_cb_register(): register completion handler
1665 * @copyeng: CE_state representing the ce we are adding the behavior to
1666 * @fn_ptr: callback that the ce should use when processing watermark events
1667 *
1668 * Caller should guarantee that no watermark events are being processed before
1669 * switching the callback function.
1670 */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001671void
1672ce_watermark_cb_register(struct CE_handle *copyeng,
1673 CE_watermark_cb fn_ptr, void *CE_wm_context)
1674{
1675 struct CE_state *CE_state = (struct CE_state *)copyeng;
1676
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001677 CE_state->watermark_cb = fn_ptr;
1678 CE_state->wm_context = CE_wm_context;
1679 ce_per_engine_handler_adjust(CE_state, 0);
1680 if (fn_ptr) {
1681 CE_state->misc_cbs = 1;
1682 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001683}
1684
1685#ifdef WLAN_FEATURE_FASTPATH
1686/**
1687 * ce_pkt_dl_len_set() set the HTT packet download length
1688 * @hif_sc: HIF context
1689 * @pkt_download_len: download length
1690 *
1691 * Return: None
1692 */
1693void ce_pkt_dl_len_set(void *hif_sc, u_int32_t pkt_download_len)
1694{
1695 struct ol_softc *sc = (struct ol_softc *)(hif_sc);
1696 struct CE_state *ce_state = sc->ce_id_to_state[CE_HTT_H2T_MSG];
1697
1698 cdf_assert_always(ce_state);
1699
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001700 ce_state->download_len = pkt_download_len;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001701
1702 cdf_print("%s CE %d Pkt download length %d\n", __func__,
1703 ce_state->id, ce_state->download_len);
1704}
1705#else
1706void ce_pkt_dl_len_set(void *hif_sc, u_int32_t pkt_download_len)
1707{
1708}
1709#endif /* WLAN_FEATURE_FASTPATH */
1710
1711bool ce_get_rx_pending(struct ol_softc *scn)
1712{
1713 int CE_id;
1714
1715 for (CE_id = 0; CE_id < scn->ce_count; CE_id++) {
1716 struct CE_state *CE_state = scn->ce_id_to_state[CE_id];
1717 if (cdf_atomic_read(&CE_state->rx_pending))
1718 return true;
1719 }
1720
1721 return false;
1722}
1723
1724/**
1725 * ce_check_rx_pending() - ce_check_rx_pending
1726 * @scn: ol_softc
1727 * @ce_id: ce_id
1728 *
1729 * Return: bool
1730 */
1731bool ce_check_rx_pending(struct ol_softc *scn, int ce_id)
1732{
1733 struct CE_state *CE_state = scn->ce_id_to_state[ce_id];
1734 if (cdf_atomic_read(&CE_state->rx_pending))
1735 return true;
1736 else
1737 return false;
1738}
Houston Hoffman8ed92e52015-09-02 14:49:48 -07001739
1740/**
1741 * ce_enable_msi(): write the msi configuration to the target
1742 * @scn: hif context
1743 * @CE_id: which copy engine will be configured for msi interupts
1744 * @msi_addr_lo: Hardware will write to this address to generate an interrupt
1745 * @msi_addr_hi: Hardware will write to this address to generate an interrupt
1746 * @msi_data: Hardware will write this data to generate an interrupt
1747 *
1748 * should be done in the initialization sequence so no locking would be needed
1749 */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001750void ce_enable_msi(struct ol_softc *scn, unsigned int CE_id,
1751 uint32_t msi_addr_lo, uint32_t msi_addr_hi,
1752 uint32_t msi_data)
1753{
1754#ifdef WLAN_ENABLE_QCA6180
1755 struct CE_state *CE_state;
1756 A_target_id_t targid;
1757 u_int32_t ctrl_addr;
1758 uint32_t tmp;
1759
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001760 CE_state = scn->ce_id_to_state[CE_id];
1761 if (!CE_state) {
1762 HIF_ERROR("%s: error - CE_state = NULL", __func__);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001763 return;
1764 }
1765 targid = TARGID(sc);
1766 ctrl_addr = CE_state->ctrl_addr;
1767 CE_MSI_ADDR_LOW_SET(scn, ctrl_addr, msi_addr_lo);
1768 CE_MSI_ADDR_HIGH_SET(scn, ctrl_addr, msi_addr_hi);
1769 CE_MSI_DATA_SET(scn, ctrl_addr, msi_data);
1770 tmp = CE_CTRL_REGISTER1_GET(scn, ctrl_addr);
1771 tmp |= (1 << CE_MSI_ENABLE_BIT);
1772 CE_CTRL_REGISTER1_SET(scn, ctrl_addr, tmp);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001773#endif
1774}
1775
1776#ifdef IPA_OFFLOAD
Leo Changd85f78d2015-11-13 10:55:34 -08001777/**
1778 * ce_ipa_get_resource() - get uc resource on copyengine
1779 * @ce: copyengine context
1780 * @ce_sr_base_paddr: copyengine source ring base physical address
1781 * @ce_sr_ring_size: copyengine source ring size
1782 * @ce_reg_paddr: copyengine register physical address
1783 *
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001784 * Copy engine should release resource to micro controller
1785 * Micro controller needs
Leo Changd85f78d2015-11-13 10:55:34 -08001786 * - Copy engine source descriptor base address
1787 * - Copy engine source descriptor size
1788 * - PCI BAR address to access copy engine regiser
1789 *
1790 * Return: None
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001791 */
1792void ce_ipa_get_resource(struct CE_handle *ce,
Leo Changd85f78d2015-11-13 10:55:34 -08001793 cdf_dma_addr_t *ce_sr_base_paddr,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001794 uint32_t *ce_sr_ring_size,
1795 cdf_dma_addr_t *ce_reg_paddr)
1796{
1797 struct CE_state *CE_state = (struct CE_state *)ce;
1798 uint32_t ring_loop;
1799 struct CE_src_desc *ce_desc;
1800 cdf_dma_addr_t phy_mem_base;
1801 struct ol_softc *scn = CE_state->scn;
1802
1803 if (CE_RUNNING != CE_state->state) {
1804 *ce_sr_base_paddr = 0;
1805 *ce_sr_ring_size = 0;
1806 return;
1807 }
1808
1809 /* Update default value for descriptor */
1810 for (ring_loop = 0; ring_loop < CE_state->src_ring->nentries;
1811 ring_loop++) {
1812 ce_desc = (struct CE_src_desc *)
1813 ((char *)CE_state->src_ring->base_addr_owner_space +
1814 ring_loop * (sizeof(struct CE_src_desc)));
1815 CE_IPA_RING_INIT(ce_desc);
1816 }
1817
1818 /* Get BAR address */
1819 hif_read_phy_mem_base(CE_state->scn, &phy_mem_base);
1820
Leo Changd85f78d2015-11-13 10:55:34 -08001821 *ce_sr_base_paddr = CE_state->src_ring->base_addr_CE_space;
1822 *ce_sr_ring_size = (uint32_t) (CE_state->src_ring->nentries *
1823 sizeof(struct CE_src_desc));
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001824 *ce_reg_paddr = phy_mem_base + CE_BASE_ADDRESS(CE_state->id) +
1825 SR_WR_INDEX_ADDRESS;
1826 return;
1827}
1828#endif /* IPA_OFFLOAD */
1829