blob: 1af44e5be61a47381aa4ababee0b7cc2977c1000 [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
28#include <osdep.h>
29#include "a_types.h"
30#include "athdefs.h"
31#include "osapi_linux.h"
32#include "targcfg.h"
33#include "cdf_lock.h"
34#include "cdf_status.h"
35#include <cdf_atomic.h> /* cdf_atomic_read */
36#include <targaddrs.h>
37#include <bmi_msg.h>
38#include "hif_io32.h"
39#include <hif.h>
40#include <htc_services.h>
41#include "regtable.h"
42#define ATH_MODULE_NAME hif
43#include <a_debug.h>
44#include "hif_main.h"
45#include "hif_hw_version.h"
46#include "ce_api.h"
47#include "ce_tasklet.h"
48#include "cdf_trace.h"
49#include "cdf_status.h"
50#include "cds_api.h"
51#ifdef CONFIG_CNSS
52#include <net/cnss.h>
53#endif
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080054#include "epping_main.h"
55#include "hif_debug.h"
56#include "mp_dev.h"
57#ifdef HIF_PCI
58#include "icnss_stub.h"
59#else
60#include <soc/qcom/icnss.h>
61#endif
62
Chandrasekaran, Manishekar681d1372015-11-05 10:42:48 +053063#include "cds_concurrency.h"
64
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080065#define AGC_DUMP 1
66#define CHANINFO_DUMP 2
67#define BB_WATCHDOG_DUMP 3
68#ifdef CONFIG_ATH_PCIE_ACCESS_DEBUG
69#define PCIE_ACCESS_DUMP 4
70#endif
71
Komal Seelam644263d2016-02-22 20:45:49 +053072void hif_dump(struct ol_softc *hif_ctx, uint8_t cmd_id, bool start)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080073{
Komal Seelam644263d2016-02-22 20:45:49 +053074 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080075 switch (cmd_id) {
76 case AGC_DUMP:
77 if (start)
78 priv_start_agc(scn);
79 else
80 priv_dump_agc(scn);
81 break;
82
83 case CHANINFO_DUMP:
84 if (start)
85 priv_start_cap_chaninfo(scn);
86 else
87 priv_dump_chaninfo(scn);
88 break;
89
90 case BB_WATCHDOG_DUMP:
91 priv_dump_bbwatchdog(scn);
92 break;
93
94#ifdef CONFIG_ATH_PCIE_ACCESS_DEBUG
95 case PCIE_ACCESS_DUMP:
96 hif_target_dump_access_log();
97 break;
98#endif
99 default:
100 HIF_ERROR("%s: Invalid htc dump command", __func__);
101 break;
102 }
103}
104
105/**
106 * hif_shut_down_device() - hif_shut_down_device
107 *
108 * SThis fucntion shuts down the device
109 *
110 * @scn: ol_softc
111 *
112 * Return: void
113 */
114void hif_shut_down_device(struct ol_softc *scn)
115{
Komal Seelam02cf2f82016-02-22 20:44:25 +0530116 hif_stop(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800117}
118
119
120
121/**
122 * hif_cancel_deferred_target_sleep() - cancel deferred target sleep
123 *
124 * This function cancels the defered target sleep
125 *
126 * @scn: ol_softc
127 *
128 * Return: void
129 */
Komal Seelam644263d2016-02-22 20:45:49 +0530130void hif_cancel_deferred_target_sleep(struct ol_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800131{
Komal Seelam644263d2016-02-22 20:45:49 +0530132 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
133
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800134 hif_pci_cancel_deferred_target_sleep(scn);
135}
136
137/**
138 * hif_get_target_id(): hif_get_target_id
139 *
140 * Return the virtual memory base address to the caller
141 *
Komal Seelam644263d2016-02-22 20:45:49 +0530142 * @scn: hif_softc
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800143 *
144 * Return: A_target_id_t
145 */
Komal Seelam644263d2016-02-22 20:45:49 +0530146A_target_id_t hif_get_target_id(struct hif_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800147{
148 return scn->mem;
149}
150
151/**
152 * hif_set_target_sleep(): hif_set_target_sleep
153 * @scn: scn
154 * @sleep_ok: sleep_ok
155 * @wait_for_it: wait
156 *
157 * Return: void
158 */
Komal Seelam644263d2016-02-22 20:45:49 +0530159void hif_set_target_sleep(struct ol_softc *hif_ctx,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800160 bool sleep_ok, bool wait_for_it)
161{
Komal Seelam644263d2016-02-22 20:45:49 +0530162 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800163 hif_target_sleep_state_adjust(scn,
164 sleep_ok, wait_for_it);
165}
166
167/**
168 * hif_target_forced_awake(): hif_target_forced_awake
169 * @scn: scn
170 *
171 * Return: bool
172 */
Komal Seelam644263d2016-02-22 20:45:49 +0530173bool hif_target_forced_awake(struct hif_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800174{
175 A_target_id_t addr = scn->mem;
176 bool awake;
177 bool forced_awake;
178
179 awake = hif_targ_is_awake(scn, addr);
180
181 forced_awake =
182 !!(hif_read32_mb
183 (addr + PCIE_LOCAL_BASE_ADDRESS +
184 PCIE_SOC_WAKE_ADDRESS) & PCIE_SOC_WAKE_V_MASK);
185
186 return awake && forced_awake;
187}
188
Houston Hoffman0dad5092015-09-28 16:25:51 -0700189
190static inline void hif_fw_event_handler(struct HIF_CE_state *hif_state)
191{
192 struct hif_msg_callbacks *msg_callbacks =
193 &hif_state->msg_callbacks_current;
194
195 if (!msg_callbacks->fwEventHandler)
196 return;
197
198 msg_callbacks->fwEventHandler(msg_callbacks->Context,
199 CDF_STATUS_E_FAILURE);
200}
201
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800202/**
203 * hif_fw_interrupt_handler(): FW interrupt handler
204 *
205 * This function is the FW interrupt handlder
206 *
207 * @irq: irq number
208 * @arg: the user pointer
209 *
210 * Return: bool
211 */
212#ifndef QCA_WIFI_3_0
213irqreturn_t hif_fw_interrupt_handler(int irq, void *arg)
214{
Komal Seelam644263d2016-02-22 20:45:49 +0530215 struct hif_softc *scn = arg;
Komal Seelam02cf2f82016-02-22 20:44:25 +0530216 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800217 uint32_t fw_indicator_address, fw_indicator;
218
219 A_TARGET_ACCESS_BEGIN_RET(scn);
220
221 fw_indicator_address = hif_state->fw_indicator_address;
222 /* For sudden unplug this will return ~0 */
223 fw_indicator = A_TARGET_READ(scn, fw_indicator_address);
224
225 if ((fw_indicator != ~0) && (fw_indicator & FW_IND_EVENT_PENDING)) {
226 /* ACK: clear Target-side pending event */
227 A_TARGET_WRITE(scn, fw_indicator_address,
228 fw_indicator & ~FW_IND_EVENT_PENDING);
229 A_TARGET_ACCESS_END_RET(scn);
230
231 if (hif_state->started) {
Houston Hoffman0dad5092015-09-28 16:25:51 -0700232 hif_fw_event_handler(hif_state);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800233 } else {
234 /*
235 * Probable Target failure before we're prepared
236 * to handle it. Generally unexpected.
237 */
238 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
239 ("%s: Early firmware event indicated\n",
240 __func__));
241 }
242 } else {
243 A_TARGET_ACCESS_END_RET(scn);
244 }
245
246 return ATH_ISR_SCHED;
247}
248#else
249irqreturn_t hif_fw_interrupt_handler(int irq, void *arg)
250{
251 return ATH_ISR_SCHED;
252}
253#endif /* #ifdef QCA_WIFI_3_0 */
254
255/**
256 * hif_get_targetdef(): hif_get_targetdef
257 * @scn: scn
258 *
259 * Return: void *
260 */
Komal Seelam02cf2f82016-02-22 20:44:25 +0530261void *hif_get_targetdef(struct ol_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800262{
Komal Seelam644263d2016-02-22 20:45:49 +0530263 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
264
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800265 return scn->targetdef;
266}
267
268/**
269 * hif_vote_link_down(): unvote for link up
270 *
271 * Call hif_vote_link_down to release a previous request made using
272 * hif_vote_link_up. A hif_vote_link_down call should only be made
273 * after a corresponding hif_vote_link_up, otherwise you could be
274 * negating a vote from another source. When no votes are present
275 * hif will not guarantee the linkstate after hif_bus_suspend.
276 *
277 * SYNCHRONIZE WITH hif_vote_link_up by only calling in MC thread
278 * and initialization deinitialization sequencences.
279 *
280 * Return: n/a
281 */
Komal Seelam644263d2016-02-22 20:45:49 +0530282void hif_vote_link_down(struct ol_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800283{
Komal Seelam644263d2016-02-22 20:45:49 +0530284 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800285 CDF_BUG(scn);
286
287 scn->linkstate_vote--;
288 if (scn->linkstate_vote == 0)
Houston Hoffmancceec342015-11-11 11:37:20 -0800289 hif_bus_prevent_linkdown(scn, false);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800290}
291
292/**
293 * hif_vote_link_up(): vote to prevent bus from suspending
294 *
295 * Makes hif guarantee that fw can message the host normally
296 * durring suspend.
297 *
298 * SYNCHRONIZE WITH hif_vote_link_up by only calling in MC thread
299 * and initialization deinitialization sequencences.
300 *
301 * Return: n/a
302 */
Komal Seelam644263d2016-02-22 20:45:49 +0530303void hif_vote_link_up(struct ol_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800304{
Komal Seelam644263d2016-02-22 20:45:49 +0530305 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800306 CDF_BUG(scn);
307
308 scn->linkstate_vote++;
309 if (scn->linkstate_vote == 1)
Houston Hoffmancceec342015-11-11 11:37:20 -0800310 hif_bus_prevent_linkdown(scn, true);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800311}
312
313/**
314 * hif_can_suspend_link(): query if hif is permitted to suspend the link
315 *
316 * Hif will ensure that the link won't be suspended if the upperlayers
317 * don't want it to.
318 *
319 * SYNCHRONIZATION: MC thread is stopped before bus suspend thus
320 * we don't need extra locking to ensure votes dont change while
321 * we are in the process of suspending or resuming.
322 *
323 * Return: false if hif will guarantee link up durring suspend.
324 */
Komal Seelam644263d2016-02-22 20:45:49 +0530325bool hif_can_suspend_link(struct ol_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800326{
Komal Seelam644263d2016-02-22 20:45:49 +0530327 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800328 CDF_BUG(scn);
329
330 return scn->linkstate_vote == 0;
331}
332
333/**
334 * hif_hia_item_address(): hif_hia_item_address
335 * @target_type: target_type
336 * @item_offset: item_offset
337 *
338 * Return: n/a
339 */
340uint32_t hif_hia_item_address(uint32_t target_type, uint32_t item_offset)
341{
342 switch (target_type) {
343 case TARGET_TYPE_AR6002:
344 return AR6002_HOST_INTEREST_ADDRESS + item_offset;
345 case TARGET_TYPE_AR6003:
346 return AR6003_HOST_INTEREST_ADDRESS + item_offset;
347 case TARGET_TYPE_AR6004:
348 return AR6004_HOST_INTEREST_ADDRESS + item_offset;
349 case TARGET_TYPE_AR6006:
350 return AR6006_HOST_INTEREST_ADDRESS + item_offset;
351 case TARGET_TYPE_AR9888:
352 return AR9888_HOST_INTEREST_ADDRESS + item_offset;
353 case TARGET_TYPE_AR6320:
354 case TARGET_TYPE_AR6320V2:
355 return AR6320_HOST_INTEREST_ADDRESS + item_offset;
356 case TARGET_TYPE_QCA6180:
357 return QCA6180_HOST_INTEREST_ADDRESS + item_offset;
358 case TARGET_TYPE_ADRASTEA:
359 /* ADRASTEA doesn't have a host interest address */
360 ASSERT(0);
361 return 0;
362 default:
363 ASSERT(0);
364 return 0;
365 }
366}
367
368/**
369 * hif_max_num_receives_reached() - check max receive is reached
370 * @count: unsigned int.
371 *
372 * Output check status as bool
373 *
374 * Return: bool
375 */
376bool hif_max_num_receives_reached(unsigned int count)
377{
378 if (WLAN_IS_EPPING_ENABLED(cds_get_conparam()))
379 return count > 120;
380 else
381 return count > MAX_NUM_OF_RECEIVES;
382}
383
384/**
385 * init_buffer_count() - initial buffer count
386 * @maxSize: cdf_size_t
387 *
388 * routine to modify the initial buffer count to be allocated on an os
389 * platform basis. Platform owner will need to modify this as needed
390 *
391 * Return: cdf_size_t
392 */
393cdf_size_t init_buffer_count(cdf_size_t maxSize)
394{
395 return maxSize;
396}
397
398/**
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800399 * hif_save_htc_htt_config_endpoint():
400 * hif_save_htc_htt_config_endpoint
401 * @htc_endpoint: htc_endpoint
402 *
403 * Return: void
404 */
Komal Seelam644263d2016-02-22 20:45:49 +0530405void
406hif_save_htc_htt_config_endpoint(struct ol_softc *hif_ctx, int htc_endpoint)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800407{
Komal Seelam644263d2016-02-22 20:45:49 +0530408 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800409
410 if (!scn) {
411 HIF_ERROR("%s: error: scn or scn->hif_sc is NULL!",
412 __func__);
413 return;
414 }
415
416 scn->htc_endpoint = htc_endpoint;
417}
418
419/**
420 * hif_get_hw_name(): get a human readable name for the hardware
Komal Seelam91553ce2016-01-27 18:57:10 +0530421 * @info: Target Info
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800422 *
Komal Seelam91553ce2016-01-27 18:57:10 +0530423 * Return: human readable name for the underlying wifi hardware.
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800424 */
Komal Seelam91553ce2016-01-27 18:57:10 +0530425static const char *hif_get_hw_name(struct hif_target_info *info)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800426{
427 int i;
Komal Seelam91553ce2016-01-27 18:57:10 +0530428
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800429 for (i = 0; i < ARRAY_SIZE(qwlan_hw_list); i++) {
Komal Seelam91553ce2016-01-27 18:57:10 +0530430 if (info->target_version == qwlan_hw_list[i].id &&
431 info->target_revision == qwlan_hw_list[i].subid) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800432 return qwlan_hw_list[i].name;
433 }
434 }
435
436 return "Unknown Device";
437}
438
439/**
440 * hif_get_hw_info(): hif_get_hw_info
441 * @scn: scn
442 * @version: version
443 * @revision: revision
444 *
445 * Return: n/a
446 */
Komal Seelam91553ce2016-01-27 18:57:10 +0530447void hif_get_hw_info(struct ol_softc *scn, u32 *version, u32 *revision,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800448 const char **target_name)
449{
Komal Seelam91553ce2016-01-27 18:57:10 +0530450 struct hif_target_info *info = hif_get_target_info_handle(scn);
451 *version = info->target_version;
452 *revision = info->target_revision;
453 *target_name = hif_get_hw_name(info);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800454}
455
456/**
457 * hif_open(): hif_open
458 *
459 * Return: scn
460 */
Komal Seelamf8600682016-02-02 18:17:13 +0530461CDF_STATUS hif_open(cdf_device_t cdf_ctx, enum ath_hal_bus_type bus_type)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800462{
Komal Seelam644263d2016-02-22 20:45:49 +0530463 struct ol_softc *hif_hdl;
464 struct hif_softc *scn;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800465 v_CONTEXT_t cds_context;
466 CDF_STATUS status = CDF_STATUS_SUCCESS;
Komal Seelam43301de2016-02-02 18:20:48 +0530467 int bus_context_size = hif_bus_get_context_size();
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800468
469 cds_context = cds_get_global_context();
470 status = cds_alloc_context(cds_context, CDF_MODULE_ID_HIF,
Komal Seelam43301de2016-02-02 18:20:48 +0530471 (void **)&scn, bus_context_size);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800472 if (status != CDF_STATUS_SUCCESS) {
473 HIF_ERROR("%s: cannot alloc ol_sc", __func__);
474 return status;
475 }
476
Komal Seelam43301de2016-02-02 18:20:48 +0530477 cdf_mem_zero(scn, bus_context_size);
Komal Seelam644263d2016-02-22 20:45:49 +0530478 hif_hdl = GET_HIF_OPAQUE_HDL(scn);
Komal Seelamf8600682016-02-02 18:17:13 +0530479 scn->cdf_dev = cdf_ctx;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800480 cdf_atomic_init(&scn->active_tasklet_cnt);
481 cdf_atomic_init(&scn->link_suspended);
482 cdf_atomic_init(&scn->tasklet_from_intr);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800483 scn->linkstate_vote = 0;
Houston Hoffman3cfe6862016-01-08 10:33:55 -0800484
485 status = hif_bus_open(scn, bus_type);
486 if (status != CDF_STATUS_SUCCESS) {
487 HIF_ERROR("%s: hif_bus_open error = %d, bus_type = %d",
488 __func__, status, bus_type);
489 cds_free_context(cds_context, CDF_MODULE_ID_HIF, scn);
490 }
491
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800492 return status;
493}
494
495/**
496 * hif_close(): hif_close
497 * @hif_ctx: hif_ctx
498 *
499 * Return: n/a
500 */
Komal Seelam644263d2016-02-22 20:45:49 +0530501void hif_close(struct ol_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800502{
Komal Seelam644263d2016-02-22 20:45:49 +0530503 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800504
505 if (scn == NULL) {
506 HIF_ERROR("%s: ol_softc is NULL", __func__);
507 return;
508 }
509
510 if (scn->athdiag_procfs_inited) {
511 athdiag_procfs_remove();
512 scn->athdiag_procfs_inited = false;
513 }
514
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800515 hif_bus_close(scn);
516 cds_free_context(cds_get_global_context(),
517 CDF_MODULE_ID_HIF, hif_ctx);
518}
519
520/**
521 * hif_enable(): hif_enable
522 * @hif_ctx: hif_ctx
523 * @dev: dev
524 * @bdev: bus dev
525 * @bid: bus ID
526 * @bus_type: bus type
527 * @type: enable type
528 *
529 * Return: CDF_STATUS
530 */
Komal Seelam644263d2016-02-22 20:45:49 +0530531CDF_STATUS hif_enable(struct ol_softc *hif_ctx, struct device *dev,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800532 void *bdev, const hif_bus_id *bid,
533 enum ath_hal_bus_type bus_type,
534 enum hif_enable_type type)
535{
536 CDF_STATUS status;
Komal Seelam644263d2016-02-22 20:45:49 +0530537 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800538
539 if (scn == NULL) {
540 HIF_ERROR("%s: hif_ctx = NULL", __func__);
541 return CDF_STATUS_E_NULL_VALUE;
542 }
543
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800544 status = hif_enable_bus(scn, dev, bdev, bid, type);
545 if (status != CDF_STATUS_SUCCESS) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800546 HIF_ERROR("%s: hif_enable_bus error = %d",
547 __func__, status);
548 return status;
549 }
550
551 if (ADRASTEA_BU)
Komal Seelamf8600682016-02-02 18:17:13 +0530552 hif_vote_link_up(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800553
554 if (hif_config_ce(scn)) {
555 HIF_ERROR("%s: Target probe failed.", __func__);
Vishwajith Upendra3f78aa62016-02-09 17:53:02 +0530556 hif_disable_bus(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800557 status = CDF_STATUS_E_FAILURE;
558 return status;
559 }
560 /*
561 * Flag to avoid potential unallocated memory access from MSI
562 * interrupt handler which could get scheduled as soon as MSI
563 * is enabled, i.e to take care of the race due to the order
564 * in where MSI is enabled before the memory, that will be
565 * in interrupt handlers, is allocated.
566 */
567
568#ifdef HIF_PCI
Komal Seelam644263d2016-02-22 20:45:49 +0530569 status = hif_configure_irq(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800570 if (status < 0) {
571 HIF_ERROR("%s: ERROR - configure_IRQ_and_CE failed, status = %d",
572 __func__, status);
573 return CDF_STATUS_E_FAILURE;
574 }
575#endif
576
577 scn->hif_init_done = true;
578
579 HIF_TRACE("%s: X OK", __func__);
580
581 return CDF_STATUS_SUCCESS;
582}
583
584/**
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800585 * hif_wlan_disable(): call the platform driver to disable wlan
586 *
587 * This function passes the con_mode to platform driver to disable
588 * wlan.
589 *
590 * Return: void
591 */
592void hif_wlan_disable(void)
593{
594 enum icnss_driver_mode mode;
595 uint32_t con_mode = cds_get_conparam();
596
Peng Xu7b962532015-10-02 17:17:03 -0700597 if (CDF_GLOBAL_FTM_MODE == con_mode)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800598 mode = ICNSS_FTM;
Peng Xu7b962532015-10-02 17:17:03 -0700599 else if (WLAN_IS_EPPING_ENABLED(cds_get_conparam()))
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800600 mode = ICNSS_EPPING;
Peng Xu7b962532015-10-02 17:17:03 -0700601 else
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800602 mode = ICNSS_MISSION;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800603
604 icnss_wlan_disable(mode);
605}
606
Komal Seelam644263d2016-02-22 20:45:49 +0530607void hif_disable(struct ol_softc *hif_ctx, enum hif_disable_type type)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800608{
Komal Seelam644263d2016-02-22 20:45:49 +0530609 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800610
611 if (!scn)
612 return;
613
614 hif_nointrs(scn);
615 if (scn->hif_init_done == false)
Komal Seelam644263d2016-02-22 20:45:49 +0530616 hif_shut_down_device(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800617 else
Komal Seelam644263d2016-02-22 20:45:49 +0530618 hif_stop(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800619
620 if (ADRASTEA_BU)
Komal Seelamf8600682016-02-02 18:17:13 +0530621 hif_vote_link_down(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800622
Vishwajith Upendra3f78aa62016-02-09 17:53:02 +0530623 hif_disable_bus(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800624
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800625 hif_wlan_disable();
626
627 scn->notice_send = false;
628
629 HIF_INFO("%s: X", __func__);
630}
631
632
633/**
Govind Singh2443fb32016-01-13 17:44:48 +0530634 * hif_crash_shutdown_dump_bus_register() - dump bus registers
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800635 * @hif_ctx: hif_ctx
636 *
637 * Return: n/a
638 */
639#if defined(TARGET_RAMDUMP_AFTER_KERNEL_PANIC) \
640&& defined(HIF_PCI) && defined(DEBUG)
641
Govind Singh2443fb32016-01-13 17:44:48 +0530642static void hif_crash_shutdown_dump_bus_register(void *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800643{
644 struct ol_softc *scn = hif_ctx;
645
Govind Singh2443fb32016-01-13 17:44:48 +0530646 if (hif_check_soc_status(scn))
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800647 return;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800648
Govind Singh2443fb32016-01-13 17:44:48 +0530649 if (hif_dump_registers(scn))
650 HIF_ERROR("Failed to dump bus registers!");
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800651}
652
653/**
654 * hif_crash_shutdown(): hif_crash_shutdown
655 *
656 * This function is called by the platform driver to dump CE registers
657 *
658 * @hif_ctx: hif_ctx
659 *
660 * Return: n/a
661 */
Komal Seelam644263d2016-02-22 20:45:49 +0530662void hif_crash_shutdown(struct ol_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800663{
Komal Seelam644263d2016-02-22 20:45:49 +0530664 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Komal Seelam02cf2f82016-02-22 20:44:25 +0530665 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800666
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800667 if (!hif_state)
668 return;
669
670
671 if (OL_TRGET_STATUS_RESET == scn->target_status) {
672 HIF_INFO_MED("%s: Target is already asserted, ignore!",
673 __func__);
674 return;
675 }
676
Rajeev Kumare3b4b4b2016-01-19 15:23:52 -0800677 if (cds_is_load_or_unload_in_progress()) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800678 HIF_ERROR("%s: Load/unload is in progress, ignore!", __func__);
679 return;
680 }
681
Govind Singh2443fb32016-01-13 17:44:48 +0530682 hif_crash_shutdown_dump_bus_register(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800683
Komal Seelam644263d2016-02-22 20:45:49 +0530684 if (ol_copy_ramdump(hif_ctx))
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800685 goto out;
686
687 HIF_INFO_MED("%s: RAM dump collecting completed!", __func__);
688
689out:
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800690 return;
691}
692#else
Komal Seelam644263d2016-02-22 20:45:49 +0530693void hif_crash_shutdown(struct ol_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800694{
695 HIF_INFO_MED("%s: Collecting target RAM dump disabled",
696 __func__);
697 return;
698}
699#endif /* TARGET_RAMDUMP_AFTER_KERNEL_PANIC */
700
701#ifdef QCA_WIFI_3_0
702/**
703 * hif_check_fw_reg(): hif_check_fw_reg
704 * @scn: scn
705 * @state:
706 *
707 * Return: int
708 */
709int hif_check_fw_reg(struct ol_softc *scn)
710{
711 return 0;
712}
713#endif
714
715#ifdef IPA_OFFLOAD
716/**
717 * hif_read_phy_mem_base(): hif_read_phy_mem_base
718 * @scn: scn
719 * @phy_mem_base: physical mem base
720 *
721 * Return: n/a
722 */
Komal Seelam644263d2016-02-22 20:45:49 +0530723void hif_read_phy_mem_base(struct hif_softc *scn, cdf_dma_addr_t *phy_mem_base)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800724{
725 *phy_mem_base = scn->mem_pa;
726}
727#endif /* IPA_OFFLOAD */
728
729/**
730 * hif_get_device_type(): hif_get_device_type
731 * @device_id: device_id
732 * @revision_id: revision_id
733 * @hif_type: returned hif_type
734 * @target_type: returned target_type
735 *
736 * Return: int
737 */
738int hif_get_device_type(uint32_t device_id,
739 uint32_t revision_id,
740 uint32_t *hif_type, uint32_t *target_type)
741{
742 int ret = 0;
743
744 switch (device_id) {
745#ifdef QCA_WIFI_3_0_ADRASTEA
746 case ADRASTEA_DEVICE_ID:
747 case ADRASTEA_DEVICE_ID_P2_E12:
748
749 *hif_type = HIF_TYPE_ADRASTEA;
750 *target_type = TARGET_TYPE_ADRASTEA;
751 break;
752#else
753 case QCA6180_DEVICE_ID:
754 *hif_type = HIF_TYPE_QCA6180;
755 *target_type = TARGET_TYPE_QCA6180;
756 break;
757#endif
758
759 case AR9888_DEVICE_ID:
760 *hif_type = HIF_TYPE_AR9888;
761 *target_type = TARGET_TYPE_AR9888;
762 break;
763
764 case AR6320_DEVICE_ID:
765 switch (revision_id) {
766 case AR6320_FW_1_1:
767 case AR6320_FW_1_3:
768 *hif_type = HIF_TYPE_AR6320;
769 *target_type = TARGET_TYPE_AR6320;
770 break;
771
772 case AR6320_FW_2_0:
773 case AR6320_FW_3_0:
774 case AR6320_FW_3_2:
775 *hif_type = HIF_TYPE_AR6320V2;
776 *target_type = TARGET_TYPE_AR6320V2;
777 break;
778
779 default:
780 HIF_ERROR("%s: error - dev_id = 0x%x, rev_id = 0x%x",
781 __func__, device_id, revision_id);
782 ret = -ENODEV;
783 goto end;
784 }
785 break;
786
787 default:
788 HIF_ERROR("%s: Unsupported device ID!", __func__);
789 ret = -ENODEV;
790 break;
791 }
792end:
793 return ret;
794}
Komal Seelam91553ce2016-01-27 18:57:10 +0530795
796/**
797 * Target info and ini parameters are global to the driver
798 * Hence these structures are exposed to all the modules in
799 * the driver and they don't need to maintains multiple copies
800 * of the same info, instead get the handle from hif and
801 * modify them in hif
802 */
803
804/**
805 * hif_get_ini_handle() - API to get hif_config_param handle
Komal Seelam644263d2016-02-22 20:45:49 +0530806 * @hif_ctx: HIF Context
Komal Seelam91553ce2016-01-27 18:57:10 +0530807 *
808 * Return: pointer to hif_config_info
809 */
Komal Seelam644263d2016-02-22 20:45:49 +0530810struct hif_config_info *hif_get_ini_handle(struct ol_softc *hif_ctx)
Komal Seelam91553ce2016-01-27 18:57:10 +0530811{
Komal Seelam644263d2016-02-22 20:45:49 +0530812 struct hif_softc *sc = HIF_GET_SOFTC(hif_ctx);
813
814 return &sc->hif_config;
Komal Seelam91553ce2016-01-27 18:57:10 +0530815}
816
817/**
818 * hif_get_target_info_handle() - API to get hif_target_info handle
Komal Seelam644263d2016-02-22 20:45:49 +0530819 * @hif_ctx: HIF context
Komal Seelam91553ce2016-01-27 18:57:10 +0530820 *
821 * Return: Pointer to hif_target_info
822 */
Komal Seelam644263d2016-02-22 20:45:49 +0530823struct hif_target_info *hif_get_target_info_handle(struct ol_softc *hif_ctx)
Komal Seelam91553ce2016-01-27 18:57:10 +0530824{
Komal Seelam644263d2016-02-22 20:45:49 +0530825 struct hif_softc *sc = HIF_GET_SOFTC(hif_ctx);
826
827 return &sc->target_info;
828
Komal Seelam91553ce2016-01-27 18:57:10 +0530829}
Komal Seelamc92a0cf2016-02-22 20:43:52 +0530830
831#if defined(FEATURE_LRO)
832/**
833 * hif_lro_flush_cb_register - API to register for LRO Flush Callback
834 * @scn: HIF Context
835 * @handler: Function pointer to be called by HIF
836 * @data: Private data to be used by the module registering to HIF
837 *
838 * Return: void
839 */
840void hif_lro_flush_cb_register(struct ol_softc *scn,
841 void (handler)(void *), void *data)
842{
843 ce_lro_flush_cb_register(scn, handler, data);
844}
845
846/**
847 * hif_lro_flush_cb_deregister - API to deregister for LRO Flush Callbacks
848 * @scn: HIF Context
849 *
850 * Return: void
851 */
852void hif_lro_flush_cb_deregister(struct ol_softc *scn)
853{
854 ce_lro_flush_cb_deregister(scn);
855}
856#endif
Komal Seelam644263d2016-02-22 20:45:49 +0530857
858/**
859 * hif_get_target_status - API to get target status
860 * @hif_ctx: HIF Context
861 *
862 * Return: enum ol_target_status
863 */
864ol_target_status hif_get_target_status(struct ol_softc *hif_ctx)
865{
866 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
867
868 return scn->target_status;
869}
870
871/**
Komal Seelama5911d32016-02-24 19:21:59 +0530872 * hif_set_target_status() - API to set target status
Komal Seelam644263d2016-02-22 20:45:49 +0530873 * @hif_ctx: HIF Context
874 * @status: Target Status
875 *
876 * Return: void
877 */
878void hif_set_target_status(struct ol_softc *hif_ctx, ol_target_status status)
879{
880 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
881
882 scn->target_status = status;
883}
Komal Seelama5911d32016-02-24 19:21:59 +0530884
885/**
886 * hif_init_ini_config() - API to initialize HIF configuration parameters
887 * @hif_ctx: HIF Context
888 * @cfg: HIF Configuration
889 *
890 * Return: void
891 */
892void hif_init_ini_config(struct ol_softc *hif_ctx, struct hif_config_info *cfg)
893{
894 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
895
896 cdf_mem_copy(&scn->hif_config, cfg, sizeof(struct hif_config_info));
897}