blob: 456c6f7744429e1dafdcae7d1e53c84da4135deb [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
Jeff Johnson30e9bb62018-12-27 20:57:09 -08002 * 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: wlan_hdd_main.c
21 *
22 * WLAN Host Device Driver implementation
23 *
24 */
25
26/* Include Files */
Rakshith Suresh Patkard9f4e612018-09-12 12:10:38 +053027#include <wbuff.h>
Dustin Brown84f46ea2018-02-15 11:57:36 -080028#include "cfg_ucfg_api.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080029#include <wlan_hdd_includes.h>
30#include <cds_api.h>
31#include <cds_sched.h>
Arun Khandavallifae92942016-08-01 13:31:08 +053032#include <linux/cpu.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080033#include <linux/etherdevice.h>
34#include <linux/firmware.h>
35#include <wlan_hdd_tx_rx.h>
36#include <wni_api.h>
37#include <wlan_hdd_cfg.h>
38#include <wlan_ptt_sock_svc.h>
39#include <dbglog_host.h>
40#include <wlan_logging_sock_svc.h>
Qiwei Caiad9b01c2018-07-09 17:21:31 +080041#include <wlan_roam_debug.h>
Dustin Brown6412d1f2019-02-05 14:52:29 -080042#include "osif_sync.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080043#include <wlan_hdd_wowl.h>
44#include <wlan_hdd_misc.h>
45#include <wlan_hdd_wext.h>
46#include "wlan_hdd_trace.h"
47#include "wlan_hdd_ioctl.h"
48#include "wlan_hdd_ftm.h"
49#include "wlan_hdd_power.h"
50#include "wlan_hdd_stats.h"
Prashanth Bhatta527fd752016-04-28 12:35:23 -070051#include "wlan_hdd_scan.h"
Krunal Sonie9c12f52018-10-04 11:45:42 -070052#include "wlan_policy_mgr_ucfg.h"
Naveen Rawate02f8f52018-04-05 11:58:04 -070053#include <wlan_osif_request_manager.h>
Dustin Brown26b3d042017-12-21 11:13:27 -080054#ifdef CONFIG_LEAK_DETECTION
Dustin Brown4bc0a622017-12-06 15:56:50 -080055#include "qdf_debug_domain.h"
Dustin Brown26b3d042017-12-21 11:13:27 -080056#endif
Dustin Brown8d8ab302019-03-05 16:19:36 -080057#include "qdf_delayed_work.h"
Dustin Brown4a93bb52019-03-13 11:46:34 -070058#include "qdf_periodic_work.h"
Dustin Brownd4241942018-02-26 12:51:37 -080059#include "qdf_str.h"
Dustin Brownd315c452018-11-27 11:28:48 -080060#include "qdf_talloc.h"
Dustin Brownd4241942018-02-26 12:51:37 -080061#include "qdf_trace.h"
62#include "qdf_types.h"
Manjunathappa Prakash3454fd62016-04-01 08:52:06 -070063#include <cdp_txrx_peer_ops.h>
Dhanashri Atrea8f82f22017-01-23 12:58:24 -080064#include <cdp_txrx_misc.h>
Mohit Khannaca4173b2017-09-12 21:52:19 -070065#include <cdp_txrx_stats.h>
bings0e03a982018-05-09 08:40:59 +080066#include "cdp_txrx_flow_ctrl_legacy.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080067
68#include <net/addrconf.h>
69#include <linux/wireless.h>
70#include <net/cfg80211.h>
71#include <linux/inetdevice.h>
72#include <net/addrconf.h>
73#include "wlan_hdd_cfg80211.h"
74#include "wlan_hdd_ext_scan.h"
75#include "wlan_hdd_p2p.h"
76#include <linux/rtnetlink.h>
77#include "sap_api.h"
78#include <linux/semaphore.h>
79#include <linux/ctype.h>
80#include <linux/compat.h>
Subrat Dash5f36fbe2019-02-12 16:28:14 +053081#include <linux/ethtool.h>
Tiger Yu8b119e92019-04-09 13:55:07 +080082
83#ifdef WLAN_FEATURE_DP_BUS_BANDWIDTH
84#include "qdf_periodic_work.h"
85#endif
86
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080087#ifdef MSM_PLATFORM
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080088#include <soc/qcom/subsystem_restart.h>
89#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080090#include <wlan_hdd_hostapd.h>
91#include <wlan_hdd_softap_tx_rx.h>
Jeff Johnson8bb61112018-03-31 13:33:54 -070092#include <wlan_hdd_green_ap.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080093#include "qwlan_version.h"
94#include "wma_types.h"
95#include "wlan_hdd_tdls.h"
96#ifdef FEATURE_WLAN_CH_AVOID
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +053097#include "cds_regdomain.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080098#endif /* FEATURE_WLAN_CH_AVOID */
Dustin Brownce46d1d2017-08-15 13:34:24 -070099#include "cdp_txrx_flow_ctrl_v2.h"
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -0700100#include "pld_common.h"
Tushnim Bhattacharyya15596cf2016-02-12 11:57:02 -0800101#include "wlan_hdd_ocb.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800102#include "wlan_hdd_nan.h"
103#include "wlan_hdd_debugfs.h"
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +0530104#include "wlan_hdd_debugfs_csr.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800105#include "wlan_hdd_driver_ops.h"
106#include "epping_main.h"
Poddar, Siddarth34872782017-08-10 14:08:51 +0530107#include "wlan_hdd_data_stall_detection.h"
stonezc9936cb2019-03-11 16:41:22 +0800108#include "wlan_hdd_mpta_helper.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800109
110#include <wlan_hdd_ipa.h>
111#include "hif.h"
112#include "wma.h"
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -0800113#include "wlan_policy_mgr_api.h"
Manikandan Mohandcc21ba2016-03-15 14:31:56 -0700114#include "wlan_hdd_tsf.h"
Komal Seelamec702b02016-02-24 18:42:16 +0530115#include "bmi.h"
Amar Singhale4f28ee2015-10-21 14:36:56 -0700116#include <wlan_hdd_regulatory.h>
Jeff Johnson2b0a7b82016-05-18 15:08:02 -0700117#include "wlan_hdd_lpass.h"
Nachiket Kukade63bb63d2018-11-21 14:42:14 +0530118#include "wlan_nan_api.h"
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -0700119#include <wlan_hdd_napi.h>
Padma, Santhosh Kumard7cc0792016-06-28 18:54:12 +0530120#include "wlan_hdd_disa.h"
Rajeev Kumar97767a02016-11-30 11:20:40 -0800121#include <dispatcher_init_deinit.h>
Rajeev Kumar699debf2017-01-06 14:17:00 -0800122#include "wlan_hdd_object_manager.h"
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +0530123#include "cds_utils.h"
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -0800124#include <cdp_txrx_handle.h>
Sandeep Puligillafdd201e2017-02-02 18:43:46 -0800125#include <qca_vendor.h>
Mukul Sharma9d797a02017-01-05 20:26:03 +0530126#include "wlan_pmo_ucfg_api.h"
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +0530127#include "sir_api.h"
Naveen Rawat910726a2017-03-06 11:42:51 -0800128#include "os_if_wifi_pos.h"
129#include "wifi_pos_api.h"
130#include "wlan_hdd_oemdata.h"
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -0800131#include "wlan_hdd_he.h"
Naveen Rawatcb5c5402017-03-22 10:12:19 -0700132#include "os_if_nan.h"
133#include "nan_public_structs.h"
Nachiket Kukade85aa3782018-11-02 20:12:34 +0530134#include "nan_ucfg_api.h"
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -0700135#include "wlan_reg_ucfg_api.h"
bings81fe50a2017-11-27 14:33:26 +0800136#include "wlan_dfs_ucfg_api.h"
Ravi Joshi4f095952017-06-29 15:39:19 -0700137#include "wlan_hdd_rx_monitor.h"
Mukul Sharmad16c2022017-07-25 18:56:12 +0530138#include "sme_power_save_api.h"
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +0530139#include "enet.h"
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -0700140#include <cdp_txrx_cmn_struct.h>
Mohit Khanna70322002018-05-15 19:21:32 -0700141#include <dp_txrx.h>
Amar Singhal0928b192017-12-01 10:50:54 -0800142#include "wlan_hdd_sysfs.h"
Nachiket Kukade98f562a2017-12-15 12:18:07 +0530143#include "wlan_disa_ucfg_api.h"
Wu Gao52084c12018-05-17 20:47:11 +0800144#include "wlan_disa_obj_mgmt_api.h"
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +0530145#include "wlan_action_oui_ucfg_api.h"
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +0530146#include "wlan_ipa_ucfg_api.h"
Arunk Khandavallia6305a32018-01-25 11:19:18 +0530147#include <target_if.h>
Alok Kumarb64650c2018-03-23 17:05:11 +0530148#include "wlan_hdd_nud_tracking.h"
Nachiket Kukaded0dd62e2018-05-21 18:39:22 +0530149#include "wlan_hdd_apf.h"
Varun Reddy Yeturue93d2462018-05-22 13:54:52 -0700150#include "wlan_hdd_twt.h"
Rachit Kankane0dc3e852018-05-07 17:33:42 +0530151#include "qc_sap_ioctl.h"
Sandeep Puligillac5609d52018-05-17 19:23:41 -0700152#include "wlan_mlme_main.h"
Wu Gaoe5689792018-07-05 19:20:13 +0800153#include "wlan_p2p_cfg_api.h"
Wu Gao637d58a2018-12-08 10:37:34 +0800154#include "wlan_cfg80211_p2p.h"
Paul Zhang37185672019-05-14 11:20:14 +0800155#include "wlan_cfg80211_interop_issues_ap.h"
Wu Gaobdb7f272018-07-05 19:33:26 +0800156#include "wlan_tdls_cfg_api.h"
Qiwei Caie689a262018-07-26 15:50:22 +0800157#include <wlan_hdd_rssi_monitor.h>
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +0530158#include "wlan_mlme_ucfg_api.h"
Sourav Mohapatra113685f2018-08-29 14:21:55 +0530159#include "wlan_fwol_ucfg_api.h"
Krunal Sonie71838d2018-09-27 10:45:05 -0700160#include "wlan_policy_mgr_ucfg.h"
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530161#ifdef CNSS_GENL
162#include <net/cnss_nl.h>
163#endif
Amar Singhal5cccafe2017-02-15 12:42:58 -0800164#include "wlan_reg_ucfg_api.h"
Zhang Qian47e22ce2018-01-04 15:38:38 +0800165#include "wlan_ocb_ucfg_api.h"
Sandeep Puligilla019a1bd2018-02-04 22:57:44 -0800166#include <wlan_hdd_spectralscan.h>
gaurank kathpalia4a205fc2018-09-15 00:59:15 +0530167#include "wlan_green_ap_ucfg_api.h"
Liangwei Dong3abfe8f2018-09-20 02:25:44 -0400168#include <wlan_p2p_ucfg_api.h>
Paul Zhang37185672019-05-14 11:20:14 +0800169#include <wlan_interop_issues_ap_ucfg_api.h>
Mohit Khanna81418772018-10-30 14:14:46 -0700170#include <target_type.h>
Arun Kumar Khandavallideda5a82019-03-11 15:32:19 +0530171#include <wlan_hdd_debugfs_coex.h>
gaurank kathpalia3ebc17b2019-05-29 10:25:09 +0530172#include "wlan_blm_ucfg_api.h"
Tiger Yue40e7832019-04-25 10:46:53 +0800173#include "ol_txrx.h"
Liangwei Dong3abfe8f2018-09-20 02:25:44 -0400174
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800175#ifdef MODULE
176#define WLAN_MODULE_NAME module_name(THIS_MODULE)
177#else
178#define WLAN_MODULE_NAME "wlan"
179#endif
180
181#ifdef TIMER_MANAGER
182#define TIMER_MANAGER_STR " +TIMER_MANAGER"
183#else
184#define TIMER_MANAGER_STR ""
185#endif
186
187#ifdef MEMORY_DEBUG
188#define MEMORY_DEBUG_STR " +MEMORY_DEBUG"
189#else
190#define MEMORY_DEBUG_STR ""
191#endif
192
Dustin Brownc1034df2018-02-07 14:51:32 -0800193#ifdef PANIC_ON_BUG
194#define PANIC_ON_BUG_STR " +PANIC_ON_BUG"
195#else
196#define PANIC_ON_BUG_STR ""
197#endif
198
Sachin Ahujadddd2632017-03-07 19:07:24 +0530199int wlan_start_ret_val;
200static DECLARE_COMPLETION(wlan_start_comp);
201static unsigned int dev_num = 1;
202static struct cdev wlan_hdd_state_cdev;
203static struct class *class;
204static dev_t device;
Arun Khandavallifae92942016-08-01 13:31:08 +0530205#ifndef MODULE
206static struct gwlan_loader *wlan_loader;
207static ssize_t wlan_boot_cb(struct kobject *kobj,
208 struct kobj_attribute *attr,
209 const char *buf, size_t count);
210struct gwlan_loader {
211 bool loaded_state;
212 struct kobject *boot_wlan_obj;
213 struct attribute_group *attr_group;
214};
215
216static struct kobj_attribute wlan_boot_attribute =
217 __ATTR(boot_wlan, 0220, NULL, wlan_boot_cb);
218
219static struct attribute *attrs[] = {
220 &wlan_boot_attribute.attr,
221 NULL,
222};
223
224#define MODULE_INITIALIZED 1
Qun Zhang4a83a462018-09-11 16:28:51 +0800225
226#ifdef MULTI_IF_NAME
227#define WLAN_LOADER_NAME "boot_" MULTI_IF_NAME
228#else
229#define WLAN_LOADER_NAME "boot_wlan"
230#endif
Arun Khandavallifae92942016-08-01 13:31:08 +0530231#endif
232
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800233/* the Android framework expects this param even though we don't use it */
234#define BUF_LEN 20
235static char fwpath_buffer[BUF_LEN];
236static struct kparam_string fwpath = {
237 .string = fwpath_buffer,
238 .maxlen = BUF_LEN,
239};
240
241static char *country_code;
242static int enable_11d = -1;
243static int enable_dfs_chan_scan = -1;
Rajeev Kumar588a2542019-04-08 10:57:19 -0700244static bool is_mode_change_psoc_idle_shutdown;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800245
Rajeev Kumar8e3e2832015-11-06 16:02:54 -0800246#define WLAN_NLINK_CESIUM 30
247
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530248static qdf_wake_lock_t wlan_wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800249
250#define WOW_MAX_FILTER_LISTS 1
251#define WOW_MAX_FILTERS_PER_LIST 4
252#define WOW_MIN_PATTERN_SIZE 6
253#define WOW_MAX_PATTERN_SIZE 64
254
Bala Venkatesh110b03e2018-07-10 16:02:08 +0530255/* max peer can be tdls peers + self peer + bss peer */
256#define HDD_MAX_VDEV_PEER_COUNT (HDD_MAX_NUM_TDLS_STA + 2)
Sourav Mohapatra808e3d42018-07-04 09:34:23 +0530257#define IS_IDLE_STOP (!cds_is_driver_unloading() && \
258 !cds_is_driver_recovering() && !cds_is_driver_loading())
Bala Venkatesh110b03e2018-07-10 16:02:08 +0530259
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800260#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
261static const struct wiphy_wowlan_support wowlan_support_reg_init = {
262 .flags = WIPHY_WOWLAN_ANY |
263 WIPHY_WOWLAN_MAGIC_PKT |
264 WIPHY_WOWLAN_DISCONNECT |
265 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
266 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
267 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
268 WIPHY_WOWLAN_4WAY_HANDSHAKE |
269 WIPHY_WOWLAN_RFKILL_RELEASE,
270 .n_patterns = WOW_MAX_FILTER_LISTS * WOW_MAX_FILTERS_PER_LIST,
271 .pattern_min_len = WOW_MIN_PATTERN_SIZE,
272 .pattern_max_len = WOW_MAX_PATTERN_SIZE,
273};
274#endif
275
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700276static const struct category_info cinfo[MAX_SUPPORTED_CATEGORY] = {
277 [QDF_MODULE_ID_TLSHIM] = {QDF_TRACE_LEVEL_ALL},
278 [QDF_MODULE_ID_WMI] = {QDF_TRACE_LEVEL_ALL},
279 [QDF_MODULE_ID_HTT] = {QDF_TRACE_LEVEL_ALL},
280 [QDF_MODULE_ID_HDD] = {QDF_TRACE_LEVEL_ALL},
281 [QDF_MODULE_ID_SME] = {QDF_TRACE_LEVEL_ALL},
282 [QDF_MODULE_ID_PE] = {QDF_TRACE_LEVEL_ALL},
283 [QDF_MODULE_ID_WMA] = {QDF_TRACE_LEVEL_ALL},
284 [QDF_MODULE_ID_SYS] = {QDF_TRACE_LEVEL_ALL},
285 [QDF_MODULE_ID_QDF] = {QDF_TRACE_LEVEL_ALL},
286 [QDF_MODULE_ID_SAP] = {QDF_TRACE_LEVEL_ALL},
287 [QDF_MODULE_ID_HDD_SOFTAP] = {QDF_TRACE_LEVEL_ALL},
288 [QDF_MODULE_ID_HDD_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
289 [QDF_MODULE_ID_HDD_SAP_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
290 [QDF_MODULE_ID_HIF] = {QDF_DATA_PATH_TRACE_LEVEL},
291 [QDF_MODULE_ID_HTC] = {QDF_DATA_PATH_TRACE_LEVEL},
292 [QDF_MODULE_ID_TXRX] = {QDF_DATA_PATH_TRACE_LEVEL},
293 [QDF_MODULE_ID_QDF_DEVICE] = {QDF_TRACE_LEVEL_ALL},
294 [QDF_MODULE_ID_CFG] = {QDF_TRACE_LEVEL_ALL},
295 [QDF_MODULE_ID_BMI] = {QDF_TRACE_LEVEL_ALL},
296 [QDF_MODULE_ID_EPPING] = {QDF_TRACE_LEVEL_ALL},
297 [QDF_MODULE_ID_QVIT] = {QDF_TRACE_LEVEL_ALL},
298 [QDF_MODULE_ID_DP] = {QDF_TRACE_LEVEL_ALL},
299 [QDF_MODULE_ID_SOC] = {QDF_TRACE_LEVEL_ALL},
300 [QDF_MODULE_ID_OS_IF] = {QDF_TRACE_LEVEL_ALL},
301 [QDF_MODULE_ID_TARGET_IF] = {QDF_TRACE_LEVEL_ALL},
302 [QDF_MODULE_ID_SCHEDULER] = {QDF_TRACE_LEVEL_ALL},
303 [QDF_MODULE_ID_MGMT_TXRX] = {QDF_TRACE_LEVEL_ALL},
304 [QDF_MODULE_ID_PMO] = {QDF_TRACE_LEVEL_ALL},
305 [QDF_MODULE_ID_SCAN] = {QDF_TRACE_LEVEL_ALL},
306 [QDF_MODULE_ID_POLICY_MGR] = {QDF_TRACE_LEVEL_ALL},
307 [QDF_MODULE_ID_P2P] = {QDF_TRACE_LEVEL_ALL},
308 [QDF_MODULE_ID_TDLS] = {QDF_TRACE_LEVEL_ALL},
309 [QDF_MODULE_ID_REGULATORY] = {QDF_TRACE_LEVEL_ALL},
310 [QDF_MODULE_ID_SERIALIZATION] = {QDF_TRACE_LEVEL_ALL},
Arif Hussainfde76e72017-09-05 16:58:23 -0700311 [QDF_MODULE_ID_DFS] = {QDF_TRACE_LEVEL_ALL},
Rajeev Kumarca8ef9d2017-10-06 10:43:21 -0700312 [QDF_MODULE_ID_OBJ_MGR] = {QDF_TRACE_LEVEL_ALL},
Deepak Dhamdheref918d422017-07-06 12:56:29 -0700313 [QDF_MODULE_ID_ROAM_DEBUG] = {QDF_TRACE_LEVEL_ALL},
Himanshu Agarwalb229a142017-12-21 10:16:45 +0530314 [QDF_MODULE_ID_GREEN_AP] = {QDF_TRACE_LEVEL_ALL},
Zhang Qian47e22ce2018-01-04 15:38:38 +0800315 [QDF_MODULE_ID_OCB] = {QDF_TRACE_LEVEL_ALL},
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530316 [QDF_MODULE_ID_IPA] = {QDF_TRACE_LEVEL_ALL},
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +0530317 [QDF_MODULE_ID_ACTION_OUI] = {QDF_TRACE_LEVEL_ALL},
Dustin Brown84f46ea2018-02-15 11:57:36 -0800318 [QDF_MODULE_ID_CONFIG] = {QDF_TRACE_LEVEL_ALL},
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +0530319 [QDF_MODULE_ID_MLME] = {QDF_TRACE_LEVEL_ALL},
Ashish Kumar Dhanotiya8d039c82018-07-11 20:41:14 +0530320 [QDF_MODULE_ID_TARGET] = {QDF_TRACE_LEVEL_ALL},
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -0700321 [QDF_MODULE_ID_CRYPTO] = {QDF_TRACE_LEVEL_ALL},
Sourav Mohapatra113685f2018-08-29 14:21:55 +0530322 [QDF_MODULE_ID_FWOL] = {QDF_TRACE_LEVEL_ALL},
Abhishek Singh0b0105f2018-09-25 10:44:16 +0530323 [QDF_MODULE_ID_SM_ENGINE] = {QDF_TRACE_LEVEL_ALL},
324 [QDF_MODULE_ID_CMN_MLME] = {QDF_TRACE_LEVEL_ALL},
Nachiket Kukade089b9832018-12-12 16:38:17 +0530325 [QDF_MODULE_ID_NAN] = {QDF_TRACE_LEVEL_ALL},
Ashish Kumar Dhanotiya6ed44342019-02-07 21:11:00 +0530326 [QDF_MODULE_ID_CP_STATS] = {QDF_TRACE_LEVEL_ALL},
Paul Zhang37185672019-05-14 11:20:14 +0800327 [QDF_MODULE_ID_INTEROP_ISSUES_AP] = {QDF_TRACE_LEVEL_ALL},
gaurank kathpalia7ef72182019-05-29 19:41:25 +0530328 [QDF_MODULE_ID_BLACKLIST_MGR] = {QDF_TRACE_LEVEL_ALL},
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700329};
330
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +0530331struct notifier_block hdd_netdev_notifier;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800332
333struct sock *cesium_nl_srv_sock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800334#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700335static void wlan_hdd_auto_shutdown_cb(void);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800336#endif
337
Sachin Ahujadddd2632017-03-07 19:07:24 +0530338void hdd_start_complete(int ret)
339{
340 wlan_start_ret_val = ret;
341
342 complete(&wlan_start_comp);
343}
344
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800345/**
Nirav Shahbd36b062016-07-18 11:12:59 +0530346 * hdd_set_rps_cpu_mask - set RPS CPU mask for interfaces
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700347 * @hdd_ctx: pointer to struct hdd_context
Nirav Shahbd36b062016-07-18 11:12:59 +0530348 *
349 * Return: none
350 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700351static void hdd_set_rps_cpu_mask(struct hdd_context *hdd_ctx)
Nirav Shahbd36b062016-07-18 11:12:59 +0530352{
Jeff Johnson9d295242017-08-29 14:39:48 -0700353 struct hdd_adapter *adapter;
Nirav Shahbd36b062016-07-18 11:12:59 +0530354
Dustin Brown920397d2017-12-13 16:27:50 -0800355 hdd_for_each_adapter(hdd_ctx, adapter)
356 hdd_send_rps_ind(adapter);
Nirav Shahbd36b062016-07-18 11:12:59 +0530357}
358
Ajit Pal Singh106c1412018-04-18 18:08:49 +0530359#ifdef QCA_HL_NETDEV_FLOW_CONTROL
360void wlan_hdd_mod_fc_timer(struct hdd_adapter *adapter,
361 enum netif_action_type action)
362{
363 if (!adapter->tx_flow_timer_initialized)
364 return;
365
366 if (action == WLAN_WAKE_NON_PRIORITY_QUEUE) {
367 qdf_mc_timer_stop(&adapter->tx_flow_control_timer);
Ajit Pal Singhe6da1de2018-12-27 16:20:45 +0530368 adapter->hdd_stats.tx_rx_stats.is_txflow_paused = false;
369 adapter->hdd_stats.tx_rx_stats.txflow_unpause_cnt++;
Ajit Pal Singh106c1412018-04-18 18:08:49 +0530370 } else if (action == WLAN_STOP_NON_PRIORITY_QUEUE) {
371 QDF_STATUS status =
372 qdf_mc_timer_start(&adapter->tx_flow_control_timer,
373 WLAN_HDD_TX_FLOW_CONTROL_OS_Q_BLOCK_TIME);
374
375 if (!QDF_IS_STATUS_SUCCESS(status))
376 hdd_err("Failed to start tx_flow_control_timer");
377 else
378 adapter->
379 hdd_stats.tx_rx_stats.txflow_timer_cnt++;
380
381 adapter->hdd_stats.tx_rx_stats.txflow_pause_cnt++;
382 adapter->hdd_stats.tx_rx_stats.is_txflow_paused = true;
383 }
384}
385#endif /* QCA_HL_NETDEV_FLOW_CONTROL */
386
Tiger Yu8b119e92019-04-09 13:55:07 +0800387#ifdef WLAN_FEATURE_DP_BUS_BANDWIDTH
Alok Kumar2fad6442018-11-08 19:19:28 +0530388void wlan_hdd_update_tcp_rx_param(struct hdd_context *hdd_ctx, void *data)
389{
390 if (!hdd_ctx) {
391 hdd_err("HDD context is null");
392 return;
393 }
394
395 if (!data) {
396 hdd_err("Data is null");
397 return;
398 }
399 if (hdd_ctx->config->enable_tcp_param_update)
400 wlan_hdd_send_tcp_param_update_event(hdd_ctx, data, 1);
401 else
402 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
403 WLAN_SVC_WLAN_TP_IND,
404 data,
405 sizeof(struct wlan_rx_tp_data));
406}
407
408void wlan_hdd_update_tcp_tx_param(struct hdd_context *hdd_ctx, void *data)
409{
410 enum wlan_tp_level next_tx_level;
411 struct wlan_tx_tp_data *tx_tp_data;
412
413 if (!hdd_ctx) {
414 hdd_err("HDD context is null");
415 return;
416 }
417
418 if (!data) {
419 hdd_err("Data is null");
420 return;
421 }
422
423 tx_tp_data = (struct wlan_tx_tp_data *)data;
424 next_tx_level = tx_tp_data->level;
425
426 if (hdd_ctx->config->enable_tcp_param_update)
427 wlan_hdd_send_tcp_param_update_event(hdd_ctx, data, 0);
428 else
429 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
430 WLAN_SVC_WLAN_TP_TX_IND,
431 &next_tx_level,
432 sizeof(next_tx_level));
433}
434
435/**
436 * wlan_hdd_send_tcp_param_update_event() - Send vendor event to update
437 * TCP parameter through Wi-Fi HAL
438 * @hdd_ctx: Pointer to HDD context
439 * @data: Parameters to update
440 * @dir: Direction(tx/rx) to update
441 *
442 * Return: None
443 */
444void wlan_hdd_send_tcp_param_update_event(struct hdd_context *hdd_ctx,
445 void *data,
446 uint8_t dir)
447{
448 struct sk_buff *vendor_event;
449 uint32_t event_len;
450 bool tcp_limit_output = false;
451 bool tcp_del_ack_ind_enabled = false;
452 bool tcp_adv_win_scl_enabled = false;
453 enum wlan_tp_level next_tp_level = WLAN_SVC_TP_NONE;
454
455 event_len = sizeof(uint8_t) + sizeof(uint8_t) + NLMSG_HDRLEN;
456
457 if (dir == 0) /*TX Flow */ {
458 struct wlan_tx_tp_data *tx_tp_data =
459 (struct wlan_tx_tp_data *)data;
460
461 next_tp_level = tx_tp_data->level;
462
463 if (tx_tp_data->tcp_limit_output) {
464 /* TCP_LIMIT_OUTPUT_BYTES */
465 event_len += sizeof(uint32_t);
466 tcp_limit_output = true;
467 }
468 } else if (dir == 1) /* RX Flow */ {
469 struct wlan_rx_tp_data *rx_tp_data =
470 (struct wlan_rx_tp_data *)data;
471
472 next_tp_level = rx_tp_data->level;
473
474 if (rx_tp_data->rx_tp_flags & TCP_DEL_ACK_IND_MASK) {
475 event_len += sizeof(uint32_t); /* TCP_DELACK_SEG */
476 tcp_del_ack_ind_enabled = true;
477 }
478 if (rx_tp_data->rx_tp_flags & TCP_ADV_WIN_SCL_MASK) {
479 event_len += sizeof(uint32_t); /* TCP_ADV_WIN_SCALE */
480 tcp_adv_win_scl_enabled = true;
481 }
482 } else {
483 hdd_err("Invalid Direction [%d]", dir);
484 return;
485 }
486
487 vendor_event =
488 cfg80211_vendor_event_alloc(
489 hdd_ctx->wiphy,
490 NULL, event_len,
491 QCA_NL80211_VENDOR_SUBCMD_THROUGHPUT_CHANGE_EVENT_INDEX,
492 GFP_KERNEL);
493
494 if (!vendor_event) {
495 hdd_err("cfg80211_vendor_event_alloc failed");
496 return;
497 }
498
499 if (nla_put_u8(
500 vendor_event,
501 QCA_WLAN_VENDOR_ATTR_THROUGHPUT_CHANGE_DIRECTION,
502 dir))
503 goto tcp_param_change_nla_failed;
504
505 if (nla_put_u8(
506 vendor_event,
507 QCA_WLAN_VENDOR_ATTR_THROUGHPUT_CHANGE_THROUGHPUT_LEVEL,
508 (next_tp_level == WLAN_SVC_TP_LOW ?
509 QCA_WLAN_THROUGHPUT_LEVEL_LOW :
510 QCA_WLAN_THROUGHPUT_LEVEL_HIGH)))
511 goto tcp_param_change_nla_failed;
512
513 if (tcp_limit_output &&
514 nla_put_u32(
515 vendor_event,
516 QCA_WLAN_VENDOR_ATTR_THROUGHPUT_CHANGE_TCP_LIMIT_OUTPUT_BYTES,
517 (next_tp_level == WLAN_SVC_TP_LOW ?
518 TCP_LIMIT_OUTPUT_BYTES_LOW :
519 TCP_LIMIT_OUTPUT_BYTES_HI)))
520 goto tcp_param_change_nla_failed;
521
522 if (tcp_del_ack_ind_enabled &&
523 (nla_put_u32(
524 vendor_event,
525 QCA_WLAN_VENDOR_ATTR_THROUGHPUT_CHANGE_TCP_DELACK_SEG,
526 (next_tp_level == WLAN_SVC_TP_LOW ?
527 TCP_DEL_ACK_LOW : TCP_DEL_ACK_HI))))
528 goto tcp_param_change_nla_failed;
529
530 if (tcp_adv_win_scl_enabled &&
531 (nla_put_u32(
532 vendor_event,
533 QCA_WLAN_VENDOR_ATTR_THROUGHPUT_CHANGE_TCP_ADV_WIN_SCALE,
534 (next_tp_level == WLAN_SVC_TP_LOW ?
535 WIN_SCALE_LOW : WIN_SCALE_HI))))
536 goto tcp_param_change_nla_failed;
537
538 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
539 return;
540
541tcp_param_change_nla_failed:
542 hdd_err("nla_put api failed");
543 kfree_skb(vendor_event);
544}
Tiger Yu8b119e92019-04-09 13:55:07 +0800545#endif /*WLAN_FEATURE_DP_BUS_BANDWIDTH*/
Alok Kumar2fad6442018-11-08 19:19:28 +0530546
Nirav Shahbd36b062016-07-18 11:12:59 +0530547/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800548 * wlan_hdd_txrx_pause_cb() - pause callback from txrx layer
549 * @vdev_id: vdev_id
550 * @action: action type
551 * @reason: reason type
552 *
553 * Return: none
554 */
555void wlan_hdd_txrx_pause_cb(uint8_t vdev_id,
556 enum netif_action_type action, enum netif_reason_type reason)
557{
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700558 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Jeff Johnson9d295242017-08-29 14:39:48 -0700559 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800560
561 if (!hdd_ctx) {
562 hdd_err("hdd ctx is NULL");
563 return;
564 }
565 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
Ajit Pal Singh106c1412018-04-18 18:08:49 +0530566 wlan_hdd_mod_fc_timer(adapter, action);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800567 wlan_hdd_netif_queue_control(adapter, action, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800568}
569
570/*
Dustin Brownab482ac2017-06-09 17:00:44 -0700571 * Store WLAN driver version and timestamp info in global variables such that
572 * crash debugger can extract them from driver debug symbol and crashdump for
573 * post processing
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800574 */
Dustin Brown96cd9632017-11-13 12:45:04 -0800575#ifdef BUILD_TAG
Rajeev Kumare555e2d2018-09-17 11:52:37 -0700576uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR TIMER_MANAGER_STR MEMORY_DEBUG_STR PANIC_ON_BUG_STR "; " BUILD_TAG;
Dustin Brown96cd9632017-11-13 12:45:04 -0800577#else
Rajeev Kumare555e2d2018-09-17 11:52:37 -0700578uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR TIMER_MANAGER_STR MEMORY_DEBUG_STR PANIC_ON_BUG_STR;
Naveen Rawat93836252017-06-20 16:30:59 -0700579#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800580
581/**
Liangwei Dong17bf2662018-01-05 02:02:05 -0500582 * hdd_get_valid_chan() - return current chan list from regulatory.
583 * @hdd_ctx: HDD context
584 * @chan_list: buf hold returned chan list
585 * @chan_num: input buf size and output returned chan num
586 *
587 * This function helps get current available chan list from regulatory
588 * module. It excludes the "disabled" and "invalid" channels.
589 *
590 * Return: 0 for success.
591 */
592static int hdd_get_valid_chan(struct hdd_context *hdd_ctx,
593 uint8_t *chan_list,
594 uint32_t *chan_num)
595{
596 int i = 0, j = 0;
597 struct regulatory_channel *cur_chan_list;
598 struct wlan_objmgr_pdev *pdev;
599
Dustin Brown07901ec2018-09-07 11:02:41 -0700600 if (!hdd_ctx || !hdd_ctx->pdev || !chan_list || !chan_num)
Liangwei Dong17bf2662018-01-05 02:02:05 -0500601 return -EINVAL;
602
Dustin Brown07901ec2018-09-07 11:02:41 -0700603 pdev = hdd_ctx->pdev;
Liangwei Dong17bf2662018-01-05 02:02:05 -0500604 cur_chan_list = qdf_mem_malloc(NUM_CHANNELS *
605 sizeof(struct regulatory_channel));
606 if (!cur_chan_list)
607 return -ENOMEM;
608
609 if (wlan_reg_get_current_chan_list(pdev, cur_chan_list) !=
610 QDF_STATUS_SUCCESS) {
611 qdf_mem_free(cur_chan_list);
612 return -EINVAL;
613 }
614
615 for (i = 0; i < NUM_CHANNELS; i++) {
616 uint32_t ch = cur_chan_list[i].chan_num;
617 enum channel_state state = wlan_reg_get_channel_state(pdev,
618 ch);
619
620 if (state != CHANNEL_STATE_DISABLE &&
621 state != CHANNEL_STATE_INVALID &&
622 j < *chan_num) {
623 chan_list[j] = (uint8_t)ch;
624 j++;
625 }
626 }
627 *chan_num = j;
628 qdf_mem_free(cur_chan_list);
629 return 0;
630}
631
632/**
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530633 * hdd_validate_channel_and_bandwidth() - Validate the channel-bandwidth combo
634 * @adapter: HDD adapter
635 * @chan_number: Channel number
636 * @chan_bw: Bandwidth
637 *
638 * Checks if the given bandwidth is valid for the given channel number.
639 *
640 * Return: 0 for success, non-zero for failure
641 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700642int hdd_validate_channel_and_bandwidth(struct hdd_adapter *adapter,
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530643 uint32_t chan_number,
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800644 enum phy_ch_width chan_bw)
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530645{
Liangwei Dong17bf2662018-01-05 02:02:05 -0500646 uint8_t chan[NUM_CHANNELS];
647 uint32_t len = NUM_CHANNELS, i;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530648 bool found = false;
Jeff Johnson16528362018-06-14 12:34:16 -0700649 mac_handle_t mac_handle;
Liangwei Dong17bf2662018-01-05 02:02:05 -0500650 int ret;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530651
Jeff Johnson16528362018-06-14 12:34:16 -0700652 mac_handle = hdd_adapter_get_mac_handle(adapter);
653 if (!mac_handle) {
654 hdd_err("Invalid MAC handle");
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530655 return -EINVAL;
656 }
657
Liangwei Dong17bf2662018-01-05 02:02:05 -0500658 ret = hdd_get_valid_chan(adapter->hdd_ctx, chan,
659 &len);
660 if (ret) {
661 hdd_err("error %d in getting valid channel list", ret);
662 return ret;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530663 }
664
665 for (i = 0; i < len; i++) {
666 if (chan[i] == chan_number) {
667 found = true;
668 break;
669 }
670 }
671
672 if (found == false) {
673 hdd_err("Channel not in driver's valid channel list");
674 return -EOPNOTSUPP;
675 }
676
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700677 if ((!WLAN_REG_IS_24GHZ_CH(chan_number)) &&
678 (!WLAN_REG_IS_5GHZ_CH(chan_number))) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530679 hdd_err("CH %d is not in 2.4GHz or 5GHz", chan_number);
680 return -EINVAL;
681 }
682
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700683 if (WLAN_REG_IS_24GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530684 if (chan_bw == CH_WIDTH_80MHZ) {
685 hdd_err("BW80 not possible in 2.4GHz band");
686 return -EINVAL;
687 }
688 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 14) &&
689 (chan_bw != CH_WIDTH_MAX)) {
690 hdd_err("Only BW20 possible on channel 14");
691 return -EINVAL;
692 }
693 }
694
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530695 return 0;
696}
697
Will Huang79af29f2019-04-11 15:46:26 +0800698uint8_t hdd_get_adapter_home_channel(struct hdd_adapter *adapter)
699{
700 uint8_t home_channel = 0;
701
702 if ((adapter->device_mode == QDF_SAP_MODE ||
703 adapter->device_mode == QDF_P2P_GO_MODE) &&
704 test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
705 home_channel = adapter->session.ap.operating_channel;
706 } else if ((adapter->device_mode == QDF_STA_MODE ||
707 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
708 adapter->session.station.conn_info.conn_state ==
709 eConnectionState_Associated) {
710 home_channel =
711 adapter->session.station.conn_info.channel;
712 }
713
714 return home_channel;
715}
716
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800717#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
Dustin Brown98f7c822019-03-06 12:25:49 -0800718static inline struct net_device *hdd_net_dev_from_notifier(void *context)
719{
720 struct netdev_notifier_info *info = context;
721
722 return info->dev;
723}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800724#else
Dustin Brown98f7c822019-03-06 12:25:49 -0800725static inline struct net_device *hdd_net_dev_from_notifier(void *context)
726{
727 return context;
728}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800729#endif
Dustin Brown98f7c822019-03-06 12:25:49 -0800730
731static int __hdd_netdev_notifier_call(struct net_device *net_dev,
732 unsigned long state)
733{
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530734 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700735 struct hdd_context *hdd_ctx;
Min Liu8c5d99e2018-09-10 17:18:44 +0800736 struct wlan_objmgr_vdev *vdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800737
Dustin Brown98f7c822019-03-06 12:25:49 -0800738 hdd_enter_dev(net_dev);
Jeff Johnson3c3994a2016-02-11 08:12:30 -0800739
Dustin Brown98f7c822019-03-06 12:25:49 -0800740 if (!net_dev->ieee80211_ptr) {
Dustin Brownaeb55642018-07-30 17:20:32 -0700741 hdd_debug("ieee80211_ptr is null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800742 return NOTIFY_DONE;
743 }
744
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530745 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
746 if (!hdd_ctx) {
747 hdd_err("HDD Context is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800748 return NOTIFY_DONE;
749 }
Jingxiang Ge9db9d232017-10-14 17:22:15 +0800750
751 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -0700752 hdd_debug("%s: Driver module is closed", __func__);
Jingxiang Ge9db9d232017-10-14 17:22:15 +0800753 return NOTIFY_DONE;
754 }
755
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530756 /* Make sure that this callback corresponds to our device. */
Dustin Brown98f7c822019-03-06 12:25:49 -0800757 adapter = hdd_get_adapter_by_iface_name(hdd_ctx, net_dev->name);
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530758 if (!adapter) {
Dustin Brown98f7c822019-03-06 12:25:49 -0800759 hdd_debug("failed to look up adapter for '%s'", net_dev->name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800760 return NOTIFY_DONE;
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530761 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800762
Dustin Brown98f7c822019-03-06 12:25:49 -0800763 if (adapter != WLAN_HDD_GET_PRIV_PTR(net_dev)) {
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530764 hdd_err("HDD adapter mismatch!");
765 return NOTIFY_DONE;
766 }
767
Dustin Brownaeb55642018-07-30 17:20:32 -0700768 if (cds_is_driver_recovering()) {
769 hdd_debug("Driver is recovering");
770 return NOTIFY_DONE;
771 }
772
773 if (cds_is_driver_in_bad_state()) {
774 hdd_debug("Driver is in failed recovery state");
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530775 return NOTIFY_DONE;
776 }
777
Dustin Brown98f7c822019-03-06 12:25:49 -0800778 hdd_debug("%s New Net Device State = %lu", net_dev->name, state);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800779
780 switch (state) {
781 case NETDEV_REGISTER:
782 break;
783
784 case NETDEV_UNREGISTER:
785 break;
786
787 case NETDEV_UP:
Jeff Johnson16528362018-06-14 12:34:16 -0700788 sme_ch_avoid_update_req(hdd_ctx->mac_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800789 break;
790
791 case NETDEV_DOWN:
792 break;
793
794 case NETDEV_CHANGE:
Jeff Johnsonc72c5732017-10-28 12:49:37 -0700795 if (adapter->is_link_up_service_needed)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800796 complete(&adapter->linkup_event_var);
797 break;
798
799 case NETDEV_GOING_DOWN:
Min Liu8c5d99e2018-09-10 17:18:44 +0800800 vdev = hdd_objmgr_get_vdev(adapter);
801 if (!vdev)
802 break;
803 if (ucfg_scan_get_vdev_status(vdev) !=
Sandeep Puligilla5f86d992017-10-29 14:58:53 -0700804 SCAN_NOT_IN_PROGRESS) {
Dustin Brown07901ec2018-09-07 11:02:41 -0700805 wlan_abort_scan(hdd_ctx->pdev, INVAL_PDEV_ID,
Jeff Johnson5a6fc962019-02-04 14:20:25 -0800806 adapter->vdev_id, INVALID_SCAN_ID,
Dustin Brown07901ec2018-09-07 11:02:41 -0700807 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800808 }
Rajeev Kumar Sirasanagandla25bdfad2019-02-15 19:15:49 +0530809 hdd_objmgr_put_vdev(vdev);
Min Liu9be5d4a2018-05-17 11:51:53 +0800810 cds_flush_work(&adapter->scan_block_work);
811 /* Need to clean up blocked scan request */
Dustin Brown96b98dd2019-03-06 12:39:37 -0800812 wlan_hdd_cfg80211_scan_block(adapter);
Min Liu9be5d4a2018-05-17 11:51:53 +0800813 hdd_debug("Scan is not Pending from user");
Arunk Khandavallif0c0d762017-12-07 10:18:50 +0530814 /*
815 * After NETDEV_GOING_DOWN, kernel calls hdd_stop.Irrespective
816 * of return status of hdd_stop call, kernel resets the IFF_UP
817 * flag after which driver does not send the cfg80211_scan_done.
818 * Ensure to cleanup the scan queue in NETDEV_GOING_DOWN
819 */
Dustin Brown98f7c822019-03-06 12:25:49 -0800820 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->pdev, net_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800821 break;
822
823 default:
824 break;
825 }
826
827 return NOTIFY_DONE;
828}
829
830/**
831 * hdd_netdev_notifier_call() - netdev notifier callback function
832 * @nb: pointer to notifier block
833 * @state: state
Dustin Brown98f7c822019-03-06 12:25:49 -0800834 * @context: notifier callback context pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800835 *
836 * Return: 0 on success, error number otherwise.
837 */
838static int hdd_netdev_notifier_call(struct notifier_block *nb,
839 unsigned long state,
Dustin Brown98f7c822019-03-06 12:25:49 -0800840 void *context)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800841{
Dustin Brown98f7c822019-03-06 12:25:49 -0800842 struct net_device *net_dev = hdd_net_dev_from_notifier(context);
843 struct osif_vdev_sync *vdev_sync;
844 int errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800845
Dustin Brown98f7c822019-03-06 12:25:49 -0800846 errno = osif_vdev_sync_op_start(net_dev, &vdev_sync);
847 if (errno)
848 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800849
Dustin Brown98f7c822019-03-06 12:25:49 -0800850 errno = __hdd_netdev_notifier_call(net_dev, state);
851
852 osif_vdev_sync_op_stop(vdev_sync);
853
854 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800855}
856
857struct notifier_block hdd_netdev_notifier = {
858 .notifier_call = hdd_netdev_notifier_call,
859};
860
861/* variable to hold the insmod parameters */
862static int con_mode;
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800863
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530864static int con_mode_ftm;
Nirav Shah6aeecf92019-02-13 14:05:03 +0530865int con_mode_epping;
Ravi Joshia307f632017-07-17 23:41:41 -0700866int con_mode_monitor;
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530867
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800868/* Variable to hold connection mode including module parameter con_mode */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800869static int curr_con_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800870
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530871/**
872 * hdd_map_nl_chan_width() - Map NL channel width to internal representation
873 * @ch_width: NL channel width
874 *
875 * Converts the NL channel width to the driver's internal representation
876 *
877 * Return: Converted channel width. In case of non matching NL channel width,
878 * CH_WIDTH_MAX will be returned.
879 */
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800880enum phy_ch_width hdd_map_nl_chan_width(enum nl80211_chan_width ch_width)
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530881{
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800882 uint8_t fw_ch_bw;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700883
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800884 fw_ch_bw = wma_get_vht_ch_width();
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530885 switch (ch_width) {
886 case NL80211_CHAN_WIDTH_20_NOHT:
887 case NL80211_CHAN_WIDTH_20:
888 return CH_WIDTH_20MHZ;
889 case NL80211_CHAN_WIDTH_40:
890 return CH_WIDTH_40MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530891 case NL80211_CHAN_WIDTH_80:
892 return CH_WIDTH_80MHZ;
893 case NL80211_CHAN_WIDTH_80P80:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800894 if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_80_PLUS_80MHZ)
895 return CH_WIDTH_80P80MHZ;
896 else if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
897 return CH_WIDTH_160MHZ;
898 else
899 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530900 case NL80211_CHAN_WIDTH_160:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800901 if (fw_ch_bw >= WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
902 return CH_WIDTH_160MHZ;
903 else
904 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530905 case NL80211_CHAN_WIDTH_5:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800906 return CH_WIDTH_5MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530907 case NL80211_CHAN_WIDTH_10:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800908 return CH_WIDTH_10MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530909 default:
910 hdd_err("Invalid channel width %d, setting to default",
911 ch_width);
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800912 return CH_WIDTH_INVALID;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530913 }
914}
915
Dustin Brown56377e12018-10-10 17:04:04 -0700916QDF_STATUS hdd_nl_to_qdf_iface_type(enum nl80211_iftype nl_type,
917 enum QDF_OPMODE *out_qdf_type)
918{
919 switch (nl_type) {
920 case NL80211_IFTYPE_ADHOC:
921 *out_qdf_type = QDF_IBSS_MODE;
922 break;
923 case NL80211_IFTYPE_AP:
924 *out_qdf_type = QDF_SAP_MODE;
925 break;
926 case NL80211_IFTYPE_MONITOR:
927 *out_qdf_type = QDF_MONITOR_MODE;
928 break;
929 case NL80211_IFTYPE_OCB:
930 *out_qdf_type = QDF_OCB_MODE;
931 break;
932 case NL80211_IFTYPE_P2P_CLIENT:
933 *out_qdf_type = QDF_P2P_CLIENT_MODE;
934 break;
935 case NL80211_IFTYPE_P2P_DEVICE:
936 *out_qdf_type = QDF_P2P_DEVICE_MODE;
937 break;
938 case NL80211_IFTYPE_P2P_GO:
939 *out_qdf_type = QDF_P2P_GO_MODE;
940 break;
941 case NL80211_IFTYPE_STATION:
942 *out_qdf_type = QDF_STA_MODE;
943 break;
944 case NL80211_IFTYPE_WDS:
945 *out_qdf_type = QDF_WDS_MODE;
946 break;
947 default:
948 hdd_err("Invalid nl80211 interface type %d", nl_type);
949 return QDF_STATUS_E_INVAL;
950 }
951
952 return QDF_STATUS_SUCCESS;
953}
954
Jeff Johnson16528362018-06-14 12:34:16 -0700955uint8_t wlan_hdd_find_opclass(mac_handle_t mac_handle, uint8_t channel,
956 uint8_t bw_offset)
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530957{
958 uint8_t opclass = 0;
959
Jeff Johnson16528362018-06-14 12:34:16 -0700960 sme_get_opclass(mac_handle, channel, bw_offset, &opclass);
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530961 return opclass;
962}
963
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800964/**
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530965 * hdd_qdf_trace_enable() - configure initial QDF Trace enable
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530966 * @module_id: Module whose trace level is being configured
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800967 * @bitmask: Bitmask of log levels to be enabled
968 *
969 * Called immediately after the cfg.ini is read in order to configure
970 * the desired trace levels.
971 *
972 * Return: None
973 */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530974int hdd_qdf_trace_enable(QDF_MODULE_ID module_id, uint32_t bitmask)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800975{
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530976 QDF_TRACE_LEVEL level;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530977 int qdf_print_idx = -1;
978 int status = -1;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800979 /*
980 * if the bitmask is the default value, then a bitmask was not
981 * specified in cfg.ini, so leave the logging level alone (it
982 * will remain at the "compiled in" default value)
983 */
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700984 if (CFG_QDF_TRACE_ENABLE_DEFAULT == bitmask)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530985 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800986
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530987 qdf_print_idx = qdf_get_pidx();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800988
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530989 /* a mask was specified. start by disabling all logging */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530990 status = qdf_print_set_category_verbose(qdf_print_idx, module_id,
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530991 QDF_TRACE_LEVEL_NONE, 0);
992
993 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530994 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800995 /* now cycle through the bitmask until all "set" bits are serviced */
Ashish Kumar Dhanotiya83f286b2017-09-15 19:52:58 +0530996 level = QDF_TRACE_LEVEL_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800997 while (0 != bitmask) {
998 if (bitmask & 1) {
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530999 status = qdf_print_set_category_verbose(qdf_print_idx,
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +05301000 module_id, level, 1);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +05301001 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +05301002 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001003 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001004
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001005 level++;
1006 bitmask >>= 1;
1007 }
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +05301008 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001009}
1010
Dustin Brownda351e32018-07-23 15:48:22 -07001011int __wlan_hdd_validate_context(struct hdd_context *hdd_ctx, const char *func)
Chris Guo1751acf2017-07-03 14:09:01 +08001012{
Dustin Brownda351e32018-07-23 15:48:22 -07001013 if (!hdd_ctx) {
1014 hdd_err("HDD context is null (via %s)", func);
1015 return -ENODEV;
1016 }
1017
1018 if (!hdd_ctx->config) {
1019 hdd_err("HDD config is null (via %s)", func);
Chris Guo1751acf2017-07-03 14:09:01 +08001020 return -ENODEV;
1021 }
1022
1023 if (cds_is_driver_recovering()) {
Dustin Brownda351e32018-07-23 15:48:22 -07001024 hdd_debug("Recovery in progress (via %s); state:0x%x",
1025 func, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001026 return -EAGAIN;
1027 }
1028
Yue Ma9f275d92017-09-14 16:58:41 -07001029 if (cds_is_load_or_unload_in_progress()) {
Dustin Brownda351e32018-07-23 15:48:22 -07001030 hdd_debug("Load/unload in progress (via %s); state:0x%x",
1031 func, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001032 return -EAGAIN;
Yue Ma9f275d92017-09-14 16:58:41 -07001033 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +05301034
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301035 if (cds_is_driver_in_bad_state()) {
Dustin Brownda351e32018-07-23 15:48:22 -07001036 hdd_debug("Driver in bad state (via %s); state:0x%x",
1037 func, cds_get_driver_state());
Sourav Mohapatra21b3c982018-04-03 17:33:03 +05301038 return -EAGAIN;
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301039 }
1040
Arunk Khandavalli2859fa12018-02-14 10:46:26 +05301041 if (cds_is_fw_down()) {
Dustin Brownda351e32018-07-23 15:48:22 -07001042 hdd_debug("FW is down (via %s); state:0x%x",
1043 func, cds_get_driver_state());
Sourav Mohapatra21b3c982018-04-03 17:33:03 +05301044 return -EAGAIN;
Arunk Khandavalli2859fa12018-02-14 10:46:26 +05301045 }
1046
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001047 return 0;
1048}
1049
Dustin Browna8700cc2018-08-07 12:04:47 -07001050int __hdd_validate_adapter(struct hdd_adapter *adapter, const char *func)
Dustin Brownf13b8c32017-05-19 17:23:08 -07001051{
1052 if (!adapter) {
Dustin Browna8700cc2018-08-07 12:04:47 -07001053 hdd_err("adapter is null (via %s)", func);
Dustin Brownf13b8c32017-05-19 17:23:08 -07001054 return -EINVAL;
1055 }
1056
1057 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
Dustin Browna8700cc2018-08-07 12:04:47 -07001058 hdd_err("bad adapter magic (via %s)", func);
Dustin Brownf13b8c32017-05-19 17:23:08 -07001059 return -EINVAL;
1060 }
1061
1062 if (!adapter->dev) {
Dustin Browna8700cc2018-08-07 12:04:47 -07001063 hdd_err("adapter net_device is null (via %s)", func);
Dustin Brownf13b8c32017-05-19 17:23:08 -07001064 return -EINVAL;
1065 }
1066
1067 if (!(adapter->dev->flags & IFF_UP)) {
Dustin Browna8700cc2018-08-07 12:04:47 -07001068 hdd_debug_rl("adapter '%s' is not up (via %s)",
1069 adapter->dev->name, func);
Dustin Brownf13b8c32017-05-19 17:23:08 -07001070 return -EAGAIN;
1071 }
1072
Jeff Johnson7eb6e842019-02-23 14:33:34 -08001073 return __wlan_hdd_validate_vdev_id(adapter->vdev_id, func);
Dustin Brownf13b8c32017-05-19 17:23:08 -07001074}
1075
Jeff Johnson7eb6e842019-02-23 14:33:34 -08001076int __wlan_hdd_validate_vdev_id(uint8_t vdev_id, const char *func)
Dustin Brown63500612018-08-07 11:36:09 -07001077{
Srinivas Girigowdad8697d42019-03-08 15:34:39 -08001078 if (vdev_id == WLAN_UMAC_VDEV_ID_MAX) {
Dustin Brown63500612018-08-07 11:36:09 -07001079 hdd_debug_rl("adapter is not up (via %s)", func);
1080 return -EINVAL;
1081 }
1082
Jeff Johnson7eb6e842019-02-23 14:33:34 -08001083 if (vdev_id >= WLAN_MAX_VDEVS) {
1084 hdd_err("bad vdev Id:%u (via %s)", vdev_id, func);
Dustin Brown63500612018-08-07 11:36:09 -07001085 return -EINVAL;
1086 }
1087
1088 return 0;
1089}
1090
Pragaspathi Thilagaraj84b72842018-09-19 22:06:57 +05301091QDF_STATUS __wlan_hdd_validate_mac_address(struct qdf_mac_addr *mac_addr,
1092 const char *func)
1093{
1094 if (!mac_addr) {
1095 hdd_err("Received NULL mac address (via %s)", func);
1096 return QDF_STATUS_E_INVAL;
1097 }
1098
1099 if (qdf_is_macaddr_zero(mac_addr)) {
1100 hdd_err("MAC is all zero (via %s)", func);
1101 return QDF_STATUS_E_INVAL;
1102 }
1103
1104 if (qdf_is_macaddr_broadcast(mac_addr)) {
1105 hdd_err("MAC is Broadcast (via %s)", func);
1106 return QDF_STATUS_E_INVAL;
1107 }
1108
1109 if (QDF_NET_IS_MAC_MULTICAST(mac_addr->bytes)) {
1110 hdd_err("MAC is Multicast (via %s)", func);
1111 return QDF_STATUS_E_INVAL;
1112 }
1113
1114 return QDF_STATUS_SUCCESS;
1115}
1116
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001117/**
Arun Khandavallica892f62017-05-26 14:25:50 +05301118 * wlan_hdd_validate_modules_state() - Check modules status
1119 * @hdd_ctx: HDD context pointer
1120 *
1121 * Check's the driver module's state and returns true if the
1122 * modules are enabled returns false if modules are closed.
1123 *
1124 * Return: True if modules are enabled or false.
1125 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001126bool wlan_hdd_validate_modules_state(struct hdd_context *hdd_ctx)
Arun Khandavallica892f62017-05-26 14:25:50 +05301127{
Arun Khandavallica892f62017-05-26 14:25:50 +05301128 if (hdd_ctx->driver_status != DRIVER_MODULES_ENABLED) {
Dustin Brown5e89ef82018-03-14 11:50:23 -07001129 hdd_info("Modules not enabled, Present status: %d",
1130 hdd_ctx->driver_status);
Arun Khandavallica892f62017-05-26 14:25:50 +05301131 return false;
1132 }
Dustin Brownf688ea12019-03-19 17:02:32 -07001133
Arun Khandavallica892f62017-05-26 14:25:50 +05301134 return true;
1135}
1136
1137/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001138 * hdd_set_ibss_power_save_params() - update IBSS Power Save params to WMA.
Jeff Johnson9d295242017-08-29 14:39:48 -07001139 * @struct hdd_adapter Hdd adapter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001140 *
1141 * This function sets the IBSS power save config parameters to WMA
1142 * which will send it to firmware if FW supports IBSS power save
1143 * before vdev start.
1144 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301145 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and QDF_STATUS_E_FAILURE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001146 * on failure.
1147 */
Jeff Johnson9d295242017-08-29 14:39:48 -07001148QDF_STATUS hdd_set_ibss_power_save_params(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001149{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001150 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001151
Jeff Johnsond36fa332019-03-18 13:42:25 -07001152 if (!hdd_ctx) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001153 hdd_err("HDD context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301154 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001155 }
1156
Manikandan Mohan2bd09772018-11-28 18:27:32 -08001157 return ucfg_mlme_ibss_power_save_setup(hdd_ctx->psoc,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08001158 adapter->vdev_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001159}
1160
Yue Macd359b72017-10-03 15:21:00 -07001161#ifdef FEATURE_RUNTIME_PM
1162/**
1163 * hdd_runtime_suspend_context_init() - API to initialize HDD Runtime Contexts
1164 * @hdd_ctx: HDD context
1165 *
1166 * Return: None
1167 */
1168static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx)
1169{
1170 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1171
Yue Macd359b72017-10-03 15:21:00 -07001172 qdf_runtime_lock_init(&ctx->dfs);
Jingxiang Geb49aa302018-01-17 20:54:15 +08001173 qdf_runtime_lock_init(&ctx->connect);
Yue Macd359b72017-10-03 15:21:00 -07001174
Dustin Brown07901ec2018-09-07 11:02:41 -07001175 wlan_scan_runtime_pm_init(hdd_ctx->pdev);
Yue Macd359b72017-10-03 15:21:00 -07001176}
1177
1178/**
1179 * hdd_runtime_suspend_context_deinit() - API to deinit HDD runtime context
1180 * @hdd_ctx: HDD Context
1181 *
1182 * Return: None
1183 */
1184static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx)
1185{
1186 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1187
Yue Macd359b72017-10-03 15:21:00 -07001188 qdf_runtime_lock_deinit(&ctx->dfs);
Jingxiang Geb49aa302018-01-17 20:54:15 +08001189 qdf_runtime_lock_deinit(&ctx->connect);
Yue Macd359b72017-10-03 15:21:00 -07001190
Dustin Brown07901ec2018-09-07 11:02:41 -07001191 wlan_scan_runtime_pm_deinit(hdd_ctx->pdev);
Yue Macd359b72017-10-03 15:21:00 -07001192}
1193
Yue Macd359b72017-10-03 15:21:00 -07001194#else /* FEATURE_RUNTIME_PM */
1195static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx) {}
1196static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx) {}
Yue Macd359b72017-10-03 15:21:00 -07001197#endif /* FEATURE_RUNTIME_PM */
1198
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001199#define INTF_MACADDR_MASK 0x7
1200
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05301201void hdd_update_macaddr(struct hdd_context *hdd_ctx,
1202 struct qdf_mac_addr hw_macaddr, bool generate_mac_auto)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001203{
1204 int8_t i;
1205 uint8_t macaddr_b3, tmp_br3;
1206
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05301207 /*
1208 * If "generate_mac_auto" is true, it indicates that all the
1209 * addresses are derived addresses, else the first addresses
1210 * is not derived address (It is provided by fw).
1211 */
1212 if (!generate_mac_auto) {
1213 qdf_mem_copy(hdd_ctx->provisioned_mac_addr[0].bytes,
1214 hw_macaddr.bytes, QDF_MAC_ADDR_SIZE);
1215 hdd_ctx->num_provisioned_addr++;
1216 hdd_info("hdd_ctx->provisioned_mac_addr[0]: "
Srinivas Girigowdacb7b8b82019-04-10 14:27:47 -07001217 QDF_MAC_ADDR_STR,
Srinivas Girigowda34fbba02019-04-08 12:07:44 -07001218 QDF_MAC_ADDR_ARRAY(hdd_ctx->
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05301219 provisioned_mac_addr[0].bytes));
1220 } else {
1221 qdf_mem_copy(hdd_ctx->derived_mac_addr[0].bytes,
1222 hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301223 QDF_MAC_ADDR_SIZE);
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05301224 hdd_ctx->num_derived_addr++;
1225 hdd_info("hdd_ctx->derived_mac_addr[0]: "
Srinivas Girigowdacb7b8b82019-04-10 14:27:47 -07001226 QDF_MAC_ADDR_STR,
Srinivas Girigowda34fbba02019-04-08 12:07:44 -07001227 QDF_MAC_ADDR_ARRAY(hdd_ctx->derived_mac_addr[0].bytes));
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05301228 }
1229 for (i = hdd_ctx->num_derived_addr; i < (QDF_MAX_CONCURRENCY_PERSONA -
1230 hdd_ctx->num_provisioned_addr);
1231 i++) {
1232 qdf_mem_copy(hdd_ctx->derived_mac_addr[i].bytes,
1233 hw_macaddr.bytes,
1234 QDF_MAC_ADDR_SIZE);
1235 macaddr_b3 = hdd_ctx->derived_mac_addr[i].bytes[3];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001236 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + i) &
1237 INTF_MACADDR_MASK;
1238 macaddr_b3 += tmp_br3;
1239
1240 /* XOR-ing bit-24 of the mac address. This will give enough
1241 * mac address range before collision
1242 */
1243 macaddr_b3 ^= (1 << 7);
1244
1245 /* Set locally administered bit */
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05301246 hdd_ctx->derived_mac_addr[i].bytes[0] |= 0x02;
1247 hdd_ctx->derived_mac_addr[i].bytes[3] = macaddr_b3;
1248 hdd_info("hdd_ctx->derived_mac_addr[%d]: "
Srinivas Girigowdacb7b8b82019-04-10 14:27:47 -07001249 QDF_MAC_ADDR_STR, i,
Srinivas Girigowda34fbba02019-04-08 12:07:44 -07001250 QDF_MAC_ADDR_ARRAY(hdd_ctx->derived_mac_addr[i].bytes));
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05301251 hdd_ctx->num_derived_addr++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001252 }
1253}
1254
Jeff Johnson2de58792019-02-08 07:49:17 -08001255#ifdef FEATURE_WLAN_TDLS
Kabilan Kannan44a58372017-12-06 18:16:11 -08001256static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
1257{
Dustin Brown1dbefe62018-09-11 16:32:03 -07001258 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001259 struct tdls_start_params tdls_cfg;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001260 QDF_STATUS status;
gaurank kathpalia651abcd2018-11-12 22:41:23 +05301261 struct wlan_mlme_nss_chains vdev_ini_cfg;
1262
1263 /* Populate the nss chain params from ini for this vdev type */
1264 sme_populate_nss_chain_params(hdd_ctx->mac_handle, &vdev_ini_cfg,
1265 QDF_TDLS_MODE,
1266 hdd_ctx->num_rf_chains);
Kabilan Kannan44a58372017-12-06 18:16:11 -08001267
Dustin Brown1dbefe62018-09-11 16:32:03 -07001268 cfg_tdls_set_vdev_nss_2g(hdd_ctx->psoc,
gaurank kathpalia651abcd2018-11-12 22:41:23 +05301269 vdev_ini_cfg.rx_nss[NSS_CHAINS_BAND_2GHZ]);
Dustin Brown1dbefe62018-09-11 16:32:03 -07001270 cfg_tdls_set_vdev_nss_5g(hdd_ctx->psoc,
gaurank kathpalia651abcd2018-11-12 22:41:23 +05301271 vdev_ini_cfg.rx_nss[NSS_CHAINS_BAND_5GHZ]);
jiad7b8a5e02018-11-26 16:37:57 +08001272 hdd_init_tdls_config(&tdls_cfg);
Kabilan Kannan44a58372017-12-06 18:16:11 -08001273 tdls_cfg.tdls_del_all_peers = eWNI_SME_DEL_ALL_TDLS_PEERS;
1274 tdls_cfg.tdls_update_dp_vdev_flags = CDP_UPDATE_TDLS_FLAGS;
1275 tdls_cfg.tdls_event_cb = wlan_cfg80211_tdls_event_callback;
1276 tdls_cfg.tdls_evt_cb_data = psoc;
Jeff Johnson1d40f5b2018-03-02 08:35:53 -08001277 tdls_cfg.tdls_peer_context = hdd_ctx;
1278 tdls_cfg.tdls_reg_peer = hdd_tdls_register_peer;
1279 tdls_cfg.tdls_dereg_peer = hdd_tdls_deregister_peer;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001280 tdls_cfg.tdls_wmm_cb = hdd_wmm_is_acm_allowed;
1281 tdls_cfg.tdls_wmm_cb_data = psoc;
1282 tdls_cfg.tdls_rx_cb = wlan_cfg80211_tdls_rx_callback;
1283 tdls_cfg.tdls_rx_cb_data = psoc;
1284 tdls_cfg.tdls_dp_vdev_update = hdd_update_dp_vdev_flags;
Arun Kumar Khandavalli43fdd252019-04-24 18:34:18 +05301285 tdls_cfg.tdls_osif_init_cb = wlan_cfg80211_tdls_osif_priv_init;
1286 tdls_cfg.tdls_osif_deinit_cb = wlan_cfg80211_tdls_osif_priv_deinit;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001287
1288 status = ucfg_tdls_update_config(psoc, &tdls_cfg);
1289 if (status != QDF_STATUS_SUCCESS) {
1290 hdd_err("failed pmo psoc configuration");
1291 return -EINVAL;
1292 }
1293
1294 hdd_ctx->tdls_umac_comp_active = true;
1295 /* enable napier specific tdls data path */
1296 hdd_ctx->tdls_nap_active = true;
1297
1298 return 0;
1299}
Jeff Johnson74c6bb22019-02-15 10:15:07 -08001300#else
1301static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
1302{
1303 return 0;
1304}
1305#endif
Kabilan Kannan44a58372017-12-06 18:16:11 -08001306
Wu Gaoca416ff2018-09-17 11:05:07 +08001307#ifdef WLAN_FEATURE_ROAM_OFFLOAD
1308static void hdd_update_roam_offload(struct hdd_context *hdd_ctx,
1309 struct wma_tgt_services *cfg)
1310{
1311 bool roam_offload_enable;
1312
Dustin Brown1dbefe62018-09-11 16:32:03 -07001313 ucfg_mlme_get_roaming_offload(hdd_ctx->psoc, &roam_offload_enable);
1314 ucfg_mlme_set_roaming_offload(hdd_ctx->psoc,
Wu Gaoca416ff2018-09-17 11:05:07 +08001315 roam_offload_enable &
1316 cfg->en_roam_offload);
1317}
1318#else
1319static inline void hdd_update_roam_offload(struct hdd_context *hdd_ctx,
1320 struct wma_tgt_services *cfg)
1321{
1322}
1323#endif
1324
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001325static void hdd_update_tgt_services(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001326 struct wma_tgt_services *cfg)
1327{
1328 struct hdd_config *config = hdd_ctx->config;
Wu Gao66454f12018-09-26 19:55:41 +08001329 bool arp_offload_enable;
Wu Gao1ab05582018-11-08 16:22:49 +08001330 bool mawc_enabled;
Wu Gaobdb7f272018-07-05 19:33:26 +08001331#ifdef FEATURE_WLAN_TDLS
1332 bool tdls_support;
1333 bool tdls_off_channel;
1334 bool tdls_buffer_sta;
1335 uint32_t tdls_uapsd_mask;
1336#endif
Will Huangb9cb1242019-04-02 14:52:17 +08001337 bool get_peer_info_enable;
jiad7b8a5e02018-11-26 16:37:57 +08001338
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001339 /* Set up UAPSD */
Pragaspathi Thilagaraj4b5c0602018-11-14 22:35:23 +05301340 ucfg_mlme_set_sap_uapsd_flag(hdd_ctx->psoc, cfg->uapsd);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001341
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08001342 /* 11AX mode support */
1343 if ((config->dot11Mode == eHDD_DOT11_MODE_11ax ||
1344 config->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY) && !cfg->en_11ax)
1345 config->dot11Mode = eHDD_DOT11_MODE_11ac;
1346
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001347 /* 11AC mode support */
1348 if ((config->dot11Mode == eHDD_DOT11_MODE_11ac ||
1349 config->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY) && !cfg->en_11ac)
1350 config->dot11Mode = eHDD_DOT11_MODE_AUTO;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001351
1352 /* ARP offload: override user setting if invalid */
Wu Gao66454f12018-09-26 19:55:41 +08001353 arp_offload_enable =
1354 ucfg_pmo_is_arp_offload_enabled(hdd_ctx->psoc);
1355 ucfg_pmo_set_arp_offload_enabled(hdd_ctx->psoc,
1356 arp_offload_enable & cfg->arp_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001357#ifdef FEATURE_WLAN_SCAN_PNO
1358 /* PNO offload */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001359 hdd_debug("PNO Capability in f/w = %d", cfg->pno_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001360 if (cfg->pno_offload)
Pragaspathi Thilagaraj24789d32018-12-10 22:28:03 +05301361 ucfg_scan_set_pno_offload(hdd_ctx->psoc, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001362#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001363#ifdef FEATURE_WLAN_TDLS
Dustin Brown1dbefe62018-09-11 16:32:03 -07001364 cfg_tdls_get_support_enable(hdd_ctx->psoc, &tdls_support);
1365 cfg_tdls_set_support_enable(hdd_ctx->psoc,
Wu Gaobdb7f272018-07-05 19:33:26 +08001366 tdls_support & cfg->en_tdls);
1367
Dustin Brown1dbefe62018-09-11 16:32:03 -07001368 cfg_tdls_get_off_channel_enable(hdd_ctx->psoc, &tdls_off_channel);
1369 cfg_tdls_set_off_channel_enable(hdd_ctx->psoc,
Wu Gaobdb7f272018-07-05 19:33:26 +08001370 tdls_off_channel &&
1371 cfg->en_tdls_offchan);
1372
Dustin Brown1dbefe62018-09-11 16:32:03 -07001373 cfg_tdls_get_buffer_sta_enable(hdd_ctx->psoc, &tdls_buffer_sta);
1374 cfg_tdls_set_buffer_sta_enable(hdd_ctx->psoc,
Wu Gaobdb7f272018-07-05 19:33:26 +08001375 tdls_buffer_sta &&
1376 cfg->en_tdls_uapsd_buf_sta);
1377
Dustin Brown1dbefe62018-09-11 16:32:03 -07001378 cfg_tdls_get_uapsd_mask(hdd_ctx->psoc, &tdls_uapsd_mask);
Wu Gaobdb7f272018-07-05 19:33:26 +08001379 if (tdls_uapsd_mask && cfg->en_tdls_uapsd_sleep_sta)
Dustin Brown1dbefe62018-09-11 16:32:03 -07001380 cfg_tdls_set_sleep_sta_enable(hdd_ctx->psoc, true);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001381 else
Dustin Brown1dbefe62018-09-11 16:32:03 -07001382 cfg_tdls_set_sleep_sta_enable(hdd_ctx->psoc, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001383#endif
Wu Gaoca416ff2018-09-17 11:05:07 +08001384 hdd_update_roam_offload(hdd_ctx, cfg);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05301385
Will Huangb9cb1242019-04-02 14:52:17 +08001386 if (ucfg_mlme_get_sap_get_peer_info(
1387 hdd_ctx->psoc, &get_peer_info_enable) == QDF_STATUS_SUCCESS) {
1388 get_peer_info_enable &= cfg->get_peer_info_enabled;
1389 ucfg_mlme_set_sap_get_peer_info(hdd_ctx->psoc,
1390 get_peer_info_enable);
1391 }
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05301392
Wu Gao1ab05582018-11-08 16:22:49 +08001393 ucfg_mlme_is_mawc_enabled(hdd_ctx->psoc, &mawc_enabled);
1394 ucfg_mlme_set_mawc_enabled(hdd_ctx->psoc,
1395 mawc_enabled & cfg->is_fw_mawc_capable);
Kabilan Kannan44a58372017-12-06 18:16:11 -08001396 hdd_update_tdls_config(hdd_ctx);
Jeff Johnson16528362018-06-14 12:34:16 -07001397 sme_update_tgt_services(hdd_ctx->mac_handle, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001398}
1399
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001400/**
1401 * hdd_update_vdev_nss() - sets the vdev nss
1402 * @hdd_ctx: HDD context
1403 *
1404 * Sets the Nss per vdev type based on INI
1405 *
1406 * Return: None
1407 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001408static void hdd_update_vdev_nss(struct hdd_context *hdd_ctx)
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001409{
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001410 uint8_t max_supp_nss = 1;
Jeff Johnson16528362018-06-14 12:34:16 -07001411 mac_handle_t mac_handle;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301412 QDF_STATUS status;
1413 bool bval;
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001414
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301415 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &bval);
1416 if (!QDF_IS_STATUS_SUCCESS(status))
1417 hdd_err("unable to get vht_enable2x2");
1418
1419 if (bval && !cds_is_sub_20_mhz_enabled())
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001420 max_supp_nss = 2;
gaurank kathpalia651abcd2018-11-12 22:41:23 +05301421
1422 hdd_debug("max nss %d", max_supp_nss);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001423
Jeff Johnson16528362018-06-14 12:34:16 -07001424 mac_handle = hdd_ctx->mac_handle;
1425 sme_update_vdev_type_nss(mac_handle, max_supp_nss,
gaurank kathpalia651abcd2018-11-12 22:41:23 +05301426 NSS_CHAINS_BAND_2GHZ);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001427
Jeff Johnson16528362018-06-14 12:34:16 -07001428 sme_update_vdev_type_nss(mac_handle, max_supp_nss,
gaurank kathpalia651abcd2018-11-12 22:41:23 +05301429 NSS_CHAINS_BAND_5GHZ);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001430}
1431
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301432/**
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301433 * hdd_update_wiphy_vhtcap() - Updates wiphy vhtcap fields
1434 * @hdd_ctx: HDD context
1435 *
1436 * Updates wiphy vhtcap fields
1437 *
1438 * Return: None
1439 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001440static void hdd_update_wiphy_vhtcap(struct hdd_context *hdd_ctx)
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301441{
1442 struct ieee80211_supported_band *band_5g =
1443 hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ];
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301444 QDF_STATUS status;
1445 uint8_t value = 0, value1 = 0;
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301446
1447 if (!band_5g) {
1448 hdd_debug("5GHz band disabled, skipping capability population");
1449 return;
1450 }
1451
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301452 status = ucfg_mlme_cfg_get_vht_tx_bfee_ant_supp(hdd_ctx->psoc,
1453 &value);
1454 if (!QDF_IS_STATUS_SUCCESS(status))
1455 hdd_err("unable to get tx_bfee_ant_supp");
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301456
Abhinav Kumare057b412018-10-09 17:28:16 +05301457 band_5g->vht_cap.cap |=
1458 (value << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301459
1460 value1 = NUM_OF_SOUNDING_DIMENSIONS;
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301461 band_5g->vht_cap.cap |=
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301462 (value1 << IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301463
Dustin Brown7e761c72018-07-31 13:50:17 -07001464 hdd_debug("Updated wiphy vhtcap:0x%x, CSNAntSupp:%d, NumSoundDim:%d",
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301465 band_5g->vht_cap.cap, value, value1);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301466}
1467
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001468static void hdd_update_tgt_ht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001469 struct wma_tgt_ht_cap *cfg)
1470{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301471 QDF_STATUS status;
Karthik Kantamnenie3bbd7f2018-09-19 20:27:32 +05301472 qdf_size_t value_len;
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05301473 uint32_t value;
Vignesh Viswanathanddc89e52018-11-02 18:43:42 +05301474 uint8_t mpdu_density;
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05301475 struct mlme_ht_capabilities_info ht_cap_info;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001476 uint8_t mcs_set[SIZE_OF_SUPPORTED_MCS_SET];
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301477 bool b_enable1x1;
Jeff Johnson16528362018-06-14 12:34:16 -07001478
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001479 /* get the MPDU density */
Vignesh Viswanathanddc89e52018-11-02 18:43:42 +05301480 status = ucfg_mlme_get_ht_mpdu_density(hdd_ctx->psoc, &mpdu_density);
1481 if (QDF_IS_STATUS_ERROR(status)) {
1482 hdd_err("could not get HT MPDU Density");
1483 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001484 }
1485
1486 /*
1487 * MPDU density:
1488 * override user's setting if value is larger
1489 * than the one supported by target
1490 */
Vignesh Viswanathanddc89e52018-11-02 18:43:42 +05301491 if (mpdu_density > cfg->mpdu_density) {
1492 status = ucfg_mlme_set_ht_mpdu_density(hdd_ctx->psoc,
1493 cfg->mpdu_density);
1494 if (QDF_IS_STATUS_ERROR(status))
1495 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001496 }
1497
1498 /* get the HT capability info */
Dustin Brown1dbefe62018-09-11 16:32:03 -07001499 status = ucfg_mlme_get_ht_cap_info(hdd_ctx->psoc, &ht_cap_info);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301500 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001501 hdd_err("could not get HT capability info");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001502 return;
1503 }
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05301504
1505 /* check and update RX STBC */
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301506 if (ht_cap_info.rx_stbc && !cfg->ht_rx_stbc)
1507 ht_cap_info.rx_stbc = cfg->ht_rx_stbc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001508
1509 /* Set the LDPC capability */
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301510 ht_cap_info.adv_coding_cap = cfg->ht_rx_ldpc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001511
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301512 if (ht_cap_info.short_gi_20_mhz && !cfg->ht_sgi_20)
1513 ht_cap_info.short_gi_20_mhz = cfg->ht_sgi_20;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001514
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301515 if (ht_cap_info.short_gi_40_mhz && !cfg->ht_sgi_40)
1516 ht_cap_info.short_gi_40_mhz = cfg->ht_sgi_40;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001517
1518 hdd_ctx->num_rf_chains = cfg->num_rf_chains;
1519 hdd_ctx->ht_tx_stbc_supported = cfg->ht_tx_stbc;
1520
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301521 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &b_enable1x1);
1522 if (!QDF_IS_STATUS_SUCCESS(status))
1523 hdd_err("unable to get vht_enable2x2");
1524
1525 b_enable1x1 = b_enable1x1 && (cfg->num_rf_chains == 2);
1526
1527 status = ucfg_mlme_set_vht_enable2x2(hdd_ctx->psoc, b_enable1x1);
1528 if (!QDF_IS_STATUS_SUCCESS(status))
1529 hdd_err("unable to set vht_enable2x2");
1530
Abhinav Kumare057b412018-10-09 17:28:16 +05301531 if (!b_enable1x1) {
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301532 ht_cap_info.tx_stbc = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001533
1534 /* 1x1 */
1535 /* Update Rx Highest Long GI data Rate */
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301536 status = ucfg_mlme_cfg_set_vht_rx_supp_data_rate(
1537 hdd_ctx->psoc,
1538 VHT_RX_HIGHEST_SUPPORTED_DATA_RATE_1_1);
1539 if (!QDF_IS_STATUS_SUCCESS(status))
1540 hdd_err("Failed to set rx_supp_data_rate");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001541 /* Update Tx Highest Long GI data Rate */
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301542 status = ucfg_mlme_cfg_set_vht_tx_supp_data_rate(
1543 hdd_ctx->psoc,
1544 VHT_TX_HIGHEST_SUPPORTED_DATA_RATE_1_1);
1545 if (!QDF_IS_STATUS_SUCCESS(status))
1546 hdd_err("Failed to set tx_supp_data_rate");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001547 }
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301548 if (!(cfg->ht_tx_stbc && b_enable1x1))
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301549 ht_cap_info.tx_stbc = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001550
Dustin Brown1dbefe62018-09-11 16:32:03 -07001551 status = ucfg_mlme_set_ht_cap_info(hdd_ctx->psoc, ht_cap_info);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301552 if (status != QDF_STATUS_SUCCESS)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001553 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001554#define WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES 0xff
Karthik Kantamnenie3bbd7f2018-09-19 20:27:32 +05301555 value_len = SIZE_OF_SUPPORTED_MCS_SET;
1556 if (ucfg_mlme_get_supported_mcs_set(
1557 hdd_ctx->psoc, mcs_set,
1558 &value_len) == QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001559 hdd_debug("Read MCS rate set");
gaurank kathpalia18b49362018-04-15 23:12:03 +05301560 if (cfg->num_rf_chains > SIZE_OF_SUPPORTED_MCS_SET)
1561 cfg->num_rf_chains = SIZE_OF_SUPPORTED_MCS_SET;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301562
1563 if (b_enable1x1) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001564 for (value = 0; value < cfg->num_rf_chains; value++)
1565 mcs_set[value] =
1566 WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES;
1567
Karthik Kantamnenie3bbd7f2018-09-19 20:27:32 +05301568 status = ucfg_mlme_set_supported_mcs_set(
1569 hdd_ctx->psoc,
1570 mcs_set,
1571 (qdf_size_t)SIZE_OF_SUPPORTED_MCS_SET);
1572 if (QDF_IS_STATUS_ERROR(status))
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001573 hdd_err("could not set MCS SET to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001574 }
1575 }
1576#undef WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES
1577}
1578
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001579static void hdd_update_tgt_vht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001580 struct wma_tgt_vht_cap *cfg)
1581{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301582 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001583 struct wiphy *wiphy = hdd_ctx->wiphy;
1584 struct ieee80211_supported_band *band_5g =
Srinivas Girigowda11c28e02017-06-27 20:06:21 -07001585 wiphy->bands[HDD_NL80211_BAND_5GHZ];
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001586 uint32_t ch_width = eHT_CHANNEL_WIDTH_80MHZ;
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001587 struct wma_caps_per_phy caps_per_phy;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301588 uint8_t val = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001589
Dustin Brown5e06bd32016-10-04 12:49:10 -07001590 if (!band_5g) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001591 hdd_debug("5GHz band disabled, skipping capability population");
Dustin Brown5e06bd32016-10-04 12:49:10 -07001592 return;
1593 }
1594
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301595 status = ucfg_mlme_update_vht_cap(hdd_ctx->psoc, cfg);
1596 if (QDF_IS_STATUS_ERROR(status))
1597 hdd_err("could not update vht capabilities");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001598
1599 if (WMI_VHT_CAP_MAX_MPDU_LEN_11454 == cfg->vht_max_mpdu)
1600 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1601 else if (WMI_VHT_CAP_MAX_MPDU_LEN_7935 == cfg->vht_max_mpdu)
1602 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1603 else
1604 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1605
1606
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001607 if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_80P80MHZ)) {
Abhinav Kumare057b412018-10-09 17:28:16 +05301608 status = ucfg_mlme_set_vht_ch_width(hdd_ctx->psoc,
1609 VHT_CAP_160_AND_80P80_SUPP);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301610 if (QDF_IS_STATUS_ERROR(status))
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001611 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001612 band_5g->vht_cap.cap |=
1613 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001614 ch_width = eHT_CHANNEL_WIDTH_80P80MHZ;
1615 } else if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_160MHZ)) {
Abhinav Kumare057b412018-10-09 17:28:16 +05301616 status = ucfg_mlme_set_vht_ch_width(hdd_ctx->psoc,
1617 VHT_CAP_160_SUPP);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301618 if (QDF_IS_STATUS_ERROR(status))
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001619 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001620 band_5g->vht_cap.cap |=
1621 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001622 ch_width = eHT_CHANNEL_WIDTH_160MHZ;
1623 }
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001624
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301625 status =
1626 ucfg_mlme_cfg_get_vht_chan_width(hdd_ctx->psoc, &val);
1627 if (QDF_IS_STATUS_ERROR(status))
1628 hdd_err("could not get channel_width");
1629
1630 val = QDF_MIN(val, ch_width);
Abhinav Kumare057b412018-10-09 17:28:16 +05301631 status = ucfg_mlme_set_vht_ch_width(hdd_ctx->psoc, val);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301632 if (QDF_IS_STATUS_ERROR(status))
1633 hdd_err("could not set the channel width");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001634
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001635 if (cfg->vht_rx_ldpc & WMI_VHT_CAP_RX_LDPC) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001636 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001637 hdd_debug("VHT RxLDPC capability is set");
1638 } else {
1639 /*
1640 * Get the RX LDPC capability for the NON DBS
1641 * hardware mode for 5G band
1642 */
1643 status = wma_get_caps_for_phyidx_hwmode(&caps_per_phy,
1644 HW_MODE_DBS_NONE, CDS_BAND_5GHZ);
1645 if ((QDF_IS_STATUS_SUCCESS(status)) &&
1646 (caps_per_phy.vht_5g & WMI_VHT_CAP_RX_LDPC)) {
1647 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
1648 hdd_debug("VHT RX LDPC capability is set");
1649 }
1650 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001651
1652 if (cfg->vht_short_gi_80 & WMI_VHT_CAP_SGI_80MHZ)
1653 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1654 if (cfg->vht_short_gi_160 & WMI_VHT_CAP_SGI_160MHZ)
1655 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1656
1657 if (cfg->vht_tx_stbc & WMI_VHT_CAP_TX_STBC)
1658 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
1659
1660 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_1SS)
1661 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1662 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_2SS)
1663 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_2;
1664 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_3SS)
1665 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_3;
1666
1667 band_5g->vht_cap.cap |=
1668 (cfg->vht_max_ampdu_len_exp <<
1669 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1670
1671 if (cfg->vht_su_bformer & WMI_VHT_CAP_SU_BFORMER)
1672 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1673 if (cfg->vht_su_bformee & WMI_VHT_CAP_SU_BFORMEE)
1674 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1675 if (cfg->vht_mu_bformer & WMI_VHT_CAP_MU_BFORMER)
1676 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1677 if (cfg->vht_mu_bformee & WMI_VHT_CAP_MU_BFORMEE)
1678 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1679
1680 if (cfg->vht_txop_ps & WMI_VHT_CAP_TXOP_PS)
1681 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1682
1683}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001684
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001685/**
1686 * hdd_generate_macaddr_auto() - Auto-generate mac address
1687 * @hdd_ctx: Pointer to the HDD context
1688 *
1689 * Auto-generate mac address using device serial number.
1690 * Keep the first 3 bytes of OUI as before and replace
1691 * the last 3 bytes with the lower 3 bytes of serial number.
1692 *
1693 * Return: 0 for success
1694 * Non zero failure code for errors
1695 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001696static int hdd_generate_macaddr_auto(struct hdd_context *hdd_ctx)
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001697{
1698 unsigned int serialno = 0;
1699 struct qdf_mac_addr mac_addr = {
1700 {0x00, 0x0A, 0xF5, 0x00, 0x00, 0x00}
1701 };
1702
Yuanyuan Liuf97e8222016-09-21 10:31:38 -07001703 serialno = pld_socinfo_get_serial_number(hdd_ctx->parent_dev);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001704 if (serialno == 0)
1705 return -EINVAL;
1706
1707 serialno &= 0x00ffffff;
1708
1709 mac_addr.bytes[3] = (serialno >> 16) & 0xff;
1710 mac_addr.bytes[4] = (serialno >> 8) & 0xff;
1711 mac_addr.bytes[5] = serialno & 0xff;
1712
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05301713 hdd_update_macaddr(hdd_ctx, mac_addr, true);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001714 return 0;
1715}
1716
Jeff Johnsonf9176382018-07-17 19:15:58 -07001717static void hdd_sar_target_config(struct hdd_context *hdd_ctx,
1718 struct wma_tgt_cfg *cfg)
1719{
1720 hdd_ctx->sar_version = cfg->sar_version;
1721}
1722
Jianmin Zhuc8bfffb2019-01-15 12:40:03 +08001723static void hdd_update_vhtcap_2g(struct hdd_context *hdd_ctx)
1724{
Jianmin Zhu2f9e7532019-01-21 15:39:50 +08001725 uint32_t chip_mode = 0;
Jianmin Zhuc8bfffb2019-01-15 12:40:03 +08001726 QDF_STATUS status;
Jianmin Zhu2f9e7532019-01-21 15:39:50 +08001727 bool b2g_vht_cfg = false;
1728 bool b2g_vht_target = false;
1729 struct wma_caps_per_phy caps_per_phy;
1730 struct wmi_unified *wmi_handle;
Jianmin Zhuc8bfffb2019-01-15 12:40:03 +08001731
Jianmin Zhu2f9e7532019-01-21 15:39:50 +08001732 wmi_handle = get_wmi_unified_hdl_from_psoc(hdd_ctx->psoc);
1733 if (!wmi_handle) {
1734 hdd_err("wmi handle is NULL");
Jianmin Zhuc8bfffb2019-01-15 12:40:03 +08001735 return;
1736 }
Jianmin Zhu2f9e7532019-01-21 15:39:50 +08001737
1738 status = ucfg_mlme_get_vht_for_24ghz(hdd_ctx->psoc, &b2g_vht_cfg);
Jianmin Zhuc8bfffb2019-01-15 12:40:03 +08001739 if (QDF_IS_STATUS_ERROR(status)) {
1740 hdd_err("Failed to get 2g vht mode");
1741 return;
1742 }
Jianmin Zhu2f9e7532019-01-21 15:39:50 +08001743 if (wmi_service_enabled(wmi_handle, wmi_service_ext_msg)) {
1744 status = wma_get_caps_for_phyidx_hwmode(&caps_per_phy,
1745 HW_MODE_DBS_NONE,
1746 CDS_BAND_ALL);
1747 if (QDF_IS_STATUS_ERROR(status)) {
1748 hdd_err("Failed to get phy caps");
1749 return;
1750 }
1751 if (caps_per_phy.vht_2g)
1752 b2g_vht_target = true;
1753 } else {
1754 status = wlan_reg_get_chip_mode(hdd_ctx->pdev, &chip_mode);
1755 if (QDF_IS_STATUS_ERROR(status)) {
1756 hdd_err("Failed to get chip mode");
1757 return;
1758 }
1759 b2g_vht_target =
1760 (chip_mode & WMI_HOST_REGDMN_MODE_11AC_VHT20_2G) ?
1761 true : false;
1762 }
Jianmin Zhuc8bfffb2019-01-15 12:40:03 +08001763
Jianmin Zhu2f9e7532019-01-21 15:39:50 +08001764 b2g_vht_cfg = b2g_vht_cfg && b2g_vht_target;
1765 hdd_debug("vht 2g target: %d, cfg: %d", b2g_vht_target, b2g_vht_cfg);
1766 status = ucfg_mlme_set_vht_for_24ghz(hdd_ctx->psoc, b2g_vht_cfg);
Jianmin Zhuc8bfffb2019-01-15 12:40:03 +08001767 if (QDF_IS_STATUS_ERROR(status)) {
1768 hdd_err("Failed to update 2g vht mode");
1769 return;
1770 }
Jianmin Zhuc8bfffb2019-01-15 12:40:03 +08001771}
1772
Arun Kumar Khandavallia4234582019-03-20 16:16:05 +05301773int hdd_update_tgt_cfg(hdd_handle_t hdd_handle, struct wma_tgt_cfg *cfg)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001774{
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001775 int ret;
Jeff Johnsonea70b942018-07-02 09:42:31 -07001776 struct hdd_context *hdd_ctx = hdd_handle_to_context(hdd_handle);
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301777 uint8_t temp_band_cap, band_capability;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001778 struct cds_config_info *cds_cfg = cds_get_ini_config();
Nitesh Shahe50711f2017-04-26 16:30:45 +05301779 uint8_t antenna_mode;
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05301780 uint8_t sub_20_chan_width;
Arif Hussainee10f902017-12-27 16:30:17 -08001781 QDF_STATUS status;
Jeff Johnson16528362018-06-14 12:34:16 -07001782 mac_handle_t mac_handle;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301783 bool bval = false;
1784 uint8_t value = 0;
Arif Hussainbd5194c2018-11-27 19:01:15 -08001785 uint32_t fine_time_meas_cap = 0;
gaurank kathpaliafa7ad0a2019-03-12 19:17:56 +05301786 enum nss_chains_band_info band;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301787
gaurank kathpalia843f7c32018-07-02 18:04:14 +05301788 if (!hdd_ctx) {
1789 hdd_err("HDD context is NULL");
Arun Kumar Khandavallia4234582019-03-20 16:16:05 +05301790 return -EINVAL;
gaurank kathpalia843f7c32018-07-02 18:04:14 +05301791 }
Dustin Brownbd68fe12017-11-21 15:28:52 -08001792 ret = hdd_objmgr_create_and_store_pdev(hdd_ctx);
1793 if (ret) {
Dustin Brown64204d22018-08-15 16:35:19 -07001794 QDF_DEBUG_PANIC("Failed to create pdev; errno:%d", ret);
Arun Kumar Khandavallia4234582019-03-20 16:16:05 +05301795 return -EINVAL;
Dustin Brown64204d22018-08-15 16:35:19 -07001796 }
1797
1798 hdd_debug("New pdev has been created with pdev_id = %u",
Dustin Brown07901ec2018-09-07 11:02:41 -07001799 hdd_ctx->pdev->pdev_objmgr.wlan_pdev_id);
Dustin Brown64204d22018-08-15 16:35:19 -07001800
Dustin Brown07901ec2018-09-07 11:02:41 -07001801 status = dispatcher_pdev_open(hdd_ctx->pdev);
Dustin Brown64204d22018-08-15 16:35:19 -07001802 if (QDF_IS_STATUS_ERROR(status)) {
1803 QDF_DEBUG_PANIC("dispatcher pdev open failed; status:%d",
1804 status);
Arun Kumar Khandavallia4234582019-03-20 16:16:05 +05301805 ret = qdf_status_to_os_return(status);
1806 goto exit;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301807 }
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001808
Sandeep Puligillab7beb472018-08-13 22:54:20 -07001809 status = hdd_component_pdev_open(hdd_ctx->pdev);
1810 if (QDF_IS_STATUS_ERROR(status)) {
1811 QDF_DEBUG_PANIC("hdd component pdev open failed; status:%d",
1812 status);
Arun Kumar Khandavallia4234582019-03-20 16:16:05 +05301813 ret = qdf_status_to_os_return(status);
1814 goto dispatcher_close;
Sandeep Puligillab7beb472018-08-13 22:54:20 -07001815 }
Arun Kumar Khandavallia4234582019-03-20 16:16:05 +05301816
Sravan Kumar Kairamcb5fd012018-07-04 17:43:22 +05301817 cdp_pdev_set_ctrl_pdev(cds_get_context(QDF_MODULE_ID_SOC),
1818 cds_get_context(QDF_MODULE_ID_TXRX),
Dustin Brown07901ec2018-09-07 11:02:41 -07001819 (struct cdp_ctrl_objmgr_pdev *)hdd_ctx->pdev);
Sravan Kumar Kairamcb5fd012018-07-04 17:43:22 +05301820
Dustin Brown07901ec2018-09-07 11:02:41 -07001821 wlan_pdev_set_dp_handle(hdd_ctx->pdev,
Sravan Kumar Kairamcb5fd012018-07-04 17:43:22 +05301822 cds_get_context(QDF_MODULE_ID_TXRX));
1823
Will Huang07244172018-05-14 14:23:30 +08001824 hdd_objmgr_update_tgt_max_vdev_psoc(hdd_ctx, cfg->max_intf_count);
1825
Dustin Brown1dbefe62018-09-11 16:32:03 -07001826 ucfg_ipa_set_dp_handle(hdd_ctx->psoc,
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301827 cds_get_context(QDF_MODULE_ID_SOC));
Dustin Brown1dbefe62018-09-11 16:32:03 -07001828 ucfg_ipa_set_txrx_handle(hdd_ctx->psoc,
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301829 cds_get_context(QDF_MODULE_ID_TXRX));
Dustin Brown07901ec2018-09-07 11:02:41 -07001830 ucfg_ipa_reg_sap_xmit_cb(hdd_ctx->pdev,
Vevek Venkatesan78f7f092019-05-23 17:16:28 +05301831 hdd_softap_ipa_start_xmit);
Dustin Brown07901ec2018-09-07 11:02:41 -07001832 ucfg_ipa_reg_send_to_nw_cb(hdd_ctx->pdev,
Vevek Venkatesan3b6be822019-05-28 18:19:15 +05301833 hdd_ipa_send_nbuf_to_network);
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301834
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05301835 status = ucfg_mlme_get_sub_20_chan_width(hdd_ctx->psoc,
1836 &sub_20_chan_width);
1837 if (QDF_IS_STATUS_ERROR(status)) {
1838 hdd_err("Failed to get sub_20_chan_width config");
Arun Kumar Khandavallia4234582019-03-20 16:16:05 +05301839 ret = qdf_status_to_os_return(status);
1840 goto pdev_close;
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05301841 }
1842
Naveen Rawat64e477e2016-05-20 10:34:56 -07001843 if (cds_cfg) {
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05301844 if (sub_20_chan_width !=
1845 WLAN_SUB_20_CH_WIDTH_NONE && !cfg->sub_20_support) {
Naveen Rawat64e477e2016-05-20 10:34:56 -07001846 hdd_err("User requested sub 20 MHz channel width but unsupported by FW.");
1847 cds_cfg->sub_20_channel_width =
1848 WLAN_SUB_20_CH_WIDTH_NONE;
1849 } else {
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05301850 cds_cfg->sub_20_channel_width = sub_20_chan_width;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001851 }
1852 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001853
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301854 status = ucfg_mlme_get_band_capability(hdd_ctx->psoc, &band_capability);
1855 if (QDF_IS_STATUS_ERROR(status)) {
1856 hdd_err("Failed to get MLME band capability");
Arun Kumar Khandavallia4234582019-03-20 16:16:05 +05301857 ret = qdf_status_to_os_return(status);
1858 goto pdev_close;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301859 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001860
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301861 /* first store the INI band capability */
1862 temp_band_cap = band_capability;
1863
1864 band_capability = cfg->band_cap;
Vignesh Viswanathan731186f2017-09-18 13:47:37 +05301865 hdd_ctx->is_fils_roaming_supported =
1866 cfg->services.is_fils_roaming_supported;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001867
Vignesh Viswanathan694e28e2018-01-18 20:53:57 +05301868 hdd_ctx->config->is_11k_offload_supported =
1869 cfg->services.is_11k_offload_supported;
1870
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08001871 /*
1872 * now overwrite the target band capability with INI
1873 * setting if INI setting is a subset
1874 */
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301875 if ((band_capability == BAND_ALL) &&
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001876 (temp_band_cap != BAND_ALL))
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301877 band_capability = temp_band_cap;
1878 else if ((band_capability != BAND_ALL) &&
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001879 (temp_band_cap != BAND_ALL) &&
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301880 (band_capability != temp_band_cap)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001881 hdd_warn("ini BandCapability not supported by the target");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001882 }
1883
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301884 status = ucfg_mlme_set_band_capability(hdd_ctx->psoc, band_capability);
1885 if (QDF_IS_STATUS_ERROR(status)) {
1886 hdd_err("Failed to set MLME Band Capability");
Arun Kumar Khandavallia4234582019-03-20 16:16:05 +05301887 ret = qdf_status_to_os_return(status);
1888 goto pdev_close;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301889 }
1890
1891 hdd_ctx->curr_band = band_capability;
Amar Singhal58b45ef2017-08-01 13:43:54 -07001892
Qun Zhang043635a2019-02-27 15:19:29 +08001893 status = wlan_hdd_update_wiphy_supported_band(hdd_ctx);
1894 if (QDF_IS_STATUS_ERROR(status)) {
1895 hdd_err("Failed to update wiphy band info");
Arun Kumar Khandavallia4234582019-03-20 16:16:05 +05301896 goto pdev_close;
Qun Zhang043635a2019-02-27 15:19:29 +08001897 }
1898
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301899 if (!cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001900 hdd_ctx->reg.reg_domain = cfg->reg_domain;
1901 hdd_ctx->reg.eeprom_rd_ext = cfg->eeprom_rd_ext;
1902 }
1903
1904 /* This can be extended to other configurations like ht, vht cap... */
1905
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05301906 if (!qdf_is_macaddr_zero(&cfg->hw_macaddr))
1907 qdf_mem_copy(&hdd_ctx->hw_macaddr, &cfg->hw_macaddr,
1908 QDF_MAC_ADDR_SIZE);
1909 else
1910 hdd_info("hw_mac is zero");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001911
1912 hdd_ctx->target_fw_version = cfg->target_fw_version;
Sandeep Puligilla3d6a8e22016-10-11 18:57:14 -07001913 hdd_ctx->target_fw_vers_ext = cfg->target_fw_vers_ext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001914
Ryan Hsuc6918552018-05-16 13:29:59 -07001915 hdd_ctx->hw_bd_id = cfg->hw_bd_id;
1916 qdf_mem_copy(&hdd_ctx->hw_bd_info, &cfg->hw_bd_info,
1917 sizeof(cfg->hw_bd_info));
1918
Dustin Brownad06be62019-02-04 14:52:56 -08001919 if (cfg->max_intf_count > WLAN_MAX_VDEVS) {
Dustin Brownbee82832018-07-23 10:10:51 -07001920 hdd_err("fw max vdevs (%u) > host max vdevs (%u); using %u",
Dustin Brownad06be62019-02-04 14:52:56 -08001921 cfg->max_intf_count, WLAN_MAX_VDEVS, WLAN_MAX_VDEVS);
1922 hdd_ctx->max_intf_count = WLAN_MAX_VDEVS;
Dustin Brownbee82832018-07-23 10:10:51 -07001923 } else {
1924 hdd_ctx->max_intf_count = cfg->max_intf_count;
1925 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001926
Jeff Johnsonf9176382018-07-17 19:15:58 -07001927 hdd_sar_target_config(hdd_ctx, cfg);
Jeff Johnsonc875e242016-09-23 18:12:34 -07001928 hdd_lpass_target_config(hdd_ctx, cfg);
Ryan Hsu3c8f79f2015-12-02 16:45:09 -08001929
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001930 hdd_ctx->ap_arpns_support = cfg->ap_arpns_support;
Pragaspathi Thilagarajeb367282019-02-19 00:42:28 +05301931 status = ucfg_mlme_set_fw_supported_roaming_akm(
1932 hdd_ctx->psoc,
1933 cfg->ft_akm_service_bitmap);
1934 if (QDF_IS_STATUS_ERROR(status))
1935 hdd_err("Failed to set ft akm suites bitmap");
1936
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001937 hdd_update_tgt_services(hdd_ctx, &cfg->services);
1938
1939 hdd_update_tgt_ht_cap(hdd_ctx, &cfg->ht_cap);
1940
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001941 hdd_update_tgt_vht_cap(hdd_ctx, &cfg->vht_cap);
Krishna Kumaar Natarajaned1efd92016-09-24 18:05:47 -07001942 if (cfg->services.en_11ax) {
1943 hdd_info("11AX: 11ax is enabled - update HDD config");
1944 hdd_update_tgt_he_cap(hdd_ctx, cfg);
1945 }
Varun Reddy Yeturue93d2462018-05-22 13:54:52 -07001946 hdd_update_tgt_twt_cap(hdd_ctx, cfg);
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07001947
gaurank kathpaliafa7ad0a2019-03-12 19:17:56 +05301948 for (band = NSS_CHAINS_BAND_2GHZ; band < NSS_CHAINS_BAND_MAX; band++) {
1949 sme_modify_nss_chains_tgt_cfg(hdd_ctx->mac_handle,
1950 QDF_STA_MODE, band);
1951 sme_modify_nss_chains_tgt_cfg(hdd_ctx->mac_handle,
1952 QDF_SAP_MODE, band);
1953 sme_modify_nss_chains_tgt_cfg(hdd_ctx->mac_handle,
1954 QDF_TDLS_MODE, band);
1955 sme_modify_nss_chains_tgt_cfg(hdd_ctx->mac_handle,
1956 QDF_P2P_DEVICE_MODE,
1957 band);
1958 sme_modify_nss_chains_tgt_cfg(hdd_ctx->mac_handle,
1959 QDF_OCB_MODE, band);
1960 sme_modify_nss_chains_tgt_cfg(hdd_ctx->mac_handle,
1961 QDF_TDLS_MODE, band);
1962 }
1963
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07001964 hdd_update_vdev_nss(hdd_ctx);
1965
gaurank kathpalia5fcefa92018-10-24 15:03:15 +05301966 hdd_ctx->dynamic_nss_chains_support =
1967 cfg->dynamic_nss_chains_support;
Arif Hussainbd5194c2018-11-27 19:01:15 -08001968 ucfg_mlme_get_fine_time_meas_cap(hdd_ctx->psoc, &fine_time_meas_cap);
1969 fine_time_meas_cap &= cfg->fine_time_measurement_cap;
1970 status = ucfg_mlme_set_fine_time_meas_cap(hdd_ctx->psoc,
1971 fine_time_meas_cap);
1972 if (QDF_IS_STATUS_ERROR(status)) {
1973 hdd_err("failed to set fine_time_meas_cap, 0x%x, ox%x",
1974 fine_time_meas_cap, cfg->fine_time_measurement_cap);
1975 ucfg_mlme_get_fine_time_meas_cap(hdd_ctx->psoc,
1976 &fine_time_meas_cap);
1977 }
1978
Krunal Sonie3531942016-04-12 17:43:53 -07001979 hdd_ctx->fine_time_meas_cap_target = cfg->fine_time_measurement_cap;
Arif Hussainbd5194c2018-11-27 19:01:15 -08001980 hdd_debug("fine_time_meas_cap: 0x%x", fine_time_meas_cap);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001981
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301982 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &bval);
1983 if (!QDF_IS_STATUS_SUCCESS(status))
1984 hdd_err("unable to get vht_enable2x2");
1985
1986 antenna_mode = (bval == 0x01) ?
Nitesh Shahe50711f2017-04-26 16:30:45 +05301987 HDD_ANTENNA_MODE_2X2 : HDD_ANTENNA_MODE_1X1;
1988 hdd_update_smps_antenna_mode(hdd_ctx, antenna_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001989 hdd_debug("Init current antenna mode: %d",
Arif Hussainee10f902017-12-27 16:30:17 -08001990 hdd_ctx->current_antenna_mode);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001991
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05301992 hdd_ctx->rcpi_enabled = cfg->rcpi_enabled;
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301993
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301994 status = ucfg_mlme_cfg_get_vht_tx_bfee_ant_supp(hdd_ctx->psoc,
Abhinav Kumare057b412018-10-09 17:28:16 +05301995 &value);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301996 if (QDF_IS_STATUS_ERROR(status)) {
1997 status = false;
1998 hdd_err("set tx_bfee_ant_supp failed");
1999 }
2000
Pragaspathi Thilagaraj6fc0a9a2019-05-17 16:49:45 +05302001 if ((value > MLME_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF) &&
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05302002 !cfg->tx_bfee_8ss_enabled) {
Pragaspathi Thilagaraj6fc0a9a2019-05-17 16:49:45 +05302003 status = ucfg_mlme_cfg_set_vht_tx_bfee_ant_supp(hdd_ctx->psoc,
2004 MLME_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05302005 if (QDF_IS_STATUS_ERROR(status)) {
2006 status = false;
2007 hdd_err("set tx_bfee_ant_supp failed");
2008 }
2009 }
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05302010
Jeff Johnson16528362018-06-14 12:34:16 -07002011 mac_handle = hdd_ctx->mac_handle;
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05302012
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05302013 hdd_debug("txBFCsnValue %d", value);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05302014
2015 /*
2016 * Update txBFCsnValue and NumSoundingDim values to vhtcap in wiphy
2017 */
2018 hdd_update_wiphy_vhtcap(hdd_ctx);
Manjeet Singh70d3d932016-12-20 20:41:10 +05302019
Jianmin Zhuc8bfffb2019-01-15 12:40:03 +08002020 hdd_update_vhtcap_2g(hdd_ctx);
2021
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05302022 hdd_ctx->wmi_max_len = cfg->wmi_max_len;
2023
Ashish Kumar Dhanotiya908925d2019-03-01 17:35:30 +05302024 wlan_config_sched_scan_plans_to_wiphy(hdd_ctx->wiphy, hdd_ctx->psoc);
Yue Macd359b72017-10-03 15:21:00 -07002025 /*
2026 * This needs to be done after HDD pdev is created and stored since
2027 * it will access the HDD pdev object lock.
2028 */
2029 hdd_runtime_suspend_context_init(hdd_ctx);
2030
Deepak Dhamdhere13230d32016-05-26 00:46:53 -07002031 /* Configure NAN datapath features */
2032 hdd_nan_datapath_target_config(hdd_ctx, cfg);
Nachiket Kukade85aa3782018-11-02 20:12:34 +05302033 ucfg_nan_set_tgt_caps(hdd_ctx->psoc, &cfg->nan_caps);
Arif Hussain759a0232017-03-20 13:17:18 -07002034 hdd_ctx->dfs_cac_offload = cfg->dfs_cac_offload;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08002035 hdd_ctx->lte_coex_ant_share = cfg->services.lte_coex_ant_share;
Liangwei Dong0da14262018-07-03 03:30:23 -04002036 hdd_ctx->obss_scan_offload = cfg->services.obss_scan_offload;
Wu Gao5f764082019-01-04 15:54:38 +08002037 status = ucfg_mlme_set_obss_detection_offload_enabled(
2038 hdd_ctx->psoc, cfg->obss_detection_offloaded);
Arif Hussainee10f902017-12-27 16:30:17 -08002039 if (QDF_IS_STATUS_ERROR(status))
2040 hdd_err("Couldn't pass WNI_CFG_OBSS_DETECTION_OFFLOAD to CFG");
Arif Hussain05fb4872018-01-03 16:02:55 -08002041
Wu Gao5f764082019-01-04 15:54:38 +08002042 status = ucfg_mlme_set_obss_color_collision_offload_enabled(
2043 hdd_ctx->psoc, cfg->obss_color_collision_offloaded);
Arif Hussain05fb4872018-01-03 16:02:55 -08002044 if (QDF_IS_STATUS_ERROR(status))
2045 hdd_err("Failed to set WNI_CFG_OBSS_COLOR_COLLISION_OFFLOAD");
Arif Hussain50689082019-03-26 12:07:58 -07002046
2047 ucfg_mlme_get_bcast_twt(hdd_ctx->psoc, &bval);
2048 if (bval)
2049 ucfg_mlme_set_bcast_twt(hdd_ctx->psoc, cfg->bcast_twt_support);
2050 else
2051 hdd_debug("bcast twt is disable in ini, fw cap %d",
2052 cfg->bcast_twt_support);
Arun Kumar Khandavallia4234582019-03-20 16:16:05 +05302053 return 0;
2054
2055dispatcher_close:
2056 dispatcher_pdev_close(hdd_ctx->pdev);
2057pdev_close:
2058 hdd_component_pdev_close(hdd_ctx->pdev);
2059exit:
2060 hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
2061
2062 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002063}
2064
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002065bool hdd_dfs_indicate_radar(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002066{
Jeff Johnson9d295242017-08-29 14:39:48 -07002067 struct hdd_adapter *adapter;
Jeff Johnson87251032017-08-29 13:31:11 -07002068 struct hdd_ap_ctx *ap_ctx;
Arif Hussain224d3812018-11-16 17:58:38 -08002069 bool dfs_disable_channel_switch = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002070
Jiachao Wuf610d912018-01-23 17:47:32 +08002071 if (!hdd_ctx) {
2072 hdd_info("Couldn't get hdd_ctx");
2073 return true;
2074 }
2075
Arif Hussain224d3812018-11-16 17:58:38 -08002076 ucfg_mlme_get_dfs_disable_channel_switch(hdd_ctx->psoc,
2077 &dfs_disable_channel_switch);
2078 if (dfs_disable_channel_switch) {
Jeff Johnson36e74c42017-09-18 08:15:42 -07002079 hdd_info("skip tx block hdd_ctx=%pK, disableDFSChSwitch=%d",
Arif Hussain224d3812018-11-16 17:58:38 -08002080 hdd_ctx, dfs_disable_channel_switch);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302081 return true;
Arif Hussaincd151632017-02-11 16:57:19 -08002082 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002083
Dustin Brown920397d2017-12-13 16:27:50 -08002084 hdd_for_each_adapter(hdd_ctx, adapter) {
Arif Hussaincd151632017-02-11 16:57:19 -08002085 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
2086
2087 if ((QDF_SAP_MODE == adapter->device_mode ||
2088 QDF_P2P_GO_MODE == adapter->device_mode) &&
Dustin Brown07901ec2018-09-07 11:02:41 -07002089 (wlan_reg_is_passive_or_disable_ch(hdd_ctx->pdev,
Jeff Johnson01206862017-10-27 20:55:59 -07002090 ap_ctx->operating_channel))) {
Arif Hussaincd151632017-02-11 16:57:19 -08002091 WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx =
2092 true;
Jeff Johnson7eb6e842019-02-23 14:33:34 -08002093 hdd_info("tx blocked for vdev: %d",
Jeff Johnson5a6fc962019-02-04 14:20:25 -08002094 adapter->vdev_id);
bings6fb9bf62018-07-05 14:01:53 +08002095 if (adapter->txrx_vdev)
2096 cdp_fc_vdev_flush(
2097 cds_get_context(QDF_MODULE_ID_SOC),
bings0e03a982018-05-09 08:40:59 +08002098 adapter->txrx_vdev);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302099 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002100 }
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302101
2102 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002103}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002104
Jeff Johnson030cd902018-11-11 10:19:40 -08002105bool hdd_is_valid_mac_address(const uint8_t *mac_addr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002106{
2107 int xdigit = 0;
2108 int separator = 0;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002109
Jeff Johnson030cd902018-11-11 10:19:40 -08002110 while (*mac_addr) {
2111 if (isxdigit(*mac_addr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002112 xdigit++;
Jeff Johnson030cd902018-11-11 10:19:40 -08002113 } else if (':' == *mac_addr) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002114 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
2115 break;
2116
2117 ++separator;
2118 } else {
2119 /* Invalid MAC found */
Jeff Johnson030cd902018-11-11 10:19:40 -08002120 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002121 }
Jeff Johnson030cd902018-11-11 10:19:40 -08002122 ++mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002123 }
2124 return xdigit == 12 && (separator == 5 || separator == 0);
2125}
2126
2127/**
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302128 * hdd_mon_mode_ether_setup() - Update monitor mode struct net_device.
2129 * @dev: Handle to struct net_device to be updated.
2130 *
2131 * Return: None
2132 */
2133static void hdd_mon_mode_ether_setup(struct net_device *dev)
2134{
2135 dev->header_ops = NULL;
2136 dev->type = ARPHRD_IEEE80211_RADIOTAP;
2137 dev->hard_header_len = ETH_HLEN;
2138 dev->mtu = ETH_DATA_LEN;
2139 dev->addr_len = ETH_ALEN;
2140 dev->tx_queue_len = 1000; /* Ethernet wants good queues */
2141 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
2142 dev->priv_flags |= IFF_TX_SKB_SHARING;
2143
2144 memset(dev->broadcast, 0xFF, ETH_ALEN);
2145}
2146
Nirav Shah73713f72018-05-17 14:50:41 +05302147#ifdef FEATURE_MONITOR_MODE_SUPPORT
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302148/**
chenguo71303962018-10-24 19:44:34 +08002149 * hdd_mon_turn_off_ps_and_wow() - Update monitor mode struct net_device.
2150 * @hdd_ctx: Pointer to HDD context.
2151 *
2152 * Return: None
2153 */
2154static void hdd_mon_turn_off_ps_and_wow(struct hdd_context *hdd_ctx)
2155{
2156 ucfg_pmo_set_power_save_mode(hdd_ctx->psoc, PS_NOT_SUPPORTED);
2157 ucfg_pmo_set_wow_enable(hdd_ctx->psoc, PMO_WOW_DISABLE_BOTH);
2158}
2159
2160/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002161 * __hdd__mon_open() - HDD Open function
2162 * @dev: Pointer to net_device structure
2163 *
2164 * This is called in response to ifconfig up
2165 *
2166 * Return: 0 for success; non-zero for failure
2167 */
2168static int __hdd_mon_open(struct net_device *dev)
2169{
2170 int ret;
Ravi Joshia307f632017-07-17 23:41:41 -07002171 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2172 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002173
Dustin Brownfdf17c12018-03-14 12:55:34 -07002174 hdd_enter_dev(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002175
2176 ret = wlan_hdd_validate_context(hdd_ctx);
2177 if (ret)
2178 return ret;
2179
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302180 hdd_mon_mode_ether_setup(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002181
2182 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
Rajeev Kumar473f9af2019-04-05 14:25:56 -07002183 ret = hdd_trigger_psoc_idle_restart(hdd_ctx);
Ravi Joshia307f632017-07-17 23:41:41 -07002184 if (ret) {
2185 hdd_err("Failed to start WLAN modules return");
2186 return ret;
2187 }
2188 hdd_err("hdd_wlan_start_modules() successful !");
2189
2190 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2191 ret = hdd_start_adapter(adapter);
2192 if (ret) {
2193 hdd_err("Failed to start adapter :%d",
2194 adapter->device_mode);
2195 return ret;
2196 }
2197 hdd_err("hdd_start_adapters() successful !");
2198 }
chenguo71303962018-10-24 19:44:34 +08002199 hdd_mon_turn_off_ps_and_wow(hdd_ctx);
Ravi Joshia307f632017-07-17 23:41:41 -07002200 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2201 }
2202
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002203 ret = hdd_set_mon_rx_cb(dev);
Ravi Joshi4f095952017-06-29 15:39:19 -07002204
2205 if (!ret)
2206 ret = hdd_enable_monitor_mode(dev);
2207
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002208 return ret;
2209}
2210
2211/**
2212 * hdd_mon_open() - Wrapper function for __hdd_mon_open to protect it from SSR
2213 * @dev: Pointer to net_device structure
2214 *
2215 * This is called in response to ifconfig up
2216 *
2217 * Return: 0 for success; non-zero for failure
2218 */
Dustin Brown0e1e1622019-01-17 11:00:22 -08002219static int hdd_mon_open(struct net_device *net_dev)
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002220{
Dustin Brown0e1e1622019-01-17 11:00:22 -08002221 int errno;
2222 struct osif_vdev_sync *vdev_sync;
2223
2224 errno = osif_vdev_sync_trans_start(net_dev, &vdev_sync);
2225 if (errno)
2226 return errno;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002227
Dustin Brown0e1e1622019-01-17 11:00:22 -08002228 errno = __hdd_mon_open(net_dev);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002229
Dustin Brown0e1e1622019-01-17 11:00:22 -08002230 osif_vdev_sync_trans_stop(vdev_sync);
2231
2232 return errno;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002233}
Nirav Shah73713f72018-05-17 14:50:41 +05302234#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002235
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002236static QDF_STATUS
2237wlan_hdd_update_dbs_scan_and_fw_mode_config(void)
2238{
2239 struct policy_mgr_dual_mac_config cfg = {0};
2240 QDF_STATUS status;
Krunal Sonie64b17e2018-12-13 16:00:02 -08002241 uint32_t chnl_sel_logic_conc = 0;
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002242 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Krunal Sonidf29bc42018-11-15 13:26:29 -08002243 uint8_t dual_mac_feature = DISABLE_DBS_CXN_AND_SCAN;
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002244
2245 if (!hdd_ctx) {
2246 hdd_err("HDD context is NULL");
2247 return QDF_STATUS_E_FAILURE;
2248 }
2249
Krunal Sonie64b17e2018-12-13 16:00:02 -08002250 /*
2251 * ROME platform doesn't support any DBS related commands in FW,
2252 * so if driver sends wmi command with dual_mac_config with all set to
2253 * 0 then FW wouldn't respond back and driver would timeout on waiting
2254 * for response. Check if FW supports DBS to eliminate ROME vs
2255 * NON-ROME platform.
2256 */
2257 if (!policy_mgr_find_if_fw_supports_dbs(hdd_ctx->psoc))
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002258 return QDF_STATUS_SUCCESS;
2259
2260 cfg.scan_config = 0;
2261 cfg.fw_mode_config = 0;
2262 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
Krunal Sonie64b17e2018-12-13 16:00:02 -08002263 if (policy_mgr_is_hw_dbs_capable(hdd_ctx->psoc)) {
2264 status =
2265 ucfg_policy_mgr_get_chnl_select_plcy(hdd_ctx->psoc,
2266 &chnl_sel_logic_conc);
2267 if (status != QDF_STATUS_SUCCESS) {
2268 hdd_err("can't get chnl sel policy, use def");
2269 return status;
2270 }
Krunal Sonidf29bc42018-11-15 13:26:29 -08002271 }
2272 status =
2273 ucfg_policy_mgr_get_dual_mac_feature(hdd_ctx->psoc,
2274 &dual_mac_feature);
2275 if (status != QDF_STATUS_SUCCESS) {
2276 hdd_err("ucfg_policy_mgr_get_dual_mac_feature failed, use def");
2277 return status;
2278 }
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002279
Krunal Sonidf29bc42018-11-15 13:26:29 -08002280 if (dual_mac_feature != DISABLE_DBS_CXN_AND_SCAN) {
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002281 status = policy_mgr_get_updated_scan_and_fw_mode_config(
Dustin Brown1dbefe62018-09-11 16:32:03 -07002282 hdd_ctx->psoc, &cfg.scan_config,
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002283 &cfg.fw_mode_config,
Krunal Sonidf29bc42018-11-15 13:26:29 -08002284 dual_mac_feature,
Krunal Sonie64b17e2018-12-13 16:00:02 -08002285 chnl_sel_logic_conc);
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002286
2287 if (status != QDF_STATUS_SUCCESS) {
2288 hdd_err("wma_get_updated_scan_and_fw_mode_config failed %d",
2289 status);
2290 return status;
2291 }
2292 }
2293
2294 hdd_debug("send scan_cfg: 0x%x fw_mode_cfg: 0x%x to fw",
2295 cfg.scan_config, cfg.fw_mode_config);
2296
2297 status = sme_soc_set_dual_mac_config(cfg);
2298 if (status != QDF_STATUS_SUCCESS) {
2299 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
2300 return status;
2301 }
2302
2303 return QDF_STATUS_SUCCESS;
2304}
2305
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002306/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302307 * hdd_start_adapter() - Wrapper function for device specific adapter
2308 * @adapter: pointer to HDD adapter
2309 *
2310 * This function is called to start the device specific adapter for
2311 * the mode passed in the adapter's device_mode.
2312 *
2313 * Return: 0 for success; non-zero for failure
2314 */
Jeff Johnson9d295242017-08-29 14:39:48 -07002315int hdd_start_adapter(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05302316{
2317
2318 int ret;
Jeff Johnsonc1e62782017-11-09 09:50:17 -08002319 enum QDF_OPMODE device_mode = adapter->device_mode;
Arun Khandavallifae92942016-08-01 13:31:08 +05302320
Dustin Brownfdf17c12018-03-14 12:55:34 -07002321 hdd_enter_dev(adapter->dev);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002322 hdd_debug("Start_adapter for mode : %d", adapter->device_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +05302323
2324 switch (device_mode) {
2325 case QDF_P2P_CLIENT_MODE:
2326 case QDF_P2P_DEVICE_MODE:
2327 case QDF_OCB_MODE:
2328 case QDF_STA_MODE:
2329 case QDF_MONITOR_MODE:
2330 ret = hdd_start_station_adapter(adapter);
2331 if (ret)
2332 goto err_start_adapter;
Alok Kumar81e1d732018-09-04 11:10:36 +05302333
2334 hdd_nud_ignore_tracking(adapter, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05302335 break;
2336 case QDF_P2P_GO_MODE:
2337 case QDF_SAP_MODE:
2338 ret = hdd_start_ap_adapter(adapter);
2339 if (ret)
2340 goto err_start_adapter;
2341 break;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05302342 case QDF_IBSS_MODE:
2343 /*
2344 * For IBSS interface is initialized as part of
2345 * hdd_init_station_mode()
2346 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08002347 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302348 case QDF_FTM_MODE:
Dustin Browndb2a8be2017-12-20 11:49:56 -08002349 /* vdevs are dynamically managed by firmware in FTM */
Arun Kumar Khandavallif573e062019-04-16 17:17:40 +05302350 hdd_register_wext(adapter->dev);
Dustin Browndb2a8be2017-12-20 11:49:56 -08002351 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302352 default:
2353 hdd_err("Invalid session type %d", device_mode);
2354 QDF_ASSERT(0);
2355 goto err_start_adapter;
2356 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08002357
Arun Khandavallifae92942016-08-01 13:31:08 +05302358 if (hdd_set_fw_params(adapter))
2359 hdd_err("Failed to set the FW params for the adapter!");
2360
Jeff Johnson912b1bb2019-03-06 10:12:36 -08002361 if (adapter->vdev_id != WLAN_UMAC_VDEV_ID_MAX) {
Dustin Browne7e71d32018-05-11 16:00:08 -07002362 ret = wlan_hdd_cfg80211_register_frames(adapter);
2363 if (ret < 0) {
2364 hdd_err("Failed to register frames - ret %d", ret);
2365 goto err_start_adapter;
2366 }
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302367 }
Dustin Browne7e71d32018-05-11 16:00:08 -07002368
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002369 wlan_hdd_update_dbs_scan_and_fw_mode_config();
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302370
Dustin Browndb2a8be2017-12-20 11:49:56 -08002371exit_with_success:
Dustin Browne74003f2018-03-14 12:51:58 -07002372 hdd_exit();
Dustin Browndb2a8be2017-12-20 11:49:56 -08002373
Arun Khandavallifae92942016-08-01 13:31:08 +05302374 return 0;
Dustin Browndb2a8be2017-12-20 11:49:56 -08002375
Arun Khandavallifae92942016-08-01 13:31:08 +05302376err_start_adapter:
2377 return -EINVAL;
2378}
2379
2380/**
Komal Seelamf2136bb2016-09-28 18:30:44 +05302381 * hdd_enable_power_management() - API to Enable Power Management
2382 *
2383 * API invokes Bus Interface Layer power management functionality
2384 *
2385 * Return: None
2386 */
2387static void hdd_enable_power_management(void)
2388{
2389 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2390
2391 if (!hif_ctx) {
2392 hdd_err("Bus Interface Context is Invalid");
2393 return;
2394 }
2395
2396 hif_enable_power_management(hif_ctx, cds_is_packet_log_enabled());
2397}
2398
2399/**
2400 * hdd_disable_power_management() - API to disable Power Management
2401 *
2402 * API disable Bus Interface Layer Power management functionality
2403 *
2404 * Return: None
2405 */
2406static void hdd_disable_power_management(void)
2407{
2408 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2409
2410 if (!hif_ctx) {
2411 hdd_err("Bus Interface Context is Invalid");
2412 return;
2413 }
2414
2415 hif_disable_power_management(hif_ctx);
2416}
2417
Ryan Hsuaadba072018-04-20 13:01:53 -07002418void hdd_update_hw_sw_info(struct hdd_context *hdd_ctx)
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302419{
2420 void *hif_sc;
Dustin Brown6f17a022017-07-19 13:40:55 -07002421 size_t target_hw_name_len;
2422 const char *target_hw_name;
Ryan Hsuaadba072018-04-20 13:01:53 -07002423 uint8_t *buf;
2424 uint32_t buf_len;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302425
2426 hif_sc = cds_get_context(QDF_MODULE_ID_HIF);
2427 if (!hif_sc) {
2428 hdd_err("HIF context is NULL");
2429 return;
2430 }
2431
Ryan Hsuaadba072018-04-20 13:01:53 -07002432 hif_get_hw_info(hif_sc, &hdd_ctx->target_hw_version,
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302433 &hdd_ctx->target_hw_revision,
Dustin Brown6f17a022017-07-19 13:40:55 -07002434 &target_hw_name);
2435
2436 if (hdd_ctx->target_hw_name)
2437 qdf_mem_free(hdd_ctx->target_hw_name);
2438
2439 target_hw_name_len = strlen(target_hw_name) + 1;
2440 hdd_ctx->target_hw_name = qdf_mem_malloc(target_hw_name_len);
2441 if (hdd_ctx->target_hw_name)
2442 qdf_mem_copy(hdd_ctx->target_hw_name, target_hw_name,
2443 target_hw_name_len);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302444
Ryan Hsuaadba072018-04-20 13:01:53 -07002445 buf = qdf_mem_malloc(WE_MAX_STR_LEN);
2446 if (buf) {
2447 buf_len = hdd_wlan_get_version(hdd_ctx, WE_MAX_STR_LEN, buf);
2448 hdd_info("%s", buf);
2449 qdf_mem_free(buf);
2450 }
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302451}
2452
2453/**
gbian62edd7e2017-03-07 13:12:13 +08002454 * hdd_update_cds_ac_specs_params() - update cds ac_specs params
2455 * @hdd_ctx: Pointer to hdd context
2456 *
2457 * Return: none
2458 */
2459static void
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002460hdd_update_cds_ac_specs_params(struct hdd_context *hdd_ctx)
gbian62edd7e2017-03-07 13:12:13 +08002461{
jitiphil8e15ea62018-11-16 18:05:34 +05302462 uint8_t tx_sched_wrr_param[TX_SCHED_WRR_PARAMS_NUM] = {0};
2463 qdf_size_t out_size = 0;
gbian62edd7e2017-03-07 13:12:13 +08002464 int i;
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002465 struct cds_context *cds_ctx;
gbian62edd7e2017-03-07 13:12:13 +08002466
Jeff Johnsond36fa332019-03-18 13:42:25 -07002467 if (!hdd_ctx)
gbian62edd7e2017-03-07 13:12:13 +08002468 return;
2469
Jeff Johnsond36fa332019-03-18 13:42:25 -07002470 if (!hdd_ctx->config) {
gbian62edd7e2017-03-07 13:12:13 +08002471 /* Do nothing if hdd_ctx is invalid */
2472 hdd_err("%s: Warning: hdd_ctx->cfg_ini is NULL", __func__);
2473 return;
2474 }
2475
2476 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2477
2478 if (!cds_ctx) {
2479 hdd_err("Invalid CDS Context");
2480 return;
2481 }
2482
Srinivas Girigowdad462f3b2019-03-25 14:05:33 -07002483 for (i = 0; i < QCA_WLAN_AC_ALL; i++) {
gbian62edd7e2017-03-07 13:12:13 +08002484 switch (i) {
Srinivas Girigowdad462f3b2019-03-25 14:05:33 -07002485 case QCA_WLAN_AC_BE:
jitiphil8e15ea62018-11-16 18:05:34 +05302486 qdf_uint8_array_parse(
2487 cfg_get(hdd_ctx->psoc,
2488 CFG_DP_ENABLE_TX_SCHED_WRR_BE),
2489 tx_sched_wrr_param,
2490 sizeof(tx_sched_wrr_param),
2491 &out_size);
gbian62edd7e2017-03-07 13:12:13 +08002492 break;
Srinivas Girigowdad462f3b2019-03-25 14:05:33 -07002493 case QCA_WLAN_AC_BK:
jitiphil8e15ea62018-11-16 18:05:34 +05302494 qdf_uint8_array_parse(
2495 cfg_get(hdd_ctx->psoc,
2496 CFG_DP_ENABLE_TX_SCHED_WRR_BK),
2497 tx_sched_wrr_param,
2498 sizeof(tx_sched_wrr_param),
2499 &out_size);
gbian62edd7e2017-03-07 13:12:13 +08002500 break;
Srinivas Girigowdad462f3b2019-03-25 14:05:33 -07002501 case QCA_WLAN_AC_VI:
jitiphil8e15ea62018-11-16 18:05:34 +05302502 qdf_uint8_array_parse(
2503 cfg_get(hdd_ctx->psoc,
2504 CFG_DP_ENABLE_TX_SCHED_WRR_VI),
2505 tx_sched_wrr_param,
2506 sizeof(tx_sched_wrr_param),
2507 &out_size);
gbian62edd7e2017-03-07 13:12:13 +08002508 break;
Srinivas Girigowdad462f3b2019-03-25 14:05:33 -07002509 case QCA_WLAN_AC_VO:
jitiphil8e15ea62018-11-16 18:05:34 +05302510 qdf_uint8_array_parse(
2511 cfg_get(hdd_ctx->psoc,
2512 CFG_DP_ENABLE_TX_SCHED_WRR_VO),
2513 tx_sched_wrr_param,
2514 sizeof(tx_sched_wrr_param),
2515 &out_size);
gbian62edd7e2017-03-07 13:12:13 +08002516 break;
2517 default:
gbian62edd7e2017-03-07 13:12:13 +08002518 break;
2519 }
2520
jitiphil8e15ea62018-11-16 18:05:34 +05302521 if (out_size == TX_SCHED_WRR_PARAMS_NUM) {
gbian62edd7e2017-03-07 13:12:13 +08002522 cds_ctx->ac_specs[i].wrr_skip_weight =
2523 tx_sched_wrr_param[0];
2524 cds_ctx->ac_specs[i].credit_threshold =
2525 tx_sched_wrr_param[1];
2526 cds_ctx->ac_specs[i].send_limit =
2527 tx_sched_wrr_param[2];
2528 cds_ctx->ac_specs[i].credit_reserve =
2529 tx_sched_wrr_param[3];
2530 cds_ctx->ac_specs[i].discard_weight =
2531 tx_sched_wrr_param[4];
2532 }
2533
jitiphil8e15ea62018-11-16 18:05:34 +05302534 out_size = 0;
gbian62edd7e2017-03-07 13:12:13 +08002535 }
2536}
2537
Ryan Hsuaadba072018-04-20 13:01:53 -07002538uint32_t hdd_wlan_get_version(struct hdd_context *hdd_ctx,
2539 const size_t version_len, uint8_t *version)
2540{
2541 uint32_t size;
2542 uint32_t msp_id = 0, mspid = 0, siid = 0, crmid = 0, sub_id = 0;
2543
2544 if (!hdd_ctx) {
2545 hdd_err("Invalid context, HDD context is null");
2546 return 0;
2547 }
2548
Ashish Kumar Dhanotiya7353f882018-05-15 12:50:19 +05302549 if (!version || version_len == 0) {
Ryan Hsuaadba072018-04-20 13:01:53 -07002550 hdd_err("Invalid buffer pointr or buffer len\n");
2551 return 0;
2552 }
2553
2554 msp_id = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
2555 mspid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
2556 siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
2557 crmid = hdd_ctx->target_fw_version & 0x7fff;
2558 sub_id = (hdd_ctx->target_fw_vers_ext & 0xf0000000) >> 28;
2559
2560 size = scnprintf(version, version_len,
Ryan Hsuc6918552018-05-16 13:29:59 -07002561 "Host SW:%s, FW:%d.%d.%d.%d.%d, HW:%s, Board ver: %x Ref design id: %x, Customer id: %x, Project id: %x, Board Data Rev: %x",
Ryan Hsuaadba072018-04-20 13:01:53 -07002562 QWLAN_VERSIONSTR,
2563 msp_id, mspid, siid, crmid, sub_id,
Ryan Hsuc6918552018-05-16 13:29:59 -07002564 hdd_ctx->target_hw_name,
2565 hdd_ctx->hw_bd_info.bdf_version,
2566 hdd_ctx->hw_bd_info.ref_design_id,
2567 hdd_ctx->hw_bd_info.customer_id,
2568 hdd_ctx->hw_bd_info.project_id,
2569 hdd_ctx->hw_bd_info.board_data_rev);
Ryan Hsuaadba072018-04-20 13:01:53 -07002570
2571 return size;
2572}
2573
Rachit Kankane0dc3e852018-05-07 17:33:42 +05302574int hdd_set_11ax_rate(struct hdd_adapter *adapter, int set_value,
2575 struct sap_config *sap_config)
2576{
2577 uint8_t preamble = 0, nss = 0, rix = 0;
2578 int ret;
2579 mac_handle_t mac_handle = adapter->hdd_ctx->mac_handle;
2580
2581 if (!sap_config) {
2582 if (!sme_is_feature_supported_by_fw(DOT11AX)) {
2583 hdd_err("Target does not support 11ax");
2584 return -EIO;
2585 }
2586 } else if (sap_config->SapHw_mode != eCSR_DOT11_MODE_11ax &&
2587 sap_config->SapHw_mode != eCSR_DOT11_MODE_11ax_ONLY) {
2588 hdd_err("Invalid hw mode, SAP hw_mode= 0x%x, ch = %d",
2589 sap_config->SapHw_mode, sap_config->channel);
2590 return -EIO;
2591 }
2592
2593 if (set_value != 0xff) {
2594 rix = RC_2_RATE_IDX_11AX(set_value);
2595 preamble = WMI_RATE_PREAMBLE_HE;
2596 nss = HT_RC_2_STREAMS_11AX(set_value);
2597
2598 set_value = hdd_assemble_rate_code(preamble, nss, rix);
2599 } else {
Jeff Johnson5a6fc962019-02-04 14:20:25 -08002600 ret = sme_set_auto_rate_he_ltf(mac_handle, adapter->vdev_id,
Rachit Kankane0dc3e852018-05-07 17:33:42 +05302601 QCA_WLAN_HE_LTF_AUTO);
2602 }
2603
2604 hdd_info("SET_11AX_RATE val %d rix %d preamble %x nss %d",
2605 set_value, rix, preamble, nss);
2606
Jeff Johnson5a6fc962019-02-04 14:20:25 -08002607 ret = wma_cli_set_command(adapter->vdev_id,
Rachit Kankane0dc3e852018-05-07 17:33:42 +05302608 WMI_VDEV_PARAM_FIXED_RATE,
2609 set_value, VDEV_CMD);
2610
2611 return ret;
2612}
2613
2614int hdd_assemble_rate_code(uint8_t preamble, uint8_t nss, uint8_t rate)
2615{
2616 int set_value;
2617
2618 if (sme_is_feature_supported_by_fw(DOT11AX))
2619 set_value = WMI_ASSEMBLE_RATECODE_V1(rate, nss, preamble);
2620 else
2621 set_value = (preamble << 6) | (nss << 4) | rate;
2622
2623 return set_value;
2624}
2625
Liangwei Dong3fa5cba2018-07-16 06:41:55 -04002626#ifdef FEATURE_WLAN_WAPI
2627/**
2628 * hdd_wapi_security_sta_exist() - return wapi security sta exist or not
2629 *
2630 * This API returns the wapi security station exist or not
2631 *
2632 * Return: true - wapi security station exist
2633 */
2634static bool hdd_wapi_security_sta_exist(void)
2635{
2636 struct hdd_adapter *adapter = NULL;
2637 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
2638
2639 hdd_for_each_adapter(hdd_ctx, adapter) {
2640 if ((adapter->device_mode == QDF_STA_MODE) &&
2641 adapter->wapi_info.wapi_mode &&
2642 (adapter->wapi_info.wapi_auth_mode != WAPI_AUTH_MODE_OPEN))
2643 return true;
2644 }
2645 return false;
2646}
2647#else
2648static bool hdd_wapi_security_sta_exist(void)
2649{
2650 return false;
2651}
2652#endif
2653
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002654#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002655static enum policy_mgr_con_mode wlan_hdd_get_mode_for_non_connected_vdev(
2656 struct wlan_objmgr_psoc *psoc, uint8_t vdev_id)
2657{
Jeff Johnson9d295242017-08-29 14:39:48 -07002658 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002659 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002660
2661 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2662 if (!adapter) {
2663 hdd_err("Adapter is NULL");
2664 return PM_MAX_NUM_OF_MODE;
2665 }
2666
2667 return policy_mgr_convert_device_mode_to_qdf_type(
2668 adapter->device_mode);
2669}
2670
Abhishek Singh3bbf6cb2019-03-28 14:05:43 +05302671/**
2672 * hdd_is_chan_switch_in_progress() - Check if any adapter has channel switch in
2673 * progress
2674 *
2675 * Return: true, if any adapter has channel switch in
2676 * progress else false
2677 */
2678static bool hdd_is_chan_switch_in_progress(void)
2679{
2680 struct hdd_adapter *adapter = NULL;
2681 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
2682
2683 hdd_for_each_adapter(hdd_ctx, adapter) {
2684 if ((adapter->device_mode == QDF_SAP_MODE ||
2685 adapter->device_mode == QDF_P2P_GO_MODE) &&
2686 qdf_atomic_read(&adapter->ch_switch_in_progress)) {
2687 hdd_debug("channel switch progress for vdev_id %d",
2688 adapter->vdev_id);
2689 return true;
2690 }
2691 }
2692
2693 return false;
2694}
2695
2696
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002697static void hdd_register_policy_manager_callback(
2698 struct wlan_objmgr_psoc *psoc)
2699{
2700 struct policy_mgr_hdd_cbacks hdd_cbacks;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07002701
Liangwei Dong3fa5cba2018-07-16 06:41:55 -04002702 qdf_mem_zero(&hdd_cbacks, sizeof(hdd_cbacks));
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002703 hdd_cbacks.sap_restart_chan_switch_cb =
Jeff Johnson23812942017-10-06 11:33:55 -07002704 hdd_sap_restart_chan_switch_cb;
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002705 hdd_cbacks.wlan_hdd_get_channel_for_sap_restart =
2706 wlan_hdd_get_channel_for_sap_restart;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002707 hdd_cbacks.get_mode_for_non_connected_vdev =
2708 wlan_hdd_get_mode_for_non_connected_vdev;
Yeshwanth Sriram Guntuka469f9572018-02-12 13:28:22 +05302709 hdd_cbacks.hdd_get_device_mode = hdd_get_device_mode;
Liangwei Dong3fa5cba2018-07-16 06:41:55 -04002710 hdd_cbacks.hdd_wapi_security_sta_exist =
2711 hdd_wapi_security_sta_exist;
Abhishek Singh3bbf6cb2019-03-28 14:05:43 +05302712 hdd_cbacks.hdd_is_chan_switch_in_progress =
2713 hdd_is_chan_switch_in_progress;
2714
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002715 if (QDF_STATUS_SUCCESS !=
2716 policy_mgr_register_hdd_cb(psoc, &hdd_cbacks)) {
2717 hdd_err("HDD callback registration with policy manager failed");
2718 }
2719}
2720#else
2721static void hdd_register_policy_manager_callback(
2722 struct wlan_objmgr_psoc *psoc)
2723{
2724}
2725#endif
2726
Nachiket Kukade2fb1fdb2019-01-08 15:35:27 +05302727#ifdef WLAN_FEATURE_NAN
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002728static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002729{
2730 struct nan_callbacks cb_obj = {0};
2731
2732 cb_obj.ndi_open = hdd_ndi_open;
2733 cb_obj.ndi_close = hdd_ndi_close;
2734 cb_obj.ndi_start = hdd_ndi_start;
2735 cb_obj.ndi_delete = hdd_ndi_delete;
2736 cb_obj.drv_ndi_create_rsp_handler = hdd_ndi_drv_ndi_create_rsp_handler;
2737 cb_obj.drv_ndi_delete_rsp_handler = hdd_ndi_drv_ndi_delete_rsp_handler;
2738
Naveen Rawat37f62c82017-03-26 22:24:43 -07002739 cb_obj.new_peer_ind = hdd_ndp_new_peer_handler;
Naveen Rawatb3143ea2017-03-26 22:25:46 -07002740 cb_obj.peer_departed_ind = hdd_ndp_peer_departed_handler;
Naveen Rawat37f62c82017-03-26 22:24:43 -07002741
Dustin Brown1dbefe62018-09-11 16:32:03 -07002742 os_if_nan_register_hdd_callbacks(hdd_ctx->psoc, &cb_obj);
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002743}
jiadff1ac132018-11-26 16:27:48 +08002744#else
2745static inline void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
2746{
2747}
2748#endif
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002749
Dustin Brown26b3d042017-12-21 11:13:27 -08002750#ifdef CONFIG_LEAK_DETECTION
Dustin Brown4c5b9902017-12-19 11:17:19 -08002751/**
2752 * hdd_check_for_leaks() - Perform runtime memory leak checks
Dustin Browna6246dd2018-05-24 14:35:58 -07002753 * @hdd_ctx: the global HDD context
Dustin Brown29533f22018-07-24 13:11:56 -07002754 * @is_ssr: true if SSR is in progress
Dustin Brown4c5b9902017-12-19 11:17:19 -08002755 *
2756 * This API triggers runtime memory leak detection. This feature enforces the
2757 * policy that any memory allocated at runtime must also be released at runtime.
2758 *
2759 * Allocating memory at runtime and releasing it at unload is effectively a
2760 * memory leak for configurations which never unload (e.g. LONU, statically
2761 * compiled driver). Such memory leaks are NOT false positives, and must be
2762 * fixed.
2763 *
2764 * Return: None
2765 */
Dustin Brown29533f22018-07-24 13:11:56 -07002766static void hdd_check_for_leaks(struct hdd_context *hdd_ctx, bool is_ssr)
Dustin Brown4bc0a622017-12-06 15:56:50 -08002767{
Dustin Brown4c5b9902017-12-19 11:17:19 -08002768 /* DO NOT REMOVE these checks; for false positives, read above first */
2769
Dustin Brown1dbefe62018-09-11 16:32:03 -07002770 wlan_objmgr_psoc_check_for_peer_leaks(hdd_ctx->psoc);
2771 wlan_objmgr_psoc_check_for_vdev_leaks(hdd_ctx->psoc);
2772 wlan_objmgr_psoc_check_for_pdev_leaks(hdd_ctx->psoc);
Dustin Brown29533f22018-07-24 13:11:56 -07002773
2774 /* many adapter resources are not freed by design during SSR */
2775 if (is_ssr)
2776 return;
2777
Dustin Brownc2796312019-03-13 16:43:36 -07002778 qdf_delayed_work_check_for_leaks();
Dustin Brown677e0862017-10-10 16:30:09 -07002779 qdf_mc_timer_check_for_leaks();
Dustin Brown8e711502017-12-07 16:49:11 -08002780 qdf_nbuf_map_check_for_leaks();
Dustin Brown4a93bb52019-03-13 11:46:34 -07002781 qdf_periodic_work_check_for_leaks();
Dustin Browne6b9d5a2017-12-14 15:18:49 -08002782 qdf_mem_check_for_leaks();
Dustin Brown4bc0a622017-12-06 15:56:50 -08002783}
2784
Dustin Brown26b3d042017-12-21 11:13:27 -08002785#define hdd_debug_domain_set(domain) qdf_debug_domain_set(domain)
2786#else
Dustin Brown29533f22018-07-24 13:11:56 -07002787static inline void hdd_check_for_leaks(struct hdd_context *hdd_ctx, bool is_ssr)
2788{ }
Dustin Brown26b3d042017-12-21 11:13:27 -08002789
2790#define hdd_debug_domain_set(domain)
2791#endif /* CONFIG_LEAK_DETECTION */
2792
gbian62edd7e2017-03-07 13:12:13 +08002793/**
Paul Zhange03cf4c2018-01-19 18:33:22 +08002794 * hdd_update_country_code - Update country code
2795 * @hdd_ctx: HDD context
2796 *
2797 * Update country code based on module parameter country_code
2798 *
2799 * Return: 0 on success and errno on failure
2800 */
2801static int hdd_update_country_code(struct hdd_context *hdd_ctx)
2802{
2803 if (!country_code)
2804 return 0;
2805
2806 return hdd_reg_set_country(hdd_ctx, country_code);
2807}
2808
Dustin Browne7e71d32018-05-11 16:00:08 -07002809int hdd_wlan_start_modules(struct hdd_context *hdd_ctx, bool reinit)
Arun Khandavallifae92942016-08-01 13:31:08 +05302810{
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002811 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05302812 qdf_device_t qdf_dev;
2813 QDF_STATUS status;
Arun Khandavallifae92942016-08-01 13:31:08 +05302814 bool unint = false;
2815 void *hif_ctx;
Jingxiang Ge95912f82018-04-19 12:01:26 +08002816 struct target_psoc_info *tgt_hdl;
Arun Khandavallifae92942016-08-01 13:31:08 +05302817
Arun Khandavallifae92942016-08-01 13:31:08 +05302818 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2819 if (!qdf_dev) {
2820 hdd_err("QDF Device Context is Invalid return");
2821 return -EINVAL;
2822 }
2823
Dustin Brown4c663222018-10-23 14:19:36 -07002824 hdd_psoc_idle_timer_stop(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05302825
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302826 if (hdd_ctx->driver_status == DRIVER_MODULES_ENABLED) {
Dustin Brown1e3ec6b2018-08-07 11:18:47 -07002827 hdd_debug("Driver modules already Enabled");
Dustin Browne74003f2018-03-14 12:51:58 -07002828 hdd_exit();
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302829 return 0;
2830 }
2831
Arun Khandavallifae92942016-08-01 13:31:08 +05302832 switch (hdd_ctx->driver_status) {
2833 case DRIVER_MODULES_UNINITIALIZED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002834 hdd_info("Wlan transitioning (UNINITIALIZED -> CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +05302835 unint = true;
2836 /* Fall through dont add break here */
2837 case DRIVER_MODULES_CLOSED:
Dustin Brown1a20b082018-08-03 17:27:15 -07002838 hdd_info("Wlan transitioning (CLOSED -> ENABLED)");
Dustin Brown550f6d22017-12-14 15:44:01 -08002839
Dustin Brown26b3d042017-12-21 11:13:27 -08002840 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_ACTIVE);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002841
Arun Khandavallifae92942016-08-01 13:31:08 +05302842 if (!reinit && !unint) {
2843 ret = pld_power_on(qdf_dev->dev);
2844 if (ret) {
Dustin Brown1e3ec6b2018-08-07 11:18:47 -07002845 hdd_err("Failed to power up device; errno:%d",
Dustin Browndca39692017-11-09 15:30:25 -08002846 ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302847 goto release_lock;
2848 }
2849 }
Yuanyuan Liuf8fe4bc2017-06-07 16:55:58 -07002850
2851 pld_set_fw_log_mode(hdd_ctx->parent_dev,
2852 hdd_ctx->config->enable_fw_log);
Arun Khandavallifae92942016-08-01 13:31:08 +05302853 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
2854 qdf_dev->bus_type,
2855 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
2856 HIF_ENABLE_TYPE_PROBE);
2857 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002858 hdd_err("Failed to open hif; errno: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302859 goto power_down;
2860 }
2861
2862 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05302863 if (!hif_ctx) {
2864 hdd_err("hif context is null!!");
Dustin Browndca39692017-11-09 15:30:25 -08002865 ret = -EINVAL;
Arun Khandavalli1318b992016-08-09 11:04:57 +05302866 goto power_down;
2867 }
2868
Arun Khandavallifae92942016-08-01 13:31:08 +05302869 status = ol_cds_init(qdf_dev, hif_ctx);
2870 if (status != QDF_STATUS_SUCCESS) {
Dustin Browndca39692017-11-09 15:30:25 -08002871 hdd_err("No Memory to Create BMI Context; status: %d",
2872 status);
2873 ret = qdf_status_to_os_return(status);
Arun Khandavallifae92942016-08-01 13:31:08 +05302874 goto hif_close;
2875 }
2876
Nirav Shah6aeecf92019-02-13 14:05:03 +05302877 if (hdd_get_conparam() == QDF_GLOBAL_EPPING_MODE) {
2878 status = epping_open();
2879 if (status) {
2880 hdd_err("Failed to open in epping mode: %d",
2881 status);
2882 ret = -EINVAL;
2883 goto cds_free;
2884 }
2885
2886 status = epping_enable(qdf_dev->dev, false);
2887 if (status) {
2888 hdd_err("Failed to enable in epping mode : %d",
2889 status);
2890 epping_close();
2891 goto cds_free;
2892 }
2893
2894 hdd_info("epping mode enabled");
2895 break;
2896 }
2897
jitiphil4c256a32018-09-07 08:51:52 +05302898 ucfg_ipa_component_config_update(hdd_ctx->psoc);
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302899
gbian62edd7e2017-03-07 13:12:13 +08002900 hdd_update_cds_ac_specs_params(hdd_ctx);
2901
Dustin Brown1dbefe62018-09-11 16:32:03 -07002902 status = hdd_component_psoc_open(hdd_ctx->psoc);
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05302903 if (QDF_IS_STATUS_ERROR(status)) {
2904 hdd_err("Failed to Open legacy components; status: %d",
2905 status);
2906 ret = qdf_status_to_os_return(status);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05302907 goto cds_free;
2908 }
2909
2910 ret = hdd_update_config(hdd_ctx);
2911 if (ret) {
2912 hdd_err("Failed to update configuration; errno: %d",
2913 ret);
2914 goto cds_free;
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05302915 }
2916
Rakshith Suresh Patkard9f4e612018-09-12 12:10:38 +05302917 status = wbuff_module_init();
2918 if (QDF_IS_STATUS_ERROR(status))
2919 hdd_err("WBUFF init unsuccessful; status: %d", status);
2920
Dustin Brown1dbefe62018-09-11 16:32:03 -07002921 status = cds_open(hdd_ctx->psoc);
Dustin Brown28b17892017-10-10 13:29:38 -07002922 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002923 hdd_err("Failed to Open CDS; status: %d", status);
Dustin Brown28b17892017-10-10 13:29:38 -07002924 ret = qdf_status_to_os_return(status);
Krunal Sonie71838d2018-09-27 10:45:05 -07002925 goto psoc_close;
Arun Khandavallifae92942016-08-01 13:31:08 +05302926 }
2927
Vignesh Viswanathan987f0bb2018-09-17 17:00:29 +05302928 hdd_ctx->mac_handle = cds_get_context(QDF_MODULE_ID_SME);
2929
Manjunathappa Prakashb6b4ff12018-06-04 12:32:33 -07002930 if (hdd_ctx->config->rx_thread_affinity_mask)
2931 cds_set_rx_thread_cpu_mask(
2932 hdd_ctx->config->rx_thread_affinity_mask);
2933
2934 /* initialize components configurations after psoc open */
Mukul Sharma9d797a02017-01-05 20:26:03 +05302935 ret = hdd_update_components_config(hdd_ctx);
2936 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002937 hdd_err("Failed to update component configs; errno: %d",
Mukul Sharma9d797a02017-01-05 20:26:03 +05302938 ret);
2939 goto close;
2940 }
Sourav Mohapatra674925f2018-04-16 11:16:58 +05302941
Dustin Brown1dbefe62018-09-11 16:32:03 -07002942 status = cds_dp_open(hdd_ctx->psoc);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002943 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002944 hdd_err("Failed to Open cds post open; status: %d",
2945 status);
2946 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002947 goto close;
2948 }
Mukul Sharma9d797a02017-01-05 20:26:03 +05302949
Sourav Mohapatra674925f2018-04-16 11:16:58 +05302950 ret = hdd_register_cb(hdd_ctx);
2951 if (ret) {
2952 hdd_err("Failed to register HDD callbacks!");
2953 goto cds_txrx_free;
2954 }
2955
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002956 /*
2957 * NAN compoenet requires certian operations like, open adapter,
2958 * close adapter, etc. to be initiated by HDD, for those
2959 * register HDD callbacks with UMAC's NAN componenet.
2960 */
2961 hdd_nan_register_callbacks(hdd_ctx);
2962
Jeff Johnson3a280122017-09-13 07:42:00 -07002963 status = cds_pre_enable();
Arun Khandavallifae92942016-08-01 13:31:08 +05302964 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002965 hdd_err("Failed to pre-enable CDS; status: %d", status);
2966 ret = qdf_status_to_os_return(status);
Sourav Mohapatra674925f2018-04-16 11:16:58 +05302967 goto deregister_cb;
Arun Khandavallifae92942016-08-01 13:31:08 +05302968 }
2969
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002970 hdd_register_policy_manager_callback(
Dustin Brown1dbefe62018-09-11 16:32:03 -07002971 hdd_ctx->psoc);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002972
Arunk Khandavalli890f6d92018-10-30 20:18:28 +05302973 hdd_sysfs_create_driver_root_obj();
Dustin Brown1dbefe62018-09-11 16:32:03 -07002974 hdd_sysfs_create_version_interface(hdd_ctx->psoc);
Arunk Khandavalli890f6d92018-10-30 20:18:28 +05302975 hdd_sysfs_create_powerstats_interface();
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302976 hdd_update_hw_sw_info(hdd_ctx);
Dustin Brown550f6d22017-12-14 15:44:01 -08002977
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302978 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2979 hdd_err("in ftm mode, no need to configure cds modules");
Dustin Browndca39692017-11-09 15:30:25 -08002980 ret = -EINVAL;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302981 break;
2982 }
Dustin Browndca39692017-11-09 15:30:25 -08002983
Dustin Browne7e71d32018-05-11 16:00:08 -07002984 ret = hdd_configure_cds(hdd_ctx);
Dustin Browndca39692017-11-09 15:30:25 -08002985 if (ret) {
2986 hdd_err("Failed to Enable cds modules; errno: %d", ret);
Arunk Khandavalli890f6d92018-10-30 20:18:28 +05302987 goto destroy_driver_sysfs;
Arun Khandavallifae92942016-08-01 13:31:08 +05302988 }
Dustin Browndca39692017-11-09 15:30:25 -08002989
Komal Seelamf2136bb2016-09-28 18:30:44 +05302990 hdd_enable_power_management();
Dustin Brown550f6d22017-12-14 15:44:01 -08002991
Arun Khandavallifae92942016-08-01 13:31:08 +05302992 break;
Dustin Brown550f6d22017-12-14 15:44:01 -08002993
Arun Khandavallifae92942016-08-01 13:31:08 +05302994 default:
Dustin Brown1e3ec6b2018-08-07 11:18:47 -07002995 QDF_DEBUG_PANIC("Unknown driver state:%d",
Arun Khandavallifae92942016-08-01 13:31:08 +05302996 hdd_ctx->driver_status);
Dustin Browndca39692017-11-09 15:30:25 -08002997 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05302998 goto release_lock;
2999 }
Dustin Brown550f6d22017-12-14 15:44:01 -08003000
Dustin Brown1a20b082018-08-03 17:27:15 -07003001 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
3002 hdd_info("Wlan transitioned (now ENABLED)");
3003
Dustin Browne74003f2018-03-14 12:51:58 -07003004 hdd_exit();
Dustin Brown550f6d22017-12-14 15:44:01 -08003005
Arun Khandavallifae92942016-08-01 13:31:08 +05303006 return 0;
3007
Arunk Khandavalli890f6d92018-10-30 20:18:28 +05303008destroy_driver_sysfs:
3009 hdd_sysfs_destroy_powerstats_interface();
3010 hdd_sysfs_destroy_version_interface();
3011 hdd_sysfs_destroy_driver_root_obj();
Rajeev Kumarbe021242017-02-16 16:12:23 -08003012 cds_post_disable();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08003013
Sourav Mohapatra674925f2018-04-16 11:16:58 +05303014deregister_cb:
3015 hdd_deregister_cb(hdd_ctx);
3016
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07003017cds_txrx_free:
Dustin Brown1dbefe62018-09-11 16:32:03 -07003018 tgt_hdl = wlan_psoc_get_tgt_if_handle(hdd_ctx->psoc);
Jingxiang Ge95912f82018-04-19 12:01:26 +08003019
3020 if (tgt_hdl && target_psoc_get_wmi_ready(tgt_hdl)) {
3021 hdd_runtime_suspend_context_deinit(hdd_ctx);
Dustin Brown07901ec2018-09-07 11:02:41 -07003022 dispatcher_pdev_close(hdd_ctx->pdev);
Jingxiang Ge95912f82018-04-19 12:01:26 +08003023 hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
3024 }
3025
Dustin Brown1dbefe62018-09-11 16:32:03 -07003026 cds_dp_close(hdd_ctx->psoc);
Dustin Brown550f6d22017-12-14 15:44:01 -08003027
Arun Khandavallifae92942016-08-01 13:31:08 +05303028close:
Rajeev Kumara3f672f2017-02-16 13:59:37 -08003029 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -08003030 hdd_info("Wlan transition aborted (now CLOSED)");
3031
Dustin Brown1dbefe62018-09-11 16:32:03 -07003032 cds_close(hdd_ctx->psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05303033
Krunal Sonie71838d2018-09-27 10:45:05 -07003034psoc_close:
Dustin Brown1dbefe62018-09-11 16:32:03 -07003035 hdd_component_psoc_close(hdd_ctx->psoc);
Dustin Brown28b17892017-10-10 13:29:38 -07003036 cds_deinit_ini_config();
3037
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07003038cds_free:
Arun Khandavallifae92942016-08-01 13:31:08 +05303039 ol_cds_free();
3040
3041hif_close:
Jeff Johnson60dc2b12017-09-28 14:56:02 -07003042 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
3043 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05303044power_down:
3045 if (!reinit && !unint)
3046 pld_power_off(qdf_dev->dev);
3047release_lock:
Abhinav Kumar7ae9b7b2017-12-19 15:11:54 +05303048 if (hdd_ctx->target_hw_name) {
3049 qdf_mem_free(hdd_ctx->target_hw_name);
3050 hdd_ctx->target_hw_name = NULL;
3051 }
Dustin Brown29533f22018-07-24 13:11:56 -07003052
3053 hdd_check_for_leaks(hdd_ctx, reinit);
Dustin Brown26b3d042017-12-21 11:13:27 -08003054 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -08003055
Dustin Browne74003f2018-03-14 12:51:58 -07003056 hdd_exit();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08003057
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07003058 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05303059}
3060
Naveen Rawat910726a2017-03-06 11:42:51 -08003061#ifdef WIFI_POS_CONVERGED
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003062static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08003063{
3064 int ret = os_if_wifi_pos_register_nl();
3065
3066 if (ret)
3067 hdd_err("os_if_wifi_pos_register_nl failed");
3068
3069 return ret;
3070}
3071
3072static int hdd_deactivate_wifi_pos(void)
3073{
3074 int ret = os_if_wifi_pos_deregister_nl();
3075
3076 if (ret)
3077 hdd_err("os_if_wifi_pos_deregister_nl failed");
3078
3079 return ret;
3080}
3081
3082/**
3083 * hdd_populate_wifi_pos_cfg - populates wifi_pos parameters
3084 * @hdd_ctx: hdd context
3085 *
3086 * Return: status of operation
3087 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003088static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08003089{
Dustin Brown1dbefe62018-09-11 16:32:03 -07003090 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Wu Gao1ab05582018-11-08 16:22:49 +08003091 uint16_t neighbor_scan_max_chan_time;
3092 uint16_t neighbor_scan_min_chan_time;
Naveen Rawat910726a2017-03-06 11:42:51 -08003093
3094 wifi_pos_set_oem_target_type(psoc, hdd_ctx->target_type);
3095 wifi_pos_set_oem_fw_version(psoc, hdd_ctx->target_fw_version);
3096 wifi_pos_set_drv_ver_major(psoc, QWLAN_VERSION_MAJOR);
3097 wifi_pos_set_drv_ver_minor(psoc, QWLAN_VERSION_MINOR);
3098 wifi_pos_set_drv_ver_patch(psoc, QWLAN_VERSION_PATCH);
3099 wifi_pos_set_drv_ver_build(psoc, QWLAN_VERSION_BUILD);
Wu Gao1ab05582018-11-08 16:22:49 +08003100 ucfg_mlme_get_neighbor_scan_max_chan_time(psoc,
3101 &neighbor_scan_max_chan_time);
3102 ucfg_mlme_get_neighbor_scan_min_chan_time(psoc,
3103 &neighbor_scan_min_chan_time);
3104 wifi_pos_set_dwell_time_min(psoc, neighbor_scan_min_chan_time);
3105 wifi_pos_set_dwell_time_max(psoc, neighbor_scan_max_chan_time);
Naveen Rawat910726a2017-03-06 11:42:51 -08003106}
3107#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003108static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08003109{
3110 return oem_activate_service(hdd_ctx);
3111}
3112
3113static int hdd_deactivate_wifi_pos(void)
3114{
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05303115 return oem_deactivate_service();
Naveen Rawat910726a2017-03-06 11:42:51 -08003116}
3117
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003118static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08003119{
3120}
3121#endif
3122
Arun Khandavallifae92942016-08-01 13:31:08 +05303123/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003124 * __hdd_open() - HDD Open function
3125 * @dev: Pointer to net_device structure
3126 *
3127 * This is called in response to ifconfig up
3128 *
3129 * Return: 0 for success; non-zero for failure
3130 */
3131static int __hdd_open(struct net_device *dev)
3132{
Jeff Johnson9d295242017-08-29 14:39:48 -07003133 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003134 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003135 int ret;
3136
Dustin Brownfdf17c12018-03-14 12:55:34 -07003137 hdd_enter_dev(dev);
Ashish Kumar Dhanotiyaf10aa5f2018-12-28 21:29:56 +05303138
3139 qdf_mtrace(QDF_MODULE_ID_HDD, QDF_MODULE_ID_HDD,
3140 TRACE_CODE_HDD_OPEN_REQUEST,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08003141 adapter->vdev_id, adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003142
Ashish Kumar Dhanotiya15a7db52017-08-03 10:27:34 +05303143 /* Nothing to be done if device is unloading */
3144 if (cds_is_driver_unloading()) {
3145 hdd_err("Driver is unloading can not open the hdd");
3146 return -EBUSY;
3147 }
3148
Dustin Brown01847752017-10-25 13:56:27 -07003149 if (cds_is_driver_recovering()) {
3150 hdd_err("WLAN is currently recovering; Please try again.");
3151 return -EBUSY;
3152 }
3153
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303154 /*
3155 * This scenario can be hit in cases where in the wlan driver after
3156 * registering the netdevices and there is a failure in driver
3157 * initialization. So return error gracefully because the netdevices
3158 * will be de-registered as part of the load failure.
3159 */
3160
3161 if (!cds_is_driver_loaded()) {
3162 hdd_err("Failed to start the wlan driver!!");
Dustin Brown3da3a832019-03-19 15:51:54 -07003163 return -EIO;
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303164 }
Abhishek Singh23edd1c2016-05-05 11:56:06 +05303165
Rajeev Kumar473f9af2019-04-05 14:25:56 -07003166 ret = hdd_trigger_psoc_idle_restart(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05303167 if (ret) {
3168 hdd_err("Failed to start WLAN modules return");
Dustin Brown3da3a832019-03-19 15:51:54 -07003169 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05303170 }
3171
Arun Khandavallifae92942016-08-01 13:31:08 +05303172 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
3173 ret = hdd_start_adapter(adapter);
3174 if (ret) {
3175 hdd_err("Failed to start adapter :%d",
3176 adapter->device_mode);
Dustin Brown3da3a832019-03-19 15:51:54 -07003177 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05303178 }
3179 }
3180
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003181 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
3182 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07003183 hdd_debug("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003184 /* Enable TX queues only when we are connected */
3185 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05303186 WLAN_START_ALL_NETIF_QUEUE,
3187 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003188 }
3189
Naveen Rawat286def52016-09-23 15:38:02 -07003190 /* Enable carrier and transmit queues for NDI */
3191 if (WLAN_HDD_IS_NDI(adapter)) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07003192 hdd_debug("Enabling Tx Queues");
Naveen Rawat286def52016-09-23 15:38:02 -07003193 wlan_hdd_netif_queue_control(adapter,
3194 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
3195 WLAN_CONTROL_PATH);
3196 }
3197
Naveen Rawat910726a2017-03-06 11:42:51 -08003198 hdd_populate_wifi_pos_cfg(hdd_ctx);
Arunk Khandavalli40943af2017-05-15 19:25:34 +05303199 hdd_lpass_notify_start(hdd_ctx, adapter);
Naveen Rawat910726a2017-03-06 11:42:51 -08003200
Dustin Brown3da3a832019-03-19 15:51:54 -07003201 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003202}
3203
3204/**
3205 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
Dustin Brown98f7c822019-03-06 12:25:49 -08003206 * @net_dev: Pointer to net_device structure
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003207 *
3208 * This is called in response to ifconfig up
3209 *
3210 * Return: 0 for success; non-zero for failure
3211 */
Dustin Brown0e1e1622019-01-17 11:00:22 -08003212static int hdd_open(struct net_device *net_dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003213{
Dustin Brown0e1e1622019-01-17 11:00:22 -08003214 int errno;
3215 struct osif_vdev_sync *vdev_sync;
3216
3217 errno = osif_vdev_sync_trans_start(net_dev, &vdev_sync);
3218 if (errno)
3219 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003220
Dustin Brown0e1e1622019-01-17 11:00:22 -08003221 errno = __hdd_open(net_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003222
Dustin Brown0e1e1622019-01-17 11:00:22 -08003223 osif_vdev_sync_trans_stop(vdev_sync);
3224
3225 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003226}
3227
gaurank kathpaliaac8504a2019-06-03 14:51:36 +05303228static bool
3229hdd_is_any_sta_interface_open(struct hdd_context *hdd_ctx)
3230{
3231 struct hdd_adapter *adapter;
3232
3233 hdd_for_each_adapter(hdd_ctx, adapter) {
3234 if (adapter->device_mode == QDF_STA_MODE &&
3235 (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags) ||
3236 test_bit(SME_SESSION_OPENED, &adapter->event_flags)))
3237 return true;
3238 }
3239
3240 return false;
3241}
3242
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003243/**
3244 * __hdd_stop() - HDD stop function
3245 * @dev: Pointer to net_device structure
3246 *
3247 * This is called in response to ifconfig down
3248 *
3249 * Return: 0 for success; non-zero for failure
3250 */
3251static int __hdd_stop(struct net_device *dev)
3252{
Jeff Johnson9d295242017-08-29 14:39:48 -07003253 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003254 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003255 int ret;
Jeff Johnson16528362018-06-14 12:34:16 -07003256 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003257
Dustin Brownfdf17c12018-03-14 12:55:34 -07003258 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003259
Ashish Kumar Dhanotiyaf10aa5f2018-12-28 21:29:56 +05303260 qdf_mtrace(QDF_MODULE_ID_HDD, QDF_MODULE_ID_HDD,
3261 TRACE_CODE_HDD_STOP_REQUEST,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08003262 adapter->vdev_id, adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003263
3264 ret = wlan_hdd_validate_context(hdd_ctx);
Arunk Khandavalli987c8d52018-06-21 17:40:31 +05303265 if (ret) {
3266 set_bit(DOWN_DURING_SSR, &adapter->event_flags);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003267 return ret;
Arunk Khandavalli987c8d52018-06-21 17:40:31 +05303268 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003269
3270 /* Nothing to be done if the interface is not opened */
3271 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07003272 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003273 return -ENODEV;
3274 }
3275
3276 /* Make sure the interface is marked as closed */
3277 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Mukul Sharmad16c2022017-07-25 18:56:12 +05303278
Jeff Johnson16528362018-06-14 12:34:16 -07003279 mac_handle = hdd_ctx->mac_handle;
3280
Mukul Sharmad16c2022017-07-25 18:56:12 +05303281 hdd_debug("Disabling Auto Power save timer");
3282 sme_ps_disable_auto_ps_timer(
Jeff Johnson16528362018-06-14 12:34:16 -07003283 mac_handle,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08003284 adapter->vdev_id);
Mukul Sharmad16c2022017-07-25 18:56:12 +05303285
3286 /*
3287 * Disable TX on the interface, after this hard_start_xmit() will not
3288 * be called on that interface
3289 */
Dustin Browna7bb6ae2018-08-16 16:51:50 -07003290 hdd_debug("Disabling queues, adapter device mode: %s(%d)",
Dustin Brown458027c2018-10-19 12:26:27 -07003291 qdf_opmode_str(adapter->device_mode), adapter->device_mode);
Kabilan Kannan8dac3502017-10-30 12:40:27 -07003292
Himanshu Agarwal865201d2017-04-12 15:45:31 +05303293 wlan_hdd_netif_queue_control(adapter,
3294 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
3295 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003296
Arunk Khandavalli40943af2017-05-15 19:25:34 +05303297 if (adapter->device_mode == QDF_STA_MODE)
3298 hdd_lpass_notify_stop(hdd_ctx);
3299
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003300 /*
Naveen Rawat286def52016-09-23 15:38:02 -07003301 * NAN data interface is different in some sense. The traffic on NDI is
3302 * bursty in nature and depends on the need to transfer. The service
3303 * layer may down the interface after the usage and up again when
3304 * required. In some sense, the NDI is expected to be available
3305 * (like SAP) iface until NDI delete request is issued by the service
3306 * layer. Skip BSS termination and adapter deletion for NAN Data
3307 * interface (NDI).
3308 */
3309 if (WLAN_HDD_IS_NDI(adapter))
3310 return 0;
3311
3312 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003313 * The interface is marked as down for outside world (aka kernel)
3314 * But the driver is pretty much alive inside. The driver needs to
3315 * tear down the existing connection on the netdev (session)
3316 * cleanup the data pipes and wait until the control plane is stabilized
3317 * for this interface. The call also needs to wait until the above
3318 * mentioned actions are completed before returning to the caller.
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003319 * Notice that hdd_stop_adapter is requested not to close the session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003320 * That is intentional to be able to scan if it is a STA/P2P interface
3321 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08003322 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003323
3324 /* DeInit the adapter. This ensures datapath cleanup as well */
3325 hdd_deinit_adapter(hdd_ctx, adapter, true);
3326
gaurank kathpaliaac8504a2019-06-03 14:51:36 +05303327 /* If no STA interface is open, then flush out the BLM entries */
3328 if (!hdd_is_any_sta_interface_open(hdd_ctx))
3329 ucfg_blm_flush_reject_ap_list(hdd_ctx->pdev);
3330
Dustin Brown4c663222018-10-23 14:19:36 -07003331 if (!hdd_is_any_interface_open(hdd_ctx))
3332 hdd_psoc_idle_timer_start(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05303333
Dustin Browne74003f2018-03-14 12:51:58 -07003334 hdd_exit();
Dustin Brown4c663222018-10-23 14:19:36 -07003335
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003336 return 0;
3337}
3338
3339/**
3340 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
3341 * @dev: pointer to net_device structure
3342 *
3343 * This is called in response to ifconfig down
3344 *
3345 * Return: 0 for success and error number for failure
3346 */
Dustin Brown0e1e1622019-01-17 11:00:22 -08003347static int hdd_stop(struct net_device *net_dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003348{
Dustin Brown0e1e1622019-01-17 11:00:22 -08003349 int errno;
3350 struct osif_vdev_sync *vdev_sync;
3351
3352 errno = osif_vdev_sync_trans_start(net_dev, &vdev_sync);
3353 if (errno)
3354 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003355
Dustin Brown0e1e1622019-01-17 11:00:22 -08003356 errno = __hdd_stop(net_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003357
Dustin Brown0e1e1622019-01-17 11:00:22 -08003358 osif_vdev_sync_trans_stop(vdev_sync);
3359
3360 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003361}
3362
3363/**
Dustin Brown96b98dd2019-03-06 12:39:37 -08003364 * hdd_uninit() - HDD uninit function
3365 * @dev: Pointer to net_device structure
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003366 *
3367 * This is called during the netdev unregister to uninitialize all data
3368 * associated with the device
3369 *
Dustin Brown96b98dd2019-03-06 12:39:37 -08003370 * This function must be protected by a transition
3371 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003372 * Return: None
3373 */
Dustin Brown96b98dd2019-03-06 12:39:37 -08003374static void hdd_uninit(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003375{
Jeff Johnson9d295242017-08-29 14:39:48 -07003376 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson399c6272017-08-30 10:51:00 -07003377 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003378
Dustin Brownfdf17c12018-03-14 12:55:34 -07003379 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003380
Dustin Brown96b98dd2019-03-06 12:39:37 -08003381 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
3382 hdd_err("Invalid magic");
3383 goto exit;
3384 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003385
Dustin Brown96b98dd2019-03-06 12:39:37 -08003386 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3387 if (!hdd_ctx) {
3388 hdd_err("NULL hdd_ctx");
3389 goto exit;
3390 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003391
Dustin Brown96b98dd2019-03-06 12:39:37 -08003392 if (dev != adapter->dev)
3393 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003394
Dustin Brown96b98dd2019-03-06 12:39:37 -08003395 hdd_deinit_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003396
Dustin Brown96b98dd2019-03-06 12:39:37 -08003397 /* after uninit our adapter structure will no longer be valid */
3398 adapter->dev = NULL;
3399 adapter->magic = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003400
Dustin Brown96b98dd2019-03-06 12:39:37 -08003401exit:
Dustin Browne74003f2018-03-14 12:51:58 -07003402 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003403}
3404
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003405static int hdd_open_cesium_nl_sock(void)
3406{
3407#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3408 struct netlink_kernel_cfg cfg = {
3409 .groups = WLAN_NLINK_MCAST_GRP_ID,
3410 .input = NULL
3411 };
3412#endif
3413 int ret = 0;
3414
3415#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3416 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3417#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
3418 THIS_MODULE,
3419#endif
3420 &cfg);
3421#else
3422 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3423 WLAN_NLINK_MCAST_GRP_ID,
3424 NULL, NULL, THIS_MODULE);
3425#endif
3426
Jeff Johnsond36fa332019-03-18 13:42:25 -07003427 if (!cesium_nl_srv_sock) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07003428 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003429 ret = -ECONNREFUSED;
3430 }
3431
3432 return ret;
3433}
3434
3435static void hdd_close_cesium_nl_sock(void)
3436{
Jeff Johnsond36fa332019-03-18 13:42:25 -07003437 if (cesium_nl_srv_sock) {
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003438 netlink_kernel_release(cesium_nl_srv_sock);
3439 cesium_nl_srv_sock = NULL;
3440 }
3441}
3442
Ashish Kumar Dhanotiya6784b502018-10-17 12:51:10 +05303443void hdd_update_dynamic_mac(struct hdd_context *hdd_ctx,
3444 struct qdf_mac_addr *curr_mac_addr,
3445 struct qdf_mac_addr *new_mac_addr)
3446{
3447 uint8_t i;
3448
3449 hdd_enter();
3450
3451 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303452 if (!qdf_mem_cmp(
3453 curr_mac_addr->bytes,
3454 &hdd_ctx->dynamic_mac_list[i].dynamic_mac.bytes[0],
Ashish Kumar Dhanotiya6784b502018-10-17 12:51:10 +05303455 sizeof(struct qdf_mac_addr))) {
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303456 qdf_mem_copy(&hdd_ctx->dynamic_mac_list[i].dynamic_mac,
Ashish Kumar Dhanotiya6784b502018-10-17 12:51:10 +05303457 new_mac_addr->bytes,
3458 sizeof(struct qdf_mac_addr));
3459 break;
3460 }
3461 }
3462
3463 hdd_exit();
3464}
3465
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003466/**
3467 * __hdd_set_mac_address() - set the user specified mac address
3468 * @dev: Pointer to the net device.
3469 * @addr: Pointer to the sockaddr.
3470 *
3471 * This function sets the user specified mac address using
Jeff Johnson06095fb2018-05-06 16:16:42 -07003472 * the command ifconfig wlanX hw ether <mac address>.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003473 *
3474 * Return: 0 for success, non zero for failure
3475 */
3476static int __hdd_set_mac_address(struct net_device *dev, void *addr)
3477{
Jeff Johnson9d295242017-08-29 14:39:48 -07003478 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Ashish Kumar Dhanotiyae533f6c2018-06-19 21:16:07 +05303479 struct hdd_adapter *adapter_temp;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003480 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003481 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303482 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003483 int ret;
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303484 struct qdf_mac_addr mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003485
Dustin Brownfdf17c12018-03-14 12:55:34 -07003486 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003487
Hanumanth Reddy Pothula5c7a7812018-03-09 12:55:32 +05303488 if (netif_running(dev)) {
3489 hdd_err("On iface up, set mac address change isn't supported");
3490 return -EBUSY;
3491 }
3492
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003493 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3494 ret = wlan_hdd_validate_context(hdd_ctx);
3495 if (0 != ret)
3496 return ret;
3497
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303498 qdf_mem_copy(&mac_addr, psta_mac_addr->sa_data, sizeof(mac_addr));
Ashish Kumar Dhanotiyae533f6c2018-06-19 21:16:07 +05303499 adapter_temp = hdd_get_adapter_by_macaddr(hdd_ctx, mac_addr.bytes);
3500 if (adapter_temp) {
3501 if (!qdf_str_cmp(adapter_temp->dev->name, dev->name))
3502 return 0;
Srinivas Girigowdacb7b8b82019-04-10 14:27:47 -07003503 hdd_err("%s adapter exist with same address " QDF_MAC_ADDR_STR,
Ashish Kumar Dhanotiyae533f6c2018-06-19 21:16:07 +05303504 adapter_temp->dev->name,
Srinivas Girigowda34fbba02019-04-08 12:07:44 -07003505 QDF_MAC_ADDR_ARRAY(mac_addr.bytes));
Ashish Kumar Dhanotiyaf974f332018-04-19 16:03:15 +05303506 return -EINVAL;
3507 }
3508
Pragaspathi Thilagaraj84b72842018-09-19 22:06:57 +05303509 qdf_ret_status = wlan_hdd_validate_mac_address(&mac_addr);
3510 if (QDF_IS_STATUS_ERROR(qdf_ret_status))
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303511 return -EINVAL;
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303512
Srinivas Girigowdacb7b8b82019-04-10 14:27:47 -07003513 hdd_info("Changing MAC to " QDF_MAC_ADDR_STR " of the interface %s ",
Srinivas Girigowda34fbba02019-04-08 12:07:44 -07003514 QDF_MAC_ADDR_ARRAY(mac_addr.bytes), dev->name);
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303515
Ashish Kumar Dhanotiya6784b502018-10-17 12:51:10 +05303516 hdd_update_dynamic_mac(hdd_ctx, &adapter->mac_addr, &mac_addr);
Jeff Johnson1e851a12017-10-28 14:36:12 -07003517 memcpy(&adapter->mac_addr, psta_mac_addr->sa_data, ETH_ALEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003518 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
3519
Dustin Browne74003f2018-03-14 12:51:58 -07003520 hdd_exit();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303521 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003522}
3523
3524/**
3525 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
Dustin Brown98f7c822019-03-06 12:25:49 -08003526 * function from SSR
3527 * @net_dev: pointer to net_device structure
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003528 * @addr: Pointer to the sockaddr
3529 *
3530 * This function sets the user specified mac address using
Jeff Johnson06095fb2018-05-06 16:16:42 -07003531 * the command ifconfig wlanX hw ether <mac address>.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003532 *
3533 * Return: 0 for success.
3534 */
Dustin Brown98f7c822019-03-06 12:25:49 -08003535static int hdd_set_mac_address(struct net_device *net_dev, void *addr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003536{
Dustin Brown98f7c822019-03-06 12:25:49 -08003537 struct osif_vdev_sync *vdev_sync;
3538 int errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003539
Dustin Brown98f7c822019-03-06 12:25:49 -08003540 errno = osif_vdev_sync_op_start(net_dev, &vdev_sync);
3541 if (errno)
3542 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003543
Dustin Brown98f7c822019-03-06 12:25:49 -08003544 errno = __hdd_set_mac_address(net_dev, addr);
3545
3546 osif_vdev_sync_op_stop(vdev_sync);
3547
3548 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003549}
3550
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303551static uint8_t *wlan_hdd_get_derived_intf_addr(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003552{
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303553 int i, j;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003554
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303555 i = qdf_ffz(hdd_ctx->derived_intf_addr_mask);
3556 if (i < 0 || i >= hdd_ctx->num_derived_addr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003557 return NULL;
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303558 qdf_atomic_set_bit(i, &hdd_ctx->derived_intf_addr_mask);
Srinivas Girigowdacb7b8b82019-04-10 14:27:47 -07003559 hdd_info("Assigning MAC from derived list" QDF_MAC_ADDR_STR,
Srinivas Girigowda34fbba02019-04-08 12:07:44 -07003560 QDF_MAC_ADDR_ARRAY(hdd_ctx->derived_mac_addr[i].bytes));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003561
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303562 /* Copy the mac in dynamic mac list at first free position */
3563 for (j = 0; j < QDF_MAX_CONCURRENCY_PERSONA; j++) {
3564 if (qdf_is_macaddr_zero(&hdd_ctx->
3565 dynamic_mac_list[j].dynamic_mac))
3566 break;
3567 }
3568 if (j == QDF_MAX_CONCURRENCY_PERSONA) {
3569 hdd_err("Max interfaces are up");
3570 return NULL;
3571 }
Dustin Brown61cc3932018-10-18 16:12:13 -07003572
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303573 qdf_mem_copy(&hdd_ctx->dynamic_mac_list[j].dynamic_mac.bytes,
3574 &hdd_ctx->derived_mac_addr[i].bytes,
Ashish Kumar Dhanotiya6784b502018-10-17 12:51:10 +05303575 sizeof(struct qdf_mac_addr));
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303576 hdd_ctx->dynamic_mac_list[j].is_provisioned_mac = false;
3577 hdd_ctx->dynamic_mac_list[j].bit_position = i;
3578
3579 return hdd_ctx->derived_mac_addr[i].bytes;
3580}
3581
3582static uint8_t *wlan_hdd_get_provisioned_intf_addr(struct hdd_context *hdd_ctx)
3583{
3584 int i, j;
3585
3586 i = qdf_ffz(hdd_ctx->provisioned_intf_addr_mask);
3587 if (i < 0 || i >= hdd_ctx->num_provisioned_addr)
3588 return NULL;
3589 qdf_atomic_set_bit(i, &hdd_ctx->provisioned_intf_addr_mask);
Srinivas Girigowdacb7b8b82019-04-10 14:27:47 -07003590 hdd_info("Assigning MAC from provisioned list" QDF_MAC_ADDR_STR,
Srinivas Girigowda34fbba02019-04-08 12:07:44 -07003591 QDF_MAC_ADDR_ARRAY(hdd_ctx->provisioned_mac_addr[i].bytes));
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303592
3593 /* Copy the mac in dynamic mac list at first free position */
3594 for (j = 0; j < QDF_MAX_CONCURRENCY_PERSONA; j++) {
3595 if (qdf_is_macaddr_zero(&hdd_ctx->
3596 dynamic_mac_list[j].dynamic_mac))
3597 break;
3598 }
3599 if (j == QDF_MAX_CONCURRENCY_PERSONA) {
3600 hdd_err("Max interfaces are up");
3601 return NULL;
3602 }
3603
3604 qdf_mem_copy(&hdd_ctx->dynamic_mac_list[j].dynamic_mac.bytes,
3605 &hdd_ctx->provisioned_mac_addr[i].bytes,
3606 sizeof(struct qdf_mac_addr));
3607 hdd_ctx->dynamic_mac_list[j].is_provisioned_mac = true;
3608 hdd_ctx->dynamic_mac_list[j].bit_position = i;
3609 return hdd_ctx->provisioned_mac_addr[i].bytes;
3610}
3611
3612uint8_t *wlan_hdd_get_intf_addr(struct hdd_context *hdd_ctx,
3613 enum QDF_OPMODE interface_type)
3614{
3615 uint8_t *mac_addr = NULL;
3616
3617 if (qdf_atomic_test_bit(interface_type,
3618 (unsigned long *)
3619 (&hdd_ctx->config->provisioned_intf_pool)))
3620 mac_addr = wlan_hdd_get_provisioned_intf_addr(hdd_ctx);
3621
3622 if ((!mac_addr) &&
3623 (qdf_atomic_test_bit(interface_type,
3624 (unsigned long *)
3625 (&hdd_ctx->config->derived_intf_pool))))
3626 mac_addr = wlan_hdd_get_derived_intf_addr(hdd_ctx);
3627
3628 if (!mac_addr)
3629 hdd_err("MAC is not available in both the lists");
3630 return mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003631}
3632
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07003633void wlan_hdd_release_intf_addr(struct hdd_context *hdd_ctx,
3634 uint8_t *releaseAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003635{
3636 int i;
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303637 int mac_pos_in_mask;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003638
Anurag Chouhan6d760662016-02-20 16:05:43 +05303639 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003640 if (!memcmp(releaseAddr,
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303641 hdd_ctx->dynamic_mac_list[i].dynamic_mac.bytes,
3642 QDF_MAC_ADDR_SIZE)) {
3643 mac_pos_in_mask =
3644 hdd_ctx->dynamic_mac_list[i].bit_position;
3645 if (hdd_ctx->dynamic_mac_list[i].is_provisioned_mac) {
3646 qdf_atomic_clear_bit(
3647 mac_pos_in_mask,
3648 &hdd_ctx->
3649 provisioned_intf_addr_mask);
3650 hdd_info("Releasing MAC from provisioned list");
3651 hdd_info(
Srinivas Girigowdacb7b8b82019-04-10 14:27:47 -07003652 QDF_MAC_ADDR_STR,
Srinivas Girigowda34fbba02019-04-08 12:07:44 -07003653 QDF_MAC_ADDR_ARRAY(releaseAddr));
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303654 } else {
3655 qdf_atomic_clear_bit(
3656 mac_pos_in_mask, &hdd_ctx->
3657 derived_intf_addr_mask);
3658 hdd_info("Releasing MAC from derived list");
Srinivas Girigowdacb7b8b82019-04-10 14:27:47 -07003659 hdd_info(QDF_MAC_ADDR_STR,
Srinivas Girigowda34fbba02019-04-08 12:07:44 -07003660 QDF_MAC_ADDR_ARRAY(releaseAddr));
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303661 }
3662 qdf_zero_macaddr(&hdd_ctx->
3663 dynamic_mac_list[i].dynamic_mac);
3664 hdd_ctx->dynamic_mac_list[i].is_provisioned_mac =
3665 false;
3666 hdd_ctx->dynamic_mac_list[i].bit_position = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003667 break;
3668 }
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303669
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003670 }
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303671 if (i == QDF_MAX_CONCURRENCY_PERSONA)
Srinivas Girigowdacb7b8b82019-04-10 14:27:47 -07003672 hdd_err("Releasing non existing MAC" QDF_MAC_ADDR_STR,
Srinivas Girigowda34fbba02019-04-08 12:07:44 -07003673 QDF_MAC_ADDR_ARRAY(releaseAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003674}
3675
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003676/**
3677 * __hdd_set_multicast_list() - set the multicast address list
3678 * @dev: Pointer to the WLAN device.
3679 * @skb: Pointer to OS packet (sk_buff).
3680 *
3681 * This funciton sets the multicast address list.
3682 *
3683 * Return: None
3684 */
3685static void __hdd_set_multicast_list(struct net_device *dev)
3686{
Jeff Johnson9d295242017-08-29 14:39:48 -07003687 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Dustin Brown0f874482018-06-13 14:39:22 -07003688 int i = 0, errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003689 struct netdev_hw_addr *ha;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003690 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303691 struct pmo_mc_addr_list_params *mc_list_request = NULL;
Dustin Brown1dbefe62018-09-11 16:32:03 -07003692 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303693 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003694
Dustin Brownfdf17c12018-03-14 12:55:34 -07003695 hdd_enter_dev(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05303696 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303697 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05303698
Dustin Brown0f874482018-06-13 14:39:22 -07003699 errno = wlan_hdd_validate_context(hdd_ctx);
3700 if (errno)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303701 goto out;
3702
Dustin Brown0f874482018-06-13 14:39:22 -07003703 errno = hdd_validate_adapter(adapter);
3704 if (errno)
Dustin Brownc788acb2017-08-01 17:43:51 -07003705 goto out;
3706
Arunk Khandavalli6a227882017-12-12 19:31:08 +05303707 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
3708 hdd_err("%s: Driver module is closed", __func__);
Dustin Brown0f874482018-06-13 14:39:22 -07003709 goto out;
Arunk Khandavalli6a227882017-12-12 19:31:08 +05303710 }
3711
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303712 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
Min Liu74a1a502018-10-10 19:59:07 +08003713 if (!mc_list_request)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303714 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003715
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05303716 /* Delete already configured multicast address list */
3717 if (adapter->mc_addr_list.mc_cnt > 0) {
Dustin Brown0f874482018-06-13 14:39:22 -07003718 hdd_debug("clear previously configured MC address list");
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05303719 hdd_disable_and_flush_mc_addr_list(adapter,
3720 pmo_mc_list_change_notify);
3721 }
3722
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003723 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003724 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303725 hdd_disable_and_flush_mc_addr_list(adapter,
3726 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003727 } else {
3728 mc_count = netdev_mc_count(dev);
Wu Gaod7dd6e42018-10-16 17:22:56 +08003729 if (mc_count > ucfg_pmo_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003730 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Wu Gaod7dd6e42018-10-16 17:22:56 +08003731 ucfg_pmo_max_mc_addr_supported(psoc));
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303732 hdd_disable_and_flush_mc_addr_list(adapter,
3733 pmo_mc_list_change_notify);
stonezdf2bdfd2018-11-20 14:45:06 +08003734 adapter->mc_addr_list.mc_cnt = 0;
Dustin Brown0f874482018-06-13 14:39:22 -07003735 goto free_req;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003736 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003737 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowdacb7b8b82019-04-10 14:27:47 -07003738 hdd_debug("ha_addr[%d] "QDF_MAC_ADDR_STR,
Srinivas Girigowda34fbba02019-04-08 12:07:44 -07003739 i, QDF_MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003740 if (i == mc_count)
3741 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303742 memset(&(mc_list_request->mc_addr[i].bytes),
3743 0, ETH_ALEN);
3744 memcpy(&(mc_list_request->mc_addr[i].bytes),
3745 ha->addr, ETH_ALEN);
Dustin Brown0f874482018-06-13 14:39:22 -07003746 hdd_debug("mlist[%d] = %pM", i,
3747 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003748 i++;
3749 }
3750 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303751
stonezdf2bdfd2018-11-20 14:45:06 +08003752 adapter->mc_addr_list.mc_cnt = mc_count;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303753 mc_list_request->psoc = psoc;
Jeff Johnson5a6fc962019-02-04 14:20:25 -08003754 mc_list_request->vdev_id = adapter->vdev_id;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303755 mc_list_request->count = mc_count;
Dustin Brown0f874482018-06-13 14:39:22 -07003756
3757 errno = hdd_cache_mc_addr_list(mc_list_request);
3758 if (errno) {
3759 hdd_err("Failed to cache MC address list for vdev %u; errno:%d",
Jeff Johnson5a6fc962019-02-04 14:20:25 -08003760 adapter->vdev_id, errno);
Dustin Brown0f874482018-06-13 14:39:22 -07003761 goto free_req;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003762 }
Dustin Brown0f874482018-06-13 14:39:22 -07003763
3764 hdd_enable_mc_addr_filtering(adapter, pmo_mc_list_change_notify);
3765
3766free_req:
3767 qdf_mem_free(mc_list_request);
3768
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303769out:
Dustin Browne74003f2018-03-14 12:51:58 -07003770 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003771}
3772
3773/**
3774 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
Dustin Brown98f7c822019-03-06 12:25:49 -08003775 * @net_dev: pointer to net_device
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003776 *
3777 * Return: none
3778 */
Dustin Brown98f7c822019-03-06 12:25:49 -08003779static void hdd_set_multicast_list(struct net_device *net_dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003780{
Dustin Brown98f7c822019-03-06 12:25:49 -08003781 struct osif_vdev_sync *vdev_sync;
3782
3783 if (osif_vdev_sync_op_start(net_dev, &vdev_sync))
3784 return;
3785
3786 __hdd_set_multicast_list(net_dev);
3787
3788 osif_vdev_sync_op_stop(vdev_sync);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003789}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003790
Subrat Dash5f36fbe2019-02-12 16:28:14 +05303791#ifdef WLAN_FEATURE_TSF_PTP
3792static const struct ethtool_ops wlan_ethtool_ops = {
3793 .get_ts_info = wlan_get_ts_info,
3794};
3795#endif
3796
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003797static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003798 .ndo_open = hdd_open,
3799 .ndo_stop = hdd_stop,
3800 .ndo_uninit = hdd_uninit,
3801 .ndo_start_xmit = hdd_hard_start_xmit,
3802 .ndo_tx_timeout = hdd_tx_timeout,
3803 .ndo_get_stats = hdd_get_stats,
3804 .ndo_do_ioctl = hdd_ioctl,
3805 .ndo_set_mac_address = hdd_set_mac_address,
3806 .ndo_select_queue = hdd_select_queue,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003807 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003808};
3809
Nirav Shah73713f72018-05-17 14:50:41 +05303810#ifdef FEATURE_MONITOR_MODE_SUPPORT
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003811/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003812static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003813 .ndo_open = hdd_mon_open,
3814 .ndo_stop = hdd_stop,
3815 .ndo_get_stats = hdd_get_stats,
3816};
3817
Subrat Dash5f36fbe2019-02-12 16:28:14 +05303818#ifdef WLAN_FEATURE_TSF_PTP
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003819/**
3820 * hdd_set_station_ops() - update net_device ops for monitor mode
Jeff Johnson5505db82017-11-02 21:19:23 -07003821 * @dev: Handle to struct net_device to be updated.
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003822 * Return: None
3823 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003824void hdd_set_station_ops(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003825{
Subrat Dash5f36fbe2019-02-12 16:28:14 +05303826 if (cds_get_conparam() == QDF_GLOBAL_MONITOR_MODE) {
3827 dev->netdev_ops = &wlan_mon_drv_ops;
3828 } else {
3829 dev->netdev_ops = &wlan_drv_ops;
3830 dev->ethtool_ops = &wlan_ethtool_ops;
3831 }
3832}
3833#else
3834void hdd_set_station_ops(struct net_device *dev)
3835{
3836 if (cds_get_conparam() == QDF_GLOBAL_MONITOR_MODE)
Jeff Johnson5505db82017-11-02 21:19:23 -07003837 dev->netdev_ops = &wlan_mon_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003838 else
Jeff Johnson5505db82017-11-02 21:19:23 -07003839 dev->netdev_ops = &wlan_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003840}
Subrat Dash5f36fbe2019-02-12 16:28:14 +05303841
3842#endif
3843#else
3844#ifdef WLAN_FEATURE_TSF_PTP
3845void hdd_set_station_ops(struct net_device *dev)
3846{
3847 dev->netdev_ops = &wlan_drv_ops;
3848 dev->ethtool_ops = &wlan_ethtool_ops;
3849}
Nirav Shah73713f72018-05-17 14:50:41 +05303850#else
3851void hdd_set_station_ops(struct net_device *dev)
3852{
3853 dev->netdev_ops = &wlan_drv_ops;
3854}
3855#endif
Subrat Dash5f36fbe2019-02-12 16:28:14 +05303856#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003857
3858/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08003859 * hdd_alloc_station_adapter() - allocate the station hdd adapter
3860 * @hdd_ctx: global hdd context
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003861 * @mac_addr: mac address to assign to the interface
Ryan Hsu07495ea2016-01-21 15:25:39 -08003862 * @name: User-visible name of the interface
3863 *
3864 * hdd adapter pointer would point to the netdev->priv space, this function
Jeff Johnson62018292018-05-06 16:18:35 -07003865 * would retrieve the pointer, and setup the hdd adapter configuration.
Ryan Hsu07495ea2016-01-21 15:25:39 -08003866 *
3867 * Return: the pointer to hdd adapter, otherwise NULL
3868 */
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003869static struct hdd_adapter *
3870hdd_alloc_station_adapter(struct hdd_context *hdd_ctx, tSirMacAddr mac_addr,
3871 unsigned char name_assign_type, const char *name)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003872{
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003873 struct net_device *dev;
3874 struct hdd_adapter *adapter;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003875 struct hdd_station_ctx *sta_ctx;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303876 QDF_STATUS qdf_status;
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003877
3878 /* cfg80211 initialization and registration */
3879 dev = alloc_netdev_mq(sizeof(*adapter), name,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003880#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003881 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003882#endif
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003883 (cds_get_conparam() == QDF_GLOBAL_MONITOR_MODE ?
3884 hdd_mon_mode_ether_setup : ether_setup),
3885 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003886
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003887 if (!dev) {
3888 hdd_err("Failed to allocate new net_device '%s'", name);
3889 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003890 }
3891
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003892 adapter = netdev_priv(dev);
3893
3894 qdf_mem_zero(adapter, sizeof(*adapter));
3895 sta_ctx = &adapter->session.station;
Jeff Johnson0a082d92019-03-04 12:25:49 -08003896 qdf_mem_set(sta_ctx->conn_info.sta_id,
3897 sizeof(sta_ctx->conn_info.sta_id),
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003898 HDD_WLAN_INVALID_STA_ID);
3899 adapter->dev = dev;
3900 adapter->hdd_ctx = hdd_ctx;
3901 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Jeff Johnson912b1bb2019-03-06 10:12:36 -08003902 adapter->vdev_id = WLAN_UMAC_VDEV_ID_MAX;
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003903
3904 qdf_status = qdf_event_create(&adapter->qdf_session_open_event);
3905 if (QDF_IS_STATUS_ERROR(qdf_status))
3906 goto free_net_dev;
3907
3908 qdf_status = qdf_event_create(&adapter->qdf_session_close_event);
3909 if (QDF_IS_STATUS_ERROR(qdf_status))
3910 goto free_net_dev;
3911
3912 adapter->offloads_configured = false;
3913 adapter->is_link_up_service_needed = false;
3914 adapter->disconnection_in_progress = false;
3915 adapter->send_mode_change = true;
3916
3917 /* Init the net_device structure */
3918 strlcpy(dev->name, name, IFNAMSIZ);
3919
3920 qdf_mem_copy(dev->dev_addr, mac_addr, sizeof(tSirMacAddr));
3921 qdf_mem_copy(adapter->mac_addr.bytes, mac_addr, sizeof(tSirMacAddr));
3922 dev->watchdog_timeo = HDD_TX_TIMEOUT;
3923
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003924 hdd_set_station_ops(adapter->dev);
3925
3926 hdd_dev_setup_destructor(dev);
3927 dev->ieee80211_ptr = &adapter->wdev;
3928 dev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
3929 adapter->wdev.wiphy = hdd_ctx->wiphy;
3930 adapter->wdev.netdev = dev;
3931
3932 /* set dev's parent to underlying device */
3933 SET_NETDEV_DEV(dev, hdd_ctx->parent_dev);
3934 hdd_wmm_init(adapter);
3935 spin_lock_init(&adapter->pause_map_lock);
3936 adapter->start_time = qdf_system_ticks();
3937 adapter->last_time = adapter->start_time;
3938
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003939 return adapter;
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003940
3941free_net_dev:
3942 free_netdev(adapter->dev);
3943
3944 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003945}
3946
Jeff Johnson9d295242017-08-29 14:39:48 -07003947static QDF_STATUS hdd_register_interface(struct hdd_adapter *adapter, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003948{
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003949 struct net_device *dev = adapter->dev;
3950 int ret;
3951
Dustin Brown491d54b2018-03-14 12:39:11 -07003952 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003953
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003954 if (rtnl_held) {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003955 if (strnchr(dev->name, IFNAMSIZ - 1, '%')) {
3956
3957 ret = dev_alloc_name(dev, dev->name);
3958 if (ret < 0) {
3959 hdd_err(
3960 "unable to get dev name: %s, err = 0x%x",
3961 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303962 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003963 }
3964 }
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003965
3966 ret = register_netdevice(dev);
3967 if (ret) {
3968 hdd_err("register_netdevice(%s) failed, err = 0x%x",
3969 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303970 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003971 }
3972 } else {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003973 ret = register_netdev(dev);
3974 if (ret) {
3975 hdd_err("register_netdev(%s) failed, err = 0x%x",
3976 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303977 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003978 }
3979 }
3980 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
3981
Dustin Browne74003f2018-03-14 12:51:58 -07003982 hdd_exit();
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003983
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303984 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003985}
3986
Jeff Johnson55d2ab42019-03-06 11:43:49 -08003987QDF_STATUS hdd_sme_open_session_callback(uint8_t vdev_id,
Pragaspathi Thilagaraj3551caa2018-09-26 15:52:56 +05303988 QDF_STATUS qdf_status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003989{
Krunal Sonib51eec72017-11-20 21:53:01 -08003990 struct hdd_adapter *adapter;
3991 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003992
Krunal Sonib51eec72017-11-20 21:53:01 -08003993 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3994 if (!hdd_ctx) {
3995 hdd_err("Invalid HDD_CTX");
3996 return QDF_STATUS_E_FAILURE;
3997 }
3998
Jeff Johnson55d2ab42019-03-06 11:43:49 -08003999 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
Jeff Johnsond36fa332019-03-18 13:42:25 -07004000 if (!adapter) {
Jeff Johnson55d2ab42019-03-06 11:43:49 -08004001 hdd_err("NULL adapter for %d", vdev_id);
Krunal Sonib51eec72017-11-20 21:53:01 -08004002 return QDF_STATUS_E_INVAL;
4003 }
Pragaspathi Thilagaraj3551caa2018-09-26 15:52:56 +05304004
4005 if (qdf_status == QDF_STATUS_SUCCESS)
4006 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
4007
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304008 qdf_event_set(&adapter->qdf_session_open_event);
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004009 hdd_debug("session %d opened", adapter->vdev_id);
Krunal Sonib51eec72017-11-20 21:53:01 -08004010
4011 return QDF_STATUS_SUCCESS;
4012}
4013
Jeff Johnson55d2ab42019-03-06 11:43:49 -08004014QDF_STATUS hdd_sme_close_session_callback(uint8_t vdev_id)
Krunal Sonib51eec72017-11-20 21:53:01 -08004015{
4016 struct hdd_adapter *adapter;
4017 struct hdd_context *hdd_ctx;
4018
4019 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
4020 if (!hdd_ctx) {
4021 hdd_err("Invalid HDD_CTX");
4022 return QDF_STATUS_E_FAILURE;
4023 }
4024
Jeff Johnson55d2ab42019-03-06 11:43:49 -08004025 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
Jeff Johnsond36fa332019-03-18 13:42:25 -07004026 if (!adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004027 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304028 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004029 }
4030
4031 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004032 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304033 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004034 }
4035
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004036 /*
4037 * For NAN Data interface, the close session results in the final
4038 * indication to the userspace
4039 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07004040 if (adapter->device_mode == QDF_NDI_MODE)
4041 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004042
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004043 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
4044
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004045 /*
4046 * We can be blocked while waiting for scheduled work to be
4047 * flushed, and the adapter structure can potentially be freed, in
4048 * which case the magic will have been reset. So make sure the
4049 * magic is still good, and hence the adapter structure is still
4050 * valid, before signaling completion
4051 */
4052 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304053 qdf_event_set(&adapter->qdf_session_close_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004054
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304055 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004056}
4057
Jeff Johnson9d295242017-08-29 14:39:48 -07004058int hdd_vdev_ready(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004059{
Min Liu8c5d99e2018-09-10 17:18:44 +08004060 struct wlan_objmgr_vdev *vdev;
Dustin Brownd28772b2017-03-17 14:16:07 -07004061 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004062
Min Liu8c5d99e2018-09-10 17:18:44 +08004063 vdev = hdd_objmgr_get_vdev(adapter);
4064 if (!vdev)
4065 return -EINVAL;
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07004066
Min Liu8c5d99e2018-09-10 17:18:44 +08004067 status = pmo_vdev_ready(vdev);
4068 if (QDF_IS_STATUS_ERROR(status)) {
Rajeev Kumar Sirasanagandla25bdfad2019-02-15 19:15:49 +05304069 hdd_objmgr_put_vdev(vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07004070 return qdf_status_to_os_return(status);
Min Liu8c5d99e2018-09-10 17:18:44 +08004071 }
4072
4073 status = ucfg_reg_11d_vdev_created_update(vdev);
4074 if (QDF_IS_STATUS_ERROR(status)) {
Rajeev Kumar Sirasanagandla25bdfad2019-02-15 19:15:49 +05304075 hdd_objmgr_put_vdev(vdev);
Min Liu8c5d99e2018-09-10 17:18:44 +08004076 return qdf_status_to_os_return(status);
4077 }
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07004078
4079 if (wma_capability_enhanced_mcast_filter())
Min Liu8c5d99e2018-09-10 17:18:44 +08004080 status = ucfg_pmo_enhanced_mc_filter_enable(vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07004081 else
Min Liu8c5d99e2018-09-10 17:18:44 +08004082 status = ucfg_pmo_enhanced_mc_filter_disable(vdev);
4083
Rajeev Kumar Sirasanagandla25bdfad2019-02-15 19:15:49 +05304084 hdd_objmgr_put_vdev(vdev);
Dustin Brownd28772b2017-03-17 14:16:07 -07004085
4086 return qdf_status_to_os_return(status);
4087}
4088
Jeff Johnson9d295242017-08-29 14:39:48 -07004089int hdd_vdev_destroy(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07004090{
4091 QDF_STATUS status;
Dustin Brown2da29eb2018-07-13 14:23:12 -07004092 int errno;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004093 struct hdd_context *hdd_ctx;
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08004094 uint8_t vdev_id;
Min Liu8c5d99e2018-09-10 17:18:44 +08004095 struct wlan_objmgr_vdev *vdev;
Dustin Brownd28772b2017-03-17 14:16:07 -07004096
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004097 vdev_id = adapter->vdev_id;
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08004098 hdd_info("destroying vdev %d", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004099
4100 /* vdev created sanity check */
4101 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Dustin Brown2da29eb2018-07-13 14:23:12 -07004102 hdd_err("vdev %u does not exist", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004103 return -EINVAL;
4104 }
Dustin Brown2da29eb2018-07-13 14:23:12 -07004105
Abhishek Singh628bb6f2019-03-26 14:52:40 +05304106 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
4107
4108 /*
4109 * if this is the last active connection check & stop the
4110 * opportunistic timer first
4111 */
4112 if ((policy_mgr_get_connection_count(hdd_ctx->psoc) == 1 &&
4113 policy_mgr_mode_specific_connection_count(hdd_ctx->psoc,
4114 policy_mgr_convert_device_mode_to_qdf_type(
4115 adapter->device_mode), NULL) == 1) ||
4116 !policy_mgr_get_connection_count(hdd_ctx->psoc))
4117 policy_mgr_check_and_stop_opportunistic_timer(hdd_ctx->psoc,
4118 adapter->vdev_id);
4119
Min Liu8c5d99e2018-09-10 17:18:44 +08004120 vdev = hdd_objmgr_get_vdev(adapter);
4121 if (!vdev)
4122 return -EINVAL;
Ashish Kumar Dhanotiya68ee2e42018-11-19 21:15:14 +05304123
4124 ucfg_pmo_del_wow_pattern(vdev);
Min Liu8c5d99e2018-09-10 17:18:44 +08004125 status = ucfg_reg_11d_vdev_delete_update(vdev);
Abhishek Singh935e4772018-11-21 14:14:10 +05304126 ucfg_scan_vdev_set_disable(vdev, REASON_VDEV_DOWN);
Rajeev Kumar Sirasanagandla25bdfad2019-02-15 19:15:49 +05304127 hdd_objmgr_put_vdev(vdev);
Yue Maf9782842017-05-08 12:49:49 -07004128
Dustin Brownd28772b2017-03-17 14:16:07 -07004129 /* close sme session (destroy vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304130 qdf_event_reset(&adapter->qdf_session_close_event);
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004131 status = sme_close_session(hdd_ctx->mac_handle, adapter->vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004132 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Brown2da29eb2018-07-13 14:23:12 -07004133 hdd_err("failed to close sme session; status:%d", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08004134 goto release_vdev;
Dustin Brownd28772b2017-03-17 14:16:07 -07004135 }
4136
4137 /* block on a completion variable until sme session is closed */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304138 status = qdf_wait_for_event_completion(
4139 &adapter->qdf_session_close_event,
Abhishek Singh13bf0ce2018-10-24 14:26:14 +05304140 SME_CMD_VDEV_CREATE_DELETE_TIMEOUT);
Dustin Brown2da29eb2018-07-13 14:23:12 -07004141
4142 if (QDF_IS_STATUS_ERROR(status)) {
4143 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
4144
Dustin Brownd28772b2017-03-17 14:16:07 -07004145 if (adapter->device_mode == QDF_NDI_MODE)
4146 hdd_ndp_session_end_handler(adapter);
Dustin Brown2da29eb2018-07-13 14:23:12 -07004147
4148 if (status == QDF_STATUS_E_TIMEOUT)
4149 hdd_err("timed out waiting for sme close session");
4150 else if (adapter->qdf_session_close_event.force_set)
4151 hdd_info("SSR occurred during sme close session");
4152 else
4153 hdd_err("failed to wait for sme close session; status:%u",
4154 status);
Dustin Brownd28772b2017-03-17 14:16:07 -07004155 }
Jiachao Wu2c42c222018-01-15 18:13:19 +08004156
Yue Maf9782842017-05-08 12:49:49 -07004157release_vdev:
Jiachao Wu2c42c222018-01-15 18:13:19 +08004158
Sandeep Puligillaef415362017-08-30 16:37:13 -07004159 /* do vdev logical destroy via objmgr */
Dustin Brownb277dd62018-01-26 15:17:33 -08004160 errno = hdd_objmgr_release_and_destroy_vdev(adapter);
Sandeep Puligillaef415362017-08-30 16:37:13 -07004161 if (errno) {
Dustin Brownb277dd62018-01-26 15:17:33 -08004162 hdd_err("failed to destroy objmgr vdev; errno:%d", errno);
Sandeep Puligillaef415362017-08-30 16:37:13 -07004163 return errno;
4164 }
4165
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08004166 hdd_info("vdev %d destroyed successfully", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004167
4168 return 0;
4169}
4170
Krunal Sonib51eec72017-11-20 21:53:01 -08004171static int hdd_set_sme_session_param(struct hdd_adapter *adapter,
4172 struct sme_session_params *session_param,
Jeff Johnson6a18c962018-07-01 09:09:37 -07004173 csr_roam_complete_cb callback,
Krunal Sonib51eec72017-11-20 21:53:01 -08004174 void *callback_ctx)
Dustin Brownd28772b2017-03-17 14:16:07 -07004175{
Dustin Brownd28772b2017-03-17 14:16:07 -07004176 uint32_t type;
4177 uint32_t sub_type;
Krunal Sonib51eec72017-11-20 21:53:01 -08004178 QDF_STATUS status;
Dustin Brownd28772b2017-03-17 14:16:07 -07004179
4180 /* determine vdev (sub)type */
4181 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304182 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07004183 hdd_err("failed to get vdev type: %d", status);
4184 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004185 }
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004186 session_param->sme_session_id = adapter->vdev_id;
Krunal Sonib51eec72017-11-20 21:53:01 -08004187 session_param->self_mac_addr = (uint8_t *)&adapter->mac_addr;
4188 session_param->type_of_persona = type;
4189 session_param->subtype_of_persona = sub_type;
4190 session_param->session_open_cb = hdd_sme_open_session_callback;
4191 session_param->session_close_cb = hdd_sme_close_session_callback;
4192 session_param->callback = callback;
4193 session_param->callback_ctx = callback_ctx;
4194
4195 return 0;
4196}
4197
gaurank kathpalia6c4b50c2019-02-28 14:07:48 +05304198void
gaurank kathpalia78af1932018-10-27 20:33:10 +05304199hdd_store_nss_chains_cfg_in_vdev(struct hdd_adapter *adapter)
4200{
4201 struct wlan_mlme_nss_chains vdev_ini_cfg;
4202 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
4203
gaurank kathpaliab414bce2018-11-09 18:44:46 +05304204 /* Populate the nss chain params from ini for this vdev type */
gaurank kathpalia78af1932018-10-27 20:33:10 +05304205 sme_populate_nss_chain_params(hdd_ctx->mac_handle, &vdev_ini_cfg,
4206 adapter->device_mode,
4207 hdd_ctx->num_rf_chains);
gaurank kathpaliab414bce2018-11-09 18:44:46 +05304208
4209 /* Store the nss chain config into the vdev */
4210 sme_store_nss_chains_cfg_in_vdev(adapter->vdev, &vdev_ini_cfg);
gaurank kathpalia78af1932018-10-27 20:33:10 +05304211}
gaurank kathpalia6982d472018-10-31 21:54:15 +05304212
4213bool hdd_is_vdev_in_conn_state(struct hdd_adapter *adapter)
4214{
4215 switch (adapter->device_mode) {
4216 case QDF_STA_MODE:
4217 case QDF_P2P_CLIENT_MODE:
4218 case QDF_P2P_DEVICE_MODE:
4219 return hdd_conn_is_connected(
4220 WLAN_HDD_GET_STATION_CTX_PTR(adapter));
4221 case QDF_SAP_MODE:
4222 case QDF_P2P_GO_MODE:
4223 return (test_bit(SOFTAP_BSS_STARTED,
4224 &adapter->event_flags));
4225 default:
4226 hdd_err("Device mode %d invalid", adapter->device_mode);
4227 return 0;
4228 }
4229
4230 return 0;
4231}
4232
Krunal Sonib51eec72017-11-20 21:53:01 -08004233int hdd_vdev_create(struct hdd_adapter *adapter,
Jeff Johnson6a18c962018-07-01 09:09:37 -07004234 csr_roam_complete_cb callback, void *ctx)
Krunal Sonib51eec72017-11-20 21:53:01 -08004235{
4236 QDF_STATUS status;
4237 int errno;
Karthik Kantamneni9180c752018-11-14 12:14:17 +05304238 bool bval;
Krunal Sonib51eec72017-11-20 21:53:01 -08004239 struct hdd_context *hdd_ctx;
4240 struct sme_session_params sme_session_params = {0};
Min Liu8c5d99e2018-09-10 17:18:44 +08004241 struct wlan_objmgr_vdev *vdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004242
4243 hdd_info("creating new vdev");
Dustin Brownd28772b2017-03-17 14:16:07 -07004244
4245 /* do vdev create via objmgr */
4246 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown07901ec2018-09-07 11:02:41 -07004247 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07004248 if (errno) {
4249 hdd_err("failed to create objmgr vdev: %d", errno);
4250 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004251 }
Dustin Brownd28772b2017-03-17 14:16:07 -07004252
4253 /* Open a SME session (prepare vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304254 status = qdf_event_reset(&adapter->qdf_session_open_event);
4255 if (QDF_STATUS_SUCCESS != status) {
4256 hdd_err("failed to reinit session open event");
4257 return -EINVAL;
4258 }
Krunal Sonib51eec72017-11-20 21:53:01 -08004259 errno = hdd_set_sme_session_param(adapter, &sme_session_params,
4260 callback, ctx);
4261 if (errno) {
4262 hdd_err("failed to populating SME params");
4263 goto objmgr_vdev_destroy_procedure;
4264 }
Jeff Johnson16528362018-06-14 12:34:16 -07004265 status = sme_open_session(hdd_ctx->mac_handle, &sme_session_params);
Dustin Brownd28772b2017-03-17 14:16:07 -07004266 if (QDF_IS_STATUS_ERROR(status)) {
4267 hdd_err("failed to open sme session: %d", status);
4268 errno = qdf_status_to_os_return(status);
Krunal Soni4a020c72017-10-30 20:58:40 -07004269 goto objmgr_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07004270 }
4271
4272 /* block on a completion variable until sme session is opened */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304273 status = qdf_wait_for_event_completion(&adapter->qdf_session_open_event,
Abhishek Singh13bf0ce2018-10-24 14:26:14 +05304274 SME_CMD_VDEV_CREATE_DELETE_TIMEOUT);
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304275 if (QDF_STATUS_SUCCESS != status) {
4276 if (adapter->qdf_session_open_event.force_set) {
4277 /*
4278 * SSR/PDR has caused shutdown, which has forcefully
4279 * set the event. Return without the closing session.
4280 */
Jeff Johnson912b1bb2019-03-06 10:12:36 -08004281 adapter->vdev_id = WLAN_UMAC_VDEV_ID_MAX;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304282 hdd_err("Session open event forcefully set");
4283 return -EINVAL;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304284 }
Jeff Johnsonc66d3102018-02-28 11:58:26 -08004285
4286 if (QDF_STATUS_E_TIMEOUT == status)
4287 hdd_err("Session failed to open within timeout period");
4288 else
4289 hdd_err("Failed to wait for session open event(status-%d)",
4290 status);
4291 errno = -ETIMEDOUT;
4292 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
4293 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07004294 }
4295
Pragaspathi Thilagaraj3551caa2018-09-26 15:52:56 +05304296 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
4297 hdd_err("Session failed to open due to vdev create failure");
4298 errno = -EINVAL;
4299 goto objmgr_vdev_destroy_procedure;
4300 }
4301
Dustin Brownd28772b2017-03-17 14:16:07 -07004302 /* firmware ready for component communication, raise vdev_ready event */
4303 errno = hdd_vdev_ready(adapter);
4304 if (errno) {
4305 hdd_err("failed to dispatch vdev ready event: %d", errno);
Krunal Soni4a020c72017-10-30 20:58:40 -07004306 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07004307 }
4308
Naveen Rawat2b430892018-03-13 13:58:18 -07004309 if (adapter->device_mode == QDF_STA_MODE) {
Karthik Kantamneni9180c752018-11-14 12:14:17 +05304310 bval = false;
4311 status = ucfg_mlme_get_rtt_mac_randomization(hdd_ctx->psoc,
4312 &bval);
4313 if (QDF_IS_STATUS_ERROR(status))
4314 hdd_err("unable to get RTT MAC randomization value");
4315
4316 hdd_debug("setting RTT mac randomization param: %d", bval);
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004317 errno = sme_cli_set_command(adapter->vdev_id,
Naveen Rawat2b430892018-03-13 13:58:18 -07004318 WMI_VDEV_PARAM_ENABLE_DISABLE_RTT_INITIATOR_RANDOM_MAC,
Karthik Kantamneni9180c752018-11-14 12:14:17 +05304319 bval,
Naveen Rawat2b430892018-03-13 13:58:18 -07004320 VDEV_CMD);
4321 if (0 != errno)
4322 hdd_err("RTT mac randomization param set failed %d",
4323 errno);
4324 }
4325
Bala Venkatesh110b03e2018-07-10 16:02:08 +05304326 if (adapter->device_mode == QDF_STA_MODE ||
Min Liu8c5d99e2018-09-10 17:18:44 +08004327 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
4328 vdev = hdd_objmgr_get_vdev(adapter);
4329 if (!vdev)
4330 goto hdd_vdev_destroy_procedure;
4331 wlan_vdev_set_max_peer_count(vdev, HDD_MAX_VDEV_PEER_COUNT);
Rajeev Kumar Sirasanagandla25bdfad2019-02-15 19:15:49 +05304332 hdd_objmgr_put_vdev(vdev);
Min Liu8c5d99e2018-09-10 17:18:44 +08004333 }
Bala Venkatesh110b03e2018-07-10 16:02:08 +05304334
gaurank kathpalia78af1932018-10-27 20:33:10 +05304335 hdd_store_nss_chains_cfg_in_vdev(adapter);
4336
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004337 hdd_info("vdev %d created successfully", adapter->vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004338
4339 return 0;
4340
4341 /*
4342 * Due to legacy constraints, we need to destroy in the same order as
4343 * create. So, split error handling into 2 cases to accommodate.
4344 */
4345
Krunal Soni4a020c72017-10-30 20:58:40 -07004346objmgr_vdev_destroy_procedure:
Dustin Brown7d043f62017-03-27 12:07:36 -07004347 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07004348
4349 return errno;
4350
Krunal Soni4a020c72017-10-30 20:58:40 -07004351hdd_vdev_destroy_procedure:
Dustin Brownd28772b2017-03-17 14:16:07 -07004352 QDF_BUG(!hdd_vdev_destroy(adapter));
4353
4354 return errno;
4355}
4356
Jeff Johnson9d295242017-08-29 14:39:48 -07004357QDF_STATUS hdd_init_station_mode(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07004358{
Jeff Johnsonb9424862017-10-30 08:49:35 -07004359 struct hdd_station_ctx *sta_ctx = &adapter->session.station;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004360 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07004361 QDF_STATUS status;
4362 int ret_val;
Jeff Johnson16528362018-06-14 12:34:16 -07004363 mac_handle_t mac_handle;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304364 bool bval = false;
Dustin Brownd28772b2017-03-17 14:16:07 -07004365
Dustin Brownd28772b2017-03-17 14:16:07 -07004366 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson16528362018-06-14 12:34:16 -07004367 mac_handle = hdd_ctx->mac_handle;
4368 sme_set_curr_device_mode(mac_handle, adapter->device_mode);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304369 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &bval);
4370 if (!QDF_IS_STATUS_SUCCESS(status))
4371 hdd_err("unable to get vht_enable2x2");
4372 sme_set_pdev_ht_vht_ies(mac_handle, bval);
4373
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004374 sme_set_vdev_ies_per_band(mac_handle, adapter->vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004375
Jeff Johnson7f2c5912018-03-23 11:42:28 -07004376 hdd_roam_profile_init(adapter);
4377 hdd_register_wext(adapter->dev);
4378
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07004379 hdd_conn_set_connection_state(adapter, eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004380
Jeff Johnson0a082d92019-03-04 12:25:49 -08004381 qdf_mem_set(sta_ctx->conn_info.sta_id,
4382 sizeof(sta_ctx->conn_info.sta_id),
4383 HDD_WLAN_INVALID_STA_ID);
Hanumanth Reddy Pothulab2d729c2017-05-30 11:49:53 +05304384
Deepak Dhamdherea2785822016-11-17 01:17:45 -08004385 /* set fast roaming capability in sme session */
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004386 status = sme_config_fast_roaming(mac_handle, adapter->vdev_id,
Abhishek Singh1f217ec2017-12-22 11:48:27 +05304387 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004388 /* Set the default operation channel */
Jeff Johnson8626e932019-02-27 18:35:22 -08004389 sta_ctx->conn_info.channel =
Vignesh Viswanathana0358ff2018-11-27 09:53:07 +05304390 hdd_ctx->config->operating_channel;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004391
4392 /* Make the default Auth Type as OPEN */
Jeff Johnson96e33512019-02-27 15:10:21 -08004393 sta_ctx->conn_info.auth_type = eCSR_AUTH_TYPE_OPEN_SYSTEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004394
4395 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304396 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004397 hdd_err("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004398 status, status);
4399 goto error_init_txrx;
4400 }
4401
4402 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4403
4404 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304405 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004406 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004407 status, status);
4408 goto error_wmm_init;
4409 }
4410
4411 set_bit(WMM_INIT_DONE, &adapter->event_flags);
4412
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004413 ret_val = sme_cli_set_command(adapter->vdev_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004414 WMI_PDEV_PARAM_BURST_ENABLE,
Dundi Raviteja3aa01be2018-05-21 18:58:59 +05304415 HDD_ENABLE_SIFS_BURST_DEFAULT,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004416 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07004417 if (ret_val)
4418 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004419
Poddar, Siddarth4b3f7312017-11-02 17:00:20 +05304420 /*
4421 * In case of USB tethering, LRO is disabled. If SSR happened
4422 * during that time, then as part of SSR init, do not enable
4423 * the LRO again. Keep the LRO state same as before SSR.
4424 */
jitiphil377bcc12018-10-05 19:46:08 +05304425 if (cdp_cfg_get(cds_get_context(QDF_MODULE_ID_SOC),
4426 cfg_dp_lro_enable) &&
4427 !(qdf_atomic_read(&hdd_ctx->vendor_disable_lro_flag)))
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -07004428 adapter->dev->features |= NETIF_F_LRO;
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05304429
Rakshith Suresh Patkar9f5c5862019-02-04 16:23:02 +05304430 if (cdp_cfg_get(cds_get_context(QDF_MODULE_ID_SOC),
4431 cfg_dp_enable_ip_tcp_udp_checksum_offload))
4432 adapter->dev->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
4433 adapter->dev->features |= NETIF_F_RXCSUM;
4434
4435 hdd_set_tso_flags(hdd_ctx, adapter->dev);
4436
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05304437 /* rcpi info initialization */
4438 qdf_mem_zero(&adapter->rcpi, sizeof(adapter->rcpi));
4439
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304440 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004441
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004442error_wmm_init:
4443 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4444 hdd_deinit_tx_rx(adapter);
4445error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07004446 hdd_unregister_wext(adapter->dev);
Dustin Brownd28772b2017-03-17 14:16:07 -07004447 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004448
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004449 return status;
4450}
4451
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304452/**
Krunal Soni4a020c72017-10-30 20:58:40 -07004453 * hdd_deinit_station_mode() - De-initialize the station adapter
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304454 * @hdd_ctx: global hdd context
4455 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07004456 * @rtnl_held: Used to indicate whether or not the caller is holding
4457 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304458 *
4459 * This function De-initializes the STA/P2P/OCB adapter.
4460 *
4461 * Return: None.
4462 */
Krunal Soni4a020c72017-10-30 20:58:40 -07004463static void hdd_deinit_station_mode(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004464 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07004465 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304466{
Dustin Brownfdf17c12018-03-14 12:55:34 -07004467 hdd_enter_dev(adapter->dev);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304468
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05304469 if (adapter->dev) {
4470 if (rtnl_held)
4471 adapter->dev->wireless_handlers = NULL;
4472 else {
4473 rtnl_lock();
4474 adapter->dev->wireless_handlers = NULL;
4475 rtnl_unlock();
4476 }
4477 }
4478
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304479 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
4480 hdd_deinit_tx_rx(adapter);
4481 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4482 }
4483
4484 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
4485 hdd_wmm_adapter_close(adapter);
4486 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
4487 }
4488
Krunal Sonib51eec72017-11-20 21:53:01 -08004489
Dustin Browne74003f2018-03-14 12:51:58 -07004490 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304491}
4492
Krunal Sonib51eec72017-11-20 21:53:01 -08004493void hdd_deinit_adapter(struct hdd_context *hdd_ctx,
4494 struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004495 bool rtnl_held)
4496{
Dustin Brown491d54b2018-03-14 12:39:11 -07004497 hdd_enter();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304498
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004499 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004500 case QDF_STA_MODE:
4501 case QDF_P2P_CLIENT_MODE:
4502 case QDF_P2P_DEVICE_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08004503 case QDF_IBSS_MODE:
4504 case QDF_NDI_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004505 {
Krunal Soni4a020c72017-10-30 20:58:40 -07004506 hdd_deinit_station_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004507 break;
4508 }
4509
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004510 case QDF_SAP_MODE:
4511 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004512 {
Krunal Soni4a020c72017-10-30 20:58:40 -07004513 hdd_deinit_ap_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004514 break;
4515 }
4516
4517 default:
4518 break;
4519 }
4520
Dustin Browne74003f2018-03-14 12:51:58 -07004521 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004522}
4523
Min Liu8c5d99e2018-09-10 17:18:44 +08004524static void hdd_cleanup_adapter(struct hdd_context *hdd_ctx,
4525 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07004526 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004527{
Jeff Johnson5505db82017-11-02 21:19:23 -07004528 struct net_device *dev = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004529
4530 if (adapter)
Jeff Johnson5505db82017-11-02 21:19:23 -07004531 dev = adapter->dev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004532 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004533 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004534 return;
4535 }
4536
Alok Kumarb64650c2018-03-23 17:05:11 +05304537 hdd_nud_deinit_tracking(adapter);
4538 qdf_mutex_destroy(&adapter->disconnection_status_lock);
Nachiket Kukade5f0ce4f2018-06-15 19:47:37 +05304539 hdd_apf_context_destroy(adapter);
Min Liu8c5d99e2018-09-10 17:18:44 +08004540 qdf_spinlock_destroy(&adapter->vdev_lock);
Alok Kumarb64650c2018-03-23 17:05:11 +05304541
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +05304542 wlan_hdd_debugfs_csr_deinit(adapter);
Arunk Khandavallica56d4b2018-11-29 15:46:00 +05304543 if (adapter->device_mode == QDF_STA_MODE)
4544 hdd_sysfs_destroy_adapter_root_obj(adapter);
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +05304545
Rajeev Kumardca5f812016-02-04 17:28:06 -08004546 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05304547
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004548 /*
4549 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
4550 * the driver is almost closed and cannot handle either control
4551 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004552 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
4553 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004554 * is not right. Setting this flag helps hdd_stop() to recognize that
4555 * the interface is closed and restricts any operations on that
4556 */
4557 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
4558
4559 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004560 if (rtnl_held)
Jeff Johnson5505db82017-11-02 21:19:23 -07004561 unregister_netdevice(dev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004562 else
Jeff Johnson5505db82017-11-02 21:19:23 -07004563 unregister_netdev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004564 /*
4565 * Note that the adapter is no longer valid at this point
4566 * since the memory has been reclaimed
4567 */
4568 }
4569}
4570
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004571static QDF_STATUS hdd_check_for_existing_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07004572 tSirMacAddr mac_addr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004573{
Jeff Johnson9d295242017-08-29 14:39:48 -07004574 struct hdd_adapter *adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004575
Dustin Brown920397d2017-12-13 16:27:50 -08004576 hdd_for_each_adapter(hdd_ctx, adapter) {
4577 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07004578 mac_addr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304579 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004580 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004581 }
Dustin Brown920397d2017-12-13 16:27:50 -08004582
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304583 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004584}
Ryan Hsu07495ea2016-01-21 15:25:39 -08004585
Arun Khandavalli2358d522016-05-16 18:05:37 +05304586#ifdef CONFIG_FW_LOGS_BASED_ON_INI
4587/**
4588 * hdd_set_fw_log_params() - Set log parameters to FW
4589 * @hdd_ctx: HDD Context
4590 * @adapter: HDD Adapter
4591 *
4592 * This function set the FW Debug log level based on the INI.
4593 *
4594 * Return: None
4595 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004596static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004597 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304598{
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304599 QDF_STATUS status;
4600 uint16_t enable_fw_log_level, enable_fw_log_type;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304601 int ret;
4602
Arun Khandavallifae92942016-08-01 13:31:08 +05304603 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
4604 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004605 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05304606 return;
4607 }
4608
Arun Khandavallifae92942016-08-01 13:31:08 +05304609 /* Enable FW logs based on INI configuration */
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304610 status = ucfg_fwol_get_enable_fw_log_type(hdd_ctx->psoc,
4611 &enable_fw_log_type);
4612 if (QDF_IS_STATUS_ERROR(status))
4613 return;
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004614 ret = sme_cli_set_command(adapter->vdev_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304615 WMI_DBGLOG_TYPE,
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304616 enable_fw_log_type,
Arun Khandavallifae92942016-08-01 13:31:08 +05304617 DBG_CMD);
4618 if (ret != 0)
4619 hdd_err("Failed to enable FW log type ret %d",
4620 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304621
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304622 status = ucfg_fwol_get_enable_fw_log_level(hdd_ctx->psoc,
4623 &enable_fw_log_level);
4624 if (QDF_IS_STATUS_ERROR(status))
4625 return;
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004626 ret = sme_cli_set_command(adapter->vdev_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304627 WMI_DBGLOG_LOG_LEVEL,
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304628 enable_fw_log_level,
Arun Khandavallifae92942016-08-01 13:31:08 +05304629 DBG_CMD);
4630 if (ret != 0)
4631 hdd_err("Failed to enable FW log level ret %d",
4632 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304633
lifengfaa83cb2018-11-24 01:53:56 +08004634 sme_enable_fw_module_log_level(hdd_ctx->mac_handle,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004635 adapter->vdev_id);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304636}
4637#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004638static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004639 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304640{
4641}
4642
4643#endif
4644
4645/**
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004646 * hdd_configure_chain_mask() - programs chain mask to firmware
4647 * @adapter: HDD adapter
4648 *
4649 * Return: 0 on success or errno on failure
4650 */
4651static int hdd_configure_chain_mask(struct hdd_adapter *adapter)
4652{
Naveen Rawat98322472018-03-06 10:29:42 -08004653 QDF_STATUS status;
4654 struct wma_caps_per_phy non_dbs_phy_cap;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004655 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Pragaspathi Thilagaraj4b5c0602018-11-14 22:35:23 +05304656 bool enable2x2 = false, enable_bt_chain_sep = false;
Krunal Sonidf29bc42018-11-15 13:26:29 -08004657 uint8_t dual_mac_feature = DISABLE_DBS_CXN_AND_SCAN;
4658
4659 status = ucfg_policy_mgr_get_dual_mac_feature(hdd_ctx->psoc,
4660 &dual_mac_feature);
4661 if (!QDF_IS_STATUS_SUCCESS(status))
4662 hdd_err("unable to get dual mac feature");
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304663
Pragaspathi Thilagaraj4b5c0602018-11-14 22:35:23 +05304664 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &enable2x2);
4665 if (QDF_IS_STATUS_ERROR(status))
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304666 hdd_err("unable to get vht_enable2x2");
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004667
Pragaspathi Thilagaraj4b5c0602018-11-14 22:35:23 +05304668 status = ucfg_mlme_get_bt_chain_separation_flag(hdd_ctx->psoc,
4669 &enable_bt_chain_sep);
4670 if (QDF_IS_STATUS_ERROR(status))
4671 hdd_debug("unable to get BT chain separation. using default");
4672
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +05304673 hdd_debug("enable2x2: %d, lte_coex: %d, disable_DBS: %d",
Pragaspathi Thilagaraj4b5c0602018-11-14 22:35:23 +05304674 enable2x2, hdd_ctx->lte_coex_ant_share,
Krunal Sonidf29bc42018-11-15 13:26:29 -08004675 dual_mac_feature);
Pragaspathi Thilagaraj4b5c0602018-11-14 22:35:23 +05304676 hdd_debug("enable_bt_chain_separation %d", enable_bt_chain_sep);
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004677
Naveen Rawat98322472018-03-06 10:29:42 -08004678 status = wma_get_caps_for_phyidx_hwmode(&non_dbs_phy_cap,
4679 HW_MODE_DBS_NONE,
4680 CDS_BAND_ALL);
4681 if (QDF_IS_STATUS_ERROR(status)) {
4682 hdd_err("couldn't get phy caps. skip chain mask programming");
4683 return qdf_status_to_os_return(status);
4684 }
4685
4686 if (non_dbs_phy_cap.tx_chain_mask_2G < 3 ||
4687 non_dbs_phy_cap.rx_chain_mask_2G < 3 ||
4688 non_dbs_phy_cap.tx_chain_mask_5G < 3 ||
4689 non_dbs_phy_cap.rx_chain_mask_5G < 3) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -07004690 hdd_debug("firmware not capable. skip chain mask programming");
Naveen Rawat98322472018-03-06 10:29:42 -08004691 return 0;
4692 }
4693
Pragaspathi Thilagaraj4b5c0602018-11-14 22:35:23 +05304694 if (enable2x2 && !enable_bt_chain_sep) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -07004695 hdd_debug("2x2 enabled. skip chain mask programming");
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004696 return 0;
4697 }
4698
Krunal Sonidf29bc42018-11-15 13:26:29 -08004699 if (dual_mac_feature != DISABLE_DBS_CXN_AND_SCAN) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -07004700 hdd_debug("DBS enabled(%d). skip chain mask programming",
Krunal Sonidf29bc42018-11-15 13:26:29 -08004701 dual_mac_feature);
Naveen Rawatb54c72b2018-02-05 10:39:06 -08004702 return 0;
4703 }
4704
Naveen Rawatdacb5032018-02-08 15:23:24 -08004705 if (hdd_ctx->lte_coex_ant_share) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -07004706 hdd_debug("lte ant sharing enabled. skip chainmask programming");
Naveen Rawatdacb5032018-02-08 15:23:24 -08004707 return 0;
4708 }
4709
Dustin Brown1dbefe62018-09-11 16:32:03 -07004710 status = ucfg_mlme_configure_chain_mask(hdd_ctx->psoc,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004711 adapter->vdev_id);
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +05304712 if (status != QDF_STATUS_SUCCESS)
4713 goto error;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004714
4715 return 0;
4716
4717error:
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +05304718 hdd_err("WMI PDEV set param failed");
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004719 return -EINVAL;
4720}
4721
4722/**
Dundi Raviteja3b637092018-09-12 13:42:50 +05304723 * hdd_send_coex_config_params() - Send coex config params to FW
4724 * @hdd_ctx: HDD context
4725 * @adapter: Primary adapter context
4726 *
4727 * This function is used to send all coex config related params to FW
4728 *
4729 * Return: 0 on success and -EINVAL on failure
4730 */
4731static int hdd_send_coex_config_params(struct hdd_context *hdd_ctx,
4732 struct hdd_adapter *adapter)
4733{
4734 struct coex_config_params coex_cfg_params = {0};
4735 struct wlan_fwol_coex_config config = {0};
Dustin Brown05d81302018-09-11 16:49:22 -07004736 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Dundi Raviteja3b637092018-09-12 13:42:50 +05304737 QDF_STATUS status;
4738
4739 if (!hdd_ctx) {
4740 hdd_err("hdd_ctx is invalid");
4741 goto err;
4742 }
4743
4744 if (!adapter) {
4745 hdd_err("adapter is invalid");
4746 goto err;
4747 }
4748
4749 if (!psoc) {
4750 hdd_err("HDD psoc is invalid");
4751 goto err;
4752 }
4753
4754 status = ucfg_fwol_get_coex_config_params(psoc, &config);
4755 if (QDF_IS_STATUS_ERROR(status)) {
4756 hdd_err("Unable to get coex config params");
4757 goto err;
4758 }
4759
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004760 coex_cfg_params.vdev_id = adapter->vdev_id;
Dundi Raviteja3b637092018-09-12 13:42:50 +05304761 coex_cfg_params.config_type = WMI_COEX_CONFIG_TX_POWER;
4762 coex_cfg_params.config_arg1 = config.max_tx_power_for_btc;
4763
4764 status = sme_send_coex_config_cmd(&coex_cfg_params);
4765 if (QDF_IS_STATUS_ERROR(status)) {
4766 hdd_err("Failed to send coex Tx power");
4767 goto err;
4768 }
4769
4770 coex_cfg_params.config_type = WMI_COEX_CONFIG_HANDOVER_RSSI;
4771 coex_cfg_params.config_arg1 = config.wlan_low_rssi_threshold;
4772
4773 status = sme_send_coex_config_cmd(&coex_cfg_params);
4774 if (QDF_IS_STATUS_ERROR(status)) {
4775 hdd_err("Failed to send coex handover RSSI");
4776 goto err;
4777 }
4778
4779 coex_cfg_params.config_type = WMI_COEX_CONFIG_BTC_MODE;
4780 coex_cfg_params.config_arg1 = config.btc_mode;
4781
4782 status = sme_send_coex_config_cmd(&coex_cfg_params);
4783 if (QDF_IS_STATUS_ERROR(status)) {
4784 hdd_err("Failed to send coex BTC mode");
4785 goto err;
4786 }
4787
4788 coex_cfg_params.config_type = WMI_COEX_CONFIG_ANTENNA_ISOLATION;
4789 coex_cfg_params.config_arg1 = config.antenna_isolation;
4790
4791 status = sme_send_coex_config_cmd(&coex_cfg_params);
4792 if (QDF_IS_STATUS_ERROR(status)) {
4793 hdd_err("Failed to send coex antenna isolation");
4794 goto err;
4795 }
4796
4797 coex_cfg_params.config_type = WMI_COEX_CONFIG_BT_LOW_RSSI_THRESHOLD;
4798 coex_cfg_params.config_arg1 = config.bt_low_rssi_threshold;
4799
4800 status = sme_send_coex_config_cmd(&coex_cfg_params);
4801 if (QDF_IS_STATUS_ERROR(status)) {
4802 hdd_err("Failed to send coex BT low RSSI threshold");
4803 goto err;
4804 }
4805
4806 coex_cfg_params.config_type = WMI_COEX_CONFIG_BT_INTERFERENCE_LEVEL;
4807 coex_cfg_params.config_arg1 = config.bt_interference_low_ll;
4808 coex_cfg_params.config_arg2 = config.bt_interference_low_ul;
4809 coex_cfg_params.config_arg3 = config.bt_interference_medium_ll;
4810 coex_cfg_params.config_arg4 = config.bt_interference_medium_ul;
4811 coex_cfg_params.config_arg5 = config.bt_interference_high_ll;
4812 coex_cfg_params.config_arg6 = config.bt_interference_high_ul;
4813
4814 status = sme_send_coex_config_cmd(&coex_cfg_params);
4815 if (QDF_IS_STATUS_ERROR(status)) {
4816 hdd_err("Failed to send coex BT interference level");
4817 goto err;
4818 }
stonezc9936cb2019-03-11 16:41:22 +08004819
4820 if (wlan_hdd_mpta_helper_enable(&coex_cfg_params, &config))
4821 goto err;
4822
Dundi Raviteja3b637092018-09-12 13:42:50 +05304823 return 0;
4824err:
4825 return -EINVAL;
4826}
4827
4828/**
Arun Khandavalli2358d522016-05-16 18:05:37 +05304829 * hdd_set_fw_params() - Set parameters to firmware
4830 * @adapter: HDD adapter
4831 *
4832 * This function Sets various parameters to fw once the
4833 * adapter is started.
4834 *
4835 * Return: 0 on success or errno on failure
4836 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004837int hdd_set_fw_params(struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304838{
4839 int ret;
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304840 uint16_t upper_brssi_thresh, lower_brssi_thresh, rts_profile;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +05304841 bool enable_dtim_1chrx;
4842 QDF_STATUS status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004843 struct hdd_context *hdd_ctx;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304844 bool bval = false;
Manikandan Mohand350c192018-11-29 14:01:12 -08004845 uint8_t max_amsdu_len, enable_tx_sch_delay;
4846 uint32_t dtim_sel_diversity, enable_secondary_rate;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304847
Dustin Brownfdf17c12018-03-14 12:55:34 -07004848 hdd_enter_dev(adapter->dev);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304849
4850 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
4851 if (!hdd_ctx)
4852 return -EINVAL;
4853
Dustin Brown732ab9c2017-06-15 13:24:09 -07004854 if (cds_get_conparam() == QDF_GLOBAL_FTM_MODE) {
4855 hdd_debug("FTM Mode is active; nothing to do");
4856 return 0;
4857 }
4858
Manikandan Mohand350c192018-11-29 14:01:12 -08004859 ret = -1;
4860 if (QDF_IS_STATUS_SUCCESS(ucfg_fwol_get_lprx_enable(hdd_ctx->psoc,
4861 &bval))) {
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004862 ret = sme_cli_set_command(adapter->vdev_id,
Manikandan Mohand350c192018-11-29 14:01:12 -08004863 WMI_PDEV_PARAM_DTIM_SYNTH,
4864 bval, PDEV_CMD);
4865 }
Ashish Kumar Dhanotiyab8630ab2017-07-21 14:18:14 +05304866 if (ret) {
4867 hdd_err("Failed to set LPRx");
4868 goto error;
4869 }
4870
Pragaspathi Thilagaraj784c4922018-12-02 22:47:29 +05304871 ucfg_mlme_get_dtim_selection_diversity(hdd_ctx->psoc,
4872 &dtim_sel_diversity);
Ashish Kumar Dhanotiya191d1642018-02-08 17:43:09 +05304873
4874 ret = sme_cli_set_command(
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004875 adapter->vdev_id,
Ashish Kumar Dhanotiya191d1642018-02-08 17:43:09 +05304876 WMI_PDEV_PARAM_1CH_DTIM_OPTIMIZED_CHAIN_SELECTION,
Pragaspathi Thilagaraj784c4922018-12-02 22:47:29 +05304877 dtim_sel_diversity, PDEV_CMD);
Ashish Kumar Dhanotiya191d1642018-02-08 17:43:09 +05304878 if (ret) {
4879 hdd_err("Failed to set DTIM_OPTIMIZED_CHAIN_SELECTION");
4880 goto error;
4881 }
4882
Manikandan Mohand350c192018-11-29 14:01:12 -08004883 ret = -1;
4884 if (QDF_IS_STATUS_SUCCESS(ucfg_fwol_get_enable_tx_sch_delay(
4885 hdd_ctx->psoc, &enable_tx_sch_delay))) {
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004886 ret = sme_cli_set_command(adapter->vdev_id,
Manikandan Mohand350c192018-11-29 14:01:12 -08004887 WMI_PDEV_PARAM_TX_SCH_DELAY,
4888 enable_tx_sch_delay, PDEV_CMD);
4889 }
Ashish Kumar Dhanotiya48dac7d2018-03-28 14:59:50 +05304890 if (ret) {
4891 hdd_err("Failed to set WMI_PDEV_PARAM_TX_SCH_DELAY");
4892 goto error;
4893 }
4894
Manikandan Mohand350c192018-11-29 14:01:12 -08004895 ret = -1;
4896 if (QDF_IS_STATUS_SUCCESS(ucfg_fwol_get_enable_secondary_rate(
4897 hdd_ctx->psoc, &enable_secondary_rate))) {
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004898 ret = sme_cli_set_command(adapter->vdev_id,
Manikandan Mohand350c192018-11-29 14:01:12 -08004899 WMI_PDEV_PARAM_SECONDARY_RETRY_ENABLE,
4900 enable_secondary_rate, PDEV_CMD);
4901 }
Ashish Kumar Dhanotiya959b38c2018-04-06 21:07:57 +05304902 if (ret) {
4903 hdd_err("Failed to set WMI_PDEV_PARAM_SECONDARY_RETRY_ENABLE");
4904 goto error;
4905 }
4906
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304907 if (adapter->device_mode == QDF_STA_MODE) {
Sourav Mohapatrad9387d82018-09-07 12:28:52 +05304908 status = ucfg_get_upper_brssi_thresh(hdd_ctx->psoc,
4909 &upper_brssi_thresh);
4910 if (QDF_IS_STATUS_ERROR(status))
4911 return -EINVAL;
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304912
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004913 sme_set_smps_cfg(adapter->vdev_id,
Sourav Mohapatrad9387d82018-09-07 12:28:52 +05304914 HDD_STA_SMPS_PARAM_UPPER_BRSSI_THRESH,
4915 upper_brssi_thresh);
4916
4917 status = ucfg_get_lower_brssi_thresh(hdd_ctx->psoc,
4918 &lower_brssi_thresh);
4919 if (QDF_IS_STATUS_ERROR(status))
4920 return -EINVAL;
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304921
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004922 sme_set_smps_cfg(adapter->vdev_id,
Sourav Mohapatrad9387d82018-09-07 12:28:52 +05304923 HDD_STA_SMPS_PARAM_LOWER_BRSSI_THRESH,
4924 lower_brssi_thresh);
4925
4926 status = ucfg_get_enable_dtim_1chrx(hdd_ctx->psoc,
4927 &enable_dtim_1chrx);
4928 if (QDF_IS_STATUS_ERROR(status))
4929 return -EINVAL;
4930
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004931 sme_set_smps_cfg(adapter->vdev_id,
Sourav Mohapatrad9387d82018-09-07 12:28:52 +05304932 HDD_STA_SMPS_PARAM_DTIM_1CHRX_ENABLE,
4933 enable_dtim_1chrx);
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304934 }
4935
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304936 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &bval);
4937 if (!QDF_IS_STATUS_SUCCESS(status))
4938 hdd_err("unable to get vht_enable2x2");
4939
4940 if (bval) {
Dustin Brown732ab9c2017-06-15 13:24:09 -07004941 hdd_debug("configuring 2x2 mode fw params");
4942
Vignesh Viswanathana851d752018-10-03 19:44:38 +05304943 ret = sme_set_cck_tx_fir_override(hdd_ctx->mac_handle,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004944 adapter->vdev_id);
Dustin Brown732ab9c2017-06-15 13:24:09 -07004945 if (ret) {
4946 hdd_err("WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE set failed %d",
4947 ret);
4948 goto error;
4949 }
Liangwei Dong22810e82018-03-15 03:42:12 -04004950
4951 if (hdd_configure_chain_mask(adapter))
4952 goto error;
Dustin Brown732ab9c2017-06-15 13:24:09 -07004953 } else {
Arun Khandavalli2358d522016-05-16 18:05:37 +05304954#define HDD_DTIM_1CHAIN_RX_ID 0x5
4955#define HDD_SMPS_PARAM_VALUE_S 29
Dustin Brown732ab9c2017-06-15 13:24:09 -07004956 hdd_debug("configuring 1x1 mode fw params");
4957
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004958 /*
4959 * Disable DTIM 1 chain Rx when in 1x1,
4960 * we are passing two value
4961 * as param_id << 29 | param_value.
4962 * Below param_value = 0(disable)
4963 */
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004964 ret = sme_cli_set_command(adapter->vdev_id,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004965 WMI_STA_SMPS_PARAM_CMDID,
4966 HDD_DTIM_1CHAIN_RX_ID <<
4967 HDD_SMPS_PARAM_VALUE_S,
4968 VDEV_CMD);
4969 if (ret) {
4970 hdd_err("DTIM 1 chain set failed %d", ret);
4971 goto error;
4972 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304973
Arun Khandavalli2358d522016-05-16 18:05:37 +05304974#undef HDD_DTIM_1CHAIN_RX_ID
4975#undef HDD_SMPS_PARAM_VALUE_S
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004976
4977 if (hdd_configure_chain_mask(adapter))
4978 goto error;
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004979 }
4980
Vignesh Viswanathana851d752018-10-03 19:44:38 +05304981 ret = sme_set_enable_mem_deep_sleep(hdd_ctx->mac_handle,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004982 adapter->vdev_id);
Dustin Brown732ab9c2017-06-15 13:24:09 -07004983 if (ret) {
4984 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d", ret);
4985 goto error;
4986 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304987
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304988 status = ucfg_fwol_get_rts_profile(hdd_ctx->psoc, &rts_profile);
4989 if (QDF_IS_STATUS_ERROR(status))
4990 return -EINVAL;
4991
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004992 ret = sme_cli_set_command(adapter->vdev_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004993 WMI_VDEV_PARAM_ENABLE_RTSCTS,
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304994 rts_profile,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004995 VDEV_CMD);
4996 if (ret) {
4997 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
4998 goto error;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304999 }
5000
Vignesh Viswanathanddc89e52018-11-02 18:43:42 +05305001 status = ucfg_mlme_get_max_amsdu_num(hdd_ctx->psoc, &max_amsdu_len);
5002 if (QDF_IS_STATUS_ERROR(status)) {
5003 hdd_err("Failed to get Max AMSDU Num");
5004 goto error;
5005 }
5006
5007 hdd_debug("SET AMSDU num %d", max_amsdu_len);
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07005008
Jeff Johnson5a6fc962019-02-04 14:20:25 -08005009 ret = wma_cli_set_command(adapter->vdev_id,
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07005010 GEN_VDEV_PARAM_AMSDU,
Vignesh Viswanathanddc89e52018-11-02 18:43:42 +05305011 max_amsdu_len,
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07005012 GEN_CMD);
5013 if (ret != 0) {
5014 hdd_err("GEN_VDEV_PARAM_AMSDU set failed %d", ret);
5015 goto error;
5016 }
5017
Arun Khandavalli2358d522016-05-16 18:05:37 +05305018 hdd_set_fw_log_params(hdd_ctx, adapter);
Dundi Raviteja3b637092018-09-12 13:42:50 +05305019
5020 ret = hdd_send_coex_config_params(hdd_ctx, adapter);
5021 if (ret) {
5022 hdd_warn("Error initializing coex config params");
5023 goto error;
5024 }
5025
Dustin Browne74003f2018-03-14 12:51:58 -07005026 hdd_exit();
Dustin Brown732ab9c2017-06-15 13:24:09 -07005027
Arun Khandavalli2358d522016-05-16 18:05:37 +05305028 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05305029
Arun Khandavalli2358d522016-05-16 18:05:37 +05305030error:
5031 return -EINVAL;
5032}
5033
Ryan Hsu07495ea2016-01-21 15:25:39 -08005034/**
Abhinav Kumarcc959f12018-08-09 13:58:30 +05305035 * hdd_init_completion() - Initialize Completion Variables
5036 * @adapter: HDD adapter
5037 *
5038 * This function Initialize the completion variables for
5039 * a particular adapter
5040 *
5041 * Return: None
5042 */
5043static void hdd_init_completion(struct hdd_adapter *adapter)
5044{
5045 init_completion(&adapter->disconnect_comp_var);
5046 init_completion(&adapter->roaming_comp_var);
5047 init_completion(&adapter->linkup_event_var);
Abhinav Kumarcc959f12018-08-09 13:58:30 +05305048 init_completion(&adapter->sta_authorized_event);
5049 init_completion(&adapter->offchannel_tx_event);
5050 init_completion(&adapter->tx_action_cnf_event);
5051 init_completion(&adapter->ibss_peer_info_comp);
5052 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
5053}
5054
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05305055static void hdd_reset_locally_admin_bit(struct hdd_context *hdd_ctx,
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07005056 tSirMacAddr mac_addr)
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05305057{
5058 int i;
5059 /*
5060 * Reset locally administered bit for dynamic_mac_list
5061 * also as while releasing the MAC address for any
5062 * interface mac will be compared with dynamic mac list
5063 */
5064 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
5065 if (!qdf_mem_cmp(
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07005066 mac_addr,
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05305067 &hdd_ctx->
5068 dynamic_mac_list[i].dynamic_mac.bytes[0],
5069 sizeof(struct qdf_mac_addr))) {
5070 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(
5071 hdd_ctx->
5072 dynamic_mac_list[i].dynamic_mac.bytes);
5073 break;
5074 }
5075 }
5076 /*
5077 * Reset locally administered bit if the device mode is
5078 * STA
5079 */
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07005080 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(mac_addr);
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05305081 hdd_debug("locally administered bit reset in sta mode: "
Srinivas Girigowdacb7b8b82019-04-10 14:27:47 -07005082 QDF_MAC_ADDR_STR, QDF_MAC_ADDR_ARRAY(mac_addr));
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05305083}
5084
Dustin Brown96b98dd2019-03-06 12:39:37 -08005085static void wlan_hdd_cfg80211_scan_block_cb(struct work_struct *work)
5086{
5087 struct hdd_adapter *adapter =
5088 container_of(work, struct hdd_adapter, scan_block_work);
5089 struct osif_vdev_sync *vdev_sync;
5090
5091 if (osif_vdev_sync_op_start(adapter->dev, &vdev_sync))
5092 return;
5093
5094 wlan_hdd_cfg80211_scan_block(adapter);
5095
5096 osif_vdev_sync_op_stop(vdev_sync);
5097}
5098
Abhinav Kumarcc959f12018-08-09 13:58:30 +05305099/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08005100 * hdd_open_adapter() - open and setup the hdd adatper
5101 * @hdd_ctx: global hdd context
5102 * @session_type: type of the interface to be created
5103 * @iface_name: User-visible name of the interface
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07005104 * @mac_addr: MAC address to assign to the interface
Ryan Hsu07495ea2016-01-21 15:25:39 -08005105 * @name_assign_type: the name of assign type of the netdev
5106 * @rtnl_held: the rtnl lock hold flag
5107 *
5108 * This function open and setup the hdd adpater according to the device
5109 * type request, assign the name, the mac address assigned, and then prepared
5110 * the hdd related parameters, queue, lock and ready to start.
5111 *
5112 * Return: the pointer of hdd adapter, otherwise NULL.
5113 */
Jeff Johnson9d295242017-08-29 14:39:48 -07005114struct hdd_adapter *hdd_open_adapter(struct hdd_context *hdd_ctx, uint8_t session_type,
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07005115 const char *iface_name, tSirMacAddr mac_addr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08005116 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08005117 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005118{
Madhvapathi Sriram8b056652019-03-27 17:38:12 +05305119 struct net_device *ndev = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005120 struct hdd_adapter *adapter = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305121 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005122
5123 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
5124 /*
5125 * Max limit reached on the number of vdevs configured by the
5126 * host. Return error
5127 */
Arun Khandavallifae92942016-08-01 13:31:08 +05305128 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
5129 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005130 return NULL;
5131 }
5132
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07005133 status = wlan_hdd_validate_mac_address((struct qdf_mac_addr *)mac_addr);
Pragaspathi Thilagaraj84b72842018-09-19 22:06:57 +05305134 if (QDF_IS_STATUS_ERROR(status)) {
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07005135 /* Not received valid mac_addr */
Arun Khandavallifae92942016-08-01 13:31:08 +05305136 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005137 return NULL;
5138 }
Pragaspathi Thilagaraj84b72842018-09-19 22:06:57 +05305139
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07005140 status = hdd_check_for_existing_macaddr(hdd_ctx, mac_addr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305141 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowdacb7b8b82019-04-10 14:27:47 -07005142 hdd_err("Duplicate MAC addr: " QDF_MAC_ADDR_STR
Arun Khandavallifae92942016-08-01 13:31:08 +05305143 " already exists",
Srinivas Girigowda34fbba02019-04-08 12:07:44 -07005144 QDF_MAC_ADDR_ARRAY(mac_addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005145 return NULL;
5146 }
5147
5148 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005149 case QDF_STA_MODE:
Ashish Kumar Dhanotiya01485192018-12-24 12:44:06 +05305150 if (!hdd_ctx->config->mac_provision) {
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07005151 hdd_reset_locally_admin_bit(hdd_ctx, mac_addr);
Ashish Kumar Dhanotiya01485192018-12-24 12:44:06 +05305152 /*
5153 * After resetting locally administered bit
5154 * again check if the new mac address is already
5155 * exists.
5156 */
5157 status = hdd_check_for_existing_macaddr(hdd_ctx,
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07005158 mac_addr);
Ashish Kumar Dhanotiya01485192018-12-24 12:44:06 +05305159 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowdacb7b8b82019-04-10 14:27:47 -07005160 hdd_err("Duplicate MAC addr: " QDF_MAC_ADDR_STR
Ashish Kumar Dhanotiya01485192018-12-24 12:44:06 +05305161 " already exists",
Srinivas Girigowda34fbba02019-04-08 12:07:44 -07005162 QDF_MAC_ADDR_ARRAY(mac_addr));
Ashish Kumar Dhanotiya01485192018-12-24 12:44:06 +05305163 return NULL;
5164 }
5165 }
Ashish Kumar Dhanotiya6784b502018-10-17 12:51:10 +05305166
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005167 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005168 case QDF_P2P_CLIENT_MODE:
5169 case QDF_P2P_DEVICE_MODE:
5170 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07005171 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305172 case QDF_MONITOR_MODE:
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07005173 adapter = hdd_alloc_station_adapter(hdd_ctx, mac_addr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08005174 name_assign_type,
5175 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005176
Jeff Johnsond36fa332019-03-18 13:42:25 -07005177 if (!adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05305178 hdd_err("failed to allocate adapter for session %d",
5179 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005180 return NULL;
5181 }
5182
Madhvapathi Sriram8b056652019-03-27 17:38:12 +05305183 ndev = adapter->dev;
5184
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005185 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005186 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005187 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005188 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305189 else if (QDF_MONITOR_MODE == session_type)
5190 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005191 else
5192 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
5193
5194 adapter->device_mode = session_type;
5195
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005196
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005197 /*
5198 * Workqueue which gets scheduled in IPv4 notification
5199 * callback
5200 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005201 INIT_WORK(&adapter->ipv4_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005202 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005203
5204#ifdef WLAN_NS_OFFLOAD
5205 /*
5206 * Workqueue which gets scheduled in IPv6
5207 * notification callback.
5208 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005209 INIT_WORK(&adapter->ipv6_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005210 hdd_ipv6_notifier_work_queue);
5211#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005212 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08005213 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08005214 goto err_free_netdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005215
5216 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07005217 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005218 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305219 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
5220 WLAN_CONTROL_PATH);
Arun Khandavallifae92942016-08-01 13:31:08 +05305221
Alok Kumarb64650c2018-03-23 17:05:11 +05305222 hdd_nud_init_tracking(adapter);
Arunk Khandavallica56d4b2018-11-29 15:46:00 +05305223 if (adapter->device_mode == QDF_STA_MODE ||
5224 adapter->device_mode == QDF_P2P_DEVICE_MODE)
5225 hdd_sysfs_create_adapter_root_obj(adapter);
Alok Kumarb64650c2018-03-23 17:05:11 +05305226 qdf_mutex_create(&adapter->disconnection_status_lock);
5227
Ravi Joshi1a292562017-05-18 16:28:54 -07005228 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005229
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005230 case QDF_P2P_GO_MODE:
5231 case QDF_SAP_MODE:
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07005232 adapter = hdd_wlan_create_ap_dev(hdd_ctx, mac_addr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08005233 name_assign_type,
5234 (uint8_t *) iface_name);
Jeff Johnsond36fa332019-03-18 13:42:25 -07005235 if (!adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005236 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05305237 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005238 return NULL;
5239 }
5240
Madhvapathi Sriram8b056652019-03-27 17:38:12 +05305241 ndev = adapter->dev;
5242
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005243 adapter->wdev.iftype =
5244 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005245 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005246 NL80211_IFTYPE_P2P_GO;
5247 adapter->device_mode = session_type;
5248
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07005249 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08005250 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005251 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08005252
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07005253 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005254 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305255 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
5256 WLAN_CONTROL_PATH);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305257
5258 /*
5259 * Workqueue which gets scheduled in IPv4 notification
5260 * callback
5261 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005262 INIT_WORK(&adapter->ipv4_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305263 hdd_ipv4_notifier_work_queue);
5264
5265#ifdef WLAN_NS_OFFLOAD
5266 /*
5267 * Workqueue which gets scheduled in IPv6
5268 * notification callback.
5269 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005270 INIT_WORK(&adapter->ipv6_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305271 hdd_ipv6_notifier_work_queue);
5272#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005273 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305274 case QDF_FTM_MODE:
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07005275 adapter = hdd_alloc_station_adapter(hdd_ctx, mac_addr,
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305276 name_assign_type,
Lin Bai1c678482017-12-18 18:29:11 +08005277 iface_name);
Jeff Johnsond36fa332019-03-18 13:42:25 -07005278 if (!adapter) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305279 hdd_err("Failed to allocate adapter for FTM mode");
5280 return NULL;
5281 }
Madhvapathi Sriram8b056652019-03-27 17:38:12 +05305282
5283 ndev = adapter->dev;
5284
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305285 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
5286 adapter->device_mode = session_type;
5287 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08005288 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08005289 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08005290
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305291 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07005292 hdd_debug("Disabling queues");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305293 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305294 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
5295 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305296 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005297 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005298 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305299 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005300 return NULL;
5301 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005302
Min Liu8c5d99e2018-09-10 17:18:44 +08005303 qdf_spinlock_create(&adapter->vdev_lock);
5304
Abhinav Kumarcc959f12018-08-09 13:58:30 +05305305 hdd_init_completion(adapter);
hqueaa33ee2017-05-04 17:56:35 +08005306 INIT_WORK(&adapter->scan_block_work, wlan_hdd_cfg80211_scan_block_cb);
Min Liu9be5d4a2018-05-17 11:51:53 +08005307 qdf_list_create(&adapter->blocked_scan_request_q, WLAN_MAX_SCAN_COUNT);
5308 qdf_mutex_create(&adapter->blocked_scan_request_q_lock);
hqueaa33ee2017-05-04 17:56:35 +08005309
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305310 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005311 /* Add it to the hdd's session list. */
Dustin Brown920397d2017-12-13 16:27:50 -08005312 status = hdd_add_adapter_back(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005313 }
5314
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305315 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsond36fa332019-03-18 13:42:25 -07005316 if (adapter) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005317 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
5318 adapter = NULL;
5319 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005320
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005321 return NULL;
5322 }
Nachiket Kukade5f0ce4f2018-06-15 19:47:37 +05305323 hdd_apf_context_init(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005324
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305325 if (QDF_STATUS_SUCCESS == status) {
Dustin Brown1dbefe62018-09-11 16:32:03 -07005326 policy_mgr_set_concurrency_mode(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08005327 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005328
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005329 /* Adapter successfully added. Increment the vdev count */
5330 hdd_ctx->current_intf_count++;
5331
Jeff Johnson5880d792016-08-15 13:32:30 -07005332 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005333 hdd_ctx->current_intf_count);
5334
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08005335 hdd_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005336 }
5337
Rajeev Kumardca5f812016-02-04 17:28:06 -08005338 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07005339 hdd_err("Interface %s wow debug_fs init failed",
5340 netdev_name(adapter->dev));
5341
5342 hdd_info("%s interface created. iftype: %d", netdev_name(adapter->dev),
5343 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005344
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +05305345 if (adapter->device_mode == QDF_STA_MODE)
5346 wlan_hdd_debugfs_csr_init(adapter);
5347
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005348 return adapter;
5349
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005350err_free_netdev:
Jeff Johnson1e851a12017-10-28 14:36:12 -07005351 wlan_hdd_release_intf_addr(hdd_ctx, adapter->mac_addr.bytes);
Madhvapathi Sriram8b056652019-03-27 17:38:12 +05305352
5353 if (ndev)
5354 free_netdev(ndev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005355
5356 return NULL;
5357}
5358
Dustin Brown728d65a2018-10-02 16:27:52 -07005359static void __hdd_close_adapter(struct hdd_context *hdd_ctx,
5360 struct hdd_adapter *adapter,
5361 bool rtnl_held)
5362{
5363 qdf_list_destroy(&adapter->blocked_scan_request_q);
5364 qdf_mutex_destroy(&adapter->blocked_scan_request_q_lock);
5365 policy_mgr_clear_concurrency_mode(hdd_ctx->psoc, adapter->device_mode);
5366
5367 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
5368
5369 if (hdd_ctx->current_intf_count != 0)
5370 hdd_ctx->current_intf_count--;
5371}
5372
5373void hdd_close_adapter(struct hdd_context *hdd_ctx,
5374 struct hdd_adapter *adapter,
5375 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005376{
Dustin Brown920397d2017-12-13 16:27:50 -08005377 /*
Dustin Brown728d65a2018-10-02 16:27:52 -07005378 * Stop the global bus bandwidth timer while touching the adapter list
5379 * to avoid bad memory access by the timer handler.
Dustin Brown920397d2017-12-13 16:27:50 -08005380 */
Dustin Brown920397d2017-12-13 16:27:50 -08005381 hdd_bus_bw_compute_timer_stop(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005382
Dustin Brown920397d2017-12-13 16:27:50 -08005383 hdd_remove_adapter(hdd_ctx, adapter);
Dustin Brown728d65a2018-10-02 16:27:52 -07005384 __hdd_close_adapter(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005385
Dustin Brown920397d2017-12-13 16:27:50 -08005386 /* conditionally restart the bw timer */
5387 hdd_bus_bw_compute_timer_try_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005388}
5389
Dustin Brown728d65a2018-10-02 16:27:52 -07005390void hdd_close_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005391{
Dustin Brown920397d2017-12-13 16:27:50 -08005392 struct hdd_adapter *adapter;
Dustin Brown2c5e0482019-02-05 16:14:43 -08005393 struct osif_vdev_sync *vdev_sync;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005394
Dustin Brown491d54b2018-03-14 12:39:11 -07005395 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005396
Dustin Brown728d65a2018-10-02 16:27:52 -07005397 while (QDF_IS_STATUS_SUCCESS(hdd_remove_front_adapter(hdd_ctx,
5398 &adapter))) {
Dustin Brown2c5e0482019-02-05 16:14:43 -08005399 vdev_sync = osif_vdev_sync_unregister(adapter->dev);
Dustin Brown693b5352019-01-17 10:00:31 -08005400 if (vdev_sync)
Dustin Brown2c5e0482019-02-05 16:14:43 -08005401 osif_vdev_sync_wait_for_ops(vdev_sync);
Dustin Brown693b5352019-01-17 10:00:31 -08005402
Dustin Brown728d65a2018-10-02 16:27:52 -07005403 wlan_hdd_release_intf_addr(hdd_ctx, adapter->mac_addr.bytes);
5404 __hdd_close_adapter(hdd_ctx, adapter, rtnl_held);
Dustin Brown693b5352019-01-17 10:00:31 -08005405
5406 if (vdev_sync)
Dustin Brown2c5e0482019-02-05 16:14:43 -08005407 osif_vdev_sync_destroy(vdev_sync);
Dustin Brown728d65a2018-10-02 16:27:52 -07005408 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005409
Dustin Browne74003f2018-03-14 12:51:58 -07005410 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005411}
5412
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005413void wlan_hdd_reset_prob_rspies(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005414{
Anurag Chouhan6d760662016-02-20 16:05:43 +05305415 struct qdf_mac_addr *bssid = NULL;
Jeff Johnsonc565af12019-03-10 21:09:47 -07005416 tSirUpdateIE update_ie;
Jeff Johnson16528362018-06-14 12:34:16 -07005417 mac_handle_t mac_handle;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005418
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005419 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005420 case QDF_STA_MODE:
5421 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005422 {
Jeff Johnsond377dce2017-10-04 10:32:42 -07005423 struct hdd_station_ctx *sta_ctx =
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005424 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Jeff Johnsone04b6992019-02-27 14:06:55 -08005425 bssid = &sta_ctx->conn_info.bssid;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005426 break;
5427 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005428 case QDF_SAP_MODE:
5429 case QDF_P2P_GO_MODE:
5430 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005431 {
Jeff Johnson1e851a12017-10-28 14:36:12 -07005432 bssid = &adapter->mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005433 break;
5434 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005435 case QDF_FTM_MODE:
5436 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005437 default:
5438 /*
5439 * wlan_hdd_reset_prob_rspies should not have been called
5440 * for these kind of devices
5441 */
Jeff Johnson5880d792016-08-15 13:32:30 -07005442 hdd_err("Unexpected request for the current device type %d",
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005443 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005444 return;
5445 }
5446
Jeff Johnsonc565af12019-03-10 21:09:47 -07005447 qdf_copy_macaddr(&update_ie.bssid, bssid);
5448 update_ie.smeSessionId = adapter->vdev_id;
5449 update_ie.ieBufferlength = 0;
5450 update_ie.pAdditionIEBuffer = NULL;
5451 update_ie.append = true;
5452 update_ie.notify = false;
Jeff Johnson16528362018-06-14 12:34:16 -07005453 mac_handle = hdd_adapter_get_mac_handle(adapter);
5454 if (sme_update_add_ie(mac_handle,
Jeff Johnsonc565af12019-03-10 21:09:47 -07005455 &update_ie,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305456 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005457 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005458 }
5459}
5460
Dustin Browndb2a8be2017-12-20 11:49:56 -08005461QDF_STATUS hdd_stop_adapter(struct hdd_context *hdd_ctx,
5462 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005463{
Dustin Brownd747ecd2018-10-26 16:32:22 -07005464 QDF_STATUS status = QDF_STATUS_SUCCESS;
5465 struct hdd_station_ctx *sta_ctx;
Dustin Brownb4260d52019-01-24 11:53:08 -08005466 struct sap_context *sap_ctx;
Jeff Johnson025618c2018-03-18 14:41:00 -07005467 struct csr_roam_profile *roam_profile;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005468 union iwreq_data wrqu;
Jeff Johnsonc565af12019-03-10 21:09:47 -07005469 tSirUpdateIE update_ie;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005470 unsigned long rc;
Jeff Johnson8f8ceb92019-03-24 08:16:55 -07005471 struct sap_config *sap_config;
Jeff Johnson16528362018-06-14 12:34:16 -07005472 mac_handle_t mac_handle;
Min Liu8c5d99e2018-09-10 17:18:44 +08005473 struct wlan_objmgr_vdev *vdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005474
Dustin Brown491d54b2018-03-14 12:39:11 -07005475 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005476
Jeff Johnson912b1bb2019-03-06 10:12:36 -08005477 if (adapter->vdev_id != WLAN_UMAC_VDEV_ID_MAX)
Dustin Browne7e71d32018-05-11 16:00:08 -07005478 wlan_hdd_cfg80211_deregister_frames(adapter);
5479
Alok Kumarb64650c2018-03-23 17:05:11 +05305480 hdd_nud_ignore_tracking(adapter, true);
5481 hdd_nud_reset_tracking(adapter);
Alok Kumar016a1ac2018-09-16 09:55:50 +05305482 hdd_nud_flush_work(adapter);
hangtian9c47aaf2018-11-26 17:59:39 +08005483 hdd_stop_tsf_sync(adapter);
Alok Kumarb64650c2018-03-23 17:05:11 +05305484
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07005485 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305486 wlan_hdd_netif_queue_control(adapter,
5487 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
5488 WLAN_CONTROL_PATH);
Jeff Johnson16528362018-06-14 12:34:16 -07005489
5490 mac_handle = hdd_ctx->mac_handle;
5491
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005492 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005493 case QDF_STA_MODE:
5494 case QDF_P2P_CLIENT_MODE:
5495 case QDF_IBSS_MODE:
5496 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005497 case QDF_NDI_MODE:
Dustin Brownd747ecd2018-10-26 16:32:22 -07005498 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
5499
5500 if (adapter->device_mode == QDF_NDI_MODE ||
5501 hdd_conn_is_connected(sta_ctx) ||
5502 hdd_is_connecting(sta_ctx)) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005503 INIT_COMPLETION(adapter->disconnect_comp_var);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005504
Jeff Johnson025618c2018-03-18 14:41:00 -07005505 roam_profile = hdd_roam_profile(adapter);
5506 /* For NDI do not use roam_profile */
Dustin Brownd747ecd2018-10-26 16:32:22 -07005507 if (adapter->device_mode == QDF_NDI_MODE)
5508 status = sme_roam_disconnect(
Jeff Johnson16528362018-06-14 12:34:16 -07005509 mac_handle,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08005510 adapter->vdev_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005511 eCSR_DISCONNECT_REASON_NDI_DELETE);
Jeff Johnson025618c2018-03-18 14:41:00 -07005512 else if (roam_profile->BSSType ==
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005513 eCSR_BSS_TYPE_START_IBSS)
Dustin Brownd747ecd2018-10-26 16:32:22 -07005514 status = sme_roam_disconnect(
Jeff Johnson16528362018-06-14 12:34:16 -07005515 mac_handle,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08005516 adapter->vdev_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005517 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Abhinav Kumar19a7a402018-07-12 17:36:57 +05305518 else if (adapter->device_mode == QDF_STA_MODE)
5519 wlan_hdd_disconnect(adapter,
5520 eCSR_DISCONNECT_REASON_DEAUTH);
5521 else
Dustin Brownd747ecd2018-10-26 16:32:22 -07005522 status = sme_roam_disconnect(
Jeff Johnson16528362018-06-14 12:34:16 -07005523 mac_handle,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08005524 adapter->vdev_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005525 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005526 /* success implies disconnect is queued */
5527 if (QDF_IS_STATUS_SUCCESS(status) &&
5528 adapter->device_mode != QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005529 rc = wait_for_completion_timeout(
5530 &adapter->disconnect_comp_var,
5531 msecs_to_jiffies
Abhishek Singhd1f21c72019-01-21 15:16:34 +05305532 (SME_DISCONNECT_TIMEOUT));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005533 if (!rc)
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07005534 hdd_warn("disconn_comp_var wait fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005535 }
Dustin Brownd747ecd2018-10-26 16:32:22 -07005536 if (QDF_IS_STATUS_ERROR(status))
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07005537 hdd_warn("failed to post disconnect");
Dustin Brownd747ecd2018-10-26 16:32:22 -07005538
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005539 memset(&wrqu, '\0', sizeof(wrqu));
5540 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
5541 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
5542 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
5543 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05305544 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005545
Dustin Brownd747ecd2018-10-26 16:32:22 -07005546 wlan_hdd_scan_abort(adapter);
Wu Gao4a1ec8c2018-07-23 19:18:40 +08005547 wlan_hdd_cleanup_actionframe(adapter);
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05305548 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05305549 hdd_clear_fils_connection_info(adapter);
Ashish Kumar Dhanotiya36510832019-02-20 22:13:25 +05305550
Liangwei Donga44d55b2019-03-20 03:22:08 -04005551 status = wlan_hdd_flush_pmksa_cache(adapter);
Ashish Kumar Dhanotiya36510832019-02-20 22:13:25 +05305552 if (QDF_IS_STATUS_ERROR(status))
5553 hdd_err("Cannot flush PMKIDCache");
5554
Visweswara Tanukub5a61242019-03-26 12:24:13 +05305555 hdd_deregister_hl_netdev_fc_timer(adapter);
5556
Dustin Brownd747ecd2018-10-26 16:32:22 -07005557 hdd_deregister_tx_flow_control(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005558
5559#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005560 cancel_work_sync(&adapter->ipv4_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005561#ifdef WLAN_NS_OFFLOAD
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005562 cancel_work_sync(&adapter->ipv6_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005563#endif
5564#endif
5565
Min Liu8c5d99e2018-09-10 17:18:44 +08005566 if (adapter->device_mode == QDF_STA_MODE) {
5567 struct wlan_objmgr_vdev *vdev;
5568
5569 vdev = hdd_objmgr_get_vdev(adapter);
5570 if (vdev) {
5571 wlan_cfg80211_sched_scan_stop(vdev);
Rajeev Kumar Sirasanagandla25bdfad2019-02-15 19:15:49 +05305572 hdd_objmgr_put_vdev(vdev);
Min Liu8c5d99e2018-09-10 17:18:44 +08005573 }
5574 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08005575
Pragaspathi Thilagaraje6f37e02019-01-04 12:24:33 +05305576 /*
5577 * During vdev destroy, if any STA is in connecting state the
5578 * roam command will be in active queue and thus vdev destroy is
5579 * queued in pending queue. In case STA tries to connect to
5580 * multiple BSSID and fails to connect, due to auth/assoc
5581 * timeouts it may take more than vdev destroy time to get
5582 * completed. On vdev destroy timeout vdev is moved to logically
5583 * deleted state. Once connection is completed, vdev destroy is
5584 * activated and to release the self-peer ref count it try to
5585 * get the ref of the vdev, which fails as vdev is logically
5586 * deleted and this leads to peer ref leak. So before vdev
5587 * destroy is queued abort any STA ongoing connection to avoid
5588 * vdev destroy timeout.
5589 */
5590 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags))
5591 hdd_abort_ongoing_sta_connection(hdd_ctx);
Dustin Browndb2a8be2017-12-20 11:49:56 -08005592
Himanshu Agarwalb229a142017-12-21 10:16:45 +05305593 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005594 break;
5595
Rajeev Kumar3b906202018-02-01 10:55:14 -08005596 case QDF_MONITOR_MODE:
5597 wlan_hdd_scan_abort(adapter);
Visweswara Tanukub5a61242019-03-26 12:24:13 +05305598 hdd_deregister_hl_netdev_fc_timer(adapter);
Rajeev Kumar3b906202018-02-01 10:55:14 -08005599 hdd_deregister_tx_flow_control(adapter);
Jinwei Chenbdd977f2019-06-14 15:09:30 +08005600 sme_delete_mon_session(mac_handle, adapter->vdev_id);
Rajeev Kumar3b906202018-02-01 10:55:14 -08005601 hdd_vdev_destroy(adapter);
5602 break;
5603
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005604 case QDF_SAP_MODE:
Will Huang7049bae2018-08-13 17:25:02 +08005605 if (test_bit(ACS_PENDING, &adapter->event_flags)) {
5606 cds_flush_delayed_work(&adapter->acs_pending_work);
5607 clear_bit(ACS_PENDING, &adapter->event_flags);
5608 }
Dustin Brownd747ecd2018-10-26 16:32:22 -07005609
wadesongf9b15ed2017-12-14 14:12:32 +08005610 wlan_hdd_scan_abort(adapter);
gaurank kathpaliab7a9f702019-02-15 18:09:58 +05305611 /* Diassociate with all the peers before stop ap post */
5612 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags))
5613 wlan_hdd_del_station(adapter);
Arunk Khandavalli96c122f2017-10-17 11:49:36 +05305614 sap_config = &adapter->session.ap.sap_config;
Dustin Brownd747ecd2018-10-26 16:32:22 -07005615 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
5616
Dustin Brown07901ec2018-09-07 11:02:41 -07005617 ucfg_ipa_flush(hdd_ctx->pdev);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005618
Dustin Brownb4260d52019-01-24 11:53:08 -08005619 /* don't flush pre-cac destroy if we are destroying pre-cac */
5620 sap_ctx = WLAN_HDD_GET_SAP_CTX_PTR(adapter);
5621 if (!wlan_sap_is_pre_cac_context(sap_ctx))
Liangwei Dongad89c762018-06-01 01:56:23 -04005622 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
Dustin Brownb4260d52019-01-24 11:53:08 -08005623
Jeff Johnson46807cd2018-04-29 21:32:22 -07005624 /* fallthrough */
Dustin Browna5cf8e02017-10-19 16:04:19 -07005625
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005626 case QDF_P2P_GO_MODE:
Krunal Soni22208392017-09-29 18:10:34 -07005627 cds_flush_work(&adapter->sap_stop_bss_work);
Abhinav Kumarb638b5d2018-03-26 12:25:41 +05305628 qdf_atomic_set(&adapter->session.ap.acs_in_progress, 0);
Dustin Browna5cf8e02017-10-19 16:04:19 -07005629 wlan_hdd_undo_acs(adapter);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005630
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005631 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005632 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5633
Visweswara Tanukub5a61242019-03-26 12:24:13 +05305634 hdd_deregister_hl_netdev_fc_timer(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005635 hdd_deregister_tx_flow_control(adapter);
Kapil Guptac1224bf2017-06-22 21:22:40 +05305636 hdd_destroy_acs_timer(adapter);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005637
Pragaspathi Thilagaraje6f37e02019-01-04 12:24:33 +05305638 /**
5639 * During vdev destroy, If any STA is in connecting state the
5640 * roam command will be in active queue and thus vdev destroy is
5641 * queued in pending queue. In case STA is tries to connected to
5642 * multiple BSSID and fails to connect, due to auth/assoc
5643 * timeouts it may take more than vdev destroy time to get
5644 * completes. If vdev destroy timeout vdev is moved to logically
5645 * deleted state. Once connection is completed, vdev destroy is
5646 * activated and to release the self-peer ref count it try to
5647 * get the ref of the vdev, which fails as vdev is logically
5648 * deleted and this leads to peer ref leak. So before vdev
5649 * destroy is queued abort any STA ongoing connection to avoid
5650 * vdev destroy timeout.
5651 */
5652 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags))
5653 hdd_abort_ongoing_sta_connection(hdd_ctx);
5654
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005655 mutex_lock(&hdd_ctx->sap_lock);
5656 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005657 status = wlansap_stop_bss(
5658 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005659
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305660 if (QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnsonca2530c2017-09-30 18:25:40 -07005661 struct hdd_hostapd_state *hostapd_state =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005662 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05305663 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05305664 qdf_stop_bss_event);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005665 status = qdf_wait_for_event_completion(
Nachiket Kukade0396b732017-11-14 16:35:16 +05305666 &hostapd_state->qdf_stop_bss_event,
Abhishek Singhd1f21c72019-01-21 15:16:34 +05305667 SME_CMD_STOP_BSS_TIMEOUT);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005668 if (QDF_IS_STATUS_ERROR(status))
Jeff Johnson5880d792016-08-15 13:32:30 -07005669 hdd_err("failure waiting for wlansap_stop_bss %d",
Dustin Brownd747ecd2018-10-26 16:32:22 -07005670 status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005671 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07005672 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005673 }
Dustin Brownd747ecd2018-10-26 16:32:22 -07005674
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005675 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Dustin Brown1dbefe62018-09-11 16:32:03 -07005676 policy_mgr_decr_session_set_pcl(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08005677 adapter->device_mode,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08005678 adapter->vdev_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -07005679 hdd_green_ap_start_state_mc(hdd_ctx,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +05305680 adapter->device_mode,
5681 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005682
Jeff Johnsonc565af12019-03-10 21:09:47 -07005683 qdf_copy_macaddr(&update_ie.bssid,
Jeff Johnson1e851a12017-10-28 14:36:12 -07005684 &adapter->mac_addr);
Jeff Johnsonc565af12019-03-10 21:09:47 -07005685 update_ie.smeSessionId = adapter->vdev_id;
5686 update_ie.ieBufferlength = 0;
5687 update_ie.pAdditionIEBuffer = NULL;
5688 update_ie.append = false;
5689 update_ie.notify = false;
Dustin Brownd747ecd2018-10-26 16:32:22 -07005690
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005691 /* Probe bcn reset */
Jeff Johnsonc565af12019-03-10 21:09:47 -07005692 status = sme_update_add_ie(mac_handle, &update_ie,
Dustin Brownd747ecd2018-10-26 16:32:22 -07005693 eUPDATE_IE_PROBE_BCN);
5694 if (status == QDF_STATUS_E_FAILURE)
5695 hdd_err("Could not pass PROBE_RSP_BCN to PE");
5696
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005697 /* Assoc resp reset */
Jeff Johnsonc565af12019-03-10 21:09:47 -07005698 status = sme_update_add_ie(mac_handle, &update_ie,
Dustin Brownd747ecd2018-10-26 16:32:22 -07005699 eUPDATE_IE_ASSOC_RESP);
5700 if (status == QDF_STATUS_E_FAILURE)
5701 hdd_err("Could not pass ASSOC_RSP to PE");
5702
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005703 /* Reset WNI_CFG_PROBE_RSP Flags */
5704 wlan_hdd_reset_prob_rspies(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005705 }
Jiachao Wub1e1ddd2018-05-21 12:04:15 +08005706 clear_bit(SOFTAP_INIT_DONE, &adapter->event_flags);
Jeff Johnsonb9424862017-10-30 08:49:35 -07005707 qdf_mem_free(adapter->session.ap.beacon);
5708 adapter->session.ap.beacon = NULL;
Jiachao Wub1e1ddd2018-05-21 12:04:15 +08005709
Ajit Pal Singh747b6802017-05-24 15:42:03 +05305710 /*
5711 * If Do_Not_Break_Stream was enabled clear avoid channel list.
5712 */
Min Liu8c5d99e2018-09-10 17:18:44 +08005713 vdev = hdd_objmgr_get_vdev(adapter);
5714 if (vdev) {
5715 if (policy_mgr_is_dnsc_set(vdev))
5716 wlan_hdd_send_avoid_freq_for_dnbs(hdd_ctx, 0);
Rajeev Kumar Sirasanagandla25bdfad2019-02-15 19:15:49 +05305717 hdd_objmgr_put_vdev(vdev);
Min Liu8c5d99e2018-09-10 17:18:44 +08005718 }
Ajit Pal Singh747b6802017-05-24 15:42:03 +05305719
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305720#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005721 cancel_work_sync(&adapter->ipv4_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305722#ifdef WLAN_NS_OFFLOAD
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005723 cancel_work_sync(&adapter->ipv6_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305724#endif
5725#endif
Dustin Browndb2a8be2017-12-20 11:49:56 -08005726
5727 hdd_vdev_destroy(adapter);
5728
Krunal Sonib51eec72017-11-20 21:53:01 -08005729 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005730 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005731 case QDF_OCB_MODE:
Dustin Brownd747ecd2018-10-26 16:32:22 -07005732 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08005733 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Dustin Brownd747ecd2018-10-26 16:32:22 -07005734 cds_get_context(QDF_MODULE_ID_TXRX),
Jeff Johnson0a082d92019-03-04 12:25:49 -08005735 sta_ctx->conn_info.sta_id[0]);
Visweswara Tanukub5a61242019-03-26 12:24:13 +05305736 hdd_deregister_hl_netdev_fc_timer(adapter);
Zhang Qian79d0d132018-02-05 13:40:16 +08005737 hdd_deregister_tx_flow_control(adapter);
5738 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005739 break;
5740 default:
5741 break;
5742 }
5743
Dustin Brown04348372017-12-14 16:13:39 -08005744 if (adapter->scan_info.default_scan_ies) {
5745 qdf_mem_free(adapter->scan_info.default_scan_ies);
5746 adapter->scan_info.default_scan_ies = NULL;
5747 }
5748
Dustin Browne74003f2018-03-14 12:51:58 -07005749 hdd_exit();
Dustin Brownd747ecd2018-10-26 16:32:22 -07005750
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305751 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005752}
5753
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305754/**
5755 * hdd_deinit_all_adapters - deinit all adapters
5756 * @hdd_ctx: HDD context
5757 * @rtnl_held: True if RTNL lock held
5758 *
5759 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005760void hdd_deinit_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305761{
Jeff Johnson9d295242017-08-29 14:39:48 -07005762 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305763
Dustin Brown491d54b2018-03-14 12:39:11 -07005764 hdd_enter();
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305765
Dustin Brown920397d2017-12-13 16:27:50 -08005766 hdd_for_each_adapter(hdd_ctx, adapter)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305767 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305768
Dustin Browne74003f2018-03-14 12:51:58 -07005769 hdd_exit();
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305770}
5771
Dustin Browndb2a8be2017-12-20 11:49:56 -08005772QDF_STATUS hdd_stop_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005773{
Jeff Johnson9d295242017-08-29 14:39:48 -07005774 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005775
Dustin Brown491d54b2018-03-14 12:39:11 -07005776 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005777
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305778 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
5779
Dustin Brown920397d2017-12-13 16:27:50 -08005780 hdd_for_each_adapter(hdd_ctx, adapter)
Dustin Browndb2a8be2017-12-20 11:49:56 -08005781 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005782
Dustin Browne74003f2018-03-14 12:51:58 -07005783 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005784
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305785 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005786}
5787
Paul Zhang84fa9382017-11-10 21:18:21 +08005788static void hdd_reset_scan_operation(struct hdd_context *hdd_ctx,
5789 struct hdd_adapter *adapter)
5790{
5791 switch (adapter->device_mode) {
5792 case QDF_STA_MODE:
5793 case QDF_P2P_CLIENT_MODE:
5794 case QDF_IBSS_MODE:
5795 case QDF_P2P_DEVICE_MODE:
5796 case QDF_NDI_MODE:
5797 wlan_hdd_scan_abort(adapter);
5798 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Min Liu8c5d99e2018-09-10 17:18:44 +08005799 if (adapter->device_mode == QDF_STA_MODE) {
5800 struct wlan_objmgr_vdev *vdev;
5801
5802 vdev = hdd_objmgr_get_vdev(adapter);
5803 if (vdev) {
5804 wlan_cfg80211_sched_scan_stop(vdev);
Rajeev Kumar Sirasanagandla25bdfad2019-02-15 19:15:49 +05305805 hdd_objmgr_put_vdev(vdev);
Min Liu8c5d99e2018-09-10 17:18:44 +08005806 }
5807 }
Paul Zhang84fa9382017-11-10 21:18:21 +08005808 break;
5809 case QDF_P2P_GO_MODE:
5810 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5811 break;
5812 case QDF_SAP_MODE:
Abhinav Kumarb638b5d2018-03-26 12:25:41 +05305813 qdf_atomic_set(&adapter->session.ap.acs_in_progress, 0);
Paul Zhang84fa9382017-11-10 21:18:21 +08005814 wlan_hdd_undo_acs(adapter);
5815 break;
5816 default:
5817 break;
5818 }
5819}
5820
Ke Huangc067b8d2018-05-21 15:50:13 +08005821#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
5822/**
5823 * hdd_adapter_abort_tx_flow() - Abort the tx flow control
5824 * @pAdapter: pointer to hdd_adapter_t
5825 *
5826 * Resume tx and stop the tx flow control timer if the tx is paused
5827 * and the flow control timer is running. This function is called by
5828 * SSR to avoid the inconsistency of tx status before and after SSR.
5829 *
5830 * Return: void
5831 */
5832static void hdd_adapter_abort_tx_flow(struct hdd_adapter *adapter)
5833{
5834 if (adapter->hdd_stats.tx_rx_stats.is_txflow_paused &&
5835 QDF_TIMER_STATE_RUNNING ==
5836 qdf_mc_timer_get_current_state(
5837 &adapter->tx_flow_control_timer)) {
5838 hdd_tx_resume_timer_expired_handler(adapter);
5839 qdf_mc_timer_stop(&adapter->tx_flow_control_timer);
5840 }
5841}
5842#endif
5843
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005844QDF_STATUS hdd_reset_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005845{
Jeff Johnson9d295242017-08-29 14:39:48 -07005846 struct hdd_adapter *adapter;
Jeff Johnsond377dce2017-10-04 10:32:42 -07005847 struct hdd_station_ctx *sta_ctx;
Jeff Johnson2d044612019-02-26 20:08:43 -08005848 struct qdf_mac_addr peer_macaddr;
Yue Ma42654682018-01-11 16:55:24 -08005849 int sta_id;
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05305850 bool value;
Min Liu8c5d99e2018-09-10 17:18:44 +08005851 struct wlan_objmgr_vdev *vdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005852
Dustin Brown491d54b2018-03-14 12:39:11 -07005853 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005854
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305855 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
5856
Dustin Brown920397d2017-12-13 16:27:50 -08005857 hdd_for_each_adapter(hdd_ctx, adapter) {
Dustin Brown5e89ef82018-03-14 11:50:23 -07005858 hdd_info("[SSR] reset adapter with device mode %s(%d)",
Dustin Brown458027c2018-10-19 12:26:27 -07005859 qdf_opmode_str(adapter->device_mode),
Dustin Brown5e89ef82018-03-14 11:50:23 -07005860 adapter->device_mode);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305861
Ke Huangc067b8d2018-05-21 15:50:13 +08005862#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
5863 hdd_adapter_abort_tx_flow(adapter);
5864#endif
5865
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305866 if ((adapter->device_mode == QDF_STA_MODE) ||
Paul Zhang679025e2018-03-08 22:39:44 +08005867 (adapter->device_mode == QDF_P2P_CLIENT_MODE)) {
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305868 /* Stop tdls timers */
Min Liu8c5d99e2018-09-10 17:18:44 +08005869 vdev = hdd_objmgr_get_vdev(adapter);
5870 if (vdev) {
5871 hdd_notify_tdls_reset_adapter(vdev);
Rajeev Kumar Sirasanagandla25bdfad2019-02-15 19:15:49 +05305872 hdd_objmgr_put_vdev(vdev);
Min Liu8c5d99e2018-09-10 17:18:44 +08005873 }
Paul Zhang679025e2018-03-08 22:39:44 +08005874 adapter->session.station.hdd_reassoc_scenario = false;
5875 }
Dustin Brown05d81302018-09-11 16:49:22 -07005876 ucfg_mlme_get_sap_internal_restart(hdd_ctx->psoc, &value);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05305877 if (value &&
Arun Khandavallicc544b32017-01-30 19:52:16 +05305878 adapter->device_mode == QDF_SAP_MODE) {
5879 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305880 WLAN_STOP_ALL_NETIF_QUEUE,
Arun Khandavallicc544b32017-01-30 19:52:16 +05305881 WLAN_CONTROL_PATH);
Ashish Kumar Dhanotiyadc3900f2019-01-11 20:42:04 +05305882 if (test_bit(ACS_PENDING, &adapter->event_flags)) {
5883 cds_flush_delayed_work(
5884 &adapter->acs_pending_work);
5885 clear_bit(ACS_PENDING, &adapter->event_flags);
5886 }
5887
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005888 if (test_bit(SOFTAP_BSS_STARTED,
Ashish Kumar Dhanotiyadc3900f2019-01-11 20:42:04 +05305889 &adapter->event_flags)) {
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005890 hdd_sap_indicate_disconnect_for_sta(adapter);
Ashish Kumar Dhanotiyadc3900f2019-01-11 20:42:04 +05305891 clear_bit(SOFTAP_BSS_STARTED,
5892 &adapter->event_flags);
5893 }
5894
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005895 } else {
Arun Khandavallicc544b32017-01-30 19:52:16 +05305896 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305897 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005898 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005899 }
Nijun Gong104ccc72018-08-07 10:43:56 +08005900 /*
5901 * Clear fc flag if it was set before SSR to avoid TX queues
5902 * permanently stopped after SSR.
5903 * Here WLAN_START_ALL_NETIF_QUEUE will actually not start any
5904 * queue since it's blocked by reason WLAN_CONTROL_PATH.
5905 */
5906 if (adapter->pause_map & (1 << WLAN_DATA_FLOW_CONTROL))
5907 wlan_hdd_netif_queue_control(adapter,
5908 WLAN_START_ALL_NETIF_QUEUE,
5909 WLAN_DATA_FLOW_CONTROL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005910
Paul Zhang84fa9382017-11-10 21:18:21 +08005911 hdd_reset_scan_operation(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005912
5913 hdd_deinit_tx_rx(adapter);
Dustin Brown1dbefe62018-09-11 16:32:03 -07005914 policy_mgr_decr_session_set_pcl(hdd_ctx->psoc,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08005915 adapter->device_mode, adapter->vdev_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -07005916 hdd_green_ap_start_state_mc(hdd_ctx, adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +05305917 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005918 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
5919 hdd_wmm_adapter_close(adapter);
5920 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
5921 }
5922
Vignesh Viswanathan2eb18742017-09-08 11:18:59 +05305923 if (adapter->device_mode == QDF_STA_MODE)
5924 hdd_clear_fils_connection_info(adapter);
5925
Wu Gao3545e642017-07-14 19:24:41 +08005926 if (adapter->device_mode == QDF_SAP_MODE) {
Jingxiang Geec113592018-08-09 15:40:39 +08005927 wlansap_cleanup_cac_timer(
5928 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Wu Gao3545e642017-07-14 19:24:41 +08005929 /*
5930 * If adapter is SAP, set session ID to invalid
5931 * since SAP session will be cleanup during SSR.
5932 */
Wu Gao36717432016-11-21 15:09:48 +08005933 wlansap_set_invalid_session(
5934 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Wu Gao3545e642017-07-14 19:24:41 +08005935 }
5936
Abhishek Singh8f4aa182019-03-06 10:29:24 +05305937 /* Release vdev ref count to avoid vdev object leak */
5938 if (adapter->device_mode == QDF_P2P_GO_MODE ||
5939 adapter->device_mode == QDF_SAP_MODE)
5940 wlansap_release_vdev_ref(
5941 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
5942
Yue Ma42654682018-01-11 16:55:24 -08005943 /* Delete connection peers if any to avoid peer object leaks */
Yue Mad5b4b9f2017-05-26 16:23:40 -07005944 if (adapter->device_mode == QDF_STA_MODE ||
5945 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
Jeff Johnsond377dce2017-10-04 10:32:42 -07005946 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Jeff Johnson2d044612019-02-26 20:08:43 -08005947 qdf_copy_macaddr(&peer_macaddr,
Jeff Johnsone04b6992019-02-27 14:06:55 -08005948 &sta_ctx->conn_info.bssid);
Yue Mad5b4b9f2017-05-26 16:23:40 -07005949
Yue Ma42654682018-01-11 16:55:24 -08005950 } else if (adapter->device_mode == QDF_P2P_GO_MODE) {
Wu Gao6b81fc52018-05-24 19:27:27 +08005951 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Yue Ma42654682018-01-11 16:55:24 -08005952 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT; sta_id++) {
5953 if (adapter->sta_info[sta_id].in_use) {
5954 hdd_debug("[SSR] deregister STA with ID %d",
5955 sta_id);
5956 hdd_softap_deregister_sta(adapter,
5957 sta_id);
5958 adapter->sta_info[sta_id].in_use = 0;
5959 }
5960 }
Yue Mad5b4b9f2017-05-26 16:23:40 -07005961 }
5962
Alok Kumarb64650c2018-03-23 17:05:11 +05305963 hdd_nud_ignore_tracking(adapter, true);
Alok Kumar016a1ac2018-09-16 09:55:50 +05305964 hdd_nud_reset_tracking(adapter);
5965 hdd_nud_flush_work(adapter);
Ashish Kumar Dhanotiyadc3900f2019-01-11 20:42:04 +05305966
5967 if (adapter->device_mode != QDF_SAP_MODE &&
5968 adapter->device_mode != QDF_P2P_GO_MODE &&
5969 adapter->device_mode != QDF_FTM_MODE)
5970 hdd_set_disconnect_status(adapter, false);
5971
hangtian9c47aaf2018-11-26 17:59:39 +08005972 hdd_stop_tsf_sync(adapter);
Alok Kumarb64650c2018-03-23 17:05:11 +05305973
Tiger Yu94a5a5c2018-03-09 21:22:26 +08005974 hdd_softap_deinit_tx_rx(adapter);
Visweswara Tanukub5a61242019-03-26 12:24:13 +05305975 hdd_deregister_hl_netdev_fc_timer(adapter);
Tiger Yu8c387702018-07-06 16:56:42 +08005976 hdd_deregister_tx_flow_control(adapter);
Tiger Yu94a5a5c2018-03-09 21:22:26 +08005977
Yue Maf9782842017-05-08 12:49:49 -07005978 /* Destroy vdev which will be recreated during reinit. */
5979 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005980 }
5981
Dustin Browne74003f2018-03-14 12:51:58 -07005982 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005983
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305984 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005985}
5986
Dustin Brown4c663222018-10-23 14:19:36 -07005987bool hdd_is_any_interface_open(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305988{
Dustin Brown920397d2017-12-13 16:27:50 -08005989 struct hdd_adapter *adapter;
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305990
Dustin Brown4c663222018-10-23 14:19:36 -07005991 if (hdd_get_conparam() == QDF_GLOBAL_FTM_MODE) {
Arun Khandavalliba479c42017-07-26 21:29:40 +05305992 hdd_info("FTM mode, don't close the module");
Dustin Brown4c663222018-10-23 14:19:36 -07005993 return true;
Arun Khandavalliba479c42017-07-26 21:29:40 +05305994 }
5995
Dustin Brown920397d2017-12-13 16:27:50 -08005996 hdd_for_each_adapter(hdd_ctx, adapter) {
5997 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags) ||
Dustin Brown4c663222018-10-23 14:19:36 -07005998 test_bit(SME_SESSION_OPENED, &adapter->event_flags))
5999 return true;
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05306000 }
6001
Dustin Brown4c663222018-10-23 14:19:36 -07006002 return false;
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05306003}
6004
yeshwanth sriram guntukaea63f632017-08-30 19:31:56 +05306005bool hdd_is_interface_up(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05306006{
6007 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
6008 return true;
6009 else
6010 return false;
6011}
6012
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05306013#if defined CFG80211_CONNECT_BSS || \
6014 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306015#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05306016 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306017/**
6018 * hdd_convert_timeout_reason() - Convert to kernel specific enum
6019 * @timeout_reason: reason for connect timeout
6020 *
6021 * This function is used to convert host timeout
6022 * reason enum to kernel specific enum.
6023 *
6024 * Return: nl timeout enum
6025 */
6026static enum nl80211_timeout_reason hdd_convert_timeout_reason(
6027 tSirResultCodes timeout_reason)
6028{
6029 switch (timeout_reason) {
6030 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
6031 return NL80211_TIMEOUT_SCAN;
6032 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
6033 return NL80211_TIMEOUT_AUTH;
6034 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
6035 return NL80211_TIMEOUT_ASSOC;
6036 default:
6037 return NL80211_TIMEOUT_UNSPECIFIED;
6038 }
6039}
6040
6041/**
6042 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
6043 * @dev: network device
6044 * @bssid: bssid to which we want to associate
6045 * @timeout_reason: reason for connect timeout
6046 *
6047 * This API is used to send connection timeout reason to supplicant
6048 *
6049 * Return: void
6050 */
6051static void hdd_cfg80211_connect_timeout(struct net_device *dev,
6052 const u8 *bssid,
6053 tSirResultCodes timeout_reason)
6054{
6055 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006056
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306057 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
6058
6059 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
6060 nl_timeout_reason);
6061}
6062
6063/**
6064 * __hdd_connect_bss() - API to send connection status to supplicant
6065 * @dev: network device
6066 * @bssid: bssid to which we want to associate
6067 * @req_ie: Request Information Element
6068 * @req_ie_len: len of the req IE
6069 * @resp_ie: Response IE
6070 * @resp_ie_len: len of ht response IE
6071 * @status: status
6072 * @gfp: Kernel Flag
6073 * @timeout_reason: reason for connect timeout
6074 *
6075 * Return: void
6076 */
6077static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
6078 struct cfg80211_bss *bss, const u8 *req_ie,
6079 size_t req_ie_len, const u8 *resp_ie,
6080 size_t resp_ie_len, int status, gfp_t gfp,
6081 tSirResultCodes timeout_reason)
6082{
6083 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006084
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306085 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
6086
6087 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
6088 resp_ie, resp_ie_len, status, gfp,
6089 nl_timeout_reason);
6090}
6091#else
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05306092#if defined CFG80211_CONNECT_TIMEOUT || \
6093 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306094static void hdd_cfg80211_connect_timeout(struct net_device *dev,
6095 const u8 *bssid,
6096 tSirResultCodes timeout_reason)
6097{
6098 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
6099}
6100#endif
6101
6102static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
6103 struct cfg80211_bss *bss, const u8 *req_ie,
6104 size_t req_ie_len, const u8 *resp_ie,
6105 size_t resp_ie_len, int status, gfp_t gfp,
6106 tSirResultCodes timeout_reason)
6107{
6108 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
6109 resp_ie, resp_ie_len, status, gfp);
6110}
6111#endif
6112
Abhishek Singha84d3952016-09-13 13:45:05 +05306113/**
6114 * hdd_connect_bss() - API to send connection status to supplicant
6115 * @dev: network device
6116 * @bssid: bssid to which we want to associate
6117 * @req_ie: Request Information Element
6118 * @req_ie_len: len of the req IE
6119 * @resp_ie: Response IE
6120 * @resp_ie_len: len of ht response IE
6121 * @status: status
6122 * @gfp: Kernel Flag
6123 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306124 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05306125 *
6126 * The API is a wrapper to send connection status to supplicant
6127 *
6128 * Return: Void
6129 */
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05306130#if defined CFG80211_CONNECT_TIMEOUT || \
6131 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
Abhishek Singha84d3952016-09-13 13:45:05 +05306132static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
6133 struct cfg80211_bss *bss, const u8 *req_ie,
6134 size_t req_ie_len, const u8 *resp_ie,
6135 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306136 bool connect_timeout,
6137 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05306138{
6139 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306140 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05306141 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306142 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
6143 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05306144}
6145#else
6146static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
6147 struct cfg80211_bss *bss, const u8 *req_ie,
6148 size_t req_ie_len, const u8 *resp_ie,
6149 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306150 bool connect_timeout,
6151 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05306152{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306153 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
6154 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05306155}
6156#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05306157
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05306158#if defined(WLAN_FEATURE_FILS_SK)
Pragaspathi Thilagaraj9e619082019-01-24 15:15:45 +05306159#if (defined(CFG80211_CONNECT_DONE) || \
6160 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))) && \
6161 (LINUX_VERSION_CODE < KERNEL_VERSION(4, 19, 0))
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05306162#if defined(CFG80211_FILS_SK_OFFLOAD_SUPPORT) || \
6163 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306164/**
6165 * hdd_populate_fils_params() - Populate FILS keys to connect response
6166 * @fils_params: connect response to supplicant
6167 * @fils_kek: FILS kek
6168 * @fils_kek_len: FILS kek length
6169 * @pmk: FILS PMK
6170 * @pmk_len: FILS PMK length
6171 * @pmkid: PMKID
6172 * @fils_seq_num: FILS Seq number
6173 *
6174 * Return: None
6175 */
6176static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
6177 *fils_params, const uint8_t *fils_kek,
6178 size_t fils_kek_len, const uint8_t *pmk,
6179 size_t pmk_len, const uint8_t *pmkid,
6180 uint16_t fils_seq_num)
6181{
6182 /* Increament seq number to be used for next FILS */
6183 fils_params->fils_erp_next_seq_num = fils_seq_num + 1;
6184 fils_params->update_erp_next_seq_num = true;
6185 fils_params->fils_kek = fils_kek;
6186 fils_params->fils_kek_len = fils_kek_len;
6187 fils_params->pmk = pmk;
6188 fils_params->pmk_len = pmk_len;
6189 fils_params->pmkid = pmkid;
Pragaspathi Thilagaraj9e619082019-01-24 15:15:45 +05306190 hdd_debug("FILS erp_next_seq_num:%d",
6191 fils_params->fils_erp_next_seq_num);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306192}
6193#else
6194static inline void hdd_populate_fils_params(struct cfg80211_connect_resp_params
6195 *fils_params, const uint8_t
6196 *fils_kek, size_t fils_kek_len,
6197 const uint8_t *pmk, size_t pmk_len,
6198 const uint8_t *pmkid,
6199 uint16_t fils_seq_num)
6200{ }
6201#endif
6202
Pragaspathi Thilagaraj9e619082019-01-24 15:15:45 +05306203#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0))
6204/**
6205 * hdd_populate_fils_params() - Populate FILS keys to connect response
6206 * @fils_params: connect response to supplicant
6207 * @fils_kek: FILS kek
6208 * @fils_kek_len: FILS kek length
6209 * @pmk: FILS PMK
6210 * @pmk_len: FILS PMK length
6211 * @pmkid: PMKID
6212 * @fils_seq_num: FILS Seq number
6213 *
6214 * Return: None
6215 */
6216static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
6217 *fils_params, const uint8_t *fils_kek,
6218 size_t fils_kek_len, const uint8_t *pmk,
6219 size_t pmk_len, const uint8_t *pmkid,
6220 uint16_t fils_seq_num)
6221{
6222 /* Increament seq number to be used for next FILS */
6223 fils_params->fils.erp_next_seq_num = fils_seq_num + 1;
6224 fils_params->fils.update_erp_next_seq_num = true;
6225 fils_params->fils.kek = fils_kek;
6226 fils_params->fils.kek_len = fils_kek_len;
6227 fils_params->fils.pmk = pmk;
6228 fils_params->fils.pmk_len = pmk_len;
6229 fils_params->fils.pmkid = pmkid;
6230 hdd_debug("FILS erp_next_seq_num:%d",
6231 fils_params->fils.erp_next_seq_num);
6232}
6233#endif /* CFG80211_CONNECT_DONE */
6234
6235#if defined(CFG80211_CONNECT_DONE) || \
6236 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
6237
Jeff Johnson172237b2017-11-07 15:32:59 -08006238void hdd_update_hlp_info(struct net_device *dev,
6239 struct csr_roam_info *roam_info)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05306240{
6241 struct sk_buff *skb;
6242 uint16_t skb_len;
6243 struct llc_snap_hdr_t *llc_hdr;
6244 QDF_STATUS status;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306245 uint8_t *hlp_data;
6246 uint16_t hlp_data_len;
6247 struct fils_join_rsp_params *roam_fils_params
6248 = roam_info->fils_join_rsp;
Jeff Johnsona1382382019-03-31 11:08:27 -07006249 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05306250
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306251 if (!roam_fils_params) {
6252 hdd_err("FILS Roam Param NULL");
6253 return;
6254 }
6255
Srinivas Girigowda3cc8e912017-11-28 18:11:57 -08006256 if (!roam_fils_params->hlp_data_len) {
Jianmin Zhucc6b3d02019-03-07 14:19:34 +08006257 hdd_debug("FILS HLP Data NULL, len %d",
6258 roam_fils_params->hlp_data_len);
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306259 return;
6260 }
6261
6262 hlp_data = roam_fils_params->hlp_data;
6263 hlp_data_len = roam_fils_params->hlp_data_len;
6264
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05306265 /* Calculate skb length */
6266 skb_len = (2 * ETH_ALEN) + hlp_data_len;
6267 skb = qdf_nbuf_alloc(NULL, skb_len, 0, 4, false);
Jeff Johnsond36fa332019-03-18 13:42:25 -07006268 if (!skb) {
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05306269 hdd_err("HLP packet nbuf alloc fails");
6270 return;
6271 }
6272
6273 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->dst_mac.bytes,
6274 QDF_MAC_ADDR_SIZE);
6275 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->src_mac.bytes,
6276 QDF_MAC_ADDR_SIZE);
6277
6278 llc_hdr = (struct llc_snap_hdr_t *) hlp_data;
6279 if (IS_SNAP(llc_hdr)) {
6280 hlp_data += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
6281 hlp_data_len += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
6282 }
6283
6284 qdf_mem_copy(skb_put(skb, hlp_data_len), hlp_data, hlp_data_len);
6285
6286 /*
6287 * This HLP packet is formed from HLP info encapsulated
6288 * in assoc response frame which is AEAD encrypted.
6289 * Hence, this checksum validation can be set unnecessary.
6290 * i.e. network layer need not worry about checksum.
6291 */
6292 skb->ip_summed = CHECKSUM_UNNECESSARY;
6293
Jeff Johnsona1382382019-03-31 11:08:27 -07006294 status = hdd_rx_packet_cbk(adapter, skb);
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05306295 if (QDF_IS_STATUS_ERROR(status)) {
6296 hdd_err("Sending HLP packet fails");
6297 return;
6298 }
6299 hdd_debug("send HLP packet to netif successfully");
6300}
6301
6302/**
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306303 * hdd_connect_done() - Wrapper API to call cfg80211_connect_done
6304 * @dev: network device
6305 * @bssid: bssid to which we want to associate
6306 * @bss: cfg80211 bss info
6307 * @roam_info: information about connected bss
6308 * @req_ie: Request Information Element
6309 * @req_ie_len: len of the req IE
6310 * @resp_ie: Response IE
6311 * @resp_ie_len: len of ht response IE
6312 * @status: status
6313 * @gfp: allocation flags
6314 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
6315 * @timeout_reason: reason for connect timeout
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306316 *
6317 * This API is used as wrapper to send FILS key/sequence number
6318 * params etc. to supplicant in case of FILS connection
6319 *
6320 * Return: None
6321 */
6322static void hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08006323 struct cfg80211_bss *bss,
6324 struct csr_roam_info *roam_info,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306325 const u8 *req_ie, size_t req_ie_len,
6326 const u8 *resp_ie, size_t resp_ie_len, u16 status,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07006327 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306328 tSirResultCodes timeout_reason)
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306329{
6330 struct cfg80211_connect_resp_params fils_params;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306331 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
6332 struct fils_join_rsp_params *roam_fils_params =
6333 roam_info->fils_join_rsp;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07006334
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306335 qdf_mem_zero(&fils_params, sizeof(fils_params));
6336
6337 if (!roam_fils_params) {
6338 fils_params.status = WLAN_STATUS_UNSPECIFIED_FAILURE;
6339 } else {
6340 fils_params.status = status;
6341 fils_params.bssid = bssid;
Srinivas Girigowdae975f532018-01-05 14:03:05 -08006342 fils_params.timeout_reason =
6343 hdd_convert_timeout_reason(timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306344 fils_params.req_ie = req_ie;
6345 fils_params.req_ie_len = req_ie_len;
6346 fils_params.resp_ie = resp_ie;
6347 fils_params.resp_ie_len = resp_ie_len;
6348 fils_params.bss = bss;
6349 hdd_populate_fils_params(&fils_params, roam_fils_params->kek,
6350 roam_fils_params->kek_len,
6351 roam_fils_params->fils_pmk,
6352 roam_fils_params->fils_pmk_len,
6353 roam_fils_params->fils_pmkid,
6354 roam_info->fils_seq_num);
Sridhar Selvaraje5260442017-08-19 10:12:03 +05306355 hdd_save_gtk_params(adapter, roam_info, false);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306356 }
Pragaspathi Thilagaraj9e619082019-01-24 15:15:45 +05306357 hdd_debug("FILS indicate connect status %d", fils_params.status);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306358
6359 cfg80211_connect_done(dev, &fils_params, gfp);
6360
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05306361 if (roam_fils_params && roam_fils_params->hlp_data_len)
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306362 hdd_update_hlp_info(dev, roam_info);
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05306363
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306364 /* Clear all the FILS key info */
6365 if (roam_fils_params && roam_fils_params->fils_pmk)
6366 qdf_mem_free(roam_fils_params->fils_pmk);
6367 if (roam_fils_params)
6368 qdf_mem_free(roam_fils_params);
6369 roam_info->fils_join_rsp = NULL;
6370}
Pragaspathi Thilagaraj9e619082019-01-24 15:15:45 +05306371#else /* CFG80211_CONNECT_DONE */
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07006372static inline void
6373hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08006374 struct cfg80211_bss *bss, struct csr_roam_info *roam_info,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07006375 const u8 *req_ie, size_t req_ie_len,
6376 const u8 *resp_ie, size_t resp_ie_len, u16 status,
6377 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306378 tSirResultCodes timeout_reason)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05306379{ }
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306380#endif
Pragaspathi Thilagaraj9e619082019-01-24 15:15:45 +05306381#endif /* WLAN_FEATURE_FILS_SK */
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306382
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05306383#if defined(WLAN_FEATURE_FILS_SK) && \
6384 (defined(CFG80211_CONNECT_DONE) || \
6385 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0)))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306386/**
6387 * hdd_fils_update_connect_results() - API to send fils connection status to
6388 * supplicant.
6389 * @dev: network device
6390 * @bssid: bssid to which we want to associate
6391 * @bss: cfg80211 bss info
6392 * @roam_info: information about connected bss
6393 * @req_ie: Request Information Element
6394 * @req_ie_len: len of the req IE
6395 * @resp_ie: Response IE
6396 * @resp_ie_len: len of ht response IE
6397 * @status: status
6398 * @gfp: allocation flags
6399 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
6400 * @timeout_reason: reason for connect timeout
6401 *
6402 * The API is a wrapper to send connection status to supplicant
6403 *
6404 * Return: 0 if success else failure
6405 */
6406static int hdd_fils_update_connect_results(struct net_device *dev,
6407 const u8 *bssid,
6408 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08006409 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306410 size_t req_ie_len, const u8 *resp_ie,
6411 size_t resp_ie_len, u16 status, gfp_t gfp,
6412 bool connect_timeout,
6413 tSirResultCodes timeout_reason)
6414{
Dustin Brown491d54b2018-03-14 12:39:11 -07006415 hdd_enter();
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306416 if (!roam_info || !roam_info->is_fils_connection)
6417 return -EINVAL;
6418
6419 hdd_connect_done(dev, bssid, bss, roam_info, req_ie, req_ie_len,
6420 resp_ie, resp_ie_len, status, gfp, connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306421 timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306422 return 0;
6423}
6424#else
6425static inline int hdd_fils_update_connect_results(struct net_device *dev,
6426 const u8 *bssid,
6427 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08006428 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306429 size_t req_ie_len, const u8 *resp_ie,
6430 size_t resp_ie_len, u16 status, gfp_t gfp,
6431 bool connect_timeout,
6432 tSirResultCodes timeout_reason)
6433{
6434 return -EINVAL;
6435}
6436#endif
6437
Anurag Chouhanc4092922016-09-08 15:56:11 +05306438/**
6439 * hdd_connect_result() - API to send connection status to supplicant
6440 * @dev: network device
6441 * @bssid: bssid to which we want to associate
6442 * @roam_info: information about connected bss
6443 * @req_ie: Request Information Element
6444 * @req_ie_len: len of the req IE
6445 * @resp_ie: Response IE
6446 * @resp_ie_len: len of ht response IE
6447 * @status: status
6448 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05306449 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306450 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05306451 *
6452 * The API is a wrapper to send connection status to supplicant
6453 * and allow runtime suspend
6454 *
6455 * Return: Void
6456 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05306457void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08006458 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05306459 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05306460 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306461 bool connect_timeout,
6462 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05306463{
Jeff Johnsona1382382019-03-31 11:08:27 -07006464 struct hdd_adapter *adapter = netdev_priv(dev);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306465 struct cfg80211_bss *bss = NULL;
Jeff Johnsona1382382019-03-31 11:08:27 -07006466 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306467
6468 if (WLAN_STATUS_SUCCESS == status) {
6469 struct ieee80211_channel *chan;
6470 int freq;
Pragaspathi Thilagaraj96742ae2019-05-29 00:49:33 +05306471 int chan_no = roam_info->bss_desc->channelId;
Anurag Chouhanc4092922016-09-08 15:56:11 +05306472
6473 if (chan_no <= 14)
6474 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07006475 HDD_NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306476 else
6477 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07006478 HDD_NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306479
Jeff Johnsona1382382019-03-31 11:08:27 -07006480 chan = ieee80211_get_channel(adapter->wdev.wiphy, freq);
6481 bss = wlan_cfg80211_get_bss(adapter->wdev.wiphy, chan, bssid,
Anurag Chouhanc4092922016-09-08 15:56:11 +05306482 roam_info->u.pConnectedProfile->SSID.ssId,
6483 roam_info->u.pConnectedProfile->SSID.length);
6484 }
Komal Seelama89be8d2016-09-29 11:09:26 +05306485
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306486 if (hdd_fils_update_connect_results(dev, bssid, bss,
6487 roam_info, req_ie, req_ie_len, resp_ie,
6488 resp_ie_len, status, gfp, connect_timeout,
6489 timeout_reason) != 0) {
6490 hdd_connect_bss(dev, bssid, bss, req_ie,
6491 req_ie_len, resp_ie, resp_ie_len,
6492 status, gfp, connect_timeout, timeout_reason);
6493 }
Komal Seelama89be8d2016-09-29 11:09:26 +05306494
Jingxiang Geb49aa302018-01-17 20:54:15 +08006495 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07006496 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306497}
6498#else
6499void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08006500 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05306501 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05306502 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306503 bool connect_timeout,
6504 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05306505{
Jeff Johnsona1382382019-03-31 11:08:27 -07006506 struct hdd_adapter *adapter = netdev_priv(dev);
6507 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05306508
Anurag Chouhanc4092922016-09-08 15:56:11 +05306509 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
6510 resp_ie, resp_ie_len, status, gfp);
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08006511
Jingxiang Geb49aa302018-01-17 20:54:15 +08006512 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07006513 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306514}
6515#endif
6516
Nirav Shah73713f72018-05-17 14:50:41 +05306517#ifdef FEATURE_MONITOR_MODE_SUPPORT
Jeff Johnsond9952752018-04-18 12:15:35 -07006518int wlan_hdd_set_mon_chan(struct hdd_adapter *adapter, uint32_t chan,
6519 uint32_t bandwidth)
6520{
6521 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6522 struct hdd_station_ctx *sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
6523 struct hdd_mon_set_ch_info *ch_info = &sta_ctx->ch_info;
6524 QDF_STATUS status;
Jeff Johnson43837af2018-10-17 12:44:05 -07006525 mac_handle_t mac_handle = hdd_ctx->mac_handle;
Jeff Johnsond9952752018-04-18 12:15:35 -07006526 struct qdf_mac_addr bssid;
6527 struct csr_roam_profile roam_profile;
6528 struct ch_params ch_params;
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006529 eConnectionState connstate;
Jeff Johnsond9952752018-04-18 12:15:35 -07006530
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006531 if (hdd_get_conparam() != QDF_GLOBAL_MONITOR_MODE &&
6532 adapter->device_mode != QDF_STA_MODE) {
6533 hdd_err("Not supported, device is not in monitor mode or sta mission mode");
Jeff Johnsond9952752018-04-18 12:15:35 -07006534 return -EINVAL;
6535 }
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006536 if (adapter->device_mode == QDF_STA_MODE &&
Pragaspathi Thilagaraja8893752019-02-06 19:58:59 +05306537 ucfg_mlme_is_change_channel_bandwidth_enabled(hdd_ctx->psoc)) {
Jeff Johnsone7951512019-02-27 10:02:51 -08006538 connstate = sta_ctx->conn_info.conn_state;
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006539 if (eConnectionState_Associated == connstate ||
6540 eConnectionState_Connecting == connstate) {
6541 return -EINVAL;
6542 }
6543 }
Jeff Johnsond9952752018-04-18 12:15:35 -07006544
Visweswara Tanuku006313a2018-04-12 12:26:34 +05306545 /* Validate Channel */
6546 if (!WLAN_REG_IS_24GHZ_CH(chan) && !WLAN_REG_IS_5GHZ_CH(chan)) {
6547 hdd_err("Channel %d Not supported", chan);
6548 return -EINVAL;
6549 }
6550
6551 if (WLAN_REG_IS_24GHZ_CH(chan)) {
6552 if (bandwidth == CH_WIDTH_80MHZ) {
6553 hdd_err("BW80 not possible in 2.4GHz band");
6554 return -EINVAL;
6555 }
6556 if ((bandwidth != CH_WIDTH_20MHZ) && (chan == 14) &&
6557 (bandwidth != CH_WIDTH_MAX)) {
6558 hdd_err("Only BW20 possible on channel 14");
6559 return -EINVAL;
6560 }
6561 }
6562
6563 if (WLAN_REG_IS_5GHZ_CH(chan)) {
6564 if ((bandwidth != CH_WIDTH_20MHZ) && (chan == 165) &&
6565 (bandwidth != CH_WIDTH_MAX)) {
6566 hdd_err("Only BW20 possible on channel 165");
6567 return -EINVAL;
6568 }
6569 }
6570
Jeff Johnsond9952752018-04-18 12:15:35 -07006571 hdd_debug("Set monitor mode Channel %d", chan);
6572 qdf_mem_zero(&roam_profile, sizeof(roam_profile));
6573 roam_profile.ChannelInfo.ChannelList = &ch_info->channel;
6574 roam_profile.ChannelInfo.numOfChannels = 1;
6575 roam_profile.phyMode = ch_info->phy_mode;
6576 roam_profile.ch_params.ch_width = bandwidth;
6577 hdd_select_cbmode(adapter, chan, &roam_profile.ch_params);
Pragaspathi Thilagaraja8893752019-02-06 19:58:59 +05306578 if (ucfg_mlme_is_change_channel_bandwidth_enabled(hdd_ctx->psoc) &&
Jeff Johnson43837af2018-10-17 12:44:05 -07006579 (!sme_find_session_by_bssid(mac_handle, adapter->mac_addr.bytes))) {
6580 status = sme_create_mon_session(mac_handle,
Rajeev Kumar Sirasanagandlae3b59912018-08-24 15:53:31 +05306581 adapter->mac_addr.bytes,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08006582 adapter->vdev_id);
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006583 if (status != QDF_STATUS_SUCCESS) {
6584 hdd_err("Status: %d Failed to create session.",
6585 status);
6586 return qdf_status_to_os_return(status);
6587 }
6588 }
Jeff Johnsond9952752018-04-18 12:15:35 -07006589 qdf_mem_copy(bssid.bytes, adapter->mac_addr.bytes,
6590 QDF_MAC_ADDR_SIZE);
6591
6592 ch_params.ch_width = bandwidth;
Dustin Brown07901ec2018-09-07 11:02:41 -07006593 wlan_reg_set_channel_params(hdd_ctx->pdev, chan, 0, &ch_params);
Jeff Johnsond9952752018-04-18 12:15:35 -07006594 if (ch_params.ch_width == CH_WIDTH_INVALID) {
6595 hdd_err("Invalid capture channel or bandwidth for a country");
6596 return -EINVAL;
6597 }
6598 if (wlan_hdd_change_hw_mode_for_given_chnl(adapter, chan,
6599 POLICY_MGR_UPDATE_REASON_SET_OPER_CHAN)) {
6600 hdd_err("Failed to change hw mode");
6601 return -EINVAL;
6602 }
6603
Jeff Johnson16528362018-06-14 12:34:16 -07006604 status = sme_roam_channel_change_req(hdd_ctx->mac_handle,
6605 bssid, &ch_params,
Jeff Johnsond9952752018-04-18 12:15:35 -07006606 &roam_profile);
6607 if (status) {
6608 hdd_err("Status: %d Failed to set sme_roam Channel for monitor mode",
6609 status);
6610 }
6611
6612 adapter->mon_chan = chan;
6613 adapter->mon_bandwidth = bandwidth;
6614 return qdf_status_to_os_return(status);
6615}
Nirav Shah73713f72018-05-17 14:50:41 +05306616#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05306617
Wu Gaodf929f12018-05-25 18:12:25 +08006618#ifdef MSM_PLATFORM
6619/**
6620 * hdd_stop_p2p_go() - call cfg80211 API to stop P2P GO
6621 * @adapter: pointer to adapter
6622 *
6623 * This function calls cfg80211 API to stop P2P GO
6624 *
6625 * Return: None
6626 */
6627static void hdd_stop_p2p_go(struct hdd_adapter *adapter)
6628{
6629 hdd_debug("[SSR] send stop ap to supplicant");
6630 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
6631}
6632
6633static inline void hdd_delete_sta(struct hdd_adapter *adapter)
6634{
6635}
6636#else
6637static inline void hdd_stop_p2p_go(struct hdd_adapter *adapter)
6638{
6639}
6640
6641/**
6642 * hdd_delete_sta() - call cfg80211 API to delete STA
6643 * @adapter: pointer to adapter
6644 *
6645 * This function calls cfg80211 API to delete STA
6646 *
6647 * Return: None
6648 */
6649static void hdd_delete_sta(struct hdd_adapter *adapter)
6650{
6651 struct qdf_mac_addr bcast_mac = QDF_MAC_ADDR_BCAST_INIT;
6652
6653 hdd_debug("[SSR] send restart supplicant");
6654 /* event supplicant to restart */
6655 cfg80211_del_sta(adapter->dev,
6656 (const u8 *)&bcast_mac.bytes[0],
6657 GFP_KERNEL);
6658}
6659#endif
6660
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006661QDF_STATUS hdd_start_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006662{
Jeff Johnson9d295242017-08-29 14:39:48 -07006663 struct hdd_adapter *adapter;
Jeff Johnsone7951512019-02-27 10:02:51 -08006664 eConnectionState conn_state;
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05306665 bool value;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006666
Dustin Brown491d54b2018-03-14 12:39:11 -07006667 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006668
Dustin Brown920397d2017-12-13 16:27:50 -08006669 hdd_for_each_adapter(hdd_ctx, adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05306670 if (!hdd_is_interface_up(adapter))
Dustin Brown920397d2017-12-13 16:27:50 -08006671 continue;
Arun Khandavallifae92942016-08-01 13:31:08 +05306672
Yue Ma42654682018-01-11 16:55:24 -08006673 hdd_debug("[SSR] start adapter with device mode %s(%d)",
Dustin Brown458027c2018-10-19 12:26:27 -07006674 qdf_opmode_str(adapter->device_mode),
Yue Ma42654682018-01-11 16:55:24 -08006675 adapter->device_mode);
6676
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006677 hdd_wmm_init(adapter);
6678
6679 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006680 case QDF_STA_MODE:
6681 case QDF_P2P_CLIENT_MODE:
6682 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006683
Jeff Johnsone7951512019-02-27 10:02:51 -08006684 conn_state = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
6685 ->conn_info.conn_state;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006686
Krunal Sonib51eec72017-11-20 21:53:01 -08006687 hdd_start_station_adapter(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006688 /* Open the gates for HDD to receive Wext commands */
Jeff Johnsonc72c5732017-10-28 12:49:37 -07006689 adapter->is_link_up_service_needed = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006690
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006691 /* Indicate disconnect event to supplicant
6692 * if associated previously
6693 */
Jeff Johnsone7951512019-02-27 10:02:51 -08006694 if (eConnectionState_Associated == conn_state ||
6695 eConnectionState_IbssConnected == conn_state ||
6696 eConnectionState_NotConnected == conn_state ||
6697 eConnectionState_IbssDisconnected == conn_state ||
6698 eConnectionState_Disconnecting == conn_state) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006699 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006700
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006701 memset(&wrqu, '\0', sizeof(wrqu));
6702 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
6703 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
6704 wireless_send_event(adapter->dev, SIOCGIWAP,
6705 &wrqu, NULL);
Jeff Johnsonb9424862017-10-30 08:49:35 -07006706 adapter->session.station.
Jeff Johnson690fe952017-10-25 11:48:39 -07006707 hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006708
6709 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05306710 wlan_hdd_cfg80211_indicate_disconnect(
6711 adapter->dev, false,
6712 WLAN_REASON_UNSPECIFIED);
Jeff Johnsone7951512019-02-27 10:02:51 -08006713 } else if (eConnectionState_Connecting == conn_state) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006714 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006715 * Indicate connect failure to supplicant if we
6716 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006717 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05306718 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306719 NULL, 0, NULL, 0,
6720 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006721 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006722 }
6723
6724 hdd_register_tx_flow_control(adapter,
6725 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08006726 hdd_tx_resume_cb,
6727 hdd_tx_flow_control_is_pause);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006728
Visweswara Tanukub5a61242019-03-26 12:24:13 +05306729 hdd_register_hl_netdev_fc_timer(
6730 adapter,
6731 hdd_tx_resume_timer_expired_handler);
6732
Arunk Khandavalli40943af2017-05-15 19:25:34 +05306733 hdd_lpass_notify_start(hdd_ctx, adapter);
Alok Kumarb64650c2018-03-23 17:05:11 +05306734 hdd_nud_ignore_tracking(adapter, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006735 break;
6736
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006737 case QDF_SAP_MODE:
Dustin Brown05d81302018-09-11 16:49:22 -07006738 ucfg_mlme_get_sap_internal_restart(hdd_ctx->psoc,
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05306739 &value);
6740 if (value)
Krunal Sonib51eec72017-11-20 21:53:01 -08006741 hdd_start_ap_adapter(adapter);
Arun Khandavallicc544b32017-01-30 19:52:16 +05306742
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006743 break;
6744
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006745 case QDF_P2P_GO_MODE:
Wu Gaodf929f12018-05-25 18:12:25 +08006746 hdd_delete_sta(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006747 break;
Arunk Khandavalli062fb032017-10-04 12:18:15 +05306748 case QDF_MONITOR_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08006749 hdd_start_station_adapter(adapter);
Arunk Khandavalli062fb032017-10-04 12:18:15 +05306750 hdd_set_mon_rx_cb(adapter->dev);
6751 wlan_hdd_set_mon_chan(adapter, adapter->mon_chan,
6752 adapter->mon_bandwidth);
6753 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006754 default:
6755 break;
6756 }
Krunal Soni9c2ee032017-07-18 13:49:54 -07006757 /*
6758 * Action frame registered in one adapter which will
6759 * applicable to all interfaces
6760 */
6761 wlan_hdd_cfg80211_register_frames(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006762 }
6763
Wu Gaodf929f12018-05-25 18:12:25 +08006764 hdd_for_each_adapter(hdd_ctx, adapter) {
6765 if (!hdd_is_interface_up(adapter))
6766 continue;
6767
6768 if (adapter->device_mode == QDF_P2P_GO_MODE)
6769 hdd_stop_p2p_go(adapter);
6770 }
6771
Dustin Browne74003f2018-03-14 12:51:58 -07006772 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006773
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306774 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006775}
6776
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006777QDF_STATUS hdd_get_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006778 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006779{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306780 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006781 qdf_list_node_t *node;
6782
6783 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006784
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006785 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006786 status = qdf_list_peek_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006787 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006788
6789 if (QDF_IS_STATUS_ERROR(status))
6790 return status;
6791
6792 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6793
6794 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006795}
6796
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006797QDF_STATUS hdd_get_next_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006798 struct hdd_adapter *current_adapter,
6799 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006800{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306801 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006802 qdf_list_node_t *node;
6803
6804 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006805
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006806 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Jeff Johnson19fc8e42017-10-30 19:53:49 -07006807 status = qdf_list_peek_next(&hdd_ctx->hdd_adapters,
Dustin Brown920397d2017-12-13 16:27:50 -08006808 &current_adapter->node,
6809 &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006810 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006811
6812 if (QDF_IS_STATUS_ERROR(status))
6813 return status;
6814
6815 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6816
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006817 return status;
6818}
6819
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006820QDF_STATUS hdd_remove_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006821 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006822{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306823 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006824
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006825 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006826 status = qdf_list_remove_node(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006827 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006828
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006829 return status;
6830}
6831
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006832QDF_STATUS hdd_remove_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006833 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006834{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306835 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006836 qdf_list_node_t *node;
6837
6838 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006839
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006840 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006841 status = qdf_list_remove_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006842 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006843
6844 if (QDF_IS_STATUS_ERROR(status))
6845 return status;
6846
6847 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6848
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006849 return status;
6850}
6851
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006852QDF_STATUS hdd_add_adapter_back(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006853 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006854{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306855 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006856
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006857 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006858 status = qdf_list_insert_back(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006859 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006860
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006861 return status;
6862}
6863
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006864QDF_STATUS hdd_add_adapter_front(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006865 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006866{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306867 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006868
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006869 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006870 status = qdf_list_insert_front(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006871 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006872
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006873 return status;
6874}
6875
Liangwei Dong3abfe8f2018-09-20 02:25:44 -04006876struct hdd_adapter *hdd_get_adapter_by_rand_macaddr(
6877 struct hdd_context *hdd_ctx, tSirMacAddr mac_addr)
6878{
6879 struct hdd_adapter *adapter;
6880
6881 hdd_for_each_adapter(hdd_ctx, adapter) {
6882 if ((adapter->device_mode == QDF_STA_MODE ||
6883 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6884 adapter->device_mode == QDF_P2P_DEVICE_MODE) &&
6885 ucfg_p2p_check_random_mac(hdd_ctx->psoc,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08006886 adapter->vdev_id, mac_addr))
Liangwei Dong3abfe8f2018-09-20 02:25:44 -04006887 return adapter;
6888 }
6889
6890 return NULL;
6891}
6892
Jeff Johnson9d295242017-08-29 14:39:48 -07006893struct hdd_adapter *hdd_get_adapter_by_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07006894 tSirMacAddr mac_addr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006895{
Jeff Johnson9d295242017-08-29 14:39:48 -07006896 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006897
Dustin Brown920397d2017-12-13 16:27:50 -08006898 hdd_for_each_adapter(hdd_ctx, adapter) {
6899 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07006900 mac_addr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006901 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006902 }
6903
6904 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006905}
6906
Jeff Johnson9d295242017-08-29 14:39:48 -07006907struct hdd_adapter *hdd_get_adapter_by_vdev(struct hdd_context *hdd_ctx,
Jeff Johnson55d2ab42019-03-06 11:43:49 -08006908 uint32_t vdev_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006909{
Jeff Johnson9d295242017-08-29 14:39:48 -07006910 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006911
Dustin Brown920397d2017-12-13 16:27:50 -08006912 hdd_for_each_adapter(hdd_ctx, adapter) {
Jeff Johnson5a6fc962019-02-04 14:20:25 -08006913 if (adapter->vdev_id == vdev_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006914 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006915 }
6916
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006917 return NULL;
6918}
6919
Jeff Johnson9d295242017-08-29 14:39:48 -07006920struct hdd_adapter *hdd_get_adapter_by_iface_name(struct hdd_context *hdd_ctx,
Naveen Rawat4edb6822017-04-12 10:09:17 -07006921 const char *iface_name)
6922{
Jeff Johnson9d295242017-08-29 14:39:48 -07006923 struct hdd_adapter *adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07006924
Dustin Brown920397d2017-12-13 16:27:50 -08006925 hdd_for_each_adapter(hdd_ctx, adapter) {
6926 if (!qdf_str_cmp(adapter->dev->name, iface_name))
Naveen Rawat4edb6822017-04-12 10:09:17 -07006927 return adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07006928 }
Dustin Brown920397d2017-12-13 16:27:50 -08006929
Naveen Rawat4edb6822017-04-12 10:09:17 -07006930 return NULL;
6931}
6932
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006933/**
6934 * hdd_get_adapter() - to get adapter matching the mode
6935 * @hdd_ctx: hdd context
6936 * @mode: adapter mode
6937 *
6938 * This routine will return the pointer to adapter matching
6939 * with the passed mode.
6940 *
6941 * Return: pointer to adapter or null
6942 */
Jeff Johnson9d295242017-08-29 14:39:48 -07006943struct hdd_adapter *hdd_get_adapter(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08006944 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006945{
Jeff Johnson9d295242017-08-29 14:39:48 -07006946 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006947
Dustin Brown920397d2017-12-13 16:27:50 -08006948 hdd_for_each_adapter(hdd_ctx, adapter) {
6949 if (adapter->device_mode == mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006950 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006951 }
6952
6953 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006954}
6955
Jeff Johnson55d2ab42019-03-06 11:43:49 -08006956enum QDF_OPMODE hdd_get_device_mode(uint32_t vdev_id)
Yeshwanth Sriram Guntuka469f9572018-02-12 13:28:22 +05306957{
6958 struct hdd_context *hdd_ctx;
6959 struct hdd_adapter *adapter;
6960
6961 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
6962 if (!hdd_ctx) {
6963 hdd_err("Invalid HDD context");
6964 return QDF_MAX_NO_OF_MODE;
6965 }
6966
Jeff Johnson55d2ab42019-03-06 11:43:49 -08006967 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
Yeshwanth Sriram Guntuka469f9572018-02-12 13:28:22 +05306968 if (!adapter) {
6969 hdd_err("Invalid HDD adapter");
6970 return QDF_MAX_NO_OF_MODE;
6971 }
6972
6973 return adapter->device_mode;
6974}
6975
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006976/**
6977 * hdd_get_operating_channel() - return operating channel of the device mode
6978 * @hdd_ctx: Pointer to the HDD context.
6979 * @mode: Device mode for which operating channel is required.
Jeff Johnson77f89bb2018-05-06 16:21:36 -07006980 * Supported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006981 * QDF_STA_MODE,
6982 * QDF_P2P_CLIENT_MODE,
6983 * QDF_SAP_MODE,
6984 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006985 *
6986 * This API returns the operating channel of the requested device mode
6987 *
6988 * Return: channel number. "0" id the requested device is not found OR it is
6989 * not connected.
6990 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006991uint8_t hdd_get_operating_channel(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08006992 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006993{
Jeff Johnson9d295242017-08-29 14:39:48 -07006994 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006995 uint8_t operatingChannel = 0;
6996
Dustin Brown920397d2017-12-13 16:27:50 -08006997 hdd_for_each_adapter(hdd_ctx, adapter) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006998 if (mode == adapter->device_mode) {
6999 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007000 case QDF_STA_MODE:
7001 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007002 if (hdd_conn_is_connected
7003 (WLAN_HDD_GET_STATION_CTX_PTR
7004 (adapter))) {
7005 operatingChannel =
7006 (WLAN_HDD_GET_STATION_CTX_PTR
7007 (adapter))->conn_info.
Jeff Johnson8626e932019-02-27 18:35:22 -08007008 channel;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007009 }
7010 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007011 case QDF_SAP_MODE:
7012 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007013 /* softap connection info */
7014 if (test_bit
7015 (SOFTAP_BSS_STARTED,
7016 &adapter->event_flags))
7017 operatingChannel =
7018 (WLAN_HDD_GET_AP_CTX_PTR
Jeff Johnson01206862017-10-27 20:55:59 -07007019 (adapter))->operating_channel;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007020 break;
7021 default:
7022 break;
7023 }
7024
Srinivas Girigowdab841da72017-03-25 18:04:39 -07007025 /* Found the device of interest. break the loop */
7026 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007027 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007028 }
Dustin Brown920397d2017-12-13 16:27:50 -08007029
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007030 return operatingChannel;
7031}
7032
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007033static inline QDF_STATUS hdd_unregister_wext_all_adapters(struct hdd_context *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007034 hdd_ctx)
7035{
Jeff Johnson9d295242017-08-29 14:39:48 -07007036 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007037
Dustin Brown491d54b2018-03-14 12:39:11 -07007038 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007039
Dustin Brown920397d2017-12-13 16:27:50 -08007040 hdd_for_each_adapter(hdd_ctx, adapter) {
7041 if (adapter->device_mode == QDF_STA_MODE ||
7042 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
7043 adapter->device_mode == QDF_IBSS_MODE ||
7044 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
7045 adapter->device_mode == QDF_SAP_MODE ||
7046 adapter->device_mode == QDF_P2P_GO_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007047 hdd_unregister_wext(adapter->dev);
7048 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007049 }
7050
Dustin Browne74003f2018-03-14 12:51:58 -07007051 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007052
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307053 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007054}
7055
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007056QDF_STATUS hdd_abort_mac_scan_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007057{
Jeff Johnson9d295242017-08-29 14:39:48 -07007058 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007059
Dustin Brown491d54b2018-03-14 12:39:11 -07007060 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007061
Dustin Brown920397d2017-12-13 16:27:50 -08007062 hdd_for_each_adapter(hdd_ctx, adapter) {
7063 if (adapter->device_mode == QDF_STA_MODE ||
7064 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
7065 adapter->device_mode == QDF_IBSS_MODE ||
7066 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
7067 adapter->device_mode == QDF_SAP_MODE ||
7068 adapter->device_mode == QDF_P2P_GO_MODE) {
Dustin Brown07901ec2018-09-07 11:02:41 -07007069 wlan_abort_scan(hdd_ctx->pdev, INVAL_PDEV_ID,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08007070 adapter->vdev_id, INVALID_SCAN_ID,
Vignesh Viswanathan19611c82018-01-16 16:20:40 +05307071 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007072 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007073 }
7074
Dustin Browne74003f2018-03-14 12:51:58 -07007075 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007076
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307077 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007078}
7079
Dustin Brownf27bce82016-11-03 12:52:27 -07007080/**
7081 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
7082 * adapters
7083 * @hdd_ctx: The HDD context containing the adapters to operate on
7084 *
7085 * return: QDF_STATUS_SUCCESS
7086 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007087static QDF_STATUS hdd_abort_sched_scan_all_adapters(struct hdd_context *hdd_ctx)
Dustin Brownf27bce82016-11-03 12:52:27 -07007088{
Jeff Johnson9d295242017-08-29 14:39:48 -07007089 struct hdd_adapter *adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07007090 int err;
7091
Dustin Brown491d54b2018-03-14 12:39:11 -07007092 hdd_enter();
Dustin Brownf27bce82016-11-03 12:52:27 -07007093
Dustin Brown920397d2017-12-13 16:27:50 -08007094 hdd_for_each_adapter(hdd_ctx, adapter) {
7095 if (adapter->device_mode == QDF_STA_MODE ||
7096 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
7097 adapter->device_mode == QDF_IBSS_MODE ||
7098 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
7099 adapter->device_mode == QDF_SAP_MODE ||
7100 adapter->device_mode == QDF_P2P_GO_MODE) {
Dustin Brownf27bce82016-11-03 12:52:27 -07007101 err = wlan_hdd_sched_scan_stop(adapter->dev);
7102 if (err)
7103 hdd_err("Unable to stop scheduled scan");
7104 }
Dustin Brownf27bce82016-11-03 12:52:27 -07007105 }
7106
Dustin Browne74003f2018-03-14 12:51:58 -07007107 hdd_exit();
Dustin Brownf27bce82016-11-03 12:52:27 -07007108
7109 return QDF_STATUS_SUCCESS;
7110}
7111
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007112#ifdef WLAN_NS_OFFLOAD
7113/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007114 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007115 * @hdd_ctx: Pointer to hdd context
7116 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007117 * Unregister for IPv6 address change notifications.
7118 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007119 * Return: None
7120 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007121static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007122{
7123 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007124}
7125
7126/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007127 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007128 * @hdd_ctx: Pointer to hdd context
7129 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007130 * Register for IPv6 address change notifications.
7131 *
7132 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007133 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007134static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007135{
7136 int ret;
7137
7138 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
7139 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007140 if (ret) {
7141 hdd_err("Failed to register IPv6 notifier: %d", ret);
7142 goto out;
7143 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007144
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007145 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007146out:
7147 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007148}
7149#else
7150/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007151 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007152 * @hdd_ctx: Pointer to hdd context
7153 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007154 * Unregister for IPv6 address change notifications.
7155 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007156 * Return: None
7157 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007158static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007159{
7160}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007161
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007162/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007163 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007164 * @hdd_ctx: Pointer to hdd context
7165 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007166 * Register for IPv6 address change notifications.
7167 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007168 * Return: None
7169 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007170static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007171{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007172 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007173}
7174#endif
7175
Alok Kumarb64650c2018-03-23 17:05:11 +05307176void hdd_set_disconnect_status(struct hdd_adapter *adapter, bool status)
7177{
7178 qdf_mutex_acquire(&adapter->disconnection_status_lock);
7179 adapter->disconnection_in_progress = status;
7180 qdf_mutex_release(&adapter->disconnection_status_lock);
7181 hdd_debug("setting disconnection status: %d", status);
7182}
7183
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007184/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007185 * hdd_register_notifiers - Register netdev notifiers.
7186 * @hdd_ctx: HDD context
7187 *
7188 * Register netdev notifiers like IPv4 and IPv6.
7189 *
7190 * Return: 0 on success and errno on failure
7191 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007192static int hdd_register_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007193{
7194 int ret;
7195
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007196 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
7197 if (ret)
Arun Khandavalli08479ba2017-08-07 19:56:23 +05307198 goto out;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007199
7200 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
7201 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
7202 if (ret) {
7203 hdd_err("Failed to register IPv4 notifier: %d", ret);
7204 goto unregister_ip6_notifier;
7205 }
7206
Alok Kumarb64650c2018-03-23 17:05:11 +05307207 ret = hdd_nud_register_netevent_notifier(hdd_ctx);
7208 if (ret) {
7209 hdd_err("Failed to register netevent notifier: %d",
7210 ret);
7211 goto unregister_inetaddr_notifier;
7212 }
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007213 return 0;
7214
Alok Kumarb64650c2018-03-23 17:05:11 +05307215unregister_inetaddr_notifier:
7216 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007217unregister_ip6_notifier:
7218 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007219out:
7220 return ret;
7221
7222}
7223
7224/**
7225 * hdd_unregister_notifiers - Unregister netdev notifiers.
7226 * @hdd_ctx: HDD context
7227 *
7228 * Unregister netdev notifiers like IPv4 and IPv6.
7229 *
7230 * Return: None.
7231 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007232void hdd_unregister_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007233{
Alok Kumarb64650c2018-03-23 17:05:11 +05307234 hdd_nud_unregister_netevent_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007235 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
7236
7237 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007238}
7239
7240/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007241 * hdd_exit_netlink_services - Exit netlink services
7242 * @hdd_ctx: HDD context
7243 *
7244 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
7245 * nl service.
7246 *
7247 * Return: None.
7248 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007249static void hdd_exit_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007250{
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05307251 spectral_scan_deactivate_service();
7252 cnss_diag_deactivate_service();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007253 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007254 ptt_sock_deactivate_svc();
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05307255 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007256
7257 nl_srv_exit();
7258}
7259
7260/**
7261 * hdd_init_netlink_services- Init netlink services
7262 * @hdd_ctx: HDD context
7263 *
7264 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
7265 * nl service.
7266 *
7267 * Return: 0 on success and errno on failure.
7268 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007269static int hdd_init_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007270{
7271 int ret;
7272
Ryan Hsuceddceb2016-04-28 10:20:14 -07007273 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007274 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007275 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007276 goto out;
7277 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07007278 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007279
Naveen Rawat910726a2017-03-06 11:42:51 -08007280 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007281 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007282 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007283 goto err_nl_srv;
7284 }
7285
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05307286 ptt_sock_activate_svc();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007287
7288 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07007289 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007290 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007291
7292 ret = cnss_diag_activate_service();
7293 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007294 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007295 goto err_close_cesium;
7296 }
7297
Dustin Brown01520852019-02-27 12:14:16 -08007298 spectral_scan_activate_service(hdd_ctx);
Sandeep Puligilla019a1bd2018-02-04 22:57:44 -08007299
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007300 return 0;
7301
7302err_close_cesium:
7303 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007304 ptt_sock_deactivate_svc();
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05307305 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007306err_nl_srv:
7307 nl_srv_exit();
7308out:
7309 return ret;
7310}
7311
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007312/**
7313 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
7314 * @hdd_ctx: HDD context.
7315 *
7316 * Destroy RX wakelock.
7317 *
7318 * Return: None.
7319 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007320static void hdd_rx_wake_lock_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007321{
7322 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
7323}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007324
7325/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007326 * hdd_rx_wake_lock_create() - Create RX wakelock
7327 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007328 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007329 * Create RX wakelock.
7330 *
7331 * Return: None.
7332 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007333static void hdd_rx_wake_lock_create(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007334{
7335 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
7336}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007337
7338/**
Houston Hoffman160db392016-10-10 17:37:51 -07007339 * hdd_context_deinit() - Deinitialize HDD context
7340 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007341 *
Houston Hoffman160db392016-10-10 17:37:51 -07007342 * Deinitialize HDD context along with all the feature specific contexts but
7343 * do not free hdd context itself. Caller of this API is supposed to free
7344 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007345 *
Houston Hoffman160db392016-10-10 17:37:51 -07007346 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007347 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007348static int hdd_context_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007349{
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05307350 qdf_wake_lock_destroy(&hdd_ctx->monitor_mode_wakelock);
7351
Houston Hoffman160db392016-10-10 17:37:51 -07007352 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007353
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007354 hdd_sap_context_destroy(hdd_ctx);
7355
7356 hdd_rx_wake_lock_destroy(hdd_ctx);
7357
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007358 hdd_scan_context_destroy(hdd_ctx);
7359
Jeff Johnson19fc8e42017-10-30 19:53:49 -07007360 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007361
Houston Hoffman160db392016-10-10 17:37:51 -07007362 return 0;
7363}
7364
Dustin Brown623e7e32018-09-05 14:27:50 -07007365void hdd_context_destroy(struct hdd_context *hdd_ctx)
Houston Hoffman160db392016-10-10 17:37:51 -07007366{
Rajeev Kumar493a31b2017-09-29 14:01:24 -07007367 cds_set_context(QDF_MODULE_ID_HDD, NULL);
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05307368
Dustin Brown623e7e32018-09-05 14:27:50 -07007369 hdd_exit_netlink_services(hdd_ctx);
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05307370 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
7371
Houston Hoffman160db392016-10-10 17:37:51 -07007372 hdd_context_deinit(hdd_ctx);
7373
Dustin Browndb2df2e2018-10-31 15:29:24 -07007374 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
7375
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307376 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007377 hdd_ctx->config = NULL;
Dustin Brown84f46ea2018-02-15 11:57:36 -08007378 cfg_release();
7379
Min Liu47104042019-04-09 17:49:21 +08007380 qdf_delayed_work_destroy(&hdd_ctx->psoc_idle_timeout_work);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007381 wiphy_free(hdd_ctx->wiphy);
7382}
7383
7384/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05307385 * wlan_destroy_bug_report_lock() - Destroy bug report lock
7386 *
7387 * This function is used to destroy bug report lock
7388 *
7389 * Return: None
7390 */
7391static void wlan_destroy_bug_report_lock(void)
7392{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07007393 struct cds_context *p_cds_context;
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05307394
7395 p_cds_context = cds_get_global_context();
7396 if (!p_cds_context) {
7397 hdd_err("cds context is NULL");
7398 return;
7399 }
7400
7401 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
7402}
7403
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +05307404#ifdef DISABLE_CHANNEL_LIST
7405static void wlan_hdd_cache_chann_mutex_destroy(struct hdd_context *hdd_ctx)
7406{
7407 qdf_mutex_destroy(&hdd_ctx->cache_channel_lock);
7408}
7409#else
7410static void wlan_hdd_cache_chann_mutex_destroy(struct hdd_context *hdd_ctx)
7411{
7412}
7413#endif
7414
Dustin Brown92bd8382018-10-31 15:49:46 -07007415void hdd_wlan_exit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007416{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007417 struct wiphy *wiphy = hdd_ctx->wiphy;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007418
Dustin Brown491d54b2018-03-14 12:39:11 -07007419 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007420
Arun Kumar Khandavallideda5a82019-03-11 15:32:19 +05307421 hdd_debugfs_mws_coex_info_deinit(hdd_ctx);
Dustin Brown4c663222018-10-23 14:19:36 -07007422 hdd_psoc_idle_timer_stop(hdd_ctx);
Dustin Brown6470aba2018-09-05 09:49:58 -07007423
Arun Khandavallifae92942016-08-01 13:31:08 +05307424 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007425
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007426#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05307427 if (QDF_TIMER_STATE_RUNNING ==
7428 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
7429 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007430 }
7431
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307432 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05307433 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07007434 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007435 }
Liangwei Dongaef84342016-10-21 05:28:00 -04007436 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
7437 qdf_mem_free(hdd_ctx->last_acs_channel_list);
7438 hdd_ctx->last_acs_channel_list = NULL;
7439 hdd_ctx->num_of_channels = 0;
7440 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007441#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007442
7443 /*
7444 * Powersave Offload Case
7445 * Disable Idle Power Save Mode
7446 */
7447 hdd_set_idle_ps_config(hdd_ctx, false);
Sandeep Puligilla8fa28fd2017-11-02 12:19:33 -07007448 /* clear the scan queue in all the scenarios */
Dustin Brown07901ec2018-09-07 11:02:41 -07007449 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->pdev, NULL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007450
Dustin Brownf688ea12019-03-19 17:02:32 -07007451 if (hdd_ctx->driver_status != DRIVER_MODULES_CLOSED) {
Arun Khandavallifae92942016-08-01 13:31:08 +05307452 hdd_unregister_wext_all_adapters(hdd_ctx);
7453 /*
7454 * Cancel any outstanding scan requests. We are about to close
7455 * all of our adapters, but an adapter structure is what SME
7456 * passes back to our callback function. Hence if there
7457 * are any outstanding scan requests then there is a
7458 * race condition between when the adapter is closed and
7459 * when the callback is invoked. We try to resolve that
7460 * race condition here by canceling any outstanding scans
7461 * before we close the adapters.
7462 * Note that the scans may be cancelled in an asynchronous
7463 * manner, so ideally there needs to be some kind of
7464 * synchronization. Rather than introduce a new
7465 * synchronization here, we will utilize the fact that we are
7466 * about to Request Full Power, and since that is synchronized,
7467 * the expectation is that by the time Request Full Power has
7468 * completed, all scans will be cancelled
7469 */
7470 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07007471 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Dustin Browndb2a8be2017-12-20 11:49:56 -08007472 hdd_stop_all_adapters(hdd_ctx);
bings29c99862017-11-01 13:54:13 +08007473 hdd_deinit_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007474 }
7475
Arun Khandavalli08479ba2017-08-07 19:56:23 +05307476 unregister_netdevice_notifier(&hdd_netdev_notifier);
7477
Rachit Kankane30807332018-06-27 18:39:36 +05307478 qdf_dp_trace_deinit();
7479
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07007480 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05307481
Visweswara Tanukuc029a202018-11-27 10:42:10 +05307482 hdd_bus_bw_compute_timer_stop(hdd_ctx);
Dustin Brown86d196b2018-08-02 11:51:49 -07007483 hdd_bus_bandwidth_deinit(hdd_ctx);
Dustin Brown021cecd2017-12-11 13:56:43 -08007484 hdd_driver_memdump_deinit();
7485
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05307486 qdf_nbuf_deinit_replenish_timer();
7487
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05307488 if (QDF_GLOBAL_MONITOR_MODE == hdd_get_conparam()) {
7489 hdd_info("Release wakelock for monitor mode!");
7490 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
7491 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
7492 }
7493
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307494 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307495 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +05307496 wlan_hdd_cache_chann_mutex_destroy(hdd_ctx);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307497
Naveen Rawate02f8f52018-04-05 11:58:04 -07007498 osif_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007499
Dustin Brownd005ad82018-01-19 10:32:13 -08007500 hdd_close_all_adapters(hdd_ctx, false);
7501
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05307502 wlansap_global_deinit();
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05307503 /*
7504 * If there is re_init failure wiphy would have already de-registered
7505 * check the wiphy status before un-registering again
7506 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05307507 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05307508 wiphy_unregister(wiphy);
7509 wlan_hdd_cfg80211_deinit(wiphy);
7510 hdd_lpass_notify_stop(hdd_ctx);
7511 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07007512
Arun Khandavallifae92942016-08-01 13:31:08 +05307513 hdd_exit_netlink_services(hdd_ctx);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05307514#ifdef FEATURE_WLAN_CH_AVOID
7515 mutex_destroy(&hdd_ctx->avoid_freq_lock);
7516#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007517}
7518
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007519#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04007520/**
7521 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007522 * @data: pointer to struct hdd_context
Liangwei Dongaef84342016-10-21 05:28:00 -04007523 *
7524 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
7525 * Then new ACS request will do a fresh scan without reusing the cached
7526 * scan information.
7527 *
7528 * Return: void
7529 */
Tang Yingying523322d2017-01-17 23:28:43 +08007530static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007531{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007532 struct hdd_context *hdd_ctx = (struct hdd_context *) data;
Jeff Johnson16528362018-06-14 12:34:16 -07007533 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007534
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007535 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007536 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04007537 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
7538 qdf_mem_free(hdd_ctx->last_acs_channel_list);
7539 hdd_ctx->last_acs_channel_list = NULL;
7540 hdd_ctx->num_of_channels = 0;
7541 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007542
Jeff Johnson16528362018-06-14 12:34:16 -07007543 mac_handle = hdd_ctx->mac_handle;
7544 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007545 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007546}
7547#endif
7548
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007549/**
7550 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
7551 * @state: state
7552 *
7553 * This function notifies FW with modem power status
7554 *
7555 * Return: 0 if successful, error number otherwise
7556 */
7557int hdd_wlan_notify_modem_power_state(int state)
7558{
7559 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307560 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007561 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -07007562 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007563
Anurag Chouhan6d760662016-02-20 16:05:43 +05307564 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007565 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05307566 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007567 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05307568
Jeff Johnson16528362018-06-14 12:34:16 -07007569 mac_handle = hdd_ctx->mac_handle;
7570 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007571 return -EINVAL;
7572
Jeff Johnson16528362018-06-14 12:34:16 -07007573 qdf_status = sme_notify_modem_power_state(mac_handle, state);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307574 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007575 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007576 state);
7577 return -EINVAL;
7578 }
7579 return 0;
7580}
7581
7582/**
7583 *
7584 * hdd_post_cds_enable_config() - HDD post cds start config helper
7585 * @adapter - Pointer to the HDD
7586 *
7587 * Return: None
7588 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007589QDF_STATUS hdd_post_cds_enable_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007590{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307591 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007592
7593 /*
7594 * Send ready indication to the HDD. This will kick off the MAC
7595 * into a 'running' state and should kick off an initial scan.
7596 */
Jeff Johnson16528362018-06-14 12:34:16 -07007597 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->mac_handle);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307598 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007599 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
7600 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307601 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007602 }
7603
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307604 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007605}
7606
Sourav Mohapatra92ea8d62018-02-05 10:03:10 +05307607struct hdd_adapter *hdd_get_first_valid_adapter(struct hdd_context *hdd_ctx)
7608{
7609 struct hdd_adapter *adapter;
7610
7611 hdd_for_each_adapter(hdd_ctx, adapter) {
7612 if (adapter && adapter->magic == WLAN_HDD_ADAPTER_MAGIC)
7613 return adapter;
7614 }
7615
7616 return NULL;
7617}
7618
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007619/* wake lock APIs for HDD */
7620void hdd_prevent_suspend(uint32_t reason)
7621{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05307622 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007623}
7624
7625void hdd_allow_suspend(uint32_t reason)
7626{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05307627 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007628}
7629
7630void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
7631{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05307632 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
7633 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007634}
7635
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007636/* Initialize channel list in sme based on the country code */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007637QDF_STATUS hdd_set_sme_chan_list(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007638{
Jeff Johnson16528362018-06-14 12:34:16 -07007639 return sme_init_chan_list(hdd_ctx->mac_handle,
Amar Singhal6f8592b2017-04-26 14:31:58 -07007640 hdd_ctx->reg.alpha2,
7641 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007642}
7643
7644/**
7645 * hdd_is_5g_supported() - check if hardware supports 5GHz
7646 * @hdd_ctx: Pointer to the hdd context
7647 *
7648 * HDD function to know if hardware supports 5GHz
7649 *
7650 * Return: true if hardware supports 5GHz
7651 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007652bool hdd_is_5g_supported(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007653{
Amar Singhal58b45ef2017-08-01 13:43:54 -07007654 if (!hdd_ctx)
zdingf54169a2016-10-12 17:08:45 +08007655 return true;
7656
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08007657 if (hdd_ctx->curr_band != BAND_2G)
zdingf54169a2016-10-12 17:08:45 +08007658 return true;
7659 else
7660 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007661}
7662
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007663static int hdd_wiphy_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007664{
7665 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07007666 int ret_val;
Wu Gaoed616a12019-01-16 15:19:21 +08007667 uint32_t channel_bonding_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007668
7669 wiphy = hdd_ctx->wiphy;
7670
7671 /*
7672 * The channel information in
7673 * wiphy needs to be initialized before wiphy registration
7674 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07007675 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
7676 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007677 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07007678 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007679 }
7680
7681#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
7682 wiphy->wowlan = &wowlan_support_reg_init;
7683#else
7684 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
7685 WIPHY_WOWLAN_MAGIC_PKT |
7686 WIPHY_WOWLAN_DISCONNECT |
7687 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
7688 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
7689 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
7690 WIPHY_WOWLAN_4WAY_HANDSHAKE |
7691 WIPHY_WOWLAN_RFKILL_RELEASE;
7692
7693 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
7694 WOW_MAX_FILTERS_PER_LIST);
7695 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
7696 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
7697#endif
Wu Gaoed616a12019-01-16 15:19:21 +08007698 ucfg_mlme_get_channel_bonding_24ghz(hdd_ctx->psoc,
7699 &channel_bonding_mode);
Liangwei Dong0da14262018-07-03 03:30:23 -04007700 if (hdd_ctx->obss_scan_offload) {
7701 hdd_debug("wmi_service_obss_scan supported");
Wu Gaoed616a12019-01-16 15:19:21 +08007702 } else if (channel_bonding_mode) {
Liangwei Dong0da14262018-07-03 03:30:23 -04007703 hdd_debug("enable wpa_supp obss_scan");
7704 wiphy->features |= NL80211_FEATURE_NEED_OBSS_SCAN;
7705 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007706
7707 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07007708 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05307709 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07007710 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05307711 return ret_val;
7712 }
Amar Singhalac26de22018-06-22 12:53:06 -07007713
Kiran Kumar Lokere0508af92018-04-23 18:38:32 -07007714 /* Check the kernel version for upstream commit aced43ce780dc5 that
7715 * has support for processing user cell_base hints when wiphy is
7716 * self managed or check the backport flag for the same.
7717 */
Amar Singhalac26de22018-06-22 12:53:06 -07007718#if defined CFG80211_USER_HINT_CELL_BASE_SELF_MANAGED || \
7719 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 18, 0))
Kiran Kumar Lokere0508af92018-04-23 18:38:32 -07007720 hdd_send_wiphy_regd_sync_event(hdd_ctx);
7721#endif
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05307722
Amar Singhal2d812012018-02-03 15:06:47 +08007723 pld_increment_driver_load_cnt(hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007724
Amar Singhale4f28ee2015-10-21 14:36:56 -07007725 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007726}
7727
Tiger Yu8b119e92019-04-09 13:55:07 +08007728#ifdef WLAN_FEATURE_DP_BUS_BANDWIDTH
Mohit Khannaca4173b2017-09-12 21:52:19 -07007729/**
7730 * hdd_display_periodic_stats() - Function to display periodic stats
7731 * @hdd_ctx - handle to hdd context
7732 * @bool data_in_interval - true, if data detected in bw time interval
7733 *
7734 * The periodicity is determined by hdd_ctx->config->periodic_stats_disp_time.
7735 * Stats show up in wlan driver logs.
7736 *
7737 * Returns: None
7738 */
Mohit Khanna70322002018-05-15 19:21:32 -07007739static void hdd_display_periodic_stats(struct hdd_context *hdd_ctx,
7740 bool data_in_interval)
Mohit Khannaca4173b2017-09-12 21:52:19 -07007741{
Mohit Khanna70322002018-05-15 19:21:32 -07007742 static uint32_t counter;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007743 static bool data_in_time_period;
7744 ol_txrx_pdev_handle pdev;
Mohit Khanna81418772018-10-30 14:14:46 -07007745 ol_txrx_soc_handle soc;
Arif Hussaincca60432018-12-03 19:45:12 -08007746 uint32_t periodic_stats_disp_time = 0;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007747
Arif Hussaincca60432018-12-03 19:45:12 -08007748 ucfg_mlme_stats_get_periodic_display_time(hdd_ctx->psoc,
7749 &periodic_stats_disp_time);
7750 if (!periodic_stats_disp_time)
Mohit Khannaca4173b2017-09-12 21:52:19 -07007751 return;
7752
Mohit Khanna81418772018-10-30 14:14:46 -07007753 soc = cds_get_context(QDF_MODULE_ID_SOC);
7754 if (!soc) {
7755 hdd_err("soc is NULL");
7756 return;
7757 }
7758
Mohit Khannaca4173b2017-09-12 21:52:19 -07007759 pdev = cds_get_context(QDF_MODULE_ID_TXRX);
7760 if (!pdev) {
7761 hdd_err("pdev is NULL");
7762 return;
7763 }
7764
7765 counter++;
7766 if (data_in_interval)
7767 data_in_time_period = data_in_interval;
7768
jitiphil869b9f72018-09-25 17:14:01 +05307769 if (counter * hdd_ctx->config->bus_bw_compute_interval >=
Arif Hussaincca60432018-12-03 19:45:12 -08007770 periodic_stats_disp_time * 1000) {
Mohit Khannaca4173b2017-09-12 21:52:19 -07007771 if (data_in_time_period) {
Mohit Khanna70322002018-05-15 19:21:32 -07007772 wlan_hdd_display_txrx_stats(hdd_ctx);
Mohit Khannac9649652018-11-28 18:10:28 -08007773 dp_txrx_ext_dump_stats(soc, CDP_DP_RX_THREAD_STATS);
Mohit Khanna81418772018-10-30 14:14:46 -07007774 cdp_display_stats(soc,
Mohit Khanna70322002018-05-15 19:21:32 -07007775 CDP_RX_RING_STATS,
7776 QDF_STATS_VERBOSITY_LEVEL_LOW);
Mohit Khanna81418772018-10-30 14:14:46 -07007777 cdp_display_stats(soc,
Mohit Khannaca4173b2017-09-12 21:52:19 -07007778 CDP_TXRX_PATH_STATS,
7779 QDF_STATS_VERBOSITY_LEVEL_LOW);
7780 wlan_hdd_display_netif_queue_history
7781 (hdd_ctx, QDF_STATS_VERBOSITY_LEVEL_LOW);
7782 qdf_dp_trace_dump_stats();
7783 }
7784 counter = 0;
7785 data_in_time_period = false;
7786 }
7787}
7788
Ravi Joshie2331e82015-07-01 18:18:54 -07007789/**
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007790 * hdd_clear_rps_cpu_mask - clear RPS CPU mask for interfaces
7791 * @hdd_ctx: pointer to struct hdd_context
7792 *
7793 * Return: none
7794 */
7795static void hdd_clear_rps_cpu_mask(struct hdd_context *hdd_ctx)
7796{
7797 struct hdd_adapter *adapter;
7798
7799 hdd_for_each_adapter(hdd_ctx, adapter)
7800 hdd_send_rps_disable_ind(adapter);
7801}
7802
7803/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07007804 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07007805 * @hdd_ctx - handle to hdd context
7806 * @tx_packets - transmit packet count
7807 * @rx_packets - receive packet count
7808 *
7809 * The function controls the bus bandwidth and dynamic control of
7810 * tcp delayed ack configuration
7811 *
7812 * Returns: None
7813 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07007814
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007815static void hdd_pld_request_bus_bandwidth(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07007816 const uint64_t tx_packets,
7817 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007818{
Mohit Khannaca4173b2017-09-12 21:52:19 -07007819 u64 total_pkts = tx_packets + rx_packets;
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007820 uint64_t temp_tx = 0, avg_rx = 0;
7821 uint64_t no_rx_offload_pkts = 0, avg_no_rx_offload_pkts = 0;
7822 uint64_t rx_offload_pkts = 0, avg_rx_offload_pkts = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07007823 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08007824 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08007825 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07007826 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007827 uint16_t index = 0;
7828 bool vote_level_change = false;
7829 bool rx_level_change = false;
7830 bool tx_level_change = false;
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007831 bool rxthread_high_tput_req = false;
Mohit Khannaf7562c32018-07-05 17:42:36 -07007832 bool dptrace_high_tput_req;
Srinivas Girigowda50335342018-09-07 15:21:01 -07007833
jitiphil869b9f72018-09-25 17:14:01 +05307834 if (total_pkts > hdd_ctx->config->bus_bw_high_threshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007835 next_vote_level = PLD_BUS_WIDTH_HIGH;
jitiphil869b9f72018-09-25 17:14:01 +05307836 else if (total_pkts > hdd_ctx->config->bus_bw_medium_threshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007837 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
jitiphil869b9f72018-09-25 17:14:01 +05307838 else if (total_pkts > hdd_ctx->config->bus_bw_low_threshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007839 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07007840 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07007841 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007842
Mohit Khannaf7562c32018-07-05 17:42:36 -07007843 dptrace_high_tput_req =
7844 next_vote_level > PLD_BUS_WIDTH_NONE ? true : false;
7845
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007846 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07007847 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
7848 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007849 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007850 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07007851 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007852 if ((next_vote_level == PLD_BUS_WIDTH_LOW) ||
7853 (next_vote_level == PLD_BUS_WIDTH_NONE)) {
Nirav Shahffc6a092016-06-09 16:09:08 +05307854 if (hdd_ctx->hbw_requested) {
7855 pld_remove_pm_qos(hdd_ctx->parent_dev);
7856 hdd_ctx->hbw_requested = false;
7857 }
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007858 if (hdd_ctx->dynamic_rps)
7859 hdd_clear_rps_cpu_mask(hdd_ctx);
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07007860 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05307861 if (!hdd_ctx->hbw_requested) {
7862 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
7863 hdd_ctx->hbw_requested = true;
7864 }
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007865 if (hdd_ctx->dynamic_rps)
7866 hdd_set_rps_cpu_mask(hdd_ctx);
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07007867 }
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007868
Manjunathappa Prakashcb6df762018-05-29 18:54:58 -07007869 if (hdd_ctx->config->napi_cpu_affinity_mask)
7870 hdd_napi_apply_throughput_policy(hdd_ctx,
7871 tx_packets,
7872 rx_packets);
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007873
jitiphil869b9f72018-09-25 17:14:01 +05307874 if (rx_packets < hdd_ctx->config->bus_bw_low_threshold)
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007875 hdd_disable_rx_ol_for_low_tput(hdd_ctx, true);
7876 else
7877 hdd_disable_rx_ol_for_low_tput(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007878 }
Mohit Khannae71e2262015-11-10 09:37:24 -08007879
Mohit Khannaf7562c32018-07-05 17:42:36 -07007880 qdf_dp_trace_apply_tput_policy(dptrace_high_tput_req);
7881
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007882 /*
7883 * Includes tcp+udp, if perf core is required for tcp, then
7884 * perf core is also required for udp.
7885 */
7886 no_rx_offload_pkts = hdd_ctx->no_rx_offload_pkt_cnt;
7887 hdd_ctx->no_rx_offload_pkt_cnt = 0;
7888 rx_offload_pkts = rx_packets - no_rx_offload_pkts;
Mohit Khannae71e2262015-11-10 09:37:24 -08007889
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007890 avg_no_rx_offload_pkts = (no_rx_offload_pkts +
7891 hdd_ctx->prev_no_rx_offload_pkts) / 2;
7892 hdd_ctx->prev_no_rx_offload_pkts = no_rx_offload_pkts;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08007893
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007894 avg_rx_offload_pkts = (rx_offload_pkts +
7895 hdd_ctx->prev_rx_offload_pkts) / 2;
7896 hdd_ctx->prev_rx_offload_pkts = rx_offload_pkts;
7897
7898 avg_rx = avg_no_rx_offload_pkts + avg_rx_offload_pkts;
7899 /*
7900 * Takes care to set Rx_thread affinity for below case
7901 * 1)LRO/GRO not supported ROME case
7902 * 2)when rx_ol is disabled in cases like concurrency etc
7903 * 3)For UDP cases
7904 */
7905 if (avg_no_rx_offload_pkts >
jitiphil869b9f72018-09-25 17:14:01 +05307906 hdd_ctx->config->bus_bw_high_threshold)
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007907 rxthread_high_tput_req = true;
Poddar, Siddarth47c23402017-10-25 12:17:39 +05307908 else
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007909 rxthread_high_tput_req = false;
Poddar, Siddarth47c23402017-10-25 12:17:39 +05307910
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007911 if (cds_sched_handle_throughput_req(rxthread_high_tput_req))
7912 hdd_warn("Rx thread high_tput(%d) affinity request failed",
7913 rxthread_high_tput_req);
7914
7915 /* fine-tuning parameters for RX Flows */
jitiphil869b9f72018-09-25 17:14:01 +05307916 if (avg_rx > hdd_ctx->config->tcp_delack_thres_high) {
Ravi Joshifed83572016-10-07 16:20:37 -07007917 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
7918 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
7919 next_rx_level = WLAN_SVC_TP_HIGH;
7920 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07007921 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07007922 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08007923 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07007924 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007925
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007926 if (hdd_ctx->cur_rx_level != next_rx_level) {
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007927 struct wlan_rx_tp_data rx_tp_data = {0};
7928
Ravi Joshie2331e82015-07-01 18:18:54 -07007929 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Jeff Johnsonb9feee42018-07-08 10:34:48 -07007930 next_rx_level, avg_rx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007931 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007932 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07007933 /* Send throughput indication only if it is enabled.
7934 * Disabling tcp_del_ack will revert the tcp stack behavior
7935 * to default delayed ack. Note that this will disable the
7936 * dynamic delayed ack mechanism across the system
7937 */
Manjunathappa Prakashbfd12762018-04-29 22:44:52 -07007938 if (hdd_ctx->en_tcp_delack_no_lro)
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007939 rx_tp_data.rx_tp_flags |= TCP_DEL_ACK_IND;
7940
Mohit Khanna6272fb682017-04-13 09:34:36 -07007941 if (hdd_ctx->config->enable_tcp_adv_win_scale)
7942 rx_tp_data.rx_tp_flags |= TCP_ADV_WIN_SCL;
7943
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007944 rx_tp_data.level = next_rx_level;
Alok Kumar2fad6442018-11-08 19:19:28 +05307945 wlan_hdd_update_tcp_rx_param(hdd_ctx, &rx_tp_data);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007946 }
7947
Mohit Khannae71e2262015-11-10 09:37:24 -08007948 /* fine-tuning parameters for TX Flows */
7949 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
7950 hdd_ctx->prev_tx = tx_packets;
7951 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
7952 next_tx_level = WLAN_SVC_TP_HIGH;
7953 else
7954 next_tx_level = WLAN_SVC_TP_LOW;
7955
Prakash Manjunathappae73e3b52018-02-27 18:56:22 -08007956 if ((hdd_ctx->config->enable_tcp_limit_output) &&
7957 (hdd_ctx->cur_tx_level != next_tx_level)) {
Alok Kumar2fad6442018-11-08 19:19:28 +05307958 struct wlan_tx_tp_data tx_tp_data = {0};
7959
Mohit Khannae71e2262015-11-10 09:37:24 -08007960 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
7961 next_tx_level, temp_tx);
7962 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007963 tx_level_change = true;
Alok Kumar2fad6442018-11-08 19:19:28 +05307964 tx_tp_data.level = next_tx_level;
7965 tx_tp_data.tcp_limit_output = true;
7966 wlan_hdd_update_tcp_tx_param(hdd_ctx, &tx_tp_data);
Mohit Khannae71e2262015-11-10 09:37:24 -08007967 }
7968
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007969 index = hdd_ctx->hdd_txrx_hist_idx;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007970 if (vote_level_change || tx_level_change || rx_level_change) {
7971 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
7972 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
7973 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
7974 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
7975 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
7976 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
7977 hdd_ctx->hdd_txrx_hist_idx++;
7978 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
7979 }
Mohit Khannaca4173b2017-09-12 21:52:19 -07007980
7981 hdd_display_periodic_stats(hdd_ctx, (total_pkts > 0) ? true : false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007982}
7983
Tiger Yue40e7832019-04-25 10:46:53 +08007984#ifdef QCA_SUPPORT_TXRX_DRIVER_TCP_DEL_ACK
7985/**
7986 * hdd_set_driver_del_ack_enable() - set driver delayed ack enabled flag
7987 * @vdev_id: vdev id
7988 * @hdd_ctx: handle to hdd context
7989 * @rx_packets: receive packet count
7990 *
7991 * Return: none
7992 */
7993static inline
7994void hdd_set_driver_del_ack_enable(uint16_t vdev_id,
7995 struct hdd_context *hdd_ctx,
7996 uint64_t rx_packets)
7997{
7998 struct hdd_config *cfg = hdd_ctx->config;
7999
8000 cdp_vdev_set_driver_del_ack_enable(cds_get_context(QDF_MODULE_ID_SOC),
8001 vdev_id, rx_packets,
8002 cfg->bus_bw_compute_interval,
8003 cfg->del_ack_threshold_high,
8004 cfg->del_ack_threshold_low);
8005}
8006#else
8007static inline
8008void hdd_set_driver_del_ack_enable(uint16_t vdev_id,
8009 struct hdd_context *hdd_ctx,
8010 uint64_t rx_packets)
8011{
8012}
8013#endif
8014
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008015#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Dustin Browna20bad52019-03-05 12:03:30 -08008016static void __hdd_bus_bw_work_handler(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008017{
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05308018 struct hdd_adapter *adapter = NULL, *con_sap_adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05308019 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05308020 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
8021 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008022 uint64_t total_tx = 0, total_rx = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05308023 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008024 bool connected = false;
8025 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
8026
Prashanth Bhattaab004382016-10-11 16:08:11 -07008027 if (wlan_hdd_validate_context(hdd_ctx))
Dustin Browna20bad52019-03-05 12:03:30 -08008028 goto stop_work;
Prashanth Bhattaab004382016-10-11 16:08:11 -07008029
Jeff Johnson214671b2017-10-30 19:45:23 -07008030 if (hdd_ctx->is_wiphy_suspended)
Dustin Browna20bad52019-03-05 12:03:30 -08008031 return;
Jingxiang Gec64e1932017-08-22 14:38:59 +08008032
Dustin Brown920397d2017-12-13 16:27:50 -08008033 hdd_for_each_adapter(hdd_ctx, adapter) {
Manjeet Singh01327cc2016-09-03 12:14:25 +05308034 /*
8035 * Validate magic so we don't end up accessing
8036 * an invalid adapter.
8037 */
8038 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
8039 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008040
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008041 if ((adapter->device_mode == QDF_STA_MODE ||
8042 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Jeff Johnsone7951512019-02-27 10:02:51 -08008043 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.conn_state
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008044 != eConnectionState_Associated) {
8045
8046 continue;
8047 }
8048
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008049 if ((adapter->device_mode == QDF_SAP_MODE ||
8050 adapter->device_mode == QDF_P2P_GO_MODE) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -07008051 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active == false) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008052
8053 continue;
8054 }
8055
8056 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
8057 adapter->prev_tx_packets);
8058 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
8059 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05308060
8061 if (adapter->device_mode == QDF_SAP_MODE ||
8062 adapter->device_mode == QDF_P2P_GO_MODE ||
8063 adapter->device_mode == QDF_IBSS_MODE) {
8064
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08008065 ret = cdp_get_intra_bss_fwd_pkts_count(
8066 cds_get_context(QDF_MODULE_ID_SOC),
Jeff Johnson5a6fc962019-02-04 14:20:25 -08008067 adapter->vdev_id,
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05308068 &fwd_tx_packets, &fwd_rx_packets);
8069 if (ret == A_OK) {
8070 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
8071 fwd_tx_packets,
8072 adapter->prev_fwd_tx_packets);
8073 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
8074 fwd_tx_packets,
8075 adapter->prev_fwd_rx_packets);
8076 }
8077 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008078
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05308079 if (adapter->device_mode == QDF_SAP_MODE)
8080 con_sap_adapter = adapter;
8081
Tiger Yue40e7832019-04-25 10:46:53 +08008082 hdd_set_driver_del_ack_enable(adapter->vdev_id, hdd_ctx,
8083 rx_packets);
8084
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008085 total_rx += adapter->stats.rx_packets;
8086 total_tx += adapter->stats.tx_packets;
8087
8088 spin_lock_bh(&hdd_ctx->bus_bw_lock);
8089 adapter->prev_tx_packets = adapter->stats.tx_packets;
8090 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05308091 adapter->prev_fwd_tx_packets = fwd_tx_packets;
8092 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008093 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
8094 connected = true;
8095 }
8096
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008097 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07008098 hdd_err("bus bandwidth timer running in disconnected state");
Dustin Browna20bad52019-03-05 12:03:30 -08008099 goto stop_work;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008100 }
8101
Yun Parka29974a2018-04-09 12:05:49 -07008102 /* add intra bss forwarded tx and rx packets */
8103 tx_packets += fwd_tx_packets_diff;
8104 rx_packets += fwd_rx_packets_diff;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008105
Dustin Brown07901ec2018-09-07 11:02:41 -07008106 if (ucfg_ipa_is_fw_wdi_activated(hdd_ctx->pdev)) {
8107 ucfg_ipa_uc_stat_query(hdd_ctx->pdev, &ipa_tx_packets,
8108 &ipa_rx_packets);
Yun Parka29974a2018-04-09 12:05:49 -07008109 tx_packets += (uint64_t)ipa_tx_packets;
8110 rx_packets += (uint64_t)ipa_rx_packets;
8111
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05308112 if (con_sap_adapter) {
8113 con_sap_adapter->stats.tx_packets += ipa_tx_packets;
8114 con_sap_adapter->stats.rx_packets += ipa_rx_packets;
8115 }
8116
Dustin Brown07901ec2018-09-07 11:02:41 -07008117 ucfg_ipa_set_perf_level(hdd_ctx->pdev, tx_packets, rx_packets);
8118 ucfg_ipa_uc_stat_request(hdd_ctx->pdev, 2);
Yun Parka29974a2018-04-09 12:05:49 -07008119 }
8120
8121 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008122
Dustin Browna20bad52019-03-05 12:03:30 -08008123 return;
8124
8125stop_work:
8126 qdf_periodic_work_stop_async(&hdd_ctx->bus_bw_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008127}
Prashanth Bhattaab004382016-10-11 16:08:11 -07008128
Dustin Browna20bad52019-03-05 12:03:30 -08008129static void hdd_bus_bw_work_handler(void *context)
Rajeev Kumarb2b5e692018-08-31 15:12:40 -07008130{
Dustin Brown3fdaaf62019-03-18 14:00:16 -07008131 struct hdd_context *hdd_ctx = context;
8132 struct qdf_op_sync *op_sync;
Dustin Browna20bad52019-03-05 12:03:30 -08008133
Dustin Brown3fdaaf62019-03-18 14:00:16 -07008134 if (qdf_op_protect(&op_sync))
8135 return;
8136
8137 __hdd_bus_bw_work_handler(hdd_ctx);
8138
8139 qdf_op_unprotect(op_sync);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05308140}
8141
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008142int hdd_bus_bandwidth_init(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07008143{
Dustin Browna20bad52019-03-05 12:03:30 -08008144 QDF_STATUS status;
8145
Dustin Brown35008ba2018-08-23 14:34:21 -07008146 hdd_enter();
8147
Prashanth Bhattaab004382016-10-11 16:08:11 -07008148 spin_lock_init(&hdd_ctx->bus_bw_lock);
Dustin Browna20bad52019-03-05 12:03:30 -08008149 status = qdf_periodic_work_create(&hdd_ctx->bus_bw_work,
8150 hdd_bus_bw_work_handler,
Dustin Brown3fdaaf62019-03-18 14:00:16 -07008151 hdd_ctx);
Dustin Brown35008ba2018-08-23 14:34:21 -07008152
8153 hdd_exit();
Prashanth Bhattaab004382016-10-11 16:08:11 -07008154
Dustin Browna20bad52019-03-05 12:03:30 -08008155 return qdf_status_to_os_return(status);
Prashanth Bhattaab004382016-10-11 16:08:11 -07008156}
8157
Dustin Brown86d196b2018-08-02 11:51:49 -07008158void hdd_bus_bandwidth_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07008159{
Dustin Brown35008ba2018-08-23 14:34:21 -07008160 hdd_enter();
Prashanth Bhattaab004382016-10-11 16:08:11 -07008161
Dustin Browna20bad52019-03-05 12:03:30 -08008162 QDF_BUG(!qdf_periodic_work_stop_sync(&hdd_ctx->bus_bw_work));
8163 qdf_periodic_work_destroy(&hdd_ctx->bus_bw_work);
Dustin Brown35008ba2018-08-23 14:34:21 -07008164
8165 hdd_exit();
Prashanth Bhattaab004382016-10-11 16:08:11 -07008166}
Tiger Yu8b119e92019-04-09 13:55:07 +08008167#endif /*WLAN_FEATURE_DP_BUS_BANDWIDTH*/
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008168
8169/**
Nirav Shahed34b212016-04-25 10:59:16 +05308170 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
8171 * @hdd_ctx: hdd context
8172 *
8173 * Return: 0 for success or error code
8174 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008175static int wlan_hdd_init_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05308176{
8177 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
8178 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Min Liu74a1a502018-10-10 19:59:07 +08008179 if (!hdd_ctx->hdd_txrx_hist)
Nirav Shahed34b212016-04-25 10:59:16 +05308180 return -ENOMEM;
Nirav Shahed34b212016-04-25 10:59:16 +05308181 return 0;
8182}
8183
8184/**
8185 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
8186 * @hdd_ctx: hdd context
8187 *
8188 * Return: none
8189 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008190void wlan_hdd_deinit_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05308191{
Jeff Johnsond36fa332019-03-18 13:42:25 -07008192 if (!hdd_ctx || !hdd_ctx->hdd_txrx_hist)
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05308193 return;
8194
8195 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
8196 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05308197}
8198
Nirav Shahda008342016-05-17 18:50:40 +05308199static uint8_t *convert_level_to_string(uint32_t level)
8200{
8201 switch (level) {
8202 /* initialize the wlan sub system */
8203 case WLAN_SVC_TP_NONE:
8204 return "NONE";
8205 case WLAN_SVC_TP_LOW:
8206 return "LOW";
8207 case WLAN_SVC_TP_MEDIUM:
8208 return "MED";
8209 case WLAN_SVC_TP_HIGH:
8210 return "HIGH";
8211 default:
8212 return "INVAL";
8213 }
8214}
8215
Nirav Shahed34b212016-04-25 10:59:16 +05308216
8217/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008218 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
8219 * @hdd_ctx: hdd context
8220 *
8221 * Return: none
8222 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008223void wlan_hdd_display_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008224{
8225 int i;
8226
Tiger Yu8b119e92019-04-09 13:55:07 +08008227#ifdef WLAN_FEATURE_DP_BUS_BANDWIDTH
Nirav Shahe6194ac2018-07-13 11:04:41 +05308228 hdd_nofl_info("BW compute Interval: %dms",
jitiphil869b9f72018-09-25 17:14:01 +05308229 hdd_ctx->config->bus_bw_compute_interval);
Nirav Shahe6194ac2018-07-13 11:04:41 +05308230 hdd_nofl_info("BW High TH: %d BW Med TH: %d BW Low TH: %d",
jitiphil869b9f72018-09-25 17:14:01 +05308231 hdd_ctx->config->bus_bw_high_threshold,
8232 hdd_ctx->config->bus_bw_medium_threshold,
8233 hdd_ctx->config->bus_bw_low_threshold);
Nirav Shahe6194ac2018-07-13 11:04:41 +05308234 hdd_nofl_info("Enable TCP DEL ACK: %d",
8235 hdd_ctx->en_tcp_delack_no_lro);
8236 hdd_nofl_info("TCP DEL High TH: %d TCP DEL Low TH: %d",
jitiphil869b9f72018-09-25 17:14:01 +05308237 hdd_ctx->config->tcp_delack_thres_high,
8238 hdd_ctx->config->tcp_delack_thres_low);
Nirav Shahe6194ac2018-07-13 11:04:41 +05308239 hdd_nofl_info("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
8240 hdd_ctx->config->tcp_tx_high_tput_thres);
Tiger Yu8b119e92019-04-09 13:55:07 +08008241#endif /*WLAN_FEATURE_DP_BUS_BANDWIDTH*/
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008242
Nirav Shahe6194ac2018-07-13 11:04:41 +05308243 hdd_nofl_info("Total entries: %d Current index: %d",
8244 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
Nirav Shahda008342016-05-17 18:50:40 +05308245
Nirav Shahe6194ac2018-07-13 11:04:41 +05308246 hdd_nofl_info("[index][timestamp]: interval_rx, interval_tx, bus_bw_level, RX TP Level, TX TP Level");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008247
8248 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07008249 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08008250 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Nirav Shahe6194ac2018-07-13 11:04:41 +05308251 hdd_nofl_info("[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
8252 i, hdd_ctx->hdd_txrx_hist[i].qtime,
8253 hdd_ctx->hdd_txrx_hist[i].interval_rx,
8254 hdd_ctx->hdd_txrx_hist[i].interval_tx,
8255 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07008256 hdd_ctx->hdd_txrx_hist[i].
8257 next_vote_level),
Nirav Shahe6194ac2018-07-13 11:04:41 +05308258 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07008259 hdd_ctx->hdd_txrx_hist[i].
8260 next_rx_level),
Nirav Shahe6194ac2018-07-13 11:04:41 +05308261 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07008262 hdd_ctx->hdd_txrx_hist[i].
8263 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008264 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008265}
8266
8267/**
8268 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
8269 * @hdd_ctx: hdd context
8270 *
8271 * Return: none
8272 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008273void wlan_hdd_clear_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008274{
8275 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05308276 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
8277 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008278}
8279
Mohit Khannaca4173b2017-09-12 21:52:19 -07008280/* length of the netif queue log needed per adapter */
8281#define ADAP_NETIFQ_LOG_LEN ((20 * WLAN_REASON_TYPE_MAX) + 50)
8282
8283/**
8284 *
8285 * hdd_display_netif_queue_history_compact() - display compact netifq history
8286 * @hdd_ctx: hdd context
8287 *
8288 * Return: none
8289 */
8290static void
8291hdd_display_netif_queue_history_compact(struct hdd_context *hdd_ctx)
8292{
8293 int adapter_num = 0;
8294 int i;
8295 int bytes_written;
8296 u32 tbytes;
8297 qdf_time_t total, pause, unpause, curr_time, delta;
Mohit Khannaca4173b2017-09-12 21:52:19 -07008298 char temp_str[20 * WLAN_REASON_TYPE_MAX];
jiadbdefb252018-01-03 14:27:06 +08008299 char *comb_log_str;
8300 uint32_t comb_log_str_size;
Mohit Khannaca4173b2017-09-12 21:52:19 -07008301 struct hdd_adapter *adapter = NULL;
Mohit Khannaca4173b2017-09-12 21:52:19 -07008302
Dustin Brownad06be62019-02-04 14:52:56 -08008303 comb_log_str_size = (ADAP_NETIFQ_LOG_LEN * WLAN_MAX_VDEVS) + 1;
jiadbdefb252018-01-03 14:27:06 +08008304 comb_log_str = qdf_mem_malloc(comb_log_str_size);
Min Liu74a1a502018-10-10 19:59:07 +08008305 if (!comb_log_str)
jiadbdefb252018-01-03 14:27:06 +08008306 return;
jiadbdefb252018-01-03 14:27:06 +08008307
Mohit Khannaca4173b2017-09-12 21:52:19 -07008308 bytes_written = 0;
Mohit Khannaca4173b2017-09-12 21:52:19 -07008309
Dustin Brown920397d2017-12-13 16:27:50 -08008310 hdd_for_each_adapter(hdd_ctx, adapter) {
Mohit Khannaca4173b2017-09-12 21:52:19 -07008311 curr_time = qdf_system_ticks();
8312 total = curr_time - adapter->start_time;
8313 delta = curr_time - adapter->last_time;
8314
8315 if (adapter->pause_map) {
8316 pause = adapter->total_pause_time + delta;
8317 unpause = adapter->total_unpause_time;
8318 } else {
8319 unpause = adapter->total_unpause_time + delta;
8320 pause = adapter->total_pause_time;
8321 }
8322
8323 tbytes = 0;
hangtian127c9532019-01-12 13:29:07 +08008324 qdf_mem_zero(temp_str, sizeof(temp_str));
Mohit Khannaca4173b2017-09-12 21:52:19 -07008325 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
8326 if (adapter->queue_oper_stats[i].pause_count == 0)
8327 continue;
8328 tbytes +=
8329 snprintf(
8330 &temp_str[tbytes],
8331 (tbytes >= sizeof(temp_str) ?
8332 0 : sizeof(temp_str) - tbytes),
8333 "%d(%d,%d) ",
8334 i,
8335 adapter->queue_oper_stats[i].
8336 pause_count,
8337 adapter->queue_oper_stats[i].
8338 unpause_count);
8339 }
8340 if (tbytes >= sizeof(temp_str))
8341 hdd_warn("log truncated");
8342
8343 bytes_written += snprintf(&comb_log_str[bytes_written],
jiadbdefb252018-01-03 14:27:06 +08008344 bytes_written >= comb_log_str_size ? 0 :
8345 comb_log_str_size - bytes_written,
Mohit Khannaca4173b2017-09-12 21:52:19 -07008346 "[%d %d] (%d) %u/%ums %s|",
Jeff Johnson5a6fc962019-02-04 14:20:25 -08008347 adapter->vdev_id, adapter->device_mode,
Mohit Khannaca4173b2017-09-12 21:52:19 -07008348 adapter->pause_map,
8349 qdf_system_ticks_to_msecs(pause),
8350 qdf_system_ticks_to_msecs(total),
8351 temp_str);
8352
Mohit Khannaca4173b2017-09-12 21:52:19 -07008353 adapter_num++;
8354 }
8355
8356 /* using QDF_TRACE to avoid printing function name */
8357 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO_LOW,
8358 "STATS |%s", comb_log_str);
8359
jiadbdefb252018-01-03 14:27:06 +08008360 if (bytes_written >= comb_log_str_size)
Mohit Khannaca4173b2017-09-12 21:52:19 -07008361 hdd_warn("log string truncated");
jiadbdefb252018-01-03 14:27:06 +08008362
8363 qdf_mem_free(comb_log_str);
Mohit Khannaca4173b2017-09-12 21:52:19 -07008364}
8365
Mohit Khannaf7e7b342019-04-08 11:54:21 -07008366/* Max size of a single netdev tx queue state string. e.g. "1: 0x1" */
8367#define HDD_NETDEV_TX_Q_STATE_STRLEN 15
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008368/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07008369 * wlan_hdd_display_netif_queue_history() - display netif queue history
Jeff Johnson58adbcf2017-09-03 08:53:31 -07008370 * @hdd_ctx: hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008371 *
8372 * Return: none
8373 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07008374void
8375wlan_hdd_display_netif_queue_history(struct hdd_context *hdd_ctx,
8376 enum qdf_stats_verbosity_level verb_lvl)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008377{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008378 int i;
Mohit Khannaf7e7b342019-04-08 11:54:21 -07008379 struct hdd_adapter *adapter = NULL;
Nirav Shahda008342016-05-17 18:50:40 +05308380 qdf_time_t total, pause, unpause, curr_time, delta;
Mohit Khannaf7e7b342019-04-08 11:54:21 -07008381 struct hdd_netif_queue_history *q_hist_ptr;
8382 char q_status_buf[NUM_TX_QUEUES * HDD_NETDEV_TX_Q_STATE_STRLEN] = {0};
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008383
Mohit Khannaca4173b2017-09-12 21:52:19 -07008384 if (verb_lvl == QDF_STATS_VERBOSITY_LEVEL_LOW) {
8385 hdd_display_netif_queue_history_compact(hdd_ctx);
8386 return;
8387 }
8388
Dustin Brown920397d2017-12-13 16:27:50 -08008389 hdd_for_each_adapter(hdd_ctx, adapter) {
Mohit Khannaf7e7b342019-04-08 11:54:21 -07008390 if (adapter->vdev_id == CDP_INVALID_VDEV_ID)
8391 continue;
Nirav Shahe6194ac2018-07-13 11:04:41 +05308392 hdd_nofl_info("Netif queue operation statistics:");
Jeff Johnson55d2ab42019-03-06 11:43:49 -08008393 hdd_nofl_info("vdev_id %d device mode %d",
Jeff Johnson5a6fc962019-02-04 14:20:25 -08008394 adapter->vdev_id, adapter->device_mode);
Nirav Shahe6194ac2018-07-13 11:04:41 +05308395 hdd_nofl_info("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05308396 curr_time = qdf_system_ticks();
8397 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05308398 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05308399 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05308400 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05308401 unpause = adapter->total_unpause_time;
8402 } else {
Nirav Shahda008342016-05-17 18:50:40 +05308403 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05308404 pause = adapter->total_pause_time;
8405 }
Nirav Shahe6194ac2018-07-13 11:04:41 +05308406 hdd_nofl_info("Total: %ums Pause: %ums Unpause: %ums",
8407 qdf_system_ticks_to_msecs(total),
8408 qdf_system_ticks_to_msecs(pause),
8409 qdf_system_ticks_to_msecs(unpause));
8410 hdd_nofl_info("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008411
Nirav Shahda008342016-05-17 18:50:40 +05308412 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
8413 qdf_time_t pause_delta = 0;
8414
8415 if (adapter->pause_map & (1 << i))
8416 pause_delta = delta;
8417
Mohit Khanna3e2115b2016-10-11 13:18:29 -07008418 /* using hdd_log to avoid printing function name */
Nirav Shahe6194ac2018-07-13 11:04:41 +05308419 hdd_nofl_info("%s: %d: %d: %ums",
8420 hdd_reason_type_to_string(i),
8421 adapter->queue_oper_stats[i].pause_count,
8422 adapter->queue_oper_stats[i].
8423 unpause_count,
8424 qdf_system_ticks_to_msecs(
8425 adapter->queue_oper_stats[i].
8426 total_pause_time + pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008427 }
8428
Mohit Khannaf7e7b342019-04-08 11:54:21 -07008429 hdd_nofl_info("Netif queue operation history: Total entries: %d current index %d(-1) time %u",
Nirav Shahe6194ac2018-07-13 11:04:41 +05308430 WLAN_HDD_MAX_HISTORY_ENTRY,
Mohit Khannaf7e7b342019-04-08 11:54:21 -07008431 adapter->history_index,
8432 qdf_system_ticks_to_msecs(qdf_system_ticks()));
Nirav Shahda008342016-05-17 18:50:40 +05308433
Mohit Khannaf7e7b342019-04-08 11:54:21 -07008434 hdd_nofl_info("%2s%20s%50s%30s%10s %s",
8435 "#", "time(ms)", "action_type", "reason_type",
8436 "pause_map", "netdev-queue-status");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008437
8438 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07008439 /* using hdd_log to avoid printing function name */
8440 if (adapter->queue_oper_history[i].time == 0)
8441 continue;
Mohit Khannaf7e7b342019-04-08 11:54:21 -07008442 q_hist_ptr = &adapter->queue_oper_history[i];
8443 wlan_hdd_dump_queue_history_state(q_hist_ptr,
8444 q_status_buf,
8445 sizeof(q_status_buf));
8446 hdd_nofl_info("%2d%20u%50s%30s%10x %s",
Nirav Shahe6194ac2018-07-13 11:04:41 +05308447 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008448 adapter->queue_oper_history[i].time),
Nirav Shahe6194ac2018-07-13 11:04:41 +05308449 hdd_action_type_to_string(
8450 adapter->queue_oper_history[i].
8451 netif_action),
8452 hdd_reason_type_to_string(
8453 adapter->queue_oper_history[i].
8454 netif_reason),
Mohit Khannaf7e7b342019-04-08 11:54:21 -07008455 adapter->queue_oper_history[i].pause_map,
8456 q_status_buf);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008457 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008458 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008459}
8460
8461/**
8462 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
8463 * @hdd_ctx: hdd context
8464 *
8465 * Return: none
8466 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008467void wlan_hdd_clear_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008468{
Jeff Johnson9d295242017-08-29 14:39:48 -07008469 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008470
Dustin Brown920397d2017-12-13 16:27:50 -08008471 hdd_for_each_adapter(hdd_ctx, adapter) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308472 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008473 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308474 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008475 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05308476 adapter->history_index = 0;
8477 adapter->start_time = adapter->last_time = qdf_system_ticks();
8478 adapter->total_pause_time = 0;
8479 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008480 }
8481}
8482
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008483#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
8484/**
8485 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
8486 * @hdd_ctx: hdd global context
8487 *
8488 * Return: none
8489 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008490static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008491{
8492 uint8_t i;
8493
8494 mutex_init(&hdd_ctx->op_ctx.op_lock);
8495 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
8496 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
8497 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
8498 }
8499}
8500#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008501static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008502{
8503}
8504#endif
8505
Yingying Tang95409972016-10-20 15:16:15 +08008506#ifdef WLAN_FEATURE_WOW_PULSE
8507/**
8508 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
Jeff Johnsonfd7d1ef2019-03-31 10:41:37 -07008509 * @hdd_ctx: struct hdd_context structure pointer
Yingying Tang95409972016-10-20 15:16:15 +08008510 * @enable: enable or disable this behaviour
8511 *
8512 * Return: int
8513 */
Jeff Johnsonfd7d1ef2019-03-31 10:41:37 -07008514static int wlan_hdd_set_wow_pulse(struct hdd_context *hdd_ctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08008515{
Yingying Tang95409972016-10-20 15:16:15 +08008516 struct wow_pulse_mode wow_pulse_set_info;
8517 QDF_STATUS status;
8518
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008519 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08008520
Jeff Johnsonfd7d1ef2019-03-31 10:41:37 -07008521 if (!ucfg_pmo_is_wow_pulse_enabled(hdd_ctx->psoc))
Yingying Tang95409972016-10-20 15:16:15 +08008522 return 0;
8523
8524 /* prepare the request to send to SME */
8525 if (enable == true) {
8526 wow_pulse_set_info.wow_pulse_enable = true;
8527 wow_pulse_set_info.wow_pulse_pin =
Jeff Johnsonfd7d1ef2019-03-31 10:41:37 -07008528 ucfg_pmo_get_wow_pulse_pin(hdd_ctx->psoc);
Wu Gao66454f12018-09-26 19:55:41 +08008529
Yingying Tang95409972016-10-20 15:16:15 +08008530 wow_pulse_set_info.wow_pulse_interval_high =
Jeff Johnsonfd7d1ef2019-03-31 10:41:37 -07008531 ucfg_pmo_get_wow_pulse_interval_high(hdd_ctx->psoc);
Wu Gao66454f12018-09-26 19:55:41 +08008532
8533 wow_pulse_set_info.wow_pulse_interval_low =
Jeff Johnsonfd7d1ef2019-03-31 10:41:37 -07008534 ucfg_pmo_get_wow_pulse_interval_low(hdd_ctx->psoc);
Yingying Tang95409972016-10-20 15:16:15 +08008535 } else {
8536 wow_pulse_set_info.wow_pulse_enable = false;
8537 wow_pulse_set_info.wow_pulse_pin = 0;
8538 wow_pulse_set_info.wow_pulse_interval_low = 0;
8539 wow_pulse_set_info.wow_pulse_interval_high = 0;
8540 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008541 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08008542 wow_pulse_set_info.wow_pulse_enable,
8543 wow_pulse_set_info.wow_pulse_pin,
8544 wow_pulse_set_info.wow_pulse_interval_low,
8545 wow_pulse_set_info.wow_pulse_interval_high);
8546
8547 status = sme_set_wow_pulse(&wow_pulse_set_info);
8548 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008549 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08008550 return -EIO;
8551 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008552 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08008553 return 0;
8554}
8555#else
Jeff Johnsonfd7d1ef2019-03-31 10:41:37 -07008556static inline int wlan_hdd_set_wow_pulse(struct hdd_context *hdd_ctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08008557{
8558 return 0;
8559}
8560#endif
8561
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008562#ifdef WLAN_FEATURE_FASTPATH
jitiphil377bcc12018-10-05 19:46:08 +05308563
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008564/**
8565 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
8566 * @hdd_cfg: hdd config
8567 * @context: lower layer context
8568 *
8569 * Return: none
8570 */
jitiphil377bcc12018-10-05 19:46:08 +05308571void hdd_enable_fastpath(struct hdd_context *hdd_ctx,
8572 void *context)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008573{
jitiphil377bcc12018-10-05 19:46:08 +05308574 if (cfg_get(hdd_ctx->psoc, CFG_DP_ENABLE_FASTPATH))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008575 hif_enable_fastpath(context);
8576}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008577#endif
8578
Yuanyuan Liu13738502016-04-06 17:41:37 -07008579#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008580/**
8581 * hdd_set_thermal_level_cb() - set thermal level callback function
Jeff Johnson0e963082018-07-04 19:39:20 -07008582 * @hdd_handle: opaque handle for the hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008583 * @level: thermal level
8584 *
8585 * Change IPA data path to SW path when the thermal throttle level greater
8586 * than 0, and restore the original data path when throttle level is 0
8587 *
8588 * Return: none
8589 */
Jeff Johnson0e963082018-07-04 19:39:20 -07008590static void hdd_set_thermal_level_cb(hdd_handle_t hdd_handle, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008591{
Jeff Johnson0e963082018-07-04 19:39:20 -07008592 struct hdd_context *hdd_ctx = hdd_handle_to_context(hdd_handle);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008593
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008594 /* Change IPA to SW path when throttle level greater than 0 */
8595 if (level > THROTTLE_LEVEL_0)
Dustin Brown07901ec2018-09-07 11:02:41 -07008596 ucfg_ipa_send_mcc_scc_msg(hdd_ctx->pdev, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008597 else
8598 /* restore original concurrency mode */
Dustin Brown07901ec2018-09-07 11:02:41 -07008599 ucfg_ipa_send_mcc_scc_msg(hdd_ctx->pdev, hdd_ctx->mcc_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008600}
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +05308601#else
8602/**
8603 * hdd_set_thermal_level_cb() - set thermal level callback function
8604 * @hdd_handle: opaque handle for the hdd context
8605 * @level: thermal level
8606 *
8607 * Change IPA data path to SW path when the thermal throttle level greater
8608 * than 0, and restore the original data path when throttle level is 0
8609 *
8610 * Return: none
8611 */
8612static void hdd_set_thermal_level_cb(hdd_handle_t hdd_handle, u_int8_t level)
8613{
8614}
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +05308615#endif
8616
8617/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08008618 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308619 * @adapter: AP adapter
8620 * @channel: Channel
Min Liu2fef5792018-01-19 17:59:42 +08008621 * @forced: Force to switch channel, ignore SCC/MCC check
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308622 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08008623 * Moves the SAP interface by invoking the function which
8624 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308625 *
8626 * Return: None
8627 */
Min Liu2fef5792018-01-19 17:59:42 +08008628void hdd_switch_sap_channel(struct hdd_adapter *adapter, uint8_t channel,
8629 bool forced)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308630{
Jeff Johnson87251032017-08-29 13:31:11 -07008631 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008632 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -07008633 mac_handle_t mac_handle;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308634
8635 if (!adapter) {
8636 hdd_err("invalid adapter");
8637 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008638 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308639
8640 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
8641
Jeff Johnson16528362018-06-14 12:34:16 -07008642 mac_handle = hdd_adapter_get_mac_handle(adapter);
8643 if (!mac_handle) {
8644 hdd_err("invalid MAC handle");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308645 return;
8646 }
8647
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008648 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8649
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008650 hdd_debug("chan:%d width:%d",
Jeff Johnson91df29d2017-10-27 19:29:50 -07008651 channel, hdd_ap_ctx->sap_config.ch_width_orig);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308652
Dustin Brown1dbefe62018-09-11 16:32:03 -07008653 policy_mgr_change_sap_channel_with_csa(hdd_ctx->psoc,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08008654 adapter->vdev_id, channel,
Min Liu2fef5792018-01-19 17:59:42 +08008655 hdd_ap_ctx->sap_config.ch_width_orig, forced);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008656}
Kapil Gupta8878ad92017-02-13 11:56:04 +05308657
Jeff Johnson9d295242017-08-29 14:39:48 -07008658int hdd_update_acs_timer_reason(struct hdd_adapter *adapter, uint8_t reason)
Kapil Gupta8878ad92017-02-13 11:56:04 +05308659{
8660 struct hdd_external_acs_timer_context *timer_context;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308661 int status;
8662 QDF_STATUS qdf_status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308663
8664 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
8665
8666 if (QDF_TIMER_STATE_RUNNING ==
Jeff Johnsonb9424862017-10-30 08:49:35 -07008667 qdf_mc_timer_get_current_state(&adapter->session.
Kapil Gupta8878ad92017-02-13 11:56:04 +05308668 ap.vendor_acs_timer)) {
Jeff Johnsonb9424862017-10-30 08:49:35 -07008669 qdf_mc_timer_stop(&adapter->session.ap.vendor_acs_timer);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308670 }
8671 timer_context = (struct hdd_external_acs_timer_context *)
Jeff Johnsonb9424862017-10-30 08:49:35 -07008672 adapter->session.ap.vendor_acs_timer.user_data;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308673 timer_context->reason = reason;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308674 qdf_status =
Jeff Johnsonb9424862017-10-30 08:49:35 -07008675 qdf_mc_timer_start(&adapter->session.ap.vendor_acs_timer,
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308676 WLAN_VENDOR_ACS_WAIT_TIME);
8677 if (qdf_status != QDF_STATUS_SUCCESS) {
8678 hdd_err("failed to start external acs timer");
8679 return -ENOSPC;
8680 }
8681 /* Update config to application */
8682 status = hdd_cfg80211_update_acs_config(adapter, reason);
Dustin Brown5e89ef82018-03-14 11:50:23 -07008683 hdd_info("Updated ACS config to nl with reason %d", reason);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308684
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308685 return status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308686}
8687
Nirav Shaheb017be2018-02-15 11:20:58 +05308688#if defined(FEATURE_WLAN_CH_AVOID)
Agrawal Ashish467dde42016-09-08 18:44:22 +05308689/**
8690 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
8691 * @hdd_ctx: hdd context pointer
8692 *
8693 * hdd_unsafe_channel_restart_sap check all unsafe channel list
8694 * and if ACS is enabled, driver will ask userspace to restart the
8695 * sap. User space on LTE coex indication restart driver.
8696 *
8697 * Return - none
8698 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008699void hdd_unsafe_channel_restart_sap(struct hdd_context *hdd_ctxt)
Agrawal Ashish467dde42016-09-08 18:44:22 +05308700{
Dustin Brown920397d2017-12-13 16:27:50 -08008701 struct hdd_adapter *adapter;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308702 uint32_t i;
8703 bool found = false;
8704 uint8_t restart_chan;
Krunal Sonidf29bc42018-11-15 13:26:29 -08008705 uint8_t scc_on_lte_coex = 0;
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05308706 bool value;
Harprit Chhabada1eeeb8d2018-09-14 15:16:56 -07008707 QDF_STATUS status;
8708 bool is_acs_support_for_dfs_ltecoex = cfg_default(CFG_USER_ACS_DFS_LTE);
8709 bool is_vendor_acs_support =
8710 cfg_default(CFG_USER_AUTO_CHANNEL_SELECTION);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008711
Dustin Brown920397d2017-12-13 16:27:50 -08008712 hdd_for_each_adapter(hdd_ctxt, adapter) {
8713 if (!(adapter->device_mode == QDF_SAP_MODE &&
8714 adapter->session.ap.sap_config.acs_cfg.acs_mode)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008715 hdd_debug("skip device mode:%d acs:%d",
Dustin Brown920397d2017-12-13 16:27:50 -08008716 adapter->device_mode,
8717 adapter->session.ap.sap_config.
8718 acs_cfg.acs_mode);
8719 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308720 }
8721
8722 found = false;
Krunal Sonidf29bc42018-11-15 13:26:29 -08008723 status =
8724 ucfg_policy_mgr_get_sta_sap_scc_lte_coex_chnl(hdd_ctxt->psoc,
8725 &scc_on_lte_coex);
8726 if (!QDF_IS_STATUS_SUCCESS(status))
8727 hdd_err("can't get scc on lte coex chnl, use def");
Tushnim Bhattacharyyad2e085d2018-06-18 11:58:50 -07008728 /*
8729 * If STA+SAP is doing SCC & g_sta_sap_scc_on_lte_coex_chan
8730 * is set, no need to move SAP.
8731 */
Manikandan Mohan956b69e2019-02-14 13:08:14 -08008732 if ((policy_mgr_is_sta_sap_scc(
8733 hdd_ctxt->psoc,
8734 adapter->session.ap.operating_channel) &&
8735 scc_on_lte_coex) ||
8736 policy_mgr_nan_sap_scc_on_unsafe_ch_chk(
8737 hdd_ctxt->psoc,
8738 adapter->session.ap.operating_channel)) {
8739 hdd_debug("SAP allowed in unsafe SCC channel");
8740 } else {
Tushnim Bhattacharyyad2e085d2018-06-18 11:58:50 -07008741 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
8742 if (adapter->session.ap.operating_channel ==
8743 hdd_ctxt->unsafe_channel_list[i]) {
8744 found = true;
8745 hdd_debug("operating ch:%d is unsafe",
8746 adapter->session.ap.operating_channel);
8747 break;
8748 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308749 }
8750 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308751 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008752 hdd_debug("ch:%d is safe. no need to change channel",
Dustin Brown920397d2017-12-13 16:27:50 -08008753 adapter->session.ap.operating_channel);
8754 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308755 }
8756
Harprit Chhabada1eeeb8d2018-09-14 15:16:56 -07008757 status = ucfg_mlme_get_acs_support_for_dfs_ltecoex(
8758 hdd_ctxt->psoc,
8759 &is_acs_support_for_dfs_ltecoex);
8760 if (!QDF_IS_STATUS_SUCCESS(status))
8761 hdd_err("get_acs_support_for_dfs_ltecoex failed,set def");
8762
8763 status = ucfg_mlme_get_vendor_acs_support(
8764 hdd_ctxt->psoc,
8765 &is_vendor_acs_support);
8766 if (!QDF_IS_STATUS_SUCCESS(status))
8767 hdd_err("get_vendor_acs_support failed, set default");
8768
8769 if (is_vendor_acs_support && is_acs_support_for_dfs_ltecoex) {
Dustin Brown920397d2017-12-13 16:27:50 -08008770 hdd_update_acs_timer_reason(adapter,
Kapil Gupta8878ad92017-02-13 11:56:04 +05308771 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
Dustin Brown920397d2017-12-13 16:27:50 -08008772 continue;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308773 } else
8774 restart_chan =
bings6c4672b2019-03-19 16:00:19 +08008775 wlansap_get_safe_channel_from_pcl_and_acs_range(
8776 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Agrawal Ashish467dde42016-09-08 18:44:22 +05308777 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008778 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05308779 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08008780 /*
8781 * SAP restart due to unsafe channel. While
8782 * restarting the SAP, make sure to clear
8783 * acs_channel, channel to reset to
8784 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308785 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08008786 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308787 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Dustin Brown05d81302018-09-11 16:49:22 -07008788 ucfg_mlme_get_sap_internal_restart(hdd_ctxt->psoc,
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05308789 &value);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05308790 if (value)
Min Liu2fef5792018-01-19 17:59:42 +08008791 hdd_switch_sap_channel(adapter, restart_chan,
8792 true);
hqu1d1b9222019-06-11 20:00:55 +08008793 else {
8794 hdd_debug("sending coex indication");
8795 wlan_hdd_send_svc_nlink_msg(
8796 hdd_ctxt->radio_index,
8797 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Liangwei Dong6663d162017-07-10 03:29:36 -04008798 return;
hqu1d1b9222019-06-11 20:00:55 +08008799 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308800 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308801 }
8802}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05308803
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008804/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008805 * hdd_init_channel_avoidance() - Initialize channel avoidance
8806 * @hdd_ctx: HDD global context
8807 *
8808 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07008809 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008810 * down to the lower layers. Then subscribe to subsequent channel
8811 * avoidance events.
8812 *
8813 * Return: None
8814 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008815static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008816{
8817 uint16_t unsafe_channel_count;
8818 int index;
8819
Yuanyuan Liu13738502016-04-06 17:41:37 -07008820 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
8821 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008822 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08008823 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008824
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008825 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008826 hdd_ctx->unsafe_channel_count);
8827
Anurag Chouhan6d760662016-02-20 16:05:43 +05308828 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08008829 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008830
8831 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008832 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008833 hdd_ctx->unsafe_channel_list[index]);
8834
8835 }
8836
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008837}
Dustin Brown676a2322017-08-15 13:16:13 -07008838
Jeff Johnson9d295242017-08-29 14:39:48 -07008839static void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008840 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07008841{
8842 uint8_t restart_chan;
8843
bings6c4672b2019-03-19 16:00:19 +08008844 restart_chan = wlansap_get_safe_channel_from_pcl_and_acs_range(
8845 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Dustin Brown676a2322017-08-15 13:16:13 -07008846 if (!restart_chan) {
8847 hdd_alert("fail to restart SAP");
8848 return;
8849 }
8850
8851 /* SAP restart due to unsafe channel. While restarting
8852 * the SAP, make sure to clear acs_channel, channel to
8853 * reset to 0. Otherwise these settings will override
8854 * the ACS while restart.
8855 */
8856 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Dustin Brown676a2322017-08-15 13:16:13 -07008857
8858 hdd_debug("sending coex indication");
8859
8860 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
8861 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Min Liu2fef5792018-01-19 17:59:42 +08008862 hdd_switch_sap_channel(adapter, restart_chan, true);
Dustin Brown676a2322017-08-15 13:16:13 -07008863}
Liangwei Dong6e1a2092017-08-30 16:29:06 +08008864
8865int hdd_clone_local_unsafe_chan(struct hdd_context *hdd_ctx,
8866 uint16_t **local_unsafe_list, uint16_t *local_unsafe_list_count)
8867{
8868 uint32_t size;
8869 uint16_t *unsafe_list;
8870 uint16_t chan_count;
8871
8872 if (!hdd_ctx || !local_unsafe_list_count || !local_unsafe_list_count)
8873 return -EINVAL;
8874
8875 chan_count = QDF_MIN(hdd_ctx->unsafe_channel_count,
8876 NUM_CHANNELS);
8877 if (chan_count) {
8878 size = chan_count * sizeof(hdd_ctx->unsafe_channel_list[0]);
8879 unsafe_list = qdf_mem_malloc(size);
Min Liu74a1a502018-10-10 19:59:07 +08008880 if (!unsafe_list)
Liangwei Dong6e1a2092017-08-30 16:29:06 +08008881 return -ENOMEM;
Liangwei Dong6e1a2092017-08-30 16:29:06 +08008882 qdf_mem_copy(unsafe_list, hdd_ctx->unsafe_channel_list, size);
8883 } else {
8884 unsafe_list = NULL;
8885 }
8886
8887 *local_unsafe_list = unsafe_list;
8888 *local_unsafe_list_count = chan_count;
8889
8890 return 0;
8891}
8892
8893bool hdd_local_unsafe_channel_updated(struct hdd_context *hdd_ctx,
8894 uint16_t *local_unsafe_list, uint16_t local_unsafe_list_count)
8895{
8896 int i, j;
8897
8898 if (local_unsafe_list_count != hdd_ctx->unsafe_channel_count)
8899 return true;
8900 if (local_unsafe_list_count == 0)
8901 return false;
8902 for (i = 0; i < local_unsafe_list_count; i++) {
8903 for (j = 0; j < local_unsafe_list_count; j++)
8904 if (local_unsafe_list[i] ==
8905 hdd_ctx->unsafe_channel_list[j])
8906 break;
8907 if (j >= local_unsafe_list_count)
8908 break;
8909 }
8910 if (i >= local_unsafe_list_count) {
8911 hdd_info("unsafe chan list same");
8912 return false;
8913 }
8914
8915 return true;
8916}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008917#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008918static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008919{
8920}
Dustin Brown676a2322017-08-15 13:16:13 -07008921
Jeff Johnson9d295242017-08-29 14:39:48 -07008922static inline void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008923 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07008924{
8925 hdd_debug("Channel avoidance is not enabled; Abort SAP restart");
8926}
Yuanyuan Liu13738502016-04-06 17:41:37 -07008927#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008928
8929/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08008930 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
8931 * user space
8932 * @frame_ind: Management frame data to be informed.
8933 *
8934 * This function is used to indicate management frame to
8935 * user space
8936 *
8937 * Return: None
8938 *
8939 */
8940void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
8941{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008942 struct hdd_context *hdd_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07008943 struct hdd_adapter *adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008944 int i;
Pragaspathi Thilagaraj28ffc042018-07-18 15:19:36 +05308945 struct ieee80211_mgmt *mgmt =
8946 (struct ieee80211_mgmt *)frame_ind->frameBuf;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008947
Dustin Browne7e71d32018-05-11 16:00:08 -07008948 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
8949 if (wlan_hdd_validate_context(hdd_ctx))
Rajeev Kumard004abc2016-02-17 12:09:56 -08008950 return;
8951
Pragaspathi Thilagaraj28ffc042018-07-18 15:19:36 +05308952 if (frame_ind->frame_len < ieee80211_hdrlen(mgmt->frame_control)) {
8953 hdd_err(" Invalid frame length");
8954 return;
8955 }
8956
Rajeev Kumard004abc2016-02-17 12:09:56 -08008957 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
Dustin Brownad06be62019-02-04 14:52:56 -08008958 for (i = 0; i < WLAN_MAX_VDEVS; i++) {
Rajeev Kumard004abc2016-02-17 12:09:56 -08008959 adapter =
Jeff Johnson55d2ab42019-03-06 11:43:49 -08008960 hdd_get_adapter_by_vdev(hdd_ctx, i);
Rajeev Kumard004abc2016-02-17 12:09:56 -08008961 if (adapter)
8962 break;
8963 }
Wu Gaoa0230a62018-01-04 20:56:57 +08008964 } else if (SME_SESSION_ID_BROADCAST == frame_ind->sessionId) {
8965 hdd_for_each_adapter(hdd_ctx, adapter) {
Jeff Johnsond36fa332019-03-18 13:42:25 -07008966 if ((adapter) &&
Wu Gaoa0230a62018-01-04 20:56:57 +08008967 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)) {
8968 __hdd_indicate_mgmt_frame(adapter,
8969 frame_ind->frame_len,
8970 frame_ind->frameBuf,
8971 frame_ind->frameType,
8972 frame_ind->rxChan,
Srinivas Dasariea1c1332019-02-18 12:43:23 +05308973 frame_ind->rxRssi,
8974 frame_ind->rx_flags);
Wu Gaoa0230a62018-01-04 20:56:57 +08008975 }
8976 }
8977 adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008978 } else {
Jeff Johnson55d2ab42019-03-06 11:43:49 -08008979 adapter = hdd_get_adapter_by_vdev(hdd_ctx,
8980 frame_ind->sessionId);
Rajeev Kumard004abc2016-02-17 12:09:56 -08008981 }
8982
Jeff Johnsond36fa332019-03-18 13:42:25 -07008983 if ((adapter) &&
Rajeev Kumard004abc2016-02-17 12:09:56 -08008984 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
8985 __hdd_indicate_mgmt_frame(adapter,
8986 frame_ind->frame_len,
8987 frame_ind->frameBuf,
8988 frame_ind->frameType,
8989 frame_ind->rxChan,
Srinivas Dasariea1c1332019-02-18 12:43:23 +05308990 frame_ind->rxRssi,
8991 frame_ind->rx_flags);
Rajeev Kumard004abc2016-02-17 12:09:56 -08008992}
8993
Kapil Gupta8878ad92017-02-13 11:56:04 +05308994void hdd_acs_response_timeout_handler(void *context)
8995{
8996 struct hdd_external_acs_timer_context *timer_context =
8997 (struct hdd_external_acs_timer_context *)context;
Jeff Johnson9d295242017-08-29 14:39:48 -07008998 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008999 struct hdd_context *hdd_ctx;
Kapil Gupta8878ad92017-02-13 11:56:04 +05309000 uint8_t reason;
9001
Dustin Brown491d54b2018-03-14 12:39:11 -07009002 hdd_enter();
Kapil Gupta8878ad92017-02-13 11:56:04 +05309003 if (!timer_context) {
9004 hdd_err("invlaid timer context");
9005 return;
9006 }
9007 adapter = timer_context->adapter;
9008 reason = timer_context->reason;
9009
9010
9011 if ((!adapter) ||
9012 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
9013 hdd_err("invalid adapter or adapter has invalid magic");
9014 return;
9015 }
9016 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
9017 if (wlan_hdd_validate_context(hdd_ctx))
9018 return;
9019
9020 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
9021 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
9022 else
9023 return;
9024
9025 hdd_err("ACS timeout happened for %s reason %d",
9026 adapter->dev->name, reason);
Jeff Johnson16528362018-06-14 12:34:16 -07009027
Kapil Gupta8878ad92017-02-13 11:56:04 +05309028 switch (reason) {
9029 /* SAP init case */
9030 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
9031 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
9032 false);
9033 wlan_hdd_cfg80211_start_acs(adapter);
9034 break;
9035 /* DFS detected on current channel */
9036 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
9037 wlan_sap_update_next_channel(
9038 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
Jeff Johnson16528362018-06-14 12:34:16 -07009039 sme_update_new_channel_event(hdd_ctx->mac_handle,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08009040 adapter->vdev_id);
Kapil Gupta8878ad92017-02-13 11:56:04 +05309041 break;
9042 /* LTE coex event on current channel */
9043 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
9044 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
9045 break;
9046 default:
9047 hdd_info("invalid reason for timer invoke");
9048
9049 }
9050}
9051
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009052/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009053 * hdd_override_ini_config - Override INI config
9054 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009055 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009056 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009057 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009058 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009059 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009060static void hdd_override_ini_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009061{
Abhinav Kumard4d6eb72018-12-04 20:30:37 +05309062 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009063
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009064 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
gaurank kathpalia97c070b2019-01-07 17:23:06 +05309065 ucfg_scan_cfg_set_dfs_chan_scan_allowed(hdd_ctx->psoc,
9066 enable_dfs_chan_scan);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009067 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009068 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009069 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009070 if (0 == enable_11d || 1 == enable_11d) {
Abhinav Kumard4d6eb72018-12-04 20:30:37 +05309071 status = ucfg_mlme_set_11d_enabled(hdd_ctx->psoc, enable_11d);
9072 if (!QDF_IS_STATUS_SUCCESS(status))
9073 hdd_err("Failed to set 11d_enable flag");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009074 }
Leo Chang11545d62016-10-17 14:53:50 -07009075
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +05309076 if (hdd_ctx->config->action_oui_enable && !ucfg_action_oui_enabled()) {
9077 hdd_ctx->config->action_oui_enable = 0;
Sourav Mohapatra58841062018-11-19 16:33:27 +05309078 hdd_err("Ignore action oui ini, since no action_oui component");
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +05309079 }
Will Huang14b120f2019-01-14 17:26:14 +08009080
9081 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
9082 hdd_override_all_ps(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009083}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009084
Ashish Kumar Dhanotiya12f68212018-09-04 22:00:14 +05309085#ifdef ENABLE_MTRACE_LOG
9086static void hdd_set_mtrace_for_each(struct hdd_context *hdd_ctx)
9087{
9088 uint8_t module_id = 0;
9089 int qdf_print_idx = -1;
9090
9091 qdf_print_idx = qdf_get_pidx();
9092 for (module_id = 0; module_id < QDF_MODULE_ID_MAX; module_id++)
9093 qdf_print_set_category_verbose(
9094 qdf_print_idx,
9095 module_id, QDF_TRACE_LEVEL_TRACE,
9096 hdd_ctx->config->enable_mtrace);
9097}
9098#else
9099static void hdd_set_mtrace_for_each(struct hdd_context *hdd_ctx)
9100{
9101}
9102
9103#endif
9104
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009105/**
Wu Gao8dd9f502019-04-26 15:04:28 +08009106 * hdd_log_level_to_bitmask() - user space log level to host log bitmask
9107 * @user_log_level: user space log level
9108 *
9109 * Convert log level from user space to host log level bitmask.
9110 *
9111 * Return: Bitmask of log levels to be enabled
9112 */
9113static uint32_t hdd_log_level_to_bitmask(enum host_log_level user_log_level)
9114{
9115 QDF_TRACE_LEVEL host_trace_level;
9116 uint32_t bitmask;
9117
9118 switch (user_log_level) {
9119 case HOST_LOG_LEVEL_NONE:
9120 host_trace_level = QDF_TRACE_LEVEL_NONE;
9121 break;
9122 case HOST_LOG_LEVEL_FATAL:
9123 host_trace_level = QDF_TRACE_LEVEL_FATAL;
9124 break;
9125 case HOST_LOG_LEVEL_ERROR:
9126 host_trace_level = QDF_TRACE_LEVEL_ERROR;
9127 break;
9128 case HOST_LOG_LEVEL_WARN:
9129 host_trace_level = QDF_TRACE_LEVEL_WARN;
9130 break;
9131 case HOST_LOG_LEVEL_INFO:
9132 host_trace_level = QDF_TRACE_LEVEL_INFO_LOW;
9133 break;
9134 case HOST_LOG_LEVEL_DEBUG:
9135 host_trace_level = QDF_TRACE_LEVEL_DEBUG;
9136 break;
9137 case HOST_LOG_LEVEL_TRACE:
9138 host_trace_level = QDF_TRACE_LEVEL_TRACE;
9139 break;
9140 default:
9141 host_trace_level = QDF_TRACE_LEVEL_TRACE;
9142 break;
9143 }
9144
9145 bitmask = (1 << (host_trace_level + 1)) - 1;
9146
9147 return bitmask;
9148}
9149
9150/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009151 * hdd_set_trace_level_for_each - Set trace level for each INI config
9152 * @hdd_ctx - HDD context
9153 *
9154 * Set trace level for each module based on INI config.
9155 *
9156 * Return: None
9157 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009158static void hdd_set_trace_level_for_each(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009159{
Wu Gao8dd9f502019-04-26 15:04:28 +08009160 uint8_t host_module_log[QDF_MODULE_ID_MAX * 2];
9161 qdf_size_t host_module_log_num = 0;
9162 QDF_MODULE_ID module_id;
9163 uint32_t bitmask;
9164 uint32_t i;
9165
Wu Gaobc6eaa12018-11-30 14:17:45 +08009166 hdd_qdf_trace_enable(QDF_MODULE_ID_DP, 0x7f);
Wu Gao8dd9f502019-04-26 15:04:28 +08009167
9168 qdf_uint8_array_parse(cfg_get(hdd_ctx->psoc,
9169 CFG_ENABLE_HOST_MODULE_LOG_LEVEL),
9170 host_module_log,
9171 QDF_MODULE_ID_MAX * 2,
9172 &host_module_log_num);
9173
9174 for (i = 0; i + 1 < host_module_log_num; i += 2) {
9175 module_id = host_module_log[i];
9176 bitmask = hdd_log_level_to_bitmask(host_module_log[i + 1]);
9177 if (module_id < QDF_MODULE_ID_MAX &&
9178 module_id >= QDF_MODULE_ID_MIN)
9179 hdd_qdf_trace_enable(module_id, bitmask);
9180 }
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07009181
Ashish Kumar Dhanotiya12f68212018-09-04 22:00:14 +05309182 hdd_set_mtrace_for_each(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009183}
9184
9185/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009186 * hdd_context_init() - Initialize HDD context
9187 * @hdd_ctx: HDD context.
9188 *
9189 * Initialize HDD context along with all the feature specific contexts.
9190 *
9191 * return: 0 on success and errno on failure.
9192 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009193static int hdd_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009194{
9195 int ret;
9196
9197 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
Dustin Brownad06be62019-02-04 14:52:56 -08009198 hdd_ctx->max_intf_count = WLAN_MAX_VDEVS;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009199
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009200 init_completion(&hdd_ctx->mc_sus_event_var);
9201 init_completion(&hdd_ctx->ready_to_suspend);
9202
9203 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009204 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05309205
Dustin Brownbee82832018-07-23 10:10:51 -07009206 qdf_list_create(&hdd_ctx->hdd_adapters, 0);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009207
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009208 ret = hdd_scan_context_init(hdd_ctx);
9209 if (ret)
9210 goto list_destroy;
9211
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009212 hdd_rx_wake_lock_create(hdd_ctx);
9213
9214 ret = hdd_sap_context_init(hdd_ctx);
9215 if (ret)
9216 goto scan_destroy;
9217
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009218 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
9219
9220 hdd_init_offloaded_packets_ctx(hdd_ctx);
9221
9222 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
9223 hdd_ctx->config);
9224 if (ret)
Wu Gao02bd75b2017-10-13 18:34:02 +08009225 goto sap_destroy;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009226
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05309227 qdf_wake_lock_create(&hdd_ctx->monitor_mode_wakelock,
9228 "monitor_mode_wakelock");
9229
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009230 return 0;
9231
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009232sap_destroy:
9233 hdd_sap_context_destroy(hdd_ctx);
9234
9235scan_destroy:
9236 hdd_scan_context_destroy(hdd_ctx);
9237 hdd_rx_wake_lock_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009238list_destroy:
Jeff Johnson19fc8e42017-10-30 19:53:49 -07009239 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08009240
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009241 return ret;
9242}
9243
Dustin Brown4c663222018-10-23 14:19:36 -07009244void hdd_psoc_idle_timer_start(struct hdd_context *hdd_ctx)
9245{
9246 uint32_t timeout_ms = hdd_ctx->config->iface_change_wait_time;
9247 enum wake_lock_reason reason =
9248 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER;
9249
Rajeev Kumar7b7bb3f2018-12-20 12:09:54 -08009250 if (!timeout_ms) {
9251 hdd_info("psoc idle timer is disabled");
9252 return;
9253 }
9254
Dustin Brown4c663222018-10-23 14:19:36 -07009255 hdd_debug("Starting psoc idle timer");
Dustin Brown8d8ab302019-03-05 16:19:36 -08009256 qdf_delayed_work_start(&hdd_ctx->psoc_idle_timeout_work, timeout_ms);
Dustin Brown4c663222018-10-23 14:19:36 -07009257 hdd_prevent_suspend_timeout(timeout_ms, reason);
9258}
9259
9260void hdd_psoc_idle_timer_stop(struct hdd_context *hdd_ctx)
9261{
Dustin Brown8d8ab302019-03-05 16:19:36 -08009262 qdf_delayed_work_stop_sync(&hdd_ctx->psoc_idle_timeout_work);
Dustin Brown4c663222018-10-23 14:19:36 -07009263 hdd_debug("Stopped psoc idle timer");
9264}
9265
Sourav Mohapatra698d6f62019-01-29 14:49:52 +05309266/*
9267 * enum hdd_block_shutdown - Control if driver allows modem shutdown
9268 * @HDD_UNBLOCK_MODEM_SHUTDOWN: Unblock shutdown
9269 * @HDD_BLOCK_MODEM_SHUTDOWN: Block shutdown
9270 *
9271 * On calling pld_block_shutdown API with the given values, modem
9272 * graceful shutdown is blocked/unblocked.
9273 */
9274enum hdd_block_shutdown {
9275 HDD_UNBLOCK_MODEM_SHUTDOWN,
9276 HDD_BLOCK_MODEM_SHUTDOWN,
9277};
9278
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009279/**
Rajeev Kumar473f9af2019-04-05 14:25:56 -07009280 * __hdd_psoc_idle_shutdown() - perform an idle shutdown on the given psoc
Dustin Brown3ecc8782018-09-19 16:37:13 -07009281 * @hdd_ctx: the hdd context which should be shutdown
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309282 *
Dustin Brown3ecc8782018-09-19 16:37:13 -07009283 * When no interfaces are "up" on a psoc, an idle shutdown timer is started.
9284 * If no interfaces are brought up before the timer expires, we do an
9285 * "idle shutdown," cutting power to the physical SoC to save power. This is
9286 * done completely transparently from the perspective of userspace.
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309287 *
Dustin Brown3ecc8782018-09-19 16:37:13 -07009288 * Return: None
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309289 */
Rajeev Kumar473f9af2019-04-05 14:25:56 -07009290static int __hdd_psoc_idle_shutdown(struct hdd_context *hdd_ctx)
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309291{
Dustin Brown363b4792019-02-05 16:11:55 -08009292 struct osif_psoc_sync *psoc_sync;
Dustin Browncfcb5762019-01-31 15:43:45 -08009293 int errno;
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309294
Dustin Brown491d54b2018-03-14 12:39:11 -07009295 hdd_enter();
Dustin Brown3ecc8782018-09-19 16:37:13 -07009296
Dustin Brown363b4792019-02-05 16:11:55 -08009297 errno = osif_psoc_sync_trans_start(hdd_ctx->parent_dev, &psoc_sync);
Dustin Browncfcb5762019-01-31 15:43:45 -08009298 if (errno) {
9299 hdd_info("psoc busy, abort idle shutdown; errno:%d", errno);
9300 goto exit;
Dustin Brown3ecc8782018-09-19 16:37:13 -07009301 }
Sourav Mohapatra698d6f62019-01-29 14:49:52 +05309302 /* Block the modem graceful shutdown till stop modules is completed */
9303 pld_block_shutdown(hdd_ctx->parent_dev, HDD_BLOCK_MODEM_SHUTDOWN);
Dustin Brown3ecc8782018-09-19 16:37:13 -07009304
Dustin Brown363b4792019-02-05 16:11:55 -08009305 osif_psoc_sync_wait_for_ops(psoc_sync);
Dustin Browncfcb5762019-01-31 15:43:45 -08009306
Dustin Brown3ecc8782018-09-19 16:37:13 -07009307 QDF_BUG(!hdd_wlan_stop_modules(hdd_ctx, false));
9308
Dustin Brown363b4792019-02-05 16:11:55 -08009309 osif_psoc_sync_trans_stop(psoc_sync);
Dustin Brown3ecc8782018-09-19 16:37:13 -07009310
Sourav Mohapatra698d6f62019-01-29 14:49:52 +05309311 pld_block_shutdown(hdd_ctx->parent_dev, HDD_UNBLOCK_MODEM_SHUTDOWN);
9312
Dustin Browncfcb5762019-01-31 15:43:45 -08009313exit:
Dustin Browne74003f2018-03-14 12:51:58 -07009314 hdd_exit();
Rajeev Kumar473f9af2019-04-05 14:25:56 -07009315 return errno;
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309316}
9317
Rajeev Kumar588a2542019-04-08 10:57:19 -07009318static int __hdd_mode_change_psoc_idle_shutdown(struct hdd_context *hdd_ctx)
9319{
9320 is_mode_change_psoc_idle_shutdown = false;
9321 return hdd_wlan_stop_modules(hdd_ctx, true);
9322}
9323
Rajeev Kumar473f9af2019-04-05 14:25:56 -07009324int hdd_psoc_idle_shutdown(struct device *dev)
9325{
9326 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
9327
Rajeev Kumard62104a2019-05-31 12:04:27 -07009328 if (!hdd_ctx) {
9329 hdd_err_rl("hdd ctx is null");
9330 return -EINVAL;
9331 }
9332
Rajeev Kumar588a2542019-04-08 10:57:19 -07009333 if (is_mode_change_psoc_idle_shutdown)
9334 return __hdd_mode_change_psoc_idle_shutdown(hdd_ctx);
9335 else
9336 return __hdd_psoc_idle_shutdown(hdd_ctx);
Rajeev Kumar473f9af2019-04-05 14:25:56 -07009337}
9338
9339static int __hdd_psoc_idle_restart(struct hdd_context *hdd_ctx)
9340{
9341 return hdd_wlan_start_modules(hdd_ctx, false);
9342}
9343
9344int hdd_psoc_idle_restart(struct device *dev)
9345{
9346 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
9347
Rajeev Kumard62104a2019-05-31 12:04:27 -07009348 if (!hdd_ctx) {
9349 hdd_err_rl("hdd ctx is null");
9350 return -EINVAL;
9351 }
9352
Rajeev Kumar473f9af2019-04-05 14:25:56 -07009353 return __hdd_psoc_idle_restart(hdd_ctx);
9354}
9355
9356int hdd_trigger_psoc_idle_restart(struct hdd_context *hdd_ctx)
Dustin Brown3ecc8782018-09-19 16:37:13 -07009357{
Dustin Brown693b5352019-01-17 10:00:31 -08009358 QDF_BUG(rtnl_is_locked());
Dustin Brown3ecc8782018-09-19 16:37:13 -07009359
Rajeev Kumar473f9af2019-04-05 14:25:56 -07009360 if (hdd_ctx->driver_status == DRIVER_MODULES_ENABLED) {
9361 hdd_psoc_idle_timer_stop(hdd_ctx);
9362 hdd_info("Driver modules already Enabled");
9363 return 0;
9364 }
9365
9366 pld_idle_restart(hdd_ctx->parent_dev, hdd_psoc_idle_restart);
9367
9368 return 0;
Dustin Brown3ecc8782018-09-19 16:37:13 -07009369}
9370
9371/**
9372 * hdd_psoc_idle_timeout_callback() - Handler for psoc idle timeout
9373 * @priv: pointer to hdd context
9374 *
9375 * Return: None
9376 */
9377static void hdd_psoc_idle_timeout_callback(void *priv)
9378{
9379 struct hdd_context *hdd_ctx = priv;
9380
9381 if (wlan_hdd_validate_context(hdd_ctx))
9382 return;
9383
Rajeev Kumar473f9af2019-04-05 14:25:56 -07009384 hdd_info("Psoc idle timeout elapsed; starting psoc shutdown");
9385
9386 pld_idle_shutdown(hdd_ctx->parent_dev, hdd_psoc_idle_shutdown);
Dustin Brown3ecc8782018-09-19 16:37:13 -07009387}
9388
Nirav Shaheb017be2018-02-15 11:20:58 +05309389#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
9390static void hdd_set_wlan_logging(struct hdd_context *hdd_ctx)
9391{
9392 wlan_logging_set_log_to_console(hdd_ctx->config->
9393 wlan_logging_to_console);
9394 wlan_logging_set_active(hdd_ctx->config->wlan_logging_enable);
9395}
9396#else
9397static void hdd_set_wlan_logging(struct hdd_context *hdd_ctx)
9398{ }
9399#endif
9400
Dundi Raviteja8e338282018-09-25 17:16:04 +05309401#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
9402static void hdd_init_wlan_logging_params(struct hdd_config *config,
9403 struct wlan_objmgr_psoc *psoc)
9404{
9405 config->wlan_logging_enable = cfg_get(psoc, CFG_WLAN_LOGGING_SUPPORT);
9406
9407 config->wlan_logging_to_console =
9408 cfg_get(psoc, CFG_WLAN_LOGGING_CONSOLE_SUPPORT);
9409}
9410#else
9411static void hdd_init_wlan_logging_params(struct hdd_config *config,
9412 struct wlan_objmgr_psoc *psoc)
9413{
9414}
9415#endif
9416
9417#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
9418static void hdd_init_wlan_auto_shutdown(struct hdd_config *config,
9419 struct wlan_objmgr_psoc *psoc)
9420{
9421 config->wlan_auto_shutdown = cfg_get(psoc, CFG_WLAN_AUTO_SHUTDOWN);
9422}
9423#else
9424static void hdd_init_wlan_auto_shutdown(struct hdd_config *config,
9425 struct wlan_objmgr_psoc *psoc)
9426{
9427}
9428#endif
9429
9430#ifndef REMOVE_PKT_LOG
9431static void hdd_init_packet_log(struct hdd_config *config,
9432 struct wlan_objmgr_psoc *psoc)
9433{
9434 config->enable_packet_log = cfg_get(psoc, CFG_ENABLE_PACKET_LOG);
9435}
9436#else
9437static void hdd_init_packet_log(struct hdd_config *config,
9438 struct wlan_objmgr_psoc *psoc)
9439{
9440}
9441#endif
9442
Sandeep Puligilla43b6d1a2018-12-03 09:16:13 -08009443#ifdef ENABLE_MTRACE_LOG
9444static void hdd_init_mtrace_log(struct hdd_config *config,
9445 struct wlan_objmgr_psoc *psoc)
9446{
9447 config->enable_mtrace = cfg_get(psoc, CFG_ENABLE_MTRACE);
9448}
9449#else
9450static void hdd_init_mtrace_log(struct hdd_config *config,
9451 struct wlan_objmgr_psoc *psoc)
9452{
9453}
9454#endif
9455
Sourav Mohapatra0dfe5552018-11-16 11:29:54 +05309456#ifdef FEATURE_RUNTIME_PM
9457static void hdd_init_runtime_pm(struct hdd_config *config,
9458 struct wlan_objmgr_psoc *psoc)
9459{
9460 config->runtime_pm = cfg_get(psoc, CFG_ENABLE_RUNTIME_PM);
9461}
9462#else
9463static void hdd_init_runtime_pm(struct hdd_config *config,
9464 struct wlan_objmgr_psoc *psoc)
9465
9466{
9467}
9468#endif
9469
9470#ifdef FEATURE_WLAN_DYNAMIC_CVM
9471static void hdd_init_vc_mode_cfg_bitmap(struct hdd_config *config,
9472 struct wlan_objmgr_psoc *psoc)
9473{
9474 config->vc_mode_cfg_bitmap = cfg_get(psoc, CFG_VC_MODE_BITMAP);
9475}
9476#else
9477static void hdd_init_vc_mode_cfg_bitmap(struct hdd_config *config,
9478 struct wlan_objmgr_psoc *psoc)
9479{
9480}
9481#endif
9482
gaurank kathpalia566c81b2019-02-20 14:31:45 +05309483#ifdef DHCP_SERVER_OFFLOAD
9484static void
9485hdd_init_dhcp_server_ip(struct hdd_context *hdd_ctx)
9486{
9487 uint8_t num_entries;
9488
9489 hdd_ctx->config->dhcp_server_ip.is_dhcp_server_ip_valid = true;
9490 hdd_string_to_u8_array(cfg_get(hdd_ctx->psoc, CFG_DHCP_SERVER_IP_NAME),
9491 hdd_ctx->config->dhcp_server_ip.dhcp_server_ip,
9492 &num_entries, IPADDR_NUM_ENTRIES);
9493
9494 if (num_entries != IPADDR_NUM_ENTRIES) {
9495 hdd_err("Incorrect IP address (%s) assigned for DHCP server!",
9496 cfg_get(hdd_ctx->psoc, CFG_DHCP_SERVER_IP_NAME));
9497 hdd_config->dhcp_server_ip.is_dhcp_server_ip_valid = false;
9498 }
9499}
9500#else
9501static void
9502hdd_init_dhcp_server_ip(struct hdd_context *hdd_ctx)
9503{
9504}
9505#endif
9506
Dundi Raviteja8e338282018-09-25 17:16:04 +05309507/**
9508 * hdd_cfg_params_init() - Initialize hdd params in hdd_config strucuture
9509 * @hdd_ctx - Pointer to HDD context
9510 *
9511 * Return: None
9512 */
9513static void hdd_cfg_params_init(struct hdd_context *hdd_ctx)
9514{
9515 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
9516 struct hdd_config *config = hdd_ctx->config;
9517
9518 if (!psoc) {
9519 hdd_err("Invalid psoc");
9520 return;
9521 }
9522
9523 if (!config) {
9524 hdd_err("Invalid hdd config");
9525 return;
9526 }
9527
gaurank kathpalia43c52622019-02-11 12:30:05 +05309528 config->dot11Mode = cfg_get(psoc, CFG_HDD_DOT11_MODE);
Dundi Raviteja8e338282018-09-25 17:16:04 +05309529 config->bug_on_reinit_failure = cfg_get(psoc,
9530 CFG_BUG_ON_REINIT_FAILURE);
9531
9532 config->is_ramdump_enabled = cfg_get(psoc,
9533 CFG_ENABLE_RAMDUMP_COLLECTION);
9534
9535 config->iface_change_wait_time = cfg_get(psoc,
9536 CFG_INTERFACE_CHANGE_WAIT);
9537
9538 config->multicast_host_fw_msgs = cfg_get(psoc,
9539 CFG_MULTICAST_HOST_FW_MSGS);
9540
9541 config->private_wext_control = cfg_get(psoc, CFG_PRIVATE_WEXT_CONTROL);
Dundi Raviteja8e338282018-09-25 17:16:04 +05309542 config->enablefwprint = cfg_get(psoc, CFG_ENABLE_FW_UART_PRINT);
9543 config->enable_fw_log = cfg_get(psoc, CFG_ENABLE_FW_LOG);
Vignesh Viswanathana0358ff2018-11-27 09:53:07 +05309544 config->operating_channel = cfg_get(psoc, CFG_OPERATING_CHANNEL);
9545 config->num_vdevs = cfg_get(psoc, CFG_NUM_VDEV_ENABLE);
Vignesh Viswanathana0358ff2018-11-27 09:53:07 +05309546 qdf_str_lcopy(config->enable_concurrent_sta,
9547 cfg_get(psoc, CFG_ENABLE_CONCURRENT_STA),
9548 CFG_CONCURRENT_IFACE_MAX_LEN);
9549 qdf_str_lcopy(config->dbs_scan_selection,
9550 cfg_get(psoc, CFG_DBS_SCAN_SELECTION),
9551 CFG_DBS_SCAN_PARAM_LENGTH);
Sourav Mohapatra0dfe5552018-11-16 11:29:54 +05309552 config->inform_bss_rssi_raw = cfg_get(psoc, CFG_INFORM_BSS_RSSI_RAW);
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05309553 config->mac_provision = cfg_get(psoc, CFG_ENABLE_MAC_PROVISION);
9554 config->provisioned_intf_pool =
9555 cfg_get(psoc, CFG_PROVISION_INTERFACE_POOL);
9556 config->derived_intf_pool = cfg_get(psoc, CFG_DERIVED_INTERFACE_POOL);
Sourav Mohapatra58841062018-11-19 16:33:27 +05309557 config->action_oui_enable = cfg_get(psoc, CFG_ENABLE_ACTION_OUI);
Jeff Johnson15a88ac2019-03-11 14:35:25 -07009558 config->advertise_concurrent_operation =
Sandeep Puligilladc6d68a2019-01-04 16:57:12 -08009559 cfg_get(psoc,
9560 CFG_ADVERTISE_CONCURRENT_OPERATION);
Sourav Mohapatra58841062018-11-19 16:33:27 +05309561 qdf_str_lcopy(config->action_oui_str[0],
9562 cfg_get(psoc, CFG_ACTION_OUI_CONNECT_1X1),
9563 ACTION_OUI_MAX_STR_LEN);
9564 qdf_str_lcopy(config->action_oui_str[1],
9565 cfg_get(psoc, CFG_ACTION_OUI_ITO_EXTENSION),
9566 ACTION_OUI_MAX_STR_LEN);
9567 qdf_str_lcopy(config->action_oui_str[2],
9568 cfg_get(psoc, CFG_ACTION_OUI_CCKM_1X1),
9569 ACTION_OUI_MAX_STR_LEN);
9570 qdf_str_lcopy(config->action_oui_str[3],
9571 cfg_get(psoc, CFG_ACTION_OUI_ITO_ALTERNATE),
9572 ACTION_OUI_MAX_STR_LEN);
9573 qdf_str_lcopy(config->action_oui_str[4],
9574 cfg_get(psoc, CFG_ACTION_OUI_SWITCH_TO_11N_MODE),
9575 ACTION_OUI_MAX_STR_LEN);
9576 qdf_str_lcopy(config->action_oui_str[5],
9577 cfg_get(psoc,
9578 CFG_ACTION_OUI_CONNECT_1X1_WITH_1_CHAIN),
9579 ACTION_OUI_MAX_STR_LEN);
Rajeev Kumar Sirasanagandlad7987f12018-12-08 23:24:04 +05309580 qdf_str_lcopy(config->action_oui_str[6],
9581 cfg_get(psoc,
9582 CFG_ACTION_OUI_DISABLE_AGGRESSIVE_TX),
9583 ACTION_OUI_MAX_STR_LEN);
Yeshwanth Sriram Guntuka22ed8002019-05-07 15:08:09 +05309584 qdf_str_lcopy(config->action_oui_str[ACTION_OUI_FORCE_MAX_NSS],
9585 cfg_get(psoc, CFG_ACTION_OUI_FORCE_MAX_NSS),
9586 ACTION_OUI_MAX_STR_LEN);
Sourav Mohapatra9e014cf2018-12-11 09:39:33 +05309587 config->enable_rtt_support = cfg_get(psoc, CFG_ENABLE_RTT_SUPPORT);
Sandeep Puligillaefeb4a92019-01-08 00:06:51 -08009588 config->is_unit_test_framework_enabled =
9589 cfg_get(psoc, CFG_ENABLE_UNIT_TEST_FRAMEWORK);
Ashish Kumar Dhanotiyad63d6862019-03-14 18:54:10 +05309590 config->disable_channel = cfg_get(psoc, CFG_ENABLE_DISABLE_CHANNEL);
Ashish Kumar Dhanotiya95498182019-04-29 13:59:20 +05309591 config->sar_version = cfg_get(psoc, CFG_SAR_VERSION);
Rajeev Kumar3a7c3402019-05-02 16:02:20 -07009592 config->is_wow_disabled = cfg_get(psoc, CFG_WOW_DISABLE);
Dundi Raviteja8e338282018-09-25 17:16:04 +05309593
Sourav Mohapatra0dfe5552018-11-16 11:29:54 +05309594 hdd_init_vc_mode_cfg_bitmap(config, psoc);
9595 hdd_init_runtime_pm(config, psoc);
Dundi Raviteja8e338282018-09-25 17:16:04 +05309596 hdd_init_wlan_auto_shutdown(config, psoc);
9597 hdd_init_wlan_logging_params(config, psoc);
9598 hdd_init_packet_log(config, psoc);
Sandeep Puligilla43b6d1a2018-12-03 09:16:13 -08009599 hdd_init_mtrace_log(config, psoc);
gaurank kathpalia566c81b2019-02-20 14:31:45 +05309600 hdd_init_dhcp_server_ip(hdd_ctx);
jitiphil869b9f72018-09-25 17:14:01 +05309601 hdd_dp_cfg_update(psoc, hdd_ctx);
Dundi Raviteja8e338282018-09-25 17:16:04 +05309602}
9603
Dustin Brown623e7e32018-09-05 14:27:50 -07009604struct hdd_context *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009605{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309606 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009607 int ret = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009608 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009609
Dustin Brown491d54b2018-03-14 12:39:11 -07009610 hdd_enter();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009611
Dustin Brown92bd8382018-10-31 15:49:46 -07009612 hdd_ctx = hdd_cfg80211_wiphy_alloc();
9613 if (!hdd_ctx) {
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009614 ret = -ENOMEM;
9615 goto err_out;
9616 }
9617
Dustin Brown8d8ab302019-03-05 16:19:36 -08009618 status = qdf_delayed_work_create(&hdd_ctx->psoc_idle_timeout_work,
9619 hdd_psoc_idle_timeout_callback,
9620 hdd_ctx);
9621 if (QDF_IS_STATUS_ERROR(status)) {
9622 ret = qdf_status_to_os_return(status);
9623 goto wiphy_dealloc;
9624 }
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309625
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009626 hdd_ctx->parent_dev = dev;
Jeff Johnson995fd512019-03-06 08:45:10 -08009627 hdd_ctx->last_scan_reject_vdev_id = WLAN_UMAC_VDEV_ID_MAX;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009628
Anurag Chouhan600c3a02016-03-01 10:33:54 +05309629 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Min Liu74a1a502018-10-10 19:59:07 +08009630 if (!hdd_ctx->config) {
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009631 ret = -ENOMEM;
9632 goto err_free_hdd_context;
9633 }
9634
Dustin Brown84f46ea2018-02-15 11:57:36 -08009635 status = cfg_parse(WLAN_INI_FILE);
9636 if (QDF_IS_STATUS_ERROR(status))
9637 hdd_err("Failed to parse cfg %s; status:%d\n",
9638 WLAN_INI_FILE, status);
9639
Dundi Ravitejafb9357a2018-09-25 12:16:03 +05309640 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx, DEFAULT_PSOC_ID);
9641 if (ret) {
Dundi Raviteja8e338282018-09-25 17:16:04 +05309642 QDF_DEBUG_PANIC("Psoc creation fails!");
Dundi Ravitejafb9357a2018-09-25 12:16:03 +05309643 goto err_free_config;
9644 }
9645
Dundi Raviteja8e338282018-09-25 17:16:04 +05309646 hdd_cfg_params_init(hdd_ctx);
9647
Dustin Brown4bbd5462019-03-22 11:18:13 -07009648 /* apply multiplier config, if not already set via module parameter */
9649 if (qdf_timer_get_multiplier() == 1)
9650 qdf_timer_set_multiplier(cfg_get(hdd_ctx->psoc,
9651 CFG_TIMER_MULTIPLIER));
Dustin Browna9a84522019-02-04 12:25:40 -08009652 hdd_debug("set timer multiplier: %u", qdf_timer_get_multiplier());
Dustin Brown7f939932017-05-18 15:02:17 -07009653
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309654 cds_set_fatal_event(cfg_get(hdd_ctx->psoc,
9655 CFG_ENABLE_FATAL_EVENT_TRIGGER));
Abhishek Singh5ea86532016-04-27 14:10:53 +05309656
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009657 hdd_override_ini_config(hdd_ctx);
9658
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009659 ret = hdd_context_init(hdd_ctx);
9660
9661 if (ret)
Dundi Ravitejafb9357a2018-09-25 12:16:03 +05309662 goto err_hdd_objmgr_destroy;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009663
Nirav Shah6aeecf92019-02-13 14:05:03 +05309664 if (hdd_get_conparam() == QDF_GLOBAL_FTM_MODE ||
9665 hdd_get_conparam() == QDF_GLOBAL_EPPING_MODE)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009666 goto skip_multicast_logging;
9667
9668 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
9669
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07009670 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
9671 if (ret)
9672 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05309673
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009674 ret = hdd_init_netlink_services(hdd_ctx);
9675 if (ret)
9676 goto err_deinit_txrx_histogram;
9677
Nirav Shaheb017be2018-02-15 11:20:58 +05309678 hdd_set_wlan_logging(hdd_ctx);
Nirav Shahed34b212016-04-25 10:59:16 +05309679
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009680skip_multicast_logging:
9681 hdd_set_trace_level_for_each(hdd_ctx);
9682
Rajeev Kumar493a31b2017-09-29 14:01:24 -07009683 cds_set_context(QDF_MODULE_ID_HDD, hdd_ctx);
9684
Dustin Browne74003f2018-03-14 12:51:58 -07009685 hdd_exit();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07009686
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009687 return hdd_ctx;
9688
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009689err_deinit_txrx_histogram:
9690 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
9691
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07009692err_deinit_hdd_context:
9693 hdd_context_deinit(hdd_ctx);
9694
Dundi Ravitejafb9357a2018-09-25 12:16:03 +05309695err_hdd_objmgr_destroy:
9696 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
9697
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009698err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05309699 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009700
9701err_free_hdd_context:
Dustin Brown8d8ab302019-03-05 16:19:36 -08009702 qdf_delayed_work_destroy(&hdd_ctx->psoc_idle_timeout_work);
9703
9704wiphy_dealloc:
Rajeev Kumarfa55a692018-01-09 14:12:41 -08009705 wiphy_free(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009706
9707err_out:
9708 return ERR_PTR(ret);
9709}
9710
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009711/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309712 * hdd_start_station_adapter()- Start the Station Adapter
9713 * @adapter: HDD adapter
9714 *
9715 * This function initializes the adapter for the station mode.
9716 *
9717 * Return: 0 on success or errno on failure.
9718 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009719int hdd_start_station_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309720{
9721 QDF_STATUS status;
Krunal Sonib51eec72017-11-20 21:53:01 -08009722 int ret;
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309723
Dustin Brownfdf17c12018-03-14 12:55:34 -07009724 hdd_enter_dev(adapter->dev);
Krunal Sonib51eec72017-11-20 21:53:01 -08009725 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
9726 hdd_err("session is already opened, %d",
Jeff Johnson5a6fc962019-02-04 14:20:25 -08009727 adapter->vdev_id);
Krunal Sonib51eec72017-11-20 21:53:01 -08009728 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
9729 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309730
Krunal Sonib51eec72017-11-20 21:53:01 -08009731 ret = hdd_vdev_create(adapter, hdd_sme_roam_callback, adapter);
9732 if (ret) {
9733 hdd_err("failed to create vdev: %d", ret);
9734 return ret;
9735 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309736 status = hdd_init_station_mode(adapter);
9737
9738 if (QDF_STATUS_SUCCESS != status) {
9739 hdd_err("Error Initializing station mode: %d", status);
9740 return qdf_status_to_os_return(status);
9741 }
9742
Arun Khandavallifae92942016-08-01 13:31:08 +05309743 hdd_register_tx_flow_control(adapter,
9744 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08009745 hdd_tx_resume_cb,
9746 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05309747
Visweswara Tanukub5a61242019-03-26 12:24:13 +05309748 hdd_register_hl_netdev_fc_timer(adapter,
9749 hdd_tx_resume_timer_expired_handler);
9750
Dustin Browne74003f2018-03-14 12:51:58 -07009751 hdd_exit();
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +05309752
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309753 return 0;
9754}
9755
9756/**
9757 * hdd_start_ap_adapter()- Start AP Adapter
9758 * @adapter: HDD adapter
9759 *
9760 * This function initializes the adapter for the AP mode.
9761 *
9762 * Return: 0 on success errno on failure.
9763 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009764int hdd_start_ap_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309765{
9766 QDF_STATUS status;
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009767 bool is_ssr = false;
Krunal Sonib51eec72017-11-20 21:53:01 -08009768 int ret;
Naveen Rawat1af09392018-01-03 17:28:21 -08009769 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Arif Hussainbd5194c2018-11-27 19:01:15 -08009770 uint32_t fine_time_meas_cap = 0;
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309771
Dustin Brown491d54b2018-03-14 12:39:11 -07009772 hdd_enter();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309773
Krunal Sonib51eec72017-11-20 21:53:01 -08009774 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
9775 hdd_err("session is already opened, %d",
Jeff Johnson5a6fc962019-02-04 14:20:25 -08009776 adapter->vdev_id);
Krunal Sonib51eec72017-11-20 21:53:01 -08009777 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
9778 }
9779 /*
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009780 * In SSR case no need to create new sap context.
9781 * Otherwise create sap context first and then create
9782 * vdev as while creating the vdev, driver needs to
9783 * register SAP callback and that callback uses sap context
Krunal Sonib51eec72017-11-20 21:53:01 -08009784 */
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009785 if (adapter->session.ap.sap_context) {
9786 is_ssr = true;
9787 } else if (!hdd_sap_create_ctx(adapter)) {
Krunal Sonib51eec72017-11-20 21:53:01 -08009788 hdd_err("sap creation failed");
9789 return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
9790 }
9791
9792 ret = hdd_vdev_create(adapter, wlansap_roam_callback,
9793 adapter->session.ap.sap_context);
9794 if (ret) {
9795 hdd_err("failed to create vdev, status:%d", ret);
9796 hdd_sap_destroy_ctx(adapter);
9797 return ret;
9798 }
Naveen Rawat1af09392018-01-03 17:28:21 -08009799
Arif Hussainbd5194c2018-11-27 19:01:15 -08009800 if (adapter->device_mode == QDF_SAP_MODE) {
9801 ucfg_mlme_get_fine_time_meas_cap(hdd_ctx->psoc,
9802 &fine_time_meas_cap);
Jeff Johnson5a6fc962019-02-04 14:20:25 -08009803 sme_cli_set_command(adapter->vdev_id,
Naveen Rawat1af09392018-01-03 17:28:21 -08009804 WMI_VDEV_PARAM_ENABLE_DISABLE_RTT_RESPONDER_ROLE,
Arif Hussainbd5194c2018-11-27 19:01:15 -08009805 (bool)(fine_time_meas_cap & WMI_FW_AP_RTT_RESPR),
Naveen Rawat1af09392018-01-03 17:28:21 -08009806 VDEV_CMD);
Arif Hussainbd5194c2018-11-27 19:01:15 -08009807 }
Naveen Rawat1af09392018-01-03 17:28:21 -08009808
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009809 status = hdd_init_ap_mode(adapter, is_ssr);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309810
9811 if (QDF_STATUS_SUCCESS != status) {
9812 hdd_err("Error Initializing the AP mode: %d", status);
9813 return qdf_status_to_os_return(status);
9814 }
9815
Arun Khandavallifae92942016-08-01 13:31:08 +05309816 hdd_register_tx_flow_control(adapter,
9817 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08009818 hdd_softap_tx_resume_cb,
9819 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05309820
Visweswara Tanukub5a61242019-03-26 12:24:13 +05309821 hdd_register_hl_netdev_fc_timer(adapter,
9822 hdd_tx_resume_timer_expired_handler);
9823
Dustin Browne74003f2018-03-14 12:51:58 -07009824 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309825 return 0;
9826}
9827
hangtianb9c91362019-06-07 10:39:38 +08009828#if defined(QCA_LL_TX_FLOW_CONTROL_V2) || defined(QCA_LL_PDEV_TX_FLOW_CONTROL)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309829/**
9830 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
9831 * @cds_cfg: CDS Configuration
9832 * @hdd_ctx: Pointer to hdd context
9833 *
9834 * Return: none
9835 */
9836static inline void hdd_txrx_populate_cds_config(struct cds_config_info
9837 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009838 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309839{
9840 cds_cfg->tx_flow_stop_queue_th =
jitiphil47c3d9a2018-11-08 18:30:55 +05309841 cfg_get(hdd_ctx->psoc, CFG_DP_TX_FLOW_STOP_QUEUE_TH);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309842 cds_cfg->tx_flow_start_queue_offset =
jitiphil47c3d9a2018-11-08 18:30:55 +05309843 cfg_get(hdd_ctx->psoc, CFG_DP_TX_FLOW_START_QUEUE_OFFSET);
Mohit Khanna70322002018-05-15 19:21:32 -07009844 /* configuration for DP RX Threads */
9845 cds_cfg->enable_dp_rx_threads = hdd_ctx->enable_dp_rx_threads;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309846}
hangtianb9c91362019-06-07 10:39:38 +08009847#else
9848static inline void hdd_txrx_populate_cds_config(struct cds_config_info
9849 *cds_cfg,
9850 struct hdd_context *hdd_ctx)
9851{
9852}
9853#endif
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309854
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309855/**
9856 * hdd_update_cds_config() - API to update cds configuration parameters
9857 * @hdd_ctx: HDD Context
9858 *
9859 * Return: 0 for Success, errno on failure
9860 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009861static int hdd_update_cds_config(struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309862{
9863 struct cds_config_info *cds_cfg;
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05309864 int value;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05309865 uint8_t band_capability;
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309866 uint8_t ito_repeat_count;
Vignesh Viswanathana851d752018-10-03 19:44:38 +05309867 bool crash_inject;
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309868 bool self_recovery;
9869 bool fw_timeout_crash;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05309870 QDF_STATUS status;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309871
Min Liu74a1a502018-10-10 19:59:07 +08009872 cds_cfg = qdf_mem_malloc(sizeof(*cds_cfg));
9873 if (!cds_cfg)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309874 return -ENOMEM;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309875
Srinivas Girigowda35b00312017-06-27 21:52:03 -07009876 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Bala Venkatesh46e29032018-11-14 18:24:55 +05309877 ucfg_mlme_get_sap_max_modulated_dtim(hdd_ctx->psoc,
9878 &cds_cfg->sta_maxlimod_dtim);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309879
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309880 status = ucfg_mlme_get_crash_inject(hdd_ctx->psoc, &crash_inject);
Vignesh Viswanathana851d752018-10-03 19:44:38 +05309881 if (QDF_IS_STATUS_ERROR(status)) {
9882 hdd_err("Failed to get crash inject ini config");
9883 goto exit;
9884 }
9885
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309886 status = ucfg_mlme_get_self_recovery(hdd_ctx->psoc, &self_recovery);
9887 if (QDF_IS_STATUS_ERROR(status)) {
9888 hdd_err("Failed to get self recovery ini config");
9889 goto exit;
9890 }
9891
9892 status = ucfg_mlme_get_fw_timeout_crash(hdd_ctx->psoc,
9893 &fw_timeout_crash);
9894 if (QDF_IS_STATUS_ERROR(status)) {
9895 hdd_err("Failed to get fw timeout crash ini config");
9896 goto exit;
9897 }
9898
9899 status = ucfg_mlme_get_ito_repeat_count(hdd_ctx->psoc,
9900 &ito_repeat_count);
9901 if (QDF_IS_STATUS_ERROR(status)) {
9902 hdd_err("Failed to get ITO repeat count ini config");
9903 goto exit;
9904 }
9905
Vignesh Viswanathana851d752018-10-03 19:44:38 +05309906 cds_cfg->force_target_assert_enabled = crash_inject;
SaidiReddy Yenugacc733af2016-11-09 17:45:42 +05309907
Dustin Brown05d81302018-09-11 16:49:22 -07009908 ucfg_mlme_get_sap_max_offload_peers(hdd_ctx->psoc, &value);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05309909 cds_cfg->ap_maxoffload_peers = value;
Dustin Brown05d81302018-09-11 16:49:22 -07009910 ucfg_mlme_get_sap_max_offload_reorder_buffs(hdd_ctx->psoc,
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05309911 &value);
9912 cds_cfg->ap_maxoffload_reorderbuffs = value;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309913
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309914 cds_cfg->reorder_offload =
jitiphil47c3d9a2018-11-08 18:30:55 +05309915 cfg_get(hdd_ctx->psoc, CFG_DP_REORDER_OFFLOAD_SUPPORT);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309916
9917 /* IPA micro controller data path offload resource config item */
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05309918 cds_cfg->uc_offload_enabled = ucfg_ipa_uc_is_enabled();
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309919
Jeff Johnsone2ba3cd2017-10-30 20:02:09 -07009920 cds_cfg->enable_rxthread = hdd_ctx->enable_rxthread;
Dustin Brown05d81302018-09-11 16:49:22 -07009921 ucfg_mlme_get_sap_max_peers(hdd_ctx->psoc, &value);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05309922 cds_cfg->max_station = value;
Naveen Rawat64e477e2016-05-20 10:34:56 -07009923 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Orhan K AKYILDIZ30e8cbc2017-08-11 18:00:28 -07009924 cds_cfg->max_msdus_per_rxinorderind =
jitiphil8e15ea62018-11-16 18:05:34 +05309925 cfg_get(hdd_ctx->psoc, CFG_DP_MAX_MSDUS_PER_RXIND);
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309926 cds_cfg->self_recovery_enabled = self_recovery;
9927 cds_cfg->fw_timeout_crash = fw_timeout_crash;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309928
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309929 cds_cfg->ito_repeat_count = ito_repeat_count;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05309930
9931 status = ucfg_mlme_get_band_capability(hdd_ctx->psoc, &band_capability);
9932 if (QDF_IS_STATUS_ERROR(status))
9933 goto exit;
9934
9935 cds_cfg->bandcapability = band_capability;
Rachit Kankane0106e382018-05-16 18:59:28 +05309936 cds_cfg->num_vdevs = hdd_ctx->config->num_vdevs;
Jiani Liu6d3b6a12019-05-08 15:15:06 +08009937 cds_cfg->enable_tx_compl_tsf64 =
9938 hdd_tsf_is_tsf64_tx_set(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309939 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07009940 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309941 cds_init_ini_config(cds_cfg);
9942 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05309943
9944exit:
9945 qdf_mem_free(cds_cfg);
9946 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309947}
9948
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009949/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009950 * hdd_update_user_config() - API to update user configuration
9951 * parameters to obj mgr which are used by multiple components
9952 * @hdd_ctx: HDD Context
9953 *
9954 * Return: 0 for Success, errno on failure
9955 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009956static int hdd_update_user_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009957{
9958 struct wlan_objmgr_psoc_user_config *user_config;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05309959 uint8_t band_capability;
9960 QDF_STATUS status;
Abhinav Kumard4d6eb72018-12-04 20:30:37 +05309961 bool value = false;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05309962
9963 status = ucfg_mlme_get_band_capability(hdd_ctx->psoc, &band_capability);
9964 if (QDF_IS_STATUS_ERROR(status))
9965 return -EIO;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009966
9967 user_config = qdf_mem_malloc(sizeof(*user_config));
Min Liu74a1a502018-10-10 19:59:07 +08009968 if (!user_config)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009969 return -ENOMEM;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009970
9971 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
Abhinav Kumard4d6eb72018-12-04 20:30:37 +05309972 status = ucfg_mlme_is_11d_enabled(hdd_ctx->psoc, &value);
9973 if (!QDF_IS_STATUS_SUCCESS(status))
9974 hdd_err("Invalid 11d_enable flag");
9975 user_config->is_11d_support_enabled = value;
9976
9977 value = false;
9978 status = ucfg_mlme_is_11h_enabled(hdd_ctx->psoc, &value);
9979 if (!QDF_IS_STATUS_SUCCESS(status))
9980 hdd_err("Invalid 11h_enable flag");
9981 user_config->is_11h_support_enabled = value;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05309982 user_config->band_capability = band_capability;
Dustin Brown1dbefe62018-09-11 16:32:03 -07009983 wlan_objmgr_psoc_set_user_config(hdd_ctx->psoc, user_config);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009984
9985 qdf_mem_free(user_config);
9986 return 0;
9987}
9988
9989/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009990 * hdd_init_thermal_info - Initialize thermal level
9991 * @hdd_ctx: HDD context
9992 *
9993 * Initialize thermal level at SME layer and set the thermal level callback
9994 * which would be called when a configured thermal threshold is hit.
9995 *
9996 * Return: 0 on success and errno on failure
9997 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009998static int hdd_init_thermal_info(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009999{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010000 QDF_STATUS status;
Manikandan Mohan9045e2e2018-11-26 16:44:19 -080010001 mac_handle_t mac_handle = hdd_ctx->mac_handle;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -080010002
Manikandan Mohan9045e2e2018-11-26 16:44:19 -080010003 status = sme_init_thermal_info(mac_handle);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -080010004
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010005 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +053010006 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -080010007
Jeff Johnson16528362018-06-14 12:34:16 -070010008 sme_add_set_thermal_level_callback(mac_handle,
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -080010009 hdd_set_thermal_level_cb);
10010
10011 return 0;
10012
10013}
10014
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010015#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
10016/**
10017 * hdd_hold_rtnl_lock - Hold RTNL lock
10018 *
10019 * Hold RTNL lock
10020 *
10021 * Return: True if held and false otherwise
10022 */
10023static inline bool hdd_hold_rtnl_lock(void)
10024{
10025 rtnl_lock();
10026 return true;
10027}
10028
10029/**
10030 * hdd_release_rtnl_lock - Release RTNL lock
10031 *
10032 * Release RTNL lock
10033 *
10034 * Return: None
10035 */
10036static inline void hdd_release_rtnl_lock(void)
10037{
10038 rtnl_unlock();
10039}
10040#else
10041static inline bool hdd_hold_rtnl_lock(void) { return false; }
10042static inline void hdd_release_rtnl_lock(void) { }
10043#endif
10044
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -080010045#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010046
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010047/* MAX iwpriv command support */
10048#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +053010049#define PKTLOG_CLEAR_BUFF 4
Venkata Sharath Chandra Manchala27e44902019-01-28 11:29:18 -080010050/* Set Maximum pktlog file size to 64MB */
10051#define MAX_PKTLOG_SIZE 64
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010052
10053/**
10054 * hdd_pktlog_set_buff_size() - set pktlog buffer size
10055 * @hdd_ctx: hdd context
10056 * @set_value2: pktlog buffer size value
10057 *
10058 *
10059 * Return: 0 for success or error.
10060 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010061static int hdd_pktlog_set_buff_size(struct hdd_context *hdd_ctx, int set_value2)
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010062{
10063 struct sir_wifi_start_log start_log = { 0 };
10064 QDF_STATUS status;
10065
10066 start_log.ring_id = RING_ID_PER_PACKET_STATS;
10067 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
10068 start_log.ini_triggered = cds_is_packet_log_enabled();
10069 start_log.user_triggered = 1;
10070 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +053010071 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010072
Jeff Johnson16528362018-06-14 12:34:16 -070010073 status = sme_wifi_start_logger(hdd_ctx->mac_handle, start_log);
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010074 if (!QDF_IS_STATUS_SUCCESS(status)) {
10075 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -070010076 hdd_exit();
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010077 return -EINVAL;
10078 }
10079
10080 return 0;
10081}
10082
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010083/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +053010084 * hdd_pktlog_clear_buff() - clear pktlog buffer
10085 * @hdd_ctx: hdd context
10086 *
10087 * Return: 0 for success or error.
10088 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010089static int hdd_pktlog_clear_buff(struct hdd_context *hdd_ctx)
Poddar, Siddarthab99a272017-04-10 12:53:26 +053010090{
10091 struct sir_wifi_start_log start_log;
10092 QDF_STATUS status;
10093
10094 start_log.ring_id = RING_ID_PER_PACKET_STATS;
10095 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
10096 start_log.ini_triggered = cds_is_packet_log_enabled();
10097 start_log.user_triggered = 1;
10098 start_log.size = 0;
10099 start_log.is_pktlog_buff_clear = true;
10100
Jeff Johnson16528362018-06-14 12:34:16 -070010101 status = sme_wifi_start_logger(hdd_ctx->mac_handle, start_log);
Poddar, Siddarthab99a272017-04-10 12:53:26 +053010102 if (!QDF_IS_STATUS_SUCCESS(status)) {
10103 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -070010104 hdd_exit();
Poddar, Siddarthab99a272017-04-10 12:53:26 +053010105 return -EINVAL;
10106 }
10107
10108 return 0;
10109}
10110
10111
10112/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010113 * hdd_process_pktlog_command() - process pktlog command
10114 * @hdd_ctx: hdd context
10115 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010116 * @set_value2: pktlog buffer size value
10117 *
10118 * This function process pktlog command.
10119 * set_value2 only matters when set_value is 3 (set buff size)
10120 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010121 *
10122 * Return: 0 for success or error.
10123 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010124int hdd_process_pktlog_command(struct hdd_context *hdd_ctx, uint32_t set_value,
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010125 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010126{
10127 int ret;
10128 bool enable;
10129 uint8_t user_triggered = 0;
10130
10131 ret = wlan_hdd_validate_context(hdd_ctx);
10132 if (0 != ret)
10133 return ret;
10134
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010135 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010136
Poddar, Siddarthab99a272017-04-10 12:53:26 +053010137 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010138 hdd_err("invalid pktlog value %d", set_value);
10139 return -EINVAL;
10140 }
10141
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010142 if (set_value == PKTLOG_SET_BUFF_SIZE) {
10143 if (set_value2 <= 0) {
10144 hdd_err("invalid pktlog size %d", set_value2);
10145 return -EINVAL;
10146 } else if (set_value2 > MAX_PKTLOG_SIZE) {
Venkata Sharath Chandra Manchala27e44902019-01-28 11:29:18 -080010147 hdd_err_rl("Pktlog size is large. max value is %uMB.",
10148 MAX_PKTLOG_SIZE);
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010149 return -EINVAL;
10150 }
10151 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +053010152 } else if (set_value == PKTLOG_CLEAR_BUFF) {
10153 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010154 }
10155
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010156 /*
10157 * set_value = 0 then disable packetlog
10158 * set_value = 1 enable packetlog forcefully
10159 * set_vlaue = 2 then disable packetlog if disabled through ini or
10160 * enable packetlog with AUTO type.
10161 */
10162 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
10163 true : false;
10164
10165 if (1 == set_value) {
10166 enable = true;
10167 user_triggered = 1;
10168 }
10169
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010170 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010171}
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070010172
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -080010173/**
10174 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
10175 * @hdd_ctx: HDD context
10176 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010177 * @user_triggered: triggered through iwpriv
10178 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -080010179 *
10180 * Return: 0 on success; error number otherwise
10181 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010182int hdd_pktlog_enable_disable(struct hdd_context *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010183 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -080010184{
10185 struct sir_wifi_start_log start_log;
10186 QDF_STATUS status;
10187
10188 start_log.ring_id = RING_ID_PER_PACKET_STATS;
10189 start_log.verbose_level =
10190 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010191 start_log.ini_triggered = cds_is_packet_log_enabled();
10192 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010193 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +053010194 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +053010195 /*
10196 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
10197 * commands. Host uses this flag to decide whether to send pktlog
10198 * disable command to fw without sending pktlog enable command
10199 * previously. For eg, If vendor sends pktlog disable command without
10200 * sending pktlog enable command, then host discards the packet
10201 * but for iwpriv command, host will send it to fw.
10202 */
10203 start_log.is_iwpriv_command = 1;
Jeff Johnson16528362018-06-14 12:34:16 -070010204 status = sme_wifi_start_logger(hdd_ctx->mac_handle, start_log);
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -080010205 if (!QDF_IS_STATUS_SUCCESS(status)) {
10206 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -070010207 hdd_exit();
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -080010208 return -EINVAL;
10209 }
10210
Poddar, Siddarth61fbc932017-12-19 14:27:55 +053010211 if (enable == true)
10212 hdd_ctx->is_pktlog_enabled = 1;
10213 else
10214 hdd_ctx->is_pktlog_enabled = 0;
10215
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -080010216 return 0;
10217}
10218#endif /* REMOVE_PKT_LOG */
10219
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010220void hdd_free_mac_address_lists(struct hdd_context *hdd_ctx)
10221{
10222 hdd_debug("Resetting MAC address lists");
hangtian127c9532019-01-12 13:29:07 +080010223 qdf_mem_zero(hdd_ctx->provisioned_mac_addr,
10224 sizeof(hdd_ctx->provisioned_mac_addr));
10225 qdf_mem_zero(hdd_ctx->derived_mac_addr,
10226 sizeof(hdd_ctx->derived_mac_addr));
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010227 hdd_ctx->num_provisioned_addr = 0;
10228 hdd_ctx->num_derived_addr = 0;
10229 hdd_ctx->provisioned_intf_addr_mask = 0;
10230 hdd_ctx->derived_intf_addr_mask = 0;
10231}
10232
Komal Seelam92fff912016-03-24 11:51:41 +053010233/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -080010234 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
10235 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +053010236 * @dev: Device Pointer
10237 * @num: Number of Valid Mac address
10238 *
10239 * Return: Pointer to MAC address buffer
10240 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -080010241static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
10242 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +053010243{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -080010244 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +053010245}
Komal Seelam92fff912016-03-24 11:51:41 +053010246
10247/**
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010248 * hdd_get_platform_wlan_derived_mac_buff() - API to query platform driver
10249 * for derived MAC address
10250 * @dev: Device Pointer
10251 * @num: Number of Valid Mac address
10252 *
10253 * Return: Pointer to MAC address buffer
10254 */
10255static uint8_t *hdd_get_platform_wlan_derived_mac_buff(struct device *dev,
10256 uint32_t *num)
10257{
10258 return pld_get_wlan_derived_mac_address(dev, num);
10259}
10260
10261/**
Komal Seelam92fff912016-03-24 11:51:41 +053010262 * hdd_populate_random_mac_addr() - API to populate random mac addresses
10263 * @hdd_ctx: HDD Context
10264 * @num: Number of random mac addresses needed
10265 *
10266 * Generate random addresses using bit manipulation on the base mac address
10267 *
10268 * Return: None
10269 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010270void hdd_populate_random_mac_addr(struct hdd_context *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +053010271{
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010272 uint32_t idx = hdd_ctx->num_derived_addr;
Komal Seelam92fff912016-03-24 11:51:41 +053010273 uint32_t iter;
Komal Seelam92fff912016-03-24 11:51:41 +053010274 uint8_t *buf = NULL;
10275 uint8_t macaddr_b3, tmp_br3;
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010276 /*
10277 * Consider first provisioned mac address as source address to derive
10278 * remaining addresses
10279 */
Komal Seelam92fff912016-03-24 11:51:41 +053010280
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010281 uint8_t *src = hdd_ctx->provisioned_mac_addr[0].bytes;
10282
10283 for (iter = 0; iter < num; ++iter, ++idx) {
10284 buf = hdd_ctx->derived_mac_addr[idx].bytes;
Komal Seelam92fff912016-03-24 11:51:41 +053010285 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
10286 macaddr_b3 = buf[3];
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010287 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + idx) &
Komal Seelam92fff912016-03-24 11:51:41 +053010288 INTF_MACADDR_MASK;
10289 macaddr_b3 += tmp_br3;
10290 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
10291 buf[0] |= 0x02;
10292 buf[3] = macaddr_b3;
Srinivas Girigowdacb7b8b82019-04-10 14:27:47 -070010293 hdd_debug(QDF_MAC_ADDR_STR, QDF_MAC_ADDR_ARRAY(buf));
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010294 hdd_ctx->num_derived_addr++;
Komal Seelam92fff912016-03-24 11:51:41 +053010295 }
10296}
10297
10298/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -080010299 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +053010300 * @hdd_ctx: HDD Context
10301 *
10302 * API to get mac addresses from platform driver and update the driver
10303 * structures and configure FW with the base mac address.
10304 * Return: int
10305 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010306static int hdd_platform_wlan_mac(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +053010307{
10308 uint32_t no_of_mac_addr, iter;
10309 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
10310 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
10311 uint8_t *addr, *buf;
10312 struct device *dev = hdd_ctx->parent_dev;
Komal Seelam92fff912016-03-24 11:51:41 +053010313 tSirMacAddr mac_addr;
10314 QDF_STATUS status;
10315
Yuanyuan Liu7145eb22016-12-01 10:59:29 -080010316 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +053010317
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010318 if (no_of_mac_addr == 0 || !addr) {
10319 hdd_debug("No mac configured from platform driver");
Komal Seelam92fff912016-03-24 11:51:41 +053010320 return -EINVAL;
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010321 }
10322
10323 hdd_free_mac_address_lists(hdd_ctx);
Komal Seelam92fff912016-03-24 11:51:41 +053010324
10325 if (no_of_mac_addr > max_mac_addr)
10326 no_of_mac_addr = max_mac_addr;
10327
10328 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
10329
10330 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010331 buf = hdd_ctx->provisioned_mac_addr[iter].bytes;
Komal Seelam92fff912016-03-24 11:51:41 +053010332 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowdacb7b8b82019-04-10 14:27:47 -070010333 hdd_info("provisioned MAC Addr [%d]" QDF_MAC_ADDR_STR, iter,
Srinivas Girigowda34fbba02019-04-08 12:07:44 -070010334 QDF_MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +053010335 }
10336
Komal Seelam92fff912016-03-24 11:51:41 +053010337
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010338 hdd_ctx->num_provisioned_addr = no_of_mac_addr;
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010339
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010340 if (hdd_ctx->config->mac_provision) {
10341 addr = hdd_get_platform_wlan_derived_mac_buff(dev,
10342 &no_of_mac_addr);
10343
10344 if (no_of_mac_addr == 0 || !addr)
10345 hdd_warn("No derived address from platform driver");
10346 else if (no_of_mac_addr >
10347 (max_mac_addr - hdd_ctx->num_provisioned_addr))
10348 no_of_mac_addr = (max_mac_addr -
10349 hdd_ctx->num_provisioned_addr);
10350
10351 for (iter = 0; iter < no_of_mac_addr; ++iter,
10352 addr += mac_addr_size) {
10353 buf = hdd_ctx->derived_mac_addr[iter].bytes;
10354 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowdacb7b8b82019-04-10 14:27:47 -070010355 hdd_debug("derived MAC Addr [%d]" QDF_MAC_ADDR_STR, iter,
Srinivas Girigowda34fbba02019-04-08 12:07:44 -070010356 QDF_MAC_ADDR_ARRAY(buf));
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010357 }
10358 hdd_ctx->num_derived_addr = no_of_mac_addr;
10359 }
10360
10361 no_of_mac_addr = hdd_ctx->num_provisioned_addr +
10362 hdd_ctx->num_derived_addr;
Komal Seelam92fff912016-03-24 11:51:41 +053010363 if (no_of_mac_addr < max_mac_addr)
10364 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
10365 no_of_mac_addr);
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010366
10367 status = sme_set_custom_mac_addr(mac_addr);
10368 if (!QDF_IS_STATUS_SUCCESS(status))
10369 return -EAGAIN;
10370
Komal Seelam92fff912016-03-24 11:51:41 +053010371 return 0;
10372}
10373
10374/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010375 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
10376 * @hdd_ctx: HDD Context
10377 *
10378 * Update MAC address to FW. If MAC address passed by FW is invalid, host
10379 * will generate its own MAC and update it to FW.
10380 *
10381 * Return: 0 for success
10382 * Non-zero error code for failure
10383 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010384static int hdd_update_mac_addr_to_fw(struct hdd_context *hdd_ctx)
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010385{
Jeff Johnson374c0852019-03-10 19:02:07 -070010386 tSirMacAddr custom_mac_addr;
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010387 QDF_STATUS status;
10388
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010389 if (hdd_ctx->num_provisioned_addr)
Jeff Johnson374c0852019-03-10 19:02:07 -070010390 qdf_mem_copy(&custom_mac_addr,
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010391 &hdd_ctx->provisioned_mac_addr[0].bytes[0],
10392 sizeof(tSirMacAddr));
10393 else
Jeff Johnson374c0852019-03-10 19:02:07 -070010394 qdf_mem_copy(&custom_mac_addr,
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010395 &hdd_ctx->derived_mac_addr[0].bytes[0],
10396 sizeof(tSirMacAddr));
Jeff Johnson374c0852019-03-10 19:02:07 -070010397 status = sme_set_custom_mac_addr(custom_mac_addr);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010398 if (!QDF_IS_STATUS_SUCCESS(status))
10399 return -EAGAIN;
10400 return 0;
10401}
10402
10403/**
Komal Seelam92fff912016-03-24 11:51:41 +053010404 * hdd_initialize_mac_address() - API to get wlan mac addresses
10405 * @hdd_ctx: HDD Context
10406 *
10407 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
10408 * is provisioned with mac addresses, driver uses it, else it will use
10409 * wlan_mac.bin to update HW MAC addresses.
10410 *
10411 * Return: None
10412 */
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010413static int hdd_initialize_mac_address(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +053010414{
10415 QDF_STATUS status;
10416 int ret;
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010417 bool update_mac_addr_to_fw = true;
Komal Seelam92fff912016-03-24 11:51:41 +053010418
Yuanyuan Liu7145eb22016-12-01 10:59:29 -080010419 ret = hdd_platform_wlan_mac(hdd_ctx);
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010420 if (hdd_ctx->config->mac_provision || !ret) {
Dustin Brown7e761c72018-07-31 13:50:17 -070010421 hdd_info("using MAC address from platform driver");
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010422 return ret;
Dustin Brown7e761c72018-07-31 13:50:17 -070010423 }
Komal Seelam92fff912016-03-24 11:51:41 +053010424
10425 status = hdd_update_mac_config(hdd_ctx);
Dustin Brown7e761c72018-07-31 13:50:17 -070010426 if (QDF_IS_STATUS_SUCCESS(status)) {
10427 hdd_info("using MAC address from wlan_mac.bin");
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010428 return 0;
Dustin Brown7e761c72018-07-31 13:50:17 -070010429 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010430
Dustin Brown7e761c72018-07-31 13:50:17 -070010431 hdd_info("using default MAC address");
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010432
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010433 /* Use fw provided MAC */
10434 if (!qdf_is_macaddr_zero(&hdd_ctx->hw_macaddr)) {
10435 hdd_update_macaddr(hdd_ctx, hdd_ctx->hw_macaddr, false);
10436 update_mac_addr_to_fw = false;
10437 return 0;
10438 } else if (hdd_generate_macaddr_auto(hdd_ctx) != 0) {
10439 struct qdf_mac_addr mac_addr;
10440
10441 hdd_err("MAC failure from device serial no.");
Jeff Johnson51a80522018-12-11 20:19:44 -080010442 qdf_get_random_bytes(&mac_addr, sizeof(mac_addr));
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010443 /*
10444 * Reset multicast bit (bit-0) and set
10445 * locally-administered bit
10446 */
10447 mac_addr.bytes[0] = 0x2;
10448 hdd_update_macaddr(hdd_ctx, mac_addr, true);
10449 }
10450
10451 if (update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010452 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Dustin Brown7e761c72018-07-31 13:50:17 -070010453 if (ret)
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -080010454 hdd_err("MAC address out-of-sync, ret:%d", ret);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010455 }
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010456 return ret;
Komal Seelam92fff912016-03-24 11:51:41 +053010457}
10458
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010459static int hdd_set_smart_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010460{
10461 int vdev_id = 0;
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +053010462 QDF_STATUS status;
10463 bool smart_chainmask_enabled;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010464 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010465 int vpdev = PDEV_CMD;
10466 int ret;
10467
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +053010468 status = ucfg_get_smart_chainmask_enabled(hdd_ctx->psoc,
10469 &smart_chainmask_enabled);
10470 if (QDF_IS_STATUS_ERROR(status))
10471 return -EINVAL;
10472
10473 ret = sme_cli_set_command(vdev_id, param_id,
10474 (int)smart_chainmask_enabled, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010475 if (ret)
10476 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
10477
10478 return ret;
10479}
10480
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010481static int hdd_set_alternative_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010482{
10483 int vdev_id = 0;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010484 QDF_STATUS status;
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010485 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010486 bool alternative_chainmask_enabled;
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010487 int vpdev = PDEV_CMD;
10488 int ret;
10489
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010490 status = ucfg_get_alternative_chainmask_enabled(
10491 hdd_ctx->psoc,
10492 &alternative_chainmask_enabled);
10493 if (QDF_IS_STATUS_ERROR(status))
10494 return -EINVAL;
10495
10496 ret = sme_cli_set_command(vdev_id, param_id,
10497 (int)alternative_chainmask_enabled, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010498 if (ret)
10499 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
10500 ret);
10501
10502 return ret;
10503}
10504
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010505static int hdd_set_ani_enabled(struct hdd_context *hdd_ctx)
Jeff Johnson12a744b2017-04-04 08:19:37 -070010506{
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010507 QDF_STATUS status;
Jeff Johnson12a744b2017-04-04 08:19:37 -070010508 int vdev_id = 0;
10509 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010510 bool value;
Jeff Johnson12a744b2017-04-04 08:19:37 -070010511 int vpdev = PDEV_CMD;
10512 int ret;
10513
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010514 status = ucfg_fwol_get_ani_enabled(hdd_ctx->psoc, &value);
10515 if (QDF_IS_STATUS_ERROR(status))
10516 return -EINVAL;
10517
10518 ret = sme_cli_set_command(vdev_id, param_id, (int)value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -070010519 if (ret)
10520 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
10521
10522 return ret;
10523}
10524
Jeff Johnson89c66ff2016-04-22 15:21:37 -070010525/**
Prashanth Bhatta07998752016-04-28 12:35:33 -070010526 * hdd_pre_enable_configure() - Configurations prior to cds_enable
10527 * @hdd_ctx: HDD context
10528 *
10529 * Pre configurations to be done at lower layer before calling cds enable.
10530 *
10531 * Return: 0 on success and errno on failure.
10532 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010533static int hdd_pre_enable_configure(struct hdd_context *hdd_ctx)
Prashanth Bhatta07998752016-04-28 12:35:33 -070010534{
10535 int ret;
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +053010536 uint8_t val = 0;
Prashanth Bhatta07998752016-04-28 12:35:33 -070010537 QDF_STATUS status;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010538 uint32_t arp_ac_category;
Leo Changfdb45c32016-10-28 11:09:23 -070010539 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010540
Leo Changfdb45c32016-10-28 11:09:23 -070010541 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Ajit Pal Singh5d269612018-04-19 16:29:12 +053010542 /* Register HL netdev flow control callback */
10543 cdp_hl_fc_register(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010544
10545 /*
10546 * Note that the cds_pre_enable() sequence triggers the cfg download.
10547 * The cfg download must occur before we update the SME config
10548 * since the SME config operation must access the cfg database
10549 */
10550 status = hdd_set_sme_config(hdd_ctx);
10551
10552 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010553 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010554 ret = qdf_status_to_os_return(status);
10555 goto out;
10556 }
10557
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -070010558 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
10559 if (QDF_STATUS_SUCCESS != status) {
10560 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
10561 ret = qdf_status_to_os_return(status);
10562 goto out;
10563 }
10564
Dustin Brown1dbefe62018-09-11 16:32:03 -070010565 status = ucfg_mlme_get_tx_chainmask_1ss(hdd_ctx->psoc, &val);
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +053010566 if (QDF_STATUS_SUCCESS != status) {
10567 hdd_err("Get tx_chainmask_1ss from mlme failed");
10568 ret = qdf_status_to_os_return(status);
10569 goto out;
10570 }
10571 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS, val,
Prashanth Bhatta07998752016-04-28 12:35:33 -070010572 PDEV_CMD);
10573 if (0 != ret) {
10574 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
10575 goto out;
10576 }
10577
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010578 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
10579 if (ret)
10580 goto out;
10581
10582 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
10583 if (ret)
10584 goto out;
10585
Jeff Johnson12a744b2017-04-04 08:19:37 -070010586 ret = hdd_set_ani_enabled(hdd_ctx);
10587 if (ret)
10588 goto out;
10589
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010590 status = ucfg_get_arp_ac_category(hdd_ctx->psoc, &arp_ac_category);
10591
10592 if (QDF_IS_STATUS_ERROR(status))
10593 return -EINVAL;
10594
Naveen Rawat247a8682017-06-05 15:00:31 -070010595 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010596 arp_ac_category,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -080010597 PDEV_CMD);
10598 if (0 != ret) {
10599 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010600 arp_ac_category, ret);
Srinivas Girigowda70e169a2017-03-07 23:55:57 -080010601 goto out;
10602 }
10603
Prashanth Bhatta07998752016-04-28 12:35:33 -070010604 status = hdd_set_sme_chan_list(hdd_ctx);
10605 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010606 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010607 ret = qdf_status_to_os_return(status);
10608 goto out;
10609 }
10610
Krunal Sonidf0f8742016-09-26 14:56:31 -070010611 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010612 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -070010613 ret = -EINVAL;
10614 goto out;
10615 }
Prashanth Bhatta07998752016-04-28 12:35:33 -070010616 hdd_init_channel_avoidance(hdd_ctx);
10617
10618out:
10619 return ret;
10620}
10621
Rachit Kankane026e77a2018-07-31 16:21:09 +053010622#ifdef FEATURE_P2P_LISTEN_OFFLOAD
Prashanth Bhatta07998752016-04-28 12:35:33 -070010623/**
Peng Xu8fdaa492016-06-22 10:20:47 -070010624 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
Jeff Johnsonf7e36d62018-07-04 21:14:02 -070010625 * @context: context registered with sme_register_p2p_lo_event(). HDD
10626 * always registers a hdd context pointer
10627 * @evt:event structure pointer
Peng Xu8fdaa492016-06-22 10:20:47 -070010628 *
10629 * This is the p2p listen offload stop event handler, it sends vendor
10630 * event back to supplicant to notify the stop reason.
10631 *
10632 * Return: None
10633 */
Jeff Johnsonf7e36d62018-07-04 21:14:02 -070010634static void wlan_hdd_p2p_lo_event_callback(void *context,
10635 struct sir_p2p_lo_event *evt)
Peng Xu8fdaa492016-06-22 10:20:47 -070010636{
Jeff Johnsonf7e36d62018-07-04 21:14:02 -070010637 struct hdd_context *hdd_ctx = context;
Peng Xu8fdaa492016-06-22 10:20:47 -070010638 struct sk_buff *vendor_event;
Jeff Johnson9d295242017-08-29 14:39:48 -070010639 struct hdd_adapter *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -070010640
Dustin Brown491d54b2018-03-14 12:39:11 -070010641 hdd_enter();
Peng Xu8fdaa492016-06-22 10:20:47 -070010642
Jeff Johnsond36fa332019-03-18 13:42:25 -070010643 if (!hdd_ctx) {
Peng Xu8fdaa492016-06-22 10:20:47 -070010644 hdd_err("Invalid HDD context pointer");
10645 return;
10646 }
10647
Peng Xu5c682812017-08-06 07:39:13 -070010648 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
10649 if (!adapter) {
10650 hdd_err("Cannot find adapter by vdev_id = %d",
10651 evt->vdev_id);
10652 return;
10653 }
10654
Peng Xu8fdaa492016-06-22 10:20:47 -070010655 vendor_event =
10656 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -070010657 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -070010658 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
10659 GFP_KERNEL);
10660
10661 if (!vendor_event) {
10662 hdd_err("cfg80211_vendor_event_alloc failed");
10663 return;
10664 }
10665
10666 if (nla_put_u32(vendor_event,
10667 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
10668 evt->reason_code)) {
10669 hdd_err("nla put failed");
10670 kfree_skb(vendor_event);
10671 return;
10672 }
10673
10674 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -070010675 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
10676 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -070010677}
Rachit Kankane026e77a2018-07-31 16:21:09 +053010678#else
10679static void wlan_hdd_p2p_lo_event_callback(void *context,
10680 struct sir_p2p_lo_event *evt)
10681{
10682}
10683#endif
Peng Xu8fdaa492016-06-22 10:20:47 -070010684
Rachit Kankanef6834c42018-08-02 18:47:50 +053010685#ifdef FEATURE_WLAN_DYNAMIC_CVM
10686static inline int hdd_set_vc_mode_config(struct hdd_context *hdd_ctx)
10687{
10688 return sme_set_vc_mode_config(hdd_ctx->config->vc_mode_cfg_bitmap);
10689}
10690#else
10691static inline int hdd_set_vc_mode_config(struct hdd_context *hdd_ctx)
10692{
10693 return QDF_STATUS_SUCCESS;
10694}
10695#endif
10696
Peng Xu8fdaa492016-06-22 10:20:47 -070010697/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010698 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
10699 * @hdd_ctx: HDD context
10700 *
10701 * This function sends the adaptive dwell time config configuration to the
10702 * firmware via WMA
10703 *
10704 * Return: 0 - success, < 0 - failure
10705 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010706static int hdd_adaptive_dwelltime_init(struct hdd_context *hdd_ctx)
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010707{
10708 QDF_STATUS status;
10709 struct adaptive_dwelltime_params dwelltime_params;
10710
Harprit Chhabadad59ae762019-01-08 16:40:43 -080010711 status = ucfg_fwol_get_all_adaptive_dwelltime_params(hdd_ctx->psoc,
10712 &dwelltime_params);
10713 status = ucfg_fwol_set_adaptive_dwelltime_config(&dwelltime_params);
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010714
10715 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
10716 if (!QDF_IS_STATUS_SUCCESS(status)) {
10717 hdd_err("Failed to send Adaptive Dwelltime configuration!");
10718 return -EAGAIN;
10719 }
10720 return 0;
10721}
10722
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010723int hdd_dbs_scan_selection_init(struct hdd_context *hdd_ctx)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010724{
10725 QDF_STATUS status;
10726 struct wmi_dbs_scan_sel_params dbs_scan_params;
10727 uint32_t i = 0;
10728 uint8_t count = 0, numentries = 0;
Krunal Sonidf29bc42018-11-15 13:26:29 -080010729 uint8_t dual_mac_feature;
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010730 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
10731 * CDS_DBS_SCAN_CLIENTS_MAX];
10732
Krunal Sonidf29bc42018-11-15 13:26:29 -080010733 status = ucfg_policy_mgr_get_dual_mac_feature(hdd_ctx->psoc,
10734 &dual_mac_feature);
10735
10736 if (status != QDF_STATUS_SUCCESS) {
10737 hdd_err("can't get dual mac feature flag");
10738 return -EINVAL;
10739 }
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010740 /* check if DBS is enabled or supported */
Krunal Sonidf29bc42018-11-15 13:26:29 -080010741 if ((dual_mac_feature == DISABLE_DBS_CXN_AND_SCAN) ||
10742 (dual_mac_feature == ENABLE_DBS_CXN_AND_DISABLE_DBS_SCAN))
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010743 return -EINVAL;
10744
10745 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
10746 dbs_scan_config, &numentries,
10747 (CDS_DBS_SCAN_PARAM_PER_CLIENT
10748 * CDS_DBS_SCAN_CLIENTS_MAX));
10749
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010750 if (!numentries) {
Dustin Brown6a8d39b2018-08-14 15:27:26 -070010751 hdd_debug("Do not send scan_selection_config");
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010752 return 0;
10753 }
10754
10755 /* hdd_set_fw_log_params */
10756 dbs_scan_params.num_clients = 0;
10757 while (count < (numentries - 2)) {
10758 dbs_scan_params.module_id[i] = dbs_scan_config[count];
10759 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
10760 dbs_scan_params.num_non_dbs_scans[i] =
10761 dbs_scan_config[count + 2];
10762 dbs_scan_params.num_clients++;
10763 hdd_debug("module:%d NDS:%d NNDS:%d",
10764 dbs_scan_params.module_id[i],
10765 dbs_scan_params.num_dbs_scans[i],
10766 dbs_scan_params.num_non_dbs_scans[i]);
10767 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
10768 i++;
10769 }
10770
10771 dbs_scan_params.pdev_id = 0;
10772
10773 hdd_debug("clients:%d pdev:%d",
10774 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
10775
Jeff Johnson16528362018-06-14 12:34:16 -070010776 status = sme_set_dbs_scan_selection_config(hdd_ctx->mac_handle,
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010777 &dbs_scan_params);
10778 hdd_debug("Sending DBS Scan Selection Configuration to fw");
10779 if (!QDF_IS_STATUS_SUCCESS(status)) {
10780 hdd_err("Failed to send DBS Scan selection configuration!");
10781 return -EAGAIN;
10782 }
10783 return 0;
10784}
10785
Arun Khandavallid4349a92016-07-25 11:10:43 +053010786#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
10787/**
10788 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
10789 * @hdd_ctx: HDD context
10790 *
10791 * Set auto shutdown callback to get indications from firmware to indicate
10792 * userspace to shutdown WLAN after a configured amount of inactivity.
10793 *
10794 * Return: 0 on success and errno on failure.
10795 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010796static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010797{
10798 QDF_STATUS status;
10799
Dundi Raviteja8e338282018-09-25 17:16:04 +053010800 if (!hdd_ctx->config->wlan_auto_shutdown)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010801 return 0;
10802
Jeff Johnson16528362018-06-14 12:34:16 -070010803 status = sme_set_auto_shutdown_cb(hdd_ctx->mac_handle,
Arun Khandavallid4349a92016-07-25 11:10:43 +053010804 wlan_hdd_auto_shutdown_cb);
10805 if (status != QDF_STATUS_SUCCESS)
10806 hdd_err("Auto shutdown feature could not be enabled: %d",
10807 status);
10808
10809 return qdf_status_to_os_return(status);
10810}
10811#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010812static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010813{
10814 return 0;
10815}
10816#endif
10817
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010818#ifdef MWS_COEX
10819/**
10820 * hdd_set_mws_coex() - Set MWS coex configurations
10821 * @hdd_ctx: HDD context
10822 *
10823 * This function sends MWS-COEX 4G quick FTDM and
10824 * MWS-COEX 5G-NR power limit to FW
10825 *
10826 * Return: 0 on success and errno on failure.
10827 */
10828static int hdd_init_mws_coex(struct hdd_context *hdd_ctx)
10829{
10830 int ret = 0;
lifengdb340e72018-11-20 00:50:20 +080010831 uint32_t mws_coex_4g_quick_tdm = 0, mws_coex_5g_nr_pwr_limit = 0;
10832
10833 ucfg_mlme_get_mws_coex_4g_quick_tdm(hdd_ctx->psoc,
10834 &mws_coex_4g_quick_tdm);
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010835
10836 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_MWSCOEX_4G_ALLOW_QUICK_FTDM,
lifengdb340e72018-11-20 00:50:20 +080010837 mws_coex_4g_quick_tdm,
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010838 PDEV_CMD);
10839 if (ret) {
10840 hdd_warn("Unable to send MWS-COEX 4G quick FTDM policy");
10841 return ret;
10842 }
10843
lifengdb340e72018-11-20 00:50:20 +080010844 ucfg_mlme_get_mws_coex_5g_nr_pwr_limit(hdd_ctx->psoc,
10845 &mws_coex_5g_nr_pwr_limit);
10846
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010847 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_MWSCOEX_SET_5GNR_PWR_LIMIT,
lifengdb340e72018-11-20 00:50:20 +080010848 mws_coex_5g_nr_pwr_limit,
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010849 PDEV_CMD);
10850 if (ret) {
10851 hdd_warn("Unable to send MWS-COEX 4G quick FTDM policy");
10852 return ret;
10853 }
lifengdb340e72018-11-20 00:50:20 +080010854
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010855 return ret;
10856}
10857#else
10858static int hdd_init_mws_coex(struct hdd_context *hdd_ctx)
10859{
10860 return 0;
10861}
10862#endif
10863
Arun Khandavallid4349a92016-07-25 11:10:43 +053010864/**
10865 * hdd_features_init() - Init features
10866 * @hdd_ctx: HDD context
Arun Khandavallid4349a92016-07-25 11:10:43 +053010867 *
10868 * Initialize features and their feature context after WLAN firmware is up.
10869 *
10870 * Return: 0 on success and errno on failure.
10871 */
Dustin Browne7e71d32018-05-11 16:00:08 -070010872static int hdd_features_init(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010873{
Jeff Johnson19ce8d02019-02-08 22:56:23 -080010874 struct tx_power_limit hddtxlimit;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010875 QDF_STATUS status;
10876 int ret;
Jeff Johnson16528362018-06-14 12:34:16 -070010877 mac_handle_t mac_handle;
Kiran Kumar Lokere1a43bcf2018-05-15 15:51:58 -070010878 struct hdd_config *cfg;
Pragaspathi Thilagaraj784c4922018-12-02 22:47:29 +053010879 bool b_cts2self, is_imps_enabled;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010880
Dustin Brown491d54b2018-03-14 12:39:11 -070010881 hdd_enter();
Arun Khandavallid4349a92016-07-25 11:10:43 +053010882
Dustin Brownad698ae2018-09-05 17:19:30 -070010883 ret = hdd_update_country_code(hdd_ctx);
10884 if (ret) {
10885 hdd_err("Failed to update country code; errno:%d", ret);
10886 return -EINVAL;
10887 }
10888
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010889 ret = hdd_init_mws_coex(hdd_ctx);
10890 if (ret)
10891 hdd_warn("Error initializing mws-coex");
10892
Kiran Kumar Lokere1a43bcf2018-05-15 15:51:58 -070010893 cfg = hdd_ctx->config;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010894 /* FW capabilities received, Set the Dot11 mode */
Jeff Johnson16528362018-06-14 12:34:16 -070010895 mac_handle = hdd_ctx->mac_handle;
10896 sme_setdef_dot11mode(mac_handle);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010897
Pragaspathi Thilagaraj784c4922018-12-02 22:47:29 +053010898 ucfg_mlme_is_imps_enabled(hdd_ctx->psoc, &is_imps_enabled);
10899 hdd_set_idle_ps_config(hdd_ctx, is_imps_enabled);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010900
Poddar, Siddarth37033032017-10-11 15:47:40 +053010901 /* Send Enable/Disable data stall detection cmd to FW */
10902 sme_cli_set_command(0, WMI_PDEV_PARAM_DATA_STALL_DETECT_ENABLE,
jitiphil377bcc12018-10-05 19:46:08 +053010903 cdp_cfg_get(cds_get_context(QDF_MODULE_ID_SOC),
10904 cfg_dp_enable_data_stall), PDEV_CMD);
Poddar, Siddarth37033032017-10-11 15:47:40 +053010905
Dustin Brown1dbefe62018-09-11 16:32:03 -070010906 ucfg_mlme_get_go_cts2self_for_sta(hdd_ctx->psoc, &b_cts2self);
Wu Gao93816212018-08-31 16:49:54 +080010907 if (b_cts2self)
Jeff Johnson16528362018-06-14 12:34:16 -070010908 sme_set_cts2self_for_p2p_go(mac_handle);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +053010909
Rachit Kankanef6834c42018-08-02 18:47:50 +053010910 if (hdd_set_vc_mode_config(hdd_ctx))
Nachiket Kukade8983cf62017-10-12 18:14:48 +053010911 hdd_warn("Error in setting Voltage Corner mode config to FW");
10912
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -070010913 if (hdd_rx_ol_init(hdd_ctx))
10914 hdd_err("Unable to initialize Rx LRO/GRO in fw");
Arun Khandavallid4349a92016-07-25 11:10:43 +053010915
10916 if (hdd_adaptive_dwelltime_init(hdd_ctx))
10917 hdd_err("Unable to send adaptive dwelltime setting to FW");
10918
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010919 if (hdd_dbs_scan_selection_init(hdd_ctx))
10920 hdd_err("Unable to send DBS scan selection setting to FW");
10921
Arun Khandavallid4349a92016-07-25 11:10:43 +053010922 ret = hdd_init_thermal_info(hdd_ctx);
10923 if (ret) {
10924 hdd_err("Error while initializing thermal information");
Dustin Browne7e71d32018-05-11 16:00:08 -070010925 return ret;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010926 }
10927
Poddar, Siddarth61fbc932017-12-19 14:27:55 +053010928 /**
10929 * In case of SSR/PDR, if pktlog was enabled manually before
Rakshith Suresh Patkar6d955262019-03-13 16:51:50 +053010930 * SSR/PDR, then enable it again automatically after Wlan
Poddar, Siddarth61fbc932017-12-19 14:27:55 +053010931 * device up.
Rakshith Suresh Patkar6d955262019-03-13 16:51:50 +053010932 * During SSR/PDR, pktlog will be disabled as part of
10933 * hdd_features_deinit if pktlog is enabled in ini.
10934 * Re-enable pktlog in SSR case, if pktlog is enabled in ini.
Poddar, Siddarth61fbc932017-12-19 14:27:55 +053010935 */
Rakshith Suresh Patkar6d955262019-03-13 16:51:50 +053010936 if (cds_is_packet_log_enabled() ||
10937 (cds_is_driver_recovering() && hdd_ctx->is_pktlog_enabled))
Alok Kumar5a75b9d2018-08-31 10:55:43 +053010938 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
Poddar, Siddarth66a46592017-02-22 11:44:44 +053010939
gaurank kathpalia3d2e3852018-10-03 22:03:23 +053010940 hddtxlimit.txPower2g = ucfg_get_tx_power(hdd_ctx->psoc, BAND_2G);
10941 hddtxlimit.txPower5g = ucfg_get_tx_power(hdd_ctx->psoc, BAND_5G);
Jeff Johnson16528362018-06-14 12:34:16 -070010942 status = sme_txpower_limit(mac_handle, &hddtxlimit);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010943 if (!QDF_IS_STATUS_SUCCESS(status))
10944 hdd_err("Error setting txlimit in sme: %d", status);
10945
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010946 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010947
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053010948 status = sme_enable_disable_chanavoidind_event(mac_handle, 0);
10949 if (QDF_IS_STATUS_ERROR(status) && (status != QDF_STATUS_E_NOSUPPORT)) {
10950 hdd_err("Failed to disable Chan Avoidance Indication");
Sourav Mohapatra674925f2018-04-16 11:16:58 +053010951 return -EINVAL;
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +053010952 }
Arun Khandavallid4349a92016-07-25 11:10:43 +053010953
10954 /* register P2P Listen Offload event callback */
10955 if (wma_is_p2p_lo_capable())
Jeff Johnson16528362018-06-14 12:34:16 -070010956 sme_register_p2p_lo_event(mac_handle, hdd_ctx,
10957 wlan_hdd_p2p_lo_event_callback);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010958
10959 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
10960
10961 if (ret)
Sourav Mohapatra674925f2018-04-16 11:16:58 +053010962 return -EINVAL;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010963
Dustin Brown11638b72018-01-25 17:37:25 +053010964 wlan_hdd_init_chan_info(hdd_ctx);
Varun Reddy Yeturu3c9f89c2018-04-18 19:10:34 -070010965 wlan_hdd_twt_init(hdd_ctx);
Dustin Brown11638b72018-01-25 17:37:25 +053010966
Dustin Browne74003f2018-03-14 12:51:58 -070010967 hdd_exit();
Arun Khandavallid4349a92016-07-25 11:10:43 +053010968 return 0;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010969}
10970
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010971/**
10972 * hdd_features_deinit() - Deinit features
10973 * @hdd_ctx: HDD context
10974 *
10975 * De-Initialize features and their feature context.
10976 *
10977 * Return: none.
10978 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010979static void hdd_features_deinit(struct hdd_context *hdd_ctx)
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010980{
Varun Reddy Yeturu3c9f89c2018-04-18 19:10:34 -070010981 wlan_hdd_twt_deinit(hdd_ctx);
Dustin Brown11638b72018-01-25 17:37:25 +053010982 wlan_hdd_deinit_chan_info(hdd_ctx);
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010983 wlan_hdd_tsf_deinit(hdd_ctx);
jitiphil4e3bef42018-11-14 14:31:13 +053010984 if (cds_is_packet_log_enabled())
10985 hdd_pktlog_enable_disable(hdd_ctx, false, 0, 0);
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010986}
10987
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010988/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -070010989 * hdd_register_bcn_cb() - register scan beacon callback
10990 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010991 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -070010992 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010993 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010994static inline QDF_STATUS hdd_register_bcn_cb(struct hdd_context *hdd_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010995{
10996 QDF_STATUS status;
10997
Dustin Brown1dbefe62018-09-11 16:32:03 -070010998 status = ucfg_scan_register_bcn_cb(hdd_ctx->psoc,
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010999 wlan_cfg80211_inform_bss_frame,
11000 SCAN_CB_TYPE_INFORM_BCN);
11001 if (!QDF_IS_STATUS_SUCCESS(status)) {
Abhishek Singh5ffe9de2019-03-05 15:42:43 +053011002 hdd_err("failed to register SCAN_CB_TYPE_INFORM_BCN with status code %08d [x%08x]",
11003 status, status);
11004 return status;
11005 }
11006
11007 status = ucfg_scan_register_bcn_cb(hdd_ctx->psoc,
11008 wlan_cfg80211_unlink_bss_list,
11009 SCAN_CB_TYPE_UNLINK_BSS);
11010 if (!QDF_IS_STATUS_SUCCESS(status)) {
11011 hdd_err("failed to refister SCAN_CB_TYPE_FLUSH_BSS with status code %08d [x%08x]",
Abhishek Singh6092fbb2017-01-25 18:10:31 +053011012 status, status);
11013 return status;
11014 }
11015
11016 return QDF_STATUS_SUCCESS;
11017}
Arun Khandavallid4349a92016-07-25 11:10:43 +053011018
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053011019/**
Manjunathappa Prakasha0cbc922018-05-08 19:48:34 -070011020 * hdd_v2_flow_pool_map() - Flow pool create callback when vdev is active
11021 * @vdev_id: vdev_id, corresponds to flow_pool
11022 *
11023 * Return: none.
11024 */
11025static void hdd_v2_flow_pool_map(int vdev_id)
11026{
11027 QDF_STATUS status;
11028
11029 status = cdp_flow_pool_map(cds_get_context(QDF_MODULE_ID_SOC),
11030 cds_get_context(QDF_MODULE_ID_TXRX),
11031 vdev_id);
11032 /*
11033 * For Adrastea flow control v2 is based on FW MAP events,
11034 * so this above callback is not implemented.
11035 * Hence this is not actual failure. Dont return failure
11036 */
11037 if ((status != QDF_STATUS_SUCCESS) &&
11038 (status != QDF_STATUS_E_INVAL)) {
11039 hdd_err("vdev_id: %d, failed to create flow pool status %d",
11040 vdev_id, status);
11041 }
11042}
11043
11044/**
11045 * hdd_v2_flow_pool_unmap() - Flow pool create callback when vdev is not active
11046 * @vdev_id: vdev_id, corresponds to flow_pool
11047 *
11048 * Return: none.
11049 */
11050static void hdd_v2_flow_pool_unmap(int vdev_id)
11051{
11052 cdp_flow_pool_unmap(cds_get_context(QDF_MODULE_ID_SOC),
11053 cds_get_context(QDF_MODULE_ID_TXRX), vdev_id);
11054}
11055
11056/**
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053011057 * hdd_action_oui_config() - Configure action_oui strings
11058 * @hdd_ctx: pointer to hdd context
11059 *
11060 * This is a HDD wrapper function which invokes ucfg api
11061 * of action_oui component to parse action oui strings.
11062 *
11063 * Return: None
11064 */
11065static void hdd_action_oui_config(struct hdd_context *hdd_ctx)
11066{
11067 QDF_STATUS status;
11068 uint32_t id;
11069 uint8_t *str;
11070
11071 if (!hdd_ctx->config->action_oui_enable)
11072 return;
11073
11074 for (id = 0; id < ACTION_OUI_MAXIMUM_ID; id++) {
11075 str = hdd_ctx->config->action_oui_str[id];
11076 if (!qdf_str_len(str))
11077 continue;
11078
Dustin Brown1dbefe62018-09-11 16:32:03 -070011079 status = ucfg_action_oui_parse(hdd_ctx->psoc, str, id);
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053011080 if (!QDF_IS_STATUS_SUCCESS(status))
11081 hdd_err("Failed to parse action_oui str: %u", id);
11082 }
11083}
11084
11085/**
11086 * hdd_action_oui_send() - Send action_oui extensions to firmware
11087 * @hdd_ctx: pointer to hdd context
11088 *
11089 * This is a HDD wrapper function which invokes ucfg api
11090 * of action_oui component to send action oui extensions to firmware.
11091 *
11092 * Return: None
11093 */
11094static void hdd_action_oui_send(struct hdd_context *hdd_ctx)
11095{
11096 QDF_STATUS status;
11097
11098 if (!hdd_ctx->config->action_oui_enable)
11099 return;
11100
Dustin Brown1dbefe62018-09-11 16:32:03 -070011101 status = ucfg_action_oui_send(hdd_ctx->psoc);
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053011102 if (!QDF_IS_STATUS_SUCCESS(status))
11103 hdd_err("Failed to send one or all action_ouis");
11104}
11105
Jeff Johnson0187c622019-01-04 06:39:44 -080011106static void hdd_hastings_bt_war_initialize(struct hdd_context *hdd_ctx)
11107{
11108 if (hdd_ctx->config->iface_change_wait_time)
11109 hdd_hastings_bt_war_disable_fw(hdd_ctx);
11110 else
11111 hdd_hastings_bt_war_enable_fw(hdd_ctx);
11112}
11113
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053011114/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011115 * hdd_configure_cds() - Configure cds modules
11116 * @hdd_ctx: HDD context
11117 * @adapter: Primary adapter context
11118 *
11119 * Enable Cds modules after WLAN firmware is up.
11120 *
11121 * Return: 0 on success and errno on failure.
11122 */
Dustin Browne7e71d32018-05-11 16:00:08 -070011123int hdd_configure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +053011124{
11125 int ret;
11126 QDF_STATUS status;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011127 int set_value;
Jeff Johnson16528362018-06-14 12:34:16 -070011128 mac_handle_t mac_handle;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053011129 bool enable_rts_sifsbursting;
11130 uint8_t enable_phy_reg_retention;
Krunal Sonidf29bc42018-11-15 13:26:29 -080011131 uint8_t max_mpdus_inampdu, is_force_1x1 = 0;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011132 uint32_t num_abg_tx_chains = 0;
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +053011133 uint16_t num_11b_tx_chains = 0;
11134 uint16_t num_11ag_tx_chains = 0;
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -070011135 struct policy_mgr_dp_cbacks dp_cbs = {0};
Bala Venkatesh2fde2c62018-09-11 20:33:24 +053011136 bool value;
Wu Gao66454f12018-09-26 19:55:41 +080011137 enum pmo_auto_pwr_detect_failure_mode auto_power_fail_mode;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053011138 bool bval = false;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011139
Jeff Johnson16528362018-06-14 12:34:16 -070011140 mac_handle = hdd_ctx->mac_handle;
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053011141
11142 hdd_action_oui_send(hdd_ctx);
Krunal Sonidf29bc42018-11-15 13:26:29 -080011143 status = ucfg_policy_mgr_get_force_1x1(hdd_ctx->psoc, &is_force_1x1);
11144 if (status != QDF_STATUS_SUCCESS) {
11145 hdd_err("Failed to get force 1x1 value");
11146 goto out;
11147 }
11148 if (is_force_1x1)
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011149 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
11150 1, PDEV_CMD);
11151 /* set chip power save failure detected callback */
Jeff Johnson16528362018-06-14 12:34:16 -070011152 sme_set_chip_pwr_save_fail_cb(mac_handle,
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011153 hdd_chip_pwr_save_fail_detected_cb);
11154
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053011155 status = ucfg_get_max_mpdus_inampdu(hdd_ctx->psoc,
11156 &max_mpdus_inampdu);
Krunal Sonidf29bc42018-11-15 13:26:29 -080011157 if (status) {
11158 hdd_err("Failed to get max mpdus in ampdu value");
11159 goto out;
11160 }
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053011161
11162 if (max_mpdus_inampdu) {
11163 set_value = max_mpdus_inampdu;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011164 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
11165 set_value, PDEV_CMD);
11166 }
11167
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053011168 status = ucfg_get_enable_rts_sifsbursting(hdd_ctx->psoc,
11169 &enable_rts_sifsbursting);
Krunal Sonidf29bc42018-11-15 13:26:29 -080011170 if (status) {
11171 hdd_err("Failed to get rts sifs bursting value");
11172 goto out;
11173 }
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053011174
11175 if (enable_rts_sifsbursting) {
11176 set_value = enable_rts_sifsbursting;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011177 sme_cli_set_command(0,
11178 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
11179 set_value, PDEV_CMD);
11180 }
11181
Dustin Brown05d81302018-09-11 16:49:22 -070011182 ucfg_mlme_get_sap_get_peer_info(hdd_ctx->psoc, &value);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +053011183 if (value) {
11184 set_value = value;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011185 sme_cli_set_command(0,
11186 (int)WMI_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
11187 set_value, PDEV_CMD);
11188 }
11189
Dustin Brown1dbefe62018-09-11 16:32:03 -070011190 status = ucfg_mlme_get_num_11b_tx_chains(hdd_ctx->psoc,
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +053011191 &num_11b_tx_chains);
11192 if (status != QDF_STATUS_SUCCESS) {
11193 hdd_err("Failed to get num_11b_tx_chains");
11194 goto out;
11195 }
11196
Dustin Brown1dbefe62018-09-11 16:32:03 -070011197 status = ucfg_mlme_get_num_11ag_tx_chains(hdd_ctx->psoc,
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +053011198 &num_11ag_tx_chains);
11199 if (status != QDF_STATUS_SUCCESS) {
11200 hdd_err("Failed to get num_11ag_tx_chains");
11201 goto out;
11202 }
11203
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053011204 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &bval);
11205 if (!QDF_IS_STATUS_SUCCESS(status))
11206 hdd_err("unable to get vht_enable2x2");
11207
11208 if (!bval) {
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011209 if (num_11b_tx_chains > 1)
11210 num_11b_tx_chains = 1;
11211 if (num_11ag_tx_chains > 1)
11212 num_11ag_tx_chains = 1;
11213 }
11214 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
11215 num_11b_tx_chains);
11216 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
11217 num_11ag_tx_chains);
11218 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
11219 num_abg_tx_chains, PDEV_CMD);
Arun Khandavallifae92942016-08-01 13:31:08 +053011220
Paul Zhang02526cd2018-09-20 17:47:46 +080011221 if (!ucfg_reg_is_regdb_offloaded(hdd_ctx->psoc))
11222 ucfg_reg_program_default_cc(hdd_ctx->pdev,
11223 hdd_ctx->reg.reg_domain);
11224
Arun Khandavallifae92942016-08-01 13:31:08 +053011225 ret = hdd_pre_enable_configure(hdd_ctx);
11226 if (ret) {
11227 hdd_err("Failed to pre-configure cds");
11228 goto out;
11229 }
11230
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -080011231 /* Always get latest IPA resources allocated from cds_open and configure
11232 * IPA module before configuring them to FW. Sequence required as crash
11233 * observed otherwise.
11234 */
Dustin Brown07901ec2018-09-07 11:02:41 -070011235 if (ucfg_ipa_uc_ol_init(hdd_ctx->pdev,
11236 cds_get_context(QDF_MODULE_ID_QDF_DEVICE))) {
Manikandan Mohan2e803a02017-02-14 14:57:53 -080011237 hdd_err("Failed to setup pipes");
11238 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -080011239 }
11240
Arun Khandavallifae92942016-08-01 13:31:08 +053011241 /*
11242 * Start CDS which starts up the SME/MAC/HAL modules and everything
11243 * else
11244 */
Dustin Brown1dbefe62018-09-11 16:32:03 -070011245 status = cds_enable(hdd_ctx->psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053011246
11247 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011248 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +053011249 goto out;
11250 }
11251
11252 status = hdd_post_cds_enable_config(hdd_ctx);
11253 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011254 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070011255 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +053011256 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +053011257 status = hdd_register_bcn_cb(hdd_ctx);
11258 if (!QDF_IS_STATUS_SUCCESS(status)) {
Paul Zhange03cf4c2018-01-19 18:33:22 +080011259 hdd_err("hdd_register_bcn_cb failed");
Abhishek Singh6092fbb2017-01-25 18:10:31 +053011260 goto cds_disable;
11261 }
Arun Khandavallifae92942016-08-01 13:31:08 +053011262
Dustin Browne7e71d32018-05-11 16:00:08 -070011263 ret = hdd_features_init(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053011264 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070011265 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +053011266
Mohit Khanna81418772018-10-30 14:14:46 -070011267 /* Donot disable rx offload on concurrency for lithium based targets */
11268 if (!(hdd_ctx->target_type == TARGET_TYPE_QCA6290 ||
11269 hdd_ctx->target_type == TARGET_TYPE_QCA6390))
11270 if (hdd_ctx->ol_enable)
11271 dp_cbs.hdd_disable_rx_ol_in_concurrency =
11272 hdd_disable_rx_ol_in_concurrency;
Yun Parkff6a16a2017-09-26 16:38:18 -070011273 dp_cbs.hdd_set_rx_mode_rps_cb = hdd_set_rx_mode_rps;
jiadbb47e132018-03-30 16:28:30 +080011274 dp_cbs.hdd_ipa_set_mcc_mode_cb = hdd_ipa_set_mcc_mode;
Manjunathappa Prakasha0cbc922018-05-08 19:48:34 -070011275 dp_cbs.hdd_v2_flow_pool_map = hdd_v2_flow_pool_map;
11276 dp_cbs.hdd_v2_flow_pool_unmap = hdd_v2_flow_pool_unmap;
Dustin Brown1dbefe62018-09-11 16:32:03 -070011277 status = policy_mgr_register_dp_cb(hdd_ctx->psoc, &dp_cbs);
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070011278 if (!QDF_IS_STATUS_SUCCESS(status)) {
Yun Parkff6a16a2017-09-26 16:38:18 -070011279 hdd_debug("Failed to register DP cb with Policy Manager");
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070011280 goto cds_disable;
11281 }
Dustin Brown1dbefe62018-09-11 16:32:03 -070011282 status = policy_mgr_register_mode_change_cb(hdd_ctx->psoc,
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053011283 wlan_hdd_send_mode_change_event);
11284 if (!QDF_IS_STATUS_SUCCESS(status)) {
11285 hdd_debug("Failed to register mode change cb with Policy Manager");
11286 goto cds_disable;
11287 }
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070011288
Jeff Johnson8bb61112018-03-31 13:33:54 -070011289 if (hdd_green_ap_enable_egap(hdd_ctx))
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +053011290 hdd_debug("enhance green ap is not enabled");
11291
Nachiket Kukadedd302662017-07-13 17:31:44 +053011292 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
11293 hdd_debug("Failed to set wow pulse");
11294
Ashish Kumar Dhanotiyacb14b112018-01-19 19:26:44 +053011295 sme_cli_set_command(0, WMI_PDEV_PARAM_GCMP_SUPPORT_ENABLE,
Manikandan Mohan66df7fc2019-01-08 17:57:05 -080011296 ucfg_fwol_get_gcmp_enable(hdd_ctx->psoc), PDEV_CMD);
Wu Gao66454f12018-09-26 19:55:41 +080011297
11298 auto_power_fail_mode =
11299 ucfg_pmo_get_auto_power_fail_mode(hdd_ctx->psoc);
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +053011300 sme_cli_set_command(0, WMI_PDEV_AUTO_DETECT_POWER_FAILURE,
Wu Gao66454f12018-09-26 19:55:41 +080011301 auto_power_fail_mode, PDEV_CMD);
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +053011302
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053011303 status = ucfg_get_enable_phy_reg_retention(hdd_ctx->psoc,
11304 &enable_phy_reg_retention);
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +053011305
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053011306 if (QDF_IS_STATUS_ERROR(status))
11307 return -EINVAL;
11308
11309 if (enable_phy_reg_retention)
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +053011310 wma_cli_set_command(0, WMI_PDEV_PARAM_FAST_PWR_TRANSITION,
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053011311 enable_phy_reg_retention, PDEV_CMD);
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +053011312
Jeff Johnson0187c622019-01-04 06:39:44 -080011313 hdd_hastings_bt_war_initialize(hdd_ctx);
11314
Arun Khandavallifae92942016-08-01 13:31:08 +053011315 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070011316
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070011317cds_disable:
Dustin Brown1dbefe62018-09-11 16:32:03 -070011318 cds_disable(hdd_ctx->psoc);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070011319
Arun Khandavallifae92942016-08-01 13:31:08 +053011320out:
11321 return -EINVAL;
11322}
11323
11324/**
11325 * hdd_deconfigure_cds() -De-Configure cds
11326 * @hdd_ctx: HDD context
11327 *
11328 * Deconfigure Cds modules before WLAN firmware is down.
11329 *
11330 * Return: 0 on success and errno on failure.
11331 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011332static int hdd_deconfigure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +053011333{
11334 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -070011335 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053011336
Dustin Brown491d54b2018-03-14 12:39:11 -070011337 hdd_enter();
Yu Wangf5d5b5f2017-05-25 22:38:32 +080011338
11339 /* De-init features */
11340 hdd_features_deinit(hdd_ctx);
11341
Dustin Brown1dbefe62018-09-11 16:32:03 -070011342 qdf_status = policy_mgr_deregister_mode_change_cb(hdd_ctx->psoc);
Srinivas Girigowdad2412882018-09-07 15:42:04 -070011343 if (!QDF_IS_STATUS_SUCCESS(qdf_status))
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053011344 hdd_debug("Failed to deregister mode change cb with Policy Manager");
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053011345
Dustin Brown1dbefe62018-09-11 16:32:03 -070011346 qdf_status = cds_disable(hdd_ctx->psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053011347 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
11348 hdd_err("Failed to Disable the CDS Modules! :%d",
11349 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -070011350 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011351 }
11352
Dustin Brown07901ec2018-09-07 11:02:41 -070011353 if (ucfg_ipa_uc_ol_deinit(hdd_ctx->pdev) != QDF_STATUS_SUCCESS) {
Sravan Kumar Kairam71121712017-04-15 00:34:42 +053011354 hdd_err("Failed to disconnect pipes");
11355 ret = -EINVAL;
11356 }
11357
Dustin Browne74003f2018-03-14 12:51:58 -070011358 hdd_exit();
Houston Hoffman6640cf32016-10-10 16:44:29 -070011359 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053011360}
11361
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070011362#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
11363static void hdd_deregister_policy_manager_callback(
11364 struct wlan_objmgr_psoc *psoc)
11365{
11366 if (QDF_STATUS_SUCCESS !=
11367 policy_mgr_deregister_hdd_cb(psoc)) {
11368 hdd_err("HDD callback deregister with policy manager failed");
11369 }
11370}
11371#else
11372static void hdd_deregister_policy_manager_callback(
11373 struct wlan_objmgr_psoc *psoc)
11374{
11375}
11376#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053011377
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011378int hdd_wlan_stop_modules(struct hdd_context *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +053011379{
11380 void *hif_ctx;
11381 qdf_device_t qdf_ctx;
11382 QDF_STATUS qdf_status;
Dustin Brown4bc0a622017-12-06 15:56:50 -080011383 bool is_recovery_stop = cds_is_driver_recovering();
Sourav Mohapatra808e3d42018-07-04 09:34:23 +053011384 int ret = 0;
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +053011385 int debugfs_threads;
Arunk Khandavallia6305a32018-01-25 11:19:18 +053011386 struct target_psoc_info *tgt_hdl;
Arun Khandavallifae92942016-08-01 13:31:08 +053011387
Dustin Brown491d54b2018-03-14 12:39:11 -070011388 hdd_enter();
Arun Khandavallifae92942016-08-01 13:31:08 +053011389 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
11390 if (!qdf_ctx) {
11391 hdd_err("QDF device context NULL");
11392 return -EINVAL;
11393 }
11394
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070011395 cds_set_module_stop_in_progress(true);
Arun Khandavallifae92942016-08-01 13:31:08 +053011396
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +053011397 debugfs_threads = hdd_return_debugfs_threads_count();
Dustin Brown70111822017-03-30 15:31:40 -070011398
Dustin Brown3fdaaf62019-03-18 14:00:16 -070011399 if (debugfs_threads > 0 || hdd_ctx->is_wiphy_suspended) {
11400 hdd_warn("Debugfs threads %d, wiphy suspend %d",
11401 debugfs_threads, hdd_ctx->is_wiphy_suspended);
Dustin Brown70111822017-03-30 15:31:40 -070011402
Sourav Mohapatra808e3d42018-07-04 09:34:23 +053011403 if (IS_IDLE_STOP && !ftm_mode) {
Dustin Brown4c663222018-10-23 14:19:36 -070011404 hdd_psoc_idle_timer_start(hdd_ctx);
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070011405 cds_set_module_stop_in_progress(false);
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011406
Dustin Brown70111822017-03-30 15:31:40 -070011407 return 0;
11408 }
Rajeev Kumar86177c22017-03-16 19:44:39 -070011409 }
11410
Liangwei Dong857cb842019-04-28 04:55:17 -040011411 hdd_deregister_policy_manager_callback(hdd_ctx->psoc);
11412
Kabilan Kannan6edafeb2017-11-16 16:34:34 -080011413 /* free user wowl patterns */
11414 hdd_free_user_wowl_ptrns();
11415
Arun Khandavallifae92942016-08-01 13:31:08 +053011416 switch (hdd_ctx->driver_status) {
11417 case DRIVER_MODULES_UNINITIALIZED:
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011418 hdd_debug("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011419 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053011420 case DRIVER_MODULES_CLOSED:
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011421 hdd_debug("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011422 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053011423 case DRIVER_MODULES_ENABLED:
Dustin Brown1a20b082018-08-03 17:27:15 -070011424 hdd_info("Wlan transitioning (CLOSED <- ENABLED)");
11425
Nirav Shah6aeecf92019-02-13 14:05:03 +053011426 if (hdd_get_conparam() == QDF_GLOBAL_FTM_MODE ||
11427 hdd_get_conparam() == QDF_GLOBAL_EPPING_MODE)
Dustin Brown1a20b082018-08-03 17:27:15 -070011428 break;
Dustin Brown550f6d22017-12-14 15:44:01 -080011429
Komal Seelamf2136bb2016-09-28 18:30:44 +053011430 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +053011431 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011432 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +053011433 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011434 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011435 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011436 hdd_debug("successfully Disabled the CDS modules!");
Dustin Brown550f6d22017-12-14 15:44:01 -080011437
Arun Khandavallifae92942016-08-01 13:31:08 +053011438 break;
11439 default:
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011440 QDF_DEBUG_PANIC("Unknown driver state:%d",
Arun Khandavallifae92942016-08-01 13:31:08 +053011441 hdd_ctx->driver_status);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011442 ret = -EINVAL;
11443 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053011444 }
11445
Arunk Khandavalli890f6d92018-10-30 20:18:28 +053011446 hdd_sysfs_destroy_powerstats_interface();
Amar Singhal18081642018-01-26 16:04:13 -080011447 hdd_sysfs_destroy_version_interface();
Arunk Khandavalli890f6d92018-10-30 20:18:28 +053011448 hdd_sysfs_destroy_driver_root_obj();
Dustin Brown550f6d22017-12-14 15:44:01 -080011449 hdd_debug("Closing CDS modules!");
Amar Singhal18081642018-01-26 16:04:13 -080011450
Nirav Shah6aeecf92019-02-13 14:05:03 +053011451 if (hdd_get_conparam() != QDF_GLOBAL_EPPING_MODE) {
11452 qdf_status = cds_post_disable();
11453 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
11454 hdd_err("Failed to process post CDS disable! :%d",
11455 qdf_status);
11456 ret = -EINVAL;
11457 QDF_ASSERT(0);
11458 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070011459
Nirav Shah6aeecf92019-02-13 14:05:03 +053011460 /* De-register the SME callbacks */
11461 hdd_deregister_cb(hdd_ctx);
Sourav Mohapatra674925f2018-04-16 11:16:58 +053011462
Nirav Shah6aeecf92019-02-13 14:05:03 +053011463 hdd_runtime_suspend_context_deinit(hdd_ctx);
psimhadeea0a12017-12-18 14:50:02 -080011464
Nirav Shah6aeecf92019-02-13 14:05:03 +053011465 qdf_status = cds_dp_close(hdd_ctx->psoc);
11466 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
11467 hdd_warn("Failed to stop CDS DP: %d", qdf_status);
11468 ret = -EINVAL;
11469 QDF_ASSERT(0);
11470 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070011471
Nirav Shah6aeecf92019-02-13 14:05:03 +053011472 qdf_status = cds_close(hdd_ctx->psoc);
11473 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
11474 hdd_warn("Failed to stop CDS: %d", qdf_status);
11475 ret = -EINVAL;
11476 QDF_ASSERT(0);
11477 }
Rakshith Suresh Patkard9f4e612018-09-12 12:10:38 +053011478
Nirav Shah6aeecf92019-02-13 14:05:03 +053011479 qdf_status = wbuff_module_deinit();
11480 if (!QDF_IS_STATUS_SUCCESS(qdf_status))
11481 hdd_err("WBUFF de-init unsuccessful; status: %d",
11482 qdf_status);
Rakshith Suresh Patkard9f4e612018-09-12 12:10:38 +053011483
Nirav Shah6aeecf92019-02-13 14:05:03 +053011484 hdd_component_pdev_close(hdd_ctx->pdev);
Rakshith Suresh Patkard9f4e612018-09-12 12:10:38 +053011485
Nirav Shah6aeecf92019-02-13 14:05:03 +053011486 hdd_component_psoc_close(hdd_ctx->psoc);
11487 dispatcher_pdev_close(hdd_ctx->pdev);
11488 ret = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
11489 if (ret) {
11490 hdd_err("Failed to destroy pdev; errno:%d", ret);
11491 QDF_ASSERT(0);
11492 }
Liangwei Dong50a64a72018-01-11 01:17:00 -050011493 }
11494
11495 /*
11496 * Reset total mac phy during module stop such that during
11497 * next module start same psoc is used to populate new service
11498 * ready data
11499 */
Dustin Brown1dbefe62018-09-11 16:32:03 -070011500 tgt_hdl = wlan_psoc_get_tgt_if_handle(hdd_ctx->psoc);
Arunk Khandavallia6305a32018-01-25 11:19:18 +053011501 if (tgt_hdl)
11502 target_psoc_set_total_mac_phy_cnt(tgt_hdl, 0);
11503
Liangwei Dong50a64a72018-01-11 01:17:00 -050011504
Arun Khandavallifae92942016-08-01 13:31:08 +053011505 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
11506 if (!hif_ctx) {
11507 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011508 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011509 }
11510
Arunk Khandavalli4b404332017-09-26 12:46:00 +053011511 if (hdd_ctx->target_hw_name) {
11512 qdf_mem_free(hdd_ctx->target_hw_name);
11513 hdd_ctx->target_hw_name = NULL;
11514 }
11515
Lin Bai7bae1032019-04-30 12:29:36 +080011516 if (hdd_get_conparam() == QDF_GLOBAL_EPPING_MODE) {
Visweswara Tanukuc949ad22019-03-20 13:00:30 +053011517 epping_disable();
11518 epping_close();
11519 }
11520
Sravan Kumar Kairam27296782017-04-21 22:04:18 +053011521 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053011522
11523 ol_cds_free();
11524
Dustin Brownc2a156e2018-10-25 16:56:27 -070011525 if (IS_IDLE_STOP) {
Arun Khandavallifae92942016-08-01 13:31:08 +053011526 ret = pld_power_off(qdf_ctx->dev);
11527 if (ret)
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011528 hdd_err("Failed to power down device; errno:%d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +053011529 }
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011530
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011531 /* Free the cache channels of the command SET_DISABLE_CHANNEL_LIST */
11532 wlan_hdd_free_cache_channels(hdd_ctx);
Arunk Khandavalli847969d2017-09-25 15:15:36 +053011533
Sourav Mohapatra9036f652019-04-02 15:02:59 +053011534 /* Free the resources allocated while storing SAR config. These needs
11535 * to be freed only in the case when it is not SSR. As in the case of
11536 * SSR, the values needs to be intact so that it can be restored during
11537 * reinit path.
11538 */
11539 if (!is_recovery_stop)
11540 wlan_hdd_free_sar_config(hdd_ctx);
11541
Jingxiang Ge3de02752019-01-29 15:47:03 +080011542 hdd_sap_destroy_ctx_all(hdd_ctx, is_recovery_stop);
11543
Dustin Brown29533f22018-07-24 13:11:56 -070011544 hdd_check_for_leaks(hdd_ctx, is_recovery_stop);
Dustin Brown26b3d042017-12-21 11:13:27 -080011545 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -080011546
Arunk Khandavalli847969d2017-09-25 15:15:36 +053011547 /* Once the firmware sequence is completed reset this flag */
11548 hdd_ctx->imps_enabled = false;
Arun Khandavallifae92942016-08-01 13:31:08 +053011549 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -080011550 hdd_info("Wlan transitioned (now CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053011551
Kai Liueabb1df2018-11-08 14:58:54 +080011552 pld_request_bus_bandwidth(hdd_ctx->parent_dev, PLD_BUS_WIDTH_NONE);
11553
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011554done:
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070011555 cds_set_module_stop_in_progress(false);
Dustin Brown4bc0a622017-12-06 15:56:50 -080011556
Dustin Browne74003f2018-03-14 12:51:58 -070011557 hdd_exit();
Arun Khandavallifae92942016-08-01 13:31:08 +053011558
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011559 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053011560}
11561
Wen Gong3f003382018-05-14 14:26:37 +080011562#ifdef WLAN_FEATURE_MEMDUMP_ENABLE
Arun Khandavallifae92942016-08-01 13:31:08 +053011563/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011564 * hdd_state_info_dump() - prints state information of hdd layer
11565 * @buf: buffer pointer
11566 * @size: size of buffer to be filled
11567 *
11568 * This function is used to dump state information of hdd layer
11569 *
11570 * Return: None
11571 */
11572static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
11573{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011574 struct hdd_context *hdd_ctx;
Jeff Johnson40dae4e2017-08-29 14:00:25 -070011575 struct hdd_station_ctx *hdd_sta_ctx;
Jeff Johnson9d295242017-08-29 14:39:48 -070011576 struct hdd_adapter *adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011577 uint16_t len = 0;
11578 char *buf = *buf_ptr;
11579
11580 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11581 if (!hdd_ctx) {
11582 hdd_err("Failed to get hdd context ");
11583 return;
11584 }
11585
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011586 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011587
11588 len += scnprintf(buf + len, *size - len,
Jeff Johnson214671b2017-10-30 19:45:23 -070011589 "\n is_wiphy_suspended %d", hdd_ctx->is_wiphy_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011590 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -080011591 "\n is_scheduler_suspended %d",
11592 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011593
Dustin Brown920397d2017-12-13 16:27:50 -080011594 hdd_for_each_adapter(hdd_ctx, adapter) {
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011595 if (adapter->dev)
11596 len += scnprintf(buf + len, *size - len,
11597 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +080011598 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011599 "\n device_mode: %d", adapter->device_mode);
11600 switch (adapter->device_mode) {
11601 case QDF_STA_MODE:
11602 case QDF_P2P_CLIENT_MODE:
11603 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
11604 len += scnprintf(buf + len, *size - len,
Jeff Johnsone7951512019-02-27 10:02:51 -080011605 "\n conn_state: %d",
11606 hdd_sta_ctx->conn_info.conn_state);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011607 break;
11608
11609 default:
11610 break;
11611 }
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011612 }
11613
11614 *size -= len;
11615 *buf_ptr += len;
11616}
11617
11618/**
11619 * hdd_register_debug_callback() - registration function for hdd layer
11620 * to print hdd state information
11621 *
11622 * Return: None
11623 */
11624static void hdd_register_debug_callback(void)
11625{
11626 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
11627}
Wen Gong3f003382018-05-14 14:26:37 +080011628#else /* WLAN_FEATURE_MEMDUMP_ENABLE */
Wen Gongaa6d55d2018-04-26 16:33:21 +080011629static void hdd_register_debug_callback(void)
11630{
11631}
Wen Gong3f003382018-05-14 14:26:37 +080011632#endif /* WLAN_FEATURE_MEMDUMP_ENABLE */
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011633
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +053011634/*
11635 * wlan_init_bug_report_lock() - Initialize bug report lock
11636 *
11637 * This function is used to create bug report lock
11638 *
11639 * Return: None
11640 */
11641static void wlan_init_bug_report_lock(void)
11642{
Jeff Johnson2b6982c2018-05-29 14:56:11 -070011643 struct cds_context *p_cds_context;
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +053011644
11645 p_cds_context = cds_get_global_context();
11646 if (!p_cds_context) {
11647 hdd_err("cds context is NULL");
11648 return;
11649 }
11650
11651 qdf_spinlock_create(&p_cds_context->bug_report_lock);
11652}
11653
Nirav Shahd21a2e32018-04-20 16:34:43 +053011654#ifdef CONFIG_DP_TRACE
Mohit Khannaf8f96822017-05-17 17:11:59 -070011655void hdd_dp_trace_init(struct hdd_config *config)
11656{
Mohit Khannaf8f96822017-05-17 17:11:59 -070011657 bool live_mode = DP_TRACE_CONFIG_DEFAULT_LIVE_MODE;
11658 uint8_t thresh = DP_TRACE_CONFIG_DEFAULT_THRESH;
11659 uint16_t thresh_time_limit = DP_TRACE_CONFIG_DEFAULT_THRESH_TIME_LIMIT;
11660 uint8_t verbosity = DP_TRACE_CONFIG_DEFAULT_VERBOSTY;
11661 uint8_t proto_bitmap = DP_TRACE_CONFIG_DEFAULT_BITMAP;
11662 uint8_t config_params[DP_TRACE_CONFIG_NUM_PARAMS];
11663 uint8_t num_entries = 0;
Lin Baiaa7f8d72017-10-18 17:23:45 +080011664 uint32_t bw_compute_interval;
Mohit Khannaf8f96822017-05-17 17:11:59 -070011665
Nirav Shahd21a2e32018-04-20 16:34:43 +053011666 if (!config->enable_dp_trace) {
11667 hdd_err("dp trace is disabled from ini");
11668 return;
11669 }
11670
Mohit Khannaf8f96822017-05-17 17:11:59 -070011671 hdd_string_to_u8_array(config->dp_trace_config, config_params,
11672 &num_entries, sizeof(config_params));
11673
11674 /* calculating, num bw timer intervals in a second (1000ms) */
Lin Baiaa7f8d72017-10-18 17:23:45 +080011675 bw_compute_interval = GET_BW_COMPUTE_INTV(config);
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080011676 if (bw_compute_interval <= 1000 && bw_compute_interval > 0)
Lin Baiaa7f8d72017-10-18 17:23:45 +080011677 thresh_time_limit = 1000 / bw_compute_interval;
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080011678 else if (bw_compute_interval > 1000) {
11679 hdd_err("busBandwidthComputeInterval > 1000, using 1000");
11680 thresh_time_limit = 1;
11681 } else
Mohit Khannaf8f96822017-05-17 17:11:59 -070011682 hdd_err("busBandwidthComputeInterval is 0, using defaults");
11683
11684 switch (num_entries) {
11685 case 4:
11686 proto_bitmap = config_params[3];
Alok Kumarb5a33a22018-05-07 18:09:14 +053011687 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070011688 case 3:
11689 verbosity = config_params[2];
Alok Kumarb5a33a22018-05-07 18:09:14 +053011690 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070011691 case 2:
11692 thresh = config_params[1];
Alok Kumarb5a33a22018-05-07 18:09:14 +053011693 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070011694 case 1:
11695 live_mode = config_params[0];
Alok Kumarb5a33a22018-05-07 18:09:14 +053011696 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070011697 default:
Dustin Browna7bb6ae2018-08-16 16:51:50 -070011698 hdd_debug("live_mode %u thresh %u time_limit %u verbosity %u bitmap 0x%x",
11699 live_mode, thresh, thresh_time_limit,
11700 verbosity, proto_bitmap);
Mohit Khannaf8f96822017-05-17 17:11:59 -070011701 };
11702
11703 qdf_dp_trace_init(live_mode, thresh, thresh_time_limit,
11704 verbosity, proto_bitmap);
11705
11706}
Nirav Shahd21a2e32018-04-20 16:34:43 +053011707#endif
11708
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011709#ifdef DISABLE_CHANNEL_LIST
Dustin Brown623e7e32018-09-05 14:27:50 -070011710static QDF_STATUS wlan_hdd_cache_chann_mutex_create(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011711{
11712 return qdf_mutex_create(&hdd_ctx->cache_channel_lock);
11713}
11714#else
Dustin Brown623e7e32018-09-05 14:27:50 -070011715static QDF_STATUS wlan_hdd_cache_chann_mutex_create(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011716{
Dustin Brown623e7e32018-09-05 14:27:50 -070011717 return QDF_STATUS_SUCCESS;
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011718}
11719#endif
11720
Dustin Brown693b5352019-01-17 10:00:31 -080011721static QDF_STATUS hdd_open_adapter_no_trans(struct hdd_context *hdd_ctx,
11722 enum QDF_OPMODE op_mode,
11723 const char *iface_name,
11724 uint8_t *mac_addr_bytes)
11725{
Dustin Brown2c5e0482019-02-05 16:14:43 -080011726 struct osif_vdev_sync *vdev_sync;
Dustin Brown693b5352019-01-17 10:00:31 -080011727 struct hdd_adapter *adapter;
11728 QDF_STATUS status;
11729 int errno;
11730
11731 QDF_BUG(rtnl_is_locked());
Dustin Brown693b5352019-01-17 10:00:31 -080011732
Dustin Brown2c5e0482019-02-05 16:14:43 -080011733 errno = osif_vdev_sync_create(hdd_ctx->parent_dev, &vdev_sync);
Dustin Brown693b5352019-01-17 10:00:31 -080011734 if (errno)
11735 return qdf_status_from_os_return(errno);
11736
11737 adapter = hdd_open_adapter(hdd_ctx, op_mode, iface_name,
11738 mac_addr_bytes, NET_NAME_UNKNOWN, true);
11739 if (!adapter) {
11740 status = QDF_STATUS_E_INVAL;
11741 goto destroy_sync;
11742 }
11743
Dustin Brown2c5e0482019-02-05 16:14:43 -080011744 osif_vdev_sync_register(adapter->dev, vdev_sync);
Dustin Brown693b5352019-01-17 10:00:31 -080011745
11746 return QDF_STATUS_SUCCESS;
11747
11748destroy_sync:
Dustin Brown2c5e0482019-02-05 16:14:43 -080011749 osif_vdev_sync_destroy(vdev_sync);
Dustin Brown693b5352019-01-17 10:00:31 -080011750
11751 return status;
11752}
11753
11754#ifdef WLAN_OPEN_P2P_INTERFACE
11755/**
11756 * hdd_open_p2p_interface - Open P2P interface
11757 * @hdd_ctx: HDD context
11758 *
11759 * Return: QDF_STATUS
11760 */
11761static QDF_STATUS hdd_open_p2p_interface(struct hdd_context *hdd_ctx)
11762{
11763 QDF_STATUS status;
11764 bool p2p_dev_addr_admin;
11765 bool is_p2p_locally_administered = false;
11766
11767 cfg_p2p_get_device_addr_admin(hdd_ctx->psoc, &p2p_dev_addr_admin);
11768
11769 if (p2p_dev_addr_admin) {
11770 if (hdd_ctx->num_provisioned_addr &&
11771 !(hdd_ctx->provisioned_mac_addr[0].bytes[0] & 0x02)) {
11772 hdd_ctx->p2p_device_address =
11773 hdd_ctx->provisioned_mac_addr[0];
11774
11775 /*
11776 * Generate the P2P Device Address. This consists of
11777 * the device's primary MAC address with the locally
11778 * administered bit set.
11779 */
11780
11781 hdd_ctx->p2p_device_address.bytes[0] |= 0x02;
11782 is_p2p_locally_administered = true;
11783 } else if (!(hdd_ctx->derived_mac_addr[0].bytes[0] & 0x02)) {
11784 hdd_ctx->p2p_device_address =
11785 hdd_ctx->derived_mac_addr[0];
11786 /*
11787 * Generate the P2P Device Address. This consists of
11788 * the device's primary MAC address with the locally
11789 * administered bit set.
11790 */
11791 hdd_ctx->p2p_device_address.bytes[0] |= 0x02;
11792 is_p2p_locally_administered = true;
11793 }
11794 }
11795 if (!is_p2p_locally_administered) {
11796 uint8_t *p2p_dev_addr;
11797
11798 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx,
11799 QDF_P2P_DEVICE_MODE);
11800 if (!p2p_dev_addr) {
11801 hdd_err("Failed to get MAC address for new p2p device");
11802 return QDF_STATUS_E_INVAL;
11803 }
11804
11805 qdf_mem_copy(hdd_ctx->p2p_device_address.bytes,
11806 p2p_dev_addr, QDF_MAC_ADDR_SIZE);
11807 }
11808
11809 status = hdd_open_adapter_no_trans(hdd_ctx, QDF_P2P_DEVICE_MODE,
11810 "p2p%d",
11811 hdd_ctx->p2p_device_address.bytes);
11812 if (QDF_IS_STATUS_ERROR(status)) {
11813 hdd_err("Failed to open p2p interface");
11814 return QDF_STATUS_E_INVAL;
11815 }
11816
11817 return QDF_STATUS_SUCCESS;
11818}
11819#else
11820static inline QDF_STATUS hdd_open_p2p_interface(struct hdd_context *hdd_ctx)
11821{
11822 return QDF_STATUS_SUCCESS;
11823}
11824#endif
11825
11826static QDF_STATUS hdd_open_ocb_interface(struct hdd_context *hdd_ctx)
11827{
11828 QDF_STATUS status;
11829 uint8_t *mac_addr;
11830
11831 mac_addr = wlan_hdd_get_intf_addr(hdd_ctx, QDF_OCB_MODE);
11832 status = hdd_open_adapter_no_trans(hdd_ctx, QDF_OCB_MODE,
11833 "wlanocb%d", mac_addr);
11834 if (QDF_IS_STATUS_ERROR(status))
11835 hdd_err("Failed to open 802.11p interface");
11836
11837 return status;
11838}
11839
11840static QDF_STATUS hdd_open_concurrent_interface(struct hdd_context *hdd_ctx)
11841{
11842 QDF_STATUS status;
11843 const char *iface_name;
11844 uint8_t *mac_addr;
11845
11846 if (qdf_str_eq(hdd_ctx->config->enable_concurrent_sta, ""))
11847 return QDF_STATUS_SUCCESS;
11848
11849 iface_name = hdd_ctx->config->enable_concurrent_sta;
11850 mac_addr = wlan_hdd_get_intf_addr(hdd_ctx, QDF_STA_MODE);
11851 status = hdd_open_adapter_no_trans(hdd_ctx, QDF_STA_MODE,
11852 iface_name, mac_addr);
11853 if (QDF_IS_STATUS_ERROR(status))
11854 hdd_err("Failed to open concurrent station interface");
11855
11856 return status;
11857}
11858
Dustin Brown61cc3932018-10-18 16:12:13 -070011859static QDF_STATUS
11860hdd_open_adapters_for_mission_mode(struct hdd_context *hdd_ctx)
Dustin Browna2deeb72018-10-18 14:19:27 -070011861{
Dustin Browna2deeb72018-10-18 14:19:27 -070011862 enum dot11p_mode dot11p_mode;
Dustin Brown61cc3932018-10-18 16:12:13 -070011863 QDF_STATUS status;
Dustin Brown693b5352019-01-17 10:00:31 -080011864 uint8_t *mac_addr;
Dustin Browna2deeb72018-10-18 14:19:27 -070011865
11866 ucfg_mlme_get_dot11p_mode(hdd_ctx->psoc, &dot11p_mode);
11867
11868 /* Create only 802.11p interface? */
11869 if (dot11p_mode == CFG_11P_STANDALONE)
Dustin Brown61cc3932018-10-18 16:12:13 -070011870 return hdd_open_ocb_interface(hdd_ctx);
Dustin Browna2deeb72018-10-18 14:19:27 -070011871
Dustin Brown693b5352019-01-17 10:00:31 -080011872 mac_addr = wlan_hdd_get_intf_addr(hdd_ctx, QDF_STA_MODE);
11873 status = hdd_open_adapter_no_trans(hdd_ctx, QDF_STA_MODE,
11874 "wlan%d", mac_addr);
11875 if (QDF_IS_STATUS_ERROR(status))
11876 return status;
Dustin Browna2deeb72018-10-18 14:19:27 -070011877
Dustin Brown61cc3932018-10-18 16:12:13 -070011878 /* opening concurrent STA is best effort, continue on error */
11879 hdd_open_concurrent_interface(hdd_ctx);
Dustin Browna2deeb72018-10-18 14:19:27 -070011880
Dustin Brown61cc3932018-10-18 16:12:13 -070011881 status = hdd_open_p2p_interface(hdd_ctx);
11882 if (status)
Dustin Browna2deeb72018-10-18 14:19:27 -070011883 goto err_close_adapters;
11884
11885 /* Open 802.11p Interface */
11886 if (dot11p_mode == CFG_11P_CONCURRENT) {
Dustin Brown61cc3932018-10-18 16:12:13 -070011887 status = hdd_open_ocb_interface(hdd_ctx);
11888 if (QDF_IS_STATUS_ERROR(status))
Dustin Browna2deeb72018-10-18 14:19:27 -070011889 goto err_close_adapters;
11890 }
11891
Dustin Brown61cc3932018-10-18 16:12:13 -070011892 return QDF_STATUS_SUCCESS;
Dustin Browna2deeb72018-10-18 14:19:27 -070011893
11894err_close_adapters:
11895 hdd_close_all_adapters(hdd_ctx, true);
11896
Dustin Brown61cc3932018-10-18 16:12:13 -070011897 return status;
Dustin Browna2deeb72018-10-18 14:19:27 -070011898}
11899
Dustin Brown61cc3932018-10-18 16:12:13 -070011900static QDF_STATUS hdd_open_adapters_for_ftm_mode(struct hdd_context *hdd_ctx)
Dustin Browna2deeb72018-10-18 14:19:27 -070011901{
Dustin Brown693b5352019-01-17 10:00:31 -080011902 uint8_t *mac_addr = wlan_hdd_get_intf_addr(hdd_ctx, QDF_FTM_MODE);
Dustin Brown61cc3932018-10-18 16:12:13 -070011903
Dustin Brown693b5352019-01-17 10:00:31 -080011904 return hdd_open_adapter_no_trans(hdd_ctx, QDF_FTM_MODE,
11905 "wlan%d", mac_addr);
Dustin Brown61cc3932018-10-18 16:12:13 -070011906}
11907
11908static QDF_STATUS
11909hdd_open_adapters_for_monitor_mode(struct hdd_context *hdd_ctx)
11910{
Dustin Brown693b5352019-01-17 10:00:31 -080011911 uint8_t *mac_addr = wlan_hdd_get_intf_addr(hdd_ctx, QDF_MONITOR_MODE);
Dustin Brown61cc3932018-10-18 16:12:13 -070011912
Dustin Brown693b5352019-01-17 10:00:31 -080011913 return hdd_open_adapter_no_trans(hdd_ctx, QDF_MONITOR_MODE,
11914 "wlan%d", mac_addr);
Dustin Brown61cc3932018-10-18 16:12:13 -070011915}
11916
11917static QDF_STATUS hdd_open_adapters_for_epping_mode(struct hdd_context *hdd_ctx)
11918{
Nirav Shah6aeecf92019-02-13 14:05:03 +053011919 epping_enable_adapter();
Dustin Brown61cc3932018-10-18 16:12:13 -070011920 return QDF_STATUS_SUCCESS;
Dustin Brown61cc3932018-10-18 16:12:13 -070011921}
11922
11923typedef QDF_STATUS (*hdd_open_mode_handler)(struct hdd_context *hdd_ctx);
11924
11925static const hdd_open_mode_handler
11926hdd_open_mode_handlers[QDF_GLOBAL_MAX_MODE] = {
11927 [QDF_GLOBAL_MISSION_MODE] = hdd_open_adapters_for_mission_mode,
11928 [QDF_GLOBAL_FTM_MODE] = hdd_open_adapters_for_ftm_mode,
11929 [QDF_GLOBAL_MONITOR_MODE] = hdd_open_adapters_for_monitor_mode,
11930 [QDF_GLOBAL_EPPING_MODE] = hdd_open_adapters_for_epping_mode,
11931};
11932
Dustin Brown92bd8382018-10-31 15:49:46 -070011933static QDF_STATUS hdd_open_adapters_for_mode(struct hdd_context *hdd_ctx,
11934 enum QDF_GLOBAL_MODE driver_mode)
Dustin Brown61cc3932018-10-18 16:12:13 -070011935{
11936 QDF_STATUS status;
11937
11938 if (driver_mode < 0 ||
11939 driver_mode >= QDF_GLOBAL_MAX_MODE ||
11940 !hdd_open_mode_handlers[driver_mode]) {
11941 hdd_err("Driver mode %d not supported", driver_mode);
11942 return -ENOTSUPP;
11943 }
Dustin Browna2deeb72018-10-18 14:19:27 -070011944
11945 hdd_hold_rtnl_lock();
Dustin Brown61cc3932018-10-18 16:12:13 -070011946 status = hdd_open_mode_handlers[driver_mode](hdd_ctx);
Dustin Browna2deeb72018-10-18 14:19:27 -070011947 hdd_release_rtnl_lock();
11948
Dustin Brown92bd8382018-10-31 15:49:46 -070011949 return status;
Dustin Browna2deeb72018-10-18 14:19:27 -070011950}
11951
Dustin Brown623e7e32018-09-05 14:27:50 -070011952int hdd_wlan_startup(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011953{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011954 QDF_STATUS status;
Dustin Brown623e7e32018-09-05 14:27:50 -070011955 int errno;
Pragaspathi Thilagaraj784c4922018-12-02 22:47:29 +053011956 bool is_imps_enabled;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011957
Dustin Brown491d54b2018-03-14 12:39:11 -070011958 hdd_enter();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011959
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053011960 hdd_action_oui_config(hdd_ctx);
11961
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053011962 qdf_nbuf_init_replenish_timer();
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011963
Dustin Brown623e7e32018-09-05 14:27:50 -070011964 status = wlan_hdd_cache_chann_mutex_create(hdd_ctx);
11965 if (QDF_IS_STATUS_ERROR(status))
11966 return qdf_status_to_os_return(status);
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011967
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +053011968#ifdef FEATURE_WLAN_CH_AVOID
11969 mutex_init(&hdd_ctx->avoid_freq_lock);
11970#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053011971
Naveen Rawate02f8f52018-04-05 11:58:04 -070011972 osif_request_manager_init();
Dustin Brown021cecd2017-12-11 13:56:43 -080011973 hdd_driver_memdump_init();
Dustin Brown86d196b2018-08-02 11:51:49 -070011974 hdd_bus_bandwidth_init(hdd_ctx);
Dustin Brown021cecd2017-12-11 13:56:43 -080011975
Arunk Khandavalli5ff0375472019-01-11 17:26:47 +053011976#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
11977 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
11978 QDF_TIMER_TYPE_SW,
11979 hdd_skip_acs_scan_timer_handler,
11980 hdd_ctx);
11981 if (QDF_IS_STATUS_ERROR(status))
11982 hdd_err("Failed to init ACS Skip timer");
11983 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
11984#endif
11985
Dustin Brown623e7e32018-09-05 14:27:50 -070011986 errno = hdd_wlan_start_modules(hdd_ctx, false);
11987 if (errno) {
11988 hdd_err("Failed to start modules; errno:%d", errno);
11989 goto memdump_deinit;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011990 }
11991
Nirav Shah6aeecf92019-02-13 14:05:03 +053011992 if (hdd_get_conparam() == QDF_GLOBAL_EPPING_MODE)
11993 return 0;
11994
Yingying Tang80e15f32016-09-27 18:23:01 +080011995 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011996
Dustin Brown623e7e32018-09-05 14:27:50 -070011997 hdd_ctx->mac_handle = cds_get_context(QDF_MODULE_ID_SME);
11998 if (!hdd_ctx->mac_handle) {
Jeff Johnson16528362018-06-14 12:34:16 -070011999 hdd_err("Mac Handle is null");
Dustin Brown623e7e32018-09-05 14:27:50 -070012000 goto stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012001 }
12002
Dustin Brown623e7e32018-09-05 14:27:50 -070012003 errno = hdd_wiphy_init(hdd_ctx);
12004 if (errno) {
12005 hdd_err("Failed to initialize wiphy; errno:%d", errno);
12006 goto stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012007 }
12008
Nirav Shahd21a2e32018-04-20 16:34:43 +053012009 hdd_dp_trace_init(hdd_ctx->config);
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053012010
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053012011 errno = hdd_initialize_mac_address(hdd_ctx);
12012 if (errno) {
12013 hdd_err("MAC initializtion failed: %d", errno);
12014 goto unregister_wiphy;
12015 }
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -080012016
Dustin Brown623e7e32018-09-05 14:27:50 -070012017 errno = register_netdevice_notifier(&hdd_netdev_notifier);
12018 if (errno) {
12019 hdd_err("register_netdevice_notifier failed; errno:%d", errno);
12020 goto unregister_wiphy;
Paul Zhangfb02f452017-12-22 11:58:43 +080012021 }
Arun Khandavalli08479ba2017-08-07 19:56:23 +053012022
Sandeep Puligilla34618782019-01-04 17:42:42 -080012023 wlan_hdd_update_11n_mode(hdd_ctx);
Yingying Tang3ba3dbc2016-09-27 16:36:58 +080012024
Arunk Khandavalli40943af2017-05-15 19:25:34 +053012025 hdd_lpass_notify_wlan_version(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012026
Dustin Brown623e7e32018-09-05 14:27:50 -070012027 errno = hdd_register_notifiers(hdd_ctx);
12028 if (errno)
Arun Kumar Khandavalli4b6e2182019-04-29 18:32:09 +053012029 goto unregister_netdev;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -070012030
Paul Zhangfb02f452017-12-22 11:58:43 +080012031 status = wlansap_global_init();
Dustin Brown92bd8382018-10-31 15:49:46 -070012032 if (QDF_IS_STATUS_ERROR(status))
12033 goto unregister_notifiers;
Paul Zhangfb02f452017-12-22 11:58:43 +080012034
Pragaspathi Thilagaraj784c4922018-12-02 22:47:29 +053012035 ucfg_mlme_is_imps_enabled(hdd_ctx->psoc, &is_imps_enabled);
12036 hdd_set_idle_ps_config(hdd_ctx, is_imps_enabled);
Arun Kumar Khandavallideda5a82019-03-11 15:32:19 +053012037 hdd_debugfs_mws_coex_info_init(hdd_ctx);
Paul Zhang37185672019-05-14 11:20:14 +080012038 wlan_cfg80211_init_interop_issues_ap(hdd_ctx->pdev);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012039
Dustin Brown92bd8382018-10-31 15:49:46 -070012040 hdd_exit();
12041
12042 return 0;
12043
12044unregister_notifiers:
12045 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012046
Dustin Brown623e7e32018-09-05 14:27:50 -070012047unregister_netdev:
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053012048 unregister_netdevice_notifier(&hdd_netdev_notifier);
12049
Dustin Brown623e7e32018-09-05 14:27:50 -070012050unregister_wiphy:
Rachit Kankane30807332018-06-27 18:39:36 +053012051 qdf_dp_trace_deinit();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080012052 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012053
Dustin Brown623e7e32018-09-05 14:27:50 -070012054stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070012055 hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053012056
Dustin Brown623e7e32018-09-05 14:27:50 -070012057memdump_deinit:
Dustin Brown86d196b2018-08-02 11:51:49 -070012058 hdd_bus_bandwidth_deinit(hdd_ctx);
Dustin Brown021cecd2017-12-11 13:56:43 -080012059 hdd_driver_memdump_deinit();
Naveen Rawate02f8f52018-04-05 11:58:04 -070012060 osif_request_manager_deinit();
Dustin Brown623e7e32018-09-05 14:27:50 -070012061 qdf_nbuf_deinit_replenish_timer();
Ryan Hsucfef0ae2016-04-28 10:20:46 -070012062
Nachiket Kukade8003d252017-03-30 15:55:58 +053012063 if (cds_is_fw_down())
12064 hdd_err("Not setting the complete event as fw is down");
12065 else
Dustin Brown623e7e32018-09-05 14:27:50 -070012066 hdd_start_complete(errno);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012067
Dustin Browne74003f2018-03-14 12:51:58 -070012068 hdd_exit();
Dustin Brown92bd8382018-10-31 15:49:46 -070012069
Dustin Brown623e7e32018-09-05 14:27:50 -070012070 return errno;
Dustin Brown92bd8382018-10-31 15:49:46 -070012071}
12072
12073QDF_STATUS hdd_psoc_create_vdevs(struct hdd_context *hdd_ctx)
12074{
12075 enum QDF_GLOBAL_MODE driver_mode = hdd_get_conparam();
12076 QDF_STATUS status;
12077
12078 status = hdd_open_adapters_for_mode(hdd_ctx, driver_mode);
12079 if (QDF_IS_STATUS_ERROR(status)) {
12080 hdd_err("Failed to create vdevs; status:%d", status);
12081 return status;
12082 }
12083
12084 if (hdd_ctx->rps)
12085 hdd_set_rps_cpu_mask(hdd_ctx);
12086
Guisen Yang2780b922019-06-03 16:21:39 +080012087 if (driver_mode != QDF_GLOBAL_FTM_MODE &&
12088 driver_mode != QDF_GLOBAL_EPPING_MODE)
Dustin Brown92bd8382018-10-31 15:49:46 -070012089 hdd_psoc_idle_timer_start(hdd_ctx);
12090
12091 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012092}
12093
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012094/**
Arun Khandavallifae92942016-08-01 13:31:08 +053012095 * hdd_wlan_update_target_info() - update target type info
12096 * @hdd_ctx: HDD context
12097 * @context: hif context
12098 *
12099 * Update target info received from firmware in hdd context
12100 * Return:None
12101 */
12102
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012103void hdd_wlan_update_target_info(struct hdd_context *hdd_ctx, void *context)
Arun Khandavallifae92942016-08-01 13:31:08 +053012104{
12105 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
12106
12107 if (!tgt_info) {
12108 hdd_err("Target info is Null");
12109 return;
12110 }
12111
12112 hdd_ctx->target_type = tgt_info->target_type;
12113}
12114
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053012115void hdd_get_nud_stats_cb(void *data, struct rsp_stats *rsp, void *context)
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012116{
12117 struct hdd_context *hdd_ctx = (struct hdd_context *)data;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012118 int status;
12119 struct hdd_adapter *adapter = NULL;
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070012120 struct osif_request *request = NULL;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012121
Dustin Brown491d54b2018-03-14 12:39:11 -070012122 hdd_enter();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012123
12124 if (!rsp) {
12125 hdd_err("data is null");
12126 return;
12127 }
12128
12129 status = wlan_hdd_validate_context(hdd_ctx);
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053012130 if (status != 0)
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012131 return;
12132
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070012133 request = osif_request_get(context);
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053012134 if (!request) {
12135 hdd_err("obselete request");
12136 return;
12137 }
12138
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012139 adapter = hdd_get_adapter_by_vdev(hdd_ctx, rsp->vdev_id);
Jeff Johnsond36fa332019-03-18 13:42:25 -070012140 if ((!adapter) || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012141 hdd_err("Invalid adapter or adapter has invalid magic");
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070012142 osif_request_put(request);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012143 return;
12144 }
12145
Alok Kumarce2c29a2018-10-12 15:44:02 +053012146 hdd_debug("rsp->arp_req_enqueue :%x", rsp->arp_req_enqueue);
12147 hdd_debug("rsp->arp_req_tx_success :%x", rsp->arp_req_tx_success);
12148 hdd_debug("rsp->arp_req_tx_failure :%x", rsp->arp_req_tx_failure);
12149 hdd_debug("rsp->arp_rsp_recvd :%x", rsp->arp_rsp_recvd);
12150 hdd_debug("rsp->out_of_order_arp_rsp_drop_cnt :%x",
12151 rsp->out_of_order_arp_rsp_drop_cnt);
12152 hdd_debug("rsp->dad_detected :%x", rsp->dad_detected);
12153 hdd_debug("rsp->connect_status :%x", rsp->connect_status);
12154 hdd_debug("rsp->ba_session_establishment_status :%x",
12155 rsp->ba_session_establishment_status);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012156
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012157 adapter->hdd_stats.hdd_arp_stats.rx_fw_cnt = rsp->arp_rsp_recvd;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012158 adapter->dad |= rsp->dad_detected;
12159 adapter->con_status = rsp->connect_status;
12160
Poddar, Siddarth31797fa2018-01-22 17:24:15 +053012161 /* Flag true indicates connectivity check stats present. */
12162 if (rsp->connect_stats_present) {
Alok Kumarce2c29a2018-10-12 15:44:02 +053012163 hdd_debug("rsp->tcp_ack_recvd :%x", rsp->tcp_ack_recvd);
12164 hdd_debug("rsp->icmpv4_rsp_recvd :%x", rsp->icmpv4_rsp_recvd);
Poddar, Siddarth31797fa2018-01-22 17:24:15 +053012165 adapter->hdd_stats.hdd_tcp_stats.rx_fw_cnt = rsp->tcp_ack_recvd;
12166 adapter->hdd_stats.hdd_icmpv4_stats.rx_fw_cnt =
12167 rsp->icmpv4_rsp_recvd;
12168 }
12169
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070012170 osif_request_complete(request);
12171 osif_request_put(request);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012172
Dustin Browne74003f2018-03-14 12:51:58 -070012173 hdd_exit();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012174}
12175
Visweswara Tanuku633976b2019-01-07 16:13:12 +053012176#ifdef WLAN_FEATURE_MOTION_DETECTION
12177/**
12178 * hdd_md_host_evt_cb - Callback for Motion Detection Event
12179 * @ctx: HDD context
12180 * @event: motion detect event
12181 *
12182 * Callback for Motion Detection Event. Re-enables Motion
12183 * Detection again upon event
12184 *
12185 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and
12186 * QDF_STATUS_E_FAILURE on failure
12187 */
12188QDF_STATUS hdd_md_host_evt_cb(void *ctx, struct sir_md_evt *event)
12189{
12190 struct hdd_adapter *adapter = NULL;
12191 struct hdd_context *hdd_ctx;
12192 QDF_STATUS status;
12193 struct sme_motion_det_en motion_det;
12194
12195 if (!ctx || !event)
12196 return QDF_STATUS_E_INVAL;
12197
12198 hdd_ctx = (struct hdd_context *)ctx;
12199 status = wlan_hdd_validate_context(hdd_ctx);
12200 if (0 != status)
12201 return QDF_STATUS_E_INVAL;
12202
12203 adapter = hdd_get_adapter_by_vdev(hdd_ctx, event->vdev_id);
12204 if (!adapter || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
12205 hdd_err("Invalid adapter or adapter has invalid magic");
12206 return QDF_STATUS_E_INVAL;
12207 }
12208
12209 hdd_debug("Motion Detection CB vdev_id=%u, status=%u",
12210 event->vdev_id, event->status);
12211
12212 if (adapter->motion_detection_mode) {
12213 motion_det.vdev_id = event->vdev_id;
12214 motion_det.enable = 1;
12215 hdd_debug("Motion Detect CB -> Enable Motion Detection again");
12216 sme_motion_det_enable(hdd_ctx->mac_handle, &motion_det);
12217 }
12218
12219 return QDF_STATUS_SUCCESS;
12220}
12221#endif /* WLAN_FEATURE_MOTION_DETECTION */
12222
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012223/**
Arun Khandavallifae92942016-08-01 13:31:08 +053012224 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012225 * @hdd_ctx: HDD context
12226 *
12227 * Register the HDD callbacks to CDS/SME.
12228 *
12229 * Return: 0 for success or Error code for failure
12230 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012231int hdd_register_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012232{
12233 QDF_STATUS status;
12234 int ret = 0;
Jeff Johnson16528362018-06-14 12:34:16 -070012235 mac_handle_t mac_handle;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012236
Dustin Brown491d54b2018-03-14 12:39:11 -070012237 hdd_enter();
Sourav Mohapatra674925f2018-04-16 11:16:58 +053012238 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
12239 hdd_err("in ftm mode, no need to register callbacks");
12240 return ret;
12241 }
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012242
Jeff Johnson16528362018-06-14 12:34:16 -070012243 mac_handle = hdd_ctx->mac_handle;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012244
Jeff Johnson16528362018-06-14 12:34:16 -070012245 sme_register_oem_data_rsp_callback(mac_handle,
12246 hdd_send_oem_data_rsp_msg);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012247
Jeff Johnson16528362018-06-14 12:34:16 -070012248 sme_register_mgmt_frame_ind_callback(mac_handle,
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +053012249 hdd_indicate_mgmt_frame);
Jeff Johnson16528362018-06-14 12:34:16 -070012250 sme_set_tsfcb(mac_handle, hdd_get_tsf_cb, hdd_ctx);
Jeff Johnson16528362018-06-14 12:34:16 -070012251 sme_stats_ext_register_callback(mac_handle,
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012252 wlan_hdd_cfg80211_stats_ext_callback);
12253
Jeff Johnson16528362018-06-14 12:34:16 -070012254 sme_ext_scan_register_callback(mac_handle,
12255 wlan_hdd_cfg80211_extscan_callback);
12256 sme_stats_ext2_register_callback(mac_handle,
lifeng66831662017-05-19 16:01:35 +080012257 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012258
Jeff Johnson16528362018-06-14 12:34:16 -070012259 sme_set_rssi_threshold_breached_cb(mac_handle,
12260 hdd_rssi_threshold_breached);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012261
Jeff Johnson16528362018-06-14 12:34:16 -070012262 sme_set_link_layer_stats_ind_cb(mac_handle,
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012263 wlan_hdd_cfg80211_link_layer_stats_callback);
12264
Jeff Johnson16528362018-06-14 12:34:16 -070012265 sme_rso_cmd_status_cb(mac_handle, wlan_hdd_rso_cmd_status_cb);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +053012266
Jeff Johnson16528362018-06-14 12:34:16 -070012267 sme_set_link_layer_ext_cb(mac_handle,
Zhang Qianca38fb12016-12-23 11:10:48 +080012268 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
Abhinav Kumar338e57d2019-02-04 17:30:10 +053012269 sme_update_hidden_ssid_status_cb(mac_handle,
12270 hdd_hidden_ssid_enable_roaming);
Zhang Qianca38fb12016-12-23 11:10:48 +080012271
Jeff Johnson16528362018-06-14 12:34:16 -070012272 status = sme_set_lost_link_info_cb(mac_handle,
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +053012273 hdd_lost_link_info_cb);
12274 /* print error and not block the startup process */
12275 if (!QDF_IS_STATUS_SUCCESS(status))
12276 hdd_err("set lost link info callback failed");
12277
Poddar, Siddarth34872782017-08-10 14:08:51 +053012278 ret = hdd_register_data_stall_detect_cb();
12279 if (ret) {
12280 hdd_err("Register data stall detect detect callback failed.");
12281 return ret;
12282 }
12283
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012284 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
12285
Jeff Johnson16528362018-06-14 12:34:16 -070012286 sme_register_set_connection_info_cb(mac_handle,
12287 hdd_set_connection_in_progress,
12288 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053012289
Jeff Johnson16528362018-06-14 12:34:16 -070012290 status = sme_congestion_register_callback(mac_handle,
12291 hdd_update_cca_info_cb);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053012292 if (!QDF_IS_STATUS_SUCCESS(status))
12293 hdd_err("set congestion callback failed");
12294
Jeff Johnson16528362018-06-14 12:34:16 -070012295 status = sme_set_bt_activity_info_cb(mac_handle,
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +053012296 hdd_bt_activity_cb);
12297 if (!QDF_IS_STATUS_SUCCESS(status))
12298 hdd_err("set bt activity info callback failed");
12299
Jeff Johnson16528362018-06-14 12:34:16 -070012300 status = sme_register_tx_queue_cb(mac_handle,
Varun Reddy Yeturu076eaa82018-01-16 12:16:14 -080012301 hdd_tx_queue_cb);
12302 if (!QDF_IS_STATUS_SUCCESS(status))
12303 hdd_err("Register tx queue callback failed");
12304
Visweswara Tanuku633976b2019-01-07 16:13:12 +053012305#ifdef WLAN_FEATURE_MOTION_DETECTION
12306 sme_set_md_host_evt_cb(mac_handle, hdd_md_host_evt_cb, (void *)hdd_ctx);
12307#endif /* WLAN_FEATURE_MOTION_DETECTION */
12308
Dustin Browne74003f2018-03-14 12:51:58 -070012309 hdd_exit();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012310
12311 return ret;
12312}
12313
12314/**
12315 * hdd_deregister_cb() - De-Register HDD callbacks.
12316 * @hdd_ctx: HDD context
12317 *
12318 * De-Register the HDD callbacks to CDS/SME.
12319 *
12320 * Return: void
12321 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012322void hdd_deregister_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012323{
12324 QDF_STATUS status;
Poddar, Siddarth34872782017-08-10 14:08:51 +053012325 int ret;
Jeff Johnson16528362018-06-14 12:34:16 -070012326 mac_handle_t mac_handle;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012327
Dustin Brown491d54b2018-03-14 12:39:11 -070012328 hdd_enter();
Sourav Mohapatra674925f2018-04-16 11:16:58 +053012329 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
12330 hdd_err("in ftm mode, no need to deregister callbacks");
12331 return;
12332 }
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012333
Jeff Johnson16528362018-06-14 12:34:16 -070012334 mac_handle = hdd_ctx->mac_handle;
12335 sme_deregister_tx_queue_cb(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012336
Jeff Johnson16528362018-06-14 12:34:16 -070012337 sme_reset_link_layer_stats_ind_cb(mac_handle);
12338 sme_reset_rssi_threshold_breached_cb(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012339
Min Liud35ae312019-05-08 15:43:13 +080012340 sme_stats_ext_deregister_callback(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012341
Jeff Johnson16528362018-06-14 12:34:16 -070012342 status = sme_reset_tsfcb(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012343 if (!QDF_IS_STATUS_SUCCESS(status))
12344 hdd_err("Failed to de-register tsfcb the callback:%d",
12345 status);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012346
Poddar, Siddarth34872782017-08-10 14:08:51 +053012347 ret = hdd_deregister_data_stall_detect_cb();
12348 if (ret)
12349 hdd_err("Failed to de-register data stall detect event callback");
12350
Jeff Johnson16528362018-06-14 12:34:16 -070012351 sme_deregister_oem_data_rsp_callback(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012352
Dustin Browne74003f2018-03-14 12:51:58 -070012353 hdd_exit();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012354}
12355
12356/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012357 * hdd_softap_sta_deauth() - handle deauth req from HDD
Jeff Johnson50e37e92019-03-08 11:32:25 -080012358 * @adapter: Pointer to the HDD adapter
12359 * @param: Params to the operation
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012360 *
12361 * This to take counter measure to handle deauth req from HDD
12362 *
12363 * Return: None
12364 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012365QDF_STATUS hdd_softap_sta_deauth(struct hdd_adapter *adapter,
Jeff Johnson50e37e92019-03-08 11:32:25 -080012366 struct csr_del_sta_params *param)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012367{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012368 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012369
Dustin Brown491d54b2018-03-14 12:39:11 -070012370 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012371
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012372 /* Ignore request to deauth bcmc station */
Jeff Johnson50e37e92019-03-08 11:32:25 -080012373 if (param->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012374 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012375
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012376 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012377 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Jeff Johnson50e37e92019-03-08 11:32:25 -080012378 param);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012379
Dustin Browne74003f2018-03-14 12:51:58 -070012380 hdd_exit();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012381 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012382}
12383
12384/**
12385 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
Jeff Johnson50e37e92019-03-08 11:32:25 -080012386 * @adapter: Pointer to the HDD
12387 * @param: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012388 *
12389 * This to take counter measure to handle deauth req from HDD
12390 *
12391 * Return: None
12392 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012393void hdd_softap_sta_disassoc(struct hdd_adapter *adapter,
Jeff Johnson50e37e92019-03-08 11:32:25 -080012394 struct csr_del_sta_params *param)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012395{
Dustin Brown491d54b2018-03-14 12:39:11 -070012396 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012397
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012398 /* Ignore request to disassoc bcmc station */
Jeff Johnson50e37e92019-03-08 11:32:25 -080012399 if (param->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012400 return;
12401
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012402 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Jeff Johnson50e37e92019-03-08 11:32:25 -080012403 param);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012404}
12405
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012406void wlan_hdd_disable_roaming(struct hdd_adapter *cur_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012407{
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012408 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(cur_adapter);
12409 struct hdd_adapter *adapter = NULL;
12410 struct csr_roam_profile *roam_profile;
12411 struct hdd_station_ctx *sta_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012412
Dustin Brown1dbefe62018-09-11 16:32:03 -070012413 if (!policy_mgr_is_sta_active_connection_exists(hdd_ctx->psoc)) {
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012414 hdd_debug("No active sta session");
12415 return;
12416 }
12417
12418 hdd_for_each_adapter(hdd_ctx, adapter) {
12419 roam_profile = hdd_roam_profile(adapter);
12420 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
12421
Jeff Johnson5a6fc962019-02-04 14:20:25 -080012422 if (cur_adapter->vdev_id != adapter->vdev_id &&
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012423 adapter->device_mode == QDF_STA_MODE &&
12424 hdd_conn_is_connected(sta_ctx)) {
Jeff Johnson5a6fc962019-02-04 14:20:25 -080012425 hdd_debug("%d Disable roaming", adapter->vdev_id);
Jeff Johnson16528362018-06-14 12:34:16 -070012426 sme_stop_roaming(hdd_ctx->mac_handle,
Jeff Johnson5a6fc962019-02-04 14:20:25 -080012427 adapter->vdev_id,
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012428 ecsr_driver_disabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012429 }
12430 }
12431}
12432
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012433void wlan_hdd_enable_roaming(struct hdd_adapter *cur_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012434{
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012435 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(cur_adapter);
12436 struct hdd_adapter *adapter = NULL;
12437 struct csr_roam_profile *roam_profile;
12438 struct hdd_station_ctx *sta_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012439
Dustin Brown1dbefe62018-09-11 16:32:03 -070012440 if (!policy_mgr_is_sta_active_connection_exists(hdd_ctx->psoc)) {
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012441 hdd_debug("No active sta session");
12442 return;
12443 }
12444
12445 hdd_for_each_adapter(hdd_ctx, adapter) {
12446 roam_profile = hdd_roam_profile(adapter);
12447 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
12448
Jeff Johnson5a6fc962019-02-04 14:20:25 -080012449 if (cur_adapter->vdev_id != adapter->vdev_id &&
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012450 adapter->device_mode == QDF_STA_MODE &&
12451 hdd_conn_is_connected(sta_ctx)) {
Jeff Johnson5a6fc962019-02-04 14:20:25 -080012452 hdd_debug("%d Enable roaming", adapter->vdev_id);
Jeff Johnson16528362018-06-14 12:34:16 -070012453 sme_start_roaming(hdd_ctx->mac_handle,
Jeff Johnson5a6fc962019-02-04 14:20:25 -080012454 adapter->vdev_id,
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012455 REASON_DRIVER_ENABLED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012456 }
12457 }
12458}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012459
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053012460/**
12461 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
12462 * @skb: sk buffer pointer
12463 *
12464 * Sends the bcast message to SVC multicast group with generic nl socket
12465 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
12466 *
12467 * Return: None
12468 */
12469static void nl_srv_bcast_svc(struct sk_buff *skb)
12470{
12471#ifdef CNSS_GENL
12472 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
12473#else
12474 nl_srv_bcast(skb);
12475#endif
12476}
12477
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012478void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012479{
12480 struct sk_buff *skb;
12481 struct nlmsghdr *nlh;
12482 tAniMsgHdr *ani_hdr;
12483 void *nl_data = NULL;
12484 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012485 struct radio_index_tlv *radio_info;
12486 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012487
12488 if (in_interrupt() || irqs_disabled() || in_atomic())
12489 flags = GFP_ATOMIC;
12490
12491 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
12492
Jeff Johnsond36fa332019-03-18 13:42:25 -070012493 if (!skb)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012494 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012495
12496 nlh = (struct nlmsghdr *)skb->data;
12497 nlh->nlmsg_pid = 0; /* from kernel */
12498 nlh->nlmsg_flags = 0;
12499 nlh->nlmsg_seq = 0;
12500 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
12501
12502 ani_hdr = NLMSG_DATA(nlh);
12503 ani_hdr->type = type;
12504
12505 switch (type) {
12506 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053012507 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012508 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012509 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070012510 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012511 ani_hdr->length = 0;
12512 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012513 break;
12514 case WLAN_SVC_WLAN_STATUS_IND:
12515 case WLAN_SVC_WLAN_VERSION_IND:
12516 case WLAN_SVC_DFS_CAC_START_IND:
12517 case WLAN_SVC_DFS_CAC_END_IND:
12518 case WLAN_SVC_DFS_RADAR_DETECT_IND:
12519 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
12520 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080012521 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053012522 case WLAN_SVC_RPS_ENABLE_IND:
Orhan K AKYILDIZe7445a22017-01-19 21:21:47 -080012523 case WLAN_SVC_CORE_MINFREQ:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012524 ani_hdr->length = len;
12525 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
12526 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
12527 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012528 break;
12529
12530 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070012531 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012532 type);
12533 kfree_skb(skb);
12534 return;
12535 }
12536
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012537 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080012538 * Add radio index at the end of the svc event in TLV format
12539 * to maintain the backward compatibility with userspace
12540 * applications.
12541 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012542
12543 tlv_len = 0;
12544
12545 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
12546 < WLAN_NL_MAX_PAYLOAD) {
12547 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
12548 sizeof(*ani_hdr) + len);
12549 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
12550 radio_info->length = (unsigned short) sizeof(radio_info->radio);
12551 radio_info->radio = radio;
12552 tlv_len = sizeof(*radio_info);
Dustin Browna2868622018-03-20 11:38:14 -070012553 hdd_debug("Added radio index tlv - radio index %d",
12554 radio_info->radio);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012555 }
12556
12557 nlh->nlmsg_len += tlv_len;
12558 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
12559
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053012560 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012561}
12562
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012563#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
12564void wlan_hdd_auto_shutdown_cb(void)
12565{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012566 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012567
12568 if (!hdd_ctx)
12569 return;
12570
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012571 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012572 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
12573 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012574}
12575
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012576void wlan_hdd_auto_shutdown_enable(struct hdd_context *hdd_ctx, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012577{
Jeff Johnson9d295242017-08-29 14:39:48 -070012578 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012579 bool ap_connected = false, sta_connected = false;
Jeff Johnson16528362018-06-14 12:34:16 -070012580 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012581
Jeff Johnson16528362018-06-14 12:34:16 -070012582 mac_handle = hdd_ctx->mac_handle;
12583 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012584 return;
12585
Dundi Raviteja8e338282018-09-25 17:16:04 +053012586 if (hdd_ctx->config->wlan_auto_shutdown == 0)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012587 return;
12588
12589 if (enable == false) {
Jeff Johnson16528362018-06-14 12:34:16 -070012590 if (sme_set_auto_shutdown_timer(mac_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012591 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012592 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012593 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012594 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070012595 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012596 return;
12597 }
12598
12599 /* To enable shutdown timer check conncurrency */
Dustin Brown1dbefe62018-09-11 16:32:03 -070012600 if (policy_mgr_concurrent_open_sessions_running(hdd_ctx->psoc)) {
Dustin Brown920397d2017-12-13 16:27:50 -080012601 hdd_for_each_adapter(hdd_ctx, adapter) {
12602 if (adapter->device_mode == QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012603 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
Jeff Johnsone7951512019-02-27 10:02:51 -080012604 conn_info.conn_state ==
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012605 eConnectionState_Associated) {
12606 sta_connected = true;
12607 break;
12608 }
12609 }
Dustin Brown920397d2017-12-13 16:27:50 -080012610
12611 if (adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012612 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
Jeff Johnson136c51b2017-10-27 20:02:41 -070012613 ap_active == true) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012614 ap_connected = true;
12615 break;
12616 }
12617 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012618 }
12619 }
12620
12621 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012622 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012623 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012624 }
Jeff Johnson68755312017-02-10 11:46:55 -080012625
Jeff Johnson16528362018-06-14 12:34:16 -070012626 if (sme_set_auto_shutdown_timer(mac_handle,
Dundi Raviteja8e338282018-09-25 17:16:04 +053012627 hdd_ctx->config->wlan_auto_shutdown)
Jeff Johnson68755312017-02-10 11:46:55 -080012628 != QDF_STATUS_SUCCESS)
12629 hdd_err("Failed to start wlan auto shutdown timer");
12630 else
Dustin Brown5e89ef82018-03-14 11:50:23 -070012631 hdd_info("Auto Shutdown timer for %d seconds enabled",
Dundi Raviteja8e338282018-09-25 17:16:04 +053012632 hdd_ctx->config->wlan_auto_shutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012633}
12634#endif
12635
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070012636struct hdd_adapter *
12637hdd_get_con_sap_adapter(struct hdd_adapter *this_sap_adapter,
12638 bool check_start_bss)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012639{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012640 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070012641 struct hdd_adapter *adapter, *con_sap_adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012642
12643 con_sap_adapter = NULL;
12644
Dustin Brown920397d2017-12-13 16:27:50 -080012645 hdd_for_each_adapter(hdd_ctx, adapter) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080012646 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
12647 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012648 adapter != this_sap_adapter) {
12649 if (check_start_bss) {
12650 if (test_bit(SOFTAP_BSS_STARTED,
12651 &adapter->event_flags)) {
12652 con_sap_adapter = adapter;
12653 break;
12654 }
12655 } else {
12656 con_sap_adapter = adapter;
12657 break;
12658 }
12659 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012660 }
12661
12662 return con_sap_adapter;
12663}
12664
Tiger Yu8b119e92019-04-09 13:55:07 +080012665#ifdef WLAN_FEATURE_DP_BUS_BANDWIDTH
Jeff Johnson9d295242017-08-29 14:39:48 -070012666static inline bool hdd_adapter_is_sta(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012667{
Dustin Brown5ec6b552017-03-31 12:11:40 -070012668 return adapter->device_mode == QDF_STA_MODE ||
12669 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012670}
12671
Jeff Johnson9d295242017-08-29 14:39:48 -070012672static inline bool hdd_adapter_is_ap(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012673{
Dustin Brown5ec6b552017-03-31 12:11:40 -070012674 return adapter->device_mode == QDF_SAP_MODE ||
12675 adapter->device_mode == QDF_P2P_GO_MODE;
12676}
12677
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012678static bool hdd_any_adapter_is_assoc(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012679{
Dustin Brown920397d2017-12-13 16:27:50 -080012680 struct hdd_adapter *adapter;
Dustin Brown5ec6b552017-03-31 12:11:40 -070012681
Dustin Brown920397d2017-12-13 16:27:50 -080012682 hdd_for_each_adapter(hdd_ctx, adapter) {
12683 if (hdd_adapter_is_sta(adapter) &&
Dustin Brown5ec6b552017-03-31 12:11:40 -070012684 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
Jeff Johnsone7951512019-02-27 10:02:51 -080012685 conn_info.conn_state == eConnectionState_Associated) {
Dustin Brown5ec6b552017-03-31 12:11:40 -070012686 return true;
12687 }
12688
Dustin Brown920397d2017-12-13 16:27:50 -080012689 if (hdd_adapter_is_ap(adapter) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -070012690 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active) {
Dustin Brown5ec6b552017-03-31 12:11:40 -070012691 return true;
12692 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070012693 }
12694
12695 return false;
12696}
12697
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012698static void __hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012699{
Dustin Browna20bad52019-03-05 12:03:30 -080012700 qdf_periodic_work_start(&hdd_ctx->bus_bw_work,
12701 hdd_ctx->config->bus_bw_compute_interval);
Dustin Brown5ec6b552017-03-31 12:11:40 -070012702}
12703
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012704void hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012705{
Dustin Brown491d54b2018-03-14 12:39:11 -070012706 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012707
Dustin Brown5ec6b552017-03-31 12:11:40 -070012708 __hdd_bus_bw_compute_timer_start(hdd_ctx);
12709
Dustin Browne74003f2018-03-14 12:51:58 -070012710 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012711}
12712
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012713void hdd_bus_bw_compute_timer_try_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012714{
Dustin Brown491d54b2018-03-14 12:39:11 -070012715 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012716
Dustin Brown5ec6b552017-03-31 12:11:40 -070012717 if (hdd_any_adapter_is_assoc(hdd_ctx))
12718 __hdd_bus_bw_compute_timer_start(hdd_ctx);
12719
Dustin Browne74003f2018-03-14 12:51:58 -070012720 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012721}
12722
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012723static void __hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012724{
Dustin Browna20bad52019-03-05 12:03:30 -080012725 if (!qdf_periodic_work_stop_sync(&hdd_ctx->bus_bw_work))
12726 return;
12727
Dustin Brown07901ec2018-09-07 11:02:41 -070012728 ucfg_ipa_set_perf_level(hdd_ctx->pdev, 0, 0);
Dustin Brown5ec6b552017-03-31 12:11:40 -070012729 hdd_reset_tcp_delack(hdd_ctx);
Tiger Yue40e7832019-04-25 10:46:53 +080012730 cdp_pdev_reset_driver_del_ack(cds_get_context(QDF_MODULE_ID_SOC),
12731 cds_get_context(QDF_MODULE_ID_TXRX));
Dustin Brown5ec6b552017-03-31 12:11:40 -070012732}
12733
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012734void hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012735{
Dustin Brown491d54b2018-03-14 12:39:11 -070012736 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012737
Dustin Brown5ec6b552017-03-31 12:11:40 -070012738 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
12739
Dustin Browne74003f2018-03-14 12:51:58 -070012740 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012741}
12742
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012743void hdd_bus_bw_compute_timer_try_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012744{
Dustin Brown491d54b2018-03-14 12:39:11 -070012745 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012746
Dustin Brown5ec6b552017-03-31 12:11:40 -070012747 if (!hdd_any_adapter_is_assoc(hdd_ctx))
12748 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
12749
Dustin Browne74003f2018-03-14 12:51:58 -070012750 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012751}
Tiger Yu8b119e92019-04-09 13:55:07 +080012752#endif /*WLAN_FEATURE_DP_BUS_BANDWIDTH*/
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012753
12754/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012755 * wlan_hdd_stop_sap() - This function stops bss of SAP.
12756 * @ap_adapter: SAP adapter
12757 *
12758 * This function will process the stopping of sap adapter.
12759 *
12760 * Return: None
12761 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012762void wlan_hdd_stop_sap(struct hdd_adapter *ap_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012763{
Jeff Johnson87251032017-08-29 13:31:11 -070012764 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070012765 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053012766 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012767 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012768
Jeff Johnsond36fa332019-03-18 13:42:25 -070012769 if (!ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012770 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012771 return;
12772 }
12773
12774 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
12775 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053012776 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012777 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053012778
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012779 mutex_lock(&hdd_ctx->sap_lock);
12780 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080012781 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012782 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012783 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053012784 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012785 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070012786 sap_context)) {
Nachiket Kukade0396b732017-11-14 16:35:16 +053012787 qdf_status = qdf_wait_for_event_completion(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080012788 qdf_stop_bss_event,
Abhishek Singhd1f21c72019-01-21 15:16:34 +053012789 SME_CMD_STOP_BSS_TIMEOUT);
Anurag Chouhance0dc992016-02-16 18:18:03 +053012790 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012791 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070012792 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012793 return;
12794 }
12795 }
12796 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Dustin Brown1dbefe62018-09-11 16:32:03 -070012797 policy_mgr_decr_session_set_pcl(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012798 ap_adapter->device_mode,
Jeff Johnson5a6fc962019-02-04 14:20:25 -080012799 ap_adapter->vdev_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070012800 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053012801 false);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012802 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012803 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012804 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012805 }
12806 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012807}
12808
12809/**
12810 * wlan_hdd_start_sap() - this function starts bss of SAP.
12811 * @ap_adapter: SAP adapter
12812 *
12813 * This function will process the starting of sap adapter.
12814 *
12815 * Return: None
12816 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012817void wlan_hdd_start_sap(struct hdd_adapter *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012818{
Jeff Johnson87251032017-08-29 13:31:11 -070012819 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070012820 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053012821 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012822 struct hdd_context *hdd_ctx;
Jeff Johnson8f8ceb92019-03-24 08:16:55 -070012823 struct sap_config *sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012824
Jeff Johnsond36fa332019-03-18 13:42:25 -070012825 if (!ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012826 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012827 return;
12828 }
12829
Krunal Soni9b04c9b2016-03-10 13:08:05 -080012830 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070012831 hdd_err("SoftAp role has not been enabled");
12832 return;
12833 }
12834
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012835 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
12836 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
12837 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Jeff Johnsonb9424862017-10-30 08:49:35 -070012838 sap_config = &ap_adapter->session.ap.sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012839
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012840 mutex_lock(&hdd_ctx->sap_lock);
12841 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
12842 goto end;
12843
12844 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012845 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012846 goto end;
12847 }
Dustin Brown07901ec2018-09-07 11:02:41 -070012848 wlan_reg_set_channel_params(hdd_ctx->pdev,
Abhinav Kumar6f694482018-09-04 16:07:39 +053012849 hdd_ap_ctx->sap_config.channel, 0,
12850 &hdd_ap_ctx->sap_config.ch_params);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012851
Wei Song2f76f642016-11-18 16:32:53 +080012852 qdf_event_reset(&hostapd_state->qdf_event);
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070012853 if (wlansap_start_bss(hdd_ap_ctx->sap_context, hdd_hostapd_sap_event_cb,
Jeff Johnson91df29d2017-10-27 19:29:50 -070012854 &hdd_ap_ctx->sap_config,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012855 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012856 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012857 goto end;
12858
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012859 hdd_debug("Waiting for SAP to start");
Nachiket Kukade0396b732017-11-14 16:35:16 +053012860 qdf_status = qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Abhishek Singhd1f21c72019-01-21 15:16:34 +053012861 SME_CMD_START_BSS_TIMEOUT);
Anurag Chouhance0dc992016-02-16 18:18:03 +053012862 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012863 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012864 goto end;
12865 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070012866 hdd_info("SAP Start Success");
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053012867 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012868 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053012869 if (hostapd_state->bss_state == BSS_START) {
Dustin Brown1dbefe62018-09-11 16:32:03 -070012870 policy_mgr_incr_active_session(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012871 ap_adapter->device_mode,
Jeff Johnson5a6fc962019-02-04 14:20:25 -080012872 ap_adapter->vdev_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070012873 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053012874 true);
12875 }
Sourav Mohapatra9bc67112017-11-08 09:36:11 +053012876 mutex_unlock(&hdd_ctx->sap_lock);
12877
12878 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012879end:
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053012880 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012881 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070012882 /* SAP context and beacon cleanup will happen during driver unload
12883 * in hdd_stop_adapter
12884 */
12885 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
12886
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012887}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012888
12889/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012890 * hdd_get_fw_version() - Get FW version
12891 * @hdd_ctx: pointer to HDD context.
12892 * @major_spid: FW version - major spid.
12893 * @minor_spid: FW version - minor spid
12894 * @ssid: FW version - ssid
12895 * @crmid: FW version - crmid
12896 *
12897 * This function is called to get the firmware build version stored
12898 * as part of the HDD context
12899 *
12900 * Return: None
12901 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012902void hdd_get_fw_version(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012903 uint32_t *major_spid, uint32_t *minor_spid,
12904 uint32_t *siid, uint32_t *crmid)
12905{
12906 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
12907 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
12908 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
12909 *crmid = hdd_ctx->target_fw_version & 0x7fff;
12910}
12911
12912#ifdef QCA_CONFIG_SMP
12913/**
12914 * wlan_hdd_get_cpu() - get cpu_index
12915 *
12916 * Return: cpu_index
12917 */
12918int wlan_hdd_get_cpu(void)
12919{
12920 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012921
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012922 put_cpu();
12923 return cpu_index;
12924}
12925#endif
12926
12927/**
12928 * hdd_get_fwpath() - get framework path
12929 *
12930 * This function is used to get the string written by
12931 * userspace to start the wlan driver
12932 *
12933 * Return: string
12934 */
12935const char *hdd_get_fwpath(void)
12936{
12937 return fwpath.string;
12938}
12939
Dustin Brown94ce20f2018-09-04 13:11:38 -070012940static inline int hdd_state_query_cb(void)
12941{
12942 return !!wlan_hdd_validate_context(cds_get_context(QDF_MODULE_ID_HDD));
12943}
12944
Dustin Brown265e82b2019-03-18 11:07:32 -070012945static int __hdd_op_protect_cb(void **out_sync, const char *func)
12946{
12947 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12948
12949 if (!hdd_ctx)
12950 return -EAGAIN;
12951
12952 return __osif_psoc_sync_op_start(hdd_ctx->parent_dev,
12953 (struct osif_psoc_sync **)out_sync,
12954 func);
12955}
12956
12957static void __hdd_op_unprotect_cb(void *sync, const char *func)
12958{
12959 __osif_psoc_sync_op_stop(sync, func);
12960}
12961
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012962/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012963 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012964 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012965 * This function initilizes CDS global context with the help of cds_init. This
12966 * has to be the first function called after probe to get a valid global
12967 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012968 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012969 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012970 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012971int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012972{
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070012973 QDF_STATUS status;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012974
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070012975 status = cds_init();
wadesongae4ffd12017-10-24 16:45:54 +080012976 if (QDF_IS_STATUS_ERROR(status)) {
12977 hdd_err("Failed to allocate CDS context");
Dustin Brownc1d81af2019-03-01 13:43:43 -080012978 return -ENOMEM;
wadesongae4ffd12017-10-24 16:45:54 +080012979 }
Dustin Brownc1d81af2019-03-01 13:43:43 -080012980
Dustin Brown265e82b2019-03-18 11:07:32 -070012981 qdf_op_callbacks_register(__hdd_op_protect_cb, __hdd_op_unprotect_cb);
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053012982
12983 wlan_init_bug_report_lock();
12984
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012985#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
12986 wlan_logging_sock_init_svc();
12987#endif
12988
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012989 hdd_trace_init();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053012990 hdd_register_debug_callback();
Qiwei Caiad9b01c2018-07-09 17:21:31 +080012991 wlan_roam_debug_init();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012992
Dustin Brownfe50cef2018-12-10 10:42:37 -080012993 return 0;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012994}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012995
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012996/**
12997 * hdd_deinit() - Deinitialize Driver
12998 *
12999 * This function frees CDS global context with the help of cds_deinit. This
13000 * has to be the last function call in remove callback to free the global
13001 * context.
13002 */
13003void hdd_deinit(void)
13004{
Qiwei Caiad9b01c2018-07-09 17:21:31 +080013005 wlan_roam_debug_deinit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013006
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013007#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
13008 wlan_logging_sock_deinit_svc();
13009#endif
Qiwei Caiad9b01c2018-07-09 17:21:31 +080013010
13011 wlan_destroy_bug_report_lock();
Dustin Brown265e82b2019-03-18 11:07:32 -070013012 qdf_op_callbacks_register(NULL, NULL);
Qiwei Caiad9b01c2018-07-09 17:21:31 +080013013 cds_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013014}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013015
Yue Ma6e7b1a02017-04-03 14:17:46 -070013016#ifdef QCA_WIFI_NAPIER_EMULATION
13017#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
13018#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013019#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070013020#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013021
Sachin Ahujadddd2632017-03-07 19:07:24 +053013022static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
13023 struct file *file)
13024{
13025 return 0;
13026}
13027
13028static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
13029 const char __user *user_buf,
13030 size_t count,
13031 loff_t *f_pos)
13032{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053013033 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053013034 static const char wlan_off_str[] = "OFF";
13035 static const char wlan_on_str[] = "ON";
13036 int ret;
13037 unsigned long rc;
13038
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053013039 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053013040 pr_err("Failed to read buffer\n");
13041 return -EINVAL;
13042 }
13043
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053013044 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053013045 pr_debug("Wifi turning off from UI\n");
13046 goto exit;
13047 }
13048
Srinivas Girigowdad2412882018-09-07 15:42:04 -070013049 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) == 0)
Sachin Ahuja16904db2017-12-13 19:56:57 +053013050 pr_info("Wifi Turning On from UI\n");
Sachin Ahuja16904db2017-12-13 19:56:57 +053013051
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053013052 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053013053 pr_err("Invalid value received from framework");
13054 goto exit;
13055 }
13056
13057 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053013058 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053013059 rc = wait_for_completion_timeout(&wlan_start_comp,
13060 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
13061 if (!rc) {
Srinivas Girigowda09625b02018-09-10 15:28:09 -070013062 hdd_alert("Timed-out!!");
Sachin Ahujadddd2632017-03-07 19:07:24 +053013063 ret = -EINVAL;
Sachin Ahujadddd2632017-03-07 19:07:24 +053013064 return ret;
13065 }
13066
13067 hdd_start_complete(0);
13068 }
13069
13070exit:
13071 return count;
13072}
13073
13074
13075const struct file_operations wlan_hdd_state_fops = {
13076 .owner = THIS_MODULE,
13077 .open = wlan_hdd_state_ctrl_param_open,
13078 .write = wlan_hdd_state_ctrl_param_write,
13079};
13080
13081static int wlan_hdd_state_ctrl_param_create(void)
13082{
13083 unsigned int wlan_hdd_state_major = 0;
13084 int ret;
13085 struct device *dev;
13086
13087 device = MKDEV(wlan_hdd_state_major, 0);
13088
13089 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
13090 if (ret) {
13091 pr_err("Failed to register qcwlanstate");
13092 goto dev_alloc_err;
13093 }
13094 wlan_hdd_state_major = MAJOR(device);
13095
13096 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
13097 if (IS_ERR(class)) {
13098 pr_err("wlan_hdd_state class_create error");
13099 goto class_err;
13100 }
13101
13102 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
13103 if (IS_ERR(dev)) {
13104 pr_err("wlan_hdd_statedevice_create error");
13105 goto err_class_destroy;
13106 }
13107
13108 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
13109 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
13110 if (ret) {
13111 pr_err("Failed to add cdev error");
13112 goto cdev_add_err;
13113 }
13114
13115 pr_info("wlan_hdd_state %s major(%d) initialized",
13116 WLAN_MODULE_NAME, wlan_hdd_state_major);
13117
13118 return 0;
13119
13120cdev_add_err:
13121 device_destroy(class, device);
13122err_class_destroy:
13123 class_destroy(class);
13124class_err:
13125 unregister_chrdev_region(device, dev_num);
13126dev_alloc_err:
13127 return -ENODEV;
13128}
13129
13130static void wlan_hdd_state_ctrl_param_destroy(void)
13131{
13132 cdev_del(&wlan_hdd_state_cdev);
13133 device_destroy(class, device);
13134 class_destroy(class);
13135 unregister_chrdev_region(device, dev_num);
13136
13137 pr_info("Device node unregistered");
13138}
13139
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013140/**
Dustin Brownd585cb32018-09-12 17:12:23 -070013141 * hdd_component_init() - Initialize all components
Mukul Sharmad75a6672017-06-22 15:40:53 +053013142 *
Dustin Brownd585cb32018-09-12 17:12:23 -070013143 * Return: QDF_STATUS
Mukul Sharmad75a6672017-06-22 15:40:53 +053013144 */
Dustin Brownd585cb32018-09-12 17:12:23 -070013145static QDF_STATUS hdd_component_init(void)
Mukul Sharmad75a6672017-06-22 15:40:53 +053013146{
Dustin Brownd585cb32018-09-12 17:12:23 -070013147 QDF_STATUS status;
13148
13149 /* initialize converged components */
Arif Hussain49698112018-07-31 00:32:50 -070013150 status = target_if_init(wma_get_psoc_from_scn_handle);
Dustin Brownd585cb32018-09-12 17:12:23 -070013151 if (QDF_IS_STATUS_ERROR(status))
13152 return status;
13153
Abhishek Singhd5cf22d2019-01-08 19:51:09 +053013154 status = ucfg_mlme_global_init();
Arif Hussain49698112018-07-31 00:32:50 -070013155 if (QDF_IS_STATUS_ERROR(status))
13156 goto target_if_deinit;
13157
Abhishek Singhd5cf22d2019-01-08 19:51:09 +053013158 status = dispatcher_init();
13159 if (QDF_IS_STATUS_ERROR(status))
13160 goto mlme_global_deinit;
13161
Dustin Brownd585cb32018-09-12 17:12:23 -070013162 /* initialize non-converged components */
13163 status = ucfg_mlme_init();
13164 if (QDF_IS_STATUS_ERROR(status))
13165 goto dispatcher_deinit;
13166
13167 status = ucfg_fwol_init();
13168 if (QDF_IS_STATUS_ERROR(status))
13169 goto mlme_deinit;
13170
13171 status = disa_init();
13172 if (QDF_IS_STATUS_ERROR(status))
13173 goto fwol_deinit;
13174
13175 status = pmo_init();
13176 if (QDF_IS_STATUS_ERROR(status))
13177 goto disa_deinit;
13178
13179 status = ucfg_ocb_init();
13180 if (QDF_IS_STATUS_ERROR(status))
13181 goto pmo_deinit;
13182
13183 status = ipa_init();
13184 if (QDF_IS_STATUS_ERROR(status))
13185 goto ocb_deinit;
13186
13187 status = ucfg_action_oui_init();
13188 if (QDF_IS_STATUS_ERROR(status))
13189 goto ipa_deinit;
13190
Nachiket Kukade63bb63d2018-11-21 14:42:14 +053013191 status = nan_init();
13192 if (QDF_IS_STATUS_ERROR(status))
13193 goto action_oui_deinit;
13194
Wu Gao637d58a2018-12-08 10:37:34 +080013195 status = ucfg_p2p_init();
13196 if (QDF_IS_STATUS_ERROR(status))
13197 goto nan_deinit;
13198
Paul Zhang37185672019-05-14 11:20:14 +080013199 status = ucfg_interop_issues_ap_init();
Wu Gaod6b5e402018-12-03 22:09:24 +080013200 if (QDF_IS_STATUS_ERROR(status))
13201 goto p2p_deinit;
13202
Paul Zhang37185672019-05-14 11:20:14 +080013203 status = policy_mgr_init();
13204 if (QDF_IS_STATUS_ERROR(status))
13205 goto interop_issues_ap_deinit;
13206
Wu Gao5f793402018-12-08 11:04:00 +080013207 status = ucfg_tdls_init();
13208 if (QDF_IS_STATUS_ERROR(status))
13209 goto policy_deinit;
13210
gaurank kathpalia3ebc17b2019-05-29 10:25:09 +053013211 status = ucfg_blm_init();
13212 if (QDF_IS_STATUS_ERROR(status))
13213 goto tdls_deinit;
13214
Dustin Brownd585cb32018-09-12 17:12:23 -070013215 return QDF_STATUS_SUCCESS;
13216
gaurank kathpalia3ebc17b2019-05-29 10:25:09 +053013217tdls_deinit:
13218 ucfg_tdls_deinit();
13219
Wu Gao5f793402018-12-08 11:04:00 +080013220policy_deinit:
13221 policy_mgr_deinit();
Paul Zhang37185672019-05-14 11:20:14 +080013222interop_issues_ap_deinit:
13223 ucfg_interop_issues_ap_deinit();
Wu Gaod6b5e402018-12-03 22:09:24 +080013224p2p_deinit:
13225 ucfg_p2p_deinit();
Wu Gao637d58a2018-12-08 10:37:34 +080013226nan_deinit:
13227 nan_deinit();
Nachiket Kukade63bb63d2018-11-21 14:42:14 +053013228action_oui_deinit:
13229 ucfg_action_oui_deinit();
Dustin Brownd585cb32018-09-12 17:12:23 -070013230ipa_deinit:
13231 ipa_deinit();
13232ocb_deinit:
13233 ucfg_ocb_deinit();
13234pmo_deinit:
13235 pmo_deinit();
13236disa_deinit:
13237 disa_deinit();
13238fwol_deinit:
13239 ucfg_fwol_deinit();
13240mlme_deinit:
13241 ucfg_mlme_deinit();
13242dispatcher_deinit:
13243 dispatcher_deinit();
Abhishek Singhd5cf22d2019-01-08 19:51:09 +053013244mlme_global_deinit:
13245 ucfg_mlme_global_deinit();
Arif Hussain49698112018-07-31 00:32:50 -070013246target_if_deinit:
13247 target_if_deinit();
Dustin Brownd585cb32018-09-12 17:12:23 -070013248
13249 return status;
Mukul Sharmad75a6672017-06-22 15:40:53 +053013250}
13251
13252/**
Dustin Brownd585cb32018-09-12 17:12:23 -070013253 * hdd_component_deinit() - Deinitialize all components
Mukul Sharmad75a6672017-06-22 15:40:53 +053013254 *
13255 * Return: None
13256 */
Dustin Brownd585cb32018-09-12 17:12:23 -070013257static void hdd_component_deinit(void)
Mukul Sharmad75a6672017-06-22 15:40:53 +053013258{
Dustin Brownd585cb32018-09-12 17:12:23 -070013259 /* deinitialize non-converged components */
gaurank kathpalia3ebc17b2019-05-29 10:25:09 +053013260 ucfg_blm_deinit();
Wu Gao5f793402018-12-08 11:04:00 +080013261 ucfg_tdls_deinit();
Wu Gaod6b5e402018-12-03 22:09:24 +080013262 policy_mgr_deinit();
Paul Zhang37185672019-05-14 11:20:14 +080013263 ucfg_interop_issues_ap_deinit();
Wu Gao637d58a2018-12-08 10:37:34 +080013264 ucfg_p2p_deinit();
Nachiket Kukade63bb63d2018-11-21 14:42:14 +053013265 nan_deinit();
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053013266 ucfg_action_oui_deinit();
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +053013267 ipa_deinit();
Zhang Qian47e22ce2018-01-04 15:38:38 +080013268 ucfg_ocb_deinit();
Mukul Sharmad75a6672017-06-22 15:40:53 +053013269 pmo_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053013270 disa_deinit();
Sourav Mohapatra113685f2018-08-29 14:21:55 +053013271 ucfg_fwol_deinit();
Vignesh Viswanathana0921c42018-09-04 19:03:35 +053013272 ucfg_mlme_deinit();
Dustin Brownd585cb32018-09-12 17:12:23 -070013273
13274 /* deinitialize converged components */
13275 dispatcher_deinit();
Abhishek Singhd5cf22d2019-01-08 19:51:09 +053013276 ucfg_mlme_global_deinit();
Arif Hussain49698112018-07-31 00:32:50 -070013277 target_if_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053013278}
13279
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +053013280QDF_STATUS hdd_component_psoc_open(struct wlan_objmgr_psoc *psoc)
13281{
Sourav Mohapatra113685f2018-08-29 14:21:55 +053013282 QDF_STATUS status;
13283
13284 status = ucfg_mlme_psoc_open(psoc);
13285 if (QDF_IS_STATUS_ERROR(status))
13286 return status;
13287
gaurank kathpalia3ebc17b2019-05-29 10:25:09 +053013288 status = ucfg_blm_psoc_open(psoc);
13289 if (QDF_IS_STATUS_ERROR(status))
13290 goto err_blm;
13291
Sourav Mohapatra113685f2018-08-29 14:21:55 +053013292 status = ucfg_fwol_psoc_open(psoc);
13293 if (QDF_IS_STATUS_ERROR(status))
Wu Gao66454f12018-09-26 19:55:41 +080013294 goto err_fwol;
13295
13296 status = ucfg_pmo_psoc_open(psoc);
13297 if (QDF_IS_STATUS_ERROR(status))
13298 goto err_pmo;
Sourav Mohapatra113685f2018-08-29 14:21:55 +053013299
Krunal Sonie9c12f52018-10-04 11:45:42 -070013300 status = ucfg_policy_mgr_psoc_open(psoc);
13301 if (QDF_IS_STATUS_ERROR(status))
13302 goto err_plcy_mgr;
13303
Wu Gao637d58a2018-12-08 10:37:34 +080013304 status = ucfg_p2p_psoc_open(psoc);
13305 if (QDF_IS_STATUS_ERROR(status))
13306 goto err_p2p;
Wu Gao5f793402018-12-08 11:04:00 +080013307
13308 status = ucfg_tdls_psoc_open(psoc);
13309 if (QDF_IS_STATUS_ERROR(status))
13310 goto err_tdls;
13311
Sourav Mohapatra113685f2018-08-29 14:21:55 +053013312 return status;
13313
Wu Gao5f793402018-12-08 11:04:00 +080013314err_tdls:
13315 ucfg_tdls_psoc_close(psoc);
Wu Gao637d58a2018-12-08 10:37:34 +080013316err_p2p:
13317 ucfg_p2p_psoc_close(psoc);
Krunal Sonie9c12f52018-10-04 11:45:42 -070013318err_plcy_mgr:
13319 ucfg_pmo_psoc_close(psoc);
Wu Gao66454f12018-09-26 19:55:41 +080013320err_pmo:
13321 ucfg_fwol_psoc_close(psoc);
13322err_fwol:
gaurank kathpalia3ebc17b2019-05-29 10:25:09 +053013323 ucfg_blm_psoc_close(psoc);
13324err_blm:
Sourav Mohapatra113685f2018-08-29 14:21:55 +053013325 ucfg_mlme_psoc_close(psoc);
Krunal Sonie9c12f52018-10-04 11:45:42 -070013326
Sourav Mohapatra113685f2018-08-29 14:21:55 +053013327 return status;
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +053013328}
13329
13330void hdd_component_psoc_close(struct wlan_objmgr_psoc *psoc)
13331{
Wu Gao5f793402018-12-08 11:04:00 +080013332 ucfg_tdls_psoc_close(psoc);
Wu Gao637d58a2018-12-08 10:37:34 +080013333 ucfg_p2p_psoc_close(psoc);
Krunal Sonie9c12f52018-10-04 11:45:42 -070013334 ucfg_policy_mgr_psoc_close(psoc);
Wu Gao66454f12018-09-26 19:55:41 +080013335 ucfg_pmo_psoc_close(psoc);
Sourav Mohapatra113685f2018-08-29 14:21:55 +053013336 ucfg_fwol_psoc_close(psoc);
gaurank kathpalia3ebc17b2019-05-29 10:25:09 +053013337 ucfg_blm_psoc_close(psoc);
Vignesh Viswanathana0921c42018-09-04 19:03:35 +053013338 ucfg_mlme_psoc_close(psoc);
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +053013339}
13340
Nachiket Kukade98f562a2017-12-15 12:18:07 +053013341void hdd_component_psoc_enable(struct wlan_objmgr_psoc *psoc)
13342{
Zhang Qian47e22ce2018-01-04 15:38:38 +080013343 ocb_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053013344 disa_psoc_enable(psoc);
Nachiket Kukade63bb63d2018-11-21 14:42:14 +053013345 nan_psoc_enable(psoc);
Wu Gao637d58a2018-12-08 10:37:34 +080013346 p2p_psoc_enable(psoc);
Paul Zhang37185672019-05-14 11:20:14 +080013347 ucfg_interop_issues_ap_psoc_enable(psoc);
Wu Gaod6b5e402018-12-03 22:09:24 +080013348 policy_mgr_psoc_enable(psoc);
Wu Gaoa67c3802018-12-27 12:07:52 +080013349 ucfg_tdls_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053013350}
13351
13352void hdd_component_psoc_disable(struct wlan_objmgr_psoc *psoc)
13353{
Wu Gaoa67c3802018-12-27 12:07:52 +080013354 ucfg_tdls_psoc_disable(psoc);
Wu Gaod6b5e402018-12-03 22:09:24 +080013355 policy_mgr_psoc_disable(psoc);
Paul Zhang37185672019-05-14 11:20:14 +080013356 ucfg_interop_issues_ap_psoc_disable(psoc);
Wu Gao637d58a2018-12-08 10:37:34 +080013357 p2p_psoc_disable(psoc);
Nachiket Kukade63bb63d2018-11-21 14:42:14 +053013358 nan_psoc_disable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053013359 disa_psoc_disable(psoc);
Zhang Qian47e22ce2018-01-04 15:38:38 +080013360 ocb_psoc_disable(psoc);
Mukul Sharmad75a6672017-06-22 15:40:53 +053013361}
13362
Sandeep Puligillab7beb472018-08-13 22:54:20 -070013363QDF_STATUS hdd_component_pdev_open(struct wlan_objmgr_pdev *pdev)
13364{
13365 return ucfg_mlme_pdev_open(pdev);
13366}
13367
13368void hdd_component_pdev_close(struct wlan_objmgr_pdev *pdev)
13369{
13370 ucfg_mlme_pdev_close(pdev);
13371}
13372
Dustin Browna2a39dc2018-09-17 15:29:59 -070013373static QDF_STATUS hdd_qdf_print_init(void)
13374{
13375 QDF_STATUS status;
13376 int qdf_print_idx;
13377
13378 status = qdf_print_setup();
13379 if (QDF_IS_STATUS_ERROR(status)) {
13380 pr_err("Failed qdf_print_setup; status:%u\n", status);
13381 return status;
13382 }
13383
13384 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
13385 if (qdf_print_idx < 0) {
13386 pr_err("Failed to register for qdf_print_ctrl\n");
13387 return QDF_STATUS_E_FAILURE;
13388 }
13389
13390 qdf_set_pidx(qdf_print_idx);
13391
13392 return QDF_STATUS_SUCCESS;
13393}
13394
13395static void hdd_qdf_print_deinit(void)
13396{
13397 int qdf_pidx = qdf_get_pidx();
13398
13399 qdf_set_pidx(-1);
13400 qdf_print_ctrl_cleanup(qdf_pidx);
13401
13402 /* currently, no qdf print 'un-setup'*/
13403}
13404
13405static QDF_STATUS hdd_qdf_init(void)
13406{
13407 QDF_STATUS status;
13408
13409 status = hdd_qdf_print_init();
13410 if (QDF_IS_STATUS_ERROR(status))
13411 goto exit;
13412
13413 status = qdf_debugfs_init();
13414 if (QDF_IS_STATUS_ERROR(status)) {
13415 hdd_err("Failed to init debugfs; status:%u", status);
13416 goto print_deinit;
13417 }
13418
13419 qdf_lock_stats_init();
13420 qdf_mem_init();
Dustin Brownc2796312019-03-13 16:43:36 -070013421 qdf_delayed_work_feature_init();
Dustin Brown4a93bb52019-03-13 11:46:34 -070013422 qdf_periodic_work_feature_init();
Dustin Browna2a39dc2018-09-17 15:29:59 -070013423 qdf_mc_timer_manager_init();
13424 qdf_event_list_init();
13425
Dustin Brownd315c452018-11-27 11:28:48 -080013426 status = qdf_talloc_feature_init();
13427 if (QDF_IS_STATUS_ERROR(status)) {
13428 hdd_err("Failed to init talloc; status:%u", status);
13429 goto event_deinit;
13430 }
13431
Dustin Browna2a39dc2018-09-17 15:29:59 -070013432 status = qdf_cpuhp_init();
13433 if (QDF_IS_STATUS_ERROR(status)) {
13434 hdd_err("Failed to init cpuhp; status:%u", status);
Dustin Brownd315c452018-11-27 11:28:48 -080013435 goto talloc_deinit;
Dustin Browna2a39dc2018-09-17 15:29:59 -070013436 }
13437
13438 status = qdf_trace_spin_lock_init();
13439 if (QDF_IS_STATUS_ERROR(status)) {
13440 hdd_err("Failed to init spinlock; status:%u", status);
13441 goto cpuhp_deinit;
13442 }
13443
13444 qdf_trace_init();
13445 qdf_register_debugcb_init();
13446
13447 return QDF_STATUS_SUCCESS;
13448
13449cpuhp_deinit:
13450 qdf_cpuhp_deinit();
Dustin Brownd315c452018-11-27 11:28:48 -080013451talloc_deinit:
13452 qdf_talloc_feature_deinit();
Dustin Browna2a39dc2018-09-17 15:29:59 -070013453event_deinit:
13454 qdf_event_list_destroy();
13455 qdf_mc_timer_manager_exit();
Dustin Brown4a93bb52019-03-13 11:46:34 -070013456 qdf_periodic_work_feature_deinit();
Dustin Brownc2796312019-03-13 16:43:36 -070013457 qdf_delayed_work_feature_deinit();
Dustin Browna2a39dc2018-09-17 15:29:59 -070013458 qdf_mem_exit();
13459 qdf_lock_stats_deinit();
13460 qdf_debugfs_exit();
13461print_deinit:
13462 hdd_qdf_print_deinit();
13463
13464exit:
13465 return status;
13466}
13467
13468static void hdd_qdf_deinit(void)
13469{
13470 /* currently, no debugcb deinit */
13471
13472 qdf_trace_deinit();
13473
13474 /* currently, no trace spinlock deinit */
13475
13476 qdf_cpuhp_deinit();
Dustin Brownd315c452018-11-27 11:28:48 -080013477 qdf_talloc_feature_deinit();
Dustin Browna2a39dc2018-09-17 15:29:59 -070013478 qdf_event_list_destroy();
13479 qdf_mc_timer_manager_exit();
Dustin Brown4a93bb52019-03-13 11:46:34 -070013480 qdf_periodic_work_feature_deinit();
Dustin Brownc2796312019-03-13 16:43:36 -070013481 qdf_delayed_work_feature_deinit();
Dustin Browna2a39dc2018-09-17 15:29:59 -070013482 qdf_mem_exit();
13483 qdf_lock_stats_deinit();
13484 qdf_debugfs_exit();
13485 hdd_qdf_print_deinit();
13486}
Dustin Brownf0f70562018-09-14 10:29:38 -070013487
Dustin Brown26afe8f2019-03-01 12:37:24 -080013488#ifdef FEATURE_MONITOR_MODE_SUPPORT
13489static bool is_monitor_mode_supported(void)
13490{
13491 return true;
13492}
13493#else
13494static bool is_monitor_mode_supported(void)
13495{
13496 pr_err("Monitor mode not supported!");
13497 return false;
13498}
13499#endif
13500
13501#ifdef WLAN_FEATURE_EPPING
13502static bool is_epping_mode_supported(void)
13503{
13504 return true;
13505}
13506#else
13507static bool is_epping_mode_supported(void)
13508{
13509 pr_err("Epping mode not supported!");
13510 return false;
13511}
13512#endif
13513
13514#ifdef QCA_WIFI_FTM
13515static bool is_ftm_mode_supported(void)
13516{
13517 return true;
13518}
13519#else
13520static bool is_ftm_mode_supported(void)
13521{
13522 pr_err("FTM mode not supported!");
13523 return false;
13524}
13525#endif
13526
13527/**
13528 * is_con_mode_valid() check con mode is valid or not
13529 * @mode: global con mode
13530 *
13531 * Return: TRUE on success FALSE on failure
13532 */
13533static bool is_con_mode_valid(enum QDF_GLOBAL_MODE mode)
13534{
13535 switch (mode) {
13536 case QDF_GLOBAL_MONITOR_MODE:
13537 return is_monitor_mode_supported();
13538 case QDF_GLOBAL_EPPING_MODE:
13539 return is_epping_mode_supported();
13540 case QDF_GLOBAL_FTM_MODE:
13541 return is_ftm_mode_supported();
13542 case QDF_GLOBAL_MISSION_MODE:
13543 return true;
13544 default:
13545 return false;
13546 }
13547}
13548
13549static void hdd_stop_present_mode(struct hdd_context *hdd_ctx,
13550 enum QDF_GLOBAL_MODE curr_mode)
13551{
13552 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED)
13553 return;
13554
13555 switch (curr_mode) {
13556 case QDF_GLOBAL_MONITOR_MODE:
13557 hdd_info("Release wakelock for monitor mode!");
13558 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
13559 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
13560 /* fallthrough */
13561 case QDF_GLOBAL_MISSION_MODE:
13562 case QDF_GLOBAL_FTM_MODE:
13563 hdd_abort_mac_scan_all_adapters(hdd_ctx);
13564 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->pdev, NULL);
13565 hdd_stop_all_adapters(hdd_ctx);
13566 hdd_deinit_all_adapters(hdd_ctx, false);
13567
13568 break;
13569 default:
13570 break;
13571 }
13572}
13573
13574static void hdd_cleanup_present_mode(struct hdd_context *hdd_ctx,
13575 enum QDF_GLOBAL_MODE curr_mode)
13576{
13577 int driver_status;
13578
13579 driver_status = hdd_ctx->driver_status;
13580
13581 switch (curr_mode) {
13582 case QDF_GLOBAL_MISSION_MODE:
13583 case QDF_GLOBAL_MONITOR_MODE:
13584 case QDF_GLOBAL_FTM_MODE:
13585 hdd_close_all_adapters(hdd_ctx, false);
13586 break;
13587 case QDF_GLOBAL_EPPING_MODE:
13588 epping_disable();
13589 epping_close();
13590 break;
13591 default:
13592 return;
13593 }
13594}
13595
13596static int
13597hdd_parse_driver_mode(const char *mode_str, enum QDF_GLOBAL_MODE *out_mode)
13598{
13599 QDF_STATUS status;
13600 uint32_t mode;
13601
13602 *out_mode = QDF_GLOBAL_MAX_MODE;
13603
13604 status = qdf_uint32_parse(mode_str, &mode);
13605 if (QDF_IS_STATUS_ERROR(status))
13606 return qdf_status_to_os_return(status);
13607
13608 if (mode >= QDF_GLOBAL_MAX_MODE)
13609 return -ERANGE;
13610
13611 *out_mode = (enum QDF_GLOBAL_MODE)mode;
13612
13613 return 0;
13614}
13615
Rajeev Kumar588a2542019-04-08 10:57:19 -070013616static int hdd_mode_change_psoc_idle_shutdown(struct device *dev)
13617{
13618 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13619
13620 return hdd_wlan_stop_modules(hdd_ctx, true);
13621}
13622
13623static int hdd_mode_change_psoc_idle_restart(struct device *dev)
13624{
13625 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13626
13627 return hdd_wlan_start_modules(hdd_ctx, false);
13628}
13629
Dustin Brown26afe8f2019-03-01 12:37:24 -080013630/**
13631 * __hdd_driver_mode_change() - Handles a driver mode change
13632 * @hdd_ctx: Pointer to the global HDD context
13633 * @next_mode: the driver mode to transition to
13634 *
13635 * This function is invoked when user updates con_mode using sys entry,
13636 * to initialize and bring-up driver in that specific mode.
13637 *
13638 * Return: Errno
13639 */
13640static int __hdd_driver_mode_change(struct hdd_context *hdd_ctx,
13641 enum QDF_GLOBAL_MODE next_mode)
13642{
13643 enum QDF_GLOBAL_MODE curr_mode;
13644 int errno;
13645
13646 hdd_info("Driver mode changing to %d", next_mode);
13647
13648 errno = wlan_hdd_validate_context(hdd_ctx);
13649 if (errno)
13650 return errno;
13651
13652 if (!is_con_mode_valid(next_mode)) {
13653 hdd_err_rl("Requested driver mode is invalid");
13654 return -EINVAL;
13655 }
13656
Dustin Brown26afe8f2019-03-01 12:37:24 -080013657 curr_mode = hdd_get_conparam();
13658 if (curr_mode == next_mode) {
13659 hdd_err_rl("Driver is already in the requested mode");
Dustin Browne0a77272019-03-19 16:28:06 -070013660 return 0;
Dustin Brown26afe8f2019-03-01 12:37:24 -080013661 }
13662
13663 /* ensure adapters are stopped */
13664 hdd_stop_present_mode(hdd_ctx, curr_mode);
13665
Rajeev Kumar588a2542019-04-08 10:57:19 -070013666 is_mode_change_psoc_idle_shutdown = true;
13667 errno = pld_idle_shutdown(hdd_ctx->parent_dev,
13668 hdd_mode_change_psoc_idle_shutdown);
Dustin Brown26afe8f2019-03-01 12:37:24 -080013669 if (errno) {
Rajeev Kumar588a2542019-04-08 10:57:19 -070013670 is_mode_change_psoc_idle_shutdown = false;
Dustin Brown26afe8f2019-03-01 12:37:24 -080013671 hdd_err("Stop wlan modules failed");
Dustin Browne0a77272019-03-19 16:28:06 -070013672 return errno;
Dustin Brown26afe8f2019-03-01 12:37:24 -080013673 }
13674
13675 /* Cleanup present mode before switching to new mode */
13676 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
13677
13678 hdd_set_conparam(next_mode);
13679
Rajeev Kumar588a2542019-04-08 10:57:19 -070013680 errno = pld_idle_restart(hdd_ctx->parent_dev,
13681 hdd_mode_change_psoc_idle_restart);
Dustin Brown26afe8f2019-03-01 12:37:24 -080013682 if (errno) {
13683 hdd_err("Start wlan modules failed: %d", errno);
Dustin Browne0a77272019-03-19 16:28:06 -070013684 return errno;
Dustin Brown26afe8f2019-03-01 12:37:24 -080013685 }
13686
13687 errno = hdd_open_adapters_for_mode(hdd_ctx, next_mode);
13688 if (errno) {
13689 hdd_err("Failed to open adapters");
Dustin Browne0a77272019-03-19 16:28:06 -070013690 return errno;
Dustin Brown26afe8f2019-03-01 12:37:24 -080013691 }
13692
13693 if (next_mode == QDF_GLOBAL_MONITOR_MODE) {
13694 struct hdd_adapter *adapter =
13695 hdd_get_adapter(hdd_ctx, QDF_MONITOR_MODE);
13696
13697 QDF_BUG(adapter);
13698 if (!adapter) {
13699 hdd_err("Failed to get monitor adapter");
Dustin Browne0a77272019-03-19 16:28:06 -070013700 return -EINVAL;
Dustin Brown26afe8f2019-03-01 12:37:24 -080013701 }
13702
13703 errno = hdd_start_adapter(adapter);
13704 if (errno) {
13705 hdd_err("Failed to start monitor adapter");
Dustin Browne0a77272019-03-19 16:28:06 -070013706 return errno;
Dustin Brown26afe8f2019-03-01 12:37:24 -080013707 }
13708
13709 hdd_info("Acquire wakelock for monitor mode");
13710 qdf_wake_lock_acquire(&hdd_ctx->monitor_mode_wakelock,
13711 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
13712 }
13713
13714 /* con_mode is a global module parameter */
13715 con_mode = next_mode;
13716 hdd_info("Driver mode successfully changed to %d", next_mode);
13717
Dustin Browne0a77272019-03-19 16:28:06 -070013718 return 0;
Dustin Brown26afe8f2019-03-01 12:37:24 -080013719}
13720
13721static int hdd_driver_mode_change(enum QDF_GLOBAL_MODE mode)
13722{
Dustin Brownc1d81af2019-03-01 13:43:43 -080013723 struct osif_driver_sync *driver_sync;
Dustin Brown26afe8f2019-03-01 12:37:24 -080013724 struct hdd_context *hdd_ctx;
13725 QDF_STATUS status;
13726 int errno;
13727
13728 hdd_enter();
13729
Dustin Brownc1d81af2019-03-01 13:43:43 -080013730 status = osif_driver_sync_trans_start_wait(&driver_sync);
Dustin Brown26afe8f2019-03-01 12:37:24 -080013731 if (QDF_IS_STATUS_ERROR(status)) {
13732 hdd_err("Failed to start 'mode change'; status:%u", status);
13733 errno = qdf_status_to_os_return(status);
13734 goto exit;
13735 }
13736
Dustin Brownc1d81af2019-03-01 13:43:43 -080013737 osif_driver_sync_wait_for_ops(driver_sync);
Dustin Brown26afe8f2019-03-01 12:37:24 -080013738
13739 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13740 errno = wlan_hdd_validate_context(hdd_ctx);
13741 if (errno)
13742 goto trans_stop;
13743
Dustin Brown26afe8f2019-03-01 12:37:24 -080013744 errno = __hdd_driver_mode_change(hdd_ctx, mode);
Dustin Brown26afe8f2019-03-01 12:37:24 -080013745
13746trans_stop:
Dustin Brownc1d81af2019-03-01 13:43:43 -080013747 osif_driver_sync_trans_stop(driver_sync);
Dustin Brown26afe8f2019-03-01 12:37:24 -080013748
13749exit:
13750 hdd_exit();
13751
13752 return errno;
13753}
13754
13755static int hdd_set_con_mode(enum QDF_GLOBAL_MODE mode)
13756{
13757 con_mode = mode;
13758
13759 return 0;
13760}
13761
13762static int (*hdd_set_con_mode_cb)(enum QDF_GLOBAL_MODE mode) = hdd_set_con_mode;
13763
13764static void hdd_driver_mode_change_register(void)
13765{
13766 hdd_set_con_mode_cb = hdd_driver_mode_change;
13767}
13768
13769static void hdd_driver_mode_change_unregister(void)
13770{
13771 hdd_set_con_mode_cb = hdd_set_con_mode;
13772}
13773
13774static int con_mode_handler(const char *kmessage, const struct kernel_param *kp)
13775{
13776 enum QDF_GLOBAL_MODE mode;
13777 int errno;
13778
13779 errno = hdd_parse_driver_mode(kmessage, &mode);
13780 if (errno) {
13781 hdd_err_rl("Failed to parse driver mode '%s'", kmessage);
13782 return errno;
13783 }
13784
13785 return hdd_set_con_mode_cb(mode);
13786}
Dustin Brown95ff00b2019-02-28 13:41:13 -080013787
Dustin Brownf0f70562018-09-14 10:29:38 -070013788/**
13789 * hdd_driver_load() - Perform the driver-level load operation
13790 *
13791 * Note: this is used in both static and DLKM driver builds
13792 *
13793 * Return: Errno
13794 */
13795static int hdd_driver_load(void)
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013796{
Dustin Brownc1d81af2019-03-01 13:43:43 -080013797 struct osif_driver_sync *driver_sync;
Dustin Brownd585cb32018-09-12 17:12:23 -070013798 QDF_STATUS status;
Dustin Brownf0f70562018-09-14 10:29:38 -070013799 int errno;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013800
Dustin Brownc1d81af2019-03-01 13:43:43 -080013801 pr_err("%s: Loading driver v%s\n", WLAN_MODULE_NAME,
Rajeev Kumare555e2d2018-09-17 11:52:37 -070013802 g_wlan_driver_version);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013803
Dustin Browna2a39dc2018-09-17 15:29:59 -070013804 status = hdd_qdf_init();
13805 if (QDF_IS_STATUS_ERROR(status)) {
13806 errno = qdf_status_to_os_return(status);
13807 goto exit;
13808 }
13809
Dustin Brownc1d81af2019-03-01 13:43:43 -080013810 osif_sync_init();
Dustin Brown21a1d462018-07-31 15:13:06 -070013811
Dustin Brownc1d81af2019-03-01 13:43:43 -080013812 status = osif_driver_sync_create_and_trans(&driver_sync);
Dustin Brown21a1d462018-07-31 15:13:06 -070013813 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Brownc1d81af2019-03-01 13:43:43 -080013814 hdd_err("Failed to init driver sync; status:%u", status);
Dustin Brown21a1d462018-07-31 15:13:06 -070013815 errno = qdf_status_to_os_return(status);
Dustin Brownc1d81af2019-03-01 13:43:43 -080013816 goto sync_deinit;
Dustin Brown21a1d462018-07-31 15:13:06 -070013817 }
13818
Dustin Brownf0f70562018-09-14 10:29:38 -070013819 errno = hdd_init();
13820 if (errno) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013821 hdd_err("Failed to init HDD; errno:%d", errno);
Dustin Brown21a1d462018-07-31 15:13:06 -070013822 goto trans_stop;
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053013823 }
13824
Dustin Brownd585cb32018-09-12 17:12:23 -070013825 status = hdd_component_init();
13826 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013827 hdd_err("Failed to init components; status:%u", status);
Dustin Brownf0f70562018-09-14 10:29:38 -070013828 errno = qdf_status_to_os_return(status);
Dustin Brownd585cb32018-09-12 17:12:23 -070013829 goto hdd_deinit;
13830 }
Mukul Sharmad75a6672017-06-22 15:40:53 +053013831
Dustin Brownf0f70562018-09-14 10:29:38 -070013832 status = qdf_wake_lock_create(&wlan_wake_lock, "wlan");
13833 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013834 hdd_err("Failed to create wake lock; status:%u", status);
Dustin Brownf0f70562018-09-14 10:29:38 -070013835 errno = qdf_status_to_os_return(status);
13836 goto comp_deinit;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013837 }
13838
Dustin Brownf0f70562018-09-14 10:29:38 -070013839 hdd_set_conparam(con_mode);
13840
Dustin Brownf0f70562018-09-14 10:29:38 -070013841 errno = wlan_hdd_state_ctrl_param_create();
13842 if (errno) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013843 hdd_err("Failed to create ctrl param; errno:%d", errno);
Dustin Brown4b9dbe62018-09-14 15:41:11 -070013844 goto wakelock_destroy;
13845 }
13846
Dustin Brown25843ad2018-09-17 14:54:33 -070013847 errno = pld_init();
13848 if (errno) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013849 hdd_err("Failed to init PLD; errno:%d", errno);
Dustin Brown25843ad2018-09-17 14:54:33 -070013850 goto param_destroy;
13851 }
13852
Dustin Brown95ff00b2019-02-28 13:41:13 -080013853 hdd_driver_mode_change_register();
Dustin Brownc1d81af2019-03-01 13:43:43 -080013854
13855 osif_driver_sync_register(driver_sync);
13856 osif_driver_sync_trans_stop(driver_sync);
Dustin Brown21a1d462018-07-31 15:13:06 -070013857
13858 /* psoc probe can happen in registration; do after 'load' transition */
Dustin Brown4b9dbe62018-09-14 15:41:11 -070013859 errno = wlan_hdd_register_driver();
13860 if (errno) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013861 hdd_err("Failed to register driver; errno:%d", errno);
Dustin Brown25843ad2018-09-17 14:54:33 -070013862 goto pld_deinit;
Sachin Ahuja16904db2017-12-13 19:56:57 +053013863 }
13864
Dustin Browna2a39dc2018-09-17 15:29:59 -070013865 hdd_debug("%s: driver loaded", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013866
13867 return 0;
Dustin Brownd585cb32018-09-12 17:12:23 -070013868
Dustin Brown25843ad2018-09-17 14:54:33 -070013869pld_deinit:
Dustin Brownc1d81af2019-03-01 13:43:43 -080013870 status = osif_driver_sync_trans_start(&driver_sync);
Dustin Brown21a1d462018-07-31 15:13:06 -070013871 QDF_BUG(QDF_IS_STATUS_SUCCESS(status));
13872
Dustin Brownc1d81af2019-03-01 13:43:43 -080013873 osif_driver_sync_unregister();
13874 osif_driver_sync_wait_for_ops(driver_sync);
13875
Dustin Brown95ff00b2019-02-28 13:41:13 -080013876 hdd_driver_mode_change_unregister();
Dustin Brown25843ad2018-09-17 14:54:33 -070013877 pld_deinit();
Dustin Brown21a1d462018-07-31 15:13:06 -070013878
Dustin Brown4b9dbe62018-09-14 15:41:11 -070013879param_destroy:
13880 wlan_hdd_state_ctrl_param_destroy();
Dustin Brownf0f70562018-09-14 10:29:38 -070013881wakelock_destroy:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053013882 qdf_wake_lock_destroy(&wlan_wake_lock);
Dustin Brownf0f70562018-09-14 10:29:38 -070013883comp_deinit:
Dustin Brownd585cb32018-09-12 17:12:23 -070013884 hdd_component_deinit();
Dustin Brownd585cb32018-09-12 17:12:23 -070013885hdd_deinit:
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053013886 hdd_deinit();
Dustin Brown21a1d462018-07-31 15:13:06 -070013887trans_stop:
Dustin Brownc1d81af2019-03-01 13:43:43 -080013888 osif_driver_sync_trans_stop(driver_sync);
13889 osif_driver_sync_destroy(driver_sync);
13890sync_deinit:
13891 osif_sync_deinit();
Dustin Browna2a39dc2018-09-17 15:29:59 -070013892 hdd_qdf_deinit();
Dustin Brownd585cb32018-09-12 17:12:23 -070013893
Dustin Brown25843ad2018-09-17 14:54:33 -070013894exit:
Dustin Brownf0f70562018-09-14 10:29:38 -070013895 return errno;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013896}
13897
13898/**
Dustin Brownf0f70562018-09-14 10:29:38 -070013899 * hdd_driver_unload() - Performs the driver-level unload operation
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013900 *
Dustin Brownf0f70562018-09-14 10:29:38 -070013901 * Note: this is used in both static and DLKM driver builds
13902 *
13903 * Return: None
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013904 */
Dustin Brownf0f70562018-09-14 10:29:38 -070013905static void hdd_driver_unload(void)
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013906{
Dustin Brownc1d81af2019-03-01 13:43:43 -080013907 struct osif_driver_sync *driver_sync;
Will Huang36049722018-04-13 11:48:51 +080013908 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Dustin Brown21a1d462018-07-31 15:13:06 -070013909 QDF_STATUS status;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053013910
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013911 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
13912 QWLAN_VERSIONSTR);
13913
Dustin Brown8c0b5e32019-01-18 13:56:02 -080013914 if (hdd_ctx)
13915 hdd_psoc_idle_timer_stop(hdd_ctx);
13916
13917 /* trigger SoC remove */
13918 wlan_hdd_unregister_driver();
13919
Dustin Brownc1d81af2019-03-01 13:43:43 -080013920 status = osif_driver_sync_trans_start_wait(&driver_sync);
Dustin Brown21a1d462018-07-31 15:13:06 -070013921 QDF_BUG(QDF_IS_STATUS_SUCCESS(status));
13922 if (QDF_IS_STATUS_ERROR(status)) {
13923 hdd_err("Unable to unload wlan; status:%u", status);
Arunk Khandavalli830c9692018-03-22 12:17:40 +053013924 return;
Dustin Brown21a1d462018-07-31 15:13:06 -070013925 }
13926
Dustin Brownc1d81af2019-03-01 13:43:43 -080013927 osif_driver_sync_unregister();
13928 osif_driver_sync_wait_for_ops(driver_sync);
Dustin Brown21a1d462018-07-31 15:13:06 -070013929
Will Huangba035ec2018-07-05 11:13:30 +080013930 cds_set_driver_loaded(false);
13931 cds_set_unload_in_progress(true);
13932
Dustin Brown95ff00b2019-02-28 13:41:13 -080013933 hdd_driver_mode_change_unregister();
Dustin Brown25843ad2018-09-17 14:54:33 -070013934 pld_deinit();
Dustin Brown4b9dbe62018-09-14 15:41:11 -070013935 wlan_hdd_state_ctrl_param_destroy();
Dustin Brownf0f70562018-09-14 10:29:38 -070013936 hdd_set_conparam(0);
Anurag Chouhana37b5b72016-02-21 14:53:42 +053013937 qdf_wake_lock_destroy(&wlan_wake_lock);
Dustin Brownd585cb32018-09-12 17:12:23 -070013938 hdd_component_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053013939 hdd_deinit();
Dustin Brown21a1d462018-07-31 15:13:06 -070013940
Dustin Brownc1d81af2019-03-01 13:43:43 -080013941 osif_driver_sync_trans_stop(driver_sync);
13942 osif_driver_sync_destroy(driver_sync);
Dustin Brown623e7e32018-09-05 14:27:50 -070013943
Dustin Brownc1d81af2019-03-01 13:43:43 -080013944 osif_sync_deinit();
Dustin Brown21a1d462018-07-31 15:13:06 -070013945
Dustin Browna2a39dc2018-09-17 15:29:59 -070013946 hdd_qdf_deinit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013947}
13948
Arun Khandavallifae92942016-08-01 13:31:08 +053013949#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013950/**
Arun Khandavallifae92942016-08-01 13:31:08 +053013951 * wlan_boot_cb() - Wlan boot callback
13952 * @kobj: object whose directory we're creating the link in.
13953 * @attr: attribute the user is interacting with
13954 * @buff: the buffer containing the user data
13955 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013956 *
Arun Khandavallifae92942016-08-01 13:31:08 +053013957 * This callback is invoked when the fs is ready to start the
13958 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013959 *
Arun Khandavallifae92942016-08-01 13:31:08 +053013960 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013961 */
Arun Khandavallifae92942016-08-01 13:31:08 +053013962static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013963 struct kobj_attribute *attr,
13964 const char *buf,
13965 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013966{
Arun Khandavallifae92942016-08-01 13:31:08 +053013967
Arun Khandavallifae92942016-08-01 13:31:08 +053013968 if (wlan_loader->loaded_state) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013969 hdd_err("wlan driver already initialized");
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013970 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053013971 }
13972
Dustin Brownf0f70562018-09-14 10:29:38 -070013973 if (hdd_driver_load())
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013974 return -EIO;
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013975
13976 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053013977
13978 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013979}
Arun Khandavallifae92942016-08-01 13:31:08 +053013980
13981/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013982 * hdd_sysfs_cleanup() - cleanup sysfs
13983 *
13984 * Return: None
13985 *
13986 */
13987static void hdd_sysfs_cleanup(void)
13988{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013989 /* remove from group */
13990 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
13991 sysfs_remove_group(wlan_loader->boot_wlan_obj,
13992 wlan_loader->attr_group);
13993
13994 /* unlink the object from parent */
13995 kobject_del(wlan_loader->boot_wlan_obj);
13996
13997 /* free the object */
13998 kobject_put(wlan_loader->boot_wlan_obj);
13999
14000 kfree(wlan_loader->attr_group);
14001 kfree(wlan_loader);
14002
14003 wlan_loader = NULL;
14004}
14005
14006/**
Arun Khandavallifae92942016-08-01 13:31:08 +053014007 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
14008 * ready
14009 *
14010 * This is creates the syfs entry boot_wlan. Which shall be invoked
14011 * when the filesystem is ready.
14012 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070014013 * QDF API cannot be used here since this function is called even before
14014 * initializing WLAN driver.
14015 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070014016 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053014017 */
14018static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014019{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070014020 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053014021
14022 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070014023 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070014024 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053014025
14026 wlan_loader->boot_wlan_obj = NULL;
14027 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
14028 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070014029 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053014030 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053014031
14032 wlan_loader->loaded_state = 0;
14033 wlan_loader->attr_group->attrs = attrs;
14034
Qun Zhang4a83a462018-09-11 16:28:51 +080014035 wlan_loader->boot_wlan_obj = kobject_create_and_add(WLAN_LOADER_NAME,
Arun Khandavallifae92942016-08-01 13:31:08 +053014036 kernel_kobj);
14037 if (!wlan_loader->boot_wlan_obj) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070014038 hdd_err("sysfs create and add failed");
Arun Khandavallifae92942016-08-01 13:31:08 +053014039 goto error_return;
14040 }
14041
14042 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
14043 wlan_loader->attr_group);
14044 if (ret) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070014045 hdd_err("sysfs create group failed; errno:%d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +053014046 goto error_return;
14047 }
14048
14049 return 0;
14050
14051error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070014052 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053014053
14054 return ret;
14055}
14056
14057/**
14058 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
14059 *
14060 * Return: 0 on success or errno on failure
14061 */
14062static int wlan_deinit_sysfs(void)
14063{
Arun Khandavallifae92942016-08-01 13:31:08 +053014064 if (!wlan_loader) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070014065 hdd_err("wlan_loader is null");
Arun Khandavallifae92942016-08-01 13:31:08 +053014066 return -EINVAL;
14067 }
14068
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070014069 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014070 return 0;
14071}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014072
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070014073#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053014074
14075#ifdef MODULE
14076/**
Dustin Brownf0f70562018-09-14 10:29:38 -070014077 * hdd_module_init() - Module init helper
Arun Khandavallifae92942016-08-01 13:31:08 +053014078 *
14079 * Module init helper function used by both module and static driver.
14080 *
14081 * Return: 0 for success, errno on failure
14082 */
14083static int hdd_module_init(void)
14084{
Dustin Brownf0f70562018-09-14 10:29:38 -070014085 if (hdd_driver_load())
Dustin Brownab482ac2017-06-09 17:00:44 -070014086 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053014087
Dustin Brownab482ac2017-06-09 17:00:44 -070014088 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053014089}
14090#else
14091static int __init hdd_module_init(void)
14092{
14093 int ret = -EINVAL;
14094
14095 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070014096 if (ret)
Dustin Browna2a39dc2018-09-17 15:29:59 -070014097 hdd_err("Failed to create sysfs entry");
Arun Khandavallifae92942016-08-01 13:31:08 +053014098
14099 return ret;
14100}
14101#endif
14102
14103
14104#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014105/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014106 * hdd_module_exit() - Exit function
14107 *
14108 * This is the driver exit point (invoked when module is unloaded using rmmod)
14109 *
14110 * Return: None
14111 */
14112static void __exit hdd_module_exit(void)
14113{
Dustin Brownf0f70562018-09-14 10:29:38 -070014114 hdd_driver_unload();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014115}
Arun Khandavallifae92942016-08-01 13:31:08 +053014116#else
14117static void __exit hdd_module_exit(void)
14118{
Dustin Brownf0f70562018-09-14 10:29:38 -070014119 hdd_driver_unload();
Arun Khandavallifae92942016-08-01 13:31:08 +053014120 wlan_deinit_sysfs();
14121}
14122#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014123
Srinivas Girigowda841da292018-02-21 16:33:00 -080014124static int fwpath_changed_handler(const char *kmessage,
14125 const struct kernel_param *kp)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014126{
14127 return param_set_copystring(kmessage, kp);
14128}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080014129
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053014130static int con_mode_handler_ftm(const char *kmessage,
Srinivas Girigowda841da292018-02-21 16:33:00 -080014131 const struct kernel_param *kp)
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053014132{
14133 int ret;
14134
14135 ret = param_set_int(kmessage, kp);
14136
14137 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
14138 pr_err("Only FTM mode supported!");
14139 return -ENOTSUPP;
14140 }
14141
14142 hdd_set_conparam(con_mode_ftm);
14143 con_mode = con_mode_ftm;
14144
14145 return ret;
14146}
14147
Nirav Shah6aeecf92019-02-13 14:05:03 +053014148#ifdef WLAN_FEATURE_EPPING
14149static int con_mode_handler_epping(const char *kmessage,
14150 const struct kernel_param *kp)
14151{
14152 int ret;
14153
14154 ret = param_set_int(kmessage, kp);
14155
14156 if (con_mode_epping != QDF_GLOBAL_EPPING_MODE) {
14157 pr_err("Only EPPING mode supported!");
14158 return -ENOTSUPP;
14159 }
14160
14161 hdd_set_conparam(con_mode_epping);
14162 con_mode = con_mode_epping;
14163
14164 return ret;
14165}
14166#endif
14167
Nirav Shah73713f72018-05-17 14:50:41 +053014168#ifdef FEATURE_MONITOR_MODE_SUPPORT
Ravi Joshia307f632017-07-17 23:41:41 -070014169static int con_mode_handler_monitor(const char *kmessage,
Srinivas Girigowda841da292018-02-21 16:33:00 -080014170 const struct kernel_param *kp)
Ravi Joshia307f632017-07-17 23:41:41 -070014171{
14172 int ret;
14173
14174 ret = param_set_int(kmessage, kp);
14175
14176 if (con_mode_monitor != QDF_GLOBAL_MONITOR_MODE) {
14177 pr_err("Only Monitor mode supported!");
14178 return -ENOTSUPP;
14179 }
14180
14181 hdd_set_conparam(con_mode_monitor);
14182 con_mode = con_mode_monitor;
14183
14184 return ret;
14185}
Nirav Shah73713f72018-05-17 14:50:41 +053014186#endif
Ravi Joshia307f632017-07-17 23:41:41 -070014187
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014188/**
14189 * hdd_get_conparam() - driver exit point
14190 *
14191 * This is the driver exit point (invoked when module is unloaded using rmmod)
14192 *
Jeff Johnson876c1a62017-12-12 10:43:07 -080014193 * Return: enum QDF_GLOBAL_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014194 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080014195enum QDF_GLOBAL_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014196{
Jeff Johnson876c1a62017-12-12 10:43:07 -080014197 return (enum QDF_GLOBAL_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014198}
14199
Dustin Brownf0f70562018-09-14 10:29:38 -070014200void hdd_set_conparam(int32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014201{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080014202 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014203}
14204
Komal Seelamc11bb222016-01-27 18:57:10 +053014205/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053014206 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
14207 * @hdd_ctx: HDD context
14208 *
14209 * Cleans up the pre cac interface, if it exists
14210 *
14211 * Return: None
14212 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014213void hdd_clean_up_pre_cac_interface(struct hdd_context *hdd_ctx)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053014214{
Jeff Johnson55d2ab42019-03-06 11:43:49 -080014215 uint8_t vdev_id;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053014216 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070014217 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053014218
Jeff Johnson55d2ab42019-03-06 11:43:49 -080014219 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->mac_handle, &vdev_id);
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053014220 if (QDF_IS_STATUS_ERROR(status)) {
14221 hdd_err("failed to get pre cac vdev id");
14222 return;
14223 }
14224
Jeff Johnson55d2ab42019-03-06 11:43:49 -080014225 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053014226 if (!precac_adapter) {
Jeff Johnsondd2f1fc2018-05-06 11:22:52 -070014227 hdd_err("invalid pre cac adapter");
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053014228 return;
14229 }
14230
14231 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
14232 wlan_hdd_sap_pre_cac_failure,
14233 (void *)precac_adapter);
14234 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
14235
14236}
14237
14238/**
Komal Seelamec702b02016-02-24 18:42:16 +053014239 * hdd_update_ol_config - API to update ol configuration parameters
14240 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053014241 *
Komal Seelamc11bb222016-01-27 18:57:10 +053014242 * Return: void
14243 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014244static void hdd_update_ol_config(struct hdd_context *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053014245{
Abhishek Singh98278ce2018-12-27 11:41:03 +053014246 struct ol_config_info cfg = {0};
Anurag Chouhandf2b2682016-02-29 14:15:27 +053014247 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053014248 bool self_recovery = false;
14249 QDF_STATUS status;
Komal Seelamc11bb222016-01-27 18:57:10 +053014250
Komal Seelamec702b02016-02-24 18:42:16 +053014251 if (!ol_ctx)
14252 return;
14253
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053014254 status = ucfg_mlme_get_self_recovery(hdd_ctx->psoc, &self_recovery);
14255 if (QDF_IS_STATUS_ERROR(status))
14256 hdd_err("Failed to get self recovery ini config");
14257
14258 cfg.enable_self_recovery = self_recovery;
Komal Seelamec702b02016-02-24 18:42:16 +053014259 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
14260 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
14261 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070014262 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053014263
14264 ol_init_ini_config(ol_ctx, &cfg);
14265}
14266
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070014267#ifdef FEATURE_RUNTIME_PM
14268/**
14269 * hdd_populate_runtime_cfg() - populate runtime configuration
14270 * @hdd_ctx: hdd context
14271 * @cfg: pointer to the configuration memory being populated
14272 *
14273 * Return: void
14274 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014275static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070014276 struct hif_config_info *cfg)
14277{
14278 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
Wu Gao66454f12018-09-26 19:55:41 +080014279 cfg->runtime_pm_delay =
14280 ucfg_pmo_get_runtime_pm_delay(hdd_ctx->psoc);
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070014281}
14282#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014283static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070014284 struct hif_config_info *cfg)
14285{
14286}
14287#endif
14288
Komal Seelamec702b02016-02-24 18:42:16 +053014289/**
14290 * hdd_update_hif_config - API to update HIF configuration parameters
14291 * @hdd_ctx: HDD Context
14292 *
14293 * Return: void
14294 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014295static void hdd_update_hif_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053014296{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053014297 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Abhishek Singh98278ce2018-12-27 11:41:03 +053014298 struct hif_config_info cfg = {0};
Vignesh Viswanathana851d752018-10-03 19:44:38 +053014299 bool prevent_link_down = false;
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053014300 bool self_recovery = false;
Vignesh Viswanathana851d752018-10-03 19:44:38 +053014301 QDF_STATUS status;
Komal Seelamec702b02016-02-24 18:42:16 +053014302
14303 if (!scn)
14304 return;
14305
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053014306 status = ucfg_mlme_get_prevent_link_down(hdd_ctx->psoc,
14307 &prevent_link_down);
Vignesh Viswanathana851d752018-10-03 19:44:38 +053014308 if (QDF_IS_STATUS_ERROR(status))
14309 hdd_err("Failed to get prevent_link_down config");
14310
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053014311 status = ucfg_mlme_get_self_recovery(hdd_ctx->psoc, &self_recovery);
14312 if (QDF_IS_STATUS_ERROR(status))
14313 hdd_err("Failed to get self recovery ini config");
14314
14315 cfg.enable_self_recovery = self_recovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070014316 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Mohit Khannaa8c9f562019-03-25 22:17:02 -070014317 cfg.rx_softirq_max_yield_duration_ns =
14318 cfg_get(hdd_ctx->psoc,
14319 CFG_DP_RX_SOFTIRQ_MAX_YIELD_TIME_NS);
14320
Komal Seelamec702b02016-02-24 18:42:16 +053014321 hif_init_ini_config(scn, &cfg);
Dustin Brownee3e0592017-09-07 13:50:11 -070014322
Vignesh Viswanathana851d752018-10-03 19:44:38 +053014323 if (prevent_link_down)
Dustin Brownee3e0592017-09-07 13:50:11 -070014324 hif_vote_link_up(scn);
Komal Seelamec702b02016-02-24 18:42:16 +053014325}
14326
Mohit Khannaa8c9f562019-03-25 22:17:02 -070014327#ifdef WLAN_FEATURE_RX_SOFTIRQ_TIME_LIMIT
14328/**
14329 * hdd_update_dp_config_rx_softirq_limits() - Update DP rx softirq limit config
14330 * datapath
14331 * @hdd_ctx: HDD Context
14332 * @params: pointer to cdp_config_params to be updated
14333 *
14334 * Void
14335 */
14336static
14337void hdd_update_dp_config_rx_softirq_limits(struct hdd_context *hdd_ctx,
14338 struct cdp_config_params *params)
14339{
14340 params->tx_comp_loop_pkt_limit = cfg_get(hdd_ctx->psoc,
14341 CFG_DP_TX_COMP_LOOP_PKT_LIMIT);
14342 params->rx_reap_loop_pkt_limit = cfg_get(hdd_ctx->psoc,
14343 CFG_DP_RX_REAP_LOOP_PKT_LIMIT);
14344 params->rx_hp_oos_update_limit = cfg_get(hdd_ctx->psoc,
14345 CFG_DP_RX_HP_OOS_UPDATE_LIMIT);
14346}
14347#else
14348static
14349void hdd_update_dp_config_rx_softirq_limits(struct hdd_context *hdd_ctx,
14350 struct cdp_config_params *params)
14351{
14352}
14353#endif /* WLAN_FEATURE_RX_SOFTIRQ_TIME_LIMIT */
14354
hangtianb9c91362019-06-07 10:39:38 +080014355#if defined(QCA_LL_TX_FLOW_CONTROL_V2) || defined(QCA_LL_PDEV_TX_FLOW_CONTROL)
14356static void
14357hdd_update_dp_config_queue_threshold(struct hdd_context *hdd_ctx,
14358 struct cdp_config_params *params)
14359{
14360 params->tx_flow_stop_queue_threshold =
14361 cfg_get(hdd_ctx->psoc, CFG_DP_TX_FLOW_STOP_QUEUE_TH);
14362 params->tx_flow_start_queue_offset =
14363 cfg_get(hdd_ctx->psoc,
14364 CFG_DP_TX_FLOW_START_QUEUE_OFFSET);
14365}
14366#else
14367static inline void
14368hdd_update_dp_config_queue_threshold(struct hdd_context *hdd_ctx,
14369 struct cdp_config_params *params)
14370{
14371}
14372#endif
14373
Komal Seelamec702b02016-02-24 18:42:16 +053014374/**
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014375 * hdd_update_dp_config() - Propagate config parameters to Lithium
14376 * datapath
14377 * @hdd_ctx: HDD Context
14378 *
14379 * Return: 0 for success/errno for failure
14380 */
14381static int hdd_update_dp_config(struct hdd_context *hdd_ctx)
14382{
Abhishek Singh98278ce2018-12-27 11:41:03 +053014383 struct cdp_config_params params = {0};
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014384 QDF_STATUS status;
jitiphil377bcc12018-10-05 19:46:08 +053014385 void *soc;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014386
jitiphil377bcc12018-10-05 19:46:08 +053014387 soc = cds_get_context(QDF_MODULE_ID_SOC);
14388 params.tso_enable = cfg_get(hdd_ctx->psoc, CFG_DP_TSO);
14389 params.lro_enable = cfg_get(hdd_ctx->psoc, CFG_DP_LRO);
hangtianb9c91362019-06-07 10:39:38 +080014390 hdd_update_dp_config_queue_threshold(hdd_ctx, &params);
jitiphil377bcc12018-10-05 19:46:08 +053014391 params.flow_steering_enable =
14392 cfg_get(hdd_ctx->psoc, CFG_DP_FLOW_STEERING_ENABLED);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014393 params.napi_enable = hdd_ctx->napi_enable;
14394 params.tcp_udp_checksumoffload =
jitiphil377bcc12018-10-05 19:46:08 +053014395 cfg_get(hdd_ctx->psoc,
14396 CFG_DP_TCP_UDP_CKSUM_OFFLOAD);
Sravan Kumar Kairam0af1ee52018-12-12 20:37:51 +053014397 params.ipa_enable = ucfg_ipa_is_enabled();
Mohit Khanna81418772018-10-30 14:14:46 -070014398 params.gro_enable = cfg_get(hdd_ctx->psoc, CFG_DP_GRO);
Mohit Khannaa8c9f562019-03-25 22:17:02 -070014399 params.tx_comp_loop_pkt_limit = cfg_get(hdd_ctx->psoc,
14400 CFG_DP_TX_COMP_LOOP_PKT_LIMIT);
14401 params.rx_reap_loop_pkt_limit = cfg_get(hdd_ctx->psoc,
14402 CFG_DP_RX_REAP_LOOP_PKT_LIMIT);
14403 params.rx_hp_oos_update_limit = cfg_get(hdd_ctx->psoc,
14404 CFG_DP_RX_HP_OOS_UPDATE_LIMIT);
14405 hdd_update_dp_config_rx_softirq_limits(hdd_ctx, &params);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014406
jitiphil377bcc12018-10-05 19:46:08 +053014407 status = cdp_update_config_parameters(soc, &params);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014408 if (status) {
Dustin Browna2868622018-03-20 11:38:14 -070014409 hdd_err("Failed to attach config parameters");
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014410 return status;
14411 }
14412
14413 return 0;
14414}
14415
14416/**
Komal Seelamec702b02016-02-24 18:42:16 +053014417 * hdd_update_config() - Initialize driver per module ini parameters
14418 * @hdd_ctx: HDD Context
14419 *
14420 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053014421 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053014422 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014423int hdd_update_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053014424{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053014425 int ret;
14426
Wu Gao66454f12018-09-26 19:55:41 +080014427 if (ucfg_pmo_is_ns_offloaded(hdd_ctx->psoc))
14428 hdd_ctx->ns_offload_enable = true;
14429
Komal Seelamec702b02016-02-24 18:42:16 +053014430 hdd_update_ol_config(hdd_ctx);
14431 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053014432 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
14433 ret = hdd_update_cds_config_ftm(hdd_ctx);
14434 else
14435 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080014436 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053014437
14438 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053014439}
14440
Mukul Sharma9d797a02017-01-05 20:26:03 +053014441/**
14442 * hdd_update_pmo_config - API to update pmo configuration parameters
14443 * @hdd_ctx: HDD context
14444 *
14445 * Return: void
14446 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014447static int hdd_update_pmo_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053014448{
Abhishek Singh98278ce2018-12-27 11:41:03 +053014449 struct pmo_psoc_cfg psoc_cfg = {0};
Mukul Sharma9d797a02017-01-05 20:26:03 +053014450 QDF_STATUS status;
Wu Gao66454f12018-09-26 19:55:41 +080014451 enum pmo_wow_enable_type wow_enable;
14452
14453 ucfg_pmo_get_psoc_config(hdd_ctx->psoc, &psoc_cfg);
Mukul Sharma9d797a02017-01-05 20:26:03 +053014454
14455 /*
14456 * Value of hdd_ctx->wowEnable can be,
14457 * 0 - Disable both magic pattern match and pattern byte match.
14458 * 1 - Enable magic pattern match on all interfaces.
14459 * 2 - Enable pattern byte match on all interfaces.
14460 * 3 - Enable both magic patter and pattern byte match on
14461 * all interfaces.
14462 */
Wu Gao66454f12018-09-26 19:55:41 +080014463 wow_enable = ucfg_pmo_get_wow_enable(hdd_ctx->psoc);
14464 psoc_cfg.magic_ptrn_enable = (wow_enable & 0x01) ? true : false;
Mukul Sharma9d797a02017-01-05 20:26:03 +053014465 psoc_cfg.ptrn_match_enable_all_vdev =
Wu Gao66454f12018-09-26 19:55:41 +080014466 (wow_enable & 0x02) ? true : false;
Mukul Sharma9d797a02017-01-05 20:26:03 +053014467 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
Will Huang3cd2b7c2017-11-17 13:16:56 +080014468 psoc_cfg.d0_wow_supported = wma_d0_wow_is_supported();
Bala Venkatesh46e29032018-11-14 18:24:55 +053014469 ucfg_mlme_get_sap_max_modulated_dtim(hdd_ctx->psoc,
14470 &psoc_cfg.sta_max_li_mod_dtim);
14471
Mukul Sharma9d797a02017-01-05 20:26:03 +053014472
Mukul Sharma9223f232017-03-08 18:42:27 +053014473 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053014474
Dustin Brown1dbefe62018-09-11 16:32:03 -070014475 status = ucfg_pmo_update_psoc_config(hdd_ctx->psoc, &psoc_cfg);
Dustin Brownb9987af2018-03-01 17:15:11 -080014476 if (QDF_IS_STATUS_ERROR(status))
14477 hdd_err("failed pmo psoc configuration; status:%d", status);
14478
14479 return qdf_status_to_os_return(status);
Mukul Sharma9d797a02017-01-05 20:26:03 +053014480}
14481
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053014482void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
Dundi Raviteja85a240a2018-09-10 15:03:07 +053014483 struct hdd_context *hdd_ctx)
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053014484{
Dundi Raviteja85a240a2018-09-10 15:03:07 +053014485 struct wlan_fwol_ie_whitelist whitelist = {0};
14486 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Dundi Raviteja85a240a2018-09-10 15:03:07 +053014487 QDF_STATUS status;
14488 bool is_ie_whitelist_enable = false;
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053014489 uint8_t i = 0;
14490
Dundi Raviteja85a240a2018-09-10 15:03:07 +053014491 status = ucfg_fwol_get_ie_whitelist(psoc, &is_ie_whitelist_enable);
14492 if (QDF_IS_STATUS_ERROR(status)) {
14493 hdd_err("Unable to get IE whitelist param");
14494 return;
14495 }
14496
14497 ie_whitelist->white_list = is_ie_whitelist_enable;
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053014498 if (!ie_whitelist->white_list)
14499 return;
14500
Dundi Raviteja85a240a2018-09-10 15:03:07 +053014501 status = ucfg_fwol_get_all_whitelist_params(psoc, &whitelist);
14502 if (QDF_IS_STATUS_ERROR(status)) {
14503 hdd_err("Unable to get all whitelist params");
14504 return;
14505 }
14506
14507 ie_whitelist->ie_bitmap[0] = whitelist.ie_bitmap_0;
14508 ie_whitelist->ie_bitmap[1] = whitelist.ie_bitmap_1;
14509 ie_whitelist->ie_bitmap[2] = whitelist.ie_bitmap_2;
14510 ie_whitelist->ie_bitmap[3] = whitelist.ie_bitmap_3;
14511 ie_whitelist->ie_bitmap[4] = whitelist.ie_bitmap_4;
14512 ie_whitelist->ie_bitmap[5] = whitelist.ie_bitmap_5;
14513 ie_whitelist->ie_bitmap[6] = whitelist.ie_bitmap_6;
14514 ie_whitelist->ie_bitmap[7] = whitelist.ie_bitmap_7;
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053014515
Dundi Raviteja9ab4e7b2018-09-28 14:18:28 +053014516 ie_whitelist->num_vendor_oui = whitelist.no_of_probe_req_ouis;
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053014517 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
Dundi Raviteja9ab4e7b2018-09-28 14:18:28 +053014518 ie_whitelist->voui[i] = whitelist.probe_req_voui[i];
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053014519}
14520
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014521uint32_t hdd_limit_max_per_index_score(uint32_t per_index_score)
14522{
14523 uint8_t i, score;
14524
14525 for (i = 0; i < MAX_INDEX_PER_INI; i++) {
14526 score = WLAN_GET_SCORE_PERCENTAGE(per_index_score, i);
14527 if (score > MAX_INDEX_SCORE)
14528 WLAN_SET_SCORE_PERCENTAGE(per_index_score,
14529 MAX_INDEX_SCORE, i);
14530 }
14531
14532 return per_index_score;
14533}
14534
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053014535QDF_STATUS hdd_update_score_config(
14536 struct scoring_config *score_config, struct hdd_context *hdd_ctx)
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014537{
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053014538 struct hdd_config *cfg = hdd_ctx->config;
gaurank kathpaliaae52c982018-10-04 01:35:18 +053014539 QDF_STATUS status;
gaurank kathpalia651abcd2018-11-12 22:41:23 +053014540 struct wlan_mlme_nss_chains vdev_ini_cfg;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053014541 bool bval = false;
Wu Gaoed616a12019-01-16 15:19:21 +080014542 uint32_t channel_bonding_mode;
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014543
Abhishek Singh98278ce2018-12-27 11:41:03 +053014544 qdf_mem_zero(&vdev_ini_cfg, sizeof(struct wlan_mlme_nss_chains));
gaurank kathpalia651abcd2018-11-12 22:41:23 +053014545 /* Populate the nss chain params from ini for this vdev type */
14546 sme_populate_nss_chain_params(hdd_ctx->mac_handle, &vdev_ini_cfg,
14547 QDF_STA_MODE,
14548 hdd_ctx->num_rf_chains);
14549
14550 score_config->vdev_nss_24g = vdev_ini_cfg.rx_nss[NSS_CHAINS_BAND_2GHZ];
gaurank kathpalia19c23542019-06-01 16:57:28 +053014551 score_config->vdev_nss_5g = vdev_ini_cfg.rx_nss[NSS_CHAINS_BAND_5GHZ];
gaurank kathpalia651abcd2018-11-12 22:41:23 +053014552
Vignesh Viswanathan987f0bb2018-09-17 17:00:29 +053014553 sme_update_score_config(hdd_ctx->mac_handle, score_config);
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014554
Wu Gaoed616a12019-01-16 15:19:21 +080014555 ucfg_mlme_get_channel_bonding_24ghz(hdd_ctx->psoc,
14556 &channel_bonding_mode);
14557 score_config->cb_mode_24G = channel_bonding_mode;
14558 ucfg_mlme_get_channel_bonding_5ghz(hdd_ctx->psoc,
14559 &channel_bonding_mode);
14560 score_config->cb_mode_5G = channel_bonding_mode;
gaurank kathpaliaae52c982018-10-04 01:35:18 +053014561
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014562 if (cfg->dot11Mode == eHDD_DOT11_MODE_AUTO ||
14563 cfg->dot11Mode == eHDD_DOT11_MODE_11ax ||
14564 cfg->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY)
14565 score_config->he_cap = 1;
14566
14567 if (score_config->he_cap ||
14568 cfg->dot11Mode == eHDD_DOT11_MODE_11ac ||
14569 cfg->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY)
14570 score_config->vht_cap = 1;
14571
14572 if (score_config->vht_cap || cfg->dot11Mode == eHDD_DOT11_MODE_11n ||
14573 cfg->dot11Mode == eHDD_DOT11_MODE_11n_ONLY)
14574 score_config->ht_cap = 1;
14575
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053014576 status = ucfg_mlme_get_vht_for_24ghz(hdd_ctx->psoc, &bval);
14577 if (!QDF_IS_STATUS_SUCCESS(status))
14578 hdd_err("Failed to get vht_for_24ghz");
14579 if (score_config->vht_cap && bval)
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014580 score_config->vht_24G_cap = 1;
14581
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053014582 status = ucfg_mlme_get_vht_enable_tx_bf(hdd_ctx->psoc,
14583 &bval);
14584 if (!QDF_IS_STATUS_SUCCESS(status))
14585 hdd_err("unable to get vht_enable_tx_bf");
14586
14587 if (bval)
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014588 score_config->beamformee_cap = 1;
14589
Vignesh Viswanathan987f0bb2018-09-17 17:00:29 +053014590 return QDF_STATUS_SUCCESS;
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014591}
14592
Abhishek Singh257a9482017-03-06 16:52:39 +053014593/**
bings81fe50a2017-11-27 14:33:26 +080014594 * hdd_update_dfs_config() - API to update dfs configuration parameters.
14595 * @hdd_ctx: HDD context
14596 *
14597 * Return: 0 if success else err
14598 */
14599static int hdd_update_dfs_config(struct hdd_context *hdd_ctx)
14600{
Dustin Brown1dbefe62018-09-11 16:32:03 -070014601 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Abhishek Singh98278ce2018-12-27 11:41:03 +053014602 struct dfs_user_config dfs_cfg = {0};
bings81fe50a2017-11-27 14:33:26 +080014603 QDF_STATUS status;
14604
Arif Hussain224d3812018-11-16 17:58:38 -080014605 ucfg_mlme_get_dfs_filter_offload(hdd_ctx->psoc,
14606 &dfs_cfg.dfs_is_phyerr_filter_offload);
bings81fe50a2017-11-27 14:33:26 +080014607 status = ucfg_dfs_update_config(psoc, &dfs_cfg);
14608 if (QDF_IS_STATUS_ERROR(status)) {
14609 hdd_err("failed dfs psoc configuration");
14610 return -EINVAL;
14611 }
14612
14613 return 0;
14614}
14615
14616/**
Abhishek Singh257a9482017-03-06 16:52:39 +053014617 * hdd_update_scan_config - API to update scan configuration parameters
14618 * @hdd_ctx: HDD context
14619 *
14620 * Return: 0 if success else err
14621 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014622static int hdd_update_scan_config(struct hdd_context *hdd_ctx)
Abhishek Singh257a9482017-03-06 16:52:39 +053014623{
Dustin Brown1dbefe62018-09-11 16:32:03 -070014624 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Sandeep Puligillad7887022019-02-26 00:48:52 -080014625 struct scan_user_cfg scan_cfg;
Abhishek Singh257a9482017-03-06 16:52:39 +053014626 QDF_STATUS status;
Krunal Sonid2c33e12018-12-06 15:02:37 -080014627 uint32_t mcast_mcc_rest_time = 0;
Vignesh Viswanathana851d752018-10-03 19:44:38 +053014628
Sandeep Puligillad7887022019-02-26 00:48:52 -080014629 qdf_mem_zero(&scan_cfg, sizeof(scan_cfg));
Krunal Sonid2c33e12018-12-06 15:02:37 -080014630 status = ucfg_mlme_get_sta_miracast_mcc_rest_time(hdd_ctx->psoc,
14631 &mcast_mcc_rest_time);
14632 if (!QDF_IS_STATUS_SUCCESS(status)) {
14633 hdd_err("ucfg_mlme_get_sta_miracast_mcc_rest_time, use def");
14634 return -EIO;
14635 }
14636 scan_cfg.sta_miracast_mcc_rest_time = mcast_mcc_rest_time;
Dundi Raviteja85a240a2018-09-10 15:03:07 +053014637 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, hdd_ctx);
Vignesh Viswanathan987f0bb2018-09-17 17:00:29 +053014638
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053014639 status = hdd_update_score_config(&scan_cfg.score_config, hdd_ctx);
Vignesh Viswanathan987f0bb2018-09-17 17:00:29 +053014640 if (QDF_IS_STATUS_ERROR(status)) {
14641 hdd_err("Failed to update scoring config");
14642 return -EINVAL;
14643 }
Abhishek Singhb20db962017-03-03 21:28:46 +053014644
Abhishek Singh257a9482017-03-06 16:52:39 +053014645 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
14646 if (status != QDF_STATUS_SUCCESS) {
14647 hdd_err("failed pmo psoc configuration");
14648 return -EINVAL;
14649 }
14650
14651 return 0;
14652}
Abhishek Singh257a9482017-03-06 16:52:39 +053014653
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014654int hdd_update_components_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053014655{
14656 int ret;
14657
14658 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053014659 if (ret)
14660 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014661
Abhishek Singh257a9482017-03-06 16:52:39 +053014662 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080014663 if (ret)
14664 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014665
Frank Liud4b2fa02017-03-29 11:46:48 +080014666 ret = hdd_update_tdls_config(hdd_ctx);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014667 if (ret)
14668 return ret;
14669
14670 ret = hdd_update_dp_config(hdd_ctx);
bings81fe50a2017-11-27 14:33:26 +080014671 if (ret)
14672 return ret;
14673
14674 ret = hdd_update_dfs_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053014675
14676 return ret;
14677}
14678
Agrawal Ashish65634612016-08-18 13:24:32 +053014679/**
14680 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
14681 * @mode : cfg80211 DFS mode
14682 *
14683 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
14684 */
14685enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
14686{
14687 switch (mode) {
14688 case DFS_MODE_ENABLE:
14689 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053014690 case DFS_MODE_DISABLE:
14691 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053014692 case DFS_MODE_DEPRIORITIZE:
14693 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053014694 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080014695 hdd_debug("ACS dfs mode is NONE");
14696 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053014697 }
14698}
14699
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053014700/**
14701 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
14702 * @hddctx: pointer to hdd context
14703 * @set_value: enable/disable
14704 *
14705 * When Host sends vendor command enable, FW will send *ONE* CA ind to
14706 * Host(even though it is duplicate). When Host send vendor command
14707 * disable,FW doesn't perform any action. Whenever any change in
14708 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
14709 *
14710 * return - 0 on success, appropriate error values on failure.
14711 */
Jeff Johnson16528362018-06-14 12:34:16 -070014712int hdd_enable_disable_ca_event(struct hdd_context *hdd_ctx, uint8_t set_value)
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053014713{
14714 QDF_STATUS status;
14715
Jeff Johnson16528362018-06-14 12:34:16 -070014716 if (0 != wlan_hdd_validate_context(hdd_ctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053014717 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053014718
Jeff Johnson16528362018-06-14 12:34:16 -070014719 status = sme_enable_disable_chanavoidind_event(hdd_ctx->mac_handle,
14720 set_value);
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053014721 if (!QDF_IS_STATUS_SUCCESS(status)) {
14722 hdd_err("Failed to send chan avoid command to SME");
14723 return -EINVAL;
14724 }
14725 return 0;
14726}
Agrawal Ashish65634612016-08-18 13:24:32 +053014727
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014728/**
14729 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
14730 * @value: value to set
14731 *
14732 * This function will set the passed value to roaming in progress flag.
14733 *
14734 * Return: None
14735 */
14736void hdd_set_roaming_in_progress(bool value)
14737{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014738 struct hdd_context *hdd_ctx;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014739
14740 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14741 if (!hdd_ctx) {
14742 hdd_err("HDD context is NULL");
14743 return;
14744 }
14745
14746 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080014747 hdd_debug("Roaming in Progress set to %d", value);
Abhinav Kumar2b431b62019-03-18 20:23:58 +053014748 if (!hdd_ctx->roaming_in_progress) {
14749 /* Reset scan reject params on successful roam complete */
14750 hdd_debug("Reset scan reject params");
14751 hdd_init_scan_reject_params(hdd_ctx);
14752 }
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014753}
14754
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053014755bool hdd_is_roaming_in_progress(struct hdd_context *hdd_ctx)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014756{
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014757 if (!hdd_ctx) {
14758 hdd_err("HDD context is NULL");
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053014759 return false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014760 }
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080014761
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053014762 hdd_debug("roaming_in_progress = %d", hdd_ctx->roaming_in_progress);
14763
14764 return hdd_ctx->roaming_in_progress;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014765}
14766
Jeff Johnsona2ac4e72019-03-06 08:35:29 -080014767bool hdd_is_connection_in_progress(uint8_t *out_vdev_id,
14768 enum scan_reject_states *out_reason)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014769{
Jeff Johnson40dae4e2017-08-29 14:00:25 -070014770 struct hdd_station_ctx *hdd_sta_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -070014771 struct hdd_adapter *adapter = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014772 uint8_t sta_id = 0;
14773 uint8_t *sta_mac = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014774 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -070014775 mac_handle_t mac_handle;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014776
14777 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14778 if (!hdd_ctx) {
14779 hdd_err("HDD context is NULL");
14780 return false;
14781 }
14782
Jeff Johnson16528362018-06-14 12:34:16 -070014783 mac_handle = hdd_ctx->mac_handle;
14784
Dustin Brown920397d2017-12-13 16:27:50 -080014785 hdd_for_each_adapter(hdd_ctx, adapter) {
Tushnim Bhattacharyya929afa42018-06-01 15:04:44 -070014786 hdd_debug("Adapter with device mode %s(%d) exists",
Dustin Brown458027c2018-10-19 12:26:27 -070014787 qdf_opmode_str(adapter->device_mode),
14788 adapter->device_mode);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014789 if (((QDF_STA_MODE == adapter->device_mode)
14790 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
14791 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
14792 && (eConnectionState_Connecting ==
14793 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
Jeff Johnsone7951512019-02-27 10:02:51 -080014794 conn_info.conn_state)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053014795 hdd_debug("%pK(%d) Connection is in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014796 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson5a6fc962019-02-04 14:20:25 -080014797 adapter->vdev_id);
Jeff Johnsona2ac4e72019-03-06 08:35:29 -080014798 if (out_vdev_id && out_reason) {
14799 *out_vdev_id = adapter->vdev_id;
14800 *out_reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014801 }
14802 return true;
14803 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070014804 /*
14805 * sme_neighbor_middle_of_roaming is for LFR2
14806 * hdd_is_roaming_in_progress is for LFR3
14807 */
14808 if (((QDF_STA_MODE == adapter->device_mode) &&
14809 sme_neighbor_middle_of_roaming(
Jeff Johnson16528362018-06-14 12:34:16 -070014810 mac_handle,
Jeff Johnson5a6fc962019-02-04 14:20:25 -080014811 adapter->vdev_id)) ||
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053014812 hdd_is_roaming_in_progress(hdd_ctx)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053014813 hdd_debug("%pK(%d) Reassociation in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014814 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson5a6fc962019-02-04 14:20:25 -080014815 adapter->vdev_id);
Jeff Johnsona2ac4e72019-03-06 08:35:29 -080014816 if (out_vdev_id && out_reason) {
14817 *out_vdev_id = adapter->vdev_id;
14818 *out_reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014819 }
14820 return true;
14821 }
14822 if ((QDF_STA_MODE == adapter->device_mode) ||
14823 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
14824 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
14825 hdd_sta_ctx =
14826 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
14827 if ((eConnectionState_Associated ==
Jeff Johnsone7951512019-02-27 10:02:51 -080014828 hdd_sta_ctx->conn_info.conn_state)
Vignesh Viswanathan0a569292018-02-14 15:34:47 +053014829 && sme_is_sta_key_exchange_in_progress(
Jeff Johnson5a6fc962019-02-04 14:20:25 -080014830 mac_handle, adapter->vdev_id)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014831 sta_mac = (uint8_t *)
Jeff Johnson1e851a12017-10-28 14:36:12 -070014832 &(adapter->mac_addr.bytes[0]);
Srinivas Girigowdacb7b8b82019-04-10 14:27:47 -070014833 hdd_debug("client " QDF_MAC_ADDR_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014834 " is in middle of WPS/EAPOL exchange.",
Srinivas Girigowda34fbba02019-04-08 12:07:44 -070014835 QDF_MAC_ADDR_ARRAY(sta_mac));
Jeff Johnsona2ac4e72019-03-06 08:35:29 -080014836 if (out_vdev_id && out_reason) {
14837 *out_vdev_id = adapter->vdev_id;
14838 *out_reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014839 }
14840 return true;
14841 }
14842 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
14843 (QDF_P2P_GO_MODE == adapter->device_mode)) {
14844 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
14845 sta_id++) {
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070014846 if (!((adapter->sta_info[sta_id].in_use)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014847 && (OL_TXRX_PEER_STATE_CONN ==
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070014848 adapter->sta_info[sta_id].peer_state)))
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014849 continue;
14850
14851 sta_mac = (uint8_t *)
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070014852 &(adapter->sta_info[sta_id].
Jeff Johnsonf2356512017-10-21 16:04:12 -070014853 sta_mac.bytes[0]);
Srinivas Girigowdacb7b8b82019-04-10 14:27:47 -070014854 hdd_debug("client " QDF_MAC_ADDR_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014855 " of SAP/GO is in middle of WPS/EAPOL exchange",
Srinivas Girigowda34fbba02019-04-08 12:07:44 -070014856 QDF_MAC_ADDR_ARRAY(sta_mac));
Jeff Johnsona2ac4e72019-03-06 08:35:29 -080014857 if (out_vdev_id && out_reason) {
14858 *out_vdev_id = adapter->vdev_id;
14859 *out_reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014860 }
14861 return true;
14862 }
14863 if (hdd_ctx->connection_in_progress) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053014864 hdd_debug("AP/GO: connection is in progress");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014865 return true;
14866 }
14867 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014868 }
Dustin Brown920397d2017-12-13 16:27:50 -080014869
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014870 return false;
14871}
14872
14873/**
14874 * hdd_restart_sap() - to restart SAP in driver internally
Jeff Johnson9d295242017-08-29 14:39:48 -070014875 * @ap_adapter: Pointer to SAP struct hdd_adapter structure
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014876 *
14877 * Return: None
14878 */
Jeff Johnson9d295242017-08-29 14:39:48 -070014879void hdd_restart_sap(struct hdd_adapter *ap_adapter)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014880{
Jeff Johnson87251032017-08-29 13:31:11 -070014881 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070014882 struct hdd_hostapd_state *hostapd_state;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014883 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014884 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Jeff Johnson8f8ceb92019-03-24 08:16:55 -070014885 struct sap_config *sap_config;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014886 void *sap_ctx;
14887
14888 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
Jeff Johnson91df29d2017-10-27 19:29:50 -070014889 sap_config = &hdd_ap_ctx->sap_config;
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070014890 sap_ctx = hdd_ap_ctx->sap_context;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014891
14892 mutex_lock(&hdd_ctx->sap_lock);
14893 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
14894 wlan_hdd_del_station(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014895 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
14896 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
14897 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
14898 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053014899 qdf_wait_for_event_completion(&hostapd_state->
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014900 qdf_stop_bss_event,
Abhishek Singhd1f21c72019-01-21 15:16:34 +053014901 SME_CMD_STOP_BSS_TIMEOUT);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014902
14903 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014904 hdd_err("SAP Stop Failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014905 goto end;
14906 }
14907 }
14908 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Dustin Brown1dbefe62018-09-11 16:32:03 -070014909 policy_mgr_decr_session_set_pcl(hdd_ctx->psoc,
Jeff Johnson5a6fc962019-02-04 14:20:25 -080014910 ap_adapter->device_mode, ap_adapter->vdev_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070014911 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053014912 false);
Jeff Johnson6867ec32017-09-29 20:30:20 -070014913 hdd_err("SAP Stop Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014914
14915 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014916 hdd_err("SAP Not able to set AP IEs");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014917 wlansap_reset_sap_config_add_ie(sap_config,
14918 eUPDATE_IE_ALL);
14919 goto end;
14920 }
14921
14922 qdf_event_reset(&hostapd_state->qdf_event);
14923 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
14924 sap_config,
14925 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014926 hdd_err("SAP Start Bss fail");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014927 wlansap_reset_sap_config_add_ie(sap_config,
14928 eUPDATE_IE_ALL);
14929 goto end;
14930 }
14931
Jeff Johnson6867ec32017-09-29 20:30:20 -070014932 hdd_info("Waiting for SAP to start");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014933 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053014934 qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Abhishek Singhd1f21c72019-01-21 15:16:34 +053014935 SME_CMD_START_BSS_TIMEOUT);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014936 wlansap_reset_sap_config_add_ie(sap_config,
14937 eUPDATE_IE_ALL);
14938 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014939 hdd_err("SAP Start failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014940 goto end;
14941 }
Jeff Johnson6867ec32017-09-29 20:30:20 -070014942 hdd_err("SAP Start Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014943 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053014944 if (hostapd_state->bss_state == BSS_START) {
Dustin Brown1dbefe62018-09-11 16:32:03 -070014945 policy_mgr_incr_active_session(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080014946 ap_adapter->device_mode,
Jeff Johnson5a6fc962019-02-04 14:20:25 -080014947 ap_adapter->vdev_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070014948 hdd_green_ap_start_state_mc(hdd_ctx,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053014949 ap_adapter->device_mode,
14950 true);
14951 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014952 }
14953end:
14954 mutex_unlock(&hdd_ctx->sap_lock);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014955}
14956
14957/**
14958 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
14959 * with non dfs acs
14960 *
14961 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
14962 *
14963 * Return: None
14964 */
14965void hdd_check_and_restart_sap_with_non_dfs_acs(void)
14966{
Jeff Johnson9d295242017-08-29 14:39:48 -070014967 struct hdd_adapter *ap_adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014968 struct hdd_context *hdd_ctx;
Jeff Johnson2b6982c2018-05-29 14:56:11 -070014969 struct cds_context *cds_ctx;
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +053014970 uint8_t restart_chan;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014971
14972 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14973 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014974 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014975 return;
14976 }
14977
14978 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
14979 if (!cds_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014980 hdd_err("Invalid CDS Context");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014981 return;
14982 }
14983
Dustin Brown1dbefe62018-09-11 16:32:03 -070014984 if (policy_mgr_get_concurrency_mode(hdd_ctx->psoc)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080014985 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Dustin Brown7e761c72018-07-31 13:50:17 -070014986 hdd_debug("Concurrency mode is not SAP");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014987 return;
14988 }
14989
14990 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Dustin Brown07901ec2018-09-07 11:02:41 -070014991 if (ap_adapter &&
14992 test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags) &&
14993 wlan_reg_is_dfs_ch(hdd_ctx->pdev,
14994 ap_adapter->session.ap.operating_channel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014995
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +053014996 hdd_warn("STA-AP Mode DFS not supported, Switch SAP channel to Non DFS");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014997
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +053014998 restart_chan =
bings6c4672b2019-03-19 16:00:19 +080014999 wlansap_get_safe_channel_from_pcl_and_acs_range(
15000 WLAN_HDD_GET_SAP_CTX_PTR(ap_adapter));
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +053015001 if (!restart_chan ||
Dustin Brown07901ec2018-09-07 11:02:41 -070015002 wlan_reg_is_dfs_ch(hdd_ctx->pdev, restart_chan))
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +053015003 restart_chan = SAP_DEFAULT_5GHZ_CHANNEL;
15004
15005 hdd_switch_sap_channel(ap_adapter, restart_chan, true);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080015006 }
15007}
15008
15009/**
15010 * hdd_set_connection_in_progress() - to set the connection in
15011 * progress flag
15012 * @value: value to set
15013 *
15014 * This function will set the passed value to connection in progress flag.
15015 * If value is previously being set to true then no need to set it again.
15016 *
15017 * Return: true if value is being set correctly and false otherwise.
15018 */
15019bool hdd_set_connection_in_progress(bool value)
15020{
15021 bool status = true;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070015022 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080015023
15024 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
15025 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070015026 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080015027 return false;
15028 }
15029
15030 qdf_spin_lock(&hdd_ctx->connection_status_lock);
15031 /*
15032 * if the value is set to true previously and if someone is
15033 * trying to make it true again then it could be some race
15034 * condition being triggered. Avoid this situation by returning
15035 * false
15036 */
15037 if (hdd_ctx->connection_in_progress && value)
15038 status = false;
15039 else
15040 hdd_ctx->connection_in_progress = value;
15041 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
15042 return status;
15043}
15044
Jeff Johnson9d295242017-08-29 14:39:48 -070015045int wlan_hdd_send_p2p_quota(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070015046{
15047 if (!adapter) {
15048 hdd_err("Invalid adapter");
15049 return -EINVAL;
15050 }
15051 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Jeff Johnson5a6fc962019-02-04 14:20:25 -080015052 sme_cli_set_command(adapter->vdev_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070015053 WMA_VDEV_MCC_SET_TIME_QUOTA,
15054 set_value, VDEV_CMD);
15055 return 0;
15056
15057}
15058
Jeff Johnson9d295242017-08-29 14:39:48 -070015059int wlan_hdd_send_mcc_latency(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070015060{
15061 if (!adapter) {
15062 hdd_err("Invalid adapter");
15063 return -EINVAL;
15064 }
15065
15066 hdd_info("Send MCC latency WMA: %d", set_value);
Jeff Johnson5a6fc962019-02-04 14:20:25 -080015067 sme_cli_set_command(adapter->vdev_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070015068 WMA_VDEV_MCC_SET_TIME_LATENCY,
15069 set_value, VDEV_CMD);
15070 return 0;
15071}
15072
Jeff Johnson9d295242017-08-29 14:39:48 -070015073struct hdd_adapter *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070015074 *psoc, uint8_t vdev_id)
15075{
Jeff Johnson9d295242017-08-29 14:39:48 -070015076 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070015077 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070015078
15079 /*
15080 * Currently PSOC is not being used. But this logic will
15081 * change once we have the converged implementation of
15082 * HDD context per PSOC in place. This would break if
15083 * multiple vdev objects reuse the vdev id.
15084 */
15085 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
15086 if (!adapter)
15087 hdd_err("Get adapter by vdev id failed");
15088
15089 return adapter;
15090}
15091
Jeff Johnson9d295242017-08-29 14:39:48 -070015092int hdd_get_rssi_snr_by_bssid(struct hdd_adapter *adapter, const uint8_t *bssid,
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053015093 int8_t *rssi, int8_t *snr)
15094{
15095 QDF_STATUS status;
Jeff Johnson16528362018-06-14 12:34:16 -070015096 mac_handle_t mac_handle;
Jeff Johnson025618c2018-03-18 14:41:00 -070015097 struct csr_roam_profile *roam_profile;
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053015098
Jeff Johnson025618c2018-03-18 14:41:00 -070015099 roam_profile = hdd_roam_profile(adapter);
Jeff Johnson16528362018-06-14 12:34:16 -070015100 mac_handle = hdd_adapter_get_mac_handle(adapter);
15101 status = sme_get_rssi_snr_by_bssid(mac_handle,
Jeff Johnson025618c2018-03-18 14:41:00 -070015102 roam_profile, bssid, rssi, snr);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053015103 if (QDF_STATUS_SUCCESS != status) {
15104 hdd_warn("sme_get_rssi_snr_by_bssid failed");
15105 return -EINVAL;
15106 }
15107
15108 return 0;
15109}
15110
Ganesh Kondabattini35739572017-06-21 16:26:39 +053015111/**
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053015112 * hdd_reset_limit_off_chan() - reset limit off-channel command parameters
15113 * @adapter - HDD adapter
15114 *
15115 * Return: 0 on success and non zero value on failure
15116 */
15117int hdd_reset_limit_off_chan(struct hdd_adapter *adapter)
15118{
15119 struct hdd_context *hdd_ctx;
15120 int ret;
15121 QDF_STATUS status;
Krunal Sonie71838d2018-09-27 10:45:05 -070015122 uint8_t sys_pref = 0;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053015123
15124 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
15125 ret = wlan_hdd_validate_context(hdd_ctx);
15126 if (ret < 0)
15127 return ret;
15128
Krunal Sonie71838d2018-09-27 10:45:05 -070015129 ucfg_policy_mgr_get_sys_pref(hdd_ctx->psoc,
15130 &sys_pref);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053015131 /* set the system preferece to default */
Krunal Sonie71838d2018-09-27 10:45:05 -070015132 policy_mgr_set_cur_conc_system_pref(hdd_ctx->psoc, sys_pref);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053015133
15134 /* clear the bitmap */
15135 adapter->active_ac = 0;
15136
15137 hdd_debug("reset ac_bitmap for session %hu active_ac %0x",
Jeff Johnson5a6fc962019-02-04 14:20:25 -080015138 adapter->vdev_id, adapter->active_ac);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053015139
Jeff Johnson16528362018-06-14 12:34:16 -070015140 status = sme_send_limit_off_channel_params(hdd_ctx->mac_handle,
Jeff Johnson5a6fc962019-02-04 14:20:25 -080015141 adapter->vdev_id,
Jeff Johnson16528362018-06-14 12:34:16 -070015142 false, 0, 0, false);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053015143 if (!QDF_IS_STATUS_SUCCESS(status)) {
15144 hdd_err("failed to reset limit off chan params");
15145 ret = -EINVAL;
15146 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053015147
15148 return ret;
15149}
15150
Yun Parkff6a16a2017-09-26 16:38:18 -070015151void hdd_set_rx_mode_rps(bool enable)
15152{
15153 struct cds_config_info *cds_cfg = cds_get_ini_config();
Ryan Hsu0e878fa2018-05-04 15:22:09 -070015154 struct hdd_context *hdd_ctx;
15155 struct hdd_adapter *adapter;
Yun Parkff6a16a2017-09-26 16:38:18 -070015156
Ryan Hsu0e878fa2018-05-04 15:22:09 -070015157 if (!cds_cfg)
15158 return;
15159
15160 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
15161 if (!hdd_ctx)
15162 return;
15163
15164 adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
15165 if (!adapter)
15166 return;
15167
15168 if (!hdd_ctx->rps && cds_cfg->uc_offload_enabled) {
Yun Parkff6a16a2017-09-26 16:38:18 -070015169 if (enable && !cds_cfg->rps_enabled)
15170 hdd_send_rps_ind(adapter);
15171 else if (!enable && cds_cfg->rps_enabled)
15172 hdd_send_rps_disable_ind(adapter);
15173 }
15174}
15175
Abhinav Kumar338e57d2019-02-04 17:30:10 +053015176void hdd_hidden_ssid_enable_roaming(hdd_handle_t hdd_handle, uint8_t vdev_id)
15177{
15178 struct hdd_context *hdd_ctx = hdd_handle_to_context(hdd_handle);
15179 struct hdd_adapter *adapter;
15180
15181 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
15182
15183 if (!adapter) {
15184 hdd_err("Adapter is null");
15185 return;
15186 }
15187 /* enable roaming on all adapters once hdd get hidden ssid rsp */
15188 wlan_hdd_enable_roaming(adapter);
15189}
15190
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015191/* Register the module init/exit functions */
15192module_init(hdd_module_init);
15193module_exit(hdd_module_exit);
15194
15195MODULE_LICENSE("Dual BSD/GPL");
15196MODULE_AUTHOR("Qualcomm Atheros, Inc.");
15197MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
15198
Srinivas Girigowda841da292018-02-21 16:33:00 -080015199static const struct kernel_param_ops con_mode_ops = {
15200 .set = con_mode_handler,
15201 .get = param_get_int,
15202};
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015203
Srinivas Girigowda841da292018-02-21 16:33:00 -080015204static const struct kernel_param_ops con_mode_ftm_ops = {
15205 .set = con_mode_handler_ftm,
15206 .get = param_get_int,
15207};
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053015208
Nirav Shah6aeecf92019-02-13 14:05:03 +053015209#ifdef WLAN_FEATURE_EPPING
15210static const struct kernel_param_ops con_mode_epping_ops = {
15211 .set = con_mode_handler_epping,
15212 .get = param_get_int,
15213};
15214#endif
15215
Nirav Shah73713f72018-05-17 14:50:41 +053015216#ifdef FEATURE_MONITOR_MODE_SUPPORT
Srinivas Girigowda841da292018-02-21 16:33:00 -080015217static const struct kernel_param_ops con_mode_monitor_ops = {
15218 .set = con_mode_handler_monitor,
15219 .get = param_get_int,
15220};
Nirav Shah73713f72018-05-17 14:50:41 +053015221#endif
Ravi Joshia307f632017-07-17 23:41:41 -070015222
Srinivas Girigowda841da292018-02-21 16:33:00 -080015223static const struct kernel_param_ops fwpath_ops = {
15224 .set = fwpath_changed_handler,
15225 .get = param_get_string,
15226};
15227
15228module_param_cb(con_mode, &con_mode_ops, &con_mode,
15229 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
15230
15231module_param_cb(con_mode_ftm, &con_mode_ftm_ops, &con_mode_ftm,
15232 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
15233
Nirav Shah6aeecf92019-02-13 14:05:03 +053015234#ifdef WLAN_FEATURE_EPPING
15235module_param_cb(con_mode_epping, &con_mode_epping_ops,
15236 &con_mode_epping, 0644);
15237#endif
15238
Nirav Shah73713f72018-05-17 14:50:41 +053015239#ifdef FEATURE_MONITOR_MODE_SUPPORT
Srinivas Girigowda841da292018-02-21 16:33:00 -080015240module_param_cb(con_mode_monitor, &con_mode_monitor_ops, &con_mode_monitor,
15241 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Nirav Shah73713f72018-05-17 14:50:41 +053015242#endif
Srinivas Girigowda841da292018-02-21 16:33:00 -080015243
15244module_param_cb(fwpath, &fwpath_ops, &fwpath,
15245 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015246
15247module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
15248
15249module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
15250
15251module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);
Dustin Brown4bbd5462019-03-22 11:18:13 -070015252
15253static int timer_multiplier_get_handler(char *buffer,
15254 const struct kernel_param *kp)
15255{
15256 return scnprintf(buffer, PAGE_SIZE, "%u", qdf_timer_get_multiplier());
15257}
15258
15259static int timer_multiplier_set_handler(const char *kmessage,
15260 const struct kernel_param *kp)
15261{
15262 QDF_STATUS status;
15263 uint32_t scalar;
15264
15265 status = qdf_uint32_parse(kmessage, &scalar);
15266 if (QDF_IS_STATUS_ERROR(status))
15267 return qdf_status_to_os_return(status);
15268
15269 if (!cfg_in_range(CFG_TIMER_MULTIPLIER, scalar))
15270 return -ERANGE;
15271
15272 qdf_timer_set_multiplier(scalar);
15273
15274 return 0;
15275}
15276
15277static const struct kernel_param_ops timer_multiplier_ops = {
15278 .get = timer_multiplier_get_handler,
15279 .set = timer_multiplier_set_handler,
15280};
15281
15282module_param_cb(timer_multiplier, &timer_multiplier_ops, NULL, 0644);
15283