blob: e5124da8702e30c28a9568c4c909875277e9973a [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
Manikandan Mohanafd6e882017-04-07 17:46:41 -07002 * Copyright (c) 2015-2017 The Linux Foundation. All rights reserved.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -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 Dhavali7090c5f2015-11-02 17:55:19 -080028#include "targcfg.h"
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +053029#include "qdf_lock.h"
30#include "qdf_status.h"
31#include "qdf_status.h"
32#include <qdf_atomic.h> /* qdf_atomic_read */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080033#include <targaddrs.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080034#include "hif_io32.h"
35#include <hif.h>
36#include "regtable.h"
37#define ATH_MODULE_NAME hif
38#include <a_debug.h>
39#include "hif_main.h"
40#include "ce_api.h"
Jeff Johnson6950fdb2016-10-07 13:00:59 -070041#include "ce_bmi.h"
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +053042#include "qdf_trace.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080043#include "hif_debug.h"
44
45/* Track a BMI transaction that is in progress */
46#ifndef BIT
47#define BIT(n) (1 << (n))
48#endif
49
50enum {
51 BMI_REQ_SEND_DONE = BIT(0), /* the bmi tx completion */
52 BMI_RESP_RECV_DONE = BIT(1), /* the bmi respond is received */
53};
54
55struct BMI_transaction {
56 struct HIF_CE_state *hif_state;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +053057 qdf_semaphore_t bmi_transaction_sem;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080058 uint8_t *bmi_request_host; /* Req BMI msg in Host addr space */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +053059 qdf_dma_addr_t bmi_request_CE; /* Req BMI msg in CE addr space */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080060 uint32_t bmi_request_length; /* Length of BMI request */
61 uint8_t *bmi_response_host; /* Rsp BMI msg in Host addr space */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +053062 qdf_dma_addr_t bmi_response_CE; /* Rsp BMI msg in CE addr space */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080063 unsigned int bmi_response_length; /* Length of received response */
64 unsigned int bmi_timeout_ms;
65 uint32_t bmi_transaction_flags; /* flags for the transcation */
66};
67
68/*
69 * send/recv completion functions for BMI.
70 * NB: The "net_buf" parameter is actually just a
71 * straight buffer, not an sk_buff.
72 */
73void hif_bmi_send_done(struct CE_handle *copyeng, void *ce_context,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +053074 void *transfer_context, qdf_dma_addr_t data,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080075 unsigned int nbytes,
76 unsigned int transfer_id, unsigned int sw_index,
77 unsigned int hw_index, uint32_t toeplitz_hash_result)
78{
79 struct BMI_transaction *transaction =
80 (struct BMI_transaction *)transfer_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080081
82#ifdef BMI_RSP_POLLING
83 /*
84 * Fix EV118783, Release a semaphore after sending
85 * no matter whether a response is been expecting now.
86 */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +053087 qdf_semaphore_release(&transaction->bmi_transaction_sem);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080088#else
89 /*
90 * If a response is anticipated, we'll complete the
91 * transaction if the response has been received.
92 * If no response is anticipated, complete the
93 * transaction now.
94 */
95 transaction->bmi_transaction_flags |= BMI_REQ_SEND_DONE;
96
97 /* resp is't needed or has already been received,
Manikandan Mohanafd6e882017-04-07 17:46:41 -070098 * never assume resp comes later then this
99 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800100 if (!transaction->bmi_response_CE ||
101 (transaction->bmi_transaction_flags & BMI_RESP_RECV_DONE)) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530102 qdf_semaphore_release(&transaction->bmi_transaction_sem);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800103 }
104#endif
105}
106
107#ifndef BMI_RSP_POLLING
108void hif_bmi_recv_data(struct CE_handle *copyeng, void *ce_context,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530109 void *transfer_context, qdf_dma_addr_t data,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800110 unsigned int nbytes,
111 unsigned int transfer_id, unsigned int flags)
112{
113 struct BMI_transaction *transaction =
114 (struct BMI_transaction *)transfer_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800115
116 transaction->bmi_response_length = nbytes;
117 transaction->bmi_transaction_flags |= BMI_RESP_RECV_DONE;
118
119 /* when both send/recv are done, the sem can be released */
Manikandan Mohanafd6e882017-04-07 17:46:41 -0700120 if (transaction->bmi_transaction_flags & BMI_REQ_SEND_DONE)
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530121 qdf_semaphore_release(&transaction->bmi_transaction_sem);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800122}
123#endif
124
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530125QDF_STATUS hif_exchange_bmi_msg(struct hif_opaque_softc *hif_ctx,
126 qdf_dma_addr_t bmi_cmd_da,
127 qdf_dma_addr_t bmi_rsp_da,
Komal Seelam2a5fa632016-02-15 10:33:44 +0530128 uint8_t *bmi_request,
129 uint32_t request_length,
130 uint8_t *bmi_response,
131 uint32_t *bmi_response_lengthp,
132 uint32_t TimeoutMS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800133{
Komal Seelam644263d2016-02-22 20:45:49 +0530134 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Komal Seelam02cf2f82016-02-22 20:44:25 +0530135 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800136 struct HIF_CE_pipe_info *send_pipe_info =
137 &(hif_state->pipe_info[BMI_CE_NUM_TO_TARG]);
138 struct CE_handle *ce_send_hdl = send_pipe_info->ce_hdl;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530139 qdf_dma_addr_t CE_request, CE_response = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800140 struct BMI_transaction *transaction = NULL;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530141 int status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800142 struct HIF_CE_pipe_info *recv_pipe_info =
143 &(hif_state->pipe_info[BMI_CE_NUM_TO_HOST]);
144 struct CE_handle *ce_recv = recv_pipe_info->ce_hdl;
145 unsigned int mux_id = 0;
146 unsigned int transaction_id = 0xffff;
147 unsigned int user_flags = 0;
148#ifdef BMI_RSP_POLLING
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530149 qdf_dma_addr_t buf;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800150 unsigned int completed_nbytes, id, flags;
151 int i;
152#endif
153
154 transaction =
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530155 (struct BMI_transaction *)qdf_mem_malloc(sizeof(*transaction));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800156 if (unlikely(!transaction)) {
157 HIF_ERROR("%s: no memory", __func__);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530158 return QDF_STATUS_E_NOMEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800159 }
160 transaction_id = (mux_id & MUX_ID_MASK) |
161 (transaction_id & TRANSACTION_ID_MASK);
162#ifdef QCA_WIFI_3_0
163 user_flags &= DESC_DATA_FLAG_MASK;
164#endif
165 A_TARGET_ACCESS_LIKELY(scn);
166
167 /* Initialize bmi_transaction_sem to block */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530168 qdf_semaphore_init(&transaction->bmi_transaction_sem);
169 qdf_semaphore_acquire(&transaction->bmi_transaction_sem);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800170
171 transaction->hif_state = hif_state;
172 transaction->bmi_request_host = bmi_request;
173 transaction->bmi_request_length = request_length;
174 transaction->bmi_response_length = 0;
175 transaction->bmi_timeout_ms = TimeoutMS;
176 transaction->bmi_transaction_flags = 0;
177
178 /*
179 * CE_request = dma_map_single(dev,
180 * (void *)bmi_request, request_length, DMA_TO_DEVICE);
181 */
Komal Seelam2a5fa632016-02-15 10:33:44 +0530182 CE_request = bmi_cmd_da;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800183 transaction->bmi_request_CE = CE_request;
184
185 if (bmi_response) {
186
187 /*
188 * CE_response = dma_map_single(dev, bmi_response,
189 * BMI_DATASZ_MAX, DMA_FROM_DEVICE);
190 */
Komal Seelam2a5fa632016-02-15 10:33:44 +0530191 CE_response = bmi_rsp_da;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800192 transaction->bmi_response_host = bmi_response;
193 transaction->bmi_response_CE = CE_response;
194 /* dma_cache_sync(dev, bmi_response,
Manikandan Mohanafd6e882017-04-07 17:46:41 -0700195 * BMI_DATASZ_MAX, DMA_FROM_DEVICE);
196 */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530197 qdf_mem_dma_sync_single_for_device(scn->qdf_dev,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800198 CE_response,
199 BMI_DATASZ_MAX,
200 DMA_FROM_DEVICE);
201 ce_recv_buf_enqueue(ce_recv, transaction,
202 transaction->bmi_response_CE);
203 /* NB: see HIF_BMI_recv_done */
204 } else {
205 transaction->bmi_response_host = NULL;
206 transaction->bmi_response_CE = 0;
207 }
208
209 /* dma_cache_sync(dev, bmi_request, request_length, DMA_TO_DEVICE); */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530210 qdf_mem_dma_sync_single_for_device(scn->qdf_dev, CE_request,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800211 request_length, DMA_TO_DEVICE);
212
213 status =
214 ce_send(ce_send_hdl, transaction,
215 CE_request, request_length,
216 transaction_id, 0, user_flags);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530217 ASSERT(status == QDF_STATUS_SUCCESS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800218 /* NB: see hif_bmi_send_done */
219
220 /* TBDXXX: handle timeout */
221
222 /* Wait for BMI request/response transaction to complete */
223 /* Always just wait for BMI request here if
Manikandan Mohanafd6e882017-04-07 17:46:41 -0700224 * BMI_RSP_POLLING is defined
225 */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530226 while (qdf_semaphore_acquire
227 (&transaction->bmi_transaction_sem)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800228 /*need some break out condition(time out?) */
229 }
230
231 if (bmi_response) {
232#ifdef BMI_RSP_POLLING
233 /* Fix EV118783, do not wait a semaphore for the BMI response
234 * since the relative interruption may be lost.
235 * poll the BMI response instead.
236 */
237 i = 0;
238 while (ce_completed_recv_next(
239 ce_recv, NULL, NULL, &buf,
240 &completed_nbytes, &id,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530241 &flags) != QDF_STATUS_SUCCESS) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800242 if (i++ > BMI_RSP_TO_MILLISEC) {
Houston Hoffmanc50572b2016-06-08 19:49:46 -0700243 HIF_ERROR("%s:error, can't get bmi response",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800244 __func__);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530245 status = QDF_STATUS_E_BUSY;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800246 break;
247 }
248 OS_DELAY(1000);
249 }
250
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530251 if ((status == QDF_STATUS_SUCCESS) && bmi_response_lengthp)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800252 *bmi_response_lengthp = completed_nbytes;
253#else
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530254 if ((status == QDF_STATUS_SUCCESS) && bmi_response_lengthp) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800255 *bmi_response_lengthp =
256 transaction->bmi_response_length;
257 }
258#endif
259
260 }
261
262 /* dma_unmap_single(dev, transaction->bmi_request_CE,
Manikandan Mohanafd6e882017-04-07 17:46:41 -0700263 * request_length, DMA_TO_DEVICE);
264 * bus_unmap_single(scn->sc_osdev,
265 * transaction->bmi_request_CE,
266 * request_length, BUS_DMA_TODEVICE);
267 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800268
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530269 if (status != QDF_STATUS_SUCCESS) {
270 qdf_dma_addr_t unused_buffer;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800271 unsigned int unused_nbytes;
272 unsigned int unused_id;
273 unsigned int toeplitz_hash_result;
274
275 ce_cancel_send_next(ce_send_hdl,
276 NULL, NULL, &unused_buffer,
277 &unused_nbytes, &unused_id,
278 &toeplitz_hash_result);
279 }
280
281 A_TARGET_ACCESS_UNLIKELY(scn);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530282 qdf_mem_free(transaction);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800283 return status;
284}