blob: 88515e4fd908d2387a096cd500c04f711bddf7f0 [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>
34#include <bmi_msg.h>
35#include "hif_io32.h"
36#include <hif.h>
37#include "regtable.h"
38#define ATH_MODULE_NAME hif
39#include <a_debug.h>
40#include "hif_main.h"
41#include "ce_api.h"
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +053042#include "qdf_trace.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080043#ifdef CONFIG_CNSS
44#include <net/cnss.h>
45#else
46#include "cnss_stub.h"
47#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080048#include "epping_main.h"
49#include "hif_debug.h"
50
51/* Track a BMI transaction that is in progress */
52#ifndef BIT
53#define BIT(n) (1 << (n))
54#endif
55
56enum {
57 BMI_REQ_SEND_DONE = BIT(0), /* the bmi tx completion */
58 BMI_RESP_RECV_DONE = BIT(1), /* the bmi respond is received */
59};
60
61struct BMI_transaction {
62 struct HIF_CE_state *hif_state;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +053063 qdf_semaphore_t bmi_transaction_sem;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080064 uint8_t *bmi_request_host; /* Req BMI msg in Host addr space */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +053065 qdf_dma_addr_t bmi_request_CE; /* Req BMI msg in CE addr space */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080066 uint32_t bmi_request_length; /* Length of BMI request */
67 uint8_t *bmi_response_host; /* Rsp BMI msg in Host addr space */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +053068 qdf_dma_addr_t bmi_response_CE; /* Rsp BMI msg in CE addr space */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080069 unsigned int bmi_response_length; /* Length of received response */
70 unsigned int bmi_timeout_ms;
71 uint32_t bmi_transaction_flags; /* flags for the transcation */
72};
73
74/*
75 * send/recv completion functions for BMI.
76 * NB: The "net_buf" parameter is actually just a
77 * straight buffer, not an sk_buff.
78 */
79void hif_bmi_send_done(struct CE_handle *copyeng, void *ce_context,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +053080 void *transfer_context, qdf_dma_addr_t data,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080081 unsigned int nbytes,
82 unsigned int transfer_id, unsigned int sw_index,
83 unsigned int hw_index, uint32_t toeplitz_hash_result)
84{
85 struct BMI_transaction *transaction =
86 (struct BMI_transaction *)transfer_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080087
88#ifdef BMI_RSP_POLLING
89 /*
90 * Fix EV118783, Release a semaphore after sending
91 * no matter whether a response is been expecting now.
92 */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +053093 qdf_semaphore_release(&transaction->bmi_transaction_sem);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080094#else
95 /*
96 * If a response is anticipated, we'll complete the
97 * transaction if the response has been received.
98 * If no response is anticipated, complete the
99 * transaction now.
100 */
101 transaction->bmi_transaction_flags |= BMI_REQ_SEND_DONE;
102
103 /* resp is't needed or has already been received,
104 * never assume resp comes later then this */
105 if (!transaction->bmi_response_CE ||
106 (transaction->bmi_transaction_flags & BMI_RESP_RECV_DONE)) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530107 qdf_semaphore_release(&transaction->bmi_transaction_sem);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800108 }
109#endif
110}
111
112#ifndef BMI_RSP_POLLING
113void hif_bmi_recv_data(struct CE_handle *copyeng, void *ce_context,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530114 void *transfer_context, qdf_dma_addr_t data,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800115 unsigned int nbytes,
116 unsigned int transfer_id, unsigned int flags)
117{
118 struct BMI_transaction *transaction =
119 (struct BMI_transaction *)transfer_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800120
121 transaction->bmi_response_length = nbytes;
122 transaction->bmi_transaction_flags |= BMI_RESP_RECV_DONE;
123
124 /* when both send/recv are done, the sem can be released */
125 if (transaction->bmi_transaction_flags & BMI_REQ_SEND_DONE) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530126 qdf_semaphore_release(&transaction->bmi_transaction_sem);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800127 }
128}
129#endif
130
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530131QDF_STATUS hif_exchange_bmi_msg(struct hif_opaque_softc *hif_ctx,
132 qdf_dma_addr_t bmi_cmd_da,
133 qdf_dma_addr_t bmi_rsp_da,
Komal Seelam2a5fa632016-02-15 10:33:44 +0530134 uint8_t *bmi_request,
135 uint32_t request_length,
136 uint8_t *bmi_response,
137 uint32_t *bmi_response_lengthp,
138 uint32_t TimeoutMS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800139{
Komal Seelam644263d2016-02-22 20:45:49 +0530140 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Komal Seelam02cf2f82016-02-22 20:44:25 +0530141 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800142 struct HIF_CE_pipe_info *send_pipe_info =
143 &(hif_state->pipe_info[BMI_CE_NUM_TO_TARG]);
144 struct CE_handle *ce_send_hdl = send_pipe_info->ce_hdl;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530145 qdf_dma_addr_t CE_request, CE_response = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800146 struct BMI_transaction *transaction = NULL;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530147 int status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800148 struct HIF_CE_pipe_info *recv_pipe_info =
149 &(hif_state->pipe_info[BMI_CE_NUM_TO_HOST]);
150 struct CE_handle *ce_recv = recv_pipe_info->ce_hdl;
151 unsigned int mux_id = 0;
152 unsigned int transaction_id = 0xffff;
153 unsigned int user_flags = 0;
154#ifdef BMI_RSP_POLLING
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530155 qdf_dma_addr_t buf;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800156 unsigned int completed_nbytes, id, flags;
157 int i;
158#endif
159
160 transaction =
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530161 (struct BMI_transaction *)qdf_mem_malloc(sizeof(*transaction));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800162 if (unlikely(!transaction)) {
163 HIF_ERROR("%s: no memory", __func__);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530164 return QDF_STATUS_E_NOMEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800165 }
166 transaction_id = (mux_id & MUX_ID_MASK) |
167 (transaction_id & TRANSACTION_ID_MASK);
168#ifdef QCA_WIFI_3_0
169 user_flags &= DESC_DATA_FLAG_MASK;
170#endif
171 A_TARGET_ACCESS_LIKELY(scn);
172
173 /* Initialize bmi_transaction_sem to block */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530174 qdf_semaphore_init(&transaction->bmi_transaction_sem);
175 qdf_semaphore_acquire(&transaction->bmi_transaction_sem);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800176
177 transaction->hif_state = hif_state;
178 transaction->bmi_request_host = bmi_request;
179 transaction->bmi_request_length = request_length;
180 transaction->bmi_response_length = 0;
181 transaction->bmi_timeout_ms = TimeoutMS;
182 transaction->bmi_transaction_flags = 0;
183
184 /*
185 * CE_request = dma_map_single(dev,
186 * (void *)bmi_request, request_length, DMA_TO_DEVICE);
187 */
Komal Seelam2a5fa632016-02-15 10:33:44 +0530188 CE_request = bmi_cmd_da;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800189 transaction->bmi_request_CE = CE_request;
190
191 if (bmi_response) {
192
193 /*
194 * CE_response = dma_map_single(dev, bmi_response,
195 * BMI_DATASZ_MAX, DMA_FROM_DEVICE);
196 */
Komal Seelam2a5fa632016-02-15 10:33:44 +0530197 CE_response = bmi_rsp_da;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800198 transaction->bmi_response_host = bmi_response;
199 transaction->bmi_response_CE = CE_response;
200 /* dma_cache_sync(dev, bmi_response,
201 BMI_DATASZ_MAX, DMA_FROM_DEVICE); */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530202 qdf_mem_dma_sync_single_for_device(scn->qdf_dev,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800203 CE_response,
204 BMI_DATASZ_MAX,
205 DMA_FROM_DEVICE);
206 ce_recv_buf_enqueue(ce_recv, transaction,
207 transaction->bmi_response_CE);
208 /* NB: see HIF_BMI_recv_done */
209 } else {
210 transaction->bmi_response_host = NULL;
211 transaction->bmi_response_CE = 0;
212 }
213
214 /* dma_cache_sync(dev, bmi_request, request_length, DMA_TO_DEVICE); */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530215 qdf_mem_dma_sync_single_for_device(scn->qdf_dev, CE_request,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800216 request_length, DMA_TO_DEVICE);
217
218 status =
219 ce_send(ce_send_hdl, transaction,
220 CE_request, request_length,
221 transaction_id, 0, user_flags);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530222 ASSERT(status == QDF_STATUS_SUCCESS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800223 /* NB: see hif_bmi_send_done */
224
225 /* TBDXXX: handle timeout */
226
227 /* Wait for BMI request/response transaction to complete */
228 /* Always just wait for BMI request here if
229 * BMI_RSP_POLLING is defined */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530230 while (qdf_semaphore_acquire
231 (&transaction->bmi_transaction_sem)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800232 /*need some break out condition(time out?) */
233 }
234
235 if (bmi_response) {
236#ifdef BMI_RSP_POLLING
237 /* Fix EV118783, do not wait a semaphore for the BMI response
238 * since the relative interruption may be lost.
239 * poll the BMI response instead.
240 */
241 i = 0;
242 while (ce_completed_recv_next(
243 ce_recv, NULL, NULL, &buf,
244 &completed_nbytes, &id,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530245 &flags) != QDF_STATUS_SUCCESS) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800246 if (i++ > BMI_RSP_TO_MILLISEC) {
247 HIF_ERROR("%s:error, can't get bmi response\n",
248 __func__);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530249 status = QDF_STATUS_E_BUSY;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800250 break;
251 }
252 OS_DELAY(1000);
253 }
254
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530255 if ((status == QDF_STATUS_SUCCESS) && bmi_response_lengthp)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800256 *bmi_response_lengthp = completed_nbytes;
257#else
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530258 if ((status == QDF_STATUS_SUCCESS) && bmi_response_lengthp) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800259 *bmi_response_lengthp =
260 transaction->bmi_response_length;
261 }
262#endif
263
264 }
265
266 /* dma_unmap_single(dev, transaction->bmi_request_CE,
267 request_length, DMA_TO_DEVICE); */
268 /* bus_unmap_single(scn->sc_osdev,
269 transaction->bmi_request_CE,
270 request_length, BUS_DMA_TODEVICE); */
271
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530272 if (status != QDF_STATUS_SUCCESS) {
273 qdf_dma_addr_t unused_buffer;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800274 unsigned int unused_nbytes;
275 unsigned int unused_id;
276 unsigned int toeplitz_hash_result;
277
278 ce_cancel_send_next(ce_send_hdl,
279 NULL, NULL, &unused_buffer,
280 &unused_nbytes, &unused_id,
281 &toeplitz_hash_result);
282 }
283
284 A_TARGET_ACCESS_UNLIKELY(scn);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530285 qdf_mem_free(transaction);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800286 return status;
287}