blob: d79e9c461e93604e1a1c2fd10e18f5de3dce0671 [file] [log] [blame]
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001/*
Houston Hoffmancceec342015-11-11 11:37:20 -08002 * Copyright (c) 2015-2016 The Linux Foundation. All rights reserved.
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08003 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21
22/*
23 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
27
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080028#include "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 Dhavalid5c9f1c2015-11-08 19:04:44 -080033#include <targaddrs.h>
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080034#include "hif_io32.h"
35#include <hif.h>
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080036#include "regtable.h"
37#define ATH_MODULE_NAME hif
38#include <a_debug.h>
39#include "hif_main.h"
40#include "hif_hw_version.h"
Poddar, Siddarthe41943f2016-04-27 15:33:48 +053041#if defined(HIF_PCI) || defined(HIF_SNOC) || defined(HIF_AHB)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080042#include "ce_tasklet.h"
Poddar, Siddarthe41943f2016-04-27 15:33:48 +053043#endif
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +053044#include "qdf_trace.h"
45#include "qdf_status.h"
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080046#include "hif_debug.h"
47#include "mp_dev.h"
Mohit Khanna440c5292016-05-12 11:05:06 -070048#include "ce_api.h"
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +053049#ifdef QCA_WIFI_QCA8074
50#include "hal_api.h"
51#endif
Manjunathappa Prakash2146da32016-10-13 14:47:47 -070052#include "hif_napi.h"
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080053
Komal Seelam5584a7c2016-02-24 19:22:48 +053054void hif_dump(struct hif_opaque_softc *hif_ctx, uint8_t cmd_id, bool start)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080055{
Poddar, Siddarthe41943f2016-04-27 15:33:48 +053056 hif_trigger_dump(hif_ctx, cmd_id, start);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080057}
58
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080059/**
60 * hif_get_target_id(): hif_get_target_id
61 *
62 * Return the virtual memory base address to the caller
63 *
Komal Seelam644263d2016-02-22 20:45:49 +053064 * @scn: hif_softc
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080065 *
66 * Return: A_target_id_t
67 */
Komal Seelam644263d2016-02-22 20:45:49 +053068A_target_id_t hif_get_target_id(struct hif_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080069{
70 return scn->mem;
71}
72
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080073/**
74 * hif_get_targetdef(): hif_get_targetdef
75 * @scn: scn
76 *
77 * Return: void *
78 */
Komal Seelam5584a7c2016-02-24 19:22:48 +053079void *hif_get_targetdef(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080080{
Komal Seelam644263d2016-02-22 20:45:49 +053081 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
82
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080083 return scn->targetdef;
84}
85
86/**
87 * hif_vote_link_down(): unvote for link up
88 *
89 * Call hif_vote_link_down to release a previous request made using
90 * hif_vote_link_up. A hif_vote_link_down call should only be made
91 * after a corresponding hif_vote_link_up, otherwise you could be
92 * negating a vote from another source. When no votes are present
93 * hif will not guarantee the linkstate after hif_bus_suspend.
94 *
95 * SYNCHRONIZE WITH hif_vote_link_up by only calling in MC thread
96 * and initialization deinitialization sequencences.
97 *
98 * Return: n/a
99 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530100void hif_vote_link_down(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800101{
Komal Seelam644263d2016-02-22 20:45:49 +0530102 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530103 QDF_BUG(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800104
105 scn->linkstate_vote--;
106 if (scn->linkstate_vote == 0)
Houston Hoffmancceec342015-11-11 11:37:20 -0800107 hif_bus_prevent_linkdown(scn, false);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800108}
109
110/**
111 * hif_vote_link_up(): vote to prevent bus from suspending
112 *
113 * Makes hif guarantee that fw can message the host normally
114 * durring suspend.
115 *
116 * SYNCHRONIZE WITH hif_vote_link_up by only calling in MC thread
117 * and initialization deinitialization sequencences.
118 *
119 * Return: n/a
120 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530121void hif_vote_link_up(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800122{
Komal Seelam644263d2016-02-22 20:45:49 +0530123 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530124 QDF_BUG(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800125
126 scn->linkstate_vote++;
127 if (scn->linkstate_vote == 1)
Houston Hoffmancceec342015-11-11 11:37:20 -0800128 hif_bus_prevent_linkdown(scn, true);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800129}
130
131/**
132 * hif_can_suspend_link(): query if hif is permitted to suspend the link
133 *
134 * Hif will ensure that the link won't be suspended if the upperlayers
135 * don't want it to.
136 *
137 * SYNCHRONIZATION: MC thread is stopped before bus suspend thus
138 * we don't need extra locking to ensure votes dont change while
139 * we are in the process of suspending or resuming.
140 *
141 * Return: false if hif will guarantee link up durring suspend.
142 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530143bool hif_can_suspend_link(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800144{
Komal Seelam644263d2016-02-22 20:45:49 +0530145 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530146 QDF_BUG(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800147
148 return scn->linkstate_vote == 0;
149}
150
Houston Hoffman4f529982016-05-05 16:11:04 -0700151#ifndef CONFIG_WIN
152#define QCA9984_HOST_INTEREST_ADDRESS -1
153#define QCA9888_HOST_INTEREST_ADDRESS -1
154#define IPQ4019_HOST_INTEREST_ADDRESS -1
155#endif
156
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800157/**
158 * hif_hia_item_address(): hif_hia_item_address
159 * @target_type: target_type
160 * @item_offset: item_offset
161 *
162 * Return: n/a
163 */
164uint32_t hif_hia_item_address(uint32_t target_type, uint32_t item_offset)
165{
166 switch (target_type) {
167 case TARGET_TYPE_AR6002:
168 return AR6002_HOST_INTEREST_ADDRESS + item_offset;
169 case TARGET_TYPE_AR6003:
170 return AR6003_HOST_INTEREST_ADDRESS + item_offset;
171 case TARGET_TYPE_AR6004:
172 return AR6004_HOST_INTEREST_ADDRESS + item_offset;
173 case TARGET_TYPE_AR6006:
174 return AR6006_HOST_INTEREST_ADDRESS + item_offset;
175 case TARGET_TYPE_AR9888:
176 return AR9888_HOST_INTEREST_ADDRESS + item_offset;
177 case TARGET_TYPE_AR6320:
178 case TARGET_TYPE_AR6320V2:
179 return AR6320_HOST_INTEREST_ADDRESS + item_offset;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800180 case TARGET_TYPE_ADRASTEA:
181 /* ADRASTEA doesn't have a host interest address */
182 ASSERT(0);
183 return 0;
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700184 case TARGET_TYPE_AR900B:
185 return AR900B_HOST_INTEREST_ADDRESS + item_offset;
186 case TARGET_TYPE_QCA9984:
187 return QCA9984_HOST_INTEREST_ADDRESS + item_offset;
188 case TARGET_TYPE_QCA9888:
189 return QCA9888_HOST_INTEREST_ADDRESS + item_offset;
190 case TARGET_TYPE_IPQ4019:
191 return IPQ4019_HOST_INTEREST_ADDRESS + item_offset;
192
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800193 default:
194 ASSERT(0);
195 return 0;
196 }
197}
198
199/**
200 * hif_max_num_receives_reached() - check max receive is reached
Komal Seelambd7c51d2016-02-24 10:27:30 +0530201 * @scn: HIF Context
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800202 * @count: unsigned int.
203 *
204 * Output check status as bool
205 *
206 * Return: bool
207 */
Komal Seelambd7c51d2016-02-24 10:27:30 +0530208bool hif_max_num_receives_reached(struct hif_softc *scn, unsigned int count)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800209{
Houston Hoffman75ef5a52016-04-14 17:15:49 -0700210 if (QDF_IS_EPPING_ENABLED(hif_get_conparam(scn)))
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800211 return count > 120;
212 else
213 return count > MAX_NUM_OF_RECEIVES;
214}
215
216/**
217 * init_buffer_count() - initial buffer count
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530218 * @maxSize: qdf_size_t
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800219 *
220 * routine to modify the initial buffer count to be allocated on an os
221 * platform basis. Platform owner will need to modify this as needed
222 *
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530223 * Return: qdf_size_t
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800224 */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530225qdf_size_t init_buffer_count(qdf_size_t maxSize)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800226{
227 return maxSize;
228}
229
230/**
Nirav Shahd7f91592016-04-21 14:18:43 +0530231 * hif_save_htc_htt_config_endpoint() - save htt_tx_endpoint
232 * @hif_ctx: hif context
233 * @htc_htt_tx_endpoint: htt_tx_endpoint
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800234 *
235 * Return: void
236 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530237void hif_save_htc_htt_config_endpoint(struct hif_opaque_softc *hif_ctx,
Nirav Shahd7f91592016-04-21 14:18:43 +0530238 int htc_htt_tx_endpoint)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800239{
Komal Seelam644263d2016-02-22 20:45:49 +0530240 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800241
242 if (!scn) {
243 HIF_ERROR("%s: error: scn or scn->hif_sc is NULL!",
244 __func__);
245 return;
246 }
247
Nirav Shahd7f91592016-04-21 14:18:43 +0530248 scn->htc_htt_tx_endpoint = htc_htt_tx_endpoint;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800249}
250
Houston Hoffmanec93ab02016-05-03 20:09:55 -0700251static const struct qwlan_hw qwlan_hw_list[] = {
252 {
253 .id = AR6320_REV1_VERSION,
254 .subid = 0,
255 .name = "QCA6174_REV1",
256 },
257 {
258 .id = AR6320_REV1_1_VERSION,
259 .subid = 0x1,
260 .name = "QCA6174_REV1_1",
261 },
262 {
263 .id = AR6320_REV1_3_VERSION,
264 .subid = 0x2,
265 .name = "QCA6174_REV1_3",
266 },
267 {
268 .id = AR6320_REV2_1_VERSION,
269 .subid = 0x4,
270 .name = "QCA6174_REV2_1",
271 },
272 {
273 .id = AR6320_REV2_1_VERSION,
274 .subid = 0x5,
275 .name = "QCA6174_REV2_2",
276 },
277 {
278 .id = AR6320_REV3_VERSION,
279 .subid = 0x6,
280 .name = "QCA6174_REV2.3",
281 },
282 {
283 .id = AR6320_REV3_VERSION,
284 .subid = 0x8,
285 .name = "QCA6174_REV3",
286 },
287 {
288 .id = AR6320_REV3_VERSION,
289 .subid = 0x9,
290 .name = "QCA6174_REV3_1",
291 },
292 {
293 .id = AR6320_REV3_2_VERSION,
294 .subid = 0xA,
295 .name = "AR6320_REV3_2_VERSION",
Houston Hoffmancd0884a2016-08-24 15:30:09 -0700296 },
297 {
298 .id = WCN3990_v1,
299 .subid = 0x0,
300 .name = "WCN3990_V1",
Houston Hoffmandd4da482016-10-17 12:41:45 -0700301 },
302 {
303 .id = WCN3990_v2,
304 .subid = 0x0,
305 .name = "WCN3990_V2",
Houston Hoffmanec93ab02016-05-03 20:09:55 -0700306 }
307};
308
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800309/**
310 * hif_get_hw_name(): get a human readable name for the hardware
Komal Seelam91553ce2016-01-27 18:57:10 +0530311 * @info: Target Info
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800312 *
Komal Seelam91553ce2016-01-27 18:57:10 +0530313 * Return: human readable name for the underlying wifi hardware.
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800314 */
Komal Seelam91553ce2016-01-27 18:57:10 +0530315static const char *hif_get_hw_name(struct hif_target_info *info)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800316{
317 int i;
Komal Seelam91553ce2016-01-27 18:57:10 +0530318
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800319 for (i = 0; i < ARRAY_SIZE(qwlan_hw_list); i++) {
Komal Seelam91553ce2016-01-27 18:57:10 +0530320 if (info->target_version == qwlan_hw_list[i].id &&
321 info->target_revision == qwlan_hw_list[i].subid) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800322 return qwlan_hw_list[i].name;
323 }
324 }
325
326 return "Unknown Device";
327}
328
329/**
330 * hif_get_hw_info(): hif_get_hw_info
331 * @scn: scn
332 * @version: version
333 * @revision: revision
334 *
335 * Return: n/a
336 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530337void hif_get_hw_info(struct hif_opaque_softc *scn, u32 *version, u32 *revision,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800338 const char **target_name)
339{
Komal Seelam91553ce2016-01-27 18:57:10 +0530340 struct hif_target_info *info = hif_get_target_info_handle(scn);
Mohit Khanna440c5292016-05-12 11:05:06 -0700341 struct hif_softc *sc = HIF_GET_SOFTC(scn);
342
343 if (sc->bus_type == QDF_BUS_TYPE_USB)
344 hif_usb_get_hw_info(sc);
345
Komal Seelam91553ce2016-01-27 18:57:10 +0530346 *version = info->target_version;
347 *revision = info->target_revision;
348 *target_name = hif_get_hw_name(info);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800349}
350
351/**
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530352 * hif_get_dev_ba(): API to get device base address.
353 * @scn: scn
354 * @version: version
355 * @revision: revision
356 *
357 * Return: n/a
358 */
359void *hif_get_dev_ba(struct hif_opaque_softc *hif_handle)
360{
361 struct hif_softc *scn = (struct hif_softc *)hif_handle;
362
363 return scn->mem;
364}
365/**
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800366 * hif_open(): hif_open
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530367 * @qdf_ctx: QDF Context
Komal Seelambd7c51d2016-02-24 10:27:30 +0530368 * @mode: Driver Mode
369 * @bus_type: Bus Type
370 * @cbk: CDS Callbacks
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800371 *
Komal Seelambd7c51d2016-02-24 10:27:30 +0530372 * API to open HIF Context
373 *
374 * Return: HIF Opaque Pointer
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800375 */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530376struct hif_opaque_softc *hif_open(qdf_device_t qdf_ctx, uint32_t mode,
377 enum qdf_bus_type bus_type,
Komal Seelam75080122016-03-02 15:18:25 +0530378 struct hif_driver_state_callbacks *cbk)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800379{
Komal Seelam644263d2016-02-22 20:45:49 +0530380 struct hif_softc *scn;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530381 QDF_STATUS status = QDF_STATUS_SUCCESS;
Houston Hoffman162164c2016-03-14 21:12:10 -0700382 int bus_context_size = hif_bus_get_context_size(bus_type);
383
384 if (bus_context_size == 0) {
385 HIF_ERROR("%s: context size 0 not allowed", __func__);
386 return NULL;
387 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800388
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530389 scn = (struct hif_softc *)qdf_mem_malloc(bus_context_size);
Komal Seelambd7c51d2016-02-24 10:27:30 +0530390 if (!scn) {
391 HIF_ERROR("%s: cannot alloc memory for HIF context of size:%d",
392 __func__, bus_context_size);
393 return GET_HIF_OPAQUE_HDL(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800394 }
395
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530396 qdf_mem_zero(scn, bus_context_size);
Komal Seelambd7c51d2016-02-24 10:27:30 +0530397
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530398 scn->qdf_dev = qdf_ctx;
Komal Seelambd7c51d2016-02-24 10:27:30 +0530399 scn->hif_con_param = mode;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530400 qdf_atomic_init(&scn->active_tasklet_cnt);
Venkateswara Swamy Bandaru31108f32016-08-08 18:04:29 +0530401 qdf_atomic_init(&scn->active_grp_tasklet_cnt);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530402 qdf_atomic_init(&scn->link_suspended);
403 qdf_atomic_init(&scn->tasklet_from_intr);
Komal Seelam75080122016-03-02 15:18:25 +0530404 qdf_mem_copy(&scn->callbacks, cbk, sizeof(struct hif_driver_state_callbacks));
Houston Hoffman3db96a42016-05-05 19:54:39 -0700405 scn->bus_type = bus_type;
Houston Hoffman3cfe6862016-01-08 10:33:55 -0800406 status = hif_bus_open(scn, bus_type);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530407 if (status != QDF_STATUS_SUCCESS) {
Houston Hoffman3cfe6862016-01-08 10:33:55 -0800408 HIF_ERROR("%s: hif_bus_open error = %d, bus_type = %d",
409 __func__, status, bus_type);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530410 qdf_mem_free(scn);
Komal Seelambd7c51d2016-02-24 10:27:30 +0530411 scn = NULL;
Houston Hoffman3cfe6862016-01-08 10:33:55 -0800412 }
413
Komal Seelambd7c51d2016-02-24 10:27:30 +0530414 return GET_HIF_OPAQUE_HDL(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800415}
416
417/**
418 * hif_close(): hif_close
419 * @hif_ctx: hif_ctx
420 *
421 * Return: n/a
422 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530423void hif_close(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800424{
Komal Seelam644263d2016-02-22 20:45:49 +0530425 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800426
427 if (scn == NULL) {
Komal Seelam5584a7c2016-02-24 19:22:48 +0530428 HIF_ERROR("%s: hif_opaque_softc is NULL", __func__);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800429 return;
430 }
431
432 if (scn->athdiag_procfs_inited) {
433 athdiag_procfs_remove();
434 scn->athdiag_procfs_inited = false;
435 }
436
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800437 hif_bus_close(scn);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530438 qdf_mem_free(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800439}
440
Houston Hoffman6fe60592016-11-18 13:12:08 -0800441#ifdef QCA_WIFI_QCA8074
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530442static QDF_STATUS hif_hal_attach(struct hif_softc *scn)
443{
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530444 if (ce_srng_based(scn)) {
445 scn->hal_soc = hal_attach(scn, scn->qdf_dev);
446 if (scn->hal_soc == NULL)
447 return QDF_STATUS_E_FAILURE;
448 }
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530449
450 return QDF_STATUS_SUCCESS;
451}
Houston Hoffman6fe60592016-11-18 13:12:08 -0800452#else
453static QDF_STATUS hif_hal_attach(struct hif_softc *scn)
454{
455 return QDF_STATUS_SUCCESS;
456}
457#endif
458
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800459/**
460 * hif_enable(): hif_enable
461 * @hif_ctx: hif_ctx
462 * @dev: dev
463 * @bdev: bus dev
464 * @bid: bus ID
465 * @bus_type: bus type
466 * @type: enable type
467 *
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530468 * Return: QDF_STATUS
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800469 */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530470QDF_STATUS hif_enable(struct hif_opaque_softc *hif_ctx, struct device *dev,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800471 void *bdev, const hif_bus_id *bid,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530472 enum qdf_bus_type bus_type,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800473 enum hif_enable_type type)
474{
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530475 QDF_STATUS status;
Komal Seelam644263d2016-02-22 20:45:49 +0530476 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800477
478 if (scn == NULL) {
479 HIF_ERROR("%s: hif_ctx = NULL", __func__);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530480 return QDF_STATUS_E_NULL_VALUE;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800481 }
482
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800483 status = hif_enable_bus(scn, dev, bdev, bid, type);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530484 if (status != QDF_STATUS_SUCCESS) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800485 HIF_ERROR("%s: hif_enable_bus error = %d",
486 __func__, status);
487 return status;
488 }
489
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530490 status = hif_hal_attach(scn);
491 if (status != QDF_STATUS_SUCCESS) {
492 HIF_ERROR("%s: hal attach failed", __func__);
493 return status;
494 }
495
Houston Hoffman108da402016-03-14 21:11:24 -0700496 if (hif_bus_configure(scn)) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800497 HIF_ERROR("%s: Target probe failed.", __func__);
Vishwajith Upendra3f78aa62016-02-09 17:53:02 +0530498 hif_disable_bus(scn);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530499 status = QDF_STATUS_E_FAILURE;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800500 return status;
501 }
Houston Hoffman108da402016-03-14 21:11:24 -0700502
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800503 /*
504 * Flag to avoid potential unallocated memory access from MSI
505 * interrupt handler which could get scheduled as soon as MSI
506 * is enabled, i.e to take care of the race due to the order
507 * in where MSI is enabled before the memory, that will be
508 * in interrupt handlers, is allocated.
509 */
510
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800511 scn->hif_init_done = true;
512
Mohit Khanna440c5292016-05-12 11:05:06 -0700513 HIF_TRACE("%s: OK", __func__);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800514
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530515 return QDF_STATUS_SUCCESS;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800516}
517
Komal Seelam5584a7c2016-02-24 19:22:48 +0530518void hif_disable(struct hif_opaque_softc *hif_ctx, enum hif_disable_type type)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800519{
Komal Seelam644263d2016-02-22 20:45:49 +0530520 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800521
522 if (!scn)
523 return;
524
525 hif_nointrs(scn);
526 if (scn->hif_init_done == false)
Poddar, Siddarthe41943f2016-04-27 15:33:48 +0530527 hif_shutdown_device(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800528 else
Komal Seelam644263d2016-02-22 20:45:49 +0530529 hif_stop(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800530
Vishwajith Upendra3f78aa62016-02-09 17:53:02 +0530531 hif_disable_bus(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800532
Komal Seelambd7c51d2016-02-24 10:27:30 +0530533 hif_wlan_disable(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800534
535 scn->notice_send = false;
536
537 HIF_INFO("%s: X", __func__);
538}
539
Nirav Shahb70bd732016-05-25 14:31:51 +0530540void hif_display_stats(struct hif_opaque_softc *hif_ctx)
541{
542 hif_display_bus_stats(hif_ctx);
543}
544
545void hif_clear_stats(struct hif_opaque_softc *hif_ctx)
546{
547 hif_clear_bus_stats(hif_ctx);
548}
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800549
550/**
Govind Singh2443fb32016-01-13 17:44:48 +0530551 * hif_crash_shutdown_dump_bus_register() - dump bus registers
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800552 * @hif_ctx: hif_ctx
553 *
554 * Return: n/a
555 */
556#if defined(TARGET_RAMDUMP_AFTER_KERNEL_PANIC) \
Houston Hoffmanbc693492016-03-14 21:11:41 -0700557&& defined(DEBUG)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800558
Govind Singh2443fb32016-01-13 17:44:48 +0530559static void hif_crash_shutdown_dump_bus_register(void *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800560{
Komal Seelam5584a7c2016-02-24 19:22:48 +0530561 struct hif_opaque_softc *scn = hif_ctx;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800562
Govind Singh2443fb32016-01-13 17:44:48 +0530563 if (hif_check_soc_status(scn))
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800564 return;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800565
Govind Singh2443fb32016-01-13 17:44:48 +0530566 if (hif_dump_registers(scn))
567 HIF_ERROR("Failed to dump bus registers!");
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800568}
569
570/**
571 * hif_crash_shutdown(): hif_crash_shutdown
572 *
573 * This function is called by the platform driver to dump CE registers
574 *
575 * @hif_ctx: hif_ctx
576 *
577 * Return: n/a
578 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530579void hif_crash_shutdown(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800580{
Komal Seelam644263d2016-02-22 20:45:49 +0530581 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800582
Houston Hoffmanbc693492016-03-14 21:11:41 -0700583 if (!hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800584 return;
585
Houston Hoffmanbc693492016-03-14 21:11:41 -0700586 if (scn->bus_type == QDF_BUS_TYPE_SNOC) {
587 HIF_INFO_MED("%s: RAM dump disabled for bustype %d",
588 __func__, scn->bus_type);
589 return;
590 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800591
Komal Seelam6ee55902016-04-11 17:11:07 +0530592 if (TARGET_STATUS_RESET == scn->target_status) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800593 HIF_INFO_MED("%s: Target is already asserted, ignore!",
594 __func__);
595 return;
596 }
597
Komal Seelambd7c51d2016-02-24 10:27:30 +0530598 if (hif_is_load_or_unload_in_progress(scn)) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800599 HIF_ERROR("%s: Load/unload is in progress, ignore!", __func__);
600 return;
601 }
602
Govind Singh2443fb32016-01-13 17:44:48 +0530603 hif_crash_shutdown_dump_bus_register(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800604
Komal Seelam644263d2016-02-22 20:45:49 +0530605 if (ol_copy_ramdump(hif_ctx))
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800606 goto out;
607
608 HIF_INFO_MED("%s: RAM dump collecting completed!", __func__);
609
610out:
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800611 return;
612}
613#else
Komal Seelam5584a7c2016-02-24 19:22:48 +0530614void hif_crash_shutdown(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800615{
616 HIF_INFO_MED("%s: Collecting target RAM dump disabled",
617 __func__);
618 return;
619}
620#endif /* TARGET_RAMDUMP_AFTER_KERNEL_PANIC */
621
622#ifdef QCA_WIFI_3_0
623/**
624 * hif_check_fw_reg(): hif_check_fw_reg
625 * @scn: scn
626 * @state:
627 *
628 * Return: int
629 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530630int hif_check_fw_reg(struct hif_opaque_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800631{
632 return 0;
633}
634#endif
635
636#ifdef IPA_OFFLOAD
637/**
638 * hif_read_phy_mem_base(): hif_read_phy_mem_base
639 * @scn: scn
640 * @phy_mem_base: physical mem base
641 *
642 * Return: n/a
643 */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530644void hif_read_phy_mem_base(struct hif_softc *scn, qdf_dma_addr_t *phy_mem_base)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800645{
646 *phy_mem_base = scn->mem_pa;
647}
648#endif /* IPA_OFFLOAD */
649
650/**
651 * hif_get_device_type(): hif_get_device_type
652 * @device_id: device_id
653 * @revision_id: revision_id
654 * @hif_type: returned hif_type
655 * @target_type: returned target_type
656 *
657 * Return: int
658 */
659int hif_get_device_type(uint32_t device_id,
660 uint32_t revision_id,
661 uint32_t *hif_type, uint32_t *target_type)
662{
663 int ret = 0;
664
665 switch (device_id) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800666 case ADRASTEA_DEVICE_ID_P2_E12:
667
668 *hif_type = HIF_TYPE_ADRASTEA;
669 *target_type = TARGET_TYPE_ADRASTEA;
670 break;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800671
672 case AR9888_DEVICE_ID:
673 *hif_type = HIF_TYPE_AR9888;
674 *target_type = TARGET_TYPE_AR9888;
675 break;
676
677 case AR6320_DEVICE_ID:
678 switch (revision_id) {
679 case AR6320_FW_1_1:
680 case AR6320_FW_1_3:
681 *hif_type = HIF_TYPE_AR6320;
682 *target_type = TARGET_TYPE_AR6320;
683 break;
684
685 case AR6320_FW_2_0:
686 case AR6320_FW_3_0:
687 case AR6320_FW_3_2:
688 *hif_type = HIF_TYPE_AR6320V2;
689 *target_type = TARGET_TYPE_AR6320V2;
690 break;
691
692 default:
693 HIF_ERROR("%s: error - dev_id = 0x%x, rev_id = 0x%x",
694 __func__, device_id, revision_id);
695 ret = -ENODEV;
696 goto end;
697 }
698 break;
699
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700700 case AR9887_DEVICE_ID:
701 *hif_type = HIF_TYPE_AR9888;
702 *target_type = TARGET_TYPE_AR9888;
Houston Hoffmanc50572b2016-06-08 19:49:46 -0700703 HIF_INFO(" *********** AR9887 **************");
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700704 break;
705
706 case QCA9984_DEVICE_ID:
707 *hif_type = HIF_TYPE_QCA9984;
708 *target_type = TARGET_TYPE_QCA9984;
Houston Hoffmanc50572b2016-06-08 19:49:46 -0700709 HIF_INFO(" *********** QCA9984 *************");
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700710 break;
711
712 case QCA9888_DEVICE_ID:
713 *hif_type = HIF_TYPE_QCA9888;
714 *target_type = TARGET_TYPE_QCA9888;
Houston Hoffmanc50572b2016-06-08 19:49:46 -0700715 HIF_INFO(" *********** QCA9888 *************");
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700716 break;
717
718 case AR900B_DEVICE_ID:
719 *hif_type = HIF_TYPE_AR900B;
720 *target_type = TARGET_TYPE_AR900B;
Houston Hoffmanc50572b2016-06-08 19:49:46 -0700721 HIF_INFO(" *********** AR900B *************");
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700722 break;
723
Houston Hoffman3db96a42016-05-05 19:54:39 -0700724 case IPQ4019_DEVICE_ID:
725 *hif_type = HIF_TYPE_IPQ4019;
726 *target_type = TARGET_TYPE_IPQ4019;
Houston Hoffmanc50572b2016-06-08 19:49:46 -0700727 HIF_INFO(" *********** IPQ4019 *************");
Houston Hoffman3db96a42016-05-05 19:54:39 -0700728 break;
729
Venkateswara Swamy Bandaru9fd9af02016-09-20 20:27:31 +0530730 case QCA8074_DEVICE_ID:
731 *hif_type = HIF_TYPE_QCA8074;
732 *target_type = TARGET_TYPE_QCA8074;
733 HIF_INFO(" *********** QCA8074 *************\n");
734 break;
735
Houston Hoffman31b25ec2016-09-19 13:12:30 -0700736 case QCA6290_EMULATION_DEVICE_ID:
737 *hif_type = HIF_TYPE_QCA6290;
738 *target_type = TARGET_TYPE_QCA6290;
739 HIF_INFO(" *********** QCA6290EMU *************\n");
740 break;
741
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800742 default:
743 HIF_ERROR("%s: Unsupported device ID!", __func__);
744 ret = -ENODEV;
745 break;
746 }
747end:
748 return ret;
749}
Komal Seelam91553ce2016-01-27 18:57:10 +0530750
751/**
Houston Hoffman26352592016-03-14 21:11:43 -0700752 * hif_needs_bmi() - return true if the soc needs bmi through the driver
753 * @hif_ctx: hif context
754 *
755 * Return: true if the soc needs driver bmi otherwise false
756 */
757bool hif_needs_bmi(struct hif_opaque_softc *hif_ctx)
758{
759 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
Pratik Gandhi815c6d82016-10-19 12:06:32 +0530760
Houston Hoffman6c0c3f92016-09-27 18:05:39 -0700761 return (hif_sc->bus_type != QDF_BUS_TYPE_SNOC) &&
762 !ce_srng_based(hif_sc);
Houston Hoffman26352592016-03-14 21:11:43 -0700763}
764
765/**
Houston Hoffman60a1eeb2016-03-14 21:11:44 -0700766 * hif_get_bus_type() - return the bus type
767 *
768 * Return: enum qdf_bus_type
769 */
770enum qdf_bus_type hif_get_bus_type(struct hif_opaque_softc *hif_hdl)
771{
772 struct hif_softc *scn = HIF_GET_SOFTC(hif_hdl);
773 return scn->bus_type;
774}
775
776/**
Komal Seelam91553ce2016-01-27 18:57:10 +0530777 * Target info and ini parameters are global to the driver
778 * Hence these structures are exposed to all the modules in
779 * the driver and they don't need to maintains multiple copies
780 * of the same info, instead get the handle from hif and
781 * modify them in hif
782 */
783
784/**
785 * hif_get_ini_handle() - API to get hif_config_param handle
Komal Seelam644263d2016-02-22 20:45:49 +0530786 * @hif_ctx: HIF Context
Komal Seelam91553ce2016-01-27 18:57:10 +0530787 *
788 * Return: pointer to hif_config_info
789 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530790struct hif_config_info *hif_get_ini_handle(struct hif_opaque_softc *hif_ctx)
Komal Seelam91553ce2016-01-27 18:57:10 +0530791{
Komal Seelam644263d2016-02-22 20:45:49 +0530792 struct hif_softc *sc = HIF_GET_SOFTC(hif_ctx);
793
794 return &sc->hif_config;
Komal Seelam91553ce2016-01-27 18:57:10 +0530795}
796
797/**
798 * hif_get_target_info_handle() - API to get hif_target_info handle
Komal Seelam644263d2016-02-22 20:45:49 +0530799 * @hif_ctx: HIF context
Komal Seelam91553ce2016-01-27 18:57:10 +0530800 *
801 * Return: Pointer to hif_target_info
802 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530803struct hif_target_info *hif_get_target_info_handle(
804 struct hif_opaque_softc *hif_ctx)
Komal Seelam91553ce2016-01-27 18:57:10 +0530805{
Komal Seelam644263d2016-02-22 20:45:49 +0530806 struct hif_softc *sc = HIF_GET_SOFTC(hif_ctx);
807
808 return &sc->target_info;
809
Komal Seelam91553ce2016-01-27 18:57:10 +0530810}
Komal Seelamc92a0cf2016-02-22 20:43:52 +0530811
812#if defined(FEATURE_LRO)
813/**
814 * hif_lro_flush_cb_register - API to register for LRO Flush Callback
815 * @scn: HIF Context
816 * @handler: Function pointer to be called by HIF
817 * @data: Private data to be used by the module registering to HIF
818 *
819 * Return: void
820 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530821void hif_lro_flush_cb_register(struct hif_opaque_softc *scn,
Manjunathappa Prakash2146da32016-10-13 14:47:47 -0700822 void (lro_flush_handler)(void *),
823 void *(lro_init_handler)(void))
Komal Seelamc92a0cf2016-02-22 20:43:52 +0530824{
Manjunathappa Prakash2146da32016-10-13 14:47:47 -0700825 if (hif_napi_enabled(scn, -1))
826 hif_napi_lro_flush_cb_register(scn, lro_flush_handler,
827 lro_init_handler);
828 else
829 ce_lro_flush_cb_register(scn, lro_flush_handler,
830 lro_init_handler);
831}
832
833/**
834 * hif_get_lro_info - Returns LRO instance for instance ID
835 * @ctx_id: LRO instance ID
836 * @hif_hdl: HIF Context
837 *
838 * Return: Pointer to LRO instance.
839 */
840void *hif_get_lro_info(int ctx_id, struct hif_opaque_softc *hif_hdl)
841{
842 void *data;
843
844 if (hif_napi_enabled(hif_hdl, -1))
845 data = hif_napi_get_lro_info(hif_hdl, ctx_id);
846 else
847 data = hif_ce_get_lro_ctx(hif_hdl, ctx_id);
848
849 return data;
850}
851
852/**
853 * hif_get_rx_ctx_id - Returns LRO instance ID based on underlying LRO instance
854 * @ctx_id: LRO context ID
855 * @hif_hdl: HIF Context
856 *
857 * Return: LRO instance ID
858 */
859int hif_get_rx_ctx_id(int ctx_id, struct hif_opaque_softc *hif_hdl)
860{
861 if (hif_napi_enabled(hif_hdl, -1))
862 return NAPI_PIPE2ID(ctx_id);
863 else
864 return ctx_id;
Komal Seelamc92a0cf2016-02-22 20:43:52 +0530865}
866
867/**
868 * hif_lro_flush_cb_deregister - API to deregister for LRO Flush Callbacks
Manjunathappa Prakash2146da32016-10-13 14:47:47 -0700869 * @hif_hdl: HIF Context
870 * @lro_deinit_cb: LRO deinit callback
Komal Seelamc92a0cf2016-02-22 20:43:52 +0530871 *
872 * Return: void
873 */
Manjunathappa Prakash2146da32016-10-13 14:47:47 -0700874void hif_lro_flush_cb_deregister(struct hif_opaque_softc *hif_hdl,
875 void (lro_deinit_cb)(void *))
Komal Seelamc92a0cf2016-02-22 20:43:52 +0530876{
Manjunathappa Prakash2146da32016-10-13 14:47:47 -0700877 if (hif_napi_enabled(hif_hdl, -1))
878 hif_napi_lro_flush_cb_deregister(hif_hdl, lro_deinit_cb);
879 else
880 ce_lro_flush_cb_deregister(hif_hdl, lro_deinit_cb);
881}
882#else /* !defined(FEATURE_LRO) */
883int hif_get_rx_ctx_id(int ctx_id, struct hif_opaque_softc *hif_hdl)
884{
885 return 0;
Komal Seelamc92a0cf2016-02-22 20:43:52 +0530886}
887#endif
Komal Seelam644263d2016-02-22 20:45:49 +0530888
889/**
890 * hif_get_target_status - API to get target status
891 * @hif_ctx: HIF Context
892 *
Komal Seelam6ee55902016-04-11 17:11:07 +0530893 * Return: enum hif_target_status
Komal Seelam644263d2016-02-22 20:45:49 +0530894 */
Komal Seelam6ee55902016-04-11 17:11:07 +0530895enum hif_target_status hif_get_target_status(struct hif_opaque_softc *hif_ctx)
Komal Seelam644263d2016-02-22 20:45:49 +0530896{
897 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
898
899 return scn->target_status;
900}
901
902/**
Komal Seelama5911d32016-02-24 19:21:59 +0530903 * hif_set_target_status() - API to set target status
Komal Seelam644263d2016-02-22 20:45:49 +0530904 * @hif_ctx: HIF Context
905 * @status: Target Status
906 *
907 * Return: void
908 */
Komal Seelam6ee55902016-04-11 17:11:07 +0530909void hif_set_target_status(struct hif_opaque_softc *hif_ctx, enum
910 hif_target_status status)
Komal Seelam644263d2016-02-22 20:45:49 +0530911{
912 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
913
914 scn->target_status = status;
915}
Komal Seelama5911d32016-02-24 19:21:59 +0530916
917/**
918 * hif_init_ini_config() - API to initialize HIF configuration parameters
919 * @hif_ctx: HIF Context
920 * @cfg: HIF Configuration
921 *
922 * Return: void
923 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530924void hif_init_ini_config(struct hif_opaque_softc *hif_ctx,
925 struct hif_config_info *cfg)
Komal Seelama5911d32016-02-24 19:21:59 +0530926{
927 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
928
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530929 qdf_mem_copy(&scn->hif_config, cfg, sizeof(struct hif_config_info));
Komal Seelama5911d32016-02-24 19:21:59 +0530930}
Komal Seelambd7c51d2016-02-24 10:27:30 +0530931
932/**
933 * hif_get_conparam() - API to get driver mode in HIF
934 * @scn: HIF Context
935 *
936 * Return: driver mode of operation
937 */
938uint32_t hif_get_conparam(struct hif_softc *scn)
939{
940 if (!scn)
941 return 0;
942
943 return scn->hif_con_param;
944}
945
946/**
947 * hif_get_callbacks_handle() - API to get callbacks Handle
948 * @scn: HIF Context
949 *
950 * Return: pointer to HIF Callbacks
951 */
Komal Seelam75080122016-03-02 15:18:25 +0530952struct hif_driver_state_callbacks *hif_get_callbacks_handle(struct hif_softc *scn)
Komal Seelambd7c51d2016-02-24 10:27:30 +0530953{
954 return &scn->callbacks;
955}
956
957/**
958 * hif_is_driver_unloading() - API to query upper layers if driver is unloading
959 * @scn: HIF Context
960 *
961 * Return: True/False
962 */
963bool hif_is_driver_unloading(struct hif_softc *scn)
964{
Komal Seelam75080122016-03-02 15:18:25 +0530965 struct hif_driver_state_callbacks *cbk = hif_get_callbacks_handle(scn);
Komal Seelambd7c51d2016-02-24 10:27:30 +0530966
967 if (cbk && cbk->is_driver_unloading)
968 return cbk->is_driver_unloading(cbk->context);
969
970 return false;
971}
972
973/**
974 * hif_is_load_or_unload_in_progress() - API to query upper layers if
975 * load/unload in progress
976 * @scn: HIF Context
977 *
978 * Return: True/False
979 */
980bool hif_is_load_or_unload_in_progress(struct hif_softc *scn)
981{
Komal Seelam75080122016-03-02 15:18:25 +0530982 struct hif_driver_state_callbacks *cbk = hif_get_callbacks_handle(scn);
Komal Seelambd7c51d2016-02-24 10:27:30 +0530983
984 if (cbk && cbk->is_load_unload_in_progress)
985 return cbk->is_load_unload_in_progress(cbk->context);
986
987 return false;
988}
989
990/**
Venkateswara Swamy Bandaru26f6f1e2016-10-03 19:35:57 +0530991 * hif_update_pipe_callback() - API to register pipe specific callbacks
992 * @osc: Opaque softc
993 * @pipeid: pipe id
994 * @callbacks: callbacks to register
995 *
996 * Return: void
997 */
998
999void hif_update_pipe_callback(struct hif_opaque_softc *osc,
1000 u_int8_t pipeid,
1001 struct hif_msg_callbacks *callbacks)
1002{
1003 struct hif_softc *scn = HIF_GET_SOFTC(osc);
1004 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
1005 struct HIF_CE_pipe_info *pipe_info;
1006
1007 QDF_BUG(pipeid < CE_COUNT_MAX);
1008
1009 HIF_INFO_LO("+%s pipeid %d\n", __func__, pipeid);
1010
1011 pipe_info = &hif_state->pipe_info[pipeid];
1012
1013 qdf_mem_copy(&pipe_info->pipe_callbacks,
1014 callbacks, sizeof(pipe_info->pipe_callbacks));
1015
1016 HIF_INFO_LO("-%s\n", __func__);
1017}
1018
1019/**
Komal Seelambd7c51d2016-02-24 10:27:30 +05301020 * hif_is_recovery_in_progress() - API to query upper layers if recovery in
1021 * progress
1022 * @scn: HIF Context
1023 *
1024 * Return: True/False
1025 */
1026bool hif_is_recovery_in_progress(struct hif_softc *scn)
1027{
Komal Seelam75080122016-03-02 15:18:25 +05301028 struct hif_driver_state_callbacks *cbk = hif_get_callbacks_handle(scn);
Komal Seelambd7c51d2016-02-24 10:27:30 +05301029
1030 if (cbk && cbk->is_recovery_in_progress)
1031 return cbk->is_recovery_in_progress(cbk->context);
1032
1033 return false;
1034}
Mohit Khanna440c5292016-05-12 11:05:06 -07001035#if defined(HIF_PCI) || defined(SNOC) || defined(HIF_AHB)
Houston Hoffman56e0d702016-05-05 17:48:06 -07001036/**
1037 * hif_batch_send() - API to access hif specific function
1038 * ce_batch_send.
1039 * @osc: HIF Context
1040 * @msdu : list of msdus to be sent
1041 * @transfer_id : transfer id
1042 * @len : donwloaded length
1043 *
1044 * Return: list of msds not sent
1045 */
1046qdf_nbuf_t hif_batch_send(struct hif_opaque_softc *osc, qdf_nbuf_t msdu,
1047 uint32_t transfer_id, u_int32_t len, uint32_t sendhead)
1048{
1049 void *ce_tx_hdl = hif_get_ce_handle(osc, CE_HTT_TX_CE);
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05301050
Houston Hoffman56e0d702016-05-05 17:48:06 -07001051 return ce_batch_send((struct CE_handle *)ce_tx_hdl, msdu, transfer_id,
1052 len, sendhead);
1053}
1054
1055/**
1056 * hif_update_tx_ring() - API to access hif specific function
1057 * ce_update_tx_ring.
1058 * @osc: HIF Context
1059 * @num_htt_cmpls : number of htt compl received.
1060 *
1061 * Return: void
1062 */
1063void hif_update_tx_ring(struct hif_opaque_softc *osc, u_int32_t num_htt_cmpls)
1064{
1065 void *ce_tx_hdl = hif_get_ce_handle(osc, CE_HTT_TX_CE);
1066 ce_update_tx_ring(ce_tx_hdl, num_htt_cmpls);
1067}
1068
1069
1070/**
1071 * hif_send_single() - API to access hif specific function
1072 * ce_send_single.
1073 * @osc: HIF Context
1074 * @msdu : msdu to be sent
1075 * @transfer_id: transfer id
1076 * @len : downloaded length
1077 *
1078 * Return: msdu sent status
1079 */
1080int hif_send_single(struct hif_opaque_softc *osc, qdf_nbuf_t msdu, uint32_t
1081 transfer_id, u_int32_t len)
1082{
1083 void *ce_tx_hdl = hif_get_ce_handle(osc, CE_HTT_TX_CE);
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05301084
Houston Hoffman56e0d702016-05-05 17:48:06 -07001085 return ce_send_single((struct CE_handle *)ce_tx_hdl, msdu, transfer_id,
1086 len);
1087}
1088
1089/**
1090 * hif_send_fast() - API to access hif specific function
1091 * ce_send_fast.
1092 * @osc: HIF Context
1093 * @msdu : array of msdus to be sent
1094 * @num_msdus : number of msdus in an array
1095 * @transfer_id: transfer id
Nirav Shahda0881a2016-05-16 10:45:16 +05301096 * @download_len: download length
Houston Hoffman56e0d702016-05-05 17:48:06 -07001097 *
1098 * Return: No. of packets that could be sent
1099 */
Nirav Shahda0881a2016-05-16 10:45:16 +05301100int hif_send_fast(struct hif_opaque_softc *osc, qdf_nbuf_t nbuf,
1101 uint32_t transfer_id, uint32_t download_len)
Houston Hoffman56e0d702016-05-05 17:48:06 -07001102{
1103 void *ce_tx_hdl = hif_get_ce_handle(osc, CE_HTT_TX_CE);
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05301104
Nirav Shahda0881a2016-05-16 10:45:16 +05301105 return ce_send_fast((struct CE_handle *)ce_tx_hdl, nbuf,
1106 transfer_id, download_len);
Houston Hoffman56e0d702016-05-05 17:48:06 -07001107}
Mohit Khanna440c5292016-05-12 11:05:06 -07001108#endif
Houston Hoffman56e0d702016-05-05 17:48:06 -07001109
1110/**
1111 * hif_reg_write() - API to access hif specific function
1112 * hif_write32_mb.
1113 * @hif_ctx : HIF Context
1114 * @offset : offset on which value has to be written
1115 * @value : value to be written
1116 *
1117 * Return: None
1118 */
1119void hif_reg_write(struct hif_opaque_softc *hif_ctx, uint32_t offset,
1120 uint32_t value)
1121{
1122 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
1123 hif_write32_mb(scn->mem + offset, value);
1124
1125}
1126
1127/**
1128 * hif_reg_read() - API to access hif specific function
1129 * hif_read32_mb.
1130 * @hif_ctx : HIF Context
1131 * @offset : offset from which value has to be read
1132 *
1133 * Return: Read value
1134 */
1135uint32_t hif_reg_read(struct hif_opaque_softc *hif_ctx, uint32_t offset)
1136{
1137
1138 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
1139 return hif_read32_mb(scn->mem + offset);
1140}
Mohit Khanna440c5292016-05-12 11:05:06 -07001141
1142#if defined(HIF_USB)
1143/**
1144 * hif_ramdump_handler(): generic ramdump handler
1145 * @scn: struct hif_opaque_softc
1146 *
1147 * Return: None
1148 */
1149
1150void hif_ramdump_handler(struct hif_opaque_softc *scn)
1151
1152{
1153 if (hif_get_bus_type == QDF_BUS_TYPE_USB)
1154 hif_usb_ramdump_handler();
1155}
1156#endif
Venkateswara Swamy Bandaru31108f32016-08-08 18:04:29 +05301157
1158/**
1159 * hif_register_ext_group_int_handler() - API to register external group
1160 * interrupt handler.
1161 * @hif_ctx : HIF Context
1162 * @numirq: number of irq's in the group
1163 * @irq: array of irq values
1164 * @ext_intr_handler: callback interrupt handler function
1165 * @context: context to passed in callback
1166 *
1167 * Return: status
1168 */
1169uint32_t hif_register_ext_group_int_handler(struct hif_opaque_softc *hif_ctx,
1170 uint32_t numirq, uint32_t irq[], ext_intr_handler handler,
1171 void *context)
1172{
1173 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
1174 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
1175 struct hif_ext_group_entry *hif_ext_group;
1176
1177 if (scn->hif_init_done) {
1178 HIF_ERROR("%s Called after HIF initialization \n", __func__);
1179 return QDF_STATUS_E_FAILURE;
1180 }
1181
1182 if (hif_state->hif_num_extgroup >= HIF_MAX_GROUP) {
1183 HIF_ERROR("%s Max groups reached\n", __func__);
1184 return QDF_STATUS_E_FAILURE;
1185 }
1186
1187 if (numirq >= HIF_MAX_GRP_IRQ) {
1188 HIF_ERROR("%s invalid numirq\n", __func__);
1189 return QDF_STATUS_E_FAILURE;
1190 }
1191
1192 hif_ext_group = &hif_state->hif_ext_group[hif_state->hif_num_extgroup];
1193
1194 hif_ext_group->numirq = numirq;
1195 qdf_mem_copy(&hif_ext_group->irq[0], irq, numirq * sizeof(irq[0]));
1196 hif_ext_group->context = context;
1197 hif_ext_group->handler = handler;
1198 hif_ext_group->configured = true;
1199 hif_ext_group->grp_id = hif_state->hif_num_extgroup;
1200
1201 hif_state->hif_num_extgroup++;
1202 return QDF_STATUS_SUCCESS;
1203}
1204
1205/**
1206 * hif_ext_grp_tasklet() - grp tasklet
1207 * data: context
1208 *
1209 * return: void
1210 */
1211void hif_ext_grp_tasklet(unsigned long data)
1212{
1213 struct hif_ext_group_entry *hif_ext_group =
1214 (struct hif_ext_group_entry *)data;
1215 struct HIF_CE_state *hif_state = hif_ext_group->hif_state;
1216 struct hif_softc *scn = HIF_GET_SOFTC(hif_state);
1217
1218 if (hif_ext_group->grp_id < HIF_MAX_GROUP) {
1219 hif_ext_group->handler(hif_ext_group->context, HIF_MAX_BUDGET);
1220 hif_grp_irq_enable(scn, hif_ext_group->grp_id);
1221 } else {
1222 HIF_ERROR("%s: ERROR - invalid grp_id = %d",
1223 __func__, hif_ext_group->grp_id);
1224 }
1225
1226 qdf_atomic_dec(&scn->active_grp_tasklet_cnt);
1227}
1228
1229/**
1230 * hif_grp_tasklet_kill() - grp tasklet kill
1231 * scn: hif_softc
1232 *
1233 * return: void
1234 */
1235void hif_grp_tasklet_kill(struct hif_softc *scn)
1236{
1237 int i;
1238 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
1239
1240 for (i = 0; i < HIF_MAX_GROUP; i++)
1241 if (hif_state->hif_ext_group[i].inited) {
1242 tasklet_kill(&hif_state->hif_ext_group[i].intr_tq);
1243 hif_state->hif_ext_group[i].inited = false;
1244 }
1245 qdf_atomic_set(&scn->active_grp_tasklet_cnt, 0);
1246}