blob: 47079aa6f7f25adf626cfff89c01a41ae43dc79b [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 Seelam91553ce2016-01-27 18:57:10 +0530467 struct hif_config_info *cfg;
Komal Seelam43301de2016-02-02 18:20:48 +0530468 int bus_context_size = hif_bus_get_context_size();
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800469
470 cds_context = cds_get_global_context();
471 status = cds_alloc_context(cds_context, CDF_MODULE_ID_HIF,
Komal Seelam43301de2016-02-02 18:20:48 +0530472 (void **)&scn, bus_context_size);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800473 if (status != CDF_STATUS_SUCCESS) {
474 HIF_ERROR("%s: cannot alloc ol_sc", __func__);
475 return status;
476 }
477
Komal Seelam43301de2016-02-02 18:20:48 +0530478 cdf_mem_zero(scn, bus_context_size);
Komal Seelam644263d2016-02-22 20:45:49 +0530479 hif_hdl = GET_HIF_OPAQUE_HDL(scn);
Komal Seelamf8600682016-02-02 18:17:13 +0530480 scn->cdf_dev = cdf_ctx;
Komal Seelam644263d2016-02-22 20:45:49 +0530481 cfg = hif_get_ini_handle(hif_hdl);
Komal Seelam91553ce2016-01-27 18:57:10 +0530482 cfg->max_no_of_peers = 1;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800483 cdf_atomic_init(&scn->active_tasklet_cnt);
484 cdf_atomic_init(&scn->link_suspended);
485 cdf_atomic_init(&scn->tasklet_from_intr);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800486 scn->linkstate_vote = 0;
Houston Hoffman3cfe6862016-01-08 10:33:55 -0800487
488 status = hif_bus_open(scn, bus_type);
489 if (status != CDF_STATUS_SUCCESS) {
490 HIF_ERROR("%s: hif_bus_open error = %d, bus_type = %d",
491 __func__, status, bus_type);
492 cds_free_context(cds_context, CDF_MODULE_ID_HIF, scn);
493 }
494
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800495 return status;
496}
497
498/**
499 * hif_close(): hif_close
500 * @hif_ctx: hif_ctx
501 *
502 * Return: n/a
503 */
Komal Seelam644263d2016-02-22 20:45:49 +0530504void hif_close(struct ol_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800505{
Komal Seelam644263d2016-02-22 20:45:49 +0530506 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800507
508 if (scn == NULL) {
509 HIF_ERROR("%s: ol_softc is NULL", __func__);
510 return;
511 }
512
513 if (scn->athdiag_procfs_inited) {
514 athdiag_procfs_remove();
515 scn->athdiag_procfs_inited = false;
516 }
517
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800518 hif_bus_close(scn);
519 cds_free_context(cds_get_global_context(),
520 CDF_MODULE_ID_HIF, hif_ctx);
521}
522
Komal Seelam644263d2016-02-22 20:45:49 +0530523void hif_init_opaque_handle(struct hif_softc *scn)
524{
525 struct ol_softc *hif_hdl = GET_HIF_OPAQUE_HDL(scn);
526
Komal Seelam644263d2016-02-22 20:45:49 +0530527 hif_hdl->targetdef = scn->targetdef;
528}
529
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800530/**
531 * hif_enable(): hif_enable
532 * @hif_ctx: hif_ctx
533 * @dev: dev
534 * @bdev: bus dev
535 * @bid: bus ID
536 * @bus_type: bus type
537 * @type: enable type
538 *
539 * Return: CDF_STATUS
540 */
Komal Seelam644263d2016-02-22 20:45:49 +0530541CDF_STATUS hif_enable(struct ol_softc *hif_ctx, struct device *dev,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800542 void *bdev, const hif_bus_id *bid,
543 enum ath_hal_bus_type bus_type,
544 enum hif_enable_type type)
545{
546 CDF_STATUS status;
Komal Seelam644263d2016-02-22 20:45:49 +0530547 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800548
549 if (scn == NULL) {
550 HIF_ERROR("%s: hif_ctx = NULL", __func__);
551 return CDF_STATUS_E_NULL_VALUE;
552 }
553
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800554 status = hif_enable_bus(scn, dev, bdev, bid, type);
555 if (status != CDF_STATUS_SUCCESS) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800556 HIF_ERROR("%s: hif_enable_bus error = %d",
557 __func__, status);
558 return status;
559 }
560
Komal Seelam644263d2016-02-22 20:45:49 +0530561 hif_init_opaque_handle(scn);
562
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800563 if (ADRASTEA_BU)
Komal Seelamf8600682016-02-02 18:17:13 +0530564 hif_vote_link_up(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800565
566 if (hif_config_ce(scn)) {
567 HIF_ERROR("%s: Target probe failed.", __func__);
Vishwajith Upendra3f78aa62016-02-09 17:53:02 +0530568 hif_disable_bus(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800569 status = CDF_STATUS_E_FAILURE;
570 return status;
571 }
572 /*
573 * Flag to avoid potential unallocated memory access from MSI
574 * interrupt handler which could get scheduled as soon as MSI
575 * is enabled, i.e to take care of the race due to the order
576 * in where MSI is enabled before the memory, that will be
577 * in interrupt handlers, is allocated.
578 */
579
580#ifdef HIF_PCI
Komal Seelam644263d2016-02-22 20:45:49 +0530581 status = hif_configure_irq(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800582 if (status < 0) {
583 HIF_ERROR("%s: ERROR - configure_IRQ_and_CE failed, status = %d",
584 __func__, status);
585 return CDF_STATUS_E_FAILURE;
586 }
587#endif
588
589 scn->hif_init_done = true;
590
591 HIF_TRACE("%s: X OK", __func__);
592
593 return CDF_STATUS_SUCCESS;
594}
595
596/**
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800597 * hif_wlan_disable(): call the platform driver to disable wlan
598 *
599 * This function passes the con_mode to platform driver to disable
600 * wlan.
601 *
602 * Return: void
603 */
604void hif_wlan_disable(void)
605{
606 enum icnss_driver_mode mode;
607 uint32_t con_mode = cds_get_conparam();
608
Peng Xu7b962532015-10-02 17:17:03 -0700609 if (CDF_GLOBAL_FTM_MODE == con_mode)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800610 mode = ICNSS_FTM;
Peng Xu7b962532015-10-02 17:17:03 -0700611 else if (WLAN_IS_EPPING_ENABLED(cds_get_conparam()))
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800612 mode = ICNSS_EPPING;
Peng Xu7b962532015-10-02 17:17:03 -0700613 else
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800614 mode = ICNSS_MISSION;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800615
616 icnss_wlan_disable(mode);
617}
618
Komal Seelam644263d2016-02-22 20:45:49 +0530619void hif_disable(struct ol_softc *hif_ctx, enum hif_disable_type type)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800620{
Komal Seelam644263d2016-02-22 20:45:49 +0530621 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800622
623 if (!scn)
624 return;
625
626 hif_nointrs(scn);
627 if (scn->hif_init_done == false)
Komal Seelam644263d2016-02-22 20:45:49 +0530628 hif_shut_down_device(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800629 else
Komal Seelam644263d2016-02-22 20:45:49 +0530630 hif_stop(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800631
632 if (ADRASTEA_BU)
Komal Seelamf8600682016-02-02 18:17:13 +0530633 hif_vote_link_down(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800634
Vishwajith Upendra3f78aa62016-02-09 17:53:02 +0530635 hif_disable_bus(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800636
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800637 hif_wlan_disable();
638
639 scn->notice_send = false;
640
641 HIF_INFO("%s: X", __func__);
642}
643
644
645/**
Govind Singh2443fb32016-01-13 17:44:48 +0530646 * hif_crash_shutdown_dump_bus_register() - dump bus registers
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800647 * @hif_ctx: hif_ctx
648 *
649 * Return: n/a
650 */
651#if defined(TARGET_RAMDUMP_AFTER_KERNEL_PANIC) \
652&& defined(HIF_PCI) && defined(DEBUG)
653
Govind Singh2443fb32016-01-13 17:44:48 +0530654static void hif_crash_shutdown_dump_bus_register(void *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800655{
656 struct ol_softc *scn = hif_ctx;
657
Govind Singh2443fb32016-01-13 17:44:48 +0530658 if (hif_check_soc_status(scn))
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800659 return;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800660
Govind Singh2443fb32016-01-13 17:44:48 +0530661 if (hif_dump_registers(scn))
662 HIF_ERROR("Failed to dump bus registers!");
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800663}
664
665/**
666 * hif_crash_shutdown(): hif_crash_shutdown
667 *
668 * This function is called by the platform driver to dump CE registers
669 *
670 * @hif_ctx: hif_ctx
671 *
672 * Return: n/a
673 */
Komal Seelam644263d2016-02-22 20:45:49 +0530674void hif_crash_shutdown(struct ol_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800675{
Komal Seelam644263d2016-02-22 20:45:49 +0530676 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Komal Seelam02cf2f82016-02-22 20:44:25 +0530677 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800678
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800679 if (!hif_state)
680 return;
681
682
683 if (OL_TRGET_STATUS_RESET == scn->target_status) {
684 HIF_INFO_MED("%s: Target is already asserted, ignore!",
685 __func__);
686 return;
687 }
688
Rajeev Kumare3b4b4b2016-01-19 15:23:52 -0800689 if (cds_is_load_or_unload_in_progress()) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800690 HIF_ERROR("%s: Load/unload is in progress, ignore!", __func__);
691 return;
692 }
693
Govind Singh2443fb32016-01-13 17:44:48 +0530694 hif_crash_shutdown_dump_bus_register(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800695
Komal Seelam644263d2016-02-22 20:45:49 +0530696 if (ol_copy_ramdump(hif_ctx))
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800697 goto out;
698
699 HIF_INFO_MED("%s: RAM dump collecting completed!", __func__);
700
701out:
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800702 return;
703}
704#else
Komal Seelam644263d2016-02-22 20:45:49 +0530705void hif_crash_shutdown(struct ol_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800706{
707 HIF_INFO_MED("%s: Collecting target RAM dump disabled",
708 __func__);
709 return;
710}
711#endif /* TARGET_RAMDUMP_AFTER_KERNEL_PANIC */
712
713#ifdef QCA_WIFI_3_0
714/**
715 * hif_check_fw_reg(): hif_check_fw_reg
716 * @scn: scn
717 * @state:
718 *
719 * Return: int
720 */
721int hif_check_fw_reg(struct ol_softc *scn)
722{
723 return 0;
724}
725#endif
726
727#ifdef IPA_OFFLOAD
728/**
729 * hif_read_phy_mem_base(): hif_read_phy_mem_base
730 * @scn: scn
731 * @phy_mem_base: physical mem base
732 *
733 * Return: n/a
734 */
Komal Seelam644263d2016-02-22 20:45:49 +0530735void hif_read_phy_mem_base(struct hif_softc *scn, cdf_dma_addr_t *phy_mem_base)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800736{
737 *phy_mem_base = scn->mem_pa;
738}
739#endif /* IPA_OFFLOAD */
740
741/**
742 * hif_get_device_type(): hif_get_device_type
743 * @device_id: device_id
744 * @revision_id: revision_id
745 * @hif_type: returned hif_type
746 * @target_type: returned target_type
747 *
748 * Return: int
749 */
750int hif_get_device_type(uint32_t device_id,
751 uint32_t revision_id,
752 uint32_t *hif_type, uint32_t *target_type)
753{
754 int ret = 0;
755
756 switch (device_id) {
757#ifdef QCA_WIFI_3_0_ADRASTEA
758 case ADRASTEA_DEVICE_ID:
759 case ADRASTEA_DEVICE_ID_P2_E12:
760
761 *hif_type = HIF_TYPE_ADRASTEA;
762 *target_type = TARGET_TYPE_ADRASTEA;
763 break;
764#else
765 case QCA6180_DEVICE_ID:
766 *hif_type = HIF_TYPE_QCA6180;
767 *target_type = TARGET_TYPE_QCA6180;
768 break;
769#endif
770
771 case AR9888_DEVICE_ID:
772 *hif_type = HIF_TYPE_AR9888;
773 *target_type = TARGET_TYPE_AR9888;
774 break;
775
776 case AR6320_DEVICE_ID:
777 switch (revision_id) {
778 case AR6320_FW_1_1:
779 case AR6320_FW_1_3:
780 *hif_type = HIF_TYPE_AR6320;
781 *target_type = TARGET_TYPE_AR6320;
782 break;
783
784 case AR6320_FW_2_0:
785 case AR6320_FW_3_0:
786 case AR6320_FW_3_2:
787 *hif_type = HIF_TYPE_AR6320V2;
788 *target_type = TARGET_TYPE_AR6320V2;
789 break;
790
791 default:
792 HIF_ERROR("%s: error - dev_id = 0x%x, rev_id = 0x%x",
793 __func__, device_id, revision_id);
794 ret = -ENODEV;
795 goto end;
796 }
797 break;
798
799 default:
800 HIF_ERROR("%s: Unsupported device ID!", __func__);
801 ret = -ENODEV;
802 break;
803 }
804end:
805 return ret;
806}
Komal Seelam91553ce2016-01-27 18:57:10 +0530807
808/**
809 * Target info and ini parameters are global to the driver
810 * Hence these structures are exposed to all the modules in
811 * the driver and they don't need to maintains multiple copies
812 * of the same info, instead get the handle from hif and
813 * modify them in hif
814 */
815
816/**
817 * hif_get_ini_handle() - API to get hif_config_param handle
Komal Seelam644263d2016-02-22 20:45:49 +0530818 * @hif_ctx: HIF Context
Komal Seelam91553ce2016-01-27 18:57:10 +0530819 *
820 * Return: pointer to hif_config_info
821 */
Komal Seelam644263d2016-02-22 20:45:49 +0530822struct hif_config_info *hif_get_ini_handle(struct ol_softc *hif_ctx)
Komal Seelam91553ce2016-01-27 18:57:10 +0530823{
Komal Seelam644263d2016-02-22 20:45:49 +0530824 struct hif_softc *sc = HIF_GET_SOFTC(hif_ctx);
825
826 return &sc->hif_config;
Komal Seelam91553ce2016-01-27 18:57:10 +0530827}
828
829/**
830 * hif_get_target_info_handle() - API to get hif_target_info handle
Komal Seelam644263d2016-02-22 20:45:49 +0530831 * @hif_ctx: HIF context
Komal Seelam91553ce2016-01-27 18:57:10 +0530832 *
833 * Return: Pointer to hif_target_info
834 */
Komal Seelam644263d2016-02-22 20:45:49 +0530835struct hif_target_info *hif_get_target_info_handle(struct ol_softc *hif_ctx)
Komal Seelam91553ce2016-01-27 18:57:10 +0530836{
Komal Seelam644263d2016-02-22 20:45:49 +0530837 struct hif_softc *sc = HIF_GET_SOFTC(hif_ctx);
838
839 return &sc->target_info;
840
Komal Seelam91553ce2016-01-27 18:57:10 +0530841}
Komal Seelamc92a0cf2016-02-22 20:43:52 +0530842
843#if defined(FEATURE_LRO)
844/**
845 * hif_lro_flush_cb_register - API to register for LRO Flush Callback
846 * @scn: HIF Context
847 * @handler: Function pointer to be called by HIF
848 * @data: Private data to be used by the module registering to HIF
849 *
850 * Return: void
851 */
852void hif_lro_flush_cb_register(struct ol_softc *scn,
853 void (handler)(void *), void *data)
854{
855 ce_lro_flush_cb_register(scn, handler, data);
856}
857
858/**
859 * hif_lro_flush_cb_deregister - API to deregister for LRO Flush Callbacks
860 * @scn: HIF Context
861 *
862 * Return: void
863 */
864void hif_lro_flush_cb_deregister(struct ol_softc *scn)
865{
866 ce_lro_flush_cb_deregister(scn);
867}
868#endif
Komal Seelam644263d2016-02-22 20:45:49 +0530869
870/**
871 * hif_get_target_status - API to get target status
872 * @hif_ctx: HIF Context
873 *
874 * Return: enum ol_target_status
875 */
876ol_target_status hif_get_target_status(struct ol_softc *hif_ctx)
877{
878 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
879
880 return scn->target_status;
881}
882
883/**
884 * hif_set_target_status - API to set target status
885 * @hif_ctx: HIF Context
886 * @status: Target Status
887 *
888 * Return: void
889 */
890void hif_set_target_status(struct ol_softc *hif_ctx, ol_target_status status)
891{
892 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
893
894 scn->target_status = status;
895}