blob: 728740ae2282048ea2a4f280c9d57744fc8832da [file] [log] [blame]
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001/*
Houston Hoffmancceec342015-11-11 11:37:20 -08002 * Copyright (c) 2015-2016 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
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080052
Komal Seelam5584a7c2016-02-24 19:22:48 +053053void hif_dump(struct hif_opaque_softc *hif_ctx, uint8_t cmd_id, bool start)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080054{
Poddar, Siddarthe41943f2016-04-27 15:33:48 +053055 hif_trigger_dump(hif_ctx, cmd_id, start);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080056}
57
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080058/**
59 * hif_get_target_id(): hif_get_target_id
60 *
61 * Return the virtual memory base address to the caller
62 *
Komal Seelam644263d2016-02-22 20:45:49 +053063 * @scn: hif_softc
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080064 *
65 * Return: A_target_id_t
66 */
Komal Seelam644263d2016-02-22 20:45:49 +053067A_target_id_t hif_get_target_id(struct hif_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080068{
69 return scn->mem;
70}
71
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080072/**
73 * hif_get_targetdef(): hif_get_targetdef
74 * @scn: scn
75 *
76 * Return: void *
77 */
Komal Seelam5584a7c2016-02-24 19:22:48 +053078void *hif_get_targetdef(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080079{
Komal Seelam644263d2016-02-22 20:45:49 +053080 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
81
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080082 return scn->targetdef;
83}
84
85/**
86 * hif_vote_link_down(): unvote for link up
87 *
88 * Call hif_vote_link_down to release a previous request made using
89 * hif_vote_link_up. A hif_vote_link_down call should only be made
90 * after a corresponding hif_vote_link_up, otherwise you could be
91 * negating a vote from another source. When no votes are present
92 * hif will not guarantee the linkstate after hif_bus_suspend.
93 *
94 * SYNCHRONIZE WITH hif_vote_link_up by only calling in MC thread
95 * and initialization deinitialization sequencences.
96 *
97 * Return: n/a
98 */
Komal Seelam5584a7c2016-02-24 19:22:48 +053099void hif_vote_link_down(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800100{
Komal Seelam644263d2016-02-22 20:45:49 +0530101 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530102 QDF_BUG(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800103
104 scn->linkstate_vote--;
105 if (scn->linkstate_vote == 0)
Houston Hoffmancceec342015-11-11 11:37:20 -0800106 hif_bus_prevent_linkdown(scn, false);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800107}
108
109/**
110 * hif_vote_link_up(): vote to prevent bus from suspending
111 *
112 * Makes hif guarantee that fw can message the host normally
113 * durring suspend.
114 *
115 * SYNCHRONIZE WITH hif_vote_link_up by only calling in MC thread
116 * and initialization deinitialization sequencences.
117 *
118 * Return: n/a
119 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530120void hif_vote_link_up(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800121{
Komal Seelam644263d2016-02-22 20:45:49 +0530122 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530123 QDF_BUG(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800124
125 scn->linkstate_vote++;
126 if (scn->linkstate_vote == 1)
Houston Hoffmancceec342015-11-11 11:37:20 -0800127 hif_bus_prevent_linkdown(scn, true);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800128}
129
130/**
131 * hif_can_suspend_link(): query if hif is permitted to suspend the link
132 *
133 * Hif will ensure that the link won't be suspended if the upperlayers
134 * don't want it to.
135 *
136 * SYNCHRONIZATION: MC thread is stopped before bus suspend thus
137 * we don't need extra locking to ensure votes dont change while
138 * we are in the process of suspending or resuming.
139 *
140 * Return: false if hif will guarantee link up durring suspend.
141 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530142bool hif_can_suspend_link(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800143{
Komal Seelam644263d2016-02-22 20:45:49 +0530144 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530145 QDF_BUG(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800146
147 return scn->linkstate_vote == 0;
148}
149
Houston Hoffman4f529982016-05-05 16:11:04 -0700150#ifndef CONFIG_WIN
151#define QCA9984_HOST_INTEREST_ADDRESS -1
152#define QCA9888_HOST_INTEREST_ADDRESS -1
153#define IPQ4019_HOST_INTEREST_ADDRESS -1
154#endif
155
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800156/**
157 * hif_hia_item_address(): hif_hia_item_address
158 * @target_type: target_type
159 * @item_offset: item_offset
160 *
161 * Return: n/a
162 */
163uint32_t hif_hia_item_address(uint32_t target_type, uint32_t item_offset)
164{
165 switch (target_type) {
166 case TARGET_TYPE_AR6002:
167 return AR6002_HOST_INTEREST_ADDRESS + item_offset;
168 case TARGET_TYPE_AR6003:
169 return AR6003_HOST_INTEREST_ADDRESS + item_offset;
170 case TARGET_TYPE_AR6004:
171 return AR6004_HOST_INTEREST_ADDRESS + item_offset;
172 case TARGET_TYPE_AR6006:
173 return AR6006_HOST_INTEREST_ADDRESS + item_offset;
174 case TARGET_TYPE_AR9888:
175 return AR9888_HOST_INTEREST_ADDRESS + item_offset;
176 case TARGET_TYPE_AR6320:
177 case TARGET_TYPE_AR6320V2:
178 return AR6320_HOST_INTEREST_ADDRESS + item_offset;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800179 case TARGET_TYPE_ADRASTEA:
180 /* ADRASTEA doesn't have a host interest address */
181 ASSERT(0);
182 return 0;
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700183 case TARGET_TYPE_AR900B:
184 return AR900B_HOST_INTEREST_ADDRESS + item_offset;
185 case TARGET_TYPE_QCA9984:
186 return QCA9984_HOST_INTEREST_ADDRESS + item_offset;
187 case TARGET_TYPE_QCA9888:
188 return QCA9888_HOST_INTEREST_ADDRESS + item_offset;
189 case TARGET_TYPE_IPQ4019:
190 return IPQ4019_HOST_INTEREST_ADDRESS + item_offset;
191
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800192 default:
193 ASSERT(0);
194 return 0;
195 }
196}
197
198/**
199 * hif_max_num_receives_reached() - check max receive is reached
Komal Seelambd7c51d2016-02-24 10:27:30 +0530200 * @scn: HIF Context
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800201 * @count: unsigned int.
202 *
203 * Output check status as bool
204 *
205 * Return: bool
206 */
Komal Seelambd7c51d2016-02-24 10:27:30 +0530207bool hif_max_num_receives_reached(struct hif_softc *scn, unsigned int count)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800208{
Houston Hoffman75ef5a52016-04-14 17:15:49 -0700209 if (QDF_IS_EPPING_ENABLED(hif_get_conparam(scn)))
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800210 return count > 120;
211 else
212 return count > MAX_NUM_OF_RECEIVES;
213}
214
215/**
216 * init_buffer_count() - initial buffer count
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530217 * @maxSize: qdf_size_t
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800218 *
219 * routine to modify the initial buffer count to be allocated on an os
220 * platform basis. Platform owner will need to modify this as needed
221 *
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530222 * Return: qdf_size_t
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800223 */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530224qdf_size_t init_buffer_count(qdf_size_t maxSize)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800225{
226 return maxSize;
227}
228
229/**
Nirav Shahd7f91592016-04-21 14:18:43 +0530230 * hif_save_htc_htt_config_endpoint() - save htt_tx_endpoint
231 * @hif_ctx: hif context
232 * @htc_htt_tx_endpoint: htt_tx_endpoint
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800233 *
234 * Return: void
235 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530236void hif_save_htc_htt_config_endpoint(struct hif_opaque_softc *hif_ctx,
Nirav Shahd7f91592016-04-21 14:18:43 +0530237 int htc_htt_tx_endpoint)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800238{
Komal Seelam644263d2016-02-22 20:45:49 +0530239 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800240
241 if (!scn) {
242 HIF_ERROR("%s: error: scn or scn->hif_sc is NULL!",
243 __func__);
244 return;
245 }
246
Nirav Shahd7f91592016-04-21 14:18:43 +0530247 scn->htc_htt_tx_endpoint = htc_htt_tx_endpoint;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800248}
249
Houston Hoffmanec93ab02016-05-03 20:09:55 -0700250static const struct qwlan_hw qwlan_hw_list[] = {
251 {
252 .id = AR6320_REV1_VERSION,
253 .subid = 0,
254 .name = "QCA6174_REV1",
255 },
256 {
257 .id = AR6320_REV1_1_VERSION,
258 .subid = 0x1,
259 .name = "QCA6174_REV1_1",
260 },
261 {
262 .id = AR6320_REV1_3_VERSION,
263 .subid = 0x2,
264 .name = "QCA6174_REV1_3",
265 },
266 {
267 .id = AR6320_REV2_1_VERSION,
268 .subid = 0x4,
269 .name = "QCA6174_REV2_1",
270 },
271 {
272 .id = AR6320_REV2_1_VERSION,
273 .subid = 0x5,
274 .name = "QCA6174_REV2_2",
275 },
276 {
277 .id = AR6320_REV3_VERSION,
278 .subid = 0x6,
279 .name = "QCA6174_REV2.3",
280 },
281 {
282 .id = AR6320_REV3_VERSION,
283 .subid = 0x8,
284 .name = "QCA6174_REV3",
285 },
286 {
287 .id = AR6320_REV3_VERSION,
288 .subid = 0x9,
289 .name = "QCA6174_REV3_1",
290 },
291 {
292 .id = AR6320_REV3_2_VERSION,
293 .subid = 0xA,
294 .name = "AR6320_REV3_2_VERSION",
Houston Hoffmancd0884a2016-08-24 15:30:09 -0700295 },
296 {
297 .id = WCN3990_v1,
298 .subid = 0x0,
299 .name = "WCN3990_V1",
Houston Hoffmandd4da482016-10-17 12:41:45 -0700300 },
301 {
302 .id = WCN3990_v2,
303 .subid = 0x0,
304 .name = "WCN3990_V2",
Houston Hoffmanec93ab02016-05-03 20:09:55 -0700305 }
306};
307
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800308/**
309 * hif_get_hw_name(): get a human readable name for the hardware
Komal Seelam91553ce2016-01-27 18:57:10 +0530310 * @info: Target Info
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800311 *
Komal Seelam91553ce2016-01-27 18:57:10 +0530312 * Return: human readable name for the underlying wifi hardware.
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800313 */
Komal Seelam91553ce2016-01-27 18:57:10 +0530314static const char *hif_get_hw_name(struct hif_target_info *info)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800315{
316 int i;
Komal Seelam91553ce2016-01-27 18:57:10 +0530317
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800318 for (i = 0; i < ARRAY_SIZE(qwlan_hw_list); i++) {
Komal Seelam91553ce2016-01-27 18:57:10 +0530319 if (info->target_version == qwlan_hw_list[i].id &&
320 info->target_revision == qwlan_hw_list[i].subid) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800321 return qwlan_hw_list[i].name;
322 }
323 }
324
325 return "Unknown Device";
326}
327
328/**
329 * hif_get_hw_info(): hif_get_hw_info
330 * @scn: scn
331 * @version: version
332 * @revision: revision
333 *
334 * Return: n/a
335 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530336void hif_get_hw_info(struct hif_opaque_softc *scn, u32 *version, u32 *revision,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800337 const char **target_name)
338{
Komal Seelam91553ce2016-01-27 18:57:10 +0530339 struct hif_target_info *info = hif_get_target_info_handle(scn);
Mohit Khanna440c5292016-05-12 11:05:06 -0700340 struct hif_softc *sc = HIF_GET_SOFTC(scn);
341
342 if (sc->bus_type == QDF_BUS_TYPE_USB)
343 hif_usb_get_hw_info(sc);
344
Komal Seelam91553ce2016-01-27 18:57:10 +0530345 *version = info->target_version;
346 *revision = info->target_revision;
347 *target_name = hif_get_hw_name(info);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800348}
349
350/**
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530351 * hif_get_dev_ba(): API to get device base address.
352 * @scn: scn
353 * @version: version
354 * @revision: revision
355 *
356 * Return: n/a
357 */
358void *hif_get_dev_ba(struct hif_opaque_softc *hif_handle)
359{
360 struct hif_softc *scn = (struct hif_softc *)hif_handle;
361
362 return scn->mem;
363}
364/**
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800365 * hif_open(): hif_open
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530366 * @qdf_ctx: QDF Context
Komal Seelambd7c51d2016-02-24 10:27:30 +0530367 * @mode: Driver Mode
368 * @bus_type: Bus Type
369 * @cbk: CDS Callbacks
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800370 *
Komal Seelambd7c51d2016-02-24 10:27:30 +0530371 * API to open HIF Context
372 *
373 * Return: HIF Opaque Pointer
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800374 */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530375struct hif_opaque_softc *hif_open(qdf_device_t qdf_ctx, uint32_t mode,
376 enum qdf_bus_type bus_type,
Komal Seelam75080122016-03-02 15:18:25 +0530377 struct hif_driver_state_callbacks *cbk)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800378{
Komal Seelam644263d2016-02-22 20:45:49 +0530379 struct hif_softc *scn;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530380 QDF_STATUS status = QDF_STATUS_SUCCESS;
Houston Hoffman162164c2016-03-14 21:12:10 -0700381 int bus_context_size = hif_bus_get_context_size(bus_type);
382
383 if (bus_context_size == 0) {
384 HIF_ERROR("%s: context size 0 not allowed", __func__);
385 return NULL;
386 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800387
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530388 scn = (struct hif_softc *)qdf_mem_malloc(bus_context_size);
Komal Seelambd7c51d2016-02-24 10:27:30 +0530389 if (!scn) {
390 HIF_ERROR("%s: cannot alloc memory for HIF context of size:%d",
391 __func__, bus_context_size);
392 return GET_HIF_OPAQUE_HDL(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800393 }
394
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530395 qdf_mem_zero(scn, bus_context_size);
Komal Seelambd7c51d2016-02-24 10:27:30 +0530396
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530397 scn->qdf_dev = qdf_ctx;
Komal Seelambd7c51d2016-02-24 10:27:30 +0530398 scn->hif_con_param = mode;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530399 qdf_atomic_init(&scn->active_tasklet_cnt);
Venkateswara Swamy Bandaru31108f32016-08-08 18:04:29 +0530400 qdf_atomic_init(&scn->active_grp_tasklet_cnt);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530401 qdf_atomic_init(&scn->link_suspended);
402 qdf_atomic_init(&scn->tasklet_from_intr);
Komal Seelam75080122016-03-02 15:18:25 +0530403 qdf_mem_copy(&scn->callbacks, cbk, sizeof(struct hif_driver_state_callbacks));
Houston Hoffman3db96a42016-05-05 19:54:39 -0700404 scn->bus_type = bus_type;
Houston Hoffman3cfe6862016-01-08 10:33:55 -0800405 status = hif_bus_open(scn, bus_type);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530406 if (status != QDF_STATUS_SUCCESS) {
Houston Hoffman3cfe6862016-01-08 10:33:55 -0800407 HIF_ERROR("%s: hif_bus_open error = %d, bus_type = %d",
408 __func__, status, bus_type);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530409 qdf_mem_free(scn);
Komal Seelambd7c51d2016-02-24 10:27:30 +0530410 scn = NULL;
Houston Hoffman3cfe6862016-01-08 10:33:55 -0800411 }
412
Komal Seelambd7c51d2016-02-24 10:27:30 +0530413 return GET_HIF_OPAQUE_HDL(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800414}
415
416/**
417 * hif_close(): hif_close
418 * @hif_ctx: hif_ctx
419 *
420 * Return: n/a
421 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530422void hif_close(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800423{
Komal Seelam644263d2016-02-22 20:45:49 +0530424 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800425
426 if (scn == NULL) {
Komal Seelam5584a7c2016-02-24 19:22:48 +0530427 HIF_ERROR("%s: hif_opaque_softc is NULL", __func__);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800428 return;
429 }
430
431 if (scn->athdiag_procfs_inited) {
432 athdiag_procfs_remove();
433 scn->athdiag_procfs_inited = false;
434 }
435
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800436 hif_bus_close(scn);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530437 qdf_mem_free(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800438}
439
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530440static QDF_STATUS hif_hal_attach(struct hif_softc *scn)
441{
442#ifdef QCA_WIFI_QCA8074
443 if (ce_srng_based(scn)) {
444 scn->hal_soc = hal_attach(scn, scn->qdf_dev);
445 if (scn->hal_soc == NULL)
446 return QDF_STATUS_E_FAILURE;
447 }
448#endif
449
450 return QDF_STATUS_SUCCESS;
451}
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800452/**
453 * hif_enable(): hif_enable
454 * @hif_ctx: hif_ctx
455 * @dev: dev
456 * @bdev: bus dev
457 * @bid: bus ID
458 * @bus_type: bus type
459 * @type: enable type
460 *
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530461 * Return: QDF_STATUS
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800462 */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530463QDF_STATUS hif_enable(struct hif_opaque_softc *hif_ctx, struct device *dev,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800464 void *bdev, const hif_bus_id *bid,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530465 enum qdf_bus_type bus_type,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800466 enum hif_enable_type type)
467{
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530468 QDF_STATUS status;
Komal Seelam644263d2016-02-22 20:45:49 +0530469 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800470
471 if (scn == NULL) {
472 HIF_ERROR("%s: hif_ctx = NULL", __func__);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530473 return QDF_STATUS_E_NULL_VALUE;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800474 }
475
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800476 status = hif_enable_bus(scn, dev, bdev, bid, type);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530477 if (status != QDF_STATUS_SUCCESS) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800478 HIF_ERROR("%s: hif_enable_bus error = %d",
479 __func__, status);
480 return status;
481 }
482
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530483 status = hif_hal_attach(scn);
484 if (status != QDF_STATUS_SUCCESS) {
485 HIF_ERROR("%s: hal attach failed", __func__);
486 return status;
487 }
488
Houston Hoffman108da402016-03-14 21:11:24 -0700489 if (hif_bus_configure(scn)) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800490 HIF_ERROR("%s: Target probe failed.", __func__);
Vishwajith Upendra3f78aa62016-02-09 17:53:02 +0530491 hif_disable_bus(scn);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530492 status = QDF_STATUS_E_FAILURE;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800493 return status;
494 }
Houston Hoffman108da402016-03-14 21:11:24 -0700495
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800496 /*
497 * Flag to avoid potential unallocated memory access from MSI
498 * interrupt handler which could get scheduled as soon as MSI
499 * is enabled, i.e to take care of the race due to the order
500 * in where MSI is enabled before the memory, that will be
501 * in interrupt handlers, is allocated.
502 */
503
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800504 scn->hif_init_done = true;
505
Mohit Khanna440c5292016-05-12 11:05:06 -0700506 HIF_TRACE("%s: OK", __func__);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800507
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530508 return QDF_STATUS_SUCCESS;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800509}
510
Komal Seelam5584a7c2016-02-24 19:22:48 +0530511void hif_disable(struct hif_opaque_softc *hif_ctx, enum hif_disable_type type)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800512{
Komal Seelam644263d2016-02-22 20:45:49 +0530513 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800514
515 if (!scn)
516 return;
517
518 hif_nointrs(scn);
519 if (scn->hif_init_done == false)
Poddar, Siddarthe41943f2016-04-27 15:33:48 +0530520 hif_shutdown_device(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800521 else
Komal Seelam644263d2016-02-22 20:45:49 +0530522 hif_stop(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800523
Vishwajith Upendra3f78aa62016-02-09 17:53:02 +0530524 hif_disable_bus(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800525
Komal Seelambd7c51d2016-02-24 10:27:30 +0530526 hif_wlan_disable(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800527
528 scn->notice_send = false;
529
530 HIF_INFO("%s: X", __func__);
531}
532
Nirav Shahb70bd732016-05-25 14:31:51 +0530533void hif_display_stats(struct hif_opaque_softc *hif_ctx)
534{
535 hif_display_bus_stats(hif_ctx);
536}
537
538void hif_clear_stats(struct hif_opaque_softc *hif_ctx)
539{
540 hif_clear_bus_stats(hif_ctx);
541}
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800542
543/**
Govind Singh2443fb32016-01-13 17:44:48 +0530544 * hif_crash_shutdown_dump_bus_register() - dump bus registers
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800545 * @hif_ctx: hif_ctx
546 *
547 * Return: n/a
548 */
549#if defined(TARGET_RAMDUMP_AFTER_KERNEL_PANIC) \
Houston Hoffmanbc693492016-03-14 21:11:41 -0700550&& defined(DEBUG)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800551
Govind Singh2443fb32016-01-13 17:44:48 +0530552static void hif_crash_shutdown_dump_bus_register(void *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800553{
Komal Seelam5584a7c2016-02-24 19:22:48 +0530554 struct hif_opaque_softc *scn = hif_ctx;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800555
Govind Singh2443fb32016-01-13 17:44:48 +0530556 if (hif_check_soc_status(scn))
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800557 return;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800558
Govind Singh2443fb32016-01-13 17:44:48 +0530559 if (hif_dump_registers(scn))
560 HIF_ERROR("Failed to dump bus registers!");
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800561}
562
563/**
564 * hif_crash_shutdown(): hif_crash_shutdown
565 *
566 * This function is called by the platform driver to dump CE registers
567 *
568 * @hif_ctx: hif_ctx
569 *
570 * Return: n/a
571 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530572void hif_crash_shutdown(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800573{
Komal Seelam644263d2016-02-22 20:45:49 +0530574 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800575
Houston Hoffmanbc693492016-03-14 21:11:41 -0700576 if (!hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800577 return;
578
Houston Hoffmanbc693492016-03-14 21:11:41 -0700579 if (scn->bus_type == QDF_BUS_TYPE_SNOC) {
580 HIF_INFO_MED("%s: RAM dump disabled for bustype %d",
581 __func__, scn->bus_type);
582 return;
583 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800584
Komal Seelam6ee55902016-04-11 17:11:07 +0530585 if (TARGET_STATUS_RESET == scn->target_status) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800586 HIF_INFO_MED("%s: Target is already asserted, ignore!",
587 __func__);
588 return;
589 }
590
Komal Seelambd7c51d2016-02-24 10:27:30 +0530591 if (hif_is_load_or_unload_in_progress(scn)) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800592 HIF_ERROR("%s: Load/unload is in progress, ignore!", __func__);
593 return;
594 }
595
Govind Singh2443fb32016-01-13 17:44:48 +0530596 hif_crash_shutdown_dump_bus_register(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800597
Komal Seelam644263d2016-02-22 20:45:49 +0530598 if (ol_copy_ramdump(hif_ctx))
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800599 goto out;
600
601 HIF_INFO_MED("%s: RAM dump collecting completed!", __func__);
602
603out:
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800604 return;
605}
606#else
Komal Seelam5584a7c2016-02-24 19:22:48 +0530607void hif_crash_shutdown(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800608{
609 HIF_INFO_MED("%s: Collecting target RAM dump disabled",
610 __func__);
611 return;
612}
613#endif /* TARGET_RAMDUMP_AFTER_KERNEL_PANIC */
614
615#ifdef QCA_WIFI_3_0
616/**
617 * hif_check_fw_reg(): hif_check_fw_reg
618 * @scn: scn
619 * @state:
620 *
621 * Return: int
622 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530623int hif_check_fw_reg(struct hif_opaque_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800624{
625 return 0;
626}
627#endif
628
629#ifdef IPA_OFFLOAD
630/**
631 * hif_read_phy_mem_base(): hif_read_phy_mem_base
632 * @scn: scn
633 * @phy_mem_base: physical mem base
634 *
635 * Return: n/a
636 */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530637void hif_read_phy_mem_base(struct hif_softc *scn, qdf_dma_addr_t *phy_mem_base)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800638{
639 *phy_mem_base = scn->mem_pa;
640}
641#endif /* IPA_OFFLOAD */
642
643/**
644 * hif_get_device_type(): hif_get_device_type
645 * @device_id: device_id
646 * @revision_id: revision_id
647 * @hif_type: returned hif_type
648 * @target_type: returned target_type
649 *
650 * Return: int
651 */
652int hif_get_device_type(uint32_t device_id,
653 uint32_t revision_id,
654 uint32_t *hif_type, uint32_t *target_type)
655{
656 int ret = 0;
657
658 switch (device_id) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800659 case ADRASTEA_DEVICE_ID:
660 case ADRASTEA_DEVICE_ID_P2_E12:
661
662 *hif_type = HIF_TYPE_ADRASTEA;
663 *target_type = TARGET_TYPE_ADRASTEA;
664 break;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800665
666 case AR9888_DEVICE_ID:
667 *hif_type = HIF_TYPE_AR9888;
668 *target_type = TARGET_TYPE_AR9888;
669 break;
670
671 case AR6320_DEVICE_ID:
672 switch (revision_id) {
673 case AR6320_FW_1_1:
674 case AR6320_FW_1_3:
675 *hif_type = HIF_TYPE_AR6320;
676 *target_type = TARGET_TYPE_AR6320;
677 break;
678
679 case AR6320_FW_2_0:
680 case AR6320_FW_3_0:
681 case AR6320_FW_3_2:
682 *hif_type = HIF_TYPE_AR6320V2;
683 *target_type = TARGET_TYPE_AR6320V2;
684 break;
685
686 default:
687 HIF_ERROR("%s: error - dev_id = 0x%x, rev_id = 0x%x",
688 __func__, device_id, revision_id);
689 ret = -ENODEV;
690 goto end;
691 }
692 break;
693
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700694 case AR9887_DEVICE_ID:
695 *hif_type = HIF_TYPE_AR9888;
696 *target_type = TARGET_TYPE_AR9888;
Houston Hoffmanc50572b2016-06-08 19:49:46 -0700697 HIF_INFO(" *********** AR9887 **************");
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700698 break;
699
700 case QCA9984_DEVICE_ID:
701 *hif_type = HIF_TYPE_QCA9984;
702 *target_type = TARGET_TYPE_QCA9984;
Houston Hoffmanc50572b2016-06-08 19:49:46 -0700703 HIF_INFO(" *********** QCA9984 *************");
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700704 break;
705
706 case QCA9888_DEVICE_ID:
707 *hif_type = HIF_TYPE_QCA9888;
708 *target_type = TARGET_TYPE_QCA9888;
Houston Hoffmanc50572b2016-06-08 19:49:46 -0700709 HIF_INFO(" *********** QCA9888 *************");
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700710 break;
711
712 case AR900B_DEVICE_ID:
713 *hif_type = HIF_TYPE_AR900B;
714 *target_type = TARGET_TYPE_AR900B;
Houston Hoffmanc50572b2016-06-08 19:49:46 -0700715 HIF_INFO(" *********** AR900B *************");
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700716 break;
717
Houston Hoffman3db96a42016-05-05 19:54:39 -0700718 case IPQ4019_DEVICE_ID:
719 *hif_type = HIF_TYPE_IPQ4019;
720 *target_type = TARGET_TYPE_IPQ4019;
Houston Hoffmanc50572b2016-06-08 19:49:46 -0700721 HIF_INFO(" *********** IPQ4019 *************");
Houston Hoffman3db96a42016-05-05 19:54:39 -0700722 break;
723
Venkateswara Swamy Bandaru9fd9af02016-09-20 20:27:31 +0530724 case QCA8074_DEVICE_ID:
725 *hif_type = HIF_TYPE_QCA8074;
726 *target_type = TARGET_TYPE_QCA8074;
727 HIF_INFO(" *********** QCA8074 *************\n");
728 break;
729
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800730 default:
731 HIF_ERROR("%s: Unsupported device ID!", __func__);
732 ret = -ENODEV;
733 break;
734 }
735end:
736 return ret;
737}
Komal Seelam91553ce2016-01-27 18:57:10 +0530738
739/**
Houston Hoffman26352592016-03-14 21:11:43 -0700740 * hif_needs_bmi() - return true if the soc needs bmi through the driver
741 * @hif_ctx: hif context
742 *
743 * Return: true if the soc needs driver bmi otherwise false
744 */
745bool hif_needs_bmi(struct hif_opaque_softc *hif_ctx)
746{
747 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
748 return hif_sc->bus_type != QDF_BUS_TYPE_SNOC;
749}
750
751/**
Houston Hoffman60a1eeb2016-03-14 21:11:44 -0700752 * hif_get_bus_type() - return the bus type
753 *
754 * Return: enum qdf_bus_type
755 */
756enum qdf_bus_type hif_get_bus_type(struct hif_opaque_softc *hif_hdl)
757{
758 struct hif_softc *scn = HIF_GET_SOFTC(hif_hdl);
759 return scn->bus_type;
760}
761
762/**
Komal Seelam91553ce2016-01-27 18:57:10 +0530763 * Target info and ini parameters are global to the driver
764 * Hence these structures are exposed to all the modules in
765 * the driver and they don't need to maintains multiple copies
766 * of the same info, instead get the handle from hif and
767 * modify them in hif
768 */
769
770/**
771 * hif_get_ini_handle() - API to get hif_config_param handle
Komal Seelam644263d2016-02-22 20:45:49 +0530772 * @hif_ctx: HIF Context
Komal Seelam91553ce2016-01-27 18:57:10 +0530773 *
774 * Return: pointer to hif_config_info
775 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530776struct hif_config_info *hif_get_ini_handle(struct hif_opaque_softc *hif_ctx)
Komal Seelam91553ce2016-01-27 18:57:10 +0530777{
Komal Seelam644263d2016-02-22 20:45:49 +0530778 struct hif_softc *sc = HIF_GET_SOFTC(hif_ctx);
779
780 return &sc->hif_config;
Komal Seelam91553ce2016-01-27 18:57:10 +0530781}
782
783/**
784 * hif_get_target_info_handle() - API to get hif_target_info handle
Komal Seelam644263d2016-02-22 20:45:49 +0530785 * @hif_ctx: HIF context
Komal Seelam91553ce2016-01-27 18:57:10 +0530786 *
787 * Return: Pointer to hif_target_info
788 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530789struct hif_target_info *hif_get_target_info_handle(
790 struct hif_opaque_softc *hif_ctx)
Komal Seelam91553ce2016-01-27 18:57:10 +0530791{
Komal Seelam644263d2016-02-22 20:45:49 +0530792 struct hif_softc *sc = HIF_GET_SOFTC(hif_ctx);
793
794 return &sc->target_info;
795
Komal Seelam91553ce2016-01-27 18:57:10 +0530796}
Komal Seelamc92a0cf2016-02-22 20:43:52 +0530797
798#if defined(FEATURE_LRO)
799/**
800 * hif_lro_flush_cb_register - API to register for LRO Flush Callback
801 * @scn: HIF Context
802 * @handler: Function pointer to be called by HIF
803 * @data: Private data to be used by the module registering to HIF
804 *
805 * Return: void
806 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530807void hif_lro_flush_cb_register(struct hif_opaque_softc *scn,
808 void (handler)(void *), void *data)
Komal Seelamc92a0cf2016-02-22 20:43:52 +0530809{
810 ce_lro_flush_cb_register(scn, handler, data);
811}
812
813/**
814 * hif_lro_flush_cb_deregister - API to deregister for LRO Flush Callbacks
815 * @scn: HIF Context
816 *
817 * Return: void
818 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530819void hif_lro_flush_cb_deregister(struct hif_opaque_softc *scn)
Komal Seelamc92a0cf2016-02-22 20:43:52 +0530820{
821 ce_lro_flush_cb_deregister(scn);
822}
823#endif
Komal Seelam644263d2016-02-22 20:45:49 +0530824
825/**
826 * hif_get_target_status - API to get target status
827 * @hif_ctx: HIF Context
828 *
Komal Seelam6ee55902016-04-11 17:11:07 +0530829 * Return: enum hif_target_status
Komal Seelam644263d2016-02-22 20:45:49 +0530830 */
Komal Seelam6ee55902016-04-11 17:11:07 +0530831enum hif_target_status hif_get_target_status(struct hif_opaque_softc *hif_ctx)
Komal Seelam644263d2016-02-22 20:45:49 +0530832{
833 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
834
835 return scn->target_status;
836}
837
838/**
Komal Seelama5911d32016-02-24 19:21:59 +0530839 * hif_set_target_status() - API to set target status
Komal Seelam644263d2016-02-22 20:45:49 +0530840 * @hif_ctx: HIF Context
841 * @status: Target Status
842 *
843 * Return: void
844 */
Komal Seelam6ee55902016-04-11 17:11:07 +0530845void hif_set_target_status(struct hif_opaque_softc *hif_ctx, enum
846 hif_target_status status)
Komal Seelam644263d2016-02-22 20:45:49 +0530847{
848 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
849
850 scn->target_status = status;
851}
Komal Seelama5911d32016-02-24 19:21:59 +0530852
853/**
854 * hif_init_ini_config() - API to initialize HIF configuration parameters
855 * @hif_ctx: HIF Context
856 * @cfg: HIF Configuration
857 *
858 * Return: void
859 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530860void hif_init_ini_config(struct hif_opaque_softc *hif_ctx,
861 struct hif_config_info *cfg)
Komal Seelama5911d32016-02-24 19:21:59 +0530862{
863 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
864
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530865 qdf_mem_copy(&scn->hif_config, cfg, sizeof(struct hif_config_info));
Komal Seelama5911d32016-02-24 19:21:59 +0530866}
Komal Seelambd7c51d2016-02-24 10:27:30 +0530867
868/**
869 * hif_get_conparam() - API to get driver mode in HIF
870 * @scn: HIF Context
871 *
872 * Return: driver mode of operation
873 */
874uint32_t hif_get_conparam(struct hif_softc *scn)
875{
876 if (!scn)
877 return 0;
878
879 return scn->hif_con_param;
880}
881
882/**
883 * hif_get_callbacks_handle() - API to get callbacks Handle
884 * @scn: HIF Context
885 *
886 * Return: pointer to HIF Callbacks
887 */
Komal Seelam75080122016-03-02 15:18:25 +0530888struct hif_driver_state_callbacks *hif_get_callbacks_handle(struct hif_softc *scn)
Komal Seelambd7c51d2016-02-24 10:27:30 +0530889{
890 return &scn->callbacks;
891}
892
893/**
894 * hif_is_driver_unloading() - API to query upper layers if driver is unloading
895 * @scn: HIF Context
896 *
897 * Return: True/False
898 */
899bool hif_is_driver_unloading(struct hif_softc *scn)
900{
Komal Seelam75080122016-03-02 15:18:25 +0530901 struct hif_driver_state_callbacks *cbk = hif_get_callbacks_handle(scn);
Komal Seelambd7c51d2016-02-24 10:27:30 +0530902
903 if (cbk && cbk->is_driver_unloading)
904 return cbk->is_driver_unloading(cbk->context);
905
906 return false;
907}
908
909/**
910 * hif_is_load_or_unload_in_progress() - API to query upper layers if
911 * load/unload in progress
912 * @scn: HIF Context
913 *
914 * Return: True/False
915 */
916bool hif_is_load_or_unload_in_progress(struct hif_softc *scn)
917{
Komal Seelam75080122016-03-02 15:18:25 +0530918 struct hif_driver_state_callbacks *cbk = hif_get_callbacks_handle(scn);
Komal Seelambd7c51d2016-02-24 10:27:30 +0530919
920 if (cbk && cbk->is_load_unload_in_progress)
921 return cbk->is_load_unload_in_progress(cbk->context);
922
923 return false;
924}
925
926/**
Venkateswara Swamy Bandaru26f6f1e2016-10-03 19:35:57 +0530927 * hif_update_pipe_callback() - API to register pipe specific callbacks
928 * @osc: Opaque softc
929 * @pipeid: pipe id
930 * @callbacks: callbacks to register
931 *
932 * Return: void
933 */
934
935void hif_update_pipe_callback(struct hif_opaque_softc *osc,
936 u_int8_t pipeid,
937 struct hif_msg_callbacks *callbacks)
938{
939 struct hif_softc *scn = HIF_GET_SOFTC(osc);
940 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
941 struct HIF_CE_pipe_info *pipe_info;
942
943 QDF_BUG(pipeid < CE_COUNT_MAX);
944
945 HIF_INFO_LO("+%s pipeid %d\n", __func__, pipeid);
946
947 pipe_info = &hif_state->pipe_info[pipeid];
948
949 qdf_mem_copy(&pipe_info->pipe_callbacks,
950 callbacks, sizeof(pipe_info->pipe_callbacks));
951
952 HIF_INFO_LO("-%s\n", __func__);
953}
954
955/**
Komal Seelambd7c51d2016-02-24 10:27:30 +0530956 * hif_is_recovery_in_progress() - API to query upper layers if recovery in
957 * progress
958 * @scn: HIF Context
959 *
960 * Return: True/False
961 */
962bool hif_is_recovery_in_progress(struct hif_softc *scn)
963{
Komal Seelam75080122016-03-02 15:18:25 +0530964 struct hif_driver_state_callbacks *cbk = hif_get_callbacks_handle(scn);
Komal Seelambd7c51d2016-02-24 10:27:30 +0530965
966 if (cbk && cbk->is_recovery_in_progress)
967 return cbk->is_recovery_in_progress(cbk->context);
968
969 return false;
970}
Mohit Khanna440c5292016-05-12 11:05:06 -0700971#if defined(HIF_PCI) || defined(SNOC) || defined(HIF_AHB)
Houston Hoffman56e0d702016-05-05 17:48:06 -0700972/**
973 * hif_batch_send() - API to access hif specific function
974 * ce_batch_send.
975 * @osc: HIF Context
976 * @msdu : list of msdus to be sent
977 * @transfer_id : transfer id
978 * @len : donwloaded length
979 *
980 * Return: list of msds not sent
981 */
982qdf_nbuf_t hif_batch_send(struct hif_opaque_softc *osc, qdf_nbuf_t msdu,
983 uint32_t transfer_id, u_int32_t len, uint32_t sendhead)
984{
985 void *ce_tx_hdl = hif_get_ce_handle(osc, CE_HTT_TX_CE);
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530986
Houston Hoffman56e0d702016-05-05 17:48:06 -0700987 return ce_batch_send((struct CE_handle *)ce_tx_hdl, msdu, transfer_id,
988 len, sendhead);
989}
990
991/**
992 * hif_update_tx_ring() - API to access hif specific function
993 * ce_update_tx_ring.
994 * @osc: HIF Context
995 * @num_htt_cmpls : number of htt compl received.
996 *
997 * Return: void
998 */
999void hif_update_tx_ring(struct hif_opaque_softc *osc, u_int32_t num_htt_cmpls)
1000{
1001 void *ce_tx_hdl = hif_get_ce_handle(osc, CE_HTT_TX_CE);
1002 ce_update_tx_ring(ce_tx_hdl, num_htt_cmpls);
1003}
1004
1005
1006/**
1007 * hif_send_single() - API to access hif specific function
1008 * ce_send_single.
1009 * @osc: HIF Context
1010 * @msdu : msdu to be sent
1011 * @transfer_id: transfer id
1012 * @len : downloaded length
1013 *
1014 * Return: msdu sent status
1015 */
1016int hif_send_single(struct hif_opaque_softc *osc, qdf_nbuf_t msdu, uint32_t
1017 transfer_id, u_int32_t len)
1018{
1019 void *ce_tx_hdl = hif_get_ce_handle(osc, CE_HTT_TX_CE);
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05301020
Houston Hoffman56e0d702016-05-05 17:48:06 -07001021 return ce_send_single((struct CE_handle *)ce_tx_hdl, msdu, transfer_id,
1022 len);
1023}
1024
1025/**
1026 * hif_send_fast() - API to access hif specific function
1027 * ce_send_fast.
1028 * @osc: HIF Context
1029 * @msdu : array of msdus to be sent
1030 * @num_msdus : number of msdus in an array
1031 * @transfer_id: transfer id
Nirav Shahda0881a2016-05-16 10:45:16 +05301032 * @download_len: download length
Houston Hoffman56e0d702016-05-05 17:48:06 -07001033 *
1034 * Return: No. of packets that could be sent
1035 */
Nirav Shahda0881a2016-05-16 10:45:16 +05301036int hif_send_fast(struct hif_opaque_softc *osc, qdf_nbuf_t nbuf,
1037 uint32_t transfer_id, uint32_t download_len)
Houston Hoffman56e0d702016-05-05 17:48:06 -07001038{
1039 void *ce_tx_hdl = hif_get_ce_handle(osc, CE_HTT_TX_CE);
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05301040
Nirav Shahda0881a2016-05-16 10:45:16 +05301041 return ce_send_fast((struct CE_handle *)ce_tx_hdl, nbuf,
1042 transfer_id, download_len);
Houston Hoffman56e0d702016-05-05 17:48:06 -07001043}
Mohit Khanna440c5292016-05-12 11:05:06 -07001044#endif
Houston Hoffman56e0d702016-05-05 17:48:06 -07001045
1046/**
1047 * hif_reg_write() - API to access hif specific function
1048 * hif_write32_mb.
1049 * @hif_ctx : HIF Context
1050 * @offset : offset on which value has to be written
1051 * @value : value to be written
1052 *
1053 * Return: None
1054 */
1055void hif_reg_write(struct hif_opaque_softc *hif_ctx, uint32_t offset,
1056 uint32_t value)
1057{
1058 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
1059 hif_write32_mb(scn->mem + offset, value);
1060
1061}
1062
1063/**
1064 * hif_reg_read() - API to access hif specific function
1065 * hif_read32_mb.
1066 * @hif_ctx : HIF Context
1067 * @offset : offset from which value has to be read
1068 *
1069 * Return: Read value
1070 */
1071uint32_t hif_reg_read(struct hif_opaque_softc *hif_ctx, uint32_t offset)
1072{
1073
1074 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
1075 return hif_read32_mb(scn->mem + offset);
1076}
Mohit Khanna440c5292016-05-12 11:05:06 -07001077
1078#if defined(HIF_USB)
1079/**
1080 * hif_ramdump_handler(): generic ramdump handler
1081 * @scn: struct hif_opaque_softc
1082 *
1083 * Return: None
1084 */
1085
1086void hif_ramdump_handler(struct hif_opaque_softc *scn)
1087
1088{
1089 if (hif_get_bus_type == QDF_BUS_TYPE_USB)
1090 hif_usb_ramdump_handler();
1091}
1092#endif
Venkateswara Swamy Bandaru31108f32016-08-08 18:04:29 +05301093
1094/**
1095 * hif_register_ext_group_int_handler() - API to register external group
1096 * interrupt handler.
1097 * @hif_ctx : HIF Context
1098 * @numirq: number of irq's in the group
1099 * @irq: array of irq values
1100 * @ext_intr_handler: callback interrupt handler function
1101 * @context: context to passed in callback
1102 *
1103 * Return: status
1104 */
1105uint32_t hif_register_ext_group_int_handler(struct hif_opaque_softc *hif_ctx,
1106 uint32_t numirq, uint32_t irq[], ext_intr_handler handler,
1107 void *context)
1108{
1109 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
1110 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
1111 struct hif_ext_group_entry *hif_ext_group;
1112
1113 if (scn->hif_init_done) {
1114 HIF_ERROR("%s Called after HIF initialization \n", __func__);
1115 return QDF_STATUS_E_FAILURE;
1116 }
1117
1118 if (hif_state->hif_num_extgroup >= HIF_MAX_GROUP) {
1119 HIF_ERROR("%s Max groups reached\n", __func__);
1120 return QDF_STATUS_E_FAILURE;
1121 }
1122
1123 if (numirq >= HIF_MAX_GRP_IRQ) {
1124 HIF_ERROR("%s invalid numirq\n", __func__);
1125 return QDF_STATUS_E_FAILURE;
1126 }
1127
1128 hif_ext_group = &hif_state->hif_ext_group[hif_state->hif_num_extgroup];
1129
1130 hif_ext_group->numirq = numirq;
1131 qdf_mem_copy(&hif_ext_group->irq[0], irq, numirq * sizeof(irq[0]));
1132 hif_ext_group->context = context;
1133 hif_ext_group->handler = handler;
1134 hif_ext_group->configured = true;
1135 hif_ext_group->grp_id = hif_state->hif_num_extgroup;
1136
1137 hif_state->hif_num_extgroup++;
1138 return QDF_STATUS_SUCCESS;
1139}
1140
1141/**
1142 * hif_ext_grp_tasklet() - grp tasklet
1143 * data: context
1144 *
1145 * return: void
1146 */
1147void hif_ext_grp_tasklet(unsigned long data)
1148{
1149 struct hif_ext_group_entry *hif_ext_group =
1150 (struct hif_ext_group_entry *)data;
1151 struct HIF_CE_state *hif_state = hif_ext_group->hif_state;
1152 struct hif_softc *scn = HIF_GET_SOFTC(hif_state);
1153
1154 if (hif_ext_group->grp_id < HIF_MAX_GROUP) {
1155 hif_ext_group->handler(hif_ext_group->context, HIF_MAX_BUDGET);
1156 hif_grp_irq_enable(scn, hif_ext_group->grp_id);
1157 } else {
1158 HIF_ERROR("%s: ERROR - invalid grp_id = %d",
1159 __func__, hif_ext_group->grp_id);
1160 }
1161
1162 qdf_atomic_dec(&scn->active_grp_tasklet_cnt);
1163}
1164
1165/**
1166 * hif_grp_tasklet_kill() - grp tasklet kill
1167 * scn: hif_softc
1168 *
1169 * return: void
1170 */
1171void hif_grp_tasklet_kill(struct hif_softc *scn)
1172{
1173 int i;
1174 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
1175
1176 for (i = 0; i < HIF_MAX_GROUP; i++)
1177 if (hif_state->hif_ext_group[i].inited) {
1178 tasklet_kill(&hif_state->hif_ext_group[i].intr_tq);
1179 hif_state->hif_ext_group[i].inited = false;
1180 }
1181 qdf_atomic_set(&scn->active_grp_tasklet_cnt, 0);
1182}