blob: 0f4a68d399582ac74429cda48af2baec48c6f725 [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 Brownd4241942018-02-26 12:51:37 -080058#include "qdf_str.h"
Dustin Brownd315c452018-11-27 11:28:48 -080059#include "qdf_talloc.h"
Dustin Brownd4241942018-02-26 12:51:37 -080060#include "qdf_trace.h"
61#include "qdf_types.h"
Manjunathappa Prakash3454fd62016-04-01 08:52:06 -070062#include <cdp_txrx_peer_ops.h>
Dhanashri Atrea8f82f22017-01-23 12:58:24 -080063#include <cdp_txrx_misc.h>
Mohit Khannaca4173b2017-09-12 21:52:19 -070064#include <cdp_txrx_stats.h>
bings0e03a982018-05-09 08:40:59 +080065#include "cdp_txrx_flow_ctrl_legacy.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080066
67#include <net/addrconf.h>
68#include <linux/wireless.h>
69#include <net/cfg80211.h>
70#include <linux/inetdevice.h>
71#include <net/addrconf.h>
72#include "wlan_hdd_cfg80211.h"
73#include "wlan_hdd_ext_scan.h"
74#include "wlan_hdd_p2p.h"
75#include <linux/rtnetlink.h>
76#include "sap_api.h"
77#include <linux/semaphore.h>
78#include <linux/ctype.h>
79#include <linux/compat.h>
Arunk Khandavalli830c9692018-03-22 12:17:40 +053080#include <linux/reboot.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080081#ifdef MSM_PLATFORM
Dustin Browna20bad52019-03-05 12:03:30 -080082#include "qdf_periodic_work.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080083#include <soc/qcom/subsystem_restart.h>
84#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080085#include <wlan_hdd_hostapd.h>
86#include <wlan_hdd_softap_tx_rx.h>
Jeff Johnson8bb61112018-03-31 13:33:54 -070087#include <wlan_hdd_green_ap.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080088#include "qwlan_version.h"
89#include "wma_types.h"
90#include "wlan_hdd_tdls.h"
91#ifdef FEATURE_WLAN_CH_AVOID
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +053092#include "cds_regdomain.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080093#endif /* FEATURE_WLAN_CH_AVOID */
Dustin Brownce46d1d2017-08-15 13:34:24 -070094#include "cdp_txrx_flow_ctrl_v2.h"
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070095#include "pld_common.h"
Tushnim Bhattacharyya15596cf2016-02-12 11:57:02 -080096#include "wlan_hdd_ocb.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080097#include "wlan_hdd_nan.h"
98#include "wlan_hdd_debugfs.h"
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +053099#include "wlan_hdd_debugfs_csr.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800100#include "wlan_hdd_driver_ops.h"
101#include "epping_main.h"
Poddar, Siddarth34872782017-08-10 14:08:51 +0530102#include "wlan_hdd_data_stall_detection.h"
stonezc9936cb2019-03-11 16:41:22 +0800103#include "wlan_hdd_mpta_helper.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800104
105#include <wlan_hdd_ipa.h>
106#include "hif.h"
107#include "wma.h"
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -0800108#include "wlan_policy_mgr_api.h"
Manikandan Mohandcc21ba2016-03-15 14:31:56 -0700109#include "wlan_hdd_tsf.h"
Komal Seelamec702b02016-02-24 18:42:16 +0530110#include "bmi.h"
Amar Singhale4f28ee2015-10-21 14:36:56 -0700111#include <wlan_hdd_regulatory.h>
Jeff Johnson2b0a7b82016-05-18 15:08:02 -0700112#include "wlan_hdd_lpass.h"
Nachiket Kukade63bb63d2018-11-21 14:42:14 +0530113#include "wlan_nan_api.h"
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -0700114#include <wlan_hdd_napi.h>
Padma, Santhosh Kumard7cc0792016-06-28 18:54:12 +0530115#include "wlan_hdd_disa.h"
Rajeev Kumar97767a02016-11-30 11:20:40 -0800116#include <dispatcher_init_deinit.h>
Rajeev Kumar699debf2017-01-06 14:17:00 -0800117#include "wlan_hdd_object_manager.h"
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +0530118#include "cds_utils.h"
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -0800119#include <cdp_txrx_handle.h>
Sandeep Puligillafdd201e2017-02-02 18:43:46 -0800120#include <qca_vendor.h>
Mukul Sharma9d797a02017-01-05 20:26:03 +0530121#include "wlan_pmo_ucfg_api.h"
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +0530122#include "sir_api.h"
Naveen Rawat910726a2017-03-06 11:42:51 -0800123#include "os_if_wifi_pos.h"
124#include "wifi_pos_api.h"
125#include "wlan_hdd_oemdata.h"
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -0800126#include "wlan_hdd_he.h"
Naveen Rawatcb5c5402017-03-22 10:12:19 -0700127#include "os_if_nan.h"
128#include "nan_public_structs.h"
Nachiket Kukade85aa3782018-11-02 20:12:34 +0530129#include "nan_ucfg_api.h"
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -0700130#include "wlan_reg_ucfg_api.h"
bings81fe50a2017-11-27 14:33:26 +0800131#include "wlan_dfs_ucfg_api.h"
Ravi Joshi4f095952017-06-29 15:39:19 -0700132#include "wlan_hdd_rx_monitor.h"
Mukul Sharmad16c2022017-07-25 18:56:12 +0530133#include "sme_power_save_api.h"
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +0530134#include "enet.h"
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -0700135#include <cdp_txrx_cmn_struct.h>
Mohit Khanna70322002018-05-15 19:21:32 -0700136#include <dp_txrx.h>
Amar Singhal0928b192017-12-01 10:50:54 -0800137#include "wlan_hdd_sysfs.h"
Nachiket Kukade98f562a2017-12-15 12:18:07 +0530138#include "wlan_disa_ucfg_api.h"
Wu Gao52084c12018-05-17 20:47:11 +0800139#include "wlan_disa_obj_mgmt_api.h"
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +0530140#include "wlan_action_oui_ucfg_api.h"
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +0530141#include "wlan_ipa_ucfg_api.h"
Arunk Khandavallia6305a32018-01-25 11:19:18 +0530142#include <target_if.h>
Alok Kumarb64650c2018-03-23 17:05:11 +0530143#include "wlan_hdd_nud_tracking.h"
Nachiket Kukaded0dd62e2018-05-21 18:39:22 +0530144#include "wlan_hdd_apf.h"
Varun Reddy Yeturue93d2462018-05-22 13:54:52 -0700145#include "wlan_hdd_twt.h"
Rachit Kankane0dc3e852018-05-07 17:33:42 +0530146#include "qc_sap_ioctl.h"
Sandeep Puligillac5609d52018-05-17 19:23:41 -0700147#include "wlan_mlme_main.h"
Wu Gaoe5689792018-07-05 19:20:13 +0800148#include "wlan_p2p_cfg_api.h"
Wu Gao637d58a2018-12-08 10:37:34 +0800149#include "wlan_cfg80211_p2p.h"
Wu Gaobdb7f272018-07-05 19:33:26 +0800150#include "wlan_tdls_cfg_api.h"
Qiwei Caie689a262018-07-26 15:50:22 +0800151#include <wlan_hdd_rssi_monitor.h>
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +0530152#include "wlan_mlme_ucfg_api.h"
Sourav Mohapatra113685f2018-08-29 14:21:55 +0530153#include "wlan_fwol_ucfg_api.h"
Krunal Sonie71838d2018-09-27 10:45:05 -0700154#include "wlan_policy_mgr_ucfg.h"
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530155#ifdef CNSS_GENL
156#include <net/cnss_nl.h>
157#endif
Amar Singhal5cccafe2017-02-15 12:42:58 -0800158#include "wlan_reg_ucfg_api.h"
Zhang Qian47e22ce2018-01-04 15:38:38 +0800159#include "wlan_ocb_ucfg_api.h"
Sandeep Puligilla019a1bd2018-02-04 22:57:44 -0800160#include <wlan_hdd_spectralscan.h>
gaurank kathpalia4a205fc2018-09-15 00:59:15 +0530161#include "wlan_green_ap_ucfg_api.h"
Liangwei Dong3abfe8f2018-09-20 02:25:44 -0400162#include <wlan_p2p_ucfg_api.h>
Mohit Khanna81418772018-10-30 14:14:46 -0700163#include <target_type.h>
Arun Kumar Khandavallideda5a82019-03-11 15:32:19 +0530164#include <wlan_hdd_debugfs_coex.h>
Liangwei Dong3abfe8f2018-09-20 02:25:44 -0400165
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800166#ifdef MODULE
167#define WLAN_MODULE_NAME module_name(THIS_MODULE)
168#else
169#define WLAN_MODULE_NAME "wlan"
170#endif
171
172#ifdef TIMER_MANAGER
173#define TIMER_MANAGER_STR " +TIMER_MANAGER"
174#else
175#define TIMER_MANAGER_STR ""
176#endif
177
178#ifdef MEMORY_DEBUG
179#define MEMORY_DEBUG_STR " +MEMORY_DEBUG"
180#else
181#define MEMORY_DEBUG_STR ""
182#endif
183
Dustin Brownc1034df2018-02-07 14:51:32 -0800184#ifdef PANIC_ON_BUG
185#define PANIC_ON_BUG_STR " +PANIC_ON_BUG"
186#else
187#define PANIC_ON_BUG_STR ""
188#endif
189
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530190bool g_is_system_reboot_triggered;
Sachin Ahujadddd2632017-03-07 19:07:24 +0530191int wlan_start_ret_val;
192static DECLARE_COMPLETION(wlan_start_comp);
193static unsigned int dev_num = 1;
194static struct cdev wlan_hdd_state_cdev;
195static struct class *class;
196static dev_t device;
Arun Khandavallifae92942016-08-01 13:31:08 +0530197#ifndef MODULE
198static struct gwlan_loader *wlan_loader;
199static ssize_t wlan_boot_cb(struct kobject *kobj,
200 struct kobj_attribute *attr,
201 const char *buf, size_t count);
202struct gwlan_loader {
203 bool loaded_state;
204 struct kobject *boot_wlan_obj;
205 struct attribute_group *attr_group;
206};
207
208static struct kobj_attribute wlan_boot_attribute =
209 __ATTR(boot_wlan, 0220, NULL, wlan_boot_cb);
210
211static struct attribute *attrs[] = {
212 &wlan_boot_attribute.attr,
213 NULL,
214};
215
216#define MODULE_INITIALIZED 1
Qun Zhang4a83a462018-09-11 16:28:51 +0800217
218#ifdef MULTI_IF_NAME
219#define WLAN_LOADER_NAME "boot_" MULTI_IF_NAME
220#else
221#define WLAN_LOADER_NAME "boot_wlan"
222#endif
Arun Khandavallifae92942016-08-01 13:31:08 +0530223#endif
224
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800225/* the Android framework expects this param even though we don't use it */
226#define BUF_LEN 20
227static char fwpath_buffer[BUF_LEN];
228static struct kparam_string fwpath = {
229 .string = fwpath_buffer,
230 .maxlen = BUF_LEN,
231};
232
233static char *country_code;
234static int enable_11d = -1;
235static int enable_dfs_chan_scan = -1;
236
Rajeev Kumar8e3e2832015-11-06 16:02:54 -0800237#define WLAN_NLINK_CESIUM 30
238
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530239static qdf_wake_lock_t wlan_wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800240
241#define WOW_MAX_FILTER_LISTS 1
242#define WOW_MAX_FILTERS_PER_LIST 4
243#define WOW_MIN_PATTERN_SIZE 6
244#define WOW_MAX_PATTERN_SIZE 64
245
Bala Venkatesh110b03e2018-07-10 16:02:08 +0530246/* max peer can be tdls peers + self peer + bss peer */
247#define HDD_MAX_VDEV_PEER_COUNT (HDD_MAX_NUM_TDLS_STA + 2)
Sourav Mohapatra808e3d42018-07-04 09:34:23 +0530248#define IS_IDLE_STOP (!cds_is_driver_unloading() && \
249 !cds_is_driver_recovering() && !cds_is_driver_loading())
Bala Venkatesh110b03e2018-07-10 16:02:08 +0530250
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800251#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
252static const struct wiphy_wowlan_support wowlan_support_reg_init = {
253 .flags = WIPHY_WOWLAN_ANY |
254 WIPHY_WOWLAN_MAGIC_PKT |
255 WIPHY_WOWLAN_DISCONNECT |
256 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
257 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
258 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
259 WIPHY_WOWLAN_4WAY_HANDSHAKE |
260 WIPHY_WOWLAN_RFKILL_RELEASE,
261 .n_patterns = WOW_MAX_FILTER_LISTS * WOW_MAX_FILTERS_PER_LIST,
262 .pattern_min_len = WOW_MIN_PATTERN_SIZE,
263 .pattern_max_len = WOW_MAX_PATTERN_SIZE,
264};
265#endif
266
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700267static const struct category_info cinfo[MAX_SUPPORTED_CATEGORY] = {
268 [QDF_MODULE_ID_TLSHIM] = {QDF_TRACE_LEVEL_ALL},
269 [QDF_MODULE_ID_WMI] = {QDF_TRACE_LEVEL_ALL},
270 [QDF_MODULE_ID_HTT] = {QDF_TRACE_LEVEL_ALL},
271 [QDF_MODULE_ID_HDD] = {QDF_TRACE_LEVEL_ALL},
272 [QDF_MODULE_ID_SME] = {QDF_TRACE_LEVEL_ALL},
273 [QDF_MODULE_ID_PE] = {QDF_TRACE_LEVEL_ALL},
274 [QDF_MODULE_ID_WMA] = {QDF_TRACE_LEVEL_ALL},
275 [QDF_MODULE_ID_SYS] = {QDF_TRACE_LEVEL_ALL},
276 [QDF_MODULE_ID_QDF] = {QDF_TRACE_LEVEL_ALL},
277 [QDF_MODULE_ID_SAP] = {QDF_TRACE_LEVEL_ALL},
278 [QDF_MODULE_ID_HDD_SOFTAP] = {QDF_TRACE_LEVEL_ALL},
279 [QDF_MODULE_ID_HDD_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
280 [QDF_MODULE_ID_HDD_SAP_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
281 [QDF_MODULE_ID_HIF] = {QDF_DATA_PATH_TRACE_LEVEL},
282 [QDF_MODULE_ID_HTC] = {QDF_DATA_PATH_TRACE_LEVEL},
283 [QDF_MODULE_ID_TXRX] = {QDF_DATA_PATH_TRACE_LEVEL},
284 [QDF_MODULE_ID_QDF_DEVICE] = {QDF_TRACE_LEVEL_ALL},
285 [QDF_MODULE_ID_CFG] = {QDF_TRACE_LEVEL_ALL},
286 [QDF_MODULE_ID_BMI] = {QDF_TRACE_LEVEL_ALL},
287 [QDF_MODULE_ID_EPPING] = {QDF_TRACE_LEVEL_ALL},
288 [QDF_MODULE_ID_QVIT] = {QDF_TRACE_LEVEL_ALL},
289 [QDF_MODULE_ID_DP] = {QDF_TRACE_LEVEL_ALL},
290 [QDF_MODULE_ID_SOC] = {QDF_TRACE_LEVEL_ALL},
291 [QDF_MODULE_ID_OS_IF] = {QDF_TRACE_LEVEL_ALL},
292 [QDF_MODULE_ID_TARGET_IF] = {QDF_TRACE_LEVEL_ALL},
293 [QDF_MODULE_ID_SCHEDULER] = {QDF_TRACE_LEVEL_ALL},
294 [QDF_MODULE_ID_MGMT_TXRX] = {QDF_TRACE_LEVEL_ALL},
295 [QDF_MODULE_ID_PMO] = {QDF_TRACE_LEVEL_ALL},
296 [QDF_MODULE_ID_SCAN] = {QDF_TRACE_LEVEL_ALL},
297 [QDF_MODULE_ID_POLICY_MGR] = {QDF_TRACE_LEVEL_ALL},
298 [QDF_MODULE_ID_P2P] = {QDF_TRACE_LEVEL_ALL},
299 [QDF_MODULE_ID_TDLS] = {QDF_TRACE_LEVEL_ALL},
300 [QDF_MODULE_ID_REGULATORY] = {QDF_TRACE_LEVEL_ALL},
301 [QDF_MODULE_ID_SERIALIZATION] = {QDF_TRACE_LEVEL_ALL},
Arif Hussainfde76e72017-09-05 16:58:23 -0700302 [QDF_MODULE_ID_DFS] = {QDF_TRACE_LEVEL_ALL},
Rajeev Kumarca8ef9d2017-10-06 10:43:21 -0700303 [QDF_MODULE_ID_OBJ_MGR] = {QDF_TRACE_LEVEL_ALL},
Deepak Dhamdheref918d422017-07-06 12:56:29 -0700304 [QDF_MODULE_ID_ROAM_DEBUG] = {QDF_TRACE_LEVEL_ALL},
Himanshu Agarwalb229a142017-12-21 10:16:45 +0530305 [QDF_MODULE_ID_GREEN_AP] = {QDF_TRACE_LEVEL_ALL},
Zhang Qian47e22ce2018-01-04 15:38:38 +0800306 [QDF_MODULE_ID_OCB] = {QDF_TRACE_LEVEL_ALL},
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530307 [QDF_MODULE_ID_IPA] = {QDF_TRACE_LEVEL_ALL},
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +0530308 [QDF_MODULE_ID_ACTION_OUI] = {QDF_TRACE_LEVEL_ALL},
Dustin Brown84f46ea2018-02-15 11:57:36 -0800309 [QDF_MODULE_ID_CONFIG] = {QDF_TRACE_LEVEL_ALL},
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +0530310 [QDF_MODULE_ID_MLME] = {QDF_TRACE_LEVEL_ALL},
Ashish Kumar Dhanotiya8d039c82018-07-11 20:41:14 +0530311 [QDF_MODULE_ID_TARGET] = {QDF_TRACE_LEVEL_ALL},
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -0700312 [QDF_MODULE_ID_CRYPTO] = {QDF_TRACE_LEVEL_ALL},
Sourav Mohapatra113685f2018-08-29 14:21:55 +0530313 [QDF_MODULE_ID_FWOL] = {QDF_TRACE_LEVEL_ALL},
Abhishek Singh0b0105f2018-09-25 10:44:16 +0530314 [QDF_MODULE_ID_SM_ENGINE] = {QDF_TRACE_LEVEL_ALL},
315 [QDF_MODULE_ID_CMN_MLME] = {QDF_TRACE_LEVEL_ALL},
Nachiket Kukade089b9832018-12-12 16:38:17 +0530316 [QDF_MODULE_ID_NAN] = {QDF_TRACE_LEVEL_ALL},
Ashish Kumar Dhanotiya6ed44342019-02-07 21:11:00 +0530317 [QDF_MODULE_ID_CP_STATS] = {QDF_TRACE_LEVEL_ALL},
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700318};
319
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +0530320struct notifier_block hdd_netdev_notifier;
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530321struct notifier_block system_reboot_notifier;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800322
323struct sock *cesium_nl_srv_sock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800324#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700325static void wlan_hdd_auto_shutdown_cb(void);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800326#endif
327
Sachin Ahujadddd2632017-03-07 19:07:24 +0530328void hdd_start_complete(int ret)
329{
330 wlan_start_ret_val = ret;
331
332 complete(&wlan_start_comp);
333}
334
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800335/**
Nirav Shahbd36b062016-07-18 11:12:59 +0530336 * hdd_set_rps_cpu_mask - set RPS CPU mask for interfaces
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700337 * @hdd_ctx: pointer to struct hdd_context
Nirav Shahbd36b062016-07-18 11:12:59 +0530338 *
339 * Return: none
340 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700341static void hdd_set_rps_cpu_mask(struct hdd_context *hdd_ctx)
Nirav Shahbd36b062016-07-18 11:12:59 +0530342{
Jeff Johnson9d295242017-08-29 14:39:48 -0700343 struct hdd_adapter *adapter;
Nirav Shahbd36b062016-07-18 11:12:59 +0530344
Dustin Brown920397d2017-12-13 16:27:50 -0800345 hdd_for_each_adapter(hdd_ctx, adapter)
346 hdd_send_rps_ind(adapter);
Nirav Shahbd36b062016-07-18 11:12:59 +0530347}
348
Ajit Pal Singh106c1412018-04-18 18:08:49 +0530349#ifdef QCA_HL_NETDEV_FLOW_CONTROL
350void wlan_hdd_mod_fc_timer(struct hdd_adapter *adapter,
351 enum netif_action_type action)
352{
353 if (!adapter->tx_flow_timer_initialized)
354 return;
355
356 if (action == WLAN_WAKE_NON_PRIORITY_QUEUE) {
357 qdf_mc_timer_stop(&adapter->tx_flow_control_timer);
Ajit Pal Singhe6da1de2018-12-27 16:20:45 +0530358 adapter->hdd_stats.tx_rx_stats.is_txflow_paused = false;
359 adapter->hdd_stats.tx_rx_stats.txflow_unpause_cnt++;
Ajit Pal Singh106c1412018-04-18 18:08:49 +0530360 } else if (action == WLAN_STOP_NON_PRIORITY_QUEUE) {
361 QDF_STATUS status =
362 qdf_mc_timer_start(&adapter->tx_flow_control_timer,
363 WLAN_HDD_TX_FLOW_CONTROL_OS_Q_BLOCK_TIME);
364
365 if (!QDF_IS_STATUS_SUCCESS(status))
366 hdd_err("Failed to start tx_flow_control_timer");
367 else
368 adapter->
369 hdd_stats.tx_rx_stats.txflow_timer_cnt++;
370
371 adapter->hdd_stats.tx_rx_stats.txflow_pause_cnt++;
372 adapter->hdd_stats.tx_rx_stats.is_txflow_paused = true;
373 }
374}
375#endif /* QCA_HL_NETDEV_FLOW_CONTROL */
376
Alok Kumar2fad6442018-11-08 19:19:28 +0530377#ifdef MSM_PLATFORM
378void wlan_hdd_update_tcp_rx_param(struct hdd_context *hdd_ctx, void *data)
379{
380 if (!hdd_ctx) {
381 hdd_err("HDD context is null");
382 return;
383 }
384
385 if (!data) {
386 hdd_err("Data is null");
387 return;
388 }
389 if (hdd_ctx->config->enable_tcp_param_update)
390 wlan_hdd_send_tcp_param_update_event(hdd_ctx, data, 1);
391 else
392 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
393 WLAN_SVC_WLAN_TP_IND,
394 data,
395 sizeof(struct wlan_rx_tp_data));
396}
397
398void wlan_hdd_update_tcp_tx_param(struct hdd_context *hdd_ctx, void *data)
399{
400 enum wlan_tp_level next_tx_level;
401 struct wlan_tx_tp_data *tx_tp_data;
402
403 if (!hdd_ctx) {
404 hdd_err("HDD context is null");
405 return;
406 }
407
408 if (!data) {
409 hdd_err("Data is null");
410 return;
411 }
412
413 tx_tp_data = (struct wlan_tx_tp_data *)data;
414 next_tx_level = tx_tp_data->level;
415
416 if (hdd_ctx->config->enable_tcp_param_update)
417 wlan_hdd_send_tcp_param_update_event(hdd_ctx, data, 0);
418 else
419 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
420 WLAN_SVC_WLAN_TP_TX_IND,
421 &next_tx_level,
422 sizeof(next_tx_level));
423}
424
425/**
426 * wlan_hdd_send_tcp_param_update_event() - Send vendor event to update
427 * TCP parameter through Wi-Fi HAL
428 * @hdd_ctx: Pointer to HDD context
429 * @data: Parameters to update
430 * @dir: Direction(tx/rx) to update
431 *
432 * Return: None
433 */
434void wlan_hdd_send_tcp_param_update_event(struct hdd_context *hdd_ctx,
435 void *data,
436 uint8_t dir)
437{
438 struct sk_buff *vendor_event;
439 uint32_t event_len;
440 bool tcp_limit_output = false;
441 bool tcp_del_ack_ind_enabled = false;
442 bool tcp_adv_win_scl_enabled = false;
443 enum wlan_tp_level next_tp_level = WLAN_SVC_TP_NONE;
444
445 event_len = sizeof(uint8_t) + sizeof(uint8_t) + NLMSG_HDRLEN;
446
447 if (dir == 0) /*TX Flow */ {
448 struct wlan_tx_tp_data *tx_tp_data =
449 (struct wlan_tx_tp_data *)data;
450
451 next_tp_level = tx_tp_data->level;
452
453 if (tx_tp_data->tcp_limit_output) {
454 /* TCP_LIMIT_OUTPUT_BYTES */
455 event_len += sizeof(uint32_t);
456 tcp_limit_output = true;
457 }
458 } else if (dir == 1) /* RX Flow */ {
459 struct wlan_rx_tp_data *rx_tp_data =
460 (struct wlan_rx_tp_data *)data;
461
462 next_tp_level = rx_tp_data->level;
463
464 if (rx_tp_data->rx_tp_flags & TCP_DEL_ACK_IND_MASK) {
465 event_len += sizeof(uint32_t); /* TCP_DELACK_SEG */
466 tcp_del_ack_ind_enabled = true;
467 }
468 if (rx_tp_data->rx_tp_flags & TCP_ADV_WIN_SCL_MASK) {
469 event_len += sizeof(uint32_t); /* TCP_ADV_WIN_SCALE */
470 tcp_adv_win_scl_enabled = true;
471 }
472 } else {
473 hdd_err("Invalid Direction [%d]", dir);
474 return;
475 }
476
477 vendor_event =
478 cfg80211_vendor_event_alloc(
479 hdd_ctx->wiphy,
480 NULL, event_len,
481 QCA_NL80211_VENDOR_SUBCMD_THROUGHPUT_CHANGE_EVENT_INDEX,
482 GFP_KERNEL);
483
484 if (!vendor_event) {
485 hdd_err("cfg80211_vendor_event_alloc failed");
486 return;
487 }
488
489 if (nla_put_u8(
490 vendor_event,
491 QCA_WLAN_VENDOR_ATTR_THROUGHPUT_CHANGE_DIRECTION,
492 dir))
493 goto tcp_param_change_nla_failed;
494
495 if (nla_put_u8(
496 vendor_event,
497 QCA_WLAN_VENDOR_ATTR_THROUGHPUT_CHANGE_THROUGHPUT_LEVEL,
498 (next_tp_level == WLAN_SVC_TP_LOW ?
499 QCA_WLAN_THROUGHPUT_LEVEL_LOW :
500 QCA_WLAN_THROUGHPUT_LEVEL_HIGH)))
501 goto tcp_param_change_nla_failed;
502
503 if (tcp_limit_output &&
504 nla_put_u32(
505 vendor_event,
506 QCA_WLAN_VENDOR_ATTR_THROUGHPUT_CHANGE_TCP_LIMIT_OUTPUT_BYTES,
507 (next_tp_level == WLAN_SVC_TP_LOW ?
508 TCP_LIMIT_OUTPUT_BYTES_LOW :
509 TCP_LIMIT_OUTPUT_BYTES_HI)))
510 goto tcp_param_change_nla_failed;
511
512 if (tcp_del_ack_ind_enabled &&
513 (nla_put_u32(
514 vendor_event,
515 QCA_WLAN_VENDOR_ATTR_THROUGHPUT_CHANGE_TCP_DELACK_SEG,
516 (next_tp_level == WLAN_SVC_TP_LOW ?
517 TCP_DEL_ACK_LOW : TCP_DEL_ACK_HI))))
518 goto tcp_param_change_nla_failed;
519
520 if (tcp_adv_win_scl_enabled &&
521 (nla_put_u32(
522 vendor_event,
523 QCA_WLAN_VENDOR_ATTR_THROUGHPUT_CHANGE_TCP_ADV_WIN_SCALE,
524 (next_tp_level == WLAN_SVC_TP_LOW ?
525 WIN_SCALE_LOW : WIN_SCALE_HI))))
526 goto tcp_param_change_nla_failed;
527
528 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
529 return;
530
531tcp_param_change_nla_failed:
532 hdd_err("nla_put api failed");
533 kfree_skb(vendor_event);
534}
535#endif /* MSM_PLATFORM */
536
Nirav Shahbd36b062016-07-18 11:12:59 +0530537/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800538 * wlan_hdd_txrx_pause_cb() - pause callback from txrx layer
539 * @vdev_id: vdev_id
540 * @action: action type
541 * @reason: reason type
542 *
543 * Return: none
544 */
545void wlan_hdd_txrx_pause_cb(uint8_t vdev_id,
546 enum netif_action_type action, enum netif_reason_type reason)
547{
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700548 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Jeff Johnson9d295242017-08-29 14:39:48 -0700549 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800550
551 if (!hdd_ctx) {
552 hdd_err("hdd ctx is NULL");
553 return;
554 }
555 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
Ajit Pal Singh106c1412018-04-18 18:08:49 +0530556 wlan_hdd_mod_fc_timer(adapter, action);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800557 wlan_hdd_netif_queue_control(adapter, action, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800558}
559
560/*
Dustin Brownab482ac2017-06-09 17:00:44 -0700561 * Store WLAN driver version and timestamp info in global variables such that
562 * crash debugger can extract them from driver debug symbol and crashdump for
563 * post processing
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800564 */
Dustin Brown96cd9632017-11-13 12:45:04 -0800565#ifdef BUILD_TAG
Rajeev Kumare555e2d2018-09-17 11:52:37 -0700566uint8_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 -0800567#else
Rajeev Kumare555e2d2018-09-17 11:52:37 -0700568uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR TIMER_MANAGER_STR MEMORY_DEBUG_STR PANIC_ON_BUG_STR;
Naveen Rawat93836252017-06-20 16:30:59 -0700569#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800570
571/**
Liangwei Dong17bf2662018-01-05 02:02:05 -0500572 * hdd_get_valid_chan() - return current chan list from regulatory.
573 * @hdd_ctx: HDD context
574 * @chan_list: buf hold returned chan list
575 * @chan_num: input buf size and output returned chan num
576 *
577 * This function helps get current available chan list from regulatory
578 * module. It excludes the "disabled" and "invalid" channels.
579 *
580 * Return: 0 for success.
581 */
582static int hdd_get_valid_chan(struct hdd_context *hdd_ctx,
583 uint8_t *chan_list,
584 uint32_t *chan_num)
585{
586 int i = 0, j = 0;
587 struct regulatory_channel *cur_chan_list;
588 struct wlan_objmgr_pdev *pdev;
589
Dustin Brown07901ec2018-09-07 11:02:41 -0700590 if (!hdd_ctx || !hdd_ctx->pdev || !chan_list || !chan_num)
Liangwei Dong17bf2662018-01-05 02:02:05 -0500591 return -EINVAL;
592
Dustin Brown07901ec2018-09-07 11:02:41 -0700593 pdev = hdd_ctx->pdev;
Liangwei Dong17bf2662018-01-05 02:02:05 -0500594 cur_chan_list = qdf_mem_malloc(NUM_CHANNELS *
595 sizeof(struct regulatory_channel));
596 if (!cur_chan_list)
597 return -ENOMEM;
598
599 if (wlan_reg_get_current_chan_list(pdev, cur_chan_list) !=
600 QDF_STATUS_SUCCESS) {
601 qdf_mem_free(cur_chan_list);
602 return -EINVAL;
603 }
604
605 for (i = 0; i < NUM_CHANNELS; i++) {
606 uint32_t ch = cur_chan_list[i].chan_num;
607 enum channel_state state = wlan_reg_get_channel_state(pdev,
608 ch);
609
610 if (state != CHANNEL_STATE_DISABLE &&
611 state != CHANNEL_STATE_INVALID &&
612 j < *chan_num) {
613 chan_list[j] = (uint8_t)ch;
614 j++;
615 }
616 }
617 *chan_num = j;
618 qdf_mem_free(cur_chan_list);
619 return 0;
620}
621
622/**
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530623 * hdd_validate_channel_and_bandwidth() - Validate the channel-bandwidth combo
624 * @adapter: HDD adapter
625 * @chan_number: Channel number
626 * @chan_bw: Bandwidth
627 *
628 * Checks if the given bandwidth is valid for the given channel number.
629 *
630 * Return: 0 for success, non-zero for failure
631 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700632int hdd_validate_channel_and_bandwidth(struct hdd_adapter *adapter,
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530633 uint32_t chan_number,
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800634 enum phy_ch_width chan_bw)
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530635{
Liangwei Dong17bf2662018-01-05 02:02:05 -0500636 uint8_t chan[NUM_CHANNELS];
637 uint32_t len = NUM_CHANNELS, i;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530638 bool found = false;
Jeff Johnson16528362018-06-14 12:34:16 -0700639 mac_handle_t mac_handle;
Liangwei Dong17bf2662018-01-05 02:02:05 -0500640 int ret;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530641
Jeff Johnson16528362018-06-14 12:34:16 -0700642 mac_handle = hdd_adapter_get_mac_handle(adapter);
643 if (!mac_handle) {
644 hdd_err("Invalid MAC handle");
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530645 return -EINVAL;
646 }
647
Liangwei Dong17bf2662018-01-05 02:02:05 -0500648 ret = hdd_get_valid_chan(adapter->hdd_ctx, chan,
649 &len);
650 if (ret) {
651 hdd_err("error %d in getting valid channel list", ret);
652 return ret;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530653 }
654
655 for (i = 0; i < len; i++) {
656 if (chan[i] == chan_number) {
657 found = true;
658 break;
659 }
660 }
661
662 if (found == false) {
663 hdd_err("Channel not in driver's valid channel list");
664 return -EOPNOTSUPP;
665 }
666
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700667 if ((!WLAN_REG_IS_24GHZ_CH(chan_number)) &&
668 (!WLAN_REG_IS_5GHZ_CH(chan_number))) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530669 hdd_err("CH %d is not in 2.4GHz or 5GHz", chan_number);
670 return -EINVAL;
671 }
672
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700673 if (WLAN_REG_IS_24GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530674 if (chan_bw == CH_WIDTH_80MHZ) {
675 hdd_err("BW80 not possible in 2.4GHz band");
676 return -EINVAL;
677 }
678 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 14) &&
679 (chan_bw != CH_WIDTH_MAX)) {
680 hdd_err("Only BW20 possible on channel 14");
681 return -EINVAL;
682 }
683 }
684
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700685 if (WLAN_REG_IS_5GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530686 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 165) &&
687 (chan_bw != CH_WIDTH_MAX)) {
688 hdd_err("Only BW20 possible on channel 165");
689 return -EINVAL;
690 }
691 }
692
693 return 0;
694}
695
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800696#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
Dustin Brown98f7c822019-03-06 12:25:49 -0800697static inline struct net_device *hdd_net_dev_from_notifier(void *context)
698{
699 struct netdev_notifier_info *info = context;
700
701 return info->dev;
702}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800703#else
Dustin Brown98f7c822019-03-06 12:25:49 -0800704static inline struct net_device *hdd_net_dev_from_notifier(void *context)
705{
706 return context;
707}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800708#endif
Dustin Brown98f7c822019-03-06 12:25:49 -0800709
710static int __hdd_netdev_notifier_call(struct net_device *net_dev,
711 unsigned long state)
712{
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530713 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700714 struct hdd_context *hdd_ctx;
Min Liu8c5d99e2018-09-10 17:18:44 +0800715 struct wlan_objmgr_vdev *vdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800716
Dustin Brown98f7c822019-03-06 12:25:49 -0800717 hdd_enter_dev(net_dev);
Jeff Johnson3c3994a2016-02-11 08:12:30 -0800718
Dustin Brown98f7c822019-03-06 12:25:49 -0800719 if (!net_dev->ieee80211_ptr) {
Dustin Brownaeb55642018-07-30 17:20:32 -0700720 hdd_debug("ieee80211_ptr is null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800721 return NOTIFY_DONE;
722 }
723
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530724 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
725 if (!hdd_ctx) {
726 hdd_err("HDD Context is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800727 return NOTIFY_DONE;
728 }
Jingxiang Ge9db9d232017-10-14 17:22:15 +0800729
730 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -0700731 hdd_debug("%s: Driver module is closed", __func__);
Jingxiang Ge9db9d232017-10-14 17:22:15 +0800732 return NOTIFY_DONE;
733 }
734
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530735 /* Make sure that this callback corresponds to our device. */
Dustin Brown98f7c822019-03-06 12:25:49 -0800736 adapter = hdd_get_adapter_by_iface_name(hdd_ctx, net_dev->name);
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530737 if (!adapter) {
Dustin Brown98f7c822019-03-06 12:25:49 -0800738 hdd_debug("failed to look up adapter for '%s'", net_dev->name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800739 return NOTIFY_DONE;
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530740 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800741
Dustin Brown98f7c822019-03-06 12:25:49 -0800742 if (adapter != WLAN_HDD_GET_PRIV_PTR(net_dev)) {
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530743 hdd_err("HDD adapter mismatch!");
744 return NOTIFY_DONE;
745 }
746
Dustin Brownaeb55642018-07-30 17:20:32 -0700747 if (cds_is_driver_recovering()) {
748 hdd_debug("Driver is recovering");
749 return NOTIFY_DONE;
750 }
751
752 if (cds_is_driver_in_bad_state()) {
753 hdd_debug("Driver is in failed recovery state");
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530754 return NOTIFY_DONE;
755 }
756
Dustin Brown98f7c822019-03-06 12:25:49 -0800757 hdd_debug("%s New Net Device State = %lu", net_dev->name, state);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800758
759 switch (state) {
760 case NETDEV_REGISTER:
761 break;
762
763 case NETDEV_UNREGISTER:
764 break;
765
766 case NETDEV_UP:
Jeff Johnson16528362018-06-14 12:34:16 -0700767 sme_ch_avoid_update_req(hdd_ctx->mac_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800768 break;
769
770 case NETDEV_DOWN:
771 break;
772
773 case NETDEV_CHANGE:
Jeff Johnsonc72c5732017-10-28 12:49:37 -0700774 if (adapter->is_link_up_service_needed)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800775 complete(&adapter->linkup_event_var);
776 break;
777
778 case NETDEV_GOING_DOWN:
Min Liu8c5d99e2018-09-10 17:18:44 +0800779 vdev = hdd_objmgr_get_vdev(adapter);
780 if (!vdev)
781 break;
782 if (ucfg_scan_get_vdev_status(vdev) !=
Sandeep Puligilla5f86d992017-10-29 14:58:53 -0700783 SCAN_NOT_IN_PROGRESS) {
Dustin Brown07901ec2018-09-07 11:02:41 -0700784 wlan_abort_scan(hdd_ctx->pdev, INVAL_PDEV_ID,
Jeff Johnson5a6fc962019-02-04 14:20:25 -0800785 adapter->vdev_id, INVALID_SCAN_ID,
Dustin Brown07901ec2018-09-07 11:02:41 -0700786 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800787 }
Rajeev Kumar Sirasanagandla25bdfad2019-02-15 19:15:49 +0530788 hdd_objmgr_put_vdev(vdev);
Min Liu9be5d4a2018-05-17 11:51:53 +0800789 cds_flush_work(&adapter->scan_block_work);
790 /* Need to clean up blocked scan request */
Dustin Brown96b98dd2019-03-06 12:39:37 -0800791 wlan_hdd_cfg80211_scan_block(adapter);
Min Liu9be5d4a2018-05-17 11:51:53 +0800792 hdd_debug("Scan is not Pending from user");
Arunk Khandavallif0c0d762017-12-07 10:18:50 +0530793 /*
794 * After NETDEV_GOING_DOWN, kernel calls hdd_stop.Irrespective
795 * of return status of hdd_stop call, kernel resets the IFF_UP
796 * flag after which driver does not send the cfg80211_scan_done.
797 * Ensure to cleanup the scan queue in NETDEV_GOING_DOWN
798 */
Dustin Brown98f7c822019-03-06 12:25:49 -0800799 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->pdev, net_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800800 break;
801
802 default:
803 break;
804 }
805
806 return NOTIFY_DONE;
807}
808
809/**
810 * hdd_netdev_notifier_call() - netdev notifier callback function
811 * @nb: pointer to notifier block
812 * @state: state
Dustin Brown98f7c822019-03-06 12:25:49 -0800813 * @context: notifier callback context pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800814 *
815 * Return: 0 on success, error number otherwise.
816 */
817static int hdd_netdev_notifier_call(struct notifier_block *nb,
818 unsigned long state,
Dustin Brown98f7c822019-03-06 12:25:49 -0800819 void *context)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800820{
Dustin Brown98f7c822019-03-06 12:25:49 -0800821 struct net_device *net_dev = hdd_net_dev_from_notifier(context);
822 struct osif_vdev_sync *vdev_sync;
823 int errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800824
Dustin Brown98f7c822019-03-06 12:25:49 -0800825 errno = osif_vdev_sync_op_start(net_dev, &vdev_sync);
826 if (errno)
827 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800828
Dustin Brown98f7c822019-03-06 12:25:49 -0800829 errno = __hdd_netdev_notifier_call(net_dev, state);
830
831 osif_vdev_sync_op_stop(vdev_sync);
832
833 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800834}
835
836struct notifier_block hdd_netdev_notifier = {
837 .notifier_call = hdd_netdev_notifier_call,
838};
839
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530840static int system_reboot_notifier_call(struct notifier_block *nb,
841 unsigned long msg_type, void *_unused)
842{
843 switch (msg_type) {
844 case SYS_DOWN:
845 case SYS_HALT:
846 case SYS_POWER_OFF:
847 g_is_system_reboot_triggered = true;
848 hdd_info("reboot, reason: %ld", msg_type);
849 break;
850 default:
851 break;
852 }
853
854 return NOTIFY_OK;
855}
856
857struct notifier_block system_reboot_notifier = {
858 .notifier_call = system_reboot_notifier_call,
859};
860
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800861/* 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]: "
1217 MAC_ADDRESS_STR,
1218 MAC_ADDR_ARRAY(hdd_ctx->
1219 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]: "
1226 MAC_ADDRESS_STR,
1227 MAC_ADDR_ARRAY(hdd_ctx->derived_mac_addr[0].bytes));
1228 }
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]: "
1249 MAC_ADDRESS_STR, i,
1250 MAC_ADDR_ARRAY(hdd_ctx->derived_mac_addr[i].bytes));
1251 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;
1285
1286 status = ucfg_tdls_update_config(psoc, &tdls_cfg);
1287 if (status != QDF_STATUS_SUCCESS) {
1288 hdd_err("failed pmo psoc configuration");
1289 return -EINVAL;
1290 }
1291
1292 hdd_ctx->tdls_umac_comp_active = true;
1293 /* enable napier specific tdls data path */
1294 hdd_ctx->tdls_nap_active = true;
1295
1296 return 0;
1297}
Jeff Johnson74c6bb22019-02-15 10:15:07 -08001298#else
1299static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
1300{
1301 return 0;
1302}
1303#endif
Kabilan Kannan44a58372017-12-06 18:16:11 -08001304
Wu Gaoca416ff2018-09-17 11:05:07 +08001305#ifdef WLAN_FEATURE_ROAM_OFFLOAD
1306static void hdd_update_roam_offload(struct hdd_context *hdd_ctx,
1307 struct wma_tgt_services *cfg)
1308{
1309 bool roam_offload_enable;
1310
Dustin Brown1dbefe62018-09-11 16:32:03 -07001311 ucfg_mlme_get_roaming_offload(hdd_ctx->psoc, &roam_offload_enable);
1312 ucfg_mlme_set_roaming_offload(hdd_ctx->psoc,
Wu Gaoca416ff2018-09-17 11:05:07 +08001313 roam_offload_enable &
1314 cfg->en_roam_offload);
1315}
1316#else
1317static inline void hdd_update_roam_offload(struct hdd_context *hdd_ctx,
1318 struct wma_tgt_services *cfg)
1319{
1320}
1321#endif
1322
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001323static void hdd_update_tgt_services(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001324 struct wma_tgt_services *cfg)
1325{
1326 struct hdd_config *config = hdd_ctx->config;
Wu Gao66454f12018-09-26 19:55:41 +08001327 bool arp_offload_enable;
Wu Gao1ab05582018-11-08 16:22:49 +08001328 bool mawc_enabled;
Wu Gaobdb7f272018-07-05 19:33:26 +08001329#ifdef FEATURE_WLAN_TDLS
1330 bool tdls_support;
1331 bool tdls_off_channel;
1332 bool tdls_buffer_sta;
1333 uint32_t tdls_uapsd_mask;
1334#endif
jiad7b8a5e02018-11-26 16:37:57 +08001335 bool value;
1336
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001337 /* Set up UAPSD */
Pragaspathi Thilagaraj4b5c0602018-11-14 22:35:23 +05301338 ucfg_mlme_set_sap_uapsd_flag(hdd_ctx->psoc, cfg->uapsd);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001339
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08001340 /* 11AX mode support */
1341 if ((config->dot11Mode == eHDD_DOT11_MODE_11ax ||
1342 config->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY) && !cfg->en_11ax)
1343 config->dot11Mode = eHDD_DOT11_MODE_11ac;
1344
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001345 /* 11AC mode support */
1346 if ((config->dot11Mode == eHDD_DOT11_MODE_11ac ||
1347 config->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY) && !cfg->en_11ac)
1348 config->dot11Mode = eHDD_DOT11_MODE_AUTO;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001349
1350 /* ARP offload: override user setting if invalid */
Wu Gao66454f12018-09-26 19:55:41 +08001351 arp_offload_enable =
1352 ucfg_pmo_is_arp_offload_enabled(hdd_ctx->psoc);
1353 ucfg_pmo_set_arp_offload_enabled(hdd_ctx->psoc,
1354 arp_offload_enable & cfg->arp_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001355#ifdef FEATURE_WLAN_SCAN_PNO
1356 /* PNO offload */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001357 hdd_debug("PNO Capability in f/w = %d", cfg->pno_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001358 if (cfg->pno_offload)
Pragaspathi Thilagaraj24789d32018-12-10 22:28:03 +05301359 ucfg_scan_set_pno_offload(hdd_ctx->psoc, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001360#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001361#ifdef FEATURE_WLAN_TDLS
Dustin Brown1dbefe62018-09-11 16:32:03 -07001362 cfg_tdls_get_support_enable(hdd_ctx->psoc, &tdls_support);
1363 cfg_tdls_set_support_enable(hdd_ctx->psoc,
Wu Gaobdb7f272018-07-05 19:33:26 +08001364 tdls_support & cfg->en_tdls);
1365
Dustin Brown1dbefe62018-09-11 16:32:03 -07001366 cfg_tdls_get_off_channel_enable(hdd_ctx->psoc, &tdls_off_channel);
1367 cfg_tdls_set_off_channel_enable(hdd_ctx->psoc,
Wu Gaobdb7f272018-07-05 19:33:26 +08001368 tdls_off_channel &&
1369 cfg->en_tdls_offchan);
1370
Dustin Brown1dbefe62018-09-11 16:32:03 -07001371 cfg_tdls_get_buffer_sta_enable(hdd_ctx->psoc, &tdls_buffer_sta);
1372 cfg_tdls_set_buffer_sta_enable(hdd_ctx->psoc,
Wu Gaobdb7f272018-07-05 19:33:26 +08001373 tdls_buffer_sta &&
1374 cfg->en_tdls_uapsd_buf_sta);
1375
Dustin Brown1dbefe62018-09-11 16:32:03 -07001376 cfg_tdls_get_uapsd_mask(hdd_ctx->psoc, &tdls_uapsd_mask);
Wu Gaobdb7f272018-07-05 19:33:26 +08001377 if (tdls_uapsd_mask && cfg->en_tdls_uapsd_sleep_sta)
Dustin Brown1dbefe62018-09-11 16:32:03 -07001378 cfg_tdls_set_sleep_sta_enable(hdd_ctx->psoc, true);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001379 else
Dustin Brown1dbefe62018-09-11 16:32:03 -07001380 cfg_tdls_set_sleep_sta_enable(hdd_ctx->psoc, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001381#endif
Wu Gaoca416ff2018-09-17 11:05:07 +08001382 hdd_update_roam_offload(hdd_ctx, cfg);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05301383
Dustin Brown05d81302018-09-11 16:49:22 -07001384 if (ucfg_mlme_get_sap_get_peer_info(hdd_ctx->psoc, &value) ==
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05301385 QDF_STATUS_SUCCESS)
1386 value &= cfg->get_peer_info_enabled;
1387
Wu Gao1ab05582018-11-08 16:22:49 +08001388 ucfg_mlme_is_mawc_enabled(hdd_ctx->psoc, &mawc_enabled);
1389 ucfg_mlme_set_mawc_enabled(hdd_ctx->psoc,
1390 mawc_enabled & cfg->is_fw_mawc_capable);
Kabilan Kannan44a58372017-12-06 18:16:11 -08001391 hdd_update_tdls_config(hdd_ctx);
Jeff Johnson16528362018-06-14 12:34:16 -07001392 sme_update_tgt_services(hdd_ctx->mac_handle, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001393}
1394
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001395/**
1396 * hdd_update_vdev_nss() - sets the vdev nss
1397 * @hdd_ctx: HDD context
1398 *
1399 * Sets the Nss per vdev type based on INI
1400 *
1401 * Return: None
1402 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001403static void hdd_update_vdev_nss(struct hdd_context *hdd_ctx)
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001404{
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001405 uint8_t max_supp_nss = 1;
Jeff Johnson16528362018-06-14 12:34:16 -07001406 mac_handle_t mac_handle;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301407 QDF_STATUS status;
1408 bool bval;
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001409
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301410 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &bval);
1411 if (!QDF_IS_STATUS_SUCCESS(status))
1412 hdd_err("unable to get vht_enable2x2");
1413
1414 if (bval && !cds_is_sub_20_mhz_enabled())
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001415 max_supp_nss = 2;
gaurank kathpalia651abcd2018-11-12 22:41:23 +05301416
1417 hdd_debug("max nss %d", max_supp_nss);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001418
Jeff Johnson16528362018-06-14 12:34:16 -07001419 mac_handle = hdd_ctx->mac_handle;
1420 sme_update_vdev_type_nss(mac_handle, max_supp_nss,
gaurank kathpalia651abcd2018-11-12 22:41:23 +05301421 NSS_CHAINS_BAND_2GHZ);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001422
Jeff Johnson16528362018-06-14 12:34:16 -07001423 sme_update_vdev_type_nss(mac_handle, max_supp_nss,
gaurank kathpalia651abcd2018-11-12 22:41:23 +05301424 NSS_CHAINS_BAND_5GHZ);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001425}
1426
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301427/**
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301428 * hdd_update_wiphy_vhtcap() - Updates wiphy vhtcap fields
1429 * @hdd_ctx: HDD context
1430 *
1431 * Updates wiphy vhtcap fields
1432 *
1433 * Return: None
1434 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001435static void hdd_update_wiphy_vhtcap(struct hdd_context *hdd_ctx)
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301436{
1437 struct ieee80211_supported_band *band_5g =
1438 hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ];
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301439 QDF_STATUS status;
1440 uint8_t value = 0, value1 = 0;
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301441
1442 if (!band_5g) {
1443 hdd_debug("5GHz band disabled, skipping capability population");
1444 return;
1445 }
1446
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301447 status = ucfg_mlme_cfg_get_vht_tx_bfee_ant_supp(hdd_ctx->psoc,
1448 &value);
1449 if (!QDF_IS_STATUS_SUCCESS(status))
1450 hdd_err("unable to get tx_bfee_ant_supp");
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301451
Abhinav Kumare057b412018-10-09 17:28:16 +05301452 band_5g->vht_cap.cap |=
1453 (value << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301454
1455 value1 = NUM_OF_SOUNDING_DIMENSIONS;
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301456 band_5g->vht_cap.cap |=
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301457 (value1 << IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301458
Dustin Brown7e761c72018-07-31 13:50:17 -07001459 hdd_debug("Updated wiphy vhtcap:0x%x, CSNAntSupp:%d, NumSoundDim:%d",
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301460 band_5g->vht_cap.cap, value, value1);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301461}
1462
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001463static void hdd_update_tgt_ht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001464 struct wma_tgt_ht_cap *cfg)
1465{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301466 QDF_STATUS status;
Karthik Kantamnenie3bbd7f2018-09-19 20:27:32 +05301467 qdf_size_t value_len;
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05301468 uint32_t value;
Vignesh Viswanathanddc89e52018-11-02 18:43:42 +05301469 uint8_t mpdu_density;
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05301470 struct mlme_ht_capabilities_info ht_cap_info;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001471 uint8_t mcs_set[SIZE_OF_SUPPORTED_MCS_SET];
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301472 bool b_enable1x1;
Jeff Johnson16528362018-06-14 12:34:16 -07001473
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001474 /* get the MPDU density */
Vignesh Viswanathanddc89e52018-11-02 18:43:42 +05301475 status = ucfg_mlme_get_ht_mpdu_density(hdd_ctx->psoc, &mpdu_density);
1476 if (QDF_IS_STATUS_ERROR(status)) {
1477 hdd_err("could not get HT MPDU Density");
1478 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001479 }
1480
1481 /*
1482 * MPDU density:
1483 * override user's setting if value is larger
1484 * than the one supported by target
1485 */
Vignesh Viswanathanddc89e52018-11-02 18:43:42 +05301486 if (mpdu_density > cfg->mpdu_density) {
1487 status = ucfg_mlme_set_ht_mpdu_density(hdd_ctx->psoc,
1488 cfg->mpdu_density);
1489 if (QDF_IS_STATUS_ERROR(status))
1490 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001491 }
1492
1493 /* get the HT capability info */
Dustin Brown1dbefe62018-09-11 16:32:03 -07001494 status = ucfg_mlme_get_ht_cap_info(hdd_ctx->psoc, &ht_cap_info);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301495 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001496 hdd_err("could not get HT capability info");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001497 return;
1498 }
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05301499
1500 /* check and update RX STBC */
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301501 if (ht_cap_info.rx_stbc && !cfg->ht_rx_stbc)
1502 ht_cap_info.rx_stbc = cfg->ht_rx_stbc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001503
1504 /* Set the LDPC capability */
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301505 ht_cap_info.adv_coding_cap = cfg->ht_rx_ldpc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001506
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301507 if (ht_cap_info.short_gi_20_mhz && !cfg->ht_sgi_20)
1508 ht_cap_info.short_gi_20_mhz = cfg->ht_sgi_20;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001509
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301510 if (ht_cap_info.short_gi_40_mhz && !cfg->ht_sgi_40)
1511 ht_cap_info.short_gi_40_mhz = cfg->ht_sgi_40;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001512
1513 hdd_ctx->num_rf_chains = cfg->num_rf_chains;
1514 hdd_ctx->ht_tx_stbc_supported = cfg->ht_tx_stbc;
1515
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301516 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &b_enable1x1);
1517 if (!QDF_IS_STATUS_SUCCESS(status))
1518 hdd_err("unable to get vht_enable2x2");
1519
1520 b_enable1x1 = b_enable1x1 && (cfg->num_rf_chains == 2);
1521
1522 status = ucfg_mlme_set_vht_enable2x2(hdd_ctx->psoc, b_enable1x1);
1523 if (!QDF_IS_STATUS_SUCCESS(status))
1524 hdd_err("unable to set vht_enable2x2");
1525
Abhinav Kumare057b412018-10-09 17:28:16 +05301526 if (!b_enable1x1) {
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301527 ht_cap_info.tx_stbc = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001528
1529 /* 1x1 */
1530 /* Update Rx Highest Long GI data Rate */
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301531 status = ucfg_mlme_cfg_set_vht_rx_supp_data_rate(
1532 hdd_ctx->psoc,
1533 VHT_RX_HIGHEST_SUPPORTED_DATA_RATE_1_1);
1534 if (!QDF_IS_STATUS_SUCCESS(status))
1535 hdd_err("Failed to set rx_supp_data_rate");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001536 /* Update Tx Highest Long GI data Rate */
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301537 status = ucfg_mlme_cfg_set_vht_tx_supp_data_rate(
1538 hdd_ctx->psoc,
1539 VHT_TX_HIGHEST_SUPPORTED_DATA_RATE_1_1);
1540 if (!QDF_IS_STATUS_SUCCESS(status))
1541 hdd_err("Failed to set tx_supp_data_rate");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001542 }
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301543 if (!(cfg->ht_tx_stbc && b_enable1x1))
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301544 ht_cap_info.tx_stbc = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001545
Dustin Brown1dbefe62018-09-11 16:32:03 -07001546 status = ucfg_mlme_set_ht_cap_info(hdd_ctx->psoc, ht_cap_info);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301547 if (status != QDF_STATUS_SUCCESS)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001548 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001549#define WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES 0xff
Karthik Kantamnenie3bbd7f2018-09-19 20:27:32 +05301550 value_len = SIZE_OF_SUPPORTED_MCS_SET;
1551 if (ucfg_mlme_get_supported_mcs_set(
1552 hdd_ctx->psoc, mcs_set,
1553 &value_len) == QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001554 hdd_debug("Read MCS rate set");
gaurank kathpalia18b49362018-04-15 23:12:03 +05301555 if (cfg->num_rf_chains > SIZE_OF_SUPPORTED_MCS_SET)
1556 cfg->num_rf_chains = SIZE_OF_SUPPORTED_MCS_SET;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301557
1558 if (b_enable1x1) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001559 for (value = 0; value < cfg->num_rf_chains; value++)
1560 mcs_set[value] =
1561 WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES;
1562
Karthik Kantamnenie3bbd7f2018-09-19 20:27:32 +05301563 status = ucfg_mlme_set_supported_mcs_set(
1564 hdd_ctx->psoc,
1565 mcs_set,
1566 (qdf_size_t)SIZE_OF_SUPPORTED_MCS_SET);
1567 if (QDF_IS_STATUS_ERROR(status))
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001568 hdd_err("could not set MCS SET to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001569 }
1570 }
1571#undef WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES
1572}
1573
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001574static void hdd_update_tgt_vht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001575 struct wma_tgt_vht_cap *cfg)
1576{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301577 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001578 struct wiphy *wiphy = hdd_ctx->wiphy;
1579 struct ieee80211_supported_band *band_5g =
Srinivas Girigowda11c28e02017-06-27 20:06:21 -07001580 wiphy->bands[HDD_NL80211_BAND_5GHZ];
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001581 uint32_t ch_width = eHT_CHANNEL_WIDTH_80MHZ;
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001582 struct wma_caps_per_phy caps_per_phy;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301583 uint8_t val = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001584
Dustin Brown5e06bd32016-10-04 12:49:10 -07001585 if (!band_5g) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001586 hdd_debug("5GHz band disabled, skipping capability population");
Dustin Brown5e06bd32016-10-04 12:49:10 -07001587 return;
1588 }
1589
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301590 status = ucfg_mlme_update_vht_cap(hdd_ctx->psoc, cfg);
1591 if (QDF_IS_STATUS_ERROR(status))
1592 hdd_err("could not update vht capabilities");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001593
1594 if (WMI_VHT_CAP_MAX_MPDU_LEN_11454 == cfg->vht_max_mpdu)
1595 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1596 else if (WMI_VHT_CAP_MAX_MPDU_LEN_7935 == cfg->vht_max_mpdu)
1597 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1598 else
1599 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1600
1601
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001602 if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_80P80MHZ)) {
Abhinav Kumare057b412018-10-09 17:28:16 +05301603 status = ucfg_mlme_set_vht_ch_width(hdd_ctx->psoc,
1604 VHT_CAP_160_AND_80P80_SUPP);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301605 if (QDF_IS_STATUS_ERROR(status))
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001606 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001607 band_5g->vht_cap.cap |=
1608 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001609 ch_width = eHT_CHANNEL_WIDTH_80P80MHZ;
1610 } else if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_160MHZ)) {
Abhinav Kumare057b412018-10-09 17:28:16 +05301611 status = ucfg_mlme_set_vht_ch_width(hdd_ctx->psoc,
1612 VHT_CAP_160_SUPP);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301613 if (QDF_IS_STATUS_ERROR(status))
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001614 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001615 band_5g->vht_cap.cap |=
1616 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001617 ch_width = eHT_CHANNEL_WIDTH_160MHZ;
1618 }
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001619
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301620 status =
1621 ucfg_mlme_cfg_get_vht_chan_width(hdd_ctx->psoc, &val);
1622 if (QDF_IS_STATUS_ERROR(status))
1623 hdd_err("could not get channel_width");
1624
1625 val = QDF_MIN(val, ch_width);
Abhinav Kumare057b412018-10-09 17:28:16 +05301626 status = ucfg_mlme_set_vht_ch_width(hdd_ctx->psoc, val);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301627 if (QDF_IS_STATUS_ERROR(status))
1628 hdd_err("could not set the channel width");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001629
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001630 if (cfg->vht_rx_ldpc & WMI_VHT_CAP_RX_LDPC) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001631 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001632 hdd_debug("VHT RxLDPC capability is set");
1633 } else {
1634 /*
1635 * Get the RX LDPC capability for the NON DBS
1636 * hardware mode for 5G band
1637 */
1638 status = wma_get_caps_for_phyidx_hwmode(&caps_per_phy,
1639 HW_MODE_DBS_NONE, CDS_BAND_5GHZ);
1640 if ((QDF_IS_STATUS_SUCCESS(status)) &&
1641 (caps_per_phy.vht_5g & WMI_VHT_CAP_RX_LDPC)) {
1642 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
1643 hdd_debug("VHT RX LDPC capability is set");
1644 }
1645 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001646
1647 if (cfg->vht_short_gi_80 & WMI_VHT_CAP_SGI_80MHZ)
1648 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1649 if (cfg->vht_short_gi_160 & WMI_VHT_CAP_SGI_160MHZ)
1650 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1651
1652 if (cfg->vht_tx_stbc & WMI_VHT_CAP_TX_STBC)
1653 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
1654
1655 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_1SS)
1656 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1657 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_2SS)
1658 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_2;
1659 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_3SS)
1660 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_3;
1661
1662 band_5g->vht_cap.cap |=
1663 (cfg->vht_max_ampdu_len_exp <<
1664 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1665
1666 if (cfg->vht_su_bformer & WMI_VHT_CAP_SU_BFORMER)
1667 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1668 if (cfg->vht_su_bformee & WMI_VHT_CAP_SU_BFORMEE)
1669 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1670 if (cfg->vht_mu_bformer & WMI_VHT_CAP_MU_BFORMER)
1671 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1672 if (cfg->vht_mu_bformee & WMI_VHT_CAP_MU_BFORMEE)
1673 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1674
1675 if (cfg->vht_txop_ps & WMI_VHT_CAP_TXOP_PS)
1676 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1677
1678}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001679
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001680/**
1681 * hdd_generate_macaddr_auto() - Auto-generate mac address
1682 * @hdd_ctx: Pointer to the HDD context
1683 *
1684 * Auto-generate mac address using device serial number.
1685 * Keep the first 3 bytes of OUI as before and replace
1686 * the last 3 bytes with the lower 3 bytes of serial number.
1687 *
1688 * Return: 0 for success
1689 * Non zero failure code for errors
1690 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001691static int hdd_generate_macaddr_auto(struct hdd_context *hdd_ctx)
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001692{
1693 unsigned int serialno = 0;
1694 struct qdf_mac_addr mac_addr = {
1695 {0x00, 0x0A, 0xF5, 0x00, 0x00, 0x00}
1696 };
1697
Yuanyuan Liuf97e8222016-09-21 10:31:38 -07001698 serialno = pld_socinfo_get_serial_number(hdd_ctx->parent_dev);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001699 if (serialno == 0)
1700 return -EINVAL;
1701
1702 serialno &= 0x00ffffff;
1703
1704 mac_addr.bytes[3] = (serialno >> 16) & 0xff;
1705 mac_addr.bytes[4] = (serialno >> 8) & 0xff;
1706 mac_addr.bytes[5] = serialno & 0xff;
1707
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05301708 hdd_update_macaddr(hdd_ctx, mac_addr, true);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001709 return 0;
1710}
1711
Jeff Johnsonf9176382018-07-17 19:15:58 -07001712static void hdd_sar_target_config(struct hdd_context *hdd_ctx,
1713 struct wma_tgt_cfg *cfg)
1714{
1715 hdd_ctx->sar_version = cfg->sar_version;
1716}
1717
Jianmin Zhuc8bfffb2019-01-15 12:40:03 +08001718static void hdd_update_vhtcap_2g(struct hdd_context *hdd_ctx)
1719{
Jianmin Zhu2f9e7532019-01-21 15:39:50 +08001720 uint32_t chip_mode = 0;
Jianmin Zhuc8bfffb2019-01-15 12:40:03 +08001721 QDF_STATUS status;
Jianmin Zhu2f9e7532019-01-21 15:39:50 +08001722 bool b2g_vht_cfg = false;
1723 bool b2g_vht_target = false;
1724 struct wma_caps_per_phy caps_per_phy;
1725 struct wmi_unified *wmi_handle;
Jianmin Zhuc8bfffb2019-01-15 12:40:03 +08001726
Jianmin Zhu2f9e7532019-01-21 15:39:50 +08001727 wmi_handle = get_wmi_unified_hdl_from_psoc(hdd_ctx->psoc);
1728 if (!wmi_handle) {
1729 hdd_err("wmi handle is NULL");
Jianmin Zhuc8bfffb2019-01-15 12:40:03 +08001730 return;
1731 }
Jianmin Zhu2f9e7532019-01-21 15:39:50 +08001732
1733 status = ucfg_mlme_get_vht_for_24ghz(hdd_ctx->psoc, &b2g_vht_cfg);
Jianmin Zhuc8bfffb2019-01-15 12:40:03 +08001734 if (QDF_IS_STATUS_ERROR(status)) {
1735 hdd_err("Failed to get 2g vht mode");
1736 return;
1737 }
Jianmin Zhu2f9e7532019-01-21 15:39:50 +08001738 if (wmi_service_enabled(wmi_handle, wmi_service_ext_msg)) {
1739 status = wma_get_caps_for_phyidx_hwmode(&caps_per_phy,
1740 HW_MODE_DBS_NONE,
1741 CDS_BAND_ALL);
1742 if (QDF_IS_STATUS_ERROR(status)) {
1743 hdd_err("Failed to get phy caps");
1744 return;
1745 }
1746 if (caps_per_phy.vht_2g)
1747 b2g_vht_target = true;
1748 } else {
1749 status = wlan_reg_get_chip_mode(hdd_ctx->pdev, &chip_mode);
1750 if (QDF_IS_STATUS_ERROR(status)) {
1751 hdd_err("Failed to get chip mode");
1752 return;
1753 }
1754 b2g_vht_target =
1755 (chip_mode & WMI_HOST_REGDMN_MODE_11AC_VHT20_2G) ?
1756 true : false;
1757 }
Jianmin Zhuc8bfffb2019-01-15 12:40:03 +08001758
Jianmin Zhu2f9e7532019-01-21 15:39:50 +08001759 b2g_vht_cfg = b2g_vht_cfg && b2g_vht_target;
1760 hdd_debug("vht 2g target: %d, cfg: %d", b2g_vht_target, b2g_vht_cfg);
1761 status = ucfg_mlme_set_vht_for_24ghz(hdd_ctx->psoc, b2g_vht_cfg);
Jianmin Zhuc8bfffb2019-01-15 12:40:03 +08001762 if (QDF_IS_STATUS_ERROR(status)) {
1763 hdd_err("Failed to update 2g vht mode");
1764 return;
1765 }
Jianmin Zhuc8bfffb2019-01-15 12:40:03 +08001766}
1767
Jeff Johnson8abc5932018-06-02 22:51:37 -07001768void hdd_update_tgt_cfg(hdd_handle_t hdd_handle, struct wma_tgt_cfg *cfg)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001769{
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001770 int ret;
Jeff Johnsonea70b942018-07-02 09:42:31 -07001771 struct hdd_context *hdd_ctx = hdd_handle_to_context(hdd_handle);
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301772 uint8_t temp_band_cap, band_capability;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001773 struct cds_config_info *cds_cfg = cds_get_ini_config();
Nitesh Shahe50711f2017-04-26 16:30:45 +05301774 uint8_t antenna_mode;
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05301775 uint8_t sub_20_chan_width;
Arif Hussainee10f902017-12-27 16:30:17 -08001776 QDF_STATUS status;
Jeff Johnson16528362018-06-14 12:34:16 -07001777 mac_handle_t mac_handle;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301778 bool bval = false;
1779 uint8_t value = 0;
Arif Hussainbd5194c2018-11-27 19:01:15 -08001780 uint32_t fine_time_meas_cap = 0;
gaurank kathpaliafa7ad0a2019-03-12 19:17:56 +05301781 enum nss_chains_band_info band;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301782
gaurank kathpalia843f7c32018-07-02 18:04:14 +05301783 if (!hdd_ctx) {
1784 hdd_err("HDD context is NULL");
1785 return;
1786 }
Dustin Brownbd68fe12017-11-21 15:28:52 -08001787 ret = hdd_objmgr_create_and_store_pdev(hdd_ctx);
1788 if (ret) {
Dustin Brown64204d22018-08-15 16:35:19 -07001789 QDF_DEBUG_PANIC("Failed to create pdev; errno:%d", ret);
1790 return;
1791 }
1792
1793 hdd_debug("New pdev has been created with pdev_id = %u",
Dustin Brown07901ec2018-09-07 11:02:41 -07001794 hdd_ctx->pdev->pdev_objmgr.wlan_pdev_id);
Dustin Brown64204d22018-08-15 16:35:19 -07001795
Dustin Brown07901ec2018-09-07 11:02:41 -07001796 status = dispatcher_pdev_open(hdd_ctx->pdev);
Dustin Brown64204d22018-08-15 16:35:19 -07001797 if (QDF_IS_STATUS_ERROR(status)) {
1798 QDF_DEBUG_PANIC("dispatcher pdev open failed; status:%d",
1799 status);
1800 return;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301801 }
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001802
Sandeep Puligillab7beb472018-08-13 22:54:20 -07001803 status = hdd_component_pdev_open(hdd_ctx->pdev);
1804 if (QDF_IS_STATUS_ERROR(status)) {
1805 QDF_DEBUG_PANIC("hdd component pdev open failed; status:%d",
1806 status);
1807 return;
1808 }
Sravan Kumar Kairamcb5fd012018-07-04 17:43:22 +05301809 cdp_pdev_set_ctrl_pdev(cds_get_context(QDF_MODULE_ID_SOC),
1810 cds_get_context(QDF_MODULE_ID_TXRX),
Dustin Brown07901ec2018-09-07 11:02:41 -07001811 (struct cdp_ctrl_objmgr_pdev *)hdd_ctx->pdev);
Sravan Kumar Kairamcb5fd012018-07-04 17:43:22 +05301812
Dustin Brown07901ec2018-09-07 11:02:41 -07001813 wlan_pdev_set_dp_handle(hdd_ctx->pdev,
Sravan Kumar Kairamcb5fd012018-07-04 17:43:22 +05301814 cds_get_context(QDF_MODULE_ID_TXRX));
1815
Will Huang07244172018-05-14 14:23:30 +08001816 hdd_objmgr_update_tgt_max_vdev_psoc(hdd_ctx, cfg->max_intf_count);
1817
Dustin Brown1dbefe62018-09-11 16:32:03 -07001818 ucfg_ipa_set_dp_handle(hdd_ctx->psoc,
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301819 cds_get_context(QDF_MODULE_ID_SOC));
Dustin Brown1dbefe62018-09-11 16:32:03 -07001820 ucfg_ipa_set_txrx_handle(hdd_ctx->psoc,
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301821 cds_get_context(QDF_MODULE_ID_TXRX));
Dustin Brown07901ec2018-09-07 11:02:41 -07001822 ucfg_ipa_reg_sap_xmit_cb(hdd_ctx->pdev,
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05301823 hdd_softap_hard_start_xmit);
Dustin Brown07901ec2018-09-07 11:02:41 -07001824 ucfg_ipa_reg_send_to_nw_cb(hdd_ctx->pdev,
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05301825 hdd_ipa_send_skb_to_network);
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301826
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05301827 status = ucfg_mlme_get_sub_20_chan_width(hdd_ctx->psoc,
1828 &sub_20_chan_width);
1829 if (QDF_IS_STATUS_ERROR(status)) {
1830 hdd_err("Failed to get sub_20_chan_width config");
1831 return;
1832 }
1833
Naveen Rawat64e477e2016-05-20 10:34:56 -07001834 if (cds_cfg) {
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05301835 if (sub_20_chan_width !=
1836 WLAN_SUB_20_CH_WIDTH_NONE && !cfg->sub_20_support) {
Naveen Rawat64e477e2016-05-20 10:34:56 -07001837 hdd_err("User requested sub 20 MHz channel width but unsupported by FW.");
1838 cds_cfg->sub_20_channel_width =
1839 WLAN_SUB_20_CH_WIDTH_NONE;
1840 } else {
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05301841 cds_cfg->sub_20_channel_width = sub_20_chan_width;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001842 }
1843 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001844
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301845 status = ucfg_mlme_get_band_capability(hdd_ctx->psoc, &band_capability);
1846 if (QDF_IS_STATUS_ERROR(status)) {
1847 hdd_err("Failed to get MLME band capability");
1848 return;
1849 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001850
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301851 /* first store the INI band capability */
1852 temp_band_cap = band_capability;
1853
1854 band_capability = cfg->band_cap;
Vignesh Viswanathan731186f2017-09-18 13:47:37 +05301855 hdd_ctx->is_fils_roaming_supported =
1856 cfg->services.is_fils_roaming_supported;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001857
Vignesh Viswanathan694e28e2018-01-18 20:53:57 +05301858 hdd_ctx->config->is_11k_offload_supported =
1859 cfg->services.is_11k_offload_supported;
1860
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08001861 /*
1862 * now overwrite the target band capability with INI
1863 * setting if INI setting is a subset
1864 */
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301865 if ((band_capability == BAND_ALL) &&
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001866 (temp_band_cap != BAND_ALL))
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301867 band_capability = temp_band_cap;
1868 else if ((band_capability != BAND_ALL) &&
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001869 (temp_band_cap != BAND_ALL) &&
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301870 (band_capability != temp_band_cap)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001871 hdd_warn("ini BandCapability not supported by the target");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001872 }
1873
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301874 status = ucfg_mlme_set_band_capability(hdd_ctx->psoc, band_capability);
1875 if (QDF_IS_STATUS_ERROR(status)) {
1876 hdd_err("Failed to set MLME Band Capability");
1877 return;
1878 }
1879
1880 hdd_ctx->curr_band = band_capability;
Amar Singhal58b45ef2017-08-01 13:43:54 -07001881
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301882 if (!cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001883 hdd_ctx->reg.reg_domain = cfg->reg_domain;
1884 hdd_ctx->reg.eeprom_rd_ext = cfg->eeprom_rd_ext;
1885 }
1886
1887 /* This can be extended to other configurations like ht, vht cap... */
1888
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05301889 if (!qdf_is_macaddr_zero(&cfg->hw_macaddr))
1890 qdf_mem_copy(&hdd_ctx->hw_macaddr, &cfg->hw_macaddr,
1891 QDF_MAC_ADDR_SIZE);
1892 else
1893 hdd_info("hw_mac is zero");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001894
1895 hdd_ctx->target_fw_version = cfg->target_fw_version;
Sandeep Puligilla3d6a8e22016-10-11 18:57:14 -07001896 hdd_ctx->target_fw_vers_ext = cfg->target_fw_vers_ext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001897
Ryan Hsuc6918552018-05-16 13:29:59 -07001898 hdd_ctx->hw_bd_id = cfg->hw_bd_id;
1899 qdf_mem_copy(&hdd_ctx->hw_bd_info, &cfg->hw_bd_info,
1900 sizeof(cfg->hw_bd_info));
1901
Dustin Brownad06be62019-02-04 14:52:56 -08001902 if (cfg->max_intf_count > WLAN_MAX_VDEVS) {
Dustin Brownbee82832018-07-23 10:10:51 -07001903 hdd_err("fw max vdevs (%u) > host max vdevs (%u); using %u",
Dustin Brownad06be62019-02-04 14:52:56 -08001904 cfg->max_intf_count, WLAN_MAX_VDEVS, WLAN_MAX_VDEVS);
1905 hdd_ctx->max_intf_count = WLAN_MAX_VDEVS;
Dustin Brownbee82832018-07-23 10:10:51 -07001906 } else {
1907 hdd_ctx->max_intf_count = cfg->max_intf_count;
1908 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001909
Jeff Johnsonf9176382018-07-17 19:15:58 -07001910 hdd_sar_target_config(hdd_ctx, cfg);
Jeff Johnsonc875e242016-09-23 18:12:34 -07001911 hdd_lpass_target_config(hdd_ctx, cfg);
Ryan Hsu3c8f79f2015-12-02 16:45:09 -08001912
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001913 hdd_ctx->ap_arpns_support = cfg->ap_arpns_support;
1914 hdd_update_tgt_services(hdd_ctx, &cfg->services);
1915
1916 hdd_update_tgt_ht_cap(hdd_ctx, &cfg->ht_cap);
1917
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001918 hdd_update_tgt_vht_cap(hdd_ctx, &cfg->vht_cap);
Krishna Kumaar Natarajaned1efd92016-09-24 18:05:47 -07001919 if (cfg->services.en_11ax) {
1920 hdd_info("11AX: 11ax is enabled - update HDD config");
1921 hdd_update_tgt_he_cap(hdd_ctx, cfg);
1922 }
Varun Reddy Yeturue93d2462018-05-22 13:54:52 -07001923 hdd_update_tgt_twt_cap(hdd_ctx, cfg);
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07001924
gaurank kathpaliafa7ad0a2019-03-12 19:17:56 +05301925 for (band = NSS_CHAINS_BAND_2GHZ; band < NSS_CHAINS_BAND_MAX; band++) {
1926 sme_modify_nss_chains_tgt_cfg(hdd_ctx->mac_handle,
1927 QDF_STA_MODE, band);
1928 sme_modify_nss_chains_tgt_cfg(hdd_ctx->mac_handle,
1929 QDF_SAP_MODE, band);
1930 sme_modify_nss_chains_tgt_cfg(hdd_ctx->mac_handle,
1931 QDF_TDLS_MODE, band);
1932 sme_modify_nss_chains_tgt_cfg(hdd_ctx->mac_handle,
1933 QDF_P2P_DEVICE_MODE,
1934 band);
1935 sme_modify_nss_chains_tgt_cfg(hdd_ctx->mac_handle,
1936 QDF_OCB_MODE, band);
1937 sme_modify_nss_chains_tgt_cfg(hdd_ctx->mac_handle,
1938 QDF_TDLS_MODE, band);
1939 }
1940
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07001941 hdd_update_vdev_nss(hdd_ctx);
1942
gaurank kathpalia5fcefa92018-10-24 15:03:15 +05301943 hdd_ctx->dynamic_nss_chains_support =
1944 cfg->dynamic_nss_chains_support;
Arif Hussainbd5194c2018-11-27 19:01:15 -08001945 ucfg_mlme_get_fine_time_meas_cap(hdd_ctx->psoc, &fine_time_meas_cap);
1946 fine_time_meas_cap &= cfg->fine_time_measurement_cap;
1947 status = ucfg_mlme_set_fine_time_meas_cap(hdd_ctx->psoc,
1948 fine_time_meas_cap);
1949 if (QDF_IS_STATUS_ERROR(status)) {
1950 hdd_err("failed to set fine_time_meas_cap, 0x%x, ox%x",
1951 fine_time_meas_cap, cfg->fine_time_measurement_cap);
1952 ucfg_mlme_get_fine_time_meas_cap(hdd_ctx->psoc,
1953 &fine_time_meas_cap);
1954 }
1955
Krunal Sonie3531942016-04-12 17:43:53 -07001956 hdd_ctx->fine_time_meas_cap_target = cfg->fine_time_measurement_cap;
Arif Hussainbd5194c2018-11-27 19:01:15 -08001957 hdd_debug("fine_time_meas_cap: 0x%x", fine_time_meas_cap);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001958
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301959 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &bval);
1960 if (!QDF_IS_STATUS_SUCCESS(status))
1961 hdd_err("unable to get vht_enable2x2");
1962
1963 antenna_mode = (bval == 0x01) ?
Nitesh Shahe50711f2017-04-26 16:30:45 +05301964 HDD_ANTENNA_MODE_2X2 : HDD_ANTENNA_MODE_1X1;
1965 hdd_update_smps_antenna_mode(hdd_ctx, antenna_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001966 hdd_debug("Init current antenna mode: %d",
Arif Hussainee10f902017-12-27 16:30:17 -08001967 hdd_ctx->current_antenna_mode);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001968
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05301969 hdd_ctx->rcpi_enabled = cfg->rcpi_enabled;
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301970
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301971 status = ucfg_mlme_cfg_get_vht_tx_bfee_ant_supp(hdd_ctx->psoc,
Abhinav Kumare057b412018-10-09 17:28:16 +05301972 &value);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301973 if (QDF_IS_STATUS_ERROR(status)) {
1974 status = false;
1975 hdd_err("set tx_bfee_ant_supp failed");
1976 }
1977
1978 if ((value >
Arif Hussainee10f902017-12-27 16:30:17 -08001979 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF) &&
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301980 !cfg->tx_bfee_8ss_enabled) {
1981 status =
1982 ucfg_mlme_cfg_set_vht_tx_bfee_ant_supp(hdd_ctx->psoc,
1983 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF);
1984 if (QDF_IS_STATUS_ERROR(status)) {
1985 status = false;
1986 hdd_err("set tx_bfee_ant_supp failed");
1987 }
1988 }
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05301989
Jeff Johnson16528362018-06-14 12:34:16 -07001990 mac_handle = hdd_ctx->mac_handle;
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05301991
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301992 hdd_debug("txBFCsnValue %d", value);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301993
1994 /*
1995 * Update txBFCsnValue and NumSoundingDim values to vhtcap in wiphy
1996 */
1997 hdd_update_wiphy_vhtcap(hdd_ctx);
Manjeet Singh70d3d932016-12-20 20:41:10 +05301998
Jianmin Zhuc8bfffb2019-01-15 12:40:03 +08001999 hdd_update_vhtcap_2g(hdd_ctx);
2000
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05302001 hdd_ctx->wmi_max_len = cfg->wmi_max_len;
2002
Ashish Kumar Dhanotiya908925d2019-03-01 17:35:30 +05302003 wlan_config_sched_scan_plans_to_wiphy(hdd_ctx->wiphy, hdd_ctx->psoc);
Yue Macd359b72017-10-03 15:21:00 -07002004 /*
2005 * This needs to be done after HDD pdev is created and stored since
2006 * it will access the HDD pdev object lock.
2007 */
2008 hdd_runtime_suspend_context_init(hdd_ctx);
2009
Deepak Dhamdhere13230d32016-05-26 00:46:53 -07002010 /* Configure NAN datapath features */
2011 hdd_nan_datapath_target_config(hdd_ctx, cfg);
Nachiket Kukade85aa3782018-11-02 20:12:34 +05302012 ucfg_nan_set_tgt_caps(hdd_ctx->psoc, &cfg->nan_caps);
Arif Hussain759a0232017-03-20 13:17:18 -07002013 hdd_ctx->dfs_cac_offload = cfg->dfs_cac_offload;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08002014 hdd_ctx->lte_coex_ant_share = cfg->services.lte_coex_ant_share;
Liangwei Dong0da14262018-07-03 03:30:23 -04002015 hdd_ctx->obss_scan_offload = cfg->services.obss_scan_offload;
Wu Gao5f764082019-01-04 15:54:38 +08002016 status = ucfg_mlme_set_obss_detection_offload_enabled(
2017 hdd_ctx->psoc, cfg->obss_detection_offloaded);
Arif Hussainee10f902017-12-27 16:30:17 -08002018 if (QDF_IS_STATUS_ERROR(status))
2019 hdd_err("Couldn't pass WNI_CFG_OBSS_DETECTION_OFFLOAD to CFG");
Arif Hussain05fb4872018-01-03 16:02:55 -08002020
Wu Gao5f764082019-01-04 15:54:38 +08002021 status = ucfg_mlme_set_obss_color_collision_offload_enabled(
2022 hdd_ctx->psoc, cfg->obss_color_collision_offloaded);
Arif Hussain05fb4872018-01-03 16:02:55 -08002023 if (QDF_IS_STATUS_ERROR(status))
2024 hdd_err("Failed to set WNI_CFG_OBSS_COLOR_COLLISION_OFFLOAD");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002025}
2026
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002027bool hdd_dfs_indicate_radar(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002028{
Jeff Johnson9d295242017-08-29 14:39:48 -07002029 struct hdd_adapter *adapter;
Jeff Johnson87251032017-08-29 13:31:11 -07002030 struct hdd_ap_ctx *ap_ctx;
Arif Hussain224d3812018-11-16 17:58:38 -08002031 bool dfs_disable_channel_switch = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002032
Jiachao Wuf610d912018-01-23 17:47:32 +08002033 if (!hdd_ctx) {
2034 hdd_info("Couldn't get hdd_ctx");
2035 return true;
2036 }
2037
Arif Hussain224d3812018-11-16 17:58:38 -08002038 ucfg_mlme_get_dfs_disable_channel_switch(hdd_ctx->psoc,
2039 &dfs_disable_channel_switch);
2040 if (dfs_disable_channel_switch) {
Jeff Johnson36e74c42017-09-18 08:15:42 -07002041 hdd_info("skip tx block hdd_ctx=%pK, disableDFSChSwitch=%d",
Arif Hussain224d3812018-11-16 17:58:38 -08002042 hdd_ctx, dfs_disable_channel_switch);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302043 return true;
Arif Hussaincd151632017-02-11 16:57:19 -08002044 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002045
Dustin Brown920397d2017-12-13 16:27:50 -08002046 hdd_for_each_adapter(hdd_ctx, adapter) {
Arif Hussaincd151632017-02-11 16:57:19 -08002047 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
2048
2049 if ((QDF_SAP_MODE == adapter->device_mode ||
2050 QDF_P2P_GO_MODE == adapter->device_mode) &&
Dustin Brown07901ec2018-09-07 11:02:41 -07002051 (wlan_reg_is_passive_or_disable_ch(hdd_ctx->pdev,
Jeff Johnson01206862017-10-27 20:55:59 -07002052 ap_ctx->operating_channel))) {
Arif Hussaincd151632017-02-11 16:57:19 -08002053 WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx =
2054 true;
Jeff Johnson7eb6e842019-02-23 14:33:34 -08002055 hdd_info("tx blocked for vdev: %d",
Jeff Johnson5a6fc962019-02-04 14:20:25 -08002056 adapter->vdev_id);
bings6fb9bf62018-07-05 14:01:53 +08002057 if (adapter->txrx_vdev)
2058 cdp_fc_vdev_flush(
2059 cds_get_context(QDF_MODULE_ID_SOC),
bings0e03a982018-05-09 08:40:59 +08002060 adapter->txrx_vdev);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302061 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002062 }
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302063
2064 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002065}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002066
Jeff Johnson030cd902018-11-11 10:19:40 -08002067bool hdd_is_valid_mac_address(const uint8_t *mac_addr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002068{
2069 int xdigit = 0;
2070 int separator = 0;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002071
Jeff Johnson030cd902018-11-11 10:19:40 -08002072 while (*mac_addr) {
2073 if (isxdigit(*mac_addr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002074 xdigit++;
Jeff Johnson030cd902018-11-11 10:19:40 -08002075 } else if (':' == *mac_addr) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002076 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
2077 break;
2078
2079 ++separator;
2080 } else {
2081 /* Invalid MAC found */
Jeff Johnson030cd902018-11-11 10:19:40 -08002082 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002083 }
Jeff Johnson030cd902018-11-11 10:19:40 -08002084 ++mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002085 }
2086 return xdigit == 12 && (separator == 5 || separator == 0);
2087}
2088
2089/**
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302090 * hdd_mon_mode_ether_setup() - Update monitor mode struct net_device.
2091 * @dev: Handle to struct net_device to be updated.
2092 *
2093 * Return: None
2094 */
2095static void hdd_mon_mode_ether_setup(struct net_device *dev)
2096{
2097 dev->header_ops = NULL;
2098 dev->type = ARPHRD_IEEE80211_RADIOTAP;
2099 dev->hard_header_len = ETH_HLEN;
2100 dev->mtu = ETH_DATA_LEN;
2101 dev->addr_len = ETH_ALEN;
2102 dev->tx_queue_len = 1000; /* Ethernet wants good queues */
2103 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
2104 dev->priv_flags |= IFF_TX_SKB_SHARING;
2105
2106 memset(dev->broadcast, 0xFF, ETH_ALEN);
2107}
2108
Nirav Shah73713f72018-05-17 14:50:41 +05302109#ifdef FEATURE_MONITOR_MODE_SUPPORT
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302110/**
chenguo71303962018-10-24 19:44:34 +08002111 * hdd_mon_turn_off_ps_and_wow() - Update monitor mode struct net_device.
2112 * @hdd_ctx: Pointer to HDD context.
2113 *
2114 * Return: None
2115 */
2116static void hdd_mon_turn_off_ps_and_wow(struct hdd_context *hdd_ctx)
2117{
2118 ucfg_pmo_set_power_save_mode(hdd_ctx->psoc, PS_NOT_SUPPORTED);
2119 ucfg_pmo_set_wow_enable(hdd_ctx->psoc, PMO_WOW_DISABLE_BOTH);
2120}
2121
2122/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002123 * __hdd__mon_open() - HDD Open function
2124 * @dev: Pointer to net_device structure
2125 *
2126 * This is called in response to ifconfig up
2127 *
2128 * Return: 0 for success; non-zero for failure
2129 */
2130static int __hdd_mon_open(struct net_device *dev)
2131{
2132 int ret;
Ravi Joshia307f632017-07-17 23:41:41 -07002133 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2134 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002135
Dustin Brownfdf17c12018-03-14 12:55:34 -07002136 hdd_enter_dev(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002137
2138 ret = wlan_hdd_validate_context(hdd_ctx);
2139 if (ret)
2140 return ret;
2141
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302142 hdd_mon_mode_ether_setup(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002143
2144 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
Dustin Brown3ecc8782018-09-19 16:37:13 -07002145 ret = hdd_psoc_idle_restart(hdd_ctx);
Ravi Joshia307f632017-07-17 23:41:41 -07002146 if (ret) {
2147 hdd_err("Failed to start WLAN modules return");
2148 return ret;
2149 }
2150 hdd_err("hdd_wlan_start_modules() successful !");
2151
2152 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2153 ret = hdd_start_adapter(adapter);
2154 if (ret) {
2155 hdd_err("Failed to start adapter :%d",
2156 adapter->device_mode);
2157 return ret;
2158 }
2159 hdd_err("hdd_start_adapters() successful !");
2160 }
chenguo71303962018-10-24 19:44:34 +08002161 hdd_mon_turn_off_ps_and_wow(hdd_ctx);
Ravi Joshia307f632017-07-17 23:41:41 -07002162 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2163 }
2164
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002165 ret = hdd_set_mon_rx_cb(dev);
Ravi Joshi4f095952017-06-29 15:39:19 -07002166
2167 if (!ret)
2168 ret = hdd_enable_monitor_mode(dev);
2169
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002170 return ret;
2171}
2172
2173/**
2174 * hdd_mon_open() - Wrapper function for __hdd_mon_open to protect it from SSR
2175 * @dev: Pointer to net_device structure
2176 *
2177 * This is called in response to ifconfig up
2178 *
2179 * Return: 0 for success; non-zero for failure
2180 */
Dustin Brown0e1e1622019-01-17 11:00:22 -08002181static int hdd_mon_open(struct net_device *net_dev)
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002182{
Dustin Brown0e1e1622019-01-17 11:00:22 -08002183 int errno;
2184 struct osif_vdev_sync *vdev_sync;
2185
2186 errno = osif_vdev_sync_trans_start(net_dev, &vdev_sync);
2187 if (errno)
2188 return errno;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002189
Dustin Brown0e1e1622019-01-17 11:00:22 -08002190 errno = __hdd_mon_open(net_dev);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002191
Dustin Brown0e1e1622019-01-17 11:00:22 -08002192 osif_vdev_sync_trans_stop(vdev_sync);
2193
2194 return errno;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002195}
Nirav Shah73713f72018-05-17 14:50:41 +05302196#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002197
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002198static QDF_STATUS
2199wlan_hdd_update_dbs_scan_and_fw_mode_config(void)
2200{
2201 struct policy_mgr_dual_mac_config cfg = {0};
2202 QDF_STATUS status;
Krunal Sonie64b17e2018-12-13 16:00:02 -08002203 uint32_t chnl_sel_logic_conc = 0;
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002204 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Krunal Sonidf29bc42018-11-15 13:26:29 -08002205 uint8_t dual_mac_feature = DISABLE_DBS_CXN_AND_SCAN;
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002206
2207 if (!hdd_ctx) {
2208 hdd_err("HDD context is NULL");
2209 return QDF_STATUS_E_FAILURE;
2210 }
2211
Krunal Sonie64b17e2018-12-13 16:00:02 -08002212 /*
2213 * ROME platform doesn't support any DBS related commands in FW,
2214 * so if driver sends wmi command with dual_mac_config with all set to
2215 * 0 then FW wouldn't respond back and driver would timeout on waiting
2216 * for response. Check if FW supports DBS to eliminate ROME vs
2217 * NON-ROME platform.
2218 */
2219 if (!policy_mgr_find_if_fw_supports_dbs(hdd_ctx->psoc))
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002220 return QDF_STATUS_SUCCESS;
2221
2222 cfg.scan_config = 0;
2223 cfg.fw_mode_config = 0;
2224 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
Krunal Sonie64b17e2018-12-13 16:00:02 -08002225 if (policy_mgr_is_hw_dbs_capable(hdd_ctx->psoc)) {
2226 status =
2227 ucfg_policy_mgr_get_chnl_select_plcy(hdd_ctx->psoc,
2228 &chnl_sel_logic_conc);
2229 if (status != QDF_STATUS_SUCCESS) {
2230 hdd_err("can't get chnl sel policy, use def");
2231 return status;
2232 }
Krunal Sonidf29bc42018-11-15 13:26:29 -08002233 }
2234 status =
2235 ucfg_policy_mgr_get_dual_mac_feature(hdd_ctx->psoc,
2236 &dual_mac_feature);
2237 if (status != QDF_STATUS_SUCCESS) {
2238 hdd_err("ucfg_policy_mgr_get_dual_mac_feature failed, use def");
2239 return status;
2240 }
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002241
Krunal Sonidf29bc42018-11-15 13:26:29 -08002242 if (dual_mac_feature != DISABLE_DBS_CXN_AND_SCAN) {
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002243 status = policy_mgr_get_updated_scan_and_fw_mode_config(
Dustin Brown1dbefe62018-09-11 16:32:03 -07002244 hdd_ctx->psoc, &cfg.scan_config,
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002245 &cfg.fw_mode_config,
Krunal Sonidf29bc42018-11-15 13:26:29 -08002246 dual_mac_feature,
Krunal Sonie64b17e2018-12-13 16:00:02 -08002247 chnl_sel_logic_conc);
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002248
2249 if (status != QDF_STATUS_SUCCESS) {
2250 hdd_err("wma_get_updated_scan_and_fw_mode_config failed %d",
2251 status);
2252 return status;
2253 }
2254 }
2255
2256 hdd_debug("send scan_cfg: 0x%x fw_mode_cfg: 0x%x to fw",
2257 cfg.scan_config, cfg.fw_mode_config);
2258
2259 status = sme_soc_set_dual_mac_config(cfg);
2260 if (status != QDF_STATUS_SUCCESS) {
2261 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
2262 return status;
2263 }
2264
2265 return QDF_STATUS_SUCCESS;
2266}
2267
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002268/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302269 * hdd_start_adapter() - Wrapper function for device specific adapter
2270 * @adapter: pointer to HDD adapter
2271 *
2272 * This function is called to start the device specific adapter for
2273 * the mode passed in the adapter's device_mode.
2274 *
2275 * Return: 0 for success; non-zero for failure
2276 */
Jeff Johnson9d295242017-08-29 14:39:48 -07002277int hdd_start_adapter(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05302278{
2279
2280 int ret;
Jeff Johnsonc1e62782017-11-09 09:50:17 -08002281 enum QDF_OPMODE device_mode = adapter->device_mode;
Arun Khandavallifae92942016-08-01 13:31:08 +05302282
Dustin Brownfdf17c12018-03-14 12:55:34 -07002283 hdd_enter_dev(adapter->dev);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002284 hdd_debug("Start_adapter for mode : %d", adapter->device_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +05302285
2286 switch (device_mode) {
2287 case QDF_P2P_CLIENT_MODE:
2288 case QDF_P2P_DEVICE_MODE:
2289 case QDF_OCB_MODE:
2290 case QDF_STA_MODE:
2291 case QDF_MONITOR_MODE:
2292 ret = hdd_start_station_adapter(adapter);
2293 if (ret)
2294 goto err_start_adapter;
Alok Kumar81e1d732018-09-04 11:10:36 +05302295
2296 hdd_nud_ignore_tracking(adapter, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05302297 break;
2298 case QDF_P2P_GO_MODE:
2299 case QDF_SAP_MODE:
2300 ret = hdd_start_ap_adapter(adapter);
2301 if (ret)
2302 goto err_start_adapter;
2303 break;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05302304 case QDF_IBSS_MODE:
2305 /*
2306 * For IBSS interface is initialized as part of
2307 * hdd_init_station_mode()
2308 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08002309 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302310 case QDF_FTM_MODE:
Dustin Browndb2a8be2017-12-20 11:49:56 -08002311 /* vdevs are dynamically managed by firmware in FTM */
2312 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302313 default:
2314 hdd_err("Invalid session type %d", device_mode);
2315 QDF_ASSERT(0);
2316 goto err_start_adapter;
2317 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08002318
Arun Khandavallifae92942016-08-01 13:31:08 +05302319 if (hdd_set_fw_params(adapter))
2320 hdd_err("Failed to set the FW params for the adapter!");
2321
Jeff Johnson912b1bb2019-03-06 10:12:36 -08002322 if (adapter->vdev_id != WLAN_UMAC_VDEV_ID_MAX) {
Dustin Browne7e71d32018-05-11 16:00:08 -07002323 ret = wlan_hdd_cfg80211_register_frames(adapter);
2324 if (ret < 0) {
2325 hdd_err("Failed to register frames - ret %d", ret);
2326 goto err_start_adapter;
2327 }
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302328 }
Dustin Browne7e71d32018-05-11 16:00:08 -07002329
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002330 wlan_hdd_update_dbs_scan_and_fw_mode_config();
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302331
Dustin Browndb2a8be2017-12-20 11:49:56 -08002332exit_with_success:
Dustin Browne74003f2018-03-14 12:51:58 -07002333 hdd_exit();
Dustin Browndb2a8be2017-12-20 11:49:56 -08002334
Arun Khandavallifae92942016-08-01 13:31:08 +05302335 return 0;
Dustin Browndb2a8be2017-12-20 11:49:56 -08002336
Arun Khandavallifae92942016-08-01 13:31:08 +05302337err_start_adapter:
2338 return -EINVAL;
2339}
2340
2341/**
Komal Seelamf2136bb2016-09-28 18:30:44 +05302342 * hdd_enable_power_management() - API to Enable Power Management
2343 *
2344 * API invokes Bus Interface Layer power management functionality
2345 *
2346 * Return: None
2347 */
2348static void hdd_enable_power_management(void)
2349{
2350 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2351
2352 if (!hif_ctx) {
2353 hdd_err("Bus Interface Context is Invalid");
2354 return;
2355 }
2356
2357 hif_enable_power_management(hif_ctx, cds_is_packet_log_enabled());
2358}
2359
2360/**
2361 * hdd_disable_power_management() - API to disable Power Management
2362 *
2363 * API disable Bus Interface Layer Power management functionality
2364 *
2365 * Return: None
2366 */
2367static void hdd_disable_power_management(void)
2368{
2369 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2370
2371 if (!hif_ctx) {
2372 hdd_err("Bus Interface Context is Invalid");
2373 return;
2374 }
2375
2376 hif_disable_power_management(hif_ctx);
2377}
2378
Ryan Hsuaadba072018-04-20 13:01:53 -07002379void hdd_update_hw_sw_info(struct hdd_context *hdd_ctx)
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302380{
2381 void *hif_sc;
Dustin Brown6f17a022017-07-19 13:40:55 -07002382 size_t target_hw_name_len;
2383 const char *target_hw_name;
Ryan Hsuaadba072018-04-20 13:01:53 -07002384 uint8_t *buf;
2385 uint32_t buf_len;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302386
2387 hif_sc = cds_get_context(QDF_MODULE_ID_HIF);
2388 if (!hif_sc) {
2389 hdd_err("HIF context is NULL");
2390 return;
2391 }
2392
Ryan Hsuaadba072018-04-20 13:01:53 -07002393 hif_get_hw_info(hif_sc, &hdd_ctx->target_hw_version,
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302394 &hdd_ctx->target_hw_revision,
Dustin Brown6f17a022017-07-19 13:40:55 -07002395 &target_hw_name);
2396
2397 if (hdd_ctx->target_hw_name)
2398 qdf_mem_free(hdd_ctx->target_hw_name);
2399
2400 target_hw_name_len = strlen(target_hw_name) + 1;
2401 hdd_ctx->target_hw_name = qdf_mem_malloc(target_hw_name_len);
2402 if (hdd_ctx->target_hw_name)
2403 qdf_mem_copy(hdd_ctx->target_hw_name, target_hw_name,
2404 target_hw_name_len);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302405
Ryan Hsuaadba072018-04-20 13:01:53 -07002406 buf = qdf_mem_malloc(WE_MAX_STR_LEN);
2407 if (buf) {
2408 buf_len = hdd_wlan_get_version(hdd_ctx, WE_MAX_STR_LEN, buf);
2409 hdd_info("%s", buf);
2410 qdf_mem_free(buf);
2411 }
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302412}
2413
2414/**
gbian62edd7e2017-03-07 13:12:13 +08002415 * hdd_update_cds_ac_specs_params() - update cds ac_specs params
2416 * @hdd_ctx: Pointer to hdd context
2417 *
2418 * Return: none
2419 */
2420static void
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002421hdd_update_cds_ac_specs_params(struct hdd_context *hdd_ctx)
gbian62edd7e2017-03-07 13:12:13 +08002422{
jitiphil8e15ea62018-11-16 18:05:34 +05302423 uint8_t tx_sched_wrr_param[TX_SCHED_WRR_PARAMS_NUM] = {0};
2424 qdf_size_t out_size = 0;
gbian62edd7e2017-03-07 13:12:13 +08002425 int i;
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002426 struct cds_context *cds_ctx;
gbian62edd7e2017-03-07 13:12:13 +08002427
Jeff Johnsond36fa332019-03-18 13:42:25 -07002428 if (!hdd_ctx)
gbian62edd7e2017-03-07 13:12:13 +08002429 return;
2430
Jeff Johnsond36fa332019-03-18 13:42:25 -07002431 if (!hdd_ctx->config) {
gbian62edd7e2017-03-07 13:12:13 +08002432 /* Do nothing if hdd_ctx is invalid */
2433 hdd_err("%s: Warning: hdd_ctx->cfg_ini is NULL", __func__);
2434 return;
2435 }
2436
2437 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2438
2439 if (!cds_ctx) {
2440 hdd_err("Invalid CDS Context");
2441 return;
2442 }
2443
2444 for (i = 0; i < OL_TX_NUM_WMM_AC; i++) {
2445 switch (i) {
2446 case OL_TX_WMM_AC_BE:
jitiphil8e15ea62018-11-16 18:05:34 +05302447 qdf_uint8_array_parse(
2448 cfg_get(hdd_ctx->psoc,
2449 CFG_DP_ENABLE_TX_SCHED_WRR_BE),
2450 tx_sched_wrr_param,
2451 sizeof(tx_sched_wrr_param),
2452 &out_size);
gbian62edd7e2017-03-07 13:12:13 +08002453 break;
2454 case OL_TX_WMM_AC_BK:
jitiphil8e15ea62018-11-16 18:05:34 +05302455 qdf_uint8_array_parse(
2456 cfg_get(hdd_ctx->psoc,
2457 CFG_DP_ENABLE_TX_SCHED_WRR_BK),
2458 tx_sched_wrr_param,
2459 sizeof(tx_sched_wrr_param),
2460 &out_size);
gbian62edd7e2017-03-07 13:12:13 +08002461 break;
2462 case OL_TX_WMM_AC_VI:
jitiphil8e15ea62018-11-16 18:05:34 +05302463 qdf_uint8_array_parse(
2464 cfg_get(hdd_ctx->psoc,
2465 CFG_DP_ENABLE_TX_SCHED_WRR_VI),
2466 tx_sched_wrr_param,
2467 sizeof(tx_sched_wrr_param),
2468 &out_size);
gbian62edd7e2017-03-07 13:12:13 +08002469 break;
2470 case OL_TX_WMM_AC_VO:
jitiphil8e15ea62018-11-16 18:05:34 +05302471 qdf_uint8_array_parse(
2472 cfg_get(hdd_ctx->psoc,
2473 CFG_DP_ENABLE_TX_SCHED_WRR_VO),
2474 tx_sched_wrr_param,
2475 sizeof(tx_sched_wrr_param),
2476 &out_size);
gbian62edd7e2017-03-07 13:12:13 +08002477 break;
2478 default:
gbian62edd7e2017-03-07 13:12:13 +08002479 break;
2480 }
2481
jitiphil8e15ea62018-11-16 18:05:34 +05302482 if (out_size == TX_SCHED_WRR_PARAMS_NUM) {
gbian62edd7e2017-03-07 13:12:13 +08002483 cds_ctx->ac_specs[i].wrr_skip_weight =
2484 tx_sched_wrr_param[0];
2485 cds_ctx->ac_specs[i].credit_threshold =
2486 tx_sched_wrr_param[1];
2487 cds_ctx->ac_specs[i].send_limit =
2488 tx_sched_wrr_param[2];
2489 cds_ctx->ac_specs[i].credit_reserve =
2490 tx_sched_wrr_param[3];
2491 cds_ctx->ac_specs[i].discard_weight =
2492 tx_sched_wrr_param[4];
2493 }
2494
jitiphil8e15ea62018-11-16 18:05:34 +05302495 out_size = 0;
gbian62edd7e2017-03-07 13:12:13 +08002496 }
2497}
2498
Ryan Hsuaadba072018-04-20 13:01:53 -07002499uint32_t hdd_wlan_get_version(struct hdd_context *hdd_ctx,
2500 const size_t version_len, uint8_t *version)
2501{
2502 uint32_t size;
2503 uint32_t msp_id = 0, mspid = 0, siid = 0, crmid = 0, sub_id = 0;
2504
2505 if (!hdd_ctx) {
2506 hdd_err("Invalid context, HDD context is null");
2507 return 0;
2508 }
2509
Ashish Kumar Dhanotiya7353f882018-05-15 12:50:19 +05302510 if (!version || version_len == 0) {
Ryan Hsuaadba072018-04-20 13:01:53 -07002511 hdd_err("Invalid buffer pointr or buffer len\n");
2512 return 0;
2513 }
2514
2515 msp_id = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
2516 mspid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
2517 siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
2518 crmid = hdd_ctx->target_fw_version & 0x7fff;
2519 sub_id = (hdd_ctx->target_fw_vers_ext & 0xf0000000) >> 28;
2520
2521 size = scnprintf(version, version_len,
Ryan Hsuc6918552018-05-16 13:29:59 -07002522 "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 -07002523 QWLAN_VERSIONSTR,
2524 msp_id, mspid, siid, crmid, sub_id,
Ryan Hsuc6918552018-05-16 13:29:59 -07002525 hdd_ctx->target_hw_name,
2526 hdd_ctx->hw_bd_info.bdf_version,
2527 hdd_ctx->hw_bd_info.ref_design_id,
2528 hdd_ctx->hw_bd_info.customer_id,
2529 hdd_ctx->hw_bd_info.project_id,
2530 hdd_ctx->hw_bd_info.board_data_rev);
Ryan Hsuaadba072018-04-20 13:01:53 -07002531
2532 return size;
2533}
2534
Rachit Kankane0dc3e852018-05-07 17:33:42 +05302535int hdd_set_11ax_rate(struct hdd_adapter *adapter, int set_value,
2536 struct sap_config *sap_config)
2537{
2538 uint8_t preamble = 0, nss = 0, rix = 0;
2539 int ret;
2540 mac_handle_t mac_handle = adapter->hdd_ctx->mac_handle;
2541
2542 if (!sap_config) {
2543 if (!sme_is_feature_supported_by_fw(DOT11AX)) {
2544 hdd_err("Target does not support 11ax");
2545 return -EIO;
2546 }
2547 } else if (sap_config->SapHw_mode != eCSR_DOT11_MODE_11ax &&
2548 sap_config->SapHw_mode != eCSR_DOT11_MODE_11ax_ONLY) {
2549 hdd_err("Invalid hw mode, SAP hw_mode= 0x%x, ch = %d",
2550 sap_config->SapHw_mode, sap_config->channel);
2551 return -EIO;
2552 }
2553
2554 if (set_value != 0xff) {
2555 rix = RC_2_RATE_IDX_11AX(set_value);
2556 preamble = WMI_RATE_PREAMBLE_HE;
2557 nss = HT_RC_2_STREAMS_11AX(set_value);
2558
2559 set_value = hdd_assemble_rate_code(preamble, nss, rix);
2560 } else {
Jeff Johnson5a6fc962019-02-04 14:20:25 -08002561 ret = sme_set_auto_rate_he_ltf(mac_handle, adapter->vdev_id,
Rachit Kankane0dc3e852018-05-07 17:33:42 +05302562 QCA_WLAN_HE_LTF_AUTO);
2563 }
2564
2565 hdd_info("SET_11AX_RATE val %d rix %d preamble %x nss %d",
2566 set_value, rix, preamble, nss);
2567
Jeff Johnson5a6fc962019-02-04 14:20:25 -08002568 ret = wma_cli_set_command(adapter->vdev_id,
Rachit Kankane0dc3e852018-05-07 17:33:42 +05302569 WMI_VDEV_PARAM_FIXED_RATE,
2570 set_value, VDEV_CMD);
2571
2572 return ret;
2573}
2574
2575int hdd_assemble_rate_code(uint8_t preamble, uint8_t nss, uint8_t rate)
2576{
2577 int set_value;
2578
2579 if (sme_is_feature_supported_by_fw(DOT11AX))
2580 set_value = WMI_ASSEMBLE_RATECODE_V1(rate, nss, preamble);
2581 else
2582 set_value = (preamble << 6) | (nss << 4) | rate;
2583
2584 return set_value;
2585}
2586
Liangwei Dong3fa5cba2018-07-16 06:41:55 -04002587#ifdef FEATURE_WLAN_WAPI
2588/**
2589 * hdd_wapi_security_sta_exist() - return wapi security sta exist or not
2590 *
2591 * This API returns the wapi security station exist or not
2592 *
2593 * Return: true - wapi security station exist
2594 */
2595static bool hdd_wapi_security_sta_exist(void)
2596{
2597 struct hdd_adapter *adapter = NULL;
2598 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
2599
2600 hdd_for_each_adapter(hdd_ctx, adapter) {
2601 if ((adapter->device_mode == QDF_STA_MODE) &&
2602 adapter->wapi_info.wapi_mode &&
2603 (adapter->wapi_info.wapi_auth_mode != WAPI_AUTH_MODE_OPEN))
2604 return true;
2605 }
2606 return false;
2607}
2608#else
2609static bool hdd_wapi_security_sta_exist(void)
2610{
2611 return false;
2612}
2613#endif
2614
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002615#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002616static enum policy_mgr_con_mode wlan_hdd_get_mode_for_non_connected_vdev(
2617 struct wlan_objmgr_psoc *psoc, uint8_t vdev_id)
2618{
Jeff Johnson9d295242017-08-29 14:39:48 -07002619 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002620 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002621
2622 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2623 if (!adapter) {
2624 hdd_err("Adapter is NULL");
2625 return PM_MAX_NUM_OF_MODE;
2626 }
2627
2628 return policy_mgr_convert_device_mode_to_qdf_type(
2629 adapter->device_mode);
2630}
2631
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002632static void hdd_register_policy_manager_callback(
2633 struct wlan_objmgr_psoc *psoc)
2634{
2635 struct policy_mgr_hdd_cbacks hdd_cbacks;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07002636
Liangwei Dong3fa5cba2018-07-16 06:41:55 -04002637 qdf_mem_zero(&hdd_cbacks, sizeof(hdd_cbacks));
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002638 hdd_cbacks.sap_restart_chan_switch_cb =
Jeff Johnson23812942017-10-06 11:33:55 -07002639 hdd_sap_restart_chan_switch_cb;
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002640 hdd_cbacks.wlan_hdd_get_channel_for_sap_restart =
2641 wlan_hdd_get_channel_for_sap_restart;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002642 hdd_cbacks.get_mode_for_non_connected_vdev =
2643 wlan_hdd_get_mode_for_non_connected_vdev;
Yeshwanth Sriram Guntuka469f9572018-02-12 13:28:22 +05302644 hdd_cbacks.hdd_get_device_mode = hdd_get_device_mode;
Liangwei Dong3fa5cba2018-07-16 06:41:55 -04002645 hdd_cbacks.hdd_wapi_security_sta_exist =
2646 hdd_wapi_security_sta_exist;
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002647 if (QDF_STATUS_SUCCESS !=
2648 policy_mgr_register_hdd_cb(psoc, &hdd_cbacks)) {
2649 hdd_err("HDD callback registration with policy manager failed");
2650 }
2651}
2652#else
2653static void hdd_register_policy_manager_callback(
2654 struct wlan_objmgr_psoc *psoc)
2655{
2656}
2657#endif
2658
Nachiket Kukade2fb1fdb2019-01-08 15:35:27 +05302659#ifdef WLAN_FEATURE_NAN
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002660static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002661{
2662 struct nan_callbacks cb_obj = {0};
2663
2664 cb_obj.ndi_open = hdd_ndi_open;
2665 cb_obj.ndi_close = hdd_ndi_close;
2666 cb_obj.ndi_start = hdd_ndi_start;
2667 cb_obj.ndi_delete = hdd_ndi_delete;
2668 cb_obj.drv_ndi_create_rsp_handler = hdd_ndi_drv_ndi_create_rsp_handler;
2669 cb_obj.drv_ndi_delete_rsp_handler = hdd_ndi_drv_ndi_delete_rsp_handler;
2670
Naveen Rawat37f62c82017-03-26 22:24:43 -07002671 cb_obj.new_peer_ind = hdd_ndp_new_peer_handler;
Naveen Rawatb3143ea2017-03-26 22:25:46 -07002672 cb_obj.peer_departed_ind = hdd_ndp_peer_departed_handler;
Naveen Rawat37f62c82017-03-26 22:24:43 -07002673
Dustin Brown1dbefe62018-09-11 16:32:03 -07002674 os_if_nan_register_hdd_callbacks(hdd_ctx->psoc, &cb_obj);
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002675}
jiadff1ac132018-11-26 16:27:48 +08002676#else
2677static inline void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
2678{
2679}
2680#endif
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002681
Dustin Brown26b3d042017-12-21 11:13:27 -08002682#ifdef CONFIG_LEAK_DETECTION
Dustin Brown4c5b9902017-12-19 11:17:19 -08002683/**
2684 * hdd_check_for_leaks() - Perform runtime memory leak checks
Dustin Browna6246dd2018-05-24 14:35:58 -07002685 * @hdd_ctx: the global HDD context
Dustin Brown29533f22018-07-24 13:11:56 -07002686 * @is_ssr: true if SSR is in progress
Dustin Brown4c5b9902017-12-19 11:17:19 -08002687 *
2688 * This API triggers runtime memory leak detection. This feature enforces the
2689 * policy that any memory allocated at runtime must also be released at runtime.
2690 *
2691 * Allocating memory at runtime and releasing it at unload is effectively a
2692 * memory leak for configurations which never unload (e.g. LONU, statically
2693 * compiled driver). Such memory leaks are NOT false positives, and must be
2694 * fixed.
2695 *
2696 * Return: None
2697 */
Dustin Brown29533f22018-07-24 13:11:56 -07002698static void hdd_check_for_leaks(struct hdd_context *hdd_ctx, bool is_ssr)
Dustin Brown4bc0a622017-12-06 15:56:50 -08002699{
Dustin Brown4c5b9902017-12-19 11:17:19 -08002700 /* DO NOT REMOVE these checks; for false positives, read above first */
2701
Dustin Brown1dbefe62018-09-11 16:32:03 -07002702 wlan_objmgr_psoc_check_for_peer_leaks(hdd_ctx->psoc);
2703 wlan_objmgr_psoc_check_for_vdev_leaks(hdd_ctx->psoc);
2704 wlan_objmgr_psoc_check_for_pdev_leaks(hdd_ctx->psoc);
Dustin Brown29533f22018-07-24 13:11:56 -07002705
2706 /* many adapter resources are not freed by design during SSR */
2707 if (is_ssr)
2708 return;
2709
Dustin Brown677e0862017-10-10 16:30:09 -07002710 qdf_mc_timer_check_for_leaks();
Dustin Brown8e711502017-12-07 16:49:11 -08002711 qdf_nbuf_map_check_for_leaks();
Dustin Browne6b9d5a2017-12-14 15:18:49 -08002712 qdf_mem_check_for_leaks();
Dustin Brown4bc0a622017-12-06 15:56:50 -08002713}
2714
Dustin Brown26b3d042017-12-21 11:13:27 -08002715#define hdd_debug_domain_set(domain) qdf_debug_domain_set(domain)
2716#else
Dustin Brown29533f22018-07-24 13:11:56 -07002717static inline void hdd_check_for_leaks(struct hdd_context *hdd_ctx, bool is_ssr)
2718{ }
Dustin Brown26b3d042017-12-21 11:13:27 -08002719
2720#define hdd_debug_domain_set(domain)
2721#endif /* CONFIG_LEAK_DETECTION */
2722
gbian62edd7e2017-03-07 13:12:13 +08002723/**
Paul Zhange03cf4c2018-01-19 18:33:22 +08002724 * hdd_update_country_code - Update country code
2725 * @hdd_ctx: HDD context
2726 *
2727 * Update country code based on module parameter country_code
2728 *
2729 * Return: 0 on success and errno on failure
2730 */
2731static int hdd_update_country_code(struct hdd_context *hdd_ctx)
2732{
2733 if (!country_code)
2734 return 0;
2735
2736 return hdd_reg_set_country(hdd_ctx, country_code);
2737}
2738
Dustin Browne7e71d32018-05-11 16:00:08 -07002739int hdd_wlan_start_modules(struct hdd_context *hdd_ctx, bool reinit)
Arun Khandavallifae92942016-08-01 13:31:08 +05302740{
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002741 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05302742 qdf_device_t qdf_dev;
2743 QDF_STATUS status;
Arun Khandavallifae92942016-08-01 13:31:08 +05302744 bool unint = false;
2745 void *hif_ctx;
Jingxiang Ge95912f82018-04-19 12:01:26 +08002746 struct target_psoc_info *tgt_hdl;
Arun Khandavallifae92942016-08-01 13:31:08 +05302747
Arun Khandavallifae92942016-08-01 13:31:08 +05302748 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2749 if (!qdf_dev) {
2750 hdd_err("QDF Device Context is Invalid return");
2751 return -EINVAL;
2752 }
2753
Dustin Brown4c663222018-10-23 14:19:36 -07002754 hdd_psoc_idle_timer_stop(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05302755
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302756 if (hdd_ctx->driver_status == DRIVER_MODULES_ENABLED) {
Dustin Brown1e3ec6b2018-08-07 11:18:47 -07002757 hdd_debug("Driver modules already Enabled");
Dustin Browne74003f2018-03-14 12:51:58 -07002758 hdd_exit();
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302759 return 0;
2760 }
2761
Arun Khandavallifae92942016-08-01 13:31:08 +05302762 switch (hdd_ctx->driver_status) {
2763 case DRIVER_MODULES_UNINITIALIZED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002764 hdd_info("Wlan transitioning (UNINITIALIZED -> CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +05302765 unint = true;
2766 /* Fall through dont add break here */
2767 case DRIVER_MODULES_CLOSED:
Dustin Brown1a20b082018-08-03 17:27:15 -07002768 hdd_info("Wlan transitioning (CLOSED -> ENABLED)");
Dustin Brown550f6d22017-12-14 15:44:01 -08002769
Dustin Brown26b3d042017-12-21 11:13:27 -08002770 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_ACTIVE);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002771
Arun Khandavallifae92942016-08-01 13:31:08 +05302772 if (!reinit && !unint) {
2773 ret = pld_power_on(qdf_dev->dev);
2774 if (ret) {
Dustin Brown1e3ec6b2018-08-07 11:18:47 -07002775 hdd_err("Failed to power up device; errno:%d",
Dustin Browndca39692017-11-09 15:30:25 -08002776 ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302777 goto release_lock;
2778 }
2779 }
Yuanyuan Liuf8fe4bc2017-06-07 16:55:58 -07002780
2781 pld_set_fw_log_mode(hdd_ctx->parent_dev,
2782 hdd_ctx->config->enable_fw_log);
Arun Khandavallifae92942016-08-01 13:31:08 +05302783 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
2784 qdf_dev->bus_type,
2785 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
2786 HIF_ENABLE_TYPE_PROBE);
2787 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002788 hdd_err("Failed to open hif; errno: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302789 goto power_down;
2790 }
2791
2792 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05302793 if (!hif_ctx) {
2794 hdd_err("hif context is null!!");
Dustin Browndca39692017-11-09 15:30:25 -08002795 ret = -EINVAL;
Arun Khandavalli1318b992016-08-09 11:04:57 +05302796 goto power_down;
2797 }
2798
Arun Khandavallifae92942016-08-01 13:31:08 +05302799 status = ol_cds_init(qdf_dev, hif_ctx);
2800 if (status != QDF_STATUS_SUCCESS) {
Dustin Browndca39692017-11-09 15:30:25 -08002801 hdd_err("No Memory to Create BMI Context; status: %d",
2802 status);
2803 ret = qdf_status_to_os_return(status);
Arun Khandavallifae92942016-08-01 13:31:08 +05302804 goto hif_close;
2805 }
2806
Nirav Shah6aeecf92019-02-13 14:05:03 +05302807 if (hdd_get_conparam() == QDF_GLOBAL_EPPING_MODE) {
2808 status = epping_open();
2809 if (status) {
2810 hdd_err("Failed to open in epping mode: %d",
2811 status);
2812 ret = -EINVAL;
2813 goto cds_free;
2814 }
2815
2816 status = epping_enable(qdf_dev->dev, false);
2817 if (status) {
2818 hdd_err("Failed to enable in epping mode : %d",
2819 status);
2820 epping_close();
2821 goto cds_free;
2822 }
2823
2824 hdd_info("epping mode enabled");
2825 break;
2826 }
2827
jitiphil4c256a32018-09-07 08:51:52 +05302828 ucfg_ipa_component_config_update(hdd_ctx->psoc);
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302829
gbian62edd7e2017-03-07 13:12:13 +08002830 hdd_update_cds_ac_specs_params(hdd_ctx);
2831
Dustin Brown1dbefe62018-09-11 16:32:03 -07002832 status = hdd_component_psoc_open(hdd_ctx->psoc);
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05302833 if (QDF_IS_STATUS_ERROR(status)) {
2834 hdd_err("Failed to Open legacy components; status: %d",
2835 status);
2836 ret = qdf_status_to_os_return(status);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05302837 goto cds_free;
2838 }
2839
2840 ret = hdd_update_config(hdd_ctx);
2841 if (ret) {
2842 hdd_err("Failed to update configuration; errno: %d",
2843 ret);
2844 goto cds_free;
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05302845 }
2846
Rakshith Suresh Patkard9f4e612018-09-12 12:10:38 +05302847 status = wbuff_module_init();
2848 if (QDF_IS_STATUS_ERROR(status))
2849 hdd_err("WBUFF init unsuccessful; status: %d", status);
2850
Dustin Brown1dbefe62018-09-11 16:32:03 -07002851 status = cds_open(hdd_ctx->psoc);
Dustin Brown28b17892017-10-10 13:29:38 -07002852 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002853 hdd_err("Failed to Open CDS; status: %d", status);
Dustin Brown28b17892017-10-10 13:29:38 -07002854 ret = qdf_status_to_os_return(status);
Krunal Sonie71838d2018-09-27 10:45:05 -07002855 goto psoc_close;
Arun Khandavallifae92942016-08-01 13:31:08 +05302856 }
2857
Vignesh Viswanathan987f0bb2018-09-17 17:00:29 +05302858 hdd_ctx->mac_handle = cds_get_context(QDF_MODULE_ID_SME);
2859
Manjunathappa Prakashb6b4ff12018-06-04 12:32:33 -07002860 if (hdd_ctx->config->rx_thread_affinity_mask)
2861 cds_set_rx_thread_cpu_mask(
2862 hdd_ctx->config->rx_thread_affinity_mask);
2863
2864 /* initialize components configurations after psoc open */
Mukul Sharma9d797a02017-01-05 20:26:03 +05302865 ret = hdd_update_components_config(hdd_ctx);
2866 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002867 hdd_err("Failed to update component configs; errno: %d",
Mukul Sharma9d797a02017-01-05 20:26:03 +05302868 ret);
2869 goto close;
2870 }
Sourav Mohapatra674925f2018-04-16 11:16:58 +05302871
Dustin Brown1dbefe62018-09-11 16:32:03 -07002872 status = cds_dp_open(hdd_ctx->psoc);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002873 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002874 hdd_err("Failed to Open cds post open; status: %d",
2875 status);
2876 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002877 goto close;
2878 }
Mukul Sharma9d797a02017-01-05 20:26:03 +05302879
Sourav Mohapatra674925f2018-04-16 11:16:58 +05302880 ret = hdd_register_cb(hdd_ctx);
2881 if (ret) {
2882 hdd_err("Failed to register HDD callbacks!");
2883 goto cds_txrx_free;
2884 }
2885
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002886 /*
2887 * NAN compoenet requires certian operations like, open adapter,
2888 * close adapter, etc. to be initiated by HDD, for those
2889 * register HDD callbacks with UMAC's NAN componenet.
2890 */
2891 hdd_nan_register_callbacks(hdd_ctx);
2892
Jeff Johnson3a280122017-09-13 07:42:00 -07002893 status = cds_pre_enable();
Arun Khandavallifae92942016-08-01 13:31:08 +05302894 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002895 hdd_err("Failed to pre-enable CDS; status: %d", status);
2896 ret = qdf_status_to_os_return(status);
Sourav Mohapatra674925f2018-04-16 11:16:58 +05302897 goto deregister_cb;
Arun Khandavallifae92942016-08-01 13:31:08 +05302898 }
2899
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002900 hdd_register_policy_manager_callback(
Dustin Brown1dbefe62018-09-11 16:32:03 -07002901 hdd_ctx->psoc);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002902
Arunk Khandavalli890f6d92018-10-30 20:18:28 +05302903 hdd_sysfs_create_driver_root_obj();
Dustin Brown1dbefe62018-09-11 16:32:03 -07002904 hdd_sysfs_create_version_interface(hdd_ctx->psoc);
Arunk Khandavalli890f6d92018-10-30 20:18:28 +05302905 hdd_sysfs_create_powerstats_interface();
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302906 hdd_update_hw_sw_info(hdd_ctx);
Dustin Brown550f6d22017-12-14 15:44:01 -08002907
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302908 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2909 hdd_err("in ftm mode, no need to configure cds modules");
Dustin Browndca39692017-11-09 15:30:25 -08002910 ret = -EINVAL;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302911 break;
2912 }
Dustin Browndca39692017-11-09 15:30:25 -08002913
Dustin Browne7e71d32018-05-11 16:00:08 -07002914 ret = hdd_configure_cds(hdd_ctx);
Dustin Browndca39692017-11-09 15:30:25 -08002915 if (ret) {
2916 hdd_err("Failed to Enable cds modules; errno: %d", ret);
Arunk Khandavalli890f6d92018-10-30 20:18:28 +05302917 goto destroy_driver_sysfs;
Arun Khandavallifae92942016-08-01 13:31:08 +05302918 }
Dustin Browndca39692017-11-09 15:30:25 -08002919
Komal Seelamf2136bb2016-09-28 18:30:44 +05302920 hdd_enable_power_management();
Dustin Brown550f6d22017-12-14 15:44:01 -08002921
Arun Khandavallifae92942016-08-01 13:31:08 +05302922 break;
Dustin Brown550f6d22017-12-14 15:44:01 -08002923
Arun Khandavallifae92942016-08-01 13:31:08 +05302924 default:
Dustin Brown1e3ec6b2018-08-07 11:18:47 -07002925 QDF_DEBUG_PANIC("Unknown driver state:%d",
Arun Khandavallifae92942016-08-01 13:31:08 +05302926 hdd_ctx->driver_status);
Dustin Browndca39692017-11-09 15:30:25 -08002927 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05302928 goto release_lock;
2929 }
Dustin Brown550f6d22017-12-14 15:44:01 -08002930
Dustin Brown1a20b082018-08-03 17:27:15 -07002931 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
2932 hdd_info("Wlan transitioned (now ENABLED)");
2933
Dustin Browne74003f2018-03-14 12:51:58 -07002934 hdd_exit();
Dustin Brown550f6d22017-12-14 15:44:01 -08002935
Arun Khandavallifae92942016-08-01 13:31:08 +05302936 return 0;
2937
Arunk Khandavalli890f6d92018-10-30 20:18:28 +05302938destroy_driver_sysfs:
2939 hdd_sysfs_destroy_powerstats_interface();
2940 hdd_sysfs_destroy_version_interface();
2941 hdd_sysfs_destroy_driver_root_obj();
Rajeev Kumarbe021242017-02-16 16:12:23 -08002942 cds_post_disable();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002943
Sourav Mohapatra674925f2018-04-16 11:16:58 +05302944deregister_cb:
2945 hdd_deregister_cb(hdd_ctx);
2946
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002947cds_txrx_free:
Dustin Brown1dbefe62018-09-11 16:32:03 -07002948 tgt_hdl = wlan_psoc_get_tgt_if_handle(hdd_ctx->psoc);
Jingxiang Ge95912f82018-04-19 12:01:26 +08002949
2950 if (tgt_hdl && target_psoc_get_wmi_ready(tgt_hdl)) {
2951 hdd_runtime_suspend_context_deinit(hdd_ctx);
Dustin Brown07901ec2018-09-07 11:02:41 -07002952 dispatcher_pdev_close(hdd_ctx->pdev);
Jingxiang Ge95912f82018-04-19 12:01:26 +08002953 hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
2954 }
2955
Dustin Brown1dbefe62018-09-11 16:32:03 -07002956 cds_dp_close(hdd_ctx->psoc);
Dustin Brown550f6d22017-12-14 15:44:01 -08002957
Arun Khandavallifae92942016-08-01 13:31:08 +05302958close:
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002959 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002960 hdd_info("Wlan transition aborted (now CLOSED)");
2961
Dustin Brown1dbefe62018-09-11 16:32:03 -07002962 cds_close(hdd_ctx->psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302963
Krunal Sonie71838d2018-09-27 10:45:05 -07002964psoc_close:
Dustin Brown1dbefe62018-09-11 16:32:03 -07002965 hdd_component_psoc_close(hdd_ctx->psoc);
Dustin Brown28b17892017-10-10 13:29:38 -07002966 cds_deinit_ini_config();
2967
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002968cds_free:
Arun Khandavallifae92942016-08-01 13:31:08 +05302969 ol_cds_free();
2970
2971hif_close:
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002972 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2973 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05302974power_down:
2975 if (!reinit && !unint)
2976 pld_power_off(qdf_dev->dev);
2977release_lock:
Abhinav Kumar7ae9b7b2017-12-19 15:11:54 +05302978 if (hdd_ctx->target_hw_name) {
2979 qdf_mem_free(hdd_ctx->target_hw_name);
2980 hdd_ctx->target_hw_name = NULL;
2981 }
Dustin Brown29533f22018-07-24 13:11:56 -07002982
2983 hdd_check_for_leaks(hdd_ctx, reinit);
Dustin Brown26b3d042017-12-21 11:13:27 -08002984 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002985
Dustin Browne74003f2018-03-14 12:51:58 -07002986 hdd_exit();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002987
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002988 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05302989}
2990
Naveen Rawat910726a2017-03-06 11:42:51 -08002991#ifdef WIFI_POS_CONVERGED
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002992static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002993{
2994 int ret = os_if_wifi_pos_register_nl();
2995
2996 if (ret)
2997 hdd_err("os_if_wifi_pos_register_nl failed");
2998
2999 return ret;
3000}
3001
3002static int hdd_deactivate_wifi_pos(void)
3003{
3004 int ret = os_if_wifi_pos_deregister_nl();
3005
3006 if (ret)
3007 hdd_err("os_if_wifi_pos_deregister_nl failed");
3008
3009 return ret;
3010}
3011
3012/**
3013 * hdd_populate_wifi_pos_cfg - populates wifi_pos parameters
3014 * @hdd_ctx: hdd context
3015 *
3016 * Return: status of operation
3017 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003018static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08003019{
Dustin Brown1dbefe62018-09-11 16:32:03 -07003020 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Wu Gao1ab05582018-11-08 16:22:49 +08003021 uint16_t neighbor_scan_max_chan_time;
3022 uint16_t neighbor_scan_min_chan_time;
Naveen Rawat910726a2017-03-06 11:42:51 -08003023
3024 wifi_pos_set_oem_target_type(psoc, hdd_ctx->target_type);
3025 wifi_pos_set_oem_fw_version(psoc, hdd_ctx->target_fw_version);
3026 wifi_pos_set_drv_ver_major(psoc, QWLAN_VERSION_MAJOR);
3027 wifi_pos_set_drv_ver_minor(psoc, QWLAN_VERSION_MINOR);
3028 wifi_pos_set_drv_ver_patch(psoc, QWLAN_VERSION_PATCH);
3029 wifi_pos_set_drv_ver_build(psoc, QWLAN_VERSION_BUILD);
Wu Gao1ab05582018-11-08 16:22:49 +08003030 ucfg_mlme_get_neighbor_scan_max_chan_time(psoc,
3031 &neighbor_scan_max_chan_time);
3032 ucfg_mlme_get_neighbor_scan_min_chan_time(psoc,
3033 &neighbor_scan_min_chan_time);
3034 wifi_pos_set_dwell_time_min(psoc, neighbor_scan_min_chan_time);
3035 wifi_pos_set_dwell_time_max(psoc, neighbor_scan_max_chan_time);
Naveen Rawat910726a2017-03-06 11:42:51 -08003036}
3037#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003038static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08003039{
3040 return oem_activate_service(hdd_ctx);
3041}
3042
3043static int hdd_deactivate_wifi_pos(void)
3044{
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05303045 return oem_deactivate_service();
Naveen Rawat910726a2017-03-06 11:42:51 -08003046}
3047
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003048static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08003049{
3050}
3051#endif
3052
Arun Khandavallifae92942016-08-01 13:31:08 +05303053/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003054 * __hdd_open() - HDD Open function
3055 * @dev: Pointer to net_device structure
3056 *
3057 * This is called in response to ifconfig up
3058 *
3059 * Return: 0 for success; non-zero for failure
3060 */
3061static int __hdd_open(struct net_device *dev)
3062{
Jeff Johnson9d295242017-08-29 14:39:48 -07003063 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003064 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003065 int ret;
3066
Dustin Brownfdf17c12018-03-14 12:55:34 -07003067 hdd_enter_dev(dev);
Ashish Kumar Dhanotiyaf10aa5f2018-12-28 21:29:56 +05303068
3069 qdf_mtrace(QDF_MODULE_ID_HDD, QDF_MODULE_ID_HDD,
3070 TRACE_CODE_HDD_OPEN_REQUEST,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08003071 adapter->vdev_id, adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003072
Ashish Kumar Dhanotiya15a7db52017-08-03 10:27:34 +05303073 /* Nothing to be done if device is unloading */
3074 if (cds_is_driver_unloading()) {
3075 hdd_err("Driver is unloading can not open the hdd");
3076 return -EBUSY;
3077 }
3078
Dustin Brown01847752017-10-25 13:56:27 -07003079 if (cds_is_driver_recovering()) {
3080 hdd_err("WLAN is currently recovering; Please try again.");
3081 return -EBUSY;
3082 }
3083
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303084 /*
3085 * This scenario can be hit in cases where in the wlan driver after
3086 * registering the netdevices and there is a failure in driver
3087 * initialization. So return error gracefully because the netdevices
3088 * will be de-registered as part of the load failure.
3089 */
3090
3091 if (!cds_is_driver_loaded()) {
3092 hdd_err("Failed to start the wlan driver!!");
Dustin Brown3da3a832019-03-19 15:51:54 -07003093 return -EIO;
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303094 }
Abhishek Singh23edd1c2016-05-05 11:56:06 +05303095
Dustin Brown3ecc8782018-09-19 16:37:13 -07003096 ret = hdd_psoc_idle_restart(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05303097 if (ret) {
3098 hdd_err("Failed to start WLAN modules return");
Dustin Brown3da3a832019-03-19 15:51:54 -07003099 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05303100 }
3101
Arun Khandavallifae92942016-08-01 13:31:08 +05303102 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
3103 ret = hdd_start_adapter(adapter);
3104 if (ret) {
3105 hdd_err("Failed to start adapter :%d",
3106 adapter->device_mode);
Dustin Brown3da3a832019-03-19 15:51:54 -07003107 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05303108 }
3109 }
3110
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003111 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
3112 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07003113 hdd_debug("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003114 /* Enable TX queues only when we are connected */
3115 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05303116 WLAN_START_ALL_NETIF_QUEUE,
3117 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003118 }
3119
Naveen Rawat286def52016-09-23 15:38:02 -07003120 /* Enable carrier and transmit queues for NDI */
3121 if (WLAN_HDD_IS_NDI(adapter)) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07003122 hdd_debug("Enabling Tx Queues");
Naveen Rawat286def52016-09-23 15:38:02 -07003123 wlan_hdd_netif_queue_control(adapter,
3124 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
3125 WLAN_CONTROL_PATH);
3126 }
3127
Naveen Rawat910726a2017-03-06 11:42:51 -08003128 hdd_populate_wifi_pos_cfg(hdd_ctx);
Arunk Khandavalli40943af2017-05-15 19:25:34 +05303129 hdd_lpass_notify_start(hdd_ctx, adapter);
Naveen Rawat910726a2017-03-06 11:42:51 -08003130
Dustin Brown3da3a832019-03-19 15:51:54 -07003131 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003132}
3133
3134/**
3135 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
Dustin Brown98f7c822019-03-06 12:25:49 -08003136 * @net_dev: Pointer to net_device structure
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003137 *
3138 * This is called in response to ifconfig up
3139 *
3140 * Return: 0 for success; non-zero for failure
3141 */
Dustin Brown0e1e1622019-01-17 11:00:22 -08003142static int hdd_open(struct net_device *net_dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003143{
Dustin Brown0e1e1622019-01-17 11:00:22 -08003144 int errno;
3145 struct osif_vdev_sync *vdev_sync;
3146
3147 errno = osif_vdev_sync_trans_start(net_dev, &vdev_sync);
3148 if (errno)
3149 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003150
Dustin Brown0e1e1622019-01-17 11:00:22 -08003151 errno = __hdd_open(net_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003152
Dustin Brown0e1e1622019-01-17 11:00:22 -08003153 osif_vdev_sync_trans_stop(vdev_sync);
3154
3155 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003156}
3157
3158/**
3159 * __hdd_stop() - HDD stop function
3160 * @dev: Pointer to net_device structure
3161 *
3162 * This is called in response to ifconfig down
3163 *
3164 * Return: 0 for success; non-zero for failure
3165 */
3166static int __hdd_stop(struct net_device *dev)
3167{
Jeff Johnson9d295242017-08-29 14:39:48 -07003168 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003169 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003170 int ret;
Jeff Johnson16528362018-06-14 12:34:16 -07003171 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003172
Dustin Brownfdf17c12018-03-14 12:55:34 -07003173 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003174
Ashish Kumar Dhanotiyaf10aa5f2018-12-28 21:29:56 +05303175 qdf_mtrace(QDF_MODULE_ID_HDD, QDF_MODULE_ID_HDD,
3176 TRACE_CODE_HDD_STOP_REQUEST,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08003177 adapter->vdev_id, adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003178
3179 ret = wlan_hdd_validate_context(hdd_ctx);
Arunk Khandavalli987c8d52018-06-21 17:40:31 +05303180 if (ret) {
3181 set_bit(DOWN_DURING_SSR, &adapter->event_flags);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003182 return ret;
Arunk Khandavalli987c8d52018-06-21 17:40:31 +05303183 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003184
3185 /* Nothing to be done if the interface is not opened */
3186 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07003187 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003188 return -ENODEV;
3189 }
3190
3191 /* Make sure the interface is marked as closed */
3192 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Mukul Sharmad16c2022017-07-25 18:56:12 +05303193
Jeff Johnson16528362018-06-14 12:34:16 -07003194 mac_handle = hdd_ctx->mac_handle;
3195
Mukul Sharmad16c2022017-07-25 18:56:12 +05303196 hdd_debug("Disabling Auto Power save timer");
3197 sme_ps_disable_auto_ps_timer(
Jeff Johnson16528362018-06-14 12:34:16 -07003198 mac_handle,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08003199 adapter->vdev_id);
Mukul Sharmad16c2022017-07-25 18:56:12 +05303200
3201 /*
3202 * Disable TX on the interface, after this hard_start_xmit() will not
3203 * be called on that interface
3204 */
Dustin Browna7bb6ae2018-08-16 16:51:50 -07003205 hdd_debug("Disabling queues, adapter device mode: %s(%d)",
Dustin Brown458027c2018-10-19 12:26:27 -07003206 qdf_opmode_str(adapter->device_mode), adapter->device_mode);
Kabilan Kannan8dac3502017-10-30 12:40:27 -07003207
Himanshu Agarwal865201d2017-04-12 15:45:31 +05303208 wlan_hdd_netif_queue_control(adapter,
3209 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
3210 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003211
Arunk Khandavalli40943af2017-05-15 19:25:34 +05303212 if (adapter->device_mode == QDF_STA_MODE)
3213 hdd_lpass_notify_stop(hdd_ctx);
3214
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003215 /*
Naveen Rawat286def52016-09-23 15:38:02 -07003216 * NAN data interface is different in some sense. The traffic on NDI is
3217 * bursty in nature and depends on the need to transfer. The service
3218 * layer may down the interface after the usage and up again when
3219 * required. In some sense, the NDI is expected to be available
3220 * (like SAP) iface until NDI delete request is issued by the service
3221 * layer. Skip BSS termination and adapter deletion for NAN Data
3222 * interface (NDI).
3223 */
3224 if (WLAN_HDD_IS_NDI(adapter))
3225 return 0;
3226
3227 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003228 * The interface is marked as down for outside world (aka kernel)
3229 * But the driver is pretty much alive inside. The driver needs to
3230 * tear down the existing connection on the netdev (session)
3231 * cleanup the data pipes and wait until the control plane is stabilized
3232 * for this interface. The call also needs to wait until the above
3233 * mentioned actions are completed before returning to the caller.
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003234 * Notice that hdd_stop_adapter is requested not to close the session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003235 * That is intentional to be able to scan if it is a STA/P2P interface
3236 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08003237 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003238
3239 /* DeInit the adapter. This ensures datapath cleanup as well */
3240 hdd_deinit_adapter(hdd_ctx, adapter, true);
3241
Dustin Brown4c663222018-10-23 14:19:36 -07003242 if (!hdd_is_any_interface_open(hdd_ctx))
3243 hdd_psoc_idle_timer_start(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05303244
Dustin Browne74003f2018-03-14 12:51:58 -07003245 hdd_exit();
Dustin Brown4c663222018-10-23 14:19:36 -07003246
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003247 return 0;
3248}
3249
3250/**
3251 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
3252 * @dev: pointer to net_device structure
3253 *
3254 * This is called in response to ifconfig down
3255 *
3256 * Return: 0 for success and error number for failure
3257 */
Dustin Brown0e1e1622019-01-17 11:00:22 -08003258static int hdd_stop(struct net_device *net_dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003259{
Dustin Brown0e1e1622019-01-17 11:00:22 -08003260 int errno;
3261 struct osif_vdev_sync *vdev_sync;
3262
3263 errno = osif_vdev_sync_trans_start(net_dev, &vdev_sync);
3264 if (errno)
3265 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003266
Dustin Brown0e1e1622019-01-17 11:00:22 -08003267 errno = __hdd_stop(net_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003268
Dustin Brown0e1e1622019-01-17 11:00:22 -08003269 osif_vdev_sync_trans_stop(vdev_sync);
3270
3271 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003272}
3273
3274/**
Dustin Brown96b98dd2019-03-06 12:39:37 -08003275 * hdd_uninit() - HDD uninit function
3276 * @dev: Pointer to net_device structure
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003277 *
3278 * This is called during the netdev unregister to uninitialize all data
3279 * associated with the device
3280 *
Dustin Brown96b98dd2019-03-06 12:39:37 -08003281 * This function must be protected by a transition
3282 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003283 * Return: None
3284 */
Dustin Brown96b98dd2019-03-06 12:39:37 -08003285static void hdd_uninit(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003286{
Jeff Johnson9d295242017-08-29 14:39:48 -07003287 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson399c6272017-08-30 10:51:00 -07003288 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003289
Dustin Brownfdf17c12018-03-14 12:55:34 -07003290 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003291
Dustin Brown96b98dd2019-03-06 12:39:37 -08003292 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
3293 hdd_err("Invalid magic");
3294 goto exit;
3295 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003296
Dustin Brown96b98dd2019-03-06 12:39:37 -08003297 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3298 if (!hdd_ctx) {
3299 hdd_err("NULL hdd_ctx");
3300 goto exit;
3301 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003302
Dustin Brown96b98dd2019-03-06 12:39:37 -08003303 if (dev != adapter->dev)
3304 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003305
Dustin Brown96b98dd2019-03-06 12:39:37 -08003306 hdd_deinit_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003307
Dustin Brown96b98dd2019-03-06 12:39:37 -08003308 /* after uninit our adapter structure will no longer be valid */
3309 adapter->dev = NULL;
3310 adapter->magic = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003311
Dustin Brown96b98dd2019-03-06 12:39:37 -08003312exit:
Dustin Browne74003f2018-03-14 12:51:58 -07003313 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003314}
3315
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003316static int hdd_open_cesium_nl_sock(void)
3317{
3318#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3319 struct netlink_kernel_cfg cfg = {
3320 .groups = WLAN_NLINK_MCAST_GRP_ID,
3321 .input = NULL
3322 };
3323#endif
3324 int ret = 0;
3325
3326#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3327 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3328#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
3329 THIS_MODULE,
3330#endif
3331 &cfg);
3332#else
3333 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3334 WLAN_NLINK_MCAST_GRP_ID,
3335 NULL, NULL, THIS_MODULE);
3336#endif
3337
Jeff Johnsond36fa332019-03-18 13:42:25 -07003338 if (!cesium_nl_srv_sock) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07003339 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003340 ret = -ECONNREFUSED;
3341 }
3342
3343 return ret;
3344}
3345
3346static void hdd_close_cesium_nl_sock(void)
3347{
Jeff Johnsond36fa332019-03-18 13:42:25 -07003348 if (cesium_nl_srv_sock) {
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003349 netlink_kernel_release(cesium_nl_srv_sock);
3350 cesium_nl_srv_sock = NULL;
3351 }
3352}
3353
Ashish Kumar Dhanotiya6784b502018-10-17 12:51:10 +05303354void hdd_update_dynamic_mac(struct hdd_context *hdd_ctx,
3355 struct qdf_mac_addr *curr_mac_addr,
3356 struct qdf_mac_addr *new_mac_addr)
3357{
3358 uint8_t i;
3359
3360 hdd_enter();
3361
3362 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303363 if (!qdf_mem_cmp(
3364 curr_mac_addr->bytes,
3365 &hdd_ctx->dynamic_mac_list[i].dynamic_mac.bytes[0],
Ashish Kumar Dhanotiya6784b502018-10-17 12:51:10 +05303366 sizeof(struct qdf_mac_addr))) {
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303367 qdf_mem_copy(&hdd_ctx->dynamic_mac_list[i].dynamic_mac,
Ashish Kumar Dhanotiya6784b502018-10-17 12:51:10 +05303368 new_mac_addr->bytes,
3369 sizeof(struct qdf_mac_addr));
3370 break;
3371 }
3372 }
3373
3374 hdd_exit();
3375}
3376
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003377/**
3378 * __hdd_set_mac_address() - set the user specified mac address
3379 * @dev: Pointer to the net device.
3380 * @addr: Pointer to the sockaddr.
3381 *
3382 * This function sets the user specified mac address using
Jeff Johnson06095fb2018-05-06 16:16:42 -07003383 * the command ifconfig wlanX hw ether <mac address>.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003384 *
3385 * Return: 0 for success, non zero for failure
3386 */
3387static int __hdd_set_mac_address(struct net_device *dev, void *addr)
3388{
Jeff Johnson9d295242017-08-29 14:39:48 -07003389 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Ashish Kumar Dhanotiyae533f6c2018-06-19 21:16:07 +05303390 struct hdd_adapter *adapter_temp;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003391 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003392 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303393 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003394 int ret;
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303395 struct qdf_mac_addr mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003396
Dustin Brownfdf17c12018-03-14 12:55:34 -07003397 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003398
Hanumanth Reddy Pothula5c7a7812018-03-09 12:55:32 +05303399 if (netif_running(dev)) {
3400 hdd_err("On iface up, set mac address change isn't supported");
3401 return -EBUSY;
3402 }
3403
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003404 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3405 ret = wlan_hdd_validate_context(hdd_ctx);
3406 if (0 != ret)
3407 return ret;
3408
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303409 qdf_mem_copy(&mac_addr, psta_mac_addr->sa_data, sizeof(mac_addr));
Ashish Kumar Dhanotiyae533f6c2018-06-19 21:16:07 +05303410 adapter_temp = hdd_get_adapter_by_macaddr(hdd_ctx, mac_addr.bytes);
3411 if (adapter_temp) {
3412 if (!qdf_str_cmp(adapter_temp->dev->name, dev->name))
3413 return 0;
3414 hdd_err("%s adapter exist with same address " MAC_ADDRESS_STR,
3415 adapter_temp->dev->name,
Ashish Kumar Dhanotiyaf974f332018-04-19 16:03:15 +05303416 MAC_ADDR_ARRAY(mac_addr.bytes));
3417 return -EINVAL;
3418 }
3419
Pragaspathi Thilagaraj84b72842018-09-19 22:06:57 +05303420 qdf_ret_status = wlan_hdd_validate_mac_address(&mac_addr);
3421 if (QDF_IS_STATUS_ERROR(qdf_ret_status))
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303422 return -EINVAL;
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303423
Ashish Kumar Dhanotiya8bfef122018-04-18 16:48:27 +05303424 hdd_info("Changing MAC to " MAC_ADDRESS_STR " of the interface %s ",
3425 MAC_ADDR_ARRAY(mac_addr.bytes), dev->name);
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303426
Ashish Kumar Dhanotiya6784b502018-10-17 12:51:10 +05303427 hdd_update_dynamic_mac(hdd_ctx, &adapter->mac_addr, &mac_addr);
Jeff Johnson1e851a12017-10-28 14:36:12 -07003428 memcpy(&adapter->mac_addr, psta_mac_addr->sa_data, ETH_ALEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003429 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
3430
Dustin Browne74003f2018-03-14 12:51:58 -07003431 hdd_exit();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303432 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003433}
3434
3435/**
3436 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
Dustin Brown98f7c822019-03-06 12:25:49 -08003437 * function from SSR
3438 * @net_dev: pointer to net_device structure
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003439 * @addr: Pointer to the sockaddr
3440 *
3441 * This function sets the user specified mac address using
Jeff Johnson06095fb2018-05-06 16:16:42 -07003442 * the command ifconfig wlanX hw ether <mac address>.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003443 *
3444 * Return: 0 for success.
3445 */
Dustin Brown98f7c822019-03-06 12:25:49 -08003446static int hdd_set_mac_address(struct net_device *net_dev, void *addr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003447{
Dustin Brown98f7c822019-03-06 12:25:49 -08003448 struct osif_vdev_sync *vdev_sync;
3449 int errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003450
Dustin Brown98f7c822019-03-06 12:25:49 -08003451 errno = osif_vdev_sync_op_start(net_dev, &vdev_sync);
3452 if (errno)
3453 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003454
Dustin Brown98f7c822019-03-06 12:25:49 -08003455 errno = __hdd_set_mac_address(net_dev, addr);
3456
3457 osif_vdev_sync_op_stop(vdev_sync);
3458
3459 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003460}
3461
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303462static uint8_t *wlan_hdd_get_derived_intf_addr(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003463{
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303464 int i, j;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003465
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303466 i = qdf_ffz(hdd_ctx->derived_intf_addr_mask);
3467 if (i < 0 || i >= hdd_ctx->num_derived_addr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003468 return NULL;
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303469 qdf_atomic_set_bit(i, &hdd_ctx->derived_intf_addr_mask);
3470 hdd_info("Assigning MAC from derived list" MAC_ADDRESS_STR,
3471 MAC_ADDR_ARRAY(hdd_ctx->derived_mac_addr[i].bytes));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003472
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303473 /* Copy the mac in dynamic mac list at first free position */
3474 for (j = 0; j < QDF_MAX_CONCURRENCY_PERSONA; j++) {
3475 if (qdf_is_macaddr_zero(&hdd_ctx->
3476 dynamic_mac_list[j].dynamic_mac))
3477 break;
3478 }
3479 if (j == QDF_MAX_CONCURRENCY_PERSONA) {
3480 hdd_err("Max interfaces are up");
3481 return NULL;
3482 }
Dustin Brown61cc3932018-10-18 16:12:13 -07003483
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303484 qdf_mem_copy(&hdd_ctx->dynamic_mac_list[j].dynamic_mac.bytes,
3485 &hdd_ctx->derived_mac_addr[i].bytes,
Ashish Kumar Dhanotiya6784b502018-10-17 12:51:10 +05303486 sizeof(struct qdf_mac_addr));
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303487 hdd_ctx->dynamic_mac_list[j].is_provisioned_mac = false;
3488 hdd_ctx->dynamic_mac_list[j].bit_position = i;
3489
3490 return hdd_ctx->derived_mac_addr[i].bytes;
3491}
3492
3493static uint8_t *wlan_hdd_get_provisioned_intf_addr(struct hdd_context *hdd_ctx)
3494{
3495 int i, j;
3496
3497 i = qdf_ffz(hdd_ctx->provisioned_intf_addr_mask);
3498 if (i < 0 || i >= hdd_ctx->num_provisioned_addr)
3499 return NULL;
3500 qdf_atomic_set_bit(i, &hdd_ctx->provisioned_intf_addr_mask);
3501 hdd_info("Assigning MAC from provisioned list" MAC_ADDRESS_STR,
3502 MAC_ADDR_ARRAY(hdd_ctx->provisioned_mac_addr[i].bytes));
3503
3504 /* Copy the mac in dynamic mac list at first free position */
3505 for (j = 0; j < QDF_MAX_CONCURRENCY_PERSONA; j++) {
3506 if (qdf_is_macaddr_zero(&hdd_ctx->
3507 dynamic_mac_list[j].dynamic_mac))
3508 break;
3509 }
3510 if (j == QDF_MAX_CONCURRENCY_PERSONA) {
3511 hdd_err("Max interfaces are up");
3512 return NULL;
3513 }
3514
3515 qdf_mem_copy(&hdd_ctx->dynamic_mac_list[j].dynamic_mac.bytes,
3516 &hdd_ctx->provisioned_mac_addr[i].bytes,
3517 sizeof(struct qdf_mac_addr));
3518 hdd_ctx->dynamic_mac_list[j].is_provisioned_mac = true;
3519 hdd_ctx->dynamic_mac_list[j].bit_position = i;
3520 return hdd_ctx->provisioned_mac_addr[i].bytes;
3521}
3522
3523uint8_t *wlan_hdd_get_intf_addr(struct hdd_context *hdd_ctx,
3524 enum QDF_OPMODE interface_type)
3525{
3526 uint8_t *mac_addr = NULL;
3527
3528 if (qdf_atomic_test_bit(interface_type,
3529 (unsigned long *)
3530 (&hdd_ctx->config->provisioned_intf_pool)))
3531 mac_addr = wlan_hdd_get_provisioned_intf_addr(hdd_ctx);
3532
3533 if ((!mac_addr) &&
3534 (qdf_atomic_test_bit(interface_type,
3535 (unsigned long *)
3536 (&hdd_ctx->config->derived_intf_pool))))
3537 mac_addr = wlan_hdd_get_derived_intf_addr(hdd_ctx);
3538
3539 if (!mac_addr)
3540 hdd_err("MAC is not available in both the lists");
3541 return mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003542}
3543
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07003544void wlan_hdd_release_intf_addr(struct hdd_context *hdd_ctx,
3545 uint8_t *releaseAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003546{
3547 int i;
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303548 int mac_pos_in_mask;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003549
Anurag Chouhan6d760662016-02-20 16:05:43 +05303550 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003551 if (!memcmp(releaseAddr,
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303552 hdd_ctx->dynamic_mac_list[i].dynamic_mac.bytes,
3553 QDF_MAC_ADDR_SIZE)) {
3554 mac_pos_in_mask =
3555 hdd_ctx->dynamic_mac_list[i].bit_position;
3556 if (hdd_ctx->dynamic_mac_list[i].is_provisioned_mac) {
3557 qdf_atomic_clear_bit(
3558 mac_pos_in_mask,
3559 &hdd_ctx->
3560 provisioned_intf_addr_mask);
3561 hdd_info("Releasing MAC from provisioned list");
3562 hdd_info(
3563 MAC_ADDRESS_STR,
3564 MAC_ADDR_ARRAY(releaseAddr));
3565 } else {
3566 qdf_atomic_clear_bit(
3567 mac_pos_in_mask, &hdd_ctx->
3568 derived_intf_addr_mask);
3569 hdd_info("Releasing MAC from derived list");
3570 hdd_info(MAC_ADDRESS_STR,
3571 MAC_ADDR_ARRAY(releaseAddr));
3572 }
3573 qdf_zero_macaddr(&hdd_ctx->
3574 dynamic_mac_list[i].dynamic_mac);
3575 hdd_ctx->dynamic_mac_list[i].is_provisioned_mac =
3576 false;
3577 hdd_ctx->dynamic_mac_list[i].bit_position = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003578 break;
3579 }
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303580
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003581 }
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303582 if (i == QDF_MAX_CONCURRENCY_PERSONA)
3583 hdd_err("Releasing non existing MAC" MAC_ADDRESS_STR,
3584 MAC_ADDR_ARRAY(releaseAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003585}
3586
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003587/**
3588 * __hdd_set_multicast_list() - set the multicast address list
3589 * @dev: Pointer to the WLAN device.
3590 * @skb: Pointer to OS packet (sk_buff).
3591 *
3592 * This funciton sets the multicast address list.
3593 *
3594 * Return: None
3595 */
3596static void __hdd_set_multicast_list(struct net_device *dev)
3597{
Jeff Johnson9d295242017-08-29 14:39:48 -07003598 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Dustin Brown0f874482018-06-13 14:39:22 -07003599 int i = 0, errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003600 struct netdev_hw_addr *ha;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003601 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303602 struct pmo_mc_addr_list_params *mc_list_request = NULL;
Dustin Brown1dbefe62018-09-11 16:32:03 -07003603 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303604 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003605
Dustin Brownfdf17c12018-03-14 12:55:34 -07003606 hdd_enter_dev(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05303607 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303608 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05303609
Dustin Brown0f874482018-06-13 14:39:22 -07003610 errno = wlan_hdd_validate_context(hdd_ctx);
3611 if (errno)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303612 goto out;
3613
Dustin Brown0f874482018-06-13 14:39:22 -07003614 errno = hdd_validate_adapter(adapter);
3615 if (errno)
Dustin Brownc788acb2017-08-01 17:43:51 -07003616 goto out;
3617
Arunk Khandavalli6a227882017-12-12 19:31:08 +05303618 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
3619 hdd_err("%s: Driver module is closed", __func__);
Dustin Brown0f874482018-06-13 14:39:22 -07003620 goto out;
Arunk Khandavalli6a227882017-12-12 19:31:08 +05303621 }
3622
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303623 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
Min Liu74a1a502018-10-10 19:59:07 +08003624 if (!mc_list_request)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303625 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003626
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05303627 /* Delete already configured multicast address list */
3628 if (adapter->mc_addr_list.mc_cnt > 0) {
Dustin Brown0f874482018-06-13 14:39:22 -07003629 hdd_debug("clear previously configured MC address list");
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05303630 hdd_disable_and_flush_mc_addr_list(adapter,
3631 pmo_mc_list_change_notify);
3632 }
3633
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003634 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003635 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303636 hdd_disable_and_flush_mc_addr_list(adapter,
3637 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003638 } else {
3639 mc_count = netdev_mc_count(dev);
Wu Gaod7dd6e42018-10-16 17:22:56 +08003640 if (mc_count > ucfg_pmo_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003641 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Wu Gaod7dd6e42018-10-16 17:22:56 +08003642 ucfg_pmo_max_mc_addr_supported(psoc));
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303643 hdd_disable_and_flush_mc_addr_list(adapter,
3644 pmo_mc_list_change_notify);
stonezdf2bdfd2018-11-20 14:45:06 +08003645 adapter->mc_addr_list.mc_cnt = 0;
Dustin Brown0f874482018-06-13 14:39:22 -07003646 goto free_req;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003647 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003648 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003649 hdd_debug("ha_addr[%d] "MAC_ADDRESS_STR,
Sachin Ahujaa69c72a2016-09-03 15:59:33 +05303650 i, MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003651 if (i == mc_count)
3652 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303653 memset(&(mc_list_request->mc_addr[i].bytes),
3654 0, ETH_ALEN);
3655 memcpy(&(mc_list_request->mc_addr[i].bytes),
3656 ha->addr, ETH_ALEN);
Dustin Brown0f874482018-06-13 14:39:22 -07003657 hdd_debug("mlist[%d] = %pM", i,
3658 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003659 i++;
3660 }
3661 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303662
stonezdf2bdfd2018-11-20 14:45:06 +08003663 adapter->mc_addr_list.mc_cnt = mc_count;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303664 mc_list_request->psoc = psoc;
Jeff Johnson5a6fc962019-02-04 14:20:25 -08003665 mc_list_request->vdev_id = adapter->vdev_id;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303666 mc_list_request->count = mc_count;
Dustin Brown0f874482018-06-13 14:39:22 -07003667
3668 errno = hdd_cache_mc_addr_list(mc_list_request);
3669 if (errno) {
3670 hdd_err("Failed to cache MC address list for vdev %u; errno:%d",
Jeff Johnson5a6fc962019-02-04 14:20:25 -08003671 adapter->vdev_id, errno);
Dustin Brown0f874482018-06-13 14:39:22 -07003672 goto free_req;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003673 }
Dustin Brown0f874482018-06-13 14:39:22 -07003674
3675 hdd_enable_mc_addr_filtering(adapter, pmo_mc_list_change_notify);
3676
3677free_req:
3678 qdf_mem_free(mc_list_request);
3679
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303680out:
Dustin Browne74003f2018-03-14 12:51:58 -07003681 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003682}
3683
3684/**
3685 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
Dustin Brown98f7c822019-03-06 12:25:49 -08003686 * @net_dev: pointer to net_device
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003687 *
3688 * Return: none
3689 */
Dustin Brown98f7c822019-03-06 12:25:49 -08003690static void hdd_set_multicast_list(struct net_device *net_dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003691{
Dustin Brown98f7c822019-03-06 12:25:49 -08003692 struct osif_vdev_sync *vdev_sync;
3693
3694 if (osif_vdev_sync_op_start(net_dev, &vdev_sync))
3695 return;
3696
3697 __hdd_set_multicast_list(net_dev);
3698
3699 osif_vdev_sync_op_stop(vdev_sync);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003700}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003701
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003702static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003703 .ndo_open = hdd_open,
3704 .ndo_stop = hdd_stop,
3705 .ndo_uninit = hdd_uninit,
3706 .ndo_start_xmit = hdd_hard_start_xmit,
3707 .ndo_tx_timeout = hdd_tx_timeout,
3708 .ndo_get_stats = hdd_get_stats,
3709 .ndo_do_ioctl = hdd_ioctl,
3710 .ndo_set_mac_address = hdd_set_mac_address,
3711 .ndo_select_queue = hdd_select_queue,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003712 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003713};
3714
Nirav Shah73713f72018-05-17 14:50:41 +05303715#ifdef FEATURE_MONITOR_MODE_SUPPORT
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003716/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003717static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003718 .ndo_open = hdd_mon_open,
3719 .ndo_stop = hdd_stop,
3720 .ndo_get_stats = hdd_get_stats,
3721};
3722
3723/**
3724 * hdd_set_station_ops() - update net_device ops for monitor mode
Jeff Johnson5505db82017-11-02 21:19:23 -07003725 * @dev: Handle to struct net_device to be updated.
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003726 * Return: None
3727 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003728void hdd_set_station_ops(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003729{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003730 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
Jeff Johnson5505db82017-11-02 21:19:23 -07003731 dev->netdev_ops = &wlan_mon_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003732 else
Jeff Johnson5505db82017-11-02 21:19:23 -07003733 dev->netdev_ops = &wlan_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003734}
Nirav Shah73713f72018-05-17 14:50:41 +05303735#else
3736void hdd_set_station_ops(struct net_device *dev)
3737{
3738 dev->netdev_ops = &wlan_drv_ops;
3739}
3740#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003741
3742/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08003743 * hdd_alloc_station_adapter() - allocate the station hdd adapter
3744 * @hdd_ctx: global hdd context
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003745 * @mac_addr: mac address to assign to the interface
Ryan Hsu07495ea2016-01-21 15:25:39 -08003746 * @name: User-visible name of the interface
3747 *
3748 * hdd adapter pointer would point to the netdev->priv space, this function
Jeff Johnson62018292018-05-06 16:18:35 -07003749 * would retrieve the pointer, and setup the hdd adapter configuration.
Ryan Hsu07495ea2016-01-21 15:25:39 -08003750 *
3751 * Return: the pointer to hdd adapter, otherwise NULL
3752 */
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003753static struct hdd_adapter *
3754hdd_alloc_station_adapter(struct hdd_context *hdd_ctx, tSirMacAddr mac_addr,
3755 unsigned char name_assign_type, const char *name)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003756{
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003757 struct net_device *dev;
3758 struct hdd_adapter *adapter;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003759 struct hdd_station_ctx *sta_ctx;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303760 QDF_STATUS qdf_status;
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003761
3762 /* cfg80211 initialization and registration */
3763 dev = alloc_netdev_mq(sizeof(*adapter), name,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003764#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003765 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003766#endif
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003767 (cds_get_conparam() == QDF_GLOBAL_MONITOR_MODE ?
3768 hdd_mon_mode_ether_setup : ether_setup),
3769 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003770
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003771 if (!dev) {
3772 hdd_err("Failed to allocate new net_device '%s'", name);
3773 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003774 }
3775
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003776 adapter = netdev_priv(dev);
3777
3778 qdf_mem_zero(adapter, sizeof(*adapter));
3779 sta_ctx = &adapter->session.station;
Jeff Johnson0a082d92019-03-04 12:25:49 -08003780 qdf_mem_set(sta_ctx->conn_info.sta_id,
3781 sizeof(sta_ctx->conn_info.sta_id),
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003782 HDD_WLAN_INVALID_STA_ID);
3783 adapter->dev = dev;
3784 adapter->hdd_ctx = hdd_ctx;
3785 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Jeff Johnson912b1bb2019-03-06 10:12:36 -08003786 adapter->vdev_id = WLAN_UMAC_VDEV_ID_MAX;
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003787
3788 qdf_status = qdf_event_create(&adapter->qdf_session_open_event);
3789 if (QDF_IS_STATUS_ERROR(qdf_status))
3790 goto free_net_dev;
3791
3792 qdf_status = qdf_event_create(&adapter->qdf_session_close_event);
3793 if (QDF_IS_STATUS_ERROR(qdf_status))
3794 goto free_net_dev;
3795
3796 adapter->offloads_configured = false;
3797 adapter->is_link_up_service_needed = false;
3798 adapter->disconnection_in_progress = false;
3799 adapter->send_mode_change = true;
3800
3801 /* Init the net_device structure */
3802 strlcpy(dev->name, name, IFNAMSIZ);
3803
3804 qdf_mem_copy(dev->dev_addr, mac_addr, sizeof(tSirMacAddr));
3805 qdf_mem_copy(adapter->mac_addr.bytes, mac_addr, sizeof(tSirMacAddr));
3806 dev->watchdog_timeo = HDD_TX_TIMEOUT;
3807
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003808 hdd_set_station_ops(adapter->dev);
3809
3810 hdd_dev_setup_destructor(dev);
3811 dev->ieee80211_ptr = &adapter->wdev;
3812 dev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
3813 adapter->wdev.wiphy = hdd_ctx->wiphy;
3814 adapter->wdev.netdev = dev;
3815
3816 /* set dev's parent to underlying device */
3817 SET_NETDEV_DEV(dev, hdd_ctx->parent_dev);
3818 hdd_wmm_init(adapter);
3819 spin_lock_init(&adapter->pause_map_lock);
3820 adapter->start_time = qdf_system_ticks();
3821 adapter->last_time = adapter->start_time;
3822
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003823 return adapter;
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003824
3825free_net_dev:
3826 free_netdev(adapter->dev);
3827
3828 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003829}
3830
Jeff Johnson9d295242017-08-29 14:39:48 -07003831static QDF_STATUS hdd_register_interface(struct hdd_adapter *adapter, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003832{
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003833 struct net_device *dev = adapter->dev;
3834 int ret;
3835
Dustin Brown491d54b2018-03-14 12:39:11 -07003836 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003837
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003838 if (rtnl_held) {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003839 if (strnchr(dev->name, IFNAMSIZ - 1, '%')) {
3840
3841 ret = dev_alloc_name(dev, dev->name);
3842 if (ret < 0) {
3843 hdd_err(
3844 "unable to get dev name: %s, err = 0x%x",
3845 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303846 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003847 }
3848 }
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003849
3850 ret = register_netdevice(dev);
3851 if (ret) {
3852 hdd_err("register_netdevice(%s) failed, err = 0x%x",
3853 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303854 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003855 }
3856 } else {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003857 ret = register_netdev(dev);
3858 if (ret) {
3859 hdd_err("register_netdev(%s) failed, err = 0x%x",
3860 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303861 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003862 }
3863 }
3864 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
3865
Dustin Browne74003f2018-03-14 12:51:58 -07003866 hdd_exit();
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003867
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303868 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003869}
3870
Jeff Johnson55d2ab42019-03-06 11:43:49 -08003871QDF_STATUS hdd_sme_open_session_callback(uint8_t vdev_id,
Pragaspathi Thilagaraj3551caa2018-09-26 15:52:56 +05303872 QDF_STATUS qdf_status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003873{
Krunal Sonib51eec72017-11-20 21:53:01 -08003874 struct hdd_adapter *adapter;
3875 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003876
Krunal Sonib51eec72017-11-20 21:53:01 -08003877 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3878 if (!hdd_ctx) {
3879 hdd_err("Invalid HDD_CTX");
3880 return QDF_STATUS_E_FAILURE;
3881 }
3882
Jeff Johnson55d2ab42019-03-06 11:43:49 -08003883 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
Jeff Johnsond36fa332019-03-18 13:42:25 -07003884 if (!adapter) {
Jeff Johnson55d2ab42019-03-06 11:43:49 -08003885 hdd_err("NULL adapter for %d", vdev_id);
Krunal Sonib51eec72017-11-20 21:53:01 -08003886 return QDF_STATUS_E_INVAL;
3887 }
Pragaspathi Thilagaraj3551caa2018-09-26 15:52:56 +05303888
3889 if (qdf_status == QDF_STATUS_SUCCESS)
3890 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
3891
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303892 qdf_event_set(&adapter->qdf_session_open_event);
Jeff Johnson5a6fc962019-02-04 14:20:25 -08003893 hdd_debug("session %d opened", adapter->vdev_id);
Krunal Sonib51eec72017-11-20 21:53:01 -08003894
3895 return QDF_STATUS_SUCCESS;
3896}
3897
Jeff Johnson55d2ab42019-03-06 11:43:49 -08003898QDF_STATUS hdd_sme_close_session_callback(uint8_t vdev_id)
Krunal Sonib51eec72017-11-20 21:53:01 -08003899{
3900 struct hdd_adapter *adapter;
3901 struct hdd_context *hdd_ctx;
3902
3903 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3904 if (!hdd_ctx) {
3905 hdd_err("Invalid HDD_CTX");
3906 return QDF_STATUS_E_FAILURE;
3907 }
3908
Jeff Johnson55d2ab42019-03-06 11:43:49 -08003909 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
Jeff Johnsond36fa332019-03-18 13:42:25 -07003910 if (!adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003911 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303912 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003913 }
3914
3915 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003916 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303917 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003918 }
3919
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003920 /*
3921 * For NAN Data interface, the close session results in the final
3922 * indication to the userspace
3923 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07003924 if (adapter->device_mode == QDF_NDI_MODE)
3925 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003926
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003927 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3928
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003929 /*
3930 * We can be blocked while waiting for scheduled work to be
3931 * flushed, and the adapter structure can potentially be freed, in
3932 * which case the magic will have been reset. So make sure the
3933 * magic is still good, and hence the adapter structure is still
3934 * valid, before signaling completion
3935 */
3936 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303937 qdf_event_set(&adapter->qdf_session_close_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003938
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303939 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003940}
3941
Jeff Johnson9d295242017-08-29 14:39:48 -07003942int hdd_vdev_ready(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003943{
Min Liu8c5d99e2018-09-10 17:18:44 +08003944 struct wlan_objmgr_vdev *vdev;
Dustin Brownd28772b2017-03-17 14:16:07 -07003945 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003946
Min Liu8c5d99e2018-09-10 17:18:44 +08003947 vdev = hdd_objmgr_get_vdev(adapter);
3948 if (!vdev)
3949 return -EINVAL;
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003950
Min Liu8c5d99e2018-09-10 17:18:44 +08003951 status = pmo_vdev_ready(vdev);
3952 if (QDF_IS_STATUS_ERROR(status)) {
Rajeev Kumar Sirasanagandla25bdfad2019-02-15 19:15:49 +05303953 hdd_objmgr_put_vdev(vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003954 return qdf_status_to_os_return(status);
Min Liu8c5d99e2018-09-10 17:18:44 +08003955 }
3956
3957 status = ucfg_reg_11d_vdev_created_update(vdev);
3958 if (QDF_IS_STATUS_ERROR(status)) {
Rajeev Kumar Sirasanagandla25bdfad2019-02-15 19:15:49 +05303959 hdd_objmgr_put_vdev(vdev);
Min Liu8c5d99e2018-09-10 17:18:44 +08003960 return qdf_status_to_os_return(status);
3961 }
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003962
3963 if (wma_capability_enhanced_mcast_filter())
Min Liu8c5d99e2018-09-10 17:18:44 +08003964 status = ucfg_pmo_enhanced_mc_filter_enable(vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003965 else
Min Liu8c5d99e2018-09-10 17:18:44 +08003966 status = ucfg_pmo_enhanced_mc_filter_disable(vdev);
3967
Rajeev Kumar Sirasanagandla25bdfad2019-02-15 19:15:49 +05303968 hdd_objmgr_put_vdev(vdev);
Dustin Brownd28772b2017-03-17 14:16:07 -07003969
3970 return qdf_status_to_os_return(status);
3971}
3972
Jeff Johnson9d295242017-08-29 14:39:48 -07003973int hdd_vdev_destroy(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003974{
3975 QDF_STATUS status;
Dustin Brown2da29eb2018-07-13 14:23:12 -07003976 int errno;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003977 struct hdd_context *hdd_ctx;
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003978 uint8_t vdev_id;
Min Liu8c5d99e2018-09-10 17:18:44 +08003979 struct wlan_objmgr_vdev *vdev;
Dustin Brownd28772b2017-03-17 14:16:07 -07003980
Jeff Johnson5a6fc962019-02-04 14:20:25 -08003981 vdev_id = adapter->vdev_id;
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003982 hdd_info("destroying vdev %d", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003983
3984 /* vdev created sanity check */
3985 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Dustin Brown2da29eb2018-07-13 14:23:12 -07003986 hdd_err("vdev %u does not exist", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003987 return -EINVAL;
3988 }
Dustin Brown2da29eb2018-07-13 14:23:12 -07003989
Abhishek Singh628bb6f2019-03-26 14:52:40 +05303990 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3991
3992 /*
3993 * if this is the last active connection check & stop the
3994 * opportunistic timer first
3995 */
3996 if ((policy_mgr_get_connection_count(hdd_ctx->psoc) == 1 &&
3997 policy_mgr_mode_specific_connection_count(hdd_ctx->psoc,
3998 policy_mgr_convert_device_mode_to_qdf_type(
3999 adapter->device_mode), NULL) == 1) ||
4000 !policy_mgr_get_connection_count(hdd_ctx->psoc))
4001 policy_mgr_check_and_stop_opportunistic_timer(hdd_ctx->psoc,
4002 adapter->vdev_id);
4003
Min Liu8c5d99e2018-09-10 17:18:44 +08004004 vdev = hdd_objmgr_get_vdev(adapter);
4005 if (!vdev)
4006 return -EINVAL;
Ashish Kumar Dhanotiya68ee2e42018-11-19 21:15:14 +05304007
4008 ucfg_pmo_del_wow_pattern(vdev);
Min Liu8c5d99e2018-09-10 17:18:44 +08004009 status = ucfg_reg_11d_vdev_delete_update(vdev);
Abhishek Singh935e4772018-11-21 14:14:10 +05304010 ucfg_scan_vdev_set_disable(vdev, REASON_VDEV_DOWN);
Rajeev Kumar Sirasanagandla25bdfad2019-02-15 19:15:49 +05304011 hdd_objmgr_put_vdev(vdev);
Yue Maf9782842017-05-08 12:49:49 -07004012
Dustin Brownd28772b2017-03-17 14:16:07 -07004013 /* close sme session (destroy vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304014 qdf_event_reset(&adapter->qdf_session_close_event);
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004015 status = sme_close_session(hdd_ctx->mac_handle, adapter->vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004016 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Brown2da29eb2018-07-13 14:23:12 -07004017 hdd_err("failed to close sme session; status:%d", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08004018 goto release_vdev;
Dustin Brownd28772b2017-03-17 14:16:07 -07004019 }
4020
4021 /* block on a completion variable until sme session is closed */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304022 status = qdf_wait_for_event_completion(
4023 &adapter->qdf_session_close_event,
Abhishek Singh13bf0ce2018-10-24 14:26:14 +05304024 SME_CMD_VDEV_CREATE_DELETE_TIMEOUT);
Dustin Brown2da29eb2018-07-13 14:23:12 -07004025
4026 if (QDF_IS_STATUS_ERROR(status)) {
4027 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
4028
Dustin Brownd28772b2017-03-17 14:16:07 -07004029 if (adapter->device_mode == QDF_NDI_MODE)
4030 hdd_ndp_session_end_handler(adapter);
Dustin Brown2da29eb2018-07-13 14:23:12 -07004031
4032 if (status == QDF_STATUS_E_TIMEOUT)
4033 hdd_err("timed out waiting for sme close session");
4034 else if (adapter->qdf_session_close_event.force_set)
4035 hdd_info("SSR occurred during sme close session");
4036 else
4037 hdd_err("failed to wait for sme close session; status:%u",
4038 status);
Dustin Brownd28772b2017-03-17 14:16:07 -07004039 }
Jiachao Wu2c42c222018-01-15 18:13:19 +08004040
Yue Maf9782842017-05-08 12:49:49 -07004041release_vdev:
Jiachao Wu2c42c222018-01-15 18:13:19 +08004042
Sandeep Puligillaef415362017-08-30 16:37:13 -07004043 /* do vdev logical destroy via objmgr */
Dustin Brownb277dd62018-01-26 15:17:33 -08004044 errno = hdd_objmgr_release_and_destroy_vdev(adapter);
Sandeep Puligillaef415362017-08-30 16:37:13 -07004045 if (errno) {
Dustin Brownb277dd62018-01-26 15:17:33 -08004046 hdd_err("failed to destroy objmgr vdev; errno:%d", errno);
Sandeep Puligillaef415362017-08-30 16:37:13 -07004047 return errno;
4048 }
4049
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08004050 hdd_info("vdev %d destroyed successfully", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004051
4052 return 0;
4053}
4054
Krunal Sonib51eec72017-11-20 21:53:01 -08004055static int hdd_set_sme_session_param(struct hdd_adapter *adapter,
4056 struct sme_session_params *session_param,
Jeff Johnson6a18c962018-07-01 09:09:37 -07004057 csr_roam_complete_cb callback,
Krunal Sonib51eec72017-11-20 21:53:01 -08004058 void *callback_ctx)
Dustin Brownd28772b2017-03-17 14:16:07 -07004059{
Dustin Brownd28772b2017-03-17 14:16:07 -07004060 uint32_t type;
4061 uint32_t sub_type;
Krunal Sonib51eec72017-11-20 21:53:01 -08004062 QDF_STATUS status;
Dustin Brownd28772b2017-03-17 14:16:07 -07004063
4064 /* determine vdev (sub)type */
4065 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304066 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07004067 hdd_err("failed to get vdev type: %d", status);
4068 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004069 }
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004070 session_param->sme_session_id = adapter->vdev_id;
Krunal Sonib51eec72017-11-20 21:53:01 -08004071 session_param->self_mac_addr = (uint8_t *)&adapter->mac_addr;
4072 session_param->type_of_persona = type;
4073 session_param->subtype_of_persona = sub_type;
4074 session_param->session_open_cb = hdd_sme_open_session_callback;
4075 session_param->session_close_cb = hdd_sme_close_session_callback;
4076 session_param->callback = callback;
4077 session_param->callback_ctx = callback_ctx;
4078
4079 return 0;
4080}
4081
gaurank kathpalia6c4b50c2019-02-28 14:07:48 +05304082void
gaurank kathpalia78af1932018-10-27 20:33:10 +05304083hdd_store_nss_chains_cfg_in_vdev(struct hdd_adapter *adapter)
4084{
4085 struct wlan_mlme_nss_chains vdev_ini_cfg;
4086 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
4087
gaurank kathpaliab414bce2018-11-09 18:44:46 +05304088 /* Populate the nss chain params from ini for this vdev type */
gaurank kathpalia78af1932018-10-27 20:33:10 +05304089 sme_populate_nss_chain_params(hdd_ctx->mac_handle, &vdev_ini_cfg,
4090 adapter->device_mode,
4091 hdd_ctx->num_rf_chains);
gaurank kathpaliab414bce2018-11-09 18:44:46 +05304092
4093 /* Store the nss chain config into the vdev */
4094 sme_store_nss_chains_cfg_in_vdev(adapter->vdev, &vdev_ini_cfg);
gaurank kathpalia78af1932018-10-27 20:33:10 +05304095}
gaurank kathpalia6982d472018-10-31 21:54:15 +05304096
4097bool hdd_is_vdev_in_conn_state(struct hdd_adapter *adapter)
4098{
4099 switch (adapter->device_mode) {
4100 case QDF_STA_MODE:
4101 case QDF_P2P_CLIENT_MODE:
4102 case QDF_P2P_DEVICE_MODE:
4103 return hdd_conn_is_connected(
4104 WLAN_HDD_GET_STATION_CTX_PTR(adapter));
4105 case QDF_SAP_MODE:
4106 case QDF_P2P_GO_MODE:
4107 return (test_bit(SOFTAP_BSS_STARTED,
4108 &adapter->event_flags));
4109 default:
4110 hdd_err("Device mode %d invalid", adapter->device_mode);
4111 return 0;
4112 }
4113
4114 return 0;
4115}
4116
Krunal Sonib51eec72017-11-20 21:53:01 -08004117int hdd_vdev_create(struct hdd_adapter *adapter,
Jeff Johnson6a18c962018-07-01 09:09:37 -07004118 csr_roam_complete_cb callback, void *ctx)
Krunal Sonib51eec72017-11-20 21:53:01 -08004119{
4120 QDF_STATUS status;
4121 int errno;
Karthik Kantamneni9180c752018-11-14 12:14:17 +05304122 bool bval;
Krunal Sonib51eec72017-11-20 21:53:01 -08004123 struct hdd_context *hdd_ctx;
4124 struct sme_session_params sme_session_params = {0};
Min Liu8c5d99e2018-09-10 17:18:44 +08004125 struct wlan_objmgr_vdev *vdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004126
4127 hdd_info("creating new vdev");
Dustin Brownd28772b2017-03-17 14:16:07 -07004128
4129 /* do vdev create via objmgr */
4130 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown07901ec2018-09-07 11:02:41 -07004131 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07004132 if (errno) {
4133 hdd_err("failed to create objmgr vdev: %d", errno);
4134 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004135 }
Dustin Brownd28772b2017-03-17 14:16:07 -07004136
4137 /* Open a SME session (prepare vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304138 status = qdf_event_reset(&adapter->qdf_session_open_event);
4139 if (QDF_STATUS_SUCCESS != status) {
4140 hdd_err("failed to reinit session open event");
4141 return -EINVAL;
4142 }
Krunal Sonib51eec72017-11-20 21:53:01 -08004143 errno = hdd_set_sme_session_param(adapter, &sme_session_params,
4144 callback, ctx);
4145 if (errno) {
4146 hdd_err("failed to populating SME params");
4147 goto objmgr_vdev_destroy_procedure;
4148 }
Jeff Johnson16528362018-06-14 12:34:16 -07004149 status = sme_open_session(hdd_ctx->mac_handle, &sme_session_params);
Dustin Brownd28772b2017-03-17 14:16:07 -07004150 if (QDF_IS_STATUS_ERROR(status)) {
4151 hdd_err("failed to open sme session: %d", status);
4152 errno = qdf_status_to_os_return(status);
Krunal Soni4a020c72017-10-30 20:58:40 -07004153 goto objmgr_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07004154 }
4155
4156 /* block on a completion variable until sme session is opened */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304157 status = qdf_wait_for_event_completion(&adapter->qdf_session_open_event,
Abhishek Singh13bf0ce2018-10-24 14:26:14 +05304158 SME_CMD_VDEV_CREATE_DELETE_TIMEOUT);
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304159 if (QDF_STATUS_SUCCESS != status) {
4160 if (adapter->qdf_session_open_event.force_set) {
4161 /*
4162 * SSR/PDR has caused shutdown, which has forcefully
4163 * set the event. Return without the closing session.
4164 */
Jeff Johnson912b1bb2019-03-06 10:12:36 -08004165 adapter->vdev_id = WLAN_UMAC_VDEV_ID_MAX;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304166 hdd_err("Session open event forcefully set");
4167 return -EINVAL;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304168 }
Jeff Johnsonc66d3102018-02-28 11:58:26 -08004169
4170 if (QDF_STATUS_E_TIMEOUT == status)
4171 hdd_err("Session failed to open within timeout period");
4172 else
4173 hdd_err("Failed to wait for session open event(status-%d)",
4174 status);
4175 errno = -ETIMEDOUT;
4176 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
4177 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07004178 }
4179
Pragaspathi Thilagaraj3551caa2018-09-26 15:52:56 +05304180 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
4181 hdd_err("Session failed to open due to vdev create failure");
4182 errno = -EINVAL;
4183 goto objmgr_vdev_destroy_procedure;
4184 }
4185
Dustin Brownd28772b2017-03-17 14:16:07 -07004186 /* firmware ready for component communication, raise vdev_ready event */
4187 errno = hdd_vdev_ready(adapter);
4188 if (errno) {
4189 hdd_err("failed to dispatch vdev ready event: %d", errno);
Krunal Soni4a020c72017-10-30 20:58:40 -07004190 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07004191 }
4192
Naveen Rawat2b430892018-03-13 13:58:18 -07004193 if (adapter->device_mode == QDF_STA_MODE) {
Karthik Kantamneni9180c752018-11-14 12:14:17 +05304194 bval = false;
4195 status = ucfg_mlme_get_rtt_mac_randomization(hdd_ctx->psoc,
4196 &bval);
4197 if (QDF_IS_STATUS_ERROR(status))
4198 hdd_err("unable to get RTT MAC randomization value");
4199
4200 hdd_debug("setting RTT mac randomization param: %d", bval);
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004201 errno = sme_cli_set_command(adapter->vdev_id,
Naveen Rawat2b430892018-03-13 13:58:18 -07004202 WMI_VDEV_PARAM_ENABLE_DISABLE_RTT_INITIATOR_RANDOM_MAC,
Karthik Kantamneni9180c752018-11-14 12:14:17 +05304203 bval,
Naveen Rawat2b430892018-03-13 13:58:18 -07004204 VDEV_CMD);
4205 if (0 != errno)
4206 hdd_err("RTT mac randomization param set failed %d",
4207 errno);
4208 }
4209
Bala Venkatesh110b03e2018-07-10 16:02:08 +05304210 if (adapter->device_mode == QDF_STA_MODE ||
Min Liu8c5d99e2018-09-10 17:18:44 +08004211 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
4212 vdev = hdd_objmgr_get_vdev(adapter);
4213 if (!vdev)
4214 goto hdd_vdev_destroy_procedure;
4215 wlan_vdev_set_max_peer_count(vdev, HDD_MAX_VDEV_PEER_COUNT);
Rajeev Kumar Sirasanagandla25bdfad2019-02-15 19:15:49 +05304216 hdd_objmgr_put_vdev(vdev);
Min Liu8c5d99e2018-09-10 17:18:44 +08004217 }
Bala Venkatesh110b03e2018-07-10 16:02:08 +05304218
gaurank kathpalia78af1932018-10-27 20:33:10 +05304219 hdd_store_nss_chains_cfg_in_vdev(adapter);
4220
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004221 hdd_info("vdev %d created successfully", adapter->vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004222
4223 return 0;
4224
4225 /*
4226 * Due to legacy constraints, we need to destroy in the same order as
4227 * create. So, split error handling into 2 cases to accommodate.
4228 */
4229
Krunal Soni4a020c72017-10-30 20:58:40 -07004230objmgr_vdev_destroy_procedure:
Dustin Brown7d043f62017-03-27 12:07:36 -07004231 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07004232
4233 return errno;
4234
Krunal Soni4a020c72017-10-30 20:58:40 -07004235hdd_vdev_destroy_procedure:
Dustin Brownd28772b2017-03-17 14:16:07 -07004236 QDF_BUG(!hdd_vdev_destroy(adapter));
4237
4238 return errno;
4239}
4240
Jeff Johnson9d295242017-08-29 14:39:48 -07004241QDF_STATUS hdd_init_station_mode(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07004242{
Jeff Johnsonb9424862017-10-30 08:49:35 -07004243 struct hdd_station_ctx *sta_ctx = &adapter->session.station;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004244 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07004245 QDF_STATUS status;
4246 int ret_val;
Jeff Johnson16528362018-06-14 12:34:16 -07004247 mac_handle_t mac_handle;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304248 bool bval = false;
Dustin Brownd28772b2017-03-17 14:16:07 -07004249
Dustin Brownd28772b2017-03-17 14:16:07 -07004250 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson16528362018-06-14 12:34:16 -07004251 mac_handle = hdd_ctx->mac_handle;
4252 sme_set_curr_device_mode(mac_handle, adapter->device_mode);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304253 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &bval);
4254 if (!QDF_IS_STATUS_SUCCESS(status))
4255 hdd_err("unable to get vht_enable2x2");
4256 sme_set_pdev_ht_vht_ies(mac_handle, bval);
4257
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004258 sme_set_vdev_ies_per_band(mac_handle, adapter->vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004259
Jeff Johnson7f2c5912018-03-23 11:42:28 -07004260 hdd_roam_profile_init(adapter);
4261 hdd_register_wext(adapter->dev);
4262
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07004263 hdd_conn_set_connection_state(adapter, eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004264
Jeff Johnson0a082d92019-03-04 12:25:49 -08004265 qdf_mem_set(sta_ctx->conn_info.sta_id,
4266 sizeof(sta_ctx->conn_info.sta_id),
4267 HDD_WLAN_INVALID_STA_ID);
Hanumanth Reddy Pothulab2d729c2017-05-30 11:49:53 +05304268
Deepak Dhamdherea2785822016-11-17 01:17:45 -08004269 /* set fast roaming capability in sme session */
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004270 status = sme_config_fast_roaming(mac_handle, adapter->vdev_id,
Abhishek Singh1f217ec2017-12-22 11:48:27 +05304271 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004272 /* Set the default operation channel */
Jeff Johnson8626e932019-02-27 18:35:22 -08004273 sta_ctx->conn_info.channel =
Vignesh Viswanathana0358ff2018-11-27 09:53:07 +05304274 hdd_ctx->config->operating_channel;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004275
4276 /* Make the default Auth Type as OPEN */
Jeff Johnson96e33512019-02-27 15:10:21 -08004277 sta_ctx->conn_info.auth_type = eCSR_AUTH_TYPE_OPEN_SYSTEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004278
4279 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304280 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004281 hdd_err("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004282 status, status);
4283 goto error_init_txrx;
4284 }
4285
4286 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4287
4288 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304289 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004290 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004291 status, status);
4292 goto error_wmm_init;
4293 }
4294
4295 set_bit(WMM_INIT_DONE, &adapter->event_flags);
4296
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004297 ret_val = sme_cli_set_command(adapter->vdev_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004298 WMI_PDEV_PARAM_BURST_ENABLE,
Dundi Raviteja3aa01be2018-05-21 18:58:59 +05304299 HDD_ENABLE_SIFS_BURST_DEFAULT,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004300 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07004301 if (ret_val)
4302 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004303
Poddar, Siddarth4b3f7312017-11-02 17:00:20 +05304304 /*
4305 * In case of USB tethering, LRO is disabled. If SSR happened
4306 * during that time, then as part of SSR init, do not enable
4307 * the LRO again. Keep the LRO state same as before SSR.
4308 */
jitiphil377bcc12018-10-05 19:46:08 +05304309 if (cdp_cfg_get(cds_get_context(QDF_MODULE_ID_SOC),
4310 cfg_dp_lro_enable) &&
4311 !(qdf_atomic_read(&hdd_ctx->vendor_disable_lro_flag)))
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -07004312 adapter->dev->features |= NETIF_F_LRO;
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05304313
Rakshith Suresh Patkar9f5c5862019-02-04 16:23:02 +05304314 if (cdp_cfg_get(cds_get_context(QDF_MODULE_ID_SOC),
4315 cfg_dp_enable_ip_tcp_udp_checksum_offload))
4316 adapter->dev->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
4317 adapter->dev->features |= NETIF_F_RXCSUM;
4318
4319 hdd_set_tso_flags(hdd_ctx, adapter->dev);
4320
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05304321 /* rcpi info initialization */
4322 qdf_mem_zero(&adapter->rcpi, sizeof(adapter->rcpi));
4323
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304324 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004325
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004326error_wmm_init:
4327 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4328 hdd_deinit_tx_rx(adapter);
4329error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07004330 hdd_unregister_wext(adapter->dev);
Dustin Brownd28772b2017-03-17 14:16:07 -07004331 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004332
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004333 return status;
4334}
4335
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304336/**
Krunal Soni4a020c72017-10-30 20:58:40 -07004337 * hdd_deinit_station_mode() - De-initialize the station adapter
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304338 * @hdd_ctx: global hdd context
4339 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07004340 * @rtnl_held: Used to indicate whether or not the caller is holding
4341 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304342 *
4343 * This function De-initializes the STA/P2P/OCB adapter.
4344 *
4345 * Return: None.
4346 */
Krunal Soni4a020c72017-10-30 20:58:40 -07004347static void hdd_deinit_station_mode(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004348 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07004349 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304350{
Dustin Brownfdf17c12018-03-14 12:55:34 -07004351 hdd_enter_dev(adapter->dev);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304352
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05304353 if (adapter->dev) {
4354 if (rtnl_held)
4355 adapter->dev->wireless_handlers = NULL;
4356 else {
4357 rtnl_lock();
4358 adapter->dev->wireless_handlers = NULL;
4359 rtnl_unlock();
4360 }
4361 }
4362
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304363 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
4364 hdd_deinit_tx_rx(adapter);
4365 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4366 }
4367
4368 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
4369 hdd_wmm_adapter_close(adapter);
4370 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
4371 }
4372
Krunal Sonib51eec72017-11-20 21:53:01 -08004373
Dustin Browne74003f2018-03-14 12:51:58 -07004374 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304375}
4376
Krunal Sonib51eec72017-11-20 21:53:01 -08004377void hdd_deinit_adapter(struct hdd_context *hdd_ctx,
4378 struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004379 bool rtnl_held)
4380{
Dustin Brown491d54b2018-03-14 12:39:11 -07004381 hdd_enter();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304382
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004383 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004384 case QDF_STA_MODE:
4385 case QDF_P2P_CLIENT_MODE:
4386 case QDF_P2P_DEVICE_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08004387 case QDF_IBSS_MODE:
4388 case QDF_NDI_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004389 {
Krunal Soni4a020c72017-10-30 20:58:40 -07004390 hdd_deinit_station_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004391 break;
4392 }
4393
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004394 case QDF_SAP_MODE:
4395 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004396 {
Krunal Soni4a020c72017-10-30 20:58:40 -07004397 hdd_deinit_ap_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004398 break;
4399 }
4400
4401 default:
4402 break;
4403 }
4404
Dustin Browne74003f2018-03-14 12:51:58 -07004405 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004406}
4407
Min Liu8c5d99e2018-09-10 17:18:44 +08004408static void hdd_cleanup_adapter(struct hdd_context *hdd_ctx,
4409 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07004410 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004411{
Jeff Johnson5505db82017-11-02 21:19:23 -07004412 struct net_device *dev = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004413
4414 if (adapter)
Jeff Johnson5505db82017-11-02 21:19:23 -07004415 dev = adapter->dev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004416 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004417 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004418 return;
4419 }
4420
Alok Kumarb64650c2018-03-23 17:05:11 +05304421 hdd_nud_deinit_tracking(adapter);
4422 qdf_mutex_destroy(&adapter->disconnection_status_lock);
Nachiket Kukade5f0ce4f2018-06-15 19:47:37 +05304423 hdd_apf_context_destroy(adapter);
Min Liu8c5d99e2018-09-10 17:18:44 +08004424 qdf_spinlock_destroy(&adapter->vdev_lock);
Alok Kumarb64650c2018-03-23 17:05:11 +05304425
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +05304426 wlan_hdd_debugfs_csr_deinit(adapter);
Arunk Khandavallica56d4b2018-11-29 15:46:00 +05304427 if (adapter->device_mode == QDF_STA_MODE)
4428 hdd_sysfs_destroy_adapter_root_obj(adapter);
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +05304429
Rajeev Kumardca5f812016-02-04 17:28:06 -08004430 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05304431
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004432 /*
4433 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
4434 * the driver is almost closed and cannot handle either control
4435 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004436 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
4437 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004438 * is not right. Setting this flag helps hdd_stop() to recognize that
4439 * the interface is closed and restricts any operations on that
4440 */
4441 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
4442
4443 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004444 if (rtnl_held)
Jeff Johnson5505db82017-11-02 21:19:23 -07004445 unregister_netdevice(dev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004446 else
Jeff Johnson5505db82017-11-02 21:19:23 -07004447 unregister_netdev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004448 /*
4449 * Note that the adapter is no longer valid at this point
4450 * since the memory has been reclaimed
4451 */
4452 }
4453}
4454
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004455static QDF_STATUS hdd_check_for_existing_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07004456 tSirMacAddr mac_addr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004457{
Jeff Johnson9d295242017-08-29 14:39:48 -07004458 struct hdd_adapter *adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004459
Dustin Brown920397d2017-12-13 16:27:50 -08004460 hdd_for_each_adapter(hdd_ctx, adapter) {
4461 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07004462 mac_addr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304463 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004464 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004465 }
Dustin Brown920397d2017-12-13 16:27:50 -08004466
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304467 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004468}
Ryan Hsu07495ea2016-01-21 15:25:39 -08004469
Arun Khandavalli2358d522016-05-16 18:05:37 +05304470#ifdef CONFIG_FW_LOGS_BASED_ON_INI
4471/**
4472 * hdd_set_fw_log_params() - Set log parameters to FW
4473 * @hdd_ctx: HDD Context
4474 * @adapter: HDD Adapter
4475 *
4476 * This function set the FW Debug log level based on the INI.
4477 *
4478 * Return: None
4479 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004480static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004481 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304482{
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304483 QDF_STATUS status;
4484 uint16_t enable_fw_log_level, enable_fw_log_type;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304485 int ret;
4486
Arun Khandavallifae92942016-08-01 13:31:08 +05304487 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
4488 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004489 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05304490 return;
4491 }
4492
Arun Khandavallifae92942016-08-01 13:31:08 +05304493 /* Enable FW logs based on INI configuration */
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304494 status = ucfg_fwol_get_enable_fw_log_type(hdd_ctx->psoc,
4495 &enable_fw_log_type);
4496 if (QDF_IS_STATUS_ERROR(status))
4497 return;
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004498 ret = sme_cli_set_command(adapter->vdev_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304499 WMI_DBGLOG_TYPE,
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304500 enable_fw_log_type,
Arun Khandavallifae92942016-08-01 13:31:08 +05304501 DBG_CMD);
4502 if (ret != 0)
4503 hdd_err("Failed to enable FW log type ret %d",
4504 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304505
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304506 status = ucfg_fwol_get_enable_fw_log_level(hdd_ctx->psoc,
4507 &enable_fw_log_level);
4508 if (QDF_IS_STATUS_ERROR(status))
4509 return;
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004510 ret = sme_cli_set_command(adapter->vdev_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304511 WMI_DBGLOG_LOG_LEVEL,
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304512 enable_fw_log_level,
Arun Khandavallifae92942016-08-01 13:31:08 +05304513 DBG_CMD);
4514 if (ret != 0)
4515 hdd_err("Failed to enable FW log level ret %d",
4516 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304517
lifengfaa83cb2018-11-24 01:53:56 +08004518 sme_enable_fw_module_log_level(hdd_ctx->mac_handle,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004519 adapter->vdev_id);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304520}
4521#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004522static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004523 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304524{
4525}
4526
4527#endif
4528
4529/**
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004530 * hdd_configure_chain_mask() - programs chain mask to firmware
4531 * @adapter: HDD adapter
4532 *
4533 * Return: 0 on success or errno on failure
4534 */
4535static int hdd_configure_chain_mask(struct hdd_adapter *adapter)
4536{
Naveen Rawat98322472018-03-06 10:29:42 -08004537 QDF_STATUS status;
4538 struct wma_caps_per_phy non_dbs_phy_cap;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004539 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Pragaspathi Thilagaraj4b5c0602018-11-14 22:35:23 +05304540 bool enable2x2 = false, enable_bt_chain_sep = false;
Krunal Sonidf29bc42018-11-15 13:26:29 -08004541 uint8_t dual_mac_feature = DISABLE_DBS_CXN_AND_SCAN;
4542
4543 status = ucfg_policy_mgr_get_dual_mac_feature(hdd_ctx->psoc,
4544 &dual_mac_feature);
4545 if (!QDF_IS_STATUS_SUCCESS(status))
4546 hdd_err("unable to get dual mac feature");
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304547
Pragaspathi Thilagaraj4b5c0602018-11-14 22:35:23 +05304548 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &enable2x2);
4549 if (QDF_IS_STATUS_ERROR(status))
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304550 hdd_err("unable to get vht_enable2x2");
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004551
Pragaspathi Thilagaraj4b5c0602018-11-14 22:35:23 +05304552 status = ucfg_mlme_get_bt_chain_separation_flag(hdd_ctx->psoc,
4553 &enable_bt_chain_sep);
4554 if (QDF_IS_STATUS_ERROR(status))
4555 hdd_debug("unable to get BT chain separation. using default");
4556
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +05304557 hdd_debug("enable2x2: %d, lte_coex: %d, disable_DBS: %d",
Pragaspathi Thilagaraj4b5c0602018-11-14 22:35:23 +05304558 enable2x2, hdd_ctx->lte_coex_ant_share,
Krunal Sonidf29bc42018-11-15 13:26:29 -08004559 dual_mac_feature);
Pragaspathi Thilagaraj4b5c0602018-11-14 22:35:23 +05304560 hdd_debug("enable_bt_chain_separation %d", enable_bt_chain_sep);
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004561
Naveen Rawat98322472018-03-06 10:29:42 -08004562 status = wma_get_caps_for_phyidx_hwmode(&non_dbs_phy_cap,
4563 HW_MODE_DBS_NONE,
4564 CDS_BAND_ALL);
4565 if (QDF_IS_STATUS_ERROR(status)) {
4566 hdd_err("couldn't get phy caps. skip chain mask programming");
4567 return qdf_status_to_os_return(status);
4568 }
4569
4570 if (non_dbs_phy_cap.tx_chain_mask_2G < 3 ||
4571 non_dbs_phy_cap.rx_chain_mask_2G < 3 ||
4572 non_dbs_phy_cap.tx_chain_mask_5G < 3 ||
4573 non_dbs_phy_cap.rx_chain_mask_5G < 3) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -07004574 hdd_debug("firmware not capable. skip chain mask programming");
Naveen Rawat98322472018-03-06 10:29:42 -08004575 return 0;
4576 }
4577
Pragaspathi Thilagaraj4b5c0602018-11-14 22:35:23 +05304578 if (enable2x2 && !enable_bt_chain_sep) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -07004579 hdd_debug("2x2 enabled. skip chain mask programming");
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004580 return 0;
4581 }
4582
Krunal Sonidf29bc42018-11-15 13:26:29 -08004583 if (dual_mac_feature != DISABLE_DBS_CXN_AND_SCAN) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -07004584 hdd_debug("DBS enabled(%d). skip chain mask programming",
Krunal Sonidf29bc42018-11-15 13:26:29 -08004585 dual_mac_feature);
Naveen Rawatb54c72b2018-02-05 10:39:06 -08004586 return 0;
4587 }
4588
Naveen Rawatdacb5032018-02-08 15:23:24 -08004589 if (hdd_ctx->lte_coex_ant_share) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -07004590 hdd_debug("lte ant sharing enabled. skip chainmask programming");
Naveen Rawatdacb5032018-02-08 15:23:24 -08004591 return 0;
4592 }
4593
Dustin Brown1dbefe62018-09-11 16:32:03 -07004594 status = ucfg_mlme_configure_chain_mask(hdd_ctx->psoc,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004595 adapter->vdev_id);
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +05304596 if (status != QDF_STATUS_SUCCESS)
4597 goto error;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004598
4599 return 0;
4600
4601error:
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +05304602 hdd_err("WMI PDEV set param failed");
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004603 return -EINVAL;
4604}
4605
4606/**
Dundi Raviteja3b637092018-09-12 13:42:50 +05304607 * hdd_send_coex_config_params() - Send coex config params to FW
4608 * @hdd_ctx: HDD context
4609 * @adapter: Primary adapter context
4610 *
4611 * This function is used to send all coex config related params to FW
4612 *
4613 * Return: 0 on success and -EINVAL on failure
4614 */
4615static int hdd_send_coex_config_params(struct hdd_context *hdd_ctx,
4616 struct hdd_adapter *adapter)
4617{
4618 struct coex_config_params coex_cfg_params = {0};
4619 struct wlan_fwol_coex_config config = {0};
Dustin Brown05d81302018-09-11 16:49:22 -07004620 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Dundi Raviteja3b637092018-09-12 13:42:50 +05304621 QDF_STATUS status;
4622
4623 if (!hdd_ctx) {
4624 hdd_err("hdd_ctx is invalid");
4625 goto err;
4626 }
4627
4628 if (!adapter) {
4629 hdd_err("adapter is invalid");
4630 goto err;
4631 }
4632
4633 if (!psoc) {
4634 hdd_err("HDD psoc is invalid");
4635 goto err;
4636 }
4637
4638 status = ucfg_fwol_get_coex_config_params(psoc, &config);
4639 if (QDF_IS_STATUS_ERROR(status)) {
4640 hdd_err("Unable to get coex config params");
4641 goto err;
4642 }
4643
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004644 coex_cfg_params.vdev_id = adapter->vdev_id;
Dundi Raviteja3b637092018-09-12 13:42:50 +05304645 coex_cfg_params.config_type = WMI_COEX_CONFIG_TX_POWER;
4646 coex_cfg_params.config_arg1 = config.max_tx_power_for_btc;
4647
4648 status = sme_send_coex_config_cmd(&coex_cfg_params);
4649 if (QDF_IS_STATUS_ERROR(status)) {
4650 hdd_err("Failed to send coex Tx power");
4651 goto err;
4652 }
4653
4654 coex_cfg_params.config_type = WMI_COEX_CONFIG_HANDOVER_RSSI;
4655 coex_cfg_params.config_arg1 = config.wlan_low_rssi_threshold;
4656
4657 status = sme_send_coex_config_cmd(&coex_cfg_params);
4658 if (QDF_IS_STATUS_ERROR(status)) {
4659 hdd_err("Failed to send coex handover RSSI");
4660 goto err;
4661 }
4662
4663 coex_cfg_params.config_type = WMI_COEX_CONFIG_BTC_MODE;
4664 coex_cfg_params.config_arg1 = config.btc_mode;
4665
4666 status = sme_send_coex_config_cmd(&coex_cfg_params);
4667 if (QDF_IS_STATUS_ERROR(status)) {
4668 hdd_err("Failed to send coex BTC mode");
4669 goto err;
4670 }
4671
4672 coex_cfg_params.config_type = WMI_COEX_CONFIG_ANTENNA_ISOLATION;
4673 coex_cfg_params.config_arg1 = config.antenna_isolation;
4674
4675 status = sme_send_coex_config_cmd(&coex_cfg_params);
4676 if (QDF_IS_STATUS_ERROR(status)) {
4677 hdd_err("Failed to send coex antenna isolation");
4678 goto err;
4679 }
4680
4681 coex_cfg_params.config_type = WMI_COEX_CONFIG_BT_LOW_RSSI_THRESHOLD;
4682 coex_cfg_params.config_arg1 = config.bt_low_rssi_threshold;
4683
4684 status = sme_send_coex_config_cmd(&coex_cfg_params);
4685 if (QDF_IS_STATUS_ERROR(status)) {
4686 hdd_err("Failed to send coex BT low RSSI threshold");
4687 goto err;
4688 }
4689
4690 coex_cfg_params.config_type = WMI_COEX_CONFIG_BT_INTERFERENCE_LEVEL;
4691 coex_cfg_params.config_arg1 = config.bt_interference_low_ll;
4692 coex_cfg_params.config_arg2 = config.bt_interference_low_ul;
4693 coex_cfg_params.config_arg3 = config.bt_interference_medium_ll;
4694 coex_cfg_params.config_arg4 = config.bt_interference_medium_ul;
4695 coex_cfg_params.config_arg5 = config.bt_interference_high_ll;
4696 coex_cfg_params.config_arg6 = config.bt_interference_high_ul;
4697
4698 status = sme_send_coex_config_cmd(&coex_cfg_params);
4699 if (QDF_IS_STATUS_ERROR(status)) {
4700 hdd_err("Failed to send coex BT interference level");
4701 goto err;
4702 }
stonezc9936cb2019-03-11 16:41:22 +08004703
4704 if (wlan_hdd_mpta_helper_enable(&coex_cfg_params, &config))
4705 goto err;
4706
Dundi Raviteja3b637092018-09-12 13:42:50 +05304707 return 0;
4708err:
4709 return -EINVAL;
4710}
4711
4712/**
Arun Khandavalli2358d522016-05-16 18:05:37 +05304713 * hdd_set_fw_params() - Set parameters to firmware
4714 * @adapter: HDD adapter
4715 *
4716 * This function Sets various parameters to fw once the
4717 * adapter is started.
4718 *
4719 * Return: 0 on success or errno on failure
4720 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004721int hdd_set_fw_params(struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304722{
4723 int ret;
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304724 uint16_t upper_brssi_thresh, lower_brssi_thresh, rts_profile;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +05304725 bool enable_dtim_1chrx;
4726 QDF_STATUS status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004727 struct hdd_context *hdd_ctx;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304728 bool bval = false;
Manikandan Mohand350c192018-11-29 14:01:12 -08004729 uint8_t max_amsdu_len, enable_tx_sch_delay;
4730 uint32_t dtim_sel_diversity, enable_secondary_rate;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304731
Dustin Brownfdf17c12018-03-14 12:55:34 -07004732 hdd_enter_dev(adapter->dev);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304733
4734 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
4735 if (!hdd_ctx)
4736 return -EINVAL;
4737
Dustin Brown732ab9c2017-06-15 13:24:09 -07004738 if (cds_get_conparam() == QDF_GLOBAL_FTM_MODE) {
4739 hdd_debug("FTM Mode is active; nothing to do");
4740 return 0;
4741 }
4742
Manikandan Mohand350c192018-11-29 14:01:12 -08004743 ret = -1;
4744 if (QDF_IS_STATUS_SUCCESS(ucfg_fwol_get_lprx_enable(hdd_ctx->psoc,
4745 &bval))) {
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004746 ret = sme_cli_set_command(adapter->vdev_id,
Manikandan Mohand350c192018-11-29 14:01:12 -08004747 WMI_PDEV_PARAM_DTIM_SYNTH,
4748 bval, PDEV_CMD);
4749 }
Ashish Kumar Dhanotiyab8630ab2017-07-21 14:18:14 +05304750 if (ret) {
4751 hdd_err("Failed to set LPRx");
4752 goto error;
4753 }
4754
Pragaspathi Thilagaraj784c4922018-12-02 22:47:29 +05304755 ucfg_mlme_get_dtim_selection_diversity(hdd_ctx->psoc,
4756 &dtim_sel_diversity);
Ashish Kumar Dhanotiya191d1642018-02-08 17:43:09 +05304757
4758 ret = sme_cli_set_command(
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004759 adapter->vdev_id,
Ashish Kumar Dhanotiya191d1642018-02-08 17:43:09 +05304760 WMI_PDEV_PARAM_1CH_DTIM_OPTIMIZED_CHAIN_SELECTION,
Pragaspathi Thilagaraj784c4922018-12-02 22:47:29 +05304761 dtim_sel_diversity, PDEV_CMD);
Ashish Kumar Dhanotiya191d1642018-02-08 17:43:09 +05304762 if (ret) {
4763 hdd_err("Failed to set DTIM_OPTIMIZED_CHAIN_SELECTION");
4764 goto error;
4765 }
4766
Manikandan Mohand350c192018-11-29 14:01:12 -08004767 ret = -1;
4768 if (QDF_IS_STATUS_SUCCESS(ucfg_fwol_get_enable_tx_sch_delay(
4769 hdd_ctx->psoc, &enable_tx_sch_delay))) {
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004770 ret = sme_cli_set_command(adapter->vdev_id,
Manikandan Mohand350c192018-11-29 14:01:12 -08004771 WMI_PDEV_PARAM_TX_SCH_DELAY,
4772 enable_tx_sch_delay, PDEV_CMD);
4773 }
Ashish Kumar Dhanotiya48dac7d2018-03-28 14:59:50 +05304774 if (ret) {
4775 hdd_err("Failed to set WMI_PDEV_PARAM_TX_SCH_DELAY");
4776 goto error;
4777 }
4778
Manikandan Mohand350c192018-11-29 14:01:12 -08004779 ret = -1;
4780 if (QDF_IS_STATUS_SUCCESS(ucfg_fwol_get_enable_secondary_rate(
4781 hdd_ctx->psoc, &enable_secondary_rate))) {
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004782 ret = sme_cli_set_command(adapter->vdev_id,
Manikandan Mohand350c192018-11-29 14:01:12 -08004783 WMI_PDEV_PARAM_SECONDARY_RETRY_ENABLE,
4784 enable_secondary_rate, PDEV_CMD);
4785 }
Ashish Kumar Dhanotiya959b38c2018-04-06 21:07:57 +05304786 if (ret) {
4787 hdd_err("Failed to set WMI_PDEV_PARAM_SECONDARY_RETRY_ENABLE");
4788 goto error;
4789 }
4790
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304791 if (adapter->device_mode == QDF_STA_MODE) {
Sourav Mohapatrad9387d82018-09-07 12:28:52 +05304792 status = ucfg_get_upper_brssi_thresh(hdd_ctx->psoc,
4793 &upper_brssi_thresh);
4794 if (QDF_IS_STATUS_ERROR(status))
4795 return -EINVAL;
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304796
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004797 sme_set_smps_cfg(adapter->vdev_id,
Sourav Mohapatrad9387d82018-09-07 12:28:52 +05304798 HDD_STA_SMPS_PARAM_UPPER_BRSSI_THRESH,
4799 upper_brssi_thresh);
4800
4801 status = ucfg_get_lower_brssi_thresh(hdd_ctx->psoc,
4802 &lower_brssi_thresh);
4803 if (QDF_IS_STATUS_ERROR(status))
4804 return -EINVAL;
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304805
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004806 sme_set_smps_cfg(adapter->vdev_id,
Sourav Mohapatrad9387d82018-09-07 12:28:52 +05304807 HDD_STA_SMPS_PARAM_LOWER_BRSSI_THRESH,
4808 lower_brssi_thresh);
4809
4810 status = ucfg_get_enable_dtim_1chrx(hdd_ctx->psoc,
4811 &enable_dtim_1chrx);
4812 if (QDF_IS_STATUS_ERROR(status))
4813 return -EINVAL;
4814
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004815 sme_set_smps_cfg(adapter->vdev_id,
Sourav Mohapatrad9387d82018-09-07 12:28:52 +05304816 HDD_STA_SMPS_PARAM_DTIM_1CHRX_ENABLE,
4817 enable_dtim_1chrx);
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304818 }
4819
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304820 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &bval);
4821 if (!QDF_IS_STATUS_SUCCESS(status))
4822 hdd_err("unable to get vht_enable2x2");
4823
4824 if (bval) {
Dustin Brown732ab9c2017-06-15 13:24:09 -07004825 hdd_debug("configuring 2x2 mode fw params");
4826
Vignesh Viswanathana851d752018-10-03 19:44:38 +05304827 ret = sme_set_cck_tx_fir_override(hdd_ctx->mac_handle,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004828 adapter->vdev_id);
Dustin Brown732ab9c2017-06-15 13:24:09 -07004829 if (ret) {
4830 hdd_err("WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE set failed %d",
4831 ret);
4832 goto error;
4833 }
Liangwei Dong22810e82018-03-15 03:42:12 -04004834
4835 if (hdd_configure_chain_mask(adapter))
4836 goto error;
Dustin Brown732ab9c2017-06-15 13:24:09 -07004837 } else {
Arun Khandavalli2358d522016-05-16 18:05:37 +05304838#define HDD_DTIM_1CHAIN_RX_ID 0x5
4839#define HDD_SMPS_PARAM_VALUE_S 29
Dustin Brown732ab9c2017-06-15 13:24:09 -07004840 hdd_debug("configuring 1x1 mode fw params");
4841
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004842 /*
4843 * Disable DTIM 1 chain Rx when in 1x1,
4844 * we are passing two value
4845 * as param_id << 29 | param_value.
4846 * Below param_value = 0(disable)
4847 */
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004848 ret = sme_cli_set_command(adapter->vdev_id,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004849 WMI_STA_SMPS_PARAM_CMDID,
4850 HDD_DTIM_1CHAIN_RX_ID <<
4851 HDD_SMPS_PARAM_VALUE_S,
4852 VDEV_CMD);
4853 if (ret) {
4854 hdd_err("DTIM 1 chain set failed %d", ret);
4855 goto error;
4856 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304857
Arun Khandavalli2358d522016-05-16 18:05:37 +05304858#undef HDD_DTIM_1CHAIN_RX_ID
4859#undef HDD_SMPS_PARAM_VALUE_S
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004860
4861 if (hdd_configure_chain_mask(adapter))
4862 goto error;
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004863 }
4864
Vignesh Viswanathana851d752018-10-03 19:44:38 +05304865 ret = sme_set_enable_mem_deep_sleep(hdd_ctx->mac_handle,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004866 adapter->vdev_id);
Dustin Brown732ab9c2017-06-15 13:24:09 -07004867 if (ret) {
4868 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d", ret);
4869 goto error;
4870 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304871
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304872 status = ucfg_fwol_get_rts_profile(hdd_ctx->psoc, &rts_profile);
4873 if (QDF_IS_STATUS_ERROR(status))
4874 return -EINVAL;
4875
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004876 ret = sme_cli_set_command(adapter->vdev_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004877 WMI_VDEV_PARAM_ENABLE_RTSCTS,
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304878 rts_profile,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004879 VDEV_CMD);
4880 if (ret) {
4881 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
4882 goto error;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304883 }
4884
Vignesh Viswanathanddc89e52018-11-02 18:43:42 +05304885 status = ucfg_mlme_get_max_amsdu_num(hdd_ctx->psoc, &max_amsdu_len);
4886 if (QDF_IS_STATUS_ERROR(status)) {
4887 hdd_err("Failed to get Max AMSDU Num");
4888 goto error;
4889 }
4890
4891 hdd_debug("SET AMSDU num %d", max_amsdu_len);
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004892
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004893 ret = wma_cli_set_command(adapter->vdev_id,
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004894 GEN_VDEV_PARAM_AMSDU,
Vignesh Viswanathanddc89e52018-11-02 18:43:42 +05304895 max_amsdu_len,
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004896 GEN_CMD);
4897 if (ret != 0) {
4898 hdd_err("GEN_VDEV_PARAM_AMSDU set failed %d", ret);
4899 goto error;
4900 }
4901
Arun Khandavalli2358d522016-05-16 18:05:37 +05304902 hdd_set_fw_log_params(hdd_ctx, adapter);
Dundi Raviteja3b637092018-09-12 13:42:50 +05304903
4904 ret = hdd_send_coex_config_params(hdd_ctx, adapter);
4905 if (ret) {
4906 hdd_warn("Error initializing coex config params");
4907 goto error;
4908 }
4909
Dustin Browne74003f2018-03-14 12:51:58 -07004910 hdd_exit();
Dustin Brown732ab9c2017-06-15 13:24:09 -07004911
Arun Khandavalli2358d522016-05-16 18:05:37 +05304912 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05304913
Arun Khandavalli2358d522016-05-16 18:05:37 +05304914error:
4915 return -EINVAL;
4916}
4917
Ryan Hsu07495ea2016-01-21 15:25:39 -08004918/**
Abhinav Kumarcc959f12018-08-09 13:58:30 +05304919 * hdd_init_completion() - Initialize Completion Variables
4920 * @adapter: HDD adapter
4921 *
4922 * This function Initialize the completion variables for
4923 * a particular adapter
4924 *
4925 * Return: None
4926 */
4927static void hdd_init_completion(struct hdd_adapter *adapter)
4928{
4929 init_completion(&adapter->disconnect_comp_var);
4930 init_completion(&adapter->roaming_comp_var);
4931 init_completion(&adapter->linkup_event_var);
Abhinav Kumarcc959f12018-08-09 13:58:30 +05304932 init_completion(&adapter->sta_authorized_event);
4933 init_completion(&adapter->offchannel_tx_event);
4934 init_completion(&adapter->tx_action_cnf_event);
4935 init_completion(&adapter->ibss_peer_info_comp);
4936 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
4937}
4938
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05304939static void hdd_reset_locally_admin_bit(struct hdd_context *hdd_ctx,
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07004940 tSirMacAddr mac_addr)
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05304941{
4942 int i;
4943 /*
4944 * Reset locally administered bit for dynamic_mac_list
4945 * also as while releasing the MAC address for any
4946 * interface mac will be compared with dynamic mac list
4947 */
4948 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
4949 if (!qdf_mem_cmp(
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07004950 mac_addr,
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05304951 &hdd_ctx->
4952 dynamic_mac_list[i].dynamic_mac.bytes[0],
4953 sizeof(struct qdf_mac_addr))) {
4954 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(
4955 hdd_ctx->
4956 dynamic_mac_list[i].dynamic_mac.bytes);
4957 break;
4958 }
4959 }
4960 /*
4961 * Reset locally administered bit if the device mode is
4962 * STA
4963 */
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07004964 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(mac_addr);
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05304965 hdd_debug("locally administered bit reset in sta mode: "
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07004966 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(mac_addr));
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05304967}
4968
Dustin Brown96b98dd2019-03-06 12:39:37 -08004969static void wlan_hdd_cfg80211_scan_block_cb(struct work_struct *work)
4970{
4971 struct hdd_adapter *adapter =
4972 container_of(work, struct hdd_adapter, scan_block_work);
4973 struct osif_vdev_sync *vdev_sync;
4974
4975 if (osif_vdev_sync_op_start(adapter->dev, &vdev_sync))
4976 return;
4977
4978 wlan_hdd_cfg80211_scan_block(adapter);
4979
4980 osif_vdev_sync_op_stop(vdev_sync);
4981}
4982
Abhinav Kumarcc959f12018-08-09 13:58:30 +05304983/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08004984 * hdd_open_adapter() - open and setup the hdd adatper
4985 * @hdd_ctx: global hdd context
4986 * @session_type: type of the interface to be created
4987 * @iface_name: User-visible name of the interface
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07004988 * @mac_addr: MAC address to assign to the interface
Ryan Hsu07495ea2016-01-21 15:25:39 -08004989 * @name_assign_type: the name of assign type of the netdev
4990 * @rtnl_held: the rtnl lock hold flag
4991 *
4992 * This function open and setup the hdd adpater according to the device
4993 * type request, assign the name, the mac address assigned, and then prepared
4994 * the hdd related parameters, queue, lock and ready to start.
4995 *
4996 * Return: the pointer of hdd adapter, otherwise NULL.
4997 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004998struct hdd_adapter *hdd_open_adapter(struct hdd_context *hdd_ctx, uint8_t session_type,
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07004999 const char *iface_name, tSirMacAddr mac_addr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08005000 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08005001 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005002{
Jeff Johnson9d295242017-08-29 14:39:48 -07005003 struct hdd_adapter *adapter = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305004 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005005
5006 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
5007 /*
5008 * Max limit reached on the number of vdevs configured by the
5009 * host. Return error
5010 */
Arun Khandavallifae92942016-08-01 13:31:08 +05305011 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
5012 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005013 return NULL;
5014 }
5015
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07005016 status = wlan_hdd_validate_mac_address((struct qdf_mac_addr *)mac_addr);
Pragaspathi Thilagaraj84b72842018-09-19 22:06:57 +05305017 if (QDF_IS_STATUS_ERROR(status)) {
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07005018 /* Not received valid mac_addr */
Arun Khandavallifae92942016-08-01 13:31:08 +05305019 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005020 return NULL;
5021 }
Pragaspathi Thilagaraj84b72842018-09-19 22:06:57 +05305022
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07005023 status = hdd_check_for_existing_macaddr(hdd_ctx, mac_addr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305024 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05305025 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
5026 " already exists",
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07005027 MAC_ADDR_ARRAY(mac_addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005028 return NULL;
5029 }
5030
5031 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005032 case QDF_STA_MODE:
Ashish Kumar Dhanotiya01485192018-12-24 12:44:06 +05305033 if (!hdd_ctx->config->mac_provision) {
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07005034 hdd_reset_locally_admin_bit(hdd_ctx, mac_addr);
Ashish Kumar Dhanotiya01485192018-12-24 12:44:06 +05305035 /*
5036 * After resetting locally administered bit
5037 * again check if the new mac address is already
5038 * exists.
5039 */
5040 status = hdd_check_for_existing_macaddr(hdd_ctx,
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07005041 mac_addr);
Ashish Kumar Dhanotiya01485192018-12-24 12:44:06 +05305042 if (QDF_STATUS_E_FAILURE == status) {
5043 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
5044 " already exists",
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07005045 MAC_ADDR_ARRAY(mac_addr));
Ashish Kumar Dhanotiya01485192018-12-24 12:44:06 +05305046 return NULL;
5047 }
5048 }
Ashish Kumar Dhanotiya6784b502018-10-17 12:51:10 +05305049
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005050 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005051 case QDF_P2P_CLIENT_MODE:
5052 case QDF_P2P_DEVICE_MODE:
5053 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07005054 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305055 case QDF_MONITOR_MODE:
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07005056 adapter = hdd_alloc_station_adapter(hdd_ctx, mac_addr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08005057 name_assign_type,
5058 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005059
Jeff Johnsond36fa332019-03-18 13:42:25 -07005060 if (!adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05305061 hdd_err("failed to allocate adapter for session %d",
5062 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005063 return NULL;
5064 }
5065
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005066 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005067 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005068 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005069 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305070 else if (QDF_MONITOR_MODE == session_type)
5071 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005072 else
5073 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
5074
5075 adapter->device_mode = session_type;
5076
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005077
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005078 /*
5079 * Workqueue which gets scheduled in IPv4 notification
5080 * callback
5081 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005082 INIT_WORK(&adapter->ipv4_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005083 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005084
5085#ifdef WLAN_NS_OFFLOAD
5086 /*
5087 * Workqueue which gets scheduled in IPv6
5088 * notification callback.
5089 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005090 INIT_WORK(&adapter->ipv6_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005091 hdd_ipv6_notifier_work_queue);
5092#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005093 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08005094 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08005095 goto err_free_netdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005096
5097 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07005098 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005099 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305100 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
5101 WLAN_CONTROL_PATH);
Arun Khandavallifae92942016-08-01 13:31:08 +05305102
Alok Kumarb64650c2018-03-23 17:05:11 +05305103 hdd_nud_init_tracking(adapter);
Arunk Khandavallica56d4b2018-11-29 15:46:00 +05305104 if (adapter->device_mode == QDF_STA_MODE ||
5105 adapter->device_mode == QDF_P2P_DEVICE_MODE)
5106 hdd_sysfs_create_adapter_root_obj(adapter);
Alok Kumarb64650c2018-03-23 17:05:11 +05305107 qdf_mutex_create(&adapter->disconnection_status_lock);
5108
Ravi Joshi1a292562017-05-18 16:28:54 -07005109 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005110
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005111 case QDF_P2P_GO_MODE:
5112 case QDF_SAP_MODE:
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07005113 adapter = hdd_wlan_create_ap_dev(hdd_ctx, mac_addr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08005114 name_assign_type,
5115 (uint8_t *) iface_name);
Jeff Johnsond36fa332019-03-18 13:42:25 -07005116 if (!adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005117 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05305118 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005119 return NULL;
5120 }
5121
5122 adapter->wdev.iftype =
5123 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005124 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005125 NL80211_IFTYPE_P2P_GO;
5126 adapter->device_mode = session_type;
5127
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07005128 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08005129 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005130 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08005131
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07005132 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005133 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305134 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
5135 WLAN_CONTROL_PATH);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305136
5137 /*
5138 * Workqueue which gets scheduled in IPv4 notification
5139 * callback
5140 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005141 INIT_WORK(&adapter->ipv4_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305142 hdd_ipv4_notifier_work_queue);
5143
5144#ifdef WLAN_NS_OFFLOAD
5145 /*
5146 * Workqueue which gets scheduled in IPv6
5147 * notification callback.
5148 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005149 INIT_WORK(&adapter->ipv6_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305150 hdd_ipv6_notifier_work_queue);
5151#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005152 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305153 case QDF_FTM_MODE:
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07005154 adapter = hdd_alloc_station_adapter(hdd_ctx, mac_addr,
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305155 name_assign_type,
Lin Bai1c678482017-12-18 18:29:11 +08005156 iface_name);
Jeff Johnsond36fa332019-03-18 13:42:25 -07005157 if (!adapter) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305158 hdd_err("Failed to allocate adapter for FTM mode");
5159 return NULL;
5160 }
5161 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
5162 adapter->device_mode = session_type;
5163 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08005164 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08005165 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08005166
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305167 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07005168 hdd_debug("Disabling queues");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305169 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305170 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
5171 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305172 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005173 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005174 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305175 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005176 return NULL;
5177 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005178
Min Liu8c5d99e2018-09-10 17:18:44 +08005179 qdf_spinlock_create(&adapter->vdev_lock);
5180
Abhinav Kumarcc959f12018-08-09 13:58:30 +05305181 hdd_init_completion(adapter);
hqueaa33ee2017-05-04 17:56:35 +08005182 INIT_WORK(&adapter->scan_block_work, wlan_hdd_cfg80211_scan_block_cb);
Min Liu9be5d4a2018-05-17 11:51:53 +08005183 qdf_list_create(&adapter->blocked_scan_request_q, WLAN_MAX_SCAN_COUNT);
5184 qdf_mutex_create(&adapter->blocked_scan_request_q_lock);
hqueaa33ee2017-05-04 17:56:35 +08005185
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305186 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005187 /* Add it to the hdd's session list. */
Dustin Brown920397d2017-12-13 16:27:50 -08005188 status = hdd_add_adapter_back(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005189 }
5190
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305191 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsond36fa332019-03-18 13:42:25 -07005192 if (adapter) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005193 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
5194 adapter = NULL;
5195 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005196
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005197 return NULL;
5198 }
Nachiket Kukade5f0ce4f2018-06-15 19:47:37 +05305199 hdd_apf_context_init(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005200
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305201 if (QDF_STATUS_SUCCESS == status) {
Dustin Brown1dbefe62018-09-11 16:32:03 -07005202 policy_mgr_set_concurrency_mode(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08005203 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005204
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005205 /* Adapter successfully added. Increment the vdev count */
5206 hdd_ctx->current_intf_count++;
5207
Jeff Johnson5880d792016-08-15 13:32:30 -07005208 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005209 hdd_ctx->current_intf_count);
5210
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08005211 hdd_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005212 }
5213
Rajeev Kumardca5f812016-02-04 17:28:06 -08005214 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07005215 hdd_err("Interface %s wow debug_fs init failed",
5216 netdev_name(adapter->dev));
5217
Ajit Pal Singh106c1412018-04-18 18:08:49 +05305218 hdd_register_hl_netdev_fc_timer(adapter,
5219 hdd_tx_resume_timer_expired_handler);
5220
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07005221 hdd_info("%s interface created. iftype: %d", netdev_name(adapter->dev),
5222 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005223
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +05305224 if (adapter->device_mode == QDF_STA_MODE)
5225 wlan_hdd_debugfs_csr_init(adapter);
5226
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005227 return adapter;
5228
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005229err_free_netdev:
Jeff Johnson1e851a12017-10-28 14:36:12 -07005230 wlan_hdd_release_intf_addr(hdd_ctx, adapter->mac_addr.bytes);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05305231 free_netdev(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005232
5233 return NULL;
5234}
5235
Dustin Brown728d65a2018-10-02 16:27:52 -07005236static void __hdd_close_adapter(struct hdd_context *hdd_ctx,
5237 struct hdd_adapter *adapter,
5238 bool rtnl_held)
5239{
5240 qdf_list_destroy(&adapter->blocked_scan_request_q);
5241 qdf_mutex_destroy(&adapter->blocked_scan_request_q_lock);
5242 policy_mgr_clear_concurrency_mode(hdd_ctx->psoc, adapter->device_mode);
5243
5244 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
5245
5246 if (hdd_ctx->current_intf_count != 0)
5247 hdd_ctx->current_intf_count--;
5248}
5249
5250void hdd_close_adapter(struct hdd_context *hdd_ctx,
5251 struct hdd_adapter *adapter,
5252 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005253{
Dustin Brown920397d2017-12-13 16:27:50 -08005254 /*
Dustin Brown728d65a2018-10-02 16:27:52 -07005255 * Stop the global bus bandwidth timer while touching the adapter list
5256 * to avoid bad memory access by the timer handler.
Dustin Brown920397d2017-12-13 16:27:50 -08005257 */
Dustin Brown920397d2017-12-13 16:27:50 -08005258 hdd_bus_bw_compute_timer_stop(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005259
Dustin Brown920397d2017-12-13 16:27:50 -08005260 hdd_remove_adapter(hdd_ctx, adapter);
Dustin Brown728d65a2018-10-02 16:27:52 -07005261 __hdd_close_adapter(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005262
Dustin Brown920397d2017-12-13 16:27:50 -08005263 /* conditionally restart the bw timer */
5264 hdd_bus_bw_compute_timer_try_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005265}
5266
Dustin Brown728d65a2018-10-02 16:27:52 -07005267void hdd_close_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005268{
Dustin Brown920397d2017-12-13 16:27:50 -08005269 struct hdd_adapter *adapter;
Dustin Brown2c5e0482019-02-05 16:14:43 -08005270 struct osif_vdev_sync *vdev_sync;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005271
Dustin Brown491d54b2018-03-14 12:39:11 -07005272 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005273
Dustin Brown728d65a2018-10-02 16:27:52 -07005274 while (QDF_IS_STATUS_SUCCESS(hdd_remove_front_adapter(hdd_ctx,
5275 &adapter))) {
Dustin Brown2c5e0482019-02-05 16:14:43 -08005276 vdev_sync = osif_vdev_sync_unregister(adapter->dev);
Dustin Brown693b5352019-01-17 10:00:31 -08005277 if (vdev_sync)
Dustin Brown2c5e0482019-02-05 16:14:43 -08005278 osif_vdev_sync_wait_for_ops(vdev_sync);
Dustin Brown693b5352019-01-17 10:00:31 -08005279
Dustin Brown728d65a2018-10-02 16:27:52 -07005280 wlan_hdd_release_intf_addr(hdd_ctx, adapter->mac_addr.bytes);
5281 __hdd_close_adapter(hdd_ctx, adapter, rtnl_held);
Dustin Brown693b5352019-01-17 10:00:31 -08005282
5283 if (vdev_sync)
Dustin Brown2c5e0482019-02-05 16:14:43 -08005284 osif_vdev_sync_destroy(vdev_sync);
Dustin Brown728d65a2018-10-02 16:27:52 -07005285 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005286
Dustin Browne74003f2018-03-14 12:51:58 -07005287 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005288}
5289
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005290void wlan_hdd_reset_prob_rspies(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005291{
Anurag Chouhan6d760662016-02-20 16:05:43 +05305292 struct qdf_mac_addr *bssid = NULL;
Jeff Johnsonc565af12019-03-10 21:09:47 -07005293 tSirUpdateIE update_ie;
Jeff Johnson16528362018-06-14 12:34:16 -07005294 mac_handle_t mac_handle;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005295
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005296 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005297 case QDF_STA_MODE:
5298 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005299 {
Jeff Johnsond377dce2017-10-04 10:32:42 -07005300 struct hdd_station_ctx *sta_ctx =
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005301 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Jeff Johnsone04b6992019-02-27 14:06:55 -08005302 bssid = &sta_ctx->conn_info.bssid;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005303 break;
5304 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005305 case QDF_SAP_MODE:
5306 case QDF_P2P_GO_MODE:
5307 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005308 {
Jeff Johnson1e851a12017-10-28 14:36:12 -07005309 bssid = &adapter->mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005310 break;
5311 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005312 case QDF_FTM_MODE:
5313 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005314 default:
5315 /*
5316 * wlan_hdd_reset_prob_rspies should not have been called
5317 * for these kind of devices
5318 */
Jeff Johnson5880d792016-08-15 13:32:30 -07005319 hdd_err("Unexpected request for the current device type %d",
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005320 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005321 return;
5322 }
5323
Jeff Johnsonc565af12019-03-10 21:09:47 -07005324 qdf_copy_macaddr(&update_ie.bssid, bssid);
5325 update_ie.smeSessionId = adapter->vdev_id;
5326 update_ie.ieBufferlength = 0;
5327 update_ie.pAdditionIEBuffer = NULL;
5328 update_ie.append = true;
5329 update_ie.notify = false;
Jeff Johnson16528362018-06-14 12:34:16 -07005330 mac_handle = hdd_adapter_get_mac_handle(adapter);
5331 if (sme_update_add_ie(mac_handle,
Jeff Johnsonc565af12019-03-10 21:09:47 -07005332 &update_ie,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305333 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005334 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005335 }
5336}
5337
Dustin Browndb2a8be2017-12-20 11:49:56 -08005338QDF_STATUS hdd_stop_adapter(struct hdd_context *hdd_ctx,
5339 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005340{
Dustin Brownd747ecd2018-10-26 16:32:22 -07005341 QDF_STATUS status = QDF_STATUS_SUCCESS;
5342 struct hdd_station_ctx *sta_ctx;
Dustin Brownb4260d52019-01-24 11:53:08 -08005343 struct sap_context *sap_ctx;
Jeff Johnson025618c2018-03-18 14:41:00 -07005344 struct csr_roam_profile *roam_profile;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005345 union iwreq_data wrqu;
Jeff Johnsonc565af12019-03-10 21:09:47 -07005346 tSirUpdateIE update_ie;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005347 unsigned long rc;
Jeff Johnson8f8ceb92019-03-24 08:16:55 -07005348 struct sap_config *sap_config;
Jeff Johnson16528362018-06-14 12:34:16 -07005349 mac_handle_t mac_handle;
Min Liu8c5d99e2018-09-10 17:18:44 +08005350 struct wlan_objmgr_vdev *vdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005351
Dustin Brown491d54b2018-03-14 12:39:11 -07005352 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005353
Jeff Johnson912b1bb2019-03-06 10:12:36 -08005354 if (adapter->vdev_id != WLAN_UMAC_VDEV_ID_MAX)
Dustin Browne7e71d32018-05-11 16:00:08 -07005355 wlan_hdd_cfg80211_deregister_frames(adapter);
5356
Alok Kumarb64650c2018-03-23 17:05:11 +05305357 hdd_nud_ignore_tracking(adapter, true);
5358 hdd_nud_reset_tracking(adapter);
Alok Kumar016a1ac2018-09-16 09:55:50 +05305359 hdd_nud_flush_work(adapter);
hangtian9c47aaf2018-11-26 17:59:39 +08005360 hdd_stop_tsf_sync(adapter);
Alok Kumarb64650c2018-03-23 17:05:11 +05305361
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07005362 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305363 wlan_hdd_netif_queue_control(adapter,
5364 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
5365 WLAN_CONTROL_PATH);
Jeff Johnson16528362018-06-14 12:34:16 -07005366
5367 mac_handle = hdd_ctx->mac_handle;
5368
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005369 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005370 case QDF_STA_MODE:
5371 case QDF_P2P_CLIENT_MODE:
5372 case QDF_IBSS_MODE:
5373 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005374 case QDF_NDI_MODE:
Dustin Brownd747ecd2018-10-26 16:32:22 -07005375 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
5376
5377 if (adapter->device_mode == QDF_NDI_MODE ||
5378 hdd_conn_is_connected(sta_ctx) ||
5379 hdd_is_connecting(sta_ctx)) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005380 INIT_COMPLETION(adapter->disconnect_comp_var);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005381
Jeff Johnson025618c2018-03-18 14:41:00 -07005382 roam_profile = hdd_roam_profile(adapter);
5383 /* For NDI do not use roam_profile */
Dustin Brownd747ecd2018-10-26 16:32:22 -07005384 if (adapter->device_mode == QDF_NDI_MODE)
5385 status = sme_roam_disconnect(
Jeff Johnson16528362018-06-14 12:34:16 -07005386 mac_handle,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08005387 adapter->vdev_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005388 eCSR_DISCONNECT_REASON_NDI_DELETE);
Jeff Johnson025618c2018-03-18 14:41:00 -07005389 else if (roam_profile->BSSType ==
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005390 eCSR_BSS_TYPE_START_IBSS)
Dustin Brownd747ecd2018-10-26 16:32:22 -07005391 status = sme_roam_disconnect(
Jeff Johnson16528362018-06-14 12:34:16 -07005392 mac_handle,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08005393 adapter->vdev_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005394 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Abhinav Kumar19a7a402018-07-12 17:36:57 +05305395 else if (adapter->device_mode == QDF_STA_MODE)
5396 wlan_hdd_disconnect(adapter,
5397 eCSR_DISCONNECT_REASON_DEAUTH);
5398 else
Dustin Brownd747ecd2018-10-26 16:32:22 -07005399 status = sme_roam_disconnect(
Jeff Johnson16528362018-06-14 12:34:16 -07005400 mac_handle,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08005401 adapter->vdev_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005402 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005403 /* success implies disconnect is queued */
5404 if (QDF_IS_STATUS_SUCCESS(status) &&
5405 adapter->device_mode != QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005406 rc = wait_for_completion_timeout(
5407 &adapter->disconnect_comp_var,
5408 msecs_to_jiffies
Abhishek Singhd1f21c72019-01-21 15:16:34 +05305409 (SME_DISCONNECT_TIMEOUT));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005410 if (!rc)
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07005411 hdd_warn("disconn_comp_var wait fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005412 }
Dustin Brownd747ecd2018-10-26 16:32:22 -07005413 if (QDF_IS_STATUS_ERROR(status))
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07005414 hdd_warn("failed to post disconnect");
Dustin Brownd747ecd2018-10-26 16:32:22 -07005415
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005416 memset(&wrqu, '\0', sizeof(wrqu));
5417 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
5418 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
5419 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
5420 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05305421 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005422
Dustin Brownd747ecd2018-10-26 16:32:22 -07005423 wlan_hdd_scan_abort(adapter);
Wu Gao4a1ec8c2018-07-23 19:18:40 +08005424 wlan_hdd_cleanup_actionframe(adapter);
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05305425 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05305426 hdd_clear_fils_connection_info(adapter);
Ashish Kumar Dhanotiya36510832019-02-20 22:13:25 +05305427
5428 status = sme_roam_del_pmkid_from_cache(mac_handle,
5429 adapter->vdev_id,
5430 NULL, true);
5431 if (QDF_IS_STATUS_ERROR(status))
5432 hdd_err("Cannot flush PMKIDCache");
5433
Dustin Brownd747ecd2018-10-26 16:32:22 -07005434 hdd_deregister_tx_flow_control(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005435
5436#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005437 cancel_work_sync(&adapter->ipv4_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005438#ifdef WLAN_NS_OFFLOAD
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005439 cancel_work_sync(&adapter->ipv6_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005440#endif
5441#endif
5442
Min Liu8c5d99e2018-09-10 17:18:44 +08005443 if (adapter->device_mode == QDF_STA_MODE) {
5444 struct wlan_objmgr_vdev *vdev;
5445
5446 vdev = hdd_objmgr_get_vdev(adapter);
5447 if (vdev) {
5448 wlan_cfg80211_sched_scan_stop(vdev);
Rajeev Kumar Sirasanagandla25bdfad2019-02-15 19:15:49 +05305449 hdd_objmgr_put_vdev(vdev);
Min Liu8c5d99e2018-09-10 17:18:44 +08005450 }
5451 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08005452
Pragaspathi Thilagaraje6f37e02019-01-04 12:24:33 +05305453 /*
5454 * During vdev destroy, if any STA is in connecting state the
5455 * roam command will be in active queue and thus vdev destroy is
5456 * queued in pending queue. In case STA tries to connect to
5457 * multiple BSSID and fails to connect, due to auth/assoc
5458 * timeouts it may take more than vdev destroy time to get
5459 * completed. On vdev destroy timeout vdev is moved to logically
5460 * deleted state. Once connection is completed, vdev destroy is
5461 * activated and to release the self-peer ref count it try to
5462 * get the ref of the vdev, which fails as vdev is logically
5463 * deleted and this leads to peer ref leak. So before vdev
5464 * destroy is queued abort any STA ongoing connection to avoid
5465 * vdev destroy timeout.
5466 */
5467 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags))
5468 hdd_abort_ongoing_sta_connection(hdd_ctx);
Dustin Browndb2a8be2017-12-20 11:49:56 -08005469
Himanshu Agarwalb229a142017-12-21 10:16:45 +05305470 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005471 break;
5472
Rajeev Kumar3b906202018-02-01 10:55:14 -08005473 case QDF_MONITOR_MODE:
5474 wlan_hdd_scan_abort(adapter);
5475 hdd_deregister_tx_flow_control(adapter);
5476 hdd_vdev_destroy(adapter);
5477 break;
5478
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005479 case QDF_SAP_MODE:
Will Huang7049bae2018-08-13 17:25:02 +08005480 if (test_bit(ACS_PENDING, &adapter->event_flags)) {
5481 cds_flush_delayed_work(&adapter->acs_pending_work);
5482 clear_bit(ACS_PENDING, &adapter->event_flags);
5483 }
Dustin Brownd747ecd2018-10-26 16:32:22 -07005484
wadesongf9b15ed2017-12-14 14:12:32 +08005485 wlan_hdd_scan_abort(adapter);
gaurank kathpaliab7a9f702019-02-15 18:09:58 +05305486 /* Diassociate with all the peers before stop ap post */
5487 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags))
5488 wlan_hdd_del_station(adapter);
Arunk Khandavalli96c122f2017-10-17 11:49:36 +05305489 sap_config = &adapter->session.ap.sap_config;
Dustin Brownd747ecd2018-10-26 16:32:22 -07005490 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
5491
Dustin Brown07901ec2018-09-07 11:02:41 -07005492 ucfg_ipa_flush(hdd_ctx->pdev);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005493
Dustin Brownb4260d52019-01-24 11:53:08 -08005494 /* don't flush pre-cac destroy if we are destroying pre-cac */
5495 sap_ctx = WLAN_HDD_GET_SAP_CTX_PTR(adapter);
5496 if (!wlan_sap_is_pre_cac_context(sap_ctx))
Liangwei Dongad89c762018-06-01 01:56:23 -04005497 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
Dustin Brownb4260d52019-01-24 11:53:08 -08005498
Jeff Johnson46807cd2018-04-29 21:32:22 -07005499 /* fallthrough */
Dustin Browna5cf8e02017-10-19 16:04:19 -07005500
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005501 case QDF_P2P_GO_MODE:
Krunal Soni22208392017-09-29 18:10:34 -07005502 cds_flush_work(&adapter->sap_stop_bss_work);
Abhinav Kumarb638b5d2018-03-26 12:25:41 +05305503 qdf_atomic_set(&adapter->session.ap.acs_in_progress, 0);
Dustin Browna5cf8e02017-10-19 16:04:19 -07005504 wlan_hdd_undo_acs(adapter);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005505
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005506 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005507 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5508
5509 hdd_deregister_tx_flow_control(adapter);
Kapil Guptac1224bf2017-06-22 21:22:40 +05305510 hdd_destroy_acs_timer(adapter);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005511
Pragaspathi Thilagaraje6f37e02019-01-04 12:24:33 +05305512 /**
5513 * During vdev destroy, If any STA is in connecting state the
5514 * roam command will be in active queue and thus vdev destroy is
5515 * queued in pending queue. In case STA is tries to connected to
5516 * multiple BSSID and fails to connect, due to auth/assoc
5517 * timeouts it may take more than vdev destroy time to get
5518 * completes. If vdev destroy timeout vdev is moved to logically
5519 * deleted state. Once connection is completed, vdev destroy is
5520 * activated and to release the self-peer ref count it try to
5521 * get the ref of the vdev, which fails as vdev is logically
5522 * deleted and this leads to peer ref leak. So before vdev
5523 * destroy is queued abort any STA ongoing connection to avoid
5524 * vdev destroy timeout.
5525 */
5526 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags))
5527 hdd_abort_ongoing_sta_connection(hdd_ctx);
5528
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005529 mutex_lock(&hdd_ctx->sap_lock);
5530 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005531 status = wlansap_stop_bss(
5532 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005533
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305534 if (QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnsonca2530c2017-09-30 18:25:40 -07005535 struct hdd_hostapd_state *hostapd_state =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005536 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05305537 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05305538 qdf_stop_bss_event);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005539 status = qdf_wait_for_event_completion(
Nachiket Kukade0396b732017-11-14 16:35:16 +05305540 &hostapd_state->qdf_stop_bss_event,
Abhishek Singhd1f21c72019-01-21 15:16:34 +05305541 SME_CMD_STOP_BSS_TIMEOUT);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005542 if (QDF_IS_STATUS_ERROR(status))
Jeff Johnson5880d792016-08-15 13:32:30 -07005543 hdd_err("failure waiting for wlansap_stop_bss %d",
Dustin Brownd747ecd2018-10-26 16:32:22 -07005544 status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005545 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07005546 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005547 }
Dustin Brownd747ecd2018-10-26 16:32:22 -07005548
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005549 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Dustin Brown1dbefe62018-09-11 16:32:03 -07005550 policy_mgr_decr_session_set_pcl(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08005551 adapter->device_mode,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08005552 adapter->vdev_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -07005553 hdd_green_ap_start_state_mc(hdd_ctx,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +05305554 adapter->device_mode,
5555 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005556
Jeff Johnsonc565af12019-03-10 21:09:47 -07005557 qdf_copy_macaddr(&update_ie.bssid,
Jeff Johnson1e851a12017-10-28 14:36:12 -07005558 &adapter->mac_addr);
Jeff Johnsonc565af12019-03-10 21:09:47 -07005559 update_ie.smeSessionId = adapter->vdev_id;
5560 update_ie.ieBufferlength = 0;
5561 update_ie.pAdditionIEBuffer = NULL;
5562 update_ie.append = false;
5563 update_ie.notify = false;
Dustin Brownd747ecd2018-10-26 16:32:22 -07005564
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005565 /* Probe bcn reset */
Jeff Johnsonc565af12019-03-10 21:09:47 -07005566 status = sme_update_add_ie(mac_handle, &update_ie,
Dustin Brownd747ecd2018-10-26 16:32:22 -07005567 eUPDATE_IE_PROBE_BCN);
5568 if (status == QDF_STATUS_E_FAILURE)
5569 hdd_err("Could not pass PROBE_RSP_BCN to PE");
5570
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005571 /* Assoc resp reset */
Jeff Johnsonc565af12019-03-10 21:09:47 -07005572 status = sme_update_add_ie(mac_handle, &update_ie,
Dustin Brownd747ecd2018-10-26 16:32:22 -07005573 eUPDATE_IE_ASSOC_RESP);
5574 if (status == QDF_STATUS_E_FAILURE)
5575 hdd_err("Could not pass ASSOC_RSP to PE");
5576
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005577 /* Reset WNI_CFG_PROBE_RSP Flags */
5578 wlan_hdd_reset_prob_rspies(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005579 }
Jiachao Wub1e1ddd2018-05-21 12:04:15 +08005580 clear_bit(SOFTAP_INIT_DONE, &adapter->event_flags);
Jeff Johnsonb9424862017-10-30 08:49:35 -07005581 qdf_mem_free(adapter->session.ap.beacon);
5582 adapter->session.ap.beacon = NULL;
Jiachao Wub1e1ddd2018-05-21 12:04:15 +08005583
Ajit Pal Singh747b6802017-05-24 15:42:03 +05305584 /*
5585 * If Do_Not_Break_Stream was enabled clear avoid channel list.
5586 */
Min Liu8c5d99e2018-09-10 17:18:44 +08005587 vdev = hdd_objmgr_get_vdev(adapter);
5588 if (vdev) {
5589 if (policy_mgr_is_dnsc_set(vdev))
5590 wlan_hdd_send_avoid_freq_for_dnbs(hdd_ctx, 0);
Rajeev Kumar Sirasanagandla25bdfad2019-02-15 19:15:49 +05305591 hdd_objmgr_put_vdev(vdev);
Min Liu8c5d99e2018-09-10 17:18:44 +08005592 }
Ajit Pal Singh747b6802017-05-24 15:42:03 +05305593
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305594#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005595 cancel_work_sync(&adapter->ipv4_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305596#ifdef WLAN_NS_OFFLOAD
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005597 cancel_work_sync(&adapter->ipv6_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305598#endif
5599#endif
Dustin Browndb2a8be2017-12-20 11:49:56 -08005600
5601 hdd_vdev_destroy(adapter);
5602
Krunal Sonib51eec72017-11-20 21:53:01 -08005603 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005604 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005605 case QDF_OCB_MODE:
Dustin Brownd747ecd2018-10-26 16:32:22 -07005606 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08005607 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Dustin Brownd747ecd2018-10-26 16:32:22 -07005608 cds_get_context(QDF_MODULE_ID_TXRX),
Jeff Johnson0a082d92019-03-04 12:25:49 -08005609 sta_ctx->conn_info.sta_id[0]);
Zhang Qian79d0d132018-02-05 13:40:16 +08005610 hdd_deregister_tx_flow_control(adapter);
5611 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005612 break;
5613 default:
5614 break;
5615 }
5616
Ajit Pal Singh106c1412018-04-18 18:08:49 +05305617 hdd_deregister_hl_netdev_fc_timer(adapter);
5618
Dustin Brown04348372017-12-14 16:13:39 -08005619 if (adapter->scan_info.default_scan_ies) {
5620 qdf_mem_free(adapter->scan_info.default_scan_ies);
5621 adapter->scan_info.default_scan_ies = NULL;
5622 }
5623
Dustin Browne74003f2018-03-14 12:51:58 -07005624 hdd_exit();
Dustin Brownd747ecd2018-10-26 16:32:22 -07005625
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305626 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005627}
5628
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305629/**
5630 * hdd_deinit_all_adapters - deinit all adapters
5631 * @hdd_ctx: HDD context
5632 * @rtnl_held: True if RTNL lock held
5633 *
5634 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005635void hdd_deinit_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305636{
Jeff Johnson9d295242017-08-29 14:39:48 -07005637 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305638
Dustin Brown491d54b2018-03-14 12:39:11 -07005639 hdd_enter();
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305640
Dustin Brown920397d2017-12-13 16:27:50 -08005641 hdd_for_each_adapter(hdd_ctx, adapter)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305642 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305643
Dustin Browne74003f2018-03-14 12:51:58 -07005644 hdd_exit();
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305645}
5646
Dustin Browndb2a8be2017-12-20 11:49:56 -08005647QDF_STATUS hdd_stop_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005648{
Jeff Johnson9d295242017-08-29 14:39:48 -07005649 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005650
Dustin Brown491d54b2018-03-14 12:39:11 -07005651 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005652
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305653 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
5654
Dustin Brown920397d2017-12-13 16:27:50 -08005655 hdd_for_each_adapter(hdd_ctx, adapter)
Dustin Browndb2a8be2017-12-20 11:49:56 -08005656 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005657
Dustin Browne74003f2018-03-14 12:51:58 -07005658 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005659
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305660 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005661}
5662
Paul Zhang84fa9382017-11-10 21:18:21 +08005663static void hdd_reset_scan_operation(struct hdd_context *hdd_ctx,
5664 struct hdd_adapter *adapter)
5665{
5666 switch (adapter->device_mode) {
5667 case QDF_STA_MODE:
5668 case QDF_P2P_CLIENT_MODE:
5669 case QDF_IBSS_MODE:
5670 case QDF_P2P_DEVICE_MODE:
5671 case QDF_NDI_MODE:
5672 wlan_hdd_scan_abort(adapter);
5673 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Min Liu8c5d99e2018-09-10 17:18:44 +08005674 if (adapter->device_mode == QDF_STA_MODE) {
5675 struct wlan_objmgr_vdev *vdev;
5676
5677 vdev = hdd_objmgr_get_vdev(adapter);
5678 if (vdev) {
5679 wlan_cfg80211_sched_scan_stop(vdev);
Rajeev Kumar Sirasanagandla25bdfad2019-02-15 19:15:49 +05305680 hdd_objmgr_put_vdev(vdev);
Min Liu8c5d99e2018-09-10 17:18:44 +08005681 }
5682 }
Paul Zhang84fa9382017-11-10 21:18:21 +08005683 break;
5684 case QDF_P2P_GO_MODE:
5685 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5686 break;
5687 case QDF_SAP_MODE:
Abhinav Kumarb638b5d2018-03-26 12:25:41 +05305688 qdf_atomic_set(&adapter->session.ap.acs_in_progress, 0);
Paul Zhang84fa9382017-11-10 21:18:21 +08005689 wlan_hdd_undo_acs(adapter);
5690 break;
5691 default:
5692 break;
5693 }
5694}
5695
Ke Huangc067b8d2018-05-21 15:50:13 +08005696#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
5697/**
5698 * hdd_adapter_abort_tx_flow() - Abort the tx flow control
5699 * @pAdapter: pointer to hdd_adapter_t
5700 *
5701 * Resume tx and stop the tx flow control timer if the tx is paused
5702 * and the flow control timer is running. This function is called by
5703 * SSR to avoid the inconsistency of tx status before and after SSR.
5704 *
5705 * Return: void
5706 */
5707static void hdd_adapter_abort_tx_flow(struct hdd_adapter *adapter)
5708{
5709 if (adapter->hdd_stats.tx_rx_stats.is_txflow_paused &&
5710 QDF_TIMER_STATE_RUNNING ==
5711 qdf_mc_timer_get_current_state(
5712 &adapter->tx_flow_control_timer)) {
5713 hdd_tx_resume_timer_expired_handler(adapter);
5714 qdf_mc_timer_stop(&adapter->tx_flow_control_timer);
5715 }
5716}
5717#endif
5718
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005719QDF_STATUS hdd_reset_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005720{
Jeff Johnson9d295242017-08-29 14:39:48 -07005721 struct hdd_adapter *adapter;
Jeff Johnsond377dce2017-10-04 10:32:42 -07005722 struct hdd_station_ctx *sta_ctx;
Jeff Johnson2d044612019-02-26 20:08:43 -08005723 struct qdf_mac_addr peer_macaddr;
Yue Ma42654682018-01-11 16:55:24 -08005724 int sta_id;
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05305725 bool value;
Min Liu8c5d99e2018-09-10 17:18:44 +08005726 struct wlan_objmgr_vdev *vdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005727
Dustin Brown491d54b2018-03-14 12:39:11 -07005728 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005729
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305730 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
5731
Dustin Brown920397d2017-12-13 16:27:50 -08005732 hdd_for_each_adapter(hdd_ctx, adapter) {
Dustin Brown5e89ef82018-03-14 11:50:23 -07005733 hdd_info("[SSR] reset adapter with device mode %s(%d)",
Dustin Brown458027c2018-10-19 12:26:27 -07005734 qdf_opmode_str(adapter->device_mode),
Dustin Brown5e89ef82018-03-14 11:50:23 -07005735 adapter->device_mode);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305736
Ke Huangc067b8d2018-05-21 15:50:13 +08005737#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
5738 hdd_adapter_abort_tx_flow(adapter);
5739#endif
5740
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305741 if ((adapter->device_mode == QDF_STA_MODE) ||
Paul Zhang679025e2018-03-08 22:39:44 +08005742 (adapter->device_mode == QDF_P2P_CLIENT_MODE)) {
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305743 /* Stop tdls timers */
Min Liu8c5d99e2018-09-10 17:18:44 +08005744 vdev = hdd_objmgr_get_vdev(adapter);
5745 if (vdev) {
5746 hdd_notify_tdls_reset_adapter(vdev);
Rajeev Kumar Sirasanagandla25bdfad2019-02-15 19:15:49 +05305747 hdd_objmgr_put_vdev(vdev);
Min Liu8c5d99e2018-09-10 17:18:44 +08005748 }
Paul Zhang679025e2018-03-08 22:39:44 +08005749 adapter->session.station.hdd_reassoc_scenario = false;
5750 }
Dustin Brown05d81302018-09-11 16:49:22 -07005751 ucfg_mlme_get_sap_internal_restart(hdd_ctx->psoc, &value);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05305752 if (value &&
Arun Khandavallicc544b32017-01-30 19:52:16 +05305753 adapter->device_mode == QDF_SAP_MODE) {
5754 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305755 WLAN_STOP_ALL_NETIF_QUEUE,
Arun Khandavallicc544b32017-01-30 19:52:16 +05305756 WLAN_CONTROL_PATH);
Ashish Kumar Dhanotiyadc3900f2019-01-11 20:42:04 +05305757 if (test_bit(ACS_PENDING, &adapter->event_flags)) {
5758 cds_flush_delayed_work(
5759 &adapter->acs_pending_work);
5760 clear_bit(ACS_PENDING, &adapter->event_flags);
5761 }
5762
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005763 if (test_bit(SOFTAP_BSS_STARTED,
Ashish Kumar Dhanotiyadc3900f2019-01-11 20:42:04 +05305764 &adapter->event_flags)) {
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005765 hdd_sap_indicate_disconnect_for_sta(adapter);
Ashish Kumar Dhanotiyadc3900f2019-01-11 20:42:04 +05305766 clear_bit(SOFTAP_BSS_STARTED,
5767 &adapter->event_flags);
5768 }
5769
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005770 } else {
Arun Khandavallicc544b32017-01-30 19:52:16 +05305771 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305772 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005773 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005774 }
Nijun Gong104ccc72018-08-07 10:43:56 +08005775 /*
5776 * Clear fc flag if it was set before SSR to avoid TX queues
5777 * permanently stopped after SSR.
5778 * Here WLAN_START_ALL_NETIF_QUEUE will actually not start any
5779 * queue since it's blocked by reason WLAN_CONTROL_PATH.
5780 */
5781 if (adapter->pause_map & (1 << WLAN_DATA_FLOW_CONTROL))
5782 wlan_hdd_netif_queue_control(adapter,
5783 WLAN_START_ALL_NETIF_QUEUE,
5784 WLAN_DATA_FLOW_CONTROL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005785
Paul Zhang84fa9382017-11-10 21:18:21 +08005786 hdd_reset_scan_operation(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005787
5788 hdd_deinit_tx_rx(adapter);
Dustin Brown1dbefe62018-09-11 16:32:03 -07005789 policy_mgr_decr_session_set_pcl(hdd_ctx->psoc,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08005790 adapter->device_mode, adapter->vdev_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -07005791 hdd_green_ap_start_state_mc(hdd_ctx, adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +05305792 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005793 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
5794 hdd_wmm_adapter_close(adapter);
5795 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
5796 }
5797
Vignesh Viswanathan2eb18742017-09-08 11:18:59 +05305798 if (adapter->device_mode == QDF_STA_MODE)
5799 hdd_clear_fils_connection_info(adapter);
5800
Wu Gao3545e642017-07-14 19:24:41 +08005801 if (adapter->device_mode == QDF_SAP_MODE) {
Jingxiang Geec113592018-08-09 15:40:39 +08005802 wlansap_cleanup_cac_timer(
5803 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Wu Gao3545e642017-07-14 19:24:41 +08005804 /*
5805 * If adapter is SAP, set session ID to invalid
5806 * since SAP session will be cleanup during SSR.
5807 */
Wu Gao36717432016-11-21 15:09:48 +08005808 wlansap_set_invalid_session(
5809 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Wu Gao3545e642017-07-14 19:24:41 +08005810 }
5811
Abhishek Singh8f4aa182019-03-06 10:29:24 +05305812 /* Release vdev ref count to avoid vdev object leak */
5813 if (adapter->device_mode == QDF_P2P_GO_MODE ||
5814 adapter->device_mode == QDF_SAP_MODE)
5815 wlansap_release_vdev_ref(
5816 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
5817
Yue Ma42654682018-01-11 16:55:24 -08005818 /* Delete connection peers if any to avoid peer object leaks */
Yue Mad5b4b9f2017-05-26 16:23:40 -07005819 if (adapter->device_mode == QDF_STA_MODE ||
5820 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
Jeff Johnsond377dce2017-10-04 10:32:42 -07005821 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Jeff Johnson2d044612019-02-26 20:08:43 -08005822 qdf_copy_macaddr(&peer_macaddr,
Jeff Johnsone04b6992019-02-27 14:06:55 -08005823 &sta_ctx->conn_info.bssid);
Yue Mad5b4b9f2017-05-26 16:23:40 -07005824
Yue Ma42654682018-01-11 16:55:24 -08005825 } else if (adapter->device_mode == QDF_P2P_GO_MODE) {
Wu Gao6b81fc52018-05-24 19:27:27 +08005826 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Yue Ma42654682018-01-11 16:55:24 -08005827 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT; sta_id++) {
5828 if (adapter->sta_info[sta_id].in_use) {
5829 hdd_debug("[SSR] deregister STA with ID %d",
5830 sta_id);
5831 hdd_softap_deregister_sta(adapter,
5832 sta_id);
5833 adapter->sta_info[sta_id].in_use = 0;
5834 }
5835 }
Yue Mad5b4b9f2017-05-26 16:23:40 -07005836 }
5837
Alok Kumarb64650c2018-03-23 17:05:11 +05305838 hdd_nud_ignore_tracking(adapter, true);
Alok Kumar016a1ac2018-09-16 09:55:50 +05305839 hdd_nud_reset_tracking(adapter);
5840 hdd_nud_flush_work(adapter);
Ashish Kumar Dhanotiyadc3900f2019-01-11 20:42:04 +05305841
5842 if (adapter->device_mode != QDF_SAP_MODE &&
5843 adapter->device_mode != QDF_P2P_GO_MODE &&
5844 adapter->device_mode != QDF_FTM_MODE)
5845 hdd_set_disconnect_status(adapter, false);
5846
hangtian9c47aaf2018-11-26 17:59:39 +08005847 hdd_stop_tsf_sync(adapter);
Alok Kumarb64650c2018-03-23 17:05:11 +05305848
Tiger Yu94a5a5c2018-03-09 21:22:26 +08005849 hdd_softap_deinit_tx_rx(adapter);
Tiger Yu8c387702018-07-06 16:56:42 +08005850 hdd_deregister_tx_flow_control(adapter);
Tiger Yu94a5a5c2018-03-09 21:22:26 +08005851
Yue Maf9782842017-05-08 12:49:49 -07005852 /* Destroy vdev which will be recreated during reinit. */
5853 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005854 }
5855
Dustin Browne74003f2018-03-14 12:51:58 -07005856 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005857
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305858 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005859}
5860
Dustin Brown4c663222018-10-23 14:19:36 -07005861bool hdd_is_any_interface_open(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305862{
Dustin Brown920397d2017-12-13 16:27:50 -08005863 struct hdd_adapter *adapter;
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305864
Dustin Brown4c663222018-10-23 14:19:36 -07005865 if (hdd_get_conparam() == QDF_GLOBAL_FTM_MODE) {
Arun Khandavalliba479c42017-07-26 21:29:40 +05305866 hdd_info("FTM mode, don't close the module");
Dustin Brown4c663222018-10-23 14:19:36 -07005867 return true;
Arun Khandavalliba479c42017-07-26 21:29:40 +05305868 }
5869
Dustin Brown920397d2017-12-13 16:27:50 -08005870 hdd_for_each_adapter(hdd_ctx, adapter) {
5871 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags) ||
Dustin Brown4c663222018-10-23 14:19:36 -07005872 test_bit(SME_SESSION_OPENED, &adapter->event_flags))
5873 return true;
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305874 }
5875
Dustin Brown4c663222018-10-23 14:19:36 -07005876 return false;
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305877}
5878
yeshwanth sriram guntukaea63f632017-08-30 19:31:56 +05305879bool hdd_is_interface_up(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05305880{
5881 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
5882 return true;
5883 else
5884 return false;
5885}
5886
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305887#if defined CFG80211_CONNECT_BSS || \
5888 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305889#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305890 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305891/**
5892 * hdd_convert_timeout_reason() - Convert to kernel specific enum
5893 * @timeout_reason: reason for connect timeout
5894 *
5895 * This function is used to convert host timeout
5896 * reason enum to kernel specific enum.
5897 *
5898 * Return: nl timeout enum
5899 */
5900static enum nl80211_timeout_reason hdd_convert_timeout_reason(
5901 tSirResultCodes timeout_reason)
5902{
5903 switch (timeout_reason) {
5904 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
5905 return NL80211_TIMEOUT_SCAN;
5906 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
5907 return NL80211_TIMEOUT_AUTH;
5908 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
5909 return NL80211_TIMEOUT_ASSOC;
5910 default:
5911 return NL80211_TIMEOUT_UNSPECIFIED;
5912 }
5913}
5914
5915/**
5916 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
5917 * @dev: network device
5918 * @bssid: bssid to which we want to associate
5919 * @timeout_reason: reason for connect timeout
5920 *
5921 * This API is used to send connection timeout reason to supplicant
5922 *
5923 * Return: void
5924 */
5925static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5926 const u8 *bssid,
5927 tSirResultCodes timeout_reason)
5928{
5929 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005930
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305931 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5932
5933 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
5934 nl_timeout_reason);
5935}
5936
5937/**
5938 * __hdd_connect_bss() - API to send connection status to supplicant
5939 * @dev: network device
5940 * @bssid: bssid to which we want to associate
5941 * @req_ie: Request Information Element
5942 * @req_ie_len: len of the req IE
5943 * @resp_ie: Response IE
5944 * @resp_ie_len: len of ht response IE
5945 * @status: status
5946 * @gfp: Kernel Flag
5947 * @timeout_reason: reason for connect timeout
5948 *
5949 * Return: void
5950 */
5951static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5952 struct cfg80211_bss *bss, const u8 *req_ie,
5953 size_t req_ie_len, const u8 *resp_ie,
5954 size_t resp_ie_len, int status, gfp_t gfp,
5955 tSirResultCodes timeout_reason)
5956{
5957 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005958
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305959 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5960
5961 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5962 resp_ie, resp_ie_len, status, gfp,
5963 nl_timeout_reason);
5964}
5965#else
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305966#if defined CFG80211_CONNECT_TIMEOUT || \
5967 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305968static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5969 const u8 *bssid,
5970 tSirResultCodes timeout_reason)
5971{
5972 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
5973}
5974#endif
5975
5976static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5977 struct cfg80211_bss *bss, const u8 *req_ie,
5978 size_t req_ie_len, const u8 *resp_ie,
5979 size_t resp_ie_len, int status, gfp_t gfp,
5980 tSirResultCodes timeout_reason)
5981{
5982 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5983 resp_ie, resp_ie_len, status, gfp);
5984}
5985#endif
5986
Abhishek Singha84d3952016-09-13 13:45:05 +05305987/**
5988 * hdd_connect_bss() - API to send connection status to supplicant
5989 * @dev: network device
5990 * @bssid: bssid to which we want to associate
5991 * @req_ie: Request Information Element
5992 * @req_ie_len: len of the req IE
5993 * @resp_ie: Response IE
5994 * @resp_ie_len: len of ht response IE
5995 * @status: status
5996 * @gfp: Kernel Flag
5997 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305998 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05305999 *
6000 * The API is a wrapper to send connection status to supplicant
6001 *
6002 * Return: Void
6003 */
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05306004#if defined CFG80211_CONNECT_TIMEOUT || \
6005 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
Abhishek Singha84d3952016-09-13 13:45:05 +05306006static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
6007 struct cfg80211_bss *bss, const u8 *req_ie,
6008 size_t req_ie_len, const u8 *resp_ie,
6009 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306010 bool connect_timeout,
6011 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05306012{
6013 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306014 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05306015 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306016 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
6017 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05306018}
6019#else
6020static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
6021 struct cfg80211_bss *bss, const u8 *req_ie,
6022 size_t req_ie_len, const u8 *resp_ie,
6023 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306024 bool connect_timeout,
6025 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05306026{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306027 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
6028 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05306029}
6030#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05306031
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05306032#if defined(WLAN_FEATURE_FILS_SK)
Pragaspathi Thilagaraj9e619082019-01-24 15:15:45 +05306033#if (defined(CFG80211_CONNECT_DONE) || \
6034 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))) && \
6035 (LINUX_VERSION_CODE < KERNEL_VERSION(4, 19, 0))
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05306036#if defined(CFG80211_FILS_SK_OFFLOAD_SUPPORT) || \
6037 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306038/**
6039 * hdd_populate_fils_params() - Populate FILS keys to connect response
6040 * @fils_params: connect response to supplicant
6041 * @fils_kek: FILS kek
6042 * @fils_kek_len: FILS kek length
6043 * @pmk: FILS PMK
6044 * @pmk_len: FILS PMK length
6045 * @pmkid: PMKID
6046 * @fils_seq_num: FILS Seq number
6047 *
6048 * Return: None
6049 */
6050static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
6051 *fils_params, const uint8_t *fils_kek,
6052 size_t fils_kek_len, const uint8_t *pmk,
6053 size_t pmk_len, const uint8_t *pmkid,
6054 uint16_t fils_seq_num)
6055{
6056 /* Increament seq number to be used for next FILS */
6057 fils_params->fils_erp_next_seq_num = fils_seq_num + 1;
6058 fils_params->update_erp_next_seq_num = true;
6059 fils_params->fils_kek = fils_kek;
6060 fils_params->fils_kek_len = fils_kek_len;
6061 fils_params->pmk = pmk;
6062 fils_params->pmk_len = pmk_len;
6063 fils_params->pmkid = pmkid;
Pragaspathi Thilagaraj9e619082019-01-24 15:15:45 +05306064 hdd_debug("FILS erp_next_seq_num:%d",
6065 fils_params->fils_erp_next_seq_num);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306066}
6067#else
6068static inline void hdd_populate_fils_params(struct cfg80211_connect_resp_params
6069 *fils_params, const uint8_t
6070 *fils_kek, size_t fils_kek_len,
6071 const uint8_t *pmk, size_t pmk_len,
6072 const uint8_t *pmkid,
6073 uint16_t fils_seq_num)
6074{ }
6075#endif
6076
Pragaspathi Thilagaraj9e619082019-01-24 15:15:45 +05306077#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0))
6078/**
6079 * hdd_populate_fils_params() - Populate FILS keys to connect response
6080 * @fils_params: connect response to supplicant
6081 * @fils_kek: FILS kek
6082 * @fils_kek_len: FILS kek length
6083 * @pmk: FILS PMK
6084 * @pmk_len: FILS PMK length
6085 * @pmkid: PMKID
6086 * @fils_seq_num: FILS Seq number
6087 *
6088 * Return: None
6089 */
6090static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
6091 *fils_params, const uint8_t *fils_kek,
6092 size_t fils_kek_len, const uint8_t *pmk,
6093 size_t pmk_len, const uint8_t *pmkid,
6094 uint16_t fils_seq_num)
6095{
6096 /* Increament seq number to be used for next FILS */
6097 fils_params->fils.erp_next_seq_num = fils_seq_num + 1;
6098 fils_params->fils.update_erp_next_seq_num = true;
6099 fils_params->fils.kek = fils_kek;
6100 fils_params->fils.kek_len = fils_kek_len;
6101 fils_params->fils.pmk = pmk;
6102 fils_params->fils.pmk_len = pmk_len;
6103 fils_params->fils.pmkid = pmkid;
6104 hdd_debug("FILS erp_next_seq_num:%d",
6105 fils_params->fils.erp_next_seq_num);
6106}
6107#endif /* CFG80211_CONNECT_DONE */
6108
6109#if defined(CFG80211_CONNECT_DONE) || \
6110 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
6111
Jeff Johnson172237b2017-11-07 15:32:59 -08006112void hdd_update_hlp_info(struct net_device *dev,
6113 struct csr_roam_info *roam_info)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05306114{
6115 struct sk_buff *skb;
6116 uint16_t skb_len;
6117 struct llc_snap_hdr_t *llc_hdr;
6118 QDF_STATUS status;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306119 uint8_t *hlp_data;
6120 uint16_t hlp_data_len;
6121 struct fils_join_rsp_params *roam_fils_params
6122 = roam_info->fils_join_rsp;
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05306123 struct hdd_adapter *padapter = WLAN_HDD_GET_PRIV_PTR(dev);
6124
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306125 if (!roam_fils_params) {
6126 hdd_err("FILS Roam Param NULL");
6127 return;
6128 }
6129
Srinivas Girigowda3cc8e912017-11-28 18:11:57 -08006130 if (!roam_fils_params->hlp_data_len) {
Jianmin Zhucc6b3d02019-03-07 14:19:34 +08006131 hdd_debug("FILS HLP Data NULL, len %d",
6132 roam_fils_params->hlp_data_len);
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306133 return;
6134 }
6135
6136 hlp_data = roam_fils_params->hlp_data;
6137 hlp_data_len = roam_fils_params->hlp_data_len;
6138
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05306139 /* Calculate skb length */
6140 skb_len = (2 * ETH_ALEN) + hlp_data_len;
6141 skb = qdf_nbuf_alloc(NULL, skb_len, 0, 4, false);
Jeff Johnsond36fa332019-03-18 13:42:25 -07006142 if (!skb) {
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05306143 hdd_err("HLP packet nbuf alloc fails");
6144 return;
6145 }
6146
6147 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->dst_mac.bytes,
6148 QDF_MAC_ADDR_SIZE);
6149 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->src_mac.bytes,
6150 QDF_MAC_ADDR_SIZE);
6151
6152 llc_hdr = (struct llc_snap_hdr_t *) hlp_data;
6153 if (IS_SNAP(llc_hdr)) {
6154 hlp_data += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
6155 hlp_data_len += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
6156 }
6157
6158 qdf_mem_copy(skb_put(skb, hlp_data_len), hlp_data, hlp_data_len);
6159
6160 /*
6161 * This HLP packet is formed from HLP info encapsulated
6162 * in assoc response frame which is AEAD encrypted.
6163 * Hence, this checksum validation can be set unnecessary.
6164 * i.e. network layer need not worry about checksum.
6165 */
6166 skb->ip_summed = CHECKSUM_UNNECESSARY;
6167
6168 status = hdd_rx_packet_cbk(padapter, skb);
6169 if (QDF_IS_STATUS_ERROR(status)) {
6170 hdd_err("Sending HLP packet fails");
6171 return;
6172 }
6173 hdd_debug("send HLP packet to netif successfully");
6174}
6175
6176/**
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306177 * hdd_connect_done() - Wrapper API to call cfg80211_connect_done
6178 * @dev: network device
6179 * @bssid: bssid to which we want to associate
6180 * @bss: cfg80211 bss info
6181 * @roam_info: information about connected bss
6182 * @req_ie: Request Information Element
6183 * @req_ie_len: len of the req IE
6184 * @resp_ie: Response IE
6185 * @resp_ie_len: len of ht response IE
6186 * @status: status
6187 * @gfp: allocation flags
6188 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
6189 * @timeout_reason: reason for connect timeout
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306190 *
6191 * This API is used as wrapper to send FILS key/sequence number
6192 * params etc. to supplicant in case of FILS connection
6193 *
6194 * Return: None
6195 */
6196static void hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08006197 struct cfg80211_bss *bss,
6198 struct csr_roam_info *roam_info,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306199 const u8 *req_ie, size_t req_ie_len,
6200 const u8 *resp_ie, size_t resp_ie_len, u16 status,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07006201 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306202 tSirResultCodes timeout_reason)
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306203{
6204 struct cfg80211_connect_resp_params fils_params;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306205 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
6206 struct fils_join_rsp_params *roam_fils_params =
6207 roam_info->fils_join_rsp;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07006208
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306209 qdf_mem_zero(&fils_params, sizeof(fils_params));
6210
6211 if (!roam_fils_params) {
6212 fils_params.status = WLAN_STATUS_UNSPECIFIED_FAILURE;
6213 } else {
6214 fils_params.status = status;
6215 fils_params.bssid = bssid;
Srinivas Girigowdae975f532018-01-05 14:03:05 -08006216 fils_params.timeout_reason =
6217 hdd_convert_timeout_reason(timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306218 fils_params.req_ie = req_ie;
6219 fils_params.req_ie_len = req_ie_len;
6220 fils_params.resp_ie = resp_ie;
6221 fils_params.resp_ie_len = resp_ie_len;
6222 fils_params.bss = bss;
6223 hdd_populate_fils_params(&fils_params, roam_fils_params->kek,
6224 roam_fils_params->kek_len,
6225 roam_fils_params->fils_pmk,
6226 roam_fils_params->fils_pmk_len,
6227 roam_fils_params->fils_pmkid,
6228 roam_info->fils_seq_num);
Sridhar Selvaraje5260442017-08-19 10:12:03 +05306229 hdd_save_gtk_params(adapter, roam_info, false);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306230 }
Pragaspathi Thilagaraj9e619082019-01-24 15:15:45 +05306231 hdd_debug("FILS indicate connect status %d", fils_params.status);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306232
6233 cfg80211_connect_done(dev, &fils_params, gfp);
6234
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05306235 if (roam_fils_params && roam_fils_params->hlp_data_len)
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306236 hdd_update_hlp_info(dev, roam_info);
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05306237
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306238 /* Clear all the FILS key info */
6239 if (roam_fils_params && roam_fils_params->fils_pmk)
6240 qdf_mem_free(roam_fils_params->fils_pmk);
6241 if (roam_fils_params)
6242 qdf_mem_free(roam_fils_params);
6243 roam_info->fils_join_rsp = NULL;
6244}
Pragaspathi Thilagaraj9e619082019-01-24 15:15:45 +05306245#else /* CFG80211_CONNECT_DONE */
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07006246static inline void
6247hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08006248 struct cfg80211_bss *bss, struct csr_roam_info *roam_info,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07006249 const u8 *req_ie, size_t req_ie_len,
6250 const u8 *resp_ie, size_t resp_ie_len, u16 status,
6251 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306252 tSirResultCodes timeout_reason)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05306253{ }
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306254#endif
Pragaspathi Thilagaraj9e619082019-01-24 15:15:45 +05306255#endif /* WLAN_FEATURE_FILS_SK */
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306256
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05306257#if defined(WLAN_FEATURE_FILS_SK) && \
6258 (defined(CFG80211_CONNECT_DONE) || \
6259 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0)))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306260/**
6261 * hdd_fils_update_connect_results() - API to send fils connection status to
6262 * supplicant.
6263 * @dev: network device
6264 * @bssid: bssid to which we want to associate
6265 * @bss: cfg80211 bss info
6266 * @roam_info: information about connected bss
6267 * @req_ie: Request Information Element
6268 * @req_ie_len: len of the req IE
6269 * @resp_ie: Response IE
6270 * @resp_ie_len: len of ht response IE
6271 * @status: status
6272 * @gfp: allocation flags
6273 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
6274 * @timeout_reason: reason for connect timeout
6275 *
6276 * The API is a wrapper to send connection status to supplicant
6277 *
6278 * Return: 0 if success else failure
6279 */
6280static int hdd_fils_update_connect_results(struct net_device *dev,
6281 const u8 *bssid,
6282 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08006283 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306284 size_t req_ie_len, const u8 *resp_ie,
6285 size_t resp_ie_len, u16 status, gfp_t gfp,
6286 bool connect_timeout,
6287 tSirResultCodes timeout_reason)
6288{
Dustin Brown491d54b2018-03-14 12:39:11 -07006289 hdd_enter();
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306290 if (!roam_info || !roam_info->is_fils_connection)
6291 return -EINVAL;
6292
6293 hdd_connect_done(dev, bssid, bss, roam_info, req_ie, req_ie_len,
6294 resp_ie, resp_ie_len, status, gfp, connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306295 timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306296 return 0;
6297}
6298#else
6299static inline int hdd_fils_update_connect_results(struct net_device *dev,
6300 const u8 *bssid,
6301 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08006302 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306303 size_t req_ie_len, const u8 *resp_ie,
6304 size_t resp_ie_len, u16 status, gfp_t gfp,
6305 bool connect_timeout,
6306 tSirResultCodes timeout_reason)
6307{
6308 return -EINVAL;
6309}
6310#endif
6311
Anurag Chouhanc4092922016-09-08 15:56:11 +05306312/**
6313 * hdd_connect_result() - API to send connection status to supplicant
6314 * @dev: network device
6315 * @bssid: bssid to which we want to associate
6316 * @roam_info: information about connected bss
6317 * @req_ie: Request Information Element
6318 * @req_ie_len: len of the req IE
6319 * @resp_ie: Response IE
6320 * @resp_ie_len: len of ht response IE
6321 * @status: status
6322 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05306323 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306324 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05306325 *
6326 * The API is a wrapper to send connection status to supplicant
6327 * and allow runtime suspend
6328 *
6329 * Return: Void
6330 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05306331void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08006332 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05306333 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05306334 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306335 bool connect_timeout,
6336 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05306337{
Jeff Johnson9d295242017-08-29 14:39:48 -07006338 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306339 struct cfg80211_bss *bss = NULL;
Jingxiang Ge929c7932018-01-24 14:01:12 +08006340 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(padapter);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306341
6342 if (WLAN_STATUS_SUCCESS == status) {
6343 struct ieee80211_channel *chan;
6344 int freq;
6345 int chan_no = roam_info->pBssDesc->channelId;
6346
6347 if (chan_no <= 14)
6348 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07006349 HDD_NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306350 else
6351 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07006352 HDD_NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306353
6354 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
Abhishek Singh59cdca12019-03-08 13:48:20 +05306355 bss = wlan_cfg80211_get_bss(padapter->wdev.wiphy, chan, bssid,
Anurag Chouhanc4092922016-09-08 15:56:11 +05306356 roam_info->u.pConnectedProfile->SSID.ssId,
6357 roam_info->u.pConnectedProfile->SSID.length);
6358 }
Komal Seelama89be8d2016-09-29 11:09:26 +05306359
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306360 if (hdd_fils_update_connect_results(dev, bssid, bss,
6361 roam_info, req_ie, req_ie_len, resp_ie,
6362 resp_ie_len, status, gfp, connect_timeout,
6363 timeout_reason) != 0) {
6364 hdd_connect_bss(dev, bssid, bss, req_ie,
6365 req_ie_len, resp_ie, resp_ie_len,
6366 status, gfp, connect_timeout, timeout_reason);
6367 }
Komal Seelama89be8d2016-09-29 11:09:26 +05306368
Jingxiang Geb49aa302018-01-17 20:54:15 +08006369 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07006370 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306371}
6372#else
6373void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08006374 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05306375 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05306376 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306377 bool connect_timeout,
6378 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05306379{
Jeff Johnson9d295242017-08-29 14:39:48 -07006380 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Jingxiang Ge929c7932018-01-24 14:01:12 +08006381 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(padapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05306382
Anurag Chouhanc4092922016-09-08 15:56:11 +05306383 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
6384 resp_ie, resp_ie_len, status, gfp);
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08006385
Jingxiang Geb49aa302018-01-17 20:54:15 +08006386 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07006387 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306388}
6389#endif
6390
Nirav Shah73713f72018-05-17 14:50:41 +05306391#ifdef FEATURE_MONITOR_MODE_SUPPORT
Jeff Johnsond9952752018-04-18 12:15:35 -07006392int wlan_hdd_set_mon_chan(struct hdd_adapter *adapter, uint32_t chan,
6393 uint32_t bandwidth)
6394{
6395 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6396 struct hdd_station_ctx *sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
6397 struct hdd_mon_set_ch_info *ch_info = &sta_ctx->ch_info;
6398 QDF_STATUS status;
Jeff Johnson43837af2018-10-17 12:44:05 -07006399 mac_handle_t mac_handle = hdd_ctx->mac_handle;
Jeff Johnsond9952752018-04-18 12:15:35 -07006400 struct qdf_mac_addr bssid;
6401 struct csr_roam_profile roam_profile;
6402 struct ch_params ch_params;
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006403 eConnectionState connstate;
Jeff Johnsond9952752018-04-18 12:15:35 -07006404
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006405 if (hdd_get_conparam() != QDF_GLOBAL_MONITOR_MODE &&
6406 adapter->device_mode != QDF_STA_MODE) {
6407 hdd_err("Not supported, device is not in monitor mode or sta mission mode");
Jeff Johnsond9952752018-04-18 12:15:35 -07006408 return -EINVAL;
6409 }
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006410 if (adapter->device_mode == QDF_STA_MODE &&
Pragaspathi Thilagaraja8893752019-02-06 19:58:59 +05306411 ucfg_mlme_is_change_channel_bandwidth_enabled(hdd_ctx->psoc)) {
Jeff Johnsone7951512019-02-27 10:02:51 -08006412 connstate = sta_ctx->conn_info.conn_state;
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006413 if (eConnectionState_Associated == connstate ||
6414 eConnectionState_Connecting == connstate) {
6415 return -EINVAL;
6416 }
6417 }
Jeff Johnsond9952752018-04-18 12:15:35 -07006418
Visweswara Tanuku006313a2018-04-12 12:26:34 +05306419 /* Validate Channel */
6420 if (!WLAN_REG_IS_24GHZ_CH(chan) && !WLAN_REG_IS_5GHZ_CH(chan)) {
6421 hdd_err("Channel %d Not supported", chan);
6422 return -EINVAL;
6423 }
6424
6425 if (WLAN_REG_IS_24GHZ_CH(chan)) {
6426 if (bandwidth == CH_WIDTH_80MHZ) {
6427 hdd_err("BW80 not possible in 2.4GHz band");
6428 return -EINVAL;
6429 }
6430 if ((bandwidth != CH_WIDTH_20MHZ) && (chan == 14) &&
6431 (bandwidth != CH_WIDTH_MAX)) {
6432 hdd_err("Only BW20 possible on channel 14");
6433 return -EINVAL;
6434 }
6435 }
6436
6437 if (WLAN_REG_IS_5GHZ_CH(chan)) {
6438 if ((bandwidth != CH_WIDTH_20MHZ) && (chan == 165) &&
6439 (bandwidth != CH_WIDTH_MAX)) {
6440 hdd_err("Only BW20 possible on channel 165");
6441 return -EINVAL;
6442 }
6443 }
6444
Jeff Johnsond9952752018-04-18 12:15:35 -07006445 hdd_debug("Set monitor mode Channel %d", chan);
6446 qdf_mem_zero(&roam_profile, sizeof(roam_profile));
6447 roam_profile.ChannelInfo.ChannelList = &ch_info->channel;
6448 roam_profile.ChannelInfo.numOfChannels = 1;
6449 roam_profile.phyMode = ch_info->phy_mode;
6450 roam_profile.ch_params.ch_width = bandwidth;
6451 hdd_select_cbmode(adapter, chan, &roam_profile.ch_params);
Pragaspathi Thilagaraja8893752019-02-06 19:58:59 +05306452 if (ucfg_mlme_is_change_channel_bandwidth_enabled(hdd_ctx->psoc) &&
Jeff Johnson43837af2018-10-17 12:44:05 -07006453 (!sme_find_session_by_bssid(mac_handle, adapter->mac_addr.bytes))) {
6454 status = sme_create_mon_session(mac_handle,
Rajeev Kumar Sirasanagandlae3b59912018-08-24 15:53:31 +05306455 adapter->mac_addr.bytes,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08006456 adapter->vdev_id);
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006457 if (status != QDF_STATUS_SUCCESS) {
6458 hdd_err("Status: %d Failed to create session.",
6459 status);
6460 return qdf_status_to_os_return(status);
6461 }
6462 }
Jeff Johnsond9952752018-04-18 12:15:35 -07006463 qdf_mem_copy(bssid.bytes, adapter->mac_addr.bytes,
6464 QDF_MAC_ADDR_SIZE);
6465
6466 ch_params.ch_width = bandwidth;
Dustin Brown07901ec2018-09-07 11:02:41 -07006467 wlan_reg_set_channel_params(hdd_ctx->pdev, chan, 0, &ch_params);
Jeff Johnsond9952752018-04-18 12:15:35 -07006468 if (ch_params.ch_width == CH_WIDTH_INVALID) {
6469 hdd_err("Invalid capture channel or bandwidth for a country");
6470 return -EINVAL;
6471 }
6472 if (wlan_hdd_change_hw_mode_for_given_chnl(adapter, chan,
6473 POLICY_MGR_UPDATE_REASON_SET_OPER_CHAN)) {
6474 hdd_err("Failed to change hw mode");
6475 return -EINVAL;
6476 }
6477
Jeff Johnson16528362018-06-14 12:34:16 -07006478 status = sme_roam_channel_change_req(hdd_ctx->mac_handle,
6479 bssid, &ch_params,
Jeff Johnsond9952752018-04-18 12:15:35 -07006480 &roam_profile);
6481 if (status) {
6482 hdd_err("Status: %d Failed to set sme_roam Channel for monitor mode",
6483 status);
6484 }
6485
6486 adapter->mon_chan = chan;
6487 adapter->mon_bandwidth = bandwidth;
6488 return qdf_status_to_os_return(status);
6489}
Nirav Shah73713f72018-05-17 14:50:41 +05306490#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05306491
Wu Gaodf929f12018-05-25 18:12:25 +08006492#ifdef MSM_PLATFORM
6493/**
6494 * hdd_stop_p2p_go() - call cfg80211 API to stop P2P GO
6495 * @adapter: pointer to adapter
6496 *
6497 * This function calls cfg80211 API to stop P2P GO
6498 *
6499 * Return: None
6500 */
6501static void hdd_stop_p2p_go(struct hdd_adapter *adapter)
6502{
6503 hdd_debug("[SSR] send stop ap to supplicant");
6504 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
6505}
6506
6507static inline void hdd_delete_sta(struct hdd_adapter *adapter)
6508{
6509}
6510#else
6511static inline void hdd_stop_p2p_go(struct hdd_adapter *adapter)
6512{
6513}
6514
6515/**
6516 * hdd_delete_sta() - call cfg80211 API to delete STA
6517 * @adapter: pointer to adapter
6518 *
6519 * This function calls cfg80211 API to delete STA
6520 *
6521 * Return: None
6522 */
6523static void hdd_delete_sta(struct hdd_adapter *adapter)
6524{
6525 struct qdf_mac_addr bcast_mac = QDF_MAC_ADDR_BCAST_INIT;
6526
6527 hdd_debug("[SSR] send restart supplicant");
6528 /* event supplicant to restart */
6529 cfg80211_del_sta(adapter->dev,
6530 (const u8 *)&bcast_mac.bytes[0],
6531 GFP_KERNEL);
6532}
6533#endif
6534
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006535QDF_STATUS hdd_start_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006536{
Jeff Johnson9d295242017-08-29 14:39:48 -07006537 struct hdd_adapter *adapter;
Jeff Johnsone7951512019-02-27 10:02:51 -08006538 eConnectionState conn_state;
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05306539 bool value;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006540
Dustin Brown491d54b2018-03-14 12:39:11 -07006541 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006542
Dustin Brown920397d2017-12-13 16:27:50 -08006543 hdd_for_each_adapter(hdd_ctx, adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05306544 if (!hdd_is_interface_up(adapter))
Dustin Brown920397d2017-12-13 16:27:50 -08006545 continue;
Arun Khandavallifae92942016-08-01 13:31:08 +05306546
Yue Ma42654682018-01-11 16:55:24 -08006547 hdd_debug("[SSR] start adapter with device mode %s(%d)",
Dustin Brown458027c2018-10-19 12:26:27 -07006548 qdf_opmode_str(adapter->device_mode),
Yue Ma42654682018-01-11 16:55:24 -08006549 adapter->device_mode);
6550
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006551 hdd_wmm_init(adapter);
6552
6553 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006554 case QDF_STA_MODE:
6555 case QDF_P2P_CLIENT_MODE:
6556 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006557
Jeff Johnsone7951512019-02-27 10:02:51 -08006558 conn_state = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
6559 ->conn_info.conn_state;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006560
Krunal Sonib51eec72017-11-20 21:53:01 -08006561 hdd_start_station_adapter(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006562 /* Open the gates for HDD to receive Wext commands */
Jeff Johnsonc72c5732017-10-28 12:49:37 -07006563 adapter->is_link_up_service_needed = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006564
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006565 /* Indicate disconnect event to supplicant
6566 * if associated previously
6567 */
Jeff Johnsone7951512019-02-27 10:02:51 -08006568 if (eConnectionState_Associated == conn_state ||
6569 eConnectionState_IbssConnected == conn_state ||
6570 eConnectionState_NotConnected == conn_state ||
6571 eConnectionState_IbssDisconnected == conn_state ||
6572 eConnectionState_Disconnecting == conn_state) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006573 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006574
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006575 memset(&wrqu, '\0', sizeof(wrqu));
6576 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
6577 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
6578 wireless_send_event(adapter->dev, SIOCGIWAP,
6579 &wrqu, NULL);
Jeff Johnsonb9424862017-10-30 08:49:35 -07006580 adapter->session.station.
Jeff Johnson690fe952017-10-25 11:48:39 -07006581 hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006582
6583 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05306584 wlan_hdd_cfg80211_indicate_disconnect(
6585 adapter->dev, false,
6586 WLAN_REASON_UNSPECIFIED);
Jeff Johnsone7951512019-02-27 10:02:51 -08006587 } else if (eConnectionState_Connecting == conn_state) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006588 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006589 * Indicate connect failure to supplicant if we
6590 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006591 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05306592 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306593 NULL, 0, NULL, 0,
6594 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006595 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006596 }
6597
6598 hdd_register_tx_flow_control(adapter,
6599 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08006600 hdd_tx_resume_cb,
6601 hdd_tx_flow_control_is_pause);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006602
Arunk Khandavalli40943af2017-05-15 19:25:34 +05306603 hdd_lpass_notify_start(hdd_ctx, adapter);
Alok Kumarb64650c2018-03-23 17:05:11 +05306604 hdd_nud_ignore_tracking(adapter, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006605 break;
6606
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006607 case QDF_SAP_MODE:
Dustin Brown05d81302018-09-11 16:49:22 -07006608 ucfg_mlme_get_sap_internal_restart(hdd_ctx->psoc,
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05306609 &value);
6610 if (value)
Krunal Sonib51eec72017-11-20 21:53:01 -08006611 hdd_start_ap_adapter(adapter);
Arun Khandavallicc544b32017-01-30 19:52:16 +05306612
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006613 break;
6614
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006615 case QDF_P2P_GO_MODE:
Wu Gaodf929f12018-05-25 18:12:25 +08006616 hdd_delete_sta(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006617 break;
Arunk Khandavalli062fb032017-10-04 12:18:15 +05306618 case QDF_MONITOR_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08006619 hdd_start_station_adapter(adapter);
Arunk Khandavalli062fb032017-10-04 12:18:15 +05306620 hdd_set_mon_rx_cb(adapter->dev);
6621 wlan_hdd_set_mon_chan(adapter, adapter->mon_chan,
6622 adapter->mon_bandwidth);
6623 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006624 default:
6625 break;
6626 }
Krunal Soni9c2ee032017-07-18 13:49:54 -07006627 /*
6628 * Action frame registered in one adapter which will
6629 * applicable to all interfaces
6630 */
6631 wlan_hdd_cfg80211_register_frames(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006632 }
6633
Wu Gaodf929f12018-05-25 18:12:25 +08006634 hdd_for_each_adapter(hdd_ctx, adapter) {
6635 if (!hdd_is_interface_up(adapter))
6636 continue;
6637
6638 if (adapter->device_mode == QDF_P2P_GO_MODE)
6639 hdd_stop_p2p_go(adapter);
6640 }
6641
Dustin Browne74003f2018-03-14 12:51:58 -07006642 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006643
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306644 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006645}
6646
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006647QDF_STATUS hdd_get_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006648 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006649{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306650 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006651 qdf_list_node_t *node;
6652
6653 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006654
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006655 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006656 status = qdf_list_peek_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006657 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006658
6659 if (QDF_IS_STATUS_ERROR(status))
6660 return status;
6661
6662 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6663
6664 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006665}
6666
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006667QDF_STATUS hdd_get_next_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006668 struct hdd_adapter *current_adapter,
6669 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006670{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306671 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006672 qdf_list_node_t *node;
6673
6674 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006675
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006676 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Jeff Johnson19fc8e42017-10-30 19:53:49 -07006677 status = qdf_list_peek_next(&hdd_ctx->hdd_adapters,
Dustin Brown920397d2017-12-13 16:27:50 -08006678 &current_adapter->node,
6679 &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006680 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006681
6682 if (QDF_IS_STATUS_ERROR(status))
6683 return status;
6684
6685 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6686
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006687 return status;
6688}
6689
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006690QDF_STATUS hdd_remove_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006691 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006692{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306693 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006694
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006695 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006696 status = qdf_list_remove_node(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006697 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006698
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006699 return status;
6700}
6701
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006702QDF_STATUS hdd_remove_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006703 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006704{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306705 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006706 qdf_list_node_t *node;
6707
6708 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006709
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006710 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006711 status = qdf_list_remove_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006712 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006713
6714 if (QDF_IS_STATUS_ERROR(status))
6715 return status;
6716
6717 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6718
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006719 return status;
6720}
6721
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006722QDF_STATUS hdd_add_adapter_back(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006723 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006724{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306725 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006726
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006727 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006728 status = qdf_list_insert_back(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006729 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006730
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006731 return status;
6732}
6733
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006734QDF_STATUS hdd_add_adapter_front(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006735 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006736{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306737 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006738
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006739 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006740 status = qdf_list_insert_front(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006741 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006742
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006743 return status;
6744}
6745
Liangwei Dong3abfe8f2018-09-20 02:25:44 -04006746struct hdd_adapter *hdd_get_adapter_by_rand_macaddr(
6747 struct hdd_context *hdd_ctx, tSirMacAddr mac_addr)
6748{
6749 struct hdd_adapter *adapter;
6750
6751 hdd_for_each_adapter(hdd_ctx, adapter) {
6752 if ((adapter->device_mode == QDF_STA_MODE ||
6753 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6754 adapter->device_mode == QDF_P2P_DEVICE_MODE) &&
6755 ucfg_p2p_check_random_mac(hdd_ctx->psoc,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08006756 adapter->vdev_id, mac_addr))
Liangwei Dong3abfe8f2018-09-20 02:25:44 -04006757 return adapter;
6758 }
6759
6760 return NULL;
6761}
6762
Jeff Johnson9d295242017-08-29 14:39:48 -07006763struct hdd_adapter *hdd_get_adapter_by_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07006764 tSirMacAddr mac_addr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006765{
Jeff Johnson9d295242017-08-29 14:39:48 -07006766 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006767
Dustin Brown920397d2017-12-13 16:27:50 -08006768 hdd_for_each_adapter(hdd_ctx, adapter) {
6769 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07006770 mac_addr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006771 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006772 }
6773
6774 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006775}
6776
Jeff Johnson9d295242017-08-29 14:39:48 -07006777struct hdd_adapter *hdd_get_adapter_by_vdev(struct hdd_context *hdd_ctx,
Jeff Johnson55d2ab42019-03-06 11:43:49 -08006778 uint32_t vdev_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006779{
Jeff Johnson9d295242017-08-29 14:39:48 -07006780 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006781
Dustin Brown920397d2017-12-13 16:27:50 -08006782 hdd_for_each_adapter(hdd_ctx, adapter) {
Jeff Johnson5a6fc962019-02-04 14:20:25 -08006783 if (adapter->vdev_id == vdev_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006784 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006785 }
6786
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006787 return NULL;
6788}
6789
Jeff Johnson9d295242017-08-29 14:39:48 -07006790struct hdd_adapter *hdd_get_adapter_by_iface_name(struct hdd_context *hdd_ctx,
Naveen Rawat4edb6822017-04-12 10:09:17 -07006791 const char *iface_name)
6792{
Jeff Johnson9d295242017-08-29 14:39:48 -07006793 struct hdd_adapter *adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07006794
Dustin Brown920397d2017-12-13 16:27:50 -08006795 hdd_for_each_adapter(hdd_ctx, adapter) {
6796 if (!qdf_str_cmp(adapter->dev->name, iface_name))
Naveen Rawat4edb6822017-04-12 10:09:17 -07006797 return adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07006798 }
Dustin Brown920397d2017-12-13 16:27:50 -08006799
Naveen Rawat4edb6822017-04-12 10:09:17 -07006800 return NULL;
6801}
6802
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006803/**
6804 * hdd_get_adapter() - to get adapter matching the mode
6805 * @hdd_ctx: hdd context
6806 * @mode: adapter mode
6807 *
6808 * This routine will return the pointer to adapter matching
6809 * with the passed mode.
6810 *
6811 * Return: pointer to adapter or null
6812 */
Jeff Johnson9d295242017-08-29 14:39:48 -07006813struct hdd_adapter *hdd_get_adapter(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08006814 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006815{
Jeff Johnson9d295242017-08-29 14:39:48 -07006816 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006817
Dustin Brown920397d2017-12-13 16:27:50 -08006818 hdd_for_each_adapter(hdd_ctx, adapter) {
6819 if (adapter->device_mode == mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006820 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006821 }
6822
6823 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006824}
6825
Jeff Johnson55d2ab42019-03-06 11:43:49 -08006826enum QDF_OPMODE hdd_get_device_mode(uint32_t vdev_id)
Yeshwanth Sriram Guntuka469f9572018-02-12 13:28:22 +05306827{
6828 struct hdd_context *hdd_ctx;
6829 struct hdd_adapter *adapter;
6830
6831 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
6832 if (!hdd_ctx) {
6833 hdd_err("Invalid HDD context");
6834 return QDF_MAX_NO_OF_MODE;
6835 }
6836
Jeff Johnson55d2ab42019-03-06 11:43:49 -08006837 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
Yeshwanth Sriram Guntuka469f9572018-02-12 13:28:22 +05306838 if (!adapter) {
6839 hdd_err("Invalid HDD adapter");
6840 return QDF_MAX_NO_OF_MODE;
6841 }
6842
6843 return adapter->device_mode;
6844}
6845
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006846/**
6847 * hdd_get_operating_channel() - return operating channel of the device mode
6848 * @hdd_ctx: Pointer to the HDD context.
6849 * @mode: Device mode for which operating channel is required.
Jeff Johnson77f89bb2018-05-06 16:21:36 -07006850 * Supported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006851 * QDF_STA_MODE,
6852 * QDF_P2P_CLIENT_MODE,
6853 * QDF_SAP_MODE,
6854 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006855 *
6856 * This API returns the operating channel of the requested device mode
6857 *
6858 * Return: channel number. "0" id the requested device is not found OR it is
6859 * not connected.
6860 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006861uint8_t hdd_get_operating_channel(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08006862 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006863{
Jeff Johnson9d295242017-08-29 14:39:48 -07006864 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006865 uint8_t operatingChannel = 0;
6866
Dustin Brown920397d2017-12-13 16:27:50 -08006867 hdd_for_each_adapter(hdd_ctx, adapter) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006868 if (mode == adapter->device_mode) {
6869 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006870 case QDF_STA_MODE:
6871 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006872 if (hdd_conn_is_connected
6873 (WLAN_HDD_GET_STATION_CTX_PTR
6874 (adapter))) {
6875 operatingChannel =
6876 (WLAN_HDD_GET_STATION_CTX_PTR
6877 (adapter))->conn_info.
Jeff Johnson8626e932019-02-27 18:35:22 -08006878 channel;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006879 }
6880 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006881 case QDF_SAP_MODE:
6882 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006883 /* softap connection info */
6884 if (test_bit
6885 (SOFTAP_BSS_STARTED,
6886 &adapter->event_flags))
6887 operatingChannel =
6888 (WLAN_HDD_GET_AP_CTX_PTR
Jeff Johnson01206862017-10-27 20:55:59 -07006889 (adapter))->operating_channel;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006890 break;
6891 default:
6892 break;
6893 }
6894
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006895 /* Found the device of interest. break the loop */
6896 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006897 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006898 }
Dustin Brown920397d2017-12-13 16:27:50 -08006899
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006900 return operatingChannel;
6901}
6902
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006903static inline QDF_STATUS hdd_unregister_wext_all_adapters(struct hdd_context *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006904 hdd_ctx)
6905{
Jeff Johnson9d295242017-08-29 14:39:48 -07006906 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006907
Dustin Brown491d54b2018-03-14 12:39:11 -07006908 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006909
Dustin Brown920397d2017-12-13 16:27:50 -08006910 hdd_for_each_adapter(hdd_ctx, adapter) {
6911 if (adapter->device_mode == QDF_STA_MODE ||
6912 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6913 adapter->device_mode == QDF_IBSS_MODE ||
6914 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6915 adapter->device_mode == QDF_SAP_MODE ||
6916 adapter->device_mode == QDF_P2P_GO_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006917 hdd_unregister_wext(adapter->dev);
6918 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006919 }
6920
Dustin Browne74003f2018-03-14 12:51:58 -07006921 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006922
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306923 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006924}
6925
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006926QDF_STATUS hdd_abort_mac_scan_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006927{
Jeff Johnson9d295242017-08-29 14:39:48 -07006928 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006929
Dustin Brown491d54b2018-03-14 12:39:11 -07006930 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006931
Dustin Brown920397d2017-12-13 16:27:50 -08006932 hdd_for_each_adapter(hdd_ctx, adapter) {
6933 if (adapter->device_mode == QDF_STA_MODE ||
6934 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6935 adapter->device_mode == QDF_IBSS_MODE ||
6936 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6937 adapter->device_mode == QDF_SAP_MODE ||
6938 adapter->device_mode == QDF_P2P_GO_MODE) {
Dustin Brown07901ec2018-09-07 11:02:41 -07006939 wlan_abort_scan(hdd_ctx->pdev, INVAL_PDEV_ID,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08006940 adapter->vdev_id, INVALID_SCAN_ID,
Vignesh Viswanathan19611c82018-01-16 16:20:40 +05306941 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006942 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006943 }
6944
Dustin Browne74003f2018-03-14 12:51:58 -07006945 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006946
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306947 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006948}
6949
Dustin Brownf27bce82016-11-03 12:52:27 -07006950/**
6951 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
6952 * adapters
6953 * @hdd_ctx: The HDD context containing the adapters to operate on
6954 *
6955 * return: QDF_STATUS_SUCCESS
6956 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006957static QDF_STATUS hdd_abort_sched_scan_all_adapters(struct hdd_context *hdd_ctx)
Dustin Brownf27bce82016-11-03 12:52:27 -07006958{
Jeff Johnson9d295242017-08-29 14:39:48 -07006959 struct hdd_adapter *adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07006960 int err;
6961
Dustin Brown491d54b2018-03-14 12:39:11 -07006962 hdd_enter();
Dustin Brownf27bce82016-11-03 12:52:27 -07006963
Dustin Brown920397d2017-12-13 16:27:50 -08006964 hdd_for_each_adapter(hdd_ctx, adapter) {
6965 if (adapter->device_mode == QDF_STA_MODE ||
6966 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6967 adapter->device_mode == QDF_IBSS_MODE ||
6968 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6969 adapter->device_mode == QDF_SAP_MODE ||
6970 adapter->device_mode == QDF_P2P_GO_MODE) {
Dustin Brownf27bce82016-11-03 12:52:27 -07006971 err = wlan_hdd_sched_scan_stop(adapter->dev);
6972 if (err)
6973 hdd_err("Unable to stop scheduled scan");
6974 }
Dustin Brownf27bce82016-11-03 12:52:27 -07006975 }
6976
Dustin Browne74003f2018-03-14 12:51:58 -07006977 hdd_exit();
Dustin Brownf27bce82016-11-03 12:52:27 -07006978
6979 return QDF_STATUS_SUCCESS;
6980}
6981
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006982#ifdef WLAN_NS_OFFLOAD
6983/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006984 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006985 * @hdd_ctx: Pointer to hdd context
6986 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006987 * Unregister for IPv6 address change notifications.
6988 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006989 * Return: None
6990 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006991static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006992{
6993 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006994}
6995
6996/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006997 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006998 * @hdd_ctx: Pointer to hdd context
6999 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007000 * Register for IPv6 address change notifications.
7001 *
7002 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007003 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007004static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007005{
7006 int ret;
7007
7008 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
7009 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007010 if (ret) {
7011 hdd_err("Failed to register IPv6 notifier: %d", ret);
7012 goto out;
7013 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007014
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007015 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007016out:
7017 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007018}
7019#else
7020/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007021 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007022 * @hdd_ctx: Pointer to hdd context
7023 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007024 * Unregister for IPv6 address change notifications.
7025 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007026 * Return: None
7027 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007028static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007029{
7030}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007031
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007032/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007033 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007034 * @hdd_ctx: Pointer to hdd context
7035 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007036 * Register for IPv6 address change notifications.
7037 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007038 * Return: None
7039 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007040static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007041{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007042 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007043}
7044#endif
7045
Alok Kumarb64650c2018-03-23 17:05:11 +05307046void hdd_set_disconnect_status(struct hdd_adapter *adapter, bool status)
7047{
7048 qdf_mutex_acquire(&adapter->disconnection_status_lock);
7049 adapter->disconnection_in_progress = status;
7050 qdf_mutex_release(&adapter->disconnection_status_lock);
7051 hdd_debug("setting disconnection status: %d", status);
7052}
7053
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007054/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007055 * hdd_register_notifiers - Register netdev notifiers.
7056 * @hdd_ctx: HDD context
7057 *
7058 * Register netdev notifiers like IPv4 and IPv6.
7059 *
7060 * Return: 0 on success and errno on failure
7061 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007062static int hdd_register_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007063{
7064 int ret;
7065
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007066 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
7067 if (ret)
Arun Khandavalli08479ba2017-08-07 19:56:23 +05307068 goto out;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007069
7070 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
7071 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
7072 if (ret) {
7073 hdd_err("Failed to register IPv4 notifier: %d", ret);
7074 goto unregister_ip6_notifier;
7075 }
7076
Alok Kumarb64650c2018-03-23 17:05:11 +05307077 ret = hdd_nud_register_netevent_notifier(hdd_ctx);
7078 if (ret) {
7079 hdd_err("Failed to register netevent notifier: %d",
7080 ret);
7081 goto unregister_inetaddr_notifier;
7082 }
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007083 return 0;
7084
Alok Kumarb64650c2018-03-23 17:05:11 +05307085unregister_inetaddr_notifier:
7086 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007087unregister_ip6_notifier:
7088 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007089out:
7090 return ret;
7091
7092}
7093
7094/**
7095 * hdd_unregister_notifiers - Unregister netdev notifiers.
7096 * @hdd_ctx: HDD context
7097 *
7098 * Unregister netdev notifiers like IPv4 and IPv6.
7099 *
7100 * Return: None.
7101 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007102void hdd_unregister_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007103{
Alok Kumarb64650c2018-03-23 17:05:11 +05307104 hdd_nud_unregister_netevent_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007105 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
7106
7107 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007108}
7109
7110/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007111 * hdd_exit_netlink_services - Exit netlink services
7112 * @hdd_ctx: HDD context
7113 *
7114 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
7115 * nl service.
7116 *
7117 * Return: None.
7118 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007119static void hdd_exit_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007120{
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05307121 spectral_scan_deactivate_service();
7122 cnss_diag_deactivate_service();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007123 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007124 ptt_sock_deactivate_svc();
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05307125 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007126
7127 nl_srv_exit();
7128}
7129
7130/**
7131 * hdd_init_netlink_services- Init netlink services
7132 * @hdd_ctx: HDD context
7133 *
7134 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
7135 * nl service.
7136 *
7137 * Return: 0 on success and errno on failure.
7138 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007139static int hdd_init_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007140{
7141 int ret;
7142
Ryan Hsuceddceb2016-04-28 10:20:14 -07007143 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007144 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007145 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007146 goto out;
7147 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07007148 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007149
Naveen Rawat910726a2017-03-06 11:42:51 -08007150 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007151 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007152 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007153 goto err_nl_srv;
7154 }
7155
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05307156 ptt_sock_activate_svc();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007157
7158 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07007159 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007160 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007161
7162 ret = cnss_diag_activate_service();
7163 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007164 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007165 goto err_close_cesium;
7166 }
7167
Dustin Brown01520852019-02-27 12:14:16 -08007168 spectral_scan_activate_service(hdd_ctx);
Sandeep Puligilla019a1bd2018-02-04 22:57:44 -08007169
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007170 return 0;
7171
7172err_close_cesium:
7173 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007174 ptt_sock_deactivate_svc();
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05307175 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007176err_nl_srv:
7177 nl_srv_exit();
7178out:
7179 return ret;
7180}
7181
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007182/**
7183 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
7184 * @hdd_ctx: HDD context.
7185 *
7186 * Destroy RX wakelock.
7187 *
7188 * Return: None.
7189 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007190static void hdd_rx_wake_lock_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007191{
7192 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
7193}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007194
7195/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007196 * hdd_rx_wake_lock_create() - Create RX wakelock
7197 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007198 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007199 * Create RX wakelock.
7200 *
7201 * Return: None.
7202 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007203static void hdd_rx_wake_lock_create(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007204{
7205 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
7206}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007207
7208/**
Houston Hoffman160db392016-10-10 17:37:51 -07007209 * hdd_context_deinit() - Deinitialize HDD context
7210 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007211 *
Houston Hoffman160db392016-10-10 17:37:51 -07007212 * Deinitialize HDD context along with all the feature specific contexts but
7213 * do not free hdd context itself. Caller of this API is supposed to free
7214 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007215 *
Houston Hoffman160db392016-10-10 17:37:51 -07007216 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007217 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007218static int hdd_context_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007219{
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05307220 qdf_wake_lock_destroy(&hdd_ctx->monitor_mode_wakelock);
7221
Houston Hoffman160db392016-10-10 17:37:51 -07007222 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007223
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007224 hdd_sap_context_destroy(hdd_ctx);
7225
7226 hdd_rx_wake_lock_destroy(hdd_ctx);
7227
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007228 hdd_scan_context_destroy(hdd_ctx);
7229
Jeff Johnson19fc8e42017-10-30 19:53:49 -07007230 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007231
Houston Hoffman160db392016-10-10 17:37:51 -07007232 return 0;
7233}
7234
Dustin Brown623e7e32018-09-05 14:27:50 -07007235void hdd_context_destroy(struct hdd_context *hdd_ctx)
Houston Hoffman160db392016-10-10 17:37:51 -07007236{
Rajeev Kumar493a31b2017-09-29 14:01:24 -07007237 cds_set_context(QDF_MODULE_ID_HDD, NULL);
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05307238
Dustin Brown623e7e32018-09-05 14:27:50 -07007239 hdd_exit_netlink_services(hdd_ctx);
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05307240 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
7241
Houston Hoffman160db392016-10-10 17:37:51 -07007242 hdd_context_deinit(hdd_ctx);
7243
Dustin Browndb2df2e2018-10-31 15:29:24 -07007244 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
7245
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307246 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007247 hdd_ctx->config = NULL;
Dustin Brown84f46ea2018-02-15 11:57:36 -08007248 cfg_release();
7249
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007250 wiphy_free(hdd_ctx->wiphy);
7251}
7252
7253/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05307254 * wlan_destroy_bug_report_lock() - Destroy bug report lock
7255 *
7256 * This function is used to destroy bug report lock
7257 *
7258 * Return: None
7259 */
7260static void wlan_destroy_bug_report_lock(void)
7261{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07007262 struct cds_context *p_cds_context;
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05307263
7264 p_cds_context = cds_get_global_context();
7265 if (!p_cds_context) {
7266 hdd_err("cds context is NULL");
7267 return;
7268 }
7269
7270 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
7271}
7272
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +05307273#ifdef DISABLE_CHANNEL_LIST
7274static void wlan_hdd_cache_chann_mutex_destroy(struct hdd_context *hdd_ctx)
7275{
7276 qdf_mutex_destroy(&hdd_ctx->cache_channel_lock);
7277}
7278#else
7279static void wlan_hdd_cache_chann_mutex_destroy(struct hdd_context *hdd_ctx)
7280{
7281}
7282#endif
7283
Dustin Brown92bd8382018-10-31 15:49:46 -07007284void hdd_wlan_exit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007285{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007286 struct wiphy *wiphy = hdd_ctx->wiphy;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007287
Dustin Brown491d54b2018-03-14 12:39:11 -07007288 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007289
Arun Kumar Khandavallideda5a82019-03-11 15:32:19 +05307290 hdd_debugfs_mws_coex_info_deinit(hdd_ctx);
Dustin Brown4c663222018-10-23 14:19:36 -07007291 hdd_psoc_idle_timer_stop(hdd_ctx);
Dustin Brown6470aba2018-09-05 09:49:58 -07007292
Arun Khandavallifae92942016-08-01 13:31:08 +05307293 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007294
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007295#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05307296 if (QDF_TIMER_STATE_RUNNING ==
7297 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
7298 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007299 }
7300
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307301 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05307302 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07007303 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007304 }
Liangwei Dongaef84342016-10-21 05:28:00 -04007305 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
7306 qdf_mem_free(hdd_ctx->last_acs_channel_list);
7307 hdd_ctx->last_acs_channel_list = NULL;
7308 hdd_ctx->num_of_channels = 0;
7309 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007310#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007311
7312 /*
7313 * Powersave Offload Case
7314 * Disable Idle Power Save Mode
7315 */
7316 hdd_set_idle_ps_config(hdd_ctx, false);
Sandeep Puligilla8fa28fd2017-11-02 12:19:33 -07007317 /* clear the scan queue in all the scenarios */
Dustin Brown07901ec2018-09-07 11:02:41 -07007318 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->pdev, NULL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007319
Dustin Brownf688ea12019-03-19 17:02:32 -07007320 if (hdd_ctx->driver_status != DRIVER_MODULES_CLOSED) {
Arun Khandavallifae92942016-08-01 13:31:08 +05307321 hdd_unregister_wext_all_adapters(hdd_ctx);
7322 /*
7323 * Cancel any outstanding scan requests. We are about to close
7324 * all of our adapters, but an adapter structure is what SME
7325 * passes back to our callback function. Hence if there
7326 * are any outstanding scan requests then there is a
7327 * race condition between when the adapter is closed and
7328 * when the callback is invoked. We try to resolve that
7329 * race condition here by canceling any outstanding scans
7330 * before we close the adapters.
7331 * Note that the scans may be cancelled in an asynchronous
7332 * manner, so ideally there needs to be some kind of
7333 * synchronization. Rather than introduce a new
7334 * synchronization here, we will utilize the fact that we are
7335 * about to Request Full Power, and since that is synchronized,
7336 * the expectation is that by the time Request Full Power has
7337 * completed, all scans will be cancelled
7338 */
7339 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07007340 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Dustin Browndb2a8be2017-12-20 11:49:56 -08007341 hdd_stop_all_adapters(hdd_ctx);
bings29c99862017-11-01 13:54:13 +08007342 hdd_deinit_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007343 }
7344
Arunk Khandavalli830c9692018-03-22 12:17:40 +05307345 unregister_reboot_notifier(&system_reboot_notifier);
Arun Khandavalli08479ba2017-08-07 19:56:23 +05307346 unregister_netdevice_notifier(&hdd_netdev_notifier);
7347
Rachit Kankane30807332018-06-27 18:39:36 +05307348 qdf_dp_trace_deinit();
7349
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07007350 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05307351
Visweswara Tanukuc029a202018-11-27 10:42:10 +05307352 hdd_bus_bw_compute_timer_stop(hdd_ctx);
Dustin Brown86d196b2018-08-02 11:51:49 -07007353 hdd_bus_bandwidth_deinit(hdd_ctx);
Dustin Brown021cecd2017-12-11 13:56:43 -08007354 hdd_driver_memdump_deinit();
7355
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05307356 qdf_nbuf_deinit_replenish_timer();
7357
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05307358 if (QDF_GLOBAL_MONITOR_MODE == hdd_get_conparam()) {
7359 hdd_info("Release wakelock for monitor mode!");
7360 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
7361 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
7362 }
7363
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307364 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307365 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +05307366 wlan_hdd_cache_chann_mutex_destroy(hdd_ctx);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307367
Naveen Rawate02f8f52018-04-05 11:58:04 -07007368 osif_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007369
Dustin Brownd005ad82018-01-19 10:32:13 -08007370 hdd_close_all_adapters(hdd_ctx, false);
7371
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05307372 wlansap_global_deinit();
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05307373 /*
7374 * If there is re_init failure wiphy would have already de-registered
7375 * check the wiphy status before un-registering again
7376 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05307377 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05307378 wiphy_unregister(wiphy);
7379 wlan_hdd_cfg80211_deinit(wiphy);
7380 hdd_lpass_notify_stop(hdd_ctx);
7381 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07007382
Arun Khandavallifae92942016-08-01 13:31:08 +05307383 hdd_exit_netlink_services(hdd_ctx);
Dustin Brown8d8ab302019-03-05 16:19:36 -08007384 qdf_delayed_work_destroy(&hdd_ctx->psoc_idle_timeout_work);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05307385#ifdef FEATURE_WLAN_CH_AVOID
7386 mutex_destroy(&hdd_ctx->avoid_freq_lock);
7387#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007388}
7389
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007390#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04007391/**
7392 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007393 * @data: pointer to struct hdd_context
Liangwei Dongaef84342016-10-21 05:28:00 -04007394 *
7395 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
7396 * Then new ACS request will do a fresh scan without reusing the cached
7397 * scan information.
7398 *
7399 * Return: void
7400 */
Tang Yingying523322d2017-01-17 23:28:43 +08007401static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007402{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007403 struct hdd_context *hdd_ctx = (struct hdd_context *) data;
Jeff Johnson16528362018-06-14 12:34:16 -07007404 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007405
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007406 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007407 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04007408 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
7409 qdf_mem_free(hdd_ctx->last_acs_channel_list);
7410 hdd_ctx->last_acs_channel_list = NULL;
7411 hdd_ctx->num_of_channels = 0;
7412 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007413
Jeff Johnson16528362018-06-14 12:34:16 -07007414 mac_handle = hdd_ctx->mac_handle;
7415 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007416 return;
Jeff Johnson16528362018-06-14 12:34:16 -07007417 sme_scan_flush_result(mac_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007418}
7419#endif
7420
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007421/**
7422 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
7423 * @state: state
7424 *
7425 * This function notifies FW with modem power status
7426 *
7427 * Return: 0 if successful, error number otherwise
7428 */
7429int hdd_wlan_notify_modem_power_state(int state)
7430{
7431 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307432 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007433 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -07007434 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007435
Anurag Chouhan6d760662016-02-20 16:05:43 +05307436 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007437 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05307438 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007439 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05307440
Jeff Johnson16528362018-06-14 12:34:16 -07007441 mac_handle = hdd_ctx->mac_handle;
7442 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007443 return -EINVAL;
7444
Jeff Johnson16528362018-06-14 12:34:16 -07007445 qdf_status = sme_notify_modem_power_state(mac_handle, state);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307446 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007447 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007448 state);
7449 return -EINVAL;
7450 }
7451 return 0;
7452}
7453
7454/**
7455 *
7456 * hdd_post_cds_enable_config() - HDD post cds start config helper
7457 * @adapter - Pointer to the HDD
7458 *
7459 * Return: None
7460 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007461QDF_STATUS hdd_post_cds_enable_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007462{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307463 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007464
7465 /*
7466 * Send ready indication to the HDD. This will kick off the MAC
7467 * into a 'running' state and should kick off an initial scan.
7468 */
Jeff Johnson16528362018-06-14 12:34:16 -07007469 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->mac_handle);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307470 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007471 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
7472 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307473 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007474 }
7475
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307476 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007477}
7478
Sourav Mohapatra92ea8d62018-02-05 10:03:10 +05307479struct hdd_adapter *hdd_get_first_valid_adapter(struct hdd_context *hdd_ctx)
7480{
7481 struct hdd_adapter *adapter;
7482
7483 hdd_for_each_adapter(hdd_ctx, adapter) {
7484 if (adapter && adapter->magic == WLAN_HDD_ADAPTER_MAGIC)
7485 return adapter;
7486 }
7487
7488 return NULL;
7489}
7490
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007491/* wake lock APIs for HDD */
7492void hdd_prevent_suspend(uint32_t reason)
7493{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05307494 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007495}
7496
7497void hdd_allow_suspend(uint32_t reason)
7498{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05307499 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007500}
7501
7502void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
7503{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05307504 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
7505 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007506}
7507
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007508/* Initialize channel list in sme based on the country code */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007509QDF_STATUS hdd_set_sme_chan_list(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007510{
Jeff Johnson16528362018-06-14 12:34:16 -07007511 return sme_init_chan_list(hdd_ctx->mac_handle,
Amar Singhal6f8592b2017-04-26 14:31:58 -07007512 hdd_ctx->reg.alpha2,
7513 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007514}
7515
7516/**
7517 * hdd_is_5g_supported() - check if hardware supports 5GHz
7518 * @hdd_ctx: Pointer to the hdd context
7519 *
7520 * HDD function to know if hardware supports 5GHz
7521 *
7522 * Return: true if hardware supports 5GHz
7523 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007524bool hdd_is_5g_supported(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007525{
Amar Singhal58b45ef2017-08-01 13:43:54 -07007526 if (!hdd_ctx)
zdingf54169a2016-10-12 17:08:45 +08007527 return true;
7528
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08007529 if (hdd_ctx->curr_band != BAND_2G)
zdingf54169a2016-10-12 17:08:45 +08007530 return true;
7531 else
7532 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007533}
7534
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007535static int hdd_wiphy_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007536{
7537 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07007538 int ret_val;
Wu Gaoed616a12019-01-16 15:19:21 +08007539 uint32_t channel_bonding_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007540
7541 wiphy = hdd_ctx->wiphy;
7542
7543 /*
7544 * The channel information in
7545 * wiphy needs to be initialized before wiphy registration
7546 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07007547 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
7548 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007549 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07007550 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007551 }
7552
7553#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
7554 wiphy->wowlan = &wowlan_support_reg_init;
7555#else
7556 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
7557 WIPHY_WOWLAN_MAGIC_PKT |
7558 WIPHY_WOWLAN_DISCONNECT |
7559 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
7560 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
7561 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
7562 WIPHY_WOWLAN_4WAY_HANDSHAKE |
7563 WIPHY_WOWLAN_RFKILL_RELEASE;
7564
7565 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
7566 WOW_MAX_FILTERS_PER_LIST);
7567 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
7568 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
7569#endif
Wu Gaoed616a12019-01-16 15:19:21 +08007570 ucfg_mlme_get_channel_bonding_24ghz(hdd_ctx->psoc,
7571 &channel_bonding_mode);
Liangwei Dong0da14262018-07-03 03:30:23 -04007572 if (hdd_ctx->obss_scan_offload) {
7573 hdd_debug("wmi_service_obss_scan supported");
Wu Gaoed616a12019-01-16 15:19:21 +08007574 } else if (channel_bonding_mode) {
Liangwei Dong0da14262018-07-03 03:30:23 -04007575 hdd_debug("enable wpa_supp obss_scan");
7576 wiphy->features |= NL80211_FEATURE_NEED_OBSS_SCAN;
7577 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007578
7579 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07007580 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05307581 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07007582 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05307583 return ret_val;
7584 }
Amar Singhalac26de22018-06-22 12:53:06 -07007585
Kiran Kumar Lokere0508af92018-04-23 18:38:32 -07007586 /* Check the kernel version for upstream commit aced43ce780dc5 that
7587 * has support for processing user cell_base hints when wiphy is
7588 * self managed or check the backport flag for the same.
7589 */
Amar Singhalac26de22018-06-22 12:53:06 -07007590#if defined CFG80211_USER_HINT_CELL_BASE_SELF_MANAGED || \
7591 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 18, 0))
Kiran Kumar Lokere0508af92018-04-23 18:38:32 -07007592 hdd_send_wiphy_regd_sync_event(hdd_ctx);
7593#endif
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05307594
Amar Singhal2d812012018-02-03 15:06:47 +08007595 pld_increment_driver_load_cnt(hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007596
Amar Singhale4f28ee2015-10-21 14:36:56 -07007597 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007598}
7599
Mohit Khannaca4173b2017-09-12 21:52:19 -07007600#ifdef MSM_PLATFORM
7601/**
7602 * hdd_display_periodic_stats() - Function to display periodic stats
7603 * @hdd_ctx - handle to hdd context
7604 * @bool data_in_interval - true, if data detected in bw time interval
7605 *
7606 * The periodicity is determined by hdd_ctx->config->periodic_stats_disp_time.
7607 * Stats show up in wlan driver logs.
7608 *
7609 * Returns: None
7610 */
Mohit Khanna70322002018-05-15 19:21:32 -07007611static void hdd_display_periodic_stats(struct hdd_context *hdd_ctx,
7612 bool data_in_interval)
Mohit Khannaca4173b2017-09-12 21:52:19 -07007613{
Mohit Khanna70322002018-05-15 19:21:32 -07007614 static uint32_t counter;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007615 static bool data_in_time_period;
7616 ol_txrx_pdev_handle pdev;
Mohit Khanna81418772018-10-30 14:14:46 -07007617 ol_txrx_soc_handle soc;
Arif Hussaincca60432018-12-03 19:45:12 -08007618 uint32_t periodic_stats_disp_time = 0;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007619
Arif Hussaincca60432018-12-03 19:45:12 -08007620 ucfg_mlme_stats_get_periodic_display_time(hdd_ctx->psoc,
7621 &periodic_stats_disp_time);
7622 if (!periodic_stats_disp_time)
Mohit Khannaca4173b2017-09-12 21:52:19 -07007623 return;
7624
Mohit Khanna81418772018-10-30 14:14:46 -07007625 soc = cds_get_context(QDF_MODULE_ID_SOC);
7626 if (!soc) {
7627 hdd_err("soc is NULL");
7628 return;
7629 }
7630
Mohit Khannaca4173b2017-09-12 21:52:19 -07007631 pdev = cds_get_context(QDF_MODULE_ID_TXRX);
7632 if (!pdev) {
7633 hdd_err("pdev is NULL");
7634 return;
7635 }
7636
7637 counter++;
7638 if (data_in_interval)
7639 data_in_time_period = data_in_interval;
7640
jitiphil869b9f72018-09-25 17:14:01 +05307641 if (counter * hdd_ctx->config->bus_bw_compute_interval >=
Arif Hussaincca60432018-12-03 19:45:12 -08007642 periodic_stats_disp_time * 1000) {
Mohit Khannaca4173b2017-09-12 21:52:19 -07007643 if (data_in_time_period) {
Mohit Khanna70322002018-05-15 19:21:32 -07007644 wlan_hdd_display_txrx_stats(hdd_ctx);
Mohit Khannac9649652018-11-28 18:10:28 -08007645 dp_txrx_ext_dump_stats(soc, CDP_DP_RX_THREAD_STATS);
Mohit Khanna81418772018-10-30 14:14:46 -07007646 cdp_display_stats(soc,
Mohit Khanna70322002018-05-15 19:21:32 -07007647 CDP_RX_RING_STATS,
7648 QDF_STATS_VERBOSITY_LEVEL_LOW);
Mohit Khanna81418772018-10-30 14:14:46 -07007649 cdp_display_stats(soc,
Mohit Khannaca4173b2017-09-12 21:52:19 -07007650 CDP_TXRX_PATH_STATS,
7651 QDF_STATS_VERBOSITY_LEVEL_LOW);
7652 wlan_hdd_display_netif_queue_history
7653 (hdd_ctx, QDF_STATS_VERBOSITY_LEVEL_LOW);
7654 qdf_dp_trace_dump_stats();
7655 }
7656 counter = 0;
7657 data_in_time_period = false;
7658 }
7659}
7660
Ravi Joshie2331e82015-07-01 18:18:54 -07007661/**
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007662 * hdd_clear_rps_cpu_mask - clear RPS CPU mask for interfaces
7663 * @hdd_ctx: pointer to struct hdd_context
7664 *
7665 * Return: none
7666 */
7667static void hdd_clear_rps_cpu_mask(struct hdd_context *hdd_ctx)
7668{
7669 struct hdd_adapter *adapter;
7670
7671 hdd_for_each_adapter(hdd_ctx, adapter)
7672 hdd_send_rps_disable_ind(adapter);
7673}
7674
7675/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07007676 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07007677 * @hdd_ctx - handle to hdd context
7678 * @tx_packets - transmit packet count
7679 * @rx_packets - receive packet count
7680 *
7681 * The function controls the bus bandwidth and dynamic control of
7682 * tcp delayed ack configuration
7683 *
7684 * Returns: None
7685 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07007686
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007687static void hdd_pld_request_bus_bandwidth(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07007688 const uint64_t tx_packets,
7689 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007690{
Mohit Khannaca4173b2017-09-12 21:52:19 -07007691 u64 total_pkts = tx_packets + rx_packets;
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007692 uint64_t temp_tx = 0, avg_rx = 0;
7693 uint64_t no_rx_offload_pkts = 0, avg_no_rx_offload_pkts = 0;
7694 uint64_t rx_offload_pkts = 0, avg_rx_offload_pkts = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07007695 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08007696 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08007697 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07007698 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007699 uint16_t index = 0;
7700 bool vote_level_change = false;
7701 bool rx_level_change = false;
7702 bool tx_level_change = false;
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007703 bool rxthread_high_tput_req = false;
Mohit Khannaf7562c32018-07-05 17:42:36 -07007704 bool dptrace_high_tput_req;
Srinivas Girigowda50335342018-09-07 15:21:01 -07007705
jitiphil869b9f72018-09-25 17:14:01 +05307706 if (total_pkts > hdd_ctx->config->bus_bw_high_threshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007707 next_vote_level = PLD_BUS_WIDTH_HIGH;
jitiphil869b9f72018-09-25 17:14:01 +05307708 else if (total_pkts > hdd_ctx->config->bus_bw_medium_threshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007709 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
jitiphil869b9f72018-09-25 17:14:01 +05307710 else if (total_pkts > hdd_ctx->config->bus_bw_low_threshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007711 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07007712 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07007713 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007714
Mohit Khannaf7562c32018-07-05 17:42:36 -07007715 dptrace_high_tput_req =
7716 next_vote_level > PLD_BUS_WIDTH_NONE ? true : false;
7717
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007718 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07007719 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
7720 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007721 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007722 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07007723 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007724 if ((next_vote_level == PLD_BUS_WIDTH_LOW) ||
7725 (next_vote_level == PLD_BUS_WIDTH_NONE)) {
Nirav Shahffc6a092016-06-09 16:09:08 +05307726 if (hdd_ctx->hbw_requested) {
7727 pld_remove_pm_qos(hdd_ctx->parent_dev);
7728 hdd_ctx->hbw_requested = false;
7729 }
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007730 if (hdd_ctx->dynamic_rps)
7731 hdd_clear_rps_cpu_mask(hdd_ctx);
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07007732 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05307733 if (!hdd_ctx->hbw_requested) {
7734 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
7735 hdd_ctx->hbw_requested = true;
7736 }
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007737 if (hdd_ctx->dynamic_rps)
7738 hdd_set_rps_cpu_mask(hdd_ctx);
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07007739 }
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007740
Manjunathappa Prakashcb6df762018-05-29 18:54:58 -07007741 if (hdd_ctx->config->napi_cpu_affinity_mask)
7742 hdd_napi_apply_throughput_policy(hdd_ctx,
7743 tx_packets,
7744 rx_packets);
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007745
jitiphil869b9f72018-09-25 17:14:01 +05307746 if (rx_packets < hdd_ctx->config->bus_bw_low_threshold)
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007747 hdd_disable_rx_ol_for_low_tput(hdd_ctx, true);
7748 else
7749 hdd_disable_rx_ol_for_low_tput(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007750 }
Mohit Khannae71e2262015-11-10 09:37:24 -08007751
Mohit Khannaf7562c32018-07-05 17:42:36 -07007752 qdf_dp_trace_apply_tput_policy(dptrace_high_tput_req);
7753
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007754 /*
7755 * Includes tcp+udp, if perf core is required for tcp, then
7756 * perf core is also required for udp.
7757 */
7758 no_rx_offload_pkts = hdd_ctx->no_rx_offload_pkt_cnt;
7759 hdd_ctx->no_rx_offload_pkt_cnt = 0;
7760 rx_offload_pkts = rx_packets - no_rx_offload_pkts;
Mohit Khannae71e2262015-11-10 09:37:24 -08007761
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007762 avg_no_rx_offload_pkts = (no_rx_offload_pkts +
7763 hdd_ctx->prev_no_rx_offload_pkts) / 2;
7764 hdd_ctx->prev_no_rx_offload_pkts = no_rx_offload_pkts;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08007765
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007766 avg_rx_offload_pkts = (rx_offload_pkts +
7767 hdd_ctx->prev_rx_offload_pkts) / 2;
7768 hdd_ctx->prev_rx_offload_pkts = rx_offload_pkts;
7769
7770 avg_rx = avg_no_rx_offload_pkts + avg_rx_offload_pkts;
7771 /*
7772 * Takes care to set Rx_thread affinity for below case
7773 * 1)LRO/GRO not supported ROME case
7774 * 2)when rx_ol is disabled in cases like concurrency etc
7775 * 3)For UDP cases
7776 */
7777 if (avg_no_rx_offload_pkts >
jitiphil869b9f72018-09-25 17:14:01 +05307778 hdd_ctx->config->bus_bw_high_threshold)
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007779 rxthread_high_tput_req = true;
Poddar, Siddarth47c23402017-10-25 12:17:39 +05307780 else
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007781 rxthread_high_tput_req = false;
Poddar, Siddarth47c23402017-10-25 12:17:39 +05307782
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007783 if (cds_sched_handle_throughput_req(rxthread_high_tput_req))
7784 hdd_warn("Rx thread high_tput(%d) affinity request failed",
7785 rxthread_high_tput_req);
7786
7787 /* fine-tuning parameters for RX Flows */
jitiphil869b9f72018-09-25 17:14:01 +05307788 if (avg_rx > hdd_ctx->config->tcp_delack_thres_high) {
Ravi Joshifed83572016-10-07 16:20:37 -07007789 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
7790 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
7791 next_rx_level = WLAN_SVC_TP_HIGH;
7792 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07007793 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07007794 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08007795 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07007796 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007797
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007798 if (hdd_ctx->cur_rx_level != next_rx_level) {
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007799 struct wlan_rx_tp_data rx_tp_data = {0};
7800
Ravi Joshie2331e82015-07-01 18:18:54 -07007801 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Jeff Johnsonb9feee42018-07-08 10:34:48 -07007802 next_rx_level, avg_rx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007803 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007804 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07007805 /* Send throughput indication only if it is enabled.
7806 * Disabling tcp_del_ack will revert the tcp stack behavior
7807 * to default delayed ack. Note that this will disable the
7808 * dynamic delayed ack mechanism across the system
7809 */
Manjunathappa Prakashbfd12762018-04-29 22:44:52 -07007810 if (hdd_ctx->en_tcp_delack_no_lro)
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007811 rx_tp_data.rx_tp_flags |= TCP_DEL_ACK_IND;
7812
Mohit Khanna6272fb682017-04-13 09:34:36 -07007813 if (hdd_ctx->config->enable_tcp_adv_win_scale)
7814 rx_tp_data.rx_tp_flags |= TCP_ADV_WIN_SCL;
7815
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007816 rx_tp_data.level = next_rx_level;
Alok Kumar2fad6442018-11-08 19:19:28 +05307817 wlan_hdd_update_tcp_rx_param(hdd_ctx, &rx_tp_data);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007818 }
7819
Mohit Khannae71e2262015-11-10 09:37:24 -08007820 /* fine-tuning parameters for TX Flows */
7821 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
7822 hdd_ctx->prev_tx = tx_packets;
7823 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
7824 next_tx_level = WLAN_SVC_TP_HIGH;
7825 else
7826 next_tx_level = WLAN_SVC_TP_LOW;
7827
Prakash Manjunathappae73e3b52018-02-27 18:56:22 -08007828 if ((hdd_ctx->config->enable_tcp_limit_output) &&
7829 (hdd_ctx->cur_tx_level != next_tx_level)) {
Alok Kumar2fad6442018-11-08 19:19:28 +05307830 struct wlan_tx_tp_data tx_tp_data = {0};
7831
Mohit Khannae71e2262015-11-10 09:37:24 -08007832 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
7833 next_tx_level, temp_tx);
7834 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007835 tx_level_change = true;
Alok Kumar2fad6442018-11-08 19:19:28 +05307836 tx_tp_data.level = next_tx_level;
7837 tx_tp_data.tcp_limit_output = true;
7838 wlan_hdd_update_tcp_tx_param(hdd_ctx, &tx_tp_data);
Mohit Khannae71e2262015-11-10 09:37:24 -08007839 }
7840
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007841 index = hdd_ctx->hdd_txrx_hist_idx;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007842 if (vote_level_change || tx_level_change || rx_level_change) {
7843 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
7844 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
7845 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
7846 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
7847 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
7848 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
7849 hdd_ctx->hdd_txrx_hist_idx++;
7850 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
7851 }
Mohit Khannaca4173b2017-09-12 21:52:19 -07007852
7853 hdd_display_periodic_stats(hdd_ctx, (total_pkts > 0) ? true : false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007854}
7855
7856#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Dustin Browna20bad52019-03-05 12:03:30 -08007857static void __hdd_bus_bw_work_handler(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007858{
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05307859 struct hdd_adapter *adapter = NULL, *con_sap_adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307860 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05307861 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
7862 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007863 uint64_t total_tx = 0, total_rx = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307864 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007865 bool connected = false;
7866 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
7867
Prashanth Bhattaab004382016-10-11 16:08:11 -07007868 if (wlan_hdd_validate_context(hdd_ctx))
Dustin Browna20bad52019-03-05 12:03:30 -08007869 goto stop_work;
Prashanth Bhattaab004382016-10-11 16:08:11 -07007870
Jeff Johnson214671b2017-10-30 19:45:23 -07007871 if (hdd_ctx->is_wiphy_suspended)
Dustin Browna20bad52019-03-05 12:03:30 -08007872 return;
Jingxiang Gec64e1932017-08-22 14:38:59 +08007873
Dustin Brown920397d2017-12-13 16:27:50 -08007874 hdd_for_each_adapter(hdd_ctx, adapter) {
Manjeet Singh01327cc2016-09-03 12:14:25 +05307875 /*
7876 * Validate magic so we don't end up accessing
7877 * an invalid adapter.
7878 */
7879 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
7880 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007881
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007882 if ((adapter->device_mode == QDF_STA_MODE ||
7883 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Jeff Johnsone7951512019-02-27 10:02:51 -08007884 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.conn_state
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007885 != eConnectionState_Associated) {
7886
7887 continue;
7888 }
7889
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007890 if ((adapter->device_mode == QDF_SAP_MODE ||
7891 adapter->device_mode == QDF_P2P_GO_MODE) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -07007892 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active == false) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007893
7894 continue;
7895 }
7896
7897 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
7898 adapter->prev_tx_packets);
7899 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
7900 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307901
7902 if (adapter->device_mode == QDF_SAP_MODE ||
7903 adapter->device_mode == QDF_P2P_GO_MODE ||
7904 adapter->device_mode == QDF_IBSS_MODE) {
7905
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08007906 ret = cdp_get_intra_bss_fwd_pkts_count(
7907 cds_get_context(QDF_MODULE_ID_SOC),
Jeff Johnson5a6fc962019-02-04 14:20:25 -08007908 adapter->vdev_id,
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307909 &fwd_tx_packets, &fwd_rx_packets);
7910 if (ret == A_OK) {
7911 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
7912 fwd_tx_packets,
7913 adapter->prev_fwd_tx_packets);
7914 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
7915 fwd_tx_packets,
7916 adapter->prev_fwd_rx_packets);
7917 }
7918 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007919
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05307920 if (adapter->device_mode == QDF_SAP_MODE)
7921 con_sap_adapter = adapter;
7922
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007923 total_rx += adapter->stats.rx_packets;
7924 total_tx += adapter->stats.tx_packets;
7925
7926 spin_lock_bh(&hdd_ctx->bus_bw_lock);
7927 adapter->prev_tx_packets = adapter->stats.tx_packets;
7928 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307929 adapter->prev_fwd_tx_packets = fwd_tx_packets;
7930 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007931 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
7932 connected = true;
7933 }
7934
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007935 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007936 hdd_err("bus bandwidth timer running in disconnected state");
Dustin Browna20bad52019-03-05 12:03:30 -08007937 goto stop_work;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007938 }
7939
Yun Parka29974a2018-04-09 12:05:49 -07007940 /* add intra bss forwarded tx and rx packets */
7941 tx_packets += fwd_tx_packets_diff;
7942 rx_packets += fwd_rx_packets_diff;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007943
Dustin Brown07901ec2018-09-07 11:02:41 -07007944 if (ucfg_ipa_is_fw_wdi_activated(hdd_ctx->pdev)) {
7945 ucfg_ipa_uc_stat_query(hdd_ctx->pdev, &ipa_tx_packets,
7946 &ipa_rx_packets);
Yun Parka29974a2018-04-09 12:05:49 -07007947 tx_packets += (uint64_t)ipa_tx_packets;
7948 rx_packets += (uint64_t)ipa_rx_packets;
7949
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05307950 if (con_sap_adapter) {
7951 con_sap_adapter->stats.tx_packets += ipa_tx_packets;
7952 con_sap_adapter->stats.rx_packets += ipa_rx_packets;
7953 }
7954
Dustin Brown07901ec2018-09-07 11:02:41 -07007955 ucfg_ipa_set_perf_level(hdd_ctx->pdev, tx_packets, rx_packets);
7956 ucfg_ipa_uc_stat_request(hdd_ctx->pdev, 2);
Yun Parka29974a2018-04-09 12:05:49 -07007957 }
7958
7959 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007960
Dustin Browna20bad52019-03-05 12:03:30 -08007961 return;
7962
7963stop_work:
7964 qdf_periodic_work_stop_async(&hdd_ctx->bus_bw_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007965}
Prashanth Bhattaab004382016-10-11 16:08:11 -07007966
Dustin Browna20bad52019-03-05 12:03:30 -08007967static void hdd_bus_bw_work_handler(void *context)
Rajeev Kumarb2b5e692018-08-31 15:12:40 -07007968{
Dustin Brown3fdaaf62019-03-18 14:00:16 -07007969 struct hdd_context *hdd_ctx = context;
7970 struct qdf_op_sync *op_sync;
Dustin Browna20bad52019-03-05 12:03:30 -08007971
Dustin Brown3fdaaf62019-03-18 14:00:16 -07007972 if (qdf_op_protect(&op_sync))
7973 return;
7974
7975 __hdd_bus_bw_work_handler(hdd_ctx);
7976
7977 qdf_op_unprotect(op_sync);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307978}
7979
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007980int hdd_bus_bandwidth_init(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007981{
Dustin Browna20bad52019-03-05 12:03:30 -08007982 QDF_STATUS status;
7983
Dustin Brown35008ba2018-08-23 14:34:21 -07007984 hdd_enter();
7985
Prashanth Bhattaab004382016-10-11 16:08:11 -07007986 spin_lock_init(&hdd_ctx->bus_bw_lock);
Dustin Browna20bad52019-03-05 12:03:30 -08007987 status = qdf_periodic_work_create(&hdd_ctx->bus_bw_work,
7988 hdd_bus_bw_work_handler,
Dustin Brown3fdaaf62019-03-18 14:00:16 -07007989 hdd_ctx);
Dustin Brown35008ba2018-08-23 14:34:21 -07007990
7991 hdd_exit();
Prashanth Bhattaab004382016-10-11 16:08:11 -07007992
Dustin Browna20bad52019-03-05 12:03:30 -08007993 return qdf_status_to_os_return(status);
Prashanth Bhattaab004382016-10-11 16:08:11 -07007994}
7995
Dustin Brown86d196b2018-08-02 11:51:49 -07007996void hdd_bus_bandwidth_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007997{
Dustin Brown35008ba2018-08-23 14:34:21 -07007998 hdd_enter();
Prashanth Bhattaab004382016-10-11 16:08:11 -07007999
Dustin Browna20bad52019-03-05 12:03:30 -08008000 QDF_BUG(!qdf_periodic_work_stop_sync(&hdd_ctx->bus_bw_work));
8001 qdf_periodic_work_destroy(&hdd_ctx->bus_bw_work);
Dustin Brown35008ba2018-08-23 14:34:21 -07008002
8003 hdd_exit();
Prashanth Bhattaab004382016-10-11 16:08:11 -07008004}
Lin Baic5c06882017-09-21 13:58:43 +08008005
Dustin Brown35008ba2018-08-23 14:34:21 -07008006#endif /* MSM_PLATFORM */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008007
8008/**
Nirav Shahed34b212016-04-25 10:59:16 +05308009 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
8010 * @hdd_ctx: hdd context
8011 *
8012 * Return: 0 for success or error code
8013 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008014static int wlan_hdd_init_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05308015{
8016 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
8017 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Min Liu74a1a502018-10-10 19:59:07 +08008018 if (!hdd_ctx->hdd_txrx_hist)
Nirav Shahed34b212016-04-25 10:59:16 +05308019 return -ENOMEM;
Nirav Shahed34b212016-04-25 10:59:16 +05308020 return 0;
8021}
8022
8023/**
8024 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
8025 * @hdd_ctx: hdd context
8026 *
8027 * Return: none
8028 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008029void wlan_hdd_deinit_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05308030{
Jeff Johnsond36fa332019-03-18 13:42:25 -07008031 if (!hdd_ctx || !hdd_ctx->hdd_txrx_hist)
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05308032 return;
8033
8034 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
8035 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05308036}
8037
Nirav Shahda008342016-05-17 18:50:40 +05308038static uint8_t *convert_level_to_string(uint32_t level)
8039{
8040 switch (level) {
8041 /* initialize the wlan sub system */
8042 case WLAN_SVC_TP_NONE:
8043 return "NONE";
8044 case WLAN_SVC_TP_LOW:
8045 return "LOW";
8046 case WLAN_SVC_TP_MEDIUM:
8047 return "MED";
8048 case WLAN_SVC_TP_HIGH:
8049 return "HIGH";
8050 default:
8051 return "INVAL";
8052 }
8053}
8054
Nirav Shahed34b212016-04-25 10:59:16 +05308055
8056/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008057 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
8058 * @hdd_ctx: hdd context
8059 *
8060 * Return: none
8061 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008062void wlan_hdd_display_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008063{
8064 int i;
8065
8066#ifdef MSM_PLATFORM
Nirav Shahe6194ac2018-07-13 11:04:41 +05308067 hdd_nofl_info("BW compute Interval: %dms",
jitiphil869b9f72018-09-25 17:14:01 +05308068 hdd_ctx->config->bus_bw_compute_interval);
Nirav Shahe6194ac2018-07-13 11:04:41 +05308069 hdd_nofl_info("BW High TH: %d BW Med TH: %d BW Low TH: %d",
jitiphil869b9f72018-09-25 17:14:01 +05308070 hdd_ctx->config->bus_bw_high_threshold,
8071 hdd_ctx->config->bus_bw_medium_threshold,
8072 hdd_ctx->config->bus_bw_low_threshold);
Nirav Shahe6194ac2018-07-13 11:04:41 +05308073 hdd_nofl_info("Enable TCP DEL ACK: %d",
8074 hdd_ctx->en_tcp_delack_no_lro);
8075 hdd_nofl_info("TCP DEL High TH: %d TCP DEL Low TH: %d",
jitiphil869b9f72018-09-25 17:14:01 +05308076 hdd_ctx->config->tcp_delack_thres_high,
8077 hdd_ctx->config->tcp_delack_thres_low);
Nirav Shahe6194ac2018-07-13 11:04:41 +05308078 hdd_nofl_info("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
8079 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008080#endif
8081
Nirav Shahe6194ac2018-07-13 11:04:41 +05308082 hdd_nofl_info("Total entries: %d Current index: %d",
8083 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
Nirav Shahda008342016-05-17 18:50:40 +05308084
Nirav Shahe6194ac2018-07-13 11:04:41 +05308085 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 -08008086
8087 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07008088 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08008089 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Nirav Shahe6194ac2018-07-13 11:04:41 +05308090 hdd_nofl_info("[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
8091 i, hdd_ctx->hdd_txrx_hist[i].qtime,
8092 hdd_ctx->hdd_txrx_hist[i].interval_rx,
8093 hdd_ctx->hdd_txrx_hist[i].interval_tx,
8094 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07008095 hdd_ctx->hdd_txrx_hist[i].
8096 next_vote_level),
Nirav Shahe6194ac2018-07-13 11:04:41 +05308097 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07008098 hdd_ctx->hdd_txrx_hist[i].
8099 next_rx_level),
Nirav Shahe6194ac2018-07-13 11:04:41 +05308100 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07008101 hdd_ctx->hdd_txrx_hist[i].
8102 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008103 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008104}
8105
8106/**
8107 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
8108 * @hdd_ctx: hdd context
8109 *
8110 * Return: none
8111 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008112void wlan_hdd_clear_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008113{
8114 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05308115 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
8116 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008117}
8118
Mohit Khannaca4173b2017-09-12 21:52:19 -07008119/* length of the netif queue log needed per adapter */
8120#define ADAP_NETIFQ_LOG_LEN ((20 * WLAN_REASON_TYPE_MAX) + 50)
8121
8122/**
8123 *
8124 * hdd_display_netif_queue_history_compact() - display compact netifq history
8125 * @hdd_ctx: hdd context
8126 *
8127 * Return: none
8128 */
8129static void
8130hdd_display_netif_queue_history_compact(struct hdd_context *hdd_ctx)
8131{
8132 int adapter_num = 0;
8133 int i;
8134 int bytes_written;
8135 u32 tbytes;
8136 qdf_time_t total, pause, unpause, curr_time, delta;
Mohit Khannaca4173b2017-09-12 21:52:19 -07008137 char temp_str[20 * WLAN_REASON_TYPE_MAX];
jiadbdefb252018-01-03 14:27:06 +08008138 char *comb_log_str;
8139 uint32_t comb_log_str_size;
Mohit Khannaca4173b2017-09-12 21:52:19 -07008140 struct hdd_adapter *adapter = NULL;
Mohit Khannaca4173b2017-09-12 21:52:19 -07008141
Dustin Brownad06be62019-02-04 14:52:56 -08008142 comb_log_str_size = (ADAP_NETIFQ_LOG_LEN * WLAN_MAX_VDEVS) + 1;
jiadbdefb252018-01-03 14:27:06 +08008143 comb_log_str = qdf_mem_malloc(comb_log_str_size);
Min Liu74a1a502018-10-10 19:59:07 +08008144 if (!comb_log_str)
jiadbdefb252018-01-03 14:27:06 +08008145 return;
jiadbdefb252018-01-03 14:27:06 +08008146
Mohit Khannaca4173b2017-09-12 21:52:19 -07008147 bytes_written = 0;
Mohit Khannaca4173b2017-09-12 21:52:19 -07008148
Dustin Brown920397d2017-12-13 16:27:50 -08008149 hdd_for_each_adapter(hdd_ctx, adapter) {
Mohit Khannaca4173b2017-09-12 21:52:19 -07008150 curr_time = qdf_system_ticks();
8151 total = curr_time - adapter->start_time;
8152 delta = curr_time - adapter->last_time;
8153
8154 if (adapter->pause_map) {
8155 pause = adapter->total_pause_time + delta;
8156 unpause = adapter->total_unpause_time;
8157 } else {
8158 unpause = adapter->total_unpause_time + delta;
8159 pause = adapter->total_pause_time;
8160 }
8161
8162 tbytes = 0;
hangtian127c9532019-01-12 13:29:07 +08008163 qdf_mem_zero(temp_str, sizeof(temp_str));
Mohit Khannaca4173b2017-09-12 21:52:19 -07008164 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
8165 if (adapter->queue_oper_stats[i].pause_count == 0)
8166 continue;
8167 tbytes +=
8168 snprintf(
8169 &temp_str[tbytes],
8170 (tbytes >= sizeof(temp_str) ?
8171 0 : sizeof(temp_str) - tbytes),
8172 "%d(%d,%d) ",
8173 i,
8174 adapter->queue_oper_stats[i].
8175 pause_count,
8176 adapter->queue_oper_stats[i].
8177 unpause_count);
8178 }
8179 if (tbytes >= sizeof(temp_str))
8180 hdd_warn("log truncated");
8181
8182 bytes_written += snprintf(&comb_log_str[bytes_written],
jiadbdefb252018-01-03 14:27:06 +08008183 bytes_written >= comb_log_str_size ? 0 :
8184 comb_log_str_size - bytes_written,
Mohit Khannaca4173b2017-09-12 21:52:19 -07008185 "[%d %d] (%d) %u/%ums %s|",
Jeff Johnson5a6fc962019-02-04 14:20:25 -08008186 adapter->vdev_id, adapter->device_mode,
Mohit Khannaca4173b2017-09-12 21:52:19 -07008187 adapter->pause_map,
8188 qdf_system_ticks_to_msecs(pause),
8189 qdf_system_ticks_to_msecs(total),
8190 temp_str);
8191
Mohit Khannaca4173b2017-09-12 21:52:19 -07008192 adapter_num++;
8193 }
8194
8195 /* using QDF_TRACE to avoid printing function name */
8196 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO_LOW,
8197 "STATS |%s", comb_log_str);
8198
jiadbdefb252018-01-03 14:27:06 +08008199 if (bytes_written >= comb_log_str_size)
Mohit Khannaca4173b2017-09-12 21:52:19 -07008200 hdd_warn("log string truncated");
jiadbdefb252018-01-03 14:27:06 +08008201
8202 qdf_mem_free(comb_log_str);
Mohit Khannaca4173b2017-09-12 21:52:19 -07008203}
8204
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008205/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07008206 * wlan_hdd_display_netif_queue_history() - display netif queue history
Jeff Johnson58adbcf2017-09-03 08:53:31 -07008207 * @hdd_ctx: hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008208 *
8209 * Return: none
8210 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07008211void
8212wlan_hdd_display_netif_queue_history(struct hdd_context *hdd_ctx,
8213 enum qdf_stats_verbosity_level verb_lvl)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008214{
8215
Jeff Johnson9d295242017-08-29 14:39:48 -07008216 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008217 int i;
Nirav Shahda008342016-05-17 18:50:40 +05308218 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008219
Mohit Khannaca4173b2017-09-12 21:52:19 -07008220 if (verb_lvl == QDF_STATS_VERBOSITY_LEVEL_LOW) {
8221 hdd_display_netif_queue_history_compact(hdd_ctx);
8222 return;
8223 }
8224
Dustin Brown920397d2017-12-13 16:27:50 -08008225 hdd_for_each_adapter(hdd_ctx, adapter) {
Nirav Shahe6194ac2018-07-13 11:04:41 +05308226 hdd_nofl_info("Netif queue operation statistics:");
Jeff Johnson55d2ab42019-03-06 11:43:49 -08008227 hdd_nofl_info("vdev_id %d device mode %d",
Jeff Johnson5a6fc962019-02-04 14:20:25 -08008228 adapter->vdev_id, adapter->device_mode);
Nirav Shahe6194ac2018-07-13 11:04:41 +05308229 hdd_nofl_info("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05308230 curr_time = qdf_system_ticks();
8231 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05308232 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05308233 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05308234 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05308235 unpause = adapter->total_unpause_time;
8236 } else {
Nirav Shahda008342016-05-17 18:50:40 +05308237 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05308238 pause = adapter->total_pause_time;
8239 }
Nirav Shahe6194ac2018-07-13 11:04:41 +05308240 hdd_nofl_info("Total: %ums Pause: %ums Unpause: %ums",
8241 qdf_system_ticks_to_msecs(total),
8242 qdf_system_ticks_to_msecs(pause),
8243 qdf_system_ticks_to_msecs(unpause));
8244 hdd_nofl_info("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008245
Nirav Shahda008342016-05-17 18:50:40 +05308246 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
8247 qdf_time_t pause_delta = 0;
8248
8249 if (adapter->pause_map & (1 << i))
8250 pause_delta = delta;
8251
Mohit Khanna3e2115b2016-10-11 13:18:29 -07008252 /* using hdd_log to avoid printing function name */
Nirav Shahe6194ac2018-07-13 11:04:41 +05308253 hdd_nofl_info("%s: %d: %d: %ums",
8254 hdd_reason_type_to_string(i),
8255 adapter->queue_oper_stats[i].pause_count,
8256 adapter->queue_oper_stats[i].
8257 unpause_count,
8258 qdf_system_ticks_to_msecs(
8259 adapter->queue_oper_stats[i].
8260 total_pause_time + pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008261 }
8262
Nirav Shahe6194ac2018-07-13 11:04:41 +05308263 hdd_nofl_info("Netif queue operation history:");
8264 hdd_nofl_info("Total entries: %d current index %d",
8265 WLAN_HDD_MAX_HISTORY_ENTRY,
8266 adapter->history_index);
Nirav Shahda008342016-05-17 18:50:40 +05308267
Nirav Shahe6194ac2018-07-13 11:04:41 +05308268 hdd_nofl_info("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008269
8270 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07008271 /* using hdd_log to avoid printing function name */
8272 if (adapter->queue_oper_history[i].time == 0)
8273 continue;
Nirav Shahe6194ac2018-07-13 11:04:41 +05308274 hdd_nofl_info("%d: %u: %s: %s: %x",
8275 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008276 adapter->queue_oper_history[i].time),
Nirav Shahe6194ac2018-07-13 11:04:41 +05308277 hdd_action_type_to_string(
8278 adapter->queue_oper_history[i].
8279 netif_action),
8280 hdd_reason_type_to_string(
8281 adapter->queue_oper_history[i].
8282 netif_reason),
8283 adapter->queue_oper_history[i].pause_map);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008284 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008285 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008286}
8287
8288/**
8289 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
8290 * @hdd_ctx: hdd context
8291 *
8292 * Return: none
8293 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008294void wlan_hdd_clear_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008295{
Jeff Johnson9d295242017-08-29 14:39:48 -07008296 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008297
Dustin Brown920397d2017-12-13 16:27:50 -08008298 hdd_for_each_adapter(hdd_ctx, adapter) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308299 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008300 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308301 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008302 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05308303 adapter->history_index = 0;
8304 adapter->start_time = adapter->last_time = qdf_system_ticks();
8305 adapter->total_pause_time = 0;
8306 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008307 }
8308}
8309
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008310#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
8311/**
8312 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
8313 * @hdd_ctx: hdd global context
8314 *
8315 * Return: none
8316 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008317static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008318{
8319 uint8_t i;
8320
8321 mutex_init(&hdd_ctx->op_ctx.op_lock);
8322 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
8323 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
8324 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
8325 }
8326}
8327#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008328static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008329{
8330}
8331#endif
8332
Yingying Tang95409972016-10-20 15:16:15 +08008333#ifdef WLAN_FEATURE_WOW_PULSE
8334/**
8335 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008336 * @phddctx: struct hdd_context structure pointer
Yingying Tang95409972016-10-20 15:16:15 +08008337 * @enable: enable or disable this behaviour
8338 *
8339 * Return: int
8340 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008341static int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08008342{
Yingying Tang95409972016-10-20 15:16:15 +08008343 struct wow_pulse_mode wow_pulse_set_info;
8344 QDF_STATUS status;
8345
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008346 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08008347
Wu Gao66454f12018-09-26 19:55:41 +08008348 if (!ucfg_pmo_is_wow_pulse_enabled(phddctx->psoc))
Yingying Tang95409972016-10-20 15:16:15 +08008349 return 0;
8350
8351 /* prepare the request to send to SME */
8352 if (enable == true) {
8353 wow_pulse_set_info.wow_pulse_enable = true;
8354 wow_pulse_set_info.wow_pulse_pin =
Wu Gao66454f12018-09-26 19:55:41 +08008355 ucfg_pmo_get_wow_pulse_pin(phddctx->psoc);
8356
Yingying Tang95409972016-10-20 15:16:15 +08008357 wow_pulse_set_info.wow_pulse_interval_high =
Wu Gao66454f12018-09-26 19:55:41 +08008358 ucfg_pmo_get_wow_pulse_interval_high(phddctx->psoc);
8359
8360 wow_pulse_set_info.wow_pulse_interval_low =
8361 ucfg_pmo_get_wow_pulse_interval_low(phddctx->psoc);
Yingying Tang95409972016-10-20 15:16:15 +08008362 } else {
8363 wow_pulse_set_info.wow_pulse_enable = false;
8364 wow_pulse_set_info.wow_pulse_pin = 0;
8365 wow_pulse_set_info.wow_pulse_interval_low = 0;
8366 wow_pulse_set_info.wow_pulse_interval_high = 0;
8367 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008368 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08008369 wow_pulse_set_info.wow_pulse_enable,
8370 wow_pulse_set_info.wow_pulse_pin,
8371 wow_pulse_set_info.wow_pulse_interval_low,
8372 wow_pulse_set_info.wow_pulse_interval_high);
8373
8374 status = sme_set_wow_pulse(&wow_pulse_set_info);
8375 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008376 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08008377 return -EIO;
8378 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008379 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08008380 return 0;
8381}
8382#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008383static inline int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08008384{
8385 return 0;
8386}
8387#endif
8388
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008389#ifdef WLAN_FEATURE_FASTPATH
jitiphil377bcc12018-10-05 19:46:08 +05308390
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008391/**
8392 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
8393 * @hdd_cfg: hdd config
8394 * @context: lower layer context
8395 *
8396 * Return: none
8397 */
jitiphil377bcc12018-10-05 19:46:08 +05308398void hdd_enable_fastpath(struct hdd_context *hdd_ctx,
8399 void *context)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008400{
jitiphil377bcc12018-10-05 19:46:08 +05308401 if (cfg_get(hdd_ctx->psoc, CFG_DP_ENABLE_FASTPATH))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008402 hif_enable_fastpath(context);
8403}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008404#endif
8405
Yuanyuan Liu13738502016-04-06 17:41:37 -07008406#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008407/**
8408 * hdd_set_thermal_level_cb() - set thermal level callback function
Jeff Johnson0e963082018-07-04 19:39:20 -07008409 * @hdd_handle: opaque handle for the hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008410 * @level: thermal level
8411 *
8412 * Change IPA data path to SW path when the thermal throttle level greater
8413 * than 0, and restore the original data path when throttle level is 0
8414 *
8415 * Return: none
8416 */
Jeff Johnson0e963082018-07-04 19:39:20 -07008417static void hdd_set_thermal_level_cb(hdd_handle_t hdd_handle, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008418{
Jeff Johnson0e963082018-07-04 19:39:20 -07008419 struct hdd_context *hdd_ctx = hdd_handle_to_context(hdd_handle);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008420
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008421 /* Change IPA to SW path when throttle level greater than 0 */
8422 if (level > THROTTLE_LEVEL_0)
Dustin Brown07901ec2018-09-07 11:02:41 -07008423 ucfg_ipa_send_mcc_scc_msg(hdd_ctx->pdev, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008424 else
8425 /* restore original concurrency mode */
Dustin Brown07901ec2018-09-07 11:02:41 -07008426 ucfg_ipa_send_mcc_scc_msg(hdd_ctx->pdev, hdd_ctx->mcc_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008427}
8428
8429/**
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +05308430 * hdd_get_safe_channel() - Get safe channel from current regulatory
8431 * @hdd_ctx: pointer to hdd context
8432 * @adapter: pointer to softap adapter
8433 *
8434 * This function is used to get safe channel from current regulatory valid
8435 * channels to restart SAP if failed to get safe channel from PCL.
8436 *
8437 * Return: Channel number to restart SAP in case of success. In case of any
8438 * failure, the channel number returned is zero.
8439 */
8440static uint8_t
8441hdd_get_safe_channel(struct hdd_context *hdd_ctx,
8442 struct hdd_adapter *adapter)
8443{
8444 struct sir_pcl_list pcl = {0};
8445 uint32_t i, j;
8446 bool found = false;
8447 int ret;
8448
8449 /* Try for safe channel from all valid channel */
8450 pcl.pcl_len = MAX_NUM_CHAN;
8451 ret = hdd_get_valid_chan(hdd_ctx, pcl.pcl_list,
8452 &pcl.pcl_len);
8453 if (ret) {
8454 hdd_err("error %d in getting valid channel list", ret);
8455 return INVALID_CHANNEL_ID;
8456 }
8457
8458 for (i = 0; i < pcl.pcl_len; i++) {
8459 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
8460 found = false;
8461 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
8462 if (pcl.pcl_list[i] ==
8463 hdd_ctx->unsafe_channel_list[j]) {
8464 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
8465 found = true;
8466 break;
8467 }
8468 }
8469
8470 if (found)
8471 continue;
8472
8473 if ((pcl.pcl_list[i] >=
8474 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
8475 (pcl.pcl_list[i] <=
8476 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
8477 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
8478 return pcl.pcl_list[i];
8479 }
8480 }
8481
8482 return INVALID_CHANNEL_ID;
8483}
8484
8485#else
8486/**
8487 * hdd_set_thermal_level_cb() - set thermal level callback function
8488 * @hdd_handle: opaque handle for the hdd context
8489 * @level: thermal level
8490 *
8491 * Change IPA data path to SW path when the thermal throttle level greater
8492 * than 0, and restore the original data path when throttle level is 0
8493 *
8494 * Return: none
8495 */
8496static void hdd_set_thermal_level_cb(hdd_handle_t hdd_handle, u_int8_t level)
8497{
8498}
8499
8500/**
8501 * hdd_get_safe_channel() - Get safe channel from current regulatory
8502 * @hdd_ctx: pointer to hdd context
8503 * @adapter: pointer to softap adapter
8504 *
8505 * This function is used to get safe channel from current regulatory valid
8506 * channels to restart SAP if failed to get safe channel from PCL.
8507 *
8508 * Return: Channel number to restart SAP in case of success. In case of any
8509 * failure, the channel number returned is zero.
8510 */
8511static uint8_t
8512hdd_get_safe_channel(struct hdd_context *hdd_ctx,
8513 struct hdd_adapter *adapter)
8514{
8515 return 0;
8516}
8517#endif
8518
8519/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308520 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
8521 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05308522 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008523 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308524 * Get a safe channel to restart SAP. PCL already takes into account the
8525 * unsafe channels. So, the PCL is validated with the ACS range to provide
8526 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008527 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308528 * Return: Channel number to restart SAP in case of success. In case of any
8529 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008530 */
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +05308531static uint8_t
8532hdd_get_safe_channel_from_pcl_and_acs_range(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008533{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308534 struct sir_pcl_list pcl;
8535 QDF_STATUS status;
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +05308536 uint32_t i;
Jeff Johnson16528362018-06-14 12:34:16 -07008537 mac_handle_t mac_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008538 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008539
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308540 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8541 if (!hdd_ctx) {
8542 hdd_err("invalid HDD context");
8543 return INVALID_CHANNEL_ID;
8544 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008545
Jeff Johnson16528362018-06-14 12:34:16 -07008546 mac_handle = hdd_ctx->mac_handle;
8547 if (!mac_handle) {
8548 hdd_err("invalid MAC handle");
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05308549 return INVALID_CHANNEL_ID;
8550 }
8551
Dustin Brown1dbefe62018-09-11 16:32:03 -07008552 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008553 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
bings37bd58f2017-07-20 16:49:26 +08008554 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list),
8555 false);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308556 if (QDF_IS_STATUS_ERROR(status)) {
8557 hdd_err("Get PCL failed");
8558 return INVALID_CHANNEL_ID;
8559 }
8560
Frank Liudc2cefb2017-06-21 15:38:18 +08008561 /*
8562 * In some scenarios, like hw dbs disabled, sap+sap case, if operating
8563 * channel is unsafe channel, the pcl may be empty, instead of return,
8564 * try to choose a safe channel from acs range.
8565 */
8566 if (!pcl.pcl_len)
8567 hdd_debug("pcl length is zero!");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308568
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008569 hdd_debug("start:%d end:%d",
Jeff Johnsonb9424862017-10-30 08:49:35 -07008570 adapter->session.ap.sap_config.acs_cfg.start_ch,
8571 adapter->session.ap.sap_config.acs_cfg.end_ch);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308572
8573 /* PCL already takes unsafe channel into account */
8574 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008575 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308576 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07008577 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308578 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07008579 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008580 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308581 return pcl.pcl_list[i];
8582 }
8583 }
8584
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008585 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308586
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +05308587 return hdd_get_safe_channel(hdd_ctx, adapter);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308588}
8589
8590/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08008591 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308592 * @adapter: AP adapter
8593 * @channel: Channel
Min Liu2fef5792018-01-19 17:59:42 +08008594 * @forced: Force to switch channel, ignore SCC/MCC check
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308595 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08008596 * Moves the SAP interface by invoking the function which
8597 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308598 *
8599 * Return: None
8600 */
Min Liu2fef5792018-01-19 17:59:42 +08008601void hdd_switch_sap_channel(struct hdd_adapter *adapter, uint8_t channel,
8602 bool forced)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308603{
Jeff Johnson87251032017-08-29 13:31:11 -07008604 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008605 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -07008606 mac_handle_t mac_handle;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308607
8608 if (!adapter) {
8609 hdd_err("invalid adapter");
8610 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008611 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308612
8613 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
8614
Jeff Johnson16528362018-06-14 12:34:16 -07008615 mac_handle = hdd_adapter_get_mac_handle(adapter);
8616 if (!mac_handle) {
8617 hdd_err("invalid MAC handle");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308618 return;
8619 }
8620
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008621 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8622
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008623 hdd_debug("chan:%d width:%d",
Jeff Johnson91df29d2017-10-27 19:29:50 -07008624 channel, hdd_ap_ctx->sap_config.ch_width_orig);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308625
Dustin Brown1dbefe62018-09-11 16:32:03 -07008626 policy_mgr_change_sap_channel_with_csa(hdd_ctx->psoc,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08008627 adapter->vdev_id, channel,
Min Liu2fef5792018-01-19 17:59:42 +08008628 hdd_ap_ctx->sap_config.ch_width_orig, forced);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008629}
Kapil Gupta8878ad92017-02-13 11:56:04 +05308630
Jeff Johnson9d295242017-08-29 14:39:48 -07008631int hdd_update_acs_timer_reason(struct hdd_adapter *adapter, uint8_t reason)
Kapil Gupta8878ad92017-02-13 11:56:04 +05308632{
8633 struct hdd_external_acs_timer_context *timer_context;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308634 int status;
8635 QDF_STATUS qdf_status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308636
8637 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
8638
8639 if (QDF_TIMER_STATE_RUNNING ==
Jeff Johnsonb9424862017-10-30 08:49:35 -07008640 qdf_mc_timer_get_current_state(&adapter->session.
Kapil Gupta8878ad92017-02-13 11:56:04 +05308641 ap.vendor_acs_timer)) {
Jeff Johnsonb9424862017-10-30 08:49:35 -07008642 qdf_mc_timer_stop(&adapter->session.ap.vendor_acs_timer);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308643 }
8644 timer_context = (struct hdd_external_acs_timer_context *)
Jeff Johnsonb9424862017-10-30 08:49:35 -07008645 adapter->session.ap.vendor_acs_timer.user_data;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308646 timer_context->reason = reason;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308647 qdf_status =
Jeff Johnsonb9424862017-10-30 08:49:35 -07008648 qdf_mc_timer_start(&adapter->session.ap.vendor_acs_timer,
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308649 WLAN_VENDOR_ACS_WAIT_TIME);
8650 if (qdf_status != QDF_STATUS_SUCCESS) {
8651 hdd_err("failed to start external acs timer");
8652 return -ENOSPC;
8653 }
8654 /* Update config to application */
8655 status = hdd_cfg80211_update_acs_config(adapter, reason);
Dustin Brown5e89ef82018-03-14 11:50:23 -07008656 hdd_info("Updated ACS config to nl with reason %d", reason);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308657
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308658 return status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308659}
8660
Nirav Shaheb017be2018-02-15 11:20:58 +05308661#if defined(FEATURE_WLAN_CH_AVOID)
Agrawal Ashish467dde42016-09-08 18:44:22 +05308662/**
8663 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
8664 * @hdd_ctx: hdd context pointer
8665 *
8666 * hdd_unsafe_channel_restart_sap check all unsafe channel list
8667 * and if ACS is enabled, driver will ask userspace to restart the
8668 * sap. User space on LTE coex indication restart driver.
8669 *
8670 * Return - none
8671 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008672void hdd_unsafe_channel_restart_sap(struct hdd_context *hdd_ctxt)
Agrawal Ashish467dde42016-09-08 18:44:22 +05308673{
Dustin Brown920397d2017-12-13 16:27:50 -08008674 struct hdd_adapter *adapter;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308675 uint32_t i;
8676 bool found = false;
8677 uint8_t restart_chan;
Krunal Sonidf29bc42018-11-15 13:26:29 -08008678 uint8_t scc_on_lte_coex = 0;
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05308679 bool value;
Harprit Chhabada1eeeb8d2018-09-14 15:16:56 -07008680 QDF_STATUS status;
8681 bool is_acs_support_for_dfs_ltecoex = cfg_default(CFG_USER_ACS_DFS_LTE);
8682 bool is_vendor_acs_support =
8683 cfg_default(CFG_USER_AUTO_CHANNEL_SELECTION);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008684
Dustin Brown920397d2017-12-13 16:27:50 -08008685 hdd_for_each_adapter(hdd_ctxt, adapter) {
8686 if (!(adapter->device_mode == QDF_SAP_MODE &&
8687 adapter->session.ap.sap_config.acs_cfg.acs_mode)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008688 hdd_debug("skip device mode:%d acs:%d",
Dustin Brown920397d2017-12-13 16:27:50 -08008689 adapter->device_mode,
8690 adapter->session.ap.sap_config.
8691 acs_cfg.acs_mode);
8692 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308693 }
8694
8695 found = false;
Krunal Sonidf29bc42018-11-15 13:26:29 -08008696 status =
8697 ucfg_policy_mgr_get_sta_sap_scc_lte_coex_chnl(hdd_ctxt->psoc,
8698 &scc_on_lte_coex);
8699 if (!QDF_IS_STATUS_SUCCESS(status))
8700 hdd_err("can't get scc on lte coex chnl, use def");
Tushnim Bhattacharyyad2e085d2018-06-18 11:58:50 -07008701 /*
8702 * If STA+SAP is doing SCC & g_sta_sap_scc_on_lte_coex_chan
8703 * is set, no need to move SAP.
8704 */
Dustin Brown1dbefe62018-09-11 16:32:03 -07008705 if (policy_mgr_is_sta_sap_scc(hdd_ctxt->psoc,
Tushnim Bhattacharyyad2e085d2018-06-18 11:58:50 -07008706 adapter->session.ap.operating_channel) &&
Krunal Sonidf29bc42018-11-15 13:26:29 -08008707 scc_on_lte_coex)
Tushnim Bhattacharyyad2e085d2018-06-18 11:58:50 -07008708 hdd_debug("SAP is allowed on SCC channel, no need to move SAP");
8709 else {
8710 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
8711 if (adapter->session.ap.operating_channel ==
8712 hdd_ctxt->unsafe_channel_list[i]) {
8713 found = true;
8714 hdd_debug("operating ch:%d is unsafe",
8715 adapter->session.ap.operating_channel);
8716 break;
8717 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308718 }
8719 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308720 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008721 hdd_debug("ch:%d is safe. no need to change channel",
Dustin Brown920397d2017-12-13 16:27:50 -08008722 adapter->session.ap.operating_channel);
8723 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308724 }
8725
Harprit Chhabada1eeeb8d2018-09-14 15:16:56 -07008726 status = ucfg_mlme_get_acs_support_for_dfs_ltecoex(
8727 hdd_ctxt->psoc,
8728 &is_acs_support_for_dfs_ltecoex);
8729 if (!QDF_IS_STATUS_SUCCESS(status))
8730 hdd_err("get_acs_support_for_dfs_ltecoex failed,set def");
8731
8732 status = ucfg_mlme_get_vendor_acs_support(
8733 hdd_ctxt->psoc,
8734 &is_vendor_acs_support);
8735 if (!QDF_IS_STATUS_SUCCESS(status))
8736 hdd_err("get_vendor_acs_support failed, set default");
8737
8738 if (is_vendor_acs_support && is_acs_support_for_dfs_ltecoex) {
Dustin Brown920397d2017-12-13 16:27:50 -08008739 hdd_update_acs_timer_reason(adapter,
Kapil Gupta8878ad92017-02-13 11:56:04 +05308740 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
Dustin Brown920397d2017-12-13 16:27:50 -08008741 continue;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308742 } else
8743 restart_chan =
8744 hdd_get_safe_channel_from_pcl_and_acs_range(
Dustin Brown920397d2017-12-13 16:27:50 -08008745 adapter);
Agrawal Ashish467dde42016-09-08 18:44:22 +05308746 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008747 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05308748 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08008749 /*
8750 * SAP restart due to unsafe channel. While
8751 * restarting the SAP, make sure to clear
8752 * acs_channel, channel to reset to
8753 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308754 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08008755 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308756 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008757 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05308758 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
8759 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Dustin Brown05d81302018-09-11 16:49:22 -07008760 ucfg_mlme_get_sap_internal_restart(hdd_ctxt->psoc,
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05308761 &value);
8762 hdd_debug("driver to start sap: %d", value);
8763 if (value)
Min Liu2fef5792018-01-19 17:59:42 +08008764 hdd_switch_sap_channel(adapter, restart_chan,
8765 true);
Liangwei Dong6663d162017-07-10 03:29:36 -04008766 else
8767 return;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308768 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308769 }
8770}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05308771
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008772/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008773 * hdd_init_channel_avoidance() - Initialize channel avoidance
8774 * @hdd_ctx: HDD global context
8775 *
8776 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07008777 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008778 * down to the lower layers. Then subscribe to subsequent channel
8779 * avoidance events.
8780 *
8781 * Return: None
8782 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008783static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008784{
8785 uint16_t unsafe_channel_count;
8786 int index;
8787
Yuanyuan Liu13738502016-04-06 17:41:37 -07008788 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
8789 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008790 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08008791 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008792
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008793 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008794 hdd_ctx->unsafe_channel_count);
8795
Anurag Chouhan6d760662016-02-20 16:05:43 +05308796 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08008797 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008798
8799 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008800 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008801 hdd_ctx->unsafe_channel_list[index]);
8802
8803 }
8804
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008805}
Dustin Brown676a2322017-08-15 13:16:13 -07008806
Jeff Johnson9d295242017-08-29 14:39:48 -07008807static void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008808 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07008809{
8810 uint8_t restart_chan;
8811
8812 restart_chan = hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
8813 if (!restart_chan) {
8814 hdd_alert("fail to restart SAP");
8815 return;
8816 }
8817
8818 /* SAP restart due to unsafe channel. While restarting
8819 * the SAP, make sure to clear acs_channel, channel to
8820 * reset to 0. Otherwise these settings will override
8821 * the ACS while restart.
8822 */
8823 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Dustin Brown676a2322017-08-15 13:16:13 -07008824
8825 hdd_debug("sending coex indication");
8826
8827 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
8828 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Min Liu2fef5792018-01-19 17:59:42 +08008829 hdd_switch_sap_channel(adapter, restart_chan, true);
Dustin Brown676a2322017-08-15 13:16:13 -07008830}
Liangwei Dong6e1a2092017-08-30 16:29:06 +08008831
8832int hdd_clone_local_unsafe_chan(struct hdd_context *hdd_ctx,
8833 uint16_t **local_unsafe_list, uint16_t *local_unsafe_list_count)
8834{
8835 uint32_t size;
8836 uint16_t *unsafe_list;
8837 uint16_t chan_count;
8838
8839 if (!hdd_ctx || !local_unsafe_list_count || !local_unsafe_list_count)
8840 return -EINVAL;
8841
8842 chan_count = QDF_MIN(hdd_ctx->unsafe_channel_count,
8843 NUM_CHANNELS);
8844 if (chan_count) {
8845 size = chan_count * sizeof(hdd_ctx->unsafe_channel_list[0]);
8846 unsafe_list = qdf_mem_malloc(size);
Min Liu74a1a502018-10-10 19:59:07 +08008847 if (!unsafe_list)
Liangwei Dong6e1a2092017-08-30 16:29:06 +08008848 return -ENOMEM;
Liangwei Dong6e1a2092017-08-30 16:29:06 +08008849 qdf_mem_copy(unsafe_list, hdd_ctx->unsafe_channel_list, size);
8850 } else {
8851 unsafe_list = NULL;
8852 }
8853
8854 *local_unsafe_list = unsafe_list;
8855 *local_unsafe_list_count = chan_count;
8856
8857 return 0;
8858}
8859
8860bool hdd_local_unsafe_channel_updated(struct hdd_context *hdd_ctx,
8861 uint16_t *local_unsafe_list, uint16_t local_unsafe_list_count)
8862{
8863 int i, j;
8864
8865 if (local_unsafe_list_count != hdd_ctx->unsafe_channel_count)
8866 return true;
8867 if (local_unsafe_list_count == 0)
8868 return false;
8869 for (i = 0; i < local_unsafe_list_count; i++) {
8870 for (j = 0; j < local_unsafe_list_count; j++)
8871 if (local_unsafe_list[i] ==
8872 hdd_ctx->unsafe_channel_list[j])
8873 break;
8874 if (j >= local_unsafe_list_count)
8875 break;
8876 }
8877 if (i >= local_unsafe_list_count) {
8878 hdd_info("unsafe chan list same");
8879 return false;
8880 }
8881
8882 return true;
8883}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008884#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008885static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008886{
8887}
Dustin Brown676a2322017-08-15 13:16:13 -07008888
Jeff Johnson9d295242017-08-29 14:39:48 -07008889static inline void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008890 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07008891{
8892 hdd_debug("Channel avoidance is not enabled; Abort SAP restart");
8893}
Yuanyuan Liu13738502016-04-06 17:41:37 -07008894#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008895
8896/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08008897 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
8898 * user space
8899 * @frame_ind: Management frame data to be informed.
8900 *
8901 * This function is used to indicate management frame to
8902 * user space
8903 *
8904 * Return: None
8905 *
8906 */
8907void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
8908{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008909 struct hdd_context *hdd_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07008910 struct hdd_adapter *adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008911 int i;
Pragaspathi Thilagaraj28ffc042018-07-18 15:19:36 +05308912 struct ieee80211_mgmt *mgmt =
8913 (struct ieee80211_mgmt *)frame_ind->frameBuf;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008914
Dustin Browne7e71d32018-05-11 16:00:08 -07008915 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
8916 if (wlan_hdd_validate_context(hdd_ctx))
Rajeev Kumard004abc2016-02-17 12:09:56 -08008917 return;
8918
Pragaspathi Thilagaraj28ffc042018-07-18 15:19:36 +05308919 if (frame_ind->frame_len < ieee80211_hdrlen(mgmt->frame_control)) {
8920 hdd_err(" Invalid frame length");
8921 return;
8922 }
8923
Rajeev Kumard004abc2016-02-17 12:09:56 -08008924 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
Dustin Brownad06be62019-02-04 14:52:56 -08008925 for (i = 0; i < WLAN_MAX_VDEVS; i++) {
Rajeev Kumard004abc2016-02-17 12:09:56 -08008926 adapter =
Jeff Johnson55d2ab42019-03-06 11:43:49 -08008927 hdd_get_adapter_by_vdev(hdd_ctx, i);
Rajeev Kumard004abc2016-02-17 12:09:56 -08008928 if (adapter)
8929 break;
8930 }
Wu Gaoa0230a62018-01-04 20:56:57 +08008931 } else if (SME_SESSION_ID_BROADCAST == frame_ind->sessionId) {
8932 hdd_for_each_adapter(hdd_ctx, adapter) {
Jeff Johnsond36fa332019-03-18 13:42:25 -07008933 if ((adapter) &&
Wu Gaoa0230a62018-01-04 20:56:57 +08008934 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)) {
8935 __hdd_indicate_mgmt_frame(adapter,
8936 frame_ind->frame_len,
8937 frame_ind->frameBuf,
8938 frame_ind->frameType,
8939 frame_ind->rxChan,
Srinivas Dasariea1c1332019-02-18 12:43:23 +05308940 frame_ind->rxRssi,
8941 frame_ind->rx_flags);
Wu Gaoa0230a62018-01-04 20:56:57 +08008942 }
8943 }
8944 adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008945 } else {
Jeff Johnson55d2ab42019-03-06 11:43:49 -08008946 adapter = hdd_get_adapter_by_vdev(hdd_ctx,
8947 frame_ind->sessionId);
Rajeev Kumard004abc2016-02-17 12:09:56 -08008948 }
8949
Jeff Johnsond36fa332019-03-18 13:42:25 -07008950 if ((adapter) &&
Rajeev Kumard004abc2016-02-17 12:09:56 -08008951 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
8952 __hdd_indicate_mgmt_frame(adapter,
8953 frame_ind->frame_len,
8954 frame_ind->frameBuf,
8955 frame_ind->frameType,
8956 frame_ind->rxChan,
Srinivas Dasariea1c1332019-02-18 12:43:23 +05308957 frame_ind->rxRssi,
8958 frame_ind->rx_flags);
Rajeev Kumard004abc2016-02-17 12:09:56 -08008959}
8960
Kapil Gupta8878ad92017-02-13 11:56:04 +05308961void hdd_acs_response_timeout_handler(void *context)
8962{
8963 struct hdd_external_acs_timer_context *timer_context =
8964 (struct hdd_external_acs_timer_context *)context;
Jeff Johnson9d295242017-08-29 14:39:48 -07008965 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008966 struct hdd_context *hdd_ctx;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308967 uint8_t reason;
8968
Dustin Brown491d54b2018-03-14 12:39:11 -07008969 hdd_enter();
Kapil Gupta8878ad92017-02-13 11:56:04 +05308970 if (!timer_context) {
8971 hdd_err("invlaid timer context");
8972 return;
8973 }
8974 adapter = timer_context->adapter;
8975 reason = timer_context->reason;
8976
8977
8978 if ((!adapter) ||
8979 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
8980 hdd_err("invalid adapter or adapter has invalid magic");
8981 return;
8982 }
8983 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8984 if (wlan_hdd_validate_context(hdd_ctx))
8985 return;
8986
8987 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
8988 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
8989 else
8990 return;
8991
8992 hdd_err("ACS timeout happened for %s reason %d",
8993 adapter->dev->name, reason);
Jeff Johnson16528362018-06-14 12:34:16 -07008994
Kapil Gupta8878ad92017-02-13 11:56:04 +05308995 switch (reason) {
8996 /* SAP init case */
8997 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
8998 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
8999 false);
9000 wlan_hdd_cfg80211_start_acs(adapter);
9001 break;
9002 /* DFS detected on current channel */
9003 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
9004 wlan_sap_update_next_channel(
9005 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
Jeff Johnson16528362018-06-14 12:34:16 -07009006 sme_update_new_channel_event(hdd_ctx->mac_handle,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08009007 adapter->vdev_id);
Kapil Gupta8878ad92017-02-13 11:56:04 +05309008 break;
9009 /* LTE coex event on current channel */
9010 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
9011 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
9012 break;
9013 default:
9014 hdd_info("invalid reason for timer invoke");
9015
9016 }
9017}
9018
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009019/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009020 * hdd_override_ini_config - Override INI config
9021 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009022 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009023 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009024 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009025 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009026 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009027static void hdd_override_ini_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009028{
Abhinav Kumard4d6eb72018-12-04 20:30:37 +05309029 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009030
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009031 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
gaurank kathpalia97c070b2019-01-07 17:23:06 +05309032 ucfg_scan_cfg_set_dfs_chan_scan_allowed(hdd_ctx->psoc,
9033 enable_dfs_chan_scan);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009034 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009035 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009036 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009037 if (0 == enable_11d || 1 == enable_11d) {
Abhinav Kumard4d6eb72018-12-04 20:30:37 +05309038 status = ucfg_mlme_set_11d_enabled(hdd_ctx->psoc, enable_11d);
9039 if (!QDF_IS_STATUS_SUCCESS(status))
9040 hdd_err("Failed to set 11d_enable flag");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009041 }
Leo Chang11545d62016-10-17 14:53:50 -07009042
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +05309043 if (hdd_ctx->config->action_oui_enable && !ucfg_action_oui_enabled()) {
9044 hdd_ctx->config->action_oui_enable = 0;
Sourav Mohapatra58841062018-11-19 16:33:27 +05309045 hdd_err("Ignore action oui ini, since no action_oui component");
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +05309046 }
Will Huang14b120f2019-01-14 17:26:14 +08009047
9048 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
9049 hdd_override_all_ps(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009050}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009051
Ashish Kumar Dhanotiya12f68212018-09-04 22:00:14 +05309052#ifdef ENABLE_MTRACE_LOG
9053static void hdd_set_mtrace_for_each(struct hdd_context *hdd_ctx)
9054{
9055 uint8_t module_id = 0;
9056 int qdf_print_idx = -1;
9057
9058 qdf_print_idx = qdf_get_pidx();
9059 for (module_id = 0; module_id < QDF_MODULE_ID_MAX; module_id++)
9060 qdf_print_set_category_verbose(
9061 qdf_print_idx,
9062 module_id, QDF_TRACE_LEVEL_TRACE,
9063 hdd_ctx->config->enable_mtrace);
9064}
9065#else
9066static void hdd_set_mtrace_for_each(struct hdd_context *hdd_ctx)
9067{
9068}
9069
9070#endif
9071
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009072/**
9073 * hdd_set_trace_level_for_each - Set trace level for each INI config
9074 * @hdd_ctx - HDD context
9075 *
9076 * Set trace level for each module based on INI config.
9077 *
9078 * Return: None
9079 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009080static void hdd_set_trace_level_for_each(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009081{
Wu Gaobc6eaa12018-11-30 14:17:45 +08009082 hdd_qdf_trace_enable(QDF_MODULE_ID_DP, 0x7f);
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05309083 hdd_qdf_trace_enable(QDF_MODULE_ID_MLME, 0xffff);
Sourav Mohapatra113685f2018-08-29 14:21:55 +05309084 hdd_qdf_trace_enable(QDF_MODULE_ID_FWOL, 0xffff);
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07009085 hdd_qdf_trace_enable(QDF_MODULE_ID_CRYPTO, 0xffff);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07009086
Ashish Kumar Dhanotiya12f68212018-09-04 22:00:14 +05309087 hdd_set_mtrace_for_each(hdd_ctx);
9088
Nirav Shah5c083da2018-08-03 13:46:02 +05309089 hdd_cfg_print_global_config(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009090}
9091
9092/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009093 * hdd_context_init() - Initialize HDD context
9094 * @hdd_ctx: HDD context.
9095 *
9096 * Initialize HDD context along with all the feature specific contexts.
9097 *
9098 * return: 0 on success and errno on failure.
9099 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009100static int hdd_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009101{
9102 int ret;
9103
9104 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
Dustin Brownad06be62019-02-04 14:52:56 -08009105 hdd_ctx->max_intf_count = WLAN_MAX_VDEVS;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009106
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009107 init_completion(&hdd_ctx->mc_sus_event_var);
9108 init_completion(&hdd_ctx->ready_to_suspend);
9109
9110 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009111 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05309112
Dustin Brownbee82832018-07-23 10:10:51 -07009113 qdf_list_create(&hdd_ctx->hdd_adapters, 0);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009114
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009115 ret = hdd_scan_context_init(hdd_ctx);
9116 if (ret)
9117 goto list_destroy;
9118
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009119 hdd_rx_wake_lock_create(hdd_ctx);
9120
9121 ret = hdd_sap_context_init(hdd_ctx);
9122 if (ret)
9123 goto scan_destroy;
9124
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009125 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
9126
9127 hdd_init_offloaded_packets_ctx(hdd_ctx);
9128
9129 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
9130 hdd_ctx->config);
9131 if (ret)
Wu Gao02bd75b2017-10-13 18:34:02 +08009132 goto sap_destroy;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009133
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05309134 qdf_wake_lock_create(&hdd_ctx->monitor_mode_wakelock,
9135 "monitor_mode_wakelock");
9136
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009137 return 0;
9138
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009139sap_destroy:
9140 hdd_sap_context_destroy(hdd_ctx);
9141
9142scan_destroy:
9143 hdd_scan_context_destroy(hdd_ctx);
9144 hdd_rx_wake_lock_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009145list_destroy:
Jeff Johnson19fc8e42017-10-30 19:53:49 -07009146 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08009147
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009148 return ret;
9149}
9150
Dustin Brown4c663222018-10-23 14:19:36 -07009151void hdd_psoc_idle_timer_start(struct hdd_context *hdd_ctx)
9152{
9153 uint32_t timeout_ms = hdd_ctx->config->iface_change_wait_time;
9154 enum wake_lock_reason reason =
9155 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER;
9156
Rajeev Kumar7b7bb3f2018-12-20 12:09:54 -08009157 if (!timeout_ms) {
9158 hdd_info("psoc idle timer is disabled");
9159 return;
9160 }
9161
Dustin Brown4c663222018-10-23 14:19:36 -07009162 hdd_debug("Starting psoc idle timer");
Dustin Brown8d8ab302019-03-05 16:19:36 -08009163 qdf_delayed_work_start(&hdd_ctx->psoc_idle_timeout_work, timeout_ms);
Dustin Brown4c663222018-10-23 14:19:36 -07009164 hdd_prevent_suspend_timeout(timeout_ms, reason);
9165}
9166
9167void hdd_psoc_idle_timer_stop(struct hdd_context *hdd_ctx)
9168{
Dustin Brown8d8ab302019-03-05 16:19:36 -08009169 qdf_delayed_work_stop_sync(&hdd_ctx->psoc_idle_timeout_work);
Dustin Brown4c663222018-10-23 14:19:36 -07009170 hdd_debug("Stopped psoc idle timer");
9171}
9172
Sourav Mohapatra698d6f62019-01-29 14:49:52 +05309173/*
9174 * enum hdd_block_shutdown - Control if driver allows modem shutdown
9175 * @HDD_UNBLOCK_MODEM_SHUTDOWN: Unblock shutdown
9176 * @HDD_BLOCK_MODEM_SHUTDOWN: Block shutdown
9177 *
9178 * On calling pld_block_shutdown API with the given values, modem
9179 * graceful shutdown is blocked/unblocked.
9180 */
9181enum hdd_block_shutdown {
9182 HDD_UNBLOCK_MODEM_SHUTDOWN,
9183 HDD_BLOCK_MODEM_SHUTDOWN,
9184};
9185
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009186/**
Dustin Brown3ecc8782018-09-19 16:37:13 -07009187 * hdd_psoc_idle_shutdown() - perform an idle shutdown on the given psoc
9188 * @hdd_ctx: the hdd context which should be shutdown
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309189 *
Dustin Brown3ecc8782018-09-19 16:37:13 -07009190 * When no interfaces are "up" on a psoc, an idle shutdown timer is started.
9191 * If no interfaces are brought up before the timer expires, we do an
9192 * "idle shutdown," cutting power to the physical SoC to save power. This is
9193 * done completely transparently from the perspective of userspace.
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309194 *
Dustin Brown3ecc8782018-09-19 16:37:13 -07009195 * Return: None
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309196 */
Dustin Brown3ecc8782018-09-19 16:37:13 -07009197static void hdd_psoc_idle_shutdown(struct hdd_context *hdd_ctx)
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309198{
Dustin Brown363b4792019-02-05 16:11:55 -08009199 struct osif_psoc_sync *psoc_sync;
Dustin Browncfcb5762019-01-31 15:43:45 -08009200 int errno;
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309201
Dustin Brown491d54b2018-03-14 12:39:11 -07009202 hdd_enter();
Dustin Brown3ecc8782018-09-19 16:37:13 -07009203
Dustin Brown363b4792019-02-05 16:11:55 -08009204 errno = osif_psoc_sync_trans_start(hdd_ctx->parent_dev, &psoc_sync);
Dustin Browncfcb5762019-01-31 15:43:45 -08009205 if (errno) {
9206 hdd_info("psoc busy, abort idle shutdown; errno:%d", errno);
9207 goto exit;
Dustin Brown3ecc8782018-09-19 16:37:13 -07009208 }
Sourav Mohapatra698d6f62019-01-29 14:49:52 +05309209 /* Block the modem graceful shutdown till stop modules is completed */
9210 pld_block_shutdown(hdd_ctx->parent_dev, HDD_BLOCK_MODEM_SHUTDOWN);
Dustin Brown3ecc8782018-09-19 16:37:13 -07009211
Dustin Brown363b4792019-02-05 16:11:55 -08009212 osif_psoc_sync_wait_for_ops(psoc_sync);
Dustin Browncfcb5762019-01-31 15:43:45 -08009213
Dustin Brown3ecc8782018-09-19 16:37:13 -07009214 QDF_BUG(!hdd_wlan_stop_modules(hdd_ctx, false));
9215
Dustin Brown363b4792019-02-05 16:11:55 -08009216 osif_psoc_sync_trans_stop(psoc_sync);
Dustin Brown3ecc8782018-09-19 16:37:13 -07009217
Sourav Mohapatra698d6f62019-01-29 14:49:52 +05309218 pld_block_shutdown(hdd_ctx->parent_dev, HDD_UNBLOCK_MODEM_SHUTDOWN);
9219
Dustin Browncfcb5762019-01-31 15:43:45 -08009220exit:
Dustin Browne74003f2018-03-14 12:51:58 -07009221 hdd_exit();
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309222}
9223
Dustin Brown3ecc8782018-09-19 16:37:13 -07009224int hdd_psoc_idle_restart(struct hdd_context *hdd_ctx)
9225{
Dustin Brown693b5352019-01-17 10:00:31 -08009226 QDF_BUG(rtnl_is_locked());
Dustin Brown3ecc8782018-09-19 16:37:13 -07009227
Dustin Browncfcb5762019-01-31 15:43:45 -08009228 return hdd_wlan_start_modules(hdd_ctx, false);
Dustin Brown3ecc8782018-09-19 16:37:13 -07009229}
9230
9231/**
9232 * hdd_psoc_idle_timeout_callback() - Handler for psoc idle timeout
9233 * @priv: pointer to hdd context
9234 *
9235 * Return: None
9236 */
9237static void hdd_psoc_idle_timeout_callback(void *priv)
9238{
9239 struct hdd_context *hdd_ctx = priv;
9240
9241 if (wlan_hdd_validate_context(hdd_ctx))
9242 return;
9243
9244 hdd_debug("Psoc idle timeout elapsed; starting psoc shutdown");
9245 hdd_psoc_idle_shutdown(hdd_ctx);
9246}
9247
Nirav Shaheb017be2018-02-15 11:20:58 +05309248#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
9249static void hdd_set_wlan_logging(struct hdd_context *hdd_ctx)
9250{
9251 wlan_logging_set_log_to_console(hdd_ctx->config->
9252 wlan_logging_to_console);
9253 wlan_logging_set_active(hdd_ctx->config->wlan_logging_enable);
9254}
9255#else
9256static void hdd_set_wlan_logging(struct hdd_context *hdd_ctx)
9257{ }
9258#endif
9259
Dundi Raviteja8e338282018-09-25 17:16:04 +05309260#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
9261static void hdd_init_wlan_logging_params(struct hdd_config *config,
9262 struct wlan_objmgr_psoc *psoc)
9263{
9264 config->wlan_logging_enable = cfg_get(psoc, CFG_WLAN_LOGGING_SUPPORT);
9265
9266 config->wlan_logging_to_console =
9267 cfg_get(psoc, CFG_WLAN_LOGGING_CONSOLE_SUPPORT);
9268}
9269#else
9270static void hdd_init_wlan_logging_params(struct hdd_config *config,
9271 struct wlan_objmgr_psoc *psoc)
9272{
9273}
9274#endif
9275
9276#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
9277static void hdd_init_wlan_auto_shutdown(struct hdd_config *config,
9278 struct wlan_objmgr_psoc *psoc)
9279{
9280 config->wlan_auto_shutdown = cfg_get(psoc, CFG_WLAN_AUTO_SHUTDOWN);
9281}
9282#else
9283static void hdd_init_wlan_auto_shutdown(struct hdd_config *config,
9284 struct wlan_objmgr_psoc *psoc)
9285{
9286}
9287#endif
9288
9289#ifndef REMOVE_PKT_LOG
9290static void hdd_init_packet_log(struct hdd_config *config,
9291 struct wlan_objmgr_psoc *psoc)
9292{
9293 config->enable_packet_log = cfg_get(psoc, CFG_ENABLE_PACKET_LOG);
9294}
9295#else
9296static void hdd_init_packet_log(struct hdd_config *config,
9297 struct wlan_objmgr_psoc *psoc)
9298{
9299}
9300#endif
9301
Sandeep Puligilla43b6d1a2018-12-03 09:16:13 -08009302#ifdef ENABLE_MTRACE_LOG
9303static void hdd_init_mtrace_log(struct hdd_config *config,
9304 struct wlan_objmgr_psoc *psoc)
9305{
9306 config->enable_mtrace = cfg_get(psoc, CFG_ENABLE_MTRACE);
9307}
9308#else
9309static void hdd_init_mtrace_log(struct hdd_config *config,
9310 struct wlan_objmgr_psoc *psoc)
9311{
9312}
9313#endif
9314
Sourav Mohapatra0dfe5552018-11-16 11:29:54 +05309315#ifdef FEATURE_RUNTIME_PM
9316static void hdd_init_runtime_pm(struct hdd_config *config,
9317 struct wlan_objmgr_psoc *psoc)
9318{
9319 config->runtime_pm = cfg_get(psoc, CFG_ENABLE_RUNTIME_PM);
9320}
9321#else
9322static void hdd_init_runtime_pm(struct hdd_config *config,
9323 struct wlan_objmgr_psoc *psoc)
9324
9325{
9326}
9327#endif
9328
9329#ifdef FEATURE_WLAN_DYNAMIC_CVM
9330static void hdd_init_vc_mode_cfg_bitmap(struct hdd_config *config,
9331 struct wlan_objmgr_psoc *psoc)
9332{
9333 config->vc_mode_cfg_bitmap = cfg_get(psoc, CFG_VC_MODE_BITMAP);
9334}
9335#else
9336static void hdd_init_vc_mode_cfg_bitmap(struct hdd_config *config,
9337 struct wlan_objmgr_psoc *psoc)
9338{
9339}
9340#endif
9341
gaurank kathpalia566c81b2019-02-20 14:31:45 +05309342#ifdef DHCP_SERVER_OFFLOAD
9343static void
9344hdd_init_dhcp_server_ip(struct hdd_context *hdd_ctx)
9345{
9346 uint8_t num_entries;
9347
9348 hdd_ctx->config->dhcp_server_ip.is_dhcp_server_ip_valid = true;
9349 hdd_string_to_u8_array(cfg_get(hdd_ctx->psoc, CFG_DHCP_SERVER_IP_NAME),
9350 hdd_ctx->config->dhcp_server_ip.dhcp_server_ip,
9351 &num_entries, IPADDR_NUM_ENTRIES);
9352
9353 if (num_entries != IPADDR_NUM_ENTRIES) {
9354 hdd_err("Incorrect IP address (%s) assigned for DHCP server!",
9355 cfg_get(hdd_ctx->psoc, CFG_DHCP_SERVER_IP_NAME));
9356 hdd_config->dhcp_server_ip.is_dhcp_server_ip_valid = false;
9357 }
9358}
9359#else
9360static void
9361hdd_init_dhcp_server_ip(struct hdd_context *hdd_ctx)
9362{
9363}
9364#endif
9365
Dundi Raviteja8e338282018-09-25 17:16:04 +05309366/**
9367 * hdd_cfg_params_init() - Initialize hdd params in hdd_config strucuture
9368 * @hdd_ctx - Pointer to HDD context
9369 *
9370 * Return: None
9371 */
9372static void hdd_cfg_params_init(struct hdd_context *hdd_ctx)
9373{
9374 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
9375 struct hdd_config *config = hdd_ctx->config;
9376
9377 if (!psoc) {
9378 hdd_err("Invalid psoc");
9379 return;
9380 }
9381
9382 if (!config) {
9383 hdd_err("Invalid hdd config");
9384 return;
9385 }
9386
gaurank kathpalia43c52622019-02-11 12:30:05 +05309387 config->dot11Mode = cfg_get(psoc, CFG_HDD_DOT11_MODE);
Dundi Raviteja8e338282018-09-25 17:16:04 +05309388 config->bug_on_reinit_failure = cfg_get(psoc,
9389 CFG_BUG_ON_REINIT_FAILURE);
9390
9391 config->is_ramdump_enabled = cfg_get(psoc,
9392 CFG_ENABLE_RAMDUMP_COLLECTION);
9393
9394 config->iface_change_wait_time = cfg_get(psoc,
9395 CFG_INTERFACE_CHANGE_WAIT);
9396
9397 config->multicast_host_fw_msgs = cfg_get(psoc,
9398 CFG_MULTICAST_HOST_FW_MSGS);
9399
9400 config->private_wext_control = cfg_get(psoc, CFG_PRIVATE_WEXT_CONTROL);
Dundi Raviteja8e338282018-09-25 17:16:04 +05309401 config->enablefwprint = cfg_get(psoc, CFG_ENABLE_FW_UART_PRINT);
9402 config->enable_fw_log = cfg_get(psoc, CFG_ENABLE_FW_LOG);
Vignesh Viswanathana0358ff2018-11-27 09:53:07 +05309403 config->operating_channel = cfg_get(psoc, CFG_OPERATING_CHANNEL);
9404 config->num_vdevs = cfg_get(psoc, CFG_NUM_VDEV_ENABLE);
Vignesh Viswanathana0358ff2018-11-27 09:53:07 +05309405 qdf_str_lcopy(config->enable_concurrent_sta,
9406 cfg_get(psoc, CFG_ENABLE_CONCURRENT_STA),
9407 CFG_CONCURRENT_IFACE_MAX_LEN);
9408 qdf_str_lcopy(config->dbs_scan_selection,
9409 cfg_get(psoc, CFG_DBS_SCAN_SELECTION),
9410 CFG_DBS_SCAN_PARAM_LENGTH);
Sourav Mohapatra0dfe5552018-11-16 11:29:54 +05309411 config->inform_bss_rssi_raw = cfg_get(psoc, CFG_INFORM_BSS_RSSI_RAW);
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05309412 config->mac_provision = cfg_get(psoc, CFG_ENABLE_MAC_PROVISION);
9413 config->provisioned_intf_pool =
9414 cfg_get(psoc, CFG_PROVISION_INTERFACE_POOL);
9415 config->derived_intf_pool = cfg_get(psoc, CFG_DERIVED_INTERFACE_POOL);
Sourav Mohapatra58841062018-11-19 16:33:27 +05309416 config->action_oui_enable = cfg_get(psoc, CFG_ENABLE_ACTION_OUI);
Jeff Johnson15a88ac2019-03-11 14:35:25 -07009417 config->advertise_concurrent_operation =
Sandeep Puligilladc6d68a2019-01-04 16:57:12 -08009418 cfg_get(psoc,
9419 CFG_ADVERTISE_CONCURRENT_OPERATION);
Sourav Mohapatra58841062018-11-19 16:33:27 +05309420 qdf_str_lcopy(config->action_oui_str[0],
9421 cfg_get(psoc, CFG_ACTION_OUI_CONNECT_1X1),
9422 ACTION_OUI_MAX_STR_LEN);
9423 qdf_str_lcopy(config->action_oui_str[1],
9424 cfg_get(psoc, CFG_ACTION_OUI_ITO_EXTENSION),
9425 ACTION_OUI_MAX_STR_LEN);
9426 qdf_str_lcopy(config->action_oui_str[2],
9427 cfg_get(psoc, CFG_ACTION_OUI_CCKM_1X1),
9428 ACTION_OUI_MAX_STR_LEN);
9429 qdf_str_lcopy(config->action_oui_str[3],
9430 cfg_get(psoc, CFG_ACTION_OUI_ITO_ALTERNATE),
9431 ACTION_OUI_MAX_STR_LEN);
9432 qdf_str_lcopy(config->action_oui_str[4],
9433 cfg_get(psoc, CFG_ACTION_OUI_SWITCH_TO_11N_MODE),
9434 ACTION_OUI_MAX_STR_LEN);
9435 qdf_str_lcopy(config->action_oui_str[5],
9436 cfg_get(psoc,
9437 CFG_ACTION_OUI_CONNECT_1X1_WITH_1_CHAIN),
9438 ACTION_OUI_MAX_STR_LEN);
Rajeev Kumar Sirasanagandlad7987f12018-12-08 23:24:04 +05309439 qdf_str_lcopy(config->action_oui_str[6],
9440 cfg_get(psoc,
9441 CFG_ACTION_OUI_DISABLE_AGGRESSIVE_TX),
9442 ACTION_OUI_MAX_STR_LEN);
Sourav Mohapatra9e014cf2018-12-11 09:39:33 +05309443 config->enable_rtt_support = cfg_get(psoc, CFG_ENABLE_RTT_SUPPORT);
Sandeep Puligillaefeb4a92019-01-08 00:06:51 -08009444 config->is_unit_test_framework_enabled =
9445 cfg_get(psoc, CFG_ENABLE_UNIT_TEST_FRAMEWORK);
Dundi Raviteja8e338282018-09-25 17:16:04 +05309446
Sourav Mohapatra0dfe5552018-11-16 11:29:54 +05309447 hdd_init_vc_mode_cfg_bitmap(config, psoc);
9448 hdd_init_runtime_pm(config, psoc);
Dundi Raviteja8e338282018-09-25 17:16:04 +05309449 hdd_init_wlan_auto_shutdown(config, psoc);
9450 hdd_init_wlan_logging_params(config, psoc);
9451 hdd_init_packet_log(config, psoc);
Sandeep Puligilla43b6d1a2018-12-03 09:16:13 -08009452 hdd_init_mtrace_log(config, psoc);
gaurank kathpalia566c81b2019-02-20 14:31:45 +05309453 hdd_init_dhcp_server_ip(hdd_ctx);
jitiphil869b9f72018-09-25 17:14:01 +05309454 hdd_dp_cfg_update(psoc, hdd_ctx);
Dundi Raviteja8e338282018-09-25 17:16:04 +05309455}
9456
Dustin Brown623e7e32018-09-05 14:27:50 -07009457struct hdd_context *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009458{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309459 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009460 int ret = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009461 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009462
Dustin Brown491d54b2018-03-14 12:39:11 -07009463 hdd_enter();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009464
Dustin Brown92bd8382018-10-31 15:49:46 -07009465 hdd_ctx = hdd_cfg80211_wiphy_alloc();
9466 if (!hdd_ctx) {
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009467 ret = -ENOMEM;
9468 goto err_out;
9469 }
9470
Dustin Brown8d8ab302019-03-05 16:19:36 -08009471 status = qdf_delayed_work_create(&hdd_ctx->psoc_idle_timeout_work,
9472 hdd_psoc_idle_timeout_callback,
9473 hdd_ctx);
9474 if (QDF_IS_STATUS_ERROR(status)) {
9475 ret = qdf_status_to_os_return(status);
9476 goto wiphy_dealloc;
9477 }
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309478
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009479 hdd_ctx->parent_dev = dev;
Jeff Johnson995fd512019-03-06 08:45:10 -08009480 hdd_ctx->last_scan_reject_vdev_id = WLAN_UMAC_VDEV_ID_MAX;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009481
Anurag Chouhan600c3a02016-03-01 10:33:54 +05309482 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Min Liu74a1a502018-10-10 19:59:07 +08009483 if (!hdd_ctx->config) {
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009484 ret = -ENOMEM;
9485 goto err_free_hdd_context;
9486 }
9487
9488 /* Read and parse the qcom_cfg.ini file */
9489 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309490 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05309491 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009492 WLAN_INI_FILE);
9493 ret = -EINVAL;
9494 goto err_free_config;
9495 }
9496
Dustin Brown84f46ea2018-02-15 11:57:36 -08009497 status = cfg_parse(WLAN_INI_FILE);
9498 if (QDF_IS_STATUS_ERROR(status))
9499 hdd_err("Failed to parse cfg %s; status:%d\n",
9500 WLAN_INI_FILE, status);
9501
Dundi Ravitejafb9357a2018-09-25 12:16:03 +05309502 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx, DEFAULT_PSOC_ID);
9503 if (ret) {
Dundi Raviteja8e338282018-09-25 17:16:04 +05309504 QDF_DEBUG_PANIC("Psoc creation fails!");
Dundi Ravitejafb9357a2018-09-25 12:16:03 +05309505 goto err_free_config;
9506 }
9507
Dundi Raviteja8e338282018-09-25 17:16:04 +05309508 hdd_cfg_params_init(hdd_ctx);
9509
Dustin Brown4bbd5462019-03-22 11:18:13 -07009510 /* apply multiplier config, if not already set via module parameter */
9511 if (qdf_timer_get_multiplier() == 1)
9512 qdf_timer_set_multiplier(cfg_get(hdd_ctx->psoc,
9513 CFG_TIMER_MULTIPLIER));
Dustin Browna9a84522019-02-04 12:25:40 -08009514 hdd_debug("set timer multiplier: %u", qdf_timer_get_multiplier());
Dustin Brown7f939932017-05-18 15:02:17 -07009515
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309516 cds_set_fatal_event(cfg_get(hdd_ctx->psoc,
9517 CFG_ENABLE_FATAL_EVENT_TRIGGER));
Abhishek Singh5ea86532016-04-27 14:10:53 +05309518
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009519 hdd_override_ini_config(hdd_ctx);
9520
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009521 ret = hdd_context_init(hdd_ctx);
9522
9523 if (ret)
Dundi Ravitejafb9357a2018-09-25 12:16:03 +05309524 goto err_hdd_objmgr_destroy;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009525
Nirav Shah6aeecf92019-02-13 14:05:03 +05309526 if (hdd_get_conparam() == QDF_GLOBAL_FTM_MODE ||
9527 hdd_get_conparam() == QDF_GLOBAL_EPPING_MODE)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009528 goto skip_multicast_logging;
9529
9530 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
9531
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07009532 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
9533 if (ret)
9534 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05309535
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009536 ret = hdd_init_netlink_services(hdd_ctx);
9537 if (ret)
9538 goto err_deinit_txrx_histogram;
9539
Nirav Shaheb017be2018-02-15 11:20:58 +05309540 hdd_set_wlan_logging(hdd_ctx);
Nirav Shahed34b212016-04-25 10:59:16 +05309541
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009542skip_multicast_logging:
9543 hdd_set_trace_level_for_each(hdd_ctx);
9544
Rajeev Kumar493a31b2017-09-29 14:01:24 -07009545 cds_set_context(QDF_MODULE_ID_HDD, hdd_ctx);
9546
Dustin Browne74003f2018-03-14 12:51:58 -07009547 hdd_exit();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07009548
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009549 return hdd_ctx;
9550
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009551err_deinit_txrx_histogram:
9552 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
9553
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07009554err_deinit_hdd_context:
9555 hdd_context_deinit(hdd_ctx);
9556
Dundi Ravitejafb9357a2018-09-25 12:16:03 +05309557err_hdd_objmgr_destroy:
9558 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
9559
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009560err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05309561 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009562
9563err_free_hdd_context:
Dustin Brown8d8ab302019-03-05 16:19:36 -08009564 qdf_delayed_work_destroy(&hdd_ctx->psoc_idle_timeout_work);
9565
9566wiphy_dealloc:
Rajeev Kumarfa55a692018-01-09 14:12:41 -08009567 wiphy_free(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009568
9569err_out:
9570 return ERR_PTR(ret);
9571}
9572
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009573/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309574 * hdd_start_station_adapter()- Start the Station Adapter
9575 * @adapter: HDD adapter
9576 *
9577 * This function initializes the adapter for the station mode.
9578 *
9579 * Return: 0 on success or errno on failure.
9580 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009581int hdd_start_station_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309582{
9583 QDF_STATUS status;
Krunal Sonib51eec72017-11-20 21:53:01 -08009584 int ret;
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309585
Dustin Brownfdf17c12018-03-14 12:55:34 -07009586 hdd_enter_dev(adapter->dev);
Krunal Sonib51eec72017-11-20 21:53:01 -08009587 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
9588 hdd_err("session is already opened, %d",
Jeff Johnson5a6fc962019-02-04 14:20:25 -08009589 adapter->vdev_id);
Krunal Sonib51eec72017-11-20 21:53:01 -08009590 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
9591 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309592
Krunal Sonib51eec72017-11-20 21:53:01 -08009593 ret = hdd_vdev_create(adapter, hdd_sme_roam_callback, adapter);
9594 if (ret) {
9595 hdd_err("failed to create vdev: %d", ret);
9596 return ret;
9597 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309598 status = hdd_init_station_mode(adapter);
9599
9600 if (QDF_STATUS_SUCCESS != status) {
9601 hdd_err("Error Initializing station mode: %d", status);
9602 return qdf_status_to_os_return(status);
9603 }
9604
Arun Khandavallifae92942016-08-01 13:31:08 +05309605 hdd_register_tx_flow_control(adapter,
9606 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08009607 hdd_tx_resume_cb,
9608 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05309609
Dustin Browne74003f2018-03-14 12:51:58 -07009610 hdd_exit();
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +05309611
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309612 return 0;
9613}
9614
9615/**
9616 * hdd_start_ap_adapter()- Start AP Adapter
9617 * @adapter: HDD adapter
9618 *
9619 * This function initializes the adapter for the AP mode.
9620 *
9621 * Return: 0 on success errno on failure.
9622 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009623int hdd_start_ap_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309624{
9625 QDF_STATUS status;
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009626 bool is_ssr = false;
Krunal Sonib51eec72017-11-20 21:53:01 -08009627 int ret;
Naveen Rawat1af09392018-01-03 17:28:21 -08009628 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Arif Hussainbd5194c2018-11-27 19:01:15 -08009629 uint32_t fine_time_meas_cap = 0;
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309630
Dustin Brown491d54b2018-03-14 12:39:11 -07009631 hdd_enter();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309632
Krunal Sonib51eec72017-11-20 21:53:01 -08009633 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
9634 hdd_err("session is already opened, %d",
Jeff Johnson5a6fc962019-02-04 14:20:25 -08009635 adapter->vdev_id);
Krunal Sonib51eec72017-11-20 21:53:01 -08009636 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
9637 }
9638 /*
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009639 * In SSR case no need to create new sap context.
9640 * Otherwise create sap context first and then create
9641 * vdev as while creating the vdev, driver needs to
9642 * register SAP callback and that callback uses sap context
Krunal Sonib51eec72017-11-20 21:53:01 -08009643 */
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009644 if (adapter->session.ap.sap_context) {
9645 is_ssr = true;
9646 } else if (!hdd_sap_create_ctx(adapter)) {
Krunal Sonib51eec72017-11-20 21:53:01 -08009647 hdd_err("sap creation failed");
9648 return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
9649 }
9650
9651 ret = hdd_vdev_create(adapter, wlansap_roam_callback,
9652 adapter->session.ap.sap_context);
9653 if (ret) {
9654 hdd_err("failed to create vdev, status:%d", ret);
9655 hdd_sap_destroy_ctx(adapter);
9656 return ret;
9657 }
Naveen Rawat1af09392018-01-03 17:28:21 -08009658
Arif Hussainbd5194c2018-11-27 19:01:15 -08009659 if (adapter->device_mode == QDF_SAP_MODE) {
9660 ucfg_mlme_get_fine_time_meas_cap(hdd_ctx->psoc,
9661 &fine_time_meas_cap);
Jeff Johnson5a6fc962019-02-04 14:20:25 -08009662 sme_cli_set_command(adapter->vdev_id,
Naveen Rawat1af09392018-01-03 17:28:21 -08009663 WMI_VDEV_PARAM_ENABLE_DISABLE_RTT_RESPONDER_ROLE,
Arif Hussainbd5194c2018-11-27 19:01:15 -08009664 (bool)(fine_time_meas_cap & WMI_FW_AP_RTT_RESPR),
Naveen Rawat1af09392018-01-03 17:28:21 -08009665 VDEV_CMD);
Arif Hussainbd5194c2018-11-27 19:01:15 -08009666 }
Naveen Rawat1af09392018-01-03 17:28:21 -08009667
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009668 status = hdd_init_ap_mode(adapter, is_ssr);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309669
9670 if (QDF_STATUS_SUCCESS != status) {
9671 hdd_err("Error Initializing the AP mode: %d", status);
9672 return qdf_status_to_os_return(status);
9673 }
9674
Arun Khandavallifae92942016-08-01 13:31:08 +05309675 hdd_register_tx_flow_control(adapter,
9676 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08009677 hdd_softap_tx_resume_cb,
9678 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05309679
Dustin Browne74003f2018-03-14 12:51:58 -07009680 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309681 return 0;
9682}
9683
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309684#ifdef QCA_LL_TX_FLOW_CONTROL_V2
9685/**
9686 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
9687 * @cds_cfg: CDS Configuration
9688 * @hdd_ctx: Pointer to hdd context
9689 *
9690 * Return: none
9691 */
9692static inline void hdd_txrx_populate_cds_config(struct cds_config_info
9693 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009694 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309695{
9696 cds_cfg->tx_flow_stop_queue_th =
jitiphil47c3d9a2018-11-08 18:30:55 +05309697 cfg_get(hdd_ctx->psoc, CFG_DP_TX_FLOW_STOP_QUEUE_TH);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309698 cds_cfg->tx_flow_start_queue_offset =
jitiphil47c3d9a2018-11-08 18:30:55 +05309699 cfg_get(hdd_ctx->psoc, CFG_DP_TX_FLOW_START_QUEUE_OFFSET);
Mohit Khanna70322002018-05-15 19:21:32 -07009700 /* configuration for DP RX Threads */
9701 cds_cfg->enable_dp_rx_threads = hdd_ctx->enable_dp_rx_threads;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309702}
9703#else
9704static inline void hdd_txrx_populate_cds_config(struct cds_config_info
9705 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009706 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309707{
9708}
9709#endif
9710
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309711/**
9712 * hdd_update_cds_config() - API to update cds configuration parameters
9713 * @hdd_ctx: HDD Context
9714 *
9715 * Return: 0 for Success, errno on failure
9716 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009717static int hdd_update_cds_config(struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309718{
9719 struct cds_config_info *cds_cfg;
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05309720 int value;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05309721 uint8_t band_capability;
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309722 uint8_t ito_repeat_count;
Vignesh Viswanathana851d752018-10-03 19:44:38 +05309723 bool crash_inject;
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309724 bool self_recovery;
9725 bool fw_timeout_crash;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05309726 QDF_STATUS status;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309727
Min Liu74a1a502018-10-10 19:59:07 +08009728 cds_cfg = qdf_mem_malloc(sizeof(*cds_cfg));
9729 if (!cds_cfg)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309730 return -ENOMEM;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309731
Srinivas Girigowda35b00312017-06-27 21:52:03 -07009732 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Bala Venkatesh46e29032018-11-14 18:24:55 +05309733 ucfg_mlme_get_sap_max_modulated_dtim(hdd_ctx->psoc,
9734 &cds_cfg->sta_maxlimod_dtim);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309735
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309736 status = ucfg_mlme_get_crash_inject(hdd_ctx->psoc, &crash_inject);
Vignesh Viswanathana851d752018-10-03 19:44:38 +05309737 if (QDF_IS_STATUS_ERROR(status)) {
9738 hdd_err("Failed to get crash inject ini config");
9739 goto exit;
9740 }
9741
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309742 status = ucfg_mlme_get_self_recovery(hdd_ctx->psoc, &self_recovery);
9743 if (QDF_IS_STATUS_ERROR(status)) {
9744 hdd_err("Failed to get self recovery ini config");
9745 goto exit;
9746 }
9747
9748 status = ucfg_mlme_get_fw_timeout_crash(hdd_ctx->psoc,
9749 &fw_timeout_crash);
9750 if (QDF_IS_STATUS_ERROR(status)) {
9751 hdd_err("Failed to get fw timeout crash ini config");
9752 goto exit;
9753 }
9754
9755 status = ucfg_mlme_get_ito_repeat_count(hdd_ctx->psoc,
9756 &ito_repeat_count);
9757 if (QDF_IS_STATUS_ERROR(status)) {
9758 hdd_err("Failed to get ITO repeat count ini config");
9759 goto exit;
9760 }
9761
Vignesh Viswanathana851d752018-10-03 19:44:38 +05309762 cds_cfg->force_target_assert_enabled = crash_inject;
SaidiReddy Yenugacc733af2016-11-09 17:45:42 +05309763
Dustin Brown05d81302018-09-11 16:49:22 -07009764 ucfg_mlme_get_sap_max_offload_peers(hdd_ctx->psoc, &value);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05309765 cds_cfg->ap_maxoffload_peers = value;
Dustin Brown05d81302018-09-11 16:49:22 -07009766 ucfg_mlme_get_sap_max_offload_reorder_buffs(hdd_ctx->psoc,
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05309767 &value);
9768 cds_cfg->ap_maxoffload_reorderbuffs = value;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309769
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309770 cds_cfg->reorder_offload =
jitiphil47c3d9a2018-11-08 18:30:55 +05309771 cfg_get(hdd_ctx->psoc, CFG_DP_REORDER_OFFLOAD_SUPPORT);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309772
9773 /* IPA micro controller data path offload resource config item */
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05309774 cds_cfg->uc_offload_enabled = ucfg_ipa_uc_is_enabled();
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309775
Jeff Johnsone2ba3cd2017-10-30 20:02:09 -07009776 cds_cfg->enable_rxthread = hdd_ctx->enable_rxthread;
Dustin Brown05d81302018-09-11 16:49:22 -07009777 ucfg_mlme_get_sap_max_peers(hdd_ctx->psoc, &value);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05309778 cds_cfg->max_station = value;
Naveen Rawat64e477e2016-05-20 10:34:56 -07009779 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Orhan K AKYILDIZ30e8cbc2017-08-11 18:00:28 -07009780 cds_cfg->max_msdus_per_rxinorderind =
jitiphil8e15ea62018-11-16 18:05:34 +05309781 cfg_get(hdd_ctx->psoc, CFG_DP_MAX_MSDUS_PER_RXIND);
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309782 cds_cfg->self_recovery_enabled = self_recovery;
9783 cds_cfg->fw_timeout_crash = fw_timeout_crash;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309784
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309785 cds_cfg->ito_repeat_count = ito_repeat_count;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05309786
9787 status = ucfg_mlme_get_band_capability(hdd_ctx->psoc, &band_capability);
9788 if (QDF_IS_STATUS_ERROR(status))
9789 goto exit;
9790
9791 cds_cfg->bandcapability = band_capability;
Rachit Kankane0106e382018-05-16 18:59:28 +05309792 cds_cfg->num_vdevs = hdd_ctx->config->num_vdevs;
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05309793
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309794 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07009795 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309796 cds_init_ini_config(cds_cfg);
9797 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05309798
9799exit:
9800 qdf_mem_free(cds_cfg);
9801 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309802}
9803
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009804/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009805 * hdd_update_user_config() - API to update user configuration
9806 * parameters to obj mgr which are used by multiple components
9807 * @hdd_ctx: HDD Context
9808 *
9809 * Return: 0 for Success, errno on failure
9810 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009811static int hdd_update_user_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009812{
9813 struct wlan_objmgr_psoc_user_config *user_config;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05309814 uint8_t band_capability;
9815 QDF_STATUS status;
Abhinav Kumard4d6eb72018-12-04 20:30:37 +05309816 bool value = false;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05309817
9818 status = ucfg_mlme_get_band_capability(hdd_ctx->psoc, &band_capability);
9819 if (QDF_IS_STATUS_ERROR(status))
9820 return -EIO;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009821
9822 user_config = qdf_mem_malloc(sizeof(*user_config));
Min Liu74a1a502018-10-10 19:59:07 +08009823 if (!user_config)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009824 return -ENOMEM;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009825
9826 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
Abhinav Kumard4d6eb72018-12-04 20:30:37 +05309827 status = ucfg_mlme_is_11d_enabled(hdd_ctx->psoc, &value);
9828 if (!QDF_IS_STATUS_SUCCESS(status))
9829 hdd_err("Invalid 11d_enable flag");
9830 user_config->is_11d_support_enabled = value;
9831
9832 value = false;
9833 status = ucfg_mlme_is_11h_enabled(hdd_ctx->psoc, &value);
9834 if (!QDF_IS_STATUS_SUCCESS(status))
9835 hdd_err("Invalid 11h_enable flag");
9836 user_config->is_11h_support_enabled = value;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05309837 user_config->band_capability = band_capability;
Dustin Brown1dbefe62018-09-11 16:32:03 -07009838 wlan_objmgr_psoc_set_user_config(hdd_ctx->psoc, user_config);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009839
9840 qdf_mem_free(user_config);
9841 return 0;
9842}
9843
9844/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009845 * hdd_init_thermal_info - Initialize thermal level
9846 * @hdd_ctx: HDD context
9847 *
9848 * Initialize thermal level at SME layer and set the thermal level callback
9849 * which would be called when a configured thermal threshold is hit.
9850 *
9851 * Return: 0 on success and errno on failure
9852 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009853static int hdd_init_thermal_info(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009854{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309855 QDF_STATUS status;
Manikandan Mohan9045e2e2018-11-26 16:44:19 -08009856 mac_handle_t mac_handle = hdd_ctx->mac_handle;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009857
Manikandan Mohan9045e2e2018-11-26 16:44:19 -08009858 status = sme_init_thermal_info(mac_handle);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009859
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309860 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05309861 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009862
Jeff Johnson16528362018-06-14 12:34:16 -07009863 sme_add_set_thermal_level_callback(mac_handle,
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009864 hdd_set_thermal_level_cb);
9865
9866 return 0;
9867
9868}
9869
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009870#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
9871/**
9872 * hdd_hold_rtnl_lock - Hold RTNL lock
9873 *
9874 * Hold RTNL lock
9875 *
9876 * Return: True if held and false otherwise
9877 */
9878static inline bool hdd_hold_rtnl_lock(void)
9879{
9880 rtnl_lock();
9881 return true;
9882}
9883
9884/**
9885 * hdd_release_rtnl_lock - Release RTNL lock
9886 *
9887 * Release RTNL lock
9888 *
9889 * Return: None
9890 */
9891static inline void hdd_release_rtnl_lock(void)
9892{
9893 rtnl_unlock();
9894}
9895#else
9896static inline bool hdd_hold_rtnl_lock(void) { return false; }
9897static inline void hdd_release_rtnl_lock(void) { }
9898#endif
9899
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009900#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009901
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309902/* MAX iwpriv command support */
9903#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309904#define PKTLOG_CLEAR_BUFF 4
Venkata Sharath Chandra Manchala27e44902019-01-28 11:29:18 -08009905/* Set Maximum pktlog file size to 64MB */
9906#define MAX_PKTLOG_SIZE 64
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309907
9908/**
9909 * hdd_pktlog_set_buff_size() - set pktlog buffer size
9910 * @hdd_ctx: hdd context
9911 * @set_value2: pktlog buffer size value
9912 *
9913 *
9914 * Return: 0 for success or error.
9915 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009916static int hdd_pktlog_set_buff_size(struct hdd_context *hdd_ctx, int set_value2)
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309917{
9918 struct sir_wifi_start_log start_log = { 0 };
9919 QDF_STATUS status;
9920
9921 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9922 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
9923 start_log.ini_triggered = cds_is_packet_log_enabled();
9924 start_log.user_triggered = 1;
9925 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309926 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309927
Jeff Johnson16528362018-06-14 12:34:16 -07009928 status = sme_wifi_start_logger(hdd_ctx->mac_handle, start_log);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309929 if (!QDF_IS_STATUS_SUCCESS(status)) {
9930 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009931 hdd_exit();
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309932 return -EINVAL;
9933 }
9934
9935 return 0;
9936}
9937
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009938/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309939 * hdd_pktlog_clear_buff() - clear pktlog buffer
9940 * @hdd_ctx: hdd context
9941 *
9942 * Return: 0 for success or error.
9943 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009944static int hdd_pktlog_clear_buff(struct hdd_context *hdd_ctx)
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309945{
9946 struct sir_wifi_start_log start_log;
9947 QDF_STATUS status;
9948
9949 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9950 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
9951 start_log.ini_triggered = cds_is_packet_log_enabled();
9952 start_log.user_triggered = 1;
9953 start_log.size = 0;
9954 start_log.is_pktlog_buff_clear = true;
9955
Jeff Johnson16528362018-06-14 12:34:16 -07009956 status = sme_wifi_start_logger(hdd_ctx->mac_handle, start_log);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309957 if (!QDF_IS_STATUS_SUCCESS(status)) {
9958 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009959 hdd_exit();
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309960 return -EINVAL;
9961 }
9962
9963 return 0;
9964}
9965
9966
9967/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009968 * hdd_process_pktlog_command() - process pktlog command
9969 * @hdd_ctx: hdd context
9970 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309971 * @set_value2: pktlog buffer size value
9972 *
9973 * This function process pktlog command.
9974 * set_value2 only matters when set_value is 3 (set buff size)
9975 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009976 *
9977 * Return: 0 for success or error.
9978 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009979int hdd_process_pktlog_command(struct hdd_context *hdd_ctx, uint32_t set_value,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309980 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009981{
9982 int ret;
9983 bool enable;
9984 uint8_t user_triggered = 0;
9985
9986 ret = wlan_hdd_validate_context(hdd_ctx);
9987 if (0 != ret)
9988 return ret;
9989
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009990 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009991
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309992 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009993 hdd_err("invalid pktlog value %d", set_value);
9994 return -EINVAL;
9995 }
9996
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309997 if (set_value == PKTLOG_SET_BUFF_SIZE) {
9998 if (set_value2 <= 0) {
9999 hdd_err("invalid pktlog size %d", set_value2);
10000 return -EINVAL;
10001 } else if (set_value2 > MAX_PKTLOG_SIZE) {
Venkata Sharath Chandra Manchala27e44902019-01-28 11:29:18 -080010002 hdd_err_rl("Pktlog size is large. max value is %uMB.",
10003 MAX_PKTLOG_SIZE);
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010004 return -EINVAL;
10005 }
10006 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +053010007 } else if (set_value == PKTLOG_CLEAR_BUFF) {
10008 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010009 }
10010
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010011 /*
10012 * set_value = 0 then disable packetlog
10013 * set_value = 1 enable packetlog forcefully
10014 * set_vlaue = 2 then disable packetlog if disabled through ini or
10015 * enable packetlog with AUTO type.
10016 */
10017 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
10018 true : false;
10019
10020 if (1 == set_value) {
10021 enable = true;
10022 user_triggered = 1;
10023 }
10024
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010025 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010026}
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070010027
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -080010028/**
10029 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
10030 * @hdd_ctx: HDD context
10031 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010032 * @user_triggered: triggered through iwpriv
10033 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -080010034 *
10035 * Return: 0 on success; error number otherwise
10036 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010037int hdd_pktlog_enable_disable(struct hdd_context *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010038 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -080010039{
10040 struct sir_wifi_start_log start_log;
10041 QDF_STATUS status;
10042
10043 start_log.ring_id = RING_ID_PER_PACKET_STATS;
10044 start_log.verbose_level =
10045 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010046 start_log.ini_triggered = cds_is_packet_log_enabled();
10047 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010048 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +053010049 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +053010050 /*
10051 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
10052 * commands. Host uses this flag to decide whether to send pktlog
10053 * disable command to fw without sending pktlog enable command
10054 * previously. For eg, If vendor sends pktlog disable command without
10055 * sending pktlog enable command, then host discards the packet
10056 * but for iwpriv command, host will send it to fw.
10057 */
10058 start_log.is_iwpriv_command = 1;
Jeff Johnson16528362018-06-14 12:34:16 -070010059 status = sme_wifi_start_logger(hdd_ctx->mac_handle, start_log);
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -080010060 if (!QDF_IS_STATUS_SUCCESS(status)) {
10061 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -070010062 hdd_exit();
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -080010063 return -EINVAL;
10064 }
10065
Poddar, Siddarth61fbc932017-12-19 14:27:55 +053010066 if (enable == true)
10067 hdd_ctx->is_pktlog_enabled = 1;
10068 else
10069 hdd_ctx->is_pktlog_enabled = 0;
10070
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -080010071 return 0;
10072}
10073#endif /* REMOVE_PKT_LOG */
10074
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010075void hdd_free_mac_address_lists(struct hdd_context *hdd_ctx)
10076{
10077 hdd_debug("Resetting MAC address lists");
hangtian127c9532019-01-12 13:29:07 +080010078 qdf_mem_zero(hdd_ctx->provisioned_mac_addr,
10079 sizeof(hdd_ctx->provisioned_mac_addr));
10080 qdf_mem_zero(hdd_ctx->derived_mac_addr,
10081 sizeof(hdd_ctx->derived_mac_addr));
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010082 hdd_ctx->num_provisioned_addr = 0;
10083 hdd_ctx->num_derived_addr = 0;
10084 hdd_ctx->provisioned_intf_addr_mask = 0;
10085 hdd_ctx->derived_intf_addr_mask = 0;
10086}
10087
Komal Seelam92fff912016-03-24 11:51:41 +053010088/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -080010089 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
10090 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +053010091 * @dev: Device Pointer
10092 * @num: Number of Valid Mac address
10093 *
10094 * Return: Pointer to MAC address buffer
10095 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -080010096static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
10097 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +053010098{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -080010099 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +053010100}
Komal Seelam92fff912016-03-24 11:51:41 +053010101
10102/**
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010103 * hdd_get_platform_wlan_derived_mac_buff() - API to query platform driver
10104 * for derived MAC address
10105 * @dev: Device Pointer
10106 * @num: Number of Valid Mac address
10107 *
10108 * Return: Pointer to MAC address buffer
10109 */
10110static uint8_t *hdd_get_platform_wlan_derived_mac_buff(struct device *dev,
10111 uint32_t *num)
10112{
10113 return pld_get_wlan_derived_mac_address(dev, num);
10114}
10115
10116/**
Komal Seelam92fff912016-03-24 11:51:41 +053010117 * hdd_populate_random_mac_addr() - API to populate random mac addresses
10118 * @hdd_ctx: HDD Context
10119 * @num: Number of random mac addresses needed
10120 *
10121 * Generate random addresses using bit manipulation on the base mac address
10122 *
10123 * Return: None
10124 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010125void hdd_populate_random_mac_addr(struct hdd_context *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +053010126{
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010127 uint32_t idx = hdd_ctx->num_derived_addr;
Komal Seelam92fff912016-03-24 11:51:41 +053010128 uint32_t iter;
Komal Seelam92fff912016-03-24 11:51:41 +053010129 uint8_t *buf = NULL;
10130 uint8_t macaddr_b3, tmp_br3;
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010131 /*
10132 * Consider first provisioned mac address as source address to derive
10133 * remaining addresses
10134 */
Komal Seelam92fff912016-03-24 11:51:41 +053010135
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010136 uint8_t *src = hdd_ctx->provisioned_mac_addr[0].bytes;
10137
10138 for (iter = 0; iter < num; ++iter, ++idx) {
10139 buf = hdd_ctx->derived_mac_addr[idx].bytes;
Komal Seelam92fff912016-03-24 11:51:41 +053010140 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
10141 macaddr_b3 = buf[3];
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010142 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + idx) &
Komal Seelam92fff912016-03-24 11:51:41 +053010143 INTF_MACADDR_MASK;
10144 macaddr_b3 += tmp_br3;
10145 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
10146 buf[0] |= 0x02;
10147 buf[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010148 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010149 hdd_ctx->num_derived_addr++;
Komal Seelam92fff912016-03-24 11:51:41 +053010150 }
10151}
10152
10153/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -080010154 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +053010155 * @hdd_ctx: HDD Context
10156 *
10157 * API to get mac addresses from platform driver and update the driver
10158 * structures and configure FW with the base mac address.
10159 * Return: int
10160 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010161static int hdd_platform_wlan_mac(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +053010162{
10163 uint32_t no_of_mac_addr, iter;
10164 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
10165 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
10166 uint8_t *addr, *buf;
10167 struct device *dev = hdd_ctx->parent_dev;
Komal Seelam92fff912016-03-24 11:51:41 +053010168 tSirMacAddr mac_addr;
10169 QDF_STATUS status;
10170
Yuanyuan Liu7145eb22016-12-01 10:59:29 -080010171 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +053010172
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010173 if (no_of_mac_addr == 0 || !addr) {
10174 hdd_debug("No mac configured from platform driver");
Komal Seelam92fff912016-03-24 11:51:41 +053010175 return -EINVAL;
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010176 }
10177
10178 hdd_free_mac_address_lists(hdd_ctx);
Komal Seelam92fff912016-03-24 11:51:41 +053010179
10180 if (no_of_mac_addr > max_mac_addr)
10181 no_of_mac_addr = max_mac_addr;
10182
10183 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
10184
10185 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010186 buf = hdd_ctx->provisioned_mac_addr[iter].bytes;
Komal Seelam92fff912016-03-24 11:51:41 +053010187 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010188 hdd_info("provisioned MAC Addr [%d]" MAC_ADDRESS_STR, iter,
10189 MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +053010190 }
10191
Komal Seelam92fff912016-03-24 11:51:41 +053010192
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010193 hdd_ctx->num_provisioned_addr = no_of_mac_addr;
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010194
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010195 if (hdd_ctx->config->mac_provision) {
10196 addr = hdd_get_platform_wlan_derived_mac_buff(dev,
10197 &no_of_mac_addr);
10198
10199 if (no_of_mac_addr == 0 || !addr)
10200 hdd_warn("No derived address from platform driver");
10201 else if (no_of_mac_addr >
10202 (max_mac_addr - hdd_ctx->num_provisioned_addr))
10203 no_of_mac_addr = (max_mac_addr -
10204 hdd_ctx->num_provisioned_addr);
10205
10206 for (iter = 0; iter < no_of_mac_addr; ++iter,
10207 addr += mac_addr_size) {
10208 buf = hdd_ctx->derived_mac_addr[iter].bytes;
10209 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
10210 hdd_debug("derived MAC Addr [%d]" MAC_ADDRESS_STR, iter,
10211 MAC_ADDR_ARRAY(buf));
10212 }
10213 hdd_ctx->num_derived_addr = no_of_mac_addr;
10214 }
10215
10216 no_of_mac_addr = hdd_ctx->num_provisioned_addr +
10217 hdd_ctx->num_derived_addr;
Komal Seelam92fff912016-03-24 11:51:41 +053010218 if (no_of_mac_addr < max_mac_addr)
10219 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
10220 no_of_mac_addr);
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010221
10222 status = sme_set_custom_mac_addr(mac_addr);
10223 if (!QDF_IS_STATUS_SUCCESS(status))
10224 return -EAGAIN;
10225
Komal Seelam92fff912016-03-24 11:51:41 +053010226 return 0;
10227}
10228
10229/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010230 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
10231 * @hdd_ctx: HDD Context
10232 *
10233 * Update MAC address to FW. If MAC address passed by FW is invalid, host
10234 * will generate its own MAC and update it to FW.
10235 *
10236 * Return: 0 for success
10237 * Non-zero error code for failure
10238 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010239static int hdd_update_mac_addr_to_fw(struct hdd_context *hdd_ctx)
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010240{
Jeff Johnson374c0852019-03-10 19:02:07 -070010241 tSirMacAddr custom_mac_addr;
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010242 QDF_STATUS status;
10243
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010244 if (hdd_ctx->num_provisioned_addr)
Jeff Johnson374c0852019-03-10 19:02:07 -070010245 qdf_mem_copy(&custom_mac_addr,
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010246 &hdd_ctx->provisioned_mac_addr[0].bytes[0],
10247 sizeof(tSirMacAddr));
10248 else
Jeff Johnson374c0852019-03-10 19:02:07 -070010249 qdf_mem_copy(&custom_mac_addr,
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010250 &hdd_ctx->derived_mac_addr[0].bytes[0],
10251 sizeof(tSirMacAddr));
Jeff Johnson374c0852019-03-10 19:02:07 -070010252 status = sme_set_custom_mac_addr(custom_mac_addr);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010253 if (!QDF_IS_STATUS_SUCCESS(status))
10254 return -EAGAIN;
10255 return 0;
10256}
10257
10258/**
Komal Seelam92fff912016-03-24 11:51:41 +053010259 * hdd_initialize_mac_address() - API to get wlan mac addresses
10260 * @hdd_ctx: HDD Context
10261 *
10262 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
10263 * is provisioned with mac addresses, driver uses it, else it will use
10264 * wlan_mac.bin to update HW MAC addresses.
10265 *
10266 * Return: None
10267 */
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010268static int hdd_initialize_mac_address(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +053010269{
10270 QDF_STATUS status;
10271 int ret;
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010272 bool update_mac_addr_to_fw = true;
Komal Seelam92fff912016-03-24 11:51:41 +053010273
Yuanyuan Liu7145eb22016-12-01 10:59:29 -080010274 ret = hdd_platform_wlan_mac(hdd_ctx);
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010275 if (hdd_ctx->config->mac_provision || !ret) {
Dustin Brown7e761c72018-07-31 13:50:17 -070010276 hdd_info("using MAC address from platform driver");
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010277 return ret;
Dustin Brown7e761c72018-07-31 13:50:17 -070010278 }
Komal Seelam92fff912016-03-24 11:51:41 +053010279
10280 status = hdd_update_mac_config(hdd_ctx);
Dustin Brown7e761c72018-07-31 13:50:17 -070010281 if (QDF_IS_STATUS_SUCCESS(status)) {
10282 hdd_info("using MAC address from wlan_mac.bin");
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010283 return 0;
Dustin Brown7e761c72018-07-31 13:50:17 -070010284 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010285
Dustin Brown7e761c72018-07-31 13:50:17 -070010286 hdd_info("using default MAC address");
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010287
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010288 /* Use fw provided MAC */
10289 if (!qdf_is_macaddr_zero(&hdd_ctx->hw_macaddr)) {
10290 hdd_update_macaddr(hdd_ctx, hdd_ctx->hw_macaddr, false);
10291 update_mac_addr_to_fw = false;
10292 return 0;
10293 } else if (hdd_generate_macaddr_auto(hdd_ctx) != 0) {
10294 struct qdf_mac_addr mac_addr;
10295
10296 hdd_err("MAC failure from device serial no.");
Jeff Johnson51a80522018-12-11 20:19:44 -080010297 qdf_get_random_bytes(&mac_addr, sizeof(mac_addr));
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010298 /*
10299 * Reset multicast bit (bit-0) and set
10300 * locally-administered bit
10301 */
10302 mac_addr.bytes[0] = 0x2;
10303 hdd_update_macaddr(hdd_ctx, mac_addr, true);
10304 }
10305
10306 if (update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010307 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Dustin Brown7e761c72018-07-31 13:50:17 -070010308 if (ret)
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -080010309 hdd_err("MAC address out-of-sync, ret:%d", ret);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010310 }
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010311 return ret;
Komal Seelam92fff912016-03-24 11:51:41 +053010312}
10313
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010314static int hdd_set_smart_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010315{
10316 int vdev_id = 0;
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +053010317 QDF_STATUS status;
10318 bool smart_chainmask_enabled;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010319 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010320 int vpdev = PDEV_CMD;
10321 int ret;
10322
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +053010323 status = ucfg_get_smart_chainmask_enabled(hdd_ctx->psoc,
10324 &smart_chainmask_enabled);
10325 if (QDF_IS_STATUS_ERROR(status))
10326 return -EINVAL;
10327
10328 ret = sme_cli_set_command(vdev_id, param_id,
10329 (int)smart_chainmask_enabled, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010330 if (ret)
10331 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
10332
10333 return ret;
10334}
10335
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010336static int hdd_set_alternative_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010337{
10338 int vdev_id = 0;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010339 QDF_STATUS status;
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010340 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010341 bool alternative_chainmask_enabled;
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010342 int vpdev = PDEV_CMD;
10343 int ret;
10344
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010345 status = ucfg_get_alternative_chainmask_enabled(
10346 hdd_ctx->psoc,
10347 &alternative_chainmask_enabled);
10348 if (QDF_IS_STATUS_ERROR(status))
10349 return -EINVAL;
10350
10351 ret = sme_cli_set_command(vdev_id, param_id,
10352 (int)alternative_chainmask_enabled, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010353 if (ret)
10354 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
10355 ret);
10356
10357 return ret;
10358}
10359
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010360static int hdd_set_ani_enabled(struct hdd_context *hdd_ctx)
Jeff Johnson12a744b2017-04-04 08:19:37 -070010361{
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010362 QDF_STATUS status;
Jeff Johnson12a744b2017-04-04 08:19:37 -070010363 int vdev_id = 0;
10364 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010365 bool value;
Jeff Johnson12a744b2017-04-04 08:19:37 -070010366 int vpdev = PDEV_CMD;
10367 int ret;
10368
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010369 status = ucfg_fwol_get_ani_enabled(hdd_ctx->psoc, &value);
10370 if (QDF_IS_STATUS_ERROR(status))
10371 return -EINVAL;
10372
10373 ret = sme_cli_set_command(vdev_id, param_id, (int)value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -070010374 if (ret)
10375 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
10376
10377 return ret;
10378}
10379
Jeff Johnson89c66ff2016-04-22 15:21:37 -070010380/**
Prashanth Bhatta07998752016-04-28 12:35:33 -070010381 * hdd_pre_enable_configure() - Configurations prior to cds_enable
10382 * @hdd_ctx: HDD context
10383 *
10384 * Pre configurations to be done at lower layer before calling cds enable.
10385 *
10386 * Return: 0 on success and errno on failure.
10387 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010388static int hdd_pre_enable_configure(struct hdd_context *hdd_ctx)
Prashanth Bhatta07998752016-04-28 12:35:33 -070010389{
10390 int ret;
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +053010391 uint8_t val = 0;
Prashanth Bhatta07998752016-04-28 12:35:33 -070010392 QDF_STATUS status;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010393 uint32_t arp_ac_category;
Leo Changfdb45c32016-10-28 11:09:23 -070010394 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010395
Leo Changfdb45c32016-10-28 11:09:23 -070010396 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Ajit Pal Singh5d269612018-04-19 16:29:12 +053010397 /* Register HL netdev flow control callback */
10398 cdp_hl_fc_register(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010399
10400 /*
10401 * Note that the cds_pre_enable() sequence triggers the cfg download.
10402 * The cfg download must occur before we update the SME config
10403 * since the SME config operation must access the cfg database
10404 */
10405 status = hdd_set_sme_config(hdd_ctx);
10406
10407 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010408 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010409 ret = qdf_status_to_os_return(status);
10410 goto out;
10411 }
10412
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -070010413 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
10414 if (QDF_STATUS_SUCCESS != status) {
10415 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
10416 ret = qdf_status_to_os_return(status);
10417 goto out;
10418 }
10419
Dustin Brown1dbefe62018-09-11 16:32:03 -070010420 status = ucfg_mlme_get_tx_chainmask_1ss(hdd_ctx->psoc, &val);
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +053010421 if (QDF_STATUS_SUCCESS != status) {
10422 hdd_err("Get tx_chainmask_1ss from mlme failed");
10423 ret = qdf_status_to_os_return(status);
10424 goto out;
10425 }
10426 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS, val,
Prashanth Bhatta07998752016-04-28 12:35:33 -070010427 PDEV_CMD);
10428 if (0 != ret) {
10429 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
10430 goto out;
10431 }
10432
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010433 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
10434 if (ret)
10435 goto out;
10436
10437 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
10438 if (ret)
10439 goto out;
10440
Jeff Johnson12a744b2017-04-04 08:19:37 -070010441 ret = hdd_set_ani_enabled(hdd_ctx);
10442 if (ret)
10443 goto out;
10444
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010445 status = ucfg_get_arp_ac_category(hdd_ctx->psoc, &arp_ac_category);
10446
10447 if (QDF_IS_STATUS_ERROR(status))
10448 return -EINVAL;
10449
Naveen Rawat247a8682017-06-05 15:00:31 -070010450 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010451 arp_ac_category,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -080010452 PDEV_CMD);
10453 if (0 != ret) {
10454 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010455 arp_ac_category, ret);
Srinivas Girigowda70e169a2017-03-07 23:55:57 -080010456 goto out;
10457 }
10458
Prashanth Bhatta07998752016-04-28 12:35:33 -070010459 status = hdd_set_sme_chan_list(hdd_ctx);
10460 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010461 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010462 ret = qdf_status_to_os_return(status);
10463 goto out;
10464 }
10465
10466 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -070010467 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010468 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -070010469 ret = -EINVAL;
10470 goto out;
10471 }
10472
Prashanth Bhatta07998752016-04-28 12:35:33 -070010473
10474 hdd_init_channel_avoidance(hdd_ctx);
10475
10476out:
10477 return ret;
10478}
10479
Rachit Kankane026e77a2018-07-31 16:21:09 +053010480#ifdef FEATURE_P2P_LISTEN_OFFLOAD
Prashanth Bhatta07998752016-04-28 12:35:33 -070010481/**
Peng Xu8fdaa492016-06-22 10:20:47 -070010482 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
Jeff Johnsonf7e36d62018-07-04 21:14:02 -070010483 * @context: context registered with sme_register_p2p_lo_event(). HDD
10484 * always registers a hdd context pointer
10485 * @evt:event structure pointer
Peng Xu8fdaa492016-06-22 10:20:47 -070010486 *
10487 * This is the p2p listen offload stop event handler, it sends vendor
10488 * event back to supplicant to notify the stop reason.
10489 *
10490 * Return: None
10491 */
Jeff Johnsonf7e36d62018-07-04 21:14:02 -070010492static void wlan_hdd_p2p_lo_event_callback(void *context,
10493 struct sir_p2p_lo_event *evt)
Peng Xu8fdaa492016-06-22 10:20:47 -070010494{
Jeff Johnsonf7e36d62018-07-04 21:14:02 -070010495 struct hdd_context *hdd_ctx = context;
Peng Xu8fdaa492016-06-22 10:20:47 -070010496 struct sk_buff *vendor_event;
Jeff Johnson9d295242017-08-29 14:39:48 -070010497 struct hdd_adapter *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -070010498
Dustin Brown491d54b2018-03-14 12:39:11 -070010499 hdd_enter();
Peng Xu8fdaa492016-06-22 10:20:47 -070010500
Jeff Johnsond36fa332019-03-18 13:42:25 -070010501 if (!hdd_ctx) {
Peng Xu8fdaa492016-06-22 10:20:47 -070010502 hdd_err("Invalid HDD context pointer");
10503 return;
10504 }
10505
Peng Xu5c682812017-08-06 07:39:13 -070010506 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
10507 if (!adapter) {
10508 hdd_err("Cannot find adapter by vdev_id = %d",
10509 evt->vdev_id);
10510 return;
10511 }
10512
Peng Xu8fdaa492016-06-22 10:20:47 -070010513 vendor_event =
10514 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -070010515 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -070010516 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
10517 GFP_KERNEL);
10518
10519 if (!vendor_event) {
10520 hdd_err("cfg80211_vendor_event_alloc failed");
10521 return;
10522 }
10523
10524 if (nla_put_u32(vendor_event,
10525 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
10526 evt->reason_code)) {
10527 hdd_err("nla put failed");
10528 kfree_skb(vendor_event);
10529 return;
10530 }
10531
10532 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -070010533 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
10534 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -070010535}
Rachit Kankane026e77a2018-07-31 16:21:09 +053010536#else
10537static void wlan_hdd_p2p_lo_event_callback(void *context,
10538 struct sir_p2p_lo_event *evt)
10539{
10540}
10541#endif
Peng Xu8fdaa492016-06-22 10:20:47 -070010542
Rachit Kankanef6834c42018-08-02 18:47:50 +053010543#ifdef FEATURE_WLAN_DYNAMIC_CVM
10544static inline int hdd_set_vc_mode_config(struct hdd_context *hdd_ctx)
10545{
10546 return sme_set_vc_mode_config(hdd_ctx->config->vc_mode_cfg_bitmap);
10547}
10548#else
10549static inline int hdd_set_vc_mode_config(struct hdd_context *hdd_ctx)
10550{
10551 return QDF_STATUS_SUCCESS;
10552}
10553#endif
10554
Peng Xu8fdaa492016-06-22 10:20:47 -070010555/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010556 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
10557 * @hdd_ctx: HDD context
10558 *
10559 * This function sends the adaptive dwell time config configuration to the
10560 * firmware via WMA
10561 *
10562 * Return: 0 - success, < 0 - failure
10563 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010564static int hdd_adaptive_dwelltime_init(struct hdd_context *hdd_ctx)
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010565{
10566 QDF_STATUS status;
10567 struct adaptive_dwelltime_params dwelltime_params;
10568
Harprit Chhabadad59ae762019-01-08 16:40:43 -080010569 status = ucfg_fwol_get_all_adaptive_dwelltime_params(hdd_ctx->psoc,
10570 &dwelltime_params);
10571 status = ucfg_fwol_set_adaptive_dwelltime_config(&dwelltime_params);
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010572
10573 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
10574 if (!QDF_IS_STATUS_SUCCESS(status)) {
10575 hdd_err("Failed to send Adaptive Dwelltime configuration!");
10576 return -EAGAIN;
10577 }
10578 return 0;
10579}
10580
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010581int hdd_dbs_scan_selection_init(struct hdd_context *hdd_ctx)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010582{
10583 QDF_STATUS status;
10584 struct wmi_dbs_scan_sel_params dbs_scan_params;
10585 uint32_t i = 0;
10586 uint8_t count = 0, numentries = 0;
Krunal Sonidf29bc42018-11-15 13:26:29 -080010587 uint8_t dual_mac_feature;
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010588 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
10589 * CDS_DBS_SCAN_CLIENTS_MAX];
10590
Krunal Sonidf29bc42018-11-15 13:26:29 -080010591 status = ucfg_policy_mgr_get_dual_mac_feature(hdd_ctx->psoc,
10592 &dual_mac_feature);
10593
10594 if (status != QDF_STATUS_SUCCESS) {
10595 hdd_err("can't get dual mac feature flag");
10596 return -EINVAL;
10597 }
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010598 /* check if DBS is enabled or supported */
Krunal Sonidf29bc42018-11-15 13:26:29 -080010599 if ((dual_mac_feature == DISABLE_DBS_CXN_AND_SCAN) ||
10600 (dual_mac_feature == ENABLE_DBS_CXN_AND_DISABLE_DBS_SCAN))
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010601 return -EINVAL;
10602
10603 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
10604 dbs_scan_config, &numentries,
10605 (CDS_DBS_SCAN_PARAM_PER_CLIENT
10606 * CDS_DBS_SCAN_CLIENTS_MAX));
10607
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010608 if (!numentries) {
Dustin Brown6a8d39b2018-08-14 15:27:26 -070010609 hdd_debug("Do not send scan_selection_config");
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010610 return 0;
10611 }
10612
10613 /* hdd_set_fw_log_params */
10614 dbs_scan_params.num_clients = 0;
10615 while (count < (numentries - 2)) {
10616 dbs_scan_params.module_id[i] = dbs_scan_config[count];
10617 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
10618 dbs_scan_params.num_non_dbs_scans[i] =
10619 dbs_scan_config[count + 2];
10620 dbs_scan_params.num_clients++;
10621 hdd_debug("module:%d NDS:%d NNDS:%d",
10622 dbs_scan_params.module_id[i],
10623 dbs_scan_params.num_dbs_scans[i],
10624 dbs_scan_params.num_non_dbs_scans[i]);
10625 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
10626 i++;
10627 }
10628
10629 dbs_scan_params.pdev_id = 0;
10630
10631 hdd_debug("clients:%d pdev:%d",
10632 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
10633
Jeff Johnson16528362018-06-14 12:34:16 -070010634 status = sme_set_dbs_scan_selection_config(hdd_ctx->mac_handle,
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010635 &dbs_scan_params);
10636 hdd_debug("Sending DBS Scan Selection Configuration to fw");
10637 if (!QDF_IS_STATUS_SUCCESS(status)) {
10638 hdd_err("Failed to send DBS Scan selection configuration!");
10639 return -EAGAIN;
10640 }
10641 return 0;
10642}
10643
Arun Khandavallid4349a92016-07-25 11:10:43 +053010644#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
10645/**
10646 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
10647 * @hdd_ctx: HDD context
10648 *
10649 * Set auto shutdown callback to get indications from firmware to indicate
10650 * userspace to shutdown WLAN after a configured amount of inactivity.
10651 *
10652 * Return: 0 on success and errno on failure.
10653 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010654static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010655{
10656 QDF_STATUS status;
10657
Dundi Raviteja8e338282018-09-25 17:16:04 +053010658 if (!hdd_ctx->config->wlan_auto_shutdown)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010659 return 0;
10660
Jeff Johnson16528362018-06-14 12:34:16 -070010661 status = sme_set_auto_shutdown_cb(hdd_ctx->mac_handle,
Arun Khandavallid4349a92016-07-25 11:10:43 +053010662 wlan_hdd_auto_shutdown_cb);
10663 if (status != QDF_STATUS_SUCCESS)
10664 hdd_err("Auto shutdown feature could not be enabled: %d",
10665 status);
10666
10667 return qdf_status_to_os_return(status);
10668}
10669#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010670static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010671{
10672 return 0;
10673}
10674#endif
10675
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010676#ifdef MWS_COEX
10677/**
10678 * hdd_set_mws_coex() - Set MWS coex configurations
10679 * @hdd_ctx: HDD context
10680 *
10681 * This function sends MWS-COEX 4G quick FTDM and
10682 * MWS-COEX 5G-NR power limit to FW
10683 *
10684 * Return: 0 on success and errno on failure.
10685 */
10686static int hdd_init_mws_coex(struct hdd_context *hdd_ctx)
10687{
10688 int ret = 0;
lifengdb340e72018-11-20 00:50:20 +080010689 uint32_t mws_coex_4g_quick_tdm = 0, mws_coex_5g_nr_pwr_limit = 0;
10690
10691 ucfg_mlme_get_mws_coex_4g_quick_tdm(hdd_ctx->psoc,
10692 &mws_coex_4g_quick_tdm);
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010693
10694 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_MWSCOEX_4G_ALLOW_QUICK_FTDM,
lifengdb340e72018-11-20 00:50:20 +080010695 mws_coex_4g_quick_tdm,
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010696 PDEV_CMD);
10697 if (ret) {
10698 hdd_warn("Unable to send MWS-COEX 4G quick FTDM policy");
10699 return ret;
10700 }
10701
lifengdb340e72018-11-20 00:50:20 +080010702 ucfg_mlme_get_mws_coex_5g_nr_pwr_limit(hdd_ctx->psoc,
10703 &mws_coex_5g_nr_pwr_limit);
10704
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010705 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_MWSCOEX_SET_5GNR_PWR_LIMIT,
lifengdb340e72018-11-20 00:50:20 +080010706 mws_coex_5g_nr_pwr_limit,
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010707 PDEV_CMD);
10708 if (ret) {
10709 hdd_warn("Unable to send MWS-COEX 4G quick FTDM policy");
10710 return ret;
10711 }
lifengdb340e72018-11-20 00:50:20 +080010712
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010713 return ret;
10714}
10715#else
10716static int hdd_init_mws_coex(struct hdd_context *hdd_ctx)
10717{
10718 return 0;
10719}
10720#endif
10721
Arun Khandavallid4349a92016-07-25 11:10:43 +053010722/**
10723 * hdd_features_init() - Init features
10724 * @hdd_ctx: HDD context
Arun Khandavallid4349a92016-07-25 11:10:43 +053010725 *
10726 * Initialize features and their feature context after WLAN firmware is up.
10727 *
10728 * Return: 0 on success and errno on failure.
10729 */
Dustin Browne7e71d32018-05-11 16:00:08 -070010730static int hdd_features_init(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010731{
Jeff Johnson19ce8d02019-02-08 22:56:23 -080010732 struct tx_power_limit hddtxlimit;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010733 QDF_STATUS status;
10734 int ret;
Jeff Johnson16528362018-06-14 12:34:16 -070010735 mac_handle_t mac_handle;
Kiran Kumar Lokere1a43bcf2018-05-15 15:51:58 -070010736 struct hdd_config *cfg;
Pragaspathi Thilagaraj784c4922018-12-02 22:47:29 +053010737 bool b_cts2self, is_imps_enabled;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010738
Dustin Brown491d54b2018-03-14 12:39:11 -070010739 hdd_enter();
Arun Khandavallid4349a92016-07-25 11:10:43 +053010740
Dustin Brownad698ae2018-09-05 17:19:30 -070010741 ret = hdd_update_country_code(hdd_ctx);
10742 if (ret) {
10743 hdd_err("Failed to update country code; errno:%d", ret);
10744 return -EINVAL;
10745 }
10746
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010747 ret = hdd_init_mws_coex(hdd_ctx);
10748 if (ret)
10749 hdd_warn("Error initializing mws-coex");
10750
Kiran Kumar Lokere1a43bcf2018-05-15 15:51:58 -070010751 cfg = hdd_ctx->config;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010752 /* FW capabilities received, Set the Dot11 mode */
Jeff Johnson16528362018-06-14 12:34:16 -070010753 mac_handle = hdd_ctx->mac_handle;
10754 sme_setdef_dot11mode(mac_handle);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010755
Pragaspathi Thilagaraj784c4922018-12-02 22:47:29 +053010756 ucfg_mlme_is_imps_enabled(hdd_ctx->psoc, &is_imps_enabled);
10757 hdd_set_idle_ps_config(hdd_ctx, is_imps_enabled);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010758
Poddar, Siddarth37033032017-10-11 15:47:40 +053010759 /* Send Enable/Disable data stall detection cmd to FW */
10760 sme_cli_set_command(0, WMI_PDEV_PARAM_DATA_STALL_DETECT_ENABLE,
jitiphil377bcc12018-10-05 19:46:08 +053010761 cdp_cfg_get(cds_get_context(QDF_MODULE_ID_SOC),
10762 cfg_dp_enable_data_stall), PDEV_CMD);
Poddar, Siddarth37033032017-10-11 15:47:40 +053010763
Dustin Brown1dbefe62018-09-11 16:32:03 -070010764 ucfg_mlme_get_go_cts2self_for_sta(hdd_ctx->psoc, &b_cts2self);
Wu Gao93816212018-08-31 16:49:54 +080010765 if (b_cts2self)
Jeff Johnson16528362018-06-14 12:34:16 -070010766 sme_set_cts2self_for_p2p_go(mac_handle);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +053010767
Rachit Kankanef6834c42018-08-02 18:47:50 +053010768 if (hdd_set_vc_mode_config(hdd_ctx))
Nachiket Kukade8983cf62017-10-12 18:14:48 +053010769 hdd_warn("Error in setting Voltage Corner mode config to FW");
10770
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -070010771 if (hdd_rx_ol_init(hdd_ctx))
10772 hdd_err("Unable to initialize Rx LRO/GRO in fw");
Arun Khandavallid4349a92016-07-25 11:10:43 +053010773
10774 if (hdd_adaptive_dwelltime_init(hdd_ctx))
10775 hdd_err("Unable to send adaptive dwelltime setting to FW");
10776
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010777 if (hdd_dbs_scan_selection_init(hdd_ctx))
10778 hdd_err("Unable to send DBS scan selection setting to FW");
10779
Arun Khandavallid4349a92016-07-25 11:10:43 +053010780 ret = hdd_init_thermal_info(hdd_ctx);
10781 if (ret) {
10782 hdd_err("Error while initializing thermal information");
Dustin Browne7e71d32018-05-11 16:00:08 -070010783 return ret;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010784 }
10785
Poddar, Siddarth61fbc932017-12-19 14:27:55 +053010786 /**
10787 * In case of SSR/PDR, if pktlog was enabled manually before
Rakshith Suresh Patkar6d955262019-03-13 16:51:50 +053010788 * SSR/PDR, then enable it again automatically after Wlan
Poddar, Siddarth61fbc932017-12-19 14:27:55 +053010789 * device up.
Rakshith Suresh Patkar6d955262019-03-13 16:51:50 +053010790 * During SSR/PDR, pktlog will be disabled as part of
10791 * hdd_features_deinit if pktlog is enabled in ini.
10792 * Re-enable pktlog in SSR case, if pktlog is enabled in ini.
Poddar, Siddarth61fbc932017-12-19 14:27:55 +053010793 */
Rakshith Suresh Patkar6d955262019-03-13 16:51:50 +053010794 if (cds_is_packet_log_enabled() ||
10795 (cds_is_driver_recovering() && hdd_ctx->is_pktlog_enabled))
Alok Kumar5a75b9d2018-08-31 10:55:43 +053010796 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
Poddar, Siddarth66a46592017-02-22 11:44:44 +053010797
gaurank kathpalia3d2e3852018-10-03 22:03:23 +053010798 hddtxlimit.txPower2g = ucfg_get_tx_power(hdd_ctx->psoc, BAND_2G);
10799 hddtxlimit.txPower5g = ucfg_get_tx_power(hdd_ctx->psoc, BAND_5G);
Jeff Johnson16528362018-06-14 12:34:16 -070010800 status = sme_txpower_limit(mac_handle, &hddtxlimit);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010801 if (!QDF_IS_STATUS_SUCCESS(status))
10802 hdd_err("Error setting txlimit in sme: %d", status);
10803
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010804 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010805
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053010806 status = sme_enable_disable_chanavoidind_event(mac_handle, 0);
10807 if (QDF_IS_STATUS_ERROR(status) && (status != QDF_STATUS_E_NOSUPPORT)) {
10808 hdd_err("Failed to disable Chan Avoidance Indication");
Sourav Mohapatra674925f2018-04-16 11:16:58 +053010809 return -EINVAL;
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +053010810 }
Arun Khandavallid4349a92016-07-25 11:10:43 +053010811
10812 /* register P2P Listen Offload event callback */
10813 if (wma_is_p2p_lo_capable())
Jeff Johnson16528362018-06-14 12:34:16 -070010814 sme_register_p2p_lo_event(mac_handle, hdd_ctx,
10815 wlan_hdd_p2p_lo_event_callback);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010816
10817 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
10818
10819 if (ret)
Sourav Mohapatra674925f2018-04-16 11:16:58 +053010820 return -EINVAL;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010821
Dustin Brown11638b72018-01-25 17:37:25 +053010822 wlan_hdd_init_chan_info(hdd_ctx);
Varun Reddy Yeturu3c9f89c2018-04-18 19:10:34 -070010823 wlan_hdd_twt_init(hdd_ctx);
Dustin Brown11638b72018-01-25 17:37:25 +053010824
Dustin Browne74003f2018-03-14 12:51:58 -070010825 hdd_exit();
Arun Khandavallid4349a92016-07-25 11:10:43 +053010826 return 0;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010827}
10828
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010829/**
10830 * hdd_features_deinit() - Deinit features
10831 * @hdd_ctx: HDD context
10832 *
10833 * De-Initialize features and their feature context.
10834 *
10835 * Return: none.
10836 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010837static void hdd_features_deinit(struct hdd_context *hdd_ctx)
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010838{
Varun Reddy Yeturu3c9f89c2018-04-18 19:10:34 -070010839 wlan_hdd_twt_deinit(hdd_ctx);
Dustin Brown11638b72018-01-25 17:37:25 +053010840 wlan_hdd_deinit_chan_info(hdd_ctx);
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010841 wlan_hdd_tsf_deinit(hdd_ctx);
jitiphil4e3bef42018-11-14 14:31:13 +053010842 if (cds_is_packet_log_enabled())
10843 hdd_pktlog_enable_disable(hdd_ctx, false, 0, 0);
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010844}
10845
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010846/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -070010847 * hdd_register_bcn_cb() - register scan beacon callback
10848 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010849 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -070010850 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010851 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010852static inline QDF_STATUS hdd_register_bcn_cb(struct hdd_context *hdd_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010853{
10854 QDF_STATUS status;
10855
Dustin Brown1dbefe62018-09-11 16:32:03 -070010856 status = ucfg_scan_register_bcn_cb(hdd_ctx->psoc,
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010857 wlan_cfg80211_inform_bss_frame,
10858 SCAN_CB_TYPE_INFORM_BCN);
10859 if (!QDF_IS_STATUS_SUCCESS(status)) {
Abhishek Singh5ffe9de2019-03-05 15:42:43 +053010860 hdd_err("failed to register SCAN_CB_TYPE_INFORM_BCN with status code %08d [x%08x]",
10861 status, status);
10862 return status;
10863 }
10864
10865 status = ucfg_scan_register_bcn_cb(hdd_ctx->psoc,
10866 wlan_cfg80211_unlink_bss_list,
10867 SCAN_CB_TYPE_UNLINK_BSS);
10868 if (!QDF_IS_STATUS_SUCCESS(status)) {
10869 hdd_err("failed to refister SCAN_CB_TYPE_FLUSH_BSS with status code %08d [x%08x]",
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010870 status, status);
10871 return status;
10872 }
10873
10874 return QDF_STATUS_SUCCESS;
10875}
Arun Khandavallid4349a92016-07-25 11:10:43 +053010876
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010877/**
Manjunathappa Prakasha0cbc922018-05-08 19:48:34 -070010878 * hdd_v2_flow_pool_map() - Flow pool create callback when vdev is active
10879 * @vdev_id: vdev_id, corresponds to flow_pool
10880 *
10881 * Return: none.
10882 */
10883static void hdd_v2_flow_pool_map(int vdev_id)
10884{
10885 QDF_STATUS status;
10886
10887 status = cdp_flow_pool_map(cds_get_context(QDF_MODULE_ID_SOC),
10888 cds_get_context(QDF_MODULE_ID_TXRX),
10889 vdev_id);
10890 /*
10891 * For Adrastea flow control v2 is based on FW MAP events,
10892 * so this above callback is not implemented.
10893 * Hence this is not actual failure. Dont return failure
10894 */
10895 if ((status != QDF_STATUS_SUCCESS) &&
10896 (status != QDF_STATUS_E_INVAL)) {
10897 hdd_err("vdev_id: %d, failed to create flow pool status %d",
10898 vdev_id, status);
10899 }
10900}
10901
10902/**
10903 * hdd_v2_flow_pool_unmap() - Flow pool create callback when vdev is not active
10904 * @vdev_id: vdev_id, corresponds to flow_pool
10905 *
10906 * Return: none.
10907 */
10908static void hdd_v2_flow_pool_unmap(int vdev_id)
10909{
10910 cdp_flow_pool_unmap(cds_get_context(QDF_MODULE_ID_SOC),
10911 cds_get_context(QDF_MODULE_ID_TXRX), vdev_id);
10912}
10913
10914/**
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053010915 * hdd_action_oui_config() - Configure action_oui strings
10916 * @hdd_ctx: pointer to hdd context
10917 *
10918 * This is a HDD wrapper function which invokes ucfg api
10919 * of action_oui component to parse action oui strings.
10920 *
10921 * Return: None
10922 */
10923static void hdd_action_oui_config(struct hdd_context *hdd_ctx)
10924{
10925 QDF_STATUS status;
10926 uint32_t id;
10927 uint8_t *str;
10928
10929 if (!hdd_ctx->config->action_oui_enable)
10930 return;
10931
10932 for (id = 0; id < ACTION_OUI_MAXIMUM_ID; id++) {
10933 str = hdd_ctx->config->action_oui_str[id];
10934 if (!qdf_str_len(str))
10935 continue;
10936
Dustin Brown1dbefe62018-09-11 16:32:03 -070010937 status = ucfg_action_oui_parse(hdd_ctx->psoc, str, id);
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053010938 if (!QDF_IS_STATUS_SUCCESS(status))
10939 hdd_err("Failed to parse action_oui str: %u", id);
10940 }
10941}
10942
10943/**
10944 * hdd_action_oui_send() - Send action_oui extensions to firmware
10945 * @hdd_ctx: pointer to hdd context
10946 *
10947 * This is a HDD wrapper function which invokes ucfg api
10948 * of action_oui component to send action oui extensions to firmware.
10949 *
10950 * Return: None
10951 */
10952static void hdd_action_oui_send(struct hdd_context *hdd_ctx)
10953{
10954 QDF_STATUS status;
10955
10956 if (!hdd_ctx->config->action_oui_enable)
10957 return;
10958
Dustin Brown1dbefe62018-09-11 16:32:03 -070010959 status = ucfg_action_oui_send(hdd_ctx->psoc);
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053010960 if (!QDF_IS_STATUS_SUCCESS(status))
10961 hdd_err("Failed to send one or all action_ouis");
10962}
10963
Jeff Johnson0187c622019-01-04 06:39:44 -080010964static void hdd_hastings_bt_war_initialize(struct hdd_context *hdd_ctx)
10965{
10966 if (hdd_ctx->config->iface_change_wait_time)
10967 hdd_hastings_bt_war_disable_fw(hdd_ctx);
10968 else
10969 hdd_hastings_bt_war_enable_fw(hdd_ctx);
10970}
10971
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053010972/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010973 * hdd_configure_cds() - Configure cds modules
10974 * @hdd_ctx: HDD context
10975 * @adapter: Primary adapter context
10976 *
10977 * Enable Cds modules after WLAN firmware is up.
10978 *
10979 * Return: 0 on success and errno on failure.
10980 */
Dustin Browne7e71d32018-05-11 16:00:08 -070010981int hdd_configure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +053010982{
10983 int ret;
10984 QDF_STATUS status;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010985 int set_value;
Jeff Johnson16528362018-06-14 12:34:16 -070010986 mac_handle_t mac_handle;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010987 bool enable_rts_sifsbursting;
10988 uint8_t enable_phy_reg_retention;
Krunal Sonidf29bc42018-11-15 13:26:29 -080010989 uint8_t max_mpdus_inampdu, is_force_1x1 = 0;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010990 uint32_t num_abg_tx_chains = 0;
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +053010991 uint16_t num_11b_tx_chains = 0;
10992 uint16_t num_11ag_tx_chains = 0;
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -070010993 struct policy_mgr_dp_cbacks dp_cbs = {0};
Bala Venkatesh2fde2c62018-09-11 20:33:24 +053010994 bool value;
Wu Gao66454f12018-09-26 19:55:41 +080010995 enum pmo_auto_pwr_detect_failure_mode auto_power_fail_mode;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053010996 bool bval = false;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010997
Jeff Johnson16528362018-06-14 12:34:16 -070010998 mac_handle = hdd_ctx->mac_handle;
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053010999
11000 hdd_action_oui_send(hdd_ctx);
Krunal Sonidf29bc42018-11-15 13:26:29 -080011001 status = ucfg_policy_mgr_get_force_1x1(hdd_ctx->psoc, &is_force_1x1);
11002 if (status != QDF_STATUS_SUCCESS) {
11003 hdd_err("Failed to get force 1x1 value");
11004 goto out;
11005 }
11006 if (is_force_1x1)
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011007 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
11008 1, PDEV_CMD);
11009 /* set chip power save failure detected callback */
Jeff Johnson16528362018-06-14 12:34:16 -070011010 sme_set_chip_pwr_save_fail_cb(mac_handle,
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011011 hdd_chip_pwr_save_fail_detected_cb);
11012
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053011013 status = ucfg_get_max_mpdus_inampdu(hdd_ctx->psoc,
11014 &max_mpdus_inampdu);
Krunal Sonidf29bc42018-11-15 13:26:29 -080011015 if (status) {
11016 hdd_err("Failed to get max mpdus in ampdu value");
11017 goto out;
11018 }
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053011019
11020 if (max_mpdus_inampdu) {
11021 set_value = max_mpdus_inampdu;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011022 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
11023 set_value, PDEV_CMD);
11024 }
11025
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053011026 status = ucfg_get_enable_rts_sifsbursting(hdd_ctx->psoc,
11027 &enable_rts_sifsbursting);
Krunal Sonidf29bc42018-11-15 13:26:29 -080011028 if (status) {
11029 hdd_err("Failed to get rts sifs bursting value");
11030 goto out;
11031 }
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053011032
11033 if (enable_rts_sifsbursting) {
11034 set_value = enable_rts_sifsbursting;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011035 sme_cli_set_command(0,
11036 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
11037 set_value, PDEV_CMD);
11038 }
11039
Dustin Brown05d81302018-09-11 16:49:22 -070011040 ucfg_mlme_get_sap_get_peer_info(hdd_ctx->psoc, &value);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +053011041 if (value) {
11042 set_value = value;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011043 sme_cli_set_command(0,
11044 (int)WMI_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
11045 set_value, PDEV_CMD);
11046 }
11047
Dustin Brown1dbefe62018-09-11 16:32:03 -070011048 status = ucfg_mlme_get_num_11b_tx_chains(hdd_ctx->psoc,
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +053011049 &num_11b_tx_chains);
11050 if (status != QDF_STATUS_SUCCESS) {
11051 hdd_err("Failed to get num_11b_tx_chains");
11052 goto out;
11053 }
11054
Dustin Brown1dbefe62018-09-11 16:32:03 -070011055 status = ucfg_mlme_get_num_11ag_tx_chains(hdd_ctx->psoc,
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +053011056 &num_11ag_tx_chains);
11057 if (status != QDF_STATUS_SUCCESS) {
11058 hdd_err("Failed to get num_11ag_tx_chains");
11059 goto out;
11060 }
11061
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053011062 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &bval);
11063 if (!QDF_IS_STATUS_SUCCESS(status))
11064 hdd_err("unable to get vht_enable2x2");
11065
11066 if (!bval) {
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011067 if (num_11b_tx_chains > 1)
11068 num_11b_tx_chains = 1;
11069 if (num_11ag_tx_chains > 1)
11070 num_11ag_tx_chains = 1;
11071 }
11072 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
11073 num_11b_tx_chains);
11074 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
11075 num_11ag_tx_chains);
11076 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
11077 num_abg_tx_chains, PDEV_CMD);
Arun Khandavallifae92942016-08-01 13:31:08 +053011078
Paul Zhang02526cd2018-09-20 17:47:46 +080011079 if (!ucfg_reg_is_regdb_offloaded(hdd_ctx->psoc))
11080 ucfg_reg_program_default_cc(hdd_ctx->pdev,
11081 hdd_ctx->reg.reg_domain);
11082
Arun Khandavallifae92942016-08-01 13:31:08 +053011083 ret = hdd_pre_enable_configure(hdd_ctx);
11084 if (ret) {
11085 hdd_err("Failed to pre-configure cds");
11086 goto out;
11087 }
11088
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -080011089 /* Always get latest IPA resources allocated from cds_open and configure
11090 * IPA module before configuring them to FW. Sequence required as crash
11091 * observed otherwise.
11092 */
Dustin Brown07901ec2018-09-07 11:02:41 -070011093 if (ucfg_ipa_uc_ol_init(hdd_ctx->pdev,
11094 cds_get_context(QDF_MODULE_ID_QDF_DEVICE))) {
Manikandan Mohan2e803a02017-02-14 14:57:53 -080011095 hdd_err("Failed to setup pipes");
11096 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -080011097 }
11098
Arun Khandavallifae92942016-08-01 13:31:08 +053011099 /*
11100 * Start CDS which starts up the SME/MAC/HAL modules and everything
11101 * else
11102 */
Dustin Brown1dbefe62018-09-11 16:32:03 -070011103 status = cds_enable(hdd_ctx->psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053011104
11105 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011106 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +053011107 goto out;
11108 }
11109
11110 status = hdd_post_cds_enable_config(hdd_ctx);
11111 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011112 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070011113 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +053011114 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +053011115 status = hdd_register_bcn_cb(hdd_ctx);
11116 if (!QDF_IS_STATUS_SUCCESS(status)) {
Paul Zhange03cf4c2018-01-19 18:33:22 +080011117 hdd_err("hdd_register_bcn_cb failed");
Abhishek Singh6092fbb2017-01-25 18:10:31 +053011118 goto cds_disable;
11119 }
Arun Khandavallifae92942016-08-01 13:31:08 +053011120
Dustin Browne7e71d32018-05-11 16:00:08 -070011121 ret = hdd_features_init(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053011122 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070011123 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +053011124
Mohit Khanna81418772018-10-30 14:14:46 -070011125 /* Donot disable rx offload on concurrency for lithium based targets */
11126 if (!(hdd_ctx->target_type == TARGET_TYPE_QCA6290 ||
11127 hdd_ctx->target_type == TARGET_TYPE_QCA6390))
11128 if (hdd_ctx->ol_enable)
11129 dp_cbs.hdd_disable_rx_ol_in_concurrency =
11130 hdd_disable_rx_ol_in_concurrency;
Yun Parkff6a16a2017-09-26 16:38:18 -070011131 dp_cbs.hdd_set_rx_mode_rps_cb = hdd_set_rx_mode_rps;
jiadbb47e132018-03-30 16:28:30 +080011132 dp_cbs.hdd_ipa_set_mcc_mode_cb = hdd_ipa_set_mcc_mode;
Manjunathappa Prakasha0cbc922018-05-08 19:48:34 -070011133 dp_cbs.hdd_v2_flow_pool_map = hdd_v2_flow_pool_map;
11134 dp_cbs.hdd_v2_flow_pool_unmap = hdd_v2_flow_pool_unmap;
Dustin Brown1dbefe62018-09-11 16:32:03 -070011135 status = policy_mgr_register_dp_cb(hdd_ctx->psoc, &dp_cbs);
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070011136 if (!QDF_IS_STATUS_SUCCESS(status)) {
Yun Parkff6a16a2017-09-26 16:38:18 -070011137 hdd_debug("Failed to register DP cb with Policy Manager");
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070011138 goto cds_disable;
11139 }
Dustin Brown1dbefe62018-09-11 16:32:03 -070011140 status = policy_mgr_register_mode_change_cb(hdd_ctx->psoc,
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053011141 wlan_hdd_send_mode_change_event);
11142 if (!QDF_IS_STATUS_SUCCESS(status)) {
11143 hdd_debug("Failed to register mode change cb with Policy Manager");
11144 goto cds_disable;
11145 }
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070011146
Jeff Johnson8bb61112018-03-31 13:33:54 -070011147 if (hdd_green_ap_enable_egap(hdd_ctx))
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +053011148 hdd_debug("enhance green ap is not enabled");
11149
Nachiket Kukadedd302662017-07-13 17:31:44 +053011150 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
11151 hdd_debug("Failed to set wow pulse");
11152
Ashish Kumar Dhanotiyacb14b112018-01-19 19:26:44 +053011153 sme_cli_set_command(0, WMI_PDEV_PARAM_GCMP_SUPPORT_ENABLE,
Manikandan Mohan66df7fc2019-01-08 17:57:05 -080011154 ucfg_fwol_get_gcmp_enable(hdd_ctx->psoc), PDEV_CMD);
Wu Gao66454f12018-09-26 19:55:41 +080011155
11156 auto_power_fail_mode =
11157 ucfg_pmo_get_auto_power_fail_mode(hdd_ctx->psoc);
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +053011158 sme_cli_set_command(0, WMI_PDEV_AUTO_DETECT_POWER_FAILURE,
Wu Gao66454f12018-09-26 19:55:41 +080011159 auto_power_fail_mode, PDEV_CMD);
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +053011160
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053011161 status = ucfg_get_enable_phy_reg_retention(hdd_ctx->psoc,
11162 &enable_phy_reg_retention);
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +053011163
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053011164 if (QDF_IS_STATUS_ERROR(status))
11165 return -EINVAL;
11166
11167 if (enable_phy_reg_retention)
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +053011168 wma_cli_set_command(0, WMI_PDEV_PARAM_FAST_PWR_TRANSITION,
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053011169 enable_phy_reg_retention, PDEV_CMD);
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +053011170
Jeff Johnson0187c622019-01-04 06:39:44 -080011171 hdd_hastings_bt_war_initialize(hdd_ctx);
11172
Arun Khandavallifae92942016-08-01 13:31:08 +053011173 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070011174
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070011175cds_disable:
Dustin Brown1dbefe62018-09-11 16:32:03 -070011176 cds_disable(hdd_ctx->psoc);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070011177
Arun Khandavallifae92942016-08-01 13:31:08 +053011178out:
11179 return -EINVAL;
11180}
11181
11182/**
11183 * hdd_deconfigure_cds() -De-Configure cds
11184 * @hdd_ctx: HDD context
11185 *
11186 * Deconfigure Cds modules before WLAN firmware is down.
11187 *
11188 * Return: 0 on success and errno on failure.
11189 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011190static int hdd_deconfigure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +053011191{
11192 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -070011193 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053011194
Dustin Brown491d54b2018-03-14 12:39:11 -070011195 hdd_enter();
Yu Wangf5d5b5f2017-05-25 22:38:32 +080011196
11197 /* De-init features */
11198 hdd_features_deinit(hdd_ctx);
11199
Dustin Brown1dbefe62018-09-11 16:32:03 -070011200 qdf_status = policy_mgr_deregister_mode_change_cb(hdd_ctx->psoc);
Srinivas Girigowdad2412882018-09-07 15:42:04 -070011201 if (!QDF_IS_STATUS_SUCCESS(qdf_status))
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053011202 hdd_debug("Failed to deregister mode change cb with Policy Manager");
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053011203
Dustin Brown1dbefe62018-09-11 16:32:03 -070011204 qdf_status = cds_disable(hdd_ctx->psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053011205 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
11206 hdd_err("Failed to Disable the CDS Modules! :%d",
11207 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -070011208 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011209 }
11210
Dustin Brown07901ec2018-09-07 11:02:41 -070011211 if (ucfg_ipa_uc_ol_deinit(hdd_ctx->pdev) != QDF_STATUS_SUCCESS) {
Sravan Kumar Kairam71121712017-04-15 00:34:42 +053011212 hdd_err("Failed to disconnect pipes");
11213 ret = -EINVAL;
11214 }
11215
Dustin Browne74003f2018-03-14 12:51:58 -070011216 hdd_exit();
Houston Hoffman6640cf32016-10-10 16:44:29 -070011217 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053011218}
11219
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070011220#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
11221static void hdd_deregister_policy_manager_callback(
11222 struct wlan_objmgr_psoc *psoc)
11223{
11224 if (QDF_STATUS_SUCCESS !=
11225 policy_mgr_deregister_hdd_cb(psoc)) {
11226 hdd_err("HDD callback deregister with policy manager failed");
11227 }
11228}
11229#else
11230static void hdd_deregister_policy_manager_callback(
11231 struct wlan_objmgr_psoc *psoc)
11232{
11233}
11234#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053011235
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011236int hdd_wlan_stop_modules(struct hdd_context *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +053011237{
11238 void *hif_ctx;
11239 qdf_device_t qdf_ctx;
11240 QDF_STATUS qdf_status;
Dustin Brown4bc0a622017-12-06 15:56:50 -080011241 bool is_recovery_stop = cds_is_driver_recovering();
Sourav Mohapatra808e3d42018-07-04 09:34:23 +053011242 int ret = 0;
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +053011243 int debugfs_threads;
Arunk Khandavallia6305a32018-01-25 11:19:18 +053011244 struct target_psoc_info *tgt_hdl;
Arun Khandavallifae92942016-08-01 13:31:08 +053011245
Dustin Brown491d54b2018-03-14 12:39:11 -070011246 hdd_enter();
Arun Khandavallifae92942016-08-01 13:31:08 +053011247
Dustin Brown1dbefe62018-09-11 16:32:03 -070011248 hdd_deregister_policy_manager_callback(hdd_ctx->psoc);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070011249
Arun Khandavallifae92942016-08-01 13:31:08 +053011250 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
11251 if (!qdf_ctx) {
11252 hdd_err("QDF device context NULL");
11253 return -EINVAL;
11254 }
11255
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070011256 cds_set_module_stop_in_progress(true);
Arun Khandavallifae92942016-08-01 13:31:08 +053011257
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +053011258 debugfs_threads = hdd_return_debugfs_threads_count();
Dustin Brown70111822017-03-30 15:31:40 -070011259
Dustin Brown3fdaaf62019-03-18 14:00:16 -070011260 if (debugfs_threads > 0 || hdd_ctx->is_wiphy_suspended) {
11261 hdd_warn("Debugfs threads %d, wiphy suspend %d",
11262 debugfs_threads, hdd_ctx->is_wiphy_suspended);
Dustin Brown70111822017-03-30 15:31:40 -070011263
Sourav Mohapatra808e3d42018-07-04 09:34:23 +053011264 if (IS_IDLE_STOP && !ftm_mode) {
Dustin Brown4c663222018-10-23 14:19:36 -070011265 hdd_psoc_idle_timer_start(hdd_ctx);
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070011266 cds_set_module_stop_in_progress(false);
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011267
Dustin Brown70111822017-03-30 15:31:40 -070011268 return 0;
11269 }
Rajeev Kumar86177c22017-03-16 19:44:39 -070011270 }
11271
Kabilan Kannan6edafeb2017-11-16 16:34:34 -080011272 /* free user wowl patterns */
11273 hdd_free_user_wowl_ptrns();
11274
Arun Khandavallifae92942016-08-01 13:31:08 +053011275 switch (hdd_ctx->driver_status) {
11276 case DRIVER_MODULES_UNINITIALIZED:
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011277 hdd_debug("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011278 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053011279 case DRIVER_MODULES_CLOSED:
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011280 hdd_debug("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011281 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053011282 case DRIVER_MODULES_ENABLED:
Dustin Brown1a20b082018-08-03 17:27:15 -070011283 hdd_info("Wlan transitioning (CLOSED <- ENABLED)");
11284
Nirav Shah6aeecf92019-02-13 14:05:03 +053011285 if (hdd_get_conparam() == QDF_GLOBAL_FTM_MODE ||
11286 hdd_get_conparam() == QDF_GLOBAL_EPPING_MODE)
Dustin Brown1a20b082018-08-03 17:27:15 -070011287 break;
Dustin Brown550f6d22017-12-14 15:44:01 -080011288
Komal Seelamf2136bb2016-09-28 18:30:44 +053011289 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +053011290 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011291 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +053011292 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011293 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011294 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011295 hdd_debug("successfully Disabled the CDS modules!");
Dustin Brown550f6d22017-12-14 15:44:01 -080011296
Arun Khandavallifae92942016-08-01 13:31:08 +053011297 break;
11298 default:
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011299 QDF_DEBUG_PANIC("Unknown driver state:%d",
Arun Khandavallifae92942016-08-01 13:31:08 +053011300 hdd_ctx->driver_status);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011301 ret = -EINVAL;
11302 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053011303 }
11304
Arunk Khandavalli890f6d92018-10-30 20:18:28 +053011305 hdd_sysfs_destroy_powerstats_interface();
Amar Singhal18081642018-01-26 16:04:13 -080011306 hdd_sysfs_destroy_version_interface();
Arunk Khandavalli890f6d92018-10-30 20:18:28 +053011307 hdd_sysfs_destroy_driver_root_obj();
Dustin Brown550f6d22017-12-14 15:44:01 -080011308 hdd_debug("Closing CDS modules!");
Amar Singhal18081642018-01-26 16:04:13 -080011309
Nirav Shah6aeecf92019-02-13 14:05:03 +053011310 if (hdd_get_conparam() != QDF_GLOBAL_EPPING_MODE) {
11311 qdf_status = cds_post_disable();
11312 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
11313 hdd_err("Failed to process post CDS disable! :%d",
11314 qdf_status);
11315 ret = -EINVAL;
11316 QDF_ASSERT(0);
11317 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070011318
Nirav Shah6aeecf92019-02-13 14:05:03 +053011319 /* De-register the SME callbacks */
11320 hdd_deregister_cb(hdd_ctx);
Sourav Mohapatra674925f2018-04-16 11:16:58 +053011321
Nirav Shah6aeecf92019-02-13 14:05:03 +053011322 hdd_runtime_suspend_context_deinit(hdd_ctx);
psimhadeea0a12017-12-18 14:50:02 -080011323
Nirav Shah6aeecf92019-02-13 14:05:03 +053011324 qdf_status = cds_dp_close(hdd_ctx->psoc);
11325 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
11326 hdd_warn("Failed to stop CDS DP: %d", qdf_status);
11327 ret = -EINVAL;
11328 QDF_ASSERT(0);
11329 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070011330
Nirav Shah6aeecf92019-02-13 14:05:03 +053011331 qdf_status = cds_close(hdd_ctx->psoc);
11332 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
11333 hdd_warn("Failed to stop CDS: %d", qdf_status);
11334 ret = -EINVAL;
11335 QDF_ASSERT(0);
11336 }
Rakshith Suresh Patkard9f4e612018-09-12 12:10:38 +053011337
Nirav Shah6aeecf92019-02-13 14:05:03 +053011338 qdf_status = wbuff_module_deinit();
11339 if (!QDF_IS_STATUS_SUCCESS(qdf_status))
11340 hdd_err("WBUFF de-init unsuccessful; status: %d",
11341 qdf_status);
Rakshith Suresh Patkard9f4e612018-09-12 12:10:38 +053011342
Nirav Shah6aeecf92019-02-13 14:05:03 +053011343 hdd_component_pdev_close(hdd_ctx->pdev);
Rakshith Suresh Patkard9f4e612018-09-12 12:10:38 +053011344
Nirav Shah6aeecf92019-02-13 14:05:03 +053011345 hdd_component_psoc_close(hdd_ctx->psoc);
11346 dispatcher_pdev_close(hdd_ctx->pdev);
11347 ret = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
11348 if (ret) {
11349 hdd_err("Failed to destroy pdev; errno:%d", ret);
11350 QDF_ASSERT(0);
11351 }
Liangwei Dong50a64a72018-01-11 01:17:00 -050011352 }
11353
11354 /*
11355 * Reset total mac phy during module stop such that during
11356 * next module start same psoc is used to populate new service
11357 * ready data
11358 */
Dustin Brown1dbefe62018-09-11 16:32:03 -070011359 tgt_hdl = wlan_psoc_get_tgt_if_handle(hdd_ctx->psoc);
Arunk Khandavallia6305a32018-01-25 11:19:18 +053011360 if (tgt_hdl)
11361 target_psoc_set_total_mac_phy_cnt(tgt_hdl, 0);
11362
Liangwei Dong50a64a72018-01-11 01:17:00 -050011363
Arun Khandavallifae92942016-08-01 13:31:08 +053011364 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
11365 if (!hif_ctx) {
11366 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011367 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011368 }
11369
Arunk Khandavalli4b404332017-09-26 12:46:00 +053011370 if (hdd_ctx->target_hw_name) {
11371 qdf_mem_free(hdd_ctx->target_hw_name);
11372 hdd_ctx->target_hw_name = NULL;
11373 }
11374
Visweswara Tanukuc949ad22019-03-20 13:00:30 +053011375 if (hdd_get_conparam() != QDF_GLOBAL_EPPING_MODE) {
11376 epping_disable();
11377 epping_close();
11378 }
11379
Sravan Kumar Kairam27296782017-04-21 22:04:18 +053011380 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053011381
11382 ol_cds_free();
11383
Dustin Brownc2a156e2018-10-25 16:56:27 -070011384 if (IS_IDLE_STOP) {
Arun Khandavallifae92942016-08-01 13:31:08 +053011385 ret = pld_power_off(qdf_ctx->dev);
11386 if (ret)
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011387 hdd_err("Failed to power down device; errno:%d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +053011388 }
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011389
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011390 /* Free the cache channels of the command SET_DISABLE_CHANNEL_LIST */
11391 wlan_hdd_free_cache_channels(hdd_ctx);
Arunk Khandavalli847969d2017-09-25 15:15:36 +053011392
Jingxiang Ge3de02752019-01-29 15:47:03 +080011393 hdd_sap_destroy_ctx_all(hdd_ctx, is_recovery_stop);
11394
Dustin Brown29533f22018-07-24 13:11:56 -070011395 hdd_check_for_leaks(hdd_ctx, is_recovery_stop);
Dustin Brown26b3d042017-12-21 11:13:27 -080011396 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -080011397
Arunk Khandavalli847969d2017-09-25 15:15:36 +053011398 /* Once the firmware sequence is completed reset this flag */
11399 hdd_ctx->imps_enabled = false;
Arun Khandavallifae92942016-08-01 13:31:08 +053011400 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -080011401 hdd_info("Wlan transitioned (now CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053011402
Kai Liueabb1df2018-11-08 14:58:54 +080011403 pld_request_bus_bandwidth(hdd_ctx->parent_dev, PLD_BUS_WIDTH_NONE);
11404
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011405done:
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070011406 cds_set_module_stop_in_progress(false);
Dustin Brown4bc0a622017-12-06 15:56:50 -080011407
Dustin Browne74003f2018-03-14 12:51:58 -070011408 hdd_exit();
Arun Khandavallifae92942016-08-01 13:31:08 +053011409
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011410 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053011411}
11412
Wen Gong3f003382018-05-14 14:26:37 +080011413#ifdef WLAN_FEATURE_MEMDUMP_ENABLE
Arun Khandavallifae92942016-08-01 13:31:08 +053011414/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011415 * hdd_state_info_dump() - prints state information of hdd layer
11416 * @buf: buffer pointer
11417 * @size: size of buffer to be filled
11418 *
11419 * This function is used to dump state information of hdd layer
11420 *
11421 * Return: None
11422 */
11423static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
11424{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011425 struct hdd_context *hdd_ctx;
Jeff Johnson40dae4e2017-08-29 14:00:25 -070011426 struct hdd_station_ctx *hdd_sta_ctx;
Jeff Johnson9d295242017-08-29 14:39:48 -070011427 struct hdd_adapter *adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011428 uint16_t len = 0;
11429 char *buf = *buf_ptr;
11430
11431 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11432 if (!hdd_ctx) {
11433 hdd_err("Failed to get hdd context ");
11434 return;
11435 }
11436
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011437 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011438
11439 len += scnprintf(buf + len, *size - len,
Jeff Johnson214671b2017-10-30 19:45:23 -070011440 "\n is_wiphy_suspended %d", hdd_ctx->is_wiphy_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011441 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -080011442 "\n is_scheduler_suspended %d",
11443 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011444
Dustin Brown920397d2017-12-13 16:27:50 -080011445 hdd_for_each_adapter(hdd_ctx, adapter) {
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011446 if (adapter->dev)
11447 len += scnprintf(buf + len, *size - len,
11448 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +080011449 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011450 "\n device_mode: %d", adapter->device_mode);
11451 switch (adapter->device_mode) {
11452 case QDF_STA_MODE:
11453 case QDF_P2P_CLIENT_MODE:
11454 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
11455 len += scnprintf(buf + len, *size - len,
Jeff Johnsone7951512019-02-27 10:02:51 -080011456 "\n conn_state: %d",
11457 hdd_sta_ctx->conn_info.conn_state);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011458 break;
11459
11460 default:
11461 break;
11462 }
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011463 }
11464
11465 *size -= len;
11466 *buf_ptr += len;
11467}
11468
11469/**
11470 * hdd_register_debug_callback() - registration function for hdd layer
11471 * to print hdd state information
11472 *
11473 * Return: None
11474 */
11475static void hdd_register_debug_callback(void)
11476{
11477 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
11478}
Wen Gong3f003382018-05-14 14:26:37 +080011479#else /* WLAN_FEATURE_MEMDUMP_ENABLE */
Wen Gongaa6d55d2018-04-26 16:33:21 +080011480static void hdd_register_debug_callback(void)
11481{
11482}
Wen Gong3f003382018-05-14 14:26:37 +080011483#endif /* WLAN_FEATURE_MEMDUMP_ENABLE */
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011484
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +053011485/*
11486 * wlan_init_bug_report_lock() - Initialize bug report lock
11487 *
11488 * This function is used to create bug report lock
11489 *
11490 * Return: None
11491 */
11492static void wlan_init_bug_report_lock(void)
11493{
Jeff Johnson2b6982c2018-05-29 14:56:11 -070011494 struct cds_context *p_cds_context;
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +053011495
11496 p_cds_context = cds_get_global_context();
11497 if (!p_cds_context) {
11498 hdd_err("cds context is NULL");
11499 return;
11500 }
11501
11502 qdf_spinlock_create(&p_cds_context->bug_report_lock);
11503}
11504
Nirav Shahd21a2e32018-04-20 16:34:43 +053011505#ifdef CONFIG_DP_TRACE
Mohit Khannaf8f96822017-05-17 17:11:59 -070011506void hdd_dp_trace_init(struct hdd_config *config)
11507{
Mohit Khannaf8f96822017-05-17 17:11:59 -070011508 bool live_mode = DP_TRACE_CONFIG_DEFAULT_LIVE_MODE;
11509 uint8_t thresh = DP_TRACE_CONFIG_DEFAULT_THRESH;
11510 uint16_t thresh_time_limit = DP_TRACE_CONFIG_DEFAULT_THRESH_TIME_LIMIT;
11511 uint8_t verbosity = DP_TRACE_CONFIG_DEFAULT_VERBOSTY;
11512 uint8_t proto_bitmap = DP_TRACE_CONFIG_DEFAULT_BITMAP;
11513 uint8_t config_params[DP_TRACE_CONFIG_NUM_PARAMS];
11514 uint8_t num_entries = 0;
Lin Baiaa7f8d72017-10-18 17:23:45 +080011515 uint32_t bw_compute_interval;
Mohit Khannaf8f96822017-05-17 17:11:59 -070011516
Nirav Shahd21a2e32018-04-20 16:34:43 +053011517 if (!config->enable_dp_trace) {
11518 hdd_err("dp trace is disabled from ini");
11519 return;
11520 }
11521
Mohit Khannaf8f96822017-05-17 17:11:59 -070011522 hdd_string_to_u8_array(config->dp_trace_config, config_params,
11523 &num_entries, sizeof(config_params));
11524
11525 /* calculating, num bw timer intervals in a second (1000ms) */
Lin Baiaa7f8d72017-10-18 17:23:45 +080011526 bw_compute_interval = GET_BW_COMPUTE_INTV(config);
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080011527 if (bw_compute_interval <= 1000 && bw_compute_interval > 0)
Lin Baiaa7f8d72017-10-18 17:23:45 +080011528 thresh_time_limit = 1000 / bw_compute_interval;
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080011529 else if (bw_compute_interval > 1000) {
11530 hdd_err("busBandwidthComputeInterval > 1000, using 1000");
11531 thresh_time_limit = 1;
11532 } else
Mohit Khannaf8f96822017-05-17 17:11:59 -070011533 hdd_err("busBandwidthComputeInterval is 0, using defaults");
11534
11535 switch (num_entries) {
11536 case 4:
11537 proto_bitmap = config_params[3];
Alok Kumarb5a33a22018-05-07 18:09:14 +053011538 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070011539 case 3:
11540 verbosity = config_params[2];
Alok Kumarb5a33a22018-05-07 18:09:14 +053011541 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070011542 case 2:
11543 thresh = config_params[1];
Alok Kumarb5a33a22018-05-07 18:09:14 +053011544 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070011545 case 1:
11546 live_mode = config_params[0];
Alok Kumarb5a33a22018-05-07 18:09:14 +053011547 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070011548 default:
Dustin Browna7bb6ae2018-08-16 16:51:50 -070011549 hdd_debug("live_mode %u thresh %u time_limit %u verbosity %u bitmap 0x%x",
11550 live_mode, thresh, thresh_time_limit,
11551 verbosity, proto_bitmap);
Mohit Khannaf8f96822017-05-17 17:11:59 -070011552 };
11553
11554 qdf_dp_trace_init(live_mode, thresh, thresh_time_limit,
11555 verbosity, proto_bitmap);
11556
11557}
Nirav Shahd21a2e32018-04-20 16:34:43 +053011558#endif
11559
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011560#ifdef DISABLE_CHANNEL_LIST
Dustin Brown623e7e32018-09-05 14:27:50 -070011561static QDF_STATUS wlan_hdd_cache_chann_mutex_create(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011562{
11563 return qdf_mutex_create(&hdd_ctx->cache_channel_lock);
11564}
11565#else
Dustin Brown623e7e32018-09-05 14:27:50 -070011566static QDF_STATUS wlan_hdd_cache_chann_mutex_create(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011567{
Dustin Brown623e7e32018-09-05 14:27:50 -070011568 return QDF_STATUS_SUCCESS;
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011569}
11570#endif
11571
Dustin Brown693b5352019-01-17 10:00:31 -080011572static QDF_STATUS hdd_open_adapter_no_trans(struct hdd_context *hdd_ctx,
11573 enum QDF_OPMODE op_mode,
11574 const char *iface_name,
11575 uint8_t *mac_addr_bytes)
11576{
Dustin Brown2c5e0482019-02-05 16:14:43 -080011577 struct osif_vdev_sync *vdev_sync;
Dustin Brown693b5352019-01-17 10:00:31 -080011578 struct hdd_adapter *adapter;
11579 QDF_STATUS status;
11580 int errno;
11581
11582 QDF_BUG(rtnl_is_locked());
Dustin Brown693b5352019-01-17 10:00:31 -080011583
Dustin Brown2c5e0482019-02-05 16:14:43 -080011584 errno = osif_vdev_sync_create(hdd_ctx->parent_dev, &vdev_sync);
Dustin Brown693b5352019-01-17 10:00:31 -080011585 if (errno)
11586 return qdf_status_from_os_return(errno);
11587
11588 adapter = hdd_open_adapter(hdd_ctx, op_mode, iface_name,
11589 mac_addr_bytes, NET_NAME_UNKNOWN, true);
11590 if (!adapter) {
11591 status = QDF_STATUS_E_INVAL;
11592 goto destroy_sync;
11593 }
11594
Dustin Brown2c5e0482019-02-05 16:14:43 -080011595 osif_vdev_sync_register(adapter->dev, vdev_sync);
Dustin Brown693b5352019-01-17 10:00:31 -080011596
11597 return QDF_STATUS_SUCCESS;
11598
11599destroy_sync:
Dustin Brown2c5e0482019-02-05 16:14:43 -080011600 osif_vdev_sync_destroy(vdev_sync);
Dustin Brown693b5352019-01-17 10:00:31 -080011601
11602 return status;
11603}
11604
11605#ifdef WLAN_OPEN_P2P_INTERFACE
11606/**
11607 * hdd_open_p2p_interface - Open P2P interface
11608 * @hdd_ctx: HDD context
11609 *
11610 * Return: QDF_STATUS
11611 */
11612static QDF_STATUS hdd_open_p2p_interface(struct hdd_context *hdd_ctx)
11613{
11614 QDF_STATUS status;
11615 bool p2p_dev_addr_admin;
11616 bool is_p2p_locally_administered = false;
11617
11618 cfg_p2p_get_device_addr_admin(hdd_ctx->psoc, &p2p_dev_addr_admin);
11619
11620 if (p2p_dev_addr_admin) {
11621 if (hdd_ctx->num_provisioned_addr &&
11622 !(hdd_ctx->provisioned_mac_addr[0].bytes[0] & 0x02)) {
11623 hdd_ctx->p2p_device_address =
11624 hdd_ctx->provisioned_mac_addr[0];
11625
11626 /*
11627 * Generate the P2P Device Address. This consists of
11628 * the device's primary MAC address with the locally
11629 * administered bit set.
11630 */
11631
11632 hdd_ctx->p2p_device_address.bytes[0] |= 0x02;
11633 is_p2p_locally_administered = true;
11634 } else if (!(hdd_ctx->derived_mac_addr[0].bytes[0] & 0x02)) {
11635 hdd_ctx->p2p_device_address =
11636 hdd_ctx->derived_mac_addr[0];
11637 /*
11638 * Generate the P2P Device Address. This consists of
11639 * the device's primary MAC address with the locally
11640 * administered bit set.
11641 */
11642 hdd_ctx->p2p_device_address.bytes[0] |= 0x02;
11643 is_p2p_locally_administered = true;
11644 }
11645 }
11646 if (!is_p2p_locally_administered) {
11647 uint8_t *p2p_dev_addr;
11648
11649 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx,
11650 QDF_P2P_DEVICE_MODE);
11651 if (!p2p_dev_addr) {
11652 hdd_err("Failed to get MAC address for new p2p device");
11653 return QDF_STATUS_E_INVAL;
11654 }
11655
11656 qdf_mem_copy(hdd_ctx->p2p_device_address.bytes,
11657 p2p_dev_addr, QDF_MAC_ADDR_SIZE);
11658 }
11659
11660 status = hdd_open_adapter_no_trans(hdd_ctx, QDF_P2P_DEVICE_MODE,
11661 "p2p%d",
11662 hdd_ctx->p2p_device_address.bytes);
11663 if (QDF_IS_STATUS_ERROR(status)) {
11664 hdd_err("Failed to open p2p interface");
11665 return QDF_STATUS_E_INVAL;
11666 }
11667
11668 return QDF_STATUS_SUCCESS;
11669}
11670#else
11671static inline QDF_STATUS hdd_open_p2p_interface(struct hdd_context *hdd_ctx)
11672{
11673 return QDF_STATUS_SUCCESS;
11674}
11675#endif
11676
11677static QDF_STATUS hdd_open_ocb_interface(struct hdd_context *hdd_ctx)
11678{
11679 QDF_STATUS status;
11680 uint8_t *mac_addr;
11681
11682 mac_addr = wlan_hdd_get_intf_addr(hdd_ctx, QDF_OCB_MODE);
11683 status = hdd_open_adapter_no_trans(hdd_ctx, QDF_OCB_MODE,
11684 "wlanocb%d", mac_addr);
11685 if (QDF_IS_STATUS_ERROR(status))
11686 hdd_err("Failed to open 802.11p interface");
11687
11688 return status;
11689}
11690
11691static QDF_STATUS hdd_open_concurrent_interface(struct hdd_context *hdd_ctx)
11692{
11693 QDF_STATUS status;
11694 const char *iface_name;
11695 uint8_t *mac_addr;
11696
11697 if (qdf_str_eq(hdd_ctx->config->enable_concurrent_sta, ""))
11698 return QDF_STATUS_SUCCESS;
11699
11700 iface_name = hdd_ctx->config->enable_concurrent_sta;
11701 mac_addr = wlan_hdd_get_intf_addr(hdd_ctx, QDF_STA_MODE);
11702 status = hdd_open_adapter_no_trans(hdd_ctx, QDF_STA_MODE,
11703 iface_name, mac_addr);
11704 if (QDF_IS_STATUS_ERROR(status))
11705 hdd_err("Failed to open concurrent station interface");
11706
11707 return status;
11708}
11709
Dustin Brown61cc3932018-10-18 16:12:13 -070011710static QDF_STATUS
11711hdd_open_adapters_for_mission_mode(struct hdd_context *hdd_ctx)
Dustin Browna2deeb72018-10-18 14:19:27 -070011712{
Dustin Browna2deeb72018-10-18 14:19:27 -070011713 enum dot11p_mode dot11p_mode;
Dustin Brown61cc3932018-10-18 16:12:13 -070011714 QDF_STATUS status;
Dustin Brown693b5352019-01-17 10:00:31 -080011715 uint8_t *mac_addr;
Dustin Browna2deeb72018-10-18 14:19:27 -070011716
11717 ucfg_mlme_get_dot11p_mode(hdd_ctx->psoc, &dot11p_mode);
11718
11719 /* Create only 802.11p interface? */
11720 if (dot11p_mode == CFG_11P_STANDALONE)
Dustin Brown61cc3932018-10-18 16:12:13 -070011721 return hdd_open_ocb_interface(hdd_ctx);
Dustin Browna2deeb72018-10-18 14:19:27 -070011722
Dustin Brown693b5352019-01-17 10:00:31 -080011723 mac_addr = wlan_hdd_get_intf_addr(hdd_ctx, QDF_STA_MODE);
11724 status = hdd_open_adapter_no_trans(hdd_ctx, QDF_STA_MODE,
11725 "wlan%d", mac_addr);
11726 if (QDF_IS_STATUS_ERROR(status))
11727 return status;
Dustin Browna2deeb72018-10-18 14:19:27 -070011728
Dustin Brown61cc3932018-10-18 16:12:13 -070011729 /* opening concurrent STA is best effort, continue on error */
11730 hdd_open_concurrent_interface(hdd_ctx);
Dustin Browna2deeb72018-10-18 14:19:27 -070011731
Dustin Brown61cc3932018-10-18 16:12:13 -070011732 status = hdd_open_p2p_interface(hdd_ctx);
11733 if (status)
Dustin Browna2deeb72018-10-18 14:19:27 -070011734 goto err_close_adapters;
11735
11736 /* Open 802.11p Interface */
11737 if (dot11p_mode == CFG_11P_CONCURRENT) {
Dustin Brown61cc3932018-10-18 16:12:13 -070011738 status = hdd_open_ocb_interface(hdd_ctx);
11739 if (QDF_IS_STATUS_ERROR(status))
Dustin Browna2deeb72018-10-18 14:19:27 -070011740 goto err_close_adapters;
11741 }
11742
Dustin Brown61cc3932018-10-18 16:12:13 -070011743 return QDF_STATUS_SUCCESS;
Dustin Browna2deeb72018-10-18 14:19:27 -070011744
11745err_close_adapters:
11746 hdd_close_all_adapters(hdd_ctx, true);
11747
Dustin Brown61cc3932018-10-18 16:12:13 -070011748 return status;
Dustin Browna2deeb72018-10-18 14:19:27 -070011749}
11750
Dustin Brown61cc3932018-10-18 16:12:13 -070011751static QDF_STATUS hdd_open_adapters_for_ftm_mode(struct hdd_context *hdd_ctx)
Dustin Browna2deeb72018-10-18 14:19:27 -070011752{
Dustin Brown693b5352019-01-17 10:00:31 -080011753 uint8_t *mac_addr = wlan_hdd_get_intf_addr(hdd_ctx, QDF_FTM_MODE);
Dustin Brown61cc3932018-10-18 16:12:13 -070011754
Dustin Brown693b5352019-01-17 10:00:31 -080011755 return hdd_open_adapter_no_trans(hdd_ctx, QDF_FTM_MODE,
11756 "wlan%d", mac_addr);
Dustin Brown61cc3932018-10-18 16:12:13 -070011757}
11758
11759static QDF_STATUS
11760hdd_open_adapters_for_monitor_mode(struct hdd_context *hdd_ctx)
11761{
Dustin Brown693b5352019-01-17 10:00:31 -080011762 uint8_t *mac_addr = wlan_hdd_get_intf_addr(hdd_ctx, QDF_MONITOR_MODE);
Dustin Brown61cc3932018-10-18 16:12:13 -070011763
Dustin Brown693b5352019-01-17 10:00:31 -080011764 return hdd_open_adapter_no_trans(hdd_ctx, QDF_MONITOR_MODE,
11765 "wlan%d", mac_addr);
Dustin Brown61cc3932018-10-18 16:12:13 -070011766}
11767
11768static QDF_STATUS hdd_open_adapters_for_epping_mode(struct hdd_context *hdd_ctx)
11769{
Nirav Shah6aeecf92019-02-13 14:05:03 +053011770 epping_enable_adapter();
Dustin Brown61cc3932018-10-18 16:12:13 -070011771 return QDF_STATUS_SUCCESS;
Dustin Brown61cc3932018-10-18 16:12:13 -070011772}
11773
11774typedef QDF_STATUS (*hdd_open_mode_handler)(struct hdd_context *hdd_ctx);
11775
11776static const hdd_open_mode_handler
11777hdd_open_mode_handlers[QDF_GLOBAL_MAX_MODE] = {
11778 [QDF_GLOBAL_MISSION_MODE] = hdd_open_adapters_for_mission_mode,
11779 [QDF_GLOBAL_FTM_MODE] = hdd_open_adapters_for_ftm_mode,
11780 [QDF_GLOBAL_MONITOR_MODE] = hdd_open_adapters_for_monitor_mode,
11781 [QDF_GLOBAL_EPPING_MODE] = hdd_open_adapters_for_epping_mode,
11782};
11783
Dustin Brown92bd8382018-10-31 15:49:46 -070011784static QDF_STATUS hdd_open_adapters_for_mode(struct hdd_context *hdd_ctx,
11785 enum QDF_GLOBAL_MODE driver_mode)
Dustin Brown61cc3932018-10-18 16:12:13 -070011786{
11787 QDF_STATUS status;
11788
11789 if (driver_mode < 0 ||
11790 driver_mode >= QDF_GLOBAL_MAX_MODE ||
11791 !hdd_open_mode_handlers[driver_mode]) {
11792 hdd_err("Driver mode %d not supported", driver_mode);
11793 return -ENOTSUPP;
11794 }
Dustin Browna2deeb72018-10-18 14:19:27 -070011795
11796 hdd_hold_rtnl_lock();
Dustin Brown61cc3932018-10-18 16:12:13 -070011797 status = hdd_open_mode_handlers[driver_mode](hdd_ctx);
Dustin Browna2deeb72018-10-18 14:19:27 -070011798 hdd_release_rtnl_lock();
11799
Dustin Brown92bd8382018-10-31 15:49:46 -070011800 return status;
Dustin Browna2deeb72018-10-18 14:19:27 -070011801}
11802
Dustin Brown623e7e32018-09-05 14:27:50 -070011803int hdd_wlan_startup(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011804{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011805 QDF_STATUS status;
Dustin Brown623e7e32018-09-05 14:27:50 -070011806 int errno;
Pragaspathi Thilagaraj784c4922018-12-02 22:47:29 +053011807 bool is_imps_enabled;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011808
Dustin Brown491d54b2018-03-14 12:39:11 -070011809 hdd_enter();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011810
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053011811 hdd_action_oui_config(hdd_ctx);
11812
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053011813 qdf_nbuf_init_replenish_timer();
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011814
Dustin Brown623e7e32018-09-05 14:27:50 -070011815 status = wlan_hdd_cache_chann_mutex_create(hdd_ctx);
11816 if (QDF_IS_STATUS_ERROR(status))
11817 return qdf_status_to_os_return(status);
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011818
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +053011819#ifdef FEATURE_WLAN_CH_AVOID
11820 mutex_init(&hdd_ctx->avoid_freq_lock);
11821#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053011822
Naveen Rawate02f8f52018-04-05 11:58:04 -070011823 osif_request_manager_init();
Dustin Brown021cecd2017-12-11 13:56:43 -080011824 hdd_driver_memdump_init();
Dustin Brown86d196b2018-08-02 11:51:49 -070011825 hdd_bus_bandwidth_init(hdd_ctx);
Dustin Brown021cecd2017-12-11 13:56:43 -080011826
Arunk Khandavalli5ff0375472019-01-11 17:26:47 +053011827#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
11828 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
11829 QDF_TIMER_TYPE_SW,
11830 hdd_skip_acs_scan_timer_handler,
11831 hdd_ctx);
11832 if (QDF_IS_STATUS_ERROR(status))
11833 hdd_err("Failed to init ACS Skip timer");
11834 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
11835#endif
11836
Dustin Brown623e7e32018-09-05 14:27:50 -070011837 errno = hdd_wlan_start_modules(hdd_ctx, false);
11838 if (errno) {
11839 hdd_err("Failed to start modules; errno:%d", errno);
11840 goto memdump_deinit;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011841 }
11842
Nirav Shah6aeecf92019-02-13 14:05:03 +053011843 if (hdd_get_conparam() == QDF_GLOBAL_EPPING_MODE)
11844 return 0;
11845
Yingying Tang80e15f32016-09-27 18:23:01 +080011846 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011847
Dustin Brown623e7e32018-09-05 14:27:50 -070011848 hdd_ctx->mac_handle = cds_get_context(QDF_MODULE_ID_SME);
11849 if (!hdd_ctx->mac_handle) {
Jeff Johnson16528362018-06-14 12:34:16 -070011850 hdd_err("Mac Handle is null");
Dustin Brown623e7e32018-09-05 14:27:50 -070011851 goto stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011852 }
11853
Dustin Brown623e7e32018-09-05 14:27:50 -070011854 errno = hdd_wiphy_init(hdd_ctx);
11855 if (errno) {
11856 hdd_err("Failed to initialize wiphy; errno:%d", errno);
11857 goto stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011858 }
11859
Nirav Shahd21a2e32018-04-20 16:34:43 +053011860 hdd_dp_trace_init(hdd_ctx->config);
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053011861
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053011862 errno = hdd_initialize_mac_address(hdd_ctx);
11863 if (errno) {
11864 hdd_err("MAC initializtion failed: %d", errno);
11865 goto unregister_wiphy;
11866 }
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -080011867
Dustin Brown623e7e32018-09-05 14:27:50 -070011868 errno = register_netdevice_notifier(&hdd_netdev_notifier);
11869 if (errno) {
11870 hdd_err("register_netdevice_notifier failed; errno:%d", errno);
11871 goto unregister_wiphy;
Paul Zhangfb02f452017-12-22 11:58:43 +080011872 }
Arun Khandavalli08479ba2017-08-07 19:56:23 +053011873
Dustin Brown623e7e32018-09-05 14:27:50 -070011874 errno = register_reboot_notifier(&system_reboot_notifier);
11875 if (errno) {
11876 hdd_err("Failed to register reboot notifier; errno:%d", errno);
11877 goto unregister_netdev;
Arunk Khandavalli830c9692018-03-22 12:17:40 +053011878 }
11879
Sandeep Puligilla34618782019-01-04 17:42:42 -080011880 wlan_hdd_update_11n_mode(hdd_ctx);
Yingying Tang3ba3dbc2016-09-27 16:36:58 +080011881
Arunk Khandavalli40943af2017-05-15 19:25:34 +053011882 hdd_lpass_notify_wlan_version(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011883
Dustin Brown623e7e32018-09-05 14:27:50 -070011884 errno = hdd_register_notifiers(hdd_ctx);
11885 if (errno)
11886 goto unregister_reboot;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -070011887
Paul Zhangfb02f452017-12-22 11:58:43 +080011888 status = wlansap_global_init();
Dustin Brown92bd8382018-10-31 15:49:46 -070011889 if (QDF_IS_STATUS_ERROR(status))
11890 goto unregister_notifiers;
Paul Zhangfb02f452017-12-22 11:58:43 +080011891
Pragaspathi Thilagaraj784c4922018-12-02 22:47:29 +053011892 ucfg_mlme_is_imps_enabled(hdd_ctx->psoc, &is_imps_enabled);
11893 hdd_set_idle_ps_config(hdd_ctx, is_imps_enabled);
Arun Kumar Khandavallideda5a82019-03-11 15:32:19 +053011894 hdd_debugfs_mws_coex_info_init(hdd_ctx);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011895
Dustin Brown92bd8382018-10-31 15:49:46 -070011896 hdd_exit();
11897
11898 return 0;
11899
11900unregister_notifiers:
11901 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011902
Dustin Brown623e7e32018-09-05 14:27:50 -070011903unregister_reboot:
Arunk Khandavalli830c9692018-03-22 12:17:40 +053011904 unregister_reboot_notifier(&system_reboot_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011905
Dustin Brown623e7e32018-09-05 14:27:50 -070011906unregister_netdev:
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011907 unregister_netdevice_notifier(&hdd_netdev_notifier);
11908
Dustin Brown623e7e32018-09-05 14:27:50 -070011909unregister_wiphy:
Rachit Kankane30807332018-06-27 18:39:36 +053011910 qdf_dp_trace_deinit();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011911 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011912
Dustin Brown623e7e32018-09-05 14:27:50 -070011913stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070011914 hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053011915
Dustin Brown623e7e32018-09-05 14:27:50 -070011916memdump_deinit:
Dustin Brown86d196b2018-08-02 11:51:49 -070011917 hdd_bus_bandwidth_deinit(hdd_ctx);
Dustin Brown021cecd2017-12-11 13:56:43 -080011918 hdd_driver_memdump_deinit();
Naveen Rawate02f8f52018-04-05 11:58:04 -070011919 osif_request_manager_deinit();
Dustin Brown623e7e32018-09-05 14:27:50 -070011920 qdf_nbuf_deinit_replenish_timer();
Ryan Hsucfef0ae2016-04-28 10:20:46 -070011921
Nachiket Kukade8003d252017-03-30 15:55:58 +053011922 if (cds_is_fw_down())
11923 hdd_err("Not setting the complete event as fw is down");
11924 else
Dustin Brown623e7e32018-09-05 14:27:50 -070011925 hdd_start_complete(errno);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011926
Dustin Browne74003f2018-03-14 12:51:58 -070011927 hdd_exit();
Dustin Brown92bd8382018-10-31 15:49:46 -070011928
Dustin Brown623e7e32018-09-05 14:27:50 -070011929 return errno;
Dustin Brown92bd8382018-10-31 15:49:46 -070011930}
11931
11932QDF_STATUS hdd_psoc_create_vdevs(struct hdd_context *hdd_ctx)
11933{
11934 enum QDF_GLOBAL_MODE driver_mode = hdd_get_conparam();
11935 QDF_STATUS status;
11936
11937 status = hdd_open_adapters_for_mode(hdd_ctx, driver_mode);
11938 if (QDF_IS_STATUS_ERROR(status)) {
11939 hdd_err("Failed to create vdevs; status:%d", status);
11940 return status;
11941 }
11942
11943 if (hdd_ctx->rps)
11944 hdd_set_rps_cpu_mask(hdd_ctx);
11945
11946 if (driver_mode != QDF_GLOBAL_FTM_MODE)
11947 hdd_psoc_idle_timer_start(hdd_ctx);
11948
11949 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011950}
11951
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011952/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011953 * hdd_wlan_update_target_info() - update target type info
11954 * @hdd_ctx: HDD context
11955 * @context: hif context
11956 *
11957 * Update target info received from firmware in hdd context
11958 * Return:None
11959 */
11960
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011961void hdd_wlan_update_target_info(struct hdd_context *hdd_ctx, void *context)
Arun Khandavallifae92942016-08-01 13:31:08 +053011962{
11963 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
11964
11965 if (!tgt_info) {
11966 hdd_err("Target info is Null");
11967 return;
11968 }
11969
11970 hdd_ctx->target_type = tgt_info->target_type;
11971}
11972
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053011973void hdd_get_nud_stats_cb(void *data, struct rsp_stats *rsp, void *context)
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011974{
11975 struct hdd_context *hdd_ctx = (struct hdd_context *)data;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011976 int status;
11977 struct hdd_adapter *adapter = NULL;
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070011978 struct osif_request *request = NULL;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011979
Dustin Brown491d54b2018-03-14 12:39:11 -070011980 hdd_enter();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011981
11982 if (!rsp) {
11983 hdd_err("data is null");
11984 return;
11985 }
11986
11987 status = wlan_hdd_validate_context(hdd_ctx);
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053011988 if (status != 0)
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011989 return;
11990
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070011991 request = osif_request_get(context);
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053011992 if (!request) {
11993 hdd_err("obselete request");
11994 return;
11995 }
11996
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011997 adapter = hdd_get_adapter_by_vdev(hdd_ctx, rsp->vdev_id);
Jeff Johnsond36fa332019-03-18 13:42:25 -070011998 if ((!adapter) || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011999 hdd_err("Invalid adapter or adapter has invalid magic");
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070012000 osif_request_put(request);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012001 return;
12002 }
12003
Alok Kumarce2c29a2018-10-12 15:44:02 +053012004 hdd_debug("rsp->arp_req_enqueue :%x", rsp->arp_req_enqueue);
12005 hdd_debug("rsp->arp_req_tx_success :%x", rsp->arp_req_tx_success);
12006 hdd_debug("rsp->arp_req_tx_failure :%x", rsp->arp_req_tx_failure);
12007 hdd_debug("rsp->arp_rsp_recvd :%x", rsp->arp_rsp_recvd);
12008 hdd_debug("rsp->out_of_order_arp_rsp_drop_cnt :%x",
12009 rsp->out_of_order_arp_rsp_drop_cnt);
12010 hdd_debug("rsp->dad_detected :%x", rsp->dad_detected);
12011 hdd_debug("rsp->connect_status :%x", rsp->connect_status);
12012 hdd_debug("rsp->ba_session_establishment_status :%x",
12013 rsp->ba_session_establishment_status);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012014
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012015 adapter->hdd_stats.hdd_arp_stats.rx_fw_cnt = rsp->arp_rsp_recvd;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012016 adapter->dad |= rsp->dad_detected;
12017 adapter->con_status = rsp->connect_status;
12018
Poddar, Siddarth31797fa2018-01-22 17:24:15 +053012019 /* Flag true indicates connectivity check stats present. */
12020 if (rsp->connect_stats_present) {
Alok Kumarce2c29a2018-10-12 15:44:02 +053012021 hdd_debug("rsp->tcp_ack_recvd :%x", rsp->tcp_ack_recvd);
12022 hdd_debug("rsp->icmpv4_rsp_recvd :%x", rsp->icmpv4_rsp_recvd);
Poddar, Siddarth31797fa2018-01-22 17:24:15 +053012023 adapter->hdd_stats.hdd_tcp_stats.rx_fw_cnt = rsp->tcp_ack_recvd;
12024 adapter->hdd_stats.hdd_icmpv4_stats.rx_fw_cnt =
12025 rsp->icmpv4_rsp_recvd;
12026 }
12027
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070012028 osif_request_complete(request);
12029 osif_request_put(request);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012030
Dustin Browne74003f2018-03-14 12:51:58 -070012031 hdd_exit();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012032}
12033
Visweswara Tanuku633976b2019-01-07 16:13:12 +053012034#ifdef WLAN_FEATURE_MOTION_DETECTION
12035/**
12036 * hdd_md_host_evt_cb - Callback for Motion Detection Event
12037 * @ctx: HDD context
12038 * @event: motion detect event
12039 *
12040 * Callback for Motion Detection Event. Re-enables Motion
12041 * Detection again upon event
12042 *
12043 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and
12044 * QDF_STATUS_E_FAILURE on failure
12045 */
12046QDF_STATUS hdd_md_host_evt_cb(void *ctx, struct sir_md_evt *event)
12047{
12048 struct hdd_adapter *adapter = NULL;
12049 struct hdd_context *hdd_ctx;
12050 QDF_STATUS status;
12051 struct sme_motion_det_en motion_det;
12052
12053 if (!ctx || !event)
12054 return QDF_STATUS_E_INVAL;
12055
12056 hdd_ctx = (struct hdd_context *)ctx;
12057 status = wlan_hdd_validate_context(hdd_ctx);
12058 if (0 != status)
12059 return QDF_STATUS_E_INVAL;
12060
12061 adapter = hdd_get_adapter_by_vdev(hdd_ctx, event->vdev_id);
12062 if (!adapter || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
12063 hdd_err("Invalid adapter or adapter has invalid magic");
12064 return QDF_STATUS_E_INVAL;
12065 }
12066
12067 hdd_debug("Motion Detection CB vdev_id=%u, status=%u",
12068 event->vdev_id, event->status);
12069
12070 if (adapter->motion_detection_mode) {
12071 motion_det.vdev_id = event->vdev_id;
12072 motion_det.enable = 1;
12073 hdd_debug("Motion Detect CB -> Enable Motion Detection again");
12074 sme_motion_det_enable(hdd_ctx->mac_handle, &motion_det);
12075 }
12076
12077 return QDF_STATUS_SUCCESS;
12078}
12079#endif /* WLAN_FEATURE_MOTION_DETECTION */
12080
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012081/**
Arun Khandavallifae92942016-08-01 13:31:08 +053012082 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012083 * @hdd_ctx: HDD context
12084 *
12085 * Register the HDD callbacks to CDS/SME.
12086 *
12087 * Return: 0 for success or Error code for failure
12088 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012089int hdd_register_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012090{
12091 QDF_STATUS status;
12092 int ret = 0;
Jeff Johnson16528362018-06-14 12:34:16 -070012093 mac_handle_t mac_handle;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012094
Dustin Brown491d54b2018-03-14 12:39:11 -070012095 hdd_enter();
Sourav Mohapatra674925f2018-04-16 11:16:58 +053012096 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
12097 hdd_err("in ftm mode, no need to register callbacks");
12098 return ret;
12099 }
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012100
Jeff Johnson16528362018-06-14 12:34:16 -070012101 mac_handle = hdd_ctx->mac_handle;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012102
Jeff Johnson16528362018-06-14 12:34:16 -070012103 sme_register_oem_data_rsp_callback(mac_handle,
12104 hdd_send_oem_data_rsp_msg);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012105
Jeff Johnson16528362018-06-14 12:34:16 -070012106 sme_register_mgmt_frame_ind_callback(mac_handle,
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +053012107 hdd_indicate_mgmt_frame);
Jeff Johnson16528362018-06-14 12:34:16 -070012108 sme_set_tsfcb(mac_handle, hdd_get_tsf_cb, hdd_ctx);
Jeff Johnson16528362018-06-14 12:34:16 -070012109 sme_stats_ext_register_callback(mac_handle,
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012110 wlan_hdd_cfg80211_stats_ext_callback);
12111
Jeff Johnson16528362018-06-14 12:34:16 -070012112 sme_ext_scan_register_callback(mac_handle,
12113 wlan_hdd_cfg80211_extscan_callback);
12114 sme_stats_ext2_register_callback(mac_handle,
lifeng66831662017-05-19 16:01:35 +080012115 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012116
Jeff Johnson16528362018-06-14 12:34:16 -070012117 sme_set_rssi_threshold_breached_cb(mac_handle,
12118 hdd_rssi_threshold_breached);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012119
Jeff Johnson16528362018-06-14 12:34:16 -070012120 sme_set_link_layer_stats_ind_cb(mac_handle,
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012121 wlan_hdd_cfg80211_link_layer_stats_callback);
12122
Jeff Johnson16528362018-06-14 12:34:16 -070012123 sme_rso_cmd_status_cb(mac_handle, wlan_hdd_rso_cmd_status_cb);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +053012124
Jeff Johnson16528362018-06-14 12:34:16 -070012125 sme_set_link_layer_ext_cb(mac_handle,
Zhang Qianca38fb12016-12-23 11:10:48 +080012126 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
Abhinav Kumar338e57d2019-02-04 17:30:10 +053012127 sme_update_hidden_ssid_status_cb(mac_handle,
12128 hdd_hidden_ssid_enable_roaming);
Zhang Qianca38fb12016-12-23 11:10:48 +080012129
Jeff Johnson16528362018-06-14 12:34:16 -070012130 status = sme_set_lost_link_info_cb(mac_handle,
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +053012131 hdd_lost_link_info_cb);
12132 /* print error and not block the startup process */
12133 if (!QDF_IS_STATUS_SUCCESS(status))
12134 hdd_err("set lost link info callback failed");
12135
Poddar, Siddarth34872782017-08-10 14:08:51 +053012136 ret = hdd_register_data_stall_detect_cb();
12137 if (ret) {
12138 hdd_err("Register data stall detect detect callback failed.");
12139 return ret;
12140 }
12141
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012142 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
12143
Jeff Johnson16528362018-06-14 12:34:16 -070012144 sme_register_set_connection_info_cb(mac_handle,
12145 hdd_set_connection_in_progress,
12146 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053012147
Jeff Johnson16528362018-06-14 12:34:16 -070012148 status = sme_congestion_register_callback(mac_handle,
12149 hdd_update_cca_info_cb);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053012150 if (!QDF_IS_STATUS_SUCCESS(status))
12151 hdd_err("set congestion callback failed");
12152
Jeff Johnson16528362018-06-14 12:34:16 -070012153 status = sme_set_bt_activity_info_cb(mac_handle,
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +053012154 hdd_bt_activity_cb);
12155 if (!QDF_IS_STATUS_SUCCESS(status))
12156 hdd_err("set bt activity info callback failed");
12157
Jeff Johnson16528362018-06-14 12:34:16 -070012158 status = sme_register_tx_queue_cb(mac_handle,
Varun Reddy Yeturu076eaa82018-01-16 12:16:14 -080012159 hdd_tx_queue_cb);
12160 if (!QDF_IS_STATUS_SUCCESS(status))
12161 hdd_err("Register tx queue callback failed");
12162
Visweswara Tanuku633976b2019-01-07 16:13:12 +053012163#ifdef WLAN_FEATURE_MOTION_DETECTION
12164 sme_set_md_host_evt_cb(mac_handle, hdd_md_host_evt_cb, (void *)hdd_ctx);
12165#endif /* WLAN_FEATURE_MOTION_DETECTION */
12166
Dustin Browne74003f2018-03-14 12:51:58 -070012167 hdd_exit();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012168
12169 return ret;
12170}
12171
12172/**
12173 * hdd_deregister_cb() - De-Register HDD callbacks.
12174 * @hdd_ctx: HDD context
12175 *
12176 * De-Register the HDD callbacks to CDS/SME.
12177 *
12178 * Return: void
12179 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012180void hdd_deregister_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012181{
12182 QDF_STATUS status;
Poddar, Siddarth34872782017-08-10 14:08:51 +053012183 int ret;
Jeff Johnson16528362018-06-14 12:34:16 -070012184 mac_handle_t mac_handle;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012185
Dustin Brown491d54b2018-03-14 12:39:11 -070012186 hdd_enter();
Sourav Mohapatra674925f2018-04-16 11:16:58 +053012187 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
12188 hdd_err("in ftm mode, no need to deregister callbacks");
12189 return;
12190 }
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012191
Jeff Johnson16528362018-06-14 12:34:16 -070012192 mac_handle = hdd_ctx->mac_handle;
12193 sme_deregister_tx_queue_cb(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012194
Jeff Johnson16528362018-06-14 12:34:16 -070012195 sme_reset_link_layer_stats_ind_cb(mac_handle);
12196 sme_reset_rssi_threshold_breached_cb(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012197
Jeff Johnson16528362018-06-14 12:34:16 -070012198 sme_stats_ext_register_callback(mac_handle,
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012199 wlan_hdd_cfg80211_stats_ext_callback);
12200
Jeff Johnson16528362018-06-14 12:34:16 -070012201 status = sme_reset_tsfcb(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012202 if (!QDF_IS_STATUS_SUCCESS(status))
12203 hdd_err("Failed to de-register tsfcb the callback:%d",
12204 status);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012205
Poddar, Siddarth34872782017-08-10 14:08:51 +053012206 ret = hdd_deregister_data_stall_detect_cb();
12207 if (ret)
12208 hdd_err("Failed to de-register data stall detect event callback");
12209
Jeff Johnson16528362018-06-14 12:34:16 -070012210 sme_deregister_oem_data_rsp_callback(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012211
Dustin Browne74003f2018-03-14 12:51:58 -070012212 hdd_exit();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012213}
12214
12215/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012216 * hdd_softap_sta_deauth() - handle deauth req from HDD
Jeff Johnson50e37e92019-03-08 11:32:25 -080012217 * @adapter: Pointer to the HDD adapter
12218 * @param: Params to the operation
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012219 *
12220 * This to take counter measure to handle deauth req from HDD
12221 *
12222 * Return: None
12223 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012224QDF_STATUS hdd_softap_sta_deauth(struct hdd_adapter *adapter,
Jeff Johnson50e37e92019-03-08 11:32:25 -080012225 struct csr_del_sta_params *param)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012226{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012227 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012228
Dustin Brown491d54b2018-03-14 12:39:11 -070012229 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012230
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012231 /* Ignore request to deauth bcmc station */
Jeff Johnson50e37e92019-03-08 11:32:25 -080012232 if (param->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012233 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012234
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012235 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012236 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Jeff Johnson50e37e92019-03-08 11:32:25 -080012237 param);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012238
Dustin Browne74003f2018-03-14 12:51:58 -070012239 hdd_exit();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012240 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012241}
12242
12243/**
12244 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
Jeff Johnson50e37e92019-03-08 11:32:25 -080012245 * @adapter: Pointer to the HDD
12246 * @param: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012247 *
12248 * This to take counter measure to handle deauth req from HDD
12249 *
12250 * Return: None
12251 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012252void hdd_softap_sta_disassoc(struct hdd_adapter *adapter,
Jeff Johnson50e37e92019-03-08 11:32:25 -080012253 struct csr_del_sta_params *param)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012254{
Dustin Brown491d54b2018-03-14 12:39:11 -070012255 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012256
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012257 /* Ignore request to disassoc bcmc station */
Jeff Johnson50e37e92019-03-08 11:32:25 -080012258 if (param->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012259 return;
12260
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012261 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Jeff Johnson50e37e92019-03-08 11:32:25 -080012262 param);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012263}
12264
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012265void wlan_hdd_disable_roaming(struct hdd_adapter *cur_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012266{
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012267 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(cur_adapter);
12268 struct hdd_adapter *adapter = NULL;
12269 struct csr_roam_profile *roam_profile;
12270 struct hdd_station_ctx *sta_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012271
Dustin Brown1dbefe62018-09-11 16:32:03 -070012272 if (!policy_mgr_is_sta_active_connection_exists(hdd_ctx->psoc)) {
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012273 hdd_debug("No active sta session");
12274 return;
12275 }
12276
12277 hdd_for_each_adapter(hdd_ctx, adapter) {
12278 roam_profile = hdd_roam_profile(adapter);
12279 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
12280
Jeff Johnson5a6fc962019-02-04 14:20:25 -080012281 if (cur_adapter->vdev_id != adapter->vdev_id &&
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012282 adapter->device_mode == QDF_STA_MODE &&
12283 hdd_conn_is_connected(sta_ctx)) {
Jeff Johnson5a6fc962019-02-04 14:20:25 -080012284 hdd_debug("%d Disable roaming", adapter->vdev_id);
Jeff Johnson16528362018-06-14 12:34:16 -070012285 sme_stop_roaming(hdd_ctx->mac_handle,
Jeff Johnson5a6fc962019-02-04 14:20:25 -080012286 adapter->vdev_id,
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012287 ecsr_driver_disabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012288 }
12289 }
12290}
12291
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012292void wlan_hdd_enable_roaming(struct hdd_adapter *cur_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012293{
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012294 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(cur_adapter);
12295 struct hdd_adapter *adapter = NULL;
12296 struct csr_roam_profile *roam_profile;
12297 struct hdd_station_ctx *sta_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012298
Dustin Brown1dbefe62018-09-11 16:32:03 -070012299 if (!policy_mgr_is_sta_active_connection_exists(hdd_ctx->psoc)) {
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012300 hdd_debug("No active sta session");
12301 return;
12302 }
12303
12304 hdd_for_each_adapter(hdd_ctx, adapter) {
12305 roam_profile = hdd_roam_profile(adapter);
12306 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
12307
Jeff Johnson5a6fc962019-02-04 14:20:25 -080012308 if (cur_adapter->vdev_id != adapter->vdev_id &&
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012309 adapter->device_mode == QDF_STA_MODE &&
12310 hdd_conn_is_connected(sta_ctx)) {
Jeff Johnson5a6fc962019-02-04 14:20:25 -080012311 hdd_debug("%d Enable roaming", adapter->vdev_id);
Jeff Johnson16528362018-06-14 12:34:16 -070012312 sme_start_roaming(hdd_ctx->mac_handle,
Jeff Johnson5a6fc962019-02-04 14:20:25 -080012313 adapter->vdev_id,
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012314 REASON_DRIVER_ENABLED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012315 }
12316 }
12317}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012318
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053012319/**
12320 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
12321 * @skb: sk buffer pointer
12322 *
12323 * Sends the bcast message to SVC multicast group with generic nl socket
12324 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
12325 *
12326 * Return: None
12327 */
12328static void nl_srv_bcast_svc(struct sk_buff *skb)
12329{
12330#ifdef CNSS_GENL
12331 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
12332#else
12333 nl_srv_bcast(skb);
12334#endif
12335}
12336
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012337void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012338{
12339 struct sk_buff *skb;
12340 struct nlmsghdr *nlh;
12341 tAniMsgHdr *ani_hdr;
12342 void *nl_data = NULL;
12343 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012344 struct radio_index_tlv *radio_info;
12345 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012346
12347 if (in_interrupt() || irqs_disabled() || in_atomic())
12348 flags = GFP_ATOMIC;
12349
12350 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
12351
Jeff Johnsond36fa332019-03-18 13:42:25 -070012352 if (!skb)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012353 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012354
12355 nlh = (struct nlmsghdr *)skb->data;
12356 nlh->nlmsg_pid = 0; /* from kernel */
12357 nlh->nlmsg_flags = 0;
12358 nlh->nlmsg_seq = 0;
12359 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
12360
12361 ani_hdr = NLMSG_DATA(nlh);
12362 ani_hdr->type = type;
12363
12364 switch (type) {
12365 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053012366 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012367 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012368 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070012369 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012370 ani_hdr->length = 0;
12371 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012372 break;
12373 case WLAN_SVC_WLAN_STATUS_IND:
12374 case WLAN_SVC_WLAN_VERSION_IND:
12375 case WLAN_SVC_DFS_CAC_START_IND:
12376 case WLAN_SVC_DFS_CAC_END_IND:
12377 case WLAN_SVC_DFS_RADAR_DETECT_IND:
12378 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
12379 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080012380 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053012381 case WLAN_SVC_RPS_ENABLE_IND:
Orhan K AKYILDIZe7445a22017-01-19 21:21:47 -080012382 case WLAN_SVC_CORE_MINFREQ:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012383 ani_hdr->length = len;
12384 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
12385 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
12386 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012387 break;
12388
12389 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070012390 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012391 type);
12392 kfree_skb(skb);
12393 return;
12394 }
12395
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012396 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080012397 * Add radio index at the end of the svc event in TLV format
12398 * to maintain the backward compatibility with userspace
12399 * applications.
12400 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012401
12402 tlv_len = 0;
12403
12404 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
12405 < WLAN_NL_MAX_PAYLOAD) {
12406 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
12407 sizeof(*ani_hdr) + len);
12408 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
12409 radio_info->length = (unsigned short) sizeof(radio_info->radio);
12410 radio_info->radio = radio;
12411 tlv_len = sizeof(*radio_info);
Dustin Browna2868622018-03-20 11:38:14 -070012412 hdd_debug("Added radio index tlv - radio index %d",
12413 radio_info->radio);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012414 }
12415
12416 nlh->nlmsg_len += tlv_len;
12417 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
12418
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053012419 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012420}
12421
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012422#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
12423void wlan_hdd_auto_shutdown_cb(void)
12424{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012425 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012426
12427 if (!hdd_ctx)
12428 return;
12429
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012430 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012431 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
12432 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012433}
12434
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012435void wlan_hdd_auto_shutdown_enable(struct hdd_context *hdd_ctx, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012436{
Jeff Johnson9d295242017-08-29 14:39:48 -070012437 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012438 bool ap_connected = false, sta_connected = false;
Jeff Johnson16528362018-06-14 12:34:16 -070012439 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012440
Jeff Johnson16528362018-06-14 12:34:16 -070012441 mac_handle = hdd_ctx->mac_handle;
12442 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012443 return;
12444
Dundi Raviteja8e338282018-09-25 17:16:04 +053012445 if (hdd_ctx->config->wlan_auto_shutdown == 0)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012446 return;
12447
12448 if (enable == false) {
Jeff Johnson16528362018-06-14 12:34:16 -070012449 if (sme_set_auto_shutdown_timer(mac_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012450 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012451 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012452 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012453 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070012454 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012455 return;
12456 }
12457
12458 /* To enable shutdown timer check conncurrency */
Dustin Brown1dbefe62018-09-11 16:32:03 -070012459 if (policy_mgr_concurrent_open_sessions_running(hdd_ctx->psoc)) {
Dustin Brown920397d2017-12-13 16:27:50 -080012460 hdd_for_each_adapter(hdd_ctx, adapter) {
12461 if (adapter->device_mode == QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012462 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
Jeff Johnsone7951512019-02-27 10:02:51 -080012463 conn_info.conn_state ==
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012464 eConnectionState_Associated) {
12465 sta_connected = true;
12466 break;
12467 }
12468 }
Dustin Brown920397d2017-12-13 16:27:50 -080012469
12470 if (adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012471 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
Jeff Johnson136c51b2017-10-27 20:02:41 -070012472 ap_active == true) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012473 ap_connected = true;
12474 break;
12475 }
12476 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012477 }
12478 }
12479
12480 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012481 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012482 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012483 }
Jeff Johnson68755312017-02-10 11:46:55 -080012484
Jeff Johnson16528362018-06-14 12:34:16 -070012485 if (sme_set_auto_shutdown_timer(mac_handle,
Dundi Raviteja8e338282018-09-25 17:16:04 +053012486 hdd_ctx->config->wlan_auto_shutdown)
Jeff Johnson68755312017-02-10 11:46:55 -080012487 != QDF_STATUS_SUCCESS)
12488 hdd_err("Failed to start wlan auto shutdown timer");
12489 else
Dustin Brown5e89ef82018-03-14 11:50:23 -070012490 hdd_info("Auto Shutdown timer for %d seconds enabled",
Dundi Raviteja8e338282018-09-25 17:16:04 +053012491 hdd_ctx->config->wlan_auto_shutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012492}
12493#endif
12494
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070012495struct hdd_adapter *
12496hdd_get_con_sap_adapter(struct hdd_adapter *this_sap_adapter,
12497 bool check_start_bss)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012498{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012499 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070012500 struct hdd_adapter *adapter, *con_sap_adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012501
12502 con_sap_adapter = NULL;
12503
Dustin Brown920397d2017-12-13 16:27:50 -080012504 hdd_for_each_adapter(hdd_ctx, adapter) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080012505 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
12506 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012507 adapter != this_sap_adapter) {
12508 if (check_start_bss) {
12509 if (test_bit(SOFTAP_BSS_STARTED,
12510 &adapter->event_flags)) {
12511 con_sap_adapter = adapter;
12512 break;
12513 }
12514 } else {
12515 con_sap_adapter = adapter;
12516 break;
12517 }
12518 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012519 }
12520
12521 return con_sap_adapter;
12522}
12523
12524#ifdef MSM_PLATFORM
Jeff Johnson9d295242017-08-29 14:39:48 -070012525static inline bool hdd_adapter_is_sta(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012526{
Dustin Brown5ec6b552017-03-31 12:11:40 -070012527 return adapter->device_mode == QDF_STA_MODE ||
12528 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012529}
12530
Jeff Johnson9d295242017-08-29 14:39:48 -070012531static inline bool hdd_adapter_is_ap(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012532{
Dustin Brown5ec6b552017-03-31 12:11:40 -070012533 return adapter->device_mode == QDF_SAP_MODE ||
12534 adapter->device_mode == QDF_P2P_GO_MODE;
12535}
12536
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012537static bool hdd_any_adapter_is_assoc(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012538{
Dustin Brown920397d2017-12-13 16:27:50 -080012539 struct hdd_adapter *adapter;
Dustin Brown5ec6b552017-03-31 12:11:40 -070012540
Dustin Brown920397d2017-12-13 16:27:50 -080012541 hdd_for_each_adapter(hdd_ctx, adapter) {
12542 if (hdd_adapter_is_sta(adapter) &&
Dustin Brown5ec6b552017-03-31 12:11:40 -070012543 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
Jeff Johnsone7951512019-02-27 10:02:51 -080012544 conn_info.conn_state == eConnectionState_Associated) {
Dustin Brown5ec6b552017-03-31 12:11:40 -070012545 return true;
12546 }
12547
Dustin Brown920397d2017-12-13 16:27:50 -080012548 if (hdd_adapter_is_ap(adapter) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -070012549 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active) {
Dustin Brown5ec6b552017-03-31 12:11:40 -070012550 return true;
12551 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070012552 }
12553
12554 return false;
12555}
12556
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012557static void __hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012558{
Dustin Browna20bad52019-03-05 12:03:30 -080012559 qdf_periodic_work_start(&hdd_ctx->bus_bw_work,
12560 hdd_ctx->config->bus_bw_compute_interval);
Dustin Brown5ec6b552017-03-31 12:11:40 -070012561}
12562
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012563void hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012564{
Dustin Brown491d54b2018-03-14 12:39:11 -070012565 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012566
Dustin Brown5ec6b552017-03-31 12:11:40 -070012567 __hdd_bus_bw_compute_timer_start(hdd_ctx);
12568
Dustin Browne74003f2018-03-14 12:51:58 -070012569 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012570}
12571
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012572void hdd_bus_bw_compute_timer_try_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012573{
Dustin Brown491d54b2018-03-14 12:39:11 -070012574 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012575
Dustin Brown5ec6b552017-03-31 12:11:40 -070012576 if (hdd_any_adapter_is_assoc(hdd_ctx))
12577 __hdd_bus_bw_compute_timer_start(hdd_ctx);
12578
Dustin Browne74003f2018-03-14 12:51:58 -070012579 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012580}
12581
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012582static void __hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012583{
Dustin Browna20bad52019-03-05 12:03:30 -080012584 if (!qdf_periodic_work_stop_sync(&hdd_ctx->bus_bw_work))
12585 return;
12586
Dustin Brown07901ec2018-09-07 11:02:41 -070012587 ucfg_ipa_set_perf_level(hdd_ctx->pdev, 0, 0);
Dustin Brown5ec6b552017-03-31 12:11:40 -070012588 hdd_reset_tcp_delack(hdd_ctx);
12589}
12590
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012591void hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012592{
Dustin Brown491d54b2018-03-14 12:39:11 -070012593 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012594
Dustin Brown5ec6b552017-03-31 12:11:40 -070012595 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
12596
Dustin Browne74003f2018-03-14 12:51:58 -070012597 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012598}
12599
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012600void hdd_bus_bw_compute_timer_try_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012601{
Dustin Brown491d54b2018-03-14 12:39:11 -070012602 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012603
Dustin Brown5ec6b552017-03-31 12:11:40 -070012604 if (!hdd_any_adapter_is_assoc(hdd_ctx))
12605 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
12606
Dustin Browne74003f2018-03-14 12:51:58 -070012607 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012608}
12609#endif
12610
12611/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012612 * wlan_hdd_stop_sap() - This function stops bss of SAP.
12613 * @ap_adapter: SAP adapter
12614 *
12615 * This function will process the stopping of sap adapter.
12616 *
12617 * Return: None
12618 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012619void wlan_hdd_stop_sap(struct hdd_adapter *ap_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012620{
Jeff Johnson87251032017-08-29 13:31:11 -070012621 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070012622 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053012623 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012624 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012625
Jeff Johnsond36fa332019-03-18 13:42:25 -070012626 if (!ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012627 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012628 return;
12629 }
12630
12631 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
12632 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053012633 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012634 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053012635
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012636 mutex_lock(&hdd_ctx->sap_lock);
12637 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080012638 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012639 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012640 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053012641 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012642 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070012643 sap_context)) {
Nachiket Kukade0396b732017-11-14 16:35:16 +053012644 qdf_status = qdf_wait_for_event_completion(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080012645 qdf_stop_bss_event,
Abhishek Singhd1f21c72019-01-21 15:16:34 +053012646 SME_CMD_STOP_BSS_TIMEOUT);
Anurag Chouhance0dc992016-02-16 18:18:03 +053012647 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012648 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070012649 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012650 return;
12651 }
12652 }
12653 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Dustin Brown1dbefe62018-09-11 16:32:03 -070012654 policy_mgr_decr_session_set_pcl(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012655 ap_adapter->device_mode,
Jeff Johnson5a6fc962019-02-04 14:20:25 -080012656 ap_adapter->vdev_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070012657 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053012658 false);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012659 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012660 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012661 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012662 }
12663 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012664}
12665
12666/**
12667 * wlan_hdd_start_sap() - this function starts bss of SAP.
12668 * @ap_adapter: SAP adapter
12669 *
12670 * This function will process the starting of sap adapter.
12671 *
12672 * Return: None
12673 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012674void wlan_hdd_start_sap(struct hdd_adapter *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012675{
Jeff Johnson87251032017-08-29 13:31:11 -070012676 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070012677 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053012678 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012679 struct hdd_context *hdd_ctx;
Jeff Johnson8f8ceb92019-03-24 08:16:55 -070012680 struct sap_config *sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012681
Jeff Johnsond36fa332019-03-18 13:42:25 -070012682 if (!ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012683 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012684 return;
12685 }
12686
Krunal Soni9b04c9b2016-03-10 13:08:05 -080012687 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070012688 hdd_err("SoftAp role has not been enabled");
12689 return;
12690 }
12691
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012692 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
12693 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
12694 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Jeff Johnsonb9424862017-10-30 08:49:35 -070012695 sap_config = &ap_adapter->session.ap.sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012696
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012697 mutex_lock(&hdd_ctx->sap_lock);
12698 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
12699 goto end;
12700
12701 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012702 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012703 goto end;
12704 }
Dustin Brown07901ec2018-09-07 11:02:41 -070012705 wlan_reg_set_channel_params(hdd_ctx->pdev,
Abhinav Kumar6f694482018-09-04 16:07:39 +053012706 hdd_ap_ctx->sap_config.channel, 0,
12707 &hdd_ap_ctx->sap_config.ch_params);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012708
Wei Song2f76f642016-11-18 16:32:53 +080012709 qdf_event_reset(&hostapd_state->qdf_event);
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070012710 if (wlansap_start_bss(hdd_ap_ctx->sap_context, hdd_hostapd_sap_event_cb,
Jeff Johnson91df29d2017-10-27 19:29:50 -070012711 &hdd_ap_ctx->sap_config,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012712 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012713 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012714 goto end;
12715
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012716 hdd_debug("Waiting for SAP to start");
Nachiket Kukade0396b732017-11-14 16:35:16 +053012717 qdf_status = qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Abhishek Singhd1f21c72019-01-21 15:16:34 +053012718 SME_CMD_START_BSS_TIMEOUT);
Anurag Chouhance0dc992016-02-16 18:18:03 +053012719 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012720 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012721 goto end;
12722 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070012723 hdd_info("SAP Start Success");
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053012724 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012725 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053012726 if (hostapd_state->bss_state == BSS_START) {
Dustin Brown1dbefe62018-09-11 16:32:03 -070012727 policy_mgr_incr_active_session(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012728 ap_adapter->device_mode,
Jeff Johnson5a6fc962019-02-04 14:20:25 -080012729 ap_adapter->vdev_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070012730 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053012731 true);
12732 }
Sourav Mohapatra9bc67112017-11-08 09:36:11 +053012733 mutex_unlock(&hdd_ctx->sap_lock);
12734
12735 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012736end:
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053012737 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012738 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070012739 /* SAP context and beacon cleanup will happen during driver unload
12740 * in hdd_stop_adapter
12741 */
12742 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
12743
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012744}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012745
12746/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012747 * hdd_get_fw_version() - Get FW version
12748 * @hdd_ctx: pointer to HDD context.
12749 * @major_spid: FW version - major spid.
12750 * @minor_spid: FW version - minor spid
12751 * @ssid: FW version - ssid
12752 * @crmid: FW version - crmid
12753 *
12754 * This function is called to get the firmware build version stored
12755 * as part of the HDD context
12756 *
12757 * Return: None
12758 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012759void hdd_get_fw_version(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012760 uint32_t *major_spid, uint32_t *minor_spid,
12761 uint32_t *siid, uint32_t *crmid)
12762{
12763 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
12764 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
12765 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
12766 *crmid = hdd_ctx->target_fw_version & 0x7fff;
12767}
12768
12769#ifdef QCA_CONFIG_SMP
12770/**
12771 * wlan_hdd_get_cpu() - get cpu_index
12772 *
12773 * Return: cpu_index
12774 */
12775int wlan_hdd_get_cpu(void)
12776{
12777 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012778
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012779 put_cpu();
12780 return cpu_index;
12781}
12782#endif
12783
12784/**
12785 * hdd_get_fwpath() - get framework path
12786 *
12787 * This function is used to get the string written by
12788 * userspace to start the wlan driver
12789 *
12790 * Return: string
12791 */
12792const char *hdd_get_fwpath(void)
12793{
12794 return fwpath.string;
12795}
12796
Dustin Brown94ce20f2018-09-04 13:11:38 -070012797static inline int hdd_state_query_cb(void)
12798{
12799 return !!wlan_hdd_validate_context(cds_get_context(QDF_MODULE_ID_HDD));
12800}
12801
Dustin Brown265e82b2019-03-18 11:07:32 -070012802static int __hdd_op_protect_cb(void **out_sync, const char *func)
12803{
12804 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12805
12806 if (!hdd_ctx)
12807 return -EAGAIN;
12808
12809 return __osif_psoc_sync_op_start(hdd_ctx->parent_dev,
12810 (struct osif_psoc_sync **)out_sync,
12811 func);
12812}
12813
12814static void __hdd_op_unprotect_cb(void *sync, const char *func)
12815{
12816 __osif_psoc_sync_op_stop(sync, func);
12817}
12818
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012819/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012820 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012821 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012822 * This function initilizes CDS global context with the help of cds_init. This
12823 * has to be the first function called after probe to get a valid global
12824 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012825 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012826 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012827 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012828int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012829{
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070012830 QDF_STATUS status;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012831
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070012832 status = cds_init();
wadesongae4ffd12017-10-24 16:45:54 +080012833 if (QDF_IS_STATUS_ERROR(status)) {
12834 hdd_err("Failed to allocate CDS context");
Dustin Brownc1d81af2019-03-01 13:43:43 -080012835 return -ENOMEM;
wadesongae4ffd12017-10-24 16:45:54 +080012836 }
Dustin Brownc1d81af2019-03-01 13:43:43 -080012837
Dustin Brown265e82b2019-03-18 11:07:32 -070012838 qdf_op_callbacks_register(__hdd_op_protect_cb, __hdd_op_unprotect_cb);
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053012839
12840 wlan_init_bug_report_lock();
12841
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012842#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
12843 wlan_logging_sock_init_svc();
12844#endif
12845
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012846 hdd_trace_init();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053012847 hdd_register_debug_callback();
Qiwei Caiad9b01c2018-07-09 17:21:31 +080012848 wlan_roam_debug_init();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012849
Dustin Brownfe50cef2018-12-10 10:42:37 -080012850 return 0;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012851}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012852
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012853/**
12854 * hdd_deinit() - Deinitialize Driver
12855 *
12856 * This function frees CDS global context with the help of cds_deinit. This
12857 * has to be the last function call in remove callback to free the global
12858 * context.
12859 */
12860void hdd_deinit(void)
12861{
Qiwei Caiad9b01c2018-07-09 17:21:31 +080012862 wlan_roam_debug_deinit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012863
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012864#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
12865 wlan_logging_sock_deinit_svc();
12866#endif
Qiwei Caiad9b01c2018-07-09 17:21:31 +080012867
12868 wlan_destroy_bug_report_lock();
Dustin Brown265e82b2019-03-18 11:07:32 -070012869 qdf_op_callbacks_register(NULL, NULL);
Qiwei Caiad9b01c2018-07-09 17:21:31 +080012870 cds_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012871}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012872
Yue Ma6e7b1a02017-04-03 14:17:46 -070012873#ifdef QCA_WIFI_NAPIER_EMULATION
12874#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
12875#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012876#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070012877#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012878
Sachin Ahujadddd2632017-03-07 19:07:24 +053012879static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
12880 struct file *file)
12881{
12882 return 0;
12883}
12884
12885static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
12886 const char __user *user_buf,
12887 size_t count,
12888 loff_t *f_pos)
12889{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012890 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053012891 static const char wlan_off_str[] = "OFF";
12892 static const char wlan_on_str[] = "ON";
12893 int ret;
12894 unsigned long rc;
12895
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012896 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053012897 pr_err("Failed to read buffer\n");
12898 return -EINVAL;
12899 }
12900
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012901 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053012902 pr_debug("Wifi turning off from UI\n");
12903 goto exit;
12904 }
12905
Srinivas Girigowdad2412882018-09-07 15:42:04 -070012906 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) == 0)
Sachin Ahuja16904db2017-12-13 19:56:57 +053012907 pr_info("Wifi Turning On from UI\n");
Sachin Ahuja16904db2017-12-13 19:56:57 +053012908
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012909 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053012910 pr_err("Invalid value received from framework");
12911 goto exit;
12912 }
12913
12914 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053012915 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053012916 rc = wait_for_completion_timeout(&wlan_start_comp,
12917 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
12918 if (!rc) {
Srinivas Girigowda09625b02018-09-10 15:28:09 -070012919 hdd_alert("Timed-out!!");
Sachin Ahujadddd2632017-03-07 19:07:24 +053012920 ret = -EINVAL;
Sachin Ahujadddd2632017-03-07 19:07:24 +053012921 return ret;
12922 }
12923
12924 hdd_start_complete(0);
12925 }
12926
12927exit:
12928 return count;
12929}
12930
12931
12932const struct file_operations wlan_hdd_state_fops = {
12933 .owner = THIS_MODULE,
12934 .open = wlan_hdd_state_ctrl_param_open,
12935 .write = wlan_hdd_state_ctrl_param_write,
12936};
12937
12938static int wlan_hdd_state_ctrl_param_create(void)
12939{
12940 unsigned int wlan_hdd_state_major = 0;
12941 int ret;
12942 struct device *dev;
12943
12944 device = MKDEV(wlan_hdd_state_major, 0);
12945
12946 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
12947 if (ret) {
12948 pr_err("Failed to register qcwlanstate");
12949 goto dev_alloc_err;
12950 }
12951 wlan_hdd_state_major = MAJOR(device);
12952
12953 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
12954 if (IS_ERR(class)) {
12955 pr_err("wlan_hdd_state class_create error");
12956 goto class_err;
12957 }
12958
12959 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
12960 if (IS_ERR(dev)) {
12961 pr_err("wlan_hdd_statedevice_create error");
12962 goto err_class_destroy;
12963 }
12964
12965 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
12966 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
12967 if (ret) {
12968 pr_err("Failed to add cdev error");
12969 goto cdev_add_err;
12970 }
12971
12972 pr_info("wlan_hdd_state %s major(%d) initialized",
12973 WLAN_MODULE_NAME, wlan_hdd_state_major);
12974
12975 return 0;
12976
12977cdev_add_err:
12978 device_destroy(class, device);
12979err_class_destroy:
12980 class_destroy(class);
12981class_err:
12982 unregister_chrdev_region(device, dev_num);
12983dev_alloc_err:
12984 return -ENODEV;
12985}
12986
12987static void wlan_hdd_state_ctrl_param_destroy(void)
12988{
12989 cdev_del(&wlan_hdd_state_cdev);
12990 device_destroy(class, device);
12991 class_destroy(class);
12992 unregister_chrdev_region(device, dev_num);
12993
12994 pr_info("Device node unregistered");
12995}
12996
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012997/**
Dustin Brownd585cb32018-09-12 17:12:23 -070012998 * hdd_component_init() - Initialize all components
Mukul Sharmad75a6672017-06-22 15:40:53 +053012999 *
Dustin Brownd585cb32018-09-12 17:12:23 -070013000 * Return: QDF_STATUS
Mukul Sharmad75a6672017-06-22 15:40:53 +053013001 */
Dustin Brownd585cb32018-09-12 17:12:23 -070013002static QDF_STATUS hdd_component_init(void)
Mukul Sharmad75a6672017-06-22 15:40:53 +053013003{
Dustin Brownd585cb32018-09-12 17:12:23 -070013004 QDF_STATUS status;
13005
13006 /* initialize converged components */
Arif Hussain49698112018-07-31 00:32:50 -070013007 status = target_if_init(wma_get_psoc_from_scn_handle);
Dustin Brownd585cb32018-09-12 17:12:23 -070013008 if (QDF_IS_STATUS_ERROR(status))
13009 return status;
13010
Abhishek Singhd5cf22d2019-01-08 19:51:09 +053013011 status = ucfg_mlme_global_init();
Arif Hussain49698112018-07-31 00:32:50 -070013012 if (QDF_IS_STATUS_ERROR(status))
13013 goto target_if_deinit;
13014
Abhishek Singhd5cf22d2019-01-08 19:51:09 +053013015 status = dispatcher_init();
13016 if (QDF_IS_STATUS_ERROR(status))
13017 goto mlme_global_deinit;
13018
Dustin Brownd585cb32018-09-12 17:12:23 -070013019 /* initialize non-converged components */
13020 status = ucfg_mlme_init();
13021 if (QDF_IS_STATUS_ERROR(status))
13022 goto dispatcher_deinit;
13023
13024 status = ucfg_fwol_init();
13025 if (QDF_IS_STATUS_ERROR(status))
13026 goto mlme_deinit;
13027
13028 status = disa_init();
13029 if (QDF_IS_STATUS_ERROR(status))
13030 goto fwol_deinit;
13031
13032 status = pmo_init();
13033 if (QDF_IS_STATUS_ERROR(status))
13034 goto disa_deinit;
13035
13036 status = ucfg_ocb_init();
13037 if (QDF_IS_STATUS_ERROR(status))
13038 goto pmo_deinit;
13039
13040 status = ipa_init();
13041 if (QDF_IS_STATUS_ERROR(status))
13042 goto ocb_deinit;
13043
13044 status = ucfg_action_oui_init();
13045 if (QDF_IS_STATUS_ERROR(status))
13046 goto ipa_deinit;
13047
Nachiket Kukade63bb63d2018-11-21 14:42:14 +053013048 status = nan_init();
13049 if (QDF_IS_STATUS_ERROR(status))
13050 goto action_oui_deinit;
13051
Wu Gao637d58a2018-12-08 10:37:34 +080013052 status = ucfg_p2p_init();
13053 if (QDF_IS_STATUS_ERROR(status))
13054 goto nan_deinit;
13055
Wu Gaod6b5e402018-12-03 22:09:24 +080013056 status = policy_mgr_init();
13057 if (QDF_IS_STATUS_ERROR(status))
13058 goto p2p_deinit;
13059
Wu Gao5f793402018-12-08 11:04:00 +080013060 status = ucfg_tdls_init();
13061 if (QDF_IS_STATUS_ERROR(status))
13062 goto policy_deinit;
13063
Dustin Brownd585cb32018-09-12 17:12:23 -070013064 return QDF_STATUS_SUCCESS;
13065
Wu Gao5f793402018-12-08 11:04:00 +080013066policy_deinit:
13067 policy_mgr_deinit();
Wu Gaod6b5e402018-12-03 22:09:24 +080013068p2p_deinit:
13069 ucfg_p2p_deinit();
Wu Gao637d58a2018-12-08 10:37:34 +080013070nan_deinit:
13071 nan_deinit();
Nachiket Kukade63bb63d2018-11-21 14:42:14 +053013072action_oui_deinit:
13073 ucfg_action_oui_deinit();
Dustin Brownd585cb32018-09-12 17:12:23 -070013074ipa_deinit:
13075 ipa_deinit();
13076ocb_deinit:
13077 ucfg_ocb_deinit();
13078pmo_deinit:
13079 pmo_deinit();
13080disa_deinit:
13081 disa_deinit();
13082fwol_deinit:
13083 ucfg_fwol_deinit();
13084mlme_deinit:
13085 ucfg_mlme_deinit();
13086dispatcher_deinit:
13087 dispatcher_deinit();
Abhishek Singhd5cf22d2019-01-08 19:51:09 +053013088mlme_global_deinit:
13089 ucfg_mlme_global_deinit();
Arif Hussain49698112018-07-31 00:32:50 -070013090target_if_deinit:
13091 target_if_deinit();
Dustin Brownd585cb32018-09-12 17:12:23 -070013092
13093 return status;
Mukul Sharmad75a6672017-06-22 15:40:53 +053013094}
13095
13096/**
Dustin Brownd585cb32018-09-12 17:12:23 -070013097 * hdd_component_deinit() - Deinitialize all components
Mukul Sharmad75a6672017-06-22 15:40:53 +053013098 *
13099 * Return: None
13100 */
Dustin Brownd585cb32018-09-12 17:12:23 -070013101static void hdd_component_deinit(void)
Mukul Sharmad75a6672017-06-22 15:40:53 +053013102{
Dustin Brownd585cb32018-09-12 17:12:23 -070013103 /* deinitialize non-converged components */
Wu Gao5f793402018-12-08 11:04:00 +080013104 ucfg_tdls_deinit();
Wu Gaod6b5e402018-12-03 22:09:24 +080013105 policy_mgr_deinit();
Wu Gao637d58a2018-12-08 10:37:34 +080013106 ucfg_p2p_deinit();
Nachiket Kukade63bb63d2018-11-21 14:42:14 +053013107 nan_deinit();
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053013108 ucfg_action_oui_deinit();
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +053013109 ipa_deinit();
Zhang Qian47e22ce2018-01-04 15:38:38 +080013110 ucfg_ocb_deinit();
Mukul Sharmad75a6672017-06-22 15:40:53 +053013111 pmo_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053013112 disa_deinit();
Sourav Mohapatra113685f2018-08-29 14:21:55 +053013113 ucfg_fwol_deinit();
Vignesh Viswanathana0921c42018-09-04 19:03:35 +053013114 ucfg_mlme_deinit();
Dustin Brownd585cb32018-09-12 17:12:23 -070013115
13116 /* deinitialize converged components */
13117 dispatcher_deinit();
Abhishek Singhd5cf22d2019-01-08 19:51:09 +053013118 ucfg_mlme_global_deinit();
Arif Hussain49698112018-07-31 00:32:50 -070013119 target_if_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053013120}
13121
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +053013122QDF_STATUS hdd_component_psoc_open(struct wlan_objmgr_psoc *psoc)
13123{
Sourav Mohapatra113685f2018-08-29 14:21:55 +053013124 QDF_STATUS status;
13125
13126 status = ucfg_mlme_psoc_open(psoc);
13127 if (QDF_IS_STATUS_ERROR(status))
13128 return status;
13129
13130 status = ucfg_fwol_psoc_open(psoc);
13131 if (QDF_IS_STATUS_ERROR(status))
Wu Gao66454f12018-09-26 19:55:41 +080013132 goto err_fwol;
13133
13134 status = ucfg_pmo_psoc_open(psoc);
13135 if (QDF_IS_STATUS_ERROR(status))
13136 goto err_pmo;
Sourav Mohapatra113685f2018-08-29 14:21:55 +053013137
Krunal Sonie9c12f52018-10-04 11:45:42 -070013138 status = ucfg_policy_mgr_psoc_open(psoc);
13139 if (QDF_IS_STATUS_ERROR(status))
13140 goto err_plcy_mgr;
13141
Wu Gao637d58a2018-12-08 10:37:34 +080013142 status = ucfg_p2p_psoc_open(psoc);
13143 if (QDF_IS_STATUS_ERROR(status))
13144 goto err_p2p;
Wu Gao5f793402018-12-08 11:04:00 +080013145
13146 status = ucfg_tdls_psoc_open(psoc);
13147 if (QDF_IS_STATUS_ERROR(status))
13148 goto err_tdls;
13149
Sourav Mohapatra113685f2018-08-29 14:21:55 +053013150 return status;
13151
Wu Gao5f793402018-12-08 11:04:00 +080013152err_tdls:
13153 ucfg_tdls_psoc_close(psoc);
Wu Gao637d58a2018-12-08 10:37:34 +080013154err_p2p:
13155 ucfg_p2p_psoc_close(psoc);
Krunal Sonie9c12f52018-10-04 11:45:42 -070013156err_plcy_mgr:
13157 ucfg_pmo_psoc_close(psoc);
Wu Gao66454f12018-09-26 19:55:41 +080013158err_pmo:
13159 ucfg_fwol_psoc_close(psoc);
13160err_fwol:
Sourav Mohapatra113685f2018-08-29 14:21:55 +053013161 ucfg_mlme_psoc_close(psoc);
Krunal Sonie9c12f52018-10-04 11:45:42 -070013162
Sourav Mohapatra113685f2018-08-29 14:21:55 +053013163 return status;
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +053013164}
13165
13166void hdd_component_psoc_close(struct wlan_objmgr_psoc *psoc)
13167{
Wu Gao5f793402018-12-08 11:04:00 +080013168 ucfg_tdls_psoc_close(psoc);
Wu Gao637d58a2018-12-08 10:37:34 +080013169 ucfg_p2p_psoc_close(psoc);
Krunal Sonie9c12f52018-10-04 11:45:42 -070013170 ucfg_policy_mgr_psoc_close(psoc);
Wu Gao66454f12018-09-26 19:55:41 +080013171 ucfg_pmo_psoc_close(psoc);
Sourav Mohapatra113685f2018-08-29 14:21:55 +053013172 ucfg_fwol_psoc_close(psoc);
Vignesh Viswanathana0921c42018-09-04 19:03:35 +053013173 ucfg_mlme_psoc_close(psoc);
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +053013174}
13175
Nachiket Kukade98f562a2017-12-15 12:18:07 +053013176void hdd_component_psoc_enable(struct wlan_objmgr_psoc *psoc)
13177{
Zhang Qian47e22ce2018-01-04 15:38:38 +080013178 ocb_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053013179 disa_psoc_enable(psoc);
Nachiket Kukade63bb63d2018-11-21 14:42:14 +053013180 nan_psoc_enable(psoc);
Wu Gao637d58a2018-12-08 10:37:34 +080013181 p2p_psoc_enable(psoc);
Wu Gaod6b5e402018-12-03 22:09:24 +080013182 policy_mgr_psoc_enable(psoc);
Wu Gaoa67c3802018-12-27 12:07:52 +080013183 ucfg_tdls_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053013184}
13185
13186void hdd_component_psoc_disable(struct wlan_objmgr_psoc *psoc)
13187{
Wu Gaoa67c3802018-12-27 12:07:52 +080013188 ucfg_tdls_psoc_disable(psoc);
Wu Gaod6b5e402018-12-03 22:09:24 +080013189 policy_mgr_psoc_disable(psoc);
Wu Gao637d58a2018-12-08 10:37:34 +080013190 p2p_psoc_disable(psoc);
Nachiket Kukade63bb63d2018-11-21 14:42:14 +053013191 nan_psoc_disable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053013192 disa_psoc_disable(psoc);
Zhang Qian47e22ce2018-01-04 15:38:38 +080013193 ocb_psoc_disable(psoc);
Mukul Sharmad75a6672017-06-22 15:40:53 +053013194}
13195
Sandeep Puligillab7beb472018-08-13 22:54:20 -070013196QDF_STATUS hdd_component_pdev_open(struct wlan_objmgr_pdev *pdev)
13197{
13198 return ucfg_mlme_pdev_open(pdev);
13199}
13200
13201void hdd_component_pdev_close(struct wlan_objmgr_pdev *pdev)
13202{
13203 ucfg_mlme_pdev_close(pdev);
13204}
13205
Dustin Browna2a39dc2018-09-17 15:29:59 -070013206static QDF_STATUS hdd_qdf_print_init(void)
13207{
13208 QDF_STATUS status;
13209 int qdf_print_idx;
13210
13211 status = qdf_print_setup();
13212 if (QDF_IS_STATUS_ERROR(status)) {
13213 pr_err("Failed qdf_print_setup; status:%u\n", status);
13214 return status;
13215 }
13216
13217 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
13218 if (qdf_print_idx < 0) {
13219 pr_err("Failed to register for qdf_print_ctrl\n");
13220 return QDF_STATUS_E_FAILURE;
13221 }
13222
13223 qdf_set_pidx(qdf_print_idx);
13224
13225 return QDF_STATUS_SUCCESS;
13226}
13227
13228static void hdd_qdf_print_deinit(void)
13229{
13230 int qdf_pidx = qdf_get_pidx();
13231
13232 qdf_set_pidx(-1);
13233 qdf_print_ctrl_cleanup(qdf_pidx);
13234
13235 /* currently, no qdf print 'un-setup'*/
13236}
13237
13238static QDF_STATUS hdd_qdf_init(void)
13239{
13240 QDF_STATUS status;
13241
13242 status = hdd_qdf_print_init();
13243 if (QDF_IS_STATUS_ERROR(status))
13244 goto exit;
13245
13246 status = qdf_debugfs_init();
13247 if (QDF_IS_STATUS_ERROR(status)) {
13248 hdd_err("Failed to init debugfs; status:%u", status);
13249 goto print_deinit;
13250 }
13251
13252 qdf_lock_stats_init();
13253 qdf_mem_init();
13254 qdf_mc_timer_manager_init();
13255 qdf_event_list_init();
13256
Dustin Brownd315c452018-11-27 11:28:48 -080013257 status = qdf_talloc_feature_init();
13258 if (QDF_IS_STATUS_ERROR(status)) {
13259 hdd_err("Failed to init talloc; status:%u", status);
13260 goto event_deinit;
13261 }
13262
Dustin Browna2a39dc2018-09-17 15:29:59 -070013263 status = qdf_cpuhp_init();
13264 if (QDF_IS_STATUS_ERROR(status)) {
13265 hdd_err("Failed to init cpuhp; status:%u", status);
Dustin Brownd315c452018-11-27 11:28:48 -080013266 goto talloc_deinit;
Dustin Browna2a39dc2018-09-17 15:29:59 -070013267 }
13268
13269 status = qdf_trace_spin_lock_init();
13270 if (QDF_IS_STATUS_ERROR(status)) {
13271 hdd_err("Failed to init spinlock; status:%u", status);
13272 goto cpuhp_deinit;
13273 }
13274
13275 qdf_trace_init();
13276 qdf_register_debugcb_init();
13277
13278 return QDF_STATUS_SUCCESS;
13279
13280cpuhp_deinit:
13281 qdf_cpuhp_deinit();
Dustin Brownd315c452018-11-27 11:28:48 -080013282talloc_deinit:
13283 qdf_talloc_feature_deinit();
Dustin Browna2a39dc2018-09-17 15:29:59 -070013284event_deinit:
13285 qdf_event_list_destroy();
13286 qdf_mc_timer_manager_exit();
13287 qdf_mem_exit();
13288 qdf_lock_stats_deinit();
13289 qdf_debugfs_exit();
13290print_deinit:
13291 hdd_qdf_print_deinit();
13292
13293exit:
13294 return status;
13295}
13296
13297static void hdd_qdf_deinit(void)
13298{
13299 /* currently, no debugcb deinit */
13300
13301 qdf_trace_deinit();
13302
13303 /* currently, no trace spinlock deinit */
13304
13305 qdf_cpuhp_deinit();
Dustin Brownd315c452018-11-27 11:28:48 -080013306 qdf_talloc_feature_deinit();
Dustin Browna2a39dc2018-09-17 15:29:59 -070013307 qdf_event_list_destroy();
13308 qdf_mc_timer_manager_exit();
13309 qdf_mem_exit();
13310 qdf_lock_stats_deinit();
13311 qdf_debugfs_exit();
13312 hdd_qdf_print_deinit();
13313}
Dustin Brownf0f70562018-09-14 10:29:38 -070013314
Dustin Brown26afe8f2019-03-01 12:37:24 -080013315#ifdef FEATURE_MONITOR_MODE_SUPPORT
13316static bool is_monitor_mode_supported(void)
13317{
13318 return true;
13319}
13320#else
13321static bool is_monitor_mode_supported(void)
13322{
13323 pr_err("Monitor mode not supported!");
13324 return false;
13325}
13326#endif
13327
13328#ifdef WLAN_FEATURE_EPPING
13329static bool is_epping_mode_supported(void)
13330{
13331 return true;
13332}
13333#else
13334static bool is_epping_mode_supported(void)
13335{
13336 pr_err("Epping mode not supported!");
13337 return false;
13338}
13339#endif
13340
13341#ifdef QCA_WIFI_FTM
13342static bool is_ftm_mode_supported(void)
13343{
13344 return true;
13345}
13346#else
13347static bool is_ftm_mode_supported(void)
13348{
13349 pr_err("FTM mode not supported!");
13350 return false;
13351}
13352#endif
13353
13354/**
13355 * is_con_mode_valid() check con mode is valid or not
13356 * @mode: global con mode
13357 *
13358 * Return: TRUE on success FALSE on failure
13359 */
13360static bool is_con_mode_valid(enum QDF_GLOBAL_MODE mode)
13361{
13362 switch (mode) {
13363 case QDF_GLOBAL_MONITOR_MODE:
13364 return is_monitor_mode_supported();
13365 case QDF_GLOBAL_EPPING_MODE:
13366 return is_epping_mode_supported();
13367 case QDF_GLOBAL_FTM_MODE:
13368 return is_ftm_mode_supported();
13369 case QDF_GLOBAL_MISSION_MODE:
13370 return true;
13371 default:
13372 return false;
13373 }
13374}
13375
13376static void hdd_stop_present_mode(struct hdd_context *hdd_ctx,
13377 enum QDF_GLOBAL_MODE curr_mode)
13378{
13379 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED)
13380 return;
13381
13382 switch (curr_mode) {
13383 case QDF_GLOBAL_MONITOR_MODE:
13384 hdd_info("Release wakelock for monitor mode!");
13385 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
13386 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
13387 /* fallthrough */
13388 case QDF_GLOBAL_MISSION_MODE:
13389 case QDF_GLOBAL_FTM_MODE:
13390 hdd_abort_mac_scan_all_adapters(hdd_ctx);
13391 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->pdev, NULL);
13392 hdd_stop_all_adapters(hdd_ctx);
13393 hdd_deinit_all_adapters(hdd_ctx, false);
13394
13395 break;
13396 default:
13397 break;
13398 }
13399}
13400
13401static void hdd_cleanup_present_mode(struct hdd_context *hdd_ctx,
13402 enum QDF_GLOBAL_MODE curr_mode)
13403{
13404 int driver_status;
13405
13406 driver_status = hdd_ctx->driver_status;
13407
13408 switch (curr_mode) {
13409 case QDF_GLOBAL_MISSION_MODE:
13410 case QDF_GLOBAL_MONITOR_MODE:
13411 case QDF_GLOBAL_FTM_MODE:
13412 hdd_close_all_adapters(hdd_ctx, false);
13413 break;
13414 case QDF_GLOBAL_EPPING_MODE:
13415 epping_disable();
13416 epping_close();
13417 break;
13418 default:
13419 return;
13420 }
13421}
13422
13423static int
13424hdd_parse_driver_mode(const char *mode_str, enum QDF_GLOBAL_MODE *out_mode)
13425{
13426 QDF_STATUS status;
13427 uint32_t mode;
13428
13429 *out_mode = QDF_GLOBAL_MAX_MODE;
13430
13431 status = qdf_uint32_parse(mode_str, &mode);
13432 if (QDF_IS_STATUS_ERROR(status))
13433 return qdf_status_to_os_return(status);
13434
13435 if (mode >= QDF_GLOBAL_MAX_MODE)
13436 return -ERANGE;
13437
13438 *out_mode = (enum QDF_GLOBAL_MODE)mode;
13439
13440 return 0;
13441}
13442
13443/**
13444 * __hdd_driver_mode_change() - Handles a driver mode change
13445 * @hdd_ctx: Pointer to the global HDD context
13446 * @next_mode: the driver mode to transition to
13447 *
13448 * This function is invoked when user updates con_mode using sys entry,
13449 * to initialize and bring-up driver in that specific mode.
13450 *
13451 * Return: Errno
13452 */
13453static int __hdd_driver_mode_change(struct hdd_context *hdd_ctx,
13454 enum QDF_GLOBAL_MODE next_mode)
13455{
13456 enum QDF_GLOBAL_MODE curr_mode;
13457 int errno;
13458
13459 hdd_info("Driver mode changing to %d", next_mode);
13460
13461 errno = wlan_hdd_validate_context(hdd_ctx);
13462 if (errno)
13463 return errno;
13464
13465 if (!is_con_mode_valid(next_mode)) {
13466 hdd_err_rl("Requested driver mode is invalid");
13467 return -EINVAL;
13468 }
13469
Dustin Brown26afe8f2019-03-01 12:37:24 -080013470 curr_mode = hdd_get_conparam();
13471 if (curr_mode == next_mode) {
13472 hdd_err_rl("Driver is already in the requested mode");
Dustin Browne0a77272019-03-19 16:28:06 -070013473 return 0;
Dustin Brown26afe8f2019-03-01 12:37:24 -080013474 }
13475
13476 /* ensure adapters are stopped */
13477 hdd_stop_present_mode(hdd_ctx, curr_mode);
13478
13479 errno = hdd_wlan_stop_modules(hdd_ctx, true);
13480 if (errno) {
13481 hdd_err("Stop wlan modules failed");
Dustin Browne0a77272019-03-19 16:28:06 -070013482 return errno;
Dustin Brown26afe8f2019-03-01 12:37:24 -080013483 }
13484
13485 /* Cleanup present mode before switching to new mode */
13486 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
13487
13488 hdd_set_conparam(next_mode);
13489
13490 errno = hdd_wlan_start_modules(hdd_ctx, false);
13491 if (errno) {
13492 hdd_err("Start wlan modules failed: %d", errno);
Dustin Browne0a77272019-03-19 16:28:06 -070013493 return errno;
Dustin Brown26afe8f2019-03-01 12:37:24 -080013494 }
13495
13496 errno = hdd_open_adapters_for_mode(hdd_ctx, next_mode);
13497 if (errno) {
13498 hdd_err("Failed to open adapters");
Dustin Browne0a77272019-03-19 16:28:06 -070013499 return errno;
Dustin Brown26afe8f2019-03-01 12:37:24 -080013500 }
13501
13502 if (next_mode == QDF_GLOBAL_MONITOR_MODE) {
13503 struct hdd_adapter *adapter =
13504 hdd_get_adapter(hdd_ctx, QDF_MONITOR_MODE);
13505
13506 QDF_BUG(adapter);
13507 if (!adapter) {
13508 hdd_err("Failed to get monitor adapter");
Dustin Browne0a77272019-03-19 16:28:06 -070013509 return -EINVAL;
Dustin Brown26afe8f2019-03-01 12:37:24 -080013510 }
13511
13512 errno = hdd_start_adapter(adapter);
13513 if (errno) {
13514 hdd_err("Failed to start monitor adapter");
Dustin Browne0a77272019-03-19 16:28:06 -070013515 return errno;
Dustin Brown26afe8f2019-03-01 12:37:24 -080013516 }
13517
13518 hdd_info("Acquire wakelock for monitor mode");
13519 qdf_wake_lock_acquire(&hdd_ctx->monitor_mode_wakelock,
13520 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
13521 }
13522
13523 /* con_mode is a global module parameter */
13524 con_mode = next_mode;
13525 hdd_info("Driver mode successfully changed to %d", next_mode);
13526
Dustin Browne0a77272019-03-19 16:28:06 -070013527 return 0;
Dustin Brown26afe8f2019-03-01 12:37:24 -080013528}
13529
13530static int hdd_driver_mode_change(enum QDF_GLOBAL_MODE mode)
13531{
Dustin Brownc1d81af2019-03-01 13:43:43 -080013532 struct osif_driver_sync *driver_sync;
Dustin Brown26afe8f2019-03-01 12:37:24 -080013533 struct hdd_context *hdd_ctx;
13534 QDF_STATUS status;
13535 int errno;
13536
13537 hdd_enter();
13538
Dustin Brownc1d81af2019-03-01 13:43:43 -080013539 status = osif_driver_sync_trans_start_wait(&driver_sync);
Dustin Brown26afe8f2019-03-01 12:37:24 -080013540 if (QDF_IS_STATUS_ERROR(status)) {
13541 hdd_err("Failed to start 'mode change'; status:%u", status);
13542 errno = qdf_status_to_os_return(status);
13543 goto exit;
13544 }
13545
Dustin Brownc1d81af2019-03-01 13:43:43 -080013546 osif_driver_sync_wait_for_ops(driver_sync);
Dustin Brown26afe8f2019-03-01 12:37:24 -080013547
13548 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13549 errno = wlan_hdd_validate_context(hdd_ctx);
13550 if (errno)
13551 goto trans_stop;
13552
Dustin Brown26afe8f2019-03-01 12:37:24 -080013553 errno = __hdd_driver_mode_change(hdd_ctx, mode);
Dustin Brown26afe8f2019-03-01 12:37:24 -080013554
13555trans_stop:
Dustin Brownc1d81af2019-03-01 13:43:43 -080013556 osif_driver_sync_trans_stop(driver_sync);
Dustin Brown26afe8f2019-03-01 12:37:24 -080013557
13558exit:
13559 hdd_exit();
13560
13561 return errno;
13562}
13563
13564static int hdd_set_con_mode(enum QDF_GLOBAL_MODE mode)
13565{
13566 con_mode = mode;
13567
13568 return 0;
13569}
13570
13571static int (*hdd_set_con_mode_cb)(enum QDF_GLOBAL_MODE mode) = hdd_set_con_mode;
13572
13573static void hdd_driver_mode_change_register(void)
13574{
13575 hdd_set_con_mode_cb = hdd_driver_mode_change;
13576}
13577
13578static void hdd_driver_mode_change_unregister(void)
13579{
13580 hdd_set_con_mode_cb = hdd_set_con_mode;
13581}
13582
13583static int con_mode_handler(const char *kmessage, const struct kernel_param *kp)
13584{
13585 enum QDF_GLOBAL_MODE mode;
13586 int errno;
13587
13588 errno = hdd_parse_driver_mode(kmessage, &mode);
13589 if (errno) {
13590 hdd_err_rl("Failed to parse driver mode '%s'", kmessage);
13591 return errno;
13592 }
13593
13594 return hdd_set_con_mode_cb(mode);
13595}
Dustin Brown95ff00b2019-02-28 13:41:13 -080013596
Dustin Brownf0f70562018-09-14 10:29:38 -070013597/**
13598 * hdd_driver_load() - Perform the driver-level load operation
13599 *
13600 * Note: this is used in both static and DLKM driver builds
13601 *
13602 * Return: Errno
13603 */
13604static int hdd_driver_load(void)
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013605{
Dustin Brownc1d81af2019-03-01 13:43:43 -080013606 struct osif_driver_sync *driver_sync;
Dustin Brownd585cb32018-09-12 17:12:23 -070013607 QDF_STATUS status;
Dustin Brownf0f70562018-09-14 10:29:38 -070013608 int errno;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013609
Dustin Brownc1d81af2019-03-01 13:43:43 -080013610 pr_err("%s: Loading driver v%s\n", WLAN_MODULE_NAME,
Rajeev Kumare555e2d2018-09-17 11:52:37 -070013611 g_wlan_driver_version);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013612
Dustin Browna2a39dc2018-09-17 15:29:59 -070013613 status = hdd_qdf_init();
13614 if (QDF_IS_STATUS_ERROR(status)) {
13615 errno = qdf_status_to_os_return(status);
13616 goto exit;
13617 }
13618
Dustin Brownc1d81af2019-03-01 13:43:43 -080013619 osif_sync_init();
Dustin Brown21a1d462018-07-31 15:13:06 -070013620
Dustin Brownc1d81af2019-03-01 13:43:43 -080013621 status = osif_driver_sync_create_and_trans(&driver_sync);
Dustin Brown21a1d462018-07-31 15:13:06 -070013622 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Brownc1d81af2019-03-01 13:43:43 -080013623 hdd_err("Failed to init driver sync; status:%u", status);
Dustin Brown21a1d462018-07-31 15:13:06 -070013624 errno = qdf_status_to_os_return(status);
Dustin Brownc1d81af2019-03-01 13:43:43 -080013625 goto sync_deinit;
Dustin Brown21a1d462018-07-31 15:13:06 -070013626 }
13627
Dustin Brownf0f70562018-09-14 10:29:38 -070013628 errno = hdd_init();
13629 if (errno) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013630 hdd_err("Failed to init HDD; errno:%d", errno);
Dustin Brown21a1d462018-07-31 15:13:06 -070013631 goto trans_stop;
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053013632 }
13633
Dustin Brownd585cb32018-09-12 17:12:23 -070013634 status = hdd_component_init();
13635 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013636 hdd_err("Failed to init components; status:%u", status);
Dustin Brownf0f70562018-09-14 10:29:38 -070013637 errno = qdf_status_to_os_return(status);
Dustin Brownd585cb32018-09-12 17:12:23 -070013638 goto hdd_deinit;
13639 }
Mukul Sharmad75a6672017-06-22 15:40:53 +053013640
Dustin Brownf0f70562018-09-14 10:29:38 -070013641 status = qdf_wake_lock_create(&wlan_wake_lock, "wlan");
13642 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013643 hdd_err("Failed to create wake lock; status:%u", status);
Dustin Brownf0f70562018-09-14 10:29:38 -070013644 errno = qdf_status_to_os_return(status);
13645 goto comp_deinit;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013646 }
13647
Dustin Brownf0f70562018-09-14 10:29:38 -070013648 hdd_set_conparam(con_mode);
13649
Dustin Brownf0f70562018-09-14 10:29:38 -070013650 errno = wlan_hdd_state_ctrl_param_create();
13651 if (errno) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013652 hdd_err("Failed to create ctrl param; errno:%d", errno);
Dustin Brown4b9dbe62018-09-14 15:41:11 -070013653 goto wakelock_destroy;
13654 }
13655
Dustin Brown25843ad2018-09-17 14:54:33 -070013656 errno = pld_init();
13657 if (errno) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013658 hdd_err("Failed to init PLD; errno:%d", errno);
Dustin Brown25843ad2018-09-17 14:54:33 -070013659 goto param_destroy;
13660 }
13661
Dustin Brown95ff00b2019-02-28 13:41:13 -080013662 hdd_driver_mode_change_register();
Dustin Brownc1d81af2019-03-01 13:43:43 -080013663
13664 osif_driver_sync_register(driver_sync);
13665 osif_driver_sync_trans_stop(driver_sync);
Dustin Brown21a1d462018-07-31 15:13:06 -070013666
13667 /* psoc probe can happen in registration; do after 'load' transition */
Dustin Brown4b9dbe62018-09-14 15:41:11 -070013668 errno = wlan_hdd_register_driver();
13669 if (errno) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013670 hdd_err("Failed to register driver; errno:%d", errno);
Dustin Brown25843ad2018-09-17 14:54:33 -070013671 goto pld_deinit;
Sachin Ahuja16904db2017-12-13 19:56:57 +053013672 }
13673
Dustin Browna2a39dc2018-09-17 15:29:59 -070013674 hdd_debug("%s: driver loaded", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013675
13676 return 0;
Dustin Brownd585cb32018-09-12 17:12:23 -070013677
Dustin Brown25843ad2018-09-17 14:54:33 -070013678pld_deinit:
Dustin Brownc1d81af2019-03-01 13:43:43 -080013679 status = osif_driver_sync_trans_start(&driver_sync);
Dustin Brown21a1d462018-07-31 15:13:06 -070013680 QDF_BUG(QDF_IS_STATUS_SUCCESS(status));
13681
Dustin Brownc1d81af2019-03-01 13:43:43 -080013682 osif_driver_sync_unregister();
13683 osif_driver_sync_wait_for_ops(driver_sync);
13684
Dustin Brown95ff00b2019-02-28 13:41:13 -080013685 hdd_driver_mode_change_unregister();
Dustin Brown25843ad2018-09-17 14:54:33 -070013686 pld_deinit();
Dustin Brown21a1d462018-07-31 15:13:06 -070013687
Dustin Brown4b9dbe62018-09-14 15:41:11 -070013688param_destroy:
13689 wlan_hdd_state_ctrl_param_destroy();
Dustin Brownf0f70562018-09-14 10:29:38 -070013690wakelock_destroy:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053013691 qdf_wake_lock_destroy(&wlan_wake_lock);
Dustin Brownf0f70562018-09-14 10:29:38 -070013692comp_deinit:
Dustin Brownd585cb32018-09-12 17:12:23 -070013693 hdd_component_deinit();
Dustin Brownd585cb32018-09-12 17:12:23 -070013694hdd_deinit:
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053013695 hdd_deinit();
Dustin Brown21a1d462018-07-31 15:13:06 -070013696trans_stop:
Dustin Brownc1d81af2019-03-01 13:43:43 -080013697 osif_driver_sync_trans_stop(driver_sync);
13698 osif_driver_sync_destroy(driver_sync);
13699sync_deinit:
13700 osif_sync_deinit();
Dustin Browna2a39dc2018-09-17 15:29:59 -070013701 hdd_qdf_deinit();
Dustin Brownd585cb32018-09-12 17:12:23 -070013702
Dustin Brown25843ad2018-09-17 14:54:33 -070013703exit:
Dustin Brownf0f70562018-09-14 10:29:38 -070013704 return errno;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013705}
13706
13707/**
Dustin Brownf0f70562018-09-14 10:29:38 -070013708 * hdd_driver_unload() - Performs the driver-level unload operation
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013709 *
Dustin Brownf0f70562018-09-14 10:29:38 -070013710 * Note: this is used in both static and DLKM driver builds
13711 *
13712 * Return: None
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013713 */
Dustin Brownf0f70562018-09-14 10:29:38 -070013714static void hdd_driver_unload(void)
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013715{
Dustin Brownc1d81af2019-03-01 13:43:43 -080013716 struct osif_driver_sync *driver_sync;
Will Huang36049722018-04-13 11:48:51 +080013717 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Dustin Brown21a1d462018-07-31 15:13:06 -070013718 QDF_STATUS status;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053013719
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013720 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
13721 QWLAN_VERSIONSTR);
13722
Dustin Brown8c0b5e32019-01-18 13:56:02 -080013723 if (g_is_system_reboot_triggered) {
13724 hdd_info("System rebooting; Skipping unload");
13725 return;
13726 }
13727
13728 if (hdd_ctx)
13729 hdd_psoc_idle_timer_stop(hdd_ctx);
13730
13731 /* trigger SoC remove */
13732 wlan_hdd_unregister_driver();
13733
Dustin Brownc1d81af2019-03-01 13:43:43 -080013734 status = osif_driver_sync_trans_start_wait(&driver_sync);
Dustin Brown21a1d462018-07-31 15:13:06 -070013735 QDF_BUG(QDF_IS_STATUS_SUCCESS(status));
13736 if (QDF_IS_STATUS_ERROR(status)) {
13737 hdd_err("Unable to unload wlan; status:%u", status);
Arunk Khandavalli830c9692018-03-22 12:17:40 +053013738 return;
Dustin Brown21a1d462018-07-31 15:13:06 -070013739 }
13740
Dustin Brownc1d81af2019-03-01 13:43:43 -080013741 osif_driver_sync_unregister();
13742 osif_driver_sync_wait_for_ops(driver_sync);
Dustin Brown21a1d462018-07-31 15:13:06 -070013743
Will Huangba035ec2018-07-05 11:13:30 +080013744 cds_set_driver_loaded(false);
13745 cds_set_unload_in_progress(true);
13746
Dustin Brown95ff00b2019-02-28 13:41:13 -080013747 hdd_driver_mode_change_unregister();
Dustin Brown25843ad2018-09-17 14:54:33 -070013748 pld_deinit();
Dustin Brown4b9dbe62018-09-14 15:41:11 -070013749 wlan_hdd_state_ctrl_param_destroy();
Dustin Brownf0f70562018-09-14 10:29:38 -070013750 hdd_set_conparam(0);
Anurag Chouhana37b5b72016-02-21 14:53:42 +053013751 qdf_wake_lock_destroy(&wlan_wake_lock);
Dustin Brownd585cb32018-09-12 17:12:23 -070013752 hdd_component_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053013753 hdd_deinit();
Dustin Brown21a1d462018-07-31 15:13:06 -070013754
Dustin Brownc1d81af2019-03-01 13:43:43 -080013755 osif_driver_sync_trans_stop(driver_sync);
13756 osif_driver_sync_destroy(driver_sync);
Dustin Brown623e7e32018-09-05 14:27:50 -070013757
Dustin Brownc1d81af2019-03-01 13:43:43 -080013758 osif_sync_deinit();
Dustin Brown21a1d462018-07-31 15:13:06 -070013759
Dustin Browna2a39dc2018-09-17 15:29:59 -070013760 hdd_qdf_deinit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013761}
13762
Arun Khandavallifae92942016-08-01 13:31:08 +053013763#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013764/**
Arun Khandavallifae92942016-08-01 13:31:08 +053013765 * wlan_boot_cb() - Wlan boot callback
13766 * @kobj: object whose directory we're creating the link in.
13767 * @attr: attribute the user is interacting with
13768 * @buff: the buffer containing the user data
13769 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013770 *
Arun Khandavallifae92942016-08-01 13:31:08 +053013771 * This callback is invoked when the fs is ready to start the
13772 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013773 *
Arun Khandavallifae92942016-08-01 13:31:08 +053013774 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013775 */
Arun Khandavallifae92942016-08-01 13:31:08 +053013776static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013777 struct kobj_attribute *attr,
13778 const char *buf,
13779 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013780{
Arun Khandavallifae92942016-08-01 13:31:08 +053013781
Arun Khandavallifae92942016-08-01 13:31:08 +053013782 if (wlan_loader->loaded_state) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013783 hdd_err("wlan driver already initialized");
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013784 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053013785 }
13786
Dustin Brownf0f70562018-09-14 10:29:38 -070013787 if (hdd_driver_load())
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013788 return -EIO;
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013789
13790 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053013791
13792 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013793}
Arun Khandavallifae92942016-08-01 13:31:08 +053013794
13795/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013796 * hdd_sysfs_cleanup() - cleanup sysfs
13797 *
13798 * Return: None
13799 *
13800 */
13801static void hdd_sysfs_cleanup(void)
13802{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013803 /* remove from group */
13804 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
13805 sysfs_remove_group(wlan_loader->boot_wlan_obj,
13806 wlan_loader->attr_group);
13807
13808 /* unlink the object from parent */
13809 kobject_del(wlan_loader->boot_wlan_obj);
13810
13811 /* free the object */
13812 kobject_put(wlan_loader->boot_wlan_obj);
13813
13814 kfree(wlan_loader->attr_group);
13815 kfree(wlan_loader);
13816
13817 wlan_loader = NULL;
13818}
13819
13820/**
Arun Khandavallifae92942016-08-01 13:31:08 +053013821 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
13822 * ready
13823 *
13824 * This is creates the syfs entry boot_wlan. Which shall be invoked
13825 * when the filesystem is ready.
13826 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013827 * QDF API cannot be used here since this function is called even before
13828 * initializing WLAN driver.
13829 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070013830 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053013831 */
13832static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013833{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013834 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053013835
13836 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070013837 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013838 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053013839
13840 wlan_loader->boot_wlan_obj = NULL;
13841 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
13842 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070013843 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053013844 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053013845
13846 wlan_loader->loaded_state = 0;
13847 wlan_loader->attr_group->attrs = attrs;
13848
Qun Zhang4a83a462018-09-11 16:28:51 +080013849 wlan_loader->boot_wlan_obj = kobject_create_and_add(WLAN_LOADER_NAME,
Arun Khandavallifae92942016-08-01 13:31:08 +053013850 kernel_kobj);
13851 if (!wlan_loader->boot_wlan_obj) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013852 hdd_err("sysfs create and add failed");
Arun Khandavallifae92942016-08-01 13:31:08 +053013853 goto error_return;
13854 }
13855
13856 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
13857 wlan_loader->attr_group);
13858 if (ret) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013859 hdd_err("sysfs create group failed; errno:%d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +053013860 goto error_return;
13861 }
13862
13863 return 0;
13864
13865error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013866 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053013867
13868 return ret;
13869}
13870
13871/**
13872 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
13873 *
13874 * Return: 0 on success or errno on failure
13875 */
13876static int wlan_deinit_sysfs(void)
13877{
Arun Khandavallifae92942016-08-01 13:31:08 +053013878 if (!wlan_loader) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013879 hdd_err("wlan_loader is null");
Arun Khandavallifae92942016-08-01 13:31:08 +053013880 return -EINVAL;
13881 }
13882
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013883 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013884 return 0;
13885}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013886
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013887#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053013888
13889#ifdef MODULE
13890/**
Dustin Brownf0f70562018-09-14 10:29:38 -070013891 * hdd_module_init() - Module init helper
Arun Khandavallifae92942016-08-01 13:31:08 +053013892 *
13893 * Module init helper function used by both module and static driver.
13894 *
13895 * Return: 0 for success, errno on failure
13896 */
13897static int hdd_module_init(void)
13898{
Dustin Brownf0f70562018-09-14 10:29:38 -070013899 if (hdd_driver_load())
Dustin Brownab482ac2017-06-09 17:00:44 -070013900 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053013901
Dustin Brownab482ac2017-06-09 17:00:44 -070013902 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053013903}
13904#else
13905static int __init hdd_module_init(void)
13906{
13907 int ret = -EINVAL;
13908
13909 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070013910 if (ret)
Dustin Browna2a39dc2018-09-17 15:29:59 -070013911 hdd_err("Failed to create sysfs entry");
Arun Khandavallifae92942016-08-01 13:31:08 +053013912
13913 return ret;
13914}
13915#endif
13916
13917
13918#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013919/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013920 * hdd_module_exit() - Exit function
13921 *
13922 * This is the driver exit point (invoked when module is unloaded using rmmod)
13923 *
13924 * Return: None
13925 */
13926static void __exit hdd_module_exit(void)
13927{
Dustin Brownf0f70562018-09-14 10:29:38 -070013928 hdd_driver_unload();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013929}
Arun Khandavallifae92942016-08-01 13:31:08 +053013930#else
13931static void __exit hdd_module_exit(void)
13932{
Dustin Brownf0f70562018-09-14 10:29:38 -070013933 hdd_driver_unload();
Arun Khandavallifae92942016-08-01 13:31:08 +053013934 wlan_deinit_sysfs();
13935}
13936#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013937
Srinivas Girigowda841da292018-02-21 16:33:00 -080013938static int fwpath_changed_handler(const char *kmessage,
13939 const struct kernel_param *kp)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013940{
13941 return param_set_copystring(kmessage, kp);
13942}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013943
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053013944static int con_mode_handler_ftm(const char *kmessage,
Srinivas Girigowda841da292018-02-21 16:33:00 -080013945 const struct kernel_param *kp)
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053013946{
13947 int ret;
13948
13949 ret = param_set_int(kmessage, kp);
13950
13951 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
13952 pr_err("Only FTM mode supported!");
13953 return -ENOTSUPP;
13954 }
13955
13956 hdd_set_conparam(con_mode_ftm);
13957 con_mode = con_mode_ftm;
13958
13959 return ret;
13960}
13961
Nirav Shah6aeecf92019-02-13 14:05:03 +053013962#ifdef WLAN_FEATURE_EPPING
13963static int con_mode_handler_epping(const char *kmessage,
13964 const struct kernel_param *kp)
13965{
13966 int ret;
13967
13968 ret = param_set_int(kmessage, kp);
13969
13970 if (con_mode_epping != QDF_GLOBAL_EPPING_MODE) {
13971 pr_err("Only EPPING mode supported!");
13972 return -ENOTSUPP;
13973 }
13974
13975 hdd_set_conparam(con_mode_epping);
13976 con_mode = con_mode_epping;
13977
13978 return ret;
13979}
13980#endif
13981
Nirav Shah73713f72018-05-17 14:50:41 +053013982#ifdef FEATURE_MONITOR_MODE_SUPPORT
Ravi Joshia307f632017-07-17 23:41:41 -070013983static int con_mode_handler_monitor(const char *kmessage,
Srinivas Girigowda841da292018-02-21 16:33:00 -080013984 const struct kernel_param *kp)
Ravi Joshia307f632017-07-17 23:41:41 -070013985{
13986 int ret;
13987
13988 ret = param_set_int(kmessage, kp);
13989
13990 if (con_mode_monitor != QDF_GLOBAL_MONITOR_MODE) {
13991 pr_err("Only Monitor mode supported!");
13992 return -ENOTSUPP;
13993 }
13994
13995 hdd_set_conparam(con_mode_monitor);
13996 con_mode = con_mode_monitor;
13997
13998 return ret;
13999}
Nirav Shah73713f72018-05-17 14:50:41 +053014000#endif
Ravi Joshia307f632017-07-17 23:41:41 -070014001
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014002/**
14003 * hdd_get_conparam() - driver exit point
14004 *
14005 * This is the driver exit point (invoked when module is unloaded using rmmod)
14006 *
Jeff Johnson876c1a62017-12-12 10:43:07 -080014007 * Return: enum QDF_GLOBAL_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014008 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080014009enum QDF_GLOBAL_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014010{
Jeff Johnson876c1a62017-12-12 10:43:07 -080014011 return (enum QDF_GLOBAL_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014012}
14013
Dustin Brownf0f70562018-09-14 10:29:38 -070014014void hdd_set_conparam(int32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014015{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080014016 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014017}
14018
Komal Seelamc11bb222016-01-27 18:57:10 +053014019/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053014020 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
14021 * @hdd_ctx: HDD context
14022 *
14023 * Cleans up the pre cac interface, if it exists
14024 *
14025 * Return: None
14026 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014027void hdd_clean_up_pre_cac_interface(struct hdd_context *hdd_ctx)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053014028{
Jeff Johnson55d2ab42019-03-06 11:43:49 -080014029 uint8_t vdev_id;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053014030 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070014031 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053014032
Jeff Johnson55d2ab42019-03-06 11:43:49 -080014033 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->mac_handle, &vdev_id);
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053014034 if (QDF_IS_STATUS_ERROR(status)) {
14035 hdd_err("failed to get pre cac vdev id");
14036 return;
14037 }
14038
Jeff Johnson55d2ab42019-03-06 11:43:49 -080014039 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053014040 if (!precac_adapter) {
Jeff Johnsondd2f1fc2018-05-06 11:22:52 -070014041 hdd_err("invalid pre cac adapter");
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053014042 return;
14043 }
14044
14045 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
14046 wlan_hdd_sap_pre_cac_failure,
14047 (void *)precac_adapter);
14048 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
14049
14050}
14051
14052/**
Komal Seelamec702b02016-02-24 18:42:16 +053014053 * hdd_update_ol_config - API to update ol configuration parameters
14054 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053014055 *
Komal Seelamc11bb222016-01-27 18:57:10 +053014056 * Return: void
14057 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014058static void hdd_update_ol_config(struct hdd_context *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053014059{
Abhishek Singh98278ce2018-12-27 11:41:03 +053014060 struct ol_config_info cfg = {0};
Anurag Chouhandf2b2682016-02-29 14:15:27 +053014061 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053014062 bool self_recovery = false;
14063 QDF_STATUS status;
Komal Seelamc11bb222016-01-27 18:57:10 +053014064
Komal Seelamec702b02016-02-24 18:42:16 +053014065 if (!ol_ctx)
14066 return;
14067
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053014068 status = ucfg_mlme_get_self_recovery(hdd_ctx->psoc, &self_recovery);
14069 if (QDF_IS_STATUS_ERROR(status))
14070 hdd_err("Failed to get self recovery ini config");
14071
14072 cfg.enable_self_recovery = self_recovery;
Komal Seelamec702b02016-02-24 18:42:16 +053014073 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
14074 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
14075 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070014076 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053014077
14078 ol_init_ini_config(ol_ctx, &cfg);
14079}
14080
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070014081#ifdef FEATURE_RUNTIME_PM
14082/**
14083 * hdd_populate_runtime_cfg() - populate runtime configuration
14084 * @hdd_ctx: hdd context
14085 * @cfg: pointer to the configuration memory being populated
14086 *
14087 * Return: void
14088 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014089static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070014090 struct hif_config_info *cfg)
14091{
14092 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
Wu Gao66454f12018-09-26 19:55:41 +080014093 cfg->runtime_pm_delay =
14094 ucfg_pmo_get_runtime_pm_delay(hdd_ctx->psoc);
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070014095}
14096#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014097static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070014098 struct hif_config_info *cfg)
14099{
14100}
14101#endif
14102
Komal Seelamec702b02016-02-24 18:42:16 +053014103/**
14104 * hdd_update_hif_config - API to update HIF configuration parameters
14105 * @hdd_ctx: HDD Context
14106 *
14107 * Return: void
14108 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014109static void hdd_update_hif_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053014110{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053014111 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Abhishek Singh98278ce2018-12-27 11:41:03 +053014112 struct hif_config_info cfg = {0};
Vignesh Viswanathana851d752018-10-03 19:44:38 +053014113 bool prevent_link_down = false;
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053014114 bool self_recovery = false;
Vignesh Viswanathana851d752018-10-03 19:44:38 +053014115 QDF_STATUS status;
Komal Seelamec702b02016-02-24 18:42:16 +053014116
14117 if (!scn)
14118 return;
14119
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053014120 status = ucfg_mlme_get_prevent_link_down(hdd_ctx->psoc,
14121 &prevent_link_down);
Vignesh Viswanathana851d752018-10-03 19:44:38 +053014122 if (QDF_IS_STATUS_ERROR(status))
14123 hdd_err("Failed to get prevent_link_down config");
14124
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053014125 status = ucfg_mlme_get_self_recovery(hdd_ctx->psoc, &self_recovery);
14126 if (QDF_IS_STATUS_ERROR(status))
14127 hdd_err("Failed to get self recovery ini config");
14128
14129 cfg.enable_self_recovery = self_recovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070014130 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053014131 hif_init_ini_config(scn, &cfg);
Dustin Brownee3e0592017-09-07 13:50:11 -070014132
Vignesh Viswanathana851d752018-10-03 19:44:38 +053014133 if (prevent_link_down)
Dustin Brownee3e0592017-09-07 13:50:11 -070014134 hif_vote_link_up(scn);
Komal Seelamec702b02016-02-24 18:42:16 +053014135}
14136
14137/**
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014138 * hdd_update_dp_config() - Propagate config parameters to Lithium
14139 * datapath
14140 * @hdd_ctx: HDD Context
14141 *
14142 * Return: 0 for success/errno for failure
14143 */
14144static int hdd_update_dp_config(struct hdd_context *hdd_ctx)
14145{
Abhishek Singh98278ce2018-12-27 11:41:03 +053014146 struct cdp_config_params params = {0};
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014147 QDF_STATUS status;
jitiphil377bcc12018-10-05 19:46:08 +053014148 void *soc;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014149
jitiphil377bcc12018-10-05 19:46:08 +053014150 soc = cds_get_context(QDF_MODULE_ID_SOC);
14151 params.tso_enable = cfg_get(hdd_ctx->psoc, CFG_DP_TSO);
14152 params.lro_enable = cfg_get(hdd_ctx->psoc, CFG_DP_LRO);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014153#ifdef QCA_LL_TX_FLOW_CONTROL_V2
14154 params.tx_flow_stop_queue_threshold =
jitiphil47c3d9a2018-11-08 18:30:55 +053014155 cfg_get(hdd_ctx->psoc, CFG_DP_TX_FLOW_STOP_QUEUE_TH);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014156 params.tx_flow_start_queue_offset =
jitiphil47c3d9a2018-11-08 18:30:55 +053014157 cfg_get(hdd_ctx->psoc,
14158 CFG_DP_TX_FLOW_START_QUEUE_OFFSET);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014159#endif
jitiphil377bcc12018-10-05 19:46:08 +053014160 params.flow_steering_enable =
14161 cfg_get(hdd_ctx->psoc, CFG_DP_FLOW_STEERING_ENABLED);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014162 params.napi_enable = hdd_ctx->napi_enable;
14163 params.tcp_udp_checksumoffload =
jitiphil377bcc12018-10-05 19:46:08 +053014164 cfg_get(hdd_ctx->psoc,
14165 CFG_DP_TCP_UDP_CKSUM_OFFLOAD);
Sravan Kumar Kairam0af1ee52018-12-12 20:37:51 +053014166 params.ipa_enable = ucfg_ipa_is_enabled();
Mohit Khanna81418772018-10-30 14:14:46 -070014167 params.gro_enable = cfg_get(hdd_ctx->psoc, CFG_DP_GRO);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014168
jitiphil377bcc12018-10-05 19:46:08 +053014169 status = cdp_update_config_parameters(soc, &params);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014170 if (status) {
Dustin Browna2868622018-03-20 11:38:14 -070014171 hdd_err("Failed to attach config parameters");
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014172 return status;
14173 }
14174
14175 return 0;
14176}
14177
14178/**
Komal Seelamec702b02016-02-24 18:42:16 +053014179 * hdd_update_config() - Initialize driver per module ini parameters
14180 * @hdd_ctx: HDD Context
14181 *
14182 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053014183 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053014184 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014185int hdd_update_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053014186{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053014187 int ret;
14188
Wu Gao66454f12018-09-26 19:55:41 +080014189 if (ucfg_pmo_is_ns_offloaded(hdd_ctx->psoc))
14190 hdd_ctx->ns_offload_enable = true;
14191
Komal Seelamec702b02016-02-24 18:42:16 +053014192 hdd_update_ol_config(hdd_ctx);
14193 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053014194 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
14195 ret = hdd_update_cds_config_ftm(hdd_ctx);
14196 else
14197 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080014198 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053014199
14200 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053014201}
14202
Mukul Sharma9d797a02017-01-05 20:26:03 +053014203/**
14204 * hdd_update_pmo_config - API to update pmo configuration parameters
14205 * @hdd_ctx: HDD context
14206 *
14207 * Return: void
14208 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014209static int hdd_update_pmo_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053014210{
Abhishek Singh98278ce2018-12-27 11:41:03 +053014211 struct pmo_psoc_cfg psoc_cfg = {0};
Mukul Sharma9d797a02017-01-05 20:26:03 +053014212 QDF_STATUS status;
Wu Gao66454f12018-09-26 19:55:41 +080014213 enum pmo_wow_enable_type wow_enable;
14214
14215 ucfg_pmo_get_psoc_config(hdd_ctx->psoc, &psoc_cfg);
Mukul Sharma9d797a02017-01-05 20:26:03 +053014216
14217 /*
14218 * Value of hdd_ctx->wowEnable can be,
14219 * 0 - Disable both magic pattern match and pattern byte match.
14220 * 1 - Enable magic pattern match on all interfaces.
14221 * 2 - Enable pattern byte match on all interfaces.
14222 * 3 - Enable both magic patter and pattern byte match on
14223 * all interfaces.
14224 */
Wu Gao66454f12018-09-26 19:55:41 +080014225 wow_enable = ucfg_pmo_get_wow_enable(hdd_ctx->psoc);
14226 psoc_cfg.magic_ptrn_enable = (wow_enable & 0x01) ? true : false;
Mukul Sharma9d797a02017-01-05 20:26:03 +053014227 psoc_cfg.ptrn_match_enable_all_vdev =
Wu Gao66454f12018-09-26 19:55:41 +080014228 (wow_enable & 0x02) ? true : false;
Mukul Sharma9d797a02017-01-05 20:26:03 +053014229 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
Will Huang3cd2b7c2017-11-17 13:16:56 +080014230 psoc_cfg.d0_wow_supported = wma_d0_wow_is_supported();
Bala Venkatesh46e29032018-11-14 18:24:55 +053014231 ucfg_mlme_get_sap_max_modulated_dtim(hdd_ctx->psoc,
14232 &psoc_cfg.sta_max_li_mod_dtim);
14233
Mukul Sharma9d797a02017-01-05 20:26:03 +053014234
Mukul Sharma9223f232017-03-08 18:42:27 +053014235 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053014236
Dustin Brown1dbefe62018-09-11 16:32:03 -070014237 status = ucfg_pmo_update_psoc_config(hdd_ctx->psoc, &psoc_cfg);
Dustin Brownb9987af2018-03-01 17:15:11 -080014238 if (QDF_IS_STATUS_ERROR(status))
14239 hdd_err("failed pmo psoc configuration; status:%d", status);
14240
14241 return qdf_status_to_os_return(status);
Mukul Sharma9d797a02017-01-05 20:26:03 +053014242}
14243
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053014244void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
Dundi Raviteja85a240a2018-09-10 15:03:07 +053014245 struct hdd_context *hdd_ctx)
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053014246{
Dundi Raviteja85a240a2018-09-10 15:03:07 +053014247 struct wlan_fwol_ie_whitelist whitelist = {0};
14248 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Dundi Raviteja85a240a2018-09-10 15:03:07 +053014249 QDF_STATUS status;
14250 bool is_ie_whitelist_enable = false;
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053014251 uint8_t i = 0;
14252
Dundi Raviteja85a240a2018-09-10 15:03:07 +053014253 status = ucfg_fwol_get_ie_whitelist(psoc, &is_ie_whitelist_enable);
14254 if (QDF_IS_STATUS_ERROR(status)) {
14255 hdd_err("Unable to get IE whitelist param");
14256 return;
14257 }
14258
14259 ie_whitelist->white_list = is_ie_whitelist_enable;
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053014260 if (!ie_whitelist->white_list)
14261 return;
14262
Dundi Raviteja85a240a2018-09-10 15:03:07 +053014263 status = ucfg_fwol_get_all_whitelist_params(psoc, &whitelist);
14264 if (QDF_IS_STATUS_ERROR(status)) {
14265 hdd_err("Unable to get all whitelist params");
14266 return;
14267 }
14268
14269 ie_whitelist->ie_bitmap[0] = whitelist.ie_bitmap_0;
14270 ie_whitelist->ie_bitmap[1] = whitelist.ie_bitmap_1;
14271 ie_whitelist->ie_bitmap[2] = whitelist.ie_bitmap_2;
14272 ie_whitelist->ie_bitmap[3] = whitelist.ie_bitmap_3;
14273 ie_whitelist->ie_bitmap[4] = whitelist.ie_bitmap_4;
14274 ie_whitelist->ie_bitmap[5] = whitelist.ie_bitmap_5;
14275 ie_whitelist->ie_bitmap[6] = whitelist.ie_bitmap_6;
14276 ie_whitelist->ie_bitmap[7] = whitelist.ie_bitmap_7;
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053014277
Dundi Raviteja9ab4e7b2018-09-28 14:18:28 +053014278 ie_whitelist->num_vendor_oui = whitelist.no_of_probe_req_ouis;
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053014279 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
Dundi Raviteja9ab4e7b2018-09-28 14:18:28 +053014280 ie_whitelist->voui[i] = whitelist.probe_req_voui[i];
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053014281}
14282
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014283uint32_t hdd_limit_max_per_index_score(uint32_t per_index_score)
14284{
14285 uint8_t i, score;
14286
14287 for (i = 0; i < MAX_INDEX_PER_INI; i++) {
14288 score = WLAN_GET_SCORE_PERCENTAGE(per_index_score, i);
14289 if (score > MAX_INDEX_SCORE)
14290 WLAN_SET_SCORE_PERCENTAGE(per_index_score,
14291 MAX_INDEX_SCORE, i);
14292 }
14293
14294 return per_index_score;
14295}
14296
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053014297QDF_STATUS hdd_update_score_config(
14298 struct scoring_config *score_config, struct hdd_context *hdd_ctx)
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014299{
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053014300 struct hdd_config *cfg = hdd_ctx->config;
gaurank kathpaliaae52c982018-10-04 01:35:18 +053014301 QDF_STATUS status;
gaurank kathpalia651abcd2018-11-12 22:41:23 +053014302 struct wlan_mlme_nss_chains vdev_ini_cfg;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053014303 bool bval = false;
Wu Gaoed616a12019-01-16 15:19:21 +080014304 uint32_t channel_bonding_mode;
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014305
Abhishek Singh98278ce2018-12-27 11:41:03 +053014306 qdf_mem_zero(&vdev_ini_cfg, sizeof(struct wlan_mlme_nss_chains));
gaurank kathpalia651abcd2018-11-12 22:41:23 +053014307 /* Populate the nss chain params from ini for this vdev type */
14308 sme_populate_nss_chain_params(hdd_ctx->mac_handle, &vdev_ini_cfg,
14309 QDF_STA_MODE,
14310 hdd_ctx->num_rf_chains);
14311
14312 score_config->vdev_nss_24g = vdev_ini_cfg.rx_nss[NSS_CHAINS_BAND_2GHZ];
14313 score_config->vdev_nss_24g = vdev_ini_cfg.rx_nss[NSS_CHAINS_BAND_5GHZ];
14314
Vignesh Viswanathan987f0bb2018-09-17 17:00:29 +053014315 sme_update_score_config(hdd_ctx->mac_handle, score_config);
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014316
Wu Gaoed616a12019-01-16 15:19:21 +080014317 ucfg_mlme_get_channel_bonding_24ghz(hdd_ctx->psoc,
14318 &channel_bonding_mode);
14319 score_config->cb_mode_24G = channel_bonding_mode;
14320 ucfg_mlme_get_channel_bonding_5ghz(hdd_ctx->psoc,
14321 &channel_bonding_mode);
14322 score_config->cb_mode_5G = channel_bonding_mode;
gaurank kathpaliaae52c982018-10-04 01:35:18 +053014323
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014324 if (cfg->dot11Mode == eHDD_DOT11_MODE_AUTO ||
14325 cfg->dot11Mode == eHDD_DOT11_MODE_11ax ||
14326 cfg->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY)
14327 score_config->he_cap = 1;
14328
14329 if (score_config->he_cap ||
14330 cfg->dot11Mode == eHDD_DOT11_MODE_11ac ||
14331 cfg->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY)
14332 score_config->vht_cap = 1;
14333
14334 if (score_config->vht_cap || cfg->dot11Mode == eHDD_DOT11_MODE_11n ||
14335 cfg->dot11Mode == eHDD_DOT11_MODE_11n_ONLY)
14336 score_config->ht_cap = 1;
14337
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053014338 status = ucfg_mlme_get_vht_for_24ghz(hdd_ctx->psoc, &bval);
14339 if (!QDF_IS_STATUS_SUCCESS(status))
14340 hdd_err("Failed to get vht_for_24ghz");
14341 if (score_config->vht_cap && bval)
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014342 score_config->vht_24G_cap = 1;
14343
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053014344 status = ucfg_mlme_get_vht_enable_tx_bf(hdd_ctx->psoc,
14345 &bval);
14346 if (!QDF_IS_STATUS_SUCCESS(status))
14347 hdd_err("unable to get vht_enable_tx_bf");
14348
14349 if (bval)
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014350 score_config->beamformee_cap = 1;
14351
Vignesh Viswanathan987f0bb2018-09-17 17:00:29 +053014352 return QDF_STATUS_SUCCESS;
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014353}
14354
Abhishek Singh257a9482017-03-06 16:52:39 +053014355/**
bings81fe50a2017-11-27 14:33:26 +080014356 * hdd_update_dfs_config() - API to update dfs configuration parameters.
14357 * @hdd_ctx: HDD context
14358 *
14359 * Return: 0 if success else err
14360 */
14361static int hdd_update_dfs_config(struct hdd_context *hdd_ctx)
14362{
Dustin Brown1dbefe62018-09-11 16:32:03 -070014363 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Abhishek Singh98278ce2018-12-27 11:41:03 +053014364 struct dfs_user_config dfs_cfg = {0};
bings81fe50a2017-11-27 14:33:26 +080014365 QDF_STATUS status;
14366
Arif Hussain224d3812018-11-16 17:58:38 -080014367 ucfg_mlme_get_dfs_filter_offload(hdd_ctx->psoc,
14368 &dfs_cfg.dfs_is_phyerr_filter_offload);
bings81fe50a2017-11-27 14:33:26 +080014369 status = ucfg_dfs_update_config(psoc, &dfs_cfg);
14370 if (QDF_IS_STATUS_ERROR(status)) {
14371 hdd_err("failed dfs psoc configuration");
14372 return -EINVAL;
14373 }
14374
14375 return 0;
14376}
14377
14378/**
Abhishek Singh257a9482017-03-06 16:52:39 +053014379 * hdd_update_scan_config - API to update scan configuration parameters
14380 * @hdd_ctx: HDD context
14381 *
14382 * Return: 0 if success else err
14383 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014384static int hdd_update_scan_config(struct hdd_context *hdd_ctx)
Abhishek Singh257a9482017-03-06 16:52:39 +053014385{
Dustin Brown1dbefe62018-09-11 16:32:03 -070014386 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Sandeep Puligillad7887022019-02-26 00:48:52 -080014387 struct scan_user_cfg scan_cfg;
Abhishek Singh257a9482017-03-06 16:52:39 +053014388 QDF_STATUS status;
Krunal Sonid2c33e12018-12-06 15:02:37 -080014389 uint32_t mcast_mcc_rest_time = 0;
Vignesh Viswanathana851d752018-10-03 19:44:38 +053014390
Sandeep Puligillad7887022019-02-26 00:48:52 -080014391 qdf_mem_zero(&scan_cfg, sizeof(scan_cfg));
Krunal Sonid2c33e12018-12-06 15:02:37 -080014392 status = ucfg_mlme_get_sta_miracast_mcc_rest_time(hdd_ctx->psoc,
14393 &mcast_mcc_rest_time);
14394 if (!QDF_IS_STATUS_SUCCESS(status)) {
14395 hdd_err("ucfg_mlme_get_sta_miracast_mcc_rest_time, use def");
14396 return -EIO;
14397 }
14398 scan_cfg.sta_miracast_mcc_rest_time = mcast_mcc_rest_time;
Dundi Raviteja85a240a2018-09-10 15:03:07 +053014399 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, hdd_ctx);
Vignesh Viswanathan987f0bb2018-09-17 17:00:29 +053014400
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053014401 status = hdd_update_score_config(&scan_cfg.score_config, hdd_ctx);
Vignesh Viswanathan987f0bb2018-09-17 17:00:29 +053014402 if (QDF_IS_STATUS_ERROR(status)) {
14403 hdd_err("Failed to update scoring config");
14404 return -EINVAL;
14405 }
Abhishek Singhb20db962017-03-03 21:28:46 +053014406
Abhishek Singh257a9482017-03-06 16:52:39 +053014407 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
14408 if (status != QDF_STATUS_SUCCESS) {
14409 hdd_err("failed pmo psoc configuration");
14410 return -EINVAL;
14411 }
14412
14413 return 0;
14414}
Abhishek Singh257a9482017-03-06 16:52:39 +053014415
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014416int hdd_update_components_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053014417{
14418 int ret;
14419
14420 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053014421 if (ret)
14422 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014423
Abhishek Singh257a9482017-03-06 16:52:39 +053014424 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080014425 if (ret)
14426 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014427
Frank Liud4b2fa02017-03-29 11:46:48 +080014428 ret = hdd_update_tdls_config(hdd_ctx);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014429 if (ret)
14430 return ret;
14431
14432 ret = hdd_update_dp_config(hdd_ctx);
bings81fe50a2017-11-27 14:33:26 +080014433 if (ret)
14434 return ret;
14435
14436 ret = hdd_update_dfs_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053014437
14438 return ret;
14439}
14440
Agrawal Ashish65634612016-08-18 13:24:32 +053014441/**
14442 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
14443 * @mode : cfg80211 DFS mode
14444 *
14445 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
14446 */
14447enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
14448{
14449 switch (mode) {
14450 case DFS_MODE_ENABLE:
14451 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053014452 case DFS_MODE_DISABLE:
14453 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053014454 case DFS_MODE_DEPRIORITIZE:
14455 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053014456 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080014457 hdd_debug("ACS dfs mode is NONE");
14458 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053014459 }
14460}
14461
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053014462/**
14463 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
14464 * @hddctx: pointer to hdd context
14465 * @set_value: enable/disable
14466 *
14467 * When Host sends vendor command enable, FW will send *ONE* CA ind to
14468 * Host(even though it is duplicate). When Host send vendor command
14469 * disable,FW doesn't perform any action. Whenever any change in
14470 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
14471 *
14472 * return - 0 on success, appropriate error values on failure.
14473 */
Jeff Johnson16528362018-06-14 12:34:16 -070014474int hdd_enable_disable_ca_event(struct hdd_context *hdd_ctx, uint8_t set_value)
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053014475{
14476 QDF_STATUS status;
14477
Jeff Johnson16528362018-06-14 12:34:16 -070014478 if (0 != wlan_hdd_validate_context(hdd_ctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053014479 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053014480
Jeff Johnson16528362018-06-14 12:34:16 -070014481 status = sme_enable_disable_chanavoidind_event(hdd_ctx->mac_handle,
14482 set_value);
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053014483 if (!QDF_IS_STATUS_SUCCESS(status)) {
14484 hdd_err("Failed to send chan avoid command to SME");
14485 return -EINVAL;
14486 }
14487 return 0;
14488}
Agrawal Ashish65634612016-08-18 13:24:32 +053014489
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014490/**
14491 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
14492 * @value: value to set
14493 *
14494 * This function will set the passed value to roaming in progress flag.
14495 *
14496 * Return: None
14497 */
14498void hdd_set_roaming_in_progress(bool value)
14499{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014500 struct hdd_context *hdd_ctx;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014501
14502 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14503 if (!hdd_ctx) {
14504 hdd_err("HDD context is NULL");
14505 return;
14506 }
14507
14508 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080014509 hdd_debug("Roaming in Progress set to %d", value);
Abhinav Kumar2b431b62019-03-18 20:23:58 +053014510 if (!hdd_ctx->roaming_in_progress) {
14511 /* Reset scan reject params on successful roam complete */
14512 hdd_debug("Reset scan reject params");
14513 hdd_init_scan_reject_params(hdd_ctx);
14514 }
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014515}
14516
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053014517bool hdd_is_roaming_in_progress(struct hdd_context *hdd_ctx)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014518{
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014519 if (!hdd_ctx) {
14520 hdd_err("HDD context is NULL");
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053014521 return false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014522 }
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080014523
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053014524 hdd_debug("roaming_in_progress = %d", hdd_ctx->roaming_in_progress);
14525
14526 return hdd_ctx->roaming_in_progress;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014527}
14528
Jeff Johnsona2ac4e72019-03-06 08:35:29 -080014529bool hdd_is_connection_in_progress(uint8_t *out_vdev_id,
14530 enum scan_reject_states *out_reason)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014531{
Jeff Johnson40dae4e2017-08-29 14:00:25 -070014532 struct hdd_station_ctx *hdd_sta_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -070014533 struct hdd_adapter *adapter = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014534 uint8_t sta_id = 0;
14535 uint8_t *sta_mac = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014536 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -070014537 mac_handle_t mac_handle;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014538
14539 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14540 if (!hdd_ctx) {
14541 hdd_err("HDD context is NULL");
14542 return false;
14543 }
14544
Jeff Johnson16528362018-06-14 12:34:16 -070014545 mac_handle = hdd_ctx->mac_handle;
14546
Dustin Brown920397d2017-12-13 16:27:50 -080014547 hdd_for_each_adapter(hdd_ctx, adapter) {
Tushnim Bhattacharyya929afa42018-06-01 15:04:44 -070014548 hdd_debug("Adapter with device mode %s(%d) exists",
Dustin Brown458027c2018-10-19 12:26:27 -070014549 qdf_opmode_str(adapter->device_mode),
14550 adapter->device_mode);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014551 if (((QDF_STA_MODE == adapter->device_mode)
14552 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
14553 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
14554 && (eConnectionState_Connecting ==
14555 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
Jeff Johnsone7951512019-02-27 10:02:51 -080014556 conn_info.conn_state)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053014557 hdd_debug("%pK(%d) Connection is in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014558 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson5a6fc962019-02-04 14:20:25 -080014559 adapter->vdev_id);
Jeff Johnsona2ac4e72019-03-06 08:35:29 -080014560 if (out_vdev_id && out_reason) {
14561 *out_vdev_id = adapter->vdev_id;
14562 *out_reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014563 }
14564 return true;
14565 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070014566 /*
14567 * sme_neighbor_middle_of_roaming is for LFR2
14568 * hdd_is_roaming_in_progress is for LFR3
14569 */
14570 if (((QDF_STA_MODE == adapter->device_mode) &&
14571 sme_neighbor_middle_of_roaming(
Jeff Johnson16528362018-06-14 12:34:16 -070014572 mac_handle,
Jeff Johnson5a6fc962019-02-04 14:20:25 -080014573 adapter->vdev_id)) ||
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053014574 hdd_is_roaming_in_progress(hdd_ctx)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053014575 hdd_debug("%pK(%d) Reassociation in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014576 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson5a6fc962019-02-04 14:20:25 -080014577 adapter->vdev_id);
Jeff Johnsona2ac4e72019-03-06 08:35:29 -080014578 if (out_vdev_id && out_reason) {
14579 *out_vdev_id = adapter->vdev_id;
14580 *out_reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014581 }
14582 return true;
14583 }
14584 if ((QDF_STA_MODE == adapter->device_mode) ||
14585 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
14586 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
14587 hdd_sta_ctx =
14588 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
14589 if ((eConnectionState_Associated ==
Jeff Johnsone7951512019-02-27 10:02:51 -080014590 hdd_sta_ctx->conn_info.conn_state)
Vignesh Viswanathan0a569292018-02-14 15:34:47 +053014591 && sme_is_sta_key_exchange_in_progress(
Jeff Johnson5a6fc962019-02-04 14:20:25 -080014592 mac_handle, adapter->vdev_id)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014593 sta_mac = (uint8_t *)
Jeff Johnson1e851a12017-10-28 14:36:12 -070014594 &(adapter->mac_addr.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053014595 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014596 " is in middle of WPS/EAPOL exchange.",
14597 MAC_ADDR_ARRAY(sta_mac));
Jeff Johnsona2ac4e72019-03-06 08:35:29 -080014598 if (out_vdev_id && out_reason) {
14599 *out_vdev_id = adapter->vdev_id;
14600 *out_reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014601 }
14602 return true;
14603 }
14604 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
14605 (QDF_P2P_GO_MODE == adapter->device_mode)) {
14606 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
14607 sta_id++) {
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070014608 if (!((adapter->sta_info[sta_id].in_use)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014609 && (OL_TXRX_PEER_STATE_CONN ==
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070014610 adapter->sta_info[sta_id].peer_state)))
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014611 continue;
14612
14613 sta_mac = (uint8_t *)
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070014614 &(adapter->sta_info[sta_id].
Jeff Johnsonf2356512017-10-21 16:04:12 -070014615 sta_mac.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053014616 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014617 " of SAP/GO is in middle of WPS/EAPOL exchange",
14618 MAC_ADDR_ARRAY(sta_mac));
Jeff Johnsona2ac4e72019-03-06 08:35:29 -080014619 if (out_vdev_id && out_reason) {
14620 *out_vdev_id = adapter->vdev_id;
14621 *out_reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014622 }
14623 return true;
14624 }
14625 if (hdd_ctx->connection_in_progress) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053014626 hdd_debug("AP/GO: connection is in progress");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014627 return true;
14628 }
14629 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014630 }
Dustin Brown920397d2017-12-13 16:27:50 -080014631
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014632 return false;
14633}
14634
14635/**
14636 * hdd_restart_sap() - to restart SAP in driver internally
Jeff Johnson9d295242017-08-29 14:39:48 -070014637 * @ap_adapter: Pointer to SAP struct hdd_adapter structure
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014638 *
14639 * Return: None
14640 */
Jeff Johnson9d295242017-08-29 14:39:48 -070014641void hdd_restart_sap(struct hdd_adapter *ap_adapter)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014642{
Jeff Johnson87251032017-08-29 13:31:11 -070014643 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070014644 struct hdd_hostapd_state *hostapd_state;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014645 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014646 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Jeff Johnson8f8ceb92019-03-24 08:16:55 -070014647 struct sap_config *sap_config;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014648 void *sap_ctx;
14649
14650 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
Jeff Johnson91df29d2017-10-27 19:29:50 -070014651 sap_config = &hdd_ap_ctx->sap_config;
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070014652 sap_ctx = hdd_ap_ctx->sap_context;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014653
14654 mutex_lock(&hdd_ctx->sap_lock);
14655 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
14656 wlan_hdd_del_station(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014657 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
14658 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
14659 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
14660 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053014661 qdf_wait_for_event_completion(&hostapd_state->
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014662 qdf_stop_bss_event,
Abhishek Singhd1f21c72019-01-21 15:16:34 +053014663 SME_CMD_STOP_BSS_TIMEOUT);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014664
14665 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014666 hdd_err("SAP Stop Failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014667 goto end;
14668 }
14669 }
14670 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Dustin Brown1dbefe62018-09-11 16:32:03 -070014671 policy_mgr_decr_session_set_pcl(hdd_ctx->psoc,
Jeff Johnson5a6fc962019-02-04 14:20:25 -080014672 ap_adapter->device_mode, ap_adapter->vdev_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070014673 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053014674 false);
Jeff Johnson6867ec32017-09-29 20:30:20 -070014675 hdd_err("SAP Stop Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014676
14677 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014678 hdd_err("SAP Not able to set AP IEs");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014679 wlansap_reset_sap_config_add_ie(sap_config,
14680 eUPDATE_IE_ALL);
14681 goto end;
14682 }
14683
14684 qdf_event_reset(&hostapd_state->qdf_event);
14685 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
14686 sap_config,
14687 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014688 hdd_err("SAP Start Bss fail");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014689 wlansap_reset_sap_config_add_ie(sap_config,
14690 eUPDATE_IE_ALL);
14691 goto end;
14692 }
14693
Jeff Johnson6867ec32017-09-29 20:30:20 -070014694 hdd_info("Waiting for SAP to start");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014695 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053014696 qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Abhishek Singhd1f21c72019-01-21 15:16:34 +053014697 SME_CMD_START_BSS_TIMEOUT);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014698 wlansap_reset_sap_config_add_ie(sap_config,
14699 eUPDATE_IE_ALL);
14700 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014701 hdd_err("SAP Start failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014702 goto end;
14703 }
Jeff Johnson6867ec32017-09-29 20:30:20 -070014704 hdd_err("SAP Start Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014705 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053014706 if (hostapd_state->bss_state == BSS_START) {
Dustin Brown1dbefe62018-09-11 16:32:03 -070014707 policy_mgr_incr_active_session(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080014708 ap_adapter->device_mode,
Jeff Johnson5a6fc962019-02-04 14:20:25 -080014709 ap_adapter->vdev_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070014710 hdd_green_ap_start_state_mc(hdd_ctx,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053014711 ap_adapter->device_mode,
14712 true);
14713 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014714 }
14715end:
14716 mutex_unlock(&hdd_ctx->sap_lock);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014717}
14718
14719/**
14720 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
14721 * with non dfs acs
14722 *
14723 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
14724 *
14725 * Return: None
14726 */
14727void hdd_check_and_restart_sap_with_non_dfs_acs(void)
14728{
Jeff Johnson9d295242017-08-29 14:39:48 -070014729 struct hdd_adapter *ap_adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014730 struct hdd_context *hdd_ctx;
Jeff Johnson2b6982c2018-05-29 14:56:11 -070014731 struct cds_context *cds_ctx;
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +053014732 uint8_t restart_chan;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014733
14734 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14735 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014736 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014737 return;
14738 }
14739
14740 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
14741 if (!cds_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014742 hdd_err("Invalid CDS Context");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014743 return;
14744 }
14745
Dustin Brown1dbefe62018-09-11 16:32:03 -070014746 if (policy_mgr_get_concurrency_mode(hdd_ctx->psoc)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080014747 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Dustin Brown7e761c72018-07-31 13:50:17 -070014748 hdd_debug("Concurrency mode is not SAP");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014749 return;
14750 }
14751
14752 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Dustin Brown07901ec2018-09-07 11:02:41 -070014753 if (ap_adapter &&
14754 test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags) &&
14755 wlan_reg_is_dfs_ch(hdd_ctx->pdev,
14756 ap_adapter->session.ap.operating_channel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014757
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +053014758 hdd_warn("STA-AP Mode DFS not supported, Switch SAP channel to Non DFS");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014759
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +053014760 restart_chan =
14761 hdd_get_safe_channel_from_pcl_and_acs_range(ap_adapter);
14762 if (!restart_chan ||
Dustin Brown07901ec2018-09-07 11:02:41 -070014763 wlan_reg_is_dfs_ch(hdd_ctx->pdev, restart_chan))
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +053014764 restart_chan = SAP_DEFAULT_5GHZ_CHANNEL;
14765
14766 hdd_switch_sap_channel(ap_adapter, restart_chan, true);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014767 }
14768}
14769
14770/**
14771 * hdd_set_connection_in_progress() - to set the connection in
14772 * progress flag
14773 * @value: value to set
14774 *
14775 * This function will set the passed value to connection in progress flag.
14776 * If value is previously being set to true then no need to set it again.
14777 *
14778 * Return: true if value is being set correctly and false otherwise.
14779 */
14780bool hdd_set_connection_in_progress(bool value)
14781{
14782 bool status = true;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014783 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014784
14785 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14786 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014787 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014788 return false;
14789 }
14790
14791 qdf_spin_lock(&hdd_ctx->connection_status_lock);
14792 /*
14793 * if the value is set to true previously and if someone is
14794 * trying to make it true again then it could be some race
14795 * condition being triggered. Avoid this situation by returning
14796 * false
14797 */
14798 if (hdd_ctx->connection_in_progress && value)
14799 status = false;
14800 else
14801 hdd_ctx->connection_in_progress = value;
14802 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
14803 return status;
14804}
14805
Jeff Johnson9d295242017-08-29 14:39:48 -070014806int wlan_hdd_send_p2p_quota(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070014807{
14808 if (!adapter) {
14809 hdd_err("Invalid adapter");
14810 return -EINVAL;
14811 }
14812 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Jeff Johnson5a6fc962019-02-04 14:20:25 -080014813 sme_cli_set_command(adapter->vdev_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070014814 WMA_VDEV_MCC_SET_TIME_QUOTA,
14815 set_value, VDEV_CMD);
14816 return 0;
14817
14818}
14819
Jeff Johnson9d295242017-08-29 14:39:48 -070014820int wlan_hdd_send_mcc_latency(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070014821{
14822 if (!adapter) {
14823 hdd_err("Invalid adapter");
14824 return -EINVAL;
14825 }
14826
14827 hdd_info("Send MCC latency WMA: %d", set_value);
Jeff Johnson5a6fc962019-02-04 14:20:25 -080014828 sme_cli_set_command(adapter->vdev_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070014829 WMA_VDEV_MCC_SET_TIME_LATENCY,
14830 set_value, VDEV_CMD);
14831 return 0;
14832}
14833
Jeff Johnson9d295242017-08-29 14:39:48 -070014834struct hdd_adapter *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070014835 *psoc, uint8_t vdev_id)
14836{
Jeff Johnson9d295242017-08-29 14:39:48 -070014837 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014838 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070014839
14840 /*
14841 * Currently PSOC is not being used. But this logic will
14842 * change once we have the converged implementation of
14843 * HDD context per PSOC in place. This would break if
14844 * multiple vdev objects reuse the vdev id.
14845 */
14846 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
14847 if (!adapter)
14848 hdd_err("Get adapter by vdev id failed");
14849
14850 return adapter;
14851}
14852
Jeff Johnson9d295242017-08-29 14:39:48 -070014853int hdd_get_rssi_snr_by_bssid(struct hdd_adapter *adapter, const uint8_t *bssid,
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053014854 int8_t *rssi, int8_t *snr)
14855{
14856 QDF_STATUS status;
Jeff Johnson16528362018-06-14 12:34:16 -070014857 mac_handle_t mac_handle;
Jeff Johnson025618c2018-03-18 14:41:00 -070014858 struct csr_roam_profile *roam_profile;
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053014859
Jeff Johnson025618c2018-03-18 14:41:00 -070014860 roam_profile = hdd_roam_profile(adapter);
Jeff Johnson16528362018-06-14 12:34:16 -070014861 mac_handle = hdd_adapter_get_mac_handle(adapter);
14862 status = sme_get_rssi_snr_by_bssid(mac_handle,
Jeff Johnson025618c2018-03-18 14:41:00 -070014863 roam_profile, bssid, rssi, snr);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053014864 if (QDF_STATUS_SUCCESS != status) {
14865 hdd_warn("sme_get_rssi_snr_by_bssid failed");
14866 return -EINVAL;
14867 }
14868
14869 return 0;
14870}
14871
Ganesh Kondabattini35739572017-06-21 16:26:39 +053014872/**
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014873 * hdd_reset_limit_off_chan() - reset limit off-channel command parameters
14874 * @adapter - HDD adapter
14875 *
14876 * Return: 0 on success and non zero value on failure
14877 */
14878int hdd_reset_limit_off_chan(struct hdd_adapter *adapter)
14879{
14880 struct hdd_context *hdd_ctx;
14881 int ret;
14882 QDF_STATUS status;
Krunal Sonie71838d2018-09-27 10:45:05 -070014883 uint8_t sys_pref = 0;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014884
14885 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
14886 ret = wlan_hdd_validate_context(hdd_ctx);
14887 if (ret < 0)
14888 return ret;
14889
Krunal Sonie71838d2018-09-27 10:45:05 -070014890 ucfg_policy_mgr_get_sys_pref(hdd_ctx->psoc,
14891 &sys_pref);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014892 /* set the system preferece to default */
Krunal Sonie71838d2018-09-27 10:45:05 -070014893 policy_mgr_set_cur_conc_system_pref(hdd_ctx->psoc, sys_pref);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014894
14895 /* clear the bitmap */
14896 adapter->active_ac = 0;
14897
14898 hdd_debug("reset ac_bitmap for session %hu active_ac %0x",
Jeff Johnson5a6fc962019-02-04 14:20:25 -080014899 adapter->vdev_id, adapter->active_ac);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014900
Jeff Johnson16528362018-06-14 12:34:16 -070014901 status = sme_send_limit_off_channel_params(hdd_ctx->mac_handle,
Jeff Johnson5a6fc962019-02-04 14:20:25 -080014902 adapter->vdev_id,
Jeff Johnson16528362018-06-14 12:34:16 -070014903 false, 0, 0, false);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014904 if (!QDF_IS_STATUS_SUCCESS(status)) {
14905 hdd_err("failed to reset limit off chan params");
14906 ret = -EINVAL;
14907 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053014908
14909 return ret;
14910}
14911
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014912/**
Yun Parkff6a16a2017-09-26 16:38:18 -070014913 * hdd_set_rx_mode_rps() - Enable/disable RPS in SAP mode
14914 * @struct hdd_context *hdd_ctx
14915 * @struct hdd_adapter *padapter
14916 * @bool enble
14917 *
14918 * Return: none
14919 */
14920void hdd_set_rx_mode_rps(bool enable)
14921{
14922 struct cds_config_info *cds_cfg = cds_get_ini_config();
Ryan Hsu0e878fa2018-05-04 15:22:09 -070014923 struct hdd_context *hdd_ctx;
14924 struct hdd_adapter *adapter;
Yun Parkff6a16a2017-09-26 16:38:18 -070014925
Ryan Hsu0e878fa2018-05-04 15:22:09 -070014926 if (!cds_cfg)
14927 return;
14928
14929 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14930 if (!hdd_ctx)
14931 return;
14932
14933 adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
14934 if (!adapter)
14935 return;
14936
14937 if (!hdd_ctx->rps && cds_cfg->uc_offload_enabled) {
Yun Parkff6a16a2017-09-26 16:38:18 -070014938 if (enable && !cds_cfg->rps_enabled)
14939 hdd_send_rps_ind(adapter);
14940 else if (!enable && cds_cfg->rps_enabled)
14941 hdd_send_rps_disable_ind(adapter);
14942 }
14943}
14944
Abhinav Kumar338e57d2019-02-04 17:30:10 +053014945void hdd_hidden_ssid_enable_roaming(hdd_handle_t hdd_handle, uint8_t vdev_id)
14946{
14947 struct hdd_context *hdd_ctx = hdd_handle_to_context(hdd_handle);
14948 struct hdd_adapter *adapter;
14949
14950 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
14951
14952 if (!adapter) {
14953 hdd_err("Adapter is null");
14954 return;
14955 }
14956 /* enable roaming on all adapters once hdd get hidden ssid rsp */
14957 wlan_hdd_enable_roaming(adapter);
14958}
14959
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014960/* Register the module init/exit functions */
14961module_init(hdd_module_init);
14962module_exit(hdd_module_exit);
14963
14964MODULE_LICENSE("Dual BSD/GPL");
14965MODULE_AUTHOR("Qualcomm Atheros, Inc.");
14966MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
14967
Srinivas Girigowda841da292018-02-21 16:33:00 -080014968static const struct kernel_param_ops con_mode_ops = {
14969 .set = con_mode_handler,
14970 .get = param_get_int,
14971};
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014972
Srinivas Girigowda841da292018-02-21 16:33:00 -080014973static const struct kernel_param_ops con_mode_ftm_ops = {
14974 .set = con_mode_handler_ftm,
14975 .get = param_get_int,
14976};
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053014977
Nirav Shah6aeecf92019-02-13 14:05:03 +053014978#ifdef WLAN_FEATURE_EPPING
14979static const struct kernel_param_ops con_mode_epping_ops = {
14980 .set = con_mode_handler_epping,
14981 .get = param_get_int,
14982};
14983#endif
14984
Nirav Shah73713f72018-05-17 14:50:41 +053014985#ifdef FEATURE_MONITOR_MODE_SUPPORT
Srinivas Girigowda841da292018-02-21 16:33:00 -080014986static const struct kernel_param_ops con_mode_monitor_ops = {
14987 .set = con_mode_handler_monitor,
14988 .get = param_get_int,
14989};
Nirav Shah73713f72018-05-17 14:50:41 +053014990#endif
Ravi Joshia307f632017-07-17 23:41:41 -070014991
Srinivas Girigowda841da292018-02-21 16:33:00 -080014992static const struct kernel_param_ops fwpath_ops = {
14993 .set = fwpath_changed_handler,
14994 .get = param_get_string,
14995};
14996
14997module_param_cb(con_mode, &con_mode_ops, &con_mode,
14998 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
14999
15000module_param_cb(con_mode_ftm, &con_mode_ftm_ops, &con_mode_ftm,
15001 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
15002
Nirav Shah6aeecf92019-02-13 14:05:03 +053015003#ifdef WLAN_FEATURE_EPPING
15004module_param_cb(con_mode_epping, &con_mode_epping_ops,
15005 &con_mode_epping, 0644);
15006#endif
15007
Nirav Shah73713f72018-05-17 14:50:41 +053015008#ifdef FEATURE_MONITOR_MODE_SUPPORT
Srinivas Girigowda841da292018-02-21 16:33:00 -080015009module_param_cb(con_mode_monitor, &con_mode_monitor_ops, &con_mode_monitor,
15010 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Nirav Shah73713f72018-05-17 14:50:41 +053015011#endif
Srinivas Girigowda841da292018-02-21 16:33:00 -080015012
15013module_param_cb(fwpath, &fwpath_ops, &fwpath,
15014 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015015
15016module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
15017
15018module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
15019
15020module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);
Dustin Brown4bbd5462019-03-22 11:18:13 -070015021
15022static int timer_multiplier_get_handler(char *buffer,
15023 const struct kernel_param *kp)
15024{
15025 return scnprintf(buffer, PAGE_SIZE, "%u", qdf_timer_get_multiplier());
15026}
15027
15028static int timer_multiplier_set_handler(const char *kmessage,
15029 const struct kernel_param *kp)
15030{
15031 QDF_STATUS status;
15032 uint32_t scalar;
15033
15034 status = qdf_uint32_parse(kmessage, &scalar);
15035 if (QDF_IS_STATUS_ERROR(status))
15036 return qdf_status_to_os_return(status);
15037
15038 if (!cfg_in_range(CFG_TIMER_MULTIPLIER, scalar))
15039 return -ERANGE;
15040
15041 qdf_timer_set_multiplier(scalar);
15042
15043 return 0;
15044}
15045
15046static const struct kernel_param_ops timer_multiplier_ops = {
15047 .get = timer_multiplier_get_handler,
15048 .set = timer_multiplier_set_handler,
15049};
15050
15051module_param_cb(timer_multiplier, &timer_multiplier_ops, NULL, 0644);
15052