blob: 8a82d5814cf06379a09a5db7730180b61591d9a7 [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
Manjunathappa Prakash2146da32016-10-13 14:47:47 -070052#include "hif_napi.h"
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080053
Komal Seelam5584a7c2016-02-24 19:22:48 +053054void hif_dump(struct hif_opaque_softc *hif_ctx, uint8_t cmd_id, bool start)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080055{
Poddar, Siddarthe41943f2016-04-27 15:33:48 +053056 hif_trigger_dump(hif_ctx, cmd_id, start);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080057}
58
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080059/**
60 * hif_get_target_id(): hif_get_target_id
61 *
62 * Return the virtual memory base address to the caller
63 *
Komal Seelam644263d2016-02-22 20:45:49 +053064 * @scn: hif_softc
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080065 *
66 * Return: A_target_id_t
67 */
Komal Seelam644263d2016-02-22 20:45:49 +053068A_target_id_t hif_get_target_id(struct hif_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080069{
70 return scn->mem;
71}
72
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080073/**
74 * hif_get_targetdef(): hif_get_targetdef
75 * @scn: scn
76 *
77 * Return: void *
78 */
Komal Seelam5584a7c2016-02-24 19:22:48 +053079void *hif_get_targetdef(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080080{
Komal Seelam644263d2016-02-22 20:45:49 +053081 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
82
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080083 return scn->targetdef;
84}
85
86/**
87 * hif_vote_link_down(): unvote for link up
88 *
89 * Call hif_vote_link_down to release a previous request made using
90 * hif_vote_link_up. A hif_vote_link_down call should only be made
91 * after a corresponding hif_vote_link_up, otherwise you could be
92 * negating a vote from another source. When no votes are present
93 * hif will not guarantee the linkstate after hif_bus_suspend.
94 *
95 * SYNCHRONIZE WITH hif_vote_link_up by only calling in MC thread
96 * and initialization deinitialization sequencences.
97 *
98 * Return: n/a
99 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530100void hif_vote_link_down(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800101{
Komal Seelam644263d2016-02-22 20:45:49 +0530102 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530103 QDF_BUG(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800104
105 scn->linkstate_vote--;
106 if (scn->linkstate_vote == 0)
Houston Hoffmancceec342015-11-11 11:37:20 -0800107 hif_bus_prevent_linkdown(scn, false);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800108}
109
110/**
111 * hif_vote_link_up(): vote to prevent bus from suspending
112 *
113 * Makes hif guarantee that fw can message the host normally
114 * durring suspend.
115 *
116 * SYNCHRONIZE WITH hif_vote_link_up by only calling in MC thread
117 * and initialization deinitialization sequencences.
118 *
119 * Return: n/a
120 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530121void hif_vote_link_up(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800122{
Komal Seelam644263d2016-02-22 20:45:49 +0530123 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530124 QDF_BUG(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800125
126 scn->linkstate_vote++;
127 if (scn->linkstate_vote == 1)
Houston Hoffmancceec342015-11-11 11:37:20 -0800128 hif_bus_prevent_linkdown(scn, true);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800129}
130
131/**
132 * hif_can_suspend_link(): query if hif is permitted to suspend the link
133 *
134 * Hif will ensure that the link won't be suspended if the upperlayers
135 * don't want it to.
136 *
137 * SYNCHRONIZATION: MC thread is stopped before bus suspend thus
138 * we don't need extra locking to ensure votes dont change while
139 * we are in the process of suspending or resuming.
140 *
141 * Return: false if hif will guarantee link up durring suspend.
142 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530143bool hif_can_suspend_link(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800144{
Komal Seelam644263d2016-02-22 20:45:49 +0530145 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530146 QDF_BUG(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800147
148 return scn->linkstate_vote == 0;
149}
150
Houston Hoffman4f529982016-05-05 16:11:04 -0700151#ifndef CONFIG_WIN
152#define QCA9984_HOST_INTEREST_ADDRESS -1
153#define QCA9888_HOST_INTEREST_ADDRESS -1
154#define IPQ4019_HOST_INTEREST_ADDRESS -1
155#endif
156
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800157/**
158 * hif_hia_item_address(): hif_hia_item_address
159 * @target_type: target_type
160 * @item_offset: item_offset
161 *
162 * Return: n/a
163 */
164uint32_t hif_hia_item_address(uint32_t target_type, uint32_t item_offset)
165{
166 switch (target_type) {
167 case TARGET_TYPE_AR6002:
168 return AR6002_HOST_INTEREST_ADDRESS + item_offset;
169 case TARGET_TYPE_AR6003:
170 return AR6003_HOST_INTEREST_ADDRESS + item_offset;
171 case TARGET_TYPE_AR6004:
172 return AR6004_HOST_INTEREST_ADDRESS + item_offset;
173 case TARGET_TYPE_AR6006:
174 return AR6006_HOST_INTEREST_ADDRESS + item_offset;
175 case TARGET_TYPE_AR9888:
176 return AR9888_HOST_INTEREST_ADDRESS + item_offset;
177 case TARGET_TYPE_AR6320:
178 case TARGET_TYPE_AR6320V2:
179 return AR6320_HOST_INTEREST_ADDRESS + item_offset;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800180 case TARGET_TYPE_ADRASTEA:
181 /* ADRASTEA doesn't have a host interest address */
182 ASSERT(0);
183 return 0;
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700184 case TARGET_TYPE_AR900B:
185 return AR900B_HOST_INTEREST_ADDRESS + item_offset;
186 case TARGET_TYPE_QCA9984:
187 return QCA9984_HOST_INTEREST_ADDRESS + item_offset;
188 case TARGET_TYPE_QCA9888:
189 return QCA9888_HOST_INTEREST_ADDRESS + item_offset;
190 case TARGET_TYPE_IPQ4019:
191 return IPQ4019_HOST_INTEREST_ADDRESS + item_offset;
192
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800193 default:
194 ASSERT(0);
195 return 0;
196 }
197}
198
Nandha Kishore Easwarancbff9c92016-11-24 13:31:19 +0530199#ifdef NAPI_YIELD_BUDGET_BASED
200bool hif_max_num_receives_reached(struct hif_softc *scn, unsigned int count)
201{
202 if (QDF_IS_EPPING_ENABLED(hif_get_conparam(scn)))
203 return count > 120;
204 else
205 return count > MAX_REAP_COUNT_PER_NAPI_POLL;
206}
207#else
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800208/**
209 * hif_max_num_receives_reached() - check max receive is reached
Komal Seelambd7c51d2016-02-24 10:27:30 +0530210 * @scn: HIF Context
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800211 * @count: unsigned int.
212 *
213 * Output check status as bool
214 *
215 * Return: bool
216 */
Komal Seelambd7c51d2016-02-24 10:27:30 +0530217bool hif_max_num_receives_reached(struct hif_softc *scn, unsigned int count)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800218{
Houston Hoffman75ef5a52016-04-14 17:15:49 -0700219 if (QDF_IS_EPPING_ENABLED(hif_get_conparam(scn)))
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800220 return count > 120;
221 else
222 return count > MAX_NUM_OF_RECEIVES;
223}
Nandha Kishore Easwarancbff9c92016-11-24 13:31:19 +0530224#endif
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800225
226/**
227 * init_buffer_count() - initial buffer count
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530228 * @maxSize: qdf_size_t
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800229 *
230 * routine to modify the initial buffer count to be allocated on an os
231 * platform basis. Platform owner will need to modify this as needed
232 *
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530233 * Return: qdf_size_t
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800234 */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530235qdf_size_t init_buffer_count(qdf_size_t maxSize)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800236{
237 return maxSize;
238}
239
240/**
Nirav Shahd7f91592016-04-21 14:18:43 +0530241 * hif_save_htc_htt_config_endpoint() - save htt_tx_endpoint
242 * @hif_ctx: hif context
243 * @htc_htt_tx_endpoint: htt_tx_endpoint
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800244 *
245 * Return: void
246 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530247void hif_save_htc_htt_config_endpoint(struct hif_opaque_softc *hif_ctx,
Nirav Shahd7f91592016-04-21 14:18:43 +0530248 int htc_htt_tx_endpoint)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800249{
Komal Seelam644263d2016-02-22 20:45:49 +0530250 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800251
252 if (!scn) {
253 HIF_ERROR("%s: error: scn or scn->hif_sc is NULL!",
254 __func__);
255 return;
256 }
257
Nirav Shahd7f91592016-04-21 14:18:43 +0530258 scn->htc_htt_tx_endpoint = htc_htt_tx_endpoint;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800259}
260
Houston Hoffmanec93ab02016-05-03 20:09:55 -0700261static const struct qwlan_hw qwlan_hw_list[] = {
262 {
263 .id = AR6320_REV1_VERSION,
264 .subid = 0,
265 .name = "QCA6174_REV1",
266 },
267 {
268 .id = AR6320_REV1_1_VERSION,
269 .subid = 0x1,
270 .name = "QCA6174_REV1_1",
271 },
272 {
273 .id = AR6320_REV1_3_VERSION,
274 .subid = 0x2,
275 .name = "QCA6174_REV1_3",
276 },
277 {
278 .id = AR6320_REV2_1_VERSION,
279 .subid = 0x4,
280 .name = "QCA6174_REV2_1",
281 },
282 {
283 .id = AR6320_REV2_1_VERSION,
284 .subid = 0x5,
285 .name = "QCA6174_REV2_2",
286 },
287 {
288 .id = AR6320_REV3_VERSION,
289 .subid = 0x6,
290 .name = "QCA6174_REV2.3",
291 },
292 {
293 .id = AR6320_REV3_VERSION,
294 .subid = 0x8,
295 .name = "QCA6174_REV3",
296 },
297 {
298 .id = AR6320_REV3_VERSION,
299 .subid = 0x9,
300 .name = "QCA6174_REV3_1",
301 },
302 {
303 .id = AR6320_REV3_2_VERSION,
304 .subid = 0xA,
305 .name = "AR6320_REV3_2_VERSION",
Houston Hoffmancd0884a2016-08-24 15:30:09 -0700306 },
307 {
308 .id = WCN3990_v1,
309 .subid = 0x0,
310 .name = "WCN3990_V1",
Houston Hoffmandd4da482016-10-17 12:41:45 -0700311 },
312 {
313 .id = WCN3990_v2,
314 .subid = 0x0,
315 .name = "WCN3990_V2",
Houston Hoffman59fd2452016-11-19 17:27:10 -0800316 },
317 {
318 .id = WCN3990_v2_1,
319 .subid = 0x0,
320 .name = "WCN3990_V2.1",
Yingying Tangd8921742016-10-18 18:13:07 +0800321 },
322 {
323 .id = QCA9379_REV1_VERSION,
324 .subid = 0xC,
325 .name = "QCA9379_REV1",
Houston Hoffmanec93ab02016-05-03 20:09:55 -0700326 }
327};
328
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800329/**
330 * hif_get_hw_name(): get a human readable name for the hardware
Komal Seelam91553ce2016-01-27 18:57:10 +0530331 * @info: Target Info
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800332 *
Komal Seelam91553ce2016-01-27 18:57:10 +0530333 * Return: human readable name for the underlying wifi hardware.
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800334 */
Komal Seelam91553ce2016-01-27 18:57:10 +0530335static const char *hif_get_hw_name(struct hif_target_info *info)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800336{
337 int i;
Komal Seelam91553ce2016-01-27 18:57:10 +0530338
Houston Hoffman60af6752016-11-21 12:13:36 -0800339 if (info->hw_name)
340 return info->hw_name;
341
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800342 for (i = 0; i < ARRAY_SIZE(qwlan_hw_list); i++) {
Komal Seelam91553ce2016-01-27 18:57:10 +0530343 if (info->target_version == qwlan_hw_list[i].id &&
344 info->target_revision == qwlan_hw_list[i].subid) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800345 return qwlan_hw_list[i].name;
346 }
347 }
348
Houston Hoffman60af6752016-11-21 12:13:36 -0800349 info->hw_name = qdf_mem_malloc(64);
350 if (!info->hw_name)
351 return "Unknown Device (nomem)";
352
353 i = qdf_snprint(info->hw_name, 64, "HW_VERSION=%x.",
354 info->target_version);
355 if (i < 0)
356 return "Unknown Device (snprintf failure)";
357 else
358 return info->hw_name;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800359}
360
361/**
362 * hif_get_hw_info(): hif_get_hw_info
363 * @scn: scn
364 * @version: version
365 * @revision: revision
366 *
367 * Return: n/a
368 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530369void hif_get_hw_info(struct hif_opaque_softc *scn, u32 *version, u32 *revision,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800370 const char **target_name)
371{
Komal Seelam91553ce2016-01-27 18:57:10 +0530372 struct hif_target_info *info = hif_get_target_info_handle(scn);
Mohit Khanna440c5292016-05-12 11:05:06 -0700373 struct hif_softc *sc = HIF_GET_SOFTC(scn);
374
375 if (sc->bus_type == QDF_BUS_TYPE_USB)
376 hif_usb_get_hw_info(sc);
377
Komal Seelam91553ce2016-01-27 18:57:10 +0530378 *version = info->target_version;
379 *revision = info->target_revision;
380 *target_name = hif_get_hw_name(info);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800381}
382
383/**
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530384 * hif_get_dev_ba(): API to get device base address.
385 * @scn: scn
386 * @version: version
387 * @revision: revision
388 *
389 * Return: n/a
390 */
391void *hif_get_dev_ba(struct hif_opaque_softc *hif_handle)
392{
393 struct hif_softc *scn = (struct hif_softc *)hif_handle;
394
395 return scn->mem;
396}
397/**
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800398 * hif_open(): hif_open
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530399 * @qdf_ctx: QDF Context
Komal Seelambd7c51d2016-02-24 10:27:30 +0530400 * @mode: Driver Mode
401 * @bus_type: Bus Type
402 * @cbk: CDS Callbacks
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800403 *
Komal Seelambd7c51d2016-02-24 10:27:30 +0530404 * API to open HIF Context
405 *
406 * Return: HIF Opaque Pointer
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800407 */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530408struct hif_opaque_softc *hif_open(qdf_device_t qdf_ctx, uint32_t mode,
409 enum qdf_bus_type bus_type,
Komal Seelam75080122016-03-02 15:18:25 +0530410 struct hif_driver_state_callbacks *cbk)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800411{
Komal Seelam644263d2016-02-22 20:45:49 +0530412 struct hif_softc *scn;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530413 QDF_STATUS status = QDF_STATUS_SUCCESS;
Houston Hoffman162164c2016-03-14 21:12:10 -0700414 int bus_context_size = hif_bus_get_context_size(bus_type);
415
416 if (bus_context_size == 0) {
417 HIF_ERROR("%s: context size 0 not allowed", __func__);
418 return NULL;
419 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800420
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530421 scn = (struct hif_softc *)qdf_mem_malloc(bus_context_size);
Komal Seelambd7c51d2016-02-24 10:27:30 +0530422 if (!scn) {
423 HIF_ERROR("%s: cannot alloc memory for HIF context of size:%d",
424 __func__, bus_context_size);
425 return GET_HIF_OPAQUE_HDL(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800426 }
427
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530428 qdf_mem_zero(scn, bus_context_size);
Komal Seelambd7c51d2016-02-24 10:27:30 +0530429
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530430 scn->qdf_dev = qdf_ctx;
Komal Seelambd7c51d2016-02-24 10:27:30 +0530431 scn->hif_con_param = mode;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530432 qdf_atomic_init(&scn->active_tasklet_cnt);
Venkateswara Swamy Bandaru31108f32016-08-08 18:04:29 +0530433 qdf_atomic_init(&scn->active_grp_tasklet_cnt);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530434 qdf_atomic_init(&scn->link_suspended);
435 qdf_atomic_init(&scn->tasklet_from_intr);
Komal Seelam75080122016-03-02 15:18:25 +0530436 qdf_mem_copy(&scn->callbacks, cbk, sizeof(struct hif_driver_state_callbacks));
Houston Hoffman3db96a42016-05-05 19:54:39 -0700437 scn->bus_type = bus_type;
Houston Hoffman3cfe6862016-01-08 10:33:55 -0800438 status = hif_bus_open(scn, bus_type);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530439 if (status != QDF_STATUS_SUCCESS) {
Houston Hoffman3cfe6862016-01-08 10:33:55 -0800440 HIF_ERROR("%s: hif_bus_open error = %d, bus_type = %d",
441 __func__, status, bus_type);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530442 qdf_mem_free(scn);
Komal Seelambd7c51d2016-02-24 10:27:30 +0530443 scn = NULL;
Houston Hoffman3cfe6862016-01-08 10:33:55 -0800444 }
445
Komal Seelambd7c51d2016-02-24 10:27:30 +0530446 return GET_HIF_OPAQUE_HDL(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800447}
448
449/**
450 * hif_close(): hif_close
451 * @hif_ctx: hif_ctx
452 *
453 * Return: n/a
454 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530455void hif_close(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800456{
Komal Seelam644263d2016-02-22 20:45:49 +0530457 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800458
459 if (scn == NULL) {
Komal Seelam5584a7c2016-02-24 19:22:48 +0530460 HIF_ERROR("%s: hif_opaque_softc is NULL", __func__);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800461 return;
462 }
463
464 if (scn->athdiag_procfs_inited) {
465 athdiag_procfs_remove();
466 scn->athdiag_procfs_inited = false;
467 }
468
Houston Hoffman60af6752016-11-21 12:13:36 -0800469 if (scn->target_info.hw_name) {
470 char *hw_name = scn->target_info.hw_name;
471 scn->target_info.hw_name = "ErrUnloading";
472 qdf_mem_free(hw_name);
473 }
474
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800475 hif_bus_close(scn);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530476 qdf_mem_free(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800477}
478
Houston Hoffman6fe60592016-11-18 13:12:08 -0800479#ifdef QCA_WIFI_QCA8074
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530480static QDF_STATUS hif_hal_attach(struct hif_softc *scn)
481{
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530482 if (ce_srng_based(scn)) {
483 scn->hal_soc = hal_attach(scn, scn->qdf_dev);
484 if (scn->hal_soc == NULL)
485 return QDF_STATUS_E_FAILURE;
486 }
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530487
488 return QDF_STATUS_SUCCESS;
489}
Houston Hoffman6fe60592016-11-18 13:12:08 -0800490#else
491static QDF_STATUS hif_hal_attach(struct hif_softc *scn)
492{
493 return QDF_STATUS_SUCCESS;
494}
495#endif
496
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800497/**
498 * hif_enable(): hif_enable
499 * @hif_ctx: hif_ctx
500 * @dev: dev
501 * @bdev: bus dev
502 * @bid: bus ID
503 * @bus_type: bus type
504 * @type: enable type
505 *
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530506 * Return: QDF_STATUS
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800507 */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530508QDF_STATUS hif_enable(struct hif_opaque_softc *hif_ctx, struct device *dev,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800509 void *bdev, const hif_bus_id *bid,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530510 enum qdf_bus_type bus_type,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800511 enum hif_enable_type type)
512{
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530513 QDF_STATUS status;
Komal Seelam644263d2016-02-22 20:45:49 +0530514 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800515
516 if (scn == NULL) {
517 HIF_ERROR("%s: hif_ctx = NULL", __func__);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530518 return QDF_STATUS_E_NULL_VALUE;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800519 }
520
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800521 status = hif_enable_bus(scn, dev, bdev, bid, type);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530522 if (status != QDF_STATUS_SUCCESS) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800523 HIF_ERROR("%s: hif_enable_bus error = %d",
524 __func__, status);
525 return status;
526 }
527
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530528 status = hif_hal_attach(scn);
529 if (status != QDF_STATUS_SUCCESS) {
530 HIF_ERROR("%s: hal attach failed", __func__);
531 return status;
532 }
533
Houston Hoffman108da402016-03-14 21:11:24 -0700534 if (hif_bus_configure(scn)) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800535 HIF_ERROR("%s: Target probe failed.", __func__);
Vishwajith Upendra3f78aa62016-02-09 17:53:02 +0530536 hif_disable_bus(scn);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530537 status = QDF_STATUS_E_FAILURE;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800538 return status;
539 }
Houston Hoffman108da402016-03-14 21:11:24 -0700540
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800541 /*
542 * Flag to avoid potential unallocated memory access from MSI
543 * interrupt handler which could get scheduled as soon as MSI
544 * is enabled, i.e to take care of the race due to the order
545 * in where MSI is enabled before the memory, that will be
546 * in interrupt handlers, is allocated.
547 */
548
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800549 scn->hif_init_done = true;
550
Mohit Khanna440c5292016-05-12 11:05:06 -0700551 HIF_TRACE("%s: OK", __func__);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800552
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530553 return QDF_STATUS_SUCCESS;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800554}
555
Komal Seelam5584a7c2016-02-24 19:22:48 +0530556void hif_disable(struct hif_opaque_softc *hif_ctx, enum hif_disable_type type)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800557{
Komal Seelam644263d2016-02-22 20:45:49 +0530558 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800559
560 if (!scn)
561 return;
562
563 hif_nointrs(scn);
564 if (scn->hif_init_done == false)
Poddar, Siddarthe41943f2016-04-27 15:33:48 +0530565 hif_shutdown_device(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800566 else
Komal Seelam644263d2016-02-22 20:45:49 +0530567 hif_stop(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800568
Vishwajith Upendra3f78aa62016-02-09 17:53:02 +0530569 hif_disable_bus(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800570
Komal Seelambd7c51d2016-02-24 10:27:30 +0530571 hif_wlan_disable(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800572
573 scn->notice_send = false;
574
575 HIF_INFO("%s: X", __func__);
576}
577
Nirav Shahb70bd732016-05-25 14:31:51 +0530578void hif_display_stats(struct hif_opaque_softc *hif_ctx)
579{
580 hif_display_bus_stats(hif_ctx);
581}
582
583void hif_clear_stats(struct hif_opaque_softc *hif_ctx)
584{
585 hif_clear_bus_stats(hif_ctx);
586}
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800587
588/**
Govind Singh2443fb32016-01-13 17:44:48 +0530589 * hif_crash_shutdown_dump_bus_register() - dump bus registers
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800590 * @hif_ctx: hif_ctx
591 *
592 * Return: n/a
593 */
594#if defined(TARGET_RAMDUMP_AFTER_KERNEL_PANIC) \
Houston Hoffmanbc693492016-03-14 21:11:41 -0700595&& defined(DEBUG)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800596
Govind Singh2443fb32016-01-13 17:44:48 +0530597static void hif_crash_shutdown_dump_bus_register(void *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800598{
Komal Seelam5584a7c2016-02-24 19:22:48 +0530599 struct hif_opaque_softc *scn = hif_ctx;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800600
Govind Singh2443fb32016-01-13 17:44:48 +0530601 if (hif_check_soc_status(scn))
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800602 return;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800603
Govind Singh2443fb32016-01-13 17:44:48 +0530604 if (hif_dump_registers(scn))
605 HIF_ERROR("Failed to dump bus registers!");
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800606}
607
608/**
609 * hif_crash_shutdown(): hif_crash_shutdown
610 *
611 * This function is called by the platform driver to dump CE registers
612 *
613 * @hif_ctx: hif_ctx
614 *
615 * Return: n/a
616 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530617void hif_crash_shutdown(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800618{
Komal Seelam644263d2016-02-22 20:45:49 +0530619 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800620
Houston Hoffmanbc693492016-03-14 21:11:41 -0700621 if (!hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800622 return;
623
Houston Hoffmanbc693492016-03-14 21:11:41 -0700624 if (scn->bus_type == QDF_BUS_TYPE_SNOC) {
625 HIF_INFO_MED("%s: RAM dump disabled for bustype %d",
626 __func__, scn->bus_type);
627 return;
628 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800629
Komal Seelam6ee55902016-04-11 17:11:07 +0530630 if (TARGET_STATUS_RESET == scn->target_status) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800631 HIF_INFO_MED("%s: Target is already asserted, ignore!",
632 __func__);
633 return;
634 }
635
Komal Seelambd7c51d2016-02-24 10:27:30 +0530636 if (hif_is_load_or_unload_in_progress(scn)) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800637 HIF_ERROR("%s: Load/unload is in progress, ignore!", __func__);
638 return;
639 }
640
Govind Singh2443fb32016-01-13 17:44:48 +0530641 hif_crash_shutdown_dump_bus_register(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800642
Komal Seelam644263d2016-02-22 20:45:49 +0530643 if (ol_copy_ramdump(hif_ctx))
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800644 goto out;
645
646 HIF_INFO_MED("%s: RAM dump collecting completed!", __func__);
647
648out:
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800649 return;
650}
651#else
Komal Seelam5584a7c2016-02-24 19:22:48 +0530652void hif_crash_shutdown(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800653{
654 HIF_INFO_MED("%s: Collecting target RAM dump disabled",
655 __func__);
656 return;
657}
658#endif /* TARGET_RAMDUMP_AFTER_KERNEL_PANIC */
659
660#ifdef QCA_WIFI_3_0
661/**
662 * hif_check_fw_reg(): hif_check_fw_reg
663 * @scn: scn
664 * @state:
665 *
666 * Return: int
667 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530668int hif_check_fw_reg(struct hif_opaque_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800669{
670 return 0;
671}
672#endif
673
674#ifdef IPA_OFFLOAD
675/**
676 * hif_read_phy_mem_base(): hif_read_phy_mem_base
677 * @scn: scn
678 * @phy_mem_base: physical mem base
679 *
680 * Return: n/a
681 */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530682void hif_read_phy_mem_base(struct hif_softc *scn, qdf_dma_addr_t *phy_mem_base)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800683{
684 *phy_mem_base = scn->mem_pa;
685}
686#endif /* IPA_OFFLOAD */
687
688/**
689 * hif_get_device_type(): hif_get_device_type
690 * @device_id: device_id
691 * @revision_id: revision_id
692 * @hif_type: returned hif_type
693 * @target_type: returned target_type
694 *
695 * Return: int
696 */
697int hif_get_device_type(uint32_t device_id,
698 uint32_t revision_id,
699 uint32_t *hif_type, uint32_t *target_type)
700{
701 int ret = 0;
702
703 switch (device_id) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800704 case ADRASTEA_DEVICE_ID_P2_E12:
705
706 *hif_type = HIF_TYPE_ADRASTEA;
707 *target_type = TARGET_TYPE_ADRASTEA;
708 break;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800709
710 case AR9888_DEVICE_ID:
711 *hif_type = HIF_TYPE_AR9888;
712 *target_type = TARGET_TYPE_AR9888;
713 break;
714
715 case AR6320_DEVICE_ID:
716 switch (revision_id) {
717 case AR6320_FW_1_1:
718 case AR6320_FW_1_3:
719 *hif_type = HIF_TYPE_AR6320;
720 *target_type = TARGET_TYPE_AR6320;
721 break;
722
723 case AR6320_FW_2_0:
724 case AR6320_FW_3_0:
725 case AR6320_FW_3_2:
726 *hif_type = HIF_TYPE_AR6320V2;
727 *target_type = TARGET_TYPE_AR6320V2;
728 break;
729
730 default:
731 HIF_ERROR("%s: error - dev_id = 0x%x, rev_id = 0x%x",
732 __func__, device_id, revision_id);
733 ret = -ENODEV;
734 goto end;
735 }
736 break;
737
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700738 case AR9887_DEVICE_ID:
739 *hif_type = HIF_TYPE_AR9888;
740 *target_type = TARGET_TYPE_AR9888;
Houston Hoffmanc50572b2016-06-08 19:49:46 -0700741 HIF_INFO(" *********** AR9887 **************");
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700742 break;
743
744 case QCA9984_DEVICE_ID:
745 *hif_type = HIF_TYPE_QCA9984;
746 *target_type = TARGET_TYPE_QCA9984;
Houston Hoffmanc50572b2016-06-08 19:49:46 -0700747 HIF_INFO(" *********** QCA9984 *************");
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700748 break;
749
750 case QCA9888_DEVICE_ID:
751 *hif_type = HIF_TYPE_QCA9888;
752 *target_type = TARGET_TYPE_QCA9888;
Houston Hoffmanc50572b2016-06-08 19:49:46 -0700753 HIF_INFO(" *********** QCA9888 *************");
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700754 break;
755
756 case AR900B_DEVICE_ID:
757 *hif_type = HIF_TYPE_AR900B;
758 *target_type = TARGET_TYPE_AR900B;
Houston Hoffmanc50572b2016-06-08 19:49:46 -0700759 HIF_INFO(" *********** AR900B *************");
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700760 break;
761
Houston Hoffman3db96a42016-05-05 19:54:39 -0700762 case IPQ4019_DEVICE_ID:
763 *hif_type = HIF_TYPE_IPQ4019;
764 *target_type = TARGET_TYPE_IPQ4019;
Houston Hoffmanc50572b2016-06-08 19:49:46 -0700765 HIF_INFO(" *********** IPQ4019 *************");
Houston Hoffman3db96a42016-05-05 19:54:39 -0700766 break;
767
Venkateswara Swamy Bandaru9fd9af02016-09-20 20:27:31 +0530768 case QCA8074_DEVICE_ID:
Karunakar Dasinenif61cb072016-09-29 11:50:45 -0700769 case RUMIM2M_DEVICE_ID_NODE0:
770 case RUMIM2M_DEVICE_ID_NODE1:
Venkateswara Swamy Bandaru9fd9af02016-09-20 20:27:31 +0530771 *hif_type = HIF_TYPE_QCA8074;
772 *target_type = TARGET_TYPE_QCA8074;
773 HIF_INFO(" *********** QCA8074 *************\n");
774 break;
775
Houston Hoffman31b25ec2016-09-19 13:12:30 -0700776 case QCA6290_EMULATION_DEVICE_ID:
777 *hif_type = HIF_TYPE_QCA6290;
778 *target_type = TARGET_TYPE_QCA6290;
779 HIF_INFO(" *********** QCA6290EMU *************\n");
780 break;
781
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800782 default:
783 HIF_ERROR("%s: Unsupported device ID!", __func__);
784 ret = -ENODEV;
785 break;
786 }
787end:
788 return ret;
789}
Komal Seelam91553ce2016-01-27 18:57:10 +0530790
791/**
Houston Hoffman26352592016-03-14 21:11:43 -0700792 * hif_needs_bmi() - return true if the soc needs bmi through the driver
793 * @hif_ctx: hif context
794 *
795 * Return: true if the soc needs driver bmi otherwise false
796 */
797bool hif_needs_bmi(struct hif_opaque_softc *hif_ctx)
798{
799 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
Pratik Gandhi815c6d82016-10-19 12:06:32 +0530800
Houston Hoffman6c0c3f92016-09-27 18:05:39 -0700801 return (hif_sc->bus_type != QDF_BUS_TYPE_SNOC) &&
802 !ce_srng_based(hif_sc);
Houston Hoffman26352592016-03-14 21:11:43 -0700803}
804
805/**
Houston Hoffman60a1eeb2016-03-14 21:11:44 -0700806 * hif_get_bus_type() - return the bus type
807 *
808 * Return: enum qdf_bus_type
809 */
810enum qdf_bus_type hif_get_bus_type(struct hif_opaque_softc *hif_hdl)
811{
812 struct hif_softc *scn = HIF_GET_SOFTC(hif_hdl);
813 return scn->bus_type;
814}
815
816/**
Komal Seelam91553ce2016-01-27 18:57:10 +0530817 * Target info and ini parameters are global to the driver
818 * Hence these structures are exposed to all the modules in
819 * the driver and they don't need to maintains multiple copies
820 * of the same info, instead get the handle from hif and
821 * modify them in hif
822 */
823
824/**
825 * hif_get_ini_handle() - API to get hif_config_param handle
Komal Seelam644263d2016-02-22 20:45:49 +0530826 * @hif_ctx: HIF Context
Komal Seelam91553ce2016-01-27 18:57:10 +0530827 *
828 * Return: pointer to hif_config_info
829 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530830struct hif_config_info *hif_get_ini_handle(struct hif_opaque_softc *hif_ctx)
Komal Seelam91553ce2016-01-27 18:57:10 +0530831{
Komal Seelam644263d2016-02-22 20:45:49 +0530832 struct hif_softc *sc = HIF_GET_SOFTC(hif_ctx);
833
834 return &sc->hif_config;
Komal Seelam91553ce2016-01-27 18:57:10 +0530835}
836
837/**
838 * hif_get_target_info_handle() - API to get hif_target_info handle
Komal Seelam644263d2016-02-22 20:45:49 +0530839 * @hif_ctx: HIF context
Komal Seelam91553ce2016-01-27 18:57:10 +0530840 *
841 * Return: Pointer to hif_target_info
842 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530843struct hif_target_info *hif_get_target_info_handle(
844 struct hif_opaque_softc *hif_ctx)
Komal Seelam91553ce2016-01-27 18:57:10 +0530845{
Komal Seelam644263d2016-02-22 20:45:49 +0530846 struct hif_softc *sc = HIF_GET_SOFTC(hif_ctx);
847
848 return &sc->target_info;
849
Komal Seelam91553ce2016-01-27 18:57:10 +0530850}
Komal Seelamc92a0cf2016-02-22 20:43:52 +0530851
852#if defined(FEATURE_LRO)
853/**
854 * hif_lro_flush_cb_register - API to register for LRO Flush Callback
855 * @scn: HIF Context
856 * @handler: Function pointer to be called by HIF
857 * @data: Private data to be used by the module registering to HIF
858 *
859 * Return: void
860 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530861void hif_lro_flush_cb_register(struct hif_opaque_softc *scn,
Manjunathappa Prakash2146da32016-10-13 14:47:47 -0700862 void (lro_flush_handler)(void *),
863 void *(lro_init_handler)(void))
Komal Seelamc92a0cf2016-02-22 20:43:52 +0530864{
Manjunathappa Prakash2146da32016-10-13 14:47:47 -0700865 if (hif_napi_enabled(scn, -1))
866 hif_napi_lro_flush_cb_register(scn, lro_flush_handler,
867 lro_init_handler);
868 else
869 ce_lro_flush_cb_register(scn, lro_flush_handler,
870 lro_init_handler);
871}
872
873/**
874 * hif_get_lro_info - Returns LRO instance for instance ID
875 * @ctx_id: LRO instance ID
876 * @hif_hdl: HIF Context
877 *
878 * Return: Pointer to LRO instance.
879 */
880void *hif_get_lro_info(int ctx_id, struct hif_opaque_softc *hif_hdl)
881{
882 void *data;
883
884 if (hif_napi_enabled(hif_hdl, -1))
885 data = hif_napi_get_lro_info(hif_hdl, ctx_id);
886 else
887 data = hif_ce_get_lro_ctx(hif_hdl, ctx_id);
888
889 return data;
890}
891
892/**
893 * hif_get_rx_ctx_id - Returns LRO instance ID based on underlying LRO instance
894 * @ctx_id: LRO context ID
895 * @hif_hdl: HIF Context
896 *
897 * Return: LRO instance ID
898 */
899int hif_get_rx_ctx_id(int ctx_id, struct hif_opaque_softc *hif_hdl)
900{
901 if (hif_napi_enabled(hif_hdl, -1))
902 return NAPI_PIPE2ID(ctx_id);
903 else
904 return ctx_id;
Komal Seelamc92a0cf2016-02-22 20:43:52 +0530905}
906
907/**
908 * hif_lro_flush_cb_deregister - API to deregister for LRO Flush Callbacks
Manjunathappa Prakash2146da32016-10-13 14:47:47 -0700909 * @hif_hdl: HIF Context
910 * @lro_deinit_cb: LRO deinit callback
Komal Seelamc92a0cf2016-02-22 20:43:52 +0530911 *
912 * Return: void
913 */
Manjunathappa Prakash2146da32016-10-13 14:47:47 -0700914void hif_lro_flush_cb_deregister(struct hif_opaque_softc *hif_hdl,
915 void (lro_deinit_cb)(void *))
Komal Seelamc92a0cf2016-02-22 20:43:52 +0530916{
Manjunathappa Prakash2146da32016-10-13 14:47:47 -0700917 if (hif_napi_enabled(hif_hdl, -1))
918 hif_napi_lro_flush_cb_deregister(hif_hdl, lro_deinit_cb);
919 else
920 ce_lro_flush_cb_deregister(hif_hdl, lro_deinit_cb);
921}
922#else /* !defined(FEATURE_LRO) */
923int hif_get_rx_ctx_id(int ctx_id, struct hif_opaque_softc *hif_hdl)
924{
925 return 0;
Komal Seelamc92a0cf2016-02-22 20:43:52 +0530926}
927#endif
Komal Seelam644263d2016-02-22 20:45:49 +0530928
929/**
930 * hif_get_target_status - API to get target status
931 * @hif_ctx: HIF Context
932 *
Komal Seelam6ee55902016-04-11 17:11:07 +0530933 * Return: enum hif_target_status
Komal Seelam644263d2016-02-22 20:45:49 +0530934 */
Komal Seelam6ee55902016-04-11 17:11:07 +0530935enum hif_target_status hif_get_target_status(struct hif_opaque_softc *hif_ctx)
Komal Seelam644263d2016-02-22 20:45:49 +0530936{
937 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
938
939 return scn->target_status;
940}
941
942/**
Komal Seelama5911d32016-02-24 19:21:59 +0530943 * hif_set_target_status() - API to set target status
Komal Seelam644263d2016-02-22 20:45:49 +0530944 * @hif_ctx: HIF Context
945 * @status: Target Status
946 *
947 * Return: void
948 */
Komal Seelam6ee55902016-04-11 17:11:07 +0530949void hif_set_target_status(struct hif_opaque_softc *hif_ctx, enum
950 hif_target_status status)
Komal Seelam644263d2016-02-22 20:45:49 +0530951{
952 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
953
954 scn->target_status = status;
955}
Komal Seelama5911d32016-02-24 19:21:59 +0530956
957/**
958 * hif_init_ini_config() - API to initialize HIF configuration parameters
959 * @hif_ctx: HIF Context
960 * @cfg: HIF Configuration
961 *
962 * Return: void
963 */
Komal Seelam5584a7c2016-02-24 19:22:48 +0530964void hif_init_ini_config(struct hif_opaque_softc *hif_ctx,
965 struct hif_config_info *cfg)
Komal Seelama5911d32016-02-24 19:21:59 +0530966{
967 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
968
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530969 qdf_mem_copy(&scn->hif_config, cfg, sizeof(struct hif_config_info));
Komal Seelama5911d32016-02-24 19:21:59 +0530970}
Komal Seelambd7c51d2016-02-24 10:27:30 +0530971
972/**
973 * hif_get_conparam() - API to get driver mode in HIF
974 * @scn: HIF Context
975 *
976 * Return: driver mode of operation
977 */
978uint32_t hif_get_conparam(struct hif_softc *scn)
979{
980 if (!scn)
981 return 0;
982
983 return scn->hif_con_param;
984}
985
986/**
987 * hif_get_callbacks_handle() - API to get callbacks Handle
988 * @scn: HIF Context
989 *
990 * Return: pointer to HIF Callbacks
991 */
Komal Seelam75080122016-03-02 15:18:25 +0530992struct hif_driver_state_callbacks *hif_get_callbacks_handle(struct hif_softc *scn)
Komal Seelambd7c51d2016-02-24 10:27:30 +0530993{
994 return &scn->callbacks;
995}
996
997/**
998 * hif_is_driver_unloading() - API to query upper layers if driver is unloading
999 * @scn: HIF Context
1000 *
1001 * Return: True/False
1002 */
1003bool hif_is_driver_unloading(struct hif_softc *scn)
1004{
Komal Seelam75080122016-03-02 15:18:25 +05301005 struct hif_driver_state_callbacks *cbk = hif_get_callbacks_handle(scn);
Komal Seelambd7c51d2016-02-24 10:27:30 +05301006
1007 if (cbk && cbk->is_driver_unloading)
1008 return cbk->is_driver_unloading(cbk->context);
1009
1010 return false;
1011}
1012
1013/**
1014 * hif_is_load_or_unload_in_progress() - API to query upper layers if
1015 * load/unload in progress
1016 * @scn: HIF Context
1017 *
1018 * Return: True/False
1019 */
1020bool hif_is_load_or_unload_in_progress(struct hif_softc *scn)
1021{
Komal Seelam75080122016-03-02 15:18:25 +05301022 struct hif_driver_state_callbacks *cbk = hif_get_callbacks_handle(scn);
Komal Seelambd7c51d2016-02-24 10:27:30 +05301023
1024 if (cbk && cbk->is_load_unload_in_progress)
1025 return cbk->is_load_unload_in_progress(cbk->context);
1026
1027 return false;
1028}
1029
1030/**
Venkateswara Swamy Bandaru26f6f1e2016-10-03 19:35:57 +05301031 * hif_update_pipe_callback() - API to register pipe specific callbacks
1032 * @osc: Opaque softc
1033 * @pipeid: pipe id
1034 * @callbacks: callbacks to register
1035 *
1036 * Return: void
1037 */
1038
1039void hif_update_pipe_callback(struct hif_opaque_softc *osc,
1040 u_int8_t pipeid,
1041 struct hif_msg_callbacks *callbacks)
1042{
1043 struct hif_softc *scn = HIF_GET_SOFTC(osc);
1044 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
1045 struct HIF_CE_pipe_info *pipe_info;
1046
1047 QDF_BUG(pipeid < CE_COUNT_MAX);
1048
1049 HIF_INFO_LO("+%s pipeid %d\n", __func__, pipeid);
1050
1051 pipe_info = &hif_state->pipe_info[pipeid];
1052
1053 qdf_mem_copy(&pipe_info->pipe_callbacks,
1054 callbacks, sizeof(pipe_info->pipe_callbacks));
1055
1056 HIF_INFO_LO("-%s\n", __func__);
1057}
1058
1059/**
Komal Seelambd7c51d2016-02-24 10:27:30 +05301060 * hif_is_recovery_in_progress() - API to query upper layers if recovery in
1061 * progress
1062 * @scn: HIF Context
1063 *
1064 * Return: True/False
1065 */
1066bool hif_is_recovery_in_progress(struct hif_softc *scn)
1067{
Komal Seelam75080122016-03-02 15:18:25 +05301068 struct hif_driver_state_callbacks *cbk = hif_get_callbacks_handle(scn);
Komal Seelambd7c51d2016-02-24 10:27:30 +05301069
1070 if (cbk && cbk->is_recovery_in_progress)
1071 return cbk->is_recovery_in_progress(cbk->context);
1072
1073 return false;
1074}
Mohit Khanna440c5292016-05-12 11:05:06 -07001075#if defined(HIF_PCI) || defined(SNOC) || defined(HIF_AHB)
Houston Hoffman56e0d702016-05-05 17:48:06 -07001076/**
1077 * hif_batch_send() - API to access hif specific function
1078 * ce_batch_send.
1079 * @osc: HIF Context
1080 * @msdu : list of msdus to be sent
1081 * @transfer_id : transfer id
1082 * @len : donwloaded length
1083 *
1084 * Return: list of msds not sent
1085 */
1086qdf_nbuf_t hif_batch_send(struct hif_opaque_softc *osc, qdf_nbuf_t msdu,
1087 uint32_t transfer_id, u_int32_t len, uint32_t sendhead)
1088{
1089 void *ce_tx_hdl = hif_get_ce_handle(osc, CE_HTT_TX_CE);
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05301090
Houston Hoffman56e0d702016-05-05 17:48:06 -07001091 return ce_batch_send((struct CE_handle *)ce_tx_hdl, msdu, transfer_id,
1092 len, sendhead);
1093}
1094
1095/**
1096 * hif_update_tx_ring() - API to access hif specific function
1097 * ce_update_tx_ring.
1098 * @osc: HIF Context
1099 * @num_htt_cmpls : number of htt compl received.
1100 *
1101 * Return: void
1102 */
1103void hif_update_tx_ring(struct hif_opaque_softc *osc, u_int32_t num_htt_cmpls)
1104{
1105 void *ce_tx_hdl = hif_get_ce_handle(osc, CE_HTT_TX_CE);
1106 ce_update_tx_ring(ce_tx_hdl, num_htt_cmpls);
1107}
1108
1109
1110/**
1111 * hif_send_single() - API to access hif specific function
1112 * ce_send_single.
1113 * @osc: HIF Context
1114 * @msdu : msdu to be sent
1115 * @transfer_id: transfer id
1116 * @len : downloaded length
1117 *
1118 * Return: msdu sent status
1119 */
1120int hif_send_single(struct hif_opaque_softc *osc, qdf_nbuf_t msdu, uint32_t
1121 transfer_id, u_int32_t len)
1122{
1123 void *ce_tx_hdl = hif_get_ce_handle(osc, CE_HTT_TX_CE);
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05301124
Houston Hoffman56e0d702016-05-05 17:48:06 -07001125 return ce_send_single((struct CE_handle *)ce_tx_hdl, msdu, transfer_id,
1126 len);
1127}
1128
1129/**
1130 * hif_send_fast() - API to access hif specific function
1131 * ce_send_fast.
1132 * @osc: HIF Context
1133 * @msdu : array of msdus to be sent
1134 * @num_msdus : number of msdus in an array
1135 * @transfer_id: transfer id
Nirav Shahda0881a2016-05-16 10:45:16 +05301136 * @download_len: download length
Houston Hoffman56e0d702016-05-05 17:48:06 -07001137 *
1138 * Return: No. of packets that could be sent
1139 */
Nirav Shahda0881a2016-05-16 10:45:16 +05301140int hif_send_fast(struct hif_opaque_softc *osc, qdf_nbuf_t nbuf,
1141 uint32_t transfer_id, uint32_t download_len)
Houston Hoffman56e0d702016-05-05 17:48:06 -07001142{
1143 void *ce_tx_hdl = hif_get_ce_handle(osc, CE_HTT_TX_CE);
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05301144
Nirav Shahda0881a2016-05-16 10:45:16 +05301145 return ce_send_fast((struct CE_handle *)ce_tx_hdl, nbuf,
1146 transfer_id, download_len);
Houston Hoffman56e0d702016-05-05 17:48:06 -07001147}
Mohit Khanna440c5292016-05-12 11:05:06 -07001148#endif
Houston Hoffman56e0d702016-05-05 17:48:06 -07001149
1150/**
1151 * hif_reg_write() - API to access hif specific function
1152 * hif_write32_mb.
1153 * @hif_ctx : HIF Context
1154 * @offset : offset on which value has to be written
1155 * @value : value to be written
1156 *
1157 * Return: None
1158 */
1159void hif_reg_write(struct hif_opaque_softc *hif_ctx, uint32_t offset,
1160 uint32_t value)
1161{
1162 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
1163 hif_write32_mb(scn->mem + offset, value);
1164
1165}
1166
1167/**
1168 * hif_reg_read() - API to access hif specific function
1169 * hif_read32_mb.
1170 * @hif_ctx : HIF Context
1171 * @offset : offset from which value has to be read
1172 *
1173 * Return: Read value
1174 */
1175uint32_t hif_reg_read(struct hif_opaque_softc *hif_ctx, uint32_t offset)
1176{
1177
1178 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
1179 return hif_read32_mb(scn->mem + offset);
1180}
Mohit Khanna440c5292016-05-12 11:05:06 -07001181
1182#if defined(HIF_USB)
1183/**
1184 * hif_ramdump_handler(): generic ramdump handler
1185 * @scn: struct hif_opaque_softc
1186 *
1187 * Return: None
1188 */
1189
1190void hif_ramdump_handler(struct hif_opaque_softc *scn)
1191
1192{
1193 if (hif_get_bus_type == QDF_BUS_TYPE_USB)
1194 hif_usb_ramdump_handler();
1195}
1196#endif
Venkateswara Swamy Bandaru31108f32016-08-08 18:04:29 +05301197
1198/**
1199 * hif_register_ext_group_int_handler() - API to register external group
1200 * interrupt handler.
1201 * @hif_ctx : HIF Context
1202 * @numirq: number of irq's in the group
1203 * @irq: array of irq values
1204 * @ext_intr_handler: callback interrupt handler function
1205 * @context: context to passed in callback
1206 *
1207 * Return: status
1208 */
1209uint32_t hif_register_ext_group_int_handler(struct hif_opaque_softc *hif_ctx,
1210 uint32_t numirq, uint32_t irq[], ext_intr_handler handler,
1211 void *context)
1212{
1213 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
1214 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
1215 struct hif_ext_group_entry *hif_ext_group;
1216
1217 if (scn->hif_init_done) {
1218 HIF_ERROR("%s Called after HIF initialization \n", __func__);
1219 return QDF_STATUS_E_FAILURE;
1220 }
1221
1222 if (hif_state->hif_num_extgroup >= HIF_MAX_GROUP) {
1223 HIF_ERROR("%s Max groups reached\n", __func__);
1224 return QDF_STATUS_E_FAILURE;
1225 }
1226
1227 if (numirq >= HIF_MAX_GRP_IRQ) {
1228 HIF_ERROR("%s invalid numirq\n", __func__);
1229 return QDF_STATUS_E_FAILURE;
1230 }
1231
1232 hif_ext_group = &hif_state->hif_ext_group[hif_state->hif_num_extgroup];
1233
1234 hif_ext_group->numirq = numirq;
1235 qdf_mem_copy(&hif_ext_group->irq[0], irq, numirq * sizeof(irq[0]));
1236 hif_ext_group->context = context;
1237 hif_ext_group->handler = handler;
1238 hif_ext_group->configured = true;
1239 hif_ext_group->grp_id = hif_state->hif_num_extgroup;
1240
1241 hif_state->hif_num_extgroup++;
1242 return QDF_STATUS_SUCCESS;
1243}
1244
1245/**
1246 * hif_ext_grp_tasklet() - grp tasklet
1247 * data: context
1248 *
1249 * return: void
1250 */
1251void hif_ext_grp_tasklet(unsigned long data)
1252{
1253 struct hif_ext_group_entry *hif_ext_group =
1254 (struct hif_ext_group_entry *)data;
1255 struct HIF_CE_state *hif_state = hif_ext_group->hif_state;
1256 struct hif_softc *scn = HIF_GET_SOFTC(hif_state);
1257
1258 if (hif_ext_group->grp_id < HIF_MAX_GROUP) {
1259 hif_ext_group->handler(hif_ext_group->context, HIF_MAX_BUDGET);
1260 hif_grp_irq_enable(scn, hif_ext_group->grp_id);
1261 } else {
1262 HIF_ERROR("%s: ERROR - invalid grp_id = %d",
1263 __func__, hif_ext_group->grp_id);
1264 }
1265
1266 qdf_atomic_dec(&scn->active_grp_tasklet_cnt);
1267}
1268
1269/**
1270 * hif_grp_tasklet_kill() - grp tasklet kill
1271 * scn: hif_softc
1272 *
1273 * return: void
1274 */
1275void hif_grp_tasklet_kill(struct hif_softc *scn)
1276{
1277 int i;
1278 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
1279
1280 for (i = 0; i < HIF_MAX_GROUP; i++)
1281 if (hif_state->hif_ext_group[i].inited) {
1282 tasklet_kill(&hif_state->hif_ext_group[i].intr_tq);
1283 hif_state->hif_ext_group[i].inited = false;
1284 }
1285 qdf_atomic_set(&scn->active_grp_tasklet_cnt, 0);
1286}