blob: 1fad5872db20218eaa24abc1bea9c1f429d4ab45 [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
Rajeev Kumar08ef0d62016-12-28 21:26:55 -08002 * Copyright (c) 2012-2017 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
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080034#include "cds_sched.h"
35#include <cds_api.h>
36#include "sir_types.h"
37#include "sir_api.h"
38#include "sir_mac_prot_def.h"
39#include "sme_api.h"
40#include "mac_init_api.h"
41#include "wlan_qct_sys.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080042#include "i_cds_packet.h"
43#include "cds_reg_service.h"
44#include "wma_types.h"
45#include "wlan_hdd_main.h"
46#include <linux/vmalloc.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080047
Yuanyuan Liu0e0aa932016-05-12 10:17:58 -070048#include "pld_common.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080049#include "sap_api.h"
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053050#include "qdf_trace.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080051#include "bmi.h"
52#include "ol_fw.h"
53#include "ol_if_athvar.h"
54#include "hif.h"
Tushnim Bhattacharyya12b48742017-03-13 12:46:45 -070055#include "wlan_policy_mgr_api.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080056#include "cds_utils.h"
57#include "wlan_logging_sock_svc.h"
58#include "wma.h"
Nirav Shah7f337db2016-05-25 10:49:02 +053059#include "pktlog_ac.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080060#include "wlan_hdd_ipa.h"
Pramod Simha0d3b9362017-03-27 14:59:58 -070061#include "wlan_policy_mgr_api.h"
Leo Chang9b097032016-10-28 11:03:17 -070062
63#include <cdp_txrx_cmn_reg.h>
64#include <cdp_txrx_cfg.h>
65#include <cdp_txrx_misc.h>
Rajeev Kumar97767a02016-11-30 11:20:40 -080066#include <dispatcher_init_deinit.h>
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -080067#include <cdp_txrx_handle.h>
68
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080069/* Preprocessor Definitions and Constants */
70
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080071/* Data definitions */
72static cds_context_type g_cds_context;
73static p_cds_contextType gp_cds_context;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053074static struct __qdf_device g_qdf_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080075
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080076static uint8_t cds_multicast_logging;
77
Leo Chang9b097032016-10-28 11:03:17 -070078static struct ol_if_ops dp_ol_if_ops = {
79 .peer_set_default_routing = wma_peer_set_default_routing,
80 .peer_rx_reorder_queue_setup = wma_peer_rx_reorder_queue_setup,
81 .peer_rx_reorder_queue_remove = wma_peer_rx_reorder_queue_remove,
Pramod Simha0d3b9362017-03-27 14:59:58 -070082 .is_hw_dbs_2x2_capable = policy_mgr_is_hw_dbs_2x2_capable
Leo Chang9b097032016-10-28 11:03:17 -070083 /* TODO: Add any other control path calls required to OL_IF/WMA layer */
84};
85
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080086void cds_sys_probe_thread_cback(void *pUserData);
87
Venkata Sharath Chandra Manchala83985632017-02-28 14:16:22 -080088/** cds_get_datapath_handles - Initialize pdev, vdev and soc
89 * @soc - soc handle
90 * @vdev - virtual handle
91 * @pdev - physical handle
92 */
93uint8_t cds_get_datapath_handles(void **soc, struct cdp_pdev **pdev,
94 struct cdp_vdev **vdev, uint8_t sessionId)
95{
96
97 (*soc) = cds_get_context(QDF_MODULE_ID_SOC);
98
99 if (!(*soc)) {
100 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
101 "soc handle is invalid");
102 return -EINVAL;
103 }
104
105 (*pdev) = cds_get_context(QDF_MODULE_ID_TXRX);
106
107 if (!(*pdev)) {
108 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
109 "pdev handle is invalid");
110 return -EINVAL;
111 }
112
113 (*vdev) = cdp_get_vdev_from_vdev_id((*soc), (*pdev),
114 sessionId);
115
116 if (!(*vdev)) {
117 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
118 "vdev handle is invalid");
119 return -EINVAL;
120 }
121 return 0;
122}
123
124
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800125/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -0800126 * cds_init() - Initialize CDS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800127 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -0800128 * This function allocates the resource required for CDS, but does not
129 * initialize all the members. This overall initialization will happen at
130 * cds_open().
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800131 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -0800132 * Return: Global context on success and NULL on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800133 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -0800134v_CONTEXT_t cds_init(void)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800135{
Mahesh Kumar Kalikot Veetil319dbcd2016-10-27 15:03:48 -0700136 qdf_debugfs_init();
Houston Hoffman1a777572017-01-13 12:43:48 -0800137 qdf_lock_stats_init();
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530138 qdf_mem_init();
Houston Hoffman9e06e542016-12-12 12:06:26 -0800139 qdf_mc_timer_manager_init();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800140
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800141 gp_cds_context = &g_cds_context;
142
Anurag Chouhandf2b2682016-02-29 14:15:27 +0530143 gp_cds_context->qdf_ctx = &g_qdf_ctx;
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530144 qdf_mem_zero(&g_qdf_ctx, sizeof(g_qdf_ctx));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800145
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530146 qdf_trace_spin_lock_init();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -0800147
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800148#if defined(TRACE_RECORD)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530149 qdf_trace_init();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800150#endif
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +0530151 qdf_register_debugcb_init();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -0800152
153 cds_ssr_protect_init();
154
155 return gp_cds_context;
156}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800157
158/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -0800159 * cds_deinit() - Deinitialize CDS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800160 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -0800161 * This function frees the CDS resources
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800162 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -0800163void cds_deinit(void)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800164{
Prashanth Bhatta5da711e2015-11-30 14:28:52 -0800165 if (gp_cds_context == NULL)
166 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800167
Arunk Khandavalli4cc97a92016-09-14 23:13:07 +0530168 qdf_mc_timer_manager_exit();
169 qdf_mem_exit();
Houston Hoffman1a777572017-01-13 12:43:48 -0800170 qdf_lock_stats_deinit();
Mahesh Kumar Kalikot Veetil319dbcd2016-10-27 15:03:48 -0700171 qdf_debugfs_exit();
Arunk Khandavalli4cc97a92016-09-14 23:13:07 +0530172
Anurag Chouhan6d760662016-02-20 16:05:43 +0530173 gp_cds_context->qdf_ctx = NULL;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -0800174 gp_cds_context = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800175
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530176 qdf_mem_zero(&g_cds_context, sizeof(g_cds_context));
Prashanth Bhatta5da711e2015-11-30 14:28:52 -0800177 return;
178}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800179
Abhishek Singh437606a2016-04-27 13:51:49 +0530180#ifdef FEATURE_WLAN_DIAG_SUPPORT
181/**
182 * cds_tdls_tx_rx_mgmt_event()- send tdls mgmt rx tx event
183 * @event_id: event id
184 * @tx_rx: tx or rx
185 * @type: type of frame
186 * @action_sub_type: action frame type
187 * @peer_mac: peer mac
188 *
189 * This Function sends tdls mgmt rx tx diag event
190 *
191 * Return: void.
192 */
193void cds_tdls_tx_rx_mgmt_event(uint8_t event_id, uint8_t tx_rx,
194 uint8_t type, uint8_t action_sub_type, uint8_t *peer_mac)
195{
196 WLAN_HOST_DIAG_EVENT_DEF(tdls_tx_rx_mgmt,
197 struct host_event_tdls_tx_rx_mgmt);
198
199 tdls_tx_rx_mgmt.event_id = event_id;
200 tdls_tx_rx_mgmt.tx_rx = tx_rx;
201 tdls_tx_rx_mgmt.type = type;
202 tdls_tx_rx_mgmt.action_sub_type = action_sub_type;
203 qdf_mem_copy(tdls_tx_rx_mgmt.peer_mac,
204 peer_mac, CDS_MAC_ADDRESS_LEN);
205 WLAN_HOST_DIAG_EVENT_REPORT(&tdls_tx_rx_mgmt,
206 EVENT_WLAN_TDLS_TX_RX_MGMT);
207}
208#endif
209
Leo Chang9b097032016-10-28 11:03:17 -0700210/**
gbian62edd7e2017-03-07 13:12:13 +0800211 * cds_cfg_update_ac_specs_params() - update ac_specs params
212 * @olcfg: cfg handle
213 * @mac_params: mac params
214 *
215 * Return: none
216 */
217static void
218cds_cfg_update_ac_specs_params(struct txrx_pdev_cfg_param_t *olcfg,
219 struct cds_config_info *cds_cfg)
220{
221 int i;
222
223 if (NULL == olcfg)
224 return;
225
226 if (NULL == cds_cfg)
227 return;
228
229 for (i = 0; i < OL_TX_NUM_WMM_AC; i++) {
230 olcfg->ac_specs[i].wrr_skip_weight =
231 cds_cfg->ac_specs[i].wrr_skip_weight;
232 olcfg->ac_specs[i].credit_threshold =
233 cds_cfg->ac_specs[i].credit_threshold;
234 olcfg->ac_specs[i].send_limit =
235 cds_cfg->ac_specs[i].send_limit;
236 olcfg->ac_specs[i].credit_reserve =
237 cds_cfg->ac_specs[i].credit_reserve;
238 olcfg->ac_specs[i].discard_weight =
239 cds_cfg->ac_specs[i].discard_weight;
240 }
241}
242
243/**
Leo Chang9b097032016-10-28 11:03:17 -0700244 * cds_cdp_cfg_attach() - attach data path config module
245 * @cds_cfg: generic platform level config instance
246 *
247 * Return: none
248 */
249static void cds_cdp_cfg_attach(struct cds_config_info *cds_cfg)
250{
251 struct txrx_pdev_cfg_param_t cdp_cfg = {0};
252 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
253
Kiran Kumar Lokere52d8dc32016-12-05 19:20:40 -0800254 cdp_cfg.is_full_reorder_offload = cds_cfg->reorder_offload;
Leo Chang9b097032016-10-28 11:03:17 -0700255 cdp_cfg.is_uc_offload_enabled = cds_cfg->uc_offload_enabled;
256 cdp_cfg.uc_tx_buffer_count = cds_cfg->uc_txbuf_count;
257 cdp_cfg.uc_tx_buffer_size = cds_cfg->uc_txbuf_size;
258 cdp_cfg.uc_rx_indication_ring_count = cds_cfg->uc_rxind_ringcount;
259 cdp_cfg.uc_tx_partition_base = cds_cfg->uc_tx_partition_base;
260 cdp_cfg.enable_rxthread = cds_cfg->enable_rxthread;
261 cdp_cfg.ip_tcp_udp_checksum_offload =
262 cds_cfg->ip_tcp_udp_checksum_offload;
263 cdp_cfg.ce_classify_enabled = cds_cfg->ce_classify_enabled;
264
gbian62edd7e2017-03-07 13:12:13 +0800265 cds_cfg_update_ac_specs_params(&cdp_cfg, cds_cfg);
Kiran Kumar Lokere9aecfee2016-11-23 17:37:42 -0800266 gp_cds_context->cfg_ctx = cdp_cfg_attach(soc, gp_cds_context->qdf_ctx,
267 (void *)(&cdp_cfg));
268 if (!gp_cds_context->cfg_ctx) {
269 WMA_LOGP("%s: failed to init cfg handle", __func__);
270 return;
271 }
272
Leo Chang9b097032016-10-28 11:03:17 -0700273 /* Configure Receive flow steering */
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -0800274 cdp_cfg_set_flow_steering(soc, gp_cds_context->cfg_ctx,
Leo Chang9b097032016-10-28 11:03:17 -0700275 cds_cfg->flow_steering_enabled);
276
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -0800277 cdp_cfg_set_flow_control_parameters(soc, gp_cds_context->cfg_ctx,
278 (void *)&cdp_cfg);
Leo Chang9b097032016-10-28 11:03:17 -0700279
280 /* adjust the cfg_ctx default value based on setting */
281 cdp_cfg_set_rx_fwd_disabled(soc, gp_cds_context->cfg_ctx,
282 (uint8_t) cds_cfg->ap_disable_intrabss_fwd);
283
284 /*
285 * adjust the packet log enable default value
286 * based on CFG INI setting
287 */
288 cdp_cfg_set_packet_log_enabled(soc, gp_cds_context->cfg_ctx,
289 (uint8_t)cds_is_packet_log_enabled());
290}
Krunal Sonid32c6bc2016-10-18 18:00:21 -0700291static QDF_STATUS cds_register_all_modules(void)
292{
293 QDF_STATUS status;
294
295 scheduler_register_wma_legacy_handler(&wma_mc_process_handler);
296 scheduler_register_sys_legacy_handler(&sys_mc_process_handler);
297
298 /* Register message queues in given order such that queue priority is
299 * intact:
300 * 1) QDF_MODULE_ID_SYS: Timer queue(legacy SYS queue)
301 * 2) QDF_MODULE_ID_TARGET_IF: Target interface queue
302 * 3) QDF_MODULE_ID_PE: Legacy PE message queue
303 * 4) QDF_MODULE_ID_SME: Legacy SME message queue
304 * 5) QDF_MODULE_ID_OS_IF: OS IF message queue for new components
305 */
306 status = scheduler_register_module(QDF_MODULE_ID_SYS,
307 &scheduler_timer_q_mq_handler);
308 status = scheduler_register_module(QDF_MODULE_ID_TARGET_IF,
309 &scheduler_target_if_mq_handler);
310 status = scheduler_register_module(QDF_MODULE_ID_PE,
311 &pe_mc_process_handler);
312 status = scheduler_register_module(QDF_MODULE_ID_SME,
313 &sme_mc_process_handler);
314 status = scheduler_register_module(QDF_MODULE_ID_OS_IF,
315 &scheduler_os_if_mq_handler);
316 return status;
317}
318
319static QDF_STATUS cds_deregister_all_modules(void)
320{
321 QDF_STATUS status;
Krunal Sonie3399902017-02-01 09:51:42 -0800322
323 scheduler_deregister_wma_legacy_handler();
324 scheduler_deregister_sys_legacy_handler();
Krunal Sonid32c6bc2016-10-18 18:00:21 -0700325 status = scheduler_deregister_module(QDF_MODULE_ID_SYS);
Rajeev Kumara88b2dc2017-01-30 16:35:14 -0800326 status = scheduler_deregister_module(QDF_MODULE_ID_TARGET_IF);
Krunal Sonid32c6bc2016-10-18 18:00:21 -0700327 status = scheduler_deregister_module(QDF_MODULE_ID_PE);
328 status = scheduler_deregister_module(QDF_MODULE_ID_SME);
329 status = scheduler_deregister_module(QDF_MODULE_ID_OS_IF);
Krunal Sonie3399902017-02-01 09:51:42 -0800330
Krunal Sonid32c6bc2016-10-18 18:00:21 -0700331 return status;
332}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800333
334/**
gbian62edd7e2017-03-07 13:12:13 +0800335 * cds_set_ac_specs_params() - set ac_specs params in cds_config_info
336 * @cds_cfg: Pointer to cds_config_info
337 * @hdd_ctx: Pointer to hdd context
338 *
339 * Return: none
340 */
341static void
342cds_set_ac_specs_params(struct cds_config_info *cds_cfg)
343{
344 int i;
345 cds_context_type *cds_ctx;
346
347 if (NULL == cds_cfg)
348 return;
349
350 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
351
352 if (!cds_ctx) {
353 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
354 "Invalid CDS Context");
355 return;
356 }
357
358 for (i = 0; i < OL_TX_NUM_WMM_AC; i++) {
359 cds_cfg->ac_specs[i] = cds_ctx->ac_specs[i];
360 }
361}
362
363/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800364 * cds_open() - open the CDS Module
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800365 *
366 * cds_open() function opens the CDS Scheduler
367 * Upon successful initialization:
368 * - All CDS submodules should have been initialized
369 *
370 * - The CDS scheduler should have opened
371 *
372 * - All the WLAN SW components should have been opened. This includes
373 * SYS, MAC, SME, WMA and TL.
374 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530375 * Return: QDF status
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800376 */
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +0530377QDF_STATUS cds_open(struct wlan_objmgr_psoc *psoc)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800378{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530379 QDF_STATUS qdf_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800380 tSirRetStatus sirStatus = eSIR_SUCCESS;
Arun Khandavallic811dcc2016-06-26 07:37:21 +0530381 struct cds_config_info *cds_cfg;
Anurag Chouhan6d760662016-02-20 16:05:43 +0530382 qdf_device_t qdf_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800383 HTC_INIT_INFO htcInfo;
Komal Seelamd9106492016-02-15 10:31:44 +0530384 struct ol_context *ol_ctx;
Komal Seelam3d202862016-02-24 18:43:24 +0530385 struct hif_opaque_softc *scn;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800386 void *HTCHandle;
387 hdd_context_t *pHddCtx;
Arun Khandavallic811dcc2016-06-26 07:37:21 +0530388 cds_context_type *cds_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800389
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530390 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800391 "%s: Opening CDS", __func__);
392
Arun Khandavallic811dcc2016-06-26 07:37:21 +0530393 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
394 if (!cds_ctx) {
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: Trying to open CDS without a PreOpen", __func__);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530397 QDF_ASSERT(0);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530398 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800399 }
400
401 /* Initialize the timer module */
Anurag Chouhan210db072016-02-22 18:42:15 +0530402 qdf_timer_module_init();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800403
404 /* Initialize bug reporting structure */
405 cds_init_log_completion();
406
407 /* Initialize the probe event */
Anurag Chouhance0dc992016-02-16 18:18:03 +0530408 if (qdf_event_create(&gp_cds_context->ProbeEvent) != QDF_STATUS_SUCCESS) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530409 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800410 "%s: Unable to init probeEvent", __func__);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530411 QDF_ASSERT(0);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530412 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800413 }
Anurag Chouhance0dc992016-02-16 18:18:03 +0530414 if (qdf_event_create(&(gp_cds_context->wmaCompleteEvent)) !=
415 QDF_STATUS_SUCCESS) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530416 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800417 "%s: Unable to init wmaCompleteEvent", __func__);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530418 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800419 goto err_probe_event;
420 }
421
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800422 pHddCtx = (hdd_context_t *) (gp_cds_context->pHDDContext);
423 if ((NULL == pHddCtx) || (NULL == pHddCtx->config)) {
424 /* Critical Error ... Cannot proceed further */
Arun Khandavallifae92942016-08-01 13:31:08 +0530425 cds_err("Hdd Context is Null");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530426 QDF_ASSERT(0);
Rajeev Kumar3e5ef0d2017-01-03 14:45:31 -0800427 goto err_wma_complete_event;
Arun Khandavallifae92942016-08-01 13:31:08 +0530428 }
Kabilan Kannan15cc6ac2016-11-12 22:25:14 -0800429
Arun Khandavallifae92942016-08-01 13:31:08 +0530430 /* Now Open the CDS Scheduler */
431
Prashanth Bhatta2ac92bd2016-10-11 16:08:00 -0700432 if (pHddCtx->driver_status == DRIVER_MODULES_UNINITIALIZED ||
433 cds_is_driver_recovering()) {
Arun Khandavallifae92942016-08-01 13:31:08 +0530434 qdf_status = cds_sched_open(gp_cds_context,
435 &gp_cds_context->qdf_sched,
436 sizeof(cds_sched_context));
437
438 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
439 /* Critical Error ... Cannot proceed further */
440 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_FATAL,
441 "%s: Failed to open CDS Scheduler", __func__);
442 QDF_ASSERT(0);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -0800443 goto err_wma_complete_event;
Arun Khandavallifae92942016-08-01 13:31:08 +0530444 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800445 }
446
Anurag Chouhan6d760662016-02-20 16:05:43 +0530447 scn = cds_get_context(QDF_MODULE_ID_HIF);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800448 if (!scn) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530449 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800450 "%s: scn is null!", __func__);
451 goto err_sched_close;
452 }
Arun Khandavallifae92942016-08-01 13:31:08 +0530453
Arun Khandavallifae92942016-08-01 13:31:08 +0530454 cds_cfg = cds_get_ini_config();
455 if (!cds_cfg) {
456 cds_err("Cds config is NULL");
457 QDF_ASSERT(0);
458 goto err_sched_close;
459 }
460 hdd_enable_fastpath(pHddCtx->config, scn);
461 hdd_wlan_update_target_info(pHddCtx, scn);
462
Anurag Chouhan6d760662016-02-20 16:05:43 +0530463 ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800464 /* Initialize BMI and Download firmware */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530465 qdf_status = bmi_download_firmware(ol_ctx);
466 if (qdf_status != QDF_STATUS_SUCCESS) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530467 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_FATAL,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530468 "BMI FIALED status:%d", qdf_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800469 goto err_bmi_close;
470 }
Komal Seelam08633492016-02-24 18:05:07 +0530471 htcInfo.pContext = ol_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800472 htcInfo.TargetFailure = ol_target_failure;
Mukul Sharma4c60a7e2017-03-06 19:42:18 +0530473 htcInfo.TargetSendSuspendComplete =
474 pmo_ucfg_psoc_target_suspend_acknowledge;
475 htcInfo.target_initial_wakeup_cb = pmo_ucfg_psoc_handle_initial_wake_up;
476 htcInfo.target_psoc = (void *)psoc;
Anurag Chouhan6d760662016-02-20 16:05:43 +0530477 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800478
479 /* Create HTC */
480 gp_cds_context->htc_ctx =
Yue Ma1e11d792016-02-26 18:58:44 -0800481 htc_create(scn, &htcInfo, qdf_ctx, cds_get_conparam());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800482 if (!gp_cds_context->htc_ctx) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530483 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800484 "%s: Failed to Create HTC", __func__);
485 goto err_bmi_close;
486 }
Mukul Sharma4c60a7e2017-03-06 19:42:18 +0530487 pmo_ucfg_psoc_update_htc_handle(psoc, (void *)gp_cds_context->htc_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800488
Komal Seelamd9106492016-02-15 10:31:44 +0530489 if (bmi_done(ol_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530490 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800491 "%s: Failed to complete BMI phase", __func__);
492 goto err_htc_close;
493 }
494
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800495 /*Open the WMA module */
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +0530496 qdf_status = wma_open(psoc, gp_cds_context,
Arif Hussaincd151632017-02-11 16:57:19 -0800497 hdd_update_tgt_cfg, cds_cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800498
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530499 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800500 /* Critical Error ... Cannot proceed further */
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530501 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800502 "%s: Failed to open WMA module", __func__);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530503 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800504 goto err_htc_close;
505 }
506
507 /* Number of peers limit differs in each chip version. If peer max
508 * limit configured in ini exceeds more than supported, WMA adjusts
Arun Khandavallic811dcc2016-06-26 07:37:21 +0530509 * and keeps correct limit in cds_cfg.max_station. So, make sure
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800510 * config entry pHddCtx->config->maxNumberOfPeers has adjusted value
511 */
Hanumanth Reddy Pothula47d29262016-10-03 16:08:04 +0530512 /* In FTM mode cds_cfg->max_stations will be zero. On updating same
513 * into hdd context config entry, leads to pe_open() to fail, if
514 * con_mode change happens from FTM mode to any other mode.
515 */
516 if (DRIVER_TYPE_PRODUCTION == cds_cfg->driver_type)
517 pHddCtx->config->maxNumberOfPeers = cds_cfg->max_station;
518
Anurag Chouhan6d760662016-02-20 16:05:43 +0530519 HTCHandle = cds_get_context(QDF_MODULE_ID_HTC);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800520 if (!HTCHandle) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530521 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800522 "%s: HTCHandle is null!", __func__);
523 goto err_wma_close;
524 }
525 if (htc_wait_target(HTCHandle)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530526 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800527 "%s: Failed to complete BMI phase", __func__);
528 goto err_wma_close;
529 }
Poddar, Siddarthef1f3022016-05-10 20:10:43 +0530530 bmi_target_ready(scn, gp_cds_context->cfg_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800531
Ravi Joshifc2ed782016-11-22 17:36:50 -0800532 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_DEBUG,
533 "%s: target_type %d 8074:%d 6290:%d",
534 __func__, pHddCtx->target_type,
535 TARGET_TYPE_QCA8074, TARGET_TYPE_QCA6290);
536
537 if (TARGET_TYPE_QCA6290 == pHddCtx->target_type)
Leo Chang9b097032016-10-28 11:03:17 -0700538 gp_cds_context->dp_soc = cdp_soc_attach(LITHIUM_DP,
539 gp_cds_context->pHIFContext, scn,
540 gp_cds_context->htc_ctx, gp_cds_context->qdf_ctx,
Pramod Simha0d3b9362017-03-27 14:59:58 -0700541 &dp_ol_if_ops, psoc);
Leo Chang9b097032016-10-28 11:03:17 -0700542 else
543 gp_cds_context->dp_soc = cdp_soc_attach(MOB_DRV_LEGACY_DP,
544 gp_cds_context->pHIFContext, scn,
545 gp_cds_context->htc_ctx, gp_cds_context->qdf_ctx,
Pramod Simha0d3b9362017-03-27 14:59:58 -0700546 &dp_ol_if_ops, psoc);
Leo Chang9b097032016-10-28 11:03:17 -0700547
Sravan Kumar Kairam27296782017-04-21 22:04:18 +0530548 pmo_ucfg_psoc_update_dp_handle(psoc, gp_cds_context->dp_soc);
549
gbian62edd7e2017-03-07 13:12:13 +0800550 cds_set_ac_specs_params(cds_cfg);
551
Leo Chang9b097032016-10-28 11:03:17 -0700552 cds_cdp_cfg_attach(cds_cfg);
553
Jeff Johnsond9f08602016-12-02 11:31:30 -0800554 /* Now proceed to open the MAC */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800555 sirStatus =
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +0530556 mac_open(psoc, &(gp_cds_context->pMACContext),
Arun Khandavallic811dcc2016-06-26 07:37:21 +0530557 gp_cds_context->pHDDContext, cds_cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800558
559 if (eSIR_SUCCESS != sirStatus) {
560 /* Critical Error ... Cannot proceed further */
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530561 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800562 "%s: Failed to open MAC", __func__);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530563 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800564 goto err_wma_close;
565 }
566
567 /* Now proceed to open the SME */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530568 qdf_status = sme_open(gp_cds_context->pMACContext);
569 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800570 /* Critical Error ... Cannot proceed further */
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530571 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800572 "%s: Failed to open SME", __func__);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530573 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800574 goto err_mac_close;
575 }
Houston Hoffman57c36d72017-01-30 12:47:02 -0800576 cds_set_context(QDF_MODULE_ID_TXRX,
Leo Chang9b097032016-10-28 11:03:17 -0700577 cdp_pdev_attach(cds_get_context(QDF_MODULE_ID_SOC),
578 gp_cds_context->cfg_ctx,
579 gp_cds_context->htc_ctx,
Houston Hoffman57c36d72017-01-30 12:47:02 -0800580 gp_cds_context->qdf_ctx, 0));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800581 if (!gp_cds_context->pdev_txrx_ctx) {
582 /* Critical Error ... Cannot proceed further */
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530583 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800584 "%s: Failed to open TXRX", __func__);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530585 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800586 goto err_sme_close;
587 }
Sravan Kumar Kairam27296782017-04-21 22:04:18 +0530588 pmo_ucfg_psoc_set_txrx_handle(psoc, gp_cds_context->pdev_txrx_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800589
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530590 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800591 "%s: CDS successfully Opened", __func__);
Krunal Sonid32c6bc2016-10-18 18:00:21 -0700592 cds_register_all_modules();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800593
Selvaraj, Sridhara7dc2382017-01-27 18:29:39 +0530594 return dispatcher_psoc_open(psoc);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800595
596err_sme_close:
597 sme_close(gp_cds_context->pMACContext);
598
599err_mac_close:
600 mac_close(gp_cds_context->pMACContext);
601
602err_wma_close:
Rajeev Kumar662d75d2017-03-13 18:11:29 -0700603 cds_shutdown_notifier_purge();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800604 wma_close(gp_cds_context);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800605 wma_wmi_service_close(gp_cds_context);
Sravan Kumar Kairam27296782017-04-21 22:04:18 +0530606 pmo_ucfg_psoc_update_dp_handle(psoc, NULL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800607
608err_htc_close:
609 if (gp_cds_context->htc_ctx) {
610 htc_destroy(gp_cds_context->htc_ctx);
611 gp_cds_context->htc_ctx = NULL;
Sravan Kumar Kairam27296782017-04-21 22:04:18 +0530612 pmo_ucfg_psoc_update_htc_handle(psoc, NULL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800613 }
614
615err_bmi_close:
Komal Seelam5a6e5082016-02-24 17:59:09 +0530616 bmi_cleanup(ol_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800617
618err_sched_close:
619 cds_sched_close(gp_cds_context);
620
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800621err_wma_complete_event:
Anurag Chouhance0dc992016-02-16 18:18:03 +0530622 qdf_event_destroy(&gp_cds_context->wmaCompleteEvent);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800623
624err_probe_event:
Anurag Chouhance0dc992016-02-16 18:18:03 +0530625 qdf_event_destroy(&gp_cds_context->ProbeEvent);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800626
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530627 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800628} /* cds_open() */
629
630/**
631 * cds_pre_enable() - pre enable cds
632 * @cds_context: CDS context
633 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530634 * Return: QDF status
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800635 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530636QDF_STATUS cds_pre_enable(v_CONTEXT_t cds_context)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800637{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530638 QDF_STATUS qdf_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800639 p_cds_contextType p_cds_context = (p_cds_contextType) cds_context;
640 void *scn;
Leo Chang9b097032016-10-28 11:03:17 -0700641 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800642
Srinivas Girigowdad395b892017-03-09 19:29:42 -0800643 QDF_TRACE(QDF_MODULE_ID_SYS, QDF_TRACE_LEVEL_DEBUG, "cds prestart");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800644 if (gp_cds_context != p_cds_context) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530645 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800646 "%s: Context mismatch", __func__);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530647 QDF_ASSERT(0);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530648 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800649 }
650
651 if (p_cds_context->pMACContext == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530652 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800653 "%s: MAC NULL context", __func__);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530654 QDF_ASSERT(0);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530655 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800656 }
657
658 if (p_cds_context->pWMAContext == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530659 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800660 "%s: WMA NULL context", __func__);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530661 QDF_ASSERT(0);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530662 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800663 }
664
Anurag Chouhan6d760662016-02-20 16:05:43 +0530665 scn = cds_get_context(QDF_MODULE_ID_HIF);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800666 if (!scn) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530667 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800668 "%s: scn is null!", __func__);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530669 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800670 }
671
Nirav Shah7f337db2016-05-25 10:49:02 +0530672 /* call Packetlog connect service */
Arun Khandavallifae92942016-08-01 13:31:08 +0530673 if (QDF_GLOBAL_FTM_MODE != cds_get_conparam() &&
Leo Chang9b097032016-10-28 11:03:17 -0700674 QDF_GLOBAL_EPPING_MODE != cds_get_conparam())
675 cdp_pkt_log_con_service(soc,
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -0800676 gp_cds_context->pdev_txrx_ctx,
677 scn);
Nirav Shah7f337db2016-05-25 10:49:02 +0530678
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800679 /* Reset wma wait event */
Anurag Chouhance0dc992016-02-16 18:18:03 +0530680 qdf_event_reset(&gp_cds_context->wmaCompleteEvent);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800681
682 /*call WMA pre start */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530683 qdf_status = wma_pre_start(gp_cds_context);
684 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530685 QDF_TRACE(QDF_MODULE_ID_SYS, QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800686 "Failed to WMA prestart");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530687 QDF_ASSERT(0);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530688 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800689 }
690
691 /* Need to update time out of complete */
Anurag Chouhance0dc992016-02-16 18:18:03 +0530692 qdf_status = qdf_wait_single_event(&gp_cds_context->wmaCompleteEvent,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800693 CDS_WMA_TIMEOUT);
Anurag Chouhance0dc992016-02-16 18:18:03 +0530694 if (qdf_status != QDF_STATUS_SUCCESS) {
695 if (qdf_status == QDF_STATUS_E_TIMEOUT) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530696 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800697 "%s: Timeout occurred before WMA complete",
698 __func__);
699 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530700 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800701 "%s: wma_pre_start reporting other error",
702 __func__);
703 }
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530704 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800705 "%s: Test MC thread by posting a probe message to SYS",
706 __func__);
707 wlan_sys_probe();
708
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530709 QDF_ASSERT(0);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530710 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800711 }
712
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530713 qdf_status = htc_start(gp_cds_context->htc_ctx);
714 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530715 QDF_TRACE(QDF_MODULE_ID_SYS, QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800716 "Failed to Start HTC");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530717 QDF_ASSERT(0);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530718 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800719 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530720 qdf_status = wma_wait_for_ready_event(gp_cds_context->pWMAContext);
721 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530722 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800723 "Failed to get ready event from target firmware");
Naveen Rawat91df30a2016-10-12 21:26:18 -0700724 /*
725 * Panic only if recovery is disabled, else return failure so
726 * that driver load can fail gracefully. We cannot trigger self
727 * recovery here because driver is not fully loaded yet.
728 */
729 if (!cds_is_self_recovery_enabled())
730 QDF_BUG(0);
731
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800732 htc_stop(gp_cds_context->htc_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530733 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800734 }
735
Leo Chang9b097032016-10-28 11:03:17 -0700736 if (cdp_pdev_post_attach(soc, gp_cds_context->pdev_txrx_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530737 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800738 "Failed to attach pdev");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800739 htc_stop(gp_cds_context->htc_ctx);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530740 QDF_ASSERT(0);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530741 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800742 }
743
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530744 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800745}
746
747/**
748 * cds_enable() - start/enable cds module
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +0530749 * @psoc: Psoc pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800750 * @cds_context: CDS context
751 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530752 * Return: QDF status
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800753 */
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +0530754QDF_STATUS cds_enable(struct wlan_objmgr_psoc *psoc, v_CONTEXT_t cds_context)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800755{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530756 QDF_STATUS qdf_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800757 tSirRetStatus sirStatus = eSIR_SUCCESS;
758 p_cds_contextType p_cds_context = (p_cds_contextType) cds_context;
759 tHalMacStartParameters halStartParams;
760
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800761 /* We support only one instance for now ... */
762 if (gp_cds_context != p_cds_context) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530763 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800764 "%s: mismatch in context", __func__);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530765 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800766 }
767
768 if ((p_cds_context->pWMAContext == NULL) ||
769 (p_cds_context->pMACContext == NULL)) {
770 if (p_cds_context->pWMAContext == NULL)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530771 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800772 "%s: WMA NULL context", __func__);
773 else
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530774 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800775 "%s: MAC NULL context", __func__);
776
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530777 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800778 }
779
780 /* Start the wma */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530781 qdf_status = wma_start(p_cds_context);
782 if (qdf_status != QDF_STATUS_SUCCESS) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530783 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800784 "%s: Failed to start wma", __func__);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530785 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800786 }
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530787 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800788 "%s: wma correctly started", __func__);
789
790 /* Start the MAC */
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530791 qdf_mem_zero(&halStartParams,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800792 sizeof(tHalMacStartParameters));
793
794 /* Start the MAC */
795 sirStatus =
796 mac_start(p_cds_context->pMACContext, &halStartParams);
797
798 if (eSIR_SUCCESS != sirStatus) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530799 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800800 "%s: Failed to start MAC", __func__);
801 goto err_wma_stop;
802 }
803
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530804 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800805 "%s: MAC correctly started", __func__);
806
807 /* START SME */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530808 qdf_status = sme_start(p_cds_context->pMACContext);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800809
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530810 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530811 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800812 "%s: Failed to start SME", __func__);
813 goto err_mac_stop;
814 }
815
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530816 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800817 "%s: SME correctly started", __func__);
818
Leo Chang9b097032016-10-28 11:03:17 -0700819 if (cdp_soc_attach_target(cds_get_context(QDF_MODULE_ID_SOC))) {
820 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_FATAL,
821 "%s: Failed to attach soc target", __func__);
822 goto err_sme_stop;
823 }
824
825 if (cdp_pdev_attach_target(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -0800826 (struct cdp_pdev *)cds_get_context(QDF_MODULE_ID_TXRX))) {
Leo Chang9b097032016-10-28 11:03:17 -0700827 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_FATAL,
828 "%s: Failed to attach pdev target", __func__);
829 goto err_soc_target_detach;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800830 }
831
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530832 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800833 "%s: CDS Start is successful!!", __func__);
834
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +0530835 dispatcher_psoc_enable(psoc);
Rajeev Kumar97767a02016-11-30 11:20:40 -0800836
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530837 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800838
Leo Chang9b097032016-10-28 11:03:17 -0700839err_soc_target_detach:
840 /* NOOP */
841
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800842err_sme_stop:
843 sme_stop(p_cds_context->pMACContext, HAL_STOP_TYPE_SYS_RESET);
844
845err_mac_stop:
846 mac_stop(p_cds_context->pMACContext, HAL_STOP_TYPE_SYS_RESET);
847
848err_wma_stop:
Anurag Chouhance0dc992016-02-16 18:18:03 +0530849 qdf_event_reset(&(gp_cds_context->wmaCompleteEvent));
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530850 qdf_status = wma_stop(p_cds_context, HAL_STOP_TYPE_RF_KILL);
851 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530852 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800853 "%s: Failed to stop wma", __func__);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530854 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800855 wma_setneedshutdown(cds_context);
856 } else {
Anurag Chouhance0dc992016-02-16 18:18:03 +0530857 qdf_status =
858 qdf_wait_single_event(&(gp_cds_context->wmaCompleteEvent),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800859 CDS_WMA_TIMEOUT);
Anurag Chouhance0dc992016-02-16 18:18:03 +0530860 if (qdf_status != QDF_STATUS_SUCCESS) {
861 if (qdf_status == QDF_STATUS_E_TIMEOUT) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530862 QDF_TRACE(QDF_MODULE_ID_QDF,
863 QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800864 "%s: Timeout occurred before WMA_stop complete",
865 __func__);
866 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530867 QDF_TRACE(QDF_MODULE_ID_QDF,
868 QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800869 "%s: WMA_stop reporting other error",
870 __func__);
871 }
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530872 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800873 wma_setneedshutdown(cds_context);
874 }
875 }
876
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530877 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800878} /* cds_enable() */
879
880/**
881 * cds_disable() - stop/disable cds module
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +0530882 * @psoc: Psoc pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800883 * @cds_context: CDS context
884 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530885 * Return: QDF status
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800886 */
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +0530887QDF_STATUS cds_disable(struct wlan_objmgr_psoc *psoc, v_CONTEXT_t cds_context)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800888{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530889 QDF_STATUS qdf_status;
Arun Khandavallifae92942016-08-01 13:31:08 +0530890 void *handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800891
Rajeev Kumar97767a02016-11-30 11:20:40 -0800892 /* PSOC disable for all new components. It needs to happen before
893 * target is PDEV suspended such that a component can abort all its
894 * ongoing transaction with FW. Always keep it before wma_stop() as
895 * wma_stop() does target PDEV suspend.
896 */
Rajeev Kumar97767a02016-11-30 11:20:40 -0800897
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +0530898 dispatcher_psoc_disable(psoc);
Rajeev Kumar97767a02016-11-30 11:20:40 -0800899
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530900 qdf_status = wma_stop(cds_context, HAL_STOP_TYPE_RF_KILL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800901
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530902 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Arun Khandavallifae92942016-08-01 13:31:08 +0530903 cds_err("Failed to stop wma");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530904 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800905 wma_setneedshutdown(cds_context);
906 }
907
Arun Khandavallifae92942016-08-01 13:31:08 +0530908 handle = cds_get_context(QDF_MODULE_ID_PE);
909 if (!handle) {
910 cds_err("Invalid PE context return!");
911 return QDF_STATUS_E_INVAL;
912 }
913 qdf_status = sme_stop(handle, HAL_STOP_TYPE_SYS_DEEP_SLEEP);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530914 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Arun Khandavallifae92942016-08-01 13:31:08 +0530915 cds_err("Failed to stop SME: %d", qdf_status);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530916 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800917 }
Arun Khandavallifae92942016-08-01 13:31:08 +0530918 qdf_status = mac_stop(handle, HAL_STOP_TYPE_SYS_DEEP_SLEEP);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800919
Arun Khandavallifae92942016-08-01 13:31:08 +0530920 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
921 cds_err("Failed to stop MAC");
922 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
923 }
Arun Khandavalli55f890b2016-08-31 18:14:56 +0530924
Arun Khandavallifae92942016-08-01 13:31:08 +0530925 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800926}
927
Govind Singhb048e872016-09-27 22:07:43 +0530928#ifdef HIF_USB
929static inline void cds_suspend_target(tp_wma_handle wma_handle)
930{
931 QDF_STATUS status;
932 /* Suspend the target and disable interrupt */
Mukul Sharma4c60a7e2017-03-06 19:42:18 +0530933 status = pmo_ucfg_psoc_suspend_target(wma_handle->psoc, 0);
Govind Singhb048e872016-09-27 22:07:43 +0530934 if (status)
935 cds_err("Failed to suspend target, status = %d", status);
936}
937#else
938static inline void cds_suspend_target(tp_wma_handle wma_handle)
939{
940 QDF_STATUS status;
941 /* Suspend the target and disable interrupt */
Mukul Sharma4c60a7e2017-03-06 19:42:18 +0530942 status = pmo_ucfg_psoc_suspend_target(wma_handle->psoc, 1);
Govind Singhb048e872016-09-27 22:07:43 +0530943 if (status)
944 cds_err("Failed to suspend target, status = %d", status);
945}
946#endif /* HIF_USB */
947
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800948/**
Govind Singhb048e872016-09-27 22:07:43 +0530949 * cds_post_disable() - post disable cds module
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800950 * @cds_context: CDS context
951 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530952 * Return: QDF status
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800953 */
Govind Singhb048e872016-09-27 22:07:43 +0530954QDF_STATUS cds_post_disable(v_CONTEXT_t cds_context)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800955{
Arun Khandavalli55f890b2016-08-31 18:14:56 +0530956 tp_wma_handle wma_handle;
Govind Singhb048e872016-09-27 22:07:43 +0530957 struct hif_opaque_softc *hif_ctx;
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +0530958 struct cdp_pdev *txrx_pdev;
959
Arun Khandavalli55f890b2016-08-31 18:14:56 +0530960 wma_handle = cds_get_context(QDF_MODULE_ID_WMA);
961 if (!wma_handle) {
962 cds_err("Failed to get wma_handle!");
963 return QDF_STATUS_E_INVAL;
964 }
965
Govind Singhb048e872016-09-27 22:07:43 +0530966 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
967 if (!hif_ctx) {
968 cds_err("Failed to get hif_handle!");
969 return QDF_STATUS_E_INVAL;
970 }
971
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +0530972 txrx_pdev = cds_get_context(QDF_MODULE_ID_TXRX);
973 if (!txrx_pdev) {
974 cds_err("Failed to get txrx pdev!");
975 return QDF_STATUS_E_INVAL;
976 }
977
Arun Khandavalli55f890b2016-08-31 18:14:56 +0530978 /*
979 * With new state machine changes cds_close can be invoked without
980 * cds_disable. So, send the following clean up prerequisites to fw,
981 * So Fw and host are in sync for cleanup indication:
982 * - Send PDEV_SUSPEND indication to firmware
983 * - Disable HIF Interrupts.
984 * - Clean up CE tasklets.
985 */
986
Govind Singhb048e872016-09-27 22:07:43 +0530987 cds_info("send denint sequence to firmware");
988 if (!cds_is_driver_recovering())
989 cds_suspend_target(wma_handle);
990 hif_disable_isr(hif_ctx);
991 hif_reset_soc(hif_ctx);
992
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +0530993 cdp_pdev_pre_detach(cds_get_context(QDF_MODULE_ID_SOC),
994 (struct cdp_pdev *)txrx_pdev, 1);
995
Govind Singhb048e872016-09-27 22:07:43 +0530996 return QDF_STATUS_SUCCESS;
997}
998
999/**
1000 * cds_close() - close cds module
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301001 * @psoc: Psoc pointer
Govind Singhb048e872016-09-27 22:07:43 +05301002 * @cds_context: CDS context
1003 *
1004 * This API allows user to close modules registered
1005 * with connectivity device services.
1006 *
1007 * Return: QDF status
1008 */
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301009QDF_STATUS cds_close(struct wlan_objmgr_psoc *psoc, v_CONTEXT_t cds_context)
Govind Singhb048e872016-09-27 22:07:43 +05301010{
1011 QDF_STATUS qdf_status;
Houston Hoffmane5ec0492017-01-30 12:28:32 -08001012 void *ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001013
Amar Singhal966397f2017-04-06 18:28:56 -07001014 dispatcher_psoc_close(psoc);
1015
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301016 qdf_status = wma_wmi_work_close(cds_context);
1017 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301018 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Xun Luoa858a472015-11-10 08:24:45 -08001019 "%s: Failed to close wma_wmi_work", __func__);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301020 QDF_ASSERT(0);
Xun Luoa858a472015-11-10 08:24:45 -08001021 }
1022
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001023 if (gp_cds_context->htc_ctx) {
1024 htc_stop(gp_cds_context->htc_ctx);
1025 htc_destroy(gp_cds_context->htc_ctx);
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301026 pmo_ucfg_psoc_update_htc_handle(psoc, NULL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001027 gp_cds_context->htc_ctx = NULL;
1028 }
1029
Houston Hoffmane5ec0492017-01-30 12:28:32 -08001030 ctx = cds_get_context(QDF_MODULE_ID_TXRX);
1031 cds_set_context(QDF_MODULE_ID_TXRX, NULL);
Sravan Kumar Kairam27296782017-04-21 22:04:18 +05301032 pmo_ucfg_psoc_set_txrx_handle(psoc, NULL);
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08001033 cdp_pdev_detach(cds_get_context(QDF_MODULE_ID_SOC),
1034 (struct cdp_pdev *)ctx, 1);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001035
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301036 qdf_status = sme_close(((p_cds_contextType) cds_context)->pMACContext);
1037 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301038 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001039 "%s: Failed to close SME", __func__);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301040 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001041 }
1042
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301043 qdf_status = mac_close(((p_cds_contextType) cds_context)->pMACContext);
1044 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301045 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001046 "%s: Failed to close MAC", __func__);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301047 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001048 }
1049
1050 ((p_cds_contextType) cds_context)->pMACContext = NULL;
1051
Houston Hoffmanbe58cc52016-12-19 16:26:44 -08001052 cdp_soc_detach(gp_cds_context->dp_soc);
Sravan Kumar Kairam27296782017-04-21 22:04:18 +05301053 pmo_ucfg_psoc_update_dp_handle(psoc, NULL);
Houston Hoffmanbe58cc52016-12-19 16:26:44 -08001054
Rajeev Kumar662d75d2017-03-13 18:11:29 -07001055 cds_shutdown_notifier_purge();
1056
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001057 if (true == wma_needshutdown(cds_context)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301058 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001059 "%s: Failed to shutdown wma", __func__);
1060 } else {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301061 qdf_status = wma_close(cds_context);
1062 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301063 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001064 "%s: Failed to close wma", __func__);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301065 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001066 }
1067 }
1068
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301069 qdf_status = wma_wmi_service_close(cds_context);
1070 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301071 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001072 "%s: Failed to close wma_wmi_service", __func__);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301073 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001074 }
1075
Anurag Chouhance0dc992016-02-16 18:18:03 +05301076 qdf_status = qdf_event_destroy(&gp_cds_context->wmaCompleteEvent);
1077 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301078 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001079 "%s: failed to destroy wmaCompleteEvent", __func__);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301080 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001081 }
1082
Anurag Chouhance0dc992016-02-16 18:18:03 +05301083 qdf_status = qdf_event_destroy(&gp_cds_context->ProbeEvent);
1084 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
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: failed to destroy ProbeEvent", __func__);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301087 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001088 }
1089
1090 cds_deinit_log_completion();
Arun Khandavallic811dcc2016-06-26 07:37:21 +05301091 cds_deinit_ini_config();
Arun Khandavallifae92942016-08-01 13:31:08 +05301092 qdf_timer_module_deinit();
1093
Krunal Sonid32c6bc2016-10-18 18:00:21 -07001094 cds_deregister_all_modules();
Rajeev Kumar97767a02016-11-30 11:20:40 -08001095
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301096 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001097}
1098
1099/**
1100 * cds_get_context() - get context data area
1101 *
1102 * @moduleId: ID of the module who's context data is being retrived.
1103 *
1104 * Each module in the system has a context / data area that is allocated
1105 * and managed by CDS. This API allows any user to get a pointer to its
1106 * allocated context data area from the CDS global context.
1107 *
1108 * Return: pointer to the context data area of the module ID
1109 * specified, or NULL if the context data is not allocated for
1110 * the module ID specified
1111 */
Anurag Chouhan6d760662016-02-20 16:05:43 +05301112void *cds_get_context(QDF_MODULE_ID moduleId)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001113{
1114 void *pModContext = NULL;
1115
1116 if (gp_cds_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301117 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001118 "%s: cds context pointer is null", __func__);
1119 return NULL;
1120 }
1121
1122 switch (moduleId) {
Anurag Chouhan6d760662016-02-20 16:05:43 +05301123 case QDF_MODULE_ID_HDD:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001124 {
1125 pModContext = gp_cds_context->pHDDContext;
1126 break;
1127 }
1128
Anurag Chouhan6d760662016-02-20 16:05:43 +05301129 case QDF_MODULE_ID_SME:
1130 case QDF_MODULE_ID_PE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001131 {
1132 /* In all these cases, we just return the MAC Context */
1133 pModContext = gp_cds_context->pMACContext;
1134 break;
1135 }
1136
Anurag Chouhan6d760662016-02-20 16:05:43 +05301137 case QDF_MODULE_ID_WMA:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001138 {
1139 /* For wma module */
1140 pModContext = gp_cds_context->pWMAContext;
1141 break;
1142 }
1143
Anurag Chouhan6d760662016-02-20 16:05:43 +05301144 case QDF_MODULE_ID_QDF:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001145 {
1146 /* For SYS this is CDS itself */
1147 pModContext = gp_cds_context;
1148 break;
1149 }
1150
Anurag Chouhan6d760662016-02-20 16:05:43 +05301151 case QDF_MODULE_ID_HIF:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001152 {
1153 pModContext = gp_cds_context->pHIFContext;
1154 break;
1155 }
1156
Anurag Chouhan6d760662016-02-20 16:05:43 +05301157 case QDF_MODULE_ID_HTC:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001158 {
1159 pModContext = gp_cds_context->htc_ctx;
1160 break;
1161 }
1162
Anurag Chouhan6d760662016-02-20 16:05:43 +05301163 case QDF_MODULE_ID_QDF_DEVICE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001164 {
Anurag Chouhan6d760662016-02-20 16:05:43 +05301165 pModContext = gp_cds_context->qdf_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001166 break;
1167 }
1168
Anurag Chouhan6d760662016-02-20 16:05:43 +05301169 case QDF_MODULE_ID_BMI:
Komal Seelamd9106492016-02-15 10:31:44 +05301170 {
1171 pModContext = gp_cds_context->g_ol_context;
1172 break;
1173 }
1174
Anurag Chouhan6d760662016-02-20 16:05:43 +05301175 case QDF_MODULE_ID_TXRX:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001176 {
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08001177 pModContext = (void *)gp_cds_context->pdev_txrx_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001178 break;
1179 }
1180
Anurag Chouhan6d760662016-02-20 16:05:43 +05301181 case QDF_MODULE_ID_CFG:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001182 {
1183 pModContext = gp_cds_context->cfg_ctx;
1184 break;
1185 }
1186
Leo Chang9b097032016-10-28 11:03:17 -07001187 case QDF_MODULE_ID_SOC:
1188 {
1189 pModContext = gp_cds_context->dp_soc;
1190 break;
1191 }
1192
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001193 default:
1194 {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301195 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001196 "%s: Module ID %i does not have its context maintained by CDS",
1197 __func__, moduleId);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301198 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001199 return NULL;
1200 }
1201 }
1202
1203 if (pModContext == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301204 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001205 "%s: Module ID %i context is Null", __func__,
1206 moduleId);
1207 }
1208
1209 return pModContext;
1210} /* cds_get_context() */
1211
1212/**
1213 * cds_get_global_context() - get CDS global Context
1214 *
1215 * This API allows any user to get the CDS Global Context pointer from a
1216 * module context data area.
1217 *
1218 * Return: pointer to the CDS global context, NULL if the function is
1219 * unable to retreive the CDS context.
1220 */
1221v_CONTEXT_t cds_get_global_context(void)
1222{
1223 if (gp_cds_context == NULL) {
Ryan Hsuceddceb2016-04-28 10:20:14 -07001224 /*
1225 * To avoid recursive call, this should not change to
1226 * QDF_TRACE().
1227 */
1228 pr_err("%s: global cds context is NULL", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001229 }
1230
1231 return gp_cds_context;
1232} /* cds_get_global_context() */
1233
1234/**
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001235 * cds_get_driver_state() - Get current driver state
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001236 *
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001237 * This API returns current driver state stored in global context.
1238 *
1239 * Return: Driver state enum
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001240 */
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001241enum cds_driver_state cds_get_driver_state(void)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001242{
1243 if (gp_cds_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301244 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001245 "%s: global cds context is NULL", __func__);
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001246
1247 return CDS_DRIVER_STATE_UNINITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001248 }
1249
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001250 return gp_cds_context->driver_state;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001251}
1252
1253/**
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001254 * cds_set_driver_state() - Set current driver state
1255 * @state: Driver state to be set to.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001256 *
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001257 * This API sets driver state to state. This API only sets the state and doesn't
1258 * clear states, please make sure to use cds_clear_driver_state to clear any
1259 * state if required.
1260 *
1261 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001262 */
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001263void cds_set_driver_state(enum cds_driver_state state)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001264{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001265 if (gp_cds_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301266 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001267 "%s: global cds context is NULL: %x", __func__,
1268 state);
1269
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001270 return;
1271 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001272
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001273 gp_cds_context->driver_state |= state;
1274}
1275
1276/**
1277 * cds_clear_driver_state() - Clear current driver state
1278 * @state: Driver state to be cleared.
1279 *
1280 * This API clears driver state. This API only clears the state, please make
1281 * sure to use cds_set_driver_state to set any new states.
1282 *
1283 * Return: None
1284 */
1285void cds_clear_driver_state(enum cds_driver_state state)
1286{
1287 if (gp_cds_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301288 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001289 "%s: global cds context is NULL: %x", __func__,
1290 state);
1291
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001292 return;
1293 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001294
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001295 gp_cds_context->driver_state &= ~state;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001296}
1297
1298/**
1299 * cds_alloc_context() - allocate a context within the CDS global Context
1300 * @p_cds_context: pointer to the global Vos context
1301 * @moduleId: module ID who's context area is being allocated.
1302 * @ppModuleContext: pointer to location where the pointer to the
1303 * allocated context is returned. Note this output pointer
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301304 * is valid only if the API returns QDF_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001305 * @param size: size of the context area to be allocated.
1306 *
1307 * This API allows any user to allocate a user context area within the
1308 * CDS Global Context.
1309 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05301310 * Return: QDF status
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001311 */
Anurag Chouhan6d760662016-02-20 16:05:43 +05301312QDF_STATUS cds_alloc_context(void *p_cds_context, QDF_MODULE_ID moduleID,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001313 void **ppModuleContext, uint32_t size)
1314{
1315 void **pGpModContext = NULL;
1316
1317 if (p_cds_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301318 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001319 "%s: cds context is null", __func__);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301320 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001321 }
1322
1323 if ((gp_cds_context != p_cds_context) || (ppModuleContext == NULL)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301324 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001325 "%s: context mismatch or null param passed",
1326 __func__);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301327 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001328 }
1329
1330 switch (moduleID) {
Anurag Chouhan6d760662016-02-20 16:05:43 +05301331 case QDF_MODULE_ID_WMA:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001332 {
1333 pGpModContext = &(gp_cds_context->pWMAContext);
1334 break;
1335 }
1336
Anurag Chouhan6d760662016-02-20 16:05:43 +05301337 case QDF_MODULE_ID_HIF:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001338 {
1339 pGpModContext = &(gp_cds_context->pHIFContext);
1340 break;
1341 }
1342
Anurag Chouhan6d760662016-02-20 16:05:43 +05301343 case QDF_MODULE_ID_BMI:
Komal Seelamd9106492016-02-15 10:31:44 +05301344 {
1345 pGpModContext = &(gp_cds_context->g_ol_context);
1346 break;
1347 }
1348
Anurag Chouhan6d760662016-02-20 16:05:43 +05301349 case QDF_MODULE_ID_EPPING:
1350 case QDF_MODULE_ID_SME:
1351 case QDF_MODULE_ID_PE:
1352 case QDF_MODULE_ID_HDD:
1353 case QDF_MODULE_ID_HDD_SOFTAP:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001354 default:
1355 {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301356 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001357 "%s: Module ID %i "
1358 "does not have its context allocated by CDS",
1359 __func__, moduleID);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301360 QDF_ASSERT(0);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301361 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001362 }
1363 }
1364
1365 if (NULL != *pGpModContext) {
1366 /* Context has already been allocated!
1367 * Prevent double allocation
1368 */
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301369 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001370 "%s: Module ID %i context has already been allocated",
1371 __func__, moduleID);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301372 return QDF_STATUS_E_EXISTS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001373 }
1374
1375 /* Dynamically allocate the context for module */
1376
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301377 *ppModuleContext = qdf_mem_malloc(size);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001378
1379 if (*ppModuleContext == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301380 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001381 "%s: Failed to " "allocate Context for module ID %i",
1382 __func__, moduleID);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301383 QDF_ASSERT(0);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301384 return QDF_STATUS_E_NOMEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001385 }
1386
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001387 *pGpModContext = *ppModuleContext;
1388
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301389 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001390} /* cds_alloc_context() */
1391
1392/**
Komal Seelamad5a90d2016-02-16 13:50:03 +05301393 * cds_set_context() - API to set context in global CDS Context
Komal Seelam1aac1982016-03-02 15:57:26 +05301394 * @module_id: Module ID
Komal Seelamad5a90d2016-02-16 13:50:03 +05301395 * @context: Pointer to the Module Context
1396 *
Komal Seelam1aac1982016-03-02 15:57:26 +05301397 * API to set a MODULE Context in global CDS Context
Komal Seelamad5a90d2016-02-16 13:50:03 +05301398 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301399 * Return: QDF_STATUS
Komal Seelamad5a90d2016-02-16 13:50:03 +05301400 */
Anurag Chouhan6d760662016-02-20 16:05:43 +05301401QDF_STATUS cds_set_context(QDF_MODULE_ID module_id, void *context)
Komal Seelamad5a90d2016-02-16 13:50:03 +05301402{
1403 p_cds_contextType p_cds_context = cds_get_global_context();
1404
1405 if (!p_cds_context) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301406 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Komal Seelam1aac1982016-03-02 15:57:26 +05301407 "cds context is Invalid");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301408 return QDF_STATUS_NOT_INITIALIZED;
Komal Seelamad5a90d2016-02-16 13:50:03 +05301409 }
1410
1411 switch (module_id) {
Houston Hoffman57c36d72017-01-30 12:47:02 -08001412 case QDF_MODULE_ID_TXRX:
1413 p_cds_context->pdev_txrx_ctx = context;
1414 break;
Anurag Chouhan6d760662016-02-20 16:05:43 +05301415 case QDF_MODULE_ID_HIF:
Komal Seelamad5a90d2016-02-16 13:50:03 +05301416 p_cds_context->pHIFContext = context;
1417 break;
1418 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301419 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Komal Seelam1aac1982016-03-02 15:57:26 +05301420 "%s: Module ID %i does not have its context managed by CDS",
1421 __func__, module_id);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301422 QDF_ASSERT(0);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301423 return QDF_STATUS_E_INVAL;
Komal Seelamad5a90d2016-02-16 13:50:03 +05301424 }
1425
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301426 return QDF_STATUS_SUCCESS;
Komal Seelamad5a90d2016-02-16 13:50:03 +05301427}
1428
1429/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001430 * cds_free_context() - free an allocated context within the
1431 * CDS global Context
1432 * @p_cds_context: pointer to the global Vos context
1433 * @moduleId: module ID who's context area is being free
1434 * @pModuleContext: pointer to module context area to be free'd.
1435 *
1436 * This API allows a user to free the user context area within the
1437 * CDS Global Context.
1438 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05301439 * Return: QDF status
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001440 */
Anurag Chouhan6d760662016-02-20 16:05:43 +05301441QDF_STATUS cds_free_context(void *p_cds_context, QDF_MODULE_ID moduleID,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001442 void *pModuleContext)
1443{
1444 void **pGpModContext = NULL;
1445
1446 if ((p_cds_context == NULL) || (gp_cds_context != p_cds_context) ||
1447 (pModuleContext == NULL)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301448 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001449 "%s: Null params or context mismatch", __func__);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301450 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001451 }
1452
1453 switch (moduleID) {
Anurag Chouhan6d760662016-02-20 16:05:43 +05301454 case QDF_MODULE_ID_WMA:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001455 {
1456 pGpModContext = &(gp_cds_context->pWMAContext);
1457 break;
1458 }
1459
Anurag Chouhan6d760662016-02-20 16:05:43 +05301460 case QDF_MODULE_ID_HIF:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001461 {
1462 pGpModContext = &(gp_cds_context->pHIFContext);
1463 break;
1464 }
1465
Anurag Chouhan6d760662016-02-20 16:05:43 +05301466 case QDF_MODULE_ID_TXRX:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001467 {
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08001468 pGpModContext = (void **)&(gp_cds_context->pdev_txrx_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001469 break;
1470 }
1471
Anurag Chouhan6d760662016-02-20 16:05:43 +05301472 case QDF_MODULE_ID_BMI:
Komal Seelamd9106492016-02-15 10:31:44 +05301473 {
1474 pGpModContext = &(gp_cds_context->g_ol_context);
1475 break;
1476 }
1477
Anurag Chouhan6d760662016-02-20 16:05:43 +05301478 case QDF_MODULE_ID_EPPING:
1479 case QDF_MODULE_ID_HDD:
1480 case QDF_MODULE_ID_SME:
1481 case QDF_MODULE_ID_PE:
1482 case QDF_MODULE_ID_HDD_SOFTAP:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001483 default:
1484 {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301485 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001486 "%s: Module ID %i "
1487 "does not have its context allocated by CDS",
1488 __func__, moduleID);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301489 QDF_ASSERT(0);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301490 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001491 }
1492 }
1493
1494 if (NULL == *pGpModContext) {
1495 /* Context has not been allocated or freed already! */
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301496 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001497 "%s: Module ID %i "
1498 "context has not been allocated or freed already",
1499 __func__, moduleID);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301500 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001501 }
1502
1503 if (*pGpModContext != pModuleContext) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301504 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001505 "%s: pGpModContext != pModuleContext", __func__);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301506 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001507 }
1508
1509 if (pModuleContext != NULL)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301510 qdf_mem_free(pModuleContext);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001511
1512 *pGpModContext = NULL;
1513
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301514 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001515} /* cds_free_context() */
1516
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001517/**
1518 * cds_sys_probe_thread_cback() - probe mc thread callback
1519 * @pUserData: pointer to user data
1520 *
1521 * Return: none
1522 */
1523void cds_sys_probe_thread_cback(void *pUserData)
1524{
1525 if (gp_cds_context != pUserData) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301526 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001527 "%s: gp_cds_context != pUserData", __func__);
1528 return;
1529 }
1530
Anurag Chouhance0dc992016-02-16 18:18:03 +05301531 if (qdf_event_set(&gp_cds_context->ProbeEvent) != QDF_STATUS_SUCCESS) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301532 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Anurag Chouhance0dc992016-02-16 18:18:03 +05301533 "%s: qdf_event_set failed", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001534 return;
1535 }
1536} /* cds_sys_probe_thread_cback() */
1537
1538/**
1539 * cds_wma_complete_cback() - wma complete callback
1540 * @pUserData: pointer to user data
1541 *
1542 * Return: none
1543 */
1544void cds_wma_complete_cback(void *pUserData)
1545{
1546 if (gp_cds_context != pUserData) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301547 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001548 "%s: gp_cds_context != pUserData", __func__);
1549 return;
1550 }
1551
Anurag Chouhance0dc992016-02-16 18:18:03 +05301552 if (qdf_event_set(&gp_cds_context->wmaCompleteEvent) !=
1553 QDF_STATUS_SUCCESS) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301554 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Anurag Chouhance0dc992016-02-16 18:18:03 +05301555 "%s: qdf_event_set failed", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001556 return;
1557 }
1558} /* cds_wma_complete_cback() */
1559
1560/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001561 * cds_get_vdev_types() - get vdev type
1562 * @mode: mode
1563 * @type: type
1564 * @sub_type: sub_type
1565 *
1566 * Return: WMI vdev type
1567 */
Anurag Chouhan6d760662016-02-20 16:05:43 +05301568QDF_STATUS cds_get_vdev_types(enum tQDF_ADAPTER_MODE mode, uint32_t *type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001569 uint32_t *sub_type)
1570{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301571 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001572 *type = 0;
1573 *sub_type = 0;
1574
1575 switch (mode) {
Anurag Chouhan6d760662016-02-20 16:05:43 +05301576 case QDF_STA_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001577 *type = WMI_VDEV_TYPE_STA;
1578 break;
Anurag Chouhan6d760662016-02-20 16:05:43 +05301579 case QDF_SAP_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001580 *type = WMI_VDEV_TYPE_AP;
1581 break;
Anurag Chouhan6d760662016-02-20 16:05:43 +05301582 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001583 *type = WMI_VDEV_TYPE_AP;
1584 *sub_type = WMI_UNIFIED_VDEV_SUBTYPE_P2P_DEVICE;
1585 break;
Anurag Chouhan6d760662016-02-20 16:05:43 +05301586 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001587 *type = WMI_VDEV_TYPE_STA;
1588 *sub_type = WMI_UNIFIED_VDEV_SUBTYPE_P2P_CLIENT;
1589 break;
Anurag Chouhan6d760662016-02-20 16:05:43 +05301590 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001591 *type = WMI_VDEV_TYPE_AP;
1592 *sub_type = WMI_UNIFIED_VDEV_SUBTYPE_P2P_GO;
1593 break;
Anurag Chouhan6d760662016-02-20 16:05:43 +05301594 case QDF_OCB_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001595 *type = WMI_VDEV_TYPE_OCB;
1596 break;
Krunal Soni8c37e322016-02-03 16:08:37 -08001597 case QDF_IBSS_MODE:
1598 *type = WMI_VDEV_TYPE_IBSS;
1599 break;
Manjunathappa Prakashb7573722016-04-21 11:24:07 -07001600 case QDF_MONITOR_MODE:
1601 *type = WMI_VDEV_TYPE_MONITOR;
1602 break;
Deepak Dhamdheree2dd5442016-05-27 15:05:51 -07001603 case QDF_NDI_MODE:
1604 *type = WMI_VDEV_TYPE_NDI;
1605 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001606 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301607 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Ryan Hsud7e6fc72015-12-07 17:26:14 -08001608 "Invalid device mode %d", mode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301609 status = QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001610 break;
1611 }
1612 return status;
1613}
1614
1615/**
1616 * cds_flush_work() - flush pending works
1617 * @work: pointer to work
1618 *
1619 * Return: none
1620 */
1621void cds_flush_work(void *work)
1622{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001623 cancel_work_sync(work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001624}
1625
1626/**
1627 * cds_flush_delayed_work() - flush delayed works
1628 * @dwork: pointer to delayed work
1629 *
1630 * Return: none
1631 */
1632void cds_flush_delayed_work(void *dwork)
1633{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001634 cancel_delayed_work_sync(dwork);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001635}
1636
1637/**
1638 * cds_is_packet_log_enabled() - check if packet log is enabled
1639 *
1640 * Return: true if packet log is enabled else false
1641 */
1642bool cds_is_packet_log_enabled(void)
1643{
1644 hdd_context_t *pHddCtx;
1645
1646 pHddCtx = (hdd_context_t *) (gp_cds_context->pHDDContext);
1647 if ((NULL == pHddCtx) || (NULL == pHddCtx->config)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301648 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001649 "%s: Hdd Context is Null", __func__);
1650 return false;
1651 }
1652
1653 return pHddCtx->config->enablePacketLog;
1654}
1655
1656/**
Mukul Sharmab7b575b2016-10-02 23:37:07 +05301657 * cds_config_recovery_work() - configure self recovery
1658 * @qdf_ctx: pointer of qdf context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001659 *
1660 * Return: none
1661 */
Mukul Sharmab7b575b2016-10-02 23:37:07 +05301662
Jeff Johnson2fb441a2016-11-30 12:13:17 -08001663static void cds_config_recovery_work(qdf_device_t qdf_ctx)
Mukul Sharmab7b575b2016-10-02 23:37:07 +05301664{
1665 if (cds_is_driver_recovering()) {
1666 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
1667 "Recovery is in progress, ignore!");
1668 } else {
1669 cds_set_recovery_in_progress(true);
1670 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
1671 "schedule recovery work!");
Yuanyuan Liu10fc3d32017-01-12 15:32:06 -08001672 pld_schedule_recovery_work(qdf_ctx->dev,
1673 PLD_REASON_DEFAULT);
Mukul Sharmab7b575b2016-10-02 23:37:07 +05301674 }
1675}
1676
1677/**
1678 * cds_trigger_recovery() - trigger self recovery
1679 * @skip_crash_inject: Boolean value to skip to send crash inject cmd
1680 *
1681 * Return: none
1682 */
1683void cds_trigger_recovery(bool skip_crash_inject)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001684{
Anurag Chouhan6d760662016-02-20 16:05:43 +05301685 tp_wma_handle wma_handle = cds_get_context(QDF_MODULE_ID_WMA);
Anurag Chouhance0dc992016-02-16 18:18:03 +05301686 QDF_STATUS status = QDF_STATUS_SUCCESS;
Houston Hoffmanc7c72a82015-12-07 15:30:48 -08001687 qdf_runtime_lock_t recovery_lock;
Yuanyuan Liu0e0aa932016-05-12 10:17:58 -07001688 qdf_device_t qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001689
1690 if (!wma_handle) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301691 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Komal Seelam1aac1982016-03-02 15:57:26 +05301692 "WMA context is invalid!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001693 return;
1694 }
Sameer Thalappilec2e9c72017-02-08 15:45:49 -08001695 if (!qdf_ctx) {
1696 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
1697 "QDF context is invalid!");
1698 return;
1699 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001700
Houston Hoffmanc7c72a82015-12-07 15:30:48 -08001701 recovery_lock = qdf_runtime_lock_init("cds_recovery");
1702 if (!recovery_lock) {
1703 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
1704 "Could not acquire runtime pm lock!");
1705 return;
1706 }
1707
1708 qdf_runtime_pm_prevent_suspend(recovery_lock);
1709
Mukul Sharmab7b575b2016-10-02 23:37:07 +05301710 if (!skip_crash_inject) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001711
Mukul Sharmab7b575b2016-10-02 23:37:07 +05301712 wma_crash_inject(wma_handle, RECOVERY_SIM_SELF_RECOVERY, 0);
1713 status = qdf_wait_single_event(&wma_handle->recovery_event,
1714 WMA_CRASH_INJECT_TIMEOUT);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001715
Mukul Sharmab7b575b2016-10-02 23:37:07 +05301716 if (QDF_STATUS_SUCCESS != status) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301717 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Mukul Sharmab7b575b2016-10-02 23:37:07 +05301718 "CRASH_INJECT command is timed out!");
1719 cds_config_recovery_work(qdf_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001720 }
Mukul Sharmab7b575b2016-10-02 23:37:07 +05301721 } else {
1722 cds_config_recovery_work(qdf_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001723 }
Houston Hoffmanc7c72a82015-12-07 15:30:48 -08001724
1725 qdf_runtime_pm_allow_suspend(recovery_lock);
1726 qdf_runtime_lock_deinit(recovery_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001727}
1728
1729/**
1730 * cds_get_monotonic_boottime() - Get kernel boot time.
1731 *
1732 * Return: Time in microseconds
1733 */
1734
1735uint64_t cds_get_monotonic_boottime(void)
1736{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001737 struct timespec ts;
1738
Yuanyuan Liu2e03b412016-04-06 14:36:15 -07001739 get_monotonic_boottime(&ts);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001740 return ((uint64_t) ts.tv_sec * 1000000) + (ts.tv_nsec / 1000);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001741}
1742
1743/**
1744 * cds_set_wakelock_logging() - Logging of wakelock enabled/disabled
1745 * @value: Boolean value
1746 *
1747 * This function is used to set the flag which will indicate whether
1748 * logging of wakelock is enabled or not
1749 *
1750 * Return: None
1751 */
1752void cds_set_wakelock_logging(bool value)
1753{
1754 p_cds_contextType p_cds_context;
1755
1756 p_cds_context = cds_get_global_context();
1757 if (!p_cds_context) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301758 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001759 "cds context is Invald");
1760 return;
1761 }
1762 p_cds_context->is_wakelock_log_enabled = value;
1763}
1764
1765/**
1766 * cds_is_wakelock_enabled() - Check if logging of wakelock is enabled/disabled
1767 * @value: Boolean value
1768 *
1769 * This function is used to check whether logging of wakelock is enabled or not
1770 *
1771 * Return: true if logging of wakelock is enabled
1772 */
1773bool cds_is_wakelock_enabled(void)
1774{
1775 p_cds_contextType p_cds_context;
1776
1777 p_cds_context = cds_get_global_context();
1778 if (!p_cds_context) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301779 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001780 "cds context is Invald");
1781 return false;
1782 }
1783 return p_cds_context->is_wakelock_log_enabled;
1784}
1785
1786/**
1787 * cds_set_ring_log_level() - Sets the log level of a particular ring
1788 * @ring_id: ring_id
1789 * @log_levelvalue: Log level specificed
1790 *
1791 * This function converts HLOS values to driver log levels and sets the log
1792 * level of a particular ring accordingly.
1793 *
1794 * Return: None
1795 */
1796void cds_set_ring_log_level(uint32_t ring_id, uint32_t log_level)
1797{
1798 p_cds_contextType p_cds_context;
1799 uint32_t log_val;
1800
1801 p_cds_context = cds_get_global_context();
1802 if (!p_cds_context) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301803 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001804 "%s: cds context is Invald", __func__);
1805 return;
1806 }
1807
1808 switch (log_level) {
1809 case LOG_LEVEL_NO_COLLECTION:
1810 log_val = WLAN_LOG_LEVEL_OFF;
1811 break;
1812 case LOG_LEVEL_NORMAL_COLLECT:
1813 log_val = WLAN_LOG_LEVEL_NORMAL;
1814 break;
1815 case LOG_LEVEL_ISSUE_REPRO:
1816 log_val = WLAN_LOG_LEVEL_REPRO;
1817 break;
1818 case LOG_LEVEL_ACTIVE:
1819 default:
1820 log_val = WLAN_LOG_LEVEL_ACTIVE;
1821 break;
1822 }
1823
1824 if (ring_id == RING_ID_WAKELOCK) {
1825 p_cds_context->wakelock_log_level = log_val;
1826 return;
1827 } else if (ring_id == RING_ID_CONNECTIVITY) {
1828 p_cds_context->connectivity_log_level = log_val;
1829 return;
1830 } else if (ring_id == RING_ID_PER_PACKET_STATS) {
1831 p_cds_context->packet_stats_log_level = log_val;
1832 return;
Chandrasekaran, Manishekar907c2af2015-11-13 12:50:04 +05301833 } else if (ring_id == RING_ID_DRIVER_DEBUG) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001834 p_cds_context->driver_debug_log_level = log_val;
1835 return;
1836 } else if (ring_id == RING_ID_FIRMWARE_DEBUG) {
1837 p_cds_context->fw_debug_log_level = log_val;
1838 return;
1839 }
1840}
1841
1842/**
1843 * cds_get_ring_log_level() - Get the a ring id's log level
1844 * @ring_id: Ring id
1845 *
1846 * Fetch and return the log level corresponding to a ring id
1847 *
1848 * Return: Log level corresponding to the ring ID
1849 */
1850enum wifi_driver_log_level cds_get_ring_log_level(uint32_t ring_id)
1851{
1852 p_cds_contextType p_cds_context;
1853
1854 p_cds_context = cds_get_global_context();
1855 if (!p_cds_context) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301856 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001857 "%s: cds context is Invald", __func__);
1858 return WLAN_LOG_LEVEL_OFF;
1859 }
1860
1861 if (ring_id == RING_ID_WAKELOCK)
1862 return p_cds_context->wakelock_log_level;
1863 else if (ring_id == RING_ID_CONNECTIVITY)
1864 return p_cds_context->connectivity_log_level;
1865 else if (ring_id == RING_ID_PER_PACKET_STATS)
1866 return p_cds_context->packet_stats_log_level;
Chandrasekaran, Manishekar907c2af2015-11-13 12:50:04 +05301867 else if (ring_id == RING_ID_DRIVER_DEBUG)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001868 return p_cds_context->driver_debug_log_level;
1869 else if (ring_id == RING_ID_FIRMWARE_DEBUG)
1870 return p_cds_context->fw_debug_log_level;
1871
1872 return WLAN_LOG_LEVEL_OFF;
1873}
1874
1875/**
1876 * cds_set_multicast_logging() - Set mutlicast logging value
1877 * @value: Value of multicast logging
1878 *
1879 * Set the multicast logging value which will indicate
1880 * whether to multicast host and fw messages even
1881 * without any registration by userspace entity
1882 *
1883 * Return: None
1884 */
1885void cds_set_multicast_logging(uint8_t value)
1886{
1887 cds_multicast_logging = value;
1888}
1889
1890/**
1891 * cds_is_multicast_logging() - Get multicast logging value
1892 *
1893 * Get the multicast logging value which will indicate
1894 * whether to multicast host and fw messages even
1895 * without any registration by userspace entity
1896 *
1897 * Return: 0 - Multicast logging disabled, 1 - Multicast logging enabled
1898 */
1899uint8_t cds_is_multicast_logging(void)
1900{
1901 return cds_multicast_logging;
1902}
1903
1904/*
1905 * cds_init_log_completion() - Initialize log param structure
1906 *
1907 * This function is used to initialize the logging related
1908 * parameters
1909 *
1910 * Return: None
1911 */
1912void cds_init_log_completion(void)
1913{
1914 p_cds_contextType p_cds_context;
1915
1916 p_cds_context = cds_get_global_context();
1917 if (!p_cds_context) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301918 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001919 "%s: cds context is Invalid", __func__);
1920 return;
1921 }
1922
1923 p_cds_context->log_complete.is_fatal = WLAN_LOG_TYPE_NON_FATAL;
1924 p_cds_context->log_complete.indicator = WLAN_LOG_INDICATOR_UNUSED;
1925 p_cds_context->log_complete.reason_code = WLAN_LOG_REASON_CODE_UNUSED;
1926 p_cds_context->log_complete.is_report_in_progress = false;
1927 /* Attempting to initialize an already initialized lock
1928 * results in a failure. This must be ok here.
1929 */
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301930 qdf_spinlock_create(&p_cds_context->bug_report_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001931}
1932
1933/**
1934 * cds_deinit_log_completion() - Deinitialize log param structure
1935 *
1936 * This function is used to deinitialize the logging related
1937 * parameters
1938 *
1939 * Return: None
1940 */
1941void cds_deinit_log_completion(void)
1942{
1943 p_cds_contextType p_cds_context;
1944
1945 p_cds_context = cds_get_global_context();
1946 if (!p_cds_context) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301947 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001948 "%s: cds context is Invalid", __func__);
1949 return;
1950 }
1951
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301952 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001953}
1954
1955/**
1956 * cds_set_log_completion() - Store the logging params
1957 * @is_fatal: Indicates if the event triggering bug report is fatal or not
1958 * @indicator: Source which trigerred the bug report
1959 * @reason_code: Reason for triggering bug report
Abhishek Singh5ea86532016-04-27 14:10:53 +05301960 * @recovery_needed: If recovery is needed after bug report
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001961 *
1962 * This function is used to set the logging parameters based on the
1963 * caller
1964 *
1965 * Return: 0 if setting of params is successful
1966 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301967QDF_STATUS cds_set_log_completion(uint32_t is_fatal,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001968 uint32_t indicator,
Abhishek Singh5ea86532016-04-27 14:10:53 +05301969 uint32_t reason_code,
1970 bool recovery_needed)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001971{
1972 p_cds_contextType p_cds_context;
1973
1974 p_cds_context = cds_get_global_context();
1975 if (!p_cds_context) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301976 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001977 "%s: cds context is Invalid", __func__);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301978 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001979 }
1980
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301981 qdf_spinlock_acquire(&p_cds_context->bug_report_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001982 p_cds_context->log_complete.is_fatal = is_fatal;
1983 p_cds_context->log_complete.indicator = indicator;
1984 p_cds_context->log_complete.reason_code = reason_code;
Abhishek Singh5ea86532016-04-27 14:10:53 +05301985 p_cds_context->log_complete.recovery_needed = recovery_needed;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001986 p_cds_context->log_complete.is_report_in_progress = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301987 qdf_spinlock_release(&p_cds_context->bug_report_lock);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301988 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001989}
1990
1991/**
Abhishek Singh5ea86532016-04-27 14:10:53 +05301992 * cds_get_and_reset_log_completion() - Get and reset logging related params
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001993 * @is_fatal: Indicates if the event triggering bug report is fatal or not
1994 * @indicator: Source which trigerred the bug report
1995 * @reason_code: Reason for triggering bug report
Abhishek Singh5ea86532016-04-27 14:10:53 +05301996 * @recovery_needed: If recovery is needed after bug report
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001997 *
1998 * This function is used to get the logging related parameters
1999 *
2000 * Return: None
2001 */
Abhishek Singh5ea86532016-04-27 14:10:53 +05302002void cds_get_and_reset_log_completion(uint32_t *is_fatal,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002003 uint32_t *indicator,
Abhishek Singh5ea86532016-04-27 14:10:53 +05302004 uint32_t *reason_code,
2005 bool *recovery_needed)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002006{
2007 p_cds_contextType p_cds_context;
2008
2009 p_cds_context = cds_get_global_context();
2010 if (!p_cds_context) {
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: cds context is Invalid", __func__);
2013 return;
2014 }
2015
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302016 qdf_spinlock_acquire(&p_cds_context->bug_report_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002017 *is_fatal = p_cds_context->log_complete.is_fatal;
2018 *indicator = p_cds_context->log_complete.indicator;
2019 *reason_code = p_cds_context->log_complete.reason_code;
Abhishek Singh5ea86532016-04-27 14:10:53 +05302020 *recovery_needed = p_cds_context->log_complete.recovery_needed;
2021
2022 /* reset */
2023 p_cds_context->log_complete.indicator = WLAN_LOG_INDICATOR_UNUSED;
2024 p_cds_context->log_complete.is_fatal = WLAN_LOG_TYPE_NON_FATAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002025 p_cds_context->log_complete.is_report_in_progress = false;
Abhishek Singh5ea86532016-04-27 14:10:53 +05302026 p_cds_context->log_complete.reason_code = WLAN_LOG_REASON_CODE_UNUSED;
2027 p_cds_context->log_complete.recovery_needed = false;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302028 qdf_spinlock_release(&p_cds_context->bug_report_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002029}
2030
2031/**
2032 * cds_is_log_report_in_progress() - Check if bug reporting is in progress
2033 *
2034 * This function is used to check if the bug reporting is already in progress
2035 *
2036 * Return: true if the bug reporting is in progress
2037 */
2038bool cds_is_log_report_in_progress(void)
2039{
2040 p_cds_contextType p_cds_context;
2041
2042 p_cds_context = cds_get_global_context();
2043 if (!p_cds_context) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302044 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002045 "%s: cds context is Invalid", __func__);
2046 return true;
2047 }
2048 return p_cds_context->log_complete.is_report_in_progress;
2049}
2050
2051/**
Abhishek Singh5ea86532016-04-27 14:10:53 +05302052 * cds_is_fatal_event_enabled() - Return if fatal event is enabled
2053 *
2054 * Return true if fatal event is enabled.
2055 */
2056bool cds_is_fatal_event_enabled(void)
2057{
2058 p_cds_contextType p_cds_context;
2059
2060 p_cds_context = cds_get_global_context();
2061 if (!p_cds_context) {
2062 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
2063 "%s: cds context is Invalid", __func__);
2064 return false;
2065 }
2066
2067
2068 return p_cds_context->enable_fatal_event;
2069}
2070
2071/**
2072 * cds_get_log_indicator() - Get the log flush indicator
2073 *
2074 * This function is used to get the log flush indicator
2075 *
2076 * Return: log indicator
2077 */
2078uint32_t cds_get_log_indicator(void)
2079{
2080 p_cds_contextType p_cds_context;
2081 uint32_t indicator;
2082
2083 p_cds_context = cds_get_global_context();
2084 if (!p_cds_context) {
2085 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
2086 "%s: cds context is Invalid", __func__);
2087 return WLAN_LOG_INDICATOR_UNUSED;
2088 }
2089
2090 if (cds_is_load_or_unload_in_progress() ||
2091 cds_is_driver_recovering()) {
Abhishek Singh5ea86532016-04-27 14:10:53 +05302092 return WLAN_LOG_INDICATOR_UNUSED;
2093 }
2094
2095 qdf_spinlock_acquire(&p_cds_context->bug_report_lock);
2096 indicator = p_cds_context->log_complete.indicator;
2097 qdf_spinlock_release(&p_cds_context->bug_report_lock);
2098 return indicator;
2099}
2100
2101/**
2102 * cds_wlan_flush_host_logs_for_fatal() - Wrapper to flush host logs
2103 *
2104 * This function is used to send signal to the logger thread to
2105 * flush the host logs.
2106 *
2107 * Return: None
2108 *
2109 */
2110void cds_wlan_flush_host_logs_for_fatal(void)
2111{
2112 wlan_flush_host_logs_for_fatal();
2113}
2114
2115/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002116 * cds_flush_logs() - Report fatal event to userspace
2117 * @is_fatal: Indicates if the event triggering bug report is fatal or not
2118 * @indicator: Source which trigerred the bug report
2119 * @reason_code: Reason for triggering bug report
Abhishek Singh5ea86532016-04-27 14:10:53 +05302120 * @dump_mac_trace: If mac trace are needed in logs.
2121 * @recovery_needed: If recovery is needed after bug report
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002122 *
2123 * This function sets the log related params and send the WMI command to the
2124 * FW to flush its logs. On receiving the flush completion event from the FW
2125 * the same will be conveyed to userspace
2126 *
2127 * Return: 0 on success
2128 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302129QDF_STATUS cds_flush_logs(uint32_t is_fatal,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002130 uint32_t indicator,
Abhishek Singh5ea86532016-04-27 14:10:53 +05302131 uint32_t reason_code,
2132 bool dump_mac_trace,
2133 bool recovery_needed)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002134{
2135 uint32_t ret;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302136 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002137
2138 p_cds_contextType p_cds_context;
2139
2140 p_cds_context = cds_get_global_context();
2141 if (!p_cds_context) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302142 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002143 "%s: cds context is Invalid", __func__);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302144 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002145 }
Abhishek Singh5ea86532016-04-27 14:10:53 +05302146 if (!p_cds_context->enable_fatal_event) {
2147 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
2148 "%s: Fatal event not enabled", __func__);
2149 return QDF_STATUS_E_FAILURE;
2150 }
2151 if (cds_is_load_or_unload_in_progress() ||
2152 cds_is_driver_recovering()) {
2153 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
2154 "%s: un/Load/SSR in progress", __func__);
2155 return QDF_STATUS_E_FAILURE;
2156 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002157
2158 if (cds_is_log_report_in_progress() == true) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302159 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002160 "%s: Bug report already in progress - dropping! type:%d, indicator=%d reason_code=%d",
2161 __func__, is_fatal, indicator, reason_code);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302162 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002163 }
2164
Abhishek Singh5ea86532016-04-27 14:10:53 +05302165 status = cds_set_log_completion(is_fatal, indicator,
2166 reason_code, recovery_needed);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302167 if (QDF_STATUS_SUCCESS != status) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302168 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002169 "%s: Failed to set log trigger params", __func__);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302170 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002171 }
2172
Abhishek Singh5ea86532016-04-27 14:10:53 +05302173 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002174 "%s: Triggering bug report: type:%d, indicator=%d reason_code=%d",
2175 __func__, is_fatal, indicator, reason_code);
2176
Abhishek Singh5ea86532016-04-27 14:10:53 +05302177 if (dump_mac_trace)
2178 qdf_trace_dump_all(p_cds_context->pMACContext, 0, 0, 500, 0);
2179
2180 if (WLAN_LOG_INDICATOR_HOST_ONLY == indicator) {
2181 cds_wlan_flush_host_logs_for_fatal();
2182 return QDF_STATUS_SUCCESS;
2183 }
2184
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002185 ret = sme_send_flush_logs_cmd_to_fw(p_cds_context->pMACContext);
2186 if (0 != ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302187 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002188 "%s: Failed to send flush FW log", __func__);
2189 cds_init_log_completion();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302190 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002191 }
2192
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302193 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002194}
2195
2196/**
2197 * cds_logging_set_fw_flush_complete() - Wrapper for FW log flush completion
2198 *
2199 * This function is used to send signal to the logger thread to indicate
2200 * that the flushing of FW logs is complete by the FW
2201 *
2202 * Return: None
2203 *
2204 */
2205void cds_logging_set_fw_flush_complete(void)
2206{
2207 wlan_logging_set_fw_flush_complete();
2208}
Abhishek Singh5ea86532016-04-27 14:10:53 +05302209
2210/**
2211 * cds_set_fatal_event() - set fatal event status
2212 * @value: pending statue to set
2213 *
2214 * Return: None
2215 */
2216void cds_set_fatal_event(bool value)
2217{
2218 p_cds_contextType p_cds_context;
2219
2220 p_cds_context = cds_get_global_context();
2221 if (!p_cds_context) {
2222 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
2223 "%s: cds context is Invalid", __func__);
2224 return;
2225 }
2226 p_cds_context->enable_fatal_event = value;
2227}
2228
Ryan Hsuceddceb2016-04-28 10:20:14 -07002229/**
2230 * cds_get_radio_index() - get radio index
2231 *
2232 * Return: radio index otherwise, -EINVAL
2233 */
2234int cds_get_radio_index(void)
2235{
2236 p_cds_contextType p_cds_context;
2237
2238 p_cds_context = cds_get_global_context();
2239 if (!p_cds_context) {
2240 /*
2241 * To avoid recursive call, this should not change to
2242 * QDF_TRACE().
2243 */
2244 pr_err("%s: cds context is invalid\n", __func__);
2245 return -EINVAL;
2246 }
2247
2248 return p_cds_context->radio_index;
2249}
2250
2251/**
2252 * cds_set_radio_index() - set radio index
2253 * @radio_index: the radio index to set
2254 *
2255 * Return: QDF status
2256 */
2257QDF_STATUS cds_set_radio_index(int radio_index)
2258{
2259 p_cds_contextType p_cds_context;
2260
2261 p_cds_context = cds_get_global_context();
2262 if (!p_cds_context) {
2263 pr_err("%s: cds context is invalid\n", __func__);
2264 return QDF_STATUS_E_FAILURE;
2265 }
2266
2267 p_cds_context->radio_index = radio_index;
2268
2269 return QDF_STATUS_SUCCESS;
2270}
Arun Khandavallic811dcc2016-06-26 07:37:21 +05302271
2272/**
2273 * cds_init_ini_config() - API to initialize CDS configuration parameters
2274 * @cfg: CDS Configuration
2275 *
2276 * Return: void
2277 */
2278
2279void cds_init_ini_config(struct cds_config_info *cfg)
2280{
2281 cds_context_type *cds_ctx;
2282
2283 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2284 if (!cds_ctx) {
2285 cds_err("Invalid CDS Context");
2286 return;
2287 }
2288
2289 cds_ctx->cds_cfg = cfg;
2290}
2291
2292/**
2293 * cds_deinit_ini_config() - API to free CDS configuration parameters
2294 *
2295 * Return: void
2296 */
2297void cds_deinit_ini_config(void)
2298{
2299 cds_context_type *cds_ctx;
2300
2301 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2302 if (!cds_ctx) {
2303 cds_err("Invalid CDS Context");
2304 return;
2305 }
2306
Arun Khandavallif6246632016-08-17 17:43:06 +05302307 if (cds_ctx->cds_cfg)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05302308 qdf_mem_free(cds_ctx->cds_cfg);
2309
2310 cds_ctx->cds_cfg = NULL;
2311}
2312
2313/**
2314 * cds_get_ini_config() - API to get CDS configuration parameters
2315 *
2316 * Return: cds config structure
2317 */
2318struct cds_config_info *cds_get_ini_config(void)
2319{
2320 cds_context_type *cds_ctx;
2321
2322 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2323 if (!cds_ctx) {
2324 cds_err("Invalid CDS Context");
2325 return NULL;
2326 }
2327
2328 return cds_ctx->cds_cfg;
2329}
Naveen Rawat64e477e2016-05-20 10:34:56 -07002330
2331/**
2332 * cds_is_5_mhz_enabled() - API to get 5MHZ enabled
2333 *
2334 * Return: true if 5 mhz is enabled, false otherwise
2335 */
2336bool cds_is_5_mhz_enabled(void)
2337{
2338 p_cds_contextType p_cds_context;
2339
2340 p_cds_context = cds_get_context(QDF_MODULE_ID_QDF);
2341 if (!p_cds_context) {
2342 cds_err("%s: cds context is invalid", __func__);
2343 return false;
2344 }
2345
2346 if (p_cds_context->cds_cfg)
2347 return (p_cds_context->cds_cfg->sub_20_channel_width ==
2348 WLAN_SUB_20_CH_WIDTH_5);
2349
2350 return false;
2351}
2352
2353/**
2354 * cds_is_10_mhz_enabled() - API to get 10-MHZ enabled
2355 *
2356 * Return: true if 10 mhz is enabled, false otherwise
2357 */
2358bool cds_is_10_mhz_enabled(void)
2359{
2360 p_cds_contextType p_cds_context;
2361
2362 p_cds_context = cds_get_context(QDF_MODULE_ID_QDF);
2363 if (!p_cds_context) {
2364 cds_err("%s: cds context is invalid", __func__);
2365 return false;
2366 }
2367
2368 if (p_cds_context->cds_cfg)
2369 return (p_cds_context->cds_cfg->sub_20_channel_width ==
2370 WLAN_SUB_20_CH_WIDTH_10);
2371
2372 return false;
2373}
2374
2375/**
2376 * cds_is_sub_20_mhz_enabled() - API to get sub 20-MHZ enabled
2377 *
2378 * Return: true if 5 or 10 mhz is enabled, false otherwise
2379 */
2380bool cds_is_sub_20_mhz_enabled(void)
2381{
2382 p_cds_contextType p_cds_context;
2383
2384 p_cds_context = cds_get_context(QDF_MODULE_ID_QDF);
2385 if (!p_cds_context) {
2386 cds_err("%s: cds context is invalid", __func__);
2387 return false;
2388 }
2389
2390 if (p_cds_context->cds_cfg)
2391 return p_cds_context->cds_cfg->sub_20_channel_width;
2392
2393 return false;
2394}
2395
Komal Seelam78ff65a2016-08-18 15:25:24 +05302396/**
Naveen Rawat91df30a2016-10-12 21:26:18 -07002397 * cds_is_self_recovery_enabled() - API to get self recovery enabled
2398 *
2399 * Return: true if self recovery enabled, false otherwise
2400 */
2401bool cds_is_self_recovery_enabled(void)
2402{
2403 p_cds_contextType p_cds_context;
2404
2405 p_cds_context = cds_get_context(QDF_MODULE_ID_QDF);
2406 if (!p_cds_context) {
2407 cds_err("%s: cds context is invalid", __func__);
2408 return false;
2409 }
2410
2411 if (p_cds_context->cds_cfg)
2412 return p_cds_context->cds_cfg->self_recovery_enabled;
2413
2414 return false;
2415}
2416
2417/**
Komal Seelam78ff65a2016-08-18 15:25:24 +05302418 * cds_svc_fw_shutdown_ind() - API to send userspace about FW crash
2419 *
2420 * @dev: Device Pointer
2421 *
2422 * Return: None
2423 */
2424void cds_svc_fw_shutdown_ind(struct device *dev)
2425{
2426 hdd_svc_fw_shutdown_ind(dev);
2427}
Himanshu Agarwal46956a52016-07-26 19:46:25 +05302428
2429/*
2430 * cds_pkt_stats_to_logger_thread() - send pktstats to user
2431 * @pl_hdr: Pointer to pl_hdr
2432 * @pkt_dump: Pointer to pkt_dump data structure.
2433 * @data: Pointer to data
2434 *
2435 * This function is used to send the pkt stats to SVC module.
2436 *
2437 * Return: None
2438 */
2439inline void cds_pkt_stats_to_logger_thread(void *pl_hdr, void *pkt_dump,
2440 void *data)
2441{
2442 if (cds_get_ring_log_level(RING_ID_PER_PACKET_STATS) !=
2443 WLAN_LOG_LEVEL_ACTIVE)
2444 return;
2445
2446 wlan_pkt_stats_to_logger_thread(pl_hdr, pkt_dump, data);
2447}
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08002448
2449/**
2450 * cds_get_conparam() - Get the connection mode parameters
2451 *
2452 * Return the connection mode parameter set by insmod or set during statically
2453 * linked driver
2454 *
2455 * Return: enum tQDF_GLOBAL_CON_MODE
2456 */
2457enum tQDF_GLOBAL_CON_MODE cds_get_conparam(void)
2458{
2459 enum tQDF_GLOBAL_CON_MODE con_mode;
2460
2461 con_mode = hdd_get_conparam();
2462
2463 return con_mode;
2464}
Dustin Brown8d2d0f52017-04-03 17:02:08 -07002465
2466#ifdef WMI_INTERFACE_EVENT_LOGGING
2467inline void
2468cds_print_htc_credit_history(uint32_t count, qdf_abstract_print *print,
2469 void *print_priv)
2470{
2471 htc_print_credit_history(gp_cds_context->htc_ctx, count,
2472 print, print_priv);
2473}
2474#endif