blob: 0d97b494994345a56990623f9a9761f7b7d840e7 [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
Houston Hoffmana575ec22015-12-14 16:35:15 -08001184void ce_per_engine_servicereap(struct ol_softc *scn, unsigned int ce_id)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001185{
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;
Houston Hoffmana575ec22015-12-14 16:35:15 -08001193 struct CE_state *CE_state = scn->ce_id_to_state[ce_id];
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001194
1195 A_TARGET_ACCESS_BEGIN(scn);
Houston Hoffmana575ec22015-12-14 16:35:15 -08001196 hif_record_ce_desc_event(ce_id, HIF_CE_REAP_ENTRY,
1197 NULL, NULL, 0);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001198
1199 /* Since this function is called from both user context and
1200 * tasklet context the spinlock has to lock the bottom halves.
1201 * This fix assumes that ATH_11AC_TXCOMPACT flag is always
1202 * enabled in TX polling mode. If this is not the case, more
1203 * bottom halve spin lock changes are needed. Due to data path
1204 * performance concern, after internal discussion we've decided
1205 * to make minimum change, i.e., only address the issue occured
1206 * in this function. The possible negative effect of this minimum
1207 * change is that, in the future, if some other function will also
1208 * be opened to let the user context to use, those cases need to be
1209 * addressed by change spin_lock to spin_lock_bh also.
1210 */
1211
Houston Hoffman44b7e4a2015-09-03 17:01:22 -07001212 cdf_spin_lock_bh(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001213
1214 if (CE_state->send_cb) {
1215 {
1216 /* Pop completed send buffers and call the
1217 * registered send callback for each
1218 */
1219 while (ce_completed_send_next_nolock
1220 (CE_state, &CE_context,
1221 &transfer_context, &buf,
1222 &nbytes, &id, &sw_idx, &hw_idx,
1223 &toeplitz_hash_result) ==
1224 CDF_STATUS_SUCCESS) {
Houston Hoffmana575ec22015-12-14 16:35:15 -08001225 if (ce_id != CE_HTT_H2T_MSG) {
Houston Hoffman44b7e4a2015-09-03 17:01:22 -07001226 cdf_spin_unlock_bh(
1227 &CE_state->ce_index_lock);
1228 CE_state->send_cb(
1229 (struct CE_handle *)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001230 CE_state, CE_context,
1231 transfer_context, buf,
1232 nbytes, id, sw_idx, hw_idx,
1233 toeplitz_hash_result);
Houston Hoffman44b7e4a2015-09-03 17:01:22 -07001234 cdf_spin_lock_bh(
1235 &CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001236 } else {
1237 struct HIF_CE_pipe_info *pipe_info =
1238 (struct HIF_CE_pipe_info *)
1239 CE_context;
1240
1241 cdf_spin_lock_bh(&pipe_info->
1242 completion_freeq_lock);
1243 pipe_info->num_sends_allowed++;
1244 cdf_spin_unlock_bh(&pipe_info->
1245 completion_freeq_lock);
1246 }
1247 }
1248 }
1249 }
1250
Houston Hoffman44b7e4a2015-09-03 17:01:22 -07001251 cdf_spin_unlock_bh(&CE_state->ce_index_lock);
Houston Hoffmana575ec22015-12-14 16:35:15 -08001252
1253 hif_record_ce_desc_event(ce_id, HIF_CE_REAP_EXIT,
1254 NULL, NULL, 0);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001255 A_TARGET_ACCESS_END(scn);
1256}
1257
1258#endif /*ATH_11AC_TXCOMPACT */
1259
1260/*
1261 * Number of times to check for any pending tx/rx completion on
1262 * a copy engine, this count should be big enough. Once we hit
1263 * this threashold we'll not check for any Tx/Rx comlpetion in same
1264 * interrupt handling. Note that this threashold is only used for
1265 * Rx interrupt processing, this can be used tor Tx as well if we
1266 * suspect any infinite loop in checking for pending Tx completion.
1267 */
1268#define CE_TXRX_COMP_CHECK_THRESHOLD 20
1269
1270/*
1271 * Guts of interrupt handler for per-engine interrupts on a particular CE.
1272 *
1273 * Invokes registered callbacks for recv_complete,
1274 * send_complete, and watermarks.
1275 *
1276 * Returns: number of messages processed
1277 */
1278
1279int ce_per_engine_service(struct ol_softc *scn, unsigned int CE_id)
1280{
1281 struct CE_state *CE_state = scn->ce_id_to_state[CE_id];
1282 uint32_t ctrl_addr = CE_state->ctrl_addr;
1283 void *CE_context;
1284 void *transfer_context;
1285 cdf_dma_addr_t buf;
1286 unsigned int nbytes;
1287 unsigned int id;
1288 unsigned int flags;
1289 uint32_t CE_int_status;
1290 unsigned int more_comp_cnt = 0;
1291 unsigned int more_snd_comp_cnt = 0;
1292 unsigned int sw_idx, hw_idx;
1293 uint32_t toeplitz_hash_result;
1294
1295 if (Q_TARGET_ACCESS_BEGIN(scn) < 0) {
1296 HIF_ERROR("[premature rc=0]\n");
1297 return 0; /* no work done */
1298 }
1299
Houston Hoffman44b7e4a2015-09-03 17:01:22 -07001300 cdf_spin_lock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001301
1302 /* Clear force_break flag and re-initialize receive_count to 0 */
1303
1304 /* NAPI: scn variables- thread/multi-processing safety? */
Houston Hoffman5bf441a2015-09-02 11:52:10 -07001305 CE_state->receive_count = 0;
Houston Hoffman18c7fc52015-09-02 11:44:42 -07001306 CE_state->force_break = 0;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001307more_completions:
1308 if (CE_state->recv_cb) {
1309
1310 /* Pop completed recv buffers and call
1311 * the registered recv callback for each
1312 */
1313 while (ce_completed_recv_next_nolock
1314 (CE_state, &CE_context, &transfer_context,
1315 &buf, &nbytes, &id, &flags) ==
1316 CDF_STATUS_SUCCESS) {
Houston Hoffman44b7e4a2015-09-03 17:01:22 -07001317 cdf_spin_unlock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001318 CE_state->recv_cb((struct CE_handle *)CE_state,
1319 CE_context, transfer_context, buf,
1320 nbytes, id, flags);
1321
1322 /*
1323 * EV #112693 -
1324 * [Peregrine][ES1][WB342][Win8x86][Performance]
1325 * BSoD_0x133 occurred in VHT80 UDP_DL
1326 * Break out DPC by force if number of loops in
1327 * hif_pci_ce_recv_data reaches MAX_NUM_OF_RECEIVES
1328 * to avoid spending too long time in
1329 * DPC for each interrupt handling. Schedule another
1330 * DPC to avoid data loss if we had taken
1331 * force-break action before apply to Windows OS
1332 * only currently, Linux/MAC os can expand to their
1333 * platform if necessary
1334 */
1335
1336 /* Break the receive processes by
1337 * force if force_break set up
1338 */
Houston Hoffman18c7fc52015-09-02 11:44:42 -07001339 if (cdf_unlikely(CE_state->force_break)) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001340 cdf_atomic_set(&CE_state->rx_pending, 1);
1341 CE_ENGINE_INT_STATUS_CLEAR(scn, ctrl_addr,
1342 HOST_IS_COPY_COMPLETE_MASK);
1343 if (Q_TARGET_ACCESS_END(scn) < 0)
1344 HIF_ERROR("<--[premature rc=%d]\n",
Houston Hoffman5bf441a2015-09-02 11:52:10 -07001345 CE_state->receive_count);
1346 return CE_state->receive_count;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001347 }
Houston Hoffman44b7e4a2015-09-03 17:01:22 -07001348 cdf_spin_lock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001349 }
1350 }
1351
1352 /*
1353 * Attention: We may experience potential infinite loop for below
1354 * While Loop during Sending Stress test.
1355 * Resolve the same way as Receive Case (Refer to EV #112693)
1356 */
1357
1358 if (CE_state->send_cb) {
1359 /* Pop completed send buffers and call
1360 * the registered send callback for each
1361 */
1362
1363#ifdef ATH_11AC_TXCOMPACT
1364 while (ce_completed_send_next_nolock
1365 (CE_state, &CE_context,
1366 &transfer_context, &buf, &nbytes,
1367 &id, &sw_idx, &hw_idx,
1368 &toeplitz_hash_result) == CDF_STATUS_SUCCESS) {
1369
1370 if (CE_id != CE_HTT_H2T_MSG ||
1371 WLAN_IS_EPPING_ENABLED(cds_get_conparam())) {
Houston Hoffman44b7e4a2015-09-03 17:01:22 -07001372 cdf_spin_unlock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001373 CE_state->send_cb((struct CE_handle *)CE_state,
1374 CE_context, transfer_context,
1375 buf, nbytes, id, sw_idx,
1376 hw_idx, toeplitz_hash_result);
Houston Hoffman44b7e4a2015-09-03 17:01:22 -07001377 cdf_spin_lock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001378 } else {
1379 struct HIF_CE_pipe_info *pipe_info =
1380 (struct HIF_CE_pipe_info *)CE_context;
1381
1382 cdf_spin_lock(&pipe_info->
1383 completion_freeq_lock);
1384 pipe_info->num_sends_allowed++;
1385 cdf_spin_unlock(&pipe_info->
1386 completion_freeq_lock);
1387 }
1388 }
1389#else /*ATH_11AC_TXCOMPACT */
1390 while (ce_completed_send_next_nolock
1391 (CE_state, &CE_context,
1392 &transfer_context, &buf, &nbytes,
1393 &id, &sw_idx, &hw_idx,
1394 &toeplitz_hash_result) == CDF_STATUS_SUCCESS) {
Houston Hoffman44b7e4a2015-09-03 17:01:22 -07001395 cdf_spin_unlock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001396 CE_state->send_cb((struct CE_handle *)CE_state,
1397 CE_context, transfer_context, buf,
1398 nbytes, id, sw_idx, hw_idx,
1399 toeplitz_hash_result);
Houston Hoffman44b7e4a2015-09-03 17:01:22 -07001400 cdf_spin_lock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001401 }
1402#endif /*ATH_11AC_TXCOMPACT */
1403 }
1404
1405more_watermarks:
1406 if (CE_state->misc_cbs) {
1407 CE_int_status = CE_ENGINE_INT_STATUS_GET(scn, ctrl_addr);
1408 if (CE_int_status & CE_WATERMARK_MASK) {
1409 if (CE_state->watermark_cb) {
Houston Hoffman44b7e4a2015-09-03 17:01:22 -07001410 cdf_spin_unlock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001411 /* Convert HW IS bits to software flags */
1412 flags =
1413 (CE_int_status & CE_WATERMARK_MASK) >>
1414 CE_WM_SHFT;
1415
1416 CE_state->
1417 watermark_cb((struct CE_handle *)CE_state,
1418 CE_state->wm_context, flags);
Houston Hoffman44b7e4a2015-09-03 17:01:22 -07001419 cdf_spin_lock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001420 }
1421 }
1422 }
1423
1424 /*
1425 * Clear the misc interrupts (watermark) that were handled above,
1426 * and that will be checked again below.
1427 * Clear and check for copy-complete interrupts again, just in case
1428 * more copy completions happened while the misc interrupts were being
1429 * handled.
1430 */
1431 CE_ENGINE_INT_STATUS_CLEAR(scn, ctrl_addr,
1432 CE_WATERMARK_MASK |
1433 HOST_IS_COPY_COMPLETE_MASK);
1434
1435 /*
1436 * Now that per-engine interrupts are cleared, verify that
1437 * no recv interrupts arrive while processing send interrupts,
1438 * and no recv or send interrupts happened while processing
1439 * misc interrupts.Go back and check again.Keep checking until
1440 * we find no more events to process.
1441 */
1442 if (CE_state->recv_cb && ce_recv_entries_done_nolock(scn, CE_state)) {
1443 if (WLAN_IS_EPPING_ENABLED(cds_get_conparam()) ||
1444 more_comp_cnt++ < CE_TXRX_COMP_CHECK_THRESHOLD) {
1445 goto more_completions;
1446 } else {
1447 HIF_ERROR(
1448 "%s:Potential infinite loop detected during Rx processing nentries_mask:0x%x sw read_idx:0x%x hw read_idx:0x%x",
1449 __func__, CE_state->dest_ring->nentries_mask,
1450 CE_state->dest_ring->sw_index,
1451 CE_DEST_RING_READ_IDX_GET(scn,
1452 CE_state->ctrl_addr));
1453 }
1454 }
1455
1456 if (CE_state->send_cb && ce_send_entries_done_nolock(scn, CE_state)) {
1457 if (WLAN_IS_EPPING_ENABLED(cds_get_conparam()) ||
1458 more_snd_comp_cnt++ < CE_TXRX_COMP_CHECK_THRESHOLD) {
1459 goto more_completions;
1460 } else {
1461 HIF_ERROR(
1462 "%s:Potential infinite loop detected during send completion nentries_mask:0x%x sw read_idx:0x%x hw read_idx:0x%x",
1463 __func__, CE_state->src_ring->nentries_mask,
1464 CE_state->src_ring->sw_index,
1465 CE_SRC_RING_READ_IDX_GET(scn,
1466 CE_state->ctrl_addr));
1467 }
1468 }
1469
1470 if (CE_state->misc_cbs) {
1471 CE_int_status = CE_ENGINE_INT_STATUS_GET(scn, ctrl_addr);
1472 if (CE_int_status & CE_WATERMARK_MASK) {
1473 if (CE_state->watermark_cb) {
1474 goto more_watermarks;
1475 }
1476 }
1477 }
1478
Houston Hoffman44b7e4a2015-09-03 17:01:22 -07001479 cdf_spin_unlock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001480 cdf_atomic_set(&CE_state->rx_pending, 0);
1481
1482 if (Q_TARGET_ACCESS_END(scn) < 0)
Houston Hoffman5bf441a2015-09-02 11:52:10 -07001483 HIF_ERROR("<--[premature rc=%d]\n", CE_state->receive_count);
1484 return CE_state->receive_count;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001485}
1486
1487/*
1488 * Handler for per-engine interrupts on ALL active CEs.
1489 * This is used in cases where the system is sharing a
1490 * single interrput for all CEs
1491 */
1492
1493void ce_per_engine_service_any(int irq, struct ol_softc *scn)
1494{
1495 int CE_id;
1496 uint32_t intr_summary;
1497
1498 A_TARGET_ACCESS_BEGIN(scn);
1499 if (!cdf_atomic_read(&scn->tasklet_from_intr)) {
1500 for (CE_id = 0; CE_id < scn->ce_count; CE_id++) {
1501 struct CE_state *CE_state = scn->ce_id_to_state[CE_id];
1502 if (cdf_atomic_read(&CE_state->rx_pending)) {
1503 cdf_atomic_set(&CE_state->rx_pending, 0);
1504 ce_per_engine_service(scn, CE_id);
1505 }
1506 }
1507
1508 A_TARGET_ACCESS_END(scn);
1509 return;
1510 }
1511
1512 intr_summary = CE_INTERRUPT_SUMMARY(scn);
1513
1514 for (CE_id = 0; intr_summary && (CE_id < scn->ce_count); CE_id++) {
1515 if (intr_summary & (1 << CE_id)) {
1516 intr_summary &= ~(1 << CE_id);
1517 } else {
1518 continue; /* no intr pending on this CE */
1519 }
1520
1521 ce_per_engine_service(scn, CE_id);
1522 }
1523
1524 A_TARGET_ACCESS_END(scn);
1525}
1526
1527/*
1528 * Adjust interrupts for the copy complete handler.
1529 * If it's needed for either send or recv, then unmask
1530 * this interrupt; otherwise, mask it.
1531 *
1532 * Called with target_lock held.
1533 */
1534static void
1535ce_per_engine_handler_adjust(struct CE_state *CE_state,
1536 int disable_copy_compl_intr)
1537{
1538 uint32_t ctrl_addr = CE_state->ctrl_addr;
1539 struct ol_softc *scn = CE_state->scn;
1540
1541 CE_state->disable_copy_compl_intr = disable_copy_compl_intr;
1542 A_TARGET_ACCESS_BEGIN(scn);
1543 if ((!disable_copy_compl_intr) &&
1544 (CE_state->send_cb || CE_state->recv_cb)) {
1545 CE_COPY_COMPLETE_INTR_ENABLE(scn, ctrl_addr);
1546 } else {
1547 CE_COPY_COMPLETE_INTR_DISABLE(scn, ctrl_addr);
1548 }
1549
1550 if (CE_state->watermark_cb) {
1551 CE_WATERMARK_INTR_ENABLE(scn, ctrl_addr);
1552 } else {
1553 CE_WATERMARK_INTR_DISABLE(scn, ctrl_addr);
1554 }
1555 A_TARGET_ACCESS_END(scn);
1556
1557}
1558
1559/*Iterate the CE_state list and disable the compl interrupt
1560 * if it has been registered already.
1561 */
1562void ce_disable_any_copy_compl_intr_nolock(struct ol_softc *scn)
1563{
1564 int CE_id;
1565
1566 A_TARGET_ACCESS_BEGIN(scn);
1567 for (CE_id = 0; CE_id < scn->ce_count; CE_id++) {
1568 struct CE_state *CE_state = scn->ce_id_to_state[CE_id];
1569 uint32_t ctrl_addr = CE_state->ctrl_addr;
1570
1571 /* if the interrupt is currently enabled, disable it */
1572 if (!CE_state->disable_copy_compl_intr
1573 && (CE_state->send_cb || CE_state->recv_cb)) {
1574 CE_COPY_COMPLETE_INTR_DISABLE(scn, ctrl_addr);
1575 }
1576
1577 if (CE_state->watermark_cb) {
1578 CE_WATERMARK_INTR_DISABLE(scn, ctrl_addr);
1579 }
1580 }
1581 A_TARGET_ACCESS_END(scn);
1582}
1583
1584void ce_enable_any_copy_compl_intr_nolock(struct ol_softc *scn)
1585{
1586 int CE_id;
1587
1588 A_TARGET_ACCESS_BEGIN(scn);
1589 for (CE_id = 0; CE_id < scn->ce_count; CE_id++) {
1590 struct CE_state *CE_state = scn->ce_id_to_state[CE_id];
1591 uint32_t ctrl_addr = CE_state->ctrl_addr;
1592
1593 /*
1594 * If the CE is supposed to have copy complete interrupts
1595 * enabled (i.e. there a callback registered, and the
1596 * "disable" flag is not set), then re-enable the interrupt.
1597 */
1598 if (!CE_state->disable_copy_compl_intr
1599 && (CE_state->send_cb || CE_state->recv_cb)) {
1600 CE_COPY_COMPLETE_INTR_ENABLE(scn, ctrl_addr);
1601 }
1602
1603 if (CE_state->watermark_cb) {
1604 CE_WATERMARK_INTR_ENABLE(scn, ctrl_addr);
1605 }
1606 }
1607 A_TARGET_ACCESS_END(scn);
1608}
1609
Houston Hoffmana837c9a2015-09-03 12:47:01 -07001610/**
1611 * ce_send_cb_register(): register completion handler
1612 * @copyeng: CE_state representing the ce we are adding the behavior to
1613 * @fn_ptr: callback that the ce should use when processing tx completions
1614 * @disable_interrupts: if the interupts should be enabled or not.
1615 *
1616 * Caller should guarantee that no transactions are in progress before
1617 * switching the callback function.
1618 *
1619 * Registers the send context before the fn pointer so that if the cb is valid
1620 * the context should be valid.
1621 *
1622 * Beware that currently this function will enable completion interrupts.
1623 */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001624void
1625ce_send_cb_register(struct CE_handle *copyeng,
1626 ce_send_cb fn_ptr,
1627 void *ce_send_context, int disable_interrupts)
1628{
1629 struct CE_state *CE_state = (struct CE_state *)copyeng;
1630
Sanjay Devnani9ce15772015-11-12 14:08:57 -08001631 if (CE_state == NULL) {
1632 pr_err("%s: Error CE state = NULL\n", __func__);
1633 return;
1634 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001635 CE_state->send_context = ce_send_context;
Houston Hoffmana837c9a2015-09-03 12:47:01 -07001636 CE_state->send_cb = fn_ptr;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001637 ce_per_engine_handler_adjust(CE_state, disable_interrupts);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001638}
1639
Houston Hoffmana837c9a2015-09-03 12:47:01 -07001640/**
1641 * ce_recv_cb_register(): register completion handler
1642 * @copyeng: CE_state representing the ce we are adding the behavior to
1643 * @fn_ptr: callback that the ce should use when processing rx completions
1644 * @disable_interrupts: if the interupts should be enabled or not.
1645 *
1646 * Registers the send context before the fn pointer so that if the cb is valid
1647 * the context should be valid.
1648 *
1649 * Caller should guarantee that no transactions are in progress before
1650 * switching the callback function.
1651 */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001652void
1653ce_recv_cb_register(struct CE_handle *copyeng,
1654 CE_recv_cb fn_ptr,
1655 void *CE_recv_context, int disable_interrupts)
1656{
1657 struct CE_state *CE_state = (struct CE_state *)copyeng;
1658
Sanjay Devnani9ce15772015-11-12 14:08:57 -08001659 if (CE_state == NULL) {
1660 pr_err("%s: ERROR CE state = NULL\n", __func__);
1661 return;
1662 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001663 CE_state->recv_context = CE_recv_context;
Houston Hoffmana837c9a2015-09-03 12:47:01 -07001664 CE_state->recv_cb = fn_ptr;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001665 ce_per_engine_handler_adjust(CE_state, disable_interrupts);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001666}
1667
Houston Hoffmana837c9a2015-09-03 12:47:01 -07001668/**
1669 * ce_watermark_cb_register(): register completion handler
1670 * @copyeng: CE_state representing the ce we are adding the behavior to
1671 * @fn_ptr: callback that the ce should use when processing watermark events
1672 *
1673 * Caller should guarantee that no watermark events are being processed before
1674 * switching the callback function.
1675 */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001676void
1677ce_watermark_cb_register(struct CE_handle *copyeng,
1678 CE_watermark_cb fn_ptr, void *CE_wm_context)
1679{
1680 struct CE_state *CE_state = (struct CE_state *)copyeng;
1681
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001682 CE_state->watermark_cb = fn_ptr;
1683 CE_state->wm_context = CE_wm_context;
1684 ce_per_engine_handler_adjust(CE_state, 0);
1685 if (fn_ptr) {
1686 CE_state->misc_cbs = 1;
1687 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001688}
1689
1690#ifdef WLAN_FEATURE_FASTPATH
1691/**
1692 * ce_pkt_dl_len_set() set the HTT packet download length
1693 * @hif_sc: HIF context
1694 * @pkt_download_len: download length
1695 *
1696 * Return: None
1697 */
1698void ce_pkt_dl_len_set(void *hif_sc, u_int32_t pkt_download_len)
1699{
1700 struct ol_softc *sc = (struct ol_softc *)(hif_sc);
1701 struct CE_state *ce_state = sc->ce_id_to_state[CE_HTT_H2T_MSG];
1702
1703 cdf_assert_always(ce_state);
1704
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001705 ce_state->download_len = pkt_download_len;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001706
1707 cdf_print("%s CE %d Pkt download length %d\n", __func__,
1708 ce_state->id, ce_state->download_len);
1709}
1710#else
1711void ce_pkt_dl_len_set(void *hif_sc, u_int32_t pkt_download_len)
1712{
1713}
1714#endif /* WLAN_FEATURE_FASTPATH */
1715
1716bool ce_get_rx_pending(struct ol_softc *scn)
1717{
1718 int CE_id;
1719
1720 for (CE_id = 0; CE_id < scn->ce_count; CE_id++) {
1721 struct CE_state *CE_state = scn->ce_id_to_state[CE_id];
1722 if (cdf_atomic_read(&CE_state->rx_pending))
1723 return true;
1724 }
1725
1726 return false;
1727}
1728
1729/**
1730 * ce_check_rx_pending() - ce_check_rx_pending
1731 * @scn: ol_softc
1732 * @ce_id: ce_id
1733 *
1734 * Return: bool
1735 */
1736bool ce_check_rx_pending(struct ol_softc *scn, int ce_id)
1737{
1738 struct CE_state *CE_state = scn->ce_id_to_state[ce_id];
1739 if (cdf_atomic_read(&CE_state->rx_pending))
1740 return true;
1741 else
1742 return false;
1743}
Houston Hoffman8ed92e52015-09-02 14:49:48 -07001744
1745/**
1746 * ce_enable_msi(): write the msi configuration to the target
1747 * @scn: hif context
1748 * @CE_id: which copy engine will be configured for msi interupts
1749 * @msi_addr_lo: Hardware will write to this address to generate an interrupt
1750 * @msi_addr_hi: Hardware will write to this address to generate an interrupt
1751 * @msi_data: Hardware will write this data to generate an interrupt
1752 *
1753 * should be done in the initialization sequence so no locking would be needed
1754 */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001755void ce_enable_msi(struct ol_softc *scn, unsigned int CE_id,
1756 uint32_t msi_addr_lo, uint32_t msi_addr_hi,
1757 uint32_t msi_data)
1758{
1759#ifdef WLAN_ENABLE_QCA6180
1760 struct CE_state *CE_state;
1761 A_target_id_t targid;
1762 u_int32_t ctrl_addr;
1763 uint32_t tmp;
1764
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001765 CE_state = scn->ce_id_to_state[CE_id];
1766 if (!CE_state) {
1767 HIF_ERROR("%s: error - CE_state = NULL", __func__);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001768 return;
1769 }
1770 targid = TARGID(sc);
1771 ctrl_addr = CE_state->ctrl_addr;
1772 CE_MSI_ADDR_LOW_SET(scn, ctrl_addr, msi_addr_lo);
1773 CE_MSI_ADDR_HIGH_SET(scn, ctrl_addr, msi_addr_hi);
1774 CE_MSI_DATA_SET(scn, ctrl_addr, msi_data);
1775 tmp = CE_CTRL_REGISTER1_GET(scn, ctrl_addr);
1776 tmp |= (1 << CE_MSI_ENABLE_BIT);
1777 CE_CTRL_REGISTER1_SET(scn, ctrl_addr, tmp);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001778#endif
1779}
1780
1781#ifdef IPA_OFFLOAD
Leo Changd85f78d2015-11-13 10:55:34 -08001782/**
1783 * ce_ipa_get_resource() - get uc resource on copyengine
1784 * @ce: copyengine context
1785 * @ce_sr_base_paddr: copyengine source ring base physical address
1786 * @ce_sr_ring_size: copyengine source ring size
1787 * @ce_reg_paddr: copyengine register physical address
1788 *
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001789 * Copy engine should release resource to micro controller
1790 * Micro controller needs
Leo Changd85f78d2015-11-13 10:55:34 -08001791 * - Copy engine source descriptor base address
1792 * - Copy engine source descriptor size
1793 * - PCI BAR address to access copy engine regiser
1794 *
1795 * Return: None
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001796 */
1797void ce_ipa_get_resource(struct CE_handle *ce,
Leo Changd85f78d2015-11-13 10:55:34 -08001798 cdf_dma_addr_t *ce_sr_base_paddr,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001799 uint32_t *ce_sr_ring_size,
1800 cdf_dma_addr_t *ce_reg_paddr)
1801{
1802 struct CE_state *CE_state = (struct CE_state *)ce;
1803 uint32_t ring_loop;
1804 struct CE_src_desc *ce_desc;
1805 cdf_dma_addr_t phy_mem_base;
1806 struct ol_softc *scn = CE_state->scn;
1807
1808 if (CE_RUNNING != CE_state->state) {
1809 *ce_sr_base_paddr = 0;
1810 *ce_sr_ring_size = 0;
1811 return;
1812 }
1813
1814 /* Update default value for descriptor */
1815 for (ring_loop = 0; ring_loop < CE_state->src_ring->nentries;
1816 ring_loop++) {
1817 ce_desc = (struct CE_src_desc *)
1818 ((char *)CE_state->src_ring->base_addr_owner_space +
1819 ring_loop * (sizeof(struct CE_src_desc)));
1820 CE_IPA_RING_INIT(ce_desc);
1821 }
1822
1823 /* Get BAR address */
1824 hif_read_phy_mem_base(CE_state->scn, &phy_mem_base);
1825
Leo Changd85f78d2015-11-13 10:55:34 -08001826 *ce_sr_base_paddr = CE_state->src_ring->base_addr_CE_space;
1827 *ce_sr_ring_size = (uint32_t) (CE_state->src_ring->nentries *
1828 sizeof(struct CE_src_desc));
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001829 *ce_reg_paddr = phy_mem_base + CE_BASE_ADDRESS(CE_state->id) +
1830 SR_WR_INDEX_ADDRESS;
1831 return;
1832}
1833#endif /* IPA_OFFLOAD */
1834