blob: 35a2835a8d11aafcd9721d893330b57a648dc1f9 [file] [log] [blame]
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001/*
yeshwanth sriram guntuka78ee68f2016-10-25 11:57:58 +05302 * Copyright (c) 2015-2017 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"
tfyu6c7625b2017-08-10 16:20:32 +080043#include "ce_api.h"
Poddar, Siddarthe41943f2016-04-27 15:33:48 +053044#endif
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +053045#include "qdf_trace.h"
46#include "qdf_status.h"
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080047#include "hif_debug.h"
48#include "mp_dev.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"
Dustin Brownccf859d2017-06-01 14:31:01 -070053#include "hif_unit_test_suspend_i.h"
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080054
Komal Seelam5584a7c2016-02-24 19:22:48 +053055void hif_dump(struct hif_opaque_softc *hif_ctx, uint8_t cmd_id, bool start)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080056{
Poddar, Siddarthe41943f2016-04-27 15:33:48 +053057 hif_trigger_dump(hif_ctx, cmd_id, start);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080058}
59
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080060/**
61 * hif_get_target_id(): hif_get_target_id
62 *
63 * Return the virtual memory base address to the caller
64 *
Komal Seelam644263d2016-02-22 20:45:49 +053065 * @scn: hif_softc
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080066 *
67 * Return: A_target_id_t
68 */
Komal Seelam644263d2016-02-22 20:45:49 +053069A_target_id_t hif_get_target_id(struct hif_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080070{
71 return scn->mem;
72}
73
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080074/**
75 * hif_get_targetdef(): hif_get_targetdef
76 * @scn: scn
77 *
78 * Return: void *
79 */
Komal Seelam5584a7c2016-02-24 19:22:48 +053080void *hif_get_targetdef(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080081{
Komal Seelam644263d2016-02-22 20:45:49 +053082 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
83
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080084 return scn->targetdef;
85}
86
87/**
88 * hif_vote_link_down(): unvote for link up
89 *
90 * Call hif_vote_link_down to release a previous request made using
91 * hif_vote_link_up. A hif_vote_link_down call should only be made
92 * after a corresponding hif_vote_link_up, otherwise you could be
93 * negating a vote from another source. When no votes are present
94 * hif will not guarantee the linkstate after hif_bus_suspend.
95 *
96 * SYNCHRONIZE WITH hif_vote_link_up by only calling in MC thread
97 * and initialization deinitialization sequencences.
98 *
99 * Return: n/a
100 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530101void hif_vote_link_down(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800102{
Komal Seelam644263d2016-02-22 20:45:49 +0530103 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800104
Manikandan Mohanbd0ef8a2017-04-10 13:10:21 -0700105 QDF_BUG(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800106 scn->linkstate_vote--;
107 if (scn->linkstate_vote == 0)
Houston Hoffmancceec342015-11-11 11:37:20 -0800108 hif_bus_prevent_linkdown(scn, false);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800109}
110
111/**
112 * hif_vote_link_up(): vote to prevent bus from suspending
113 *
114 * Makes hif guarantee that fw can message the host normally
115 * durring suspend.
116 *
117 * SYNCHRONIZE WITH hif_vote_link_up by only calling in MC thread
118 * and initialization deinitialization sequencences.
119 *
120 * Return: n/a
121 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530122void hif_vote_link_up(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800123{
Komal Seelam644263d2016-02-22 20:45:49 +0530124 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800125
Manikandan Mohanbd0ef8a2017-04-10 13:10:21 -0700126 QDF_BUG(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800127 scn->linkstate_vote++;
128 if (scn->linkstate_vote == 1)
Houston Hoffmancceec342015-11-11 11:37:20 -0800129 hif_bus_prevent_linkdown(scn, true);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800130}
131
132/**
133 * hif_can_suspend_link(): query if hif is permitted to suspend the link
134 *
135 * Hif will ensure that the link won't be suspended if the upperlayers
136 * don't want it to.
137 *
138 * SYNCHRONIZATION: MC thread is stopped before bus suspend thus
139 * we don't need extra locking to ensure votes dont change while
140 * we are in the process of suspending or resuming.
141 *
142 * Return: false if hif will guarantee link up durring suspend.
143 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530144bool hif_can_suspend_link(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800145{
Komal Seelam644263d2016-02-22 20:45:49 +0530146 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800147
Manikandan Mohanbd0ef8a2017-04-10 13:10:21 -0700148 QDF_BUG(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800149 return scn->linkstate_vote == 0;
150}
151
152/**
153 * hif_hia_item_address(): hif_hia_item_address
154 * @target_type: target_type
155 * @item_offset: item_offset
156 *
157 * Return: n/a
158 */
159uint32_t hif_hia_item_address(uint32_t target_type, uint32_t item_offset)
160{
161 switch (target_type) {
162 case TARGET_TYPE_AR6002:
163 return AR6002_HOST_INTEREST_ADDRESS + item_offset;
164 case TARGET_TYPE_AR6003:
165 return AR6003_HOST_INTEREST_ADDRESS + item_offset;
166 case TARGET_TYPE_AR6004:
167 return AR6004_HOST_INTEREST_ADDRESS + item_offset;
168 case TARGET_TYPE_AR6006:
169 return AR6006_HOST_INTEREST_ADDRESS + item_offset;
170 case TARGET_TYPE_AR9888:
171 return AR9888_HOST_INTEREST_ADDRESS + item_offset;
172 case TARGET_TYPE_AR6320:
173 case TARGET_TYPE_AR6320V2:
174 return AR6320_HOST_INTEREST_ADDRESS + item_offset;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800175 case TARGET_TYPE_ADRASTEA:
176 /* ADRASTEA doesn't have a host interest address */
177 ASSERT(0);
178 return 0;
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700179 case TARGET_TYPE_AR900B:
180 return AR900B_HOST_INTEREST_ADDRESS + item_offset;
181 case TARGET_TYPE_QCA9984:
182 return QCA9984_HOST_INTEREST_ADDRESS + item_offset;
183 case TARGET_TYPE_QCA9888:
184 return QCA9888_HOST_INTEREST_ADDRESS + item_offset;
185 case TARGET_TYPE_IPQ4019:
186 return IPQ4019_HOST_INTEREST_ADDRESS + item_offset;
187
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800188 default:
189 ASSERT(0);
190 return 0;
191 }
192}
193
194/**
195 * hif_max_num_receives_reached() - check max receive is reached
Komal Seelambd7c51d2016-02-24 10:27:30 +0530196 * @scn: HIF Context
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800197 * @count: unsigned int.
198 *
199 * Output check status as bool
200 *
201 * Return: bool
202 */
Komal Seelambd7c51d2016-02-24 10:27:30 +0530203bool hif_max_num_receives_reached(struct hif_softc *scn, unsigned int count)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800204{
Houston Hoffman75ef5a52016-04-14 17:15:49 -0700205 if (QDF_IS_EPPING_ENABLED(hif_get_conparam(scn)))
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800206 return count > 120;
207 else
208 return count > MAX_NUM_OF_RECEIVES;
209}
210
211/**
212 * init_buffer_count() - initial buffer count
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530213 * @maxSize: qdf_size_t
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800214 *
215 * routine to modify the initial buffer count to be allocated on an os
216 * platform basis. Platform owner will need to modify this as needed
217 *
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530218 * Return: qdf_size_t
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800219 */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530220qdf_size_t init_buffer_count(qdf_size_t maxSize)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800221{
222 return maxSize;
223}
224
225/**
Nirav Shahd7f91592016-04-21 14:18:43 +0530226 * hif_save_htc_htt_config_endpoint() - save htt_tx_endpoint
227 * @hif_ctx: hif context
228 * @htc_htt_tx_endpoint: htt_tx_endpoint
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800229 *
230 * Return: void
231 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530232void hif_save_htc_htt_config_endpoint(struct hif_opaque_softc *hif_ctx,
Nirav Shahd7f91592016-04-21 14:18:43 +0530233 int htc_htt_tx_endpoint)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800234{
Komal Seelam644263d2016-02-22 20:45:49 +0530235 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800236
237 if (!scn) {
238 HIF_ERROR("%s: error: scn or scn->hif_sc is NULL!",
239 __func__);
240 return;
241 }
242
Nirav Shahd7f91592016-04-21 14:18:43 +0530243 scn->htc_htt_tx_endpoint = htc_htt_tx_endpoint;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800244}
245
Houston Hoffmanec93ab02016-05-03 20:09:55 -0700246static const struct qwlan_hw qwlan_hw_list[] = {
247 {
248 .id = AR6320_REV1_VERSION,
249 .subid = 0,
250 .name = "QCA6174_REV1",
251 },
252 {
253 .id = AR6320_REV1_1_VERSION,
254 .subid = 0x1,
255 .name = "QCA6174_REV1_1",
256 },
257 {
258 .id = AR6320_REV1_3_VERSION,
259 .subid = 0x2,
260 .name = "QCA6174_REV1_3",
261 },
262 {
263 .id = AR6320_REV2_1_VERSION,
264 .subid = 0x4,
265 .name = "QCA6174_REV2_1",
266 },
267 {
268 .id = AR6320_REV2_1_VERSION,
269 .subid = 0x5,
270 .name = "QCA6174_REV2_2",
271 },
272 {
273 .id = AR6320_REV3_VERSION,
274 .subid = 0x6,
275 .name = "QCA6174_REV2.3",
276 },
277 {
278 .id = AR6320_REV3_VERSION,
279 .subid = 0x8,
280 .name = "QCA6174_REV3",
281 },
282 {
283 .id = AR6320_REV3_VERSION,
284 .subid = 0x9,
285 .name = "QCA6174_REV3_1",
286 },
287 {
288 .id = AR6320_REV3_2_VERSION,
289 .subid = 0xA,
290 .name = "AR6320_REV3_2_VERSION",
Houston Hoffmancd0884a2016-08-24 15:30:09 -0700291 },
292 {
293 .id = WCN3990_v1,
294 .subid = 0x0,
295 .name = "WCN3990_V1",
Houston Hoffmandd4da482016-10-17 12:41:45 -0700296 },
297 {
298 .id = WCN3990_v2,
299 .subid = 0x0,
300 .name = "WCN3990_V2",
Houston Hoffman59fd2452016-11-19 17:27:10 -0800301 },
302 {
303 .id = WCN3990_v2_1,
304 .subid = 0x0,
305 .name = "WCN3990_V2.1",
Yingying Tangd8921742016-10-18 18:13:07 +0800306 },
307 {
308 .id = QCA9379_REV1_VERSION,
309 .subid = 0xC,
310 .name = "QCA9379_REV1",
Yingying Tang80404362016-10-20 23:29:57 +0800311 },
312 {
313 .id = QCA9379_REV1_VERSION,
314 .subid = 0xD,
315 .name = "QCA9379_REV1_1",
Houston Hoffmanec93ab02016-05-03 20:09:55 -0700316 }
317};
318
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800319/**
320 * hif_get_hw_name(): get a human readable name for the hardware
Komal Seelam91553ce2016-01-27 18:57:10 +0530321 * @info: Target Info
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800322 *
Komal Seelam91553ce2016-01-27 18:57:10 +0530323 * Return: human readable name for the underlying wifi hardware.
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800324 */
Komal Seelam91553ce2016-01-27 18:57:10 +0530325static const char *hif_get_hw_name(struct hif_target_info *info)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800326{
327 int i;
Komal Seelam91553ce2016-01-27 18:57:10 +0530328
Houston Hoffman60af6752016-11-21 12:13:36 -0800329 if (info->hw_name)
330 return info->hw_name;
331
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800332 for (i = 0; i < ARRAY_SIZE(qwlan_hw_list); i++) {
Komal Seelam91553ce2016-01-27 18:57:10 +0530333 if (info->target_version == qwlan_hw_list[i].id &&
334 info->target_revision == qwlan_hw_list[i].subid) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800335 return qwlan_hw_list[i].name;
336 }
337 }
338
Houston Hoffman60af6752016-11-21 12:13:36 -0800339 info->hw_name = qdf_mem_malloc(64);
340 if (!info->hw_name)
341 return "Unknown Device (nomem)";
342
343 i = qdf_snprint(info->hw_name, 64, "HW_VERSION=%x.",
344 info->target_version);
345 if (i < 0)
346 return "Unknown Device (snprintf failure)";
347 else
348 return info->hw_name;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800349}
350
351/**
352 * hif_get_hw_info(): hif_get_hw_info
353 * @scn: scn
354 * @version: version
355 * @revision: revision
356 *
357 * Return: n/a
358 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530359void hif_get_hw_info(struct hif_opaque_softc *scn, u32 *version, u32 *revision,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800360 const char **target_name)
361{
Komal Seelam91553ce2016-01-27 18:57:10 +0530362 struct hif_target_info *info = hif_get_target_info_handle(scn);
Mohit Khanna440c5292016-05-12 11:05:06 -0700363 struct hif_softc *sc = HIF_GET_SOFTC(scn);
364
365 if (sc->bus_type == QDF_BUS_TYPE_USB)
366 hif_usb_get_hw_info(sc);
367
Komal Seelam91553ce2016-01-27 18:57:10 +0530368 *version = info->target_version;
369 *revision = info->target_revision;
370 *target_name = hif_get_hw_name(info);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800371}
372
373/**
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530374 * hif_get_dev_ba(): API to get device base address.
375 * @scn: scn
376 * @version: version
377 * @revision: revision
378 *
379 * Return: n/a
380 */
381void *hif_get_dev_ba(struct hif_opaque_softc *hif_handle)
382{
383 struct hif_softc *scn = (struct hif_softc *)hif_handle;
384
385 return scn->mem;
386}
387/**
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800388 * hif_open(): hif_open
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530389 * @qdf_ctx: QDF Context
Komal Seelambd7c51d2016-02-24 10:27:30 +0530390 * @mode: Driver Mode
391 * @bus_type: Bus Type
392 * @cbk: CDS Callbacks
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800393 *
Komal Seelambd7c51d2016-02-24 10:27:30 +0530394 * API to open HIF Context
395 *
396 * Return: HIF Opaque Pointer
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800397 */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530398struct hif_opaque_softc *hif_open(qdf_device_t qdf_ctx, uint32_t mode,
399 enum qdf_bus_type bus_type,
Komal Seelam75080122016-03-02 15:18:25 +0530400 struct hif_driver_state_callbacks *cbk)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800401{
Komal Seelam644263d2016-02-22 20:45:49 +0530402 struct hif_softc *scn;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530403 QDF_STATUS status = QDF_STATUS_SUCCESS;
Houston Hoffman162164c2016-03-14 21:12:10 -0700404 int bus_context_size = hif_bus_get_context_size(bus_type);
405
406 if (bus_context_size == 0) {
407 HIF_ERROR("%s: context size 0 not allowed", __func__);
408 return NULL;
409 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800410
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530411 scn = (struct hif_softc *)qdf_mem_malloc(bus_context_size);
Komal Seelambd7c51d2016-02-24 10:27:30 +0530412 if (!scn) {
413 HIF_ERROR("%s: cannot alloc memory for HIF context of size:%d",
414 __func__, bus_context_size);
415 return GET_HIF_OPAQUE_HDL(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800416 }
417
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530418 scn->qdf_dev = qdf_ctx;
Komal Seelambd7c51d2016-02-24 10:27:30 +0530419 scn->hif_con_param = mode;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530420 qdf_atomic_init(&scn->active_tasklet_cnt);
Venkateswara Swamy Bandaru31108f32016-08-08 18:04:29 +0530421 qdf_atomic_init(&scn->active_grp_tasklet_cnt);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530422 qdf_atomic_init(&scn->link_suspended);
423 qdf_atomic_init(&scn->tasklet_from_intr);
Manikandan Mohanbd0ef8a2017-04-10 13:10:21 -0700424 qdf_mem_copy(&scn->callbacks, cbk,
425 sizeof(struct hif_driver_state_callbacks));
Houston Hoffman3db96a42016-05-05 19:54:39 -0700426 scn->bus_type = bus_type;
Houston Hoffman3cfe6862016-01-08 10:33:55 -0800427 status = hif_bus_open(scn, bus_type);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530428 if (status != QDF_STATUS_SUCCESS) {
Houston Hoffman3cfe6862016-01-08 10:33:55 -0800429 HIF_ERROR("%s: hif_bus_open error = %d, bus_type = %d",
430 __func__, status, bus_type);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530431 qdf_mem_free(scn);
Komal Seelambd7c51d2016-02-24 10:27:30 +0530432 scn = NULL;
Houston Hoffman3cfe6862016-01-08 10:33:55 -0800433 }
434
Komal Seelambd7c51d2016-02-24 10:27:30 +0530435 return GET_HIF_OPAQUE_HDL(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800436}
437
438/**
439 * hif_close(): hif_close
440 * @hif_ctx: hif_ctx
441 *
442 * Return: n/a
443 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530444void hif_close(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800445{
Komal Seelam644263d2016-02-22 20:45:49 +0530446 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800447
448 if (scn == NULL) {
Komal Seelam5584a7c2016-02-24 19:22:48 +0530449 HIF_ERROR("%s: hif_opaque_softc is NULL", __func__);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800450 return;
451 }
452
453 if (scn->athdiag_procfs_inited) {
454 athdiag_procfs_remove();
455 scn->athdiag_procfs_inited = false;
456 }
457
Houston Hoffman60af6752016-11-21 12:13:36 -0800458 if (scn->target_info.hw_name) {
459 char *hw_name = scn->target_info.hw_name;
Manikandan Mohanbd0ef8a2017-04-10 13:10:21 -0700460
Houston Hoffman60af6752016-11-21 12:13:36 -0800461 scn->target_info.hw_name = "ErrUnloading";
462 qdf_mem_free(hw_name);
463 }
464
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800465 hif_bus_close(scn);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530466 qdf_mem_free(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800467}
468
Houston Hoffman6fe60592016-11-18 13:12:08 -0800469#ifdef QCA_WIFI_QCA8074
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530470static QDF_STATUS hif_hal_attach(struct hif_softc *scn)
471{
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530472 if (ce_srng_based(scn)) {
473 scn->hal_soc = hal_attach(scn, scn->qdf_dev);
474 if (scn->hal_soc == NULL)
475 return QDF_STATUS_E_FAILURE;
476 }
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530477
478 return QDF_STATUS_SUCCESS;
479}
Houston Hoffman4e2df402017-05-21 19:36:56 -0700480
481static QDF_STATUS hif_hal_detach(struct hif_softc *scn)
482{
483 if (ce_srng_based(scn)) {
484 hal_detach(scn->hal_soc);
485 scn->hal_soc = NULL;
486 }
487
488 return QDF_STATUS_SUCCESS;
489}
Houston Hoffman6fe60592016-11-18 13:12:08 -0800490#else
491static QDF_STATUS hif_hal_attach(struct hif_softc *scn)
492{
493 return QDF_STATUS_SUCCESS;
494}
Houston Hoffman4e2df402017-05-21 19:36:56 -0700495
496static QDF_STATUS hif_hal_detach(struct hif_softc *scn)
497{
498 return QDF_STATUS_SUCCESS;
499}
Houston Hoffman6fe60592016-11-18 13:12:08 -0800500#endif
501
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800502/**
503 * hif_enable(): hif_enable
504 * @hif_ctx: hif_ctx
505 * @dev: dev
506 * @bdev: bus dev
507 * @bid: bus ID
508 * @bus_type: bus type
509 * @type: enable type
510 *
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530511 * Return: QDF_STATUS
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800512 */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530513QDF_STATUS hif_enable(struct hif_opaque_softc *hif_ctx, struct device *dev,
Manikandan Mohanbd0ef8a2017-04-10 13:10:21 -0700514 void *bdev,
515 const struct hif_bus_id *bid,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530516 enum qdf_bus_type bus_type,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800517 enum hif_enable_type type)
518{
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530519 QDF_STATUS status;
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 == NULL) {
523 HIF_ERROR("%s: hif_ctx = NULL", __func__);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530524 return QDF_STATUS_E_NULL_VALUE;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800525 }
526
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800527 status = hif_enable_bus(scn, dev, bdev, bid, type);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530528 if (status != QDF_STATUS_SUCCESS) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800529 HIF_ERROR("%s: hif_enable_bus error = %d",
530 __func__, status);
531 return status;
532 }
533
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530534 status = hif_hal_attach(scn);
535 if (status != QDF_STATUS_SUCCESS) {
536 HIF_ERROR("%s: hal attach failed", __func__);
Houston Hoffman4e2df402017-05-21 19:36:56 -0700537 goto disable_bus;
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530538 }
539
Houston Hoffman108da402016-03-14 21:11:24 -0700540 if (hif_bus_configure(scn)) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800541 HIF_ERROR("%s: Target probe failed.", __func__);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530542 status = QDF_STATUS_E_FAILURE;
Houston Hoffman4e2df402017-05-21 19:36:56 -0700543 goto hal_detach;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800544 }
Houston Hoffman108da402016-03-14 21:11:24 -0700545
Dustin Brownccf859d2017-06-01 14:31:01 -0700546 hif_ut_suspend_init(scn);
547
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800548 /*
549 * Flag to avoid potential unallocated memory access from MSI
550 * interrupt handler which could get scheduled as soon as MSI
551 * is enabled, i.e to take care of the race due to the order
552 * in where MSI is enabled before the memory, that will be
553 * in interrupt handlers, is allocated.
554 */
555
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800556 scn->hif_init_done = true;
557
Srinivas Girigowda6e0cfd92017-03-09 15:49:59 -0800558 HIF_DBG("%s: OK", __func__);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800559
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530560 return QDF_STATUS_SUCCESS;
Houston Hoffman4e2df402017-05-21 19:36:56 -0700561
562hal_detach:
563 hif_hal_detach(scn);
564disable_bus:
565 hif_disable_bus(scn);
566 return status;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800567}
568
Komal Seelam5584a7c2016-02-24 19:22:48 +0530569void hif_disable(struct hif_opaque_softc *hif_ctx, enum hif_disable_type type)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800570{
Komal Seelam644263d2016-02-22 20:45:49 +0530571 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800572
573 if (!scn)
574 return;
575
576 hif_nointrs(scn);
577 if (scn->hif_init_done == false)
Poddar, Siddarthe41943f2016-04-27 15:33:48 +0530578 hif_shutdown_device(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800579 else
Komal Seelam644263d2016-02-22 20:45:49 +0530580 hif_stop(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800581
Houston Hoffman4e2df402017-05-21 19:36:56 -0700582 hif_hal_detach(scn);
583
Vishwajith Upendra3f78aa62016-02-09 17:53:02 +0530584 hif_disable_bus(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800585
Komal Seelambd7c51d2016-02-24 10:27:30 +0530586 hif_wlan_disable(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800587
588 scn->notice_send = false;
589
Srinivas Girigowda6e0cfd92017-03-09 15:49:59 -0800590 HIF_DBG("%s: X", __func__);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800591}
592
Nirav Shahb70bd732016-05-25 14:31:51 +0530593void hif_display_stats(struct hif_opaque_softc *hif_ctx)
594{
595 hif_display_bus_stats(hif_ctx);
596}
597
598void hif_clear_stats(struct hif_opaque_softc *hif_ctx)
599{
600 hif_clear_bus_stats(hif_ctx);
601}
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800602
603/**
Govind Singh2443fb32016-01-13 17:44:48 +0530604 * hif_crash_shutdown_dump_bus_register() - dump bus registers
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800605 * @hif_ctx: hif_ctx
606 *
607 * Return: n/a
608 */
609#if defined(TARGET_RAMDUMP_AFTER_KERNEL_PANIC) \
Houston Hoffmanbc693492016-03-14 21:11:41 -0700610&& defined(DEBUG)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800611
Govind Singh2443fb32016-01-13 17:44:48 +0530612static void hif_crash_shutdown_dump_bus_register(void *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800613{
Komal Seelam5584a7c2016-02-24 19:22:48 +0530614 struct hif_opaque_softc *scn = hif_ctx;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800615
Govind Singh2443fb32016-01-13 17:44:48 +0530616 if (hif_check_soc_status(scn))
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800617 return;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800618
Govind Singh2443fb32016-01-13 17:44:48 +0530619 if (hif_dump_registers(scn))
620 HIF_ERROR("Failed to dump bus registers!");
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800621}
622
623/**
624 * hif_crash_shutdown(): hif_crash_shutdown
625 *
626 * This function is called by the platform driver to dump CE registers
627 *
628 * @hif_ctx: hif_ctx
629 *
630 * Return: n/a
631 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530632void hif_crash_shutdown(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800633{
Komal Seelam644263d2016-02-22 20:45:49 +0530634 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800635
Houston Hoffmanbc693492016-03-14 21:11:41 -0700636 if (!hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800637 return;
638
Houston Hoffmanbc693492016-03-14 21:11:41 -0700639 if (scn->bus_type == QDF_BUS_TYPE_SNOC) {
640 HIF_INFO_MED("%s: RAM dump disabled for bustype %d",
641 __func__, scn->bus_type);
642 return;
643 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800644
Komal Seelam6ee55902016-04-11 17:11:07 +0530645 if (TARGET_STATUS_RESET == scn->target_status) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800646 HIF_INFO_MED("%s: Target is already asserted, ignore!",
647 __func__);
648 return;
649 }
650
Komal Seelambd7c51d2016-02-24 10:27:30 +0530651 if (hif_is_load_or_unload_in_progress(scn)) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800652 HIF_ERROR("%s: Load/unload is in progress, ignore!", __func__);
653 return;
654 }
655
Govind Singh2443fb32016-01-13 17:44:48 +0530656 hif_crash_shutdown_dump_bus_register(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800657
Komal Seelam644263d2016-02-22 20:45:49 +0530658 if (ol_copy_ramdump(hif_ctx))
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800659 goto out;
660
661 HIF_INFO_MED("%s: RAM dump collecting completed!", __func__);
662
663out:
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800664 return;
665}
666#else
Komal Seelam5584a7c2016-02-24 19:22:48 +0530667void hif_crash_shutdown(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800668{
669 HIF_INFO_MED("%s: Collecting target RAM dump disabled",
670 __func__);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800671}
672#endif /* TARGET_RAMDUMP_AFTER_KERNEL_PANIC */
673
674#ifdef QCA_WIFI_3_0
675/**
676 * hif_check_fw_reg(): hif_check_fw_reg
677 * @scn: scn
678 * @state:
679 *
680 * Return: int
681 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530682int hif_check_fw_reg(struct hif_opaque_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800683{
684 return 0;
685}
686#endif
687
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800688/**
689 * hif_read_phy_mem_base(): hif_read_phy_mem_base
690 * @scn: scn
691 * @phy_mem_base: physical mem base
692 *
693 * Return: n/a
694 */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530695void hif_read_phy_mem_base(struct hif_softc *scn, qdf_dma_addr_t *phy_mem_base)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800696{
697 *phy_mem_base = scn->mem_pa;
698}
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800699
700/**
701 * hif_get_device_type(): hif_get_device_type
702 * @device_id: device_id
703 * @revision_id: revision_id
704 * @hif_type: returned hif_type
705 * @target_type: returned target_type
706 *
707 * Return: int
708 */
709int hif_get_device_type(uint32_t device_id,
710 uint32_t revision_id,
711 uint32_t *hif_type, uint32_t *target_type)
712{
713 int ret = 0;
714
715 switch (device_id) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800716 case ADRASTEA_DEVICE_ID_P2_E12:
717
718 *hif_type = HIF_TYPE_ADRASTEA;
719 *target_type = TARGET_TYPE_ADRASTEA;
720 break;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800721
722 case AR9888_DEVICE_ID:
723 *hif_type = HIF_TYPE_AR9888;
724 *target_type = TARGET_TYPE_AR9888;
725 break;
726
727 case AR6320_DEVICE_ID:
728 switch (revision_id) {
729 case AR6320_FW_1_1:
730 case AR6320_FW_1_3:
731 *hif_type = HIF_TYPE_AR6320;
732 *target_type = TARGET_TYPE_AR6320;
733 break;
734
735 case AR6320_FW_2_0:
736 case AR6320_FW_3_0:
737 case AR6320_FW_3_2:
738 *hif_type = HIF_TYPE_AR6320V2;
739 *target_type = TARGET_TYPE_AR6320V2;
740 break;
741
742 default:
743 HIF_ERROR("%s: error - dev_id = 0x%x, rev_id = 0x%x",
744 __func__, device_id, revision_id);
745 ret = -ENODEV;
746 goto end;
747 }
748 break;
749
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700750 case AR9887_DEVICE_ID:
751 *hif_type = HIF_TYPE_AR9888;
752 *target_type = TARGET_TYPE_AR9888;
Houston Hoffmanc50572b2016-06-08 19:49:46 -0700753 HIF_INFO(" *********** AR9887 **************");
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700754 break;
755
756 case QCA9984_DEVICE_ID:
757 *hif_type = HIF_TYPE_QCA9984;
758 *target_type = TARGET_TYPE_QCA9984;
Houston Hoffmanc50572b2016-06-08 19:49:46 -0700759 HIF_INFO(" *********** QCA9984 *************");
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700760 break;
761
762 case QCA9888_DEVICE_ID:
763 *hif_type = HIF_TYPE_QCA9888;
764 *target_type = TARGET_TYPE_QCA9888;
Houston Hoffmanc50572b2016-06-08 19:49:46 -0700765 HIF_INFO(" *********** QCA9888 *************");
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700766 break;
767
768 case AR900B_DEVICE_ID:
769 *hif_type = HIF_TYPE_AR900B;
770 *target_type = TARGET_TYPE_AR900B;
Houston Hoffmanc50572b2016-06-08 19:49:46 -0700771 HIF_INFO(" *********** AR900B *************");
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700772 break;
773
Houston Hoffman3db96a42016-05-05 19:54:39 -0700774 case IPQ4019_DEVICE_ID:
775 *hif_type = HIF_TYPE_IPQ4019;
776 *target_type = TARGET_TYPE_IPQ4019;
Houston Hoffmanc50572b2016-06-08 19:49:46 -0700777 HIF_INFO(" *********** IPQ4019 *************");
Houston Hoffman3db96a42016-05-05 19:54:39 -0700778 break;
779
Venkateswara Swamy Bandaru9fd9af02016-09-20 20:27:31 +0530780 case QCA8074_DEVICE_ID:
Karunakar Dasinenif61cb072016-09-29 11:50:45 -0700781 case RUMIM2M_DEVICE_ID_NODE0:
782 case RUMIM2M_DEVICE_ID_NODE1:
Sathish Kumar2d2f19a2017-02-13 15:52:07 +0530783 case RUMIM2M_DEVICE_ID_NODE2:
784 case RUMIM2M_DEVICE_ID_NODE3:
Venkateswara Swamy Bandaru9fd9af02016-09-20 20:27:31 +0530785 *hif_type = HIF_TYPE_QCA8074;
786 *target_type = TARGET_TYPE_QCA8074;
787 HIF_INFO(" *********** QCA8074 *************\n");
788 break;
789
Houston Hoffman31b25ec2016-09-19 13:12:30 -0700790 case QCA6290_EMULATION_DEVICE_ID:
Houston Hoffman14f621c2017-05-01 10:35:50 -0700791 case QCA6290_DEVICE_ID:
Houston Hoffman31b25ec2016-09-19 13:12:30 -0700792 *hif_type = HIF_TYPE_QCA6290;
793 *target_type = TARGET_TYPE_QCA6290;
794 HIF_INFO(" *********** QCA6290EMU *************\n");
795 break;
796
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800797 default:
798 HIF_ERROR("%s: Unsupported device ID!", __func__);
799 ret = -ENODEV;
800 break;
801 }
Houston Hoffman817ff7f2017-07-13 14:03:28 -0700802
803 if (*target_type == TARGET_TYPE_UNKNOWN) {
804 HIF_ERROR("%s: Unsupported target_type!", __func__);
805 ret = -ENODEV;
806 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800807end:
808 return ret;
809}
Komal Seelam91553ce2016-01-27 18:57:10 +0530810
811/**
Houston Hoffman26352592016-03-14 21:11:43 -0700812 * hif_needs_bmi() - return true if the soc needs bmi through the driver
813 * @hif_ctx: hif context
814 *
815 * Return: true if the soc needs driver bmi otherwise false
816 */
817bool hif_needs_bmi(struct hif_opaque_softc *hif_ctx)
818{
819 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
Pratik Gandhi815c6d82016-10-19 12:06:32 +0530820
Houston Hoffman6c0c3f92016-09-27 18:05:39 -0700821 return (hif_sc->bus_type != QDF_BUS_TYPE_SNOC) &&
822 !ce_srng_based(hif_sc);
Houston Hoffman26352592016-03-14 21:11:43 -0700823}
824
825/**
Houston Hoffman60a1eeb2016-03-14 21:11:44 -0700826 * hif_get_bus_type() - return the bus type
827 *
828 * Return: enum qdf_bus_type
829 */
830enum qdf_bus_type hif_get_bus_type(struct hif_opaque_softc *hif_hdl)
831{
832 struct hif_softc *scn = HIF_GET_SOFTC(hif_hdl);
Manikandan Mohanbd0ef8a2017-04-10 13:10:21 -0700833
Houston Hoffman60a1eeb2016-03-14 21:11:44 -0700834 return scn->bus_type;
835}
836
837/**
Komal Seelam91553ce2016-01-27 18:57:10 +0530838 * Target info and ini parameters are global to the driver
839 * Hence these structures are exposed to all the modules in
840 * the driver and they don't need to maintains multiple copies
841 * of the same info, instead get the handle from hif and
842 * modify them in hif
843 */
844
845/**
846 * hif_get_ini_handle() - API to get hif_config_param handle
Komal Seelam644263d2016-02-22 20:45:49 +0530847 * @hif_ctx: HIF Context
Komal Seelam91553ce2016-01-27 18:57:10 +0530848 *
849 * Return: pointer to hif_config_info
850 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530851struct hif_config_info *hif_get_ini_handle(struct hif_opaque_softc *hif_ctx)
Komal Seelam91553ce2016-01-27 18:57:10 +0530852{
Komal Seelam644263d2016-02-22 20:45:49 +0530853 struct hif_softc *sc = HIF_GET_SOFTC(hif_ctx);
854
855 return &sc->hif_config;
Komal Seelam91553ce2016-01-27 18:57:10 +0530856}
857
858/**
859 * hif_get_target_info_handle() - API to get hif_target_info handle
Komal Seelam644263d2016-02-22 20:45:49 +0530860 * @hif_ctx: HIF context
Komal Seelam91553ce2016-01-27 18:57:10 +0530861 *
862 * Return: Pointer to hif_target_info
863 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530864struct hif_target_info *hif_get_target_info_handle(
865 struct hif_opaque_softc *hif_ctx)
Komal Seelam91553ce2016-01-27 18:57:10 +0530866{
Komal Seelam644263d2016-02-22 20:45:49 +0530867 struct hif_softc *sc = HIF_GET_SOFTC(hif_ctx);
868
869 return &sc->target_info;
870
Komal Seelam91553ce2016-01-27 18:57:10 +0530871}
Komal Seelamc92a0cf2016-02-22 20:43:52 +0530872
873#if defined(FEATURE_LRO)
Manjunathappa Prakash2146da32016-10-13 14:47:47 -0700874
875/**
876 * hif_get_lro_info - Returns LRO instance for instance ID
877 * @ctx_id: LRO instance ID
878 * @hif_hdl: HIF Context
879 *
880 * Return: Pointer to LRO instance.
881 */
882void *hif_get_lro_info(int ctx_id, struct hif_opaque_softc *hif_hdl)
883{
884 void *data;
885
886 if (hif_napi_enabled(hif_hdl, -1))
887 data = hif_napi_get_lro_info(hif_hdl, ctx_id);
888 else
889 data = hif_ce_get_lro_ctx(hif_hdl, ctx_id);
890
891 return data;
892}
893
894/**
895 * hif_get_rx_ctx_id - Returns LRO instance ID based on underlying LRO instance
896 * @ctx_id: LRO context ID
897 * @hif_hdl: HIF Context
898 *
899 * Return: LRO instance ID
900 */
901int hif_get_rx_ctx_id(int ctx_id, struct hif_opaque_softc *hif_hdl)
902{
903 if (hif_napi_enabled(hif_hdl, -1))
904 return NAPI_PIPE2ID(ctx_id);
905 else
906 return ctx_id;
Komal Seelamc92a0cf2016-02-22 20:43:52 +0530907}
908
Manjunathappa Prakash2146da32016-10-13 14:47:47 -0700909#else /* !defined(FEATURE_LRO) */
910int hif_get_rx_ctx_id(int ctx_id, struct hif_opaque_softc *hif_hdl)
911{
912 return 0;
Komal Seelamc92a0cf2016-02-22 20:43:52 +0530913}
914#endif
Komal Seelam644263d2016-02-22 20:45:49 +0530915
916/**
917 * hif_get_target_status - API to get target status
918 * @hif_ctx: HIF Context
919 *
Komal Seelam6ee55902016-04-11 17:11:07 +0530920 * Return: enum hif_target_status
Komal Seelam644263d2016-02-22 20:45:49 +0530921 */
Komal Seelam6ee55902016-04-11 17:11:07 +0530922enum hif_target_status hif_get_target_status(struct hif_opaque_softc *hif_ctx)
Komal Seelam644263d2016-02-22 20:45:49 +0530923{
924 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
925
926 return scn->target_status;
927}
928
929/**
Komal Seelama5911d32016-02-24 19:21:59 +0530930 * hif_set_target_status() - API to set target status
Komal Seelam644263d2016-02-22 20:45:49 +0530931 * @hif_ctx: HIF Context
932 * @status: Target Status
933 *
934 * Return: void
935 */
Komal Seelam6ee55902016-04-11 17:11:07 +0530936void hif_set_target_status(struct hif_opaque_softc *hif_ctx, enum
937 hif_target_status status)
Komal Seelam644263d2016-02-22 20:45:49 +0530938{
939 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
940
941 scn->target_status = status;
942}
Komal Seelama5911d32016-02-24 19:21:59 +0530943
944/**
945 * hif_init_ini_config() - API to initialize HIF configuration parameters
946 * @hif_ctx: HIF Context
947 * @cfg: HIF Configuration
948 *
949 * Return: void
950 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530951void hif_init_ini_config(struct hif_opaque_softc *hif_ctx,
952 struct hif_config_info *cfg)
Komal Seelama5911d32016-02-24 19:21:59 +0530953{
954 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
955
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530956 qdf_mem_copy(&scn->hif_config, cfg, sizeof(struct hif_config_info));
Komal Seelama5911d32016-02-24 19:21:59 +0530957}
Komal Seelambd7c51d2016-02-24 10:27:30 +0530958
959/**
960 * hif_get_conparam() - API to get driver mode in HIF
961 * @scn: HIF Context
962 *
963 * Return: driver mode of operation
964 */
965uint32_t hif_get_conparam(struct hif_softc *scn)
966{
967 if (!scn)
968 return 0;
969
970 return scn->hif_con_param;
971}
972
973/**
974 * hif_get_callbacks_handle() - API to get callbacks Handle
975 * @scn: HIF Context
976 *
977 * Return: pointer to HIF Callbacks
978 */
Manikandan Mohanbd0ef8a2017-04-10 13:10:21 -0700979struct hif_driver_state_callbacks *hif_get_callbacks_handle(
980 struct hif_softc *scn)
Komal Seelambd7c51d2016-02-24 10:27:30 +0530981{
982 return &scn->callbacks;
983}
984
985/**
986 * hif_is_driver_unloading() - API to query upper layers if driver is unloading
987 * @scn: HIF Context
988 *
989 * Return: True/False
990 */
991bool hif_is_driver_unloading(struct hif_softc *scn)
992{
Komal Seelam75080122016-03-02 15:18:25 +0530993 struct hif_driver_state_callbacks *cbk = hif_get_callbacks_handle(scn);
Komal Seelambd7c51d2016-02-24 10:27:30 +0530994
995 if (cbk && cbk->is_driver_unloading)
996 return cbk->is_driver_unloading(cbk->context);
997
998 return false;
999}
1000
1001/**
1002 * hif_is_load_or_unload_in_progress() - API to query upper layers if
1003 * load/unload in progress
1004 * @scn: HIF Context
1005 *
1006 * Return: True/False
1007 */
1008bool hif_is_load_or_unload_in_progress(struct hif_softc *scn)
1009{
Komal Seelam75080122016-03-02 15:18:25 +05301010 struct hif_driver_state_callbacks *cbk = hif_get_callbacks_handle(scn);
Komal Seelambd7c51d2016-02-24 10:27:30 +05301011
1012 if (cbk && cbk->is_load_unload_in_progress)
1013 return cbk->is_load_unload_in_progress(cbk->context);
1014
1015 return false;
1016}
1017
1018/**
Venkateswara Swamy Bandaru26f6f1e2016-10-03 19:35:57 +05301019 * hif_update_pipe_callback() - API to register pipe specific callbacks
1020 * @osc: Opaque softc
1021 * @pipeid: pipe id
1022 * @callbacks: callbacks to register
1023 *
1024 * Return: void
1025 */
1026
1027void hif_update_pipe_callback(struct hif_opaque_softc *osc,
1028 u_int8_t pipeid,
1029 struct hif_msg_callbacks *callbacks)
1030{
1031 struct hif_softc *scn = HIF_GET_SOFTC(osc);
1032 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
1033 struct HIF_CE_pipe_info *pipe_info;
1034
1035 QDF_BUG(pipeid < CE_COUNT_MAX);
1036
1037 HIF_INFO_LO("+%s pipeid %d\n", __func__, pipeid);
1038
1039 pipe_info = &hif_state->pipe_info[pipeid];
1040
1041 qdf_mem_copy(&pipe_info->pipe_callbacks,
1042 callbacks, sizeof(pipe_info->pipe_callbacks));
1043
1044 HIF_INFO_LO("-%s\n", __func__);
1045}
1046
1047/**
Komal Seelambd7c51d2016-02-24 10:27:30 +05301048 * hif_is_recovery_in_progress() - API to query upper layers if recovery in
1049 * progress
1050 * @scn: HIF Context
1051 *
1052 * Return: True/False
1053 */
1054bool hif_is_recovery_in_progress(struct hif_softc *scn)
1055{
Komal Seelam75080122016-03-02 15:18:25 +05301056 struct hif_driver_state_callbacks *cbk = hif_get_callbacks_handle(scn);
Komal Seelambd7c51d2016-02-24 10:27:30 +05301057
1058 if (cbk && cbk->is_recovery_in_progress)
1059 return cbk->is_recovery_in_progress(cbk->context);
1060
1061 return false;
1062}
Mohit Khanna440c5292016-05-12 11:05:06 -07001063#if defined(HIF_PCI) || defined(SNOC) || defined(HIF_AHB)
Houston Hoffman56e0d702016-05-05 17:48:06 -07001064/**
1065 * hif_batch_send() - API to access hif specific function
1066 * ce_batch_send.
1067 * @osc: HIF Context
1068 * @msdu : list of msdus to be sent
1069 * @transfer_id : transfer id
1070 * @len : donwloaded length
1071 *
1072 * Return: list of msds not sent
1073 */
1074qdf_nbuf_t hif_batch_send(struct hif_opaque_softc *osc, qdf_nbuf_t msdu,
1075 uint32_t transfer_id, u_int32_t len, uint32_t sendhead)
1076{
1077 void *ce_tx_hdl = hif_get_ce_handle(osc, CE_HTT_TX_CE);
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05301078
Houston Hoffman56e0d702016-05-05 17:48:06 -07001079 return ce_batch_send((struct CE_handle *)ce_tx_hdl, msdu, transfer_id,
1080 len, sendhead);
1081}
1082
1083/**
1084 * hif_update_tx_ring() - API to access hif specific function
1085 * ce_update_tx_ring.
1086 * @osc: HIF Context
1087 * @num_htt_cmpls : number of htt compl received.
1088 *
1089 * Return: void
1090 */
1091void hif_update_tx_ring(struct hif_opaque_softc *osc, u_int32_t num_htt_cmpls)
1092{
1093 void *ce_tx_hdl = hif_get_ce_handle(osc, CE_HTT_TX_CE);
Manikandan Mohanbd0ef8a2017-04-10 13:10:21 -07001094
Houston Hoffman56e0d702016-05-05 17:48:06 -07001095 ce_update_tx_ring(ce_tx_hdl, num_htt_cmpls);
1096}
1097
1098
1099/**
1100 * hif_send_single() - API to access hif specific function
1101 * ce_send_single.
1102 * @osc: HIF Context
1103 * @msdu : msdu to be sent
1104 * @transfer_id: transfer id
1105 * @len : downloaded length
1106 *
1107 * Return: msdu sent status
1108 */
1109int hif_send_single(struct hif_opaque_softc *osc, qdf_nbuf_t msdu, uint32_t
1110 transfer_id, u_int32_t len)
1111{
1112 void *ce_tx_hdl = hif_get_ce_handle(osc, CE_HTT_TX_CE);
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05301113
Houston Hoffman56e0d702016-05-05 17:48:06 -07001114 return ce_send_single((struct CE_handle *)ce_tx_hdl, msdu, transfer_id,
1115 len);
1116}
1117
1118/**
1119 * hif_send_fast() - API to access hif specific function
1120 * ce_send_fast.
1121 * @osc: HIF Context
1122 * @msdu : array of msdus to be sent
1123 * @num_msdus : number of msdus in an array
1124 * @transfer_id: transfer id
Nirav Shahda0881a2016-05-16 10:45:16 +05301125 * @download_len: download length
Houston Hoffman56e0d702016-05-05 17:48:06 -07001126 *
1127 * Return: No. of packets that could be sent
1128 */
Nirav Shahda0881a2016-05-16 10:45:16 +05301129int hif_send_fast(struct hif_opaque_softc *osc, qdf_nbuf_t nbuf,
1130 uint32_t transfer_id, uint32_t download_len)
Houston Hoffman56e0d702016-05-05 17:48:06 -07001131{
1132 void *ce_tx_hdl = hif_get_ce_handle(osc, CE_HTT_TX_CE);
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05301133
Nirav Shahda0881a2016-05-16 10:45:16 +05301134 return ce_send_fast((struct CE_handle *)ce_tx_hdl, nbuf,
1135 transfer_id, download_len);
Houston Hoffman56e0d702016-05-05 17:48:06 -07001136}
Mohit Khanna440c5292016-05-12 11:05:06 -07001137#endif
Houston Hoffman56e0d702016-05-05 17:48:06 -07001138
1139/**
1140 * hif_reg_write() - API to access hif specific function
1141 * hif_write32_mb.
1142 * @hif_ctx : HIF Context
1143 * @offset : offset on which value has to be written
1144 * @value : value to be written
1145 *
1146 * Return: None
1147 */
1148void hif_reg_write(struct hif_opaque_softc *hif_ctx, uint32_t offset,
1149 uint32_t value)
1150{
1151 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Manikandan Mohanbd0ef8a2017-04-10 13:10:21 -07001152
Houston Hoffman56e0d702016-05-05 17:48:06 -07001153 hif_write32_mb(scn->mem + offset, value);
1154
1155}
1156
1157/**
1158 * hif_reg_read() - API to access hif specific function
1159 * hif_read32_mb.
1160 * @hif_ctx : HIF Context
1161 * @offset : offset from which value has to be read
1162 *
1163 * Return: Read value
1164 */
1165uint32_t hif_reg_read(struct hif_opaque_softc *hif_ctx, uint32_t offset)
1166{
1167
1168 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Manikandan Mohanbd0ef8a2017-04-10 13:10:21 -07001169
Houston Hoffman56e0d702016-05-05 17:48:06 -07001170 return hif_read32_mb(scn->mem + offset);
1171}
Mohit Khanna440c5292016-05-12 11:05:06 -07001172
1173#if defined(HIF_USB)
1174/**
1175 * hif_ramdump_handler(): generic ramdump handler
1176 * @scn: struct hif_opaque_softc
1177 *
1178 * Return: None
1179 */
1180
1181void hif_ramdump_handler(struct hif_opaque_softc *scn)
1182
1183{
1184 if (hif_get_bus_type == QDF_BUS_TYPE_USB)
1185 hif_usb_ramdump_handler();
1186}
1187#endif
Venkateswara Swamy Bandaru31108f32016-08-08 18:04:29 +05301188
Dustin Brown2af3d672017-05-30 16:14:01 -07001189#ifdef WLAN_SUSPEND_RESUME_TEST
1190irqreturn_t hif_wake_interrupt_handler(int irq, void *context)
1191{
1192 struct hif_softc *scn = context;
1193
1194 HIF_INFO("wake interrupt received on irq %d", irq);
1195
1196 if (hif_is_ut_suspended(scn))
1197 hif_ut_fw_resume(scn);
1198
1199 return IRQ_HANDLED;
1200}
1201#else /* WLAN_SUSPEND_RESUME_TEST */
1202irqreturn_t hif_wake_interrupt_handler(int irq, void *context)
1203{
1204 HIF_INFO("wake interrupt received on irq %d", irq);
1205
1206 return IRQ_HANDLED;
1207}
1208#endif /* WLAN_SUSPEND_RESUME_TEST */