blob: f2338c6f7221e48bd11a2fb8c27b58266dd30bf0 [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"
Poddar, Siddarthe41943f2016-04-27 15:33:48 +053043#endif
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +053044#include "qdf_trace.h"
45#include "qdf_status.h"
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080046#include "hif_debug.h"
47#include "mp_dev.h"
Mohit Khanna440c5292016-05-12 11:05:06 -070048#include "ce_api.h"
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +053049#ifdef QCA_WIFI_QCA8074
50#include "hal_api.h"
51#endif
Manjunathappa Prakash2146da32016-10-13 14:47:47 -070052#include "hif_napi.h"
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
Houston Hoffman4f529982016-05-05 16:11:04 -0700152#ifndef CONFIG_WIN
153#define QCA9984_HOST_INTEREST_ADDRESS -1
154#define QCA9888_HOST_INTEREST_ADDRESS -1
155#define IPQ4019_HOST_INTEREST_ADDRESS -1
156#endif
157
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800158/**
159 * hif_hia_item_address(): hif_hia_item_address
160 * @target_type: target_type
161 * @item_offset: item_offset
162 *
163 * Return: n/a
164 */
165uint32_t hif_hia_item_address(uint32_t target_type, uint32_t item_offset)
166{
167 switch (target_type) {
168 case TARGET_TYPE_AR6002:
169 return AR6002_HOST_INTEREST_ADDRESS + item_offset;
170 case TARGET_TYPE_AR6003:
171 return AR6003_HOST_INTEREST_ADDRESS + item_offset;
172 case TARGET_TYPE_AR6004:
173 return AR6004_HOST_INTEREST_ADDRESS + item_offset;
174 case TARGET_TYPE_AR6006:
175 return AR6006_HOST_INTEREST_ADDRESS + item_offset;
176 case TARGET_TYPE_AR9888:
177 return AR9888_HOST_INTEREST_ADDRESS + item_offset;
178 case TARGET_TYPE_AR6320:
179 case TARGET_TYPE_AR6320V2:
180 return AR6320_HOST_INTEREST_ADDRESS + item_offset;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800181 case TARGET_TYPE_ADRASTEA:
182 /* ADRASTEA doesn't have a host interest address */
183 ASSERT(0);
184 return 0;
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700185 case TARGET_TYPE_AR900B:
186 return AR900B_HOST_INTEREST_ADDRESS + item_offset;
187 case TARGET_TYPE_QCA9984:
188 return QCA9984_HOST_INTEREST_ADDRESS + item_offset;
189 case TARGET_TYPE_QCA9888:
190 return QCA9888_HOST_INTEREST_ADDRESS + item_offset;
191 case TARGET_TYPE_IPQ4019:
192 return IPQ4019_HOST_INTEREST_ADDRESS + item_offset;
193
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800194 default:
195 ASSERT(0);
196 return 0;
197 }
198}
199
200/**
201 * hif_max_num_receives_reached() - check max receive is reached
Komal Seelambd7c51d2016-02-24 10:27:30 +0530202 * @scn: HIF Context
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800203 * @count: unsigned int.
204 *
205 * Output check status as bool
206 *
207 * Return: bool
208 */
Komal Seelambd7c51d2016-02-24 10:27:30 +0530209bool hif_max_num_receives_reached(struct hif_softc *scn, unsigned int count)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800210{
Houston Hoffman75ef5a52016-04-14 17:15:49 -0700211 if (QDF_IS_EPPING_ENABLED(hif_get_conparam(scn)))
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800212 return count > 120;
213 else
214 return count > MAX_NUM_OF_RECEIVES;
215}
216
217/**
218 * init_buffer_count() - initial buffer count
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530219 * @maxSize: qdf_size_t
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800220 *
221 * routine to modify the initial buffer count to be allocated on an os
222 * platform basis. Platform owner will need to modify this as needed
223 *
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530224 * Return: qdf_size_t
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800225 */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530226qdf_size_t init_buffer_count(qdf_size_t maxSize)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800227{
228 return maxSize;
229}
230
231/**
Nirav Shahd7f91592016-04-21 14:18:43 +0530232 * hif_save_htc_htt_config_endpoint() - save htt_tx_endpoint
233 * @hif_ctx: hif context
234 * @htc_htt_tx_endpoint: htt_tx_endpoint
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800235 *
236 * Return: void
237 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530238void hif_save_htc_htt_config_endpoint(struct hif_opaque_softc *hif_ctx,
Nirav Shahd7f91592016-04-21 14:18:43 +0530239 int htc_htt_tx_endpoint)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800240{
Komal Seelam644263d2016-02-22 20:45:49 +0530241 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800242
243 if (!scn) {
244 HIF_ERROR("%s: error: scn or scn->hif_sc is NULL!",
245 __func__);
246 return;
247 }
248
Nirav Shahd7f91592016-04-21 14:18:43 +0530249 scn->htc_htt_tx_endpoint = htc_htt_tx_endpoint;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800250}
251
Houston Hoffmanec93ab02016-05-03 20:09:55 -0700252static const struct qwlan_hw qwlan_hw_list[] = {
253 {
254 .id = AR6320_REV1_VERSION,
255 .subid = 0,
256 .name = "QCA6174_REV1",
257 },
258 {
259 .id = AR6320_REV1_1_VERSION,
260 .subid = 0x1,
261 .name = "QCA6174_REV1_1",
262 },
263 {
264 .id = AR6320_REV1_3_VERSION,
265 .subid = 0x2,
266 .name = "QCA6174_REV1_3",
267 },
268 {
269 .id = AR6320_REV2_1_VERSION,
270 .subid = 0x4,
271 .name = "QCA6174_REV2_1",
272 },
273 {
274 .id = AR6320_REV2_1_VERSION,
275 .subid = 0x5,
276 .name = "QCA6174_REV2_2",
277 },
278 {
279 .id = AR6320_REV3_VERSION,
280 .subid = 0x6,
281 .name = "QCA6174_REV2.3",
282 },
283 {
284 .id = AR6320_REV3_VERSION,
285 .subid = 0x8,
286 .name = "QCA6174_REV3",
287 },
288 {
289 .id = AR6320_REV3_VERSION,
290 .subid = 0x9,
291 .name = "QCA6174_REV3_1",
292 },
293 {
294 .id = AR6320_REV3_2_VERSION,
295 .subid = 0xA,
296 .name = "AR6320_REV3_2_VERSION",
Houston Hoffmancd0884a2016-08-24 15:30:09 -0700297 },
298 {
299 .id = WCN3990_v1,
300 .subid = 0x0,
301 .name = "WCN3990_V1",
Houston Hoffmandd4da482016-10-17 12:41:45 -0700302 },
303 {
304 .id = WCN3990_v2,
305 .subid = 0x0,
306 .name = "WCN3990_V2",
Houston Hoffman59fd2452016-11-19 17:27:10 -0800307 },
308 {
309 .id = WCN3990_v2_1,
310 .subid = 0x0,
311 .name = "WCN3990_V2.1",
Yingying Tangd8921742016-10-18 18:13:07 +0800312 },
313 {
314 .id = QCA9379_REV1_VERSION,
315 .subid = 0xC,
316 .name = "QCA9379_REV1",
Yingying Tang80404362016-10-20 23:29:57 +0800317 },
318 {
319 .id = QCA9379_REV1_VERSION,
320 .subid = 0xD,
321 .name = "QCA9379_REV1_1",
Houston Hoffmanec93ab02016-05-03 20:09:55 -0700322 }
323};
324
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800325/**
326 * hif_get_hw_name(): get a human readable name for the hardware
Komal Seelam91553ce2016-01-27 18:57:10 +0530327 * @info: Target Info
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800328 *
Komal Seelam91553ce2016-01-27 18:57:10 +0530329 * Return: human readable name for the underlying wifi hardware.
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800330 */
Komal Seelam91553ce2016-01-27 18:57:10 +0530331static const char *hif_get_hw_name(struct hif_target_info *info)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800332{
333 int i;
Komal Seelam91553ce2016-01-27 18:57:10 +0530334
Houston Hoffman60af6752016-11-21 12:13:36 -0800335 if (info->hw_name)
336 return info->hw_name;
337
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800338 for (i = 0; i < ARRAY_SIZE(qwlan_hw_list); i++) {
Komal Seelam91553ce2016-01-27 18:57:10 +0530339 if (info->target_version == qwlan_hw_list[i].id &&
340 info->target_revision == qwlan_hw_list[i].subid) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800341 return qwlan_hw_list[i].name;
342 }
343 }
344
Houston Hoffman60af6752016-11-21 12:13:36 -0800345 info->hw_name = qdf_mem_malloc(64);
346 if (!info->hw_name)
347 return "Unknown Device (nomem)";
348
349 i = qdf_snprint(info->hw_name, 64, "HW_VERSION=%x.",
350 info->target_version);
351 if (i < 0)
352 return "Unknown Device (snprintf failure)";
353 else
354 return info->hw_name;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800355}
356
357/**
358 * hif_get_hw_info(): hif_get_hw_info
359 * @scn: scn
360 * @version: version
361 * @revision: revision
362 *
363 * Return: n/a
364 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530365void hif_get_hw_info(struct hif_opaque_softc *scn, u32 *version, u32 *revision,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800366 const char **target_name)
367{
Komal Seelam91553ce2016-01-27 18:57:10 +0530368 struct hif_target_info *info = hif_get_target_info_handle(scn);
Mohit Khanna440c5292016-05-12 11:05:06 -0700369 struct hif_softc *sc = HIF_GET_SOFTC(scn);
370
371 if (sc->bus_type == QDF_BUS_TYPE_USB)
372 hif_usb_get_hw_info(sc);
373
Komal Seelam91553ce2016-01-27 18:57:10 +0530374 *version = info->target_version;
375 *revision = info->target_revision;
376 *target_name = hif_get_hw_name(info);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800377}
378
379/**
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530380 * hif_get_dev_ba(): API to get device base address.
381 * @scn: scn
382 * @version: version
383 * @revision: revision
384 *
385 * Return: n/a
386 */
387void *hif_get_dev_ba(struct hif_opaque_softc *hif_handle)
388{
389 struct hif_softc *scn = (struct hif_softc *)hif_handle;
390
391 return scn->mem;
392}
393/**
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800394 * hif_open(): hif_open
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530395 * @qdf_ctx: QDF Context
Komal Seelambd7c51d2016-02-24 10:27:30 +0530396 * @mode: Driver Mode
397 * @bus_type: Bus Type
398 * @cbk: CDS Callbacks
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800399 *
Komal Seelambd7c51d2016-02-24 10:27:30 +0530400 * API to open HIF Context
401 *
402 * Return: HIF Opaque Pointer
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800403 */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530404struct hif_opaque_softc *hif_open(qdf_device_t qdf_ctx, uint32_t mode,
405 enum qdf_bus_type bus_type,
Komal Seelam75080122016-03-02 15:18:25 +0530406 struct hif_driver_state_callbacks *cbk)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800407{
Komal Seelam644263d2016-02-22 20:45:49 +0530408 struct hif_softc *scn;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530409 QDF_STATUS status = QDF_STATUS_SUCCESS;
Houston Hoffman162164c2016-03-14 21:12:10 -0700410 int bus_context_size = hif_bus_get_context_size(bus_type);
411
412 if (bus_context_size == 0) {
413 HIF_ERROR("%s: context size 0 not allowed", __func__);
414 return NULL;
415 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800416
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530417 scn = (struct hif_softc *)qdf_mem_malloc(bus_context_size);
Komal Seelambd7c51d2016-02-24 10:27:30 +0530418 if (!scn) {
419 HIF_ERROR("%s: cannot alloc memory for HIF context of size:%d",
420 __func__, bus_context_size);
421 return GET_HIF_OPAQUE_HDL(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800422 }
423
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530424 scn->qdf_dev = qdf_ctx;
Komal Seelambd7c51d2016-02-24 10:27:30 +0530425 scn->hif_con_param = mode;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530426 qdf_atomic_init(&scn->active_tasklet_cnt);
Venkateswara Swamy Bandaru31108f32016-08-08 18:04:29 +0530427 qdf_atomic_init(&scn->active_grp_tasklet_cnt);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530428 qdf_atomic_init(&scn->link_suspended);
429 qdf_atomic_init(&scn->tasklet_from_intr);
Manikandan Mohanbd0ef8a2017-04-10 13:10:21 -0700430 qdf_mem_copy(&scn->callbacks, cbk,
431 sizeof(struct hif_driver_state_callbacks));
Houston Hoffman3db96a42016-05-05 19:54:39 -0700432 scn->bus_type = bus_type;
Houston Hoffman3cfe6862016-01-08 10:33:55 -0800433 status = hif_bus_open(scn, bus_type);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530434 if (status != QDF_STATUS_SUCCESS) {
Houston Hoffman3cfe6862016-01-08 10:33:55 -0800435 HIF_ERROR("%s: hif_bus_open error = %d, bus_type = %d",
436 __func__, status, bus_type);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530437 qdf_mem_free(scn);
Komal Seelambd7c51d2016-02-24 10:27:30 +0530438 scn = NULL;
Houston Hoffman3cfe6862016-01-08 10:33:55 -0800439 }
440
Komal Seelambd7c51d2016-02-24 10:27:30 +0530441 return GET_HIF_OPAQUE_HDL(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800442}
443
444/**
445 * hif_close(): hif_close
446 * @hif_ctx: hif_ctx
447 *
448 * Return: n/a
449 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530450void hif_close(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800451{
Komal Seelam644263d2016-02-22 20:45:49 +0530452 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800453
454 if (scn == NULL) {
Komal Seelam5584a7c2016-02-24 19:22:48 +0530455 HIF_ERROR("%s: hif_opaque_softc is NULL", __func__);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800456 return;
457 }
458
459 if (scn->athdiag_procfs_inited) {
460 athdiag_procfs_remove();
461 scn->athdiag_procfs_inited = false;
462 }
463
Houston Hoffman60af6752016-11-21 12:13:36 -0800464 if (scn->target_info.hw_name) {
465 char *hw_name = scn->target_info.hw_name;
Manikandan Mohanbd0ef8a2017-04-10 13:10:21 -0700466
Houston Hoffman60af6752016-11-21 12:13:36 -0800467 scn->target_info.hw_name = "ErrUnloading";
468 qdf_mem_free(hw_name);
469 }
470
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800471 hif_bus_close(scn);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530472 qdf_mem_free(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800473}
474
Houston Hoffman6fe60592016-11-18 13:12:08 -0800475#ifdef QCA_WIFI_QCA8074
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530476static QDF_STATUS hif_hal_attach(struct hif_softc *scn)
477{
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530478 if (ce_srng_based(scn)) {
479 scn->hal_soc = hal_attach(scn, scn->qdf_dev);
480 if (scn->hal_soc == NULL)
481 return QDF_STATUS_E_FAILURE;
482 }
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530483
484 return QDF_STATUS_SUCCESS;
485}
Houston Hoffman4e2df402017-05-21 19:36:56 -0700486
487static QDF_STATUS hif_hal_detach(struct hif_softc *scn)
488{
489 if (ce_srng_based(scn)) {
490 hal_detach(scn->hal_soc);
491 scn->hal_soc = NULL;
492 }
493
494 return QDF_STATUS_SUCCESS;
495}
Houston Hoffman6fe60592016-11-18 13:12:08 -0800496#else
497static QDF_STATUS hif_hal_attach(struct hif_softc *scn)
498{
499 return QDF_STATUS_SUCCESS;
500}
Houston Hoffman4e2df402017-05-21 19:36:56 -0700501
502static QDF_STATUS hif_hal_detach(struct hif_softc *scn)
503{
504 return QDF_STATUS_SUCCESS;
505}
Houston Hoffman6fe60592016-11-18 13:12:08 -0800506#endif
507
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800508/**
509 * hif_enable(): hif_enable
510 * @hif_ctx: hif_ctx
511 * @dev: dev
512 * @bdev: bus dev
513 * @bid: bus ID
514 * @bus_type: bus type
515 * @type: enable type
516 *
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530517 * Return: QDF_STATUS
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800518 */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530519QDF_STATUS hif_enable(struct hif_opaque_softc *hif_ctx, struct device *dev,
Manikandan Mohanbd0ef8a2017-04-10 13:10:21 -0700520 void *bdev,
521 const struct hif_bus_id *bid,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530522 enum qdf_bus_type bus_type,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800523 enum hif_enable_type type)
524{
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530525 QDF_STATUS status;
Komal Seelam644263d2016-02-22 20:45:49 +0530526 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800527
528 if (scn == NULL) {
529 HIF_ERROR("%s: hif_ctx = NULL", __func__);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530530 return QDF_STATUS_E_NULL_VALUE;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800531 }
532
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800533 status = hif_enable_bus(scn, dev, bdev, bid, type);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530534 if (status != QDF_STATUS_SUCCESS) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800535 HIF_ERROR("%s: hif_enable_bus error = %d",
536 __func__, status);
537 return status;
538 }
539
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530540 status = hif_hal_attach(scn);
541 if (status != QDF_STATUS_SUCCESS) {
542 HIF_ERROR("%s: hal attach failed", __func__);
Houston Hoffman4e2df402017-05-21 19:36:56 -0700543 goto disable_bus;
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530544 }
545
Houston Hoffman108da402016-03-14 21:11:24 -0700546 if (hif_bus_configure(scn)) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800547 HIF_ERROR("%s: Target probe failed.", __func__);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530548 status = QDF_STATUS_E_FAILURE;
Houston Hoffman4e2df402017-05-21 19:36:56 -0700549 goto hal_detach;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800550 }
Houston Hoffman108da402016-03-14 21:11:24 -0700551
Dustin Brownccf859d2017-06-01 14:31:01 -0700552 hif_ut_suspend_init(scn);
553
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800554 /*
555 * Flag to avoid potential unallocated memory access from MSI
556 * interrupt handler which could get scheduled as soon as MSI
557 * is enabled, i.e to take care of the race due to the order
558 * in where MSI is enabled before the memory, that will be
559 * in interrupt handlers, is allocated.
560 */
561
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800562 scn->hif_init_done = true;
563
Srinivas Girigowda6e0cfd92017-03-09 15:49:59 -0800564 HIF_DBG("%s: OK", __func__);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800565
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530566 return QDF_STATUS_SUCCESS;
Houston Hoffman4e2df402017-05-21 19:36:56 -0700567
568hal_detach:
569 hif_hal_detach(scn);
570disable_bus:
571 hif_disable_bus(scn);
572 return status;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800573}
574
Komal Seelam5584a7c2016-02-24 19:22:48 +0530575void hif_disable(struct hif_opaque_softc *hif_ctx, enum hif_disable_type type)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800576{
Komal Seelam644263d2016-02-22 20:45:49 +0530577 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800578
579 if (!scn)
580 return;
581
582 hif_nointrs(scn);
583 if (scn->hif_init_done == false)
Poddar, Siddarthe41943f2016-04-27 15:33:48 +0530584 hif_shutdown_device(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800585 else
Komal Seelam644263d2016-02-22 20:45:49 +0530586 hif_stop(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800587
Houston Hoffman4e2df402017-05-21 19:36:56 -0700588 hif_hal_detach(scn);
589
Vishwajith Upendra3f78aa62016-02-09 17:53:02 +0530590 hif_disable_bus(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800591
Komal Seelambd7c51d2016-02-24 10:27:30 +0530592 hif_wlan_disable(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800593
594 scn->notice_send = false;
595
Srinivas Girigowda6e0cfd92017-03-09 15:49:59 -0800596 HIF_DBG("%s: X", __func__);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800597}
598
Nirav Shahb70bd732016-05-25 14:31:51 +0530599void hif_display_stats(struct hif_opaque_softc *hif_ctx)
600{
601 hif_display_bus_stats(hif_ctx);
602}
603
604void hif_clear_stats(struct hif_opaque_softc *hif_ctx)
605{
606 hif_clear_bus_stats(hif_ctx);
607}
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800608
609/**
Govind Singh2443fb32016-01-13 17:44:48 +0530610 * hif_crash_shutdown_dump_bus_register() - dump bus registers
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800611 * @hif_ctx: hif_ctx
612 *
613 * Return: n/a
614 */
615#if defined(TARGET_RAMDUMP_AFTER_KERNEL_PANIC) \
Houston Hoffmanbc693492016-03-14 21:11:41 -0700616&& defined(DEBUG)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800617
Govind Singh2443fb32016-01-13 17:44:48 +0530618static void hif_crash_shutdown_dump_bus_register(void *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800619{
Komal Seelam5584a7c2016-02-24 19:22:48 +0530620 struct hif_opaque_softc *scn = hif_ctx;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800621
Govind Singh2443fb32016-01-13 17:44:48 +0530622 if (hif_check_soc_status(scn))
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800623 return;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800624
Govind Singh2443fb32016-01-13 17:44:48 +0530625 if (hif_dump_registers(scn))
626 HIF_ERROR("Failed to dump bus registers!");
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800627}
628
629/**
630 * hif_crash_shutdown(): hif_crash_shutdown
631 *
632 * This function is called by the platform driver to dump CE registers
633 *
634 * @hif_ctx: hif_ctx
635 *
636 * Return: n/a
637 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530638void hif_crash_shutdown(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800639{
Komal Seelam644263d2016-02-22 20:45:49 +0530640 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800641
Houston Hoffmanbc693492016-03-14 21:11:41 -0700642 if (!hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800643 return;
644
Houston Hoffmanbc693492016-03-14 21:11:41 -0700645 if (scn->bus_type == QDF_BUS_TYPE_SNOC) {
646 HIF_INFO_MED("%s: RAM dump disabled for bustype %d",
647 __func__, scn->bus_type);
648 return;
649 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800650
Komal Seelam6ee55902016-04-11 17:11:07 +0530651 if (TARGET_STATUS_RESET == scn->target_status) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800652 HIF_INFO_MED("%s: Target is already asserted, ignore!",
653 __func__);
654 return;
655 }
656
Komal Seelambd7c51d2016-02-24 10:27:30 +0530657 if (hif_is_load_or_unload_in_progress(scn)) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800658 HIF_ERROR("%s: Load/unload is in progress, ignore!", __func__);
659 return;
660 }
661
Govind Singh2443fb32016-01-13 17:44:48 +0530662 hif_crash_shutdown_dump_bus_register(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800663
Komal Seelam644263d2016-02-22 20:45:49 +0530664 if (ol_copy_ramdump(hif_ctx))
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800665 goto out;
666
667 HIF_INFO_MED("%s: RAM dump collecting completed!", __func__);
668
669out:
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800670 return;
671}
672#else
Komal Seelam5584a7c2016-02-24 19:22:48 +0530673void hif_crash_shutdown(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800674{
675 HIF_INFO_MED("%s: Collecting target RAM dump disabled",
676 __func__);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800677}
678#endif /* TARGET_RAMDUMP_AFTER_KERNEL_PANIC */
679
680#ifdef QCA_WIFI_3_0
681/**
682 * hif_check_fw_reg(): hif_check_fw_reg
683 * @scn: scn
684 * @state:
685 *
686 * Return: int
687 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530688int hif_check_fw_reg(struct hif_opaque_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800689{
690 return 0;
691}
692#endif
693
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800694/**
695 * hif_read_phy_mem_base(): hif_read_phy_mem_base
696 * @scn: scn
697 * @phy_mem_base: physical mem base
698 *
699 * Return: n/a
700 */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530701void hif_read_phy_mem_base(struct hif_softc *scn, qdf_dma_addr_t *phy_mem_base)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800702{
703 *phy_mem_base = scn->mem_pa;
704}
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800705
706/**
707 * hif_get_device_type(): hif_get_device_type
708 * @device_id: device_id
709 * @revision_id: revision_id
710 * @hif_type: returned hif_type
711 * @target_type: returned target_type
712 *
713 * Return: int
714 */
715int hif_get_device_type(uint32_t device_id,
716 uint32_t revision_id,
717 uint32_t *hif_type, uint32_t *target_type)
718{
719 int ret = 0;
720
721 switch (device_id) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800722 case ADRASTEA_DEVICE_ID_P2_E12:
723
724 *hif_type = HIF_TYPE_ADRASTEA;
725 *target_type = TARGET_TYPE_ADRASTEA;
726 break;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800727
728 case AR9888_DEVICE_ID:
729 *hif_type = HIF_TYPE_AR9888;
730 *target_type = TARGET_TYPE_AR9888;
731 break;
732
733 case AR6320_DEVICE_ID:
734 switch (revision_id) {
735 case AR6320_FW_1_1:
736 case AR6320_FW_1_3:
737 *hif_type = HIF_TYPE_AR6320;
738 *target_type = TARGET_TYPE_AR6320;
739 break;
740
741 case AR6320_FW_2_0:
742 case AR6320_FW_3_0:
743 case AR6320_FW_3_2:
744 *hif_type = HIF_TYPE_AR6320V2;
745 *target_type = TARGET_TYPE_AR6320V2;
746 break;
747
748 default:
749 HIF_ERROR("%s: error - dev_id = 0x%x, rev_id = 0x%x",
750 __func__, device_id, revision_id);
751 ret = -ENODEV;
752 goto end;
753 }
754 break;
755
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700756 case AR9887_DEVICE_ID:
757 *hif_type = HIF_TYPE_AR9888;
758 *target_type = TARGET_TYPE_AR9888;
Houston Hoffmanc50572b2016-06-08 19:49:46 -0700759 HIF_INFO(" *********** AR9887 **************");
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700760 break;
761
762 case QCA9984_DEVICE_ID:
763 *hif_type = HIF_TYPE_QCA9984;
764 *target_type = TARGET_TYPE_QCA9984;
Houston Hoffmanc50572b2016-06-08 19:49:46 -0700765 HIF_INFO(" *********** QCA9984 *************");
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700766 break;
767
768 case QCA9888_DEVICE_ID:
769 *hif_type = HIF_TYPE_QCA9888;
770 *target_type = TARGET_TYPE_QCA9888;
Houston Hoffmanc50572b2016-06-08 19:49:46 -0700771 HIF_INFO(" *********** QCA9888 *************");
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700772 break;
773
774 case AR900B_DEVICE_ID:
775 *hif_type = HIF_TYPE_AR900B;
776 *target_type = TARGET_TYPE_AR900B;
Houston Hoffmanc50572b2016-06-08 19:49:46 -0700777 HIF_INFO(" *********** AR900B *************");
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700778 break;
779
Houston Hoffman3db96a42016-05-05 19:54:39 -0700780 case IPQ4019_DEVICE_ID:
781 *hif_type = HIF_TYPE_IPQ4019;
782 *target_type = TARGET_TYPE_IPQ4019;
Houston Hoffmanc50572b2016-06-08 19:49:46 -0700783 HIF_INFO(" *********** IPQ4019 *************");
Houston Hoffman3db96a42016-05-05 19:54:39 -0700784 break;
785
Venkateswara Swamy Bandaru9fd9af02016-09-20 20:27:31 +0530786 case QCA8074_DEVICE_ID:
Karunakar Dasinenif61cb072016-09-29 11:50:45 -0700787 case RUMIM2M_DEVICE_ID_NODE0:
788 case RUMIM2M_DEVICE_ID_NODE1:
Sathish Kumar2d2f19a2017-02-13 15:52:07 +0530789 case RUMIM2M_DEVICE_ID_NODE2:
790 case RUMIM2M_DEVICE_ID_NODE3:
Venkateswara Swamy Bandaru9fd9af02016-09-20 20:27:31 +0530791 *hif_type = HIF_TYPE_QCA8074;
792 *target_type = TARGET_TYPE_QCA8074;
793 HIF_INFO(" *********** QCA8074 *************\n");
794 break;
795
Houston Hoffman31b25ec2016-09-19 13:12:30 -0700796 case QCA6290_EMULATION_DEVICE_ID:
Houston Hoffman14f621c2017-05-01 10:35:50 -0700797 case QCA6290_DEVICE_ID:
Houston Hoffman31b25ec2016-09-19 13:12:30 -0700798 *hif_type = HIF_TYPE_QCA6290;
799 *target_type = TARGET_TYPE_QCA6290;
800 HIF_INFO(" *********** QCA6290EMU *************\n");
801 break;
802
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800803 default:
804 HIF_ERROR("%s: Unsupported device ID!", __func__);
805 ret = -ENODEV;
806 break;
807 }
808end:
809 return ret;
810}
Komal Seelam91553ce2016-01-27 18:57:10 +0530811
812/**
Houston Hoffman26352592016-03-14 21:11:43 -0700813 * hif_needs_bmi() - return true if the soc needs bmi through the driver
814 * @hif_ctx: hif context
815 *
816 * Return: true if the soc needs driver bmi otherwise false
817 */
818bool hif_needs_bmi(struct hif_opaque_softc *hif_ctx)
819{
820 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
Pratik Gandhi815c6d82016-10-19 12:06:32 +0530821
Houston Hoffman6c0c3f92016-09-27 18:05:39 -0700822 return (hif_sc->bus_type != QDF_BUS_TYPE_SNOC) &&
823 !ce_srng_based(hif_sc);
Houston Hoffman26352592016-03-14 21:11:43 -0700824}
825
826/**
Houston Hoffman60a1eeb2016-03-14 21:11:44 -0700827 * hif_get_bus_type() - return the bus type
828 *
829 * Return: enum qdf_bus_type
830 */
831enum qdf_bus_type hif_get_bus_type(struct hif_opaque_softc *hif_hdl)
832{
833 struct hif_softc *scn = HIF_GET_SOFTC(hif_hdl);
Manikandan Mohanbd0ef8a2017-04-10 13:10:21 -0700834
Houston Hoffman60a1eeb2016-03-14 21:11:44 -0700835 return scn->bus_type;
836}
837
838/**
Komal Seelam91553ce2016-01-27 18:57:10 +0530839 * Target info and ini parameters are global to the driver
840 * Hence these structures are exposed to all the modules in
841 * the driver and they don't need to maintains multiple copies
842 * of the same info, instead get the handle from hif and
843 * modify them in hif
844 */
845
846/**
847 * hif_get_ini_handle() - API to get hif_config_param handle
Komal Seelam644263d2016-02-22 20:45:49 +0530848 * @hif_ctx: HIF Context
Komal Seelam91553ce2016-01-27 18:57:10 +0530849 *
850 * Return: pointer to hif_config_info
851 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530852struct hif_config_info *hif_get_ini_handle(struct hif_opaque_softc *hif_ctx)
Komal Seelam91553ce2016-01-27 18:57:10 +0530853{
Komal Seelam644263d2016-02-22 20:45:49 +0530854 struct hif_softc *sc = HIF_GET_SOFTC(hif_ctx);
855
856 return &sc->hif_config;
Komal Seelam91553ce2016-01-27 18:57:10 +0530857}
858
859/**
860 * hif_get_target_info_handle() - API to get hif_target_info handle
Komal Seelam644263d2016-02-22 20:45:49 +0530861 * @hif_ctx: HIF context
Komal Seelam91553ce2016-01-27 18:57:10 +0530862 *
863 * Return: Pointer to hif_target_info
864 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530865struct hif_target_info *hif_get_target_info_handle(
866 struct hif_opaque_softc *hif_ctx)
Komal Seelam91553ce2016-01-27 18:57:10 +0530867{
Komal Seelam644263d2016-02-22 20:45:49 +0530868 struct hif_softc *sc = HIF_GET_SOFTC(hif_ctx);
869
870 return &sc->target_info;
871
Komal Seelam91553ce2016-01-27 18:57:10 +0530872}
Komal Seelamc92a0cf2016-02-22 20:43:52 +0530873
874#if defined(FEATURE_LRO)
Manjunathappa Prakash2146da32016-10-13 14:47:47 -0700875
876/**
877 * hif_get_lro_info - Returns LRO instance for instance ID
878 * @ctx_id: LRO instance ID
879 * @hif_hdl: HIF Context
880 *
881 * Return: Pointer to LRO instance.
882 */
883void *hif_get_lro_info(int ctx_id, struct hif_opaque_softc *hif_hdl)
884{
885 void *data;
886
887 if (hif_napi_enabled(hif_hdl, -1))
888 data = hif_napi_get_lro_info(hif_hdl, ctx_id);
889 else
890 data = hif_ce_get_lro_ctx(hif_hdl, ctx_id);
891
892 return data;
893}
894
895/**
896 * hif_get_rx_ctx_id - Returns LRO instance ID based on underlying LRO instance
897 * @ctx_id: LRO context ID
898 * @hif_hdl: HIF Context
899 *
900 * Return: LRO instance ID
901 */
902int hif_get_rx_ctx_id(int ctx_id, struct hif_opaque_softc *hif_hdl)
903{
904 if (hif_napi_enabled(hif_hdl, -1))
905 return NAPI_PIPE2ID(ctx_id);
906 else
907 return ctx_id;
Komal Seelamc92a0cf2016-02-22 20:43:52 +0530908}
909
Manjunathappa Prakash2146da32016-10-13 14:47:47 -0700910#else /* !defined(FEATURE_LRO) */
911int hif_get_rx_ctx_id(int ctx_id, struct hif_opaque_softc *hif_hdl)
912{
913 return 0;
Komal Seelamc92a0cf2016-02-22 20:43:52 +0530914}
915#endif
Komal Seelam644263d2016-02-22 20:45:49 +0530916
917/**
918 * hif_get_target_status - API to get target status
919 * @hif_ctx: HIF Context
920 *
Komal Seelam6ee55902016-04-11 17:11:07 +0530921 * Return: enum hif_target_status
Komal Seelam644263d2016-02-22 20:45:49 +0530922 */
Komal Seelam6ee55902016-04-11 17:11:07 +0530923enum hif_target_status hif_get_target_status(struct hif_opaque_softc *hif_ctx)
Komal Seelam644263d2016-02-22 20:45:49 +0530924{
925 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
926
927 return scn->target_status;
928}
929
930/**
Komal Seelama5911d32016-02-24 19:21:59 +0530931 * hif_set_target_status() - API to set target status
Komal Seelam644263d2016-02-22 20:45:49 +0530932 * @hif_ctx: HIF Context
933 * @status: Target Status
934 *
935 * Return: void
936 */
Komal Seelam6ee55902016-04-11 17:11:07 +0530937void hif_set_target_status(struct hif_opaque_softc *hif_ctx, enum
938 hif_target_status status)
Komal Seelam644263d2016-02-22 20:45:49 +0530939{
940 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
941
942 scn->target_status = status;
943}
Komal Seelama5911d32016-02-24 19:21:59 +0530944
945/**
946 * hif_init_ini_config() - API to initialize HIF configuration parameters
947 * @hif_ctx: HIF Context
948 * @cfg: HIF Configuration
949 *
950 * Return: void
951 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530952void hif_init_ini_config(struct hif_opaque_softc *hif_ctx,
953 struct hif_config_info *cfg)
Komal Seelama5911d32016-02-24 19:21:59 +0530954{
955 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
956
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530957 qdf_mem_copy(&scn->hif_config, cfg, sizeof(struct hif_config_info));
Komal Seelama5911d32016-02-24 19:21:59 +0530958}
Komal Seelambd7c51d2016-02-24 10:27:30 +0530959
960/**
961 * hif_get_conparam() - API to get driver mode in HIF
962 * @scn: HIF Context
963 *
964 * Return: driver mode of operation
965 */
966uint32_t hif_get_conparam(struct hif_softc *scn)
967{
968 if (!scn)
969 return 0;
970
971 return scn->hif_con_param;
972}
973
974/**
975 * hif_get_callbacks_handle() - API to get callbacks Handle
976 * @scn: HIF Context
977 *
978 * Return: pointer to HIF Callbacks
979 */
Manikandan Mohanbd0ef8a2017-04-10 13:10:21 -0700980struct hif_driver_state_callbacks *hif_get_callbacks_handle(
981 struct hif_softc *scn)
Komal Seelambd7c51d2016-02-24 10:27:30 +0530982{
983 return &scn->callbacks;
984}
985
986/**
987 * hif_is_driver_unloading() - API to query upper layers if driver is unloading
988 * @scn: HIF Context
989 *
990 * Return: True/False
991 */
992bool hif_is_driver_unloading(struct hif_softc *scn)
993{
Komal Seelam75080122016-03-02 15:18:25 +0530994 struct hif_driver_state_callbacks *cbk = hif_get_callbacks_handle(scn);
Komal Seelambd7c51d2016-02-24 10:27:30 +0530995
996 if (cbk && cbk->is_driver_unloading)
997 return cbk->is_driver_unloading(cbk->context);
998
999 return false;
1000}
1001
1002/**
1003 * hif_is_load_or_unload_in_progress() - API to query upper layers if
1004 * load/unload in progress
1005 * @scn: HIF Context
1006 *
1007 * Return: True/False
1008 */
1009bool hif_is_load_or_unload_in_progress(struct hif_softc *scn)
1010{
Komal Seelam75080122016-03-02 15:18:25 +05301011 struct hif_driver_state_callbacks *cbk = hif_get_callbacks_handle(scn);
Komal Seelambd7c51d2016-02-24 10:27:30 +05301012
1013 if (cbk && cbk->is_load_unload_in_progress)
1014 return cbk->is_load_unload_in_progress(cbk->context);
1015
1016 return false;
1017}
1018
1019/**
Venkateswara Swamy Bandaru26f6f1e2016-10-03 19:35:57 +05301020 * hif_update_pipe_callback() - API to register pipe specific callbacks
1021 * @osc: Opaque softc
1022 * @pipeid: pipe id
1023 * @callbacks: callbacks to register
1024 *
1025 * Return: void
1026 */
1027
1028void hif_update_pipe_callback(struct hif_opaque_softc *osc,
1029 u_int8_t pipeid,
1030 struct hif_msg_callbacks *callbacks)
1031{
1032 struct hif_softc *scn = HIF_GET_SOFTC(osc);
1033 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
1034 struct HIF_CE_pipe_info *pipe_info;
1035
1036 QDF_BUG(pipeid < CE_COUNT_MAX);
1037
1038 HIF_INFO_LO("+%s pipeid %d\n", __func__, pipeid);
1039
1040 pipe_info = &hif_state->pipe_info[pipeid];
1041
1042 qdf_mem_copy(&pipe_info->pipe_callbacks,
1043 callbacks, sizeof(pipe_info->pipe_callbacks));
1044
1045 HIF_INFO_LO("-%s\n", __func__);
1046}
1047
1048/**
Komal Seelambd7c51d2016-02-24 10:27:30 +05301049 * hif_is_recovery_in_progress() - API to query upper layers if recovery in
1050 * progress
1051 * @scn: HIF Context
1052 *
1053 * Return: True/False
1054 */
1055bool hif_is_recovery_in_progress(struct hif_softc *scn)
1056{
Komal Seelam75080122016-03-02 15:18:25 +05301057 struct hif_driver_state_callbacks *cbk = hif_get_callbacks_handle(scn);
Komal Seelambd7c51d2016-02-24 10:27:30 +05301058
1059 if (cbk && cbk->is_recovery_in_progress)
1060 return cbk->is_recovery_in_progress(cbk->context);
1061
1062 return false;
1063}
Mohit Khanna440c5292016-05-12 11:05:06 -07001064#if defined(HIF_PCI) || defined(SNOC) || defined(HIF_AHB)
Houston Hoffman56e0d702016-05-05 17:48:06 -07001065/**
1066 * hif_batch_send() - API to access hif specific function
1067 * ce_batch_send.
1068 * @osc: HIF Context
1069 * @msdu : list of msdus to be sent
1070 * @transfer_id : transfer id
1071 * @len : donwloaded length
1072 *
1073 * Return: list of msds not sent
1074 */
1075qdf_nbuf_t hif_batch_send(struct hif_opaque_softc *osc, qdf_nbuf_t msdu,
1076 uint32_t transfer_id, u_int32_t len, uint32_t sendhead)
1077{
1078 void *ce_tx_hdl = hif_get_ce_handle(osc, CE_HTT_TX_CE);
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05301079
Houston Hoffman56e0d702016-05-05 17:48:06 -07001080 return ce_batch_send((struct CE_handle *)ce_tx_hdl, msdu, transfer_id,
1081 len, sendhead);
1082}
1083
1084/**
1085 * hif_update_tx_ring() - API to access hif specific function
1086 * ce_update_tx_ring.
1087 * @osc: HIF Context
1088 * @num_htt_cmpls : number of htt compl received.
1089 *
1090 * Return: void
1091 */
1092void hif_update_tx_ring(struct hif_opaque_softc *osc, u_int32_t num_htt_cmpls)
1093{
1094 void *ce_tx_hdl = hif_get_ce_handle(osc, CE_HTT_TX_CE);
Manikandan Mohanbd0ef8a2017-04-10 13:10:21 -07001095
Houston Hoffman56e0d702016-05-05 17:48:06 -07001096 ce_update_tx_ring(ce_tx_hdl, num_htt_cmpls);
1097}
1098
1099
1100/**
1101 * hif_send_single() - API to access hif specific function
1102 * ce_send_single.
1103 * @osc: HIF Context
1104 * @msdu : msdu to be sent
1105 * @transfer_id: transfer id
1106 * @len : downloaded length
1107 *
1108 * Return: msdu sent status
1109 */
1110int hif_send_single(struct hif_opaque_softc *osc, qdf_nbuf_t msdu, uint32_t
1111 transfer_id, u_int32_t len)
1112{
1113 void *ce_tx_hdl = hif_get_ce_handle(osc, CE_HTT_TX_CE);
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05301114
Houston Hoffman56e0d702016-05-05 17:48:06 -07001115 return ce_send_single((struct CE_handle *)ce_tx_hdl, msdu, transfer_id,
1116 len);
1117}
1118
1119/**
1120 * hif_send_fast() - API to access hif specific function
1121 * ce_send_fast.
1122 * @osc: HIF Context
1123 * @msdu : array of msdus to be sent
1124 * @num_msdus : number of msdus in an array
1125 * @transfer_id: transfer id
Nirav Shahda0881a2016-05-16 10:45:16 +05301126 * @download_len: download length
Houston Hoffman56e0d702016-05-05 17:48:06 -07001127 *
1128 * Return: No. of packets that could be sent
1129 */
Nirav Shahda0881a2016-05-16 10:45:16 +05301130int hif_send_fast(struct hif_opaque_softc *osc, qdf_nbuf_t nbuf,
1131 uint32_t transfer_id, uint32_t download_len)
Houston Hoffman56e0d702016-05-05 17:48:06 -07001132{
1133 void *ce_tx_hdl = hif_get_ce_handle(osc, CE_HTT_TX_CE);
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05301134
Nirav Shahda0881a2016-05-16 10:45:16 +05301135 return ce_send_fast((struct CE_handle *)ce_tx_hdl, nbuf,
1136 transfer_id, download_len);
Houston Hoffman56e0d702016-05-05 17:48:06 -07001137}
Mohit Khanna440c5292016-05-12 11:05:06 -07001138#endif
Houston Hoffman56e0d702016-05-05 17:48:06 -07001139
1140/**
1141 * hif_reg_write() - API to access hif specific function
1142 * hif_write32_mb.
1143 * @hif_ctx : HIF Context
1144 * @offset : offset on which value has to be written
1145 * @value : value to be written
1146 *
1147 * Return: None
1148 */
1149void hif_reg_write(struct hif_opaque_softc *hif_ctx, uint32_t offset,
1150 uint32_t value)
1151{
1152 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Manikandan Mohanbd0ef8a2017-04-10 13:10:21 -07001153
Houston Hoffman56e0d702016-05-05 17:48:06 -07001154 hif_write32_mb(scn->mem + offset, value);
1155
1156}
1157
1158/**
1159 * hif_reg_read() - API to access hif specific function
1160 * hif_read32_mb.
1161 * @hif_ctx : HIF Context
1162 * @offset : offset from which value has to be read
1163 *
1164 * Return: Read value
1165 */
1166uint32_t hif_reg_read(struct hif_opaque_softc *hif_ctx, uint32_t offset)
1167{
1168
1169 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Manikandan Mohanbd0ef8a2017-04-10 13:10:21 -07001170
Houston Hoffman56e0d702016-05-05 17:48:06 -07001171 return hif_read32_mb(scn->mem + offset);
1172}
Mohit Khanna440c5292016-05-12 11:05:06 -07001173
1174#if defined(HIF_USB)
1175/**
1176 * hif_ramdump_handler(): generic ramdump handler
1177 * @scn: struct hif_opaque_softc
1178 *
1179 * Return: None
1180 */
1181
1182void hif_ramdump_handler(struct hif_opaque_softc *scn)
1183
1184{
1185 if (hif_get_bus_type == QDF_BUS_TYPE_USB)
1186 hif_usb_ramdump_handler();
1187}
1188#endif
Venkateswara Swamy Bandaru31108f32016-08-08 18:04:29 +05301189