blob: 898ffebc6c2deb5ad507c31a955d65ff173d0350 [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
Alok Kumarac741772018-10-11 12:40:42 +05302 * Copyright (c) 2012-2019 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>
Rakshith Suresh Patkarba55fd02018-11-20 13:03:43 +053039#include <scheduler_core.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080040
Yuanyuan Liu0e0aa932016-05-12 10:17:58 -070041#include "pld_common.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080042#include "sap_api.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080043#include "bmi.h"
44#include "ol_fw.h"
45#include "ol_if_athvar.h"
46#include "hif.h"
Tushnim Bhattacharyya12b48742017-03-13 12:46:45 -070047#include "wlan_policy_mgr_api.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080048#include "cds_utils.h"
49#include "wlan_logging_sock_svc.h"
50#include "wma.h"
Nirav Shah7f337db2016-05-25 10:49:02 +053051#include "pktlog_ac.h"
Pramod Simha0d3b9362017-03-27 14:59:58 -070052#include "wlan_policy_mgr_api.h"
Leo Chang9b097032016-10-28 11:03:17 -070053
54#include <cdp_txrx_cmn_reg.h>
55#include <cdp_txrx_cfg.h>
56#include <cdp_txrx_misc.h>
Rakesh Pillai6a36b0a2019-09-06 16:30:05 +053057#include <ol_defines.h>
Rajeev Kumar97767a02016-11-30 11:20:40 -080058#include <dispatcher_init_deinit.h>
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -080059#include <cdp_txrx_handle.h>
Govind Singh27a74032017-11-10 15:08:19 +053060#include "target_type.h"
Zhang Qian47e22ce2018-01-04 15:38:38 +080061#include "wlan_ocb_ucfg_api.h"
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +053062#include "wlan_ipa_ucfg_api.h"
Mohit Khanna70322002018-05-15 19:21:32 -070063#include "dp_txrx.h"
Himanshu Agarwaledf30dc2017-06-05 15:54:27 +053064#ifdef ENABLE_SMMU_S1_TRANSLATION
65#include "pld_common.h"
66#include <asm/dma-iommu.h>
67#include <linux/iommu.h>
68#endif
Sravan Kumar Kairamb8bdf522018-05-30 22:14:50 +053069
70#ifdef QCA_WIFI_QCA8074
71#include <target_if_dp.h>
72#endif
Bala Venkatesh2fde2c62018-09-11 20:33:24 +053073#include "wlan_mlme_ucfg_api.h"
jitiphil377bcc12018-10-05 19:46:08 +053074#include "cfg_ucfg_api.h"
Rajeev Kumar00750362019-04-03 18:59:38 -070075#include "wlan_cp_stats_mc_ucfg_api.h"
Sravan Kumar Kairamb8bdf522018-05-30 22:14:50 +053076
Himanshu Agarwaledf30dc2017-06-05 15:54:27 +053077/* Preprocessor Definitions and Constants */
78
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080079/* Preprocessor Definitions and Constants */
80
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080081/* Data definitions */
Jeff Johnson2b6982c2018-05-29 14:56:11 -070082static struct cds_context g_cds_context;
83static struct cds_context *gp_cds_context;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053084static struct __qdf_device g_qdf_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080085
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080086static uint8_t cds_multicast_logging;
87
Sravan Kumar Kairamb8bdf522018-05-30 22:14:50 +053088#ifdef QCA_WIFI_QCA8074
Leo Chang9b097032016-10-28 11:03:17 -070089static struct ol_if_ops dp_ol_if_ops = {
Sravan Kumar Kairamb8bdf522018-05-30 22:14:50 +053090 .peer_set_default_routing = target_if_peer_set_default_routing,
91 .peer_rx_reorder_queue_setup = target_if_peer_rx_reorder_queue_setup,
92 .peer_rx_reorder_queue_remove = target_if_peer_rx_reorder_queue_remove,
Liangwei Dong897b4392019-11-05 19:16:02 +080093 .is_hw_dbs_2x2_capable = policy_mgr_is_dp_hw_dbs_2x2_capable,
Sravan Kumar Kairamb8bdf522018-05-30 22:14:50 +053094 .lro_hash_config = target_if_lro_hash_config,
Manjunathappa Prakash8280a152019-05-23 17:29:24 -070095 .rx_invalid_peer = wma_rx_invalid_peer_ind,
Jinwei Chenc4602362019-07-22 15:34:05 +080096 .is_roam_inprogress = wma_is_roam_in_progress,
97 .get_con_mode = cds_get_conparam
Leo Chang9b097032016-10-28 11:03:17 -070098 /* TODO: Add any other control path calls required to OL_IF/WMA layer */
99};
Sravan Kumar Kairamb8bdf522018-05-30 22:14:50 +0530100#else
101static struct ol_if_ops dp_ol_if_ops;
102#endif
Leo Chang9b097032016-10-28 11:03:17 -0700103
Srinivas Girigowda161b9f22017-07-24 17:38:09 -0700104static void cds_trigger_recovery_work(void *param);
105
106/**
Dustin Brown2a24d7c2018-08-16 10:19:10 -0700107 * struct cds_recovery_call_info - caller information for cds_trigger_recovery
108 * @func: caller's function name
109 * @line: caller's line number
110 */
111struct cds_recovery_call_info {
112 const char *func;
113 uint32_t line;
114} __cds_recovery_caller;
115
116/**
Srinivas Girigowda161b9f22017-07-24 17:38:09 -0700117 * cds_recovery_work_init() - Initialize recovery work queue
118 *
119 * Return: none
120 */
121static QDF_STATUS cds_recovery_work_init(void)
122{
123 qdf_create_work(0, &gp_cds_context->cds_recovery_work,
Dustin Brown2a24d7c2018-08-16 10:19:10 -0700124 cds_trigger_recovery_work, &__cds_recovery_caller);
Srinivas Girigowda161b9f22017-07-24 17:38:09 -0700125 gp_cds_context->cds_recovery_wq =
126 qdf_create_workqueue("cds_recovery_workqueue");
Jeff Johnsone7afbe92019-03-18 13:43:43 -0700127 if (!gp_cds_context->cds_recovery_wq) {
Srinivas Girigowda161b9f22017-07-24 17:38:09 -0700128 cds_err("Failed to create cds_recovery_workqueue");
129 return QDF_STATUS_E_FAILURE;
130 }
131
132 return QDF_STATUS_SUCCESS;
133}
134
135/**
136 * cds_recovery_work_deinit() - Initialize recovery work queue
137 *
138 * Return: none
139 */
140static void cds_recovery_work_deinit(void)
141{
142 if (gp_cds_context->cds_recovery_wq) {
143 qdf_flush_workqueue(0, gp_cds_context->cds_recovery_wq);
144 qdf_destroy_workqueue(0, gp_cds_context->cds_recovery_wq);
145 }
146}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800147
Venkata Sharath Chandra Manchala83985632017-02-28 14:16:22 -0800148/** cds_get_datapath_handles - Initialize pdev, vdev and soc
149 * @soc - soc handle
150 * @vdev - virtual handle
151 * @pdev - physical handle
152 */
153uint8_t cds_get_datapath_handles(void **soc, struct cdp_pdev **pdev,
154 struct cdp_vdev **vdev, uint8_t sessionId)
155{
156
157 (*soc) = cds_get_context(QDF_MODULE_ID_SOC);
158
159 if (!(*soc)) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700160 cds_err("soc handle is invalid");
Venkata Sharath Chandra Manchala83985632017-02-28 14:16:22 -0800161 return -EINVAL;
162 }
163
164 (*pdev) = cds_get_context(QDF_MODULE_ID_TXRX);
165
166 if (!(*pdev)) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700167 cds_err("pdev handle is invalid");
Venkata Sharath Chandra Manchala83985632017-02-28 14:16:22 -0800168 return -EINVAL;
169 }
170
171 (*vdev) = cdp_get_vdev_from_vdev_id((*soc), (*pdev),
172 sessionId);
173
174 if (!(*vdev)) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700175 cds_err("vdev handle is invalid");
Venkata Sharath Chandra Manchala83985632017-02-28 14:16:22 -0800176 return -EINVAL;
177 }
178 return 0;
179}
180
Rajeev Kumarc58f7c22019-05-10 11:07:38 -0700181static bool cds_is_drv_connected(void)
182{
183 int ret;
184 qdf_device_t qdf_ctx;
185
186 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
187 if (!qdf_ctx) {
188 cds_err("cds context is invalid");
189 return false;
190 }
191
192 ret = pld_is_drv_connected(qdf_ctx->dev);
193
194 return ((ret > 0) ? true : false);
195}
Venkata Sharath Chandra Manchala83985632017-02-28 14:16:22 -0800196
Manikandan Mohan1baadae2019-08-23 08:32:56 -0700197static QDF_STATUS cds_wmi_send_recv_qmi(void *buf, uint32_t len, void * cb_ctx,
198 qdf_wmi_recv_qmi_cb wmi_rx_cb)
199{
200 qdf_device_t qdf_ctx;
201
202 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
203 if (!qdf_ctx) {
204 cds_err("cds context is invalid");
205 return QDF_STATUS_E_INVAL;
206 }
207
208 if (pld_qmi_send(qdf_ctx->dev, 0, buf, len, cb_ctx, wmi_rx_cb))
209 return QDF_STATUS_E_INVAL;
210
211 return QDF_STATUS_SUCCESS;
212}
213
Jeff Johnson7aaeeea2017-09-26 13:16:24 -0700214QDF_STATUS cds_init(void)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800215{
Dustin Browna2a39dc2018-09-17 15:29:59 -0700216 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800217
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800218 gp_cds_context = &g_cds_context;
219
Dustin Browna2a39dc2018-09-17 15:29:59 -0700220 status = cds_recovery_work_init();
221 if (QDF_IS_STATUS_ERROR(status)) {
222 cds_err("Failed to init recovery work; status:%u", status);
wadesongae4ffd12017-10-24 16:45:54 +0800223 goto deinit;
224 }
Srinivas Girigowda161b9f22017-07-24 17:38:09 -0700225
Dustin Browna2a39dc2018-09-17 15:29:59 -0700226 cds_ssr_protect_init();
227
228 gp_cds_context->qdf_ctx = &g_qdf_ctx;
229
230 qdf_register_self_recovery_callback(__cds_trigger_recovery);
231 qdf_register_fw_down_callback(cds_is_fw_down);
Liangwei Dong71917802018-09-25 02:10:07 -0400232 qdf_register_recovering_state_query_callback(cds_is_driver_recovering);
Rajeev Kumarc58f7c22019-05-10 11:07:38 -0700233 qdf_register_drv_connected_callback(cds_is_drv_connected);
Manikandan Mohan1baadae2019-08-23 08:32:56 -0700234 qdf_register_wmi_send_recv_qmi_callback(cds_wmi_send_recv_qmi);
Dustin Browna2a39dc2018-09-17 15:29:59 -0700235
wadesongae4ffd12017-10-24 16:45:54 +0800236 return QDF_STATUS_SUCCESS;
Dustin Browna2a39dc2018-09-17 15:29:59 -0700237
wadesongae4ffd12017-10-24 16:45:54 +0800238deinit:
wadesongae4ffd12017-10-24 16:45:54 +0800239 gp_cds_context = NULL;
240 qdf_mem_zero(&g_cds_context, sizeof(g_cds_context));
Dustin Browna2a39dc2018-09-17 15:29:59 -0700241
242 return status;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -0800243}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800244
245/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -0800246 * cds_deinit() - Deinitialize CDS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800247 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -0800248 * This function frees the CDS resources
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800249 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -0800250void cds_deinit(void)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800251{
Dustin Browna2a39dc2018-09-17 15:29:59 -0700252 QDF_BUG(gp_cds_context);
253 if (!gp_cds_context)
Prashanth Bhatta5da711e2015-11-30 14:28:52 -0800254 return;
Dustin Brown3fdaaf62019-03-18 14:00:16 -0700255
Liangwei Dong71917802018-09-25 02:10:07 -0400256 qdf_register_recovering_state_query_callback(NULL);
Dustin Browna2a39dc2018-09-17 15:29:59 -0700257 qdf_register_fw_down_callback(NULL);
258 qdf_register_self_recovery_callback(NULL);
Manikandan Mohan1baadae2019-08-23 08:32:56 -0700259 qdf_register_wmi_send_recv_qmi_callback(NULL);
Arunk Khandavalli4cc97a92016-09-14 23:13:07 +0530260
Anurag Chouhan6d760662016-02-20 16:05:43 +0530261 gp_cds_context->qdf_ctx = NULL;
Dustin Browna2a39dc2018-09-17 15:29:59 -0700262 qdf_mem_zero(&g_qdf_ctx, sizeof(g_qdf_ctx));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800263
Dustin Browna2a39dc2018-09-17 15:29:59 -0700264 /* currently, no ssr_protect_deinit */
265
266 cds_recovery_work_deinit();
267
268 gp_cds_context = NULL;
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530269 qdf_mem_zero(&g_cds_context, sizeof(g_cds_context));
Prashanth Bhatta5da711e2015-11-30 14:28:52 -0800270}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800271
Abhishek Singh437606a2016-04-27 13:51:49 +0530272#ifdef FEATURE_WLAN_DIAG_SUPPORT
273/**
274 * cds_tdls_tx_rx_mgmt_event()- send tdls mgmt rx tx event
275 * @event_id: event id
276 * @tx_rx: tx or rx
277 * @type: type of frame
278 * @action_sub_type: action frame type
279 * @peer_mac: peer mac
280 *
281 * This Function sends tdls mgmt rx tx diag event
282 *
283 * Return: void.
284 */
285void cds_tdls_tx_rx_mgmt_event(uint8_t event_id, uint8_t tx_rx,
286 uint8_t type, uint8_t action_sub_type, uint8_t *peer_mac)
287{
288 WLAN_HOST_DIAG_EVENT_DEF(tdls_tx_rx_mgmt,
289 struct host_event_tdls_tx_rx_mgmt);
290
291 tdls_tx_rx_mgmt.event_id = event_id;
292 tdls_tx_rx_mgmt.tx_rx = tx_rx;
293 tdls_tx_rx_mgmt.type = type;
294 tdls_tx_rx_mgmt.action_sub_type = action_sub_type;
295 qdf_mem_copy(tdls_tx_rx_mgmt.peer_mac,
296 peer_mac, CDS_MAC_ADDRESS_LEN);
297 WLAN_HOST_DIAG_EVENT_REPORT(&tdls_tx_rx_mgmt,
298 EVENT_WLAN_TDLS_TX_RX_MGMT);
299}
300#endif
301
Leo Chang9b097032016-10-28 11:03:17 -0700302/**
gbian62edd7e2017-03-07 13:12:13 +0800303 * cds_cfg_update_ac_specs_params() - update ac_specs params
304 * @olcfg: cfg handle
305 * @mac_params: mac params
306 *
307 * Return: none
308 */
309static void
310cds_cfg_update_ac_specs_params(struct txrx_pdev_cfg_param_t *olcfg,
311 struct cds_config_info *cds_cfg)
312{
313 int i;
314
Jeff Johnsone7afbe92019-03-18 13:43:43 -0700315 if (!olcfg)
gbian62edd7e2017-03-07 13:12:13 +0800316 return;
317
Jeff Johnsone7afbe92019-03-18 13:43:43 -0700318 if (!cds_cfg)
gbian62edd7e2017-03-07 13:12:13 +0800319 return;
320
Srinivas Girigowdad462f3b2019-03-25 14:05:33 -0700321 for (i = 0; i < QCA_WLAN_AC_ALL; i++) {
gbian62edd7e2017-03-07 13:12:13 +0800322 olcfg->ac_specs[i].wrr_skip_weight =
323 cds_cfg->ac_specs[i].wrr_skip_weight;
324 olcfg->ac_specs[i].credit_threshold =
325 cds_cfg->ac_specs[i].credit_threshold;
326 olcfg->ac_specs[i].send_limit =
327 cds_cfg->ac_specs[i].send_limit;
328 olcfg->ac_specs[i].credit_reserve =
329 cds_cfg->ac_specs[i].credit_reserve;
330 olcfg->ac_specs[i].discard_weight =
331 cds_cfg->ac_specs[i].discard_weight;
332 }
333}
334
hangtianb9c91362019-06-07 10:39:38 +0800335#if defined(QCA_LL_TX_FLOW_CONTROL_V2) || defined(QCA_LL_PDEV_TX_FLOW_CONTROL)
Nirav Shahe6c8e642018-03-25 11:42:48 +0530336static inline void
jitiphil377bcc12018-10-05 19:46:08 +0530337cds_cdp_set_flow_control_params(struct wlan_objmgr_psoc *psoc,
Nirav Shahe6c8e642018-03-25 11:42:48 +0530338 struct txrx_pdev_cfg_param_t *cdp_cfg)
339{
jitiphil377bcc12018-10-05 19:46:08 +0530340 cdp_cfg->tx_flow_stop_queue_th =
341 cfg_get(psoc, CFG_DP_TX_FLOW_STOP_QUEUE_TH);
Nirav Shahe6c8e642018-03-25 11:42:48 +0530342 cdp_cfg->tx_flow_start_queue_offset =
jitiphil377bcc12018-10-05 19:46:08 +0530343 cfg_get(psoc, CFG_DP_TX_FLOW_START_QUEUE_OFFSET);
Nirav Shahe6c8e642018-03-25 11:42:48 +0530344}
hangtianb9c91362019-06-07 10:39:38 +0800345#else
346static inline void
347cds_cdp_set_flow_control_params(struct wlan_objmgr_psoc *psoc,
348 struct txrx_pdev_cfg_param_t *cdp_cfg)
349{}
350#endif
Nirav Shahe6c8e642018-03-25 11:42:48 +0530351
Tiger Yue40e7832019-04-25 10:46:53 +0800352#ifdef QCA_SUPPORT_TXRX_DRIVER_TCP_DEL_ACK
353static inline void
354cds_cdp_update_del_ack_params(struct wlan_objmgr_psoc *psoc,
355 struct txrx_pdev_cfg_param_t *cdp_cfg)
356{
357 cdp_cfg->del_ack_enable =
358 cfg_get(psoc, CFG_DP_DRIVER_TCP_DELACK_ENABLE);
359 cdp_cfg->del_ack_pkt_count =
360 cfg_get(psoc, CFG_DP_DRIVER_TCP_DELACK_PKT_CNT);
361 cdp_cfg->del_ack_timer_value =
362 cfg_get(psoc, CFG_DP_DRIVER_TCP_DELACK_TIMER_VALUE);
363}
364#else
365static inline void
366cds_cdp_update_del_ack_params(struct wlan_objmgr_psoc *psoc,
367 struct txrx_pdev_cfg_param_t *cdp_cfg)
368{}
369#endif
370
Nirav Shahfb9b1df2019-11-15 11:40:52 +0530371#ifdef WLAN_SUPPORT_TXRX_HL_BUNDLE
372static inline void
373cds_cdp_update_bundle_params(struct wlan_objmgr_psoc *psoc,
374 struct txrx_pdev_cfg_param_t *cdp_cfg)
375{
376 cdp_cfg->bundle_timer_value =
377 cfg_get(psoc, CFG_DP_HL_BUNDLE_TIMER_VALUE);
378 cdp_cfg->bundle_size =
379 cfg_get(psoc, CFG_DP_HL_BUNDLE_SIZE);
380}
381#else
382static inline void
383cds_cdp_update_bundle_params(struct wlan_objmgr_psoc *psoc,
384 struct txrx_pdev_cfg_param_t *cdp_cfg)
385{
386}
387#endif
388
gbian62edd7e2017-03-07 13:12:13 +0800389/**
Leo Chang9b097032016-10-28 11:03:17 -0700390 * cds_cdp_cfg_attach() - attach data path config module
391 * @cds_cfg: generic platform level config instance
392 *
393 * Return: none
394 */
jitiphil377bcc12018-10-05 19:46:08 +0530395static void cds_cdp_cfg_attach(struct wlan_objmgr_psoc *psoc)
Leo Chang9b097032016-10-28 11:03:17 -0700396{
397 struct txrx_pdev_cfg_param_t cdp_cfg = {0};
398 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
jitiphil377bcc12018-10-05 19:46:08 +0530399 struct hdd_context *hdd_ctx = gp_cds_context->hdd_context;
Leo Chang9b097032016-10-28 11:03:17 -0700400
jitiphil377bcc12018-10-05 19:46:08 +0530401 cdp_cfg.is_full_reorder_offload =
402 cfg_get(psoc, CFG_DP_REORDER_OFFLOAD_SUPPORT);
403 cdp_cfg.is_uc_offload_enabled = ucfg_ipa_uc_is_enabled();
404 cdp_cfg.uc_tx_buffer_count = cfg_get(psoc, CFG_DP_IPA_UC_TX_BUF_COUNT);
405 cdp_cfg.uc_tx_buffer_size =
406 cfg_get(psoc, CFG_DP_IPA_UC_TX_BUF_SIZE);
407 cdp_cfg.uc_rx_indication_ring_count =
408 cfg_get(psoc, CFG_DP_IPA_UC_RX_IND_RING_COUNT);
409 cdp_cfg.uc_tx_partition_base =
410 cfg_get(psoc, CFG_DP_IPA_UC_TX_PARTITION_BASE);
411 cdp_cfg.enable_rxthread = hdd_ctx->enable_rxthread;
Leo Chang9b097032016-10-28 11:03:17 -0700412 cdp_cfg.ip_tcp_udp_checksum_offload =
jitiphil377bcc12018-10-05 19:46:08 +0530413 cfg_get(psoc, CFG_DP_TCP_UDP_CKSUM_OFFLOAD);
414 cdp_cfg.ce_classify_enabled =
415 cfg_get(psoc, CFG_DP_CE_CLASSIFY_ENABLE);
416 cdp_cfg.tso_enable = cfg_get(psoc, CFG_DP_TSO);
417 cdp_cfg.lro_enable = cfg_get(psoc, CFG_DP_LRO);
418 cdp_cfg.enable_data_stall_detection =
419 cfg_get(psoc, CFG_DP_ENABLE_DATA_STALL_DETECTION);
jitiphil377bcc12018-10-05 19:46:08 +0530420 cdp_cfg.gro_enable = cfg_get(psoc, CFG_DP_GRO);
421 cdp_cfg.enable_flow_steering =
422 cfg_get(psoc, CFG_DP_FLOW_STEERING_ENABLED);
423 cdp_cfg.disable_intra_bss_fwd =
424 cfg_get(psoc, CFG_DP_AP_STA_SECURITY_SEPERATION);
Leo Chang9b097032016-10-28 11:03:17 -0700425
Tiger Yue40e7832019-04-25 10:46:53 +0800426 cds_cdp_update_del_ack_params(psoc, &cdp_cfg);
427
Nirav Shahfb9b1df2019-11-15 11:40:52 +0530428 cds_cdp_update_bundle_params(psoc, &cdp_cfg);
429
Kiran Kumar Lokere9aecfee2016-11-23 17:37:42 -0800430 gp_cds_context->cfg_ctx = cdp_cfg_attach(soc, gp_cds_context->qdf_ctx,
431 (void *)(&cdp_cfg));
432 if (!gp_cds_context->cfg_ctx) {
433 WMA_LOGP("%s: failed to init cfg handle", __func__);
434 return;
435 }
436
Leo Chang9b097032016-10-28 11:03:17 -0700437 /* Configure Receive flow steering */
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -0800438 cdp_cfg_set_flow_steering(soc, gp_cds_context->cfg_ctx,
jitiphil377bcc12018-10-05 19:46:08 +0530439 cfg_get(psoc, CFG_DP_FLOW_STEERING_ENABLED));
Leo Chang9b097032016-10-28 11:03:17 -0700440
jitiphil377bcc12018-10-05 19:46:08 +0530441 cds_cdp_set_flow_control_params(psoc, &cdp_cfg);
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -0800442 cdp_cfg_set_flow_control_parameters(soc, gp_cds_context->cfg_ctx,
Nirav Shahe6c8e642018-03-25 11:42:48 +0530443 (void *)&cdp_cfg);
Leo Chang9b097032016-10-28 11:03:17 -0700444
445 /* adjust the cfg_ctx default value based on setting */
446 cdp_cfg_set_rx_fwd_disabled(soc, gp_cds_context->cfg_ctx,
jitiphil377bcc12018-10-05 19:46:08 +0530447 cfg_get(psoc,
448 CFG_DP_AP_STA_SECURITY_SEPERATION));
Leo Chang9b097032016-10-28 11:03:17 -0700449
450 /*
451 * adjust the packet log enable default value
452 * based on CFG INI setting
453 */
454 cdp_cfg_set_packet_log_enabled(soc, gp_cds_context->cfg_ctx,
455 (uint8_t)cds_is_packet_log_enabled());
Yu Wang66a250b2017-07-19 11:46:40 +0800456
457 /* adjust the ptp rx option default value based on CFG INI setting */
458 cdp_cfg_set_ptp_rx_opt_enabled(soc, gp_cds_context->cfg_ctx,
459 (uint8_t)cds_is_ptp_rx_opt_enabled());
Leo Chang9b097032016-10-28 11:03:17 -0700460}
Krunal Sonid32c6bc2016-10-18 18:00:21 -0700461static QDF_STATUS cds_register_all_modules(void)
462{
463 QDF_STATUS status;
464
465 scheduler_register_wma_legacy_handler(&wma_mc_process_handler);
466 scheduler_register_sys_legacy_handler(&sys_mc_process_handler);
467
468 /* Register message queues in given order such that queue priority is
469 * intact:
470 * 1) QDF_MODULE_ID_SYS: Timer queue(legacy SYS queue)
471 * 2) QDF_MODULE_ID_TARGET_IF: Target interface queue
472 * 3) QDF_MODULE_ID_PE: Legacy PE message queue
473 * 4) QDF_MODULE_ID_SME: Legacy SME message queue
474 * 5) QDF_MODULE_ID_OS_IF: OS IF message queue for new components
475 */
476 status = scheduler_register_module(QDF_MODULE_ID_SYS,
477 &scheduler_timer_q_mq_handler);
478 status = scheduler_register_module(QDF_MODULE_ID_TARGET_IF,
479 &scheduler_target_if_mq_handler);
480 status = scheduler_register_module(QDF_MODULE_ID_PE,
481 &pe_mc_process_handler);
482 status = scheduler_register_module(QDF_MODULE_ID_SME,
483 &sme_mc_process_handler);
484 status = scheduler_register_module(QDF_MODULE_ID_OS_IF,
485 &scheduler_os_if_mq_handler);
Vignesh Viswanathancad91322018-04-04 17:44:28 +0530486 status = scheduler_register_module(QDF_MODULE_ID_SCAN,
487 &scheduler_scan_mq_handler);
Krunal Sonid32c6bc2016-10-18 18:00:21 -0700488 return status;
489}
490
491static QDF_STATUS cds_deregister_all_modules(void)
492{
493 QDF_STATUS status;
Krunal Sonie3399902017-02-01 09:51:42 -0800494
495 scheduler_deregister_wma_legacy_handler();
496 scheduler_deregister_sys_legacy_handler();
Jianmin Zhu4f3708d2019-04-09 11:05:33 +0800497 status = scheduler_deregister_module(QDF_MODULE_ID_SCAN);
Krunal Sonid32c6bc2016-10-18 18:00:21 -0700498 status = scheduler_deregister_module(QDF_MODULE_ID_SYS);
Rajeev Kumara88b2dc2017-01-30 16:35:14 -0800499 status = scheduler_deregister_module(QDF_MODULE_ID_TARGET_IF);
Krunal Sonid32c6bc2016-10-18 18:00:21 -0700500 status = scheduler_deregister_module(QDF_MODULE_ID_PE);
501 status = scheduler_deregister_module(QDF_MODULE_ID_SME);
502 status = scheduler_deregister_module(QDF_MODULE_ID_OS_IF);
Krunal Sonie3399902017-02-01 09:51:42 -0800503
Krunal Sonid32c6bc2016-10-18 18:00:21 -0700504 return status;
505}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800506
507/**
gbian62edd7e2017-03-07 13:12:13 +0800508 * cds_set_ac_specs_params() - set ac_specs params in cds_config_info
509 * @cds_cfg: Pointer to cds_config_info
510 * @hdd_ctx: Pointer to hdd context
511 *
512 * Return: none
513 */
514static void
515cds_set_ac_specs_params(struct cds_config_info *cds_cfg)
516{
517 int i;
Jeff Johnson2b6982c2018-05-29 14:56:11 -0700518 struct cds_context *cds_ctx;
gbian62edd7e2017-03-07 13:12:13 +0800519
Jeff Johnsone7afbe92019-03-18 13:43:43 -0700520 if (!cds_cfg)
gbian62edd7e2017-03-07 13:12:13 +0800521 return;
522
523 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
524
525 if (!cds_ctx) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700526 cds_err("Invalid CDS Context");
gbian62edd7e2017-03-07 13:12:13 +0800527 return;
528 }
529
Srinivas Girigowdad462f3b2019-03-25 14:05:33 -0700530 for (i = 0; i < QCA_WLAN_AC_ALL; i++) {
gbian62edd7e2017-03-07 13:12:13 +0800531 cds_cfg->ac_specs[i] = cds_ctx->ac_specs[i];
532 }
533}
534
535/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800536 * cds_open() - open the CDS Module
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800537 *
538 * cds_open() function opens the CDS Scheduler
539 * Upon successful initialization:
540 * - All CDS submodules should have been initialized
541 *
542 * - The CDS scheduler should have opened
543 *
544 * - All the WLAN SW components should have been opened. This includes
545 * SYS, MAC, SME, WMA and TL.
546 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530547 * Return: QDF status
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800548 */
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +0530549QDF_STATUS cds_open(struct wlan_objmgr_psoc *psoc)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800550{
Dustin Brownf7971192017-10-25 14:54:37 -0700551 QDF_STATUS status;
Arun Khandavallic811dcc2016-06-26 07:37:21 +0530552 struct cds_config_info *cds_cfg;
Anurag Chouhan6d760662016-02-20 16:05:43 +0530553 qdf_device_t qdf_ctx;
Manikandan Mohan83c939c2017-04-13 20:23:07 -0700554 struct htc_init_info htcInfo;
Komal Seelamd9106492016-02-15 10:31:44 +0530555 struct ol_context *ol_ctx;
Komal Seelam3d202862016-02-24 18:43:24 +0530556 struct hif_opaque_softc *scn;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800557 void *HTCHandle;
Jeff Johnsonc18b26c2017-09-03 08:46:45 -0700558 struct hdd_context *hdd_ctx;
Jeff Johnson2b6982c2018-05-29 14:56:11 -0700559 struct cds_context *cds_ctx;
Jeff Johnsonec563952018-06-11 09:57:09 -0700560 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800561
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700562 cds_debug("Opening CDS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800563
Arun Khandavallic811dcc2016-06-26 07:37:21 +0530564 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
565 if (!cds_ctx) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700566 cds_alert("Trying to open CDS without a PreOpen");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530567 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800568 }
569
570 /* Initialize the timer module */
Anurag Chouhan210db072016-02-22 18:42:15 +0530571 qdf_timer_module_init();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800572
573 /* Initialize bug reporting structure */
574 cds_init_log_completion();
575
Jeff Johnson2ccd8152018-05-29 16:02:23 -0700576 status = qdf_event_create(&gp_cds_context->wma_complete_event);
Dustin Brownf7971192017-10-25 14:54:37 -0700577 if (QDF_IS_STATUS_ERROR(status)) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700578 cds_alert("Unable to init wma_complete_event");
Dustin Browna22671a2018-05-29 12:13:51 -0700579 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800580 }
581
Dustin Brown5f8955a2018-08-27 10:20:24 -0700582 hdd_ctx = gp_cds_context->hdd_context;
Dustin Brownf7971192017-10-25 14:54:37 -0700583 if (!hdd_ctx || !hdd_ctx->config) {
Arun Khandavallifae92942016-08-01 13:31:08 +0530584 cds_err("Hdd Context is Null");
Dustin Brownf7971192017-10-25 14:54:37 -0700585
586 status = QDF_STATUS_E_FAILURE;
Rajeev Kumar3e5ef0d2017-01-03 14:45:31 -0800587 goto err_wma_complete_event;
Arun Khandavallifae92942016-08-01 13:31:08 +0530588 }
Kabilan Kannan15cc6ac2016-11-12 22:25:14 -0800589
Dustin Brown44cde352017-12-04 13:14:46 -0800590 status = dispatcher_enable();
591 if (QDF_IS_STATUS_ERROR(status)) {
592 cds_err("Failed to enable dispatcher; status:%d", status);
593 goto err_wma_complete_event;
594 }
595
Arun Khandavallifae92942016-08-01 13:31:08 +0530596 /* Now Open the CDS Scheduler */
Dustin Brown0707ddf2017-09-20 15:31:56 -0700597 status = cds_sched_open(gp_cds_context,
598 &gp_cds_context->qdf_sched,
599 sizeof(cds_sched_context));
Dustin Brown0707ddf2017-09-20 15:31:56 -0700600 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Brown0707ddf2017-09-20 15:31:56 -0700601 cds_alert("Failed to open CDS Scheduler");
Dustin Brown44cde352017-12-04 13:14:46 -0800602 goto err_dispatcher_disable;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800603 }
604
Anurag Chouhan6d760662016-02-20 16:05:43 +0530605 scn = cds_get_context(QDF_MODULE_ID_HIF);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800606 if (!scn) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700607 cds_alert("scn is null!");
Dustin Brownf7971192017-10-25 14:54:37 -0700608
609 status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800610 goto err_sched_close;
611 }
Arun Khandavallifae92942016-08-01 13:31:08 +0530612
Arun Khandavallifae92942016-08-01 13:31:08 +0530613 cds_cfg = cds_get_ini_config();
614 if (!cds_cfg) {
615 cds_err("Cds config is NULL");
Dustin Brownf7971192017-10-25 14:54:37 -0700616
617 status = QDF_STATUS_E_FAILURE;
Arun Khandavallifae92942016-08-01 13:31:08 +0530618 goto err_sched_close;
619 }
Dustin Brownf7971192017-10-25 14:54:37 -0700620
jitiphil377bcc12018-10-05 19:46:08 +0530621 hdd_enable_fastpath(hdd_ctx, scn);
Arun Khandavallifae92942016-08-01 13:31:08 +0530622
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800623 /* Initialize BMI and Download firmware */
Dustin Brownf7971192017-10-25 14:54:37 -0700624 ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
625 status = bmi_download_firmware(ol_ctx);
626 if (QDF_IS_STATUS_ERROR(status)) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700627 cds_alert("BMI FIALED status:%d", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800628 goto err_bmi_close;
629 }
Tiger Yu086b6992017-11-20 16:33:43 +0800630
631 hdd_wlan_update_target_info(hdd_ctx, scn);
632
Komal Seelam08633492016-02-24 18:05:07 +0530633 htcInfo.pContext = ol_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800634 htcInfo.TargetFailure = ol_target_failure;
Mukul Sharma4c60a7e2017-03-06 19:42:18 +0530635 htcInfo.TargetSendSuspendComplete =
Wu Gaod7dd6e42018-10-16 17:22:56 +0800636 ucfg_pmo_psoc_target_suspend_acknowledge;
637 htcInfo.target_initial_wakeup_cb = ucfg_pmo_psoc_handle_initial_wake_up;
Mukul Sharma4c60a7e2017-03-06 19:42:18 +0530638 htcInfo.target_psoc = (void *)psoc;
Manjunathappa Prakashf5b6f5f2019-03-27 15:17:41 -0700639 htcInfo.cfg_wmi_credit_cnt = hdd_ctx->config->cfg_wmi_credit_cnt;
Anurag Chouhan6d760662016-02-20 16:05:43 +0530640 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800641
642 /* Create HTC */
643 gp_cds_context->htc_ctx =
Yue Ma1e11d792016-02-26 18:58:44 -0800644 htc_create(scn, &htcInfo, qdf_ctx, cds_get_conparam());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800645 if (!gp_cds_context->htc_ctx) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700646 cds_alert("Failed to Create HTC");
Dustin Brownf7971192017-10-25 14:54:37 -0700647
648 status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800649 goto err_bmi_close;
650 }
Wu Gaod7dd6e42018-10-16 17:22:56 +0800651 ucfg_pmo_psoc_update_htc_handle(psoc, (void *)gp_cds_context->htc_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800652
Dustin Brownf7971192017-10-25 14:54:37 -0700653 status = bmi_done(ol_ctx);
654 if (QDF_IS_STATUS_ERROR(status)) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700655 cds_alert("Failed to complete BMI phase");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800656 goto err_htc_close;
657 }
658
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800659 /*Open the WMA module */
bings482bae22018-01-17 16:25:31 +0800660 status = wma_open(psoc, hdd_update_tgt_cfg, cds_cfg,
661 hdd_ctx->target_type);
Dustin Brownf7971192017-10-25 14:54:37 -0700662 if (QDF_IS_STATUS_ERROR(status)) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700663 cds_alert("Failed to open WMA module");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800664 goto err_htc_close;
665 }
666
667 /* Number of peers limit differs in each chip version. If peer max
668 * limit configured in ini exceeds more than supported, WMA adjusts
Arun Khandavallic811dcc2016-06-26 07:37:21 +0530669 * and keeps correct limit in cds_cfg.max_station. So, make sure
Jeff Johnsonc18b26c2017-09-03 08:46:45 -0700670 * config entry hdd_ctx->config->maxNumberOfPeers has adjusted value
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800671 */
Hanumanth Reddy Pothula47d29262016-10-03 16:08:04 +0530672 /* In FTM mode cds_cfg->max_stations will be zero. On updating same
673 * into hdd context config entry, leads to pe_open() to fail, if
674 * con_mode change happens from FTM mode to any other mode.
675 */
Srinivas Girigowda35b00312017-06-27 21:52:03 -0700676 if (QDF_DRIVER_TYPE_PRODUCTION == cds_cfg->driver_type)
Bala Venkatesh2fde2c62018-09-11 20:33:24 +0530677 ucfg_mlme_set_sap_max_peers(psoc, cds_cfg->max_station);
Hanumanth Reddy Pothula47d29262016-10-03 16:08:04 +0530678
Anurag Chouhan6d760662016-02-20 16:05:43 +0530679 HTCHandle = cds_get_context(QDF_MODULE_ID_HTC);
hangtiane52fa912018-11-26 15:44:38 +0800680 gp_cds_context->cfg_ctx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800681 if (!HTCHandle) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700682 cds_alert("HTCHandle is null!");
Dustin Brownf7971192017-10-25 14:54:37 -0700683
684 status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800685 goto err_wma_close;
686 }
Nachiket Kukadef44b33e2017-09-06 16:49:29 +0530687
Dustin Brownf7971192017-10-25 14:54:37 -0700688 status = htc_wait_target(HTCHandle);
689 if (QDF_IS_STATUS_ERROR(status)) {
690 cds_alert("Failed to complete BMI phase. status: %d", status);
Dustin Brown5f8955a2018-08-27 10:20:24 -0700691 QDF_BUG(status == QDF_STATUS_E_NOMEM || cds_is_fw_down());
Nachiket Kukade8003d252017-03-30 15:55:58 +0530692
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800693 goto err_wma_close;
694 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800695
Manjunathappa Prakash458f6fe2019-05-13 18:33:01 -0700696 cds_debug("target_type %d 8074:%d 6290:%d 6390: %d 6490: %d",
Venkata Sharath Chandra Manchala9ac16202018-07-06 01:17:40 -0700697 hdd_ctx->target_type,
698 TARGET_TYPE_QCA8074,
699 TARGET_TYPE_QCA6290,
Manjunathappa Prakash458f6fe2019-05-13 18:33:01 -0700700 TARGET_TYPE_QCA6390,
701 TARGET_TYPE_QCA6490);
Ravi Joshifc2ed782016-11-22 17:36:50 -0800702
Venkata Sharath Chandra Manchala9ac16202018-07-06 01:17:40 -0700703 if (TARGET_TYPE_QCA6290 == hdd_ctx->target_type ||
Manjunathappa Prakash458f6fe2019-05-13 18:33:01 -0700704 TARGET_TYPE_QCA6390 == hdd_ctx->target_type ||
705 TARGET_TYPE_QCA6490 == hdd_ctx->target_type)
Leo Chang9b097032016-10-28 11:03:17 -0700706 gp_cds_context->dp_soc = cdp_soc_attach(LITHIUM_DP,
Jeff Johnsona40e21c2018-05-29 15:59:57 -0700707 gp_cds_context->hif_context, psoc,
Leo Chang9b097032016-10-28 11:03:17 -0700708 gp_cds_context->htc_ctx, gp_cds_context->qdf_ctx,
Arunk Khandavallia6305a32018-01-25 11:19:18 +0530709 &dp_ol_if_ops);
Leo Chang9b097032016-10-28 11:03:17 -0700710 else
711 gp_cds_context->dp_soc = cdp_soc_attach(MOB_DRV_LEGACY_DP,
Jeff Johnsona40e21c2018-05-29 15:59:57 -0700712 gp_cds_context->hif_context, psoc,
Leo Chang9b097032016-10-28 11:03:17 -0700713 gp_cds_context->htc_ctx, gp_cds_context->qdf_ctx,
Arunk Khandavallia6305a32018-01-25 11:19:18 +0530714 &dp_ol_if_ops);
Leo Chang9b097032016-10-28 11:03:17 -0700715
Dustin Brownf7971192017-10-25 14:54:37 -0700716 if (!gp_cds_context->dp_soc) {
717 status = QDF_STATUS_E_FAILURE;
Manikandan Mohanfb9d2b52017-05-10 15:01:28 -0700718 goto err_wma_close;
Dustin Brownf7971192017-10-25 14:54:37 -0700719 }
Manikandan Mohanfb9d2b52017-05-10 15:01:28 -0700720
Lin Bai362e52b2018-05-07 14:42:50 +0800721 wlan_psoc_set_dp_handle(psoc, gp_cds_context->dp_soc);
Wu Gaod7dd6e42018-10-16 17:22:56 +0800722 ucfg_pmo_psoc_update_dp_handle(psoc, gp_cds_context->dp_soc);
Zhang Qian47e22ce2018-01-04 15:38:38 +0800723 ucfg_ocb_update_dp_handle(psoc, gp_cds_context->dp_soc);
Sravan Kumar Kairam27296782017-04-21 22:04:18 +0530724
gbian62edd7e2017-03-07 13:12:13 +0800725 cds_set_ac_specs_params(cds_cfg);
jitiphil377bcc12018-10-05 19:46:08 +0530726 cds_cfg_update_ac_specs_params((struct txrx_pdev_cfg_param_t *)
727 gp_cds_context->cfg_ctx, cds_cfg);
728 cds_cdp_cfg_attach(psoc);
Leo Chang9b097032016-10-28 11:03:17 -0700729
Nirav Shaheb017be2018-02-15 11:20:58 +0530730 bmi_target_ready(scn, gp_cds_context->cfg_ctx);
731
Jeff Johnsond9f08602016-12-02 11:31:30 -0800732 /* Now proceed to open the MAC */
Jeff Johnsonec563952018-06-11 09:57:09 -0700733 status = mac_open(psoc, &mac_handle,
Jeff Johnsonac99e472018-06-07 23:00:08 -0700734 gp_cds_context->hdd_context, cds_cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800735
Jeff Johnsonac99e472018-06-07 23:00:08 -0700736 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700737 cds_alert("Failed to open MAC");
Houston Hoffman59c9c912017-03-29 14:10:39 -0700738 goto err_soc_detach;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800739 }
Jeff Johnsonec563952018-06-11 09:57:09 -0700740 gp_cds_context->mac_context = mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800741
742 /* Now proceed to open the SME */
Jeff Johnsonec563952018-06-11 09:57:09 -0700743 status = sme_open(mac_handle);
Dustin Brownf7971192017-10-25 14:54:37 -0700744 if (QDF_IS_STATUS_ERROR(status)) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700745 cds_alert("Failed to open SME");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800746 goto err_mac_close;
747 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800748
Krunal Sonid32c6bc2016-10-18 18:00:21 -0700749 cds_register_all_modules();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800750
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +0530751 status = dispatcher_psoc_open(psoc);
Dustin Brown5f8955a2018-08-27 10:20:24 -0700752 if (QDF_IS_STATUS_ERROR(status)) {
753 cds_alert("Failed to open PSOC Components");
754 goto deregister_modules;
755 }
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +0530756
Rajeev Kumar00750362019-04-03 18:59:38 -0700757 ucfg_mc_cp_stats_register_pmo_handler();
758
Dustin Brown5f8955a2018-08-27 10:20:24 -0700759 return QDF_STATUS_SUCCESS;
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +0530760
Dustin Brown5f8955a2018-08-27 10:20:24 -0700761deregister_modules:
762 cds_deregister_all_modules();
763 sme_close(mac_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800764
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800765err_mac_close:
Jeff Johnsonec563952018-06-11 09:57:09 -0700766 mac_close(mac_handle);
Dustin Brownda0262a2018-08-24 16:29:37 -0700767 gp_cds_context->mac_context = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800768
Houston Hoffman59c9c912017-03-29 14:10:39 -0700769err_soc_detach:
Dustin Brownda0262a2018-08-24 16:29:37 -0700770 cdp_soc_detach(gp_cds_context->dp_soc);
Dustin Brown5f8955a2018-08-27 10:20:24 -0700771 gp_cds_context->dp_soc = NULL;
Dustin Brownda0262a2018-08-24 16:29:37 -0700772
773 ucfg_ocb_update_dp_handle(psoc, NULL);
Wu Gaod7dd6e42018-10-16 17:22:56 +0800774 ucfg_pmo_psoc_update_dp_handle(psoc, NULL);
Dustin Brownda0262a2018-08-24 16:29:37 -0700775 wlan_psoc_set_dp_handle(psoc, NULL);
776
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800777err_wma_close:
Rajeev Kumar662d75d2017-03-13 18:11:29 -0700778 cds_shutdown_notifier_purge();
Jeff Johnson542da352017-09-13 09:17:28 -0700779 wma_close();
Jeff Johnson7b3ddc22017-09-13 09:42:44 -0700780 wma_wmi_service_close();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800781
782err_htc_close:
783 if (gp_cds_context->htc_ctx) {
784 htc_destroy(gp_cds_context->htc_ctx);
785 gp_cds_context->htc_ctx = NULL;
Wu Gaod7dd6e42018-10-16 17:22:56 +0800786 ucfg_pmo_psoc_update_htc_handle(psoc, NULL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800787 }
788
789err_bmi_close:
Komal Seelam5a6e5082016-02-24 17:59:09 +0530790 bmi_cleanup(ol_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800791
792err_sched_close:
Dustin Brown5f8955a2018-08-27 10:20:24 -0700793 if (QDF_IS_STATUS_ERROR(cds_sched_close()))
794 QDF_DEBUG_PANIC("Failed to close CDS Scheduler");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800795
Dustin Brown44cde352017-12-04 13:14:46 -0800796err_dispatcher_disable:
797 if (QDF_IS_STATUS_ERROR(dispatcher_disable()))
Dustin Brown5f8955a2018-08-27 10:20:24 -0700798 QDF_DEBUG_PANIC("Failed to disable dispatcher");
Dustin Brown44cde352017-12-04 13:14:46 -0800799
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800800err_wma_complete_event:
Jeff Johnson2ccd8152018-05-29 16:02:23 -0700801 qdf_event_destroy(&gp_cds_context->wma_complete_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800802
Dustin Brownf7971192017-10-25 14:54:37 -0700803 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800804} /* cds_open() */
805
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -0700806QDF_STATUS cds_dp_open(struct wlan_objmgr_psoc *psoc)
807{
Mohit Khanna70322002018-05-15 19:21:32 -0700808 QDF_STATUS qdf_status;
809 struct dp_txrx_config dp_config;
810
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -0700811 cds_set_context(QDF_MODULE_ID_TXRX,
812 cdp_pdev_attach(cds_get_context(QDF_MODULE_ID_SOC),
Sravan Kumar Kairam1cbfb002018-06-14 18:28:48 +0530813 (struct cdp_ctrl_objmgr_pdev *)gp_cds_context->cfg_ctx,
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -0700814 gp_cds_context->htc_ctx,
815 gp_cds_context->qdf_ctx, 0));
816 if (!gp_cds_context->pdev_txrx_ctx) {
817 /* Critical Error ... Cannot proceed further */
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700818 cds_alert("Failed to open TXRX");
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -0700819 QDF_ASSERT(0);
Rakesh Pillai76778392019-07-11 20:04:27 +0530820 goto close;
821 }
822
823 if (cdp_txrx_intr_attach(gp_cds_context->dp_soc)
824 != QDF_STATUS_SUCCESS) {
825 cds_alert("Failed to attach interrupts");
826 goto pdev_detach;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -0700827 }
828
Mohit Khanna70322002018-05-15 19:21:32 -0700829 dp_config.enable_rx_threads =
Jinwei Chenc4602362019-07-22 15:34:05 +0800830 (cds_get_conparam() == QDF_GLOBAL_MONITOR_MODE) ?
831 false : gp_cds_context->cds_cfg->enable_dp_rx_threads;
832
Mohit Khanna70322002018-05-15 19:21:32 -0700833 qdf_status = dp_txrx_init(cds_get_context(QDF_MODULE_ID_SOC),
Rakesh Pillai6a36b0a2019-09-06 16:30:05 +0530834 OL_TXRX_PDEV_ID,
Mohit Khanna70322002018-05-15 19:21:32 -0700835 &dp_config);
836
837 if (!QDF_IS_STATUS_SUCCESS(qdf_status))
Rakesh Pillai76778392019-07-11 20:04:27 +0530838 goto intr_close;
Mohit Khanna70322002018-05-15 19:21:32 -0700839
Rakesh Pillai6a36b0a2019-09-06 16:30:05 +0530840 ucfg_pmo_psoc_set_txrx_pdev_id(psoc, OL_TXRX_PDEV_ID);
841 ucfg_ocb_set_txrx_pdev_id(psoc, OL_TXRX_PDEV_ID);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -0700842
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700843 cds_debug("CDS successfully Opened");
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -0700844
845 return 0;
846
Rakesh Pillai76778392019-07-11 20:04:27 +0530847intr_close:
848 cdp_txrx_intr_detach(gp_cds_context->dp_soc);
849
Mohit Khanna70322002018-05-15 19:21:32 -0700850pdev_detach:
851 cdp_pdev_detach(gp_cds_context->dp_soc,
852 cds_get_context(QDF_MODULE_ID_TXRX), false);
Rakesh Pillai76778392019-07-11 20:04:27 +0530853
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -0700854close:
855 return QDF_STATUS_E_FAILURE;
856}
857
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800858/**
859 * cds_pre_enable() - pre enable cds
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800860 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530861 * Return: QDF status
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800862 */
Jeff Johnson3a280122017-09-13 07:42:00 -0700863QDF_STATUS cds_pre_enable(void)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800864{
Dustin Brown9746bd62018-05-25 15:15:27 -0700865 QDF_STATUS status;
866 int errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800867 void *scn;
Jeff Johnson3a280122017-09-13 07:42:00 -0700868 void *soc;
Tiger Yu9973e362018-06-06 13:54:22 +0800869 void *hif_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800870
Dustin Brown9746bd62018-05-25 15:15:27 -0700871 cds_enter();
Jeff Johnson3a280122017-09-13 07:42:00 -0700872
873 if (!gp_cds_context) {
Dustin Brown9746bd62018-05-25 15:15:27 -0700874 cds_err("cds context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530875 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800876 }
877
Jeff Johnson830f3222018-05-29 15:58:18 -0700878 if (!gp_cds_context->wma_context) {
Dustin Brown9746bd62018-05-25 15:15:27 -0700879 cds_err("wma context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530880 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800881 }
882
Anurag Chouhan6d760662016-02-20 16:05:43 +0530883 scn = cds_get_context(QDF_MODULE_ID_HIF);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800884 if (!scn) {
Dustin Brown9746bd62018-05-25 15:15:27 -0700885 cds_err("hif context is null");
886 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800887 }
888
Jeff Johnson3a280122017-09-13 07:42:00 -0700889 soc = cds_get_context(QDF_MODULE_ID_SOC);
890 if (!soc) {
Dustin Brown9746bd62018-05-25 15:15:27 -0700891 cds_err("soc context is null");
892 return QDF_STATUS_E_INVAL;
Jeff Johnson3a280122017-09-13 07:42:00 -0700893 }
894
Nirav Shah7f337db2016-05-25 10:49:02 +0530895 /* call Packetlog connect service */
Arun Khandavallifae92942016-08-01 13:31:08 +0530896 if (QDF_GLOBAL_FTM_MODE != cds_get_conparam() &&
Leo Chang9b097032016-10-28 11:03:17 -0700897 QDF_GLOBAL_EPPING_MODE != cds_get_conparam())
Rakesh Pillai6a36b0a2019-09-06 16:30:05 +0530898 cdp_pkt_log_con_service(soc, OL_TXRX_PDEV_ID,
Dustin Brown9746bd62018-05-25 15:15:27 -0700899 scn);
Nirav Shah7f337db2016-05-25 10:49:02 +0530900
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800901 /*call WMA pre start */
Dustin Brown9746bd62018-05-25 15:15:27 -0700902 status = wma_pre_start();
903 if (QDF_IS_STATUS_ERROR(status)) {
904 cds_err("Failed to WMA prestart");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530905 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800906 }
907
Dustin Brown9746bd62018-05-25 15:15:27 -0700908 status = htc_start(gp_cds_context->htc_ctx);
909 if (QDF_IS_STATUS_ERROR(status)) {
910 cds_err("Failed to Start HTC");
911 goto exit_with_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800912 }
913
Jeff Johnson830f3222018-05-29 15:58:18 -0700914 status = wma_wait_for_ready_event(gp_cds_context->wma_context);
Dustin Brown9746bd62018-05-25 15:15:27 -0700915 if (QDF_IS_STATUS_ERROR(status)) {
916 cds_err("Failed to wait for ready event; status: %u", status);
Dustin Brown9746bd62018-05-25 15:15:27 -0700917 goto stop_wmi;
918 }
919
920 errno = cdp_pdev_post_attach(soc, gp_cds_context->pdev_txrx_ctx);
921 if (errno) {
922 cds_err("Failed to attach pdev");
923 status = qdf_status_from_os_return(errno);
924 goto stop_wmi;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800925 }
926
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530927 return QDF_STATUS_SUCCESS;
Dustin Brown9746bd62018-05-25 15:15:27 -0700928
929stop_wmi:
Tiger Yu9973e362018-06-06 13:54:22 +0800930 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
931 if (!hif_ctx)
932 cds_err("%s: Failed to get hif_handle!", __func__);
933
Dustin Brown9746bd62018-05-25 15:15:27 -0700934 wma_wmi_stop();
Tiger Yu9973e362018-06-06 13:54:22 +0800935
936 if (hif_ctx) {
937 cds_err("%s: Disable the isr & reset the soc!", __func__);
938 hif_disable_isr(hif_ctx);
939 hif_reset_soc(hif_ctx);
940 }
Dustin Brown9746bd62018-05-25 15:15:27 -0700941 htc_stop(gp_cds_context->htc_ctx);
942
Arun Kumar Khandavalli52cca562019-09-19 16:38:18 +0530943 wma_wmi_work_close();
Dustin Brown9746bd62018-05-25 15:15:27 -0700944exit_with_status:
945 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800946}
947
Jeff Johnson8f9dd5f2017-09-13 14:16:08 -0700948QDF_STATUS cds_enable(struct wlan_objmgr_psoc *psoc)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800949{
Dustin Brown6a8d39b2018-08-14 15:27:26 -0700950 QDF_STATUS qdf_status;
Jeff Johnson4ea79742018-07-21 21:57:24 -0700951 struct mac_start_params mac_params;
Dustin Brown6a8d39b2018-08-14 15:27:26 -0700952 int errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800953
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800954 /* We support only one instance for now ... */
Jeff Johnson8f9dd5f2017-09-13 14:16:08 -0700955 if (!gp_cds_context) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -0700956 cds_err("Invalid CDS context");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530957 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800958 }
959
Dustin Brown6a8d39b2018-08-14 15:27:26 -0700960 if (!gp_cds_context->wma_context) {
961 cds_err("WMA NULL context");
962 return QDF_STATUS_E_FAILURE;
963 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800964
Dustin Brown6a8d39b2018-08-14 15:27:26 -0700965 if (!gp_cds_context->mac_context) {
966 cds_err("MAC NULL context");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530967 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800968 }
969
970 /* Start the wma */
Jeff Johnsond4892552017-09-13 08:41:31 -0700971 qdf_status = wma_start();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530972 if (qdf_status != QDF_STATUS_SUCCESS) {
Dustin Brown6a8d39b2018-08-14 15:27:26 -0700973 cds_err("Failed to start wma; status:%d", qdf_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530974 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800975 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800976
977 /* Start the MAC */
Jeff Johnson4ea79742018-07-21 21:57:24 -0700978 qdf_mem_zero(&mac_params, sizeof(mac_params));
979 mac_params.driver_type = QDF_DRIVER_TYPE_PRODUCTION;
980 qdf_status = mac_start(gp_cds_context->mac_context, &mac_params);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800981
Jeff Johnsonac99e472018-06-07 23:00:08 -0700982 if (QDF_STATUS_SUCCESS != qdf_status) {
Dustin Brown6a8d39b2018-08-14 15:27:26 -0700983 cds_err("Failed to start MAC; status:%d", qdf_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800984 goto err_wma_stop;
985 }
986
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800987 /* START SME */
Jeff Johnson528c2cf2018-05-29 15:55:58 -0700988 qdf_status = sme_start(gp_cds_context->mac_context);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530989 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Dustin Brown6a8d39b2018-08-14 15:27:26 -0700990 cds_err("Failed to start SME; status:%d", qdf_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800991 goto err_mac_stop;
992 }
993
Venkata Sharath Chandra Manchala598f5032018-09-05 18:55:43 -0700994 qdf_status = cdp_soc_attach_target(cds_get_context(QDF_MODULE_ID_SOC));
995 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
996 cds_err("Failed to attach soc target; status:%d", qdf_status);
Leo Chang9b097032016-10-28 11:03:17 -0700997 goto err_sme_stop;
998 }
999
Dustin Brown6a8d39b2018-08-14 15:27:26 -07001000 errno = cdp_pdev_attach_target(cds_get_context(QDF_MODULE_ID_SOC),
1001 cds_get_context(QDF_MODULE_ID_TXRX));
1002 if (errno) {
1003 cds_err("Failed to attach pdev target; errno:%d", errno);
Leo Chang9b097032016-10-28 11:03:17 -07001004 goto err_soc_target_detach;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001005 }
1006
Min Liu81f2ed32018-01-08 14:21:02 +08001007 qdf_status = dispatcher_psoc_enable(psoc);
1008 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Dustin Brown6a8d39b2018-08-14 15:27:26 -07001009 cds_err("dispatcher_psoc_enable failed; status:%d", qdf_status);
Min Liu81f2ed32018-01-08 14:21:02 +08001010 goto err_soc_target_detach;
1011 }
Rajeev Kumar97767a02016-11-30 11:20:40 -08001012
Nachiket Kukade98f562a2017-12-15 12:18:07 +05301013 /* Trigger psoc enable for CLD components */
1014 hdd_component_psoc_enable(psoc);
1015
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301016 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001017
Leo Chang9b097032016-10-28 11:03:17 -07001018err_soc_target_detach:
1019 /* NOOP */
1020
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001021err_sme_stop:
Jeff Johnson62cd6802018-07-20 12:38:25 -07001022 sme_stop(gp_cds_context->mac_context);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001023
1024err_mac_stop:
Jeff Johnson62cd6802018-07-20 12:38:25 -07001025 mac_stop(gp_cds_context->mac_context);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001026
1027err_wma_stop:
Jeff Johnson2ccd8152018-05-29 16:02:23 -07001028 qdf_event_reset(&gp_cds_context->wma_complete_event);
Jeff Johnson62cd6802018-07-20 12:38:25 -07001029 qdf_status = wma_stop();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301030 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001031 cds_err("Failed to stop wma");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301032 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Jeff Johnson1f8d0a02017-09-13 08:09:05 -07001033 wma_setneedshutdown();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001034 } else {
Anurag Chouhance0dc992016-02-16 18:18:03 +05301035 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +05301036 qdf_wait_for_event_completion(
Jeff Johnson2ccd8152018-05-29 16:02:23 -07001037 &gp_cds_context->wma_complete_event,
Nachiket Kukade0396b732017-11-14 16:35:16 +05301038 CDS_WMA_TIMEOUT);
Anurag Chouhance0dc992016-02-16 18:18:03 +05301039 if (qdf_status != QDF_STATUS_SUCCESS) {
1040 if (qdf_status == QDF_STATUS_E_TIMEOUT) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001041 cds_alert("Timeout occurred before WMA_stop complete");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001042 } else {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001043 cds_alert("WMA_stop reporting other error");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001044 }
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301045 QDF_ASSERT(0);
Jeff Johnson1f8d0a02017-09-13 08:09:05 -07001046 wma_setneedshutdown();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001047 }
1048 }
1049
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301050 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001051} /* cds_enable() */
1052
1053/**
1054 * cds_disable() - stop/disable cds module
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301055 * @psoc: Psoc pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001056 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05301057 * Return: QDF status
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001058 */
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -07001059QDF_STATUS cds_disable(struct wlan_objmgr_psoc *psoc)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001060{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301061 QDF_STATUS qdf_status;
Arun Khandavallifae92942016-08-01 13:31:08 +05301062 void *handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001063
Rajeev Kumar97767a02016-11-30 11:20:40 -08001064 /* PSOC disable for all new components. It needs to happen before
1065 * target is PDEV suspended such that a component can abort all its
1066 * ongoing transaction with FW. Always keep it before wma_stop() as
1067 * wma_stop() does target PDEV suspend.
1068 */
Rajeev Kumar97767a02016-11-30 11:20:40 -08001069
Nachiket Kukade98f562a2017-12-15 12:18:07 +05301070 /* Trigger psoc disable for CLD components */
1071 if (psoc) {
1072 hdd_component_psoc_disable(psoc);
Jiachao Wu341d0752018-01-02 15:20:32 +08001073 dispatcher_psoc_disable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +05301074 }
Rajeev Kumar97767a02016-11-30 11:20:40 -08001075
Jeff Johnson62cd6802018-07-20 12:38:25 -07001076 qdf_status = wma_stop();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001077
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301078 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Arun Khandavallifae92942016-08-01 13:31:08 +05301079 cds_err("Failed to stop wma");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301080 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Jeff Johnson1f8d0a02017-09-13 08:09:05 -07001081 wma_setneedshutdown();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001082 }
1083
Arun Khandavallifae92942016-08-01 13:31:08 +05301084 handle = cds_get_context(QDF_MODULE_ID_PE);
1085 if (!handle) {
1086 cds_err("Invalid PE context return!");
1087 return QDF_STATUS_E_INVAL;
1088 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001089
Naveen Rawatbcd3d012017-12-05 11:11:55 -08001090 umac_stop();
Arun Khandavalli55f890b2016-08-31 18:14:56 +05301091
Arun Khandavallifae92942016-08-01 13:31:08 +05301092 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001093}
1094
Govind Singhb048e872016-09-27 22:07:43 +05301095#ifdef HIF_USB
1096static inline void cds_suspend_target(tp_wma_handle wma_handle)
1097{
1098 QDF_STATUS status;
1099 /* Suspend the target and disable interrupt */
Wu Gaod7dd6e42018-10-16 17:22:56 +08001100 status = ucfg_pmo_psoc_suspend_target(wma_handle->psoc, 0);
Govind Singhb048e872016-09-27 22:07:43 +05301101 if (status)
1102 cds_err("Failed to suspend target, status = %d", status);
1103}
1104#else
1105static inline void cds_suspend_target(tp_wma_handle wma_handle)
1106{
1107 QDF_STATUS status;
1108 /* Suspend the target and disable interrupt */
Wu Gaod7dd6e42018-10-16 17:22:56 +08001109 status = ucfg_pmo_psoc_suspend_target(wma_handle->psoc, 1);
Govind Singhb048e872016-09-27 22:07:43 +05301110 if (status)
1111 cds_err("Failed to suspend target, status = %d", status);
1112}
1113#endif /* HIF_USB */
1114
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001115/**
Govind Singhb048e872016-09-27 22:07:43 +05301116 * cds_post_disable() - post disable cds module
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001117 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05301118 * Return: QDF status
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001119 */
Rajeev Kumarbe021242017-02-16 16:12:23 -08001120QDF_STATUS cds_post_disable(void)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001121{
Arun Khandavalli55f890b2016-08-31 18:14:56 +05301122 tp_wma_handle wma_handle;
Govind Singhb048e872016-09-27 22:07:43 +05301123 struct hif_opaque_softc *hif_ctx;
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05301124 struct cdp_pdev *txrx_pdev;
Rakshith Suresh Patkarba55fd02018-11-20 13:03:43 +05301125 struct scheduler_ctx *sched_ctx;
Alok Kumarac741772018-10-11 12:40:42 +05301126 QDF_STATUS qdf_status;
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05301127
Arun Khandavalli55f890b2016-08-31 18:14:56 +05301128 wma_handle = cds_get_context(QDF_MODULE_ID_WMA);
1129 if (!wma_handle) {
1130 cds_err("Failed to get wma_handle!");
1131 return QDF_STATUS_E_INVAL;
1132 }
1133
Govind Singhb048e872016-09-27 22:07:43 +05301134 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
1135 if (!hif_ctx) {
1136 cds_err("Failed to get hif_handle!");
1137 return QDF_STATUS_E_INVAL;
1138 }
1139
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05301140 txrx_pdev = cds_get_context(QDF_MODULE_ID_TXRX);
1141 if (!txrx_pdev) {
1142 cds_err("Failed to get txrx pdev!");
1143 return QDF_STATUS_E_INVAL;
1144 }
1145
Rakshith Suresh Patkarba55fd02018-11-20 13:03:43 +05301146 /* flush any unprocessed scheduler messages */
1147 sched_ctx = scheduler_get_context();
1148 if (sched_ctx)
1149 scheduler_queues_flush(sched_ctx);
1150
Arun Khandavalli55f890b2016-08-31 18:14:56 +05301151 /*
1152 * With new state machine changes cds_close can be invoked without
1153 * cds_disable. So, send the following clean up prerequisites to fw,
1154 * So Fw and host are in sync for cleanup indication:
1155 * - Send PDEV_SUSPEND indication to firmware
1156 * - Disable HIF Interrupts.
1157 * - Clean up CE tasklets.
1158 */
1159
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301160 cds_info("send deinit sequence to firmware");
1161 if (!(cds_is_driver_recovering() || cds_is_driver_in_bad_state()))
Govind Singhb048e872016-09-27 22:07:43 +05301162 cds_suspend_target(wma_handle);
1163 hif_disable_isr(hif_ctx);
1164 hif_reset_soc(hif_ctx);
1165
Wu Gao9a24fa72017-07-28 18:32:22 +08001166 if (gp_cds_context->htc_ctx) {
Kabilan Kannanfc3a8c02018-02-21 13:36:29 -08001167 wma_wmi_stop();
Wu Gao9a24fa72017-07-28 18:32:22 +08001168 htc_stop(gp_cds_context->htc_ctx);
1169 }
1170
Alok Kumarac741772018-10-11 12:40:42 +05301171 qdf_status = cds_close_rx_thread();
1172 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
1173 cds_err("Failed to close RX thread!");
1174 return QDF_STATUS_E_INVAL;
1175 }
1176
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05301177 cdp_pdev_pre_detach(cds_get_context(QDF_MODULE_ID_SOC),
1178 (struct cdp_pdev *)txrx_pdev, 1);
1179
Govind Singhb048e872016-09-27 22:07:43 +05301180 return QDF_STATUS_SUCCESS;
1181}
1182
1183/**
1184 * cds_close() - close cds module
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301185 * @psoc: Psoc pointer
Govind Singhb048e872016-09-27 22:07:43 +05301186 *
1187 * This API allows user to close modules registered
1188 * with connectivity device services.
1189 *
1190 * Return: QDF status
1191 */
Jeff Johnsone4b14592017-09-13 14:23:33 -07001192QDF_STATUS cds_close(struct wlan_objmgr_psoc *psoc)
Govind Singhb048e872016-09-27 22:07:43 +05301193{
1194 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001195
Dustin Brownd33276b2017-11-29 11:08:11 -08001196 qdf_status = cds_sched_close();
1197 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
1198 if (QDF_IS_STATUS_ERROR(qdf_status))
1199 cds_err("Failed to close CDS Scheduler");
1200
Dustin Brown44cde352017-12-04 13:14:46 -08001201 qdf_status = dispatcher_disable();
1202 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
1203 if (QDF_IS_STATUS_ERROR(qdf_status))
1204 cds_err("Failed to disable dispatcher; status:%d", qdf_status);
1205
Amar Singhal966397f2017-04-06 18:28:56 -07001206 dispatcher_psoc_close(psoc);
1207
Jeff Johnson6b8473d2017-09-13 09:20:53 -07001208 qdf_status = wma_wmi_work_close();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301209 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001210 cds_err("Failed to close wma_wmi_work");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301211 QDF_ASSERT(0);
Xun Luoa858a472015-11-10 08:24:45 -08001212 }
1213
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001214 if (gp_cds_context->htc_ctx) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001215 htc_destroy(gp_cds_context->htc_ctx);
Wu Gaod7dd6e42018-10-16 17:22:56 +08001216 ucfg_pmo_psoc_update_htc_handle(psoc, NULL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001217 gp_cds_context->htc_ctx = NULL;
1218 }
1219
Jeff Johnson528c2cf2018-05-29 15:55:58 -07001220 qdf_status = sme_close(gp_cds_context->mac_context);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301221 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001222 cds_err("Failed to close SME");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301223 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001224 }
1225
Jeff Johnson528c2cf2018-05-29 15:55:58 -07001226 qdf_status = mac_close(gp_cds_context->mac_context);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301227 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001228 cds_err("Failed to close MAC");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301229 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001230 }
1231
Jeff Johnson528c2cf2018-05-29 15:55:58 -07001232 gp_cds_context->mac_context = NULL;
Abhishek Amburec0069162019-10-01 14:10:23 +05301233 /*
1234 * Call this before cdp soc detatch as it used the cdp soc to free the
1235 * cdp vdev if any.
1236 */
1237 wma_release_pending_vdev_refs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001238
Houston Hoffmanbe58cc52016-12-19 16:26:44 -08001239 cdp_soc_detach(gp_cds_context->dp_soc);
Jinwei Chen000e7f22019-03-13 17:48:17 +08001240 gp_cds_context->dp_soc = NULL;
1241
Wu Gaod7dd6e42018-10-16 17:22:56 +08001242 ucfg_pmo_psoc_update_dp_handle(psoc, NULL);
Lin Bai362e52b2018-05-07 14:42:50 +08001243 wlan_psoc_set_dp_handle(psoc, NULL);
Houston Hoffmanbe58cc52016-12-19 16:26:44 -08001244
Rajeev Kumar662d75d2017-03-13 18:11:29 -07001245 cds_shutdown_notifier_purge();
1246
Jeff Johnson1b5404e2017-09-13 08:04:46 -07001247 if (true == wma_needshutdown()) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001248 cds_err("Failed to shutdown wma");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001249 } else {
Jeff Johnson542da352017-09-13 09:17:28 -07001250 qdf_status = wma_close();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301251 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001252 cds_err("Failed to close wma");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301253 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001254 }
1255 }
1256
Jeff Johnson7b3ddc22017-09-13 09:42:44 -07001257 qdf_status = wma_wmi_service_close();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301258 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001259 cds_err("Failed to close wma_wmi_service");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301260 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001261 }
1262
Jeff Johnson2ccd8152018-05-29 16:02:23 -07001263 qdf_status = qdf_event_destroy(&gp_cds_context->wma_complete_event);
Anurag Chouhance0dc992016-02-16 18:18:03 +05301264 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001265 cds_err("failed to destroy wma_complete_event");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301266 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001267 }
1268
Arun Khandavallic811dcc2016-06-26 07:37:21 +05301269 cds_deinit_ini_config();
Arun Khandavallifae92942016-08-01 13:31:08 +05301270 qdf_timer_module_deinit();
1271
Krunal Sonid32c6bc2016-10-18 18:00:21 -07001272 cds_deregister_all_modules();
Rajeev Kumar97767a02016-11-30 11:20:40 -08001273
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301274 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001275}
1276
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07001277QDF_STATUS cds_dp_close(struct wlan_objmgr_psoc *psoc)
1278{
1279 void *ctx;
1280
1281 cdp_txrx_intr_detach(gp_cds_context->dp_soc);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07001282 ctx = cds_get_context(QDF_MODULE_ID_TXRX);
Mohit Khanna70322002018-05-15 19:21:32 -07001283
1284 dp_txrx_deinit(cds_get_context(QDF_MODULE_ID_SOC));
1285
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07001286 cdp_pdev_detach(cds_get_context(QDF_MODULE_ID_SOC),
1287 (struct cdp_pdev *)ctx, 1);
Mohit Khanna70322002018-05-15 19:21:32 -07001288
psimhadeea0a12017-12-18 14:50:02 -08001289 cds_set_context(QDF_MODULE_ID_TXRX, NULL);
Rakesh Pillai6a36b0a2019-09-06 16:30:05 +05301290 ucfg_pmo_psoc_set_txrx_pdev_id(psoc, OL_TXRX_INVALID_PDEV_ID);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07001291
1292 return QDF_STATUS_SUCCESS;
1293}
1294
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001295/**
1296 * cds_get_context() - get context data area
1297 *
Jeff Johnsonb3be6a62018-05-30 18:50:12 -07001298 * @module_id: ID of the module who's context data is being retrieved.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001299 *
1300 * Each module in the system has a context / data area that is allocated
1301 * and managed by CDS. This API allows any user to get a pointer to its
1302 * allocated context data area from the CDS global context.
1303 *
1304 * Return: pointer to the context data area of the module ID
1305 * specified, or NULL if the context data is not allocated for
1306 * the module ID specified
1307 */
Jeff Johnsonb3be6a62018-05-30 18:50:12 -07001308void *cds_get_context(QDF_MODULE_ID module_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001309{
Jeff Johnson835b7602018-05-30 19:06:24 -07001310 void *context = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001311
Jeff Johnsone7afbe92019-03-18 13:43:43 -07001312 if (!gp_cds_context) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001313 cds_err("cds context pointer is null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001314 return NULL;
1315 }
1316
Jeff Johnsonb3be6a62018-05-30 18:50:12 -07001317 switch (module_id) {
Anurag Chouhan6d760662016-02-20 16:05:43 +05301318 case QDF_MODULE_ID_HDD:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001319 {
Jeff Johnson835b7602018-05-30 19:06:24 -07001320 context = gp_cds_context->hdd_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001321 break;
1322 }
1323
Anurag Chouhan6d760662016-02-20 16:05:43 +05301324 case QDF_MODULE_ID_SME:
1325 case QDF_MODULE_ID_PE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001326 {
1327 /* In all these cases, we just return the MAC Context */
Jeff Johnson835b7602018-05-30 19:06:24 -07001328 context = gp_cds_context->mac_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001329 break;
1330 }
1331
Anurag Chouhan6d760662016-02-20 16:05:43 +05301332 case QDF_MODULE_ID_WMA:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001333 {
1334 /* For wma module */
Jeff Johnson835b7602018-05-30 19:06:24 -07001335 context = gp_cds_context->wma_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001336 break;
1337 }
1338
Anurag Chouhan6d760662016-02-20 16:05:43 +05301339 case QDF_MODULE_ID_QDF:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001340 {
1341 /* For SYS this is CDS itself */
Jeff Johnson835b7602018-05-30 19:06:24 -07001342 context = gp_cds_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001343 break;
1344 }
1345
Anurag Chouhan6d760662016-02-20 16:05:43 +05301346 case QDF_MODULE_ID_HIF:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001347 {
Jeff Johnson835b7602018-05-30 19:06:24 -07001348 context = gp_cds_context->hif_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001349 break;
1350 }
1351
Anurag Chouhan6d760662016-02-20 16:05:43 +05301352 case QDF_MODULE_ID_HTC:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001353 {
Jeff Johnson835b7602018-05-30 19:06:24 -07001354 context = gp_cds_context->htc_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001355 break;
1356 }
1357
Anurag Chouhan6d760662016-02-20 16:05:43 +05301358 case QDF_MODULE_ID_QDF_DEVICE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001359 {
Jeff Johnson835b7602018-05-30 19:06:24 -07001360 context = gp_cds_context->qdf_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001361 break;
1362 }
1363
Anurag Chouhan6d760662016-02-20 16:05:43 +05301364 case QDF_MODULE_ID_BMI:
Komal Seelamd9106492016-02-15 10:31:44 +05301365 {
Jeff Johnson835b7602018-05-30 19:06:24 -07001366 context = gp_cds_context->g_ol_context;
Komal Seelamd9106492016-02-15 10:31:44 +05301367 break;
1368 }
1369
Anurag Chouhan6d760662016-02-20 16:05:43 +05301370 case QDF_MODULE_ID_TXRX:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001371 {
Jeff Johnson835b7602018-05-30 19:06:24 -07001372 context = (void *)gp_cds_context->pdev_txrx_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001373 break;
1374 }
1375
Anurag Chouhan6d760662016-02-20 16:05:43 +05301376 case QDF_MODULE_ID_CFG:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001377 {
Jeff Johnson835b7602018-05-30 19:06:24 -07001378 context = gp_cds_context->cfg_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001379 break;
1380 }
1381
Leo Chang9b097032016-10-28 11:03:17 -07001382 case QDF_MODULE_ID_SOC:
1383 {
Jeff Johnson835b7602018-05-30 19:06:24 -07001384 context = gp_cds_context->dp_soc;
Leo Chang9b097032016-10-28 11:03:17 -07001385 break;
1386 }
1387
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001388 default:
1389 {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001390 cds_err("Module ID %i does not have its context maintained by CDS",
1391 module_id);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301392 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001393 return NULL;
1394 }
1395 }
1396
Jeff Johnson835b7602018-05-30 19:06:24 -07001397 if (!context)
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001398 cds_err("Module ID %i context is Null", module_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001399
Jeff Johnson835b7602018-05-30 19:06:24 -07001400 return context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001401} /* cds_get_context() */
1402
1403/**
1404 * cds_get_global_context() - get CDS global Context
1405 *
1406 * This API allows any user to get the CDS Global Context pointer from a
1407 * module context data area.
1408 *
1409 * Return: pointer to the CDS global context, NULL if the function is
Jeff Johnson6bb5d782018-05-11 14:52:18 -07001410 * unable to retrieve the CDS context.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001411 */
Jeff Johnson31a67582017-09-26 14:54:28 -07001412void *cds_get_global_context(void)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001413{
Jeff Johnsone7afbe92019-03-18 13:43:43 -07001414 if (!gp_cds_context) {
Ryan Hsuceddceb2016-04-28 10:20:14 -07001415 /*
1416 * To avoid recursive call, this should not change to
1417 * QDF_TRACE().
1418 */
1419 pr_err("%s: global cds context is NULL", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001420 }
1421
1422 return gp_cds_context;
1423} /* cds_get_global_context() */
1424
1425/**
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001426 * cds_get_driver_state() - Get current driver state
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001427 *
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001428 * This API returns current driver state stored in global context.
1429 *
1430 * Return: Driver state enum
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001431 */
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001432enum cds_driver_state cds_get_driver_state(void)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001433{
Jeff Johnsone7afbe92019-03-18 13:43:43 -07001434 if (!gp_cds_context) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001435 cds_err("global cds context is NULL");
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001436
1437 return CDS_DRIVER_STATE_UNINITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001438 }
1439
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001440 return gp_cds_context->driver_state;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001441}
1442
1443/**
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001444 * cds_set_driver_state() - Set current driver state
1445 * @state: Driver state to be set to.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001446 *
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001447 * This API sets driver state to state. This API only sets the state and doesn't
1448 * clear states, please make sure to use cds_clear_driver_state to clear any
1449 * state if required.
1450 *
1451 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001452 */
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001453void cds_set_driver_state(enum cds_driver_state state)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001454{
Jeff Johnsone7afbe92019-03-18 13:43:43 -07001455 if (!gp_cds_context) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001456 cds_err("global cds context is NULL: %x", state);
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001457
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001458 return;
1459 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001460
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001461 gp_cds_context->driver_state |= state;
1462}
1463
1464/**
1465 * cds_clear_driver_state() - Clear current driver state
1466 * @state: Driver state to be cleared.
1467 *
1468 * This API clears driver state. This API only clears the state, please make
1469 * sure to use cds_set_driver_state to set any new states.
1470 *
1471 * Return: None
1472 */
1473void cds_clear_driver_state(enum cds_driver_state state)
1474{
Jeff Johnsone7afbe92019-03-18 13:43:43 -07001475 if (!gp_cds_context) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001476 cds_err("global cds context is NULL: %x", state);
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001477
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001478 return;
1479 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001480
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001481 gp_cds_context->driver_state &= ~state;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001482}
1483
1484/**
1485 * cds_alloc_context() - allocate a context within the CDS global Context
Jeff Johnsonb3be6a62018-05-30 18:50:12 -07001486 * @module_id: module ID who's context area is being allocated.
Jeff Johnson13269962018-05-30 19:16:46 -07001487 * @module_context: pointer to location where the pointer to the
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001488 * allocated context is returned. Note this output pointer
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301489 * is valid only if the API returns QDF_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001490 * @param size: size of the context area to be allocated.
1491 *
1492 * This API allows any user to allocate a user context area within the
1493 * CDS Global Context.
1494 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05301495 * Return: QDF status
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001496 */
Jeff Johnsonb3be6a62018-05-30 18:50:12 -07001497QDF_STATUS cds_alloc_context(QDF_MODULE_ID module_id,
Jeff Johnson13269962018-05-30 19:16:46 -07001498 void **module_context, uint32_t size)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001499{
Jeff Johnson835b7602018-05-30 19:06:24 -07001500 void **cds_mod_context = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001501
Jeff Johnsonadb3b1c2017-09-13 10:42:36 -07001502 if (!gp_cds_context) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001503 cds_err("cds context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301504 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001505 }
1506
Jeff Johnson13269962018-05-30 19:16:46 -07001507 if (!module_context) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001508 cds_err("null param passed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301509 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001510 }
1511
Jeff Johnsonb3be6a62018-05-30 18:50:12 -07001512 switch (module_id) {
Anurag Chouhan6d760662016-02-20 16:05:43 +05301513 case QDF_MODULE_ID_WMA:
Jeff Johnson835b7602018-05-30 19:06:24 -07001514 cds_mod_context = &gp_cds_context->wma_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001515 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001516
Anurag Chouhan6d760662016-02-20 16:05:43 +05301517 case QDF_MODULE_ID_HIF:
Jeff Johnson835b7602018-05-30 19:06:24 -07001518 cds_mod_context = &gp_cds_context->hif_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001519 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001520
Anurag Chouhan6d760662016-02-20 16:05:43 +05301521 case QDF_MODULE_ID_BMI:
Jeff Johnson835b7602018-05-30 19:06:24 -07001522 cds_mod_context = &gp_cds_context->g_ol_context;
Komal Seelamd9106492016-02-15 10:31:44 +05301523 break;
Komal Seelamd9106492016-02-15 10:31:44 +05301524
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001525 default:
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001526 cds_err("Module ID %i does not have its context allocated by CDS",
1527 module_id);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301528 QDF_ASSERT(0);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301529 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001530 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001531
Jeff Johnson835b7602018-05-30 19:06:24 -07001532 if (*cds_mod_context) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001533 /* Context has already been allocated!
1534 * Prevent double allocation
1535 */
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001536 cds_err("Module ID %i context has already been allocated",
1537 module_id);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301538 return QDF_STATUS_E_EXISTS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001539 }
1540
1541 /* Dynamically allocate the context for module */
1542
Jeff Johnson13269962018-05-30 19:16:46 -07001543 *module_context = qdf_mem_malloc(size);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001544
Jeff Johnson13269962018-05-30 19:16:46 -07001545 if (!*module_context) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001546 cds_err("Failed to allocate Context for module ID %i",
1547 module_id);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301548 QDF_ASSERT(0);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301549 return QDF_STATUS_E_NOMEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001550 }
1551
Jeff Johnson13269962018-05-30 19:16:46 -07001552 *cds_mod_context = *module_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001553
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301554 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001555} /* cds_alloc_context() */
1556
1557/**
Komal Seelamad5a90d2016-02-16 13:50:03 +05301558 * cds_set_context() - API to set context in global CDS Context
Komal Seelam1aac1982016-03-02 15:57:26 +05301559 * @module_id: Module ID
Komal Seelamad5a90d2016-02-16 13:50:03 +05301560 * @context: Pointer to the Module Context
1561 *
Komal Seelam1aac1982016-03-02 15:57:26 +05301562 * API to set a MODULE Context in global CDS Context
Komal Seelamad5a90d2016-02-16 13:50:03 +05301563 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301564 * Return: QDF_STATUS
Komal Seelamad5a90d2016-02-16 13:50:03 +05301565 */
Anurag Chouhan6d760662016-02-20 16:05:43 +05301566QDF_STATUS cds_set_context(QDF_MODULE_ID module_id, void *context)
Komal Seelamad5a90d2016-02-16 13:50:03 +05301567{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07001568 struct cds_context *p_cds_context = cds_get_global_context();
Komal Seelamad5a90d2016-02-16 13:50:03 +05301569
1570 if (!p_cds_context) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001571 cds_err("cds context is Invalid");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301572 return QDF_STATUS_NOT_INITIALIZED;
Komal Seelamad5a90d2016-02-16 13:50:03 +05301573 }
1574
1575 switch (module_id) {
Jeff Johnson3543fb22017-09-24 13:44:13 -07001576 case QDF_MODULE_ID_HDD:
Jeff Johnson323a6f02018-05-29 15:09:12 -07001577 p_cds_context->hdd_context = context;
Jeff Johnson3543fb22017-09-24 13:44:13 -07001578 break;
Houston Hoffman57c36d72017-01-30 12:47:02 -08001579 case QDF_MODULE_ID_TXRX:
1580 p_cds_context->pdev_txrx_ctx = context;
1581 break;
Anurag Chouhan6d760662016-02-20 16:05:43 +05301582 case QDF_MODULE_ID_HIF:
Jeff Johnsona40e21c2018-05-29 15:59:57 -07001583 p_cds_context->hif_context = context;
Komal Seelamad5a90d2016-02-16 13:50:03 +05301584 break;
1585 default:
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001586 cds_err("Module ID %i does not have its context managed by CDS",
1587 module_id);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301588 QDF_ASSERT(0);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301589 return QDF_STATUS_E_INVAL;
Komal Seelamad5a90d2016-02-16 13:50:03 +05301590 }
1591
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301592 return QDF_STATUS_SUCCESS;
Komal Seelamad5a90d2016-02-16 13:50:03 +05301593}
1594
1595/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001596 * cds_free_context() - free an allocated context within the
1597 * CDS global Context
Jeff Johnsonb3be6a62018-05-30 18:50:12 -07001598 * @module_id: module ID who's context area is being free
Jeff Johnson13269962018-05-30 19:16:46 -07001599 * @module_context: pointer to module context area to be free'd.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001600 *
1601 * This API allows a user to free the user context area within the
1602 * CDS Global Context.
1603 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05301604 * Return: QDF status
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001605 */
Jeff Johnson13269962018-05-30 19:16:46 -07001606QDF_STATUS cds_free_context(QDF_MODULE_ID module_id, void *module_context)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001607{
Jeff Johnson835b7602018-05-30 19:06:24 -07001608 void **cds_mod_context = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001609
Jeff Johnsonadb3b1c2017-09-13 10:42:36 -07001610 if (!gp_cds_context) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001611 cds_err("cds context is null");
Jeff Johnsonadb3b1c2017-09-13 10:42:36 -07001612 return QDF_STATUS_E_FAILURE;
1613 }
1614
Jeff Johnson13269962018-05-30 19:16:46 -07001615 if (!module_context) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001616 cds_err("Null param");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301617 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001618 }
1619
Jeff Johnsonb3be6a62018-05-30 18:50:12 -07001620 switch (module_id) {
Anurag Chouhan6d760662016-02-20 16:05:43 +05301621 case QDF_MODULE_ID_WMA:
Jeff Johnson835b7602018-05-30 19:06:24 -07001622 cds_mod_context = &gp_cds_context->wma_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001623 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001624
Anurag Chouhan6d760662016-02-20 16:05:43 +05301625 case QDF_MODULE_ID_HIF:
Jeff Johnson835b7602018-05-30 19:06:24 -07001626 cds_mod_context = &gp_cds_context->hif_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001627 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001628
Anurag Chouhan6d760662016-02-20 16:05:43 +05301629 case QDF_MODULE_ID_TXRX:
Jeff Johnson835b7602018-05-30 19:06:24 -07001630 cds_mod_context = (void **)&gp_cds_context->pdev_txrx_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001631 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001632
Anurag Chouhan6d760662016-02-20 16:05:43 +05301633 case QDF_MODULE_ID_BMI:
Jeff Johnson835b7602018-05-30 19:06:24 -07001634 cds_mod_context = &gp_cds_context->g_ol_context;
Komal Seelamd9106492016-02-15 10:31:44 +05301635 break;
Komal Seelamd9106492016-02-15 10:31:44 +05301636
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001637 default:
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001638 cds_err("Module ID %i does not have its context allocated by CDS",
1639 module_id);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301640 QDF_ASSERT(0);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301641 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001642 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001643
Jeff Johnson835b7602018-05-30 19:06:24 -07001644 if (!*cds_mod_context) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001645 /* Context has not been allocated or freed already! */
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001646 cds_err("Module ID %i context has not been allocated or freed already",
1647 module_id);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301648 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001649 }
1650
Jeff Johnson13269962018-05-30 19:16:46 -07001651 if (*cds_mod_context != module_context) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001652 cds_err("cds_mod_context != module_context");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301653 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001654 }
1655
Jeff Johnson13269962018-05-30 19:16:46 -07001656 qdf_mem_free(module_context);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001657
Jeff Johnson835b7602018-05-30 19:06:24 -07001658 *cds_mod_context = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001659
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301660 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001661} /* cds_free_context() */
1662
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001663
1664/**
1665 * cds_flush_work() - flush pending works
1666 * @work: pointer to work
1667 *
1668 * Return: none
1669 */
1670void cds_flush_work(void *work)
1671{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001672 cancel_work_sync(work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001673}
1674
1675/**
1676 * cds_flush_delayed_work() - flush delayed works
1677 * @dwork: pointer to delayed work
1678 *
1679 * Return: none
1680 */
1681void cds_flush_delayed_work(void *dwork)
1682{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001683 cancel_delayed_work_sync(dwork);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001684}
1685
Nirav Shahbb8e47c2018-05-17 16:56:41 +05301686#ifndef REMOVE_PKT_LOG
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001687/**
1688 * cds_is_packet_log_enabled() - check if packet log is enabled
1689 *
1690 * Return: true if packet log is enabled else false
1691 */
1692bool cds_is_packet_log_enabled(void)
1693{
Jeff Johnsonc18b26c2017-09-03 08:46:45 -07001694 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001695
Jeff Johnson323a6f02018-05-29 15:09:12 -07001696 hdd_ctx = gp_cds_context->hdd_context;
Jeff Johnsone7afbe92019-03-18 13:43:43 -07001697 if ((!hdd_ctx) || (!hdd_ctx->config)) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001698 cds_alert("Hdd Context is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001699 return false;
1700 }
Dundi Raviteja8e338282018-09-25 17:16:04 +05301701 return hdd_ctx->config->enable_packet_log;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001702}
Nirav Shahbb8e47c2018-05-17 16:56:41 +05301703#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001704
Dustin Brown100201e2017-07-10 11:48:40 -07001705static int cds_force_assert_target_via_pld(qdf_device_t qdf)
Mukul Sharmab7b575b2016-10-02 23:37:07 +05301706{
Dustin Brown100201e2017-07-10 11:48:40 -07001707 int errno;
1708
1709 errno = pld_force_assert_target(qdf->dev);
1710 if (errno == -EOPNOTSUPP)
1711 cds_info("PLD does not support target force assert");
1712 else if (errno)
1713 cds_err("Failed PLD target force assert; errno %d", errno);
1714 else
1715 cds_info("Target force assert triggered via PLD");
1716
1717 return errno;
Mukul Sharmab7b575b2016-10-02 23:37:07 +05301718}
1719
Dustin Brown100201e2017-07-10 11:48:40 -07001720static QDF_STATUS cds_force_assert_target_via_wmi(qdf_device_t qdf)
Rajeev Kumardb60f162017-07-25 20:27:59 -07001721{
Dustin Brown100201e2017-07-10 11:48:40 -07001722 QDF_STATUS status;
1723 t_wma_handle *wma;
1724
1725 wma = cds_get_context(QDF_MODULE_ID_WMA);
1726 if (!wma) {
1727 cds_err("wma is null");
1728 return QDF_STATUS_E_INVAL;
1729 }
1730
1731 status = wma_crash_inject(wma, RECOVERY_SIM_SELF_RECOVERY, 0);
1732 if (QDF_IS_STATUS_ERROR(status)) {
1733 cds_err("Failed target force assert; status %d", status);
1734 return status;
1735 }
1736
Nachiket Kukade0396b732017-11-14 16:35:16 +05301737 status = qdf_wait_for_event_completion(&wma->recovery_event,
Dustin Brown100201e2017-07-10 11:48:40 -07001738 WMA_CRASH_INJECT_TIMEOUT);
1739 if (QDF_IS_STATUS_ERROR(status)) {
1740 cds_err("Failed target force assert wait; status %d", status);
1741 return status;
1742 }
1743
1744 return QDF_STATUS_SUCCESS;
1745}
1746
1747/**
1748 * cds_force_assert_target() - Send assert command to firmware
1749 * @qdf: QDF device instance to assert
1750 *
1751 * An out-of-band recovery mechanism will cleanup and restart the entire wlan
1752 * subsystem in the event of a firmware crash. This API injects a firmware
1753 * crash to start this process when the wlan driver is known to be in a bad
1754 * state. If a firmware assert inject fails, the wlan driver will schedule
1755 * the driver recovery anyway, as a best effort attempt to return to a working
1756 * state.
1757 *
1758 * Return: QDF_STATUS
1759 */
1760static QDF_STATUS cds_force_assert_target(qdf_device_t qdf)
1761{
1762 int errno;
1763 QDF_STATUS status;
1764
1765 /* first, try target assert inject via pld */
1766 errno = cds_force_assert_target_via_pld(qdf);
1767 if (!errno)
1768 return QDF_STATUS_SUCCESS;
1769 if (errno != -EOPNOTSUPP)
1770 return QDF_STATUS_E_FAILURE;
1771
1772 /* pld assert is not supported, try target assert inject via wmi */
1773 status = cds_force_assert_target_via_wmi(qdf);
1774 if (QDF_IS_STATUS_SUCCESS(status))
1775 return QDF_STATUS_SUCCESS;
1776
1777 /* wmi assert failed, start recovery without the firmware assert */
1778 cds_err("Scheduling recovery work without firmware assert");
Dustin Brown100201e2017-07-10 11:48:40 -07001779 pld_schedule_recovery_work(qdf->dev, PLD_REASON_DEFAULT);
1780
1781 return status;
Rajeev Kumardb60f162017-07-25 20:27:59 -07001782}
1783
Mukul Sharmab7b575b2016-10-02 23:37:07 +05301784/**
Dustin Brown485bbad2018-08-20 10:28:40 -07001785 * cds_trigger_recovery_handler() - handle a self recovery request
1786 * @func: the name of the function that called cds_trigger_recovery
1787 * @line: the line number of the call site which called cds_trigger_recovery
Mukul Sharmab7b575b2016-10-02 23:37:07 +05301788 *
1789 * Return: none
1790 */
Dustin Brown485bbad2018-08-20 10:28:40 -07001791static void cds_trigger_recovery_handler(const char *func, const uint32_t line)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001792{
Dustin Brown100201e2017-07-10 11:48:40 -07001793 QDF_STATUS status;
1794 qdf_runtime_lock_t rtl;
1795 qdf_device_t qdf;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001796
Dustin Brownffd584f2018-08-20 13:03:33 -07001797 /* NOTE! This code path is delicate! Think very carefully before
1798 * modifying the content or order of the following. Please review any
1799 * potential changes with someone closely familiar with this feature.
1800 */
Zhu Jianmin26b9b8a2018-05-15 09:04:45 +08001801
Kabilan Kannan973744a2018-01-03 10:28:50 -08001802 if (cds_is_driver_recovering()) {
Dustin Brownffd584f2018-08-20 13:03:33 -07001803 cds_info("WLAN recovery already in progress");
Sameer Thalappilec2e9c72017-02-08 15:45:49 -08001804 return;
1805 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001806
Kabilan Kannan973744a2018-01-03 10:28:50 -08001807 if (cds_is_driver_in_bad_state()) {
Dustin Brownffd584f2018-08-20 13:03:33 -07001808 cds_info("WLAN has already failed recovery");
Houston Hoffmanc7c72a82015-12-07 15:30:48 -08001809 return;
1810 }
1811
Rajeev Kumar6dd45a82017-10-20 14:43:05 -07001812 if (cds_is_fw_down()) {
Dustin Brownffd584f2018-08-20 13:03:33 -07001813 cds_info("Firmware has already initiated recovery");
Rajeev Kumar6dd45a82017-10-20 14:43:05 -07001814 return;
1815 }
1816
Yuanyuan Liu3ab55312018-12-03 15:41:02 -08001817 qdf = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
1818 if (!qdf) {
1819 cds_err("Qdf context is null");
1820 return;
1821 }
1822
Dustin Brownffd584f2018-08-20 13:03:33 -07001823 /* if *wlan* recovery is disabled, crash here for debugging */
Dustin Browne5fa1972018-08-13 14:28:55 -07001824 if (!cds_is_self_recovery_enabled()) {
Dustin Brownffd584f2018-08-20 13:03:33 -07001825 QDF_DEBUG_PANIC("WLAN recovery is not enabled (via %s:%d)",
Dustin Brown485bbad2018-08-20 10:28:40 -07001826 func, line);
Dustin Browne5fa1972018-08-13 14:28:55 -07001827 return;
1828 }
1829
Dustin Brownffd584f2018-08-20 13:03:33 -07001830 /* ignore recovery if we are unloading; it would be a waste anyway */
1831 if (cds_is_driver_unloading()) {
1832 cds_info("WLAN is unloading; ignore recovery");
1833 return;
1834 }
1835
Dustin Brown100201e2017-07-10 11:48:40 -07001836 status = qdf_runtime_lock_init(&rtl);
1837 if (QDF_IS_STATUS_ERROR(status)) {
Srinivas Girigowda161b9f22017-07-24 17:38:09 -07001838 cds_err("qdf_runtime_lock_init failed, status: %d", status);
Dustin Brown100201e2017-07-10 11:48:40 -07001839 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001840 }
Houston Hoffmanc7c72a82015-12-07 15:30:48 -08001841
Dustin Brown100201e2017-07-10 11:48:40 -07001842 status = qdf_runtime_pm_prevent_suspend(&rtl);
1843 if (QDF_IS_STATUS_ERROR(status)) {
1844 cds_err("Failed to acquire runtime pm lock");
1845 goto deinit_rtl;
1846 }
1847
hangtian6b62cb12019-03-15 09:46:09 +08001848 cds_set_recovery_in_progress(true);
Dustin Brown100201e2017-07-10 11:48:40 -07001849 cds_force_assert_target(qdf);
1850
1851 status = qdf_runtime_pm_allow_suspend(&rtl);
1852 if (QDF_IS_STATUS_ERROR(status))
1853 cds_err("Failed to release runtime pm lock");
1854
1855deinit_rtl:
1856 qdf_runtime_lock_deinit(&rtl);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001857}
1858
Dustin Brown485bbad2018-08-20 10:28:40 -07001859static void cds_trigger_recovery_work(void *context)
1860{
1861 struct cds_recovery_call_info *call_info = context;
1862
1863 cds_trigger_recovery_handler(call_info->func, call_info->line);
1864}
1865
1866void __cds_trigger_recovery(enum qdf_hang_reason reason, const char *func,
1867 const uint32_t line)
1868{
1869 if (!gp_cds_context) {
1870 cds_err("gp_cds_context is null");
1871 return;
1872 }
1873
1874 gp_cds_context->recovery_reason = reason;
1875
1876 if (in_atomic()) {
1877 __cds_recovery_caller.func = func;
1878 __cds_recovery_caller.line = line;
1879 qdf_queue_work(0, gp_cds_context->cds_recovery_wq,
1880 &gp_cds_context->cds_recovery_work);
1881 return;
1882 }
1883
1884 cds_trigger_recovery_handler(func, line);
1885}
1886
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001887/**
Anurag Chouhan4085ff72017-10-05 18:09:56 +05301888 * cds_get_recovery_reason() - get self recovery reason
1889 * @reason: recovery reason
1890 *
1891 * Return: None
1892 */
1893void cds_get_recovery_reason(enum qdf_hang_reason *reason)
1894{
1895 if (!gp_cds_context) {
1896 cds_err("gp_cds_context is null");
1897 return;
1898 }
1899
1900 *reason = gp_cds_context->recovery_reason;
1901}
1902
1903/**
1904 * cds_reset_recovery_reason() - reset the reason to unspecified
1905 *
1906 * Return: None
1907 */
1908void cds_reset_recovery_reason(void)
1909{
1910 if (!gp_cds_context) {
1911 cds_err("gp_cds_context is null");
1912 return;
1913 }
1914
1915 gp_cds_context->recovery_reason = QDF_REASON_UNSPECIFIED;
1916}
1917
Srinivas Girigowda161b9f22017-07-24 17:38:09 -07001918/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001919 * cds_set_wakelock_logging() - Logging of wakelock enabled/disabled
1920 * @value: Boolean value
1921 *
1922 * This function is used to set the flag which will indicate whether
1923 * logging of wakelock is enabled or not
1924 *
1925 * Return: None
1926 */
1927void cds_set_wakelock_logging(bool value)
1928{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07001929 struct cds_context *p_cds_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001930
1931 p_cds_context = cds_get_global_context();
1932 if (!p_cds_context) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001933 cds_err("cds context is Invald");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001934 return;
1935 }
1936 p_cds_context->is_wakelock_log_enabled = value;
1937}
1938
1939/**
1940 * cds_is_wakelock_enabled() - Check if logging of wakelock is enabled/disabled
1941 * @value: Boolean value
1942 *
1943 * This function is used to check whether logging of wakelock is enabled or not
1944 *
1945 * Return: true if logging of wakelock is enabled
1946 */
1947bool cds_is_wakelock_enabled(void)
1948{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07001949 struct cds_context *p_cds_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001950
1951 p_cds_context = cds_get_global_context();
1952 if (!p_cds_context) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001953 cds_err("cds context is Invald");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001954 return false;
1955 }
1956 return p_cds_context->is_wakelock_log_enabled;
1957}
1958
1959/**
1960 * cds_set_ring_log_level() - Sets the log level of a particular ring
1961 * @ring_id: ring_id
1962 * @log_levelvalue: Log level specificed
1963 *
1964 * This function converts HLOS values to driver log levels and sets the log
1965 * level of a particular ring accordingly.
1966 *
1967 * Return: None
1968 */
1969void cds_set_ring_log_level(uint32_t ring_id, uint32_t log_level)
1970{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07001971 struct cds_context *p_cds_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001972 uint32_t log_val;
1973
1974 p_cds_context = cds_get_global_context();
1975 if (!p_cds_context) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07001976 cds_err("cds context is Invald");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001977 return;
1978 }
1979
1980 switch (log_level) {
1981 case LOG_LEVEL_NO_COLLECTION:
1982 log_val = WLAN_LOG_LEVEL_OFF;
1983 break;
1984 case LOG_LEVEL_NORMAL_COLLECT:
1985 log_val = WLAN_LOG_LEVEL_NORMAL;
1986 break;
1987 case LOG_LEVEL_ISSUE_REPRO:
1988 log_val = WLAN_LOG_LEVEL_REPRO;
1989 break;
1990 case LOG_LEVEL_ACTIVE:
1991 default:
1992 log_val = WLAN_LOG_LEVEL_ACTIVE;
1993 break;
1994 }
1995
1996 if (ring_id == RING_ID_WAKELOCK) {
1997 p_cds_context->wakelock_log_level = log_val;
1998 return;
1999 } else if (ring_id == RING_ID_CONNECTIVITY) {
2000 p_cds_context->connectivity_log_level = log_val;
2001 return;
2002 } else if (ring_id == RING_ID_PER_PACKET_STATS) {
2003 p_cds_context->packet_stats_log_level = log_val;
2004 return;
Chandrasekaran, Manishekar907c2af2015-11-13 12:50:04 +05302005 } else if (ring_id == RING_ID_DRIVER_DEBUG) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002006 p_cds_context->driver_debug_log_level = log_val;
2007 return;
2008 } else if (ring_id == RING_ID_FIRMWARE_DEBUG) {
2009 p_cds_context->fw_debug_log_level = log_val;
2010 return;
2011 }
2012}
2013
2014/**
2015 * cds_get_ring_log_level() - Get the a ring id's log level
2016 * @ring_id: Ring id
2017 *
2018 * Fetch and return the log level corresponding to a ring id
2019 *
2020 * Return: Log level corresponding to the ring ID
2021 */
2022enum wifi_driver_log_level cds_get_ring_log_level(uint32_t ring_id)
2023{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002024 struct cds_context *p_cds_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002025
2026 p_cds_context = cds_get_global_context();
2027 if (!p_cds_context) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07002028 cds_err("cds context is Invald");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002029 return WLAN_LOG_LEVEL_OFF;
2030 }
2031
2032 if (ring_id == RING_ID_WAKELOCK)
2033 return p_cds_context->wakelock_log_level;
2034 else if (ring_id == RING_ID_CONNECTIVITY)
2035 return p_cds_context->connectivity_log_level;
2036 else if (ring_id == RING_ID_PER_PACKET_STATS)
2037 return p_cds_context->packet_stats_log_level;
Chandrasekaran, Manishekar907c2af2015-11-13 12:50:04 +05302038 else if (ring_id == RING_ID_DRIVER_DEBUG)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002039 return p_cds_context->driver_debug_log_level;
2040 else if (ring_id == RING_ID_FIRMWARE_DEBUG)
2041 return p_cds_context->fw_debug_log_level;
2042
2043 return WLAN_LOG_LEVEL_OFF;
2044}
2045
2046/**
2047 * cds_set_multicast_logging() - Set mutlicast logging value
2048 * @value: Value of multicast logging
2049 *
2050 * Set the multicast logging value which will indicate
2051 * whether to multicast host and fw messages even
2052 * without any registration by userspace entity
2053 *
2054 * Return: None
2055 */
2056void cds_set_multicast_logging(uint8_t value)
2057{
2058 cds_multicast_logging = value;
2059}
2060
2061/**
2062 * cds_is_multicast_logging() - Get multicast logging value
2063 *
2064 * Get the multicast logging value which will indicate
2065 * whether to multicast host and fw messages even
2066 * without any registration by userspace entity
2067 *
2068 * Return: 0 - Multicast logging disabled, 1 - Multicast logging enabled
2069 */
2070uint8_t cds_is_multicast_logging(void)
2071{
2072 return cds_multicast_logging;
2073}
2074
2075/*
2076 * cds_init_log_completion() - Initialize log param structure
2077 *
2078 * This function is used to initialize the logging related
2079 * parameters
2080 *
2081 * Return: None
2082 */
2083void cds_init_log_completion(void)
2084{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002085 struct cds_context *p_cds_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002086
2087 p_cds_context = cds_get_global_context();
2088 if (!p_cds_context) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07002089 cds_err("cds context is Invalid");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002090 return;
2091 }
2092
2093 p_cds_context->log_complete.is_fatal = WLAN_LOG_TYPE_NON_FATAL;
2094 p_cds_context->log_complete.indicator = WLAN_LOG_INDICATOR_UNUSED;
2095 p_cds_context->log_complete.reason_code = WLAN_LOG_REASON_CODE_UNUSED;
2096 p_cds_context->log_complete.is_report_in_progress = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002097}
2098
2099/**
2100 * cds_set_log_completion() - Store the logging params
2101 * @is_fatal: Indicates if the event triggering bug report is fatal or not
2102 * @indicator: Source which trigerred the bug report
2103 * @reason_code: Reason for triggering bug report
Abhishek Singh5ea86532016-04-27 14:10:53 +05302104 * @recovery_needed: If recovery is needed after bug report
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002105 *
2106 * This function is used to set the logging parameters based on the
2107 * caller
2108 *
2109 * Return: 0 if setting of params is successful
2110 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302111QDF_STATUS cds_set_log_completion(uint32_t is_fatal,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002112 uint32_t indicator,
Abhishek Singh5ea86532016-04-27 14:10:53 +05302113 uint32_t reason_code,
2114 bool recovery_needed)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002115{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002116 struct cds_context *p_cds_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002117
2118 p_cds_context = cds_get_global_context();
2119 if (!p_cds_context) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07002120 cds_err("cds context is Invalid");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302121 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002122 }
2123
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302124 qdf_spinlock_acquire(&p_cds_context->bug_report_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002125 p_cds_context->log_complete.is_fatal = is_fatal;
2126 p_cds_context->log_complete.indicator = indicator;
2127 p_cds_context->log_complete.reason_code = reason_code;
Abhishek Singh5ea86532016-04-27 14:10:53 +05302128 p_cds_context->log_complete.recovery_needed = recovery_needed;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002129 p_cds_context->log_complete.is_report_in_progress = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302130 qdf_spinlock_release(&p_cds_context->bug_report_lock);
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07002131 cds_debug("is_fatal %d indicator %d reason_code %d recovery needed %d",
2132 is_fatal, indicator, reason_code, recovery_needed);
Rajeev Kumardcce8092018-05-02 15:48:17 -07002133
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302134 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002135}
2136
2137/**
Abhishek Singh5ea86532016-04-27 14:10:53 +05302138 * cds_get_and_reset_log_completion() - Get and reset logging related params
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002139 * @is_fatal: Indicates if the event triggering bug report is fatal or not
2140 * @indicator: Source which trigerred the bug report
2141 * @reason_code: Reason for triggering bug report
Abhishek Singh5ea86532016-04-27 14:10:53 +05302142 * @recovery_needed: If recovery is needed after bug report
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002143 *
2144 * This function is used to get the logging related parameters
2145 *
2146 * Return: None
2147 */
Abhishek Singh5ea86532016-04-27 14:10:53 +05302148void cds_get_and_reset_log_completion(uint32_t *is_fatal,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002149 uint32_t *indicator,
Abhishek Singh5ea86532016-04-27 14:10:53 +05302150 uint32_t *reason_code,
2151 bool *recovery_needed)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002152{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002153 struct cds_context *p_cds_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002154
2155 p_cds_context = cds_get_global_context();
2156 if (!p_cds_context) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07002157 cds_err("cds context is Invalid");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002158 return;
2159 }
2160
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302161 qdf_spinlock_acquire(&p_cds_context->bug_report_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002162 *is_fatal = p_cds_context->log_complete.is_fatal;
2163 *indicator = p_cds_context->log_complete.indicator;
2164 *reason_code = p_cds_context->log_complete.reason_code;
Abhishek Singh5ea86532016-04-27 14:10:53 +05302165 *recovery_needed = p_cds_context->log_complete.recovery_needed;
2166
2167 /* reset */
2168 p_cds_context->log_complete.indicator = WLAN_LOG_INDICATOR_UNUSED;
2169 p_cds_context->log_complete.is_fatal = WLAN_LOG_TYPE_NON_FATAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002170 p_cds_context->log_complete.is_report_in_progress = false;
Abhishek Singh5ea86532016-04-27 14:10:53 +05302171 p_cds_context->log_complete.reason_code = WLAN_LOG_REASON_CODE_UNUSED;
2172 p_cds_context->log_complete.recovery_needed = false;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302173 qdf_spinlock_release(&p_cds_context->bug_report_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002174}
2175
2176/**
2177 * cds_is_log_report_in_progress() - Check if bug reporting is in progress
2178 *
2179 * This function is used to check if the bug reporting is already in progress
2180 *
2181 * Return: true if the bug reporting is in progress
2182 */
2183bool cds_is_log_report_in_progress(void)
2184{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002185 struct cds_context *p_cds_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002186
2187 p_cds_context = cds_get_global_context();
2188 if (!p_cds_context) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07002189 cds_err("cds context is Invalid");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002190 return true;
2191 }
2192 return p_cds_context->log_complete.is_report_in_progress;
2193}
2194
2195/**
Abhishek Singh5ea86532016-04-27 14:10:53 +05302196 * cds_is_fatal_event_enabled() - Return if fatal event is enabled
2197 *
2198 * Return true if fatal event is enabled.
2199 */
2200bool cds_is_fatal_event_enabled(void)
2201{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002202 struct cds_context *p_cds_context;
Abhishek Singh5ea86532016-04-27 14:10:53 +05302203
2204 p_cds_context = cds_get_global_context();
2205 if (!p_cds_context) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07002206 cds_err("cds context is Invalid");
Abhishek Singh5ea86532016-04-27 14:10:53 +05302207 return false;
2208 }
2209
2210
2211 return p_cds_context->enable_fatal_event;
2212}
2213
Yu Wang66a250b2017-07-19 11:46:40 +08002214#ifdef WLAN_FEATURE_TSF_PLUS
2215bool cds_is_ptp_rx_opt_enabled(void)
2216{
2217 struct hdd_context *hdd_ctx;
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002218 struct cds_context *p_cds_context;
Yu Wang66a250b2017-07-19 11:46:40 +08002219
2220 p_cds_context = cds_get_global_context();
2221 if (!p_cds_context) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07002222 cds_err("cds context is Invalid");
Yu Wang66a250b2017-07-19 11:46:40 +08002223 return false;
2224 }
2225
Jeff Johnson323a6f02018-05-29 15:09:12 -07002226 hdd_ctx = (struct hdd_context *)(p_cds_context->hdd_context);
Jeff Johnsone7afbe92019-03-18 13:43:43 -07002227 if ((!hdd_ctx) || (!hdd_ctx->config)) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07002228 cds_err("Hdd Context is Null");
Yu Wang66a250b2017-07-19 11:46:40 +08002229 return false;
2230 }
2231
yuanl2746f072018-09-21 19:19:16 +08002232 return hdd_tsf_is_rx_set(hdd_ctx);
Yu Wang66a250b2017-07-19 11:46:40 +08002233}
2234
2235bool cds_is_ptp_tx_opt_enabled(void)
2236{
2237 struct hdd_context *hdd_ctx;
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002238 struct cds_context *p_cds_context;
Yu Wang66a250b2017-07-19 11:46:40 +08002239
2240 p_cds_context = cds_get_global_context();
2241 if (!p_cds_context) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07002242 cds_err("cds context is Invalid");
Yu Wang66a250b2017-07-19 11:46:40 +08002243 return false;
2244 }
2245
Jeff Johnson323a6f02018-05-29 15:09:12 -07002246 hdd_ctx = (struct hdd_context *)(p_cds_context->hdd_context);
Jeff Johnsone7afbe92019-03-18 13:43:43 -07002247 if ((!hdd_ctx) || (!hdd_ctx->config)) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07002248 cds_err("Hdd Context is Null");
Yu Wang66a250b2017-07-19 11:46:40 +08002249 return false;
2250 }
2251
yuanl2746f072018-09-21 19:19:16 +08002252 return hdd_tsf_is_tx_set(hdd_ctx);
Yu Wang66a250b2017-07-19 11:46:40 +08002253}
2254#endif
2255
Abhishek Singh5ea86532016-04-27 14:10:53 +05302256/**
2257 * cds_get_log_indicator() - Get the log flush indicator
2258 *
2259 * This function is used to get the log flush indicator
2260 *
2261 * Return: log indicator
2262 */
2263uint32_t cds_get_log_indicator(void)
2264{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002265 struct cds_context *p_cds_context;
Abhishek Singh5ea86532016-04-27 14:10:53 +05302266 uint32_t indicator;
2267
2268 p_cds_context = cds_get_global_context();
2269 if (!p_cds_context) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07002270 cds_err("cds context is Invalid");
Abhishek Singh5ea86532016-04-27 14:10:53 +05302271 return WLAN_LOG_INDICATOR_UNUSED;
2272 }
2273
2274 if (cds_is_load_or_unload_in_progress() ||
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05302275 cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Abhishek Singh5ea86532016-04-27 14:10:53 +05302276 return WLAN_LOG_INDICATOR_UNUSED;
2277 }
2278
2279 qdf_spinlock_acquire(&p_cds_context->bug_report_lock);
2280 indicator = p_cds_context->log_complete.indicator;
2281 qdf_spinlock_release(&p_cds_context->bug_report_lock);
2282 return indicator;
2283}
2284
2285/**
2286 * cds_wlan_flush_host_logs_for_fatal() - Wrapper to flush host logs
2287 *
2288 * This function is used to send signal to the logger thread to
2289 * flush the host logs.
2290 *
2291 * Return: None
2292 *
2293 */
2294void cds_wlan_flush_host_logs_for_fatal(void)
2295{
Jingxiang Ge92fd1ee2019-07-05 17:14:47 +08002296 if (cds_is_log_report_in_progress())
2297 wlan_flush_host_logs_for_fatal();
Abhishek Singh5ea86532016-04-27 14:10:53 +05302298}
2299
2300/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002301 * cds_flush_logs() - Report fatal event to userspace
2302 * @is_fatal: Indicates if the event triggering bug report is fatal or not
2303 * @indicator: Source which trigerred the bug report
2304 * @reason_code: Reason for triggering bug report
Abhishek Singh5ea86532016-04-27 14:10:53 +05302305 * @dump_mac_trace: If mac trace are needed in logs.
2306 * @recovery_needed: If recovery is needed after bug report
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002307 *
2308 * This function sets the log related params and send the WMI command to the
2309 * FW to flush its logs. On receiving the flush completion event from the FW
2310 * the same will be conveyed to userspace
2311 *
2312 * Return: 0 on success
2313 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302314QDF_STATUS cds_flush_logs(uint32_t is_fatal,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002315 uint32_t indicator,
Abhishek Singh5ea86532016-04-27 14:10:53 +05302316 uint32_t reason_code,
2317 bool dump_mac_trace,
2318 bool recovery_needed)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002319{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302320 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002321
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002322 struct cds_context *p_cds_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002323
2324 p_cds_context = cds_get_global_context();
2325 if (!p_cds_context) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07002326 cds_err("cds context is Invalid");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302327 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002328 }
Abhishek Singh5ea86532016-04-27 14:10:53 +05302329 if (!p_cds_context->enable_fatal_event) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07002330 cds_err("Fatal event not enabled");
Abhishek Singh5ea86532016-04-27 14:10:53 +05302331 return QDF_STATUS_E_FAILURE;
2332 }
2333 if (cds_is_load_or_unload_in_progress() ||
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05302334 cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07002335 cds_err("un/Load/SSR in progress");
Abhishek Singh5ea86532016-04-27 14:10:53 +05302336 return QDF_STATUS_E_FAILURE;
2337 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002338
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07002339 if (cds_is_log_report_in_progress()) {
2340 cds_err("Bug report already in progress - dropping! type:%d, indicator=%d reason_code=%d",
2341 is_fatal, indicator, reason_code);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302342 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002343 }
2344
Abhishek Singh5ea86532016-04-27 14:10:53 +05302345 status = cds_set_log_completion(is_fatal, indicator,
2346 reason_code, recovery_needed);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302347 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07002348 cds_err("Failed to set log trigger params");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302349 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002350 }
2351
Yeshwanth Sriram Guntukacbe61442018-08-23 18:08:44 +05302352 cds_debug("Triggering bug report: type:%d, indicator=%d reason_code=%d",
2353 is_fatal, indicator, reason_code);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002354
Abhishek Singh5ea86532016-04-27 14:10:53 +05302355 if (dump_mac_trace)
Jeff Johnson528c2cf2018-05-29 15:55:58 -07002356 qdf_trace_dump_all(p_cds_context->mac_context, 0, 0, 500, 0);
Abhishek Singh5ea86532016-04-27 14:10:53 +05302357
2358 if (WLAN_LOG_INDICATOR_HOST_ONLY == indicator) {
2359 cds_wlan_flush_host_logs_for_fatal();
2360 return QDF_STATUS_SUCCESS;
2361 }
2362
Jeff Johnson40894142018-11-17 12:05:54 -08002363 status = sme_send_flush_logs_cmd_to_fw();
2364 if (QDF_IS_STATUS_ERROR(status)) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07002365 cds_err("Failed to send flush FW log");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002366 cds_init_log_completion();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302367 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002368 }
2369
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302370 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002371}
2372
2373/**
2374 * cds_logging_set_fw_flush_complete() - Wrapper for FW log flush completion
2375 *
2376 * This function is used to send signal to the logger thread to indicate
2377 * that the flushing of FW logs is complete by the FW
2378 *
2379 * Return: None
2380 *
2381 */
2382void cds_logging_set_fw_flush_complete(void)
2383{
Jingxiang Gece8ebf72019-07-05 15:54:30 +08002384 if (cds_is_fatal_event_enabled())
2385 wlan_logging_set_fw_flush_complete();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002386}
Abhishek Singh5ea86532016-04-27 14:10:53 +05302387
2388/**
2389 * cds_set_fatal_event() - set fatal event status
2390 * @value: pending statue to set
2391 *
2392 * Return: None
2393 */
2394void cds_set_fatal_event(bool value)
2395{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002396 struct cds_context *p_cds_context;
Abhishek Singh5ea86532016-04-27 14:10:53 +05302397
2398 p_cds_context = cds_get_global_context();
2399 if (!p_cds_context) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07002400 cds_err("cds context is Invalid");
Abhishek Singh5ea86532016-04-27 14:10:53 +05302401 return;
2402 }
2403 p_cds_context->enable_fatal_event = value;
2404}
2405
Ryan Hsuceddceb2016-04-28 10:20:14 -07002406/**
2407 * cds_get_radio_index() - get radio index
2408 *
2409 * Return: radio index otherwise, -EINVAL
2410 */
2411int cds_get_radio_index(void)
2412{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002413 struct cds_context *p_cds_context;
Ryan Hsuceddceb2016-04-28 10:20:14 -07002414
2415 p_cds_context = cds_get_global_context();
2416 if (!p_cds_context) {
2417 /*
2418 * To avoid recursive call, this should not change to
2419 * QDF_TRACE().
2420 */
2421 pr_err("%s: cds context is invalid\n", __func__);
2422 return -EINVAL;
2423 }
2424
2425 return p_cds_context->radio_index;
2426}
2427
2428/**
2429 * cds_set_radio_index() - set radio index
2430 * @radio_index: the radio index to set
2431 *
2432 * Return: QDF status
2433 */
2434QDF_STATUS cds_set_radio_index(int radio_index)
2435{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002436 struct cds_context *p_cds_context;
Ryan Hsuceddceb2016-04-28 10:20:14 -07002437
2438 p_cds_context = cds_get_global_context();
2439 if (!p_cds_context) {
2440 pr_err("%s: cds context is invalid\n", __func__);
2441 return QDF_STATUS_E_FAILURE;
2442 }
2443
2444 p_cds_context->radio_index = radio_index;
2445
2446 return QDF_STATUS_SUCCESS;
2447}
Arun Khandavallic811dcc2016-06-26 07:37:21 +05302448
2449/**
2450 * cds_init_ini_config() - API to initialize CDS configuration parameters
2451 * @cfg: CDS Configuration
2452 *
2453 * Return: void
2454 */
2455
2456void cds_init_ini_config(struct cds_config_info *cfg)
2457{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002458 struct cds_context *cds_ctx;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05302459
2460 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2461 if (!cds_ctx) {
2462 cds_err("Invalid CDS Context");
2463 return;
2464 }
2465
2466 cds_ctx->cds_cfg = cfg;
2467}
2468
2469/**
2470 * cds_deinit_ini_config() - API to free CDS configuration parameters
2471 *
2472 * Return: void
2473 */
2474void cds_deinit_ini_config(void)
2475{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002476 struct cds_context *cds_ctx;
Dustin Brownffd584f2018-08-20 13:03:33 -07002477 struct cds_config_info *cds_cfg;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05302478
2479 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2480 if (!cds_ctx) {
2481 cds_err("Invalid CDS Context");
2482 return;
2483 }
2484
Dustin Brownffd584f2018-08-20 13:03:33 -07002485 cds_cfg = cds_ctx->cds_cfg;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05302486 cds_ctx->cds_cfg = NULL;
Dustin Brownffd584f2018-08-20 13:03:33 -07002487
2488 if (cds_cfg)
2489 qdf_mem_free(cds_cfg);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05302490}
2491
2492/**
2493 * cds_get_ini_config() - API to get CDS configuration parameters
2494 *
2495 * Return: cds config structure
2496 */
2497struct cds_config_info *cds_get_ini_config(void)
2498{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002499 struct cds_context *cds_ctx;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05302500
2501 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2502 if (!cds_ctx) {
2503 cds_err("Invalid CDS Context");
2504 return NULL;
2505 }
2506
2507 return cds_ctx->cds_cfg;
2508}
Naveen Rawat64e477e2016-05-20 10:34:56 -07002509
2510/**
2511 * cds_is_5_mhz_enabled() - API to get 5MHZ enabled
2512 *
2513 * Return: true if 5 mhz is enabled, false otherwise
2514 */
2515bool cds_is_5_mhz_enabled(void)
2516{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002517 struct cds_context *p_cds_context;
Naveen Rawat64e477e2016-05-20 10:34:56 -07002518
2519 p_cds_context = cds_get_context(QDF_MODULE_ID_QDF);
2520 if (!p_cds_context) {
2521 cds_err("%s: cds context is invalid", __func__);
2522 return false;
2523 }
2524
2525 if (p_cds_context->cds_cfg)
2526 return (p_cds_context->cds_cfg->sub_20_channel_width ==
2527 WLAN_SUB_20_CH_WIDTH_5);
2528
2529 return false;
2530}
2531
2532/**
2533 * cds_is_10_mhz_enabled() - API to get 10-MHZ enabled
2534 *
2535 * Return: true if 10 mhz is enabled, false otherwise
2536 */
2537bool cds_is_10_mhz_enabled(void)
2538{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002539 struct cds_context *p_cds_context;
Naveen Rawat64e477e2016-05-20 10:34:56 -07002540
2541 p_cds_context = cds_get_context(QDF_MODULE_ID_QDF);
2542 if (!p_cds_context) {
2543 cds_err("%s: cds context is invalid", __func__);
2544 return false;
2545 }
2546
2547 if (p_cds_context->cds_cfg)
2548 return (p_cds_context->cds_cfg->sub_20_channel_width ==
2549 WLAN_SUB_20_CH_WIDTH_10);
2550
2551 return false;
2552}
2553
2554/**
2555 * cds_is_sub_20_mhz_enabled() - API to get sub 20-MHZ enabled
2556 *
2557 * Return: true if 5 or 10 mhz is enabled, false otherwise
2558 */
2559bool cds_is_sub_20_mhz_enabled(void)
2560{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002561 struct cds_context *p_cds_context;
Naveen Rawat64e477e2016-05-20 10:34:56 -07002562
2563 p_cds_context = cds_get_context(QDF_MODULE_ID_QDF);
2564 if (!p_cds_context) {
2565 cds_err("%s: cds context is invalid", __func__);
2566 return false;
2567 }
2568
2569 if (p_cds_context->cds_cfg)
2570 return p_cds_context->cds_cfg->sub_20_channel_width;
2571
2572 return false;
2573}
2574
Komal Seelam78ff65a2016-08-18 15:25:24 +05302575/**
Naveen Rawat91df30a2016-10-12 21:26:18 -07002576 * cds_is_self_recovery_enabled() - API to get self recovery enabled
2577 *
2578 * Return: true if self recovery enabled, false otherwise
2579 */
2580bool cds_is_self_recovery_enabled(void)
2581{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002582 struct cds_context *p_cds_context;
Naveen Rawat91df30a2016-10-12 21:26:18 -07002583
2584 p_cds_context = cds_get_context(QDF_MODULE_ID_QDF);
2585 if (!p_cds_context) {
2586 cds_err("%s: cds context is invalid", __func__);
2587 return false;
2588 }
2589
2590 if (p_cds_context->cds_cfg)
2591 return p_cds_context->cds_cfg->self_recovery_enabled;
2592
2593 return false;
2594}
2595
2596/**
Yuanyuan Liue4709772018-09-05 14:57:46 -07002597 * cds_is_fw_down() - Is FW down or not
2598 *
2599 * Return: true if FW is down and false otherwise.
2600 */
2601bool cds_is_fw_down(void)
2602{
2603 qdf_device_t qdf_ctx;
2604
2605 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
Yuanyuan Liudfb40922018-10-02 15:17:00 -07002606 if (!qdf_ctx) {
2607 cds_err("cds context is invalid");
2608 return false;
2609 }
2610
Yuanyuan Liue4709772018-09-05 14:57:46 -07002611 return pld_is_fw_down(qdf_ctx->dev);
2612}
2613
2614/**
Komal Seelam78ff65a2016-08-18 15:25:24 +05302615 * cds_svc_fw_shutdown_ind() - API to send userspace about FW crash
2616 *
2617 * @dev: Device Pointer
2618 *
2619 * Return: None
2620 */
2621void cds_svc_fw_shutdown_ind(struct device *dev)
2622{
2623 hdd_svc_fw_shutdown_ind(dev);
2624}
Himanshu Agarwal46956a52016-07-26 19:46:25 +05302625
Nirav Shaheb017be2018-02-15 11:20:58 +05302626#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
Himanshu Agarwal46956a52016-07-26 19:46:25 +05302627/*
2628 * cds_pkt_stats_to_logger_thread() - send pktstats to user
2629 * @pl_hdr: Pointer to pl_hdr
2630 * @pkt_dump: Pointer to pkt_dump data structure.
2631 * @data: Pointer to data
2632 *
2633 * This function is used to send the pkt stats to SVC module.
2634 *
2635 * Return: None
2636 */
2637inline void cds_pkt_stats_to_logger_thread(void *pl_hdr, void *pkt_dump,
2638 void *data)
2639{
2640 if (cds_get_ring_log_level(RING_ID_PER_PACKET_STATS) !=
2641 WLAN_LOG_LEVEL_ACTIVE)
2642 return;
2643
2644 wlan_pkt_stats_to_logger_thread(pl_hdr, pkt_dump, data);
2645}
Nirav Shaheb017be2018-02-15 11:20:58 +05302646#endif
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08002647
2648/**
2649 * cds_get_conparam() - Get the connection mode parameters
2650 *
2651 * Return the connection mode parameter set by insmod or set during statically
2652 * linked driver
2653 *
Jeff Johnson876c1a62017-12-12 10:43:07 -08002654 * Return: enum QDF_GLOBAL_MODE
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08002655 */
Jeff Johnson876c1a62017-12-12 10:43:07 -08002656enum QDF_GLOBAL_MODE cds_get_conparam(void)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08002657{
Jeff Johnson876c1a62017-12-12 10:43:07 -08002658 enum QDF_GLOBAL_MODE con_mode;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08002659
2660 con_mode = hdd_get_conparam();
2661
2662 return con_mode;
2663}
Dustin Brown8d2d0f52017-04-03 17:02:08 -07002664
Rachit Kankaneb1035622018-01-24 18:41:35 +05302665#ifdef FEATURE_HTC_CREDIT_HISTORY
Dustin Brown8d2d0f52017-04-03 17:02:08 -07002666inline void
2667cds_print_htc_credit_history(uint32_t count, qdf_abstract_print *print,
2668 void *print_priv)
2669{
2670 htc_print_credit_history(gp_cds_context->htc_ctx, count,
2671 print, print_priv);
2672}
2673#endif
Sravan Kumar Kairamc1ae71c2017-02-24 12:27:27 +05302674
Poddar, Siddarth3906e172018-01-09 11:24:58 +05302675uint32_t cds_get_connectivity_stats_pkt_bitmap(void *context)
2676{
2677 struct hdd_adapter *adapter = NULL;
2678
Alok Kumarfa826fd2018-02-19 15:10:34 +05302679 if (!context)
2680 return 0;
2681
Poddar, Siddarth3906e172018-01-09 11:24:58 +05302682 adapter = (struct hdd_adapter *)context;
2683 if (unlikely(adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07002684 cds_err("Magic cookie(%x) for adapter sanity verification is invalid",
2685 adapter->magic);
Alok Kumard27a9ed2018-04-17 10:36:24 +05302686 return 0;
Poddar, Siddarth3906e172018-01-09 11:24:58 +05302687 }
2688 return adapter->pkt_type_bitmap;
2689}
2690
2691/**
2692 * cds_get_arp_stats_gw_ip() - get arp stats track IP
2693 *
2694 * Return: ARP stats IP to track
2695 */
Poddar, Siddarth31797fa2018-01-22 17:24:15 +05302696uint32_t cds_get_arp_stats_gw_ip(void *context)
Sravan Kumar Kairamc1ae71c2017-02-24 12:27:27 +05302697{
Alok Kumarfa826fd2018-02-19 15:10:34 +05302698 struct hdd_adapter *adapter = NULL;
2699
2700 if (!context)
2701 return 0;
2702
2703 adapter = (struct hdd_adapter *)context;
Sravan Kumar Kairamc1ae71c2017-02-24 12:27:27 +05302704
Poddar, Siddarth31797fa2018-01-22 17:24:15 +05302705 if (unlikely(adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
Jeff Johnsond0a6b2c2018-05-30 22:57:39 -07002706 cds_err("Magic cookie(%x) for adapter sanity verification is invalid",
2707 adapter->magic);
Sravan Kumar Kairamc1ae71c2017-02-24 12:27:27 +05302708 return 0;
2709 }
2710
Poddar, Siddarth31797fa2018-01-22 17:24:15 +05302711 return adapter->track_arp_ip;
Sravan Kumar Kairamc1ae71c2017-02-24 12:27:27 +05302712}
2713
2714/**
2715 * cds_incr_arp_stats_tx_tgt_delivered() - increment ARP stats
2716 *
2717 * Return: none
2718 */
2719void cds_incr_arp_stats_tx_tgt_delivered(void)
2720{
2721 struct hdd_context *hdd_ctx;
2722 struct hdd_adapter *adapter = NULL;
2723
Jeff Johnson323a6f02018-05-29 15:09:12 -07002724 hdd_ctx = gp_cds_context->hdd_context;
Sravan Kumar Kairamc1ae71c2017-02-24 12:27:27 +05302725 if (!hdd_ctx) {
2726 cds_err("Hdd Context is Null");
2727 return;
2728 }
2729
2730 hdd_for_each_adapter(hdd_ctx, adapter) {
2731 if (QDF_STA_MODE == adapter->device_mode)
2732 break;
2733 }
2734
2735 if (adapter)
2736 adapter->hdd_stats.hdd_arp_stats.tx_host_fw_sent++;
2737}
2738
2739/**
2740 * cds_incr_arp_stats_tx_tgt_acked() - increment ARP stats
2741 *
2742 * Return: none
2743 */
2744void cds_incr_arp_stats_tx_tgt_acked(void)
2745{
2746 struct hdd_context *hdd_ctx;
2747 struct hdd_adapter *adapter = NULL;
2748
Jeff Johnson323a6f02018-05-29 15:09:12 -07002749 hdd_ctx = gp_cds_context->hdd_context;
Sravan Kumar Kairamc1ae71c2017-02-24 12:27:27 +05302750 if (!hdd_ctx) {
2751 cds_err("Hdd Context is Null");
2752 return;
2753 }
2754
2755 hdd_for_each_adapter(hdd_ctx, adapter) {
2756 if (QDF_STA_MODE == adapter->device_mode)
2757 break;
2758 }
2759
2760 if (adapter)
2761 adapter->hdd_stats.hdd_arp_stats.tx_ack_cnt++;
2762}
Himanshu Agarwaledf30dc2017-06-05 15:54:27 +05302763
2764#ifdef ENABLE_SMMU_S1_TRANSLATION
Rakshith Suresh Patkar65bdb192019-05-16 12:49:45 +05302765#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0))
2766QDF_STATUS cds_smmu_mem_map_setup(qdf_device_t osdev, bool ipa_present)
2767{
2768 struct iommu_domain *domain;
2769 bool ipa_smmu_enabled;
2770 bool wlan_smmu_enabled;
2771
2772 domain = pld_smmu_get_domain(osdev->dev);
2773 if (domain) {
2774 int attr = 0;
2775 int errno = iommu_domain_get_attr(domain,
2776 DOMAIN_ATTR_S1_BYPASS, &attr);
2777
2778 wlan_smmu_enabled = !errno && !attr;
2779 } else {
2780 cds_info("No SMMU mapping present");
2781 wlan_smmu_enabled = false;
2782 }
2783
2784 if (!wlan_smmu_enabled) {
2785 osdev->smmu_s1_enabled = false;
2786 goto exit_with_success;
2787 }
2788
2789 if (!ipa_present) {
2790 osdev->smmu_s1_enabled = true;
2791 goto exit_with_success;
2792 }
2793
2794 ipa_smmu_enabled = qdf_get_ipa_smmu_enabled();
2795
2796 osdev->smmu_s1_enabled = ipa_smmu_enabled && wlan_smmu_enabled;
2797 if (ipa_smmu_enabled != wlan_smmu_enabled) {
2798 cds_err("SMMU mismatch; IPA:%s, WLAN:%s",
2799 ipa_smmu_enabled ? "enabled" : "disabled",
2800 wlan_smmu_enabled ? "enabled" : "disabled");
2801 return QDF_STATUS_E_FAILURE;
2802 }
2803
2804exit_with_success:
2805 osdev->domain = domain;
2806
2807 cds_info("SMMU S1 %s", osdev->smmu_s1_enabled ? "enabled" : "disabled");
2808
2809 return QDF_STATUS_SUCCESS;
2810}
2811
2812#else
Yun Park45d35972018-03-02 09:57:54 -08002813QDF_STATUS cds_smmu_mem_map_setup(qdf_device_t osdev, bool ipa_present)
Himanshu Agarwaledf30dc2017-06-05 15:54:27 +05302814{
Dustin Brownd0bf6402018-08-03 16:22:56 -07002815 struct dma_iommu_mapping *mapping;
2816 bool ipa_smmu_enabled;
2817 bool wlan_smmu_enabled;
Himanshu Agarwaledf30dc2017-06-05 15:54:27 +05302818
Dustin Brownd0bf6402018-08-03 16:22:56 -07002819 mapping = pld_smmu_get_mapping(osdev->dev);
2820 if (mapping) {
2821 int attr = 0;
2822 int errno = iommu_domain_get_attr(mapping->domain,
2823 DOMAIN_ATTR_S1_BYPASS, &attr);
Himanshu Agarwala89ce242017-11-17 17:36:34 +05302824
Dustin Brownd0bf6402018-08-03 16:22:56 -07002825 wlan_smmu_enabled = !errno && !attr;
Himanshu Agarwala89ce242017-11-17 17:36:34 +05302826 } else {
Dustin Brownd0bf6402018-08-03 16:22:56 -07002827 cds_info("No SMMU mapping present");
2828 wlan_smmu_enabled = false;
Himanshu Agarwaledf30dc2017-06-05 15:54:27 +05302829 }
Dustin Brownd0bf6402018-08-03 16:22:56 -07002830
2831 if (!wlan_smmu_enabled) {
2832 osdev->smmu_s1_enabled = false;
2833 goto exit_with_success;
2834 }
2835
2836 if (!ipa_present) {
2837 osdev->smmu_s1_enabled = true;
2838 goto exit_with_success;
2839 }
2840
2841 ipa_smmu_enabled = qdf_get_ipa_smmu_enabled();
2842
2843 osdev->smmu_s1_enabled = ipa_smmu_enabled && wlan_smmu_enabled;
2844 if (ipa_smmu_enabled != wlan_smmu_enabled) {
2845 cds_err("SMMU mismatch; IPA:%s, WLAN:%s",
2846 ipa_smmu_enabled ? "enabled" : "disabled",
2847 wlan_smmu_enabled ? "enabled" : "disabled");
2848 return QDF_STATUS_E_FAILURE;
2849 }
2850
2851exit_with_success:
Sravan Kumar Kairam5a8c4ba2018-04-12 11:54:31 +05302852 osdev->iommu_mapping = mapping;
Himanshu Agarwaledf30dc2017-06-05 15:54:27 +05302853
Dustin Brownd0bf6402018-08-03 16:22:56 -07002854 cds_info("SMMU S1 %s", osdev->smmu_s1_enabled ? "enabled" : "disabled");
2855
Himanshu Agarwala89ce242017-11-17 17:36:34 +05302856 return QDF_STATUS_SUCCESS;
Himanshu Agarwaledf30dc2017-06-05 15:54:27 +05302857}
Rakshith Suresh Patkar65bdb192019-05-16 12:49:45 +05302858#endif
Himanshu Agarwaledf30dc2017-06-05 15:54:27 +05302859
Sravan Kumar Kairam4329c5f2018-03-02 11:26:29 +05302860#ifdef IPA_OFFLOAD
Himanshu Agarwaledf30dc2017-06-05 15:54:27 +05302861int cds_smmu_map_unmap(bool map, uint32_t num_buf, qdf_mem_info_t *buf_arr)
2862{
Sravan Kumar Kairam983a4452018-03-20 13:30:22 +05302863 return ucfg_ipa_uc_smmu_map(map, num_buf, buf_arr);
Himanshu Agarwaledf30dc2017-06-05 15:54:27 +05302864}
2865#else
Sravan Kumar Kairam4329c5f2018-03-02 11:26:29 +05302866int cds_smmu_map_unmap(bool map, uint32_t num_buf, qdf_mem_info_t *buf_arr)
2867{
2868 return 0;
2869}
2870#endif
2871
2872#else
Rakshith Suresh Patkar65bdb192019-05-16 12:49:45 +05302873#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0))
2874QDF_STATUS cds_smmu_mem_map_setup(qdf_device_t osdev, bool ipa_present)
2875{
2876 osdev->smmu_s1_enabled = false;
2877 osdev->domain = NULL;
2878 return QDF_STATUS_SUCCESS;
2879}
2880#else
Yun Park45d35972018-03-02 09:57:54 -08002881QDF_STATUS cds_smmu_mem_map_setup(qdf_device_t osdev, bool ipa_present)
Himanshu Agarwaledf30dc2017-06-05 15:54:27 +05302882{
Sravan Kumar Kairamb664b6c2018-02-27 17:43:10 +05302883 osdev->smmu_s1_enabled = false;
Himanshu Agarwala89ce242017-11-17 17:36:34 +05302884 return QDF_STATUS_SUCCESS;
Himanshu Agarwaledf30dc2017-06-05 15:54:27 +05302885}
Rakshith Suresh Patkar65bdb192019-05-16 12:49:45 +05302886#endif
Himanshu Agarwaledf30dc2017-06-05 15:54:27 +05302887
2888int cds_smmu_map_unmap(bool map, uint32_t num_buf, qdf_mem_info_t *buf_arr)
2889{
2890 return 0;
2891}
2892#endif