blob: 6186e949b233afb5c5e9b8e269e27eb88cc6a850 [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"
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080053
Komal Seelam5584a7c2016-02-24 19:22:48 +053054void hif_dump(struct hif_opaque_softc *hif_ctx, uint8_t cmd_id, bool start)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080055{
Poddar, Siddarthe41943f2016-04-27 15:33:48 +053056 hif_trigger_dump(hif_ctx, cmd_id, start);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080057}
58
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080059/**
60 * hif_get_target_id(): hif_get_target_id
61 *
62 * Return the virtual memory base address to the caller
63 *
Komal Seelam644263d2016-02-22 20:45:49 +053064 * @scn: hif_softc
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080065 *
66 * Return: A_target_id_t
67 */
Komal Seelam644263d2016-02-22 20:45:49 +053068A_target_id_t hif_get_target_id(struct hif_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080069{
70 return scn->mem;
71}
72
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080073/**
74 * hif_get_targetdef(): hif_get_targetdef
75 * @scn: scn
76 *
77 * Return: void *
78 */
Komal Seelam5584a7c2016-02-24 19:22:48 +053079void *hif_get_targetdef(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080080{
Komal Seelam644263d2016-02-22 20:45:49 +053081 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
82
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080083 return scn->targetdef;
84}
85
86/**
87 * hif_vote_link_down(): unvote for link up
88 *
89 * Call hif_vote_link_down to release a previous request made using
90 * hif_vote_link_up. A hif_vote_link_down call should only be made
91 * after a corresponding hif_vote_link_up, otherwise you could be
92 * negating a vote from another source. When no votes are present
93 * hif will not guarantee the linkstate after hif_bus_suspend.
94 *
95 * SYNCHRONIZE WITH hif_vote_link_up by only calling in MC thread
96 * and initialization deinitialization sequencences.
97 *
98 * Return: n/a
99 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530100void hif_vote_link_down(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800101{
Komal Seelam644263d2016-02-22 20:45:49 +0530102 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800103
Manikandan Mohanbd0ef8a2017-04-10 13:10:21 -0700104 QDF_BUG(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800105 scn->linkstate_vote--;
106 if (scn->linkstate_vote == 0)
Houston Hoffmancceec342015-11-11 11:37:20 -0800107 hif_bus_prevent_linkdown(scn, false);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800108}
109
110/**
111 * hif_vote_link_up(): vote to prevent bus from suspending
112 *
113 * Makes hif guarantee that fw can message the host normally
114 * durring suspend.
115 *
116 * SYNCHRONIZE WITH hif_vote_link_up by only calling in MC thread
117 * and initialization deinitialization sequencences.
118 *
119 * Return: n/a
120 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530121void hif_vote_link_up(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800122{
Komal Seelam644263d2016-02-22 20:45:49 +0530123 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800124
Manikandan Mohanbd0ef8a2017-04-10 13:10:21 -0700125 QDF_BUG(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800126 scn->linkstate_vote++;
127 if (scn->linkstate_vote == 1)
Houston Hoffmancceec342015-11-11 11:37:20 -0800128 hif_bus_prevent_linkdown(scn, true);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800129}
130
131/**
132 * hif_can_suspend_link(): query if hif is permitted to suspend the link
133 *
134 * Hif will ensure that the link won't be suspended if the upperlayers
135 * don't want it to.
136 *
137 * SYNCHRONIZATION: MC thread is stopped before bus suspend thus
138 * we don't need extra locking to ensure votes dont change while
139 * we are in the process of suspending or resuming.
140 *
141 * Return: false if hif will guarantee link up durring suspend.
142 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530143bool hif_can_suspend_link(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800144{
Komal Seelam644263d2016-02-22 20:45:49 +0530145 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800146
Manikandan Mohanbd0ef8a2017-04-10 13:10:21 -0700147 QDF_BUG(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800148 return scn->linkstate_vote == 0;
149}
150
Houston Hoffman4f529982016-05-05 16:11:04 -0700151#ifndef CONFIG_WIN
152#define QCA9984_HOST_INTEREST_ADDRESS -1
153#define QCA9888_HOST_INTEREST_ADDRESS -1
154#define IPQ4019_HOST_INTEREST_ADDRESS -1
155#endif
156
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800157/**
158 * hif_hia_item_address(): hif_hia_item_address
159 * @target_type: target_type
160 * @item_offset: item_offset
161 *
162 * Return: n/a
163 */
164uint32_t hif_hia_item_address(uint32_t target_type, uint32_t item_offset)
165{
166 switch (target_type) {
167 case TARGET_TYPE_AR6002:
168 return AR6002_HOST_INTEREST_ADDRESS + item_offset;
169 case TARGET_TYPE_AR6003:
170 return AR6003_HOST_INTEREST_ADDRESS + item_offset;
171 case TARGET_TYPE_AR6004:
172 return AR6004_HOST_INTEREST_ADDRESS + item_offset;
173 case TARGET_TYPE_AR6006:
174 return AR6006_HOST_INTEREST_ADDRESS + item_offset;
175 case TARGET_TYPE_AR9888:
176 return AR9888_HOST_INTEREST_ADDRESS + item_offset;
177 case TARGET_TYPE_AR6320:
178 case TARGET_TYPE_AR6320V2:
179 return AR6320_HOST_INTEREST_ADDRESS + item_offset;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800180 case TARGET_TYPE_ADRASTEA:
181 /* ADRASTEA doesn't have a host interest address */
182 ASSERT(0);
183 return 0;
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700184 case TARGET_TYPE_AR900B:
185 return AR900B_HOST_INTEREST_ADDRESS + item_offset;
186 case TARGET_TYPE_QCA9984:
187 return QCA9984_HOST_INTEREST_ADDRESS + item_offset;
188 case TARGET_TYPE_QCA9888:
189 return QCA9888_HOST_INTEREST_ADDRESS + item_offset;
190 case TARGET_TYPE_IPQ4019:
191 return IPQ4019_HOST_INTEREST_ADDRESS + item_offset;
192
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800193 default:
194 ASSERT(0);
195 return 0;
196 }
197}
198
199/**
200 * hif_max_num_receives_reached() - check max receive is reached
Komal Seelambd7c51d2016-02-24 10:27:30 +0530201 * @scn: HIF Context
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800202 * @count: unsigned int.
203 *
204 * Output check status as bool
205 *
206 * Return: bool
207 */
Komal Seelambd7c51d2016-02-24 10:27:30 +0530208bool hif_max_num_receives_reached(struct hif_softc *scn, unsigned int count)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800209{
Houston Hoffman75ef5a52016-04-14 17:15:49 -0700210 if (QDF_IS_EPPING_ENABLED(hif_get_conparam(scn)))
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800211 return count > 120;
212 else
213 return count > MAX_NUM_OF_RECEIVES;
214}
215
216/**
217 * init_buffer_count() - initial buffer count
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530218 * @maxSize: qdf_size_t
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800219 *
220 * routine to modify the initial buffer count to be allocated on an os
221 * platform basis. Platform owner will need to modify this as needed
222 *
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530223 * Return: qdf_size_t
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800224 */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530225qdf_size_t init_buffer_count(qdf_size_t maxSize)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800226{
227 return maxSize;
228}
229
230/**
Nirav Shahd7f91592016-04-21 14:18:43 +0530231 * hif_save_htc_htt_config_endpoint() - save htt_tx_endpoint
232 * @hif_ctx: hif context
233 * @htc_htt_tx_endpoint: htt_tx_endpoint
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800234 *
235 * Return: void
236 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530237void hif_save_htc_htt_config_endpoint(struct hif_opaque_softc *hif_ctx,
Nirav Shahd7f91592016-04-21 14:18:43 +0530238 int htc_htt_tx_endpoint)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800239{
Komal Seelam644263d2016-02-22 20:45:49 +0530240 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800241
242 if (!scn) {
243 HIF_ERROR("%s: error: scn or scn->hif_sc is NULL!",
244 __func__);
245 return;
246 }
247
Nirav Shahd7f91592016-04-21 14:18:43 +0530248 scn->htc_htt_tx_endpoint = htc_htt_tx_endpoint;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800249}
250
Houston Hoffmanec93ab02016-05-03 20:09:55 -0700251static const struct qwlan_hw qwlan_hw_list[] = {
252 {
253 .id = AR6320_REV1_VERSION,
254 .subid = 0,
255 .name = "QCA6174_REV1",
256 },
257 {
258 .id = AR6320_REV1_1_VERSION,
259 .subid = 0x1,
260 .name = "QCA6174_REV1_1",
261 },
262 {
263 .id = AR6320_REV1_3_VERSION,
264 .subid = 0x2,
265 .name = "QCA6174_REV1_3",
266 },
267 {
268 .id = AR6320_REV2_1_VERSION,
269 .subid = 0x4,
270 .name = "QCA6174_REV2_1",
271 },
272 {
273 .id = AR6320_REV2_1_VERSION,
274 .subid = 0x5,
275 .name = "QCA6174_REV2_2",
276 },
277 {
278 .id = AR6320_REV3_VERSION,
279 .subid = 0x6,
280 .name = "QCA6174_REV2.3",
281 },
282 {
283 .id = AR6320_REV3_VERSION,
284 .subid = 0x8,
285 .name = "QCA6174_REV3",
286 },
287 {
288 .id = AR6320_REV3_VERSION,
289 .subid = 0x9,
290 .name = "QCA6174_REV3_1",
291 },
292 {
293 .id = AR6320_REV3_2_VERSION,
294 .subid = 0xA,
295 .name = "AR6320_REV3_2_VERSION",
Houston Hoffmancd0884a2016-08-24 15:30:09 -0700296 },
297 {
298 .id = WCN3990_v1,
299 .subid = 0x0,
300 .name = "WCN3990_V1",
Houston Hoffmandd4da482016-10-17 12:41:45 -0700301 },
302 {
303 .id = WCN3990_v2,
304 .subid = 0x0,
305 .name = "WCN3990_V2",
Houston Hoffman59fd2452016-11-19 17:27:10 -0800306 },
307 {
308 .id = WCN3990_v2_1,
309 .subid = 0x0,
310 .name = "WCN3990_V2.1",
Yingying Tangd8921742016-10-18 18:13:07 +0800311 },
312 {
313 .id = QCA9379_REV1_VERSION,
314 .subid = 0xC,
315 .name = "QCA9379_REV1",
Yingying Tang80404362016-10-20 23:29:57 +0800316 },
317 {
318 .id = QCA9379_REV1_VERSION,
319 .subid = 0xD,
320 .name = "QCA9379_REV1_1",
Houston Hoffmanec93ab02016-05-03 20:09:55 -0700321 }
322};
323
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800324/**
325 * hif_get_hw_name(): get a human readable name for the hardware
Komal Seelam91553ce2016-01-27 18:57:10 +0530326 * @info: Target Info
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800327 *
Komal Seelam91553ce2016-01-27 18:57:10 +0530328 * Return: human readable name for the underlying wifi hardware.
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800329 */
Komal Seelam91553ce2016-01-27 18:57:10 +0530330static const char *hif_get_hw_name(struct hif_target_info *info)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800331{
332 int i;
Komal Seelam91553ce2016-01-27 18:57:10 +0530333
Houston Hoffman60af6752016-11-21 12:13:36 -0800334 if (info->hw_name)
335 return info->hw_name;
336
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800337 for (i = 0; i < ARRAY_SIZE(qwlan_hw_list); i++) {
Komal Seelam91553ce2016-01-27 18:57:10 +0530338 if (info->target_version == qwlan_hw_list[i].id &&
339 info->target_revision == qwlan_hw_list[i].subid) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800340 return qwlan_hw_list[i].name;
341 }
342 }
343
Houston Hoffman60af6752016-11-21 12:13:36 -0800344 info->hw_name = qdf_mem_malloc(64);
345 if (!info->hw_name)
346 return "Unknown Device (nomem)";
347
348 i = qdf_snprint(info->hw_name, 64, "HW_VERSION=%x.",
349 info->target_version);
350 if (i < 0)
351 return "Unknown Device (snprintf failure)";
352 else
353 return info->hw_name;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800354}
355
356/**
357 * hif_get_hw_info(): hif_get_hw_info
358 * @scn: scn
359 * @version: version
360 * @revision: revision
361 *
362 * Return: n/a
363 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530364void hif_get_hw_info(struct hif_opaque_softc *scn, u32 *version, u32 *revision,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800365 const char **target_name)
366{
Komal Seelam91553ce2016-01-27 18:57:10 +0530367 struct hif_target_info *info = hif_get_target_info_handle(scn);
Mohit Khanna440c5292016-05-12 11:05:06 -0700368 struct hif_softc *sc = HIF_GET_SOFTC(scn);
369
370 if (sc->bus_type == QDF_BUS_TYPE_USB)
371 hif_usb_get_hw_info(sc);
372
Komal Seelam91553ce2016-01-27 18:57:10 +0530373 *version = info->target_version;
374 *revision = info->target_revision;
375 *target_name = hif_get_hw_name(info);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800376}
377
378/**
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530379 * hif_get_dev_ba(): API to get device base address.
380 * @scn: scn
381 * @version: version
382 * @revision: revision
383 *
384 * Return: n/a
385 */
386void *hif_get_dev_ba(struct hif_opaque_softc *hif_handle)
387{
388 struct hif_softc *scn = (struct hif_softc *)hif_handle;
389
390 return scn->mem;
391}
392/**
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800393 * hif_open(): hif_open
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530394 * @qdf_ctx: QDF Context
Komal Seelambd7c51d2016-02-24 10:27:30 +0530395 * @mode: Driver Mode
396 * @bus_type: Bus Type
397 * @cbk: CDS Callbacks
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800398 *
Komal Seelambd7c51d2016-02-24 10:27:30 +0530399 * API to open HIF Context
400 *
401 * Return: HIF Opaque Pointer
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800402 */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530403struct hif_opaque_softc *hif_open(qdf_device_t qdf_ctx, uint32_t mode,
404 enum qdf_bus_type bus_type,
Komal Seelam75080122016-03-02 15:18:25 +0530405 struct hif_driver_state_callbacks *cbk)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800406{
Komal Seelam644263d2016-02-22 20:45:49 +0530407 struct hif_softc *scn;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530408 QDF_STATUS status = QDF_STATUS_SUCCESS;
Houston Hoffman162164c2016-03-14 21:12:10 -0700409 int bus_context_size = hif_bus_get_context_size(bus_type);
410
411 if (bus_context_size == 0) {
412 HIF_ERROR("%s: context size 0 not allowed", __func__);
413 return NULL;
414 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800415
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530416 scn = (struct hif_softc *)qdf_mem_malloc(bus_context_size);
Komal Seelambd7c51d2016-02-24 10:27:30 +0530417 if (!scn) {
418 HIF_ERROR("%s: cannot alloc memory for HIF context of size:%d",
419 __func__, bus_context_size);
420 return GET_HIF_OPAQUE_HDL(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800421 }
422
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530423 scn->qdf_dev = qdf_ctx;
Komal Seelambd7c51d2016-02-24 10:27:30 +0530424 scn->hif_con_param = mode;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530425 qdf_atomic_init(&scn->active_tasklet_cnt);
Venkateswara Swamy Bandaru31108f32016-08-08 18:04:29 +0530426 qdf_atomic_init(&scn->active_grp_tasklet_cnt);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530427 qdf_atomic_init(&scn->link_suspended);
428 qdf_atomic_init(&scn->tasklet_from_intr);
Manikandan Mohanbd0ef8a2017-04-10 13:10:21 -0700429 qdf_mem_copy(&scn->callbacks, cbk,
430 sizeof(struct hif_driver_state_callbacks));
Houston Hoffman3db96a42016-05-05 19:54:39 -0700431 scn->bus_type = bus_type;
Houston Hoffman3cfe6862016-01-08 10:33:55 -0800432 status = hif_bus_open(scn, bus_type);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530433 if (status != QDF_STATUS_SUCCESS) {
Houston Hoffman3cfe6862016-01-08 10:33:55 -0800434 HIF_ERROR("%s: hif_bus_open error = %d, bus_type = %d",
435 __func__, status, bus_type);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530436 qdf_mem_free(scn);
Komal Seelambd7c51d2016-02-24 10:27:30 +0530437 scn = NULL;
Houston Hoffman3cfe6862016-01-08 10:33:55 -0800438 }
439
Komal Seelambd7c51d2016-02-24 10:27:30 +0530440 return GET_HIF_OPAQUE_HDL(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800441}
442
443/**
444 * hif_close(): hif_close
445 * @hif_ctx: hif_ctx
446 *
447 * Return: n/a
448 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530449void hif_close(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800450{
Komal Seelam644263d2016-02-22 20:45:49 +0530451 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800452
453 if (scn == NULL) {
Komal Seelam5584a7c2016-02-24 19:22:48 +0530454 HIF_ERROR("%s: hif_opaque_softc is NULL", __func__);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800455 return;
456 }
457
458 if (scn->athdiag_procfs_inited) {
459 athdiag_procfs_remove();
460 scn->athdiag_procfs_inited = false;
461 }
462
Houston Hoffman60af6752016-11-21 12:13:36 -0800463 if (scn->target_info.hw_name) {
464 char *hw_name = scn->target_info.hw_name;
Manikandan Mohanbd0ef8a2017-04-10 13:10:21 -0700465
Houston Hoffman60af6752016-11-21 12:13:36 -0800466 scn->target_info.hw_name = "ErrUnloading";
467 qdf_mem_free(hw_name);
468 }
469
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800470 hif_bus_close(scn);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530471 qdf_mem_free(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800472}
473
Houston Hoffman6fe60592016-11-18 13:12:08 -0800474#ifdef QCA_WIFI_QCA8074
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530475static QDF_STATUS hif_hal_attach(struct hif_softc *scn)
476{
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530477 if (ce_srng_based(scn)) {
478 scn->hal_soc = hal_attach(scn, scn->qdf_dev);
479 if (scn->hal_soc == NULL)
480 return QDF_STATUS_E_FAILURE;
481 }
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530482
483 return QDF_STATUS_SUCCESS;
484}
Houston Hoffman6fe60592016-11-18 13:12:08 -0800485#else
486static QDF_STATUS hif_hal_attach(struct hif_softc *scn)
487{
488 return QDF_STATUS_SUCCESS;
489}
490#endif
491
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800492/**
493 * hif_enable(): hif_enable
494 * @hif_ctx: hif_ctx
495 * @dev: dev
496 * @bdev: bus dev
497 * @bid: bus ID
498 * @bus_type: bus type
499 * @type: enable type
500 *
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530501 * Return: QDF_STATUS
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800502 */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530503QDF_STATUS hif_enable(struct hif_opaque_softc *hif_ctx, struct device *dev,
Manikandan Mohanbd0ef8a2017-04-10 13:10:21 -0700504 void *bdev,
505 const struct hif_bus_id *bid,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530506 enum qdf_bus_type bus_type,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800507 enum hif_enable_type type)
508{
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530509 QDF_STATUS status;
Komal Seelam644263d2016-02-22 20:45:49 +0530510 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800511
512 if (scn == NULL) {
513 HIF_ERROR("%s: hif_ctx = NULL", __func__);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530514 return QDF_STATUS_E_NULL_VALUE;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800515 }
516
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800517 status = hif_enable_bus(scn, dev, bdev, bid, type);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530518 if (status != QDF_STATUS_SUCCESS) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800519 HIF_ERROR("%s: hif_enable_bus error = %d",
520 __func__, status);
521 return status;
522 }
523
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530524 status = hif_hal_attach(scn);
525 if (status != QDF_STATUS_SUCCESS) {
526 HIF_ERROR("%s: hal attach failed", __func__);
527 return status;
528 }
529
Houston Hoffman108da402016-03-14 21:11:24 -0700530 if (hif_bus_configure(scn)) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800531 HIF_ERROR("%s: Target probe failed.", __func__);
Vishwajith Upendra3f78aa62016-02-09 17:53:02 +0530532 hif_disable_bus(scn);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530533 status = QDF_STATUS_E_FAILURE;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800534 return status;
535 }
Houston Hoffman108da402016-03-14 21:11:24 -0700536
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800537 /*
538 * Flag to avoid potential unallocated memory access from MSI
539 * interrupt handler which could get scheduled as soon as MSI
540 * is enabled, i.e to take care of the race due to the order
541 * in where MSI is enabled before the memory, that will be
542 * in interrupt handlers, is allocated.
543 */
544
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800545 scn->hif_init_done = true;
546
Mohit Khanna440c5292016-05-12 11:05:06 -0700547 HIF_TRACE("%s: OK", __func__);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800548
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530549 return QDF_STATUS_SUCCESS;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800550}
551
Komal Seelam5584a7c2016-02-24 19:22:48 +0530552void hif_disable(struct hif_opaque_softc *hif_ctx, enum hif_disable_type type)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800553{
Komal Seelam644263d2016-02-22 20:45:49 +0530554 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800555
556 if (!scn)
557 return;
558
559 hif_nointrs(scn);
560 if (scn->hif_init_done == false)
Poddar, Siddarthe41943f2016-04-27 15:33:48 +0530561 hif_shutdown_device(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800562 else
Komal Seelam644263d2016-02-22 20:45:49 +0530563 hif_stop(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800564
Vishwajith Upendra3f78aa62016-02-09 17:53:02 +0530565 hif_disable_bus(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800566
Komal Seelambd7c51d2016-02-24 10:27:30 +0530567 hif_wlan_disable(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800568
569 scn->notice_send = false;
570
571 HIF_INFO("%s: X", __func__);
572}
573
Nirav Shahb70bd732016-05-25 14:31:51 +0530574void hif_display_stats(struct hif_opaque_softc *hif_ctx)
575{
576 hif_display_bus_stats(hif_ctx);
577}
578
579void hif_clear_stats(struct hif_opaque_softc *hif_ctx)
580{
581 hif_clear_bus_stats(hif_ctx);
582}
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800583
584/**
Govind Singh2443fb32016-01-13 17:44:48 +0530585 * hif_crash_shutdown_dump_bus_register() - dump bus registers
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800586 * @hif_ctx: hif_ctx
587 *
588 * Return: n/a
589 */
590#if defined(TARGET_RAMDUMP_AFTER_KERNEL_PANIC) \
Houston Hoffmanbc693492016-03-14 21:11:41 -0700591&& defined(DEBUG)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800592
Govind Singh2443fb32016-01-13 17:44:48 +0530593static void hif_crash_shutdown_dump_bus_register(void *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800594{
Komal Seelam5584a7c2016-02-24 19:22:48 +0530595 struct hif_opaque_softc *scn = hif_ctx;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800596
Govind Singh2443fb32016-01-13 17:44:48 +0530597 if (hif_check_soc_status(scn))
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800598 return;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800599
Govind Singh2443fb32016-01-13 17:44:48 +0530600 if (hif_dump_registers(scn))
601 HIF_ERROR("Failed to dump bus registers!");
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800602}
603
604/**
605 * hif_crash_shutdown(): hif_crash_shutdown
606 *
607 * This function is called by the platform driver to dump CE registers
608 *
609 * @hif_ctx: hif_ctx
610 *
611 * Return: n/a
612 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530613void hif_crash_shutdown(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800614{
Komal Seelam644263d2016-02-22 20:45:49 +0530615 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800616
Houston Hoffmanbc693492016-03-14 21:11:41 -0700617 if (!hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800618 return;
619
Houston Hoffmanbc693492016-03-14 21:11:41 -0700620 if (scn->bus_type == QDF_BUS_TYPE_SNOC) {
621 HIF_INFO_MED("%s: RAM dump disabled for bustype %d",
622 __func__, scn->bus_type);
623 return;
624 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800625
Komal Seelam6ee55902016-04-11 17:11:07 +0530626 if (TARGET_STATUS_RESET == scn->target_status) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800627 HIF_INFO_MED("%s: Target is already asserted, ignore!",
628 __func__);
629 return;
630 }
631
Komal Seelambd7c51d2016-02-24 10:27:30 +0530632 if (hif_is_load_or_unload_in_progress(scn)) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800633 HIF_ERROR("%s: Load/unload is in progress, ignore!", __func__);
634 return;
635 }
636
Govind Singh2443fb32016-01-13 17:44:48 +0530637 hif_crash_shutdown_dump_bus_register(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800638
Komal Seelam644263d2016-02-22 20:45:49 +0530639 if (ol_copy_ramdump(hif_ctx))
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800640 goto out;
641
642 HIF_INFO_MED("%s: RAM dump collecting completed!", __func__);
643
644out:
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800645 return;
646}
647#else
Komal Seelam5584a7c2016-02-24 19:22:48 +0530648void hif_crash_shutdown(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800649{
650 HIF_INFO_MED("%s: Collecting target RAM dump disabled",
651 __func__);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800652}
653#endif /* TARGET_RAMDUMP_AFTER_KERNEL_PANIC */
654
655#ifdef QCA_WIFI_3_0
656/**
657 * hif_check_fw_reg(): hif_check_fw_reg
658 * @scn: scn
659 * @state:
660 *
661 * Return: int
662 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530663int hif_check_fw_reg(struct hif_opaque_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800664{
665 return 0;
666}
667#endif
668
669#ifdef IPA_OFFLOAD
670/**
671 * hif_read_phy_mem_base(): hif_read_phy_mem_base
672 * @scn: scn
673 * @phy_mem_base: physical mem base
674 *
675 * Return: n/a
676 */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530677void hif_read_phy_mem_base(struct hif_softc *scn, qdf_dma_addr_t *phy_mem_base)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800678{
679 *phy_mem_base = scn->mem_pa;
680}
681#endif /* IPA_OFFLOAD */
682
683/**
684 * hif_get_device_type(): hif_get_device_type
685 * @device_id: device_id
686 * @revision_id: revision_id
687 * @hif_type: returned hif_type
688 * @target_type: returned target_type
689 *
690 * Return: int
691 */
692int hif_get_device_type(uint32_t device_id,
693 uint32_t revision_id,
694 uint32_t *hif_type, uint32_t *target_type)
695{
696 int ret = 0;
697
698 switch (device_id) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800699 case ADRASTEA_DEVICE_ID_P2_E12:
700
701 *hif_type = HIF_TYPE_ADRASTEA;
702 *target_type = TARGET_TYPE_ADRASTEA;
703 break;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800704
705 case AR9888_DEVICE_ID:
706 *hif_type = HIF_TYPE_AR9888;
707 *target_type = TARGET_TYPE_AR9888;
708 break;
709
710 case AR6320_DEVICE_ID:
711 switch (revision_id) {
712 case AR6320_FW_1_1:
713 case AR6320_FW_1_3:
714 *hif_type = HIF_TYPE_AR6320;
715 *target_type = TARGET_TYPE_AR6320;
716 break;
717
718 case AR6320_FW_2_0:
719 case AR6320_FW_3_0:
720 case AR6320_FW_3_2:
721 *hif_type = HIF_TYPE_AR6320V2;
722 *target_type = TARGET_TYPE_AR6320V2;
723 break;
724
725 default:
726 HIF_ERROR("%s: error - dev_id = 0x%x, rev_id = 0x%x",
727 __func__, device_id, revision_id);
728 ret = -ENODEV;
729 goto end;
730 }
731 break;
732
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700733 case AR9887_DEVICE_ID:
734 *hif_type = HIF_TYPE_AR9888;
735 *target_type = TARGET_TYPE_AR9888;
Houston Hoffmanc50572b2016-06-08 19:49:46 -0700736 HIF_INFO(" *********** AR9887 **************");
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700737 break;
738
739 case QCA9984_DEVICE_ID:
740 *hif_type = HIF_TYPE_QCA9984;
741 *target_type = TARGET_TYPE_QCA9984;
Houston Hoffmanc50572b2016-06-08 19:49:46 -0700742 HIF_INFO(" *********** QCA9984 *************");
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700743 break;
744
745 case QCA9888_DEVICE_ID:
746 *hif_type = HIF_TYPE_QCA9888;
747 *target_type = TARGET_TYPE_QCA9888;
Houston Hoffmanc50572b2016-06-08 19:49:46 -0700748 HIF_INFO(" *********** QCA9888 *************");
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700749 break;
750
751 case AR900B_DEVICE_ID:
752 *hif_type = HIF_TYPE_AR900B;
753 *target_type = TARGET_TYPE_AR900B;
Houston Hoffmanc50572b2016-06-08 19:49:46 -0700754 HIF_INFO(" *********** AR900B *************");
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700755 break;
756
Houston Hoffman3db96a42016-05-05 19:54:39 -0700757 case IPQ4019_DEVICE_ID:
758 *hif_type = HIF_TYPE_IPQ4019;
759 *target_type = TARGET_TYPE_IPQ4019;
Houston Hoffmanc50572b2016-06-08 19:49:46 -0700760 HIF_INFO(" *********** IPQ4019 *************");
Houston Hoffman3db96a42016-05-05 19:54:39 -0700761 break;
762
Venkateswara Swamy Bandaru9fd9af02016-09-20 20:27:31 +0530763 case QCA8074_DEVICE_ID:
Karunakar Dasinenif61cb072016-09-29 11:50:45 -0700764 case RUMIM2M_DEVICE_ID_NODE0:
765 case RUMIM2M_DEVICE_ID_NODE1:
Sathish Kumar2d2f19a2017-02-13 15:52:07 +0530766 case RUMIM2M_DEVICE_ID_NODE2:
767 case RUMIM2M_DEVICE_ID_NODE3:
Venkateswara Swamy Bandaru9fd9af02016-09-20 20:27:31 +0530768 *hif_type = HIF_TYPE_QCA8074;
769 *target_type = TARGET_TYPE_QCA8074;
770 HIF_INFO(" *********** QCA8074 *************\n");
771 break;
772
Houston Hoffman31b25ec2016-09-19 13:12:30 -0700773 case QCA6290_EMULATION_DEVICE_ID:
774 *hif_type = HIF_TYPE_QCA6290;
775 *target_type = TARGET_TYPE_QCA6290;
776 HIF_INFO(" *********** QCA6290EMU *************\n");
777 break;
778
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800779 default:
780 HIF_ERROR("%s: Unsupported device ID!", __func__);
781 ret = -ENODEV;
782 break;
783 }
784end:
785 return ret;
786}
Komal Seelam91553ce2016-01-27 18:57:10 +0530787
788/**
Houston Hoffman26352592016-03-14 21:11:43 -0700789 * hif_needs_bmi() - return true if the soc needs bmi through the driver
790 * @hif_ctx: hif context
791 *
792 * Return: true if the soc needs driver bmi otherwise false
793 */
794bool hif_needs_bmi(struct hif_opaque_softc *hif_ctx)
795{
796 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
Pratik Gandhi815c6d82016-10-19 12:06:32 +0530797
Houston Hoffman6c0c3f92016-09-27 18:05:39 -0700798 return (hif_sc->bus_type != QDF_BUS_TYPE_SNOC) &&
799 !ce_srng_based(hif_sc);
Houston Hoffman26352592016-03-14 21:11:43 -0700800}
801
802/**
Houston Hoffman60a1eeb2016-03-14 21:11:44 -0700803 * hif_get_bus_type() - return the bus type
804 *
805 * Return: enum qdf_bus_type
806 */
807enum qdf_bus_type hif_get_bus_type(struct hif_opaque_softc *hif_hdl)
808{
809 struct hif_softc *scn = HIF_GET_SOFTC(hif_hdl);
Manikandan Mohanbd0ef8a2017-04-10 13:10:21 -0700810
Houston Hoffman60a1eeb2016-03-14 21:11:44 -0700811 return scn->bus_type;
812}
813
814/**
Komal Seelam91553ce2016-01-27 18:57:10 +0530815 * Target info and ini parameters are global to the driver
816 * Hence these structures are exposed to all the modules in
817 * the driver and they don't need to maintains multiple copies
818 * of the same info, instead get the handle from hif and
819 * modify them in hif
820 */
821
822/**
823 * hif_get_ini_handle() - API to get hif_config_param handle
Komal Seelam644263d2016-02-22 20:45:49 +0530824 * @hif_ctx: HIF Context
Komal Seelam91553ce2016-01-27 18:57:10 +0530825 *
826 * Return: pointer to hif_config_info
827 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530828struct hif_config_info *hif_get_ini_handle(struct hif_opaque_softc *hif_ctx)
Komal Seelam91553ce2016-01-27 18:57:10 +0530829{
Komal Seelam644263d2016-02-22 20:45:49 +0530830 struct hif_softc *sc = HIF_GET_SOFTC(hif_ctx);
831
832 return &sc->hif_config;
Komal Seelam91553ce2016-01-27 18:57:10 +0530833}
834
835/**
836 * hif_get_target_info_handle() - API to get hif_target_info handle
Komal Seelam644263d2016-02-22 20:45:49 +0530837 * @hif_ctx: HIF context
Komal Seelam91553ce2016-01-27 18:57:10 +0530838 *
839 * Return: Pointer to hif_target_info
840 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530841struct hif_target_info *hif_get_target_info_handle(
842 struct hif_opaque_softc *hif_ctx)
Komal Seelam91553ce2016-01-27 18:57:10 +0530843{
Komal Seelam644263d2016-02-22 20:45:49 +0530844 struct hif_softc *sc = HIF_GET_SOFTC(hif_ctx);
845
846 return &sc->target_info;
847
Komal Seelam91553ce2016-01-27 18:57:10 +0530848}
Komal Seelamc92a0cf2016-02-22 20:43:52 +0530849
850#if defined(FEATURE_LRO)
851/**
852 * hif_lro_flush_cb_register - API to register for LRO Flush Callback
853 * @scn: HIF Context
854 * @handler: Function pointer to be called by HIF
855 * @data: Private data to be used by the module registering to HIF
856 *
857 * Return: void
858 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530859void hif_lro_flush_cb_register(struct hif_opaque_softc *scn,
Manjunathappa Prakash2146da32016-10-13 14:47:47 -0700860 void (lro_flush_handler)(void *),
861 void *(lro_init_handler)(void))
Komal Seelamc92a0cf2016-02-22 20:43:52 +0530862{
Manjunathappa Prakash2146da32016-10-13 14:47:47 -0700863 if (hif_napi_enabled(scn, -1))
864 hif_napi_lro_flush_cb_register(scn, lro_flush_handler,
865 lro_init_handler);
866 else
867 ce_lro_flush_cb_register(scn, lro_flush_handler,
868 lro_init_handler);
869}
870
871/**
872 * hif_get_lro_info - Returns LRO instance for instance ID
873 * @ctx_id: LRO instance ID
874 * @hif_hdl: HIF Context
875 *
876 * Return: Pointer to LRO instance.
877 */
878void *hif_get_lro_info(int ctx_id, struct hif_opaque_softc *hif_hdl)
879{
880 void *data;
881
882 if (hif_napi_enabled(hif_hdl, -1))
883 data = hif_napi_get_lro_info(hif_hdl, ctx_id);
884 else
885 data = hif_ce_get_lro_ctx(hif_hdl, ctx_id);
886
887 return data;
888}
889
890/**
891 * hif_get_rx_ctx_id - Returns LRO instance ID based on underlying LRO instance
892 * @ctx_id: LRO context ID
893 * @hif_hdl: HIF Context
894 *
895 * Return: LRO instance ID
896 */
897int hif_get_rx_ctx_id(int ctx_id, struct hif_opaque_softc *hif_hdl)
898{
899 if (hif_napi_enabled(hif_hdl, -1))
900 return NAPI_PIPE2ID(ctx_id);
901 else
902 return ctx_id;
Komal Seelamc92a0cf2016-02-22 20:43:52 +0530903}
904
905/**
906 * hif_lro_flush_cb_deregister - API to deregister for LRO Flush Callbacks
Manjunathappa Prakash2146da32016-10-13 14:47:47 -0700907 * @hif_hdl: HIF Context
908 * @lro_deinit_cb: LRO deinit callback
Komal Seelamc92a0cf2016-02-22 20:43:52 +0530909 *
910 * Return: void
911 */
Manjunathappa Prakash2146da32016-10-13 14:47:47 -0700912void hif_lro_flush_cb_deregister(struct hif_opaque_softc *hif_hdl,
913 void (lro_deinit_cb)(void *))
Komal Seelamc92a0cf2016-02-22 20:43:52 +0530914{
Manjunathappa Prakash2146da32016-10-13 14:47:47 -0700915 if (hif_napi_enabled(hif_hdl, -1))
916 hif_napi_lro_flush_cb_deregister(hif_hdl, lro_deinit_cb);
917 else
918 ce_lro_flush_cb_deregister(hif_hdl, lro_deinit_cb);
919}
920#else /* !defined(FEATURE_LRO) */
921int hif_get_rx_ctx_id(int ctx_id, struct hif_opaque_softc *hif_hdl)
922{
923 return 0;
Komal Seelamc92a0cf2016-02-22 20:43:52 +0530924}
925#endif
Komal Seelam644263d2016-02-22 20:45:49 +0530926
927/**
928 * hif_get_target_status - API to get target status
929 * @hif_ctx: HIF Context
930 *
Komal Seelam6ee55902016-04-11 17:11:07 +0530931 * Return: enum hif_target_status
Komal Seelam644263d2016-02-22 20:45:49 +0530932 */
Komal Seelam6ee55902016-04-11 17:11:07 +0530933enum hif_target_status hif_get_target_status(struct hif_opaque_softc *hif_ctx)
Komal Seelam644263d2016-02-22 20:45:49 +0530934{
935 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
936
937 return scn->target_status;
938}
939
940/**
Komal Seelama5911d32016-02-24 19:21:59 +0530941 * hif_set_target_status() - API to set target status
Komal Seelam644263d2016-02-22 20:45:49 +0530942 * @hif_ctx: HIF Context
943 * @status: Target Status
944 *
945 * Return: void
946 */
Komal Seelam6ee55902016-04-11 17:11:07 +0530947void hif_set_target_status(struct hif_opaque_softc *hif_ctx, enum
948 hif_target_status status)
Komal Seelam644263d2016-02-22 20:45:49 +0530949{
950 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
951
952 scn->target_status = status;
953}
Komal Seelama5911d32016-02-24 19:21:59 +0530954
955/**
956 * hif_init_ini_config() - API to initialize HIF configuration parameters
957 * @hif_ctx: HIF Context
958 * @cfg: HIF Configuration
959 *
960 * Return: void
961 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530962void hif_init_ini_config(struct hif_opaque_softc *hif_ctx,
963 struct hif_config_info *cfg)
Komal Seelama5911d32016-02-24 19:21:59 +0530964{
965 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
966
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530967 qdf_mem_copy(&scn->hif_config, cfg, sizeof(struct hif_config_info));
Komal Seelama5911d32016-02-24 19:21:59 +0530968}
Komal Seelambd7c51d2016-02-24 10:27:30 +0530969
970/**
971 * hif_get_conparam() - API to get driver mode in HIF
972 * @scn: HIF Context
973 *
974 * Return: driver mode of operation
975 */
976uint32_t hif_get_conparam(struct hif_softc *scn)
977{
978 if (!scn)
979 return 0;
980
981 return scn->hif_con_param;
982}
983
984/**
985 * hif_get_callbacks_handle() - API to get callbacks Handle
986 * @scn: HIF Context
987 *
988 * Return: pointer to HIF Callbacks
989 */
Manikandan Mohanbd0ef8a2017-04-10 13:10:21 -0700990struct hif_driver_state_callbacks *hif_get_callbacks_handle(
991 struct hif_softc *scn)
Komal Seelambd7c51d2016-02-24 10:27:30 +0530992{
993 return &scn->callbacks;
994}
995
996/**
997 * hif_is_driver_unloading() - API to query upper layers if driver is unloading
998 * @scn: HIF Context
999 *
1000 * Return: True/False
1001 */
1002bool hif_is_driver_unloading(struct hif_softc *scn)
1003{
Komal Seelam75080122016-03-02 15:18:25 +05301004 struct hif_driver_state_callbacks *cbk = hif_get_callbacks_handle(scn);
Komal Seelambd7c51d2016-02-24 10:27:30 +05301005
1006 if (cbk && cbk->is_driver_unloading)
1007 return cbk->is_driver_unloading(cbk->context);
1008
1009 return false;
1010}
1011
1012/**
1013 * hif_is_load_or_unload_in_progress() - API to query upper layers if
1014 * load/unload in progress
1015 * @scn: HIF Context
1016 *
1017 * Return: True/False
1018 */
1019bool hif_is_load_or_unload_in_progress(struct hif_softc *scn)
1020{
Komal Seelam75080122016-03-02 15:18:25 +05301021 struct hif_driver_state_callbacks *cbk = hif_get_callbacks_handle(scn);
Komal Seelambd7c51d2016-02-24 10:27:30 +05301022
1023 if (cbk && cbk->is_load_unload_in_progress)
1024 return cbk->is_load_unload_in_progress(cbk->context);
1025
1026 return false;
1027}
1028
1029/**
Venkateswara Swamy Bandaru26f6f1e2016-10-03 19:35:57 +05301030 * hif_update_pipe_callback() - API to register pipe specific callbacks
1031 * @osc: Opaque softc
1032 * @pipeid: pipe id
1033 * @callbacks: callbacks to register
1034 *
1035 * Return: void
1036 */
1037
1038void hif_update_pipe_callback(struct hif_opaque_softc *osc,
1039 u_int8_t pipeid,
1040 struct hif_msg_callbacks *callbacks)
1041{
1042 struct hif_softc *scn = HIF_GET_SOFTC(osc);
1043 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
1044 struct HIF_CE_pipe_info *pipe_info;
1045
1046 QDF_BUG(pipeid < CE_COUNT_MAX);
1047
1048 HIF_INFO_LO("+%s pipeid %d\n", __func__, pipeid);
1049
1050 pipe_info = &hif_state->pipe_info[pipeid];
1051
1052 qdf_mem_copy(&pipe_info->pipe_callbacks,
1053 callbacks, sizeof(pipe_info->pipe_callbacks));
1054
1055 HIF_INFO_LO("-%s\n", __func__);
1056}
1057
1058/**
Komal Seelambd7c51d2016-02-24 10:27:30 +05301059 * hif_is_recovery_in_progress() - API to query upper layers if recovery in
1060 * progress
1061 * @scn: HIF Context
1062 *
1063 * Return: True/False
1064 */
1065bool hif_is_recovery_in_progress(struct hif_softc *scn)
1066{
Komal Seelam75080122016-03-02 15:18:25 +05301067 struct hif_driver_state_callbacks *cbk = hif_get_callbacks_handle(scn);
Komal Seelambd7c51d2016-02-24 10:27:30 +05301068
1069 if (cbk && cbk->is_recovery_in_progress)
1070 return cbk->is_recovery_in_progress(cbk->context);
1071
1072 return false;
1073}
Mohit Khanna440c5292016-05-12 11:05:06 -07001074#if defined(HIF_PCI) || defined(SNOC) || defined(HIF_AHB)
Houston Hoffman56e0d702016-05-05 17:48:06 -07001075/**
1076 * hif_batch_send() - API to access hif specific function
1077 * ce_batch_send.
1078 * @osc: HIF Context
1079 * @msdu : list of msdus to be sent
1080 * @transfer_id : transfer id
1081 * @len : donwloaded length
1082 *
1083 * Return: list of msds not sent
1084 */
1085qdf_nbuf_t hif_batch_send(struct hif_opaque_softc *osc, qdf_nbuf_t msdu,
1086 uint32_t transfer_id, u_int32_t len, uint32_t sendhead)
1087{
1088 void *ce_tx_hdl = hif_get_ce_handle(osc, CE_HTT_TX_CE);
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05301089
Houston Hoffman56e0d702016-05-05 17:48:06 -07001090 return ce_batch_send((struct CE_handle *)ce_tx_hdl, msdu, transfer_id,
1091 len, sendhead);
1092}
1093
1094/**
1095 * hif_update_tx_ring() - API to access hif specific function
1096 * ce_update_tx_ring.
1097 * @osc: HIF Context
1098 * @num_htt_cmpls : number of htt compl received.
1099 *
1100 * Return: void
1101 */
1102void hif_update_tx_ring(struct hif_opaque_softc *osc, u_int32_t num_htt_cmpls)
1103{
1104 void *ce_tx_hdl = hif_get_ce_handle(osc, CE_HTT_TX_CE);
Manikandan Mohanbd0ef8a2017-04-10 13:10:21 -07001105
Houston Hoffman56e0d702016-05-05 17:48:06 -07001106 ce_update_tx_ring(ce_tx_hdl, num_htt_cmpls);
1107}
1108
1109
1110/**
1111 * hif_send_single() - API to access hif specific function
1112 * ce_send_single.
1113 * @osc: HIF Context
1114 * @msdu : msdu to be sent
1115 * @transfer_id: transfer id
1116 * @len : downloaded length
1117 *
1118 * Return: msdu sent status
1119 */
1120int hif_send_single(struct hif_opaque_softc *osc, qdf_nbuf_t msdu, uint32_t
1121 transfer_id, u_int32_t len)
1122{
1123 void *ce_tx_hdl = hif_get_ce_handle(osc, CE_HTT_TX_CE);
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05301124
Houston Hoffman56e0d702016-05-05 17:48:06 -07001125 return ce_send_single((struct CE_handle *)ce_tx_hdl, msdu, transfer_id,
1126 len);
1127}
1128
1129/**
1130 * hif_send_fast() - API to access hif specific function
1131 * ce_send_fast.
1132 * @osc: HIF Context
1133 * @msdu : array of msdus to be sent
1134 * @num_msdus : number of msdus in an array
1135 * @transfer_id: transfer id
Nirav Shahda0881a2016-05-16 10:45:16 +05301136 * @download_len: download length
Houston Hoffman56e0d702016-05-05 17:48:06 -07001137 *
1138 * Return: No. of packets that could be sent
1139 */
Nirav Shahda0881a2016-05-16 10:45:16 +05301140int hif_send_fast(struct hif_opaque_softc *osc, qdf_nbuf_t nbuf,
1141 uint32_t transfer_id, uint32_t download_len)
Houston Hoffman56e0d702016-05-05 17:48:06 -07001142{
1143 void *ce_tx_hdl = hif_get_ce_handle(osc, CE_HTT_TX_CE);
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05301144
Nirav Shahda0881a2016-05-16 10:45:16 +05301145 return ce_send_fast((struct CE_handle *)ce_tx_hdl, nbuf,
1146 transfer_id, download_len);
Houston Hoffman56e0d702016-05-05 17:48:06 -07001147}
Mohit Khanna440c5292016-05-12 11:05:06 -07001148#endif
Houston Hoffman56e0d702016-05-05 17:48:06 -07001149
1150/**
1151 * hif_reg_write() - API to access hif specific function
1152 * hif_write32_mb.
1153 * @hif_ctx : HIF Context
1154 * @offset : offset on which value has to be written
1155 * @value : value to be written
1156 *
1157 * Return: None
1158 */
1159void hif_reg_write(struct hif_opaque_softc *hif_ctx, uint32_t offset,
1160 uint32_t value)
1161{
1162 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Manikandan Mohanbd0ef8a2017-04-10 13:10:21 -07001163
Houston Hoffman56e0d702016-05-05 17:48:06 -07001164 hif_write32_mb(scn->mem + offset, value);
1165
1166}
1167
1168/**
1169 * hif_reg_read() - API to access hif specific function
1170 * hif_read32_mb.
1171 * @hif_ctx : HIF Context
1172 * @offset : offset from which value has to be read
1173 *
1174 * Return: Read value
1175 */
1176uint32_t hif_reg_read(struct hif_opaque_softc *hif_ctx, uint32_t offset)
1177{
1178
1179 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Manikandan Mohanbd0ef8a2017-04-10 13:10:21 -07001180
Houston Hoffman56e0d702016-05-05 17:48:06 -07001181 return hif_read32_mb(scn->mem + offset);
1182}
Mohit Khanna440c5292016-05-12 11:05:06 -07001183
1184#if defined(HIF_USB)
1185/**
1186 * hif_ramdump_handler(): generic ramdump handler
1187 * @scn: struct hif_opaque_softc
1188 *
1189 * Return: None
1190 */
1191
1192void hif_ramdump_handler(struct hif_opaque_softc *scn)
1193
1194{
1195 if (hif_get_bus_type == QDF_BUS_TYPE_USB)
1196 hif_usb_ramdump_handler();
1197}
1198#endif
Venkateswara Swamy Bandaru31108f32016-08-08 18:04:29 +05301199
1200/**
1201 * hif_register_ext_group_int_handler() - API to register external group
1202 * interrupt handler.
1203 * @hif_ctx : HIF Context
1204 * @numirq: number of irq's in the group
1205 * @irq: array of irq values
1206 * @ext_intr_handler: callback interrupt handler function
1207 * @context: context to passed in callback
1208 *
1209 * Return: status
1210 */
1211uint32_t hif_register_ext_group_int_handler(struct hif_opaque_softc *hif_ctx,
1212 uint32_t numirq, uint32_t irq[], ext_intr_handler handler,
1213 void *context)
1214{
1215 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
1216 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
1217 struct hif_ext_group_entry *hif_ext_group;
1218
Venkateswara Swamy Bandaru61824942017-04-12 12:31:59 +05301219 if (scn->ext_grp_irq_configured) {
1220 HIF_ERROR("%s Called after ext grp irq configured\n", __func__);
Venkateswara Swamy Bandaru31108f32016-08-08 18:04:29 +05301221 return QDF_STATUS_E_FAILURE;
1222 }
1223
1224 if (hif_state->hif_num_extgroup >= HIF_MAX_GROUP) {
1225 HIF_ERROR("%s Max groups reached\n", __func__);
1226 return QDF_STATUS_E_FAILURE;
1227 }
1228
1229 if (numirq >= HIF_MAX_GRP_IRQ) {
1230 HIF_ERROR("%s invalid numirq\n", __func__);
1231 return QDF_STATUS_E_FAILURE;
1232 }
1233
1234 hif_ext_group = &hif_state->hif_ext_group[hif_state->hif_num_extgroup];
1235
1236 hif_ext_group->numirq = numirq;
1237 qdf_mem_copy(&hif_ext_group->irq[0], irq, numirq * sizeof(irq[0]));
1238 hif_ext_group->context = context;
1239 hif_ext_group->handler = handler;
1240 hif_ext_group->configured = true;
1241 hif_ext_group->grp_id = hif_state->hif_num_extgroup;
Pamidipati, Vijay30dc8f22016-10-26 21:54:23 +05301242 hif_ext_group->hif_state = hif_state;
Venkateswara Swamy Bandaru31108f32016-08-08 18:04:29 +05301243
1244 hif_state->hif_num_extgroup++;
1245 return QDF_STATUS_SUCCESS;
1246}
1247
1248/**
Venkateswara Swamy Bandaru61824942017-04-12 12:31:59 +05301249 * hif_configure_ext_group_interrupts() - API to configure external group
1250 * interrpts
1251 * @hif_ctx : HIF Context
1252 *
1253 * Return: status
1254 */
1255uint32_t hif_configure_ext_group_interrupts(struct hif_opaque_softc *hif_ctx)
1256{
1257 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
1258
1259 if (scn->ext_grp_irq_configured) {
1260 HIF_ERROR("%s Called after ext grp irq configured\n", __func__);
1261 return QDF_STATUS_E_FAILURE;
1262 }
1263
1264 hif_grp_irq_configure(scn);
1265 scn->ext_grp_irq_configured = true;
1266
1267 return QDF_STATUS_SUCCESS;
1268}
1269
1270/**
Venkateswara Swamy Bandaru31108f32016-08-08 18:04:29 +05301271 * hif_ext_grp_tasklet() - grp tasklet
1272 * data: context
1273 *
1274 * return: void
1275 */
1276void hif_ext_grp_tasklet(unsigned long data)
1277{
1278 struct hif_ext_group_entry *hif_ext_group =
1279 (struct hif_ext_group_entry *)data;
1280 struct HIF_CE_state *hif_state = hif_ext_group->hif_state;
1281 struct hif_softc *scn = HIF_GET_SOFTC(hif_state);
1282
1283 if (hif_ext_group->grp_id < HIF_MAX_GROUP) {
1284 hif_ext_group->handler(hif_ext_group->context, HIF_MAX_BUDGET);
1285 hif_grp_irq_enable(scn, hif_ext_group->grp_id);
1286 } else {
1287 HIF_ERROR("%s: ERROR - invalid grp_id = %d",
1288 __func__, hif_ext_group->grp_id);
1289 }
1290
1291 qdf_atomic_dec(&scn->active_grp_tasklet_cnt);
1292}
1293
1294/**
1295 * hif_grp_tasklet_kill() - grp tasklet kill
1296 * scn: hif_softc
1297 *
1298 * return: void
1299 */
1300void hif_grp_tasklet_kill(struct hif_softc *scn)
1301{
1302 int i;
1303 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
1304
1305 for (i = 0; i < HIF_MAX_GROUP; i++)
1306 if (hif_state->hif_ext_group[i].inited) {
1307 tasklet_kill(&hif_state->hif_ext_group[i].intr_tq);
1308 hif_state->hif_ext_group[i].inited = false;
1309 }
1310 qdf_atomic_set(&scn->active_grp_tasklet_cnt, 0);
1311}