blob: 6cc16e942719b32230a3d63789052b441f1f368a [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
Kabilan Kannan973744a2018-01-03 10:28:50 -08002 * Copyright (c) 2012-2018 The Linux Foundation. All rights reserved.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004 * Permission to use, copy, modify, and/or distribute this software for
5 * any purpose with or without fee is hereby granted, provided that the
6 * above copyright notice and this permission notice appear in all
7 * copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
17 */
18
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080019/**
20 * DOC: cds_api.c
21 *
22 * Connectivity driver services APIs
23 */
24
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080025#include <cds_api.h>
26#include "sir_types.h"
27#include "sir_api.h"
28#include "sir_mac_prot_def.h"
29#include "sme_api.h"
30#include "mac_init_api.h"
31#include "wlan_qct_sys.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080032#include "i_cds_packet.h"
33#include "cds_reg_service.h"
34#include "wma_types.h"
35#include "wlan_hdd_main.h"
Jeff Johnson7b3c98f2018-07-08 20:52:37 -070036#include "wlan_hdd_power.h"
Yu Wang66a250b2017-07-19 11:46:40 +080037#include "wlan_hdd_tsf.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080038#include <linux/vmalloc.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080039
Yuanyuan Liu0e0aa932016-05-12 10:17:58 -070040#include "pld_common.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080041#include "sap_api.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080042#include "bmi.h"
43#include "ol_fw.h"
44#include "ol_if_athvar.h"
45#include "hif.h"
Tushnim Bhattacharyya12b48742017-03-13 12:46:45 -070046#include "wlan_policy_mgr_api.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080047#include "cds_utils.h"
48#include "wlan_logging_sock_svc.h"
49#include "wma.h"
Nirav Shah7f337db2016-05-25 10:49:02 +053050#include "pktlog_ac.h"
Pramod Simha0d3b9362017-03-27 14:59:58 -070051#include "wlan_policy_mgr_api.h"
Leo Chang9b097032016-10-28 11:03:17 -070052
53#include <cdp_txrx_cmn_reg.h>
54#include <cdp_txrx_cfg.h>
55#include <cdp_txrx_misc.h>
Rajeev Kumar97767a02016-11-30 11:20:40 -080056#include <dispatcher_init_deinit.h>
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -080057#include <cdp_txrx_handle.h>
Govind Singh27a74032017-11-10 15:08:19 +053058#include "target_type.h"
Zhang Qian47e22ce2018-01-04 15:38:38 +080059#include "wlan_ocb_ucfg_api.h"
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +053060#include "wlan_ipa_ucfg_api.h"
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -080061
Himanshu Agarwaledf30dc2017-06-05 15:54:27 +053062#ifdef ENABLE_SMMU_S1_TRANSLATION
63#include "pld_common.h"
64#include <asm/dma-iommu.h>
65#include <linux/iommu.h>
66#endif
Sravan Kumar Kairamb8bdf522018-05-30 22:14:50 +053067
68#ifdef QCA_WIFI_QCA8074
69#include <target_if_dp.h>
70#endif
71
Himanshu Agarwaledf30dc2017-06-05 15:54:27 +053072/* Preprocessor Definitions and Constants */
73
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080074/* Preprocessor Definitions and Constants */
75
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080076/* Data definitions */
Jeff Johnson2b6982c2018-05-29 14:56:11 -070077static struct cds_context g_cds_context;
78static struct cds_context *gp_cds_context;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053079static struct __qdf_device g_qdf_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080080
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080081static uint8_t cds_multicast_logging;
82
Sravan Kumar Kairamb8bdf522018-05-30 22:14:50 +053083#ifdef QCA_WIFI_QCA8074
Leo Chang9b097032016-10-28 11:03:17 -070084static struct ol_if_ops dp_ol_if_ops = {
Sravan Kumar Kairamb8bdf522018-05-30 22:14:50 +053085 .peer_set_default_routing = target_if_peer_set_default_routing,
86 .peer_rx_reorder_queue_setup = target_if_peer_rx_reorder_queue_setup,
87 .peer_rx_reorder_queue_remove = target_if_peer_rx_reorder_queue_remove,
Dhanashri Atref5e02122017-04-13 15:36:42 -070088 .is_hw_dbs_2x2_capable = policy_mgr_is_hw_dbs_2x2_capable,
Sravan Kumar Kairamb8bdf522018-05-30 22:14:50 +053089 .lro_hash_config = target_if_lro_hash_config,
jiadcd49ec72017-12-05 13:33:11 +080090 .rx_mic_error = wma_rx_mic_error_ind
Leo Chang9b097032016-10-28 11:03:17 -070091 /* TODO: Add any other control path calls required to OL_IF/WMA layer */
92};
Sravan Kumar Kairamb8bdf522018-05-30 22:14:50 +053093#else
94static struct ol_if_ops dp_ol_if_ops;
95#endif
Leo Chang9b097032016-10-28 11:03:17 -070096
Srinivas Girigowda161b9f22017-07-24 17:38:09 -070097static void cds_trigger_recovery_work(void *param);
98
99/**
100 * cds_recovery_work_init() - Initialize recovery work queue
101 *
102 * Return: none
103 */
104static QDF_STATUS cds_recovery_work_init(void)
105{
106 qdf_create_work(0, &gp_cds_context->cds_recovery_work,
107 cds_trigger_recovery_work, NULL);
108 gp_cds_context->cds_recovery_wq =
109 qdf_create_workqueue("cds_recovery_workqueue");
110 if (NULL == gp_cds_context->cds_recovery_wq) {
111 cds_err("Failed to create cds_recovery_workqueue");
112 return QDF_STATUS_E_FAILURE;
113 }
114
115 return QDF_STATUS_SUCCESS;
116}
117
118/**
119 * cds_recovery_work_deinit() - Initialize recovery work queue
120 *
121 * Return: none
122 */
123static void cds_recovery_work_deinit(void)
124{
125 if (gp_cds_context->cds_recovery_wq) {
126 qdf_flush_workqueue(0, gp_cds_context->cds_recovery_wq);
127 qdf_destroy_workqueue(0, gp_cds_context->cds_recovery_wq);
128 }
129}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800130
Venkata Sharath Chandra Manchala83985632017-02-28 14:16:22 -0800131/** cds_get_datapath_handles - Initialize pdev, vdev and soc
132 * @soc - soc handle
133 * @vdev - virtual handle
134 * @pdev - physical handle
135 */
136uint8_t cds_get_datapath_handles(void **soc, struct cdp_pdev **pdev,
137 struct cdp_vdev **vdev, uint8_t sessionId)
138{
139
140 (*soc) = cds_get_context(QDF_MODULE_ID_SOC);
141
142 if (!(*soc)) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700143 cds_err("soc handle is invalid");
Venkata Sharath Chandra Manchala83985632017-02-28 14:16:22 -0800144 return -EINVAL;
145 }
146
147 (*pdev) = cds_get_context(QDF_MODULE_ID_TXRX);
148
149 if (!(*pdev)) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700150 cds_err("pdev handle is invalid");
Venkata Sharath Chandra Manchala83985632017-02-28 14:16:22 -0800151 return -EINVAL;
152 }
153
154 (*vdev) = cdp_get_vdev_from_vdev_id((*soc), (*pdev),
155 sessionId);
156
157 if (!(*vdev)) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700158 cds_err("vdev handle is invalid");
Venkata Sharath Chandra Manchala83985632017-02-28 14:16:22 -0800159 return -EINVAL;
160 }
161 return 0;
162}
163
164
Jeff Johnson7aaeeea2017-09-26 13:16:24 -0700165QDF_STATUS cds_init(void)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800166{
wadesongae4ffd12017-10-24 16:45:54 +0800167 QDF_STATUS ret;
168
169 ret = qdf_debugfs_init();
Rajeev Kumar3f5c5932018-03-09 13:14:46 -0800170 if (ret != QDF_STATUS_SUCCESS)
wadesongae4ffd12017-10-24 16:45:54 +0800171 cds_err("Failed to init debugfs");
wadesongae4ffd12017-10-24 16:45:54 +0800172
Houston Hoffman1a777572017-01-13 12:43:48 -0800173 qdf_lock_stats_init();
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530174 qdf_mem_init();
Houston Hoffman9e06e542016-12-12 12:06:26 -0800175 qdf_mc_timer_manager_init();
Nachiket Kukade0396b732017-11-14 16:35:16 +0530176 qdf_event_list_init();
Dustin Browna2dcb5f2017-10-20 17:36:19 -0700177 qdf_cpuhp_init();
Dustin Brown100201e2017-07-10 11:48:40 -0700178 qdf_register_self_recovery_callback(cds_trigger_recovery);
Rajeev Kumar807c5f52018-03-08 13:29:08 -0800179 qdf_register_fw_down_callback(cds_is_fw_down);
Ryan Hsud0327d52018-05-29 15:07:25 -0700180 qdf_register_ssr_protect_callbacks(cds_ssr_protect,
181 cds_ssr_unprotect);
182 qdf_register_module_state_query_callback(
183 cds_is_module_state_transitioning);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800184
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800185 gp_cds_context = &g_cds_context;
186
Anurag Chouhandf2b2682016-02-29 14:15:27 +0530187 gp_cds_context->qdf_ctx = &g_qdf_ctx;
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530188 qdf_mem_zero(&g_qdf_ctx, sizeof(g_qdf_ctx));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800189
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530190 qdf_trace_spin_lock_init();
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530191 qdf_trace_init();
Rachit Kankane0baf6e72018-01-19 15:01:50 +0530192
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +0530193 qdf_register_debugcb_init();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -0800194
195 cds_ssr_protect_init();
196
wadesongae4ffd12017-10-24 16:45:54 +0800197 ret = cds_recovery_work_init();
198 if (ret != QDF_STATUS_SUCCESS) {
199 cds_err("Failed to init recovery work");
200 goto deinit;
201 }
Srinivas Girigowda161b9f22017-07-24 17:38:09 -0700202
wadesongae4ffd12017-10-24 16:45:54 +0800203 return QDF_STATUS_SUCCESS;
204deinit:
Rachit Kankane45d8b8c2018-06-26 19:34:02 +0530205 qdf_trace_deinit();
wadesongae4ffd12017-10-24 16:45:54 +0800206 qdf_mc_timer_manager_exit();
207 qdf_mem_exit();
208 qdf_lock_stats_deinit();
209 qdf_debugfs_exit();
210 gp_cds_context->qdf_ctx = NULL;
211 gp_cds_context = NULL;
212 qdf_mem_zero(&g_cds_context, sizeof(g_cds_context));
wadesongae4ffd12017-10-24 16:45:54 +0800213 return ret;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -0800214}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800215
216/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -0800217 * cds_deinit() - Deinitialize CDS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800218 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -0800219 * This function frees the CDS resources
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800220 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -0800221void cds_deinit(void)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800222{
Prashanth Bhatta5da711e2015-11-30 14:28:52 -0800223 if (gp_cds_context == NULL)
224 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800225
Srinivas Girigowda161b9f22017-07-24 17:38:09 -0700226 cds_recovery_work_deinit();
Rachit Kankane45d8b8c2018-06-26 19:34:02 +0530227 qdf_trace_deinit();
Dustin Browna2dcb5f2017-10-20 17:36:19 -0700228 qdf_cpuhp_deinit();
Arunk Khandavalli4cc97a92016-09-14 23:13:07 +0530229 qdf_mc_timer_manager_exit();
230 qdf_mem_exit();
Houston Hoffman1a777572017-01-13 12:43:48 -0800231 qdf_lock_stats_deinit();
Mahesh Kumar Kalikot Veetil319dbcd2016-10-27 15:03:48 -0700232 qdf_debugfs_exit();
Nachiket Kukade0396b732017-11-14 16:35:16 +0530233 qdf_event_list_destroy();
Arunk Khandavalli4cc97a92016-09-14 23:13:07 +0530234
Anurag Chouhan6d760662016-02-20 16:05:43 +0530235 gp_cds_context->qdf_ctx = NULL;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -0800236 gp_cds_context = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800237
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530238 qdf_mem_zero(&g_cds_context, sizeof(g_cds_context));
Prashanth Bhatta5da711e2015-11-30 14:28:52 -0800239 return;
240}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800241
Abhishek Singh437606a2016-04-27 13:51:49 +0530242#ifdef FEATURE_WLAN_DIAG_SUPPORT
243/**
244 * cds_tdls_tx_rx_mgmt_event()- send tdls mgmt rx tx event
245 * @event_id: event id
246 * @tx_rx: tx or rx
247 * @type: type of frame
248 * @action_sub_type: action frame type
249 * @peer_mac: peer mac
250 *
251 * This Function sends tdls mgmt rx tx diag event
252 *
253 * Return: void.
254 */
255void cds_tdls_tx_rx_mgmt_event(uint8_t event_id, uint8_t tx_rx,
256 uint8_t type, uint8_t action_sub_type, uint8_t *peer_mac)
257{
258 WLAN_HOST_DIAG_EVENT_DEF(tdls_tx_rx_mgmt,
259 struct host_event_tdls_tx_rx_mgmt);
260
261 tdls_tx_rx_mgmt.event_id = event_id;
262 tdls_tx_rx_mgmt.tx_rx = tx_rx;
263 tdls_tx_rx_mgmt.type = type;
264 tdls_tx_rx_mgmt.action_sub_type = action_sub_type;
265 qdf_mem_copy(tdls_tx_rx_mgmt.peer_mac,
266 peer_mac, CDS_MAC_ADDRESS_LEN);
267 WLAN_HOST_DIAG_EVENT_REPORT(&tdls_tx_rx_mgmt,
268 EVENT_WLAN_TDLS_TX_RX_MGMT);
269}
270#endif
271
Leo Chang9b097032016-10-28 11:03:17 -0700272/**
gbian62edd7e2017-03-07 13:12:13 +0800273 * cds_cfg_update_ac_specs_params() - update ac_specs params
274 * @olcfg: cfg handle
275 * @mac_params: mac params
276 *
277 * Return: none
278 */
279static void
280cds_cfg_update_ac_specs_params(struct txrx_pdev_cfg_param_t *olcfg,
281 struct cds_config_info *cds_cfg)
282{
283 int i;
284
285 if (NULL == olcfg)
286 return;
287
288 if (NULL == cds_cfg)
289 return;
290
291 for (i = 0; i < OL_TX_NUM_WMM_AC; i++) {
292 olcfg->ac_specs[i].wrr_skip_weight =
293 cds_cfg->ac_specs[i].wrr_skip_weight;
294 olcfg->ac_specs[i].credit_threshold =
295 cds_cfg->ac_specs[i].credit_threshold;
296 olcfg->ac_specs[i].send_limit =
297 cds_cfg->ac_specs[i].send_limit;
298 olcfg->ac_specs[i].credit_reserve =
299 cds_cfg->ac_specs[i].credit_reserve;
300 olcfg->ac_specs[i].discard_weight =
301 cds_cfg->ac_specs[i].discard_weight;
302 }
303}
304
Nirav Shahe6c8e642018-03-25 11:42:48 +0530305#ifdef QCA_LL_TX_FLOW_CONTROL_V2
306static inline void
307cds_cdp_set_flow_control_params(struct cds_config_info *cds_cfg,
308 struct txrx_pdev_cfg_param_t *cdp_cfg)
309{
310 cdp_cfg->tx_flow_stop_queue_th = cds_cfg->tx_flow_stop_queue_th;
311 cdp_cfg->tx_flow_start_queue_offset =
312 cds_cfg->tx_flow_start_queue_offset;
313}
314#else
315static inline void
316cds_cdp_set_flow_control_params(struct cds_config_info *cds_cfg,
317 struct txrx_pdev_cfg_param_t *cdp_cfg)
318{}
319#endif
320
gbian62edd7e2017-03-07 13:12:13 +0800321/**
Leo Chang9b097032016-10-28 11:03:17 -0700322 * cds_cdp_cfg_attach() - attach data path config module
323 * @cds_cfg: generic platform level config instance
324 *
325 * Return: none
326 */
327static void cds_cdp_cfg_attach(struct cds_config_info *cds_cfg)
328{
329 struct txrx_pdev_cfg_param_t cdp_cfg = {0};
330 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
331
Kiran Kumar Lokere52d8dc32016-12-05 19:20:40 -0800332 cdp_cfg.is_full_reorder_offload = cds_cfg->reorder_offload;
Leo Chang9b097032016-10-28 11:03:17 -0700333 cdp_cfg.is_uc_offload_enabled = cds_cfg->uc_offload_enabled;
334 cdp_cfg.uc_tx_buffer_count = cds_cfg->uc_txbuf_count;
335 cdp_cfg.uc_tx_buffer_size = cds_cfg->uc_txbuf_size;
336 cdp_cfg.uc_rx_indication_ring_count = cds_cfg->uc_rxind_ringcount;
337 cdp_cfg.uc_tx_partition_base = cds_cfg->uc_tx_partition_base;
338 cdp_cfg.enable_rxthread = cds_cfg->enable_rxthread;
339 cdp_cfg.ip_tcp_udp_checksum_offload =
340 cds_cfg->ip_tcp_udp_checksum_offload;
341 cdp_cfg.ce_classify_enabled = cds_cfg->ce_classify_enabled;
342
gbian62edd7e2017-03-07 13:12:13 +0800343 cds_cfg_update_ac_specs_params(&cdp_cfg, cds_cfg);
Kiran Kumar Lokere9aecfee2016-11-23 17:37:42 -0800344 gp_cds_context->cfg_ctx = cdp_cfg_attach(soc, gp_cds_context->qdf_ctx,
345 (void *)(&cdp_cfg));
346 if (!gp_cds_context->cfg_ctx) {
347 WMA_LOGP("%s: failed to init cfg handle", __func__);
348 return;
349 }
350
Leo Chang9b097032016-10-28 11:03:17 -0700351 /* Configure Receive flow steering */
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -0800352 cdp_cfg_set_flow_steering(soc, gp_cds_context->cfg_ctx,
Leo Chang9b097032016-10-28 11:03:17 -0700353 cds_cfg->flow_steering_enabled);
354
Nirav Shahe6c8e642018-03-25 11:42:48 +0530355 cds_cdp_set_flow_control_params(cds_cfg, &cdp_cfg);
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -0800356 cdp_cfg_set_flow_control_parameters(soc, gp_cds_context->cfg_ctx,
Nirav Shahe6c8e642018-03-25 11:42:48 +0530357 (void *)&cdp_cfg);
Leo Chang9b097032016-10-28 11:03:17 -0700358
359 /* adjust the cfg_ctx default value based on setting */
360 cdp_cfg_set_rx_fwd_disabled(soc, gp_cds_context->cfg_ctx,
361 (uint8_t) cds_cfg->ap_disable_intrabss_fwd);
362
363 /*
364 * adjust the packet log enable default value
365 * based on CFG INI setting
366 */
367 cdp_cfg_set_packet_log_enabled(soc, gp_cds_context->cfg_ctx,
368 (uint8_t)cds_is_packet_log_enabled());
Yu Wang66a250b2017-07-19 11:46:40 +0800369
370 /* adjust the ptp rx option default value based on CFG INI setting */
371 cdp_cfg_set_ptp_rx_opt_enabled(soc, gp_cds_context->cfg_ctx,
372 (uint8_t)cds_is_ptp_rx_opt_enabled());
Leo Chang9b097032016-10-28 11:03:17 -0700373}
Krunal Sonid32c6bc2016-10-18 18:00:21 -0700374static QDF_STATUS cds_register_all_modules(void)
375{
376 QDF_STATUS status;
377
378 scheduler_register_wma_legacy_handler(&wma_mc_process_handler);
379 scheduler_register_sys_legacy_handler(&sys_mc_process_handler);
380
381 /* Register message queues in given order such that queue priority is
382 * intact:
383 * 1) QDF_MODULE_ID_SYS: Timer queue(legacy SYS queue)
384 * 2) QDF_MODULE_ID_TARGET_IF: Target interface queue
385 * 3) QDF_MODULE_ID_PE: Legacy PE message queue
386 * 4) QDF_MODULE_ID_SME: Legacy SME message queue
387 * 5) QDF_MODULE_ID_OS_IF: OS IF message queue for new components
388 */
389 status = scheduler_register_module(QDF_MODULE_ID_SYS,
390 &scheduler_timer_q_mq_handler);
391 status = scheduler_register_module(QDF_MODULE_ID_TARGET_IF,
392 &scheduler_target_if_mq_handler);
393 status = scheduler_register_module(QDF_MODULE_ID_PE,
394 &pe_mc_process_handler);
395 status = scheduler_register_module(QDF_MODULE_ID_SME,
396 &sme_mc_process_handler);
397 status = scheduler_register_module(QDF_MODULE_ID_OS_IF,
398 &scheduler_os_if_mq_handler);
Vignesh Viswanathancad91322018-04-04 17:44:28 +0530399 status = scheduler_register_module(QDF_MODULE_ID_SCAN,
400 &scheduler_scan_mq_handler);
Krunal Sonid32c6bc2016-10-18 18:00:21 -0700401 return status;
402}
403
404static QDF_STATUS cds_deregister_all_modules(void)
405{
406 QDF_STATUS status;
Krunal Sonie3399902017-02-01 09:51:42 -0800407
408 scheduler_deregister_wma_legacy_handler();
409 scheduler_deregister_sys_legacy_handler();
Krunal Sonid32c6bc2016-10-18 18:00:21 -0700410 status = scheduler_deregister_module(QDF_MODULE_ID_SYS);
Rajeev Kumara88b2dc2017-01-30 16:35:14 -0800411 status = scheduler_deregister_module(QDF_MODULE_ID_TARGET_IF);
Krunal Sonid32c6bc2016-10-18 18:00:21 -0700412 status = scheduler_deregister_module(QDF_MODULE_ID_PE);
413 status = scheduler_deregister_module(QDF_MODULE_ID_SME);
414 status = scheduler_deregister_module(QDF_MODULE_ID_OS_IF);
Krunal Sonie3399902017-02-01 09:51:42 -0800415
Krunal Sonid32c6bc2016-10-18 18:00:21 -0700416 return status;
417}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800418
419/**
gbian62edd7e2017-03-07 13:12:13 +0800420 * cds_set_ac_specs_params() - set ac_specs params in cds_config_info
421 * @cds_cfg: Pointer to cds_config_info
422 * @hdd_ctx: Pointer to hdd context
423 *
424 * Return: none
425 */
426static void
427cds_set_ac_specs_params(struct cds_config_info *cds_cfg)
428{
429 int i;
Jeff Johnson2b6982c2018-05-29 14:56:11 -0700430 struct cds_context *cds_ctx;
gbian62edd7e2017-03-07 13:12:13 +0800431
432 if (NULL == cds_cfg)
433 return;
434
435 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
436
437 if (!cds_ctx) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700438 cds_err("Invalid CDS Context");
gbian62edd7e2017-03-07 13:12:13 +0800439 return;
440 }
441
442 for (i = 0; i < OL_TX_NUM_WMM_AC; i++) {
443 cds_cfg->ac_specs[i] = cds_ctx->ac_specs[i];
444 }
445}
446
447/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800448 * cds_open() - open the CDS Module
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800449 *
450 * cds_open() function opens the CDS Scheduler
451 * Upon successful initialization:
452 * - All CDS submodules should have been initialized
453 *
454 * - The CDS scheduler should have opened
455 *
456 * - All the WLAN SW components should have been opened. This includes
457 * SYS, MAC, SME, WMA and TL.
458 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530459 * Return: QDF status
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800460 */
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +0530461QDF_STATUS cds_open(struct wlan_objmgr_psoc *psoc)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800462{
Dustin Brownf7971192017-10-25 14:54:37 -0700463 QDF_STATUS status;
Arun Khandavallic811dcc2016-06-26 07:37:21 +0530464 struct cds_config_info *cds_cfg;
Anurag Chouhan6d760662016-02-20 16:05:43 +0530465 qdf_device_t qdf_ctx;
Manikandan Mohan83c939c2017-04-13 20:23:07 -0700466 struct htc_init_info htcInfo;
Komal Seelamd9106492016-02-15 10:31:44 +0530467 struct ol_context *ol_ctx;
Komal Seelam3d202862016-02-24 18:43:24 +0530468 struct hif_opaque_softc *scn;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800469 void *HTCHandle;
Jeff Johnsonc18b26c2017-09-03 08:46:45 -0700470 struct hdd_context *hdd_ctx;
Jeff Johnson2b6982c2018-05-29 14:56:11 -0700471 struct cds_context *cds_ctx;
Jeff Johnsonec563952018-06-11 09:57:09 -0700472 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800473
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700474 cds_debug("Opening CDS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800475
Arun Khandavallic811dcc2016-06-26 07:37:21 +0530476 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
477 if (!cds_ctx) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700478 cds_alert("Trying to open CDS without a PreOpen");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530479 QDF_ASSERT(0);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530480 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800481 }
482
483 /* Initialize the timer module */
Anurag Chouhan210db072016-02-22 18:42:15 +0530484 qdf_timer_module_init();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800485
486 /* Initialize bug reporting structure */
487 cds_init_log_completion();
488
Jeff Johnson2ccd8152018-05-29 16:02:23 -0700489 status = qdf_event_create(&gp_cds_context->wma_complete_event);
Dustin Brownf7971192017-10-25 14:54:37 -0700490 if (QDF_IS_STATUS_ERROR(status)) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700491 cds_alert("Unable to init wma_complete_event");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530492 QDF_ASSERT(0);
Dustin Browna22671a2018-05-29 12:13:51 -0700493 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800494 }
495
Jeff Johnson323a6f02018-05-29 15:09:12 -0700496 hdd_ctx = (struct hdd_context *)(gp_cds_context->hdd_context);
Dustin Brownf7971192017-10-25 14:54:37 -0700497 if (!hdd_ctx || !hdd_ctx->config) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800498 /* Critical Error ... Cannot proceed further */
Arun Khandavallifae92942016-08-01 13:31:08 +0530499 cds_err("Hdd Context is Null");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530500 QDF_ASSERT(0);
Dustin Brownf7971192017-10-25 14:54:37 -0700501
502 status = QDF_STATUS_E_FAILURE;
Rajeev Kumar3e5ef0d2017-01-03 14:45:31 -0800503 goto err_wma_complete_event;
Arun Khandavallifae92942016-08-01 13:31:08 +0530504 }
Kabilan Kannan15cc6ac2016-11-12 22:25:14 -0800505
Dustin Brown44cde352017-12-04 13:14:46 -0800506 status = dispatcher_enable();
507 if (QDF_IS_STATUS_ERROR(status)) {
508 cds_err("Failed to enable dispatcher; status:%d", status);
509 goto err_wma_complete_event;
510 }
511
Arun Khandavallifae92942016-08-01 13:31:08 +0530512 /* Now Open the CDS Scheduler */
Dustin Brown0707ddf2017-09-20 15:31:56 -0700513 status = cds_sched_open(gp_cds_context,
514 &gp_cds_context->qdf_sched,
515 sizeof(cds_sched_context));
Dustin Brown0707ddf2017-09-20 15:31:56 -0700516 if (QDF_IS_STATUS_ERROR(status)) {
517 /* Critical Error ... Cannot proceed further */
518 cds_alert("Failed to open CDS Scheduler");
519 QDF_ASSERT(0);
Dustin Brown44cde352017-12-04 13:14:46 -0800520 goto err_dispatcher_disable;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800521 }
522
Anurag Chouhan6d760662016-02-20 16:05:43 +0530523 scn = cds_get_context(QDF_MODULE_ID_HIF);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800524 if (!scn) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700525 cds_alert("scn is null!");
Dustin Brownf7971192017-10-25 14:54:37 -0700526
527 status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800528 goto err_sched_close;
529 }
Arun Khandavallifae92942016-08-01 13:31:08 +0530530
Arun Khandavallifae92942016-08-01 13:31:08 +0530531 cds_cfg = cds_get_ini_config();
532 if (!cds_cfg) {
533 cds_err("Cds config is NULL");
534 QDF_ASSERT(0);
Dustin Brownf7971192017-10-25 14:54:37 -0700535
536 status = QDF_STATUS_E_FAILURE;
Arun Khandavallifae92942016-08-01 13:31:08 +0530537 goto err_sched_close;
538 }
Dustin Brownf7971192017-10-25 14:54:37 -0700539
Jeff Johnsonc18b26c2017-09-03 08:46:45 -0700540 hdd_enable_fastpath(hdd_ctx->config, scn);
Arun Khandavallifae92942016-08-01 13:31:08 +0530541
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800542 /* Initialize BMI and Download firmware */
Dustin Brownf7971192017-10-25 14:54:37 -0700543 ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
544 status = bmi_download_firmware(ol_ctx);
545 if (QDF_IS_STATUS_ERROR(status)) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700546 cds_alert("BMI FIALED status:%d", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800547 goto err_bmi_close;
548 }
Tiger Yu086b6992017-11-20 16:33:43 +0800549
550 hdd_wlan_update_target_info(hdd_ctx, scn);
551
Komal Seelam08633492016-02-24 18:05:07 +0530552 htcInfo.pContext = ol_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800553 htcInfo.TargetFailure = ol_target_failure;
Mukul Sharma4c60a7e2017-03-06 19:42:18 +0530554 htcInfo.TargetSendSuspendComplete =
555 pmo_ucfg_psoc_target_suspend_acknowledge;
556 htcInfo.target_initial_wakeup_cb = pmo_ucfg_psoc_handle_initial_wake_up;
557 htcInfo.target_psoc = (void *)psoc;
Anurag Chouhan6d760662016-02-20 16:05:43 +0530558 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800559
560 /* Create HTC */
561 gp_cds_context->htc_ctx =
Yue Ma1e11d792016-02-26 18:58:44 -0800562 htc_create(scn, &htcInfo, qdf_ctx, cds_get_conparam());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800563 if (!gp_cds_context->htc_ctx) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700564 cds_alert("Failed to Create HTC");
Dustin Brownf7971192017-10-25 14:54:37 -0700565
566 status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800567 goto err_bmi_close;
568 }
Mukul Sharma4c60a7e2017-03-06 19:42:18 +0530569 pmo_ucfg_psoc_update_htc_handle(psoc, (void *)gp_cds_context->htc_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800570
Dustin Brownf7971192017-10-25 14:54:37 -0700571 status = bmi_done(ol_ctx);
572 if (QDF_IS_STATUS_ERROR(status)) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700573 cds_alert("Failed to complete BMI phase");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800574 goto err_htc_close;
575 }
576
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800577 /*Open the WMA module */
bings482bae22018-01-17 16:25:31 +0800578 status = wma_open(psoc, hdd_update_tgt_cfg, cds_cfg,
579 hdd_ctx->target_type);
Dustin Brownf7971192017-10-25 14:54:37 -0700580 if (QDF_IS_STATUS_ERROR(status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800581 /* Critical Error ... Cannot proceed further */
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700582 cds_alert("Failed to open WMA module");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530583 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800584 goto err_htc_close;
585 }
586
587 /* Number of peers limit differs in each chip version. If peer max
588 * limit configured in ini exceeds more than supported, WMA adjusts
Arun Khandavallic811dcc2016-06-26 07:37:21 +0530589 * and keeps correct limit in cds_cfg.max_station. So, make sure
Jeff Johnsonc18b26c2017-09-03 08:46:45 -0700590 * config entry hdd_ctx->config->maxNumberOfPeers has adjusted value
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800591 */
Hanumanth Reddy Pothula47d29262016-10-03 16:08:04 +0530592 /* In FTM mode cds_cfg->max_stations will be zero. On updating same
593 * into hdd context config entry, leads to pe_open() to fail, if
594 * con_mode change happens from FTM mode to any other mode.
595 */
Srinivas Girigowda35b00312017-06-27 21:52:03 -0700596 if (QDF_DRIVER_TYPE_PRODUCTION == cds_cfg->driver_type)
Jeff Johnsonc18b26c2017-09-03 08:46:45 -0700597 hdd_ctx->config->maxNumberOfPeers = cds_cfg->max_station;
Hanumanth Reddy Pothula47d29262016-10-03 16:08:04 +0530598
Anurag Chouhan6d760662016-02-20 16:05:43 +0530599 HTCHandle = cds_get_context(QDF_MODULE_ID_HTC);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800600 if (!HTCHandle) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700601 cds_alert("HTCHandle is null!");
Dustin Brownf7971192017-10-25 14:54:37 -0700602
603 status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800604 goto err_wma_close;
605 }
Nachiket Kukadef44b33e2017-09-06 16:49:29 +0530606
Dustin Brownf7971192017-10-25 14:54:37 -0700607 status = htc_wait_target(HTCHandle);
608 if (QDF_IS_STATUS_ERROR(status)) {
609 cds_alert("Failed to complete BMI phase. status: %d", status);
Nachiket Kukade8003d252017-03-30 15:55:58 +0530610
Dustin Brownf7971192017-10-25 14:54:37 -0700611 if (status != QDF_STATUS_E_NOMEM && !cds_is_fw_down())
Nachiket Kukade8003d252017-03-30 15:55:58 +0530612 QDF_BUG(0);
613
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800614 goto err_wma_close;
615 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800616
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700617 cds_debug("target_type %d 8074:%d 6290:%d", hdd_ctx->target_type,
618 TARGET_TYPE_QCA8074, TARGET_TYPE_QCA6290);
Ravi Joshifc2ed782016-11-22 17:36:50 -0800619
Jeff Johnsonc18b26c2017-09-03 08:46:45 -0700620 if (TARGET_TYPE_QCA6290 == hdd_ctx->target_type)
Leo Chang9b097032016-10-28 11:03:17 -0700621 gp_cds_context->dp_soc = cdp_soc_attach(LITHIUM_DP,
Jeff Johnsona40e21c2018-05-29 15:59:57 -0700622 gp_cds_context->hif_context, psoc,
Leo Chang9b097032016-10-28 11:03:17 -0700623 gp_cds_context->htc_ctx, gp_cds_context->qdf_ctx,
Arunk Khandavallia6305a32018-01-25 11:19:18 +0530624 &dp_ol_if_ops);
Leo Chang9b097032016-10-28 11:03:17 -0700625 else
626 gp_cds_context->dp_soc = cdp_soc_attach(MOB_DRV_LEGACY_DP,
Jeff Johnsona40e21c2018-05-29 15:59:57 -0700627 gp_cds_context->hif_context, psoc,
Leo Chang9b097032016-10-28 11:03:17 -0700628 gp_cds_context->htc_ctx, gp_cds_context->qdf_ctx,
Arunk Khandavallia6305a32018-01-25 11:19:18 +0530629 &dp_ol_if_ops);
Leo Chang9b097032016-10-28 11:03:17 -0700630
Dustin Brownf7971192017-10-25 14:54:37 -0700631 if (!gp_cds_context->dp_soc) {
632 status = QDF_STATUS_E_FAILURE;
Manikandan Mohanfb9d2b52017-05-10 15:01:28 -0700633 goto err_wma_close;
Dustin Brownf7971192017-10-25 14:54:37 -0700634 }
Manikandan Mohanfb9d2b52017-05-10 15:01:28 -0700635
Lin Bai362e52b2018-05-07 14:42:50 +0800636 wlan_psoc_set_dp_handle(psoc, gp_cds_context->dp_soc);
Sravan Kumar Kairam27296782017-04-21 22:04:18 +0530637 pmo_ucfg_psoc_update_dp_handle(psoc, gp_cds_context->dp_soc);
Zhang Qian47e22ce2018-01-04 15:38:38 +0800638 ucfg_ocb_update_dp_handle(psoc, gp_cds_context->dp_soc);
Sravan Kumar Kairam27296782017-04-21 22:04:18 +0530639
gbian62edd7e2017-03-07 13:12:13 +0800640 cds_set_ac_specs_params(cds_cfg);
641
Leo Chang9b097032016-10-28 11:03:17 -0700642 cds_cdp_cfg_attach(cds_cfg);
643
Nirav Shaheb017be2018-02-15 11:20:58 +0530644 bmi_target_ready(scn, gp_cds_context->cfg_ctx);
645
Jeff Johnsond9f08602016-12-02 11:31:30 -0800646 /* Now proceed to open the MAC */
Jeff Johnsonec563952018-06-11 09:57:09 -0700647 status = mac_open(psoc, &mac_handle,
Jeff Johnsonac99e472018-06-07 23:00:08 -0700648 gp_cds_context->hdd_context, cds_cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800649
Jeff Johnsonac99e472018-06-07 23:00:08 -0700650 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800651 /* Critical Error ... Cannot proceed further */
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700652 cds_alert("Failed to open MAC");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530653 QDF_ASSERT(0);
Houston Hoffman59c9c912017-03-29 14:10:39 -0700654 goto err_soc_detach;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800655 }
Jeff Johnsonec563952018-06-11 09:57:09 -0700656 gp_cds_context->mac_context = mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800657
658 /* Now proceed to open the SME */
Jeff Johnsonec563952018-06-11 09:57:09 -0700659 status = sme_open(mac_handle);
Dustin Brownf7971192017-10-25 14:54:37 -0700660 if (QDF_IS_STATUS_ERROR(status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800661 /* Critical Error ... Cannot proceed further */
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700662 cds_alert("Failed to open SME");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530663 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800664 goto err_mac_close;
665 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800666
Krunal Sonid32c6bc2016-10-18 18:00:21 -0700667 cds_register_all_modules();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800668
Selvaraj, Sridhara7dc2382017-01-27 18:29:39 +0530669 return dispatcher_psoc_open(psoc);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800670
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800671err_mac_close:
Jeff Johnsonec563952018-06-11 09:57:09 -0700672 mac_close(mac_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800673
Houston Hoffman59c9c912017-03-29 14:10:39 -0700674err_soc_detach:
675 /* todo: add propper error handling */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800676err_wma_close:
Rajeev Kumar662d75d2017-03-13 18:11:29 -0700677 cds_shutdown_notifier_purge();
Jeff Johnson542da352017-09-13 09:17:28 -0700678 wma_close();
Jeff Johnson7b3ddc22017-09-13 09:42:44 -0700679 wma_wmi_service_close();
Sravan Kumar Kairam27296782017-04-21 22:04:18 +0530680 pmo_ucfg_psoc_update_dp_handle(psoc, NULL);
Lin Bai362e52b2018-05-07 14:42:50 +0800681 wlan_psoc_set_dp_handle(psoc, NULL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800682
683err_htc_close:
684 if (gp_cds_context->htc_ctx) {
685 htc_destroy(gp_cds_context->htc_ctx);
686 gp_cds_context->htc_ctx = NULL;
Sravan Kumar Kairam27296782017-04-21 22:04:18 +0530687 pmo_ucfg_psoc_update_htc_handle(psoc, NULL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800688 }
689
690err_bmi_close:
Komal Seelam5a6e5082016-02-24 17:59:09 +0530691 bmi_cleanup(ol_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800692
693err_sched_close:
Dustin Brown0707ddf2017-09-20 15:31:56 -0700694 if (QDF_IS_STATUS_ERROR(cds_sched_close())) {
695 cds_err("Failed to close CDS Scheduler");
696 QDF_ASSERT(false);
Hanumanth Reddy Pothula0b571432017-02-23 17:15:37 +0530697 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800698
Dustin Brown44cde352017-12-04 13:14:46 -0800699err_dispatcher_disable:
700 if (QDF_IS_STATUS_ERROR(dispatcher_disable()))
701 cds_err("Failed to disable dispatcher");
702
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800703err_wma_complete_event:
Jeff Johnson2ccd8152018-05-29 16:02:23 -0700704 qdf_event_destroy(&gp_cds_context->wma_complete_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800705
Dustin Brownf7971192017-10-25 14:54:37 -0700706 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800707} /* cds_open() */
708
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -0700709QDF_STATUS cds_dp_open(struct wlan_objmgr_psoc *psoc)
710{
711 if (cdp_txrx_intr_attach(gp_cds_context->dp_soc)
712 != QDF_STATUS_SUCCESS) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700713 cds_alert("Failed to attach interrupts");
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -0700714 goto close;
715 }
716
717 cds_set_context(QDF_MODULE_ID_TXRX,
718 cdp_pdev_attach(cds_get_context(QDF_MODULE_ID_SOC),
Sravan Kumar Kairam1cbfb002018-06-14 18:28:48 +0530719 (struct cdp_ctrl_objmgr_pdev *)gp_cds_context->cfg_ctx,
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -0700720 gp_cds_context->htc_ctx,
721 gp_cds_context->qdf_ctx, 0));
722 if (!gp_cds_context->pdev_txrx_ctx) {
723 /* Critical Error ... Cannot proceed further */
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700724 cds_alert("Failed to open TXRX");
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -0700725 QDF_ASSERT(0);
726 goto intr_close;
727 }
728
729 pmo_ucfg_psoc_set_txrx_handle(psoc, gp_cds_context->pdev_txrx_ctx);
Zhang Qian47e22ce2018-01-04 15:38:38 +0800730 ucfg_ocb_set_txrx_handle(psoc, gp_cds_context->pdev_txrx_ctx);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -0700731
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700732 cds_debug("CDS successfully Opened");
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -0700733
734 return 0;
735
736intr_close:
737 cdp_txrx_intr_detach(gp_cds_context->dp_soc);
738close:
739 return QDF_STATUS_E_FAILURE;
740}
741
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800742/**
743 * cds_pre_enable() - pre enable cds
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800744 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530745 * Return: QDF status
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800746 */
Jeff Johnson3a280122017-09-13 07:42:00 -0700747QDF_STATUS cds_pre_enable(void)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800748{
Dustin Brown9746bd62018-05-25 15:15:27 -0700749 QDF_STATUS status;
750 int errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800751 void *scn;
Jeff Johnson3a280122017-09-13 07:42:00 -0700752 void *soc;
Tiger Yu9973e362018-06-06 13:54:22 +0800753 void *hif_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800754
Dustin Brown9746bd62018-05-25 15:15:27 -0700755 cds_enter();
Jeff Johnson3a280122017-09-13 07:42:00 -0700756
757 if (!gp_cds_context) {
Dustin Brown9746bd62018-05-25 15:15:27 -0700758 cds_err("cds context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530759 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800760 }
761
Jeff Johnson830f3222018-05-29 15:58:18 -0700762 if (!gp_cds_context->wma_context) {
Dustin Brown9746bd62018-05-25 15:15:27 -0700763 cds_err("wma context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530764 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800765 }
766
Anurag Chouhan6d760662016-02-20 16:05:43 +0530767 scn = cds_get_context(QDF_MODULE_ID_HIF);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800768 if (!scn) {
Dustin Brown9746bd62018-05-25 15:15:27 -0700769 cds_err("hif context is null");
770 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800771 }
772
Jeff Johnson3a280122017-09-13 07:42:00 -0700773 soc = cds_get_context(QDF_MODULE_ID_SOC);
774 if (!soc) {
Dustin Brown9746bd62018-05-25 15:15:27 -0700775 cds_err("soc context is null");
776 return QDF_STATUS_E_INVAL;
Jeff Johnson3a280122017-09-13 07:42:00 -0700777 }
778
Nirav Shah7f337db2016-05-25 10:49:02 +0530779 /* call Packetlog connect service */
Arun Khandavallifae92942016-08-01 13:31:08 +0530780 if (QDF_GLOBAL_FTM_MODE != cds_get_conparam() &&
Leo Chang9b097032016-10-28 11:03:17 -0700781 QDF_GLOBAL_EPPING_MODE != cds_get_conparam())
Dustin Brown9746bd62018-05-25 15:15:27 -0700782 cdp_pkt_log_con_service(soc, gp_cds_context->pdev_txrx_ctx,
783 scn);
Nirav Shah7f337db2016-05-25 10:49:02 +0530784
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800785 /* Reset wma wait event */
Jeff Johnson2ccd8152018-05-29 16:02:23 -0700786 qdf_event_reset(&gp_cds_context->wma_complete_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800787
788 /*call WMA pre start */
Dustin Brown9746bd62018-05-25 15:15:27 -0700789 status = wma_pre_start();
790 if (QDF_IS_STATUS_ERROR(status)) {
791 cds_err("Failed to WMA prestart");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530792 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800793 }
794
795 /* Need to update time out of complete */
Dustin Brown9746bd62018-05-25 15:15:27 -0700796 status = qdf_wait_for_event_completion(
Jeff Johnson2ccd8152018-05-29 16:02:23 -0700797 &gp_cds_context->wma_complete_event,
Nachiket Kukade0396b732017-11-14 16:35:16 +0530798 CDS_WMA_TIMEOUT);
Dustin Brown9746bd62018-05-25 15:15:27 -0700799 if (QDF_IS_STATUS_ERROR(status)) {
800 cds_err("Failed to wait for WMA complete; status:%u", status);
Dustin Brownc30f3932018-05-25 16:48:23 -0700801 cds_trigger_recovery(QDF_REASON_UNSPECIFIED);
Dustin Brown9746bd62018-05-25 15:15:27 -0700802 goto exit_with_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800803 }
804
Dustin Brown9746bd62018-05-25 15:15:27 -0700805 status = htc_start(gp_cds_context->htc_ctx);
806 if (QDF_IS_STATUS_ERROR(status)) {
807 cds_err("Failed to Start HTC");
808 goto exit_with_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800809 }
810
Jeff Johnson830f3222018-05-29 15:58:18 -0700811 status = wma_wait_for_ready_event(gp_cds_context->wma_context);
Dustin Brown9746bd62018-05-25 15:15:27 -0700812 if (QDF_IS_STATUS_ERROR(status)) {
813 cds_err("Failed to wait for ready event; status: %u", status);
814 cds_trigger_recovery(QDF_REASON_UNSPECIFIED);
815 goto stop_wmi;
816 }
817
818 errno = cdp_pdev_post_attach(soc, gp_cds_context->pdev_txrx_ctx);
819 if (errno) {
820 cds_err("Failed to attach pdev");
821 status = qdf_status_from_os_return(errno);
822 goto stop_wmi;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800823 }
824
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530825 return QDF_STATUS_SUCCESS;
Dustin Brown9746bd62018-05-25 15:15:27 -0700826
827stop_wmi:
Tiger Yu9973e362018-06-06 13:54:22 +0800828 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
829 if (!hif_ctx)
830 cds_err("%s: Failed to get hif_handle!", __func__);
831
Dustin Brown9746bd62018-05-25 15:15:27 -0700832 wma_wmi_stop();
Tiger Yu9973e362018-06-06 13:54:22 +0800833
834 if (hif_ctx) {
835 cds_err("%s: Disable the isr & reset the soc!", __func__);
836 hif_disable_isr(hif_ctx);
837 hif_reset_soc(hif_ctx);
838 }
Dustin Brown9746bd62018-05-25 15:15:27 -0700839 htc_stop(gp_cds_context->htc_ctx);
840
841exit_with_status:
842 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800843}
844
845/**
846 * cds_enable() - start/enable cds module
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +0530847 * @psoc: Psoc pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800848 * @cds_context: CDS context
849 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530850 * Return: QDF status
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800851 */
Jeff Johnson8f9dd5f2017-09-13 14:16:08 -0700852QDF_STATUS cds_enable(struct wlan_objmgr_psoc *psoc)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800853{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530854 QDF_STATUS qdf_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800855 tHalMacStartParameters halStartParams;
856
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800857 /* We support only one instance for now ... */
Jeff Johnson8f9dd5f2017-09-13 14:16:08 -0700858 if (!gp_cds_context) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700859 cds_err("Invalid CDS context");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530860 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800861 }
862
Jeff Johnson830f3222018-05-29 15:58:18 -0700863 if ((!gp_cds_context->wma_context) ||
Jeff Johnson528c2cf2018-05-29 15:55:58 -0700864 (gp_cds_context->mac_context == NULL)) {
Jeff Johnson830f3222018-05-29 15:58:18 -0700865 if (!gp_cds_context->wma_context)
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700866 cds_err("WMA NULL context");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800867 else
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700868 cds_err("MAC NULL context");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800869
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530870 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800871 }
872
873 /* Start the wma */
Jeff Johnsond4892552017-09-13 08:41:31 -0700874 qdf_status = wma_start();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530875 if (qdf_status != QDF_STATUS_SUCCESS) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700876 cds_err("Failed to start wma");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530877 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800878 }
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700879 cds_info("wma correctly started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800880
881 /* Start the MAC */
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530882 qdf_mem_zero(&halStartParams,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800883 sizeof(tHalMacStartParameters));
884
885 /* Start the MAC */
Jeff Johnsonac99e472018-06-07 23:00:08 -0700886 qdf_status = mac_start(gp_cds_context->mac_context, &halStartParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800887
Jeff Johnsonac99e472018-06-07 23:00:08 -0700888 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700889 cds_alert("Failed to start MAC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800890 goto err_wma_stop;
891 }
892
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700893 cds_info("MAC correctly started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800894
895 /* START SME */
Jeff Johnson528c2cf2018-05-29 15:55:58 -0700896 qdf_status = sme_start(gp_cds_context->mac_context);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800897
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530898 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700899 cds_alert("Failed to start SME");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800900 goto err_mac_stop;
901 }
902
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700903 cds_info("SME correctly started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800904
Leo Chang9b097032016-10-28 11:03:17 -0700905 if (cdp_soc_attach_target(cds_get_context(QDF_MODULE_ID_SOC))) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700906 cds_alert("Failed to attach soc target");
Leo Chang9b097032016-10-28 11:03:17 -0700907 goto err_sme_stop;
908 }
909
910 if (cdp_pdev_attach_target(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -0800911 (struct cdp_pdev *)cds_get_context(QDF_MODULE_ID_TXRX))) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700912 cds_alert("Failed to attach pdev target");
Leo Chang9b097032016-10-28 11:03:17 -0700913 goto err_soc_target_detach;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800914 }
915
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700916 cds_info("CDS Start is successful!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800917
Min Liu81f2ed32018-01-08 14:21:02 +0800918 qdf_status = dispatcher_psoc_enable(psoc);
919 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700920 cds_alert("dispatcher_psoc_enable failed");
Min Liu81f2ed32018-01-08 14:21:02 +0800921 goto err_soc_target_detach;
922 }
Rajeev Kumar97767a02016-11-30 11:20:40 -0800923
Nachiket Kukade98f562a2017-12-15 12:18:07 +0530924 /* Trigger psoc enable for CLD components */
925 hdd_component_psoc_enable(psoc);
926
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530927 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800928
Leo Chang9b097032016-10-28 11:03:17 -0700929err_soc_target_detach:
930 /* NOOP */
931
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800932err_sme_stop:
Jeff Johnson528c2cf2018-05-29 15:55:58 -0700933 sme_stop(gp_cds_context->mac_context, HAL_STOP_TYPE_SYS_RESET);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800934
935err_mac_stop:
Jeff Johnson528c2cf2018-05-29 15:55:58 -0700936 mac_stop(gp_cds_context->mac_context, HAL_STOP_TYPE_SYS_RESET);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800937
938err_wma_stop:
Jeff Johnson2ccd8152018-05-29 16:02:23 -0700939 qdf_event_reset(&gp_cds_context->wma_complete_event);
Jeff Johnsonacc1cc72017-09-13 08:47:49 -0700940 qdf_status = wma_stop(HAL_STOP_TYPE_RF_KILL);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530941 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700942 cds_err("Failed to stop wma");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530943 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Jeff Johnson1f8d0a02017-09-13 08:09:05 -0700944 wma_setneedshutdown();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800945 } else {
Anurag Chouhance0dc992016-02-16 18:18:03 +0530946 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +0530947 qdf_wait_for_event_completion(
Jeff Johnson2ccd8152018-05-29 16:02:23 -0700948 &gp_cds_context->wma_complete_event,
Nachiket Kukade0396b732017-11-14 16:35:16 +0530949 CDS_WMA_TIMEOUT);
Anurag Chouhance0dc992016-02-16 18:18:03 +0530950 if (qdf_status != QDF_STATUS_SUCCESS) {
951 if (qdf_status == QDF_STATUS_E_TIMEOUT) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700952 cds_alert("Timeout occurred before WMA_stop complete");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800953 } else {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700954 cds_alert("WMA_stop reporting other error");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800955 }
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530956 QDF_ASSERT(0);
Jeff Johnson1f8d0a02017-09-13 08:09:05 -0700957 wma_setneedshutdown();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800958 }
959 }
960
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530961 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800962} /* cds_enable() */
963
964/**
965 * cds_disable() - stop/disable cds module
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +0530966 * @psoc: Psoc pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800967 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530968 * Return: QDF status
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800969 */
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -0700970QDF_STATUS cds_disable(struct wlan_objmgr_psoc *psoc)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800971{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530972 QDF_STATUS qdf_status;
Arun Khandavallifae92942016-08-01 13:31:08 +0530973 void *handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800974
Rajeev Kumar97767a02016-11-30 11:20:40 -0800975 /* PSOC disable for all new components. It needs to happen before
976 * target is PDEV suspended such that a component can abort all its
977 * ongoing transaction with FW. Always keep it before wma_stop() as
978 * wma_stop() does target PDEV suspend.
979 */
Rajeev Kumar97767a02016-11-30 11:20:40 -0800980
Nachiket Kukade98f562a2017-12-15 12:18:07 +0530981 /* Trigger psoc disable for CLD components */
982 if (psoc) {
983 hdd_component_psoc_disable(psoc);
Jiachao Wu341d0752018-01-02 15:20:32 +0800984 dispatcher_psoc_disable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +0530985 }
Rajeev Kumar97767a02016-11-30 11:20:40 -0800986
Jeff Johnsonacc1cc72017-09-13 08:47:49 -0700987 qdf_status = wma_stop(HAL_STOP_TYPE_RF_KILL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800988
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530989 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Arun Khandavallifae92942016-08-01 13:31:08 +0530990 cds_err("Failed to stop wma");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530991 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Jeff Johnson1f8d0a02017-09-13 08:09:05 -0700992 wma_setneedshutdown();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800993 }
994
Arun Khandavallifae92942016-08-01 13:31:08 +0530995 handle = cds_get_context(QDF_MODULE_ID_PE);
996 if (!handle) {
997 cds_err("Invalid PE context return!");
998 return QDF_STATUS_E_INVAL;
999 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001000
Naveen Rawatbcd3d012017-12-05 11:11:55 -08001001 umac_stop();
Arun Khandavalli55f890b2016-08-31 18:14:56 +05301002
Arun Khandavallifae92942016-08-01 13:31:08 +05301003 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001004}
1005
Govind Singhb048e872016-09-27 22:07:43 +05301006#ifdef HIF_USB
1007static inline void cds_suspend_target(tp_wma_handle wma_handle)
1008{
1009 QDF_STATUS status;
1010 /* Suspend the target and disable interrupt */
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301011 status = pmo_ucfg_psoc_suspend_target(wma_handle->psoc, 0);
Govind Singhb048e872016-09-27 22:07:43 +05301012 if (status)
1013 cds_err("Failed to suspend target, status = %d", status);
1014}
1015#else
1016static inline void cds_suspend_target(tp_wma_handle wma_handle)
1017{
1018 QDF_STATUS status;
1019 /* Suspend the target and disable interrupt */
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301020 status = pmo_ucfg_psoc_suspend_target(wma_handle->psoc, 1);
Govind Singhb048e872016-09-27 22:07:43 +05301021 if (status)
1022 cds_err("Failed to suspend target, status = %d", status);
1023}
1024#endif /* HIF_USB */
1025
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001026/**
Govind Singhb048e872016-09-27 22:07:43 +05301027 * cds_post_disable() - post disable cds module
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001028 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05301029 * Return: QDF status
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001030 */
Rajeev Kumarbe021242017-02-16 16:12:23 -08001031QDF_STATUS cds_post_disable(void)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001032{
Arun Khandavalli55f890b2016-08-31 18:14:56 +05301033 tp_wma_handle wma_handle;
Govind Singhb048e872016-09-27 22:07:43 +05301034 struct hif_opaque_softc *hif_ctx;
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05301035 struct cdp_pdev *txrx_pdev;
1036
Arun Khandavalli55f890b2016-08-31 18:14:56 +05301037 wma_handle = cds_get_context(QDF_MODULE_ID_WMA);
1038 if (!wma_handle) {
1039 cds_err("Failed to get wma_handle!");
1040 return QDF_STATUS_E_INVAL;
1041 }
1042
Govind Singhb048e872016-09-27 22:07:43 +05301043 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
1044 if (!hif_ctx) {
1045 cds_err("Failed to get hif_handle!");
1046 return QDF_STATUS_E_INVAL;
1047 }
1048
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05301049 txrx_pdev = cds_get_context(QDF_MODULE_ID_TXRX);
1050 if (!txrx_pdev) {
1051 cds_err("Failed to get txrx pdev!");
1052 return QDF_STATUS_E_INVAL;
1053 }
1054
Arun Khandavalli55f890b2016-08-31 18:14:56 +05301055 /*
1056 * With new state machine changes cds_close can be invoked without
1057 * cds_disable. So, send the following clean up prerequisites to fw,
1058 * So Fw and host are in sync for cleanup indication:
1059 * - Send PDEV_SUSPEND indication to firmware
1060 * - Disable HIF Interrupts.
1061 * - Clean up CE tasklets.
1062 */
1063
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301064 cds_info("send deinit sequence to firmware");
1065 if (!(cds_is_driver_recovering() || cds_is_driver_in_bad_state()))
Govind Singhb048e872016-09-27 22:07:43 +05301066 cds_suspend_target(wma_handle);
1067 hif_disable_isr(hif_ctx);
1068 hif_reset_soc(hif_ctx);
1069
Wu Gao9a24fa72017-07-28 18:32:22 +08001070 if (gp_cds_context->htc_ctx) {
Kabilan Kannanfc3a8c02018-02-21 13:36:29 -08001071 wma_wmi_stop();
Wu Gao9a24fa72017-07-28 18:32:22 +08001072 htc_stop(gp_cds_context->htc_ctx);
1073 }
1074
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05301075 cdp_pdev_pre_detach(cds_get_context(QDF_MODULE_ID_SOC),
1076 (struct cdp_pdev *)txrx_pdev, 1);
1077
Govind Singhb048e872016-09-27 22:07:43 +05301078 return QDF_STATUS_SUCCESS;
1079}
1080
1081/**
1082 * cds_close() - close cds module
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301083 * @psoc: Psoc pointer
Govind Singhb048e872016-09-27 22:07:43 +05301084 *
1085 * This API allows user to close modules registered
1086 * with connectivity device services.
1087 *
1088 * Return: QDF status
1089 */
Jeff Johnsone4b14592017-09-13 14:23:33 -07001090QDF_STATUS cds_close(struct wlan_objmgr_psoc *psoc)
Govind Singhb048e872016-09-27 22:07:43 +05301091{
1092 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001093
Dustin Brownd33276b2017-11-29 11:08:11 -08001094 qdf_status = cds_sched_close();
1095 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
1096 if (QDF_IS_STATUS_ERROR(qdf_status))
1097 cds_err("Failed to close CDS Scheduler");
1098
Dustin Brown44cde352017-12-04 13:14:46 -08001099 qdf_status = dispatcher_disable();
1100 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
1101 if (QDF_IS_STATUS_ERROR(qdf_status))
1102 cds_err("Failed to disable dispatcher; status:%d", qdf_status);
1103
Amar Singhal966397f2017-04-06 18:28:56 -07001104 dispatcher_psoc_close(psoc);
1105
Jeff Johnson6b8473d2017-09-13 09:20:53 -07001106 qdf_status = wma_wmi_work_close();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301107 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001108 cds_err("Failed to close wma_wmi_work");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301109 QDF_ASSERT(0);
Xun Luoa858a472015-11-10 08:24:45 -08001110 }
1111
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001112 if (gp_cds_context->htc_ctx) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001113 htc_destroy(gp_cds_context->htc_ctx);
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301114 pmo_ucfg_psoc_update_htc_handle(psoc, NULL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001115 gp_cds_context->htc_ctx = NULL;
1116 }
1117
Jeff Johnson528c2cf2018-05-29 15:55:58 -07001118 qdf_status = sme_close(gp_cds_context->mac_context);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301119 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001120 cds_err("Failed to close SME");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301121 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001122 }
1123
Jeff Johnson528c2cf2018-05-29 15:55:58 -07001124 qdf_status = mac_close(gp_cds_context->mac_context);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301125 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001126 cds_err("Failed to close MAC");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301127 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001128 }
1129
Jeff Johnson528c2cf2018-05-29 15:55:58 -07001130 gp_cds_context->mac_context = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001131
Houston Hoffmanbe58cc52016-12-19 16:26:44 -08001132 cdp_soc_detach(gp_cds_context->dp_soc);
Sravan Kumar Kairam27296782017-04-21 22:04:18 +05301133 pmo_ucfg_psoc_update_dp_handle(psoc, NULL);
Lin Bai362e52b2018-05-07 14:42:50 +08001134 wlan_psoc_set_dp_handle(psoc, NULL);
Houston Hoffmanbe58cc52016-12-19 16:26:44 -08001135
Rajeev Kumar662d75d2017-03-13 18:11:29 -07001136 cds_shutdown_notifier_purge();
1137
Jeff Johnson1b5404e2017-09-13 08:04:46 -07001138 if (true == wma_needshutdown()) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001139 cds_err("Failed to shutdown wma");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001140 } else {
Jeff Johnson542da352017-09-13 09:17:28 -07001141 qdf_status = wma_close();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301142 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001143 cds_err("Failed to close wma");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301144 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001145 }
1146 }
1147
Jeff Johnson7b3ddc22017-09-13 09:42:44 -07001148 qdf_status = wma_wmi_service_close();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301149 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001150 cds_err("Failed to close wma_wmi_service");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301151 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001152 }
1153
Jeff Johnson2ccd8152018-05-29 16:02:23 -07001154 qdf_status = qdf_event_destroy(&gp_cds_context->wma_complete_event);
Anurag Chouhance0dc992016-02-16 18:18:03 +05301155 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001156 cds_err("failed to destroy wma_complete_event");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301157 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001158 }
1159
Arun Khandavallic811dcc2016-06-26 07:37:21 +05301160 cds_deinit_ini_config();
Arun Khandavallifae92942016-08-01 13:31:08 +05301161 qdf_timer_module_deinit();
1162
Krunal Sonid32c6bc2016-10-18 18:00:21 -07001163 cds_deregister_all_modules();
Rajeev Kumar97767a02016-11-30 11:20:40 -08001164
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301165 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001166}
1167
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07001168QDF_STATUS cds_dp_close(struct wlan_objmgr_psoc *psoc)
1169{
1170 void *ctx;
1171
1172 cdp_txrx_intr_detach(gp_cds_context->dp_soc);
1173
1174 ctx = cds_get_context(QDF_MODULE_ID_TXRX);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07001175 cdp_pdev_detach(cds_get_context(QDF_MODULE_ID_SOC),
1176 (struct cdp_pdev *)ctx, 1);
psimhadeea0a12017-12-18 14:50:02 -08001177 cds_set_context(QDF_MODULE_ID_TXRX, NULL);
1178 pmo_ucfg_psoc_set_txrx_handle(psoc, NULL);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07001179
1180 return QDF_STATUS_SUCCESS;
1181}
1182
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001183/**
1184 * cds_get_context() - get context data area
1185 *
Jeff Johnsonb3be6a62018-05-30 18:50:12 -07001186 * @module_id: ID of the module who's context data is being retrieved.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001187 *
1188 * Each module in the system has a context / data area that is allocated
1189 * and managed by CDS. This API allows any user to get a pointer to its
1190 * allocated context data area from the CDS global context.
1191 *
1192 * Return: pointer to the context data area of the module ID
1193 * specified, or NULL if the context data is not allocated for
1194 * the module ID specified
1195 */
Jeff Johnsonb3be6a62018-05-30 18:50:12 -07001196void *cds_get_context(QDF_MODULE_ID module_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001197{
Jeff Johnson835b7602018-05-30 19:06:24 -07001198 void *context = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001199
1200 if (gp_cds_context == NULL) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001201 cds_err("cds context pointer is null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001202 return NULL;
1203 }
1204
Jeff Johnsonb3be6a62018-05-30 18:50:12 -07001205 switch (module_id) {
Anurag Chouhan6d760662016-02-20 16:05:43 +05301206 case QDF_MODULE_ID_HDD:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001207 {
Jeff Johnson835b7602018-05-30 19:06:24 -07001208 context = gp_cds_context->hdd_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001209 break;
1210 }
1211
Anurag Chouhan6d760662016-02-20 16:05:43 +05301212 case QDF_MODULE_ID_SME:
1213 case QDF_MODULE_ID_PE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001214 {
1215 /* In all these cases, we just return the MAC Context */
Jeff Johnson835b7602018-05-30 19:06:24 -07001216 context = gp_cds_context->mac_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001217 break;
1218 }
1219
Anurag Chouhan6d760662016-02-20 16:05:43 +05301220 case QDF_MODULE_ID_WMA:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001221 {
1222 /* For wma module */
Jeff Johnson835b7602018-05-30 19:06:24 -07001223 context = gp_cds_context->wma_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001224 break;
1225 }
1226
Anurag Chouhan6d760662016-02-20 16:05:43 +05301227 case QDF_MODULE_ID_QDF:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001228 {
1229 /* For SYS this is CDS itself */
Jeff Johnson835b7602018-05-30 19:06:24 -07001230 context = gp_cds_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001231 break;
1232 }
1233
Anurag Chouhan6d760662016-02-20 16:05:43 +05301234 case QDF_MODULE_ID_HIF:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001235 {
Jeff Johnson835b7602018-05-30 19:06:24 -07001236 context = gp_cds_context->hif_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001237 break;
1238 }
1239
Anurag Chouhan6d760662016-02-20 16:05:43 +05301240 case QDF_MODULE_ID_HTC:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001241 {
Jeff Johnson835b7602018-05-30 19:06:24 -07001242 context = gp_cds_context->htc_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001243 break;
1244 }
1245
Anurag Chouhan6d760662016-02-20 16:05:43 +05301246 case QDF_MODULE_ID_QDF_DEVICE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001247 {
Jeff Johnson835b7602018-05-30 19:06:24 -07001248 context = gp_cds_context->qdf_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001249 break;
1250 }
1251
Anurag Chouhan6d760662016-02-20 16:05:43 +05301252 case QDF_MODULE_ID_BMI:
Komal Seelamd9106492016-02-15 10:31:44 +05301253 {
Jeff Johnson835b7602018-05-30 19:06:24 -07001254 context = gp_cds_context->g_ol_context;
Komal Seelamd9106492016-02-15 10:31:44 +05301255 break;
1256 }
1257
Anurag Chouhan6d760662016-02-20 16:05:43 +05301258 case QDF_MODULE_ID_TXRX:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001259 {
Jeff Johnson835b7602018-05-30 19:06:24 -07001260 context = (void *)gp_cds_context->pdev_txrx_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001261 break;
1262 }
1263
Anurag Chouhan6d760662016-02-20 16:05:43 +05301264 case QDF_MODULE_ID_CFG:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001265 {
Jeff Johnson835b7602018-05-30 19:06:24 -07001266 context = gp_cds_context->cfg_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001267 break;
1268 }
1269
Leo Chang9b097032016-10-28 11:03:17 -07001270 case QDF_MODULE_ID_SOC:
1271 {
Jeff Johnson835b7602018-05-30 19:06:24 -07001272 context = gp_cds_context->dp_soc;
Leo Chang9b097032016-10-28 11:03:17 -07001273 break;
1274 }
1275
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001276 default:
1277 {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001278 cds_err("Module ID %i does not have its context maintained by CDS",
1279 module_id);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301280 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001281 return NULL;
1282 }
1283 }
1284
Jeff Johnson835b7602018-05-30 19:06:24 -07001285 if (!context)
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001286 cds_err("Module ID %i context is Null", module_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001287
Jeff Johnson835b7602018-05-30 19:06:24 -07001288 return context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001289} /* cds_get_context() */
1290
1291/**
1292 * cds_get_global_context() - get CDS global Context
1293 *
1294 * This API allows any user to get the CDS Global Context pointer from a
1295 * module context data area.
1296 *
1297 * Return: pointer to the CDS global context, NULL if the function is
Jeff Johnson6bb5d782018-05-11 14:52:18 -07001298 * unable to retrieve the CDS context.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001299 */
Jeff Johnson31a67582017-09-26 14:54:28 -07001300void *cds_get_global_context(void)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001301{
1302 if (gp_cds_context == NULL) {
Ryan Hsuceddceb2016-04-28 10:20:14 -07001303 /*
1304 * To avoid recursive call, this should not change to
1305 * QDF_TRACE().
1306 */
1307 pr_err("%s: global cds context is NULL", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001308 }
1309
1310 return gp_cds_context;
1311} /* cds_get_global_context() */
1312
1313/**
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001314 * cds_get_driver_state() - Get current driver state
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001315 *
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001316 * This API returns current driver state stored in global context.
1317 *
1318 * Return: Driver state enum
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001319 */
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001320enum cds_driver_state cds_get_driver_state(void)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001321{
1322 if (gp_cds_context == NULL) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001323 cds_err("global cds context is NULL");
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001324
1325 return CDS_DRIVER_STATE_UNINITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001326 }
1327
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001328 return gp_cds_context->driver_state;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001329}
1330
1331/**
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001332 * cds_set_driver_state() - Set current driver state
1333 * @state: Driver state to be set to.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001334 *
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001335 * This API sets driver state to state. This API only sets the state and doesn't
1336 * clear states, please make sure to use cds_clear_driver_state to clear any
1337 * state if required.
1338 *
1339 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001340 */
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001341void cds_set_driver_state(enum cds_driver_state state)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001342{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001343 if (gp_cds_context == NULL) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001344 cds_err("global cds context is NULL: %x", state);
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001345
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001346 return;
1347 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001348
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001349 gp_cds_context->driver_state |= state;
1350}
1351
1352/**
1353 * cds_clear_driver_state() - Clear current driver state
1354 * @state: Driver state to be cleared.
1355 *
1356 * This API clears driver state. This API only clears the state, please make
1357 * sure to use cds_set_driver_state to set any new states.
1358 *
1359 * Return: None
1360 */
1361void cds_clear_driver_state(enum cds_driver_state state)
1362{
1363 if (gp_cds_context == NULL) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001364 cds_err("global cds context is NULL: %x", state);
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001365
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001366 return;
1367 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001368
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001369 gp_cds_context->driver_state &= ~state;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001370}
1371
Nachiket Kukade8003d252017-03-30 15:55:58 +05301372enum cds_fw_state cds_get_fw_state(void)
1373{
1374 if (gp_cds_context == NULL) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001375 cds_err("global cds context is NULL");
Nachiket Kukade8003d252017-03-30 15:55:58 +05301376
1377 return CDS_FW_STATE_UNINITIALIZED;
1378 }
1379
1380 return gp_cds_context->fw_state;
1381}
1382
1383void cds_set_fw_state(enum cds_fw_state state)
1384{
1385 if (gp_cds_context == NULL) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001386 cds_err("global cds context is NULL: %d", state);
Nachiket Kukade8003d252017-03-30 15:55:58 +05301387
1388 return;
1389 }
1390
1391 qdf_atomic_set_bit(state, &gp_cds_context->fw_state);
1392}
1393
1394void cds_clear_fw_state(enum cds_fw_state state)
1395{
1396 if (gp_cds_context == NULL) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001397 cds_err("global cds context is NULL: %d", state);
Nachiket Kukade8003d252017-03-30 15:55:58 +05301398
1399 return;
1400 }
1401
1402 qdf_atomic_clear_bit(state, &gp_cds_context->fw_state);
1403}
1404
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001405/**
1406 * cds_alloc_context() - allocate a context within the CDS global Context
Jeff Johnsonb3be6a62018-05-30 18:50:12 -07001407 * @module_id: module ID who's context area is being allocated.
Jeff Johnson13269962018-05-30 19:16:46 -07001408 * @module_context: pointer to location where the pointer to the
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001409 * allocated context is returned. Note this output pointer
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301410 * is valid only if the API returns QDF_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001411 * @param size: size of the context area to be allocated.
1412 *
1413 * This API allows any user to allocate a user context area within the
1414 * CDS Global Context.
1415 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05301416 * Return: QDF status
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001417 */
Jeff Johnsonb3be6a62018-05-30 18:50:12 -07001418QDF_STATUS cds_alloc_context(QDF_MODULE_ID module_id,
Jeff Johnson13269962018-05-30 19:16:46 -07001419 void **module_context, uint32_t size)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001420{
Jeff Johnson835b7602018-05-30 19:06:24 -07001421 void **cds_mod_context = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001422
Jeff Johnsonadb3b1c2017-09-13 10:42:36 -07001423 if (!gp_cds_context) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001424 cds_err("cds context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301425 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001426 }
1427
Jeff Johnson13269962018-05-30 19:16:46 -07001428 if (!module_context) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001429 cds_err("null param passed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301430 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001431 }
1432
Jeff Johnsonb3be6a62018-05-30 18:50:12 -07001433 switch (module_id) {
Anurag Chouhan6d760662016-02-20 16:05:43 +05301434 case QDF_MODULE_ID_WMA:
Jeff Johnson835b7602018-05-30 19:06:24 -07001435 cds_mod_context = &gp_cds_context->wma_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001436 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001437
Anurag Chouhan6d760662016-02-20 16:05:43 +05301438 case QDF_MODULE_ID_HIF:
Jeff Johnson835b7602018-05-30 19:06:24 -07001439 cds_mod_context = &gp_cds_context->hif_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001440 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001441
Anurag Chouhan6d760662016-02-20 16:05:43 +05301442 case QDF_MODULE_ID_BMI:
Jeff Johnson835b7602018-05-30 19:06:24 -07001443 cds_mod_context = &gp_cds_context->g_ol_context;
Komal Seelamd9106492016-02-15 10:31:44 +05301444 break;
Komal Seelamd9106492016-02-15 10:31:44 +05301445
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001446 default:
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001447 cds_err("Module ID %i does not have its context allocated by CDS",
1448 module_id);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301449 QDF_ASSERT(0);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301450 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001451 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001452
Jeff Johnson835b7602018-05-30 19:06:24 -07001453 if (*cds_mod_context) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001454 /* Context has already been allocated!
1455 * Prevent double allocation
1456 */
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001457 cds_err("Module ID %i context has already been allocated",
1458 module_id);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301459 return QDF_STATUS_E_EXISTS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001460 }
1461
1462 /* Dynamically allocate the context for module */
1463
Jeff Johnson13269962018-05-30 19:16:46 -07001464 *module_context = qdf_mem_malloc(size);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001465
Jeff Johnson13269962018-05-30 19:16:46 -07001466 if (!*module_context) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001467 cds_err("Failed to allocate Context for module ID %i",
1468 module_id);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301469 QDF_ASSERT(0);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301470 return QDF_STATUS_E_NOMEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001471 }
1472
Jeff Johnson13269962018-05-30 19:16:46 -07001473 *cds_mod_context = *module_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001474
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301475 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001476} /* cds_alloc_context() */
1477
1478/**
Komal Seelamad5a90d2016-02-16 13:50:03 +05301479 * cds_set_context() - API to set context in global CDS Context
Komal Seelam1aac1982016-03-02 15:57:26 +05301480 * @module_id: Module ID
Komal Seelamad5a90d2016-02-16 13:50:03 +05301481 * @context: Pointer to the Module Context
1482 *
Komal Seelam1aac1982016-03-02 15:57:26 +05301483 * API to set a MODULE Context in global CDS Context
Komal Seelamad5a90d2016-02-16 13:50:03 +05301484 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301485 * Return: QDF_STATUS
Komal Seelamad5a90d2016-02-16 13:50:03 +05301486 */
Anurag Chouhan6d760662016-02-20 16:05:43 +05301487QDF_STATUS cds_set_context(QDF_MODULE_ID module_id, void *context)
Komal Seelamad5a90d2016-02-16 13:50:03 +05301488{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07001489 struct cds_context *p_cds_context = cds_get_global_context();
Komal Seelamad5a90d2016-02-16 13:50:03 +05301490
1491 if (!p_cds_context) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001492 cds_err("cds context is Invalid");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301493 return QDF_STATUS_NOT_INITIALIZED;
Komal Seelamad5a90d2016-02-16 13:50:03 +05301494 }
1495
1496 switch (module_id) {
Jeff Johnson3543fb22017-09-24 13:44:13 -07001497 case QDF_MODULE_ID_HDD:
Jeff Johnson323a6f02018-05-29 15:09:12 -07001498 p_cds_context->hdd_context = context;
Jeff Johnson3543fb22017-09-24 13:44:13 -07001499 break;
Houston Hoffman57c36d72017-01-30 12:47:02 -08001500 case QDF_MODULE_ID_TXRX:
1501 p_cds_context->pdev_txrx_ctx = context;
1502 break;
Anurag Chouhan6d760662016-02-20 16:05:43 +05301503 case QDF_MODULE_ID_HIF:
Jeff Johnsona40e21c2018-05-29 15:59:57 -07001504 p_cds_context->hif_context = context;
Komal Seelamad5a90d2016-02-16 13:50:03 +05301505 break;
1506 default:
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001507 cds_err("Module ID %i does not have its context managed by CDS",
1508 module_id);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301509 QDF_ASSERT(0);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301510 return QDF_STATUS_E_INVAL;
Komal Seelamad5a90d2016-02-16 13:50:03 +05301511 }
1512
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301513 return QDF_STATUS_SUCCESS;
Komal Seelamad5a90d2016-02-16 13:50:03 +05301514}
1515
1516/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001517 * cds_free_context() - free an allocated context within the
1518 * CDS global Context
Jeff Johnsonb3be6a62018-05-30 18:50:12 -07001519 * @module_id: module ID who's context area is being free
Jeff Johnson13269962018-05-30 19:16:46 -07001520 * @module_context: pointer to module context area to be free'd.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001521 *
1522 * This API allows a user to free the user context area within the
1523 * CDS Global Context.
1524 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05301525 * Return: QDF status
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001526 */
Jeff Johnson13269962018-05-30 19:16:46 -07001527QDF_STATUS cds_free_context(QDF_MODULE_ID module_id, void *module_context)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001528{
Jeff Johnson835b7602018-05-30 19:06:24 -07001529 void **cds_mod_context = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001530
Jeff Johnsonadb3b1c2017-09-13 10:42:36 -07001531 if (!gp_cds_context) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001532 cds_err("cds context is null");
Jeff Johnsonadb3b1c2017-09-13 10:42:36 -07001533 return QDF_STATUS_E_FAILURE;
1534 }
1535
Jeff Johnson13269962018-05-30 19:16:46 -07001536 if (!module_context) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001537 cds_err("Null param");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301538 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001539 }
1540
Jeff Johnsonb3be6a62018-05-30 18:50:12 -07001541 switch (module_id) {
Anurag Chouhan6d760662016-02-20 16:05:43 +05301542 case QDF_MODULE_ID_WMA:
Jeff Johnson835b7602018-05-30 19:06:24 -07001543 cds_mod_context = &gp_cds_context->wma_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001544 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001545
Anurag Chouhan6d760662016-02-20 16:05:43 +05301546 case QDF_MODULE_ID_HIF:
Jeff Johnson835b7602018-05-30 19:06:24 -07001547 cds_mod_context = &gp_cds_context->hif_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001548 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001549
Anurag Chouhan6d760662016-02-20 16:05:43 +05301550 case QDF_MODULE_ID_TXRX:
Jeff Johnson835b7602018-05-30 19:06:24 -07001551 cds_mod_context = (void **)&gp_cds_context->pdev_txrx_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001552 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001553
Anurag Chouhan6d760662016-02-20 16:05:43 +05301554 case QDF_MODULE_ID_BMI:
Jeff Johnson835b7602018-05-30 19:06:24 -07001555 cds_mod_context = &gp_cds_context->g_ol_context;
Komal Seelamd9106492016-02-15 10:31:44 +05301556 break;
Komal Seelamd9106492016-02-15 10:31:44 +05301557
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001558 default:
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001559 cds_err("Module ID %i does not have its context allocated by CDS",
1560 module_id);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301561 QDF_ASSERT(0);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301562 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001563 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001564
Jeff Johnson835b7602018-05-30 19:06:24 -07001565 if (!*cds_mod_context) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001566 /* Context has not been allocated or freed already! */
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001567 cds_err("Module ID %i context has not been allocated or freed already",
1568 module_id);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301569 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001570 }
1571
Jeff Johnson13269962018-05-30 19:16:46 -07001572 if (*cds_mod_context != module_context) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001573 cds_err("cds_mod_context != module_context");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301574 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001575 }
1576
Jeff Johnson13269962018-05-30 19:16:46 -07001577 qdf_mem_free(module_context);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001578
Jeff Johnson835b7602018-05-30 19:06:24 -07001579 *cds_mod_context = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001580
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301581 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001582} /* cds_free_context() */
1583
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001584/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001585 * cds_wma_complete_cback() - wma complete callback
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001586 *
1587 * Return: none
1588 */
Jeff Johnsonf7ab8142017-09-13 09:04:23 -07001589void cds_wma_complete_cback(void)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001590{
Jeff Johnsonf7ab8142017-09-13 09:04:23 -07001591 if (!gp_cds_context) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001592 cds_err("invalid gp_cds_context");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001593 return;
1594 }
1595
Jeff Johnson2ccd8152018-05-29 16:02:23 -07001596 if (qdf_event_set(&gp_cds_context->wma_complete_event) !=
Anurag Chouhance0dc992016-02-16 18:18:03 +05301597 QDF_STATUS_SUCCESS) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001598 cds_err("qdf_event_set failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001599 return;
1600 }
1601} /* cds_wma_complete_cback() */
1602
1603/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001604 * cds_get_vdev_types() - get vdev type
1605 * @mode: mode
1606 * @type: type
1607 * @sub_type: sub_type
1608 *
1609 * Return: WMI vdev type
1610 */
Jeff Johnsonc1e62782017-11-09 09:50:17 -08001611QDF_STATUS cds_get_vdev_types(enum QDF_OPMODE mode, uint32_t *type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001612 uint32_t *sub_type)
1613{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301614 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001615 *type = 0;
1616 *sub_type = 0;
1617
1618 switch (mode) {
Anurag Chouhan6d760662016-02-20 16:05:43 +05301619 case QDF_STA_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001620 *type = WMI_VDEV_TYPE_STA;
1621 break;
Anurag Chouhan6d760662016-02-20 16:05:43 +05301622 case QDF_SAP_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001623 *type = WMI_VDEV_TYPE_AP;
1624 break;
Anurag Chouhan6d760662016-02-20 16:05:43 +05301625 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001626 *type = WMI_VDEV_TYPE_AP;
1627 *sub_type = WMI_UNIFIED_VDEV_SUBTYPE_P2P_DEVICE;
1628 break;
Anurag Chouhan6d760662016-02-20 16:05:43 +05301629 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001630 *type = WMI_VDEV_TYPE_STA;
1631 *sub_type = WMI_UNIFIED_VDEV_SUBTYPE_P2P_CLIENT;
1632 break;
Anurag Chouhan6d760662016-02-20 16:05:43 +05301633 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001634 *type = WMI_VDEV_TYPE_AP;
1635 *sub_type = WMI_UNIFIED_VDEV_SUBTYPE_P2P_GO;
1636 break;
Anurag Chouhan6d760662016-02-20 16:05:43 +05301637 case QDF_OCB_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001638 *type = WMI_VDEV_TYPE_OCB;
1639 break;
Krunal Soni8c37e322016-02-03 16:08:37 -08001640 case QDF_IBSS_MODE:
1641 *type = WMI_VDEV_TYPE_IBSS;
1642 break;
Manjunathappa Prakashb7573722016-04-21 11:24:07 -07001643 case QDF_MONITOR_MODE:
1644 *type = WMI_VDEV_TYPE_MONITOR;
1645 break;
Deepak Dhamdheree2dd5442016-05-27 15:05:51 -07001646 case QDF_NDI_MODE:
1647 *type = WMI_VDEV_TYPE_NDI;
1648 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001649 default:
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001650 cds_err("Invalid device mode %d", mode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301651 status = QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001652 break;
1653 }
1654 return status;
1655}
1656
1657/**
1658 * cds_flush_work() - flush pending works
1659 * @work: pointer to work
1660 *
1661 * Return: none
1662 */
1663void cds_flush_work(void *work)
1664{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001665 cancel_work_sync(work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001666}
1667
1668/**
1669 * cds_flush_delayed_work() - flush delayed works
1670 * @dwork: pointer to delayed work
1671 *
1672 * Return: none
1673 */
1674void cds_flush_delayed_work(void *dwork)
1675{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001676 cancel_delayed_work_sync(dwork);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001677}
1678
Nirav Shahbb8e47c2018-05-17 16:56:41 +05301679#ifndef REMOVE_PKT_LOG
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001680/**
1681 * cds_is_packet_log_enabled() - check if packet log is enabled
1682 *
1683 * Return: true if packet log is enabled else false
1684 */
1685bool cds_is_packet_log_enabled(void)
1686{
Jeff Johnsonc18b26c2017-09-03 08:46:45 -07001687 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001688
Jeff Johnson323a6f02018-05-29 15:09:12 -07001689 hdd_ctx = gp_cds_context->hdd_context;
Jeff Johnsonc18b26c2017-09-03 08:46:45 -07001690 if ((NULL == hdd_ctx) || (NULL == hdd_ctx->config)) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001691 cds_alert("Hdd Context is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001692 return false;
1693 }
Jeff Johnsonc18b26c2017-09-03 08:46:45 -07001694 return hdd_ctx->config->enablePacketLog;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001695}
Nirav Shahbb8e47c2018-05-17 16:56:41 +05301696#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001697
Dustin Brown100201e2017-07-10 11:48:40 -07001698static int cds_force_assert_target_via_pld(qdf_device_t qdf)
Mukul Sharmab7b575b2016-10-02 23:37:07 +05301699{
Dustin Brown100201e2017-07-10 11:48:40 -07001700 int errno;
1701
1702 errno = pld_force_assert_target(qdf->dev);
1703 if (errno == -EOPNOTSUPP)
1704 cds_info("PLD does not support target force assert");
1705 else if (errno)
1706 cds_err("Failed PLD target force assert; errno %d", errno);
1707 else
1708 cds_info("Target force assert triggered via PLD");
1709
1710 return errno;
Mukul Sharmab7b575b2016-10-02 23:37:07 +05301711}
1712
Dustin Brown100201e2017-07-10 11:48:40 -07001713static QDF_STATUS cds_force_assert_target_via_wmi(qdf_device_t qdf)
Rajeev Kumardb60f162017-07-25 20:27:59 -07001714{
Dustin Brown100201e2017-07-10 11:48:40 -07001715 QDF_STATUS status;
1716 t_wma_handle *wma;
1717
1718 wma = cds_get_context(QDF_MODULE_ID_WMA);
1719 if (!wma) {
1720 cds_err("wma is null");
1721 return QDF_STATUS_E_INVAL;
1722 }
1723
1724 status = wma_crash_inject(wma, RECOVERY_SIM_SELF_RECOVERY, 0);
1725 if (QDF_IS_STATUS_ERROR(status)) {
1726 cds_err("Failed target force assert; status %d", status);
1727 return status;
1728 }
1729
Nachiket Kukade0396b732017-11-14 16:35:16 +05301730 status = qdf_wait_for_event_completion(&wma->recovery_event,
Dustin Brown100201e2017-07-10 11:48:40 -07001731 WMA_CRASH_INJECT_TIMEOUT);
1732 if (QDF_IS_STATUS_ERROR(status)) {
1733 cds_err("Failed target force assert wait; status %d", status);
1734 return status;
1735 }
1736
1737 return QDF_STATUS_SUCCESS;
1738}
1739
1740/**
1741 * cds_force_assert_target() - Send assert command to firmware
1742 * @qdf: QDF device instance to assert
1743 *
1744 * An out-of-band recovery mechanism will cleanup and restart the entire wlan
1745 * subsystem in the event of a firmware crash. This API injects a firmware
1746 * crash to start this process when the wlan driver is known to be in a bad
1747 * state. If a firmware assert inject fails, the wlan driver will schedule
1748 * the driver recovery anyway, as a best effort attempt to return to a working
1749 * state.
1750 *
1751 * Return: QDF_STATUS
1752 */
1753static QDF_STATUS cds_force_assert_target(qdf_device_t qdf)
1754{
1755 int errno;
1756 QDF_STATUS status;
1757
1758 /* first, try target assert inject via pld */
1759 errno = cds_force_assert_target_via_pld(qdf);
1760 if (!errno)
1761 return QDF_STATUS_SUCCESS;
1762 if (errno != -EOPNOTSUPP)
1763 return QDF_STATUS_E_FAILURE;
1764
1765 /* pld assert is not supported, try target assert inject via wmi */
1766 status = cds_force_assert_target_via_wmi(qdf);
1767 if (QDF_IS_STATUS_SUCCESS(status))
1768 return QDF_STATUS_SUCCESS;
1769
1770 /* wmi assert failed, start recovery without the firmware assert */
1771 cds_err("Scheduling recovery work without firmware assert");
1772 cds_set_recovery_in_progress(true);
1773 pld_schedule_recovery_work(qdf->dev, PLD_REASON_DEFAULT);
1774
1775 return status;
Rajeev Kumardb60f162017-07-25 20:27:59 -07001776}
1777
Mukul Sharmab7b575b2016-10-02 23:37:07 +05301778/**
Srinivas Girigowda161b9f22017-07-24 17:38:09 -07001779 * cds_trigger_recovery_work() - trigger self recovery work
Mukul Sharmab7b575b2016-10-02 23:37:07 +05301780 *
1781 * Return: none
1782 */
Srinivas Girigowda161b9f22017-07-24 17:38:09 -07001783static void cds_trigger_recovery_work(void *param)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001784{
Dustin Brown100201e2017-07-10 11:48:40 -07001785 QDF_STATUS status;
1786 qdf_runtime_lock_t rtl;
1787 qdf_device_t qdf;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001788
Zhu Jianmin26b9b8a2018-05-15 09:04:45 +08001789 if (cds_is_driver_unloading()) {
1790 cds_err("Unloading in progress; ignoring recovery trigger");
1791 return;
1792 }
1793
Kabilan Kannan973744a2018-01-03 10:28:50 -08001794 if (cds_is_driver_recovering()) {
1795 cds_err("Recovery in progress; ignoring recovery trigger");
Sameer Thalappilec2e9c72017-02-08 15:45:49 -08001796 return;
1797 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001798
Kabilan Kannan973744a2018-01-03 10:28:50 -08001799 if (cds_is_driver_in_bad_state()) {
1800 cds_err("Driver is in bad state; ignoring recovery trigger");
Houston Hoffmanc7c72a82015-12-07 15:30:48 -08001801 return;
1802 }
1803
Rajeev Kumar6dd45a82017-10-20 14:43:05 -07001804 if (cds_is_fw_down()) {
1805 cds_err("FW is down; ignoring recovery trigger");
1806 return;
1807 }
1808
Kabilan Kannan973744a2018-01-03 10:28:50 -08001809 if (!cds_is_self_recovery_enabled()) {
1810 cds_err("Recovery is not enabled");
1811 QDF_BUG(0);
1812 return;
1813 }
1814
Dustin Brown100201e2017-07-10 11:48:40 -07001815 qdf = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
1816 if (!qdf) {
1817 cds_err("Qdf context is null");
1818 return;
Sameer Thalappilac5d26e2017-01-10 15:32:58 -08001819 }
1820
Dustin Brown100201e2017-07-10 11:48:40 -07001821 status = qdf_runtime_lock_init(&rtl);
1822 if (QDF_IS_STATUS_ERROR(status)) {
Srinivas Girigowda161b9f22017-07-24 17:38:09 -07001823 cds_err("qdf_runtime_lock_init failed, status: %d", status);
Dustin Brown100201e2017-07-10 11:48:40 -07001824 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001825 }
Houston Hoffmanc7c72a82015-12-07 15:30:48 -08001826
Dustin Brown100201e2017-07-10 11:48:40 -07001827 status = qdf_runtime_pm_prevent_suspend(&rtl);
1828 if (QDF_IS_STATUS_ERROR(status)) {
1829 cds_err("Failed to acquire runtime pm lock");
1830 goto deinit_rtl;
1831 }
1832
1833 cds_force_assert_target(qdf);
1834
1835 status = qdf_runtime_pm_allow_suspend(&rtl);
1836 if (QDF_IS_STATUS_ERROR(status))
1837 cds_err("Failed to release runtime pm lock");
1838
1839deinit_rtl:
1840 qdf_runtime_lock_deinit(&rtl);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001841}
1842
1843/**
Anurag Chouhan4085ff72017-10-05 18:09:56 +05301844 * cds_get_recovery_reason() - get self recovery reason
1845 * @reason: recovery reason
1846 *
1847 * Return: None
1848 */
1849void cds_get_recovery_reason(enum qdf_hang_reason *reason)
1850{
1851 if (!gp_cds_context) {
1852 cds_err("gp_cds_context is null");
1853 return;
1854 }
1855
1856 *reason = gp_cds_context->recovery_reason;
1857}
1858
1859/**
1860 * cds_reset_recovery_reason() - reset the reason to unspecified
1861 *
1862 * Return: None
1863 */
1864void cds_reset_recovery_reason(void)
1865{
1866 if (!gp_cds_context) {
1867 cds_err("gp_cds_context is null");
1868 return;
1869 }
1870
1871 gp_cds_context->recovery_reason = QDF_REASON_UNSPECIFIED;
1872}
1873
1874/**
Srinivas Girigowda161b9f22017-07-24 17:38:09 -07001875 * cds_trigger_recovery() - trigger self recovery
Anurag Chouhan4085ff72017-10-05 18:09:56 +05301876 * @reason: recovery reason
Srinivas Girigowda161b9f22017-07-24 17:38:09 -07001877 *
1878 * Return: none
1879 */
Anurag Chouhan4085ff72017-10-05 18:09:56 +05301880void cds_trigger_recovery(enum qdf_hang_reason reason)
Srinivas Girigowda161b9f22017-07-24 17:38:09 -07001881{
Anurag Chouhan4085ff72017-10-05 18:09:56 +05301882 if (!gp_cds_context) {
1883 cds_err("gp_cds_context is null");
1884 return;
1885 }
1886
1887 gp_cds_context->recovery_reason = reason;
Srinivas Girigowda161b9f22017-07-24 17:38:09 -07001888 if (in_atomic()) {
1889 qdf_queue_work(0, gp_cds_context->cds_recovery_wq,
1890 &gp_cds_context->cds_recovery_work);
1891 return;
1892 }
1893 cds_trigger_recovery_work(NULL);
1894}
1895
1896/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001897 * cds_get_monotonic_boottime() - Get kernel boot time.
1898 *
1899 * Return: Time in microseconds
1900 */
1901
1902uint64_t cds_get_monotonic_boottime(void)
1903{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001904 struct timespec ts;
1905
Yuanyuan Liu2e03b412016-04-06 14:36:15 -07001906 get_monotonic_boottime(&ts);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001907 return ((uint64_t) ts.tv_sec * 1000000) + (ts.tv_nsec / 1000);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001908}
1909
1910/**
1911 * cds_set_wakelock_logging() - Logging of wakelock enabled/disabled
1912 * @value: Boolean value
1913 *
1914 * This function is used to set the flag which will indicate whether
1915 * logging of wakelock is enabled or not
1916 *
1917 * Return: None
1918 */
1919void cds_set_wakelock_logging(bool value)
1920{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07001921 struct cds_context *p_cds_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001922
1923 p_cds_context = cds_get_global_context();
1924 if (!p_cds_context) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001925 cds_err("cds context is Invald");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001926 return;
1927 }
1928 p_cds_context->is_wakelock_log_enabled = value;
1929}
1930
1931/**
1932 * cds_is_wakelock_enabled() - Check if logging of wakelock is enabled/disabled
1933 * @value: Boolean value
1934 *
1935 * This function is used to check whether logging of wakelock is enabled or not
1936 *
1937 * Return: true if logging of wakelock is enabled
1938 */
1939bool cds_is_wakelock_enabled(void)
1940{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07001941 struct cds_context *p_cds_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001942
1943 p_cds_context = cds_get_global_context();
1944 if (!p_cds_context) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001945 cds_err("cds context is Invald");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001946 return false;
1947 }
1948 return p_cds_context->is_wakelock_log_enabled;
1949}
1950
1951/**
1952 * cds_set_ring_log_level() - Sets the log level of a particular ring
1953 * @ring_id: ring_id
1954 * @log_levelvalue: Log level specificed
1955 *
1956 * This function converts HLOS values to driver log levels and sets the log
1957 * level of a particular ring accordingly.
1958 *
1959 * Return: None
1960 */
1961void cds_set_ring_log_level(uint32_t ring_id, uint32_t log_level)
1962{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07001963 struct cds_context *p_cds_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001964 uint32_t log_val;
1965
1966 p_cds_context = cds_get_global_context();
1967 if (!p_cds_context) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001968 cds_err("cds context is Invald");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001969 return;
1970 }
1971
1972 switch (log_level) {
1973 case LOG_LEVEL_NO_COLLECTION:
1974 log_val = WLAN_LOG_LEVEL_OFF;
1975 break;
1976 case LOG_LEVEL_NORMAL_COLLECT:
1977 log_val = WLAN_LOG_LEVEL_NORMAL;
1978 break;
1979 case LOG_LEVEL_ISSUE_REPRO:
1980 log_val = WLAN_LOG_LEVEL_REPRO;
1981 break;
1982 case LOG_LEVEL_ACTIVE:
1983 default:
1984 log_val = WLAN_LOG_LEVEL_ACTIVE;
1985 break;
1986 }
1987
1988 if (ring_id == RING_ID_WAKELOCK) {
1989 p_cds_context->wakelock_log_level = log_val;
1990 return;
1991 } else if (ring_id == RING_ID_CONNECTIVITY) {
1992 p_cds_context->connectivity_log_level = log_val;
1993 return;
1994 } else if (ring_id == RING_ID_PER_PACKET_STATS) {
1995 p_cds_context->packet_stats_log_level = log_val;
1996 return;
Chandrasekaran, Manishekar907c2af2015-11-13 12:50:04 +05301997 } else if (ring_id == RING_ID_DRIVER_DEBUG) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001998 p_cds_context->driver_debug_log_level = log_val;
1999 return;
2000 } else if (ring_id == RING_ID_FIRMWARE_DEBUG) {
2001 p_cds_context->fw_debug_log_level = log_val;
2002 return;
2003 }
2004}
2005
2006/**
2007 * cds_get_ring_log_level() - Get the a ring id's log level
2008 * @ring_id: Ring id
2009 *
2010 * Fetch and return the log level corresponding to a ring id
2011 *
2012 * Return: Log level corresponding to the ring ID
2013 */
2014enum wifi_driver_log_level cds_get_ring_log_level(uint32_t ring_id)
2015{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002016 struct cds_context *p_cds_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002017
2018 p_cds_context = cds_get_global_context();
2019 if (!p_cds_context) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07002020 cds_err("cds context is Invald");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002021 return WLAN_LOG_LEVEL_OFF;
2022 }
2023
2024 if (ring_id == RING_ID_WAKELOCK)
2025 return p_cds_context->wakelock_log_level;
2026 else if (ring_id == RING_ID_CONNECTIVITY)
2027 return p_cds_context->connectivity_log_level;
2028 else if (ring_id == RING_ID_PER_PACKET_STATS)
2029 return p_cds_context->packet_stats_log_level;
Chandrasekaran, Manishekar907c2af2015-11-13 12:50:04 +05302030 else if (ring_id == RING_ID_DRIVER_DEBUG)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002031 return p_cds_context->driver_debug_log_level;
2032 else if (ring_id == RING_ID_FIRMWARE_DEBUG)
2033 return p_cds_context->fw_debug_log_level;
2034
2035 return WLAN_LOG_LEVEL_OFF;
2036}
2037
2038/**
2039 * cds_set_multicast_logging() - Set mutlicast logging value
2040 * @value: Value of multicast logging
2041 *
2042 * Set the multicast logging value which will indicate
2043 * whether to multicast host and fw messages even
2044 * without any registration by userspace entity
2045 *
2046 * Return: None
2047 */
2048void cds_set_multicast_logging(uint8_t value)
2049{
2050 cds_multicast_logging = value;
2051}
2052
2053/**
2054 * cds_is_multicast_logging() - Get multicast logging value
2055 *
2056 * Get the multicast logging value which will indicate
2057 * whether to multicast host and fw messages even
2058 * without any registration by userspace entity
2059 *
2060 * Return: 0 - Multicast logging disabled, 1 - Multicast logging enabled
2061 */
2062uint8_t cds_is_multicast_logging(void)
2063{
2064 return cds_multicast_logging;
2065}
2066
2067/*
2068 * cds_init_log_completion() - Initialize log param structure
2069 *
2070 * This function is used to initialize the logging related
2071 * parameters
2072 *
2073 * Return: None
2074 */
2075void cds_init_log_completion(void)
2076{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002077 struct cds_context *p_cds_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002078
2079 p_cds_context = cds_get_global_context();
2080 if (!p_cds_context) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07002081 cds_err("cds context is Invalid");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002082 return;
2083 }
2084
2085 p_cds_context->log_complete.is_fatal = WLAN_LOG_TYPE_NON_FATAL;
2086 p_cds_context->log_complete.indicator = WLAN_LOG_INDICATOR_UNUSED;
2087 p_cds_context->log_complete.reason_code = WLAN_LOG_REASON_CODE_UNUSED;
2088 p_cds_context->log_complete.is_report_in_progress = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002089}
2090
2091/**
2092 * cds_set_log_completion() - Store the logging params
2093 * @is_fatal: Indicates if the event triggering bug report is fatal or not
2094 * @indicator: Source which trigerred the bug report
2095 * @reason_code: Reason for triggering bug report
Abhishek Singh5ea86532016-04-27 14:10:53 +05302096 * @recovery_needed: If recovery is needed after bug report
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002097 *
2098 * This function is used to set the logging parameters based on the
2099 * caller
2100 *
2101 * Return: 0 if setting of params is successful
2102 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302103QDF_STATUS cds_set_log_completion(uint32_t is_fatal,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002104 uint32_t indicator,
Abhishek Singh5ea86532016-04-27 14:10:53 +05302105 uint32_t reason_code,
2106 bool recovery_needed)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002107{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002108 struct cds_context *p_cds_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002109
2110 p_cds_context = cds_get_global_context();
2111 if (!p_cds_context) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07002112 cds_err("cds context is Invalid");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302113 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002114 }
2115
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302116 qdf_spinlock_acquire(&p_cds_context->bug_report_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002117 p_cds_context->log_complete.is_fatal = is_fatal;
2118 p_cds_context->log_complete.indicator = indicator;
2119 p_cds_context->log_complete.reason_code = reason_code;
Abhishek Singh5ea86532016-04-27 14:10:53 +05302120 p_cds_context->log_complete.recovery_needed = recovery_needed;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002121 p_cds_context->log_complete.is_report_in_progress = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302122 qdf_spinlock_release(&p_cds_context->bug_report_lock);
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07002123 cds_debug("is_fatal %d indicator %d reason_code %d recovery needed %d",
2124 is_fatal, indicator, reason_code, recovery_needed);
Rajeev Kumardcce8092018-05-02 15:48:17 -07002125
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302126 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002127}
2128
2129/**
Abhishek Singh5ea86532016-04-27 14:10:53 +05302130 * cds_get_and_reset_log_completion() - Get and reset logging related params
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002131 * @is_fatal: Indicates if the event triggering bug report is fatal or not
2132 * @indicator: Source which trigerred the bug report
2133 * @reason_code: Reason for triggering bug report
Abhishek Singh5ea86532016-04-27 14:10:53 +05302134 * @recovery_needed: If recovery is needed after bug report
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002135 *
2136 * This function is used to get the logging related parameters
2137 *
2138 * Return: None
2139 */
Abhishek Singh5ea86532016-04-27 14:10:53 +05302140void cds_get_and_reset_log_completion(uint32_t *is_fatal,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002141 uint32_t *indicator,
Abhishek Singh5ea86532016-04-27 14:10:53 +05302142 uint32_t *reason_code,
2143 bool *recovery_needed)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002144{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002145 struct cds_context *p_cds_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002146
2147 p_cds_context = cds_get_global_context();
2148 if (!p_cds_context) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07002149 cds_err("cds context is Invalid");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002150 return;
2151 }
2152
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302153 qdf_spinlock_acquire(&p_cds_context->bug_report_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002154 *is_fatal = p_cds_context->log_complete.is_fatal;
2155 *indicator = p_cds_context->log_complete.indicator;
2156 *reason_code = p_cds_context->log_complete.reason_code;
Abhishek Singh5ea86532016-04-27 14:10:53 +05302157 *recovery_needed = p_cds_context->log_complete.recovery_needed;
2158
2159 /* reset */
2160 p_cds_context->log_complete.indicator = WLAN_LOG_INDICATOR_UNUSED;
2161 p_cds_context->log_complete.is_fatal = WLAN_LOG_TYPE_NON_FATAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002162 p_cds_context->log_complete.is_report_in_progress = false;
Abhishek Singh5ea86532016-04-27 14:10:53 +05302163 p_cds_context->log_complete.reason_code = WLAN_LOG_REASON_CODE_UNUSED;
2164 p_cds_context->log_complete.recovery_needed = false;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302165 qdf_spinlock_release(&p_cds_context->bug_report_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002166}
2167
2168/**
2169 * cds_is_log_report_in_progress() - Check if bug reporting is in progress
2170 *
2171 * This function is used to check if the bug reporting is already in progress
2172 *
2173 * Return: true if the bug reporting is in progress
2174 */
2175bool cds_is_log_report_in_progress(void)
2176{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002177 struct cds_context *p_cds_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002178
2179 p_cds_context = cds_get_global_context();
2180 if (!p_cds_context) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07002181 cds_err("cds context is Invalid");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002182 return true;
2183 }
2184 return p_cds_context->log_complete.is_report_in_progress;
2185}
2186
2187/**
Abhishek Singh5ea86532016-04-27 14:10:53 +05302188 * cds_is_fatal_event_enabled() - Return if fatal event is enabled
2189 *
2190 * Return true if fatal event is enabled.
2191 */
2192bool cds_is_fatal_event_enabled(void)
2193{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002194 struct cds_context *p_cds_context;
Abhishek Singh5ea86532016-04-27 14:10:53 +05302195
2196 p_cds_context = cds_get_global_context();
2197 if (!p_cds_context) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07002198 cds_err("cds context is Invalid");
Abhishek Singh5ea86532016-04-27 14:10:53 +05302199 return false;
2200 }
2201
2202
2203 return p_cds_context->enable_fatal_event;
2204}
2205
Yu Wang66a250b2017-07-19 11:46:40 +08002206#ifdef WLAN_FEATURE_TSF_PLUS
2207bool cds_is_ptp_rx_opt_enabled(void)
2208{
2209 struct hdd_context *hdd_ctx;
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002210 struct cds_context *p_cds_context;
Yu Wang66a250b2017-07-19 11:46:40 +08002211
2212 p_cds_context = cds_get_global_context();
2213 if (!p_cds_context) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07002214 cds_err("cds context is Invalid");
Yu Wang66a250b2017-07-19 11:46:40 +08002215 return false;
2216 }
2217
Jeff Johnson323a6f02018-05-29 15:09:12 -07002218 hdd_ctx = (struct hdd_context *)(p_cds_context->hdd_context);
Yu Wang66a250b2017-07-19 11:46:40 +08002219 if ((NULL == hdd_ctx) || (NULL == hdd_ctx->config)) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07002220 cds_err("Hdd Context is Null");
Yu Wang66a250b2017-07-19 11:46:40 +08002221 return false;
2222 }
2223
2224 return HDD_TSF_IS_RX_SET(hdd_ctx);
2225}
2226
2227bool cds_is_ptp_tx_opt_enabled(void)
2228{
2229 struct hdd_context *hdd_ctx;
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002230 struct cds_context *p_cds_context;
Yu Wang66a250b2017-07-19 11:46:40 +08002231
2232 p_cds_context = cds_get_global_context();
2233 if (!p_cds_context) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07002234 cds_err("cds context is Invalid");
Yu Wang66a250b2017-07-19 11:46:40 +08002235 return false;
2236 }
2237
Jeff Johnson323a6f02018-05-29 15:09:12 -07002238 hdd_ctx = (struct hdd_context *)(p_cds_context->hdd_context);
Yu Wang66a250b2017-07-19 11:46:40 +08002239 if ((NULL == hdd_ctx) || (NULL == hdd_ctx->config)) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07002240 cds_err("Hdd Context is Null");
Yu Wang66a250b2017-07-19 11:46:40 +08002241 return false;
2242 }
2243
2244 return HDD_TSF_IS_TX_SET(hdd_ctx);
2245}
2246#endif
2247
Abhishek Singh5ea86532016-04-27 14:10:53 +05302248/**
2249 * cds_get_log_indicator() - Get the log flush indicator
2250 *
2251 * This function is used to get the log flush indicator
2252 *
2253 * Return: log indicator
2254 */
2255uint32_t cds_get_log_indicator(void)
2256{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002257 struct cds_context *p_cds_context;
Abhishek Singh5ea86532016-04-27 14:10:53 +05302258 uint32_t indicator;
2259
2260 p_cds_context = cds_get_global_context();
2261 if (!p_cds_context) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07002262 cds_err("cds context is Invalid");
Abhishek Singh5ea86532016-04-27 14:10:53 +05302263 return WLAN_LOG_INDICATOR_UNUSED;
2264 }
2265
2266 if (cds_is_load_or_unload_in_progress() ||
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05302267 cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Abhishek Singh5ea86532016-04-27 14:10:53 +05302268 return WLAN_LOG_INDICATOR_UNUSED;
2269 }
2270
2271 qdf_spinlock_acquire(&p_cds_context->bug_report_lock);
2272 indicator = p_cds_context->log_complete.indicator;
2273 qdf_spinlock_release(&p_cds_context->bug_report_lock);
2274 return indicator;
2275}
2276
2277/**
2278 * cds_wlan_flush_host_logs_for_fatal() - Wrapper to flush host logs
2279 *
2280 * This function is used to send signal to the logger thread to
2281 * flush the host logs.
2282 *
2283 * Return: None
2284 *
2285 */
2286void cds_wlan_flush_host_logs_for_fatal(void)
2287{
2288 wlan_flush_host_logs_for_fatal();
2289}
2290
2291/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002292 * cds_flush_logs() - Report fatal event to userspace
2293 * @is_fatal: Indicates if the event triggering bug report is fatal or not
2294 * @indicator: Source which trigerred the bug report
2295 * @reason_code: Reason for triggering bug report
Abhishek Singh5ea86532016-04-27 14:10:53 +05302296 * @dump_mac_trace: If mac trace are needed in logs.
2297 * @recovery_needed: If recovery is needed after bug report
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002298 *
2299 * This function sets the log related params and send the WMI command to the
2300 * FW to flush its logs. On receiving the flush completion event from the FW
2301 * the same will be conveyed to userspace
2302 *
2303 * Return: 0 on success
2304 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302305QDF_STATUS cds_flush_logs(uint32_t is_fatal,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002306 uint32_t indicator,
Abhishek Singh5ea86532016-04-27 14:10:53 +05302307 uint32_t reason_code,
2308 bool dump_mac_trace,
2309 bool recovery_needed)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002310{
2311 uint32_t ret;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302312 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002313
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002314 struct cds_context *p_cds_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002315
2316 p_cds_context = cds_get_global_context();
2317 if (!p_cds_context) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07002318 cds_err("cds context is Invalid");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302319 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002320 }
Abhishek Singh5ea86532016-04-27 14:10:53 +05302321 if (!p_cds_context->enable_fatal_event) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07002322 cds_err("Fatal event not enabled");
Abhishek Singh5ea86532016-04-27 14:10:53 +05302323 return QDF_STATUS_E_FAILURE;
2324 }
2325 if (cds_is_load_or_unload_in_progress() ||
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05302326 cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07002327 cds_err("un/Load/SSR in progress");
Abhishek Singh5ea86532016-04-27 14:10:53 +05302328 return QDF_STATUS_E_FAILURE;
2329 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002330
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07002331 if (cds_is_log_report_in_progress()) {
2332 cds_err("Bug report already in progress - dropping! type:%d, indicator=%d reason_code=%d",
2333 is_fatal, indicator, reason_code);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302334 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002335 }
2336
Abhishek Singh5ea86532016-04-27 14:10:53 +05302337 status = cds_set_log_completion(is_fatal, indicator,
2338 reason_code, recovery_needed);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302339 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07002340 cds_err("Failed to set log trigger params");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302341 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002342 }
2343
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07002344 cds_info("Triggering bug report: type:%d, indicator=%d reason_code=%d",
2345 is_fatal, indicator, reason_code);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002346
Abhishek Singh5ea86532016-04-27 14:10:53 +05302347 if (dump_mac_trace)
Jeff Johnson528c2cf2018-05-29 15:55:58 -07002348 qdf_trace_dump_all(p_cds_context->mac_context, 0, 0, 500, 0);
Abhishek Singh5ea86532016-04-27 14:10:53 +05302349
2350 if (WLAN_LOG_INDICATOR_HOST_ONLY == indicator) {
2351 cds_wlan_flush_host_logs_for_fatal();
2352 return QDF_STATUS_SUCCESS;
2353 }
2354
Jeff Johnson528c2cf2018-05-29 15:55:58 -07002355 ret = sme_send_flush_logs_cmd_to_fw(p_cds_context->mac_context);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002356 if (0 != ret) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07002357 cds_err("Failed to send flush FW log");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002358 cds_init_log_completion();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302359 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002360 }
2361
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302362 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002363}
2364
2365/**
2366 * cds_logging_set_fw_flush_complete() - Wrapper for FW log flush completion
2367 *
2368 * This function is used to send signal to the logger thread to indicate
2369 * that the flushing of FW logs is complete by the FW
2370 *
2371 * Return: None
2372 *
2373 */
2374void cds_logging_set_fw_flush_complete(void)
2375{
2376 wlan_logging_set_fw_flush_complete();
2377}
Abhishek Singh5ea86532016-04-27 14:10:53 +05302378
2379/**
2380 * cds_set_fatal_event() - set fatal event status
2381 * @value: pending statue to set
2382 *
2383 * Return: None
2384 */
2385void cds_set_fatal_event(bool value)
2386{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002387 struct cds_context *p_cds_context;
Abhishek Singh5ea86532016-04-27 14:10:53 +05302388
2389 p_cds_context = cds_get_global_context();
2390 if (!p_cds_context) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07002391 cds_err("cds context is Invalid");
Abhishek Singh5ea86532016-04-27 14:10:53 +05302392 return;
2393 }
2394 p_cds_context->enable_fatal_event = value;
2395}
2396
Ryan Hsuceddceb2016-04-28 10:20:14 -07002397/**
2398 * cds_get_radio_index() - get radio index
2399 *
2400 * Return: radio index otherwise, -EINVAL
2401 */
2402int cds_get_radio_index(void)
2403{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002404 struct cds_context *p_cds_context;
Ryan Hsuceddceb2016-04-28 10:20:14 -07002405
2406 p_cds_context = cds_get_global_context();
2407 if (!p_cds_context) {
2408 /*
2409 * To avoid recursive call, this should not change to
2410 * QDF_TRACE().
2411 */
2412 pr_err("%s: cds context is invalid\n", __func__);
2413 return -EINVAL;
2414 }
2415
2416 return p_cds_context->radio_index;
2417}
2418
2419/**
2420 * cds_set_radio_index() - set radio index
2421 * @radio_index: the radio index to set
2422 *
2423 * Return: QDF status
2424 */
2425QDF_STATUS cds_set_radio_index(int radio_index)
2426{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002427 struct cds_context *p_cds_context;
Ryan Hsuceddceb2016-04-28 10:20:14 -07002428
2429 p_cds_context = cds_get_global_context();
2430 if (!p_cds_context) {
2431 pr_err("%s: cds context is invalid\n", __func__);
2432 return QDF_STATUS_E_FAILURE;
2433 }
2434
2435 p_cds_context->radio_index = radio_index;
2436
2437 return QDF_STATUS_SUCCESS;
2438}
Arun Khandavallic811dcc2016-06-26 07:37:21 +05302439
2440/**
2441 * cds_init_ini_config() - API to initialize CDS configuration parameters
2442 * @cfg: CDS Configuration
2443 *
2444 * Return: void
2445 */
2446
2447void cds_init_ini_config(struct cds_config_info *cfg)
2448{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002449 struct cds_context *cds_ctx;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05302450
2451 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2452 if (!cds_ctx) {
2453 cds_err("Invalid CDS Context");
2454 return;
2455 }
2456
2457 cds_ctx->cds_cfg = cfg;
2458}
2459
2460/**
2461 * cds_deinit_ini_config() - API to free CDS configuration parameters
2462 *
2463 * Return: void
2464 */
2465void cds_deinit_ini_config(void)
2466{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002467 struct cds_context *cds_ctx;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05302468
2469 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2470 if (!cds_ctx) {
2471 cds_err("Invalid CDS Context");
2472 return;
2473 }
2474
Arun Khandavallif6246632016-08-17 17:43:06 +05302475 if (cds_ctx->cds_cfg)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05302476 qdf_mem_free(cds_ctx->cds_cfg);
2477
2478 cds_ctx->cds_cfg = NULL;
2479}
2480
2481/**
2482 * cds_get_ini_config() - API to get CDS configuration parameters
2483 *
2484 * Return: cds config structure
2485 */
2486struct cds_config_info *cds_get_ini_config(void)
2487{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002488 struct cds_context *cds_ctx;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05302489
2490 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2491 if (!cds_ctx) {
2492 cds_err("Invalid CDS Context");
2493 return NULL;
2494 }
2495
2496 return cds_ctx->cds_cfg;
2497}
Naveen Rawat64e477e2016-05-20 10:34:56 -07002498
2499/**
2500 * cds_is_5_mhz_enabled() - API to get 5MHZ enabled
2501 *
2502 * Return: true if 5 mhz is enabled, false otherwise
2503 */
2504bool cds_is_5_mhz_enabled(void)
2505{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002506 struct cds_context *p_cds_context;
Naveen Rawat64e477e2016-05-20 10:34:56 -07002507
2508 p_cds_context = cds_get_context(QDF_MODULE_ID_QDF);
2509 if (!p_cds_context) {
2510 cds_err("%s: cds context is invalid", __func__);
2511 return false;
2512 }
2513
2514 if (p_cds_context->cds_cfg)
2515 return (p_cds_context->cds_cfg->sub_20_channel_width ==
2516 WLAN_SUB_20_CH_WIDTH_5);
2517
2518 return false;
2519}
2520
2521/**
2522 * cds_is_10_mhz_enabled() - API to get 10-MHZ enabled
2523 *
2524 * Return: true if 10 mhz is enabled, false otherwise
2525 */
2526bool cds_is_10_mhz_enabled(void)
2527{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002528 struct cds_context *p_cds_context;
Naveen Rawat64e477e2016-05-20 10:34:56 -07002529
2530 p_cds_context = cds_get_context(QDF_MODULE_ID_QDF);
2531 if (!p_cds_context) {
2532 cds_err("%s: cds context is invalid", __func__);
2533 return false;
2534 }
2535
2536 if (p_cds_context->cds_cfg)
2537 return (p_cds_context->cds_cfg->sub_20_channel_width ==
2538 WLAN_SUB_20_CH_WIDTH_10);
2539
2540 return false;
2541}
2542
2543/**
2544 * cds_is_sub_20_mhz_enabled() - API to get sub 20-MHZ enabled
2545 *
2546 * Return: true if 5 or 10 mhz is enabled, false otherwise
2547 */
2548bool cds_is_sub_20_mhz_enabled(void)
2549{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002550 struct cds_context *p_cds_context;
Naveen Rawat64e477e2016-05-20 10:34:56 -07002551
2552 p_cds_context = cds_get_context(QDF_MODULE_ID_QDF);
2553 if (!p_cds_context) {
2554 cds_err("%s: cds context is invalid", __func__);
2555 return false;
2556 }
2557
2558 if (p_cds_context->cds_cfg)
2559 return p_cds_context->cds_cfg->sub_20_channel_width;
2560
2561 return false;
2562}
2563
Komal Seelam78ff65a2016-08-18 15:25:24 +05302564/**
Naveen Rawat91df30a2016-10-12 21:26:18 -07002565 * cds_is_self_recovery_enabled() - API to get self recovery enabled
2566 *
2567 * Return: true if self recovery enabled, false otherwise
2568 */
2569bool cds_is_self_recovery_enabled(void)
2570{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002571 struct cds_context *p_cds_context;
Naveen Rawat91df30a2016-10-12 21:26:18 -07002572
2573 p_cds_context = cds_get_context(QDF_MODULE_ID_QDF);
2574 if (!p_cds_context) {
2575 cds_err("%s: cds context is invalid", __func__);
2576 return false;
2577 }
2578
2579 if (p_cds_context->cds_cfg)
2580 return p_cds_context->cds_cfg->self_recovery_enabled;
2581
2582 return false;
2583}
2584
2585/**
Komal Seelam78ff65a2016-08-18 15:25:24 +05302586 * cds_svc_fw_shutdown_ind() - API to send userspace about FW crash
2587 *
2588 * @dev: Device Pointer
2589 *
2590 * Return: None
2591 */
2592void cds_svc_fw_shutdown_ind(struct device *dev)
2593{
2594 hdd_svc_fw_shutdown_ind(dev);
2595}
Himanshu Agarwal46956a52016-07-26 19:46:25 +05302596
Nirav Shaheb017be2018-02-15 11:20:58 +05302597#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
Himanshu Agarwal46956a52016-07-26 19:46:25 +05302598/*
2599 * cds_pkt_stats_to_logger_thread() - send pktstats to user
2600 * @pl_hdr: Pointer to pl_hdr
2601 * @pkt_dump: Pointer to pkt_dump data structure.
2602 * @data: Pointer to data
2603 *
2604 * This function is used to send the pkt stats to SVC module.
2605 *
2606 * Return: None
2607 */
2608inline void cds_pkt_stats_to_logger_thread(void *pl_hdr, void *pkt_dump,
2609 void *data)
2610{
2611 if (cds_get_ring_log_level(RING_ID_PER_PACKET_STATS) !=
2612 WLAN_LOG_LEVEL_ACTIVE)
2613 return;
2614
2615 wlan_pkt_stats_to_logger_thread(pl_hdr, pkt_dump, data);
2616}
Nirav Shaheb017be2018-02-15 11:20:58 +05302617#endif
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08002618
2619/**
2620 * cds_get_conparam() - Get the connection mode parameters
2621 *
2622 * Return the connection mode parameter set by insmod or set during statically
2623 * linked driver
2624 *
Jeff Johnson876c1a62017-12-12 10:43:07 -08002625 * Return: enum QDF_GLOBAL_MODE
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08002626 */
Jeff Johnson876c1a62017-12-12 10:43:07 -08002627enum QDF_GLOBAL_MODE cds_get_conparam(void)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08002628{
Jeff Johnson876c1a62017-12-12 10:43:07 -08002629 enum QDF_GLOBAL_MODE con_mode;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08002630
2631 con_mode = hdd_get_conparam();
2632
2633 return con_mode;
2634}
Dustin Brown8d2d0f52017-04-03 17:02:08 -07002635
Rachit Kankaneb1035622018-01-24 18:41:35 +05302636#ifdef FEATURE_HTC_CREDIT_HISTORY
Dustin Brown8d2d0f52017-04-03 17:02:08 -07002637inline void
2638cds_print_htc_credit_history(uint32_t count, qdf_abstract_print *print,
2639 void *print_priv)
2640{
2641 htc_print_credit_history(gp_cds_context->htc_ctx, count,
2642 print, print_priv);
2643}
2644#endif
Sravan Kumar Kairamc1ae71c2017-02-24 12:27:27 +05302645
Poddar, Siddarth3906e172018-01-09 11:24:58 +05302646uint32_t cds_get_connectivity_stats_pkt_bitmap(void *context)
2647{
2648 struct hdd_adapter *adapter = NULL;
2649
Alok Kumarfa826fd2018-02-19 15:10:34 +05302650 if (!context)
2651 return 0;
2652
Poddar, Siddarth3906e172018-01-09 11:24:58 +05302653 adapter = (struct hdd_adapter *)context;
2654 if (unlikely(adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07002655 cds_err("Magic cookie(%x) for adapter sanity verification is invalid",
2656 adapter->magic);
Alok Kumard27a9ed2018-04-17 10:36:24 +05302657 return 0;
Poddar, Siddarth3906e172018-01-09 11:24:58 +05302658 }
2659 return adapter->pkt_type_bitmap;
2660}
2661
2662/**
2663 * cds_get_arp_stats_gw_ip() - get arp stats track IP
2664 *
2665 * Return: ARP stats IP to track
2666 */
Poddar, Siddarth31797fa2018-01-22 17:24:15 +05302667uint32_t cds_get_arp_stats_gw_ip(void *context)
Sravan Kumar Kairamc1ae71c2017-02-24 12:27:27 +05302668{
Alok Kumarfa826fd2018-02-19 15:10:34 +05302669 struct hdd_adapter *adapter = NULL;
2670
2671 if (!context)
2672 return 0;
2673
2674 adapter = (struct hdd_adapter *)context;
Sravan Kumar Kairamc1ae71c2017-02-24 12:27:27 +05302675
Poddar, Siddarth31797fa2018-01-22 17:24:15 +05302676 if (unlikely(adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07002677 cds_err("Magic cookie(%x) for adapter sanity verification is invalid",
2678 adapter->magic);
Sravan Kumar Kairamc1ae71c2017-02-24 12:27:27 +05302679 return 0;
2680 }
2681
Poddar, Siddarth31797fa2018-01-22 17:24:15 +05302682 return adapter->track_arp_ip;
Sravan Kumar Kairamc1ae71c2017-02-24 12:27:27 +05302683}
2684
2685/**
2686 * cds_incr_arp_stats_tx_tgt_delivered() - increment ARP stats
2687 *
2688 * Return: none
2689 */
2690void cds_incr_arp_stats_tx_tgt_delivered(void)
2691{
2692 struct hdd_context *hdd_ctx;
2693 struct hdd_adapter *adapter = NULL;
2694
Jeff Johnson323a6f02018-05-29 15:09:12 -07002695 hdd_ctx = gp_cds_context->hdd_context;
Sravan Kumar Kairamc1ae71c2017-02-24 12:27:27 +05302696 if (!hdd_ctx) {
2697 cds_err("Hdd Context is Null");
2698 return;
2699 }
2700
2701 hdd_for_each_adapter(hdd_ctx, adapter) {
2702 if (QDF_STA_MODE == adapter->device_mode)
2703 break;
2704 }
2705
2706 if (adapter)
2707 adapter->hdd_stats.hdd_arp_stats.tx_host_fw_sent++;
2708}
2709
2710/**
2711 * cds_incr_arp_stats_tx_tgt_acked() - increment ARP stats
2712 *
2713 * Return: none
2714 */
2715void cds_incr_arp_stats_tx_tgt_acked(void)
2716{
2717 struct hdd_context *hdd_ctx;
2718 struct hdd_adapter *adapter = NULL;
2719
Jeff Johnson323a6f02018-05-29 15:09:12 -07002720 hdd_ctx = gp_cds_context->hdd_context;
Sravan Kumar Kairamc1ae71c2017-02-24 12:27:27 +05302721 if (!hdd_ctx) {
2722 cds_err("Hdd Context is Null");
2723 return;
2724 }
2725
2726 hdd_for_each_adapter(hdd_ctx, adapter) {
2727 if (QDF_STA_MODE == adapter->device_mode)
2728 break;
2729 }
2730
2731 if (adapter)
2732 adapter->hdd_stats.hdd_arp_stats.tx_ack_cnt++;
2733}
Himanshu Agarwaledf30dc2017-06-05 15:54:27 +05302734
2735#ifdef ENABLE_SMMU_S1_TRANSLATION
Yun Park45d35972018-03-02 09:57:54 -08002736QDF_STATUS cds_smmu_mem_map_setup(qdf_device_t osdev, bool ipa_present)
Himanshu Agarwaledf30dc2017-06-05 15:54:27 +05302737{
2738 int attr = 0;
Yun Park45d35972018-03-02 09:57:54 -08002739 bool ipa_smmu_enable = false;
Himanshu Agarwaledf30dc2017-06-05 15:54:27 +05302740 struct dma_iommu_mapping *mapping = pld_smmu_get_mapping(osdev->dev);
2741
2742 osdev->smmu_s1_enabled = false;
Himanshu Agarwala89ce242017-11-17 17:36:34 +05302743
Yun Park45d35972018-03-02 09:57:54 -08002744 if (ipa_present) {
2745 ipa_smmu_enable = qdf_get_ipa_smmu_enabled();
2746 if (ipa_smmu_enable)
2747 cds_info("SMMU enabled from IPA side");
2748 else
2749 cds_info("SMMU not enabled from IPA side");
2750 }
Himanshu Agarwala89ce242017-11-17 17:36:34 +05302751
2752 if (mapping && ((iommu_domain_get_attr(mapping->domain,
2753 DOMAIN_ATTR_S1_BYPASS, &attr) == 0) &&
2754 !attr)) {
2755 cds_info("SMMU enabled from WLAN side");
Yun Park45d35972018-03-02 09:57:54 -08002756
2757 if (ipa_present) {
2758 if (ipa_smmu_enable) {
2759 cds_info("SMMU enabled from both IPA and WLAN side");
2760 osdev->smmu_s1_enabled = true;
2761 } else {
2762 cds_err("SMMU mismatch: IPA: disable, WLAN: enable");
2763 return QDF_STATUS_E_FAILURE;
2764 }
Himanshu Agarwala89ce242017-11-17 17:36:34 +05302765 } else {
Yun Park45d35972018-03-02 09:57:54 -08002766 osdev->smmu_s1_enabled = true;
Himanshu Agarwala89ce242017-11-17 17:36:34 +05302767 }
Yun Park45d35972018-03-02 09:57:54 -08002768
Himanshu Agarwala89ce242017-11-17 17:36:34 +05302769 } else {
2770 cds_info("No SMMU mapping present or SMMU disabled from WLAN side");
Yun Park45d35972018-03-02 09:57:54 -08002771
2772 if (ipa_present) {
2773 if (ipa_smmu_enable) {
2774 cds_err("SMMU mismatch: IPA: enable, WLAN: disable");
2775 return QDF_STATUS_E_FAILURE;
2776 } else {
Jeff Johnsonf2cf6592018-05-06 16:27:44 -07002777 cds_info("SMMU disabled from both IPA and WLAN side");
Yun Park45d35972018-03-02 09:57:54 -08002778 }
Himanshu Agarwala89ce242017-11-17 17:36:34 +05302779 }
Himanshu Agarwaledf30dc2017-06-05 15:54:27 +05302780 }
Sravan Kumar Kairam5a8c4ba2018-04-12 11:54:31 +05302781 osdev->iommu_mapping = mapping;
Himanshu Agarwaledf30dc2017-06-05 15:54:27 +05302782
Himanshu Agarwala89ce242017-11-17 17:36:34 +05302783 return QDF_STATUS_SUCCESS;
Himanshu Agarwaledf30dc2017-06-05 15:54:27 +05302784}
2785
Sravan Kumar Kairam4329c5f2018-03-02 11:26:29 +05302786#ifdef IPA_OFFLOAD
Himanshu Agarwaledf30dc2017-06-05 15:54:27 +05302787int cds_smmu_map_unmap(bool map, uint32_t num_buf, qdf_mem_info_t *buf_arr)
2788{
Sravan Kumar Kairam983a4452018-03-20 13:30:22 +05302789 return ucfg_ipa_uc_smmu_map(map, num_buf, buf_arr);
Himanshu Agarwaledf30dc2017-06-05 15:54:27 +05302790}
2791#else
Sravan Kumar Kairam4329c5f2018-03-02 11:26:29 +05302792int cds_smmu_map_unmap(bool map, uint32_t num_buf, qdf_mem_info_t *buf_arr)
2793{
2794 return 0;
2795}
2796#endif
2797
2798#else
Yun Park45d35972018-03-02 09:57:54 -08002799QDF_STATUS cds_smmu_mem_map_setup(qdf_device_t osdev, bool ipa_present)
Himanshu Agarwaledf30dc2017-06-05 15:54:27 +05302800{
Sravan Kumar Kairamb664b6c2018-02-27 17:43:10 +05302801 osdev->smmu_s1_enabled = false;
Sravan Kumar Kairam5a8c4ba2018-04-12 11:54:31 +05302802 osdev->iommu_mapping = NULL;
Himanshu Agarwala89ce242017-11-17 17:36:34 +05302803 return QDF_STATUS_SUCCESS;
Himanshu Agarwaledf30dc2017-06-05 15:54:27 +05302804}
2805
2806int cds_smmu_map_unmap(bool map, uint32_t num_buf, qdf_mem_info_t *buf_arr)
2807{
2808 return 0;
2809}
2810#endif