blob: 766f91048ee98aa7462946a0c7b2397b53859cf3 [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);
Pratik Gandhi815c6d82016-10-19 12:06:32 +0530748
749 if (hif_sc->bus_type == QDF_BUS_TYPE_SNOC)
750 return false;
751
752 if (hif_sc->target_info.target_type == TARGET_TYPE_QCA8074)
753 return false;
754
755 return true;
Houston Hoffman26352592016-03-14 21:11:43 -0700756}
757
758/**
Houston Hoffman60a1eeb2016-03-14 21:11:44 -0700759 * hif_get_bus_type() - return the bus type
760 *
761 * Return: enum qdf_bus_type
762 */
763enum qdf_bus_type hif_get_bus_type(struct hif_opaque_softc *hif_hdl)
764{
765 struct hif_softc *scn = HIF_GET_SOFTC(hif_hdl);
766 return scn->bus_type;
767}
768
769/**
Komal Seelam91553ce2016-01-27 18:57:10 +0530770 * Target info and ini parameters are global to the driver
771 * Hence these structures are exposed to all the modules in
772 * the driver and they don't need to maintains multiple copies
773 * of the same info, instead get the handle from hif and
774 * modify them in hif
775 */
776
777/**
778 * hif_get_ini_handle() - API to get hif_config_param handle
Komal Seelam644263d2016-02-22 20:45:49 +0530779 * @hif_ctx: HIF Context
Komal Seelam91553ce2016-01-27 18:57:10 +0530780 *
781 * Return: pointer to hif_config_info
782 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530783struct hif_config_info *hif_get_ini_handle(struct hif_opaque_softc *hif_ctx)
Komal Seelam91553ce2016-01-27 18:57:10 +0530784{
Komal Seelam644263d2016-02-22 20:45:49 +0530785 struct hif_softc *sc = HIF_GET_SOFTC(hif_ctx);
786
787 return &sc->hif_config;
Komal Seelam91553ce2016-01-27 18:57:10 +0530788}
789
790/**
791 * hif_get_target_info_handle() - API to get hif_target_info handle
Komal Seelam644263d2016-02-22 20:45:49 +0530792 * @hif_ctx: HIF context
Komal Seelam91553ce2016-01-27 18:57:10 +0530793 *
794 * Return: Pointer to hif_target_info
795 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530796struct hif_target_info *hif_get_target_info_handle(
797 struct hif_opaque_softc *hif_ctx)
Komal Seelam91553ce2016-01-27 18:57:10 +0530798{
Komal Seelam644263d2016-02-22 20:45:49 +0530799 struct hif_softc *sc = HIF_GET_SOFTC(hif_ctx);
800
801 return &sc->target_info;
802
Komal Seelam91553ce2016-01-27 18:57:10 +0530803}
Komal Seelamc92a0cf2016-02-22 20:43:52 +0530804
805#if defined(FEATURE_LRO)
806/**
807 * hif_lro_flush_cb_register - API to register for LRO Flush Callback
808 * @scn: HIF Context
809 * @handler: Function pointer to be called by HIF
810 * @data: Private data to be used by the module registering to HIF
811 *
812 * Return: void
813 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530814void hif_lro_flush_cb_register(struct hif_opaque_softc *scn,
815 void (handler)(void *), void *data)
Komal Seelamc92a0cf2016-02-22 20:43:52 +0530816{
817 ce_lro_flush_cb_register(scn, handler, data);
818}
819
820/**
821 * hif_lro_flush_cb_deregister - API to deregister for LRO Flush Callbacks
822 * @scn: HIF Context
823 *
824 * Return: void
825 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530826void hif_lro_flush_cb_deregister(struct hif_opaque_softc *scn)
Komal Seelamc92a0cf2016-02-22 20:43:52 +0530827{
828 ce_lro_flush_cb_deregister(scn);
829}
830#endif
Komal Seelam644263d2016-02-22 20:45:49 +0530831
832/**
833 * hif_get_target_status - API to get target status
834 * @hif_ctx: HIF Context
835 *
Komal Seelam6ee55902016-04-11 17:11:07 +0530836 * Return: enum hif_target_status
Komal Seelam644263d2016-02-22 20:45:49 +0530837 */
Komal Seelam6ee55902016-04-11 17:11:07 +0530838enum hif_target_status hif_get_target_status(struct hif_opaque_softc *hif_ctx)
Komal Seelam644263d2016-02-22 20:45:49 +0530839{
840 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
841
842 return scn->target_status;
843}
844
845/**
Komal Seelama5911d32016-02-24 19:21:59 +0530846 * hif_set_target_status() - API to set target status
Komal Seelam644263d2016-02-22 20:45:49 +0530847 * @hif_ctx: HIF Context
848 * @status: Target Status
849 *
850 * Return: void
851 */
Komal Seelam6ee55902016-04-11 17:11:07 +0530852void hif_set_target_status(struct hif_opaque_softc *hif_ctx, enum
853 hif_target_status status)
Komal Seelam644263d2016-02-22 20:45:49 +0530854{
855 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
856
857 scn->target_status = status;
858}
Komal Seelama5911d32016-02-24 19:21:59 +0530859
860/**
861 * hif_init_ini_config() - API to initialize HIF configuration parameters
862 * @hif_ctx: HIF Context
863 * @cfg: HIF Configuration
864 *
865 * Return: void
866 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530867void hif_init_ini_config(struct hif_opaque_softc *hif_ctx,
868 struct hif_config_info *cfg)
Komal Seelama5911d32016-02-24 19:21:59 +0530869{
870 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
871
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530872 qdf_mem_copy(&scn->hif_config, cfg, sizeof(struct hif_config_info));
Komal Seelama5911d32016-02-24 19:21:59 +0530873}
Komal Seelambd7c51d2016-02-24 10:27:30 +0530874
875/**
876 * hif_get_conparam() - API to get driver mode in HIF
877 * @scn: HIF Context
878 *
879 * Return: driver mode of operation
880 */
881uint32_t hif_get_conparam(struct hif_softc *scn)
882{
883 if (!scn)
884 return 0;
885
886 return scn->hif_con_param;
887}
888
889/**
890 * hif_get_callbacks_handle() - API to get callbacks Handle
891 * @scn: HIF Context
892 *
893 * Return: pointer to HIF Callbacks
894 */
Komal Seelam75080122016-03-02 15:18:25 +0530895struct hif_driver_state_callbacks *hif_get_callbacks_handle(struct hif_softc *scn)
Komal Seelambd7c51d2016-02-24 10:27:30 +0530896{
897 return &scn->callbacks;
898}
899
900/**
901 * hif_is_driver_unloading() - API to query upper layers if driver is unloading
902 * @scn: HIF Context
903 *
904 * Return: True/False
905 */
906bool hif_is_driver_unloading(struct hif_softc *scn)
907{
Komal Seelam75080122016-03-02 15:18:25 +0530908 struct hif_driver_state_callbacks *cbk = hif_get_callbacks_handle(scn);
Komal Seelambd7c51d2016-02-24 10:27:30 +0530909
910 if (cbk && cbk->is_driver_unloading)
911 return cbk->is_driver_unloading(cbk->context);
912
913 return false;
914}
915
916/**
917 * hif_is_load_or_unload_in_progress() - API to query upper layers if
918 * load/unload in progress
919 * @scn: HIF Context
920 *
921 * Return: True/False
922 */
923bool hif_is_load_or_unload_in_progress(struct hif_softc *scn)
924{
Komal Seelam75080122016-03-02 15:18:25 +0530925 struct hif_driver_state_callbacks *cbk = hif_get_callbacks_handle(scn);
Komal Seelambd7c51d2016-02-24 10:27:30 +0530926
927 if (cbk && cbk->is_load_unload_in_progress)
928 return cbk->is_load_unload_in_progress(cbk->context);
929
930 return false;
931}
932
933/**
Venkateswara Swamy Bandaru26f6f1e2016-10-03 19:35:57 +0530934 * hif_update_pipe_callback() - API to register pipe specific callbacks
935 * @osc: Opaque softc
936 * @pipeid: pipe id
937 * @callbacks: callbacks to register
938 *
939 * Return: void
940 */
941
942void hif_update_pipe_callback(struct hif_opaque_softc *osc,
943 u_int8_t pipeid,
944 struct hif_msg_callbacks *callbacks)
945{
946 struct hif_softc *scn = HIF_GET_SOFTC(osc);
947 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
948 struct HIF_CE_pipe_info *pipe_info;
949
950 QDF_BUG(pipeid < CE_COUNT_MAX);
951
952 HIF_INFO_LO("+%s pipeid %d\n", __func__, pipeid);
953
954 pipe_info = &hif_state->pipe_info[pipeid];
955
956 qdf_mem_copy(&pipe_info->pipe_callbacks,
957 callbacks, sizeof(pipe_info->pipe_callbacks));
958
959 HIF_INFO_LO("-%s\n", __func__);
960}
961
962/**
Komal Seelambd7c51d2016-02-24 10:27:30 +0530963 * hif_is_recovery_in_progress() - API to query upper layers if recovery in
964 * progress
965 * @scn: HIF Context
966 *
967 * Return: True/False
968 */
969bool hif_is_recovery_in_progress(struct hif_softc *scn)
970{
Komal Seelam75080122016-03-02 15:18:25 +0530971 struct hif_driver_state_callbacks *cbk = hif_get_callbacks_handle(scn);
Komal Seelambd7c51d2016-02-24 10:27:30 +0530972
973 if (cbk && cbk->is_recovery_in_progress)
974 return cbk->is_recovery_in_progress(cbk->context);
975
976 return false;
977}
Mohit Khanna440c5292016-05-12 11:05:06 -0700978#if defined(HIF_PCI) || defined(SNOC) || defined(HIF_AHB)
Houston Hoffman56e0d702016-05-05 17:48:06 -0700979/**
980 * hif_batch_send() - API to access hif specific function
981 * ce_batch_send.
982 * @osc: HIF Context
983 * @msdu : list of msdus to be sent
984 * @transfer_id : transfer id
985 * @len : donwloaded length
986 *
987 * Return: list of msds not sent
988 */
989qdf_nbuf_t hif_batch_send(struct hif_opaque_softc *osc, qdf_nbuf_t msdu,
990 uint32_t transfer_id, u_int32_t len, uint32_t sendhead)
991{
992 void *ce_tx_hdl = hif_get_ce_handle(osc, CE_HTT_TX_CE);
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530993
Houston Hoffman56e0d702016-05-05 17:48:06 -0700994 return ce_batch_send((struct CE_handle *)ce_tx_hdl, msdu, transfer_id,
995 len, sendhead);
996}
997
998/**
999 * hif_update_tx_ring() - API to access hif specific function
1000 * ce_update_tx_ring.
1001 * @osc: HIF Context
1002 * @num_htt_cmpls : number of htt compl received.
1003 *
1004 * Return: void
1005 */
1006void hif_update_tx_ring(struct hif_opaque_softc *osc, u_int32_t num_htt_cmpls)
1007{
1008 void *ce_tx_hdl = hif_get_ce_handle(osc, CE_HTT_TX_CE);
1009 ce_update_tx_ring(ce_tx_hdl, num_htt_cmpls);
1010}
1011
1012
1013/**
1014 * hif_send_single() - API to access hif specific function
1015 * ce_send_single.
1016 * @osc: HIF Context
1017 * @msdu : msdu to be sent
1018 * @transfer_id: transfer id
1019 * @len : downloaded length
1020 *
1021 * Return: msdu sent status
1022 */
1023int hif_send_single(struct hif_opaque_softc *osc, qdf_nbuf_t msdu, uint32_t
1024 transfer_id, u_int32_t len)
1025{
1026 void *ce_tx_hdl = hif_get_ce_handle(osc, CE_HTT_TX_CE);
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05301027
Houston Hoffman56e0d702016-05-05 17:48:06 -07001028 return ce_send_single((struct CE_handle *)ce_tx_hdl, msdu, transfer_id,
1029 len);
1030}
1031
1032/**
1033 * hif_send_fast() - API to access hif specific function
1034 * ce_send_fast.
1035 * @osc: HIF Context
1036 * @msdu : array of msdus to be sent
1037 * @num_msdus : number of msdus in an array
1038 * @transfer_id: transfer id
Nirav Shahda0881a2016-05-16 10:45:16 +05301039 * @download_len: download length
Houston Hoffman56e0d702016-05-05 17:48:06 -07001040 *
1041 * Return: No. of packets that could be sent
1042 */
Nirav Shahda0881a2016-05-16 10:45:16 +05301043int hif_send_fast(struct hif_opaque_softc *osc, qdf_nbuf_t nbuf,
1044 uint32_t transfer_id, uint32_t download_len)
Houston Hoffman56e0d702016-05-05 17:48:06 -07001045{
1046 void *ce_tx_hdl = hif_get_ce_handle(osc, CE_HTT_TX_CE);
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05301047
Nirav Shahda0881a2016-05-16 10:45:16 +05301048 return ce_send_fast((struct CE_handle *)ce_tx_hdl, nbuf,
1049 transfer_id, download_len);
Houston Hoffman56e0d702016-05-05 17:48:06 -07001050}
Mohit Khanna440c5292016-05-12 11:05:06 -07001051#endif
Houston Hoffman56e0d702016-05-05 17:48:06 -07001052
1053/**
1054 * hif_reg_write() - API to access hif specific function
1055 * hif_write32_mb.
1056 * @hif_ctx : HIF Context
1057 * @offset : offset on which value has to be written
1058 * @value : value to be written
1059 *
1060 * Return: None
1061 */
1062void hif_reg_write(struct hif_opaque_softc *hif_ctx, uint32_t offset,
1063 uint32_t value)
1064{
1065 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
1066 hif_write32_mb(scn->mem + offset, value);
1067
1068}
1069
1070/**
1071 * hif_reg_read() - API to access hif specific function
1072 * hif_read32_mb.
1073 * @hif_ctx : HIF Context
1074 * @offset : offset from which value has to be read
1075 *
1076 * Return: Read value
1077 */
1078uint32_t hif_reg_read(struct hif_opaque_softc *hif_ctx, uint32_t offset)
1079{
1080
1081 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
1082 return hif_read32_mb(scn->mem + offset);
1083}
Mohit Khanna440c5292016-05-12 11:05:06 -07001084
1085#if defined(HIF_USB)
1086/**
1087 * hif_ramdump_handler(): generic ramdump handler
1088 * @scn: struct hif_opaque_softc
1089 *
1090 * Return: None
1091 */
1092
1093void hif_ramdump_handler(struct hif_opaque_softc *scn)
1094
1095{
1096 if (hif_get_bus_type == QDF_BUS_TYPE_USB)
1097 hif_usb_ramdump_handler();
1098}
1099#endif
Venkateswara Swamy Bandaru31108f32016-08-08 18:04:29 +05301100
1101/**
1102 * hif_register_ext_group_int_handler() - API to register external group
1103 * interrupt handler.
1104 * @hif_ctx : HIF Context
1105 * @numirq: number of irq's in the group
1106 * @irq: array of irq values
1107 * @ext_intr_handler: callback interrupt handler function
1108 * @context: context to passed in callback
1109 *
1110 * Return: status
1111 */
1112uint32_t hif_register_ext_group_int_handler(struct hif_opaque_softc *hif_ctx,
1113 uint32_t numirq, uint32_t irq[], ext_intr_handler handler,
1114 void *context)
1115{
1116 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
1117 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
1118 struct hif_ext_group_entry *hif_ext_group;
1119
1120 if (scn->hif_init_done) {
1121 HIF_ERROR("%s Called after HIF initialization \n", __func__);
1122 return QDF_STATUS_E_FAILURE;
1123 }
1124
1125 if (hif_state->hif_num_extgroup >= HIF_MAX_GROUP) {
1126 HIF_ERROR("%s Max groups reached\n", __func__);
1127 return QDF_STATUS_E_FAILURE;
1128 }
1129
1130 if (numirq >= HIF_MAX_GRP_IRQ) {
1131 HIF_ERROR("%s invalid numirq\n", __func__);
1132 return QDF_STATUS_E_FAILURE;
1133 }
1134
1135 hif_ext_group = &hif_state->hif_ext_group[hif_state->hif_num_extgroup];
1136
1137 hif_ext_group->numirq = numirq;
1138 qdf_mem_copy(&hif_ext_group->irq[0], irq, numirq * sizeof(irq[0]));
1139 hif_ext_group->context = context;
1140 hif_ext_group->handler = handler;
1141 hif_ext_group->configured = true;
1142 hif_ext_group->grp_id = hif_state->hif_num_extgroup;
1143
1144 hif_state->hif_num_extgroup++;
1145 return QDF_STATUS_SUCCESS;
1146}
1147
1148/**
1149 * hif_ext_grp_tasklet() - grp tasklet
1150 * data: context
1151 *
1152 * return: void
1153 */
1154void hif_ext_grp_tasklet(unsigned long data)
1155{
1156 struct hif_ext_group_entry *hif_ext_group =
1157 (struct hif_ext_group_entry *)data;
1158 struct HIF_CE_state *hif_state = hif_ext_group->hif_state;
1159 struct hif_softc *scn = HIF_GET_SOFTC(hif_state);
1160
1161 if (hif_ext_group->grp_id < HIF_MAX_GROUP) {
1162 hif_ext_group->handler(hif_ext_group->context, HIF_MAX_BUDGET);
1163 hif_grp_irq_enable(scn, hif_ext_group->grp_id);
1164 } else {
1165 HIF_ERROR("%s: ERROR - invalid grp_id = %d",
1166 __func__, hif_ext_group->grp_id);
1167 }
1168
1169 qdf_atomic_dec(&scn->active_grp_tasklet_cnt);
1170}
1171
1172/**
1173 * hif_grp_tasklet_kill() - grp tasklet kill
1174 * scn: hif_softc
1175 *
1176 * return: void
1177 */
1178void hif_grp_tasklet_kill(struct hif_softc *scn)
1179{
1180 int i;
1181 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
1182
1183 for (i = 0; i < HIF_MAX_GROUP; i++)
1184 if (hif_state->hif_ext_group[i].inited) {
1185 tasklet_kill(&hif_state->hif_ext_group[i].intr_tq);
1186 hif_state->hif_ext_group[i].inited = false;
1187 }
1188 qdf_atomic_set(&scn->active_grp_tasklet_cnt, 0);
1189}