blob: cc3cfb741286bd43f06b95b4848ca127b907cbb6 [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/**
399 * hif_init_cdf_ctx(): hif_init_cdf_ctx
400 * @hif_ctx: hif_ctx
401 *
402 * Return: int
403 */
Komal Seelam644263d2016-02-22 20:45:49 +0530404int hif_init_cdf_ctx(struct hif_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800405{
Komal Seelamf8600682016-02-02 18:17:13 +0530406 cdf_device_t cdf_ctx = scn->cdf_dev;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800407
408 cdf_ctx->drv = &scn->aps_osdev;
409 cdf_ctx->drv_hdl = scn->aps_osdev.bdev;
410 cdf_ctx->dev = scn->aps_osdev.device;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800411 return 0;
412}
413
414/**
415 * hif_deinit_cdf_ctx(): hif_deinit_cdf_ctx
416 * @hif_ctx: hif_ctx
417 *
418 * Return: void
419 */
Komal Seelam644263d2016-02-22 20:45:49 +0530420void hif_deinit_cdf_ctx(struct hif_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800421{
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800422 if (scn == NULL || !scn->cdf_dev)
423 return;
424 scn->cdf_dev = NULL;
425}
426
427/**
428 * hif_save_htc_htt_config_endpoint():
429 * hif_save_htc_htt_config_endpoint
430 * @htc_endpoint: htc_endpoint
431 *
432 * Return: void
433 */
Komal Seelam644263d2016-02-22 20:45:49 +0530434void
435hif_save_htc_htt_config_endpoint(struct ol_softc *hif_ctx, int htc_endpoint)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800436{
Komal Seelam644263d2016-02-22 20:45:49 +0530437 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800438
439 if (!scn) {
440 HIF_ERROR("%s: error: scn or scn->hif_sc is NULL!",
441 __func__);
442 return;
443 }
444
445 scn->htc_endpoint = htc_endpoint;
446}
447
448/**
449 * hif_get_hw_name(): get a human readable name for the hardware
Komal Seelam91553ce2016-01-27 18:57:10 +0530450 * @info: Target Info
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800451 *
Komal Seelam91553ce2016-01-27 18:57:10 +0530452 * Return: human readable name for the underlying wifi hardware.
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800453 */
Komal Seelam91553ce2016-01-27 18:57:10 +0530454static const char *hif_get_hw_name(struct hif_target_info *info)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800455{
456 int i;
Komal Seelam91553ce2016-01-27 18:57:10 +0530457
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800458 for (i = 0; i < ARRAY_SIZE(qwlan_hw_list); i++) {
Komal Seelam91553ce2016-01-27 18:57:10 +0530459 if (info->target_version == qwlan_hw_list[i].id &&
460 info->target_revision == qwlan_hw_list[i].subid) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800461 return qwlan_hw_list[i].name;
462 }
463 }
464
465 return "Unknown Device";
466}
467
468/**
469 * hif_get_hw_info(): hif_get_hw_info
470 * @scn: scn
471 * @version: version
472 * @revision: revision
473 *
474 * Return: n/a
475 */
Komal Seelam91553ce2016-01-27 18:57:10 +0530476void hif_get_hw_info(struct ol_softc *scn, u32 *version, u32 *revision,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800477 const char **target_name)
478{
Komal Seelam91553ce2016-01-27 18:57:10 +0530479 struct hif_target_info *info = hif_get_target_info_handle(scn);
480 *version = info->target_version;
481 *revision = info->target_revision;
482 *target_name = hif_get_hw_name(info);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800483}
484
485/**
486 * hif_open(): hif_open
487 *
488 * Return: scn
489 */
Komal Seelamf8600682016-02-02 18:17:13 +0530490CDF_STATUS hif_open(cdf_device_t cdf_ctx, enum ath_hal_bus_type bus_type)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800491{
Komal Seelam644263d2016-02-22 20:45:49 +0530492 struct ol_softc *hif_hdl;
493 struct hif_softc *scn;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800494 v_CONTEXT_t cds_context;
495 CDF_STATUS status = CDF_STATUS_SUCCESS;
Komal Seelam91553ce2016-01-27 18:57:10 +0530496 struct hif_config_info *cfg;
Komal Seelam43301de2016-02-02 18:20:48 +0530497 int bus_context_size = hif_bus_get_context_size();
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800498
499 cds_context = cds_get_global_context();
500 status = cds_alloc_context(cds_context, CDF_MODULE_ID_HIF,
Komal Seelam43301de2016-02-02 18:20:48 +0530501 (void **)&scn, bus_context_size);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800502 if (status != CDF_STATUS_SUCCESS) {
503 HIF_ERROR("%s: cannot alloc ol_sc", __func__);
504 return status;
505 }
506
Komal Seelam43301de2016-02-02 18:20:48 +0530507 cdf_mem_zero(scn, bus_context_size);
Komal Seelam644263d2016-02-22 20:45:49 +0530508 hif_hdl = GET_HIF_OPAQUE_HDL(scn);
Komal Seelamf8600682016-02-02 18:17:13 +0530509 scn->cdf_dev = cdf_ctx;
Komal Seelam644263d2016-02-22 20:45:49 +0530510 hif_hdl->cdf_dev = cdf_ctx;
511 cfg = hif_get_ini_handle(hif_hdl);
Komal Seelam91553ce2016-01-27 18:57:10 +0530512 cfg->max_no_of_peers = 1;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800513 cdf_atomic_init(&scn->active_tasklet_cnt);
514 cdf_atomic_init(&scn->link_suspended);
515 cdf_atomic_init(&scn->tasklet_from_intr);
516 init_waitqueue_head(&scn->aps_osdev.event_queue);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800517 scn->linkstate_vote = 0;
Houston Hoffman3cfe6862016-01-08 10:33:55 -0800518
519 status = hif_bus_open(scn, bus_type);
520 if (status != CDF_STATUS_SUCCESS) {
521 HIF_ERROR("%s: hif_bus_open error = %d, bus_type = %d",
522 __func__, status, bus_type);
523 cds_free_context(cds_context, CDF_MODULE_ID_HIF, scn);
524 }
525
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800526 return status;
527}
528
529/**
530 * hif_close(): hif_close
531 * @hif_ctx: hif_ctx
532 *
533 * Return: n/a
534 */
Komal Seelam644263d2016-02-22 20:45:49 +0530535void hif_close(struct ol_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800536{
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: ol_softc is NULL", __func__);
541 return;
542 }
543
544 if (scn->athdiag_procfs_inited) {
545 athdiag_procfs_remove();
546 scn->athdiag_procfs_inited = false;
547 }
548
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800549 hif_bus_close(scn);
550 cds_free_context(cds_get_global_context(),
551 CDF_MODULE_ID_HIF, hif_ctx);
552}
553
Komal Seelam644263d2016-02-22 20:45:49 +0530554void hif_init_opaque_handle(struct hif_softc *scn)
555{
556 struct ol_softc *hif_hdl = GET_HIF_OPAQUE_HDL(scn);
557
558 cdf_mem_copy(&hif_hdl->aps_osdev, &scn->aps_osdev,
559 sizeof(hif_hdl->aps_osdev));
560 hif_hdl->cdf_dev = scn->cdf_dev;
561 hif_hdl->targetdef = scn->targetdef;
562}
563
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800564/**
565 * hif_enable(): hif_enable
566 * @hif_ctx: hif_ctx
567 * @dev: dev
568 * @bdev: bus dev
569 * @bid: bus ID
570 * @bus_type: bus type
571 * @type: enable type
572 *
573 * Return: CDF_STATUS
574 */
Komal Seelam644263d2016-02-22 20:45:49 +0530575CDF_STATUS hif_enable(struct ol_softc *hif_ctx, struct device *dev,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800576 void *bdev, const hif_bus_id *bid,
577 enum ath_hal_bus_type bus_type,
578 enum hif_enable_type type)
579{
580 CDF_STATUS status;
Komal Seelam644263d2016-02-22 20:45:49 +0530581 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800582
583 if (scn == NULL) {
584 HIF_ERROR("%s: hif_ctx = NULL", __func__);
585 return CDF_STATUS_E_NULL_VALUE;
586 }
587
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800588 status = hif_enable_bus(scn, dev, bdev, bid, type);
589 if (status != CDF_STATUS_SUCCESS) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800590 HIF_ERROR("%s: hif_enable_bus error = %d",
591 __func__, status);
592 return status;
593 }
594
Komal Seelam644263d2016-02-22 20:45:49 +0530595 hif_init_opaque_handle(scn);
596
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800597 if (ADRASTEA_BU)
Komal Seelamf8600682016-02-02 18:17:13 +0530598 hif_vote_link_up(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800599
600 if (hif_config_ce(scn)) {
601 HIF_ERROR("%s: Target probe failed.", __func__);
602 hif_disable_bus(scn->aps_osdev.bdev);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800603 status = CDF_STATUS_E_FAILURE;
604 return status;
605 }
606 /*
607 * Flag to avoid potential unallocated memory access from MSI
608 * interrupt handler which could get scheduled as soon as MSI
609 * is enabled, i.e to take care of the race due to the order
610 * in where MSI is enabled before the memory, that will be
611 * in interrupt handlers, is allocated.
612 */
613
614#ifdef HIF_PCI
Komal Seelam644263d2016-02-22 20:45:49 +0530615 status = hif_configure_irq(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800616 if (status < 0) {
617 HIF_ERROR("%s: ERROR - configure_IRQ_and_CE failed, status = %d",
618 __func__, status);
619 return CDF_STATUS_E_FAILURE;
620 }
621#endif
622
623 scn->hif_init_done = true;
624
625 HIF_TRACE("%s: X OK", __func__);
626
627 return CDF_STATUS_SUCCESS;
628}
629
630/**
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800631 * hif_wlan_disable(): call the platform driver to disable wlan
632 *
633 * This function passes the con_mode to platform driver to disable
634 * wlan.
635 *
636 * Return: void
637 */
638void hif_wlan_disable(void)
639{
640 enum icnss_driver_mode mode;
641 uint32_t con_mode = cds_get_conparam();
642
Peng Xu7b962532015-10-02 17:17:03 -0700643 if (CDF_GLOBAL_FTM_MODE == con_mode)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800644 mode = ICNSS_FTM;
Peng Xu7b962532015-10-02 17:17:03 -0700645 else if (WLAN_IS_EPPING_ENABLED(cds_get_conparam()))
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800646 mode = ICNSS_EPPING;
Peng Xu7b962532015-10-02 17:17:03 -0700647 else
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800648 mode = ICNSS_MISSION;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800649
650 icnss_wlan_disable(mode);
651}
652
Komal Seelam644263d2016-02-22 20:45:49 +0530653void hif_disable(struct ol_softc *hif_ctx, enum hif_disable_type type)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800654{
Komal Seelam644263d2016-02-22 20:45:49 +0530655 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800656
657 if (!scn)
658 return;
659
660 hif_nointrs(scn);
661 if (scn->hif_init_done == false)
Komal Seelam644263d2016-02-22 20:45:49 +0530662 hif_shut_down_device(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800663 else
Komal Seelam644263d2016-02-22 20:45:49 +0530664 hif_stop(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800665
666 if (ADRASTEA_BU)
Komal Seelamf8600682016-02-02 18:17:13 +0530667 hif_vote_link_down(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800668
669 if (scn->aps_osdev.bdev)
670 hif_disable_bus(scn->aps_osdev.bdev);
671
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800672 hif_wlan_disable();
673
674 scn->notice_send = false;
675
676 HIF_INFO("%s: X", __func__);
677}
678
679
680/**
Govind Singh2443fb32016-01-13 17:44:48 +0530681 * hif_crash_shutdown_dump_bus_register() - dump bus registers
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800682 * @hif_ctx: hif_ctx
683 *
684 * Return: n/a
685 */
686#if defined(TARGET_RAMDUMP_AFTER_KERNEL_PANIC) \
687&& defined(HIF_PCI) && defined(DEBUG)
688
Govind Singh2443fb32016-01-13 17:44:48 +0530689static void hif_crash_shutdown_dump_bus_register(void *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800690{
691 struct ol_softc *scn = hif_ctx;
692
Govind Singh2443fb32016-01-13 17:44:48 +0530693 if (hif_check_soc_status(scn))
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800694 return;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800695
Govind Singh2443fb32016-01-13 17:44:48 +0530696 if (hif_dump_registers(scn))
697 HIF_ERROR("Failed to dump bus registers!");
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800698}
699
700/**
701 * hif_crash_shutdown(): hif_crash_shutdown
702 *
703 * This function is called by the platform driver to dump CE registers
704 *
705 * @hif_ctx: hif_ctx
706 *
707 * Return: n/a
708 */
Komal Seelam644263d2016-02-22 20:45:49 +0530709void hif_crash_shutdown(struct ol_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800710{
Komal Seelam644263d2016-02-22 20:45:49 +0530711 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Komal Seelam02cf2f82016-02-22 20:44:25 +0530712 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800713
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800714 if (!hif_state)
715 return;
716
717
718 if (OL_TRGET_STATUS_RESET == scn->target_status) {
719 HIF_INFO_MED("%s: Target is already asserted, ignore!",
720 __func__);
721 return;
722 }
723
Rajeev Kumare3b4b4b2016-01-19 15:23:52 -0800724 if (cds_is_load_or_unload_in_progress()) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800725 HIF_ERROR("%s: Load/unload is in progress, ignore!", __func__);
726 return;
727 }
728
Govind Singh2443fb32016-01-13 17:44:48 +0530729 hif_crash_shutdown_dump_bus_register(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800730
Komal Seelam644263d2016-02-22 20:45:49 +0530731 if (ol_copy_ramdump(hif_ctx))
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800732 goto out;
733
734 HIF_INFO_MED("%s: RAM dump collecting completed!", __func__);
735
736out:
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800737 return;
738}
739#else
Komal Seelam644263d2016-02-22 20:45:49 +0530740void hif_crash_shutdown(struct ol_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800741{
742 HIF_INFO_MED("%s: Collecting target RAM dump disabled",
743 __func__);
744 return;
745}
746#endif /* TARGET_RAMDUMP_AFTER_KERNEL_PANIC */
747
748#ifdef QCA_WIFI_3_0
749/**
750 * hif_check_fw_reg(): hif_check_fw_reg
751 * @scn: scn
752 * @state:
753 *
754 * Return: int
755 */
756int hif_check_fw_reg(struct ol_softc *scn)
757{
758 return 0;
759}
760#endif
761
762#ifdef IPA_OFFLOAD
763/**
764 * hif_read_phy_mem_base(): hif_read_phy_mem_base
765 * @scn: scn
766 * @phy_mem_base: physical mem base
767 *
768 * Return: n/a
769 */
Komal Seelam644263d2016-02-22 20:45:49 +0530770void hif_read_phy_mem_base(struct hif_softc *scn, cdf_dma_addr_t *phy_mem_base)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800771{
772 *phy_mem_base = scn->mem_pa;
773}
774#endif /* IPA_OFFLOAD */
775
776/**
777 * hif_get_device_type(): hif_get_device_type
778 * @device_id: device_id
779 * @revision_id: revision_id
780 * @hif_type: returned hif_type
781 * @target_type: returned target_type
782 *
783 * Return: int
784 */
785int hif_get_device_type(uint32_t device_id,
786 uint32_t revision_id,
787 uint32_t *hif_type, uint32_t *target_type)
788{
789 int ret = 0;
790
791 switch (device_id) {
792#ifdef QCA_WIFI_3_0_ADRASTEA
793 case ADRASTEA_DEVICE_ID:
794 case ADRASTEA_DEVICE_ID_P2_E12:
795
796 *hif_type = HIF_TYPE_ADRASTEA;
797 *target_type = TARGET_TYPE_ADRASTEA;
798 break;
799#else
800 case QCA6180_DEVICE_ID:
801 *hif_type = HIF_TYPE_QCA6180;
802 *target_type = TARGET_TYPE_QCA6180;
803 break;
804#endif
805
806 case AR9888_DEVICE_ID:
807 *hif_type = HIF_TYPE_AR9888;
808 *target_type = TARGET_TYPE_AR9888;
809 break;
810
811 case AR6320_DEVICE_ID:
812 switch (revision_id) {
813 case AR6320_FW_1_1:
814 case AR6320_FW_1_3:
815 *hif_type = HIF_TYPE_AR6320;
816 *target_type = TARGET_TYPE_AR6320;
817 break;
818
819 case AR6320_FW_2_0:
820 case AR6320_FW_3_0:
821 case AR6320_FW_3_2:
822 *hif_type = HIF_TYPE_AR6320V2;
823 *target_type = TARGET_TYPE_AR6320V2;
824 break;
825
826 default:
827 HIF_ERROR("%s: error - dev_id = 0x%x, rev_id = 0x%x",
828 __func__, device_id, revision_id);
829 ret = -ENODEV;
830 goto end;
831 }
832 break;
833
834 default:
835 HIF_ERROR("%s: Unsupported device ID!", __func__);
836 ret = -ENODEV;
837 break;
838 }
839end:
840 return ret;
841}
Komal Seelam91553ce2016-01-27 18:57:10 +0530842
843/**
844 * Target info and ini parameters are global to the driver
845 * Hence these structures are exposed to all the modules in
846 * the driver and they don't need to maintains multiple copies
847 * of the same info, instead get the handle from hif and
848 * modify them in hif
849 */
850
851/**
852 * hif_get_ini_handle() - API to get hif_config_param handle
Komal Seelam644263d2016-02-22 20:45:49 +0530853 * @hif_ctx: HIF Context
Komal Seelam91553ce2016-01-27 18:57:10 +0530854 *
855 * Return: pointer to hif_config_info
856 */
Komal Seelam644263d2016-02-22 20:45:49 +0530857struct hif_config_info *hif_get_ini_handle(struct ol_softc *hif_ctx)
Komal Seelam91553ce2016-01-27 18:57:10 +0530858{
Komal Seelam644263d2016-02-22 20:45:49 +0530859 struct hif_softc *sc = HIF_GET_SOFTC(hif_ctx);
860
861 return &sc->hif_config;
Komal Seelam91553ce2016-01-27 18:57:10 +0530862}
863
864/**
865 * hif_get_target_info_handle() - API to get hif_target_info handle
Komal Seelam644263d2016-02-22 20:45:49 +0530866 * @hif_ctx: HIF context
Komal Seelam91553ce2016-01-27 18:57:10 +0530867 *
868 * Return: Pointer to hif_target_info
869 */
Komal Seelam644263d2016-02-22 20:45:49 +0530870struct hif_target_info *hif_get_target_info_handle(struct ol_softc *hif_ctx)
Komal Seelam91553ce2016-01-27 18:57:10 +0530871{
Komal Seelam644263d2016-02-22 20:45:49 +0530872 struct hif_softc *sc = HIF_GET_SOFTC(hif_ctx);
873
874 return &sc->target_info;
875
Komal Seelam91553ce2016-01-27 18:57:10 +0530876}
Komal Seelamc92a0cf2016-02-22 20:43:52 +0530877
878#if defined(FEATURE_LRO)
879/**
880 * hif_lro_flush_cb_register - API to register for LRO Flush Callback
881 * @scn: HIF Context
882 * @handler: Function pointer to be called by HIF
883 * @data: Private data to be used by the module registering to HIF
884 *
885 * Return: void
886 */
887void hif_lro_flush_cb_register(struct ol_softc *scn,
888 void (handler)(void *), void *data)
889{
890 ce_lro_flush_cb_register(scn, handler, data);
891}
892
893/**
894 * hif_lro_flush_cb_deregister - API to deregister for LRO Flush Callbacks
895 * @scn: HIF Context
896 *
897 * Return: void
898 */
899void hif_lro_flush_cb_deregister(struct ol_softc *scn)
900{
901 ce_lro_flush_cb_deregister(scn);
902}
903#endif
Komal Seelam644263d2016-02-22 20:45:49 +0530904
905/**
906 * hif_get_target_status - API to get target status
907 * @hif_ctx: HIF Context
908 *
909 * Return: enum ol_target_status
910 */
911ol_target_status hif_get_target_status(struct ol_softc *hif_ctx)
912{
913 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
914
915 return scn->target_status;
916}
917
918/**
919 * hif_set_target_status - API to set target status
920 * @hif_ctx: HIF Context
921 * @status: Target Status
922 *
923 * Return: void
924 */
925void hif_set_target_status(struct ol_softc *hif_ctx, ol_target_status status)
926{
927 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
928
929 scn->target_status = status;
930}