blob: b3978b50442128eb2b1be8facd72c25ac9cfb710 [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
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"
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +053038#include "qdf_lock.h"
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080039#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"
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080043
44#ifdef IPA_OFFLOAD
45#ifdef QCA_WIFI_3_0
46#define CE_IPA_RING_INIT(ce_desc) \
47 do { \
48 ce_desc->gather = 0; \
49 ce_desc->enable_11h = 0; \
50 ce_desc->meta_data_low = 0; \
51 ce_desc->packet_result_offset = 64; \
52 ce_desc->toeplitz_hash_enable = 0; \
53 ce_desc->addr_y_search_disable = 0; \
54 ce_desc->addr_x_search_disable = 0; \
55 ce_desc->misc_int_disable = 0; \
56 ce_desc->target_int_disable = 0; \
57 ce_desc->host_int_disable = 0; \
58 ce_desc->dest_byte_swap = 0; \
59 ce_desc->byte_swap = 0; \
60 ce_desc->type = 2; \
61 ce_desc->tx_classify = 1; \
62 ce_desc->buffer_addr_hi = 0; \
63 ce_desc->meta_data = 0; \
64 ce_desc->nbytes = 128; \
65 } while (0)
66#else
67#define CE_IPA_RING_INIT(ce_desc) \
68 do { \
69 ce_desc->byte_swap = 0; \
70 ce_desc->nbytes = 60; \
71 ce_desc->gather = 0; \
72 } while (0)
73#endif /* QCA_WIFI_3_0 */
74#endif /* IPA_OFFLOAD */
75
76static int war1_allow_sleep;
77/* io32 write workaround */
78static int hif_ce_war1;
79
Houston Hoffman68e837e2015-12-04 12:57:24 -080080#ifdef CONFIG_SLUB_DEBUG_ON
81
82/**
83 * struct hif_ce_event - structure for detailing a ce event
84 * @type: what the event was
85 * @time: when it happened
86 * @descriptor: descriptor enqueued or dequeued
87 * @memory: virtual address that was used
88 * @index: location of the descriptor in the ce ring;
89 */
90struct hif_ce_desc_event {
91 uint16_t index;
92 enum hif_ce_event_type type;
93 uint64_t time;
94 union ce_desc descriptor;
95 void *memory;
96};
97
98/* max history to record per copy engine */
99#define HIF_CE_HISTORY_MAX 512
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530100qdf_atomic_t hif_ce_desc_history_index[CE_COUNT_MAX];
Houston Hoffman68e837e2015-12-04 12:57:24 -0800101struct hif_ce_desc_event hif_ce_desc_history[CE_COUNT_MAX][HIF_CE_HISTORY_MAX];
102
Houston Hoffman4275ba22015-12-06 21:02:11 -0800103
Houston Hoffman68e837e2015-12-04 12:57:24 -0800104/**
105 * get_next_record_index() - get the next record index
106 * @table_index: atomic index variable to increment
107 * @array_size: array size of the circular buffer
108 *
109 * Increment the atomic index and reserve the value.
110 * Takes care of buffer wrap.
111 * Guaranteed to be thread safe as long as fewer than array_size contexts
112 * try to access the array. If there are more than array_size contexts
113 * trying to access the array, full locking of the recording process would
114 * be needed to have sane logging.
115 */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530116static int get_next_record_index(qdf_atomic_t *table_index, int array_size)
Houston Hoffman68e837e2015-12-04 12:57:24 -0800117{
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530118 int record_index = qdf_atomic_inc_return(table_index);
Houston Hoffman68e837e2015-12-04 12:57:24 -0800119 if (record_index == array_size)
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530120 qdf_atomic_sub(array_size, table_index);
Houston Hoffman68e837e2015-12-04 12:57:24 -0800121
122 while (record_index >= array_size)
123 record_index -= array_size;
124 return record_index;
125}
126
127/**
128 * hif_record_ce_desc_event() - record ce descriptor events
Komal Seelambd7c51d2016-02-24 10:27:30 +0530129 * @scn: hif_softc
Houston Hoffman68e837e2015-12-04 12:57:24 -0800130 * @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 */
Komal Seelambd7c51d2016-02-24 10:27:30 +0530136void hif_record_ce_desc_event(struct hif_softc *scn, int ce_id,
137 enum hif_ce_event_type type,
138 union ce_desc *descriptor,
139 void *memory, int index)
Houston Hoffman68e837e2015-12-04 12:57:24 -0800140{
Komal Seelambd7c51d2016-02-24 10:27:30 +0530141 struct hif_callbacks *cbk = hif_get_callbacks_handle(scn);
Houston Hoffman68e837e2015-12-04 12:57:24 -0800142 int record_index = get_next_record_index(
143 &hif_ce_desc_history_index[ce_id], HIF_CE_HISTORY_MAX);
144
145 struct hif_ce_desc_event *event =
146 &hif_ce_desc_history[ce_id][record_index];
147 event->type = type;
Komal Seelambd7c51d2016-02-24 10:27:30 +0530148
149 if (cbk && cbk->get_monotonic_boottime)
150 event->time = cbk->get_monotonic_boottime();
151 else
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530152 event->time = ((uint64_t)qdf_system_ticks_to_msecs(
153 qdf_system_ticks()) * 1000);
Komal Seelambd7c51d2016-02-24 10:27:30 +0530154
Houston Hoffman4275ba22015-12-06 21:02:11 -0800155 if (descriptor != NULL)
156 event->descriptor = *descriptor;
157 else
158 memset(&event->descriptor, 0, sizeof(union ce_desc));
Houston Hoffman68e837e2015-12-04 12:57:24 -0800159 event->memory = memory;
160 event->index = index;
161}
162
163/**
164 * ce_init_ce_desc_event_log() - initialize the ce event log
165 * @ce_id: copy engine id for which we are initializing the log
166 * @size: size of array to dedicate
167 *
168 * Currently the passed size is ignored in favor of a precompiled value.
169 */
170void ce_init_ce_desc_event_log(int ce_id, int size)
171{
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530172 qdf_atomic_init(&hif_ce_desc_history_index[ce_id]);
Houston Hoffman68e837e2015-12-04 12:57:24 -0800173}
174#else
Komal Seelambd7c51d2016-02-24 10:27:30 +0530175void hif_record_ce_desc_event(struct hif_softc *scn,
Houston Hoffman68e837e2015-12-04 12:57:24 -0800176 int ce_id, enum hif_ce_event_type type,
177 union ce_desc *descriptor, void *memory,
178 int index)
179{
180}
181
Houston Hoffman5cc292b2015-12-22 11:33:14 -0800182inline void ce_init_ce_desc_event_log(int ce_id, int size)
Houston Hoffman68e837e2015-12-04 12:57:24 -0800183{
184}
185#endif
186
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800187/*
188 * Support for Copy Engine hardware, which is mainly used for
189 * communication between Host and Target over a PCIe interconnect.
190 */
191
192/*
193 * A single CopyEngine (CE) comprises two "rings":
194 * a source ring
195 * a destination ring
196 *
197 * Each ring consists of a number of descriptors which specify
198 * an address, length, and meta-data.
199 *
200 * Typically, one side of the PCIe interconnect (Host or Target)
201 * controls one ring and the other side controls the other ring.
202 * The source side chooses when to initiate a transfer and it
203 * chooses what to send (buffer address, length). The destination
204 * side keeps a supply of "anonymous receive buffers" available and
205 * it handles incoming data as it arrives (when the destination
206 * recieves an interrupt).
207 *
208 * The sender may send a simple buffer (address/length) or it may
209 * send a small list of buffers. When a small list is sent, hardware
210 * "gathers" these and they end up in a single destination buffer
211 * with a single interrupt.
212 *
213 * There are several "contexts" managed by this layer -- more, it
214 * may seem -- than should be needed. These are provided mainly for
215 * maximum flexibility and especially to facilitate a simpler HIF
216 * implementation. There are per-CopyEngine recv, send, and watermark
217 * contexts. These are supplied by the caller when a recv, send,
218 * or watermark handler is established and they are echoed back to
219 * the caller when the respective callbacks are invoked. There is
220 * also a per-transfer context supplied by the caller when a buffer
221 * (or sendlist) is sent and when a buffer is enqueued for recv.
222 * These per-transfer contexts are echoed back to the caller when
223 * the buffer is sent/received.
224 * Target TX harsh result toeplitz_hash_result
225 */
226
227/*
228 * Guts of ce_send, used by both ce_send and ce_sendlist_send.
229 * The caller takes responsibility for any needed locking.
230 */
231int
232ce_completed_send_next_nolock(struct CE_state *CE_state,
233 void **per_CE_contextp,
234 void **per_transfer_contextp,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530235 qdf_dma_addr_t *bufferp,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800236 unsigned int *nbytesp,
237 unsigned int *transfer_idp,
238 unsigned int *sw_idx, unsigned int *hw_idx,
239 uint32_t *toeplitz_hash_result);
240
Komal Seelam644263d2016-02-22 20:45:49 +0530241void war_ce_src_ring_write_idx_set(struct hif_softc *scn,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800242 u32 ctrl_addr, unsigned int write_index)
243{
244 if (hif_ce_war1) {
245 void __iomem *indicator_addr;
246
247 indicator_addr = scn->mem + ctrl_addr + DST_WATERMARK_ADDRESS;
248
249 if (!war1_allow_sleep
250 && ctrl_addr == CE_BASE_ADDRESS(CDC_WAR_DATA_CE)) {
251 hif_write32_mb(indicator_addr,
252 (CDC_WAR_MAGIC_STR | write_index));
253 } else {
254 unsigned long irq_flags;
255 local_irq_save(irq_flags);
256 hif_write32_mb(indicator_addr, 1);
257
258 /*
259 * PCIE write waits for ACK in IPQ8K, there is no
260 * need to read back value.
261 */
262 (void)hif_read32_mb(indicator_addr);
263 (void)hif_read32_mb(indicator_addr); /* conservative */
264
265 CE_SRC_RING_WRITE_IDX_SET(scn,
266 ctrl_addr, write_index);
267
268 hif_write32_mb(indicator_addr, 0);
269 local_irq_restore(irq_flags);
270 }
271 } else
272 CE_SRC_RING_WRITE_IDX_SET(scn, ctrl_addr, write_index);
273}
274
275int
276ce_send_nolock(struct CE_handle *copyeng,
277 void *per_transfer_context,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530278 qdf_dma_addr_t buffer,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800279 uint32_t nbytes,
280 uint32_t transfer_id,
281 uint32_t flags,
282 uint32_t user_flags)
283{
284 int status;
285 struct CE_state *CE_state = (struct CE_state *)copyeng;
286 struct CE_ring_state *src_ring = CE_state->src_ring;
287 uint32_t ctrl_addr = CE_state->ctrl_addr;
288 unsigned int nentries_mask = src_ring->nentries_mask;
289 unsigned int sw_index = src_ring->sw_index;
290 unsigned int write_index = src_ring->write_index;
291 uint64_t dma_addr = buffer;
Komal Seelam644263d2016-02-22 20:45:49 +0530292 struct hif_softc *scn = CE_state->scn;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800293
294 A_TARGET_ACCESS_BEGIN_RET(scn);
295 if (unlikely(CE_RING_DELTA(nentries_mask,
296 write_index, sw_index - 1) <= 0)) {
297 OL_ATH_CE_PKT_ERROR_COUNT_INCR(scn, CE_RING_DELTA_FAIL);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530298 status = QDF_STATUS_E_FAILURE;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800299 A_TARGET_ACCESS_END_RET(scn);
300 return status;
301 }
302 {
Houston Hoffman68e837e2015-12-04 12:57:24 -0800303 enum hif_ce_event_type event_type = HIF_TX_GATHER_DESC_POST;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800304 struct CE_src_desc *src_ring_base =
305 (struct CE_src_desc *)src_ring->base_addr_owner_space;
306 struct CE_src_desc *shadow_base =
307 (struct CE_src_desc *)src_ring->shadow_base;
308 struct CE_src_desc *src_desc =
309 CE_SRC_RING_TO_DESC(src_ring_base, write_index);
310 struct CE_src_desc *shadow_src_desc =
311 CE_SRC_RING_TO_DESC(shadow_base, write_index);
312
313 /* Update low 32 bits source descriptor address */
314 shadow_src_desc->buffer_addr =
315 (uint32_t)(dma_addr & 0xFFFFFFFF);
316#ifdef QCA_WIFI_3_0
317 shadow_src_desc->buffer_addr_hi =
318 (uint32_t)((dma_addr >> 32) & 0x1F);
319 user_flags |= shadow_src_desc->buffer_addr_hi;
320 memcpy(&(((uint32_t *)shadow_src_desc)[1]), &user_flags,
321 sizeof(uint32_t));
322#endif
323 shadow_src_desc->meta_data = transfer_id;
324
325 /*
326 * Set the swap bit if:
327 * typical sends on this CE are swapped (host is big-endian)
328 * and this send doesn't disable the swapping
329 * (data is not bytestream)
330 */
331 shadow_src_desc->byte_swap =
332 (((CE_state->attr_flags & CE_ATTR_BYTE_SWAP_DATA)
333 != 0) & ((flags & CE_SEND_FLAG_SWAP_DISABLE) == 0));
334 shadow_src_desc->gather = ((flags & CE_SEND_FLAG_GATHER) != 0);
335 shadow_src_desc->nbytes = nbytes;
336
337 *src_desc = *shadow_src_desc;
338
339 src_ring->per_transfer_context[write_index] =
340 per_transfer_context;
341
342 /* Update Source Ring Write Index */
343 write_index = CE_RING_IDX_INCR(nentries_mask, write_index);
344
345 /* WORKAROUND */
346 if (!shadow_src_desc->gather) {
Houston Hoffman68e837e2015-12-04 12:57:24 -0800347 event_type = HIF_TX_DESC_POST;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800348 war_ce_src_ring_write_idx_set(scn, ctrl_addr,
349 write_index);
350 }
351
Houston Hoffman68e837e2015-12-04 12:57:24 -0800352 /* src_ring->write index hasn't been updated event though
353 * the register has allready been written to.
354 */
Komal Seelambd7c51d2016-02-24 10:27:30 +0530355 hif_record_ce_desc_event(scn, CE_state->id, event_type,
Houston Hoffman68e837e2015-12-04 12:57:24 -0800356 (union ce_desc *) shadow_src_desc, per_transfer_context,
357 src_ring->write_index);
358
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800359 src_ring->write_index = write_index;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530360 status = QDF_STATUS_SUCCESS;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800361 }
362 A_TARGET_ACCESS_END_RET(scn);
363
364 return status;
365}
366
367int
368ce_send(struct CE_handle *copyeng,
369 void *per_transfer_context,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530370 qdf_dma_addr_t buffer,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800371 uint32_t nbytes,
372 uint32_t transfer_id,
373 uint32_t flags,
374 uint32_t user_flag)
375{
376 struct CE_state *CE_state = (struct CE_state *)copyeng;
377 int status;
378
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530379 qdf_spin_lock_bh(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800380 status = ce_send_nolock(copyeng, per_transfer_context, buffer, nbytes,
381 transfer_id, flags, user_flag);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530382 qdf_spin_unlock_bh(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800383
384 return status;
385}
386
387unsigned int ce_sendlist_sizeof(void)
388{
389 return sizeof(struct ce_sendlist);
390}
391
392void ce_sendlist_init(struct ce_sendlist *sendlist)
393{
394 struct ce_sendlist_s *sl = (struct ce_sendlist_s *)sendlist;
395 sl->num_items = 0;
396}
397
398int
399ce_sendlist_buf_add(struct ce_sendlist *sendlist,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530400 qdf_dma_addr_t buffer,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800401 uint32_t nbytes,
402 uint32_t flags,
403 uint32_t user_flags)
404{
405 struct ce_sendlist_s *sl = (struct ce_sendlist_s *)sendlist;
406 unsigned int num_items = sl->num_items;
407 struct ce_sendlist_item *item;
408
409 if (num_items >= CE_SENDLIST_ITEMS_MAX) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530410 QDF_ASSERT(num_items < CE_SENDLIST_ITEMS_MAX);
411 return QDF_STATUS_E_RESOURCES;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800412 }
413
414 item = &sl->item[num_items];
415 item->send_type = CE_SIMPLE_BUFFER_TYPE;
416 item->data = buffer;
417 item->u.nbytes = nbytes;
418 item->flags = flags;
419 item->user_flags = user_flags;
420 sl->num_items = num_items + 1;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530421 return QDF_STATUS_SUCCESS;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800422}
423
424int
425ce_sendlist_send(struct CE_handle *copyeng,
426 void *per_transfer_context,
427 struct ce_sendlist *sendlist, unsigned int transfer_id)
428{
429 int status = -ENOMEM;
430 struct ce_sendlist_s *sl = (struct ce_sendlist_s *)sendlist;
431 struct CE_state *CE_state = (struct CE_state *)copyeng;
432 struct CE_ring_state *src_ring = CE_state->src_ring;
433 unsigned int nentries_mask = src_ring->nentries_mask;
434 unsigned int num_items = sl->num_items;
435 unsigned int sw_index;
436 unsigned int write_index;
437
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530438 QDF_ASSERT((num_items > 0) && (num_items < src_ring->nentries));
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800439
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530440 qdf_spin_lock_bh(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800441 sw_index = src_ring->sw_index;
442 write_index = src_ring->write_index;
443
444 if (CE_RING_DELTA(nentries_mask, write_index, sw_index - 1) >=
445 num_items) {
446 struct ce_sendlist_item *item;
447 int i;
448
449 /* handle all but the last item uniformly */
450 for (i = 0; i < num_items - 1; i++) {
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, CE_SENDLIST_ITEM_CTXT,
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, transfer_id,
457 item->flags | CE_SEND_FLAG_GATHER,
458 item->user_flags);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530459 QDF_ASSERT(status == QDF_STATUS_SUCCESS);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800460 }
461 /* provide valid context pointer for final item */
462 item = &sl->item[i];
463 /* TBDXXX: Support extensible sendlist_types? */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530464 QDF_ASSERT(item->send_type == CE_SIMPLE_BUFFER_TYPE);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800465 status = ce_send_nolock(copyeng, per_transfer_context,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530466 (qdf_dma_addr_t) item->data,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800467 item->u.nbytes,
468 transfer_id, item->flags,
469 item->user_flags);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530470 QDF_ASSERT(status == QDF_STATUS_SUCCESS);
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +0530471 QDF_NBUF_UPDATE_TX_PKT_COUNT((qdf_nbuf_t)per_transfer_context,
472 QDF_NBUF_TX_PKT_CE);
473 DPTRACE(qdf_dp_trace((qdf_nbuf_t)per_transfer_context,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530474 QDF_DP_TRACE_CE_PACKET_PTR_RECORD,
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +0530475 (uint8_t *)(((qdf_nbuf_t)per_transfer_context)->data),
476 sizeof(((qdf_nbuf_t)per_transfer_context)->data)));
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800477 } else {
478 /*
479 * Probably not worth the additional complexity to support
480 * partial sends with continuation or notification. We expect
481 * to use large rings and small sendlists. If we can't handle
482 * the entire request at once, punt it back to the caller.
483 */
484 }
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530485 qdf_spin_unlock_bh(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800486
487 return status;
488}
489
490#ifdef WLAN_FEATURE_FASTPATH
491#ifdef QCA_WIFI_3_0
492static inline void
493ce_buffer_addr_hi_set(struct CE_src_desc *shadow_src_desc,
494 uint64_t dma_addr,
495 uint32_t user_flags)
496{
497 shadow_src_desc->buffer_addr_hi =
498 (uint32_t)((dma_addr >> 32) & 0x1F);
499 user_flags |= shadow_src_desc->buffer_addr_hi;
500 memcpy(&(((uint32_t *)shadow_src_desc)[1]), &user_flags,
501 sizeof(uint32_t));
502}
503#else
504static inline void
505ce_buffer_addr_hi_set(struct CE_src_desc *shadow_src_desc,
506 uint64_t dma_addr,
507 uint32_t user_flags)
508{
509}
510#endif
511
512/**
513 * ce_send_fast() CE layer Tx buffer posting function
514 * @copyeng: copy engine handle
515 * @msdus: iarray of msdu to be sent
516 * @num_msdus: number of msdus in an array
517 * @transfer_id: transfer_id
518 *
519 * Assumption : Called with an array of MSDU's
520 * Function:
521 * For each msdu in the array
522 * 1. Check no. of available entries
523 * 2. Create src ring entries (allocated in consistent memory
524 * 3. Write index to h/w
525 *
526 * Return: No. of packets that could be sent
527 */
528
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +0530529int ce_send_fast(struct CE_handle *copyeng, qdf_nbuf_t *msdus,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800530 unsigned int num_msdus, unsigned int transfer_id)
531{
532 struct CE_state *ce_state = (struct CE_state *)copyeng;
Komal Seelam644263d2016-02-22 20:45:49 +0530533 struct hif_softc *scn = ce_state->scn;
Komal Seelam5584a7c2016-02-24 19:22:48 +0530534 struct hif_opaque_softc *hif_hdl = GET_HIF_OPAQUE_HDL(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800535 struct CE_ring_state *src_ring = ce_state->src_ring;
536 u_int32_t ctrl_addr = ce_state->ctrl_addr;
537 unsigned int nentries_mask = src_ring->nentries_mask;
538 unsigned int write_index;
539 unsigned int sw_index;
540 unsigned int frag_len;
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +0530541 qdf_nbuf_t msdu;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800542 int i;
543 uint64_t dma_addr;
544 uint32_t user_flags = 0;
545
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530546 qdf_spin_lock_bh(&ce_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800547 sw_index = src_ring->sw_index;
548 write_index = src_ring->write_index;
549
550 /* 2 msdus per packet */
551 for (i = 0; i < num_msdus; i++) {
552 struct CE_src_desc *src_ring_base =
553 (struct CE_src_desc *)src_ring->base_addr_owner_space;
554 struct CE_src_desc *shadow_base =
555 (struct CE_src_desc *)src_ring->shadow_base;
556 struct CE_src_desc *src_desc =
557 CE_SRC_RING_TO_DESC(src_ring_base, write_index);
558 struct CE_src_desc *shadow_src_desc =
559 CE_SRC_RING_TO_DESC(shadow_base, write_index);
560
Komal Seelam644263d2016-02-22 20:45:49 +0530561 hif_pm_runtime_get_noresume(hif_hdl);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800562 msdu = msdus[i];
563
564 /*
565 * First fill out the ring descriptor for the HTC HTT frame
566 * header. These are uncached writes. Should we use a local
567 * structure instead?
568 */
569 /* HTT/HTC header can be passed as a argument */
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +0530570 dma_addr = qdf_nbuf_get_frag_paddr(msdu, 0);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800571 shadow_src_desc->buffer_addr = (uint32_t)(dma_addr &
572 0xFFFFFFFF);
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +0530573 user_flags = qdf_nbuf_data_attr_get(msdu) & DESC_DATA_FLAG_MASK;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800574 ce_buffer_addr_hi_set(shadow_src_desc, dma_addr, user_flags);
575
576 shadow_src_desc->meta_data = transfer_id;
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +0530577 shadow_src_desc->nbytes = qdf_nbuf_get_frag_len(msdu, 0);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800578
579 /*
580 * HTC HTT header is a word stream, so byte swap if CE byte
581 * swap enabled
582 */
583 shadow_src_desc->byte_swap = ((ce_state->attr_flags &
584 CE_ATTR_BYTE_SWAP_DATA) != 0);
585 /* For the first one, it still does not need to write */
586 shadow_src_desc->gather = 1;
587 *src_desc = *shadow_src_desc;
588
589 /* By default we could initialize the transfer context to this
590 * value
591 */
592 src_ring->per_transfer_context[write_index] =
593 CE_SENDLIST_ITEM_CTXT;
594
595 write_index = CE_RING_IDX_INCR(nentries_mask, write_index);
596
597 src_desc = CE_SRC_RING_TO_DESC(src_ring_base, write_index);
598 shadow_src_desc = CE_SRC_RING_TO_DESC(shadow_base, write_index);
599 /*
600 * Now fill out the ring descriptor for the actual data
601 * packet
602 */
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +0530603 dma_addr = qdf_nbuf_get_frag_paddr(msdu, 1);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800604 shadow_src_desc->buffer_addr = (uint32_t)(dma_addr &
605 0xFFFFFFFF);
606 /*
607 * Clear packet offset for all but the first CE desc.
608 */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530609 user_flags &= ~QDF_CE_TX_PKT_OFFSET_BIT_M;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800610 ce_buffer_addr_hi_set(shadow_src_desc, dma_addr, user_flags);
611 shadow_src_desc->meta_data = transfer_id;
612
613 /* get actual packet length */
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +0530614 frag_len = qdf_nbuf_get_frag_len(msdu, 1);
Houston Hoffmana5e74c12015-09-02 18:06:28 -0700615
616 /* only read download_len once */
617 shadow_src_desc->nbytes = ce_state->download_len;
618 if (shadow_src_desc->nbytes > frag_len)
619 shadow_src_desc->nbytes = frag_len;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800620
621 /* Data packet is a byte stream, so disable byte swap */
622 shadow_src_desc->byte_swap = 0;
623 /* For the last one, gather is not set */
624 shadow_src_desc->gather = 0;
625 *src_desc = *shadow_src_desc;
626 src_ring->per_transfer_context[write_index] = msdu;
627 write_index = CE_RING_IDX_INCR(nentries_mask, write_index);
628 }
629
630 /* Write the final index to h/w one-shot */
631 if (i) {
632 src_ring->write_index = write_index;
Houston Hoffmanf4607852015-12-17 17:14:40 -0800633
Komal Seelam644263d2016-02-22 20:45:49 +0530634 if (hif_pm_runtime_get(hif_hdl) == 0) {
Houston Hoffmanf4607852015-12-17 17:14:40 -0800635 /* Don't call WAR_XXX from here
636 * Just call XXX instead, that has the reqd. intel
637 */
638 war_ce_src_ring_write_idx_set(scn, ctrl_addr,
639 write_index);
Komal Seelam644263d2016-02-22 20:45:49 +0530640 hif_pm_runtime_put(hif_hdl);
Houston Hoffmanf4607852015-12-17 17:14:40 -0800641 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800642 }
643
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530644 qdf_spin_unlock_bh(&ce_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800645
646 /*
647 * If all packets in the array are transmitted,
648 * i = num_msdus
649 * Temporarily add an ASSERT
650 */
651 ASSERT(i == num_msdus);
652 return i;
653}
654#endif /* WLAN_FEATURE_FASTPATH */
655
656int
657ce_recv_buf_enqueue(struct CE_handle *copyeng,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530658 void *per_recv_context, qdf_dma_addr_t buffer)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800659{
660 int status;
661 struct CE_state *CE_state = (struct CE_state *)copyeng;
662 struct CE_ring_state *dest_ring = CE_state->dest_ring;
663 uint32_t ctrl_addr = CE_state->ctrl_addr;
664 unsigned int nentries_mask = dest_ring->nentries_mask;
665 unsigned int write_index;
666 unsigned int sw_index;
667 int val = 0;
668 uint64_t dma_addr = buffer;
Komal Seelam644263d2016-02-22 20:45:49 +0530669 struct hif_softc *scn = CE_state->scn;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800670
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530671 qdf_spin_lock_bh(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800672 write_index = dest_ring->write_index;
673 sw_index = dest_ring->sw_index;
674
675 A_TARGET_ACCESS_BEGIN_RET_EXT(scn, val);
676 if (val == -1) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530677 qdf_spin_unlock_bh(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800678 return val;
679 }
680
681 if (CE_RING_DELTA(nentries_mask, write_index, sw_index - 1) > 0) {
682 struct CE_dest_desc *dest_ring_base =
683 (struct CE_dest_desc *)dest_ring->
684 base_addr_owner_space;
685 struct CE_dest_desc *dest_desc =
686 CE_DEST_RING_TO_DESC(dest_ring_base, write_index);
687
688 /* Update low 32 bit destination descriptor */
689 dest_desc->buffer_addr = (uint32_t)(dma_addr & 0xFFFFFFFF);
690#ifdef QCA_WIFI_3_0
691 dest_desc->buffer_addr_hi =
692 (uint32_t)((dma_addr >> 32) & 0x1F);
693#endif
694 dest_desc->nbytes = 0;
695
696 dest_ring->per_transfer_context[write_index] =
697 per_recv_context;
698
Komal Seelambd7c51d2016-02-24 10:27:30 +0530699 hif_record_ce_desc_event(scn, CE_state->id, HIF_RX_DESC_POST,
Houston Hoffman68e837e2015-12-04 12:57:24 -0800700 (union ce_desc *) dest_desc, per_recv_context,
701 write_index);
702
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800703 /* Update Destination Ring Write Index */
704 write_index = CE_RING_IDX_INCR(nentries_mask, write_index);
705 CE_DEST_RING_WRITE_IDX_SET(scn, ctrl_addr, write_index);
706 dest_ring->write_index = write_index;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530707 status = QDF_STATUS_SUCCESS;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800708 } else {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530709 status = QDF_STATUS_E_FAILURE;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800710 }
711 A_TARGET_ACCESS_END_RET_EXT(scn, val);
712 if (val == -1) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530713 qdf_spin_unlock_bh(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800714 return val;
715 }
716
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530717 qdf_spin_unlock_bh(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800718
719 return status;
720}
721
722void
723ce_send_watermarks_set(struct CE_handle *copyeng,
724 unsigned int low_alert_nentries,
725 unsigned int high_alert_nentries)
726{
727 struct CE_state *CE_state = (struct CE_state *)copyeng;
728 uint32_t ctrl_addr = CE_state->ctrl_addr;
Komal Seelam644263d2016-02-22 20:45:49 +0530729 struct hif_softc *scn = CE_state->scn;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800730
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800731 CE_SRC_RING_LOWMARK_SET(scn, ctrl_addr, low_alert_nentries);
732 CE_SRC_RING_HIGHMARK_SET(scn, ctrl_addr, high_alert_nentries);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800733}
734
735void
736ce_recv_watermarks_set(struct CE_handle *copyeng,
737 unsigned int low_alert_nentries,
738 unsigned int high_alert_nentries)
739{
740 struct CE_state *CE_state = (struct CE_state *)copyeng;
741 uint32_t ctrl_addr = CE_state->ctrl_addr;
Komal Seelam644263d2016-02-22 20:45:49 +0530742 struct hif_softc *scn = CE_state->scn;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800743
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800744 CE_DEST_RING_LOWMARK_SET(scn, ctrl_addr,
745 low_alert_nentries);
746 CE_DEST_RING_HIGHMARK_SET(scn, ctrl_addr,
747 high_alert_nentries);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800748}
749
750unsigned int ce_send_entries_avail(struct CE_handle *copyeng)
751{
752 struct CE_state *CE_state = (struct CE_state *)copyeng;
753 struct CE_ring_state *src_ring = CE_state->src_ring;
754 unsigned int nentries_mask = src_ring->nentries_mask;
755 unsigned int sw_index;
756 unsigned int write_index;
757
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530758 qdf_spin_lock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800759 sw_index = src_ring->sw_index;
760 write_index = src_ring->write_index;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530761 qdf_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
766unsigned int ce_recv_entries_avail(struct CE_handle *copyeng)
767{
768 struct CE_state *CE_state = (struct CE_state *)copyeng;
769 struct CE_ring_state *dest_ring = CE_state->dest_ring;
770 unsigned int nentries_mask = dest_ring->nentries_mask;
771 unsigned int sw_index;
772 unsigned int write_index;
773
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530774 qdf_spin_lock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800775 sw_index = dest_ring->sw_index;
776 write_index = dest_ring->write_index;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530777 qdf_spin_unlock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800778
779 return CE_RING_DELTA(nentries_mask, write_index, sw_index - 1);
780}
781
782/*
783 * Guts of ce_send_entries_done.
784 * The caller takes responsibility for any necessary locking.
785 */
786unsigned int
Komal Seelam644263d2016-02-22 20:45:49 +0530787ce_send_entries_done_nolock(struct hif_softc *scn,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800788 struct CE_state *CE_state)
789{
790 struct CE_ring_state *src_ring = CE_state->src_ring;
791 uint32_t ctrl_addr = CE_state->ctrl_addr;
792 unsigned int nentries_mask = src_ring->nentries_mask;
793 unsigned int sw_index;
794 unsigned int read_index;
795
796 sw_index = src_ring->sw_index;
797 read_index = CE_SRC_RING_READ_IDX_GET(scn, ctrl_addr);
798
799 return CE_RING_DELTA(nentries_mask, sw_index, read_index);
800}
801
802unsigned int ce_send_entries_done(struct CE_handle *copyeng)
803{
804 struct CE_state *CE_state = (struct CE_state *)copyeng;
805 unsigned int nentries;
806
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530807 qdf_spin_lock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800808 nentries = ce_send_entries_done_nolock(CE_state->scn, CE_state);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530809 qdf_spin_unlock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800810
811 return nentries;
812}
813
814/*
815 * Guts of ce_recv_entries_done.
816 * The caller takes responsibility for any necessary locking.
817 */
818unsigned int
Komal Seelam644263d2016-02-22 20:45:49 +0530819ce_recv_entries_done_nolock(struct hif_softc *scn,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800820 struct CE_state *CE_state)
821{
822 struct CE_ring_state *dest_ring = CE_state->dest_ring;
823 uint32_t ctrl_addr = CE_state->ctrl_addr;
824 unsigned int nentries_mask = dest_ring->nentries_mask;
825 unsigned int sw_index;
826 unsigned int read_index;
827
828 sw_index = dest_ring->sw_index;
829 read_index = CE_DEST_RING_READ_IDX_GET(scn, ctrl_addr);
830
831 return CE_RING_DELTA(nentries_mask, sw_index, read_index);
832}
833
834unsigned int ce_recv_entries_done(struct CE_handle *copyeng)
835{
836 struct CE_state *CE_state = (struct CE_state *)copyeng;
837 unsigned int nentries;
838
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530839 qdf_spin_lock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800840 nentries = ce_recv_entries_done_nolock(CE_state->scn, CE_state);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530841 qdf_spin_unlock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800842
843 return nentries;
844}
845
846/* Debug support */
847void *ce_debug_cmplrn_context; /* completed recv next context */
848void *ce_debug_cnclsn_context; /* cancel send next context */
849void *ce_debug_rvkrn_context; /* revoke receive next context */
850void *ce_debug_cmplsn_context; /* completed send next context */
851
852/*
853 * Guts of ce_completed_recv_next.
854 * The caller takes responsibility for any necessary locking.
855 */
856int
857ce_completed_recv_next_nolock(struct CE_state *CE_state,
858 void **per_CE_contextp,
859 void **per_transfer_contextp,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530860 qdf_dma_addr_t *bufferp,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800861 unsigned int *nbytesp,
862 unsigned int *transfer_idp,
863 unsigned int *flagsp)
864{
865 int status;
866 struct CE_ring_state *dest_ring = CE_state->dest_ring;
867 unsigned int nentries_mask = dest_ring->nentries_mask;
868 unsigned int sw_index = dest_ring->sw_index;
Komal Seelambd7c51d2016-02-24 10:27:30 +0530869 struct hif_softc *scn = CE_state->scn;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800870 struct CE_dest_desc *dest_ring_base =
871 (struct CE_dest_desc *)dest_ring->base_addr_owner_space;
872 struct CE_dest_desc *dest_desc =
873 CE_DEST_RING_TO_DESC(dest_ring_base, sw_index);
874 int nbytes;
875 struct CE_dest_desc dest_desc_info;
876 /*
877 * By copying the dest_desc_info element to local memory, we could
878 * avoid extra memory read from non-cachable memory.
879 */
880 dest_desc_info = *dest_desc;
881 nbytes = dest_desc_info.nbytes;
882 if (nbytes == 0) {
883 /*
884 * This closes a relatively unusual race where the Host
885 * sees the updated DRRI before the update to the
886 * corresponding descriptor has completed. We treat this
887 * as a descriptor that is not yet done.
888 */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530889 status = QDF_STATUS_E_FAILURE;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800890 goto done;
891 }
892
Komal Seelambd7c51d2016-02-24 10:27:30 +0530893 hif_record_ce_desc_event(scn, CE_state->id, HIF_RX_DESC_COMPLETION,
Houston Hoffman68e837e2015-12-04 12:57:24 -0800894 (union ce_desc *) dest_desc,
895 dest_ring->per_transfer_context[sw_index],
896 sw_index);
897
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800898 dest_desc->nbytes = 0;
899
900 /* Return data from completed destination descriptor */
901 *bufferp = HIF_CE_DESC_ADDR_TO_DMA(&dest_desc_info);
902 *nbytesp = nbytes;
903 *transfer_idp = dest_desc_info.meta_data;
904 *flagsp = (dest_desc_info.byte_swap) ? CE_RECV_FLAG_SWAPPED : 0;
905
906 if (per_CE_contextp) {
907 *per_CE_contextp = CE_state->recv_context;
908 }
909
910 ce_debug_cmplrn_context = dest_ring->per_transfer_context[sw_index];
911 if (per_transfer_contextp) {
912 *per_transfer_contextp = ce_debug_cmplrn_context;
913 }
914 dest_ring->per_transfer_context[sw_index] = 0; /* sanity */
915
916 /* Update sw_index */
917 sw_index = CE_RING_IDX_INCR(nentries_mask, sw_index);
918 dest_ring->sw_index = sw_index;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530919 status = QDF_STATUS_SUCCESS;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800920
921done:
922 return status;
923}
924
925int
926ce_completed_recv_next(struct CE_handle *copyeng,
927 void **per_CE_contextp,
928 void **per_transfer_contextp,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530929 qdf_dma_addr_t *bufferp,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800930 unsigned int *nbytesp,
931 unsigned int *transfer_idp, unsigned int *flagsp)
932{
933 struct CE_state *CE_state = (struct CE_state *)copyeng;
934 int status;
935
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530936 qdf_spin_lock_bh(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800937 status =
938 ce_completed_recv_next_nolock(CE_state, per_CE_contextp,
939 per_transfer_contextp, bufferp,
940 nbytesp, transfer_idp, flagsp);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530941 qdf_spin_unlock_bh(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800942
943 return status;
944}
945
946/* NB: Modeled after ce_completed_recv_next_nolock */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530947QDF_STATUS
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800948ce_revoke_recv_next(struct CE_handle *copyeng,
949 void **per_CE_contextp,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530950 void **per_transfer_contextp, qdf_dma_addr_t *bufferp)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800951{
952 struct CE_state *CE_state;
953 struct CE_ring_state *dest_ring;
954 unsigned int nentries_mask;
955 unsigned int sw_index;
956 unsigned int write_index;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530957 QDF_STATUS status;
Komal Seelam644263d2016-02-22 20:45:49 +0530958 struct hif_softc *scn;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800959
960 CE_state = (struct CE_state *)copyeng;
961 dest_ring = CE_state->dest_ring;
962 if (!dest_ring) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530963 return QDF_STATUS_E_FAILURE;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800964 }
965
966 scn = CE_state->scn;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530967 qdf_spin_lock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800968 nentries_mask = dest_ring->nentries_mask;
969 sw_index = dest_ring->sw_index;
970 write_index = dest_ring->write_index;
971 if (write_index != sw_index) {
972 struct CE_dest_desc *dest_ring_base =
973 (struct CE_dest_desc *)dest_ring->
974 base_addr_owner_space;
975 struct CE_dest_desc *dest_desc =
976 CE_DEST_RING_TO_DESC(dest_ring_base, sw_index);
977
978 /* Return data from completed destination descriptor */
979 *bufferp = HIF_CE_DESC_ADDR_TO_DMA(dest_desc);
980
981 if (per_CE_contextp) {
982 *per_CE_contextp = CE_state->recv_context;
983 }
984
985 ce_debug_rvkrn_context =
986 dest_ring->per_transfer_context[sw_index];
987 if (per_transfer_contextp) {
988 *per_transfer_contextp = ce_debug_rvkrn_context;
989 }
990 dest_ring->per_transfer_context[sw_index] = 0; /* sanity */
991
992 /* Update sw_index */
993 sw_index = CE_RING_IDX_INCR(nentries_mask, sw_index);
994 dest_ring->sw_index = sw_index;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530995 status = QDF_STATUS_SUCCESS;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800996 } else {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530997 status = QDF_STATUS_E_FAILURE;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800998 }
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530999 qdf_spin_unlock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001000
1001 return status;
1002}
1003
1004/*
1005 * Guts of ce_completed_send_next.
1006 * The caller takes responsibility for any necessary locking.
1007 */
1008int
1009ce_completed_send_next_nolock(struct CE_state *CE_state,
1010 void **per_CE_contextp,
1011 void **per_transfer_contextp,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301012 qdf_dma_addr_t *bufferp,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001013 unsigned int *nbytesp,
1014 unsigned int *transfer_idp,
1015 unsigned int *sw_idx,
1016 unsigned int *hw_idx,
1017 uint32_t *toeplitz_hash_result)
1018{
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301019 int status = QDF_STATUS_E_FAILURE;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001020 struct CE_ring_state *src_ring = CE_state->src_ring;
1021 uint32_t ctrl_addr = CE_state->ctrl_addr;
1022 unsigned int nentries_mask = src_ring->nentries_mask;
1023 unsigned int sw_index = src_ring->sw_index;
1024 unsigned int read_index;
Komal Seelam644263d2016-02-22 20:45:49 +05301025 struct hif_softc *scn = CE_state->scn;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001026
1027 if (src_ring->hw_index == sw_index) {
1028 /*
1029 * The SW completion index has caught up with the cached
1030 * version of the HW completion index.
1031 * Update the cached HW completion index to see whether
1032 * the SW has really caught up to the HW, or if the cached
1033 * value of the HW index has become stale.
1034 */
1035 A_TARGET_ACCESS_BEGIN_RET(scn);
1036 src_ring->hw_index =
Houston Hoffman3d0cda82015-12-03 13:25:05 -08001037 CE_SRC_RING_READ_IDX_GET_FROM_DDR(scn, ctrl_addr);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001038 A_TARGET_ACCESS_END_RET(scn);
1039 }
1040 read_index = src_ring->hw_index;
1041
1042 if (sw_idx)
1043 *sw_idx = sw_index;
1044
1045 if (hw_idx)
1046 *hw_idx = read_index;
1047
1048 if ((read_index != sw_index) && (read_index != 0xffffffff)) {
1049 struct CE_src_desc *shadow_base =
1050 (struct CE_src_desc *)src_ring->shadow_base;
1051 struct CE_src_desc *shadow_src_desc =
1052 CE_SRC_RING_TO_DESC(shadow_base, sw_index);
1053#ifdef QCA_WIFI_3_0
1054 struct CE_src_desc *src_ring_base =
1055 (struct CE_src_desc *)src_ring->base_addr_owner_space;
1056 struct CE_src_desc *src_desc =
1057 CE_SRC_RING_TO_DESC(src_ring_base, sw_index);
1058#endif
Komal Seelambd7c51d2016-02-24 10:27:30 +05301059 hif_record_ce_desc_event(scn, CE_state->id,
1060 HIF_TX_DESC_COMPLETION,
Houston Hoffman68e837e2015-12-04 12:57:24 -08001061 (union ce_desc *) shadow_src_desc,
1062 src_ring->per_transfer_context[sw_index],
1063 sw_index);
1064
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001065 /* Return data from completed source descriptor */
1066 *bufferp = HIF_CE_DESC_ADDR_TO_DMA(shadow_src_desc);
1067 *nbytesp = shadow_src_desc->nbytes;
1068 *transfer_idp = shadow_src_desc->meta_data;
1069#ifdef QCA_WIFI_3_0
1070 *toeplitz_hash_result = src_desc->toeplitz_hash_result;
1071#else
1072 *toeplitz_hash_result = 0;
1073#endif
1074 if (per_CE_contextp) {
1075 *per_CE_contextp = CE_state->send_context;
1076 }
1077
1078 ce_debug_cmplsn_context =
1079 src_ring->per_transfer_context[sw_index];
1080 if (per_transfer_contextp) {
1081 *per_transfer_contextp = ce_debug_cmplsn_context;
1082 }
1083 src_ring->per_transfer_context[sw_index] = 0; /* sanity */
1084
1085 /* Update sw_index */
1086 sw_index = CE_RING_IDX_INCR(nentries_mask, sw_index);
1087 src_ring->sw_index = sw_index;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301088 status = QDF_STATUS_SUCCESS;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001089 }
1090
1091 return status;
1092}
1093
1094/* NB: Modeled after ce_completed_send_next */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301095QDF_STATUS
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001096ce_cancel_send_next(struct CE_handle *copyeng,
1097 void **per_CE_contextp,
1098 void **per_transfer_contextp,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301099 qdf_dma_addr_t *bufferp,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001100 unsigned int *nbytesp,
1101 unsigned int *transfer_idp,
1102 uint32_t *toeplitz_hash_result)
1103{
1104 struct CE_state *CE_state;
1105 struct CE_ring_state *src_ring;
1106 unsigned int nentries_mask;
1107 unsigned int sw_index;
1108 unsigned int write_index;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301109 QDF_STATUS status;
Komal Seelam644263d2016-02-22 20:45:49 +05301110 struct hif_softc *scn;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001111
1112 CE_state = (struct CE_state *)copyeng;
1113 src_ring = CE_state->src_ring;
1114 if (!src_ring) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301115 return QDF_STATUS_E_FAILURE;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001116 }
1117
1118 scn = CE_state->scn;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301119 qdf_spin_lock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001120 nentries_mask = src_ring->nentries_mask;
1121 sw_index = src_ring->sw_index;
1122 write_index = src_ring->write_index;
1123
1124 if (write_index != sw_index) {
1125 struct CE_src_desc *src_ring_base =
1126 (struct CE_src_desc *)src_ring->base_addr_owner_space;
1127 struct CE_src_desc *src_desc =
1128 CE_SRC_RING_TO_DESC(src_ring_base, sw_index);
1129
1130 /* Return data from completed source descriptor */
1131 *bufferp = HIF_CE_DESC_ADDR_TO_DMA(src_desc);
1132 *nbytesp = src_desc->nbytes;
1133 *transfer_idp = src_desc->meta_data;
1134#ifdef QCA_WIFI_3_0
1135 *toeplitz_hash_result = src_desc->toeplitz_hash_result;
1136#else
1137 *toeplitz_hash_result = 0;
1138#endif
1139
1140 if (per_CE_contextp) {
1141 *per_CE_contextp = CE_state->send_context;
1142 }
1143
1144 ce_debug_cnclsn_context =
1145 src_ring->per_transfer_context[sw_index];
1146 if (per_transfer_contextp) {
1147 *per_transfer_contextp = ce_debug_cnclsn_context;
1148 }
1149 src_ring->per_transfer_context[sw_index] = 0; /* sanity */
1150
1151 /* Update sw_index */
1152 sw_index = CE_RING_IDX_INCR(nentries_mask, sw_index);
1153 src_ring->sw_index = sw_index;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301154 status = QDF_STATUS_SUCCESS;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001155 } else {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301156 status = QDF_STATUS_E_FAILURE;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001157 }
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301158 qdf_spin_unlock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001159
1160 return status;
1161}
1162
1163/* Shift bits to convert IS_*_RING_*_WATERMARK_MASK to CE_WM_FLAG_*_* */
1164#define CE_WM_SHFT 1
1165
1166int
1167ce_completed_send_next(struct CE_handle *copyeng,
1168 void **per_CE_contextp,
1169 void **per_transfer_contextp,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301170 qdf_dma_addr_t *bufferp,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001171 unsigned int *nbytesp,
1172 unsigned int *transfer_idp,
1173 unsigned int *sw_idx,
1174 unsigned int *hw_idx,
1175 unsigned int *toeplitz_hash_result)
1176{
1177 struct CE_state *CE_state = (struct CE_state *)copyeng;
1178 int status;
1179
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301180 qdf_spin_lock_bh(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001181 status =
1182 ce_completed_send_next_nolock(CE_state, per_CE_contextp,
1183 per_transfer_contextp, bufferp,
1184 nbytesp, transfer_idp, sw_idx,
1185 hw_idx, toeplitz_hash_result);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301186 qdf_spin_unlock_bh(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001187
1188 return status;
1189}
1190
1191#ifdef ATH_11AC_TXCOMPACT
1192/* CE engine descriptor reap
1193 * Similar to ce_per_engine_service , Only difference is ce_per_engine_service
1194 * does recieve and reaping of completed descriptor ,
1195 * This function only handles reaping of Tx complete descriptor.
1196 * The Function is called from threshold reap poll routine
1197 * hif_send_complete_check so should not countain recieve functionality
1198 * within it .
1199 */
1200
Komal Seelam644263d2016-02-22 20:45:49 +05301201void ce_per_engine_servicereap(struct hif_softc *scn, unsigned int ce_id)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001202{
1203 void *CE_context;
1204 void *transfer_context;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301205 qdf_dma_addr_t buf;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001206 unsigned int nbytes;
1207 unsigned int id;
1208 unsigned int sw_idx, hw_idx;
1209 uint32_t toeplitz_hash_result;
Houston Hoffmana575ec22015-12-14 16:35:15 -08001210 struct CE_state *CE_state = scn->ce_id_to_state[ce_id];
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001211
Houston Hoffmanbac94542016-03-14 21:11:59 -07001212 if (Q_TARGET_ACCESS_BEGIN(scn) < 0)
1213 return;
1214
Komal Seelambd7c51d2016-02-24 10:27:30 +05301215 hif_record_ce_desc_event(scn, ce_id, HIF_CE_REAP_ENTRY,
Houston Hoffmana575ec22015-12-14 16:35:15 -08001216 NULL, NULL, 0);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001217
1218 /* Since this function is called from both user context and
1219 * tasklet context the spinlock has to lock the bottom halves.
1220 * This fix assumes that ATH_11AC_TXCOMPACT flag is always
1221 * enabled in TX polling mode. If this is not the case, more
1222 * bottom halve spin lock changes are needed. Due to data path
1223 * performance concern, after internal discussion we've decided
1224 * to make minimum change, i.e., only address the issue occured
1225 * in this function. The possible negative effect of this minimum
1226 * change is that, in the future, if some other function will also
1227 * be opened to let the user context to use, those cases need to be
1228 * addressed by change spin_lock to spin_lock_bh also.
1229 */
1230
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301231 qdf_spin_lock_bh(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001232
1233 if (CE_state->send_cb) {
1234 {
1235 /* Pop completed send buffers and call the
1236 * registered send callback for each
1237 */
1238 while (ce_completed_send_next_nolock
1239 (CE_state, &CE_context,
1240 &transfer_context, &buf,
1241 &nbytes, &id, &sw_idx, &hw_idx,
1242 &toeplitz_hash_result) ==
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301243 QDF_STATUS_SUCCESS) {
Houston Hoffmana575ec22015-12-14 16:35:15 -08001244 if (ce_id != CE_HTT_H2T_MSG) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301245 qdf_spin_unlock_bh(
Houston Hoffman44b7e4a2015-09-03 17:01:22 -07001246 &CE_state->ce_index_lock);
1247 CE_state->send_cb(
1248 (struct CE_handle *)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001249 CE_state, CE_context,
1250 transfer_context, buf,
1251 nbytes, id, sw_idx, hw_idx,
1252 toeplitz_hash_result);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301253 qdf_spin_lock_bh(
Houston Hoffman44b7e4a2015-09-03 17:01:22 -07001254 &CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001255 } else {
1256 struct HIF_CE_pipe_info *pipe_info =
1257 (struct HIF_CE_pipe_info *)
1258 CE_context;
1259
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301260 qdf_spin_lock_bh(&pipe_info->
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001261 completion_freeq_lock);
1262 pipe_info->num_sends_allowed++;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301263 qdf_spin_unlock_bh(&pipe_info->
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001264 completion_freeq_lock);
1265 }
1266 }
1267 }
1268 }
1269
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301270 qdf_spin_unlock_bh(&CE_state->ce_index_lock);
Houston Hoffmana575ec22015-12-14 16:35:15 -08001271
Komal Seelambd7c51d2016-02-24 10:27:30 +05301272 hif_record_ce_desc_event(scn, ce_id, HIF_CE_REAP_EXIT,
Houston Hoffmana575ec22015-12-14 16:35:15 -08001273 NULL, NULL, 0);
Houston Hoffmanbac94542016-03-14 21:11:59 -07001274 Q_TARGET_ACCESS_END(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001275}
1276
1277#endif /*ATH_11AC_TXCOMPACT */
1278
1279/*
1280 * Number of times to check for any pending tx/rx completion on
1281 * a copy engine, this count should be big enough. Once we hit
1282 * this threashold we'll not check for any Tx/Rx comlpetion in same
1283 * interrupt handling. Note that this threashold is only used for
1284 * Rx interrupt processing, this can be used tor Tx as well if we
1285 * suspect any infinite loop in checking for pending Tx completion.
1286 */
1287#define CE_TXRX_COMP_CHECK_THRESHOLD 20
1288
1289/*
1290 * Guts of interrupt handler for per-engine interrupts on a particular CE.
1291 *
1292 * Invokes registered callbacks for recv_complete,
1293 * send_complete, and watermarks.
1294 *
1295 * Returns: number of messages processed
1296 */
1297
Komal Seelam644263d2016-02-22 20:45:49 +05301298int ce_per_engine_service(struct hif_softc *scn, unsigned int CE_id)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001299{
1300 struct CE_state *CE_state = scn->ce_id_to_state[CE_id];
1301 uint32_t ctrl_addr = CE_state->ctrl_addr;
1302 void *CE_context;
1303 void *transfer_context;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301304 qdf_dma_addr_t buf;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001305 unsigned int nbytes;
1306 unsigned int id;
1307 unsigned int flags;
1308 uint32_t CE_int_status;
1309 unsigned int more_comp_cnt = 0;
1310 unsigned int more_snd_comp_cnt = 0;
1311 unsigned int sw_idx, hw_idx;
1312 uint32_t toeplitz_hash_result;
Komal Seelambd7c51d2016-02-24 10:27:30 +05301313 uint32_t mode = hif_get_conparam(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001314
1315 if (Q_TARGET_ACCESS_BEGIN(scn) < 0) {
1316 HIF_ERROR("[premature rc=0]\n");
1317 return 0; /* no work done */
1318 }
1319
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301320 qdf_spin_lock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001321
1322 /* Clear force_break flag and re-initialize receive_count to 0 */
1323
1324 /* NAPI: scn variables- thread/multi-processing safety? */
Houston Hoffman5bf441a2015-09-02 11:52:10 -07001325 CE_state->receive_count = 0;
Houston Hoffman18c7fc52015-09-02 11:44:42 -07001326 CE_state->force_break = 0;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001327more_completions:
1328 if (CE_state->recv_cb) {
1329
1330 /* Pop completed recv buffers and call
1331 * the registered recv callback for each
1332 */
1333 while (ce_completed_recv_next_nolock
1334 (CE_state, &CE_context, &transfer_context,
1335 &buf, &nbytes, &id, &flags) ==
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301336 QDF_STATUS_SUCCESS) {
1337 qdf_spin_unlock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001338 CE_state->recv_cb((struct CE_handle *)CE_state,
1339 CE_context, transfer_context, buf,
1340 nbytes, id, flags);
1341
1342 /*
1343 * EV #112693 -
1344 * [Peregrine][ES1][WB342][Win8x86][Performance]
1345 * BSoD_0x133 occurred in VHT80 UDP_DL
1346 * Break out DPC by force if number of loops in
1347 * hif_pci_ce_recv_data reaches MAX_NUM_OF_RECEIVES
1348 * to avoid spending too long time in
1349 * DPC for each interrupt handling. Schedule another
1350 * DPC to avoid data loss if we had taken
1351 * force-break action before apply to Windows OS
1352 * only currently, Linux/MAC os can expand to their
1353 * platform if necessary
1354 */
1355
1356 /* Break the receive processes by
1357 * force if force_break set up
1358 */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301359 if (qdf_unlikely(CE_state->force_break)) {
1360 qdf_atomic_set(&CE_state->rx_pending, 1);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001361 CE_ENGINE_INT_STATUS_CLEAR(scn, ctrl_addr,
1362 HOST_IS_COPY_COMPLETE_MASK);
1363 if (Q_TARGET_ACCESS_END(scn) < 0)
1364 HIF_ERROR("<--[premature rc=%d]\n",
Houston Hoffman5bf441a2015-09-02 11:52:10 -07001365 CE_state->receive_count);
1366 return CE_state->receive_count;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001367 }
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301368 qdf_spin_lock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001369 }
1370 }
1371
1372 /*
1373 * Attention: We may experience potential infinite loop for below
1374 * While Loop during Sending Stress test.
1375 * Resolve the same way as Receive Case (Refer to EV #112693)
1376 */
1377
1378 if (CE_state->send_cb) {
1379 /* Pop completed send buffers and call
1380 * the registered send callback for each
1381 */
1382
1383#ifdef ATH_11AC_TXCOMPACT
1384 while (ce_completed_send_next_nolock
1385 (CE_state, &CE_context,
1386 &transfer_context, &buf, &nbytes,
1387 &id, &sw_idx, &hw_idx,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301388 &toeplitz_hash_result) == QDF_STATUS_SUCCESS) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001389
1390 if (CE_id != CE_HTT_H2T_MSG ||
Komal Seelambd7c51d2016-02-24 10:27:30 +05301391 WLAN_IS_EPPING_ENABLED(mode)) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301392 qdf_spin_unlock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001393 CE_state->send_cb((struct CE_handle *)CE_state,
1394 CE_context, transfer_context,
1395 buf, nbytes, id, sw_idx,
1396 hw_idx, toeplitz_hash_result);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301397 qdf_spin_lock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001398 } else {
1399 struct HIF_CE_pipe_info *pipe_info =
1400 (struct HIF_CE_pipe_info *)CE_context;
1401
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301402 qdf_spin_lock(&pipe_info->
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001403 completion_freeq_lock);
1404 pipe_info->num_sends_allowed++;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301405 qdf_spin_unlock(&pipe_info->
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001406 completion_freeq_lock);
1407 }
1408 }
1409#else /*ATH_11AC_TXCOMPACT */
1410 while (ce_completed_send_next_nolock
1411 (CE_state, &CE_context,
1412 &transfer_context, &buf, &nbytes,
1413 &id, &sw_idx, &hw_idx,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301414 &toeplitz_hash_result) == QDF_STATUS_SUCCESS) {
1415 qdf_spin_unlock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001416 CE_state->send_cb((struct CE_handle *)CE_state,
1417 CE_context, transfer_context, buf,
1418 nbytes, id, sw_idx, hw_idx,
1419 toeplitz_hash_result);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301420 qdf_spin_lock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001421 }
1422#endif /*ATH_11AC_TXCOMPACT */
1423 }
1424
1425more_watermarks:
1426 if (CE_state->misc_cbs) {
1427 CE_int_status = CE_ENGINE_INT_STATUS_GET(scn, ctrl_addr);
1428 if (CE_int_status & CE_WATERMARK_MASK) {
1429 if (CE_state->watermark_cb) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301430 qdf_spin_unlock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001431 /* Convert HW IS bits to software flags */
1432 flags =
1433 (CE_int_status & CE_WATERMARK_MASK) >>
1434 CE_WM_SHFT;
1435
1436 CE_state->
1437 watermark_cb((struct CE_handle *)CE_state,
1438 CE_state->wm_context, flags);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301439 qdf_spin_lock(&CE_state->ce_index_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001440 }
1441 }
1442 }
1443
1444 /*
1445 * Clear the misc interrupts (watermark) that were handled above,
1446 * and that will be checked again below.
1447 * Clear and check for copy-complete interrupts again, just in case
1448 * more copy completions happened while the misc interrupts were being
1449 * handled.
1450 */
1451 CE_ENGINE_INT_STATUS_CLEAR(scn, ctrl_addr,
1452 CE_WATERMARK_MASK |
1453 HOST_IS_COPY_COMPLETE_MASK);
1454
1455 /*
1456 * Now that per-engine interrupts are cleared, verify that
1457 * no recv interrupts arrive while processing send interrupts,
1458 * and no recv or send interrupts happened while processing
1459 * misc interrupts.Go back and check again.Keep checking until
1460 * we find no more events to process.
1461 */
1462 if (CE_state->recv_cb && ce_recv_entries_done_nolock(scn, CE_state)) {
Komal Seelambd7c51d2016-02-24 10:27:30 +05301463 if (WLAN_IS_EPPING_ENABLED(mode) ||
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001464 more_comp_cnt++ < CE_TXRX_COMP_CHECK_THRESHOLD) {
1465 goto more_completions;
1466 } else {
1467 HIF_ERROR(
1468 "%s:Potential infinite loop detected during Rx processing nentries_mask:0x%x sw read_idx:0x%x hw read_idx:0x%x",
1469 __func__, CE_state->dest_ring->nentries_mask,
1470 CE_state->dest_ring->sw_index,
1471 CE_DEST_RING_READ_IDX_GET(scn,
1472 CE_state->ctrl_addr));
1473 }
1474 }
1475
1476 if (CE_state->send_cb && ce_send_entries_done_nolock(scn, CE_state)) {
Komal Seelambd7c51d2016-02-24 10:27:30 +05301477 if (WLAN_IS_EPPING_ENABLED(mode) ||
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001478 more_snd_comp_cnt++ < CE_TXRX_COMP_CHECK_THRESHOLD) {
1479 goto more_completions;
1480 } else {
1481 HIF_ERROR(
1482 "%s:Potential infinite loop detected during send completion nentries_mask:0x%x sw read_idx:0x%x hw read_idx:0x%x",
1483 __func__, CE_state->src_ring->nentries_mask,
1484 CE_state->src_ring->sw_index,
1485 CE_SRC_RING_READ_IDX_GET(scn,
1486 CE_state->ctrl_addr));
1487 }
1488 }
1489
1490 if (CE_state->misc_cbs) {
1491 CE_int_status = CE_ENGINE_INT_STATUS_GET(scn, ctrl_addr);
1492 if (CE_int_status & CE_WATERMARK_MASK) {
1493 if (CE_state->watermark_cb) {
1494 goto more_watermarks;
1495 }
1496 }
1497 }
1498
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301499 qdf_spin_unlock(&CE_state->ce_index_lock);
1500 qdf_atomic_set(&CE_state->rx_pending, 0);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001501
1502 if (Q_TARGET_ACCESS_END(scn) < 0)
Houston Hoffman5bf441a2015-09-02 11:52:10 -07001503 HIF_ERROR("<--[premature rc=%d]\n", CE_state->receive_count);
1504 return CE_state->receive_count;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001505}
1506
1507/*
1508 * Handler for per-engine interrupts on ALL active CEs.
1509 * This is used in cases where the system is sharing a
1510 * single interrput for all CEs
1511 */
1512
Komal Seelam644263d2016-02-22 20:45:49 +05301513void ce_per_engine_service_any(int irq, struct hif_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001514{
1515 int CE_id;
1516 uint32_t intr_summary;
1517
Houston Hoffmanbac94542016-03-14 21:11:59 -07001518 if (Q_TARGET_ACCESS_BEGIN(scn) < 0)
1519 return;
1520
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301521 if (!qdf_atomic_read(&scn->tasklet_from_intr)) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001522 for (CE_id = 0; CE_id < scn->ce_count; CE_id++) {
1523 struct CE_state *CE_state = scn->ce_id_to_state[CE_id];
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301524 if (qdf_atomic_read(&CE_state->rx_pending)) {
1525 qdf_atomic_set(&CE_state->rx_pending, 0);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001526 ce_per_engine_service(scn, CE_id);
1527 }
1528 }
1529
Houston Hoffmanbac94542016-03-14 21:11:59 -07001530 Q_TARGET_ACCESS_END(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001531 return;
1532 }
1533
1534 intr_summary = CE_INTERRUPT_SUMMARY(scn);
1535
1536 for (CE_id = 0; intr_summary && (CE_id < scn->ce_count); CE_id++) {
1537 if (intr_summary & (1 << CE_id)) {
1538 intr_summary &= ~(1 << CE_id);
1539 } else {
1540 continue; /* no intr pending on this CE */
1541 }
1542
1543 ce_per_engine_service(scn, CE_id);
1544 }
1545
Houston Hoffmanbac94542016-03-14 21:11:59 -07001546 Q_TARGET_ACCESS_END(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001547}
1548
1549/*
1550 * Adjust interrupts for the copy complete handler.
1551 * If it's needed for either send or recv, then unmask
1552 * this interrupt; otherwise, mask it.
1553 *
1554 * Called with target_lock held.
1555 */
1556static void
1557ce_per_engine_handler_adjust(struct CE_state *CE_state,
1558 int disable_copy_compl_intr)
1559{
1560 uint32_t ctrl_addr = CE_state->ctrl_addr;
Komal Seelam644263d2016-02-22 20:45:49 +05301561 struct hif_softc *scn = CE_state->scn;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001562
1563 CE_state->disable_copy_compl_intr = disable_copy_compl_intr;
Houston Hoffmanbac94542016-03-14 21:11:59 -07001564
1565 if (Q_TARGET_ACCESS_BEGIN(scn) < 0)
1566 return;
1567
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001568 if ((!disable_copy_compl_intr) &&
1569 (CE_state->send_cb || CE_state->recv_cb)) {
1570 CE_COPY_COMPLETE_INTR_ENABLE(scn, ctrl_addr);
1571 } else {
1572 CE_COPY_COMPLETE_INTR_DISABLE(scn, ctrl_addr);
1573 }
1574
1575 if (CE_state->watermark_cb) {
1576 CE_WATERMARK_INTR_ENABLE(scn, ctrl_addr);
1577 } else {
1578 CE_WATERMARK_INTR_DISABLE(scn, ctrl_addr);
1579 }
Houston Hoffmanbac94542016-03-14 21:11:59 -07001580 Q_TARGET_ACCESS_END(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001581}
1582
1583/*Iterate the CE_state list and disable the compl interrupt
1584 * if it has been registered already.
1585 */
Komal Seelam644263d2016-02-22 20:45:49 +05301586void ce_disable_any_copy_compl_intr_nolock(struct hif_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001587{
1588 int CE_id;
1589
Houston Hoffmanbac94542016-03-14 21:11:59 -07001590 if (Q_TARGET_ACCESS_BEGIN(scn) < 0)
1591 return;
1592
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001593 for (CE_id = 0; CE_id < scn->ce_count; CE_id++) {
1594 struct CE_state *CE_state = scn->ce_id_to_state[CE_id];
1595 uint32_t ctrl_addr = CE_state->ctrl_addr;
1596
1597 /* if the interrupt is currently enabled, disable it */
1598 if (!CE_state->disable_copy_compl_intr
1599 && (CE_state->send_cb || CE_state->recv_cb)) {
1600 CE_COPY_COMPLETE_INTR_DISABLE(scn, ctrl_addr);
1601 }
1602
1603 if (CE_state->watermark_cb) {
1604 CE_WATERMARK_INTR_DISABLE(scn, ctrl_addr);
1605 }
1606 }
Houston Hoffmanbac94542016-03-14 21:11:59 -07001607 Q_TARGET_ACCESS_END(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001608}
1609
Komal Seelam644263d2016-02-22 20:45:49 +05301610void ce_enable_any_copy_compl_intr_nolock(struct hif_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001611{
1612 int CE_id;
1613
Houston Hoffmanbac94542016-03-14 21:11:59 -07001614 if (Q_TARGET_ACCESS_BEGIN(scn) < 0)
1615 return;
1616
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001617 for (CE_id = 0; CE_id < scn->ce_count; CE_id++) {
1618 struct CE_state *CE_state = scn->ce_id_to_state[CE_id];
1619 uint32_t ctrl_addr = CE_state->ctrl_addr;
1620
1621 /*
1622 * If the CE is supposed to have copy complete interrupts
1623 * enabled (i.e. there a callback registered, and the
1624 * "disable" flag is not set), then re-enable the interrupt.
1625 */
1626 if (!CE_state->disable_copy_compl_intr
1627 && (CE_state->send_cb || CE_state->recv_cb)) {
1628 CE_COPY_COMPLETE_INTR_ENABLE(scn, ctrl_addr);
1629 }
1630
1631 if (CE_state->watermark_cb) {
1632 CE_WATERMARK_INTR_ENABLE(scn, ctrl_addr);
1633 }
1634 }
Houston Hoffmanbac94542016-03-14 21:11:59 -07001635 Q_TARGET_ACCESS_END(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001636}
1637
Houston Hoffmana837c9a2015-09-03 12:47:01 -07001638/**
1639 * ce_send_cb_register(): register completion handler
1640 * @copyeng: CE_state representing the ce we are adding the behavior to
1641 * @fn_ptr: callback that the ce should use when processing tx completions
1642 * @disable_interrupts: if the interupts should be enabled or not.
1643 *
1644 * Caller should guarantee that no transactions are in progress before
1645 * switching the callback function.
1646 *
1647 * Registers the send context before the fn pointer so that if the cb is valid
1648 * the context should be valid.
1649 *
1650 * Beware that currently this function will enable completion interrupts.
1651 */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001652void
1653ce_send_cb_register(struct CE_handle *copyeng,
1654 ce_send_cb fn_ptr,
1655 void *ce_send_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->send_context = ce_send_context;
Houston Hoffmana837c9a2015-09-03 12:47:01 -07001664 CE_state->send_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_recv_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 rx completions
1672 * @disable_interrupts: if the interupts should be enabled or not.
1673 *
1674 * Registers the send context before the fn pointer so that if the cb is valid
1675 * the context should be valid.
1676 *
1677 * Caller should guarantee that no transactions are in progress before
1678 * switching the callback function.
1679 */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001680void
1681ce_recv_cb_register(struct CE_handle *copyeng,
1682 CE_recv_cb fn_ptr,
1683 void *CE_recv_context, int disable_interrupts)
1684{
1685 struct CE_state *CE_state = (struct CE_state *)copyeng;
1686
Sanjay Devnani9ce15772015-11-12 14:08:57 -08001687 if (CE_state == NULL) {
1688 pr_err("%s: ERROR CE state = NULL\n", __func__);
1689 return;
1690 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001691 CE_state->recv_context = CE_recv_context;
Houston Hoffmana837c9a2015-09-03 12:47:01 -07001692 CE_state->recv_cb = fn_ptr;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001693 ce_per_engine_handler_adjust(CE_state, disable_interrupts);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001694}
1695
Houston Hoffmana837c9a2015-09-03 12:47:01 -07001696/**
1697 * ce_watermark_cb_register(): register completion handler
1698 * @copyeng: CE_state representing the ce we are adding the behavior to
1699 * @fn_ptr: callback that the ce should use when processing watermark events
1700 *
1701 * Caller should guarantee that no watermark events are being processed before
1702 * switching the callback function.
1703 */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001704void
1705ce_watermark_cb_register(struct CE_handle *copyeng,
1706 CE_watermark_cb fn_ptr, void *CE_wm_context)
1707{
1708 struct CE_state *CE_state = (struct CE_state *)copyeng;
1709
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001710 CE_state->watermark_cb = fn_ptr;
1711 CE_state->wm_context = CE_wm_context;
1712 ce_per_engine_handler_adjust(CE_state, 0);
1713 if (fn_ptr) {
1714 CE_state->misc_cbs = 1;
1715 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001716}
1717
1718#ifdef WLAN_FEATURE_FASTPATH
1719/**
1720 * ce_pkt_dl_len_set() set the HTT packet download length
1721 * @hif_sc: HIF context
1722 * @pkt_download_len: download length
1723 *
1724 * Return: None
1725 */
1726void ce_pkt_dl_len_set(void *hif_sc, u_int32_t pkt_download_len)
1727{
Komal Seelam644263d2016-02-22 20:45:49 +05301728 struct hif_softc *sc = (struct hif_softc *)(hif_sc);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001729 struct CE_state *ce_state = sc->ce_id_to_state[CE_HTT_H2T_MSG];
1730
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301731 qdf_assert_always(ce_state);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001732
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001733 ce_state->download_len = pkt_download_len;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001734
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301735 qdf_print("%s CE %d Pkt download length %d", __func__,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001736 ce_state->id, ce_state->download_len);
1737}
1738#else
1739void ce_pkt_dl_len_set(void *hif_sc, u_int32_t pkt_download_len)
1740{
1741}
1742#endif /* WLAN_FEATURE_FASTPATH */
1743
Komal Seelam644263d2016-02-22 20:45:49 +05301744bool ce_get_rx_pending(struct hif_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001745{
1746 int CE_id;
1747
1748 for (CE_id = 0; CE_id < scn->ce_count; CE_id++) {
1749 struct CE_state *CE_state = scn->ce_id_to_state[CE_id];
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301750 if (qdf_atomic_read(&CE_state->rx_pending))
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001751 return true;
1752 }
1753
1754 return false;
1755}
1756
1757/**
1758 * ce_check_rx_pending() - ce_check_rx_pending
Komal Seelam644263d2016-02-22 20:45:49 +05301759 * @scn: hif_softc
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001760 * @ce_id: ce_id
1761 *
1762 * Return: bool
1763 */
Komal Seelam644263d2016-02-22 20:45:49 +05301764bool ce_check_rx_pending(struct hif_softc *scn, int ce_id)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001765{
1766 struct CE_state *CE_state = scn->ce_id_to_state[ce_id];
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301767 if (qdf_atomic_read(&CE_state->rx_pending))
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001768 return true;
1769 else
1770 return false;
1771}
Houston Hoffman8ed92e52015-09-02 14:49:48 -07001772
1773/**
1774 * ce_enable_msi(): write the msi configuration to the target
1775 * @scn: hif context
1776 * @CE_id: which copy engine will be configured for msi interupts
1777 * @msi_addr_lo: Hardware will write to this address to generate an interrupt
1778 * @msi_addr_hi: Hardware will write to this address to generate an interrupt
1779 * @msi_data: Hardware will write this data to generate an interrupt
1780 *
1781 * should be done in the initialization sequence so no locking would be needed
1782 */
Komal Seelam644263d2016-02-22 20:45:49 +05301783void ce_enable_msi(struct hif_softc *scn, unsigned int CE_id,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001784 uint32_t msi_addr_lo, uint32_t msi_addr_hi,
1785 uint32_t msi_data)
1786{
1787#ifdef WLAN_ENABLE_QCA6180
1788 struct CE_state *CE_state;
1789 A_target_id_t targid;
1790 u_int32_t ctrl_addr;
1791 uint32_t tmp;
1792
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001793 CE_state = scn->ce_id_to_state[CE_id];
1794 if (!CE_state) {
1795 HIF_ERROR("%s: error - CE_state = NULL", __func__);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001796 return;
1797 }
1798 targid = TARGID(sc);
1799 ctrl_addr = CE_state->ctrl_addr;
1800 CE_MSI_ADDR_LOW_SET(scn, ctrl_addr, msi_addr_lo);
1801 CE_MSI_ADDR_HIGH_SET(scn, ctrl_addr, msi_addr_hi);
1802 CE_MSI_DATA_SET(scn, ctrl_addr, msi_data);
1803 tmp = CE_CTRL_REGISTER1_GET(scn, ctrl_addr);
1804 tmp |= (1 << CE_MSI_ENABLE_BIT);
1805 CE_CTRL_REGISTER1_SET(scn, ctrl_addr, tmp);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001806#endif
1807}
1808
1809#ifdef IPA_OFFLOAD
Leo Changd85f78d2015-11-13 10:55:34 -08001810/**
1811 * ce_ipa_get_resource() - get uc resource on copyengine
1812 * @ce: copyengine context
1813 * @ce_sr_base_paddr: copyengine source ring base physical address
1814 * @ce_sr_ring_size: copyengine source ring size
1815 * @ce_reg_paddr: copyengine register physical address
1816 *
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001817 * Copy engine should release resource to micro controller
1818 * Micro controller needs
Leo Changd85f78d2015-11-13 10:55:34 -08001819 * - Copy engine source descriptor base address
1820 * - Copy engine source descriptor size
1821 * - PCI BAR address to access copy engine regiser
1822 *
1823 * Return: None
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001824 */
1825void ce_ipa_get_resource(struct CE_handle *ce,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301826 qdf_dma_addr_t *ce_sr_base_paddr,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001827 uint32_t *ce_sr_ring_size,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301828 qdf_dma_addr_t *ce_reg_paddr)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001829{
1830 struct CE_state *CE_state = (struct CE_state *)ce;
1831 uint32_t ring_loop;
1832 struct CE_src_desc *ce_desc;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301833 qdf_dma_addr_t phy_mem_base;
Komal Seelam644263d2016-02-22 20:45:49 +05301834 struct hif_softc *scn = CE_state->scn;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001835
1836 if (CE_RUNNING != CE_state->state) {
1837 *ce_sr_base_paddr = 0;
1838 *ce_sr_ring_size = 0;
1839 return;
1840 }
1841
1842 /* Update default value for descriptor */
1843 for (ring_loop = 0; ring_loop < CE_state->src_ring->nentries;
1844 ring_loop++) {
1845 ce_desc = (struct CE_src_desc *)
1846 ((char *)CE_state->src_ring->base_addr_owner_space +
1847 ring_loop * (sizeof(struct CE_src_desc)));
1848 CE_IPA_RING_INIT(ce_desc);
1849 }
1850
1851 /* Get BAR address */
1852 hif_read_phy_mem_base(CE_state->scn, &phy_mem_base);
1853
Leo Changd85f78d2015-11-13 10:55:34 -08001854 *ce_sr_base_paddr = CE_state->src_ring->base_addr_CE_space;
1855 *ce_sr_ring_size = (uint32_t) (CE_state->src_ring->nentries *
1856 sizeof(struct CE_src_desc));
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001857 *ce_reg_paddr = phy_mem_base + CE_BASE_ADDRESS(CE_state->id) +
1858 SR_WR_INDEX_ADDRESS;
1859 return;
1860}
1861#endif /* IPA_OFFLOAD */
1862