blob: 56519b063b006b264bdeb9b120ffa740ccafe61c [file] [log] [blame]
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001/*
Pratik Gandhi034cb7c2017-11-10 16:46:06 +05302 * Copyright (c) 2015-2018 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>
Pratik Gandhi034cb7c2017-11-10 16:46:06 +053036#include <target_type.h>
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080037#include "regtable.h"
38#define ATH_MODULE_NAME hif
39#include <a_debug.h>
40#include "hif_main.h"
41#include "hif_hw_version.h"
Poddar, Siddarthe41943f2016-04-27 15:33:48 +053042#if defined(HIF_PCI) || defined(HIF_SNOC) || defined(HIF_AHB)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080043#include "ce_tasklet.h"
tfyu6c7625b2017-08-10 16:20:32 +080044#include "ce_api.h"
Poddar, Siddarthe41943f2016-04-27 15:33:48 +053045#endif
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +053046#include "qdf_trace.h"
47#include "qdf_status.h"
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080048#include "hif_debug.h"
49#include "mp_dev.h"
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +053050#ifdef QCA_WIFI_QCA8074
51#include "hal_api.h"
52#endif
Manjunathappa Prakash2146da32016-10-13 14:47:47 -070053#include "hif_napi.h"
Dustin Brownccf859d2017-06-01 14:31:01 -070054#include "hif_unit_test_suspend_i.h"
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080055
Komal Seelam5584a7c2016-02-24 19:22:48 +053056void hif_dump(struct hif_opaque_softc *hif_ctx, uint8_t cmd_id, bool start)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080057{
Poddar, Siddarthe41943f2016-04-27 15:33:48 +053058 hif_trigger_dump(hif_ctx, cmd_id, start);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080059}
60
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080061/**
62 * hif_get_target_id(): hif_get_target_id
63 *
64 * Return the virtual memory base address to the caller
65 *
Komal Seelam644263d2016-02-22 20:45:49 +053066 * @scn: hif_softc
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080067 *
68 * Return: A_target_id_t
69 */
Komal Seelam644263d2016-02-22 20:45:49 +053070A_target_id_t hif_get_target_id(struct hif_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080071{
72 return scn->mem;
73}
74
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080075/**
76 * hif_get_targetdef(): hif_get_targetdef
77 * @scn: scn
78 *
79 * Return: void *
80 */
Komal Seelam5584a7c2016-02-24 19:22:48 +053081void *hif_get_targetdef(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080082{
Komal Seelam644263d2016-02-22 20:45:49 +053083 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
84
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080085 return scn->targetdef;
86}
87
88/**
89 * hif_vote_link_down(): unvote for link up
90 *
91 * Call hif_vote_link_down to release a previous request made using
92 * hif_vote_link_up. A hif_vote_link_down call should only be made
93 * after a corresponding hif_vote_link_up, otherwise you could be
94 * negating a vote from another source. When no votes are present
95 * hif will not guarantee the linkstate after hif_bus_suspend.
96 *
97 * SYNCHRONIZE WITH hif_vote_link_up by only calling in MC thread
98 * and initialization deinitialization sequencences.
99 *
100 * Return: n/a
101 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530102void hif_vote_link_down(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800103{
Komal Seelam644263d2016-02-22 20:45:49 +0530104 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800105
Manikandan Mohanbd0ef8a2017-04-10 13:10:21 -0700106 QDF_BUG(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800107 scn->linkstate_vote--;
108 if (scn->linkstate_vote == 0)
Houston Hoffmancceec342015-11-11 11:37:20 -0800109 hif_bus_prevent_linkdown(scn, false);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800110}
111
112/**
113 * hif_vote_link_up(): vote to prevent bus from suspending
114 *
115 * Makes hif guarantee that fw can message the host normally
116 * durring suspend.
117 *
118 * SYNCHRONIZE WITH hif_vote_link_up by only calling in MC thread
119 * and initialization deinitialization sequencences.
120 *
121 * Return: n/a
122 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530123void hif_vote_link_up(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800124{
Komal Seelam644263d2016-02-22 20:45:49 +0530125 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800126
Manikandan Mohanbd0ef8a2017-04-10 13:10:21 -0700127 QDF_BUG(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800128 scn->linkstate_vote++;
129 if (scn->linkstate_vote == 1)
Houston Hoffmancceec342015-11-11 11:37:20 -0800130 hif_bus_prevent_linkdown(scn, true);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800131}
132
133/**
134 * hif_can_suspend_link(): query if hif is permitted to suspend the link
135 *
136 * Hif will ensure that the link won't be suspended if the upperlayers
137 * don't want it to.
138 *
139 * SYNCHRONIZATION: MC thread is stopped before bus suspend thus
140 * we don't need extra locking to ensure votes dont change while
141 * we are in the process of suspending or resuming.
142 *
143 * Return: false if hif will guarantee link up durring suspend.
144 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530145bool hif_can_suspend_link(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800146{
Komal Seelam644263d2016-02-22 20:45:49 +0530147 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800148
Manikandan Mohanbd0ef8a2017-04-10 13:10:21 -0700149 QDF_BUG(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800150 return scn->linkstate_vote == 0;
151}
152
153/**
154 * hif_hia_item_address(): hif_hia_item_address
155 * @target_type: target_type
156 * @item_offset: item_offset
157 *
158 * Return: n/a
159 */
160uint32_t hif_hia_item_address(uint32_t target_type, uint32_t item_offset)
161{
162 switch (target_type) {
163 case TARGET_TYPE_AR6002:
164 return AR6002_HOST_INTEREST_ADDRESS + item_offset;
165 case TARGET_TYPE_AR6003:
166 return AR6003_HOST_INTEREST_ADDRESS + item_offset;
167 case TARGET_TYPE_AR6004:
168 return AR6004_HOST_INTEREST_ADDRESS + item_offset;
169 case TARGET_TYPE_AR6006:
170 return AR6006_HOST_INTEREST_ADDRESS + item_offset;
171 case TARGET_TYPE_AR9888:
172 return AR9888_HOST_INTEREST_ADDRESS + item_offset;
173 case TARGET_TYPE_AR6320:
174 case TARGET_TYPE_AR6320V2:
175 return AR6320_HOST_INTEREST_ADDRESS + item_offset;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800176 case TARGET_TYPE_ADRASTEA:
177 /* ADRASTEA doesn't have a host interest address */
178 ASSERT(0);
179 return 0;
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700180 case TARGET_TYPE_AR900B:
181 return AR900B_HOST_INTEREST_ADDRESS + item_offset;
182 case TARGET_TYPE_QCA9984:
183 return QCA9984_HOST_INTEREST_ADDRESS + item_offset;
184 case TARGET_TYPE_QCA9888:
185 return QCA9888_HOST_INTEREST_ADDRESS + item_offset;
186 case TARGET_TYPE_IPQ4019:
187 return IPQ4019_HOST_INTEREST_ADDRESS + item_offset;
188
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800189 default:
190 ASSERT(0);
191 return 0;
192 }
193}
194
195/**
196 * hif_max_num_receives_reached() - check max receive is reached
Komal Seelambd7c51d2016-02-24 10:27:30 +0530197 * @scn: HIF Context
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800198 * @count: unsigned int.
199 *
200 * Output check status as bool
201 *
202 * Return: bool
203 */
Komal Seelambd7c51d2016-02-24 10:27:30 +0530204bool hif_max_num_receives_reached(struct hif_softc *scn, unsigned int count)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800205{
Houston Hoffman75ef5a52016-04-14 17:15:49 -0700206 if (QDF_IS_EPPING_ENABLED(hif_get_conparam(scn)))
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800207 return count > 120;
208 else
209 return count > MAX_NUM_OF_RECEIVES;
210}
211
212/**
213 * init_buffer_count() - initial buffer count
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530214 * @maxSize: qdf_size_t
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800215 *
216 * routine to modify the initial buffer count to be allocated on an os
217 * platform basis. Platform owner will need to modify this as needed
218 *
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530219 * Return: qdf_size_t
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800220 */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530221qdf_size_t init_buffer_count(qdf_size_t maxSize)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800222{
223 return maxSize;
224}
225
226/**
Nirav Shahd7f91592016-04-21 14:18:43 +0530227 * hif_save_htc_htt_config_endpoint() - save htt_tx_endpoint
228 * @hif_ctx: hif context
229 * @htc_htt_tx_endpoint: htt_tx_endpoint
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800230 *
231 * Return: void
232 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530233void hif_save_htc_htt_config_endpoint(struct hif_opaque_softc *hif_ctx,
Nirav Shahd7f91592016-04-21 14:18:43 +0530234 int htc_htt_tx_endpoint)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800235{
Komal Seelam644263d2016-02-22 20:45:49 +0530236 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800237
238 if (!scn) {
239 HIF_ERROR("%s: error: scn or scn->hif_sc is NULL!",
240 __func__);
241 return;
242 }
243
Nirav Shahd7f91592016-04-21 14:18:43 +0530244 scn->htc_htt_tx_endpoint = htc_htt_tx_endpoint;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800245}
246
Houston Hoffmanec93ab02016-05-03 20:09:55 -0700247static const struct qwlan_hw qwlan_hw_list[] = {
248 {
249 .id = AR6320_REV1_VERSION,
250 .subid = 0,
251 .name = "QCA6174_REV1",
252 },
253 {
254 .id = AR6320_REV1_1_VERSION,
255 .subid = 0x1,
256 .name = "QCA6174_REV1_1",
257 },
258 {
259 .id = AR6320_REV1_3_VERSION,
260 .subid = 0x2,
261 .name = "QCA6174_REV1_3",
262 },
263 {
264 .id = AR6320_REV2_1_VERSION,
265 .subid = 0x4,
266 .name = "QCA6174_REV2_1",
267 },
268 {
269 .id = AR6320_REV2_1_VERSION,
270 .subid = 0x5,
271 .name = "QCA6174_REV2_2",
272 },
273 {
274 .id = AR6320_REV3_VERSION,
275 .subid = 0x6,
276 .name = "QCA6174_REV2.3",
277 },
278 {
279 .id = AR6320_REV3_VERSION,
280 .subid = 0x8,
281 .name = "QCA6174_REV3",
282 },
283 {
284 .id = AR6320_REV3_VERSION,
285 .subid = 0x9,
286 .name = "QCA6174_REV3_1",
287 },
288 {
289 .id = AR6320_REV3_2_VERSION,
290 .subid = 0xA,
291 .name = "AR6320_REV3_2_VERSION",
Houston Hoffmancd0884a2016-08-24 15:30:09 -0700292 },
293 {
294 .id = WCN3990_v1,
295 .subid = 0x0,
296 .name = "WCN3990_V1",
Houston Hoffmandd4da482016-10-17 12:41:45 -0700297 },
298 {
299 .id = WCN3990_v2,
300 .subid = 0x0,
301 .name = "WCN3990_V2",
Houston Hoffman59fd2452016-11-19 17:27:10 -0800302 },
303 {
304 .id = WCN3990_v2_1,
305 .subid = 0x0,
306 .name = "WCN3990_V2.1",
Yingying Tangd8921742016-10-18 18:13:07 +0800307 },
308 {
309 .id = QCA9379_REV1_VERSION,
310 .subid = 0xC,
311 .name = "QCA9379_REV1",
Yingying Tang80404362016-10-20 23:29:57 +0800312 },
313 {
314 .id = QCA9379_REV1_VERSION,
315 .subid = 0xD,
316 .name = "QCA9379_REV1_1",
Houston Hoffmanec93ab02016-05-03 20:09:55 -0700317 }
318};
319
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800320/**
321 * hif_get_hw_name(): get a human readable name for the hardware
Komal Seelam91553ce2016-01-27 18:57:10 +0530322 * @info: Target Info
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800323 *
Komal Seelam91553ce2016-01-27 18:57:10 +0530324 * Return: human readable name for the underlying wifi hardware.
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800325 */
Komal Seelam91553ce2016-01-27 18:57:10 +0530326static const char *hif_get_hw_name(struct hif_target_info *info)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800327{
328 int i;
Komal Seelam91553ce2016-01-27 18:57:10 +0530329
Houston Hoffman60af6752016-11-21 12:13:36 -0800330 if (info->hw_name)
331 return info->hw_name;
332
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800333 for (i = 0; i < ARRAY_SIZE(qwlan_hw_list); i++) {
Komal Seelam91553ce2016-01-27 18:57:10 +0530334 if (info->target_version == qwlan_hw_list[i].id &&
335 info->target_revision == qwlan_hw_list[i].subid) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800336 return qwlan_hw_list[i].name;
337 }
338 }
339
Houston Hoffman60af6752016-11-21 12:13:36 -0800340 info->hw_name = qdf_mem_malloc(64);
341 if (!info->hw_name)
342 return "Unknown Device (nomem)";
343
344 i = qdf_snprint(info->hw_name, 64, "HW_VERSION=%x.",
345 info->target_version);
346 if (i < 0)
347 return "Unknown Device (snprintf failure)";
348 else
349 return info->hw_name;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800350}
351
352/**
353 * hif_get_hw_info(): hif_get_hw_info
354 * @scn: scn
355 * @version: version
356 * @revision: revision
357 *
358 * Return: n/a
359 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530360void hif_get_hw_info(struct hif_opaque_softc *scn, u32 *version, u32 *revision,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800361 const char **target_name)
362{
Komal Seelam91553ce2016-01-27 18:57:10 +0530363 struct hif_target_info *info = hif_get_target_info_handle(scn);
Mohit Khanna440c5292016-05-12 11:05:06 -0700364 struct hif_softc *sc = HIF_GET_SOFTC(scn);
365
366 if (sc->bus_type == QDF_BUS_TYPE_USB)
367 hif_usb_get_hw_info(sc);
368
Komal Seelam91553ce2016-01-27 18:57:10 +0530369 *version = info->target_version;
370 *revision = info->target_revision;
371 *target_name = hif_get_hw_name(info);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800372}
373
374/**
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530375 * hif_get_dev_ba(): API to get device base address.
376 * @scn: scn
377 * @version: version
378 * @revision: revision
379 *
380 * Return: n/a
381 */
382void *hif_get_dev_ba(struct hif_opaque_softc *hif_handle)
383{
384 struct hif_softc *scn = (struct hif_softc *)hif_handle;
385
386 return scn->mem;
387}
388/**
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800389 * hif_open(): hif_open
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530390 * @qdf_ctx: QDF Context
Komal Seelambd7c51d2016-02-24 10:27:30 +0530391 * @mode: Driver Mode
392 * @bus_type: Bus Type
393 * @cbk: CDS Callbacks
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800394 *
Komal Seelambd7c51d2016-02-24 10:27:30 +0530395 * API to open HIF Context
396 *
397 * Return: HIF Opaque Pointer
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800398 */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530399struct hif_opaque_softc *hif_open(qdf_device_t qdf_ctx, uint32_t mode,
400 enum qdf_bus_type bus_type,
Komal Seelam75080122016-03-02 15:18:25 +0530401 struct hif_driver_state_callbacks *cbk)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800402{
Komal Seelam644263d2016-02-22 20:45:49 +0530403 struct hif_softc *scn;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530404 QDF_STATUS status = QDF_STATUS_SUCCESS;
Houston Hoffman162164c2016-03-14 21:12:10 -0700405 int bus_context_size = hif_bus_get_context_size(bus_type);
406
407 if (bus_context_size == 0) {
408 HIF_ERROR("%s: context size 0 not allowed", __func__);
409 return NULL;
410 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800411
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530412 scn = (struct hif_softc *)qdf_mem_malloc(bus_context_size);
Komal Seelambd7c51d2016-02-24 10:27:30 +0530413 if (!scn) {
414 HIF_ERROR("%s: cannot alloc memory for HIF context of size:%d",
415 __func__, bus_context_size);
416 return GET_HIF_OPAQUE_HDL(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800417 }
418
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530419 scn->qdf_dev = qdf_ctx;
Komal Seelambd7c51d2016-02-24 10:27:30 +0530420 scn->hif_con_param = mode;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530421 qdf_atomic_init(&scn->active_tasklet_cnt);
Venkateswara Swamy Bandaru31108f32016-08-08 18:04:29 +0530422 qdf_atomic_init(&scn->active_grp_tasklet_cnt);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530423 qdf_atomic_init(&scn->link_suspended);
424 qdf_atomic_init(&scn->tasklet_from_intr);
Manikandan Mohanbd0ef8a2017-04-10 13:10:21 -0700425 qdf_mem_copy(&scn->callbacks, cbk,
426 sizeof(struct hif_driver_state_callbacks));
Houston Hoffman3db96a42016-05-05 19:54:39 -0700427 scn->bus_type = bus_type;
Houston Hoffman3cfe6862016-01-08 10:33:55 -0800428 status = hif_bus_open(scn, bus_type);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530429 if (status != QDF_STATUS_SUCCESS) {
Houston Hoffman3cfe6862016-01-08 10:33:55 -0800430 HIF_ERROR("%s: hif_bus_open error = %d, bus_type = %d",
431 __func__, status, bus_type);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530432 qdf_mem_free(scn);
Komal Seelambd7c51d2016-02-24 10:27:30 +0530433 scn = NULL;
Houston Hoffman3cfe6862016-01-08 10:33:55 -0800434 }
435
Komal Seelambd7c51d2016-02-24 10:27:30 +0530436 return GET_HIF_OPAQUE_HDL(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800437}
438
439/**
440 * hif_close(): hif_close
441 * @hif_ctx: hif_ctx
442 *
443 * Return: n/a
444 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530445void hif_close(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800446{
Komal Seelam644263d2016-02-22 20:45:49 +0530447 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800448
449 if (scn == NULL) {
Komal Seelam5584a7c2016-02-24 19:22:48 +0530450 HIF_ERROR("%s: hif_opaque_softc is NULL", __func__);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800451 return;
452 }
453
454 if (scn->athdiag_procfs_inited) {
455 athdiag_procfs_remove();
456 scn->athdiag_procfs_inited = false;
457 }
458
Houston Hoffman60af6752016-11-21 12:13:36 -0800459 if (scn->target_info.hw_name) {
460 char *hw_name = scn->target_info.hw_name;
Manikandan Mohanbd0ef8a2017-04-10 13:10:21 -0700461
Houston Hoffman60af6752016-11-21 12:13:36 -0800462 scn->target_info.hw_name = "ErrUnloading";
463 qdf_mem_free(hw_name);
464 }
465
Arunk Khandavallie14e8e92017-04-03 21:40:26 +0530466 if (scn->vaddr_rri_on_ddr)
467 qdf_mem_free_consistent(scn->qdf_dev, scn->qdf_dev->dev,
468 (CE_COUNT*sizeof(uint32_t)),
469 scn->vaddr_rri_on_ddr, scn->paddr_rri_on_ddr,
470 0);
471
472 scn->vaddr_rri_on_ddr = NULL;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800473 hif_bus_close(scn);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530474 qdf_mem_free(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800475}
476
Houston Hoffman6fe60592016-11-18 13:12:08 -0800477#ifdef QCA_WIFI_QCA8074
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530478static QDF_STATUS hif_hal_attach(struct hif_softc *scn)
479{
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530480 if (ce_srng_based(scn)) {
481 scn->hal_soc = hal_attach(scn, scn->qdf_dev);
482 if (scn->hal_soc == NULL)
483 return QDF_STATUS_E_FAILURE;
484 }
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530485
486 return QDF_STATUS_SUCCESS;
487}
Houston Hoffman4e2df402017-05-21 19:36:56 -0700488
489static QDF_STATUS hif_hal_detach(struct hif_softc *scn)
490{
491 if (ce_srng_based(scn)) {
492 hal_detach(scn->hal_soc);
493 scn->hal_soc = NULL;
494 }
495
496 return QDF_STATUS_SUCCESS;
497}
Houston Hoffman6fe60592016-11-18 13:12:08 -0800498#else
499static QDF_STATUS hif_hal_attach(struct hif_softc *scn)
500{
501 return QDF_STATUS_SUCCESS;
502}
Houston Hoffman4e2df402017-05-21 19:36:56 -0700503
504static QDF_STATUS hif_hal_detach(struct hif_softc *scn)
505{
506 return QDF_STATUS_SUCCESS;
507}
Houston Hoffman6fe60592016-11-18 13:12:08 -0800508#endif
509
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800510/**
511 * hif_enable(): hif_enable
512 * @hif_ctx: hif_ctx
513 * @dev: dev
514 * @bdev: bus dev
515 * @bid: bus ID
516 * @bus_type: bus type
517 * @type: enable type
518 *
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530519 * Return: QDF_STATUS
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800520 */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530521QDF_STATUS hif_enable(struct hif_opaque_softc *hif_ctx, struct device *dev,
Manikandan Mohanbd0ef8a2017-04-10 13:10:21 -0700522 void *bdev,
523 const struct hif_bus_id *bid,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530524 enum qdf_bus_type bus_type,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800525 enum hif_enable_type type)
526{
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530527 QDF_STATUS status;
Komal Seelam644263d2016-02-22 20:45:49 +0530528 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800529
530 if (scn == NULL) {
531 HIF_ERROR("%s: hif_ctx = NULL", __func__);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530532 return QDF_STATUS_E_NULL_VALUE;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800533 }
534
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800535 status = hif_enable_bus(scn, dev, bdev, bid, type);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530536 if (status != QDF_STATUS_SUCCESS) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800537 HIF_ERROR("%s: hif_enable_bus error = %d",
538 __func__, status);
539 return status;
540 }
541
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530542 status = hif_hal_attach(scn);
543 if (status != QDF_STATUS_SUCCESS) {
544 HIF_ERROR("%s: hal attach failed", __func__);
Houston Hoffman4e2df402017-05-21 19:36:56 -0700545 goto disable_bus;
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530546 }
547
Houston Hoffman108da402016-03-14 21:11:24 -0700548 if (hif_bus_configure(scn)) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800549 HIF_ERROR("%s: Target probe failed.", __func__);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530550 status = QDF_STATUS_E_FAILURE;
Houston Hoffman4e2df402017-05-21 19:36:56 -0700551 goto hal_detach;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800552 }
Houston Hoffman108da402016-03-14 21:11:24 -0700553
Dustin Brownccf859d2017-06-01 14:31:01 -0700554 hif_ut_suspend_init(scn);
555
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800556 /*
557 * Flag to avoid potential unallocated memory access from MSI
558 * interrupt handler which could get scheduled as soon as MSI
559 * is enabled, i.e to take care of the race due to the order
560 * in where MSI is enabled before the memory, that will be
561 * in interrupt handlers, is allocated.
562 */
563
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800564 scn->hif_init_done = true;
565
Srinivas Girigowda6e0cfd92017-03-09 15:49:59 -0800566 HIF_DBG("%s: OK", __func__);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800567
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530568 return QDF_STATUS_SUCCESS;
Houston Hoffman4e2df402017-05-21 19:36:56 -0700569
570hal_detach:
571 hif_hal_detach(scn);
572disable_bus:
573 hif_disable_bus(scn);
574 return status;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800575}
576
Komal Seelam5584a7c2016-02-24 19:22:48 +0530577void hif_disable(struct hif_opaque_softc *hif_ctx, enum hif_disable_type type)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800578{
Komal Seelam644263d2016-02-22 20:45:49 +0530579 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800580
581 if (!scn)
582 return;
583
584 hif_nointrs(scn);
585 if (scn->hif_init_done == false)
Poddar, Siddarthe41943f2016-04-27 15:33:48 +0530586 hif_shutdown_device(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800587 else
Komal Seelam644263d2016-02-22 20:45:49 +0530588 hif_stop(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800589
Houston Hoffman4e2df402017-05-21 19:36:56 -0700590 hif_hal_detach(scn);
591
Vishwajith Upendra3f78aa62016-02-09 17:53:02 +0530592 hif_disable_bus(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800593
Komal Seelambd7c51d2016-02-24 10:27:30 +0530594 hif_wlan_disable(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800595
596 scn->notice_send = false;
597
Srinivas Girigowda6e0cfd92017-03-09 15:49:59 -0800598 HIF_DBG("%s: X", __func__);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800599}
600
Nirav Shahb70bd732016-05-25 14:31:51 +0530601void hif_display_stats(struct hif_opaque_softc *hif_ctx)
602{
603 hif_display_bus_stats(hif_ctx);
604}
605
606void hif_clear_stats(struct hif_opaque_softc *hif_ctx)
607{
608 hif_clear_bus_stats(hif_ctx);
609}
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800610
611/**
Govind Singh2443fb32016-01-13 17:44:48 +0530612 * hif_crash_shutdown_dump_bus_register() - dump bus registers
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800613 * @hif_ctx: hif_ctx
614 *
615 * Return: n/a
616 */
617#if defined(TARGET_RAMDUMP_AFTER_KERNEL_PANIC) \
Houston Hoffmanbc693492016-03-14 21:11:41 -0700618&& defined(DEBUG)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800619
Govind Singh2443fb32016-01-13 17:44:48 +0530620static void hif_crash_shutdown_dump_bus_register(void *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800621{
Komal Seelam5584a7c2016-02-24 19:22:48 +0530622 struct hif_opaque_softc *scn = hif_ctx;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800623
Govind Singh2443fb32016-01-13 17:44:48 +0530624 if (hif_check_soc_status(scn))
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800625 return;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800626
Govind Singh2443fb32016-01-13 17:44:48 +0530627 if (hif_dump_registers(scn))
628 HIF_ERROR("Failed to dump bus registers!");
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800629}
630
631/**
632 * hif_crash_shutdown(): hif_crash_shutdown
633 *
634 * This function is called by the platform driver to dump CE registers
635 *
636 * @hif_ctx: hif_ctx
637 *
638 * Return: n/a
639 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530640void hif_crash_shutdown(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800641{
Komal Seelam644263d2016-02-22 20:45:49 +0530642 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800643
Houston Hoffmanbc693492016-03-14 21:11:41 -0700644 if (!hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800645 return;
646
Houston Hoffmanbc693492016-03-14 21:11:41 -0700647 if (scn->bus_type == QDF_BUS_TYPE_SNOC) {
648 HIF_INFO_MED("%s: RAM dump disabled for bustype %d",
649 __func__, scn->bus_type);
650 return;
651 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800652
Komal Seelam6ee55902016-04-11 17:11:07 +0530653 if (TARGET_STATUS_RESET == scn->target_status) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800654 HIF_INFO_MED("%s: Target is already asserted, ignore!",
655 __func__);
656 return;
657 }
658
Komal Seelambd7c51d2016-02-24 10:27:30 +0530659 if (hif_is_load_or_unload_in_progress(scn)) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800660 HIF_ERROR("%s: Load/unload is in progress, ignore!", __func__);
661 return;
662 }
663
Govind Singh2443fb32016-01-13 17:44:48 +0530664 hif_crash_shutdown_dump_bus_register(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800665
Komal Seelam644263d2016-02-22 20:45:49 +0530666 if (ol_copy_ramdump(hif_ctx))
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800667 goto out;
668
669 HIF_INFO_MED("%s: RAM dump collecting completed!", __func__);
670
671out:
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800672 return;
673}
674#else
Komal Seelam5584a7c2016-02-24 19:22:48 +0530675void hif_crash_shutdown(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800676{
677 HIF_INFO_MED("%s: Collecting target RAM dump disabled",
678 __func__);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800679}
680#endif /* TARGET_RAMDUMP_AFTER_KERNEL_PANIC */
681
682#ifdef QCA_WIFI_3_0
683/**
684 * hif_check_fw_reg(): hif_check_fw_reg
685 * @scn: scn
686 * @state:
687 *
688 * Return: int
689 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530690int hif_check_fw_reg(struct hif_opaque_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800691{
692 return 0;
693}
694#endif
695
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800696/**
697 * hif_read_phy_mem_base(): hif_read_phy_mem_base
698 * @scn: scn
699 * @phy_mem_base: physical mem base
700 *
701 * Return: n/a
702 */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530703void hif_read_phy_mem_base(struct hif_softc *scn, qdf_dma_addr_t *phy_mem_base)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800704{
705 *phy_mem_base = scn->mem_pa;
706}
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800707
708/**
709 * hif_get_device_type(): hif_get_device_type
710 * @device_id: device_id
711 * @revision_id: revision_id
712 * @hif_type: returned hif_type
713 * @target_type: returned target_type
714 *
715 * Return: int
716 */
717int hif_get_device_type(uint32_t device_id,
718 uint32_t revision_id,
719 uint32_t *hif_type, uint32_t *target_type)
720{
721 int ret = 0;
722
723 switch (device_id) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800724 case ADRASTEA_DEVICE_ID_P2_E12:
725
726 *hif_type = HIF_TYPE_ADRASTEA;
727 *target_type = TARGET_TYPE_ADRASTEA;
728 break;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800729
730 case AR9888_DEVICE_ID:
731 *hif_type = HIF_TYPE_AR9888;
732 *target_type = TARGET_TYPE_AR9888;
733 break;
734
735 case AR6320_DEVICE_ID:
736 switch (revision_id) {
737 case AR6320_FW_1_1:
738 case AR6320_FW_1_3:
739 *hif_type = HIF_TYPE_AR6320;
740 *target_type = TARGET_TYPE_AR6320;
741 break;
742
743 case AR6320_FW_2_0:
744 case AR6320_FW_3_0:
745 case AR6320_FW_3_2:
746 *hif_type = HIF_TYPE_AR6320V2;
747 *target_type = TARGET_TYPE_AR6320V2;
748 break;
749
750 default:
751 HIF_ERROR("%s: error - dev_id = 0x%x, rev_id = 0x%x",
752 __func__, device_id, revision_id);
753 ret = -ENODEV;
754 goto end;
755 }
756 break;
757
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700758 case AR9887_DEVICE_ID:
759 *hif_type = HIF_TYPE_AR9888;
760 *target_type = TARGET_TYPE_AR9888;
Houston Hoffmanc50572b2016-06-08 19:49:46 -0700761 HIF_INFO(" *********** AR9887 **************");
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700762 break;
763
764 case QCA9984_DEVICE_ID:
765 *hif_type = HIF_TYPE_QCA9984;
766 *target_type = TARGET_TYPE_QCA9984;
Houston Hoffmanc50572b2016-06-08 19:49:46 -0700767 HIF_INFO(" *********** QCA9984 *************");
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700768 break;
769
770 case QCA9888_DEVICE_ID:
771 *hif_type = HIF_TYPE_QCA9888;
772 *target_type = TARGET_TYPE_QCA9888;
Houston Hoffmanc50572b2016-06-08 19:49:46 -0700773 HIF_INFO(" *********** QCA9888 *************");
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700774 break;
775
776 case AR900B_DEVICE_ID:
777 *hif_type = HIF_TYPE_AR900B;
778 *target_type = TARGET_TYPE_AR900B;
Houston Hoffmanc50572b2016-06-08 19:49:46 -0700779 HIF_INFO(" *********** AR900B *************");
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700780 break;
781
Houston Hoffman3db96a42016-05-05 19:54:39 -0700782 case IPQ4019_DEVICE_ID:
783 *hif_type = HIF_TYPE_IPQ4019;
784 *target_type = TARGET_TYPE_IPQ4019;
Houston Hoffmanc50572b2016-06-08 19:49:46 -0700785 HIF_INFO(" *********** IPQ4019 *************");
Houston Hoffman3db96a42016-05-05 19:54:39 -0700786 break;
787
Venkateswara Swamy Bandaru9fd9af02016-09-20 20:27:31 +0530788 case QCA8074_DEVICE_ID:
Karunakar Dasinenif61cb072016-09-29 11:50:45 -0700789 case RUMIM2M_DEVICE_ID_NODE0:
790 case RUMIM2M_DEVICE_ID_NODE1:
Sathish Kumar2d2f19a2017-02-13 15:52:07 +0530791 case RUMIM2M_DEVICE_ID_NODE2:
792 case RUMIM2M_DEVICE_ID_NODE3:
Venkateswara Swamy Bandaru9fd9af02016-09-20 20:27:31 +0530793 *hif_type = HIF_TYPE_QCA8074;
794 *target_type = TARGET_TYPE_QCA8074;
795 HIF_INFO(" *********** QCA8074 *************\n");
796 break;
797
Houston Hoffman31b25ec2016-09-19 13:12:30 -0700798 case QCA6290_EMULATION_DEVICE_ID:
Houston Hoffman14f621c2017-05-01 10:35:50 -0700799 case QCA6290_DEVICE_ID:
Houston Hoffman31b25ec2016-09-19 13:12:30 -0700800 *hif_type = HIF_TYPE_QCA6290;
801 *target_type = TARGET_TYPE_QCA6290;
802 HIF_INFO(" *********** QCA6290EMU *************\n");
803 break;
804
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800805 default:
806 HIF_ERROR("%s: Unsupported device ID!", __func__);
807 ret = -ENODEV;
808 break;
809 }
Houston Hoffman817ff7f2017-07-13 14:03:28 -0700810
811 if (*target_type == TARGET_TYPE_UNKNOWN) {
812 HIF_ERROR("%s: Unsupported target_type!", __func__);
813 ret = -ENODEV;
814 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800815end:
816 return ret;
817}
Komal Seelam91553ce2016-01-27 18:57:10 +0530818
819/**
Houston Hoffman26352592016-03-14 21:11:43 -0700820 * hif_needs_bmi() - return true if the soc needs bmi through the driver
821 * @hif_ctx: hif context
822 *
823 * Return: true if the soc needs driver bmi otherwise false
824 */
825bool hif_needs_bmi(struct hif_opaque_softc *hif_ctx)
826{
827 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
Pratik Gandhi815c6d82016-10-19 12:06:32 +0530828
Houston Hoffman6c0c3f92016-09-27 18:05:39 -0700829 return (hif_sc->bus_type != QDF_BUS_TYPE_SNOC) &&
830 !ce_srng_based(hif_sc);
Houston Hoffman26352592016-03-14 21:11:43 -0700831}
832
833/**
Houston Hoffman60a1eeb2016-03-14 21:11:44 -0700834 * hif_get_bus_type() - return the bus type
835 *
836 * Return: enum qdf_bus_type
837 */
838enum qdf_bus_type hif_get_bus_type(struct hif_opaque_softc *hif_hdl)
839{
840 struct hif_softc *scn = HIF_GET_SOFTC(hif_hdl);
Manikandan Mohanbd0ef8a2017-04-10 13:10:21 -0700841
Houston Hoffman60a1eeb2016-03-14 21:11:44 -0700842 return scn->bus_type;
843}
844
845/**
Komal Seelam91553ce2016-01-27 18:57:10 +0530846 * Target info and ini parameters are global to the driver
847 * Hence these structures are exposed to all the modules in
848 * the driver and they don't need to maintains multiple copies
849 * of the same info, instead get the handle from hif and
850 * modify them in hif
851 */
852
853/**
854 * hif_get_ini_handle() - API to get hif_config_param handle
Komal Seelam644263d2016-02-22 20:45:49 +0530855 * @hif_ctx: HIF Context
Komal Seelam91553ce2016-01-27 18:57:10 +0530856 *
857 * Return: pointer to hif_config_info
858 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530859struct hif_config_info *hif_get_ini_handle(struct hif_opaque_softc *hif_ctx)
Komal Seelam91553ce2016-01-27 18:57:10 +0530860{
Komal Seelam644263d2016-02-22 20:45:49 +0530861 struct hif_softc *sc = HIF_GET_SOFTC(hif_ctx);
862
863 return &sc->hif_config;
Komal Seelam91553ce2016-01-27 18:57:10 +0530864}
865
866/**
867 * hif_get_target_info_handle() - API to get hif_target_info handle
Komal Seelam644263d2016-02-22 20:45:49 +0530868 * @hif_ctx: HIF context
Komal Seelam91553ce2016-01-27 18:57:10 +0530869 *
870 * Return: Pointer to hif_target_info
871 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530872struct hif_target_info *hif_get_target_info_handle(
873 struct hif_opaque_softc *hif_ctx)
Komal Seelam91553ce2016-01-27 18:57:10 +0530874{
Komal Seelam644263d2016-02-22 20:45:49 +0530875 struct hif_softc *sc = HIF_GET_SOFTC(hif_ctx);
876
877 return &sc->target_info;
878
Komal Seelam91553ce2016-01-27 18:57:10 +0530879}
Komal Seelamc92a0cf2016-02-22 20:43:52 +0530880
881#if defined(FEATURE_LRO)
Manjunathappa Prakash2146da32016-10-13 14:47:47 -0700882
883/**
884 * hif_get_lro_info - Returns LRO instance for instance ID
885 * @ctx_id: LRO instance ID
886 * @hif_hdl: HIF Context
887 *
888 * Return: Pointer to LRO instance.
889 */
890void *hif_get_lro_info(int ctx_id, struct hif_opaque_softc *hif_hdl)
891{
892 void *data;
893
894 if (hif_napi_enabled(hif_hdl, -1))
895 data = hif_napi_get_lro_info(hif_hdl, ctx_id);
896 else
897 data = hif_ce_get_lro_ctx(hif_hdl, ctx_id);
898
899 return data;
900}
901
902/**
903 * hif_get_rx_ctx_id - Returns LRO instance ID based on underlying LRO instance
904 * @ctx_id: LRO context ID
905 * @hif_hdl: HIF Context
906 *
907 * Return: LRO instance ID
908 */
909int hif_get_rx_ctx_id(int ctx_id, struct hif_opaque_softc *hif_hdl)
910{
911 if (hif_napi_enabled(hif_hdl, -1))
912 return NAPI_PIPE2ID(ctx_id);
913 else
914 return ctx_id;
Komal Seelamc92a0cf2016-02-22 20:43:52 +0530915}
916
Manjunathappa Prakash2146da32016-10-13 14:47:47 -0700917#else /* !defined(FEATURE_LRO) */
918int hif_get_rx_ctx_id(int ctx_id, struct hif_opaque_softc *hif_hdl)
919{
920 return 0;
Komal Seelamc92a0cf2016-02-22 20:43:52 +0530921}
922#endif
Komal Seelam644263d2016-02-22 20:45:49 +0530923
924/**
925 * hif_get_target_status - API to get target status
926 * @hif_ctx: HIF Context
927 *
Komal Seelam6ee55902016-04-11 17:11:07 +0530928 * Return: enum hif_target_status
Komal Seelam644263d2016-02-22 20:45:49 +0530929 */
Komal Seelam6ee55902016-04-11 17:11:07 +0530930enum hif_target_status hif_get_target_status(struct hif_opaque_softc *hif_ctx)
Komal Seelam644263d2016-02-22 20:45:49 +0530931{
932 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
933
934 return scn->target_status;
935}
936
937/**
Komal Seelama5911d32016-02-24 19:21:59 +0530938 * hif_set_target_status() - API to set target status
Komal Seelam644263d2016-02-22 20:45:49 +0530939 * @hif_ctx: HIF Context
940 * @status: Target Status
941 *
942 * Return: void
943 */
Komal Seelam6ee55902016-04-11 17:11:07 +0530944void hif_set_target_status(struct hif_opaque_softc *hif_ctx, enum
945 hif_target_status status)
Komal Seelam644263d2016-02-22 20:45:49 +0530946{
947 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
948
949 scn->target_status = status;
950}
Komal Seelama5911d32016-02-24 19:21:59 +0530951
952/**
953 * hif_init_ini_config() - API to initialize HIF configuration parameters
954 * @hif_ctx: HIF Context
955 * @cfg: HIF Configuration
956 *
957 * Return: void
958 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530959void hif_init_ini_config(struct hif_opaque_softc *hif_ctx,
960 struct hif_config_info *cfg)
Komal Seelama5911d32016-02-24 19:21:59 +0530961{
962 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
963
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530964 qdf_mem_copy(&scn->hif_config, cfg, sizeof(struct hif_config_info));
Komal Seelama5911d32016-02-24 19:21:59 +0530965}
Komal Seelambd7c51d2016-02-24 10:27:30 +0530966
967/**
968 * hif_get_conparam() - API to get driver mode in HIF
969 * @scn: HIF Context
970 *
971 * Return: driver mode of operation
972 */
973uint32_t hif_get_conparam(struct hif_softc *scn)
974{
975 if (!scn)
976 return 0;
977
978 return scn->hif_con_param;
979}
980
981/**
982 * hif_get_callbacks_handle() - API to get callbacks Handle
983 * @scn: HIF Context
984 *
985 * Return: pointer to HIF Callbacks
986 */
Manikandan Mohanbd0ef8a2017-04-10 13:10:21 -0700987struct hif_driver_state_callbacks *hif_get_callbacks_handle(
988 struct hif_softc *scn)
Komal Seelambd7c51d2016-02-24 10:27:30 +0530989{
990 return &scn->callbacks;
991}
992
993/**
994 * hif_is_driver_unloading() - API to query upper layers if driver is unloading
995 * @scn: HIF Context
996 *
997 * Return: True/False
998 */
999bool hif_is_driver_unloading(struct hif_softc *scn)
1000{
Komal Seelam75080122016-03-02 15:18:25 +05301001 struct hif_driver_state_callbacks *cbk = hif_get_callbacks_handle(scn);
Komal Seelambd7c51d2016-02-24 10:27:30 +05301002
1003 if (cbk && cbk->is_driver_unloading)
1004 return cbk->is_driver_unloading(cbk->context);
1005
1006 return false;
1007}
1008
1009/**
1010 * hif_is_load_or_unload_in_progress() - API to query upper layers if
1011 * load/unload in progress
1012 * @scn: HIF Context
1013 *
1014 * Return: True/False
1015 */
1016bool hif_is_load_or_unload_in_progress(struct hif_softc *scn)
1017{
Komal Seelam75080122016-03-02 15:18:25 +05301018 struct hif_driver_state_callbacks *cbk = hif_get_callbacks_handle(scn);
Komal Seelambd7c51d2016-02-24 10:27:30 +05301019
1020 if (cbk && cbk->is_load_unload_in_progress)
1021 return cbk->is_load_unload_in_progress(cbk->context);
1022
1023 return false;
1024}
1025
1026/**
Venkateswara Swamy Bandaru26f6f1e2016-10-03 19:35:57 +05301027 * hif_update_pipe_callback() - API to register pipe specific callbacks
1028 * @osc: Opaque softc
1029 * @pipeid: pipe id
1030 * @callbacks: callbacks to register
1031 *
1032 * Return: void
1033 */
1034
1035void hif_update_pipe_callback(struct hif_opaque_softc *osc,
1036 u_int8_t pipeid,
1037 struct hif_msg_callbacks *callbacks)
1038{
1039 struct hif_softc *scn = HIF_GET_SOFTC(osc);
1040 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
1041 struct HIF_CE_pipe_info *pipe_info;
1042
1043 QDF_BUG(pipeid < CE_COUNT_MAX);
1044
1045 HIF_INFO_LO("+%s pipeid %d\n", __func__, pipeid);
1046
1047 pipe_info = &hif_state->pipe_info[pipeid];
1048
1049 qdf_mem_copy(&pipe_info->pipe_callbacks,
1050 callbacks, sizeof(pipe_info->pipe_callbacks));
1051
1052 HIF_INFO_LO("-%s\n", __func__);
1053}
1054
1055/**
Komal Seelambd7c51d2016-02-24 10:27:30 +05301056 * hif_is_recovery_in_progress() - API to query upper layers if recovery in
1057 * progress
1058 * @scn: HIF Context
1059 *
1060 * Return: True/False
1061 */
1062bool hif_is_recovery_in_progress(struct hif_softc *scn)
1063{
Komal Seelam75080122016-03-02 15:18:25 +05301064 struct hif_driver_state_callbacks *cbk = hif_get_callbacks_handle(scn);
Komal Seelambd7c51d2016-02-24 10:27:30 +05301065
1066 if (cbk && cbk->is_recovery_in_progress)
1067 return cbk->is_recovery_in_progress(cbk->context);
1068
1069 return false;
1070}
Govind Singhbc679dc2017-06-08 12:33:59 +05301071
1072/**
1073 * hif_is_target_ready() - API to query if target is in ready state
1074 * progress
1075 * @scn: HIF Context
1076 *
1077 * Return: True/False
1078 */
1079bool hif_is_target_ready(struct hif_softc *scn)
1080{
1081 struct hif_driver_state_callbacks *cbk = hif_get_callbacks_handle(scn);
1082
1083 if (cbk && cbk->is_target_ready)
1084 return cbk->is_target_ready(cbk->context);
1085
1086 return false;
1087}
Mohit Khanna440c5292016-05-12 11:05:06 -07001088#if defined(HIF_PCI) || defined(SNOC) || defined(HIF_AHB)
Houston Hoffman56e0d702016-05-05 17:48:06 -07001089/**
1090 * hif_batch_send() - API to access hif specific function
1091 * ce_batch_send.
1092 * @osc: HIF Context
1093 * @msdu : list of msdus to be sent
1094 * @transfer_id : transfer id
1095 * @len : donwloaded length
1096 *
1097 * Return: list of msds not sent
1098 */
1099qdf_nbuf_t hif_batch_send(struct hif_opaque_softc *osc, qdf_nbuf_t msdu,
1100 uint32_t transfer_id, u_int32_t len, uint32_t sendhead)
1101{
1102 void *ce_tx_hdl = hif_get_ce_handle(osc, CE_HTT_TX_CE);
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05301103
Houston Hoffman56e0d702016-05-05 17:48:06 -07001104 return ce_batch_send((struct CE_handle *)ce_tx_hdl, msdu, transfer_id,
1105 len, sendhead);
1106}
1107
1108/**
1109 * hif_update_tx_ring() - API to access hif specific function
1110 * ce_update_tx_ring.
1111 * @osc: HIF Context
1112 * @num_htt_cmpls : number of htt compl received.
1113 *
1114 * Return: void
1115 */
1116void hif_update_tx_ring(struct hif_opaque_softc *osc, u_int32_t num_htt_cmpls)
1117{
1118 void *ce_tx_hdl = hif_get_ce_handle(osc, CE_HTT_TX_CE);
Manikandan Mohanbd0ef8a2017-04-10 13:10:21 -07001119
Houston Hoffman56e0d702016-05-05 17:48:06 -07001120 ce_update_tx_ring(ce_tx_hdl, num_htt_cmpls);
1121}
1122
1123
1124/**
1125 * hif_send_single() - API to access hif specific function
1126 * ce_send_single.
1127 * @osc: HIF Context
1128 * @msdu : msdu to be sent
1129 * @transfer_id: transfer id
1130 * @len : downloaded length
1131 *
1132 * Return: msdu sent status
1133 */
1134int hif_send_single(struct hif_opaque_softc *osc, qdf_nbuf_t msdu, uint32_t
1135 transfer_id, u_int32_t len)
1136{
1137 void *ce_tx_hdl = hif_get_ce_handle(osc, CE_HTT_TX_CE);
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05301138
Houston Hoffman56e0d702016-05-05 17:48:06 -07001139 return ce_send_single((struct CE_handle *)ce_tx_hdl, msdu, transfer_id,
1140 len);
1141}
1142
1143/**
1144 * hif_send_fast() - API to access hif specific function
1145 * ce_send_fast.
1146 * @osc: HIF Context
1147 * @msdu : array of msdus to be sent
1148 * @num_msdus : number of msdus in an array
1149 * @transfer_id: transfer id
Nirav Shahda0881a2016-05-16 10:45:16 +05301150 * @download_len: download length
Houston Hoffman56e0d702016-05-05 17:48:06 -07001151 *
1152 * Return: No. of packets that could be sent
1153 */
Nirav Shahda0881a2016-05-16 10:45:16 +05301154int hif_send_fast(struct hif_opaque_softc *osc, qdf_nbuf_t nbuf,
1155 uint32_t transfer_id, uint32_t download_len)
Houston Hoffman56e0d702016-05-05 17:48:06 -07001156{
1157 void *ce_tx_hdl = hif_get_ce_handle(osc, CE_HTT_TX_CE);
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05301158
Nirav Shahda0881a2016-05-16 10:45:16 +05301159 return ce_send_fast((struct CE_handle *)ce_tx_hdl, nbuf,
1160 transfer_id, download_len);
Houston Hoffman56e0d702016-05-05 17:48:06 -07001161}
Mohit Khanna440c5292016-05-12 11:05:06 -07001162#endif
Houston Hoffman56e0d702016-05-05 17:48:06 -07001163
1164/**
1165 * hif_reg_write() - API to access hif specific function
1166 * hif_write32_mb.
1167 * @hif_ctx : HIF Context
1168 * @offset : offset on which value has to be written
1169 * @value : value to be written
1170 *
1171 * Return: None
1172 */
1173void hif_reg_write(struct hif_opaque_softc *hif_ctx, uint32_t offset,
1174 uint32_t value)
1175{
1176 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Manikandan Mohanbd0ef8a2017-04-10 13:10:21 -07001177
Houston Hoffman56e0d702016-05-05 17:48:06 -07001178 hif_write32_mb(scn->mem + offset, value);
1179
1180}
1181
1182/**
1183 * hif_reg_read() - API to access hif specific function
1184 * hif_read32_mb.
1185 * @hif_ctx : HIF Context
1186 * @offset : offset from which value has to be read
1187 *
1188 * Return: Read value
1189 */
1190uint32_t hif_reg_read(struct hif_opaque_softc *hif_ctx, uint32_t offset)
1191{
1192
1193 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Manikandan Mohanbd0ef8a2017-04-10 13:10:21 -07001194
Houston Hoffman56e0d702016-05-05 17:48:06 -07001195 return hif_read32_mb(scn->mem + offset);
1196}
Mohit Khanna440c5292016-05-12 11:05:06 -07001197
1198#if defined(HIF_USB)
1199/**
1200 * hif_ramdump_handler(): generic ramdump handler
1201 * @scn: struct hif_opaque_softc
1202 *
1203 * Return: None
1204 */
1205
1206void hif_ramdump_handler(struct hif_opaque_softc *scn)
1207
1208{
1209 if (hif_get_bus_type == QDF_BUS_TYPE_USB)
1210 hif_usb_ramdump_handler();
1211}
1212#endif
Venkateswara Swamy Bandaru31108f32016-08-08 18:04:29 +05301213
Dustin Brown2af3d672017-05-30 16:14:01 -07001214#ifdef WLAN_SUSPEND_RESUME_TEST
1215irqreturn_t hif_wake_interrupt_handler(int irq, void *context)
1216{
1217 struct hif_softc *scn = context;
1218
1219 HIF_INFO("wake interrupt received on irq %d", irq);
1220
Dustin Brownbbba9172017-10-04 17:03:56 -07001221 if (scn->initial_wakeup_cb)
1222 scn->initial_wakeup_cb(scn->initial_wakeup_priv);
1223
Dustin Brown2af3d672017-05-30 16:14:01 -07001224 if (hif_is_ut_suspended(scn))
1225 hif_ut_fw_resume(scn);
1226
1227 return IRQ_HANDLED;
1228}
1229#else /* WLAN_SUSPEND_RESUME_TEST */
1230irqreturn_t hif_wake_interrupt_handler(int irq, void *context)
1231{
Dustin Brownbbba9172017-10-04 17:03:56 -07001232 struct hif_softc *scn = context;
1233
Dustin Brown2af3d672017-05-30 16:14:01 -07001234 HIF_INFO("wake interrupt received on irq %d", irq);
1235
Dustin Brownbbba9172017-10-04 17:03:56 -07001236 if (scn->initial_wakeup_cb)
1237 scn->initial_wakeup_cb(scn->initial_wakeup_priv);
1238
Dustin Brown2af3d672017-05-30 16:14:01 -07001239 return IRQ_HANDLED;
1240}
1241#endif /* WLAN_SUSPEND_RESUME_TEST */
Dustin Brownbbba9172017-10-04 17:03:56 -07001242
1243void hif_set_initial_wakeup_cb(struct hif_opaque_softc *hif_ctx,
1244 void (*callback)(void *),
1245 void *priv)
1246{
1247 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
1248
1249 scn->initial_wakeup_cb = callback;
1250 scn->initial_wakeup_priv = priv;
1251}
1252