blob: afecf3b7def26bdb962012ca2738c0f3af28a5ac [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
Arunk Khandavallie14e8e92017-04-03 21:40:26 +0530465 if (scn->vaddr_rri_on_ddr)
466 qdf_mem_free_consistent(scn->qdf_dev, scn->qdf_dev->dev,
467 (CE_COUNT*sizeof(uint32_t)),
468 scn->vaddr_rri_on_ddr, scn->paddr_rri_on_ddr,
469 0);
470
471 scn->vaddr_rri_on_ddr = NULL;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800472 hif_bus_close(scn);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530473 qdf_mem_free(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800474}
475
Houston Hoffman6fe60592016-11-18 13:12:08 -0800476#ifdef QCA_WIFI_QCA8074
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530477static QDF_STATUS hif_hal_attach(struct hif_softc *scn)
478{
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530479 if (ce_srng_based(scn)) {
480 scn->hal_soc = hal_attach(scn, scn->qdf_dev);
481 if (scn->hal_soc == NULL)
482 return QDF_STATUS_E_FAILURE;
483 }
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530484
485 return QDF_STATUS_SUCCESS;
486}
Houston Hoffman4e2df402017-05-21 19:36:56 -0700487
488static QDF_STATUS hif_hal_detach(struct hif_softc *scn)
489{
490 if (ce_srng_based(scn)) {
491 hal_detach(scn->hal_soc);
492 scn->hal_soc = NULL;
493 }
494
495 return QDF_STATUS_SUCCESS;
496}
Houston Hoffman6fe60592016-11-18 13:12:08 -0800497#else
498static QDF_STATUS hif_hal_attach(struct hif_softc *scn)
499{
500 return QDF_STATUS_SUCCESS;
501}
Houston Hoffman4e2df402017-05-21 19:36:56 -0700502
503static QDF_STATUS hif_hal_detach(struct hif_softc *scn)
504{
505 return QDF_STATUS_SUCCESS;
506}
Houston Hoffman6fe60592016-11-18 13:12:08 -0800507#endif
508
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800509/**
510 * hif_enable(): hif_enable
511 * @hif_ctx: hif_ctx
512 * @dev: dev
513 * @bdev: bus dev
514 * @bid: bus ID
515 * @bus_type: bus type
516 * @type: enable type
517 *
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530518 * Return: QDF_STATUS
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800519 */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530520QDF_STATUS hif_enable(struct hif_opaque_softc *hif_ctx, struct device *dev,
Manikandan Mohanbd0ef8a2017-04-10 13:10:21 -0700521 void *bdev,
522 const struct hif_bus_id *bid,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530523 enum qdf_bus_type bus_type,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800524 enum hif_enable_type type)
525{
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530526 QDF_STATUS status;
Komal Seelam644263d2016-02-22 20:45:49 +0530527 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800528
529 if (scn == NULL) {
530 HIF_ERROR("%s: hif_ctx = NULL", __func__);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530531 return QDF_STATUS_E_NULL_VALUE;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800532 }
533
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800534 status = hif_enable_bus(scn, dev, bdev, bid, type);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530535 if (status != QDF_STATUS_SUCCESS) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800536 HIF_ERROR("%s: hif_enable_bus error = %d",
537 __func__, status);
538 return status;
539 }
540
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530541 status = hif_hal_attach(scn);
542 if (status != QDF_STATUS_SUCCESS) {
543 HIF_ERROR("%s: hal attach failed", __func__);
Houston Hoffman4e2df402017-05-21 19:36:56 -0700544 goto disable_bus;
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530545 }
546
Houston Hoffman108da402016-03-14 21:11:24 -0700547 if (hif_bus_configure(scn)) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800548 HIF_ERROR("%s: Target probe failed.", __func__);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530549 status = QDF_STATUS_E_FAILURE;
Houston Hoffman4e2df402017-05-21 19:36:56 -0700550 goto hal_detach;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800551 }
Houston Hoffman108da402016-03-14 21:11:24 -0700552
Dustin Brownccf859d2017-06-01 14:31:01 -0700553 hif_ut_suspend_init(scn);
554
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800555 /*
556 * Flag to avoid potential unallocated memory access from MSI
557 * interrupt handler which could get scheduled as soon as MSI
558 * is enabled, i.e to take care of the race due to the order
559 * in where MSI is enabled before the memory, that will be
560 * in interrupt handlers, is allocated.
561 */
562
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800563 scn->hif_init_done = true;
564
Srinivas Girigowda6e0cfd92017-03-09 15:49:59 -0800565 HIF_DBG("%s: OK", __func__);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800566
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530567 return QDF_STATUS_SUCCESS;
Houston Hoffman4e2df402017-05-21 19:36:56 -0700568
569hal_detach:
570 hif_hal_detach(scn);
571disable_bus:
572 hif_disable_bus(scn);
573 return status;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800574}
575
Komal Seelam5584a7c2016-02-24 19:22:48 +0530576void hif_disable(struct hif_opaque_softc *hif_ctx, enum hif_disable_type type)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800577{
Komal Seelam644263d2016-02-22 20:45:49 +0530578 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800579
580 if (!scn)
581 return;
582
583 hif_nointrs(scn);
584 if (scn->hif_init_done == false)
Poddar, Siddarthe41943f2016-04-27 15:33:48 +0530585 hif_shutdown_device(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800586 else
Komal Seelam644263d2016-02-22 20:45:49 +0530587 hif_stop(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800588
Houston Hoffman4e2df402017-05-21 19:36:56 -0700589 hif_hal_detach(scn);
590
Vishwajith Upendra3f78aa62016-02-09 17:53:02 +0530591 hif_disable_bus(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800592
Komal Seelambd7c51d2016-02-24 10:27:30 +0530593 hif_wlan_disable(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800594
595 scn->notice_send = false;
596
Srinivas Girigowda6e0cfd92017-03-09 15:49:59 -0800597 HIF_DBG("%s: X", __func__);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800598}
599
Nirav Shahb70bd732016-05-25 14:31:51 +0530600void hif_display_stats(struct hif_opaque_softc *hif_ctx)
601{
602 hif_display_bus_stats(hif_ctx);
603}
604
605void hif_clear_stats(struct hif_opaque_softc *hif_ctx)
606{
607 hif_clear_bus_stats(hif_ctx);
608}
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800609
610/**
Govind Singh2443fb32016-01-13 17:44:48 +0530611 * hif_crash_shutdown_dump_bus_register() - dump bus registers
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800612 * @hif_ctx: hif_ctx
613 *
614 * Return: n/a
615 */
616#if defined(TARGET_RAMDUMP_AFTER_KERNEL_PANIC) \
Houston Hoffmanbc693492016-03-14 21:11:41 -0700617&& defined(DEBUG)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800618
Govind Singh2443fb32016-01-13 17:44:48 +0530619static void hif_crash_shutdown_dump_bus_register(void *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800620{
Komal Seelam5584a7c2016-02-24 19:22:48 +0530621 struct hif_opaque_softc *scn = hif_ctx;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800622
Govind Singh2443fb32016-01-13 17:44:48 +0530623 if (hif_check_soc_status(scn))
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800624 return;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800625
Govind Singh2443fb32016-01-13 17:44:48 +0530626 if (hif_dump_registers(scn))
627 HIF_ERROR("Failed to dump bus registers!");
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800628}
629
630/**
631 * hif_crash_shutdown(): hif_crash_shutdown
632 *
633 * This function is called by the platform driver to dump CE registers
634 *
635 * @hif_ctx: hif_ctx
636 *
637 * Return: n/a
638 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530639void hif_crash_shutdown(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800640{
Komal Seelam644263d2016-02-22 20:45:49 +0530641 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800642
Houston Hoffmanbc693492016-03-14 21:11:41 -0700643 if (!hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800644 return;
645
Houston Hoffmanbc693492016-03-14 21:11:41 -0700646 if (scn->bus_type == QDF_BUS_TYPE_SNOC) {
647 HIF_INFO_MED("%s: RAM dump disabled for bustype %d",
648 __func__, scn->bus_type);
649 return;
650 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800651
Komal Seelam6ee55902016-04-11 17:11:07 +0530652 if (TARGET_STATUS_RESET == scn->target_status) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800653 HIF_INFO_MED("%s: Target is already asserted, ignore!",
654 __func__);
655 return;
656 }
657
Komal Seelambd7c51d2016-02-24 10:27:30 +0530658 if (hif_is_load_or_unload_in_progress(scn)) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800659 HIF_ERROR("%s: Load/unload is in progress, ignore!", __func__);
660 return;
661 }
662
Govind Singh2443fb32016-01-13 17:44:48 +0530663 hif_crash_shutdown_dump_bus_register(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800664
Komal Seelam644263d2016-02-22 20:45:49 +0530665 if (ol_copy_ramdump(hif_ctx))
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800666 goto out;
667
668 HIF_INFO_MED("%s: RAM dump collecting completed!", __func__);
669
670out:
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800671 return;
672}
673#else
Komal Seelam5584a7c2016-02-24 19:22:48 +0530674void hif_crash_shutdown(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800675{
676 HIF_INFO_MED("%s: Collecting target RAM dump disabled",
677 __func__);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800678}
679#endif /* TARGET_RAMDUMP_AFTER_KERNEL_PANIC */
680
681#ifdef QCA_WIFI_3_0
682/**
683 * hif_check_fw_reg(): hif_check_fw_reg
684 * @scn: scn
685 * @state:
686 *
687 * Return: int
688 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530689int hif_check_fw_reg(struct hif_opaque_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800690{
691 return 0;
692}
693#endif
694
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800695/**
696 * hif_read_phy_mem_base(): hif_read_phy_mem_base
697 * @scn: scn
698 * @phy_mem_base: physical mem base
699 *
700 * Return: n/a
701 */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530702void hif_read_phy_mem_base(struct hif_softc *scn, qdf_dma_addr_t *phy_mem_base)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800703{
704 *phy_mem_base = scn->mem_pa;
705}
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800706
707/**
708 * hif_get_device_type(): hif_get_device_type
709 * @device_id: device_id
710 * @revision_id: revision_id
711 * @hif_type: returned hif_type
712 * @target_type: returned target_type
713 *
714 * Return: int
715 */
716int hif_get_device_type(uint32_t device_id,
717 uint32_t revision_id,
718 uint32_t *hif_type, uint32_t *target_type)
719{
720 int ret = 0;
721
722 switch (device_id) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800723 case ADRASTEA_DEVICE_ID_P2_E12:
724
725 *hif_type = HIF_TYPE_ADRASTEA;
726 *target_type = TARGET_TYPE_ADRASTEA;
727 break;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800728
729 case AR9888_DEVICE_ID:
730 *hif_type = HIF_TYPE_AR9888;
731 *target_type = TARGET_TYPE_AR9888;
732 break;
733
734 case AR6320_DEVICE_ID:
735 switch (revision_id) {
736 case AR6320_FW_1_1:
737 case AR6320_FW_1_3:
738 *hif_type = HIF_TYPE_AR6320;
739 *target_type = TARGET_TYPE_AR6320;
740 break;
741
742 case AR6320_FW_2_0:
743 case AR6320_FW_3_0:
744 case AR6320_FW_3_2:
745 *hif_type = HIF_TYPE_AR6320V2;
746 *target_type = TARGET_TYPE_AR6320V2;
747 break;
748
749 default:
750 HIF_ERROR("%s: error - dev_id = 0x%x, rev_id = 0x%x",
751 __func__, device_id, revision_id);
752 ret = -ENODEV;
753 goto end;
754 }
755 break;
756
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700757 case AR9887_DEVICE_ID:
758 *hif_type = HIF_TYPE_AR9888;
759 *target_type = TARGET_TYPE_AR9888;
Houston Hoffmanc50572b2016-06-08 19:49:46 -0700760 HIF_INFO(" *********** AR9887 **************");
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700761 break;
762
763 case QCA9984_DEVICE_ID:
764 *hif_type = HIF_TYPE_QCA9984;
765 *target_type = TARGET_TYPE_QCA9984;
Houston Hoffmanc50572b2016-06-08 19:49:46 -0700766 HIF_INFO(" *********** QCA9984 *************");
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700767 break;
768
769 case QCA9888_DEVICE_ID:
770 *hif_type = HIF_TYPE_QCA9888;
771 *target_type = TARGET_TYPE_QCA9888;
Houston Hoffmanc50572b2016-06-08 19:49:46 -0700772 HIF_INFO(" *********** QCA9888 *************");
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700773 break;
774
775 case AR900B_DEVICE_ID:
776 *hif_type = HIF_TYPE_AR900B;
777 *target_type = TARGET_TYPE_AR900B;
Houston Hoffmanc50572b2016-06-08 19:49:46 -0700778 HIF_INFO(" *********** AR900B *************");
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700779 break;
780
Houston Hoffman3db96a42016-05-05 19:54:39 -0700781 case IPQ4019_DEVICE_ID:
782 *hif_type = HIF_TYPE_IPQ4019;
783 *target_type = TARGET_TYPE_IPQ4019;
Houston Hoffmanc50572b2016-06-08 19:49:46 -0700784 HIF_INFO(" *********** IPQ4019 *************");
Houston Hoffman3db96a42016-05-05 19:54:39 -0700785 break;
786
Venkateswara Swamy Bandaru9fd9af02016-09-20 20:27:31 +0530787 case QCA8074_DEVICE_ID:
Karunakar Dasinenif61cb072016-09-29 11:50:45 -0700788 case RUMIM2M_DEVICE_ID_NODE0:
789 case RUMIM2M_DEVICE_ID_NODE1:
Sathish Kumar2d2f19a2017-02-13 15:52:07 +0530790 case RUMIM2M_DEVICE_ID_NODE2:
791 case RUMIM2M_DEVICE_ID_NODE3:
Venkateswara Swamy Bandaru9fd9af02016-09-20 20:27:31 +0530792 *hif_type = HIF_TYPE_QCA8074;
793 *target_type = TARGET_TYPE_QCA8074;
794 HIF_INFO(" *********** QCA8074 *************\n");
795 break;
796
Houston Hoffman31b25ec2016-09-19 13:12:30 -0700797 case QCA6290_EMULATION_DEVICE_ID:
Houston Hoffman14f621c2017-05-01 10:35:50 -0700798 case QCA6290_DEVICE_ID:
Houston Hoffman31b25ec2016-09-19 13:12:30 -0700799 *hif_type = HIF_TYPE_QCA6290;
800 *target_type = TARGET_TYPE_QCA6290;
801 HIF_INFO(" *********** QCA6290EMU *************\n");
802 break;
803
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800804 default:
805 HIF_ERROR("%s: Unsupported device ID!", __func__);
806 ret = -ENODEV;
807 break;
808 }
Houston Hoffman817ff7f2017-07-13 14:03:28 -0700809
810 if (*target_type == TARGET_TYPE_UNKNOWN) {
811 HIF_ERROR("%s: Unsupported target_type!", __func__);
812 ret = -ENODEV;
813 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800814end:
815 return ret;
816}
Komal Seelam91553ce2016-01-27 18:57:10 +0530817
818/**
Houston Hoffman26352592016-03-14 21:11:43 -0700819 * hif_needs_bmi() - return true if the soc needs bmi through the driver
820 * @hif_ctx: hif context
821 *
822 * Return: true if the soc needs driver bmi otherwise false
823 */
824bool hif_needs_bmi(struct hif_opaque_softc *hif_ctx)
825{
826 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
Pratik Gandhi815c6d82016-10-19 12:06:32 +0530827
Houston Hoffman6c0c3f92016-09-27 18:05:39 -0700828 return (hif_sc->bus_type != QDF_BUS_TYPE_SNOC) &&
829 !ce_srng_based(hif_sc);
Houston Hoffman26352592016-03-14 21:11:43 -0700830}
831
832/**
Houston Hoffman60a1eeb2016-03-14 21:11:44 -0700833 * hif_get_bus_type() - return the bus type
834 *
835 * Return: enum qdf_bus_type
836 */
837enum qdf_bus_type hif_get_bus_type(struct hif_opaque_softc *hif_hdl)
838{
839 struct hif_softc *scn = HIF_GET_SOFTC(hif_hdl);
Manikandan Mohanbd0ef8a2017-04-10 13:10:21 -0700840
Houston Hoffman60a1eeb2016-03-14 21:11:44 -0700841 return scn->bus_type;
842}
843
844/**
Komal Seelam91553ce2016-01-27 18:57:10 +0530845 * Target info and ini parameters are global to the driver
846 * Hence these structures are exposed to all the modules in
847 * the driver and they don't need to maintains multiple copies
848 * of the same info, instead get the handle from hif and
849 * modify them in hif
850 */
851
852/**
853 * hif_get_ini_handle() - API to get hif_config_param handle
Komal Seelam644263d2016-02-22 20:45:49 +0530854 * @hif_ctx: HIF Context
Komal Seelam91553ce2016-01-27 18:57:10 +0530855 *
856 * Return: pointer to hif_config_info
857 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530858struct hif_config_info *hif_get_ini_handle(struct hif_opaque_softc *hif_ctx)
Komal Seelam91553ce2016-01-27 18:57:10 +0530859{
Komal Seelam644263d2016-02-22 20:45:49 +0530860 struct hif_softc *sc = HIF_GET_SOFTC(hif_ctx);
861
862 return &sc->hif_config;
Komal Seelam91553ce2016-01-27 18:57:10 +0530863}
864
865/**
866 * hif_get_target_info_handle() - API to get hif_target_info handle
Komal Seelam644263d2016-02-22 20:45:49 +0530867 * @hif_ctx: HIF context
Komal Seelam91553ce2016-01-27 18:57:10 +0530868 *
869 * Return: Pointer to hif_target_info
870 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530871struct hif_target_info *hif_get_target_info_handle(
872 struct hif_opaque_softc *hif_ctx)
Komal Seelam91553ce2016-01-27 18:57:10 +0530873{
Komal Seelam644263d2016-02-22 20:45:49 +0530874 struct hif_softc *sc = HIF_GET_SOFTC(hif_ctx);
875
876 return &sc->target_info;
877
Komal Seelam91553ce2016-01-27 18:57:10 +0530878}
Komal Seelamc92a0cf2016-02-22 20:43:52 +0530879
880#if defined(FEATURE_LRO)
Manjunathappa Prakash2146da32016-10-13 14:47:47 -0700881
882/**
883 * hif_get_lro_info - Returns LRO instance for instance ID
884 * @ctx_id: LRO instance ID
885 * @hif_hdl: HIF Context
886 *
887 * Return: Pointer to LRO instance.
888 */
889void *hif_get_lro_info(int ctx_id, struct hif_opaque_softc *hif_hdl)
890{
891 void *data;
892
893 if (hif_napi_enabled(hif_hdl, -1))
894 data = hif_napi_get_lro_info(hif_hdl, ctx_id);
895 else
896 data = hif_ce_get_lro_ctx(hif_hdl, ctx_id);
897
898 return data;
899}
900
901/**
902 * hif_get_rx_ctx_id - Returns LRO instance ID based on underlying LRO instance
903 * @ctx_id: LRO context ID
904 * @hif_hdl: HIF Context
905 *
906 * Return: LRO instance ID
907 */
908int hif_get_rx_ctx_id(int ctx_id, struct hif_opaque_softc *hif_hdl)
909{
910 if (hif_napi_enabled(hif_hdl, -1))
911 return NAPI_PIPE2ID(ctx_id);
912 else
913 return ctx_id;
Komal Seelamc92a0cf2016-02-22 20:43:52 +0530914}
915
Manjunathappa Prakash2146da32016-10-13 14:47:47 -0700916#else /* !defined(FEATURE_LRO) */
917int hif_get_rx_ctx_id(int ctx_id, struct hif_opaque_softc *hif_hdl)
918{
919 return 0;
Komal Seelamc92a0cf2016-02-22 20:43:52 +0530920}
921#endif
Komal Seelam644263d2016-02-22 20:45:49 +0530922
923/**
924 * hif_get_target_status - API to get target status
925 * @hif_ctx: HIF Context
926 *
Komal Seelam6ee55902016-04-11 17:11:07 +0530927 * Return: enum hif_target_status
Komal Seelam644263d2016-02-22 20:45:49 +0530928 */
Komal Seelam6ee55902016-04-11 17:11:07 +0530929enum hif_target_status hif_get_target_status(struct hif_opaque_softc *hif_ctx)
Komal Seelam644263d2016-02-22 20:45:49 +0530930{
931 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
932
933 return scn->target_status;
934}
935
936/**
Komal Seelama5911d32016-02-24 19:21:59 +0530937 * hif_set_target_status() - API to set target status
Komal Seelam644263d2016-02-22 20:45:49 +0530938 * @hif_ctx: HIF Context
939 * @status: Target Status
940 *
941 * Return: void
942 */
Komal Seelam6ee55902016-04-11 17:11:07 +0530943void hif_set_target_status(struct hif_opaque_softc *hif_ctx, enum
944 hif_target_status status)
Komal Seelam644263d2016-02-22 20:45:49 +0530945{
946 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
947
948 scn->target_status = status;
949}
Komal Seelama5911d32016-02-24 19:21:59 +0530950
951/**
952 * hif_init_ini_config() - API to initialize HIF configuration parameters
953 * @hif_ctx: HIF Context
954 * @cfg: HIF Configuration
955 *
956 * Return: void
957 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530958void hif_init_ini_config(struct hif_opaque_softc *hif_ctx,
959 struct hif_config_info *cfg)
Komal Seelama5911d32016-02-24 19:21:59 +0530960{
961 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
962
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530963 qdf_mem_copy(&scn->hif_config, cfg, sizeof(struct hif_config_info));
Komal Seelama5911d32016-02-24 19:21:59 +0530964}
Komal Seelambd7c51d2016-02-24 10:27:30 +0530965
966/**
967 * hif_get_conparam() - API to get driver mode in HIF
968 * @scn: HIF Context
969 *
970 * Return: driver mode of operation
971 */
972uint32_t hif_get_conparam(struct hif_softc *scn)
973{
974 if (!scn)
975 return 0;
976
977 return scn->hif_con_param;
978}
979
980/**
981 * hif_get_callbacks_handle() - API to get callbacks Handle
982 * @scn: HIF Context
983 *
984 * Return: pointer to HIF Callbacks
985 */
Manikandan Mohanbd0ef8a2017-04-10 13:10:21 -0700986struct hif_driver_state_callbacks *hif_get_callbacks_handle(
987 struct hif_softc *scn)
Komal Seelambd7c51d2016-02-24 10:27:30 +0530988{
989 return &scn->callbacks;
990}
991
992/**
993 * hif_is_driver_unloading() - API to query upper layers if driver is unloading
994 * @scn: HIF Context
995 *
996 * Return: True/False
997 */
998bool hif_is_driver_unloading(struct hif_softc *scn)
999{
Komal Seelam75080122016-03-02 15:18:25 +05301000 struct hif_driver_state_callbacks *cbk = hif_get_callbacks_handle(scn);
Komal Seelambd7c51d2016-02-24 10:27:30 +05301001
1002 if (cbk && cbk->is_driver_unloading)
1003 return cbk->is_driver_unloading(cbk->context);
1004
1005 return false;
1006}
1007
1008/**
1009 * hif_is_load_or_unload_in_progress() - API to query upper layers if
1010 * load/unload in progress
1011 * @scn: HIF Context
1012 *
1013 * Return: True/False
1014 */
1015bool hif_is_load_or_unload_in_progress(struct hif_softc *scn)
1016{
Komal Seelam75080122016-03-02 15:18:25 +05301017 struct hif_driver_state_callbacks *cbk = hif_get_callbacks_handle(scn);
Komal Seelambd7c51d2016-02-24 10:27:30 +05301018
1019 if (cbk && cbk->is_load_unload_in_progress)
1020 return cbk->is_load_unload_in_progress(cbk->context);
1021
1022 return false;
1023}
1024
1025/**
Venkateswara Swamy Bandaru26f6f1e2016-10-03 19:35:57 +05301026 * hif_update_pipe_callback() - API to register pipe specific callbacks
1027 * @osc: Opaque softc
1028 * @pipeid: pipe id
1029 * @callbacks: callbacks to register
1030 *
1031 * Return: void
1032 */
1033
1034void hif_update_pipe_callback(struct hif_opaque_softc *osc,
1035 u_int8_t pipeid,
1036 struct hif_msg_callbacks *callbacks)
1037{
1038 struct hif_softc *scn = HIF_GET_SOFTC(osc);
1039 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
1040 struct HIF_CE_pipe_info *pipe_info;
1041
1042 QDF_BUG(pipeid < CE_COUNT_MAX);
1043
1044 HIF_INFO_LO("+%s pipeid %d\n", __func__, pipeid);
1045
1046 pipe_info = &hif_state->pipe_info[pipeid];
1047
1048 qdf_mem_copy(&pipe_info->pipe_callbacks,
1049 callbacks, sizeof(pipe_info->pipe_callbacks));
1050
1051 HIF_INFO_LO("-%s\n", __func__);
1052}
1053
1054/**
Komal Seelambd7c51d2016-02-24 10:27:30 +05301055 * hif_is_recovery_in_progress() - API to query upper layers if recovery in
1056 * progress
1057 * @scn: HIF Context
1058 *
1059 * Return: True/False
1060 */
1061bool hif_is_recovery_in_progress(struct hif_softc *scn)
1062{
Komal Seelam75080122016-03-02 15:18:25 +05301063 struct hif_driver_state_callbacks *cbk = hif_get_callbacks_handle(scn);
Komal Seelambd7c51d2016-02-24 10:27:30 +05301064
1065 if (cbk && cbk->is_recovery_in_progress)
1066 return cbk->is_recovery_in_progress(cbk->context);
1067
1068 return false;
1069}
Mohit Khanna440c5292016-05-12 11:05:06 -07001070#if defined(HIF_PCI) || defined(SNOC) || defined(HIF_AHB)
Houston Hoffman56e0d702016-05-05 17:48:06 -07001071/**
1072 * hif_batch_send() - API to access hif specific function
1073 * ce_batch_send.
1074 * @osc: HIF Context
1075 * @msdu : list of msdus to be sent
1076 * @transfer_id : transfer id
1077 * @len : donwloaded length
1078 *
1079 * Return: list of msds not sent
1080 */
1081qdf_nbuf_t hif_batch_send(struct hif_opaque_softc *osc, qdf_nbuf_t msdu,
1082 uint32_t transfer_id, u_int32_t len, uint32_t sendhead)
1083{
1084 void *ce_tx_hdl = hif_get_ce_handle(osc, CE_HTT_TX_CE);
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05301085
Houston Hoffman56e0d702016-05-05 17:48:06 -07001086 return ce_batch_send((struct CE_handle *)ce_tx_hdl, msdu, transfer_id,
1087 len, sendhead);
1088}
1089
1090/**
1091 * hif_update_tx_ring() - API to access hif specific function
1092 * ce_update_tx_ring.
1093 * @osc: HIF Context
1094 * @num_htt_cmpls : number of htt compl received.
1095 *
1096 * Return: void
1097 */
1098void hif_update_tx_ring(struct hif_opaque_softc *osc, u_int32_t num_htt_cmpls)
1099{
1100 void *ce_tx_hdl = hif_get_ce_handle(osc, CE_HTT_TX_CE);
Manikandan Mohanbd0ef8a2017-04-10 13:10:21 -07001101
Houston Hoffman56e0d702016-05-05 17:48:06 -07001102 ce_update_tx_ring(ce_tx_hdl, num_htt_cmpls);
1103}
1104
1105
1106/**
1107 * hif_send_single() - API to access hif specific function
1108 * ce_send_single.
1109 * @osc: HIF Context
1110 * @msdu : msdu to be sent
1111 * @transfer_id: transfer id
1112 * @len : downloaded length
1113 *
1114 * Return: msdu sent status
1115 */
1116int hif_send_single(struct hif_opaque_softc *osc, qdf_nbuf_t msdu, uint32_t
1117 transfer_id, u_int32_t len)
1118{
1119 void *ce_tx_hdl = hif_get_ce_handle(osc, CE_HTT_TX_CE);
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05301120
Houston Hoffman56e0d702016-05-05 17:48:06 -07001121 return ce_send_single((struct CE_handle *)ce_tx_hdl, msdu, transfer_id,
1122 len);
1123}
1124
1125/**
1126 * hif_send_fast() - API to access hif specific function
1127 * ce_send_fast.
1128 * @osc: HIF Context
1129 * @msdu : array of msdus to be sent
1130 * @num_msdus : number of msdus in an array
1131 * @transfer_id: transfer id
Nirav Shahda0881a2016-05-16 10:45:16 +05301132 * @download_len: download length
Houston Hoffman56e0d702016-05-05 17:48:06 -07001133 *
1134 * Return: No. of packets that could be sent
1135 */
Nirav Shahda0881a2016-05-16 10:45:16 +05301136int hif_send_fast(struct hif_opaque_softc *osc, qdf_nbuf_t nbuf,
1137 uint32_t transfer_id, uint32_t download_len)
Houston Hoffman56e0d702016-05-05 17:48:06 -07001138{
1139 void *ce_tx_hdl = hif_get_ce_handle(osc, CE_HTT_TX_CE);
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05301140
Nirav Shahda0881a2016-05-16 10:45:16 +05301141 return ce_send_fast((struct CE_handle *)ce_tx_hdl, nbuf,
1142 transfer_id, download_len);
Houston Hoffman56e0d702016-05-05 17:48:06 -07001143}
Mohit Khanna440c5292016-05-12 11:05:06 -07001144#endif
Houston Hoffman56e0d702016-05-05 17:48:06 -07001145
1146/**
1147 * hif_reg_write() - API to access hif specific function
1148 * hif_write32_mb.
1149 * @hif_ctx : HIF Context
1150 * @offset : offset on which value has to be written
1151 * @value : value to be written
1152 *
1153 * Return: None
1154 */
1155void hif_reg_write(struct hif_opaque_softc *hif_ctx, uint32_t offset,
1156 uint32_t value)
1157{
1158 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Manikandan Mohanbd0ef8a2017-04-10 13:10:21 -07001159
Houston Hoffman56e0d702016-05-05 17:48:06 -07001160 hif_write32_mb(scn->mem + offset, value);
1161
1162}
1163
1164/**
1165 * hif_reg_read() - API to access hif specific function
1166 * hif_read32_mb.
1167 * @hif_ctx : HIF Context
1168 * @offset : offset from which value has to be read
1169 *
1170 * Return: Read value
1171 */
1172uint32_t hif_reg_read(struct hif_opaque_softc *hif_ctx, uint32_t offset)
1173{
1174
1175 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Manikandan Mohanbd0ef8a2017-04-10 13:10:21 -07001176
Houston Hoffman56e0d702016-05-05 17:48:06 -07001177 return hif_read32_mb(scn->mem + offset);
1178}
Mohit Khanna440c5292016-05-12 11:05:06 -07001179
1180#if defined(HIF_USB)
1181/**
1182 * hif_ramdump_handler(): generic ramdump handler
1183 * @scn: struct hif_opaque_softc
1184 *
1185 * Return: None
1186 */
1187
1188void hif_ramdump_handler(struct hif_opaque_softc *scn)
1189
1190{
1191 if (hif_get_bus_type == QDF_BUS_TYPE_USB)
1192 hif_usb_ramdump_handler();
1193}
1194#endif
Venkateswara Swamy Bandaru31108f32016-08-08 18:04:29 +05301195
Dustin Brown2af3d672017-05-30 16:14:01 -07001196#ifdef WLAN_SUSPEND_RESUME_TEST
1197irqreturn_t hif_wake_interrupt_handler(int irq, void *context)
1198{
1199 struct hif_softc *scn = context;
1200
1201 HIF_INFO("wake interrupt received on irq %d", irq);
1202
1203 if (hif_is_ut_suspended(scn))
1204 hif_ut_fw_resume(scn);
1205
1206 return IRQ_HANDLED;
1207}
1208#else /* WLAN_SUSPEND_RESUME_TEST */
1209irqreturn_t hif_wake_interrupt_handler(int irq, void *context)
1210{
1211 HIF_INFO("wake interrupt received on irq %d", irq);
1212
1213 return IRQ_HANDLED;
1214}
1215#endif /* WLAN_SUSPEND_RESUME_TEST */