blob: 936a45127e4cfe1dd399a0c2cba59ace59c6051b [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"
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080049
Komal Seelam5584a7c2016-02-24 19:22:48 +053050void hif_dump(struct hif_opaque_softc *hif_ctx, uint8_t cmd_id, bool start)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080051{
Poddar, Siddarthe41943f2016-04-27 15:33:48 +053052 hif_trigger_dump(hif_ctx, cmd_id, start);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080053}
54
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080055/**
56 * hif_get_target_id(): hif_get_target_id
57 *
58 * Return the virtual memory base address to the caller
59 *
Komal Seelam644263d2016-02-22 20:45:49 +053060 * @scn: hif_softc
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080061 *
62 * Return: A_target_id_t
63 */
Komal Seelam644263d2016-02-22 20:45:49 +053064A_target_id_t hif_get_target_id(struct hif_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080065{
66 return scn->mem;
67}
68
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080069/**
70 * hif_get_targetdef(): hif_get_targetdef
71 * @scn: scn
72 *
73 * Return: void *
74 */
Komal Seelam5584a7c2016-02-24 19:22:48 +053075void *hif_get_targetdef(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080076{
Komal Seelam644263d2016-02-22 20:45:49 +053077 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
78
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080079 return scn->targetdef;
80}
81
82/**
83 * hif_vote_link_down(): unvote for link up
84 *
85 * Call hif_vote_link_down to release a previous request made using
86 * hif_vote_link_up. A hif_vote_link_down call should only be made
87 * after a corresponding hif_vote_link_up, otherwise you could be
88 * negating a vote from another source. When no votes are present
89 * hif will not guarantee the linkstate after hif_bus_suspend.
90 *
91 * SYNCHRONIZE WITH hif_vote_link_up by only calling in MC thread
92 * and initialization deinitialization sequencences.
93 *
94 * Return: n/a
95 */
Komal Seelam5584a7c2016-02-24 19:22:48 +053096void hif_vote_link_down(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080097{
Komal Seelam644263d2016-02-22 20:45:49 +053098 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +053099 QDF_BUG(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800100
101 scn->linkstate_vote--;
102 if (scn->linkstate_vote == 0)
Houston Hoffmancceec342015-11-11 11:37:20 -0800103 hif_bus_prevent_linkdown(scn, false);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800104}
105
106/**
107 * hif_vote_link_up(): vote to prevent bus from suspending
108 *
109 * Makes hif guarantee that fw can message the host normally
110 * durring suspend.
111 *
112 * SYNCHRONIZE WITH hif_vote_link_up by only calling in MC thread
113 * and initialization deinitialization sequencences.
114 *
115 * Return: n/a
116 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530117void hif_vote_link_up(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800118{
Komal Seelam644263d2016-02-22 20:45:49 +0530119 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530120 QDF_BUG(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800121
122 scn->linkstate_vote++;
123 if (scn->linkstate_vote == 1)
Houston Hoffmancceec342015-11-11 11:37:20 -0800124 hif_bus_prevent_linkdown(scn, true);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800125}
126
127/**
128 * hif_can_suspend_link(): query if hif is permitted to suspend the link
129 *
130 * Hif will ensure that the link won't be suspended if the upperlayers
131 * don't want it to.
132 *
133 * SYNCHRONIZATION: MC thread is stopped before bus suspend thus
134 * we don't need extra locking to ensure votes dont change while
135 * we are in the process of suspending or resuming.
136 *
137 * Return: false if hif will guarantee link up durring suspend.
138 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530139bool hif_can_suspend_link(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800140{
Komal Seelam644263d2016-02-22 20:45:49 +0530141 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530142 QDF_BUG(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800143
144 return scn->linkstate_vote == 0;
145}
146
Houston Hoffman4f529982016-05-05 16:11:04 -0700147#ifndef CONFIG_WIN
148#define QCA9984_HOST_INTEREST_ADDRESS -1
149#define QCA9888_HOST_INTEREST_ADDRESS -1
150#define IPQ4019_HOST_INTEREST_ADDRESS -1
151#endif
152
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800153/**
154 * hif_hia_item_address(): hif_hia_item_address
155 * @target_type: target_type
156 * @item_offset: item_offset
157 *
158 * Return: n/a
159 */
160uint32_t hif_hia_item_address(uint32_t target_type, uint32_t item_offset)
161{
162 switch (target_type) {
163 case TARGET_TYPE_AR6002:
164 return AR6002_HOST_INTEREST_ADDRESS + item_offset;
165 case TARGET_TYPE_AR6003:
166 return AR6003_HOST_INTEREST_ADDRESS + item_offset;
167 case TARGET_TYPE_AR6004:
168 return AR6004_HOST_INTEREST_ADDRESS + item_offset;
169 case TARGET_TYPE_AR6006:
170 return AR6006_HOST_INTEREST_ADDRESS + item_offset;
171 case TARGET_TYPE_AR9888:
172 return AR9888_HOST_INTEREST_ADDRESS + item_offset;
173 case TARGET_TYPE_AR6320:
174 case TARGET_TYPE_AR6320V2:
175 return AR6320_HOST_INTEREST_ADDRESS + item_offset;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800176 case TARGET_TYPE_ADRASTEA:
177 /* ADRASTEA doesn't have a host interest address */
178 ASSERT(0);
179 return 0;
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700180 case TARGET_TYPE_AR900B:
181 return AR900B_HOST_INTEREST_ADDRESS + item_offset;
182 case TARGET_TYPE_QCA9984:
183 return QCA9984_HOST_INTEREST_ADDRESS + item_offset;
184 case TARGET_TYPE_QCA9888:
185 return QCA9888_HOST_INTEREST_ADDRESS + item_offset;
186 case TARGET_TYPE_IPQ4019:
187 return IPQ4019_HOST_INTEREST_ADDRESS + item_offset;
188
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800189 default:
190 ASSERT(0);
191 return 0;
192 }
193}
194
195/**
196 * hif_max_num_receives_reached() - check max receive is reached
Komal Seelambd7c51d2016-02-24 10:27:30 +0530197 * @scn: HIF Context
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800198 * @count: unsigned int.
199 *
200 * Output check status as bool
201 *
202 * Return: bool
203 */
Komal Seelambd7c51d2016-02-24 10:27:30 +0530204bool hif_max_num_receives_reached(struct hif_softc *scn, unsigned int count)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800205{
Houston Hoffman75ef5a52016-04-14 17:15:49 -0700206 if (QDF_IS_EPPING_ENABLED(hif_get_conparam(scn)))
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800207 return count > 120;
208 else
209 return count > MAX_NUM_OF_RECEIVES;
210}
211
212/**
213 * init_buffer_count() - initial buffer count
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530214 * @maxSize: qdf_size_t
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800215 *
216 * routine to modify the initial buffer count to be allocated on an os
217 * platform basis. Platform owner will need to modify this as needed
218 *
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530219 * Return: qdf_size_t
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800220 */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530221qdf_size_t init_buffer_count(qdf_size_t maxSize)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800222{
223 return maxSize;
224}
225
226/**
Nirav Shahd7f91592016-04-21 14:18:43 +0530227 * hif_save_htc_htt_config_endpoint() - save htt_tx_endpoint
228 * @hif_ctx: hif context
229 * @htc_htt_tx_endpoint: htt_tx_endpoint
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800230 *
231 * Return: void
232 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530233void hif_save_htc_htt_config_endpoint(struct hif_opaque_softc *hif_ctx,
Nirav Shahd7f91592016-04-21 14:18:43 +0530234 int htc_htt_tx_endpoint)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800235{
Komal Seelam644263d2016-02-22 20:45:49 +0530236 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800237
238 if (!scn) {
239 HIF_ERROR("%s: error: scn or scn->hif_sc is NULL!",
240 __func__);
241 return;
242 }
243
Nirav Shahd7f91592016-04-21 14:18:43 +0530244 scn->htc_htt_tx_endpoint = htc_htt_tx_endpoint;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800245}
246
Houston Hoffmanec93ab02016-05-03 20:09:55 -0700247static const struct qwlan_hw qwlan_hw_list[] = {
248 {
249 .id = AR6320_REV1_VERSION,
250 .subid = 0,
251 .name = "QCA6174_REV1",
252 },
253 {
254 .id = AR6320_REV1_1_VERSION,
255 .subid = 0x1,
256 .name = "QCA6174_REV1_1",
257 },
258 {
259 .id = AR6320_REV1_3_VERSION,
260 .subid = 0x2,
261 .name = "QCA6174_REV1_3",
262 },
263 {
264 .id = AR6320_REV2_1_VERSION,
265 .subid = 0x4,
266 .name = "QCA6174_REV2_1",
267 },
268 {
269 .id = AR6320_REV2_1_VERSION,
270 .subid = 0x5,
271 .name = "QCA6174_REV2_2",
272 },
273 {
274 .id = AR6320_REV3_VERSION,
275 .subid = 0x6,
276 .name = "QCA6174_REV2.3",
277 },
278 {
279 .id = AR6320_REV3_VERSION,
280 .subid = 0x8,
281 .name = "QCA6174_REV3",
282 },
283 {
284 .id = AR6320_REV3_VERSION,
285 .subid = 0x9,
286 .name = "QCA6174_REV3_1",
287 },
288 {
289 .id = AR6320_REV3_2_VERSION,
290 .subid = 0xA,
291 .name = "AR6320_REV3_2_VERSION",
Houston Hoffmancd0884a2016-08-24 15:30:09 -0700292 },
293 {
294 .id = WCN3990_v1,
295 .subid = 0x0,
296 .name = "WCN3990_V1",
Houston Hoffmanec93ab02016-05-03 20:09:55 -0700297 }
298};
299
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800300/**
301 * hif_get_hw_name(): get a human readable name for the hardware
Komal Seelam91553ce2016-01-27 18:57:10 +0530302 * @info: Target Info
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800303 *
Komal Seelam91553ce2016-01-27 18:57:10 +0530304 * Return: human readable name for the underlying wifi hardware.
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800305 */
Komal Seelam91553ce2016-01-27 18:57:10 +0530306static const char *hif_get_hw_name(struct hif_target_info *info)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800307{
308 int i;
Komal Seelam91553ce2016-01-27 18:57:10 +0530309
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800310 for (i = 0; i < ARRAY_SIZE(qwlan_hw_list); i++) {
Komal Seelam91553ce2016-01-27 18:57:10 +0530311 if (info->target_version == qwlan_hw_list[i].id &&
312 info->target_revision == qwlan_hw_list[i].subid) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800313 return qwlan_hw_list[i].name;
314 }
315 }
316
317 return "Unknown Device";
318}
319
320/**
321 * hif_get_hw_info(): hif_get_hw_info
322 * @scn: scn
323 * @version: version
324 * @revision: revision
325 *
326 * Return: n/a
327 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530328void hif_get_hw_info(struct hif_opaque_softc *scn, u32 *version, u32 *revision,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800329 const char **target_name)
330{
Komal Seelam91553ce2016-01-27 18:57:10 +0530331 struct hif_target_info *info = hif_get_target_info_handle(scn);
Mohit Khanna440c5292016-05-12 11:05:06 -0700332 struct hif_softc *sc = HIF_GET_SOFTC(scn);
333
334 if (sc->bus_type == QDF_BUS_TYPE_USB)
335 hif_usb_get_hw_info(sc);
336
Komal Seelam91553ce2016-01-27 18:57:10 +0530337 *version = info->target_version;
338 *revision = info->target_revision;
339 *target_name = hif_get_hw_name(info);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800340}
341
342/**
343 * hif_open(): hif_open
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530344 * @qdf_ctx: QDF Context
Komal Seelambd7c51d2016-02-24 10:27:30 +0530345 * @mode: Driver Mode
346 * @bus_type: Bus Type
347 * @cbk: CDS Callbacks
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800348 *
Komal Seelambd7c51d2016-02-24 10:27:30 +0530349 * API to open HIF Context
350 *
351 * Return: HIF Opaque Pointer
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800352 */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530353struct hif_opaque_softc *hif_open(qdf_device_t qdf_ctx, uint32_t mode,
354 enum qdf_bus_type bus_type,
Komal Seelam75080122016-03-02 15:18:25 +0530355 struct hif_driver_state_callbacks *cbk)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800356{
Komal Seelam644263d2016-02-22 20:45:49 +0530357 struct hif_softc *scn;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530358 QDF_STATUS status = QDF_STATUS_SUCCESS;
Houston Hoffman162164c2016-03-14 21:12:10 -0700359 int bus_context_size = hif_bus_get_context_size(bus_type);
360
361 if (bus_context_size == 0) {
362 HIF_ERROR("%s: context size 0 not allowed", __func__);
363 return NULL;
364 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800365
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530366 scn = (struct hif_softc *)qdf_mem_malloc(bus_context_size);
Komal Seelambd7c51d2016-02-24 10:27:30 +0530367 if (!scn) {
368 HIF_ERROR("%s: cannot alloc memory for HIF context of size:%d",
369 __func__, bus_context_size);
370 return GET_HIF_OPAQUE_HDL(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800371 }
372
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530373 qdf_mem_zero(scn, bus_context_size);
Komal Seelambd7c51d2016-02-24 10:27:30 +0530374
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530375 scn->qdf_dev = qdf_ctx;
Komal Seelambd7c51d2016-02-24 10:27:30 +0530376 scn->hif_con_param = mode;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530377 qdf_atomic_init(&scn->active_tasklet_cnt);
Venkateswara Swamy Bandaru31108f32016-08-08 18:04:29 +0530378 qdf_atomic_init(&scn->active_grp_tasklet_cnt);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530379 qdf_atomic_init(&scn->link_suspended);
380 qdf_atomic_init(&scn->tasklet_from_intr);
Komal Seelam75080122016-03-02 15:18:25 +0530381 qdf_mem_copy(&scn->callbacks, cbk, sizeof(struct hif_driver_state_callbacks));
Houston Hoffman3db96a42016-05-05 19:54:39 -0700382 scn->bus_type = bus_type;
Houston Hoffman3cfe6862016-01-08 10:33:55 -0800383 status = hif_bus_open(scn, bus_type);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530384 if (status != QDF_STATUS_SUCCESS) {
Houston Hoffman3cfe6862016-01-08 10:33:55 -0800385 HIF_ERROR("%s: hif_bus_open error = %d, bus_type = %d",
386 __func__, status, bus_type);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530387 qdf_mem_free(scn);
Komal Seelambd7c51d2016-02-24 10:27:30 +0530388 scn = NULL;
Houston Hoffman3cfe6862016-01-08 10:33:55 -0800389 }
390
Komal Seelambd7c51d2016-02-24 10:27:30 +0530391 return GET_HIF_OPAQUE_HDL(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800392}
393
394/**
395 * hif_close(): hif_close
396 * @hif_ctx: hif_ctx
397 *
398 * Return: n/a
399 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530400void hif_close(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800401{
Komal Seelam644263d2016-02-22 20:45:49 +0530402 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800403
404 if (scn == NULL) {
Komal Seelam5584a7c2016-02-24 19:22:48 +0530405 HIF_ERROR("%s: hif_opaque_softc is NULL", __func__);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800406 return;
407 }
408
409 if (scn->athdiag_procfs_inited) {
410 athdiag_procfs_remove();
411 scn->athdiag_procfs_inited = false;
412 }
413
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800414 hif_bus_close(scn);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530415 qdf_mem_free(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800416}
417
418/**
419 * hif_enable(): hif_enable
420 * @hif_ctx: hif_ctx
421 * @dev: dev
422 * @bdev: bus dev
423 * @bid: bus ID
424 * @bus_type: bus type
425 * @type: enable type
426 *
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530427 * Return: QDF_STATUS
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800428 */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530429QDF_STATUS hif_enable(struct hif_opaque_softc *hif_ctx, struct device *dev,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800430 void *bdev, const hif_bus_id *bid,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530431 enum qdf_bus_type bus_type,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800432 enum hif_enable_type type)
433{
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530434 QDF_STATUS status;
Komal Seelam644263d2016-02-22 20:45:49 +0530435 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800436
437 if (scn == NULL) {
438 HIF_ERROR("%s: hif_ctx = NULL", __func__);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530439 return QDF_STATUS_E_NULL_VALUE;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800440 }
441
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800442 status = hif_enable_bus(scn, dev, bdev, bid, type);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530443 if (status != QDF_STATUS_SUCCESS) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800444 HIF_ERROR("%s: hif_enable_bus error = %d",
445 __func__, status);
446 return status;
447 }
448
Houston Hoffman108da402016-03-14 21:11:24 -0700449 if (hif_bus_configure(scn)) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800450 HIF_ERROR("%s: Target probe failed.", __func__);
Vishwajith Upendra3f78aa62016-02-09 17:53:02 +0530451 hif_disable_bus(scn);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530452 status = QDF_STATUS_E_FAILURE;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800453 return status;
454 }
Houston Hoffman108da402016-03-14 21:11:24 -0700455
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800456 /*
457 * Flag to avoid potential unallocated memory access from MSI
458 * interrupt handler which could get scheduled as soon as MSI
459 * is enabled, i.e to take care of the race due to the order
460 * in where MSI is enabled before the memory, that will be
461 * in interrupt handlers, is allocated.
462 */
463
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800464 scn->hif_init_done = true;
465
Mohit Khanna440c5292016-05-12 11:05:06 -0700466 HIF_TRACE("%s: OK", __func__);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800467
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530468 return QDF_STATUS_SUCCESS;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800469}
470
Komal Seelam5584a7c2016-02-24 19:22:48 +0530471void hif_disable(struct hif_opaque_softc *hif_ctx, enum hif_disable_type type)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800472{
Komal Seelam644263d2016-02-22 20:45:49 +0530473 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800474
475 if (!scn)
476 return;
477
478 hif_nointrs(scn);
479 if (scn->hif_init_done == false)
Poddar, Siddarthe41943f2016-04-27 15:33:48 +0530480 hif_shutdown_device(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800481 else
Komal Seelam644263d2016-02-22 20:45:49 +0530482 hif_stop(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800483
Vishwajith Upendra3f78aa62016-02-09 17:53:02 +0530484 hif_disable_bus(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800485
Komal Seelambd7c51d2016-02-24 10:27:30 +0530486 hif_wlan_disable(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800487
488 scn->notice_send = false;
489
490 HIF_INFO("%s: X", __func__);
491}
492
Nirav Shahb70bd732016-05-25 14:31:51 +0530493void hif_display_stats(struct hif_opaque_softc *hif_ctx)
494{
495 hif_display_bus_stats(hif_ctx);
496}
497
498void hif_clear_stats(struct hif_opaque_softc *hif_ctx)
499{
500 hif_clear_bus_stats(hif_ctx);
501}
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800502
503/**
Govind Singh2443fb32016-01-13 17:44:48 +0530504 * hif_crash_shutdown_dump_bus_register() - dump bus registers
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800505 * @hif_ctx: hif_ctx
506 *
507 * Return: n/a
508 */
509#if defined(TARGET_RAMDUMP_AFTER_KERNEL_PANIC) \
Houston Hoffmanbc693492016-03-14 21:11:41 -0700510&& defined(DEBUG)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800511
Govind Singh2443fb32016-01-13 17:44:48 +0530512static void hif_crash_shutdown_dump_bus_register(void *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800513{
Komal Seelam5584a7c2016-02-24 19:22:48 +0530514 struct hif_opaque_softc *scn = hif_ctx;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800515
Govind Singh2443fb32016-01-13 17:44:48 +0530516 if (hif_check_soc_status(scn))
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800517 return;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800518
Govind Singh2443fb32016-01-13 17:44:48 +0530519 if (hif_dump_registers(scn))
520 HIF_ERROR("Failed to dump bus registers!");
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800521}
522
523/**
524 * hif_crash_shutdown(): hif_crash_shutdown
525 *
526 * This function is called by the platform driver to dump CE registers
527 *
528 * @hif_ctx: hif_ctx
529 *
530 * Return: n/a
531 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530532void hif_crash_shutdown(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800533{
Komal Seelam644263d2016-02-22 20:45:49 +0530534 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800535
Houston Hoffmanbc693492016-03-14 21:11:41 -0700536 if (!hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800537 return;
538
Houston Hoffmanbc693492016-03-14 21:11:41 -0700539 if (scn->bus_type == QDF_BUS_TYPE_SNOC) {
540 HIF_INFO_MED("%s: RAM dump disabled for bustype %d",
541 __func__, scn->bus_type);
542 return;
543 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800544
Komal Seelam6ee55902016-04-11 17:11:07 +0530545 if (TARGET_STATUS_RESET == scn->target_status) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800546 HIF_INFO_MED("%s: Target is already asserted, ignore!",
547 __func__);
548 return;
549 }
550
Komal Seelambd7c51d2016-02-24 10:27:30 +0530551 if (hif_is_load_or_unload_in_progress(scn)) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800552 HIF_ERROR("%s: Load/unload is in progress, ignore!", __func__);
553 return;
554 }
555
Govind Singh2443fb32016-01-13 17:44:48 +0530556 hif_crash_shutdown_dump_bus_register(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800557
Komal Seelam644263d2016-02-22 20:45:49 +0530558 if (ol_copy_ramdump(hif_ctx))
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800559 goto out;
560
561 HIF_INFO_MED("%s: RAM dump collecting completed!", __func__);
562
563out:
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800564 return;
565}
566#else
Komal Seelam5584a7c2016-02-24 19:22:48 +0530567void hif_crash_shutdown(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800568{
569 HIF_INFO_MED("%s: Collecting target RAM dump disabled",
570 __func__);
571 return;
572}
573#endif /* TARGET_RAMDUMP_AFTER_KERNEL_PANIC */
574
575#ifdef QCA_WIFI_3_0
576/**
577 * hif_check_fw_reg(): hif_check_fw_reg
578 * @scn: scn
579 * @state:
580 *
581 * Return: int
582 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530583int hif_check_fw_reg(struct hif_opaque_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800584{
585 return 0;
586}
587#endif
588
589#ifdef IPA_OFFLOAD
590/**
591 * hif_read_phy_mem_base(): hif_read_phy_mem_base
592 * @scn: scn
593 * @phy_mem_base: physical mem base
594 *
595 * Return: n/a
596 */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530597void hif_read_phy_mem_base(struct hif_softc *scn, qdf_dma_addr_t *phy_mem_base)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800598{
599 *phy_mem_base = scn->mem_pa;
600}
601#endif /* IPA_OFFLOAD */
602
603/**
604 * hif_get_device_type(): hif_get_device_type
605 * @device_id: device_id
606 * @revision_id: revision_id
607 * @hif_type: returned hif_type
608 * @target_type: returned target_type
609 *
610 * Return: int
611 */
612int hif_get_device_type(uint32_t device_id,
613 uint32_t revision_id,
614 uint32_t *hif_type, uint32_t *target_type)
615{
616 int ret = 0;
617
618 switch (device_id) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800619 case ADRASTEA_DEVICE_ID:
620 case ADRASTEA_DEVICE_ID_P2_E12:
621
622 *hif_type = HIF_TYPE_ADRASTEA;
623 *target_type = TARGET_TYPE_ADRASTEA;
624 break;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800625
626 case AR9888_DEVICE_ID:
627 *hif_type = HIF_TYPE_AR9888;
628 *target_type = TARGET_TYPE_AR9888;
629 break;
630
631 case AR6320_DEVICE_ID:
632 switch (revision_id) {
633 case AR6320_FW_1_1:
634 case AR6320_FW_1_3:
635 *hif_type = HIF_TYPE_AR6320;
636 *target_type = TARGET_TYPE_AR6320;
637 break;
638
639 case AR6320_FW_2_0:
640 case AR6320_FW_3_0:
641 case AR6320_FW_3_2:
642 *hif_type = HIF_TYPE_AR6320V2;
643 *target_type = TARGET_TYPE_AR6320V2;
644 break;
645
646 default:
647 HIF_ERROR("%s: error - dev_id = 0x%x, rev_id = 0x%x",
648 __func__, device_id, revision_id);
649 ret = -ENODEV;
650 goto end;
651 }
652 break;
653
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700654 case AR9887_DEVICE_ID:
655 *hif_type = HIF_TYPE_AR9888;
656 *target_type = TARGET_TYPE_AR9888;
Houston Hoffmanc50572b2016-06-08 19:49:46 -0700657 HIF_INFO(" *********** AR9887 **************");
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700658 break;
659
660 case QCA9984_DEVICE_ID:
661 *hif_type = HIF_TYPE_QCA9984;
662 *target_type = TARGET_TYPE_QCA9984;
Houston Hoffmanc50572b2016-06-08 19:49:46 -0700663 HIF_INFO(" *********** QCA9984 *************");
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700664 break;
665
666 case QCA9888_DEVICE_ID:
667 *hif_type = HIF_TYPE_QCA9888;
668 *target_type = TARGET_TYPE_QCA9888;
Houston Hoffmanc50572b2016-06-08 19:49:46 -0700669 HIF_INFO(" *********** QCA9888 *************");
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700670 break;
671
672 case AR900B_DEVICE_ID:
673 *hif_type = HIF_TYPE_AR900B;
674 *target_type = TARGET_TYPE_AR900B;
Houston Hoffmanc50572b2016-06-08 19:49:46 -0700675 HIF_INFO(" *********** AR900B *************");
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700676 break;
677
Houston Hoffman3db96a42016-05-05 19:54:39 -0700678 case IPQ4019_DEVICE_ID:
679 *hif_type = HIF_TYPE_IPQ4019;
680 *target_type = TARGET_TYPE_IPQ4019;
Houston Hoffmanc50572b2016-06-08 19:49:46 -0700681 HIF_INFO(" *********** IPQ4019 *************");
Houston Hoffman3db96a42016-05-05 19:54:39 -0700682 break;
683
Venkateswara Swamy Bandaru9fd9af02016-09-20 20:27:31 +0530684 case QCA8074_DEVICE_ID:
685 *hif_type = HIF_TYPE_QCA8074;
686 *target_type = TARGET_TYPE_QCA8074;
687 HIF_INFO(" *********** QCA8074 *************\n");
688 break;
689
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800690 default:
691 HIF_ERROR("%s: Unsupported device ID!", __func__);
692 ret = -ENODEV;
693 break;
694 }
695end:
696 return ret;
697}
Komal Seelam91553ce2016-01-27 18:57:10 +0530698
699/**
Houston Hoffman26352592016-03-14 21:11:43 -0700700 * hif_needs_bmi() - return true if the soc needs bmi through the driver
701 * @hif_ctx: hif context
702 *
703 * Return: true if the soc needs driver bmi otherwise false
704 */
705bool hif_needs_bmi(struct hif_opaque_softc *hif_ctx)
706{
707 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
708 return hif_sc->bus_type != QDF_BUS_TYPE_SNOC;
709}
710
711/**
Houston Hoffman60a1eeb2016-03-14 21:11:44 -0700712 * hif_get_bus_type() - return the bus type
713 *
714 * Return: enum qdf_bus_type
715 */
716enum qdf_bus_type hif_get_bus_type(struct hif_opaque_softc *hif_hdl)
717{
718 struct hif_softc *scn = HIF_GET_SOFTC(hif_hdl);
719 return scn->bus_type;
720}
721
722/**
Komal Seelam91553ce2016-01-27 18:57:10 +0530723 * Target info and ini parameters are global to the driver
724 * Hence these structures are exposed to all the modules in
725 * the driver and they don't need to maintains multiple copies
726 * of the same info, instead get the handle from hif and
727 * modify them in hif
728 */
729
730/**
731 * hif_get_ini_handle() - API to get hif_config_param handle
Komal Seelam644263d2016-02-22 20:45:49 +0530732 * @hif_ctx: HIF Context
Komal Seelam91553ce2016-01-27 18:57:10 +0530733 *
734 * Return: pointer to hif_config_info
735 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530736struct hif_config_info *hif_get_ini_handle(struct hif_opaque_softc *hif_ctx)
Komal Seelam91553ce2016-01-27 18:57:10 +0530737{
Komal Seelam644263d2016-02-22 20:45:49 +0530738 struct hif_softc *sc = HIF_GET_SOFTC(hif_ctx);
739
740 return &sc->hif_config;
Komal Seelam91553ce2016-01-27 18:57:10 +0530741}
742
743/**
744 * hif_get_target_info_handle() - API to get hif_target_info handle
Komal Seelam644263d2016-02-22 20:45:49 +0530745 * @hif_ctx: HIF context
Komal Seelam91553ce2016-01-27 18:57:10 +0530746 *
747 * Return: Pointer to hif_target_info
748 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530749struct hif_target_info *hif_get_target_info_handle(
750 struct hif_opaque_softc *hif_ctx)
Komal Seelam91553ce2016-01-27 18:57:10 +0530751{
Komal Seelam644263d2016-02-22 20:45:49 +0530752 struct hif_softc *sc = HIF_GET_SOFTC(hif_ctx);
753
754 return &sc->target_info;
755
Komal Seelam91553ce2016-01-27 18:57:10 +0530756}
Komal Seelamc92a0cf2016-02-22 20:43:52 +0530757
758#if defined(FEATURE_LRO)
759/**
760 * hif_lro_flush_cb_register - API to register for LRO Flush Callback
761 * @scn: HIF Context
762 * @handler: Function pointer to be called by HIF
763 * @data: Private data to be used by the module registering to HIF
764 *
765 * Return: void
766 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530767void hif_lro_flush_cb_register(struct hif_opaque_softc *scn,
768 void (handler)(void *), void *data)
Komal Seelamc92a0cf2016-02-22 20:43:52 +0530769{
770 ce_lro_flush_cb_register(scn, handler, data);
771}
772
773/**
774 * hif_lro_flush_cb_deregister - API to deregister for LRO Flush Callbacks
775 * @scn: HIF Context
776 *
777 * Return: void
778 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530779void hif_lro_flush_cb_deregister(struct hif_opaque_softc *scn)
Komal Seelamc92a0cf2016-02-22 20:43:52 +0530780{
781 ce_lro_flush_cb_deregister(scn);
782}
783#endif
Komal Seelam644263d2016-02-22 20:45:49 +0530784
785/**
786 * hif_get_target_status - API to get target status
787 * @hif_ctx: HIF Context
788 *
Komal Seelam6ee55902016-04-11 17:11:07 +0530789 * Return: enum hif_target_status
Komal Seelam644263d2016-02-22 20:45:49 +0530790 */
Komal Seelam6ee55902016-04-11 17:11:07 +0530791enum hif_target_status hif_get_target_status(struct hif_opaque_softc *hif_ctx)
Komal Seelam644263d2016-02-22 20:45:49 +0530792{
793 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
794
795 return scn->target_status;
796}
797
798/**
Komal Seelama5911d32016-02-24 19:21:59 +0530799 * hif_set_target_status() - API to set target status
Komal Seelam644263d2016-02-22 20:45:49 +0530800 * @hif_ctx: HIF Context
801 * @status: Target Status
802 *
803 * Return: void
804 */
Komal Seelam6ee55902016-04-11 17:11:07 +0530805void hif_set_target_status(struct hif_opaque_softc *hif_ctx, enum
806 hif_target_status status)
Komal Seelam644263d2016-02-22 20:45:49 +0530807{
808 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
809
810 scn->target_status = status;
811}
Komal Seelama5911d32016-02-24 19:21:59 +0530812
813/**
814 * hif_init_ini_config() - API to initialize HIF configuration parameters
815 * @hif_ctx: HIF Context
816 * @cfg: HIF Configuration
817 *
818 * Return: void
819 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530820void hif_init_ini_config(struct hif_opaque_softc *hif_ctx,
821 struct hif_config_info *cfg)
Komal Seelama5911d32016-02-24 19:21:59 +0530822{
823 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
824
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530825 qdf_mem_copy(&scn->hif_config, cfg, sizeof(struct hif_config_info));
Komal Seelama5911d32016-02-24 19:21:59 +0530826}
Komal Seelambd7c51d2016-02-24 10:27:30 +0530827
828/**
829 * hif_get_conparam() - API to get driver mode in HIF
830 * @scn: HIF Context
831 *
832 * Return: driver mode of operation
833 */
834uint32_t hif_get_conparam(struct hif_softc *scn)
835{
836 if (!scn)
837 return 0;
838
839 return scn->hif_con_param;
840}
841
842/**
843 * hif_get_callbacks_handle() - API to get callbacks Handle
844 * @scn: HIF Context
845 *
846 * Return: pointer to HIF Callbacks
847 */
Komal Seelam75080122016-03-02 15:18:25 +0530848struct hif_driver_state_callbacks *hif_get_callbacks_handle(struct hif_softc *scn)
Komal Seelambd7c51d2016-02-24 10:27:30 +0530849{
850 return &scn->callbacks;
851}
852
853/**
854 * hif_is_driver_unloading() - API to query upper layers if driver is unloading
855 * @scn: HIF Context
856 *
857 * Return: True/False
858 */
859bool hif_is_driver_unloading(struct hif_softc *scn)
860{
Komal Seelam75080122016-03-02 15:18:25 +0530861 struct hif_driver_state_callbacks *cbk = hif_get_callbacks_handle(scn);
Komal Seelambd7c51d2016-02-24 10:27:30 +0530862
863 if (cbk && cbk->is_driver_unloading)
864 return cbk->is_driver_unloading(cbk->context);
865
866 return false;
867}
868
869/**
870 * hif_is_load_or_unload_in_progress() - API to query upper layers if
871 * load/unload in progress
872 * @scn: HIF Context
873 *
874 * Return: True/False
875 */
876bool hif_is_load_or_unload_in_progress(struct hif_softc *scn)
877{
Komal Seelam75080122016-03-02 15:18:25 +0530878 struct hif_driver_state_callbacks *cbk = hif_get_callbacks_handle(scn);
Komal Seelambd7c51d2016-02-24 10:27:30 +0530879
880 if (cbk && cbk->is_load_unload_in_progress)
881 return cbk->is_load_unload_in_progress(cbk->context);
882
883 return false;
884}
885
886/**
887 * hif_is_recovery_in_progress() - API to query upper layers if recovery in
888 * progress
889 * @scn: HIF Context
890 *
891 * Return: True/False
892 */
893bool hif_is_recovery_in_progress(struct hif_softc *scn)
894{
Komal Seelam75080122016-03-02 15:18:25 +0530895 struct hif_driver_state_callbacks *cbk = hif_get_callbacks_handle(scn);
Komal Seelambd7c51d2016-02-24 10:27:30 +0530896
897 if (cbk && cbk->is_recovery_in_progress)
898 return cbk->is_recovery_in_progress(cbk->context);
899
900 return false;
901}
Mohit Khanna440c5292016-05-12 11:05:06 -0700902#if defined(HIF_PCI) || defined(SNOC) || defined(HIF_AHB)
Houston Hoffman56e0d702016-05-05 17:48:06 -0700903/**
904 * hif_batch_send() - API to access hif specific function
905 * ce_batch_send.
906 * @osc: HIF Context
907 * @msdu : list of msdus to be sent
908 * @transfer_id : transfer id
909 * @len : donwloaded length
910 *
911 * Return: list of msds not sent
912 */
913qdf_nbuf_t hif_batch_send(struct hif_opaque_softc *osc, qdf_nbuf_t msdu,
914 uint32_t transfer_id, u_int32_t len, uint32_t sendhead)
915{
916 void *ce_tx_hdl = hif_get_ce_handle(osc, CE_HTT_TX_CE);
917 return ce_batch_send((struct CE_handle *)ce_tx_hdl, msdu, transfer_id,
918 len, sendhead);
919}
920
921/**
922 * hif_update_tx_ring() - API to access hif specific function
923 * ce_update_tx_ring.
924 * @osc: HIF Context
925 * @num_htt_cmpls : number of htt compl received.
926 *
927 * Return: void
928 */
929void hif_update_tx_ring(struct hif_opaque_softc *osc, u_int32_t num_htt_cmpls)
930{
931 void *ce_tx_hdl = hif_get_ce_handle(osc, CE_HTT_TX_CE);
932 ce_update_tx_ring(ce_tx_hdl, num_htt_cmpls);
933}
934
935
936/**
937 * hif_send_single() - API to access hif specific function
938 * ce_send_single.
939 * @osc: HIF Context
940 * @msdu : msdu to be sent
941 * @transfer_id: transfer id
942 * @len : downloaded length
943 *
944 * Return: msdu sent status
945 */
946int hif_send_single(struct hif_opaque_softc *osc, qdf_nbuf_t msdu, uint32_t
947 transfer_id, u_int32_t len)
948{
949 void *ce_tx_hdl = hif_get_ce_handle(osc, CE_HTT_TX_CE);
950 return ce_send_single((struct CE_handle *)ce_tx_hdl, msdu, transfer_id,
951 len);
952}
953
954/**
955 * hif_send_fast() - API to access hif specific function
956 * ce_send_fast.
957 * @osc: HIF Context
958 * @msdu : array of msdus to be sent
959 * @num_msdus : number of msdus in an array
960 * @transfer_id: transfer id
Nirav Shahda0881a2016-05-16 10:45:16 +0530961 * @download_len: download length
Houston Hoffman56e0d702016-05-05 17:48:06 -0700962 *
963 * Return: No. of packets that could be sent
964 */
Nirav Shahda0881a2016-05-16 10:45:16 +0530965int hif_send_fast(struct hif_opaque_softc *osc, qdf_nbuf_t nbuf,
966 uint32_t transfer_id, uint32_t download_len)
Houston Hoffman56e0d702016-05-05 17:48:06 -0700967{
968 void *ce_tx_hdl = hif_get_ce_handle(osc, CE_HTT_TX_CE);
Nirav Shahda0881a2016-05-16 10:45:16 +0530969 return ce_send_fast((struct CE_handle *)ce_tx_hdl, nbuf,
970 transfer_id, download_len);
Houston Hoffman56e0d702016-05-05 17:48:06 -0700971}
Mohit Khanna440c5292016-05-12 11:05:06 -0700972#endif
Houston Hoffman56e0d702016-05-05 17:48:06 -0700973
974/**
975 * hif_reg_write() - API to access hif specific function
976 * hif_write32_mb.
977 * @hif_ctx : HIF Context
978 * @offset : offset on which value has to be written
979 * @value : value to be written
980 *
981 * Return: None
982 */
983void hif_reg_write(struct hif_opaque_softc *hif_ctx, uint32_t offset,
984 uint32_t value)
985{
986 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
987 hif_write32_mb(scn->mem + offset, value);
988
989}
990
991/**
992 * hif_reg_read() - API to access hif specific function
993 * hif_read32_mb.
994 * @hif_ctx : HIF Context
995 * @offset : offset from which value has to be read
996 *
997 * Return: Read value
998 */
999uint32_t hif_reg_read(struct hif_opaque_softc *hif_ctx, uint32_t offset)
1000{
1001
1002 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
1003 return hif_read32_mb(scn->mem + offset);
1004}
Mohit Khanna440c5292016-05-12 11:05:06 -07001005
1006#if defined(HIF_USB)
1007/**
1008 * hif_ramdump_handler(): generic ramdump handler
1009 * @scn: struct hif_opaque_softc
1010 *
1011 * Return: None
1012 */
1013
1014void hif_ramdump_handler(struct hif_opaque_softc *scn)
1015
1016{
1017 if (hif_get_bus_type == QDF_BUS_TYPE_USB)
1018 hif_usb_ramdump_handler();
1019}
1020#endif
Venkateswara Swamy Bandaru31108f32016-08-08 18:04:29 +05301021
1022/**
1023 * hif_register_ext_group_int_handler() - API to register external group
1024 * interrupt handler.
1025 * @hif_ctx : HIF Context
1026 * @numirq: number of irq's in the group
1027 * @irq: array of irq values
1028 * @ext_intr_handler: callback interrupt handler function
1029 * @context: context to passed in callback
1030 *
1031 * Return: status
1032 */
1033uint32_t hif_register_ext_group_int_handler(struct hif_opaque_softc *hif_ctx,
1034 uint32_t numirq, uint32_t irq[], ext_intr_handler handler,
1035 void *context)
1036{
1037 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
1038 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
1039 struct hif_ext_group_entry *hif_ext_group;
1040
1041 if (scn->hif_init_done) {
1042 HIF_ERROR("%s Called after HIF initialization \n", __func__);
1043 return QDF_STATUS_E_FAILURE;
1044 }
1045
1046 if (hif_state->hif_num_extgroup >= HIF_MAX_GROUP) {
1047 HIF_ERROR("%s Max groups reached\n", __func__);
1048 return QDF_STATUS_E_FAILURE;
1049 }
1050
1051 if (numirq >= HIF_MAX_GRP_IRQ) {
1052 HIF_ERROR("%s invalid numirq\n", __func__);
1053 return QDF_STATUS_E_FAILURE;
1054 }
1055
1056 hif_ext_group = &hif_state->hif_ext_group[hif_state->hif_num_extgroup];
1057
1058 hif_ext_group->numirq = numirq;
1059 qdf_mem_copy(&hif_ext_group->irq[0], irq, numirq * sizeof(irq[0]));
1060 hif_ext_group->context = context;
1061 hif_ext_group->handler = handler;
1062 hif_ext_group->configured = true;
1063 hif_ext_group->grp_id = hif_state->hif_num_extgroup;
1064
1065 hif_state->hif_num_extgroup++;
1066 return QDF_STATUS_SUCCESS;
1067}
1068
1069/**
1070 * hif_ext_grp_tasklet() - grp tasklet
1071 * data: context
1072 *
1073 * return: void
1074 */
1075void hif_ext_grp_tasklet(unsigned long data)
1076{
1077 struct hif_ext_group_entry *hif_ext_group =
1078 (struct hif_ext_group_entry *)data;
1079 struct HIF_CE_state *hif_state = hif_ext_group->hif_state;
1080 struct hif_softc *scn = HIF_GET_SOFTC(hif_state);
1081
1082 if (hif_ext_group->grp_id < HIF_MAX_GROUP) {
1083 hif_ext_group->handler(hif_ext_group->context, HIF_MAX_BUDGET);
1084 hif_grp_irq_enable(scn, hif_ext_group->grp_id);
1085 } else {
1086 HIF_ERROR("%s: ERROR - invalid grp_id = %d",
1087 __func__, hif_ext_group->grp_id);
1088 }
1089
1090 qdf_atomic_dec(&scn->active_grp_tasklet_cnt);
1091}
1092
1093/**
1094 * hif_grp_tasklet_kill() - grp tasklet kill
1095 * scn: hif_softc
1096 *
1097 * return: void
1098 */
1099void hif_grp_tasklet_kill(struct hif_softc *scn)
1100{
1101 int i;
1102 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
1103
1104 for (i = 0; i < HIF_MAX_GROUP; i++)
1105 if (hif_state->hif_ext_group[i].inited) {
1106 tasklet_kill(&hif_state->hif_ext_group[i].intr_tq);
1107 hif_state->hif_ext_group[i].inited = false;
1108 }
1109 qdf_atomic_set(&scn->active_grp_tasklet_cnt, 0);
1110}