blob: 2f1c0a4b989b3cb06a0878ed97756c6180b8e9bf [file] [log] [blame]
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001/*
Komal Seelam644263d2016-02-22 20:45:49 +05302 * Copyright (c) 2013-2016 The Linux Foundation. All rights reserved.
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08003 *
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
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080028#include "hif.h"
29#include "hif_io32.h"
30#include "ce_api.h"
31#include "ce_main.h"
32#include "ce_internal.h"
33#include "ce_reg.h"
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +053034#include "qdf_lock.h"
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080035#include "regtable.h"
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080036#include "epping_main.h"
37#include "hif_main.h"
38#include "hif_debug.h"
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080039
40#ifdef IPA_OFFLOAD
41#ifdef QCA_WIFI_3_0
42#define CE_IPA_RING_INIT(ce_desc) \
43 do { \
44 ce_desc->gather = 0; \
45 ce_desc->enable_11h = 0; \
46 ce_desc->meta_data_low = 0; \
47 ce_desc->packet_result_offset = 64; \
48 ce_desc->toeplitz_hash_enable = 0; \
49 ce_desc->addr_y_search_disable = 0; \
50 ce_desc->addr_x_search_disable = 0; \
51 ce_desc->misc_int_disable = 0; \
52 ce_desc->target_int_disable = 0; \
53 ce_desc->host_int_disable = 0; \
54 ce_desc->dest_byte_swap = 0; \
55 ce_desc->byte_swap = 0; \
56 ce_desc->type = 2; \
57 ce_desc->tx_classify = 1; \
58 ce_desc->buffer_addr_hi = 0; \
59 ce_desc->meta_data = 0; \
60 ce_desc->nbytes = 128; \
61 } while (0)
62#else
63#define CE_IPA_RING_INIT(ce_desc) \
64 do { \
65 ce_desc->byte_swap = 0; \
66 ce_desc->nbytes = 60; \
67 ce_desc->gather = 0; \
68 } while (0)
69#endif /* QCA_WIFI_3_0 */
70#endif /* IPA_OFFLOAD */
71
72static int war1_allow_sleep;
73/* io32 write workaround */
74static int hif_ce_war1;
75
Houston Hoffman68e837e2015-12-04 12:57:24 -080076#ifdef CONFIG_SLUB_DEBUG_ON
77
78/**
79 * struct hif_ce_event - structure for detailing a ce event
80 * @type: what the event was
81 * @time: when it happened
82 * @descriptor: descriptor enqueued or dequeued
83 * @memory: virtual address that was used
84 * @index: location of the descriptor in the ce ring;
85 */
86struct hif_ce_desc_event {
87 uint16_t index;
88 enum hif_ce_event_type type;
89 uint64_t time;
90 union ce_desc descriptor;
91 void *memory;
92};
93
94/* max history to record per copy engine */
95#define HIF_CE_HISTORY_MAX 512
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +053096qdf_atomic_t hif_ce_desc_history_index[CE_COUNT_MAX];
Houston Hoffman68e837e2015-12-04 12:57:24 -080097struct hif_ce_desc_event hif_ce_desc_history[CE_COUNT_MAX][HIF_CE_HISTORY_MAX];
98
Houston Hoffman4275ba22015-12-06 21:02:11 -080099
Houston Hoffman68e837e2015-12-04 12:57:24 -0800100/**
101 * get_next_record_index() - get the next record index
102 * @table_index: atomic index variable to increment
103 * @array_size: array size of the circular buffer
104 *
105 * Increment the atomic index and reserve the value.
106 * Takes care of buffer wrap.
107 * Guaranteed to be thread safe as long as fewer than array_size contexts
108 * try to access the array. If there are more than array_size contexts
109 * trying to access the array, full locking of the recording process would
110 * be needed to have sane logging.
111 */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530112static int get_next_record_index(qdf_atomic_t *table_index, int array_size)
Houston Hoffman68e837e2015-12-04 12:57:24 -0800113{
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530114 int record_index = qdf_atomic_inc_return(table_index);
Houston Hoffman68e837e2015-12-04 12:57:24 -0800115 if (record_index == array_size)
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530116 qdf_atomic_sub(array_size, table_index);
Houston Hoffman68e837e2015-12-04 12:57:24 -0800117
118 while (record_index >= array_size)
119 record_index -= array_size;
120 return record_index;
121}
122
123/**
124 * hif_record_ce_desc_event() - record ce descriptor events
Komal Seelambd7c51d2016-02-24 10:27:30 +0530125 * @scn: hif_softc
Houston Hoffman68e837e2015-12-04 12:57:24 -0800126 * @ce_id: which ce is the event occuring on
127 * @type: what happened
128 * @descriptor: pointer to the descriptor posted/completed
129 * @memory: virtual address of buffer related to the descriptor
130 * @index: index that the descriptor was/will be at.
131 */
Komal Seelambd7c51d2016-02-24 10:27:30 +0530132void hif_record_ce_desc_event(struct hif_softc *scn, int ce_id,
133 enum hif_ce_event_type type,
134 union ce_desc *descriptor,
135 void *memory, int index)
Houston Hoffman68e837e2015-12-04 12:57:24 -0800136{
137 int record_index = get_next_record_index(
138 &hif_ce_desc_history_index[ce_id], HIF_CE_HISTORY_MAX);
139
140 struct hif_ce_desc_event *event =
141 &hif_ce_desc_history[ce_id][record_index];
142 event->type = type;
Komal Seelam75080122016-03-02 15:18:25 +0530143 event->time = qdf_get_monotonic_boottime();
Komal Seelambd7c51d2016-02-24 10:27:30 +0530144
Houston Hoffman4275ba22015-12-06 21:02:11 -0800145 if (descriptor != NULL)
146 event->descriptor = *descriptor;
147 else
148 memset(&event->descriptor, 0, sizeof(union ce_desc));
Houston Hoffman68e837e2015-12-04 12:57:24 -0800149 event->memory = memory;
150 event->index = index;
151}
152
153/**
154 * ce_init_ce_desc_event_log() - initialize the ce event log
155 * @ce_id: copy engine id for which we are initializing the log
156 * @size: size of array to dedicate
157 *
158 * Currently the passed size is ignored in favor of a precompiled value.
159 */
160void ce_init_ce_desc_event_log(int ce_id, int size)
161{
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530162 qdf_atomic_init(&hif_ce_desc_history_index[ce_id]);
Houston Hoffman68e837e2015-12-04 12:57:24 -0800163}
164#else
Komal Seelambd7c51d2016-02-24 10:27:30 +0530165void hif_record_ce_desc_event(struct hif_softc *scn,
Houston Hoffman68e837e2015-12-04 12:57:24 -0800166 int ce_id, enum hif_ce_event_type type,
167 union ce_desc *descriptor, void *memory,
168 int index)
169{
170}
171
Houston Hoffman5cc292b2015-12-22 11:33:14 -0800172inline void ce_init_ce_desc_event_log(int ce_id, int size)
Houston Hoffman68e837e2015-12-04 12:57:24 -0800173{
174}
175#endif
176
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800177/*
178 * Support for Copy Engine hardware, which is mainly used for
179 * communication between Host and Target over a PCIe interconnect.
180 */
181
182/*
183 * A single CopyEngine (CE) comprises two "rings":
184 * a source ring
185 * a destination ring
186 *
187 * Each ring consists of a number of descriptors which specify
188 * an address, length, and meta-data.
189 *
190 * Typically, one side of the PCIe interconnect (Host or Target)
191 * controls one ring and the other side controls the other ring.
192 * The source side chooses when to initiate a transfer and it
193 * chooses what to send (buffer address, length). The destination
194 * side keeps a supply of "anonymous receive buffers" available and
195 * it handles incoming data as it arrives (when the destination
196 * recieves an interrupt).
197 *
198 * The sender may send a simple buffer (address/length) or it may
199 * send a small list of buffers. When a small list is sent, hardware
200 * "gathers" these and they end up in a single destination buffer
201 * with a single interrupt.
202 *
203 * There are several "contexts" managed by this layer -- more, it
204 * may seem -- than should be needed. These are provided mainly for
205 * maximum flexibility and especially to facilitate a simpler HIF
206 * implementation. There are per-CopyEngine recv, send, and watermark
207 * contexts. These are supplied by the caller when a recv, send,
208 * or watermark handler is established and they are echoed back to
209 * the caller when the respective callbacks are invoked. There is
210 * also a per-transfer context supplied by the caller when a buffer
211 * (or sendlist) is sent and when a buffer is enqueued for recv.
212 * These per-transfer contexts are echoed back to the caller when
213 * the buffer is sent/received.
214 * Target TX harsh result toeplitz_hash_result
215 */
216
217/*
218 * Guts of ce_send, used by both ce_send and ce_sendlist_send.
219 * The caller takes responsibility for any needed locking.
220 */
221int
222ce_completed_send_next_nolock(struct CE_state *CE_state,
223 void **per_CE_contextp,
224 void **per_transfer_contextp,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530225 qdf_dma_addr_t *bufferp,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800226 unsigned int *nbytesp,
227 unsigned int *transfer_idp,
228 unsigned int *sw_idx, unsigned int *hw_idx,
229 uint32_t *toeplitz_hash_result);
230
Komal Seelam644263d2016-02-22 20:45:49 +0530231void war_ce_src_ring_write_idx_set(struct hif_softc *scn,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800232 u32 ctrl_addr, unsigned int write_index)
233{
234 if (hif_ce_war1) {
235 void __iomem *indicator_addr;
236
237 indicator_addr = scn->mem + ctrl_addr + DST_WATERMARK_ADDRESS;
238
239 if (!war1_allow_sleep
240 && ctrl_addr == CE_BASE_ADDRESS(CDC_WAR_DATA_CE)) {
241 hif_write32_mb(indicator_addr,
242 (CDC_WAR_MAGIC_STR | write_index));
243 } else {
244 unsigned long irq_flags;
245 local_irq_save(irq_flags);
246 hif_write32_mb(indicator_addr, 1);
247
248 /*
249 * PCIE write waits for ACK in IPQ8K, there is no
250 * need to read back value.
251 */
252 (void)hif_read32_mb(indicator_addr);
253 (void)hif_read32_mb(indicator_addr); /* conservative */
254
255 CE_SRC_RING_WRITE_IDX_SET(scn,
256 ctrl_addr, write_index);
257
258 hif_write32_mb(indicator_addr, 0);
259 local_irq_restore(irq_flags);
260 }
261 } else
262 CE_SRC_RING_WRITE_IDX_SET(scn, ctrl_addr, write_index);
263}
264
265int
266ce_send_nolock(struct CE_handle *copyeng,
267 void *per_transfer_context,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530268 qdf_dma_addr_t buffer,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800269 uint32_t nbytes,
270 uint32_t transfer_id,
271 uint32_t flags,
272 uint32_t user_flags)
273{
274 int status;
275 struct CE_state *CE_state = (struct CE_state *)copyeng;
276 struct CE_ring_state *src_ring = CE_state->src_ring;
277 uint32_t ctrl_addr = CE_state->ctrl_addr;
278 unsigned int nentries_mask = src_ring->nentries_mask;
279 unsigned int sw_index = src_ring->sw_index;
280 unsigned int write_index = src_ring->write_index;
281 uint64_t dma_addr = buffer;
Komal Seelam644263d2016-02-22 20:45:49 +0530282 struct hif_softc *scn = CE_state->scn;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800283
Houston Hoffman2c32cf62016-03-14 21:12:00 -0700284 if (Q_TARGET_ACCESS_BEGIN(scn) < 0)
Houston Hoffman987ab442016-03-14 21:12:02 -0700285 return QDF_STATUS_E_FAILURE;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800286 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);
Houston Hoffman987ab442016-03-14 21:12:02 -0700289 Q_TARGET_ACCESS_END(scn);
290 return QDF_STATUS_E_FAILURE;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800291 }
292 {
Houston Hoffman68e837e2015-12-04 12:57:24 -0800293 enum hif_ce_event_type event_type = HIF_TX_GATHER_DESC_POST;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800294 struct CE_src_desc *src_ring_base =
295 (struct CE_src_desc *)src_ring->base_addr_owner_space;
296 struct CE_src_desc *shadow_base =
297 (struct CE_src_desc *)src_ring->shadow_base;
298 struct CE_src_desc *src_desc =
299 CE_SRC_RING_TO_DESC(src_ring_base, write_index);
300 struct CE_src_desc *shadow_src_desc =
301 CE_SRC_RING_TO_DESC(shadow_base, write_index);
302
303 /* Update low 32 bits source descriptor address */
304 shadow_src_desc->buffer_addr =
305 (uint32_t)(dma_addr & 0xFFFFFFFF);
306#ifdef QCA_WIFI_3_0
307 shadow_src_desc->buffer_addr_hi =
308 (uint32_t)((dma_addr >> 32) & 0x1F);
309 user_flags |= shadow_src_desc->buffer_addr_hi;
310 memcpy(&(((uint32_t *)shadow_src_desc)[1]), &user_flags,
311 sizeof(uint32_t));
312#endif
313 shadow_src_desc->meta_data = transfer_id;
314
315 /*
316 * Set the swap bit if:
317 * typical sends on this CE are swapped (host is big-endian)
318 * and this send doesn't disable the swapping
319 * (data is not bytestream)
320 */
321 shadow_src_desc->byte_swap =
322 (((CE_state->attr_flags & CE_ATTR_BYTE_SWAP_DATA)
323 != 0) & ((flags & CE_SEND_FLAG_SWAP_DISABLE) == 0));
324 shadow_src_desc->gather = ((flags & CE_SEND_FLAG_GATHER) != 0);
325 shadow_src_desc->nbytes = nbytes;
326
327 *src_desc = *shadow_src_desc;
328
329 src_ring->per_transfer_context[write_index] =
330 per_transfer_context;
331
332 /* Update Source Ring Write Index */
333 write_index = CE_RING_IDX_INCR(nentries_mask, write_index);
334
335 /* WORKAROUND */
336 if (!shadow_src_desc->gather) {
Houston Hoffman68e837e2015-12-04 12:57:24 -0800337 event_type = HIF_TX_DESC_POST;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800338 war_ce_src_ring_write_idx_set(scn, ctrl_addr,
339 write_index);
340 }
341
Houston Hoffman68e837e2015-12-04 12:57:24 -0800342 /* src_ring->write index hasn't been updated event though
343 * the register has allready been written to.
344 */
Komal Seelambd7c51d2016-02-24 10:27:30 +0530345 hif_record_ce_desc_event(scn, CE_state->id, event_type,
Houston Hoffman68e837e2015-12-04 12:57:24 -0800346 (union ce_desc *) shadow_src_desc, per_transfer_context,
347 src_ring->write_index);
348
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800349 src_ring->write_index = write_index;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530350 status = QDF_STATUS_SUCCESS;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800351 }
Houston Hoffman987ab442016-03-14 21:12:02 -0700352 Q_TARGET_ACCESS_END(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800353 return status;
354}
355
356int
357ce_send(struct CE_handle *copyeng,
358 void *per_transfer_context,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530359 qdf_dma_addr_t buffer,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800360 uint32_t nbytes,
361 uint32_t transfer_id,
362 uint32_t flags,
363 uint32_t user_flag)
364{
365 struct CE_state *CE_state = (struct CE_state *)copyeng;
366 int status;
367
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530368 qdf_spin_lock_bh(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800369 status = ce_send_nolock(copyeng, per_transfer_context, buffer, nbytes,
370 transfer_id, flags, user_flag);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530371 qdf_spin_unlock_bh(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800372
373 return status;
374}
375
376unsigned int ce_sendlist_sizeof(void)
377{
378 return sizeof(struct ce_sendlist);
379}
380
381void ce_sendlist_init(struct ce_sendlist *sendlist)
382{
383 struct ce_sendlist_s *sl = (struct ce_sendlist_s *)sendlist;
384 sl->num_items = 0;
385}
386
387int
388ce_sendlist_buf_add(struct ce_sendlist *sendlist,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530389 qdf_dma_addr_t buffer,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800390 uint32_t nbytes,
391 uint32_t flags,
392 uint32_t user_flags)
393{
394 struct ce_sendlist_s *sl = (struct ce_sendlist_s *)sendlist;
395 unsigned int num_items = sl->num_items;
396 struct ce_sendlist_item *item;
397
398 if (num_items >= CE_SENDLIST_ITEMS_MAX) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530399 QDF_ASSERT(num_items < CE_SENDLIST_ITEMS_MAX);
400 return QDF_STATUS_E_RESOURCES;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800401 }
402
403 item = &sl->item[num_items];
404 item->send_type = CE_SIMPLE_BUFFER_TYPE;
405 item->data = buffer;
406 item->u.nbytes = nbytes;
407 item->flags = flags;
408 item->user_flags = user_flags;
409 sl->num_items = num_items + 1;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530410 return QDF_STATUS_SUCCESS;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800411}
412
413int
414ce_sendlist_send(struct CE_handle *copyeng,
415 void *per_transfer_context,
416 struct ce_sendlist *sendlist, unsigned int transfer_id)
417{
418 int status = -ENOMEM;
419 struct ce_sendlist_s *sl = (struct ce_sendlist_s *)sendlist;
420 struct CE_state *CE_state = (struct CE_state *)copyeng;
421 struct CE_ring_state *src_ring = CE_state->src_ring;
422 unsigned int nentries_mask = src_ring->nentries_mask;
423 unsigned int num_items = sl->num_items;
424 unsigned int sw_index;
425 unsigned int write_index;
426
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530427 QDF_ASSERT((num_items > 0) && (num_items < src_ring->nentries));
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800428
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530429 qdf_spin_lock_bh(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800430 sw_index = src_ring->sw_index;
431 write_index = src_ring->write_index;
432
433 if (CE_RING_DELTA(nentries_mask, write_index, sw_index - 1) >=
434 num_items) {
435 struct ce_sendlist_item *item;
436 int i;
437
438 /* handle all but the last item uniformly */
439 for (i = 0; i < num_items - 1; i++) {
440 item = &sl->item[i];
441 /* TBDXXX: Support extensible sendlist_types? */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530442 QDF_ASSERT(item->send_type == CE_SIMPLE_BUFFER_TYPE);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800443 status = ce_send_nolock(copyeng, CE_SENDLIST_ITEM_CTXT,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530444 (qdf_dma_addr_t) item->data,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800445 item->u.nbytes, transfer_id,
446 item->flags | CE_SEND_FLAG_GATHER,
447 item->user_flags);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530448 QDF_ASSERT(status == QDF_STATUS_SUCCESS);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800449 }
450 /* provide valid context pointer for final item */
451 item = &sl->item[i];
452 /* TBDXXX: Support extensible sendlist_types? */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530453 QDF_ASSERT(item->send_type == CE_SIMPLE_BUFFER_TYPE);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800454 status = ce_send_nolock(copyeng, per_transfer_context,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530455 (qdf_dma_addr_t) item->data,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800456 item->u.nbytes,
457 transfer_id, item->flags,
458 item->user_flags);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530459 QDF_ASSERT(status == QDF_STATUS_SUCCESS);
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +0530460 QDF_NBUF_UPDATE_TX_PKT_COUNT((qdf_nbuf_t)per_transfer_context,
461 QDF_NBUF_TX_PKT_CE);
462 DPTRACE(qdf_dp_trace((qdf_nbuf_t)per_transfer_context,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530463 QDF_DP_TRACE_CE_PACKET_PTR_RECORD,
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +0530464 (uint8_t *)(((qdf_nbuf_t)per_transfer_context)->data),
465 sizeof(((qdf_nbuf_t)per_transfer_context)->data)));
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800466 } else {
467 /*
468 * Probably not worth the additional complexity to support
469 * partial sends with continuation or notification. We expect
470 * to use large rings and small sendlists. If we can't handle
471 * the entire request at once, punt it back to the caller.
472 */
473 }
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530474 qdf_spin_unlock_bh(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800475
476 return status;
477}
478
479#ifdef WLAN_FEATURE_FASTPATH
480#ifdef QCA_WIFI_3_0
481static inline void
482ce_buffer_addr_hi_set(struct CE_src_desc *shadow_src_desc,
483 uint64_t dma_addr,
484 uint32_t user_flags)
485{
486 shadow_src_desc->buffer_addr_hi =
487 (uint32_t)((dma_addr >> 32) & 0x1F);
488 user_flags |= shadow_src_desc->buffer_addr_hi;
489 memcpy(&(((uint32_t *)shadow_src_desc)[1]), &user_flags,
490 sizeof(uint32_t));
491}
492#else
493static inline void
494ce_buffer_addr_hi_set(struct CE_src_desc *shadow_src_desc,
495 uint64_t dma_addr,
496 uint32_t user_flags)
497{
498}
499#endif
500
501/**
502 * ce_send_fast() CE layer Tx buffer posting function
503 * @copyeng: copy engine handle
504 * @msdus: iarray of msdu to be sent
505 * @num_msdus: number of msdus in an array
506 * @transfer_id: transfer_id
507 *
508 * Assumption : Called with an array of MSDU's
509 * Function:
510 * For each msdu in the array
511 * 1. Check no. of available entries
512 * 2. Create src ring entries (allocated in consistent memory
513 * 3. Write index to h/w
514 *
515 * Return: No. of packets that could be sent
516 */
517
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +0530518int ce_send_fast(struct CE_handle *copyeng, qdf_nbuf_t *msdus,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800519 unsigned int num_msdus, unsigned int transfer_id)
520{
521 struct CE_state *ce_state = (struct CE_state *)copyeng;
Komal Seelam644263d2016-02-22 20:45:49 +0530522 struct hif_softc *scn = ce_state->scn;
Komal Seelam5584a7c2016-02-24 19:22:48 +0530523 struct hif_opaque_softc *hif_hdl = GET_HIF_OPAQUE_HDL(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800524 struct CE_ring_state *src_ring = ce_state->src_ring;
525 u_int32_t ctrl_addr = ce_state->ctrl_addr;
526 unsigned int nentries_mask = src_ring->nentries_mask;
527 unsigned int write_index;
528 unsigned int sw_index;
529 unsigned int frag_len;
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +0530530 qdf_nbuf_t msdu;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800531 int i;
532 uint64_t dma_addr;
533 uint32_t user_flags = 0;
534
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530535 qdf_spin_lock_bh(&ce_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800536 sw_index = src_ring->sw_index;
537 write_index = src_ring->write_index;
538
539 /* 2 msdus per packet */
540 for (i = 0; i < num_msdus; i++) {
541 struct CE_src_desc *src_ring_base =
542 (struct CE_src_desc *)src_ring->base_addr_owner_space;
543 struct CE_src_desc *shadow_base =
544 (struct CE_src_desc *)src_ring->shadow_base;
545 struct CE_src_desc *src_desc =
546 CE_SRC_RING_TO_DESC(src_ring_base, write_index);
547 struct CE_src_desc *shadow_src_desc =
548 CE_SRC_RING_TO_DESC(shadow_base, write_index);
549
Komal Seelam644263d2016-02-22 20:45:49 +0530550 hif_pm_runtime_get_noresume(hif_hdl);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800551 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 */
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +0530559 dma_addr = qdf_nbuf_get_frag_paddr(msdu, 0);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800560 shadow_src_desc->buffer_addr = (uint32_t)(dma_addr &
561 0xFFFFFFFF);
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +0530562 user_flags = qdf_nbuf_data_attr_get(msdu) & DESC_DATA_FLAG_MASK;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800563 ce_buffer_addr_hi_set(shadow_src_desc, dma_addr, user_flags);
564
565 shadow_src_desc->meta_data = transfer_id;
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +0530566 shadow_src_desc->nbytes = qdf_nbuf_get_frag_len(msdu, 0);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800567
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 */
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +0530592 dma_addr = qdf_nbuf_get_frag_paddr(msdu, 1);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800593 shadow_src_desc->buffer_addr = (uint32_t)(dma_addr &
594 0xFFFFFFFF);
595 /*
596 * Clear packet offset for all but the first CE desc.
597 */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530598 user_flags &= ~QDF_CE_TX_PKT_OFFSET_BIT_M;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800599 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 */
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +0530603 frag_len = qdf_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;
Houston Hoffmanf4607852015-12-17 17:14:40 -0800622
Komal Seelam644263d2016-02-22 20:45:49 +0530623 if (hif_pm_runtime_get(hif_hdl) == 0) {
Houston Hoffmanf4607852015-12-17 17:14:40 -0800624 /* Don't call WAR_XXX from here
625 * Just call XXX instead, that has the reqd. intel
626 */
627 war_ce_src_ring_write_idx_set(scn, ctrl_addr,
628 write_index);
Komal Seelam644263d2016-02-22 20:45:49 +0530629 hif_pm_runtime_put(hif_hdl);
Houston Hoffmanf4607852015-12-17 17:14:40 -0800630 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800631 }
632
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530633 qdf_spin_unlock_bh(&ce_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800634
635 /*
636 * If all packets in the array are transmitted,
637 * i = num_msdus
638 * Temporarily add an ASSERT
639 */
640 ASSERT(i == num_msdus);
641 return i;
642}
643#endif /* WLAN_FEATURE_FASTPATH */
644
Houston Hoffman4411ad42016-03-14 21:12:04 -0700645/**
646 * ce_recv_buf_enqueue() - enqueue a recv buffer into a copy engine
647 * @coyeng: copy engine handle
648 * @per_recv_context: virtual address of the nbuf
649 * @buffer: physical address of the nbuf
650 *
651 * Return: 0 if the buffer is enqueued
652 */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800653int
654ce_recv_buf_enqueue(struct CE_handle *copyeng,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530655 void *per_recv_context, qdf_dma_addr_t buffer)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800656{
657 int status;
658 struct CE_state *CE_state = (struct CE_state *)copyeng;
659 struct CE_ring_state *dest_ring = CE_state->dest_ring;
660 uint32_t ctrl_addr = CE_state->ctrl_addr;
661 unsigned int nentries_mask = dest_ring->nentries_mask;
662 unsigned int write_index;
663 unsigned int sw_index;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800664 uint64_t dma_addr = buffer;
Komal Seelam644263d2016-02-22 20:45:49 +0530665 struct hif_softc *scn = CE_state->scn;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800666
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530667 qdf_spin_lock_bh(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800668 write_index = dest_ring->write_index;
669 sw_index = dest_ring->sw_index;
670
Houston Hoffman4411ad42016-03-14 21:12:04 -0700671 if (Q_TARGET_ACCESS_BEGIN(scn) < 0) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530672 qdf_spin_unlock_bh(&CE_state->ce_index_lock);
Houston Hoffman4411ad42016-03-14 21:12:04 -0700673 return -EIO;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800674 }
675
676 if (CE_RING_DELTA(nentries_mask, write_index, sw_index - 1) > 0) {
677 struct CE_dest_desc *dest_ring_base =
678 (struct CE_dest_desc *)dest_ring->
679 base_addr_owner_space;
680 struct CE_dest_desc *dest_desc =
681 CE_DEST_RING_TO_DESC(dest_ring_base, write_index);
682
683 /* Update low 32 bit destination descriptor */
684 dest_desc->buffer_addr = (uint32_t)(dma_addr & 0xFFFFFFFF);
685#ifdef QCA_WIFI_3_0
686 dest_desc->buffer_addr_hi =
687 (uint32_t)((dma_addr >> 32) & 0x1F);
688#endif
689 dest_desc->nbytes = 0;
690
691 dest_ring->per_transfer_context[write_index] =
692 per_recv_context;
693
Komal Seelambd7c51d2016-02-24 10:27:30 +0530694 hif_record_ce_desc_event(scn, CE_state->id, HIF_RX_DESC_POST,
Houston Hoffman68e837e2015-12-04 12:57:24 -0800695 (union ce_desc *) dest_desc, per_recv_context,
696 write_index);
697
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800698 /* Update Destination Ring Write Index */
699 write_index = CE_RING_IDX_INCR(nentries_mask, write_index);
700 CE_DEST_RING_WRITE_IDX_SET(scn, ctrl_addr, write_index);
701 dest_ring->write_index = write_index;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530702 status = QDF_STATUS_SUCCESS;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800703 } else {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530704 status = QDF_STATUS_E_FAILURE;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800705 }
Houston Hoffman4411ad42016-03-14 21:12:04 -0700706 Q_TARGET_ACCESS_END(scn);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530707 qdf_spin_unlock_bh(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800708 return status;
709}
710
711void
712ce_send_watermarks_set(struct CE_handle *copyeng,
713 unsigned int low_alert_nentries,
714 unsigned int high_alert_nentries)
715{
716 struct CE_state *CE_state = (struct CE_state *)copyeng;
717 uint32_t ctrl_addr = CE_state->ctrl_addr;
Komal Seelam644263d2016-02-22 20:45:49 +0530718 struct hif_softc *scn = CE_state->scn;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800719
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800720 CE_SRC_RING_LOWMARK_SET(scn, ctrl_addr, low_alert_nentries);
721 CE_SRC_RING_HIGHMARK_SET(scn, ctrl_addr, high_alert_nentries);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800722}
723
724void
725ce_recv_watermarks_set(struct CE_handle *copyeng,
726 unsigned int low_alert_nentries,
727 unsigned int high_alert_nentries)
728{
729 struct CE_state *CE_state = (struct CE_state *)copyeng;
730 uint32_t ctrl_addr = CE_state->ctrl_addr;
Komal Seelam644263d2016-02-22 20:45:49 +0530731 struct hif_softc *scn = CE_state->scn;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800732
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800733 CE_DEST_RING_LOWMARK_SET(scn, ctrl_addr,
734 low_alert_nentries);
735 CE_DEST_RING_HIGHMARK_SET(scn, ctrl_addr,
736 high_alert_nentries);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800737}
738
739unsigned int ce_send_entries_avail(struct CE_handle *copyeng)
740{
741 struct CE_state *CE_state = (struct CE_state *)copyeng;
742 struct CE_ring_state *src_ring = CE_state->src_ring;
743 unsigned int nentries_mask = src_ring->nentries_mask;
744 unsigned int sw_index;
745 unsigned int write_index;
746
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530747 qdf_spin_lock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800748 sw_index = src_ring->sw_index;
749 write_index = src_ring->write_index;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530750 qdf_spin_unlock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800751
752 return CE_RING_DELTA(nentries_mask, write_index, sw_index - 1);
753}
754
755unsigned int ce_recv_entries_avail(struct CE_handle *copyeng)
756{
757 struct CE_state *CE_state = (struct CE_state *)copyeng;
758 struct CE_ring_state *dest_ring = CE_state->dest_ring;
759 unsigned int nentries_mask = dest_ring->nentries_mask;
760 unsigned int sw_index;
761 unsigned int write_index;
762
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530763 qdf_spin_lock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800764 sw_index = dest_ring->sw_index;
765 write_index = dest_ring->write_index;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530766 qdf_spin_unlock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800767
768 return CE_RING_DELTA(nentries_mask, write_index, sw_index - 1);
769}
770
771/*
772 * Guts of ce_send_entries_done.
773 * The caller takes responsibility for any necessary locking.
774 */
775unsigned int
Komal Seelam644263d2016-02-22 20:45:49 +0530776ce_send_entries_done_nolock(struct hif_softc *scn,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800777 struct CE_state *CE_state)
778{
779 struct CE_ring_state *src_ring = CE_state->src_ring;
780 uint32_t ctrl_addr = CE_state->ctrl_addr;
781 unsigned int nentries_mask = src_ring->nentries_mask;
782 unsigned int sw_index;
783 unsigned int read_index;
784
785 sw_index = src_ring->sw_index;
786 read_index = CE_SRC_RING_READ_IDX_GET(scn, ctrl_addr);
787
788 return CE_RING_DELTA(nentries_mask, sw_index, read_index);
789}
790
791unsigned int ce_send_entries_done(struct CE_handle *copyeng)
792{
793 struct CE_state *CE_state = (struct CE_state *)copyeng;
794 unsigned int nentries;
795
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530796 qdf_spin_lock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800797 nentries = ce_send_entries_done_nolock(CE_state->scn, CE_state);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530798 qdf_spin_unlock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800799
800 return nentries;
801}
802
803/*
804 * Guts of ce_recv_entries_done.
805 * The caller takes responsibility for any necessary locking.
806 */
807unsigned int
Komal Seelam644263d2016-02-22 20:45:49 +0530808ce_recv_entries_done_nolock(struct hif_softc *scn,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800809 struct CE_state *CE_state)
810{
811 struct CE_ring_state *dest_ring = CE_state->dest_ring;
812 uint32_t ctrl_addr = CE_state->ctrl_addr;
813 unsigned int nentries_mask = dest_ring->nentries_mask;
814 unsigned int sw_index;
815 unsigned int read_index;
816
817 sw_index = dest_ring->sw_index;
818 read_index = CE_DEST_RING_READ_IDX_GET(scn, ctrl_addr);
819
820 return CE_RING_DELTA(nentries_mask, sw_index, read_index);
821}
822
823unsigned int ce_recv_entries_done(struct CE_handle *copyeng)
824{
825 struct CE_state *CE_state = (struct CE_state *)copyeng;
826 unsigned int nentries;
827
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530828 qdf_spin_lock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800829 nentries = ce_recv_entries_done_nolock(CE_state->scn, CE_state);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530830 qdf_spin_unlock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800831
832 return nentries;
833}
834
835/* Debug support */
836void *ce_debug_cmplrn_context; /* completed recv next context */
837void *ce_debug_cnclsn_context; /* cancel send next context */
838void *ce_debug_rvkrn_context; /* revoke receive next context */
839void *ce_debug_cmplsn_context; /* completed send next context */
840
841/*
842 * Guts of ce_completed_recv_next.
843 * The caller takes responsibility for any necessary locking.
844 */
845int
846ce_completed_recv_next_nolock(struct CE_state *CE_state,
847 void **per_CE_contextp,
848 void **per_transfer_contextp,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530849 qdf_dma_addr_t *bufferp,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800850 unsigned int *nbytesp,
851 unsigned int *transfer_idp,
852 unsigned int *flagsp)
853{
854 int status;
855 struct CE_ring_state *dest_ring = CE_state->dest_ring;
856 unsigned int nentries_mask = dest_ring->nentries_mask;
857 unsigned int sw_index = dest_ring->sw_index;
Komal Seelambd7c51d2016-02-24 10:27:30 +0530858 struct hif_softc *scn = CE_state->scn;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800859 struct CE_dest_desc *dest_ring_base =
860 (struct CE_dest_desc *)dest_ring->base_addr_owner_space;
861 struct CE_dest_desc *dest_desc =
862 CE_DEST_RING_TO_DESC(dest_ring_base, sw_index);
863 int nbytes;
864 struct CE_dest_desc dest_desc_info;
865 /*
866 * By copying the dest_desc_info element to local memory, we could
867 * avoid extra memory read from non-cachable memory.
868 */
869 dest_desc_info = *dest_desc;
870 nbytes = dest_desc_info.nbytes;
871 if (nbytes == 0) {
872 /*
873 * This closes a relatively unusual race where the Host
874 * sees the updated DRRI before the update to the
875 * corresponding descriptor has completed. We treat this
876 * as a descriptor that is not yet done.
877 */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530878 status = QDF_STATUS_E_FAILURE;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800879 goto done;
880 }
881
Komal Seelambd7c51d2016-02-24 10:27:30 +0530882 hif_record_ce_desc_event(scn, CE_state->id, HIF_RX_DESC_COMPLETION,
Houston Hoffman68e837e2015-12-04 12:57:24 -0800883 (union ce_desc *) dest_desc,
884 dest_ring->per_transfer_context[sw_index],
885 sw_index);
886
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800887 dest_desc->nbytes = 0;
888
889 /* Return data from completed destination descriptor */
890 *bufferp = HIF_CE_DESC_ADDR_TO_DMA(&dest_desc_info);
891 *nbytesp = nbytes;
892 *transfer_idp = dest_desc_info.meta_data;
893 *flagsp = (dest_desc_info.byte_swap) ? CE_RECV_FLAG_SWAPPED : 0;
894
895 if (per_CE_contextp) {
896 *per_CE_contextp = CE_state->recv_context;
897 }
898
899 ce_debug_cmplrn_context = dest_ring->per_transfer_context[sw_index];
900 if (per_transfer_contextp) {
901 *per_transfer_contextp = ce_debug_cmplrn_context;
902 }
903 dest_ring->per_transfer_context[sw_index] = 0; /* sanity */
904
905 /* Update sw_index */
906 sw_index = CE_RING_IDX_INCR(nentries_mask, sw_index);
907 dest_ring->sw_index = sw_index;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530908 status = QDF_STATUS_SUCCESS;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800909
910done:
911 return status;
912}
913
914int
915ce_completed_recv_next(struct CE_handle *copyeng,
916 void **per_CE_contextp,
917 void **per_transfer_contextp,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530918 qdf_dma_addr_t *bufferp,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800919 unsigned int *nbytesp,
920 unsigned int *transfer_idp, unsigned int *flagsp)
921{
922 struct CE_state *CE_state = (struct CE_state *)copyeng;
923 int status;
924
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530925 qdf_spin_lock_bh(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800926 status =
927 ce_completed_recv_next_nolock(CE_state, per_CE_contextp,
928 per_transfer_contextp, bufferp,
929 nbytesp, transfer_idp, flagsp);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530930 qdf_spin_unlock_bh(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800931
932 return status;
933}
934
935/* NB: Modeled after ce_completed_recv_next_nolock */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530936QDF_STATUS
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800937ce_revoke_recv_next(struct CE_handle *copyeng,
938 void **per_CE_contextp,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530939 void **per_transfer_contextp, qdf_dma_addr_t *bufferp)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800940{
941 struct CE_state *CE_state;
942 struct CE_ring_state *dest_ring;
943 unsigned int nentries_mask;
944 unsigned int sw_index;
945 unsigned int write_index;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530946 QDF_STATUS status;
Komal Seelam644263d2016-02-22 20:45:49 +0530947 struct hif_softc *scn;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800948
949 CE_state = (struct CE_state *)copyeng;
950 dest_ring = CE_state->dest_ring;
951 if (!dest_ring) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530952 return QDF_STATUS_E_FAILURE;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800953 }
954
955 scn = CE_state->scn;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530956 qdf_spin_lock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800957 nentries_mask = dest_ring->nentries_mask;
958 sw_index = dest_ring->sw_index;
959 write_index = dest_ring->write_index;
960 if (write_index != sw_index) {
961 struct CE_dest_desc *dest_ring_base =
962 (struct CE_dest_desc *)dest_ring->
963 base_addr_owner_space;
964 struct CE_dest_desc *dest_desc =
965 CE_DEST_RING_TO_DESC(dest_ring_base, sw_index);
966
967 /* Return data from completed destination descriptor */
968 *bufferp = HIF_CE_DESC_ADDR_TO_DMA(dest_desc);
969
970 if (per_CE_contextp) {
971 *per_CE_contextp = CE_state->recv_context;
972 }
973
974 ce_debug_rvkrn_context =
975 dest_ring->per_transfer_context[sw_index];
976 if (per_transfer_contextp) {
977 *per_transfer_contextp = ce_debug_rvkrn_context;
978 }
979 dest_ring->per_transfer_context[sw_index] = 0; /* sanity */
980
981 /* Update sw_index */
982 sw_index = CE_RING_IDX_INCR(nentries_mask, sw_index);
983 dest_ring->sw_index = sw_index;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530984 status = QDF_STATUS_SUCCESS;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800985 } else {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530986 status = QDF_STATUS_E_FAILURE;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800987 }
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530988 qdf_spin_unlock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800989
990 return status;
991}
992
993/*
994 * Guts of ce_completed_send_next.
995 * The caller takes responsibility for any necessary locking.
996 */
997int
998ce_completed_send_next_nolock(struct CE_state *CE_state,
999 void **per_CE_contextp,
1000 void **per_transfer_contextp,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301001 qdf_dma_addr_t *bufferp,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001002 unsigned int *nbytesp,
1003 unsigned int *transfer_idp,
1004 unsigned int *sw_idx,
1005 unsigned int *hw_idx,
1006 uint32_t *toeplitz_hash_result)
1007{
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301008 int status = QDF_STATUS_E_FAILURE;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001009 struct CE_ring_state *src_ring = CE_state->src_ring;
1010 uint32_t ctrl_addr = CE_state->ctrl_addr;
1011 unsigned int nentries_mask = src_ring->nentries_mask;
1012 unsigned int sw_index = src_ring->sw_index;
1013 unsigned int read_index;
Komal Seelam644263d2016-02-22 20:45:49 +05301014 struct hif_softc *scn = CE_state->scn;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001015
1016 if (src_ring->hw_index == sw_index) {
1017 /*
1018 * The SW completion index has caught up with the cached
1019 * version of the HW completion index.
1020 * Update the cached HW completion index to see whether
1021 * the SW has really caught up to the HW, or if the cached
1022 * value of the HW index has become stale.
1023 */
Houston Hoffman2c32cf62016-03-14 21:12:00 -07001024 if (Q_TARGET_ACCESS_BEGIN(scn) < 0)
Houston Hoffman987ab442016-03-14 21:12:02 -07001025 return QDF_STATUS_E_FAILURE;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001026 src_ring->hw_index =
Houston Hoffman3d0cda82015-12-03 13:25:05 -08001027 CE_SRC_RING_READ_IDX_GET_FROM_DDR(scn, ctrl_addr);
Houston Hoffman2c32cf62016-03-14 21:12:00 -07001028 if (Q_TARGET_ACCESS_END(scn) < 0)
Houston Hoffman987ab442016-03-14 21:12:02 -07001029 return QDF_STATUS_E_FAILURE;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001030 }
1031 read_index = src_ring->hw_index;
1032
1033 if (sw_idx)
1034 *sw_idx = sw_index;
1035
1036 if (hw_idx)
1037 *hw_idx = read_index;
1038
1039 if ((read_index != sw_index) && (read_index != 0xffffffff)) {
1040 struct CE_src_desc *shadow_base =
1041 (struct CE_src_desc *)src_ring->shadow_base;
1042 struct CE_src_desc *shadow_src_desc =
1043 CE_SRC_RING_TO_DESC(shadow_base, sw_index);
1044#ifdef QCA_WIFI_3_0
1045 struct CE_src_desc *src_ring_base =
1046 (struct CE_src_desc *)src_ring->base_addr_owner_space;
1047 struct CE_src_desc *src_desc =
1048 CE_SRC_RING_TO_DESC(src_ring_base, sw_index);
1049#endif
Komal Seelambd7c51d2016-02-24 10:27:30 +05301050 hif_record_ce_desc_event(scn, CE_state->id,
1051 HIF_TX_DESC_COMPLETION,
Houston Hoffman68e837e2015-12-04 12:57:24 -08001052 (union ce_desc *) shadow_src_desc,
1053 src_ring->per_transfer_context[sw_index],
1054 sw_index);
1055
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001056 /* Return data from completed source descriptor */
1057 *bufferp = HIF_CE_DESC_ADDR_TO_DMA(shadow_src_desc);
1058 *nbytesp = shadow_src_desc->nbytes;
1059 *transfer_idp = shadow_src_desc->meta_data;
1060#ifdef QCA_WIFI_3_0
1061 *toeplitz_hash_result = src_desc->toeplitz_hash_result;
1062#else
1063 *toeplitz_hash_result = 0;
1064#endif
1065 if (per_CE_contextp) {
1066 *per_CE_contextp = CE_state->send_context;
1067 }
1068
1069 ce_debug_cmplsn_context =
1070 src_ring->per_transfer_context[sw_index];
1071 if (per_transfer_contextp) {
1072 *per_transfer_contextp = ce_debug_cmplsn_context;
1073 }
1074 src_ring->per_transfer_context[sw_index] = 0; /* sanity */
1075
1076 /* Update sw_index */
1077 sw_index = CE_RING_IDX_INCR(nentries_mask, sw_index);
1078 src_ring->sw_index = sw_index;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301079 status = QDF_STATUS_SUCCESS;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001080 }
1081
1082 return status;
1083}
1084
1085/* NB: Modeled after ce_completed_send_next */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301086QDF_STATUS
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001087ce_cancel_send_next(struct CE_handle *copyeng,
1088 void **per_CE_contextp,
1089 void **per_transfer_contextp,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301090 qdf_dma_addr_t *bufferp,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001091 unsigned int *nbytesp,
1092 unsigned int *transfer_idp,
1093 uint32_t *toeplitz_hash_result)
1094{
1095 struct CE_state *CE_state;
1096 struct CE_ring_state *src_ring;
1097 unsigned int nentries_mask;
1098 unsigned int sw_index;
1099 unsigned int write_index;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301100 QDF_STATUS status;
Komal Seelam644263d2016-02-22 20:45:49 +05301101 struct hif_softc *scn;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001102
1103 CE_state = (struct CE_state *)copyeng;
1104 src_ring = CE_state->src_ring;
1105 if (!src_ring) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301106 return QDF_STATUS_E_FAILURE;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001107 }
1108
1109 scn = CE_state->scn;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301110 qdf_spin_lock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001111 nentries_mask = src_ring->nentries_mask;
1112 sw_index = src_ring->sw_index;
1113 write_index = src_ring->write_index;
1114
1115 if (write_index != sw_index) {
1116 struct CE_src_desc *src_ring_base =
1117 (struct CE_src_desc *)src_ring->base_addr_owner_space;
1118 struct CE_src_desc *src_desc =
1119 CE_SRC_RING_TO_DESC(src_ring_base, sw_index);
1120
1121 /* Return data from completed source descriptor */
1122 *bufferp = HIF_CE_DESC_ADDR_TO_DMA(src_desc);
1123 *nbytesp = src_desc->nbytes;
1124 *transfer_idp = src_desc->meta_data;
1125#ifdef QCA_WIFI_3_0
1126 *toeplitz_hash_result = src_desc->toeplitz_hash_result;
1127#else
1128 *toeplitz_hash_result = 0;
1129#endif
1130
1131 if (per_CE_contextp) {
1132 *per_CE_contextp = CE_state->send_context;
1133 }
1134
1135 ce_debug_cnclsn_context =
1136 src_ring->per_transfer_context[sw_index];
1137 if (per_transfer_contextp) {
1138 *per_transfer_contextp = ce_debug_cnclsn_context;
1139 }
1140 src_ring->per_transfer_context[sw_index] = 0; /* sanity */
1141
1142 /* Update sw_index */
1143 sw_index = CE_RING_IDX_INCR(nentries_mask, sw_index);
1144 src_ring->sw_index = sw_index;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301145 status = QDF_STATUS_SUCCESS;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001146 } else {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301147 status = QDF_STATUS_E_FAILURE;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001148 }
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301149 qdf_spin_unlock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001150
1151 return status;
1152}
1153
1154/* Shift bits to convert IS_*_RING_*_WATERMARK_MASK to CE_WM_FLAG_*_* */
1155#define CE_WM_SHFT 1
1156
1157int
1158ce_completed_send_next(struct CE_handle *copyeng,
1159 void **per_CE_contextp,
1160 void **per_transfer_contextp,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301161 qdf_dma_addr_t *bufferp,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001162 unsigned int *nbytesp,
1163 unsigned int *transfer_idp,
1164 unsigned int *sw_idx,
1165 unsigned int *hw_idx,
1166 unsigned int *toeplitz_hash_result)
1167{
1168 struct CE_state *CE_state = (struct CE_state *)copyeng;
1169 int status;
1170
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301171 qdf_spin_lock_bh(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001172 status =
1173 ce_completed_send_next_nolock(CE_state, per_CE_contextp,
1174 per_transfer_contextp, bufferp,
1175 nbytesp, transfer_idp, sw_idx,
1176 hw_idx, toeplitz_hash_result);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301177 qdf_spin_unlock_bh(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001178
1179 return status;
1180}
1181
1182#ifdef ATH_11AC_TXCOMPACT
1183/* CE engine descriptor reap
1184 * Similar to ce_per_engine_service , Only difference is ce_per_engine_service
1185 * does recieve and reaping of completed descriptor ,
1186 * This function only handles reaping of Tx complete descriptor.
1187 * The Function is called from threshold reap poll routine
1188 * hif_send_complete_check so should not countain recieve functionality
1189 * within it .
1190 */
1191
Komal Seelam644263d2016-02-22 20:45:49 +05301192void ce_per_engine_servicereap(struct hif_softc *scn, unsigned int ce_id)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001193{
1194 void *CE_context;
1195 void *transfer_context;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301196 qdf_dma_addr_t buf;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001197 unsigned int nbytes;
1198 unsigned int id;
1199 unsigned int sw_idx, hw_idx;
1200 uint32_t toeplitz_hash_result;
Houston Hoffmana575ec22015-12-14 16:35:15 -08001201 struct CE_state *CE_state = scn->ce_id_to_state[ce_id];
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001202
Houston Hoffmanbac94542016-03-14 21:11:59 -07001203 if (Q_TARGET_ACCESS_BEGIN(scn) < 0)
1204 return;
1205
Komal Seelambd7c51d2016-02-24 10:27:30 +05301206 hif_record_ce_desc_event(scn, ce_id, HIF_CE_REAP_ENTRY,
Houston Hoffmana575ec22015-12-14 16:35:15 -08001207 NULL, NULL, 0);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001208
1209 /* Since this function is called from both user context and
1210 * tasklet context the spinlock has to lock the bottom halves.
1211 * This fix assumes that ATH_11AC_TXCOMPACT flag is always
1212 * enabled in TX polling mode. If this is not the case, more
1213 * bottom halve spin lock changes are needed. Due to data path
1214 * performance concern, after internal discussion we've decided
1215 * to make minimum change, i.e., only address the issue occured
1216 * in this function. The possible negative effect of this minimum
1217 * change is that, in the future, if some other function will also
1218 * be opened to let the user context to use, those cases need to be
1219 * addressed by change spin_lock to spin_lock_bh also.
1220 */
1221
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301222 qdf_spin_lock_bh(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001223
1224 if (CE_state->send_cb) {
1225 {
1226 /* Pop completed send buffers and call the
1227 * registered send callback for each
1228 */
1229 while (ce_completed_send_next_nolock
1230 (CE_state, &CE_context,
1231 &transfer_context, &buf,
1232 &nbytes, &id, &sw_idx, &hw_idx,
1233 &toeplitz_hash_result) ==
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301234 QDF_STATUS_SUCCESS) {
Houston Hoffmana575ec22015-12-14 16:35:15 -08001235 if (ce_id != CE_HTT_H2T_MSG) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301236 qdf_spin_unlock_bh(
Houston Hoffman44b7e4a2015-09-03 17:01:22 -07001237 &CE_state->ce_index_lock);
1238 CE_state->send_cb(
1239 (struct CE_handle *)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001240 CE_state, CE_context,
1241 transfer_context, buf,
1242 nbytes, id, sw_idx, hw_idx,
1243 toeplitz_hash_result);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301244 qdf_spin_lock_bh(
Houston Hoffman44b7e4a2015-09-03 17:01:22 -07001245 &CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001246 } else {
1247 struct HIF_CE_pipe_info *pipe_info =
1248 (struct HIF_CE_pipe_info *)
1249 CE_context;
1250
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301251 qdf_spin_lock_bh(&pipe_info->
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001252 completion_freeq_lock);
1253 pipe_info->num_sends_allowed++;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301254 qdf_spin_unlock_bh(&pipe_info->
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001255 completion_freeq_lock);
1256 }
1257 }
1258 }
1259 }
1260
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301261 qdf_spin_unlock_bh(&CE_state->ce_index_lock);
Houston Hoffmana575ec22015-12-14 16:35:15 -08001262
Komal Seelambd7c51d2016-02-24 10:27:30 +05301263 hif_record_ce_desc_event(scn, ce_id, HIF_CE_REAP_EXIT,
Houston Hoffmana575ec22015-12-14 16:35:15 -08001264 NULL, NULL, 0);
Houston Hoffmanbac94542016-03-14 21:11:59 -07001265 Q_TARGET_ACCESS_END(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001266}
1267
1268#endif /*ATH_11AC_TXCOMPACT */
1269
1270/*
1271 * Number of times to check for any pending tx/rx completion on
1272 * a copy engine, this count should be big enough. Once we hit
1273 * this threashold we'll not check for any Tx/Rx comlpetion in same
1274 * interrupt handling. Note that this threashold is only used for
1275 * Rx interrupt processing, this can be used tor Tx as well if we
1276 * suspect any infinite loop in checking for pending Tx completion.
1277 */
1278#define CE_TXRX_COMP_CHECK_THRESHOLD 20
1279
1280/*
1281 * Guts of interrupt handler for per-engine interrupts on a particular CE.
1282 *
1283 * Invokes registered callbacks for recv_complete,
1284 * send_complete, and watermarks.
1285 *
1286 * Returns: number of messages processed
1287 */
1288
Komal Seelam644263d2016-02-22 20:45:49 +05301289int ce_per_engine_service(struct hif_softc *scn, unsigned int CE_id)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001290{
1291 struct CE_state *CE_state = scn->ce_id_to_state[CE_id];
1292 uint32_t ctrl_addr = CE_state->ctrl_addr;
1293 void *CE_context;
1294 void *transfer_context;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301295 qdf_dma_addr_t buf;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001296 unsigned int nbytes;
1297 unsigned int id;
1298 unsigned int flags;
1299 uint32_t CE_int_status;
1300 unsigned int more_comp_cnt = 0;
1301 unsigned int more_snd_comp_cnt = 0;
1302 unsigned int sw_idx, hw_idx;
1303 uint32_t toeplitz_hash_result;
Komal Seelambd7c51d2016-02-24 10:27:30 +05301304 uint32_t mode = hif_get_conparam(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001305
1306 if (Q_TARGET_ACCESS_BEGIN(scn) < 0) {
1307 HIF_ERROR("[premature rc=0]\n");
1308 return 0; /* no work done */
1309 }
1310
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301311 qdf_spin_lock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001312
1313 /* Clear force_break flag and re-initialize receive_count to 0 */
1314
1315 /* NAPI: scn variables- thread/multi-processing safety? */
Houston Hoffman5bf441a2015-09-02 11:52:10 -07001316 CE_state->receive_count = 0;
Houston Hoffman18c7fc52015-09-02 11:44:42 -07001317 CE_state->force_break = 0;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001318more_completions:
1319 if (CE_state->recv_cb) {
1320
1321 /* Pop completed recv buffers and call
1322 * the registered recv callback for each
1323 */
1324 while (ce_completed_recv_next_nolock
1325 (CE_state, &CE_context, &transfer_context,
1326 &buf, &nbytes, &id, &flags) ==
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301327 QDF_STATUS_SUCCESS) {
1328 qdf_spin_unlock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001329 CE_state->recv_cb((struct CE_handle *)CE_state,
1330 CE_context, transfer_context, buf,
1331 nbytes, id, flags);
1332
1333 /*
1334 * EV #112693 -
1335 * [Peregrine][ES1][WB342][Win8x86][Performance]
1336 * BSoD_0x133 occurred in VHT80 UDP_DL
1337 * Break out DPC by force if number of loops in
1338 * hif_pci_ce_recv_data reaches MAX_NUM_OF_RECEIVES
1339 * to avoid spending too long time in
1340 * DPC for each interrupt handling. Schedule another
1341 * DPC to avoid data loss if we had taken
1342 * force-break action before apply to Windows OS
1343 * only currently, Linux/MAC os can expand to their
1344 * platform if necessary
1345 */
1346
1347 /* Break the receive processes by
1348 * force if force_break set up
1349 */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301350 if (qdf_unlikely(CE_state->force_break)) {
1351 qdf_atomic_set(&CE_state->rx_pending, 1);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001352 CE_ENGINE_INT_STATUS_CLEAR(scn, ctrl_addr,
1353 HOST_IS_COPY_COMPLETE_MASK);
1354 if (Q_TARGET_ACCESS_END(scn) < 0)
1355 HIF_ERROR("<--[premature rc=%d]\n",
Houston Hoffman5bf441a2015-09-02 11:52:10 -07001356 CE_state->receive_count);
1357 return CE_state->receive_count;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001358 }
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301359 qdf_spin_lock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001360 }
1361 }
1362
1363 /*
1364 * Attention: We may experience potential infinite loop for below
1365 * While Loop during Sending Stress test.
1366 * Resolve the same way as Receive Case (Refer to EV #112693)
1367 */
1368
1369 if (CE_state->send_cb) {
1370 /* Pop completed send buffers and call
1371 * the registered send callback for each
1372 */
1373
1374#ifdef ATH_11AC_TXCOMPACT
1375 while (ce_completed_send_next_nolock
1376 (CE_state, &CE_context,
1377 &transfer_context, &buf, &nbytes,
1378 &id, &sw_idx, &hw_idx,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301379 &toeplitz_hash_result) == QDF_STATUS_SUCCESS) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001380
1381 if (CE_id != CE_HTT_H2T_MSG ||
Komal Seelambd7c51d2016-02-24 10:27:30 +05301382 WLAN_IS_EPPING_ENABLED(mode)) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301383 qdf_spin_unlock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001384 CE_state->send_cb((struct CE_handle *)CE_state,
1385 CE_context, transfer_context,
1386 buf, nbytes, id, sw_idx,
1387 hw_idx, toeplitz_hash_result);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301388 qdf_spin_lock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001389 } else {
1390 struct HIF_CE_pipe_info *pipe_info =
1391 (struct HIF_CE_pipe_info *)CE_context;
1392
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301393 qdf_spin_lock(&pipe_info->
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001394 completion_freeq_lock);
1395 pipe_info->num_sends_allowed++;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301396 qdf_spin_unlock(&pipe_info->
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001397 completion_freeq_lock);
1398 }
1399 }
1400#else /*ATH_11AC_TXCOMPACT */
1401 while (ce_completed_send_next_nolock
1402 (CE_state, &CE_context,
1403 &transfer_context, &buf, &nbytes,
1404 &id, &sw_idx, &hw_idx,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301405 &toeplitz_hash_result) == QDF_STATUS_SUCCESS) {
1406 qdf_spin_unlock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001407 CE_state->send_cb((struct CE_handle *)CE_state,
1408 CE_context, transfer_context, buf,
1409 nbytes, id, sw_idx, hw_idx,
1410 toeplitz_hash_result);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301411 qdf_spin_lock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001412 }
1413#endif /*ATH_11AC_TXCOMPACT */
1414 }
1415
1416more_watermarks:
1417 if (CE_state->misc_cbs) {
1418 CE_int_status = CE_ENGINE_INT_STATUS_GET(scn, ctrl_addr);
1419 if (CE_int_status & CE_WATERMARK_MASK) {
1420 if (CE_state->watermark_cb) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301421 qdf_spin_unlock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001422 /* Convert HW IS bits to software flags */
1423 flags =
1424 (CE_int_status & CE_WATERMARK_MASK) >>
1425 CE_WM_SHFT;
1426
1427 CE_state->
1428 watermark_cb((struct CE_handle *)CE_state,
1429 CE_state->wm_context, flags);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301430 qdf_spin_lock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001431 }
1432 }
1433 }
1434
1435 /*
1436 * Clear the misc interrupts (watermark) that were handled above,
1437 * and that will be checked again below.
1438 * Clear and check for copy-complete interrupts again, just in case
1439 * more copy completions happened while the misc interrupts were being
1440 * handled.
1441 */
1442 CE_ENGINE_INT_STATUS_CLEAR(scn, ctrl_addr,
1443 CE_WATERMARK_MASK |
1444 HOST_IS_COPY_COMPLETE_MASK);
1445
1446 /*
1447 * Now that per-engine interrupts are cleared, verify that
1448 * no recv interrupts arrive while processing send interrupts,
1449 * and no recv or send interrupts happened while processing
1450 * misc interrupts.Go back and check again.Keep checking until
1451 * we find no more events to process.
1452 */
1453 if (CE_state->recv_cb && ce_recv_entries_done_nolock(scn, CE_state)) {
Komal Seelambd7c51d2016-02-24 10:27:30 +05301454 if (WLAN_IS_EPPING_ENABLED(mode) ||
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001455 more_comp_cnt++ < CE_TXRX_COMP_CHECK_THRESHOLD) {
1456 goto more_completions;
1457 } else {
1458 HIF_ERROR(
1459 "%s:Potential infinite loop detected during Rx processing nentries_mask:0x%x sw read_idx:0x%x hw read_idx:0x%x",
1460 __func__, CE_state->dest_ring->nentries_mask,
1461 CE_state->dest_ring->sw_index,
1462 CE_DEST_RING_READ_IDX_GET(scn,
1463 CE_state->ctrl_addr));
1464 }
1465 }
1466
1467 if (CE_state->send_cb && ce_send_entries_done_nolock(scn, CE_state)) {
Komal Seelambd7c51d2016-02-24 10:27:30 +05301468 if (WLAN_IS_EPPING_ENABLED(mode) ||
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001469 more_snd_comp_cnt++ < CE_TXRX_COMP_CHECK_THRESHOLD) {
1470 goto more_completions;
1471 } else {
1472 HIF_ERROR(
1473 "%s:Potential infinite loop detected during send completion nentries_mask:0x%x sw read_idx:0x%x hw read_idx:0x%x",
1474 __func__, CE_state->src_ring->nentries_mask,
1475 CE_state->src_ring->sw_index,
1476 CE_SRC_RING_READ_IDX_GET(scn,
1477 CE_state->ctrl_addr));
1478 }
1479 }
1480
1481 if (CE_state->misc_cbs) {
1482 CE_int_status = CE_ENGINE_INT_STATUS_GET(scn, ctrl_addr);
1483 if (CE_int_status & CE_WATERMARK_MASK) {
1484 if (CE_state->watermark_cb) {
1485 goto more_watermarks;
1486 }
1487 }
1488 }
1489
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301490 qdf_spin_unlock(&CE_state->ce_index_lock);
1491 qdf_atomic_set(&CE_state->rx_pending, 0);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001492
1493 if (Q_TARGET_ACCESS_END(scn) < 0)
Houston Hoffman5bf441a2015-09-02 11:52:10 -07001494 HIF_ERROR("<--[premature rc=%d]\n", CE_state->receive_count);
1495 return CE_state->receive_count;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001496}
1497
1498/*
1499 * Handler for per-engine interrupts on ALL active CEs.
1500 * This is used in cases where the system is sharing a
1501 * single interrput for all CEs
1502 */
1503
Komal Seelam644263d2016-02-22 20:45:49 +05301504void ce_per_engine_service_any(int irq, struct hif_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001505{
1506 int CE_id;
1507 uint32_t intr_summary;
1508
Houston Hoffmanbac94542016-03-14 21:11:59 -07001509 if (Q_TARGET_ACCESS_BEGIN(scn) < 0)
1510 return;
1511
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301512 if (!qdf_atomic_read(&scn->tasklet_from_intr)) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001513 for (CE_id = 0; CE_id < scn->ce_count; CE_id++) {
1514 struct CE_state *CE_state = scn->ce_id_to_state[CE_id];
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301515 if (qdf_atomic_read(&CE_state->rx_pending)) {
1516 qdf_atomic_set(&CE_state->rx_pending, 0);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001517 ce_per_engine_service(scn, CE_id);
1518 }
1519 }
1520
Houston Hoffmanbac94542016-03-14 21:11:59 -07001521 Q_TARGET_ACCESS_END(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001522 return;
1523 }
1524
1525 intr_summary = CE_INTERRUPT_SUMMARY(scn);
1526
1527 for (CE_id = 0; intr_summary && (CE_id < scn->ce_count); CE_id++) {
1528 if (intr_summary & (1 << CE_id)) {
1529 intr_summary &= ~(1 << CE_id);
1530 } else {
1531 continue; /* no intr pending on this CE */
1532 }
1533
1534 ce_per_engine_service(scn, CE_id);
1535 }
1536
Houston Hoffmanbac94542016-03-14 21:11:59 -07001537 Q_TARGET_ACCESS_END(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001538}
1539
1540/*
1541 * Adjust interrupts for the copy complete handler.
1542 * If it's needed for either send or recv, then unmask
1543 * this interrupt; otherwise, mask it.
1544 *
1545 * Called with target_lock held.
1546 */
1547static void
1548ce_per_engine_handler_adjust(struct CE_state *CE_state,
1549 int disable_copy_compl_intr)
1550{
1551 uint32_t ctrl_addr = CE_state->ctrl_addr;
Komal Seelam644263d2016-02-22 20:45:49 +05301552 struct hif_softc *scn = CE_state->scn;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001553
1554 CE_state->disable_copy_compl_intr = disable_copy_compl_intr;
Houston Hoffmanbac94542016-03-14 21:11:59 -07001555
1556 if (Q_TARGET_ACCESS_BEGIN(scn) < 0)
1557 return;
1558
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001559 if ((!disable_copy_compl_intr) &&
1560 (CE_state->send_cb || CE_state->recv_cb)) {
1561 CE_COPY_COMPLETE_INTR_ENABLE(scn, ctrl_addr);
1562 } else {
1563 CE_COPY_COMPLETE_INTR_DISABLE(scn, ctrl_addr);
1564 }
1565
1566 if (CE_state->watermark_cb) {
1567 CE_WATERMARK_INTR_ENABLE(scn, ctrl_addr);
1568 } else {
1569 CE_WATERMARK_INTR_DISABLE(scn, ctrl_addr);
1570 }
Houston Hoffmanbac94542016-03-14 21:11:59 -07001571 Q_TARGET_ACCESS_END(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001572}
1573
1574/*Iterate the CE_state list and disable the compl interrupt
1575 * if it has been registered already.
1576 */
Komal Seelam644263d2016-02-22 20:45:49 +05301577void ce_disable_any_copy_compl_intr_nolock(struct hif_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001578{
1579 int CE_id;
1580
Houston Hoffmanbac94542016-03-14 21:11:59 -07001581 if (Q_TARGET_ACCESS_BEGIN(scn) < 0)
1582 return;
1583
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001584 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 /* if the interrupt is currently enabled, disable it */
1589 if (!CE_state->disable_copy_compl_intr
1590 && (CE_state->send_cb || CE_state->recv_cb)) {
1591 CE_COPY_COMPLETE_INTR_DISABLE(scn, ctrl_addr);
1592 }
1593
1594 if (CE_state->watermark_cb) {
1595 CE_WATERMARK_INTR_DISABLE(scn, ctrl_addr);
1596 }
1597 }
Houston Hoffmanbac94542016-03-14 21:11:59 -07001598 Q_TARGET_ACCESS_END(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001599}
1600
Komal Seelam644263d2016-02-22 20:45:49 +05301601void ce_enable_any_copy_compl_intr_nolock(struct hif_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001602{
1603 int CE_id;
1604
Houston Hoffmanbac94542016-03-14 21:11:59 -07001605 if (Q_TARGET_ACCESS_BEGIN(scn) < 0)
1606 return;
1607
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001608 for (CE_id = 0; CE_id < scn->ce_count; CE_id++) {
1609 struct CE_state *CE_state = scn->ce_id_to_state[CE_id];
1610 uint32_t ctrl_addr = CE_state->ctrl_addr;
1611
1612 /*
1613 * If the CE is supposed to have copy complete interrupts
1614 * enabled (i.e. there a callback registered, and the
1615 * "disable" flag is not set), then re-enable the interrupt.
1616 */
1617 if (!CE_state->disable_copy_compl_intr
1618 && (CE_state->send_cb || CE_state->recv_cb)) {
1619 CE_COPY_COMPLETE_INTR_ENABLE(scn, ctrl_addr);
1620 }
1621
1622 if (CE_state->watermark_cb) {
1623 CE_WATERMARK_INTR_ENABLE(scn, ctrl_addr);
1624 }
1625 }
Houston Hoffmanbac94542016-03-14 21:11:59 -07001626 Q_TARGET_ACCESS_END(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001627}
1628
Houston Hoffmana837c9a2015-09-03 12:47:01 -07001629/**
1630 * ce_send_cb_register(): register completion handler
1631 * @copyeng: CE_state representing the ce we are adding the behavior to
1632 * @fn_ptr: callback that the ce should use when processing tx completions
1633 * @disable_interrupts: if the interupts should be enabled or not.
1634 *
1635 * Caller should guarantee that no transactions are in progress before
1636 * switching the callback function.
1637 *
1638 * Registers the send context before the fn pointer so that if the cb is valid
1639 * the context should be valid.
1640 *
1641 * Beware that currently this function will enable completion interrupts.
1642 */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001643void
1644ce_send_cb_register(struct CE_handle *copyeng,
1645 ce_send_cb fn_ptr,
1646 void *ce_send_context, int disable_interrupts)
1647{
1648 struct CE_state *CE_state = (struct CE_state *)copyeng;
1649
Sanjay Devnani9ce15772015-11-12 14:08:57 -08001650 if (CE_state == NULL) {
1651 pr_err("%s: Error CE state = NULL\n", __func__);
1652 return;
1653 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001654 CE_state->send_context = ce_send_context;
Houston Hoffmana837c9a2015-09-03 12:47:01 -07001655 CE_state->send_cb = fn_ptr;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001656 ce_per_engine_handler_adjust(CE_state, disable_interrupts);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001657}
1658
Houston Hoffmana837c9a2015-09-03 12:47:01 -07001659/**
1660 * ce_recv_cb_register(): register completion handler
1661 * @copyeng: CE_state representing the ce we are adding the behavior to
1662 * @fn_ptr: callback that the ce should use when processing rx completions
1663 * @disable_interrupts: if the interupts should be enabled or not.
1664 *
1665 * Registers the send context before the fn pointer so that if the cb is valid
1666 * the context should be valid.
1667 *
1668 * Caller should guarantee that no transactions are in progress before
1669 * switching the callback function.
1670 */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001671void
1672ce_recv_cb_register(struct CE_handle *copyeng,
1673 CE_recv_cb fn_ptr,
1674 void *CE_recv_context, int disable_interrupts)
1675{
1676 struct CE_state *CE_state = (struct CE_state *)copyeng;
1677
Sanjay Devnani9ce15772015-11-12 14:08:57 -08001678 if (CE_state == NULL) {
1679 pr_err("%s: ERROR CE state = NULL\n", __func__);
1680 return;
1681 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001682 CE_state->recv_context = CE_recv_context;
Houston Hoffmana837c9a2015-09-03 12:47:01 -07001683 CE_state->recv_cb = fn_ptr;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001684 ce_per_engine_handler_adjust(CE_state, disable_interrupts);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001685}
1686
Houston Hoffmana837c9a2015-09-03 12:47:01 -07001687/**
1688 * ce_watermark_cb_register(): register completion handler
1689 * @copyeng: CE_state representing the ce we are adding the behavior to
1690 * @fn_ptr: callback that the ce should use when processing watermark events
1691 *
1692 * Caller should guarantee that no watermark events are being processed before
1693 * switching the callback function.
1694 */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001695void
1696ce_watermark_cb_register(struct CE_handle *copyeng,
1697 CE_watermark_cb fn_ptr, void *CE_wm_context)
1698{
1699 struct CE_state *CE_state = (struct CE_state *)copyeng;
1700
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001701 CE_state->watermark_cb = fn_ptr;
1702 CE_state->wm_context = CE_wm_context;
1703 ce_per_engine_handler_adjust(CE_state, 0);
1704 if (fn_ptr) {
1705 CE_state->misc_cbs = 1;
1706 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001707}
1708
1709#ifdef WLAN_FEATURE_FASTPATH
1710/**
1711 * ce_pkt_dl_len_set() set the HTT packet download length
1712 * @hif_sc: HIF context
1713 * @pkt_download_len: download length
1714 *
1715 * Return: None
1716 */
1717void ce_pkt_dl_len_set(void *hif_sc, u_int32_t pkt_download_len)
1718{
Komal Seelam644263d2016-02-22 20:45:49 +05301719 struct hif_softc *sc = (struct hif_softc *)(hif_sc);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001720 struct CE_state *ce_state = sc->ce_id_to_state[CE_HTT_H2T_MSG];
1721
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301722 qdf_assert_always(ce_state);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001723
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001724 ce_state->download_len = pkt_download_len;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001725
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301726 qdf_print("%s CE %d Pkt download length %d", __func__,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001727 ce_state->id, ce_state->download_len);
1728}
1729#else
1730void ce_pkt_dl_len_set(void *hif_sc, u_int32_t pkt_download_len)
1731{
1732}
1733#endif /* WLAN_FEATURE_FASTPATH */
1734
Komal Seelam644263d2016-02-22 20:45:49 +05301735bool ce_get_rx_pending(struct hif_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001736{
1737 int CE_id;
1738
1739 for (CE_id = 0; CE_id < scn->ce_count; CE_id++) {
1740 struct CE_state *CE_state = scn->ce_id_to_state[CE_id];
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301741 if (qdf_atomic_read(&CE_state->rx_pending))
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001742 return true;
1743 }
1744
1745 return false;
1746}
1747
1748/**
1749 * ce_check_rx_pending() - ce_check_rx_pending
Komal Seelam644263d2016-02-22 20:45:49 +05301750 * @scn: hif_softc
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001751 * @ce_id: ce_id
1752 *
1753 * Return: bool
1754 */
Komal Seelam644263d2016-02-22 20:45:49 +05301755bool ce_check_rx_pending(struct hif_softc *scn, int ce_id)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001756{
1757 struct CE_state *CE_state = scn->ce_id_to_state[ce_id];
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301758 if (qdf_atomic_read(&CE_state->rx_pending))
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001759 return true;
1760 else
1761 return false;
1762}
Houston Hoffman8ed92e52015-09-02 14:49:48 -07001763
1764/**
1765 * ce_enable_msi(): write the msi configuration to the target
1766 * @scn: hif context
1767 * @CE_id: which copy engine will be configured for msi interupts
1768 * @msi_addr_lo: Hardware will write to this address to generate an interrupt
1769 * @msi_addr_hi: Hardware will write to this address to generate an interrupt
1770 * @msi_data: Hardware will write this data to generate an interrupt
1771 *
1772 * should be done in the initialization sequence so no locking would be needed
1773 */
Komal Seelam644263d2016-02-22 20:45:49 +05301774void ce_enable_msi(struct hif_softc *scn, unsigned int CE_id,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001775 uint32_t msi_addr_lo, uint32_t msi_addr_hi,
1776 uint32_t msi_data)
1777{
1778#ifdef WLAN_ENABLE_QCA6180
1779 struct CE_state *CE_state;
1780 A_target_id_t targid;
1781 u_int32_t ctrl_addr;
1782 uint32_t tmp;
1783
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001784 CE_state = scn->ce_id_to_state[CE_id];
1785 if (!CE_state) {
1786 HIF_ERROR("%s: error - CE_state = NULL", __func__);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001787 return;
1788 }
1789 targid = TARGID(sc);
1790 ctrl_addr = CE_state->ctrl_addr;
1791 CE_MSI_ADDR_LOW_SET(scn, ctrl_addr, msi_addr_lo);
1792 CE_MSI_ADDR_HIGH_SET(scn, ctrl_addr, msi_addr_hi);
1793 CE_MSI_DATA_SET(scn, ctrl_addr, msi_data);
1794 tmp = CE_CTRL_REGISTER1_GET(scn, ctrl_addr);
1795 tmp |= (1 << CE_MSI_ENABLE_BIT);
1796 CE_CTRL_REGISTER1_SET(scn, ctrl_addr, tmp);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001797#endif
1798}
1799
1800#ifdef IPA_OFFLOAD
Leo Changd85f78d2015-11-13 10:55:34 -08001801/**
1802 * ce_ipa_get_resource() - get uc resource on copyengine
1803 * @ce: copyengine context
1804 * @ce_sr_base_paddr: copyengine source ring base physical address
1805 * @ce_sr_ring_size: copyengine source ring size
1806 * @ce_reg_paddr: copyengine register physical address
1807 *
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001808 * Copy engine should release resource to micro controller
1809 * Micro controller needs
Leo Changd85f78d2015-11-13 10:55:34 -08001810 * - Copy engine source descriptor base address
1811 * - Copy engine source descriptor size
1812 * - PCI BAR address to access copy engine regiser
1813 *
1814 * Return: None
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001815 */
1816void ce_ipa_get_resource(struct CE_handle *ce,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301817 qdf_dma_addr_t *ce_sr_base_paddr,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001818 uint32_t *ce_sr_ring_size,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301819 qdf_dma_addr_t *ce_reg_paddr)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001820{
1821 struct CE_state *CE_state = (struct CE_state *)ce;
1822 uint32_t ring_loop;
1823 struct CE_src_desc *ce_desc;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301824 qdf_dma_addr_t phy_mem_base;
Komal Seelam644263d2016-02-22 20:45:49 +05301825 struct hif_softc *scn = CE_state->scn;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001826
1827 if (CE_RUNNING != CE_state->state) {
1828 *ce_sr_base_paddr = 0;
1829 *ce_sr_ring_size = 0;
1830 return;
1831 }
1832
1833 /* Update default value for descriptor */
1834 for (ring_loop = 0; ring_loop < CE_state->src_ring->nentries;
1835 ring_loop++) {
1836 ce_desc = (struct CE_src_desc *)
1837 ((char *)CE_state->src_ring->base_addr_owner_space +
1838 ring_loop * (sizeof(struct CE_src_desc)));
1839 CE_IPA_RING_INIT(ce_desc);
1840 }
1841
1842 /* Get BAR address */
1843 hif_read_phy_mem_base(CE_state->scn, &phy_mem_base);
1844
Leo Changd85f78d2015-11-13 10:55:34 -08001845 *ce_sr_base_paddr = CE_state->src_ring->base_addr_CE_space;
1846 *ce_sr_ring_size = (uint32_t) (CE_state->src_ring->nentries *
1847 sizeof(struct CE_src_desc));
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001848 *ce_reg_paddr = phy_mem_base + CE_BASE_ADDRESS(CE_state->id) +
1849 SR_WR_INDEX_ADDRESS;
1850 return;
1851}
1852#endif /* IPA_OFFLOAD */
1853