blob: 8f773da31909d8922f8d64760372a689f0c3675c [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
Komal Seelamb3a3bdf2016-02-01 19:22:17 +05302 * Copyright (c) 2015-2016 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"
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +053041#include "qdf_trace.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080042#ifdef CONFIG_CNSS
43#include <net/cnss.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080044#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080045#include "hif_debug.h"
46
47/* Track a BMI transaction that is in progress */
48#ifndef BIT
49#define BIT(n) (1 << (n))
50#endif
51
52enum {
53 BMI_REQ_SEND_DONE = BIT(0), /* the bmi tx completion */
54 BMI_RESP_RECV_DONE = BIT(1), /* the bmi respond is received */
55};
56
57struct BMI_transaction {
58 struct HIF_CE_state *hif_state;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +053059 qdf_semaphore_t bmi_transaction_sem;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080060 uint8_t *bmi_request_host; /* Req BMI msg in Host addr space */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +053061 qdf_dma_addr_t bmi_request_CE; /* Req BMI msg in CE addr space */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080062 uint32_t bmi_request_length; /* Length of BMI request */
63 uint8_t *bmi_response_host; /* Rsp BMI msg in Host addr space */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +053064 qdf_dma_addr_t bmi_response_CE; /* Rsp BMI msg in CE addr space */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080065 unsigned int bmi_response_length; /* Length of received response */
66 unsigned int bmi_timeout_ms;
67 uint32_t bmi_transaction_flags; /* flags for the transcation */
68};
69
70/*
71 * send/recv completion functions for BMI.
72 * NB: The "net_buf" parameter is actually just a
73 * straight buffer, not an sk_buff.
74 */
75void hif_bmi_send_done(struct CE_handle *copyeng, void *ce_context,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +053076 void *transfer_context, qdf_dma_addr_t data,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080077 unsigned int nbytes,
78 unsigned int transfer_id, unsigned int sw_index,
79 unsigned int hw_index, uint32_t toeplitz_hash_result)
80{
81 struct BMI_transaction *transaction =
82 (struct BMI_transaction *)transfer_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080083
84#ifdef BMI_RSP_POLLING
85 /*
86 * Fix EV118783, Release a semaphore after sending
87 * no matter whether a response is been expecting now.
88 */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +053089 qdf_semaphore_release(&transaction->bmi_transaction_sem);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080090#else
91 /*
92 * If a response is anticipated, we'll complete the
93 * transaction if the response has been received.
94 * If no response is anticipated, complete the
95 * transaction now.
96 */
97 transaction->bmi_transaction_flags |= BMI_REQ_SEND_DONE;
98
99 /* resp is't needed or has already been received,
100 * never assume resp comes later then this */
101 if (!transaction->bmi_response_CE ||
102 (transaction->bmi_transaction_flags & BMI_RESP_RECV_DONE)) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530103 qdf_semaphore_release(&transaction->bmi_transaction_sem);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800104 }
105#endif
106}
107
108#ifndef BMI_RSP_POLLING
109void hif_bmi_recv_data(struct CE_handle *copyeng, void *ce_context,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530110 void *transfer_context, qdf_dma_addr_t data,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800111 unsigned int nbytes,
112 unsigned int transfer_id, unsigned int flags)
113{
114 struct BMI_transaction *transaction =
115 (struct BMI_transaction *)transfer_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800116
117 transaction->bmi_response_length = nbytes;
118 transaction->bmi_transaction_flags |= BMI_RESP_RECV_DONE;
119
120 /* when both send/recv are done, the sem can be released */
121 if (transaction->bmi_transaction_flags & BMI_REQ_SEND_DONE) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530122 qdf_semaphore_release(&transaction->bmi_transaction_sem);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800123 }
124}
125#endif
126
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530127QDF_STATUS hif_exchange_bmi_msg(struct hif_opaque_softc *hif_ctx,
128 qdf_dma_addr_t bmi_cmd_da,
129 qdf_dma_addr_t bmi_rsp_da,
Komal Seelam2a5fa632016-02-15 10:33:44 +0530130 uint8_t *bmi_request,
131 uint32_t request_length,
132 uint8_t *bmi_response,
133 uint32_t *bmi_response_lengthp,
134 uint32_t TimeoutMS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800135{
Komal Seelam644263d2016-02-22 20:45:49 +0530136 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Komal Seelam02cf2f82016-02-22 20:44:25 +0530137 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800138 struct HIF_CE_pipe_info *send_pipe_info =
139 &(hif_state->pipe_info[BMI_CE_NUM_TO_TARG]);
140 struct CE_handle *ce_send_hdl = send_pipe_info->ce_hdl;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530141 qdf_dma_addr_t CE_request, CE_response = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800142 struct BMI_transaction *transaction = NULL;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530143 int status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800144 struct HIF_CE_pipe_info *recv_pipe_info =
145 &(hif_state->pipe_info[BMI_CE_NUM_TO_HOST]);
146 struct CE_handle *ce_recv = recv_pipe_info->ce_hdl;
147 unsigned int mux_id = 0;
148 unsigned int transaction_id = 0xffff;
149 unsigned int user_flags = 0;
150#ifdef BMI_RSP_POLLING
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530151 qdf_dma_addr_t buf;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800152 unsigned int completed_nbytes, id, flags;
153 int i;
154#endif
155
156 transaction =
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530157 (struct BMI_transaction *)qdf_mem_malloc(sizeof(*transaction));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800158 if (unlikely(!transaction)) {
159 HIF_ERROR("%s: no memory", __func__);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530160 return QDF_STATUS_E_NOMEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800161 }
162 transaction_id = (mux_id & MUX_ID_MASK) |
163 (transaction_id & TRANSACTION_ID_MASK);
164#ifdef QCA_WIFI_3_0
165 user_flags &= DESC_DATA_FLAG_MASK;
166#endif
167 A_TARGET_ACCESS_LIKELY(scn);
168
169 /* Initialize bmi_transaction_sem to block */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530170 qdf_semaphore_init(&transaction->bmi_transaction_sem);
171 qdf_semaphore_acquire(&transaction->bmi_transaction_sem);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800172
173 transaction->hif_state = hif_state;
174 transaction->bmi_request_host = bmi_request;
175 transaction->bmi_request_length = request_length;
176 transaction->bmi_response_length = 0;
177 transaction->bmi_timeout_ms = TimeoutMS;
178 transaction->bmi_transaction_flags = 0;
179
180 /*
181 * CE_request = dma_map_single(dev,
182 * (void *)bmi_request, request_length, DMA_TO_DEVICE);
183 */
Komal Seelam2a5fa632016-02-15 10:33:44 +0530184 CE_request = bmi_cmd_da;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800185 transaction->bmi_request_CE = CE_request;
186
187 if (bmi_response) {
188
189 /*
190 * CE_response = dma_map_single(dev, bmi_response,
191 * BMI_DATASZ_MAX, DMA_FROM_DEVICE);
192 */
Komal Seelam2a5fa632016-02-15 10:33:44 +0530193 CE_response = bmi_rsp_da;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800194 transaction->bmi_response_host = bmi_response;
195 transaction->bmi_response_CE = CE_response;
196 /* dma_cache_sync(dev, bmi_response,
197 BMI_DATASZ_MAX, DMA_FROM_DEVICE); */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530198 qdf_mem_dma_sync_single_for_device(scn->qdf_dev,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800199 CE_response,
200 BMI_DATASZ_MAX,
201 DMA_FROM_DEVICE);
202 ce_recv_buf_enqueue(ce_recv, transaction,
203 transaction->bmi_response_CE);
204 /* NB: see HIF_BMI_recv_done */
205 } else {
206 transaction->bmi_response_host = NULL;
207 transaction->bmi_response_CE = 0;
208 }
209
210 /* dma_cache_sync(dev, bmi_request, request_length, DMA_TO_DEVICE); */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530211 qdf_mem_dma_sync_single_for_device(scn->qdf_dev, CE_request,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800212 request_length, DMA_TO_DEVICE);
213
214 status =
215 ce_send(ce_send_hdl, transaction,
216 CE_request, request_length,
217 transaction_id, 0, user_flags);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530218 ASSERT(status == QDF_STATUS_SUCCESS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800219 /* NB: see hif_bmi_send_done */
220
221 /* TBDXXX: handle timeout */
222
223 /* Wait for BMI request/response transaction to complete */
224 /* Always just wait for BMI request here if
225 * BMI_RSP_POLLING is defined */
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,
263 request_length, DMA_TO_DEVICE); */
264 /* bus_unmap_single(scn->sc_osdev,
265 transaction->bmi_request_CE,
266 request_length, BUS_DMA_TODEVICE); */
267
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530268 if (status != QDF_STATUS_SUCCESS) {
269 qdf_dma_addr_t unused_buffer;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800270 unsigned int unused_nbytes;
271 unsigned int unused_id;
272 unsigned int toeplitz_hash_result;
273
274 ce_cancel_send_next(ce_send_hdl,
275 NULL, NULL, &unused_buffer,
276 &unused_nbytes, &unused_id,
277 &toeplitz_hash_result);
278 }
279
280 A_TARGET_ACCESS_UNLIKELY(scn);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530281 qdf_mem_free(transaction);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800282 return status;
283}