blob: f7e442471c85190ae294367d12f08cbe941ee47b [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
Ryan Hsu4252a2f2016-01-05 11:18:24 -08002 * Copyright (c) 2012-2016 The Linux Foundation. All rights reserved.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -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/**
29 * DOC: cds_api.c
30 *
31 * Connectivity driver services APIs
32 */
33
34#include <cds_mq.h>
35#include "cds_sched.h"
36#include <cds_api.h>
37#include "sir_types.h"
38#include "sir_api.h"
39#include "sir_mac_prot_def.h"
40#include "sme_api.h"
41#include "mac_init_api.h"
42#include "wlan_qct_sys.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080043#include "i_cds_packet.h"
44#include "cds_reg_service.h"
45#include "wma_types.h"
46#include "wlan_hdd_main.h"
47#include <linux/vmalloc.h>
48#ifdef CONFIG_CNSS
49#include <net/cnss.h>
50#endif
51
52#include "sap_api.h"
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053053#include "qdf_trace.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080054#include "bmi.h"
55#include "ol_fw.h"
56#include "ol_if_athvar.h"
57#include "hif.h"
58
59#include "cds_utils.h"
60#include "wlan_logging_sock_svc.h"
61#include "wma.h"
62
63#include "wlan_hdd_ipa.h"
64/* Preprocessor Definitions and Constants */
65
66/* Maximum number of cds message queue get wrapper failures to cause panic */
67#define CDS_WRAPPER_MAX_FAIL_COUNT (CDS_CORE_MAX_MESSAGES * 3)
68
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080069/* Data definitions */
70static cds_context_type g_cds_context;
71static p_cds_contextType gp_cds_context;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053072static struct __qdf_device g_qdf_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080073
74/* Debug variable to detect MC thread stuck */
75static atomic_t cds_wrapper_empty_count;
76
77static uint8_t cds_multicast_logging;
78
79void cds_sys_probe_thread_cback(void *pUserData);
80
81/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080082 * cds_init() - Initialize CDS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080083 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080084 * This function allocates the resource required for CDS, but does not
85 * initialize all the members. This overall initialization will happen at
86 * cds_open().
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080087 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080088 * Return: Global context on success and NULL on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080089 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080090v_CONTEXT_t cds_init(void)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080091{
Anurag Chouhan210db072016-02-22 18:42:15 +053092 qdf_mc_timer_manager_init();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080093 cdf_mem_init();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080094
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080095 gp_cds_context = &g_cds_context;
96
Anurag Chouhandf2b2682016-02-29 14:15:27 +053097 gp_cds_context->qdf_ctx = &g_qdf_ctx;
98 cdf_mem_zero(&g_qdf_ctx, sizeof(g_qdf_ctx));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080099
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530100 qdf_trace_spin_lock_init();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -0800101
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800102#if defined(TRACE_RECORD)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530103 qdf_trace_init();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800104#endif
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530105 qdf_dp_trace_init();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -0800106
107 cds_ssr_protect_init();
108
109 return gp_cds_context;
110}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800111
112/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -0800113 * cds_deinit() - Deinitialize CDS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800114 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -0800115 * This function frees the CDS resources
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800116 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -0800117void cds_deinit(void)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800118{
Prashanth Bhatta5da711e2015-11-30 14:28:52 -0800119 if (gp_cds_context == NULL)
120 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800121
Anurag Chouhan6d760662016-02-20 16:05:43 +0530122 gp_cds_context->qdf_ctx = NULL;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -0800123 gp_cds_context = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800124
Prashanth Bhatta9e143052015-12-04 11:56:47 -0800125 cdf_mem_zero(&g_cds_context, sizeof(g_cds_context));
126
Anurag Chouhan210db072016-02-22 18:42:15 +0530127 qdf_mc_timer_manager_exit();
Yuanyuan Liufd9bfc52015-12-14 15:44:20 -0800128 cdf_mem_exit();
129
Prashanth Bhatta5da711e2015-11-30 14:28:52 -0800130 return;
131}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800132
133#ifdef WLAN_FEATURE_NAN
134/**
135 * cds_set_nan_enable() - set nan enable flag in mac open param
136 * @wma_handle: Pointer to mac open param
137 * @hdd_ctx: Pointer to hdd context
138 *
139 * Return: none
140 */
141static void cds_set_nan_enable(tMacOpenParameters *param,
142 hdd_context_t *hdd_ctx)
143{
144 param->is_nan_enabled = hdd_ctx->config->enable_nan_support;
145}
146#else
147static void cds_set_nan_enable(tMacOpenParameters *param,
148 hdd_context_t *pHddCtx)
149{
150}
151#endif
152
153/**
154 * cds_open() - open the CDS Module
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800155 *
156 * cds_open() function opens the CDS Scheduler
157 * Upon successful initialization:
158 * - All CDS submodules should have been initialized
159 *
160 * - The CDS scheduler should have opened
161 *
162 * - All the WLAN SW components should have been opened. This includes
163 * SYS, MAC, SME, WMA and TL.
164 *
165 * Return: CDF status
166 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530167QDF_STATUS cds_open(void)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800168{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530169 QDF_STATUS qdf_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800170 int iter = 0;
171 tSirRetStatus sirStatus = eSIR_SUCCESS;
172 tMacOpenParameters mac_openParms;
Anurag Chouhan6d760662016-02-20 16:05:43 +0530173 qdf_device_t qdf_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800174 HTC_INIT_INFO htcInfo;
Komal Seelamd9106492016-02-15 10:31:44 +0530175 struct ol_context *ol_ctx;
Komal Seelam3d202862016-02-24 18:43:24 +0530176 struct hif_opaque_softc *scn;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800177 void *HTCHandle;
178 hdd_context_t *pHddCtx;
179
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530180 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800181 "%s: Opening CDS", __func__);
182
183 if (NULL == gp_cds_context) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530184 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800185 "%s: Trying to open CDS without a PreOpen", __func__);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530186 QDF_ASSERT(0);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530187 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800188 }
189
190 /* Initialize the timer module */
Anurag Chouhan210db072016-02-22 18:42:15 +0530191 qdf_timer_module_init();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800192
193 /* Initialize bug reporting structure */
194 cds_init_log_completion();
195
196 /* Initialize the probe event */
Anurag Chouhance0dc992016-02-16 18:18:03 +0530197 if (qdf_event_create(&gp_cds_context->ProbeEvent) != QDF_STATUS_SUCCESS) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530198 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800199 "%s: Unable to init probeEvent", __func__);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530200 QDF_ASSERT(0);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530201 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800202 }
Anurag Chouhance0dc992016-02-16 18:18:03 +0530203 if (qdf_event_create(&(gp_cds_context->wmaCompleteEvent)) !=
204 QDF_STATUS_SUCCESS) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530205 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800206 "%s: Unable to init wmaCompleteEvent", __func__);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530207 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800208 goto err_probe_event;
209 }
210
211 /* Initialize the free message queue */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530212 qdf_status = cds_mq_init(&gp_cds_context->freeVosMq);
213 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800214 /* Critical Error ... Cannot proceed further */
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530215 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800216 "%s: Failed to initialize CDS free message queue",
217 __func__);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530218 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800219 goto err_wma_complete_event;
220 }
221
222 for (iter = 0; iter < CDS_CORE_MAX_MESSAGES; iter++) {
223 (gp_cds_context->aMsgWrappers[iter]).pVosMsg =
224 &(gp_cds_context->aMsgBuffers[iter]);
225 INIT_LIST_HEAD(&gp_cds_context->aMsgWrappers[iter].msgNode);
226 cds_mq_put(&gp_cds_context->freeVosMq,
227 &(gp_cds_context->aMsgWrappers[iter]));
228 }
229
230 /* Now Open the CDS Scheduler */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530231 qdf_status = cds_sched_open(gp_cds_context, &gp_cds_context->cdf_sched,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800232 sizeof(cds_sched_context));
233
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530234 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800235 /* Critical Error ... Cannot proceed further */
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530236 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800237 "%s: Failed to open CDS Scheduler", __func__);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530238 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800239 goto err_msg_queue;
240 }
241
242 pHddCtx = (hdd_context_t *) (gp_cds_context->pHDDContext);
243 if ((NULL == pHddCtx) || (NULL == pHddCtx->config)) {
244 /* Critical Error ... Cannot proceed further */
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530245 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800246 "%s: Hdd Context is Null", __func__);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530247 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800248 goto err_sched_close;
249 }
250
Anurag Chouhan6d760662016-02-20 16:05:43 +0530251 scn = cds_get_context(QDF_MODULE_ID_HIF);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800252 if (!scn) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530253 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800254 "%s: scn is null!", __func__);
255 goto err_sched_close;
256 }
Komal Seelamc11bb222016-01-27 18:57:10 +0530257
Komal Seelamec702b02016-02-24 18:42:16 +0530258 hdd_update_config(pHddCtx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800259
Anurag Chouhan6d760662016-02-20 16:05:43 +0530260 ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800261 /* Initialize BMI and Download firmware */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530262 qdf_status = bmi_download_firmware(ol_ctx);
263 if (qdf_status != QDF_STATUS_SUCCESS) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530264 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_FATAL,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530265 "BMI FIALED status:%d", qdf_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800266 goto err_bmi_close;
267 }
268
Komal Seelam08633492016-02-24 18:05:07 +0530269 htcInfo.pContext = ol_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800270 htcInfo.TargetFailure = ol_target_failure;
271 htcInfo.TargetSendSuspendComplete = wma_target_suspend_acknowledge;
Anurag Chouhan6d760662016-02-20 16:05:43 +0530272 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800273
274 /* Create HTC */
275 gp_cds_context->htc_ctx =
Anurag Chouhan6d760662016-02-20 16:05:43 +0530276 htc_create(scn, &htcInfo, qdf_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800277 if (!gp_cds_context->htc_ctx) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530278 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800279 "%s: Failed to Create HTC", __func__);
280 goto err_bmi_close;
281 }
282
Komal Seelamd9106492016-02-15 10:31:44 +0530283 if (bmi_done(ol_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530284 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800285 "%s: Failed to complete BMI phase", __func__);
286 goto err_htc_close;
287 }
288
289 /*
290 ** Need to open WMA first because it calls WDI_Init, which calls wpalOpen
291 ** The reason that is needed becasue cds_packet_open need to use PAL APIs
292 */
293
294 /*Open the WMA module */
295 cdf_mem_set(&mac_openParms, sizeof(mac_openParms), 0);
296 /* UMA is supported in hardware for performing the
297 ** frame translation 802.11 <-> 802.3
298 */
299 mac_openParms.frameTransRequired = 1;
300 mac_openParms.driverType = eDRIVER_TYPE_PRODUCTION;
301 mac_openParms.powersaveOffloadEnabled =
302 pHddCtx->config->enablePowersaveOffload;
303 mac_openParms.staDynamicDtim = pHddCtx->config->enableDynamicDTIM;
304 mac_openParms.staModDtim = pHddCtx->config->enableModulatedDTIM;
305 mac_openParms.staMaxLIModDtim = pHddCtx->config->fMaxLIModulatedDTIM;
306 mac_openParms.wowEnable = pHddCtx->config->wowEnable;
307 mac_openParms.maxWoWFilters = pHddCtx->config->maxWoWFilters;
308 /* Here olIniInfo is used to store ini status of arp offload
309 * ns offload and others. Currently 1st bit is used for arp
310 * off load and 2nd bit for ns offload currently, rest bits are unused
311 */
312 if (pHddCtx->config->fhostArpOffload)
313 mac_openParms.olIniInfo = mac_openParms.olIniInfo | 0x1;
314 if (pHddCtx->config->fhostNSOffload)
315 mac_openParms.olIniInfo = mac_openParms.olIniInfo | 0x2;
316 /*
317 * Copy the DFS Phyerr Filtering Offload status.
318 * This parameter reflects the value of the
319 * dfsPhyerrFilterOffload flag as set in the ini.
320 */
321 mac_openParms.dfsPhyerrFilterOffload =
322 pHddCtx->config->fDfsPhyerrFilterOffload;
323 if (pHddCtx->config->ssdp)
324 mac_openParms.ssdp = pHddCtx->config->ssdp;
325#ifdef FEATURE_WLAN_RA_FILTERING
326 mac_openParms.RArateLimitInterval =
327 pHddCtx->config->RArateLimitInterval;
328 mac_openParms.IsRArateLimitEnabled =
329 pHddCtx->config->IsRArateLimitEnabled;
330#endif
331
332 mac_openParms.apMaxOffloadPeers = pHddCtx->config->apMaxOffloadPeers;
333
334 mac_openParms.apMaxOffloadReorderBuffs =
335 pHddCtx->config->apMaxOffloadReorderBuffs;
336
337 mac_openParms.apDisableIntraBssFwd =
338 pHddCtx->config->apDisableIntraBssFwd;
339
340 mac_openParms.dfsRadarPriMultiplier =
341 pHddCtx->config->dfsRadarPriMultiplier;
342 mac_openParms.reorderOffload = pHddCtx->config->reorderOffloadSupport;
343
344 /* IPA micro controller data path offload resource config item */
345 mac_openParms.ucOffloadEnabled = hdd_ipa_uc_is_enabled(pHddCtx);
346 mac_openParms.ucTxBufCount = pHddCtx->config->IpaUcTxBufCount;
347 mac_openParms.ucTxBufSize = pHddCtx->config->IpaUcTxBufSize;
348 mac_openParms.ucRxIndRingCount = pHddCtx->config->IpaUcRxIndRingCount;
349 mac_openParms.ucTxPartitionBase = pHddCtx->config->IpaUcTxPartitionBase;
350 mac_openParms.max_scan = pHddCtx->config->max_scan_count;
351
352 mac_openParms.ip_tcp_udp_checksum_offload =
353 pHddCtx->config->enable_ip_tcp_udp_checksum_offload;
354 mac_openParms.enable_rxthread = pHddCtx->config->enableRxThread;
355 mac_openParms.ce_classify_enabled =
356 pHddCtx->config->ce_classify_enabled;
357
358#ifdef QCA_LL_TX_FLOW_CONTROL_V2
359 mac_openParms.tx_flow_stop_queue_th =
360 pHddCtx->config->TxFlowStopQueueThreshold;
361 mac_openParms.tx_flow_start_queue_offset =
362 pHddCtx->config->TxFlowStartQueueOffset;
363#endif
364 cds_set_nan_enable(&mac_openParms, pHddCtx);
365
366 mac_openParms.tx_chain_mask_cck = pHddCtx->config->tx_chain_mask_cck;
367 mac_openParms.self_gen_frm_pwr = pHddCtx->config->self_gen_frm_pwr;
Komal Seelam02d09342016-02-23 18:03:19 +0530368 mac_openParms.maxStation = pHddCtx->config->maxNumberOfPeers;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800369
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530370 qdf_status = wma_open(gp_cds_context,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800371 hdd_update_tgt_cfg,
372 hdd_dfs_indicate_radar, &mac_openParms);
373
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530374 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800375 /* Critical Error ... Cannot proceed further */
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530376 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800377 "%s: Failed to open WMA module", __func__);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530378 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800379 goto err_htc_close;
380 }
381
382 /* Number of peers limit differs in each chip version. If peer max
383 * limit configured in ini exceeds more than supported, WMA adjusts
384 * and keeps correct limit in mac_openParms.maxStation. So, make sure
385 * config entry pHddCtx->config->maxNumberOfPeers has adjusted value
386 */
387 pHddCtx->config->maxNumberOfPeers = mac_openParms.maxStation;
Anurag Chouhan6d760662016-02-20 16:05:43 +0530388 HTCHandle = cds_get_context(QDF_MODULE_ID_HTC);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800389 if (!HTCHandle) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530390 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800391 "%s: HTCHandle is null!", __func__);
392 goto err_wma_close;
393 }
394 if (htc_wait_target(HTCHandle)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530395 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800396 "%s: Failed to complete BMI phase", __func__);
397 goto err_wma_close;
398 }
399
400 /* Now proceed to open the MAC */
401
402 /* UMA is supported in hardware for performing the
403 * frame translation 802.11 <-> 802.3
404 */
405 mac_openParms.frameTransRequired = 1;
406
407 sirStatus =
408 mac_open(&(gp_cds_context->pMACContext), gp_cds_context->pHDDContext,
409 &mac_openParms);
410
411 if (eSIR_SUCCESS != sirStatus) {
412 /* Critical Error ... Cannot proceed further */
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530413 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800414 "%s: Failed to open MAC", __func__);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530415 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800416 goto err_wma_close;
417 }
418
419 /* Now proceed to open the SME */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530420 qdf_status = sme_open(gp_cds_context->pMACContext);
421 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800422 /* Critical Error ... Cannot proceed further */
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530423 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800424 "%s: Failed to open SME", __func__);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530425 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800426 goto err_mac_close;
427 }
428
429 gp_cds_context->pdev_txrx_ctx =
430 ol_txrx_pdev_alloc(gp_cds_context->cfg_ctx,
431 gp_cds_context->htc_ctx,
Anurag Chouhan6d760662016-02-20 16:05:43 +0530432 gp_cds_context->qdf_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800433 if (!gp_cds_context->pdev_txrx_ctx) {
434 /* Critical Error ... Cannot proceed further */
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530435 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800436 "%s: Failed to open TXRX", __func__);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530437 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800438 goto err_sme_close;
439 }
440
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530441 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800442 "%s: CDS successfully Opened", __func__);
443
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530444 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800445
446err_sme_close:
447 sme_close(gp_cds_context->pMACContext);
448
449err_mac_close:
450 mac_close(gp_cds_context->pMACContext);
451
452err_wma_close:
453 wma_close(gp_cds_context);
454
455 wma_wmi_service_close(gp_cds_context);
456
457err_htc_close:
458 if (gp_cds_context->htc_ctx) {
459 htc_destroy(gp_cds_context->htc_ctx);
460 gp_cds_context->htc_ctx = NULL;
461 }
462
463err_bmi_close:
Komal Seelam5a6e5082016-02-24 17:59:09 +0530464 bmi_cleanup(ol_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800465
466err_sched_close:
467 cds_sched_close(gp_cds_context);
468
469err_msg_queue:
470 cds_mq_deinit(&gp_cds_context->freeVosMq);
471
472err_wma_complete_event:
Anurag Chouhance0dc992016-02-16 18:18:03 +0530473 qdf_event_destroy(&gp_cds_context->wmaCompleteEvent);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800474
475err_probe_event:
Anurag Chouhance0dc992016-02-16 18:18:03 +0530476 qdf_event_destroy(&gp_cds_context->ProbeEvent);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800477
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530478 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800479} /* cds_open() */
480
481/**
482 * cds_pre_enable() - pre enable cds
483 * @cds_context: CDS context
484 *
485 * Return: CDF status
486 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530487QDF_STATUS cds_pre_enable(v_CONTEXT_t cds_context)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800488{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530489 QDF_STATUS qdf_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800490 p_cds_contextType p_cds_context = (p_cds_contextType) cds_context;
491 void *scn;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530492 QDF_TRACE(QDF_MODULE_ID_SYS, QDF_TRACE_LEVEL_INFO, "cds prestart");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800493
494 if (gp_cds_context != p_cds_context) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530495 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800496 "%s: Context mismatch", __func__);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530497 QDF_ASSERT(0);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530498 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800499 }
500
501 if (p_cds_context->pMACContext == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530502 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800503 "%s: MAC NULL context", __func__);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530504 QDF_ASSERT(0);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530505 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800506 }
507
508 if (p_cds_context->pWMAContext == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530509 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800510 "%s: WMA NULL context", __func__);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530511 QDF_ASSERT(0);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530512 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800513 }
514
Anurag Chouhan6d760662016-02-20 16:05:43 +0530515 scn = cds_get_context(QDF_MODULE_ID_HIF);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800516 if (!scn) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530517 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800518 "%s: scn is null!", __func__);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530519 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800520 }
521
522 /* Reset wma wait event */
Anurag Chouhance0dc992016-02-16 18:18:03 +0530523 qdf_event_reset(&gp_cds_context->wmaCompleteEvent);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800524
525 /*call WMA pre start */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530526 qdf_status = wma_pre_start(gp_cds_context);
527 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530528 QDF_TRACE(QDF_MODULE_ID_SYS, QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800529 "Failed to WMA prestart");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530530 QDF_ASSERT(0);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530531 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800532 }
533
534 /* Need to update time out of complete */
Anurag Chouhance0dc992016-02-16 18:18:03 +0530535 qdf_status = qdf_wait_single_event(&gp_cds_context->wmaCompleteEvent,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800536 CDS_WMA_TIMEOUT);
Anurag Chouhance0dc992016-02-16 18:18:03 +0530537 if (qdf_status != QDF_STATUS_SUCCESS) {
538 if (qdf_status == QDF_STATUS_E_TIMEOUT) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530539 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800540 "%s: Timeout occurred before WMA complete",
541 __func__);
542 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530543 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800544 "%s: wma_pre_start reporting other error",
545 __func__);
546 }
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530547 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800548 "%s: Test MC thread by posting a probe message to SYS",
549 __func__);
550 wlan_sys_probe();
551
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530552 QDF_ASSERT(0);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530553 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800554 }
555
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530556 qdf_status = htc_start(gp_cds_context->htc_ctx);
557 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530558 QDF_TRACE(QDF_MODULE_ID_SYS, QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800559 "Failed to Start HTC");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530560 QDF_ASSERT(0);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530561 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800562 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530563 qdf_status = wma_wait_for_ready_event(gp_cds_context->pWMAContext);
564 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530565 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800566 "Failed to get ready event from target firmware");
567 htc_set_target_to_sleep(scn);
568 htc_stop(gp_cds_context->htc_ctx);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530569 QDF_ASSERT(0);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530570 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800571 }
572
573 if (ol_txrx_pdev_attach(gp_cds_context->pdev_txrx_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530574 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800575 "Failed to attach pdev");
576 htc_set_target_to_sleep(scn);
577 htc_stop(gp_cds_context->htc_ctx);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530578 QDF_ASSERT(0);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530579 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800580 }
581
582 htc_set_target_to_sleep(scn);
583
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530584 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800585}
586
587/**
588 * cds_enable() - start/enable cds module
589 * @cds_context: CDS context
590 *
591 * Return: CDF status
592 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530593QDF_STATUS cds_enable(v_CONTEXT_t cds_context)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800594{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530595 QDF_STATUS qdf_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800596 tSirRetStatus sirStatus = eSIR_SUCCESS;
597 p_cds_contextType p_cds_context = (p_cds_contextType) cds_context;
598 tHalMacStartParameters halStartParams;
599
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530600 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800601 "%s: Starting Libra SW", __func__);
602
603 /* We support only one instance for now ... */
604 if (gp_cds_context != p_cds_context) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530605 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800606 "%s: mismatch in context", __func__);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530607 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800608 }
609
610 if ((p_cds_context->pWMAContext == NULL) ||
611 (p_cds_context->pMACContext == NULL)) {
612 if (p_cds_context->pWMAContext == NULL)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530613 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800614 "%s: WMA NULL context", __func__);
615 else
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530616 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800617 "%s: MAC NULL context", __func__);
618
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530619 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800620 }
621
622 /* Start the wma */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530623 qdf_status = wma_start(p_cds_context);
624 if (qdf_status != QDF_STATUS_SUCCESS) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530625 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800626 "%s: Failed to start wma", __func__);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530627 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800628 }
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530629 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800630 "%s: wma correctly started", __func__);
631
632 /* Start the MAC */
633 cdf_mem_zero(&halStartParams,
634 sizeof(tHalMacStartParameters));
635
636 /* Start the MAC */
637 sirStatus =
638 mac_start(p_cds_context->pMACContext, &halStartParams);
639
640 if (eSIR_SUCCESS != sirStatus) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530641 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800642 "%s: Failed to start MAC", __func__);
643 goto err_wma_stop;
644 }
645
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530646 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800647 "%s: MAC correctly started", __func__);
648
649 /* START SME */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530650 qdf_status = sme_start(p_cds_context->pMACContext);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800651
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530652 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530653 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800654 "%s: Failed to start SME", __func__);
655 goto err_mac_stop;
656 }
657
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530658 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800659 "%s: SME correctly started", __func__);
660
661 if (ol_txrx_pdev_attach_target
662 (p_cds_context->pdev_txrx_ctx) != A_OK) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530663 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800664 "%s: Failed attach target", __func__);
665 goto err_sme_stop;
666 }
667
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530668 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800669 "TL correctly started");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530670 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800671 "%s: CDS Start is successful!!", __func__);
672
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530673 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800674
675err_sme_stop:
676 sme_stop(p_cds_context->pMACContext, HAL_STOP_TYPE_SYS_RESET);
677
678err_mac_stop:
679 mac_stop(p_cds_context->pMACContext, HAL_STOP_TYPE_SYS_RESET);
680
681err_wma_stop:
Anurag Chouhance0dc992016-02-16 18:18:03 +0530682 qdf_event_reset(&(gp_cds_context->wmaCompleteEvent));
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530683 qdf_status = wma_stop(p_cds_context, HAL_STOP_TYPE_RF_KILL);
684 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530685 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800686 "%s: Failed to stop wma", __func__);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530687 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800688 wma_setneedshutdown(cds_context);
689 } else {
Anurag Chouhance0dc992016-02-16 18:18:03 +0530690 qdf_status =
691 qdf_wait_single_event(&(gp_cds_context->wmaCompleteEvent),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800692 CDS_WMA_TIMEOUT);
Anurag Chouhance0dc992016-02-16 18:18:03 +0530693 if (qdf_status != QDF_STATUS_SUCCESS) {
694 if (qdf_status == QDF_STATUS_E_TIMEOUT) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530695 QDF_TRACE(QDF_MODULE_ID_QDF,
696 QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800697 "%s: Timeout occurred before WMA_stop complete",
698 __func__);
699 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530700 QDF_TRACE(QDF_MODULE_ID_QDF,
701 QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800702 "%s: WMA_stop reporting other error",
703 __func__);
704 }
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530705 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800706 wma_setneedshutdown(cds_context);
707 }
708 }
709
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530710 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800711} /* cds_enable() */
712
713/**
714 * cds_disable() - stop/disable cds module
715 * @cds_context: CDS context
716 *
717 * Return: CDF status
718 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530719QDF_STATUS cds_disable(v_CONTEXT_t cds_context)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800720{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530721 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800722
723 /* wma_stop is called before the SYS so that the processing of target
724 * pending responses will not be handled during uninitialization of
725 * WLAN driver
726 */
Anurag Chouhance0dc992016-02-16 18:18:03 +0530727 qdf_event_reset(&(gp_cds_context->wmaCompleteEvent));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800728
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530729 qdf_status = wma_stop(cds_context, HAL_STOP_TYPE_RF_KILL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800730
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530731 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530732 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800733 "%s: Failed to stop wma", __func__);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530734 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800735 wma_setneedshutdown(cds_context);
736 }
737
738 hif_disable_isr(((cds_context_type *) cds_context)->pHIFContext);
739 hif_reset_soc(((cds_context_type *) cds_context)->pHIFContext);
740
741 /* SYS STOP will stop SME and MAC */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530742 qdf_status = sys_stop(cds_context);
743 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530744 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800745 "%s: Failed to stop SYS", __func__);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530746 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800747 }
748
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530749 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800750}
751
752/**
753 * cds_close() - close cds module
754 * @cds_context: CDS context
755 *
756 * Return: CDF status
757 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530758QDF_STATUS cds_close(v_CONTEXT_t cds_context)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800759{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530760 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800761
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530762 qdf_status = wma_wmi_work_close(cds_context);
763 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530764 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Xun Luoa858a472015-11-10 08:24:45 -0800765 "%s: Failed to close wma_wmi_work", __func__);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530766 QDF_ASSERT(0);
Xun Luoa858a472015-11-10 08:24:45 -0800767 }
768
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800769 if (gp_cds_context->htc_ctx) {
770 htc_stop(gp_cds_context->htc_ctx);
771 htc_destroy(gp_cds_context->htc_ctx);
772 gp_cds_context->htc_ctx = NULL;
773 }
774
775 ol_txrx_pdev_detach(gp_cds_context->pdev_txrx_ctx, 1);
Anurag Chouhan6d760662016-02-20 16:05:43 +0530776 cds_free_context(cds_context, QDF_MODULE_ID_TXRX,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800777 gp_cds_context->pdev_txrx_ctx);
778
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530779 qdf_status = sme_close(((p_cds_contextType) cds_context)->pMACContext);
780 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530781 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800782 "%s: Failed to close SME", __func__);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530783 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800784 }
785
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530786 qdf_status = mac_close(((p_cds_contextType) cds_context)->pMACContext);
787 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530788 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800789 "%s: Failed to close MAC", __func__);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530790 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800791 }
792
793 ((p_cds_contextType) cds_context)->pMACContext = NULL;
794
795 if (true == wma_needshutdown(cds_context)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530796 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800797 "%s: Failed to shutdown wma", __func__);
798 } else {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530799 qdf_status = wma_close(cds_context);
800 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530801 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800802 "%s: Failed to close wma", __func__);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530803 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800804 }
805 }
806
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530807 qdf_status = wma_wmi_service_close(cds_context);
808 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530809 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800810 "%s: Failed to close wma_wmi_service", __func__);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530811 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800812 }
813
814 cds_mq_deinit(&((p_cds_contextType) cds_context)->freeVosMq);
815
Anurag Chouhance0dc992016-02-16 18:18:03 +0530816 qdf_status = qdf_event_destroy(&gp_cds_context->wmaCompleteEvent);
817 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530818 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800819 "%s: failed to destroy wmaCompleteEvent", __func__);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530820 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800821 }
822
Anurag Chouhance0dc992016-02-16 18:18:03 +0530823 qdf_status = qdf_event_destroy(&gp_cds_context->ProbeEvent);
824 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530825 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800826 "%s: failed to destroy ProbeEvent", __func__);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530827 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800828 }
829
830 cds_deinit_log_completion();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -0800831
832 gp_cds_context->pHDDContext = NULL;
833
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530834 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800835}
836
837/**
838 * cds_get_context() - get context data area
839 *
840 * @moduleId: ID of the module who's context data is being retrived.
841 *
842 * Each module in the system has a context / data area that is allocated
843 * and managed by CDS. This API allows any user to get a pointer to its
844 * allocated context data area from the CDS global context.
845 *
846 * Return: pointer to the context data area of the module ID
847 * specified, or NULL if the context data is not allocated for
848 * the module ID specified
849 */
Anurag Chouhan6d760662016-02-20 16:05:43 +0530850void *cds_get_context(QDF_MODULE_ID moduleId)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800851{
852 void *pModContext = NULL;
853
854 if (gp_cds_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530855 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800856 "%s: cds context pointer is null", __func__);
857 return NULL;
858 }
859
860 switch (moduleId) {
Anurag Chouhan6d760662016-02-20 16:05:43 +0530861 case QDF_MODULE_ID_HDD:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800862 {
863 pModContext = gp_cds_context->pHDDContext;
864 break;
865 }
866
Anurag Chouhan6d760662016-02-20 16:05:43 +0530867 case QDF_MODULE_ID_SME:
868 case QDF_MODULE_ID_PE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800869 {
870 /* In all these cases, we just return the MAC Context */
871 pModContext = gp_cds_context->pMACContext;
872 break;
873 }
874
Anurag Chouhan6d760662016-02-20 16:05:43 +0530875 case QDF_MODULE_ID_WMA:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800876 {
877 /* For wma module */
878 pModContext = gp_cds_context->pWMAContext;
879 break;
880 }
881
Anurag Chouhan6d760662016-02-20 16:05:43 +0530882 case QDF_MODULE_ID_QDF:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800883 {
884 /* For SYS this is CDS itself */
885 pModContext = gp_cds_context;
886 break;
887 }
888
Anurag Chouhan6d760662016-02-20 16:05:43 +0530889 case QDF_MODULE_ID_HIF:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800890 {
891 pModContext = gp_cds_context->pHIFContext;
892 break;
893 }
894
Anurag Chouhan6d760662016-02-20 16:05:43 +0530895 case QDF_MODULE_ID_HTC:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800896 {
897 pModContext = gp_cds_context->htc_ctx;
898 break;
899 }
900
Anurag Chouhan6d760662016-02-20 16:05:43 +0530901 case QDF_MODULE_ID_QDF_DEVICE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800902 {
Anurag Chouhan6d760662016-02-20 16:05:43 +0530903 pModContext = gp_cds_context->qdf_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800904 break;
905 }
906
Anurag Chouhan6d760662016-02-20 16:05:43 +0530907 case QDF_MODULE_ID_BMI:
Komal Seelamd9106492016-02-15 10:31:44 +0530908 {
909 pModContext = gp_cds_context->g_ol_context;
910 break;
911 }
912
Anurag Chouhan6d760662016-02-20 16:05:43 +0530913 case QDF_MODULE_ID_TXRX:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800914 {
915 pModContext = gp_cds_context->pdev_txrx_ctx;
916 break;
917 }
918
Anurag Chouhan6d760662016-02-20 16:05:43 +0530919 case QDF_MODULE_ID_CFG:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800920 {
921 pModContext = gp_cds_context->cfg_ctx;
922 break;
923 }
924
925 default:
926 {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530927 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800928 "%s: Module ID %i does not have its context maintained by CDS",
929 __func__, moduleId);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530930 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800931 return NULL;
932 }
933 }
934
935 if (pModContext == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530936 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800937 "%s: Module ID %i context is Null", __func__,
938 moduleId);
939 }
940
941 return pModContext;
942} /* cds_get_context() */
943
944/**
945 * cds_get_global_context() - get CDS global Context
946 *
947 * This API allows any user to get the CDS Global Context pointer from a
948 * module context data area.
949 *
950 * Return: pointer to the CDS global context, NULL if the function is
951 * unable to retreive the CDS context.
952 */
953v_CONTEXT_t cds_get_global_context(void)
954{
955 if (gp_cds_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530956 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800957 "%s: global cds context is NULL", __func__);
958 }
959
960 return gp_cds_context;
961} /* cds_get_global_context() */
962
963/**
Prashanth Bhatta9e143052015-12-04 11:56:47 -0800964 * cds_get_driver_state() - Get current driver state
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800965 *
Prashanth Bhatta9e143052015-12-04 11:56:47 -0800966 * This API returns current driver state stored in global context.
967 *
968 * Return: Driver state enum
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800969 */
Prashanth Bhatta9e143052015-12-04 11:56:47 -0800970enum cds_driver_state cds_get_driver_state(void)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800971{
972 if (gp_cds_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530973 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800974 "%s: global cds context is NULL", __func__);
Prashanth Bhatta9e143052015-12-04 11:56:47 -0800975
976 return CDS_DRIVER_STATE_UNINITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800977 }
978
Prashanth Bhatta9e143052015-12-04 11:56:47 -0800979 return gp_cds_context->driver_state;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800980}
981
982/**
Prashanth Bhatta9e143052015-12-04 11:56:47 -0800983 * cds_set_driver_state() - Set current driver state
984 * @state: Driver state to be set to.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800985 *
Prashanth Bhatta9e143052015-12-04 11:56:47 -0800986 * This API sets driver state to state. This API only sets the state and doesn't
987 * clear states, please make sure to use cds_clear_driver_state to clear any
988 * state if required.
989 *
990 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800991 */
Prashanth Bhatta9e143052015-12-04 11:56:47 -0800992void cds_set_driver_state(enum cds_driver_state state)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800993{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800994 if (gp_cds_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530995 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prashanth Bhatta9e143052015-12-04 11:56:47 -0800996 "%s: global cds context is NULL: %x", __func__,
997 state);
998
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800999 return;
1000 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001001
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001002 gp_cds_context->driver_state |= state;
1003}
1004
1005/**
1006 * cds_clear_driver_state() - Clear current driver state
1007 * @state: Driver state to be cleared.
1008 *
1009 * This API clears driver state. This API only clears the state, please make
1010 * sure to use cds_set_driver_state to set any new states.
1011 *
1012 * Return: None
1013 */
1014void cds_clear_driver_state(enum cds_driver_state state)
1015{
1016 if (gp_cds_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301017 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001018 "%s: global cds context is NULL: %x", __func__,
1019 state);
1020
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001021 return;
1022 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001023
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001024 gp_cds_context->driver_state &= ~state;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001025}
1026
1027/**
1028 * cds_alloc_context() - allocate a context within the CDS global Context
1029 * @p_cds_context: pointer to the global Vos context
1030 * @moduleId: module ID who's context area is being allocated.
1031 * @ppModuleContext: pointer to location where the pointer to the
1032 * allocated context is returned. Note this output pointer
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301033 * is valid only if the API returns QDF_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001034 * @param size: size of the context area to be allocated.
1035 *
1036 * This API allows any user to allocate a user context area within the
1037 * CDS Global Context.
1038 *
1039 * Return: CDF status
1040 */
Anurag Chouhan6d760662016-02-20 16:05:43 +05301041QDF_STATUS cds_alloc_context(void *p_cds_context, QDF_MODULE_ID moduleID,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001042 void **ppModuleContext, uint32_t size)
1043{
1044 void **pGpModContext = NULL;
1045
1046 if (p_cds_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301047 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001048 "%s: cds context is null", __func__);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301049 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001050 }
1051
1052 if ((gp_cds_context != p_cds_context) || (ppModuleContext == NULL)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301053 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001054 "%s: context mismatch or null param passed",
1055 __func__);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301056 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001057 }
1058
1059 switch (moduleID) {
Anurag Chouhan6d760662016-02-20 16:05:43 +05301060 case QDF_MODULE_ID_WMA:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001061 {
1062 pGpModContext = &(gp_cds_context->pWMAContext);
1063 break;
1064 }
1065
Anurag Chouhan6d760662016-02-20 16:05:43 +05301066 case QDF_MODULE_ID_HIF:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001067 {
1068 pGpModContext = &(gp_cds_context->pHIFContext);
1069 break;
1070 }
1071
Anurag Chouhan6d760662016-02-20 16:05:43 +05301072 case QDF_MODULE_ID_BMI:
Komal Seelamd9106492016-02-15 10:31:44 +05301073 {
1074 pGpModContext = &(gp_cds_context->g_ol_context);
1075 break;
1076 }
1077
Anurag Chouhan6d760662016-02-20 16:05:43 +05301078 case QDF_MODULE_ID_EPPING:
1079 case QDF_MODULE_ID_SME:
1080 case QDF_MODULE_ID_PE:
1081 case QDF_MODULE_ID_HDD:
1082 case QDF_MODULE_ID_HDD_SOFTAP:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001083 default:
1084 {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301085 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001086 "%s: Module ID %i "
1087 "does not have its context allocated by CDS",
1088 __func__, moduleID);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301089 QDF_ASSERT(0);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301090 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001091 }
1092 }
1093
1094 if (NULL != *pGpModContext) {
1095 /* Context has already been allocated!
1096 * Prevent double allocation
1097 */
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301098 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001099 "%s: Module ID %i context has already been allocated",
1100 __func__, moduleID);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301101 return QDF_STATUS_E_EXISTS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001102 }
1103
1104 /* Dynamically allocate the context for module */
1105
1106 *ppModuleContext = cdf_mem_malloc(size);
1107
1108 if (*ppModuleContext == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301109 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001110 "%s: Failed to " "allocate Context for module ID %i",
1111 __func__, moduleID);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301112 QDF_ASSERT(0);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301113 return QDF_STATUS_E_NOMEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001114 }
1115
Anurag Chouhan6d760662016-02-20 16:05:43 +05301116 if (moduleID == QDF_MODULE_ID_TLSHIM)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001117 cdf_mem_zero(*ppModuleContext, size);
1118
1119 *pGpModContext = *ppModuleContext;
1120
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301121 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001122} /* cds_alloc_context() */
1123
1124/**
Komal Seelamad5a90d2016-02-16 13:50:03 +05301125 * cds_set_context() - API to set context in global CDS Context
1126 * @moduleID: Module ID
1127 * @context: Pointer to the Module Context
1128 *
1129 * API to set a MODULE Context in gloabl CDS Context
1130 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301131 * Return: QDF_STATUS
Komal Seelamad5a90d2016-02-16 13:50:03 +05301132 */
Anurag Chouhan6d760662016-02-20 16:05:43 +05301133QDF_STATUS cds_set_context(QDF_MODULE_ID module_id, void *context)
Komal Seelamad5a90d2016-02-16 13:50:03 +05301134{
1135 p_cds_contextType p_cds_context = cds_get_global_context();
1136
1137 if (!p_cds_context) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301138 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Komal Seelamad5a90d2016-02-16 13:50:03 +05301139 "cds context is Invald");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301140 return QDF_STATUS_NOT_INITIALIZED;
Komal Seelamad5a90d2016-02-16 13:50:03 +05301141 }
1142
1143 switch (module_id) {
Anurag Chouhan6d760662016-02-20 16:05:43 +05301144 case QDF_MODULE_ID_HIF:
Komal Seelamad5a90d2016-02-16 13:50:03 +05301145 p_cds_context->pHIFContext = context;
1146 break;
1147 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301148 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Komal Seelamad5a90d2016-02-16 13:50:03 +05301149 "%s: Module ID %i does not have its context "
1150 "allocated by CDS", __func__, module_id);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301151 QDF_ASSERT(0);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301152 return QDF_STATUS_E_INVAL;
Komal Seelamad5a90d2016-02-16 13:50:03 +05301153 }
1154
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301155 return QDF_STATUS_SUCCESS;
Komal Seelamad5a90d2016-02-16 13:50:03 +05301156}
1157
1158/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001159 * cds_free_context() - free an allocated context within the
1160 * CDS global Context
1161 * @p_cds_context: pointer to the global Vos context
1162 * @moduleId: module ID who's context area is being free
1163 * @pModuleContext: pointer to module context area to be free'd.
1164 *
1165 * This API allows a user to free the user context area within the
1166 * CDS Global Context.
1167 *
1168 * Return: CDF status
1169 */
Anurag Chouhan6d760662016-02-20 16:05:43 +05301170QDF_STATUS cds_free_context(void *p_cds_context, QDF_MODULE_ID moduleID,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001171 void *pModuleContext)
1172{
1173 void **pGpModContext = NULL;
1174
1175 if ((p_cds_context == NULL) || (gp_cds_context != p_cds_context) ||
1176 (pModuleContext == NULL)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301177 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001178 "%s: Null params or context mismatch", __func__);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301179 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001180 }
1181
1182 switch (moduleID) {
Anurag Chouhan6d760662016-02-20 16:05:43 +05301183 case QDF_MODULE_ID_WMA:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001184 {
1185 pGpModContext = &(gp_cds_context->pWMAContext);
1186 break;
1187 }
1188
Anurag Chouhan6d760662016-02-20 16:05:43 +05301189 case QDF_MODULE_ID_HIF:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001190 {
1191 pGpModContext = &(gp_cds_context->pHIFContext);
1192 break;
1193 }
1194
Anurag Chouhan6d760662016-02-20 16:05:43 +05301195 case QDF_MODULE_ID_TXRX:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001196 {
1197 pGpModContext = &(gp_cds_context->pdev_txrx_ctx);
1198 break;
1199 }
1200
Anurag Chouhan6d760662016-02-20 16:05:43 +05301201 case QDF_MODULE_ID_BMI:
Komal Seelamd9106492016-02-15 10:31:44 +05301202 {
1203 pGpModContext = &(gp_cds_context->g_ol_context);
1204 break;
1205 }
1206
Anurag Chouhan6d760662016-02-20 16:05:43 +05301207 case QDF_MODULE_ID_EPPING:
1208 case QDF_MODULE_ID_HDD:
1209 case QDF_MODULE_ID_SME:
1210 case QDF_MODULE_ID_PE:
1211 case QDF_MODULE_ID_HDD_SOFTAP:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001212 default:
1213 {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301214 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001215 "%s: Module ID %i "
1216 "does not have its context allocated by CDS",
1217 __func__, moduleID);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301218 QDF_ASSERT(0);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301219 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001220 }
1221 }
1222
1223 if (NULL == *pGpModContext) {
1224 /* Context has not been allocated or freed already! */
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301225 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001226 "%s: Module ID %i "
1227 "context has not been allocated or freed already",
1228 __func__, moduleID);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301229 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001230 }
1231
1232 if (*pGpModContext != pModuleContext) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301233 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001234 "%s: pGpModContext != pModuleContext", __func__);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301235 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001236 }
1237
1238 if (pModuleContext != NULL)
1239 cdf_mem_free(pModuleContext);
1240
1241 *pGpModContext = NULL;
1242
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301243 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001244} /* cds_free_context() */
1245
1246/**
1247 * cds_mq_post_message() - post a message to a message queue
1248 * @msgQueueId: identifies the message queue upon which the message
1249 * will be posted.
1250 * @message: a pointer to a message buffer. Memory for this message
1251 * buffer is allocated by the caller and free'd by the CDF after the
1252 * message is posted to the message queue. If the consumer of the
1253 * message needs anything in this message, it needs to copy the contents
1254 * before returning from the message queue handler.
1255 *
1256 * Return: CDF status
1257 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301258QDF_STATUS cds_mq_post_message(CDS_MQ_ID msgQueueId, cds_msg_t *pMsg)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001259{
1260 p_cds_mq_type pTargetMq = NULL;
1261 p_cds_msg_wrapper pMsgWrapper = NULL;
1262 uint32_t debug_count = 0;
1263
1264 if ((gp_cds_context == NULL) || (pMsg == NULL)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301265 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001266 "%s: Null params or global cds context is null",
1267 __func__);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301268 QDF_ASSERT(0);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301269 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001270 }
1271
1272 switch (msgQueueId) {
1273 /* Message Queue ID for messages bound for SME */
1274 case CDS_MQ_ID_SME:
1275 {
1276 pTargetMq = &(gp_cds_context->cdf_sched.smeMcMq);
1277 break;
1278 }
1279
1280 /* Message Queue ID for messages bound for PE */
1281 case CDS_MQ_ID_PE:
1282 {
1283 pTargetMq = &(gp_cds_context->cdf_sched.peMcMq);
1284 break;
1285 }
1286
1287 /* Message Queue ID for messages bound for wma */
1288 case CDS_MQ_ID_WMA:
1289 {
1290 pTargetMq = &(gp_cds_context->cdf_sched.wmaMcMq);
1291 break;
1292 }
1293
1294 /* Message Queue ID for messages bound for the SYS module */
1295 case CDS_MQ_ID_SYS:
1296 {
1297 pTargetMq = &(gp_cds_context->cdf_sched.sysMcMq);
1298 break;
1299 }
1300
1301 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301302 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001303 ("%s: Trying to queue msg into unknown MC Msg queue ID %d"),
1304 __func__, msgQueueId);
1305
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301306 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001307 }
1308
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301309 QDF_ASSERT(NULL != pTargetMq);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001310 if (pTargetMq == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301311 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001312 "%s: pTargetMq == NULL", __func__);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301313 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001314 }
1315
1316 /* Try and get a free Msg wrapper */
1317 pMsgWrapper = cds_mq_get(&gp_cds_context->freeVosMq);
1318
1319 if (NULL == pMsgWrapper) {
1320 debug_count = atomic_inc_return(&cds_wrapper_empty_count);
1321 if (1 == debug_count)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301322 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001323 "%s: CDS Core run out of message wrapper %d",
1324 __func__, debug_count);
1325
1326 if (CDS_WRAPPER_MAX_FAIL_COUNT == debug_count)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301327 QDF_BUG(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001328
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301329 return QDF_STATUS_E_RESOURCES;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001330 }
1331
1332 atomic_set(&cds_wrapper_empty_count, 0);
1333
1334 /* Copy the message now */
1335 cdf_mem_copy((void *)pMsgWrapper->pVosMsg,
1336 (void *)pMsg, sizeof(cds_msg_t));
1337
1338 cds_mq_put(pTargetMq, pMsgWrapper);
1339
1340 set_bit(MC_POST_EVENT_MASK, &gp_cds_context->cdf_sched.mcEventFlag);
1341 wake_up_interruptible(&gp_cds_context->cdf_sched.mcWaitQueue);
1342
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301343 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001344} /* cds_mq_post_message() */
1345
1346/**
1347 * cds_sys_probe_thread_cback() - probe mc thread callback
1348 * @pUserData: pointer to user data
1349 *
1350 * Return: none
1351 */
1352void cds_sys_probe_thread_cback(void *pUserData)
1353{
1354 if (gp_cds_context != pUserData) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301355 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001356 "%s: gp_cds_context != pUserData", __func__);
1357 return;
1358 }
1359
Anurag Chouhance0dc992016-02-16 18:18:03 +05301360 if (qdf_event_set(&gp_cds_context->ProbeEvent) != QDF_STATUS_SUCCESS) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301361 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Anurag Chouhance0dc992016-02-16 18:18:03 +05301362 "%s: qdf_event_set failed", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001363 return;
1364 }
1365} /* cds_sys_probe_thread_cback() */
1366
1367/**
1368 * cds_wma_complete_cback() - wma complete callback
1369 * @pUserData: pointer to user data
1370 *
1371 * Return: none
1372 */
1373void cds_wma_complete_cback(void *pUserData)
1374{
1375 if (gp_cds_context != pUserData) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301376 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001377 "%s: gp_cds_context != pUserData", __func__);
1378 return;
1379 }
1380
Anurag Chouhance0dc992016-02-16 18:18:03 +05301381 if (qdf_event_set(&gp_cds_context->wmaCompleteEvent) !=
1382 QDF_STATUS_SUCCESS) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301383 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Anurag Chouhance0dc992016-02-16 18:18:03 +05301384 "%s: qdf_event_set failed", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001385 return;
1386 }
1387} /* cds_wma_complete_cback() */
1388
1389/**
1390 * cds_core_return_msg() - return core message
1391 * @pVContext: pointer to cds context
1392 * @pMsgWrapper: pointer to message wrapper
1393 *
1394 * Return: none
1395 */
1396void cds_core_return_msg(void *pVContext, p_cds_msg_wrapper pMsgWrapper)
1397{
1398 p_cds_contextType p_cds_context = (p_cds_contextType) pVContext;
1399
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301400 QDF_ASSERT(gp_cds_context == p_cds_context);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001401
1402 if (gp_cds_context != p_cds_context) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301403 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001404 "%s: gp_cds_context != p_cds_context", __func__);
1405 return;
1406 }
1407
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301408 QDF_ASSERT(NULL != pMsgWrapper);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001409
1410 if (pMsgWrapper == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301411 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001412 "%s: pMsgWrapper == NULL in function", __func__);
1413 return;
1414 }
1415
1416 /*
1417 ** Return the message on the free message queue
1418 */
1419 INIT_LIST_HEAD(&pMsgWrapper->msgNode);
1420 cds_mq_put(&p_cds_context->freeVosMq, pMsgWrapper);
1421} /* cds_core_return_msg() */
1422
1423
1424/**
1425 * cds_shutdown() - shutdown CDS
1426 * @cds_context: global cds context
1427 *
1428 * Return: CDF status
1429 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301430QDF_STATUS cds_shutdown(v_CONTEXT_t cds_context)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001431{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301432 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001433 tpAniSirGlobal pmac = (((p_cds_contextType)cds_context)->pMACContext);
1434
1435 ol_txrx_pdev_detach(gp_cds_context->pdev_txrx_ctx, 1);
Anurag Chouhan6d760662016-02-20 16:05:43 +05301436 cds_free_context(cds_context, QDF_MODULE_ID_TXRX,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001437 gp_cds_context->pdev_txrx_ctx);
1438
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301439 qdf_status = sme_close(((p_cds_contextType) cds_context)->pMACContext);
1440 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301441 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001442 "%s: Failed to close SME", __func__);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301443 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001444 }
1445 /*
1446 * CAC timer will be initiated and started only when SAP starts on
1447 * DFS channel and it will be stopped and destroyed immediately once the
1448 * radar detected or timedout. So as per design CAC timer should be
1449 * destroyed after stop
1450 */
1451 if (pmac->sap.SapDfsInfo.is_dfs_cac_timer_running) {
Anurag Chouhan210db072016-02-22 18:42:15 +05301452 qdf_mc_timer_stop(&pmac->sap.SapDfsInfo.sap_dfs_cac_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001453 pmac->sap.SapDfsInfo.is_dfs_cac_timer_running = 0;
Anurag Chouhan210db072016-02-22 18:42:15 +05301454 qdf_mc_timer_destroy(&pmac->sap.SapDfsInfo.sap_dfs_cac_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001455 }
1456
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301457 qdf_status = mac_close(((p_cds_contextType) cds_context)->pMACContext);
1458 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301459 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001460 "%s: Failed to close MAC", __func__);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301461 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001462 }
1463
1464 ((p_cds_contextType) cds_context)->pMACContext = NULL;
1465
1466 if (false == wma_needshutdown(cds_context)) {
1467
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301468 qdf_status = wma_close(cds_context);
1469 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301470 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001471 "%s: Failed to close wma!", __func__);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301472 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001473 }
1474 }
1475
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301476 qdf_status = wma_wmi_work_close(cds_context);
1477 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301478 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Xun Luoa858a472015-11-10 08:24:45 -08001479 "%s: Failed to close wma_wmi_work!", __func__);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301480 QDF_ASSERT(0);
Xun Luoa858a472015-11-10 08:24:45 -08001481 }
1482
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001483 if (gp_cds_context->htc_ctx) {
1484 htc_stop(gp_cds_context->htc_ctx);
1485 htc_destroy(gp_cds_context->htc_ctx);
1486 gp_cds_context->htc_ctx = NULL;
1487 }
1488
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301489 qdf_status = wma_wmi_service_close(cds_context);
1490 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301491 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001492 "%s: Failed to close wma_wmi_service!", __func__);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301493 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001494 }
1495
1496 cds_mq_deinit(&((p_cds_contextType) cds_context)->freeVosMq);
1497
Anurag Chouhance0dc992016-02-16 18:18:03 +05301498 qdf_status = qdf_event_destroy(&gp_cds_context->wmaCompleteEvent);
1499 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301500 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001501 "%s: failed to destroy wmaCompleteEvent", __func__);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301502 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001503 }
1504
Anurag Chouhance0dc992016-02-16 18:18:03 +05301505 qdf_status = qdf_event_destroy(&gp_cds_context->ProbeEvent);
1506 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301507 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001508 "%s: failed to destroy ProbeEvent", __func__);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301509 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001510 }
1511
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301512 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001513}
1514
1515/**
1516 * cds_get_vdev_types() - get vdev type
1517 * @mode: mode
1518 * @type: type
1519 * @sub_type: sub_type
1520 *
1521 * Return: WMI vdev type
1522 */
Anurag Chouhan6d760662016-02-20 16:05:43 +05301523QDF_STATUS cds_get_vdev_types(enum tQDF_ADAPTER_MODE mode, uint32_t *type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001524 uint32_t *sub_type)
1525{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301526 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001527 *type = 0;
1528 *sub_type = 0;
1529
1530 switch (mode) {
Anurag Chouhan6d760662016-02-20 16:05:43 +05301531 case QDF_STA_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001532 *type = WMI_VDEV_TYPE_STA;
1533 break;
Anurag Chouhan6d760662016-02-20 16:05:43 +05301534 case QDF_SAP_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001535 *type = WMI_VDEV_TYPE_AP;
1536 break;
Anurag Chouhan6d760662016-02-20 16:05:43 +05301537 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001538 *type = WMI_VDEV_TYPE_AP;
1539 *sub_type = WMI_UNIFIED_VDEV_SUBTYPE_P2P_DEVICE;
1540 break;
Anurag Chouhan6d760662016-02-20 16:05:43 +05301541 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001542 *type = WMI_VDEV_TYPE_STA;
1543 *sub_type = WMI_UNIFIED_VDEV_SUBTYPE_P2P_CLIENT;
1544 break;
Anurag Chouhan6d760662016-02-20 16:05:43 +05301545 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001546 *type = WMI_VDEV_TYPE_AP;
1547 *sub_type = WMI_UNIFIED_VDEV_SUBTYPE_P2P_GO;
1548 break;
Anurag Chouhan6d760662016-02-20 16:05:43 +05301549 case QDF_OCB_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001550 *type = WMI_VDEV_TYPE_OCB;
1551 break;
1552 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301553 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Ryan Hsud7e6fc72015-12-07 17:26:14 -08001554 "Invalid device mode %d", mode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301555 status = QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001556 break;
1557 }
1558 return status;
1559}
1560
1561/**
1562 * cds_flush_work() - flush pending works
1563 * @work: pointer to work
1564 *
1565 * Return: none
1566 */
1567void cds_flush_work(void *work)
1568{
1569#if defined (CONFIG_CNSS)
1570 cnss_flush_work(work);
1571#elif defined (WLAN_OPEN_SOURCE)
1572 cancel_work_sync(work);
1573#endif
1574}
1575
1576/**
1577 * cds_flush_delayed_work() - flush delayed works
1578 * @dwork: pointer to delayed work
1579 *
1580 * Return: none
1581 */
1582void cds_flush_delayed_work(void *dwork)
1583{
1584#if defined (CONFIG_CNSS)
1585 cnss_flush_delayed_work(dwork);
1586#elif defined (WLAN_OPEN_SOURCE)
1587 cancel_delayed_work_sync(dwork);
1588#endif
1589}
1590
1591/**
1592 * cds_is_packet_log_enabled() - check if packet log is enabled
1593 *
1594 * Return: true if packet log is enabled else false
1595 */
1596bool cds_is_packet_log_enabled(void)
1597{
1598 hdd_context_t *pHddCtx;
1599
1600 pHddCtx = (hdd_context_t *) (gp_cds_context->pHDDContext);
1601 if ((NULL == pHddCtx) || (NULL == pHddCtx->config)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301602 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001603 "%s: Hdd Context is Null", __func__);
1604 return false;
1605 }
1606
1607 return pHddCtx->config->enablePacketLog;
1608}
1609
1610/**
1611 * cds_trigger_recovery() - trigger self recovery
1612 *
1613 * Return: none
1614 */
1615void cds_trigger_recovery(void)
1616{
Anurag Chouhan6d760662016-02-20 16:05:43 +05301617 tp_wma_handle wma_handle = cds_get_context(QDF_MODULE_ID_WMA);
Anurag Chouhance0dc992016-02-16 18:18:03 +05301618 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001619
1620 if (!wma_handle) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301621 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001622 "WMA context is invald!");
1623 return;
1624 }
1625
1626 wma_crash_inject(wma_handle, RECOVERY_SIM_SELF_RECOVERY, 0);
1627
Anurag Chouhance0dc992016-02-16 18:18:03 +05301628 status = qdf_wait_single_event(&wma_handle->recovery_event,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001629 WMA_CRASH_INJECT_TIMEOUT);
1630
Anurag Chouhance0dc992016-02-16 18:18:03 +05301631 if (QDF_STATUS_SUCCESS != status) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301632 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001633 "CRASH_INJECT command is timed out!");
1634 #ifdef CONFIG_CNSS
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001635 if (cds_is_driver_recovering()) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301636 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001637 "Recovery is in progress, ignore!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001638 return;
1639 }
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001640 cds_set_recovery_in_progress(true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001641 cnss_schedule_recovery_work();
1642 #endif
1643
1644 return;
1645 }
1646}
1647
1648/**
1649 * cds_get_monotonic_boottime() - Get kernel boot time.
1650 *
1651 * Return: Time in microseconds
1652 */
1653
1654uint64_t cds_get_monotonic_boottime(void)
1655{
1656#ifdef CONFIG_CNSS
1657 struct timespec ts;
1658
1659 cnss_get_monotonic_boottime(&ts);
1660 return ((uint64_t) ts.tv_sec * 1000000) + (ts.tv_nsec / 1000);
1661#else
Anurag Chouhan50220ce2016-02-18 20:11:33 +05301662 return ((uint64_t)qdf_system_ticks_to_msecs(qdf_system_ticks()) *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001663 1000);
1664#endif
1665}
1666
1667/**
1668 * cds_set_wakelock_logging() - Logging of wakelock enabled/disabled
1669 * @value: Boolean value
1670 *
1671 * This function is used to set the flag which will indicate whether
1672 * logging of wakelock is enabled or not
1673 *
1674 * Return: None
1675 */
1676void cds_set_wakelock_logging(bool value)
1677{
1678 p_cds_contextType p_cds_context;
1679
1680 p_cds_context = cds_get_global_context();
1681 if (!p_cds_context) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301682 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001683 "cds context is Invald");
1684 return;
1685 }
1686 p_cds_context->is_wakelock_log_enabled = value;
1687}
1688
1689/**
1690 * cds_is_wakelock_enabled() - Check if logging of wakelock is enabled/disabled
1691 * @value: Boolean value
1692 *
1693 * This function is used to check whether logging of wakelock is enabled or not
1694 *
1695 * Return: true if logging of wakelock is enabled
1696 */
1697bool cds_is_wakelock_enabled(void)
1698{
1699 p_cds_contextType p_cds_context;
1700
1701 p_cds_context = cds_get_global_context();
1702 if (!p_cds_context) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301703 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001704 "cds context is Invald");
1705 return false;
1706 }
1707 return p_cds_context->is_wakelock_log_enabled;
1708}
1709
1710/**
1711 * cds_set_ring_log_level() - Sets the log level of a particular ring
1712 * @ring_id: ring_id
1713 * @log_levelvalue: Log level specificed
1714 *
1715 * This function converts HLOS values to driver log levels and sets the log
1716 * level of a particular ring accordingly.
1717 *
1718 * Return: None
1719 */
1720void cds_set_ring_log_level(uint32_t ring_id, uint32_t log_level)
1721{
1722 p_cds_contextType p_cds_context;
1723 uint32_t log_val;
1724
1725 p_cds_context = cds_get_global_context();
1726 if (!p_cds_context) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301727 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001728 "%s: cds context is Invald", __func__);
1729 return;
1730 }
1731
1732 switch (log_level) {
1733 case LOG_LEVEL_NO_COLLECTION:
1734 log_val = WLAN_LOG_LEVEL_OFF;
1735 break;
1736 case LOG_LEVEL_NORMAL_COLLECT:
1737 log_val = WLAN_LOG_LEVEL_NORMAL;
1738 break;
1739 case LOG_LEVEL_ISSUE_REPRO:
1740 log_val = WLAN_LOG_LEVEL_REPRO;
1741 break;
1742 case LOG_LEVEL_ACTIVE:
1743 default:
1744 log_val = WLAN_LOG_LEVEL_ACTIVE;
1745 break;
1746 }
1747
1748 if (ring_id == RING_ID_WAKELOCK) {
1749 p_cds_context->wakelock_log_level = log_val;
1750 return;
1751 } else if (ring_id == RING_ID_CONNECTIVITY) {
1752 p_cds_context->connectivity_log_level = log_val;
1753 return;
1754 } else if (ring_id == RING_ID_PER_PACKET_STATS) {
1755 p_cds_context->packet_stats_log_level = log_val;
1756 return;
Chandrasekaran, Manishekar907c2af2015-11-13 12:50:04 +05301757 } else if (ring_id == RING_ID_DRIVER_DEBUG) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001758 p_cds_context->driver_debug_log_level = log_val;
1759 return;
1760 } else if (ring_id == RING_ID_FIRMWARE_DEBUG) {
1761 p_cds_context->fw_debug_log_level = log_val;
1762 return;
1763 }
1764}
1765
1766/**
1767 * cds_get_ring_log_level() - Get the a ring id's log level
1768 * @ring_id: Ring id
1769 *
1770 * Fetch and return the log level corresponding to a ring id
1771 *
1772 * Return: Log level corresponding to the ring ID
1773 */
1774enum wifi_driver_log_level cds_get_ring_log_level(uint32_t ring_id)
1775{
1776 p_cds_contextType p_cds_context;
1777
1778 p_cds_context = cds_get_global_context();
1779 if (!p_cds_context) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301780 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001781 "%s: cds context is Invald", __func__);
1782 return WLAN_LOG_LEVEL_OFF;
1783 }
1784
1785 if (ring_id == RING_ID_WAKELOCK)
1786 return p_cds_context->wakelock_log_level;
1787 else if (ring_id == RING_ID_CONNECTIVITY)
1788 return p_cds_context->connectivity_log_level;
1789 else if (ring_id == RING_ID_PER_PACKET_STATS)
1790 return p_cds_context->packet_stats_log_level;
Chandrasekaran, Manishekar907c2af2015-11-13 12:50:04 +05301791 else if (ring_id == RING_ID_DRIVER_DEBUG)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001792 return p_cds_context->driver_debug_log_level;
1793 else if (ring_id == RING_ID_FIRMWARE_DEBUG)
1794 return p_cds_context->fw_debug_log_level;
1795
1796 return WLAN_LOG_LEVEL_OFF;
1797}
1798
1799/**
1800 * cds_set_multicast_logging() - Set mutlicast logging value
1801 * @value: Value of multicast logging
1802 *
1803 * Set the multicast logging value which will indicate
1804 * whether to multicast host and fw messages even
1805 * without any registration by userspace entity
1806 *
1807 * Return: None
1808 */
1809void cds_set_multicast_logging(uint8_t value)
1810{
1811 cds_multicast_logging = value;
1812}
1813
1814/**
1815 * cds_is_multicast_logging() - Get multicast logging value
1816 *
1817 * Get the multicast logging value which will indicate
1818 * whether to multicast host and fw messages even
1819 * without any registration by userspace entity
1820 *
1821 * Return: 0 - Multicast logging disabled, 1 - Multicast logging enabled
1822 */
1823uint8_t cds_is_multicast_logging(void)
1824{
1825 return cds_multicast_logging;
1826}
1827
1828/*
1829 * cds_init_log_completion() - Initialize log param structure
1830 *
1831 * This function is used to initialize the logging related
1832 * parameters
1833 *
1834 * Return: None
1835 */
1836void cds_init_log_completion(void)
1837{
1838 p_cds_contextType p_cds_context;
1839
1840 p_cds_context = cds_get_global_context();
1841 if (!p_cds_context) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301842 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001843 "%s: cds context is Invalid", __func__);
1844 return;
1845 }
1846
1847 p_cds_context->log_complete.is_fatal = WLAN_LOG_TYPE_NON_FATAL;
1848 p_cds_context->log_complete.indicator = WLAN_LOG_INDICATOR_UNUSED;
1849 p_cds_context->log_complete.reason_code = WLAN_LOG_REASON_CODE_UNUSED;
1850 p_cds_context->log_complete.is_report_in_progress = false;
1851 /* Attempting to initialize an already initialized lock
1852 * results in a failure. This must be ok here.
1853 */
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301854 qdf_spinlock_create(&p_cds_context->bug_report_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001855}
1856
1857/**
1858 * cds_deinit_log_completion() - Deinitialize log param structure
1859 *
1860 * This function is used to deinitialize the logging related
1861 * parameters
1862 *
1863 * Return: None
1864 */
1865void cds_deinit_log_completion(void)
1866{
1867 p_cds_contextType p_cds_context;
1868
1869 p_cds_context = cds_get_global_context();
1870 if (!p_cds_context) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301871 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001872 "%s: cds context is Invalid", __func__);
1873 return;
1874 }
1875
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301876 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001877}
1878
1879/**
1880 * cds_set_log_completion() - Store the logging params
1881 * @is_fatal: Indicates if the event triggering bug report is fatal or not
1882 * @indicator: Source which trigerred the bug report
1883 * @reason_code: Reason for triggering bug report
1884 *
1885 * This function is used to set the logging parameters based on the
1886 * caller
1887 *
1888 * Return: 0 if setting of params is successful
1889 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301890QDF_STATUS cds_set_log_completion(uint32_t is_fatal,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001891 uint32_t indicator,
1892 uint32_t reason_code)
1893{
1894 p_cds_contextType p_cds_context;
1895
1896 p_cds_context = cds_get_global_context();
1897 if (!p_cds_context) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301898 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001899 "%s: cds context is Invalid", __func__);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301900 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001901 }
1902
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301903 qdf_spinlock_acquire(&p_cds_context->bug_report_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001904 p_cds_context->log_complete.is_fatal = is_fatal;
1905 p_cds_context->log_complete.indicator = indicator;
1906 p_cds_context->log_complete.reason_code = reason_code;
1907 p_cds_context->log_complete.is_report_in_progress = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301908 qdf_spinlock_release(&p_cds_context->bug_report_lock);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301909 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001910}
1911
1912/**
1913 * cds_get_log_completion() - Get the logging related params
1914 * @is_fatal: Indicates if the event triggering bug report is fatal or not
1915 * @indicator: Source which trigerred the bug report
1916 * @reason_code: Reason for triggering bug report
1917 *
1918 * This function is used to get the logging related parameters
1919 *
1920 * Return: None
1921 */
1922void cds_get_log_completion(uint32_t *is_fatal,
1923 uint32_t *indicator,
1924 uint32_t *reason_code)
1925{
1926 p_cds_contextType p_cds_context;
1927
1928 p_cds_context = cds_get_global_context();
1929 if (!p_cds_context) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301930 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001931 "%s: cds context is Invalid", __func__);
1932 return;
1933 }
1934
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301935 qdf_spinlock_acquire(&p_cds_context->bug_report_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001936 *is_fatal = p_cds_context->log_complete.is_fatal;
1937 *indicator = p_cds_context->log_complete.indicator;
1938 *reason_code = p_cds_context->log_complete.reason_code;
1939 p_cds_context->log_complete.is_report_in_progress = false;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301940 qdf_spinlock_release(&p_cds_context->bug_report_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001941}
1942
1943/**
1944 * cds_is_log_report_in_progress() - Check if bug reporting is in progress
1945 *
1946 * This function is used to check if the bug reporting is already in progress
1947 *
1948 * Return: true if the bug reporting is in progress
1949 */
1950bool cds_is_log_report_in_progress(void)
1951{
1952 p_cds_contextType p_cds_context;
1953
1954 p_cds_context = cds_get_global_context();
1955 if (!p_cds_context) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301956 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001957 "%s: cds context is Invalid", __func__);
1958 return true;
1959 }
1960 return p_cds_context->log_complete.is_report_in_progress;
1961}
1962
1963/**
1964 * cds_flush_logs() - Report fatal event to userspace
1965 * @is_fatal: Indicates if the event triggering bug report is fatal or not
1966 * @indicator: Source which trigerred the bug report
1967 * @reason_code: Reason for triggering bug report
1968 *
1969 * This function sets the log related params and send the WMI command to the
1970 * FW to flush its logs. On receiving the flush completion event from the FW
1971 * the same will be conveyed to userspace
1972 *
1973 * Return: 0 on success
1974 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301975QDF_STATUS cds_flush_logs(uint32_t is_fatal,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001976 uint32_t indicator,
1977 uint32_t reason_code)
1978{
1979 uint32_t ret;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301980 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001981
1982 p_cds_contextType p_cds_context;
1983
1984 p_cds_context = cds_get_global_context();
1985 if (!p_cds_context) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301986 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001987 "%s: cds context is Invalid", __func__);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301988 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001989 }
1990
1991 if (cds_is_log_report_in_progress() == true) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301992 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001993 "%s: Bug report already in progress - dropping! type:%d, indicator=%d reason_code=%d",
1994 __func__, is_fatal, indicator, reason_code);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301995 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001996 }
1997
1998 status = cds_set_log_completion(is_fatal, indicator, reason_code);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301999 if (QDF_STATUS_SUCCESS != status) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302000 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002001 "%s: Failed to set log trigger params", __func__);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302002 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002003 }
2004
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302005 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002006 "%s: Triggering bug report: type:%d, indicator=%d reason_code=%d",
2007 __func__, is_fatal, indicator, reason_code);
2008
2009 ret = sme_send_flush_logs_cmd_to_fw(p_cds_context->pMACContext);
2010 if (0 != ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302011 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002012 "%s: Failed to send flush FW log", __func__);
2013 cds_init_log_completion();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302014 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002015 }
2016
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302017 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002018}
2019
2020/**
2021 * cds_logging_set_fw_flush_complete() - Wrapper for FW log flush completion
2022 *
2023 * This function is used to send signal to the logger thread to indicate
2024 * that the flushing of FW logs is complete by the FW
2025 *
2026 * Return: None
2027 *
2028 */
2029void cds_logging_set_fw_flush_complete(void)
2030{
2031 wlan_logging_set_fw_flush_complete();
2032}